From bc608051ab64a442d57a2162efccf214b1872f34 Mon Sep 17 00:00:00 2001 From: Tommy Vaillancourt Date: Thu, 5 Sep 2024 13:54:33 -0400 Subject: [PATCH 001/128] proposed fix for 874 --- lib_com/options.h | 3 +++ lib_dec/ivas_stereo_dft_dec_fx.c | 23 ++++++++++++++++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/lib_com/options.h b/lib_com/options.h index 6b9976ba5..75364c385 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -180,6 +180,9 @@ #define FIX_869_WRONG_UVGAIN_STEP /* VA: Fix wrong decoding of uv gain quantizer for td-stereo*/ #define FIX_871_REMOVE_UNNECESSARY_CONDITION /* VA: remove a condition that is not needed and prevented correct frame classification of the secondary channel of the TD stereo */ + +#define FIX_874_INCREASE_ITD_PRECISION /*VA : Fix issue 874 by increasing ITD precision already when decoding index */ +#define FIX_874_INCREASE_ITD_PRECISION_A /*VA : Fix a possible issue where 2*PI should be used instead of PI (to be confirmed) */ /* ################## End DEVELOPMENT switches ######################### */ /* clang-format on */ diff --git a/lib_dec/ivas_stereo_dft_dec_fx.c b/lib_dec/ivas_stereo_dft_dec_fx.c index 19973a3df..8159e4398 100644 --- a/lib_dec/ivas_stereo_dft_dec_fx.c +++ b/lib_dec/ivas_stereo_dft_dec_fx.c @@ -926,7 +926,11 @@ void stereo_dft_dec_smooth_parameters_fx( Word16 q_val; IF( GT_32( L_sub( hStereoDft->gipd_fx[add( k, k_offset )], hStereoDft->ipd_xfade_prev_fx ), EVS_PI_FX_Q27 ) ) { +#ifdef FIX_874_INCREASE_ITD_PRECISION_A + hStereoDft->ipd_xfade_target_fx = L_sub( hStereoDft->gipd_fx[add( k, k_offset )], EVS_PI_FX_Q27 << 1 ); +#else hStereoDft->ipd_xfade_target_fx = L_sub( hStereoDft->gipd_fx[add( k, k_offset )], EVS_PI_FX_Q27 ); +#endif move32(); hStereoDft->ipd_xfade_step_fx = BASOP_Util_Divide3232_Scale( L_sub( hStereoDft->ipd_xfade_target_fx, hStereoDft->ipd_xfade_prev_fx ), L_shl( L_sub( STEREO_DFT_ITD_CNG_XFADE, hStereoDft->ipd_xfade_counter ), Q24 ), &q_val ); move32(); @@ -2450,12 +2454,16 @@ static void stereo_dft_compute_td_stefi_params_fx( static void stereo_dft_dequantize_ipd_fx( Word16 *ind, Word32 *out_fx, +#ifndef FIX_874_INCREASE_ITD_PRECISION const Word16 N, +#endif const Word16 bits ) { - Word16 i; Word16 delta_fx; +#ifndef FIX_874_INCREASE_ITD_PRECISION + Word16 i; Word32 temp_out; +#endif IF( EQ_16( bits, 2 ) ) /* 2-bit phase quantization for the highest frequency band only */ { delta_fx = ( EVS_PI_FX ) >> 1; @@ -2478,12 +2486,17 @@ static void stereo_dft_dequantize_ipd_fx( assert( 0 ); } +#ifndef FIX_874_INCREASE_ITD_PRECISION FOR( i = 0; i < N; i++ ) { temp_out = L_sub( L_mult0( ind[i], delta_fx ), ( EVS_PI_FX ) ); *out_fx = L_shl( temp_out, 14 ); move32(); } +#else + *out_fx = L_sub( W_sat_l( W_mult_32_16( L_shl( ind[0], 13 ), delta_fx ) ), EVS_PI_FX_Q27 ); + move32(); +#endif return; } @@ -3782,7 +3795,11 @@ void stereo_dft_dec_read_BS_fx( move16(); nb = add( nb, STEREO_DFT_GIPD_NBITS ); n_bits = add( n_bits, STEREO_DFT_GIPD_NBITS ); +#ifndef FIX_874_INCREASE_ITD_PRECISION stereo_dft_dequantize_ipd_fx( &ind1_ipd[0], hStereoDft->gipd_fx + add( k, k_offset ), 1, STEREO_DFT_GIPD_NBITS ); +#else + stereo_dft_dequantize_ipd_fx( &ind1_ipd[0], hStereoDft->gipd_fx + add( k, k_offset ), STEREO_DFT_GIPD_NBITS ); +#endif } } ELSE IF( LE_16( *nb_bits, ( ( IVAS_SID_5k2 - SID_2k40 ) / FRAMES_PER_SEC - STEREO_DFT_FLAG_BITS - STEREO_DFT_SID_GIPD_NBITS - SID_FORMAT_NBITS ) ) ) @@ -3798,7 +3815,11 @@ void stereo_dft_dec_read_BS_fx( move16(); nb = add( nb, STEREO_DFT_SID_GIPD_NBITS ); n_bits = add( n_bits, STEREO_DFT_SID_GIPD_NBITS ); +#ifndef FIX_874_INCREASE_ITD_PRECISION stereo_dft_dequantize_ipd_fx( &ind1_ipd[0], hStereoDft->gipd_fx + add( k, k_offset ), 1, STEREO_DFT_SID_GIPD_NBITS ); +#else + stereo_dft_dequantize_ipd_fx( &ind1_ipd[0], hStereoDft->gipd_fx + add( k, k_offset ), STEREO_DFT_SID_GIPD_NBITS ); +#endif } } ELSE -- GitLab From 72f50b510a9fc60f057fd44fbc5a0a9a2124e8d1 Mon Sep 17 00:00:00 2001 From: Jan Kiene Date: Thu, 10 Oct 2024 14:13:36 +0200 Subject: [PATCH 002/128] add JBM BE test for neutral profile --- .gitlab-ci.yml | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 169688653..3ebcfb504 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -952,6 +952,24 @@ ivas-pytest-renderer: <<: *ivas-pytest-anchor +# --------------------------------------------------------------- +# Various other tests +# --------------------------------------------------------------- + +voip-be-on-merge-request: + extends: + - .test-job-linux-needs-testv-dir + - .rules-merge-request + stage: test + needs: ["build-codec-linux-make"] + timeout: "10 minutes" + script: + - *print-common-info + - make clean + - make -j + - python3 -m pytest tests/test_be_for_jbm_neutral_dly_profile.py + + # --------------------------------------------------------------- # Complexity measurement jobs # --------------------------------------------------------------- -- GitLab From 26047a06a75321ad6ede473951bcccf24816bd31 Mon Sep 17 00:00:00 2001 From: Jan Kiene Date: Thu, 10 Oct 2024 14:19:51 +0200 Subject: [PATCH 003/128] fix rules --- .gitlab-ci.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 3ebcfb504..dbe527606 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -959,7 +959,8 @@ ivas-pytest-renderer: voip-be-on-merge-request: extends: - .test-job-linux-needs-testv-dir - - .rules-merge-request + rules: + - if: $CI_PIPELINE_SOURCE == 'merge_request_event' && $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "main" # only have MR pipelines for MRs to main stage: test needs: ["build-codec-linux-make"] timeout: "10 minutes" -- GitLab From 68b584217c9c3d7d4a5b530b2ec85d8b2ad25e54 Mon Sep 17 00:00:00 2001 From: Eleni Fotopoulou Date: Thu, 17 Oct 2024 10:48:17 +0200 Subject: [PATCH 004/128] change to left shift operation for consistency with the previous case --- lib_dec/ivas_stereo_dft_dec_fx.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib_dec/ivas_stereo_dft_dec_fx.c b/lib_dec/ivas_stereo_dft_dec_fx.c index b6c58eb7c..b3fdec88b 100644 --- a/lib_dec/ivas_stereo_dft_dec_fx.c +++ b/lib_dec/ivas_stereo_dft_dec_fx.c @@ -949,7 +949,11 @@ void stereo_dft_dec_smooth_parameters_fx( } ELSE IF( GT_32( L_sub( hStereoDft->ipd_xfade_prev_fx, hStereoDft->gipd_fx[add( k, k_offset )] ), EVS_PI_FX_Q27 ) ) { +#ifndef FIX_874_INCREASE_ITD_PRECISION_A hStereoDft->ipd_xfade_target_fx = L_add( hStereoDft->gipd_fx[add( k, k_offset )], L_shl( EVS_PI_FX_Q27, 1 ) ); +#else + hStereoDft->ipd_xfade_target_fx = L_add( hStereoDft->gipd_fx[add( k, k_offset )], EVS_PI_FX_Q27 <<1 ); +#endif move32(); hStereoDft->ipd_xfade_step_fx = BASOP_Util_Divide3232_Scale( L_sub( hStereoDft->ipd_xfade_target_fx, hStereoDft->ipd_xfade_prev_fx ), L_shl( L_sub( STEREO_DFT_ITD_CNG_XFADE, hStereoDft->ipd_xfade_counter ), Q24 ), &q_val ); q_val = add( q_val, Q9 ); /* Q27 - (Q15 - q_val + (-3))*/ -- GitLab From 06d212d3a6854d74ed29124a4c9b6167dbe5644f Mon Sep 17 00:00:00 2001 From: Eleni Fotopoulou Date: Fri, 18 Oct 2024 16:06:51 +0200 Subject: [PATCH 005/128] fix for corner cases where ipd differences are exactly pi, but fixed point calculation rounding enables changes for cases when <> pi --- lib_dec/ivas_stereo_dft_dec_fx.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/lib_dec/ivas_stereo_dft_dec_fx.c b/lib_dec/ivas_stereo_dft_dec_fx.c index b3fdec88b..42e9d86ec 100644 --- a/lib_dec/ivas_stereo_dft_dec_fx.c +++ b/lib_dec/ivas_stereo_dft_dec_fx.c @@ -898,11 +898,17 @@ void stereo_dft_dec_smooth_parameters_fx( Word32 diff_ipd; Word16 nbands; Word32 max_res_pred_ind; +#ifdef FIX_874_INCREASE_ITD_PRECISION + Word32 PI_round; +#endif N_div = STEREO_DFT_NBDIV; move16(); k_offset = STEREO_DFT_OFFSET; move16(); +#ifdef FIX_874_INCREASE_ITD_PRECISION + PI_round = EVS_PI_FX_Q27 + EPSILLON_FX; /*add error corrections when comparing ipds with exactly a difference of pi*/ +#endif test(); IF( hStereoDft->frame_sid_nodata || prev_sid_nodata ) @@ -1242,12 +1248,20 @@ void stereo_dft_dec_smooth_parameters_fx( /* Smoothing of IPDs*/ pgIpd = hStereoDft->gipd_fx + ( add( k, k_offset ) ); diff_ipd = L_sub( pgIpd[0], pgIpd[-hStereoDft->prm_res[add( k, k_offset )]] ); +#ifndef FIX_874_INCREASE_ITD_PRECISION IF( LT_32( diff_ipd, -EVS_PI_FX_Q27 ) ) +#else + IF( LT_32( diff_ipd, -PI_round ) ) +#endif { pgIpd[0] = L_add( pgIpd[0], EVS_2PI_FX_Q27 ); move32(); } +#ifndef FIX_874_INCREASE_ITD_PRECISION ELSE IF( GT_32( diff_ipd, EVS_PI_FX_Q27 ) ) +#else + ELSE IF( GT_32( diff_ipd, PI_round ) ) +#endif { pgIpd[0] = L_sub( pgIpd[0], EVS_2PI_FX_Q27 ); move32(); @@ -1264,6 +1278,7 @@ void stereo_dft_dec_smooth_parameters_fx( { pgIpd[0] = L_add( L_shr( pgIpd[0], 1 ), L_shr( pgIpd[-hStereoDft->prm_res[add( k, k_offset )]], 1 ) ); move32(); + printf("offset = %d \n", hStereoDft->prm_res[add( k, k_offset )]); } } @@ -3837,6 +3852,7 @@ void stereo_dft_dec_read_BS_fx( move16(); move16(); + dbgwrite(hStereoDft->gipd_fx, sizeof(Word32), 3, 1, "res/gipd_fx"); /*------------------------------------------------------------------* * read Residual parameters *-----------------------------------------------------------------*/ -- GitLab From f9a144747651413ecd1631f45ac23810baef1840 Mon Sep 17 00:00:00 2001 From: Eleni Fotopoulou Date: Fri, 18 Oct 2024 16:10:47 +0200 Subject: [PATCH 006/128] rename define to reflect IPD changes and not ITD --- lib_com/options.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib_com/options.h b/lib_com/options.h index 31444407e..c671abd75 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -181,8 +181,8 @@ #define FIX_871_REMOVE_UNNECESSARY_CONDITION /* VA: remove a condition that is not needed and prevented correct frame classification of the secondary channel of the TD stereo */ -#define FIX_874_INCREASE_ITD_PRECISION /*VA : Fix issue 874 by increasing ITD precision already when decoding index */ -#define FIX_874_INCREASE_ITD_PRECISION_A /*VA : Fix a possible issue where 2*PI should be used instead of PI (to be confirmed) */ +#define FIX_874_INCREASE_IPD_PRECISION /*VA : Fix issue 874 by increasing ITD precision already when decoding index */ +#define FIX_874_INCREASE_IPD_PRECISION_A /*VA : Fix a possible issue where 2*PI should be used instead of PI (to be confirmed) */ #define FIX_875_SATURATION_DURING_ROUNDING /* VA: fix a possible saturation when rounding */ #define FIX_882_LOW_LEVEL_DISCONTINUITIES /* VA: Fix 882, discontinuities for low level signal by adding a scaling function that uses rounding, this function is more complex than normal one, has to be used only when necessary*/ #define FIX_879_DIFF_CONCEAL_PATH /* FhG: Fix for issue 879 and different concelalment paths that led to crash */ -- GitLab From 921ac0ec794c31b801af536c7ecea9271ab9e3cc Mon Sep 17 00:00:00 2001 From: Eleni Fotopoulou Date: Fri, 18 Oct 2024 16:10:57 +0200 Subject: [PATCH 007/128] remove debugging code --- lib_dec/ivas_stereo_dft_dec_fx.c | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/lib_dec/ivas_stereo_dft_dec_fx.c b/lib_dec/ivas_stereo_dft_dec_fx.c index 42e9d86ec..f21290554 100644 --- a/lib_dec/ivas_stereo_dft_dec_fx.c +++ b/lib_dec/ivas_stereo_dft_dec_fx.c @@ -898,7 +898,7 @@ void stereo_dft_dec_smooth_parameters_fx( Word32 diff_ipd; Word16 nbands; Word32 max_res_pred_ind; -#ifdef FIX_874_INCREASE_ITD_PRECISION +#ifdef FIX_874_INCREASE_IPD_PRECISION Word32 PI_round; #endif @@ -906,7 +906,7 @@ void stereo_dft_dec_smooth_parameters_fx( move16(); k_offset = STEREO_DFT_OFFSET; move16(); -#ifdef FIX_874_INCREASE_ITD_PRECISION +#ifdef FIX_874_INCREASE_IPD_PRECISION PI_round = EVS_PI_FX_Q27 + EPSILLON_FX; /*add error corrections when comparing ipds with exactly a difference of pi*/ #endif @@ -932,7 +932,7 @@ void stereo_dft_dec_smooth_parameters_fx( Word16 q_val; IF( GT_32( L_sub( hStereoDft->gipd_fx[add( k, k_offset )], hStereoDft->ipd_xfade_prev_fx ), EVS_PI_FX_Q27 ) ) { -#ifdef FIX_874_INCREASE_ITD_PRECISION_A +#ifdef FIX_874_INCREASE_IPD_PRECISION_A hStereoDft->ipd_xfade_target_fx = L_sub( hStereoDft->gipd_fx[add( k, k_offset )], EVS_PI_FX_Q27 << 1 ); #else hStereoDft->ipd_xfade_target_fx = L_sub( hStereoDft->gipd_fx[add( k, k_offset )], EVS_PI_FX_Q27 ); @@ -955,7 +955,7 @@ void stereo_dft_dec_smooth_parameters_fx( } ELSE IF( GT_32( L_sub( hStereoDft->ipd_xfade_prev_fx, hStereoDft->gipd_fx[add( k, k_offset )] ), EVS_PI_FX_Q27 ) ) { -#ifndef FIX_874_INCREASE_ITD_PRECISION_A +#ifndef FIX_874_INCREASE_IPD_PRECISION_A hStereoDft->ipd_xfade_target_fx = L_add( hStereoDft->gipd_fx[add( k, k_offset )], L_shl( EVS_PI_FX_Q27, 1 ) ); #else hStereoDft->ipd_xfade_target_fx = L_add( hStereoDft->gipd_fx[add( k, k_offset )], EVS_PI_FX_Q27 <<1 ); @@ -1248,7 +1248,7 @@ void stereo_dft_dec_smooth_parameters_fx( /* Smoothing of IPDs*/ pgIpd = hStereoDft->gipd_fx + ( add( k, k_offset ) ); diff_ipd = L_sub( pgIpd[0], pgIpd[-hStereoDft->prm_res[add( k, k_offset )]] ); -#ifndef FIX_874_INCREASE_ITD_PRECISION +#ifndef FIX_874_INCREASE_IPD_PRECISION IF( LT_32( diff_ipd, -EVS_PI_FX_Q27 ) ) #else IF( LT_32( diff_ipd, -PI_round ) ) @@ -1257,7 +1257,7 @@ void stereo_dft_dec_smooth_parameters_fx( pgIpd[0] = L_add( pgIpd[0], EVS_2PI_FX_Q27 ); move32(); } -#ifndef FIX_874_INCREASE_ITD_PRECISION +#ifndef FIX_874_INCREASE_IPD_PRECISION ELSE IF( GT_32( diff_ipd, EVS_PI_FX_Q27 ) ) #else ELSE IF( GT_32( diff_ipd, PI_round ) ) @@ -2473,13 +2473,13 @@ static void stereo_dft_compute_td_stefi_params_fx( static void stereo_dft_dequantize_ipd_fx( Word16 *ind, Word32 *out_fx, -#ifndef FIX_874_INCREASE_ITD_PRECISION +#ifndef FIX_874_INCREASE_IPD_PRECISION const Word16 N, #endif const Word16 bits ) { Word16 delta_fx; -#ifndef FIX_874_INCREASE_ITD_PRECISION +#ifndef FIX_874_INCREASE_IPD_PRECISION Word16 i; Word32 temp_out; #endif @@ -2505,7 +2505,7 @@ static void stereo_dft_dequantize_ipd_fx( assert( 0 ); } -#ifndef FIX_874_INCREASE_ITD_PRECISION +#ifndef FIX_874_INCREASE_IPD_PRECISION FOR( i = 0; i < N; i++ ) { temp_out = L_sub( L_mult0( ind[i], delta_fx ), ( EVS_PI_FX ) ); @@ -3814,7 +3814,7 @@ void stereo_dft_dec_read_BS_fx( move16(); nb = add( nb, STEREO_DFT_GIPD_NBITS ); n_bits = add( n_bits, STEREO_DFT_GIPD_NBITS ); -#ifndef FIX_874_INCREASE_ITD_PRECISION +#ifndef FIX_874_INCREASE_IPD_PRECISION stereo_dft_dequantize_ipd_fx( &ind1_ipd[0], hStereoDft->gipd_fx + add( k, k_offset ), 1, STEREO_DFT_GIPD_NBITS ); #else stereo_dft_dequantize_ipd_fx( &ind1_ipd[0], hStereoDft->gipd_fx + add( k, k_offset ), STEREO_DFT_GIPD_NBITS ); @@ -3834,7 +3834,7 @@ void stereo_dft_dec_read_BS_fx( move16(); nb = add( nb, STEREO_DFT_SID_GIPD_NBITS ); n_bits = add( n_bits, STEREO_DFT_SID_GIPD_NBITS ); -#ifndef FIX_874_INCREASE_ITD_PRECISION +#ifndef FIX_874_INCREASE_IPD_PRECISION stereo_dft_dequantize_ipd_fx( &ind1_ipd[0], hStereoDft->gipd_fx + add( k, k_offset ), 1, STEREO_DFT_SID_GIPD_NBITS ); #else stereo_dft_dequantize_ipd_fx( &ind1_ipd[0], hStereoDft->gipd_fx + add( k, k_offset ), STEREO_DFT_SID_GIPD_NBITS ); @@ -3852,7 +3852,6 @@ void stereo_dft_dec_read_BS_fx( move16(); move16(); - dbgwrite(hStereoDft->gipd_fx, sizeof(Word32), 3, 1, "res/gipd_fx"); /*------------------------------------------------------------------* * read Residual parameters *-----------------------------------------------------------------*/ -- GitLab From 548f6b251802b92d9b9157802548a6e14ab5957b Mon Sep 17 00:00:00 2001 From: Eleni Fotopoulou Date: Fri, 18 Oct 2024 16:14:37 +0200 Subject: [PATCH 008/128] remove more debugging code --- lib_dec/ivas_stereo_dft_dec_fx.c | 1 - 1 file changed, 1 deletion(-) diff --git a/lib_dec/ivas_stereo_dft_dec_fx.c b/lib_dec/ivas_stereo_dft_dec_fx.c index f21290554..a5286b3ae 100644 --- a/lib_dec/ivas_stereo_dft_dec_fx.c +++ b/lib_dec/ivas_stereo_dft_dec_fx.c @@ -1278,7 +1278,6 @@ void stereo_dft_dec_smooth_parameters_fx( { pgIpd[0] = L_add( L_shr( pgIpd[0], 1 ), L_shr( pgIpd[-hStereoDft->prm_res[add( k, k_offset )]], 1 ) ); move32(); - printf("offset = %d \n", hStereoDft->prm_res[add( k, k_offset )]); } } -- GitLab From d1a5956cc25aed21630fdd87a58c833e518f144e Mon Sep 17 00:00:00 2001 From: Eleni Fotopoulou Date: Fri, 18 Oct 2024 16:16:42 +0200 Subject: [PATCH 009/128] add assignment macro --- lib_dec/ivas_stereo_dft_dec_fx.c | 1 + 1 file changed, 1 insertion(+) diff --git a/lib_dec/ivas_stereo_dft_dec_fx.c b/lib_dec/ivas_stereo_dft_dec_fx.c index a5286b3ae..4563dafd6 100644 --- a/lib_dec/ivas_stereo_dft_dec_fx.c +++ b/lib_dec/ivas_stereo_dft_dec_fx.c @@ -908,6 +908,7 @@ void stereo_dft_dec_smooth_parameters_fx( move16(); #ifdef FIX_874_INCREASE_IPD_PRECISION PI_round = EVS_PI_FX_Q27 + EPSILLON_FX; /*add error corrections when comparing ipds with exactly a difference of pi*/ + move32(); #endif test(); -- GitLab From 3b101a3ea4998450b84ee6e513a62cc6322bc819 Mon Sep 17 00:00:00 2001 From: Eleni Fotopoulou Date: Fri, 18 Oct 2024 16:42:09 +0200 Subject: [PATCH 010/128] clang format --- lib_dec/ivas_stereo_dft_dec_fx.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib_dec/ivas_stereo_dft_dec_fx.c b/lib_dec/ivas_stereo_dft_dec_fx.c index 4563dafd6..40c8baf96 100644 --- a/lib_dec/ivas_stereo_dft_dec_fx.c +++ b/lib_dec/ivas_stereo_dft_dec_fx.c @@ -898,7 +898,7 @@ void stereo_dft_dec_smooth_parameters_fx( Word32 diff_ipd; Word16 nbands; Word32 max_res_pred_ind; -#ifdef FIX_874_INCREASE_IPD_PRECISION +#ifdef FIX_874_INCREASE_IPD_PRECISION Word32 PI_round; #endif @@ -906,7 +906,7 @@ void stereo_dft_dec_smooth_parameters_fx( move16(); k_offset = STEREO_DFT_OFFSET; move16(); -#ifdef FIX_874_INCREASE_IPD_PRECISION +#ifdef FIX_874_INCREASE_IPD_PRECISION PI_round = EVS_PI_FX_Q27 + EPSILLON_FX; /*add error corrections when comparing ipds with exactly a difference of pi*/ move32(); #endif @@ -959,7 +959,7 @@ void stereo_dft_dec_smooth_parameters_fx( #ifndef FIX_874_INCREASE_IPD_PRECISION_A hStereoDft->ipd_xfade_target_fx = L_add( hStereoDft->gipd_fx[add( k, k_offset )], L_shl( EVS_PI_FX_Q27, 1 ) ); #else - hStereoDft->ipd_xfade_target_fx = L_add( hStereoDft->gipd_fx[add( k, k_offset )], EVS_PI_FX_Q27 <<1 ); + hStereoDft->ipd_xfade_target_fx = L_add( hStereoDft->gipd_fx[add( k, k_offset )], EVS_PI_FX_Q27 << 1 ); #endif move32(); hStereoDft->ipd_xfade_step_fx = BASOP_Util_Divide3232_Scale( L_sub( hStereoDft->ipd_xfade_target_fx, hStereoDft->ipd_xfade_prev_fx ), L_shl( L_sub( STEREO_DFT_ITD_CNG_XFADE, hStereoDft->ipd_xfade_counter ), Q24 ), &q_val ); -- GitLab From 74cfcf73a26f9d06151e8acb469b335937922e7e Mon Sep 17 00:00:00 2001 From: Erik Norvell Date: Mon, 21 Oct 2024 13:45:05 +0200 Subject: [PATCH 011/128] Add fix NONBE_FIX_943_PORT_1208_DFT_STEREO_PLC_BURST to address issue 943 --- lib_com/options.h | 1 + lib_dec/ivas_stereo_dft_plc_fx.c | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/lib_com/options.h b/lib_com/options.h index 93908a861..5df2d052b 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -187,6 +187,7 @@ #define FIX_918_WRONG_SCALING_ON_MODE_SWITCHING /* VA: Fix wrong scaling of secondary channel when switching from stereo DFT to TD */ #define FIX_924_IGF_ROUNDFX_SAT #define FIX_930_JBM_BUFSIZE_MULT /* FhG: Fix 930, Word16 too small for apa_buffer_size */ +#define NONBE_FIX_943_PORT_1208_DFT_STEREO_PLC_BURST /* Ericsson: BASOP Issue 943, Float Issue 1208, fix for overflow of sample offset counter for burst error in DFT Stereo PLC. */ /* ################## End DEVELOPMENT switches ######################### */ diff --git a/lib_dec/ivas_stereo_dft_plc_fx.c b/lib_dec/ivas_stereo_dft_plc_fx.c index f6551e090..a8bb5a6e6 100644 --- a/lib_dec/ivas_stereo_dft_plc_fx.c +++ b/lib_dec/ivas_stereo_dft_plc_fx.c @@ -83,6 +83,9 @@ void stereo_dft_res_ecu_fx( Word16 trigo_dec[STEREO_DFT32MS_N_8k / 2 + 1]; Word16 trigo_step; Word16 q_fac; +#ifdef NONBE_FIX_943_PORT_1208_DFT_STEREO_PLC_BURST + Word16 time_offs; +#endif set32_fx( pDFT_RES, 0, L_FRAME8k ); @@ -122,7 +125,12 @@ void stereo_dft_res_ecu_fx( IF( k == 0 ) { Copy32( pDFT_RES, res_buf, L_FRAME8k ); /* hStereoDft->q_dft */ +#ifdef NONBE_FIX_943_PORT_1208_DFT_STEREO_PLC_BURST + time_offs = add_sat( hStereoDft->time_offs, output_frame ); + stereo_dft_res_subst_spec_fx( hStereoDft, res_buf, DFT_PRED_RES, time_offs, L_res, L_FRAME8k, k, num_plocs, plocs, plocsi, FALSE ); +#else stereo_dft_res_subst_spec_fx( hStereoDft, res_buf, DFT_PRED_RES, hStereoDft->time_offs + output_frame, L_res, L_FRAME8k, k, num_plocs, plocs, plocsi, FALSE ); +#endif rfft_fx( res_buf, trigo_dec, L_FRAME8k, +1 ); @@ -162,7 +170,11 @@ void stereo_dft_res_ecu_fx( } /*in case of burst error*/ +#ifdef NONBE_FIX_943_PORT_1208_DFT_STEREO_PLC_BURST + hStereoDft->time_offs = add_sat( hStereoDft->time_offs, L_FRAME8k ); /* Q0 */ +#else hStereoDft->time_offs = add( hStereoDft->time_offs, L_FRAME8k ); /* Q0 */ +#endif move16(); } -- GitLab From 14e237f866ccc379dd30c1803aa01511f0770638 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Mon, 21 Oct 2024 18:18:01 +0530 Subject: [PATCH 012/128] Fix for 3gpp issue 935: Decoder crash for multi-channel and ISM, BINAURAL_ROOM_REVERB output with specific renderer configuration files [x] Reason for crash: Issue is related to division by 0 in response_step_limit_fx() for pTarget_color_L buffer values. These are calculated using pAcoustic_dsr buffer values of IVAS_ROOM_ACOUSTICS_CONFIG_DATA handle. However, for the configuration that is given values are very small. Even with Q31, many of the values are becoming zero which eventually makes pTarget_color_L values zero. Check is added to address this condition. --- lib_rend/ivas_reverb_filter_design.c | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/lib_rend/ivas_reverb_filter_design.c b/lib_rend/ivas_reverb_filter_design.c index 79ad2c151..b4cc42a34 100644 --- a/lib_rend/ivas_reverb_filter_design.c +++ b/lib_rend/ivas_reverb_filter_design.c @@ -681,9 +681,18 @@ static void response_step_limit_fx( FOR( i = add( pivot_bin_idx, 1 ); i < dim_x; i++ ) { Word16 div_e; - Word32 desiredChange = BASOP_Util_Divide3232_Scale_cadence( X[i], X[i - 1], &div_e ); - Word16 desiredChange_q = sub( 31, ( div_e ) ); + Word32 desiredChange = 0; + move32(); + Word16 desiredChange_q = Q31; + move16(); Word64 temp; + + IF( X[i] ) + { + desiredChange = BASOP_Util_Divide3232_Scale_cadence( X[i], X[i - 1], &div_e ); + desiredChange_q = sub( 31, ( div_e ) ); + } + IF( GT_16( desiredChange_q, 30 ) ) { desiredChange = L_shr( desiredChange, desiredChange_q - 30 ); @@ -720,9 +729,17 @@ static void response_step_limit_fx( FOR( i = sub( pivot_bin_idx, 1 ); i >= 0; i-- ) { Word16 div_e; - Word32 desiredChange = BASOP_Util_Divide3232_Scale_cadence( X[i], X[i + 1], &div_e ); - Word16 desiredChange_q = sub( 31, ( div_e ) ); + Word32 desiredChange = 0; + move32(); + Word16 desiredChange_q = Q31; + move16(); Word64 temp; + + IF( X[i] ) + { + desiredChange = BASOP_Util_Divide3232_Scale_cadence( X[i], X[i + 1], &div_e ); + desiredChange_q = sub( 31, ( div_e ) ); + } IF( GT_16( desiredChange_q, 30 ) ) { desiredChange = L_shr( desiredChange, desiredChange_q - 30 ); -- GitLab From a19c33cb716e2a83fb72f1cc7972b017ebfc1f78 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Mon, 21 Oct 2024 18:30:59 +0530 Subject: [PATCH 013/128] MASA path changes and float code cleanup [x] MSAN error fixes in encoder [x] MASA path conversion and cleanup [x] Q-info addition for decoder files --- lib_com/ivas_ism_com.c | 9 +- lib_com/ivas_prot.h | 2 +- lib_com/ivas_spar_com.c | 2 +- lib_com/ivas_stat_com.h | 44 +- lib_com/prot.h | 2 + lib_dec/ACcontextMapping_dec.c | 6 +- lib_dec/FEC.c | 17 +- lib_dec/FEC_HQ_core.c | 8 +- lib_dec/FEC_HQ_phase_ecu.c | 48 +- lib_dec/LD_music_post_filter.c | 17 +- lib_dec/acelp_core_switch_dec.c | 8 +- lib_dec/ari_dec.c | 16 +- lib_dec/arith_coder_dec.c | 12 +- lib_dec/avq_dec.c | 5 +- lib_dec/bass_psfilter.c | 36 +- lib_dec/ivas_mct_core_dec.c | 4 +- lib_dec/ivas_mct_dec.c | 84 +- lib_dec/ivas_mct_dec_mct_fx.c | 14 +- lib_dec/ivas_mdct_core_dec.c | 110 +-- lib_dec/ivas_sce_dec_fx.c | 60 +- lib_dec/ivas_sns_dec_fx.c | 84 +- lib_dec/ivas_spar_decoder.c | 528 ++++++------ lib_dec/jbm_jb4sb.c | 4 +- lib_enc/cod_ace_fx.c | 5 + lib_enc/cod_tcx_fx.c | 4 + lib_enc/core_enc_init.c | 7 + lib_enc/ext_sig_ana.c | 14 - lib_enc/init_enc.c | 18 +- lib_enc/ivas_core_enc.c | 10 - lib_enc/ivas_core_pre_proc_front.c | 51 +- lib_enc/ivas_cpe_enc.c | 55 +- lib_enc/ivas_dirac_enc.c | 4 +- lib_enc/ivas_enc.c | 153 ---- lib_enc/ivas_enc_cov_handler.c | 8 +- lib_enc/ivas_init_enc.c | 88 -- lib_enc/ivas_ism_enc.c | 82 +- lib_enc/ivas_ism_metadata_enc.c | 14 - lib_enc/ivas_masa_enc.c | 1215 ++++++++------------------- lib_enc/ivas_mc_param_enc.c | 57 +- lib_enc/ivas_mc_paramupmix_enc.c | 4 +- lib_enc/ivas_mct_enc.c | 94 +-- lib_enc/ivas_mdct_core_enc.c | 22 +- lib_enc/ivas_qmetadata_enc.c | 71 +- lib_enc/ivas_qspherical_enc.c | 4 +- lib_enc/ivas_sce_enc.c | 56 +- lib_enc/ivas_spar_encoder.c | 236 +++--- lib_enc/ivas_spar_md_enc.c | 14 + lib_enc/ivas_stat_enc.h | 14 +- lib_enc/ivas_stereo_mdct_core_enc.c | 15 - lib_enc/lib_enc.c | 8 - lib_enc/stat_enc.h | 37 +- lib_enc/swb_bwe_enc_fx.c | 4 + lib_enc/transient_detection.c | 33 +- lib_enc/transient_detection_fx.c | 6 +- lib_rend/ivas_reverb_iir_filter.c | 40 +- lib_rend/lib_rend.c | 8 +- lib_util/masa_file_reader.c | 26 +- 57 files changed, 1232 insertions(+), 2365 deletions(-) diff --git a/lib_com/ivas_ism_com.c b/lib_com/ivas_ism_com.c index 458e473aa..583051b23 100644 --- a/lib_com/ivas_ism_com.c +++ b/lib_com/ivas_ism_com.c @@ -811,15 +811,8 @@ void ivas_ism_reset_metadata_enc( move32(); hIsmMeta->pitch_fx = 0; move32(); - hIsmMeta->radius_fx = 1 << 9; + hIsmMeta->radius_fx = 1 << 9; // Q9 move16(); -#ifdef IVAS_FLOAT_FIXED_TO_BE_REMOVED - hIsmMeta->azimuth = 0.0f; - hIsmMeta->elevation = 0.0f; - hIsmMeta->yaw = 0.0f; - hIsmMeta->pitch = 0.0f; - hIsmMeta->radius = 1.0f; -#endif hIsmMeta->ism_metadata_flag = 0; move16(); hIsmMeta->non_diegetic_flag = 0; diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index f0181aa9e..5ffc7f4f3 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -6506,7 +6506,7 @@ void ivas_enc_cov_handler_process_fx( ivas_enc_cov_handler_state_t *hCovEnc, /* i/o: SPAR Covar. encoder handle */ Word32 **ppIn_FR_real, Word32 **ppIn_FR_imag, - Word16 *q_ppIn_FR, + Word16 q_ppIn_FR, Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], Word16 *q_cov_real[IVAS_SPAR_MAX_CH], Word32 *cov_dtx_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], diff --git a/lib_com/ivas_spar_com.c b/lib_com/ivas_spar_com.c index 17bc88128..fb5cb5792 100644 --- a/lib_com/ivas_spar_com.c +++ b/lib_com/ivas_spar_com.c @@ -3814,7 +3814,7 @@ void ivas_get_spar_md_from_dirac_fx( } ELSE { - cov_real_dirac_fx[i][j][band] = L_shl_sat( Mpy_32_32( Mpy_32_32( en_ratio_fac_fx, response_avg_fx[i] ), response_avg_fx[j] ), 1 ); + cov_real_dirac_fx[i][j][band] = L_shl( Mpy_32_32( Mpy_32_32( en_ratio_fac_fx, response_avg_fx[i] ), response_avg_fx[j] ), 1 ); move32(); } } diff --git a/lib_com/ivas_stat_com.h b/lib_com/ivas_stat_com.h index 4cb4168df..5fdcf2bc1 100644 --- a/lib_com/ivas_stat_com.h +++ b/lib_com/ivas_stat_com.h @@ -65,12 +65,13 @@ typedef struct Word16 radius_fx; /* radius value read from the input metadata file */ /* Q9 */ Word32 yaw_fx; /* yaw value read from the input metadata file */ /* Q22 */ Word32 pitch_fx; /* pitch value read from the input metadata file */ /* Q22 */ +#else + float azimuth; /* azimuth value read from the input metadata file */ + float elevation; /* elevation value read from the input metadata file */ + float radius; /* radius value read from the input metadata file */ + float yaw; /* yaw value read from the input metadata file */ + float pitch; /* pitch value read from the input metadata file */ #endif - float azimuth; /* azimuth value read from the input metadata file */ - float elevation; /* elevation value read from the input metadata file */ - float radius; /* radius value read from the input metadata file */ - float yaw; /* yaw value read from the input metadata file */ - float pitch; /* pitch value read from the input metadata file */ int16_t non_diegetic_flag; /* Non-diegetic (non-headtracked) object flag */ @@ -79,11 +80,12 @@ typedef struct int16_t last_radius_idx; /* last frame index of coded radius */ int16_t radius_diff_cnt; /* FEC counter of consecutive differentially radius coded frames */ +#ifndef IVAS_FLOAT_FIXED float last_azimuth; /* MD smoothing in DTX- last Q azimuth value */ float last_elevation; /* MD smoothing in DTX - last Q elevation value */ float last_true_azimuth; /* MD smoothing in DTX- last true Q azimuth value */ float last_true_elevation; /* MD smoothing in DTX- last true Q elevation value */ -#ifdef IVAS_FLOAT_FIXED +#else Word32 last_azimuth_fx; /* MD smoothing in DTX- last Q azimuth value */ /* Q22 */ Word32 last_elevation_fx; /* MD smoothing in DTX - last Q elevation value */ /* Q22 */ Word32 last_true_azimuth_fx; /* MD smoothing in DTX- last true Q azimuth value */ /* Q22 */ @@ -92,9 +94,10 @@ typedef struct int16_t ism_md_fec_cnt_enc; /* counter of continuous frames where MD are not transmitted */ int16_t ism_md_inc_diff_cnt; /* counter of continuous frames where MD are transmitted in inactive segments when MD significantly changes */ - float last_true_radius; /* last true Q radius value */ -#ifdef IVAS_FLOAT_FIXED - Word16 last_true_radius_fx; /* last true Q radius value */ +#ifndef IVAS_FLOAT_FIXED + float last_true_radius; /* last true Q radius value */ +#else + Word16 last_true_radius_fx; /* last true Q radius value */ #endif int16_t ism_imp; /* ISM importance flag */ @@ -103,9 +106,10 @@ typedef struct #ifdef IVAS_FLOAT_FIXED Word32 q_azimuth_old_fx; Word32 q_elevation_old_fx; -#endif +#else float q_azimuth_old; float q_elevation_old; +#endif } ISM_METADATA_FRAME, *ISM_METADATA_HANDLE; @@ -453,15 +457,16 @@ typedef struct ivas_masa_descriptive_meta_struct typedef struct ivas_masa_directional_spatial_meta_struct { +#ifndef IVAS_FLOAT_FIXED float azimuth[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; float elevation[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; float energy_ratio[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; float spread_coherence[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; -#ifdef IVAS_FLOAT_FIXED - Word32 azimuth_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; /* Q22 */ - Word32 elevation_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; /* Q22 */ - Word32 energy_ratio_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; /* Q30 */ - Word16 spread_coherence_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; /* Q15 */ +#else + Word32 azimuth_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; /* Q22 */ + Word32 elevation_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; /* Q22 */ + Word32 energy_ratio_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; /* Q30 */ + Word16 spread_coherence_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; /* Q15 */ #endif uint16_t spherical_index[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; @@ -469,14 +474,15 @@ typedef struct ivas_masa_directional_spatial_meta_struct typedef struct ivas_masa_common_spatial_meta_struct { +#ifndef IVAS_FLOAT_FIXED float diffuse_to_total_ratio[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; float surround_coherence[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; -#ifdef IVAS_FLOAT_FIXED + float remainder_to_total_ratio[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; +#else Word32 diffuse_to_total_ratio_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; // Q30 - Word16 surround_coherence_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; // Q14 + Word16 surround_coherence_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; // Q15 Word32 remainder_to_total_ratio_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; // Q30 #endif - float remainder_to_total_ratio[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; } MASA_COMMON_SPATIAL_META; @@ -611,7 +617,7 @@ typedef struct ivas_masa_qmetadata_frame_struct #ifndef IVAS_FLOAT_FIXED float dir_comp_ratio; #else - Word16 dir_comp_ratio_fx; /* Q15 */ + Word16 dir_comp_ratio_fx; /* Q15 */ #endif uint8_t is_masa_ivas_format; diff --git a/lib_com/prot.h b/lib_com/prot.h index c430c9c3d..d0fc8d2ff 100644 --- a/lib_com/prot.h +++ b/lib_com/prot.h @@ -9345,6 +9345,7 @@ void FEC_clas_estim( const int16_t FEC_mode /* i : ACELP FEC mode */ ); +#ifndef IVAS_FLOAT_FIXED void InitTransientDetection( const int16_t nFrameLength, const int16_t nTCXDelay, @@ -9367,6 +9368,7 @@ float GetTCXMaxenergyChange( const int16_t isTCX10, const int16_t nCurrentSubblocks, const int16_t nPrevSubblocks ); +#endif void SetTCXModeInfo( Encoder_State *st, /* i/o: encoder state structure */ diff --git a/lib_dec/ACcontextMapping_dec.c b/lib_dec/ACcontextMapping_dec.c index 952303ce8..470e11e64 100644 --- a/lib_dec/ACcontextMapping_dec.c +++ b/lib_dec/ACcontextMapping_dec.c @@ -44,6 +44,7 @@ #include "ivas_prot.h" /* Range coder header file */ #include +#ifndef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* * ACcontextMapping_decode2_no_mem_s17_LC_ivas() * @@ -51,7 +52,6 @@ *-------------------------------------------------------------------*/ /*! r: resQBits */ -#ifndef IVAS_FLOAT_FIXED int16_t ACcontextMapping_decode2_no_mem_s17_LC_ivas( Decoder_State *st, /* i/o: decoder state */ int16_t *x, /* o : decoded spectrum */ @@ -319,7 +319,7 @@ int16_t ACcontextMapping_decode2_no_mem_s17_LC_ivas( return resQBits; } -#endif + /*-------------------------------------------------------------------* * RCcontextMapping_decode2_no_mem_s17_LCS() @@ -328,7 +328,7 @@ int16_t ACcontextMapping_decode2_no_mem_s17_LC_ivas( *-------------------------------------------------------------------*/ /*! r: resQBits */ -#ifndef IVAS_FLOAT_FIXED + int16_t RCcontextMapping_decode2_no_mem_s17_LCS( Decoder_State *st, /* i/o: decoder state */ int16_t *x, /* o : decoded spectrum */ diff --git a/lib_dec/FEC.c b/lib_dec/FEC.c index 3f19f35eb..dc3600728 100644 --- a/lib_dec/FEC.c +++ b/lib_dec/FEC.c @@ -43,24 +43,20 @@ #include "prot.h" #include "wmc_auto.h" +#ifndef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* * Local function prototypes *-------------------------------------------------------------------*/ -#ifndef IVAS_FLOAT_FIXED static void gain_dec_bfi( float *past_qua_en ); -#endif - -#ifndef IVAS_FLOAT_FIXED static void pulseRes_preCalc( Word16 *cond1, Word16 *cond2, Word32 *cond3, Word16 new_pit, Word16 Tc, Word16 L_frame ); -#endif /*-------------------------------------------------------------------* * FEC_exc_estim() * * Calculation of excitation signal *-------------------------------------------------------------------*/ -#ifndef IVAS_FLOAT_FIXED + void FEC_exc_estim( Decoder_State *st, /* i/o: Decoder static memory */ const int16_t L_frame, /* i : length of the frame */ @@ -482,7 +478,6 @@ void FEC_exc_estim( return; } -#endif /*-------------------------------------------------------------------* @@ -492,7 +487,7 @@ void FEC_exc_estim( * next frame *-------------------------------------------------------------------*/ -#ifndef IVAS_FLOAT_FIXED + static void gain_dec_bfi( float *past_qua_en /* i/o: gain quantization memory (4 words) */ ) @@ -522,9 +517,13 @@ static void gain_dec_bfi( return; } -#endif +/*-------------------------------------------------------------------* + * Local function prototypes + *-------------------------------------------------------------------*/ +#endif + #define WMC_TOOL_SKIP /*-------------------------------------------------------------------* * pulseRes_preCalc() diff --git a/lib_dec/FEC_HQ_core.c b/lib_dec/FEC_HQ_core.c index 17fe13469..e9695a9ef 100644 --- a/lib_dec/FEC_HQ_core.c +++ b/lib_dec/FEC_HQ_core.c @@ -1550,17 +1550,15 @@ void save_synthesis_hq_fec_fx( { case EVS_MONO: post_hq_delay = NS2SA_FX2( st->output_Fs, POST_HQ_DELAY_NS ); - move16(); BREAK; case IVAS_SCE: post_hq_delay = NS2SA_FX2( st->output_Fs, DELAY_CLDFB_NS ); - move16(); BREAK; case IVAS_CPE_DFT: + test(); IF( EQ_16( hCPE->nchan_out, 1 ) && hCPE->hStereoDft->hConfig->res_cod_mode == STEREO_DFT_RES_COD_OFF ) { post_hq_delay = NS2SA_FX2( st->output_Fs, DELAY_CLDFB_NS ); - move16(); } ELSE { @@ -1579,13 +1577,13 @@ void save_synthesis_hq_fec_fx( test(); test(); test(); - IF( ( EQ_16( st->codec_mode, MODE1 ) && st->hTcxDec != NULL ) && ( ( EQ_16( st->core, ACELP_CORE ) && !( EQ_16( st->bfi, 1 ) && EQ_16( st->con_tcx, 1 ) ) ) || EQ_16( st->core, HQ_CORE ) ) ) + IF( ( EQ_16( st->codec_mode, MODE1 ) && st->hTcxDec != NULL ) && ( ( ( st->core == ACELP_CORE ) && !( EQ_16( st->bfi, 1 ) && EQ_16( st->con_tcx, 1 ) ) ) || EQ_16( st->core, HQ_CORE ) ) ) { Copy( st->hTcxDec->synth_history_fx + output_frame, st->hTcxDec->synth_history_fx, add( sub( output_frame, post_hq_delay ), NS2SA_FX2( st->output_Fs, PH_ECU_MEM_NS ) ) ); FOR( Word16 i = 0; i < output_frame; i++ ) { #ifdef FIX_856_EXTRACT_L - st->hTcxDec->old_synthFB_fx[sub( add( i, output_frame ), post_hq_delay )] = extract_h( L_shl_sat( output_fx[i], 16 ) ); + st->hTcxDec->old_synthFB_fx[( ( i + output_frame ) - post_hq_delay )] = extract_h( L_shl_sat( output_fx[i], 16 ) ); // Q16 #else st->hTcxDec->old_synthFB_fx[sub( add( i, output_frame ), post_hq_delay )] = extract_l( output_fx[i] ); #endif diff --git a/lib_dec/FEC_HQ_phase_ecu.c b/lib_dec/FEC_HQ_phase_ecu.c index 3ab4ca0ef..7a46d308b 100644 --- a/lib_dec/FEC_HQ_phase_ecu.c +++ b/lib_dec/FEC_HQ_phase_ecu.c @@ -43,6 +43,7 @@ #include "prot.h" #include "wmc_auto.h" +#ifndef IVAS_FLOAT_FIXED /*---------------------------------------------------------------------* * Local constants *---------------------------------------------------------------------*/ @@ -98,10 +99,8 @@ * Local functions *---------------------------------------------------------------------*/ -#ifndef IVAS_FLOAT_FIXED static int16_t rand_phase( const int16_t seed, float *sin_F, float *cos_F ); static float imax2_jacobsen_mag( const float *y_re, const float *y_im ); -#endif /*-------------------------------------------------------------------* * mult_rev2() @@ -109,7 +108,7 @@ static float imax2_jacobsen_mag( const float *y_re, const float *y_im ); * Multiplication of two vectors second vector is multiplied in reverse order *-------------------------------------------------------------------*/ -#ifndef IVAS_FLOAT_FIXED + static void mult_rev2( const float x1[], /* i : Input vector 1 */ const float x2[], /* i : Input vector 2 */ @@ -126,7 +125,6 @@ static void mult_rev2( return; } -#endif /*-------------------------------------------------------------------* @@ -135,7 +133,6 @@ static void mult_rev2( * Square magnitude of fft spectrum *-------------------------------------------------------------------*/ -#ifndef IVAS_FLOAT_FIXED static void fft_spec2( float x[], /* i/o: Input vector: complex spectrum -> square magnitude spectrum */ const int16_t N /* i : Vector length */ @@ -153,7 +150,7 @@ static void fft_spec2( return; } -#endif + /*------------------------------------------------------------------* * rand_phase() @@ -161,7 +158,6 @@ static void fft_spec2( * randomized phase in form of sin and cos components *------------------------------------------------------------------*/ -#ifndef IVAS_FLOAT_FIXED /*! r: Updated seed from RNG */ static int16_t rand_phase( const int16_t seed, /* i : RNG seed */ @@ -193,7 +189,7 @@ static int16_t rand_phase( return seed2; } -#endif + /*----------------------------------------------------------------------------- * imax2_jacobsen_mag() @@ -262,7 +258,6 @@ float imax2_jacobsen_mag( return posi; } -#endif /*------------------------------------------------------------------* @@ -271,7 +266,7 @@ float imax2_jacobsen_mag( * Transient analysis *------------------------------------------------------------------*/ -#ifndef IVAS_FLOAT_FIXED + static void trans_ana( const float *xfp, /* i : Input signal */ float *mag_chg, /* i/o: Magnitude modification */ @@ -453,7 +448,6 @@ static void trans_ana( return; } -#endif /*------------------------------------------------------------------* @@ -462,7 +456,6 @@ static void trans_ana( * Peak-picking algorithm *------------------------------------------------------------------*/ -#ifndef IVAS_FLOAT_FIXED void peakfinder( const float *x0, /* i : vector from which the maxima will be found */ const int16_t len0, /* i : length of input vector */ @@ -659,7 +652,7 @@ void peakfinder( return; } -#endif + /*-------------------------------------------------------------------* * imax_pos() @@ -668,7 +661,6 @@ void peakfinder( *-------------------------------------------------------------------*/ /*! r: interpolated maximum position */ -#ifndef IVAS_FLOAT_FIXED float imax_pos( const float *y /* i : Input vector for peak interpolation */ ) @@ -710,7 +702,7 @@ float imax_pos( return posi + 1.0f; } -#endif + /*-------------------------------------------------------------------* * spec_ana() @@ -718,7 +710,6 @@ float imax_pos( * Spectral analysis *-------------------------------------------------------------------*/ -#ifndef IVAS_FLOAT_FIXED static void spec_ana( const float *prevsynth, /* i : Input signal */ int16_t *plocs, /* o : The indicies of the identified peaks */ @@ -956,7 +947,7 @@ static void spec_ana( return; } -#endif + /*-------------------------------------------------------------------* * subst_spec() @@ -964,7 +955,6 @@ static void spec_ana( * Substitution spectrum calculation *-------------------------------------------------------------------*/ -#ifndef IVAS_FLOAT_FIXED static void subst_spec( const int16_t *plocs, /* i : The indicies of the identified peaks */ const float *plocsi, /* i : Interpolated positions of the identified peaks */ @@ -1278,7 +1268,7 @@ static void subst_spec( return; } -#endif + /*-------------------------------------------------------------------------- * rec_wtda() @@ -1286,7 +1276,6 @@ static void subst_spec( * Windowing and TDA of reconstructed frame *--------------------------------------------------------------------------*/ -#ifndef IVAS_FLOAT_FIXED static void rec_wtda( float *X, /* i/o: ECU frame / unwindowed ECU frame */ float *ecu_rec, /* o : Reconstructed frame in tda domain */ @@ -1395,7 +1384,6 @@ static void rec_wtda( return; } -#endif /*-------------------------------------------------------------------------- @@ -1404,7 +1392,6 @@ static void rec_wtda( * Frame reconstruction *--------------------------------------------------------------------------*/ -#ifndef IVAS_FLOAT_FIXED static void rec_frame( float *X, /* i/o: FFT spectrum / IFFT of spectrum */ float *ecu_rec, /* o : Reconstructed frame in tda domain */ @@ -1446,7 +1433,6 @@ static void rec_frame( return; } -#endif /*-------------------------------------------------------------------------- @@ -1455,7 +1441,6 @@ static void rec_frame( * FIR downsampling filter *--------------------------------------------------------------------------*/ -#ifndef IVAS_FLOAT_FIXED static void fir_dwn( const float x[], /* i : input vector */ const float h[], /* i : impulse response of the FIR filter */ @@ -1508,7 +1493,6 @@ static void fir_dwn( return; } -#endif /*-------------------------------------------------------------------------- @@ -1517,7 +1501,6 @@ static void fir_dwn( * Pitch/correlation analysis and adaptive analysis frame length calculation *--------------------------------------------------------------------------*/ -#ifndef IVAS_FLOAT_FIXED static void fec_ecu_pitch( const float *prevsynth, /* i : previous synthesis */ float *prevsynth_LP, /* o : down-sampled synthesis */ @@ -1643,7 +1626,6 @@ static void fec_ecu_pitch( return; } -#endif /*-------------------------------------------------------------------------- @@ -1653,7 +1635,6 @@ static void fec_ecu_pitch( * next power of 2 using linear interpolation. *--------------------------------------------------------------------------*/ -#ifndef IVAS_FLOAT_FIXED static void fec_ecu_dft( const float *prevsynth_LP, /* i : Downsampled past synthesis (2*160 samples) */ const int16_t N, /* i : Analysis frame length in 8 kHz (corr. max) */ @@ -1719,7 +1700,6 @@ static void fec_ecu_dft( * fast cosinus generator Amp*cos(2*pi*freq+phi) *--------------------------------------------------------------------------*/ -#ifndef IVAS_FLOAT_FIXED static void singenerator( const int16_t L, /* i : size of output */ const float cosfreq, /* i : cosine of 1-sample dephasing at the given frequency */ @@ -1769,7 +1749,6 @@ static void singenerator( return; } -#endif /*-------------------------------------------------------------------------- @@ -1778,7 +1757,6 @@ static void singenerator( * ECU frame sinusoid generation *--------------------------------------------------------------------------*/ -#ifndef IVAS_FLOAT_FIXED static void sinusoidal_synthesis( const float *Tfr, /* i : DFT coefficients, real part */ const float *Tfi, /* i : DFT coefficients, imag part */ @@ -1902,7 +1880,6 @@ static void sinusoidal_synthesis( return; } -#endif /*-------------------------------------------------------------------------- * fec_noise_filling() @@ -1915,7 +1892,6 @@ static void sinusoidal_synthesis( * it to be inserted into wtda *--------------------------------------------------------------------------*/ -#ifndef IVAS_FLOAT_FIXED static void fec_noise_filling( const float *prevsynth, /* i : Past synthesis buffer (length 2*L) */ float *synthesis, /* i/o: Sinusoidal ECU / Sinusoidal ECU + noise */ @@ -2031,7 +2007,6 @@ static void fec_noise_filling( return; } -#endif /*-------------------------------------------------------------------------- * fec_alg() @@ -2040,7 +2015,6 @@ static void fec_noise_filling( * length *--------------------------------------------------------------------------*/ -#ifndef IVAS_FLOAT_FIXED static void fec_alg( const float *prevsynth, /* i : previous synthesis */ const float *prevsynth_LP, /* i : down-sampled synthesis */ @@ -2074,7 +2048,6 @@ static void fec_alg( return; } -#endif /*-------------------------------------------------------------------------- @@ -2083,7 +2056,6 @@ static void fec_alg( * Main routine for HQ phase ECU *--------------------------------------------------------------------------*/ -#ifndef IVAS_FLOAT_FIXED static void hq_phase_ecu( const float *prevsynth, /* i : buffer of previously synthesized signal */ float *ecu_rec, /* o : reconstructed frame in tda domain */ @@ -2175,9 +2147,7 @@ static void hq_phase_ecu( return; } -#endif -#ifndef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------------- * hq_ecu() * diff --git a/lib_dec/LD_music_post_filter.c b/lib_dec/LD_music_post_filter.c index e3817e69f..dfdd586b4 100644 --- a/lib_dec/LD_music_post_filter.c +++ b/lib_dec/LD_music_post_filter.c @@ -43,6 +43,7 @@ #include "prot_fx.h" #include "wmc_auto.h" +#ifndef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* * Local constants *-------------------------------------------------------------------*/ @@ -65,14 +66,11 @@ * Local function prototypes *-------------------------------------------------------------------*/ -#ifndef IVAS_FLOAT_FIXED static void spectrum_mod_dct( float data[], const float lf_E[], float lf_EO[], const float noiseE[], const float minGain, float lp_gbin[], const int16_t music_flag, int16_t min_band, const float MAX_GN, const int16_t max_band ); static void analy_sp_dct( const float dct_in[], float dct_buf[], float *fr_bands, float *lf_E, float *etot ); static void find_enr_dct( const float data[], float band[], float *ptE, float *Etot, const int16_t min_band, const int16_t max_band, float *Bin_E, const float bin_freq ); -#endif -#ifndef IVAS_FLOAT_FIXED /*------------------------------------------------------------------------* * LD_music_post_filter() * @@ -360,7 +358,6 @@ void LD_music_post_filter( /* reconstruction of the enhanced synthesis */ mvr2r( DCT_buf, dtc_out, DCT_L_POST ); } -#endif /*---------------------------------------------------------------------------* * spectrum_mod_dct() @@ -368,7 +365,6 @@ void LD_music_post_filter( * spectrum enhancement according to the output of signal_type_clas() *---------------------------------------------------------------------------*/ -#ifndef IVAS_FLOAT_FIXED static void spectrum_mod_dct( float data[], /* i/o: DCT spectrum */ const float lf_E[], /* i : per bin E for first 46 bins (without DC) */ @@ -523,7 +519,6 @@ static void spectrum_mod_dct( return; } -#endif /*----------------------------------------------------------------------------------* * analy_sp_dct() @@ -531,7 +526,6 @@ static void spectrum_mod_dct( * Spectral analysis of the current synthesized frame *----------------------------------------------------------------------------------*/ -#ifndef IVAS_FLOAT_FIXED static void analy_sp_dct( const float dct_in[], /* i : input DCT spectrum */ float dct_buf[], /* i : output DCT spectrum */ @@ -558,7 +552,6 @@ static void analy_sp_dct( return; } -#endif /*------------------------------------------------------------------------* * find_enr_dct) @@ -567,7 +560,6 @@ static void analy_sp_dct( * The energy is normalized by the number of frequency bins in a channel *------------------------------------------------------------------------*/ -#ifndef IVAS_FLOAT_FIXED void find_enr_dct( const float data[], /* i : fft result, for the format see fft_rel.c */ float band[], /* o : per band energy */ @@ -630,7 +622,6 @@ void find_enr_dct( return; } -#endif /*------------------------------------------------------------------------* * Prep_music_postP() @@ -638,7 +629,6 @@ void find_enr_dct( * Performs the steps needed to do the music post processing *------------------------------------------------------------------------*/ -#ifndef IVAS_FLOAT_FIXED void Prep_music_postP( float exc_buffer_in[], /* i/o: excitation buffer */ float dct_buffer_out[], /* o : DCT output buffer */ @@ -701,7 +691,6 @@ void Prep_music_postP( return; } -#endif /*------------------------------------------------------------------------* * Post_music_postP() @@ -710,7 +699,6 @@ void Prep_music_postP( * to retreive the aligned excitation and redo the synthesis *------------------------------------------------------------------------*/ -#ifndef IVAS_FLOAT_FIXED void Post_music_postP( float dct_buffer_in[], /* i/o: excitation buffer */ float exc_buffer_out[], /* o : DCT output buffer */ @@ -731,7 +719,6 @@ void Post_music_postP( return; } -#endif /*-------------------------------------------------------------------* @@ -739,7 +726,7 @@ void Post_music_postP( * * Initialize LD music postfilter state structure *-------------------------------------------------------------------*/ -#ifndef IVAS_FLOAT_FIXED + void music_postfilt_init_flt( MUSIC_POSTFILT_HANDLE hMusicPF /* i/o: LD music postfilter handle */ ) diff --git a/lib_dec/acelp_core_switch_dec.c b/lib_dec/acelp_core_switch_dec.c index a982d8bb4..a7a2eb75b 100644 --- a/lib_dec/acelp_core_switch_dec.c +++ b/lib_dec/acelp_core_switch_dec.c @@ -40,22 +40,18 @@ #include "rom_com.h" #include "prot.h" #include "wmc_auto.h" - +#ifndef IVAS_FLOAT_FIXED /*---------------------------------------------------------------------* * Local function prototypes *---------------------------------------------------------------------*/ - -#ifndef IVAS_FLOAT_FIXED static void decod_gen_voic_core_switch( Decoder_State *st, const int16_t L_frame, const int16_t sharpFlag, const float *Aq, float *exc, const int32_t core_brate ); -#endif - /*-------------------------------------------------------------------* * acelp_core_switch_dec() * * ACELP core decoder in the first ACELP->HQ switching frame *-------------------------------------------------------------------*/ -#ifndef IVAS_FLOAT_FIXED + ivas_error acelp_core_switch_dec( Decoder_State *st, /* i/o: decoder state structure */ float *synth_subfr_out, /* o : synthesized ACELP subframe */ diff --git a/lib_dec/ari_dec.c b/lib_dec/ari_dec.c index 7d63c3b34..2102356fa 100644 --- a/lib_dec/ari_dec.c +++ b/lib_dec/ari_dec.c @@ -113,15 +113,15 @@ Word16 ari_start_decoding_14bits_prm_ivas_fx( Word16 i; const Word16 *p; - val = L_deposit_l( 0 ); - + val = 0; + move32(); p = ptr + bp; FOR( i = 0; i < cbitsnew; i++ ) { val = L_or( L_shl( val, 1 ), *( p + i ) ); } - s->low = L_deposit_l( 0 ); + s->low = 0; move32(); s->high = ari_q4new; move32(); @@ -189,8 +189,7 @@ Word16 ari_decode_14bits_pow_ivas( move16(); k = sub( k, 1 ); symbol = (UWord16) L_shl( 1, k ); - move16(); - break; + BREAK; } } assert( k < 12 ); /* maximum 2^10-1*/ @@ -220,7 +219,6 @@ Word16 ari_decode_14bits_pow_ivas( highlim = 16384; move16(); move16(); - move16(); } @@ -238,7 +236,6 @@ Word16 ari_decode_14bits_pow_ivas( value = (UWord32) W_sub( value, ari_q2new ); low = L_sub( low, ari_q2new ); high = L_sub( high, ari_q2new ); - move32(); } ELSE { @@ -248,7 +245,6 @@ Word16 ari_decode_14bits_pow_ivas( value = (UWord32) W_sub( value, ari_q1new ); low = L_sub( low, ari_q1new ); high = L_sub( high, ari_q1new ); - move32(); } ELSE { @@ -262,7 +258,6 @@ Word16 ari_decode_14bits_pow_ivas( assert( abs( ptr[bp] ) <= 1 && "AC expects reading binary values!!!" ); value = (UWord32) ( W_shl( value, 1 ) | ptr[bp++] ); - move32(); } test(); @@ -340,6 +335,7 @@ Word16 ari_decode_14bits_sign_ivas( } ELSE { + test(); IF( GE_32( low, ari_q1new ) && LE_32( high, ari_q3new ) ) { value = (UWord32) W_sub( value, ari_q1new ); @@ -348,7 +344,7 @@ Word16 ari_decode_14bits_sign_ivas( } ELSE { - break; + BREAK; } } } diff --git a/lib_dec/arith_coder_dec.c b/lib_dec/arith_coder_dec.c index a4f4d7409..f41f4f590 100644 --- a/lib_dec/arith_coder_dec.c +++ b/lib_dec/arith_coder_dec.c @@ -120,11 +120,11 @@ static int16_t tcx_arith_decode( #ifdef IVAS_FLOAT_FIXED static Word16 tcx_arith_decode_ivas_fx( const Word16 L_frame, /* i : number of spectral lines */ - const Word16 envelope[], /* i : scaled envelope (Q15-e) */ + const Word16 envelope[], /* i : scaled envelope (Q15-envelope_e) */ Word16 envelope_e, /* i : scaled envelope exponent (Q0) */ const Word16 target_bits, /* i : target bit budget */ Word16 prm[], /* i : bitstream parameters */ - Word32 q_spectrum[], /* o : scalar quantized spectrum */ + Word32 q_spectrum[], /* o : scalar quantized spectrum (Q31-q_spectrum_e) */ Word16 *q_spectrum_e /* o : spectrum exponent */ ) { @@ -159,13 +159,13 @@ static Word16 tcx_arith_decode_ivas_fx( bp = ari_decode_14bits_sign_ivas( prm, bp, target_bits, &s, &as ); q_spectrum[k] = L_mult( q, sub( 3, shl( s, 1 ) ) ); move32(); - q_spectrum[k] = L_shl( q_spectrum[k], 30 - SPEC_EXP_DEC ); + q_spectrum[k] = L_shl( q_spectrum[k], 30 - SPEC_EXP_DEC ); // Q(31-20) move32(); } ELSE { /* line is zero, no sign needed */ - q_spectrum[k] = L_deposit_l( 0 ); + q_spectrum[k] = 0; move32(); } @@ -297,7 +297,7 @@ void tcx_arith_decode_envelope( #ifdef IVAS_FLOAT_FIXED void tcx_arith_decode_envelope_ivas_fx( Decoder_State *st, /* i/o: coder state */ - Word32 q_spectrum[], /* o : quantised MDCT coefficients */ + Word32 q_spectrum[], /* o : quantised MDCT coefficients Q(31-q_spectrum_e) */ Word16 *q_spectrum_e, /* o : MDCT exponent */ const Word16 L_frame, /* i : frame or MDCT length */ Word16 L_spec, /* i : length w/o BW limitation */ @@ -328,7 +328,7 @@ void tcx_arith_decode_envelope_ivas_fx( test(); test(); test(); - IF( GT_16( L_spec, N_MAX_ARI ) || ( EQ_16( st->element_mode, EVS_MONO ) && GT_16( target_bits, ( ACELP_13k20 / FRAMES_PER_SEC ) ) ) || + IF( GT_16( L_spec, N_MAX_ARI ) || ( ( st->element_mode == EVS_MONO ) && GT_16( target_bits, ( ACELP_13k20 / FRAMES_PER_SEC ) ) ) || ( EQ_16( st->element_mode, IVAS_SCE ) && ( GT_16( st->bits_frame_nominal, ( LPC_SHAPED_ARI_MAX_RATE / FRAMES_PER_SEC ) ) ) ) || ( GT_16( st->element_mode, IVAS_SCE ) && ( GT_16( st->bits_frame_nominal, ( LPC_SHAPED_ARI_MAX_RATE_CPE / FRAMES_PER_SEC ) ) ) ) || ( target_bits <= 0 ) ) diff --git a/lib_dec/avq_dec.c b/lib_dec/avq_dec.c index b0eef6b2f..8fc098d2d 100644 --- a/lib_dec/avq_dec.c +++ b/lib_dec/avq_dec.c @@ -41,12 +41,12 @@ #include "wmc_auto.h" #include +#ifndef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* * Local prototypes *-------------------------------------------------------------------*/ -#ifndef IVAS_FLOAT_FIXED + static void read_cv( Decoder_State *st, uint16_t *I, int16_t *kv, int16_t nq, int16_t *nbits ); -#endif /*-----------------------------------------------------------------* * AVQ_demuxdec() @@ -55,7 +55,6 @@ static void read_cv( Decoder_State *st, uint16_t *I, int16_t *kv, int16_t nq, in * split algebraic vector dequantizer based on RE8 latice. *-----------------------------------------------------------------*/ -#ifndef IVAS_FLOAT_FIXED void AVQ_demuxdec( Decoder_State *st, /* i/o: decoder state structure */ int16_t xriq[], /* o : decoded subvectors [0..8*Nsv-1]*/ diff --git a/lib_dec/bass_psfilter.c b/lib_dec/bass_psfilter.c index 47ca645bc..9d1487125 100644 --- a/lib_dec/bass_psfilter.c +++ b/lib_dec/bass_psfilter.c @@ -725,8 +725,8 @@ Word16 res_bpf_adapt_ivas_fx( W_tmp = W_add_nosat( W_tmp, W_mult0_32_32( res_buf[i], res_buf[i] ) ); } - res_hb_nrg = (Word32) W_shr( W_tmp, shl( q_res, 1 ) ); // Q0 - res_hb_nrg = Mpy_32_16_1( res_hb_nrg, bw_inv ); + res_hb_nrg = W_extract_l( W_shr( W_tmp, shl( q_res, 1 ) ) ); // Q0 + res_hb_nrg = Mpy_32_16_1( res_hb_nrg, bw_inv ); // Q0 res_hb_nrg = L_add( Mpy_32_16_1( res_hb_nrg, STEREO_DFT_BPF_ADAPT_ALPHA_FX ), Mpy_32_16_1( hStereoDft->res_hb_nrg_mem_fx, sub( MAX_16, STEREO_DFT_BPF_ADAPT_ALPHA_FX ) ) ); hStereoDft->res_hb_nrg_mem_fx = res_hb_nrg; move32(); @@ -738,7 +738,7 @@ Word16 res_bpf_adapt_ivas_fx( { tmp = L_sub( bpf_error_signal_8k[i], hStereoDft->bpf_error_signal_last_fx ); error_nrg = Madd_32_32( error_nrg, tmp, tmp ); - hStereoDft->bpf_error_signal_last_fx = bpf_error_signal_8k[add( i, ( STEREO_DFT_L_SUBFR_8k - 1 ) )]; + hStereoDft->bpf_error_signal_last_fx = bpf_error_signal_8k[( i + ( STEREO_DFT_L_SUBFR_8k - 1 ) )]; move32(); } error_nrg = L_shl( error_nrg, 1 ); // Q0 @@ -810,7 +810,7 @@ void bpf_pitch_coherence( #ifdef IVAS_FLOAT_FIXED void bpf_pitch_coherence_ivas_fx( Decoder_State *st, /* i/o: decoder state structure */ - const Word32 pitch_buf[] /* i : pitch for every subfr [0,1,2,3] */ + const Word32 pitch_buf[] /* i : pitch for every subfr [0,1,2,3] Q20 */ ) { Word16 nb_subfr; @@ -820,31 +820,31 @@ void bpf_pitch_coherence_ivas_fx( SWITCH( st->L_frame ) { case 80: - scaled_inv_L_frame = 26843545; + scaled_inv_L_frame = 26843545; // 1/80 in Q31 move32(); BREAK; case 160: - scaled_inv_L_frame = 13421773; + scaled_inv_L_frame = 13421773; // 1/160 in Q31 move32(); BREAK; case 256: - scaled_inv_L_frame = 8388608; + scaled_inv_L_frame = 8388608; // 1/256 in Q31 move32(); BREAK; case 320: - scaled_inv_L_frame = 6710886; + scaled_inv_L_frame = 6710886; // 1/320 in Q31 move32(); BREAK; case 512: - scaled_inv_L_frame = 4194304; + scaled_inv_L_frame = 4194304; // 1/512 in Q31 move32(); BREAK; case 640: - scaled_inv_L_frame = 3355443; + scaled_inv_L_frame = 3355443; // 1/640 in Q31 move32(); BREAK; case 960: - scaled_inv_L_frame = 2236962; + scaled_inv_L_frame = 2236962; // 1/80 in Q31 move32(); BREAK; default: @@ -854,27 +854,27 @@ void bpf_pitch_coherence_ivas_fx( nb_subfr = shr( st->L_frame, 6 ); test(); - IF( GT_16( st->clas_dec, UNVOICED_CLAS ) && NE_16( st->element_mode, EVS_MONO ) ) + IF( GT_16( st->clas_dec, UNVOICED_CLAS ) && ( st->element_mode != EVS_MONO ) ) { pc = L_abs( L_sub( L_add( st->old_pitch_buf_fx[nb_subfr + 3], st->old_pitch_buf_fx[nb_subfr + 2] ), L_add( st->old_pitch_buf_fx[nb_subfr], st->old_pitch_buf_fx[nb_subfr + 1] ) ) ); pc = Mpy_32_32( pc, scaled_inv_L_frame ); pcn1 = L_add( Mpy_32_32( pc, K_PC_DEC_FX32 ), C_PC_DEC_FX ); - pcn1 = L_max( L_min( pcn1, 4096 ), 0 ); + pcn1 = L_max( L_min( pcn1, 4096 ), 0 ); // 4096 = 1 in Q12 pc = L_abs( L_sub( L_add( pitch_buf[nb_subfr - 1], pitch_buf[nb_subfr - 2] ), L_add( pitch_buf[1], pitch_buf[0] ) ) ); pc = Mpy_32_32( pc, scaled_inv_L_frame ); pcn2 = L_add( Mpy_32_32( pc, K_PC_DEC_FX32 ), C_PC_DEC_FX ); - pcn2 = L_max( L_min( pcn2, 4096 ), 0 ); + pcn2 = L_max( L_min( pcn2, 4096 ), 0 ); // 4096 = 1 in Q12 pc = L_abs( L_sub( L_add( st->old_pitch_buf_fx[nb_subfr + 3], st->old_pitch_buf_fx[nb_subfr + 2] ), L_add( pitch_buf[1], pitch_buf[0] ) ) ); pc = Mpy_32_32( pc, scaled_inv_L_frame ); pcn3 = L_add( Mpy_32_32( pc, K_PC_DEC_FX32 ), C_PC_DEC_FX ); - pcn3 = L_max( L_min( pcn3, 4096 ), 0 ); + pcn3 = L_max( L_min( pcn3, 4096 ), 0 ); // 4096 = 1 in Q12 - IF( LT_32( L_add( pcn1, L_add( pcn2, pcn3 ) ), 10240 ) ) + IF( LT_32( L_add( pcn1, L_add( pcn2, pcn3 ) ), 10240 /*2.5f in Q12*/ ) ) { - st->hBPF->psf_att_fx = 13107; - move16(); /*Q15*/ + st->hBPF->psf_att_fx = 13107; //.4 in Q15 + move16(); /*Q15*/ set16_fx( &st->hBPF->Track_on_hist[L_TRACK_HIST - nb_subfr], 1, nb_subfr ); } } diff --git a/lib_dec/ivas_mct_core_dec.c b/lib_dec/ivas_mct_core_dec.c index 3e95cbc53..8816f03ff 100644 --- a/lib_dec/ivas_mct_core_dec.c +++ b/lib_dec/ivas_mct_core_dec.c @@ -202,7 +202,7 @@ void ivas_mct_side_bits_fx( } /*read MCT data and calculate frame bits per channel */ - FOR( ch = 0; ch < shr( hMCT->nchan_out_woLFE, 1 ); ch++ ) + FOR( ch = 0; ch < hMCT->nchan_out_woLFE / 2; ch++ ) { initMdctStereoDecData_fx( hMCT->hBlockData[ch]->hStereoMdct, st0->igf, st0->hIGFDec->igfData.igfInfo.grid, hCPE[0]->element_brate, st0->bwidth ); } @@ -292,7 +292,7 @@ void ivas_mct_core_dec( MCT_DEC_HANDLE hMCT, /* i/o: MCT decoder structure */ CPE_DEC_HANDLE hCPE[MCT_MAX_BLOCKS], /* i/o: CPE decoder structure */ const Word16 nCPE, /* i : number of CPEs */ - Word32 *signal_out_fx[], + Word32 *signal_out_fx[], // q_x Word16 q_x[MCT_MAX_CHANNELS] ) { Word16 i, k, ch, cpe_id, nChannels; diff --git a/lib_dec/ivas_mct_dec.c b/lib_dec/ivas_mct_dec.c index f3221106d..197c9f2a9 100644 --- a/lib_dec/ivas_mct_dec.c +++ b/lib_dec/ivas_mct_dec.c @@ -292,7 +292,7 @@ ivas_error ivas_mct_dec( #else ivas_error ivas_mct_dec_fx( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ - Word32 *output_fx[], /* o : output synthesis signal */ + Word32 *output_fx[], /* o : output synthesis signal Q11*/ const Word16 output_frame, /* i : output frame length per channel */ const Word16 nb_bits_metadata /* i : number of metadata bits */ ) @@ -306,18 +306,18 @@ ivas_error ivas_mct_dec_fx( Word16 nTnsBitsTCX10[MCT_MAX_BLOCKS][CPE_CHANNELS][NB_DIV]; Word16 fUseTns[MCT_MAX_BLOCKS][CPE_CHANNELS][NB_DIV]; STnsData tnsData[MCT_MAX_BLOCKS][CPE_CHANNELS][NB_DIV]; - Word16 Aq_fx[MCT_MAX_BLOCKS][CPE_CHANNELS][( NB_SUBFR16k + 1 ) * ( M + 1 )]; + Word16 Aq_fx[MCT_MAX_BLOCKS][CPE_CHANNELS][( NB_SUBFR16k + 1 ) * ( M + 1 )]; // Q12 Word32 output_lfe_ch_fx[L_FRAME48k]; Word16 q_output = 11; Word16 n, k, i; - Word32 *x_fx[CPE_CHANNELS][NB_DIV]; + Word32 *x_fx[CPE_CHANNELS][NB_DIV]; //(Q(31 - x_e) Word16 x_e[MAX_CICP_CHANNELS][NB_DIV]; Word16 x_len[CPE_CHANNELS][NB_DIV]; set16_fx( x_len[0], 0, NB_DIV ); set16_fx( x_len[1], 0, NB_DIV ); Decoder_State **sts; - Word16 synth_fx[CPE_CHANNELS][L_FRAME_PLUS]; + Word16 synth_fx[CPE_CHANNELS][L_FRAME_PLUS]; //(Q_synth) Word32 ivas_total_brate; ivas_error error; Word16 e_sig[CPE_CHANNELS] = { 15, 15 }; @@ -342,7 +342,7 @@ ivas_error ivas_mct_dec_fx( IF( EQ_16( st_ivas->ivas_format, MC_FORMAT ) && ( EQ_16( st_ivas->mc_mode, MC_MODE_MCT ) || EQ_16( st_ivas->mc_mode, MC_MODE_PARAMUPMIX ) ) ) { /* save LFE channel */ - Copy32( output_fx[LFE_CHANNEL], output_lfe_ch_fx, output_frame ); + Copy32( output_fx[LFE_CHANNEL], output_lfe_ch_fx, output_frame ); // Q11 } IF( EQ_16( st_ivas->ivas_format, MC_FORMAT ) && EQ_16( st_ivas->mc_mode, MC_MODE_MCT ) && ( st_ivas->bfi == 0 ) ) @@ -406,11 +406,11 @@ ivas_error ivas_mct_dec_fx( FOR( n = 0; n < CPE_CHANNELS; n++ ) { - x_fx[n][0] = output_fx[add( n, shl( cpe_id, 1 /* * CPE_CHANNELS*/ ) )]; + x_fx[n][0] = output_fx[n + ( cpe_id * CPE_CHANNELS )]; // Q11 x_e[n][0] = 20; move16(); move16(); - x_fx[n][1] = output_fx[add( n, shl( cpe_id, 1 /* * CPE_CHANNELS*/ ) )] + ( L_FRAME48k / 2 ); + x_fx[n][1] = output_fx[n + ( cpe_id * CPE_CHANNELS )] + ( L_FRAME48k / 2 ); // Q11 x_e[n][1] = 20; move16(); move16(); @@ -436,7 +436,7 @@ ivas_error ivas_mct_dec_fx( move16(); FOR( k = 0; k < subFrames; ++k ) { - Scale_sig32( x_fx[ch][k], shr( L_FRAME48k, sub( subFrames, 1 ) ), sub( x_e[ch][k], 20 ) ); + Scale_sig32( x_fx[ch][k], shr( L_FRAME48k, sub( subFrames, 1 ) ), sub( x_e[ch][k], 20 ) ); // Scaling back to Q11 } } @@ -453,13 +453,13 @@ ivas_error ivas_mct_dec_fx( // Scaling output buffer to q_x FOR( i = 0; i < hMCT->nchan_out_woLFE; ++i ) { - Scale_sig32( output_fx[i], L_FRAME48k, sub( q_x[i], Q11 ) ); + Scale_sig32( output_fx[i], L_FRAME48k, sub( q_x[i], Q11 ) ); // Q11 -> Q12 } ivas_mct_core_dec( hMCT, st_ivas->hCPE, nCPE, output_fx, q_x ); // Scaling output buffer back to Q11 FOR( i = 0; i < hMCT->nchan_out_woLFE; ++i ) { - Scale_sig32( output_fx[i], L_FRAME48k, sub( Q11, q_x[i] ) ); + Scale_sig32( output_fx[i], L_FRAME48k, sub( Q11, q_x[i] ) ); // Q12 -> Q11 } @@ -485,9 +485,9 @@ ivas_error ivas_mct_dec_fx( FOR( n = 0; n < CPE_CHANNELS; n++ ) { - Copy_Scale_sig_16_32( Aq_fx[cpe_id][n], Aq_fx_32[cpe_id][n], 102, Q16 - Q12 ); - x_fx[n][0] = output_fx[add( n, shl( cpe_id, 1 /* * CPE_CHANNELS*/ ) )]; - x_fx[n][1] = output_fx[add( n, shl( cpe_id, 1 /* * CPE_CHANNELS*/ ) )] + ( L_FRAME48k / 2 ); + Copy_Scale_sig_16_32( Aq_fx[cpe_id][n], Aq_fx_32[cpe_id][n], 102, Q16 - Q12 ); // Q16 + x_fx[n][0] = output_fx[n + ( cpe_id * CPE_CHANNELS )]; // Q11 + x_fx[n][1] = output_fx[n + ( cpe_id * CPE_CHANNELS )] + ( L_FRAME48k / 2 ); // Q11 x_e[n][0] = 20; move16(); move16(); @@ -510,10 +510,10 @@ ivas_error ivas_mct_dec_fx( nSubFrames = NB_DIV; } move16(); - Scale_sig32( x_fx[ind][0], shr( L_FRAME48k, sub( nSubFrames, 1 ) ), sub( x_e[ind][0], 20 ) ); + Scale_sig32( x_fx[ind][0], shr( L_FRAME48k, sub( nSubFrames, 1 ) ), sub( x_e[ind][0], 20 ) ); // Q11 IF( EQ_16( nSubFrames, 2 ) ) { - Scale_sig32( x_fx[ind][1], shr( L_FRAME48k, 1 ), sub( x_e[ind][1], 20 ) ); + Scale_sig32( x_fx[ind][1], shr( L_FRAME48k, 1 ), sub( x_e[ind][1], 20 ) ); // Q11 } } } @@ -533,16 +533,16 @@ ivas_error ivas_mct_dec_fx( { set16_fx( x_all_e[i], 0, NB_DIV ); } - Word32 *x_all_fx[MAX_CICP_CHANNELS][NB_DIV]; + Word32 *x_all_fx[MAX_CICP_CHANNELS][NB_DIV]; //(Q(31 - x_all_e) FOR( cpe_id = 0; cpe_id < nCPE; cpe_id++ ) { FOR( n = 0; n < CPE_CHANNELS; n++ ) { - x_all_fx[add( n, shl( cpe_id, 1 /* * CPE_CHANNELS*/ ) )][0] = output_fx[add( n, shl( cpe_id, 1 /* * CPE_CHANNELS*/ ) )]; - x_all_fx[add( n, shl( cpe_id, 1 /* * CPE_CHANNELS*/ ) )][1] = output_fx[add( n, shl( cpe_id, 1 /* * CPE_CHANNELS*/ ) )] + ( L_FRAME48k / 2 ); - x_all_e[add( n, shl( cpe_id, 1 /* * CPE_CHANNELS*/ ) )][1] = 20; + x_all_fx[n + ( cpe_id * CPE_CHANNELS )][0] = output_fx[n + ( cpe_id * CPE_CHANNELS )]; // Q11 + x_all_fx[n + ( cpe_id * CPE_CHANNELS )][1] = output_fx[n + ( cpe_id * CPE_CHANNELS )] + ( L_FRAME48k / 2 ); // Q11 + x_all_e[n + ( cpe_id * CPE_CHANNELS )][1] = 20; move16(); - x_all_e[add( n, shl( cpe_id, 1 /* * CPE_CHANNELS*/ ) )][0] = 20; + x_all_e[n + ( cpe_id * CPE_CHANNELS )][0] = 20; move16(); } } @@ -553,8 +553,8 @@ ivas_error ivas_mct_dec_fx( { FOR( n = 0; n < CPE_CHANNELS; n++ ) { - Scale_sig32( x_all_fx[add( n, shl( cpe_id, 1 /* * CPE_CHANNELS*/ ) )][0], ( L_FRAME48k / 2 ), sub( x_all_e[add( n, shl( cpe_id, 1 /* * CPE_CHANNELS*/ ) )][0], 20 ) ); - Scale_sig32( x_all_fx[add( n, shl( cpe_id, 1 /* * CPE_CHANNELS*/ ) )][1], ( L_FRAME48k / 2 ), sub( x_all_e[add( n, shl( cpe_id, 1 /* * CPE_CHANNELS*/ ) )][1], 20 ) ); + Scale_sig32( x_all_fx[n + ( cpe_id * CPE_CHANNELS )][0], ( L_FRAME48k / 2 ), sub( x_all_e[n + ( cpe_id * CPE_CHANNELS )][0], 20 ) ); // Q11 + Scale_sig32( x_all_fx[n + ( cpe_id * CPE_CHANNELS )][1], ( L_FRAME48k / 2 ), sub( x_all_e[n + ( cpe_id * CPE_CHANNELS )][1], 20 ) ); // Q11 } } } @@ -566,8 +566,8 @@ ivas_error ivas_mct_dec_fx( FOR( n = 0; n < CPE_CHANNELS; n++ ) { - x_fx[n][0] = output_fx[add( n, shl( cpe_id, 1 /* * CPE_CHANNELS*/ ) )]; - x_fx[n][1] = output_fx[add( n, shl( cpe_id, 1 /* * CPE_CHANNELS*/ ) )] + ( L_FRAME48k / 2 ); + x_fx[n][0] = output_fx[n + ( cpe_id * CPE_CHANNELS )]; // Q11 + x_fx[n][1] = output_fx[n + ( cpe_id * CPE_CHANNELS )] + ( L_FRAME48k / 2 ); // Q11 } Copy_Scale_sig_16_32( hCPE->hCoreCoder[0]->old_Aq_12_8_fx, hCPE->hCoreCoder[0]->old_Aq_12_8_fx_32, add( M, 1 ), sub( 28, norm_s( sub( hCPE->hCoreCoder[0]->old_Aq_12_8_fx[0], 1 ) ) ) ); @@ -616,11 +616,11 @@ ivas_error ivas_mct_dec_fx( IF( ( st_ivas->sba_dirac_stereo_flag != 0 ) && ( NE_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) || GE_16( cpe_id, sub( nCPE, 2 ) ) ) ) { - Copy_Scale_sig_16_32( synth_fx[n], synth_fx_32[n], L_FRAME48k, Q11 - 0 ); + Copy_Scale_sig_16_32( synth_fx[n], synth_fx_32[n], L_FRAME48k, Q11 - 0 ); // Q11 Copy_Scale_sig_16_32( hCPE->hCoreCoder[n]->hHQ_core->old_out_fx, hCPE->hCoreCoder[n]->hHQ_core->oldOut_fx, output_frame, sub( Q11, hCPE->hCoreCoder[n]->hHQ_core->Q_old_wtda ) ); ivas_post_proc_fx( NULL, hCPE, n, synth_fx_32[n], NULL, output_frame, 1, Q11 ); #ifdef MSAN_FIX - Copy_Scale_sig_32_16( synth_fx_32[n], synth_fx[n], output_frame, 0 - Q11 ); + Copy_Scale_sig_32_16( synth_fx_32[n], synth_fx[n], output_frame, 0 - Q11 ); // Q0 #else Copy_Scale_sig_32_16( synth_fx_32[n], synth_fx[n], L_FRAME48k, 0 - Q11 ); #endif @@ -650,25 +650,25 @@ ivas_error ivas_mct_dec_fx( { dirac_stereo_flag = 0; } - IF( NE_32( ( error = core_switching_post_dec_ivas_fx( sts[n], synth_fx[n], output_fx[add( shl( cpe_id, 1 /* * CPE_CHANNELS*/ ), n )], output_mem_fx, st_ivas->ivas_format, 0, output_frame, 0 /*core_switching_flag*/, dirac_stereo_flag, -1, hCPE->last_element_mode, &Q_synth ) ), IVAS_ERR_OK ) ) + IF( NE_32( ( error = core_switching_post_dec_ivas_fx( sts[n], synth_fx[n], output_fx[( cpe_id * CPE_CHANNELS ) + n], output_mem_fx, st_ivas->ivas_format, 0, output_frame, 0 /*core_switching_flag*/, dirac_stereo_flag, -1, hCPE->last_element_mode, &Q_synth ) ), IVAS_ERR_OK ) ) { return error; } - Copy_Scale_sig_16_32( synth_fx[n], output_fx[add( shl( cpe_id, 1 /* * CPE_CHANNELS*/ ), n )], output_frame, sub( Q11, Q_synth ) ); + Copy_Scale_sig_16_32( synth_fx[n], output_fx[( cpe_id * CPE_CHANNELS ) + n], output_frame, sub( Q11, Q_synth ) ); // Q11 /* Save synthesis for HQ FEC */ Word32 output_fx_[L_FRAME48k]; - Copy32( output_fx[add( shl( cpe_id, 1 /* * CPE_CHANNELS*/ ), n )], output_fx_, L_FRAME48k ); - Scale_sig32( output_fx_, L_FRAME48k, Q16 - Q11 ); - Copy_Scale_sig32_16( sts[n]->prev_synth_buffer32_fx, sts[n]->prev_synth_buffer_fx, NS2SA( 48000, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS ), -11 ); + Copy32( output_fx[( cpe_id * CPE_CHANNELS ) + n], output_fx_, L_FRAME48k ); // Q11 + Scale_sig32( output_fx_, L_FRAME48k, Q16 - Q11 ); // Q11 -> Q16 + Copy_Scale_sig32_16( sts[n]->prev_synth_buffer32_fx, sts[n]->prev_synth_buffer_fx, NS2SA( 48000, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS ), -11 ); // Q11 -> Q0 sts[n]->q_prev_synth_buffer_fx = 0; move16(); save_synthesis_hq_fec_fx( sts[n], output_fx_, output_frame, hCPE ); /* CoreCoder common updates */ - ivas_updt_dec_common_fx( hCPE->hCoreCoder[n], NORMAL_HQ_CORE, -1, output_fx[add( shl( cpe_id, 1 /* * CPE_CHANNELS*/ ), n )], 11 ); + ivas_updt_dec_common_fx( hCPE->hCoreCoder[n], NORMAL_HQ_CORE, -1, output_fx[( cpe_id * CPE_CHANNELS ) + n], 11 ); } /* n_channels loop */ @@ -676,7 +676,7 @@ ivas_error ivas_mct_dec_fx( { IF( hCPE->hCoreCoder[n] ) { - Copy_Scale_sig_16_32( hCPE->hCoreCoder[n]->delay_buf_out_fx, hCPE->hCoreCoder[n]->delay_buf_out32_fx, HQ_DELTA_MAX * HQ_DELAY_COMP, Q11 ); + Copy_Scale_sig_16_32( hCPE->hCoreCoder[n]->delay_buf_out_fx, hCPE->hCoreCoder[n]->delay_buf_out32_fx, HQ_DELTA_MAX * HQ_DELAY_COMP, Q11 ); // Q0 -> Q11 } } @@ -697,16 +697,16 @@ ivas_error ivas_mct_dec_fx( Word32 tmp[L_FRAME48k]; /*save center channel output*/ - Copy32( output_fx[sub( hMCT->nchan_out_woLFE, 1 )], tmp, output_frame ); + Copy32( output_fx[hMCT->nchan_out_woLFE - 1], tmp, output_frame ); // Q11 - FOR( n = sub( hMCT->nchan_out_woLFE, 1 ); n >= LFE_CHANNEL; n-- ) + FOR( n = hMCT->nchan_out_woLFE - 1; n >= LFE_CHANNEL; n-- ) { - Copy32( output_fx[sub( n, 1 )], output_fx[add( n, 1 )], output_frame ); + Copy32( output_fx[n - 1], output_fx[n + 1], output_frame ); // Q11 } - Copy32( tmp, output_fx[sub( LFE_CHANNEL, 1 )], output_frame ); + Copy32( tmp, output_fx[LFE_CHANNEL - 1], output_frame ); // Q11 /* save LFE channel */ - Copy32( output_lfe_ch_fx, output_fx[LFE_CHANNEL], output_frame ); + Copy32( output_lfe_ch_fx, output_fx[LFE_CHANNEL], output_frame ); // Q11 } pop_wmops(); @@ -794,7 +794,7 @@ ivas_error create_mct_dec_fx( /* in case we have an uneven number of transport channels, indicate last channel ID as inactive */ if ( hMCT->nchan_out_woLFE % 2 ) { - st_ivas->hCPE[sub( st_ivas->nCPE, 1 )]->hCoreCoder[1]->mct_chan_mode = MCT_CHAN_MODE_IGNORE; + st_ivas->hCPE[st_ivas->nCPE - 1]->hCoreCoder[1]->mct_chan_mode = MCT_CHAN_MODE_IGNORE; move32(); } @@ -827,7 +827,7 @@ ivas_error create_mct_dec_fx( hMCT->hBlockData[n]->hStereoMdct->reverse_dmx = 0; move16(); move16(); - hMCT->hBlockData[n]->hStereoMdct->smooth_ratio_fx = ONE_IN_Q26; + hMCT->hBlockData[n]->hStereoMdct->smooth_ratio_fx = ONE_IN_Q26; // Q26 move32(); } FOR( ; n < MCT_MAX_BLOCKS; n++ ) @@ -1442,7 +1442,7 @@ ivas_error ivas_mc_dec_config_fx( { FOR( Word16 i = 0; i < 4; i++ ) { - st_ivas->hRenderConfig->directivity_fx[add( imult1616( i, 3 ), 2 )] = shl_sat( st_ivas->hRenderConfig->directivity_fx[add( imult1616( i, 3 ), 2 )], 9 ); + st_ivas->hRenderConfig->directivity_fx[( i * 3 ) + 2] = shl_sat( st_ivas->hRenderConfig->directivity_fx[( i * 3 ) + 2], 9 ); // Q15 move16(); } } @@ -1454,7 +1454,7 @@ ivas_error ivas_mc_dec_config_fx( { FOR( Word16 i = 0; i < 4; i++ ) { - st_ivas->hRenderConfig->directivity_fx[add( imult1616( i, 3 ), 2 )] = shr( st_ivas->hRenderConfig->directivity_fx[add( imult1616( i, 3 ), 2 )], 9 ); + st_ivas->hRenderConfig->directivity_fx[( i * 3 ) + 2] = shr( st_ivas->hRenderConfig->directivity_fx[( i * 3 ) + 2], 9 ); // Q15 move16(); } } diff --git a/lib_dec/ivas_mct_dec_mct_fx.c b/lib_dec/ivas_mct_dec_mct_fx.c index d6e5b6865..0f9bd98cc 100644 --- a/lib_dec/ivas_mct_dec_mct_fx.c +++ b/lib_dec/ivas_mct_dec_mct_fx.c @@ -239,7 +239,7 @@ void apply_MCT_dec_fx( Word16 pair; MCT_DEC_BLOCK_DATA_HANDLE hBlock; - FOR( pair = sub( hMCT->currBlockDataCnt, 1 ); pair >= 0; pair-- ) + FOR( pair = hMCT->currBlockDataCnt - 1; pair >= 0; pair-- ) { hBlock = hMCT->hBlockData[pair]; @@ -260,7 +260,7 @@ void apply_MCT_dec_fx( void mctStereoIGF_dec_fx( MCT_DEC_HANDLE hMCT, /* i/o: MCT decoder structure */ Decoder_State **stm, /* i/o: decoder state structure */ - Word32 *x[MCT_MAX_CHANNELS][NB_DIV], /* i/o: decoded and dequantized spectrum*/ + Word32 *x[MCT_MAX_CHANNELS][NB_DIV], /* i/o: decoded and dequantized spectrum i:Q12*/ const Word16 bfi /* i : bad frame flag */ ) { @@ -272,7 +272,7 @@ void mctStereoIGF_dec_fx( Word16 L_spec[CPE_CHANNELS]; Word16 L_frame[CPE_CHANNELS]; Word16 L_frameTCX[CPE_CHANNELS]; - Word32 *p_x[CPE_CHANNELS][NB_DIV]; + Word32 *p_x[CPE_CHANNELS][NB_DIV]; // Q(31 - p_x_e) Word16 p_x_e[CPE_CHANNELS][NB_DIV]; Word16 p_x_len[CPE_CHANNELS][NB_DIV]; Word16 singleChEle[MCT_MAX_CHANNELS]; @@ -305,13 +305,13 @@ void mctStereoIGF_dec_fx( move16(); // Using input Q-factor as 12 - set16_fx( p_x_e[0], 31 - Q12, CPE_CHANNELS ); - set16_fx( p_x_e[1], 31 - Q12, CPE_CHANNELS ); + set16_fx( p_x_e[0], 31 - Q12, CPE_CHANNELS ); // Q12 + set16_fx( p_x_e[1], 31 - Q12, CPE_CHANNELS ); // Q12 FOR( k = 0; k < nSubframes; k++ ) { - p_x[0][k] = x[ch1][k]; - p_x[1][k] = x[ch2][k]; + p_x[0][k] = x[ch1][k]; // Q12 + p_x[1][k] = x[ch2][k]; // Q12 test(); IF( NE_16( hMCT->hBlockData[b]->hStereoMdct->IGFStereoMode[k], SMDCT_DUAL_MONO ) || NE_16( hMCT->hBlockData[b]->hStereoMdct->mdct_stereo_mode[k], SMDCT_DUAL_MONO ) ) diff --git a/lib_dec/ivas_mdct_core_dec.c b/lib_dec/ivas_mdct_core_dec.c index 777d18f5c..90cb85cc3 100644 --- a/lib_dec/ivas_mdct_core_dec.c +++ b/lib_dec/ivas_mdct_core_dec.c @@ -722,7 +722,7 @@ void ivas_mdct_dec_side_bits_frame_channel_fx( FOR( Word16 n = 0; n < nSubframes; ++n ) { - const Word16 is_side = (Word16) L_and( EQ_16( ch, 1 ), EQ_16( param_lpc[0][n], SNS_STEREO_MODE_MS ) ); + const Word16 is_side = extract_l( L_and( EQ_16( ch, 1 ), EQ_16( param_lpc[0][n], SNS_STEREO_MODE_MS ) ) ); const Word16 *bits; Word16 nStages; IF( EQ_16( nSubframes, 1 ) ) @@ -736,6 +736,7 @@ void ivas_mdct_dec_side_bits_frame_channel_fx( nStages = SNS_MSVQ_NSTAGES_TCX10; } move16(); + move16(); IF( is_side ) { /* check for zero-side flag */ @@ -753,6 +754,7 @@ void ivas_mdct_dec_side_bits_frame_channel_fx( { bits = ivas_sns_cdbks_side_tcx10_bits; } + move16(); } FOR( Word16 j = 0; j < nStages; ++j ) @@ -1029,7 +1031,7 @@ void ivas_mdct_core_invQ_fx( Word32 *x[CPE_CHANNELS][NB_DIV], /* i/o: signal buffer */ Word16 x_e[CPE_CHANNELS][NB_DIV], Word16 x_len[CPE_CHANNELS][NB_DIV], - Word16 Aq[CPE_CHANNELS][( NB_SUBFR16k + 1 ) * ( M + 1 )], /* i : LP coefficients */ + Word16 Aq[CPE_CHANNELS][( NB_SUBFR16k + 1 ) * ( M + 1 )], /* i : LP coefficients Q12*/ Word16 ms_mask[NB_DIV][MAX_SFB], /* i : M/S mask */ const Word16 MCT_flag /* i : hMCT handle allocated (1) or not (0) */ ) @@ -1044,7 +1046,7 @@ void ivas_mdct_core_invQ_fx( Word16 Aind[CPE_CHANNELS][M + 1]; Word32 sns[CPE_CHANNELS][NB_DIV][M]; /* TCX */ - Word16 xn_buf[L_MDCT_OVLP_MAX + L_FRAME_PLUS + L_MDCT_OVLP_MAX]; + Word16 xn_buf[L_MDCT_OVLP_MAX + L_FRAME_PLUS + L_MDCT_OVLP_MAX]; // Q14 Word16 tcx_offset[CPE_CHANNELS]; Word16 tcx_offsetFB[CPE_CHANNELS]; Word16 left_rect[CPE_CHANNELS]; @@ -1142,8 +1144,8 @@ void ivas_mdct_core_invQ_fx( stereo_decoder_tcx_fx( hCPE->hStereoMdct, ms_mask, x_0[1], &spectralData_tmp[0], &spectralData_tmp[1], &hCPE->hStereoMdct->mdct_stereo_mode[0], sts[0]->core, sts[1]->core, sts[0]->igf, L_frameTCX[0], L_frameTCX[1], 0, sts[0]->last_core, sts[1]->last_core, 1, &q_r, &q_l ); #ifdef MSAN_FIX - Copy_Scale_sig_32_16( spectralData_tmp[0], sts[0]->hTonalMDCTConc->lastBlockData.spectralData, L_frameTCX[0], -15 ); - Copy_Scale_sig_32_16( spectralData_tmp[1], sts[1]->hTonalMDCTConc->lastBlockData.spectralData, L_frameTCX[1], -15 ); + Copy_Scale_sig_32_16( spectralData_tmp[0], sts[0]->hTonalMDCTConc->lastBlockData.spectralData, L_frameTCX[0], -15 ); // q_l - 15 + Copy_Scale_sig_32_16( spectralData_tmp[1], sts[1]->hTonalMDCTConc->lastBlockData.spectralData, L_frameTCX[1], -15 ); // q_r - 15 #else Copy_Scale_sig_32_16( spectralData_tmp[0], sts[0]->hTonalMDCTConc->lastBlockData.spectralData, L_FRAME_MAX, -15 ); Copy_Scale_sig_32_16( spectralData_tmp[1], sts[1]->hTonalMDCTConc->lastBlockData.spectralData, L_FRAME_MAX, -15 ); @@ -1298,8 +1300,8 @@ void ivas_mdct_core_invQ_fx( } } - Copy( tmp_ms_sig[0], sts[0]->hTonalMDCTConc->lastBlockData.spectralData, L_frameTCX[0] ); - Copy( tmp_ms_sig[1], sts[1]->hTonalMDCTConc->lastBlockData.spectralData, L_frameTCX[0] ); + Copy( tmp_ms_sig[0], sts[0]->hTonalMDCTConc->lastBlockData.spectralData, L_frameTCX[0] ); // Q(15 - tmp_ms_sig_e) + Copy( tmp_ms_sig[1], sts[1]->hTonalMDCTConc->lastBlockData.spectralData, L_frameTCX[0] ); // Q(15 - tmp_ms_sig_e) sts[0]->hTonalMDCTConc->lastBlockData.spectralData_exp = tmp_ms_sig_e[0]; move16(); sts[1]->hTonalMDCTConc->lastBlockData.spectralData_exp = tmp_ms_sig_e[1]; @@ -1990,14 +1992,14 @@ void ivas_mdct_core_reconstruct_fx( Word16 q_win = -2; move16(); /* TCX */ - Word16 xn_buf_fx[L_MDCT_OVLP_MAX + L_FRAME_PLUS + L_MDCT_OVLP_MAX]; + Word16 xn_buf_fx[L_MDCT_OVLP_MAX + L_FRAME_PLUS + L_MDCT_OVLP_MAX]; // Q(-2) Word16 tcx_offset[CPE_CHANNELS]; Word16 tcx_offsetFB[CPE_CHANNELS]; Word16 left_rect[CPE_CHANNELS]; Word16 L_spec[CPE_CHANNELS]; Word16 pitch[CPE_CHANNELS][NB_SUBFR16k]; - Word16 pit_gain_fx[CPE_CHANNELS][NB_SUBFR16k]; + Word16 pit_gain_fx[CPE_CHANNELS][NB_SUBFR16k]; // Q14 Word16 skip_decoding, sf; set16_fx( xn_buf_fx, 0, L_MDCT_OVLP_MAX + L_FRAME_PLUS + L_MDCT_OVLP_MAX ); @@ -2052,21 +2054,21 @@ void ivas_mdct_core_reconstruct_fx( set16_fx( synthFB_fx, 0, L_FRAME_PLUS + M ); IF( st->core != ACELP_CORE ) { - Scale_sig( st->hTcxDec->syn_Overl_TDACFB, L_FRAME_MAX / 2, sub( q_win, st->hTcxDec->Q_syn_Overl_TDACFB ) ); - Scale_sig( st->hTcxDec->syn_Overl_TDAC, L_FRAME32k / 2, sub( q_win, st->hTcxDec->Q_syn_Overl_TDAC ) ); - Scale_sig( st->hTcxDec->old_syn_Overl, L_FRAME32k / 2, sub( q_win, sub( -1, st->Q_syn ) ) ); - Scale_sig( st->hTcxDec->syn_Overl, L_FRAME32k / 2, sub( q_win, st->Q_syn ) ); - Scale_sig( st->hTcxDec->syn_OverlFB, L_FRAME_MAX / 2, sub( q_win, st->Q_syn ) ); - Scale_sig( st->hHQ_core->old_out_LB_fx, L_FRAME32k, sub( q_win, st->hHQ_core->Q_old_wtda_LB ) ); - Scale_sig( st->hHQ_core->old_out_fx, L_FRAME48k, sub( q_win, st->hHQ_core->Q_old_wtda ) ); + Scale_sig( st->hTcxDec->syn_Overl_TDACFB, L_FRAME_MAX / 2, sub( q_win, st->hTcxDec->Q_syn_Overl_TDACFB ) ); // st->hTcxDec->Q_syn_Overl_TDACFB -> q_win + Scale_sig( st->hTcxDec->syn_Overl_TDAC, L_FRAME32k / 2, sub( q_win, st->hTcxDec->Q_syn_Overl_TDAC ) ); // st->hTcxDec->Q_syn_Overl_TDAC -> q_win + Scale_sig( st->hTcxDec->old_syn_Overl, L_FRAME32k / 2, sub( q_win, sub( -1, st->Q_syn ) ) ); // Q(-1 - st->Q_syn) -> q_win + Scale_sig( st->hTcxDec->syn_Overl, L_FRAME32k / 2, sub( q_win, st->Q_syn ) ); // Q(st->Q_syn) -> q_win + Scale_sig( st->hTcxDec->syn_OverlFB, L_FRAME_MAX / 2, sub( q_win, st->Q_syn ) ); // Q(st->Q_syn) -> q_win + Scale_sig( st->hHQ_core->old_out_LB_fx, L_FRAME32k, sub( q_win, st->hHQ_core->Q_old_wtda_LB ) ); // Q(st->hHQ_core->Q_old_wtda_LB) -> q_win + Scale_sig( st->hHQ_core->old_out_fx, L_FRAME48k, sub( q_win, st->hHQ_core->Q_old_wtda ) ); // Q(st->hHQ_core->Q_old_wtda) -> q_win #ifdef MSAN_FIX - Scale_sig( synth_buf_fx, add( add( st->hTcxDec->old_synth_len, L_FRAME_PLUS ), M ), sub( q_win, q_syn ) ); - Scale_sig( synth_bufFB_fx, add( add( st->hTcxDec->old_synth_lenFB, L_FRAME_PLUS ), M ), sub( q_win, q_syn ) ); + Scale_sig( synth_buf_fx, add( add( st->hTcxDec->old_synth_len, L_FRAME_PLUS ), M ), sub( q_win, q_syn ) ); // q_syn -> q_win + Scale_sig( synth_bufFB_fx, add( add( st->hTcxDec->old_synth_lenFB, L_FRAME_PLUS ), M ), sub( q_win, q_syn ) ); // q_syn -> q_win #else Scale_sig( synth_buf_fx, 3136, sub( q_win, q_syn ) ); Scale_sig( synth_bufFB_fx, 3136, sub( q_win, q_syn ) ); #endif - Scale_sig( st->syn, M + 1, sub( q_win, st->Q_syn ) ); + Scale_sig( st->syn, M + 1, sub( q_win, st->Q_syn ) ); // st->Q_syn -> q_win FOR( k = 0; k < nSubframes[ch]; k++ ) { init_tcx_info_fx( st, L_frame_global[ch], L_frame_globalTCX[ch], k, bfi, &tcx_offset[ch], @@ -2079,18 +2081,18 @@ void ivas_mdct_core_reconstruct_fx( IF( ( EQ_16( hCPE->nchan_out, 1 ) && EQ_16( st->hTcxDec->kernel_type[k], MDST_IV ) ) || EQ_16( st->hTcxCfg->tcx_last_overlap_mode, TRANSITION_OVERLAP ) ) { decoder_tcx_imdct_fx( st, L_frame_global[ch], L_frame_globalTCX[ch], L_spec[ch], tcx_offset[ch], tcx_offsetFB[ch], L_frame[ch], L_frameTCX[ch], left_rect[ch], x_fx[ch][k], q_x, xn_buf_fx, q_win, - MDCT_IV, fUseTns[ch][k], &synth_fx[L_mult0( k, L_frame[ch] )], &synthFB_fx[L_mult0( k, L_frameTCX[ch] )], bfi, k, 0 ); + MDCT_IV, fUseTns[ch][k], &synth_fx[k * L_frame[ch]], &synthFB_fx[k * L_frameTCX[ch]], bfi, k, 0 ); } ELSE { decoder_tcx_imdct_fx( st, L_frame_global[ch], L_frame_globalTCX[ch], L_spec[ch], tcx_offset[ch], tcx_offsetFB[ch], L_frame[ch], L_frameTCX[ch], left_rect[ch], x_fx[ch][k], q_x, xn_buf_fx, q_win, - st->hTcxDec->kernel_type[k], fUseTns[ch][k], &synth_fx[L_mult0( k, L_frame[ch] )], &synthFB_fx[L_mult0( k, L_frameTCX[ch] )], bfi, k, 0 ); + st->hTcxDec->kernel_type[k], fUseTns[ch][k], &synth_fx[k * L_frame[ch]], &synthFB_fx[k * L_frameTCX[ch]], bfi, k, 0 ); } } ELSE { - set16_fx( &synth_fx[L_mult0( k, L_frame[ch] )], 0, L_frame[ch] ); - set16_fx( &synthFB_fx[L_mult0( k, L_frame[ch] )], 0, L_frameTCX[ch] ); + set16_fx( &synth_fx[k * L_frame[ch]], 0, L_frame[ch] ); + set16_fx( &synthFB_fx[k * L_frame[ch]], 0, L_frameTCX[ch] ); } } @@ -2115,25 +2117,26 @@ void ivas_mdct_core_reconstruct_fx( { st->Q_syn = add( q_win, sf ); } - Scale_sig( st->hTcxDec->syn_Overl_TDACFB, L_FRAME_MAX / 2, sub( sub( -1, st->Q_syn ), q_win ) ); + + Scale_sig( st->hTcxDec->syn_Overl_TDACFB, L_FRAME_MAX / 2, sub( sub( -1, st->Q_syn ), q_win ) ); // q_win -> Q(-1 - st->Q_syn) st->hTcxDec->Q_syn_Overl_TDACFB = sub( -1, st->Q_syn ); move16(); - Scale_sig( st->hTcxDec->syn_Overl_TDAC, L_FRAME32k / 2, sub( sub( -1, st->Q_syn ), q_win ) ); + Scale_sig( st->hTcxDec->syn_Overl_TDAC, L_FRAME32k / 2, sub( sub( -1, st->Q_syn ), q_win ) ); // q_win -> Q(-1 - st->Q_syn) st->hTcxDec->Q_syn_Overl_TDAC = sub( -1, st->Q_syn ); move16(); - Scale_sig( st->hTcxDec->old_syn_Overl, L_FRAME32k / 2, sub( sub( -1, st->Q_syn ), q_win ) ); + Scale_sig( st->hTcxDec->old_syn_Overl, L_FRAME32k / 2, sub( sub( -1, st->Q_syn ), q_win ) ); // q_win -> Q(-1 - st->Q_syn) #ifdef MSAN_FIX - Scale_sig( synth_buf_fx, add( add( st->hTcxDec->old_synth_len, L_FRAME_PLUS ), M ), sub( q_syn, q_win ) ); - Scale_sig( synth_bufFB_fx, add( add( st->hTcxDec->old_synth_lenFB, L_FRAME_PLUS ), M ), sub( q_syn, q_win ) ); + Scale_sig( synth_buf_fx, add( add( st->hTcxDec->old_synth_len, L_FRAME_PLUS ), M ), sub( q_syn, q_win ) ); // q_win -> q_syn + Scale_sig( synth_bufFB_fx, add( add( st->hTcxDec->old_synth_lenFB, L_FRAME_PLUS ), M ), sub( q_syn, q_win ) ); // q_win -> q_syn #else Scale_sig( synth_buf_fx, 3136, sub( q_syn, q_win ) ); Scale_sig( synth_bufFB_fx, 3136, sub( q_syn, q_win ) ); #endif Scale_sig( st->syn, M + 1, add( st->Q_syn, 2 ) ); - Scale_sig( st->hTcxDec->syn_OverlFB, L_FRAME_MAX / 2, sub( st->Q_syn, q_win ) ); - Scale_sig( st->hTcxDec->syn_Overl, L_FRAME32k / 2, sub( st->Q_syn, q_win ) ); - Scale_sig( st->hHQ_core->old_out_LB_fx, L_FRAME32k, sub( st->Q_syn, q_win ) ); - Scale_sig( st->hHQ_core->old_out_fx, L_FRAME48k, sub( st->Q_syn, q_win ) ); + Scale_sig( st->hTcxDec->syn_OverlFB, L_FRAME_MAX / 2, sub( st->Q_syn, q_win ) ); // q_win -> st->Q_syn + Scale_sig( st->hTcxDec->syn_Overl, L_FRAME32k / 2, sub( st->Q_syn, q_win ) ); // q_win -> st->Q_syn + Scale_sig( st->hHQ_core->old_out_LB_fx, L_FRAME32k, sub( st->Q_syn, q_win ) ); // q_win -> st->Q_syn + Scale_sig( st->hHQ_core->old_out_fx, L_FRAME48k, sub( st->Q_syn, q_win ) ); // q_win -> st->Q_syn st->hHQ_core->Q_old_wtda = st->Q_syn; move16(); st->hHQ_core->Q_old_wtda_LB = st->Q_syn; @@ -2142,15 +2145,15 @@ void ivas_mdct_core_reconstruct_fx( ELSE /*ACELP core for ACELP-PLC */ { assert( EQ_16( st->bfi, 1 ) ); - Scale_sig( synth_buf_fx, add( add( st->hTcxDec->old_synth_len, L_FRAME_PLUS ), M ), negate( q_syn ) ); - Scale_sig( synth_bufFB_fx, add( add( st->hTcxDec->old_synth_lenFB, L_FRAME_PLUS ), M ), negate( q_syn ) ); + Scale_sig( synth_buf_fx, add( add( st->hTcxDec->old_synth_len, L_FRAME_PLUS ), M ), negate( q_syn ) ); // Q0 + Scale_sig( synth_bufFB_fx, add( add( st->hTcxDec->old_synth_lenFB, L_FRAME_PLUS ), M ), negate( q_syn ) ); // Q0 q_syn = 0; move16(); move16(); /* PLC: [TCX: TD PLC] */ IF( MCT_flag != 0 ) { - con_tcx_ivas_fx( st, &synthFB_fx[0], -16384, NULL, 0, NULL ); + con_tcx_ivas_fx( st, &synthFB_fx[0], -16384, NULL, 0, NULL ); //-1.Q14 = -16384 } ELSE { @@ -2164,14 +2167,14 @@ void ivas_mdct_core_reconstruct_fx( } } - Scale_sig( synthFB_fx, st->hTcxDec->L_frameTCX, q_syn ); + Scale_sig( synthFB_fx, st->hTcxDec->L_frameTCX, q_syn ); // q_syn IF( ( EQ_16( st->nbLostCmpt, 1 ) ) || ( st->hTcxDec->tcxConceal_recalc_exc != 0 ) ) { - Scale_sig( synthFB_fx - add( add( shr( st->hTcxDec->L_frameTCX, 1 ), st->hTcxDec->pit_max_TCX ), 2 * M ), add( add( shr( st->hTcxDec->L_frameTCX, 1 ), st->hTcxDec->pit_max_TCX ), 2 * M ), sub( q_syn, sub( st->Q_exc, 1 ) ) ); + Scale_sig( synthFB_fx - add( add( shr( st->hTcxDec->L_frameTCX, 1 ), st->hTcxDec->pit_max_TCX ), 2 * M ), add( add( shr( st->hTcxDec->L_frameTCX, 1 ), st->hTcxDec->pit_max_TCX ), 2 * M ), sub( q_syn, sub( st->Q_exc, 1 ) ) ); // 2 * q_syn - (st->Q_exc - 1) } ELSE { - Scale_sig( synthFB_fx - st->hTcxDec->L_frameTCX, st->hTcxDec->L_frameTCX, sub( q_syn, sub( st->Q_exc, 1 ) ) ); + Scale_sig( synthFB_fx - st->hTcxDec->L_frameTCX, st->hTcxDec->L_frameTCX, sub( q_syn, sub( st->Q_exc, 1 ) ) ); // 2 * q_syn - (st->Q_exc - 1) } lerp( synthFB_fx, synth_fx, st->L_frame, st->hTcxDec->L_frameTCX ); @@ -2217,7 +2220,7 @@ void ivas_mdct_core_reconstruct_fx( st->hTcxDec->q_synth_history_fx = st->hTcxDec->q_old_synth; move16(); move16(); - Scale_sig( st->hTcxDec->old_synthFB_fx, st->hTcxDec->old_synth_lenFB, sub( st->Q_syn, q_syn ) ); + Scale_sig( st->hTcxDec->old_synthFB_fx, st->hTcxDec->old_synth_lenFB, sub( st->Q_syn, q_syn ) ); // st->Q_syn IF( st->hHQ_core != NULL ) { Copy( st->hHQ_core->old_out_fx + NS2SA( st->output_Fs, N_ZERO_MDCT_NS ), st->hTcxDec->old_synthFB_fx + st->hTcxDec->old_synth_lenFB, NS2SA( st->output_Fs, PH_ECU_LOOKAHEAD_NS ) ); @@ -2232,14 +2235,14 @@ void ivas_mdct_core_reconstruct_fx( Word16 x_fx_16[1200]; IF( st->p_bpf_noise_buf_32 ) { - Copy_Scale_sig_32_16( st->p_bpf_noise_buf_32, st->p_bpf_noise_buf, st->L_frame, -Q11 ); + Copy_Scale_sig_32_16( st->p_bpf_noise_buf_32, st->p_bpf_noise_buf, st->L_frame, -Q11 ); // Q11 -> Q0 } post_decoder_ivas_fx( st, synth_buf_fx, pit_gain_fx[ch], pitch[ch], x_fx_16, st->p_bpf_noise_buf ); IF( st->p_bpf_noise_buf_32 ) { - Copy_Scale_sig_16_32_no_sat( st->p_bpf_noise_buf, st->p_bpf_noise_buf_32, st->L_frame, Q11 ); + Copy_Scale_sig_16_32_no_sat( st->p_bpf_noise_buf, st->p_bpf_noise_buf_32, st->L_frame, Q11 ); // Q0 -> Q11 } IF( signal_outFB_fx[ch] != NULL ) { @@ -2254,7 +2257,7 @@ void ivas_mdct_core_reconstruct_fx( st->last_coder_type = st->coder_type; move16(); - Copy_Scale_sig_16_32( x_fx_16, x_fx[ch][0], st->L_frame, sub( q_x, q_syn ) ); + Copy_Scale_sig_16_32( x_fx_16, x_fx[ch][0], st->L_frame, sub( q_x, q_syn ) ); // q_syn -> Q_x } IF( GT_16( e_sig[0], e_sig[1] ) ) @@ -2311,9 +2314,9 @@ void ivas_mdct_core_reconstruct_fx( L_tmp = Mpy_32_32( W_extract_h( nrgL_fx ), W_extract_h( nrgR_fx ) ); e_tmp = add( e_nrgL, e_nrgR ); L_tmp = ISqrt32( L_tmp, &e_tmp ); - hCPE->hStereoMdct->lastCoh_fx = extract_l( L_shr( Mpy_32_32( L_abs( W_extract_h( xcorr_fx ) ), L_tmp ), sub( 17, add( e_xcorr, e_tmp ) ) ) ); + hCPE->hStereoMdct->lastCoh_fx = extract_l( L_shr( Mpy_32_32( L_abs( W_extract_h( xcorr_fx ) ), L_tmp ), sub( 17, add( e_xcorr, e_tmp ) ) ) ); // Q14 move16(); - hCPE->hStereoMdct->lastCoh_fx = s_min( hCPE->hStereoMdct->lastCoh_fx, 16384 ); + hCPE->hStereoMdct->lastCoh_fx = s_min( hCPE->hStereoMdct->lastCoh_fx, 16384 ); // 1.Q14 = 16384 move16(); } @@ -2452,8 +2455,8 @@ void ivas_mdct_core_tns_ns_fx( CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ Word16 fUseTns[CPE_CHANNELS][NB_DIV], /* i : two entries for each channel in TCX10 */ STnsData tnsData[CPE_CHANNELS][NB_DIV], /* o : TNS parameter */ - Word32 *x_fx[CPE_CHANNELS][NB_DIV], /* o : synthesis @internal_FS */ - Word32 Aq_fx[CPE_CHANNELS][( NB_SUBFR16k + 1 ) * ( M + 1 )], /* o : LP coefficients */ + Word32 *x_fx[CPE_CHANNELS][NB_DIV], /* o : synthesis @internal_FS Q(31 - x_e)*/ + Word32 Aq_fx[CPE_CHANNELS][( NB_SUBFR16k + 1 ) * ( M + 1 )], /* o : LP coefficients Q16*/ const Word16 MCT_flag, /* i : hMCT handle allocated (1) or not (0) */ Word16 x_e[CPE_CHANNELS][NB_DIV] ) { @@ -2531,11 +2534,13 @@ void ivas_mdct_core_tns_ns_fx( q_x = sub( 31, x_e[ch][k] ); IF( bfi == 0 ) { - sns_interpolate_scalefactors_fx( sns_int_scf_fx, &Aq_fx[ch][k * M], DEC ); + sns_interpolate_scalefactors_fx( sns_int_scf_fx, &Aq_fx[ch][k * M], DEC ); // Q16 + test(); + test(); IF( ( MCT_flag != 0 ) && st->hTonalMDCTConc != NULL && EQ_16( add( k, 1 ), nSubframes[ch] ) ) { - Word16 scf_fx[FDNS_NPTS], scf_e[FDNS_NPTS]; + Word16 scf_fx[FDNS_NPTS] /*(16 - scf_e)*/, scf_e[FDNS_NPTS]; Word16 q_shift; FOR( Word16 ind = 0; ind < st->hTonalMDCTConc->nScaleFactors; ind++ ) { @@ -2552,7 +2557,8 @@ void ivas_mdct_core_tns_ns_fx( { IF( st->hTonalMDCTConc != NULL ) { - IF( ( MCT_flag == 0 ) && LT_16( st->hTcxDec->cummulative_damping_tcx, 32440 ) ) + test(); + IF( ( MCT_flag == 0 ) && LT_16( st->hTcxDec->cummulative_damping_tcx, 32440 ) ) // 0.99.Q15 = 32440 { Word16 *scf_last_m, *scf_last_e; Word32 *scf_bg; @@ -2571,7 +2577,7 @@ void ivas_mdct_core_tns_ns_fx( FOR( Word16 i = 0; i < st->hTonalMDCTConc->nScaleFactors; i++ ) { - sns_int_scf_fx[i] = Madd_32_16( Mpy_32_16_1( L_shl( scf_last_m[i], add( 1, scf_last_e[i] ) ), fade_out ), scf_bg[i], fade_in ); + sns_int_scf_fx[i] = Madd_32_16( Mpy_32_16_1( L_shl( scf_last_m[i], add( 1, scf_last_e[i] ) ), fade_out ), scf_bg[i], fade_in ); // Q16 move32(); } } @@ -2581,7 +2587,7 @@ void ivas_mdct_core_tns_ns_fx( move16(); FOR( Word16 i = 0; i < st->hTonalMDCTConc->nScaleFactors; i++ ) { - sns_int_scf_fx[i] = L_shl( st->hTonalMDCTConc->lastBlockData.scaleFactors[i], add( 1, st->hTonalMDCTConc->lastBlockData.scaleFactors_exp[i] ) ); + sns_int_scf_fx[i] = L_shl( st->hTonalMDCTConc->lastBlockData.scaleFactors[i], add( 1, st->hTonalMDCTConc->lastBlockData.scaleFactors_exp[i] ) ); // Q16 move32(); } } @@ -2615,7 +2621,7 @@ void ivas_mdct_core_tns_ns_fx( // q_sns_int_scf -= 1; FOR( Word16 c = 0; c < FDNS_NPTS; c++ ) { - sns_int_scf_fx[c] = L_shl( sns_int_scf_fx[c], sub( q_sns_int_scf, 16 ) ); + sns_int_scf_fx[c] = L_shl( sns_int_scf_fx[c], sub( q_sns_int_scf, 16 ) ); // Q16 -> q_sns_int_scf move32(); } q_2 = q_x; diff --git a/lib_dec/ivas_sce_dec_fx.c b/lib_dec/ivas_sce_dec_fx.c index f38068570..19058c9c9 100644 --- a/lib_dec/ivas_sce_dec_fx.c +++ b/lib_dec/ivas_sce_dec_fx.c @@ -52,10 +52,10 @@ ivas_error ivas_sce_dec_fx( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ - const Word16 sce_id, /* i : SCE # identifier */ - Word32 *output[1], /* o : output synthesis signal */ - const Word16 output_frame, /* i : output frame length per channel */ - const Word16 nb_bits_metadata /* i : number of metadata bits */ + const Word16 sce_id, /* i : SCE # identifier Q0*/ + Word32 *output[1], /* o : output synthesis signal Q11*/ + const Word16 output_frame, /* i : output frame length per channel Q0*/ + const Word16 nb_bits_metadata /* i : number of metadata bits Q0*/ ) { Word32 outputHB[1][L_FRAME48k]; /*Word32 buffer for output HB synthesis, one channel */ @@ -75,9 +75,9 @@ ivas_error ivas_sce_dec_fx( st->BER_detect = s_or( st->BER_detect, st_ivas->BER_detect ); move16(); - ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate; + ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate; /*Q0*/ move32(); - last_ivas_total_brate = st_ivas->hDecoderConfig->last_ivas_total_brate; + last_ivas_total_brate = st_ivas->hDecoderConfig->last_ivas_total_brate; /*Q0*/ move32(); IF( EQ_16( (Word16) st_ivas->ivas_format, ISM_FORMAT ) ) @@ -97,7 +97,7 @@ ivas_error ivas_sce_dec_fx( test(); IF( !st_ivas->bfi && EQ_32( ivas_total_brate, IVAS_SID_5k2 ) ) { - st->total_brate = L_sub( ivas_total_brate, L_shr( L_mult( nb_bits_metadata, FRAMES_PER_SEC ), 1 ) ); + st->total_brate = L_sub( ivas_total_brate, L_mult0( nb_bits_metadata, FRAMES_PER_SEC ) ); /*Q0*/ move16(); test(); assert( EQ_32( st->total_brate, SID_2k40 ) && "SCE SID must be 2.4kbps!" ); @@ -116,7 +116,7 @@ ivas_error ivas_sce_dec_fx( } ELSE IF( !st_ivas->bfi && NE_16( (Word16) st_ivas->ivas_format, ISM_FORMAT ) && LE_32( last_ivas_total_brate, IVAS_SID_5k2 ) ) { - st->total_brate = L_sub( hSCE->element_brate, L_shr( L_mult( nb_bits_metadata, FRAMES_PER_SEC ), 1 ) ); + st->total_brate = L_sub( hSCE->element_brate, L_mult0( nb_bits_metadata, FRAMES_PER_SEC ) ); /*Q0*/ move32(); } @@ -147,13 +147,13 @@ ivas_error ivas_sce_dec_fx( ( LT_32( hSCE->element_brate, MIN_BRATE_FB_ISM ) && st->is_ism_format ) ) { /* WB and SWB are supported */ - st->bwidth = add( get_next_indice_fx( st, 1 ), WB ); + st->bwidth = add( get_next_indice_fx( st, 1 ), WB ); /*Q0*/ move16(); } ELSE { /* WB, SWB and FB are supported */ - st->bwidth = get_next_indice_fx( st, NBITS_BWIDTH ); + st->bwidth = get_next_indice_fx( st, NBITS_BWIDTH ); /*Q0*/ move16(); } } @@ -182,33 +182,33 @@ ivas_error ivas_sce_dec_fx( test(); IF( EQ_16( (Word16) st_ivas->ism_mode, ISM_MASA_MODE_DISC ) || EQ_16( (Word16) st_ivas->ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) ) { - st->bits_frame_nominal = extract_l( L_sub( Mpy_32_16_1( hSCE->element_brate, INV_FRAME_PER_SEC_Q15 ), ISM_NB_BITS_METADATA_NOMINAL ) ); + st->bits_frame_nominal = extract_l( L_sub( Mpy_32_16_1( hSCE->element_brate, INV_FRAME_PER_SEC_Q15 ), ISM_NB_BITS_METADATA_NOMINAL ) ); /*Q0*/ move16(); } ELSE IF( ( EQ_16( (Word16) st_ivas->mc_mode, MC_MODE_MCMASA ) && GE_32( ivas_total_brate, MCMASA_SEPARATE_BRATE ) ) || ( EQ_16( (Word16) st_ivas->ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) ) ) { - st->bits_frame_nominal = extract_l( Mpy_32_16_1( hSCE->element_brate, INV_FRAME_PER_SEC_Q15 ) ); + st->bits_frame_nominal = extract_l( Mpy_32_16_1( hSCE->element_brate, INV_FRAME_PER_SEC_Q15 ) ); /*Q0*/ move16(); } ELSE IF( EQ_16( (Word16) st_ivas->ism_mode, ISM_MODE_NONE ) && EQ_16( (Word16) st_ivas->ivas_format, SBA_ISM_FORMAT ) ) { - st->bits_frame_nominal = extract_l( Mpy_32_16_1( st_ivas->hSpar->core_nominal_brate, INV_FRAME_PER_SEC_Q15 ) ); + st->bits_frame_nominal = extract_l( Mpy_32_16_1( st_ivas->hSpar->core_nominal_brate, INV_FRAME_PER_SEC_Q15 ) ); /*Q0*/ move16(); } ELSE { - st->bits_frame_nominal = st_ivas->hQMetaData->bits_frame_nominal; + st->bits_frame_nominal = st_ivas->hQMetaData->bits_frame_nominal; /*Q0*/ move16(); } } ELSE IF( EQ_16( (Word16) st_ivas->ivas_format, SBA_FORMAT ) ) { - st->bits_frame_nominal = extract_l( Mpy_32_16_1( st_ivas->hSpar->core_nominal_brate, INV_FRAME_PER_SEC_Q15 ) ); + st->bits_frame_nominal = extract_l( Mpy_32_16_1( st_ivas->hSpar->core_nominal_brate, INV_FRAME_PER_SEC_Q15 ) ); /*Q0*/ move16(); } ELSE { - st->bits_frame_nominal = extract_l( L_sub( Mpy_32_16_1( hSCE->element_brate, INV_FRAME_PER_SEC_Q15 ), ISM_NB_BITS_METADATA_NOMINAL ) ); + st->bits_frame_nominal = extract_l( L_sub( Mpy_32_16_1( hSCE->element_brate, INV_FRAME_PER_SEC_Q15 ), ISM_NB_BITS_METADATA_NOMINAL ) ); /*Q0*/ move16(); } @@ -220,7 +220,7 @@ ivas_error ivas_sce_dec_fx( test(); IF( !st_ivas->bfi && EQ_32( ivas_total_brate, IVAS_SID_5k2 ) ) { - st->total_brate = L_sub( ivas_total_brate, L_shr( L_mult( nb_bits_metadata, FRAMES_PER_SEC ), 1 ) ); + st->total_brate = L_sub( ivas_total_brate, L_mult0( nb_bits_metadata, FRAMES_PER_SEC ) ); /*Q0*/ if ( EQ_16( (Word16) st_ivas->ivas_format, ISM_FORMAT ) && NE_16( st_ivas->hISMDTX.sce_id_dtx, sce_id ) ) { @@ -230,12 +230,12 @@ ivas_error ivas_sce_dec_fx( } ELSE IF( !st_ivas->bfi && EQ_32( ivas_total_brate, FRAME_NO_DATA ) ) { - st->total_brate = ivas_total_brate; + st->total_brate = ivas_total_brate; /*Q0*/ move32(); } ELSE IF( !st_ivas->bfi && NE_16( (Word16) st_ivas->ivas_format, ISM_FORMAT ) && NE_16( (Word16) st_ivas->ivas_format, MASA_ISM_FORMAT ) ) /* note: in ISMs, total_brate[] is set in ivas_ism_config() */ { - st->total_brate = L_sub( hSCE->element_brate, L_shr( L_mult( nb_bits_metadata, FRAMES_PER_SEC ), 1 ) ); + st->total_brate = L_sub( hSCE->element_brate, L_mult0( nb_bits_metadata, FRAMES_PER_SEC ) ); /*Q0*/ move32(); } @@ -257,7 +257,7 @@ ivas_error ivas_sce_dec_fx( } ELSE { - st->flag_ACELP16k = set_ACELP_flag_IVAS( IVAS_SCE, hSCE->element_brate, st->total_brate, 0, 0, -1, -1 ); + st->flag_ACELP16k = set_ACELP_flag_IVAS( IVAS_SCE, hSCE->element_brate, st->total_brate, 0, 0, -1, -1 ); /*Q0*/ move16(); } @@ -306,7 +306,7 @@ ivas_error ivas_sce_dec_fx( IF( st_ivas->sba_dirac_stereo_flag && ( GT_32( st->core_brate, SID_2k40 ) || EQ_16( st->cng_type, LP_CNG ) ) ) { /* skip addition of ACELP BWE for now, will be done after upmix */ - Copy32( outputHB[0], hSCE->save_hb_synth_fx, output_frame ); + Copy32( outputHB[0], hSCE->save_hb_synth_fx, output_frame ); /*Q11*/ hSCE->q_save_hb_synth_fx = Q11; move16(); } @@ -314,7 +314,7 @@ ivas_error ivas_sce_dec_fx( { Word32 output_Fs; - output_Fs = st_ivas->hDecoderConfig->output_Fs; + output_Fs = st_ivas->hDecoderConfig->output_Fs; /*Q0*/ move32(); /*----------------------------------------------------------------* @@ -333,17 +333,17 @@ ivas_error ivas_sce_dec_fx( * output LB and HB mix *----------------------------------------------------------------*/ - v_add_fx( output[0], outputHB[0], output[0], output_frame ); + v_add_fx( output[0], outputHB[0], output[0], output_frame ); /*Q11*/ } /*----------------------------------------------------------------* * Common updates *----------------------------------------------------------------*/ - hSCE->last_element_brate = hSCE->element_brate; + hSCE->last_element_brate = hSCE->element_brate; /*Q0*/ move32(); - st_ivas->BER_detect = s_or( st_ivas->BER_detect, st->BER_detect ); + st_ivas->BER_detect = s_or( st_ivas->BER_detect, st->BER_detect ); /*Q0*/ move16(); @@ -360,8 +360,8 @@ ivas_error ivas_sce_dec_fx( ivas_error create_sce_dec( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ - const Word16 sce_id, /* i : SCE # identifier */ - const Word32 element_brate /* i : element bitrate */ + const Word16 sce_id, /* i : SCE # identifier Q0*/ + const Word32 element_brate /* i : element bitrate Q0*/ ) { SCE_DEC_HANDLE hSCE; @@ -371,7 +371,7 @@ ivas_error create_sce_dec( error = IVAS_ERR_OK; move16(); - output_frame = extract_l( Mpy_32_16_1( st_ivas->hDecoderConfig->output_Fs, INV_FRAME_PER_SEC_Q15 ) ); + output_frame = extract_l( Mpy_32_16_1( st_ivas->hDecoderConfig->output_Fs, INV_FRAME_PER_SEC_Q15 ) ); /*Q0*/ /*-----------------------------------------------------------------* * Allocate SCE handle @@ -386,9 +386,9 @@ ivas_error create_sce_dec( * Initialization - general parameters *-----------------------------------------------------------------*/ - hSCE->sce_id = sce_id; + hSCE->sce_id = sce_id; /*Q0*/ move16(); - hSCE->element_brate = element_brate; + hSCE->element_brate = element_brate; /*Q0*/ move32(); set32_fx( hSCE->prev_hb_synth_fx, 0, NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, IVAS_DEC_DELAY_NS - DELAY_BWE_TOTAL_NS ) ); diff --git a/lib_dec/ivas_sns_dec_fx.c b/lib_dec/ivas_sns_dec_fx.c index d33eb08b7..1863e11ae 100644 --- a/lib_dec/ivas_sns_dec_fx.c +++ b/lib_dec/ivas_sns_dec_fx.c @@ -53,7 +53,7 @@ static void sns_1st_dec_fx( const Word16 index, /* i : codebook index */ const Word16 core, const Word16 L_frame, - Word32 *snsq_fx /* i/o: i:prediction o:quantized sns */ + Word32 *snsq_fx /* i/o: i:prediction o:quantized sns Q16*/ ) { Word16 i; @@ -68,20 +68,20 @@ static void sns_1st_dec_fx( SWITCH( L_frame ) { case L_FRAME16k: - means = &sns_1st_means_16k[core - 1][0]; + means = &sns_1st_means_16k[core - 1][0]; /*Q0*/ BREAK; case L_FRAME25_6k: - means = &sns_1st_means_25k6[core - 1][0]; + means = &sns_1st_means_25k6[core - 1][0]; /*Q0*/ BREAK; case L_FRAME32k: - means = &sns_1st_means_32k[core - 1][0]; + means = &sns_1st_means_32k[core - 1][0]; /*Q0*/ BREAK; default: assert( !"illegal frame length in sns_1st_cod" ); } - p_dico = &sns_1st_cdbk[0][core - 1][0] + i_mult( index % 32, ( M / 2 ) ); + p_dico = &sns_1st_cdbk[0][core - 1][0] + i_mult( index % 32, ( M / 2 ) ); /*Q0*/ FOR( i = 0; i < M / 2; i++ ) { @@ -89,11 +89,11 @@ static void sns_1st_dec_fx( move32(); } - p_dico = &sns_1st_cdbk[1][sub( core, 1 )][0] + i_mult( shr( index, 5 ), ( M / 2 ) ); + p_dico = &sns_1st_cdbk[1][sub( core, 1 )][0] + i_mult( shr( index, 5 ), ( M / 2 ) ); /*Q0*/ FOR( i = M / 2; i < M; i++ ) { - snsq_fx[i] = L_add( L_mult( ( *p_dico++ ), cdbk_fix ), L_mult( means[i], means_fix ) ); + snsq_fx[i] = L_add( L_mult( ( *p_dico++ ), cdbk_fix ), L_mult( means[i], means_fix ) ); /*Q16*/ move32(); } @@ -106,14 +106,14 @@ static void sns_1st_dec_fx( *-------------------------------------------------------------------*/ static void sns_2st_dec_fx( - Word32 *snsq_fx, /* i/o: i:1st stage o:1st+2nd stage */ + Word32 *snsq_fx, /* i/o: i:1st stage o:1st+2nd stage q_snsq*/ Word16 *q_snsq, - Word16 *indx /* i : index[] (4 bits per words) */ + Word16 *indx /* i : index[] (4 bits per words) Q0*/ ) { Word16 i; Word16 xq_fx[M]; - Word16 scale_fx = 13107; + Word16 scale_fx = 13107; /*1.0/2.5f in Q15*/ move16(); /* quantize */ AVQ_dec_lpc( indx, xq_fx, 2 ); @@ -129,8 +129,8 @@ static void sns_2st_dec_fx( IF( GE_16( *q_snsq, 16 ) ) { snsq_dIFf = sub( *q_snsq, 16 ); - tmp1 = L_shr( snsq_fx[i], snsq_dIFf ); - snsq_fx[i] = L_add( tmp1, tmp ); + tmp1 = L_shr( snsq_fx[i], snsq_dIFf ); /*Q16*/ + snsq_fx[i] = L_add( tmp1, tmp ); /*Q16*/ move32(); *q_snsq = 16; move16(); @@ -138,8 +138,8 @@ static void sns_2st_dec_fx( ELSE { snsq_dIFf = sub( 16, *q_snsq ); - tmp1 = L_shr( tmp, snsq_dIFf ); - snsq_fx[i] = L_add( snsq_fx[i], tmp1 ); + tmp1 = L_shr( tmp, snsq_dIFf ); /*q_snsq*/ + snsq_fx[i] = L_add( snsq_fx[i], tmp1 ); /*q_snsq*/ move32(); } } @@ -152,18 +152,18 @@ static void sns_2st_dec_fx( *-------------------------------------------------------------------*/ void sns_avq_dec_fx( - Word16 *index, /* i : Quantization indices */ - Word32 SNS_Q[NB_DIV][M], /* o : Quantized SNS vectors */ + Word16 *index, /* i : Quantization indices Q0*/ + Word32 SNS_Q[NB_DIV][M], /* o : Quantized SNS vectors q_snsq*/ Word16 *q_snsq, - const Word16 L_frame, /* i : frame length */ - const Word16 numlpc /* i : Number of sets of lpc */ + const Word16 L_frame, /* i : frame length Q0*/ + const Word16 numlpc /* i : Number of sets of lpc Q0*/ ) { Word16 i, nbi, last; Word16 q_type; /* go from one-based indexing to zero-based indexing */ - last = sub( numlpc, 1 ); + last = sub( numlpc, 1 ); /*Q0*/ index++; @@ -173,13 +173,13 @@ void sns_avq_dec_fx( move16(); sns_2st_dec_fx( SNS_Q[last], q_snsq, index ); - nbi = add( add( 2, index[0] ), index[1] ); + nbi = add( add( 2, index[0] ), index[1] ); /*Q0*/ index += nbi; /* Decode intermediate LPC (512 framing) */ IF( EQ_16( numlpc, 2 ) ) { - q_type = *index++; + q_type = *index++; /*Q0*/ move16(); IF( q_type == 0 ) @@ -193,7 +193,7 @@ void sns_avq_dec_fx( { FOR( i = 0; i < M; i++ ) { - SNS_Q[0][i] = SNS_Q[1][i]; + SNS_Q[0][i] = SNS_Q[1][i]; /*q_snsq*/ move32(); } sns_2st_dec_fx( SNS_Q[0], q_snsq, index ); @@ -210,18 +210,18 @@ void sns_avq_dec_fx( *-------------------------------------------------------------------*/ void sns_avq_dec_stereo_fx( - Word16 *indexl, /* i : Quantization indices (left channel) */ - Word16 *indexr, /* i : Quantization indices (right channe) */ - const Word16 L_frame, /* i : frame length */ - Word32 *SNS_Ql, /* o : Quantized SNS vectors (left channel) */ + Word16 *indexl, /* i : Quantization indices (left channel) Q0*/ + Word16 *indexr, /* i : Quantization indices (right channe) Q0*/ + const Word16 L_frame, /* i : frame length Q0*/ + Word32 *SNS_Ql, /* o : Quantized SNS vectors (left channel) q_l*/ Word16 *q_l, - Word32 *SNS_Qr, /* o : Quantized SNS vectors (right channe) */ + Word32 *SNS_Qr, /* o : Quantized SNS vectors (right channe) q_r*/ Word16 *q_r ) { Word16 i, stereo_mode; Word32 mid_q_fx[M], side_q_fx[M]; - stereo_mode = *indexl++; + stereo_mode = *indexl++; /*Q0*/ move16(); indexr++; @@ -236,7 +236,7 @@ void sns_avq_dec_stereo_fx( IF( EQ_16( stereo_mode, 2 ) ) { /* MS coding */ - tmp1 = *indexl++; + tmp1 = *indexl++; /*Q0*/ move16(); sns_1st_dec_fx( tmp1, TCX_20_CORE, L_frame, mid_q_fx ); q_mid = 16; @@ -291,9 +291,9 @@ void sns_avq_dec_stereo_fx( ELSE { /* LR decoding */ - tmp1 = *indexl++; + tmp1 = *indexl++; /*Q0*/ move16(); - tmp2 = *indexr++; + tmp2 = *indexr++; /*Q0*/ move16(); sns_1st_dec_fx( tmp1, TCX_20_CORE, L_frame, SNS_Ql ); *q_l = 16; @@ -316,8 +316,8 @@ void sns_avq_dec_stereo_fx( *-------------------------------------------------------------------*/ void dequantize_sns_fx( - Word16 indices[CPE_CHANNELS][NPRM_LPC_NEW], - Word32 snsQ_out_fx[CPE_CHANNELS][NB_DIV][M], + Word16 indices[CPE_CHANNELS][NPRM_LPC_NEW], /*Q0*/ + Word32 snsQ_out_fx[CPE_CHANNELS][NB_DIV][M], /*Q16*/ Decoder_State **sts ) { Word16 nSubframes, k, ch; @@ -325,13 +325,13 @@ void dequantize_sns_fx( Word16 zero_side_flag[NB_DIV]; Decoder_State *st; - sns_stereo_mode[0] = indices[0][0]; + sns_stereo_mode[0] = indices[0][0]; /*Q0*/ move16(); - sns_stereo_mode[1] = indices[0][1]; + sns_stereo_mode[1] = indices[0][1]; /*Q0*/ move16(); - zero_side_flag[0] = indices[0][2]; + zero_side_flag[0] = indices[0][2]; /*Q0*/ move16(); - zero_side_flag[1] = indices[0][3]; + zero_side_flag[1] = indices[0][3]; /*Q0*/ move16(); FOR( ch = 0; ch < CPE_CHANNELS; ++ch ) @@ -365,7 +365,7 @@ void dequantize_sns_fx( move16(); } - Word32 *snsQ_fx = snsQ_out_fx[ch][k]; + Word32 *snsQ_fx = snsQ_out_fx[ch][k]; /*Q16*/ IF( is_side ) { @@ -379,13 +379,13 @@ void dequantize_sns_fx( nStages = SNS_MSVQ_NSTAGES_SIDE; move16(); - msvq_dec_fx( side_cdbks_fx, NULL, NULL, nStages, M, M, &indices[ch][add( idxIndices, SNS_STEREO_MODE_OFFSET_INDICES )], 0, NULL, snsQ_fx, NULL, 15 ); // always 15 + msvq_dec_fx( side_cdbks_fx, NULL, NULL, nStages, M, M, &indices[ch][( idxIndices + SNS_STEREO_MODE_OFFSET_INDICES )], 0, NULL, snsQ_fx, NULL, 15 ); // always 15 } ELSE { - msvq_dec_fx( cdbks_fx, NULL, NULL, nStages, M, M, &indices[ch][add( idxIndices, SNS_STEREO_MODE_OFFSET_INDICES )], 0, NULL, snsQ_fx, NULL, 12 ); + msvq_dec_fx( cdbks_fx, NULL, NULL, nStages, M, M, &indices[ch][( idxIndices + SNS_STEREO_MODE_OFFSET_INDICES )], 0, NULL, snsQ_fx, NULL, 12 ); } - idxIndices = add( idxIndices, nStages ); + idxIndices = add( idxIndices, nStages ); /*Q0*/ } } @@ -402,7 +402,7 @@ void dequantize_sns_fx( { IF( EQ_16( sns_stereo_mode[k], SNS_STEREO_MODE_MS ) ) { - inverseMS_fx( M, snsQ_out_fx[0][k], snsQ_out_fx[1][k], ONE_IN_Q31 ); + inverseMS_fx( M, snsQ_out_fx[0][k], snsQ_out_fx[1][k], ONE_IN_Q31 ); /*Q16*/ } } } diff --git a/lib_dec/ivas_spar_decoder.c b/lib_dec/ivas_spar_decoder.c index b8b1e0545..6089012bc 100644 --- a/lib_dec/ivas_spar_decoder.c +++ b/lib_dec/ivas_spar_decoder.c @@ -278,7 +278,7 @@ ivas_error ivas_spar_dec_open( #else ivas_error ivas_spar_dec_open_fx( Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ - const Word16 spar_reconfig_flag /* i : SPAR reconfiguration flag */ + const Word16 spar_reconfig_flag /* i : SPAR reconfiguration flag Q0*/ ) { SPAR_DEC_HANDLE hSpar; @@ -292,10 +292,10 @@ ivas_error ivas_spar_dec_open_fx( error = IVAS_ERR_OK; move32(); - sba_order_internal = s_min( st_ivas->sba_analysis_order, IVAS_MAX_SBA_ORDER ); + sba_order_internal = s_min( st_ivas->sba_analysis_order, IVAS_MAX_SBA_ORDER ); /*Q0*/ move16(); - num_channels_internal = ivas_sba_get_nchan_metadata_fx( sba_order_internal, st_ivas->hDecoderConfig->ivas_total_brate ); + num_channels_internal = ivas_sba_get_nchan_metadata_fx( sba_order_internal, st_ivas->hDecoderConfig->ivas_total_brate ); /*Q0*/ hSpar = st_ivas->hSpar; @@ -308,16 +308,16 @@ ivas_error ivas_spar_dec_open_fx( } } - output_Fs = st_ivas->hDecoderConfig->output_Fs; + output_Fs = st_ivas->hDecoderConfig->output_Fs; /*Q0*/ move32(); IF( GT_16( num_channels_internal, ( SBA_HOA2_ORDER + 1 ) * ( SBA_HOA2_ORDER + 1 ) ) ) { - num_decor_chs = IVAS_HBR_MAX_DECOR_CHS; + num_decor_chs = IVAS_HBR_MAX_DECOR_CHS; /*Q0*/ move16(); } ELSE { - num_decor_chs = sub( num_channels_internal, 1 ); + num_decor_chs = sub( num_channels_internal, 1 ); /*Q0*/ } /* TD decorr. */ @@ -346,7 +346,7 @@ ivas_error ivas_spar_dec_open_fx( move16(); if ( hSpar->hTdDecorr ) { - hSpar->hTdDecorr->ducking_flag = ivas_spar_br_table_consts[hSpar->hMdDec->table_idx].td_ducking; + hSpar->hTdDecorr->ducking_flag = ivas_spar_br_table_consts[hSpar->hMdDec->table_idx].td_ducking; /*Q0*/ move16(); } @@ -357,9 +357,9 @@ ivas_error ivas_spar_dec_open_fx( { return error; } - fb_cfg->pcm_offset = NS2SA_FX2( output_Fs, DELAY_FB_1_NS + IVAS_ENC_DELAY_NS + IVAS_DEC_DELAY_NS ); + fb_cfg->pcm_offset = NS2SA_FX2( output_Fs, DELAY_FB_1_NS + IVAS_ENC_DELAY_NS + IVAS_DEC_DELAY_NS ); /*Q0*/ move16(); - fb_cfg->remix_order = remix_order_set[hSpar->hMdDec->spar_md_cfg.remix_unmix_order]; + fb_cfg->remix_order = remix_order_set[hSpar->hMdDec->spar_md_cfg.remix_unmix_order]; /*Q0*/ move16(); /* FB mixer handle */ @@ -440,21 +440,21 @@ ivas_error ivas_spar_dec_open_fx( ivas_output_init( &( st_ivas->hTransSetup ), st_ivas->transport_config ); set16_fx( hSpar->subframe_nbslots, 0, MAX_JBM_SUBFRAMES_5MS ); - set16_fx( hSpar->subframe_nbslots, JBM_CLDFB_SLOTS_IN_SUBFRAME, DEFAULT_JBM_SUBFRAMES_5MS ); - hSpar->nb_subframes = DEFAULT_JBM_SUBFRAMES_5MS; + set16_fx( hSpar->subframe_nbslots, JBM_CLDFB_SLOTS_IN_SUBFRAME, DEFAULT_JBM_SUBFRAMES_5MS ); /*Q0*/ + hSpar->nb_subframes = DEFAULT_JBM_SUBFRAMES_5MS; /*Q0*/ move16(); hSpar->subframes_rendered = 0; move16(); hSpar->slots_rendered = 0; move16(); - hSpar->num_slots = DEFAULT_JBM_SUBFRAMES_5MS * JBM_CLDFB_SLOTS_IN_SUBFRAME; + hSpar->num_slots = DEFAULT_JBM_SUBFRAMES_5MS * JBM_CLDFB_SLOTS_IN_SUBFRAME; /*Q0*/ move16(); /* init render timeslot mapping */ set16_fx( hSpar->render_to_md_map, 0, MAX_JBM_SUBFRAMES_5MS * JBM_CLDFB_SLOTS_IN_SUBFRAME ); FOR( map_idx = 0; map_idx < DEFAULT_JBM_CLDFB_TIMESLOTS; map_idx++ ) { - hSpar->render_to_md_map[map_idx] = map_idx; + hSpar->render_to_md_map[map_idx] = map_idx; /*Q0*/ move16(); } @@ -468,17 +468,17 @@ ivas_error ivas_spar_dec_open_fx( buffer_mode = TC_BUFFER_MODE_RENDERER; move32(); - nchan_tc = ivas_jbm_dec_get_num_tc_channels_fx( st_ivas ); - nchan_to_allocate = num_channels_internal; + nchan_tc = ivas_jbm_dec_get_num_tc_channels_fx( st_ivas ); /*Q0*/ + nchan_to_allocate = num_channels_internal; /*Q0*/ move16(); test(); if ( EQ_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) && EQ_32( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) ) { - nchan_to_allocate = add( nchan_to_allocate, st_ivas->nchan_ism ); + nchan_to_allocate = add( nchan_to_allocate, st_ivas->nchan_ism ); /*Q0*/ } - granularity = NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, CLDFB_SLOT_NS ); + granularity = NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, CLDFB_SLOT_NS ); /*Q0*/ move16(); test(); @@ -490,17 +490,17 @@ ivas_error ivas_spar_dec_open_fx( test(); IF( ( EQ_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) && EQ_32( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) && EQ_32( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_STEREO ) ) ) { - nchan_tc = add( st_ivas->hDecoderConfig->nchan_out, st_ivas->nchan_ism ); - nchan_to_allocate = nchan_tc; + nchan_tc = add( st_ivas->hDecoderConfig->nchan_out, st_ivas->nchan_ism ); /*Q0*/ + nchan_to_allocate = nchan_tc; /*Q0*/ move16(); } ELSE { buffer_mode = TC_BUFFER_MODE_BUFFER; move32(); - nchan_tc = st_ivas->hDecoderConfig->nchan_out; + nchan_tc = st_ivas->hDecoderConfig->nchan_out; /*Q0*/ move16(); - nchan_to_allocate = nchan_tc; + nchan_to_allocate = nchan_tc; /*Q0*/ move16(); } } @@ -518,7 +518,7 @@ ivas_error ivas_spar_dec_open_fx( /* get correct granularity in case of binaural rendering of the discrete objects with the td obj renderer */ Word32 quo, rem; iDiv_and_mod_32( st_ivas->hDecoderConfig->output_Fs, FRAMES_PER_SEC * MAX_PARAM_SPATIAL_SUBFRAMES, &quo, &rem, 0 ); - granularity = extract_l( quo ); + granularity = extract_l( quo ); /*Q0*/ } IF( NE_32( ( error = ivas_jbm_dec_tc_buffer_open_fx( st_ivas, buffer_mode, nchan_tc, nchan_to_allocate, nchan_to_allocate, granularity ) ), IVAS_ERR_OK ) ) @@ -582,8 +582,8 @@ void ivas_spar_dec_close( #else void ivas_spar_dec_close_fx( SPAR_DEC_HANDLE *hSpar, /* i/o: SPAR decoder handle */ - const Word32 output_Fs, /* i : output sampling rate */ - const Word16 spar_reconfig_flag /* i : SPAR reconfiguration flag */ + const Word32 output_Fs, /* i : output sampling rate Q0*/ + const Word16 spar_reconfig_flag /* i : SPAR reconfiguration flag Q0*/ ) { test(); @@ -631,7 +631,7 @@ void ivas_spar_dec_close_fx( #ifdef IVAS_FLOAT_FIXED ivas_error ivas_spar_dec_fx( Decoder_Struct *st_ivas, /* i/o: IVAS decoder struct */ - Word16 *nb_bits_read /* o : number of MD bits read */ + Word16 *nb_bits_read /* o : number of MD bits read Q0*/ ) { DECODER_CONFIG_HANDLE hDecoderConfig; @@ -657,14 +657,14 @@ ivas_error ivas_spar_dec_fx( st0 = st_ivas->hCPE[0]->hCoreCoder[0]; } - bit_stream_orig = st0->bit_stream; - next_bit_pos_orig = st0->next_bit_pos; + bit_stream_orig = st0->bit_stream; /*Q0*/ + next_bit_pos_orig = st0->next_bit_pos; /*Q0*/ move16(); IF( EQ_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) { iDiv_and_mod_32( hDecoderConfig->ivas_total_brate, FRAMES_PER_SEC, &quo, &rem, 0 ); - last_bit_pos = sub( extract_l( L_sub( quo, 1 ) ), nb_bits_read[1] ); + last_bit_pos = sub( extract_l( L_sub( quo, 1 ) ), nb_bits_read[1] ); /*Q0*/ } ELSE { @@ -683,38 +683,38 @@ ivas_error ivas_spar_dec_fx( IF( EQ_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) { iDiv_and_mod_32( hDecoderConfig->ivas_total_brate, FRAMES_PER_SEC, &quo, &rem, 0 ); - last_bit_pos = sub( extract_l( L_sub( quo, 1 ) ), nb_bits_read[1] ); + last_bit_pos = sub( extract_l( L_sub( quo, 1 ) ), nb_bits_read[1] ); /*Q0*/ } ELSE { iDiv_and_mod_32( hDecoderConfig->ivas_total_brate, FRAMES_PER_SEC, &quo, &rem, 0 ); - last_bit_pos = extract_l( L_sub( quo, 1 ) ); + last_bit_pos = extract_l( L_sub( quo, 1 ) ); /*Q0*/ } test(); if ( !st0->bfi && EQ_32( hDecoderConfig->ivas_total_brate, IVAS_SID_5k2 ) ) { - last_bit_pos = sub( last_bit_pos, SID_FORMAT_NBITS ); + last_bit_pos = sub( last_bit_pos, SID_FORMAT_NBITS ); /*Q0*/ } - nb_bits_read_orig = *nb_bits_read; + nb_bits_read_orig = *nb_bits_read; /*Q0*/ move16(); - last_bit_pos = sub( last_bit_pos, nb_bits_read_orig ); + last_bit_pos = sub( last_bit_pos, nb_bits_read_orig ); /*Q0*/ /* reverse the bitstream for easier reading of indices */ FOR( i = 0; i < s_min( MAX_BITS_METADATA, last_bit_pos ); i++ ) { - bstr_meta[i] = st_ivas->bit_stream[sub( last_bit_pos, i )]; + bstr_meta[i] = st_ivas->bit_stream[( last_bit_pos - i )]; /*Q0*/ move16(); } - st0->bit_stream = bstr_meta; + st0->bit_stream = bstr_meta; /*Q0*/ st0->next_bit_pos = 0; move16(); - st0->bits_frame = s_min( MAX_BITS_METADATA, add( last_bit_pos, 1 ) ); + st0->bits_frame = s_min( MAX_BITS_METADATA, add( last_bit_pos, 1 ) ); /*Q0*/ move16(); if ( !st0->bfi ) { - st0->total_brate = hDecoderConfig->ivas_total_brate; /* to avoid BER detect */ + st0->total_brate = hDecoderConfig->ivas_total_brate; /* to avoid BER detect */ /*Q0*/ move32(); } @@ -727,21 +727,21 @@ ivas_error ivas_spar_dec_fx( return error; } - *nb_bits_read = add( st0->next_bit_pos, nb_bits_read_orig ); + *nb_bits_read = add( st0->next_bit_pos, nb_bits_read_orig ); /*Q0*/ move16(); - st0->bit_stream = bit_stream_orig; - st0->next_bit_pos = next_bit_pos_orig; + st0->bit_stream = bit_stream_orig; /*Q0*/ + st0->next_bit_pos = next_bit_pos_orig; /*Q0*/ move16(); test(); IF( !st0->bfi && EQ_32( hDecoderConfig->ivas_total_brate, IVAS_SID_5k2 ) ) { Word16 zero_pad_bits; - *nb_bits_read = add( *nb_bits_read, SID_FORMAT_NBITS ); + *nb_bits_read = add( *nb_bits_read, SID_FORMAT_NBITS ); /*Q0*/ move16(); - zero_pad_bits = sub( ( IVAS_SID_5k2 - SID_2k40 ) / FRAMES_PER_SEC, *nb_bits_read ); + zero_pad_bits = sub( ( IVAS_SID_5k2 - SID_2k40 ) / FRAMES_PER_SEC, *nb_bits_read ); /*Q0*/ assert( zero_pad_bits <= 1 ); - *nb_bits_read = add( *nb_bits_read, zero_pad_bits ); + *nb_bits_read = add( *nb_bits_read, zero_pad_bits ); /*Q0*/ move16(); } @@ -853,10 +853,10 @@ ivas_error ivas_spar_dec( #ifdef IVAS_FLOAT_FIXED static Word16 ivas_get_spar_table_idx_from_coded_idx( - const Word32 ivas_total_brate, /* i : IVAS total bitrate */ - const Word16 sba_order, /* i : Ambisonic (SBA) order */ + const Word32 ivas_total_brate, /* i : IVAS total bitrate Q0*/ + const Word16 sba_order, /* i : Ambisonic (SBA) order Q0*/ Decoder_State *st0, /* i/o: decoder state structure - for bitstream handling*/ - Word16 *bitlen /* o : number of bits */ + Word16 *bitlen /* o : number of bits Q0*/ ) { Word16 table_idx, ind1[IVAS_SPAR_BR_TABLE_LEN]; @@ -878,12 +878,12 @@ static Word16 ivas_get_spar_table_idx_from_coded_idx( } assert( j > 0 ); - *bitlen = ivas_get_bits_to_encode( sub( j, 1 ) ); + *bitlen = ivas_get_bits_to_encode( sub( j, 1 ) ); /*Q0*/ move16(); - ind2 = get_next_indice_fx( st0, *bitlen ); + ind2 = get_next_indice_fx( st0, *bitlen ); /*Q0*/ - table_idx = ind1[ind2]; + table_idx = ind1[ind2]; /*Q0*/ move16(); return table_idx; @@ -929,17 +929,17 @@ static int16_t ivas_get_spar_table_idx_from_coded_idx( #ifdef IVAS_FLOAT_FIXED static Word16 ivas_parse_spar_header( - const Word32 ivas_total_brate, /* i : IVAS total bitrate */ - const Word16 sba_order, /* i : Ambisonic (SBA) order */ + const Word32 ivas_total_brate, /* i : IVAS total bitrate Q0*/ + const Word16 sba_order, /* i : Ambisonic (SBA) order Q0*/ Decoder_State *st0, /* i/o: decoder state structure - for bitstream handling*/ - Word16 *table_idx ) + Word16 *table_idx /*Q0*/ ) { Word16 bitlen, bwidth; - *table_idx = ivas_get_spar_table_idx_from_coded_idx( ivas_total_brate, sba_order, st0, &bitlen ); + *table_idx = ivas_get_spar_table_idx_from_coded_idx( ivas_total_brate, sba_order, st0, &bitlen ); /*Q0*/ move16(); - bwidth = ivas_spar_br_table_consts[( *table_idx )].bwidth; + bwidth = ivas_spar_br_table_consts[( *table_idx )].bwidth; /*Q0*/ move16(); return bwidth; @@ -966,7 +966,7 @@ static int16_t ivas_parse_spar_header( static Word16 get_random_number_fx( Word16 *seed ) { - return Random( seed ); + return Random( seed ); /*Q15*/ } #else static float get_random_number( @@ -981,12 +981,13 @@ static float get_random_number( #ifdef IVAS_FLOAT_FIXED static Word32 matrix_det_fx( - const Word32 a00, - const Word32 a01, - const Word32 a10, - const Word32 a11 ) + const Word32 a00, /*Q27*/ + const Word32 a01, /*Q27*/ + const Word32 a10, /*Q27*/ + const Word32 a11 /*Q27*/ +) { - return L_sub( Mpy_32_32( a00, a11 ), Mpy_32_32( a01, a10 ) ); + return L_sub( Mpy_32_32( a00, a11 ), Mpy_32_32( a01, a10 ) ); /*Q23*/ } #else static float matrix_det( @@ -1002,8 +1003,8 @@ static float matrix_det( #ifdef IVAS_FLOAT_FIXED static void matrix_inverse_fx( - Word32 in[3][3], - Word32 out[3][3], + Word32 in[3][3], /*Q27*/ + Word32 out[3][3], /*out_q*/ const Word16 size, Word16 *out_q ) { @@ -1016,9 +1017,9 @@ static void matrix_inverse_fx( IF( EQ_16( size, 1 ) ) { - tmp_32 = BASOP_Util_Divide3232_Scale( ONE_IN_Q27, L_max( in[0][0], eps_fx ), &tmp_e ); + tmp_32 = BASOP_Util_Divide3232_Scale( ONE_IN_Q27, L_max( in[0][0], eps_fx ), &tmp_e ); /*Q: 15 - tmp_e*/ shift = norm_l( tmp_32 ); - out[0][0] = L_shl( tmp_32, shift ); + out[0][0] = L_shl( tmp_32, shift ); /*out_q*/ move32(); *out_q = add( shift, sub( Q15, tmp_e ) ); move16(); @@ -1027,20 +1028,20 @@ static void matrix_inverse_fx( } ELSE IF( EQ_16( size, 2 ) ) { - det = matrix_det_fx( in[0][1], in[0][1], in[1][0], in[1][1] ); - tmp_32 = BASOP_Util_Divide3232_Scale( ONE_IN_Q23, L_max( det, eps_fx ), &tmp_e ); + det = matrix_det_fx( in[0][1], in[0][1], in[1][0], in[1][1] ); /*Q23*/ + tmp_32 = BASOP_Util_Divide3232_Scale( ONE_IN_Q23, L_max( det, eps_fx ), &tmp_e ); /*Q: 15 - tmp_e*/ shift = norm_l( tmp_32 ); - fac = L_shl( tmp_32, shift ); + fac = L_shl( tmp_32, shift ); /*q_fac*/ q_fac = add( shift, sub( Q15, tmp_e ) ); - out[0][0] = Mpy_32_32( in[1][1], fac ); + out[0][0] = Mpy_32_32( in[1][1], fac ); /*q_fac - 4*/ move32(); - out[1][0] = Mpy_32_32( in[1][0], L_negate( fac ) ); + out[1][0] = Mpy_32_32( in[1][0], L_negate( fac ) ); /*q_fac - 4*/ move32(); - out[0][1] = Mpy_32_32( in[0][1], L_negate( fac ) ); + out[0][1] = Mpy_32_32( in[0][1], L_negate( fac ) ); /*q_fac - 4*/ move32(); - out[1][1] = Mpy_32_32( in[0][0], fac ); + out[1][1] = Mpy_32_32( in[0][0], fac ); /*q_fac - 4*/ move32(); *out_q = add( Q27, sub( q_fac, 31 ) ); @@ -1049,31 +1050,31 @@ static void matrix_inverse_fx( return; } - det = L_add( L_sub( Mpy_32_32( in[0][0], matrix_det_fx( in[1][1], in[1][2], in[2][1], in[2][2] ) ), Mpy_32_32( in[1][0], matrix_det_fx( in[0][1], in[0][2], in[2][1], in[2][2] ) ) ), Mpy_32_32( in[2][0], matrix_det_fx( in[0][1], in[0][2], in[1][1], in[1][2] ) ) ); - tmp_32 = BASOP_Util_Divide3232_Scale( ONE_IN_Q19, L_max( det, eps_fx ), &tmp_e ); + det = L_add( L_sub( Mpy_32_32( in[0][0], matrix_det_fx( in[1][1], in[1][2], in[2][1], in[2][2] ) ), Mpy_32_32( in[1][0], matrix_det_fx( in[0][1], in[0][2], in[2][1], in[2][2] ) ) ), Mpy_32_32( in[2][0], matrix_det_fx( in[0][1], in[0][2], in[1][1], in[1][2] ) ) ); /*Q19*/ + tmp_32 = BASOP_Util_Divide3232_Scale( ONE_IN_Q19, L_max( det, eps_fx ), &tmp_e ); /*Q: 31 - tmp_e*/ shift = norm_l( tmp_32 ); - fac = L_shl( tmp_32, shift ); + fac = L_shl( tmp_32, shift ); /*q_fac*/ q_fac = add( shift, sub( Q15, tmp_e ) ); - out[0][0] = Mpy_32_32( matrix_det_fx( in[1][1], in[1][2], in[2][1], in[2][2] ), fac ); + out[0][0] = Mpy_32_32( matrix_det_fx( in[1][1], in[1][2], in[2][1], in[2][2] ), fac ); /*q_fac-8*/ move32(); - out[1][0] = Mpy_32_32( matrix_det_fx( in[1][0], in[1][2], in[2][0], in[2][2] ), L_negate( fac ) ); + out[1][0] = Mpy_32_32( matrix_det_fx( in[1][0], in[1][2], in[2][0], in[2][2] ), L_negate( fac ) ); /*q_fac-8*/ move32(); - out[2][0] = Mpy_32_32( matrix_det_fx( in[1][0], in[1][1], in[2][0], in[2][1] ), fac ); + out[2][0] = Mpy_32_32( matrix_det_fx( in[1][0], in[1][1], in[2][0], in[2][1] ), fac ); /*q_fac-8*/ move32(); - out[0][1] = Mpy_32_32( matrix_det_fx( in[0][1], in[0][2], in[2][1], in[2][2] ), L_negate( fac ) ); + out[0][1] = Mpy_32_32( matrix_det_fx( in[0][1], in[0][2], in[2][1], in[2][2] ), L_negate( fac ) ); /*q_fac-8*/ move32(); - out[1][1] = Mpy_32_32( matrix_det_fx( in[0][0], in[0][2], in[2][0], in[2][2] ), fac ); + out[1][1] = Mpy_32_32( matrix_det_fx( in[0][0], in[0][2], in[2][0], in[2][2] ), fac ); /*q_fac-8*/ move32(); - out[2][1] = Mpy_32_32( matrix_det_fx( in[0][0], in[0][1], in[2][0], in[2][1] ), L_negate( fac ) ); + out[2][1] = Mpy_32_32( matrix_det_fx( in[0][0], in[0][1], in[2][0], in[2][1] ), L_negate( fac ) ); /*q_fac-8*/ move32(); - out[0][2] = Mpy_32_32( matrix_det_fx( in[0][1], in[0][2], in[1][1], in[1][2] ), fac ); + out[0][2] = Mpy_32_32( matrix_det_fx( in[0][1], in[0][2], in[1][1], in[1][2] ), fac ); /*q_fac-8*/ move32(); - out[1][2] = Mpy_32_32( matrix_det_fx( in[0][0], in[0][2], in[1][0], in[1][2] ), L_negate( fac ) ); + out[1][2] = Mpy_32_32( matrix_det_fx( in[0][0], in[0][2], in[1][0], in[1][2] ), L_negate( fac ) ); /*q_fac-8*/ move32(); - out[2][2] = Mpy_32_32( matrix_det_fx( in[0][0], in[0][1], in[1][0], in[1][1] ), fac ); + out[2][2] = Mpy_32_32( matrix_det_fx( in[0][0], in[0][1], in[1][0], in[1][1] ), fac ); /*q_fac-8*/ move32(); *out_q = add( Q23, sub( q_fac, 31 ) ); @@ -1164,45 +1165,45 @@ void ivas_spar_get_cldfb_gains_fx( Word16 Q_cf_len_s; Word16 Q_weights; - pt_len = cldfbAnaDec0->p_filter_length; + pt_len = cldfbAnaDec0->p_filter_length; /*Q0*/ move16(); - num_cldfb_bands = cldfbAnaDec0->no_channels; + num_cldfb_bands = cldfbAnaDec0->no_channels; /*Q0*/ move16(); - stride = NS2SA_FX2( output_Fs_fx, DELAY_CLDFB_NS ); - encfb_delay = NS2SA_FX2( output_Fs_fx, IVAS_FB_ENC_DELAY_NS ); - decfb_delay = NS2SA_FX2( output_Fs_fx, IVAS_FB_DEC_DELAY_NS ); + stride = NS2SA_FX2( output_Fs_fx, DELAY_CLDFB_NS ); /*Q0*/ + encfb_delay = NS2SA_FX2( output_Fs_fx, IVAS_FB_ENC_DELAY_NS ); /*Q0*/ + decfb_delay = NS2SA_FX2( output_Fs_fx, IVAS_FB_DEC_DELAY_NS ); /*Q0*/ - cf_start = add( sub( hSpar->hFbMixer->cross_fade_start_offset, encfb_delay ), decfb_delay ); /* time domain after CLDFB synthesis*/ - cf_end = add( sub( hSpar->hFbMixer->cross_fade_end_offset, encfb_delay ), decfb_delay ); + cf_start = add( sub( hSpar->hFbMixer->cross_fade_start_offset, encfb_delay ), decfb_delay ); /* time domain after CLDFB synthesis*/ /*Q0*/ + cf_end = add( sub( hSpar->hFbMixer->cross_fade_end_offset, encfb_delay ), decfb_delay ); /*Q0*/ cf_len = sub( cf_end, cf_start ); - weights_fx = hSpar->hFbMixer->cldfb_cross_fade_fx; - cf_cldfb_start = shr( extract_l( ceil_fixed( sub( divide1616( sub( cf_start, shr( decfb_delay, 1 ) ), shl( stride, 9 ) ), 32 ), 6 ) ), 6 ); - cf_cldfb_end = shr( divide1616( add( sub( cf_start, shr( decfb_delay, 1 ) ), cf_len ), shl( stride, 9 ) ), 6 ); /*q-factor of stride is 9(as max value is 60)*/ - num_cf_slots = add( sub( cf_cldfb_end, cf_cldfb_start ), 1 ); - num_samples = add( imult1616( num_cf_slots, stride ), sub( pt_len, stride ) ); + weights_fx = hSpar->hFbMixer->cldfb_cross_fade_fx; /*hSpar->hFbMixer->cldfb_cross_fade_q*/ + cf_cldfb_start = shr( extract_l( ceil_fixed( sub( divide1616( sub( cf_start, shr( decfb_delay, 1 ) ), shl( stride, 9 ) ), 32 ), 6 ) ), 6 ); /*Q0*/ + cf_cldfb_end = shr( divide1616( add( sub( cf_start, shr( decfb_delay, 1 ) ), cf_len ), shl( stride, 9 ) ), 6 ); /*q-factor of stride is 9(as max value is 60)*/ /*Q0*/ + num_cf_slots = add( sub( cf_cldfb_end, cf_cldfb_start ), 1 ); /*Q0*/ + num_samples = add( imult1616( num_cf_slots, stride ), sub( pt_len, stride ) ); /*Q0*/ seed = RANDOM_INITSEED; move16(); split_band = SPAR_DIRAC_SPLIT_START_BAND; move16(); - pp_ts_im_fx[0] = ts_im_fx; - pp_ts_re_fx[0] = ts_re_fx; + pp_ts_im_fx[0] = ts_im_fx; /*Q22*/ + pp_ts_re_fx[0] = ts_re_fx; /*Q22*/ set32_fx( tgt_fx, 0, ( 3 - 1 ) * CLDFB_NO_CHANNELS_MAX + 10 * CLDFB_NO_CHANNELS_MAX ); - cf_start_s_fx = divide3232( ( sub( cf_start, shr( decfb_delay, 1 ) ) ), output_Fs_fx ); - cf_len_s_fx = divide3232( sub( hSpar->hFbMixer->cross_fade_end_offset, hSpar->hFbMixer->cross_fade_start_offset ), output_Fs_fx ); + cf_start_s_fx = divide3232( ( sub( cf_start, shr( decfb_delay, 1 ) ) ), output_Fs_fx ); /*Q_cf_start_s*/ + cf_len_s_fx = divide3232( sub( hSpar->hFbMixer->cross_fade_end_offset, hSpar->hFbMixer->cross_fade_start_offset ), output_Fs_fx ); /*Q_cf_len_s*/ Q_cf_start_s = sub( norm_s( cf_start_s_fx ), 1 ); Q_cf_len_s = norm_s( cf_len_s_fx ); Q_weights = add( 15, sub( Q_cf_start_s, Q_cf_len_s ) ); FOR( ts = 0; ts < CLDFB_NO_COL_MAX; ts++ ) { - weights_fx[ts] = divide1616( shl( sub( divide3232( L_mult0( add( shl( ts, 1 ), 1 ), shr( stride, 1 ) ), output_Fs_fx ), cf_start_s_fx ), Q_cf_start_s ), shl( cf_len_s_fx, Q_cf_len_s ) ); + weights_fx[ts] = divide1616( shl( sub( divide3232( L_mult0( add( shl( ts, 1 ), 1 ), shr( stride, 1 ) ), output_Fs_fx ), cf_start_s_fx ), Q_cf_start_s ), shl( cf_len_s_fx, Q_cf_len_s ) ); /*Q_weights*/ move16(); - weights_fx[ts] = s_max( s_min( weights_fx[ts], shl( 1, Q_weights ) ), 0 ); + weights_fx[ts] = s_max( s_min( weights_fx[ts], shl( 1, Q_weights ) ), 0 ); /*Q_weights*/ move16(); } - hSpar->hFbMixer->cldfb_cross_fade_start = cf_cldfb_start; + hSpar->hFbMixer->cldfb_cross_fade_start = cf_cldfb_start; /*Q0*/ move16(); - hSpar->hFbMixer->cldfb_cross_fade_end = cf_cldfb_end; + hSpar->hFbMixer->cldfb_cross_fade_end = cf_cldfb_end; /*Q0*/ move16(); test(); @@ -1215,10 +1216,10 @@ void ivas_spar_get_cldfb_gains_fx( /* optimization*/ /* compute time-domain cross-fade for considered time slots*/ - tmp_idx = sub( cf_start, imult1616( cf_cldfb_start, stride ) ); + tmp_idx = sub( cf_start, imult1616( cf_cldfb_start, stride ) ); /*Q0*/ FOR( sample = 0; sample < cf_len; sample++ ) { - tgt_fx[tmp_idx] = L_deposit_h( hSpar->hFbMixer->pFilterbank_cross_fade_fx[sample] ); + tgt_fx[tmp_idx] = L_deposit_h( hSpar->hFbMixer->pFilterbank_cross_fade_fx[sample] ); /*Q31*/ move32(); tmp_idx = add( tmp_idx, 1 ); /* increasing window function */ @@ -1226,7 +1227,7 @@ void ivas_spar_get_cldfb_gains_fx( FOR( ; tmp_idx < num_samples; tmp_idx++ ) { /* fill up with ones*/ - tgt_fx[tmp_idx] = MAX_32; + tgt_fx[tmp_idx] = MAX_32; /*Q31*/ move32(); } FOR( sample = 0; sample < num_samples; sample++ ) @@ -1241,8 +1242,8 @@ void ivas_spar_get_cldfb_gains_fx( FOR( sample = 0; sample < sub( pt_len, stride ); sample++ ) { /* fill internal CLDFB analysis time buffer with data*/ - Word16 x_fx = get_random_number_fx( &seed ); - cldfbAnaDec0->cldfb_state_fx[sample] = L_shl( x_fx, 12 ); + Word16 x_fx = get_random_number_fx( &seed ); /*Q15*/ + cldfbAnaDec0->cldfb_state_fx[sample] = L_shl( x_fx, 12 ); /*Q27*/ move32(); } Word16 q_cldfb = 27; @@ -1253,8 +1254,8 @@ void ivas_spar_get_cldfb_gains_fx( { FOR( sample = 0; sample < stride; sample++ ) { - Word16 x_fx = get_random_number_fx( &seed ); - ts_inout_fx[sample] = L_shl( x_fx, 12 ); /*Q-27*/ + Word16 x_fx = get_random_number_fx( &seed ); /*Q15*/ + ts_inout_fx[sample] = L_shl( x_fx, 12 ); /*Q27*/ move32(); } @@ -1264,15 +1265,15 @@ void ivas_spar_get_cldfb_gains_fx( FOR( sample = 0; sample < stride; sample++ ) { - T_fx[add( imult1616( slot, stride ), sample )][slot] = ts_inout_fx[sample]; + T_fx[( ( slot * stride ) + sample )][slot] = ts_inout_fx[sample]; /*Q21*/ move32(); } - tmp_idx = sub( pt_len, 1 ); + tmp_idx = sub( pt_len, 1 ); /*Q0*/ FOR( sample = stride; sample < pt_len; sample++ ) { - T_fx[add( imult1616( slot, stride ), sample )][slot] = cldfbSynDec0->cldfb_state_fx[tmp_idx]; + T_fx[( ( slot * stride ) + sample )][slot] = cldfbSynDec0->cldfb_state_fx[tmp_idx]; /*Q21*/ move32(); - tmp_idx = sub( tmp_idx, 1 ); + tmp_idx = sub( tmp_idx, 1 ); /*Q0*/ } } @@ -1297,11 +1298,11 @@ void ivas_spar_get_cldfb_gains_fx( } } - Tt_T_fx[1][0] = Tt_T_fx[0][1]; + Tt_T_fx[1][0] = Tt_T_fx[0][1]; /*Q27*/ move32(); - Tt_T_fx[2][0] = Tt_T_fx[0][2]; + Tt_T_fx[2][0] = Tt_T_fx[0][2]; /*Q27*/ move32(); - Tt_T_fx[2][1] = Tt_T_fx[1][2]; + Tt_T_fx[2][1] = Tt_T_fx[1][2]; /*Q27*/ move32(); FOR( slot_row = 0; slot_row < num_cf_slots; slot_row++ ) { @@ -1309,7 +1310,7 @@ void ivas_spar_get_cldfb_gains_fx( move32(); FOR( sample = 0; sample < num_samples; sample++ ) { - Tt_tgt_fx[slot_row] = L_add( Tt_tgt_fx[slot_row], Mpy_32_32( T_fx[sample][slot_row], tgt_fx[sample] ) ); + Tt_tgt_fx[slot_row] = L_add( Tt_tgt_fx[slot_row], Mpy_32_32( T_fx[sample][slot_row], tgt_fx[sample] ) ); /*Q21*/ move32(); } } @@ -1323,9 +1324,9 @@ void ivas_spar_get_cldfb_gains_fx( move32(); FOR( slot_col = 0; slot_col < num_cf_slots; slot_col++ ) { - tmp = L_add( tmp, Mpy_32_32( Tt_T_inv_fx[slot_row][slot_col], Tt_tgt_fx[slot_col] ) ); + tmp = L_add( tmp, Mpy_32_32( Tt_T_inv_fx[slot_row][slot_col], Tt_tgt_fx[slot_col] ) ); /*output_q-10*/ } - weights_fx[add( cf_cldfb_start, slot_row )] = extract_l( L_shr( L_max( L_min( tmp, L_shl( 1, sub( output_q, 10 ) ) ), 0 ), sub( sub( output_q, 10 ), Q_weights ) ) ); /*Q_weights*/ + weights_fx[( cf_cldfb_start + slot_row )] = extract_l( L_shr( L_max( L_min( tmp, L_shl( 1, sub( output_q, 10 ) ) ), 0 ), sub( sub( output_q, 10 ), Q_weights ) ) ); /*Q_weights*/ move16(); } hSpar->hFbMixer->cldfb_cross_fade_q = Q_weights; @@ -1337,8 +1338,8 @@ void ivas_spar_get_cldfb_gains_fx( return; } Word16 ivas_is_res_channel( - const Word16 ch, /* i : ch index in WYZX ordering */ - const Word16 nchan_transport /* i : number of transport channels (1-4) */ + const Word16 ch, /* i : ch index in WYZX ordering Q0*/ + const Word16 nchan_transport /* i : number of transport channels (1-4) Q0*/ ) { const Word16 rc_map[FOA_CHANNELS][FOA_CHANNELS] = { @@ -1355,7 +1356,7 @@ Word16 ivas_is_res_channel( } assert( nchan_transport <= FOA_CHANNELS ); - return ( rc_map[nchan_transport - 1][ch] ); + return ( rc_map[nchan_transport - 1][ch] ); /*Q0*/ } #else void ivas_spar_get_cldfb_gains( @@ -1596,15 +1597,15 @@ static ivas_error ivas_spar_dec_MD_fx( * Initialization *---------------------------------------------------------------------*/ - sba_order = s_min( st_ivas->sba_analysis_order, IVAS_MAX_SBA_ORDER ); - bfi = st_ivas->bfi; + sba_order = s_min( st_ivas->sba_analysis_order, IVAS_MAX_SBA_ORDER ); /*Q0*/ + bfi = st_ivas->bfi; /*Q0*/ move16(); - ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate; + ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate; /*Q0*/ move32(); - num_channels = ivas_sba_get_nchan_metadata_fx( sba_order, ivas_total_brate ); - num_md_sub_frames = ivas_get_spar_dec_md_num_subframes( sba_order, hDecoderConfig->ivas_total_brate, st_ivas->last_active_ivas_total_brate ); + num_channels = ivas_sba_get_nchan_metadata_fx( sba_order, ivas_total_brate ); /*Q0*/ + num_md_sub_frames = ivas_get_spar_dec_md_num_subframes( sba_order, hDecoderConfig->ivas_total_brate, st_ivas->last_active_ivas_total_brate ); /*Q0*/ - num_bands_out = hSpar->hFbMixer->pFb->filterbank_num_bands; + num_bands_out = hSpar->hFbMixer->pFb->filterbank_num_bands; /*Q0*/ move16(); test(); @@ -1621,17 +1622,17 @@ static ivas_error ivas_spar_dec_MD_fx( } ELSE { - hSpar->hMdDec->spar_md.num_bands = s_min( SPAR_DIRAC_SPLIT_START_BAND, IVAS_MAX_NUM_BANDS ); + hSpar->hMdDec->spar_md.num_bands = s_min( SPAR_DIRAC_SPLIT_START_BAND, IVAS_MAX_NUM_BANDS ); /*Q0*/ move16(); } IF( NE_16( hSpar->hMdDec->table_idx, table_idx ) ) { - hSpar->hMdDec->table_idx = table_idx; + hSpar->hMdDec->table_idx = table_idx; /*Q0*/ move16(); if ( hSpar->hTdDecorr ) { - hSpar->hTdDecorr->ducking_flag = ivas_spar_br_table_consts[table_idx].td_ducking; + hSpar->hTdDecorr->ducking_flag = ivas_spar_br_table_consts[table_idx].td_ducking; /*Q0*/ move16(); } @@ -1828,10 +1829,11 @@ static ivas_error ivas_spar_dec_MD( static Word16 ivas_spar_get_cldfb_slot_gain_fx( SPAR_DEC_HANDLE hSpar, /* i/o: SPAR decoder handle */ const DECODER_CONFIG_HANDLE hDecoderConfig, /* i : configuration structure */ - const Word16 time_slot_idx, - Word16 *time_slot_idx0, - Word16 *time_slot_idx1, - Word16 *weight_lowfreq_fx ) + const Word16 time_slot_idx, /*Q0*/ + Word16 *time_slot_idx0, /*Q0*/ + Word16 *time_slot_idx1, /*Q0*/ + Word16 *weight_lowfreq_fx /*Q15*/ +) { Word16 weight_fx; Word32 encfb_delay_fx, decfb_delay_fx; @@ -1840,40 +1842,40 @@ static Word16 ivas_spar_get_cldfb_slot_gain_fx( Word16 i_hist; Word16 split_band; - *weight_lowfreq_fx = hSpar->hFbMixer->cldfb_cross_fade_fx[time_slot_idx]; + *weight_lowfreq_fx = hSpar->hFbMixer->cldfb_cross_fade_fx[time_slot_idx]; /*Q15*/ move16(); encfb_delay_fx = IVAS_FB_ENC_DELAY_NS; move32(); decfb_delay_fx = IVAS_FB_DEC_DELAY_NS; move32(); - Word32 one_by_outfs = 0; // q15 + Word32 one_by_outfs = 0; // Q15 move32(); SWITCH( hDecoderConfig->output_Fs ) { case 16000: - one_by_outfs = 2048000000; + one_by_outfs = 2048000000; /* 1000000000.0f/(output_Fs) in Q15 */ move32(); BREAK; case 32000: - one_by_outfs = 1024000000; + one_by_outfs = 1024000000; /* 1000000000.0f/(output_Fs) in Q15 */ move32(); BREAK; case 48000: - one_by_outfs = 682666688; + one_by_outfs = 682666688; /* 1000000000.0f/(output_Fs) in Q15 */ move32(); BREAK; default: assert( 0 ); } - Word64 fade_start = W_mult0_32_32( one_by_outfs, hSpar->hFbMixer->cross_fade_start_offset ); + Word64 fade_start = W_mult0_32_32( one_by_outfs, hSpar->hFbMixer->cross_fade_start_offset ); /*Q15*/ move64(); - fade_start = W_shr( fade_start, 15 ); - xfade_start_ns_fx = L_add( L_sub( W_extract_l( fade_start ), encfb_delay_fx ), L_shr( decfb_delay_fx, 1 ) ); - xfade_delay_subframes = extract_l( Mpy_32_32( xfade_start_ns_fx, 429 /* 1 / ( FRAME_SIZE_NS / MAX_PARAM_SPATIAL_SUBFRAMES ) in Q31 -> 429 */ ) ); + fade_start = W_shr( fade_start, 15 ); /*Q0*/ + xfade_start_ns_fx = L_add( L_sub( W_extract_l( fade_start ), encfb_delay_fx ), L_shr( decfb_delay_fx, 1 ) ); /*Q0*/ + xfade_delay_subframes = extract_l( Mpy_32_32( xfade_start_ns_fx, 429 /* 1 / ( FRAME_SIZE_NS / MAX_PARAM_SPATIAL_SUBFRAMES ) in Q31 -> 429 */ ) ); /*Q0*/ - i_hist = sub( 4, xfade_delay_subframes ); + i_hist = sub( 4, xfade_delay_subframes ); /*Q0*/ split_band = SPAR_DIRAC_SPLIT_START_BAND; move16(); @@ -1890,15 +1892,15 @@ static Word16 ivas_spar_get_cldfb_slot_gain_fx( move16(); BREAK; case 1: - weight_fx = 8191; + weight_fx = 8191; /*0.25f in Q15*/ move16(); BREAK; case 2: - weight_fx = 16383; + weight_fx = 16383; /*0.5f in Q15*/ move16(); BREAK; case 3: - weight_fx = 24575; + weight_fx = 24575; /*0.75f in Q15*/ move16(); BREAK; default: @@ -1912,23 +1914,23 @@ static Word16 ivas_spar_get_cldfb_slot_gain_fx( weight_fx = 0; move16(); } - *time_slot_idx0 = i_hist; + *time_slot_idx0 = i_hist; /*Q0*/ move16(); - *time_slot_idx1 = add( i_hist, 1 ); + *time_slot_idx1 = add( i_hist, 1 ); /*Q0*/ move16(); } ELSE { /* determine cross-fade gain for current frame Parameters*/ - *time_slot_idx0 = hSpar->hFbMixer->cldfb_cross_fade_start; + *time_slot_idx0 = hSpar->hFbMixer->cldfb_cross_fade_start; /*Q0*/ move16(); - *time_slot_idx1 = hSpar->hFbMixer->cldfb_cross_fade_end; + *time_slot_idx1 = hSpar->hFbMixer->cldfb_cross_fade_end; /*Q0*/ move16(); - weight_fx = *weight_lowfreq_fx; + weight_fx = *weight_lowfreq_fx; /*Q15*/ move16(); } - return weight_fx; + return weight_fx; /*Q15*/ } #else @@ -1992,20 +1994,21 @@ static float ivas_spar_get_cldfb_slot_gain( #ifdef IVAS_FLOAT_FIXED void ivas_spar_get_parameters_fx( - SPAR_DEC_HANDLE hSpar, /* i/o: SPAR decoder handle */ - const DECODER_CONFIG_HANDLE hDecoderConfig, /* i : configuration structure */ - const Word16 ts, - const Word16 num_ch_out, - const Word16 num_ch_in, - const Word16 num_spar_bands, - Word32 par_mat_fx[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH][IVAS_MAX_NUM_BANDS] ) + SPAR_DEC_HANDLE hSpar, /* i/o: SPAR decoder handle */ + const DECODER_CONFIG_HANDLE hDecoderConfig, /* i : configuration structure */ + const Word16 ts, /*Q0*/ + const Word16 num_ch_out, /*Q0*/ + const Word16 num_ch_in, /*Q0*/ + const Word16 num_spar_bands, /*Q0*/ + Word32 par_mat_fx[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH][IVAS_MAX_NUM_BANDS] /*hSpar->hMdDec->Q_mixer_mat*/ +) { Word16 spar_band, out_ch, in_ch; Word16 weight_fx, weight_20ms_fx; Word16 ts0, ts1, split_band; // weight = ivas_spar_get_cldfb_slot_gain(hSpar, hDecoderConfig, ts, &ts0, &ts1, &weight_20ms); - weight_fx = ivas_spar_get_cldfb_slot_gain_fx( hSpar, hDecoderConfig, ts, &ts0, &ts1, &weight_20ms_fx ); + weight_fx = ivas_spar_get_cldfb_slot_gain_fx( hSpar, hDecoderConfig, ts, &ts0, &ts1, &weight_20ms_fx ); /*Q15*/ split_band = SPAR_DIRAC_SPLIT_START_BAND; move16(); @@ -2025,12 +2028,12 @@ void ivas_spar_get_parameters_fx( { par_mat_fx[out_ch][in_ch][spar_band] = L_add_sat( Mpy_32_16_1( hSpar->hMdDec->mixer_mat_prev_fx[ts0][out_ch][in_ch][spar_band], sub( MAX_WORD16, weight_fx ) ), - Mpy_32_16_1( hSpar->hMdDec->mixer_mat_prev_fx[ts1][out_ch][in_ch][spar_band], weight_fx ) ); + Mpy_32_16_1( hSpar->hMdDec->mixer_mat_prev_fx[ts1][out_ch][in_ch][spar_band], weight_fx ) ); /*hSpar->hMdDec->Q_mixer_mat*/ move32(); } ELSE { - par_mat_fx[out_ch][in_ch][spar_band] = hSpar->hMdDec->mixer_mat_fx[out_ch][in_ch][spar_band]; + par_mat_fx[out_ch][in_ch][spar_band] = hSpar->hMdDec->mixer_mat_fx[out_ch][in_ch][spar_band]; /*hSpar->hMdDec->Q_mixer_mat*/ move32(); } } @@ -2042,7 +2045,7 @@ void ivas_spar_get_parameters_fx( /* 20ms Transport channel reconstruction with matching encoder/decoder processing */ Word16 prev_idx = SPAR_DIRAC_SPLIT_START_BAND < IVAS_MAX_NUM_BANDS ? 1 : 0; /* if SPAR_DIRAC_SPLIT_START_BAND == IVAS_MAX_NUM_BANDS, then the sub-frame mixer_mat delay line is not active */ move16(); - par_mat_fx[out_ch][in_ch][spar_band] = L_add_sat( Mpy_32_16_1( hSpar->hMdDec->mixer_mat_prev_fx[prev_idx][out_ch][in_ch][spar_band], sub( MAX_WORD16, weight_20ms_fx ) ), Mpy_32_16_1( hSpar->hMdDec->mixer_mat_fx[out_ch][in_ch][spar_band], weight_20ms_fx ) ); + par_mat_fx[out_ch][in_ch][spar_band] = L_add_sat( Mpy_32_16_1( hSpar->hMdDec->mixer_mat_prev_fx[prev_idx][out_ch][in_ch][spar_band], sub( MAX_WORD16, weight_20ms_fx ) ), Mpy_32_16_1( hSpar->hMdDec->mixer_mat_fx[out_ch][in_ch][spar_band], weight_20ms_fx ) ); /*hSpar->hMdDec->Q_mixer_mat*/ move32(); } } @@ -2177,12 +2180,13 @@ static void ivas_spar_get_skip_mat( #else static void ivas_spar_get_skip_mat_fx( - SPAR_DEC_HANDLE hSpar, /* i/o: SPAR decoder handle */ - const Word16 num_ch_out, - const Word16 num_ch_in, - const Word16 num_spar_bands, - Word16 skip_mat[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], - const Word16 num_md_sub_frames ) + SPAR_DEC_HANDLE hSpar, /* i/o: SPAR decoder handle */ + const Word16 num_ch_out, /*Q0*/ + const Word16 num_ch_in, /*Q0*/ + const Word16 num_spar_bands, /*Q0*/ + Word16 skip_mat[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], /*Q0*/ + const Word16 num_md_sub_frames /*Q0*/ +) { Word16 spar_band, out_ch, in_ch; Word16 i_ts, skip_flag; @@ -2221,7 +2225,7 @@ static void ivas_spar_get_skip_mat_fx( { FOR( spar_band = 0; spar_band < num_spar_bands; spar_band++ ) { - IF( hSpar->hMdDec->mixer_mat_fx[out_ch][in_ch][add( spar_band, i_mult( i_ts, IVAS_MAX_NUM_BANDS ) )] != 0 ) + IF( hSpar->hMdDec->mixer_mat_fx[out_ch][in_ch][( spar_band + ( i_ts * IVAS_MAX_NUM_BANDS ) )] != 0 ) { skip_flag = 0; move16(); @@ -2247,15 +2251,15 @@ static void ivas_spar_get_skip_mat_fx( #ifdef IVAS_FLOAT_FIXED static void ivas_spar_calc_smooth_facs_fx( - Word32 *cldfb_in_ts_re_fx[CLDFB_NO_COL_MAX], // i - Word32 *cldfb_in_ts_im_fx[CLDFB_NO_COL_MAX], // i + Word32 *cldfb_in_ts_re_fx[CLDFB_NO_COL_MAX], // i q_cldfb + Word32 *cldfb_in_ts_im_fx[CLDFB_NO_COL_MAX], // i q_cldfb Word16 q_cldfb, - Word16 nbands_spar, - const Word16 nSlots, - const Word16 isFirstSubframe, + Word16 nbands_spar, /*Q0*/ + const Word16 nSlots, /*Q0*/ + const Word16 isFirstSubframe, /*Q0*/ ivas_fb_bin_to_band_data_t *bin2band, - Word16 *smooth_fac_fx, // o - Word32 smooth_buf_fx[IVAS_MAX_NUM_BANDS][2 * SBA_DIRAC_NRG_SMOOTH_LONG + 1] ) // o + Word16 *smooth_fac_fx, // o Q15 + Word32 smooth_buf_fx[IVAS_MAX_NUM_BANDS][2 * SBA_DIRAC_NRG_SMOOTH_LONG + 1] ) // o Q0 { Word16 b, bin, i, ts; Word32 subframe_band_nrg_fx[IVAS_MAX_NUM_BANDS]; @@ -2370,7 +2374,7 @@ static void ivas_spar_calc_smooth_facs_fx( } /* apply upper bounds depending on band */ - smooth_fac_fx[b] = s_max( min_smooth_gains1_fx[b], s_min( max_smooth_gains2_fx[b], smooth_fac_fx[b] ) ); + smooth_fac_fx[b] = s_max( min_smooth_gains1_fx[b], s_min( max_smooth_gains2_fx[b], smooth_fac_fx[b] ) ); /*Q15*/ move16(); } @@ -2382,7 +2386,7 @@ static void ivas_spar_calc_smooth_facs_fx( { FOR( i = 2 * SBA_DIRAC_NRG_SMOOTH_LONG; i > 0; i-- ) { - smooth_buf_fx[b][i] = smooth_buf_fx[b][i - 1]; + smooth_buf_fx[b][i] = smooth_buf_fx[b][i - 1]; /*Q0*/ move32(); } } @@ -2549,8 +2553,8 @@ void ivas_spar_dec_agc_pca( #else void ivas_spar_dec_agc_pca_fx( Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ - Word32 *output[], /* i/o: input/output audio channels */ - const Word16 output_frame /* i : output frame length */ + Word32 *output[], /* i/o: input/output audio channels Q14*/ + const Word16 output_frame /* i : output frame length Q0*/ ) { Word16 nchan_transport; @@ -2562,7 +2566,7 @@ void ivas_spar_dec_agc_pca_fx( hSpar = st_ivas->hSpar; hDecoderConfig = st_ivas->hDecoderConfig; - nchan_transport = hSpar->hMdDec->spar_md_cfg.nchan_transport; + nchan_transport = hSpar->hMdDec->spar_md_cfg.nchan_transport; /*Q0*/ move16(); IF( GE_16( st_ivas->nchan_transport, 3 ) ) @@ -2572,22 +2576,22 @@ void ivas_spar_dec_agc_pca_fx( /*convert WYZX downmix to WYXZ*/ FOR( i = 0; i < output_frame; i++ ) { - temp = output[2][i]; + temp = output[2][i]; /*Q14*/ move32(); - output[2][i] = output[3][i]; + output[2][i] = output[3][i]; /*Q14*/ move32(); - output[3][i] = temp; + output[3][i] = temp; /*Q14*/ move32(); } } IF( hSpar->hMdDec->td_decorr_flag ) { - num_in_ingest = ivas_sba_get_nchan_metadata_fx( st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate ); + num_in_ingest = ivas_sba_get_nchan_metadata_fx( st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate ); /*Q0*/ } ELSE { - num_in_ingest = nchan_transport; + num_in_ingest = nchan_transport; /*Q0*/ move16(); } @@ -2647,7 +2651,7 @@ void ivas_spar_dec_set_render_map( #else void ivas_spar_dec_set_render_map_fx( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ - const Word16 nCldfbTs /* i : number of CLDFB time slots */ + const Word16 nCldfbTs /* i : number of CLDFB time slots Q0*/ ) { SPAR_DEC_HANDLE hSpar; @@ -2655,7 +2659,7 @@ void ivas_spar_dec_set_render_map_fx( hSpar = st_ivas->hSpar; /* adapt subframes */ - hSpar->num_slots = nCldfbTs; + hSpar->num_slots = nCldfbTs; /*Q0*/ move16(); hSpar->slots_rendered = 0; move16(); @@ -2670,9 +2674,9 @@ void ivas_spar_dec_set_render_map_fx( test(); IF( !( EQ_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) && EQ_32( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) ) ) { - st_ivas->hTcBuffer->nb_subframes = hSpar->nb_subframes; + st_ivas->hTcBuffer->nb_subframes = hSpar->nb_subframes; /*Q0*/ move16(); - Copy( hSpar->subframe_nbslots, st_ivas->hTcBuffer->subframe_nbslots, hSpar->nb_subframes ); + Copy( hSpar->subframe_nbslots, st_ivas->hTcBuffer->subframe_nbslots, hSpar->nb_subframes ); /*Q0*/ } ivas_jbm_dec_get_md_map( DEFAULT_JBM_CLDFB_TIMESLOTS, nCldfbTs, 1, 0, DEFAULT_JBM_CLDFB_TIMESLOTS, hSpar->render_to_md_map ); @@ -2710,7 +2714,7 @@ void ivas_spar_dec_set_render_params( #else void ivas_spar_dec_set_render_params_fx( Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ - const Word16 n_cldfb_slots /* i : number of cldfb slots in this frame */ + const Word16 n_cldfb_slots /* i : number of cldfb slots in this frame Q0*/ ) { SPAR_DEC_HANDLE hSpar; @@ -2718,9 +2722,9 @@ void ivas_spar_dec_set_render_params_fx( Word16 num_bands_out; hSpar = st_ivas->hSpar; - nchan_transport = hSpar->hMdDec->spar_md_cfg.nchan_transport; + nchan_transport = hSpar->hMdDec->spar_md_cfg.nchan_transport; /*Q0*/ move16(); - num_bands_out = hSpar->hFbMixer->pFb->filterbank_num_bands; + num_bands_out = hSpar->hFbMixer->pFb->filterbank_num_bands; /*Q0*/ move16(); ivas_spar_dec_gen_umx_mat_fx( hSpar->hMdDec, nchan_transport, num_bands_out, st_ivas->bfi, ivas_get_spar_dec_md_num_subframes( st_ivas->sba_order, st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->last_active_ivas_total_brate ) ); @@ -2819,9 +2823,9 @@ void ivas_spar_dec_digest_tc( #else void ivas_spar_dec_digest_tc_fx( Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ - const Word16 nchan_transport, /* i : number of transport channels */ - const Word16 nCldfbSlots, /* i : number of CLDFB slots */ - const Word16 nSamplesForRendering /* i : number of samples provided */ + const Word16 nchan_transport, /* i : number of transport channels Q0*/ + const Word16 nCldfbSlots, /* i : number of CLDFB slots Q0*/ + const Word16 nSamplesForRendering /* i : number of samples provided Q0*/ ) { SPAR_DEC_HANDLE hSpar; @@ -2846,7 +2850,7 @@ void ivas_spar_dec_digest_tc_fx( { if ( EQ_32( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) ) { - ch_sba_idx = st_ivas->nchan_ism; + ch_sba_idx = st_ivas->nchan_ism; /*Q0*/ move16(); } } @@ -2854,20 +2858,20 @@ void ivas_spar_dec_digest_tc_fx( /* TD decorrelator */ Word32 quo, rem; iDiv_and_mod_32( st_ivas->hDecoderConfig->output_Fs, FRAMES_PER_SEC, &quo, &rem, 0 ); - default_frame = extract_l( quo ); - nSamplesLeftForTD = nSamplesForRendering; + default_frame = extract_l( quo ); /*Q0*/ + nSamplesLeftForTD = nSamplesForRendering; /*Q0*/ move16(); - nchan_internal = ivas_sba_get_nchan_metadata_fx( st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate ); + nchan_internal = ivas_sba_get_nchan_metadata_fx( st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate ); /*Q0*/ FOR( ch = 0; ch < nchan_internal; ch++ ) { - pPcm_tmp[ch] = Pcm_tmp[ch]; - p_tc[ch] = st_ivas->hTcBuffer->tc_fx[add( ch, ch_sba_idx )]; + pPcm_tmp[ch] = Pcm_tmp[ch]; /*Q11*/ + p_tc[ch] = st_ivas->hTcBuffer->tc_fx[( ch + ch_sba_idx )]; /*Q11*/ } WHILE( nSamplesLeftForTD ) { - Word16 nSamplesToDecorr = s_min( nSamplesLeftForTD, default_frame ); + Word16 nSamplesToDecorr = s_min( nSamplesLeftForTD, default_frame ); /*Q0*/ IF( hSpar->hTdDecorr ) { @@ -2879,27 +2883,27 @@ void ivas_spar_dec_digest_tc_fx( { FOR( ch = 0; ch < sub( nchan_internal, nchan_transport ); ch++ ) { - Copy32( pPcm_tmp[sub( sub( hSpar->hTdDecorr->num_apd_outputs, 1 ), ch )], p_tc[sub( sub( nchan_internal, 1 ), ch )], nSamplesToDecorr ); + Copy32( pPcm_tmp[( ( hSpar->hTdDecorr->num_apd_outputs - 1 ) - ch )], p_tc[( ( nchan_internal - 1 ) - ch )], nSamplesToDecorr ); /*Q11*/ } } ELSE { FOR( ch = 0; ch < sub( nchan_internal, nchan_transport ); ch++ ) { - set32_fx( p_tc[sub( sub( nchan_internal, 1 ), ch )], 0, nSamplesToDecorr ); + set32_fx( p_tc[( ( nchan_internal - 1 ) - ch )], 0, nSamplesToDecorr ); } FOR( ch = 0; ch < hSpar->hTdDecorr->num_apd_outputs; ch++ ) { - Copy32( pPcm_tmp[sub( sub( hSpar->hTdDecorr->num_apd_outputs, 1 ), ch )], p_tc[sub( sub( nchan_internal, 1 ), ch )], nSamplesToDecorr ); + Copy32( pPcm_tmp[( ( hSpar->hTdDecorr->num_apd_outputs - 1 ) - ch )], p_tc[( ( nchan_internal - 1 ) - ch )], nSamplesToDecorr ); /*Q11*/ } } } FOR( ch = 0; ch < nchan_internal; ch++ ) { - p_tc[ch] = p_tc[ch] + nSamplesToDecorr; + p_tc[ch] = p_tc[ch] + nSamplesToDecorr; /*Q11*/ } - nSamplesLeftForTD = sub( nSamplesLeftForTD, nSamplesToDecorr ); + nSamplesLeftForTD = sub( nSamplesLeftForTD, nSamplesToDecorr ); /*Q0*/ } } @@ -3047,8 +3051,8 @@ void ivas_spar_dec_upmixer( #ifdef IVAS_FLOAT_FIXED void ivas_spar_dec_upmixer_sf_fx( Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ - Word32 *output_fx[], /* o : output audio channels */ - const Word16 nchan_internal, /* i : number of internal channels */ + Word32 *output_fx[], /* o : output audio channels Q11*/ + const Word16 nchan_internal, /* i : number of internal channels Q0*/ Word16 out_len ) { Word16 cldfb_band, num_cldfb_bands, numch_in, numch_out; @@ -3072,19 +3076,19 @@ void ivas_spar_dec_upmixer_sf_fx( push_wmops( "ivas_spar_dec_upmixer_sf" ); hSpar = st_ivas->hSpar; hDecoderConfig = st_ivas->hDecoderConfig; - nchan_transport = hSpar->hMdDec->spar_md_cfg.nchan_transport; + nchan_transport = hSpar->hMdDec->spar_md_cfg.nchan_transport; /*Q0*/ move16(); - num_cldfb_bands = hSpar->hFbMixer->pFb->fb_bin_to_band.num_cldfb_bands; + num_cldfb_bands = hSpar->hFbMixer->pFb->fb_bin_to_band.num_cldfb_bands; /*Q0*/ move16(); - numch_in = hSpar->hFbMixer->fb_cfg->num_in_chans; + numch_in = hSpar->hFbMixer->fb_cfg->num_in_chans; /*Q0*/ move16(); - numch_out = hSpar->hFbMixer->fb_cfg->num_out_chans; + numch_out = hSpar->hFbMixer->fb_cfg->num_out_chans; /*Q0*/ move16(); - num_md_sub_frames = ivas_get_spar_dec_md_num_subframes( st_ivas->sba_order, hDecoderConfig->ivas_total_brate, st_ivas->last_active_ivas_total_brate ); - slot_size = NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, CLDFB_SLOT_NS ); + num_md_sub_frames = ivas_get_spar_dec_md_num_subframes( st_ivas->sba_order, hDecoderConfig->ivas_total_brate, st_ivas->last_active_ivas_total_brate ); /*Q0*/ + slot_size = NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, CLDFB_SLOT_NS ); /*Q0*/ move16(); - slot_idx_start = hSpar->slots_rendered; + slot_idx_start = hSpar->slots_rendered; /*Q0*/ move16(); test(); @@ -3097,7 +3101,7 @@ void ivas_spar_dec_upmixer_sf_fx( FOR( i = 0; i < nchan_internal; i++ ) { - p_tc_fx[i] = st_ivas->hTcBuffer->tc_fx[add( i, nchan_ism )] + i_mult( slot_idx_start, slot_size ); + p_tc_fx[i] = st_ivas->hTcBuffer->tc_fx[( i + nchan_ism )] + i_mult( slot_idx_start, slot_size ); /*Q11*/ } test(); @@ -3106,7 +3110,7 @@ void ivas_spar_dec_upmixer_sf_fx( { FOR( i = 0; i < nchan_ism; i++ ) { - p_tc_fx[add( i, nchan_internal )] = st_ivas->hTcBuffer->tc_fx[i] + i_mult( slot_idx_start, slot_size ); + p_tc_fx[( i + nchan_internal )] = st_ivas->hTcBuffer->tc_fx[i] + i_mult( slot_idx_start, slot_size ); /*Q11*/ } } } @@ -3114,7 +3118,7 @@ void ivas_spar_dec_upmixer_sf_fx( { FOR( i = 0; i < nchan_internal; i++ ) { - p_tc_fx[i] = st_ivas->hTcBuffer->tc_fx[i] + i_mult( slot_idx_start, slot_size ); + p_tc_fx[i] = st_ivas->hTcBuffer->tc_fx[i] + i_mult( slot_idx_start, slot_size ); /*Q11*/ } } @@ -3125,12 +3129,12 @@ void ivas_spar_dec_upmixer_sf_fx( IF( hSpar->hMdDec->td_decorr_flag ) { - num_in_ingest = nchan_internal; + num_in_ingest = nchan_internal; /*Q0*/ move16(); } ELSE { - num_in_ingest = nchan_transport; + num_in_ingest = nchan_transport; /*Q0*/ move16(); } @@ -3138,7 +3142,7 @@ void ivas_spar_dec_upmixer_sf_fx( * PCA decoder *---------------------------------------------------------------------*/ - hSpar->hFbMixer->fb_cfg->num_in_chans = num_in_ingest; + hSpar->hFbMixer->fb_cfg->num_in_chans = num_in_ingest; /*Q0*/ move16(); @@ -3157,8 +3161,8 @@ void ivas_spar_dec_upmixer_sf_fx( { FOR( ts = 0; ts < MAX_PARAM_SPATIAL_SUBFRAMES; ts++ ) { - cldfb_in_ts_re_fx[in_ch][ts] = &Pcm_tmp_fx[in_ch][i_mult( ts, num_cldfb_bands )]; - cldfb_in_ts_im_fx[in_ch][ts] = &Pcm_tmp_fx[in_ch][add( i_mult( ts, num_cldfb_bands ), ( 4 * num_cldfb_bands ) )]; + cldfb_in_ts_re_fx[in_ch][ts] = &Pcm_tmp_fx[in_ch][( ts * num_cldfb_bands )]; /*Q11*/ + cldfb_in_ts_im_fx[in_ch][ts] = &Pcm_tmp_fx[in_ch][( ( ts * num_cldfb_bands ) + ( 4 * num_cldfb_bands ) )]; /*Q11*/ } } } @@ -3168,8 +3172,8 @@ void ivas_spar_dec_upmixer_sf_fx( { FOR( ts = 0; ts < MAX_PARAM_SPATIAL_SUBFRAMES; ts++ ) { - cldfb_in_ts_re_fx[in_ch][ts] = &Pcm_tmp_fx[in_ch][i_mult( ts, num_cldfb_bands )]; - cldfb_in_ts_im_fx[in_ch][ts] = &Pcm_tmp_fx[in_ch][add( i_mult( ts, num_cldfb_bands ), ( 4 * num_cldfb_bands ) )]; + cldfb_in_ts_re_fx[in_ch][ts] = &Pcm_tmp_fx[in_ch][( ts * num_cldfb_bands )]; /*Q11*/ + cldfb_in_ts_im_fx[in_ch][ts] = &Pcm_tmp_fx[in_ch][( ( ts * num_cldfb_bands ) + ( 4 * num_cldfb_bands ) )]; /*Q11*/ } } } @@ -3178,7 +3182,7 @@ void ivas_spar_dec_upmixer_sf_fx( * CLDFB Processing and Synthesis *---------------------------------------------------------------------*/ - num_spar_bands = hSpar->hFbMixer->pFb->filterbank_num_bands; + num_spar_bands = hSpar->hFbMixer->pFb->filterbank_num_bands; /*Q0*/ move16(); /* apply parameters */ @@ -3196,7 +3200,7 @@ void ivas_spar_dec_upmixer_sf_fx( { Word16 q_cldfb = 11; move16(); - cldfbAnalysis_ts_fx_fixed_q( &p_tc_fx[in_ch][i_mult( ts, num_cldfb_bands )], cldfb_in_ts_re_fx[in_ch][ts], cldfb_in_ts_im_fx[in_ch][ts], num_cldfb_bands, st_ivas->cldfbAnaDec[in_ch], &q_cldfb ); + cldfbAnalysis_ts_fx_fixed_q( &p_tc_fx[in_ch][( ts * num_cldfb_bands )], cldfb_in_ts_re_fx[in_ch][ts], cldfb_in_ts_im_fx[in_ch][ts], num_cldfb_bands, st_ivas->cldfbAnaDec[in_ch], &q_cldfb ); } } @@ -3204,13 +3208,13 @@ void ivas_spar_dec_upmixer_sf_fx( test(); IF( EQ_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) && EQ_32( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) && EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) ) { - FOR( ; in_ch < add( st_ivas->nchan_ism, numch_in ); in_ch++ ) + FOR( ; in_ch < ( st_ivas->nchan_ism + numch_in ); in_ch++ ) { FOR( ts = 0; ts < hSpar->subframe_nbslots[hSpar->subframes_rendered]; ts++ ) { Word16 q_cldfb = 11; move16(); - cldfbAnalysis_ts_fx_fixed_q( &p_tc_fx[in_ch][i_mult( ts, num_cldfb_bands )], cldfb_in_ts_re_fx[in_ch][ts], cldfb_in_ts_im_fx[in_ch][ts], num_cldfb_bands, st_ivas->cldfbAnaDec[in_ch], &q_cldfb ); + cldfbAnalysis_ts_fx_fixed_q( &p_tc_fx[in_ch][( ts * num_cldfb_bands )], cldfb_in_ts_re_fx[in_ch][ts], cldfb_in_ts_im_fx[in_ch][ts], num_cldfb_bands, st_ivas->cldfbAnaDec[in_ch], &q_cldfb ); } } } @@ -3226,9 +3230,9 @@ void ivas_spar_dec_upmixer_sf_fx( } FOR( ts = 0; ts < hSpar->subframe_nbslots[hSpar->subframes_rendered]; ts++ ) { - md_idx = hSpar->render_to_md_map[add( ts, slot_idx_start )]; + md_idx = hSpar->render_to_md_map[( ts + slot_idx_start )]; /*Q0*/ move16(); - Scale_sig( hSpar->hFbMixer->cldfb_cross_fade_fx, CLDFB_NO_COL_MAX, Q15 - st_ivas->hSpar->hFbMixer->cldfb_cross_fade_q ); + Scale_sig( hSpar->hFbMixer->cldfb_cross_fade_fx, CLDFB_NO_COL_MAX, Q15 - st_ivas->hSpar->hFbMixer->cldfb_cross_fade_q ); /*Q15*/ st_ivas->hSpar->hFbMixer->cldfb_cross_fade_q = Q15; move16(); ivas_spar_get_parameters_fx( hSpar, hDecoderConfig, md_idx, numch_out, numch_in, num_spar_bands, mixer_mat_fx ); @@ -3245,7 +3249,7 @@ void ivas_spar_dec_upmixer_sf_fx( { mixer_mat_fx[out_ch][in_ch][spar_band] = Madd_32_16( Mpy_32_16_1( mixer_mat_fx[out_ch][in_ch][spar_band], sub( 32767, hSpar->hMdDec->smooth_fac_fx[spar_band] ) ), hSpar->hMdDec->mixer_mat_prev2_fx[out_ch][in_ch][spar_band], hSpar->hMdDec->smooth_fac_fx[spar_band] ); /*q1*/ move32(); - hSpar->hMdDec->mixer_mat_prev2_fx[out_ch][in_ch][spar_band] = mixer_mat_fx[out_ch][in_ch][spar_band]; + hSpar->hMdDec->mixer_mat_prev2_fx[out_ch][in_ch][spar_band] = mixer_mat_fx[out_ch][in_ch][spar_band]; /*q1*/ move32(); } } @@ -3271,9 +3275,9 @@ void ivas_spar_dec_upmixer_sf_fx( { IF( LT_16( cldfb_band, CLDFB_PAR_WEIGHT_START_BAND ) ) /* tuning parameter, depends on how much SPAR Filters overlap for the CLDFB bands */ { - spar_band = bin2band->p_cldfb_map_to_spar_band[cldfb_band]; + spar_band = bin2band->p_cldfb_map_to_spar_band[cldfb_band]; /*Q0*/ move16(); - cldfb_par_fx = mixer_mat_fx[out_ch][in_ch][spar_band]; + cldfb_par_fx = mixer_mat_fx[out_ch][in_ch][spar_band]; /*q1*/ move32(); } ELSE @@ -3283,8 +3287,8 @@ void ivas_spar_dec_upmixer_sf_fx( FOR( spar_band = bin2band->p_spar_start_bands[cldfb_band]; spar_band < num_spar_bands; spar_band++ ) { /* accumulate contributions from all SPAR bands */ - Word16 tmp = extract_l( L_shr( bin2band->pp_cldfb_weights_per_spar_band_fx[cldfb_band][spar_band], 7 ) ); - cldfb_par_fx = L_add_sat( cldfb_par_fx, Mpy_32_16_1( mixer_mat_fx[out_ch][in_ch][spar_band], tmp ) ); /*q1*/ + Word16 tmp = extract_l( L_shr( bin2band->pp_cldfb_weights_per_spar_band_fx[cldfb_band][spar_band], 7 ) ); /*Q15*/ + cldfb_par_fx = L_add_sat( cldfb_par_fx, Mpy_32_16_1( mixer_mat_fx[out_ch][in_ch][spar_band], tmp ) ); /*q1*/ } } @@ -3307,10 +3311,10 @@ void ivas_spar_dec_upmixer_sf_fx( } test(); - IF( ( EQ_16( ( add( add( slot_idx_start, ts ), 1 ) ), hSpar->num_slots ) ) || ( NE_16( ( shr( md_idx, 2 ) /* md_idx / JBM_CLDFB_SLOTS_IN_SUBFRAME */ ), ( hSpar->render_to_md_map[add( add( slot_idx_start, ts ), 1 )] / JBM_CLDFB_SLOTS_IN_SUBFRAME /*It's value is 4*/ ) ) ) ) + IF( ( EQ_16( ( add( add( slot_idx_start, ts ), 1 ) ), hSpar->num_slots ) ) || ( NE_16( ( shr( md_idx, 2 ) /* md_idx / JBM_CLDFB_SLOTS_IN_SUBFRAME */ ), ( hSpar->render_to_md_map[( ( slot_idx_start + ts ) + 1 )] / JBM_CLDFB_SLOTS_IN_SUBFRAME /*It's value is 4*/ ) ) ) ) { /* we have crossed an unadapted parameter sf border, update previous mixing matrices */ - Word16 md_sf = shr( md_idx, 2 ) /* md_idx / JBM_CLDFB_SLOTS_IN_SUBFRAME */; + Word16 md_sf = shr( md_idx, 2 ) /* md_idx / JBM_CLDFB_SLOTS_IN_SUBFRAME */; /*Q0*/ split_band = SPAR_DIRAC_SPLIT_START_BAND; move16(); if ( NE_16( num_md_sub_frames, MAX_PARAM_SPATIAL_SUBFRAMES ) ) @@ -3320,10 +3324,10 @@ void ivas_spar_dec_upmixer_sf_fx( } IF( LT_16( split_band, IVAS_MAX_NUM_BANDS ) ) { - Copy32( hSpar->hMdDec->mixer_mat_prev_fx[1][0][0], hSpar->hMdDec->mixer_mat_prev_fx[0][0][0], IVAS_MAX_FB_MIXER_OUT_CH * IVAS_MAX_SPAR_FB_MIXER_IN_CH * IVAS_MAX_NUM_BANDS ); - Copy32( hSpar->hMdDec->mixer_mat_prev_fx[2][0][0], hSpar->hMdDec->mixer_mat_prev_fx[1][0][0], IVAS_MAX_FB_MIXER_OUT_CH * IVAS_MAX_SPAR_FB_MIXER_IN_CH * IVAS_MAX_NUM_BANDS ); - Copy32( hSpar->hMdDec->mixer_mat_prev_fx[3][0][0], hSpar->hMdDec->mixer_mat_prev_fx[2][0][0], IVAS_MAX_FB_MIXER_OUT_CH * IVAS_MAX_SPAR_FB_MIXER_IN_CH * IVAS_MAX_NUM_BANDS ); - Copy32( hSpar->hMdDec->mixer_mat_prev_fx[4][0][0], hSpar->hMdDec->mixer_mat_prev_fx[3][0][0], IVAS_MAX_FB_MIXER_OUT_CH * IVAS_MAX_SPAR_FB_MIXER_IN_CH * IVAS_MAX_NUM_BANDS ); + Copy32( hSpar->hMdDec->mixer_mat_prev_fx[1][0][0], hSpar->hMdDec->mixer_mat_prev_fx[0][0][0], IVAS_MAX_FB_MIXER_OUT_CH * IVAS_MAX_SPAR_FB_MIXER_IN_CH * IVAS_MAX_NUM_BANDS ); /*hSpar->hMdDec->Q_mixer_mat*/ + Copy32( hSpar->hMdDec->mixer_mat_prev_fx[2][0][0], hSpar->hMdDec->mixer_mat_prev_fx[1][0][0], IVAS_MAX_FB_MIXER_OUT_CH * IVAS_MAX_SPAR_FB_MIXER_IN_CH * IVAS_MAX_NUM_BANDS ); /*hSpar->hMdDec->Q_mixer_mat*/ + Copy32( hSpar->hMdDec->mixer_mat_prev_fx[3][0][0], hSpar->hMdDec->mixer_mat_prev_fx[2][0][0], IVAS_MAX_FB_MIXER_OUT_CH * IVAS_MAX_SPAR_FB_MIXER_IN_CH * IVAS_MAX_NUM_BANDS ); /*hSpar->hMdDec->Q_mixer_mat*/ + Copy32( hSpar->hMdDec->mixer_mat_prev_fx[4][0][0], hSpar->hMdDec->mixer_mat_prev_fx[3][0][0], IVAS_MAX_FB_MIXER_OUT_CH * IVAS_MAX_SPAR_FB_MIXER_IN_CH * IVAS_MAX_NUM_BANDS ); /*hSpar->hMdDec->Q_mixer_mat*/ FOR( out_ch = 0; out_ch < numch_out; out_ch++ ) { @@ -3331,14 +3335,14 @@ void ivas_spar_dec_upmixer_sf_fx( { FOR( b = 0; b < num_spar_bands; b++ ) { - hSpar->hMdDec->mixer_mat_prev_fx[4][out_ch][in_ch][b] = hSpar->hMdDec->mixer_mat_fx[out_ch][in_ch][add( b, i_mult( md_sf, IVAS_MAX_NUM_BANDS ) )]; + hSpar->hMdDec->mixer_mat_prev_fx[4][out_ch][in_ch][b] = hSpar->hMdDec->mixer_mat_fx[out_ch][in_ch][( b + ( md_sf * IVAS_MAX_NUM_BANDS ) )]; /*hSpar->hMdDec->Q_mixer_mat*/ move32(); } } } - hSpar->i_subframe = add( hSpar->i_subframe, 1 ); + hSpar->i_subframe = add( hSpar->i_subframe, 1 ); /*Q0*/ move16(); - hSpar->i_subframe = s_min( hSpar->i_subframe, MAX_PARAM_SPATIAL_SUBFRAMES ); + hSpar->i_subframe = s_min( hSpar->i_subframe, MAX_PARAM_SPATIAL_SUBFRAMES ); /*Q0*/ move16(); } } @@ -3359,7 +3363,7 @@ void ivas_spar_dec_upmixer_sf_fx( idx_lfe = 0; move16(); - outchannels = add( st_ivas->hOutSetup.nchan_out_woLFE, st_ivas->hOutSetup.num_lfe ); + outchannels = add( st_ivas->hOutSetup.nchan_out_woLFE, st_ivas->hOutSetup.num_lfe ); /*Q0*/ FOR( ch = 0; ch < outchannels; ch++ ) { @@ -3383,16 +3387,16 @@ void ivas_spar_dec_upmixer_sf_fx( IF( ( EQ_32( hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_FOA ) || !( EQ_32( st_ivas->hOutSetup.output_config, IVAS_AUDIO_CONFIG_BINAURAL ) || EQ_32( st_ivas->hOutSetup.output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR ) || EQ_32( st_ivas->hOutSetup.output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) ) ) && !( EQ_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) && EQ_32( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) && EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) ) ) { - Scale_sig32( st_ivas->cldfbSynDec[idx_in]->cldfb_state_fx, st_ivas->cldfbSynDec[idx_in]->p_filter_length, -6 ); + Scale_sig32( st_ivas->cldfbSynDec[idx_in]->cldfb_state_fx, st_ivas->cldfbSynDec[idx_in]->p_filter_length, -6 ); /*st_ivas->cldfbSynDec[idx_in]->Q_cldfb_state-6*/ st_ivas->cldfbSynDec[idx_in]->Q_cldfb_state = sub( st_ivas->cldfbSynDec[idx_in]->Q_cldfb_state, 6 ); move16(); - Scale_sig32( output_fx[ch], out_len, -6 ); + Scale_sig32( output_fx[ch], out_len, -6 ); /*Q5*/ FOR( ts = 0; ts < hSpar->subframe_nbslots[hSpar->subframes_rendered]; ts++ ) { cldfbSynthesis_ivas_fx( &cldfb_in_ts_re_fx[idx_in][ts], &cldfb_in_ts_im_fx[idx_in][ts], &output_fx[ch][i_mult( ts, num_cldfb_bands )], num_cldfb_bands, st_ivas->cldfbSynDec[idx_in] ); } - Scale_sig32( output_fx[ch], out_len, 6 ); - Scale_sig32( st_ivas->cldfbSynDec[idx_in]->cldfb_state_fx, st_ivas->cldfbSynDec[idx_in]->p_filter_length, 6 ); + Scale_sig32( output_fx[ch], out_len, 6 ); /*Q11*/ + Scale_sig32( st_ivas->cldfbSynDec[idx_in]->cldfb_state_fx, st_ivas->cldfbSynDec[idx_in]->p_filter_length, 6 ); /*st_ivas->cldfbSynDec[idx_in]->Q_cldfb_state+6*/ st_ivas->cldfbSynDec[idx_in]->Q_cldfb_state = add( st_ivas->cldfbSynDec[idx_in]->Q_cldfb_state, 6 ); move16(); } @@ -3406,24 +3410,24 @@ void ivas_spar_dec_upmixer_sf_fx( /* CLDFB to time synthesis (overwrite mixer output) */ FOR( out_ch = 0; out_ch < numch_out_dirac; out_ch++ ) { - Scale_sig32( st_ivas->cldfbSynDec[out_ch]->cldfb_state_fx, st_ivas->cldfbSynDec[out_ch]->p_filter_length, -6 ); + Scale_sig32( st_ivas->cldfbSynDec[out_ch]->cldfb_state_fx, st_ivas->cldfbSynDec[out_ch]->p_filter_length, -6 ); /*st_ivas->cldfbSynDec[out_ch]->Q_cldfb_state-6*/ st_ivas->cldfbSynDec[out_ch]->Q_cldfb_state = sub( st_ivas->cldfbSynDec[out_ch]->Q_cldfb_state, 6 ); move16(); - Scale_sig32( output_fx[out_ch], out_len, -6 ); + Scale_sig32( output_fx[out_ch], out_len, -6 ); /*Q5*/ FOR( ts = 0; ts < hSpar->subframe_nbslots[hSpar->subframes_rendered]; ts++ ) { cldfbSynthesis_ivas_fx( &cldfb_in_ts_re_fx[out_ch][ts], &cldfb_in_ts_im_fx[out_ch][ts], &output_fx[out_ch][i_mult( ts, num_cldfb_bands )], num_cldfb_bands, st_ivas->cldfbSynDec[out_ch] ); } - Scale_sig32( output_fx[out_ch], out_len, 6 ); - Scale_sig32( st_ivas->cldfbSynDec[out_ch]->cldfb_state_fx, st_ivas->cldfbSynDec[out_ch]->p_filter_length, 6 ); + Scale_sig32( output_fx[out_ch], out_len, 6 ); /*Q11*/ + Scale_sig32( st_ivas->cldfbSynDec[out_ch]->cldfb_state_fx, st_ivas->cldfbSynDec[out_ch]->p_filter_length, 6 ); /*st_ivas->cldfbSynDec[out_ch]->Q_cldfb_state+6*/ st_ivas->cldfbSynDec[out_ch]->Q_cldfb_state = add( st_ivas->cldfbSynDec[out_ch]->Q_cldfb_state, 6 ); move16(); } } - hSpar->slots_rendered = add( hSpar->slots_rendered, hSpar->subframe_nbslots[hSpar->subframes_rendered] ); + hSpar->slots_rendered = add( hSpar->slots_rendered, hSpar->subframe_nbslots[hSpar->subframes_rendered] ); /*Q0*/ move16(); - hSpar->subframes_rendered = add( hSpar->subframes_rendered, 1 ); + hSpar->subframes_rendered = add( hSpar->subframes_rendered, 1 ); /*Q0*/ move16(); pop_wmops(); diff --git a/lib_dec/jbm_jb4sb.c b/lib_dec/jbm_jb4sb.c index 32c52ba3b..44d6abe4b 100644 --- a/lib_dec/jbm_jb4sb.c +++ b/lib_dec/jbm_jb4sb.c @@ -240,7 +240,7 @@ ivas_error JB4_Create( move32(); /* internal configuration values - do not change!!! */ h->timeScale = 0; - move32(); + move16(); h->frameDuration = 0; move32(); @@ -789,7 +789,7 @@ static Word16 JB4_adaptPlayout( *maxScaling = 0; move32(); stretchTime = false; - + move16(); /* switch type of current playout (first one, active, DTX) */ IF( !h->firstDataUnitPopped ) { diff --git a/lib_enc/cod_ace_fx.c b/lib_enc/cod_ace_fx.c index efa0e0d4c..262d8d424 100644 --- a/lib_enc/cod_ace_fx.c +++ b/lib_enc/cod_ace_fx.c @@ -98,7 +98,12 @@ Word16 coder_acelp_fx( /* o : SEGSNR for CL decision * /* Configure ACELP */ + +#ifndef MSAN_FIX hLPDmem->nbits = BITS_ALLOC_config_acelp( target_bits, st->coder_type, acelp_cfg, st->narrowBand, st->nb_subfr ); +#else + BITS_ALLOC_config_acelp( target_bits, st->coder_type, acelp_cfg, st->narrowBand, st->nb_subfr ); +#endif /* Init Framing parameters */ move16(); diff --git a/lib_enc/cod_tcx_fx.c b/lib_enc/cod_tcx_fx.c index e449b2420..86be7be4e 100644 --- a/lib_enc/cod_tcx_fx.c +++ b/lib_enc/cod_tcx_fx.c @@ -4394,7 +4394,9 @@ void coder_tcx_fx( Word16 winMDST[N_MAX + L_MDCT_OVLP_MAX]; Word16 *pWinMDST; Word16 left_overlap_mode, right_overlap_mode; +#ifndef MSAN_FIX LPD_state_HANDLE hLPDmem = st->hLPDmem; +#endif TCX_ENC_HANDLE hTcxEnc = st->hTcxEnc; left_overlap = right_overlap = -1; @@ -4560,7 +4562,9 @@ void coder_tcx_fx( st, hm_cfg ); +#ifndef MSAN_FIX hLPDmem->nbits = add( hLPDmem->nbits, add( tnsBits, ltpBits ) ); +#endif } diff --git a/lib_enc/core_enc_init.c b/lib_enc/core_enc_init.c index 8c01fae3b..fc2bef83c 100644 --- a/lib_enc/core_enc_init.c +++ b/lib_enc/core_enc_init.c @@ -722,12 +722,19 @@ static void init_tcx( hTcxEnc->spectrum[0] = hTcxEnc->spectrum_long; hTcxEnc->spectrum[1] = hTcxEnc->spectrum_long + N_TCX10_MAX; + #ifdef IVAS_FLOAT_FIXED hTcxEnc->spectrum_fx[0] = hTcxEnc->spectrum_long_fx; hTcxEnc->spectrum_fx[1] = hTcxEnc->spectrum_long_fx + N_TCX10_MAX; st->preemph_fac_flt = fix16_to_float( st->preemph_fac, Q15 ); #endif +#ifdef MSAN_FIX + set_zero( hTcxEnc->spectrum[0], N_TCX10_MAX ); + set_zero( hTcxEnc->spectrum[1], N_TCX10_MAX ); + set_zero_fx( hTcxEnc->spectrum_fx[0], N_TCX10_MAX ); + set_zero_fx( hTcxEnc->spectrum_fx[1], N_TCX10_MAX ); +#endif init_tcx_cfg( st->hTcxCfg, total_brate, st->sr_core, st->input_Fs, st->L_frame, st->bwidth, hTcxEnc->L_frameTCX, st->fscale, st->encoderLookahead_enc, st->encoderLookahead_FB, st->preemph_fac_flt, st->tcxonly, st->rf_mode, st->igf, diff --git a/lib_enc/ext_sig_ana.c b/lib_enc/ext_sig_ana.c index 2d1a7c3d6..33c3201b0 100644 --- a/lib_enc/ext_sig_ana.c +++ b/lib_enc/ext_sig_ana.c @@ -133,7 +133,6 @@ void core_signal_analysis_high_bitrate( #ifdef IVAS_FLOAT_FIXED_CONVERSIONS if ( st->element_mode == IVAS_CPE_DFT ) { - floatToFixed_arr( st->hTranDet->transientDetector.pSubblockEnergies->subblockNrgChange_flt, st->hTranDet->transientDetector.pSubblockEnergies->subblockNrgChange, Q7, NSUBBLOCKS + MAX_TD_DELAY ); hTcxEnc->tcxltp_norm_corr_past = float_to_fix16( hTcxEnc->tcxltp_norm_corr_past_flt, Q15 ); q_fac = Q_factor_arr( st->buf_wspeech_enc_flt, L_FRAME16k + L_SUBFR + L_FRAME16k + L_NEXT_MAX_16k + 320 ); floatToFixed_arr( st->buf_wspeech_enc_flt, buf_wspeech_enc_fx, q_fac, L_FRAME16k + L_SUBFR + L_FRAME16k + L_NEXT_MAX_16k + 320 ); @@ -149,7 +148,6 @@ void core_signal_analysis_high_bitrate( } else if ( st->element_mode != IVAS_CPE_MDCT ) { - floatToFixed_arr( st->hTranDet->transientDetector.pSubblockEnergies->subblockNrgChange_flt, st->hTranDet->transientDetector.pSubblockEnergies->subblockNrgChange, Q7, NSUBBLOCKS + MAX_TD_DELAY ); hTcxEnc->tcxltp_norm_corr_past = float_to_fix16( hTcxEnc->tcxltp_norm_corr_past_flt, Q15 ); q_fac = Q_factor_arr( st->buf_speech_enc_flt, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k ); floatToFixed_arr( st->buf_speech_enc_flt, buf_speech_enc_fx, q_fac, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k ); @@ -479,12 +477,6 @@ void core_signal_analysis_high_bitrate( // -1 = -32768 , Q=15 , ltp_gain // spectrum_fx[]=fixed( (float)spectrum[]) , Q=q_factor_spectrum floatToFixed_arrL( hTcxEnc->spectrum_long, hTcxEnc->spectrum_long_fx, q_factor_spectrum, N_MAX ); - - // subblockNrg=(fix)((float)subblockNrg_flt) - floatToFixed_arrL( st->hTranDet->transientDetector.pSubblockEnergies->subblockNrg_flt, st->hTranDet->transientDetector.pSubblockEnergies->subblockNrg, 7, 24 ); - - // subblockNrgChange=(fix)((float)subblockNrgChange_flt) - floatToFixed_arr( st->hTranDet->transientDetector.pSubblockEnergies->subblockNrgChange_flt, st->hTranDet->transientDetector.pSubblockEnergies->subblockNrgChange, 7, 24 ); #endif test(); TNSAnalysis_ivas_fx( st->hTcxCfg, L_frameTCX, st->hTcxCfg->tcx_coded_lines, transform_type[frameno], ( frameno == 0 ) && ( st->last_core == ACELP_CORE ), hTcxEnc->spectrum_fx[frameno], st->hTranDet, -32768, &hTcxEnc->tnsData[frameno], &hTcxEnc->fUseTns[frameno], NULL ); @@ -493,12 +485,6 @@ void core_signal_analysis_high_bitrate( { // conv params to float // spectrum[]=float( (fix)spectrum_fx[]) , Q=q_factor_spectrum fixedToFloat_arrL( hTcxEnc->spectrum_long_fx, hTcxEnc->spectrum_long, q_factor_spectrum, N_MAX ); - - // subblockNrg_flt=(float)((fixed)subblockNrg) - fixedToFloat_arrL( st->hTranDet->transientDetector.pSubblockEnergies->subblockNrg, st->hTranDet->transientDetector.pSubblockEnergies->subblockNrg_flt, 7, 24 ); - - // subblockNrgChange_flt=(float)((fixed)subblockNrgChange) - fixedToFloat_arr( st->hTranDet->transientDetector.pSubblockEnergies->subblockNrgChange, st->hTranDet->transientDetector.pSubblockEnergies->subblockNrgChange_flt, 7, 24 ); } #endif #endif diff --git a/lib_enc/init_enc.c b/lib_enc/init_enc.c index 5c23fee65..cb326efb2 100644 --- a/lib_enc/init_enc.c +++ b/lib_enc/init_enc.c @@ -890,6 +890,7 @@ ivas_error init_encoder( } #ifdef MSAN_FIX set_f( st->hTcxEnc->spectrum_long, 0, N_MAX ); + set32_fx( st->hTcxEnc->spectrum_long_fx, 0, N_MAX ); #endif // MSAN_FIX /* Share the memories for 2xTCX10/4xTCX5 and for TCX20 */ @@ -1057,6 +1058,16 @@ ivas_error init_encoder( { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Transient Detection\n" ) ); } +#ifdef IVAS_FLOAT_FIXED + IF( GT_16( st->element_mode, EVS_MONO ) ) + { + InitTransientDetection_ivas_fx( shl( div_l( st->input_Fs, FRAMES_PER_SEC ), 1 ), 0, st->hTranDet, 1 ); + } + ELSE + { + InitTransientDetection_ivas_fx( shl( div_l( st->input_Fs, FRAMES_PER_SEC ), 1 ), NS2SA_FX2( st->input_Fs, DELAY_FIR_RESAMPL_NS ), st->hTranDet, 0 ); + } +#else if ( st->element_mode > EVS_MONO ) { @@ -1066,6 +1077,7 @@ ivas_error init_encoder( { InitTransientDetection( (int16_t) ( st->input_Fs / FRAMES_PER_SEC ), NS2SA( st->input_Fs, DELAY_FIR_RESAMPL_NS ), st->hTranDet, 0 ); } +#endif /*-----------------------------------------------------------------* * IVAS parameters @@ -2329,16 +2341,16 @@ ivas_error init_encoder_ivas_fx( Word16 frame_length = BASOP_Util_Divide3232_Scale( st->input_Fs, FRAMES_PER_SEC, &temp ); frame_length = shr( frame_length, sub( 15, temp ) ); +#ifdef IVAS_FLOAT_FIXED IF( GT_16( st->element_mode, EVS_MONO ) ) { InitTransientDetection_ivas_fx( frame_length, 0, st->hTranDet, 1 ); } ELSE { - InitTransientDetection_ivas_fx( frame_length, NS2SA( st->input_Fs, DELAY_FIR_RESAMPL_NS ), st->hTranDet, 0 ); + InitTransientDetection_ivas_fx( frame_length, NS2SA_FX2( st->input_Fs, DELAY_FIR_RESAMPL_NS ), st->hTranDet, 0 ); } - -#if 1 +#else if ( GT_16( st->element_mode, EVS_MONO ) ) { InitTransientDetection( frame_length, 0, st->hTranDet, 1 ); diff --git a/lib_enc/ivas_core_enc.c b/lib_enc/ivas_core_enc.c index 75f550d91..6effecd94 100644 --- a/lib_enc/ivas_core_enc.c +++ b/lib_enc/ivas_core_enc.c @@ -237,11 +237,6 @@ ivas_error ivas_core_enc( st->hTcxEnc->tcxltp_norm_corr_past = (Word16) floatToFixed( st->hTcxEnc->tcxltp_norm_corr_past_flt, Q15 ); } - IF( st->hTranDet ) - { - floatToFixed_arr( st->hTranDet->subblockEnergies.subblockNrgChange_flt, st->hTranDet->subblockEnergies.subblockNrgChange, Q15 - NRG_CHANGE_E, NSUBBLOCKS + MAX_TD_DELAY ); - } - f2me( cor_map_sum[n], &cor_map_sum_fx, &exp_cor_map_sum ); q_fft_buff = Q_factor_arrL( fft_buff[n], ( 2 * L_FFT ) ); @@ -322,11 +317,6 @@ ivas_error ivas_core_enc( st->hTcxEnc->tfm_mem = fixedToFloat_32( st->hTcxEnc->tfm_mem_fx, Q31 ); st->hTcxEnc->tcxltp_norm_corr_past_flt = fixedToFloat_16( st->hTcxEnc->tcxltp_norm_corr_past, Q15 ); } - - IF( st->hTranDet ) - { - fixedToFloat_arr( st->hTranDet->subblockEnergies.subblockNrgChange, st->hTranDet->subblockEnergies.subblockNrgChange_flt, Q15 - NRG_CHANGE_E, NSUBBLOCKS + MAX_TD_DELAY ); - } #endif if ( st->element_mode == IVAS_CPE_MDCT || st->element_mode == IVAS_SCE ) diff --git a/lib_enc/ivas_core_pre_proc_front.c b/lib_enc/ivas_core_pre_proc_front.c index f7659715c..917c185cd 100644 --- a/lib_enc/ivas_core_pre_proc_front.c +++ b/lib_enc/ivas_core_pre_proc_front.c @@ -2922,30 +2922,29 @@ ivas_error pre_proc_front_ivas_fx( #ifdef IVAS_FLOAT_FIXED_CONVERSIONS IF( EQ_16( element_mode, IVAS_SCE ) ) { - Word16 q1 = Q_factor_arr( st->hTranDet->subblockEnergies.subblockNrg_flt, NSUBBLOCKS + MAX_TD_DELAY ); - Word16 q2 = Q_factor_arr( st->hTranDet->subblockEnergies.accSubblockNrg_flt, NSUBBLOCKS + MAX_TD_DELAY + 1 ); - - st->hTranDet->transientDetector.pSubblockEnergies->facAccSubblockNrg = float_to_fix16( st->hTranDet->transientDetector.pSubblockEnergies->facAccSubblockNrg_flt, Q15 ); - floatToFixed_arrL( st->hTranDet->subblockEnergies.subblockNrg_flt, st->hTranDet->subblockEnergies.subblockNrg, q1, NSUBBLOCKS + MAX_TD_DELAY ); - floatToFixed_arrL( st->hTranDet->subblockEnergies.accSubblockNrg_flt, st->hTranDet->subblockEnergies.accSubblockNrg, q2, NSUBBLOCKS + MAX_TD_DELAY + 1 ); - st->hTranDet->subblockEnergies.subblockNrg_e = 31 - q1; - st->hTranDet->subblockEnergies.accSubblockNrg_e = 31 - q2; + Word16 q1 = Q7; + Word16 q2 = Q7; + st->hTranDet->subblockEnergies.subblockNrg_e = sub( 31, q1 ); + st->hTranDet->subblockEnergies.accSubblockNrg_e = sub( 31, q2 ); + move16(); + move16(); + move16(); + move16(); } ELSE IF( EQ_16( element_mode, IVAS_CPE_DFT ) ) { FOR( i = 0; i < CPE_CHANNELS; i++ ) { - Word16 q1 = Q_factor_arr( hCPE->hCoreCoder[i]->hTranDet->subblockEnergies.subblockNrg_flt, NSUBBLOCKS + MAX_TD_DELAY ); - Word16 q2 = Q_factor_arr( hCPE->hCoreCoder[i]->hTranDet->subblockEnergies.accSubblockNrg_flt, NSUBBLOCKS + MAX_TD_DELAY + 1 ); - - hCPE->hCoreCoder[i]->hTranDet->transientDetector.pSubblockEnergies->facAccSubblockNrg = float_to_fix16( hCPE->hCoreCoder[i]->hTranDet->transientDetector.pSubblockEnergies->facAccSubblockNrg_flt, Q15 ); - floatToFixed_arrL( hCPE->hCoreCoder[i]->hTranDet->subblockEnergies.subblockNrg_flt, hCPE->hCoreCoder[i]->hTranDet->subblockEnergies.subblockNrg, q1, NSUBBLOCKS + MAX_TD_DELAY ); - floatToFixed_arrL( hCPE->hCoreCoder[i]->hTranDet->subblockEnergies.accSubblockNrg_flt, hCPE->hCoreCoder[i]->hTranDet->subblockEnergies.accSubblockNrg, q2, NSUBBLOCKS + MAX_TD_DELAY + 1 ); - hCPE->hCoreCoder[i]->hTranDet->subblockEnergies.subblockNrg_e = 31 - q1; - hCPE->hCoreCoder[i]->hTranDet->subblockEnergies.accSubblockNrg_e = 31 - q2; + Word16 q1 = Q7; + Word16 q2 = Q7; + hCPE->hCoreCoder[i]->hTranDet->subblockEnergies.subblockNrg_e = sub( 31, q1 ); + hCPE->hCoreCoder[i]->hTranDet->subblockEnergies.accSubblockNrg_e = sub( 31, q2 ); + move16(); + move16(); + move16(); + move16(); } } - #endif IF( EQ_16( element_mode, IVAS_SCE ) ) { @@ -2967,24 +2966,6 @@ ivas_error pre_proc_front_ivas_fx( } } } - -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - IF( EQ_16( element_mode, IVAS_SCE ) ) - { - fixedToFloat_arrL( st->hTranDet->subblockEnergies.subblockNrg, st->hTranDet->subblockEnergies.subblockNrg_flt, ( 31 - st->hTranDet->subblockEnergies.subblockNrg_e ), NSUBBLOCKS + MAX_TD_DELAY ); - fixedToFloat_arrL( st->hTranDet->subblockEnergies.accSubblockNrg, st->hTranDet->subblockEnergies.accSubblockNrg_flt, ( 31 - st->hTranDet->subblockEnergies.accSubblockNrg_e ), NSUBBLOCKS + MAX_TD_DELAY + 1 ); - st->hTranDet->transientDetector.pSubblockEnergies->facAccSubblockNrg_flt = fix16_to_float( st->hTranDet->transientDetector.pSubblockEnergies->facAccSubblockNrg, Q15 ); - } - ELSE IF( EQ_16( element_mode, IVAS_CPE_DFT ) ) - { - FOR( i = 0; i < CPE_CHANNELS; i++ ) - { - fixedToFloat_arrL( hCPE->hCoreCoder[i]->hTranDet->subblockEnergies.subblockNrg, hCPE->hCoreCoder[i]->hTranDet->subblockEnergies.subblockNrg_flt, ( 31 - hCPE->hCoreCoder[i]->hTranDet->subblockEnergies.subblockNrg_e ), NSUBBLOCKS + MAX_TD_DELAY ); - fixedToFloat_arrL( hCPE->hCoreCoder[i]->hTranDet->subblockEnergies.accSubblockNrg, hCPE->hCoreCoder[i]->hTranDet->subblockEnergies.accSubblockNrg_flt, ( 31 - hCPE->hCoreCoder[i]->hTranDet->subblockEnergies.accSubblockNrg_e ), NSUBBLOCKS + MAX_TD_DELAY + 1 ); - hCPE->hCoreCoder[i]->hTranDet->transientDetector.pSubblockEnergies->facAccSubblockNrg_flt = fix16_to_float( hCPE->hCoreCoder[i]->hTranDet->transientDetector.pSubblockEnergies->facAccSubblockNrg, Q15 ); - } - } -#endif #else if ( element_mode == IVAS_SCE ) { diff --git a/lib_enc/ivas_cpe_enc.c b/lib_enc/ivas_cpe_enc.c index 8ba98f4fd..62fb9ae70 100644 --- a/lib_enc/ivas_cpe_enc.c +++ b/lib_enc/ivas_cpe_enc.c @@ -471,57 +471,13 @@ ivas_error ivas_cpe_enc( { #ifdef IVAS_FLOAT_FIXED #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - sts[n]->hTranDet->subblockEnergies.firState1 = (Word16) floatToFixed( sts[n]->hTranDet->subblockEnergies.firState1_flt, -1 ); - sts[n]->hTranDet->subblockEnergies.firState2 = (Word16) floatToFixed( sts[n]->hTranDet->subblockEnergies.firState2_flt, -1 ); - - FOR( Word16 i = 0; i < NSUBBLOCKS + MAX_TD_DELAY + 1; i++ ) - { - sts[n]->hTranDet->subblockEnergies.accSubblockNrg[i] = floatToFixed( sts[n]->hTranDet->subblockEnergies.accSubblockNrg_flt[i], 7 ); - } - - FOR( Word16 i = 0; i < NSUBBLOCKS + MAX_TD_DELAY; i++ ) - { - sts[n]->hTranDet->subblockEnergies.subblockNrg[i] = floatToFixed( sts[n]->hTranDet->subblockEnergies.subblockNrg_flt[i], 7 ); - sts[n]->hTranDet->subblockEnergies.subblockNrgChange[i] = (Word16) floatToFixed( sts[n]->hTranDet->subblockEnergies.subblockNrgChange_flt[i], 7 ); - } - - - FOR( Word16 i = 0; i < L_FRAME_MAX / NSUBBLOCKS; i++ ) - { - sts[n]->hTranDet->delayBuffer.buffer[i] = (Word16) floatToFixed( sts[n]->hTranDet->delayBuffer.buffer_flt[i], -1 ); - } - - sts[n]->hTranDet->transientDetector.attackRatioThreshold = (Word16) floatToFixed( sts[n]->hTranDet->transientDetector.attackRatioThreshold_flt, 11 ); - floatToFixed_arr16( sts[n]->input, sts[n]->input_fx, -1, input_frame ); - - sts[n]->hTranDet->subblockEnergies.facAccSubblockNrg = float_to_fix16( sts[n]->hTranDet->subblockEnergies.facAccSubblockNrg_flt, 15 ); - #endif - RunTransientDetection_ivas_fx( sts[n]->input_fx, input_frame, sts[n]->hTranDet ); - -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - - sts[n]->hTranDet->subblockEnergies.firState1_flt = fixedToFloat( (Word32) sts[n]->hTranDet->subblockEnergies.firState1, -1 ); - sts[n]->hTranDet->subblockEnergies.firState2_flt = fixedToFloat( (Word32) sts[n]->hTranDet->subblockEnergies.firState2, -1 ); - - FOR( Word16 i = 0; i < NSUBBLOCKS + MAX_TD_DELAY; i++ ) - { - sts[n]->hTranDet->subblockEnergies.subblockNrg_flt[i] = fixedToFloat( sts[n]->hTranDet->subblockEnergies.subblockNrg[i], 7 ); - sts[n]->hTranDet->subblockEnergies.subblockNrgChange_flt[i] = fixedToFloat( (Word32) sts[n]->hTranDet->subblockEnergies.subblockNrgChange[i], 7 ); - } - - FOR( Word16 i = 0; i < NSUBBLOCKS + MAX_TD_DELAY + 1; i++ ) - { - sts[n]->hTranDet->subblockEnergies.accSubblockNrg_flt[i] = fixedToFloat( sts[n]->hTranDet->subblockEnergies.accSubblockNrg[i], 7 ); - } - - FOR( Word16 i = 0; i < L_FRAME_MAX / NSUBBLOCKS; i++ ) - { - sts[n]->hTranDet->delayBuffer.buffer_flt[i] = fixedToFloat( (Word32) sts[n]->hTranDet->delayBuffer.buffer[i], -1 ); - } -#endif + sts[n]->hTranDet->subblockEnergies.subblockNrg_e = 31 - Q7; + sts[n]->hTranDet->subblockEnergies.accSubblockNrg_e = 31 - Q7; + move16(); + move16(); #else RunTransientDetection( sts[n]->input, input_frame, sts[n]->hTranDet ); #endif @@ -529,9 +485,6 @@ ivas_error ivas_cpe_enc( #ifndef IVAS_FLOAT_FIXED currFlatness[n] = GetTCXAvgTemporalFlatnessMeasure( sts[n]->hTranDet, NSUBBLOCKS, 0 ); #else -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - floatToFixed_arr( sts[n]->hTranDet->transientDetector.pSubblockEnergies->subblockNrgChange_flt, sts[n]->hTranDet->transientDetector.pSubblockEnergies->subblockNrgChange, 7, NSUBBLOCKS + MAX_TD_DELAY ); -#endif currFlatness_fx[n] = GetTCXAvgTemporalFlatnessMeasure_ivas_fx( sts[n]->hTranDet, NSUBBLOCKS, 0 ); move16(); #ifdef IVAS_FLOAT_FIXED_CONVERSIONS diff --git a/lib_enc/ivas_dirac_enc.c b/lib_enc/ivas_dirac_enc.c index 1738910de..7891a753b 100644 --- a/lib_enc/ivas_dirac_enc.c +++ b/lib_enc/ivas_dirac_enc.c @@ -498,7 +498,7 @@ ivas_error ivas_dirac_enc( int16_t orig_dirac_bands; float dir[3], avg_dir[3]; #ifdef IVAS_FLOAT_FIXED - Word32 dir_fx[3] /*, avg_dir_fx[3]*/; + Word32 dir_fx[3], avg_dir_fx[3]; #endif float energySum, vecLen; int16_t i, j, b, i_ts; @@ -601,7 +601,7 @@ ivas_error ivas_dirac_enc( energySum += hDirAC->buffer_energy[i * orig_dirac_bands + j]; } -#ifdef IVAS_FLOAT_FIXED_ +#ifdef IVAS_FLOAT_FIXED /*==========================================flt-2-fix======================================================*/ Word16 q_dir_e = 0; f2me_buf( avg_dir, avg_dir_fx, &q_dir_e, 3 ); diff --git a/lib_enc/ivas_enc.c b/lib_enc/ivas_enc.c index 281bd0ff5..978bb371f 100644 --- a/lib_enc/ivas_enc.c +++ b/lib_enc/ivas_enc.c @@ -803,8 +803,6 @@ ivas_error ivas_enc( } for ( i = 0; i < st_ivas->hEncoderConfig->nchan_ism; i++ ) { - st_ivas->hIsmMetaData[i]->azimuth_fx = floatToFixed( st_ivas->hIsmMetaData[i]->azimuth, Q22 ); - st_ivas->hIsmMetaData[i]->elevation_fx = floatToFixed( st_ivas->hIsmMetaData[i]->elevation, Q22 ); floatToFixed_arr32( st_ivas->hParamIsm->hFbMixer->ppFilterbank_prior_input[i], st_ivas->hParamIsm->hFbMixer->ppFilterbank_prior_input_fx[i], Q14, st_ivas->hParamIsm->hFbMixer->fb_cfg->prior_input_length ); st_ivas->hParamIsm->last_cardioid_left_fx[i] = float_to_fix16( st_ivas->hParamIsm->last_cardioid_left[i], Q14 ); } @@ -824,7 +822,6 @@ ivas_error ivas_enc( } for ( i = 0; i < st_ivas->hEncoderConfig->nchan_ism; i++ ) { - st_ivas->hIsmMetaData[i]->azimuth_fx = floatToFixed( st_ivas->hIsmMetaData[i]->azimuth, Q22 ); fixedToFloat_arrL32( st_ivas->hParamIsm->hFbMixer->ppFilterbank_prior_input_fx[i], st_ivas->hParamIsm->hFbMixer->ppFilterbank_prior_input[i], Q14, st_ivas->hParamIsm->hFbMixer->fb_cfg->prior_input_length ); st_ivas->hParamIsm->last_cardioid_left[i] = fixedToFloat_16( st_ivas->hParamIsm->last_cardioid_left_fx[i], Q14 ); } @@ -870,31 +867,11 @@ ivas_error ivas_enc( #ifdef IVAS_FLOAT_FIXED #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - MASA_METADATA_HANDLE current_meta = &( st_ivas->hMasa->masaMetadata ); - MASA_METADATA_HANDLE previous_meta = &( st_ivas->hMasa->data.sync_state.previous_metadata ); - fixedToFloat_arrL( st_ivas->hMasa->data.importanceWeight_fx, st_ivas->hMasa->data.importanceWeight, 30, 24 ); for ( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) { for ( int j = 0; j < MASA_FREQUENCY_BANDS; j++ ) { - for ( int k = 0; k < MASA_MAXIMUM_DIRECTIONS; k++ ) - { - current_meta->directional_meta[k].azimuth_fx[i][j] = floatToFixed( current_meta->directional_meta[k].azimuth[i][j], Q22 ); - current_meta->directional_meta[k].elevation_fx[i][j] = floatToFixed( current_meta->directional_meta[k].elevation[i][j], Q22 ); - current_meta->directional_meta[k].energy_ratio_fx[i][j] = floatToFixed( current_meta->directional_meta[k].energy_ratio[i][j], Q30 ); - current_meta->directional_meta[k].spread_coherence_fx[i][j] = (Word16) min( 32767, floatToFixed( current_meta->directional_meta[k].spread_coherence[i][j], Q15 ) ); - previous_meta->directional_meta[k].azimuth_fx[i][j] = floatToFixed( previous_meta->directional_meta[k].azimuth[i][j], Q22 ); - previous_meta->directional_meta[k].elevation_fx[i][j] = floatToFixed( previous_meta->directional_meta[k].elevation[i][j], Q22 ); - previous_meta->directional_meta[k].energy_ratio_fx[i][j] = floatToFixed( previous_meta->directional_meta[k].energy_ratio[i][j], Q30 ); - previous_meta->directional_meta[k].spread_coherence_fx[i][j] = (Word16) min( 32767, floatToFixed( previous_meta->directional_meta[k].spread_coherence[i][j], Q15 ) ); - } f2me( st_ivas->hMasa->data.energy[i][j], &st_ivas->hMasa->data.energy_fx[i][j], &st_ivas->hMasa->data.energy_e[i][j] ); - current_meta->common_meta.surround_coherence_fx[i][j] = (Word16) min( 32767, floatToFixed( current_meta->common_meta.surround_coherence[i][j], Q15 ) ); - current_meta->common_meta.diffuse_to_total_ratio_fx[i][j] = floatToFixed( current_meta->common_meta.diffuse_to_total_ratio[i][j], Q30 ); - current_meta->common_meta.remainder_to_total_ratio_fx[i][j] = floatToFixed( current_meta->common_meta.remainder_to_total_ratio[i][j], Q30 ); - previous_meta->common_meta.surround_coherence_fx[i][j] = (Word16) min( 32767, floatToFixed( previous_meta->common_meta.surround_coherence[i][j], Q15 ) ); - previous_meta->common_meta.diffuse_to_total_ratio_fx[i][j] = floatToFixed( previous_meta->common_meta.diffuse_to_total_ratio[i][j], Q30 ); - previous_meta->common_meta.remainder_to_total_ratio_fx[i][j] = floatToFixed( previous_meta->common_meta.remainder_to_total_ratio[i][j], Q30 ); } } @@ -904,29 +881,6 @@ ivas_error ivas_enc( return error; } #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - for ( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) - { - for ( int j = 0; j < MASA_FREQUENCY_BANDS; j++ ) - { - for ( int k = 0; k < MASA_MAXIMUM_DIRECTIONS; k++ ) - { - current_meta->directional_meta[k].azimuth[i][j] = fixedToFloat( current_meta->directional_meta[k].azimuth_fx[i][j], Q22 ); - current_meta->directional_meta[k].elevation[i][j] = fixedToFloat( current_meta->directional_meta[k].elevation_fx[i][j], Q22 ); - current_meta->directional_meta[k].energy_ratio[i][j] = fixedToFloat( current_meta->directional_meta[k].energy_ratio_fx[i][j], Q30 ); - current_meta->directional_meta[k].spread_coherence[i][j] = fixedToFloat( current_meta->directional_meta[k].spread_coherence_fx[i][j], Q15 ); - previous_meta->directional_meta[k].azimuth[i][j] = fixedToFloat( previous_meta->directional_meta[k].azimuth_fx[i][j], Q22 ); - previous_meta->directional_meta[k].elevation[i][j] = fixedToFloat( previous_meta->directional_meta[k].elevation_fx[i][j], Q22 ); - previous_meta->directional_meta[k].energy_ratio[i][j] = fixedToFloat( previous_meta->directional_meta[k].energy_ratio_fx[i][j], Q30 ); - previous_meta->directional_meta[k].spread_coherence[i][j] = fixedToFloat( previous_meta->directional_meta[k].spread_coherence_fx[i][j], Q15 ); - } - current_meta->common_meta.surround_coherence[i][j] = fixedToFloat( current_meta->common_meta.surround_coherence_fx[i][j], Q15 ); - current_meta->common_meta.diffuse_to_total_ratio[i][j] = fixedToFloat( current_meta->common_meta.diffuse_to_total_ratio_fx[i][j], Q30 ); - current_meta->common_meta.remainder_to_total_ratio[i][j] = fixedToFloat( current_meta->common_meta.remainder_to_total_ratio_fx[i][j], Q30 ); - previous_meta->common_meta.surround_coherence[i][j] = fixedToFloat( previous_meta->common_meta.surround_coherence_fx[i][j], Q15 ); - previous_meta->common_meta.diffuse_to_total_ratio[i][j] = fixedToFloat( previous_meta->common_meta.diffuse_to_total_ratio_fx[i][j], Q30 ); - previous_meta->common_meta.remainder_to_total_ratio[i][j] = fixedToFloat( previous_meta->common_meta.remainder_to_total_ratio_fx[i][j], Q30 ); - } - } if ( st_ivas->hQMetaData->q_direction ) { for ( int band = 0; band < st_ivas->hMasa->config.numCodingBands; band++ ) @@ -942,7 +896,6 @@ ivas_error ivas_enc( } } } - fixedToFloat_arrL( st_ivas->hMasa->data.importanceWeight_fx, st_ivas->hMasa->data.importanceWeight, 30, 24 ); #endif // IVAS_FLOAT_FIXED_CONVERSIONS #else if ( ( error = ivas_masa_enc_config( st_ivas ) ) != IVAS_ERR_OK ) @@ -1016,31 +969,11 @@ ivas_error ivas_enc( #ifdef IVAS_FLOAT_FIXED #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - MASA_METADATA_HANDLE current_meta = &( st_ivas->hMasa->masaMetadata ); - MASA_METADATA_HANDLE previous_meta = &( st_ivas->hMasa->data.sync_state.previous_metadata ); - fixedToFloat_arrL( st_ivas->hMasa->data.importanceWeight_fx, st_ivas->hMasa->data.importanceWeight, 30, 24 ); for ( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) { for ( int j = 0; j < MASA_FREQUENCY_BANDS; j++ ) { - for ( int k = 0; k < MASA_MAXIMUM_DIRECTIONS; k++ ) - { - current_meta->directional_meta[k].azimuth_fx[i][j] = floatToFixed( current_meta->directional_meta[k].azimuth[i][j], Q22 ); - current_meta->directional_meta[k].elevation_fx[i][j] = floatToFixed( current_meta->directional_meta[k].elevation[i][j], Q22 ); - current_meta->directional_meta[k].energy_ratio_fx[i][j] = floatToFixed( current_meta->directional_meta[k].energy_ratio[i][j], Q30 ); - current_meta->directional_meta[k].spread_coherence_fx[i][j] = (Word16) min( 32767, floatToFixed( current_meta->directional_meta[k].spread_coherence[i][j], Q15 ) ); - previous_meta->directional_meta[k].azimuth_fx[i][j] = floatToFixed( previous_meta->directional_meta[k].azimuth[i][j], Q22 ); - previous_meta->directional_meta[k].elevation_fx[i][j] = floatToFixed( previous_meta->directional_meta[k].elevation[i][j], Q22 ); - previous_meta->directional_meta[k].energy_ratio_fx[i][j] = floatToFixed( previous_meta->directional_meta[k].energy_ratio[i][j], Q30 ); - previous_meta->directional_meta[k].spread_coherence_fx[i][j] = (Word16) min( 32767, floatToFixed( previous_meta->directional_meta[k].spread_coherence[i][j], Q15 ) ); - } f2me( st_ivas->hMasa->data.energy[i][j], &st_ivas->hMasa->data.energy_fx[i][j], &st_ivas->hMasa->data.energy_e[i][j] ); - current_meta->common_meta.surround_coherence_fx[i][j] = (Word16) min( 32767, floatToFixed( current_meta->common_meta.surround_coherence[i][j], Q15 ) ); - current_meta->common_meta.diffuse_to_total_ratio_fx[i][j] = floatToFixed( current_meta->common_meta.diffuse_to_total_ratio[i][j], Q30 ); - current_meta->common_meta.remainder_to_total_ratio_fx[i][j] = floatToFixed( current_meta->common_meta.remainder_to_total_ratio[i][j], Q30 ); - previous_meta->common_meta.surround_coherence_fx[i][j] = (Word16) min( 32767, floatToFixed( previous_meta->common_meta.surround_coherence[i][j], Q15 ) ); - previous_meta->common_meta.diffuse_to_total_ratio_fx[i][j] = floatToFixed( previous_meta->common_meta.diffuse_to_total_ratio[i][j], Q30 ); - previous_meta->common_meta.remainder_to_total_ratio_fx[i][j] = floatToFixed( previous_meta->common_meta.remainder_to_total_ratio[i][j], Q30 ); } } #endif // IVAS_FLOAT_FIXED_CONVERSIONS @@ -1049,29 +982,6 @@ ivas_error ivas_enc( return error; } #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - for ( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) - { - for ( int j = 0; j < MASA_FREQUENCY_BANDS; j++ ) - { - for ( int k = 0; k < MASA_MAXIMUM_DIRECTIONS; k++ ) - { - current_meta->directional_meta[k].azimuth[i][j] = fixedToFloat( current_meta->directional_meta[k].azimuth_fx[i][j], Q22 ); - current_meta->directional_meta[k].elevation[i][j] = fixedToFloat( current_meta->directional_meta[k].elevation_fx[i][j], Q22 ); - current_meta->directional_meta[k].energy_ratio[i][j] = fixedToFloat( current_meta->directional_meta[k].energy_ratio_fx[i][j], Q30 ); - current_meta->directional_meta[k].spread_coherence[i][j] = fixedToFloat( current_meta->directional_meta[k].spread_coherence_fx[i][j], Q15 ); - previous_meta->directional_meta[k].azimuth[i][j] = fixedToFloat( previous_meta->directional_meta[k].azimuth_fx[i][j], Q22 ); - previous_meta->directional_meta[k].elevation[i][j] = fixedToFloat( previous_meta->directional_meta[k].elevation_fx[i][j], Q22 ); - previous_meta->directional_meta[k].energy_ratio[i][j] = fixedToFloat( previous_meta->directional_meta[k].energy_ratio_fx[i][j], Q30 ); - previous_meta->directional_meta[k].spread_coherence[i][j] = fixedToFloat( previous_meta->directional_meta[k].spread_coherence_fx[i][j], Q15 ); - } - current_meta->common_meta.surround_coherence[i][j] = fixedToFloat( current_meta->common_meta.surround_coherence_fx[i][j], Q15 ); - current_meta->common_meta.diffuse_to_total_ratio[i][j] = fixedToFloat( current_meta->common_meta.diffuse_to_total_ratio_fx[i][j], Q30 ); - current_meta->common_meta.remainder_to_total_ratio[i][j] = fixedToFloat( current_meta->common_meta.remainder_to_total_ratio_fx[i][j], Q30 ); - previous_meta->common_meta.surround_coherence[i][j] = fixedToFloat( previous_meta->common_meta.surround_coherence_fx[i][j], Q15 ); - previous_meta->common_meta.diffuse_to_total_ratio[i][j] = fixedToFloat( previous_meta->common_meta.diffuse_to_total_ratio_fx[i][j], Q30 ); - previous_meta->common_meta.remainder_to_total_ratio[i][j] = fixedToFloat( previous_meta->common_meta.remainder_to_total_ratio_fx[i][j], Q30 ); - } - } if ( st_ivas->hQMetaData->q_direction ) { for ( int band = 0; band < st_ivas->hMasa->config.numCodingBands; band++ ) @@ -1087,7 +997,6 @@ ivas_error ivas_enc( } } } - fixedToFloat_arrL( st_ivas->hMasa->data.importanceWeight_fx, st_ivas->hMasa->data.importanceWeight, 30, 24 ); #endif // IVAS_FLOAT_FIXED_CONVERSIONS #else if ( ( error = ivas_omasa_enc_config( st_ivas ) ) != IVAS_ERR_OK ) @@ -1112,19 +1021,6 @@ ivas_error ivas_enc( int16_t j; int16_t nchan_transport = st_ivas->nchan_transport; int16_t nchan_ism = hEncoderConfig->nchan_ism; - Word16 block_m_idx, band_m_idx; - for ( block_m_idx = 0; block_m_idx < hOMasa->nSubframes; block_m_idx++ ) - { - for ( band_m_idx = 0; band_m_idx < hOMasa->nbands; band_m_idx++ ) - { - hMasa->data.hOmasaData->energy_ism_fx[block_m_idx][band_m_idx] = floatToFixed( hMasa->data.hOmasaData->energy_ism[block_m_idx][band_m_idx], 31 - hMasa->data.hOmasaData->energy_ism_fx_e[block_m_idx][band_m_idx] ); - } - } - for ( i = 0; i < nchan_ism; i++ ) - { - st_ivas->hIsmMetaData[i]->azimuth_fx = float_to_fix( st_ivas->hIsmMetaData[i]->azimuth, Q22 ); - st_ivas->hIsmMetaData[i]->elevation_fx = float_to_fix( st_ivas->hIsmMetaData[i]->elevation, Q22 ); - } int16_t norm_data_in = MAX16B; for ( j = 0; j < nchan_ism + nchan_transport; j++ ) { @@ -1144,76 +1040,31 @@ ivas_error ivas_enc( { floatToFixed_arrL( hOMasa->cldfbAnaEnc[i]->cldfb_state, hOMasa->cldfbAnaEnc[i]->cldfb_state_fx, st_ivas->q_data_fx, hOMasa->cldfbAnaEnc[i]->cldfb_state_length ); } - // int16_t numSf = hMasa->config.joinedSubframes == TRUE ? 1 : 4; for ( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) { for ( j = 0; j < MASA_FREQUENCY_BANDS; j++ ) { f2me( hMasa->data.energy[i][j], &hMasa->data.energy_fx[i][j], &hMasa->data.energy_e[i][j] ); - for ( int k = 0; k < hMasa->config.numberOfDirections; k++ ) - { - hMasa->masaMetadata.directional_meta[k].energy_ratio_fx[i][j] = float_to_fix( hMasa->masaMetadata.directional_meta[k].energy_ratio[i][j], 30 ); - hMasa->masaMetadata.directional_meta[k].azimuth_fx[i][j] = float_to_fix( hMasa->masaMetadata.directional_meta[k].azimuth[i][j], 22 ); - hMasa->masaMetadata.directional_meta[k].elevation_fx[i][j] = float_to_fix( hMasa->masaMetadata.directional_meta[k].elevation[i][j], 22 ); - hMasa->masaMetadata.directional_meta[k].spread_coherence_fx[i][j] = float_to_fix16( hMasa->masaMetadata.directional_meta[k].spread_coherence[i][j], 15 ); - } - hMasa->masaMetadata.common_meta.surround_coherence_fx[i][j] = float_to_fix16( hMasa->masaMetadata.common_meta.surround_coherence[i][j], 15 ); - hMasa->masaMetadata.common_meta.diffuse_to_total_ratio_fx[i][j] = float_to_fix( hMasa->masaMetadata.common_meta.diffuse_to_total_ratio[i][j], 30 ); } } - for ( i = 0; i < MASA_FREQUENCY_BANDS; i++ ) - { - hMasa->data.importanceWeight_fx[i] = floatToFixed( hMasa->data.importanceWeight[i], Q30 ); - } #endif ivas_omasa_enc_fx( st_ivas->hOMasa, st_ivas->hMasa, st_ivas->hIsmMetaData, data_fx, st_ivas->q_data_fx, input_frame, st_ivas->nchan_transport, hEncoderConfig->nchan_ism, st_ivas->ism_mode, data_separated_object_fx, &idx_separated_object ); #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - for ( block_m_idx = 0; block_m_idx < hOMasa->nSubframes; block_m_idx++ ) - { - for ( band_m_idx = 0; band_m_idx < hOMasa->nbands; band_m_idx++ ) - { - hMasa->data.hOmasaData->energy_ism[block_m_idx][band_m_idx] = me2f( hMasa->data.hOmasaData->energy_ism_fx[block_m_idx][band_m_idx], hMasa->data.hOmasaData->energy_ism_fx_e[block_m_idx][band_m_idx] ); - } - } for ( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) { for ( j = 0; j < MASA_FREQUENCY_BANDS; j++ ) { hMasa->data.energy[i][j] = me2f( hMasa->data.energy_fx[i][j], hMasa->data.energy_e[i][j] ); - for ( int k = 0; k < hMasa->config.numberOfDirections; k++ ) - { - hMasa->masaMetadata.directional_meta[k].energy_ratio[i][j] = fix_to_float( hMasa->masaMetadata.directional_meta[k].energy_ratio_fx[i][j], 30 ); - hMasa->masaMetadata.directional_meta[k].azimuth[i][j] = fix_to_float( hMasa->masaMetadata.directional_meta[k].azimuth_fx[i][j], 22 ); - hMasa->masaMetadata.directional_meta[k].elevation[i][j] = fix_to_float( hMasa->masaMetadata.directional_meta[k].elevation_fx[i][j], 22 ); - hMasa->masaMetadata.directional_meta[k].spread_coherence[i][j] = fix_to_float( hMasa->masaMetadata.directional_meta[k].spread_coherence_fx[i][j], 15 ); - } - hMasa->masaMetadata.common_meta.surround_coherence[i][j] = fix_to_float( hMasa->masaMetadata.common_meta.surround_coherence_fx[i][j], 15 ); - hMasa->masaMetadata.common_meta.diffuse_to_total_ratio[i][j] = fix_to_float( hMasa->masaMetadata.common_meta.diffuse_to_total_ratio_fx[i][j], 30 ); } } for ( i = 0; i < nchan_ism; i++ ) { fixedToFloat_arrL( hOMasa->cldfbAnaEnc[i]->cldfb_state_fx, hOMasa->cldfbAnaEnc[i]->cldfb_state, st_ivas->q_data_fx, hOMasa->cldfbAnaEnc[i]->cldfb_state_length ); } - for ( block_m_idx = 0; block_m_idx < hOMasa->nSubframes; block_m_idx++ ) - { - for ( i = 0; i < hOMasa->nbands; i++ ) - { - for ( int k = 0; k < nchan_ism; k++ ) - { - hMasa->data.hOmasaData->energy_ratio_ism[block_m_idx][i][k] = me2f( hMasa->data.hOmasaData->energy_ratio_ism_fx[block_m_idx][i][k], 1 ); - } - } - } for ( i = 0; i < nchan_ism + nchan_transport; i++ ) { fixedToFloat_arrL( data_fx[i], data_f[i], st_ivas->q_data_fx, input_frame ); } - for ( i = 0; i < nchan_ism; i++ ) - { - st_ivas->hIsmMetaData[i]->azimuth = fixedToFloat( st_ivas->hIsmMetaData[i]->azimuth_fx, Q22 ); - st_ivas->hIsmMetaData[i]->elevation = fixedToFloat( st_ivas->hIsmMetaData[i]->elevation_fx, Q22 ); - } fixedToFloat_arrL( data_separated_object_fx, data_separated_object, st_ivas->q_data_fx, input_frame ); #endif // IVAS_FLOAT_FIXED_CONVERSIONS } @@ -1517,10 +1368,6 @@ ivas_error ivas_enc( #endif ivas_mcmasa_enc_fx( st_ivas->hMcMasa, st_ivas->hQMetaData, st_ivas->hMasa, data_fx, input_frame, st_ivas->nchan_transport, nchan_inp, q_data ); #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - FOR( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) - { - st_ivas->hMasa->data.lfeToTotalEnergyRatio[i] = st_ivas->hMasa->data.lfeToTotalEnergyRatio_fx[i] / (float) ( 1 << ( Q15 - st_ivas->hMasa->data.lfeToTotalEnergyRatio_e[i] ) ); - } for ( i = 0; i < nchan_inp; i++ ) { fixedToFloat_arrL( data_fx[i], data_f[i], q_data, input_frame ); diff --git a/lib_enc/ivas_enc_cov_handler.c b/lib_enc/ivas_enc_cov_handler.c index f2ee3a9d6..7c5223b42 100644 --- a/lib_enc/ivas_enc_cov_handler.c +++ b/lib_enc/ivas_enc_cov_handler.c @@ -60,7 +60,7 @@ *------------------------------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED -static void ivas_band_cov_fx( Word32 **ppIn_FR_real, Word32 **ppIn_FR_imag, Word16 *q_In_FR, const Word16 num_chans, const Word16 num_bins, Word16 stride, Word32 **pFb_bin_to_band, const Word16 *pFb_start_bin_per_band, const Word16 *pFb_active_bins_per_band, const Word16 start_band, const Word16 end_band, Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], Word16 *q_cov_real[IVAS_SPAR_MAX_CH], const Word16 HOA_md_ind[IVAS_SPAR_MAX_CH] ); +static void ivas_band_cov_fx( Word32 **ppIn_FR_real, Word32 **ppIn_FR_imag, Word16 q_In_FR, const Word16 num_chans, const Word16 num_bins, Word16 stride, Word32 **pFb_bin_to_band, const Word16 *pFb_start_bin_per_band, const Word16 *pFb_active_bins_per_band, const Word16 start_band, const Word16 end_band, Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], Word16 *q_cov_real[IVAS_SPAR_MAX_CH], const Word16 HOA_md_ind[IVAS_SPAR_MAX_CH] ); #else static void ivas_band_cov( float **ppIn_FR_real, float **ppIn_FR_imag, const int16_t num_chans, const int16_t num_bins, int16_t stride, float **pFb_bin_to_band, const int16_t *pFb_start_bin_per_band, const int16_t *pFb_active_bins_per_band, const int16_t start_band, const int16_t end_band, float *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], const int16_t HOA_md_ind[IVAS_SPAR_MAX_CH] ); #endif @@ -547,7 +547,7 @@ void ivas_enc_cov_handler_process_fx( ivas_enc_cov_handler_state_t *hCovEnc, /* i/o: SPAR Covar. encoder handle */ Word32 **ppIn_FR_real, Word32 **ppIn_FR_imag, - Word16 *q_ppIn_FR, + Word16 q_ppIn_FR, Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], Word16 *q_cov_real[IVAS_SPAR_MAX_CH], Word32 *cov_dtx_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], @@ -819,7 +819,7 @@ void ivas_enc_cov_handler_process( static void ivas_band_cov_fx( Word32 **ppIn_FR_real, Word32 **ppIn_FR_imag, - Word16 *q_In_FR, + Word16 q_In_FR, const Word16 num_chans, const Word16 num_bins, Word16 stride, @@ -905,7 +905,7 @@ static void ivas_band_cov_fx( cov_real_64bit[i][j][k] = temp * (Word64) ( num_blocks ); // (q_In_FR[i1] + q_In_FR[j1] + (q_shift - 10) - guard_bits move64(); } - q_cov_real[i][j] = add( add( q_In_FR[i1], q_In_FR[j1] ), sub( q_shift, Q10 ) ); + q_cov_real[i][j] = add( add( q_In_FR, q_In_FR ), sub( q_shift, Q10 ) ); move16(); } } diff --git a/lib_enc/ivas_init_enc.c b/lib_enc/ivas_init_enc.c index 4d6376af1..1d77e746c 100644 --- a/lib_enc/ivas_init_enc.c +++ b/lib_enc/ivas_init_enc.c @@ -1204,31 +1204,11 @@ ivas_error ivas_init_encoder( } #else #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - MASA_METADATA_HANDLE current_meta = &( st_ivas->hMasa->masaMetadata ); - MASA_METADATA_HANDLE previous_meta = &( st_ivas->hMasa->data.sync_state.previous_metadata ); - fixedToFloat_arrL( st_ivas->hMasa->data.importanceWeight_fx, st_ivas->hMasa->data.importanceWeight, 30, 24 ); for ( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) { for ( int j = 0; j < MASA_FREQUENCY_BANDS; j++ ) { - for ( int k = 0; k < MASA_MAXIMUM_DIRECTIONS; k++ ) - { - current_meta->directional_meta[k].azimuth_fx[i][j] = floatToFixed( current_meta->directional_meta[k].azimuth[i][j], Q22 ); - current_meta->directional_meta[k].elevation_fx[i][j] = floatToFixed( current_meta->directional_meta[k].elevation[i][j], Q22 ); - current_meta->directional_meta[k].energy_ratio_fx[i][j] = floatToFixed( current_meta->directional_meta[k].energy_ratio[i][j], Q30 ); - current_meta->directional_meta[k].spread_coherence_fx[i][j] = (Word16) min( 32767, floatToFixed( current_meta->directional_meta[k].spread_coherence[i][j], Q15 ) ); - previous_meta->directional_meta[k].azimuth_fx[i][j] = floatToFixed( previous_meta->directional_meta[k].azimuth[i][j], Q22 ); - previous_meta->directional_meta[k].elevation_fx[i][j] = floatToFixed( previous_meta->directional_meta[k].elevation[i][j], Q22 ); - previous_meta->directional_meta[k].energy_ratio_fx[i][j] = floatToFixed( previous_meta->directional_meta[k].energy_ratio[i][j], Q30 ); - previous_meta->directional_meta[k].spread_coherence_fx[i][j] = (Word16) min( 32767, floatToFixed( previous_meta->directional_meta[k].spread_coherence[i][j], Q15 ) ); - } f2me( st_ivas->hMasa->data.energy[i][j], &st_ivas->hMasa->data.energy_fx[i][j], &st_ivas->hMasa->data.energy_e[i][j] ); - current_meta->common_meta.surround_coherence_fx[i][j] = (Word16) min( 32767, floatToFixed( current_meta->common_meta.surround_coherence[i][j], Q15 ) ); - current_meta->common_meta.diffuse_to_total_ratio_fx[i][j] = floatToFixed( current_meta->common_meta.diffuse_to_total_ratio[i][j], Q30 ); - current_meta->common_meta.remainder_to_total_ratio_fx[i][j] = floatToFixed( current_meta->common_meta.remainder_to_total_ratio[i][j], Q30 ); - previous_meta->common_meta.surround_coherence_fx[i][j] = (Word16) min( 32767, floatToFixed( previous_meta->common_meta.surround_coherence[i][j], Q15 ) ); - previous_meta->common_meta.diffuse_to_total_ratio_fx[i][j] = floatToFixed( previous_meta->common_meta.diffuse_to_total_ratio[i][j], Q30 ); - previous_meta->common_meta.remainder_to_total_ratio_fx[i][j] = floatToFixed( previous_meta->common_meta.remainder_to_total_ratio[i][j], Q30 ); } } #endif // IVAS_FLOAT_FIXED_CONVERSIONS @@ -1238,29 +1218,6 @@ ivas_error ivas_init_encoder( } #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - for ( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) - { - for ( int j = 0; j < MASA_FREQUENCY_BANDS; j++ ) - { - for ( int k = 0; k < MASA_MAXIMUM_DIRECTIONS; k++ ) - { - current_meta->directional_meta[k].azimuth[i][j] = fixedToFloat( current_meta->directional_meta[k].azimuth_fx[i][j], Q22 ); - current_meta->directional_meta[k].elevation[i][j] = fixedToFloat( current_meta->directional_meta[k].elevation_fx[i][j], Q22 ); - current_meta->directional_meta[k].energy_ratio[i][j] = fixedToFloat( current_meta->directional_meta[k].energy_ratio_fx[i][j], Q30 ); - current_meta->directional_meta[k].spread_coherence[i][j] = fixedToFloat( current_meta->directional_meta[k].spread_coherence_fx[i][j], Q15 ); - previous_meta->directional_meta[k].azimuth[i][j] = fixedToFloat( previous_meta->directional_meta[k].azimuth_fx[i][j], Q22 ); - previous_meta->directional_meta[k].elevation[i][j] = fixedToFloat( previous_meta->directional_meta[k].elevation_fx[i][j], Q22 ); - previous_meta->directional_meta[k].energy_ratio[i][j] = fixedToFloat( previous_meta->directional_meta[k].energy_ratio_fx[i][j], Q30 ); - previous_meta->directional_meta[k].spread_coherence[i][j] = fixedToFloat( previous_meta->directional_meta[k].spread_coherence_fx[i][j], Q15 ); - } - current_meta->common_meta.surround_coherence[i][j] = fixedToFloat( current_meta->common_meta.surround_coherence_fx[i][j], Q15 ); - current_meta->common_meta.diffuse_to_total_ratio[i][j] = fixedToFloat( current_meta->common_meta.diffuse_to_total_ratio_fx[i][j], Q30 ); - current_meta->common_meta.remainder_to_total_ratio[i][j] = fixedToFloat( current_meta->common_meta.remainder_to_total_ratio_fx[i][j], Q30 ); - previous_meta->common_meta.surround_coherence[i][j] = fixedToFloat( previous_meta->common_meta.surround_coherence_fx[i][j], Q15 ); - previous_meta->common_meta.diffuse_to_total_ratio[i][j] = fixedToFloat( previous_meta->common_meta.diffuse_to_total_ratio_fx[i][j], Q30 ); - previous_meta->common_meta.remainder_to_total_ratio[i][j] = fixedToFloat( previous_meta->common_meta.remainder_to_total_ratio_fx[i][j], Q30 ); - } - } if ( st_ivas->hQMetaData->q_direction != NULL ) { for ( int band = 0; band < st_ivas->hMasa->config.numCodingBands; band++ ) @@ -1276,7 +1233,6 @@ ivas_error ivas_init_encoder( } } } - fixedToFloat_arrL( st_ivas->hMasa->data.importanceWeight_fx, st_ivas->hMasa->data.importanceWeight, 30, 24 ); #endif #endif // IVAS_FLOAT_FIXED_CONVERSIONS @@ -1923,31 +1879,11 @@ ivas_error ivas_init_encoder_fx( } #else #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - MASA_METADATA_HANDLE current_meta = &( st_ivas->hMasa->masaMetadata ); - MASA_METADATA_HANDLE previous_meta = &( st_ivas->hMasa->data.sync_state.previous_metadata ); - fixedToFloat_arrL( st_ivas->hMasa->data.importanceWeight_fx, st_ivas->hMasa->data.importanceWeight, 30, 24 ); for ( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) { for ( int j = 0; j < MASA_FREQUENCY_BANDS; j++ ) { - for ( int k = 0; k < MASA_MAXIMUM_DIRECTIONS; k++ ) - { - current_meta->directional_meta[k].azimuth_fx[i][j] = floatToFixed( current_meta->directional_meta[k].azimuth[i][j], Q22 ); - current_meta->directional_meta[k].elevation_fx[i][j] = floatToFixed( current_meta->directional_meta[k].elevation[i][j], Q22 ); - current_meta->directional_meta[k].energy_ratio_fx[i][j] = floatToFixed( current_meta->directional_meta[k].energy_ratio[i][j], Q30 ); - current_meta->directional_meta[k].spread_coherence_fx[i][j] = (Word16) min( 32767, floatToFixed( current_meta->directional_meta[k].spread_coherence[i][j], Q15 ) ); - previous_meta->directional_meta[k].azimuth_fx[i][j] = floatToFixed( previous_meta->directional_meta[k].azimuth[i][j], Q22 ); - previous_meta->directional_meta[k].elevation_fx[i][j] = floatToFixed( previous_meta->directional_meta[k].elevation[i][j], Q22 ); - previous_meta->directional_meta[k].energy_ratio_fx[i][j] = floatToFixed( previous_meta->directional_meta[k].energy_ratio[i][j], Q30 ); - previous_meta->directional_meta[k].spread_coherence_fx[i][j] = (Word16) min( 32767, floatToFixed( previous_meta->directional_meta[k].spread_coherence[i][j], Q15 ) ); - } f2me( st_ivas->hMasa->data.energy[i][j], &st_ivas->hMasa->data.energy_fx[i][j], &st_ivas->hMasa->data.energy_e[i][j] ); - current_meta->common_meta.surround_coherence_fx[i][j] = (Word16) min( 32767, floatToFixed( current_meta->common_meta.surround_coherence[i][j], Q15 ) ); - current_meta->common_meta.diffuse_to_total_ratio_fx[i][j] = floatToFixed( current_meta->common_meta.diffuse_to_total_ratio[i][j], Q30 ); - current_meta->common_meta.remainder_to_total_ratio_fx[i][j] = floatToFixed( current_meta->common_meta.remainder_to_total_ratio[i][j], Q30 ); - previous_meta->common_meta.surround_coherence_fx[i][j] = (Word16) min( 32767, floatToFixed( previous_meta->common_meta.surround_coherence[i][j], Q15 ) ); - previous_meta->common_meta.diffuse_to_total_ratio_fx[i][j] = floatToFixed( previous_meta->common_meta.diffuse_to_total_ratio[i][j], Q30 ); - previous_meta->common_meta.remainder_to_total_ratio_fx[i][j] = floatToFixed( previous_meta->common_meta.remainder_to_total_ratio[i][j], Q30 ); } } #endif // IVAS_FLOAT_FIXED_CONVERSIONS @@ -1957,29 +1893,6 @@ ivas_error ivas_init_encoder_fx( } #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - for ( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) - { - for ( int j = 0; j < MASA_FREQUENCY_BANDS; j++ ) - { - for ( int k = 0; k < MASA_MAXIMUM_DIRECTIONS; k++ ) - { - current_meta->directional_meta[k].azimuth[i][j] = fixedToFloat( current_meta->directional_meta[k].azimuth_fx[i][j], Q22 ); - current_meta->directional_meta[k].elevation[i][j] = fixedToFloat( current_meta->directional_meta[k].elevation_fx[i][j], Q22 ); - current_meta->directional_meta[k].energy_ratio[i][j] = fixedToFloat( current_meta->directional_meta[k].energy_ratio_fx[i][j], Q30 ); - current_meta->directional_meta[k].spread_coherence[i][j] = fixedToFloat( current_meta->directional_meta[k].spread_coherence_fx[i][j], Q15 ); - previous_meta->directional_meta[k].azimuth[i][j] = fixedToFloat( previous_meta->directional_meta[k].azimuth_fx[i][j], Q22 ); - previous_meta->directional_meta[k].elevation[i][j] = fixedToFloat( previous_meta->directional_meta[k].elevation_fx[i][j], Q22 ); - previous_meta->directional_meta[k].energy_ratio[i][j] = fixedToFloat( previous_meta->directional_meta[k].energy_ratio_fx[i][j], Q30 ); - previous_meta->directional_meta[k].spread_coherence[i][j] = fixedToFloat( previous_meta->directional_meta[k].spread_coherence_fx[i][j], Q15 ); - } - current_meta->common_meta.surround_coherence[i][j] = fixedToFloat( current_meta->common_meta.surround_coherence_fx[i][j], Q15 ); - current_meta->common_meta.diffuse_to_total_ratio[i][j] = fixedToFloat( current_meta->common_meta.diffuse_to_total_ratio_fx[i][j], Q30 ); - current_meta->common_meta.remainder_to_total_ratio[i][j] = fixedToFloat( current_meta->common_meta.remainder_to_total_ratio_fx[i][j], Q30 ); - previous_meta->common_meta.surround_coherence[i][j] = fixedToFloat( previous_meta->common_meta.surround_coherence_fx[i][j], Q15 ); - previous_meta->common_meta.diffuse_to_total_ratio[i][j] = fixedToFloat( previous_meta->common_meta.diffuse_to_total_ratio_fx[i][j], Q30 ); - previous_meta->common_meta.remainder_to_total_ratio[i][j] = fixedToFloat( previous_meta->common_meta.remainder_to_total_ratio_fx[i][j], Q30 ); - } - } if ( st_ivas->hQMetaData->q_direction != NULL ) { for ( int band = 0; band < st_ivas->hMasa->config.numCodingBands; band++ ) @@ -1995,7 +1908,6 @@ ivas_error ivas_init_encoder_fx( } } } - fixedToFloat_arrL( st_ivas->hMasa->data.importanceWeight_fx, st_ivas->hMasa->data.importanceWeight, 30, 24 ); #endif #endif // IVAS_FLOAT_FIXED_CONVERSIONS diff --git a/lib_enc/ivas_ism_enc.c b/lib_enc/ivas_ism_enc.c index 9d8612ff0..78eb1974d 100644 --- a/lib_enc/ivas_ism_enc.c +++ b/lib_enc/ivas_ism_enc.c @@ -557,68 +557,21 @@ ivas_error ivas_ism_enc( #ifdef IVAS_FLOAT_FIXED #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - st->hTranDet->subblockEnergies.firState1 = (Word16) floatToFixed( st->hTranDet->subblockEnergies.firState1_flt, -1 ); - st->hTranDet->subblockEnergies.firState2 = (Word16) floatToFixed( st->hTranDet->subblockEnergies.firState2_flt, -1 ); - - FOR( i = 0; i < NSUBBLOCKS + MAX_TD_DELAY + 1; i++ ) - { - st->hTranDet->subblockEnergies.accSubblockNrg[i] = floatToFixed( st->hTranDet->subblockEnergies.accSubblockNrg_flt[i], 7 ); - } - - FOR( i = 0; i < NSUBBLOCKS + MAX_TD_DELAY; i++ ) - { - st->hTranDet->subblockEnergies.subblockNrg[i] = floatToFixed( st->hTranDet->subblockEnergies.subblockNrg_flt[i], 7 ); - st->hTranDet->subblockEnergies.subblockNrgChange[i] = (Word16) floatToFixed( st->hTranDet->subblockEnergies.subblockNrgChange_flt[i], 7 ); - } - - - FOR( i = 0; i < L_FRAME_MAX / NSUBBLOCKS; i++ ) - { - st->hTranDet->delayBuffer.buffer[i] = (Word16) floatToFixed( st->hTranDet->delayBuffer.buffer_flt[i], 7 ); - } - - st->hTranDet->transientDetector.attackRatioThreshold = (Word16) floatToFixed( st->hTranDet->transientDetector.attackRatioThreshold_flt, 11 ); - floatToFixed_arr16( st->input, st->input_fx, -1, input_frame ); - st->hTranDet->subblockEnergies.facAccSubblockNrg = float_to_fix16( st->hTranDet->subblockEnergies.facAccSubblockNrg_flt, 15 ); - #endif - RunTransientDetection_ivas_fx( st->input_fx, input_frame, st->hTranDet ); - -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - - st->hTranDet->subblockEnergies.firState1_flt = fixedToFloat( (Word32) st->hTranDet->subblockEnergies.firState1, -1 ); - st->hTranDet->subblockEnergies.firState2_flt = fixedToFloat( (Word32) st->hTranDet->subblockEnergies.firState2, -1 ); - - FOR( i = 0; i < NSUBBLOCKS + MAX_TD_DELAY; i++ ) - { - st->hTranDet->subblockEnergies.subblockNrg_flt[i] = fixedToFloat( st->hTranDet->subblockEnergies.subblockNrg[i], 7 ); - st->hTranDet->subblockEnergies.subblockNrgChange_flt[i] = fixedToFloat( (Word32) st->hTranDet->subblockEnergies.subblockNrgChange[i], 7 ); - } - - FOR( i = 0; i < NSUBBLOCKS + MAX_TD_DELAY + 1; i++ ) - { - st->hTranDet->subblockEnergies.accSubblockNrg_flt[i] = fixedToFloat( st->hTranDet->subblockEnergies.accSubblockNrg[i], 7 ); - } - - FOR( i = 0; i < L_FRAME_MAX / NSUBBLOCKS; i++ ) - { - st->hTranDet->delayBuffer.buffer_flt[i] = fixedToFloat( (Word32) st->hTranDet->delayBuffer.buffer[i], -1 ); - } -#endif + st->hTranDet->subblockEnergies.subblockNrg_e = 31 - Q7; + st->hTranDet->subblockEnergies.accSubblockNrg_e = 31 - Q7; + move16(); + move16(); #else RunTransientDetection( st->input, input_frame, st->hTranDet ); #endif #ifdef IVAS_FLOAT_FIXED -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - Word16 e_tmp; - f2me_buf_16( st->hTranDet->transientDetector.pSubblockEnergies->subblockNrgChange_flt, st->hTranDet->transientDetector.pSubblockEnergies->subblockNrgChange, &e_tmp, 24 ); -#endif currFlatness_fx[0] = GetTCXAvgTemporalFlatnessMeasure_fx( (const TransientDetection *) st->hTranDet, NSUBBLOCKS, 0 ); #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - currFlatness[0] = me2f_16( currFlatness_fx[0], e_tmp ); + currFlatness[0] = me2f_16( currFlatness_fx[0], 15 - Q7 ); #endif #else currFlatness[0] = GetTCXAvgTemporalFlatnessMeasure( st->hTranDet, NSUBBLOCKS, 0 ); @@ -664,20 +617,6 @@ ivas_error ivas_ism_enc( *-----------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - IF( st_ivas->hIsmMetaData != NULL ) - { - FOR( int ch = 0; ch < st_ivas->hEncoderConfig->nchan_ism; ch++ ) - { - st_ivas->hIsmMetaData[ch]->azimuth_fx = floatToFixed( st_ivas->hIsmMetaData[ch]->azimuth, Q22 ); - st_ivas->hIsmMetaData[ch]->elevation_fx = floatToFixed( st_ivas->hIsmMetaData[ch]->elevation, Q22 ); - st_ivas->hIsmMetaData[ch]->yaw_fx = floatToFixed( st_ivas->hIsmMetaData[ch]->yaw, Q22 ); - st_ivas->hIsmMetaData[ch]->pitch_fx = floatToFixed( st_ivas->hIsmMetaData[ch]->pitch, Q22 ); - st_ivas->hIsmMetaData[ch]->radius_fx = float_to_fix16( st_ivas->hIsmMetaData[ch]->radius, Q9 ); - st_ivas->hIsmMetaData[ch]->last_true_azimuth_fx = float_to_fix( st_ivas->hIsmMetaData[ch]->last_true_azimuth, Q22 ); - st_ivas->hIsmMetaData[ch]->last_true_elevation_fx = float_to_fix( st_ivas->hIsmMetaData[ch]->last_true_elevation, Q22 ); - st_ivas->hIsmMetaData[ch]->last_true_radius_fx = float_to_fix16( st_ivas->hIsmMetaData[ch]->last_true_radius, Q9 ); - } - } if ( st_ivas->hISMDTX ) { floatToFixed_arr16( st_ivas->hISMDTX->coh, st_ivas->hISMDTX->coh_fx, Q15, st_ivas->nchan_transport ); @@ -895,17 +834,6 @@ ivas_error ivas_ism_enc( pop_wmops(); #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - IF( st_ivas->hIsmMetaData != NULL ) - { - FOR( int ch = 0; ch < st_ivas->hEncoderConfig->nchan_ism; ch++ ) - { - st_ivas->hIsmMetaData[ch]->last_true_azimuth = fix_to_float( st_ivas->hIsmMetaData[ch]->last_true_azimuth_fx, Q22 ); - st_ivas->hIsmMetaData[ch]->last_true_elevation = fix_to_float( st_ivas->hIsmMetaData[ch]->last_true_elevation_fx, Q22 ); - st_ivas->hIsmMetaData[ch]->last_true_radius = fix16_to_float( st_ivas->hIsmMetaData[ch]->last_true_radius_fx, Q9 ); - st_ivas->hIsmMetaData[ch]->last_azimuth = fix_to_float( st_ivas->hIsmMetaData[ch]->last_azimuth_fx, Q22 ); - st_ivas->hIsmMetaData[ch]->last_elevation = fix_to_float( st_ivas->hIsmMetaData[ch]->last_elevation_fx, Q22 ); - } - } IF( st_ivas->hISMDTX ) { me2f_buf( &st_ivas->hISMDTX->long_term_energy_stereo_dmx_enc_fx[0][0], st_ivas->hISMDTX->long_term_energy_stereo_dmx_enc_e, &st_ivas->hISMDTX->long_term_energy_stereo_dmx_enc[0][0], st_ivas->nchan_transport * PARAM_ISM_HYS_BUF_SIZE ); diff --git a/lib_enc/ivas_ism_metadata_enc.c b/lib_enc/ivas_ism_metadata_enc.c index d383d7b32..982b35550 100644 --- a/lib_enc/ivas_ism_metadata_enc.c +++ b/lib_enc/ivas_ism_metadata_enc.c @@ -1622,11 +1622,6 @@ ivas_error ivas_ism_metadata_enc_create( move16(); st_ivas->hIsmMetaData[ch]->q_elevation_old_fx = 0; move16(); - /*===============fix-to-flt====================*/ - st_ivas->hIsmMetaData[ch]->q_azimuth_old = fix_to_float( st_ivas->hIsmMetaData[ch]->q_azimuth_old_fx, Q22 ); - st_ivas->hIsmMetaData[ch]->q_elevation_old = fix_to_float( st_ivas->hIsmMetaData[ch]->q_elevation_old_fx, Q22 ); - /*===============fix-to-flt====================*/ - #ifdef IVAS_FLOAT_FIXED ivas_ism_reset_metadata_enc( st_ivas->hIsmMetaData[ch] ); @@ -1644,15 +1639,6 @@ ivas_error ivas_ism_metadata_enc_create( st_ivas->hIsmMetaData[ch]->ism_md_fec_cnt_enc = 0; st_ivas->hIsmMetaData[ch]->ism_md_inc_diff_cnt = ISM_MD_INC_DIFF_CNT_MAX; st_ivas->hIsmMetaData[ch]->last_true_radius_fx = ONE_IN_Q9; - - /*===============fix-to-flt====================*/ - st_ivas->hIsmMetaData[ch]->last_azimuth = fix_to_float( st_ivas->hIsmMetaData[ch]->last_azimuth_fx, Q22 ); - st_ivas->hIsmMetaData[ch]->last_elevation = fix_to_float( st_ivas->hIsmMetaData[ch]->last_elevation_fx, Q22 ); - - st_ivas->hIsmMetaData[ch]->last_true_azimuth = fix_to_float( st_ivas->hIsmMetaData[ch]->last_true_azimuth_fx, Q22 ); - st_ivas->hIsmMetaData[ch]->last_true_elevation = fix_to_float( st_ivas->hIsmMetaData[ch]->last_true_elevation_fx, Q22 ); - st_ivas->hIsmMetaData[ch]->last_true_radius = fix16_to_float( st_ivas->hIsmMetaData[ch]->last_true_radius_fx, Q9 ); - /*===============fix-to-flt====================*/ } IF( EQ_16( st_ivas->hEncoderConfig->ivas_format, MASA_ISM_FORMAT ) ) diff --git a/lib_enc/ivas_masa_enc.c b/lib_enc/ivas_masa_enc.c index 3525a8ab0..97101e412 100644 --- a/lib_enc/ivas_masa_enc.c +++ b/lib_enc/ivas_masa_enc.c @@ -250,10 +250,15 @@ ivas_error ivas_masa_enc_open( hMasa->data.onset_detector_2 = 0.0f; #endif - set_zero( hMasa->data.lfeToTotalEnergyRatio, MAX_PARAM_SPATIAL_SUBFRAMES ); +#ifdef IVAS_FLOAT_FIXED set32_fx( hMasa->data.lfeToTotalEnergyRatio_fx, 0, MAX_PARAM_SPATIAL_SUBFRAMES ); set16_fx( hMasa->data.lfeToTotalEnergyRatio_e, 0, MAX_PARAM_SPATIAL_SUBFRAMES ); + hMasa->data.prevq_lfeToTotalEnergyRatio_fx = 0; + move32(); +#else + set_zero( hMasa->data.lfeToTotalEnergyRatio, MAX_PARAM_SPATIAL_SUBFRAMES ); hMasa->data.prevq_lfeToTotalEnergyRatio = 0.0f; +#endif hMasa->data.prevq_lfeIndex = 0; hMasa->data.sync_state.prev_sim_stop = 0; @@ -280,10 +285,17 @@ ivas_error ivas_masa_enc_open( { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for OMASA data encoder\n" ) ); } +#ifdef IVAS_FLOAT_FIXED + FOR( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) + { + set32_fx( hOmasaData->masa_to_total_energy_ratio_fx[i], 0, MASA_FREQUENCY_BANDS ); + } +#else for ( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) { set_f( hOmasaData->masa_to_total_energy_ratio[i], 0, MASA_FREQUENCY_BANDS ); } +#endif #ifndef IVAS_FLOAT_FIXED hOmasaData->lp_noise_CPE = -1; #else @@ -291,12 +303,16 @@ ivas_error ivas_masa_enc_open( #endif hOmasaData->omasa_stereo_sw_cnt = OMASA_STEREO_SW_CNT_MAX; #ifdef IVAS_FLOAT_FIXED - for ( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) + FOR( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) { - set_zero( hOmasaData->energy_ism[i], MASA_FREQUENCY_BANDS ); set_zero_fx( hOmasaData->energy_ism_fx[i], MASA_FREQUENCY_BANDS ); set16_fx( hOmasaData->energy_ism_fx_e[i], 0, MASA_FREQUENCY_BANDS ); } +#else + for ( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) + { + set_zero( hOmasaData->energy_ism[i], MASA_FREQUENCY_BANDS ); + } #endif hMasa->data.hOmasaData = hOmasaData; @@ -358,483 +374,344 @@ ivas_error ivas_masa_encode( MASA_ENCODER_HANDLE hMasa, /* i/o: MASA encoder structure */ IVAS_QMETADATA_HANDLE hQMetaData, /* i/o: q_metadata handle */ BSTR_ENC_HANDLE hMetaData, /* i/o: Metadata bitstream handle */ - int16_t *nb_bits_metadata, /* o : number of metadata bits written */ - const int16_t nchan_transport, /* i : number of MASA input/transport channels */ + Word16 *nb_bits_metadata, /* o : number of metadata bits written */ + const Word16 nchan_transport, /* i : number of MASA input/transport channels */ const IVAS_FORMAT ivas_format, /* i : IVAS format */ - const int32_t ivas_total_brate, /* i : IVAS total bitrate */ - const int16_t Opt_DTX_ON, /* i : DTX on flag */ - const int16_t element_mode, /* i : element mode */ + const Word32 ivas_total_brate, /* i : IVAS total bitrate */ + const Word16 Opt_DTX_ON, /* i : DTX on flag */ + const Word16 element_mode, /* i : element mode */ const ISM_MODE ism_mode, /* i : ISM format mode */ - const int16_t nchan_ism, /* i : number of ISM channels */ + const Word16 nchan_ism, /* i : number of ISM channels */ ISM_METADATA_HANDLE hIsmMetaData[MAX_NUM_OBJECTS], /* i : ISM metadata handle */ - const int16_t idx_separated_object, /* i : index of the separated object */ + const Word16 idx_separated_object, /* i : index of the separated object */ OMASA_ENC_HANDLE hOMasa, /* i : OMASA encoder handle */ - const int16_t ism_imp, /* i : importance of separated object */ - const int16_t flag_omasa_ener_brate /* i : less bitrate for objects in OMASA flag */ + const Word16 ism_imp, /* i : importance of separated object */ + const Word16 flag_omasa_ener_brate /* i : less bitrate for objects in OMASA flag */ ) { MASA_DIRECTIONAL_SPATIAL_META *h_orig_metadata; - int16_t i, j; - int16_t masa_sid_descriptor; - int16_t low_bitrate_mode; - int32_t masa_total_brate; + Word16 i, j, s; + Word16 masa_sid_descriptor; + Word16 low_bitrate_mode; + Word32 masa_total_brate; ivas_error error; - Word16 guard_bits; + Word16 guard_bits, tmp; + +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + for ( i = 0; i < hQMetaData->no_directions; i++ ) + { + for ( j = hQMetaData->q_direction[i].cfg.start_band; j < hQMetaData->q_direction[i].cfg.nbands; ++j ) + { + floatToFixed_arrL( hQMetaData->q_direction[i].band_data[j].energy_ratio, hQMetaData->q_direction[i].band_data[j].energy_ratio_fx, Q30, MAX_PARAM_SPATIAL_SUBFRAMES ); + floatToFixed_arrL( hQMetaData->q_direction[i].band_data[j].azimuth, hQMetaData->q_direction[i].band_data[j].azimuth_fx, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); + floatToFixed_arrL( hQMetaData->q_direction[i].band_data[j].elevation, hQMetaData->q_direction[i].band_data[j].elevation_fx, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); + floatToFixed_arrL( hQMetaData->q_direction[i].band_data[j].q_azimuth, hQMetaData->q_direction[i].band_data[j].q_azimuth_fx, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); + floatToFixed_arrL( hQMetaData->q_direction[i].band_data[j].q_elevation, hQMetaData->q_direction[i].band_data[j].q_elevation_fx, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); + } + } + hMasa->data.q_energy = Q31; + // guard_bits = find_guarded_bits_fx( 9 ); + guard_bits = find_guarded_bits_fx( 24 ); + for ( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) + { + hMasa->data.q_energy = s_min( hMasa->data.q_energy, L_get_q_buf1( hMasa->data.energy[i], MASA_FREQUENCY_BANDS ) ); + } + hMasa->data.q_energy -= guard_bits; + for ( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) + { + for ( j = 0; j < MASA_FREQUENCY_BANDS; j++ ) + { + hMasa->data.energy_e[i][j] = 31 - hMasa->data.q_energy; + } + } + for ( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) + { + floatToFixed_arrL32( hMasa->data.energy[i], hMasa->data.energy_fx[i], hMasa->data.q_energy, MASA_FREQUENCY_BANDS ); + } +#endif masa_sid_descriptor = -1; h_orig_metadata = NULL; low_bitrate_mode = 0; + move16(); + move16(); - if ( ivas_format == MASA_FORMAT || ivas_format == MASA_ISM_FORMAT ) + test(); + IF( EQ_32( ivas_format, MASA_FORMAT ) || EQ_32( ivas_format, MASA_ISM_FORMAT ) ) { /* Create the MASA SID descriptor for the metadata and CPE mode, in order to have the SID frame self-contained. */ - if ( Opt_DTX_ON && hQMetaData != NULL ) + test(); + IF( Opt_DTX_ON && hQMetaData != NULL ) { - if ( nchan_transport == 2 ) /* this is MASA format in CPE only */ + IF( EQ_16( nchan_transport, 2 ) ) /* this is MASA format in CPE only */ { masa_sid_descriptor = 0; /* for IVAS_CPE_DFT */ - if ( element_mode == IVAS_CPE_MDCT ) + move16(); + if ( EQ_16( element_mode, IVAS_CPE_MDCT ) ) { masa_sid_descriptor = 1; + move16(); } } } /* Validate and compensate ratios as necessary */ -#ifdef IVAS_FLOAT_FIXED -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - Word16 sf, dir; - MASA_METADATA_HANDLE hMeta = &( hMasa->masaMetadata ); - Word16 numDirs = hMeta->descriptive_meta.numberOfDirections + 1; - FOR( sf = 0; sf < MAX_PARAM_SPATIAL_SUBFRAMES; sf++ ) - { - floatToFixed_arrL32( hMeta->common_meta.remainder_to_total_ratio[sf], hMeta->common_meta.remainder_to_total_ratio_fx[sf], Q30, MASA_FREQUENCY_BANDS ); - FOR( dir = 0; dir < numDirs; dir++ ) - { - floatToFixed_arrL32( hMeta->directional_meta[dir].energy_ratio[sf], hMeta->directional_meta[dir].energy_ratio_fx[sf], Q30, MASA_FREQUENCY_BANDS ); - } - floatToFixed_arrL32( hMeta->common_meta.diffuse_to_total_ratio[sf], hMeta->common_meta.diffuse_to_total_ratio_fx[sf], Q30, MASA_FREQUENCY_BANDS ); - } -#endif compensate_energy_ratios_fx( hMasa ); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - FOR( sf = 0; sf < MAX_PARAM_SPATIAL_SUBFRAMES; sf++ ) - { - FOR( dir = 0; dir < numDirs; dir++ ) - { - fixedToFloat_arrL32( hMeta->directional_meta[dir].energy_ratio_fx[sf], hMeta->directional_meta[dir].energy_ratio[sf], Q30, MASA_FREQUENCY_BANDS ); - } - fixedToFloat_arrL32( hMeta->common_meta.diffuse_to_total_ratio_fx[sf], hMeta->common_meta.diffuse_to_total_ratio[sf], Q30, MASA_FREQUENCY_BANDS ); - } -#endif -#else - compensate_energy_ratios( hMasa ); -#endif - if ( Opt_DTX_ON ) + IF( Opt_DTX_ON ) { - if ( ( h_orig_metadata = (MASA_DIRECTIONAL_SPATIAL_META *) malloc( MASA_MAXIMUM_DIRECTIONS * sizeof( MASA_DIRECTIONAL_SPATIAL_META ) ) ) == NULL ) + IF( ( h_orig_metadata = (MASA_DIRECTIONAL_SPATIAL_META *) malloc( MASA_MAXIMUM_DIRECTIONS * sizeof( MASA_DIRECTIONAL_SPATIAL_META ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for MASA encoder\n" ) ); } - for ( i = 0; i < MASA_MAXIMUM_DIRECTIONS; i++ ) + FOR( i = 0; i < MASA_MAXIMUM_DIRECTIONS; i++ ) { - for ( j = 0; j < MAX_PARAM_SPATIAL_SUBFRAMES; j++ ) + FOR( j = 0; j < MAX_PARAM_SPATIAL_SUBFRAMES; j++ ) { - mvr2r( hMasa->masaMetadata.directional_meta[i].azimuth[j], h_orig_metadata[i].azimuth[j], MASA_FREQUENCY_BANDS ); - mvr2r( hMasa->masaMetadata.directional_meta[i].elevation[j], h_orig_metadata[i].elevation[j], MASA_FREQUENCY_BANDS ); - mvr2r( hMasa->masaMetadata.directional_meta[i].energy_ratio[j], h_orig_metadata[i].energy_ratio[j], MASA_FREQUENCY_BANDS ); - mvs2s( (int16_t *) ( hMasa->masaMetadata.directional_meta[i].spherical_index[j] ), (int16_t *) ( h_orig_metadata[i].spherical_index[j] ), MASA_FREQUENCY_BANDS ); + Copy32( hMasa->masaMetadata.directional_meta[i].azimuth_fx[j], h_orig_metadata[i].azimuth_fx[j], MASA_FREQUENCY_BANDS ); + Copy32( hMasa->masaMetadata.directional_meta[i].elevation_fx[j], h_orig_metadata[i].elevation_fx[j], MASA_FREQUENCY_BANDS ); + Copy32( hMasa->masaMetadata.directional_meta[i].energy_ratio_fx[j], h_orig_metadata[i].energy_ratio_fx[j], MASA_FREQUENCY_BANDS ); + Copy( (Word16 *) ( hMasa->masaMetadata.directional_meta[i].spherical_index[j] ), (Word16 *) ( h_orig_metadata[i].spherical_index[j] ), MASA_FREQUENCY_BANDS ); } } } - if ( ( ivas_format == MASA_FORMAT || ivas_format == MASA_ISM_FORMAT ) && ivas_total_brate >= IVAS_384k ) + test(); + test(); + if ( ( EQ_32( ivas_format, MASA_FORMAT ) || EQ_32( ivas_format, MASA_ISM_FORMAT ) ) && GE_32( ivas_total_brate, IVAS_384k ) ) { hMasa->config.mergeRatiosOverSubframes = 0; + move16(); } /* Combine frequency bands and sub-frames */ -#ifdef IVAS_FLOAT_FIXED -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - Word16 numSf = hMasa->config.joinedSubframes == TRUE ? 1 : MAX_PARAM_SPATIAL_SUBFRAMES; - for ( i = 0; i < 4; i++ ) - { - for ( j = 0; j < 24; j++ ) - { - f2me( hMasa->data.energy[i][j], &hMasa->data.energy_fx[i][j], &hMasa->data.energy_e[i][j] ); - } - } - if ( hMasa->config.numCodingBands <= MAX_REDUCED_NBANDS ) - { - for ( i = 0; i < hMasa->config.numberOfDirections; i++ ) - { - for ( j = 0; j < numSf; j++ ) /* NB: for numSf==1, operates only on first sub-frame */ - { - floatToFixed_arrL32( hMeta->directional_meta[i].azimuth[j], hMeta->directional_meta[i].azimuth_fx[j], Q22, MASA_FREQUENCY_BANDS ); - floatToFixed_arrL32( hMeta->directional_meta[i].elevation[j], hMeta->directional_meta[i].elevation_fx[j], Q22, MASA_FREQUENCY_BANDS ); - floatToFixed_arrL32( hMeta->directional_meta[i].energy_ratio[j], hMeta->directional_meta[i].energy_ratio_fx[j], Q30, MASA_FREQUENCY_BANDS ); - } - } - if ( hMasa->config.useCoherence && hMasa->config.coherencePresent ) - { - for ( i = 0; i < hMasa->config.numberOfDirections; i++ ) - { - for ( j = 0; j < numSf; j++ ) /* NB: for numSf==1, operates only on first sub-frame */ - { - floatToFixed_arr( hMeta->directional_meta[i].spread_coherence[j], hMeta->directional_meta[i].spread_coherence_fx[j], Q15, MASA_FREQUENCY_BANDS ); - if ( i == 0 ) - { - floatToFixed_arr( hMeta->common_meta.surround_coherence[j], hMeta->common_meta.surround_coherence_fx[j], Q15, MASA_FREQUENCY_BANDS ); - } - } - } - } - } - if ( hMasa->config.mergeRatiosOverSubframes ) - { - if ( hMasa->config.useCoherence && hMasa->config.coherencePresent ) - { - for ( j = 0; j < numSf; j++ ) /* NB: for numSf==1, operates only on first sub-frame */ - { - floatToFixed_arr( hMeta->common_meta.surround_coherence[j], hMeta->common_meta.surround_coherence_fx[j], Q15, MASA_FREQUENCY_BANDS ); - } - } - for ( i = 0; i < hMasa->config.numberOfDirections; i++ ) - { - for ( j = 0; j < numSf; j++ ) /* NB: for numSf==1, operates only on first sub-frame */ - { - floatToFixed_arrL32( hMeta->directional_meta[i].energy_ratio[j], hMeta->directional_meta[i].energy_ratio_fx[j], Q30, MASA_FREQUENCY_BANDS ); - } - } - } -#endif combine_freqbands_and_subframes_fx( hMasa ); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - for ( i = 0; i < 4; i++ ) - { - for ( j = 0; j < 24; j++ ) - { - hMasa->data.energy[i][j] = me2f( hMasa->data.energy_fx[i][j], hMasa->data.energy_e[i][j] ); - } - } - if ( hMasa->config.numCodingBands <= MAX_REDUCED_NBANDS ) + + /* aligning the exponents */ + s = 0; + move16(); + FOR( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) { - for ( i = 0; i < hMasa->config.numberOfDirections; i++ ) - { - for ( j = 0; j < numSf; j++ ) /* NB: for numSf==1, operates only on first sub-frame */ - { - fixedToFloat_arrL32( hMeta->directional_meta[i].azimuth_fx[j], hMeta->directional_meta[i].azimuth[j], Q22, MASA_FREQUENCY_BANDS ); - fixedToFloat_arrL32( hMeta->directional_meta[i].elevation_fx[j], hMeta->directional_meta[i].elevation[j], Q22, MASA_FREQUENCY_BANDS ); - fixedToFloat_arrL32( hMeta->directional_meta[i].energy_ratio_fx[j], hMeta->directional_meta[i].energy_ratio[j], Q30, MASA_FREQUENCY_BANDS ); - } - } - if ( hMasa->config.useCoherence && hMasa->config.coherencePresent ) - { - for ( i = 0; i < hMasa->config.numberOfDirections; i++ ) - { - for ( j = 0; j < numSf; j++ ) /* NB: for numSf==1, operates only on first sub-frame */ - { - fixedToFloat_arr( hMeta->directional_meta[i].spread_coherence_fx[j], hMeta->directional_meta[i].spread_coherence[j], Q15, MASA_FREQUENCY_BANDS ); - if ( i == 0 ) - { - fixedToFloat_arr( hMeta->common_meta.surround_coherence_fx[j], hMeta->common_meta.surround_coherence[j], Q15, MASA_FREQUENCY_BANDS ); - } - } - } - } + maximum_s( hMasa->data.energy_e[i], MASA_FREQUENCY_BANDS, &tmp ); + s = s_max( s, tmp ); } - if ( hMasa->config.mergeRatiosOverSubframes ) + FOR( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) { - if ( hMasa->config.useCoherence && hMasa->config.coherencePresent ) - { - for ( j = 0; j < numSf; j++ ) /* NB: for numSf==1, operates only on first sub-frame */ - { - fixedToFloat_arr( hMeta->common_meta.surround_coherence_fx[j], hMeta->common_meta.surround_coherence[j], Q15, MASA_FREQUENCY_BANDS ); - } - } - for ( i = 0; i < hMasa->config.numberOfDirections; i++ ) + FOR( j = 0; j < MASA_FREQUENCY_BANDS; j++ ) { - for ( j = 0; j < numSf; j++ ) /* NB: for numSf==1, operates only on first sub-frame */ - { - fixedToFloat_arrL32( hMeta->directional_meta[i].energy_ratio_fx[j], hMeta->directional_meta[i].energy_ratio[j], Q30, MASA_FREQUENCY_BANDS ); - } + hMasa->data.energy_fx[i][j] = L_shr( hMasa->data.energy_fx[i][j], sub( s, hMasa->data.energy_e[i][j] ) ); + hMasa->data.energy_e[i][j] = s; + move32(); + move16(); } } -#endif -#else - combine_freqbands_and_subframes( hMasa ); -#endif + hMasa->data.q_energy = sub( 31, s ); + move16(); } - if ( hMasa->config.numberOfDirections == 2 && hMasa->config.numTwoDirBands < hMasa->config.numCodingBands && ( ivas_format == MASA_FORMAT || ivas_format == MASA_ISM_FORMAT ) ) + test(); + test(); + test(); + IF( EQ_16( hMasa->config.numberOfDirections, 2 ) && LT_16( hMasa->config.numTwoDirBands, hMasa->config.numCodingBands ) && ( EQ_32( ivas_format, MASA_FORMAT ) || EQ_32( ivas_format, MASA_ISM_FORMAT ) ) ) { - if ( ( ivas_format == MASA_ISM_FORMAT && ism_mode != ISM_MODE_NONE && ism_mode != ISM_MASA_MODE_MASA_ONE_OBJ ) || ( ivas_format != MASA_ISM_FORMAT ) ) + test(); + test(); + test(); + IF( ( EQ_32( ivas_format, MASA_ISM_FORMAT ) && NE_32( ism_mode, ISM_MODE_NONE ) && NE_32( ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) ) || NE_32( ivas_format, MASA_ISM_FORMAT ) ) { /* Combine directions */ -#ifdef IVAS_FLOAT_FIXED -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - Word16 numCodingBands = hMasa->config.numCodingBands; - Word16 numDirections = hMasa->config.numberOfDirections; - Word16 numSf = hMasa->config.joinedSubframes == TRUE ? 1 : MAX_PARAM_SPATIAL_SUBFRAMES; - Word16 computeCoherence = hMasa->config.useCoherence && hMasa->config.coherencePresent; - MASA_METADATA_HANDLE hMeta; - hMeta = &( hMasa->masaMetadata ); - for ( i = 0; i < numDirections; i++ ) - { - for ( j = 0; j < numSf; j++ ) - { - for ( int k = 0; k < hMasa->config.numCodingBands; k++ ) - { - hMeta->directional_meta[i].energy_ratio_fx[j][k] = floatToFixed( hMeta->directional_meta[i].energy_ratio[j][k], Q30 ); - hMeta->directional_meta[i].azimuth_fx[j][k] = floatToFixed( hMeta->directional_meta[i].azimuth[j][k], Q22 ); - hMeta->directional_meta[i].elevation_fx[j][k] = floatToFixed( hMeta->directional_meta[i].elevation[j][k], Q22 ); - } - } - } - /* Combine directions on the remaining bands */ - for ( i = 0; i < hMasa->config.numCodingBands; i++ ) - { - for ( j = 0; j < numSf; j++ ) - { - hMeta->directional_meta[0].spread_coherence_fx[j][i] = (Word16) floatToFixed( hMeta->directional_meta[0].spread_coherence[j][i], Q15 ); - hMeta->directional_meta[1].spread_coherence_fx[j][i] = (Word16) floatToFixed( hMeta->directional_meta[1].spread_coherence[j][i], Q15 ); - hMeta->common_meta.surround_coherence_fx[j][i] = (Word16) floatToFixed( hMeta->common_meta.surround_coherence[j][i], Q15 ); - } - } - - /* Estimate the importance of having two directions instead of one */ - for ( i = 0; i < MASA_FREQUENCY_BANDS; i++ ) - { - hMasa->data.importanceWeight_fx[i] = floatToFixed( hMasa->data.importanceWeight[i], Q30 ); - } -#endif - ivas_masa_combine_directions_fx( hMasa ); - -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - for ( i = 0; i < numCodingBands; i++ ) - { - if ( hMasa->data.twoDirBands[i] == 0 ) - { - for ( j = 0; j < numSf; j++ ) - { - hMeta->directional_meta[0].azimuth[j][i] = fixedToFloat( hMeta->directional_meta[0].azimuth_fx[j][i], Q22 ); - hMeta->directional_meta[0].elevation[j][i] = fixedToFloat( hMeta->directional_meta[0].elevation_fx[j][i], Q22 ); - if ( computeCoherence ) - { - hMeta->directional_meta[0].spread_coherence[j][i] = fixedToFloat( hMeta->directional_meta[0].spread_coherence_fx[j][i], Q15 ); - hMeta->common_meta.surround_coherence[j][i] = fixedToFloat( hMeta->common_meta.surround_coherence_fx[j][i], Q15 ); - } - hMeta->directional_meta[0].energy_ratio[j][i] = fixedToFloat( hMeta->directional_meta[0].energy_ratio_fx[j][i], Q30 ); - hMeta->directional_meta[1].energy_ratio[j][i] = fixedToFloat( hMeta->directional_meta[1].energy_ratio_fx[j][i], Q30 ); - } - } - } -#endif -#else - ivas_masa_combine_directions( hMasa ); -#endif } /* If we joined all bands, then metadata is now one directional. */ - if ( hMasa->config.numTwoDirBands == 0 ) + IF( hMasa->config.numTwoDirBands == 0 ) { hMasa->config.numberOfDirections = 1; hMasa->masaMetadata.descriptive_meta.numberOfDirections = 0; hQMetaData->no_directions = 1; + move16(); + move16(); + move16(); } } /* Reset qmetadata bit budget */ hQMetaData->metadata_max_bits = hMasa->config.max_metadata_bits; - if ( ivas_format == MASA_FORMAT || ivas_format == MASA_ISM_FORMAT ) + move16(); + test(); + IF( EQ_32( ivas_format, MASA_FORMAT ) || EQ_32( ivas_format, MASA_ISM_FORMAT ) ) { - if ( ivas_format == MASA_ISM_FORMAT && ism_mode != ISM_MODE_NONE ) + test(); + IF( EQ_32( ivas_format, MASA_ISM_FORMAT ) && NE_32( ism_mode, ISM_MODE_NONE ) ) { /* write the number of objects in ISM_MASA format*/ - push_next_indice( hMetaData, nchan_ism - 1, NO_BITS_MASA_ISM_NO_OBJ ); - hQMetaData->metadata_max_bits -= NO_BITS_MASA_ISM_NO_OBJ; + push_next_indice( hMetaData, sub( nchan_ism, 1 ), NO_BITS_MASA_ISM_NO_OBJ ); + hQMetaData->metadata_max_bits = sub( hQMetaData->metadata_max_bits, NO_BITS_MASA_ISM_NO_OBJ ); + move16(); /* write index of separated object if needed */ - if ( ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ && nchan_ism > 1 ) + test(); + IF( EQ_32( ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) && GT_16( nchan_ism, 1 ) ) { push_next_indice( hMetaData, idx_separated_object, NO_BITS_MASA_ISM_NO_OBJ ); - hQMetaData->metadata_max_bits -= NO_BITS_MASA_ISM_NO_OBJ; + hQMetaData->metadata_max_bits = sub( hQMetaData->metadata_max_bits, NO_BITS_MASA_ISM_NO_OBJ ); + move16(); } /* write ISM importance flag (one per object) */ - if ( ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ ) + IF( EQ_32( ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) ) { push_next_indice( hMetaData, hIsmMetaData[0]->ism_imp, ISM_METADATA_FLAG_BITS ); - hQMetaData->metadata_max_bits -= ISM_METADATA_FLAG_BITS; + hQMetaData->metadata_max_bits = sub( hQMetaData->metadata_max_bits, ISM_METADATA_FLAG_BITS ); + move16(); } - else if ( ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ ) + ELSE IF( EQ_32( ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) ) { - if ( hIsmMetaData[0]->ism_md_null_flag ) + IF( hIsmMetaData[0]->ism_md_null_flag ) { /* signal NULL metadata frame */ push_next_indice( hMetaData, 1, ISM_METADATA_MD_FLAG_BITS ); - hQMetaData->metadata_max_bits -= ISM_METADATA_MD_FLAG_BITS; + hQMetaData->metadata_max_bits = sub( hQMetaData->metadata_max_bits, ISM_METADATA_MD_FLAG_BITS ); + move16(); /* write the ISM class to ISM_NO_META and again the true ISM class */ push_next_indice( hMetaData, ISM_NO_META, ISM_METADATA_FLAG_BITS ); - hQMetaData->metadata_max_bits -= ISM_METADATA_FLAG_BITS; + hQMetaData->metadata_max_bits = sub( hQMetaData->metadata_max_bits, ISM_METADATA_FLAG_BITS ); + move16(); push_next_indice( hMetaData, hIsmMetaData[0]->ism_imp, ISM_METADATA_FLAG_BITS ); - hQMetaData->metadata_max_bits -= ISM_METADATA_FLAG_BITS; + hQMetaData->metadata_max_bits = sub( hQMetaData->metadata_max_bits, ISM_METADATA_FLAG_BITS ); + move16(); } - else + ELSE { push_next_indice( hMetaData, hIsmMetaData[0]->ism_imp, ISM_METADATA_FLAG_BITS ); - hQMetaData->metadata_max_bits -= ISM_METADATA_FLAG_BITS; + hQMetaData->metadata_max_bits = sub( hQMetaData->metadata_max_bits, ISM_METADATA_FLAG_BITS ); + move16(); - if ( hIsmMetaData[0]->ism_imp == ISM_NO_META ) + IF( EQ_16( hIsmMetaData[0]->ism_imp, ISM_NO_META ) ) { /* signal low-rate ISM_NO_META frame */ push_next_indice( hMetaData, 0, ISM_METADATA_MD_FLAG_BITS ); - hQMetaData->metadata_max_bits -= ISM_METADATA_MD_FLAG_BITS; + hQMetaData->metadata_max_bits = sub( hQMetaData->metadata_max_bits, ISM_METADATA_MD_FLAG_BITS ); + move16(); /* signal presence of MD in low-rate ISM_NO_META frame */ push_next_indice( hMetaData, hIsmMetaData[0]->ism_md_lowrate_flag, ISM_METADATA_INACTIVE_FLAG_BITS ); - hQMetaData->metadata_max_bits -= ISM_METADATA_INACTIVE_FLAG_BITS; + hQMetaData->metadata_max_bits = sub( hQMetaData->metadata_max_bits, ISM_METADATA_INACTIVE_FLAG_BITS ); + move16(); } } } - else if ( ism_mode == ISM_MASA_MODE_DISC ) + ELSE IF( EQ_32( ism_mode, ISM_MASA_MODE_DISC ) ) { - for ( i = 0; i < nchan_ism; i++ ) + FOR( i = 0; i < nchan_ism; i++ ) { - if ( hIsmMetaData[i]->ism_md_null_flag ) + IF( hIsmMetaData[i]->ism_md_null_flag ) { /* signal NULL metadata frame */ push_next_indice( hMetaData, 1, ISM_METADATA_MD_FLAG_BITS ); - hQMetaData->metadata_max_bits -= ISM_METADATA_MD_FLAG_BITS; + hQMetaData->metadata_max_bits = sub( hQMetaData->metadata_max_bits, ISM_METADATA_MD_FLAG_BITS ); + move16(); /* write the ISM class to ISM_NO_META and again the true ISM class */ push_next_indice( hMetaData, ISM_NO_META, ISM_METADATA_FLAG_BITS ); - hQMetaData->metadata_max_bits -= ISM_METADATA_FLAG_BITS; + hQMetaData->metadata_max_bits = sub( hQMetaData->metadata_max_bits, ISM_METADATA_FLAG_BITS ); + move16(); push_next_indice( hMetaData, hIsmMetaData[i]->ism_imp, ISM_METADATA_FLAG_BITS ); - hQMetaData->metadata_max_bits -= ISM_METADATA_FLAG_BITS; + hQMetaData->metadata_max_bits = sub( hQMetaData->metadata_max_bits, ISM_METADATA_FLAG_BITS ); + move16(); } - else + ELSE { push_next_indice( hMetaData, hIsmMetaData[i]->ism_imp, ISM_METADATA_FLAG_BITS ); - hQMetaData->metadata_max_bits -= ISM_METADATA_FLAG_BITS; + hQMetaData->metadata_max_bits = sub( hQMetaData->metadata_max_bits, ISM_METADATA_FLAG_BITS ); + move16(); - if ( hIsmMetaData[i]->ism_imp == ISM_NO_META ) + IF( EQ_16( hIsmMetaData[i]->ism_imp, ISM_NO_META ) ) { /* signal low-rate ISM_NO_META frame */ push_next_indice( hMetaData, 0, ISM_METADATA_MD_FLAG_BITS ); - hQMetaData->metadata_max_bits -= ISM_METADATA_MD_FLAG_BITS; + hQMetaData->metadata_max_bits = sub( hQMetaData->metadata_max_bits, ISM_METADATA_MD_FLAG_BITS ); + move16(); /* signal presence of MD in low-rate ISM_NO_META frame */ push_next_indice( hMetaData, hIsmMetaData[i]->ism_md_lowrate_flag, ISM_METADATA_INACTIVE_FLAG_BITS ); - hQMetaData->metadata_max_bits -= ISM_METADATA_INACTIVE_FLAG_BITS; + hQMetaData->metadata_max_bits = sub( hQMetaData->metadata_max_bits, ISM_METADATA_INACTIVE_FLAG_BITS ); + move16(); } } } - - if ( ivas_total_brate == IVAS_128k && nchan_ism >= 3 ) + test(); + IF( EQ_32( ivas_total_brate, IVAS_128k ) && GE_16( nchan_ism, 3 ) ) { push_next_indice( hMetaData, flag_omasa_ener_brate, 1 ); - hQMetaData->metadata_max_bits -= 1; + hQMetaData->metadata_max_bits = sub( hQMetaData->metadata_max_bits, 1 ); + move16(); } } } - else + ELSE { /* write the number of MASA transport channels */ - push_next_indice( hMetaData, nchan_transport - 1, MASA_TRANSP_BITS ); - hQMetaData->metadata_max_bits -= MASA_TRANSP_BITS; + push_next_indice( hMetaData, sub( nchan_transport, 1 ), MASA_TRANSP_BITS ); + hQMetaData->metadata_max_bits = sub( hQMetaData->metadata_max_bits, MASA_TRANSP_BITS ); + move16(); } - if ( ivas_format == MASA_ISM_FORMAT && ism_mode == ISM_MODE_NONE ) + test(); + IF( EQ_32( ivas_format, MASA_ISM_FORMAT ) && EQ_32( ism_mode, ISM_MODE_NONE ) ) { /* signal MASA_ISM_FORMAT to decoder */ push_next_indice( hMetaData, 1, 1 ); /* write reserved bit */ push_next_indice( hMetaData, 0, MASA_HEADER_BITS - 1 ); - hQMetaData->metadata_max_bits -= MASA_HEADER_BITS; + hQMetaData->metadata_max_bits = sub( hQMetaData->metadata_max_bits, MASA_HEADER_BITS ); + move16(); } - else + ELSE { /* the MASA_ISM_FORMAT is not signalled here */ /* write reserved bits */ push_next_indice( hMetaData, 0, MASA_HEADER_BITS ); - hQMetaData->metadata_max_bits -= MASA_HEADER_BITS; + hQMetaData->metadata_max_bits = sub( hQMetaData->metadata_max_bits, MASA_HEADER_BITS ); + move16(); } /* write number of directions */ - push_next_indice( hMetaData, hQMetaData->no_directions - 1, 1 ); - hQMetaData->metadata_max_bits -= 1; + push_next_indice( hMetaData, sub( hQMetaData->no_directions, 1 ), 1 ); + hQMetaData->metadata_max_bits = sub( hQMetaData->metadata_max_bits, 1 ); + move16(); /* write subframe mode */ - push_next_indice( hMetaData, hQMetaData->q_direction[0].cfg.nblocks == 1 ? 1 : 0, MASA_SUBFRAME_BITS ); - hQMetaData->metadata_max_bits -= MASA_SUBFRAME_BITS; - } - - if ( ivas_format == MC_FORMAT ) - { - int16_t lfeBitsWritten; -#ifdef IVAS_FLOAT_FIXED -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - for ( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) + IF( EQ_16( hQMetaData->q_direction[0].cfg.nblocks, 1 ) ) { - f2me( hMasa->data.lfeToTotalEnergyRatio[i], &hMasa->data.lfeToTotalEnergyRatio_fx[i], &hMasa->data.lfeToTotalEnergyRatio_e[i] ); + push_next_indice( hMetaData, 1, MASA_SUBFRAME_BITS ); } - hMasa->data.prevq_lfeToTotalEnergyRatio_fx = floatToFixed( hMasa->data.prevq_lfeToTotalEnergyRatio, Q31 ); -#endif - lfeBitsWritten = encode_lfe_to_total_energy_ratio_fx( hMasa, hMetaData, ivas_total_brate ); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - hMasa->data.prevq_lfeToTotalEnergyRatio = fixedToFloat( hMasa->data.prevq_lfeToTotalEnergyRatio_fx, Q31 ); -#endif -#else - lfeBitsWritten = encode_lfe_to_total_energy_ratio( hMasa, hMetaData, ivas_total_brate ); -#endif - hQMetaData->metadata_max_bits -= lfeBitsWritten; + ELSE + { + push_next_indice( hMetaData, 0, MASA_SUBFRAME_BITS ); + } + hQMetaData->metadata_max_bits = sub( hQMetaData->metadata_max_bits, MASA_SUBFRAME_BITS ); + move16(); } -#ifdef IVAS_FLOAT_FIXED -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - // Word16 numSf = hMasa->config.joinedSubframes == TRUE ? 1 : MAX_PARAM_SPATIAL_SUBFRAMES; - hMasa->data.q_energy = Q31; - guard_bits = find_guarded_bits_fx( 24 ); - for ( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) - { - hMasa->data.q_energy = s_min( hMasa->data.q_energy, L_get_q_buf1( hMasa->data.energy[i], MASA_FREQUENCY_BANDS ) ); - } - hMasa->data.q_energy -= guard_bits; - for ( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) - { - floatToFixed_arrL32( hMasa->data.energy[i], hMasa->data.energy_fx[i], hMasa->data.q_energy, MASA_FREQUENCY_BANDS ); - } - for ( int16_t d = 0; d < hQMetaData->no_directions; d++ ) + + IF( EQ_32( ivas_format, MC_FORMAT ) ) { - for ( i = hQMetaData->q_direction[d].cfg.start_band; i < hQMetaData->q_direction[d].cfg.nbands; i++ ) - { - for ( j = 0; j < hQMetaData->q_direction[d].cfg.nblocks; j++ ) - { - hQMetaData->q_direction[d].band_data[i].elevation_fx[j] = float_to_fix( hQMetaData->q_direction[d].band_data[i].elevation[j], Q22 ); - hQMetaData->q_direction[d].band_data[i].azimuth_fx[j] = float_to_fix( hQMetaData->q_direction[d].band_data[i].azimuth[j], Q22 ); - hQMetaData->q_direction[d].band_data[i].energy_ratio_fx[j] = floatToFixed( hQMetaData->q_direction[d].band_data[i].energy_ratio[j], Q30 ); - } - } + Word16 lfeBitsWritten; + + lfeBitsWritten = encode_lfe_to_total_energy_ratio_fx( hMasa, hMetaData, ivas_total_brate ); + + hQMetaData->metadata_max_bits = sub( hQMetaData->metadata_max_bits, lfeBitsWritten ); + move16(); } -#endif + /* Move data from encoder to qmetadata */ test(); IF( EQ_32( ivas_format, MASA_FORMAT ) || EQ_32( ivas_format, MASA_ISM_FORMAT ) ) { move_metadata_to_qmetadata_fx( hMasa, hQMetaData ); } -#else - /* Move data from encoder to qmetadata */ - if ( ivas_format == MASA_FORMAT || ivas_format == MASA_ISM_FORMAT ) - { - move_metadata_to_qmetadata( hMasa, hQMetaData ); - } -#endif -#ifdef IVAS_FLOAT_FIXED test(); IF( LT_16( hMasa->config.max_metadata_bits, MINIMUM_BIT_BUDGET_NORMAL_META ) && !hMasa->config.joinedSubframes ) @@ -844,41 +721,17 @@ ivas_error ivas_masa_encode( low_bitrate_mode = (Word16) LE_32( ivas_total_brate, 32000 ); /* Write low bitrate mode. 1 signals that we have merged through time, 0 signals merge through frequency. */ - push_next_indice( hMetaData, hQMetaData->q_direction[0].cfg.nblocks == 1 ? 1 : 0, MASA_LOWBITRATE_MODE_BITS ); - hQMetaData->metadata_max_bits = sub( hQMetaData->metadata_max_bits, MASA_LOWBITRATE_MODE_BITS ); - } -#else - if ( hMasa->config.max_metadata_bits < MINIMUM_BIT_BUDGET_NORMAL_META && !hMasa->config.joinedSubframes ) - { - reduce_metadata_further( hMasa, hQMetaData, ivas_format ); - - low_bitrate_mode = ( ivas_total_brate <= 32000 ); - - /* Write low bitrate mode. 1 signals that we have merged through time, 0 signals merge through frequency. */ - push_next_indice( hMetaData, hQMetaData->q_direction[0].cfg.nblocks == 1 ? 1 : 0, MASA_LOWBITRATE_MODE_BITS ); - hQMetaData->metadata_max_bits -= MASA_LOWBITRATE_MODE_BITS; - } -#endif -#ifdef IVAS_FLOAT_FIXED -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - if ( EQ_32( ivas_format, MASA_ISM_FORMAT ) && EQ_32( ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) ) - { - for ( int sf = 0; sf < MAX_PARAM_SPATIAL_SUBFRAMES; ++sf ) + IF( EQ_16( hQMetaData->q_direction[0].cfg.nblocks, 1 ) ) { - for ( int band = 0; band < MASA_FREQUENCY_BANDS; ++band ) - { - hMasa->data.hOmasaData->masa_to_total_energy_ratio_fx[sf][band] = floatToFixed_32( hMasa->data.hOmasaData->masa_to_total_energy_ratio[sf][band], Q30 ); - } + push_next_indice( hMetaData, 1, MASA_LOWBITRATE_MODE_BITS ); } + ELSE + { + push_next_indice( hMetaData, 0, MASA_LOWBITRATE_MODE_BITS ); + } + hQMetaData->metadata_max_bits = sub( hQMetaData->metadata_max_bits, MASA_LOWBITRATE_MODE_BITS ); + move16(); } - for ( int obj = 0; obj < nchan_ism; obj++ ) - { - hIsmMetaData[obj]->elevation_fx = floatToFixed( hIsmMetaData[obj]->elevation, Q22 ); - hIsmMetaData[obj]->azimuth_fx = floatToFixed( hIsmMetaData[obj]->azimuth, Q22 ); - hIsmMetaData[obj]->q_elevation_old_fx = floatToFixed( hIsmMetaData[obj]->q_elevation_old, Q22 ); - hIsmMetaData[obj]->q_azimuth_old_fx = floatToFixed( hIsmMetaData[obj]->q_azimuth_old, Q22 ); - } -#endif /* Encode MASA+ISM metadata */ test(); @@ -896,110 +749,17 @@ ivas_error ivas_masa_encode( } } -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - for ( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) - { - fixedToFloat_arrL32( hMasa->data.energy_fx[i], hMasa->data.energy[i], hMasa->data.q_energy, MASA_FREQUENCY_BANDS ); - } - for ( int16_t d = 0; d < hQMetaData->no_directions; d++ ) - { - for ( i = hQMetaData->q_direction[d].cfg.start_band; i < hQMetaData->q_direction[d].cfg.nbands; i++ ) - { - for ( j = 0; j < hQMetaData->q_direction[d].cfg.nblocks; j++ ) - { - hQMetaData->q_direction[d].band_data[i].elevation[j] = fix_to_float( hQMetaData->q_direction[d].band_data[i].elevation_fx[j], Q22 ); - hQMetaData->q_direction[d].band_data[i].azimuth[j] = fix_to_float( hQMetaData->q_direction[d].band_data[i].azimuth_fx[j], Q22 ); - hQMetaData->q_direction[d].band_data[i].energy_ratio[j] = fixedToFloat( hQMetaData->q_direction[d].band_data[i].energy_ratio_fx[j], Q30 ); - } - } - } - if ( EQ_32( ivas_format, MASA_ISM_FORMAT ) && EQ_32( ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) ) - { - for ( int sf = 0; sf < MAX_PARAM_SPATIAL_SUBFRAMES; ++sf ) - { - for ( int band = 0; band < MASA_FREQUENCY_BANDS; ++band ) - { - fixedToFloat_arrL( hMasa->data.hOmasaData->q_energy_ratio_ism_fx[sf][band], hMasa->data.hOmasaData->q_energy_ratio_ism[sf][band], Q30, nchan_ism ); - } - } - for ( int block_m_idx = 0; block_m_idx < hOMasa->nSubframes; block_m_idx++ ) - { - for ( i = 0; i < hOMasa->nbands; i++ ) - { - for ( int k = 0; k < nchan_ism; k++ ) - { - hMasa->data.hOmasaData->energy_ratio_ism[block_m_idx][i][k] = fixedToFloat( hMasa->data.hOmasaData->energy_ratio_ism_fx[block_m_idx][i][k], Q30 ); - } - } - } - } - if ( EQ_32( ivas_format, MASA_ISM_FORMAT ) ) - { - for ( int sf = 0; sf < MAX_PARAM_SPATIAL_SUBFRAMES; ++sf ) - { - for ( int band = 0; band < MASA_FREQUENCY_BANDS; ++band ) - { - fixedToFloat_arrL( hMasa->data.hOmasaData->q_energy_ratio_ism_fx[sf][band], hMasa->data.hOmasaData->q_energy_ratio_ism[sf][band], Q30, nchan_ism ); - hMasa->data.hOmasaData->masa_to_total_energy_ratio[sf][band] = fixedToFloat_32( hMasa->data.hOmasaData->masa_to_total_energy_ratio_fx[sf][band], Q30 ); - } - } - } - for ( int obj = 0; obj < nchan_ism; obj++ ) - { - hIsmMetaData[obj]->elevation = fixedToFloat( hIsmMetaData[obj]->elevation_fx, Q22 ); - hIsmMetaData[obj]->azimuth = fixedToFloat( hIsmMetaData[obj]->azimuth_fx, Q22 ); - hIsmMetaData[obj]->q_elevation_old = fixedToFloat( hIsmMetaData[obj]->q_elevation_old_fx, Q22 ); - hIsmMetaData[obj]->q_azimuth_old = fixedToFloat( hIsmMetaData[obj]->q_azimuth_old_fx, Q22 ); - } -#endif -#else - /* Encode MASA+ISM metadata */ - if ( ivas_format == MASA_ISM_FORMAT && ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ ) - { - /* encode MASA/ISM energy ratios */ - ivas_encode_masaism_metadata( hMasa, hQMetaData, hMetaData, hIsmMetaData, nchan_ism, low_bitrate_mode, hOMasa->nCodingBands, hOMasa->nSubframes, idx_separated_object, ism_imp ); - } - else - { - if ( ivas_format == MASA_ISM_FORMAT ) - { - hMasa->data.hOmasaData->masa_to_total_energy_ratio[0][0] = -1; /* signals NOT to adjust the energy ratios */ - } - } -#endif - /* Encode metadata */ masa_total_brate = ivas_total_brate; -#ifndef IVAS_FLOAT_FIXED - if ( ivas_format == MASA_ISM_FORMAT && ism_mode == ISM_MASA_MODE_DISC ) - { - masa_total_brate = calculate_cpe_brate_MASA_ISM( ism_mode, ivas_total_brate, nchan_ism ); - } -#else + move32(); test(); IF( EQ_32( ivas_format, MASA_ISM_FORMAT ) && EQ_32( ism_mode, ISM_MASA_MODE_DISC ) ) { masa_total_brate = calculate_cpe_brate_MASA_ISM_fx( ism_mode, ivas_total_brate, nchan_ism ); } -#endif IF( GE_32( masa_total_brate, IVAS_384k ) ) { -#ifdef IVAS_FLOAT_FIXED -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - for ( int16_t d = 0; d < hQMetaData->no_directions; d++ ) - { - for ( i = hQMetaData->q_direction[d].cfg.start_band; i < hQMetaData->q_direction[d].cfg.nbands; i++ ) - { - for ( j = 0; j < hQMetaData->q_direction[d].cfg.nblocks; j++ ) - { - hQMetaData->q_direction[d].band_data[i].elevation_fx[j] = float_to_fix( hQMetaData->q_direction[d].band_data[i].elevation[j], Q22 ); - hQMetaData->q_direction[d].band_data[i].azimuth_fx[j] = float_to_fix( hQMetaData->q_direction[d].band_data[i].azimuth[j], Q22 ); - hQMetaData->q_direction[d].band_data[i].energy_ratio_fx[j] = floatToFixed( hQMetaData->q_direction[d].band_data[i].energy_ratio[j], Q30 ); - } - } - } -#endif // IVAS_FLOAT_FIXED_CONVERSIONS IF( GE_32( masa_total_brate, IVAS_512k ) ) { IF( NE_32( ( error = ivas_qmetadata_enc_encode_hr_384_512_fx( hMetaData, hQMetaData, 16, 4 ) ), IVAS_ERR_OK ) ) @@ -1014,113 +774,13 @@ ivas_error ivas_masa_encode( return error; } } - -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - for ( int16_t d = 0; d < hQMetaData->no_directions; d++ ) - { - for ( i = hQMetaData->q_direction[d].cfg.start_band; i < hQMetaData->q_direction[d].cfg.nbands; i++ ) - { - for ( j = 0; j < hQMetaData->q_direction[d].cfg.nblocks; j++ ) - { - hQMetaData->q_direction[d].band_data[i].elevation[j] = fix_to_float( hQMetaData->q_direction[d].band_data[i].elevation_fx[j], Q22 ); - hQMetaData->q_direction[d].band_data[i].azimuth[j] = fix_to_float( hQMetaData->q_direction[d].band_data[i].azimuth_fx[j], Q22 ); - hQMetaData->q_direction[d].band_data[i].energy_ratio[j] = fixedToFloat( hQMetaData->q_direction[d].band_data[i].energy_ratio_fx[j], Q30 ); - } - } - } - if ( masa_total_brate >= IVAS_512k ) - { - for ( int16_t d = 0; d < hQMetaData->no_directions; d++ ) - { - for ( i = hQMetaData->q_direction[d].cfg.start_band; i < hQMetaData->q_direction[d].cfg.nbands; i++ ) - { - for ( j = 0; j < hQMetaData->q_direction[d].cfg.nblocks; j++ ) - { - hQMetaData->q_direction[d].band_data[i].q_elevation[j] = fix_to_float( hQMetaData->q_direction[d].band_data[i].q_elevation_fx[j], Q22 ); - hQMetaData->q_direction[d].band_data[i].q_azimuth[j] = fix_to_float( hQMetaData->q_direction[d].band_data[i].q_azimuth_fx[j], Q22 ); - } - } - } - } -#endif // IVAS_FLOAT_FIXED_CONVERSIONS - -#else - if ( masa_total_brate >= IVAS_512k ) - { - if ( ( error = ivas_qmetadata_enc_encode_hr_384_512( hMetaData, hQMetaData, 16, 4 ) ) != IVAS_ERR_OK ) - { - return error; - } - } - else - { - if ( ( error = ivas_qmetadata_enc_encode_hr_384_512( hMetaData, hQMetaData, 11, 3 ) ) != IVAS_ERR_OK ) - { - return error; - } - } -#endif } - else + ELSE { -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - for ( i = 0; i < hQMetaData->no_directions; i++ ) - { - for ( j = hQMetaData->q_direction[0].cfg.start_band; j < hQMetaData->q_direction[0].cfg.nbands; ++j ) - { - floatToFixed_arrL( hQMetaData->q_direction[i].band_data[j].energy_ratio, hQMetaData->q_direction[i].band_data[j].energy_ratio_fx, Q30, MAX_PARAM_SPATIAL_SUBFRAMES ); - floatToFixed_arrL( hQMetaData->q_direction[i].band_data[j].azimuth, hQMetaData->q_direction[i].band_data[j].azimuth_fx, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); - floatToFixed_arrL( hQMetaData->q_direction[i].band_data[j].elevation, hQMetaData->q_direction[i].band_data[j].elevation_fx, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); - -#ifndef MSAN_FIX - floatToFixed_arrL( hQMetaData->q_direction[i].band_data[j].q_azimuth, hQMetaData->q_direction[i].band_data[j].q_azimuth_fx, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); - floatToFixed_arrL( hQMetaData->q_direction[i].band_data[j].q_elevation, hQMetaData->q_direction[i].band_data[j].q_elevation_fx, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); -#endif - } - } -#endif - if ( ( error = ivas_qmetadata_enc_encode_fx( hMetaData, hQMetaData, 0 ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_qmetadata_enc_encode_fx( hMetaData, hQMetaData, 0 ) ), IVAS_ERR_OK ) ) { return error; } -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - for ( i = 0; i < hQMetaData->no_directions; i++ ) - { - for ( j = hQMetaData->q_direction[0].cfg.start_band; j < hQMetaData->q_direction[0].cfg.nbands; ++j ) - { - fixedToFloat_arrL( hQMetaData->q_direction[i].band_data[j].energy_ratio_fx, hQMetaData->q_direction[i].band_data[j].energy_ratio, Q30, MAX_PARAM_SPATIAL_SUBFRAMES ); - /*fixedToFloat_arrL( hQMetaData->q_direction[i].band_data[j].azimuth_fx, hQMetaData->q_direction[i].band_data[j].azimuth, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); - fixedToFloat_arrL( hQMetaData->q_direction[i].band_data[j].elevation_fx, hQMetaData->q_direction[i].band_data[j].elevation, Q22, MAX_PARAM_SPATIAL_SUBFRAMES );*/ - fixedToFloat_arrL( hQMetaData->q_direction[i].band_data[j].q_azimuth_fx, hQMetaData->q_direction[i].band_data[j].q_azimuth, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); - fixedToFloat_arrL( hQMetaData->q_direction[i].band_data[j].q_elevation_fx, hQMetaData->q_direction[i].band_data[j].q_elevation, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); - } - } -#endif - } - -#ifndef IVAS_FLOAT_FIXED - if ( ivas_format == MASA_ISM_FORMAT && ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ ) - { - /* Modify spatial metadata based on the MASA-to-total energy ratios */ - ivas_omasa_modify_masa_energy_ratios( hQMetaData, hMasa->data.hOmasaData->masa_to_total_energy_ratio ); - } -#else - Word16 b, d; - - IF( EQ_32( ivas_format, MASA_ISM_FORMAT ) && EQ_32( ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) ) - { - for ( b = 0; b < hQMetaData->q_direction[0].cfg.nbands; b++ ) - { - for ( d = 0; d < hQMetaData->no_directions; d++ ) - { - floatToFixed_arr32( hQMetaData->q_direction[d].band_data[b].energy_ratio, hQMetaData->q_direction[d].band_data[b].energy_ratio_fx, Q30, MAX_PARAM_SPATIAL_SUBFRAMES ); - } - } - - for ( b = 0; b < MAX_PARAM_SPATIAL_SUBFRAMES; ++b ) - { - floatToFixed_arr32( hMasa->data.hOmasaData->masa_to_total_energy_ratio[b], hMasa->data.hOmasaData->masa_to_total_energy_ratio_fx[b], Q30, MASA_MAXIMUM_CODING_SUBBANDS ); - } } test(); @@ -1130,292 +790,80 @@ ivas_error ivas_masa_encode( ivas_omasa_modify_masa_energy_ratios_fx( hQMetaData, hMasa->data.hOmasaData->masa_to_total_energy_ratio_fx ); } - IF( EQ_32( ivas_format, MASA_ISM_FORMAT ) && EQ_32( ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) ) - { - for ( b = 0; b < hQMetaData->q_direction[0].cfg.nbands; b++ ) - { - for ( d = 0; d < hQMetaData->no_directions; d++ ) - { - fixedToFloat_arrL( hQMetaData->q_direction[d].band_data[b].energy_ratio_fx, hQMetaData->q_direction[d].band_data[b].energy_ratio, Q30, MAX_PARAM_SPATIAL_SUBFRAMES ); - } - } - } -#endif - *nb_bits_metadata = hMetaData->nb_bits_tot; + move16(); - if ( ivas_format == MASA_FORMAT && Opt_DTX_ON ) + test(); + IF( EQ_32( ivas_format, MASA_FORMAT ) && Opt_DTX_ON ) { /* save old values */ - uint8_t numCodingBands = hMasa->config.numCodingBands; - uint8_t numTwoDirBands = hMasa->config.numTwoDirBands; - int16_t nbands = hQMetaData->q_direction[0].cfg.nbands; - uint8_t numberOfDirections = hMasa->config.numberOfDirections; - uint8_t numberOfDirectionsMeta = hMasa->masaMetadata.descriptive_meta.numberOfDirections; - uint16_t numberOfDirectionsQMetaData = hQMetaData->no_directions; + UWord8 numCodingBands = hMasa->config.numCodingBands; + UWord8 numTwoDirBands = hMasa->config.numTwoDirBands; + Word16 nbands = hQMetaData->q_direction[0].cfg.nbands; + UWord8 numberOfDirections = hMasa->config.numberOfDirections; + UWord8 numberOfDirectionsMeta = hMasa->masaMetadata.descriptive_meta.numberOfDirections; + UWord16 numberOfDirectionsQMetaData = hQMetaData->no_directions; + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); - if ( !( hMasa->config.numberOfDirections == 1 && hQMetaData->q_direction->cfg.nbands == 5 ) ) + test(); + IF( !( EQ_16( hMasa->config.numberOfDirections, 1 ) && EQ_16( hQMetaData->q_direction->cfg.nbands, 5 ) ) ) { - for ( i = 0; i < MASA_MAXIMUM_DIRECTIONS; i++ ) + FOR( i = 0; i < MASA_MAXIMUM_DIRECTIONS; i++ ) { - for ( j = 0; j < MAX_PARAM_SPATIAL_SUBFRAMES; j++ ) + FOR( j = 0; j < MAX_PARAM_SPATIAL_SUBFRAMES; j++ ) { - mvr2r( h_orig_metadata[i].azimuth[j], hMasa->masaMetadata.directional_meta[i].azimuth[j], MASA_FREQUENCY_BANDS ); - mvr2r( h_orig_metadata[i].elevation[j], hMasa->masaMetadata.directional_meta[i].elevation[j], MASA_FREQUENCY_BANDS ); - mvr2r( h_orig_metadata[i].energy_ratio[j], hMasa->masaMetadata.directional_meta[i].energy_ratio[j], MASA_FREQUENCY_BANDS ); + Copy32( h_orig_metadata[i].azimuth_fx[j], hMasa->masaMetadata.directional_meta[i].azimuth_fx[j], MASA_FREQUENCY_BANDS ); + Copy32( h_orig_metadata[i].elevation_fx[j], hMasa->masaMetadata.directional_meta[i].elevation_fx[j], MASA_FREQUENCY_BANDS ); + Copy32( h_orig_metadata[i].energy_ratio_fx[j], hMasa->masaMetadata.directional_meta[i].energy_ratio_fx[j], MASA_FREQUENCY_BANDS ); } } /* Force to have 5 bands and 1 direction */ hMasa->config.numCodingBands = 5; hMasa->config.numTwoDirBands = 0; -#ifdef IVAS_FLOAT_FIXED -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - MASA_METADATA_HANDLE hMeta = &( hMasa->masaMetadata ); - Word16 numSf = hMasa->config.joinedSubframes == TRUE ? 1 : MAX_PARAM_SPATIAL_SUBFRAMES; - for ( i = 0; i < 4; i++ ) - { - for ( j = 0; j < 24; j++ ) - { - f2me( hMasa->data.energy[i][j], &hMasa->data.energy_fx[i][j], &hMasa->data.energy_e[i][j] ); - } - } - if ( hMasa->config.numCodingBands <= MAX_REDUCED_NBANDS ) - { - for ( i = 0; i < hMasa->config.numberOfDirections; i++ ) - { - for ( j = 0; j < numSf; j++ ) /* NB: for numSf==1, operates only on first sub-frame */ - { - floatToFixed_arrL32( hMeta->directional_meta[i].azimuth[j], hMeta->directional_meta[i].azimuth_fx[j], Q22, MASA_FREQUENCY_BANDS ); - floatToFixed_arrL32( hMeta->directional_meta[i].elevation[j], hMeta->directional_meta[i].elevation_fx[j], Q22, MASA_FREQUENCY_BANDS ); - floatToFixed_arrL32( hMeta->directional_meta[i].energy_ratio[j], hMeta->directional_meta[i].energy_ratio_fx[j], Q30, MASA_FREQUENCY_BANDS ); - } - } - if ( hMasa->config.useCoherence && hMasa->config.coherencePresent ) - { - for ( i = 0; i < hMasa->config.numberOfDirections; i++ ) - { - for ( j = 0; j < numSf; j++ ) /* NB: for numSf==1, operates only on first sub-frame */ - { - floatToFixed_arr( hMeta->directional_meta[i].spread_coherence[j], hMeta->directional_meta[i].spread_coherence_fx[j], Q15, MASA_FREQUENCY_BANDS ); - if ( i == 0 ) - { - floatToFixed_arr( hMeta->common_meta.surround_coherence[j], hMeta->common_meta.surround_coherence_fx[j], Q15, MASA_FREQUENCY_BANDS ); - } - } - } - } - } - if ( hMasa->config.mergeRatiosOverSubframes ) - { - if ( hMasa->config.useCoherence && hMasa->config.coherencePresent ) - { - for ( j = 0; j < numSf; j++ ) /* NB: for numSf==1, operates only on first sub-frame */ - { - floatToFixed_arr( hMeta->common_meta.surround_coherence[j], hMeta->common_meta.surround_coherence_fx[j], Q15, MASA_FREQUENCY_BANDS ); - } - } - for ( i = 0; i < hMasa->config.numberOfDirections; i++ ) - { - for ( j = 0; j < numSf; j++ ) /* NB: for numSf==1, operates only on first sub-frame */ - { - floatToFixed_arrL32( hMeta->directional_meta[i].energy_ratio[j], hMeta->directional_meta[i].energy_ratio_fx[j], Q30, MASA_FREQUENCY_BANDS ); - } - } - } -#endif + move16(); + move16(); + combine_freqbands_and_subframes_fx( hMasa ); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - for ( i = 0; i < 4; i++ ) - { - for ( j = 0; j < 24; j++ ) - { - hMasa->data.energy[i][j] = me2f( hMasa->data.energy_fx[i][j], hMasa->data.energy_e[i][j] ); - } - } - if ( hMasa->config.numCodingBands <= MAX_REDUCED_NBANDS ) - { - for ( i = 0; i < hMasa->config.numberOfDirections; i++ ) - { - for ( j = 0; j < numSf; j++ ) /* NB: for numSf==1, operates only on first sub-frame */ - { - fixedToFloat_arrL32( hMeta->directional_meta[i].azimuth_fx[j], hMeta->directional_meta[i].azimuth[j], Q22, MASA_FREQUENCY_BANDS ); - fixedToFloat_arrL32( hMeta->directional_meta[i].elevation_fx[j], hMeta->directional_meta[i].elevation[j], Q22, MASA_FREQUENCY_BANDS ); - fixedToFloat_arrL32( hMeta->directional_meta[i].energy_ratio_fx[j], hMeta->directional_meta[i].energy_ratio[j], Q30, MASA_FREQUENCY_BANDS ); - } - } - if ( hMasa->config.useCoherence && hMasa->config.coherencePresent ) - { - for ( i = 0; i < hMasa->config.numberOfDirections; i++ ) - { - for ( j = 0; j < numSf; j++ ) /* NB: for numSf==1, operates only on first sub-frame */ - { - fixedToFloat_arr( hMeta->directional_meta[i].spread_coherence_fx[j], hMeta->directional_meta[i].spread_coherence[j], Q15, MASA_FREQUENCY_BANDS ); - if ( i == 0 ) - { - fixedToFloat_arr( hMeta->common_meta.surround_coherence_fx[j], hMeta->common_meta.surround_coherence[j], Q15, MASA_FREQUENCY_BANDS ); - } - } - } - } - } - if ( hMasa->config.mergeRatiosOverSubframes ) - { - if ( hMasa->config.useCoherence && hMasa->config.coherencePresent ) - { - for ( j = 0; j < numSf; j++ ) /* NB: for numSf==1, operates only on first sub-frame */ - { - fixedToFloat_arr( hMeta->common_meta.surround_coherence_fx[j], hMeta->common_meta.surround_coherence[j], Q15, MASA_FREQUENCY_BANDS ); - } - } - for ( i = 0; i < hMasa->config.numberOfDirections; i++ ) - { - for ( j = 0; j < numSf; j++ ) /* NB: for numSf==1, operates only on first sub-frame */ - { - fixedToFloat_arrL32( hMeta->directional_meta[i].energy_ratio_fx[j], hMeta->directional_meta[i].energy_ratio[j], Q30, MASA_FREQUENCY_BANDS ); - } - } - } -#endif -#else - combine_freqbands_and_subframes( hMasa ); -#endif + hQMetaData->q_direction[0].cfg.nbands = 5; + move16(); - if ( hMasa->config.numberOfDirections == 2 && hMasa->config.numTwoDirBands < hMasa->config.numCodingBands ) + test(); + IF( EQ_16( hMasa->config.numberOfDirections, 2 ) && LT_16( hMasa->config.numTwoDirBands, hMasa->config.numCodingBands ) ) { /* Combine directions */ -#ifdef IVAS_FLOAT_FIXED -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - numCodingBands = hMasa->config.numCodingBands; - Word16 numDirections = hMasa->config.numberOfDirections; - numSf = hMasa->config.joinedSubframes == TRUE ? 1 : MAX_PARAM_SPATIAL_SUBFRAMES; - Word16 computeCoherence = hMasa->config.useCoherence && hMasa->config.coherencePresent; - hMeta = &( hMasa->masaMetadata ); - for ( i = 0; i < numDirections; i++ ) - { - for ( j = 0; j < numSf; j++ ) - { - for ( int k = 0; k < hMasa->config.numCodingBands; k++ ) - { - hMeta->directional_meta[i].energy_ratio_fx[j][k] = floatToFixed( hMeta->directional_meta[i].energy_ratio[j][k], Q30 ); - hMeta->directional_meta[i].azimuth_fx[j][k] = floatToFixed( hMeta->directional_meta[i].azimuth[j][k], Q22 ); - hMeta->directional_meta[i].elevation_fx[j][k] = floatToFixed( hMeta->directional_meta[i].elevation[j][k], Q22 ); - } - } - } - /* Combine directions on the remaining bands */ - for ( i = 0; i < hMasa->config.numCodingBands; i++ ) - { - for ( j = 0; j < numSf; j++ ) - { - hMeta->directional_meta[0].spread_coherence_fx[j][i] = (Word16) floatToFixed( hMeta->directional_meta[0].spread_coherence[j][i], Q15 ); - hMeta->directional_meta[1].spread_coherence_fx[j][i] = (Word16) floatToFixed( hMeta->directional_meta[1].spread_coherence[j][i], Q15 ); - hMeta->common_meta.surround_coherence_fx[j][i] = (Word16) floatToFixed( hMeta->common_meta.surround_coherence[j][i], Q15 ); - } - } - - /* Estimate the importance of having two directions instead of one */ - for ( i = 0; i < MASA_FREQUENCY_BANDS; i++ ) - { - hMasa->data.importanceWeight_fx[i] = floatToFixed( hMasa->data.importanceWeight[i], Q30 ); - } -#endif ivas_masa_combine_directions_fx( hMasa ); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - for ( i = 0; i < numCodingBands; i++ ) - { - if ( hMasa->data.twoDirBands[i] == 0 ) - { - for ( j = 0; j < numSf; j++ ) - { - hMeta->directional_meta[0].azimuth[j][i] = fixedToFloat( hMeta->directional_meta[0].azimuth_fx[j][i], Q22 ); - hMeta->directional_meta[0].elevation[j][i] = fixedToFloat( hMeta->directional_meta[0].elevation_fx[j][i], Q22 ); - if ( computeCoherence ) - { - hMeta->directional_meta[0].spread_coherence[j][i] = fixedToFloat( hMeta->directional_meta[0].spread_coherence_fx[j][i], Q15 ); - hMeta->common_meta.surround_coherence[j][i] = fixedToFloat( hMeta->common_meta.surround_coherence_fx[j][i], Q15 ); - } - hMeta->directional_meta[0].energy_ratio[j][i] = fixedToFloat( hMeta->directional_meta[0].energy_ratio_fx[j][i], Q30 ); - hMeta->directional_meta[1].energy_ratio[j][i] = fixedToFloat( hMeta->directional_meta[1].energy_ratio_fx[j][i], Q30 ); - } - } - } -#endif -#else - ivas_masa_combine_directions( hMasa ); -#endif - /* If we joined all bands, then metadata is now one directional. */ - if ( hMasa->config.numTwoDirBands == 0 ) + IF( hMasa->config.numTwoDirBands == 0 ) { hMasa->config.numberOfDirections = 1; hMasa->masaMetadata.descriptive_meta.numberOfDirections = 0; hQMetaData->no_directions = 1; + move16(); + move16(); + move16(); } } -#ifdef IVAS_FLOAT_FIXED move_metadata_to_qmetadata_fx( hMasa, hQMetaData ); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - for ( d = 0; d < hQMetaData->no_directions; d++ ) - { - for ( i = hQMetaData->q_direction[d].cfg.start_band; i < hQMetaData->q_direction[d].cfg.nbands; i++ ) - { - for ( j = 0; j < hQMetaData->q_direction[d].cfg.nblocks; j++ ) - { - hQMetaData->q_direction[d].band_data[i].elevation[j] = fix_to_float( hQMetaData->q_direction[d].band_data[i].elevation_fx[j], Q22 ); - hQMetaData->q_direction[d].band_data[i].azimuth[j] = fix_to_float( hQMetaData->q_direction[d].band_data[i].azimuth_fx[j], Q22 ); - hQMetaData->q_direction[d].band_data[i].energy_ratio[j] = fixedToFloat( hQMetaData->q_direction[d].band_data[i].energy_ratio_fx[j], Q30 ); - } - } - } -#endif -#else - move_metadata_to_qmetadata( hMasa, hQMetaData ); -#endif - FOR( j = hQMetaData->q_direction[0].cfg.start_band; j < hQMetaData->q_direction[0].cfg.nbands; ++j ) { -#ifdef IVAS_FLOAT_FIXED - /*=====================================flt-2-fix============================================*/ - hQMetaData->q_direction[0].band_data[j].energy_ratio_fx[0] = floatToFixed( hQMetaData->q_direction[0].band_data[j].energy_ratio[0], Q30 ); - /*=====================================flt-2-fix============================================*/ - hQMetaData->q_direction[0].band_data[j].energy_ratio_index[0] = masa_sq_fx( L_sub( ONE_IN_Q30, hQMetaData->q_direction[0].band_data[j].energy_ratio_fx[0] ), diffuseness_thresholds_fx, DIRAC_DIFFUSE_LEVELS ); -#else - hQMetaData->q_direction[0].band_data[j].energy_ratio_index[0] = masa_sq( 1.0f - hQMetaData->q_direction[0].band_data[j].energy_ratio[0], diffuseness_thresholds, DIRAC_DIFFUSE_LEVELS ); -#endif + move32(); } } free( h_orig_metadata ); -#ifdef IVAS_FLOAT_FIXED -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - IVAS_QDIRECTION *q_direction; - q_direction = &( hQMetaData->q_direction[0] ); - FOR( b = 0; b < q_direction->cfg.nbands; b++ ) - { - FOR( int m = 0; m < q_direction->cfg.nblocks; m++ ) - { - q_direction->band_data[b].azimuth_fx[m] = floatToFixed( q_direction->band_data[b].azimuth[m], Q22 ); - q_direction->band_data[b].elevation_fx[m] = floatToFixed( q_direction->band_data[b].elevation[m], Q22 ); - } - } -#endif + ivas_qmetadata_enc_sid_encode_fx( hMetaData, hQMetaData, masa_sid_descriptor, ivas_format ); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - FOR( b = 0; b < q_direction->cfg.nbands; b++ ) - { - q_direction->band_data[b].q_azimuth[0] = fixedToFloat( q_direction->band_data[b].q_azimuth_fx[0], Q22 ); - q_direction->band_data[b].q_elevation[0] = fixedToFloat( q_direction->band_data[b].q_elevation_fx[0], Q22 ); - } -#endif -#else - ivas_qmetadata_enc_sid_encode( hMetaData, hQMetaData, masa_sid_descriptor, ivas_format ); -#endif /* restore old values */ hMasa->config.numCodingBands = numCodingBands; @@ -1424,7 +872,31 @@ ivas_error ivas_masa_encode( hMasa->config.numberOfDirections = numberOfDirections; hMasa->masaMetadata.descriptive_meta.numberOfDirections = numberOfDirectionsMeta; hQMetaData->no_directions = numberOfDirectionsQMetaData; + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + } + +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + for ( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) + { + fixedToFloat_arrL32( hMasa->data.energy_fx[i], hMasa->data.energy[i], hMasa->data.q_energy, MASA_FREQUENCY_BANDS ); + } + for ( i = 0; i < hQMetaData->no_directions; i++ ) + { + for ( j = hQMetaData->q_direction[0].cfg.start_band; j < hQMetaData->q_direction[0].cfg.nbands; ++j ) + { + fixedToFloat_arrL( hQMetaData->q_direction[i].band_data[j].energy_ratio_fx, hQMetaData->q_direction[i].band_data[j].energy_ratio, Q30, MAX_PARAM_SPATIAL_SUBFRAMES ); + fixedToFloat_arrL( hQMetaData->q_direction[i].band_data[j].azimuth_fx, hQMetaData->q_direction[i].band_data[j].azimuth, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); + fixedToFloat_arrL( hQMetaData->q_direction[i].band_data[j].elevation_fx, hQMetaData->q_direction[i].band_data[j].elevation, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); + fixedToFloat_arrL( hQMetaData->q_direction[i].band_data[j].q_azimuth_fx, hQMetaData->q_direction[i].band_data[j].q_azimuth, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); + fixedToFloat_arrL( hQMetaData->q_direction[i].band_data[j].q_elevation_fx, hQMetaData->q_direction[i].band_data[j].q_elevation, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); + } } +#endif return IVAS_ERR_OK; } @@ -2243,20 +1715,6 @@ ivas_error ivas_masa_enc_config( floatToFixed_arr32( hMasa->data.dir_align_state.previous_ele_dir2, hMasa->data.dir_align_state.previous_ele_dir2_fx, Q22, MASA_FREQUENCY_BANDS ); floatToFixed_arr32( hMasa->data.dir_align_state.previous_azi_dir1, hMasa->data.dir_align_state.previous_azi_dir1_fx, Q22, MASA_FREQUENCY_BANDS ); floatToFixed_arr32( hMasa->data.dir_align_state.previous_azi_dir2, hMasa->data.dir_align_state.previous_azi_dir2_fx, Q22, MASA_FREQUENCY_BANDS ); - for ( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) - { - for ( int j = 0; j < MASA_FREQUENCY_BANDS; j++ ) - { - hMasa->masaMetadata.directional_meta[0].azimuth_fx[i][j] = float_to_fix( hMasa->masaMetadata.directional_meta[0].azimuth[i][j], Q22 ); - hMasa->masaMetadata.directional_meta[0].elevation_fx[i][j] = float_to_fix( hMasa->masaMetadata.directional_meta[0].elevation[i][j], Q22 ); - hMasa->masaMetadata.directional_meta[0].energy_ratio_fx[i][j] = float_to_fix( hMasa->masaMetadata.directional_meta[0].energy_ratio[i][j], Q30 ); - hMasa->masaMetadata.directional_meta[0].spread_coherence_fx[i][j] = float_to_fix16( hMasa->masaMetadata.directional_meta[0].spread_coherence[i][j], Q15 ); - hMasa->masaMetadata.directional_meta[1].azimuth_fx[i][j] = float_to_fix( hMasa->masaMetadata.directional_meta[1].azimuth[i][j], Q22 ); - hMasa->masaMetadata.directional_meta[1].elevation_fx[i][j] = float_to_fix( hMasa->masaMetadata.directional_meta[1].elevation[i][j], Q22 ); - hMasa->masaMetadata.directional_meta[1].energy_ratio_fx[i][j] = float_to_fix( hMasa->masaMetadata.directional_meta[1].energy_ratio[i][j], Q30 ); - hMasa->masaMetadata.directional_meta[1].spread_coherence_fx[i][j] = float_to_fix16( hMasa->masaMetadata.directional_meta[1].spread_coherence[i][j], Q15 ); - } - } #endif // IVAS_FLOAT_FIXED_TO_BE_REMOVED masa_metadata_direction_alignment_fx( hMasa ); #ifdef IVAS_FLOAT_FIXED_TO_BE_REMOVED @@ -2264,46 +1722,13 @@ ivas_error ivas_masa_enc_config( fixedToFloat_arrL( hMasa->data.dir_align_state.previous_ele_dir2_fx, hMasa->data.dir_align_state.previous_ele_dir2, Q22, MASA_FREQUENCY_BANDS ); fixedToFloat_arrL( hMasa->data.dir_align_state.previous_azi_dir1_fx, hMasa->data.dir_align_state.previous_azi_dir1, Q22, MASA_FREQUENCY_BANDS ); fixedToFloat_arrL( hMasa->data.dir_align_state.previous_azi_dir2_fx, hMasa->data.dir_align_state.previous_ele_dir2, Q22, MASA_FREQUENCY_BANDS ); - for ( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) - { - for ( int j = 0; j < MASA_FREQUENCY_BANDS; j++ ) - { - hMasa->masaMetadata.directional_meta[0].azimuth[i][j] = fixedToFloat( hMasa->masaMetadata.directional_meta[0].azimuth_fx[i][j], Q22 ); - hMasa->masaMetadata.directional_meta[0].elevation[i][j] = fixedToFloat( hMasa->masaMetadata.directional_meta[0].elevation_fx[i][j], Q22 ); - hMasa->masaMetadata.directional_meta[0].energy_ratio[i][j] = fixedToFloat( hMasa->masaMetadata.directional_meta[0].energy_ratio_fx[i][j], Q30 ); - hMasa->masaMetadata.directional_meta[0].spread_coherence[i][j] = fixedToFloat( hMasa->masaMetadata.directional_meta[0].spread_coherence_fx[i][j], Q15 ); - hMasa->masaMetadata.directional_meta[1].azimuth[i][j] = fixedToFloat( hMasa->masaMetadata.directional_meta[1].azimuth_fx[i][j], Q22 ); - hMasa->masaMetadata.directional_meta[1].elevation[i][j] = fixedToFloat( hMasa->masaMetadata.directional_meta[1].elevation_fx[i][j], Q22 ); - hMasa->masaMetadata.directional_meta[1].energy_ratio[i][j] = fixedToFloat( hMasa->masaMetadata.directional_meta[1].energy_ratio_fx[i][j], Q30 ); - hMasa->masaMetadata.directional_meta[1].spread_coherence[i][j] = fixedToFloat( hMasa->masaMetadata.directional_meta[1].spread_coherence_fx[i][j], Q15 ); - } - } #endif // IVAS_FLOAT_FIXED_TO_BE_REMOVED #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - MASA_METADATA_HANDLE current_meta = &( hMasa->masaMetadata ); - MASA_METADATA_HANDLE previous_meta = &( hMasa->data.sync_state.previous_metadata ); for ( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) { for ( int j = 0; j < MASA_FREQUENCY_BANDS; j++ ) { - for ( int k = 0; k < MASA_MAXIMUM_DIRECTIONS; k++ ) - { - current_meta->directional_meta[k].azimuth_fx[i][j] = float_to_fix( current_meta->directional_meta[k].azimuth[i][j], Q22 ); - current_meta->directional_meta[k].elevation_fx[i][j] = float_to_fix( current_meta->directional_meta[k].elevation[i][j], Q22 ); - current_meta->directional_meta[k].energy_ratio_fx[i][j] = float_to_fix( current_meta->directional_meta[k].energy_ratio[i][j], Q30 ); - current_meta->directional_meta[k].spread_coherence_fx[i][j] = float_to_fix16( current_meta->directional_meta[k].spread_coherence[i][j], Q15 ); - previous_meta->directional_meta[k].azimuth_fx[i][j] = floatToFixed( previous_meta->directional_meta[k].azimuth[i][j], Q22 ); - previous_meta->directional_meta[k].elevation_fx[i][j] = floatToFixed( previous_meta->directional_meta[k].elevation[i][j], Q22 ); - previous_meta->directional_meta[k].energy_ratio_fx[i][j] = floatToFixed( previous_meta->directional_meta[k].energy_ratio[i][j], Q30 ); - previous_meta->directional_meta[k].spread_coherence_fx[i][j] = (Word16) min( 32767, floatToFixed( previous_meta->directional_meta[k].spread_coherence[i][j], Q15 ) ); - } f2me( hMasa->data.energy[i][j], &hMasa->data.energy_fx[i][j], &hMasa->data.energy_e[i][j] ); - current_meta->common_meta.surround_coherence_fx[i][j] = float_to_fix16( current_meta->common_meta.surround_coherence[i][j], Q15 ); - current_meta->common_meta.diffuse_to_total_ratio_fx[i][j] = float_to_fix( current_meta->common_meta.diffuse_to_total_ratio[i][j], Q30 ); - current_meta->common_meta.remainder_to_total_ratio_fx[i][j] = float_to_fix( current_meta->common_meta.remainder_to_total_ratio[i][j], Q30 ); - previous_meta->common_meta.surround_coherence_fx[i][j] = (Word16) min( 32767, floatToFixed( previous_meta->common_meta.surround_coherence[i][j], Q15 ) ); - previous_meta->common_meta.diffuse_to_total_ratio_fx[i][j] = floatToFixed( previous_meta->common_meta.diffuse_to_total_ratio[i][j], Q30 ); - previous_meta->common_meta.remainder_to_total_ratio_fx[i][j] = floatToFixed( previous_meta->common_meta.remainder_to_total_ratio[i][j], Q30 ); } } #endif // IVAS_FLOAT_FIXED_CONVERSIONS @@ -2317,31 +1742,7 @@ ivas_error ivas_masa_enc_config( /* Inspect metadata for parameter changes that affect coding. */ detect_metadata_composition_fx( hMasa, &joinedSubframes, &coherencePresent, &isActualTwoDir ); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - for ( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) - { - for ( int j = 0; j < MASA_FREQUENCY_BANDS; j++ ) - { - for ( int k = 0; k < MASA_MAXIMUM_DIRECTIONS; k++ ) - { - current_meta->directional_meta[k].azimuth[i][j] = fixedToFloat( current_meta->directional_meta[k].azimuth_fx[i][j], Q22 ); - current_meta->directional_meta[k].elevation[i][j] = fixedToFloat( current_meta->directional_meta[k].elevation_fx[i][j], Q22 ); - current_meta->directional_meta[k].energy_ratio[i][j] = fixedToFloat( current_meta->directional_meta[k].energy_ratio_fx[i][j], Q30 ); - current_meta->directional_meta[k].spread_coherence[i][j] = fixedToFloat( current_meta->directional_meta[k].spread_coherence_fx[i][j], Q15 ); - previous_meta->directional_meta[k].azimuth[i][j] = fixedToFloat( previous_meta->directional_meta[k].azimuth_fx[i][j], Q22 ); - previous_meta->directional_meta[k].elevation[i][j] = fixedToFloat( previous_meta->directional_meta[k].elevation_fx[i][j], Q22 ); - previous_meta->directional_meta[k].energy_ratio[i][j] = fixedToFloat( previous_meta->directional_meta[k].energy_ratio_fx[i][j], Q30 ); - previous_meta->directional_meta[k].spread_coherence[i][j] = fixedToFloat( previous_meta->directional_meta[k].spread_coherence_fx[i][j], Q15 ); - } - current_meta->common_meta.surround_coherence[i][j] = fixedToFloat( current_meta->common_meta.surround_coherence_fx[i][j], Q15 ); - current_meta->common_meta.diffuse_to_total_ratio[i][j] = fixedToFloat( current_meta->common_meta.diffuse_to_total_ratio_fx[i][j], Q30 ); - current_meta->common_meta.remainder_to_total_ratio[i][j] = fixedToFloat( current_meta->common_meta.remainder_to_total_ratio_fx[i][j], Q30 ); - previous_meta->common_meta.surround_coherence[i][j] = fixedToFloat( previous_meta->common_meta.surround_coherence_fx[i][j], Q15 ); - previous_meta->common_meta.diffuse_to_total_ratio[i][j] = fixedToFloat( previous_meta->common_meta.diffuse_to_total_ratio_fx[i][j], Q30 ); - previous_meta->common_meta.remainder_to_total_ratio[i][j] = fixedToFloat( previous_meta->common_meta.remainder_to_total_ratio_fx[i][j], Q30 ); - } - } -#endif // IVAS_FLOAT_FIXED_CONVERSIONS + hMasa->config.joinedSubframes = joinedSubframes; hMasa->config.coherencePresent = coherencePresent; hMasa->config.numberOfDirections = ( hMasa->masaMetadata.descriptive_meta.numberOfDirections + 1 ) == 2 && isActualTwoDir ? 2 : 1; @@ -2372,7 +1773,69 @@ ivas_error ivas_masa_enc_config( ivas_masa_set_coding_config_fx( &( hMasa->config ), hMasa->data.band_mapping, ivas_total_brate, st_ivas->nchan_transport, ( ivas_format == MC_FORMAT && st_ivas->mc_mode == MC_MODE_MCMASA ) ); } #endif +#ifdef IVAS_FLOAT_FIXED + /* Setup importance weights for two-direction band selection. */ + IF( EQ_16( hMasa->config.numberOfDirections, 2 ) ) + { + set32_fx( hMasa->data.importanceWeight_fx, ONE_IN_Q30, hMasa->config.numCodingBands ); + + IF( EQ_16( hMasa->config.numCodingBands, 5 ) ) + { + hMasa->data.importanceWeight_fx[4] = 751619277; // 0.7f in Q30 + move32(); + } + ELSE IF( EQ_16( hMasa->config.numCodingBands, 8 ) ) + { + hMasa->data.importanceWeight_fx[7] = 751619277; // 0.7f in Q30 + move32(); + } + ELSE IF( EQ_16( hMasa->config.numCodingBands, 10 ) ) + { + hMasa->data.importanceWeight_fx[8] = 751619277; // 0.7f in Q30 + hMasa->data.importanceWeight_fx[9] = 107374182; // 0.1f in Q30 + move32(); + move32(); + } + ELSE IF( EQ_16( hMasa->config.numCodingBands, 12 ) ) + { + hMasa->data.importanceWeight_fx[10] = 751619277; // 0.7f in Q30 + hMasa->data.importanceWeight_fx[11] = 107374182; // 0.1f in Q30 + move32(); + move32(); + } + ELSE IF( EQ_16( hMasa->config.numCodingBands, 18 ) ) + { + hMasa->data.importanceWeight_fx[14] = 858993459; // 0.8f in Q30 + hMasa->data.importanceWeight_fx[15] = 536870912; // 0.5f in Q30 + hMasa->data.importanceWeight_fx[16] = 214748365; // 0.2f in Q30 + hMasa->data.importanceWeight_fx[17] = 0; + move32(); + move32(); + move32(); + move32(); + } + ELSE IF( EQ_16( hMasa->config.numCodingBands, 24 ) ) + { + hMasa->data.importanceWeight_fx[20] = 858993459; // 0.8f in Q30 + hMasa->data.importanceWeight_fx[21] = 536870912; // 0.5f in Q30 + hMasa->data.importanceWeight_fx[22] = 214748365; // 0.2f in Q30 + hMasa->data.importanceWeight_fx[23] = 0; + move32(); + move32(); + move32(); + move32(); + } + IF( EQ_16( hMasa->config.numTwoDirBands, hMasa->config.numCodingBands ) ) + { + set8_fx( (Word8 *) hMasa->data.twoDirBands, 1, hMasa->config.numCodingBands ); + } + } + ELSE + { + set8_fx( (Word8 *) hMasa->data.twoDirBands, 0, hMasa->config.numCodingBands ); + } +#else /* Setup importance weights for two-direction band selection. */ if ( hMasa->config.numberOfDirections == 2 ) { @@ -2420,6 +1883,7 @@ ivas_error ivas_masa_enc_config( { set_c( (int8_t *) hMasa->data.twoDirBands, 0, hMasa->config.numCodingBands ); } +#endif /* Set qmeta to correct values */ if ( ( error = ivas_qmetadata_allocate_memory( hQMetaData, hMasa->config.numCodingBands, hMasa->config.numberOfDirections == 2 && hMasa->config.numTwoDirBands != 0 ? 2 : 1, hMasa->config.useCoherence ) ) != IVAS_ERR_OK ) @@ -2569,7 +2033,7 @@ ivas_error ivas_masa_enc_config( return error; } #endif // IVAS_FLOAT_FIXED - +#ifdef IVAS_FLOAT_FIXED /*-----------------------------------------------------------------------* * ivas_masa_surrcoh_signicant() * @@ -2644,7 +2108,7 @@ UWord8 ivas_masa_surrcoh_signicant_fx( return 0; } - +#else /*-----------------------------------------------------------------------* * ivas_masa_surrcoh_signicant() * @@ -2688,7 +2152,7 @@ uint8_t ivas_masa_surrcoh_signicant( return 0; /* Surrounding coherence was not significant in any subframe */ } - +#endif /*-----------------------------------------------------------------------* * Local functions @@ -6836,7 +6300,7 @@ void ivas_merge_masa_metadata_fx( return; } -#endif // IVAS_FLOAT_FIXED +#else void ivas_merge_masa_metadata( MASA_ENCODER_HANDLE hMasa, /* i/o: MASA enc handle. source for MASA metadata and combined metadata will be here */ @@ -6953,7 +6417,7 @@ void ivas_merge_masa_metadata( return; } - +#endif #ifdef IVAS_FLOAT_FIXED static void quantize_ratio_ism_vector_ivas_fx( const Word16 *ratio_ism, /* ratio_ism_e */ @@ -8981,7 +8445,7 @@ static void ivas_encode_masaism_metadata_fx( { FOR( obj = 0; obj < nchan_ism; obj++ ) { - assert( ( hOmasaData->energy_ratio_ism[sf][band][obj] >= 0 ) && ( hOmasaData->energy_ratio_ism[sf][band][obj] <= 1 ) ); + assert( ( hOmasaData->energy_ratio_ism_fx[sf][band][obj] >= 0 ) && ( hOmasaData->energy_ratio_ism_fx[sf][band][obj] <= ONE_IN_Q30 ) ); ratio_ism_fx[band][obj] = extract_h( hOmasaData->energy_ratio_ism_fx[sf][band][obj] ); // Q14 move16(); } @@ -9165,7 +8629,7 @@ void ivas_merge_masa_transports_fx( return; } -#endif // IVAS_FLOAT_FIXED +#else void ivas_merge_masa_transports( float data_in_f1[][L_FRAME48k], @@ -9186,3 +8650,4 @@ void ivas_merge_masa_transports( return; } +#endif diff --git a/lib_enc/ivas_mc_param_enc.c b/lib_enc/ivas_mc_param_enc.c index a6316ea3d..f74174689 100644 --- a/lib_enc/ivas_mc_param_enc.c +++ b/lib_enc/ivas_mc_param_enc.c @@ -829,31 +829,11 @@ void ivas_param_mc_enc_fx( #ifdef IVAS_FLOAT_FIXED_CONVERSIONS for ( ch = 0; ch < st_ivas->nchan_transport; ch++ ) { - Word16 cpe_idx = ch / 2; - st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.firState1 = (Word16) floatToFixed( st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.firState1_flt, -1 ); - st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.firState2 = (Word16) floatToFixed( st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.firState2_flt, -1 ); - - for ( i = 0; i < NSUBBLOCKS + MAX_TD_DELAY + 1; i++ ) - { - st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.accSubblockNrg[i] = floatToFixed( st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.accSubblockNrg_flt[i], 7 ); - } - - for ( i = 0; i < NSUBBLOCKS + MAX_TD_DELAY; i++ ) - { - st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.subblockNrg[i] = floatToFixed( st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.subblockNrg_flt[i], 7 ); - st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.subblockNrgChange[i] = (Word16) floatToFixed( st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.subblockNrgChange_flt[i], 7 ); - } - - st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.subblockNrg_e = 31 - 7; - st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.accSubblockNrg_e = 31 - 7; - - for ( i = 0; i < L_FRAME_MAX / NSUBBLOCKS; i++ ) - { - st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->delayBuffer.buffer[i] = (Word16) floatToFixed( st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->delayBuffer.buffer_flt[i], 7 ); - } - st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->transientDetector.attackRatioThreshold = float_to_fix16( st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->transientDetector.attackRatioThreshold_flt, Q15 - ATTACKTHRESHOLD_E ); - - st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.facAccSubblockNrg = float_to_fix16( st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.facAccSubblockNrg_flt, 15 ); + Word16 cpe_idx = shr( ch, 1 ); + st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.subblockNrg_e = 31 - Q7; + st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.accSubblockNrg_e = 31 - Q7; + move16(); + move16(); } #endif @@ -1014,35 +994,26 @@ void ivas_param_mc_enc_fx( hParamMC->hMetadataPMC.last_coded_bwidth = hParamMC->hMetadataPMC.coded_bwidth; move16(); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - for ( ch = 0; ch < st_ivas->nchan_transport; ch++ ) + FOR( ch = 0; ch < st_ivas->nchan_transport; ch++ ) { - Word16 cpe_idx = ch / 2; - st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.firState1_flt = fixedToFloat( (Word32) st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.firState1, -1 ); - st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.firState2_flt = fixedToFloat( (Word32) st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.firState2, -1 ); - - for ( i = 0; i < NSUBBLOCKS + MAX_TD_DELAY; i++ ) - { - st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.subblockNrg_flt[i] = fixedToFloat( st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.subblockNrg[i], 7 ); - st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.subblockNrgChange_flt[i] = fixedToFloat( (Word32) st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.subblockNrgChange[i], 7 ); - } - - for ( i = 0; i < NSUBBLOCKS + MAX_TD_DELAY + 1; i++ ) + Word16 cpe_idx = shr( ch, 1 ); + FOR( i = 0; i < NSUBBLOCKS + MAX_TD_DELAY; i++ ) { - st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.accSubblockNrg_flt[i] = fixedToFloat( st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.accSubblockNrg[i], 7 ); + st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.subblockNrg_e = 31 - Q7; + move16(); } - - for ( i = 0; i < L_FRAME_MAX / NSUBBLOCKS; i++ ) + FOR( i = 0; i < NSUBBLOCKS + MAX_TD_DELAY + 1; i++ ) { - st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->delayBuffer.buffer_flt[i] = fixedToFloat( (Word32) st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->delayBuffer.buffer[i], -1 ); + st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.accSubblockNrg_e = 31 - Q7; + move16(); } } +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS for ( i = 0; i < hParamMC->hFbMixer->fb_cfg->num_in_chans; i++ ) { fixedToFloat_arrL( hParamMC->hFbMixer->ppFilterbank_prior_input_fx[i], hParamMC->hFbMixer->ppFilterbank_prior_input[i], Q11, input_frame / PARAM_MC_MDFT_NO_SLOTS ); } - #endif pop_wmops(); diff --git a/lib_enc/ivas_mc_paramupmix_enc.c b/lib_enc/ivas_mc_paramupmix_enc.c index ddb275e08..7e4902855 100644 --- a/lib_enc/ivas_mc_paramupmix_enc.c +++ b/lib_enc/ivas_mc_paramupmix_enc.c @@ -1442,7 +1442,7 @@ static ivas_error ivas_mc_paramupmix_param_est_enc_fx( Word16 *q_cov_real[IVAS_SPAR_MAX_CH]; Word16 *q_cov_dtx_real[IVAS_SPAR_MAX_CH]; Word32 *pp_in_fr_real_fx[MC_PARAMUPMIX_COMBINATIONS * MC_PARAMUPMIX_NCH], *pp_in_fr_imag_fx[MC_PARAMUPMIX_COMBINATIONS * MC_PARAMUPMIX_NCH]; - Word16 q_ppIn_FR[MC_PARAMUPMIX_COMBINATIONS * MC_PARAMUPMIX_NCH]; + Word16 q_ppIn_FR; Word32 rxy_fx, ryy_fx; Word32 rxx_fx; @@ -1588,7 +1588,7 @@ static ivas_error ivas_mc_paramupmix_param_est_enc_fx( set_s( q_cov_dtx_real[i], Q31, MC_PARAMUPMIX_NCH ); } - set_s( q_ppIn_FR, sub( Q14, gb ), MC_PARAMUPMIX_COMBINATIONS * MC_PARAMUPMIX_NCH ); + q_ppIn_FR = sub( Q14, gb ); ivas_enc_cov_handler_process_fx( hMCParamUpmix->hCovEnc[b], pp_in_fr_real_fx, pp_in_fr_imag_fx, q_ppIn_FR, cov_real_fx, q_cov_real, cov_dtx_real_fx, q_cov_dtx_real, hMCParamUpmix->hFbMixer->pFb, 0, hMCParamUpmix->hFbMixer->pFb->filterbank_num_bands, MC_PARAMUPMIX_NCH, 0 /*dtx_vad*/, transient_det[b], HOA_md_ind, NULL, NULL, NULL, 0, 0 ); FOR( i = 0; i < MC_PARAMUPMIX_NCH; i++ ) diff --git a/lib_enc/ivas_mct_enc.c b/lib_enc/ivas_mct_enc.c index 59ea11b01..f326b1a32 100644 --- a/lib_enc/ivas_mct_enc.c +++ b/lib_enc/ivas_mct_enc.c @@ -42,6 +42,7 @@ #ifdef IVAS_FLOAT_FIXED #include "prot_fx.h" #include "ivas_prot_fx.h" +#include "prot_fx_enc.h" #include "rom_com.h" #endif @@ -438,6 +439,7 @@ ivas_error ivas_mct_enc( hMCT->p_orig_spectrum_long[cpe_id][n] = orig_spectrum_long[cpe_id][n]; #ifdef MSAN_FIX set_zero( mdst_spectrum_long[cpe_id][n], L_FRAME48k ); + set_zero( orig_spectrum_long[cpe_id][n], L_FRAME48k ); #endif #endif set32_fx( orig_spectrum_long_fx[cpe_id][n], 0, L_FRAME48k ); @@ -1770,31 +1772,11 @@ static ivas_error ivas_mc_enc_reconfig( } #ifdef IVAS_FLOAT_FIXED #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - MASA_METADATA_HANDLE current_meta = &( st_ivas->hMasa->masaMetadata ); - MASA_METADATA_HANDLE previous_meta = &( st_ivas->hMasa->data.sync_state.previous_metadata ); - fixedToFloat_arrL( st_ivas->hMasa->data.importanceWeight_fx, st_ivas->hMasa->data.importanceWeight, 30, 24 ); for ( int i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) { for ( int j = 0; j < MASA_FREQUENCY_BANDS; j++ ) { - for ( int k = 0; k < MASA_MAXIMUM_DIRECTIONS; k++ ) - { - current_meta->directional_meta[k].azimuth_fx[i][j] = floatToFixed( current_meta->directional_meta[k].azimuth[i][j], Q22 ); - current_meta->directional_meta[k].elevation_fx[i][j] = floatToFixed( current_meta->directional_meta[k].elevation[i][j], Q22 ); - current_meta->directional_meta[k].energy_ratio_fx[i][j] = floatToFixed( current_meta->directional_meta[k].energy_ratio[i][j], Q30 ); - current_meta->directional_meta[k].spread_coherence_fx[i][j] = (Word16) min( 32767, floatToFixed( current_meta->directional_meta[k].spread_coherence[i][j], Q15 ) ); - previous_meta->directional_meta[k].azimuth_fx[i][j] = floatToFixed( previous_meta->directional_meta[k].azimuth[i][j], Q22 ); - previous_meta->directional_meta[k].elevation_fx[i][j] = floatToFixed( previous_meta->directional_meta[k].elevation[i][j], Q22 ); - previous_meta->directional_meta[k].energy_ratio_fx[i][j] = floatToFixed( previous_meta->directional_meta[k].energy_ratio[i][j], Q30 ); - previous_meta->directional_meta[k].spread_coherence_fx[i][j] = (Word16) min( 32767, floatToFixed( previous_meta->directional_meta[k].spread_coherence[i][j], Q15 ) ); - } f2me( st_ivas->hMasa->data.energy[i][j], &st_ivas->hMasa->data.energy_fx[i][j], &st_ivas->hMasa->data.energy_e[i][j] ); - current_meta->common_meta.surround_coherence_fx[i][j] = (Word16) min( 32767, floatToFixed( current_meta->common_meta.surround_coherence[i][j], Q15 ) ); - current_meta->common_meta.diffuse_to_total_ratio_fx[i][j] = floatToFixed( current_meta->common_meta.diffuse_to_total_ratio[i][j], Q30 ); - current_meta->common_meta.remainder_to_total_ratio_fx[i][j] = floatToFixed( current_meta->common_meta.remainder_to_total_ratio[i][j], Q30 ); - previous_meta->common_meta.surround_coherence_fx[i][j] = (Word16) min( 32767, floatToFixed( previous_meta->common_meta.surround_coherence[i][j], Q15 ) ); - previous_meta->common_meta.diffuse_to_total_ratio_fx[i][j] = floatToFixed( previous_meta->common_meta.diffuse_to_total_ratio[i][j], Q30 ); - previous_meta->common_meta.remainder_to_total_ratio_fx[i][j] = floatToFixed( previous_meta->common_meta.remainder_to_total_ratio[i][j], Q30 ); } } #endif // IVAS_FLOAT_FIXED_CONVERSIONS @@ -1803,29 +1785,6 @@ static ivas_error ivas_mc_enc_reconfig( return error; } #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - for ( int i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) - { - for ( int j = 0; j < MASA_FREQUENCY_BANDS; j++ ) - { - for ( int k = 0; k < MASA_MAXIMUM_DIRECTIONS; k++ ) - { - current_meta->directional_meta[k].azimuth[i][j] = fixedToFloat( current_meta->directional_meta[k].azimuth_fx[i][j], Q22 ); - current_meta->directional_meta[k].elevation[i][j] = fixedToFloat( current_meta->directional_meta[k].elevation_fx[i][j], Q22 ); - current_meta->directional_meta[k].energy_ratio[i][j] = fixedToFloat( current_meta->directional_meta[k].energy_ratio_fx[i][j], Q30 ); - current_meta->directional_meta[k].spread_coherence[i][j] = fixedToFloat( current_meta->directional_meta[k].spread_coherence_fx[i][j], Q15 ); - previous_meta->directional_meta[k].azimuth[i][j] = fixedToFloat( previous_meta->directional_meta[k].azimuth_fx[i][j], Q22 ); - previous_meta->directional_meta[k].elevation[i][j] = fixedToFloat( previous_meta->directional_meta[k].elevation_fx[i][j], Q22 ); - previous_meta->directional_meta[k].energy_ratio[i][j] = fixedToFloat( previous_meta->directional_meta[k].energy_ratio_fx[i][j], Q30 ); - previous_meta->directional_meta[k].spread_coherence[i][j] = fixedToFloat( previous_meta->directional_meta[k].spread_coherence_fx[i][j], Q15 ); - } - current_meta->common_meta.surround_coherence[i][j] = fixedToFloat( current_meta->common_meta.surround_coherence_fx[i][j], Q15 ); - current_meta->common_meta.diffuse_to_total_ratio[i][j] = fixedToFloat( current_meta->common_meta.diffuse_to_total_ratio_fx[i][j], Q30 ); - current_meta->common_meta.remainder_to_total_ratio[i][j] = fixedToFloat( current_meta->common_meta.remainder_to_total_ratio_fx[i][j], Q30 ); - previous_meta->common_meta.surround_coherence[i][j] = fixedToFloat( previous_meta->common_meta.surround_coherence_fx[i][j], Q15 ); - previous_meta->common_meta.diffuse_to_total_ratio[i][j] = fixedToFloat( previous_meta->common_meta.diffuse_to_total_ratio_fx[i][j], Q30 ); - previous_meta->common_meta.remainder_to_total_ratio[i][j] = fixedToFloat( previous_meta->common_meta.remainder_to_total_ratio_fx[i][j], Q30 ); - } - } if ( st_ivas->hQMetaData->q_direction != NULL ) { for ( int band = 0; band < st_ivas->hMasa->config.numCodingBands; band++ ) @@ -1841,7 +1800,6 @@ static ivas_error ivas_mc_enc_reconfig( } } } - fixedToFloat_arrL( st_ivas->hMasa->data.importanceWeight_fx, st_ivas->hMasa->data.importanceWeight, 30, 24 ); #endif // IVAS_FLOAT_FIXED_CONVERSIONS #else if ( ( error = ivas_mcmasa_enc_open( st_ivas ) ) != IVAS_ERR_OK ) @@ -1855,31 +1813,11 @@ static ivas_error ivas_mc_enc_reconfig( /* reconfigure McMASA instance */ #ifdef IVAS_FLOAT_FIXED #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - MASA_METADATA_HANDLE current_meta = &( st_ivas->hMasa->masaMetadata ); - MASA_METADATA_HANDLE previous_meta = &( st_ivas->hMasa->data.sync_state.previous_metadata ); - fixedToFloat_arrL( st_ivas->hMasa->data.importanceWeight_fx, st_ivas->hMasa->data.importanceWeight, 30, 24 ); for ( int i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) { for ( int j = 0; j < MASA_FREQUENCY_BANDS; j++ ) { - for ( int k = 0; k < MASA_MAXIMUM_DIRECTIONS; k++ ) - { - current_meta->directional_meta[k].azimuth_fx[i][j] = floatToFixed( current_meta->directional_meta[k].azimuth[i][j], Q22 ); - current_meta->directional_meta[k].elevation_fx[i][j] = floatToFixed( current_meta->directional_meta[k].elevation[i][j], Q22 ); - current_meta->directional_meta[k].energy_ratio_fx[i][j] = floatToFixed( current_meta->directional_meta[k].energy_ratio[i][j], Q30 ); - current_meta->directional_meta[k].spread_coherence_fx[i][j] = (Word16) min( 32767, floatToFixed( current_meta->directional_meta[k].spread_coherence[i][j], Q15 ) ); - previous_meta->directional_meta[k].azimuth_fx[i][j] = floatToFixed( previous_meta->directional_meta[k].azimuth[i][j], Q22 ); - previous_meta->directional_meta[k].elevation_fx[i][j] = floatToFixed( previous_meta->directional_meta[k].elevation[i][j], Q22 ); - previous_meta->directional_meta[k].energy_ratio_fx[i][j] = floatToFixed( previous_meta->directional_meta[k].energy_ratio[i][j], Q30 ); - previous_meta->directional_meta[k].spread_coherence_fx[i][j] = (Word16) min( 32767, floatToFixed( previous_meta->directional_meta[k].spread_coherence[i][j], Q15 ) ); - } f2me( st_ivas->hMasa->data.energy[i][j], &st_ivas->hMasa->data.energy_fx[i][j], &st_ivas->hMasa->data.energy_e[i][j] ); - current_meta->common_meta.surround_coherence_fx[i][j] = (Word16) min( 32767, floatToFixed( current_meta->common_meta.surround_coherence[i][j], Q15 ) ); - current_meta->common_meta.diffuse_to_total_ratio_fx[i][j] = floatToFixed( current_meta->common_meta.diffuse_to_total_ratio[i][j], Q30 ); - current_meta->common_meta.remainder_to_total_ratio_fx[i][j] = floatToFixed( current_meta->common_meta.remainder_to_total_ratio[i][j], Q30 ); - previous_meta->common_meta.surround_coherence_fx[i][j] = (Word16) min( 32767, floatToFixed( previous_meta->common_meta.surround_coherence[i][j], Q15 ) ); - previous_meta->common_meta.diffuse_to_total_ratio_fx[i][j] = floatToFixed( previous_meta->common_meta.diffuse_to_total_ratio[i][j], Q30 ); - previous_meta->common_meta.remainder_to_total_ratio_fx[i][j] = floatToFixed( previous_meta->common_meta.remainder_to_total_ratio[i][j], Q30 ); } } #endif // IVAS_FLOAT_FIXED_CONVERSIONS @@ -1888,29 +1826,6 @@ static ivas_error ivas_mc_enc_reconfig( return error; } #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - for ( int i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) - { - for ( int j = 0; j < MASA_FREQUENCY_BANDS; j++ ) - { - for ( int k = 0; k < MASA_MAXIMUM_DIRECTIONS; k++ ) - { - current_meta->directional_meta[k].azimuth[i][j] = fixedToFloat( current_meta->directional_meta[k].azimuth_fx[i][j], Q22 ); - current_meta->directional_meta[k].elevation[i][j] = fixedToFloat( current_meta->directional_meta[k].elevation_fx[i][j], Q22 ); - current_meta->directional_meta[k].energy_ratio[i][j] = fixedToFloat( current_meta->directional_meta[k].energy_ratio_fx[i][j], Q30 ); - current_meta->directional_meta[k].spread_coherence[i][j] = fixedToFloat( current_meta->directional_meta[k].spread_coherence_fx[i][j], Q15 ); - previous_meta->directional_meta[k].azimuth[i][j] = fixedToFloat( previous_meta->directional_meta[k].azimuth_fx[i][j], Q22 ); - previous_meta->directional_meta[k].elevation[i][j] = fixedToFloat( previous_meta->directional_meta[k].elevation_fx[i][j], Q22 ); - previous_meta->directional_meta[k].energy_ratio[i][j] = fixedToFloat( previous_meta->directional_meta[k].energy_ratio_fx[i][j], Q30 ); - previous_meta->directional_meta[k].spread_coherence[i][j] = fixedToFloat( previous_meta->directional_meta[k].spread_coherence_fx[i][j], Q15 ); - } - current_meta->common_meta.surround_coherence[i][j] = fixedToFloat( current_meta->common_meta.surround_coherence_fx[i][j], Q15 ); - current_meta->common_meta.diffuse_to_total_ratio[i][j] = fixedToFloat( current_meta->common_meta.diffuse_to_total_ratio_fx[i][j], Q30 ); - current_meta->common_meta.remainder_to_total_ratio[i][j] = fixedToFloat( current_meta->common_meta.remainder_to_total_ratio_fx[i][j], Q30 ); - previous_meta->common_meta.surround_coherence[i][j] = fixedToFloat( previous_meta->common_meta.surround_coherence_fx[i][j], Q15 ); - previous_meta->common_meta.diffuse_to_total_ratio[i][j] = fixedToFloat( previous_meta->common_meta.diffuse_to_total_ratio_fx[i][j], Q30 ); - previous_meta->common_meta.remainder_to_total_ratio[i][j] = fixedToFloat( previous_meta->common_meta.remainder_to_total_ratio_fx[i][j], Q30 ); - } - } if ( st_ivas->hQMetaData->q_direction != NULL ) { for ( int band = 0; band < st_ivas->hMasa->config.numCodingBands; band++ ) @@ -1926,7 +1841,6 @@ static ivas_error ivas_mc_enc_reconfig( } } } - fixedToFloat_arrL( st_ivas->hMasa->data.importanceWeight_fx, st_ivas->hMasa->data.importanceWeight, 30, 24 ); #endif // IVAS_FLOAT_FIXED_CONVERSIONS #else if ( ( error = ivas_mcmasa_enc_reconfig( st_ivas ) ) != IVAS_ERR_OK ) @@ -1999,7 +1913,11 @@ static ivas_error ivas_mc_enc_reconfig( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Transient Detection\n" ) ); } +#ifdef IVAS_FLOAT_FIXED + InitTransientDetection_ivas_fx( shl( div_l( st->input_Fs, FRAMES_PER_SEC ), 1 ), NS2SA_FX2( st->input_Fs, DELAY_FIR_RESAMPL_NS ), st->hTranDet, 0 ); +#else InitTransientDetection( (int16_t) ( st->input_Fs / FRAMES_PER_SEC ), NS2SA( st->input_Fs, DELAY_FIR_RESAMPL_NS ), st->hTranDet, 0 ); +#endif } if ( st->hIGFEnc == NULL ) diff --git a/lib_enc/ivas_mdct_core_enc.c b/lib_enc/ivas_mdct_core_enc.c index 57ff78f07..aecf4c9a9 100644 --- a/lib_enc/ivas_mdct_core_enc.c +++ b/lib_enc/ivas_mdct_core_enc.c @@ -1743,10 +1743,6 @@ void ivas_mdct_core_whitening_enc( st->prevEnergyHF_fx = floatToFixed_32( st->prevEnergyHF, q_com ); st->currEnergyHF_fx = floatToFixed_32( st->currEnergyHF, q_com ); st->currEnergyHF_e_fx = sub( Q31, q_com ); - IF( st->hTranDet ) - { - floatToFixed_arr( st->hTranDet->subblockEnergies.subblockNrgChange_flt, st->hTranDet->subblockEnergies.subblockNrgChange, Q15 - NRG_CHANGE_E, NSUBBLOCKS + MAX_TD_DELAY ); - } IF( st->hTcxEnc ) { st->hTcxEnc->tfm_mem_fx = floatToFixed_32( st->hTcxEnc->tfm_mem, Q31 ); @@ -1787,7 +1783,6 @@ void ivas_mdct_core_whitening_enc( #ifdef IVAS_FLOAT_FIXED #ifdef IVAS_FLOAT_FIXED_CONVERSIONS TCX_ENC_HANDLE hTcxEnc = st->hTcxEnc; - floatToFixed_arr( st->hTranDet->transientDetector.pSubblockEnergies->subblockNrgChange_flt, st->hTranDet->transientDetector.pSubblockEnergies->subblockNrgChange, 7, NSUBBLOCKS + MAX_TD_DELAY ); hTcxEnc->tcxltp_norm_corr_past = float_to_fix16( hTcxEnc->tcxltp_norm_corr_past_flt, Q15 ); q_fac = Q_factor_arr( old_wsp[ch], L_WSP ); floatToFixed_arr( old_wsp[ch], old_wsp_fx[ch], q_fac, L_WSP ); @@ -1921,7 +1916,6 @@ void ivas_mdct_core_whitening_enc( if ( st->element_mode == IVAS_CPE_DFT ) { - floatToFixed_arr( st->hTranDet->transientDetector.pSubblockEnergies->subblockNrgChange_flt, st->hTranDet->transientDetector.pSubblockEnergies->subblockNrgChange, Q7, NSUBBLOCKS + MAX_TD_DELAY ); hTcxEnc->tcxltp_norm_corr_past = float_to_fix16( hTcxEnc->tcxltp_norm_corr_past_flt, Q15 ); q_fac = Q_factor_arr( st->buf_wspeech_enc_flt, L_FRAME16k + L_SUBFR + L_FRAME16k + L_NEXT_MAX_16k + 320 ); floatToFixed_arr( st->buf_wspeech_enc_flt, st->buf_wspeech_enc, q_fac, L_FRAME16k + L_SUBFR + L_FRAME16k + L_NEXT_MAX_16k + 320 ); @@ -1929,7 +1923,6 @@ void ivas_mdct_core_whitening_enc( } else if ( st->element_mode != IVAS_CPE_MDCT ) { - floatToFixed_arr( st->hTranDet->transientDetector.pSubblockEnergies->subblockNrgChange_flt, st->hTranDet->transientDetector.pSubblockEnergies->subblockNrgChange, Q7, NSUBBLOCKS + MAX_TD_DELAY ); hTcxEnc->tcxltp_norm_corr_past = float_to_fix16( hTcxEnc->tcxltp_norm_corr_past_flt, Q15 ); q_fac = Q_factor_arr( st->buf_speech_enc_flt, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k ); floatToFixed_arr( st->buf_speech_enc_flt, st->buf_speech_enc, q_fac, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k ); @@ -1938,9 +1931,6 @@ void ivas_mdct_core_whitening_enc( st->hTcxEnc->exp_buf_speech_ltp = 15 - q_fac; } - floatToFixed_arrL( st->hTranDet->transientDetector.pSubblockEnergies->subblockNrg_flt, st->hTranDet->transientDetector.pSubblockEnergies->subblockNrg, 7, 24 ); - floatToFixed_arr( st->hTranDet->transientDetector.pSubblockEnergies->subblockNrgChange_flt, st->hTranDet->transientDetector.pSubblockEnergies->subblockNrgChange, 7, 24 ); - IF( NE_16( st->element_mode, IVAS_CPE_MDCT ) && st->igf ) { if ( st->hIGFEnc ) @@ -2059,15 +2049,9 @@ void ivas_mdct_core_whitening_enc( IF( st->hTcxEnc->fUseTns[0] || st->hTcxEnc->fUseTns[1] ) { if ( st->hTcxCfg->fIsTNSAllowed ) - { // conv params to float - // spectrum[]=float( (fix)spectrum_fx[]) , Q=q_factor_spectrum - // fixedToFloat_arrL( hTcxEnc->spectrum_long_fx, hTcxEnc->spectrum_long, q_factor_spectrum, N_MAX ); - - // subblockNrg_flt=(float)((fixed)subblockNrg) - fixedToFloat_arrL( st->hTranDet->transientDetector.pSubblockEnergies->subblockNrg, st->hTranDet->transientDetector.pSubblockEnergies->subblockNrg_flt, 7, 24 ); - - // subblockNrgChange_flt=(float)((fixed)subblockNrgChange) - fixedToFloat_arr( st->hTranDet->transientDetector.pSubblockEnergies->subblockNrgChange, st->hTranDet->transientDetector.pSubblockEnergies->subblockNrgChange_flt, 7, 24 ); + { + st->hTranDet->transientDetector.pSubblockEnergies->subblockNrg_e = 31 - Q7; + move16(); } } } diff --git a/lib_enc/ivas_qmetadata_enc.c b/lib_enc/ivas_qmetadata_enc.c index 48b1a7a44..79a32e4a4 100644 --- a/lib_enc/ivas_qmetadata_enc.c +++ b/lib_enc/ivas_qmetadata_enc.c @@ -355,7 +355,6 @@ ivas_error ivas_qmetadata_enc_encode_fx( Word16 nbands, nblocks, start_band; Word16 ndirections, d; Word32 azimuth_orig[MASA_MAXIMUM_CODING_SUBBANDS][MAX_PARAM_SPATIAL_SUBFRAMES], elevation_orig[MASA_MAXIMUM_CODING_SUBBANDS][MAX_PARAM_SPATIAL_SUBFRAMES]; - float azimuth_orig_flt[MASA_MAXIMUM_CODING_SUBBANDS][MAX_PARAM_SPATIAL_SUBFRAMES], elevation_orig_flt[MASA_MAXIMUM_CODING_SUBBANDS][MAX_PARAM_SPATIAL_SUBFRAMES]; Word16 all_coherence_zero; Word16 bit_pos_0, total_bits_1dir, bits_no_dirs_coh; Word16 bits_signaling[QMETADATA_MAX_NO_DIRECTIONS]; @@ -442,7 +441,7 @@ ivas_error ivas_qmetadata_enc_encode_fx( bits_diff_sum = 0; move16(); - // TODO + bits_diff[0] = ivas_qmetadata_entropy_encode_diffuseness_fx( hMetaData, &( hQMetaData->q_direction[0] ), &diffuseness_index_max_ec_frame_pre[0] ); move16(); bits_diff_sum = add( bits_diff_sum, bits_diff[0] ); @@ -591,7 +590,6 @@ ivas_error ivas_qmetadata_enc_encode_fx( q_direction->not_in_2D = 0; move16(); /* Quantize directions*/ - // TODO : Remove azimuth_orig_flt and elevation_orig_flt once full fixed point quantize_direction_frame2D_fx( q_direction, azimuth_orig, elevation_orig ); } ELSE @@ -715,19 +713,6 @@ ivas_error ivas_qmetadata_enc_encode_fx( extra_bits = sub( hQMetaData->metadata_max_bits, sub( hMetaData->nb_bits_tot, bit_pos_0 ) ); } -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - for ( int j = hQMetaData->q_direction[0].cfg.start_band; j < hQMetaData->q_direction[0].cfg.nbands; ++j ) - { - fixedToFloat_arrL( hQMetaData->q_direction[d].band_data[j].azimuth_fx, hQMetaData->q_direction[d].band_data[j].azimuth, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); - fixedToFloat_arrL( hQMetaData->q_direction[d].band_data[j].elevation_fx, hQMetaData->q_direction[d].band_data[j].elevation, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); - } - for ( i = start_band; i < nbands; i++ ) - { - fixedToFloat_arrL( azimuth_orig[i], azimuth_orig_flt[i], Q22, nblocks ); - fixedToFloat_arrL( elevation_orig[i], elevation_orig_flt[i], Q22, nblocks ); - } -#endif - /* Requantized directions */ IF( LE_16( add( total_bits_1dir, bits_surround_coh ), hQMetaData->qmetadata_max_bit_req ) && GT_16( add( add( add( bits_dir[d], bits_diff[d] ), bits_coherence[d] ), bits_signaling[d] ), total_bits_1dir ) ) { @@ -753,59 +738,48 @@ ivas_error ivas_qmetadata_enc_encode_fx( IF( hQMetaData->is_masa_ivas_format == 0 ) { - reduce_bits = bits_dir_raw - ( total_bits_1dir - bits_diff[d] - bits_coherence[d] - bits_signaling[d] ); + reduce_bits = sub( bits_dir_raw, sub( sub( sub( total_bits_1dir, bits_diff[d] ), bits_coherence[d] ), bits_signaling[d] ) ); ind_order[0] = -1; + move16(); } ELSE { ind_order[0] = 0; - reduce_bits = min( nbands * nblocks + MASA_BIT_REDUCT_PARAM, bits_dir_raw - ( total_bits_1dir - bits_diff[d] - bits_coherence[d] - bits_signaling[d] ) ); + move16(); + reduce_bits = s_min( add( imult1616( nbands, nblocks ), MASA_BIT_REDUCT_PARAM ), sub( bits_dir_raw, sub( sub( sub( total_bits_1dir, bits_diff[d] ), bits_coherence[d] ), bits_signaling[d] ) ) ); - IF( GT_16( reduce_bits, ( bits_dir_raw - nbands * nblocks ) ) ) + IF( GT_16( reduce_bits, sub( bits_dir_raw, imult1616( nbands, nblocks ) ) ) ) { - reduce_bits = bits_dir_raw - nbands * nblocks; + reduce_bits = sub( bits_dir_raw, imult1616( nbands, nblocks ) ); } } only_reduce_bits_direction_fx( &extra_bits, q_direction, reduce_bits, nbands, nblocks, ind_order ); bits_dir[d] = hMetaData->nb_bits_tot; -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - - for ( int j = 0; j < MASA_MAXIMUM_CODING_SUBBANDS; j++ ) - { - floatToFixed_arrL32( elevation_orig_flt[j], elevation_orig[j], Q22, 4 ); - floatToFixed_arrL32( azimuth_orig_flt[j], azimuth_orig[j], Q22, 4 ); - } + move16(); - for ( int k = q_direction->cfg.start_band; k < q_direction->cfg.nbands; k++ ) - { - floatToFixed_arrL32( q_direction->band_data[k].elevation, q_direction->band_data[k].elevation_fx, Q22, 4 ); - floatToFixed_arrL32( q_direction->band_data[k].azimuth, q_direction->band_data[k].azimuth_fx, Q22, 4 ); - } -#endif // IVAS_FLOAT_FIXED_CONVERSIONS requantize_direction_EC_3_fx( &extra_bits, q_direction, nbands, hMetaData, elevation_orig, azimuth_orig, ind_order ); - bits_dir[d] = hMetaData->nb_bits_tot - bits_dir[d]; -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - for ( int k = q_direction->cfg.start_band; k < q_direction->cfg.nbands; k++ ) - { - fixedToFloat_arrL32( q_direction->band_data[k].elevation_fx, q_direction->band_data[k].elevation, Q22, 4 ); - fixedToFloat_arrL32( q_direction->band_data[k].azimuth_fx, q_direction->band_data[k].azimuth, Q22, 4 ); - } -#endif // IVAS_FLOAT_FIXED_CONVERSIONS + bits_dir[d] = sub( hMetaData->nb_bits_tot, bits_dir[d] ); + move16(); } /* finalize writing coherence */ + test(); + test(); IF( GT_16( bits_coherence[d], 0 ) && EQ_16( all_coherence_zero, 0 ) && GT_16( nblocks, 1 ) ) { bit_pos_start = hMetaData->nb_bits_tot; hMetaData->nb_bits_tot = bit_pos_start_coh; ivas_qmetadata_quantize_coherence_fx( hQMetaData, d, all_coherence_zero, hMetaData, 1, &indice_coherence, 0 ); hMetaData->nb_bits_tot = bit_pos_start; + move16(); + move16(); + move16(); } - IF( EQ_16( d, 0 ) ) + IF( d == 0 ) { - total_bits_1dir = hQMetaData->metadata_max_bits - ( hMetaData->nb_bits_tot - bit_pos_0 ); + total_bits_1dir = sub( hQMetaData->metadata_max_bits, sub( hMetaData->nb_bits_tot, bit_pos_0 ) ); } /* Save quantized DOAs */ @@ -816,13 +790,6 @@ ivas_error ivas_qmetadata_enc_encode_fx( } /* Copy original DOAs back to q_direction*/ -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - for ( i = start_band; i < nbands; i++ ) - { - floatToFixed_arrL( azimuth_orig_flt[i], azimuth_orig[i], Q22, nblocks ); - floatToFixed_arrL( elevation_orig_flt[i], elevation_orig[i], Q22, nblocks ); - } -#endif FOR( i = start_band; i < nbands; i++ ) { Copy32( azimuth_orig[i], q_direction->band_data[i].azimuth_fx, nblocks ); @@ -1227,7 +1194,7 @@ ivas_error ivas_qmetadata_enc_encode( * * Main function for quantizing and coding Spatial Metadata at HRs *-----------------------------------------------------------------------*/ - +#ifndef IVAS_FLOAT_FIXED ivas_error ivas_qmetadata_enc_encode_hr_384_512( BSTR_ENC_HANDLE hMetaData, /* i/o: metadata bitstream handle */ IVAS_QMETADATA *hQMetaData, /* i/o: metadata handle */ @@ -1466,7 +1433,7 @@ ivas_error ivas_qmetadata_enc_encode_hr_384_512( return error; } -#ifdef IVAS_FLOAT_FIXED +#else ivas_error ivas_qmetadata_enc_encode_hr_384_512_fx( BSTR_ENC_HANDLE hMetaData, /* i/o: metadata bitstream handle */ IVAS_QMETADATA *hQMetaData, /* i/o: metadata handle */ diff --git a/lib_enc/ivas_qspherical_enc.c b/lib_enc/ivas_qspherical_enc.c index ee3d4a1e1..74a787b2c 100644 --- a/lib_enc/ivas_qspherical_enc.c +++ b/lib_enc/ivas_qspherical_enc.c @@ -66,7 +66,7 @@ static Word16 direction_distance_cp_fx( Word32 theta, Word32 theta_hat, Word32 t * * *----------------------------------------------------------------------*/ - +#ifndef IVAS_FLOAT_FIXED void quantize_direction_frame( IVAS_QDIRECTION *q_direction, /* i/o: quantized direction structure */ float azimuth_orig[MASA_MAXIMUM_CODING_SUBBANDS][MAX_PARAM_SPATIAL_SUBFRAMES], @@ -166,7 +166,7 @@ void quantize_direction_frame( return; } -#ifdef IVAS_FLOAT_FIXED +#else void quantize_direction_frame_fx( IVAS_QDIRECTION *q_direction, /* i/o: quantized direction structure */ Word32 azimuth_orig[MASA_MAXIMUM_CODING_SUBBANDS][MAX_PARAM_SPATIAL_SUBFRAMES], /* o : Q22 */ diff --git a/lib_enc/ivas_sce_enc.c b/lib_enc/ivas_sce_enc.c index e27f432be..b6e5fbaf6 100644 --- a/lib_enc/ivas_sce_enc.c +++ b/lib_enc/ivas_sce_enc.c @@ -146,62 +146,24 @@ ivas_error ivas_sce_enc( { #ifdef IVAS_FLOAT_FIXED #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - st->hTranDet->subblockEnergies.firState1 = (Word16) floatToFixed( st->hTranDet->subblockEnergies.firState1_flt, -1 ); - st->hTranDet->subblockEnergies.firState2 = (Word16) floatToFixed( st->hTranDet->subblockEnergies.firState2_flt, -1 ); - - FOR( Word16 i = 0; i < NSUBBLOCKS + MAX_TD_DELAY + 1; i++ ) - { - st->hTranDet->subblockEnergies.accSubblockNrg[i] = floatToFixed( st->hTranDet->subblockEnergies.accSubblockNrg_flt[i], 7 ); - } - - FOR( Word16 i = 0; i < NSUBBLOCKS + MAX_TD_DELAY; i++ ) - { - st->hTranDet->subblockEnergies.subblockNrg[i] = floatToFixed( st->hTranDet->subblockEnergies.subblockNrg_flt[i], 7 ); - st->hTranDet->subblockEnergies.subblockNrgChange[i] = (Word16) floatToFixed( st->hTranDet->subblockEnergies.subblockNrgChange_flt[i], 7 ); - } - - - FOR( Word16 i = 0; i < L_FRAME_MAX / NSUBBLOCKS; i++ ) - { - st->hTranDet->delayBuffer.buffer[i] = (Word16) floatToFixed( st->hTranDet->delayBuffer.buffer_flt[i], -1 ); - } - - st->hTranDet->transientDetector.attackRatioThreshold = (Word16) floatToFixed( st->hTranDet->transientDetector.attackRatioThreshold_flt, 11 ); - floatToFixed_arr16( st->input, st->input_fx, -1, input_frame ); - - st->hTranDet->subblockEnergies.facAccSubblockNrg = float_to_fix16( st->hTranDet->subblockEnergies.facAccSubblockNrg_flt, 15 ); - #endif - RunTransientDetection_ivas_fx( st->input_fx, input_frame, st->hTranDet ); - -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - - st->hTranDet->subblockEnergies.firState1_flt = fixedToFloat( (Word32) st->hTranDet->subblockEnergies.firState1, -1 ); - st->hTranDet->subblockEnergies.firState2_flt = fixedToFloat( (Word32) st->hTranDet->subblockEnergies.firState2, -1 ); - FOR( Word16 i = 0; i < NSUBBLOCKS + MAX_TD_DELAY; i++ ) - { - st->hTranDet->subblockEnergies.subblockNrg_flt[i] = fixedToFloat( st->hTranDet->subblockEnergies.subblockNrg[i], 7 ); - st->hTranDet->subblockEnergies.subblockNrgChange_flt[i] = fixedToFloat( (Word32) st->hTranDet->subblockEnergies.subblockNrgChange[i], 7 ); - } - - FOR( Word16 i = 0; i < NSUBBLOCKS + MAX_TD_DELAY + 1; i++ ) - { - st->hTranDet->subblockEnergies.accSubblockNrg_flt[i] = fixedToFloat( st->hTranDet->subblockEnergies.accSubblockNrg[i], 7 ); - } - - FOR( Word16 i = 0; i < L_FRAME_MAX / NSUBBLOCKS; i++ ) - { - st->hTranDet->delayBuffer.buffer_flt[i] = fixedToFloat( (Word32) st->hTranDet->delayBuffer.buffer[i], -1 ); - } -#endif + st->hTranDet->subblockEnergies.subblockNrg_e = 31 - Q7; + st->hTranDet->subblockEnergies.accSubblockNrg_e = 31 - Q7; + move16(); + move16(); #else RunTransientDetection( st->input, input_frame, st->hTranDet ); #endif } +#ifdef IVAS_FLOAT_FIXED + Word16 tmp = GetTCXAvgTemporalFlatnessMeasure_fx( (const TransientDetection *) st->hTranDet, NSUBBLOCKS, 0 ); + currFlatness[0] = me2f_16( tmp, 15 - Q7 ); +#else currFlatness[0] = GetTCXAvgTemporalFlatnessMeasure( st->hTranDet, NSUBBLOCKS, 0 ); +#endif /*----------------------------------------------------------------* * Configuration of core encoder diff --git a/lib_enc/ivas_spar_encoder.c b/lib_enc/ivas_spar_encoder.c index 68b457c3c..582595208 100644 --- a/lib_enc/ivas_spar_encoder.c +++ b/lib_enc/ivas_spar_encoder.c @@ -644,17 +644,18 @@ static ivas_error ivas_spar_cov_md_process( SPAR_ENC_HANDLE hSpar, const IVAS_QMETADATA_HANDLE hQMetaData, BSTR_ENC_HANDLE hMetaData, - const int16_t nchan_inp, - const int16_t sba_order, - float *ppIn_FR_real[IVAS_SPAR_MAX_CH], - float *ppIn_FR_imag[IVAS_SPAR_MAX_CH], - const int16_t transient_det[2], - const int16_t dtx_vad, - const int16_t nchan_transport, - int16_t *dyn_active_w_flag ) + const Word16 nchan_inp, + const Word16 sba_order, + Word32 *ppIn_FR_real_fx[IVAS_SPAR_MAX_CH], + Word32 *ppIn_FR_imag_fx[IVAS_SPAR_MAX_CH], + const Word16 transient_det[2], + const Word16 dtx_vad, + const Word16 nchan_transport, + Word16 *dyn_active_w_flag, + Word16 q_ppIn_FR ) { - int16_t i, j, i_ts, b, table_idx; - int16_t active_w_vlbr; + Word16 i, j, i_ts, b, table_idx; + Word16 active_w_vlbr; /* note: the actual dimensions of matrixes correspond to num_channels = ivas_sba_get_nchan_metadata( sba_order, ivas_total_brate ); */ float *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH]; float *cov_dtx_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH]; @@ -667,34 +668,42 @@ static ivas_error ivas_spar_cov_md_process( Word16 *q_cov_dtx_real[IVAS_SPAR_MAX_CH]; Word32 cov_real_buf_fx[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH][IVAS_MAX_NUM_BANDS]; Word32 cov_dtx_real_buf_fx[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH][IVAS_MAX_NUM_BANDS]; - Word32 *ppIn_FR_real_fx[IVAS_SPAR_MAX_CH], *ppIn_FR_imag_fx[IVAS_SPAR_MAX_CH]; - Word16 q_ppIn_FR[IVAS_SPAR_MAX_CH]; - Word16 input_frame; - Word16 nchan_fb_in; #endif ivas_error error; error = IVAS_ERR_OK; + move32(); - active_w_vlbr = ( hEncoderConfig->ivas_total_brate < IVAS_24k4 ) ? 1 : 0; + IF( LT_32( hEncoderConfig->ivas_total_brate, IVAS_24k4 ) ) + { + active_w_vlbr = 1; + move16(); + } + ELSE + { + active_w_vlbr = 0; + move16(); + } /*-----------------------------------------------------------------------------------------* * Set SPAR bitrates *-----------------------------------------------------------------------------------------*/ - table_idx = ivas_get_spar_table_idx( hEncoderConfig->ivas_total_brate, sba_order, SPAR_CONFIG_BW, NULL, NULL ); + table_idx = ivas_get_spar_table_idx_fx( hEncoderConfig->ivas_total_brate, sba_order, SPAR_CONFIG_BW, NULL, NULL ); - if ( hSpar->hMdEnc->table_idx != table_idx ) + IF( NE_16( hSpar->hMdEnc->table_idx, table_idx ) ) { hSpar->hMdEnc->table_idx = table_idx; - if ( hEncoderConfig->ivas_total_brate != hEncoderConfig->last_ivas_total_brate && !hSpar->spar_reconfig_flag ) + move16(); + test(); + IF( NE_32( hEncoderConfig->ivas_total_brate, hEncoderConfig->last_ivas_total_brate ) && !hSpar->spar_reconfig_flag ) { - if ( ( error = ivas_spar_md_enc_init( hSpar->hMdEnc, hEncoderConfig, sba_order ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_spar_md_enc_init( hSpar->hMdEnc, hEncoderConfig, sba_order ) ), IVAS_ERR_OK ) ) { return error; } } - else + ELSE { ivas_spar_set_bitrate_config( &hSpar->hMdEnc->spar_md_cfg, table_idx, ( hSpar->hMdEnc->spar_hoa_md_flag ) ? IVAS_MAX_NUM_BANDS : SPAR_DIRAC_SPLIT_START_BAND, hSpar->hMdEnc->spar_hoa_dirac2spar_md_flag, 1, hEncoderConfig->Opt_PCA_ON, hSpar->AGC_Enable ); } @@ -746,44 +755,10 @@ static ivas_error ivas_spar_cov_md_process( } #endif -#ifdef IVAS_FLOAT_FIXED - input_frame = extract_l( Mpy_32_32( hEncoderConfig->input_Fs, ONE_BY_FRAMES_PER_SEC_Q31 ) ); - nchan_fb_in = hSpar->hFbMixer->fb_cfg->nchan_fb_in; - move16(); - - FOR( i = 0; i < nchan_fb_in; i++ ) - { - IF( ( ppIn_FR_real_fx[i] = (Word32 *) malloc( sizeof( Word32 ) * input_frame ) ) == NULL ) - { - return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR encoder Fixed" ); - } - set_zero_fx( ppIn_FR_real_fx[i], input_frame ); - IF( ( ppIn_FR_imag_fx[i] = (Word32 *) malloc( sizeof( Word32 ) * input_frame ) ) == NULL ) - { - return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR encoder Fixed" ); - } - set_zero_fx( ppIn_FR_imag_fx[i], input_frame ); - } - set_s( q_ppIn_FR, Q31, nchan_fb_in ); - - FOR( i = 0; i < nchan_fb_in; i++ ) - { - q_ppIn_FR[i] = L_get_q_buf1( ppIn_FR_real[i], input_frame ); - q_ppIn_FR[i] = min( q_ppIn_FR[i], L_get_q_buf1( ppIn_FR_imag[i], input_frame ) ); - floatToFixed_arrL( ppIn_FR_real[i], ppIn_FR_real_fx[i], q_ppIn_FR[i], input_frame ); - floatToFixed_arrL( ppIn_FR_imag[i], ppIn_FR_imag_fx[i], q_ppIn_FR[i], input_frame ); - } -#endif - -#ifdef IVAS_FLOAT_FIXED ivas_enc_cov_handler_process_fx( hSpar->hCovEnc, ppIn_FR_real_fx, ppIn_FR_imag_fx, q_ppIn_FR, cov_real_fx, q_cov_real, cov_dtx_real_fx, q_cov_dtx_real, hSpar->hFbMixer->pFb, 0, hSpar->hFbMixer->pFb->filterbank_num_bands, nchan_inp, dtx_vad, transient_det, hSpar->hMdEnc->HOA_md_ind, &hSpar->hMdEnc->spar_md.res_ind, remix_order_set[hSpar->hMdEnc->spar_md_cfg.remix_unmix_order], dyn_active_w_flag, nchan_transport, 1 ); -#else - ivas_enc_cov_handler_process( hSpar->hCovEnc, ppIn_FR_real, ppIn_FR_imag, cov_real, cov_dtx_real, hSpar->hFbMixer->pFb, 0, hSpar->hFbMixer->pFb->filterbank_num_bands, nchan_inp, dtx_vad, transient_det, hSpar->hMdEnc->HOA_md_ind, - &hSpar->hMdEnc->spar_md.res_ind, remix_order_set[hSpar->hMdEnc->spar_md_cfg.remix_unmix_order], dyn_active_w_flag, nchan_transport, 1 ); -#endif -#ifdef IVAS_FLOAT_FIXED +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS FOR( i = 0; i < nchan_inp; i++ ) { FOR( j = 0; j < nchan_inp; j++ ) @@ -800,29 +775,30 @@ static ivas_error ivas_spar_cov_md_process( free( q_cov_dtx_real[i] ); q_cov_dtx_real[i] = NULL; } - // Note: No need to convert ppIn_FR_real_fx and ppIn_FR_imag_fx back to float as they are not used after ivas_spar_cov_md_process() - - FOR( i = 0; i < nchan_fb_in; i++ ) - { - free( ppIn_FR_real_fx[i] ); - ppIn_FR_real_fx[i] = NULL; - free( ppIn_FR_imag_fx[i] ); - ppIn_FR_imag_fx[i] = NULL; - } #endif - - if ( nchan_transport > 1 && nchan_transport <= ( FOA_CHANNELS - 1 ) ) + test(); + IF( GT_16( nchan_transport, 1 ) && LE_16( nchan_transport, ( FOA_CHANNELS - 1 ) ) ) { push_next_indice( hMetaData, *dyn_active_w_flag, 1 ); - if ( ( *dyn_active_w_flag == 1 ) && ( nchan_transport == 2 ) ) + test(); + IF( EQ_16( *dyn_active_w_flag, 1 ) && EQ_16( nchan_transport, 2 ) ) { - push_next_indice( hMetaData, hSpar->hMdEnc->spar_md.res_ind - nchan_transport, 1 ); + push_next_indice( hMetaData, sub( hSpar->hMdEnc->spar_md.res_ind, nchan_transport ), 1 ); + } + IF( EQ_16( *dyn_active_w_flag, 1 ) ) + { + hSpar->front_vad_flag = 1; + move16(); + } + ELSE + { + hSpar->front_vad_flag = hSpar->front_vad_flag; + move16(); } - hSpar->front_vad_flag = ( *dyn_active_w_flag == 1 ) ? 1 : hSpar->front_vad_flag; } - else + ELSE { - if ( nchan_transport == FOA_CHANNELS ) + IF( EQ_16( nchan_transport, FOA_CHANNELS ) ) { push_next_indice( hMetaData, 0, 1 ); } @@ -832,83 +808,83 @@ static ivas_error ivas_spar_cov_md_process( * MetaData encoder *-----------------------------------------------------------------------------------------*/ - if ( hSpar->hMdEnc->spar_hoa_md_flag == 0 ) + IF( hSpar->hMdEnc->spar_hoa_md_flag == 0 ) { -#ifdef IVAS_FLOAT_FIXED - if ( ( error = ivas_spar_md_enc_process_fx( hSpar->hMdEnc, hEncoderConfig, cov_real, cov_dtx_real, cov_real_fx, hSpar->hCovEnc->pCov_state->q_cov_real_per_band, cov_dtx_real_fx, hSpar->hCovEnc->pCov_dtx_state->q_cov_real_per_band, hMetaData, dtx_vad, nchan_inp, sba_order, hSpar->hFbMixer->prior_mixer, *dyn_active_w_flag, hQMetaData->dirac_mono_flag ) ) != IVAS_ERR_OK ) -#else - if ( ( error = ivas_spar_md_enc_process( hSpar->hMdEnc, hEncoderConfig, cov_real, cov_dtx_real, hMetaData, dtx_vad, nchan_inp, sba_order, hSpar->hFbMixer->prior_mixer, *dyn_active_w_flag, hQMetaData->dirac_mono_flag ) ) != IVAS_ERR_OK ) -#endif + IF( NE_32( ( error = ivas_spar_md_enc_process_fx( hSpar->hMdEnc, hEncoderConfig, cov_real, cov_dtx_real, cov_real_fx, hSpar->hCovEnc->pCov_state->q_cov_real_per_band, cov_dtx_real_fx, hSpar->hCovEnc->pCov_dtx_state->q_cov_real_per_band, hMetaData, dtx_vad, nchan_inp, sba_order, hSpar->hFbMixer->prior_mixer, *dyn_active_w_flag, hQMetaData->dirac_mono_flag ) ), IVAS_ERR_OK ) ) { return error; } } - if ( hSpar->hMdEnc->spar_hoa_dirac2spar_md_flag ) + IF( hSpar->hMdEnc->spar_hoa_dirac2spar_md_flag ) { - float azi_dirac[IVAS_MAX_NUM_BANDS][MAX_PARAM_SPATIAL_SUBFRAMES]; - float ele_dirac[IVAS_MAX_NUM_BANDS][MAX_PARAM_SPATIAL_SUBFRAMES]; - float diffuseness[IVAS_MAX_NUM_BANDS]; - float Wscale_d[IVAS_MAX_NUM_BANDS]; -#ifdef IVAS_FLOAT_FIXED Word16 order; Word32 azi_dirac_fx[IVAS_MAX_NUM_BANDS][MAX_PARAM_SPATIAL_SUBFRAMES]; Word32 ele_dirac_fx[IVAS_MAX_NUM_BANDS][MAX_PARAM_SPATIAL_SUBFRAMES]; Word32 diffuseness_fx[IVAS_MAX_NUM_BANDS]; Word32 Wscale_d_fx[IVAS_MAX_NUM_BANDS]; -#endif - int16_t d_start_band, d_end_band; - int16_t dirac_band_idx; + Word16 d_start_band, d_end_band; + Word16 dirac_band_idx; d_start_band = hSpar->enc_param_start_band; + move16(); d_end_band = IVAS_MAX_NUM_BANDS; + move16(); - for ( b = d_start_band; b < d_end_band; b++ ) + FOR( b = d_start_band; b < d_end_band; b++ ) { - dirac_band_idx = hSpar->dirac_to_spar_md_bands[b] - d_start_band; - for ( i_ts = 0; i_ts < hQMetaData->q_direction->cfg.nblocks; i_ts++ ) + dirac_band_idx = sub( hSpar->dirac_to_spar_md_bands[b], d_start_band ); + FOR( i_ts = 0; i_ts < hQMetaData->q_direction->cfg.nblocks; i_ts++ ) { - azi_dirac[b][i_ts] = hQMetaData->q_direction->band_data[dirac_band_idx].azimuth[i_ts]; - ele_dirac[b][i_ts] = hQMetaData->q_direction->band_data[dirac_band_idx].elevation[i_ts]; + azi_dirac_fx[b][i_ts] = hQMetaData->q_direction->band_data[dirac_band_idx].azimuth_fx[i_ts]; + move32(); + ele_dirac_fx[b][i_ts] = hQMetaData->q_direction->band_data[dirac_band_idx].elevation_fx[i_ts]; + move32(); } - diffuseness[b] = 1.0f - hQMetaData->q_direction->band_data[dirac_band_idx].energy_ratio[0]; + diffuseness_fx[b] = L_sub( ONE_IN_Q30, hQMetaData->q_direction->band_data[dirac_band_idx].energy_ratio_fx[0] ); + move32(); } - - if ( d_start_band >= 6 && dtx_vad == 1 ) + test(); + IF( GE_16( d_start_band, 6 ) && EQ_16( dtx_vad, 1 ) ) { +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS mvr2r( hSpar->hMdEnc->spar_md.band_coeffs[d_start_band - 1].P_quant_re, hSpar->hMdEnc->spar_md.band_coeffs[d_start_band - 1].P_re, IVAS_SPAR_MAX_CH - 1 ); +#endif + Copy32( hSpar->hMdEnc->spar_md.band_coeffs[d_start_band - 1].P_quant_re_fx, hSpar->hMdEnc->spar_md.band_coeffs[d_start_band - 1].P_re_fx, IVAS_SPAR_MAX_CH - 1 ); } - for ( b = d_start_band; b < d_end_band; b++ ) + FOR( b = d_start_band; b < d_end_band; b++ ) { - Wscale_d[b] = 1.0f; - for ( i = 1; i < nchan_inp; i++ ) + Word16 tmp_e, Wscale_d_e = 0; + move16(); + Wscale_d_fx[b] = ONE_IN_Q31; + move32(); + FOR( i = 1; i < nchan_inp; i++ ) { - Wscale_d[b] += cov_real[i][i][b] / max( EPSILON, cov_real[0][0][b] ); + Word32 tmp = L_deposit_h( BASOP_Util_Divide3232_Scale( cov_real_fx[i][i][b], cov_real_fx[0][0][b], &tmp_e ) ); + tmp_e = add( tmp_e, sub( sub( Q31, hSpar->hCovEnc->pCov_state->q_cov_real_per_band[i][i][b] ), sub( Q31, hSpar->hCovEnc->pCov_state->q_cov_real_per_band[0][0][b] ) ) ); + Wscale_d_fx[b] = BASOP_Util_Add_Mant32Exp( tmp, tmp_e, Wscale_d_fx[b], Wscale_d_e, &Wscale_d_e ); + move32(); } - Wscale_d[b] = Wscale_d[b] / ( 1.0f + (float) sba_order ); /*DirAC normalized signal variance sums to 1 + order*/ - Wscale_d[b] = sqrtf( Wscale_d[b] ); - Wscale_d[b] = min( 2.0f, max( Wscale_d[b], 1.0f ) ); + Wscale_d_fx[b] = L_deposit_h( BASOP_Util_Divide3232_Scale( Wscale_d_fx[b], L_add( 1, sba_order ), &tmp_e ) ); + move32(); + tmp_e = add( tmp_e, sub( Wscale_d_e, Q31 ) ); + Wscale_d_fx[b] = Sqrt32( Wscale_d_fx[b], &tmp_e ); + move32(); + Wscale_d_fx[b] = L_shl_sat( Wscale_d_fx[b], sub( tmp_e, Q2 ) ); // saturating to Q29, as final value is limited to 2 below + move32(); + Wscale_d_fx[b] = L_min( ONE_IN_Q30, L_max( Wscale_d_fx[b], ONE_IN_Q29 ) ); // Q29 + move32(); } #ifdef IVAS_FLOAT_FIXED #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - for ( b = d_start_band; b < d_end_band; b++ ) - { - for ( i_ts = 0; i_ts < hQMetaData->q_direction->cfg.nblocks; i_ts++ ) - { - azi_dirac_fx[b][i_ts] = float_to_fix( azi_dirac[b][i_ts], Q22 ); - ele_dirac_fx[b][i_ts] = float_to_fix( ele_dirac[b][i_ts], Q22 ); - } - diffuseness_fx[b] = float_to_fix( diffuseness[b], Q30 ); - Wscale_d_fx[b] = float_to_fix( Wscale_d[b], Q29 ); - } for ( b = 0; b < IVAS_MAX_NUM_BANDS; b++ ) { for ( i = 0; i < IVAS_SPAR_MAX_CH - 1; i++ ) { - hSpar->hMdEnc->spar_md.band_coeffs[b].P_re_fx[i] = float_to_fix( hSpar->hMdEnc->spar_md.band_coeffs[b].P_re[i], Q22 ); - hSpar->hMdEnc->spar_md.band_coeffs[b].pred_re_fx[i] = float_to_fix( hSpar->hMdEnc->spar_md.band_coeffs[b].pred_re[i], Q22 ); + hSpar->hMdEnc->spar_md.band_coeffs[b].P_re_fx[i] = L_shr( hSpar->hMdEnc->spar_md.band_coeffs[b].P_re_fx[i], Q6 ); + hSpar->hMdEnc->spar_md.band_coeffs[b].pred_re_fx[i] = L_shr( hSpar->hMdEnc->spar_md.band_coeffs[b].pred_re_fx[i], Q6 ); } hSpar->hMdEnc->spar_md.band_coeffs[b].q_P_re_fx = Q22; hSpar->hMdEnc->spar_md.band_coeffs[b].q_pred_re_fx = Q22; @@ -974,13 +950,9 @@ static ivas_error ivas_spar_cov_md_process( #endif } - if ( hSpar->hMdEnc->spar_hoa_md_flag ) + IF( hSpar->hMdEnc->spar_hoa_md_flag ) { -#ifdef IVAS_FLOAT_FIXED error = ivas_spar_md_enc_process_fx( hSpar->hMdEnc, hEncoderConfig, cov_real, cov_dtx_real, cov_real_fx, hSpar->hCovEnc->pCov_state->q_cov_real_per_band, cov_dtx_real_fx, hSpar->hCovEnc->pCov_dtx_state->q_cov_real_per_band, hMetaData, dtx_vad, nchan_inp, sba_order, hSpar->hFbMixer->prior_mixer, *dyn_active_w_flag, hQMetaData->dirac_mono_flag ); -#else - error = ivas_spar_md_enc_process( hSpar->hMdEnc, hEncoderConfig, cov_real, cov_dtx_real, hMetaData, dtx_vad, nchan_inp, sba_order, hSpar->hFbMixer->prior_mixer, *dyn_active_w_flag, hQMetaData->dirac_mono_flag ); -#endif } return error; @@ -1271,6 +1243,12 @@ static ivas_error ivas_spar_enc_process( ppIn_FR_imag[i] = pcm_tmp[i] + input_frame; p_pcm_tmp[i] = pcm_tmp[i]; } + FOR( i = 0; i < nchan_fb_in; i++ ) + { + ppIn_FR_real_fx[i] = pcm_tmp_fx[i]; + ppIn_FR_imag_fx[i] = pcm_tmp_fx[i] + input_frame; + p_pcm_tmp_fx[i] = pcm_tmp_fx[i]; + } dtx_vad = ( hEncoderConfig->Opt_DTX_ON == 1 ) ? front_vad_flag : 1; @@ -1304,8 +1282,28 @@ static ivas_error ivas_spar_enc_process( /*-----------------------------------------------------------------------------------------* * Covariance and MD processing *-----------------------------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - if ( ( error = ivas_spar_cov_md_process( hEncoderConfig, st_ivas->hSpar, st_ivas->hQMetaData, hMetaData, nchan_inp, sba_order, ppIn_FR_real, ppIn_FR_imag, transient_det, dtx_vad, nchan_transport, &dyn_active_w_flag ) ) != IVAS_ERR_OK ) + for ( b = hSpar->enc_param_start_band; b < IVAS_MAX_NUM_BANDS; b++ ) + { + Word16 dirac_band_idx = hSpar->dirac_to_spar_md_bands[b] - hSpar->enc_param_start_band; + for ( i_ts = 0; i_ts < hQMetaData->q_direction->cfg.nblocks; i_ts++ ) + { + hQMetaData->q_direction->band_data[dirac_band_idx].azimuth_fx[i_ts] = float_to_fix( hQMetaData->q_direction->band_data[dirac_band_idx].azimuth[i_ts], Q22 ); + hQMetaData->q_direction->band_data[dirac_band_idx].elevation_fx[i_ts] = float_to_fix( hQMetaData->q_direction->band_data[dirac_band_idx].elevation[i_ts], Q22 ); + } + hQMetaData->q_direction->band_data[dirac_band_idx].energy_ratio_fx[0] = float_to_fix( hQMetaData->q_direction->band_data[dirac_band_idx].energy_ratio[0], Q30 ); + } +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + for ( int ch_idx = 0; ch_idx < nchan_fb_in; ch_idx++ ) + { + floatToFixed_arrL32( ppIn_FR_real[ch_idx], ppIn_FR_real_fx[ch_idx], Q14 - gb, input_frame ); + floatToFixed_arrL32( ppIn_FR_imag[ch_idx], ppIn_FR_imag_fx[ch_idx], Q14 - gb, input_frame ); + } +#endif +#endif + + if ( ( error = ivas_spar_cov_md_process( hEncoderConfig, st_ivas->hSpar, st_ivas->hQMetaData, hMetaData, nchan_inp, sba_order, ppIn_FR_real_fx, ppIn_FR_imag_fx, transient_det, dtx_vad, nchan_transport, &dyn_active_w_flag, Q14 - gb ) ) != IVAS_ERR_OK ) { return error; } diff --git a/lib_enc/ivas_spar_md_enc.c b/lib_enc/ivas_spar_md_enc.c index d61ed4bd6..4e8a5ba3f 100644 --- a/lib_enc/ivas_spar_md_enc.c +++ b/lib_enc/ivas_spar_md_enc.c @@ -415,6 +415,20 @@ ivas_error ivas_spar_md_enc_init( } } +#ifdef MSAN_FIX + FOR( i = 0; i < num_channels; i++ ) + { + FOR( j = 0; j < num_channels; j++ ) + { + FOR( k = 0; k < IVAS_MAX_NUM_BANDS; k++ ) + { + hMdEnc->mixer_mat_fx[i][j][k] = 0; + move32(); + } + } + } +#endif + ivas_clear_band_coeffs( hMdEnc->spar_md.band_coeffs, IVAS_MAX_NUM_BANDS ); ivas_clear_band_coeff_idx( hMdEnc->spar_md.band_coeffs_idx, IVAS_MAX_NUM_BANDS ); ivas_clear_band_coeff_idx( hMdEnc->spar_md_prior.band_coeffs_idx, IVAS_MAX_NUM_BANDS ); diff --git a/lib_enc/ivas_stat_enc.h b/lib_enc/ivas_stat_enc.h index 67ff327e2..746d5712a 100644 --- a/lib_enc/ivas_stat_enc.h +++ b/lib_enc/ivas_stat_enc.h @@ -1235,11 +1235,12 @@ typedef struct ivas_omasa_enc_state_structure typedef struct ivas_omasa_encoder_one_data_struct { +#ifndef IVAS_FLOAT_FIXED float energy_ism[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; float energy_ratio_ism[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS]; float q_energy_ratio_ism[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS]; float masa_to_total_energy_ratio[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; -#ifdef IVAS_FLOAT_FIXED +#else Word32 energy_ism_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; Word16 energy_ism_fx_e[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; Word32 energy_ratio_ism_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS]; /*q30*/ @@ -1249,10 +1250,10 @@ typedef struct ivas_omasa_encoder_one_data_struct #ifndef IVAS_FLOAT_FIXED float lp_noise_CPE; /* LP filtered total noise estimation */ #else - Word16 lp_noise_CPE_fx; /* LP filtered total noise estimation Q8 */ + Word16 lp_noise_CPE_fx; /* LP filtered total noise estimation Q8 */ #endif - int16_t omasa_stereo_sw_cnt; + Word16 omasa_stereo_sw_cnt; } OMASA_ENCODER_DATA_STATE, *OMASA_ENCODER_DATA_HANDLE; @@ -1302,16 +1303,17 @@ typedef struct ivas_masa_encoder_data_struct HANDLE_CLDFB_FILTER_BANK cldfbAnaEnc[MAX_NUM_ENC_CLDFB_INSTANCES]; int16_t band_mapping[MASA_FREQUENCY_BANDS + 1]; uint8_t twoDirBands[MASA_FREQUENCY_BANDS]; - float importanceWeight[MASA_FREQUENCY_BANDS]; SPHERICAL_GRID_DATA Sph_Grid16; - float lfeToTotalEnergyRatio[MAX_PARAM_SPATIAL_SUBFRAMES]; #ifdef IVAS_FLOAT_FIXED Word32 importanceWeight_fx[MASA_FREQUENCY_BANDS]; /*q30*/ Word32 lfeToTotalEnergyRatio_fx[MAX_PARAM_SPATIAL_SUBFRAMES]; Word16 lfeToTotalEnergyRatio_e[MAX_PARAM_SPATIAL_SUBFRAMES]; #endif +#ifndef IVAS_FLOAT_FIXED + float importanceWeight[MASA_FREQUENCY_BANDS]; + float lfeToTotalEnergyRatio[MAX_PARAM_SPATIAL_SUBFRAMES]; float prevq_lfeToTotalEnergyRatio; -#ifdef IVAS_FLOAT_FIXED +#else Word32 prevq_lfeToTotalEnergyRatio_fx; // Q31 #endif int16_t prevq_lfeIndex; diff --git a/lib_enc/ivas_stereo_mdct_core_enc.c b/lib_enc/ivas_stereo_mdct_core_enc.c index 3b8f329cc..e57aadf5d 100644 --- a/lib_enc/ivas_stereo_mdct_core_enc.c +++ b/lib_enc/ivas_stereo_mdct_core_enc.c @@ -626,10 +626,6 @@ void stereo_mdct_core_enc( st->prevEnergyHF_fx = floatToFixed_32( st->prevEnergyHF, q_com ); st->currEnergyHF_fx = floatToFixed_32( st->currEnergyHF, q_com ); st->currEnergyHF_e_fx = sub( Q31, q_com ); - IF( st->hTranDet ) - { - floatToFixed_arr( st->hTranDet->subblockEnergies.subblockNrgChange_flt, st->hTranDet->subblockEnergies.subblockNrgChange, Q15 - NRG_CHANGE_E, NSUBBLOCKS + MAX_TD_DELAY ); - } IF( st->hTcxEnc ) { st->hTcxEnc->tfm_mem_fx = floatToFixed_32( st->hTcxEnc->tfm_mem, Q31 ); @@ -663,23 +659,12 @@ void stereo_mdct_core_enc( #endif /* adaptively sync tcx modes*/ #ifdef IVAS_FLOAT_FIXED -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - Word16 temp_q = Q_factor_arrL( sts[0]->hTranDet->subblockEnergies.accSubblockNrg_flt, NSUBBLOCKS + MAX_TD_DELAY + 1 ); - temp_q = s_min( temp_q, Q_factor_arrL( sts[1]->hTranDet->subblockEnergies.accSubblockNrg_flt, NSUBBLOCKS + MAX_TD_DELAY + 1 ) ); - for ( ch = 0; ch < CPE_CHANNELS; ch++ ) - { - st = sts[ch]; - floatToFixed_arrL32( st->hTranDet->subblockEnergies.accSubblockNrg_flt, st->hTranDet->subblockEnergies.accSubblockNrg, temp_q, NSUBBLOCKS + MAX_TD_DELAY + 1 ); - } -#endif - IF( EQ_16( hCPE->last_element_mode, IVAS_CPE_MDCT ) && ( GT_16( abs_s( sub( sts[0]->hTcxCfg->tcx_last_overlap_mode, sts[1]->hTcxCfg->tcx_last_overlap_mode ) ), extract_l( 2 ) ) || EQ_16( sts[0]->hTcxCfg->tcx_last_overlap_mode, sts[1]->hTcxCfg->tcx_last_overlap_mode ) || EQ_16( add( sts[0]->hTcxCfg->tcx_last_overlap_mode, sts[1]->hTcxCfg->tcx_last_overlap_mode ), extract_l( 5 ) ) ) ) /* disable syncing for stereo switching or large diff in last frame overlap */ { sync_tcx_mode( sts ); } - #else if ( ( hCPE->last_element_mode == IVAS_CPE_MDCT ) && ( abs( sts[0]->hTcxCfg->tcx_last_overlap_mode - sts[1]->hTcxCfg->tcx_last_overlap_mode ) > 2 || sts[0]->hTcxCfg->tcx_last_overlap_mode == sts[1]->hTcxCfg->tcx_last_overlap_mode || diff --git a/lib_enc/lib_enc.c b/lib_enc/lib_enc.c index fdb85842b..4ba0f3444 100644 --- a/lib_enc/lib_enc.c +++ b/lib_enc/lib_enc.c @@ -479,14 +479,6 @@ ivas_error IVAS_ENC_FeedObjectMetadata( Word32 yaw_fx = float_to_fix( metadata.yaw, Q22 ); /* Q22 */ Word32 pitch_fx = float_to_fix( metadata.pitch, Q22 ); /* Q22 */ error = ivas_set_ism_metadata_fx( hIvasEnc->st_ivas->hIsmMetaData[ismIndex], azimuth_fx, elevation_fx, radius_fx, yaw_fx, pitch_fx, metadata.non_diegetic_flag ); - - /*================fix-to-flt====================*/ - hIvasEnc->st_ivas->hIsmMetaData[ismIndex]->azimuth = fix_to_float( azimuth_fx, Q22 ); - hIvasEnc->st_ivas->hIsmMetaData[ismIndex]->elevation = fix_to_float( elevation_fx, Q22 ); - hIvasEnc->st_ivas->hIsmMetaData[ismIndex]->radius = fix_to_float( radius_fx, Q9 ); - hIvasEnc->st_ivas->hIsmMetaData[ismIndex]->yaw = fix_to_float( yaw_fx, Q22 ); - hIvasEnc->st_ivas->hIsmMetaData[ismIndex]->pitch = fix_to_float( pitch_fx, Q22 ); - /*================fix-to-flt====================*/ #else error = ivas_set_ism_metadata( hIvasEnc->st_ivas->hIsmMetaData[ismIndex], metadata.azimuth, metadata.elevation, metadata.radius, metadata.yaw, metadata.pitch, metadata.non_diegetic_flag ); #endif diff --git a/lib_enc/stat_enc.h b/lib_enc/stat_enc.h index b1a97be46..500dd1307 100644 --- a/lib_enc/stat_enc.h +++ b/lib_enc/stat_enc.h @@ -139,8 +139,10 @@ typedef struct signal_buffers_enc_data_structure /* Delay buffer: Used to buffer input samples and to define the subblock size of a transient detector. */ typedef struct { - int16_t nSubblockSize; /* Subblock size of a transient detector that uses this delay buffer. */ + int16_t nSubblockSize; /* Subblock size of a transient detector that uses this delay buffer. */ +#ifndef IVAS_FLOAT_FIXED float buffer_flt[L_FRAME_MAX / NSUBBLOCKS]; /* Delay buffer */ +#endif Word16 buffer[L_FRAME48k / NSUBBLOCKS]; int16_t nDelay; /* Size of the delay buffer in use. Maximum delay from all users of this buffer. */ @@ -149,27 +151,37 @@ typedef struct /* Subblock energies: Holds subblock energies and recursively accumulated energies. Also buffers the energies. */ typedef struct { - DelayBuffer *pDelayBuffer; /* Delay buffer. */ + DelayBuffer *pDelayBuffer; /* Delay buffer. */ +#ifndef IVAS_FLOAT_FIXED float subblockNrg_flt[NSUBBLOCKS + MAX_TD_DELAY]; /* Subblock energies with a delay buffering. */ +#endif Word32 subblockNrg[NSUBBLOCKS + MAX_TD_DELAY]; Word16 subblockNrg_e; +#ifndef IVAS_FLOAT_FIXED float accSubblockNrg_flt[NSUBBLOCKS + MAX_TD_DELAY + 1]; /* Recursively accumulated subblock energies with a delay buffering. At index i the value corresponds to the accumulated subblock energy up to i-1, including block i-1 and without block i. */ +#endif Word32 accSubblockNrg[NSUBBLOCKS + MAX_TD_DELAY + 1]; Word16 accSubblockNrg_e; +#ifndef IVAS_FLOAT_FIXED float subblockNrgChange_flt[NSUBBLOCKS + MAX_TD_DELAY]; /* subblockNrgChange[i] = max(subblockNrg[i]/subblockNrg[i-1], subblockNrg[i-1]/subblockNrg[i]) */ - Word16 subblockNrgChange[NSUBBLOCKS + MAX_TD_DELAY]; /* Q7(15 - SUBBLOCK_NRG_CHANGE_E) */ - int16_t nDelay; /* Size of the delay buffer in use, as number of subblocks. Maximum delay from all users of this buffer. */ - int16_t nPartialDelay; /* Delay of the input (modulo pDelayBuffer->nSubblockSize), nPartialDelay <= pDelayBuffer->nDelay. */ +#endif + Word16 subblockNrgChange[NSUBBLOCKS + MAX_TD_DELAY]; /* Q7(15 - SUBBLOCK_NRG_CHANGE_E) */ + int16_t nDelay; /* Size of the delay buffer in use, as number of subblocks. Maximum delay from all users of this buffer. */ + int16_t nPartialDelay; /* Delay of the input (modulo pDelayBuffer->nSubblockSize), nPartialDelay <= pDelayBuffer->nDelay. */ /* Decay factor for the recursive accumulation */ +#ifndef IVAS_FLOAT_FIXED float facAccSubblockNrg_flt; +#endif Word16 facAccSubblockNrg; /* High-pass filter states (delay line) */ +#ifndef IVAS_FLOAT_FIXED float firState1_flt; float firState2_flt; +#endif Word16 firState1; Word16 firState2; @@ -190,11 +202,13 @@ typedef struct TransientDetector int16_t nSubblocksToCheck; /* Number of subblocks to check for transients. */ TCheckSubblocksForAttack CheckSubblocksForAttack; /* Function for checking a presence of an attack. */ TCheckSubblocksForAttack_fx CheckSubblocksForAttack_fx; /* Function for checking a presence of an attack. */ - float attackRatioThreshold_flt; /* Attack ratio threshold */ - Word16 attackRatioThreshold; /* Attack ratio threshold Q11 */ - int16_t bIsAttackPresent; /* True when an attack was detected. */ - int16_t prev_bIsAttackPresent; /* True if an attack was detected in the previous frame. */ - int16_t attackIndex; /* The index of an attack. */ +#ifndef IVAS_FLOAT_FIXED + float attackRatioThreshold_flt; /* Attack ratio threshold */ +#endif + Word16 attackRatioThreshold; /* Attack ratio threshold Q11 */ + int16_t bIsAttackPresent; /* True when an attack was detected. */ + int16_t prev_bIsAttackPresent; /* True if an attack was detected in the previous frame. */ + int16_t attackIndex; /* The index of an attack. */ } TransientDetector; /* Transient detection: Holds all transient detectors and buffers used by them. */ @@ -1106,7 +1120,10 @@ typedef struct sp_mus_clas_structure typedef struct lpd_state_structure { + +#ifndef MSAN_FIX Word16 nbits; /* number of bits used by ACELP or TCX */ +#endif /* signal memory */ float syn_flt[1 + M]; /* Synthesis memory (non-pe) */ diff --git a/lib_enc/swb_bwe_enc_fx.c b/lib_enc/swb_bwe_enc_fx.c index d3e56a079..ba1fe063f 100644 --- a/lib_enc/swb_bwe_enc_fx.c +++ b/lib_enc/swb_bwe_enc_fx.c @@ -4084,7 +4084,11 @@ void fd_bwe_enc_init_fx( set16_fx( hBWE_FD->new_input_hp_fx, 0, NS2SA( 16000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_12k8_NS + DELAY_FIR_RESAMPL_NS - DELAY_CLDFB_NS ) ); set16_fx( hBWE_FD->old_input_fx, 0, NS2SA( 48000, DELAY_FD_BWE_ENC_12k8_NS + DELAY_FIR_RESAMPL_NS ) ); set16_fx( hBWE_FD->old_input_wb_fx, 0, NS2SA( 16000, DELAY_FD_BWE_ENC_12k8_NS ) ); +#ifndef MSAN_FIX set16_fx( hBWE_FD->old_input_lp_fx, 0, NS2SA( 16000, ACELP_LOOK_NS + DELAY_SWB_TBE_16k_NS ) ); +#else + set16_fx( hBWE_FD->old_input_lp_fx, 0, NS2SA( 16000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_NS ) ); +#endif set16_fx( hBWE_FD->old_syn_12k8_16k_fx, 0, NS2SA( 16000, DELAY_FD_BWE_ENC_NS ) ); hBWE_FD->prev_mode = NORMAL; move16(); diff --git a/lib_enc/transient_detection.c b/lib_enc/transient_detection.c index fc757ed49..b88d296fb 100644 --- a/lib_enc/transient_detection.c +++ b/lib_enc/transient_detection.c @@ -63,17 +63,17 @@ * Local function prototypes *---------------------------------------------------------------*/ -static void InitDelayBuffer( const int16_t nFrameLength, const int16_t nDelay, DelayBuffer *pDelayBuffer ); -static void InitSubblockEnergies( const int16_t nFrameLength, const int16_t nDelay, DelayBuffer *pDelayBuffer, SubblockEnergies *pSubblockEnergies ); -static void InitTransientDetector( SubblockEnergies *pSubblockEnergies, const int16_t nDelay, const int16_t nSubblocksToCheck, TCheckSubblocksForAttack pCheckSubblocksForAttack, const float attackRatioThreshold, TransientDetector *pTransientDetector ); #ifndef IVAS_FLOAT_FIXED static void UpdateDelayBuffer( const float *inputconst, const int16_t nSamplesAvailable, DelayBuffer *pDelayBuffer ); static void HighPassFilter( const float *input, const int16_t length, float *pFirState1, float *pFirState2, float *output ); static void UpdateSubblockEnergies( const float *input, const int16_t nSamplesAvailable, SubblockEnergies *pSubblockEnergies ); static void CalculateSubblockEnergies( const float *input, const int16_t nSamplesAvailable, SubblockEnergies *pSubblockEnergies ); static void RunTransientDetector( TransientDetector *pTransientDetector ); -#endif +static void InitTransientDetector( SubblockEnergies *pSubblockEnergies, const int16_t nDelay, const int16_t nSubblocksToCheck, TCheckSubblocksForAttack pCheckSubblocksForAttack, const float attackRatioThreshold, TransientDetector *pTransientDetector ); +static void InitSubblockEnergies( const int16_t nFrameLength, const int16_t nDelay, DelayBuffer *pDelayBuffer, SubblockEnergies *pSubblockEnergies ); +static void InitDelayBuffer( const int16_t nFrameLength, const int16_t nDelay, DelayBuffer *pDelayBuffer ); static void GetAttackForTCXDecision( const float *pSubblockNrg, const float *pAccSubblockNrg, const int16_t nSubblocks, const int16_t nPastSubblocks, const float attackRatioThreshold, int16_t *pbIsAttackPresent, int16_t *pAttackIndex ); +#endif /*-------------------------------------------------------------------* * InitTransientDetection() @@ -81,6 +81,7 @@ static void GetAttackForTCXDecision( const float *pSubblockNrg, const float *pAc * *-------------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED void InitTransientDetection( const int16_t nFrameLength, const int16_t nTCXDelay, @@ -109,7 +110,7 @@ void InitTransientDetection( return; } - +#endif /*-------------------------------------------------------------------* * GetTCXAvgTemporalFlatnessMeasure() @@ -117,6 +118,7 @@ void InitTransientDetection( * *-------------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED float GetTCXAvgTemporalFlatnessMeasure( TRAN_DET_HANDLE hTranDet, const int16_t nCurrentSubblocks, @@ -136,7 +138,9 @@ float GetTCXAvgTemporalFlatnessMeasure( sumTempFlatness = 0.0f; assert( ( nPrevSubblocks <= nRelativeDelay ) && ( nCurrentSubblocks <= NSUBBLOCKS + nDelay ) ); + pSubblockNrgChange = &pSubblockEnergies->subblockNrgChange_flt[nRelativeDelay - nPrevSubblocks]; + for ( i = 0; i < nTotBlocks; i++ ) { sumTempFlatness += pSubblockNrgChange[i]; @@ -144,14 +148,14 @@ float GetTCXAvgTemporalFlatnessMeasure( return sumTempFlatness / (float) nTotBlocks; } - +#endif /*-------------------------------------------------------------------* * GetTCXMaxenergyChange() * * *-------------------------------------------------------------------*/ - +#ifndef IVAS_FLOAT_FIXED float GetTCXMaxenergyChange( TRAN_DET_HANDLE hTranDet, const int16_t isTCX10, @@ -208,6 +212,7 @@ float GetTCXMaxenergyChange( return maxEnergyChange; } +#endif #ifndef IVAS_FLOAT_FIXED @@ -415,6 +420,7 @@ void SetTCXModeInfo( * See TCheckSubblocksForAttack for definition of parameters. * It is assumed that the delay of MDCT overlap was not taken into account, so that the last subblock corresponds to the newest input subblock. */ +#ifndef IVAS_FLOAT_FIXED static void GetAttackForTCXDecision( const float *pSubblockNrg, const float *pAccSubblockNrg, @@ -506,8 +512,10 @@ static void InitDelayBuffer( return; } +#endif +#ifndef IVAS_FLOAT_FIXED static void InitSubblockEnergies( const int16_t nFrameLength, const int16_t nDelay, @@ -518,21 +526,22 @@ static void InitSubblockEnergies( assert( ( pDelayBuffer != NULL ) && ( pSubblockEnergies != NULL ) && ( pDelayBuffer->nSubblockSize * NSUBBLOCKS == nFrameLength ) && ( pDelayBuffer->nSubblockSize > 0 ) ); - set_f( pSubblockEnergies->subblockNrg_flt, MIN_BLOCK_ENERGY, nMaxBuffSize ); - set_f( pSubblockEnergies->accSubblockNrg_flt, MIN_BLOCK_ENERGY, nMaxBuffSize + 1 ); - set_f( pSubblockEnergies->subblockNrgChange_flt, 1.0f, nMaxBuffSize ); pSubblockEnergies->nDelay = nDelay / pDelayBuffer->nSubblockSize; assert( pSubblockEnergies->nDelay < nMaxBuffSize ); pSubblockEnergies->nPartialDelay = nDelay % pDelayBuffer->nSubblockSize; - pSubblockEnergies->facAccSubblockNrg_flt = 0.8125f; /* Energy accumulation factor */ + set_f( pSubblockEnergies->accSubblockNrg_flt, MIN_BLOCK_ENERGY, nMaxBuffSize + 1 ); + set_f( pSubblockEnergies->subblockNrg_flt, MIN_BLOCK_ENERGY, nMaxBuffSize ); + set_f( pSubblockEnergies->subblockNrgChange_flt, 1.0f, nMaxBuffSize ); pSubblockEnergies->firState1_flt = 0.0f; pSubblockEnergies->firState2_flt = 0.0f; + pSubblockEnergies->facAccSubblockNrg_flt = 0.8125f; /* Energy accumulation factor */ pSubblockEnergies->pDelayBuffer = pDelayBuffer; pDelayBuffer->nDelay = max( pDelayBuffer->nDelay, pSubblockEnergies->nPartialDelay ); return; } +#endif /** Init transient detector. @@ -545,6 +554,7 @@ static void InitSubblockEnergies( * @param attackRatioThreshold Attack ratio threshold. * @param pTransientDetector Structure to be initialized. */ +#ifndef IVAS_FLOAT_FIXED static void InitTransientDetector( SubblockEnergies *pSubblockEnergies, const int16_t nDelay, @@ -572,6 +582,7 @@ static void InitTransientDetector( return; } +#endif #ifndef IVAS_FLOAT_FIXED diff --git a/lib_enc/transient_detection_fx.c b/lib_enc/transient_detection_fx.c index 1300d421f..7b003bc9f 100644 --- a/lib_enc/transient_detection_fx.c +++ b/lib_enc/transient_detection_fx.c @@ -942,9 +942,9 @@ static void InitSubblockEnergies( Word16 nFrameLength, Word16 nDelay, DelayBuffe assert( ( pDelayBuffer != NULL ) && ( pSubblockEnergies != NULL ) && ( pDelayBuffer->nSubblockSize * NSUBBLOCKS == nFrameLength ) && ( pDelayBuffer->nSubblockSize > 0 ) ); - set32_fx( pSubblockEnergies->subblockNrg, MIN_BLOCK_ENERGY, nMaxBuffSize ); - set32_fx( pSubblockEnergies->accSubblockNrg, MIN_BLOCK_ENERGY, nMaxBuffSize + 1 ); - set16_fx( pSubblockEnergies->subblockNrgChange, 0x7fff, nMaxBuffSize ); + set32_fx( pSubblockEnergies->subblockNrg, 13743, nMaxBuffSize ); + set32_fx( pSubblockEnergies->accSubblockNrg, 13743, nMaxBuffSize + 1 ); + set16_fx( pSubblockEnergies->subblockNrgChange, ONE_IN_Q7, nMaxBuffSize ); pSubblockEnergies->nDelay = nDelay / pDelayBuffer->nSubblockSize; assert( pSubblockEnergies->nDelay < nMaxBuffSize ); pSubblockEnergies->nPartialDelay = nDelay % pDelayBuffer->nSubblockSize; diff --git a/lib_rend/ivas_reverb_iir_filter.c b/lib_rend/ivas_reverb_iir_filter.c index 85245aadc..9b7a9c0c5 100644 --- a/lib_rend/ivas_reverb_iir_filter.c +++ b/lib_rend/ivas_reverb_iir_filter.c @@ -63,9 +63,9 @@ void ivas_reverb_iir_filt_init( FOR( UWord16 i = 0; i < maxTaps; i++ ) { - iirFilter->CoefA_fx[i] = 0; + iirFilter->CoefA_fx[i] = 0;/*Q30*/ move32(); - iirFilter->CoefB_fx[i] = 0; + iirFilter->CoefB_fx[i] = 0;/*Q30*/ move32(); } @@ -111,8 +111,8 @@ void ivas_reverb_iir_filt_init( void ivas_reverb_iir_filt_set( ivas_rev_iir_filter_t *iirFilter, /* i/o: IIR filter */ UWord16 nr_taps, /* i : number of IIR filter taps */ - const Word16 *coefA, /* i : A filter coefficients to set */ - const Word16 *coefB /* i : the B filter coefficients to set */ + const Word16 *coefA, /* i : A filter coefficients to set Q14*/ + const Word16 *coefB /* i : the B filter coefficients to set Q14*/ ) { UWord16 i; @@ -132,7 +132,7 @@ void ivas_reverb_iir_filt_set( { FOR( i = 0; i < iirFilter->nr_taps; i++ ) { - iirFilter->CoefB_fx[i] = L_shl( coefB[i], 16 ); /*Q30*/ + iirFilter->CoefB_fx[i] = L_shl( coefB[i]/*Q14*/, 16 ); /*Q30*/ move32(); } } @@ -140,9 +140,9 @@ void ivas_reverb_iir_filt_set( { FOR( i = 0; i < iirFilter->nr_taps; i++ ) { - iirFilter->CoefA_fx[i] = L_shl( coefA[i], 16 ); /*Q30*/ + iirFilter->CoefA_fx[i] = L_shl( coefA[i]/*Q14*/, 16 ); /*Q30*/ move32(); - iirFilter->CoefB_fx[i] = L_shl( coefB[i], 16 ); /*Q30*/ + iirFilter->CoefB_fx[i] = L_shl( coefB[i]/*Q14*/, 16 ); /*Q30*/ move32(); } } @@ -202,35 +202,35 @@ void ivas_reverb_iir_filt_set( void ivas_reverb_iir_filt_2taps_feed_blk_fx( ivas_rev_iir_filter_t *iirFilter, /* i/o: IIR filter */ const UWord16 blk_size, /* i : size */ - const Word32 *input, /* i : input buffer */ - Word32 *output /* i : output buffer */ + const Word32 *input, /* i : input buffer Q30 */ + Word32 *output /* i/o : output buffer Q30 */ ) { UWord16 i; Word32 flt_output_fx = 0; move32(); - Word32 flt_CoefB_0_fx = iirFilter->CoefB_fx[0]; + Word32 flt_CoefB_0_fx = iirFilter->CoefB_fx[0];/*Q30*/ move32(); - Word32 flt_CoefB_1_fx = iirFilter->CoefB_fx[1]; + Word32 flt_CoefB_1_fx = iirFilter->CoefB_fx[1];/*Q30*/ move32(); - Word32 flt_CoefA_1_fx = iirFilter->CoefA_fx[1]; + Word32 flt_CoefA_1_fx = iirFilter->CoefA_fx[1];/*Q30*/ move32(); - Word32 flt_pBuffer_0_fx = iirFilter->pBuffer_fx[0]; + Word32 flt_pBuffer_0_fx = iirFilter->pBuffer_fx[0];/*Q30*/ move32(); - Word32 flt_pBuffer_1_fx = iirFilter->pBuffer_fx[1]; + Word32 flt_pBuffer_1_fx = iirFilter->pBuffer_fx[1];/*Q30*/ move32(); FOR( i = 0; i < blk_size; i++ ) { - flt_output_fx = L_add( L_shl( Mpy_32_32( input[i], flt_CoefB_0_fx ), 1 ), flt_pBuffer_0_fx ); - flt_pBuffer_0_fx = L_sub( L_add( flt_pBuffer_1_fx, L_shl( Mpy_32_32( input[i], flt_CoefB_1_fx ), 1 ) ), L_shl( Mpy_32_32( flt_output_fx, flt_CoefA_1_fx ), 1 ) ); - output[i] = flt_output_fx; + flt_output_fx = L_add( L_shl( Mpy_32_32( input[i], flt_CoefB_0_fx ), 1 ), flt_pBuffer_0_fx );//Q30 + flt_pBuffer_0_fx = L_sub( L_add( flt_pBuffer_1_fx/*Q30*/, L_shl( Mpy_32_32( input[i]/*Q30*/, flt_CoefB_1_fx /*Q30*/)/*Q29*/, 1 ) /*Q30*/), L_shl( Mpy_32_32( flt_output_fx/*Q30*/, flt_CoefA_1_fx/*Q30*/ ), 1 /*Q30*/) );/*Q30*/ + output[i] = flt_output_fx;/*Q30*/ move32(); } - iirFilter->pBuffer_fx[0] = flt_pBuffer_0_fx; + iirFilter->pBuffer_fx[0] = flt_pBuffer_0_fx;/*Q30*/ move32(); - iirFilter->pBuffer_fx[1] = flt_pBuffer_1_fx; + iirFilter->pBuffer_fx[1] = flt_pBuffer_1_fx;/*Q30*/ move32(); - iirFilter->Output_fx = flt_output_fx; + iirFilter->Output_fx = flt_output_fx;//Q30 move32(); return; diff --git a/lib_rend/lib_rend.c b/lib_rend/lib_rend.c index 4ddf64c89..a178953ba 100644 --- a/lib_rend/lib_rend.c +++ b/lib_rend/lib_rend.c @@ -12149,9 +12149,9 @@ static void copyMasaMetadataToDiracRenderer_fx( { FOR( bin = MASA_band_grouping_24[band]; bin < MASA_band_grouping_24[band + 1] && bin < maxBin; bin++ ) { - hSpatParamRendCom->azimuth[meta_write_index][bin] = (Word16) meta->directional_meta[0].azimuth[sf][band]; + hSpatParamRendCom->azimuth[meta_write_index][bin] = extract_l( L_shr( meta->directional_meta[0].azimuth_fx[sf][band], Q22 ) ); // Q22 -> Q0 move16(); - hSpatParamRendCom->elevation[meta_write_index][bin] = (Word16) meta->directional_meta[0].elevation[sf][band]; + hSpatParamRendCom->elevation[meta_write_index][bin] = extract_l( L_shr( meta->directional_meta[0].elevation_fx[sf][band], Q22 ) ); // Q22 -> Q0 move16(); hSpatParamRendCom->energy_ratio1_fx[meta_write_index][bin] = meta->directional_meta[0].energy_ratio_fx[sf][band]; move32(); @@ -12164,9 +12164,9 @@ static void copyMasaMetadataToDiracRenderer_fx( IF( EQ_16( hSpatParamRendCom->numSimultaneousDirections, 2 ) ) { - hSpatParamRendCom->azimuth2[meta_write_index][bin] = (Word16) meta->directional_meta[1].azimuth[sf][band]; + hSpatParamRendCom->azimuth2[meta_write_index][bin] = extract_l( L_shr( meta->directional_meta[1].azimuth_fx[sf][band], Q22 ) ); // Q22 -> Q0 move16(); - hSpatParamRendCom->elevation2[meta_write_index][bin] = (Word16) meta->directional_meta[1].elevation[sf][band]; + hSpatParamRendCom->elevation2[meta_write_index][bin] = extract_l( L_shr( meta->directional_meta[1].elevation_fx[sf][band], Q22 ) ); // Q22 -> Q0 move16(); hSpatParamRendCom->energy_ratio2_fx[meta_write_index][bin] = meta->directional_meta[1].energy_ratio_fx[sf][band]; move32(); diff --git a/lib_util/masa_file_reader.c b/lib_util/masa_file_reader.c index 11178d54c..59d7b632c 100644 --- a/lib_util/masa_file_reader.c +++ b/lib_util/masa_file_reader.c @@ -190,8 +190,9 @@ ivas_error MasaFileReader_readNextFrame( for ( b = 0; b < MASA_FREQUENCY_BANDS; b++ ) { +#ifndef IVAS_FLOAT_FIXED deindex_sph_idx( readIndex[b], &self->sph_grid16, &( hMeta->directional_meta[i].elevation[j][b] ), &( hMeta->directional_meta[i].azimuth[j][b] ) ); -#ifdef IVAS_FLOAT_FIXED +#else deindex_sph_idx_fx( readIndex[b], &self->sph_grid16, &( hMeta->directional_meta[i].elevation_fx[j][b] ), &( hMeta->directional_meta[i].azimuth_fx[j][b] ) ); #endif hMeta->directional_meta[i].spherical_index[j][b] = readIndex[b]; @@ -205,9 +206,10 @@ ivas_error MasaFileReader_readNextFrame( for ( b = 0; b < MASA_FREQUENCY_BANDS; b++ ) { +#ifndef IVAS_FLOAT_FIXED hMeta->directional_meta[i].energy_ratio[j][b] = ( (float) readOther[b] ) / UINT8_MAX; -#ifdef IVAS_FLOAT_FIXED - hMeta->directional_meta[i].energy_ratio_fx[j][b] = (Word32) ( readOther[b] * ONE_IN_Q22 ); // Q30 +#else + hMeta->directional_meta[i].energy_ratio_fx[j][b] = (Word32) ( readOther[b] * ONE_IN_Q22 ); // Q30 #endif } @@ -220,8 +222,9 @@ ivas_error MasaFileReader_readNextFrame( for ( b = 0; b < MASA_FREQUENCY_BANDS; b++ ) { +#ifndef IVAS_FLOAT_FIXED hMeta->directional_meta[i].spread_coherence[j][b] = ( (float) readOther[b] ) / UINT8_MAX; -#ifdef IVAS_FLOAT_FIXED +#else hMeta->directional_meta[i].spread_coherence_fx[j][b] = (Word16) ( readOther[b] * ONE_IN_Q7 ); // Q15 #endif @@ -237,9 +240,10 @@ ivas_error MasaFileReader_readNextFrame( for ( b = 0; b < MASA_FREQUENCY_BANDS; b++ ) { +#ifndef IVAS_FLOAT_FIXED hMeta->common_meta.diffuse_to_total_ratio[j][b] = ( (float) readOther[b] ) / UINT8_MAX; -#ifdef IVAS_FLOAT_FIXED - hMeta->common_meta.diffuse_to_total_ratio_fx[j][b] = (Word32) ( readOther[b] * ONE_IN_Q22 ); // Q30 +#else + hMeta->common_meta.diffuse_to_total_ratio_fx[j][b] = (Word32) ( readOther[b] * ONE_IN_Q22 ); // Q30 #endif } @@ -252,9 +256,10 @@ ivas_error MasaFileReader_readNextFrame( for ( b = 0; b < MASA_FREQUENCY_BANDS; b++ ) { +#ifndef IVAS_FLOAT_FIXED hMeta->common_meta.surround_coherence[j][b] = ( (float) readOther[b] ) / UINT8_MAX; -#ifdef IVAS_FLOAT_FIXED - hMeta->common_meta.surround_coherence_fx[j][b] = shl( (Word16) readOther[b], 7 ); // Q8->Q15 +#else + hMeta->common_meta.surround_coherence_fx[j][b] = shl( (Word16) readOther[b], 7 ); // Q8->Q15 move16(); #endif } @@ -267,7 +272,12 @@ ivas_error MasaFileReader_readNextFrame( for ( b = 0; b < MASA_FREQUENCY_BANDS; b++ ) { +#ifndef IVAS_FLOAT_FIXED hMeta->common_meta.remainder_to_total_ratio[j][b] = ( (float) readOther[b] ) / UINT8_MAX; +#else + hMeta->common_meta.remainder_to_total_ratio_fx[j][b] = L_shl( (Word32) readOther[b], Q22 ); // Q8 -> Q30 + move32(); +#endif } } -- GitLab From 12a75978d256362b19f42634065977a208bb6807 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Mon, 21 Oct 2024 18:34:17 +0530 Subject: [PATCH 014/128] Clang formatting changes --- lib_rend/ivas_reverb_iir_filter.c | 32 +++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/lib_rend/ivas_reverb_iir_filter.c b/lib_rend/ivas_reverb_iir_filter.c index 9b7a9c0c5..5ec718a3f 100644 --- a/lib_rend/ivas_reverb_iir_filter.c +++ b/lib_rend/ivas_reverb_iir_filter.c @@ -63,9 +63,9 @@ void ivas_reverb_iir_filt_init( FOR( UWord16 i = 0; i < maxTaps; i++ ) { - iirFilter->CoefA_fx[i] = 0;/*Q30*/ + iirFilter->CoefA_fx[i] = 0; /*Q30*/ move32(); - iirFilter->CoefB_fx[i] = 0;/*Q30*/ + iirFilter->CoefB_fx[i] = 0; /*Q30*/ move32(); } @@ -132,7 +132,7 @@ void ivas_reverb_iir_filt_set( { FOR( i = 0; i < iirFilter->nr_taps; i++ ) { - iirFilter->CoefB_fx[i] = L_shl( coefB[i]/*Q14*/, 16 ); /*Q30*/ + iirFilter->CoefB_fx[i] = L_shl( coefB[i] /*Q14*/, 16 ); /*Q30*/ move32(); } } @@ -140,9 +140,9 @@ void ivas_reverb_iir_filt_set( { FOR( i = 0; i < iirFilter->nr_taps; i++ ) { - iirFilter->CoefA_fx[i] = L_shl( coefA[i]/*Q14*/, 16 ); /*Q30*/ + iirFilter->CoefA_fx[i] = L_shl( coefA[i] /*Q14*/, 16 ); /*Q30*/ move32(); - iirFilter->CoefB_fx[i] = L_shl( coefB[i]/*Q14*/, 16 ); /*Q30*/ + iirFilter->CoefB_fx[i] = L_shl( coefB[i] /*Q14*/, 16 ); /*Q30*/ move32(); } } @@ -209,28 +209,28 @@ void ivas_reverb_iir_filt_2taps_feed_blk_fx( UWord16 i; Word32 flt_output_fx = 0; move32(); - Word32 flt_CoefB_0_fx = iirFilter->CoefB_fx[0];/*Q30*/ + Word32 flt_CoefB_0_fx = iirFilter->CoefB_fx[0]; /*Q30*/ move32(); - Word32 flt_CoefB_1_fx = iirFilter->CoefB_fx[1];/*Q30*/ + Word32 flt_CoefB_1_fx = iirFilter->CoefB_fx[1]; /*Q30*/ move32(); - Word32 flt_CoefA_1_fx = iirFilter->CoefA_fx[1];/*Q30*/ + Word32 flt_CoefA_1_fx = iirFilter->CoefA_fx[1]; /*Q30*/ move32(); - Word32 flt_pBuffer_0_fx = iirFilter->pBuffer_fx[0];/*Q30*/ + Word32 flt_pBuffer_0_fx = iirFilter->pBuffer_fx[0]; /*Q30*/ move32(); - Word32 flt_pBuffer_1_fx = iirFilter->pBuffer_fx[1];/*Q30*/ + Word32 flt_pBuffer_1_fx = iirFilter->pBuffer_fx[1]; /*Q30*/ move32(); FOR( i = 0; i < blk_size; i++ ) { - flt_output_fx = L_add( L_shl( Mpy_32_32( input[i], flt_CoefB_0_fx ), 1 ), flt_pBuffer_0_fx );//Q30 - flt_pBuffer_0_fx = L_sub( L_add( flt_pBuffer_1_fx/*Q30*/, L_shl( Mpy_32_32( input[i]/*Q30*/, flt_CoefB_1_fx /*Q30*/)/*Q29*/, 1 ) /*Q30*/), L_shl( Mpy_32_32( flt_output_fx/*Q30*/, flt_CoefA_1_fx/*Q30*/ ), 1 /*Q30*/) );/*Q30*/ - output[i] = flt_output_fx;/*Q30*/ + flt_output_fx = L_add( L_shl( Mpy_32_32( input[i], flt_CoefB_0_fx ), 1 ), flt_pBuffer_0_fx ); // Q30 + flt_pBuffer_0_fx = L_sub( L_add( flt_pBuffer_1_fx /*Q30*/, L_shl( Mpy_32_32( input[i] /*Q30*/, flt_CoefB_1_fx /*Q30*/ ) /*Q29*/, 1 ) /*Q30*/ ), L_shl( Mpy_32_32( flt_output_fx /*Q30*/, flt_CoefA_1_fx /*Q30*/ ), 1 /*Q30*/ ) ); /*Q30*/ + output[i] = flt_output_fx; /*Q30*/ move32(); } - iirFilter->pBuffer_fx[0] = flt_pBuffer_0_fx;/*Q30*/ + iirFilter->pBuffer_fx[0] = flt_pBuffer_0_fx; /*Q30*/ move32(); - iirFilter->pBuffer_fx[1] = flt_pBuffer_1_fx;/*Q30*/ + iirFilter->pBuffer_fx[1] = flt_pBuffer_1_fx; /*Q30*/ move32(); - iirFilter->Output_fx = flt_output_fx;//Q30 + iirFilter->Output_fx = flt_output_fx; // Q30 move32(); return; -- GitLab From e7aae6fea9329fae292ab83bc643f3f9a1593eb9 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Mon, 21 Oct 2024 19:34:42 +0530 Subject: [PATCH 015/128] EVS encoder BE fix --- lib_enc/transient_detection_fx.c | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/lib_enc/transient_detection_fx.c b/lib_enc/transient_detection_fx.c index 7b003bc9f..4c9907b28 100644 --- a/lib_enc/transient_detection_fx.c +++ b/lib_enc/transient_detection_fx.c @@ -44,6 +44,7 @@ static void InitDelayBuffer( Word16 nFrameLength, Word16 nDelay, DelayBuffer *pDelayBuffer ); static void InitSubblockEnergies( Word16 nFrameLength, Word16 nDelay, DelayBuffer *pDelayBuffer, SubblockEnergies *pSubblockEnergies ); +static void InitSubblockEnergies_ivas_fx( Word16 nFrameLength, Word16 nDelay, DelayBuffer *pDelayBuffer, SubblockEnergies *pSubblockEnergies ); static void InitTransientDetector_fx( SubblockEnergies *pSubblockEnergies, Word16 nDelay, Word16 nSubblocksToCheck, TCheckSubblocksForAttack_fx pCheckSubblocksForAttack, Word16 attackRatioThreshold, TransientDetector *pTransientDetector ); static void UpdateDelayBuffer( Word16 const *input, Word16 nSamplesAvailable, DelayBuffer *pDelayBuffer ); static void HighPassFilter( Word16 const *input, Word16 length, Word16 *pFirState1, Word16 *pFirState2, Word16 *output ); @@ -255,7 +256,7 @@ void InitTransientDetection_ivas_fx( Word16 nFrameLength, /* Init the delay buffer. */ InitDelayBuffer( nFrameLength, nTCXDelay, &pTransientDetection->delayBuffer ); /* Init a subblock energies buffer used for the TCX Short/Long decision. */ - InitSubblockEnergies( nFrameLength, nTCXDelay, &pTransientDetection->delayBuffer, &pTransientDetection->subblockEnergies ); + InitSubblockEnergies_ivas_fx( nFrameLength, nTCXDelay, &pTransientDetection->delayBuffer, &pTransientDetection->subblockEnergies ); /* Init the TCX Short/Long transient detector. */ InitTCXTransientDetector( nTCXDelay, &pTransientDetection->subblockEnergies, &pTransientDetection->transientDetector ); /* We need two past subblocks for the TCX TD and NSUBBLOCKS+1 for the temporal flatness measure FOR the TCX LTP. */ @@ -940,6 +941,28 @@ static void InitSubblockEnergies( Word16 nFrameLength, Word16 nDelay, DelayBuffe (void) nFrameLength; + assert( ( pDelayBuffer != NULL ) && ( pSubblockEnergies != NULL ) && ( pDelayBuffer->nSubblockSize * NSUBBLOCKS == nFrameLength ) && ( pDelayBuffer->nSubblockSize > 0 ) ); + + set32_fx( pSubblockEnergies->subblockNrg, MIN_BLOCK_ENERGY, nMaxBuffSize ); + set32_fx( pSubblockEnergies->accSubblockNrg, MIN_BLOCK_ENERGY, nMaxBuffSize + 1 ); + set16_fx( pSubblockEnergies->subblockNrgChange, 0x7fff, nMaxBuffSize ); + pSubblockEnergies->nDelay = nDelay / pDelayBuffer->nSubblockSize; + assert( pSubblockEnergies->nDelay < nMaxBuffSize ); + pSubblockEnergies->nPartialDelay = nDelay % pDelayBuffer->nSubblockSize; + pSubblockEnergies->facAccSubblockNrg = 26624 /*0.8125f Q15*/; /* Energy accumulation factor */ + pSubblockEnergies->firState1 = 0; + pSubblockEnergies->firState2 = 0; + + pSubblockEnergies->pDelayBuffer = pDelayBuffer; + pDelayBuffer->nDelay = s_max( pDelayBuffer->nDelay, pSubblockEnergies->nPartialDelay ); +} + +static void InitSubblockEnergies_ivas_fx( Word16 nFrameLength, Word16 nDelay, DelayBuffer *pDelayBuffer, SubblockEnergies *pSubblockEnergies ) +{ + Word16 const nMaxBuffSize = sizeof( pSubblockEnergies->subblockNrg ) / sizeof( pSubblockEnergies->subblockNrg[0] ); + (void) nFrameLength; + + assert( ( pDelayBuffer != NULL ) && ( pSubblockEnergies != NULL ) && ( pDelayBuffer->nSubblockSize * NSUBBLOCKS == nFrameLength ) && ( pDelayBuffer->nSubblockSize > 0 ) ); set32_fx( pSubblockEnergies->subblockNrg, 13743, nMaxBuffSize ); -- GitLab From 5a40c85431a7e48c5f2cbd15d0475ea9e9898768 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Tue, 22 Oct 2024 14:09:27 +0530 Subject: [PATCH 016/128] Q-info addition for decoder and renderer files --- lib_com/ivas_prot.h | 103 +- lib_dec/core_switching_dec.c | 137 ++- lib_dec/ivas_stereo_dft_dec_fx.c | 1388 ++++++++++++------------ lib_dec/ivas_svd_dec.c | 528 ++++----- lib_dec/ivas_tcx_core_dec.c | 234 ++-- lib_dec/ivas_td_low_rate_dec.c | 86 +- lib_rend/ivas_crend.c | 341 +++--- lib_rend/ivas_limiter.c | 890 +-------------- lib_rend/ivas_objectRenderer_mix.c | 229 ++-- lib_rend/ivas_objectRenderer_sfx.c | 190 ++-- lib_rend/ivas_objectRenderer_sources.c | 246 +++-- lib_rend/ivas_reverb_filter_design.c | 227 ++-- lib_rend/ivas_rom_rend.c | 819 ++++++++++++++ lib_rend/ivas_rom_rend.h | 2 + lib_rend/ivas_shoebox.c | 146 +-- lib_rend/ivas_stat_rend.h | 386 +++---- lib_rend/ivas_td_decorr.c | 67 +- 17 files changed, 3048 insertions(+), 2971 deletions(-) diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index 5ffc7f4f3..876313d1b 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -695,17 +695,17 @@ void decod_gen_2sbfr( #ifdef IVAS_FLOAT_FIXED void decod_gen_2sbfr_ivas_fx( - Decoder_State *st, /* i/o: decoder static memory */ - const Word16 sharpFlag, /* i : formant sharpening flag */ - const Word16 *Aq, /* i : LP filter coefficient */ - Word16 *pitch_buf, /* o : floating pitch values for each subframe */ - Word16 *voice_factors, /* o : voicing factors */ - Word16 *exc, /* i/o: adapt. excitation exc */ - Word16 *exc2, /* i/o: adapt. excitation/total exc */ - Word16 *bwe_exc, /* o : excitation for SWB TBE */ - Word16 *gain_buf, /* o : floating pitch gain for each subframe */ - const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag */ - const Word16 tdm_Pri_pitch_buf[] /* i : pitch values for primary channel */ + Decoder_State *st, /* i/o: decoder static memory */ + const Word16 sharpFlag, /* i : formant sharpening flag `Q0*/ + const Word16 *Aq, /* i : LP filter coefficient Q12*/ + Word16 *pitch_buf, /* o : Word16 pitch values for each subframe Q6*/ + Word16 *voice_factors, /* o : voicing factors Q15*/ + Word16 *exc, /* i/o: adapt. excitation exc Q_exc*/ + Word16 *exc2, /* i/o: adapt. excitation/total exc Q_exc*/ + Word16 *bwe_exc, /* o : excitation for SWB TBE Q_exc*/ + Word16 *gain_buf, /* o : Word16 pitch gain for each subframe Q14*/ + const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag Q0*/ + const Word16 tdm_Pri_pitch_buf[] /* i : pitch values for primary channel Q6*/ ); #endif @@ -1860,9 +1860,9 @@ void stereo_dft_quantize_res_gains( ); #ifdef IVAS_FLOAT_FIXED void stereo_dft_dequantize_itd_fx( - Word16 *ind, - Word32 *out, - const Word32 output_Fs + Word16 *ind, /* Q0 */ + Word32 *out, /* Q15 */ + const Word32 output_Fs /* Q0 */ ); #endif // IVAS_FLOAT_FIXED @@ -1894,9 +1894,9 @@ void stereo_dft_enc_sid_coh( #ifdef IVAS_FLOAT_FIXED void stereo_dft_dec_sid_coh_fx( Decoder_State *st, /* i/o: decoder state structure */ - const Word16 nbands, /* i : number of DFT stereo bands */ - Word16 *coh, /* i/o: coherence */ - Word16 *nb_bits /* i/o: number of bits read */ + const Word16 nbands, /* i : number of DFT stereo bands Q0*/ + Word16 *coh, /* i/o: coherence Q15*/ + Word16 *nb_bits /* i/o: number of bits read Q0*/ ); #endif // IVAS_FLOAT_FIXED @@ -2045,17 +2045,17 @@ void bpf_pitch_coherence( ); #ifdef IVAS_FLOAT_FIXED void stereo_dft_dec_read_BS_fx( - const Word32 ivas_total_brate, /* i : IVAS total bitrate */ - const Word32 element_brate, /* i : element bitrate */ - Word32 *total_brate, /* o : total bitrate */ - Decoder_State *st, /* i/o: decoder state structure */ - STEREO_DFT_DEC_DATA_HANDLE hStereoDft, /* i/o: decoder stereo handle */ - const Word16 bwidth, /* i : bandwidth */ - const Word16 output_frame, /* i : output frame length */ - Word32 res_buf[STEREO_DFT_N_8k], /* o : residual buffer */ - Word16 *nb_bits, /* o : number of bits read */ - Word16 *coh, /* i/o: Coherence */ - const Word16 ivas_format /* i : ivas format */ + const Word32 ivas_total_brate, /* i : IVAS total bitrate Q0*/ + const Word32 element_brate, /* i : element bitrate Q0*/ + Word32 *total_brate, /* o : total bitrate Q0*/ + Decoder_State *st, /* i/o: decoder state structure */ + STEREO_DFT_DEC_DATA_HANDLE hStereoDft, /* i/o: decoder stereo handle */ + const Word16 bwidth, /* i : bandwidth Q0*/ + const Word16 output_frame, /* i : output frame length Q0*/ + Word32 res_buf_fx[STEREO_DFT_N_8k], /* o : residual buffer Q0*/ + Word16 *nb_bits, /* o : number of bits read Q0*/ + Word16 *coh_fx, /* i/o: Coherence Q15*/ + const Word16 ivas_format /* i : ivas format Q0*/ ); #endif // IVAS_FLOAT_FIXED @@ -2959,15 +2959,14 @@ uint16_t get_indice_st( #ifdef IVAS_FLOAT_FIXED void tdm_low_rate_dec_fx( - Decoder_State *st, /* i/o: decoder static memory */ - Word16 dct_epit[], /* o : GSC excitation in DCT domain */ - //Word16 *tmp_noise, /* o : long term temporary noise energy */ - Word16 *pitch_buf, /* o : floating pitch values for each subframe */ - Word16 *voice_factors, /* o : voicing factors */ - Word16 *exc, /* i/o: adapt. excitation exc */ - Word16 *exc2, /* i/o: adapt. excitation/total exc */ - Word16 *bwe_exc, /* o : excitation for SWB TBE */ - const Word16 *lsf_new /* i : ISFs at the end of the frame */ + Decoder_State *st, /* i/o: decoder static memory */ + Word16 dct_epit[], /* o : GSC excitation in DCT domain Q_exc*/ + Word16 *pitch_buf, /* o : Word16 pitch values for each subframe Q6*/ + Word16 *voice_factors, /* o : voicing factors Q15*/ + Word16 *exc, /* i/o: adapt. excitation exc Q_exc*/ + Word16 *exc2, /* i/o: adapt. excitation/total exc Q_exc*/ + Word16 *bwe_exc, /* o : excitation for SWB TBE Q_exc*/ + const Word16 *lsf_new /* i : ISFs at the end of the frame Q8/100 (2.56x)*/ ); #endif @@ -5462,18 +5461,18 @@ Word16 matrix_product_mant_exp( #ifdef IVAS_FLOAT_FIXED void mat2svdMat_fx( - const Word32 *mat, /* i : matrix as column ordered vector */ - Word32 svdMat[MAX_OUTPUT_CHANNELS][MAX_OUTPUT_CHANNELS], /* o : matrix as two-dimensional arry */ - const Word16 nRows, /* i : number of rows of the matrix */ - const Word16 mCols, /* i : number of columns of the matrix */ - const Word16 transpose /* i : flag indication transposition */ + const Word32 *mat, /* i : matrix as column ordered vector Qx*/ + Word32 svdMat[MAX_OUTPUT_CHANNELS][MAX_OUTPUT_CHANNELS], /* o : matrix as two-dimensional arry Qx*/ + const Word16 nRows, /* i : number of rows of the matrix Q0*/ + const Word16 mCols, /* i : number of columns of the matrix Q0*/ + const Word16 transpose /* i : flag indication transposition Q0*/ ); void svdMat2mat_fx( - Word32 svdMat[MAX_OUTPUT_CHANNELS][MAX_OUTPUT_CHANNELS], /* i : matrix as two-dimensional arry */ - Word32 *mat, /* o : matrix as column ordered vector */ - const Word16 nRows, /* i : number of rows of the matrix */ - const Word16 mCols /* i : number of columns of the matrix */ + Word32 svdMat[MAX_OUTPUT_CHANNELS][MAX_OUTPUT_CHANNELS], /* i : matrix as two-dimensional arry Qx*/ + Word32 *mat, /* o : matrix as column ordered vector Qx*/ + const Word16 nRows, /* i : number of rows of the matrix Q0*/ + const Word16 mCols /* i : number of columns of the matrix Q0*/ ); #else @@ -5599,14 +5598,14 @@ Word16 computeMixingMatricesResidual_fx( #ifdef IVAS_FLOAT_FIXED /*! r: error or success */ Word16 svd_fx( - Word32 InputMatrix[][MAX_OUTPUT_CHANNELS], /* i : matrix to be decomposed (M) */ + Word32 InputMatrix[][MAX_OUTPUT_CHANNELS], /* i : matrix to be decomposed (M) InputMatrix_e*/ Word16 InputMatrix_e, - Word32 singularVectors_Left[][MAX_OUTPUT_CHANNELS], /* o : left singular vectors (U) */ - Word32 singularValues[MAX_OUTPUT_CHANNELS], /* o : singular values vector (S) */ - Word32 singularVectors_Right[][MAX_OUTPUT_CHANNELS], /* o : right singular vectors (V) */ + Word32 singularVectors_Left_fx[][MAX_OUTPUT_CHANNELS], /* o : left singular vectors (U) Q31*/ + Word32 singularValues_fx[MAX_OUTPUT_CHANNELS], /* o : singular values vector (S) singularValues_fx_e*/ + Word32 singularVectors_Right_fx[][MAX_OUTPUT_CHANNELS], /* o : right singular vectors (V) Q31*/ Word16 singularValues_fx_e[MAX_OUTPUT_CHANNELS], - const Word16 nChannelsL, /* i : number of rows in the matrix to be decomposed */ - const Word16 nChannelsC /* i : number of columns in the matrix to be decomposed */ + const Word16 nChannelsL, /* i : number of rows in the matrix to be decomposed Q0*/ + const Word16 nChannelsC /* i : number of columns in the matrix to be decomposed Q0*/ ); #else /*! r: error or success */ diff --git a/lib_dec/core_switching_dec.c b/lib_dec/core_switching_dec.c index 4a6c372c6..47ab012a9 100644 --- a/lib_dec/core_switching_dec.c +++ b/lib_dec/core_switching_dec.c @@ -78,7 +78,7 @@ ivas_error core_switching_pre_dec_ivas_fx( Word16 i, oldLenClasBuff, newLenClasBuff; ivas_error error; Word16 exp = 25; - + move16(); error = IVAS_ERR_OK; move32(); @@ -86,7 +86,7 @@ ivas_error core_switching_pre_dec_ivas_fx( test(); test(); test(); - IF( EQ_16( st->last_codec_mode, MODE2 ) || ( ( EQ_16( st->last_core, TCX_20_CORE ) || EQ_16( st->last_core, TCX_10_CORE ) ) && GT_16( st->element_mode, EVS_MONO ) ) ) + IF( EQ_16( st->last_codec_mode, MODE2 ) || ( ( EQ_16( st->last_core, TCX_20_CORE ) || EQ_16( st->last_core, TCX_10_CORE ) ) && ( st->element_mode > EVS_MONO ) ) ) { #ifndef FIX_770_DISCONTINUITIES_SW_TCX2ACELP Copy( st->mem_syn2_fx, st->mem_syn1_fx, M ); @@ -113,9 +113,9 @@ ivas_error core_switching_pre_dec_ivas_fx( move16(); IF( st->hPFstat != NULL ) { - Scale_sig( st->hPFstat->mem_pf_in, L_SUBFR, st->Q_syn ); /* Post_filter mem */ - Scale_sig( st->hPFstat->mem_res2, DECMEM_RES2, st->Q_syn ); /* NB post_filter mem */ - Scale_sig( st->hPFstat->mem_stp, L_SUBFR, st->Q_syn ); /* Post_filter mem */ + Scale_sig( st->hPFstat->mem_pf_in, L_SUBFR, st->Q_syn ); /* Post_filter mem ,Q_syn*/ + Scale_sig( st->hPFstat->mem_res2, DECMEM_RES2, st->Q_syn ); /* NB post_filter mem , Q_syn*/ + Scale_sig( st->hPFstat->mem_stp, L_SUBFR, st->Q_syn ); /* Post_filter mem ,Q_syn*/ set16_fx( st->hBPF->pst_old_syn_fx, 0, NBPSF_PIT_MAX ); /* BPF mem*/ } IF( st->hBPF != NULL ) @@ -123,9 +123,10 @@ ivas_error core_switching_pre_dec_ivas_fx( st->hBPF->pst_lp_ener_fx = round_fx( L_shl( Mpy_32_16_1( st->lp_error_ener, 0x6054 ), 2 + 8 ) ); /* convert from 15Q16, log2 -> 7Q8 10*log10 */ st->hBPF->pst_mem_deemp_err_fx = 0; move16(); + move16(); } #endif - st->psf_lp_noise_fx = round_fx( L_shl( st->lp_noise, 1 ) ); + st->psf_lp_noise_fx = round_fx( L_shl( st->lp_noise, 1 ) ); // Q(23+1-16)->Q8 move16(); /* reset old HB synthesis buffer */ @@ -141,7 +142,7 @@ ivas_error core_switching_pre_dec_ivas_fx( set16_fx( st->hb_prev_synth_buffer_fx, 0, NS2SA( 48000, DELAY_BWE_TOTAL_NS ) ); test(); - IF( st->hBWE_TD != NULL && NE_16( st->last_core, ACELP_CORE ) ) + IF( st->hBWE_TD != NULL && ( st->last_core != ACELP_CORE ) ) { #ifdef MSAN_FIX st->hBWE_TD->prev_hb_synth_fx_exp = 31; @@ -183,8 +184,8 @@ ivas_error core_switching_pre_dec_ivas_fx( set16_fx( st->hHQ_core->last_env_fx, 0, BANDS_MAX ); st->hHQ_core->last_max_pos_pulse = 0; - move16(); + IF( GT_32( st->output_Fs, 16000 ) ) { set32_fx( st->hHQ_core->prev_coeff_out_fx, 0, L_HQ_WB_BWE ); @@ -196,7 +197,7 @@ ivas_error core_switching_pre_dec_ivas_fx( } /* reset the GSC pre echo energy threshold in case of switching */ - IF( st->hGSCDec != NULL ) + if ( st->hGSCDec != NULL ) { st->hGSCDec->Last_frame_ener_fx = MAX_32; move32(); @@ -205,7 +206,7 @@ ivas_error core_switching_pre_dec_ivas_fx( test(); IF( EQ_16( st->last_core, TCX_20_CORE ) || EQ_16( st->last_core, TCX_10_CORE ) ) { - IF( EQ_16( st->element_mode, EVS_MONO ) ) + IF( st->element_mode == EVS_MONO ) { st->last_core = HQ_CORE; move16(); @@ -229,7 +230,7 @@ ivas_error core_switching_pre_dec_ivas_fx( } } - IF( NE_16( st->prev_bfi, 0 ) ) + IF( st->prev_bfi != 0 ) { Word16 delay_comp; @@ -243,11 +244,10 @@ ivas_error core_switching_pre_dec_ivas_fx( } delay_comp = NS2SA( st->output_Fs, DELAY_CLDFB_NS ); - /*TODO To be tested:control not entering the block*/ test(); test(); - IF( !st->last_con_tcx && EQ_16( st->last_core_bfi, ACELP_CORE ) && EQ_16( st->core, HQ_CORE ) ) + IF( !st->last_con_tcx && ( st->last_core_bfi == ACELP_CORE ) && EQ_16( st->core, HQ_CORE ) ) { /*TODO None of the test dtreams are entering this block,hence enabled assert(0)*/ assert( 0 ); @@ -265,12 +265,10 @@ ivas_error core_switching_pre_dec_ivas_fx( set32_fx( imagBufferTmp_fx[i], 0, CLDFB_NO_CHANNELS_MAX ); realBuffer_fx[i] = realBufferTmp_fx[i]; imagBuffer_fx[i] = imagBufferTmp_fx[i]; - move32(); - move32(); } /* CLDFB analysis of the synthesis at internal sampling rate */ - IF( ( error = cldfb_save_memory_ivas_fx( st->cldfbAna ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = cldfb_save_memory_ivas_fx( st->cldfbAna ) ), IVAS_ERR_OK ) ) { return error; } @@ -279,7 +277,7 @@ ivas_error core_switching_pre_dec_ivas_fx( cldfb_restore_memory_ivas_fx( st->cldfbAna ); /*Assuming Q10*/ /* CLDFB synthesis of the combined signal */ - IF( ( error = cldfb_save_memory_ivas_fx( st->cldfbSyn ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = cldfb_save_memory_ivas_fx( st->cldfbSyn ) ), IVAS_ERR_OK ) ) { return error; } @@ -292,11 +290,11 @@ ivas_error core_switching_pre_dec_ivas_fx( test(); test(); - IF( !st->last_con_tcx && EQ_16( st->last_core_bfi, ACELP_CORE ) && EQ_16( st->core, HQ_CORE ) ) + IF( !st->last_con_tcx && ( st->last_core_bfi == ACELP_CORE ) && EQ_16( st->core, HQ_CORE ) ) { - lerp( st->hTcxDec->syn_Overl, st->hHQ_core->fer_samples_fx + delay_comp, output_frame / 2, st->last_L_frame / 2 ); + lerp( st->hTcxDec->syn_Overl, st->hHQ_core->fer_samples_fx + delay_comp, shr( output_frame, 1 ), shr( st->last_L_frame, 1 ) ); /*Set to zero the remaining part*/ - set16_fx( st->hHQ_core->fer_samples_fx + delay_comp + output_frame / 2, 0, ( output_frame / 2 ) - delay_comp ); + set16_fx( st->hHQ_core->fer_samples_fx + delay_comp + output_frame / 2, 0, sub( shr( output_frame, 1 ), delay_comp ) ); } } @@ -318,14 +316,14 @@ ivas_error core_switching_pre_dec_ivas_fx( { oldLenClasBuff = mult_r( L_SYN_MEM_CLAS_ESTIM, div_s( st->last_L_frame, st->L_frame ) ); newLenClasBuff = L_SYN_MEM_CLAS_ESTIM; + move16(); } ELSE { oldLenClasBuff = L_SYN_MEM_CLAS_ESTIM; + move16(); newLenClasBuff = mult_r( L_SYN_MEM_CLAS_ESTIM, div_s( st->L_frame, st->last_L_frame ) ); } - move16(); - move16(); lerp( &st->mem_syn_clas_estim_fx[L_SYN_MEM_CLAS_ESTIM - oldLenClasBuff], &st->mem_syn_clas_estim_fx[L_SYN_MEM_CLAS_ESTIM - newLenClasBuff], newLenClasBuff, oldLenClasBuff ); } } @@ -339,7 +337,7 @@ ivas_error core_switching_pre_dec_ivas_fx( within ACELP_CORE if switching from another bitarate to vbr, last_ppp and last_nelp is always updated in the previous frame */ test(); test(); - IF( EQ_16( st->core, ACELP_CORE ) && ( NE_16( st->last_core, ACELP_CORE ) || EQ_16( st->last_codec_mode, MODE2 ) ) ) + IF( ( st->core == ACELP_CORE ) && ( ( st->last_core != ACELP_CORE ) || EQ_16( st->last_codec_mode, MODE2 ) ) ) { st->last_ppp_mode_dec = 0; st->last_nelp_mode_dec = 0; @@ -351,7 +349,7 @@ ivas_error core_switching_pre_dec_ivas_fx( test(); test(); test(); - IF( EQ_16( st->core, ACELP_CORE ) && ( NE_16( st->last_core, ACELP_CORE ) || EQ_16( st->last_codec_mode, MODE2 ) || LE_32( st->last_total_brate, PPP_NELP_2k80 ) ) ) + IF( ( st->core == ACELP_CORE ) && ( ( st->last_core != ACELP_CORE ) || EQ_16( st->last_codec_mode, MODE2 ) || LE_32( st->last_total_brate, PPP_NELP_2k80 ) ) ) { st->act_count = 3; st->uv_count = 0; @@ -370,11 +368,11 @@ ivas_error core_switching_pre_dec_ivas_fx( test(); test(); test(); - IF( ( ( EQ_16( st->core, ACELP_CORE ) || EQ_16( st->core, AMR_WB_CORE ) ) && EQ_16( st->last_core, HQ_CORE ) ) || ( ( EQ_16( st->element_mode, IVAS_CPE_DFT ) || EQ_16( st->element_mode, IVAS_CPE_TD ) || ( EQ_16( st->element_mode, IVAS_CPE_MDCT ) && EQ_16( last_element_mode, IVAS_CPE_DFT ) ) ) && EQ_16( nchan_out, 2 ) && - NE_32( st->core_brate, SID_2k40 ) && NE_32( st->core_brate, FRAME_NO_DATA ) && ( EQ_32( last_core_brate_st0, FRAME_NO_DATA ) || EQ_32( last_core_brate_st0, SID_2k40 ) ) ) ) + IF( ( ( ( st->core == ACELP_CORE ) || EQ_16( st->core, AMR_WB_CORE ) ) && EQ_16( st->last_core, HQ_CORE ) ) || ( ( EQ_16( st->element_mode, IVAS_CPE_DFT ) || EQ_16( st->element_mode, IVAS_CPE_TD ) || ( EQ_16( st->element_mode, IVAS_CPE_MDCT ) && EQ_16( last_element_mode, IVAS_CPE_DFT ) ) ) && EQ_16( nchan_out, 2 ) && + NE_32( st->core_brate, SID_2k40 ) && ( st->core_brate != FRAME_NO_DATA ) && ( ( last_core_brate_st0 == FRAME_NO_DATA ) || EQ_32( last_core_brate_st0, SID_2k40 ) ) ) ) { test(); - IF( EQ_16( st->element_mode, IVAS_CPE_DFT ) || EQ_16( st->element_mode, IVAS_CPE_TD ) ) + if ( EQ_16( st->element_mode, IVAS_CPE_DFT ) || EQ_16( st->element_mode, IVAS_CPE_TD ) ) { st->hPFstat->reset = 1; move16(); @@ -403,7 +401,7 @@ ivas_error core_switching_pre_dec_ivas_fx( test(); test(); test(); - IF( ( EQ_16( st->element_mode, IVAS_CPE_DFT ) || EQ_16( st->element_mode, IVAS_CPE_TD ) ) && EQ_16( nchan_out, 2 ) && GT_32( st->core_brate, SID_2k40 ) && ( EQ_32( last_core_brate_st0, FRAME_NO_DATA ) || EQ_32( last_core_brate_st0, SID_2k40 ) ) && st->hTcxDec != NULL ) + IF( ( EQ_16( st->element_mode, IVAS_CPE_DFT ) || EQ_16( st->element_mode, IVAS_CPE_TD ) ) && EQ_16( nchan_out, 2 ) && GT_32( st->core_brate, SID_2k40 ) && ( ( last_core_brate_st0 == FRAME_NO_DATA ) || EQ_32( last_core_brate_st0, SID_2k40 ) ) && st->hTcxDec != NULL ) { /* Last frame was Stereo CNG and the synthesis memory is outdated -- reset */ set16_fx( st->hTcxDec->old_syn_Overl, 0, L_FRAME32k / 2 ); @@ -417,7 +415,7 @@ ivas_error core_switching_pre_dec_ivas_fx( set16_fx( st->mem_syn2_fx, 0, M ); } set16_fx( st->mem_syn1_fx, 0, M ); - IF( st->hBWE_TD != NULL ) + if ( st->hBWE_TD != NULL ) { st->hBWE_TD->bwe_non_lin_prev_scale_fx = 0; move32(); @@ -452,7 +450,9 @@ ivas_error core_switching_pre_dec_ivas_fx( st->lp_gainp_fx = 0; move16(); st->lp_gainc_fx = extract_h( Sqrt32( st->lp_ener_fx, &exp ) ); /*Q=15-exp*/ - st->lp_gainc_fx = shr( st->lp_gainc_fx, 12 - exp ); /*Q3*/ + move16(); + st->lp_gainc_fx = shr( st->lp_gainc_fx, sub( 12, exp ) ); /*Q3*/ + move16(); st->last_voice_factor_fx = 0; st->Last_GSC_noisy_speech_flag = 0; @@ -467,7 +467,7 @@ ivas_error core_switching_pre_dec_ivas_fx( /* reset TBE memories */ test(); test(); - IF( !st->last_con_tcx && !( ( EQ_16( st->last_core, HQ_CORE ) ) && GT_16( st->element_mode, EVS_MONO ) ) ) + IF( !st->last_con_tcx && !( ( EQ_16( st->last_core, HQ_CORE ) ) && ( st->element_mode > EVS_MONO ) ) ) { set16_fx( st->old_exc_fx, 0, L_EXC_MEM_DEC ); } @@ -500,7 +500,7 @@ ivas_error core_switching_pre_dec_ivas_fx( test(); test(); test(); - IF( ( EQ_16( st->core, ACELP_CORE ) || EQ_16( st->core, AMR_WB_CORE ) ) && ( EQ_16( st->last_core, TCX_20_CORE ) || EQ_16( st->last_core, TCX_10_CORE ) ) ) + IF( ( ( st->core == ACELP_CORE ) || EQ_16( st->core, AMR_WB_CORE ) ) && ( EQ_16( st->last_core, TCX_20_CORE ) || EQ_16( st->last_core, TCX_10_CORE ) ) ) { IF( st->hBWE_TD != NULL ) { @@ -525,7 +525,9 @@ ivas_error core_switching_pre_dec_ivas_fx( st->lp_gainp_fx = 0; move16(); st->lp_gainc_fx = extract_h( Sqrt32( st->lp_ener_fx, &exp ) ); /*Q=15-exp*/ - st->lp_gainc_fx = shr( st->lp_gainc_fx, 12 - exp ); /*Q3*/ + move16(); + st->lp_gainc_fx = shr( st->lp_gainc_fx, sub( 12, exp ) ); /*Q3*/ + move16(); st->last_voice_factor_fx = 0; st->Last_GSC_noisy_speech_flag = 0; @@ -559,7 +561,7 @@ ivas_error core_switching_pre_dec_ivas_fx( { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for old_synth_lenFB (32 bit) \n" ) ); } - Copy_Scale_sig_16_32( st->hTcxDec->old_synthFB_fx, old_synthFB_fx, st->hTcxDec->old_synth_lenFB, sub( Q10, Q_old_synthFB ) ); + Copy_Scale_sig_16_32( st->hTcxDec->old_synthFB_fx, old_synthFB_fx, st->hTcxDec->old_synth_lenFB, sub( Q10, Q_old_synthFB ) ); // Q10 Copy32( old_synthFB_fx + st->hTcxDec->old_synth_lenFB - offset, st->cldfbAna->cldfb_state_fx, offset ); st->cldfbAna->Q_cldfb_state = Q10; move16(); @@ -572,7 +574,7 @@ ivas_error core_switching_pre_dec_ivas_fx( test(); test(); test(); - IF( EQ_16( st->core, HQ_CORE ) && ( EQ_16( st->last_core, ACELP_CORE ) || EQ_16( st->last_core, AMR_WB_CORE ) || ( ( NE_16( st->element_mode, EVS_MONO ) ) && ( NE_16( st->last_core, HQ_CORE ) ) ) ) ) + IF( EQ_16( st->core, HQ_CORE ) && ( ( st->last_core == ACELP_CORE ) || EQ_16( st->last_core, AMR_WB_CORE ) || ( ( ( st->element_mode != EVS_MONO ) ) && ( NE_16( st->last_core, HQ_CORE ) ) ) ) ) { set32_fx( st->hHQ_core->prev_env_fx, 0, SFM_N_WB ); set32_fx( st->hHQ_core->prev_normq_fx, 0, SFM_N_WB ); @@ -592,13 +594,14 @@ ivas_error core_switching_pre_dec_ivas_fx( set32_fx( st->hHQ_core->prev_coeff_out_fx, 0, L_HQ_WB_BWE ); } - IF( NE_16( st->element_mode, EVS_MONO ) ) + IF( st->element_mode != EVS_MONO ) { /* Estimate mem_env_delta to reinit env_stab */ tmp_fx = L_max( 0, L_add( ENV_STAB_EST1_FX, L_add( Mult_32_16( st->stab_fac_smooth_lt_fx, ENV_STAB_EST2_FX ), Mult_32_16( st->log_energy_diff_lt_fx, ENV_STAB_EST3_FX ) ) ) ); /*Q12*/ st->hHQ_core->mem_env_delta = extract_l( L_min( MAX16B, tmp_fx ) ); /* Convert to Q12 and handle saturation */ - + move16(); + test(); IF( NE_16( st->last_core, TCX_20_CORE ) && NE_16( st->last_core, TCX_10_CORE ) ) { set16_fx( st->hHQ_core->old_out_fx, 0, output_frame ); @@ -631,14 +634,15 @@ ivas_error core_switching_pre_dec_ivas_fx( /* handle switching cases where preecho_sb was not called in the last frame (memory not up to date) */ IF( st->hHQ_core != NULL ) { - st->hHQ_core->pastpre--; - IF( LE_16( st->hHQ_core->pastpre, 0 ) ) + st->hHQ_core->pastpre = sub( st->hHQ_core->pastpre, 1 ); + move16(); + IF( st->hHQ_core->pastpre < 0 ) { reset_preecho_dec_fx( st->hHQ_core ); } } - - IF( EQ_32( st->core_brate, FRAME_NO_DATA ) ) + test(); + IF( st->core_brate == FRAME_NO_DATA ) { st->VAD = 0; st->m_frame_type = ZERO_FRAME; @@ -657,7 +661,7 @@ ivas_error core_switching_pre_dec_ivas_fx( move16(); move16(); /*switch on CNA on active frames*/ - IF( EQ_16( st->element_mode, EVS_MONO ) ) /* for IVAS modes, st->flag_cna is set earlier */ + IF( ( st->element_mode == EVS_MONO ) ) /* for IVAS modes, st->flag_cna is set earlier */ { test(); test(); @@ -677,7 +681,7 @@ ivas_error core_switching_pre_dec_ivas_fx( } } - IF( EQ_16( st->core, AMR_WB_CORE ) ) + if ( EQ_16( st->core, AMR_WB_CORE ) ) { st->cng_type = LP_CNG; move16(); @@ -688,18 +692,26 @@ ivas_error core_switching_pre_dec_ivas_fx( test(); test(); test(); - IF( st->hFdCngDec && ( NE_16( st->last_L_frame, st->L_frame ) || NE_16( st->hFdCngDec->hFdCngCom->frameSize, st->L_frame ) || EQ_16( st->ini_frame, 0 ) || NE_16( st->bwidth, st->last_bwidth ) ) ) + IF( st->hFdCngDec && ( NE_16( st->last_L_frame, st->L_frame ) || NE_16( st->hFdCngDec->hFdCngCom->frameSize, st->L_frame ) || ( st->ini_frame == 0 ) || NE_16( st->bwidth, st->last_bwidth ) ) ) { /* || st->last_core == AMR_WB_CORE || st->last_codec_mode == MODE2)){*/ IF( NE_16( st->core, AMR_WB_CORE ) ) { - configureFdCngDec_ivas_fx( st->hFdCngDec, st->bwidth, st->rf_flag == 1 && st->total_brate == ACELP_13k20 ? ACELP_9k60 : st->total_brate, st->L_frame, st->last_L_frame, st->element_mode ); + test(); + IF( EQ_16( st->rf_flag, 1 ) && EQ_32( st->total_brate, ACELP_13k20 ) ) + { + configureFdCngDec_ivas_fx( st->hFdCngDec, st->bwidth, ACELP_9k60, st->L_frame, st->last_L_frame, st->element_mode ); + } + ELSE + { + configureFdCngDec_ivas_fx( st->hFdCngDec, st->bwidth, st->total_brate, st->L_frame, st->last_L_frame, st->element_mode ); + } } ELSE { configureFdCngDec_ivas_fx( st->hFdCngDec, WB, ACELP_8k00, st->L_frame, st->last_L_frame, st->element_mode ); - IF( st->VAD ) + if ( st->VAD ) { st->hFdCngDec->hFdCngCom->CngBitrate = st->total_brate; move32(); @@ -724,7 +736,7 @@ ivas_error core_switching_pre_dec_ivas_fx( IF( EQ_16( st->L_frame, L_FRAME ) ) { - FOR( i = 0; i < shl( st->L_frame, 1 ); i++ ) + FOR( i = 0; i < ( st->L_frame * 2 ); i++ ) { st->hFdCngDec->hFdCngCom->olapBufferSynth_fx[i] = Mult_32_16( st->hFdCngDec->hFdCngCom->olapBufferSynth_fx[i], (Word16) 20480 /* 0.6250f in Q15 */ ); move32(); @@ -732,7 +744,7 @@ ivas_error core_switching_pre_dec_ivas_fx( } ELSE { - FOR( i = 0; i < shl( st->L_frame, 1 ); i++ ) + FOR( i = 0; i < ( st->L_frame * 2 ); i++ ) { st->hFdCngDec->hFdCngCom->olapBufferSynth_fx[i] = Mult_32_16( L_shl( st->hFdCngDec->hFdCngCom->olapBufferSynth_fx[i], 1 ), (Word16) 26214 /* 1.6f in Q14 */ ); move32(); @@ -1772,7 +1784,7 @@ void bandwidth_switching_detect_ivas_fx( st_fx->bws_cnt1 = 0; move16(); } - ELSE IF( GT_32( st_fx->total_brate, ACELP_9k60 ) && LT_32( st_fx->last_core_brate, ACELP_9k60 ) && EQ_16( st_fx->bwidth, SWB ) && EQ_16( st_fx->last_bwidth, WB ) && EQ_16( st_fx->last_low_rate_mode, 0 ) ) + ELSE IF( GT_32( st_fx->total_brate, ACELP_9k60 ) && LT_32( st_fx->last_core_brate, ACELP_9k60 ) && EQ_16( st_fx->bwidth, SWB ) && EQ_16( st_fx->last_bwidth, WB ) && ( st_fx->last_low_rate_mode == 0 ) ) { st_fx->bws_cnt1 = add( st_fx->bws_cnt1, 1 ); move16(); @@ -1987,8 +1999,9 @@ void ivas_bw_switching_pre_proc_fx( Flag Overflow = 0; + move32(); - IF( GT_16( st->element_mode, EVS_MONO ) ) + IF( st->element_mode > EVS_MONO ) { test(); test(); @@ -1999,33 +2012,36 @@ void ivas_bw_switching_pre_proc_fx( test(); test(); test(); - IF( EQ_16( st->core, ACELP_CORE ) && !( EQ_16( st->bfi, 1 ) && EQ_16( st->con_tcx, 1 ) ) && st->hBWE_FD != NULL && !( LE_32( st->core_brate, SID_2k40 ) && EQ_16( st->element_mode, IVAS_CPE_DFT ) && EQ_16( nchan_out, 2 ) ) && !( EQ_16( st->element_mode, IVAS_CPE_MDCT ) && EQ_16( nchan_out, 1 ) && EQ_16( st->idchan, 1 ) && LE_32( last_element_brate, IVAS_SID_5k2 ) ) ) + test(); + IF( ( st->core == ACELP_CORE ) && !( EQ_16( st->bfi, 1 ) && EQ_16( st->con_tcx, 1 ) ) && st->hBWE_FD != NULL && !( LE_32( st->core_brate, SID_2k40 ) && EQ_16( st->element_mode, IVAS_CPE_DFT ) && EQ_16( nchan_out, 2 ) ) && !( EQ_16( st->element_mode, IVAS_CPE_MDCT ) && EQ_16( nchan_out, 1 ) && EQ_16( st->idchan, 1 ) && LE_32( last_element_brate, IVAS_SID_5k2 ) ) ) { /* Calculate tilt of the ACELP core synthesis - needed in SWB BWE decoding */ Word16 old_syn_12k8_16k_tmp_16fx[L_FRAME16k]; Copy_Scale_sig_32_16( old_syn_12k8_16k_fx, old_syn_12k8_16k_tmp_16fx, st->L_frame, sub( -1, Q ) ); - st->tilt_wb_fx = round_fx_sat( L_shl_sat( calc_tilt_bwe_fx( old_syn_12k8_16k_tmp_16fx, -1, st->L_frame ), sub( Q, 8 ) ) ); + st->tilt_wb_fx = round_fx_sat( L_shl_sat( calc_tilt_bwe_fx( old_syn_12k8_16k_tmp_16fx, -1, st->L_frame ), sub( Q, 8 ) ) ); // Q24+(Q-8) - 16 + move16(); } return; } + test(); test(); - test(); - IF( EQ_16( st->core, ACELP_CORE ) && !( EQ_16( st->bfi, 1 ) && EQ_16( st->con_tcx, 1 ) ) ) + IF( ( st->core == ACELP_CORE ) && !( EQ_16( st->bfi, 1 ) && EQ_16( st->con_tcx, 1 ) ) ) { /*----------------------------------------------------------------------* * Calculate tilt of the ACELP core synthesis *----------------------------------------------------------------------*/ st->tilt_wb_fx = ivas_calc_tilt_bwe_fx( old_syn_12k8_16k_fx, Q, st->L_frame ); - + move16(); /*-------------------------------------------------------------------------------* * Calculate frequency energy of 0~3.2kHz and 3.2~6.4kHz the ACELP core synthesis *-------------------------------------------------------------------------------*/ edct_fx( old_syn_12k8_16k_fx, syn_dct_fx, L_FRAME, &Q ); Word64 W_tmp = 0; + move64(); Word32 tmp; Word16 shift; FOR( i = 0; i < L_FRAME / 2; i++ ) @@ -2039,8 +2055,9 @@ void ivas_bw_switching_pre_proc_fx( tmp = getSqrtWord32( tmp ); st->enerLL_fx = tmp; + move32(); st->enerLL_fx_Q = shr( sub( add( Q, shift ), 32 ), 1 ); - + move16(); W_tmp = 0; move64(); FOR( ; i < L_FRAME; i++ ) @@ -2055,6 +2072,7 @@ void ivas_bw_switching_pre_proc_fx( st->enerLH_fx = tmp; move32(); st->enerLH_fx_Q = shr( sub( add( Q, shift ), 32 ), 1 ); + move16(); } ELSE { @@ -2090,7 +2108,6 @@ void ivas_bw_switching_pre_proc_fx( ELSE { Word32 tmp, L_tmp = 0; - L_tmp = 0; move32(); FOR( i = 0; i < L_FRAME / 2; i++ ) { @@ -2135,9 +2152,9 @@ void ivas_bw_switching_pre_proc_fx( set16_fx( st->prev_SWB_fenv_fx, 0, SWB_FENV ); } } - ELSE IF( ( ( EQ_16( st->core, ACELP_CORE ) && ( EQ_16( st->last_core, HQ_CORE ) || EQ_16( st->last_core, TCX_10_CORE ) || EQ_16( st->last_core, TCX_20_CORE ) ) ) || ( EQ_16( st->core, st->last_core ) && NE_16( st->extl, st->last_extl ) ) ) && GE_16( st->last_bwidth, SWB ) ) + ELSE IF( ( ( ( st->core == ACELP_CORE ) && ( EQ_16( st->last_core, HQ_CORE ) || EQ_16( st->last_core, TCX_10_CORE ) || EQ_16( st->last_core, TCX_20_CORE ) ) ) || ( EQ_16( st->core, st->last_core ) && NE_16( st->extl, st->last_extl ) ) ) && GE_16( st->last_bwidth, SWB ) ) { - st->attenu_fx = 3277; + st->attenu_fx = 3277; // 0.1f in Q15 move16(); } @@ -2146,7 +2163,7 @@ void ivas_bw_switching_pre_proc_fx( test(); test(); test(); - IF( EQ_16( st->last_core, HQ_CORE ) || ( EQ_16( st->last_core, ACELP_CORE ) && !( EQ_16( st->last_extl, WB_TBE ) || EQ_16( st->last_extl, SWB_TBE ) || EQ_16( st->last_extl, FB_TBE ) ) && GT_32( st->core_brate, ACELP_8k00 ) ) ) + if ( EQ_16( st->last_core, HQ_CORE ) || ( ( st->last_core == ACELP_CORE ) && !( EQ_16( st->last_extl, WB_TBE ) || EQ_16( st->last_extl, SWB_TBE ) || EQ_16( st->last_extl, FB_TBE ) ) && GT_32( st->core_brate, ACELP_8k00 ) ) ) { st->prev_fractive = 0; move16(); diff --git a/lib_dec/ivas_stereo_dft_dec_fx.c b/lib_dec/ivas_stereo_dft_dec_fx.c index 40c8baf96..1c5a15e28 100644 --- a/lib_dec/ivas_stereo_dft_dec_fx.c +++ b/lib_dec/ivas_stereo_dft_dec_fx.c @@ -285,79 +285,79 @@ void stereo_dft_dec_reset_fx( *-------------------------------------------------------------------------*/ static void stereo_dft_dec_open_fx( - STEREO_DFT_DEC_DATA_HANDLE hStereoDft, /* i/o: decoder DFT stereo handle */ - const Word32 output_Fs, /* i : output sampling rate */ - const Word16 nchan_transport /* i : number of transport channels */ + STEREO_DFT_DEC_DATA_HANDLE hStereoDft, /* i/o: decoder DFT stereo handle */ + const Word32 output_Fs, /* i : output sampling rate Q0*/ + const Word16 nchan_transport /* i : number of transport channels Q0*/ ) { /*Sizes*/ // hStereoDft->N = (Word16) ( STEREO_DFT_HOP_MAX * output_Fs / 48000 ); - hStereoDft->N = extract_l( Mpy_32_32( imult3216( output_Fs, STEREO_DFT_HOP_MAX ), 44740 ) ); + hStereoDft->N = extract_l( Mpy_32_32( imult3216( output_Fs, STEREO_DFT_HOP_MAX ), 44740 /* 1/48000 in Q31 */ ) ); /* Q0 */ move16(); /*Init. DFT sizes*/ - hStereoDft->NFFT = extract_l( Mpy_32_32( imult3216( output_Fs, STEREO_DFT32MS_N_MAX ), 44740 ) ); + hStereoDft->NFFT = extract_l( Mpy_32_32( imult3216( output_Fs, STEREO_DFT32MS_N_MAX ), 44740 /* 1/48000 in Q31 */ ) ); /* Q0 */ move16(); - hStereoDft->dft_trigo_8k_fx = dft_trigo_32k_fx; - hStereoDft->dft_trigo_12k8_fx = dft_trigo_12k8_fx; - hStereoDft->dft_trigo_16k_fx = dft_trigo_32k_fx; + hStereoDft->dft_trigo_8k_fx = dft_trigo_32k_fx; /* Q15 */ + hStereoDft->dft_trigo_12k8_fx = dft_trigo_12k8_fx; /* Q15 */ + hStereoDft->dft_trigo_16k_fx = dft_trigo_32k_fx; /* Q15 */ - hStereoDft->dft32ms_ovl = extract_l( Mpy_32_32( imult3216( output_Fs, STEREO_DFT32MS_OVL_MAX ), 44740 ) ); - hStereoDft->win232ms_8k_fx = dft_win232ms_8k_fx; - hStereoDft->win232ms_12k8_fx = dft_win232ms_12k8_fx; - hStereoDft->win232ms_16k_fx = dft_win232ms_16k_fx; + hStereoDft->dft32ms_ovl = extract_l( Mpy_32_32( imult3216( output_Fs, STEREO_DFT32MS_OVL_MAX ), 44740 /* 1/48000 in Q31 */ ) ); /* Q0 */ + hStereoDft->win232ms_8k_fx = dft_win232ms_8k_fx; /* Q15 */ + hStereoDft->win232ms_12k8_fx = dft_win232ms_12k8_fx; /* Q15 */ + hStereoDft->win232ms_16k_fx = dft_win232ms_16k_fx; /* Q15 */ - hStereoDft->dft32ms_ovl2 = extract_l( Mpy_32_32( imult3216( output_Fs, STEREO_DFT32MS_OVL2_MAX ), 44740 ) ); - hStereoDft->win32ms_8k_fx = dft_win232ms_8k_fx + 1; - hStereoDft->win32ms_12k8_fx = dft_win232ms_12k8_fx + 1; - hStereoDft->win32ms_16k_fx = dft_win232ms_16k_fx + 1; + hStereoDft->dft32ms_ovl2 = extract_l( Mpy_32_32( imult3216( output_Fs, STEREO_DFT32MS_OVL2_MAX ), 44740 /* 1/48000 in Q31 */ ) ); /* Q0 */ + hStereoDft->win32ms_8k_fx = dft_win232ms_8k_fx + 1; /* Q15 */ + hStereoDft->win32ms_12k8_fx = dft_win232ms_12k8_fx + 1; /* Q15 */ + hStereoDft->win32ms_16k_fx = dft_win232ms_16k_fx + 1; /* Q15 */ IF( EQ_32( output_Fs, 16000 ) ) { - hStereoDft->dft_trigo_fx = dft_trigo_32k_fx; - hStereoDft->dft_trigo_step = STEREO_DFT_TRIGO_SRATE_16k_STEP; + hStereoDft->dft_trigo_fx = dft_trigo_32k_fx; /* Q15 */ + hStereoDft->dft_trigo_step = STEREO_DFT_TRIGO_SRATE_16k_STEP; /* Q0 */ move16(); - hStereoDft->win232ms_fx = dft_win232ms_16k_fx; - hStereoDft->win32ms_fx = dft_win232ms_16k_fx + 1; + hStereoDft->win232ms_fx = dft_win232ms_16k_fx; /* Q15 */ + hStereoDft->win32ms_fx = dft_win232ms_16k_fx + 1; /* Q15 */ } ELSE IF( EQ_32( output_Fs, 32000 ) ) { - hStereoDft->dft_trigo_fx = dft_trigo_32k_fx; - hStereoDft->dft_trigo_step = STEREO_DFT_TRIGO_SRATE_32k_STEP; + hStereoDft->dft_trigo_fx = dft_trigo_32k_fx; /* Q15 */ + hStereoDft->dft_trigo_step = STEREO_DFT_TRIGO_SRATE_32k_STEP; /* Q0 */ move16(); - hStereoDft->win232ms_fx = dft_win232ms_32k_fx; - hStereoDft->win32ms_fx = dft_win232ms_32k_fx + 1; + hStereoDft->win232ms_fx = dft_win232ms_32k_fx; /* Q15 */ + hStereoDft->win32ms_fx = dft_win232ms_32k_fx + 1; /* Q15 */ } ELSE { assert( output_Fs == 48000 ); - hStereoDft->dft_trigo_fx = dft_trigo_48k_fx; - hStereoDft->dft_trigo_step = STEREO_DFT_TRIGO_SRATE_48k_STEP; + hStereoDft->dft_trigo_fx = dft_trigo_48k_fx; /* Q15 */ + hStereoDft->dft_trigo_step = STEREO_DFT_TRIGO_SRATE_48k_STEP; /* Q0 */ move16(); - hStereoDft->win232ms_fx = dft_win232ms_48k_fx; - hStereoDft->win32ms_fx = dft_win232ms_48k_fx + 1; + hStereoDft->win232ms_fx = dft_win232ms_48k_fx; /* Q15 */ + hStereoDft->win32ms_fx = dft_win232ms_48k_fx + 1; /* Q15 */ } - hStereoDft->win_8k_fx = dft_win_8k_fx; + hStereoDft->win_8k_fx = dft_win_8k_fx; /* Q15 */ /*Bands: find the number of bands, Nyquist freq. is not taken into account*/ set16_fx( hStereoDft->band_res, hStereoDft->hConfig->band_res, STEREO_DFT_DEC_DFT_NB ); - hStereoDft->nbands = stereo_dft_band_config_fx( hStereoDft->band_limits, hStereoDft->band_res[0], hStereoDft->NFFT, DEC ); + hStereoDft->nbands = stereo_dft_band_config_fx( hStereoDft->band_limits, hStereoDft->band_res[0], hStereoDft->NFFT, DEC ); /* Q0 */ move16(); - hStereoDft->hb_stefi_delay = NS2SA_FX2( output_Fs, STEREO_DFT_TD_STEFI_DELAY_NS ); + hStereoDft->hb_stefi_delay = NS2SA_FX2( output_Fs, STEREO_DFT_TD_STEFI_DELAY_NS ); /* Q0 */ move16(); IF( GT_16( nchan_transport, 2 ) ) { - hStereoDft->min_smooth_gains_fx = min_smooth_gains2_fx; - hStereoDft->max_smooth_gains_fx = max_smooth_gains2_fx; + hStereoDft->min_smooth_gains_fx = min_smooth_gains2_fx; /* Q15 */ + hStereoDft->max_smooth_gains_fx = max_smooth_gains2_fx; /* Q15 */ } ELSE { - hStereoDft->min_smooth_gains_fx = min_smooth_gains1_fx; - hStereoDft->max_smooth_gains_fx = max_smooth_gains1_fx; + hStereoDft->min_smooth_gains_fx = min_smooth_gains1_fx; /* Q15 */ + hStereoDft->max_smooth_gains_fx = max_smooth_gains1_fx; /* Q15 */ } hStereoDft->q_hb_stefi_sig_fx = Q31; move16(); @@ -378,11 +378,11 @@ static void stereo_dft_dec_open_fx( *------------------------------------------------------------------------*/ ivas_error stereo_dft_dec_create_fx( - STEREO_DFT_DEC_DATA_HANDLE *hStereoDft, /* i/o: decoder DFT stereo handle */ - const Word32 element_brate, /* i : element bitrate */ - const Word32 output_Fs, /* i : output sampling rate */ - const Word16 sba_dirac_stereo_flag, /* i : signal stereo output for SBA DirAC */ - const Word16 nchan_transport /* i : number of transport channels */ + STEREO_DFT_DEC_DATA_HANDLE *hStereoDft, /* i/o: decoder DFT stereo handle */ + const Word32 element_brate, /* i : element bitrate Q0*/ + const Word32 output_Fs, /* i : output sampling rate Q0*/ + const Word16 sba_dirac_stereo_flag, /* i : signal stereo output for SBA DirAC Q0*/ + const Word16 nchan_transport /* i : number of transport channels Q0*/ ) { STEREO_DFT_DEC_DATA_HANDLE hStereoDft_loc; @@ -443,11 +443,12 @@ ivas_error stereo_dft_dec_create_fx( *-------------------------------------------------------------------------*/ static void stereo_dft_dequantize_res_gains_fx( - Word16 *ind1, - Word16 *ind2, - Word32 *gout, - Word32 *rout, - const Word16 N ) + Word16 *ind1, /* Q0 */ + Word16 *ind2, /* Q0 */ + Word32 *gout, /* Q31 */ + Word32 *rout, /* Q31 */ + const Word16 N /* Q0 */ +) { Word16 i, index; Word16 tmp; @@ -455,9 +456,9 @@ static void stereo_dft_dequantize_res_gains_fx( FOR( i = 0; i < N; i++ ) { /* Ensure the indices are within range -- may go out of range due to frame loss */ - ind1[i] = check_bounds_s( ind1[i], 0, 30 ); + ind1[i] = check_bounds_s( ind1[i], 0, 30 ); /* Q0 */ move16(); - ind2[i] = check_bounds_s( ind2[i], 0, 7 ); + ind2[i] = check_bounds_s( ind2[i], 0, 7 ); /* Q0 */ move16(); IF( LE_16( ind1[i], 15 ) ) { @@ -472,15 +473,15 @@ static void stereo_dft_dequantize_res_gains_fx( // gout[i] = LE_16( ind1[i], 15 ) ? L_negate( dft_res_gains_q_fx[index][0] ) : dft_res_gains_q_fx[index][0]; IF( LE_16( ind1[i], 15 ) ) { - gout[i] = L_negate( dft_res_gains_q_fx[index][0] ); + gout[i] = L_negate( dft_res_gains_q_fx[index][0] ); /* Q31 */ move16(); } ELSE { - gout[i] = dft_res_gains_q_fx[index][0]; + gout[i] = dft_res_gains_q_fx[index][0]; /* Q31 */ move16(); } - rout[i] = dft_res_gains_q_fx[index][1]; + rout[i] = dft_res_gains_q_fx[index][1]; /* Q31 */ move16(); } @@ -494,11 +495,12 @@ static void stereo_dft_dequantize_res_gains_fx( *---------------------------------------------------------------------------*/ static void stereo_dft_dequantize_res_gains_f_fx( - Word32 *ind1, - Word32 *ind2, - Word32 *gout, - Word32 *rout, - const Word16 N ) + Word32 *ind1, /* Q26 */ + Word32 *ind2, /* Q26 */ + Word32 *gout, /* Q31 */ + Word32 *rout, /* Q31 */ + const Word16 N /* Q0 */ +) { Word16 i, i1, j1, sign, ji, ij; Word32 L_tmp; @@ -507,9 +509,9 @@ static void stereo_dft_dequantize_res_gains_f_fx( FOR( i = 0; i < N; i++ ) { /* Ensure the indices are within range -- may go out of range due to frame loss */ - ind1[i] = check_bounds_l( ind1[i], 0, 31 << Q26 ); + ind1[i] = check_bounds_l( ind1[i], 0, 31 << Q26 ); /* Q26 */ move32(); - ind2[i] = check_bounds_l( ind2[i], 0, 7 << Q26 ); + ind2[i] = check_bounds_l( ind2[i], 0, 7 << Q26 ); /* Q26 */ move32(); /* compensate for the offset and extract/remove sign of first index */ @@ -526,49 +528,49 @@ static void stereo_dft_dequantize_res_gains_f_fx( } IF( LT_32( ind1[i], L_shl( 15, Q26 ) ) ) { - L_tmp = L_sub( L_shl( 15, Q26 ), ind1[i] ); + L_tmp = L_sub( L_shl( 15, Q26 ), ind1[i] ); /* Q26 */ } ELSE { - L_tmp = L_sub( ind1[i], L_shl( 15, Q26 ) ); + L_tmp = L_sub( ind1[i], L_shl( 15, Q26 ) ); /* Q26 */ } - i1 = extract_l( L_shr( ( L_tmp ), Q26 ) ); + i1 = extract_l( L_shr( ( L_tmp ), Q26 ) ); /* Q0 */ IF( LT_32( ind1[i], L_shl( 15, Q26 ) ) ) { - L_tmp = L_sub( L_shl( 15, Q26 ), ind1[i] ); + L_tmp = L_sub( L_shl( 15, Q26 ), ind1[i] ); /* Q26 */ } ELSE { - L_tmp = L_sub( ind1[i], L_shl( 15, Q26 ) ); + L_tmp = L_sub( ind1[i], L_shl( 15, Q26 ) ); /* Q26 */ } - fi = L_sub( ( L_tmp ), L_shl( i1, Q26 ) ); + fi = L_sub( ( L_tmp ), L_shl( i1, Q26 ) ); /* Q26 */ move16(); - j1 = extract_l( L_shr( ind2[i], Q26 ) ); - fj = L_sub( ind2[i], L_shl( j1, Q26 ) ); + j1 = extract_l( L_shr( ind2[i], Q26 ) ); /* Q0 */ + fj = L_sub( ind2[i], L_shl( j1, Q26 ) ); /* Q26 */ /* choose base indices for interpolation */ IF( LT_32( fj, ONE_IN_Q25 ) ) { - ji = extract_l( L_min( j1, 7 ) ); + ji = extract_l( L_min( j1, 7 ) ); /* Q0 */ } ELSE { - ji = extract_l( L_min( add( j1, 1 ), 7 ) ); + ji = extract_l( L_min( add( j1, 1 ), 7 ) ); /* Q0 */ } IF( LT_32( fi, ONE_IN_Q25 ) ) { - ij = extract_l( L_min( i1, 15 ) ); + ij = extract_l( L_min( i1, 15 ) ); /* Q0 */ } ELSE { - ij = extract_l( L_min( add( i1, 1 ), 15 ) ); + ij = extract_l( L_min( add( i1, 1 ), 15 ) ); /* Q0 */ } /* interpolate values from table */ IF( LT_16( i1, 15 ) ) { - gout[i] = Madd_32_32( Mpy_32_32( L_sub( MAX_32, L_shl( fi, Q5 ) ), dft_res_gains_q_fx[add( shl( i1, 3 ), ji )][0] ), dft_res_gains_q_fx[add( shl( add( i1, 1 ), 3 ), ji )][0], L_shl( fi, Q5 ) ); + gout[i] = Madd_32_32( Mpy_32_32( L_sub( MAX_32, L_shl( fi, Q5 ) ), dft_res_gains_q_fx[( i1 << 3 ) + ji][0] ), dft_res_gains_q_fx[( ( i1 + 1 ) << 3 ) + ji][0], L_shl( fi, Q5 ) ); /* Q31 */ move32(); IF( EQ_16( sign, -1 ) ) { @@ -578,7 +580,7 @@ static void stereo_dft_dequantize_res_gains_f_fx( } ELSE { - gout[i] = dft_res_gains_q_fx[120 + ji][0]; + gout[i] = dft_res_gains_q_fx[120 + ji][0]; /* Q31 */ move32(); IF( EQ_16( sign, -1 ) ) { @@ -589,12 +591,12 @@ static void stereo_dft_dequantize_res_gains_f_fx( IF( LT_16( j1, 7 ) ) { - rout[i] = Madd_32_32( Mpy_32_32( L_sub( MAX_32, L_shl( fj, Q5 ) ), dft_res_gains_q_fx[add( shl( ij, 3 ), j1 )][1] ), L_shl( fj, Q5 ), dft_res_gains_q_fx[add( add( shl( ij, 3 ), j1 ), 1 )][1] ); + rout[i] = Madd_32_32( Mpy_32_32( L_sub( MAX_32, L_shl( fj, Q5 ) ), dft_res_gains_q_fx[( ij << 3 ) + j1][1] ), L_shl( fj, Q5 ), dft_res_gains_q_fx[( ij << 3 ) + j1 + 1][1] ); /* Q31 */ move32(); } ELSE { - rout[i] = dft_res_gains_q_fx[add( shl( ij, 3 ), 7 )][1]; + rout[i] = dft_res_gains_q_fx[( ij << 3 ) + 7][1]; /* Q31 */ move32(); } } @@ -608,9 +610,9 @@ static void stereo_dft_dequantize_res_gains_f_fx( *-------------------------------------------------------------------------*/ void stereo_dft_dec_update_fx( - STEREO_DFT_DEC_DATA_HANDLE hStereoDft, /* i/o: decoder DFT stereo handle */ - const Word16 output_frame, /* i : output frame length */ - const Word16 sba_dirac_stereo_flag /* i : signal stereo output for SBA DirAC */ + STEREO_DFT_DEC_DATA_HANDLE hStereoDft, /* i/o: decoder DFT stereo handle */ + const Word16 output_frame, /* i : output frame length Q0*/ + const Word16 sba_dirac_stereo_flag /* i : signal stereo output for SBA DirAC Q0*/ ) { Word16 b, i, k_offset; @@ -621,30 +623,30 @@ void stereo_dft_dec_update_fx( /* Update parameters */ FOR( i = 0; i < k_offset * STEREO_DFT_BAND_MAX; i++ ) { - hStereoDft->side_gain_fx[i] = hStereoDft->side_gain_fx[STEREO_DFT_NBDIV * STEREO_DFT_BAND_MAX + i]; + hStereoDft->side_gain_fx[i] = hStereoDft->side_gain_fx[STEREO_DFT_NBDIV * STEREO_DFT_BAND_MAX + i]; /* Q31 */ move32(); - hStereoDft->res_pred_gain_fx[i] = hStereoDft->res_pred_gain_fx[STEREO_DFT_NBDIV * STEREO_DFT_BAND_MAX + i]; + hStereoDft->res_pred_gain_fx[i] = hStereoDft->res_pred_gain_fx[STEREO_DFT_NBDIV * STEREO_DFT_BAND_MAX + i]; /* Q31 */ move32(); } FOR( i = 0; i < k_offset; i++ ) { - hStereoDft->gipd_fx[i] = hStereoDft->gipd_fx[STEREO_DFT_NBDIV + i]; + hStereoDft->gipd_fx[i] = hStereoDft->gipd_fx[STEREO_DFT_NBDIV + i]; /* Q27 */ move32(); } /* Update configuration memories */ FOR( i = 0; i < k_offset; i++ ) { - hStereoDft->band_res[i] = hStereoDft->band_res[i + STEREO_DFT_NBDIV]; + hStereoDft->band_res[i] = hStereoDft->band_res[i + STEREO_DFT_NBDIV]; /* Q0 */ move16(); - hStereoDft->prm_res[i] = hStereoDft->prm_res[i + STEREO_DFT_NBDIV]; + hStereoDft->prm_res[i] = hStereoDft->prm_res[i + STEREO_DFT_NBDIV]; /* Q0 */ move16(); - hStereoDft->itd_fx[i] = hStereoDft->itd_fx[STEREO_DFT_NBDIV + i]; + hStereoDft->itd_fx[i] = hStereoDft->itd_fx[STEREO_DFT_NBDIV + i]; /* Q15 */ move32(); - hStereoDft->res_cod_mode[i] = hStereoDft->res_cod_mode[i + STEREO_DFT_NBDIV]; + hStereoDft->res_cod_mode[i] = hStereoDft->res_cod_mode[i + STEREO_DFT_NBDIV]; /* Q0 */ move16(); - hStereoDft->res_pred_mode[i] = hStereoDft->res_pred_mode[i + STEREO_DFT_NBDIV]; + hStereoDft->res_pred_mode[i] = hStereoDft->res_pred_mode[i + STEREO_DFT_NBDIV]; /* Q0 */ move16(); } @@ -668,13 +670,13 @@ void stereo_dft_dec_update_fx( FOR( i = STEREO_DFT_CORE_HIST_MAX - 1; i > 0; i-- ) { - hStereoDft->core_hist[i] = hStereoDft->core_hist[i - 1]; + hStereoDft->core_hist[i] = hStereoDft->core_hist[i - 1]; /* Q0 */ move16(); } - Copy32( hStereoDft->hb_stefi_sig_fx + output_frame, hStereoDft->hb_stefi_sig_fx, hStereoDft->hb_stefi_delay ); - Copy32( hStereoDft->hb_nrg_fx, hStereoDft->hb_nrg_fx + 1, STEREO_DFT_CORE_HIST_MAX - 1 ); - Copy32( hStereoDft->td_gain_fx, hStereoDft->td_gain_fx + 1, STEREO_DFT_CORE_HIST_MAX - 1 ); + Copy32( hStereoDft->hb_stefi_sig_fx + output_frame, hStereoDft->hb_stefi_sig_fx, hStereoDft->hb_stefi_delay ); /* Qx */ + Copy32( hStereoDft->hb_nrg_fx, hStereoDft->hb_nrg_fx + 1, STEREO_DFT_CORE_HIST_MAX - 1 ); /* Qx */ + Copy32( hStereoDft->td_gain_fx, hStereoDft->td_gain_fx + 1, STEREO_DFT_CORE_HIST_MAX - 1 ); /* q_td_gain */ #ifdef FIX_826_PRECISION_LOST_AND_COMPL Copy( hStereoDft->q_td_gain, hStereoDft->q_td_gain + 1, STEREO_DFT_CORE_HIST_MAX - 1 ); #else @@ -688,7 +690,7 @@ void stereo_dft_dec_update_fx( { FOR( i = SBA_DIRAC_NRG_SMOOTH_LONG; i > 1; i-- ) { - hStereoDft->smooth_buf_fx[b][i] = hStereoDft->smooth_buf_fx[b][i - 2]; + hStereoDft->smooth_buf_fx[b][i] = hStereoDft->smooth_buf_fx[b][i - 2]; /* q_smooth_buf_fx */ move32(); } } @@ -704,11 +706,11 @@ void stereo_dft_dec_update_fx( *-------------------------------------------------------------------------*/ void stereo_dft_dec_synthesize_fx( - CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ - Word32 DFT[CPE_CHANNELS][STEREO_DFT_BUF_MAX], /* i : DFT buffers */ - const Word16 chan, /* i : channel number */ - Word32 output[L_FRAME48k], /* o : output synthesis signal */ - const Word16 output_frame /* i : output frame length */ + CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ + Word32 DFT[CPE_CHANNELS][STEREO_DFT_BUF_MAX], /* i : DFT buffers qDFT*/ + const Word16 chan, /* i : channel number Q0*/ + Word32 output[L_FRAME48k], /* o : output synthesis signal qDFT*/ + const Word16 output_frame /* i : output frame length Q0*/ ) { Word16 i, k; @@ -716,7 +718,7 @@ void stereo_dft_dec_synthesize_fx( STEREO_DFT_DEC_DATA_HANDLE hStereoDft; Word32 *p_DFT; const Word16 *win, *win2; - Word16 trigo_dec[( ( STEREO_DFT32MS_N_MAX ) >> 1 ) + 1]; + Word16 trigo_dec[STEREO_DFT32MS_N_MAX / 2 + 1]; Word16 trigo_step; Word16 ovl, zp, NFFT; Word32 outputFs; @@ -734,20 +736,20 @@ void stereo_dft_dec_synthesize_fx( hCPE->lt_es_em_fx = L_shr( hCPE->lt_es_em_fx, 9 ); // Q24 -> Q15 - outputFs = L_mult0( output_frame, FRAMES_PER_SEC ); + outputFs = L_mult0( output_frame, FRAMES_PER_SEC ); /* Q0 */ zp = NS2SA_FX2( outputFs, STEREO_DFT32MS_ZP_NS ); move16(); ovl = NS2SA_FX2( outputFs, STEREO_DFT32MS_OVL_NS ); move16(); - win = hStereoDft->win32ms_fx; + win = hStereoDft->win32ms_fx; /* Q15 */ NFFT = NS2SA_FX2( outputFs, STEREO_DFT32MS_N_NS ); move16(); ovl2 = NS2SA_FX2( outputFs, STEREO_DFT32MS_OVL2_NS ); move16(); flat_portion_end = NS2SA_FX2( outputFs, L_sub( STEREO_DFT32MS_WIN_CENTER_NS, L_shr( STEREO_DFT32MS_OVL2_NS, 1 ) ) ); move16(); - win2 = hStereoDft->win232ms_fx; + win2 = hStereoDft->win232ms_fx; /* Q15 */ p_DFT = DFT[chan]; set32_fx( output, 0, NS2SA_FX2( outputFs, FRAME_SIZE_NS ) ); @@ -758,7 +760,7 @@ void stereo_dft_dec_synthesize_fx( test(); if ( ( chan == 0 && GT_16( hCPE->hCoreCoder[0]->last_coder_type, UNVOICED ) ) || EQ_16( hCPE->last_element_mode, IVAS_CPE_MDCT ) || LT_16( hCPE->last_element_mode, IVAS_CPE_DFT ) ) { - hCPE->stereo_switching_counter = 10; + hCPE->stereo_switching_counter = 10; /* Q0 */ move16(); } @@ -766,7 +768,7 @@ void stereo_dft_dec_synthesize_fx( { /* Set the level of dispersion */ Word16 tmp = extract_l( L_max( (Word16) 0xF333, L_min( (Word16) 0x3333, hCPE->lt_es_em_fx ) ) ); - hCPE->NbFrameMod = extract_h( L_add( L_mult0( 12, tmp ), 0x0000D99A ) ); /* -0.1: -0.4 ; -0.1 -> 0, 0.4 -> 6*/ + hCPE->NbFrameMod = extract_h( L_add( L_mult0( 12, tmp ), 0x0000D99A ) ); /* -0.1: -0.4 ; -0.1 -> 0, 0.4 -> 6*/ /* Q0 */ move16(); } moffset = s_max( 0, sub( 6, hCPE->NbFrameMod ) ); @@ -775,15 +777,15 @@ void stereo_dft_dec_synthesize_fx( * Synthesis *-----------------------------------------------------------------*/ - trigo_step = i_mult( hStereoDft->dft_trigo_step, STEREO_DFT_TRIGO_DEC_STEP ); - FOR( i = 0; i < shr( NFFT, 2 ); i++ ) + trigo_step = i_mult( hStereoDft->dft_trigo_step, STEREO_DFT_TRIGO_DEC_STEP ); /* Q0 */ + FOR( i = 0; i < NFFT / 4; i++ ) { - trigo_dec[i] = hStereoDft->dft_trigo_fx[i_mult( i, trigo_step )]; + trigo_dec[i] = hStereoDft->dft_trigo_fx[i * trigo_step]; /* Q15 */ move16(); - trigo_dec[sub( shr( NFFT, 1 ), i )] = hStereoDft->dft_trigo_fx[i * trigo_step]; + trigo_dec[NFFT / 2 - i] = hStereoDft->dft_trigo_fx[i * trigo_step]; /* Q15 */ move16(); } - trigo_dec[shr( NFFT, 2 )] = hStereoDft->dft_trigo_fx[shr( NFFT, 2 ) * trigo_step]; + trigo_dec[NFFT / 4] = hStereoDft->dft_trigo_fx[NFFT / 4 * trigo_step]; /* Q15 */ move16(); FOR( k = 0; k < STEREO_DFT_NBDIV; k++ ) @@ -796,17 +798,17 @@ void stereo_dft_dec_synthesize_fx( test(); IF( LE_16( hCPE->stereo_switching_counter, 6 ) && EQ_16( chan, 1 ) && ( GT_32( hCPE->lt_es_em_fx, (Word16) 0xCCCD ) || GT_16( hCPE->NbFrameMod, 4 ) ) ) { - FOR( i = 3; i < sub( sub( NFFT, moffset ), 1 ); i++ ) + FOR( i = 3; i < NFFT - moffset - 1; i++ ) { - p_DFT[i] = L_negate( p_DFT[add( add( i, moffset ), 1 )] ); + p_DFT[i] = L_negate( p_DFT[i + moffset + 1] ); /* q_DFT */ move32(); } } ELSE IF( LT_16( hCPE->stereo_switching_counter, 7 ) && ( GT_32( hCPE->lt_es_em_fx, (Word16) 0x199A ) || GT_16( hCPE->NbFrameMod, 4 ) ) ) { - FOR( i = sub( 16, hCPE->NbFrameMod ); i < sub( NFFT, add( moffset, 1 ) ); i++ ) + FOR( i = 16 - hCPE->NbFrameMod; i < NFFT - moffset - 1; i++ ) { - p_DFT[i - 2] = L_negate( p_DFT[add( add( i, moffset ), 1 )] ); + p_DFT[i - 2] = L_negate( p_DFT[i + moffset + 1] ); /* q_DFT */ move32(); } } @@ -826,19 +828,19 @@ void stereo_dft_dec_synthesize_fx( /* Left OLA - 3.125ms */ FOR( i = 0; i < ovl; i++ ) { - output[add( offset, i )] = Madd_32_16( L_shr( hCPE->output_mem_fx[chan][i], sub( hCPE->q_output_mem_fx[chan], hCPE->hStereoDft->q_dft ) ), p_DFT[add( zp, i )], win[STEREO_DFT32MS_STEP * i] ); + output[offset + i] = Madd_32_16( L_shr( hCPE->output_mem_fx[chan][i], sub( hCPE->q_output_mem_fx[chan], hCPE->hStereoDft->q_dft ) ), p_DFT[zp + i], win[STEREO_DFT32MS_STEP * i] ); /* hCPE->hStereoDft->q_dft */ move32(); } /* Flat Portion */ FOR( i = ovl; i < flat_portion_end; i++ ) { - output[add( offset, i )] = p_DFT[add( zp, i )]; + output[offset + i] = p_DFT[zp + i]; /* hCPE->hStereoDft->q_dft */ move32(); } /* Right OLA */ FOR( i = 0; i < ovl2; i++ ) { - ola_buff[i] = Mpy_32_16_1( p_DFT[add( sub( NFFT, add( zp, ovl2 ) ), i )], win2[sub( sub( ovl2, i ), 1 )] ); + ola_buff[i] = Mpy_32_16_1( p_DFT[NFFT - zp - ovl2 + i], win2[ovl2 - 1 - i] ); /* hCPE->hStereoDft->q_dft */ move32(); } } @@ -850,19 +852,19 @@ void stereo_dft_dec_synthesize_fx( /* Left OLA */ FOR( i = 0; i < ovl2; i++ ) { - output[add( offset, i )] = Madd_32_16( ola_buff[i], p_DFT[add( zp, i )], win2[i] ); + output[offset + i] = Madd_32_16( ola_buff[i], p_DFT[zp + i], win2[i] ); /* hCPE->hStereoDft->q_dft */ move32(); } /* Flat Portion */ - FOR( i = ovl2; i < sub( NFFT, add( shl( zp, 1 ), ovl ) ); i++ ) + FOR( i = ovl2; i < NFFT - 2 * zp - ovl; i++ ) { - output[add( offset, i )] = p_DFT[add( zp, i )]; + output[offset + i] = p_DFT[zp + i]; /* hCPE->hStereoDft->q_dft */ move32(); } /* Right OLA - 3.125ms */ FOR( i = 0; i < ovl; i++ ) { - hCPE->output_mem_fx[chan][i] = Mpy_32_16_1( p_DFT[add( sub( NFFT, add( zp, ovl ) ), i )], win[i_mult( STEREO_DFT32MS_STEP, ( sub( sub( ovl, i ), 1 ) ) )] ); + hCPE->output_mem_fx[chan][i] = Mpy_32_16_1( p_DFT[NFFT - zp - ovl + i], win[STEREO_DFT32MS_STEP * ( ovl - 1 - i )] ); /* hCPE->hStereoDft->q_dft */ move32(); } hCPE->q_output_mem_fx[chan] = hCPE->hStereoDft->q_dft; @@ -886,9 +888,9 @@ void stereo_dft_dec_synthesize_fx( void stereo_dft_dec_smooth_parameters_fx( STEREO_DFT_DEC_DATA_HANDLE hStereoDft, /* i/o: decoder DFT stereo handle */ - const Word16 prev_sid_nodata, /* i : Previous SID/No data indicator */ - const Word16 active_frame_counter, /* i : Active frame counter */ - const Word32 element_brate /* i : Element bitrate */ + const Word16 prev_sid_nodata, /* i : Previous SID/No data indicator Q0*/ + const Word16 active_frame_counter, /* i : Active frame counter Q0*/ + const Word32 element_brate /* i : Element bitrate Q0*/ ) { Word16 k_offset, k, k2, b, N_div; @@ -917,7 +919,7 @@ void stereo_dft_dec_smooth_parameters_fx( k = 1; FOR( b = 0; b < hStereoDft->nbands; b++ ) { - *( hStereoDft->side_gain_fx + add( i_mult( sub( add( k, k_offset ), 1 ), STEREO_DFT_BAND_MAX ), b ) ) = *( hStereoDft->side_gain_fx + add( i_mult( add( k, k_offset ), STEREO_DFT_BAND_MAX ), b ) ); + *( hStereoDft->side_gain_fx + add( i_mult( sub( add( k, k_offset ), 1 ), STEREO_DFT_BAND_MAX ), b ) ) = *( hStereoDft->side_gain_fx + add( i_mult( add( k, k_offset ), STEREO_DFT_BAND_MAX ), b ) ); /* Q31 */ move32(); } @@ -931,15 +933,15 @@ void stereo_dft_dec_smooth_parameters_fx( #endif { Word16 q_val; - IF( GT_32( L_sub( hStereoDft->gipd_fx[add( k, k_offset )], hStereoDft->ipd_xfade_prev_fx ), EVS_PI_FX_Q27 ) ) + IF( GT_32( L_sub( hStereoDft->gipd_fx[k + k_offset], hStereoDft->ipd_xfade_prev_fx ), EVS_PI_FX_Q27 ) ) { #ifdef FIX_874_INCREASE_IPD_PRECISION_A - hStereoDft->ipd_xfade_target_fx = L_sub( hStereoDft->gipd_fx[add( k, k_offset )], EVS_PI_FX_Q27 << 1 ); + hStereoDft->ipd_xfade_target_fx = L_sub( hStereoDft->gipd_fx[k + k_offset], EVS_PI_FX_Q27 << 1 ); /* Q27 */ #else hStereoDft->ipd_xfade_target_fx = L_sub( hStereoDft->gipd_fx[add( k, k_offset )], EVS_PI_FX_Q27 ); #endif move32(); - hStereoDft->ipd_xfade_step_fx = BASOP_Util_Divide3232_Scale( L_sub( hStereoDft->ipd_xfade_target_fx, hStereoDft->ipd_xfade_prev_fx ), L_shl( L_sub( STEREO_DFT_ITD_CNG_XFADE, hStereoDft->ipd_xfade_counter ), Q24 ), &q_val ); + hStereoDft->ipd_xfade_step_fx = BASOP_Util_Divide3232_Scale( L_sub( hStereoDft->ipd_xfade_target_fx, hStereoDft->ipd_xfade_prev_fx ), L_shl( L_sub( STEREO_DFT_ITD_CNG_XFADE, hStereoDft->ipd_xfade_counter ), Q24 ), &q_val ); /* Q27 */ move32(); q_val = add( q_val, Q9 ); /* Q27 - (Q15 - q_val + (-3))*/ @@ -950,20 +952,20 @@ void stereo_dft_dec_smooth_parameters_fx( } ELSE { - hStereoDft->ipd_xfade_step_fx = L_shl( hStereoDft->ipd_xfade_step_fx, q_val ); + hStereoDft->ipd_xfade_step_fx = L_shl( hStereoDft->ipd_xfade_step_fx, q_val ); /* Q27 */ move32(); } } - ELSE IF( GT_32( L_sub( hStereoDft->ipd_xfade_prev_fx, hStereoDft->gipd_fx[add( k, k_offset )] ), EVS_PI_FX_Q27 ) ) + ELSE IF( GT_32( L_sub( hStereoDft->ipd_xfade_prev_fx, hStereoDft->gipd_fx[k + k_offset] ), EVS_PI_FX_Q27 ) ) { #ifndef FIX_874_INCREASE_IPD_PRECISION_A hStereoDft->ipd_xfade_target_fx = L_add( hStereoDft->gipd_fx[add( k, k_offset )], L_shl( EVS_PI_FX_Q27, 1 ) ); #else - hStereoDft->ipd_xfade_target_fx = L_add( hStereoDft->gipd_fx[add( k, k_offset )], EVS_PI_FX_Q27 << 1 ); + hStereoDft->ipd_xfade_target_fx = L_add( hStereoDft->gipd_fx[k + k_offset], EVS_PI_FX_Q27 << 1 ); /* Q27 */ #endif move32(); - hStereoDft->ipd_xfade_step_fx = BASOP_Util_Divide3232_Scale( L_sub( hStereoDft->ipd_xfade_target_fx, hStereoDft->ipd_xfade_prev_fx ), L_shl( L_sub( STEREO_DFT_ITD_CNG_XFADE, hStereoDft->ipd_xfade_counter ), Q24 ), &q_val ); - q_val = add( q_val, Q9 ); /* Q27 - (Q15 - q_val + (-3))*/ + hStereoDft->ipd_xfade_step_fx = BASOP_Util_Divide3232_Scale( L_sub( hStereoDft->ipd_xfade_target_fx, hStereoDft->ipd_xfade_prev_fx ), L_shl( L_sub( STEREO_DFT_ITD_CNG_XFADE, hStereoDft->ipd_xfade_counter ), Q24 ), &q_val ); /* Q27 */ + q_val = add( q_val, Q9 ); /* Q27 - (Q15 - q_val + (-3))*/ move32(); IF( GT_16( q_val, 32 ) ) { @@ -971,13 +973,13 @@ void stereo_dft_dec_smooth_parameters_fx( } ELSE { - hStereoDft->ipd_xfade_step_fx = L_shl( hStereoDft->ipd_xfade_step_fx, q_val ); + hStereoDft->ipd_xfade_step_fx = L_shl( hStereoDft->ipd_xfade_step_fx, q_val ); /* Q27 */ move32(); } } ELSE { - hStereoDft->ipd_xfade_target_fx = hStereoDft->gipd_fx[add( k, k_offset )]; + hStereoDft->ipd_xfade_target_fx = hStereoDft->gipd_fx[k + k_offset]; /* Q27 */ move32(); hStereoDft->ipd_xfade_step_fx = BASOP_Util_Divide3232_Scale( L_sub( hStereoDft->ipd_xfade_target_fx, hStereoDft->ipd_xfade_prev_fx ), L_shl( L_sub( STEREO_DFT_ITD_CNG_XFADE, hStereoDft->ipd_xfade_counter ), Q24 ), &q_val ); q_val = add( q_val, Q9 ); /* Q27 - (Q15 - q_val + (-3))*/ @@ -988,7 +990,7 @@ void stereo_dft_dec_smooth_parameters_fx( } ELSE { - hStereoDft->ipd_xfade_step_fx = L_shl( hStereoDft->ipd_xfade_step_fx, q_val ); + hStereoDft->ipd_xfade_step_fx = L_shl( hStereoDft->ipd_xfade_step_fx, q_val ); /* Q27 */ move32(); } } @@ -999,11 +1001,11 @@ void stereo_dft_dec_smooth_parameters_fx( test(); IF( NE_32( hStereoDft->ipd_xfade_prev_fx, hStereoDft->ipd_xfade_target_fx ) && LT_16( hStereoDft->ipd_xfade_counter, STEREO_DFT_ITD_CNG_XFADE ) && LE_32( hStereoDft->last_active_element_brate, 24400 ) ) { - hStereoDft->gipd_fx[add( k, k_offset )] = L_add( hStereoDft->ipd_xfade_prev_fx, hStereoDft->ipd_xfade_step_fx ); + hStereoDft->gipd_fx[k + k_offset] = L_add( hStereoDft->ipd_xfade_prev_fx, hStereoDft->ipd_xfade_step_fx ); /* Q27 */ move32(); - hStereoDft->ipd_xfade_prev_fx = hStereoDft->gipd_fx[add( k, k_offset )]; + hStereoDft->ipd_xfade_prev_fx = hStereoDft->gipd_fx[k + k_offset]; /* Q27 */ move32(); - hStereoDft->ipd_xfade_counter = add( hStereoDft->ipd_xfade_counter, 1 ); + hStereoDft->ipd_xfade_counter = add( hStereoDft->ipd_xfade_counter, 1 ); /* Q27 */ move16(); } } @@ -1012,18 +1014,18 @@ void stereo_dft_dec_smooth_parameters_fx( /* First active frame, "reset" everything if long enough active encoding, only triggered if STEREO_DFT_ITD_CNG_XFADE_RESET = -1 */ IF( GT_16( active_frame_counter, STEREO_DFT_ITD_CNG_XFADE_RESET ) ) { - hStereoDft->ipd_xfade_target_fx = hStereoDft->gipd_fx[add( k, k_offset )]; + hStereoDft->ipd_xfade_target_fx = hStereoDft->gipd_fx[k + k_offset]; /* Q27 */ move32(); - hStereoDft->ipd_xfade_prev_fx = hStereoDft->gipd_fx[add( k, k_offset )]; + hStereoDft->ipd_xfade_prev_fx = hStereoDft->gipd_fx[k + k_offset]; /* Q27 */ move32(); hStereoDft->ipd_xfade_counter = 0; move16(); } } - FOR( k2 = 1; k2 < hStereoDft->prm_res[add( k, k_offset )]; k2++ ) + FOR( k2 = 1; k2 < hStereoDft->prm_res[k + k_offset]; k2++ ) { - hStereoDft->gipd_fx[sub( add( k, k_offset ), k2 )] = hStereoDft->gipd_fx[add( k, k_offset )]; + hStereoDft->gipd_fx[( k + k_offset ) - k2] = hStereoDft->gipd_fx[k + k_offset]; /* Q27 */ move32(); } @@ -1037,7 +1039,7 @@ void stereo_dft_dec_smooth_parameters_fx( #endif { Word16 q_val; - hStereoDft->itd_xfade_target_fx = hStereoDft->itd_fx[add( k, k_offset )]; + hStereoDft->itd_xfade_target_fx = hStereoDft->itd_fx[k + k_offset]; /* Q15 */ move32(); hStereoDft->itd_xfade_step_fx = BASOP_Util_Divide3232_Scale( L_sub( hStereoDft->itd_xfade_target_fx, hStereoDft->itd_xfade_prev_fx ), L_shl( sub( STEREO_DFT_ITD_CNG_XFADE, hStereoDft->itd_xfade_counter ), Q15 ), &q_val ); IF( GT_16( q_val, 16 ) ) @@ -1046,7 +1048,7 @@ void stereo_dft_dec_smooth_parameters_fx( } ELSE { - hStereoDft->itd_xfade_step_fx = L_shl( hStereoDft->itd_xfade_step_fx, q_val ); + hStereoDft->itd_xfade_step_fx = L_shl( hStereoDft->itd_xfade_step_fx, q_val ); /* Q15 */ move32(); } move32(); @@ -1055,11 +1057,11 @@ void stereo_dft_dec_smooth_parameters_fx( /* xfade */ IF( NE_32( hStereoDft->itd_xfade_prev_fx, hStereoDft->itd_xfade_target_fx ) && LT_16( hStereoDft->itd_xfade_counter, STEREO_DFT_ITD_CNG_XFADE ) && LE_32( hStereoDft->last_active_element_brate, 24400 ) ) { - hStereoDft->itd_fx[add( k, k_offset )] = L_add( hStereoDft->itd_xfade_prev_fx, hStereoDft->itd_xfade_step_fx ); + hStereoDft->itd_fx[k + k_offset] = L_add( hStereoDft->itd_xfade_prev_fx, hStereoDft->itd_xfade_step_fx ); /* Q15 */ move32(); - hStereoDft->itd_xfade_prev_fx = hStereoDft->itd_fx[add( k, k_offset )]; + hStereoDft->itd_xfade_prev_fx = hStereoDft->itd_fx[k + k_offset]; /* Q15 */ move32(); - hStereoDft->itd_xfade_counter = add( hStereoDft->itd_xfade_counter, 1 ); + hStereoDft->itd_xfade_counter = add( hStereoDft->itd_xfade_counter, 1 ); /* Q0 */ } } ELSE @@ -1067,20 +1069,20 @@ void stereo_dft_dec_smooth_parameters_fx( /* First active frame, "reset" everything if long enough active encoding, only triggered if STEREO_DFT_ITD_CNG_XFADE_RESET = -1 */ IF( GT_16( active_frame_counter, STEREO_DFT_ITD_CNG_XFADE_RESET ) ) { - hStereoDft->itd_xfade_target_fx = hStereoDft->itd_fx[add( k, k_offset )]; + hStereoDft->itd_xfade_target_fx = hStereoDft->itd_fx[k + k_offset]; /* Q15 */ move32(); - hStereoDft->itd_xfade_prev_fx = hStereoDft->itd_fx[add( k, k_offset )]; + hStereoDft->itd_xfade_prev_fx = hStereoDft->itd_fx[k + k_offset]; /* Q15 */ move32(); - hStereoDft->itd_xfade_counter = 0; + hStereoDft->itd_xfade_counter = 0; /* Q0 */ move32(); } hStereoDft->last_active_element_brate = element_brate; move32(); } - FOR( k2 = 1; k2 < hStereoDft->prm_res[add( k, k_offset )]; k2++ ) + FOR( k2 = 1; k2 < hStereoDft->prm_res[k + k_offset]; k2++ ) { - hStereoDft->itd_fx[sub( add( k, k_offset ), k2 )] = hStereoDft->itd_fx[add( k, k_offset )]; + hStereoDft->itd_fx[( k + k_offset ) - k2] = hStereoDft->itd_fx[k + k_offset]; /* Q15 */ move32(); } @@ -1092,22 +1094,22 @@ void stereo_dft_dec_smooth_parameters_fx( { hStereoDft->itd_xfade_counter = 0; move16(); - hStereoDft->itd_xfade_target_fx = hStereoDft->itd_fx[STEREO_DFT_NBDIV - 1]; + hStereoDft->itd_xfade_target_fx = hStereoDft->itd_fx[STEREO_DFT_NBDIV - 1]; /* Q15 */ move32(); - hStereoDft->itd_xfade_prev_fx = hStereoDft->itd_fx[STEREO_DFT_NBDIV - 1]; + hStereoDft->itd_xfade_prev_fx = hStereoDft->itd_fx[STEREO_DFT_NBDIV - 1]; /* Q15 */ move32(); hStereoDft->ipd_xfade_counter = 0; move16(); - hStereoDft->ipd_xfade_target_fx = hStereoDft->gipd_fx[STEREO_DFT_NBDIV - 1]; + hStereoDft->ipd_xfade_target_fx = hStereoDft->gipd_fx[STEREO_DFT_NBDIV - 1]; /* Q27 */ move32(); - hStereoDft->ipd_xfade_prev_fx = hStereoDft->gipd_fx[STEREO_DFT_NBDIV - 1]; + hStereoDft->ipd_xfade_prev_fx = hStereoDft->gipd_fx[STEREO_DFT_NBDIV - 1]; /* Q27 */ move32(); } hStereoDft->last_active_element_brate = element_brate; move32(); - FOR( k = sub( hStereoDft->prm_res[k_offset], 1 ); k < N_div; k += hStereoDft->prm_res[add( k, k_offset )] ) + FOR( k = sub( hStereoDft->prm_res[k_offset], 1 ); k < N_div; k += hStereoDft->prm_res[k + k_offset] ) { max_res_pred_ind = 0; move32(); @@ -1121,19 +1123,19 @@ void stereo_dft_dec_smooth_parameters_fx( FOR( b = sub( hStereoDft->nbands_respred, 1 ); b >= nbands; b-- ) { hStereoDft->res_gains_ind_fx[1][b + STEREO_DFT_BAND_MAX] = - hStereoDft->res_gains_ind_fx[1][b - STEREO_DFT_RES_PRED_BAND_MIN_RED + hStereoDft->res_pred_band_min + STEREO_DFT_BAND_MAX]; + hStereoDft->res_gains_ind_fx[1][b - STEREO_DFT_RES_PRED_BAND_MIN_RED + hStereoDft->res_pred_band_min + STEREO_DFT_BAND_MAX]; /* Q26 */ move32(); - hStereoDft->res_gains_ind_fx[1][b - STEREO_DFT_RES_PRED_BAND_MIN_RED + hStereoDft->res_pred_band_min + STEREO_DFT_BAND_MAX] = 0; + hStereoDft->res_gains_ind_fx[1][b - STEREO_DFT_RES_PRED_BAND_MIN_RED + hStereoDft->res_pred_band_min + STEREO_DFT_BAND_MAX] = 0; /* Q26 */ move32(); } } /* Get maximal index */ - FOR( b = hStereoDft->res_pred_band_min; b < sub( nbands, STEREO_DFT_RES_PRED_BAND_MIN_CONST ); b++ ) + FOR( b = hStereoDft->res_pred_band_min; b < nbands - STEREO_DFT_RES_PRED_BAND_MIN_CONST; b++ ) { IF( LT_32( max_res_pred_ind, hStereoDft->res_gains_ind_fx[1][b + STEREO_DFT_BAND_MAX] ) ) { - max_res_pred_ind = hStereoDft->res_gains_ind_fx[1][b + STEREO_DFT_BAND_MAX]; + max_res_pred_ind = hStereoDft->res_gains_ind_fx[1][b + STEREO_DFT_BAND_MAX]; /* Q26 */ move32(); } } @@ -1142,7 +1144,7 @@ void stereo_dft_dec_smooth_parameters_fx( FOR( ; b < nbands; b++ ) { assert( hStereoDft->res_gains_ind_fx[1][b + STEREO_DFT_BAND_MAX] == 0 ); - hStereoDft->res_gains_ind_fx[1][b + STEREO_DFT_BAND_MAX] = max_res_pred_ind; + hStereoDft->res_gains_ind_fx[1][b + STEREO_DFT_BAND_MAX] = max_res_pred_ind; /* Q26 */ move32(); } } @@ -1152,12 +1154,12 @@ void stereo_dft_dec_smooth_parameters_fx( Word32 tmp; Word16 tmps1, tmps2; - hStereoDft->res_gains_ind_fx[0][b] = hStereoDft->res_gains_ind_fx[0][b + STEREO_DFT_BAND_MAX]; + hStereoDft->res_gains_ind_fx[0][b] = hStereoDft->res_gains_ind_fx[0][b + STEREO_DFT_BAND_MAX]; /* Q26 */ move32(); /*stereo_dft_dequantize_res_gains_f(&hStereoDft->res_gains_ind[0][b], &hStereoDft->res_gains_ind[1][b+STEREO_DFT_BAND_MAX],hStereoDft->side_gain+(k+k_offset)*STEREO_DFT_BAND_MAX+b, hStereoDft->res_pred_gain+(k+k_offset)*STEREO_DFT_BAND_MAX+b, 1);*/ - tmps1 = (Word16) L_shr( hStereoDft->res_gains_ind_fx[0][b], Q26 ); + tmps1 = (Word16) L_shr( hStereoDft->res_gains_ind_fx[0][b], Q26 ); /* Q0 */ move16(); - tmps2 = (Word16) L_shr( hStereoDft->res_gains_ind_fx[1][b + STEREO_DFT_BAND_MAX], Q26 ); + tmps2 = (Word16) L_shr( hStereoDft->res_gains_ind_fx[1][b + STEREO_DFT_BAND_MAX], Q26 ); /* Q0 */ move16(); stereo_dft_dequantize_res_gains_fx( &tmps1, &tmps2, hStereoDft->side_gain_fx + add( i_mult( add( k, k_offset ), STEREO_DFT_BAND_MAX ), b ), hStereoDft->res_pred_gain_fx + add( i_mult( add( k, k_offset ), STEREO_DFT_BAND_MAX ), b ), 1 ); @@ -1165,20 +1167,20 @@ void stereo_dft_dec_smooth_parameters_fx( test(); IF( hStereoDft->attackPresent ) { - hStereoDft->res_gains_ind_fx[1][b] = Mpy_32_16_1( hStereoDft->res_gains_ind_fx[1][b], (Word16) 0x6666 ); + hStereoDft->res_gains_ind_fx[1][b] = Mpy_32_16_1( hStereoDft->res_gains_ind_fx[1][b], (Word16) 0x6666 ); /* Q26 */ move32(); } ELSE IF( hStereoDft->trans || ( hStereoDft->res_pred_mode[k] && ( LT_32( hStereoDft->res_gains_ind_fx[1][b + STEREO_DFT_BAND_MAX], ONE_IN_Q27 ) ) ) ) /* Assuming Maximum Q of res_gains_ind_fx is Q26 */ { hStereoDft->res_gains_ind_fx[1][b] = Madd_32_16( Mpy_32_16_1( hStereoDft->res_gains_ind_fx[1][b], (Word16) 0x4CCD ), - hStereoDft->res_gains_ind_fx[1][b + STEREO_DFT_BAND_MAX], (Word16) 0x3333 ); + hStereoDft->res_gains_ind_fx[1][b + STEREO_DFT_BAND_MAX], (Word16) 0x3333 ); /* Q26 */ move32(); } ELSE { hStereoDft->res_gains_ind_fx[1][b] = Madd_32_16( Mpy_32_16_1( hStereoDft->res_gains_ind_fx[1][b], dft_alpha_s2_fx[b] ), hStereoDft->res_gains_ind_fx[1][b + STEREO_DFT_BAND_MAX], - sub( (Word16) 0x7FFF, dft_alpha_s2_fx[b] ) ); + sub( (Word16) 0x7FFF, dft_alpha_s2_fx[b] ) ); /* Q26 */ move32(); } @@ -1192,25 +1194,25 @@ void stereo_dft_dec_smooth_parameters_fx( test(); IF( hStereoDft->attackPresent ) { - hStereoDft->res_gains_ind_fx[0][b] = hStereoDft->res_gains_ind_fx[0][b + STEREO_DFT_BAND_MAX]; + hStereoDft->res_gains_ind_fx[0][b] = hStereoDft->res_gains_ind_fx[0][b + STEREO_DFT_BAND_MAX]; /* Q26 */ move32(); - hStereoDft->res_gains_ind_fx[1][b] = Mpy_32_16_1( hStereoDft->res_gains_ind_fx[1][b], (Word16) 0x6666 ); + hStereoDft->res_gains_ind_fx[1][b] = Mpy_32_16_1( hStereoDft->res_gains_ind_fx[1][b], (Word16) 0x6666 ); /* Q26 */ move32(); } ELSE IF( hStereoDft->trans || ( hStereoDft->res_pred_mode[k] && LT_32( hStereoDft->res_gains_ind_fx[1][b + STEREO_DFT_BAND_MAX], ONE_IN_Q27 ) ) ) { - hStereoDft->res_gains_ind_fx[0][b] = hStereoDft->res_gains_ind_fx[0][b + STEREO_DFT_BAND_MAX]; + hStereoDft->res_gains_ind_fx[0][b] = hStereoDft->res_gains_ind_fx[0][b + STEREO_DFT_BAND_MAX]; /* Q26 */ move32(); IF( EQ_16( hStereoDft->hConfig->band_res, STEREO_DFT_BAND_RES_LOW ) ) { hStereoDft->res_gains_ind_fx[1][b] = Madd_32_16( Mpy_32_16_1( hStereoDft->res_gains_ind_fx[1][b], dft_alpha_w_b2_fx[b] ), - hStereoDft->res_gains_ind_fx[1][b + STEREO_DFT_BAND_MAX], sub( (Word16) 0x7FFF, dft_alpha_w_b2_fx[b] ) ); + hStereoDft->res_gains_ind_fx[1][b + STEREO_DFT_BAND_MAX], sub( (Word16) 0x7FFF, dft_alpha_w_b2_fx[b] ) ); /* Q26 */ move32(); } ELSE { hStereoDft->res_gains_ind_fx[1][b] = Madd_32_16( Mpy_32_16_1( hStereoDft->res_gains_ind_fx[1][b], dft_alpha_w_fx[b] ), - hStereoDft->res_gains_ind_fx[1][b + STEREO_DFT_BAND_MAX], sub( (Word16) 0x7FFF, dft_alpha_w_fx[b] ) ); + hStereoDft->res_gains_ind_fx[1][b + STEREO_DFT_BAND_MAX], sub( (Word16) 0x7FFF, dft_alpha_w_fx[b] ) ); /* Q26 */ move32(); } } @@ -1220,22 +1222,22 @@ void stereo_dft_dec_smooth_parameters_fx( { hStereoDft->res_gains_ind_fx[0][b] = Madd_32_16( Mpy_32_16_1( hStereoDft->res_gains_ind_fx[0][b], dft_alpha_s_b2_fx[b] ), hStereoDft->res_gains_ind_fx[0][b + STEREO_DFT_BAND_MAX], - sub( (Word16) 0x7FFF, dft_alpha_s_b2_fx[b] ) ); + sub( (Word16) 0x7FFF, dft_alpha_s_b2_fx[b] ) ); /* Q26 */ move32(); hStereoDft->res_gains_ind_fx[1][b] = Madd_32_16( Mpy_32_16_1( hStereoDft->res_gains_ind_fx[1][b], dft_alpha_s2_b2_fx[b] ), hStereoDft->res_gains_ind_fx[1][b + STEREO_DFT_BAND_MAX], - sub( (Word16) 0x7FFF, dft_alpha_s2_b2_fx[b] ) ); + sub( (Word16) 0x7FFF, dft_alpha_s2_b2_fx[b] ) ); /* Q26 */ move32(); } ELSE { hStereoDft->res_gains_ind_fx[0][b] = Madd_32_16( Mpy_32_16_1( hStereoDft->res_gains_ind_fx[0][b], dft_alpha_s_fx[b] ), hStereoDft->res_gains_ind_fx[0][b + STEREO_DFT_BAND_MAX], - sub( (Word16) ( 0x7FFF ), dft_alpha_s_fx[b] ) ); + sub( (Word16) ( 0x7FFF ), dft_alpha_s_fx[b] ) ); /* Q26 */ move32(); hStereoDft->res_gains_ind_fx[1][b] = Madd_32_16( Mpy_32_16_1( hStereoDft->res_gains_ind_fx[1][b], dft_alpha_s2_fx[b] ), hStereoDft->res_gains_ind_fx[1][b + STEREO_DFT_BAND_MAX], - sub( (Word16) ( 0x7FFF ), dft_alpha_s2_fx[b] ) ); + sub( (Word16) ( 0x7FFF ), dft_alpha_s2_fx[b] ) ); /* Q26 */ move32(); } } @@ -1248,14 +1250,14 @@ void stereo_dft_dec_smooth_parameters_fx( /* Smoothing of IPDs*/ pgIpd = hStereoDft->gipd_fx + ( add( k, k_offset ) ); - diff_ipd = L_sub( pgIpd[0], pgIpd[-hStereoDft->prm_res[add( k, k_offset )]] ); + diff_ipd = L_sub( pgIpd[0], pgIpd[-hStereoDft->prm_res[k + k_offset]] ); /* Q27 */ #ifndef FIX_874_INCREASE_IPD_PRECISION IF( LT_32( diff_ipd, -EVS_PI_FX_Q27 ) ) #else IF( LT_32( diff_ipd, -PI_round ) ) #endif { - pgIpd[0] = L_add( pgIpd[0], EVS_2PI_FX_Q27 ); + pgIpd[0] = L_add( pgIpd[0], EVS_2PI_FX_Q27 ); /* Q27 */ move32(); } #ifndef FIX_874_INCREASE_IPD_PRECISION @@ -1264,7 +1266,7 @@ void stereo_dft_dec_smooth_parameters_fx( ELSE IF( GT_32( diff_ipd, PI_round ) ) #endif { - pgIpd[0] = L_sub( pgIpd[0], EVS_2PI_FX_Q27 ); + pgIpd[0] = L_sub( pgIpd[0], EVS_2PI_FX_Q27 ); /* Q27 */ move32(); } @@ -1272,12 +1274,12 @@ void stereo_dft_dec_smooth_parameters_fx( { IF( hStereoDft->wasTransient ) { - pgIpd[0] = L_add( Mpy_32_16_1( pgIpd[0], (Word16) 0x6666 ), Mpy_32_16_1( pgIpd[-hStereoDft->prm_res[add( k, k_offset )]], (Word16) ( 0x199A ) ) ); + pgIpd[0] = L_add( Mpy_32_16_1( pgIpd[0], (Word16) 0x6666 ), Mpy_32_16_1( pgIpd[-hStereoDft->prm_res[k + k_offset]], (Word16) ( 0x199A ) ) ); /* Q27 */ move32(); } ELSE { - pgIpd[0] = L_add( L_shr( pgIpd[0], 1 ), L_shr( pgIpd[-hStereoDft->prm_res[add( k, k_offset )]], 1 ) ); + pgIpd[0] = L_add( L_shr( pgIpd[0], 1 ), L_shr( pgIpd[-hStereoDft->prm_res[k + k_offset]], 1 ) ); /* Q27 */ move32(); } } @@ -1285,21 +1287,21 @@ void stereo_dft_dec_smooth_parameters_fx( IF( !hStereoDft->attackPresent ) { - pSideGain = hStereoDft->side_gain_fx + i_mult( add( k, k_offset ), STEREO_DFT_BAND_MAX ); + pSideGain = hStereoDft->side_gain_fx + i_mult( add( k, k_offset ), STEREO_DFT_BAND_MAX ); /* Q31 */ FOR( b = 0; b < hStereoDft->res_cod_band_max; b++ ) { pSideGain[b] = Madd_32_16( Mpy_32_16_1( pSideGain[b], dft_res_cod_alpha_fx[b] ), - pSideGain[sub( b, i_mult( hStereoDft->prm_res[add( k, k_offset )], STEREO_DFT_BAND_MAX ) )], - sub( (Word16) 0x7FFF, dft_res_cod_alpha_fx[b] ) ); + pSideGain[b - hStereoDft->prm_res[k + k_offset] * STEREO_DFT_BAND_MAX], + sub( (Word16) 0x7FFF, dft_res_cod_alpha_fx[b] ) ); /* Q31 */ move32(); } } /*Interpolation between DFT slots*/ - FOR( k2 = 1; k2 < hStereoDft->prm_res[add( k, k_offset )]; k2++ ) + FOR( k2 = 1; k2 < hStereoDft->prm_res[k + k_offset]; k2++ ) { - pInterpol = hStereoDft->gipd_fx + sub( add( k, k_offset ), k2 ); - pIpd = hStereoDft->gipd_fx + add( k, k_offset ); + pInterpol = hStereoDft->gipd_fx + sub( add( k, k_offset ), k2 ); /* Q27 */ + pIpd = hStereoDft->gipd_fx + add( k, k_offset ); /* Q27 */ IF( hStereoDft->attackPresent ) { *( pInterpol ) = *( pIpd ); @@ -1307,13 +1309,13 @@ void stereo_dft_dec_smooth_parameters_fx( } ELSE { - *( pInterpol ) = *( hStereoDft->gipd_fx + sub( add( k, k_offset ), hStereoDft->prm_res[add( k, k_offset )] ) ); + *( pInterpol ) = *( hStereoDft->gipd_fx + sub( add( k, k_offset ), hStereoDft->prm_res[k + k_offset] ) ); move32(); } FOR( b = 0; b < hStereoDft->nbands; b++ ) { - *( hStereoDft->res_pred_gain_fx + add( i_mult( sub( add( k, k_offset ), k2 ), STEREO_DFT_BAND_MAX ), b ) ) = *( hStereoDft->res_pred_gain_fx + add( i_mult( sub( add( k, k_offset ), hStereoDft->prm_res[add( k, k_offset )] ), STEREO_DFT_BAND_MAX ), b ) ); + *( hStereoDft->res_pred_gain_fx + add( i_mult( sub( add( k, k_offset ), k2 ), STEREO_DFT_BAND_MAX ), b ) ) = *( hStereoDft->res_pred_gain_fx + add( i_mult( sub( add( k, k_offset ), hStereoDft->prm_res[k + k_offset] ), STEREO_DFT_BAND_MAX ), b ) ); /* Q31 */ move32(); test(); test(); @@ -1321,17 +1323,17 @@ void stereo_dft_dec_smooth_parameters_fx( test(); IF( b < hStereoDft->res_cod_band_max || hStereoDft->attackPresent || hStereoDft->trans || ( hStereoDft->res_pred_mode[k] && LT_32( hStereoDft->res_gains_ind_fx[1][b + STEREO_DFT_BAND_MAX], ONE_IN_Q27 ) ) ) { - *( hStereoDft->side_gain_fx + add( i_mult( sub( add( k, k_offset ), k2 ), STEREO_DFT_BAND_MAX ), b ) ) = *( hStereoDft->side_gain_fx + add( i_mult( add( k, k_offset ), STEREO_DFT_BAND_MAX ), b ) ); + *( hStereoDft->side_gain_fx + add( i_mult( sub( add( k, k_offset ), k2 ), STEREO_DFT_BAND_MAX ), b ) ) = *( hStereoDft->side_gain_fx + add( i_mult( add( k, k_offset ), STEREO_DFT_BAND_MAX ), b ) ); /* Q31 */ move32(); } ELSE { - *( hStereoDft->side_gain_fx + add( i_mult( sub( add( k, k_offset ), k2 ), STEREO_DFT_BAND_MAX ), b ) ) = *( hStereoDft->side_gain_fx + add( i_mult( sub( add( k, k_offset ), hStereoDft->prm_res[add( k, k_offset )] ), STEREO_DFT_BAND_MAX ), b ) ); + *( hStereoDft->side_gain_fx + add( i_mult( sub( add( k, k_offset ), k2 ), STEREO_DFT_BAND_MAX ), b ) ) = *( hStereoDft->side_gain_fx + add( i_mult( sub( add( k, k_offset ), hStereoDft->prm_res[k + k_offset] ), STEREO_DFT_BAND_MAX ), b ) ); /* Q31 */ move32(); } } - hStereoDft->itd_fx[sub( add( k, k_offset ), k2 )] = hStereoDft->itd_fx[add( k, k_offset )]; + hStereoDft->itd_fx[k + k_offset - k2] = hStereoDft->itd_fx[k + k_offset]; /* Q15 */ move32(); } /*end of interpolation*/ } @@ -1346,10 +1348,10 @@ void stereo_dft_dec_smooth_parameters_fx( *-------------------------------------------------------------------------*/ void stereo_dft_dec_res_fx( - CPE_DEC_HANDLE hCPE, /* i/o: decoder CPE handle */ - Word32 res_buf[STEREO_DFT_N_8k], /* i : residual buffer */ - Word16 q_res, /* i : q fact of residural buffer */ - Word32 *output /* o : output */ + CPE_DEC_HANDLE hCPE, /* i/o: decoder CPE handle */ + Word32 res_buf[STEREO_DFT_N_8k], /* i : residual buffer q_res*/ + Word16 q_res, /* i : q fact of residural buffer */ + Word32 *output /* o : output Q16*/ ) { Word16 i; @@ -1363,6 +1365,7 @@ void stereo_dft_dec_res_fx( prev_bfi = hCPE->hCoreCoder[0]->prev_old_bfi; /* The core decoding is already completed here and the prev_bfi has been updated for the next frame. The prev_old_bfi still holds the prev_bfi for the current frame. */ + /* Q0 */ move16(); /* flush memories when switching residual coding on */ @@ -1387,9 +1390,9 @@ void stereo_dft_dec_res_fx( Word16 q_shift = sub( hCPE->hStereoDft->q_res_cod_mem_fx, Q16 ); FOR( i = 0; i < STEREO_DFT_OVL_8k; i++ ) { - win[i] = extract_h( L_add( hCPE->hStereoDft->res_cod_mem_fx[i], L_shl( L_mult( win[i], hCPE->hStereoDft->win_8k_fx[i] ), q_shift ) ) ); + win[i] = extract_h( L_add( hCPE->hStereoDft->res_cod_mem_fx[i], L_shl( L_mult( win[i], hCPE->hStereoDft->win_8k_fx[i] ), q_shift ) ) ); /* q_res_cod_mem_fx */ move16(); - hCPE->hStereoDft->res_cod_mem_fx[i] = L_mult( win[L_FRAME8k + i], hCPE->hStereoDft->win_8k_fx[STEREO_DFT_OVL_8k - 1 - i] ); + hCPE->hStereoDft->res_cod_mem_fx[i] = L_mult( win[L_FRAME8k + i], hCPE->hStereoDft->win_8k_fx[STEREO_DFT_OVL_8k - 1 - i] ); /* q_res_cod_mem_fx */ move32(); } IF( q_shift != 0 ) @@ -1410,38 +1413,38 @@ void stereo_dft_dec_res_fx( { win[i] = extract_h( Madd_32_16( Mpy_32_16_1( hCPE->hStereoDft->res_cod_mem_fx[i], sub( MAX_16, mult( fac, fac ) ) ), L_mult( hCPE->hStereoDft->win_8k_fx[i], win[i] ), - sub( MAX_16, mult( sub( MAX_16, fac ), sub( MAX_16, fac ) ) ) ) ); + sub( MAX_16, mult( sub( MAX_16, fac ), sub( MAX_16, fac ) ) ) ) ); /* Q0 */ move16(); - hCPE->hStereoDft->res_cod_mem_fx[i] = L_mult( win[L_FRAME8k + i], hCPE->hStereoDft->win_8k_fx[STEREO_DFT_OVL_8k - 1 - i] ); + hCPE->hStereoDft->res_cod_mem_fx[i] = L_mult( win[L_FRAME8k + i], hCPE->hStereoDft->win_8k_fx[STEREO_DFT_OVL_8k - 1 - i] ); /* Q16 */ move32(); fac = add( fac, step ); } } - Copy( win, out_16, L_FRAME8k ); + Copy( win, out_16, L_FRAME8k ); /* Q0 */ IF( hCPE->hCoreCoder[0]->core == ACELP_CORE ) { /* bass post-filter */ bass_psfilter_fx( hCPE->hStereoDft->hBpf, hCPE->hCoreCoder[0]->Opt_AMR_WB, out_16, L_FRAME8k, hCPE->hCoreCoder[0]->old_pitch_buf_16_fx + ( L_FRAME8k / STEREO_DFT_L_SUBFR_8k ), hCPE->hCoreCoder[0]->bpf_off, hCPE->hCoreCoder[0]->stab_fac_fx, &hCPE->hStereoDft->stab_fac_smooth_res_fx, hCPE->hCoreCoder[0]->last_coder_type, 0, bpf_error_signal_8k_16 ); - Copy_Scale_sig_16_32( bpf_error_signal_8k_16, bpf_error_signal_8k, L_FRAME8k, Q15 ); + Copy_Scale_sig_16_32( bpf_error_signal_8k_16, bpf_error_signal_8k, L_FRAME8k, Q15 ); /* Q15 */ res_bpf_flag = res_bpf_adapt_ivas_fx( hCPE->hStereoDft, bpf_error_signal_8k, res_buf, q_res ); IF( prev_bfi ) { /* Ramp up BPF contribution for the first good frame */ - step = (Word16) ( 0x00CD ); // ( 1.0f / L_FRAME8k ); + step = (Word16) ( 0x00CD ); // ( 1.0f / L_FRAME8k ); /* Q15 */ move16(); fac = negate( step ); FOR( i = 0; i < L_FRAME8k; i++ ) { fac = add( fac, step ); - bpf_error_signal_8k[i] = Mpy_32_16_1( bpf_error_signal_8k[i], fac ); + bpf_error_signal_8k[i] = Mpy_32_16_1( bpf_error_signal_8k[i], fac ); /* Q15 */ move32(); } } - Copy_Scale_sig_16_32( out_16, output, L_FRAME8k, 16 ); + Copy_Scale_sig_16_32( out_16, output, L_FRAME8k, 16 ); /* Q16 */ IF( res_bpf_flag ) { v_sub_32( output, bpf_error_signal_8k, output, L_FRAME8k ); @@ -1452,12 +1455,12 @@ void stereo_dft_dec_res_fx( set16_fx( hCPE->hStereoDft->hBpf->pst_old_syn_fx, 0, STEREO_DFT_NBPSF_PIT_MAX_8k ); hCPE->hStereoDft->hBpf->pst_mem_deemp_err_fx = 0; move16(); - Copy_Scale_sig_16_32( out_16, output, L_FRAME8k, 16 ); + Copy_Scale_sig_16_32( out_16, output, L_FRAME8k, 16 ); /* Q16 */ } ELSE { /* This step is needed to ensure output is properly populated with scaled values in all cases*/ - Copy_Scale_sig_16_32( out_16, output, L_FRAME8k, 16 ); + Copy_Scale_sig_16_32( out_16, output, L_FRAME8k, 16 ); /* Q16 */ } return; @@ -1471,18 +1474,18 @@ void stereo_dft_dec_res_fx( *-------------------------------------------------------------------------*/ void stereo_dft_dec_fx( - STEREO_DFT_DEC_DATA_HANDLE hStereoDft, /* i/o: decoder DFT stereo handle */ - Decoder_State *st0, /* i/o: decoder state structure */ - Word32 DFT[CPE_CHANNELS][STEREO_DFT_BUF_MAX], /* i/o: DFT buffers */ - Word32 *input_mem, /* i/o: mem of buffer DFT analysis */ - STEREO_CNG_DEC_HANDLE hStereoCng, /* i/o: Stereo CNG data structure */ - const Word16 sba_dirac_stereo_flag, /* i : signal stereo output for SBA DirAC */ - const Word16 sba_mono_flag, /* i : signal mono output for SBA DirAC */ - ivas_spar_md_dec_state_t *hMdDec, /* i : SPAR MD handle for upmixing */ - const Word16 cross_fade_start_offset, /* i : SPAR mixer delay compensation */ - const Word32 output_Fs, /* i : Fs for delay calculation */ - const Word16 nchan_transport, /* i : number of transpor channels */ - const Word16 num_md_sub_frames /* i : number of MD subframes */ + STEREO_DFT_DEC_DATA_HANDLE hStereoDft, /* i/o: decoder DFT stereo handle */ + Decoder_State *st0, /* i/o: decoder state structure */ + Word32 DFT[CPE_CHANNELS][STEREO_DFT_BUF_MAX], /* i/o: DFT buffers qDFT*/ + Word32 *input_mem, /* i/o: mem of buffer DFT analysis */ + STEREO_CNG_DEC_HANDLE hStereoCng, /* i/o: Stereo CNG data structure Q0*/ + const Word16 sba_dirac_stereo_flag, /* i : signal stereo output for SBA DirAC Q0*/ + const Word16 sba_mono_flag, /* i : signal mono output for SBA DirAC Q0*/ + ivas_spar_md_dec_state_t *hMdDec, /* i : SPAR MD handle for upmixing */ + const Word16 cross_fade_start_offset, /* i : SPAR mixer delay compensation Q0*/ + const Word32 output_Fs, /* i : Fs for delay calculation Q0*/ + const Word16 nchan_transport, /* i : number of transpor channels Q0*/ + const Word16 num_md_sub_frames /* i : number of MD subframes Q0*/ ) { Word16 i, k, b, N_div, stop; @@ -1521,7 +1524,7 @@ void stereo_dft_dec_fx( Word16 q_samp_ratio = Q15; move16(); - output_frame = (Word16) Mpy_32_32( L_add( st0->output_Fs, FRAMES_PER_SEC_BY_2 ), ONE_BY_FRAMES_PER_SEC_Q31 ); + output_frame = (Word16) Mpy_32_32( L_add( st0->output_Fs, FRAMES_PER_SEC_BY_2 ), ONE_BY_FRAMES_PER_SEC_Q31 ); /* Q0 */ /*------------------------------------------------------------------* * Initialization @@ -1543,7 +1546,7 @@ void stereo_dft_dec_fx( test(); test(); hStereoDft->trans = (Word16) ( ( EQ_16( st0->clas_dec, ONSET ) || EQ_16( st0->clas_dec, SIN_ONSET ) || EQ_16( st0->clas_dec, UNVOICED_CLAS ) || EQ_16( st0->clas_dec, UNVOICED_TRANSITION ) ) || LE_16( st0->stab_fac_fx, (Word16) 0x2000 ) ) || - ( ( EQ_16( st0->core, TCX_20_CORE ) && ( EQ_16( st0->hTcxCfg->tcx_last_overlap_mode, MIN_OVERLAP ) || EQ_16( st0->hTcxCfg->tcx_last_overlap_mode, HALF_OVERLAP ) ) ) || EQ_16( st0->core, TCX_10_CORE ) ); + ( ( EQ_16( st0->core, TCX_20_CORE ) && ( EQ_16( st0->hTcxCfg->tcx_last_overlap_mode, MIN_OVERLAP ) || EQ_16( st0->hTcxCfg->tcx_last_overlap_mode, HALF_OVERLAP ) ) ) || EQ_16( st0->core, TCX_10_CORE ) ); /* Q0 */ move16(); /* Initialization */ @@ -1558,7 +1561,7 @@ void stereo_dft_dec_fx( test(); IF( LT_16( output_frame, inner_frame_tbl[st0->bwidth] ) && ( sba_dirac_stereo_flag == 0 ) ) { - hStereoDft->nbands = stereo_dft_band_config_fx( hStereoDft->band_limits, hStereoDft->band_res[k_offset], hStereoDft->NFFT, DEC ); + hStereoDft->nbands = stereo_dft_band_config_fx( hStereoDft->band_limits, hStereoDft->band_res[k_offset], hStereoDft->NFFT, DEC ); /* Q0 */ } IF( st0->bfi == 0 ) @@ -1578,19 +1581,19 @@ void stereo_dft_dec_fx( move32(); IF( prev_bfi ) { - dmx_nrg = stereo_dft_dmx_swb_nrg_fx( DFT[0], DFT[0] + STEREO_DFT32MS_N_MAX, s_min( hStereoDft->NFFT, STEREO_DFT32MS_N_32k ), 0, 0 ); + dmx_nrg = stereo_dft_dmx_swb_nrg_fx( DFT[0], DFT[0] + STEREO_DFT32MS_N_MAX, s_min( hStereoDft->NFFT, STEREO_DFT32MS_N_32k ), 0, 0 ); /* Q0 */ } FOR( k = 0; k < N_div; k++ ) { - pDFT_DMX = DFT[0] + i_mult( k, STEREO_DFT32MS_N_MAX ); - pDFT_RES = DFT[1] + i_mult( k, STEREO_DFT32MS_N_MAX ); + pDFT_DMX = DFT[0] + i_mult( k, STEREO_DFT32MS_N_MAX ); /* qDFT */ + pDFT_RES = DFT[1] + i_mult( k, STEREO_DFT32MS_N_MAX ); /* qDFT */ pDFT_DMX1 = 0; move16(); IF( GT_16( nchan_transport, 1 ) ) { - pDFT_DMX1 = DFT[1] + i_mult( k, STEREO_DFT32MS_N_MAX ); + pDFT_DMX1 = DFT[1] + i_mult( k, STEREO_DFT32MS_N_MAX ); /* qDFT */ } /*Apply Stereo*/ @@ -1604,22 +1607,22 @@ void stereo_dft_dec_fx( move16(); /* since delay is just 3.125ms, the parameters received are used for the second window */ - pSideGain = hStereoDft->side_gain_fx + i_mult( add( k, k_offset ), STEREO_DFT_BAND_MAX ); - pgIpd = hStereoDft->gipd_fx + add( k, k_offset ); - pPredGain = hStereoDft->res_pred_gain_fx + i_mult( add( k, k_offset ), STEREO_DFT_BAND_MAX ); + pSideGain = hStereoDft->side_gain_fx + i_mult( add( k, k_offset ), STEREO_DFT_BAND_MAX ); /* Q31 */ + pgIpd = hStereoDft->gipd_fx + add( k, k_offset ); /* Q27 */ + pPredGain = hStereoDft->res_pred_gain_fx + i_mult( add( k, k_offset ), STEREO_DFT_BAND_MAX ); /* Q31 */ /* Use coarse band partition in inactive frames */ test(); IF( hStereoDft->frame_sid_nodata && !sba_dirac_stereo_flag ) { - NFFT_inner = i_mult( ( STEREO_DFT32MS_N_MAX / L_FRAME48k ), inner_frame_tbl[st0->bwidth] ); + NFFT_inner = i_mult( ( STEREO_DFT32MS_N_MAX / L_FRAME48k ), inner_frame_tbl[st0->bwidth] ); /* Q0 */ hStereoDft->nbands = stereo_dft_band_config_fx( hStereoDft->band_limits, 2, NFFT_inner, DEC ); } IF( st0->bfi ) { - hStereoDft->past_DMX_pos = ( hStereoDft->past_DMX_pos + STEREO_DFT_PAST_MAX - 1 ) % STEREO_DFT_PAST_MAX; + hStereoDft->past_DMX_pos = ( sub( add( hStereoDft->past_DMX_pos, STEREO_DFT_PAST_MAX ), 1 ) ) % STEREO_DFT_PAST_MAX; /* Q0 */ } test(); @@ -1634,7 +1637,7 @@ void stereo_dft_dec_fx( { IF( EQ_16( k, 1 ) ) { - Copy32( pDFT_RES, hStereoDft->res_mem_fx, shl( hStereoDft->band_limits[hStereoDft->res_cod_band_max], 1 ) ); + Copy32( pDFT_RES, hStereoDft->res_mem_fx, shl( hStereoDft->band_limits[hStereoDft->res_cod_band_max], 1 ) ); /* qDFT */ hStereoDft->time_offs = 0; move16(); } @@ -1650,16 +1653,16 @@ void stereo_dft_dec_fx( test(); IF( hStereoDft->frame_sid_nodata && !sba_dirac_stereo_flag ) { - DFT_L[0] = pDFT_DMX[0]; + DFT_L[0] = pDFT_DMX[0]; /* qDFT */ move32(); - DFT_R[0] = pDFT_RES[0]; + DFT_R[0] = pDFT_RES[0]; /* qDFT */ move32(); } ELSE { - DFT_L[0] = pDFT_DMX[0]; + DFT_L[0] = pDFT_DMX[0]; /* qDFT */ move32(); - DFT_R[0] = pDFT_DMX[0]; + DFT_R[0] = pDFT_DMX[0]; /* qDFT */ move32(); } @@ -1677,7 +1680,7 @@ void stereo_dft_dec_fx( test(); IF( hStereoDft->frame_sid_nodata && !sba_dirac_stereo_flag ) { - g = hStereoDft->g_state_fx[b]; + g = hStereoDft->g_state_fx[b]; /* Q15 */ move16(); } @@ -1686,11 +1689,11 @@ void stereo_dft_dec_fx( test(); IF( LT_16( hStereoDft->band_limits[b], L_FRAME16k ) && ( hStereoDft->frame_sid_nodata || ( st0->VAD == 0 ) ) ) { - hFdCngDec->cna_nbands = add( b, 1 ); + hFdCngDec->cna_nbands = add( b, 1 ); /* Q0 */ move16(); - hFdCngDec->cna_band_limits[b] = hStereoDft->band_limits[b]; + hFdCngDec->cna_band_limits[b] = hStereoDft->band_limits[b]; /* Q0 */ move16(); - hFdCngDec->cna_g_state_fx[b] = g; + hFdCngDec->cna_g_state_fx[b] = g; /* Q15 */ move16(); } @@ -1715,7 +1718,7 @@ void stereo_dft_dec_fx( { /* Low pass filter coherence */ /* store coherence from inactive frames for later use by the stereo CNA */ - hFdCngDec->cna_cm_fx[b] = hStereoCng->cm_fx[b]; + hFdCngDec->cna_cm_fx[b] = hStereoCng->cm_fx[b]; /* Q15 */ move16(); /* Calculate gamma */ @@ -1725,9 +1728,9 @@ void stereo_dft_dec_fx( Word16 q_loc1, q_loc2; gamma = hStereoCng->cm_fx[b]; move16(); - gamma = BASOP_Util_Divide3232_Scale( gamma, sub( MAX_16, gamma ), &q_loc1 ); + gamma = BASOP_Util_Divide3232_Scale( gamma, sub( MAX_16, gamma ), &q_loc1 ); /* q_loc1 */ l_gamma = L_deposit_l( gamma ); - op1 = L_add( l_gamma, L_shr( L_deposit_l( sub( MAX_16, mult( g, g ) ) ), q_loc1 ) ); + op1 = L_add( l_gamma, L_shr( L_deposit_l( sub( MAX_16, mult( g, g ) ) ), q_loc1 ) ); /* q_loc1 */ q_loc1 = add( Q16, q_loc1 ); q_loc2 = q_loc1; op1 = Sqrt32( op1, &q_loc1 ); @@ -1737,8 +1740,8 @@ void stereo_dft_dec_fx( op2 = L_shl( op2, sub( q_loc2, q_loc1 ) ); q_loc2 = q_loc1; } - gamma = extract_h( L_sub( op1, op2 ) ); - gamma = shl( gamma, q_loc2 ); + gamma = extract_h( L_sub( op1, op2 ) ); /* q_loc1 - 16 */ + gamma = shl( gamma, q_loc2 ); /* 2 * q_loc1 - 16 */ } ELSE { @@ -1749,14 +1752,14 @@ void stereo_dft_dec_fx( FOR( i = hStereoDft->band_limits[b]; i < hStereoDft->band_limits[b + 1]; i++ ) { /* Create L and R signals with the correct coherence by mixing channel 0 (pDFT_DMX) and channel 1 (pDFT_RES) */ - DFT_L[2 * i] = Madd_32_16( Madd_32_16( pDFT_DMX[2 * i], pDFT_DMX[2 * i], g ), pDFT_RES[2 * i], gamma ); + DFT_L[2 * i] = Madd_32_16( Madd_32_16( pDFT_DMX[2 * i], pDFT_DMX[2 * i], g ), pDFT_RES[2 * i], gamma ); /* qDFT */ move32(); - DFT_R[2 * i] = Msub_32_16( Msub_32_16( pDFT_DMX[2 * i], pDFT_DMX[2 * i], g ), pDFT_RES[2 * i], gamma ); + DFT_R[2 * i] = Msub_32_16( Msub_32_16( pDFT_DMX[2 * i], pDFT_DMX[2 * i], g ), pDFT_RES[2 * i], gamma ); /* qDFT */ move32(); - DFT_L[add( shl( i, 1 ), 1 )] = Madd_32_16( Madd_32_16( pDFT_DMX[add( shl( i, 1 ), 1 )], pDFT_DMX[add( shl( i, 1 ), 1 )], g ), pDFT_RES[add( shl( i, 1 ), 1 )], gamma ); + DFT_L[2 * i + 1] = Madd_32_16( Madd_32_16( pDFT_DMX[2 * i + 1], pDFT_DMX[2 * i + 1], g ), pDFT_RES[2 * i + 1], gamma ); /* qDFt */ move32(); - DFT_R[add( shl( i, 1 ), 1 )] = Msub_32_16( Msub_32_16( pDFT_DMX[add( shl( i, 1 ), 1 )], pDFT_DMX[add( shl( i, 1 ), 1 )], g ), pDFT_RES[add( shl( i, 1 ), 1 )], gamma ); + DFT_R[2 * i + 1] = Msub_32_16( Msub_32_16( pDFT_DMX[2 * i + 1], pDFT_DMX[2 * i + 1], g ), pDFT_RES[2 * i + 1], gamma ); /* qDFT */ move32(); } @@ -1765,19 +1768,19 @@ void stereo_dft_dec_fx( Word32 theta = pgIpd[0]; WHILE( GT_32( theta, EVS_2PI_FX_Q27 ) ) { - theta = L_sub( theta, EVS_2PI_FX_Q27 ); + theta = L_sub( theta, EVS_2PI_FX_Q27 ); /* Q27 */ } WHILE( LT_32( theta, -EVS_2PI_FX_Q27 ) ) { - theta = L_add( theta, EVS_2PI_FX_Q27 ); + theta = L_add( theta, EVS_2PI_FX_Q27 ); /* Q27 */ } IF( GT_32( theta, EVS_PI_FX_Q27 ) ) { - theta = L_sub( theta, EVS_2PI_FX_Q27 ); + theta = L_sub( theta, EVS_2PI_FX_Q27 ); /* Q27 */ } ELSE IF( LT_32( theta, -EVS_PI_FX_Q27 ) ) { - theta = L_add( theta, EVS_2PI_FX_Q27 ); + theta = L_add( theta, EVS_2PI_FX_Q27 ); /* Q27 */ } c0 = getCosWord16( (Word16) L_shr( theta, 14 ) ); IF( EQ_16( c0, ONE_IN_Q14 ) ) @@ -1793,10 +1796,10 @@ void stereo_dft_dec_fx( FOR( i = hStereoDft->band_limits[b]; i < hStereoDft->band_limits[b + 1]; i++ ) { /*rotate L*/ - tmp = Msub_32_16( Mpy_32_16_1( DFT_L[2 * i], c0 ), DFT_L[add( shl( i, 1 ), 1 )], s0 ); - DFT_L[add( shl( i, 1 ), 1 )] = Madd_32_16( Mpy_32_16_1( DFT_L[2 * i], s0 ), DFT_L[add( shl( i, 1 ), 1 )], c0 ); + tmp = Msub_32_16( Mpy_32_16_1( DFT_L[2 * i], c0 ), DFT_L[2 * i + 1], s0 ); /* qDFT */ + DFT_L[2 * i + 1] = Madd_32_16( Mpy_32_16_1( DFT_L[2 * i], s0 ), DFT_L[2 * i + 1], c0 ); /* qDFT */ move32(); - DFT_L[2 * i] = tmp; + DFT_L[2 * i] = tmp; /* qDFT */ move32(); } } @@ -1812,53 +1815,53 @@ void stereo_dft_dec_fx( { i = 0; move16(); - DFT_W = Mpy_32_32( hStereoDft->mixer_mat_smooth_fx[0][0][b + k * IVAS_MAX_NUM_BANDS], pDFT_DMX[2 * i] ); + DFT_W = Mpy_32_32( hStereoDft->mixer_mat_smooth_fx[0][0][b + k * IVAS_MAX_NUM_BANDS], pDFT_DMX[2 * i] ); /* qDFT */ move32(); - DFT_L[2 * i] = DFT_W; + DFT_L[2 * i] = DFT_W; /* qDFT */ move32(); DFT_R[2 * i] = 0; move32(); - DFT_W = Mpy_32_32( hStereoDft->mixer_mat_smooth_fx[0][0][b + k * IVAS_MAX_NUM_BANDS], pDFT_DMX[add( shl( i, 1 ), 1 )] ); + DFT_W = Mpy_32_32( hStereoDft->mixer_mat_smooth_fx[0][0][b + k * IVAS_MAX_NUM_BANDS], pDFT_DMX[2 * i + 1] ); /* qDFT */ move32(); - DFT_L[add( shl( i, 1 ), 1 )] = DFT_W; + DFT_L[2 * i + 1] = DFT_W; /* qDFT */ move32(); - DFT_R[add( shl( i, 1 ), 1 )] = 0; + DFT_R[2 * i + 1] = 0; move32(); } FOR( i = hStereoDft->band_limits[b]; i < s_min( stop, hStereoDft->band_limits[b + 1] ); i++ ) { - DFT_W = Madd_32_32( Mpy_32_32( hStereoDft->mixer_mat_smooth_fx[0][0][add( b, i_mult( k, IVAS_MAX_NUM_BANDS ) )], pDFT_DMX[2 * i] ), - L_add( hStereoDft->mixer_mat_smooth_fx[0][1][add( b, i_mult( k, IVAS_MAX_NUM_BANDS ) )], - L_add( hStereoDft->mixer_mat_smooth_fx[0][2][add( b, i_mult( k, IVAS_MAX_NUM_BANDS ) )], - hStereoDft->mixer_mat_smooth_fx[0][3][add( b, i_mult( k, IVAS_MAX_NUM_BANDS ) )] ) ), - DFT_PRED_RES[2 * i] ); - DFT_L[2 * i] = DFT_W; + DFT_W = Madd_32_32( Mpy_32_32( hStereoDft->mixer_mat_smooth_fx[0][0][b + k * IVAS_MAX_NUM_BANDS], pDFT_DMX[2 * i] ), + L_add( hStereoDft->mixer_mat_smooth_fx[0][1][b + k * IVAS_MAX_NUM_BANDS], + L_add( hStereoDft->mixer_mat_smooth_fx[0][2][b + k * IVAS_MAX_NUM_BANDS], + hStereoDft->mixer_mat_smooth_fx[0][3][b + k * IVAS_MAX_NUM_BANDS] ) ), + DFT_PRED_RES[2 * i] ); /* qDFT */ + DFT_L[2 * i] = DFT_W; /* qDFT */ move32(); DFT_R[2 * i] = 0; move32(); - DFT_W = Madd_32_32( Mpy_32_32( hStereoDft->mixer_mat_smooth_fx[0][0][add( b, i_mult( k, IVAS_MAX_NUM_BANDS ) )], pDFT_DMX[add( shl( i, 1 ), 1 )] ), - L_add( hStereoDft->mixer_mat_smooth_fx[0][1][add( b, i_mult( k, IVAS_MAX_NUM_BANDS ) )], - L_add( hStereoDft->mixer_mat_smooth_fx[0][2][add( b, i_mult( k, IVAS_MAX_NUM_BANDS ) )], - hStereoDft->mixer_mat_smooth_fx[0][3][add( b, i_mult( k, IVAS_MAX_NUM_BANDS ) )] ) ), - DFT_PRED_RES[add( shl( i, 1 ), 1 )] ); - DFT_L[add( shl( i, 1 ), 1 )] = DFT_W; + DFT_W = Madd_32_32( Mpy_32_32( hStereoDft->mixer_mat_smooth_fx[0][0][b + k * IVAS_MAX_NUM_BANDS], pDFT_DMX[2 * i + 1] ), + L_add( hStereoDft->mixer_mat_smooth_fx[0][1][b + k * IVAS_MAX_NUM_BANDS], + L_add( hStereoDft->mixer_mat_smooth_fx[0][2][b + k * IVAS_MAX_NUM_BANDS], + hStereoDft->mixer_mat_smooth_fx[0][3][b + k * IVAS_MAX_NUM_BANDS] ) ), + DFT_PRED_RES[2 * i + 1] ); /* qDFT */ + DFT_L[2 * i + 1] = DFT_W; /* qDFT */ move32(); - DFT_R[add( shl( i, 1 ), 1 )] = 0; + DFT_R[2 * i + 1] = 0; move32(); } FOR( ; i < hStereoDft->band_limits[b + 1]; i++ ) { - DFT_W = Mpy_32_32( hStereoDft->mixer_mat_smooth_fx[0][0][add( b, i_mult( k, IVAS_MAX_NUM_BANDS ) )], pDFT_DMX[2 * i] ); - DFT_L[2 * i] = DFT_W; + DFT_W = Mpy_32_32( hStereoDft->mixer_mat_smooth_fx[0][0][b + k * IVAS_MAX_NUM_BANDS], pDFT_DMX[2 * i] ); /* qDFT */ + DFT_L[2 * i] = DFT_W; /* qDFT */ move32(); DFT_R[2 * i] = 0; move32(); - DFT_W = Mpy_32_32( hStereoDft->mixer_mat_smooth_fx[0][0][add( b, i_mult( k, IVAS_MAX_NUM_BANDS ) )], pDFT_DMX[add( shl( i, 1 ), 1 )] ); - DFT_L[add( shl( i, 1 ), 1 )] = DFT_W; + DFT_W = Mpy_32_32( hStereoDft->mixer_mat_smooth_fx[0][0][b + k * IVAS_MAX_NUM_BANDS], pDFT_DMX[2 * i + 1] ); /* qDFT */ + DFT_L[2 * i + 1] = DFT_W; /* qDFT */ move32(); - DFT_R[add( shl( i, 1 ), 1 )] = 0; + DFT_R[2 * i + 1] = 0; move32(); } } @@ -1868,72 +1871,72 @@ void stereo_dft_dec_fx( { i = 0; move16(); - DFT_W = Mpy_32_32( hStereoDft->mixer_mat_smooth_fx[0][0][add( b, i_mult( k, IVAS_MAX_NUM_BANDS ) )], pDFT_DMX[2 * i] ); - DFT_Y = Mpy_32_32( hStereoDft->mixer_mat_smooth_fx[1][0][add( b, i_mult( k, IVAS_MAX_NUM_BANDS ) )], pDFT_DMX[2 * i] ); + DFT_W = Mpy_32_32( hStereoDft->mixer_mat_smooth_fx[0][0][b + k * IVAS_MAX_NUM_BANDS], pDFT_DMX[2 * i] ); /* qDFT */ + DFT_Y = Mpy_32_32( hStereoDft->mixer_mat_smooth_fx[1][0][b + k * IVAS_MAX_NUM_BANDS], pDFT_DMX[2 * i] ); /* qDFT */ - DFT_L[2 * i] = L_add( DFT_W, DFT_Y ); + DFT_L[2 * i] = L_add( DFT_W, DFT_Y ); /* qDFT */ move32(); - DFT_R[2 * i] = L_sub( DFT_W, DFT_Y ); + DFT_R[2 * i] = L_sub( DFT_W, DFT_Y ); /* qDFT */ move32(); - DFT_W = Mpy_32_32( hStereoDft->mixer_mat_smooth_fx[0][0][add( b, i_mult( k, IVAS_MAX_NUM_BANDS ) )], pDFT_DMX[add( shl( i, 1 ), 1 )] ); - DFT_Y = Mpy_32_32( hStereoDft->mixer_mat_smooth_fx[1][0][add( b, i_mult( k, IVAS_MAX_NUM_BANDS ) )], pDFT_DMX[add( shl( i, 1 ), 1 )] ); + DFT_W = Mpy_32_32( hStereoDft->mixer_mat_smooth_fx[0][0][b + k * IVAS_MAX_NUM_BANDS], pDFT_DMX[2 * i + 1] ); /* qDFT */ + DFT_Y = Mpy_32_32( hStereoDft->mixer_mat_smooth_fx[1][0][b + k * IVAS_MAX_NUM_BANDS], pDFT_DMX[2 * i + 1] ); /* qDFT */ - DFT_L[2 * i + 1] = L_add( DFT_W, DFT_Y ); + DFT_L[2 * i + 1] = L_add( DFT_W, DFT_Y ); /* qDFT */ move32(); - DFT_R[2 * i + 1] = L_sub( DFT_W, DFT_Y ); + DFT_R[2 * i + 1] = L_sub( DFT_W, DFT_Y ); /* qDFT */ move32(); } FOR( i = hStereoDft->band_limits[b]; i < min( stop, hStereoDft->band_limits[b + 1] ); i++ ) { - DFT_W = Madd_32_32( Mpy_32_32( hStereoDft->mixer_mat_smooth_fx[0][0][add( b, i_mult( k, IVAS_MAX_NUM_BANDS ) )], pDFT_DMX[2 * i] ), - L_add( hStereoDft->mixer_mat_smooth_fx[0][1][add( b, i_mult( k, IVAS_MAX_NUM_BANDS ) )], - L_add( hStereoDft->mixer_mat_smooth_fx[0][2][add( b, i_mult( k, IVAS_MAX_NUM_BANDS ) )], - hStereoDft->mixer_mat_smooth_fx[0][3][add( b, i_mult( k, IVAS_MAX_NUM_BANDS ) )] ) ), - DFT_PRED_RES[2 * i] ); - DFT_Y = Madd_32_32( Mpy_32_32( hStereoDft->mixer_mat_smooth_fx[1][0][add( b, i_mult( k, IVAS_MAX_NUM_BANDS ) )], pDFT_DMX[2 * i] ), - L_add( hStereoDft->mixer_mat_smooth_fx[1][1][add( b, i_mult( k, IVAS_MAX_NUM_BANDS ) )], - L_add( hStereoDft->mixer_mat_smooth_fx[1][2][add( b, i_mult( k, IVAS_MAX_NUM_BANDS ) )], - hStereoDft->mixer_mat_smooth_fx[1][3][add( b, i_mult( k, IVAS_MAX_NUM_BANDS ) )] ) ), - DFT_PRED_RES[2 * i] ); - - DFT_L[2 * i] = L_add( DFT_W, DFT_Y ); + DFT_W = Madd_32_32( Mpy_32_32( hStereoDft->mixer_mat_smooth_fx[0][0][b + k * IVAS_MAX_NUM_BANDS], pDFT_DMX[2 * i] ), + L_add( hStereoDft->mixer_mat_smooth_fx[0][1][b + k * IVAS_MAX_NUM_BANDS], + L_add( hStereoDft->mixer_mat_smooth_fx[0][2][b + k * IVAS_MAX_NUM_BANDS], + hStereoDft->mixer_mat_smooth_fx[0][3][b + k * IVAS_MAX_NUM_BANDS] ) ), + DFT_PRED_RES[2 * i] ); /* qDFT */ + DFT_Y = Madd_32_32( Mpy_32_32( hStereoDft->mixer_mat_smooth_fx[1][0][b + k * IVAS_MAX_NUM_BANDS], pDFT_DMX[2 * i] ), + L_add( hStereoDft->mixer_mat_smooth_fx[1][1][b + k * IVAS_MAX_NUM_BANDS], + L_add( hStereoDft->mixer_mat_smooth_fx[1][2][b + k * IVAS_MAX_NUM_BANDS], + hStereoDft->mixer_mat_smooth_fx[1][3][b + k * IVAS_MAX_NUM_BANDS] ) ), + DFT_PRED_RES[2 * i] ); /* qDFT */ + + DFT_L[2 * i] = L_add( DFT_W, DFT_Y ); /* qDFT */ move32(); - DFT_R[2 * i] = L_sub( DFT_W, DFT_Y ); + DFT_R[2 * i] = L_sub( DFT_W, DFT_Y ); /* qDFT */ move32(); - DFT_W = Madd_32_32( Mpy_32_32( hStereoDft->mixer_mat_smooth_fx[0][0][add( b, i_mult( k, IVAS_MAX_NUM_BANDS ) )], pDFT_DMX[add( shl( i, 1 ), 1 )] ), - L_add( hStereoDft->mixer_mat_smooth_fx[0][1][add( b, i_mult( k, IVAS_MAX_NUM_BANDS ) )], - L_add( hStereoDft->mixer_mat_smooth_fx[0][2][add( b, i_mult( k, IVAS_MAX_NUM_BANDS ) )], - hStereoDft->mixer_mat_smooth_fx[0][3][add( b, i_mult( k, IVAS_MAX_NUM_BANDS ) )] ) ), - DFT_PRED_RES[add( shl( i, 1 ), 1 )] ); - DFT_Y = Madd_32_32( Mpy_32_32( hStereoDft->mixer_mat_smooth_fx[1][0][add( b, i_mult( k, IVAS_MAX_NUM_BANDS ) )], pDFT_DMX[add( shl( i, 1 ), 1 )] ), - L_add( hStereoDft->mixer_mat_smooth_fx[1][1][add( b, i_mult( k, IVAS_MAX_NUM_BANDS ) )], - L_add( hStereoDft->mixer_mat_smooth_fx[1][2][add( b, i_mult( k, IVAS_MAX_NUM_BANDS ) )], - hStereoDft->mixer_mat_smooth_fx[1][3][add( b, i_mult( k, IVAS_MAX_NUM_BANDS ) )] ) ), - DFT_PRED_RES[add( shl( i, 1 ), 1 )] ); - - DFT_L[add( shl( i, 1 ), 1 )] = L_add( DFT_W, DFT_Y ); + DFT_W = Madd_32_32( Mpy_32_32( hStereoDft->mixer_mat_smooth_fx[0][0][b + k * IVAS_MAX_NUM_BANDS], pDFT_DMX[2 * i + 1] ), + L_add( hStereoDft->mixer_mat_smooth_fx[0][1][b + k * IVAS_MAX_NUM_BANDS], + L_add( hStereoDft->mixer_mat_smooth_fx[0][2][b + k * IVAS_MAX_NUM_BANDS], + hStereoDft->mixer_mat_smooth_fx[0][3][b + k * IVAS_MAX_NUM_BANDS] ) ), + DFT_PRED_RES[2 * i + 1] ); /* qDFT */ + DFT_Y = Madd_32_32( Mpy_32_32( hStereoDft->mixer_mat_smooth_fx[1][0][b + k * IVAS_MAX_NUM_BANDS], pDFT_DMX[2 * i + 1] ), + L_add( hStereoDft->mixer_mat_smooth_fx[1][1][b + k * IVAS_MAX_NUM_BANDS], + L_add( hStereoDft->mixer_mat_smooth_fx[1][2][b + k * IVAS_MAX_NUM_BANDS], + hStereoDft->mixer_mat_smooth_fx[1][3][b + k * IVAS_MAX_NUM_BANDS] ) ), + DFT_PRED_RES[2 * i + 1] ); /* qDFT */ + + DFT_L[2 * i + 1] = L_add( DFT_W, DFT_Y ); /* qDFT */ move32(); - DFT_R[add( shl( i, 1 ), 1 )] = L_sub( DFT_W, DFT_Y ); + DFT_R[2 * i + 1] = L_sub( DFT_W, DFT_Y ); /* qDFT */ move32(); } FOR( ; i < hStereoDft->band_limits[b + 1]; i++ ) { - DFT_W = Mpy_32_32( hStereoDft->mixer_mat_smooth_fx[0][0][add( b, i_mult( k, IVAS_MAX_NUM_BANDS ) )], pDFT_DMX[2 * i] ); - DFT_Y = Mpy_32_32( hStereoDft->mixer_mat_smooth_fx[1][0][add( b, i_mult( k, IVAS_MAX_NUM_BANDS ) )], pDFT_DMX[2 * i] ); + DFT_W = Mpy_32_32( hStereoDft->mixer_mat_smooth_fx[0][0][b + k * IVAS_MAX_NUM_BANDS], pDFT_DMX[2 * i] ); /* qDFT */ + DFT_Y = Mpy_32_32( hStereoDft->mixer_mat_smooth_fx[1][0][b + k * IVAS_MAX_NUM_BANDS], pDFT_DMX[2 * i] ); /* qDFT */ - DFT_L[2 * i] = L_add( DFT_W, DFT_Y ); + DFT_L[2 * i] = L_add( DFT_W, DFT_Y ); /* qDFT */ move32(); - DFT_R[2 * i] = L_sub( DFT_W, DFT_Y ); + DFT_R[2 * i] = L_sub( DFT_W, DFT_Y ); /* qDFT */ move32(); - DFT_W = Mpy_32_32( hStereoDft->mixer_mat_smooth_fx[0][0][add( b, i_mult( k, IVAS_MAX_NUM_BANDS ) )], pDFT_DMX[add( shl( i, 1 ), 1 )] ); - DFT_Y = Mpy_32_32( hStereoDft->mixer_mat_smooth_fx[1][0][add( b, i_mult( k, IVAS_MAX_NUM_BANDS ) )], pDFT_DMX[add( shl( i, 1 ), 1 )] ); + DFT_W = Mpy_32_32( hStereoDft->mixer_mat_smooth_fx[0][0][b + k * IVAS_MAX_NUM_BANDS], pDFT_DMX[2 * i + 1] ); /* qDFT */ + DFT_Y = Mpy_32_32( hStereoDft->mixer_mat_smooth_fx[1][0][b + k * IVAS_MAX_NUM_BANDS], pDFT_DMX[2 * i + 1] ); /* qDFT */ - DFT_L[add( shl( i, 1 ), 1 )] = L_add( DFT_W, DFT_Y ); + DFT_L[2 * i + 1] = L_add( DFT_W, DFT_Y ); /* qDFT */ move32(); - DFT_R[add( shl( i, 1 ), 1 )] = L_sub( DFT_W, DFT_Y ); + DFT_R[2 * i + 1] = L_sub( DFT_W, DFT_Y ); /* qDFT */ move32(); } } @@ -1945,42 +1948,42 @@ void stereo_dft_dec_fx( i = 0; move32(); - DFT_W = pDFT_DMX[2 * i]; + DFT_W = pDFT_DMX[2 * i]; /* qDFT */ move32(); - DFT_Y = Madd_32_32( pDFT_DMX1[2 * i], hStereoDft->mixer_mat_smooth_fx[1][0][add( b, i_mult( k, IVAS_MAX_NUM_BANDS ) )], pDFT_DMX[2 * i] ); + DFT_Y = Madd_32_32( pDFT_DMX1[2 * i], hStereoDft->mixer_mat_smooth_fx[1][0][b + k * IVAS_MAX_NUM_BANDS], pDFT_DMX[2 * i] ); /* qDFT */ - DFT_L[2 * i] = L_add( DFT_W, DFT_Y ); + DFT_L[2 * i] = L_add( DFT_W, DFT_Y ); /* qDFT */ move32(); - DFT_R[2 * i] = L_sub( DFT_W, DFT_Y ); + DFT_R[2 * i] = L_sub( DFT_W, DFT_Y ); /* qDFT */ move32(); - DFT_W = pDFT_DMX[add( shl( i, 1 ), 1 )]; + DFT_W = pDFT_DMX[2 * i + 1]; /* qDFT */ move32(); - DFT_Y = Madd_32_32( pDFT_DMX1[add( shl( i, 1 ), 1 )], hStereoDft->mixer_mat_smooth_fx[1][0][add( b, i_mult( k, IVAS_MAX_NUM_BANDS ) )], pDFT_DMX[add( shl( i, 1 ), 1 )] ); + DFT_Y = Madd_32_32( pDFT_DMX1[2 * i + 1], hStereoDft->mixer_mat_smooth_fx[1][0][b + k * IVAS_MAX_NUM_BANDS], pDFT_DMX[2 * i + 1] ); /* qDFT */ - DFT_L[add( shl( i, 1 ), 1 )] = L_add( DFT_W, DFT_Y ); + DFT_L[2 * i + 1] = L_add( DFT_W, DFT_Y ); /* qDFT */ move32(); - DFT_R[add( shl( i, 1 ), 1 )] = L_sub( DFT_W, DFT_Y ); + DFT_R[2 * i + 1] = L_sub( DFT_W, DFT_Y ); /* qDFT */ move32(); } FOR( i = hStereoDft->band_limits[b]; i < hStereoDft->band_limits[b + 1]; i++ ) { - DFT_W = pDFT_DMX[2 * i]; + DFT_W = pDFT_DMX[2 * i]; /* qDFT */ move32(); - DFT_Y = Madd_32_32( pDFT_DMX1[2 * i], hStereoDft->mixer_mat_smooth_fx[1][0][add( b, i_mult( k, IVAS_MAX_NUM_BANDS ) )], pDFT_DMX[2 * i] ); + DFT_Y = Madd_32_32( pDFT_DMX1[2 * i], hStereoDft->mixer_mat_smooth_fx[1][0][b + k * IVAS_MAX_NUM_BANDS], pDFT_DMX[2 * i] ); /* qDFT */ - DFT_L[2 * i] = L_add( DFT_W, DFT_Y ); + DFT_L[2 * i] = L_add( DFT_W, DFT_Y ); /* qDFT */ move32(); - DFT_R[2 * i] = L_sub( DFT_W, DFT_Y ); + DFT_R[2 * i] = L_sub( DFT_W, DFT_Y ); /* qDFT */ move32(); - DFT_W = pDFT_DMX[add( shl( i, 1 ), 1 )]; + DFT_W = pDFT_DMX[2 * i + 1]; /* qDFT */ move32(); - DFT_Y = Madd_32_32( pDFT_DMX1[add( shl( i, 1 ), 1 )], hStereoDft->mixer_mat_smooth_fx[1][0][add( b, i_mult( k, IVAS_MAX_NUM_BANDS ) )], pDFT_DMX[add( shl( i, 1 ), 1 )] ); + DFT_Y = Madd_32_32( pDFT_DMX1[2 * i + 1], hStereoDft->mixer_mat_smooth_fx[1][0][b + k * IVAS_MAX_NUM_BANDS], pDFT_DMX[2 * i + 1] ); /* qDFT */ - DFT_L[add( shl( i, 1 ), 1 )] = L_add( DFT_W, DFT_Y ); + DFT_L[2 * i + 1] = L_add( DFT_W, DFT_Y ); /* qDFT */ move32(); - DFT_R[add( shl( i, 1 ), 1 )] = L_sub( DFT_W, DFT_Y ); + DFT_R[2 * i + 1] = L_sub( DFT_W, DFT_Y ); /* qDFT */ move32(); } } @@ -1991,37 +1994,37 @@ void stereo_dft_dec_fx( } ELSE { - FOR( i = hStereoDft->band_limits[b]; i < s_min( stop, hStereoDft->band_limits[b + 1] ); i++ ) + FOR( i = hStereoDft->band_limits[b]; i < min( stop, hStereoDft->band_limits[b + 1] ); i++ ) { - tmp = L_add( Madd_32_16( pDFT_RES[2 * i], pDFT_DMX[2 * i], g ), DFT_PRED_RES[2 * i] ); + tmp = L_add( Madd_32_16( pDFT_RES[2 * i], pDFT_DMX[2 * i], g ), DFT_PRED_RES[2 * i] ); /* qDFT */ - DFT_L[2 * i] = L_add( pDFT_DMX[2 * i], tmp ); + DFT_L[2 * i] = L_add( pDFT_DMX[2 * i], tmp ); /* qDFT */ move32(); - DFT_R[2 * i] = L_sub( pDFT_DMX[2 * i], tmp ); + DFT_R[2 * i] = L_sub( pDFT_DMX[2 * i], tmp ); /* qDFT */ move32(); - tmp = L_add( Madd_32_16( pDFT_RES[add( shl( i, 1 ), 1 )], pDFT_DMX[add( shl( i, 1 ), 1 )], g ), DFT_PRED_RES[add( shl( i, 1 ), 1 )] ); + tmp = L_add( Madd_32_16( pDFT_RES[2 * i + 1], pDFT_DMX[2 * i + 1], g ), DFT_PRED_RES[2 * i + 1] ); /* qDFT */ - DFT_L[add( shl( i, 1 ), 1 )] = L_add( pDFT_DMX[add( shl( i, 1 ), 1 )], tmp ); + DFT_L[2 * i + 1] = L_add( pDFT_DMX[2 * i + 1], tmp ); /* qDFT */ move32(); - DFT_R[add( shl( i, 1 ), 1 )] = L_sub( pDFT_DMX[add( shl( i, 1 ), 1 )], tmp ); + DFT_R[2 * i + 1] = L_sub( pDFT_DMX[2 * i + 1], tmp ); /* qDFT */ move32(); } FOR( ; i < hStereoDft->band_limits[b + 1]; i++ ) { - tmp = Madd_32_16( pDFT_RES[2 * i], pDFT_DMX[2 * i], g ); + tmp = Madd_32_16( pDFT_RES[2 * i], pDFT_DMX[2 * i], g ); /* qDFT */ - DFT_L[2 * i] = L_add( pDFT_DMX[2 * i], tmp ); + DFT_L[2 * i] = L_add( pDFT_DMX[2 * i], tmp ); /* qDFT */ move32(); - DFT_R[2 * i] = L_sub( pDFT_DMX[2 * i], tmp ); + DFT_R[2 * i] = L_sub( pDFT_DMX[2 * i], tmp ); /* qDFT */ move32(); - tmp = Madd_32_16( pDFT_RES[2 * i + 1], pDFT_DMX[2 * i + 1], g ); + tmp = Madd_32_16( pDFT_RES[2 * i + 1], pDFT_DMX[2 * i + 1], g ); /* qDFT */ - DFT_L[add( shl( i, 1 ), 1 )] = L_add( pDFT_DMX[add( shl( i, 1 ), 1 )], tmp ); + DFT_L[2 * i + 1] = L_add( pDFT_DMX[2 * i + 1], tmp ); /* qDFT */ move32(); - DFT_R[add( shl( i, 1 ), 1 )] = L_sub( pDFT_DMX[add( shl( i, 1 ), 1 )], tmp ); + DFT_R[2 * i + 1] = L_sub( pDFT_DMX[2 * i + 1], tmp ); /* qDFT */ move32(); } @@ -2032,19 +2035,19 @@ void stereo_dft_dec_fx( move32(); WHILE( GT_32( theta, EVS_2PI_FX_Q27 ) ) { - theta = L_sub( theta, EVS_2PI_FX_Q27 ); + theta = L_sub( theta, EVS_2PI_FX_Q27 ); /* Q27 */ } WHILE( LT_32( theta, -EVS_2PI_FX_Q27 ) ) { - theta = L_add( theta, EVS_2PI_FX_Q27 ); + theta = L_add( theta, EVS_2PI_FX_Q27 ); /* Q27 */ } IF( GT_32( theta, EVS_PI_FX_Q27 ) ) { - theta = L_sub( theta, EVS_2PI_FX_Q27 ); + theta = L_sub( theta, EVS_2PI_FX_Q27 ); /* Q27 */ } ELSE IF( LT_32( theta, -EVS_PI_FX_Q27 ) ) { - theta = L_add( theta, EVS_2PI_FX_Q27 ); + theta = L_add( theta, EVS_2PI_FX_Q27 ); /* Q27 */ } c0 = getCosWord16( (Word16) L_shr( theta, 14 ) ); IF( EQ_16( c0, ONE_IN_Q14 ) ) @@ -2060,10 +2063,10 @@ void stereo_dft_dec_fx( FOR( i = hStereoDft->band_limits[b]; i < hStereoDft->band_limits[b + 1]; i++ ) { /*rotate L*/ - tmp = Msub_32_16( Mpy_32_16_1( DFT_L[2 * i], c0 ), DFT_L[add( shl( i, 1 ), 1 )], s0 ); - DFT_L[add( shl( i, 1 ), 1 )] = Madd_32_16( Mpy_32_16_1( DFT_L[2 * i], s0 ), DFT_L[add( shl( i, 1 ), 1 )], c0 ); + tmp = Msub_32_16( Mpy_32_16_1( DFT_L[2 * i], c0 ), DFT_L[2 * i + 1], s0 ); /* qDFT */ + DFT_L[2 * i + 1] = Madd_32_16( Mpy_32_16_1( DFT_L[2 * i], s0 ), DFT_L[2 * i + 1], c0 ); /* qDFT */ move32(); - DFT_L[2 * i] = tmp; + DFT_L[2 * i] = tmp; /* qDFT */ move32(); } } @@ -2073,7 +2076,7 @@ void stereo_dft_dec_fx( test(); if ( hStereoDft->frame_sid_nodata || ( st0->VAD == 0 ) ) { - hFdCngDec->cna_band_limits[hFdCngDec->cna_nbands] = hStereoDft->band_limits[hFdCngDec->cna_nbands]; + hFdCngDec->cna_band_limits[hFdCngDec->cna_nbands] = hStereoDft->band_limits[hFdCngDec->cna_nbands]; /* Q0 */ move16(); } @@ -2086,7 +2089,7 @@ void stereo_dft_dec_fx( move16(); } - FOR( i = hStereoDft->band_limits[b]; i < shr( hStereoDft->NFFT, 1 ); i++ ) + FOR( i = hStereoDft->band_limits[b]; i < hStereoDft->NFFT / 2; i++ ) { DFT_L[2 * i] = 0; move32(); @@ -2101,13 +2104,13 @@ void stereo_dft_dec_fx( /*Nyquist Freq.*/ IF( EQ_16( hStereoDft->band_limits[b], shr( hStereoDft->NFFT, 1 ) ) ) { - DFT_L[1] = L_add( pDFT_DMX[1], Mpy_32_16_1( pDFT_DMX[1], g ) ); + DFT_L[1] = L_add( pDFT_DMX[1], Mpy_32_16_1( pDFT_DMX[1], g ) ); /* qDFT */ move32(); - DFT_R[1] = L_sub( pDFT_DMX[1], Mpy_32_16_1( pDFT_DMX[1], g ) ); + DFT_R[1] = L_sub( pDFT_DMX[1], Mpy_32_16_1( pDFT_DMX[1], g ) ); /* qDFT */ move32(); - DFT_L[1] = Mpy_32_16_1( DFT_L[1], INV_SQRT2_FX_Q15 ); + DFT_L[1] = Mpy_32_16_1( DFT_L[1], INV_SQRT2_FX_Q15 ); /* qDFT */ move32(); - DFT_R[1] = Mpy_32_16_1( DFT_R[1], INV_SQRT2_FX_Q15 ); + DFT_R[1] = Mpy_32_16_1( DFT_R[1], INV_SQRT2_FX_Q15 ); /* qDFT */ move32(); } ELSE @@ -2126,9 +2129,9 @@ void stereo_dft_dec_fx( /* Dummy upmix-> mono binauralization */ FOR( i = 0; i < hStereoDft->NFFT; i++ ) { - DFT_L[i] = L_add( pDFT_DMX[i], pDFT_RES[i] ); + DFT_L[i] = L_add( pDFT_DMX[i], pDFT_RES[i] ); /* qDFT */ move32(); - DFT_R[i] = L_sub( pDFT_DMX[i], pDFT_RES[i] ); + DFT_R[i] = L_sub( pDFT_DMX[i], pDFT_RES[i] ); /* qDFT */ move32(); } } @@ -2136,7 +2139,7 @@ void stereo_dft_dec_fx( /* Comfort Noise Addition */ IF( st0->flag_cna ) { - ptr_per = &hFdCngDec->smoothed_psd_fx[hFdCngCom->startBand]; + ptr_per = &hFdCngDec->smoothed_psd_fx[hFdCngCom->startBand]; /* hFdCngDec->smoothed_psd_exp */ scale_fact0 = 0; move16(); @@ -2188,16 +2191,16 @@ void stereo_dft_dec_fx( { IF( NE_16( q_loc1, q_loc2 ) ) { - op2 = L_shl( op2, sub( q_loc2, q_loc1 ) ); + op2 = L_shl( op2, sub( q_loc2, q_loc1 ) ); /* qloc2 */ q_loc2 = q_loc1; move16(); } - gamma = extract_h( L_sub( op1, op2 ) ); - gamma = shl( gamma, q_loc2 ); + gamma = extract_h( L_sub( op1, op2 ) ); /* qloc2 - 16 */ + gamma = shl( gamma, q_loc2 ); /* 2 * qloc2 - 16 */ } ELSE { - gamma = extract_h( L_shl( op1, q_loc1 ) ); + gamma = extract_h( L_shl( op1, q_loc1 ) ); /* 2 * qloc2 - 16 */ } } ELSE @@ -2206,7 +2209,7 @@ void stereo_dft_dec_fx( move16(); } - FOR( i = s_max( hFdCngDec->cna_band_limits[b], shr( hFdCngCom->startBand, 1 ) ); i < s_min( hFdCngDec->cna_band_limits[b + 1], ( L_FRAME16k ) >> 1 ); i++ ) + FOR( i = max( hFdCngDec->cna_band_limits[b], ( hFdCngCom->startBand / 2 ) ); i < min( hFdCngDec->cna_band_limits[b + 1], ( L_FRAME16k ) >> 1 ); i++ ) { Word32 l_tmp; lev1 = *ptr_per++; @@ -2219,17 +2222,17 @@ void stereo_dft_dec_fx( IF( ( lev1 > 0 ) && ( lev2 > 0 ) && GT_32( Mpy_32_16_1( L_max( lev1, lev2 ), (Word16) 0x6AAB ), L_min( lev1, lev2 ) ) ) { /* take the minimum of two adjacent frequency bins */ - cna_level = L_min( lev1, lev2 ); + cna_level = L_min( lev1, lev2 ); /* hFdCngDec->smoothed_psd_exp */ } ELSE { /* take the average of two adjacent frequency bins */ - cna_level = L_add( L_shr( lev1, 1 ), L_shr( lev2, 1 ) ); + cna_level = L_add( L_shr( lev1, 1 ), L_shr( lev2, 1 ) ); /* hFdCngDec->smoothed_psd_exp */ } q_cna_level = hFdCngDec->smoothed_psd_exp; move16(); l_tmp = Sqrt32( cna_level, &q_cna_level ); - scale_fact = Mpy_32_32( l_tmp, scale_fact0 ); + scale_fact = Mpy_32_32( l_tmp, scale_fact0 ); /* q_cna_level */ /* scale_fact0 will be in Q15 by the time the above operation is performed so the q of scale_fact represented now by q_cna_level has to be updated @@ -2237,32 +2240,32 @@ void stereo_dft_dec_fx( q_cna_level = sub( Q31, add( q_cna_level, Q16 ) ); /* generate comfort noise from gaussian noise and add to the decoded DFT spectrum */ - N1 = L_shl( Mpy_32_16_1( scale_fact, rand_gauss_fix( &ftmp, cna_seed ) ), Q2 ); - N2 = L_shl( Mpy_32_16_1( scale_fact, rand_gauss_fix( &ftmp, cna_seed ) ), Q2 ); - l_tmp = L_add( Madd_32_16( N1, N1, g ), Mpy_32_16_1( N2, gamma ) ); - l_tmp = L_shr( l_tmp, sub( q_cna_level, hStereoDft->q_dft ) ); - DFT_L[2 * i] = L_add( DFT_L[2 * i], l_tmp ); + N1 = L_shl( Mpy_32_16_1( scale_fact, rand_gauss_fix( &ftmp, cna_seed ) ), Q2 ); /* q_cna_level */ + N2 = L_shl( Mpy_32_16_1( scale_fact, rand_gauss_fix( &ftmp, cna_seed ) ), Q2 ); /* q_cna_level */ + l_tmp = L_add( Madd_32_16( N1, N1, g ), Mpy_32_16_1( N2, gamma ) ); /* q_cna_level */ + l_tmp = L_shr( l_tmp, sub( q_cna_level, hStereoDft->q_dft ) ); /* q_dft */ + DFT_L[2 * i] = L_add( DFT_L[2 * i], l_tmp ); /* q_dft */ move32(); - l_tmp = L_sub( Msub_32_16( N1, N1, g ), Mpy_32_16_1( N2, gamma ) ); - l_tmp = L_shr( l_tmp, sub( q_cna_level, hStereoDft->q_dft ) ); - DFT_R[2 * i] = L_add( DFT_R[2 * i], l_tmp ); + l_tmp = L_sub( Msub_32_16( N1, N1, g ), Mpy_32_16_1( N2, gamma ) ); /* q_cna_level */ + l_tmp = L_shr( l_tmp, sub( q_cna_level, hStereoDft->q_dft ) ); /* q_dft */ + DFT_R[2 * i] = L_add( DFT_R[2 * i], l_tmp ); /* q_dft */ move32(); - N1 = L_shl( Mpy_32_16_1( scale_fact, rand_gauss_fix( &ftmp, cna_seed ) ), Q2 ); - N2 = L_shl( Mpy_32_16_1( scale_fact, rand_gauss_fix( &ftmp, cna_seed ) ), Q2 ); - l_tmp = L_add( Madd_32_16( N1, N1, g ), Mpy_32_16_1( N2, gamma ) ); - l_tmp = L_shr( l_tmp, sub( q_cna_level, hStereoDft->q_dft ) ); - DFT_L[2 * i + 1] = L_add( DFT_L[2 * i + 1], l_tmp ); + N1 = L_shl( Mpy_32_16_1( scale_fact, rand_gauss_fix( &ftmp, cna_seed ) ), Q2 ); /* q_cna_level */ + N2 = L_shl( Mpy_32_16_1( scale_fact, rand_gauss_fix( &ftmp, cna_seed ) ), Q2 ); /* q_cna_level */ + l_tmp = L_add( Madd_32_16( N1, N1, g ), Mpy_32_16_1( N2, gamma ) ); /* q_cna_level */ + l_tmp = L_shr( l_tmp, sub( q_cna_level, hStereoDft->q_dft ) ); /* q_dft */ + DFT_L[2 * i + 1] = L_add( DFT_L[2 * i + 1], l_tmp ); /* q_dft */ move32(); - l_tmp = L_sub( Msub_32_16( N1, N1, g ), Mpy_32_16_1( N2, gamma ) ); - l_tmp = L_shr( l_tmp, sub( q_cna_level, hStereoDft->q_dft ) ); - DFT_R[2 * i + 1] = L_add( DFT_R[2 * i + 1], l_tmp ); + l_tmp = L_sub( Msub_32_16( N1, N1, g ), Mpy_32_16_1( N2, gamma ) ); /* q_cna_level */ + l_tmp = L_shr( l_tmp, sub( q_cna_level, hStereoDft->q_dft ) ); /* q_dft */ + DFT_R[2 * i + 1] = L_add( DFT_R[2 * i + 1], l_tmp ); /* q_dft */ move32(); } } /* update CNA re-scaling factor */ - hFdCngDec->cna_rescale_fact_fx = extract_l( L_shr( L_mult0( (Word16) 0x6666, hFdCngDec->cna_act_fact_fx ), Q15 ) ); + hFdCngDec->cna_rescale_fact_fx = extract_l( L_shr( L_mult0( (Word16) 0x6666, hFdCngDec->cna_act_fact_fx ), Q15 ) ); /* q_cna_act */ move16(); IF( !hFdCngDec->first_cna_noise_updated ) @@ -2273,9 +2276,9 @@ void stereo_dft_dec_fx( } /* Update memories */ - hStereoDft->past_DMX_pos = s_and( ( add( hStereoDft->past_DMX_pos, 1 ) ), ( STEREO_DFT_PAST_MAX - 1 ) ); + hStereoDft->past_DMX_pos = s_and( ( add( hStereoDft->past_DMX_pos, 1 ) ), ( STEREO_DFT_PAST_MAX - 1 ) ); /* Q0 */ move16(); - Copy32( pDFT_DMX, hStereoDft->DFT_past_DMX_fx[hStereoDft->past_DMX_pos], s_min( hStereoDft->NFFT, STEREO_DFT32MS_N_32k ) ); + Copy32( pDFT_DMX, hStereoDft->DFT_past_DMX_fx[hStereoDft->past_DMX_pos], s_min( hStereoDft->NFFT, STEREO_DFT32MS_N_32k ) ); /* qDFT */ hStereoDft->q_DFT_past_DMX_fx[hStereoDft->past_DMX_pos] = hStereoDft->q_dft; move16(); IF( pPredGain ) @@ -2283,20 +2286,20 @@ void stereo_dft_dec_fx( stereo_dft_adapt_sf_delay_fx( hStereoDft, pPredGain ); } - Copy32( DFT_L, DFT[0] + k * STEREO_DFT32MS_N_MAX, hStereoDft->NFFT ); - Copy32( DFT_R, DFT[1] + k * STEREO_DFT32MS_N_MAX, hStereoDft->NFFT ); + Copy32( DFT_L, DFT[0] + k * STEREO_DFT32MS_N_MAX, hStereoDft->NFFT ); /* qDFT */ + Copy32( DFT_R, DFT[1] + k * STEREO_DFT32MS_N_MAX, hStereoDft->NFFT ); /* qDFT */ } IF( st0->bfi && !prev_bfi ) { Word16 q_shift0; Word16 q_shift1; - idx_k0 = add( hStereoDft->past_DMX_pos, STEREO_DFT_PAST_MAX - 1 ) & ( STEREO_DFT_PAST_MAX - 1 ); + idx_k0 = add( hStereoDft->past_DMX_pos, STEREO_DFT_PAST_MAX - 1 ) & ( STEREO_DFT_PAST_MAX - 1 ); /* Q0 */ idx_k1 = add( idx_k0, 1 ) & ( STEREO_DFT_PAST_MAX - 1 ); q_shift0 = sub( hStereoDft->q_dft, hStereoDft->q_DFT_past_DMX_fx[idx_k0] ); q_shift1 = sub( hStereoDft->q_dft, hStereoDft->q_DFT_past_DMX_fx[idx_k1] ); /*dmx energy memory*/ - hStereoDft->past_dmx_nrg_fx = stereo_dft_dmx_swb_nrg_fx( hStereoDft->DFT_past_DMX_fx[idx_k0], hStereoDft->DFT_past_DMX_fx[idx_k1], s_min( hStereoDft->NFFT, STEREO_DFT32MS_N_32k ), q_shift0, q_shift1 ); + hStereoDft->past_dmx_nrg_fx = stereo_dft_dmx_swb_nrg_fx( hStereoDft->DFT_past_DMX_fx[idx_k0], hStereoDft->DFT_past_DMX_fx[idx_k1], s_min( hStereoDft->NFFT, STEREO_DFT32MS_N_32k ), q_shift0, q_shift1 ); /* 2 * q_DFT */ } stereo_dft_compute_td_stefi_params_fx( hStereoDft, samp_ratio ); @@ -2311,8 +2314,8 @@ void stereo_dft_dec_fx( *-------------------------------------------------------------------------*/ static void stereo_dft_compute_td_stefi_params_fx( - STEREO_DFT_DEC_DATA_HANDLE hStereoDft, /* i/o: decoder DFT stereo handle */ - const Word16 samp_ratio /* i : sampling ratio */ + STEREO_DFT_DEC_DATA_HANDLE hStereoDft, /* i/o: decoder DFT stereo handle */ + const Word16 samp_ratio /* i : sampling ratio Q13*/ ) { Word16 pdmx_ind; @@ -2330,9 +2333,9 @@ static void stereo_dft_compute_td_stefi_params_fx( Word32 op1; Word16 q_div, q_sqrt; - pdmx_ind = hStereoDft->past_DMX_pos; + pdmx_ind = hStereoDft->past_DMX_pos; /* Q0 */ move16(); - bres = hStereoDft->band_res[1]; + bres = hStereoDft->band_res[1]; /* Q0 */ move16(); test(); @@ -2345,16 +2348,16 @@ static void stereo_dft_compute_td_stefi_params_fx( return; } - bin0 = extract_l( L_shr_r( Mpy_32_16_1( (Word32) hStereoDft->NFFT, samp_ratio ), 1 ) ); + bin0 = extract_l( L_shr_r( Mpy_32_16_1( (Word32) hStereoDft->NFFT, samp_ratio ), 1 ) ); /* Q0 */ bin0 = shl( bin0, Q3 ); - bin0 = s_min( bin0, hStereoDft->band_limits[hStereoDft->nbands] ); - b = hStereoDft->nbands; + bin0 = s_min( bin0, hStereoDft->band_limits[hStereoDft->nbands] ); /* Q0 */ + b = hStereoDft->nbands; /* Q0 */ move16(); WHILE( GT_16( hStereoDft->band_limits[b], bin0 ) ) { - b = sub( b, 1 ); + b--; } - band0 = b; + band0 = b; /* Q0 */ move16(); /* calculate averages over high bands */ @@ -2379,11 +2382,11 @@ static void stereo_dft_compute_td_stefi_params_fx( pred_g = L_add( pred_g, L_shr( Mpy_32_16_1( L_add( L_shr( hStereoDft->res_pred_gain_fx[b + STEREO_DFT_BAND_MAX], 1 ), L_shr( hStereoDft->res_pred_gain_fx[b + 2 * STEREO_DFT_BAND_MAX], 1 ) ), dft_res_pred_weights_fx[bres][b - band0] ), - shift_g ) ); + shift_g ) ); /* Q30 - shift_g */ pred_gain_avg = L_add( pred_gain_avg, L_shr( Mpy_32_16_1( L_add( L_shr( hStereoDft->past_res_pred_gain_fx[STEFI_DELAY_IND( STEREO_DFT_TD_STEFI_SUBFR_DELAY + 2, pdmx_ind )][b], 1 ), L_shr( hStereoDft->past_res_pred_gain_fx[STEFI_DELAY_IND( STEREO_DFT_TD_STEFI_SUBFR_DELAY + 1, pdmx_ind )][b], 1 ) ), dft_res_pred_weights_fx[bres][b - band0] ), - shift_g ) ); + shift_g ) ); /* Q30 - shift_g */ nbands = add( nbands, 1 ); wsum = L_add( wsum, dft_res_pred_weights_fx[bres][b - band0] ); @@ -2401,14 +2404,14 @@ static void stereo_dft_compute_td_stefi_params_fx( move16(); return; } - wsum = L_shl( wsum, sub( Q16, shift_g ) ); - pred_g = BASOP_Util_Divide3232_Scale( pred_g, wsum, &q_div ); + wsum = L_shl( wsum, sub( Q16, shift_g ) ); /* Q31 - shift_g */ + pred_g = BASOP_Util_Divide3232_Scale( pred_g, wsum, &q_div ); /* q_div */ IF( GT_16( sub( 15, q_div ), 15 ) ) { pred_g = L_shl( pred_g, q_div ); } - pred_gain_avg = BASOP_Util_Divide3232_Scale( pred_gain_avg, wsum, &q_div ); + pred_gain_avg = BASOP_Util_Divide3232_Scale( pred_gain_avg, wsum, &q_div ); /* q_div */ IF( GT_16( sub( 15, q_div ), 15 ) ) { pred_gain_avg = L_shl( pred_gain_avg, q_div ); @@ -2424,10 +2427,10 @@ static void stereo_dft_compute_td_stefi_params_fx( nrg_pred_DMX = hStereoDft->hb_nrg_fx[1]; move32(); - op1 = BASOP_Util_Divide3232_Scale( L_add( EPSILON_FIX, nrg_DMX ), L_add( EPSILON_FIX, nrg_pred_DMX ), &q_div ); + op1 = BASOP_Util_Divide3232_Scale( L_add( EPSILON_FIX, nrg_DMX ), L_add( EPSILON_FIX, nrg_pred_DMX ), &q_div ); /* q_div */ q_sqrt = add( Q16, q_div ); op1 = Sqrt32( op1, &q_sqrt ); - g2 = Mpy_32_32( pred_g, op1 ); + g2 = Mpy_32_32( pred_g, op1 ); /* q_div + q_sqrt - 31 */ IF( LT_16( q_sqrt, 0 ) ) { g2 = L_shl( g2, q_sqrt ); @@ -2438,25 +2441,25 @@ static void stereo_dft_compute_td_stefi_params_fx( { IF( LT_32( L_shr( pred_gain_avg, q_sqrt ), g2 ) ) { - g2 = pred_gain_avg; + g2 = pred_gain_avg; /* q_pred_gain_avg */ move32(); } ELSE { g2 = L_min( Mpy_32_16_1( L_shr( pred_gain_avg, q_sqrt ), STEREO_DFT_STEFFI_GAIN_AMP_FX ), Madd_32_16( Mpy_32_16_1( L_shr( pred_gain_avg, q_sqrt ), sub( (Word16) 0x7FFF, STEREO_DFT_STEFFI_GAIN_REST_AMT_FX ) ), - g2, STEREO_DFT_STEFFI_GAIN_REST_AMT_FX ) ); - g2 = L_shl( g2, q_sqrt ); + g2, STEREO_DFT_STEFFI_GAIN_REST_AMT_FX ) ); /* q_pred_gain_avg - q_sqrt */ + g2 = L_shl( g2, q_sqrt ); /* q_pred_gain_avg */ } } ELSE { g2 = L_min( Mpy_32_16_1( pred_gain_avg, STEREO_DFT_STEFFI_GAIN_AMP_FX ), Madd_32_16( Mpy_32_16_1( pred_gain_avg, sub( (Word16) 0x7FFF, STEREO_DFT_STEFFI_GAIN_REST_AMT_FX ) ), - g2, STEREO_DFT_STEFFI_GAIN_REST_AMT_FX ) ); + g2, STEREO_DFT_STEFFI_GAIN_REST_AMT_FX ) ); /* q_pred_gain_avg */ } - hStereoDft->td_gain_fx[0] = L_deposit_h( (Word16) g2 ); + hStereoDft->td_gain_fx[0] = L_deposit_h( (Word16) g2 ); /* Q16 + q_pred_gain_avg */ hStereoDft->q_td_gain[0] = add( 16, q_pred_gain_avg ); move32(); move16(); @@ -2471,12 +2474,13 @@ static void stereo_dft_compute_td_stefi_params_fx( } static void stereo_dft_dequantize_ipd_fx( - Word16 *ind, - Word32 *out_fx, + Word16 *ind, /* Q0 */ + Word32 *out_fx, /* Q27 */ #ifndef FIX_874_INCREASE_IPD_PRECISION const Word16 N, #endif - const Word16 bits ) + const Word16 bits /* Q0 */ +) { Word16 delta_fx; #ifndef FIX_874_INCREASE_IPD_PRECISION @@ -2485,22 +2489,22 @@ static void stereo_dft_dequantize_ipd_fx( #endif IF( EQ_16( bits, 2 ) ) /* 2-bit phase quantization for the highest frequency band only */ { - delta_fx = ( EVS_PI_FX ) >> 1; + delta_fx = ( EVS_PI_FX ) >> 1; /* Q13 */ move16(); } ELSE IF( EQ_16( bits, 3 ) ) { - delta_fx = ( EVS_PI_FX ) >> 2; + delta_fx = ( EVS_PI_FX ) >> 2; /* Q13 */ move16(); } ELSE IF( EQ_16( bits, 4 ) ) { - delta_fx = ( EVS_PI_FX ) >> 3; + delta_fx = ( EVS_PI_FX ) >> 3; /* Q13 */ move16(); } ELSE { - delta_fx = ( EVS_PI_FX ) >> 2; + delta_fx = ( EVS_PI_FX ) >> 2; /* Q13 */ move16(); assert( 0 ); } @@ -2508,8 +2512,8 @@ static void stereo_dft_dequantize_ipd_fx( #ifndef FIX_874_INCREASE_IPD_PRECISION FOR( i = 0; i < N; i++ ) { - temp_out = L_sub( L_mult0( ind[i], delta_fx ), ( EVS_PI_FX ) ); - *out_fx = L_shl( temp_out, 14 ); + temp_out = L_sub( L_mult0( ind[i], delta_fx ), ( EVS_PI_FX ) ); /* Q13 */ + *out_fx = L_shl( temp_out, 14 ); /* Q27 */ move32(); } #else @@ -2525,15 +2529,15 @@ static void stereo_dft_dequantize_ipd_fx( * *-------------------------------------------------------------------------*/ void stereo_dft_generate_res_pred_fx( - STEREO_DFT_DEC_DATA_HANDLE hStereoDft, /* i/o: decoder DFT stereo handle */ - const Word16 samp_ratio, /* i : sampling ratio */ - Word32 *pDFT_DMX, /* i : downmix signal */ - Word32 *DFT_PRED_RES, /* o : residual prediction signal */ - Word32 *pPredGain, /* i : residual prediction gains */ - const Word16 k, /* i : subframe index */ - Word32 *ap_filt_DMX, /* i : enhanced stereo filling signal */ - Word16 *stop, /* o : last FD stereo filling bin */ - const Word16 bfi /* i : BFI flag */ + STEREO_DFT_DEC_DATA_HANDLE hStereoDft, /* i/o: decoder DFT stereo handle */ + const Word16 samp_ratio, /* i : sampling ratio Q13*/ + Word32 *pDFT_DMX, /* i : downmix signal qDFT*/ + Word32 *DFT_PRED_RES, /* o : residual prediction signal qDFT*/ + Word32 *pPredGain, /* i : residual prediction gains Q31*/ + const Word16 k, /* i : subframe index Q0*/ + Word32 *ap_filt_DMX, /* i : enhanced stereo filling signal qDFT*/ + Word16 *stop, /* o : last FD stereo filling bin Q0*/ + const Word16 bfi /* i : BFI flag Q0*/ ) { /* general variables */ @@ -2570,24 +2574,24 @@ void stereo_dft_generate_res_pred_fx( } ELSE { - alpha = (Word16) ( 0x199A ); + alpha = (Word16) ( 0x199A ); /* Q15 */ move16(); } // gain_limit = 0x7FFF; // 2.0 in Q14 /* residual prediction only used up to 16 kHz (SWB) */ - nbands_respred = s_min( hStereoDft->nbands, STEREO_DFT_RES_PRED_BAND_MAX ); + nbands_respred = s_min( hStereoDft->nbands, STEREO_DFT_RES_PRED_BAND_MAX ); /* Q0 */ /* In ACELP mode the downmix signal is not available in bandwidth extension area. * * Therefore, the downmix energy in the corresponding subbands is estimated. */ - bin0 = (Word16) ( L_shr( L_add( L_mult0( hStereoDft->NFFT, samp_ratio ), ONE_IN_Q12 ), Q12 + 1 ) ); + bin0 = (Word16) ( L_shr( L_add( L_mult0( hStereoDft->NFFT, samp_ratio ), ONE_IN_Q12 ), Q12 + 1 ) ); /* Q0 */ move16(); - bin0 = s_min( bin0, hStereoDft->band_limits[hStereoDft->nbands] ); + bin0 = s_min( bin0, hStereoDft->band_limits[hStereoDft->nbands] ); /* Q0 */ b = hStereoDft->nbands; move16(); WHILE( GE_16( hStereoDft->band_limits[b], bin0 ) ) { - b = sub( b, 1 ); + b--; } band0 = b; move16(); @@ -2595,12 +2599,12 @@ void stereo_dft_generate_res_pred_fx( IF( LT_16( hStereoDft->res_pred_mode[k + STEREO_DFT_OFFSET], STEREO_DFT_RESPRED_ESF ) ) { /* no ESF signal available, use stereo filling over whole spectrum */ - lb_stefi_start_band = s_max( hStereoDft->res_pred_band_min, hStereoDft->res_cod_band_max ); + lb_stefi_start_band = s_max( hStereoDft->res_pred_band_min, hStereoDft->res_cod_band_max ); /* Q0 */ } ELSE { /* ESF signal available, use ESF in lowband, stereo filling in highband */ - lb_stefi_start_band = s_max( band0, hStereoDft->res_cod_band_max ); + lb_stefi_start_band = s_max( band0, hStereoDft->res_cod_band_max ); /* Q0 */ } IF( bfi ) @@ -2623,14 +2627,14 @@ void stereo_dft_generate_res_pred_fx( move64(); /* calculate band energies (low band only in case of ACELP) */ - FOR( i = hStereoDft->band_limits[b]; i < s_min( hStereoDft->band_limits[b + 1], bin0 ); i++ ) + FOR( i = hStereoDft->band_limits[b]; i < min( hStereoDft->band_limits[b + 1], bin0 ); i++ ) { dmx_nrg_64bit = W_add( dmx_nrg_64bit, W_add( W_mult0_32_32( pDFT_DMX[2 * i], pDFT_DMX[2 * i] ), - W_mult0_32_32( pDFT_DMX[add( shl( i, 1 ), 1 )], pDFT_DMX[add( shl( i, 1 ), 1 )] ) ) ); + W_mult0_32_32( pDFT_DMX[2 * i + 1], pDFT_DMX[2 * i + 1] ) ) ); /* 2 * q_dft */ rev_nrg_64bit = W_add( rev_nrg_64bit, W_add( W_mult0_32_32( ap_filt_DMX[2 * i], ap_filt_DMX[2 * i] ), - W_mult0_32_32( ap_filt_DMX[add( shl( i, 1 ), 1 )], ap_filt_DMX[add( shl( i, 1 ), 1 )] ) ) ); + W_mult0_32_32( ap_filt_DMX[2 * i + 1], ap_filt_DMX[2 * i + 1] ) ) ); /* 2 * q_dft */ } q_shift = W_norm( dmx_nrg_64bit ); dmx_nrg = W_extract_l( W_shl( dmx_nrg_64bit, sub( q_shift, 32 ) ) ); // 2 * hStereoDft->q_dft + (q_shift - 32) @@ -2641,8 +2645,8 @@ void stereo_dft_generate_res_pred_fx( /* Reach a common Q for dmx_nrg and rev_nrg */ q_com = s_min( dmx_nrg_q, rev_nrg_q ); - dmx_nrg = L_shl( dmx_nrg, sub( q_com, dmx_nrg_q ) ); - rev_nrg = L_shl( rev_nrg, sub( q_com, rev_nrg_q ) ); + dmx_nrg = L_shl( dmx_nrg, sub( q_com, dmx_nrg_q ) ); /* q_com */ + rev_nrg = L_shl( rev_nrg, sub( q_com, rev_nrg_q ) ); /* q_com */ IF( LT_16( hStereoDft->q_smoothed_nrg, q_com ) ) { rev_nrg = L_shr( rev_nrg, shl( sub( q_com, hStereoDft->q_smoothed_nrg ), 1 ) ); @@ -2652,23 +2656,23 @@ void stereo_dft_generate_res_pred_fx( } ELSE IF( GT_16( hStereoDft->q_smoothed_nrg, q_com ) ) { - hStereoDft->smooth_res_nrg_fx[b] = L_shr( hStereoDft->smooth_res_nrg_fx[b], shl( sub( hStereoDft->q_smoothed_nrg, q_com ), 1 ) ); + hStereoDft->smooth_res_nrg_fx[b] = L_shr( hStereoDft->smooth_res_nrg_fx[b], shl( sub( hStereoDft->q_smoothed_nrg, q_com ), 1 ) ); /* hStereoDft->q_smoothed_nrg */ move32(); - hStereoDft->smooth_dmx_nrg_fx[b] = L_shr( hStereoDft->smooth_dmx_nrg_fx[b], shl( sub( hStereoDft->q_smoothed_nrg, q_com ), 1 ) ); + hStereoDft->smooth_dmx_nrg_fx[b] = L_shr( hStereoDft->smooth_dmx_nrg_fx[b], shl( sub( hStereoDft->q_smoothed_nrg, q_com ), 1 ) ); /* hStereoDft->q_smoothed_nrg */ move32(); q_smoothed_nrg_local[b] = q_com; move16(); } /* smoothing */ - hStereoDft->smooth_res_nrg_fx[b] = Madd_32_16( Mpy_32_16_1( hStereoDft->smooth_res_nrg_fx[b], alpha ), rev_nrg, sub( (Word16) ( 0x7FFF ), alpha ) ); + hStereoDft->smooth_res_nrg_fx[b] = Madd_32_16( Mpy_32_16_1( hStereoDft->smooth_res_nrg_fx[b], alpha ), rev_nrg, sub( (Word16) ( 0x7FFF ), alpha ) ); /* hStereoDft->q_smoothed_nrg */ move32(); - hStereoDft->smooth_dmx_nrg_fx[b] = Madd_32_16( Mpy_32_16_1( hStereoDft->smooth_dmx_nrg_fx[b], alpha ), dmx_nrg, sub( (Word16) ( 0x7FFF ), alpha ) ); + hStereoDft->smooth_dmx_nrg_fx[b] = Madd_32_16( Mpy_32_16_1( hStereoDft->smooth_dmx_nrg_fx[b], alpha ), dmx_nrg, sub( (Word16) ( 0x7FFF ), alpha ) ); /* hStereoDft->q_smoothed_nrg */ move32(); /* normalization factor */ IF( hStereoDft->smooth_res_nrg_fx[b] != 0 ) { - norm_fac = BASOP_Util_Divide3232_Scale( hStereoDft->smooth_dmx_nrg_fx[b], hStereoDft->smooth_res_nrg_fx[b], &q_norm_fac ); + norm_fac = BASOP_Util_Divide3232_Scale( hStereoDft->smooth_dmx_nrg_fx[b], hStereoDft->smooth_res_nrg_fx[b], &q_norm_fac ); /* q_norm_fac */ norm_fac = Sqrt16( norm_fac, &q_norm_fac ); IF( norm_fac != 0 ) { @@ -2705,7 +2709,7 @@ void stereo_dft_generate_res_pred_fx( } ELSE { - norm_fac = extract_l( L_shr( L_mult0( norm_fac, lim_norm_fac ), Q15 ) ); + norm_fac = extract_l( L_shr( L_mult0( norm_fac, lim_norm_fac ), Q15 ) ); /* q_norm_fac */ q_norm_fac = add( q_norm_fac, 1 ); test(); IF( q_norm_fac < 0 ) @@ -2732,11 +2736,11 @@ void stereo_dft_generate_res_pred_fx( move16(); } - FOR( i = hStereoDft->band_limits[b]; i < s_min( hStereoDft->band_limits[b + 1], bin0 ); i++ ) + FOR( i = hStereoDft->band_limits[b]; i < min( hStereoDft->band_limits[b + 1], bin0 ); i++ ) { - DFT_PRED_RES[2 * i] = L_shl( Mpy_32_32( Mpy_32_16_1( pPredGain[b], norm_fac ), ap_filt_DMX[2 * i] ), q_norm_fac ); + DFT_PRED_RES[2 * i] = L_shl( Mpy_32_32( Mpy_32_16_1( pPredGain[b], norm_fac ), ap_filt_DMX[2 * i] ), q_norm_fac ); /* q_dft */ move32(); - DFT_PRED_RES[add( shl( i, 1 ), 1 )] = L_shl( Mpy_32_32( Mpy_32_16_1( pPredGain[b], norm_fac ), ap_filt_DMX[add( shl( i, 1 ), 1 )] ), q_norm_fac ); + DFT_PRED_RES[2 * i + 1] = L_shl( Mpy_32_32( Mpy_32_16_1( pPredGain[b], norm_fac ), ap_filt_DMX[2 * i + 1] ), q_norm_fac ); /* q_dft */ move32(); } } @@ -2750,13 +2754,16 @@ void stereo_dft_generate_res_pred_fx( } FOR( b = 0; b < STEREO_DFT_BAND_MAX; b++ ) { - hStereoDft->smooth_dmx_nrg_fx[b] = L_shl( hStereoDft->smooth_dmx_nrg_fx[b], sub( q_com, q_smoothed_nrg_local[b] ) ); - hStereoDft->smooth_res_nrg_fx[b] = L_shl( hStereoDft->smooth_res_nrg_fx[b], sub( q_com, q_smoothed_nrg_local[b] ) ); + hStereoDft->smooth_dmx_nrg_fx[b] = L_shl( hStereoDft->smooth_dmx_nrg_fx[b], sub( q_com, q_smoothed_nrg_local[b] ) ); /* q_com */ + move32(); + + hStereoDft->smooth_res_nrg_fx[b] = L_shl( hStereoDft->smooth_res_nrg_fx[b], sub( q_com, q_smoothed_nrg_local[b] ) ); /* q_com */ + move32(); } IF( GT_16( q_com, hStereoDft->q_dft ) ) { - scale_sig32( hStereoDft->smooth_dmx_nrg_fx, STEREO_DFT_BAND_MAX, sub( hStereoDft->q_dft, q_com ) ); - scale_sig32( hStereoDft->smooth_res_nrg_fx, STEREO_DFT_BAND_MAX, sub( hStereoDft->q_dft, q_com ) ); + scale_sig32( hStereoDft->smooth_dmx_nrg_fx, STEREO_DFT_BAND_MAX, sub( hStereoDft->q_dft, q_com ) ); /* q_dft */ + scale_sig32( hStereoDft->smooth_res_nrg_fx, STEREO_DFT_BAND_MAX, sub( hStereoDft->q_dft, q_com ) ); /* q_dft */ hStereoDft->q_smoothed_nrg = hStereoDft->q_dft; move16(); } @@ -2769,8 +2776,8 @@ void stereo_dft_generate_res_pred_fx( FOR( b = lb_stefi_start_band; b <= band0; b++ ) { Word16 temp, temp_e; - d_short_ind = add( sub( STEREO_DFT_PAST_MAX, STEREO_DFT_STEFFI_DELAY_SHORT ), b & 1 ); - temp = BASOP_Util_Divide1616_Scale( b, sub( hStereoDft->nbands, 1 ), &temp_e ); /*(float) b / ( hStereoDft->nbands - 1 )*/ + d_short_ind = add( sub( STEREO_DFT_PAST_MAX, STEREO_DFT_STEFFI_DELAY_SHORT ), b & 1 ); /* Q0 */ + temp = BASOP_Util_Divide1616_Scale( b, sub( hStereoDft->nbands, 1 ), &temp_e ); /*(float) b / ( hStereoDft->nbands - 1 )*/ IF( temp_e < 0 ) { temp = shl( temp, temp_e ); @@ -2787,20 +2794,20 @@ void stereo_dft_generate_res_pred_fx( move16(); /* Even number of window sliding (assymmetric OLA) */ - d_short_ind = shl( shr( d_short_ind, 1 ), 1 ); - d_long_ind = shl( shr( d_long_ind, 1 ), 1 ); + d_short_ind = shl( shr( d_short_ind, 1 ), 1 ); /* Q0 */ + d_long_ind = shl( shr( d_long_ind, 1 ), 1 ); /* Q0 */ - d_short = sub( STEREO_DFT_PAST_MAX, d_short_ind ); - d_long = sub( STEREO_DFT_PAST_MAX, d_long_ind ); + d_short = sub( STEREO_DFT_PAST_MAX, d_short_ind ); /* Q0 */ + d_long = sub( STEREO_DFT_PAST_MAX, d_long_ind ); /* Q0 */ - d_short_ind = add( add( d_short_ind, hStereoDft->past_DMX_pos ), 1 ) % STEREO_DFT_PAST_MAX; + d_short_ind = add( add( d_short_ind, hStereoDft->past_DMX_pos ), 1 ) % STEREO_DFT_PAST_MAX; /* Q0 */ move16(); - d_long_ind = add( add( d_long_ind, hStereoDft->past_DMX_pos ), 1 ) % STEREO_DFT_PAST_MAX; + d_long_ind = add( add( d_long_ind, hStereoDft->past_DMX_pos ), 1 ) % STEREO_DFT_PAST_MAX; /* Q0 */ move16(); - g_short = hStereoDft->stefi_short_gain_fx; + g_short = hStereoDft->stefi_short_gain_fx; /* Q15 */ move16(); - g_long = hStereoDft->stefi_long_gain_fx; + g_long = hStereoDft->stefi_long_gain_fx; /* Q15 */ move16(); /* change mixing ratio if long and short delay are the same */ @@ -2844,35 +2851,35 @@ void stereo_dft_generate_res_pred_fx( move32(); dmx_nrg = EPSILON_FIX; move32(); - FOR( i = hStereoDft->band_limits[b]; i < s_min( bin0, hStereoDft->band_limits[b + 1] ); i++ ) + FOR( i = hStereoDft->band_limits[b]; i < min( bin0, hStereoDft->band_limits[b + 1] ); i++ ) { - dmx_nrg = Madd_32_32( Madd_32_32( dmx_nrg, pDFT_DMX[2 * i], pDFT_DMX[2 * i] ), pDFT_DMX[add( shl( i, 1 ), 1 )], pDFT_DMX[add( shl( i, 1 ), 1 )] ); + dmx_nrg = Madd_32_32( Madd_32_32( dmx_nrg, pDFT_DMX[2 * i], pDFT_DMX[2 * i] ), pDFT_DMX[2 * i + 1], pDFT_DMX[2 * i + 1] ); /* 2 * q_dft - 31 */ - DFT_PRED_RES[2 * i] = L_add( L_shl( Mpy_32_16_1( hStereoDft->DFT_past_DMX_fx[d_short_ind][2 * i], g_short ), q_shift0 ), L_shl( Mpy_32_16_1( hStereoDft->DFT_past_DMX_fx[d_long_ind][2 * i], g_long ), q_shift1 ) ); + DFT_PRED_RES[2 * i] = L_add( L_shl( Mpy_32_16_1( hStereoDft->DFT_past_DMX_fx[d_short_ind][2 * i], g_short ), q_shift0 ), L_shl( Mpy_32_16_1( hStereoDft->DFT_past_DMX_fx[d_long_ind][2 * i], g_long ), q_shift1 ) ); /* q_dft */ move32(); - DFT_PRED_RES[add( shl( i, 1 ), 1 )] = L_add( L_shl( Mpy_32_16_1( hStereoDft->DFT_past_DMX_fx[d_short_ind][add( shl( i, 1 ), 1 )], g_short ), q_shift0 ), L_shl( Mpy_32_16_1( hStereoDft->DFT_past_DMX_fx[d_long_ind][add( shl( i, 1 ), 1 )], g_long ), q_shift1 ) ); + DFT_PRED_RES[2 * i + 1] = L_add( L_shl( Mpy_32_16_1( hStereoDft->DFT_past_DMX_fx[d_short_ind][2 * i + 1], g_short ), q_shift0 ), L_shl( Mpy_32_16_1( hStereoDft->DFT_past_DMX_fx[d_long_ind][2 * i + 1], g_long ), q_shift1 ) ); /* q_dft */ move32(); - past_dmx_nrg = Madd_32_32( Madd_32_32( past_dmx_nrg, DFT_PRED_RES[2 * i], DFT_PRED_RES[2 * i] ), DFT_PRED_RES[add( shl( i, 1 ), 1 )], DFT_PRED_RES[add( shl( i, 1 ), 1 )] ); + past_dmx_nrg = Madd_32_32( Madd_32_32( past_dmx_nrg, DFT_PRED_RES[2 * i], DFT_PRED_RES[2 * i] ), DFT_PRED_RES[2 * i + 1], DFT_PRED_RES[2 * i + 1] ); /* q_dft */ } test(); IF( !bfi || GE_16( b, hStereoDft->res_cod_band_max ) ) { Word16 q_div; Word16 op; - op = BASOP_Util_Divide3232_Scale( L_add( 1, dmx_nrg ), L_add( 1, past_dmx_nrg ), &q_div ); + op = BASOP_Util_Divide3232_Scale( L_add( 1, dmx_nrg ), L_add( 1, past_dmx_nrg ), &q_div ); /* q_sqrt */ q_sqrt = q_div; move16(); norm_fac = Sqrt16( op, &q_sqrt ); - g2 = Mpy_32_16_1( pPredGain[b], norm_fac ); + g2 = Mpy_32_16_1( pPredGain[b], norm_fac ); /* Q31 */ IF( LE_32( q_sqrt, norm_l( g2 ) ) ) { g2 = L_shl( g2, q_sqrt ); pred_gain_avg = Madd_32_16( Mpy_32_16_1( hStereoDft->past_res_pred_gain_fx[d_short_ind][b], g_short ), - hStereoDft->past_res_pred_gain_fx[d_long_ind][b], g_long ); + hStereoDft->past_res_pred_gain_fx[d_long_ind][b], g_long ); /* Q31 */ g2 = L_min( Mpy_32_16_1( pred_gain_avg, STEREO_DFT_STEFFI_GAIN_AMP_FX ), Madd_32_16( Mpy_32_16_1( pred_gain_avg, sub( MAX_16, STEREO_DFT_STEFFI_GAIN_REST_AMT_FX ) ), - g2, STEREO_DFT_STEFFI_GAIN_REST_AMT_FX ) ); + g2, STEREO_DFT_STEFFI_GAIN_REST_AMT_FX ) ); /* Q31 */ q_sqrt = 0; move16(); } @@ -2881,23 +2888,23 @@ void stereo_dft_generate_res_pred_fx( /* Multiplication with STEREO_DFT_STEFFI_GAIN_AMP_FX is avodided since the float value of this constant is 1.0f */ g2 = Madd_32_16( Mpy_32_16_1( hStereoDft->past_res_pred_gain_fx[d_short_ind][b], g_short ), - hStereoDft->past_res_pred_gain_fx[d_long_ind][b], g_long ); + hStereoDft->past_res_pred_gain_fx[d_long_ind][b], g_long ); /* Q31 */ q_sqrt = 0; move16(); } FOR( i = hStereoDft->band_limits[b]; i < min( bin0, hStereoDft->band_limits[b + 1] ); i++ ) { - DFT_PRED_RES[2 * i] = L_shl( Mpy_32_32( g2, DFT_PRED_RES[2 * i] ), q_sqrt ); + DFT_PRED_RES[2 * i] = L_shl( Mpy_32_32( g2, DFT_PRED_RES[2 * i] ), q_sqrt ); /* q_dft */ move32(); - DFT_PRED_RES[add( shl( i, 1 ), 1 )] = L_shl( Mpy_32_32( g2, DFT_PRED_RES[add( shl( i, 1 ), 1 )] ), q_sqrt ); + DFT_PRED_RES[2 * i + 1] = L_shl( Mpy_32_32( g2, DFT_PRED_RES[2 * i + 1] ), q_sqrt ); /* q_dft */ move32(); } } } ELSE { - set32_fx( DFT_PRED_RES + shl( hStereoDft->band_limits[b], 1 ), 0, shl( sub( min( bin0, hStereoDft->band_limits[b + 1] ), hStereoDft->band_limits[b] ), 1 ) ); + set32_fx( DFT_PRED_RES + shl( hStereoDft->band_limits[b], 1 ), 0, shl( sub( s_min( bin0, hStereoDft->band_limits[b + 1] ), hStereoDft->band_limits[b] ), 1 ) ); } } } @@ -2918,12 +2925,12 @@ void stereo_dft_generate_res_pred_fx( /* calculate high band energy only */ dmx_nrg = EPSILON_FIX; move32(); - FOR( i = bin0; i < shr( hStereoDft->NFFT, 1 ); i++ ) + FOR( i = bin0; i < hStereoDft->NFFT / 2; i++ ) { - dmx_nrg = L_add( dmx_nrg, Madd_32_32( Mpy_32_32( pDFT_DMX[2 * i], pDFT_DMX[2 * i] ), pDFT_DMX[add( shl( i, 1 ), 1 )], pDFT_DMX[add( shl( i, 1 ), 1 )] ) ); + dmx_nrg = L_add( dmx_nrg, Madd_32_32( Mpy_32_32( pDFT_DMX[2 * i], pDFT_DMX[2 * i] ), pDFT_DMX[2 * i + 1], pDFT_DMX[2 * i + 1] ) ); /* 2 * q_dft - 31 */ } - hStereoDft->hb_nrg_fx[0] = L_add( hStereoDft->hb_nrg_fx[0], div_l( dmx_nrg, shr( hStereoDft->NFFT, 2 ) ) ); + hStereoDft->hb_nrg_fx[0] = L_add( hStereoDft->hb_nrg_fx[0], div_l( dmx_nrg, shr( hStereoDft->NFFT, 2 ) ) ); /* Q15 */ move32(); *stop = bin0; move16(); @@ -2932,22 +2939,22 @@ void stereo_dft_generate_res_pred_fx( { /* TCX/HQ core -> ACELP transition */ /* apply short delay only and blend to long/short gain */ - dmx_nrg = hStereoDft->hb_nrg_subr_fx[k]; + dmx_nrg = hStereoDft->hb_nrg_subr_fx[k]; /* Q15 */ move32(); d_short_ind = STEREO_DFT_PAST_MAX - STEREO_DFT_TD_STEFI_SUBFR_DELAY; move16(); - d_short_ind = s_and( add( d_short_ind, add( hStereoDft->past_DMX_pos, 1 ) ), ( STEREO_DFT_PAST_MAX - 1 ) ); + d_short_ind = s_and( add( d_short_ind, add( hStereoDft->past_DMX_pos, 1 ) ), ( STEREO_DFT_PAST_MAX - 1 ) ); /* Q0 */ /* calculate high band energy of past dmx */ // past_dmx_nrg = EPSILON_FIX; past_dmx_nrg = 0; move32(); - FOR( i = bin0; i < s_min( shr( hStereoDft->NFFT, 1 ), STEREO_DFT32MS_N_32k / 2 ); i++ ) + FOR( i = bin0; i < min( ( hStereoDft->NFFT / 2 ), ( STEREO_DFT32MS_N_32k / 2 ) ); i++ ) { - past_dmx_nrg = L_add( past_dmx_nrg, Madd_32_32( Mpy_32_32( hStereoDft->DFT_past_DMX_fx[d_short_ind][2 * i], hStereoDft->DFT_past_DMX_fx[d_short_ind][2 * i] ), hStereoDft->DFT_past_DMX_fx[d_short_ind][add( shl( i, 1 ), 1 )], hStereoDft->DFT_past_DMX_fx[d_short_ind][add( shl( i, 1 ), 1 )] ) ); + past_dmx_nrg = L_add( past_dmx_nrg, Madd_32_32( Mpy_32_32( hStereoDft->DFT_past_DMX_fx[d_short_ind][2 * i], hStereoDft->DFT_past_DMX_fx[d_short_ind][2 * i] ), hStereoDft->DFT_past_DMX_fx[d_short_ind][2 * i + 1], hStereoDft->DFT_past_DMX_fx[d_short_ind][2 * i + 1] ) ); /* 2 * hStereoDft->q_DFT_past_DMX_fx[d_short_ind] - 31 */ } - past_dmx_nrg = L_shl( past_dmx_nrg, shl( sub( hStereoDft->q_dft, hStereoDft->q_DFT_past_DMX_fx[d_short_ind] ), 1 ) ); + past_dmx_nrg = L_shl( past_dmx_nrg, shl( sub( hStereoDft->q_dft, hStereoDft->q_DFT_past_DMX_fx[d_short_ind] ), 1 ) ); /* 2 * hStereoDft->q_dft - 31*/ IF( past_dmx_nrg == 0 ) { past_dmx_nrg = EPSILON_FX; @@ -2973,8 +2980,8 @@ void stereo_dft_generate_res_pred_fx( Word32 op = BASOP_Util_Divide3232_Scale( L_add( EPSILON_FIX, dmx_nrg ), L_add( EPSILON_FIX, past_dmx_nrg ), &q_divide ); q_norm_fac = add( add( Q16, q_divide ), hStereoDft->q_hb_nrg_subr ); op = Sqrt32( op, &q_norm_fac ); - g2 = Mpy_32_32( pPredGain[b], op ); - pred_gain_avg = Mpy_32_16_1( hStereoDft->past_res_pred_gain_fx[d_short_ind][b], g_short ); + g2 = Mpy_32_32( pPredGain[b], op ); /* Q31 */ + pred_gain_avg = Mpy_32_16_1( hStereoDft->past_res_pred_gain_fx[d_short_ind][b], g_short ); /* Q31 */ IF( q_norm_fac < 0 ) { g2 = L_shl( g2, q_norm_fac ); @@ -2992,30 +2999,30 @@ void stereo_dft_generate_res_pred_fx( { g2 = L_min( Mpy_32_16_1( L_shr( pred_gain_avg, q_norm_fac ), STEREO_DFT_STEFFI_GAIN_AMP_FX ), Madd_32_16( Mpy_32_16_1( L_shr( pred_gain_avg, q_norm_fac ), sub( (Word16) 0x7FFF, STEREO_DFT_STEFFI_GAIN_REST_AMT_FX ) ), - g2, STEREO_DFT_STEFFI_GAIN_REST_AMT_FX ) ); - g2 = L_shl( g2, q_norm_fac ); + g2, STEREO_DFT_STEFFI_GAIN_REST_AMT_FX ) ); /* Q31 - q_norm_fac */ + g2 = L_shl( g2, q_norm_fac ); /* Q31 */ } } ELSE { g2 = L_min( Mpy_32_16_1( pred_gain_avg, STEREO_DFT_STEFFI_GAIN_AMP_FX ), Madd_32_16( Mpy_32_16_1( pred_gain_avg, sub( (Word16) 0x7FFF, STEREO_DFT_STEFFI_GAIN_REST_AMT_FX ) ), - g2, STEREO_DFT_STEFFI_GAIN_REST_AMT_FX ) ); + g2, STEREO_DFT_STEFFI_GAIN_REST_AMT_FX ) ); /* Q31 */ } q_shift = sub( hStereoDft->q_dft, hStereoDft->q_DFT_past_DMX_fx[d_short_ind] ); move16(); - FOR( i = s_max( hStereoDft->band_limits[b], bin0 ); i < s_min( hStereoDft->band_limits[b + 1], STEREO_DFT32MS_N_32k / 2 ); i++ ) + FOR( i = max( hStereoDft->band_limits[b], bin0 ); i < min( hStereoDft->band_limits[b + 1], STEREO_DFT32MS_N_32k / 2 ); i++ ) { - DFT_PRED_RES[2 * i] = L_shl( Mpy_32_32( g2, hStereoDft->DFT_past_DMX_fx[d_short_ind][2 * i] ), q_shift ); + DFT_PRED_RES[2 * i] = L_shl( Mpy_32_32( g2, hStereoDft->DFT_past_DMX_fx[d_short_ind][2 * i] ), q_shift ); /* q_dft */ move32(); - DFT_PRED_RES[add( shl( i, 1 ), 1 )] = L_shl( Mpy_32_32( g2, hStereoDft->DFT_past_DMX_fx[d_short_ind][add( shl( i, 1 ), 1 )] ), q_shift ); + DFT_PRED_RES[2 * i + 1] = L_shl( Mpy_32_32( g2, hStereoDft->DFT_past_DMX_fx[d_short_ind][2 * i + 1] ), q_shift ); /* q_dft */ move32(); } } ELSE { - begin = s_max( hStereoDft->band_limits[b], bin0 ); - end = s_min( hStereoDft->band_limits[b + 1], STEREO_DFT32MS_N_32k / 2 ); + begin = s_max( hStereoDft->band_limits[b], bin0 ); /* Q0 */ + end = s_min( hStereoDft->band_limits[b + 1], STEREO_DFT32MS_N_32k / 2 ); /* Q0 */ set32_fx( DFT_PRED_RES + shl( begin, 1 ), 0, shl( sub( end, begin ), 1 ) ); } } @@ -3025,7 +3032,7 @@ void stereo_dft_generate_res_pred_fx( FOR( b = band0; b < nbands_respred; b++ ) { /* TCX/HQ core -> TCX/HQ core: business as usual */ - d_short_ind = add( sub( STEREO_DFT_PAST_MAX, STEREO_DFT_STEFFI_DELAY_SHORT ), b & 1 ); + d_short_ind = add( sub( STEREO_DFT_PAST_MAX, STEREO_DFT_STEFFI_DELAY_SHORT ), b & 1 ); /* Q0 */ Word16 temp, temp_e; temp = BASOP_Util_Divide1616_Scale( b, sub( hStereoDft->nbands, 1 ), &temp_e ); /*(float) b / ( hStereoDft->nbands - 1 )*/ IF( temp_e < 0 ) @@ -3037,31 +3044,31 @@ void stereo_dft_generate_res_pred_fx( temp = shr( temp, 3 ); /*adding 3 as guard bit*/ temp_e = add( temp_e, 3 ); temp = shr( add( imult1616( ( STEREO_DFT_PAST_MAX + 4 - 1 ), temp ), shl( 1, sub( 14, temp_e ) ) ), sub( 15, temp_e ) ); /*( (float) b / ( hStereoDft->nbands - 1 ) ) + 0.5f*/ /*Q0*/ - d_long_ind = sub( s_max( 4, temp ), 4 ); + d_long_ind = sub( s_max( 4, temp ), 4 ); /* Q0 */ /* make sure d_short really corresponds to a shorter or equally long delay than d_long (e.g. not always the case for * STEREO_DFT_STEFFI_DELAY_SHORT=3 and STEREO_DFT_STEFFI_DELAY_LONG=4)*/ - d_short_ind = s_max( d_short_ind, d_long_ind ); + d_short_ind = s_max( d_short_ind, d_long_ind ); /* Q0 */ /* Even number of window sliding (assymmetric OLA) */ - d_short_ind = d_short_ind & (Word16) ( 0xFFFE ); + d_short_ind = d_short_ind & (Word16) ( 0xFFFE ); /* Q0 */ move16(); - d_long_ind = d_long_ind & (Word16) ( 0xFFFE ); + d_long_ind = d_long_ind & (Word16) ( 0xFFFE ); /* Q0 */ move16(); - d_short = sub( STEREO_DFT_PAST_MAX, d_short_ind ); + d_short = sub( STEREO_DFT_PAST_MAX, d_short_ind ); /* Q0 */ move16(); - d_long = sub( STEREO_DFT_PAST_MAX, d_long_ind ); + d_long = sub( STEREO_DFT_PAST_MAX, d_long_ind ); /* Q0 */ move16(); /* Works as long as STEREO_DFT_PAST_MAX is a power of 2*/ - d_short_ind = ( add( d_short_ind, add( hStereoDft->past_DMX_pos, 1 ) ) ) & ( STEREO_DFT_PAST_MAX - 1 ); + d_short_ind = ( add( d_short_ind, add( hStereoDft->past_DMX_pos, 1 ) ) ) & ( STEREO_DFT_PAST_MAX - 1 ); /* Q0 */ move16(); - d_long_ind = ( add( d_long_ind, add( hStereoDft->past_DMX_pos, 1 ) ) ) & ( STEREO_DFT_PAST_MAX - 1 ); + d_long_ind = ( add( d_long_ind, add( hStereoDft->past_DMX_pos, 1 ) ) ) & ( STEREO_DFT_PAST_MAX - 1 ); /* Q0 */ move16(); - g_short = hStereoDft->stefi_short_gain_fx; + g_short = hStereoDft->stefi_short_gain_fx; /* Q15 */ move16(); - g_long = hStereoDft->stefi_long_gain_fx; + g_long = hStereoDft->stefi_long_gain_fx; /* Q15 */ move16(); /* change mixing ratio if long and short delay are the same */ @@ -3118,18 +3125,18 @@ void stereo_dft_generate_res_pred_fx( move32(); dmx_nrg = EPSILON_FIX; move32(); - FOR( i = s_max( hStereoDft->band_limits[b], bin0 ); i < s_min( hStereoDft->band_limits[b + 1], STEREO_DFT32MS_N_32k / 2 ); i++ ) + FOR( i = max( hStereoDft->band_limits[b], bin0 ); i < min( hStereoDft->band_limits[b + 1], STEREO_DFT32MS_N_32k / 2 ); i++ ) { - dmx_nrg = L_add( dmx_nrg, Madd_32_32( Mpy_32_32( pDFT_DMX[2 * i], pDFT_DMX[2 * i] ), pDFT_DMX[add( shl( i, 1 ), 1 )], pDFT_DMX[add( shl( i, 1 ), 1 )] ) ); + dmx_nrg = L_add( dmx_nrg, Madd_32_32( Mpy_32_32( pDFT_DMX[2 * i], pDFT_DMX[2 * i] ), pDFT_DMX[2 * i + 1], pDFT_DMX[2 * i + 1] ) ); /* 2 * q_dft - 31 */ - DFT_PRED_RES[2 * i] = L_add( L_shl( Mpy_32_16_1( hStereoDft->DFT_past_DMX_fx[d_short_ind][2 * i], g_short ), q_shift0 ), L_shl( Mpy_32_16_1( hStereoDft->DFT_past_DMX_fx[d_long_ind][2 * i], g_long ), q_shift1 ) ); + DFT_PRED_RES[2 * i] = L_add( L_shl( Mpy_32_16_1( hStereoDft->DFT_past_DMX_fx[d_short_ind][2 * i], g_short ), q_shift0 ), L_shl( Mpy_32_16_1( hStereoDft->DFT_past_DMX_fx[d_long_ind][2 * i], g_long ), q_shift1 ) ); /* q_dft */ move32(); - DFT_PRED_RES[add( shl( i, 1 ), 1 )] = L_add( L_shl( Mpy_32_16_1( hStereoDft->DFT_past_DMX_fx[d_short_ind][add( shl( i, 1 ), 1 )], g_short ), q_shift0 ), L_shl( Mpy_32_16_1( hStereoDft->DFT_past_DMX_fx[d_long_ind][add( shl( i, 1 ), 1 )], g_long ), q_shift1 ) ); + DFT_PRED_RES[2 * i + 1] = L_add( L_shl( Mpy_32_16_1( hStereoDft->DFT_past_DMX_fx[d_short_ind][2 * i + 1], g_short ), q_shift0 ), L_shl( Mpy_32_16_1( hStereoDft->DFT_past_DMX_fx[d_long_ind][2 * i + 1], g_long ), q_shift1 ) ); /* q_dft */ move32(); - past_dmx_nrg = L_add( past_dmx_nrg, Madd_32_32( Mpy_32_32( DFT_PRED_RES[2 * i], DFT_PRED_RES[2 * i] ), DFT_PRED_RES[2 * i + 1], DFT_PRED_RES[2 * i + 1] ) ); + past_dmx_nrg = L_add( past_dmx_nrg, Madd_32_32( Mpy_32_32( DFT_PRED_RES[2 * i], DFT_PRED_RES[2 * i] ), DFT_PRED_RES[2 * i + 1], DFT_PRED_RES[2 * i + 1] ) ); /* 2 * q_dft - 31 */ } - op1 = L_deposit_h( BASOP_Util_Divide3232_Scale( ( EPSILON_FIX + dmx_nrg ), ( EPSILON_FIX + past_dmx_nrg ), &q_div ) ); + op1 = L_deposit_h( BASOP_Util_Divide3232_Scale( ( EPSILON_FIX + dmx_nrg ), ( EPSILON_FIX + past_dmx_nrg ), &q_div ) ); /* q_div + 16 */ q_norm_fac = q_div; move16(); op1 = Sqrt32( op1, &q_norm_fac ); @@ -3137,26 +3144,26 @@ void stereo_dft_generate_res_pred_fx( { assert( 0 ); } - norm_fac = extract_h( op1 ); + norm_fac = extract_h( op1 ); /* q_norm_fac - 16 */ q_norm_fac = sub( q_norm_fac, Q16 ); - g2 = Mpy_32_16_1( pPredGain[b], norm_fac ); - pred_gain_avg = Madd_32_16( Mpy_32_16_1( hStereoDft->past_res_pred_gain_fx[d_short_ind][b], g_short ), hStereoDft->past_res_pred_gain_fx[d_long_ind][b], g_long ); + g2 = Mpy_32_16_1( pPredGain[b], norm_fac ); /* Q31 */ + pred_gain_avg = Madd_32_16( Mpy_32_16_1( hStereoDft->past_res_pred_gain_fx[d_short_ind][b], g_short ), hStereoDft->past_res_pred_gain_fx[d_long_ind][b], g_long ); /* Q31 */ g2 = L_min( Mpy_32_16_1( pred_gain_avg, STEREO_DFT_STEFFI_GAIN_AMP_FX ), - Madd_32_16( Mpy_32_16_1( pred_gain_avg, sub( (Word16) ( 0x7FFF ), STEREO_DFT_STEFFI_GAIN_REST_AMT_FX ) ), g2, STEREO_DFT_STEFFI_GAIN_REST_AMT_FX ) ); + Madd_32_16( Mpy_32_16_1( pred_gain_avg, sub( (Word16) ( 0x7FFF ), STEREO_DFT_STEFFI_GAIN_REST_AMT_FX ) ), g2, STEREO_DFT_STEFFI_GAIN_REST_AMT_FX ) ); /* Q31 */ - FOR( i = s_max( hStereoDft->band_limits[b], bin0 ); i < s_min( hStereoDft->band_limits[b + 1], STEREO_DFT32MS_N_32k / 2 ); i++ ) + FOR( i = max( hStereoDft->band_limits[b], bin0 ); i < min( hStereoDft->band_limits[b + 1], STEREO_DFT32MS_N_32k / 2 ); i++ ) { - DFT_PRED_RES[2 * i] = Mpy_32_32( g2, DFT_PRED_RES[2 * i] ); + DFT_PRED_RES[2 * i] = Mpy_32_32( g2, DFT_PRED_RES[2 * i] ); /* Q31 */ move32(); - DFT_PRED_RES[add( shl( i, 1 ), 1 )] = Mpy_32_32( g2, DFT_PRED_RES[add( shl( i, 1 ), 1 )] ); + DFT_PRED_RES[2 * i + 1] = Mpy_32_32( g2, DFT_PRED_RES[2 * i + 1] ); /* Q31 */ move32(); } } ELSE { - begin = s_max( hStereoDft->band_limits[b], bin0 ); - end = s_min( hStereoDft->band_limits[b + 1], STEREO_DFT32MS_N_32k / 2 ); + begin = s_max( hStereoDft->band_limits[b], bin0 ); /* Q0 */ + end = s_min( hStereoDft->band_limits[b + 1], STEREO_DFT32MS_N_32k / 2 ); /* Q0 */ set32_fx( DFT_PRED_RES + shl( begin, 1 ), 0, shl( sub( end, begin ), 1 ) ); } } @@ -3169,12 +3176,12 @@ void stereo_dft_generate_res_pred_fx( test(); IF( hStereoDft->attackPresent || hStereoDft->wasTransient ) { - hStereoDft->past_res_pred_gain_fx[s_and( add( hStereoDft->past_DMX_pos, 1 ), ( STEREO_DFT_PAST_MAX - 1 ) )][b] = MIN_32; + hStereoDft->past_res_pred_gain_fx[( hStereoDft->past_DMX_pos + 1 ) % STEREO_DFT_PAST_MAX][b] = MIN_32; move32(); } ELSE { - hStereoDft->past_res_pred_gain_fx[s_and( add( hStereoDft->past_DMX_pos, 1 ), ( STEREO_DFT_PAST_MAX - 1 ) )][b] = pPredGain[b]; + hStereoDft->past_res_pred_gain_fx[( hStereoDft->past_DMX_pos + 1 ) % STEREO_DFT_PAST_MAX][b] = pPredGain[b]; move32(); } } @@ -3220,32 +3227,32 @@ static void stereo_dft_adapt_sf_delay_fx( max_pg = pPredGain[b]; move16(); } - sum_pg = L_add( sum_pg, L_shr( pPredGain[b], q_guard ) ); + sum_pg = L_add( sum_pg, L_shr( pPredGain[b], q_guard ) ); /* q_gurad */ } IF( GT_16( q_guard, hStereoDft->q_lt_pred_gain ) ) { - hStereoDft->lt_pred_gain_fx = L_shr( hStereoDft->lt_pred_gain_fx, sub( q_guard, hStereoDft->q_lt_pred_gain ) ); + hStereoDft->lt_pred_gain_fx = L_shr( hStereoDft->lt_pred_gain_fx, sub( q_guard, hStereoDft->q_lt_pred_gain ) ); /* q_guard */ hStereoDft->q_lt_pred_gain = q_guard; move16(); } ELSE { - sum_pg = L_shr( sum_pg, sub( hStereoDft->q_lt_pred_gain, q_guard ) ); + sum_pg = L_shr( sum_pg, sub( hStereoDft->q_lt_pred_gain, q_guard ) ); /* hStereoDft->q_lt_pred_gain */ q_guard = hStereoDft->q_lt_pred_gain; move16(); } IF( sum_pg > 0 ) { /* Calculate mean of the prediction gain */ - hStereoDft->lt_pred_gain_fx = Madd_32_16( Mpy_32_16_1( sum_pg, STEREO_DFT_LT_PREDGAIN_UPD_FX ), hStereoDft->lt_pred_gain_fx, sub( MAX_16, STEREO_DFT_LT_PREDGAIN_UPD_FX ) ); + hStereoDft->lt_pred_gain_fx = Madd_32_16( Mpy_32_16_1( sum_pg, STEREO_DFT_LT_PREDGAIN_UPD_FX ), hStereoDft->lt_pred_gain_fx, sub( MAX_16, STEREO_DFT_LT_PREDGAIN_UPD_FX ) ); /* hStereoDft->q_lt_pred_gain */ /* Calculate the variation of the prediction gain */ - new_variation = L_abs( L_sub( sum_pg, hStereoDft->lt_pred_gain_fx ) ); - hStereoDft->lt_pred_gain_variation_fx = Madd_32_16( Mpy_32_16_1( new_variation, STEREO_DFT_VR_PREDGAIN_UPD_FX ), hStereoDft->lt_pred_gain_variation_fx, sub( MAX_16, STEREO_DFT_VR_PREDGAIN_UPD_FX ) ); + new_variation = L_abs( L_sub( sum_pg, hStereoDft->lt_pred_gain_fx ) ); /* hStereoDft->q_lt_pred_gain */ + hStereoDft->lt_pred_gain_variation_fx = Madd_32_16( Mpy_32_16_1( new_variation, STEREO_DFT_VR_PREDGAIN_UPD_FX ), hStereoDft->lt_pred_gain_variation_fx, sub( MAX_16, STEREO_DFT_VR_PREDGAIN_UPD_FX ) ); /* hStereoDft->q_lt_pred_gain */ } /* Calculate ratio of variation and mean of prediction gain */ - var_mean_ratio = STEREO_DFT_RES_RATIO_LIMIT_FX; + var_mean_ratio = STEREO_DFT_RES_RATIO_LIMIT_FX; /* Q31 */ move16(); IF( hStereoDft->lt_pred_gain_fx > 0 ) @@ -3259,40 +3266,40 @@ static void stereo_dft_adapt_sf_delay_fx( } IF( LT_32( L_shr( STEREO_DFT_RES_RATIO_LIMIT_FX_3_BY_2, q_div ), opr2 ) ) { - var_mean_ratio = STEREO_DFT_RES_RATIO_LIMIT_FX_3_BY_2; + var_mean_ratio = STEREO_DFT_RES_RATIO_LIMIT_FX_3_BY_2; /* Q31 */ move32(); } ELSE { - var_mean_ratio = L_shl( opr2, q_div ); + var_mean_ratio = L_shl( opr2, q_div ); /* Q31 */ } } IF( GT_32( max_pg, STEREO_DFT_STEFFI_PG_THRESHOLD_FX ) ) { /* slow upwards */ - alpha_up = STEREO_DFT_STEFFI_RATIO_UP_HIGH_FX; + alpha_up = STEREO_DFT_STEFFI_RATIO_UP_HIGH_FX; /* Q31 */ move16(); - alpha_down = STEREO_DFT_STEFFI_RATIO_DOWN_HIGH_FX; + alpha_down = STEREO_DFT_STEFFI_RATIO_DOWN_HIGH_FX; /* Q31 */ move16(); } ELSE { /* slow downwards */ - alpha_up = STEREO_DFT_STEFFI_RATIO_UP_LOW_FX; + alpha_up = STEREO_DFT_STEFFI_RATIO_UP_LOW_FX; /* Q31 */ move16(); - alpha_down = STEREO_DFT_STEFFI_RATIO_DOWN_LOW_FX; + alpha_down = STEREO_DFT_STEFFI_RATIO_DOWN_LOW_FX; /* Q31 */ move16(); } IF( GT_16( extract_h( var_mean_ratio ), extract_h( hStereoDft->lt_var_mean_ratio_fx ) ) ) { - hStereoDft->lt_var_mean_ratio_fx = Madd_32_32( Mpy_32_32( var_mean_ratio, alpha_up ), hStereoDft->lt_var_mean_ratio_fx, L_sub( MAX_32, alpha_up ) ); + hStereoDft->lt_var_mean_ratio_fx = Madd_32_32( Mpy_32_32( var_mean_ratio, alpha_up ), hStereoDft->lt_var_mean_ratio_fx, L_sub( MAX_32, alpha_up ) ); /* Q31 */ move32(); } ELSE { - hStereoDft->lt_var_mean_ratio_fx = Madd_32_32( Mpy_32_32( var_mean_ratio, alpha_down ), hStereoDft->lt_var_mean_ratio_fx, L_sub( MAX_32, alpha_down ) ); + hStereoDft->lt_var_mean_ratio_fx = Madd_32_32( Mpy_32_32( var_mean_ratio, alpha_down ), hStereoDft->lt_var_mean_ratio_fx, L_sub( MAX_32, alpha_down ) ); /* Q31 */ move32(); } @@ -3300,7 +3307,7 @@ static void stereo_dft_adapt_sf_delay_fx( variation is relatively high compared to the mean */ IF( GE_16( extract_h( hStereoDft->lt_var_mean_ratio_fx ), extract_h( STEREO_DFT_RES_RATIO_LIMIT_FX ) ) ) { - target_delay = L_shl( STEREO_DFT_STEFFI_DELAY_SHORT, Q15 ); + target_delay = L_shl( STEREO_DFT_STEFFI_DELAY_SHORT, Q15 ); /* Q15 */ move32(); } ELSE @@ -3308,11 +3315,11 @@ static void stereo_dft_adapt_sf_delay_fx( target_delay = L_min( L_shl( STEREO_DFT_STEFFI_DELAY_LONG, Q15 ), L_add( L_shl( STEREO_DFT_STEFFI_DELAY_SHORT, Q15 ), L_mult0( ( STEREO_DFT_STEFFI_DELAY_OFFSET + STEREO_DFT_STEFFI_DELAY_LONG - STEREO_DFT_STEFFI_DELAY_SHORT ), - sub( MAX_16, extract_h( L_shl( Mpy_32_16_1( hStereoDft->lt_var_mean_ratio_fx, ONE_STEREO_DFT_RES_RATIO_LIMIT_Q12 ), Q3 ) ) ) ) ) ); + sub( MAX_16, extract_h( L_shl( Mpy_32_16_1( hStereoDft->lt_var_mean_ratio_fx, ONE_STEREO_DFT_RES_RATIO_LIMIT_Q12 ), Q3 ) ) ) ) ) ); /* Q15 */ } /* Adapt the stereo filling delay by interpolating between two delay taps, one at the shortest delay and one at the longest delay */ - hStereoDft->stefi_short_gain_fx = extract_l( L_shr( L_sub( L_shl( STEREO_DFT_STEFFI_DELAY_LONG, Q15 ), target_delay ), 1 ) ); + hStereoDft->stefi_short_gain_fx = extract_l( L_shr( L_sub( L_shl( STEREO_DFT_STEFFI_DELAY_LONG, Q15 ), target_delay ), 1 ) ); /* Q15 */ q_sqrt = 0; move16(); IF( EQ_16( hStereoDft->stefi_short_gain_fx, MIN_16 ) ) @@ -3326,10 +3333,10 @@ static void stereo_dft_adapt_sf_delay_fx( { op = hStereoDft->stefi_short_gain_fx; move16(); - hStereoDft->stefi_long_gain_fx = Sqrt16( sub( MAX_16, mult( op, op ) ), &q_sqrt ); + hStereoDft->stefi_long_gain_fx = Sqrt16( sub( MAX_16, mult( op, op ) ), &q_sqrt ); /* Q15 */ IF( q_sqrt != 0 ) { - hStereoDft->stefi_long_gain_fx = shl( hStereoDft->stefi_long_gain_fx, q_sqrt ); + hStereoDft->stefi_long_gain_fx = shl( hStereoDft->stefi_long_gain_fx, q_sqrt ); /* Q15 */ } } @@ -3337,9 +3344,9 @@ static void stereo_dft_adapt_sf_delay_fx( } void stereo_dft_dec_sid_coh_fx( Decoder_State *st, /* i/o: decoder state structure */ - const Word16 nbands, /* i : number of DFT stereo bands */ - Word16 *coh_fx, /* i/o: coherence */ - Word16 *nb_bits /* i/o: number of bits read */ + const Word16 nbands, /* i : number of DFT stereo bands Q0*/ + Word16 *coh_fx, /* i/o: coherence Q15*/ + Word16 *nb_bits /* i/o: number of bits read Q0*/ ) { Word16 alpha_fx; @@ -3356,17 +3363,17 @@ void stereo_dft_dec_sid_coh_fx( Word16 bits_tmp; Word16 b; - nr_of_sid_stereo_bits = ( IVAS_SID_5k2 - SID_2k40 ) / FRAMES_PER_SEC - SID_FORMAT_NBITS; + nr_of_sid_stereo_bits = ( IVAS_SID_5k2 - SID_2k40 ) / FRAMES_PER_SEC - SID_FORMAT_NBITS; /* Q0 */ move16(); /* If the coherence is not encoded due to lack of bits set alpha to zero which leads to that the coherence */ /* from the previous frame is used. */ - IF( GT_16( sub( sub( nr_of_sid_stereo_bits, *nb_bits ), STEREO_DFT_N_COH_ALPHA_BITS - STEREO_DFT_PRED_NBITS ), 0 ) ) + IF( sub( sub( nr_of_sid_stereo_bits, *nb_bits ), STEREO_DFT_N_COH_ALPHA_BITS - STEREO_DFT_PRED_NBITS ) > 0 ) { /* Read coherence from bitstream */ - coh_pred_index = get_next_indice_fx( st, STEREO_DFT_PRED_NBITS ); /* Read predictor index */ + coh_pred_index = get_next_indice_fx( st, STEREO_DFT_PRED_NBITS ); /* Read predictor index Q0*/ ( *nb_bits ) = add( ( *nb_bits ), STEREO_DFT_PRED_NBITS ); - alpha_index = get_next_indice_fx( st, STEREO_DFT_N_COH_ALPHA_BITS ); /* Read alpha index */ + alpha_index = get_next_indice_fx( st, STEREO_DFT_N_COH_ALPHA_BITS ); /* Read alpha index Q0*/ ( *nb_bits ) = add( ( *nb_bits ), STEREO_DFT_N_COH_ALPHA_BITS ); alpha_step = 0; @@ -3375,10 +3382,10 @@ void stereo_dft_dec_sid_coh_fx( { IF( GT_16( sub( nr_of_sid_stereo_bits, *nb_bits ), dft_cng_coh_alpha_start[i] ) ) { - alpha_step = add( i, 1 ); + alpha_step = i + 1; } } - alpha_fx = dft_cng_alpha_bits_fx[alpha_step][alpha_index]; /*Q-15*/ + alpha_fx = dft_cng_alpha_bits_fx[alpha_step][alpha_index]; /* Q15 */ move16(); } ELSE @@ -3390,12 +3397,12 @@ void stereo_dft_dec_sid_coh_fx( FOR( i = *nb_bits; i < nr_of_sid_stereo_bits; i++ ) { get_next_indice_fx( st, 1 ); - ( *nb_bits ) = add( ( *nb_bits ), 1 ); + ( *nb_bits )++; } } - pptr_fx = dft_cng_coh_pred_fx[coh_pred_index]; /*Q-13*/ - pred_fx = 3276; /*Q-13*/ + pptr_fx = dft_cng_coh_pred_fx[coh_pred_index]; /*Q13*/ + pred_fx = 3276; /*Q13*/ move16(); move16(); FOR( b = 0; b < nbands; b++ ) @@ -3412,9 +3419,9 @@ void stereo_dft_dec_sid_coh_fx( /* Read residual index from bitstream */ IF( LT_16( *nb_bits, nr_of_sid_stereo_bits ) ) /* If the bit limit is reached, res_index = 0 is assumed for remaining indices */ { - bits_tmp = read_GR0( &st->bit_stream[st->next_bit_pos], &res_index, 1 ); - *nb_bits = add( *nb_bits, bits_tmp ); - st->next_bit_pos = add( st->next_bit_pos, bits_tmp ); + bits_tmp = read_GR0( &st->bit_stream[st->next_bit_pos], &res_index, 1 ); /* Q0 */ + *nb_bits = add( *nb_bits, bits_tmp ); /* Q0 */ + st->next_bit_pos = add( st->next_bit_pos, bits_tmp ); /* Q0 */ move16(); move16(); } @@ -3425,13 +3432,13 @@ void stereo_dft_dec_sid_coh_fx( } /* Reconstruct */ - res_index = dft_cng_coh_u2i[res_index]; + res_index = dft_cng_coh_u2i[res_index]; /* Q0 */ move16(); - pred_err_fx = shr( usdequant_fx( res_index, -13107 /*Q-15*/, 1638 /*Q-14*/ ), 2 ); - cohBandq_fx[b] = add( pred_fx, pred_err_fx ); /* Store for intra-frame prediction */ + pred_err_fx = shr( usdequant_fx( res_index, -13107 /*Q-15*/, 1638 /*Q-14*/ ), 2 ); /* Q15 */ + cohBandq_fx[b] = add( pred_fx, pred_err_fx ); /* Store for intra-frame prediction */ IF( GT_16( cohBandq_fx[b], 8192 ) ) { - cohBandq_fx[b] = 8192; + cohBandq_fx[b] = 8192; /* Q13 */ move16(); } ELSE IF( cohBandq_fx[b] < 0 ) @@ -3439,7 +3446,7 @@ void stereo_dft_dec_sid_coh_fx( cohBandq_fx[b] = 0; move16(); } - coh_fx[b] = shl_sat( cohBandq_fx[b], 2 ); /* Update memory for next frame */ + coh_fx[b] = shl_sat( cohBandq_fx[b], 2 ); /* Update memory for next frame */ /* Q15 */ move16(); pred_fx = 0; move16(); @@ -3449,29 +3456,30 @@ void stereo_dft_dec_sid_coh_fx( FOR( i = *nb_bits; i < nr_of_sid_stereo_bits; i++ ) { get_next_indice_fx( st, 1 ); - ( *nb_bits ) = add( ( *nb_bits ), 1 ); + ( *nb_bits )++; } return; } void stereo_dft_dequantize_itd_fx( - Word16 *ind, - Word32 *out_fx, - const Word32 output_Fs ) + Word16 *ind, /* Q0 */ + Word32 *out_fx, /* Q15 */ + const Word32 output_Fs /* Q0 */ +) { Word16 itd; Word16 mask; - mask = ( 1 << ( STEREO_DFT_ITD_NBITS - 1 ) ) - 1; + mask = ( 1 << ( STEREO_DFT_ITD_NBITS - 1 ) ) - 1; /* Q0 */ move16(); - itd = s_and( ind[0], mask ) + STEREO_DFT_ITD_MIN; + itd = s_and( ind[0], mask ) + STEREO_DFT_ITD_MIN; /* Q0 */ IF( shr( ind[0], ( STEREO_DFT_ITD_NBITS - 1 ) ) ) { - itd = imult1616( -1, itd ); + itd = imult1616( -1, itd ); /* Q0 */ } assert( ( ABSVAL( itd ) <= STEREO_DFT_ITD_MAX ) && ( ABSVAL( itd ) >= STEREO_DFT_ITD_MIN ) ); /*Convert back @ fs*/ - *out_fx = L_mult( itd, divide3232( output_Fs, STEREO_DFT_ITD_FS << 1 ) ); /*Q-15*/ + *out_fx = L_mult( itd, divide3232( output_Fs, STEREO_DFT_ITD_FS << 1 ) ); /*Q15*/ move32(); return; } @@ -3482,17 +3490,17 @@ void stereo_dft_dequantize_itd_fx( *-------------------------------------------------------------------------*/ void stereo_dft_dec_read_BS_fx( - const Word32 ivas_total_brate, /* i : IVAS total bitrate */ - const Word32 element_brate, /* i : element bitrate */ - Word32 *total_brate, /* o : total bitrate */ - Decoder_State *st, /* i/o: decoder state structure */ - STEREO_DFT_DEC_DATA_HANDLE hStereoDft, /* i/o: decoder stereo handle */ - const Word16 bwidth, /* i : bandwidth */ - const Word16 output_frame, /* i : output frame length */ - Word32 res_buf_fx[STEREO_DFT_N_8k], /* o : residual buffer */ - Word16 *nb_bits, /* o : number of bits read */ - Word16 *coh_fx, /* i/o: Coherence */ - const Word16 ivas_format /* i : ivas format */ + const Word32 ivas_total_brate, /* i : IVAS total bitrate Q0*/ + const Word32 element_brate, /* i : element bitrate Q0*/ + Word32 *total_brate, /* o : total bitrate Q0*/ + Decoder_State *st, /* i/o: decoder state structure */ + STEREO_DFT_DEC_DATA_HANDLE hStereoDft, /* i/o: decoder stereo handle */ + const Word16 bwidth, /* i : bandwidth Q0*/ + const Word16 output_frame, /* i : output frame length Q0*/ + Word32 res_buf_fx[STEREO_DFT_N_8k], /* o : residual buffer Q0*/ + Word16 *nb_bits, /* o : number of bits read Q0*/ + Word16 *coh_fx, /* i/o: Coherence Q15*/ + const Word16 ivas_format /* i : ivas format Q0*/ ) { Word32 sg_tmp_fx[STEREO_DFT_BAND_MAX]; @@ -3517,7 +3525,7 @@ void stereo_dft_dec_read_BS_fx( * Initialization *-----------------------------------------------------------------*/ - k_offset = STEREO_DFT_OFFSET; + k_offset = STEREO_DFT_OFFSET; /* Q0 */ move16(); IF( EQ_32( ivas_total_brate, IVAS_SID_5k2 ) ) @@ -3534,7 +3542,7 @@ void stereo_dft_dec_read_BS_fx( hStereoDft->frame_nodata = 0; hStereoDft->frame_sid_nodata = 1; hStereoDft->frame_sid = 1; - *nb_bits = ( IVAS_SID_5k2 - SID_2k40 ) / FRAMES_PER_SEC - SID_FORMAT_NBITS; + *nb_bits = ( IVAS_SID_5k2 - SID_2k40 ) / FRAMES_PER_SEC - SID_FORMAT_NBITS; /* Q0 */ } move16(); move16(); @@ -3548,8 +3556,8 @@ void stereo_dft_dec_read_BS_fx( hStereoDft->frame_sid = 0; *nb_bits = 0; *total_brate = 0; - hStereoDft->itd_fx[k = hStereoDft->prm_res[k_offset] - 1 + k_offset] = hStereoDft->itd_xfade_target_fx; - hStereoDft->gipd_fx[hStereoDft->prm_res[k_offset] - 1 + k_offset] = hStereoDft->ipd_xfade_target_fx; + hStereoDft->itd_fx[k = hStereoDft->prm_res[k_offset] - 1 + k_offset] = hStereoDft->itd_xfade_target_fx; /* Q15 */ + hStereoDft->gipd_fx[hStereoDft->prm_res[k_offset] - 1 + k_offset] = hStereoDft->ipd_xfade_target_fx; /* Q27 */ move16(); move16(); @@ -3569,7 +3577,7 @@ void stereo_dft_dec_read_BS_fx( move16(); move16(); - st->total_brate = L_mult0( *nb_bits, FRAMES_PER_SEC ); + st->total_brate = L_mult0( *nb_bits, FRAMES_PER_SEC ); /* Q0 */ } hStereoDft->reverb_flag = 0; @@ -3578,7 +3586,7 @@ void stereo_dft_dec_read_BS_fx( /* reverse the bitstream */ FOR( b = 0; b < *nb_bits; b++ ) { - bit_stream_side[b] = st->bit_stream[-b]; + bit_stream_side[b] = st->bit_stream[-b]; /* Q0 */ move16(); } @@ -3588,12 +3596,12 @@ void stereo_dft_dec_read_BS_fx( bit_stream_side[b] = 0; move16(); } - st->bit_stream = bit_stream_side; + st->bit_stream = bit_stream_side; /* Q0 */ /*init*/ - max_bits = *nb_bits; + max_bits = *nb_bits; /* Q0 */ *nb_bits = 0; - N_div = STEREO_DFT_NBDIV; + N_div = STEREO_DFT_NBDIV; /* Q0 */ move16(); move16(); @@ -3612,7 +3620,7 @@ void stereo_dft_dec_read_BS_fx( } ELSE { - hStereoDft->attackPresent = get_next_indice_fx( st, 1 ); + hStereoDft->attackPresent = get_next_indice_fx( st, 1 ); /* Q0 */ ( *nb_bits ) = add( ( *nb_bits ), 1 ); move16(); move16(); @@ -3622,7 +3630,7 @@ void stereo_dft_dec_read_BS_fx( test(); IF( EQ_16( bwidth, WB ) && hStereoDft->hConfig->ada_wb_res_cod_mode ) { - hStereoDft->res_cod_mode[k_offset] = get_next_indice_fx( st, 1 ); + hStereoDft->res_cod_mode[k_offset] = get_next_indice_fx( st, 1 ); /* Q0 */ move16(); ( *nb_bits ) = add( ( *nb_bits ), 1 ); move16(); @@ -3631,43 +3639,43 @@ void stereo_dft_dec_read_BS_fx( /* read number of bands in the bitstream - depends on the audio bandwidth and not to output_Fs */ IF( hStereoDft->frame_sid ) { - NFFT_inner = imult1616( inner_frame_tbl[bwidth], STEREO_DFT32MS_N_MAX / L_FRAME48k ); + NFFT_inner = imult1616( inner_frame_tbl[bwidth], STEREO_DFT32MS_N_MAX / L_FRAME48k ); /* Q0 */ } ELSE { - NFFT_inner = imult1616( inner_frame_tbl[st->bwidth], STEREO_DFT32MS_N_MAX / L_FRAME48k ); + NFFT_inner = imult1616( inner_frame_tbl[st->bwidth], STEREO_DFT32MS_N_MAX / L_FRAME48k ); /* Q0 */ } /* Use coarse band partition in inactive frames */ IF( hStereoDft->frame_sid ) { - hStereoDft->band_res[k_offset] = STEREO_DFT_BAND_RES_LOW; - hStereoDft->res_cod_mode[k_offset] = STEREO_DFT_RES_COD_OFF; + hStereoDft->band_res[k_offset] = STEREO_DFT_BAND_RES_LOW; /* Q0 */ + hStereoDft->res_cod_mode[k_offset] = STEREO_DFT_RES_COD_OFF; /* Q0 */ move16(); move16(); - hStereoDft->nbands = stereo_dft_band_config_fx( hStereoDft->band_limits, hStereoDft->band_res[k_offset], s_min( STEREO_DFT32MS_N_MAX, NFFT_inner ), DEC ); + hStereoDft->nbands = stereo_dft_band_config_fx( hStereoDft->band_limits, hStereoDft->band_res[k_offset], s_min( STEREO_DFT32MS_N_MAX, NFFT_inner ), DEC ); /* Q0 */ IF( hStereoDft->nbands > STEREO_DFT_COH_MAXBAND ) { - hStereoDft->band_limits[STEREO_DFT_COH_MAXBAND] = hStereoDft->band_limits[hStereoDft->nbands]; - hStereoDft->nbands = STEREO_DFT_COH_MAXBAND; + hStereoDft->band_limits[STEREO_DFT_COH_MAXBAND] = hStereoDft->band_limits[hStereoDft->nbands]; /* Q0 */ + hStereoDft->nbands = STEREO_DFT_COH_MAXBAND; /* Q0 */ move16(); move16(); } } ELSE { - hStereoDft->nbands = stereo_dft_band_config_fx( hStereoDft->band_limits, hStereoDft->band_res[k_offset], NFFT_inner, DEC ); + hStereoDft->nbands = stereo_dft_band_config_fx( hStereoDft->band_limits, hStereoDft->band_res[k_offset], NFFT_inner, DEC ); /* Q0 */ move16(); } - hStereoDft->res_cod_band_max = dft_band_res_cod[hStereoDft->band_res[k_offset]][hStereoDft->res_cod_mode[k_offset]]; + hStereoDft->res_cod_band_max = dft_band_res_cod[hStereoDft->band_res[k_offset]][hStereoDft->res_cod_mode[k_offset]]; /* Q0 */ move16(); - hStereoDft->res_cod_line_max = (Word16) L_shr( L_add( ( 1 << Q13 ) /*0.5f Q-14*/, L_shl( L_mult0( sub( hStereoDft->band_limits[hStereoDft->res_cod_band_max], 1 ), divide1616( shr( output_frame, 1 ), ( hStereoDft->NFFT ) ) ) /*Q-14*/, 1 ) ), Q14 ); + hStereoDft->res_cod_line_max = (Word16) L_shr( L_add( ( 1 << Q13 ) /*0.5f Q-14*/, L_shl( L_mult0( sub( hStereoDft->band_limits[hStereoDft->res_cod_band_max], 1 ), divide1616( shr( output_frame, 1 ), ( hStereoDft->NFFT ) ) ) /*Q-14*/, 1 ) ), Q14 ); /* Q0 */ move16(); - hStereoDft->res_cod_line_max = shl( shr( hStereoDft->res_cod_line_max, 3 ), 3 ); + hStereoDft->res_cod_line_max = shl( shr( hStereoDft->res_cod_line_max, 3 ), 3 ); /* Q0 */ move16(); - hStereoDft->res_pred_band_min = s_max( STEREO_DFT_RES_PRED_BAND_MIN, hStereoDft->res_cod_band_max ); + hStereoDft->res_pred_band_min = s_max( STEREO_DFT_RES_PRED_BAND_MIN, hStereoDft->res_cod_band_max ); /* Q0 */ move16(); @@ -3706,49 +3714,49 @@ void stereo_dft_dec_read_BS_fx( nb = st->next_bit_pos; move16(); move16(); - n_bits = read_flag_EC_DFT( &st->bit_stream[nb], &hStereoDft->side_gain_flag_1 ); + n_bits = read_flag_EC_DFT( &st->bit_stream[nb], &hStereoDft->side_gain_flag_1 ); /* Q0 */ nb = add( nb, n_bits ); IF( hStereoDft->side_gain_flag_1 == 0 ) { - b = read_BS_adapt_GR_sg( st->bit_stream, nb, ind1, hStereoDft->nbands, &hStereoDft->side_gain_flag_2, dft_maps_sg ); - n_bits = add( n_bits, b ); + b = read_BS_adapt_GR_sg( st->bit_stream, nb, ind1, hStereoDft->nbands, &hStereoDft->side_gain_flag_2, dft_maps_sg ); /* Q0 */ + n_bits = add( n_bits, b ); /* Q0 */ } ELSE { IF( EQ_16( hStereoDft->side_gain_flag_1, 2 ) ) /* differential */ { - b = read_BS_GR( st->bit_stream, nb, ind1, hStereoDft->nbands, &hStereoDft->side_gain_flag_2 ); - n_bits = add( n_bits, b ); + b = read_BS_GR( st->bit_stream, nb, ind1, hStereoDft->nbands, &hStereoDft->side_gain_flag_2 ); /* Q0 */ + n_bits = add( n_bits, b ); /* Q0 */ FOR( b = 0; b < hStereoDft->nbands; b++ ) { - ind1[b] = add( ind1[b], hStereoDft->side_gain_index_previous[b] ); + ind1[b] = add( ind1[b], hStereoDft->side_gain_index_previous[b] ); /* Q0 */ } } ELSE { FOR( b = 0; b < hStereoDft->nbands; b++ ) { - ind1[b] = get_value( &st->bit_stream[nb], STEREO_DFT_SIDEGAIN_NBITS ); - nb = add( nb, STEREO_DFT_SIDEGAIN_NBITS ); - n_bits = add( n_bits, STEREO_DFT_SIDEGAIN_NBITS ); + ind1[b] = get_value( &st->bit_stream[nb], STEREO_DFT_SIDEGAIN_NBITS ); /* Q0 */ + nb = add( nb, STEREO_DFT_SIDEGAIN_NBITS ); /* Q0 */ + n_bits = add( n_bits, STEREO_DFT_SIDEGAIN_NBITS ); /* Q0 */ } } } FOR( b = 0; b < hStereoDft->nbands; b++ ) { - hStereoDft->side_gain_index_previous[b] = ind1[b]; + hStereoDft->side_gain_index_previous[b] = ind1[b]; /* Q0 */ move16(); #ifdef FIX_860_FER_CRASH - hStereoDft->res_gains_ind_fx[0][b + STEREO_DFT_BAND_MAX] = L_shl_sat( ind1[b], 26 ); + hStereoDft->res_gains_ind_fx[0][b + STEREO_DFT_BAND_MAX] = L_shl_sat( ind1[b], 26 ); /* Q26 */ #else hStereoDft->res_gains_ind_fx[0][b + STEREO_DFT_BAND_MAX] = L_shl( ind1[b], 26 ); #endif move32(); } - st->next_bit_pos = add( st->next_bit_pos, n_bits ); + st->next_bit_pos = add( st->next_bit_pos, n_bits ); /* Q0 */ ( *nb_bits ) = add( ( *nb_bits ), n_bits ); move16(); move16(); @@ -3760,34 +3768,34 @@ void stereo_dft_dec_read_BS_fx( IF( !hStereoDft->frame_sid_nodata ) { - itd_mode = get_next_indice_fx( st, STEREO_DFT_ITD_MODE_NBITS ); - ( *nb_bits ) = add( ( *nb_bits ), STEREO_DFT_ITD_MODE_NBITS ); /*ITD mode flag: 1bit*/ + itd_mode = get_next_indice_fx( st, STEREO_DFT_ITD_MODE_NBITS ); /* Q0 */ + ( *nb_bits ) = add( ( *nb_bits ), STEREO_DFT_ITD_MODE_NBITS ); /*ITD mode flag: 1bit Q0*/ move16(); hStereoDft->itd_fx[k + k_offset] = 0; move32(); IF( itd_mode ) { - ( *nb_bits ) = add( ( *nb_bits ), read_itd( st, &I ) ); + ( *nb_bits ) = add( ( *nb_bits ), read_itd( st, &I ) ); /* Q0 */ move16(); stereo_dft_dequantize_itd_fx( &I, hStereoDft->itd_fx + add( k, k_offset ), st->output_Fs ); } } ELSE IF( LE_16( *nb_bits, ( ( IVAS_SID_5k2 - SID_2k40 ) / FRAMES_PER_SEC - STEREO_DFT_ITD_MODE_NBITS - STEREO_DFT_SID_ITD_NBITS - 1 - SID_FORMAT_NBITS ) ) ) { - itd_mode = get_next_indice_fx( st, STEREO_DFT_ITD_MODE_NBITS ); - ( *nb_bits ) = add( ( *nb_bits ), STEREO_DFT_ITD_MODE_NBITS ); /*ITD mode flag: 1bit*/ + itd_mode = get_next_indice_fx( st, STEREO_DFT_ITD_MODE_NBITS ); /* Q0 */ + ( *nb_bits ) = add( ( *nb_bits ), STEREO_DFT_ITD_MODE_NBITS ); /*ITD mode flag: 1bit*/ move16(); - hStereoDft->itd_fx[add( k, k_offset )] = 0; + hStereoDft->itd_fx[k + k_offset] = 0; /* Q0 */ move32(); IF( itd_mode ) { - sign_flag = get_next_indice_fx( st, 1 ); - I = get_next_indice_fx( st, STEREO_DFT_SID_ITD_NBITS ); - ( *nb_bits ) = add( ( *nb_bits ), STEREO_DFT_SID_ITD_NBITS + 1 ); + sign_flag = get_next_indice_fx( st, 1 ); /* Q0 */ + I = get_next_indice_fx( st, STEREO_DFT_SID_ITD_NBITS ); /* Q0 */ + ( *nb_bits ) = add( ( *nb_bits ), STEREO_DFT_SID_ITD_NBITS + 1 ); /* Q0 */ move16(); - I = shl( I, STEREO_DFT_SID_ITD_FAC ); - I = add( I, shl( sign_flag, 8 ) ); + I = shl( I, STEREO_DFT_SID_ITD_FAC ); /* Q0 */ + I = add( I, shl( sign_flag, 8 ) ); /* Q0 */ stereo_dft_dequantize_itd_fx( &I, hStereoDft->itd_fx + add( k, k_offset ), st->output_Fs ); } } @@ -3798,22 +3806,22 @@ void stereo_dft_dec_read_BS_fx( n_bits = 0; move16(); - nb = st->next_bit_pos; + nb = st->next_bit_pos; /* Q0 */ move16(); IF( !hStereoDft->frame_sid_nodata ) { /* Active frame */ - hStereoDft->no_ipd_flag = st->bit_stream[nb]; + hStereoDft->no_ipd_flag = st->bit_stream[nb]; /* Q0 */ move16(); - nb = add( nb, 1 ); - n_bits = add( n_bits, 1 ); + nb = add( nb, 1 ); /* Q0 */ + n_bits = add( n_bits, 1 ); /* Q0 */ IF( hStereoDft->no_ipd_flag == 0 ) { - ind1_ipd[0] = get_value( &st->bit_stream[nb], STEREO_DFT_GIPD_NBITS ); + ind1_ipd[0] = get_value( &st->bit_stream[nb], STEREO_DFT_GIPD_NBITS ); /* Q0 */ move16(); - nb = add( nb, STEREO_DFT_GIPD_NBITS ); - n_bits = add( n_bits, STEREO_DFT_GIPD_NBITS ); + nb = add( nb, STEREO_DFT_GIPD_NBITS ); /* Q0 */ + n_bits = add( n_bits, STEREO_DFT_GIPD_NBITS ); /* Q0 */ #ifndef FIX_874_INCREASE_IPD_PRECISION stereo_dft_dequantize_ipd_fx( &ind1_ipd[0], hStereoDft->gipd_fx + add( k, k_offset ), 1, STEREO_DFT_GIPD_NBITS ); #else @@ -3824,16 +3832,16 @@ void stereo_dft_dec_read_BS_fx( ELSE IF( LE_16( *nb_bits, ( ( IVAS_SID_5k2 - SID_2k40 ) / FRAMES_PER_SEC - STEREO_DFT_FLAG_BITS - STEREO_DFT_SID_GIPD_NBITS - SID_FORMAT_NBITS ) ) ) { /* SID frame, only read IPD only if enough bits left in bitstream */ - hStereoDft->no_ipd_flag = st->bit_stream[nb]; + hStereoDft->no_ipd_flag = st->bit_stream[nb]; /* Q0 */ move16(); - nb = add( nb, 1 ); - n_bits = add( n_bits, 1 ); + nb = add( nb, 1 ); /* Q0 */ + n_bits = add( n_bits, 1 ); /* Q0 */ IF( hStereoDft->no_ipd_flag == 0 ) { - ind1_ipd[0] = get_value( &st->bit_stream[nb], STEREO_DFT_SID_GIPD_NBITS ); + ind1_ipd[0] = get_value( &st->bit_stream[nb], STEREO_DFT_SID_GIPD_NBITS ); /* Q0 */ move16(); - nb = add( nb, STEREO_DFT_SID_GIPD_NBITS ); - n_bits = add( n_bits, STEREO_DFT_SID_GIPD_NBITS ); + nb = add( nb, STEREO_DFT_SID_GIPD_NBITS ); /* Q0 */ + n_bits = add( n_bits, STEREO_DFT_SID_GIPD_NBITS ); /* Q0 */ #ifndef FIX_874_INCREASE_IPD_PRECISION stereo_dft_dequantize_ipd_fx( &ind1_ipd[0], hStereoDft->gipd_fx + add( k, k_offset ), 1, STEREO_DFT_SID_GIPD_NBITS ); #else @@ -3843,12 +3851,12 @@ void stereo_dft_dec_read_BS_fx( } ELSE { - hStereoDft->no_ipd_flag = 1; + hStereoDft->no_ipd_flag = 1; /* Q0 */ move16(); } - st->next_bit_pos = add( st->next_bit_pos, n_bits ); - ( *nb_bits ) = add( ( *nb_bits ), n_bits ); + st->next_bit_pos = add( st->next_bit_pos, n_bits ); /* Q0 */ + ( *nb_bits ) = add( ( *nb_bits ), n_bits ); /* Q0 */ move16(); move16(); @@ -3858,7 +3866,7 @@ void stereo_dft_dec_read_BS_fx( /* Residual prediction */ /* Switch it off if ITD detected */ n_bits = 0; - nb = st->next_bit_pos; + nb = st->next_bit_pos; /* Q0 */ move16(); move16(); @@ -3866,49 +3874,49 @@ void stereo_dft_dec_read_BS_fx( IF( !hStereoDft->frame_sid_nodata ) { test(); - IF( hStereoDft->res_pred_mode[add( k, k_offset )] && hStereoDft->attackPresent == 0 ) + IF( hStereoDft->res_pred_mode[k + k_offset] && hStereoDft->attackPresent == 0 ) { - nbands = s_min( hStereoDft->nbands, STEREO_DFT_RES_PRED_BAND_MAX ); + nbands = s_min( hStereoDft->nbands, STEREO_DFT_RES_PRED_BAND_MAX ); /* Q0 */ hStereoDft->reverb_flag = 0; - hStereoDft->nbands_respred = nbands; + hStereoDft->nbands_respred = nbands; /* Q0 */ move16(); move16(); /* Read bit for adaptive SF (WB/SWB & FB) */ IF( EQ_16( hStereoDft->hConfig->res_cod_mode, STEREO_DFT_RES_COD_OFF ) ) { - hStereoDft->reverb_flag = get_next_indice_fx( st, STEREO_DFT_REVERB_MODE_NBITS ); - ( *nb_bits ) = add( ( *nb_bits ), STEREO_DFT_REVERB_MODE_NBITS ); + hStereoDft->reverb_flag = get_next_indice_fx( st, STEREO_DFT_REVERB_MODE_NBITS ); /* Q0 */ + ( *nb_bits ) = add( ( *nb_bits ), STEREO_DFT_REVERB_MODE_NBITS ); /* Q0 */ move16(); move16(); - nb = add( nb, STEREO_DFT_REVERB_MODE_NBITS ); + nb = add( nb, STEREO_DFT_REVERB_MODE_NBITS ); /* Q0 */ IF( hStereoDft->reverb_flag ) { - nbands = sub( nbands, STEREO_DFT_RES_PRED_BAND_MIN_CONST ); + nbands = sub( nbands, STEREO_DFT_RES_PRED_BAND_MIN_CONST ); /* Q0 */ } } /* get coding type */ - b = read_flag_EC_DFT( &st->bit_stream[nb], &hStereoDft->res_pred_flag_0 ); - nb = add( nb, b ); - n_bits = add( n_bits, b ); + b = read_flag_EC_DFT( &st->bit_stream[nb], &hStereoDft->res_pred_flag_0 ); /* Q0 */ + nb = add( nb, b ); /* Q0 */ + n_bits = add( n_bits, b ); /* Q0 */ IF( hStereoDft->res_pred_flag_0 == 0 ) { - b = read_BS_adapt_GR_rpg( st->bit_stream, nb, ind1_pred, hStereoDft->res_pred_band_min, nbands, &hStereoDft->res_pred_flag_1 ); - n_bits = add( n_bits, b ); + b = read_BS_adapt_GR_rpg( st->bit_stream, nb, ind1_pred, hStereoDft->res_pred_band_min, nbands, &hStereoDft->res_pred_flag_1 ); /* Q0 */ + n_bits = add( n_bits, b ); /* Q0 */ } ELSE { IF( EQ_16( hStereoDft->res_pred_flag_0, 2 ) ) { - b = read_BS_GR( st->bit_stream, nb, &ind1_pred[hStereoDft->res_pred_band_min], nbands - hStereoDft->res_pred_band_min, &hStereoDft->res_pred_flag_1 ); + b = read_BS_GR( st->bit_stream, nb, &ind1_pred[hStereoDft->res_pred_band_min], nbands - hStereoDft->res_pred_band_min, &hStereoDft->res_pred_flag_1 ); /* Q0 */ - n_bits = add( n_bits, b ); + n_bits = add( n_bits, b ); /* Q0 */ FOR( b = hStereoDft->res_pred_band_min; b < nbands; b++ ) { - ind1_pred[b] = add( ind1_pred[b], hStereoDft->res_pred_index_previous[b] ); + ind1_pred[b] = add( ind1_pred[b], hStereoDft->res_pred_index_previous[b] ); /* Q0 */ move16(); } } @@ -3916,10 +3924,10 @@ void stereo_dft_dec_read_BS_fx( { FOR( b = hStereoDft->res_pred_band_min; b < nbands; b++ ) { - ind1_pred[b] = get_value( &st->bit_stream[nb], STEREO_DFT_RES_GAINS_BITS ); + ind1_pred[b] = get_value( &st->bit_stream[nb], STEREO_DFT_RES_GAINS_BITS ); /* Q0 */ move16(); - nb = add( nb, STEREO_DFT_RES_GAINS_BITS ); - n_bits = add( n_bits, STEREO_DFT_RES_GAINS_BITS ); + nb = add( nb, STEREO_DFT_RES_GAINS_BITS ); /* Q0 */ + n_bits = add( n_bits, STEREO_DFT_RES_GAINS_BITS ); /* Q0 */ } } } @@ -3929,21 +3937,21 @@ void stereo_dft_dec_read_BS_fx( I = 0; move16(); stereo_dft_dequantize_res_gains_fx( ind1 + b, &I, hStereoDft->side_gain_fx + add( i_mult( add( k, k_offset ), STEREO_DFT_BAND_MAX ), b ), hStereoDft->res_pred_gain_fx + add( i_mult( add( k, k_offset ), STEREO_DFT_BAND_MAX ), b ), 1 ); - hStereoDft->res_pred_index_previous[b] = I; + hStereoDft->res_pred_index_previous[b] = I; /* Q0 */ move16(); - hStereoDft->res_gains_ind_fx[1][b + STEREO_DFT_BAND_MAX] = 0; + hStereoDft->res_gains_ind_fx[1][b + STEREO_DFT_BAND_MAX] = 0; /* Q26 */ move32(); } FOR( b = hStereoDft->res_pred_band_min; b < nbands; b++ ) { - I = ind1_pred[b]; + I = ind1_pred[b]; /* Q0 */ move16(); stereo_dft_dequantize_res_gains_fx( ind1 + b, &I, hStereoDft->side_gain_fx + add( i_mult( add( k, k_offset ), STEREO_DFT_BAND_MAX ), b ), hStereoDft->res_pred_gain_fx + add( i_mult( add( k, k_offset ), STEREO_DFT_BAND_MAX ), b ), 1 ); - hStereoDft->res_pred_index_previous[b] = I; + hStereoDft->res_pred_index_previous[b] = I; /* Q0 */ move16(); #ifdef FIX_860_FER_CRASH - hStereoDft->res_gains_ind_fx[1][b + STEREO_DFT_BAND_MAX] = L_shl_sat( I, 26 ); + hStereoDft->res_gains_ind_fx[1][b + STEREO_DFT_BAND_MAX] = L_shl_sat( I, 26 ); /* Q26 */ #else hStereoDft->res_gains_ind_fx[1][b + STEREO_DFT_BAND_MAX] = L_shl( I, 26 ); #endif @@ -3956,9 +3964,9 @@ void stereo_dft_dec_read_BS_fx( move16(); stereo_dft_dequantize_res_gains_fx( ind1 + b, &I, hStereoDft->side_gain_fx + add( i_mult( add( k, k_offset ), STEREO_DFT_BAND_MAX ), b ), hStereoDft->res_pred_gain_fx + add( i_mult( add( k, k_offset ), STEREO_DFT_BAND_MAX ), b ), 1 ); move16(); - hStereoDft->res_pred_index_previous[b] = I; + hStereoDft->res_pred_index_previous[b] = I; /* Q0 */ move16(); - hStereoDft->res_gains_ind_fx[1][b + STEREO_DFT_BAND_MAX] = 0; + hStereoDft->res_gains_ind_fx[1][b + STEREO_DFT_BAND_MAX] = 0; /* Q26 */ move32(); } } @@ -3969,10 +3977,10 @@ void stereo_dft_dec_read_BS_fx( I = 0; move16(); stereo_dft_dequantize_res_gains_fx( ind1 + b, &I, hStereoDft->side_gain_fx + add( i_mult( add( k, k_offset ), STEREO_DFT_BAND_MAX ), b ), hStereoDft->res_pred_gain_fx + add( i_mult( add( k, k_offset ), STEREO_DFT_BAND_MAX ), b ), 1 ); - hStereoDft->res_pred_index_previous[b] = I; + hStereoDft->res_pred_index_previous[b] = I; /* Q0 */ move16(); #ifdef FIX_860_FER_CRASH - hStereoDft->res_gains_ind_fx[1][b + STEREO_DFT_BAND_MAX] = L_shl_sat( I, 26 ); + hStereoDft->res_gains_ind_fx[1][b + STEREO_DFT_BAND_MAX] = L_shl_sat( I, 26 ); /* Q26 */ #else hStereoDft->res_gains_ind_fx[1][b + STEREO_DFT_BAND_MAX] = L_shl( I, 26 ); #endif @@ -3980,8 +3988,8 @@ void stereo_dft_dec_read_BS_fx( } } - st->next_bit_pos = add( st->next_bit_pos, n_bits ); - ( *nb_bits ) = add( ( *nb_bits ), n_bits ); + st->next_bit_pos = add( st->next_bit_pos, n_bits ); /* Q0 */ + ( *nb_bits ) = add( ( *nb_bits ), n_bits ); /* Q0 */ move16(); move16(); } @@ -4014,12 +4022,12 @@ void stereo_dft_dec_read_BS_fx( IF( GT_32( ivas_total_brate, IVAS_SID_5k2 ) ) { // hStereoDft->recovery_flg = stereo_dft_sg_recovery( hStereoDft ); - hStereoDft->recovery_flg = stereo_dft_sg_recovery_fx( hStereoDft ); + hStereoDft->recovery_flg = stereo_dft_sg_recovery_fx( hStereoDft ); /* Q0 */ IF( hStereoDft->recovery_flg ) { - Copy32( sg_tmp_fx, hStereoDft->side_gain_fx + 2 * STEREO_DFT_BAND_MAX, STEREO_DFT_BAND_MAX ); - Copy32( res_pred_gain_tmp_fx, hStereoDft->res_pred_gain_fx + 2 * STEREO_DFT_BAND_MAX, STEREO_DFT_BAND_MAX ); + Copy32( sg_tmp_fx, hStereoDft->side_gain_fx + 2 * STEREO_DFT_BAND_MAX, STEREO_DFT_BAND_MAX ); /* Q31 */ + Copy32( res_pred_gain_tmp_fx, hStereoDft->res_pred_gain_fx + 2 * STEREO_DFT_BAND_MAX, STEREO_DFT_BAND_MAX ); /* Q31 */ } } @@ -4033,8 +4041,8 @@ void stereo_dft_dec_read_BS_fx( { Word16 dec[STEREO_DFT_N_MAX_RES]; - I = get_next_indice_fx( st, STEREO_DFT_RES_GLOBAL_GAIN_BITS ); - ( *nb_bits ) = add( ( *nb_bits ), STEREO_DFT_RES_GLOBAL_GAIN_BITS ); + I = get_next_indice_fx( st, STEREO_DFT_RES_GLOBAL_GAIN_BITS ); /* Q0 */ + ( *nb_bits ) = add( ( *nb_bits ), STEREO_DFT_RES_GLOBAL_GAIN_BITS ); /* Q0 */ move16(); move16(); @@ -4045,24 +4053,24 @@ void stereo_dft_dec_read_BS_fx( rc_uni_dec_init_fx( &range_uni_dec_state, bit_stream_side + *nb_bits, max_bits - *nb_bits ); - hStereoDft->res_global_gain_fx = ECSQ_dequantize_gain_fx( I ); + hStereoDft->res_global_gain_fx = ECSQ_dequantize_gain_fx( I ); /* Q15 */ move32(); #ifdef DEBUGGING dbgwrite_txt( (const float *) ( &hStereoDft->res_global_gain_fx ), 1, "fixed_res_global_gain.txt", NULL ); #endif - ecsq_inst.config_index = sub( shl( hStereoDft->res_cod_mode[k_offset], 1 ), 1 ); + ecsq_inst.config_index = sub( shl( hStereoDft->res_cod_mode[k_offset], 1 ), 1 ); /* Q0 */ move16(); ECSQ_decode( &ecsq_inst, hStereoDft->res_cod_line_max, dec ); - n_bits = rc_uni_dec_virtual_finish_fx( &range_uni_dec_state ); + n_bits = rc_uni_dec_virtual_finish_fx( &range_uni_dec_state ); /* Q0 */ set_zero_fx( res_buf_fx, STEREO_DFT_N_8k ); FOR( Word16 c = 0; c < hStereoDft->res_cod_line_max; c++ ) { - dec[c] = shl_sat( dec[c], 8 ); + dec[c] = shl_sat( dec[c], 8 ); /* Q0 */ move16(); } @@ -4082,7 +4090,7 @@ void stereo_dft_dec_read_BS_fx( set_zero_fx( res_buf_fx, STEREO_DFT_N_8k ); } - ( *nb_bits ) = add( ( *nb_bits ), n_bits ); + ( *nb_bits ) = add( ( *nb_bits ), n_bits ); /* Q0 */ pop_wmops(); } @@ -4096,11 +4104,11 @@ void stereo_dft_dec_read_BS_fx( test(); IF( EQ_32( ivas_total_brate, IVAS_SID_5k2 ) && NE_16( ivas_format, MASA_FORMAT ) ) { - *nb_bits = (Word16) Mult_32_16( L_sub( element_brate, SID_2k40 ), INV_FRAME_PER_SEC_Q15 ); /* => hCPE->hCoreCoder[0]->total_brate = SID_2k40; */ + *nb_bits = (Word16) Mult_32_16( L_sub( element_brate, SID_2k40 ), INV_FRAME_PER_SEC_Q15 ); /* => hCPE->hCoreCoder[0]->total_brate = SID_2k40; Q0*/ move16(); } { - *total_brate = L_sub( element_brate, L_mult0( *nb_bits, FRAMES_PER_SEC ) ); + *total_brate = L_sub( element_brate, L_mult0( *nb_bits, FRAMES_PER_SEC ) ); /* Q0 */ move32(); } return; diff --git a/lib_dec/ivas_svd_dec.c b/lib_dec/ivas_svd_dec.c index e33ad58e3..e0c210a2f 100644 --- a/lib_dec/ivas_svd_dec.c +++ b/lib_dec/ivas_svd_dec.c @@ -92,62 +92,67 @@ static void flushToZeroArray( float arr[MAX_OUTPUT_CHANNELS], const int16_t leng static void flushToZeroMat( float mat[][MAX_OUTPUT_CHANNELS], const int16_t m, const int16_t n ); #else static void HouseholderReduction_fx( - Word32 singularVectors_Left_fx[][MAX_OUTPUT_CHANNELS], - Word32 singularValues_fx[MAX_OUTPUT_CHANNELS], - Word32 singularVectors_Right_fx[][MAX_OUTPUT_CHANNELS], - Word32 secDiag_fx[MAX_OUTPUT_CHANNELS], + Word32 singularVectors_Left_fx[][MAX_OUTPUT_CHANNELS], /* exp(singularVectors_Left_e) */ + Word32 singularValues_fx[MAX_OUTPUT_CHANNELS], /* exp(singularValues_fx_e) */ + Word32 singularVectors_Right_fx[][MAX_OUTPUT_CHANNELS], /* exp(singularVectors_Left_e) */ + Word32 secDiag_fx[MAX_OUTPUT_CHANNELS], /* exp(secDiag_fx_e) */ Word16 singularVectors_Left_e, Word16 singularValues_fx_e[MAX_OUTPUT_CHANNELS], Word16 *secDiag_fx_e, - const int16_t nChannelsL, - const int16_t nChannelsC, - Word32 *eps_x_fx, + const Word16 nChannelsL, /* Q0 */ + const Word16 nChannelsC, /* Q0 */ + Word32 *eps_x_fx, /* exp(eps_x_fx_e) */ Word16 *eps_x_fx_e ); static void biDiagonalReductionLeft_fx( - Word32 singularVectors[][MAX_OUTPUT_CHANNELS], - Word32 singularValues[MAX_OUTPUT_CHANNELS], - Word32 secDiag[MAX_OUTPUT_CHANNELS], + Word32 singularVectors[][MAX_OUTPUT_CHANNELS], /* exp(singularVectors_e) */ + Word32 singularValues[MAX_OUTPUT_CHANNELS], /* exp(singularValues_e) */ + Word32 secDiag[MAX_OUTPUT_CHANNELS], /* exp(secDiag_e) */ Word16 *singularVectors_e, Word16 singularValues_e[MAX_OUTPUT_CHANNELS], Word16 *secDiag_e, - const Word16 nChannelsL, - const Word16 nChannelsC, - const Word16 currChannel, - Word32 *sig_x, + const Word16 nChannelsL, /* Q0 */ + const Word16 nChannelsC, /* Q0 */ + const Word16 currChannel, /* Q0 */ + Word32 *sig_x, /* exp(sig_x_e) */ Word16 *sig_x_e, - Word32 *g ); // Q31 + Word32 *g /* Q31 */ +); static void biDiagonalReductionRight_fx( - Word32 singularVectors[][MAX_OUTPUT_CHANNELS], - Word32 secDiag[MAX_OUTPUT_CHANNELS], + Word32 singularVectors[][MAX_OUTPUT_CHANNELS], /* exp(singularVectors_e) */ + Word32 secDiag[MAX_OUTPUT_CHANNELS], /* exp(secDiag_e) */ Word16 *singularVectors_e, Word16 *secDiag_e, - const Word16 nChannelsL, - const Word16 nChannelsC, - const Word16 currChannel, - Word32 *sig_x, + const Word16 nChannelsL, /* Q0 */ + const Word16 nChannelsC, /* Q0 */ + const Word16 currChannel, /* Q0 */ + Word32 *sig_x, /* exp(sig_x_e) */ Word16 *sig_x_e, - Word32 *g ); // Q31 + Word32 *g /* Q31 */ +); // Q31 static void singularVectorsAccumulationLeft_fx( - Word32 singularVectors_Left[][MAX_OUTPUT_CHANNELS], // Q31 output - Word32 singularValues[MAX_OUTPUT_CHANNELS], + Word32 singularVectors_Left[][MAX_OUTPUT_CHANNELS], /* exp(singularVectors_e) as Input, Q31 as output */ + Word32 singularValues[MAX_OUTPUT_CHANNELS], /* exp(singularValues_e) */ Word16 singularVectors_e, Word16 singularValues_e[MAX_OUTPUT_CHANNELS], - const Word16 nChannelsL, - const Word16 nChannelsC ); + const Word16 nChannelsL, /* Q0 */ + const Word16 nChannelsC /* Q0 */ +); static void singularVectorsAccumulationRight_fx( - Word32 singularVectors_Left[][MAX_OUTPUT_CHANNELS], - Word32 singularVectors_Right[][MAX_OUTPUT_CHANNELS], // Q31 output - Word32 secDiag[MAX_OUTPUT_CHANNELS], + Word32 singularVectors_Left[][MAX_OUTPUT_CHANNELS], /* Q31 */ + Word32 singularVectors_Right[][MAX_OUTPUT_CHANNELS], /* Q31 */ + Word32 secDiag[MAX_OUTPUT_CHANNELS], /* exp(secDiag_e) */ Word16 singularVectors_e, Word16 secDiag_e, - const Word16 nChannelsC ); + const Word16 nChannelsC /* Q0 */ +); static Word32 maxWithSign_fx( - const Word32 a ); + const Word32 a /* Qx */ +); #if 0 static void flushToZeroArray_fx( @@ -161,54 +166,55 @@ static void flushToZeroMat_fx( #endif static Word16 BidagonalDiagonalisation_fx( - Word32 singularVectors_Left_fx[][MAX_OUTPUT_CHANNELS], /* i/o: left singular vectors (U) Q31 */ - Word32 singularValues_fx[MAX_OUTPUT_CHANNELS], /* i/o: singular values vector (S) */ - Word32 singularVectors_Right_fx[][MAX_OUTPUT_CHANNELS], /* i/o: right singular vectors (V) Q31 */ - Word32 secDiag_fx[MAX_OUTPUT_CHANNELS], /* i/o: */ - Word16 singularValues_fx_e[MAX_OUTPUT_CHANNELS], /* i/o: singular values vector (S) */ - Word16 *secDiag_fx_e, /* i/o: */ - const Word16 nChannelsL, /* i : number of rows in the matrix to be decomposed */ - const Word16 nChannelsC, /* i : number of columns in the matrix to be decomposed */ - const Word32 eps_x, /* i : */ - const Word16 eps_x_e /* i : */ + Word32 singularVectors_Left_fx[][MAX_OUTPUT_CHANNELS], /* i/o: left singular vectors (U) Q31*/ + Word32 singularValues_fx[MAX_OUTPUT_CHANNELS], /* i/o: singular values vector (S) singularValues_fx_e*/ + Word32 singularVectors_Right_fx[][MAX_OUTPUT_CHANNELS], /* i/o: right singular vectors (V) Q31*/ + Word32 secDiag_fx[MAX_OUTPUT_CHANNELS], /* i/o: secDiag_fx_e*/ + Word16 singularValues_fx_e[MAX_OUTPUT_CHANNELS], /* i/o: singular values vector (S) */ + Word16 *secDiag_fx_e, /* i/o: */ + const Word16 nChannelsL, /* i : number of rows in the matrix to be decomposed Q0*/ + const Word16 nChannelsC, /* i : number of columns in the matrix to be decomposed Q0*/ + const Word32 eps_x, /* i : eps_x_e*/ + const Word16 eps_x_e /* i : */ ); static void ApplyRotation_fx( Word32 singularVector[][MAX_OUTPUT_CHANNELS], - const Word32 c, + const Word32 c, /* exp(c_e)*/ const Word16 c_e, - const Word32 s, + const Word32 s, /* exp(s_e) */ const Word16 s_e, - Word32 x11, + Word32 x11, /* exp(x11_e) */ Word16 x11_e, - Word32 x12, + Word32 x12, /* exp(x12_e) */ Word16 x12_e, - Word32 *d, + Word32 *d, /* exp(d_e) */ Word16 *d_e, - Word32 *g, + Word32 *g, /* exp(g_e) */ Word16 *g_e, - const Word16 currentIndex1, - const Word16 currentIndex2, - const Word16 nChannels ); + const Word16 currentIndex1, /* Q0 */ + const Word16 currentIndex2, /* Q0 */ + const Word16 nChannels /* Q0 */ +); static Word32 GivensRotation_fx( - const Word32 x, + const Word32 x, /* exp(x_e) */ const Word16 x_e, - const Word32 z, + const Word32 z, /* exp(z_e) */ const Word16 z_e, Word16 *out_e ); static void ApplyQRTransform_fx( - Word32 singularVectors_Left[][MAX_OUTPUT_CHANNELS], /* i/o: left singular vectors (U) Q31 */ - Word32 singularValues[MAX_OUTPUT_CHANNELS], /* i/o: singular values vector (S) */ - Word32 singularVectors_Right[][MAX_OUTPUT_CHANNELS], /* i/o: right singular vectors (V) Q31 */ - Word32 secDiag[MAX_OUTPUT_CHANNELS], /* i/o: */ + Word32 singularVectors_Left[][MAX_OUTPUT_CHANNELS], /* i/o: left singular vectors (U) Q31*/ + Word32 singularValues[MAX_OUTPUT_CHANNELS], /* i/o: singular values vector (S) singularValues_e*/ + Word32 singularVectors_Right[][MAX_OUTPUT_CHANNELS], /* i/o: right singular vectors (V) Q31*/ + Word32 secDiag[MAX_OUTPUT_CHANNELS], /* i/o: secDiag_e*/ Word16 singularValues_e[MAX_OUTPUT_CHANNELS], Word16 secDiag_e[MAX_OUTPUT_CHANNELS], - const Word16 startIndex, /* i : */ - const Word16 currentIndex, /* i : */ - const Word16 nChannelsL, /* i : number of rows in the matrix to be decomposed */ - const Word16 nChannelsC /* i : number of columns in the matrix to be decomposed */ + const Word16 startIndex, /* i : Q0*/ + const Word16 currentIndex, /* i : Q0*/ + const Word16 nChannelsL, /* i : number of rows in the matrix to be decomposed Q0*/ + const Word16 nChannelsC /* i : number of columns in the matrix to be decomposed Q0*/ ); #endif @@ -220,11 +226,11 @@ static void ApplyQRTransform_fx( *-------------------------------------------------------------------------*/ void mat2svdMat_fx( - const Word32 *mat, /* i : matrix as column ordered vector */ - Word32 svdMat[MAX_OUTPUT_CHANNELS][MAX_OUTPUT_CHANNELS], /* o : matrix as two-dimensional arry */ - const Word16 nRows, /* i : number of rows of the matrix */ - const Word16 mCols, /* i : number of columns of the matrix */ - const Word16 transpose /* i : flag indication transposition */ + const Word32 *mat, /* i : matrix as column ordered vector Qx*/ + Word32 svdMat[MAX_OUTPUT_CHANNELS][MAX_OUTPUT_CHANNELS], /* o : matrix as two-dimensional arry Qx*/ + const Word16 nRows, /* i : number of rows of the matrix Q0*/ + const Word16 mCols, /* i : number of columns of the matrix Q0*/ + const Word16 transpose /* i : flag indication transposition Q0*/ ) { Word16 i, j; @@ -235,11 +241,11 @@ void mat2svdMat_fx( { FOR( j = 0; j < nRows; j++ ) { - svdMat[i][j] = mat[add( j, i_mult( nRows, i ) )]; + svdMat[i][j] = mat[j + ( nRows * i )]; /* Qx */ move32(); } - set_zero_fx( &svdMat[i][mCols], MAX_OUTPUT_CHANNELS - nRows ); + set_zero_fx( &svdMat[i][mCols], sub( MAX_OUTPUT_CHANNELS, nRows ) ); } FOR( ; i < MAX_OUTPUT_CHANNELS; i++ ) @@ -253,11 +259,11 @@ void mat2svdMat_fx( { FOR( j = 0; j < mCols; j++ ) { - svdMat[i][j] = mat[add( i, i_mult( nRows, j ) )]; + svdMat[i][j] = mat[i + ( nRows * j )]; /* Qx */ move32(); } - set_zero_fx( &svdMat[i][mCols], MAX_OUTPUT_CHANNELS - mCols ); + set_zero_fx( &svdMat[i][mCols], sub( MAX_OUTPUT_CHANNELS, mCols ) ); } FOR( ; i < MAX_OUTPUT_CHANNELS; i++ ) @@ -277,10 +283,10 @@ void mat2svdMat_fx( *---------------------------------------------------------------------*/ void svdMat2mat_fx( - Word32 svdMat[MAX_OUTPUT_CHANNELS][MAX_OUTPUT_CHANNELS], /* i : matrix as two-dimensional arry */ - Word32 *mat, /* o : matrix as column ordered vector */ - const Word16 nRows, /* i : number of rows of the matrix */ - const Word16 mCols /* i : number of columns of the matrix */ + Word32 svdMat[MAX_OUTPUT_CHANNELS][MAX_OUTPUT_CHANNELS], /* i : matrix as two-dimensional arry Qx*/ + Word32 *mat, /* o : matrix as column ordered vector Qx*/ + const Word16 nRows, /* i : number of rows of the matrix Q0*/ + const Word16 mCols /* i : number of columns of the matrix Q0*/ ) { Word16 i, j; @@ -289,7 +295,7 @@ void svdMat2mat_fx( { FOR( j = 0; j < mCols; j++ ) { - mat[add( i, i_mult( nRows, j ) )] = svdMat[i][j]; + mat[i + ( nRows * j )] = svdMat[i][j]; /* Qx */ move32(); } } @@ -391,14 +397,14 @@ void svdMat2mat( #ifdef IVAS_FLOAT_FIXED /*! r: error or success */ Word16 svd_fx( - Word32 InputMatrix[][MAX_OUTPUT_CHANNELS], /* i : matrix to be decomposed (M) */ + Word32 InputMatrix[][MAX_OUTPUT_CHANNELS], /* i : matrix to be decomposed (M) InputMatrix_e*/ Word16 InputMatrix_e, - Word32 singularVectors_Left_fx[][MAX_OUTPUT_CHANNELS], /* o : left singular vectors (U) (Q31) */ - Word32 singularValues_fx[MAX_OUTPUT_CHANNELS], /* o : singular values vector (S) */ - Word32 singularVectors_Right_fx[][MAX_OUTPUT_CHANNELS], /* o : right singular vectors (V) (Q31) */ + Word32 singularVectors_Left_fx[][MAX_OUTPUT_CHANNELS], /* o : left singular vectors (U) Q31*/ + Word32 singularValues_fx[MAX_OUTPUT_CHANNELS], /* o : singular values vector (S) singularValues_fx_e*/ + Word32 singularVectors_Right_fx[][MAX_OUTPUT_CHANNELS], /* o : right singular vectors (V) Q31*/ Word16 singularValues_fx_e[MAX_OUTPUT_CHANNELS], - const Word16 nChannelsL, /* i : number of rows in the matrix to be decomposed */ - const Word16 nChannelsC /* i : number of columns in the matrix to be decomposed */ + const Word16 nChannelsL, /* i : number of rows in the matrix to be decomposed Q0*/ + const Word16 nChannelsC /* i : number of columns in the matrix to be decomposed Q0*/ ) { Word16 iCh, jCh; @@ -422,7 +428,7 @@ Word16 svd_fx( { FOR( jCh = 0; jCh < nChannelsC; jCh++ ) { - singularVectors_Left_fx[iCh][jCh] = InputMatrix[iCh][jCh]; + singularVectors_Left_fx[iCh][jCh] = InputMatrix[iCh][jCh]; /* Q31 */ move32(); } } @@ -438,26 +444,26 @@ Word16 svd_fx( // flushToZeroMat(singularVectors_Right, nChannelsC, nChannelsC); /* BidagonalDiagonalisation */ - errorMessage = BidagonalDiagonalisation_fx( singularVectors_Left_fx, singularValues_fx, singularVectors_Right_fx, secDiag_fx, singularValues_fx_e, &secDiag_fx_e, nChannelsL, nChannelsC, eps_x_fx, eps_x_fx_e ); + errorMessage = BidagonalDiagonalisation_fx( singularVectors_Left_fx, singularValues_fx, singularVectors_Right_fx, secDiag_fx, singularValues_fx_e, &secDiag_fx_e, nChannelsL, nChannelsC, eps_x_fx, eps_x_fx_e ); /* Q0 */ /* Sort the singular values descending order */ - lengthSingularValues = s_min( nChannelsL, nChannelsC ); + lengthSingularValues = s_min( nChannelsL, nChannelsC ); /* Q0 */ DO { condition = 0; move16(); - FOR( iCh = 0; iCh < sub( lengthSingularValues, 1 ); iCh++ ) + FOR( iCh = 0; iCh < lengthSingularValues - 1; iCh++ ) { IF( BASOP_Util_Cmp_Mant32Exp( singularValues_fx[iCh], singularValues_fx_e[iCh], singularValues_fx[iCh + 1], singularValues_fx_e[iCh + 1] ) < 0 ) { condition = 1; move16(); - temp_fx = singularValues_fx[iCh]; + temp_fx = singularValues_fx[iCh]; /* singularValues_fx_e */ move32(); - singularValues_fx[iCh] = singularValues_fx[iCh + 1]; + singularValues_fx[iCh] = singularValues_fx[iCh + 1]; /* singularValues_fx_e */ move32(); - singularValues_fx[iCh + 1] = temp_fx; + singularValues_fx[iCh + 1] = temp_fx; /* singularValues_fx_e */ move32(); temp_fx_e = singularValues_fx_e[iCh]; move16(); @@ -468,21 +474,21 @@ Word16 svd_fx( FOR( jCh = 0; jCh < nChannelsL; ++jCh ) { - temp_fx = singularVectors_Left_fx[jCh][iCh]; + temp_fx = singularVectors_Left_fx[jCh][iCh]; /* Q31 */ move32(); - singularVectors_Left_fx[jCh][iCh] = singularVectors_Left_fx[jCh][iCh + 1]; + singularVectors_Left_fx[jCh][iCh] = singularVectors_Left_fx[jCh][iCh + 1]; /* Q31 */ move32(); - singularVectors_Left_fx[jCh][iCh + 1] = temp_fx; + singularVectors_Left_fx[jCh][iCh + 1] = temp_fx; /* Q31 */ move32(); } FOR( jCh = 0; jCh < nChannelsC; ++jCh ) { - temp_fx = singularVectors_Right_fx[jCh][iCh]; + temp_fx = singularVectors_Right_fx[jCh][iCh]; /* Q31 */ move32(); - singularVectors_Right_fx[jCh][iCh] = singularVectors_Right_fx[jCh][iCh + 1]; + singularVectors_Right_fx[jCh][iCh] = singularVectors_Right_fx[jCh][iCh + 1]; /* Q31 */ move32(); - singularVectors_Right_fx[jCh][iCh + 1] = temp_fx; + singularVectors_Right_fx[jCh][iCh + 1] = temp_fx; /* Q31 */ move32(); } } @@ -585,16 +591,16 @@ int16_t svd( #ifdef IVAS_FLOAT_FIXED static Word16 BidagonalDiagonalisation_fx( - Word32 singularVectors_Left_fx[][MAX_OUTPUT_CHANNELS], /* i/o: left singular vectors (U) Q31 */ - Word32 singularValues_fx[MAX_OUTPUT_CHANNELS], /* i/o: singular values vector (S) */ - Word32 singularVectors_Right_fx[][MAX_OUTPUT_CHANNELS], /* i/o: right singular vectors (V) Q31 */ - Word32 secDiag_fx[MAX_OUTPUT_CHANNELS], /* i/o: */ - Word16 singularValues_fx_e[MAX_OUTPUT_CHANNELS], /* i/o: singular values vector (S) */ - Word16 *secDiag_fx_e, /* i/o: */ - const Word16 nChannelsL, /* i : number of rows in the matrix to be decomposed */ - const Word16 nChannelsC, /* i : number of columns in the matrix to be decomposed */ - const Word32 eps_x, /* i : */ - const Word16 eps_x_e /* i : */ + Word32 singularVectors_Left_fx[][MAX_OUTPUT_CHANNELS], /* i/o: left singular vectors (U) Q31*/ + Word32 singularValues_fx[MAX_OUTPUT_CHANNELS], /* i/o: singular values vector (S) singularValues_fx_e*/ + Word32 singularVectors_Right_fx[][MAX_OUTPUT_CHANNELS], /* i/o: right singular vectors (V) Q31*/ + Word32 secDiag_fx[MAX_OUTPUT_CHANNELS], /* i/o: secDiag_fx_e*/ + Word16 singularValues_fx_e[MAX_OUTPUT_CHANNELS], /* i/o: singular values vector (S) */ + Word16 *secDiag_fx_e, /* i/o: */ + const Word16 nChannelsL, /* i : number of rows in the matrix to be decomposed Q0*/ + const Word16 nChannelsC, /* i : number of columns in the matrix to be decomposed Q0*/ + const Word32 eps_x, /* i : eps_x_e*/ + const Word16 eps_x_e /* i : */ ) { Word16 kCh, nCh, iCh, jCh, split; @@ -621,18 +627,18 @@ static Word16 BidagonalDiagonalisation_fx( move16(); iteration = 0; move16(); - split = iCh - 1; + split = iCh - 1; /* Q0 */ move16(); WHILE( EQ_16( convergence, 0 ) ) { - iteration = add( iteration, 1 ); - found_split = 1; + iteration = add( iteration, 1 ); /* Q0 */ + found_split = 1; /* Q0 */ move16(); FOR( jCh = iCh; jCh >= 0; jCh-- ) { - split = sub( jCh, 1 ); + split = sub( jCh, 1 ); /* Q0 */ IF( LE_16( BASOP_Util_Cmp_Mant32Exp( L_abs( secDiag_fx[jCh] ), secDiag_new_e[jCh], Mpy_32_32( CONVERGENCE_FACTOR_FX, eps_x ), eps_x_e ), 0 ) ) /* is secDiag[ch] vanishing compared to eps_x */ { found_split = 0; @@ -648,7 +654,7 @@ static Word16 BidagonalDiagonalisation_fx( // convergence = ( jCh == iCh ) ? 1 : 0; IF( EQ_16( jCh, iCh ) ) { - convergence = 1; + convergence = 1; /* Q0 */ move16(); } ELSE @@ -670,19 +676,19 @@ static Word16 BidagonalDiagonalisation_fx( FOR( kCh = jCh; kCh <= iCh; kCh++ ) { - g = Mpy_32_32( s, secDiag_fx[kCh] ); + g = Mpy_32_32( s, secDiag_fx[kCh] ); /* exp(s_e + secDiag_new_e) */ g_e = add( s_e, secDiag_new_e[kCh] ); - secDiag_fx[kCh] = Mpy_32_32( c, secDiag_fx[kCh] ); + secDiag_fx[kCh] = Mpy_32_32( c, secDiag_fx[kCh] ); /* exp(c_e + secDiag_new_e) */ secDiag_new_e[kCh] = add( c_e, secDiag_new_e[kCh] ); IF( LE_16( BASOP_Util_Cmp_Mant32Exp( L_abs( g ), g_e, Mpy_32_32( CONVERGENCE_FACTOR_FX, eps_x ), eps_x_e ), 0 ) ) /* is singularValues[split] vanishing compared to eps_x */ { BREAK; } - c = singularValues_fx[kCh]; + c = singularValues_fx[kCh]; /* exp(singularValues_new_e) */ c_e = singularValues_new_e[kCh]; - singularValues_fx[kCh] = GivensRotation_fx( g, g_e, singularValues_fx[kCh], singularValues_new_e[kCh], &singularValues_new_e[kCh] ); - c = BASOP_Util_Divide3232_Scale_cadence( c, maxWithSign_fx( singularValues_fx[kCh] ), &temp_exp ); + singularValues_fx[kCh] = GivensRotation_fx( g, g_e, singularValues_fx[kCh], singularValues_new_e[kCh], &singularValues_new_e[kCh] ); /* exp(singularValues_new_e) */ + c = BASOP_Util_Divide3232_Scale_cadence( c, maxWithSign_fx( singularValues_fx[kCh] ), &temp_exp ); /* exp(temp_exp + (c_e - singularValues_new_e)) */ c_e = add( temp_exp, sub( c_e, singularValues_new_e[kCh] ) ); IF( c_e > 0 ) { @@ -690,7 +696,7 @@ static Word16 BidagonalDiagonalisation_fx( c_e = 0; move16(); } - s = BASOP_Util_Divide3232_Scale_cadence( -g, maxWithSign_fx( singularValues_fx[kCh] ), &temp_exp ); + s = BASOP_Util_Divide3232_Scale_cadence( -g, maxWithSign_fx( singularValues_fx[kCh] ), &temp_exp ); /* exp(temp_exp + (g_e - singularValues_new_e))*/ s_e = add( temp_exp, sub( g_e, singularValues_new_e[kCh] ) ); IF( s_e > 0 ) { @@ -766,7 +772,7 @@ static Word16 BidagonalDiagonalisation_fx( move16(); FOR( iCh = 0; iCh < nChannelsC; iCh++ ) { - secDiag_fx[iCh] = L_shr_r( secDiag_fx[iCh], sub( *secDiag_fx_e, secDiag_new_e[iCh] ) ); + secDiag_fx[iCh] = L_shr_r( secDiag_fx[iCh], sub( *secDiag_fx_e, secDiag_new_e[iCh] ) ); /* exp(secDiag_fx_e) */ move32(); } @@ -887,16 +893,16 @@ static int16_t BidagonalDiagonalisation( #ifdef IVAS_FLOAT_FIXED static void ApplyQRTransform_fx( - Word32 singularVectors_Left[][MAX_OUTPUT_CHANNELS], /* i/o: left singular vectors (U) Q31 */ - Word32 singularValues[MAX_OUTPUT_CHANNELS], /* i/o: singular values vector (S) */ - Word32 singularVectors_Right[][MAX_OUTPUT_CHANNELS], /* i/o: right singular vectors (V) Q31 */ - Word32 secDiag[MAX_OUTPUT_CHANNELS], /* i/o: */ + Word32 singularVectors_Left[][MAX_OUTPUT_CHANNELS], /* i/o: left singular vectors (U) Q31*/ + Word32 singularValues[MAX_OUTPUT_CHANNELS], /* i/o: singular values vector (S) singularValues_e*/ + Word32 singularVectors_Right[][MAX_OUTPUT_CHANNELS], /* i/o: right singular vectors (V) Q31*/ + Word32 secDiag[MAX_OUTPUT_CHANNELS], /* i/o: secDiag_e*/ Word16 singularValues_e[MAX_OUTPUT_CHANNELS], Word16 secDiag_e[MAX_OUTPUT_CHANNELS], - const Word16 startIndex, /* i : */ - const Word16 currentIndex, /* i : */ - const Word16 nChannelsL, /* i : number of rows in the matrix to be decomposed */ - const Word16 nChannelsC /* i : number of columns in the matrix to be decomposed */ + const Word16 startIndex, /* i : Q0*/ + const Word16 currentIndex, /* i : Q0*/ + const Word16 nChannelsL, /* i : number of rows in the matrix to be decomposed Q0*/ + const Word16 nChannelsC /* i : number of columns in the matrix to be decomposed Q0*/ ) { Word16 ch, split; @@ -929,42 +935,42 @@ static void ApplyQRTransform_fx( Word16 s_e = 0; move16(); - x_kk = singularValues[currentIndex]; + x_kk = singularValues[currentIndex]; /* exp(singularValues_e) */ move32(); x_kk_e = singularValues_e[currentIndex]; move16(); - x_ii = singularValues[startIndex]; + x_ii = singularValues[startIndex]; /* exp(singularValues_e) */ move32(); x_ii_e = singularValues_e[startIndex]; move16(); - split = sub( currentIndex, 1 ); + split = sub( currentIndex, 1 ); /* Q0 */ move16(); - x_split = singularValues[split]; + x_split = singularValues[split]; /* exp(singularValues_e) */ move32(); x_split_e = singularValues_e[split]; move16(); - g = secDiag[split]; + g = secDiag[split]; /* exp(secDiag_e) */ move32(); g_e = secDiag_e[split]; move16(); - r = secDiag[currentIndex]; + r = secDiag[currentIndex]; /* exp(secDiag_e) */ move32(); r_e = secDiag_e[currentIndex]; move16(); // d = (x_split + x_kk) * (x_split - x_kk) + (g + r) * (g - r); - L_temp1 = BASOP_Util_Add_Mant32Exp( x_split, x_split_e, x_kk, x_kk_e, &L_temp1_e ); - L_temp2 = BASOP_Util_Add_Mant32Exp( x_split, x_split_e, L_negate( x_kk ), x_kk_e, &L_temp2_e ); - L_temp3 = BASOP_Util_Add_Mant32Exp( g, g_e, r, r_e, &L_temp3_e ); - L_temp4 = BASOP_Util_Add_Mant32Exp( g, g_e, L_negate( r ), r_e, &L_temp4_e ); - d = BASOP_Util_Add_Mant32Exp( Mpy_32_32( L_temp1, L_temp2 ), add( L_temp1_e, L_temp2_e ), Mpy_32_32( L_temp3, L_temp4 ), add( L_temp3_e, L_temp4_e ), &d_e ); + L_temp1 = BASOP_Util_Add_Mant32Exp( x_split, x_split_e, x_kk, x_kk_e, &L_temp1_e ); /* exp(L_temp1_e) */ + L_temp2 = BASOP_Util_Add_Mant32Exp( x_split, x_split_e, L_negate( x_kk ), x_kk_e, &L_temp2_e ); /* exp(L_temp2_e) */ + L_temp3 = BASOP_Util_Add_Mant32Exp( g, g_e, r, r_e, &L_temp3_e ); /* exp(L_temp3_e) */ + L_temp4 = BASOP_Util_Add_Mant32Exp( g, g_e, L_negate( r ), r_e, &L_temp4_e ); /* exp(L_temp4_e) */ + d = BASOP_Util_Add_Mant32Exp( Mpy_32_32( L_temp1, L_temp2 ), add( L_temp1_e, L_temp2_e ), Mpy_32_32( L_temp3, L_temp4 ), add( L_temp3_e, L_temp4_e ), &d_e ); /* exp(d_e) */ // d /= maxWithSign((r + r) * x_split); - L_temp1 = BASOP_Util_Add_Mant32Exp( r, r_e, r, r_e, &L_temp1_e ); - L_temp1 = maxWithSign_fx( Mpy_32_32( L_temp1, x_split ) ); + L_temp1 = BASOP_Util_Add_Mant32Exp( r, r_e, r, r_e, &L_temp1_e ); /* exp(L_temp1_e) */ + L_temp1 = maxWithSign_fx( Mpy_32_32( L_temp1, x_split ) ); /* exp(L_temp1_e + x_split_e) */ L_temp1_e = add( L_temp1_e, x_split_e ); - d = BASOP_Util_Divide3232_Scale_cadence( d, L_temp1, &temp_exp ); + d = BASOP_Util_Divide3232_Scale_cadence( d, L_temp1, &temp_exp ); /* temp_exp + d_e - L_temp1_e */ d_e = add( temp_exp, sub( d_e, L_temp1_e ) ); g = GivensRotation_fx( MAX_32, 0, d, d_e, &g_e ); @@ -981,29 +987,29 @@ static void ApplyQRTransform_fx( } L_temp1_e = g_e; move16(); - L_temp2 = maxWithSign_fx( BASOP_Util_Add_Mant32Exp( d, d_e, L_temp1, L_temp1_e, &L_temp2_e ) ); - mu = BASOP_Util_Divide3232_Scale_cadence( x_split, L_temp2, &mu_e ); + L_temp2 = maxWithSign_fx( BASOP_Util_Add_Mant32Exp( d, d_e, L_temp1, L_temp1_e, &L_temp2_e ) ); /* exp(L_temp2_e) */ + mu = BASOP_Util_Divide3232_Scale_cadence( x_split, L_temp2, &mu_e ); /* exp(mu_e + (x-plit_e - L_temp2_e)) */ mu_e = add( mu_e, sub( x_split_e, L_temp2_e ) ); - mu = BASOP_Util_Add_Mant32Exp( mu, mu_e, L_negate( r ), r_e, &mu_e ); + mu = BASOP_Util_Add_Mant32Exp( mu, mu_e, L_negate( r ), r_e, &mu_e ); /* exp(mu_e) */ // d = ((x_ii + x_kk) * (x_ii - x_kk) + r * mu) / maxWithSign(x_ii); - L_temp1 = BASOP_Util_Add_Mant32Exp( x_ii, x_ii_e, x_kk, x_kk_e, &L_temp1_e ); - L_temp2 = BASOP_Util_Add_Mant32Exp( x_ii, x_ii_e, L_negate( x_kk ), x_kk_e, &L_temp2_e ); - d = BASOP_Util_Add_Mant32Exp( Mpy_32_32( L_temp1, L_temp2 ), add( L_temp1_e, L_temp2_e ), Mpy_32_32( r, mu ), add( r_e, mu_e ), &d_e ); - d = BASOP_Util_Divide3232_Scale_cadence( d, maxWithSign_fx( x_ii ), &temp_exp ); + L_temp1 = BASOP_Util_Add_Mant32Exp( x_ii, x_ii_e, x_kk, x_kk_e, &L_temp1_e ); /* exp(L_temp1_e) */ + L_temp2 = BASOP_Util_Add_Mant32Exp( x_ii, x_ii_e, L_negate( x_kk ), x_kk_e, &L_temp2_e ); /* exp(L_temp2_e) */ + d = BASOP_Util_Add_Mant32Exp( Mpy_32_32( L_temp1, L_temp2 ), add( L_temp1_e, L_temp2_e ), Mpy_32_32( r, mu ), add( r_e, mu_e ), &d_e ); /* exp(d_e) */ + d = BASOP_Util_Divide3232_Scale_cadence( d, maxWithSign_fx( x_ii ), &temp_exp ); /* exp(temp_exp + (d_e - x_ii_e) */ d_e = add( temp_exp, sub( d_e, x_ii_e ) ); /*QR transformation*/ FOR( ch = startIndex; ch <= split; ch++ ) { - r = Mpy_32_32( s, secDiag[ch + 1] ); + r = Mpy_32_32( s, secDiag[ch + 1] ); /* exp(s_e + secDiag_e) */ r_e = add( s_e, secDiag_e[ch + 1] ); - g = Mpy_32_32( c, secDiag[ch + 1] ); + g = Mpy_32_32( c, secDiag[ch + 1] ); /* exp(c_e + secDiag_e) */ g_e = add( c_e, secDiag_e[ch + 1] ); - secDiag[ch] = GivensRotation_fx( d, d_e, r, r_e, &secDiag_e[ch] ); + secDiag[ch] = GivensRotation_fx( d, d_e, r, r_e, &secDiag_e[ch] ); /* exp(secDiag_e) */ move32(); - c = BASOP_Util_Divide3232_Scale_cadence( d, maxWithSign_fx( secDiag[ch] ), &c_e ); + c = BASOP_Util_Divide3232_Scale_cadence( d, maxWithSign_fx( secDiag[ch] ), &c_e ); /* exp(c_e + (d_e + secDiag_e)) */ c_e = add( c_e, sub( d_e, secDiag_e[ch] ) ); IF( c_e > 0 ) { @@ -1011,7 +1017,7 @@ static void ApplyQRTransform_fx( c_e = 0; move16(); } - s = BASOP_Util_Divide3232_Scale_cadence( r, maxWithSign_fx( secDiag[ch] ), &s_e ); + s = BASOP_Util_Divide3232_Scale_cadence( r, maxWithSign_fx( secDiag[ch] ), &s_e ); /* exp(s_e + (r_e - sec_Diag_e))*/ s_e = add( s_e, sub( r_e, secDiag_e[ch] ) ); IF( s_e > 0 ) { @@ -1020,12 +1026,12 @@ static void ApplyQRTransform_fx( move16(); } - r = Mpy_32_32( s, singularValues[ch + 1] ); + r = Mpy_32_32( s, singularValues[ch + 1] ); /* exp(r_e + secDiag_e) */ r_e = add( s_e, singularValues_e[ch + 1] ); - x_split = Mpy_32_32( c, singularValues[ch + 1] ); + x_split = Mpy_32_32( c, singularValues[ch + 1] ); /* exp(c_e + secDiag_e) */ x_split_e = add( c_e, singularValues_e[ch + 1] ); - aux = g; + aux = g; /* exp(g_e) */ move32(); aux_e = g_e; move16(); @@ -1033,14 +1039,14 @@ static void ApplyQRTransform_fx( // ApplyRotation(singularVectors_Right, c, s, x_ii, aux, &d, &g, ch + 1, ch, nChannelsC); ApplyRotation_fx( singularVectors_Right, c, c_e, s, s_e, x_ii, x_ii_e, aux, aux_e, &d, &d_e, &g, &g_e, ch + 1, ch, nChannelsC ); - singularValues[ch] = GivensRotation_fx( d, d_e, r, r_e, &singularValues_e[ch] ); + singularValues[ch] = GivensRotation_fx( d, d_e, r, r_e, &singularValues_e[ch] ); /* exp(singularValues_e) */ move32(); IF( GT_32( L_abs( singularValues[ch] ), Mpy_32_32( CONVERGENCE_FACTOR_FX, L_abs( singularValues[ch] ) ) ) ) { - aux = BASOP_Util_Divide3232_Scale_cadence( ONE_IN_Q30, singularValues[ch], &aux_e ); + aux = BASOP_Util_Divide3232_Scale_cadence( ONE_IN_Q30, singularValues[ch], &aux_e ); /* exp(aux_e + (1 - singularValues_e)) */ aux_e = add( aux_e, sub( 1, singularValues_e[ch] ) ); - c = Mpy_32_32( d, aux ); + c = Mpy_32_32( d, aux ); /* exp(d_e + aux_e) */ c_e = add( d_e, aux_e ); IF( c_e > 0 ) { @@ -1049,7 +1055,7 @@ static void ApplyQRTransform_fx( move16(); } - s = Mpy_32_32( r, aux ); + s = Mpy_32_32( r, aux ); /* exp(r_e + aux_e) */ s_e = add( r_e, aux_e ); IF( s_e > 0 ) { @@ -1065,11 +1071,11 @@ static void ApplyQRTransform_fx( secDiag[startIndex] = 0; move32(); - secDiag[currentIndex] = d; + secDiag[currentIndex] = d; /* exp(d_e) */ move32(); secDiag_e[currentIndex] = d_e; move16(); - singularValues[currentIndex] = x_ii; + singularValues[currentIndex] = x_ii; /* exp(x_ii_e) */ move32(); singularValues_e[currentIndex] = x_ii_e; move16(); @@ -1151,28 +1157,29 @@ static void ApplyQRTransform( #ifdef IVAS_FLOAT_FIXED static void ApplyRotation_fx( Word32 singularVector[][MAX_OUTPUT_CHANNELS], - const Word32 c, + const Word32 c, /* exp(c_e)*/ const Word16 c_e, - const Word32 s, + const Word32 s, /* exp(s_e) */ const Word16 s_e, - Word32 x11, + Word32 x11, /* exp(x11_e) */ Word16 x11_e, - Word32 x12, + Word32 x12, /* exp(x12_e) */ Word16 x12_e, - Word32 *d, + Word32 *d, /* exp(d_e) */ Word16 *d_e, - Word32 *g, + Word32 *g, /* exp(g_e) */ Word16 *g_e, - const Word16 currentIndex1, - const Word16 currentIndex2, - const Word16 nChannels ) + const Word16 currentIndex1, /* Q0 */ + const Word16 currentIndex2, /* Q0 */ + const Word16 nChannels /* Q0 */ +) { Word16 ch; Word16 temp_exp; - *d = BASOP_Util_Add_Mant32Exp( Mpy_32_32( c, x11 ), add( c_e, x11_e ), Mpy_32_32( s, x12 ), add( s_e, x12_e ), d_e ); + *d = BASOP_Util_Add_Mant32Exp( Mpy_32_32( c, x11 ), add( c_e, x11_e ), Mpy_32_32( s, x12 ), add( s_e, x12_e ), d_e ); /* exp(d_e) */ move32(); - *g = BASOP_Util_Add_Mant32Exp( Mpy_32_32( c, x12 ), add( c_e, x12_e ), Mpy_32_32( L_negate( s ), x11 ), add( s_e, x11_e ), g_e ); + *g = BASOP_Util_Add_Mant32Exp( Mpy_32_32( c, x12 ), add( c_e, x12_e ), Mpy_32_32( L_negate( s ), x11 ), add( s_e, x11_e ), g_e ); /* exp(g_e) */ move32(); FOR( ch = 0; ch < nChannels; ch++ ) @@ -1181,13 +1188,13 @@ static void ApplyRotation_fx( move32(); x12 = singularVector[ch][currentIndex1]; move32(); - singularVector[ch][currentIndex2] = BASOP_Util_Add_Mant32Exp( Mpy_32_32( c, x11 ), c_e, Mpy_32_32( s, x12 ), s_e, &temp_exp ); + singularVector[ch][currentIndex2] = BASOP_Util_Add_Mant32Exp( Mpy_32_32( c, x11 ), c_e, Mpy_32_32( s, x12 ), s_e, &temp_exp ); /* exp(temp_exp) */ move32(); - singularVector[ch][currentIndex2] = L_shl_sat( singularVector[ch][currentIndex2], temp_exp ); + singularVector[ch][currentIndex2] = L_shl_sat( singularVector[ch][currentIndex2], temp_exp ); /* exp(temp_exp) */ move32(); - singularVector[ch][currentIndex1] = BASOP_Util_Add_Mant32Exp( Mpy_32_32( c, x12 ), c_e, Mpy_32_32( L_negate( s ), x11 ), s_e, &temp_exp ); + singularVector[ch][currentIndex1] = BASOP_Util_Add_Mant32Exp( Mpy_32_32( c, x12 ), c_e, Mpy_32_32( L_negate( s ), x11 ), s_e, &temp_exp ); /* exp(temp_exp) */ move32(); - singularVector[ch][currentIndex1] = L_shl_sat( singularVector[ch][currentIndex1], temp_exp ); + singularVector[ch][currentIndex1] = L_shl_sat( singularVector[ch][currentIndex1], temp_exp ); /* exp(temp_exp) */ move32(); } @@ -1231,16 +1238,16 @@ static void ApplyRotation( #ifdef IVAS_FLOAT_FIXED static void HouseholderReduction_fx( - Word32 singularVectors_Left_fx[][MAX_OUTPUT_CHANNELS], - Word32 singularValues_fx[MAX_OUTPUT_CHANNELS], - Word32 singularVectors_Right_fx[][MAX_OUTPUT_CHANNELS], - Word32 secDiag_fx[MAX_OUTPUT_CHANNELS], + Word32 singularVectors_Left_fx[][MAX_OUTPUT_CHANNELS], /* exp(singularVectors_Left_e) */ + Word32 singularValues_fx[MAX_OUTPUT_CHANNELS], /* exp(singularValues_fx_e) */ + Word32 singularVectors_Right_fx[][MAX_OUTPUT_CHANNELS], /* exp(singularVectors_Left_e) */ + Word32 secDiag_fx[MAX_OUTPUT_CHANNELS], /* exp(secDiag_fx_e) */ Word16 singularVectors_Left_e, Word16 singularValues_fx_e[MAX_OUTPUT_CHANNELS], Word16 *secDiag_fx_e, - const Word16 nChannelsL, - const Word16 nChannelsC, - Word32 *eps_x_fx, + const Word16 nChannelsL, /* Q0 */ + const Word16 nChannelsC, /* Q0 */ + Word32 *eps_x_fx, /* exp(eps_x_fx_e) */ Word16 *eps_x_fx_e ) { Word16 nCh; @@ -1258,10 +1265,10 @@ static void HouseholderReduction_fx( biDiagonalReductionRight_fx( singularVectors_Left_fx, secDiag_fx, &singularVectors_Left_e, secDiag_fx_e, nChannelsL, nChannelsC, nCh, &sig_x_fx, &sig_x_fx_e, &g_fx ); Word16 L_temp_e; - Word32 L_temp = BASOP_Util_Add_Mant32Exp( L_abs( singularValues_fx[nCh] ), singularValues_fx_e[nCh], L_abs( secDiag_fx[nCh] ), *secDiag_fx_e, &L_temp_e ); + Word32 L_temp = BASOP_Util_Add_Mant32Exp( L_abs( singularValues_fx[nCh] ), singularValues_fx_e[nCh], L_abs( secDiag_fx[nCh] ), *secDiag_fx_e, &L_temp_e ); /* exp(L_temp_e) */ IF( EQ_16( BASOP_Util_Cmp_Mant32Exp( L_temp, L_temp_e, *eps_x_fx, *eps_x_fx_e ), 1 ) ) { - *eps_x_fx = L_temp; + *eps_x_fx = L_temp; /* exp(L_temp_e) */ move32(); *eps_x_fx_e = L_temp_e; move32(); @@ -1312,18 +1319,19 @@ static void HouseholderReduction( #ifdef IVAS_FLOAT_FIXED static void biDiagonalReductionLeft_fx( - Word32 singularVectors[][MAX_OUTPUT_CHANNELS], - Word32 singularValues[MAX_OUTPUT_CHANNELS], - Word32 secDiag[MAX_OUTPUT_CHANNELS], + Word32 singularVectors[][MAX_OUTPUT_CHANNELS], /* exp(singularVectors_e) */ + Word32 singularValues[MAX_OUTPUT_CHANNELS], /* exp(singularValues_e) */ + Word32 secDiag[MAX_OUTPUT_CHANNELS], /* exp(secDiag_e) */ Word16 *singularVectors_e, Word16 singularValues_e[MAX_OUTPUT_CHANNELS], Word16 *secDiag_e, - const Word16 nChannelsL, - const Word16 nChannelsC, - const Word16 currChannel, - Word32 *sig_x, + const Word16 nChannelsL, /* Q0 */ + const Word16 nChannelsC, /* Q0 */ + const Word16 currChannel, /* Q0 */ + Word32 *sig_x, /* exp(sig_x_e) */ Word16 *sig_x_e, - Word32 *g ) // Q31 + Word32 *g /* Q31 */ +) { Word16 iCh, jCh, idx; Word32 norm_x, f, r; @@ -1337,14 +1345,14 @@ static void biDiagonalReductionLeft_fx( set16_fx( sing_exp2[jCh], *singularVectors_e, MAX_OUTPUT_CHANNELS ); } - secDiag[currChannel] = Mpy_32_32( *sig_x, *g ); + secDiag[currChannel] = Mpy_32_32( *sig_x, *g ); /* exp(sig_x_e) */ move32(); // rescaling block IF( GT_16( *sig_x_e, *secDiag_e ) ) { FOR( Word16 i = 0; i < MAX_OUTPUT_CHANNELS; i++ ){ IF( NE_16( i, currChannel ) ){ - secDiag[i] = L_shl( secDiag[i], sub( *secDiag_e, *sig_x_e ) ); + secDiag[i] = L_shl( secDiag[i], sub( *secDiag_e, *sig_x_e ) ); /* sig_x_e */ move32(); } } @@ -1353,7 +1361,7 @@ move16(); } ELSE IF( LT_16( *sig_x_e, *secDiag_e ) ) { - secDiag[currChannel] = L_shr_r( secDiag[currChannel], sub( *secDiag_e, *sig_x_e ) ); + secDiag[currChannel] = L_shr_r( secDiag[currChannel], sub( *secDiag_e, *sig_x_e ) ); /* exp(secDiag_e) */ move32(); } @@ -1370,7 +1378,7 @@ IF( LT_16( currChannel, nChannelsL ) ) /* i <= m */ FOR( jCh = idx; jCh < nChannelsL; jCh++ ) /* nChannelsL */ { - ( *sig_x ) = BASOP_Util_Add_Mant32Exp( *sig_x, *sig_x_e, L_abs( singularVectors[jCh][currChannel] ), *singularVectors_e, sig_x_e ); + ( *sig_x ) = BASOP_Util_Add_Mant32Exp( *sig_x, *sig_x_e, L_abs( singularVectors[jCh][currChannel] ), *singularVectors_e, sig_x_e ); /* exp(sig_x_e) */ } IF( ( *sig_x ) ) /*(fabsf(*sig_x) > EPSILON * fabsf(*sig_x)) { */ @@ -1381,11 +1389,11 @@ IF( LT_16( currChannel, nChannelsL ) ) /* i <= m */ move16(); FOR( jCh = idx; jCh < nChannelsL; jCh++ ) /* nChannelsL */ { - singularVectors[jCh][currChannel] = BASOP_Util_Divide3232_Scale_cadence( singularVectors[jCh][currChannel], maxWithSign_fx( *sig_x ), &sing_exp[jCh] ); + singularVectors[jCh][currChannel] = BASOP_Util_Divide3232_Scale_cadence( singularVectors[jCh][currChannel], maxWithSign_fx( *sig_x ), &sing_exp[jCh] ); /* exp(sing_exp + (singularVectors_e - sig_x_e) */ move32(); sing_exp[jCh] = add( sing_exp[jCh], sub( *singularVectors_e, *sig_x_e ) ); move16(); - norm_x = BASOP_Util_Add_Mant32Exp( norm_x, norm_x_e, Mpy_32_32( singularVectors[jCh][currChannel], singularVectors[jCh][currChannel] ), shl( sing_exp[jCh], 1 ), &norm_x_e ); + norm_x = BASOP_Util_Add_Mant32Exp( norm_x, norm_x_e, Mpy_32_32( singularVectors[jCh][currChannel], singularVectors[jCh][currChannel] ), shl( sing_exp[jCh], 1 ), &norm_x_e ); /* exp(norm_x_e) */ } IF( GT_16( norm_x_e, 0 ) ) { @@ -1410,9 +1418,9 @@ IF( LT_16( currChannel, nChannelsL ) ) /* i <= m */ move32(); } - r = BASOP_Util_Add_Mant32Exp( Mpy_32_32( ( *g ), singularVectors[currChannel][idx] ), sing_exp[currChannel], -norm_x, norm_x_e, &r_e ); + r = BASOP_Util_Add_Mant32Exp( Mpy_32_32( ( *g ), singularVectors[currChannel][idx] ), sing_exp[currChannel], -norm_x, norm_x_e, &r_e ); /* exp(r_e) */ #ifdef FIX_827_HIGH_MLD - singularVectors[currChannel][idx] = BASOP_Util_Add_Mant32Exp( singularVectors[currChannel][idx], sing_exp[currChannel], -( *g ), 0, &sing_exp[currChannel] ); + singularVectors[currChannel][idx] = BASOP_Util_Add_Mant32Exp( singularVectors[currChannel][idx], sing_exp[currChannel], -( *g ), 0, &sing_exp[currChannel] ); /* sing_exp */ #else singularVectors[currChannel][idx] = BASOP_Util_Add_Mant32Exp( singularVectors[currChannel][idx], sing_exp[idx], -( *g ), 0, &sing_exp[currChannel] ); #endif @@ -1426,15 +1434,15 @@ IF( LT_16( currChannel, nChannelsL ) ) /* i <= m */ move16(); FOR( jCh = idx; jCh < nChannelsL; jCh++ ) /* nChannelsL */ { - norm_x = BASOP_Util_Add_Mant32Exp( norm_x, norm_x_e, Mpy_32_32( singularVectors[jCh][currChannel], singularVectors[jCh][iCh] ), add( sing_exp[jCh], *singularVectors_e ), &norm_x_e ); + norm_x = BASOP_Util_Add_Mant32Exp( norm_x, norm_x_e, Mpy_32_32( singularVectors[jCh][currChannel], singularVectors[jCh][iCh] ), add( sing_exp[jCh], *singularVectors_e ), &norm_x_e ); /* exp(norm_x_e) */ } - f = BASOP_Util_Divide3232_Scale_cadence( norm_x, maxWithSign_fx( r ), &f_e ); + f = BASOP_Util_Divide3232_Scale_cadence( norm_x, maxWithSign_fx( r ), &f_e ); /* f_e + (norm_x_e - r_e) */ f_e = add( f_e, sub( norm_x_e, r_e ) ); FOR( jCh = idx; jCh < nChannelsL; jCh++ ) /* nChannelsL */ { - singularVectors[jCh][iCh] = BASOP_Util_Add_Mant32Exp( singularVectors[jCh][iCh], *singularVectors_e, Mpy_32_32( f, singularVectors[jCh][currChannel] ), add( f_e, sing_exp[jCh] ), &sing_exp2[jCh][iCh] ); + singularVectors[jCh][iCh] = BASOP_Util_Add_Mant32Exp( singularVectors[jCh][iCh], *singularVectors_e, Mpy_32_32( f, singularVectors[jCh][currChannel] ), add( f_e, sing_exp[jCh] ), &sing_exp2[jCh][iCh] ); /* exp( sing_exp2) */ move32(); } } @@ -1442,7 +1450,7 @@ IF( LT_16( currChannel, nChannelsL ) ) /* i <= m */ FOR( jCh = idx; jCh < nChannelsL; jCh++ ) /* nChannelsL */ { - singularVectors[jCh][currChannel] = Mpy_32_32( singularVectors[jCh][currChannel], ( *sig_x ) ); + singularVectors[jCh][currChannel] = Mpy_32_32( singularVectors[jCh][currChannel], ( *sig_x ) ); /* sing_exp + sig_x_e */ move32(); sing_exp2[jCh][currChannel] = add( sing_exp[jCh], *sig_x_e ); move16(); @@ -1463,7 +1471,7 @@ IF( LT_16( currChannel, nChannelsL ) ) /* i <= m */ { FOR( jCh = 0; jCh < nChannelsL; jCh++ ) { - singularVectors[jCh][iCh] = L_shr_r( singularVectors[jCh][iCh], sub( exp_max, sing_exp2[jCh][iCh] ) ); + singularVectors[jCh][iCh] = L_shr_r( singularVectors[jCh][iCh], sub( exp_max, sing_exp2[jCh][iCh] ) ); /* exp(exp_max) */ move32(); } } @@ -1472,7 +1480,7 @@ IF( LT_16( currChannel, nChannelsL ) ) /* i <= m */ } // rescaling block - singularValues[currChannel] = Mpy_32_32( ( *sig_x ), ( *g ) ); + singularValues[currChannel] = Mpy_32_32( ( *sig_x ), ( *g ) ); /* sig_x_e */ move32(); singularValues_e[currChannel] = *sig_x_e; move16(); @@ -1561,16 +1569,17 @@ static void biDiagonalReductionLeft( #ifdef IVAS_FLOAT_FIXED static void biDiagonalReductionRight_fx( - Word32 singularVectors[][MAX_OUTPUT_CHANNELS], - Word32 secDiag[MAX_OUTPUT_CHANNELS], + Word32 singularVectors[][MAX_OUTPUT_CHANNELS], /* exp(singularVectors_e) */ + Word32 secDiag[MAX_OUTPUT_CHANNELS], /* exp(secDiag_e) */ Word16 *singularVectors_e, Word16 *secDiag_e, - const Word16 nChannelsL, - const Word16 nChannelsC, - const Word16 currChannel, - Word32 *sig_x, + const Word16 nChannelsL, /* Q0 */ + const Word16 nChannelsC, /* Q0 */ + const Word16 currChannel, /* Q0 */ + Word32 *sig_x, /* exp(sig_x_e) */ Word16 *sig_x_e, - Word32 *g ) + Word32 *g /* Q31 */ +) { Word16 iCh, jCh, idx; Word32 norm_x, r; @@ -1594,11 +1603,11 @@ static void biDiagonalReductionRight_fx( IF( LT_16( currChannel, nChannelsL ) && NE_16( currChannel, sub( nChannelsC, 1 ) ) ) /* i <=m && i !=n */ { - idx = add( currChannel, 1 ); + idx = add( currChannel, 1 ); /* Q0 */ FOR( jCh = idx; jCh < nChannelsC; jCh++ ) /* nChannelsC */ { - ( *sig_x ) = BASOP_Util_Add_Mant32Exp( *sig_x, *sig_x_e, L_abs( singularVectors[currChannel][jCh] ), *singularVectors_e, sig_x_e ); + ( *sig_x ) = BASOP_Util_Add_Mant32Exp( *sig_x, *sig_x_e, L_abs( singularVectors[currChannel][jCh] ), *singularVectors_e, sig_x_e ); /* exp(sig_x_e) */ } IF( ( *sig_x ) ) /*(fabsf(*sig_x) > EPSILON * fabsf(*sig_x)) { */ @@ -1610,11 +1619,11 @@ static void biDiagonalReductionRight_fx( FOR( jCh = idx; jCh < nChannelsC; jCh++ ) /*nChannelsC */ { - singularVectors[currChannel][jCh] = BASOP_Util_Divide3232_Scale_cadence( singularVectors[currChannel][jCh], maxWithSign_fx( *sig_x ), &sing_exp[jCh] ); + singularVectors[currChannel][jCh] = BASOP_Util_Divide3232_Scale_cadence( singularVectors[currChannel][jCh], maxWithSign_fx( *sig_x ), &sing_exp[jCh] ); /* exp(sing_exp + (singularVectors_e - sig_x_e)) */ move32(); sing_exp[jCh] = add( sing_exp[jCh], sub( *singularVectors_e, *sig_x_e ) ); move16(); - norm_x = BASOP_Util_Add_Mant32Exp( norm_x, norm_x_e, Mpy_32_32( singularVectors[currChannel][jCh], singularVectors[currChannel][jCh] ), shl( sing_exp[jCh], 1 ), &norm_x_e ); + norm_x = BASOP_Util_Add_Mant32Exp( norm_x, norm_x_e, Mpy_32_32( singularVectors[currChannel][jCh], singularVectors[currChannel][jCh] ), shl( sing_exp[jCh], 1 ), &norm_x_e ); /* exp(norm_x_e) */ } IF( GT_16( norm_x_e, 0 ) ) { @@ -1629,22 +1638,22 @@ static void biDiagonalReductionRight_fx( L_temp = L_shl_r( L_temp, L_temp_e ); // Q31 IF( singularVectors[currChannel][idx] >= 0 ) { - ( *g ) = L_negate( L_temp ); + ( *g ) = L_negate( L_temp ); /* exp(L_temp_e) */ move32(); } ELSE { - ( *g ) = L_negate( L_negate( L_temp ) ); + ( *g ) = L_negate( L_negate( L_temp ) ); /* exp(L_temp_e) */ move32(); } - r = BASOP_Util_Add_Mant32Exp( Mpy_32_32( ( *g ), singularVectors[currChannel][idx] ), sing_exp[idx], -norm_x, norm_x_e, &r_e ); - singularVectors[currChannel][idx] = BASOP_Util_Add_Mant32Exp( singularVectors[currChannel][idx], sing_exp[idx], -( *g ), 0, &sing_exp[idx] ); + r = BASOP_Util_Add_Mant32Exp( Mpy_32_32( ( *g ), singularVectors[currChannel][idx] ), sing_exp[idx], -norm_x, norm_x_e, &r_e ); /* exp(r_e) */ + singularVectors[currChannel][idx] = BASOP_Util_Add_Mant32Exp( singularVectors[currChannel][idx], sing_exp[idx], -( *g ), 0, &sing_exp[idx] ); /* exp(sing_exp) */ move32(); FOR( jCh = idx; jCh < nChannelsC; jCh++ ) /* nChannelsC */ { - secDiag[jCh] = BASOP_Util_Divide3232_Scale_cadence( singularVectors[currChannel][jCh], maxWithSign_fx( r ), &secDiag_exp[jCh] ); + secDiag[jCh] = BASOP_Util_Divide3232_Scale_cadence( singularVectors[currChannel][jCh], maxWithSign_fx( r ), &secDiag_exp[jCh] ); /* exp(secDiag_exp + (sing_exp - r_e) */ move32(); secDiag_exp[jCh] = add( secDiag_exp[jCh], sub( sing_exp[jCh], r_e ) ); move32(); @@ -1658,19 +1667,19 @@ static void biDiagonalReductionRight_fx( move16(); FOR( jCh = idx; jCh < nChannelsC; jCh++ ) /* nChannelsC */ { - norm_x = BASOP_Util_Add_Mant32Exp( norm_x, norm_x_e, Mpy_32_32( singularVectors[iCh][jCh], singularVectors[currChannel][jCh] ), add( *singularVectors_e, sing_exp[jCh] ), &norm_x_e ); + norm_x = BASOP_Util_Add_Mant32Exp( norm_x, norm_x_e, Mpy_32_32( singularVectors[iCh][jCh], singularVectors[currChannel][jCh] ), add( *singularVectors_e, sing_exp[jCh] ), &norm_x_e ); /* exp(norm_x_e) */ } FOR( jCh = idx; jCh < nChannelsC; jCh++ ) /* nChannelsC */ { - singularVectors[iCh][jCh] = BASOP_Util_Add_Mant32Exp( singularVectors[iCh][jCh], *singularVectors_e, Mpy_32_32( norm_x, secDiag[jCh] ), add( norm_x_e, secDiag_exp[jCh] ), &sing_exp2[iCh][jCh] ); + singularVectors[iCh][jCh] = BASOP_Util_Add_Mant32Exp( singularVectors[iCh][jCh], *singularVectors_e, Mpy_32_32( norm_x, secDiag[jCh] ), add( norm_x_e, secDiag_exp[jCh] ), &sing_exp2[iCh][jCh] ); /* exp(sing_exp2) */ move32(); } } FOR( jCh = idx; jCh < nChannelsC; jCh++ ) /* nChannelsC */ { - singularVectors[currChannel][jCh] = Mpy_32_32( singularVectors[currChannel][jCh], ( *sig_x ) ); + singularVectors[currChannel][jCh] = Mpy_32_32( singularVectors[currChannel][jCh], ( *sig_x ) ); /* exp(sing_exp + sig_x_e) */ move32(); sing_exp2[currChannel][jCh] = add( sing_exp[jCh], *sig_x_e ); move16(); @@ -1685,7 +1694,7 @@ static void biDiagonalReductionRight_fx( } FOR( jCh = 0; jCh < nChannelsC; jCh++ ) { - secDiag[jCh] = L_shr_r( secDiag[jCh], sub( exp_max, secDiag_exp[jCh] ) ); + secDiag[jCh] = L_shr_r( secDiag[jCh], sub( exp_max, secDiag_exp[jCh] ) ); /* exp(exp_max) */ move32(); } @@ -1704,7 +1713,7 @@ static void biDiagonalReductionRight_fx( { FOR( jCh = 0; jCh < nChannelsC; jCh++ ) { - singularVectors[iCh][jCh] = L_shr_r( singularVectors[iCh][jCh], sub( exp_max, sing_exp2[iCh][jCh] ) ); + singularVectors[iCh][jCh] = L_shr_r( singularVectors[iCh][jCh], sub( exp_max, sing_exp2[iCh][jCh] ) ); /* exp(exp_max) */ move32(); } } @@ -1792,12 +1801,13 @@ static void biDiagonalReductionRight( #ifdef IVAS_FLOAT_FIXED static void singularVectorsAccumulationLeft_fx( - Word32 singularVectors_Left[][MAX_OUTPUT_CHANNELS], // Q31 output - Word32 singularValues[MAX_OUTPUT_CHANNELS], + Word32 singularVectors_Left[][MAX_OUTPUT_CHANNELS], /* exp(singularVectors_e) as Input, Q31 as output */ + Word32 singularValues[MAX_OUTPUT_CHANNELS], /* exp(singularValues_e) */ Word16 singularVectors_e, Word16 singularValues_e[MAX_OUTPUT_CHANNELS], - const Word16 nChannelsL, - const Word16 nChannelsC ) + const Word16 nChannelsL, /* Q0 */ + const Word16 nChannelsC /* Q0 */ +) { Word16 nCh, iCh, k; Word16 nChannels; @@ -1810,11 +1820,11 @@ static void singularVectorsAccumulationLeft_fx( } /* Processing */ - nChannels = min( nChannelsL, nChannelsC ); /* min(nChannelsL,ChannelsC) */ + nChannels = s_min( nChannelsL, nChannelsC ); /* min(nChannelsL,ChannelsC) Q0*/ // FILE *fp = fopen("t_ii_out.txt","a"); FOR( nCh = nChannels - 1; nCh >= 0; nCh-- ) /* min(nChannelsL,ChannelsC) */ { - t_ii = singularValues[nCh]; + t_ii = singularValues[nCh]; /* exp(singularValues_e) */ move32(); t_ii_e = singularValues_e[nCh]; move16(); @@ -1827,7 +1837,7 @@ static void singularVectorsAccumulationLeft_fx( IF( t_ii ) /*if (fabsf(t_ii) > EPSILON *fabsf(t_ii)) {*/ { - t_ii = BASOP_Util_Divide3232_Scale_cadence( ONE_IN_Q30, maxWithSign_fx( t_ii ), &temp_exp ); + t_ii = BASOP_Util_Divide3232_Scale_cadence( ONE_IN_Q30, maxWithSign_fx( t_ii ), &temp_exp ); /* exp(1 + (temp_exp + tii_e)) */ t_ii_e = add( 1, sub( temp_exp, t_ii_e ) ); // fprintf( fp, "%e\n", me2f( t_ii, t_ii_e ) ); FOR( iCh = nCh + 1; iCh < nChannelsC; iCh++ ) /* nChannelsC */ @@ -1838,21 +1848,21 @@ static void singularVectorsAccumulationLeft_fx( move16(); FOR( k = nCh + 1; k < nChannelsL; k++ ) /* nChannelsL */ { - norm_y = BASOP_Util_Add_Mant32Exp( norm_y, norm_y_e, Mpy_32_32( singularVectors_Left[k][nCh], singularVectors_Left[k][iCh] ), add( sing_exp2[k][nCh], sing_exp2[k][iCh] ), &norm_y_e ); + norm_y = BASOP_Util_Add_Mant32Exp( norm_y, norm_y_e, Mpy_32_32( singularVectors_Left[k][nCh], singularVectors_Left[k][iCh] ), add( sing_exp2[k][nCh], sing_exp2[k][iCh] ), &norm_y_e ); /* exp(norm_y_e) */ } t_jj = BASOP_Util_Divide3232_Scale_cadence( Mpy_32_32( t_ii, norm_y ), maxWithSign_fx( singularVectors_Left[nCh][nCh] ), &temp_exp ); // t_ii_e+norm_y_e-*singularVectors_e, t_jj_e = add( temp_exp, sub( add( t_ii_e, norm_y_e ), sing_exp2[nCh][nCh] ) ); FOR( k = nCh; k < nChannelsL; k++ ) /* nChannelsL */ { - singularVectors_Left[k][iCh] = BASOP_Util_Add_Mant32Exp( singularVectors_Left[k][iCh], sing_exp2[k][iCh], Mpy_32_32( t_jj, singularVectors_Left[k][nCh] ), add( t_jj_e, sing_exp2[k][nCh] ), &sing_exp2[k][iCh] ); + singularVectors_Left[k][iCh] = BASOP_Util_Add_Mant32Exp( singularVectors_Left[k][iCh], sing_exp2[k][iCh], Mpy_32_32( t_jj, singularVectors_Left[k][nCh] ), add( t_jj_e, sing_exp2[k][nCh] ), &sing_exp2[k][iCh] ); /* exp(sing_exp2) */ move32(); } } FOR( iCh = nCh; iCh < nChannelsL; iCh++ ) /* nChannelsL */ { - singularVectors_Left[iCh][nCh] = Mpy_32_32( singularVectors_Left[iCh][nCh], t_ii ); + singularVectors_Left[iCh][nCh] = Mpy_32_32( singularVectors_Left[iCh][nCh], t_ii ); /* exp(sing_exp2 + t_ii_e) */ move32(); sing_exp2[iCh][nCh] = add( sing_exp2[iCh][nCh], t_ii_e ); move16(); @@ -1867,7 +1877,7 @@ static void singularVectorsAccumulationLeft_fx( } } - singularVectors_Left[nCh][nCh] = BASOP_Util_Add_Mant32Exp( singularVectors_Left[nCh][nCh], sing_exp2[nCh][nCh], ONE_IN_Q30, 1, &sing_exp2[nCh][nCh] ); + singularVectors_Left[nCh][nCh] = BASOP_Util_Add_Mant32Exp( singularVectors_Left[nCh][nCh], sing_exp2[nCh][nCh], ONE_IN_Q30, 1, &sing_exp2[nCh][nCh] ); /* exp(sing_exp2) */ move32(); } // fclose(fp); @@ -1875,7 +1885,7 @@ static void singularVectorsAccumulationLeft_fx( { FOR( iCh = 0; iCh < nChannelsC; iCh++ ) { - singularVectors_Left[nCh][iCh] = L_shl_sat( singularVectors_Left[nCh][iCh], sing_exp2[nCh][iCh] ); + singularVectors_Left[nCh][iCh] = L_shl_sat( singularVectors_Left[nCh][iCh], sing_exp2[nCh][iCh] ); /* Q31 */ move32(); } } @@ -1953,12 +1963,13 @@ static void singularVectorsAccumulationLeft( #ifdef IVAS_FLOAT_FIXED static void singularVectorsAccumulationRight_fx( - Word32 singularVectors_Left[][MAX_OUTPUT_CHANNELS], - Word32 singularVectors_Right[][MAX_OUTPUT_CHANNELS], // Q31 - Word32 secDiag[MAX_OUTPUT_CHANNELS], + Word32 singularVectors_Left[][MAX_OUTPUT_CHANNELS], /* Q31 */ + Word32 singularVectors_Right[][MAX_OUTPUT_CHANNELS], /* Q31 */ + Word32 secDiag[MAX_OUTPUT_CHANNELS], /* exp(secDiag_e) */ Word16 singularVectors_e, Word16 secDiag_e, - const Word16 nChannelsC ) + const Word16 nChannelsC /* Q0 */ +) { Word16 nCh, iCh, k; Word16 nChannels; @@ -1966,10 +1977,10 @@ static void singularVectorsAccumulationRight_fx( Word16 norm_y_e, temp_exp1, sing_right_exp[MAX_OUTPUT_CHANNELS][MAX_OUTPUT_CHANNELS] = { 0 }; /* Processing */ - nChannels = nChannelsC; /* nChannelsC */ + nChannels = nChannelsC; /* nChannelsC Q0*/ /* avoid compiler warning */ - t_ii = secDiag[nChannels - 1]; + t_ii = secDiag[nChannels - 1]; /* exp(secDiag_e) */ move32(); FOR( nCh = nChannels - 1; nCh >= 0; nCh-- ) /* nChannelsC, min(nChannelsLmnChannelsC) otherwise */ @@ -1982,8 +1993,8 @@ static void singularVectorsAccumulationRight_fx( FOR( iCh = nCh + 1; iCh < nChannelsC; iCh++ ) /* nChannelsC*/ { - ratio_float = BASOP_Util_Divide3232_Scale_cadence( singularVectors_Left[nCh][iCh], maxWithSign_fx( singularVectors_Left[nCh][nCh + 1] ), &temp_exp1 ); - singularVectors_Right[iCh][nCh] = BASOP_Util_Divide3232_Scale_cadence( ratio_float, maxWithSign_fx( t_ii ), &sing_right_exp[iCh][nCh] ); + ratio_float = BASOP_Util_Divide3232_Scale_cadence( singularVectors_Left[nCh][iCh], maxWithSign_fx( singularVectors_Left[nCh][nCh + 1] ), &temp_exp1 ); /* exp(temp_exp1) */ + singularVectors_Right[iCh][nCh] = BASOP_Util_Divide3232_Scale_cadence( ratio_float, maxWithSign_fx( t_ii ), &sing_right_exp[iCh][nCh] ); /* exp(sing_right_exp + (temp_exp1 - secDiag_e) */ move32(); sing_right_exp[iCh][nCh] = add( sing_right_exp[iCh][nCh], sub( temp_exp1, secDiag_e ) ); move16(); @@ -1999,14 +2010,14 @@ static void singularVectorsAccumulationRight_fx( FOR( k = nCh + 1; k < nChannelsC; k++ ) /* nChannelsC */ { - norm_y = BASOP_Util_Add_Mant32Exp( norm_y, norm_y_e, Mpy_32_32( singularVectors_Left[nCh][k], singularVectors_Right[k][iCh] ), add( singularVectors_e, sing_right_exp[k][iCh] ), &norm_y_e ); + norm_y = BASOP_Util_Add_Mant32Exp( norm_y, norm_y_e, Mpy_32_32( singularVectors_Left[nCh][k], singularVectors_Right[k][iCh] ), add( singularVectors_e, sing_right_exp[k][iCh] ), &norm_y_e ); /* exp(norm_y_e) */ } FOR( k = nCh + 1; k < nChannelsC; k++ ) /* nChannelsC */ { - singularVectors_Right[k][iCh] = BASOP_Util_Add_Mant32Exp( singularVectors_Right[k][iCh], sing_right_exp[k][iCh], Mpy_32_32( norm_y, singularVectors_Right[k][nCh] ), add( norm_y_e, sing_right_exp[k][nCh] ), &sing_right_exp[k][iCh] ); + singularVectors_Right[k][iCh] = BASOP_Util_Add_Mant32Exp( singularVectors_Right[k][iCh], sing_right_exp[k][iCh], Mpy_32_32( norm_y, singularVectors_Right[k][nCh] ), add( norm_y_e, sing_right_exp[k][nCh] ), &sing_right_exp[k][iCh] ); /* exp(sing_right_exp) */ move32(); - singularVectors_Right[k][iCh] = L_shl_sat( singularVectors_Right[k][iCh], sing_right_exp[k][iCh] ); + singularVectors_Right[k][iCh] = L_shl_sat( singularVectors_Right[k][iCh], sing_right_exp[k][iCh] ); /* Q31 */ move32(); sing_right_exp[k][iCh] = 0; move16(); @@ -2023,7 +2034,7 @@ static void singularVectorsAccumulationRight_fx( } singularVectors_Right[nCh][nCh] = MAX_32; move32(); - t_ii = secDiag[nCh]; + t_ii = secDiag[nCh]; /* exp(secDiag_e) */ move32(); } return; @@ -2096,9 +2107,9 @@ static void singularVectorsAccumulationRight( #ifdef IVAS_FLOAT_FIXED static Word32 GivensRotation_fx( - const Word32 x, + const Word32 x, /* exp(x_e) */ const Word16 x_e, - const Word32 z, + const Word32 z, /* exp(z_e) */ const Word16 z_e, Word16 *out_e ) { @@ -2123,11 +2134,11 @@ static Word32 GivensRotation_fx( } ELSE { - cotan = BASOP_Util_Divide3232_Scale_cadence( z_abs, x_abs, &temp_exp ); + cotan = BASOP_Util_Divide3232_Scale_cadence( z_abs, x_abs, &temp_exp ); /* exp(temp_exp + (z_e - x_e) */ temp_exp = add( temp_exp, sub( z_e, x_e ) ); - L_temp = BASOP_Util_Add_Mant32Exp( ONE_IN_Q30, 1, Mpy_32_32( cotan, cotan ), 2 * temp_exp, &temp_exp ); + L_temp = BASOP_Util_Add_Mant32Exp( ONE_IN_Q30, 1, Mpy_32_32( cotan, cotan ), 2 * temp_exp, &temp_exp ); /* exp(temp_exp) */ L_temp = Sqrt32( L_temp, &temp_exp ); - r = Mpy_32_32( x_abs, L_temp ); + r = Mpy_32_32( x_abs, L_temp ); /* exp(x_e + temp_exp) */ *out_e = add( x_e, temp_exp ); } } @@ -2140,11 +2151,11 @@ static Word32 GivensRotation_fx( } ELSE { - tan = BASOP_Util_Divide3232_Scale_cadence( x_abs, z_abs, &temp_exp ); + tan = BASOP_Util_Divide3232_Scale_cadence( x_abs, z_abs, &temp_exp ); /* exp(temp_exp + (x_e - z_e) */ temp_exp = add( temp_exp, sub( x_e, z_e ) ); - L_temp = BASOP_Util_Add_Mant32Exp( ONE_IN_Q30, 1, Mpy_32_32( tan, tan ), shl( temp_exp, 1 ), &temp_exp ); + L_temp = BASOP_Util_Add_Mant32Exp( ONE_IN_Q30, 1, Mpy_32_32( tan, tan ), shl( temp_exp, 1 ), &temp_exp ); /* exp(temp_exp) */ L_temp = Sqrt32( L_temp, &temp_exp ); - r = Mpy_32_32( z_abs, L_temp ); + r = Mpy_32_32( z_abs, L_temp ); /* exp(z_e + temp_exp) */ *out_e = add( z_e, temp_exp ); } } @@ -2201,7 +2212,8 @@ static float GivensRotation( #ifdef IVAS_FLOAT_FIXED static Word32 maxWithSign_fx( - const Word32 a ) + const Word32 a /* Qx */ +) { IF( GT_32( L_abs( a ), SVD_MINIMUM_VALUE_FX ) ) { diff --git a/lib_dec/ivas_tcx_core_dec.c b/lib_dec/ivas_tcx_core_dec.c index d0bed2c21..05734c278 100644 --- a/lib_dec/ivas_tcx_core_dec.c +++ b/lib_dec/ivas_tcx_core_dec.c @@ -65,9 +65,9 @@ static void stereo_tcx_dec_mode_switch_reconf_ivas_fx( Decoder_State *st, const *-------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED void stereo_tcx_init_dec_fx( - Decoder_State *st, /* i/o: decoder state structure */ - const Word16 MCT_flag, /* i : hMCT handle allocated (1) or not (0)*/ - const Word16 last_element_mode /* i : element mode of previous frame */ + Decoder_State *st, /* i/o: decoder state structure */ + const Word16 MCT_flag, /* i : hMCT handle allocated (1) or not (0) Q0*/ + const Word16 last_element_mode /* i : element mode of previous frame Q0*/ ) { TCX_LTP_DEC_HANDLE hTcxLtpDec = st->hTcxLtpDec; @@ -75,20 +75,20 @@ void stereo_tcx_init_dec_fx( st->rate_switching_init = 0; move16(); - st->m_frame_type = ACTIVE_FRAME; + st->m_frame_type = ACTIVE_FRAME; /* Q0 */ move16(); - st->core_brate = st->total_brate; + st->core_brate = st->total_brate; /* Q0 */ move32(); /*sampling rate*/ - st->sr_core = getCoreSamplerateMode2( st->element_mode, L_mult0( st->bits_frame_nominal, FRAMES_PER_SEC ), st->bwidth, st->flag_ACELP16k, st->rf_flag, st->is_ism_format ); + st->sr_core = getCoreSamplerateMode2( st->element_mode, L_mult0( st->bits_frame_nominal, FRAMES_PER_SEC ), st->bwidth, st->flag_ACELP16k, st->rf_flag, st->is_ism_format ); /* Q0 */ move32(); - st->fscale = sr2fscale_fx( st->sr_core ); + st->fscale = sr2fscale_fx( st->sr_core ); /* Q0 */ move16(); /*frame size*/ - st->L_frame = extract_l( Mult_32_16( st->sr_core, INV_FRAME_PER_SEC_Q15 ) ); - hTcxDec->L_frameTCX = extract_l( Mult_32_16( st->output_Fs, INV_FRAME_PER_SEC_Q15 ) ); + st->L_frame = extract_l( Mult_32_16( st->sr_core, INV_FRAME_PER_SEC_Q15 ) ); /* Q0 */ + hTcxDec->L_frameTCX = extract_l( Mult_32_16( st->output_Fs, INV_FRAME_PER_SEC_Q15 ) ); /* Q0 */ move16(); move16(); @@ -98,47 +98,47 @@ void stereo_tcx_init_dec_fx( test(); IF( ( EQ_16( st->L_frame, L_FRAME16k ) && LE_32( L_mult0( st->bits_frame_nominal, FRAMES_PER_SEC ), MAX_ACELP_BRATE ) ) || ( st->tcxonly && ( EQ_32( st->sr_core, 32000 ) || EQ_32( st->sr_core, INT_FS_16k ) ) ) ) { - st->nb_subfr = NB_SUBFR16k; + st->nb_subfr = NB_SUBFR16k; /* Q0 */ move16(); } ELSE { - st->nb_subfr = NB_SUBFR; + st->nb_subfr = NB_SUBFR; /* Q0 */ move16(); } move16(); /*TCX tools*/ - st->hTcxCfg->ctx_hm = getCtxHm( st->element_mode, L_mult0( st->bits_frame_nominal, FRAMES_PER_SEC ), st->rf_flag ); + st->hTcxCfg->ctx_hm = getCtxHm( st->element_mode, L_mult0( st->bits_frame_nominal, FRAMES_PER_SEC ), st->rf_flag ); /* Q0 */ move16(); - st->hTcxCfg->resq = getResq( L_mult0( st->bits_frame_nominal, FRAMES_PER_SEC ) ); + st->hTcxCfg->resq = getResq( L_mult0( st->bits_frame_nominal, FRAMES_PER_SEC ) ); /* Q0 */ move16(); - hTcxDec->tcx_lpc_shaped_ari = getTcxLpcShapedAri( L_mult0( st->bits_frame_nominal, FRAMES_PER_SEC ), st->rf_flag, st->element_mode ); + hTcxDec->tcx_lpc_shaped_ari = getTcxLpcShapedAri( L_mult0( st->bits_frame_nominal, FRAMES_PER_SEC ), st->rf_flag, st->element_mode ); /* Q0 */ move16(); - st->igf = getIgfPresent_fx( st->element_mode, L_mult0( st->bits_frame_nominal, FRAMES_PER_SEC ), st->bwidth, st->rf_flag ); + st->igf = getIgfPresent_fx( st->element_mode, L_mult0( st->bits_frame_nominal, FRAMES_PER_SEC ), st->bwidth, st->rf_flag ); /* Q0 */ move16(); IF( st->element_mode != EVS_MONO ) { - st->hTcxCfg->fIsTNSAllowed = getTnsAllowed( L_mult0( st->bits_frame_nominal, FRAMES_PER_SEC ), st->igf, st->element_mode ); + st->hTcxCfg->fIsTNSAllowed = getTnsAllowed( L_mult0( st->bits_frame_nominal, FRAMES_PER_SEC ), st->igf, st->element_mode ); /* Q0 */ move16(); } IF( hTcxLtpDec != NULL ) { - hTcxLtpDec->tcxltp = getTcxLtp( st->sr_core ); + hTcxLtpDec->tcxltp = getTcxLtp( st->sr_core ); /* Q0 */ move16(); } IF( EQ_16( st->element_mode, IVAS_SCE ) ) { - st->tcxonly = getTcxonly_fx( st->element_mode, L_mult0( st->bits_frame_nominal, FRAMES_PER_SEC ), MCT_flag, st->is_ism_format ); + st->tcxonly = getTcxonly_fx( st->element_mode, L_mult0( st->bits_frame_nominal, FRAMES_PER_SEC ), MCT_flag, st->is_ism_format ); /* Q0 */ move16(); /* LPC quantization */ test(); IF( LE_32( st->sr_core, INT_FS_16k ) && st->tcxonly == 0 ) { - st->lpcQuantization = 1; + st->lpcQuantization = 1; /* Q0 */ move16(); } ELSE @@ -150,12 +150,12 @@ void stereo_tcx_init_dec_fx( IF( st->tcxonly == 0 ) { - st->numlpc = 1; + st->numlpc = 1; /* Q0 */ move16(); } ELSE { - st->numlpc = 2; + st->numlpc = 2; /* Q0 */ move16(); } move16(); @@ -284,18 +284,18 @@ void stereo_tcx_init_dec( *-------------------------------------------------------------------*/ void stereo_tcx_core_dec_fx( - Decoder_State *st, /* i/o: decoder state structure */ - const FRAME_MODE frameMode, /* i : Decoder frame mode */ - Word16 *signal_out_fx, /* o : synthesis @internal_Fs, Q0 */ - Word16 *signal_outFB_fx, /* o : synthesis @output_Fs, Q0 */ - Word16 pitch_buf_fx[], /* o : Word16 pitch for each subframe, Q6 */ - const Word16 sba_dirac_stereo_flag, /* i : signal stereo output for SBA DirAC */ - STEREO_TD_DEC_DATA_HANDLE hStereoTD, /* i/o: TD stereo decoder handle */ - const Word16 last_element_mode, /* i : last element mode */ - const Word16 flag_sec_CNA, /* i : CNA flag for secondary channel */ - STEREO_CNG_DEC_HANDLE hStereoCng, /* i : Stereo CNG handle */ - const Word16 nchan_out, /* i : number of output channels */ - const IVAS_FORMAT ivas_format /* i : IVAS format */ + Decoder_State *st, /* i/o: decoder state structure */ + const FRAME_MODE frameMode, /* i : Decoder frame mode */ + Word16 *signal_out_fx, /* o : synthesis @internal_Fs, Q0*/ + Word16 *signal_outFB_fx, /* o : synthesis @output_Fs, Q0*/ + Word16 pitch_buf_fx[], /* o : Word16 pitch for each subframe, Q6*/ + const Word16 sba_dirac_stereo_flag, /* i : signal stereo output for SBA DirAC Q0*/ + STEREO_TD_DEC_DATA_HANDLE hStereoTD, /* i/o: TD stereo decoder handle */ + const Word16 last_element_mode, /* i : last element mode Q0*/ + const Word16 flag_sec_CNA, /* i : CNA flag for secondary channel Q0*/ + STEREO_CNG_DEC_HANDLE hStereoCng, /* i : Stereo CNG handle */ + const Word16 nchan_out, /* i : number of output channels Q0*/ + const IVAS_FORMAT ivas_format /* i : IVAS format */ ) { Word16 i, k; @@ -357,10 +357,10 @@ void stereo_tcx_core_dec_fx( *--------------------------------------------------------------------------------*/ iDiv_and_mod_32( st->total_brate, FRAMES_PER_SEC, &L_tmp, &mod, 0 ); - total_nbbits = extract_l( L_tmp ); + total_nbbits = extract_l( L_tmp ); /* Q0 */ bitsRead = 0; move16(); - LSF_Q_prediction = -1; /* to avoid compilation warnings */ + LSF_Q_prediction = -1; /* to avoid compilation warnings Q0*/ move16(); IF( frameMode == FRAMEMODE_NORMAL ) @@ -375,7 +375,7 @@ void stereo_tcx_core_dec_fx( { st->m_decodeMode = DEC_CONCEALMENT_EXT; move32(); - bfi = 1; + bfi = 1; /* Q0 */ move16(); } /* for bass postfilter */ @@ -394,8 +394,8 @@ void stereo_tcx_core_dec_fx( /* Initialize pointers */ synth_fx = synth_buf_fx + hTcxDec->old_synth_len; synthFB_fx = synth_bufFB_fx + hTcxDec->old_synth_lenFB; - Copy_Scale_sig( hTcxDec->old_synth, synth_buf_fx, hTcxDec->old_synth_len, negate( st->Q_syn ) ); - Copy( hTcxDec->old_synthFB_fx, synth_bufFB_fx, hTcxDec->old_synth_lenFB ); + Copy_Scale_sig( hTcxDec->old_synth, synth_buf_fx, hTcxDec->old_synth_len, negate( st->Q_syn ) ); /* q_old_synth - st->Q_syn */ + Copy( hTcxDec->old_synthFB_fx, synth_bufFB_fx, hTcxDec->old_synth_lenFB ); /* q_old_synthFB */ set16_fx( synth_fx, 0, L_FRAME_PLUS + M ); set16_fx( synthFB_fx, 0, L_FRAME_PLUS + M ); @@ -405,7 +405,7 @@ void stereo_tcx_core_dec_fx( IF( !bfi ) { - st->second_last_core = st->last_core; + st->second_last_core = st->last_core; /* Q0 */ move16(); move16(); @@ -421,7 +421,7 @@ void stereo_tcx_core_dec_fx( /* PLC: [Common: mode decision] * PLC: Decide which Concealment to use. Update pitch lags if needed */ - st->core = GetPLCModeDecision_ivas_fx( st ); + st->core = GetPLCModeDecision_ivas_fx( st ); /* Q0 */ move16(); } @@ -442,24 +442,24 @@ void stereo_tcx_core_dec_fx( test(); IF( bfi && st->use_partial_copy && EQ_16( st->rf_frame_type, RF_TCXFD ) ) { - tcx_lpc_cdk = tcxlpc_get_cdk( GENERIC ); + tcx_lpc_cdk = tcxlpc_get_cdk( GENERIC ); /* Q0 */ move16(); } ELSE { - tcx_lpc_cdk = tcxlpc_get_cdk( st->coder_type ); + tcx_lpc_cdk = tcxlpc_get_cdk( st->coder_type ); /* Q0 */ move16(); } - Copy( st->lsf_old_fx, &lsf_fx[0], M ); - Copy( st->lsp_old_fx, &lsp_fx[0], M ); + Copy( st->lsf_old_fx, &lsf_fx[0], M ); /* Q2.56 */ + Copy( st->lsp_old_fx, &lsp_fx[0], M ); /* Q15 */ D_lsf_tcxlpc( param_lpc, &lsf_fx[M], lspind, st->narrowBand, tcx_lpc_cdk, st->mem_MA_fx ); lsf2lsp_fx( &lsf_fx[M], &lsp_fx[M], M, st->sr_core ); lsf_update_memory( st->narrowBand, &lsf_fx[M], st->mem_MA_fx, st->mem_MA_fx, M ); - Copy( &lsf_fx[M], st->mem_AR_fx, M ); + Copy( &lsf_fx[M], st->mem_AR_fx, M ); /* Q2.56 */ hTcxDec->envWeighted = 1; move16(); @@ -470,8 +470,8 @@ void stereo_tcx_core_dec_fx( { IF( hTcxDec->envWeighted ) { - Copy( st->lspold_uw, st->lsp_old_fx, M ); - Copy( st->lsfold_uw, st->lsf_old_fx, M ); + Copy( st->lspold_uw, st->lsp_old_fx, M ); /* Q15 */ + Copy( st->lsfold_uw, st->lsf_old_fx, M ); /* Q2.56 */ hTcxDec->envWeighted = 0; move16(); } @@ -480,8 +480,8 @@ void stereo_tcx_core_dec_fx( FOR( k = 0; k < st->numlpc; ++k ) { - Copy( &lsp_fx[imult1616( add( k, 1 ), M )], &lspnew_uw_fx[k * M], M ); /*basop not used for k * M as M is a multiple of 2*/ - Copy( &lsf_fx[imult1616( add( k, 1 ), M )], &lsfnew_uw_fx[k * M], M ); + Copy( &lsp_fx[( k + 1 ) * M], &lspnew_uw_fx[k * M], M ); /*basop not used for k * M as M is a multiple of 2 Q15*/ + Copy( &lsf_fx[( k + 1 ) * M], &lsfnew_uw_fx[k * M], M ); /* Q2.56 */ } } @@ -490,11 +490,11 @@ void stereo_tcx_core_dec_fx( { FOR( i = 0; i < M; i++ ) { - st->lsf_adaptive_mean_fx[i] = add( add( mult_r( st->lsfoldbfi1_fx[i], ONE_BY_THREE_Q15 ), mult_r( st->lsfoldbfi0_fx[i], ONE_BY_THREE_Q15 ) ), mult_r( lsfnew_uw_fx[add( i_mult( k, M ), i )], ONE_BY_THREE_Q15 ) ); + st->lsf_adaptive_mean_fx[i] = add( add( mult_r( st->lsfoldbfi1_fx[i], ONE_BY_THREE_Q15 ), mult_r( st->lsfoldbfi0_fx[i], ONE_BY_THREE_Q15 ) ), mult_r( lsfnew_uw_fx[k * M + i], ONE_BY_THREE_Q15 ) ); /* Q2.56 */ move16(); - st->lsfoldbfi1_fx[i] = st->lsfoldbfi0_fx[i]; + st->lsfoldbfi1_fx[i] = st->lsfoldbfi0_fx[i]; /* Q2.56 */ move16(); - st->lsfoldbfi0_fx[i] = lsfnew_uw_fx[add( i_mult( k, M ), i )]; + st->lsfoldbfi0_fx[i] = lsfnew_uw_fx[( k * M ) + i]; /* Q2.56 */ move16(); } } @@ -519,28 +519,28 @@ void stereo_tcx_core_dec_fx( IF( EQ_16( st->nbLostCmpt, 1 ) ) { - Copy( st->lsf_old_fx, st->old_lsf_q_cng, M ); - Copy( st->lsp_old_fx, st->old_lsp_q_cng, M ); + Copy( st->lsf_old_fx, st->old_lsf_q_cng, M ); /* Q2.56 */ + Copy( st->lsp_old_fx, st->old_lsp_q_cng, M ); /* Q15 */ } - lsfBase = PlcGetLsfBase( st->lpcQuantization, st->narrowBand, st->sr_core ); + lsfBase = PlcGetLsfBase( st->lpcQuantization, st->narrowBand, st->sr_core ); /* Q2.56 */ dlpc_bfi( st->L_frame, lsfnew_uw_fx, st->lsfold_uw, st->last_good, st->nbLostCmpt, st->mem_MA_fx, st->mem_AR_fx, &( st->stab_fac_fx ), st->lsf_adaptive_mean_fx, st->numlpc, st->lsf_cng, (Word8) st->plcBackgroundNoiseUpdated, st->lsf_q_cng, st->old_lsf_q_cng, lsfBase, (Word8) st->tcxonly ); hTcxDec->envWeighted = 0; move16(); - Copy( st->lspold_uw, lsp_fx, M ); - Copy( st->lsfold_uw, lsf_fx, M ); + Copy( st->lspold_uw, lsp_fx, M ); /* Q15 */ + Copy( st->lsfold_uw, lsf_fx, M ); /* Q2.56 */ FOR( k = 0; k < st->numlpc; k++ ) { - Copy( &lsfnew_uw_fx[k * M], &lsf_fx[imult1616( add( k, 1 ), M )], M ); + Copy( &lsfnew_uw_fx[k * M], &lsf_fx[( k + 1 ) * M], M ); /* Q2.56 */ - lsf2lsp_fx( &lsf_fx[imult1616( add( k, 1 ), M )], &lsp_fx[imult1616( add( k, 1 ), M )], M, st->sr_core ); - lsf2lsp_fx( st->lsf_q_cng, st->lsp_q_cng, M, st->sr_core ); + lsf2lsp_fx( &lsf_fx[( k + 1 ) * M], &lsp_fx[( k + 1 ) * M], M, st->sr_core ); /* Q2.56 */ + lsf2lsp_fx( st->lsf_q_cng, st->lsp_q_cng, M, st->sr_core ); /* Q2.56 */ - Copy( &lsp_fx[imult1616( add( k, 1 ), M )], &lspnew_uw_fx[k * M], M ); + Copy( &lsp_fx[( k + 1 ) * M], &lspnew_uw_fx[k * M], M ); /* Q2.56 */ } } @@ -550,19 +550,19 @@ void stereo_tcx_core_dec_fx( IF( st->rate_switching_reset ) { - Copy( &( lsf_fx[M] ), &( lsf_fx[0] ), M ); - Copy( &( lsp_fx[M] ), &( lsp_fx[0] ), M ); - Copy( &( lsf_fx[M] ), st->lsf_old_fx, M ); - Copy( &( lsp_fx[M] ), st->lsp_old_fx, M ); - Copy( &( lsf_fx[M] ), lsfmid_fx, M ); - Copy( &( lsp_fx[M] ), lspmid_fx, M ); + Copy( &( lsf_fx[M] ), &( lsf_fx[0] ), M ); /* Q2.56 */ + Copy( &( lsp_fx[M] ), &( lsp_fx[0] ), M ); /* Q15 */ + Copy( &( lsf_fx[M] ), st->lsf_old_fx, M ); /* Q2.56 */ + Copy( &( lsp_fx[M] ), st->lsp_old_fx, M ); /* Q2.56 */ + Copy( &( lsf_fx[M] ), lsfmid_fx, M ); /* Q2.56 */ + Copy( &( lsp_fx[M] ), lspmid_fx, M ); /* Q15 */ E_LPC_f_lsp_a_conversion( st->lsp_old_fx, st->old_Aq_12_8_fx, M ); } test(); if ( st->enablePlcWaveadjust && bfi ) { - st->hPlcInfo->nbLostCmpt = add( st->hPlcInfo->nbLostCmpt, 1 ); + st->hPlcInfo->nbLostCmpt = add( st->hPlcInfo->nbLostCmpt, 1 ); /* Q0 */ move16(); } @@ -586,11 +586,11 @@ void stereo_tcx_core_dec_fx( test(); IF( ( EQ_16( st->nbLostCmpt, 1 ) ) || hTcxDec->tcxConceal_recalc_exc ) { - Copy_Scale_sig( &synthFB_fx[negate( add( add( shr( st->hTcxDec->L_frameTCX, 1 ), hTcxDec->pit_max_TCX ), 2 * M ) )], &synthFB_fx[negate( add( add( shr( st->hTcxDec->L_frameTCX, 1 ), hTcxDec->pit_max_TCX ), 2 * M ) )], add( add( shr( st->hTcxDec->L_frameTCX, 1 ), hTcxDec->pit_max_TCX ), 2 * M ), negate( sub( st->Q_exc, 1 ) ) ); + Copy_Scale_sig( &synthFB_fx[-( ( st->hTcxDec->L_frameTCX / 2 ) + hTcxDec->pit_max_TCX + 2 * M )], &synthFB_fx[-( ( st->hTcxDec->L_frameTCX / 2 ) + hTcxDec->pit_max_TCX + 2 * M )], add( add( shr( st->hTcxDec->L_frameTCX, 1 ), hTcxDec->pit_max_TCX ), 2 * M ), negate( sub( st->Q_exc, 1 ) ) ); /* q_old_synthFB + Q_exc - 1 */ } ELSE { - Copy_Scale_sig( &synthFB_fx[negate( st->hTcxDec->L_frameTCX )], &synthFB_fx[negate( st->hTcxDec->L_frameTCX )], st->hTcxDec->L_frameTCX, negate( sub( st->Q_exc, 1 ) ) ); + Copy_Scale_sig( &synthFB_fx[-( st->hTcxDec->L_frameTCX )], &synthFB_fx[-( st->hTcxDec->L_frameTCX )], st->hTcxDec->L_frameTCX, negate( sub( st->Q_exc, 1 ) ) ); /* q_old_synthFB + Q_exc - 1 */ } lerp( synthFB_fx, synth_fx, st->L_frame, hTcxDec->L_frameTCX ); @@ -604,7 +604,7 @@ void stereo_tcx_core_dec_fx( test(); IF( st->narrowBand || EQ_32( st->sr_core, INT_FS_12k8 ) || EQ_32( st->sr_core, INT_FS_16k ) ) { - Copy( Aq_fx, st->mem_Aq, i_mult( st->nb_subfr, ( M + 1 ) ) ); + Copy( Aq_fx, st->mem_Aq, i_mult( st->nb_subfr, ( M + 1 ) ) ); /* Q12 */ } /* PLC: [TCX: Tonal Concealment] */ @@ -620,14 +620,14 @@ void stereo_tcx_core_dec_fx( *--------------------------------------------------------------------------------*/ /* Set pointer to parameters */ - prm = param; + prm = param; /* Q0 */ IF( EQ_16( st->core, TCX_20_CORE ) ) { /* Stability Factor */ IF( !bfi ) { - st->stab_fac_fx = lsf_stab_fx( &lsf_fx[M], &lsf_fx[0], 0, st->L_frame ); + st->stab_fac_fx = lsf_stab_fx( &lsf_fx[M], &lsf_fx[0], 0, st->L_frame ); /* Q15 */ move16(); } @@ -645,7 +645,7 @@ void stereo_tcx_core_dec_fx( /* diffuse LPC power on rate switching*/ RecLpcSpecPowDiffuseLc( &lsp_fx[M], &lsp_fx[0], &lsf_fx[M], st, 0 ); int_lsp_fx( st->L_frame, &lsp_fx[0], &lsp_fx[M], Aq_fx, M, interpol_frac_fx, 0 ); - Copy( &lsf_fx[M], lsfnew_uw_fx, M ); + Copy( &lsf_fx[M], lsfnew_uw_fx, M ); /* Q2.56 */ } ELSE { @@ -678,22 +678,22 @@ void stereo_tcx_core_dec_fx( FOR( k = 0; k < 2; k++ ) { /* Set pointer to parameters */ - prm = param + imult1616( k, DEC_NPRM_DIV ); + prm = param + imult1616( k, DEC_NPRM_DIV ); /* Q0 */ /* Stability Factor */ IF( !bfi ) { - st->stab_fac_fx = lsf_stab_fx( &lsf_fx[imult1616( add( k, 1 ), M )], &lsf_fx[k * M], 0, st->L_frame ); + st->stab_fac_fx = lsf_stab_fx( &lsf_fx[( k + 1 ) * M], &lsf_fx[k * M], 0, st->L_frame ); /* Q15 */ move16(); } - E_LPC_f_lsp_a_conversion( &lsp_fx[imult1616( add( k, 1 ), M )], Aq_fx, M ); + E_LPC_f_lsp_a_conversion( &lsp_fx[( k + 1 ) * M], Aq_fx, M ); { IGFDecRestoreTCX10SubFrameData_fx( st->hIGFDec, k ); } /* TCX decoder */ - decoder_tcx_ivas_fx( st, prm, Aq_fx, Aind, &synth_fx[imult1616( k, shr( st->L_frame, 1 ) )], &synthFB_fx[imult1616( k, shr( hTcxDec->L_frameTCX, 1 ) )], bfi, k, sba_dirac_stereo_flag ); + decoder_tcx_ivas_fx( st, prm, Aq_fx, Aind, &synth_fx[k * st->L_frame / 2], &synthFB_fx[k * ( hTcxDec->L_frameTCX / 2 )], bfi, k, sba_dirac_stereo_flag ); } } @@ -743,7 +743,7 @@ void stereo_tcx_core_dec_fx( IF( st->narrowBand || EQ_32( st->sr_core, INT_FS_12k8 ) || EQ_32( st->sr_core, INT_FS_16k ) ) { int_lsp_fx( st->L_frame, st->lspold_uw, lspnew_uw_fx, Aq_fx, M, interpol_frac_fx, 0 ); - Copy( Aq_fx, st->mem_Aq, i_mult( st->nb_subfr, ( M + 1 ) ) ); + Copy( Aq_fx, st->mem_Aq, i_mult( st->nb_subfr, ( M + 1 ) ) ); /* Q12 */ } } } @@ -764,9 +764,9 @@ void stereo_tcx_core_dec_fx( set16_fx( pitch_C, shl( round_fx( st->old_fpitch ), Q6 ), 4 ); /* note: codec_mode is forced to MODE2, since FEC_clas_estim() considers only TCX being in Mode2*/ - Word16 prev_codec_mode = st->codec_mode; + Word16 prev_codec_mode = st->codec_mode; /* Q0 */ move16(); - st->codec_mode = MODE2; + st->codec_mode = MODE2; /* Q0 */ move16(); IF( st->tcxonly ) { @@ -784,7 +784,7 @@ void stereo_tcx_core_dec_fx( FEC_clas_estim_fx( st, 0, st->L_frame, &st->clas_dec, st->core_ext_mode, pitch_C, synth_fx, &st->lp_ener_FER_fx, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, st->mem_syn_clas_estim_fx, &st->classifier_Q_mem_syn, hTcxLtpDec->tcxltp ? hTcxDec->tcxltp_last_gain_unmodified : MIN_16, CLASSIFIER_TCX, bfi, st->last_core_brate, -1 ); #endif } - st->codec_mode = prev_codec_mode; + st->codec_mode = prev_codec_mode; /* Q0 */ move16(); } } @@ -818,23 +818,23 @@ void stereo_tcx_core_dec_fx( } /* Update past buffers */ - Copy_Scale_sig( synth_buf_fx + st->L_frame, hTcxDec->old_synth, hTcxDec->old_synth_len, 0 ); - Copy( hTcxDec->old_synthFB_fx + sub( hTcxDec->L_frameTCX, NS2SA_FX2( st->output_Fs, PH_ECU_MEM_NS ) ), hTcxDec->synth_history_fx, NS2SA_FX2( st->output_Fs, PH_ECU_MEM_NS ) ); - Copy( synth_bufFB_fx + hTcxDec->L_frameTCX, hTcxDec->old_synthFB_fx, hTcxDec->old_synth_lenFB ); - Copy( st->hHQ_core->old_out_fx + NS2SA_FX2( st->output_Fs, N_ZERO_MDCT_NS ), hTcxDec->old_synthFB_fx + hTcxDec->old_synth_lenFB, NS2SA_FX2( st->output_Fs, PH_ECU_LOOKAHEAD_NS ) ); + Copy_Scale_sig( synth_buf_fx + st->L_frame, hTcxDec->old_synth, hTcxDec->old_synth_len, 0 ); /* q_old_synth - st->Q_syn */ + Copy( hTcxDec->old_synthFB_fx + sub( hTcxDec->L_frameTCX, NS2SA_FX2( st->output_Fs, PH_ECU_MEM_NS ) ), hTcxDec->synth_history_fx, NS2SA_FX2( st->output_Fs, PH_ECU_MEM_NS ) ); /* q_old_synthFB */ + Copy( synth_bufFB_fx + hTcxDec->L_frameTCX, hTcxDec->old_synthFB_fx, hTcxDec->old_synth_lenFB ); /* q_old_synthFB */ + Copy( st->hHQ_core->old_out_fx + NS2SA_FX2( st->output_Fs, N_ZERO_MDCT_NS ), hTcxDec->old_synthFB_fx + hTcxDec->old_synth_lenFB, NS2SA_FX2( st->output_Fs, PH_ECU_LOOKAHEAD_NS ) ); /* exp(exp_old_out) */ Copy( &lspnew_uw_fx[imult1616( sub( st->numlpc, 1 ), M )], st->lspold_uw, M ); Copy( &lsfnew_uw_fx[imult1616( sub( st->numlpc, 1 ), M )], st->lsfold_uw, M ); IF( EQ_16( bfi, 1 ) ) { - Copy( st->lspold_uw, st->lsp_old_fx, M ); /* for recovery */ - Copy( st->lsfold_uw, st->lsf_old_fx, M ); /* for recovery */ + Copy( st->lspold_uw, st->lsp_old_fx, M ); /* for recovery Q15*/ + Copy( st->lsfold_uw, st->lsf_old_fx, M ); /* for recovery Q15*/ } ELSE { - Copy( &lsp_fx[i_mult( st->numlpc, M )], st->lsp_old_fx, M ); - Copy( &lsf_fx[i_mult( st->numlpc, M )], st->lsf_old_fx, M ); + Copy( &lsp_fx[( st->numlpc ) * M], st->lsp_old_fx, M ); /* Q15 */ + Copy( &lsf_fx[( st->numlpc ) * M], st->lsf_old_fx, M ); /* Q2.56 */ } Copy( st->lsp_q_cng, st->old_lsp_q_cng, M ); Copy( st->lsf_q_cng, st->old_lsf_q_cng, M ); @@ -851,7 +851,7 @@ void stereo_tcx_core_dec_fx( Word16 buf[L_LP], res[L_FRAME], A[M + 1], r_h[M + 1], r_l[M + 1], tmp, lsptmp[M], q_r; assert( EQ_16( st->L_frame, L_FRAME ) ); - Copy( synth_fx + L_FRAME - L_LP, buf, L_LP ); + Copy( synth_fx + L_FRAME - L_LP, buf, L_LP ); /* q_old_synth - st->Q_syn */ tmp = synth_fx[L_FRAME - L_LP - 1]; move16(); E_UTIL_f_preemph2( 0, buf, st->preemph_fac, L_LP, &tmp ); @@ -879,7 +879,7 @@ void stereo_tcx_core_dec_fx( } ELSE { - st->hTdCngDec->ho_16k_lsp[st->hTdCngDec->ho_circ_ptr] = 1; + st->hTdCngDec->ho_16k_lsp[st->hTdCngDec->ho_circ_ptr] = 1; /* Q0 */ move16(); } } @@ -904,11 +904,11 @@ void stereo_tcx_core_dec_fx( IF( st->p_bpf_noise_buf_32 ) #endif // MSAN_FIX { - Copy_Scale_sig_16_32_no_sat( st->p_bpf_noise_buf, st->p_bpf_noise_buf_32, st->L_frame, Q11 ); + Copy_Scale_sig_16_32_no_sat( st->p_bpf_noise_buf, st->p_bpf_noise_buf_32, st->L_frame, Q11 ); /* q_p_bpf + Q11 */ } IF( signal_outFB_fx ) { - Copy( synthFB_fx, signal_outFB_fx, hTcxDec->L_frameTCX ); + Copy( synthFB_fx, signal_outFB_fx, hTcxDec->L_frameTCX ); /* q_old_synthFB */ } IF( !bfi ) @@ -941,7 +941,7 @@ void stereo_tcx_core_dec_fx( /* updates */ st->last_voice_factor_fx = 0; move16(); - st->last_coder_type = st->coder_type; + st->last_coder_type = st->coder_type; /* Q0 */ move16(); /* -------------------------------------------------------------- * @@ -956,9 +956,9 @@ void stereo_tcx_core_dec_fx( noisy_speech_detection_fx( st->hFdCngDec, st->VAD && EQ_16( st->m_frame_type, ACTIVE_FRAME ), signal_out_fx, 0 ); st->hFdCngDec->hFdCngCom->likelihood_noisy_speech_32fx = L_add( Mpy_32_32( Q31_0_99, st->hFdCngDec->hFdCngCom->likelihood_noisy_speech_32fx ), - imult3216( Q31_0_01, st->hFdCngDec->hFdCngCom->flag_noisy_speech ) ); - st->hFdCngDec->hFdCngCom->likelihood_noisy_speech = extract_h( st->hFdCngDec->hFdCngCom->likelihood_noisy_speech_32fx ); - st->lp_noise = st->hFdCngDec->lp_noise; + imult3216( Q31_0_01, st->hFdCngDec->hFdCngCom->flag_noisy_speech ) ); /* Q31 */ + st->hFdCngDec->hFdCngCom->likelihood_noisy_speech = extract_h( st->hFdCngDec->hFdCngCom->likelihood_noisy_speech_32fx ); /* Q15 */ + st->lp_noise = st->hFdCngDec->lp_noise; /* Q9.23 */ move32(); move32(); move16(); @@ -1765,9 +1765,9 @@ static void stereo_tcx_dec_mode_switch_reconf( #endif #ifdef IVAS_FLOAT_FIXED static void stereo_tcx_dec_mode_switch_reconf_ivas_fx( - Decoder_State *st, /* i/o: decoder state structure */ - const Word16 MCT_flag, /* i : hMCT handle allocated (1) or not (0)*/ - const Word16 last_element_mode, /* i : element mode of previous frame */ + Decoder_State *st, /* i/o: decoder state structure */ + const Word16 MCT_flag, /* i : hMCT handle allocated (1) or not (0) Q0*/ + const Word16 last_element_mode, /* i : element mode of previous frame Q0*/ Word16 *Q_syn_Overl_TDAC, Word16 *Q_fer_samples, Word16 *Q_syn_Overl, @@ -1779,7 +1779,7 @@ static void stereo_tcx_dec_mode_switch_reconf_ivas_fx( { Word16 frame_size_index; - st->rate_switching_init = 1; + st->rate_switching_init = 1; /* Q0 */ move16(); /* Identify frame type - TCX Reconfiguration */ @@ -1808,12 +1808,12 @@ static void stereo_tcx_dec_mode_switch_reconf_ivas_fx( return; } static void dec_prm_tcx_ivas_fx( - Decoder_State *st, /* i/o: decoder memory state */ - Word16 param[], /* o : decoded parameters */ - Word16 param_lpc[], /* o : LPC parameters */ - Word16 *total_nbbits, /* i/o: number of bits / decoded bits */ - const Word16 last_element_mode, /* i : last element mode */ - Word16 *bitsRead /* o : number of read bits */ + Decoder_State *st, /* i/o: decoder memory state */ + Word16 param[], /* o : decoded parameters Q0*/ + Word16 param_lpc[], /* o : LPC parameters Q0*/ + Word16 *total_nbbits, /* i/o: number of bits / decoded bits Q0*/ + const Word16 last_element_mode, /* i : last element mode Q0*/ + Word16 *bitsRead /* o : number of read bits Q0*/ ) { Word16 start_bit_pos, bits_common; @@ -1830,14 +1830,14 @@ static void dec_prm_tcx_ivas_fx( IF( NE_16( st->element_mode, IVAS_CPE_MDCT ) ) { // The value of 1/ FRAMES_PER_SEC shifted left by 19 because taking Q as 15 led to precision loss - st->bits_frame_core = extract_l( L_sub( L_shr( Mpy_32_16_1( st->total_brate, 10486 ), 4 ), st->next_bit_pos ) ); + st->bits_frame_core = extract_l( L_sub( L_shr( Mpy_32_16_1( st->total_brate, 10486 ), 4 ), st->next_bit_pos ) ); /* Q0 */ move16(); } - start_bit_pos = st->next_bit_pos; + start_bit_pos = st->next_bit_pos; /* Q0 */ move16(); /* Init LTP data */ - st->hTcxDec->tcx_hm_LtpPitchLag = -1; + st->hTcxDec->tcx_hm_LtpPitchLag = -1; /* Q0 */ move16(); st->hTcxLtpDec->tcxltp_gain = 0; move16(); @@ -1853,7 +1853,7 @@ static void dec_prm_tcx_ivas_fx( test(); IF( !st->use_partial_copy && NE_16( st->element_mode, IVAS_CPE_MDCT ) ) { - st->last_core_from_bs = get_next_indice_fx( st, 1 ); /* Store decoder memory of last_core */ + st->last_core_from_bs = get_next_indice_fx( st, 1 ); /* Store decoder memory of last_core Q0*/ move16(); test(); @@ -1862,7 +1862,7 @@ static void dec_prm_tcx_ivas_fx( /* A mismatch between the memory and the last_core from the bitstream indicates a frame was lost. If prev_bfi is not set the frame loss occured during CNG and the prev_bfi needs to be set. */ - st->prev_bfi = 1; + st->prev_bfi = 1; /* Q0 */ move16(); } @@ -1885,13 +1885,13 @@ static void dec_prm_tcx_ivas_fx( &st->hHQ_core->Q_old_wtda_LB, &Q_old_Aq_12_8 ); } - st->last_core = st->last_core_from_bs; + st->last_core = st->last_core_from_bs; /* Q0 */ move16(); /*for TCX 10 force last_core to be TCX since ACELP as previous core is forbidden*/ if ( EQ_16( st->core, TCX_10_CORE ) ) { - st->last_core = TCX_20_CORE; + st->last_core = TCX_20_CORE; /* Q0 */ move16(); } } @@ -1937,11 +1937,11 @@ static void dec_prm_tcx_ivas_fx( { st->BER_detect = 1; move16(); - st->next_bit_pos = add( start_bit_pos, sub( *total_nbbits, bitsRead[0] ) ); + st->next_bit_pos = add( start_bit_pos, sub( *total_nbbits, bitsRead[0] ) ); /* Q0 */ move16(); } - bitsRead[0] = sub( st->next_bit_pos, start_bit_pos ); + bitsRead[0] = sub( st->next_bit_pos, start_bit_pos ); /* Q0 */ move16(); } diff --git a/lib_dec/ivas_td_low_rate_dec.c b/lib_dec/ivas_td_low_rate_dec.c index 132a7d743..03f85a5d6 100644 --- a/lib_dec/ivas_td_low_rate_dec.c +++ b/lib_dec/ivas_td_low_rate_dec.c @@ -219,14 +219,14 @@ void tdm_low_rate_dec( #endif #ifdef IVAS_FLOAT_FIXED void tdm_low_rate_dec_fx( - Decoder_State *st, /* i/o: decoder static memory */ - Word16 dct_epit[], /* o : GSC excitation in DCT domain Q_exc */ - Word16 *pitch_buf, /* o : Word16 pitch values for each subframe Q6 */ - Word16 *voice_factors, /* o : voicing factors Q15 */ - Word16 *exc, /* i/o: adapt. excitation exc Q_exc */ - Word16 *exc2, /* i/o: adapt. excitation/total exc Q_exc */ - Word16 *bwe_exc, /* o : excitation for SWB TBE Q_exc */ - const Word16 *lsf_new /* i : ISFs at the end of the frame Q8/100 (2.56x) */ + Decoder_State *st, /* i/o: decoder static memory */ + Word16 dct_epit[], /* o : GSC excitation in DCT domain Q_exc*/ + Word16 *pitch_buf, /* o : Word16 pitch values for each subframe Q6*/ + Word16 *voice_factors, /* o : voicing factors Q15*/ + Word16 *exc, /* i/o: adapt. excitation exc Q_exc*/ + Word16 *exc2, /* i/o: adapt. excitation/total exc Q_exc*/ + Word16 *bwe_exc, /* o : excitation for SWB TBE Q_exc*/ + const Word16 *lsf_new /* i : ISFs at the end of the frame Q8/100 (2.56x)*/ ) { Word16 tmp_nb_bits_tot, pit_band_idx; @@ -249,11 +249,11 @@ void tdm_low_rate_dec_fx( move16(); st->GSC_noisy_speech = 1; move16(); - hGSCDec->noise_lev = 14; + hGSCDec->noise_lev = 14; /* Q0 */ move16(); - pit_band_idx = 10 + BAND1k2; - hGSCDec->Last_GSC_pit_band_idx = pit_band_idx; + pit_band_idx = 10 + BAND1k2; /* Q0 */ + hGSCDec->Last_GSC_pit_band_idx = pit_band_idx; /* Q0 */ move16(); move16(); @@ -265,9 +265,9 @@ void tdm_low_rate_dec_fx( st->bpf_off = 1; move16(); - st->bfi_pitch_fx = mean_fx( pitch_buf, 4 ); + st->bfi_pitch_fx = mean_fx( pitch_buf, 4 ); /* Q6 */ move16(); - st->bfi_pitch_frame = L_FRAME; + st->bfi_pitch_frame = L_FRAME; /* Q0 */ move16(); Diff_len = L_FRAME / 2; move16(); @@ -285,24 +285,24 @@ void tdm_low_rate_dec_fx( *--------------------------------------------------------------------------------------*/ /* find the current total number of bits used */ - tmp_nb_bits_tot = st->next_bit_pos; + tmp_nb_bits_tot = st->next_bit_pos; /* Q0 */ move16(); move16(); if ( EQ_16( st->element_mode, IVAS_CPE_TD ) ) { - tmp_nb_bits_tot = add( tmp_nb_bits_tot, TDM_SIGNAL_BITS_READ_FROM_THE_END_OF_BS ); + tmp_nb_bits_tot = add( tmp_nb_bits_tot, TDM_SIGNAL_BITS_READ_FROM_THE_END_OF_BS ); /* Q0 */ } if ( EQ_16( st->tdm_LRTD_flag, 1 ) ) { - tmp_nb_bits_tot = sub( tmp_nb_bits_tot, STEREO_BITS_TCA ); + tmp_nb_bits_tot = sub( tmp_nb_bits_tot, STEREO_BITS_TCA ); /* Q0 */ } if ( st->extl_brate_orig > 0 ) { /* subtract 1 bit for TBE/BWE BWE flag (bit counted in extl_brate) */ - tmp_nb_bits_tot = sub( tmp_nb_bits_tot, 1 ); + tmp_nb_bits_tot = sub( tmp_nb_bits_tot, 1 ); /* Q0 */ } gsc_dec_ivas_fx( st, dct_epit, pit_band_idx, Diff_len, tmp_nb_bits_tot, nb_subfr, st->coder_type, &last_bin, lsf_new, exc_wo_nf_fx, &st->Q_exc ); @@ -348,8 +348,8 @@ void tdm_low_rate_dec_fx( * Updates *--------------------------------------------------------------------------------------*/ - Copy( exc, exc2, L_FRAME ); - Copy( exc_wo_nf_fx, exc, L_FRAME ); + Copy( exc, exc2, L_FRAME ); /* Q_exc */ + Copy( exc_wo_nf_fx, exc, L_FRAME ); /* Q_exc */ /*--------------------------------------------------------------------------------------* * Channel aware mode parameters @@ -507,16 +507,16 @@ void decod_gen_2sbfr( void decod_gen_2sbfr_ivas_fx( Decoder_State *st, /* i/o: decoder static memory */ - const Word16 sharpFlag, /* i : formant sharpening flag */ - const Word16 *Aq, /* i : LP filter coefficient Q12 */ - Word16 *pitch_buf, /* o : Word16 pitch values for each subframe Q6 */ - Word16 *voice_factors, /* o : voicing factors Q15 */ - Word16 *exc, /* i/o: adapt. excitation exc Q_exc */ - Word16 *exc2, /* i/o: adapt. excitation/total exc Q_exc */ - Word16 *bwe_exc, /* o : excitation for SWB TBE Q_exc */ - Word16 *gain_buf, /* o : Word16 pitch gain for each subframe Q14 */ - const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag */ - const Word16 tdm_Pri_pitch_buf[] /* i : pitch values for primary channel Q6 */ + const Word16 sharpFlag, /* i : formant sharpening flag `Q0*/ + const Word16 *Aq, /* i : LP filter coefficient Q12*/ + Word16 *pitch_buf, /* o : Word16 pitch values for each subframe Q6*/ + Word16 *voice_factors, /* o : voicing factors Q15*/ + Word16 *exc, /* i/o: adapt. excitation exc Q_exc*/ + Word16 *exc2, /* i/o: adapt. excitation/total exc Q_exc*/ + Word16 *bwe_exc, /* o : excitation for SWB TBE Q_exc*/ + Word16 *gain_buf, /* o : Word16 pitch gain for each subframe Q14*/ + const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag Q0*/ + const Word16 tdm_Pri_pitch_buf[] /* i : pitch values for primary channel Q6*/ ) { Word16 T0, T0_frac, T0_min, T0_max; /* integer pitch variables */ @@ -560,8 +560,8 @@ void decod_gen_2sbfr_ivas_fx( * ACELP subframe loop *------------------------------------------------------------------*/ - p_Aq = Aq; /* pointer to interpolated LPC parameters */ - pt_pitch = pitch_buf; /* pointer to the pitch buffer */ + p_Aq = Aq; /* pointer to interpolated LPC parameters Q12*/ + pt_pitch = pitch_buf; /* pointer to the pitch buffer Q6*/ FOR( i_subfr = 0; i_subfr < L_frame; i_subfr += 2 * L_SUBFR ) { @@ -569,7 +569,7 @@ void decod_gen_2sbfr_ivas_fx( * Decode pitch lag *----------------------------------------------------------------------*/ - *pt_pitch = pit_decode_ivas_fx( st, st->core_brate, 0, L_frame, i_subfr, GENERIC, &pitch_limit_flag, &T0, &T0_frac, &T0_min, &T0_max, 2 * L_SUBFR, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf ); + *pt_pitch = pit_decode_ivas_fx( st, st->core_brate, 0, L_frame, i_subfr, GENERIC, &pitch_limit_flag, &T0, &T0_frac, &T0_min, &T0_max, 2 * L_SUBFR, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf ); /* Q6 */ test(); test(); @@ -602,19 +602,19 @@ void decod_gen_2sbfr_ivas_fx( *--------------------------------------------------------------*/ gain_dec_lbr_ivas_fx( st, GENERIC, i_subfr, code, &gain_pit, &gain_code, &gain_inov, &norm_gain_code, gc_mem, gp_mem, 2 * L_SUBFR ); - st->tilt_code_fx = est_tilt_ivas_fx( exc + i_subfr, gain_pit, code, gain_code, &voice_fac, st->Q_exc, 2 * L_SUBFR, 0 ); + st->tilt_code_fx = est_tilt_ivas_fx( exc + i_subfr, gain_pit, code, gain_code, &voice_fac, st->Q_exc, 2 * L_SUBFR, 0 ); /* Q15 */ move16(); /* update LP filtered gains for the case of frame erasures */ lp_gain_updt_ivas_fx( i_subfr, gain_pit, norm_gain_code, &st->lp_gainp_fx, &st->lp_gainc_fx, L_frame ); - lp_gain_updt_ivas_fx( i_subfr + L_SUBFR, gain_pit, norm_gain_code, &st->lp_gainp_fx, &st->lp_gainc_fx, L_frame ); + lp_gain_updt_ivas_fx( add( i_subfr, L_SUBFR ), gain_pit, norm_gain_code, &st->lp_gainp_fx, &st->lp_gainc_fx, L_frame ); /*----------------------------------------------------------------------* * Find the total excitation *----------------------------------------------------------------------*/ #ifdef FIX_734_MISSING_SUBFR_LOW_RATE_ACELP /* Don't need the if/else as here L_frame==L_FRAME all the time */ - Rescale_exc( st->hMusicPF->dct_post_old_exc_fx, &exc[i_subfr], ( bwe_exc != NULL ) ? &bwe_exc[imult1616( i_subfr, HIBND_ACB_L_FAC )] : NULL, st->hGSCDec->last_exc_dct_in_fx, + Rescale_exc( st->hMusicPF->dct_post_old_exc_fx, &exc[i_subfr], ( bwe_exc != NULL ) ? &bwe_exc[i_subfr * HIBND_ACB_L_FAC] : NULL, st->hGSCDec->last_exc_dct_in_fx, 2 * L_SUBFR, 2 * L_SUBFR * HIBND_ACB_L_FAC, gain_code, &( st->Q_exc ), st->Q_subfr, exc2, i_subfr, st->coder_type ); #else @@ -646,7 +646,7 @@ void decod_gen_2sbfr_ivas_fx( // prep_tbe_exc_fx(L_frame, /*L_SUBFR,*/ i_subfr, gain_pit, gain_code, code, voice_fac, &voice_factors[i_subfr / L_SUBFR], bwe_exc, 0, NULL, Q_exc, T0, T0_frac, GENERIC, st->core_brate/*, st->element_mode, st->idchan, st->hBWE_TD != NULL, st->tdm_LRTD_flag*/); prep_tbe_exc_ivas_fx( L_frame, L_SUBFR, i_subfr, gain_pit, gain_code, code, voice_fac, &voice_factors[i_subfr / L_SUBFR], bwe_exc, 0, NULL, st->Q_exc, T0, T0_frac, GENERIC, st->core_brate, st->element_mode, st->idchan, st->hBWE_TD != NULL, st->tdm_LRTD_flag ); #endif - voice_factors[add( shr( i_subfr, 6 ) /*i_subfr / L_SUBFR*/, 1 )] = voice_factors[i_subfr / L_SUBFR /*i_subfr / L_SUBFR*/]; + voice_factors[i_subfr / L_SUBFR + 1] = voice_factors[i_subfr / L_SUBFR /*i_subfr / L_SUBFR*/]; /* Q15 */ move16(); /*----------------------------------------------------------------* @@ -666,25 +666,25 @@ void decod_gen_2sbfr_ivas_fx( // enhancer_fx(MODE1, st->core_brate, -1, 0, GENERIC, L_frame, voice_fac, st->stab_fac, norm_gain_code, gain_inov, &st->gc_threshold, code + L_SUBFR, exc2 + i_subfr + L_SUBFR, gain_pit, st->dispMem); enhancer_fx( st->core_brate, 0, GENERIC, i_subfr, L_frame, voice_fac, st->stab_fac_fx, norm_gain_code, gain_inov, &st->gc_threshold_fx, code + L_SUBFR, exc2 + L_SUBFR, gain_pit, &st->dm_fx, st->Q_exc ); #endif - p_Aq += 2 * ( M + 1 ); + p_Aq += 2 * ( M + 1 ); /* Q12 */ pt_pitch++; - *pt_pitch = *( pt_pitch - 1 ); + *pt_pitch = *( pt_pitch - 1 ); /* Q6 */ move16(); pt_pitch++; - gain_buf[i_subfr / L_SUBFR /*i_subfr / L_SUBFR*/] = gain_pit; + gain_buf[i_subfr / L_SUBFR /*i_subfr / L_SUBFR*/] = gain_pit; /* Q14 */ move16(); - gain_buf[shr( add( i_subfr, L_SUBFR ), 6 ) /*(i_subfr+L_SUBFR) / L_SUBFR*/] = gain_pit; + gain_buf[( i_subfr + L_SUBFR ) / L_SUBFR /*(i_subfr+L_SUBFR) / L_SUBFR*/] = gain_pit; /* Q14 */ move16(); - st->tilt_code_dec_fx[i_subfr / L_SUBFR /*i_subfr / L_SUBFR*/] = st->tilt_code_fx; + st->tilt_code_dec_fx[i_subfr / L_SUBFR /*i_subfr / L_SUBFR*/] = st->tilt_code_fx; /* Q15 */ move16(); - st->tilt_code_dec_fx[shr( add( i_subfr, L_SUBFR ), 6 ) /*( i_subfr + L_SUBFR ) / L_SUBFR*/] = st->tilt_code_fx; + st->tilt_code_dec_fx[( i_subfr + L_SUBFR ) / L_SUBFR /*( i_subfr + L_SUBFR ) / L_SUBFR*/] = st->tilt_code_fx; /* Q15 */ move16(); } /* SC-VBR */ - st->prev_gain_pit_dec_fx = gain_pit; + st->prev_gain_pit_dec_fx = gain_pit; /* Q14 */ move16(); return; diff --git a/lib_rend/ivas_crend.c b/lib_rend/ivas_crend.c index 255ad1b24..78ebf384d 100644 --- a/lib_rend/ivas_crend.c +++ b/lib_rend/ivas_crend.c @@ -306,22 +306,22 @@ static ivas_error ivas_rend_initCrend_fx( { hHrtf->max_num_ir = sub( hHrtf->max_num_ir, 1 ); /* subtract LFE */ move16(); - hHrtf->gain_lfe_fx = GAIN_LFE_FX; + hHrtf->gain_lfe_fx = GAIN_LFE_FX; // Q14 move16(); IF( EQ_32( output_Fs, 48000 ) ) { IF( EQ_16( outConfig, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR ) ) { - hHrtf->latency_s_fx = CRendBin_Combined_BRIR_latency_s_fx; - hHrtf->max_num_iterations = CRendBin_Combined_BRIR_max_num_iterations_48kHz; - hHrtf->index_frequency_max_diffuse = CRendBin_Combined_BRIR_index_frequency_max_diffuse_48kHz; + hHrtf->latency_s_fx = CRendBin_Combined_BRIR_latency_s_fx; // Q31 + hHrtf->max_num_iterations = CRendBin_Combined_BRIR_max_num_iterations_48kHz; // Q0 + hHrtf->index_frequency_max_diffuse = CRendBin_Combined_BRIR_index_frequency_max_diffuse_48kHz; // Q0 } ELSE { - hHrtf->latency_s_fx = CRendBin_Combined_HRIR_latency_s_fx; - hHrtf->max_num_iterations = CRendBin_Combined_HRIR_max_num_iterations_48kHz; - hHrtf->index_frequency_max_diffuse = CRendBin_Combined_HRIR_index_frequency_max_diffuse_48kHz; + hHrtf->latency_s_fx = CRendBin_Combined_HRIR_latency_s_fx; // Q31 + hHrtf->max_num_iterations = CRendBin_Combined_HRIR_max_num_iterations_48kHz; // Q0 + hHrtf->index_frequency_max_diffuse = CRendBin_Combined_HRIR_index_frequency_max_diffuse_48kHz; // Q0 } move32(); move16(); @@ -331,19 +331,19 @@ static ivas_error ivas_rend_initCrend_fx( { IF( EQ_16( outConfig, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR ) ) { - hHrtf->num_iterations_diffuse[j] = CRendBin_Combined_BRIR_num_iterations_diffuse_48kHz[j]; - hHrtf->pIndex_frequency_max_diffuse[j] = CRendBin_Combined_BRIR_pIndex_frequency_max_diffuse_48kHz[j]; + hHrtf->num_iterations_diffuse[j] = CRendBin_Combined_BRIR_num_iterations_diffuse_48kHz[j]; // Q0 + hHrtf->pIndex_frequency_max_diffuse[j] = CRendBin_Combined_BRIR_pIndex_frequency_max_diffuse_48kHz[j]; // Q0 - hHrtf->pOut_to_bin_diffuse_re_fx[j] = CRendBin_Combined_BRIR_coeff_diffuse_re_48kHz_fx[j]; - hHrtf->pOut_to_bin_diffuse_im_fx[j] = CRendBin_Combined_BRIR_coeff_diffuse_im_48kHz_fx[j]; + hHrtf->pOut_to_bin_diffuse_re_fx[j] = CRendBin_Combined_BRIR_coeff_diffuse_re_48kHz_fx[j]; // Q31 + hHrtf->pOut_to_bin_diffuse_im_fx[j] = CRendBin_Combined_BRIR_coeff_diffuse_im_48kHz_fx[j]; // Q31 } ELSE { - hHrtf->num_iterations_diffuse[j] = CRendBin_Combined_HRIR_num_iterations_diffuse_48kHz[j]; - hHrtf->pIndex_frequency_max_diffuse[j] = CRendBin_Combined_HRIR_pIndex_frequency_max_diffuse_48kHz[j]; + hHrtf->num_iterations_diffuse[j] = CRendBin_Combined_HRIR_num_iterations_diffuse_48kHz[j]; // Q0 + hHrtf->pIndex_frequency_max_diffuse[j] = CRendBin_Combined_HRIR_pIndex_frequency_max_diffuse_48kHz[j]; // Q0 - hHrtf->pOut_to_bin_diffuse_re_fx[j] = CRendBin_Combined_HRIR_coeff_diffuse_re_48kHz_fx[j]; - hHrtf->pOut_to_bin_diffuse_im_fx[j] = CRendBin_Combined_HRIR_coeff_diffuse_im_48kHz_fx[j]; + hHrtf->pOut_to_bin_diffuse_re_fx[j] = CRendBin_Combined_HRIR_coeff_diffuse_re_48kHz_fx[j]; // Q31 + hHrtf->pOut_to_bin_diffuse_im_fx[j] = CRendBin_Combined_HRIR_coeff_diffuse_im_48kHz_fx[j]; // Q31 } move32(); move32(); @@ -355,15 +355,15 @@ static ivas_error ivas_rend_initCrend_fx( { IF( EQ_16( outConfig, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR ) ) { - hHrtf->latency_s_fx = CRendBin_Combined_BRIR_latency_s_fx; - hHrtf->max_num_iterations = CRendBin_Combined_BRIR_max_num_iterations_32kHz; - hHrtf->index_frequency_max_diffuse = CRendBin_Combined_BRIR_index_frequency_max_diffuse_32kHz; + hHrtf->latency_s_fx = CRendBin_Combined_BRIR_latency_s_fx; // Q31 + hHrtf->max_num_iterations = CRendBin_Combined_BRIR_max_num_iterations_32kHz; // Q0 + hHrtf->index_frequency_max_diffuse = CRendBin_Combined_BRIR_index_frequency_max_diffuse_32kHz; // Q0 } ELSE { - hHrtf->latency_s_fx = CRendBin_Combined_HRIR_latency_s_fx; - hHrtf->max_num_iterations = CRendBin_Combined_HRIR_max_num_iterations_32kHz; - hHrtf->index_frequency_max_diffuse = CRendBin_Combined_HRIR_index_frequency_max_diffuse_32kHz; + hHrtf->latency_s_fx = CRendBin_Combined_HRIR_latency_s_fx; // Q31 + hHrtf->max_num_iterations = CRendBin_Combined_HRIR_max_num_iterations_32kHz; // Q0 + hHrtf->index_frequency_max_diffuse = CRendBin_Combined_HRIR_index_frequency_max_diffuse_32kHz; // Q0 } move32(); move16(); @@ -373,19 +373,19 @@ static ivas_error ivas_rend_initCrend_fx( { IF( EQ_16( outConfig, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR ) ) { - hHrtf->num_iterations_diffuse[j] = CRendBin_Combined_BRIR_num_iterations_diffuse_32kHz[j]; - hHrtf->pIndex_frequency_max_diffuse[j] = CRendBin_Combined_BRIR_pIndex_frequency_max_diffuse_32kHz[j]; + hHrtf->num_iterations_diffuse[j] = CRendBin_Combined_BRIR_num_iterations_diffuse_32kHz[j]; // Q0 + hHrtf->pIndex_frequency_max_diffuse[j] = CRendBin_Combined_BRIR_pIndex_frequency_max_diffuse_32kHz[j]; // Q0 - hHrtf->pOut_to_bin_diffuse_re_fx[j] = CRendBin_Combined_BRIR_coeff_diffuse_re_32kHz_fx[j]; - hHrtf->pOut_to_bin_diffuse_im_fx[j] = CRendBin_Combined_BRIR_coeff_diffuse_im_32kHz_fx[j]; + hHrtf->pOut_to_bin_diffuse_re_fx[j] = CRendBin_Combined_BRIR_coeff_diffuse_re_32kHz_fx[j]; // Q31 + hHrtf->pOut_to_bin_diffuse_im_fx[j] = CRendBin_Combined_BRIR_coeff_diffuse_im_32kHz_fx[j]; // Q31 } ELSE { - hHrtf->num_iterations_diffuse[j] = CRendBin_Combined_HRIR_num_iterations_diffuse_32kHz[j]; - hHrtf->pIndex_frequency_max_diffuse[j] = CRendBin_Combined_HRIR_pIndex_frequency_max_diffuse_32kHz[j]; + hHrtf->num_iterations_diffuse[j] = CRendBin_Combined_HRIR_num_iterations_diffuse_32kHz[j]; // Q0 + hHrtf->pIndex_frequency_max_diffuse[j] = CRendBin_Combined_HRIR_pIndex_frequency_max_diffuse_32kHz[j]; // Q0 - hHrtf->pOut_to_bin_diffuse_re_fx[j] = CRendBin_Combined_HRIR_coeff_diffuse_re_32kHz_fx[j]; - hHrtf->pOut_to_bin_diffuse_im_fx[j] = CRendBin_Combined_HRIR_coeff_diffuse_im_32kHz_fx[j]; + hHrtf->pOut_to_bin_diffuse_re_fx[j] = CRendBin_Combined_HRIR_coeff_diffuse_re_32kHz_fx[j]; // Q31 + hHrtf->pOut_to_bin_diffuse_im_fx[j] = CRendBin_Combined_HRIR_coeff_diffuse_im_32kHz_fx[j]; // Q31 } move32(); move32(); @@ -397,13 +397,13 @@ static ivas_error ivas_rend_initCrend_fx( { IF( EQ_16( outConfig, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR ) ) { - hHrtf->latency_s_fx = CRendBin_Combined_BRIR_latency_s_fx; + hHrtf->latency_s_fx = CRendBin_Combined_BRIR_latency_s_fx; // Q31 hHrtf->max_num_iterations = CRendBin_Combined_BRIR_max_num_iterations_16kHz; hHrtf->index_frequency_max_diffuse = CRendBin_Combined_BRIR_index_frequency_max_diffuse_16kHz; } ELSE { - hHrtf->latency_s_fx = CRendBin_Combined_HRIR_latency_s_fx; + hHrtf->latency_s_fx = CRendBin_Combined_HRIR_latency_s_fx; // Q31 hHrtf->max_num_iterations = CRendBin_Combined_HRIR_max_num_iterations_16kHz; hHrtf->index_frequency_max_diffuse = CRendBin_Combined_HRIR_index_frequency_max_diffuse_16kHz; } @@ -418,16 +418,16 @@ static ivas_error ivas_rend_initCrend_fx( hHrtf->num_iterations_diffuse[j] = CRendBin_Combined_BRIR_num_iterations_diffuse_16kHz[j]; hHrtf->pIndex_frequency_max_diffuse[j] = CRendBin_Combined_BRIR_pIndex_frequency_max_diffuse_16kHz[j]; - hHrtf->pOut_to_bin_diffuse_re_fx[j] = CRendBin_Combined_BRIR_coeff_diffuse_re_16kHz_fx[j]; - hHrtf->pOut_to_bin_diffuse_im_fx[j] = CRendBin_Combined_BRIR_coeff_diffuse_im_16kHz_fx[j]; + hHrtf->pOut_to_bin_diffuse_re_fx[j] = CRendBin_Combined_BRIR_coeff_diffuse_re_16kHz_fx[j]; // Q31 + hHrtf->pOut_to_bin_diffuse_im_fx[j] = CRendBin_Combined_BRIR_coeff_diffuse_im_16kHz_fx[j]; // Q31 } ELSE { hHrtf->num_iterations_diffuse[j] = CRendBin_Combined_HRIR_num_iterations_diffuse_16kHz[j]; hHrtf->pIndex_frequency_max_diffuse[j] = CRendBin_Combined_HRIR_pIndex_frequency_max_diffuse_16kHz[j]; - hHrtf->pOut_to_bin_diffuse_re_fx[j] = CRendBin_Combined_HRIR_coeff_diffuse_re_16kHz_fx[j]; - hHrtf->pOut_to_bin_diffuse_im_fx[j] = CRendBin_Combined_HRIR_coeff_diffuse_im_16kHz_fx[j]; + hHrtf->pOut_to_bin_diffuse_re_fx[j] = CRendBin_Combined_HRIR_coeff_diffuse_re_16kHz_fx[j]; // Q31 + hHrtf->pOut_to_bin_diffuse_im_fx[j] = CRendBin_Combined_HRIR_coeff_diffuse_im_16kHz_fx[j]; // Q31 } move32(); move32(); @@ -472,11 +472,11 @@ static ivas_error ivas_rend_initCrend_fx( { IF( EQ_16( outConfig, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR ) ) { - hHrtf->inv_diffuse_weight_fx[i] = CRendBin_Combined_BRIR_inv_diffuse_weight_48kHz_fx[tmp]; + hHrtf->inv_diffuse_weight_fx[i] = CRendBin_Combined_BRIR_inv_diffuse_weight_48kHz_fx[tmp]; // Q15 } ELSE { - hHrtf->inv_diffuse_weight_fx[i] = CRendBin_Combined_HRIR_inv_diffuse_weight_48kHz_fx[tmp]; + hHrtf->inv_diffuse_weight_fx[i] = CRendBin_Combined_HRIR_inv_diffuse_weight_48kHz_fx[tmp]; // Q15 } move16(); @@ -487,16 +487,16 @@ static ivas_error ivas_rend_initCrend_fx( hHrtf->num_iterations[i][j] = CRendBin_Combined_BRIR_num_iterations_48kHz[tmp][j]; hHrtf->pIndex_frequency_max[i][j] = CRendBin_Combined_BRIR_pIndex_frequency_max_48kHz[tmp][j]; - hHrtf->pOut_to_bin_re_fx[i][j] = CRendBin_Combined_BRIR_coeff_re_48kHz_fx[tmp][j]; - hHrtf->pOut_to_bin_im_fx[i][j] = CRendBin_Combined_BRIR_coeff_im_48kHz_fx[tmp][j]; + hHrtf->pOut_to_bin_re_fx[i][j] = CRendBin_Combined_BRIR_coeff_re_48kHz_fx[tmp][j]; // Q29 + hHrtf->pOut_to_bin_im_fx[i][j] = CRendBin_Combined_BRIR_coeff_im_48kHz_fx[tmp][j]; // Q29 } ELSE { hHrtf->num_iterations[i][j] = CRendBin_Combined_HRIR_num_iterations_48kHz[tmp][j]; hHrtf->pIndex_frequency_max[i][j] = CRendBin_Combined_HRIR_pIndex_frequency_max_48kHz[tmp][j]; - hHrtf->pOut_to_bin_re_fx[i][j] = CRendBin_Combined_HRIR_coeff_re_48kHz_fx[tmp][j]; - hHrtf->pOut_to_bin_im_fx[i][j] = CRendBin_Combined_HRIR_coeff_im_48kHz_fx[tmp][j]; + hHrtf->pOut_to_bin_re_fx[i][j] = CRendBin_Combined_HRIR_coeff_re_48kHz_fx[tmp][j]; // Q29 + hHrtf->pOut_to_bin_im_fx[i][j] = CRendBin_Combined_HRIR_coeff_im_48kHz_fx[tmp][j]; // Q29 } move32(); move32(); @@ -508,11 +508,11 @@ static ivas_error ivas_rend_initCrend_fx( { IF( EQ_16( outConfig, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR ) ) { - hHrtf->inv_diffuse_weight_fx[i] = CRendBin_Combined_BRIR_inv_diffuse_weight_32kHz_fx[tmp]; + hHrtf->inv_diffuse_weight_fx[i] = CRendBin_Combined_BRIR_inv_diffuse_weight_32kHz_fx[tmp]; // Q15 } ELSE { - hHrtf->inv_diffuse_weight_fx[i] = CRendBin_Combined_HRIR_inv_diffuse_weight_32kHz_fx[tmp]; + hHrtf->inv_diffuse_weight_fx[i] = CRendBin_Combined_HRIR_inv_diffuse_weight_32kHz_fx[tmp]; // Q15 } move16(); @@ -523,16 +523,16 @@ static ivas_error ivas_rend_initCrend_fx( hHrtf->num_iterations[i][j] = CRendBin_Combined_BRIR_num_iterations_32kHz[tmp][j]; hHrtf->pIndex_frequency_max[i][j] = CRendBin_Combined_BRIR_pIndex_frequency_max_32kHz[tmp][j]; - hHrtf->pOut_to_bin_re_fx[i][j] = CRendBin_Combined_BRIR_coeff_re_32kHz_fx[tmp][j]; - hHrtf->pOut_to_bin_im_fx[i][j] = CRendBin_Combined_BRIR_coeff_im_32kHz_fx[tmp][j]; + hHrtf->pOut_to_bin_re_fx[i][j] = CRendBin_Combined_BRIR_coeff_re_32kHz_fx[tmp][j]; // Q29 + hHrtf->pOut_to_bin_im_fx[i][j] = CRendBin_Combined_BRIR_coeff_im_32kHz_fx[tmp][j]; // Q29 } ELSE { hHrtf->num_iterations[i][j] = CRendBin_Combined_HRIR_num_iterations_32kHz[tmp][j]; hHrtf->pIndex_frequency_max[i][j] = CRendBin_Combined_HRIR_pIndex_frequency_max_32kHz[tmp][j]; - hHrtf->pOut_to_bin_re_fx[i][j] = CRendBin_Combined_HRIR_coeff_re_32kHz_fx[tmp][j]; - hHrtf->pOut_to_bin_im_fx[i][j] = CRendBin_Combined_HRIR_coeff_im_32kHz_fx[tmp][j]; + hHrtf->pOut_to_bin_re_fx[i][j] = CRendBin_Combined_HRIR_coeff_re_32kHz_fx[tmp][j]; // Q29 + hHrtf->pOut_to_bin_im_fx[i][j] = CRendBin_Combined_HRIR_coeff_im_32kHz_fx[tmp][j]; // Q29 } move32(); move32(); @@ -544,11 +544,11 @@ static ivas_error ivas_rend_initCrend_fx( { IF( EQ_16( outConfig, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR ) ) { - hHrtf->inv_diffuse_weight_fx[i] = CRendBin_Combined_BRIR_inv_diffuse_weight_16kHz_fx[tmp]; + hHrtf->inv_diffuse_weight_fx[i] = CRendBin_Combined_BRIR_inv_diffuse_weight_16kHz_fx[tmp]; // Q15 } ELSE { - hHrtf->inv_diffuse_weight_fx[i] = CRendBin_Combined_HRIR_inv_diffuse_weight_16kHz_fx[tmp]; + hHrtf->inv_diffuse_weight_fx[i] = CRendBin_Combined_HRIR_inv_diffuse_weight_16kHz_fx[tmp]; // Q15 } move16(); @@ -559,16 +559,16 @@ static ivas_error ivas_rend_initCrend_fx( hHrtf->num_iterations[i][j] = CRendBin_Combined_BRIR_num_iterations_16kHz[tmp][j]; hHrtf->pIndex_frequency_max[i][j] = CRendBin_Combined_BRIR_pIndex_frequency_max_16kHz[tmp][j]; - hHrtf->pOut_to_bin_re_fx[i][j] = CRendBin_Combined_BRIR_coeff_re_16kHz_fx[tmp][j]; - hHrtf->pOut_to_bin_im_fx[i][j] = CRendBin_Combined_BRIR_coeff_im_16kHz_fx[tmp][j]; + hHrtf->pOut_to_bin_re_fx[i][j] = CRendBin_Combined_BRIR_coeff_re_16kHz_fx[tmp][j]; // Q29 + hHrtf->pOut_to_bin_im_fx[i][j] = CRendBin_Combined_BRIR_coeff_im_16kHz_fx[tmp][j]; // Q29 } ELSE { hHrtf->num_iterations[i][j] = CRendBin_Combined_HRIR_num_iterations_16kHz[tmp][j]; hHrtf->pIndex_frequency_max[i][j] = CRendBin_Combined_HRIR_pIndex_frequency_max_16kHz[tmp][j]; - hHrtf->pOut_to_bin_re_fx[i][j] = CRendBin_Combined_HRIR_coeff_re_16kHz_fx[tmp][j]; - hHrtf->pOut_to_bin_im_fx[i][j] = CRendBin_Combined_HRIR_coeff_im_16kHz_fx[tmp][j]; + hHrtf->pOut_to_bin_re_fx[i][j] = CRendBin_Combined_HRIR_coeff_re_16kHz_fx[tmp][j]; // Q29 + hHrtf->pOut_to_bin_im_fx[i][j] = CRendBin_Combined_HRIR_coeff_im_16kHz_fx[tmp][j]; // Q29 } move32(); move32(); @@ -588,7 +588,7 @@ static ivas_error ivas_rend_initCrend_fx( { IF( EQ_32( output_Fs, 48000 ) ) { - hHrtf->latency_s_fx = CRendBin_HOA3_HRIR_latency_s_fx; + hHrtf->latency_s_fx = CRendBin_HOA3_HRIR_latency_s_fx; // Q31 hHrtf->max_num_iterations = CRendBin_HOA3_HRIR_max_num_iterations_48kHz; hHrtf->index_frequency_max_diffuse = CRendBin_HOA3_HRIR_index_frequency_max_diffuse_48kHz; move32(); @@ -597,7 +597,7 @@ static ivas_error ivas_rend_initCrend_fx( FOR( i = 0; i < hHrtf->max_num_ir; i++ ) { - hHrtf->inv_diffuse_weight_fx[i] = CRendBin_HOA3_HRIR_inv_diffuse_weight_48kHz_fx[i]; + hHrtf->inv_diffuse_weight_fx[i] = CRendBin_HOA3_HRIR_inv_diffuse_weight_48kHz_fx[i]; // Q15 move16(); FOR( j = 0; j < BINAURAL_CHANNELS; j++ ) @@ -605,8 +605,8 @@ static ivas_error ivas_rend_initCrend_fx( hHrtf->num_iterations[i][j] = CRendBin_HOA3_HRIR_num_iterations_48kHz[i][j]; hHrtf->pIndex_frequency_max[i][j] = CRendBin_HOA3_HRIR_pIndex_frequency_max_48kHz[i][j]; - hHrtf->pOut_to_bin_re_fx[i][j] = CRendBin_HOA3_HRIR_coeff_re_48kHz_fx[i][j]; - hHrtf->pOut_to_bin_im_fx[i][j] = CRendBin_HOA3_HRIR_coeff_im_48kHz_fx[i][j]; + hHrtf->pOut_to_bin_re_fx[i][j] = CRendBin_HOA3_HRIR_coeff_re_48kHz_fx[i][j]; // Q29 + hHrtf->pOut_to_bin_im_fx[i][j] = CRendBin_HOA3_HRIR_coeff_im_48kHz_fx[i][j]; // Q29 move32(); move32(); move16(); @@ -618,8 +618,8 @@ static ivas_error ivas_rend_initCrend_fx( hHrtf->num_iterations_diffuse[j] = CRendBin_HOA3_HRIR_num_iterations_diffuse_48kHz[j]; hHrtf->pIndex_frequency_max_diffuse[j] = CRendBin_HOA3_HRIR_pIndex_frequency_max_diffuse_48kHz[j]; - hHrtf->pOut_to_bin_diffuse_re_fx[j] = CRendBin_HOA3_HRIR_coeff_diffuse_re_48kHz_fx[j]; - hHrtf->pOut_to_bin_diffuse_im_fx[j] = CRendBin_HOA3_HRIR_coeff_diffuse_im_48kHz_fx[j]; + hHrtf->pOut_to_bin_diffuse_re_fx[j] = CRendBin_HOA3_HRIR_coeff_diffuse_re_48kHz_fx[j]; // Q31 + hHrtf->pOut_to_bin_diffuse_im_fx[j] = CRendBin_HOA3_HRIR_coeff_diffuse_im_48kHz_fx[j]; // Q31 move32(); move32(); move16(); @@ -628,7 +628,7 @@ static ivas_error ivas_rend_initCrend_fx( } ELSE IF( EQ_32( output_Fs, 32000 ) ) { - hHrtf->latency_s_fx = CRendBin_HOA3_HRIR_latency_s_fx; + hHrtf->latency_s_fx = CRendBin_HOA3_HRIR_latency_s_fx; // Q31 hHrtf->max_num_iterations = CRendBin_HOA3_HRIR_max_num_iterations_32kHz; hHrtf->index_frequency_max_diffuse = CRendBin_HOA3_HRIR_index_frequency_max_diffuse_32kHz; move32(); @@ -637,7 +637,7 @@ static ivas_error ivas_rend_initCrend_fx( FOR( i = 0; i < hHrtf->max_num_ir; i++ ) { - hHrtf->inv_diffuse_weight_fx[i] = CRendBin_HOA3_HRIR_inv_diffuse_weight_32kHz_fx[i]; + hHrtf->inv_diffuse_weight_fx[i] = CRendBin_HOA3_HRIR_inv_diffuse_weight_32kHz_fx[i]; // Q15 move16(); FOR( j = 0; j < BINAURAL_CHANNELS; j++ ) @@ -645,8 +645,8 @@ static ivas_error ivas_rend_initCrend_fx( hHrtf->num_iterations[i][j] = CRendBin_HOA3_HRIR_num_iterations_32kHz[i][j]; hHrtf->pIndex_frequency_max[i][j] = CRendBin_HOA3_HRIR_pIndex_frequency_max_32kHz[i][j]; - hHrtf->pOut_to_bin_re_fx[i][j] = CRendBin_HOA3_HRIR_coeff_re_32kHz_fx[i][j]; - hHrtf->pOut_to_bin_im_fx[i][j] = CRendBin_HOA3_HRIR_coeff_im_32kHz_fx[i][j]; + hHrtf->pOut_to_bin_re_fx[i][j] = CRendBin_HOA3_HRIR_coeff_re_32kHz_fx[i][j]; // Q29 + hHrtf->pOut_to_bin_im_fx[i][j] = CRendBin_HOA3_HRIR_coeff_im_32kHz_fx[i][j]; // Q29 move32(); move32(); move16(); @@ -659,8 +659,8 @@ static ivas_error ivas_rend_initCrend_fx( hHrtf->num_iterations_diffuse[j] = CRendBin_HOA3_HRIR_num_iterations_diffuse_32kHz[j]; hHrtf->pIndex_frequency_max_diffuse[j] = CRendBin_HOA3_HRIR_pIndex_frequency_max_diffuse_32kHz[j]; - hHrtf->pOut_to_bin_diffuse_re_fx[j] = CRendBin_HOA3_HRIR_coeff_diffuse_re_32kHz_fx[j]; - hHrtf->pOut_to_bin_diffuse_im_fx[j] = CRendBin_HOA3_HRIR_coeff_diffuse_im_32kHz_fx[j]; + hHrtf->pOut_to_bin_diffuse_re_fx[j] = CRendBin_HOA3_HRIR_coeff_diffuse_re_32kHz_fx[j]; // Q31 + hHrtf->pOut_to_bin_diffuse_im_fx[j] = CRendBin_HOA3_HRIR_coeff_diffuse_im_32kHz_fx[j]; // Q31 move32(); move32(); move16(); @@ -669,7 +669,7 @@ static ivas_error ivas_rend_initCrend_fx( } ELSE IF( EQ_32( output_Fs, 16000 ) ) { - hHrtf->latency_s_fx = CRendBin_HOA3_HRIR_latency_s_fx; + hHrtf->latency_s_fx = CRendBin_HOA3_HRIR_latency_s_fx; // Q31 hHrtf->max_num_iterations = CRendBin_HOA3_HRIR_max_num_iterations_16kHz; hHrtf->index_frequency_max_diffuse = CRendBin_HOA3_HRIR_index_frequency_max_diffuse_16kHz; move32(); @@ -678,7 +678,7 @@ static ivas_error ivas_rend_initCrend_fx( FOR( i = 0; i < hHrtf->max_num_ir; i++ ) { - hHrtf->inv_diffuse_weight_fx[i] = CRendBin_HOA3_HRIR_inv_diffuse_weight_16kHz_fx[i]; + hHrtf->inv_diffuse_weight_fx[i] = CRendBin_HOA3_HRIR_inv_diffuse_weight_16kHz_fx[i]; // Q15 move16(); FOR( j = 0; j < BINAURAL_CHANNELS; j++ ) @@ -686,8 +686,8 @@ static ivas_error ivas_rend_initCrend_fx( hHrtf->num_iterations[i][j] = CRendBin_HOA3_HRIR_num_iterations_16kHz[i][j]; hHrtf->pIndex_frequency_max[i][j] = CRendBin_HOA3_HRIR_pIndex_frequency_max_16kHz[i][j]; - hHrtf->pOut_to_bin_re_fx[i][j] = CRendBin_HOA3_HRIR_coeff_re_16kHz_fx[i][j]; - hHrtf->pOut_to_bin_im_fx[i][j] = CRendBin_HOA3_HRIR_coeff_im_16kHz_fx[i][j]; + hHrtf->pOut_to_bin_re_fx[i][j] = CRendBin_HOA3_HRIR_coeff_re_16kHz_fx[i][j]; // Q29 + hHrtf->pOut_to_bin_im_fx[i][j] = CRendBin_HOA3_HRIR_coeff_im_16kHz_fx[i][j]; // Q29 move32(); move32(); move16(); @@ -700,8 +700,8 @@ static ivas_error ivas_rend_initCrend_fx( hHrtf->num_iterations_diffuse[j] = CRendBin_HOA3_HRIR_num_iterations_diffuse_16kHz[j]; hHrtf->pIndex_frequency_max_diffuse[j] = CRendBin_HOA3_HRIR_pIndex_frequency_max_diffuse_16kHz[j]; - hHrtf->pOut_to_bin_diffuse_re_fx[j] = CRendBin_HOA3_HRIR_coeff_diffuse_re_16kHz_fx[j]; - hHrtf->pOut_to_bin_diffuse_im_fx[j] = CRendBin_HOA3_HRIR_coeff_diffuse_im_16kHz_fx[j]; + hHrtf->pOut_to_bin_diffuse_re_fx[j] = CRendBin_HOA3_HRIR_coeff_diffuse_re_16kHz_fx[j]; // Q31 + hHrtf->pOut_to_bin_diffuse_im_fx[j] = CRendBin_HOA3_HRIR_coeff_diffuse_im_16kHz_fx[j]; // Q31 move32(); move32(); move16(); @@ -717,7 +717,7 @@ static ivas_error ivas_rend_initCrend_fx( { IF( EQ_32( output_Fs, 48000 ) ) { - hHrtf->latency_s_fx = CRendBin_HOA2_HRIR_latency_s_fx; + hHrtf->latency_s_fx = CRendBin_HOA2_HRIR_latency_s_fx; // Q31 hHrtf->max_num_iterations = CRendBin_HOA2_HRIR_max_num_iterations_48kHz; hHrtf->index_frequency_max_diffuse = CRendBin_HOA2_HRIR_index_frequency_max_diffuse_48kHz; move32(); @@ -726,7 +726,7 @@ static ivas_error ivas_rend_initCrend_fx( FOR( i = 0; i < hHrtf->max_num_ir; i++ ) { - hHrtf->inv_diffuse_weight_fx[i] = CRendBin_HOA2_HRIR_inv_diffuse_weight_48kHz_fx[i]; + hHrtf->inv_diffuse_weight_fx[i] = CRendBin_HOA2_HRIR_inv_diffuse_weight_48kHz_fx[i]; // Q15 move16(); FOR( j = 0; j < BINAURAL_CHANNELS; j++ ) @@ -734,8 +734,8 @@ static ivas_error ivas_rend_initCrend_fx( hHrtf->num_iterations[i][j] = CRendBin_HOA2_HRIR_num_iterations_48kHz[i][j]; hHrtf->pIndex_frequency_max[i][j] = CRendBin_HOA2_HRIR_pIndex_frequency_max_48kHz[i][j]; - hHrtf->pOut_to_bin_re_fx[i][j] = CRendBin_HOA2_HRIR_coeff_re_48kHz_fx[i][j]; - hHrtf->pOut_to_bin_im_fx[i][j] = CRendBin_HOA2_HRIR_coeff_im_48kHz_fx[i][j]; + hHrtf->pOut_to_bin_re_fx[i][j] = CRendBin_HOA2_HRIR_coeff_re_48kHz_fx[i][j]; // Q29 + hHrtf->pOut_to_bin_im_fx[i][j] = CRendBin_HOA2_HRIR_coeff_im_48kHz_fx[i][j]; // Q29 move32(); move32(); move16(); @@ -747,8 +747,8 @@ static ivas_error ivas_rend_initCrend_fx( hHrtf->num_iterations_diffuse[j] = CRendBin_HOA2_HRIR_num_iterations_diffuse_48kHz[j]; hHrtf->pIndex_frequency_max_diffuse[j] = CRendBin_HOA2_HRIR_pIndex_frequency_max_diffuse_48kHz[j]; - hHrtf->pOut_to_bin_diffuse_re_fx[j] = CRendBin_HOA2_HRIR_coeff_diffuse_re_48kHz_fx[j]; - hHrtf->pOut_to_bin_diffuse_im_fx[j] = CRendBin_HOA2_HRIR_coeff_diffuse_im_48kHz_fx[j]; + hHrtf->pOut_to_bin_diffuse_re_fx[j] = CRendBin_HOA2_HRIR_coeff_diffuse_re_48kHz_fx[j]; // Q31 + hHrtf->pOut_to_bin_diffuse_im_fx[j] = CRendBin_HOA2_HRIR_coeff_diffuse_im_48kHz_fx[j]; // Q31 move32(); move32(); move16(); @@ -757,7 +757,7 @@ static ivas_error ivas_rend_initCrend_fx( } ELSE IF( EQ_32( output_Fs, 32000 ) ) { - hHrtf->latency_s_fx = CRendBin_HOA2_HRIR_latency_s_fx; + hHrtf->latency_s_fx = CRendBin_HOA2_HRIR_latency_s_fx; // Q31 hHrtf->max_num_iterations = CRendBin_HOA2_HRIR_max_num_iterations_32kHz; hHrtf->index_frequency_max_diffuse = CRendBin_HOA2_HRIR_index_frequency_max_diffuse_32kHz; move32(); @@ -766,7 +766,7 @@ static ivas_error ivas_rend_initCrend_fx( FOR( i = 0; i < hHrtf->max_num_ir; i++ ) { - hHrtf->inv_diffuse_weight_fx[i] = CRendBin_HOA2_HRIR_inv_diffuse_weight_32kHz_fx[i]; + hHrtf->inv_diffuse_weight_fx[i] = CRendBin_HOA2_HRIR_inv_diffuse_weight_32kHz_fx[i]; // Q15 move16(); FOR( j = 0; j < BINAURAL_CHANNELS; j++ ) @@ -774,8 +774,8 @@ static ivas_error ivas_rend_initCrend_fx( hHrtf->num_iterations[i][j] = CRendBin_HOA2_HRIR_num_iterations_32kHz[i][j]; hHrtf->pIndex_frequency_max[i][j] = CRendBin_HOA2_HRIR_pIndex_frequency_max_32kHz[i][j]; - hHrtf->pOut_to_bin_re_fx[i][j] = CRendBin_HOA2_HRIR_coeff_re_32kHz_fx[i][j]; - hHrtf->pOut_to_bin_im_fx[i][j] = CRendBin_HOA2_HRIR_coeff_im_32kHz_fx[i][j]; + hHrtf->pOut_to_bin_re_fx[i][j] = CRendBin_HOA2_HRIR_coeff_re_32kHz_fx[i][j]; // Q29 + hHrtf->pOut_to_bin_im_fx[i][j] = CRendBin_HOA2_HRIR_coeff_im_32kHz_fx[i][j]; // Q29 move32(); move32(); move16(); @@ -788,8 +788,8 @@ static ivas_error ivas_rend_initCrend_fx( hHrtf->num_iterations_diffuse[j] = CRendBin_HOA2_HRIR_num_iterations_diffuse_32kHz[j]; hHrtf->pIndex_frequency_max_diffuse[j] = CRendBin_HOA2_HRIR_pIndex_frequency_max_diffuse_32kHz[j]; - hHrtf->pOut_to_bin_diffuse_re_fx[j] = CRendBin_HOA2_HRIR_coeff_diffuse_re_32kHz_fx[j]; - hHrtf->pOut_to_bin_diffuse_im_fx[j] = CRendBin_HOA2_HRIR_coeff_diffuse_im_32kHz_fx[j]; + hHrtf->pOut_to_bin_diffuse_re_fx[j] = CRendBin_HOA2_HRIR_coeff_diffuse_re_32kHz_fx[j]; // Q31 + hHrtf->pOut_to_bin_diffuse_im_fx[j] = CRendBin_HOA2_HRIR_coeff_diffuse_im_32kHz_fx[j]; // Q31 move32(); move32(); move16(); @@ -798,7 +798,7 @@ static ivas_error ivas_rend_initCrend_fx( } ELSE IF( EQ_32( output_Fs, 16000 ) ) { - hHrtf->latency_s_fx = CRendBin_HOA2_HRIR_latency_s_fx; + hHrtf->latency_s_fx = CRendBin_HOA2_HRIR_latency_s_fx; // Q31 hHrtf->max_num_iterations = CRendBin_HOA2_HRIR_max_num_iterations_16kHz; hHrtf->index_frequency_max_diffuse = CRendBin_HOA2_HRIR_index_frequency_max_diffuse_16kHz; move32(); @@ -807,7 +807,7 @@ static ivas_error ivas_rend_initCrend_fx( FOR( i = 0; i < hHrtf->max_num_ir; i++ ) { - hHrtf->inv_diffuse_weight_fx[i] = CRendBin_HOA2_HRIR_inv_diffuse_weight_16kHz_fx[i]; + hHrtf->inv_diffuse_weight_fx[i] = CRendBin_HOA2_HRIR_inv_diffuse_weight_16kHz_fx[i]; // Q15 move16(); FOR( j = 0; j < BINAURAL_CHANNELS; j++ ) @@ -815,8 +815,8 @@ static ivas_error ivas_rend_initCrend_fx( hHrtf->num_iterations[i][j] = CRendBin_HOA2_HRIR_num_iterations_16kHz[i][j]; hHrtf->pIndex_frequency_max[i][j] = CRendBin_HOA2_HRIR_pIndex_frequency_max_16kHz[i][j]; - hHrtf->pOut_to_bin_re_fx[i][j] = CRendBin_HOA2_HRIR_coeff_re_16kHz_fx[i][j]; - hHrtf->pOut_to_bin_im_fx[i][j] = CRendBin_HOA2_HRIR_coeff_im_16kHz_fx[i][j]; + hHrtf->pOut_to_bin_re_fx[i][j] = CRendBin_HOA2_HRIR_coeff_re_16kHz_fx[i][j]; // Q29 + hHrtf->pOut_to_bin_im_fx[i][j] = CRendBin_HOA2_HRIR_coeff_im_16kHz_fx[i][j]; // Q29 move32(); move32(); move16(); @@ -829,8 +829,8 @@ static ivas_error ivas_rend_initCrend_fx( hHrtf->num_iterations_diffuse[j] = CRendBin_HOA2_HRIR_num_iterations_diffuse_16kHz[j]; hHrtf->pIndex_frequency_max_diffuse[j] = CRendBin_HOA2_HRIR_pIndex_frequency_max_diffuse_16kHz[j]; - hHrtf->pOut_to_bin_diffuse_re_fx[j] = CRendBin_HOA2_HRIR_coeff_diffuse_re_16kHz_fx[j]; - hHrtf->pOut_to_bin_diffuse_im_fx[j] = CRendBin_HOA2_HRIR_coeff_diffuse_im_16kHz_fx[j]; + hHrtf->pOut_to_bin_diffuse_re_fx[j] = CRendBin_HOA2_HRIR_coeff_diffuse_re_16kHz_fx[j]; // Q31 + hHrtf->pOut_to_bin_diffuse_im_fx[j] = CRendBin_HOA2_HRIR_coeff_diffuse_im_16kHz_fx[j]; // Q31 move32(); move32(); move16(); @@ -846,7 +846,7 @@ static ivas_error ivas_rend_initCrend_fx( { IF( EQ_32( output_Fs, 48000 ) ) { - hHrtf->latency_s_fx = CRendBin_FOA_HRIR_latency_s_fx; + hHrtf->latency_s_fx = CRendBin_FOA_HRIR_latency_s_fx; // Q31 hHrtf->max_num_iterations = CRendBin_FOA_HRIR_max_num_iterations_48kHz; hHrtf->index_frequency_max_diffuse = CRendBin_FOA_HRIR_index_frequency_max_diffuse_48kHz; move32(); @@ -855,7 +855,7 @@ static ivas_error ivas_rend_initCrend_fx( FOR( i = 0; i < hHrtf->max_num_ir; i++ ) { - hHrtf->inv_diffuse_weight_fx[i] = CRendBin_FOA_HRIR_inv_diffuse_weight_48kHz_fx[i]; + hHrtf->inv_diffuse_weight_fx[i] = CRendBin_FOA_HRIR_inv_diffuse_weight_48kHz_fx[i]; // Q15 move16(); FOR( j = 0; j < BINAURAL_CHANNELS; j++ ) @@ -863,8 +863,8 @@ static ivas_error ivas_rend_initCrend_fx( hHrtf->num_iterations[i][j] = CRendBin_FOA_HRIR_num_iterations_48kHz[i][j]; hHrtf->pIndex_frequency_max[i][j] = CRendBin_FOA_HRIR_pIndex_frequency_max_48kHz[i][j]; - hHrtf->pOut_to_bin_re_fx[i][j] = CRendBin_FOA_HRIR_coeff_re_48kHz_fx[i][j]; - hHrtf->pOut_to_bin_im_fx[i][j] = CRendBin_FOA_HRIR_coeff_im_48kHz_fx[i][j]; + hHrtf->pOut_to_bin_re_fx[i][j] = CRendBin_FOA_HRIR_coeff_re_48kHz_fx[i][j]; // Q29 + hHrtf->pOut_to_bin_im_fx[i][j] = CRendBin_FOA_HRIR_coeff_im_48kHz_fx[i][j]; // Q29 move32(); move32(); move16(); @@ -876,8 +876,8 @@ static ivas_error ivas_rend_initCrend_fx( hHrtf->num_iterations_diffuse[j] = CRendBin_FOA_HRIR_num_iterations_diffuse_48kHz[j]; hHrtf->pIndex_frequency_max_diffuse[j] = CRendBin_FOA_HRIR_pIndex_frequency_max_diffuse_48kHz[j]; - hHrtf->pOut_to_bin_diffuse_re_fx[j] = CRendBin_FOA_HRIR_coeff_diffuse_re_48kHz_fx[j]; - hHrtf->pOut_to_bin_diffuse_im_fx[j] = CRendBin_FOA_HRIR_coeff_diffuse_im_48kHz_fx[j]; + hHrtf->pOut_to_bin_diffuse_re_fx[j] = CRendBin_FOA_HRIR_coeff_diffuse_re_48kHz_fx[j]; // Q31 + hHrtf->pOut_to_bin_diffuse_im_fx[j] = CRendBin_FOA_HRIR_coeff_diffuse_im_48kHz_fx[j]; // Q31 move32(); move32(); move16(); @@ -886,7 +886,7 @@ static ivas_error ivas_rend_initCrend_fx( } ELSE IF( EQ_32( output_Fs, 32000 ) ) { - hHrtf->latency_s_fx = CRendBin_FOA_HRIR_latency_s_fx; + hHrtf->latency_s_fx = CRendBin_FOA_HRIR_latency_s_fx; // Q31 hHrtf->max_num_iterations = CRendBin_FOA_HRIR_max_num_iterations_32kHz; hHrtf->index_frequency_max_diffuse = CRendBin_FOA_HRIR_index_frequency_max_diffuse_32kHz; move32(); @@ -895,7 +895,7 @@ static ivas_error ivas_rend_initCrend_fx( FOR( i = 0; i < hHrtf->max_num_ir; i++ ) { - hHrtf->inv_diffuse_weight_fx[i] = CRendBin_FOA_HRIR_inv_diffuse_weight_32kHz_fx[i]; + hHrtf->inv_diffuse_weight_fx[i] = CRendBin_FOA_HRIR_inv_diffuse_weight_32kHz_fx[i]; // Q15 move16(); FOR( j = 0; j < BINAURAL_CHANNELS; j++ ) @@ -903,8 +903,8 @@ static ivas_error ivas_rend_initCrend_fx( hHrtf->num_iterations[i][j] = CRendBin_FOA_HRIR_num_iterations_32kHz[i][j]; hHrtf->pIndex_frequency_max[i][j] = CRendBin_FOA_HRIR_pIndex_frequency_max_32kHz[i][j]; - hHrtf->pOut_to_bin_re_fx[i][j] = CRendBin_FOA_HRIR_coeff_re_32kHz_fx[i][j]; - hHrtf->pOut_to_bin_im_fx[i][j] = CRendBin_FOA_HRIR_coeff_im_32kHz_fx[i][j]; + hHrtf->pOut_to_bin_re_fx[i][j] = CRendBin_FOA_HRIR_coeff_re_32kHz_fx[i][j]; // Q29 + hHrtf->pOut_to_bin_im_fx[i][j] = CRendBin_FOA_HRIR_coeff_im_32kHz_fx[i][j]; // Q29 move32(); move32(); move16(); @@ -917,8 +917,8 @@ static ivas_error ivas_rend_initCrend_fx( hHrtf->num_iterations_diffuse[j] = CRendBin_FOA_HRIR_num_iterations_diffuse_32kHz[j]; hHrtf->pIndex_frequency_max_diffuse[j] = CRendBin_FOA_HRIR_pIndex_frequency_max_diffuse_32kHz[j]; - hHrtf->pOut_to_bin_diffuse_re_fx[j] = CRendBin_FOA_HRIR_coeff_diffuse_re_32kHz_fx[j]; - hHrtf->pOut_to_bin_diffuse_im_fx[j] = CRendBin_FOA_HRIR_coeff_diffuse_im_32kHz_fx[j]; + hHrtf->pOut_to_bin_diffuse_re_fx[j] = CRendBin_FOA_HRIR_coeff_diffuse_re_32kHz_fx[j]; // Q31 + hHrtf->pOut_to_bin_diffuse_im_fx[j] = CRendBin_FOA_HRIR_coeff_diffuse_im_32kHz_fx[j]; // Q31 move32(); move32(); move16(); @@ -927,7 +927,7 @@ static ivas_error ivas_rend_initCrend_fx( } ELSE IF( EQ_32( output_Fs, 16000 ) ) { - hHrtf->latency_s_fx = CRendBin_FOA_HRIR_latency_s_fx; + hHrtf->latency_s_fx = CRendBin_FOA_HRIR_latency_s_fx; // Q31 hHrtf->max_num_iterations = CRendBin_FOA_HRIR_max_num_iterations_16kHz; hHrtf->index_frequency_max_diffuse = CRendBin_FOA_HRIR_index_frequency_max_diffuse_16kHz; move32(); @@ -936,7 +936,7 @@ static ivas_error ivas_rend_initCrend_fx( FOR( i = 0; i < hHrtf->max_num_ir; i++ ) { - hHrtf->inv_diffuse_weight_fx[i] = CRendBin_FOA_HRIR_inv_diffuse_weight_16kHz_fx[i]; + hHrtf->inv_diffuse_weight_fx[i] = CRendBin_FOA_HRIR_inv_diffuse_weight_16kHz_fx[i]; // Q15 move16(); FOR( j = 0; j < BINAURAL_CHANNELS; j++ ) @@ -944,8 +944,8 @@ static ivas_error ivas_rend_initCrend_fx( hHrtf->num_iterations[i][j] = CRendBin_FOA_HRIR_num_iterations_16kHz[i][j]; hHrtf->pIndex_frequency_max[i][j] = CRendBin_FOA_HRIR_pIndex_frequency_max_16kHz[i][j]; - hHrtf->pOut_to_bin_re_fx[i][j] = CRendBin_FOA_HRIR_coeff_re_16kHz_fx[i][j]; - hHrtf->pOut_to_bin_im_fx[i][j] = CRendBin_FOA_HRIR_coeff_im_16kHz_fx[i][j]; + hHrtf->pOut_to_bin_re_fx[i][j] = CRendBin_FOA_HRIR_coeff_re_16kHz_fx[i][j]; // Q29 + hHrtf->pOut_to_bin_im_fx[i][j] = CRendBin_FOA_HRIR_coeff_im_16kHz_fx[i][j]; // Q29 move32(); move32(); move16(); @@ -958,8 +958,8 @@ static ivas_error ivas_rend_initCrend_fx( hHrtf->num_iterations_diffuse[j] = CRendBin_FOA_HRIR_num_iterations_diffuse_16kHz[j]; hHrtf->pIndex_frequency_max_diffuse[j] = CRendBin_FOA_HRIR_pIndex_frequency_max_diffuse_16kHz[j]; - hHrtf->pOut_to_bin_diffuse_re_fx[j] = CRendBin_FOA_HRIR_coeff_diffuse_re_16kHz_fx[j]; - hHrtf->pOut_to_bin_diffuse_im_fx[j] = CRendBin_FOA_HRIR_coeff_diffuse_im_16kHz_fx[j]; + hHrtf->pOut_to_bin_diffuse_re_fx[j] = CRendBin_FOA_HRIR_coeff_diffuse_re_16kHz_fx[j]; // Q31 + hHrtf->pOut_to_bin_diffuse_im_fx[j] = CRendBin_FOA_HRIR_coeff_diffuse_im_16kHz_fx[j]; // Q31 move32(); move32(); move16(); @@ -992,13 +992,13 @@ static ivas_error ivas_rend_initCrend_fx( IF( EQ_16( outConfig, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR ) ) { - hHrtf->latency_s_fx = hSetOfHRTF->hHRTF_brir_combined->latency_s_fx; + hHrtf->latency_s_fx = hSetOfHRTF->hHRTF_brir_combined->latency_s_fx; // Q31 hHrtf->max_num_iterations = hSetOfHRTF->hHRTF_brir_combined->max_num_iterations; hHrtf->index_frequency_max_diffuse = hSetOfHRTF->hHRTF_brir_combined->index_frequency_max_diffuse; } ELSE { - hHrtf->latency_s_fx = hSetOfHRTF->hHRTF_hrir_combined->latency_s_fx; + hHrtf->latency_s_fx = hSetOfHRTF->hHRTF_hrir_combined->latency_s_fx; // Q31 hHrtf->max_num_iterations = hSetOfHRTF->hHRTF_hrir_combined->max_num_iterations; hHrtf->index_frequency_max_diffuse = hSetOfHRTF->hHRTF_hrir_combined->index_frequency_max_diffuse; } @@ -1013,16 +1013,16 @@ static ivas_error ivas_rend_initCrend_fx( hHrtf->num_iterations_diffuse[j] = hSetOfHRTF->hHRTF_brir_combined->num_iterations_diffuse[j]; hHrtf->pIndex_frequency_max_diffuse[j] = hSetOfHRTF->hHRTF_brir_combined->pIndex_frequency_max_diffuse[j]; - hHrtf->pOut_to_bin_diffuse_re_fx[j] = hSetOfHRTF->hHRTF_brir_combined->pOut_to_bin_diffuse_re_fx[j]; - hHrtf->pOut_to_bin_diffuse_im_fx[j] = hSetOfHRTF->hHRTF_brir_combined->pOut_to_bin_diffuse_im_fx[j]; + hHrtf->pOut_to_bin_diffuse_re_fx[j] = hSetOfHRTF->hHRTF_brir_combined->pOut_to_bin_diffuse_re_fx[j]; // Q31 + hHrtf->pOut_to_bin_diffuse_im_fx[j] = hSetOfHRTF->hHRTF_brir_combined->pOut_to_bin_diffuse_im_fx[j]; // Q31 } ELSE { hHrtf->num_iterations_diffuse[j] = hSetOfHRTF->hHRTF_hrir_combined->num_iterations_diffuse[j]; hHrtf->pIndex_frequency_max_diffuse[j] = hSetOfHRTF->hHRTF_hrir_combined->pIndex_frequency_max_diffuse[j]; - hHrtf->pOut_to_bin_diffuse_re_fx[j] = hSetOfHRTF->hHRTF_hrir_combined->pOut_to_bin_diffuse_re_fx[j]; - hHrtf->pOut_to_bin_diffuse_im_fx[j] = hSetOfHRTF->hHRTF_hrir_combined->pOut_to_bin_diffuse_im_fx[j]; + hHrtf->pOut_to_bin_diffuse_re_fx[j] = hSetOfHRTF->hHRTF_hrir_combined->pOut_to_bin_diffuse_re_fx[j]; // Q31 + hHrtf->pOut_to_bin_diffuse_im_fx[j] = hSetOfHRTF->hHRTF_hrir_combined->pOut_to_bin_diffuse_im_fx[j]; // Q31 } move32(); move32(); @@ -1060,11 +1060,11 @@ static ivas_error ivas_rend_initCrend_fx( IF( EQ_16( outConfig, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR ) ) { - hHrtf->inv_diffuse_weight_fx[i] = hSetOfHRTF->hHRTF_brir_combined->inv_diffuse_weight_fx[tmp]; + hHrtf->inv_diffuse_weight_fx[i] = hSetOfHRTF->hHRTF_brir_combined->inv_diffuse_weight_fx[tmp]; // Q15 } ELSE { - hHrtf->inv_diffuse_weight_fx[i] = hSetOfHRTF->hHRTF_hrir_combined->inv_diffuse_weight_fx[tmp]; + hHrtf->inv_diffuse_weight_fx[i] = hSetOfHRTF->hHRTF_hrir_combined->inv_diffuse_weight_fx[tmp]; // Q15 } move16(); @@ -1075,16 +1075,16 @@ static ivas_error ivas_rend_initCrend_fx( hHrtf->num_iterations[i][j] = hSetOfHRTF->hHRTF_brir_combined->num_iterations[tmp][j]; hHrtf->pIndex_frequency_max[i][j] = hSetOfHRTF->hHRTF_brir_combined->pIndex_frequency_max[tmp][j]; - hHrtf->pOut_to_bin_re_fx[i][j] = hSetOfHRTF->hHRTF_brir_combined->pOut_to_bin_re_fx[tmp][j]; - hHrtf->pOut_to_bin_im_fx[i][j] = hSetOfHRTF->hHRTF_brir_combined->pOut_to_bin_im_fx[tmp][j]; + hHrtf->pOut_to_bin_re_fx[i][j] = hSetOfHRTF->hHRTF_brir_combined->pOut_to_bin_re_fx[tmp][j]; // Q29 + hHrtf->pOut_to_bin_im_fx[i][j] = hSetOfHRTF->hHRTF_brir_combined->pOut_to_bin_im_fx[tmp][j]; // Q29 } ELSE { hHrtf->num_iterations[i][j] = hSetOfHRTF->hHRTF_hrir_combined->num_iterations[tmp][j]; hHrtf->pIndex_frequency_max[i][j] = hSetOfHRTF->hHRTF_hrir_combined->pIndex_frequency_max[tmp][j]; - hHrtf->pOut_to_bin_re_fx[i][j] = hSetOfHRTF->hHRTF_hrir_combined->pOut_to_bin_re_fx[tmp][j]; - hHrtf->pOut_to_bin_im_fx[i][j] = hSetOfHRTF->hHRTF_hrir_combined->pOut_to_bin_im_fx[tmp][j]; + hHrtf->pOut_to_bin_re_fx[i][j] = hSetOfHRTF->hHRTF_hrir_combined->pOut_to_bin_re_fx[tmp][j]; // Q29 + hHrtf->pOut_to_bin_im_fx[i][j] = hSetOfHRTF->hHRTF_hrir_combined->pOut_to_bin_im_fx[tmp][j]; // Q29 } move32(); move32(); @@ -1097,7 +1097,7 @@ static ivas_error ivas_rend_initCrend_fx( { IF( EQ_16( inConfig, IVAS_AUDIO_CONFIG_HOA3 ) ) { - hHrtf->latency_s_fx = hSetOfHRTF->hHRTF_hrir_hoa3->latency_s_fx; + hHrtf->latency_s_fx = hSetOfHRTF->hHRTF_hrir_hoa3->latency_s_fx; // Q31 hHrtf->max_num_iterations = hSetOfHRTF->hHRTF_hrir_hoa3->max_num_iterations; hHrtf->index_frequency_max_diffuse = hSetOfHRTF->hHRTF_hrir_hoa3->index_frequency_max_diffuse; move32(); @@ -1106,7 +1106,7 @@ static ivas_error ivas_rend_initCrend_fx( FOR( i = 0; i < hHrtf->max_num_ir; i++ ) { - hHrtf->inv_diffuse_weight_fx[i] = hSetOfHRTF->hHRTF_hrir_hoa3->inv_diffuse_weight_fx[i]; + hHrtf->inv_diffuse_weight_fx[i] = hSetOfHRTF->hHRTF_hrir_hoa3->inv_diffuse_weight_fx[i]; // Q31 move16(); FOR( j = 0; j < BINAURAL_CHANNELS; j++ ) @@ -1114,8 +1114,8 @@ static ivas_error ivas_rend_initCrend_fx( hHrtf->num_iterations[i][j] = hSetOfHRTF->hHRTF_hrir_hoa3->num_iterations[i][j]; hHrtf->pIndex_frequency_max[i][j] = hSetOfHRTF->hHRTF_hrir_hoa3->pIndex_frequency_max[i][j]; - hHrtf->pOut_to_bin_re_fx[i][j] = hSetOfHRTF->hHRTF_hrir_hoa3->pOut_to_bin_re_fx[i][j]; - hHrtf->pOut_to_bin_im_fx[i][j] = hSetOfHRTF->hHRTF_hrir_hoa3->pOut_to_bin_im_fx[i][j]; + hHrtf->pOut_to_bin_re_fx[i][j] = hSetOfHRTF->hHRTF_hrir_hoa3->pOut_to_bin_re_fx[i][j]; // Q29 + hHrtf->pOut_to_bin_im_fx[i][j] = hSetOfHRTF->hHRTF_hrir_hoa3->pOut_to_bin_im_fx[i][j]; // Q29 move32(); move32(); move16(); @@ -1127,8 +1127,8 @@ static ivas_error ivas_rend_initCrend_fx( hHrtf->num_iterations_diffuse[j] = hSetOfHRTF->hHRTF_hrir_hoa3->num_iterations_diffuse[j]; hHrtf->pIndex_frequency_max_diffuse[j] = hSetOfHRTF->hHRTF_hrir_hoa3->pIndex_frequency_max_diffuse[j]; - hHrtf->pOut_to_bin_diffuse_re_fx[j] = hSetOfHRTF->hHRTF_hrir_hoa3->pOut_to_bin_diffuse_re_fx[j]; - hHrtf->pOut_to_bin_diffuse_im_fx[j] = hSetOfHRTF->hHRTF_hrir_hoa3->pOut_to_bin_diffuse_im_fx[j]; + hHrtf->pOut_to_bin_diffuse_re_fx[j] = hSetOfHRTF->hHRTF_hrir_hoa3->pOut_to_bin_diffuse_re_fx[j]; // Q31 + hHrtf->pOut_to_bin_diffuse_im_fx[j] = hSetOfHRTF->hHRTF_hrir_hoa3->pOut_to_bin_diffuse_im_fx[j]; // Q31 move32(); move32(); move16(); @@ -1137,7 +1137,7 @@ static ivas_error ivas_rend_initCrend_fx( } ELSE IF( EQ_16( inConfig, IVAS_AUDIO_CONFIG_HOA2 ) ) { - hHrtf->latency_s_fx = hSetOfHRTF->hHRTF_hrir_hoa2->latency_s_fx; + hHrtf->latency_s_fx = hSetOfHRTF->hHRTF_hrir_hoa2->latency_s_fx; // Q31 hHrtf->max_num_iterations = hSetOfHRTF->hHRTF_hrir_hoa2->max_num_iterations; hHrtf->index_frequency_max_diffuse = hSetOfHRTF->hHRTF_hrir_hoa2->index_frequency_max_diffuse; move32(); @@ -1146,7 +1146,7 @@ static ivas_error ivas_rend_initCrend_fx( FOR( i = 0; i < hHrtf->max_num_ir; i++ ) { - hHrtf->inv_diffuse_weight_fx[i] = hSetOfHRTF->hHRTF_hrir_hoa2->inv_diffuse_weight_fx[i]; + hHrtf->inv_diffuse_weight_fx[i] = hSetOfHRTF->hHRTF_hrir_hoa2->inv_diffuse_weight_fx[i]; // Q15 move16(); FOR( j = 0; j < BINAURAL_CHANNELS; j++ ) @@ -1154,8 +1154,8 @@ static ivas_error ivas_rend_initCrend_fx( hHrtf->num_iterations[i][j] = hSetOfHRTF->hHRTF_hrir_hoa2->num_iterations[i][j]; hHrtf->pIndex_frequency_max[i][j] = hSetOfHRTF->hHRTF_hrir_hoa2->pIndex_frequency_max[i][j]; - hHrtf->pOut_to_bin_re_fx[i][j] = hSetOfHRTF->hHRTF_hrir_hoa2->pOut_to_bin_re_fx[i][j]; - hHrtf->pOut_to_bin_im_fx[i][j] = hSetOfHRTF->hHRTF_hrir_hoa2->pOut_to_bin_im_fx[i][j]; + hHrtf->pOut_to_bin_re_fx[i][j] = hSetOfHRTF->hHRTF_hrir_hoa2->pOut_to_bin_re_fx[i][j]; // Q29 + hHrtf->pOut_to_bin_im_fx[i][j] = hSetOfHRTF->hHRTF_hrir_hoa2->pOut_to_bin_im_fx[i][j]; // Q29 move32(); move32(); move16(); @@ -1167,8 +1167,8 @@ static ivas_error ivas_rend_initCrend_fx( hHrtf->num_iterations_diffuse[j] = hSetOfHRTF->hHRTF_hrir_hoa2->num_iterations_diffuse[j]; hHrtf->pIndex_frequency_max_diffuse[j] = hSetOfHRTF->hHRTF_hrir_hoa2->pIndex_frequency_max_diffuse[j]; - hHrtf->pOut_to_bin_diffuse_re_fx[j] = hSetOfHRTF->hHRTF_hrir_hoa2->pOut_to_bin_diffuse_re_fx[j]; - hHrtf->pOut_to_bin_diffuse_im_fx[j] = hSetOfHRTF->hHRTF_hrir_hoa2->pOut_to_bin_diffuse_im_fx[j]; + hHrtf->pOut_to_bin_diffuse_re_fx[j] = hSetOfHRTF->hHRTF_hrir_hoa2->pOut_to_bin_diffuse_re_fx[j]; // Q31 + hHrtf->pOut_to_bin_diffuse_im_fx[j] = hSetOfHRTF->hHRTF_hrir_hoa2->pOut_to_bin_diffuse_im_fx[j]; // Q31 move32(); move32(); move16(); @@ -1177,7 +1177,7 @@ static ivas_error ivas_rend_initCrend_fx( } ELSE IF( EQ_16( inConfig, IVAS_AUDIO_CONFIG_FOA ) ) { - hHrtf->latency_s_fx = hSetOfHRTF->hHRTF_hrir_foa->latency_s_fx; + hHrtf->latency_s_fx = hSetOfHRTF->hHRTF_hrir_foa->latency_s_fx; // Q31 hHrtf->max_num_iterations = hSetOfHRTF->hHRTF_hrir_foa->max_num_iterations; hHrtf->index_frequency_max_diffuse = hSetOfHRTF->hHRTF_hrir_foa->index_frequency_max_diffuse; move32(); @@ -1186,7 +1186,7 @@ static ivas_error ivas_rend_initCrend_fx( FOR( i = 0; i < hHrtf->max_num_ir; i++ ) { - hHrtf->inv_diffuse_weight_fx[i] = hSetOfHRTF->hHRTF_hrir_foa->inv_diffuse_weight_fx[i]; + hHrtf->inv_diffuse_weight_fx[i] = hSetOfHRTF->hHRTF_hrir_foa->inv_diffuse_weight_fx[i]; // Q31 move16(); FOR( j = 0; j < BINAURAL_CHANNELS; j++ ) @@ -1194,8 +1194,8 @@ static ivas_error ivas_rend_initCrend_fx( hHrtf->num_iterations[i][j] = hSetOfHRTF->hHRTF_hrir_foa->num_iterations[i][j]; hHrtf->pIndex_frequency_max[i][j] = hSetOfHRTF->hHRTF_hrir_foa->pIndex_frequency_max[i][j]; - hHrtf->pOut_to_bin_re_fx[i][j] = hSetOfHRTF->hHRTF_hrir_foa->pOut_to_bin_re_fx[i][j]; - hHrtf->pOut_to_bin_im_fx[i][j] = hSetOfHRTF->hHRTF_hrir_foa->pOut_to_bin_im_fx[i][j]; + hHrtf->pOut_to_bin_re_fx[i][j] = hSetOfHRTF->hHRTF_hrir_foa->pOut_to_bin_re_fx[i][j]; // Q29 + hHrtf->pOut_to_bin_im_fx[i][j] = hSetOfHRTF->hHRTF_hrir_foa->pOut_to_bin_im_fx[i][j]; // Q29 move32(); move32(); move16(); @@ -1207,8 +1207,8 @@ static ivas_error ivas_rend_initCrend_fx( hHrtf->num_iterations_diffuse[j] = hSetOfHRTF->hHRTF_hrir_foa->num_iterations_diffuse[j]; hHrtf->pIndex_frequency_max_diffuse[j] = hSetOfHRTF->hHRTF_hrir_foa->pIndex_frequency_max_diffuse[j]; - hHrtf->pOut_to_bin_diffuse_re_fx[j] = hSetOfHRTF->hHRTF_hrir_foa->pOut_to_bin_diffuse_re_fx[j]; - hHrtf->pOut_to_bin_diffuse_im_fx[j] = hSetOfHRTF->hHRTF_hrir_foa->pOut_to_bin_diffuse_im_fx[j]; + hHrtf->pOut_to_bin_diffuse_re_fx[j] = hSetOfHRTF->hHRTF_hrir_foa->pOut_to_bin_diffuse_re_fx[j]; // Q31 + hHrtf->pOut_to_bin_diffuse_im_fx[j] = hSetOfHRTF->hHRTF_hrir_foa->pOut_to_bin_diffuse_im_fx[j]; // Q31 move32(); move32(); move16(); @@ -2341,7 +2341,7 @@ static ivas_error ivas_er_init_handle( move32(); if ( EQ_16( i, 2 ) ) { - reflections->user_origin_fx[i] = ER_LIST_HEIGHT_FX; + reflections->user_origin_fx[i] = ER_LIST_HEIGHT_FX; // Q22 move32(); } } @@ -2675,7 +2675,7 @@ ivas_error ivas_rend_openCrend( /* Set sample rate and frame size */ - hCrend->reflections->output_Fs_fx = output_Fs; + hCrend->reflections->output_Fs_fx = output_Fs; // Q0 move32(); hCrend->reflections->max_frame_size = extract_l( Mult_32_16( output_Fs, INV_FRAME_PER_SEC_Q15 ) ); @@ -2721,6 +2721,7 @@ void ivas_rend_closeCrend( Word16 i; CREND_HANDLE hCrend; + test(); IF( pCrend == NULL || *pCrend == NULL ) { return; @@ -3086,8 +3087,8 @@ static ivas_error ivas_rend_crendConvolver( const CREND_WRAPPER *pCrend, AUDIO_CONFIG inConfig, AUDIO_CONFIG outConfig, - Word32 *pcm_in[], - Word32 *pcm_out[], + Word32 *pcm_in[], // Qx + Word32 *pcm_out[], // Qx const Word32 output_Fs, const Word16 i_ts ) { @@ -3149,26 +3150,26 @@ static ivas_error ivas_rend_crendConvolver( move16(); FOR( idx_in = 0; idx_in < nchan_in; idx_in++ ) { - pIn = &pcm_in[idx_in][imult1616( i_ts, subframe_length )]; + pIn = &pcm_in[idx_in][i_ts * subframe_length]; IF( NE_16( idx_in, lfe_idx_in ) ) { IF( pCrend->hHrtfCrend->num_iterations_diffuse[0] > 0 ) { - pFreq_buf_re = &hCrend->freq_buffer_re_diffuse_fx[offset_diffuse]; - pFreq_buf_im = &hCrend->freq_buffer_im_diffuse_fx[offset_diffuse]; - pFreq_filt_re = &hCrend->freq_buffer_re_fx[i][offset]; - pFreq_filt_im = &hCrend->freq_buffer_im_fx[i][offset]; + pFreq_buf_re = &hCrend->freq_buffer_re_diffuse_fx[offset_diffuse]; // Qx + pFreq_buf_im = &hCrend->freq_buffer_im_diffuse_fx[offset_diffuse]; // Qx + pFreq_filt_re = &hCrend->freq_buffer_re_fx[i][offset]; // Qx + pFreq_filt_im = &hCrend->freq_buffer_im_fx[i][offset]; // Qx FOR( k = 0; k < pCrend->hHrtfCrend->index_frequency_max_diffuse; k++ ) { - pFreq_buf_re[k] = L_add( Mpy_32_16_r( pFreq_filt_re[k], pCrend->hHrtfCrend->inv_diffuse_weight_fx[i] ), pFreq_buf_re[k] ); - pFreq_buf_im[k] = L_add( Mpy_32_16_r( pFreq_filt_im[k], pCrend->hHrtfCrend->inv_diffuse_weight_fx[i] ), pFreq_buf_im[k] ); + pFreq_buf_re[k] = L_add( Mpy_32_16_r( pFreq_filt_re[k], pCrend->hHrtfCrend->inv_diffuse_weight_fx[i] ), pFreq_buf_re[k] ); // Qx + pFreq_buf_im[k] = L_add( Mpy_32_16_r( pFreq_filt_im[k], pCrend->hHrtfCrend->inv_diffuse_weight_fx[i] ), pFreq_buf_im[k] ); // Qx move32(); move32(); } } - pFreq_buf_re = &hCrend->freq_buffer_re_fx[i][offset]; - pFreq_buf_im = &hCrend->freq_buffer_im_fx[i][offset]; + pFreq_buf_re = &hCrend->freq_buffer_re_fx[i][offset]; // Qx + pFreq_buf_im = &hCrend->freq_buffer_im_fx[i][offset]; // Qx ivas_mdft_fx( pIn, pFreq_buf_re, pFreq_buf_im, subframe_length, subframe_length ); @@ -3198,15 +3199,15 @@ static ivas_error ivas_rend_crendConvolver( offset_in = offset_in % ( pCrend->hHrtfCrend->max_num_iterations ); move16(); offset_in = imult1616( offset_in, subframe_length ); - pFreq_buf_re = &hCrend->freq_buffer_re_fx[i][offset_in]; - pFreq_buf_im = &hCrend->freq_buffer_im_fx[i][offset_in]; - pFreq_filt_re = &pCrend->hHrtfCrend->pOut_to_bin_re_fx[i][j][offset]; - pFreq_filt_im = &pCrend->hHrtfCrend->pOut_to_bin_im_fx[i][j][offset]; + pFreq_buf_re = &hCrend->freq_buffer_re_fx[i][offset_in]; // Qx + pFreq_buf_im = &hCrend->freq_buffer_im_fx[i][offset_in]; // Qx + pFreq_filt_re = &pCrend->hHrtfCrend->pOut_to_bin_re_fx[i][j][offset]; // Q29 + pFreq_filt_im = &pCrend->hHrtfCrend->pOut_to_bin_im_fx[i][j][offset]; // Q29 FOR( k = 0; k < pCrend->hHrtfCrend->pIndex_frequency_max[i][j][m]; k++ ) { - tmp_out_re[k] = L_add( L_shl( Msub_32_32( Mpy_32_32( pFreq_buf_re[k], pFreq_filt_re[k] ), pFreq_buf_im[k], pFreq_filt_im[k] ), 2 ), tmp_out_re[k] ); - tmp_out_im[k] = L_add( L_shl( Madd_32_32( Mpy_32_32( pFreq_buf_re[k], pFreq_filt_im[k] ), pFreq_buf_im[k], pFreq_filt_re[k] ), 2 ), tmp_out_im[k] ); + tmp_out_re[k] = L_add( L_shl( Msub_32_32( Mpy_32_32( pFreq_buf_re[k], pFreq_filt_re[k] ), pFreq_buf_im[k], pFreq_filt_im[k] ), 2 ), tmp_out_re[k] ); // Qx + tmp_out_im[k] = L_add( L_shl( Madd_32_32( Mpy_32_32( pFreq_buf_re[k], pFreq_filt_im[k] ), pFreq_buf_im[k], pFreq_filt_re[k] ), 2 ), tmp_out_im[k] ); // Qx move32(); move32(); } @@ -3224,14 +3225,14 @@ static ivas_error ivas_rend_crendConvolver( offset_diffuse = offset_diffuse % pCrend->hHrtfCrend->num_iterations_diffuse[0]; move16(); offset_diffuse = imult1616( offset_diffuse, subframe_length ); - pFreq_buf_re = &hCrend->freq_buffer_re_diffuse_fx[offset_diffuse]; - pFreq_buf_im = &hCrend->freq_buffer_im_diffuse_fx[offset_diffuse]; - pFreq_filt_re = &pCrend->hHrtfCrend->pOut_to_bin_diffuse_re_fx[j][offset]; - pFreq_filt_im = &pCrend->hHrtfCrend->pOut_to_bin_diffuse_im_fx[j][offset]; + pFreq_buf_re = &hCrend->freq_buffer_re_diffuse_fx[offset_diffuse]; // Qx + pFreq_buf_im = &hCrend->freq_buffer_im_diffuse_fx[offset_diffuse]; // Qx + pFreq_filt_re = &pCrend->hHrtfCrend->pOut_to_bin_diffuse_re_fx[j][offset]; // Q31 + pFreq_filt_im = &pCrend->hHrtfCrend->pOut_to_bin_diffuse_im_fx[j][offset]; // Q31 FOR( k = 0; k < pCrend->hHrtfCrend->pIndex_frequency_max_diffuse[j][m]; k++ ) { - tmp_out_re[k] = L_add( Msub_32_32( Mpy_32_32( pFreq_buf_re[k], pFreq_filt_re[k] ), pFreq_buf_im[k], pFreq_filt_im[k] ), tmp_out_re[k] ); - tmp_out_im[k] = L_add( Madd_32_32( Mpy_32_32( pFreq_buf_re[k], pFreq_filt_im[k] ), pFreq_buf_im[k], pFreq_filt_re[k] ), tmp_out_im[k] ); + tmp_out_re[k] = L_add( Msub_32_32( Mpy_32_32( pFreq_buf_re[k], pFreq_filt_re[k] ), pFreq_buf_im[k], pFreq_filt_im[k] ), tmp_out_re[k] ); // Qx + tmp_out_im[k] = L_add( Madd_32_32( Mpy_32_32( pFreq_buf_re[k], pFreq_filt_im[k] ), pFreq_buf_im[k], pFreq_filt_re[k] ), tmp_out_im[k] ); // Qx move32(); move32(); } @@ -3243,11 +3244,11 @@ static ivas_error ivas_rend_crendConvolver( #ifdef DEBUGGING dbgwrite_txt( (const float *) pOut, subframe_length << 1, "Fixed_imdft_out.txt", NULL ); #endif - pFreq_buf_re = &pcm_out[j][imult1616( i_ts, subframe_length )]; + pFreq_buf_re = &pcm_out[j][i_ts * subframe_length]; FOR( k = 0; k < subframe_length; k++ ) { - pFreq_buf_re[k] = L_add( pOut[k], hCrend->prev_out_buffer_fx[j][k] ); - hCrend->prev_out_buffer_fx[j][k] = pOut[add( k, subframe_length )]; + pFreq_buf_re[k] = L_add( pOut[k], hCrend->prev_out_buffer_fx[j][k] ); // Qx + hCrend->prev_out_buffer_fx[j][k] = pOut[k + subframe_length]; // Qx move32(); move32(); } @@ -3454,7 +3455,7 @@ ivas_error ivas_rend_crendProcess( COMBINED_ORIENTATION_HANDLE hCombinedOrientationData, IVAS_OUTPUT_SETUP_HANDLE hIntSetup, EFAP_HANDLE hEFAPdata, - Word32 *output_fx[], /* i/o: input/output audio channels */ + Word32 *output_fx[], /* i/o: input/output audio channels Qx */ const Word32 output_Fs, const Word16 num_subframes /* i : number of subframes to render */ ) @@ -3735,8 +3736,8 @@ ivas_error ivas_rend_crendProcessSubframe( const IVAS_OUTPUT_SETUP_HANDLE hIntSetup, /* i : internal setup handle */ const EFAP_HANDLE hEFAPdata, /* i : EFAP handle */ DECODER_TC_BUFFER_HANDLE hTcBuffer, /* i/o: JBM handle */ - Word32 *input_f[], /* i : transport channels */ - Word32 *output[], /* i/o: input/output audio channels */ + Word32 *input_f[], /* i : transport channels Qx */ + Word32 *output[], /* i/o: input/output audio channels Qx */ const Word16 n_samples_to_render, /* i : output frame length per channel */ const Word32 output_Fs /* i : output sampling rate */ ) @@ -3879,7 +3880,7 @@ ivas_error ivas_rend_crendProcessSubframe( { FOR( Word16 j = 0; j < n_samples_to_render; j++ ) { - output[i][j] = L_shr( output[i][j], 2 ); + output[i][j] = L_shr( output[i][j], 2 ); // Q = *pCrend->p_io_qfactor move32(); } } @@ -3887,7 +3888,7 @@ ivas_error ivas_rend_crendProcessSubframe( /* move to output */ FOR( ch = 0; ch < nchan_out; ch++ ) { - MVR2R_WORD32( pcm_tmp_fx[ch], output[ch], n_samples_to_render ); + MVR2R_WORD32( pcm_tmp_fx[ch], output[ch], n_samples_to_render ); // Qx } hTcBuffer->subframes_rendered = last_sf; diff --git a/lib_rend/ivas_limiter.c b/lib_rend/ivas_limiter.c index 458dd5a08..199c14564 100644 --- a/lib_rend/ivas_limiter.c +++ b/lib_rend/ivas_limiter.c @@ -35,6 +35,7 @@ #include #include "prot.h" #include "ivas_prot_rend.h" +#include "ivas_rom_rend.h" #include "wmc_auto.h" #include #ifdef IVAS_FLOAT_FIXED @@ -49,823 +50,6 @@ #define ATTACK_CNST_8k ( 1913946752 ) // Q31 #endif -Word32 release_cnst_table[4][201] = // Q31 - { - { - 1913946752, - 1919716352, - 1925351680, - 1930855552, - 1936230784, - 1941479808, - 1946605312, - 1951609728, - 1956495744, - 1961265792, - 1965922304, - 1970467584, - 1974904320, - 1979234560, - 1983460736, - 1987585024, - 1991609856, - 1995537280, - 1999369344, - 2003108480, - 2006756480, - 2010315520, - 2013787520, - 2017174528, - 2020478464, - 2023701248, - 2026844672, - 2029910656, - 2032900992, - 2035817344, - 2038661376, - 2041435008, - 2044139648, - 2046777088, - 2049348864, - 2051856384, - 2054301440, - 2056685312, - 2059009536, - 2061275520, - 2063484672, - 2065638272, - 2067737856, - 2069784448, - 2071779584, - 2073724416, - 2075620096, - 2077467904, - 2079268992, - 2081024512, - 2082735488, - 2084403200, - 2086028416, - 2087612544, - 2089156352, - 2090660864, - 2092127104, - 2093555968, - 2094948480, - 2096305408, - 2097627776, - 2098916352, - 2100172032, - 2101395584, - 2102587776, - 2103749504, - 2104881408, - 2105984384, - 2107059072, - 2108106112, - 2109126400, - 2110120448, - 2111088896, - 2112032512, - 2112951808, - 2113847552, - 2114720128, - 2115570304, - 2116398592, - 2117205504, - 2117991552, - 2118757504, - 2119503616, - 2120230400, - 2120938496, - 2121628288, - 2122300288, - 2122954880, - 2123592576, - 2124213760, - 2124818944, - 2125408384, - 2125982592, - 2126541952, - 2127086848, - 2127617664, - 2128134656, - 2128638336, - 2129128832, - 2129606784, - 2130072192, - 2130525568, - 2130967296, - 2131397376, - 2131816448, - 2132224640, - 2132622080, - 2133009408, - 2133386496, - 2133753856, - 2134111744, - 2134460288, - 2134799744, - 2135130368, - 2135452416, - 2135766144, - 2136071680, - 2136369152, - 2136659072, - 2136941312, - 2137216256, - 2137484160, - 2137744896, - 2137998976, - 2138246400, - 2138487424, - 2138722176, - 2138950656, - 2139173376, - 2139390208, - 2139601408, - 2139807104, - 2140007424, - 2140202624, - 2140392576, - 2140577664, - 2140758016, - 2140933504, - 2141104512, - 2141271040, - 2141433216, - 2141591168, - 2141745024, - 2141894912, - 2142040832, - 2142182912, - 2142321408, - 2142456192, - 2142587392, - 2142715264, - 2142839808, - 2142961152, - 2143079296, - 2143194240, - 2143306240, - 2143415424, - 2143521664, - 2143625216, - 2143725952, - 2143824128, - 2143919744, - 2144012800, - 2144103424, - 2144191744, - 2144277760, - 2144361472, - 2144443136, - 2144522496, - 2144599936, - 2144675200, - 2144748544, - 2144820096, - 2144889600, - 2144957440, - 2145023488, - 2145087744, - 2145150336, - 2145211264, - 2145270656, - 2145328512, - 2145384832, - 2145439616, - 2145493120, - 2145545088, - 2145595776, - 2145645056, - 2145693184, - 2145739904, - 2145785472, - 2145829888, - 2145873152, - 2145915136, - 2145956224, - 2145996032, - 2146034944, - 2146072832, - 2146109696, - 2146145664, - 2146180608, - 2146214656, - 2146247808, - }, - { - 2027355264, - 2030408704, - 2033386624, - 2036290944, - 2039123328, - 2041885440, - 2044578944, - 2047205376, - 2049766528, - 2052263680, - 2054698496, - 2057072384, - 2059387008, - 2061643520, - 2063843328, - 2065987968, - 2068078720, - 2070116864, - 2072103552, - 2074040192, - 2075927936, - 2077767936, - 2079561472, - 2081309568, - 2083013376, - 2084673920, - 2086292352, - 2087869696, - 2089406976, - 2090905216, - 2092365184, - 2093788032, - 2095174528, - 2096525824, - 2097842432, - 2099125632, - 2100375808, - 2101594240, - 2102781312, - 2103938048, - 2105065216, - 2106163456, - 2107233536, - 2108276096, - 2109292032, - 2110281728, - 2111246080, - 2112185728, - 2113101056, - 2113992960, - 2114861824, - 2115708288, - 2116532992, - 2117336448, - 2118119168, - 2118881792, - 2119624704, - 2120348416, - 2121053440, - 2121740288, - 2122409344, - 2123061120, - 2123696128, - 2124314624, - 2124917120, - 2125504128, - 2126075776, - 2126632832, - 2127175296, - 2127703808, - 2128218624, - 2128720000, - 2129208448, - 2129684352, - 2130147712, - 2130599168, - 2131038976, - 2131467264, - 2131884416, - 2132290816, - 2132686592, - 2133072256, - 2133447680, - 2133813504, - 2134169856, - 2134516864, - 2134854784, - 2135184000, - 2135504640, - 2135816960, - 2136121216, - 2136417536, - 2136706048, - 2136987136, - 2137260928, - 2137527552, - 2137787264, - 2138040192, - 2138286592, - 2138526464, - 2138760192, - 2138987776, - 2139209472, - 2139425408, - 2139635712, - 2139840512, - 2140039936, - 2140234240, - 2140423424, - 2140607744, - 2140787200, - 2140962048, - 2141132288, - 2141298048, - 2141459584, - 2141616896, - 2141769984, - 2141919232, - 2142064512, - 2142205952, - 2142343808, - 2142478080, - 2142608768, - 2142736128, - 2142860032, - 2142980864, - 2143098368, - 2143212928, - 2143324544, - 2143433088, - 2143538944, - 2143641984, - 2143742336, - 2143840000, - 2143935232, - 2144027904, - 2144118144, - 2144206080, - 2144291712, - 2144375168, - 2144456320, - 2144535424, - 2144612480, - 2144687488, - 2144760448, - 2144831616, - 2144900992, - 2144968448, - 2145034112, - 2145098112, - 2145160448, - 2145221248, - 2145280256, - 2145337856, - 2145393920, - 2145448576, - 2145501696, - 2145553536, - 2145603968, - 2145653120, - 2145700992, - 2145747456, - 2145792896, - 2145837056, - 2145880064, - 2145922048, - 2145962880, - 2146002560, - 2146041344, - 2146078976, - 2146115712, - 2146151424, - 2146186240, - 2146220160, - 2146253184, - 2146285312, - 2146316672, - 2146347136, - 2146376832, - 2146405760, - 2146433920, - 2146461440, - 2146488192, - 2146514176, - 2146539520, - 2146564224, - 2146588160, - 2146611584, - 2146634368, - 2146656640, - 2146678272, - 2146699264, - 2146719744, - 2146739712, - 2146759168, - 2146778112, - 2146796544, - 2146814464, - 2146832000, - 2146849024, - 2146865664, - }, - { - 2086555136, - 2088125824, - 2089656576, - 2091148416, - 2092602240, - 2094018944, - 2095399680, - 2096745088, - 2098056192, - 2099333888, - 2100578816, - 2101792000, - 2102974080, - 2104125824, - 2105248128, - 2106341760, - 2107407232, - 2108445440, - 2109456896, - 2110442496, - 2111402624, - 2112338176, - 2113249664, - 2114137728, - 2115002880, - 2115845760, - 2116666880, - 2117466880, - 2118246272, - 2119005568, - 2119745280, - 2120465920, - 2121167872, - 2121851776, - 2122517888, - 2123166976, - 2123799168, - 2124414976, - 2125014912, - 2125599360, - 2126168704, - 2126723200, - 2127263360, - 2127789568, - 2128302208, - 2128801408, - 2129287808, - 2129761536, - 2130222976, - 2130672512, - 2131110272, - 2131536768, - 2131952128, - 2132356736, - 2132750848, - 2133134720, - 2133508736, - 2133872896, - 2134227584, - 2134573184, - 2134909696, - 2135237504, - 2135556736, - 2135867648, - 2136170624, - 2136465536, - 2136752896, - 2137032832, - 2137305344, - 2137570816, - 2137829376, - 2138081280, - 2138326528, - 2138565504, - 2138798080, - 2139024768, - 2139245440, - 2139460480, - 2139669888, - 2139873792, - 2140072320, - 2140265856, - 2140454144, - 2140637696, - 2140816384, - 2140990464, - 2141159936, - 2141325056, - 2141485824, - 2141642368, - 2141794944, - 2141943424, - 2142088064, - 2142228992, - 2142366208, - 2142499840, - 2142630016, - 2142756736, - 2142880128, - 2143000448, - 2143117440, - 2143231488, - 2143342592, - 2143450752, - 2143556096, - 2143658624, - 2143758592, - 2143855872, - 2143950592, - 2144043008, - 2144132864, - 2144220416, - 2144305664, - 2144388608, - 2144469504, - 2144548224, - 2144624896, - 2144699648, - 2144772352, - 2144843264, - 2144912256, - 2144979328, - 2145044864, - 2145108480, - 2145170560, - 2145231104, - 2145289856, - 2145347200, - 2145403008, - 2145457408, - 2145510400, - 2145561984, - 2145612160, - 2145661056, - 2145708672, - 2145755136, - 2145800192, - 2145844224, - 2145887104, - 2145928832, - 2145969408, - 2146008960, - 2146047616, - 2146085120, - 2146121600, - 2146157184, - 2146191872, - 2146225664, - 2146258560, - 2146290560, - 2146321792, - 2146352128, - 2146381696, - 2146410496, - 2146438528, - 2146465920, - 2146492416, - 2146518400, - 2146543616, - 2146568192, - 2146592128, - 2146615424, - 2146638080, - 2146660224, - 2146681728, - 2146702720, - 2146723072, - 2146743040, - 2146762368, - 2146781184, - 2146799616, - 2146817408, - 2146834816, - 2146851840, - 2146868352, - 2146884352, - 2146900096, - 2146915328, - 2146930176, - 2146944640, - 2146958720, - 2146972416, - 2146985856, - 2146998784, - 2147011456, - 2147023872, - 2147035904, - 2147047552, - 2147058944, - 2147070080, - 2147080832, - 2147091456, - 2147101696, - 2147111680, - 2147121408, - 2147130880, - 2147140096, - 2147149056, - 2147157760, - 2147166336, - 2147174656, - }, - { - 2106670080, - 2107727232, - 2108757120, - 2109760640, - 2110738432, - 2111691008, - 2112619136, - 2113523328, - 2114404352, - 2115262592, - 2116098816, - 2116913408, - 2117707136, - 2118480256, - 2119233536, - 2119967360, - 2120682240, - 2121378688, - 2122057088, - 2122717952, - 2123361792, - 2123988992, - 2124599936, - 2125195136, - 2125774848, - 2126339584, - 2126889728, - 2127425536, - 2127947520, - 2128456064, - 2128951296, - 2129433856, - 2129903744, - 2130361600, - 2130807424, - 2131241728, - 2131664768, - 2132076928, - 2132478208, - 2132869248, - 2133250048, - 2133620992, - 2133982208, - 2134334080, - 2134676864, - 2135010688, - 2135335936, - 2135652608, - 2135961088, - 2136261504, - 2136554112, - 2136839168, - 2137116800, - 2137387136, - 2137650560, - 2137907072, - 2138156928, - 2138400256, - 2138637184, - 2138867968, - 2139092864, - 2139311744, - 2139524992, - 2139732736, - 2139934976, - 2140131968, - 2140323840, - 2140510720, - 2140692736, - 2140870016, - 2141042688, - 2141210752, - 2141374592, - 2141534080, - 2141689344, - 2141840640, - 2141987968, - 2142131456, - 2142271232, - 2142407424, - 2142539904, - 2142669056, - 2142794752, - 2142917248, - 2143036544, - 2143152640, - 2143265792, - 2143375872, - 2143483264, - 2143587712, - 2143689472, - 2143788544, - 2143885056, - 2143979136, - 2144070656, - 2144159872, - 2144246656, - 2144331264, - 2144413568, - 2144493824, - 2144571904, - 2144647936, - 2144722048, - 2144794240, - 2144864512, - 2144932864, - 2144999552, - 2145064448, - 2145127680, - 2145189248, - 2145249152, - 2145307520, - 2145364480, - 2145419776, - 2145473792, - 2145526272, - 2145577472, - 2145627264, - 2145675776, - 2145723008, - 2145768960, - 2145813760, - 2145857408, - 2145899904, - 2145941376, - 2145981696, - 2146020864, - 2146059136, - 2146096384, - 2146132608, - 2146167936, - 2146202368, - 2146235776, - 2146268416, - 2146300160, - 2146331136, - 2146361216, - 2146390528, - 2146419200, - 2146446976, - 2146474112, - 2146500480, - 2146526208, - 2146551168, - 2146575488, - 2146599296, - 2146622464, - 2146644864, - 2146666880, - 2146688128, - 2146708992, - 2146729216, - 2146748928, - 2146768128, - 2146786816, - 2146805120, - 2146822784, - 2146840064, - 2146856960, - 2146873344, - 2146889216, - 2146904832, - 2146919936, - 2146934656, - 2146948992, - 2146962944, - 2146976640, - 2146989824, - 2147002752, - 2147015296, - 2147027584, - 2147039488, - 2147051136, - 2147062400, - 2147073408, - 2147084160, - 2147094528, - 2147104768, - 2147114624, - 2147124352, - 2147133696, - 2147142912, - 2147151744, - 2147160448, - 2147168896, - 2147177088, - 2147185152, - 2147192960, - 2147200512, - 2147207936, - 2147215104, - 2147222144, - 2147229056, - 2147235712, - 2147242112, - 2147248384, - 2147254656, - 2147260544, - 2147266432, - 2147272064, - 2147277568, - }, - - - }; /*-------------------------------------------------------------------* * detect_strong_saturations() @@ -925,11 +109,11 @@ static int16_t detect_strong_saturations( } #else static Word16 detect_strong_saturations_fx( - const Word16 BER_detect, /* i : BER detect flag */ - Word16 *strong_saturation_cnt, /* i/o: counter of strong saturations */ - const Word32 max_val, /* i : maximum absolute value */ - Word32 *frame_gain, /* i/o: frame gain value */ - Word16 q_factor /* i : Q factor of the output samples */ + const Word16 BER_detect, /* i : BER detect flag */ + Word16 *strong_saturation_cnt, /* i/o: counter of strong saturations */ + const Word32 max_val, /* i : maximum absolute value q_factor */ + Word32 *frame_gain, /* i/o: frame gain value Q30 */ + Word16 q_factor /* i : Q factor of the output samples */ ) { Word16 apply_strong_limiting; @@ -937,8 +121,8 @@ static Word16 detect_strong_saturations_fx( apply_strong_limiting = 0; move16(); - compare_max_value_Mul_3 = W_shl( 98187, q_factor ); // 3 * IVAS_LIMITER_THRESHOLD - compare_max_value_Mul_10 = W_shl( 327290, q_factor ); // 10 * IVAS_LIMITER_THRESHOLD + compare_max_value_Mul_3 = W_shl( 98187, q_factor ); // 3 * IVAS_LIMITER_THRESHOLD : Q(q_factor) + compare_max_value_Mul_10 = W_shl( 327290, q_factor ); // 10 * IVAS_LIMITER_THRESHOLD : Q(q_factor) test(); IF( BER_detect ) { @@ -1035,19 +219,19 @@ ivas_error ivas_limiter_open_fx( SWITCH( sampling_rate ) { case 48000: - attack_cnst_fx = ATTACK_CNST_48k; + attack_cnst_fx = ATTACK_CNST_48k; /*Q31*/ move32(); BREAK; case 32000: - attack_cnst_fx = ATTACK_CNST_32k; + attack_cnst_fx = ATTACK_CNST_32k; /*Q31*/ move32(); BREAK; case 16000: - attack_cnst_fx = ATTACK_CNST_16k; + attack_cnst_fx = ATTACK_CNST_16k; /*Q31*/ move32(); BREAK; case 8000: - attack_cnst_fx = ATTACK_CNST_8k; + attack_cnst_fx = ATTACK_CNST_8k; /*Q31*/ move32(); BREAK; default: @@ -1164,12 +348,12 @@ void ivas_limiter_close( #ifdef IVAS_FLOAT_FIXED void ivas_limiter_dec_fx( - IVAS_LIMITER_HANDLE hLimiter, /* i/o: limiter struct handle */ - Word32 *output[MAX_OUTPUT_CHANNELS], /* i/o: input/output buffer */ - const Word16 num_channels, /* i : number of channels to be processed */ - const Word16 output_frame, /* i : number of samples per channel in the buffer */ - const Word16 BER_detect, /* i : BER detect flag */ - Word16 q_factor /* i : Q factor of the output samples */ + IVAS_LIMITER_HANDLE hLimiter, /* i/o: limiter struct handle */ + Word32 *output[MAX_OUTPUT_CHANNELS], /* i/o: input/output buffer Q : q_factor */ + const Word16 num_channels, /* i : number of channels to be processed */ + const Word16 output_frame, /* i : number of samples per channel in the buffer */ + const Word16 BER_detect, /* i : BER detect flag */ + Word16 q_factor /* i : Q factor of the output samples */ ) { Word16 c; @@ -1191,9 +375,9 @@ void ivas_limiter_dec_fx( FOR( c = 0; c < num_channels; ++c ) { - channels[c] = output[c]; + channels[c] = output[c]; /*q_factor*/ } - Word32 limiter_thresold = L_shl( IVAS_LIMITER_THRESHOLD, q_factor ); + Word32 limiter_thresold = L_shl( IVAS_LIMITER_THRESHOLD, q_factor ); /*q_factor*/ limiter_process_fx( hLimiter, output_frame, limiter_thresold, BER_detect, &hLimiter->strong_saturation_count, q_factor ); return; @@ -1243,12 +427,12 @@ void ivas_limiter_dec( #ifdef IVAS_FLOAT_FIXED void limiter_process_fx( - IVAS_LIMITER_HANDLE hLimiter, /* i/o: limiter struct handle */ - const Word16 output_frame, /* i : number of samples to be processed per channel in the I/O buffer */ - const Word32 threshold, /* i : signal amplitude above which limiting starts to be applied */ - const Word16 BER_detect, /* i : BER detect flag */ - Word16 *strong_saturation_cnt, /* i/o: counter of strong saturations (can be NULL) */ - Word16 q_factor /* i : Q factor of output samples */ + IVAS_LIMITER_HANDLE hLimiter, /* i/o: limiter struct handle */ + const Word16 output_frame, /* i : number of samples to be processed per channel in the I/O buffer */ + const Word32 threshold, /* i : signal amplitude above which limiting starts to be applied Q : q_factor */ + const Word16 BER_detect, /* i : BER detect flag */ + Word16 *strong_saturation_cnt, /* i/o: counter of strong saturations (can be NULL) */ + Word16 q_factor /* i : Q factor of output samples */ ) { Word16 i, c; @@ -1274,7 +458,7 @@ void limiter_process_fx( apply_strong_limiting = 0; move16(); - gain = hLimiter->gain_fx; + gain = hLimiter->gain_fx; /* Q30 */ move32(); output = hLimiter->channel_ptrs_fx; num_channels = hLimiter->num_channels; @@ -1296,7 +480,7 @@ void limiter_process_fx( tmp = L_abs( output[c][i] ); if ( GT_32( tmp, max_val ) ) { - max_val = tmp; + max_val = tmp; /*q_factor*/ move32(); } } @@ -1321,15 +505,15 @@ void limiter_process_fx( case 640: case 320: case 160: - releaseHeuristic_cnst = 85899345; + releaseHeuristic_cnst = 85899345; /*Q30*/ move32(); - releaseHeuristic_cnst_2 = 21474836; + releaseHeuristic_cnst_2 = 21474836; /*Q30*/ move32(); BREAK; default: - releaseHeuristic_cnst = 21474836; + releaseHeuristic_cnst = 21474836; /*Q30*/ move32(); - releaseHeuristic_cnst_2 = 5368709; + releaseHeuristic_cnst_2 = 5368709; /*Q30*/ move32(); BREAK; } @@ -1338,7 +522,7 @@ void limiter_process_fx( IF( GT_32( max_val, threshold ) ) { - frame_gain = L_shl( divide3232( threshold, max_val ), 15 ); // to q30 + frame_gain = L_shl( divide3232( threshold, max_val ), 15 ); // to Q30 releaseHeuristic = L_min( ONE_IN_Q30, L_add( releaseHeuristic, releaseHeuristic_cnst ) ); // releaseHeuristic_cnst is Q30 of ( 4.f * output_frame / sampling_rate ) // release_constant = powf( 0.01f, 1.0f / ( 0.005f * powf( 200.f, .08 ) * sampling_rate ) ); /* Unoptimized code for reference */ @@ -1365,6 +549,7 @@ void limiter_process_fx( /* No samples above threshold but gain from previous frame is not 1.f, * transition to gain == 1.f */ frame_gain = ONE_IN_Q30; + move32(); } /* Detection of very strong saturations */ IF( strong_saturation_cnt != NULL ) @@ -1376,9 +561,9 @@ void limiter_process_fx( /* Limit gain reduction to 20dB. Any peaks that require gain reduction * higher than this are most likely due to bit errors during decoding */ test(); - IF( LT_32( frame_gain, compare_value ) && !apply_strong_limiting ) + if ( LT_32( frame_gain, compare_value ) && !apply_strong_limiting ) { - frame_gain = compare_value; + frame_gain = compare_value; /*Q30*/ move32(); } @@ -1394,7 +579,8 @@ void limiter_process_fx( result = BASOP_Util_Divide3232_Scale( releaseHeuristic, div32, &scale ); idx = extract_l( Mpy_32_32( hLimiter->sampling_rate, 134218 ) ); - release_constant = release_cnst_table[idx][shr( result, sub( 15, scale ) )]; /* Q31 */ + result = shr( result, sub( 15, scale ) ); + release_constant = release_cnst_table[idx][result]; /* Q31 */ move32(); /* Unoptimized code for reference */ /* releaseTimeInSeconds = 0.005f * powf(200.f, releaseHeuristic); <-- Map heuristic value (0; 1) exponentially to range (0.005; 1) diff --git a/lib_rend/ivas_objectRenderer_mix.c b/lib_rend/ivas_objectRenderer_mix.c index 72b35aa90..ff5642344 100644 --- a/lib_rend/ivas_objectRenderer_mix.c +++ b/lib_rend/ivas_objectRenderer_mix.c @@ -51,8 +51,8 @@ #define RESAMPLE_FACTOR_32_48 ( 32.0f / 48.0f ) #ifdef IVAS_FLOAT_FIXED -#define RESAMPLE_FACTOR_16_48_FX ( 5461 ) -#define RESAMPLE_FACTOR_32_48_FX ( 10922 ) +#define RESAMPLE_FACTOR_16_48_FX ( 5461 ) // Q14 +#define RESAMPLE_FACTOR_32_48_FX ( 10922 ) // Q14 #endif @@ -73,8 +73,8 @@ static ivas_error DefaultBSplineModel_fx( TDREND_HRFILT_FiltSet_t *HrFiltSet_p, #ifdef IVAS_FLOAT_FIXED void TDREND_MIX_LIST_SetPos_fx( - BINAURAL_TD_OBJECT_RENDERER_HANDLE hBinRendererTd, /* i/o: TD renderer handle */ - const Word32 *Pos_p /* i : Listener's position */ + BINAURAL_TD_OBJECT_RENDERER_HANDLE hBinRendererTd, /* i/o: TD renderer handle */ + const Word32 *Pos_p /* i : Listener's position */ // Q Pos_fx->q_fact ) { TDREND_MIX_Listener_t *Listener_p; @@ -85,7 +85,7 @@ void TDREND_MIX_LIST_SetPos_fx( IF( NE_32( Pos_p[0], Listener_p->Pos_fx[0] ) || NE_32( Pos_p[1], Listener_p->Pos_fx[1] ) || NE_32( Pos_p[2], Listener_p->Pos_fx[2] ) ) { /* Set position */ - Copy32( Pos_p, Listener_p->Pos_fx, 3 ); + Copy32( Pos_p, Listener_p->Pos_fx, 3 ); // Q Pos_fx->q_fact /* Set pose update flag */ Listener_p->PoseUpdated = TRUE; @@ -154,9 +154,11 @@ ivas_error TDREND_MIX_LIST_SetOrient( #else ivas_error TDREND_MIX_LIST_SetOrient_fx( BINAURAL_TD_OBJECT_RENDERER_HANDLE hBinRendererTd, /* i/o: TD renderer handle */ - const Word32 *FrontVec_p_fx, /* i : Listener's orientation front vector */ - const Word32 *UpVec_p_fx, /* i : Listener's orientation up vector */ - const Word16 orient_q /* i : Listener's orientation q-factor */ + const Word32 *FrontVec_p_fx, + /* i : Listener's orientation front vector */ // orient_q + const Word32 *UpVec_p_fx, + /* i : Listener's orientation up vector */ // orient_q + const Word16 orient_q /* i : Listener's orientation q-factor */ ) { @@ -180,7 +182,7 @@ ivas_error TDREND_MIX_LIST_SetOrient_fx( List_p = hBinRendererTd->Listener_p; /* Evaluate the normalized orientation vectors and set pose update flag */ - List_p->PoseUpdated = TDREND_SPATIAL_EvalOrthonormOrient_fx( List_p->Front_fx, List_p->Up_fx, List_p->Right_fx, FrontVec_p_fx, UpVec_p_fx, orient_q ); + List_p->PoseUpdated = TDREND_SPATIAL_EvalOrthonormOrient_fx( List_p->Front_fx, List_p->Up_fx, List_p->Right_fx, FrontVec_p_fx, UpVec_p_fx, orient_q ); // Q0 move16(); return IVAS_ERR_OK; @@ -313,10 +315,10 @@ void TDREND_MIX_Dealloc( --------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED ivas_error TDREND_MIX_Init_fx( - BINAURAL_TD_OBJECT_RENDERER_HANDLE hBinRendererTd, /* i/o: TD renderer handle */ - TDREND_HRFILT_FiltSet_t **hHrtfTD, /* i/o: HRTF data (initialized in case of NULL) */ - const TDREND_MixSpatSpec_t *MixSpatSpec_p, /* i : Mixer spatial specification */ - const Word32 output_Fs /* i : Output sampling rate */ + BINAURAL_TD_OBJECT_RENDERER_HANDLE hBinRendererTd, /* i/o: TD renderer handle */ + TDREND_HRFILT_FiltSet_t **hHrtfTD, /* i/o: HRTF data (initialized in case of NULL) */ + const TDREND_MixSpatSpec_t *MixSpatSpec_p, /* i : Mixer spatial specification */ + const Word32 output_Fs /* i : Output sampling rate */ // Q0 ) { ivas_error error; @@ -326,16 +328,16 @@ ivas_error TDREND_MIX_Init_fx( /* Spatial settings */ IF( MixSpatSpec_p != NULL ) { - hBinRendererTd->UseCommonDistAttenModel = MixSpatSpec_p->UseCommonDistAttenModel; + hBinRendererTd->UseCommonDistAttenModel = MixSpatSpec_p->UseCommonDistAttenModel; // Q0 move16(); - hBinRendererTd->DistAttenModel = MixSpatSpec_p->DistAttenModel; + hBinRendererTd->DistAttenModel = MixSpatSpec_p->DistAttenModel; // Q0 move16(); } ELSE { - hBinRendererTd->UseCommonDistAttenModel = TRUE; + hBinRendererTd->UseCommonDistAttenModel = TRUE; // Q0 move16(); - hBinRendererTd->DistAttenModel = 0x0000; /* Distance attenuation not activated; */ + hBinRendererTd->DistAttenModel = 0x0000; /* Distance attenuation not activated; */ // Q0 move16(); } /* Init virtual and rendering listeners for spatial mixers */ @@ -452,15 +454,15 @@ ivas_error TDREND_MIX_SetDistAttenModel( ELSE { /* Set the common distance attenuation model */ - hBinRendererTd->DistAttenModel = DistAttenModel; + hBinRendererTd->DistAttenModel = DistAttenModel; // Q0 move32(); /* If using common distance attenuation model, set it. */ IF( hBinRendererTd->UseCommonDistAttenModel ) { - hBinRendererTd->DistAttenEnabled = TRUE; + hBinRendererTd->DistAttenEnabled = TRUE; // Q0 move16(); - hBinRendererTd->DistAttenModel = DistAttenModel; + hBinRendererTd->DistAttenModel = DistAttenModel; // Q0 move32(); } } @@ -504,8 +506,9 @@ ivas_error TDREND_MIX_SetDistAttenModel( #ifdef IVAS_FLOAT_FIXED ivas_error TDREND_MIX_AddSrc_fx( BINAURAL_TD_OBJECT_RENDERER_HANDLE hBinRendererTd, /* i/o: TD renderer handle */ - Word16 *SrcInd, /* o : Source index */ - const TDREND_PosType_t PosType /* i : Position type (absolute/relative) */ + Word16 *SrcInd, + /* o : Source index */ // Q0 + const TDREND_PosType_t PosType /* i : Position type (absolute/relative) */ ) { TDREND_SRC_t *Src_p; @@ -514,11 +517,11 @@ ivas_error TDREND_MIX_AddSrc_fx( error = IVAS_ERR_OK; move32(); /* Get unique source index */ - *SrcInd = add( hBinRendererTd->MaxSrcInd, 1 ); + *SrcInd = add( hBinRendererTd->MaxSrcInd, 1 ); // Q0 move16(); - hBinRendererTd->MaxSrcInd = add( hBinRendererTd->MaxSrcInd, 1 ); + hBinRendererTd->MaxSrcInd = add( hBinRendererTd->MaxSrcInd, 1 ); // Q0 move16(); - hBinRendererTd->NumOfSrcs = add( hBinRendererTd->NumOfSrcs, 1 ); + hBinRendererTd->NumOfSrcs = add( hBinRendererTd->NumOfSrcs, 1 ); // Q0 move16(); IF( GT_16( hBinRendererTd->NumOfSrcs, MAX_NUM_TDREND_CHANNELS ) ) @@ -545,9 +548,9 @@ ivas_error TDREND_MIX_AddSrc_fx( /* Special OpenAL initialization due to a common distance attenuation model */ IF( NE_16( hBinRendererTd->DistAttenModel, 0 ) ) { - Src_p->SrcSpatial_p->DistAttenEnabled = TRUE; + Src_p->SrcSpatial_p->DistAttenEnabled = TRUE; // Q0 move16(); - Src_p->SrcSpatial_p->DistAtten.DistAttenModel = hBinRendererTd->DistAttenModel; + Src_p->SrcSpatial_p->DistAtten.DistAttenModel = hBinRendererTd->DistAttenModel; // Q0 move32(); } /* Add source to mixer */ @@ -662,8 +665,8 @@ static ivas_error BSplineModelEvalAlloc( #ifdef IVAS_FLOAT_FIXED static ivas_error DefaultBSplineModel_fx( - TDREND_HRFILT_FiltSet_t *HrFiltSet_p, /* o : Loaded HR filter set */ - const Word32 output_Fs /* i : Output sampling rate */ + TDREND_HRFILT_FiltSet_t *HrFiltSet_p, /* o : Loaded HR filter set */ + const Word32 output_Fs /* i : Output sampling rate */ // Q0 ) { ModelParams_t *model; @@ -678,19 +681,19 @@ static ivas_error DefaultBSplineModel_fx( SWITCH( output_Fs ) { case 48000: - HrFiltSet_p->lr_energy_and_iac_fx[0] = defaultHRIR_left_avg_power_48kHz_fx; - HrFiltSet_p->lr_energy_and_iac_fx[1] = defaultHRIR_right_avg_power_48kHz_fx; - HrFiltSet_p->lr_energy_and_iac_fx[2] = defaultHRIR_coherence_48kHz_fx; + HrFiltSet_p->lr_energy_and_iac_fx[0] = defaultHRIR_left_avg_power_48kHz_fx; // Q23 + HrFiltSet_p->lr_energy_and_iac_fx[1] = defaultHRIR_right_avg_power_48kHz_fx; // Q23 + HrFiltSet_p->lr_energy_and_iac_fx[2] = defaultHRIR_coherence_48kHz_fx; // Q23 BREAK; case 32000: - HrFiltSet_p->lr_energy_and_iac_fx[0] = defaultHRIR_left_avg_power_32kHz_fx; - HrFiltSet_p->lr_energy_and_iac_fx[1] = defaultHRIR_right_avg_power_32kHz_fx; - HrFiltSet_p->lr_energy_and_iac_fx[2] = defaultHRIR_coherence_32kHz_fx; + HrFiltSet_p->lr_energy_and_iac_fx[0] = defaultHRIR_left_avg_power_32kHz_fx; // Q23 + HrFiltSet_p->lr_energy_and_iac_fx[1] = defaultHRIR_right_avg_power_32kHz_fx; // Q23 + HrFiltSet_p->lr_energy_and_iac_fx[2] = defaultHRIR_coherence_32kHz_fx; // Q23 BREAK; case 16000: - HrFiltSet_p->lr_energy_and_iac_fx[0] = defaultHRIR_left_avg_power_16kHz_fx; - HrFiltSet_p->lr_energy_and_iac_fx[1] = defaultHRIR_right_avg_power_16kHz_fx; - HrFiltSet_p->lr_energy_and_iac_fx[2] = defaultHRIR_coherence_16kHz_fx; + HrFiltSet_p->lr_energy_and_iac_fx[0] = defaultHRIR_left_avg_power_16kHz_fx; // Q23 + HrFiltSet_p->lr_energy_and_iac_fx[1] = defaultHRIR_right_avg_power_16kHz_fx; // Q23 + HrFiltSet_p->lr_energy_and_iac_fx[2] = defaultHRIR_coherence_16kHz_fx; // Q23 BREAK; } @@ -699,52 +702,52 @@ static ivas_error DefaultBSplineModel_fx( move16(); /* int16_t parameters */ - model->UseItdModel = 1; + model->UseItdModel = 1; // Q0 move16(); - model->SplineDegree = 4; + model->SplineDegree = 4; // Q0 move16(); - model->elevDim2 = 17; + model->elevDim2 = 17; // Q0 move16(); - model->elevDim3 = 15; + model->elevDim3 = 15; // Q0 move16(); - model->AlphaN = 470; + model->AlphaN = 470; // Q0 move16(); - model->num_unique_azim_splines = 1; + model->num_unique_azim_splines = 1; // Q0 move16(); - model->elevSegSamples = 4; + model->elevSegSamples = 4; // Q0 move16(); - model->elevBsLen[0] = 5; + model->elevBsLen[0] = 5; // Q0 move16(); - model->elevBsLen[1] = 9; + model->elevBsLen[1] = 9; // Q0 move16(); - model->elevBsLen[2] = 13; + model->elevBsLen[2] = 13; // Q0 move16(); - model->elevBsLen[3] = 9; + model->elevBsLen[3] = 9; // Q0 move16(); - model->elevBsStart[0] = 0; + model->elevBsStart[0] = 0; // Q0 move16(); - model->elevBsStart[1] = 5; + model->elevBsStart[1] = 5; // Q0 move16(); - model->elevBsStart[2] = 14; + model->elevBsStart[2] = 14; // Q0 move16(); - model->elevBsStart[3] = 27; + model->elevBsStart[3] = 27; // Q0 move16(); - model->azimDim2 = defaultHRIR_rom_azimDim2; - model->azimDim3 = defaultHRIR_rom_azimDim3; - model->azim_start_idx = defaultHRIR_rom_azim_start_idx; - model->azimSegSamples = defaultHRIR_rom_azimSegSamples; - model->azimShapeIdx = defaultHRIR_rom_azimShapeIdx; - model->azimShapeSampFactor = defaultHRIR_rom_azimShapeSampFactor; + model->azimDim2 = defaultHRIR_rom_azimDim2; // Q0 + model->azimDim3 = defaultHRIR_rom_azimDim3; // Q0 + model->azim_start_idx = defaultHRIR_rom_azim_start_idx; // Q0 + model->azimSegSamples = defaultHRIR_rom_azimSegSamples; // Q0 + model->azimShapeIdx = defaultHRIR_rom_azimShapeIdx; // Q0 + model->azimShapeSampFactor = defaultHRIR_rom_azimShapeSampFactor; // Q0 - model->elevKSeq_fx = defaultHRIR_rom_elevKSeq_fx; - model->elevBsShape_fx = (const Word32 *) defaultHRIR_rom_elevBsShape_fx; + model->elevKSeq_fx = defaultHRIR_rom_elevKSeq_fx; // Q22 + model->elevBsShape_fx = (const Word32 *) defaultHRIR_rom_elevBsShape_fx; // Q30 IF( ( model->azimBsShape_fx = (const Word32 **) malloc( model->num_unique_azim_splines * sizeof( Word32 * ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Binaural TD renderer\n" ) ); } - model->azimBsShape_fx[0] = defaultHRIR_rom_azimBsShape_fx; + model->azimBsShape_fx[0] = defaultHRIR_rom_azimBsShape_fx; // Q30 IF( ( model->azimKSeq_fx = (Word32 **) malloc( 18 * sizeof( Word32 * ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Binaural TD renderer\n" ) ); @@ -759,8 +762,8 @@ static ivas_error DefaultBSplineModel_fx( } model->azimKSeq_fx[0][0] = 0; model->azimKSeq_fx[model->elevDim3 - 1][0] = 0; - model->azimKSeq_fx[0][1] = 360 << Q22; - model->azimKSeq_fx[model->elevDim3 - 1][1] = 360 << Q22; + model->azimKSeq_fx[0][1] = 360 << Q22; // Q22 + model->azimKSeq_fx[model->elevDim3 - 1][1] = 360 << Q22; // Q22 move32(); move32(); move32(); @@ -774,7 +777,7 @@ static ivas_error DefaultBSplineModel_fx( } FOR( j = 0; j < model->azimDim2[i]; j++ ) { - model->azimKSeq_fx[i][j] = L_shl( L_mult0( defaultHRIR_rom_azimSegSamples[0], j ), Q22 ); + model->azimKSeq_fx[i][j] = L_shl( L_mult0( defaultHRIR_rom_azimSegSamples[0], j ), Q22 ); // Q22 move32(); } } @@ -782,65 +785,65 @@ static ivas_error DefaultBSplineModel_fx( SWITCH( output_Fs ) { case 48000: - model->AlphaL_fx = (const Word32 *) defaultHRIR_rom_AlphaL48_fx; + model->AlphaL_fx = (const Word32 *) defaultHRIR_rom_AlphaL48_fx; // Q30 model->AlphaL_e = 1; move16(); - model->AlphaR_fx = (const Word32 *) defaultHRIR_rom_AlphaR48_fx; + model->AlphaR_fx = (const Word32 *) defaultHRIR_rom_AlphaR48_fx; // Q30 model->AlphaR_e = 1; move16(); - model->EL_fx = (const Word32 *) defaultHRIR_rom_EL48_fx; + model->EL_fx = (const Word32 *) defaultHRIR_rom_EL48_fx; // Q28 model->EL_e = 3; move16(); - model->ER_fx = (const Word32 *) defaultHRIR_rom_ER48_fx; + model->ER_fx = (const Word32 *) defaultHRIR_rom_ER48_fx; // Q28 model->ER_e = 3; move16(); - model->K = 128; + model->K = 128; // Q0 move16(); IF( HrFiltSet_p->ModelParams.UseItdModel ) { - modelITD->resamp_factor_fx = ONE_IN_Q14; + modelITD->resamp_factor_fx = ONE_IN_Q14; // Q14 move16(); } BREAK; case 32000: - model->AlphaL_fx = (const Word32 *) defaultHRIR_rom_AlphaL32_fx; + model->AlphaL_fx = (const Word32 *) defaultHRIR_rom_AlphaL32_fx; // Q30 model->AlphaL_e = 1; move16(); - model->AlphaR_fx = (const Word32 *) defaultHRIR_rom_AlphaR32_fx; + model->AlphaR_fx = (const Word32 *) defaultHRIR_rom_AlphaR32_fx; // Q30 model->AlphaR_e = 1; move16(); - model->EL_fx = (const Word32 *) defaultHRIR_rom_EL32_fx; + model->EL_fx = (const Word32 *) defaultHRIR_rom_EL32_fx; // Q28 model->EL_e = 3; move16(); - model->ER_fx = (const Word32 *) defaultHRIR_rom_ER32_fx; + model->ER_fx = (const Word32 *) defaultHRIR_rom_ER32_fx; // Q28 model->ER_e = 3; move16(); - model->K = 86; + model->K = 86; // Q0 move16(); IF( HrFiltSet_p->ModelParams.UseItdModel ) { - modelITD->resamp_factor_fx = RESAMPLE_FACTOR_32_48_FX; + modelITD->resamp_factor_fx = RESAMPLE_FACTOR_32_48_FX; // Q14 move16(); } BREAK; case 16000: - model->AlphaL_fx = (const Word32 *) defaultHRIR_rom_AlphaL16_fx; + model->AlphaL_fx = (const Word32 *) defaultHRIR_rom_AlphaL16_fx; // Q30 model->AlphaL_e = 1; move16(); - model->AlphaR_fx = (const Word32 *) defaultHRIR_rom_AlphaR16_fx; + model->AlphaR_fx = (const Word32 *) defaultHRIR_rom_AlphaR16_fx; // Q30 model->AlphaR_e = 1; move16(); - model->EL_fx = (const Word32 *) defaultHRIR_rom_EL16_fx; + model->EL_fx = (const Word32 *) defaultHRIR_rom_EL16_fx; // Q28 model->EL_e = 3; move16(); - model->ER_fx = (const Word32 *) defaultHRIR_rom_ER16_fx; + model->ER_fx = (const Word32 *) defaultHRIR_rom_ER16_fx; // Q28 model->ER_e = 3; move16(); - model->K = 43; + model->K = 43; // Q0 move16(); IF( HrFiltSet_p->ModelParams.UseItdModel ) { - modelITD->resamp_factor_fx = RESAMPLE_FACTOR_16_48_FX; + modelITD->resamp_factor_fx = RESAMPLE_FACTOR_16_48_FX; // Q14 move16(); } BREAK; @@ -848,69 +851,69 @@ static ivas_error DefaultBSplineModel_fx( BREAK; } - modelITD->N = 4; + modelITD->N = 4; // Q0 move16(); - modelITD->elevDim2 = 20; + modelITD->elevDim2 = 20; // Q0 move16(); - modelITD->elevDim3 = 18; + modelITD->elevDim3 = 18; // Q0 move16(); - modelITD->azimDim2 = 41; + modelITD->azimDim2 = 41; // Q0 move16(); - modelITD->azimDim3 = 41; + modelITD->azimDim3 = 41; // Q0 move16(); - modelITD->elevSegSamples = 3; + modelITD->elevSegSamples = 3; // Q0 move16(); - modelITD->elevBsLen[0] = 4; + modelITD->elevBsLen[0] = 4; // Q0 move16(); - modelITD->elevBsLen[1] = 7; + modelITD->elevBsLen[1] = 7; // Q0 move16(); - modelITD->elevBsLen[2] = 10; + modelITD->elevBsLen[2] = 10; // Q0 move16(); - modelITD->elevBsLen[3] = 7; + modelITD->elevBsLen[3] = 7; // Q0 move16(); - modelITD->elevBsStart[0] = 0; + modelITD->elevBsStart[0] = 0; // Q0 move16(); - modelITD->elevBsStart[1] = 4; + modelITD->elevBsStart[1] = 4; // Q0 move16(); - modelITD->elevBsStart[2] = 11; + modelITD->elevBsStart[2] = 11; // Q0 move16(); - modelITD->elevBsStart[3] = 21; + modelITD->elevBsStart[3] = 21; // Q0 move16(); - modelITD->elevKSeq_fx = defaultHRIR_rom_ITD_elevKSeq_fx; + modelITD->elevKSeq_fx = defaultHRIR_rom_ITD_elevKSeq_fx; // Q22 - modelITD->azimBsLen[0] = 11; + modelITD->azimBsLen[0] = 11; // Q0 move16(); - modelITD->azimBsLen[1] = 21; + modelITD->azimBsLen[1] = 21; // Q0 move16(); - modelITD->azimBsLen[2] = 31; + modelITD->azimBsLen[2] = 31; // Q0 move16(); - modelITD->azimBsLen[3] = 21; + modelITD->azimBsLen[3] = 21; // Q0 move16(); - modelITD->azimBsStart[0] = 0; + modelITD->azimBsStart[0] = 0; // Q0 move16(); - modelITD->azimBsStart[1] = 11; + modelITD->azimBsStart[1] = 11; // Q0 move16(); - modelITD->azimBsStart[2] = 32; + modelITD->azimBsStart[2] = 32; // Q0 move16(); - modelITD->azimBsStart[3] = 63; + modelITD->azimBsStart[3] = 63; // Q0 move16(); - modelITD->azimSegSamples = 10; + modelITD->azimSegSamples = 10; // Q0 move16(); - modelITD->azimKSeq_fx = defaultHRIR_rom_ITD_azimKSeq_fx; + modelITD->azimKSeq_fx = defaultHRIR_rom_ITD_azimKSeq_fx; // Q22 modelITD->W_fx = (const Word32 *) defaultHRIR_rom_ITD_W_fx; // Q25 modelITD->W_e = 6; move16(); - modelITD->azimBsShape_fx = defaultHRIR_rom_ITD_azimBsShape_fx; - modelITD->elevBsShape_fx = defaultHRIR_rom_ITD_elevBsShape_fx; + modelITD->azimBsShape_fx = defaultHRIR_rom_ITD_azimBsShape_fx; // Q30 + modelITD->elevBsShape_fx = defaultHRIR_rom_ITD_elevBsShape_fx; // Q30 HRTF_model_precalc( model ); - HrFiltSet_p->latency_s_fx = defaultHRIR_rom_latency_s_fx; + HrFiltSet_p->latency_s_fx = defaultHRIR_rom_latency_s_fx; // Q31 move32(); - HrFiltSet_p->SampleRate = output_Fs; + HrFiltSet_p->SampleRate = output_Fs; // Q0 move32(); - HrFiltSet_p->FiltLength = HrFiltSet_p->ModelParams.K; + HrFiltSet_p->FiltLength = HrFiltSet_p->ModelParams.K; // Q0 move16(); IF( NE_32( ( error = BSplineModelEvalAlloc_fx( &HrFiltSet_p->ModelParams, &HrFiltSet_p->ModelEval ) ), IVAS_ERR_OK ) ) diff --git a/lib_rend/ivas_objectRenderer_sfx.c b/lib_rend/ivas_objectRenderer_sfx.c index cbd860f49..cc81d0d6d 100644 --- a/lib_rend/ivas_objectRenderer_sfx.c +++ b/lib_rend/ivas_objectRenderer_sfx.c @@ -168,10 +168,10 @@ void TDREND_Apply_ITD_fx( Word32 *input_fx, /* i : Input subframe to be time adjusted Qx */ Word32 *out_left_fx, /* o : Output left channel with ITD applied Qx */ Word32 *out_right_fx, /* o : Output right channel with ITD applied Qx */ - Word16 *previtd, /* i/o: Previous ITD value */ - const Word16 itd, /* i : Current subframe ITD value */ + Word16 *previtd, /* i/o: Previous ITD value Q0 */ + const Word16 itd, /* i : Current subframe ITD value Q0 */ Word32 *mem_itd_fx, /* i/o: ITD buffer memory Qx */ - const Word16 length /* i : Subframe length */ + const Word16 length /* i : Subframe length Q0 */ ) { Word16 transition_len; @@ -183,95 +183,95 @@ void TDREND_Apply_ITD_fx( Word32 *pstart1_fx; Word32 *pstart2_fx; Word32 *pstart3_fx; - Word32 buffer_fx[ITD_MEM_LEN + L_SUBFRAME5MS_48k]; + Word32 buffer_fx[ITD_MEM_LEN + L_SUBFRAME5MS_48k]; // Qx Word32 *p_input_fx; Word32 *out_buf_A_fx, *out_buf_B_fx; push_wmops( "TDREND_Apply_ITD" ); /* Prepare resampling buffer */ - Copy32( mem_itd_fx, buffer_fx, ITD_MEM_LEN ); /* Retrieve memory */ - p_input_fx = buffer_fx + ITD_MEM_LEN; /* pointer to the current subframe */ - Copy32( input_fx, p_input_fx, length ); /* input current subframe */ - Copy32( buffer_fx + length, mem_itd_fx, ITD_MEM_LEN ); /* update memory for next frame */ + Copy32( mem_itd_fx, buffer_fx, ITD_MEM_LEN ); /* Retrieve memory */ // Qx + p_input_fx = buffer_fx + ITD_MEM_LEN; /* pointer to the current subframe */ // Qx + Copy32( input_fx, p_input_fx, length ); /* input current subframe */ // Qx + Copy32( buffer_fx + length, mem_itd_fx, ITD_MEM_LEN ); /* update memory for next frame */ // Qx - currShift = abs_s( itd ); - prevShift = abs_s( *previtd ); - tlen3 = s_max( 0, sub( SFX_SPAT_BIN_SINC_M, currShift ) ); /* Make sure there is enough look-ahead for the sinc resampling */ - transition_len = sub( length, tlen3 ); + currShift = abs_s( itd ); // Q0 + prevShift = abs_s( *previtd ); // Q0 + tlen3 = s_max( 0, sub( SFX_SPAT_BIN_SINC_M, currShift ) ); /* Make sure there is enough look-ahead for the sinc resampling */ // Q0 + transition_len = sub( length, tlen3 ); // Q0 IF( i_mult( ( *previtd ), itd ) < 0 ) { /* ITD sign change - apply shift on both channels */ - Word16 tmp1 = imult1616( transition_len, prevShift ); - Word16 tmp2 = add( prevShift, currShift ); + Word16 tmp1 = imult1616( transition_len, prevShift ); // Q0 + Word16 tmp2 = add( prevShift, currShift ); // Q0 Word16 tmp_e; - Word16 tmp3 = BASOP_Util_Divide1616_Scale( tmp1, tmp2, &tmp_e ); + Word16 tmp3 = BASOP_Util_Divide1616_Scale( tmp1, tmp2, &tmp_e ); // exp(tmp_e) Word16 tmp4; - Word16 tmp_e2 = BASOP_Util_Add_MantExp( tmp3, tmp_e, ONE_IN_Q14, 0, &tmp4 ); - tmp4 = shr( tmp4, sub( 15, tmp_e2 ) ); // Q0 - tlen1 = tmp4; + Word16 tmp_e2 = BASOP_Util_Add_MantExp( tmp3, tmp_e, ONE_IN_Q14, 0, &tmp4 ); // exp(tmp4) + tmp4 = shr( tmp4, sub( 15, tmp_e2 ) ); // Q0 + tlen1 = tmp4; // Q0 move16(); - tlen2 = sub( transition_len, tlen1 ); - pstart1_fx = p_input_fx - prevShift; - length_in1 = add( tlen1, prevShift ); - pstart2_fx = pstart1_fx + length_in1; - length_in2 = sub( tlen2, currShift ); - pstart3_fx = pstart2_fx + length_in2; + tlen2 = sub( transition_len, tlen1 ); // Q0 + pstart1_fx = p_input_fx - prevShift; // Qx + length_in1 = add( tlen1, prevShift ); // Q0 + pstart2_fx = pstart1_fx + length_in1; // Qx + length_in2 = sub( tlen2, currShift ); // Q0 + pstart3_fx = pstart2_fx + length_in2; // Qx } ELSE { /* ITD sign stays the same, or one of them is zero */ - tlen1 = transition_len; + tlen1 = transition_len; // Q0 move16(); - tlen2 = 0; + tlen2 = 0; // Q0 move16(); - pstart1_fx = p_input_fx - prevShift; - length_in1 = sub( add( transition_len, prevShift ), currShift ); - pstart2_fx = pstart1_fx + length_in1; - length_in2 = 0; + pstart1_fx = p_input_fx - prevShift; // Qx + length_in1 = sub( add( transition_len, prevShift ), currShift ); // Q0 + pstart2_fx = pstart1_fx + length_in1; // Qx + length_in2 = 0; // Q0 move16(); - pstart3_fx = pstart2_fx + add( length_in2, currShift ); + pstart3_fx = pstart2_fx + add( length_in2, currShift ); // Qx } IF( *previtd == 0 ) { IF( itd > 0 ) { - out_buf_A_fx = out_right_fx; - out_buf_B_fx = out_left_fx; + out_buf_A_fx = out_right_fx; // Qx + out_buf_B_fx = out_left_fx; // Qx } ELSE { - out_buf_A_fx = out_left_fx; - out_buf_B_fx = out_right_fx; + out_buf_A_fx = out_left_fx; // Qx + out_buf_B_fx = out_right_fx; // Qx } } ELSE { IF( *previtd > 0 ) { - out_buf_A_fx = out_right_fx; - out_buf_B_fx = out_left_fx; + out_buf_A_fx = out_right_fx; // Qx + out_buf_B_fx = out_left_fx; // Qx } ELSE { - out_buf_A_fx = out_left_fx; - out_buf_B_fx = out_right_fx; + out_buf_A_fx = out_left_fx; // Qx + out_buf_B_fx = out_right_fx; // Qx } } /* Output buffer A */ sincResample_fx( pstart1_fx, out_buf_A_fx, length_in1, tlen1 ); - Copy32( pstart2_fx, out_buf_A_fx + tlen1, sub( length, tlen1 ) ); + Copy32( pstart2_fx, out_buf_A_fx + tlen1, sub( length, tlen1 ) ); // Qx /* Output buffer B */ - Copy32( p_input_fx, out_buf_B_fx, tlen1 ); + Copy32( p_input_fx, out_buf_B_fx, tlen1 ); // Qx sincResample_fx( pstart2_fx, out_buf_B_fx + tlen1, length_in2, tlen2 ); - Copy32( pstart3_fx, out_buf_B_fx + transition_len, tlen3 ); + Copy32( pstart3_fx, out_buf_B_fx + transition_len, tlen3 ); // Qx - *previtd = itd; + *previtd = itd; // Q0 move16(); pop_wmops(); @@ -355,8 +355,8 @@ static void sincResample( static void sincResample_fx( const Word32 *input_fx, /*i : Input signal Qx */ Word32 *output_fx, /*o : Output signal Qx */ - const Word16 length_in, /*i : Input length */ - const Word16 length_out /*i : Output length */ + const Word16 length_in, /*i : Input length Q0 */ + const Word16 length_out /*i : Output length Q0 */ ) { Word16 snc0; @@ -366,7 +366,7 @@ static void sincResample_fx( Word16 t_step_e; Word32 t_frac_fx; Word16 t_frac_e; - Word64 tmp64_fx; + Word64 tmp64_fx; // Qx + 32 const Word32 *p_mid_fx; const Word32 *p_forward_fx; const Word32 *p_backward_fx; @@ -374,7 +374,7 @@ static void sincResample_fx( const Word32 *p_sinc_backward_fx; // epsilon: 1e-15f - const Word32 eps = 1208925824; + const Word32 eps = 1208925824; // exp(eps_e) move32(); const Word16 eps_e = -49; move16(); @@ -386,7 +386,7 @@ static void sincResample_fx( } /* Compute fractional time step */ - t_step_fx = L_deposit_h( BASOP_Util_Divide1616_Scale( length_in, length_out, &t_step_e ) ); + t_step_fx = L_deposit_h( BASOP_Util_Divide1616_Scale( length_in, length_out, &t_step_e ) ); // exp(t_step_e) t_frac_fx = 0; move32(); t_frac_e = 0; @@ -395,42 +395,42 @@ static void sincResample_fx( FOR( i = 0; i < length_out; i++ ) { Word16 t_frac_plus_eps_e; - Word32 t_frac_plus_eps = BASOP_Util_Add_Mant32Exp( t_frac_fx, t_frac_e, eps, eps_e, &t_frac_plus_eps_e ); - t = extract_l( L_shr( t_frac_plus_eps, sub( 31, t_frac_plus_eps_e ) ) ); // Q0 + Word32 t_frac_plus_eps = BASOP_Util_Add_Mant32Exp( t_frac_fx, t_frac_e, eps, eps_e, &t_frac_plus_eps_e ); // exp(t_frac_plus_eps_e) + t = extract_l( L_shr( t_frac_plus_eps, sub( 31, t_frac_plus_eps_e ) ) ); // Q0 /* Calculate the sinc-index for the center value of the sinc */ Word32 center_val; Word16 center_val_e; - center_val = BASOP_Util_Add_Mant32Exp( t_frac_plus_eps, t_frac_plus_eps_e, L_negate( L_deposit_h( t ) ), 15, ¢er_val_e ); - center_val_e = add( center_val_e, 6 ); // center_val * SFX_SPAT_BIN_NUM_SUBSAMPLES (i.e. 64) - center_val = BASOP_Util_Add_Mant32Exp( center_val, center_val_e, ONE_IN_Q29, 1, ¢er_val_e ); - snc0 = extract_l( L_shr( center_val, sub( 31, center_val_e ) ) ); + center_val = BASOP_Util_Add_Mant32Exp( t_frac_plus_eps, t_frac_plus_eps_e, L_negate( L_deposit_h( t ) ), 15, ¢er_val_e ); // exp(center_val_e) + center_val_e = add( center_val_e, 6 ); // center_val * SFX_SPAT_BIN_NUM_SUBSAMPLES (i.e. 64) + center_val = BASOP_Util_Add_Mant32Exp( center_val, center_val_e, ONE_IN_Q29, 1, ¢er_val_e ); // exp(center_val_e) + snc0 = extract_l( L_shr( center_val, sub( 31, center_val_e ) ) ); // Q0 /* Run convolution forward and backward from mid point */ - p_mid_fx = input_fx + t; - p_forward_fx = p_mid_fx + 1; - p_backward_fx = p_mid_fx - 1; - p_sinc_forward_fx = SincTable_fx + sub( SFX_SPAT_BIN_NUM_SUBSAMPLES, snc0 ); - p_sinc_backward_fx = SincTable_fx + add( SFX_SPAT_BIN_NUM_SUBSAMPLES, snc0 ); + p_mid_fx = input_fx + t; // Qx + p_forward_fx = p_mid_fx + 1; // Qx + p_backward_fx = p_mid_fx - 1; // Qx + p_sinc_forward_fx = SincTable_fx + sub( SFX_SPAT_BIN_NUM_SUBSAMPLES, snc0 ); // Q31 + p_sinc_backward_fx = SincTable_fx + add( SFX_SPAT_BIN_NUM_SUBSAMPLES, snc0 ); // Q31 - tmp64_fx = W_mult_32_32( *p_mid_fx, SincTable_fx[snc0] ); /* Middle point */ + tmp64_fx = W_mult_32_32( *p_mid_fx, SincTable_fx[snc0] ); /* Middle point */ // Qx + 32 FOR( j = 0; j < SFX_SPAT_BIN_SINC_M - 1; j++ ) { - tmp64_fx = W_add( tmp64_fx, W_mac_32_32( W_mult_32_32( *p_forward_fx, *p_sinc_forward_fx ), *p_backward_fx, *p_sinc_backward_fx ) ); - p_sinc_forward_fx += SFX_SPAT_BIN_NUM_SUBSAMPLES; - p_sinc_backward_fx += SFX_SPAT_BIN_NUM_SUBSAMPLES; - p_forward_fx++; - p_backward_fx--; + tmp64_fx = W_add( tmp64_fx, W_mac_32_32( W_mult_32_32( *p_forward_fx, *p_sinc_forward_fx ), *p_backward_fx, *p_sinc_backward_fx ) ); // Qx + 32 + p_sinc_forward_fx += SFX_SPAT_BIN_NUM_SUBSAMPLES; // Q31 + p_sinc_backward_fx += SFX_SPAT_BIN_NUM_SUBSAMPLES; // Q31 + p_forward_fx++; // Qx + p_backward_fx--; // Qx } - tmp64_fx = W_mac_32_32( tmp64_fx, *p_forward_fx, *p_sinc_forward_fx ); /* Integer index always rounded down --> 4 steps backward, 5 steps forward */ + tmp64_fx = W_mac_32_32( tmp64_fx, *p_forward_fx, *p_sinc_forward_fx ); /* Integer index always rounded down --> 4 steps backward, 5 steps forward */ // Qx + 32 - output_fx[i] = W_extract_h( tmp64_fx ); + output_fx[i] = W_extract_h( tmp64_fx ); // Qx move32(); /* Advance fractional time */ - t_frac_fx = BASOP_Util_Add_Mant32Exp( t_frac_fx, t_frac_e, t_step_fx, t_step_e, &t_frac_e ); + t_frac_fx = BASOP_Util_Add_Mant32Exp( t_frac_fx, t_frac_e, t_step_fx, t_step_e, &t_frac_e ); // exp( t_frac_fx ) } return; @@ -501,39 +501,39 @@ void TDREND_firfilt( #else void TDREND_firfilt_fx( Word32 *signal_fx, /* i/o: Input signal / Filtered signal Qx */ - Word32 *filter_fx, /* i/o: FIR filter Qy */ - const Word16 filter_e, /* i : FIR filter exp */ - const Word32 *filter_delta_fx, /* i : FIR filter delta Qy */ - const Word16 intp_count, /* i : interpolation count */ + Word32 *filter_fx, /* i/o: FIR filter filter_e */ + const Word16 filter_e, /* i : FIR filter exp Q0 */ + const Word32 *filter_delta_fx, /* i : FIR filter delta filter_e */ + const Word16 intp_count, /* i : interpolation count Q0 */ Word32 *mem_fx, /* i/o: filter memory Qx */ - const Word16 subframe_length, /* i : Length of signal */ - const Word16 filterlength, /* i : Filter length */ + const Word16 subframe_length, /* i : Length of signal Q0 */ + const Word16 filterlength, /* i : Filter length Q0 */ const Word16 Gain_fx, /* i : Gain Q14 */ const Word16 prevGain_fx /* i : Previous gain Q14 */ ) { /* NOTE: this function is implemented with the assumption that the exponent/Q-factor of input signal will not change. */ - Word32 buffer_fx[SFX_SPAT_BIN_MAX_FILTER_LENGTH - 1 + L_SUBFRAME5MS_48k]; - Word32 *p_signal_fx; - Word32 *p_tmp_fx; - Word32 *p_filter_fx; + Word32 buffer_fx[SFX_SPAT_BIN_MAX_FILTER_LENGTH - 1 + L_SUBFRAME5MS_48k]; // Qx + Word32 *p_signal_fx; // Qx + Word32 *p_tmp_fx; // Qx + Word32 *p_filter_fx; // exp(filter_e) Word16 i, j; Word32 tmp_fx; - Word16 step_fx, gain_tmp_fx, gain_delta_fx; + Word16 step_fx /* Q15 */, gain_tmp_fx /* Q15 */, gain_delta_fx /* Q14 */; Word16 tmp_e; Word64 tmp64_fx; - gain_delta_fx = sub( Gain_fx, prevGain_fx ); // Q14 - step_fx = BASOP_Util_Divide1616_Scale( gain_delta_fx, subframe_length, &tmp_e ); + gain_delta_fx = sub( Gain_fx, prevGain_fx ); // Q14 + step_fx = BASOP_Util_Divide1616_Scale( gain_delta_fx, subframe_length, &tmp_e ); // exp(tmp_e) tmp_e = sub( tmp_e, Q14 ); step_fx = shl_sat( step_fx, tmp_e ); // Q15 gain_tmp_fx = shl_sat( prevGain_fx, 1 ); // Q15 /* Handle memory */ - p_signal_fx = buffer_fx + sub( filterlength, 1 ); - Copy32( mem_fx, buffer_fx, sub( filterlength, 1 ) ); /* Insert memory */ - Copy32( signal_fx, buffer_fx + sub( filterlength, 1 ), subframe_length ); /* Insert current frame */ - Copy32( signal_fx + add( sub( subframe_length, filterlength ), 1 ), mem_fx, sub( filterlength, 1 ) ); /* Update memory for next frame */ + p_signal_fx = buffer_fx + sub( filterlength, 1 ); // Qx + Copy32( mem_fx, buffer_fx, sub( filterlength, 1 ) ); /* Insert memory */ // Qx + Copy32( signal_fx, buffer_fx + sub( filterlength, 1 ), subframe_length ); /* Insert current frame */ // Qx + Copy32( signal_fx + add( sub( subframe_length, filterlength ), 1 ), mem_fx, sub( filterlength, 1 ) ); /* Update memory for next frame */ // Qx /* Convolution */ FOR( i = 0; i < subframe_length; i++ ) @@ -542,28 +542,28 @@ void TDREND_firfilt_fx( move64(); tmp_e = 0; move16(); - p_tmp_fx = p_signal_fx + i; - p_filter_fx = filter_fx; + p_tmp_fx = p_signal_fx + i; // Qx + p_filter_fx = filter_fx; // exp(filter_e) FOR( j = 0; j < filterlength; j++ ) { - tmp64_fx = W_mac_32_32( tmp64_fx, *p_filter_fx, *p_tmp_fx ); - p_filter_fx++; - p_tmp_fx--; + tmp64_fx = W_mac_32_32( tmp64_fx, *p_filter_fx, *p_tmp_fx ); // Qx + (Q31 - filter_e) + 1 + p_filter_fx++; // exp(filter_e) + p_tmp_fx--; // Qx } // This is done to keep the output Q same as input Q for signal - tmp64_fx = W_shl( tmp64_fx, filter_e ); - tmp_fx = W_extract_h( tmp64_fx ); + tmp64_fx = W_shl( tmp64_fx, filter_e ); // Qx + 32 + tmp_fx = W_extract_h( tmp64_fx ); // Qx /* Apply linear gain interpolation in case of abrupt gain changes */ - gain_tmp_fx = add( gain_tmp_fx, step_fx ); - signal_fx[i] = Mpy_32_16_1( tmp_fx, gain_tmp_fx ); + gain_tmp_fx = add( gain_tmp_fx, step_fx ); // Q15 + signal_fx[i] = Mpy_32_16_1( tmp_fx, gain_tmp_fx ); // Qx move32(); IF( LT_16( i, intp_count ) ) { - v_add_fx( filter_fx, filter_delta_fx, filter_fx, filterlength ); + v_add_fx( filter_fx, filter_delta_fx, filter_fx, filterlength ); // exp(filter_e) } } diff --git a/lib_rend/ivas_objectRenderer_sources.c b/lib_rend/ivas_objectRenderer_sources.c index 066e77796..c9d841915 100644 --- a/lib_rend/ivas_objectRenderer_sources.c +++ b/lib_rend/ivas_objectRenderer_sources.c @@ -72,7 +72,7 @@ static void TDREND_SRC_SPATIAL_Dealloc( TDREND_SRC_SPATIAL_t *SrcSpatial_p ); ivas_error TDREND_MIX_SRC_SetPos_fx( BINAURAL_TD_OBJECT_RENDERER_HANDLE hBinRendererTd, /* i/o: TD renderer handle */ const Word16 SrcInd, /* i : Source index */ - const Word32 *Vec_p /* i : Position vector */ + const Word32 *Vec_p /* i : Position vector Q25 */ ) { TDREND_SRC_SPATIAL_t *SrcSpatial_p; @@ -84,11 +84,11 @@ ivas_error TDREND_MIX_SRC_SetPos_fx( ELSE { SrcSpatial_p = hBinRendererTd->Sources[SrcInd]->SrcSpatial_p; - SrcSpatial_p->Pos_p_fx[0] = L_shr( SrcSpatial_p->Pos_p_fx[0], sub( SrcSpatial_p->q_Pos_p, Q25 ) ); + SrcSpatial_p->Pos_p_fx[0] = L_shr( SrcSpatial_p->Pos_p_fx[0], sub( SrcSpatial_p->q_Pos_p, Q25 ) ); // Q25 move32(); - SrcSpatial_p->Pos_p_fx[1] = L_shr( SrcSpatial_p->Pos_p_fx[1], sub( SrcSpatial_p->q_Pos_p, Q25 ) ); + SrcSpatial_p->Pos_p_fx[1] = L_shr( SrcSpatial_p->Pos_p_fx[1], sub( SrcSpatial_p->q_Pos_p, Q25 ) ); // Q25 move32(); - SrcSpatial_p->Pos_p_fx[2] = L_shr( SrcSpatial_p->Pos_p_fx[2], sub( SrcSpatial_p->q_Pos_p, Q25 ) ); + SrcSpatial_p->Pos_p_fx[2] = L_shr( SrcSpatial_p->Pos_p_fx[2], sub( SrcSpatial_p->q_Pos_p, Q25 ) ); // Q25 move32(); SrcSpatial_p->q_Pos_p = Q25; move16(); @@ -96,7 +96,7 @@ ivas_error TDREND_MIX_SRC_SetPos_fx( test(); IF( NE_32( SrcSpatial_p->Pos_p_fx[0], Vec_p[0] ) || NE_32( SrcSpatial_p->Pos_p_fx[1], Vec_p[1] ) || NE_32( SrcSpatial_p->Pos_p_fx[2], Vec_p[2] ) ) { - Copy32( Vec_p, SrcSpatial_p->Pos_p_fx, 3 ); + Copy32( Vec_p, SrcSpatial_p->Pos_p_fx, 3 ); // Q25 SrcSpatial_p->Updated = TRUE; move16(); } @@ -140,10 +140,10 @@ ivas_error TDREND_MIX_SRC_SetPos( --------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED ivas_error TDREND_MIX_SRC_SetDir_fx( - BINAURAL_TD_OBJECT_RENDERER_HANDLE hBinRendererTd, /* i/o: TD renderer handle */ - const Word16 SrcInd, /* i : Source index */ - const Word32 *Vec_p, /* i : Direction vector */ - const Word16 Vec_p_q /* i : Direction vector q */ + BINAURAL_TD_OBJECT_RENDERER_HANDLE hBinRendererTd, /* i/o: TD renderer handle */ + const Word16 SrcInd, /* i : Source index */ + const Word32 *Vec_p, /* i : Direction vector Vec_p_q */ + const Word16 Vec_p_q /* i : Direction vector q */ ) { TDREND_SRC_SPATIAL_t *SrcSpatial_p; @@ -204,8 +204,8 @@ ivas_error TDREND_MIX_SRC_SetDir( --------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED ivas_error TDREND_MIX_SRC_SetDirAtten_fx( - BINAURAL_TD_OBJECT_RENDERER_HANDLE hBinRendererTd, /* i/o: TD renderer handle */ - const Word16 SrcInd, /* i : Source index */ + BINAURAL_TD_OBJECT_RENDERER_HANDLE hBinRendererTd, /* i/o: TD renderer handle */ + const Word16 SrcInd, /* i : Source index Q0 */ const TDREND_DirAtten_t *DirAtten_p /* i : Directional attenuation specifier */ ) { @@ -253,8 +253,8 @@ ivas_error TDREND_MIX_SRC_SetDirAtten( #ifdef IVAS_FLOAT_FIXED ivas_error TDREND_MIX_SRC_SetPlayState( - BINAURAL_TD_OBJECT_RENDERER_HANDLE hBinRendererTd, /* i/o: TD renderer handle */ - const Word16 SrcInd, /* i : Source index */ + BINAURAL_TD_OBJECT_RENDERER_HANDLE hBinRendererTd, /* i/o: TD renderer handle */ + const Word16 SrcInd, /* i : Source index Q0 */ const TDREND_PlayStatus_t PlayStatus /* i : Play state */ ) { @@ -334,11 +334,11 @@ static void TDREND_SRC_REND_Init_fx( /* SrcGain */ FOR( nC = 0; nC < SPAT_BIN_MAX_INPUT_CHANNELS; nC++ ) { - SrcRend_p->SrcGainMin_p_fx[nC] = 0; /*Assuming Q15*/ + SrcRend_p->SrcGainMin_p_fx[nC] = 0; /* Q15 */ move16(); - SrcRend_p->SrcGain_p_fx[nC] = ONE_IN_Q14; + SrcRend_p->SrcGain_p_fx[nC] = ONE_IN_Q14; // Q14 move16(); - SrcRend_p->SrcGainMax_p_fx[nC] = 32767; /*Assuming Q15*/ + SrcRend_p->SrcGainMax_p_fx[nC] = 32767; /* Q15 */ move16(); } SrcRend_p->SrcGainUpdated = FALSE; @@ -346,9 +346,9 @@ static void TDREND_SRC_REND_Init_fx( /* Init directional and distance gains */ FOR( nC = 0; nC < SPAT_BIN_MAX_INPUT_CHANNELS; nC++ ) { - SrcRend_p->DirGain_p_fx[nC] = ONE_IN_Q14; + SrcRend_p->DirGain_p_fx[nC] = ONE_IN_Q14; // Q14 move16(); - SrcRend_p->DistGain_p_fx[nC] = ONE_IN_Q14; + SrcRend_p->DistGain_p_fx[nC] = ONE_IN_Q14; // Q14 move16(); } return; @@ -520,19 +520,31 @@ void TDREND_SRC_REND_UpdateFiltersFromSpatialParams_fx( BINAURAL_TD_OBJECT_RENDERER_HANDLE hBinRendererTd, /* i/o: TD renderer handle */ TDREND_SRC_REND_t *SrcRend_p, /* i/o: Source object */ TDREND_SRC_SPATIAL_t *SrcSpatial_p, /* i : Spatial aspects of source */ - Word32 *hrf_left_prev, /* i/o: Left filter */ - Word16 *hrf_left_prev_e, /* i/o: Left filter exponent */ - Word32 *hrf_right_prev, /* i/o: Right filter */ - Word16 *hrf_right_prev_e, /* i/o: Right filter exponent */ - Word32 *hrf_left_delta, /* o : Left filter interpolation delta */ - Word16 *hrf_left_delta_e, /* o : Left filter interpolation delta exponent */ - Word32 *hrf_right_delta, /* o : Right filter interpolation delta */ - Word16 *hrf_right_delta_e, /* o : Right filter interpolation delta exponent */ - Word16 *intp_count, /* o : Interpolation count */ - Word16 *filterlength, /* o : Length of filters */ - Word16 *itd, /* o : ITD value */ - Word16 *Gain, /* o : Gain value */ - TDREND_SRC_t *Src_p, /* i/o: Source pointer */ + Word32 *hrf_left_prev, + /* i/o: Left filter */ // exp(hrf_left_prev_e) + Word16 *hrf_left_prev_e, + /* i/o: Left filter exponent */ // Q0 + Word32 *hrf_right_prev, + /* i/o: Right filter */ // exp(hrf_right_prev_e) + Word16 *hrf_right_prev_e, + /* i/o: Right filter exponent */ // Q0 + Word32 *hrf_left_delta, + /* o : Left filter interpolation delta */ // exp(hrf_left_delta_e) + Word16 *hrf_left_delta_e, + /* o : Left filter interpolation delta exponent */ // Q0 + Word32 *hrf_right_delta, + /* o : Right filter interpolation delta */ // exp(hrf_right_delta_e) + Word16 *hrf_right_delta_e, + /* o : Right filter interpolation delta exponent */ // Q0 + Word16 *intp_count, + /* o : Interpolation count */ // Q0 + Word16 *filterlength, + /* o : Length of filters */ // Q0 + Word16 *itd, + /* o : ITD value */ // Q0 + Word16 *Gain, + /* o : Gain value */ // Q14 + TDREND_SRC_t *Src_p, /* i/o: Source pointer */ const Word16 subframe_update_flag ) { TDREND_MIX_Listener_t *Listener_p; @@ -552,7 +564,7 @@ void TDREND_SRC_REND_UpdateFiltersFromSpatialParams_fx( Listener_p = hBinRendererTd->Listener_p; HrFiltSet_p = hBinRendererTd->HrFiltSet_p; - *filterlength = s_min( HrFiltSet_p->FiltLength, SFX_SPAT_BIN_MAX_FILTER_LENGTH ); + *filterlength = s_min( HrFiltSet_p->FiltLength, SFX_SPAT_BIN_MAX_FILTER_LENGTH ); // Q0 move16(); IF( EQ_16( SrcSpatial_p->PosType, TDREND_POSTYPE_ABSOLUTE ) ) { @@ -575,16 +587,16 @@ void TDREND_SRC_REND_UpdateFiltersFromSpatialParams_fx( } ELSE { - Word32 tmp1 = Mpy_32_32( ListRelPos[0], ListRelPos[0] ); - Word32 tmp2 = Mpy_32_32( ListRelPos[1], ListRelPos[1] ); - Word32 tmp3 = L_add( tmp1, tmp2 ); + Word32 tmp1 = Mpy_32_32( ListRelPos[0], ListRelPos[0] ); // exp(2*ListRelPos_e) + Word32 tmp2 = Mpy_32_32( ListRelPos[1], ListRelPos[1] ); // exp(2*ListRelPos_e) + Word32 tmp3 = L_add( tmp1, tmp2 ); // exp(2*ListRelPos_e) Word16 tmp_e = shl( ListRelPos_e, 1 ); - Word32 tmp4 = Sqrt32( tmp3, &tmp_e ); - Word16 tmp5 = BASOP_util_atan2( ListRelPos[2], tmp4, sub( ListRelPos_e, tmp_e ) ); - Word32 tmp6 = Mpy_32_16_1( _180_OVER_PI_Q25, tmp5 ); // Q25 + Q13 - Q15 = Q23 + Word32 tmp4 = Sqrt32( tmp3, &tmp_e ); // exp(tmp_e) + Word16 tmp5 = BASOP_util_atan2( ListRelPos[2], tmp4, sub( ListRelPos_e, tmp_e ) ); // Q13 + Word32 tmp6 = Mpy_32_16_1( _180_OVER_PI_Q25, tmp5 ); // Q25 + Q13 - Q15 = Q23 /* Basis set is [front, right, up], which is a left-handed coordinate system. Minus sign here is to change to a positive-left system for azimuth */ - Word16 tmp7 = BASOP_util_atan2( ListRelPos[1], ListRelPos[0], 0 ); - Word32 tmp8 = L_negate( Mpy_32_16_1( _180_OVER_PI_Q25, tmp7 ) ); // Q25 + Q13 - Q15 = Q23 + Word16 tmp7 = BASOP_util_atan2( ListRelPos[1], ListRelPos[0], 0 ); // Q13 + Word32 tmp8 = L_negate( Mpy_32_16_1( _180_OVER_PI_Q25, tmp7 ) ); // Q25 + Q13 - Q15 = Q23 Elev = L_shr( tmp6, 1 ); // Q22 Azim = L_shr( tmp8, 1 ); // Q22 @@ -594,7 +606,7 @@ void TDREND_SRC_REND_UpdateFiltersFromSpatialParams_fx( /* 6. Evaluate the directional and distance gains */ /* Directional gain */ - *SrcRend_p->DirGain_p_fx = ONE_IN_Q14; + *SrcRend_p->DirGain_p_fx = ONE_IN_Q14; // Q14 move16(); IF( SrcSpatial_p->DirAttenEnabled ) { @@ -602,7 +614,7 @@ void TDREND_SRC_REND_UpdateFiltersFromSpatialParams_fx( } /* Distance gain */ - *SrcRend_p->DistGain_p_fx = ONE_IN_Q14; + *SrcRend_p->DistGain_p_fx = ONE_IN_Q14; // Q14 move16(); IF( hBinRendererTd->UseCommonDistAttenModel ) { @@ -610,69 +622,69 @@ void TDREND_SRC_REND_UpdateFiltersFromSpatialParams_fx( { SrcSpatial_p->DistAtten.DistAttenModel = hBinRendererTd->DistAttenModel; move32(); - *SrcRend_p->DistGain_p_fx = TDREND_SRC_SPATIAL_GetDistGain_fx( &SrcSpatial_p->DistAtten, ListRelDist, ListRelDist_e ); + *SrcRend_p->DistGain_p_fx = TDREND_SRC_SPATIAL_GetDistGain_fx( &SrcSpatial_p->DistAtten, ListRelDist, ListRelDist_e ); // Q14 move32(); } } ELSE IF( SrcSpatial_p->DistAttenEnabled ) { - *SrcRend_p->DistGain_p_fx = TDREND_SRC_SPATIAL_GetDistGain_fx( &SrcSpatial_p->DistAtten, ListRelDist, ListRelDist_e ); + *SrcRend_p->DistGain_p_fx = TDREND_SRC_SPATIAL_GetDistGain_fx( &SrcSpatial_p->DistAtten, ListRelDist, ListRelDist_e ); // Q14 move32(); } /* Update total gains */ - *Gain = extract_h( L_shl( Mpy_32_32( L_shl( L_mult( *SrcRend_p->SrcGain_p_fx, *SrcRend_p->DirGain_p_fx ), 1 ), L_shl( L_mult( *SrcRend_p->DistGain_p_fx, hBinRendererTd->Gain_fx ), 1 ) ), 1 ) ); + *Gain = extract_h( L_shl( Mpy_32_32( L_shl( L_mult( *SrcRend_p->SrcGain_p_fx, *SrcRend_p->DirGain_p_fx ), 1 ), L_shl( L_mult( *SrcRend_p->DistGain_p_fx, hBinRendererTd->Gain_fx ), 1 ) ), 1 ) ); // Q14 move16(); /* Delta for interpolation, in case the angular step exceeds MAX_ANGULAR_STEP */ - Word32 ele_tmp = Src_p->elev_prev_fx; + Word32 ele_tmp = Src_p->elev_prev_fx; // Q22 move32(); IF( GT_32( ele_tmp, DEG_180_IN_Q22 ) ) { - ele_tmp = L_sub( ele_tmp, DEG_360_IN_Q22 ); + ele_tmp = L_sub( ele_tmp, DEG_360_IN_Q22 ); // Q22 } ELSE IF( LT_32( ele_tmp, -DEG_180_IN_Q22 ) ) { - ele_tmp = L_add( ele_tmp, DEG_360_IN_Q22 ); + ele_tmp = L_add( ele_tmp, DEG_360_IN_Q22 ); // Q22 } - elev_delta = L_sub( Elev, ele_tmp ); + elev_delta = L_sub( Elev, ele_tmp ); // Q22 - Word32 azi_tmp = Src_p->azim_prev_fx; + Word32 azi_tmp = Src_p->azim_prev_fx; // Q22 IF( GT_32( azi_tmp, DEG_180_IN_Q22 ) ) { - azi_tmp = L_sub( azi_tmp, DEG_360_IN_Q22 ); + azi_tmp = L_sub( azi_tmp, DEG_360_IN_Q22 ); // Q22 } ELSE IF( LT_32( azi_tmp, -DEG_180_IN_Q22 ) ) { - azi_tmp = L_add( azi_tmp, DEG_360_IN_Q22 ); + azi_tmp = L_add( azi_tmp, DEG_360_IN_Q22 ); // Q22 } - azim_delta = L_sub( Azim, azi_tmp ); + azim_delta = L_sub( Azim, azi_tmp ); // Q22 - Src_p->elev_prev_fx = Elev; + Src_p->elev_prev_fx = Elev; // Q22 move32(); - Src_p->azim_prev_fx = Azim; + Src_p->azim_prev_fx = Azim; // Q22 move32(); /* map to -180:180 range */ IF( GT_32( azim_delta, DEG_180_IN_Q22 ) ) { - azim_delta = L_sub( azim_delta, DEG_360_IN_Q22 ); + azim_delta = L_sub( azim_delta, DEG_360_IN_Q22 ); // Q22 } ELSE IF( LT_32( azim_delta, -DEG_180_IN_Q22 ) ) { - azim_delta = L_add( azim_delta, DEG_360_IN_Q22 ); + azim_delta = L_add( azim_delta, DEG_360_IN_Q22 ); // Q22 } Word16 tmp1 = extract_l( Mpy_32_32( L_abs( azim_delta ), 100 << Q9 ) ); // Q22 + Q9 - Q31 = Q0 Word16 tmp2 = extract_l( Mpy_32_32( L_abs( elev_delta ), 100 << Q9 ) ); // Q22 + Q9 - Q31 = Q0 - *intp_count = s_min( MAX_INTERPOLATION_STEPS, s_max( tmp1, tmp2 ) ); + *intp_count = s_min( MAX_INTERPOLATION_STEPS, s_max( tmp1, tmp2 ) ); // Q0 move16(); } ELSE /* TDREND_POSTYPE_NON_DIEGETIC */ { - *itd = 0; + *itd = 0; // Q0 move16(); - *Gain = ONE_IN_Q14; + *Gain = ONE_IN_Q14; // Q14 move16(); set32_fx( hrf_left, 0, *filterlength ); set32_fx( hrf_right, 0, *filterlength ); @@ -684,11 +696,11 @@ void TDREND_SRC_REND_UpdateFiltersFromSpatialParams_fx( move16(); hrf_right_e = 6; move16(); - *intp_count = MAX_INTERPOLATION_STEPS; + *intp_count = MAX_INTERPOLATION_STEPS; // Q22 move16(); - Src_p->elev_prev_fx = 0; + Src_p->elev_prev_fx = 0; // Q22 move16(); - Src_p->azim_prev_fx = DEG_360_IN_Q22; /* Dummy angle -- sets max interpolation if switching to TDREND_POSTYPE_ABSOLUTE */ + Src_p->azim_prev_fx = DEG_360_IN_Q22; /* Dummy angle -- sets max interpolation if switching to TDREND_POSTYPE_ABSOLUTE */ // Q22 move16(); } @@ -700,47 +712,47 @@ void TDREND_SRC_REND_UpdateFiltersFromSpatialParams_fx( tmp_e = s_max( *hrf_left_prev_e, hrf_left_e ); FOR( Word16 i = 0; i < *filterlength; i++ ) { - hrf_left[i] = L_shr( hrf_left[i], sub( tmp_e, hrf_left_e ) ); + hrf_left[i] = L_shr( hrf_left[i], sub( tmp_e, hrf_left_e ) ); // exp(tmp_e) move32(); - hrf_left_prev[i] = L_shr( hrf_left_prev[i], sub( tmp_e, *hrf_left_prev_e ) ); + hrf_left_prev[i] = L_shr( hrf_left_prev[i], sub( tmp_e, *hrf_left_prev_e ) ); // exp(tmp_e) move32(); } *hrf_left_prev_e = tmp_e; move16(); hrf_left_e = tmp_e; move16(); - v_sub_32( hrf_left, hrf_left_prev, hrf_left_delta, *filterlength ); + v_sub_32( hrf_left, hrf_left_prev, hrf_left_delta, *filterlength ); // exp(tmp_e) *hrf_left_delta_e = tmp_e; move16(); - Word32 fac = L_deposit_h( div_s( 1, *intp_count ) ); - v_multc_fixed( hrf_left_delta, fac, hrf_left_delta, *filterlength ); + Word32 fac = L_deposit_h( div_s( 1, *intp_count ) ); // Q15 + v_multc_fixed( hrf_left_delta, fac, hrf_left_delta, *filterlength ); // exp(hrf_left_delta_e) tmp_e = s_max( *hrf_right_prev_e, hrf_right_e ); FOR( Word16 i = 0; i < *filterlength; i++ ) { - hrf_right[i] = L_shr( hrf_right[i], sub( tmp_e, hrf_right_e ) ); + hrf_right[i] = L_shr( hrf_right[i], sub( tmp_e, hrf_right_e ) ); // exp(tmp_e) move32(); - hrf_right_prev[i] = L_shr( hrf_right_prev[i], sub( tmp_e, *hrf_right_prev_e ) ); + hrf_right_prev[i] = L_shr( hrf_right_prev[i], sub( tmp_e, *hrf_right_prev_e ) ); // exp(tmp_e) move32(); } *hrf_right_prev_e = tmp_e; move16(); hrf_right_e = tmp_e; move16(); - v_sub_32( hrf_right, hrf_right_prev, hrf_right_delta, *filterlength ); + v_sub_32( hrf_right, hrf_right_prev, hrf_right_delta, *filterlength ); // exp(hrf_right_delta_e) *hrf_right_delta_e = tmp_e; move16(); - v_multc_fixed( hrf_right_delta, fac, hrf_right_delta, *filterlength ); + v_multc_fixed( hrf_right_delta, fac, hrf_right_delta, *filterlength ); // exp(hrf_right_delta_e) } ELSE { /* No interpolation, just set the new filters and reset deltas */ - Copy32( hrf_left, hrf_left_prev, *filterlength ); + Copy32( hrf_left, hrf_left_prev, *filterlength ); // exp(hrf_left_prev_e) *hrf_left_prev_e = hrf_left_e; move16(); - Copy32( hrf_right, hrf_right_prev, *filterlength ); + Copy32( hrf_right, hrf_right_prev, *filterlength ); // exp(hrf_right_prev_e) *hrf_right_prev_e = hrf_right_e; move16(); set32_fx( hrf_left_delta, 0, *filterlength ); @@ -830,7 +842,7 @@ static void TDREND_SRC_SPATIAL_Init_fx( const TDREND_PosType_t PosType /* i : Relative/absolute position type */ ) { - Word16 nC; + Word16 nC; // Q0 /* Initialize variables */ SrcSpatial_p->Updated = FALSE; @@ -854,25 +866,25 @@ static void TDREND_SRC_SPATIAL_Init_fx( #endif /* Source directional attenuation */ - SrcSpatial_p->DirAttenEnabled = FALSE; + SrcSpatial_p->DirAttenEnabled = FALSE; // Q0 move16(); - SrcSpatial_p->DirAtten.ConeInnerAngle_fx = DEG_360_IN_Q22; + SrcSpatial_p->DirAtten.ConeInnerAngle_fx = DEG_360_IN_Q22; // Q22 move32(); - SrcSpatial_p->DirAtten.ConeOuterAngle_fx = DEG_360_IN_Q22; + SrcSpatial_p->DirAtten.ConeOuterAngle_fx = DEG_360_IN_Q22; // Q22 move32(); - SrcSpatial_p->DirAtten.ConeOuterGain_fx = ONE_IN_Q30; + SrcSpatial_p->DirAtten.ConeOuterGain_fx = ONE_IN_Q30; // Q30 move16(); /* Source distance attenuation */ - SrcSpatial_p->DistAttenEnabled = FALSE; + SrcSpatial_p->DistAttenEnabled = FALSE; // Q0 move16(); - SrcSpatial_p->DistAtten.DistAttenModel = TDREND_DIST_ATTEN_MODEL_INV_DIST_CLAMPED; + SrcSpatial_p->DistAtten.DistAttenModel = TDREND_DIST_ATTEN_MODEL_INV_DIST_CLAMPED; // Q0 move16(); - SrcSpatial_p->DistAtten.RefDist_fx = ONE_IN_Q30; + SrcSpatial_p->DistAtten.RefDist_fx = ONE_IN_Q30; // Q30 move32(); SrcSpatial_p->DistAtten.MaxDist_fx = 2113929216; /* Maximum radius (2^ISM_RADIUS_NBITS-1)*0.25 */ /*15.75 in Q27*/ move32(); - SrcSpatial_p->DistAtten.RollOffFactor_fx = ONE_IN_Q30; + SrcSpatial_p->DistAtten.RollOffFactor_fx = ONE_IN_Q30; // Q30 move16(); return; @@ -928,10 +940,10 @@ static void TDREND_SRC_SPATIAL_SetDirAtten_fx( ) { /* Set directional attenuation */ - SrcSpatial_p->DirAttenEnabled = TRUE; - SrcSpatial_p->DirAtten.ConeInnerAngle_fx = DirAtten_p->ConeInnerAngle_fx; - SrcSpatial_p->DirAtten.ConeOuterAngle_fx = DirAtten_p->ConeOuterAngle_fx; - SrcSpatial_p->DirAtten.ConeOuterGain_fx = DirAtten_p->ConeOuterGain_fx; + SrcSpatial_p->DirAttenEnabled = TRUE; // Q0 + SrcSpatial_p->DirAtten.ConeInnerAngle_fx = DirAtten_p->ConeInnerAngle_fx; // Q22 + SrcSpatial_p->DirAtten.ConeOuterAngle_fx = DirAtten_p->ConeOuterAngle_fx; // Q22 + SrcSpatial_p->DirAtten.ConeOuterGain_fx = DirAtten_p->ConeOuterGain_fx; // Q30 move16(); move16(); move16(); @@ -1008,9 +1020,9 @@ static float TDREND_SRC_SPATIAL_GetDirGain( #else static Word16 TDREND_SRC_SPATIAL_GetDirGain_fx( /* o : Directional Gain Output Q14 */ const TDREND_DirAtten_t *DirAtten_p, /* i : Directional attenuation specification */ - const Word32 *Front_p_fx, /* i : Front-pointing vector */ + const Word32 *Front_p_fx, /* i : Front-pointing vector Q30 */ const Word32 *RelPos_p_fx, /* i : Relative position */ - const Word16 RelPos_p_e /* i : Relative position exp */ + const Word16 RelPos_p_e /* i : Relative position exp RelPos_p_e */ ) { Word16 DirGain_fx; // Q14 @@ -1028,12 +1040,12 @@ static Word16 TDREND_SRC_SPATIAL_GetDirGain_fx( /* Angle = acos ( Proj coeff from projecting -RelPos onto Front / norm(RelPos) ); */ FOR( Word16 i = 0; i < 3; i++ ) { - Vec_fx[i] = L_negate( RelPos_p_fx[i] ); + Vec_fx[i] = L_negate( RelPos_p_fx[i] ); // exp(RelPos_p_e) move32(); } ProjCoef_fx = dotp_fixed( Vec_fx, Front_p_fx, 3 ); // exp: RelPos_p_e + 1 ProjCoef_e = add( RelPos_p_e, 1 ); - NormRelPos_fx = TDREND_SPATIAL_VecNorm_fx( RelPos_p_fx, RelPos_p_e, &NormRelPos_e ); + NormRelPos_fx = TDREND_SPATIAL_VecNorm_fx( RelPos_p_fx, RelPos_p_e, &NormRelPos_e ); // exp(NormRelPos_e) IF( NormRelPos_fx != 0 ) { @@ -1043,15 +1055,15 @@ static Word16 TDREND_SRC_SPATIAL_GetDirGain_fx( Word32 tmp1, tmp2, tmp3, tmp4; // acos(x/y) = atan( sqrt(1-(x/y)^2) / (x/y) ) - tmp1 = L_deposit_h( BASOP_Util_Divide3232_Scale( ProjCoef_fx, NormRelPos_fx, &tmp_e1 ) ); // x/y + tmp1 = L_deposit_h( BASOP_Util_Divide3232_Scale( ProjCoef_fx, NormRelPos_fx, &tmp_e1 ) ); // x/y /* exp(tmp_e1) */ tmp_e1 = add( tmp_e1, sub( ProjCoef_e, NormRelPos_e ) ); - tmp2 = Mpy_32_32( tmp1, tmp1 ); // (x/y)^2 + tmp2 = Mpy_32_32( tmp1, tmp1 ); // (x/y)^2 /* exp(tmp_e2 */ tmp_e2 = shl( tmp_e1, 1 ); - tmp3 = BASOP_Util_Add_Mant32Exp( ONE_IN_Q30, 1, L_negate( tmp2 ), tmp_e2, &tmp_e3 ); // 1 - (x/y)^2 + tmp3 = BASOP_Util_Add_Mant32Exp( ONE_IN_Q30, 1, L_negate( tmp2 ), tmp_e2, &tmp_e3 ); // 1 - (x/y)^2 /* exp(tmp_e3) */ tmp_e4 = tmp_e3; move16(); tmp3 = L_abs( tmp3 ); // for safety: sometimes it can go negative due to slight precision difference between numerator and denominator. - tmp4 = Sqrt32( tmp3, &tmp_e4 ); // sqrt(1 - (x/y)^2) + tmp4 = Sqrt32( tmp3, &tmp_e4 ); // sqrt(1 - (x/y)^2) /* exp(tmp_e4) */ acosfx = BASOP_util_atan2( tmp4, tmp1, sub( tmp_e4, tmp_e1 ) ); // 2Q13 AngleDeg_fx = L_shr( Mpy_32_16_1( _180_OVER_PI_Q25, acosfx ), 1 ); // Q22 } @@ -1063,21 +1075,21 @@ static Word16 TDREND_SRC_SPATIAL_GetDirGain_fx( IF( LE_32( AngleDeg_fx, L_shr( DirAtten_p->ConeInnerAngle_fx, 1 ) ) ) { - DirGain_fx = ONE_IN_Q14; + DirGain_fx = ONE_IN_Q14; // Q14 move16(); } ELSE IF( LE_32( AngleDeg_fx, L_shr( DirAtten_p->ConeOuterAngle_fx, 1 ) ) ) { // DirGain = 1.0f - ( 2.0f * AngleDeg - DirAtten_p->ConeInnerAngle ) / ( DirAtten_p->ConeOuterAngle - DirAtten_p->ConeInnerAngle ) * ( 1.0f - DirAtten_p->ConeOuterGain ); Word32 tmp1, tmp2, tmp3; - tmp1 = L_sub( ONE_IN_Q30, DirAtten_p->ConeOuterGain_fx ); - tmp2 = L_sub( DirAtten_p->ConeOuterAngle_fx, DirAtten_p->ConeInnerAngle_fx ); - tmp3 = L_sub( L_shl( AngleDeg_fx, 1 ), DirAtten_p->ConeInnerAngle_fx ); - DirGain_fx = sub( ONE_IN_Q14, div_l( Mpy_32_32( tmp1, tmp3 ), extract_h( tmp2 ) ) ); + tmp1 = L_sub( ONE_IN_Q30, DirAtten_p->ConeOuterGain_fx ); // Q30 + tmp2 = L_sub( DirAtten_p->ConeOuterAngle_fx, DirAtten_p->ConeInnerAngle_fx ); // Q22 + tmp3 = L_sub( L_shl( AngleDeg_fx, 1 ) /* 2.0f * AngleDeg */, DirAtten_p->ConeInnerAngle_fx ); // Q22 + DirGain_fx = sub( ONE_IN_Q14, div_l( Mpy_32_32( tmp1, tmp3 ), extract_h( tmp2 ) ) ); // Q14 } ELSE { - DirGain_fx = extract_h( DirAtten_p->ConeOuterGain_fx ); + DirGain_fx = extract_h( DirAtten_p->ConeOuterGain_fx ); // Q14 } return DirGain_fx; @@ -1131,11 +1143,11 @@ static float TDREND_SRC_SPATIAL_GetDistGain( #else static Word16 TDREND_SRC_SPATIAL_GetDistGain_fx( /* o : Distance gain Q14 */ const TDREND_DistAtten_t *DistAtten_p, /* i : Distance attenuation parameters */ - const Word32 Dist_fx, /* i : Distance value */ + const Word32 Dist_fx, /* i : Distance value Dist_e */ const Word16 Dist_e /* i : Distance value exp */ ) { - Word16 DistGain_fx; + Word16 DistGain_fx; // Q14 Word32 Dist2_fx; Word16 Dist2_e; Word16 tmp_e; @@ -1143,7 +1155,7 @@ static Word16 TDREND_SRC_SPATIAL_GetDistGain_fx( Word32 tmp32; Word16 flag; - DistGain_fx = ONE_IN_Q14; + DistGain_fx = ONE_IN_Q14; // Q14 move16(); DistGain_e = 1; move16(); @@ -1158,7 +1170,7 @@ static Word16 TDREND_SRC_SPATIAL_GetDistGain_fx( tmp32 = BASOP_Util_Add_Mant32Exp( Dist2_fx, Dist2_e, L_negate( DistAtten_p->RefDist_fx ), 1, &tmp_e ); // exp: tmp_e tmp32 = Mpy_32_32( tmp32, DistAtten_p->RollOffFactor_fx ); // exp: 1 + tmp_e tmp32 = BASOP_Util_Add_Mant32Exp( DistAtten_p->RefDist_fx, 1, tmp32, add( 1, tmp_e ), &tmp_e ); // exp: tmp_e - DistGain_fx = BASOP_Util_Divide3232_Scale( DistAtten_p->RefDist_fx, tmp32, &DistGain_e ); + DistGain_fx = BASOP_Util_Divide3232_Scale( DistAtten_p->RefDist_fx, tmp32, &DistGain_e ); // exp: DistGain_e DistGain_e = add( DistGain_e, sub( 1, tmp_e ) ); BREAK; @@ -1166,7 +1178,7 @@ static Word16 TDREND_SRC_SPATIAL_GetDistGain_fx( flag = BASOP_Util_Cmp_Mant32Exp( Dist2_fx, Dist2_e, DistAtten_p->RefDist_fx, 1 ); IF( flag < 0 ) { - Dist2_fx = DistAtten_p->RefDist_fx; + Dist2_fx = DistAtten_p->RefDist_fx; // Q30 move32(); Dist2_e = 1; move16(); @@ -1174,7 +1186,7 @@ static Word16 TDREND_SRC_SPATIAL_GetDistGain_fx( flag = BASOP_Util_Cmp_Mant32Exp( Dist2_fx, Dist2_e, DistAtten_p->MaxDist_fx, 4 ); IF( flag > 0 ) { - Dist2_fx = DistAtten_p->MaxDist_fx; + Dist2_fx = DistAtten_p->MaxDist_fx; // Q27 move32(); Dist2_e = 4; move16(); @@ -1182,7 +1194,7 @@ static Word16 TDREND_SRC_SPATIAL_GetDistGain_fx( tmp32 = BASOP_Util_Add_Mant32Exp( Dist2_fx, Dist2_e, L_negate( DistAtten_p->RefDist_fx ), 1, &tmp_e ); // exp: tmp_e tmp32 = Mpy_32_32( tmp32, DistAtten_p->RollOffFactor_fx ); // exp: 1 + tmp_e tmp32 = BASOP_Util_Add_Mant32Exp( DistAtten_p->RefDist_fx, 1, tmp32, add( 1, tmp_e ), &tmp_e ); // exp: tmp_e - DistGain_fx = BASOP_Util_Divide3232_Scale( DistAtten_p->RefDist_fx, tmp32, &DistGain_e ); + DistGain_fx = BASOP_Util_Divide3232_Scale( DistAtten_p->RefDist_fx, tmp32, &DistGain_e ); // exp: DistGain_e DistGain_e = add( DistGain_e, sub( 1, tmp_e ) ); BREAK; @@ -1339,11 +1351,11 @@ void TDREND_SRC_Init_fx( TDREND_SRC_REND_Init_fx( Src_p->SrcRend_p ); /* Reset memory buffers */ - Src_p->itd = 0; + Src_p->itd = 0; // Q0 move16(); - Src_p->previtd = 0; + Src_p->previtd = 0; // Q0 move16(); - Src_p->filterlength = 1; /* Init to unit impulse of length 1 */ + Src_p->filterlength = 1; /* Init to unit impulse of length 1 */ // Q0 move16(); set32_fx( Src_p->mem_itd_fx, 0, ITD_MEM_LEN ); set32_fx( Src_p->mem_hrf_left_fx, 0, SFX_SPAT_BIN_MAX_FILTER_LENGTH - 1 ); @@ -1351,21 +1363,21 @@ void TDREND_SRC_Init_fx( set32_fx( Src_p->hrf_left_prev_fx, 0, SFX_SPAT_BIN_MAX_FILTER_LENGTH ); set32_fx( Src_p->hrf_right_prev_fx, 0, SFX_SPAT_BIN_MAX_FILTER_LENGTH ); - Src_p->hrf_left_prev_fx[0] = ONE_IN_Q30; + Src_p->hrf_left_prev_fx[0] = ONE_IN_Q30; // Q30 move32(); Src_p->hrf_left_prev_e = 1; move16(); - Src_p->hrf_right_prev_fx[0] = ONE_IN_Q30; + Src_p->hrf_right_prev_fx[0] = ONE_IN_Q30; // Q30 move32(); Src_p->hrf_right_prev_e = 1; move16(); - Src_p->azim_prev_fx = 0; + Src_p->azim_prev_fx = 0; // Q22 move32(); - Src_p->elev_prev_fx = 0; + Src_p->elev_prev_fx = 0; // Q22 move32(); - Src_p->Gain_fx = ONE_IN_Q14; + Src_p->Gain_fx = ONE_IN_Q14; // Q14 move16(); - Src_p->prevGain_fx = ONE_IN_Q14; + Src_p->prevGain_fx = ONE_IN_Q14; // Q14 move16(); return; } diff --git a/lib_rend/ivas_reverb_filter_design.c b/lib_rend/ivas_reverb_filter_design.c index b4cc42a34..c0d147123 100644 --- a/lib_rend/ivas_reverb_filter_design.c +++ b/lib_rend/ivas_reverb_filter_design.c @@ -46,12 +46,15 @@ * Local constants *------------------------------------------------------------------------------------------*/ -#define STEP_LIMIT_PIVOT_FREQ ( 1000.0f ) /* Pivot (initial reference) frequency for response gradient limit */ -#define RESPONSE_STEP_LIMIT_LF ( 4.0f ) /* Maximum step in dB per bin at low frequencies (< pivot frequency) */ -#define RESPONSE_STEP_LIMIT_LF_FX ( 536870912 ) /* Maximum step in dB per bin at low frequencies (< pivot frequency) */ -#define RESPONSE_STEP_LIMIT_HF ( 1.5f ) /* Maximum step in dB per bin at high frequencies (> pivot frequency) */ -#define RESPONSE_STEP_LIMIT_HF_FX ( 1610612736 ) /* Maximum step in dB per bin at high frequencies (> pivot frequency) */ -#define EPS ( 1e-30f ) +#ifndef IVAS_FLOAT_FIXED +#define STEP_LIMIT_PIVOT_FREQ ( 1000.0f ) /* Pivot (initial reference) frequency for response gradient limit */ +#define RESPONSE_STEP_LIMIT_LF ( 4.0f ) /* Maximum step in dB per bin at low frequencies (< pivot frequency) */ +#define RESPONSE_STEP_LIMIT_HF ( 1.5f ) /* Maximum step in dB per bin at high frequencies (> pivot frequency) */ +#define EPS ( 1e-30f ) +#else +#define RESPONSE_STEP_LIMIT_LF_FX ( 536870912 ) /* Q27 Maximum step in dB per bin at low frequencies (< pivot frequency) */ +#define RESPONSE_STEP_LIMIT_HF_FX ( 1610612736 ) /* Q30 Maximum step in dB per bin at high frequencies (> pivot frequency) */ +#endif /*------------------------------------------------------------------------------------------* @@ -194,9 +197,9 @@ static void calc_min_phase( #endif #ifdef IVAS_FLOAT_FIXED static void calc_min_phase_fx( - rv_fftwf_type_complex_fx *pSpectrum, + rv_fftwf_type_complex_fx *pSpectrum /*Q31*/, const Word16 fft_size, - Word32 *pMinPhase, + Word32 *pMinPhase, /*q_pCepstrum*/ Word16 *q_pCepstrum ) { Word16 idx; @@ -244,13 +247,13 @@ static void calc_min_phase_fx( /* Initial angle set to match Hann window alignment in Matlab */ - initial_angle = shr( add( ( EVS_PI_FX ), shr( angle_increment, 2 ) ), 1 ); // q = 13 + initial_angle = shr( add( ( EVS_PI_FX /*Q13*/ ), shr( angle_increment, 2 ) ), 1 ); // Q13 FOR( idx = 0; idx < cepstrum_smoothing_extent; idx++ ) { - const Word16 sine_value = getSinWord16( add( initial_angle, shl( mult( shl( idx, 8 ), angle_increment ), 5 ) ) ); // q15 + const Word16 sine_value = getSinWord16( add( initial_angle, shl( mult( shl( idx, 8 ), angle_increment ), 5 ) ) ); // Q15 - pFolded_cepstrum_smoothing_win[add( idx, sub( half_fft_size, cepstrum_smoothing_extent ) )] = L_mult( sine_value, sine_value ); // q31 + pFolded_cepstrum_smoothing_win[idx + half_fft_size - cepstrum_smoothing_extent] = L_mult( sine_value, sine_value ); // Q31 move32(); } @@ -264,9 +267,9 @@ static void calc_min_phase_fx( /* Compute the log amplitude spectrum */ FOR( idx = 0; idx < spectrum_size; idx++ ) { - W_tmp0 = W_mult_32_32( pSpectrum[idx][0], pSpectrum[idx][0] ); - W_tmp1 = W_mult_32_32( pSpectrum[idx][1], pSpectrum[idx][1] ); - W_tmp0 = W_add( W_tmp0, W_tmp1 ); + W_tmp0 = W_mult_32_32( pSpectrum[idx][0], pSpectrum[idx][0] ); // Q30 * 2 - 1 + W_tmp1 = W_mult_32_32( pSpectrum[idx][1], pSpectrum[idx][1] ); // Q30 * 2 - 1 + W_tmp0 = W_add( W_tmp0, W_tmp1 ); // Q30 * 2 - 1 W_shift = W_norm( W_tmp0 ); pCepstrum[idx] = Mpy_32_32( L_add( BASOP_Util_Log2( W_extract_h( W_shl( W_tmp0, W_shift ) ) ), L_shl( negate( W_shift ), 25 ) ), LN_2_Q31 ); /* log2 = 0.693147, q = 31, value = 1488521848 */ // q =26 move32(); @@ -275,7 +278,7 @@ static void calc_min_phase_fx( /* Extending one-sided spectrum to double-sided one */ FOR( idx = spectrum_size; idx < fft_size; idx++ ) { - pCepstrum[idx] = pCepstrum[sub( fft_size, idx )]; + pCepstrum[idx] = pCepstrum[fft_size - idx]; move32(); } Word16 guarded_bits; @@ -311,7 +314,7 @@ static void calc_min_phase_fx( { pFolded_cepstrum_re[idx] = L_shl( pCepstrum[idx], 1 ); // q = q_pCepstrum move32(); - pFolded_cepstrum_im[idx] = L_negate( L_shl( pCepstrum[sub( fft_size, idx )], 1 ) ); // q = q_pCepstrum + pFolded_cepstrum_im[idx] = L_negate( L_shl( pCepstrum[fft_size - idx], 1 ) ); // q = q_pCepstrum move32(); /* Note: sign inverted because of fft rather than ifft used before */ } @@ -414,7 +417,7 @@ static void calc_min_phase_filter( #ifdef IVAS_FLOAT_FIXED static void calc_min_phase_filter_fx( - rv_fftwf_type_complex_fx *pH_flt, + rv_fftwf_type_complex_fx *pH_flt, // Q31 const Word16 fft_size ) { const Word16 spectrum_size = add( shr( fft_size, 1 ), 1 ); @@ -433,21 +436,21 @@ static void calc_min_phase_filter_fx( /* Cancel out initial phase by computing amplitude */ /* Note: slightly different (but mathematically equivalent) approach used for better efficiency */ move16(); - W_tmp1 = W_mult_32_32( pH_flt[idx][0], pH_flt[idx][0] ); - W_tmp2 = W_mult_32_32( pH_flt[idx][1], pH_flt[idx][1] ); - W_tmp1 = W_add( W_tmp1, W_tmp2 ); + W_tmp1 = W_mult_32_32( pH_flt[idx][0], pH_flt[idx][0] ); // Q31 *2 - 1 + W_tmp2 = W_mult_32_32( pH_flt[idx][1], pH_flt[idx][1] ); // Q31 *2 - 1 + W_tmp1 = W_add( W_tmp1, W_tmp2 ); // Q31 *2 - 1 W_shift = W_norm( W_tmp1 ); - L_tmp = W_extract_h( W_shl( W_tmp1, W_shift ) ); - Word16 exp = negate( W_shift ); // 31-31-W_shift + L_tmp = W_extract_h( W_shl( W_tmp1, W_shift ) ); // Q31 *2 - 1 + W_shift - 31 + Word16 exp = negate( W_shift ); // 31-31-W_shift - Word32 current_ampl = Sqrt32( L_tmp, &exp ); // q = 31 -exp == 31 - current_ampl = L_shl( current_ampl, exp ); + Word32 current_ampl = Sqrt32( L_tmp, &exp ); // q = 31 - exp = q31 + current_ampl = L_shl( current_ampl, exp ); // Q31 /* Using the phase computed by calc_min_phase() + additional delay */ /* Apply the computed phase */ - pH_flt[idx][0] = Mpy_32_16_1( current_ampl, shl_sat( getCosWord16( abs_s( (Word16) L_shr( pMin_phase[idx], sub( q_pMin_phase, 13 ) ) ) ), 1 ) ); // shifting right for next function. + pH_flt[idx][0] = Mpy_32_16_1( current_ampl, shl_sat( getCosWord16( abs_s( (Word16) L_shr( pMin_phase[idx], sub( q_pMin_phase, 13 ) ) ) ), 1 ) ); // shifting right for next function.//Q31 + Q13 + 1 - 15 move32(); - pH_flt[idx][1] = Mpy_32_16_1( current_ampl, getSinWord16( (Word16) L_shr( pMin_phase[idx], sub( q_pMin_phase, 13 ) ) ) ); + pH_flt[idx][1] = Mpy_32_16_1( current_ampl, getSinWord16( (Word16) L_shr( pMin_phase[idx], sub( q_pMin_phase, 13 ) ) ) ); // Q31 + Q15 - 15 move32(); } @@ -511,8 +514,8 @@ static void apply_window_fft( #endif #ifdef IVAS_FLOAT_FIXED static void apply_window_fft_fx( - rv_fftwf_type_complex_fx *pH_flt, - const Word32 *pWindow, + rv_fftwf_type_complex_fx *pH_flt, // q_pFilter + const Word32 *pWindow, // Q30 const Word16 fft_size, Word16 *q_pFilter ) { @@ -525,13 +528,13 @@ static void apply_window_fft_fx( /* Real parts */ FOR( idx = 0; idx <= half_fft_size; idx++ ) { - pFilter[idx] = pH_flt[idx][0]; + pFilter[idx] = pH_flt[idx][0]; // Q31 move32(); } /* Img parts */ FOR( idx = 1; idx < half_fft_size; idx++ ) { - pFilter[sub( fft_size, idx )] = pH_flt[idx][1]; + pFilter[fft_size - idx] = pH_flt[idx][1]; // Q31 move32(); } *q_pFilter = 31; @@ -545,10 +548,11 @@ static void apply_window_fft_fx( { FOR( Word16 j = 0; j < fft_size; j++ ) { - pFilter[j] = L_shl( pFilter[j], temp ); + pFilter[j] = L_shl( pFilter[j], temp ); // q_pFilter + temp move32(); } *q_pFilter = add( *q_pFilter, temp ); + move16(); } ifft_rel_fx32( pFilter, fft_size, log2_fft_size ); @@ -575,12 +579,12 @@ static void apply_window_fft_fx( move16(); } - fft_rel_fx32( pFilter, fft_size, log2_fft_size ); // q = q_pFilter + fft_rel_fx32( pFilter, fft_size, log2_fft_size ); // q_pFilter /* Copy data to the output with format conversion */ - pH_flt[0][0] = pFilter[0]; + pH_flt[0][0] = pFilter[0]; // q_pFilter move32(); - pH_flt[half_fft_size][0] = pFilter[half_fft_size]; + pH_flt[half_fft_size][0] = pFilter[half_fft_size]; // q_pFilter move32(); pH_flt[0][1] = 0; move32(); @@ -588,9 +592,9 @@ static void apply_window_fft_fx( move32(); FOR( idx = 1; idx < half_fft_size; idx++ ) { - pH_flt[idx][0] = pFilter[idx]; + pH_flt[idx][0] = pFilter[idx]; // q_pFilter move32(); - pH_flt[idx][1] = pFilter[sub( fft_size, idx )]; + pH_flt[idx][1] = pFilter[fft_size - idx]; // q_pFilter move32(); } @@ -665,17 +669,20 @@ static void response_step_limit( return; } #else - static void response_step_limit_fx( - Word32 *X, + Word32 *X, // Q30 const Word16 dim_x, const Word16 pivot_bin_idx ) { Word16 i; - const Word32 positive_step_limit_lf = 1701766107; - const Word32 negative_step_limit_lf = 677485289; // 1.0f / positive_step_limit_lf = 0.63095734448019324;//q = 30 - const Word32 positive_step_limit_hf = 1276144549; - const Word32 negative_step_limit_hf = 903441154; // 1.0f / positive_step_limit_hf = 1.26209271246779263; //q = 30 + const Word32 positive_step_limit_lf = 1701766107; // Q30 + const Word32 negative_step_limit_lf = 677485289; // 1.0f / positive_step_limit_lf = 0.63095734448019324;//q = 30 + const Word32 positive_step_limit_hf = 1276144549; // Q30 + const Word32 negative_step_limit_hf = 903441154; // 1.0f / positive_step_limit_hf = 1.26209271246779263; //q = 30 + move32(); + move32(); + move32(); + move32(); /* Go up from pivot frequency and limit the slope to the maximum given by T. */ FOR( i = add( pivot_bin_idx, 1 ); i < dim_x; i++ ) @@ -695,7 +702,7 @@ static void response_step_limit_fx( IF( GT_16( desiredChange_q, 30 ) ) { - desiredChange = L_shr( desiredChange, desiredChange_q - 30 ); + desiredChange = L_shr( desiredChange, sub( desiredChange_q, 30 ) ); // Q30 desiredChange_q = 30; move16(); } @@ -703,23 +710,23 @@ static void response_step_limit_fx( IF( GE_32( X[i], X[i - 1] ) ) { - IF( GT_32( change, L_shr( positive_step_limit_hf, 30 - desiredChange_q ) ) ) + IF( GT_32( change, L_shr( positive_step_limit_hf, sub( 30, desiredChange_q ) ) ) ) { - change = positive_step_limit_hf; // q = 30; + change = positive_step_limit_hf; // Q30 move32(); - temp = W_mult0_32_32( X[i - 1], change ); - X[i] = (Word32) W_shr( temp, 30 ); + temp = W_mult0_32_32( X[i - 1], change ); // Q30+Q30 + X[i] = (Word32) W_shr( temp, 30 ); // Q30 move32(); } } ELSE { - IF( LT_32( change, L_shr( negative_step_limit_hf, 30 - desiredChange_q ) ) ) + IF( LT_32( change, L_shr( negative_step_limit_hf, sub( 30, desiredChange_q ) ) ) ) { - change = negative_step_limit_hf; // q = 30; + change = negative_step_limit_hf; // Q30; move32(); - temp = W_mult0_32_32( X[i - 1], change ); - X[i] = (Word32) W_shr( temp, 30 ); + temp = W_mult0_32_32( X[i - 1], change ); // Q30+Q30 + X[i] = (Word32) W_shr( temp, 30 ); // Q30 move32(); } } @@ -742,7 +749,7 @@ static void response_step_limit_fx( } IF( GT_16( desiredChange_q, 30 ) ) { - desiredChange = L_shr( desiredChange, desiredChange_q - 30 ); + desiredChange = L_shr( desiredChange, sub( desiredChange_q, 30 ) ); // Q30 desiredChange_q = 30; move16(); } @@ -752,10 +759,10 @@ static void response_step_limit_fx( { IF( GT_32( change, L_shr( positive_step_limit_lf, sub( 30, desiredChange_q ) ) ) ) { - change = positive_step_limit_lf; // q = 30; + change = positive_step_limit_lf; // Q30 move32(); - temp = W_mult0_32_32( X[i + 1], change ); - X[i] = (Word32) W_shr( temp, 30 ); + temp = W_mult0_32_32( X[i + 1], change ); // Q30 + Q30 + X[i] = (Word32) W_shr( temp, 30 ); // Q30 move32(); } } @@ -763,10 +770,10 @@ static void response_step_limit_fx( { IF( LT_32( change, L_shr( negative_step_limit_lf, sub( 30, desiredChange_q ) ) ) ) { - change = negative_step_limit_lf; // q = 30; + change = negative_step_limit_lf; // Q30 move32(); - temp = W_mult0_32_32( X[i + 1], change ); - X[i] = (Word32) W_shr( temp, 30 ); + temp = W_mult0_32_32( X[i + 1], change ); // Q30 + Q30 + X[i] = (Word32) W_shr( temp, 30 ); // Q30 move32(); } } @@ -820,7 +827,6 @@ void ivas_reverb_define_window_fft( return; } #else - void ivas_reverb_define_window_fft_fx( Word32 *pWindow, // output in Q31 const Word16 transitionStart, @@ -836,32 +842,32 @@ void ivas_reverb_define_window_fft_fx( /* The first portion of the sequence is kept unchanged, window == 1 */ FOR( idx = 0; idx < transitionStart; idx++ ) { - pWindow[idx] = ONE_IN_Q31; // q31 + pWindow[idx] = ONE_IN_Q31; // Q31 move32(); } /* Adding Hann half-window for smooth transition */ Word16 s1 = sub( norm_s( shr( EVS_PI_FX, 1 ) ), 1 ); Word16 s2 = norm_s( sub( shl( transitionLength, 1 ), 1 ) ); - Word16 var1 = shl( EVS_PI_FX, s1 ); + Word16 var1 = shl( EVS_PI_FX, s1 ); // Q13+s1 Word16 var2 = shl( sub( shl( transitionLength, 1 ), 1 ), s2 ); - angle_increment = div_s( shr( var1, 5 ), var2 ); // q = 15 + angle_increment = div_s( shr( var1, 5 ), var2 ); // Q15 /* Initial angle set to match Hann window alignment in Matlab */ - initial_angle = shr( add( ( EVS_PI_FX ), shr( angle_increment, 2 ) ), 1 ); // q = 13 + initial_angle = shr( add( ( EVS_PI_FX ), shr( angle_increment, 2 ) ), 1 ); // Q13 FOR( idx = 0; idx < transitionLength; idx++ ) { - const Word16 sine_value = getSineWord16R2( mult( add( initial_angle, shl( mult( shl( idx, 8 ), angle_increment ), 5 ) ), 20858 ) ); // q31 + const Word16 sine_value = getSineWord16R2( mult( add( initial_angle, shl( mult( shl( idx, 8 ), angle_increment ), 5 ) ), 20858 ) ); // Q31 - pWindow[add( idx, transitionStart )] = L_mult( sine_value, sine_value ); + pWindow[idx + transitionStart] = L_mult( sine_value, sine_value ); // Q31 move32(); } /* Padding the rest with zeros */ FOR( idx = add( transitionStart, transitionLength ); idx < fftLength; idx++ ) { - pWindow[idx] = 0; + pWindow[idx] = 0; // Q31 move32(); } @@ -918,12 +924,12 @@ int16_t ivas_reverb_calc_color_filters( #endif #ifdef IVAS_FLOAT_FIXED Word16 ivas_reverb_calc_color_filters_fx( - const Word32 *pTargetL, - const Word32 *pTargetR, - const Word32 *pWindow, + const Word32 *pTargetL, // Q30 + const Word32 *pTargetR, // Q30 + const Word32 *pWindow, // Q30 const Word16 fft_size, - rv_fftwf_type_complex_fx *pBeqL, - rv_fftwf_type_complex_fx *pBeqR, + rv_fftwf_type_complex_fx *pBeqL, // q_pBeqL + rv_fftwf_type_complex_fx *pBeqR, // q_pBeqR Word16 *q_pBeqL, Word16 *q_pBeqR ) { @@ -932,11 +938,11 @@ Word16 ivas_reverb_calc_color_filters_fx( half_fft_size = shr( fft_size, 1 ); FOR( idx = 0; idx <= half_fft_size; idx++ ) { - pBeqL[idx][0] = L_shl( pTargetL[idx], 1 ); + pBeqL[idx][0] = L_shl( pTargetL[idx], 1 ); // Q31 move32(); pBeqL[idx][1] = 0; move32(); - pBeqR[idx][0] = L_shl( pTargetR[idx], 1 ); + pBeqR[idx][0] = L_shl( pTargetR[idx], 1 ); // Q31 move32(); pBeqR[idx][1] = 0; move32(); @@ -1172,7 +1178,6 @@ void ivas_reverb_calc_color_levels( return; } #else - void ivas_reverb_calc_color_levels_fx( const Word32 output_Fs, const Word16 freq_count, @@ -1229,9 +1234,9 @@ void ivas_reverb_calc_color_levels_fx( /* Obtaining T60 filters coefficients for the current loop */ FOR( i = 0; i < nrcoefs; i++ ) { - coefA[i] = pT60_filter_coeff[add( i_mult( shl( nrcoefs, 1 ), loop_idx ), add( i, nrcoefs ) )]; // q = 31 + coefA[i] = pT60_filter_coeff[2 * nrcoefs * loop_idx + i + nrcoefs]; // q = 31 move32(); - coefB[i] = pT60_filter_coeff[add( i_mult( shl( nrcoefs, 1 ), loop_idx ), i )]; // // q = 31 + coefB[i] = pT60_filter_coeff[2 * nrcoefs * loop_idx + i]; // // q = 31 move32(); } t60_e[freq_count] = -100; @@ -1270,7 +1275,7 @@ void ivas_reverb_calc_color_levels_fx( /* Dividing by the number of loops to compute the average T60 estimate */ FOR( freq_idx = 0; freq_idx < freq_count; freq_idx++ ) { - t60[freq_idx] = Mpy_32_32( t60[freq_idx], L_shl( loop_count_inverted, 16 ) ); + t60[freq_idx] = Mpy_32_32( t60[freq_idx], L_shl( loop_count_inverted, 16 ) ); // t60_e[freq_idx] + 31 - 15 + 16 move32(); } @@ -1410,11 +1415,11 @@ void ivas_reverb_interpolate_acoustic_data_fx( const Word32 *pInput_t60, // input in Q26 const Word32 *pInput_dsr, // input in Q30 const Word16 output_table_size, - const Word32 *pOutput_fc, - Word32 *pOutput_t60, - Word32 *pOutput_dsr, - Word16 *pOutput_t60_e, // output e - Word16 *pOutput_dsr_e // output e + const Word32 *pOutput_fc, // Q16 + Word32 *pOutput_t60, // pOutput_t60_e + Word32 *pOutput_dsr, // pOutput_dsr_e + Word16 *pOutput_t60_e, // output e + Word16 *pOutput_dsr_e // output e ) { Word16 input_idx, output_idx; @@ -1657,10 +1662,10 @@ void ivas_reverb_get_hrtf_set_properties( #else void ivas_reverb_get_hrtf_set_properties_fx( - Word32 **ppHrtf_set_L_re, - Word32 **ppHrtf_set_L_im, - Word32 **ppHrtf_set_R_re, - Word32 **ppHrtf_set_R_im, + Word32 **ppHrtf_set_L_re, // Q29 + Word32 **ppHrtf_set_L_im, // Q29 + Word32 **ppHrtf_set_R_re, // Q29 + Word32 **ppHrtf_set_R_im, // Q29 const AUDIO_CONFIG input_audio_config, const Word16 hrtf_count, const Word16 in_freq_count, @@ -1675,6 +1680,18 @@ void ivas_reverb_get_hrtf_set_properties_fx( { MAX_WORD16, 0, MAX_WORD16 }, { MAX_WORD16, 0, -MAX_WORD16 } }; + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); const Word32 inp_freq_step = divide3232( ONE_IN_Q22, L_shl( in_freq_count, 23 ) ); // q= 15 const Word32 inp_freq_offset = L_shr( inp_freq_step, 1 ); // q= 15 const Word16 out_freq_step = divide3232( ONE_IN_Q21, L_shl( L_sub( out_freq_count, 1 ), 22 ) ); // q = 15 @@ -1743,7 +1760,7 @@ void ivas_reverb_get_hrtf_set_properties_fx( IF( GT_32( base_idx, L_sub( in_freq_count, 2 ) ) ) /* In case of extrapolation (above last bin), choose nearest */ { base_idx = L_sub( in_freq_count, 2 ); - relative_pos = ONE_IN_Q31; + relative_pos = ONE_IN_Q31; // Q31 move32(); } } @@ -1781,10 +1798,10 @@ void ivas_reverb_get_hrtf_set_properties_fx( /* In case of 5.1 or 7.1 formats, use the available HRTF paires directly*/ IF( !is_ambisonics ) { - current_base_L_ptr_re = ( ppHrtf_set_L_re[hrtf_idx] + base_idx ); - current_base_R_ptr_re = ( ppHrtf_set_R_re[hrtf_idx] + base_idx ); - current_base_L_ptr_im = ( ppHrtf_set_L_im[hrtf_idx] + base_idx ); - current_base_R_ptr_im = ( ppHrtf_set_R_im[hrtf_idx] + base_idx ); + current_base_L_ptr_re = ( ppHrtf_set_L_re[hrtf_idx] + base_idx ); // Q29 + current_base_R_ptr_re = ( ppHrtf_set_R_re[hrtf_idx] + base_idx ); // Q29 + current_base_L_ptr_im = ( ppHrtf_set_L_im[hrtf_idx] + base_idx ); // Q29 + current_base_R_ptr_im = ( ppHrtf_set_R_im[hrtf_idx] + base_idx ); // Q29 } /* In case of FOA format, combine the W channel with the X/Y channels */ @@ -1803,31 +1820,31 @@ void ivas_reverb_get_hrtf_set_properties_fx( FOR( ch_index = 0; ch_index < 3; ch_index++ ) { - combined_channels_L_re[freq_idx] = L_add( combined_channels_L_re[freq_idx], Mpy_32_16_1( ppHrtf_set_L_re[ch_index][base_idx + freq_idx], foa_sum_coeffs[hrtf_idx][ch_index] ) ); + combined_channels_L_re[freq_idx] = L_add( combined_channels_L_re[freq_idx], Mpy_32_16_1( ppHrtf_set_L_re[ch_index][base_idx + freq_idx], foa_sum_coeffs[hrtf_idx][ch_index] ) ); // Q29 + Q15 - 15 move32(); - combined_channels_R_re[freq_idx] = L_add( combined_channels_R_re[freq_idx], Mpy_32_16_1( ppHrtf_set_R_re[ch_index][base_idx + freq_idx], foa_sum_coeffs[hrtf_idx][ch_index] ) ); + combined_channels_R_re[freq_idx] = L_add( combined_channels_R_re[freq_idx], Mpy_32_16_1( ppHrtf_set_R_re[ch_index][base_idx + freq_idx], foa_sum_coeffs[hrtf_idx][ch_index] ) ); // Q29 + Q15 - 15 move32(); - combined_channels_L_im[freq_idx] = L_add( combined_channels_L_im[freq_idx], Mpy_32_16_1( ppHrtf_set_L_im[ch_index][base_idx + freq_idx], foa_sum_coeffs[hrtf_idx][ch_index] ) ); + combined_channels_L_im[freq_idx] = L_add( combined_channels_L_im[freq_idx], Mpy_32_16_1( ppHrtf_set_L_im[ch_index][base_idx + freq_idx], foa_sum_coeffs[hrtf_idx][ch_index] ) ); // Q29 + Q15 - 15 move32(); - combined_channels_R_im[freq_idx] = L_add( combined_channels_R_im[freq_idx], Mpy_32_16_1( ppHrtf_set_R_im[ch_index][base_idx + freq_idx], foa_sum_coeffs[hrtf_idx][ch_index] ) ); + combined_channels_R_im[freq_idx] = L_add( combined_channels_R_im[freq_idx], Mpy_32_16_1( ppHrtf_set_R_im[ch_index][base_idx + freq_idx], foa_sum_coeffs[hrtf_idx][ch_index] ) ); // Q29 + Q15 - 15 move32(); } } - current_base_L_ptr_re = &combined_channels_L_re[0]; - current_base_R_ptr_re = &combined_channels_R_re[0]; - current_base_L_ptr_im = &combined_channels_L_im[0]; - current_base_R_ptr_im = &combined_channels_R_im[0]; + current_base_L_ptr_re = &combined_channels_L_re[0]; // Q29 + current_base_R_ptr_re = &combined_channels_R_re[0]; // Q29 + current_base_L_ptr_im = &combined_channels_L_im[0]; // Q29 + current_base_R_ptr_im = &combined_channels_R_im[0]; // Q29 } FOR( freq_idx = 0; freq_idx < 2; freq_idx++ ) { Word32 L_re, L_im, R_re, R_im, C_re; - L_re = current_base_L_ptr_re[freq_idx]; // q = 29 - R_re = current_base_R_ptr_re[freq_idx]; // q = 29 - L_im = current_base_L_ptr_im[freq_idx]; // q = 29 - R_im = current_base_R_ptr_im[freq_idx]; // q = 29 + L_re = current_base_L_ptr_re[freq_idx]; // Q29 + R_re = current_base_R_ptr_re[freq_idx]; // Q29 + L_im = current_base_L_ptr_im[freq_idx]; // Q29 + R_im = current_base_R_ptr_im[freq_idx]; // Q29 move32(); move32(); move32(); @@ -1872,9 +1889,9 @@ void ivas_reverb_get_hrtf_set_properties_fx( IA_coherence[freq_idx] = L_shl( IA_coherence[freq_idx], sub( 27, sub( 15, temp ) ) ); // q = 27 move32(); /* Limiting to (0...1) range in case of small numerical errors or negative values */ - IA_coherence[freq_idx] = min( IA_coherence[freq_idx], ONE_IN_Q27 ); + IA_coherence[freq_idx] = min( IA_coherence[freq_idx], ONE_IN_Q27 ); // Q27 move32(); - IA_coherence[freq_idx] = max( IA_coherence[freq_idx], 0 ); + IA_coherence[freq_idx] = max( IA_coherence[freq_idx], 0 ); // Q27 move32(); } diff --git a/lib_rend/ivas_rom_rend.c b/lib_rend/ivas_rom_rend.c index b78c6fba1..caaea5173 100644 --- a/lib_rend/ivas_rom_rend.c +++ b/lib_rend/ivas_rom_rend.c @@ -1155,6 +1155,825 @@ const float ivas_reverb_default_DSR[IVAS_REVERB_DEFAULT_N_BANDS] = 6.2001e-08f, 2.8483e-08f, 2.6267e-08f }; +Word32 release_cnst_table[4][201] = // Q31 + { + { + 1913946752, + 1919716352, + 1925351680, + 1930855552, + 1936230784, + 1941479808, + 1946605312, + 1951609728, + 1956495744, + 1961265792, + 1965922304, + 1970467584, + 1974904320, + 1979234560, + 1983460736, + 1987585024, + 1991609856, + 1995537280, + 1999369344, + 2003108480, + 2006756480, + 2010315520, + 2013787520, + 2017174528, + 2020478464, + 2023701248, + 2026844672, + 2029910656, + 2032900992, + 2035817344, + 2038661376, + 2041435008, + 2044139648, + 2046777088, + 2049348864, + 2051856384, + 2054301440, + 2056685312, + 2059009536, + 2061275520, + 2063484672, + 2065638272, + 2067737856, + 2069784448, + 2071779584, + 2073724416, + 2075620096, + 2077467904, + 2079268992, + 2081024512, + 2082735488, + 2084403200, + 2086028416, + 2087612544, + 2089156352, + 2090660864, + 2092127104, + 2093555968, + 2094948480, + 2096305408, + 2097627776, + 2098916352, + 2100172032, + 2101395584, + 2102587776, + 2103749504, + 2104881408, + 2105984384, + 2107059072, + 2108106112, + 2109126400, + 2110120448, + 2111088896, + 2112032512, + 2112951808, + 2113847552, + 2114720128, + 2115570304, + 2116398592, + 2117205504, + 2117991552, + 2118757504, + 2119503616, + 2120230400, + 2120938496, + 2121628288, + 2122300288, + 2122954880, + 2123592576, + 2124213760, + 2124818944, + 2125408384, + 2125982592, + 2126541952, + 2127086848, + 2127617664, + 2128134656, + 2128638336, + 2129128832, + 2129606784, + 2130072192, + 2130525568, + 2130967296, + 2131397376, + 2131816448, + 2132224640, + 2132622080, + 2133009408, + 2133386496, + 2133753856, + 2134111744, + 2134460288, + 2134799744, + 2135130368, + 2135452416, + 2135766144, + 2136071680, + 2136369152, + 2136659072, + 2136941312, + 2137216256, + 2137484160, + 2137744896, + 2137998976, + 2138246400, + 2138487424, + 2138722176, + 2138950656, + 2139173376, + 2139390208, + 2139601408, + 2139807104, + 2140007424, + 2140202624, + 2140392576, + 2140577664, + 2140758016, + 2140933504, + 2141104512, + 2141271040, + 2141433216, + 2141591168, + 2141745024, + 2141894912, + 2142040832, + 2142182912, + 2142321408, + 2142456192, + 2142587392, + 2142715264, + 2142839808, + 2142961152, + 2143079296, + 2143194240, + 2143306240, + 2143415424, + 2143521664, + 2143625216, + 2143725952, + 2143824128, + 2143919744, + 2144012800, + 2144103424, + 2144191744, + 2144277760, + 2144361472, + 2144443136, + 2144522496, + 2144599936, + 2144675200, + 2144748544, + 2144820096, + 2144889600, + 2144957440, + 2145023488, + 2145087744, + 2145150336, + 2145211264, + 2145270656, + 2145328512, + 2145384832, + 2145439616, + 2145493120, + 2145545088, + 2145595776, + 2145645056, + 2145693184, + 2145739904, + 2145785472, + 2145829888, + 2145873152, + 2145915136, + 2145956224, + 2145996032, + 2146034944, + 2146072832, + 2146109696, + 2146145664, + 2146180608, + 2146214656, + 2146247808, + }, + { + 2027355264, + 2030408704, + 2033386624, + 2036290944, + 2039123328, + 2041885440, + 2044578944, + 2047205376, + 2049766528, + 2052263680, + 2054698496, + 2057072384, + 2059387008, + 2061643520, + 2063843328, + 2065987968, + 2068078720, + 2070116864, + 2072103552, + 2074040192, + 2075927936, + 2077767936, + 2079561472, + 2081309568, + 2083013376, + 2084673920, + 2086292352, + 2087869696, + 2089406976, + 2090905216, + 2092365184, + 2093788032, + 2095174528, + 2096525824, + 2097842432, + 2099125632, + 2100375808, + 2101594240, + 2102781312, + 2103938048, + 2105065216, + 2106163456, + 2107233536, + 2108276096, + 2109292032, + 2110281728, + 2111246080, + 2112185728, + 2113101056, + 2113992960, + 2114861824, + 2115708288, + 2116532992, + 2117336448, + 2118119168, + 2118881792, + 2119624704, + 2120348416, + 2121053440, + 2121740288, + 2122409344, + 2123061120, + 2123696128, + 2124314624, + 2124917120, + 2125504128, + 2126075776, + 2126632832, + 2127175296, + 2127703808, + 2128218624, + 2128720000, + 2129208448, + 2129684352, + 2130147712, + 2130599168, + 2131038976, + 2131467264, + 2131884416, + 2132290816, + 2132686592, + 2133072256, + 2133447680, + 2133813504, + 2134169856, + 2134516864, + 2134854784, + 2135184000, + 2135504640, + 2135816960, + 2136121216, + 2136417536, + 2136706048, + 2136987136, + 2137260928, + 2137527552, + 2137787264, + 2138040192, + 2138286592, + 2138526464, + 2138760192, + 2138987776, + 2139209472, + 2139425408, + 2139635712, + 2139840512, + 2140039936, + 2140234240, + 2140423424, + 2140607744, + 2140787200, + 2140962048, + 2141132288, + 2141298048, + 2141459584, + 2141616896, + 2141769984, + 2141919232, + 2142064512, + 2142205952, + 2142343808, + 2142478080, + 2142608768, + 2142736128, + 2142860032, + 2142980864, + 2143098368, + 2143212928, + 2143324544, + 2143433088, + 2143538944, + 2143641984, + 2143742336, + 2143840000, + 2143935232, + 2144027904, + 2144118144, + 2144206080, + 2144291712, + 2144375168, + 2144456320, + 2144535424, + 2144612480, + 2144687488, + 2144760448, + 2144831616, + 2144900992, + 2144968448, + 2145034112, + 2145098112, + 2145160448, + 2145221248, + 2145280256, + 2145337856, + 2145393920, + 2145448576, + 2145501696, + 2145553536, + 2145603968, + 2145653120, + 2145700992, + 2145747456, + 2145792896, + 2145837056, + 2145880064, + 2145922048, + 2145962880, + 2146002560, + 2146041344, + 2146078976, + 2146115712, + 2146151424, + 2146186240, + 2146220160, + 2146253184, + 2146285312, + 2146316672, + 2146347136, + 2146376832, + 2146405760, + 2146433920, + 2146461440, + 2146488192, + 2146514176, + 2146539520, + 2146564224, + 2146588160, + 2146611584, + 2146634368, + 2146656640, + 2146678272, + 2146699264, + 2146719744, + 2146739712, + 2146759168, + 2146778112, + 2146796544, + 2146814464, + 2146832000, + 2146849024, + 2146865664, + }, + { + 2086555136, + 2088125824, + 2089656576, + 2091148416, + 2092602240, + 2094018944, + 2095399680, + 2096745088, + 2098056192, + 2099333888, + 2100578816, + 2101792000, + 2102974080, + 2104125824, + 2105248128, + 2106341760, + 2107407232, + 2108445440, + 2109456896, + 2110442496, + 2111402624, + 2112338176, + 2113249664, + 2114137728, + 2115002880, + 2115845760, + 2116666880, + 2117466880, + 2118246272, + 2119005568, + 2119745280, + 2120465920, + 2121167872, + 2121851776, + 2122517888, + 2123166976, + 2123799168, + 2124414976, + 2125014912, + 2125599360, + 2126168704, + 2126723200, + 2127263360, + 2127789568, + 2128302208, + 2128801408, + 2129287808, + 2129761536, + 2130222976, + 2130672512, + 2131110272, + 2131536768, + 2131952128, + 2132356736, + 2132750848, + 2133134720, + 2133508736, + 2133872896, + 2134227584, + 2134573184, + 2134909696, + 2135237504, + 2135556736, + 2135867648, + 2136170624, + 2136465536, + 2136752896, + 2137032832, + 2137305344, + 2137570816, + 2137829376, + 2138081280, + 2138326528, + 2138565504, + 2138798080, + 2139024768, + 2139245440, + 2139460480, + 2139669888, + 2139873792, + 2140072320, + 2140265856, + 2140454144, + 2140637696, + 2140816384, + 2140990464, + 2141159936, + 2141325056, + 2141485824, + 2141642368, + 2141794944, + 2141943424, + 2142088064, + 2142228992, + 2142366208, + 2142499840, + 2142630016, + 2142756736, + 2142880128, + 2143000448, + 2143117440, + 2143231488, + 2143342592, + 2143450752, + 2143556096, + 2143658624, + 2143758592, + 2143855872, + 2143950592, + 2144043008, + 2144132864, + 2144220416, + 2144305664, + 2144388608, + 2144469504, + 2144548224, + 2144624896, + 2144699648, + 2144772352, + 2144843264, + 2144912256, + 2144979328, + 2145044864, + 2145108480, + 2145170560, + 2145231104, + 2145289856, + 2145347200, + 2145403008, + 2145457408, + 2145510400, + 2145561984, + 2145612160, + 2145661056, + 2145708672, + 2145755136, + 2145800192, + 2145844224, + 2145887104, + 2145928832, + 2145969408, + 2146008960, + 2146047616, + 2146085120, + 2146121600, + 2146157184, + 2146191872, + 2146225664, + 2146258560, + 2146290560, + 2146321792, + 2146352128, + 2146381696, + 2146410496, + 2146438528, + 2146465920, + 2146492416, + 2146518400, + 2146543616, + 2146568192, + 2146592128, + 2146615424, + 2146638080, + 2146660224, + 2146681728, + 2146702720, + 2146723072, + 2146743040, + 2146762368, + 2146781184, + 2146799616, + 2146817408, + 2146834816, + 2146851840, + 2146868352, + 2146884352, + 2146900096, + 2146915328, + 2146930176, + 2146944640, + 2146958720, + 2146972416, + 2146985856, + 2146998784, + 2147011456, + 2147023872, + 2147035904, + 2147047552, + 2147058944, + 2147070080, + 2147080832, + 2147091456, + 2147101696, + 2147111680, + 2147121408, + 2147130880, + 2147140096, + 2147149056, + 2147157760, + 2147166336, + 2147174656, + }, + { + 2106670080, + 2107727232, + 2108757120, + 2109760640, + 2110738432, + 2111691008, + 2112619136, + 2113523328, + 2114404352, + 2115262592, + 2116098816, + 2116913408, + 2117707136, + 2118480256, + 2119233536, + 2119967360, + 2120682240, + 2121378688, + 2122057088, + 2122717952, + 2123361792, + 2123988992, + 2124599936, + 2125195136, + 2125774848, + 2126339584, + 2126889728, + 2127425536, + 2127947520, + 2128456064, + 2128951296, + 2129433856, + 2129903744, + 2130361600, + 2130807424, + 2131241728, + 2131664768, + 2132076928, + 2132478208, + 2132869248, + 2133250048, + 2133620992, + 2133982208, + 2134334080, + 2134676864, + 2135010688, + 2135335936, + 2135652608, + 2135961088, + 2136261504, + 2136554112, + 2136839168, + 2137116800, + 2137387136, + 2137650560, + 2137907072, + 2138156928, + 2138400256, + 2138637184, + 2138867968, + 2139092864, + 2139311744, + 2139524992, + 2139732736, + 2139934976, + 2140131968, + 2140323840, + 2140510720, + 2140692736, + 2140870016, + 2141042688, + 2141210752, + 2141374592, + 2141534080, + 2141689344, + 2141840640, + 2141987968, + 2142131456, + 2142271232, + 2142407424, + 2142539904, + 2142669056, + 2142794752, + 2142917248, + 2143036544, + 2143152640, + 2143265792, + 2143375872, + 2143483264, + 2143587712, + 2143689472, + 2143788544, + 2143885056, + 2143979136, + 2144070656, + 2144159872, + 2144246656, + 2144331264, + 2144413568, + 2144493824, + 2144571904, + 2144647936, + 2144722048, + 2144794240, + 2144864512, + 2144932864, + 2144999552, + 2145064448, + 2145127680, + 2145189248, + 2145249152, + 2145307520, + 2145364480, + 2145419776, + 2145473792, + 2145526272, + 2145577472, + 2145627264, + 2145675776, + 2145723008, + 2145768960, + 2145813760, + 2145857408, + 2145899904, + 2145941376, + 2145981696, + 2146020864, + 2146059136, + 2146096384, + 2146132608, + 2146167936, + 2146202368, + 2146235776, + 2146268416, + 2146300160, + 2146331136, + 2146361216, + 2146390528, + 2146419200, + 2146446976, + 2146474112, + 2146500480, + 2146526208, + 2146551168, + 2146575488, + 2146599296, + 2146622464, + 2146644864, + 2146666880, + 2146688128, + 2146708992, + 2146729216, + 2146748928, + 2146768128, + 2146786816, + 2146805120, + 2146822784, + 2146840064, + 2146856960, + 2146873344, + 2146889216, + 2146904832, + 2146919936, + 2146934656, + 2146948992, + 2146962944, + 2146976640, + 2146989824, + 2147002752, + 2147015296, + 2147027584, + 2147039488, + 2147051136, + 2147062400, + 2147073408, + 2147084160, + 2147094528, + 2147104768, + 2147114624, + 2147124352, + 2147133696, + 2147142912, + 2147151744, + 2147160448, + 2147168896, + 2147177088, + 2147185152, + 2147192960, + 2147200512, + 2147207936, + 2147215104, + 2147222144, + 2147229056, + 2147235712, + 2147242112, + 2147248384, + 2147254656, + 2147260544, + 2147266432, + 2147272064, + 2147277568, + }, + + + }; + + /*----------------------------------------------------------------------------------* * Renderer SBA & MC enc/dec matrices *----------------------------------------------------------------------------------*/ diff --git a/lib_rend/ivas_rom_rend.h b/lib_rend/ivas_rom_rend.h index 06590cee1..f98897eca 100644 --- a/lib_rend/ivas_rom_rend.h +++ b/lib_rend/ivas_rom_rend.h @@ -186,6 +186,8 @@ extern const float ivas_reverb_default_fc[]; extern const float ivas_reverb_default_RT60[]; extern const float ivas_reverb_default_DSR[]; +Word32 release_cnst_table[4][201]; // Q31 + /*----------------------------------------------------------------------------------* * Renderer SBA & MC enc/dec matrices *----------------------------------------------------------------------------------*/ diff --git a/lib_rend/ivas_shoebox.c b/lib_rend/ivas_shoebox.c index 585696760..1cbdc63c1 100644 --- a/lib_rend/ivas_shoebox.c +++ b/lib_rend/ivas_shoebox.c @@ -49,18 +49,19 @@ * Local constants *------------------------------------------------------------------------*/ -#define ER_MAX_SOURCES 25 -#define ER_REF_ORDER 1 +#define ER_MAX_SOURCES 25 +#define ER_REF_ORDER 1 +#ifndef IVAS_FLOAT_FIXED #define ER_AIR_COEFF ( 0.00137f ) #define ER_SOUND_SPEED ( 343.0f ) #define ER_MIN_WALL_DIST ( 0.1f ) #define ER_EUCLIDEAN_SCALE ( 1.29246971E-26f ) -#ifdef IVAS_FLOAT_FIXED -#define ER_AIR_COEFF_FX ( Word32 )( 0.00137 * ONE_IN_Q31 ) // Q.31 -#define ER_SOUND_SPEED_FX ( Word32 )( 1 / 343.0 * ONE_IN_Q31 ) // 1/343.0f in Q1.31 -#define ER_MIN_WALL_DIST_FX ( Word32 )( 0.1 * ONE_IN_Q22 ) // Q.22 -#define ER_EUCLIDEAN_SCALE_FX ( 0x1 ) ////Q.22 -#define ER_RECIPROCAL_EUCLIDEAN_SCALE_FX ( 0x1 ) // Q.22 +#else +#define ER_AIR_COEFF_FX ( Word32 )( 2942053 ) // 0.00137f in Q.31 +#define ER_SOUND_SPEED_FX ( Word32 )( 6260885 ) // 1/343.0f in Q1.31 +#define ER_MIN_WALL_DIST_FX ( Word32 )( 419430 ) // Q.22 +#define ER_EUCLIDEAN_SCALE_FX ( 0x1 ) // Q.22 +#define ER_RECIPROCAL_EUCLIDEAN_SCALE_FX ( 0x1 ) // Q.22 #endif @@ -192,9 +193,8 @@ void ivas_shoebox_init( move32(); /* Add defaults */ obj->max_bands = 1; - obj->MAX_SOURCES = ER_MAX_SOURCES; - obj->REF_ORDER = ER_REF_ORDER; - move16(); + obj->MAX_SOURCES = ER_MAX_SOURCES; // Q0 + obj->REF_ORDER = ER_REF_ORDER; // Q0 move16(); move16(); move16(); @@ -225,10 +225,10 @@ void ivas_shoebox_init( move16(); /* Params */ - obj->radius_fx = ER_RADIUS_FX; - obj->min_wall_dist_fx = ER_MIN_WALL_DIST_FX; - obj->soundspeed_fx = ER_SOUND_SPEED_FX; - obj->air_coeff_fx = ER_AIR_COEFF_FX; + obj->radius_fx = ER_RADIUS_FX; // Q30 + obj->min_wall_dist_fx = ER_MIN_WALL_DIST_FX; // Q22 + obj->soundspeed_fx = ER_SOUND_SPEED_FX; // Q31 + obj->air_coeff_fx = ER_AIR_COEFF_FX; // Q31 move32(); move32(); move32(); @@ -305,7 +305,8 @@ static void shoebox_bound( #else static void shoebox_bound_fx( shoebox_obj_t *obj, - Word32 *out_pos ) + Word32 *out_pos // Q22 +) { Word32 out_tmp, out_tmp1; Word32 i; @@ -360,7 +361,7 @@ static void shoebox_bound_fx( } move32(); } - out_pos[1] = W_extract_l( W_mult0_32_32( out_tmp, i ) ); + out_pos[1] = W_extract_l( W_mult0_32_32( out_tmp, i ) ); // Q22 move32(); } @@ -387,7 +388,7 @@ static void shoebox_bound_fx( } move32(); } - out_pos[2] = (Word32) W_mult0_32_32( out_tmp, (Word32) i ); + out_pos[2] = W_extract_l( W_mult0_32_32( out_tmp, (Word32) i ) ); // Q22 move32(); } @@ -482,9 +483,9 @@ static void shoebox_get_coord( static void shoebox_get_coord_fx( shoebox_obj_t *obj, - Word32 *fcnOutput_data, - const Word32 src_pos_data[], - Word32 *tmp_pos, + Word32 *fcnOutput_data, // 0th and 1st idx in Q0 and 2nd idx in Q30 + const Word32 src_pos_data[], // Q22 + Word32 *tmp_pos, // Q22 Word32 out_tmp, Word32 coord, Word32 loop_ub, @@ -501,18 +502,18 @@ static void shoebox_get_coord_fx( IF( obj->isCartesian == 0 ) { /* Convert Spherical to Cartesian */ - tmp_data[2] = Mpy_32_32( fcnOutput_data[2], shoebox_sin_cos_tbl_fx[fcnOutput_data[1]][0] ); //.29 = .30 * .30 + tmp_data[2] = Mpy_32_32( fcnOutput_data[2] /* Q30 */, shoebox_sin_cos_tbl_fx[fcnOutput_data[1] /* Q0 */][0] ); // Q29 = .Q30 * Q30 move32(); - rcoselev = Mpy_32_32( fcnOutput_data[2], shoebox_sin_cos_tbl_fx[fcnOutput_data[1]][1] ); //.29 = .30 * .30 - tmp_data[0] = Mpy_32_32( rcoselev, shoebox_sin_cos_tbl_fx[fcnOutput_data[0]][1] ); // .28 =.29*.30 + rcoselev = Mpy_32_32( fcnOutput_data[2] /* Q30 */, shoebox_sin_cos_tbl_fx[fcnOutput_data[1] /* Q0 */][1] ); // Q29 = Q30 * Q30 + tmp_data[0] = Mpy_32_32( rcoselev, shoebox_sin_cos_tbl_fx[fcnOutput_data[0] /* Q0 */][1] ); // Q28 =Q29*Q30 move32(); - tmp_data[1] = Mpy_32_32( rcoselev, shoebox_sin_cos_tbl_fx[fcnOutput_data[0]][0] ); // .28 = .29*.30 + tmp_data[1] = Mpy_32_32( rcoselev, shoebox_sin_cos_tbl_fx[fcnOutput_data[0] /* Q0 */][0] ); // Q28 = Q29*Q30 move32(); - tmp_data[0] = L_shr( tmp_data[0], 6 ); + tmp_data[0] = L_shr( tmp_data[0], 6 ); // Q28 -> Q22 move32(); - tmp_data[1] = L_shr( tmp_data[1], 6 ); + tmp_data[1] = L_shr( tmp_data[1], 6 ); // Q28 -> Q22 move32(); - tmp_data[2] = L_shr( tmp_data[2], 7 ); + tmp_data[2] = L_shr( tmp_data[2], 7 ); // Q29 -> Q22 move32(); } ELSE @@ -528,14 +529,14 @@ static void shoebox_get_coord_fx( IF( obj->isZHeight != 0 ) { /* FIX Z COORDINATE */ - tmp_data[2] = L_sub( src_pos_data[L_add( k, 2 )], L_shr( obj->cal.room_H_fx, 1 ) ); + tmp_data[2] = L_sub( src_pos_data[k + 2] /* Q22 */, L_shr( obj->cal.room_H_fx, 1 ) ); // Q22 move32(); } } FOR( k = 0; k < tmp_size_idx_1; k++ ) { - obj->src_pos_fx[L_add( coord, k ) - 1] = tmp_data[k]; //.22 + obj->src_pos_fx[coord + k - 1] = tmp_data[k]; // Q22 move32(); } @@ -543,18 +544,18 @@ static void shoebox_get_coord_fx( k = L_add( out_tmp, 1 ); - tmp_pos[0] = obj->src_pos_fx[k - 1]; //.22 - tmp_pos[1] = obj->src_pos_fx[k]; - tmp_pos[2] = obj->src_pos_fx[k + 1]; + tmp_pos[0] = obj->src_pos_fx[k - 1]; // Q22 + tmp_pos[1] = obj->src_pos_fx[k]; // Q22 + tmp_pos[2] = obj->src_pos_fx[k + 1]; // Q22 move32(); move32(); move32(); IF( isRelative != 0 ) { - tmp_pos[0] = L_add( tmp_pos[0], obj->list_pos_fx[0] ); //.22 - tmp_pos[1] = L_add( tmp_pos[1], obj->list_pos_fx[1] ); - tmp_pos[2] = L_add( tmp_pos[2], obj->list_pos_fx[2] ); + tmp_pos[0] = L_add( tmp_pos[0], obj->list_pos_fx[0] ); // Q22 + tmp_pos[1] = L_add( tmp_pos[1], obj->list_pos_fx[1] ); // Q22 + tmp_pos[2] = L_add( tmp_pos[2], obj->list_pos_fx[2] ); // Q22 move32(); move32(); @@ -627,13 +628,14 @@ static float shoebox_get_euclidian_distance_internal( #else static Word32 shoebox_get_euclidian_distance_internal_fx( shoebox_obj_t *obj, - Word32 *tmp_pos, - Word32 *scale ) + Word32 *tmp_pos, // Q22 + Word32 *scale // Q22 +) { Word32 absxk, out_tmp, t; Word16 q; - absxk = L_abs( L_sub( obj->list_pos_fx[0], tmp_pos[0] ) ); // Q.22-Q22 + absxk = L_abs( L_sub( obj->list_pos_fx[0], tmp_pos[0] ) ); // Q22-Q22 IF( GT_32( absxk, ER_EUCLIDEAN_SCALE_FX ) ) { @@ -658,15 +660,15 @@ static Word32 shoebox_get_euclidian_distance_internal_fx( out_tmp = W_extract_h( W_shl( W_mult_32_32( out_tmp, t ), q ) ); // Q22 + Q31 + Q1 - 32 = Q22 out_tmp = W_extract_h( W_shl( W_mult_32_32( out_tmp, t ), q ) ); // Q22 + Q31 + Q1 - 32 = Q22 - out_tmp = L_add( out_tmp, ONE_IN_Q22 ); //.22 - *scale = absxk; // Q.22 + out_tmp = L_add( out_tmp, ONE_IN_Q22 ); // Q22 + *scale = absxk; // Q22 move32(); } ELSE { t = (Word32) BASOP_Util_Divide3232_Scale_cadence( absxk, *scale, &q ); t = W_extract_h( W_shl( W_mult_32_32( t, t ), sub( shl( q, 1 ), 9 ) ) ); // Q31 + Q31 + Q1 - 9 - 32 = Q22 - out_tmp = L_add( out_tmp, t ); //.22 + out_tmp = L_add( out_tmp, t ); // Q22 move32(); } @@ -676,17 +678,17 @@ static Word32 shoebox_get_euclidian_distance_internal_fx( { t = (Word32) BASOP_Util_Divide3232_Scale_cadence( *scale, absxk, &q ); - out_tmp = W_extract_h( W_shl( W_mult_32_32( out_tmp, t ), q ) ); // Q22 + Q31 + Q1 - 32 = Q22 - out_tmp = W_extract_h( W_shl( W_mult_32_32( out_tmp, t ), q ) ); // Q22 + Q31 + Q1 - 32 = Q22 - out_tmp = L_add( out_tmp, ONE_IN_Q22 ); //.22 - *scale = absxk; // Q.22 + out_tmp = W_extract_h( W_shl( W_mult_32_32( out_tmp, t ), q ) ); // Q22 + Q31 + Q1 - 32 = Q22 + out_tmp = W_extract_h( W_shl( W_mult_32_32( out_tmp, t ), q ) ); // Q22 + Q31 + Q1 - 32 = Q22 + out_tmp = L_add( out_tmp, ONE_IN_Q22 ); // Q22 + *scale = absxk; // Q22 move32(); } ELSE { t = (Word32) BASOP_Util_Divide3232_Scale_cadence( absxk, *scale, &q ); t = W_extract_h( W_shl( W_mult_32_32( t, t ), sub( shl( q, 1 ), 9 ) ) ); // Q31 + Q31 + Q1 - 9 - 32 = Q22 - out_tmp = L_add( out_tmp, t ); //.22 + out_tmp = L_add( out_tmp, t ); // Q22 } return out_tmp; @@ -851,8 +853,8 @@ void ivas_shoebox_set_scene( void ivas_shoebox_set_scene( shoebox_obj_t *obj, shoebox_output_t *ER_PARAMS, - const Word32 list_pos_fx[3], - const Word32 src_pos_data[], + const Word32 list_pos_fx[3], // Q22 + const Word32 src_pos_data[], // 0th and 1st idx in Q0 and 2nd idx in Q30 const UWord16 isCartesian, const UWord16 isRelative ) { @@ -881,20 +883,20 @@ void ivas_shoebox_set_scene( set32_fx( &obj->src_pos_fx[0], 0, 75U ); - obj->list_pos_fx[0] = list_pos_fx[0]; - obj->list_pos_fx[1] = list_pos_fx[1]; - obj->list_pos_fx[2] = list_pos_fx[2]; + obj->list_pos_fx[0] = list_pos_fx[0]; // Q22 + obj->list_pos_fx[1] = list_pos_fx[1]; // Q22 + obj->list_pos_fx[2] = list_pos_fx[2]; // Q22 move32(); move32(); move32(); /* ---------- ADJUST LISTENER ------------- */ IF( obj->isZHeight != 0 ) { - obj->list_pos_fx[2] = L_sub( list_pos_fx[2], L_shr( obj->cal.room_H_fx, 1 ) ); // Q.22 + obj->list_pos_fx[2] = L_sub( list_pos_fx[2], L_shr( obj->cal.room_H_fx, 1 ) ); // Q22 move32(); } - tmp_pos_fx[1] = obj->list_pos_fx[1]; - tmp_pos_fx[2] = obj->list_pos_fx[2]; + tmp_pos_fx[1] = obj->list_pos_fx[1]; // Q22 + tmp_pos_fx[2] = obj->list_pos_fx[2]; // Q22 move32(); move32(); @@ -922,14 +924,14 @@ void ivas_shoebox_set_scene( FOR( n = 0; n < loop_ub; n++ ) { - fcnOutput_data_fx[n] = src_pos_data[L_add( k, n )]; + fcnOutput_data_fx[n] = src_pos_data[k + n]; move32(); } shoebox_get_coord_fx( obj, fcnOutput_data_fx, src_pos_data, tmp_pos_fx, out_tmp, coord, loop_ub, k, isRelative ); shoebox_bound_fx( obj, tmp_pos_fx ); - scale_fx = ER_EUCLIDEAN_SCALE_FX; + scale_fx = ER_EUCLIDEAN_SCALE_FX; // Q22 move32(); out_tmp_fx = shoebox_get_euclidian_distance_internal_fx( obj, tmp_pos_fx, &scale_fx ); q_format = Q31 - Q22; @@ -950,7 +952,7 @@ void ivas_shoebox_set_scene( /* 2. ER_struct : Early reflection structure */ /* 3. src_num : Index of source to compute patterns for */ /* ------ */ - out_tmp_fx = obj->src_dist_fx[j]; + out_tmp_fx = obj->src_dist_fx[j]; // Q22 move32(); FOR( loop_ub = 0; loop_ub < 6; loop_ub++ ) @@ -970,8 +972,8 @@ void ivas_shoebox_set_scene( /* Initialize image position coordinates */ im_pos_fx[0] = tmp_pos_fx[0]; // Q:22 - im_pos_fx[1] = tmp_pos_fx[1]; - im_pos_fx[2] = tmp_pos_fx[2]; + im_pos_fx[1] = tmp_pos_fx[1]; // Q:22 + im_pos_fx[2] = tmp_pos_fx[2]; // Q:22 move32(); move32(); move32(); @@ -996,7 +998,7 @@ void ivas_shoebox_set_scene( im_pos_fx[coord] = L_add( tmp_pos_fx[coord], - L_shl( L_sub( L_shr( (Word32) W_mult0_32_32( ( L_negate( L_sub( 1, L_shl( L_and( L_add( loop_ub, 1 ), 1 ), 1 ) ) ) ), scale_fx ), 1 ), tmp_pos_fx[coord] ), 1 ) ); // Q:22 + L_shl( L_sub( L_shr( W_extract_l( W_mult0_32_32( ( L_negate( L_sub( 1, L_shl( L_and( L_add( loop_ub, 1 ), 1 ), 1 ) ) ) ), scale_fx ) ), 1 ), tmp_pos_fx[coord] ), 1 ) ); // Q:22 move32(); /* 0. Get euclidean distance from IMAGE SOURCE [N,W] to LIST */ @@ -1006,23 +1008,23 @@ void ivas_shoebox_set_scene( q_format = Q31 - Q22; move16(); - path_dist_fx = Sqrt32( path_dist_fx, &q_format ); // Input: Q:22, Output : Q.30 + path_dist_fx = Sqrt32( path_dist_fx, &q_format ); // Input: Q:22, Output : Q30 - path_dist_fx = Mpy_32_32( scale_fx, path_dist_fx ); // Q22 * Q = Q - path_dist_fx = L_shl( path_dist_fx, q_format ); + path_dist_fx = Mpy_32_32( scale_fx, path_dist_fx ); // Q22 + (31 - q_format) - 31 = Q22 - q_format + path_dist_fx = L_shl( path_dist_fx, q_format ); // Q22 - q_format + (q_format) = Q22 /* 1. Compute time-of arrival (TOA) */ - ER_PARAMS->times.data_fx[rcoselev - 1] = Mpy_32_32( path_dist_fx, obj->soundspeed_fx ); // Q.22 + ER_PARAMS->times.data_fx[rcoselev - 1] = Mpy_32_32( path_dist_fx, obj->soundspeed_fx ); // Q22 move32(); /* 2./3. DOA */ - sub_im_nd_list_pos_1 = L_sub( im_pos_fx[1], obj->list_pos_fx[1] ); // Q.22 - sub_im_nd_list_pos_0 = L_sub( im_pos_fx[0], obj->list_pos_fx[0] ); // Q.22 + sub_im_nd_list_pos_1 = L_sub( im_pos_fx[1], obj->list_pos_fx[1] ); // Q22 + sub_im_nd_list_pos_0 = L_sub( im_pos_fx[0], obj->list_pos_fx[0] ); // Q22 q_format = Q22 - Q22; move16(); - atan_pos = BASOP_util_atan2( sub_im_nd_list_pos_1, sub_im_nd_list_pos_0, q_format ); // Q.13 - az_angle_d = rad2deg_fx( atan_pos ); // Q.23 + atan_pos = BASOP_util_atan2( sub_im_nd_list_pos_1, sub_im_nd_list_pos_0, q_format ); // Q13 + az_angle_d = rad2deg_fx( atan_pos ); // Q23 ER_PARAMS->az_angle.data_fx[rcoselev - 1] = az_angle_d; move32(); @@ -1045,7 +1047,7 @@ void ivas_shoebox_set_scene( q_format_n = Q31 - Q31; asin_val = BASOP_util_atan2( sub_im_nd_list_div_path, one_minus_sub_im_nd_list_div_path_sq_rt, q_format_n ); // Q13 - asin_val_deg = rad2deg_fx( asin_val ); // Q.23 + asin_val_deg = rad2deg_fx( asin_val ); // Q23 ER_PARAMS->el_angle.data_fx[rcoselev - 1] = asin_val_deg; move32(); @@ -1054,7 +1056,7 @@ void ivas_shoebox_set_scene( /* and propagation loss */ if ( LT_32( path_dist_fx, out_tmp_fx ) ) { - path_dist_fx = out_tmp_fx; + path_dist_fx = out_tmp_fx; // Q22 move32(); } @@ -1068,7 +1070,7 @@ void ivas_shoebox_set_scene( pro_pd_air_coeff = Mpy_32_32( path_dist_fx, obj->air_coeff_fx ); // Q.22 *Q.31 =Q.22 result_gain = L_sub( product, pro_pd_air_coeff ); - ER_PARAMS->gains.data_fx[rcoselev - 1] = result_gain; + ER_PARAMS->gains.data_fx[rcoselev - 1] = result_gain; // Q22 move32(); } } diff --git a/lib_rend/ivas_stat_rend.h b/lib_rend/ivas_stat_rend.h index b6f6274cf..03b8fd46e 100644 --- a/lib_rend/ivas_stat_rend.h +++ b/lib_rend/ivas_stat_rend.h @@ -94,10 +94,10 @@ typedef struct ivas_output_setup_structure typedef struct ivas_td_decorr_APD_filt_state_t { - int16_t order[IVAS_MAX_DECORR_APD_SECTIONS]; - int16_t idx[IVAS_MAX_DECORR_APD_SECTIONS]; + Word16 order[IVAS_MAX_DECORR_APD_SECTIONS]; + Word16 idx[IVAS_MAX_DECORR_APD_SECTIONS]; #ifdef IVAS_FLOAT_FIXED - Word16 coeffs[IVAS_MAX_DECORR_APD_SECTIONS]; + Word16 coeffs[IVAS_MAX_DECORR_APD_SECTIONS]; // Q15 Word32 *state[IVAS_MAX_DECORR_APD_SECTIONS]; #else float coeffs[IVAS_MAX_DECORR_APD_SECTIONS]; @@ -116,11 +116,11 @@ typedef struct ivas_td_decorr_state_t #endif ivas_td_decorr_APD_filt_state_t APD_filt_state[IVAS_MAX_DECORR_CHS]; - int16_t num_apd_outputs; - int16_t num_apd_sections; - int16_t ducking_flag; + Word16 num_apd_outputs; + Word16 num_apd_sections; + Word16 ducking_flag; - int16_t offset; + Word16 offset; } ivas_td_decorr_state_t; @@ -132,8 +132,8 @@ typedef struct ivas_td_decorr_state_t /*Onset detector*/ typedef struct dirac_onset_detection_params_structure { - int16_t num_freq_bands; - int16_t max_band_decorr; + Word16 num_freq_bands; + Word16 max_band_decorr; } DIRAC_ONSET_DETECTION_PARAMS; @@ -153,11 +153,11 @@ typedef struct dirac_onset_detection_state_structure /*Decorrelator*/ typedef struct dirac_decorr_params_structure { - int16_t max_band_decorr; - int16_t max_frequency; + Word16 max_band_decorr; + Word16 max_frequency; - int16_t *pre_delay; - int16_t *filter_length; + Word16 *pre_delay; + Word16 *filter_length; #ifndef IVAS_FLOAT_FIXED float *filter_coeff_num_real; float *filter_coeff_den_real; @@ -169,11 +169,11 @@ typedef struct dirac_decorr_params_structure Word16 *phase_coeff_real_fx; /* Q14 */ Word16 *phase_coeff_imag_fx; /* Q14 */ #endif - int16_t *split_frequency_bands; - int16_t num_split_frequency_bands; + Word16 *split_frequency_bands; + Word16 num_split_frequency_bands; - int16_t use_ducker; - int16_t add_back_onsets_on; + Word16 use_ducker; + Word16 add_back_onsets_on; DIRAC_ONSET_DETECTION_PARAMS h_onset_detection_power_params; @@ -201,23 +201,23 @@ typedef struct dirac_decorr_state_structure typedef struct ivas_spatial_parametric_rend_common_data_structure { - int16_t slot_size; - int16_t subframe_nbslots[MAX_JBM_SUBFRAMES_5MS]; - int16_t subframes_rendered; - int16_t slots_rendered; - int16_t num_slots; - int16_t render_to_md_map[MAX_JBM_SUBFRAMES_5MS * JBM_CLDFB_SLOTS_IN_SUBFRAME]; - int16_t nb_subframes; + Word16 slot_size; + Word16 subframe_nbslots[MAX_JBM_SUBFRAMES_5MS]; + Word16 subframes_rendered; + Word16 slots_rendered; + Word16 num_slots; + Word16 render_to_md_map[MAX_JBM_SUBFRAMES_5MS * JBM_CLDFB_SLOTS_IN_SUBFRAME]; + Word16 nb_subframes; - int16_t num_freq_bands; - int16_t numSimultaneousDirections; /* From 1 to 2 + MAX_NUM_OBJECTS */ - int16_t numParametricDirections; /* 1 or 2 */ - int16_t numIsmDirections; /* From 0 to MAX_NUM_OBJECTS */ + Word16 num_freq_bands; + Word16 numSimultaneousDirections; /* From 1 to 2 + MAX_NUM_OBJECTS */ + Word16 numParametricDirections; /* 1 or 2 */ + Word16 numIsmDirections; /* From 0 to MAX_NUM_OBJECTS */ - int16_t **azimuth; - int16_t **elevation; - int16_t **azimuth2; - int16_t **elevation2; + Word16 **azimuth; + Word16 **elevation; + Word16 **azimuth2; + Word16 **elevation2; #ifndef IVAS_FLOAT_FIXED float **diffuseness_vector; @@ -241,9 +241,9 @@ typedef struct ivas_spatial_parametric_rend_common_data_structure #endif /* Metadata access indices and buffer size */ - int16_t dirac_bs_md_write_idx; - int16_t dirac_read_idx; - int16_t dirac_md_buffer_length; + Word16 dirac_bs_md_write_idx; + Word16 dirac_read_idx; + Word16 dirac_md_buffer_length; } SPAT_PARAM_REND_COMMON_DATA, *SPAT_PARAM_REND_COMMON_DATA_HANDLE; @@ -335,9 +335,9 @@ typedef struct dirac_dec_stack_mem /*Output synthesis*/ typedef struct dirac_output_synthesis_params_structure { - int16_t max_band_decorr; + Word16 max_band_decorr; - int16_t use_onset_filters; + Word16 use_onset_filters; #ifndef IVAS_FLOAT_FIXED float *interpolator; @@ -348,8 +348,8 @@ typedef struct dirac_output_synthesis_params_structure Word16 *alpha_synthesis_fx; /* Q15 */ Word16 *alpha_synthesis_fast_fx; /* Q15 */ #endif - int16_t numAlphas; - int16_t numAlphasFast; + Word16 numAlphas; + Word16 numAlphasFast; #ifdef IVAS_FLOAT_FIXED Word32 *proto_matrix_fx; @@ -521,7 +521,7 @@ typedef struct MASA_TRANSPORT_SIGNAL_TYPE current_stereo_type; MASA_TRANSPORT_SIGNAL_TYPE type_change_direction; - int16_t dipole_freq_range[2]; + Word16 dipole_freq_range[2]; #ifndef IVAS_FLOAT_FIXED float left_bb_power; @@ -584,8 +584,8 @@ typedef struct Word32 subtract_target_ratio_db_fx; /* Q21 */ #endif - int16_t counter; - int16_t interpolator; + Word16 counter; + Word16 interpolator; } MASA_STEREO_TYPE_DETECT; @@ -597,7 +597,7 @@ typedef struct ivas_mcmasa_lfe_synth_struct #else Word16 lfeToTotalEnergyRatio_fx[MAX_PARAM_SPATIAL_SUBFRAMES]; /* Q14 */ #endif - int16_t lfeGainPrevIndex; + Word16 lfeGainPrevIndex; #ifndef IVAS_FLOAT_FIXED float transportEneSmooth; float protoLfeEneSmooth; @@ -619,41 +619,41 @@ typedef struct ivas_mcmasa_lfe_synth_struct #else Word32 *lfeSynthRingBuffer_fx; /* Q11 */ #endif - int16_t ringBufferLoPointer; - int16_t ringBufferHiPointer; + Word16 ringBufferLoPointer; + Word16 ringBufferHiPointer; #ifndef IVAS_FLOAT_FIXED float lowpassSum; #else Word32 lowpassSum_fx; /* Q11 */ #endif - int16_t ringBufferSize; + Word16 ringBufferSize; #ifndef IVAS_FLOAT_FIXED float *lfeSynthRingBuffer2; #else Word32 *lfeSynthRingBuffer2_fx; /* Q11 */ #endif - int16_t ringBufferLoPointer2; + Word16 ringBufferLoPointer2; #ifndef IVAS_FLOAT_FIXED float lowpassSum2; #else Word32 lowpassSum2_fx; /* Q11 */ #endif - int16_t ringBufferSize2; + Word16 ringBufferSize2; #ifndef IVAS_FLOAT_FIXED float *delayBuffer_syncLp; #else Word32 *delayBuffer_syncLp_fx; /* Q11 */ #endif - int16_t delayBuffer_syncLp_size; + Word16 delayBuffer_syncLp_size; #ifndef IVAS_FLOAT_FIXED float *delayBuffer_syncDirAC; #else Word32 *delayBuffer_syncDirAC_fx; /* Q11 */ #endif - int16_t delayBuffer_syncDirAC_size; + Word16 delayBuffer_syncDirAC_size; #ifndef IVAS_FLOAT_FIXED float lfeGainPrev; @@ -673,7 +673,7 @@ typedef struct ivas_dirac_rend_data_structure IVAS_OUTPUT_SETUP hOutSetup; /*Parameter estimation*/ - int16_t index_buffer_intensity; + Word16 index_buffer_intensity; #ifndef IVAS_FLOAT_FIXED float *buffer_intensity_real[DIRAC_NUM_DIMS][DIRAC_NO_COL_AVG_DIFF]; float *buffer_energy; @@ -697,19 +697,19 @@ typedef struct ivas_dirac_rend_data_structure #endif /*Decoder parameters */ /*Prototypes*/ - int16_t num_outputs_dir; - int16_t num_outputs_diff; - int16_t num_protos_dir; - int16_t num_protos_diff; - int16_t num_protos_ambi; + Word16 num_outputs_dir; + Word16 num_outputs_diff; + Word16 num_protos_dir; + Word16 num_protos_diff; + Word16 num_protos_ambi; DIRAC_SYNTHESIS_CONFIG synthesisConf; DIRAC_PANNING_CONFIG panningConf; /* prototype computing */ - int16_t *proto_index_dir; - int16_t *proto_index_diff; + Word16 *proto_index_dir; + Word16 *proto_index_diff; - int16_t proto_signal_decorr_on; + Word16 proto_signal_decorr_on; /*Decoder states=memories*/ #ifndef IVAS_FLOAT_FIXED @@ -727,9 +727,9 @@ typedef struct ivas_dirac_rend_data_structure DIRAC_DEC_STACK_MEM stack_mem; MASA_STEREO_TYPE_DETECT *masa_stereo_type_detect; - int16_t num_ele_spk_no_diffuse_rendering; + Word16 num_ele_spk_no_diffuse_rendering; - const int16_t *sba_map_tc; + const Word16 *sba_map_tc; DIRAC_OUTPUT_SYNTHESIS_PARAMS h_output_synthesis_psd_params; DIRAC_OUTPUT_SYNTHESIS_STATE h_output_synthesis_psd_state; @@ -748,7 +748,7 @@ typedef struct ivas_dirac_rend_data_structure * with a precalculated inverse matrix */ typedef struct vbap_vs_triplet_structure { - uint8_t speaker_node[3]; + UWord8 speaker_node[3]; #ifndef IVAS_FLOAT_FIXED float inverse_matrix[3][3]; #else @@ -763,8 +763,8 @@ typedef struct vbap_vs_triplet_structure typedef struct triplet_search_structure { VBAP_VS_TRIPLET *triplets; - int16_t num_triplets; - int16_t initial_search_indices[VBAP_NUM_SEARCH_SECTORS]; + Word16 num_triplets; + Word16 initial_search_indices[VBAP_NUM_SEARCH_SECTORS]; } VBAP_SEARCH_STRUCT; @@ -773,12 +773,12 @@ typedef struct triplet_search_structure typedef struct vbap_data_structure { VBAP_SEARCH_STRUCT search_struct[2]; /* Default to max two groups in this implementation */ - int16_t num_search_structs; - int16_t num_speaker_nodes; - int16_t num_speaker_nodes_internal; - int16_t top_virtual_speaker_node_index; /* These indices can be negative */ - int16_t bottom_virtual_speaker_node_index; - int16_t back_virtual_speaker_node_index; + Word16 num_search_structs; + Word16 num_speaker_nodes; + Word16 num_speaker_nodes_internal; + Word16 top_virtual_speaker_node_index; /* These indices can be negative */ + Word16 bottom_virtual_speaker_node_index; + Word16 back_virtual_speaker_node_index; #ifdef IVAS_FLOAT_FIXED Word16 *bottom_virtual_speaker_node_division_gains_fx; Word16 *top_virtual_speaker_node_division_gains_fx; @@ -904,7 +904,7 @@ typedef struct ivas_dirac_dec_binaural_data_structure float earlyPartEneCorrection[CLDFB_NO_CHANNELS_MAX]; #endif REVERB_STRUCT_HANDLE hReverb; - uint8_t renderStereoOutputInsteadOfBinaural; + UWord8 renderStereoOutputInsteadOfBinaural; #ifndef IVAS_FLOAT_FIXED float frameMeanDiffuseness[CLDFB_NO_CHANNELS_MAX]; float processMtxRePrev[BINAURAL_CHANNELS][BINAURAL_CHANNELS + MAX_NUM_OBJECTS][CLDFB_NO_CHANNELS_MAX]; @@ -968,7 +968,7 @@ typedef struct ivas_dirac_dec_binaural_data_structure Word32 diffuseFieldCoherenceY_fx[BINAURAL_COHERENCE_DIFFERENCE_BINS]; Word32 diffuseFieldCoherenceZ_fx[BINAURAL_COHERENCE_DIFFERENCE_BINS]; #endif - uint16_t useTdDecorr; + UWord16 useTdDecorr; ivas_td_decorr_state_t *hTdDecorr; #ifndef IVAS_FLOAT_FIXED float reqularizationFactor; @@ -1046,8 +1046,8 @@ typedef struct EFAP_VERTEX typedef struct EFAP_VERTEX_DATA { EFAP_VERTEX *vertexArray; /* Array of vertices */ - int16_t numVtx; /* Number of vertices */ - int16_t *vtxOrder; /* Array that indicates the order of the vertex ranked by increasing azimuth */ + Word16 numVtx; /* Number of vertices */ + Word16 *vtxOrder; /* Array that indicates the order of the vertex ranked by increasing azimuth */ } EFAP_VERTEX_DATA; #ifndef IVAS_FLOAT_FIXED @@ -1073,22 +1073,22 @@ typedef struct EFAP_POLYSET #endif typedef struct EFAP_LS_TRIANGLE { - int16_t LS[3]; /* Array indicating the loudspeaker index of the triangle vertices */ + Word16 LS[3]; /* Array indicating the loudspeaker index of the triangle vertices */ } EFAP_LS_TRIANGLE; typedef struct EFAP_POLYSET_DATA { EFAP_POLYSET polysetArray[EFAP_MAX_POLY_SET]; /* Array of polygons */ - int16_t numPoly; /* Number of polygons */ + Word16 numPoly; /* Number of polygons */ EFAP_LS_TRIANGLE triArray[EFAP_MAX_POLY_SET]; /* Array of triangles */ - int16_t numTri; /* Number of triangles */ + Word16 numTri; /* Number of triangles */ } EFAP_POLYSET_DATA; typedef struct EFAP { - int16_t numSpk; /* Number of loudspeakers */ + Word16 numSpk; /* Number of loudspeakers */ #ifndef IVAS_FLOAT_FIXED float *aziSpk; /* Loudspeaker azimuths */ float *eleSpk; /* Loudspeaker elevations */ @@ -1107,7 +1107,7 @@ typedef struct EFAP Word32 *bufferLong_fx; /* tmp buffer that will be given as a parameter for computing the gain; this is a 1D array of length numVtx */ Word32 *bufferShort_fx; /* tmp buffer that will be given as a parameter for computing the gain; this is the result of downMixMatrix*bufferLong, length is numSpk */ #endif - int16_t numTot; /* Total number of real + ghost loudspeakers, used later for freeing memory */ + Word16 numTot; /* Total number of real + ghost loudspeakers, used later for freeing memory */ } EFAP, *EFAP_HANDLE; @@ -1317,21 +1317,21 @@ typedef struct ivas_rev_delay_line_t #else Word32 *pBuffer_fx; #endif - uint16_t MaxDelay; - int16_t Delay; - uint16_t BufferPos; + UWord16 MaxDelay; + Word16 Delay; + UWord16 BufferPos; #ifndef IVAS_FLOAT_FIXED float Gain; #else - Word16 Gain_fx; + Word16 Gain_fx; // Q14 #endif } ivas_rev_delay_line_t; typedef struct ivas_rev_iir_filter_t { - uint16_t MaxTaps; - uint16_t nr_taps; - uint16_t isFIR; + UWord16 MaxTaps; + UWord16 nr_taps; + UWord16 isFIR; #ifndef IVAS_FLOAT_FIXED float Output; float CoefA[IVAS_REV_MAX_IIR_FILTER_LENGTH]; @@ -1397,14 +1397,14 @@ typedef struct ivas_reverb_state_t ivas_rev_delay_line_t predelay_line; Word32 *pPredelay_buffer_fx; /* jot reverberator: */ - uint16_t nr_of_branches; /* number of feedback loops */ + UWord16 nr_of_branches; /* number of feedback loops */ ivas_rev_delay_line_t delay_line[IVAS_REV_MAX_NR_BRANCHES]; /* feedback loop delays */ Word32 *loop_delay_buffer_fx[IVAS_REV_MAX_NR_BRANCHES]; /* feedback loop delay sample buffers */ ivas_rev_iir_filter_t t60[IVAS_REV_MAX_NR_BRANCHES]; /* feedback loop filters */ Word32 gain_matrix_fx[IVAS_REV_MAX_NR_BRANCHES][IVAS_REV_MAX_NR_BRANCHES]; /* feedback matrix */ Word16 mixer_fx[BINAURAL_CHANNELS][IVAS_REV_MAX_NR_BRANCHES]; /* binauralization filters: */ - int16_t do_corr_filter; + Word16 do_corr_filter; ivas_reverb_t2f_f2t_t fft_filter_ols; ivas_reverb_fft_filter_t fft_filter_correl_0; ivas_reverb_fft_filter_t fft_filter_correl_1; @@ -1473,24 +1473,24 @@ typedef struct float abs_coeff[IVAS_ROOM_ABS_COEFF]; float list_orig[3]; #else - Word32 room_L_fx; - Word32 room_W_fx; - Word32 room_H_fx; - Word32 abs_coeff_fx[IVAS_ROOM_ABS_COEFF]; - Word32 list_orig_fx[3]; + Word32 room_L_fx; // Q22 + Word32 room_W_fx; // Q22 + Word32 room_H_fx; // Q22 + Word32 abs_coeff_fx[IVAS_ROOM_ABS_COEFF]; // Q30 + Word32 list_orig_fx[3]; // Q22 #endif } shoebox_config_t; /* Structure to hold the corrected( bounded ) source and listener positions */ typedef struct { - uint16_t isCartesian; - uint16_t isRelative; - uint16_t isZHeight; - uint16_t isRadians; - uint16_t MAX_SOURCES; - uint16_t max_bands; - uint16_t REF_ORDER; + UWord16 isCartesian; + UWord16 isRelative; + UWord16 isZHeight; + UWord16 isRadians; + UWord16 MAX_SOURCES; + UWord16 max_bands; + UWord16 REF_ORDER; #ifndef IVAS_FLOAT_FIXED float src_pos[75]; @@ -1501,15 +1501,15 @@ typedef struct float soundspeed; float air_coeff; #else - Word32 src_dist_fx[25]; - Word32 list_pos_fx[3]; - Word32 src_pos_fx[75]; - Word32 radius_fx; - Word32 min_wall_dist_fx; - Word32 soundspeed_fx; - Word32 air_coeff_fx; + Word32 src_dist_fx[25]; // Q22 + Word32 list_pos_fx[3]; // Q22 + Word32 src_pos_fx[75]; // Q22 + Word32 radius_fx; // Q30 + Word32 min_wall_dist_fx; // Q22 + Word32 soundspeed_fx; // Q31 + Word32 air_coeff_fx; // Q31 #endif // IVAS_FLOAT_FIXED - uint16_t nSrc; + UWord16 nSrc; shoebox_config_t cal; @@ -1520,7 +1520,7 @@ typedef struct shoebox_data_t #ifndef IVAS_FLOAT_FIXED float data[150]; #else - Word32 data_fx[150]; + Word32 data_fx[150]; // Q22 #endif Word32 size[1]; @@ -1528,8 +1528,8 @@ typedef struct shoebox_data_t typedef struct { - uint16_t n_sources; - uint16_t n_ref; + UWord16 n_sources; + UWord16 n_ref; shoebox_data_t times; shoebox_data_t gains; shoebox_data_t az_angle; @@ -1584,24 +1584,24 @@ typedef struct er_struct_t typedef struct { - int16_t modelROM; /* Flag that indicates that the model resides in ROM (controls init/dealloc). */ - int16_t UseItdModel; /* Controls whether ITD model is used. */ - int16_t SplineDegree; /* Degree of the spline functions */ - int16_t K; /* Length of filter */ - int16_t elevDim2; - int16_t elevDim3; - int16_t AlphaN; /* Number of rows in Alpha matrices */ - int16_t num_unique_azim_splines; - int16_t elevSegSamples; - - int16_t elevBsLen[HRTF_MODEL_BSPLINE_NUM_COEFFS]; - int16_t elevBsStart[HRTF_MODEL_BSPLINE_NUM_COEFFS]; - const int16_t *azimDim2; - const int16_t *azimDim3; - const int16_t *azim_start_idx; - const int16_t *azimSegSamples; - const int16_t *azimShapeIdx; - const int16_t *azimShapeSampFactor; + Word16 modelROM; /* Flag that indicates that the model resides in ROM (controls init/dealloc). */ + Word16 UseItdModel; /* Controls whether ITD model is used. */ + Word16 SplineDegree; /* Degree of the spline functions */ + Word16 K; /* Length of filter */ + Word16 elevDim2; + Word16 elevDim3; + Word16 AlphaN; /* Number of rows in Alpha matrices */ + Word16 num_unique_azim_splines; + Word16 elevSegSamples; + + Word16 elevBsLen[HRTF_MODEL_BSPLINE_NUM_COEFFS]; + Word16 elevBsStart[HRTF_MODEL_BSPLINE_NUM_COEFFS]; + const Word16 *azimDim2; + const Word16 *azimDim3; + const Word16 *azim_start_idx; + const Word16 *azimSegSamples; + const Word16 *azimShapeIdx; + const Word16 *azimShapeSampFactor; #ifdef IVAS_FLOAT_FIXED const Word32 *elevKSeq_fx; /* Array, N x elevDim2 x elevDim3 */ @@ -1625,9 +1625,9 @@ typedef struct const float **azimBsShape; #endif // IVAS_FLOAT_FIXED - int16_t azimDim3Max; - int16_t iSecFirst[HRTF_MODEL_N_SECTIONS]; /* Indices for start of sections */ - int16_t iSecLast[HRTF_MODEL_N_SECTIONS]; /* Indices for end of sections */ + Word16 azimDim3Max; + Word16 iSecFirst[HRTF_MODEL_N_SECTIONS]; /* Indices for start of sections */ + Word16 iSecLast[HRTF_MODEL_N_SECTIONS]; /* Indices for end of sections */ #ifndef IVAS_FLOAT_FIXED const float *EL; /* Array, size (AlphaN*HRTF_MODEL_N_SECTIONS) */ const float *ER; /* Array, size (AlphaN*HRTF_MODEL_N_SECTIONS) */ @@ -1656,12 +1656,12 @@ typedef struct float *elevKSeq_dyn; float *elevBsShape_dyn; #endif - int16_t *azimDim2_dyn; - int16_t *azimDim3_dyn; - int16_t *azim_start_idx_dyn; - int16_t *azimSegSamples_dyn; - int16_t *azimShapeIdx_dyn; - int16_t *azimShapeSampFactor_dyn; + Word16 *azimDim2_dyn; + Word16 *azimDim3_dyn; + Word16 *azim_start_idx_dyn; + Word16 *azimSegSamples_dyn; + Word16 *azimShapeIdx_dyn; + Word16 *azimShapeSampFactor_dyn; #ifdef IVAS_FLOAT_FIXED Word32 **azimBsShape_dyn_fx; #else @@ -1672,33 +1672,33 @@ typedef struct typedef struct { - int16_t N; /* Polynomial degree */ + Word16 N; /* Polynomial degree */ - int16_t elevDim2; - int16_t elevDim3; + Word16 elevDim2; + Word16 elevDim3; #ifndef IVAS_FLOAT_FIXED const float *elevKSeq; /* Array, length elevDim3-2 */ #endif - int16_t azimDim2; - int16_t azimDim3; + Word16 azimDim2; + Word16 azimDim3; #ifndef IVAS_FLOAT_FIXED const float *azimKSeq; /* Array, length azimDim3-2 */ const float *W; /* Array, size (elevDim3*azimDim3) x K */ #endif - int16_t azimBsLen[HRTF_MODEL_BSPLINE_NUM_COEFFS]; - int16_t azimBsStart[HRTF_MODEL_BSPLINE_NUM_COEFFS]; + Word16 azimBsLen[HRTF_MODEL_BSPLINE_NUM_COEFFS]; + Word16 azimBsStart[HRTF_MODEL_BSPLINE_NUM_COEFFS]; #ifndef IVAS_FLOAT_FIXED const float *azimBsShape; #endif - int16_t azimSegSamples; + Word16 azimSegSamples; - int16_t elevBsLen[HRTF_MODEL_BSPLINE_NUM_COEFFS]; - int16_t elevBsStart[HRTF_MODEL_BSPLINE_NUM_COEFFS]; + Word16 elevBsLen[HRTF_MODEL_BSPLINE_NUM_COEFFS]; + Word16 elevBsStart[HRTF_MODEL_BSPLINE_NUM_COEFFS]; #ifndef IVAS_FLOAT_FIXED const float *elevBsShape; #endif - int16_t elevSegSamples; + Word16 elevSegSamples; #ifndef IVAS_FLOAT_FIXED float resamp_factor; #else @@ -1743,7 +1743,7 @@ typedef struct #else Word32 val_fx; #endif - int16_t i; + Word16 i; } ValueIndex_t; @@ -1757,8 +1757,8 @@ typedef struct #endif ValueIndex_t BMEnergiesL[HRTF_MODEL_BSPLINE_NUM_COEFFS_SQ]; ValueIndex_t BMEnergiesR[HRTF_MODEL_BSPLINE_NUM_COEFFS_SQ]; - int16_t UseIndsL[HRTF_MODEL_BSPLINE_NUM_COEFFS_SQ]; - int16_t UseIndsR[HRTF_MODEL_BSPLINE_NUM_COEFFS_SQ]; + Word16 UseIndsL[HRTF_MODEL_BSPLINE_NUM_COEFFS_SQ]; + Word16 UseIndsR[HRTF_MODEL_BSPLINE_NUM_COEFFS_SQ]; #ifndef IVAS_FLOAT_FIXED float *hrfModL; float *hrfModR; @@ -1786,7 +1786,7 @@ typedef struct /* Mixer listener */ typedef struct { - int16_t PoseUpdated; + Word16 PoseUpdated; #ifdef IVAS_FLOAT_FIXED Word32 Pos_fx[3]; Word16 Pos_q; @@ -1802,16 +1802,16 @@ typedef struct float Vel[3]; #endif // IVAS_FLOAT_FIXED - int16_t VelUpdated; + Word16 VelUpdated; } TDREND_MIX_Listener_t; /* HR filter */ typedef struct TDREND_HRFILT_FiltSet_struct { - int32_t SampleRate; /* Sample rate of the HR filter */ - int16_t NumPos; - int16_t NumElev; + Word32 SampleRate; /* Sample rate of the HR filter */ + Word16 NumPos; + Word16 NumElev; #ifndef IVAS_FLOAT_FIXED float Dist; float *ItdSet_p; @@ -1819,7 +1819,7 @@ typedef struct TDREND_HRFILT_FiltSet_struct Word32 Dist_fx; Word32 *ItdSet_p_fx; #endif - int16_t FiltLength; + Word16 FiltLength; #ifndef IVAS_FLOAT_FIXED float *Azim_p; float *Elev_p; @@ -1883,18 +1883,18 @@ typedef struct /* Mixer spatial specification */ typedef struct { - int16_t UseCommonDistAttenModel; /* Common distance attenuation model flag */ + Word16 UseCommonDistAttenModel; /* Common distance attenuation model flag */ TDREND_DistAttenModel_t DistAttenModel; /* Distance attenuation model */ } TDREND_MixSpatSpec_t; typedef struct TDREND_SRC_REND_s { - int16_t InputAvailable; + Word16 InputAvailable; TDREND_PlayStatus_t PlayStatus; /* Gains */ - int16_t SrcGainUpdated; + Word16 SrcGainUpdated; #ifdef IVAS_FLOAT_FIXED Word16 SrcGain_p_fx[SPAT_BIN_MAX_INPUT_CHANNELS]; // Q14 Word16 SrcGainMin_p_fx[SPAT_BIN_MAX_INPUT_CHANNELS]; @@ -1913,7 +1913,7 @@ typedef struct TDREND_SRC_REND_s /* Source spatial parameters */ typedef struct { - int16_t Updated; + Word16 Updated; TDREND_PosType_t PosType; #ifndef IVAS_FLOAT_FIXED float Pos_p[3 * SPAT_BIN_MAX_INPUT_CHANNELS]; @@ -1924,9 +1924,9 @@ typedef struct Word16 q_Pos_p; Word32 Front_p_fx[3 * SPAT_BIN_MAX_INPUT_CHANNELS]; // Q30 #endif // IVAS_FLOAT_FIXED - int16_t DirAttenEnabled; + Word16 DirAttenEnabled; TDREND_DirAtten_t DirAtten; - int16_t DistAttenEnabled; + Word16 DistAttenEnabled; TDREND_DistAtten_t DistAtten; } TDREND_SRC_SPATIAL_t; @@ -1940,9 +1940,9 @@ typedef struct #endif TDREND_SRC_SPATIAL_t *SrcSpatial_p; TDREND_SRC_REND_t *SrcRend_p; - int16_t itd; - int16_t previtd; - int16_t filterlength; + Word16 itd; + Word16 previtd; + Word16 filterlength; #ifdef IVAS_FLOAT_FIXED Word32 mem_itd_fx[ITD_MEM_LEN]; /* Q11 */ Word32 mem_hrf_left_fx[SFX_SPAT_BIN_MAX_FILTER_LENGTH - 1]; @@ -1974,8 +1974,8 @@ typedef struct ivas_binaural_td_rendering_struct { TDREND_MixSpatSpec_t *TdRend_MixSpatSpec_p; TDREND_DirAtten_t *DirAtten_p; - int16_t NumOfSrcs; - int16_t MaxSrcInd; + Word16 NumOfSrcs; + Word16 MaxSrcInd; TDREND_SRC_t *Sources[MAX_NUM_TDREND_CHANNELS]; #ifdef IVAS_FLOAT_FIXED @@ -1987,8 +1987,8 @@ typedef struct ivas_binaural_td_rendering_struct TDREND_MIX_Listener_t *Listener_p; /* The virtual listener */ TDREND_HRFILT_FiltSet_t *HrFiltSet_p; /* HR filter set */ - int16_t UseCommonDistAttenModel; /* Use common dist atten model (TRUE/FALSE) */ - int16_t DistAttenEnabled; /* (TRUE/FALSE) */ + Word16 UseCommonDistAttenModel; /* Use common dist atten model (TRUE/FALSE) */ + Word16 DistAttenEnabled; /* (TRUE/FALSE) */ TDREND_DistAttenModel_t DistAttenModel; /* Common distance attenuation model */ } BINAURAL_TD_OBJECT_RENDERER, *BINAURAL_TD_OBJECT_RENDERER_HANDLE; @@ -2008,10 +2008,10 @@ typedef struct #ifdef IVAS_FLOAT_FIXED typedef struct ivas_hrtfs_structure { - Word32 *pOut_to_bin_re_fx[MAX_INTERN_CHANNELS][BINAURAL_CHANNELS]; - Word32 *pOut_to_bin_im_fx[MAX_INTERN_CHANNELS][BINAURAL_CHANNELS]; - Word32 *pOut_to_bin_diffuse_re_fx[BINAURAL_CHANNELS]; - Word32 *pOut_to_bin_diffuse_im_fx[BINAURAL_CHANNELS]; + Word32 *pOut_to_bin_re_fx[MAX_INTERN_CHANNELS][BINAURAL_CHANNELS]; // Q29 + Word32 *pOut_to_bin_im_fx[MAX_INTERN_CHANNELS][BINAURAL_CHANNELS]; // Q29 + Word32 *pOut_to_bin_diffuse_re_fx[BINAURAL_CHANNELS]; // Q31 + Word32 *pOut_to_bin_diffuse_im_fx[BINAURAL_CHANNELS]; // Q31 UWord16 num_iterations[MAX_INTERN_CHANNELS][BINAURAL_CHANNELS]; UWord16 num_iterations_diffuse[BINAURAL_CHANNELS]; UWord16 *pIndex_frequency_max[MAX_INTERN_CHANNELS][BINAURAL_CHANNELS]; @@ -2019,9 +2019,9 @@ typedef struct ivas_hrtfs_structure UWord16 index_frequency_max_diffuse; Word16 max_num_ir; Word16 max_num_iterations; - Word16 inv_diffuse_weight_fx[MAX_INTERN_CHANNELS]; /* inverse diffuse weights array, access one inverse weight by pInvDiffuseWeight[channel] */ + Word16 inv_diffuse_weight_fx[MAX_INTERN_CHANNELS]; /* inverse diffuse weights array, access one inverse weight by pInvDiffuseWeight[channel] Q15 */ Word32 latency_s_fx; - Word16 gain_lfe_fx; + Word16 gain_lfe_fx; // Q14 } HRTFS_DATA, *HRTFS_HANDLE; #else typedef struct ivas_hrtfs_structure @@ -2202,7 +2202,7 @@ typedef struct ivas_hrtfs_fastconv_struct float FASTCONV_FOA_latency_s; #endif - int16_t allocate_init_flag; /*Memory allocation flag 0: if the hrtf pointers are allocated at application level , 1: of allocated at ivas_binaural_hrtf_open() */ + Word16 allocate_init_flag; /*Memory allocation flag 0: if the hrtf pointers are allocated at application level , 1: of allocated at ivas_binaural_hrtf_open() */ #ifdef IVAS_FLOAT_FIXED Word32 fastconvReverberationTimes_fx[CLDFB_NO_CHANNELS_MAX]; /* Q31 */ @@ -2290,8 +2290,8 @@ typedef struct ivas_LS_setupconversion_struct #else Word32 *dmxEnergyPrev_fx[MAX_OUTPUT_CHANNELS]; #endif - int16_t sfbOffset[MAX_SFB + 2]; - int16_t sfbCnt; + Word16 sfbOffset[MAX_SFB + 2]; + Word16 sfbCnt; #ifdef IVAS_FLOAT_FIXED Word16 te_prev_exp; Word16 dmx_prev_exp; @@ -2388,8 +2388,8 @@ typedef enum typedef struct ivas_masa_external_rendering_struct { - int16_t nchan_input; - int16_t nchan_output; + Word16 nchan_input; + Word16 nchan_output; RENDERER_TYPE renderer_type; DIRAC_REND_HANDLE hDirACRend; SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom; @@ -2495,10 +2495,10 @@ typedef struct ivas_mcmasa_ana_data_structure typedef struct ivas_omasa_ana_data_structure { - int16_t nbands; + Word16 nbands; /* CLDFB analysis */ - int16_t num_Cldfb_instances; + Word16 num_Cldfb_instances; HANDLE_CLDFB_FILTER_BANK cldfbAnaEnc[MAX_NUM_OBJECTS]; /* DirAC parameter estimation */ @@ -2507,11 +2507,11 @@ typedef struct ivas_omasa_ana_data_structure float **direction_vector_m[DIRAC_NUM_DIMS]; /* Average direction vector */ #endif - int16_t band_grouping[MASA_FREQUENCY_BANDS + 1]; - int16_t block_grouping[5]; + Word16 band_grouping[MASA_FREQUENCY_BANDS + 1]; + Word16 block_grouping[5]; /* diffuseness */ - int16_t index_buffer_intensity; + Word16 index_buffer_intensity; #ifndef IVAS_FLOAT_FIXED float *buffer_intensity_real[DIRAC_NUM_DIMS][DIRAC_NO_COL_AVG_DIFF]; @@ -2560,10 +2560,10 @@ typedef struct ivas_omasa_ana_data_structure #ifdef IVAS_FLOAT_FIXED typedef struct ivas_dirac_ana_data_structure { - int16_t nbands; + Word16 nbands; /* CLDFB analysis */ - int16_t num_Cldfb_instances; + Word16 num_Cldfb_instances; HANDLE_CLDFB_FILTER_BANK cldfbAnaEnc[DIRAC_MAX_ANA_CHANS]; /* DirAC parameter estimation */ @@ -2572,11 +2572,11 @@ typedef struct ivas_dirac_ana_data_structure #else Word32 **direction_vector_m_fx[DIRAC_NUM_DIMS]; /* Average direction vector */ #endif - int16_t band_grouping[MASA_FREQUENCY_BANDS + 1]; - int16_t block_grouping[5]; + Word16 band_grouping[MASA_FREQUENCY_BANDS + 1]; + Word16 block_grouping[5]; /* diffuseness */ - int16_t index_buffer_intensity; + Word16 index_buffer_intensity; #ifndef IVAS_FLOAT_FIXED float *buffer_intensity_real[DIRAC_NUM_DIMS][DIRAC_NO_COL_AVG_DIFF]; #else @@ -2632,7 +2632,7 @@ typedef struct ivas_dirac_ana_data_structure typedef struct ivas_masa_prerend_data_structure { /* CLDFB analysis */ - int16_t num_Cldfb_instances; + Word16 num_Cldfb_instances; HANDLE_CLDFB_FILTER_BANK cldfbAnaEnc[MASA_MAX_TRANSPORT_CHANNELS]; MASA_DECODER_EXT_OUT_META_HANDLE hMasaOut; diff --git a/lib_rend/ivas_td_decorr.c b/lib_rend/ivas_td_decorr.c index 1e6632af4..ab172f972 100644 --- a/lib_rend/ivas_td_decorr.c +++ b/lib_rend/ivas_td_decorr.c @@ -90,30 +90,30 @@ static const float ivas_three_pow_frac[IVAS_MAX_DECORR_APD_SECTIONS] = { }; #else -static const Word16 ivas_hadamard_decorr_APD_coeff[IVAS_APD_16_SECT][IVAS_APD_16_SECT] = { - { 13107, 13107, 13107, 13107, 13107, 13107, 13107, 13107, 13107, 13107, 13107, 13107, 13107, 13107, 13107, 13107 }, - { 13107, -13107, 13107, -13107, 13107, -13107, 13107, -13107, 13107, -13107, 13107, -13107, 13107, -13107, 13107, -13107 }, - { 13107, 13107, -13107, -13107, 13107, 13107, -13107, -13107, 13107, 13107, -13107, -13107, 13107, 13107, -13107, -13107 }, - { 13107, -13107, -13107, 13107, 13107, -13107, -13107, 13107, 13107, -13107, -13107, 13107, 13107, -13107, -13107, 13107 }, - { 13107, 13107, 13107, 13107, -13107, -13107, -13107, -13107, 13107, 13107, 13107, 13107, -13107, -13107, -13107, -13107 }, - { 13107, -13107, 13107, -13107, -13107, 13107, -13107, 13107, 13107, -13107, 13107, -13107, -13107, 13107, -13107, 13107 }, - { 13107, 13107, -13107, -13107, -13107, -13107, 13107, 13107, 13107, 13107, -13107, -13107, -13107, -13107, 13107, 13107 }, - { 13107, -13107, -13107, 13107, -13107, 13107, 13107, -13107, 13107, -13107, -13107, 13107, -13107, 13107, 13107, -13107 }, - { 13107, 13107, 13107, 13107, 13107, 13107, 13107, 13107, -13107, -13107, -13107, -13107, -13107, -13107, -13107, -13107 }, - { 13107, -13107, 13107, -13107, 13107, -13107, 13107, -13107, -13107, 13107, -13107, 13107, -13107, 13107, -13107, 13107 }, - { 13107, 13107, -13107, -13107, 13107, 13107, -13107, -13107, -13107, -13107, 13107, 13107, -13107, -13107, 13107, 13107 }, - { 13107, -13107, -13107, 13107, 13107, -13107, -13107, 13107, -13107, 13107, 13107, -13107, -13107, 13107, 13107, -13107 }, - { 13107, 13107, 13107, 13107, -13107, -13107, -13107, -13107, -13107, -13107, -13107, -13107, 13107, 13107, 13107, 13107 }, - { 13107, -13107, 13107, -13107, -13107, 13107, -13107, 13107, -13107, 13107, -13107, 13107, 13107, -13107, 13107, -13107 }, - { 13107, 13107, -13107, -13107, -13107, -13107, 13107, 13107, -13107, -13107, 13107, 13107, 13107, 13107, -13107, -13107 }, - { 13107, -13107, -13107, 13107, -13107, 13107, 13107, -13107, -13107, 13107, 13107, -13107, 13107, -13107, -13107, 13107 } +static const Word16 ivas_hadamard_decorr_APD_coeff[IVAS_APD_16_SECT][IVAS_APD_16_SECT] = { /* Q15 */ + { 13107, 13107, 13107, 13107, 13107, 13107, 13107, 13107, 13107, 13107, 13107, 13107, 13107, 13107, 13107, 13107 }, + { 13107, -13107, 13107, -13107, 13107, -13107, 13107, -13107, 13107, -13107, 13107, -13107, 13107, -13107, 13107, -13107 }, + { 13107, 13107, -13107, -13107, 13107, 13107, -13107, -13107, 13107, 13107, -13107, -13107, 13107, 13107, -13107, -13107 }, + { 13107, -13107, -13107, 13107, 13107, -13107, -13107, 13107, 13107, -13107, -13107, 13107, 13107, -13107, -13107, 13107 }, + { 13107, 13107, 13107, 13107, -13107, -13107, -13107, -13107, 13107, 13107, 13107, 13107, -13107, -13107, -13107, -13107 }, + { 13107, -13107, 13107, -13107, -13107, 13107, -13107, 13107, 13107, -13107, 13107, -13107, -13107, 13107, -13107, 13107 }, + { 13107, 13107, -13107, -13107, -13107, -13107, 13107, 13107, 13107, 13107, -13107, -13107, -13107, -13107, 13107, 13107 }, + { 13107, -13107, -13107, 13107, -13107, 13107, 13107, -13107, 13107, -13107, -13107, 13107, -13107, 13107, 13107, -13107 }, + { 13107, 13107, 13107, 13107, 13107, 13107, 13107, 13107, -13107, -13107, -13107, -13107, -13107, -13107, -13107, -13107 }, + { 13107, -13107, 13107, -13107, 13107, -13107, 13107, -13107, -13107, 13107, -13107, 13107, -13107, 13107, -13107, 13107 }, + { 13107, 13107, -13107, -13107, 13107, 13107, -13107, -13107, -13107, -13107, 13107, 13107, -13107, -13107, 13107, 13107 }, + { 13107, -13107, -13107, 13107, 13107, -13107, -13107, 13107, -13107, 13107, 13107, -13107, -13107, 13107, 13107, -13107 }, + { 13107, 13107, 13107, 13107, -13107, -13107, -13107, -13107, -13107, -13107, -13107, -13107, 13107, 13107, 13107, 13107 }, + { 13107, -13107, 13107, -13107, -13107, 13107, -13107, 13107, -13107, 13107, -13107, 13107, 13107, -13107, 13107, -13107 }, + { 13107, 13107, -13107, -13107, -13107, -13107, 13107, 13107, -13107, -13107, 13107, 13107, 13107, 13107, -13107, -13107 }, + { 13107, -13107, -13107, 13107, -13107, 13107, 13107, -13107, -13107, 13107, 13107, -13107, 13107, -13107, -13107, 13107 } }; /* For R = 3.^([0:obj.parm_APD_nSections-1]/4); Q22 */ -static const Word32 ivas_three_pow_frac[IVAS_MAX_DECORR_APD_SECTIONS] = { - 4194304, 5520015, 7264748, 9560946, 12582912, 16560043, 21794242, - 28682836, 37748736, 49680132, 65382728, 86048512, 113246208, - 149040384, 196148192, 258145536 +static const Word32 ivas_three_pow_frac[IVAS_MAX_DECORR_APD_SECTIONS] = { /* Q22 */ + 4194304, 5520015, 7264748, 9560946, 12582912, 16560043, 21794242, + 28682836, 37748736, 49680132, 65382728, 86048512, 113246208, + 149040384, 196148192, 258145536 }; #endif @@ -212,12 +212,12 @@ ivas_error ivas_td_decorr_reconfig_dec( IF( LT_32( ivas_total_brate, IVAS_24k4 ) ) { - ( *hTdDecorr )->pTrans_det->duck_mult_fac = IVAS_TDET_DUCK_MULT_FAC_PARA_BIN_LOW_BR; + ( *hTdDecorr )->pTrans_det->duck_mult_fac = IVAS_TDET_DUCK_MULT_FAC_PARA_BIN_LOW_BR; // Q29 move32(); } ELSE { - ( *hTdDecorr )->pTrans_det->duck_mult_fac = IVAS_TDET_DUCK_MULT_FAC_PARA_BIN; + ( *hTdDecorr )->pTrans_det->duck_mult_fac = IVAS_TDET_DUCK_MULT_FAC_PARA_BIN; // Q29 move32(); } } @@ -349,8 +349,7 @@ ivas_error ivas_td_decorr_dec_open_fx( ivas_td_decorr_state_t *hTdDecorr_loc; ivas_error error; - buf_len = extract_l( Mpy_32_32( output_Fs, 4294968 ) ); - // IVAS_DECORR_PARM_LOOKAHEAD_TAU * 2 ^ 31 -> 4294968 + buf_len = extract_l( Mpy_32_32( output_Fs, 4294968 ) ); // IVAS_DECORR_PARM_LOOKAHEAD_TAU * 2 ^ 31 -> 4294968 num_out_chans = sub( nchan_internal, 1 ); @@ -678,7 +677,7 @@ static void ivas_td_decorr_init( FOR( j = 0; j < hTdDecorr->num_apd_sections; j++ ) { hTdDecorr->APD_filt_state[i].order[j] = hTdDecorr->APD_filt_state[0].order[j]; - hTdDecorr->APD_filt_state[i].coeffs[j] = ivas_hadamard_decorr_APD_coeff[i][j]; + hTdDecorr->APD_filt_state[i].coeffs[j] = ivas_hadamard_decorr_APD_coeff[i][j]; // Q15 hTdDecorr->APD_filt_state[i].idx[j] = 0; move16(); @@ -825,7 +824,7 @@ void ivas_td_decorr_process( void ivas_td_decorr_APD_iir_filter_fx( ivas_td_decorr_APD_filt_state_t *filter_state, - Word32 *pIn_out, + Word32 *pIn_out, // Q11 const Word16 num_APD_sections, const Word16 length ) { @@ -838,7 +837,7 @@ void ivas_td_decorr_APD_iir_filter_fx( FOR( k = 0; k < num_APD_sections; k++ ) { Word32 *pFilt_state = filter_state->state[k]; - Word16 filt_coeff = filter_state->coeffs[k]; + Word16 filt_coeff = filter_state->coeffs[k]; // Q15 Word16 order = filter_state->order[k]; move16(); move16(); @@ -851,10 +850,10 @@ void ivas_td_decorr_APD_iir_filter_fx( tmp_pIn_buf_i = pIn[i]; move32(); - pOut[i] = Madd_32_16( pFilt_state[idx], pIn[i], filt_coeff ); + pOut[i] = Madd_32_16( pFilt_state[idx], pIn[i], filt_coeff ); // Q11 move32(); - pFilt_state[idx++] = Msub_32_16( tmp_pIn_buf_i, pOut[i], filt_coeff ); + pFilt_state[idx++] = Msub_32_16( tmp_pIn_buf_i, pOut[i], filt_coeff ); // Q11 move32(); if ( EQ_16( order, idx ) ) @@ -898,8 +897,8 @@ static void ivas_td_decorr_APD_sections_fx( void ivas_td_decorr_process_fx( ivas_td_decorr_state_t *hTdDecorr, /* i/o: SPAR Covar. decoder handle */ - Word32 *pcm_in[], /* i : input audio channels */ - Word32 **ppOut_pcm, /* o : output audio channels */ + Word32 *pcm_in[], /* i : input audio channels Q11 */ + Word32 **ppOut_pcm, /* o : output audio channels Q11 */ const Word16 output_frame /* i : output frame length */ ) { @@ -917,7 +916,7 @@ void ivas_td_decorr_process_fx( FOR( j = 0; j < output_frame; j++ ) { - ppOut_pcm[0][j] = L_shl( Mpy_32_32( ppOut_pcm[0][j], in_duck_gain[j] ), 1 ); + ppOut_pcm[0][j] = L_shl( Mpy_32_32( ppOut_pcm[0][j], in_duck_gain[j] ), 1 ); // Q11 move32(); } } @@ -937,7 +936,7 @@ void ivas_td_decorr_process_fx( { FOR( j = 0; j < output_frame; j++ ) { - ppOut_pcm[i][j] = L_shl( Mpy_32_32( ppOut_pcm[i][j], out_duck_gain[j] ), 1 ); + ppOut_pcm[i][j] = L_shl( Mpy_32_32( ppOut_pcm[i][j], out_duck_gain[j] ), 1 ); // Q11 move32(); } } -- GitLab From baacf96b3499ae6f427fef3ea2b28fdc85de9b58 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Tue, 22 Oct 2024 17:00:07 +0530 Subject: [PATCH 017/128] Fix for 3GPP issue 942: Decoder crash for MASA1 rateswitching to EXT with FER in generate_masking_noise_mdct_fx() --- lib_com/cnst.h | 1 + lib_com/prot_fx.h | 6 ++ lib_dec/acelp_core_dec_ivas_fx.c | 8 +- lib_dec/dec_tcx.c | 2 +- lib_dec/fd_cng_dec_fx.c | 123 +++++++++++++++++++++++++++++++ lib_dec/ivas_tcx_core_dec.c | 9 ++- 6 files changed, 145 insertions(+), 4 deletions(-) diff --git a/lib_com/cnst.h b/lib_com/cnst.h index 5619e905d..6bcb3ea4b 100644 --- a/lib_com/cnst.h +++ b/lib_com/cnst.h @@ -1481,6 +1481,7 @@ enum #define LOW_RATE_HQ_CORE 1 /* Signal use of Low Rate MDCT core */ #define LOW_RATE_HQ_CORE_TRAN 2 /* Signal use of Low Rate MDCT core Tran SWB */ #define NORM_MDCT_FACTOR L_FRAME8k /* Normalize Low Rate MDCT coefficients to this frame size */ +#define SQRT_NORM_MDCT_FACTOR_Q27 (1697734891) /* Normalize Low Rate MDCT coefficients to this frame size */ #define BANDS_MAX ( 4 * 8 ) #define MAX_GQLEVS 32 /* Max fine gain levels */ #define BITS_DE_CMODE 1 diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index 6befe335c..9c2e272e4 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -7486,6 +7486,12 @@ void generate_masking_noise_mdct_fx( Word32 *mdctBuffer, /* i/o: time-domain s , Word16 L_frame ); +#ifdef IVAS_FLOAT_FIXED +void generate_masking_noise_mdct_ivas_fx( Word32 *mdctBuffer, /* i/o: time-domain signal */ + Word16 *mdctBuffer_e, /* i/o: exponent time-domain signal */ + HANDLE_FD_CNG_COM st /* i/o: FD_CNG structure containing all buffers and variables */ ); +#endif + // init_dec_fx.c ivas_error init_decoder_fx( Decoder_State *st_fx, /* o: Decoder static variables structure */ diff --git a/lib_dec/acelp_core_dec_ivas_fx.c b/lib_dec/acelp_core_dec_ivas_fx.c index a16878a55..679120dbb 100644 --- a/lib_dec/acelp_core_dec_ivas_fx.c +++ b/lib_dec/acelp_core_dec_ivas_fx.c @@ -1613,7 +1613,13 @@ ivas_error acelp_core_dec_ivas_fx( { set16_fx( st->hFdCngDec->hFdCngCom->olapBufferSynth2, 0, st->hFdCngDec->hFdCngCom->fftlen ); } - generate_masking_noise_fx( psyn_fx, st->Q_syn, st->hFdCngDec->hFdCngCom, st->hFdCngDec->hFdCngCom->frameSize, 0 /*, 0, 0, st->element_mode, hStereoCng, nchan_out*/ ); + Word32 psyn_32_fx[L_FRAME16k]; + Word16 exp; + Copy_Scale_sig_16_32_no_sat( psyn_fx, psyn_32_fx, st->hFdCngDec->hFdCngCom->frameSize, sub( Q6, st->Q_syn ) ); // Q6 + Copy_Scale_sig_16_32_no_sat( st->hFdCngDec->hFdCngCom->olapBufferSynth2, st->hFdCngDec->hFdCngCom->olapBufferSynth2_fx, shl( st->hFdCngDec->hFdCngCom->frameSize, 1 ), Q15 ); // Q15 + generate_masking_noise_ivas_fx( psyn_32_fx, &exp, st->hFdCngDec->hFdCngCom, st->hFdCngDec->hFdCngCom->frameSize, 0, 0, 0, st->element_mode, hStereoCng, nchan_out ); + Copy_Scale_sig_32_16( psyn_32_fx, psyn_fx, st->hFdCngDec->hFdCngCom->frameSize, sub( st->Q_syn, exp ) ); // Q = st->Q_syn + Copy_Scale_sig_32_16( st->hFdCngDec->hFdCngCom->olapBufferSynth2_fx, st->hFdCngDec->hFdCngCom->olapBufferSynth2, shl( st->hFdCngDec->hFdCngCom->frameSize, 1 ), -Q15 ); // Q0 } } } diff --git a/lib_dec/dec_tcx.c b/lib_dec/dec_tcx.c index b952ba542..79efe8356 100644 --- a/lib_dec/dec_tcx.c +++ b/lib_dec/dec_tcx.c @@ -2088,7 +2088,7 @@ void decoder_tcx_imdct_fx( /* Generate additional comfort noise to mask potential coding artefacts */ IF( NE_16( st->flag_cna, 0 ) && NE_16( st->element_mode, IVAS_CPE_TD ) && NE_16( st->element_mode, IVAS_CPE_DFT ) && EQ_16( st->cna_dirac_flag, 0 ) ) { - generate_masking_noise_mdct_fx( x_fx, &x_e, st->hFdCngDec->hFdCngCom, L_frame ); + generate_masking_noise_mdct_ivas_fx( x_fx, &x_e, st->hFdCngDec->hFdCngCom ); FOR( Word16 ind = 0; ind < L_frame; ind++ ) { x_fx[ind] = L_shr( x_fx[ind], sub( 31, add( x_e, q_x ) ) ); diff --git a/lib_dec/fd_cng_dec_fx.c b/lib_dec/fd_cng_dec_fx.c index 2bfaa4b02..b6ba82895 100644 --- a/lib_dec/fd_cng_dec_fx.c +++ b/lib_dec/fd_cng_dec_fx.c @@ -5050,6 +5050,129 @@ void generate_masking_noise_mdct_fx( } } } + +void generate_masking_noise_mdct_ivas_fx( + Word32 *mdctBuffer, /* i/o: time-domain signal */ + Word16 *mdctBuffer_e, /* i/o: exponent time-domain signal */ + HANDLE_FD_CNG_COM hFdCngCom /* i/o: FD_CNG structure containing all buffers and variables */ ) +{ + Word16 i, sq, cnt; + Word16 cngNoiseLevelExp; + Word32 scale, temp; + Word32 sqrtNoiseLevel; + Word32 maskingNoise[2 * L_FRAME16k]; + Word32 *pMaskingNoise; + Word32 *cngNoiseLevel; + Word16 *seed; + + // PMTE(); /*IVAS CODE need to be added */ + /* pointer initializations */ + cngNoiseLevel = hFdCngCom->cngNoiseLevel; + seed = &( hFdCngCom->seed ); + + /* Compute additional CN level */ + cngNoiseLevelExp = hFdCngCom->cngNoiseLevelExp; + move16(); + + scale = ONE_IN_Q30; + move32(); + + cnt = sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ); + + /* skip noise generating if level is very low, to avoid problems with possibly running into denormals */ + IF( hFdCngCom->likelihood_noisy_speech > 0 ) + { + FOR( i = 0; i < SIZE_SCALE_TABLE_CN; i++ ) + { + test(); + test(); + IF( EQ_16( hFdCngCom->CngBandwidth, scaleTable_cn_only[i].bwmode ) && + GE_32( hFdCngCom->CngBitrate, scaleTable_cn_only[i].bitrateFrom ) && + LE_32( hFdCngCom->CngBitrate, scaleTable_cn_only[i].bitrateTo ) ) + { + BREAK; + } + } + + /* Exclude clean speech */ + scale = L_mult( scaleTable_cn_only[i].scale, hFdCngCom->likelihood_noisy_speech ); // Q30 (14 + 15 + 1) + + /* + Generate Gaussian random noise in real and imaginary parts of the FFT bins + Amplitudes are adjusted to the estimated noise level cngNoiseLevel in each bin + */ + IF( hFdCngCom->startBand == 0 ) + { + /* *cngNoiseLevel * scale * 0.5 */ + temp = Mpy_32_32( *cngNoiseLevel, scale ); // exp = cngNoiseLevelExp (cngNoiseLevelExp + Q30(scale) + 1(0.5f) - 31) + sq = cngNoiseLevelExp; + move16(); + + sqrtNoiseLevel = Sqrt32( temp, &sq ); + + rand_gauss_fx( &temp, seed, Q15 ); // Q15 + + maskingNoise[0] = L_shl( Mpy_32_32( temp, sqrtNoiseLevel ), sq ); // Q15 + move32(); + + pMaskingNoise = &maskingNoise[1]; + cngNoiseLevel++; + cnt = sub( cnt, 1 ); + } + ELSE + { + set32_fx( maskingNoise, 0, hFdCngCom->startBand ); + pMaskingNoise = maskingNoise + hFdCngCom->startBand; + } + + FOR( i = 0; i < cnt; i++ ) + { + /* MDCT bins */ + /* *cngNoiseLevel * scale * 0.5 */ + temp = Mpy_32_32( *cngNoiseLevel, scale ); // exp = cngNoiseLevelExp (cngNoiseLevelExp + Q30(scale) + 1(0.5f) - 31) + sq = cngNoiseLevelExp; + move16(); + + sqrtNoiseLevel = Sqrt32( temp, &sq ); + + rand_gauss_fx( &temp, seed, Q15 ); // Q15 + + *pMaskingNoise = L_shl( Mpy_32_32( temp, sqrtNoiseLevel ), sq ); // Q15 + move32(); + + pMaskingNoise++; + cngNoiseLevel++; + } + + /*re-normalization of energy level: M/sqrt(2)*/ + v_multc_fixed( maskingNoise, SQRT_NORM_MDCT_FACTOR_Q27, maskingNoise, hFdCngCom->stopFFTbin ); // Q11 + + scale_sig32( maskingNoise, hFdCngCom->stopFFTbin, sub( 20, *mdctBuffer_e ) ); // exp = *mdctBuffer_e + + /* Add some comfort noise on top of decoded signal */ + v_add_fixed( maskingNoise, mdctBuffer, mdctBuffer, hFdCngCom->stopFFTbin, 1 ); + *mdctBuffer_e = sub( *mdctBuffer_e, 1 ); + move16(); + } + ELSE + { + /* very low level case - just update random seeds */ + IF( hFdCngCom->startBand == 0 ) + { + rand_gauss_fx( &maskingNoise[0], seed, Q15 ); // Q15 + cngNoiseLevel++; + cnt = sub( cnt, 1 ); + } + + FOR( i = 0; i < cnt; i++ ) + { + rand_gauss_fx( &maskingNoise[0], seed, Q15 ); // Q15 + move32(); + } + } + + return; +} #endif #ifdef IVAS_CODE_CNG diff --git a/lib_dec/ivas_tcx_core_dec.c b/lib_dec/ivas_tcx_core_dec.c index 05734c278..4ac7c32a8 100644 --- a/lib_dec/ivas_tcx_core_dec.c +++ b/lib_dec/ivas_tcx_core_dec.c @@ -996,8 +996,13 @@ void stereo_tcx_core_dec_fx( } ELSE IF( NE_16( st->element_mode, IVAS_CPE_DFT ) ) { - // generate_masking_noise( signal_out, st->hFdCngDec->hFdCngCom, st->hFdCngDec->hFdCngCom->frameSize, 0, 0, 0, st->element_mode, hStereoCng, nchan_out ); - generate_masking_noise_fx( signal_out_fx, 0, st->hFdCngDec->hFdCngCom, st->hFdCngDec->hFdCngCom->frameSize, 0 ); + Word32 signal_out_32_fx[L_FRAME48k]; + Word16 exp; + Copy_Scale_sig_16_32_no_sat( signal_out_fx, signal_out_32_fx, st->hFdCngDec->hFdCngCom->frameSize, Q6 ); + Copy_Scale_sig_16_32_no_sat( st->hFdCngDec->hFdCngCom->olapBufferSynth2, st->hFdCngDec->hFdCngCom->olapBufferSynth2_fx, shl( st->hFdCngDec->hFdCngCom->frameSize, 1 ), Q15 ); + generate_masking_noise_ivas_fx( signal_out_32_fx, &exp, st->hFdCngDec->hFdCngCom, st->hFdCngDec->hFdCngCom->frameSize, 0, 0, 0, st->element_mode, hStereoCng, nchan_out ); + Copy_Scale_sig_32_16( signal_out_32_fx, signal_out_fx, st->hFdCngDec->hFdCngCom->frameSize, negate( exp ) ); // Q0 + Copy_Scale_sig_32_16( st->hFdCngDec->hFdCngCom->olapBufferSynth2_fx, st->hFdCngDec->hFdCngCom->olapBufferSynth2, shl( st->hFdCngDec->hFdCngCom->frameSize, 1 ), -Q15 ); // Q0 } } -- GitLab From f81dbc2978d28e2fc50273271a46da99c9e19a66 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Tue, 22 Oct 2024 17:44:44 +0530 Subject: [PATCH 018/128] Fix for 3GPP issue 947 --- lib_rend/ivas_rom_rend.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_rend/ivas_rom_rend.h b/lib_rend/ivas_rom_rend.h index f98897eca..904078982 100644 --- a/lib_rend/ivas_rom_rend.h +++ b/lib_rend/ivas_rom_rend.h @@ -186,7 +186,7 @@ extern const float ivas_reverb_default_fc[]; extern const float ivas_reverb_default_RT60[]; extern const float ivas_reverb_default_DSR[]; -Word32 release_cnst_table[4][201]; // Q31 +extern Word32 release_cnst_table[4][201]; // Q31 /*----------------------------------------------------------------------------------* * Renderer SBA & MC enc/dec matrices -- GitLab From 35e6a02a833f6ca70218074e7b8b6cb48964e2d0 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Tue, 22 Oct 2024 20:59:09 +0530 Subject: [PATCH 019/128] Fix for 3gpp issue 926: Usage of L_shl(), L_shl_o(), L_shl_sat() and L_shr(), L_shr_o(), L_shr_sat() --- lib_com/ivas_spar_com.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib_com/ivas_spar_com.c b/lib_com/ivas_spar_com.c index fb5cb5792..31e787a78 100644 --- a/lib_com/ivas_spar_com.c +++ b/lib_com/ivas_spar_com.c @@ -2077,6 +2077,7 @@ static void ivas_calc_p_coeffs_per_band_fx( Word32 cov_dd_re[IVAS_SPAR_MAX_CH - 1][IVAS_SPAR_MAX_CH - 1]; Word32 cov_uu_re[IVAS_SPAR_MAX_CH - 1][IVAS_SPAR_MAX_CH - 1]; Word16 b_ts_idx; + Word16 tmp; b_ts_idx = add( band_idx, imult1616( i_ts, IVAS_MAX_NUM_BANDS ) ); @@ -2230,7 +2231,7 @@ static void ivas_calc_p_coeffs_per_band_fx( Word16 factor_exp = 0; move16(); factor = BASOP_Util_Divide3232_Scale( L_shl( 1, q_postpred_cov_re ), factor, &factor_exp ); - factor = L_shl_sat( factor, factor_exp ); + tmp = sub( 15, factor_exp ); /* normalise Hermitian (except for rounding) cov_uu */ FOR( i = num_dmx; i < num_ch; i++ ) @@ -2240,7 +2241,7 @@ static void ivas_calc_p_coeffs_per_band_fx( IF( EQ_16( i, j ) ) { /* force diagonal to be real */ - cov_uu_re[sub( i, num_dmx )][sub( j, num_dmx )] = W_extract_l( W_shr( W_mult0_32_32( cov_uu_re[sub( i, num_dmx )][sub( j, num_dmx )], factor ), 15 ) ); + cov_uu_re[sub( i, num_dmx )][sub( j, num_dmx )] = W_extract_l( W_shr( W_mult0_32_32( cov_uu_re[sub( i, num_dmx )][sub( j, num_dmx )], factor ), tmp ) ); move32(); } ELSE @@ -3736,7 +3737,8 @@ void ivas_get_spar_md_from_dirac_fx( } - en_ratio_fac_fx = L_sub( ONE_IN_Q31, L_shl_sat( diffuseness_fx[band], 1 ) ); // assuming q of dissusion 30 + en_ratio_fac_fx = L_shl( L_sub( ONE_IN_Q30 - EPSILON_FX /* Guard to prevent overflow if diffuseness_fx is 0 */, diffuseness_fx[band] ), 1 ); // assuming q of dissusion 30 + en_ratio_fac_fx = L_max( en_ratio_fac_fx, 0 ); FOR( i = 0; i < num_ch; i++ ) { -- GitLab From 490a54a57f7efd7c4cab1b37ecb08eefbe2d8ad1 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Tue, 22 Oct 2024 22:07:35 +0530 Subject: [PATCH 020/128] Q-info updates, MSAN error fixes --- lib_com/ivas_prot_fx.h | 36 + lib_com/ivas_spar_com.c | 2495 ++++++++++++++++++++---- lib_com/prot_fx.h | 106 +- lib_com/rom_com.c | 4 +- lib_com/rom_com.h | 4 +- lib_dec/d_gain2p.c | 14 +- lib_dec/d_gain2p_fx.c | 29 +- lib_dec/dec4t64.c | 31 +- lib_dec/dec4t64_fx.c | 22 +- lib_dec/dec_LPD_fx.c | 54 +- lib_dec/dec_ace_fx.c | 107 +- lib_dec/dec_acelp_fx.c | 30 +- lib_dec/dec_acelp_tcx_main_fx.c | 43 +- lib_dec/dec_amr_wb_fx.c | 24 +- lib_dec/dec_gen_voic_fx.c | 238 +-- lib_dec/dec_higher_acelp_fx.c | 31 +- lib_dec/dec_tcx.c | 96 +- lib_dec/dec_tran_fx.c | 28 +- lib_dec/dec_uv_fx.c | 8 +- lib_dec/dlpc_avq_fx.c | 9 +- lib_dec/igf_dec_fx.c | 348 ++-- lib_dec/igf_scf_dec_fx.c | 50 +- lib_dec/init_dec_fx.c | 106 +- lib_dec/inov_dec_fx.c | 57 +- lib_dec/ivas_mono_dmx_renderer.c | 20 +- lib_dec/ivas_objectRenderer_internal.c | 14 +- lib_dec/ivas_omasa_dec.c | 42 +- lib_dec/ivas_osba_dec.c | 8 +- lib_dec/ivas_out_setup_conversion.c | 101 +- lib_dec/ivas_qmetadata_dec.c | 1059 +++++----- lib_dec/ivas_spar_md_dec.c | 702 +++---- lib_dec/ivas_stat_dec.h | 22 +- lib_dec/peak_vq_dec_fx.c | 25 +- lib_dec/pit_dec_fx.c | 58 +- lib_dec/pitch_extr_fx.c | 8 +- lib_dec/post_dec_fx.c | 73 +- lib_dec/ppp_dec_fx.c | 20 +- lib_dec/pvq_core_dec_fx.c | 40 +- lib_dec/pvq_decode_fx.c | 4 + lib_dec/range_dec_fx.c | 24 +- lib_dec/rom_dec.c | 34 +- lib_dec/rom_dec.h | 59 +- lib_dec/rst_dec_fx.c | 10 +- lib_dec/stat_dec.h | 740 +++---- lib_dec/stat_noise_uv_dec_fx.c | 12 +- lib_enc/acelp_core_enc.c | 4 +- lib_enc/ivas_core_enc.c | 9 +- lib_enc/ivas_core_pre_proc_front.c | 12 + lib_enc/ivas_cpe_enc.c | 3 + lib_enc/ivas_spar_encoder.c | 6 +- lib_enc/ivas_spar_md_enc.c | 78 +- lib_rend/ivas_efap.c | 4 + lib_rend/ivas_objectRenderer_vec.c | 46 +- lib_rend/ivas_omasa_ana.c | 106 +- lib_rend/ivas_orient_trk.c | 66 +- lib_rend/ivas_prot_rend.h | 32 +- lib_rend/ivas_rom_rend.c | 2 +- lib_rend/ivas_rom_rend.h | 72 +- lib_rend/ivas_rotation.c | 216 +- lib_rend/ivas_sba_rendering.c | 32 +- 60 files changed, 4913 insertions(+), 2820 deletions(-) diff --git a/lib_com/ivas_prot_fx.h b/lib_com/ivas_prot_fx.h index 513f686a7..07f548f32 100644 --- a/lib_com/ivas_prot_fx.h +++ b/lib_com/ivas_prot_fx.h @@ -692,6 +692,28 @@ Word16 masa_sq_fx( const Word16 cb_sz /* i : codebook size */ ); +void ivas_compute_spar_params_enc_fx( + Word32 *cov_real_fx[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + Word16 *q_cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + Word32 dm_fv_re_fx[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], + Word16 *q_dm_fv_re, + const Word16 i_ts, + Word32 ***mixer_mat_fx, + Word16 *q_mixer_mat, + const Word16 start_band, + const Word16 end_band, + const Word16 dtx_vad, + const Word16 num_ch, + const Word16 bands_bw, + const Word16 active_w, + const Word16 active_w_vlbr, + ivas_spar_md_com_cfg *hSparCfg, + ivas_spar_md_t *hSparMd, + Word32 *pWscale, + Word16 *q_Wscale, + const Word16 from_dirac, + const Word16 dyn_active_w_flag ); + void ivas_compute_spar_params_fx( Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], Word16 q_cov_real, @@ -1998,6 +2020,20 @@ Word16 set_ACELP_flag_IVAS( const Word16 cng_type /* i : CNG type */ ); +void ivas_calc_c_p_coeffs_enc_fx( + ivas_spar_md_t *pSparMd, + Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + Word16 *q_cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + const Word16 i_ts, + Word32 ***mixer_mat, + Word16 q_mixer_mat, + const Word16 num_ch, + const Word16 num_dmx, + const Word16 band_idx, + const Word16 dtx_vad, + const Word16 compute_p_flag, + const Word16 dyn_active_w_flag ); + void ivas_calc_c_p_coeffs_fx( ivas_spar_md_t *pSparMd, Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], diff --git a/lib_com/ivas_spar_com.c b/lib_com/ivas_spar_com.c index 31e787a78..1cea89b76 100644 --- a/lib_com/ivas_spar_com.c +++ b/lib_com/ivas_spar_com.c @@ -87,6 +87,51 @@ *------------------------------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED +static void ivas_get_pred_coeffs_enc_fx( + Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + Word16 *q_cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + Word32 ppPred_coeffs_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], + Word16 *q_pred_coeffs, + Word32 ppDM_Fv_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], + Word16 *q_dm_fv_re, + const Word16 in_chans, + const Word16 start_band, + const Word16 end_band, + const Word16 active_w, + const Word16 active_w_vlbr, + const Word16 dtx_vad, + const Word16 from_dirac, + const Word16 dyn_active_w_flag, + const Word16 res_ind ); + +static void ivas_get_Wscaling_factor_enc_fx( + Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + Word16 *q_cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + Word32 pred_coeffs_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], + Word16 q_pred_coeffs_re, + Word32 ***mixer_mat, + Word16 q_mixer_mat, + const Word16 start_band, + const Word16 end_band, + const Word16 dtx_vad, + const Word16 num_ch, + const Word16 *pNum_dmx, + const Word16 bands_bw, + const Word16 active_w, + const Word16 active_w_vlbr, + Word32 *pWscale, + Word16 *q_pWscale, + const Word16 dyn_active_w_flag ); + +static void ivas_calc_post_pred_per_band_enc_fx( + Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + Word16 *q_cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + Word32 ***mixer_mat, + Word16 q_mixer_mat, + const Word16 num_ch, + const Word16 band_idx, + Word32 postpred_cov_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + Word16 *q_postpred_cov_re ); static void ivas_get_pred_coeffs_fx( Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], @@ -696,10 +741,13 @@ static void ivas_get_pred_coeffs( * Calculation of prediction coefficients *-----------------------------------------------------------------------------------------*/ -static void ivas_get_pred_coeffs_fx( +static void ivas_get_pred_coeffs_enc_fx( Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + Word16 *q_cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], Word32 ppPred_coeffs_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], + Word16 *q_pred_coeffs, Word32 ppDM_Fv_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], + Word16 *q_dm_fv_re, const Word16 in_chans, const Word16 start_band, const Word16 end_band, @@ -708,203 +756,166 @@ static void ivas_get_pred_coeffs_fx( const Word16 dtx_vad, const Word16 from_dirac, const Word16 dyn_active_w_flag, - const Word16 res_ind, - Word16 *q_pred_coeffs, - Word16 *q_dm_fv_re ) + const Word16 res_ind ) { - Word16 i, j, k, b, p; + Word16 i, j, k, b; Word32 abs_value; Word32 w_norm_fac; - Word32 one_in_q; - Word32 div_factor[IVAS_MAX_NUM_BANDS]; + Word32 one_in_q, L_tmp; + Word16 q_tmp, e_tmp; + Word64 abs_value64, tmp64; + Word16 q_ppPred_coeffs_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS]; + Word16 div_factor[IVAS_MAX_NUM_BANDS]; + Word16 div_factor_e[IVAS_MAX_NUM_BANDS]; Word16 pred_dim = sub( in_chans, 1 ); - Word16 tmp_shift, prev_tmp_shift, s_div, div_shift; + Word16 tmp_shift, s_div, div_shift; IF( EQ_16( from_dirac, 1 ) ) { - w_norm_fac = ONE_IN_Q29; + w_norm_fac = 1; move32(); } ELSE { - w_norm_fac = 3 * ONE_IN_Q29; + w_norm_fac = 3; move32(); } - tmp_shift = Q30; - move16(); + IF( active_w == 0 ) { - Word32 pPred_temp[IVAS_MAX_NUM_BANDS]; - Word16 q_pred_temp; - prev_tmp_shift = 31; - move16(); + Word64 pPred_temp[IVAS_MAX_NUM_BANDS]; + Word16 q_pPred_temp[IVAS_MAX_NUM_BANDS]; - set32_fx( pPred_temp, 0, IVAS_MAX_NUM_BANDS ); + set64_fx( pPred_temp, 0, IVAS_MAX_NUM_BANDS ); + set16_fx( q_pPred_temp, 31, IVAS_MAX_NUM_BANDS ); FOR( k = start_band; k < end_band; k++ ) { - div_factor[k] = L_max( 1, cov_real[0][0][k] ); - move32(); - tmp_shift = Q30; + div_factor[k] = BASOP_Util_Divide3232_Scale( ONE_IN_Q31, L_max( 1, cov_real[0][0][k] ), &s_div ); move16(); - IF( NE_32( cov_real[0][0][k], ONE_IN_Q30 ) ) + + div_factor_e[k] = sub( add( s_div, q_cov_real[0][0][k] ), 31 ); + move16(); + } + + FOR( i = 0; i < pred_dim; i++ ) + { + FOR( k = start_band; k < end_band; k++ ) { - div_factor[k] = L_deposit_l( BASOP_Util_Divide3232_Scale( ONE_IN_Q31, div_factor[k], &s_div ) ); - move32(); - IF( s_div < 0 ) + tmp64 = W_mult_32_16( cov_real[add( i, 1 )][0][k], div_factor[k] ); + tmp_shift = W_norm( tmp64 ); + IF( tmp64 != 0 ) { - div_shift = add( 15, s_div ); - tmp_shift = Q30; + ppPred_coeffs_re[i][k] = W_extract_h( W_shl( tmp64, tmp_shift ) ); // 1 + q_cov_real[i+1][0][k] + tmp_shift + 15 - div_factor_e[k] - 32 + move32(); + q_ppPred_coeffs_re[i][k] = add( sub( add( q_cov_real[add( i, 1 )][0][k], tmp_shift ), div_factor_e[k] ), 1 + 15 - 32 ); move16(); } ELSE { - div_shift = 15; + ppPred_coeffs_re[i][k] = 0; + move32(); + q_ppPred_coeffs_re[i][k] = 31; move16(); - tmp_shift = sub( Q30, s_div ); } - div_factor[k] = L_shl( div_factor[k], div_shift ); // Q = tmp_shift - move16(); - IF( LT_16( tmp_shift, prev_tmp_shift ) ) + // IVAS_CALCULATE_SQ_ABS_N( ppPred_coeffs_re[i][k], abs_value ); + abs_value = Mpy_32_32( ppPred_coeffs_re[i][k], ppPred_coeffs_re[i][k] ); // Q = 2*q_ppPred_coeffs_re[i][k] - 31 + q_tmp = sub( shl( q_ppPred_coeffs_re[i][k], 1 ), 31 ); + + IF( GE_16( q_tmp, q_pPred_temp[k] ) ) { - FOR( p = start_band; p < k; p++ ) - { - div_factor[p] = L_shr( div_factor[p], sub( prev_tmp_shift, tmp_shift ) ); - move32(); - } - prev_tmp_shift = tmp_shift; - move16(); + abs_value = L_shr( abs_value, sub( q_tmp, q_pPred_temp[k] ) ); } - ELSE IF( GT_16( tmp_shift, prev_tmp_shift ) ) + ELSE { - div_factor[k] = L_shr( div_factor[k], sub( tmp_shift, prev_tmp_shift ) ); - move32(); - tmp_shift = prev_tmp_shift; + pPred_temp[k] = W_shr( pPred_temp[k], sub( q_pPred_temp[k], q_tmp ) ); + move64(); + q_pPred_temp[k] = q_tmp; move16(); } - } - } - - FOR( i = 0; i < pred_dim; i++ ) - { - FOR( k = start_band; k < end_band; k++ ) - { - ppPred_coeffs_re[i][k] = Mpy_32_32( cov_real[add( i, 1 )][0][k], div_factor[k] ); // Q30 + temp_shift - 31 => tmp_shift - 1 - move32(); - // IVAS_CALCULATE_SQ_ABS_N( ppPred_coeffs_re[i][k], abs_value ); - abs_value = Mpy_32_32( ppPred_coeffs_re[i][k], ppPred_coeffs_re[i][k] ); // Q = 2*tmp_shift - 2 - 31 - - pPred_temp[k] = L_add( pPred_temp[k], abs_value ); // Q= 2*tmp_shift - 2 - 31 - move32(); + pPred_temp[k] = W_add( pPred_temp[k], abs_value ); // Q = q_pPred_temp[k] + move64(); } } - *q_pred_coeffs = sub( tmp_shift, 1 ); - move16(); FOR( k = start_band; k < end_band; k++ ) { - q_pred_temp = sub( 31, sub( shl( *q_pred_coeffs, 1 ), 31 ) ); - pPred_temp[k] = Sqrt32( pPred_temp[k], &q_pred_temp ); - move32(); + tmp_shift = W_norm( pPred_temp[k] ); + e_tmp = sub( 31, sub( add( q_pPred_temp[k], tmp_shift ), 32 ) ); + L_tmp = Sqrt32( W_extract_h( W_shl( pPred_temp[k], tmp_shift ) ), &e_tmp ); - IF( LT_16( q_pred_temp, 1 ) ) + one_in_q = L_shl_sat( 1, sub( 31, e_tmp ) ); + + IF( LT_32( one_in_q, L_tmp ) ) { - pPred_temp[k] = L_shr( pPred_temp[k], add( abs_s( q_pred_temp ), 1 ) ); // Q30 - move32(); - q_pred_temp = 1; + div_factor[k] = BASOP_Util_Divide3232_Scale( one_in_q, L_tmp, &s_div ); + move16(); + div_factor[k] = shl_sat( div_factor[k], s_div ); // Q = Q15 + move16(); + div_factor_e[k] = 0; move16(); } - ELSE IF( GT_16( q_pred_temp, 1 ) ) + ELSE { - pPred_temp[k] = L_shl( pPred_temp[k], sub( abs_s( q_pred_temp ), 1 ) ); // Q30 - move32(); - q_pred_temp = 1; + div_factor[k] = ONE_IN_Q15 - 1; + move16(); + div_factor_e[k] = 0; move16(); } + } - one_in_q = L_shl( 1, sub( 31, q_pred_temp ) ); - - IF( LT_32( one_in_q, pPred_temp[k] ) ) + tmp_shift = 31; + move16(); + FOR( i = 0; i < pred_dim; i++ ) + { + FOR( k = start_band; k < end_band; k++ ) { - div_factor[k] = pPred_temp[k]; - move32(); - - div_factor[k] = L_deposit_l( BASOP_Util_Divide3232_Scale( one_in_q, div_factor[k], &s_div ) ); - move32(); - IF( s_div < 0 ) - { - div_shift = add( 15, s_div ); - tmp_shift = Q30; - move16(); - } - ELSE + IF( NE_16( div_factor[k], ONE_IN_Q15 - 1 ) ) { - div_shift = 15; - move16(); - tmp_shift = sub( Q30, s_div ); + ppPred_coeffs_re[i][k] = Mpy_32_16_1( ppPred_coeffs_re[i][k], div_factor[k] ); // Q = q_ppPred_coeffs_re[i][k] + move32(); } - div_factor[k] = L_shl( div_factor[k], div_shift ); // Q = tmp_shift - move32(); - } - ELSE - { - div_factor[k] = one_in_q; + ppDM_Fv_re[i][k] = 0; move32(); - tmp_shift = sub( 31, q_pred_temp ); - } - IF( LT_16( tmp_shift, prev_tmp_shift ) ) - { - FOR( p = start_band; p < k; p++ ) + IF( ppPred_coeffs_re[i][k] != 0 ) { - div_factor[p] = L_shr( div_factor[p], sub( prev_tmp_shift, tmp_shift ) ); - move32(); + tmp_shift = s_min( tmp_shift, add( norm_l( ppPred_coeffs_re[i][k] ), q_ppPred_coeffs_re[i][k] ) ); } - prev_tmp_shift = tmp_shift; - move16(); - } - ELSE IF( GT_16( tmp_shift, prev_tmp_shift ) ) - { - div_factor[k] = L_shr( div_factor[k], sub( tmp_shift, prev_tmp_shift ) ); - move32(); - tmp_shift = prev_tmp_shift; - move16(); } } - FOR( i = 0; i < pred_dim; i++ ) { FOR( k = start_band; k < end_band; k++ ) { - ppPred_coeffs_re[i][k] = Mpy_32_32( ppPred_coeffs_re[i][k], div_factor[k] ); // Q = q_pred_coeffs + tmp_shift -31 - move32(); - ppDM_Fv_re[i][k] = 0; + ppPred_coeffs_re[i][k] = L_shr( ppPred_coeffs_re[i][k], sub( q_ppPred_coeffs_re[i][k], tmp_shift ) ); move32(); } } - *q_pred_coeffs = sub( add( *q_pred_coeffs, tmp_shift ), 31 ); - *q_dm_fv_re = 0; + *q_pred_coeffs = tmp_shift; + move16(); + *q_dm_fv_re = 31; move16(); } ELSE { + Word64 dm_alpha64[IVAS_MAX_NUM_BANDS]; + Word64 real64[IVAS_SPAR_MAX_CH - 1]; + Word64 re, dm_y; + Word16 dm_beta_re_q; + Word16 dm_alpha64_q[IVAS_MAX_NUM_BANDS]; + Word16 dm_v_re_q[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS]; Word32 dm_alpha[IVAS_MAX_NUM_BANDS], dm_v_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS]; - Word32 real[IVAS_SPAR_MAX_CH - 1], dm_beta_re = 0, dm_g[IVAS_MAX_NUM_BANDS]; - Word32 dm_f_local, dm_w, dm_y, DM_F[IVAS_MAX_NUM_BANDS]; - Word32 num_f, den_f, passive_g /*, inv_den_f*/; + Word32 dm_g[IVAS_MAX_NUM_BANDS]; + Word16 real64_q[IVAS_SPAR_MAX_CH - 1]; + Word32 dm_f_local, dm_w, DM_F[IVAS_MAX_NUM_BANDS]; + Word16 DM_F_q[IVAS_MAX_NUM_BANDS], dm_g_q[IVAS_MAX_NUM_BANDS]; + Word32 num_f, den_f, passive_g, dm_beta_re /*, inv_den_f*/; Word32 activew_quad_thresh, g_th_sq; Word32 L_tmp1, L_tmp2; - Word16 L_tmp2_q; - Word16 dm_alpha_e, den_f_e, s_dm_f; - prev_tmp_shift = 31; - dm_alpha_e = 0; - Word16 dm_beta_re_e = 0; - move32(); - move16(); - move16(); - move16(); - + Word16 L_tmp1_q, L_tmp2_q; + Word16 den_f_e, s_dm_f; IF( EQ_16( dyn_active_w_flag, 1 ) ) { @@ -919,72 +930,91 @@ static void ivas_get_pred_coeffs_fx( g_th_sq = Mpy_32_32( activew_quad_thresh, activew_quad_thresh ); // Q27 set32_fx( dm_alpha, 0, IVAS_MAX_NUM_BANDS ); + set64_fx( dm_alpha64, 0, IVAS_MAX_NUM_BANDS ); + set16_fx( dm_alpha64_q, 31, IVAS_MAX_NUM_BANDS ); FOR( i = 1; i < in_chans; i++ ) { FOR( k = start_band; k < end_band; k++ ) { // IVAS_CALCULATE_SQ_ABS_N( cov_real[i][0][k], abs_value ); - abs_value = Mpy_32_32( cov_real[i][0][k], cov_real[i][0][k] ); // Q29 - dm_alpha[k] = L_add( dm_alpha[k], abs_value ); // Q29 - move32(); + abs_value64 = W_mult0_32_32( cov_real[i][0][k], cov_real[i][0][k] ); // Q = 2 * q_cov_real[i][0][k] + tmp_shift = W_norm( abs_value64 ); + IF( abs_value64 != 0 ) + { + q_tmp = sub( add( shl( q_cov_real[i][0][k], 1 ), tmp_shift ), 32 ); + } + ELSE + { + q_tmp = 31; + move16(); + } + IF( LT_16( q_tmp, dm_alpha64_q[k] ) ) + { + dm_alpha64[k] = W_add( W_shr( dm_alpha64[k], sub( dm_alpha64_q[k], q_tmp ) ), W_extract_h( W_shl( abs_value64, tmp_shift ) ) ); + move64(); + dm_alpha64_q[k] = q_tmp; + move16(); + } + ELSE + { + tmp_shift = sub( add( q_tmp, sub( 32, tmp_shift ) ), dm_alpha64_q[k] ); + IF( LT_16( tmp_shift, 63 ) ) + { + dm_alpha64[k] = W_add( dm_alpha64[k], W_shr( abs_value64, tmp_shift ) ); + move64(); + } + } } } FOR( k = start_band; k < end_band; k++ ) { - dm_alpha_e = 31 - Q29; - dm_alpha[k] = Sqrt32( dm_alpha[k], &dm_alpha_e ); - move32(); - - div_factor[k] = L_max( dm_alpha[k], 1 ); - move32(); - - div_factor[k] = L_deposit_l( BASOP_Util_Divide3232_Scale( ONE_IN_Q31, div_factor[k], &s_div ) ); - move32(); - IF( s_div < 0 ) + tmp_shift = W_norm( dm_alpha64[k] ); + IF( dm_alpha64[k] != 0 ) { - div_shift = add( 15, sub( s_div, dm_alpha_e ) ); - tmp_shift = Q30; - move16(); + e_tmp = sub( 31, sub( add( dm_alpha64_q[k], tmp_shift ), 32 ) ); } ELSE { - div_shift = 15; + e_tmp = 0; move16(); - tmp_shift = sub( Q30, sub( s_div, dm_alpha_e ) ); } - div_factor[k] = L_shl( div_factor[k], div_shift ); // Q = tmp_shift + dm_alpha[k] = Sqrt32( W_extract_h( W_shl( dm_alpha64[k], tmp_shift ) ), &e_tmp ); move32(); + dm_alpha64_q[k] = sub( 31, e_tmp ); + move16(); - IF( LT_16( tmp_shift, prev_tmp_shift ) ) - { - FOR( p = start_band; p < k; p++ ) - { - div_factor[p] = L_shr( div_factor[p], sub( prev_tmp_shift, tmp_shift ) ); - move32(); - } - prev_tmp_shift = tmp_shift; - move16(); - } - ELSE IF( GT_16( tmp_shift, prev_tmp_shift ) ) - { - div_factor[k] = L_shr( div_factor[k], sub( tmp_shift, prev_tmp_shift ) ); - move32(); - tmp_shift = prev_tmp_shift; - move16(); - } + div_factor[k] = BASOP_Util_Divide3232_Scale( ONE_IN_Q31, L_max( dm_alpha[k], 1 ), &s_div ); + move16(); + + div_factor_e[k] = sub( add( dm_alpha64_q[k], s_div ), 31 ); + move16(); } FOR( i = 0; i < pred_dim; i++ ) { FOR( k = start_band; k < end_band; k++ ) { - dm_v_re[i][k] = Mpy_32_32( cov_real[i + 1][0][k], div_factor[k] ); // Q30 + Qb - 31 = tmp_shift - 1 - move32(); - } - } - + tmp64 = W_mult_32_16( cov_real[add( i, 1 )][0][k], div_factor[k] ); + tmp_shift = W_norm( tmp64 ); + IF( tmp64 != 0 ) + { + dm_v_re[i][k] = W_extract_h( W_shl( tmp64, tmp_shift ) ); // 1 + q_cov_real[i+1][0][k] + tmp_shift + 15 - div_factor_e[k] - 32 + move32(); + dm_v_re_q[i][k] = add( sub( add( q_cov_real[add( i, 1 )][0][k], tmp_shift ), div_factor_e[k] ), 1 + 15 - 32 ); + move16(); + } + ELSE + { + dm_v_re[i][k] = 0; + move32(); + dm_v_re_q[i][k] = 31; + move16(); + } + } + } + IF( dtx_vad == 0 ) { dm_f_local = IVAS_ACTIVEW_DM_F_DTX_Q30; @@ -1006,60 +1036,121 @@ static void ivas_get_pred_coeffs_fx( FOR( b = start_band; b < end_band; b++ ) { - set32_fx( real, 0, pred_dim ); + set64_fx( real64, 0, pred_dim ); + set16_fx( real64_q, 31, pred_dim ); FOR( j = 0; j < pred_dim; j++ ) { FOR( k = 1; k < in_chans; k++ ) { - Word32 re; - // IVAS_RMULT_FLOAT( cov_real[j + 1][k][b], dm_v_re[k - 1][b], re ); - re = Mpy_32_32( cov_real[add( j, 1 )][k][b], dm_v_re[sub( k, 1 )][b] ); // Q30 + Q_div_factor - 1 - 31 - real[j] = L_add( real[j], re ); // tmp_shift - 2 - move32(); + re = W_mult0_32_32( cov_real[add( j, 1 )][k][b], dm_v_re[sub( k, 1 )][b] ); + tmp_shift = W_norm( re ); + IF( re != 0 ) + { + q_tmp = sub( add( add( q_cov_real[add( j, 1 )][k][b], dm_v_re_q[sub( k, 1 )][b] ), tmp_shift ), 32 ); + } + ELSE + { + q_tmp = 31; + move16(); + } + + IF( LT_16( q_tmp, real64_q[j] ) ) + { + real64[j] = W_add( W_shr( real64[j], sub( real64_q[j], q_tmp ) ), W_extract_h( W_shl( re, tmp_shift ) ) ); + move64(); + real64_q[j] = q_tmp; + move16(); + } + ELSE + { + tmp_shift = sub( add( q_tmp, sub( 32, tmp_shift ) ), real64_q[j] ); + IF( LT_16( tmp_shift, 63 ) ) + { + real64[j] = W_add( real64[j], W_shr( re, tmp_shift ) ); + move64(); + } + } } } - dm_beta_re = 0; - move32(); + + tmp64 = 0; + move64(); + dm_beta_re_q = 31; + move16(); FOR( k = 0; k < pred_dim; k++ ) { - Word32 re; // IVAS_RMULT_FLOAT( real[k], dm_v_re[k][b], re ); - re = Mpy_32_32( real[k], dm_v_re[k][b] ); // Q = 2*tmp_shift - 3 - 31 - dm_beta_re = L_add( dm_beta_re, re ); // Q = 2*tmp_shift - 3 - 31 + tmp_shift = W_norm( real64[k] ); + re = W_mult0_32_32( W_extract_h( W_shl( real64[k], tmp_shift ) ), dm_v_re[k][b] ); + q_tmp = sub( add( add( real64_q[k], dm_v_re_q[k][b] ), tmp_shift ), 32 ); + tmp_shift = W_norm( re ); + IF( re != 0 ) + { + q_tmp = sub( add( q_tmp, tmp_shift ), 32 ); + } + ELSE + { + q_tmp = 31; + move16(); + } + + IF( LT_16( q_tmp, dm_beta_re_q ) ) + { + tmp64 = W_add( W_shr( tmp64, sub( dm_beta_re_q, q_tmp ) ), W_extract_h( W_shl( re, tmp_shift ) ) ); + dm_beta_re_q = q_tmp; + move16(); + } + ELSE + { + tmp_shift = sub( add( q_tmp, sub( 32, tmp_shift ) ), dm_beta_re_q ); + IF( LT_16( tmp_shift, 63 ) ) + { + tmp64 = W_add( tmp64, W_shr( re, tmp_shift ) ); + } + } + } + tmp_shift = W_norm( tmp64 ); + dm_beta_re = W_extract_h( W_shl( tmp64, tmp_shift ) ); + IF( tmp64 != 0 ) + { + dm_beta_re_q = sub( add( dm_beta_re_q, tmp_shift ), 32 ); + } + ELSE + { + dm_beta_re_q = 31; + move16(); } - dm_beta_re_e = sub( 31, ( sub( sub( shl( tmp_shift, 1 ), 3 ), 31 ) ) ); - dm_w = cov_real[0][0][b]; // Q30 + dm_w = cov_real[0][0][b]; // q_cov_real[0][0][b] move32(); den_f = L_max( dm_w, 1 ); - passive_g = L_deposit_l( BASOP_Util_Divide3232_Scale( dm_alpha[b], den_f, &s_div ) ); + passive_g = L_deposit_l( BASOP_Util_Divide3232_Scale( dm_alpha[b], den_f, &s_div ) ); // dm_alpha64_q[b] - q_cov_real[0][0][b] + 15 - s_div - div_shift = add( ( sub( 15, ( sub( ( sub( 31, dm_alpha_e ) ), Q30 ) ) ) ), sub( s_div, 1 ) ); - passive_g = L_shl( passive_g, div_shift ); // Q = 29 + div_shift = sub( Q29, add( sub( dm_alpha64_q[b], q_cov_real[0][0][b] ), sub( 15, s_div ) ) ); + passive_g = L_shl_sat( passive_g, div_shift ); // Q = 29 IF( EQ_16( dyn_active_w_flag, 1 ) ) { dm_alpha[b] = 0; move32(); + dm_alpha64_q[b] = 0; + move16(); dm_w = 0; move32(); FOR( i = 0; i < pred_dim; i++ ) { dm_v_re[i][b] = 0; move32(); + dm_v_re_q[i][b] = 31; + move16(); } - IF( NE_16( sub( tmp_shift, 1 ), 31 ) ) - { - dm_v_re[sub( res_ind, 1 )][b] = L_shl( 1, sub( tmp_shift, 1 ) ); - move32(); - } - ELSE - { - dm_v_re[sub( res_ind, 1 )][b] = MAX_32; - move32(); - } + dm_v_re[sub( res_ind, 1 )][b] = MAX_32; + move32(); + dm_v_re_q[i][b] = 31; + move16(); + passive_g = activew_quad_thresh; move32(); } @@ -1069,46 +1160,168 @@ static void ivas_get_pred_coeffs_fx( /*linear activeW*/ dm_y = 0; move32(); + q_tmp = 31; + move16(); FOR( k = 1; k < in_chans; k++ ) { - dm_y = L_add( dm_y, L_shr( cov_real[k][k][b], 2 ) ); // Q28 + IF( GT_16( q_tmp, q_cov_real[k][k][b] ) ) + { + dm_y = W_add( W_shr( dm_y, sub( q_tmp, q_cov_real[k][k][b] ) ), cov_real[k][k][b] ); + q_tmp = q_cov_real[k][k][b]; + move16(); + } + ELSE + { + dm_y = W_add( dm_y, L_shr( cov_real[k][k][b], sub( q_cov_real[k][k][b], q_tmp ) ) ); + } + } + tmp64 = W_mult0_32_32( w_norm_fac, dm_w ); + IF( LT_16( q_tmp, q_cov_real[0][0][b] ) ) + { + tmp64 = W_shr( tmp64, sub( q_cov_real[0][0][b], q_tmp ) ); + } + ELSE + { + q_tmp = q_cov_real[0][0][b]; + move16(); + dm_y = W_shr( dm_y, sub( q_tmp, q_cov_real[0][0][b] ) ); } - den_f = L_max( dm_y, 1 ); // Q28 - den_f = L_max( den_f, Mpy_32_32( w_norm_fac, dm_w ) ); // Q28 - DM_F[b] = L_deposit_l( BASOP_Util_Divide3232_Scale( Mpy_32_32( dm_f_local, dm_alpha[b] ), den_f, &s_div ) ); // Q30 + 31 - dm_alpha_e - 31 + den_f_e - 31 => den_f_e - dm_alpha_e - 1 - move32(); + if ( GT_64( tmp64, dm_y ) ) + { + dm_y = tmp64; + move16(); + } - div_shift = add( ( sub( 15, ( sub( ( sub( 30, dm_alpha_e ) ), 28 ) ) ) ), s_div ); + tmp_shift = W_norm( dm_y ); + IF( dm_y == 0 ) + { + tmp_shift = 32; + move16(); + den_f = W_extract_l( dm_y ); + } + ELSE + { + den_f = W_extract_h( W_shl( dm_y, tmp_shift ) ); // q_tmp + tmp_shift - 32 + } - DM_F[b] = L_shl( DM_F[b], div_shift ); // Q30 - move32(); + den_f = L_max( den_f, 1 ); - DM_F[b] = L_min( ONE_IN_Q30, DM_F[b] ); + DM_F[b] = L_deposit_l( BASOP_Util_Divide3232_Scale( Mpy_32_32( dm_f_local, dm_alpha[b] ), den_f, &s_div ) ); // Q30 + dm_alpha64_q[b] - 31 - q_tmp - tmp_shift + 32 + 15 - s_div move32(); - L_tmp1 = L_add( L_shr( dm_w, 1 ), Mpy_32_32( dm_alpha[b], DM_F[b] ) ); /* Q 29*/ - L_tmp2 = Mpy_32_32( Mpy_32_32( DM_F[b], DM_F[b] ), dm_beta_re ); - L_tmp2_q = add( 29, sub( shl( tmp_shift, 1 ), 65 ) ); // simplified equation for calculating Q of L_tmp2 - L_tmp2 = L_shl( L_tmp2, sub( 29, L_tmp2_q ) ); + DM_F_q[b] = add( sub( sub( dm_alpha64_q[b], add( q_tmp, tmp_shift ) ), s_div ), ( 30 - 31 + 32 + 15 ) ); + move16(); + + IF( LT_32( ONE_IN_Q30, L_shl_sat( DM_F[b], sub( Q30, DM_F_q[b] ) ) ) ) + { + DM_F[b] = ONE_IN_Q31; + move32(); + DM_F_q[b] = Q31; + move16(); + } + + tmp64 = W_mult0_32_32( DM_F[b], DM_F[b] ); + tmp_shift = W_norm( tmp64 ); + IF( tmp64 == 0 ) + { + tmp_shift = 32; + move16(); + } + ELSE + { + tmp64 = W_shl( tmp64, tmp_shift ); + } + tmp64 = W_mult0_32_32( W_extract_h( tmp64 ), dm_beta_re ); // 2 * DM_F_q[b] + tmp_shift - 32 + dm_beta_re_q + q_tmp = sub( add( add( shl( DM_F_q[b], 1 ), tmp_shift ), dm_beta_re_q ), 32 ); + tmp_shift = sub( W_norm( tmp64 ), 2 ); + IF( tmp64 == 0 ) + { + tmp_shift = 32; + move16(); + } + ELSE + { + tmp64 = W_shl( tmp64, tmp_shift ); + } + L_tmp2 = W_extract_h( tmp64 ); + L_tmp2_q = sub( add( q_tmp, tmp_shift ), 32 ); + + tmp64 = W_shl( W_mult0_32_32( dm_alpha[b], DM_F[b] ), 1 ); + tmp_shift = sub( W_norm( tmp64 ), 2 ); + IF( tmp64 == 0 ) + { + tmp_shift = 32; + move16(); + } + ELSE + { + tmp64 = W_shl( tmp64, tmp_shift ); + } + L_tmp1 = W_extract_h( tmp64 ); // DM_F_q[b] + dm_alpha64_q[b] + tmp_shift - 32 + L_tmp1_q = sub( add( add( DM_F_q[b], dm_alpha64_q[b] ), tmp_shift ), 32 ); + + IF( LT_16( L_tmp2_q, L_tmp1_q ) ) + { + L_tmp1 = L_add( L_shr( L_tmp1, sub( L_tmp1_q, L_tmp2_q ) ), L_tmp2 ); + L_tmp1_q = L_tmp2_q; + move16(); + } + ELSE + { + L_tmp1 = L_add( L_tmp1, L_shr( L_tmp2, sub( L_tmp2_q, L_tmp1_q ) ) ); + } + + tmp_shift = sub( norm_l( dm_w ), 1 ); + L_tmp2 = L_shl( dm_w, tmp_shift ); + L_tmp2_q = add( q_cov_real[0][0][b], tmp_shift ); + + IF( LT_16( L_tmp2_q, L_tmp1_q ) ) + { + den_f = L_add( L_shr( L_tmp1, sub( L_tmp1_q, L_tmp2_q ) ), L_tmp2 ); + den_f_e = sub( 31, L_tmp2_q ); + } + ELSE + { + den_f = L_add( L_tmp1, L_shr( L_tmp2, sub( L_tmp2_q, L_tmp1_q ) ) ); + den_f_e = sub( 31, L_tmp1_q ); + } - den_f = L_add( L_tmp1, L_tmp2 ); // Q29 den_f = L_max( den_f, 1 ); - den_f_e = 31 - 29; - move16(); - L_tmp2 = Mpy_32_32( DM_F[b], dm_beta_re ); - L_tmp2_q = add( 30, sub( ( sub( shl( tmp_shift, 1 ), 34 ) ), 31 ) ); - L_tmp2 = L_shl( L_tmp2, ( sub( ( sub( 29, dm_alpha_e ) ), L_tmp2_q ) ) ); - L_tmp1 = L_shr( dm_alpha[b], ( sub( ( sub( 31, dm_alpha_e ) ), 29 ) ) ); - L_tmp1 = L_add( L_tmp1, L_tmp2 ); // Q29 + tmp64 = W_mult0_32_32( DM_F[b], dm_beta_re ); + tmp_shift = sub( W_norm( tmp64 ), 1 ); + IF( tmp64 == 0 ) + { + tmp_shift = 32; + move16(); + } + ELSE + { + tmp64 = W_shl( tmp64, tmp_shift ); + } + L_tmp2_q = sub( add( add( DM_F_q[b], dm_beta_re_q ), tmp_shift ), 32 ); + L_tmp2 = W_extract_h( tmp64 ); - dm_g[b] = L_deposit_l( BASOP_Util_Divide3232_Scale( L_tmp1, den_f, &s_div ) ); // Q29 + den_f_e - 31 + 15 - s_div - move32(); - div_shift = add( sub( 15, ( sub( 29, sub( 31, den_f_e ) ) ) ), s_div ); - dm_g[b] = L_shl( dm_g[b], div_shift ); // Q30 + tmp_shift = sub( norm_l( dm_alpha[b] ), 1 ); + + IF( LT_16( L_tmp2_q, add( dm_alpha64_q[b], tmp_shift ) ) ) + { + L_tmp1 = L_add( L_shr( dm_alpha[b], sub( dm_alpha64_q[b], L_tmp2_q ) ), L_tmp2 ); + L_tmp1_q = L_tmp2_q; + move16(); + } + ELSE + { + L_tmp1_q = add( dm_alpha64_q[b], tmp_shift ); + L_tmp1 = L_add( L_shl( dm_alpha[b], tmp_shift ), L_shr( L_tmp2, sub( L_tmp2_q, L_tmp1_q ) ) ); + } + + dm_g[b] = L_deposit_l( BASOP_Util_Divide3232_Scale( L_tmp1, den_f, &s_div ) ); // L_tmp1_q - (31 - den_f_e) + (15 - s_div) move32(); + dm_g_q[b] = add( sub( add( L_tmp1_q, den_f_e ), s_div ), 15 - 31 ); + move16(); } ELSE { @@ -1117,67 +1330,591 @@ static void ivas_get_pred_coeffs_fx( Word16 num_f_e; /* quadratic activeW */ + tmp64 = W_shl( W_mult0_32_32( dm_alpha[b], activew_quad_thresh ), 1 ); + tmp_shift = sub( W_norm( tmp64 ), 1 ); + IF( tmp64 == 0 ) + { + tmp_shift = 32; + move16(); + } + ELSE + { + tmp64 = W_shl( tmp64, tmp_shift ); + } + L_tmp1 = W_extract_h( tmp64 ); // DM_F_q[b] + dm_alpha64_q[b] + tmp_shift - 32 + L_tmp1_q = sub( add( add( DM_F_q[b], dm_alpha64_q[b] ), tmp_shift ), 32 ); - num_f = BASOP_Util_Add_Mant32Exp( dm_beta_re, dm_beta_re_e, L_negate( L_shl( Mpy_32_32( dm_alpha[b], activew_quad_thresh ), 1 ) ), add( dm_alpha_e, ( 31 - Q29 ) ), &num_f_e ); + num_f = BASOP_Util_Add_Mant32Exp( dm_beta_re, sub( 31, dm_beta_re_q ), L_negate( L_tmp1 ), sub( 31, L_tmp1_q ), &num_f_e ); - sqrt_val = L_shl( Mpy_32_32( Mpy_32_32( dm_alpha[b], dm_alpha[b] ), g_th_sq ), 2 ); /*Q27*/ - val_e = 4; + sqrt_val = L_shl( Mpy_32_32( Mpy_32_32( dm_alpha[b], dm_alpha[b] ), g_th_sq ), 2 ); + val_e = sub( 31, sub( add( sub( shl( dm_alpha64_q[b], 1 ), 31 ), 27 ), 31 ) ); move16(); - sqrt_val = BASOP_Util_Add_Mant32Exp( sqrt_val, 4, Mpy_32_32( dm_beta_re, dm_beta_re ), 2 * dm_beta_re_e, &val_e ); - sqrt_val = BASOP_Util_Add_Mant32Exp( sqrt_val, val_e, L_negate( L_shl( Mpy_32_32( Mpy_32_32( dm_beta_re, g_th_sq ), dm_w ), 2 ) ), add( dm_beta_re_e, 4 + 1 ), &val_e ); + sqrt_val = BASOP_Util_Add_Mant32Exp( sqrt_val, val_e, Mpy_32_32( dm_beta_re, dm_beta_re ), sub( 31, shl( dm_beta_re_q, 1 ) ), &val_e ); + sqrt_val = BASOP_Util_Add_Mant32Exp( sqrt_val, val_e, L_negate( L_shl( Mpy_32_32( Mpy_32_32( dm_beta_re, g_th_sq ), dm_w ), 2 ) ), sub( 31, sub( add( sub( add( dm_beta_re_q, 27 ), 31 ), q_cov_real[0][0][b] ), 31 ) ), &val_e ); // val_e = norm_l( sqrt_val ); sqrt_val = Sqrt32( sqrt_val, &val_e ); - IF( val_e < 0 ) - { - sqrt_val = L_shr( sqrt_val, abs_s( val_e ) ); - } - ELSE IF( val_e > 0 ) - { - sqrt_val = L_shl( sqrt_val, abs_s( val_e ) ); - val_e = 0; - move16(); - } - num_f = BASOP_Util_Add_Mant32Exp( num_f, num_f_e, sqrt_val, 0, &num_f_e ); + + num_f = BASOP_Util_Add_Mant32Exp( num_f, num_f_e, sqrt_val, val_e, &num_f_e ); den_f = L_shl( Mpy_32_32( dm_beta_re, g_th_sq ), 1 ); - den_f_e = add( dm_beta_re_e, 4 ); + den_f_e = add( sub( 31, dm_beta_re_q ), 4 ); den_f = L_max( den_f, 1 ); dm_g[b] = activew_quad_thresh; // Q29 move32(); + dm_g_q[b] = Q29; + move16(); DM_F[b] = BASOP_Util_Divide3232_Scale_cadence( Mpy_32_32( dm_g[b], num_f ), den_f, &s_dm_f ); move32(); - s_dm_f = add( s_dm_f, sub( add( 2, num_f_e ), den_f_e ) ); /*Resultant exp for DM_F s_dm_f +( 2 + num_f_e ) - den_f_e*/ - div_shift = sub( s_dm_f, 1 ); - DM_F[b] = L_shl( DM_F[b], div_shift ); // Q30 - move32(); + DM_F_q[b] = add( s_dm_f, sub( add( 2, num_f_e ), den_f_e ) ); + move16(); } } + *q_pred_coeffs = 31; + move16(); + *q_dm_fv_re = 31; + move16(); + FOR( i = 0; i < pred_dim; i++ ) { FOR( b = start_band; b < end_band; b++ ) { - ppPred_coeffs_re[i][b] = Mpy_32_32( dm_v_re[i][b], dm_g[b] ); // Q = tmp_shift - 1 + 30 - 31 + tmp64 = W_mult0_32_32( dm_v_re[i][b], dm_g[b] ); + tmp_shift = W_norm( tmp64 ); + IF( tmp64 == 0 ) + { + tmp_shift = 32; + move16(); + } + ELSE + { + tmp64 = W_shl( tmp64, tmp_shift ); + } + ppPred_coeffs_re[i][b] = W_extract_h( tmp64 ); // Q = dm_v_re_q[i][b] + dm_g_q[b] + tmp_shift - 32 move32(); - ppDM_Fv_re[i][b] = Mpy_32_32( dm_v_re[i][b], DM_F[b] ); + q_ppPred_coeffs_re[i][b] = sub( add( add( dm_v_re_q[i][b], dm_g_q[b] ), tmp_shift ), 32 ); + move16(); + + tmp64 = W_mult0_32_32( dm_v_re[i][b], DM_F[b] ); + tmp_shift = W_norm( tmp64 ); + IF( tmp64 == 0 ) + { + tmp_shift = 32; + move16(); + } + ELSE + { + tmp64 = W_shl( tmp64, tmp_shift ); + } + ppDM_Fv_re[i][b] = W_extract_h( tmp64 ); // Q = dm_v_re_q[i][b] + DM_F_q[b] + tmp_shift - 32 + move32(); + dm_v_re_q[i][b] = sub( add( add( dm_v_re_q[i][b], DM_F_q[b] ), tmp_shift ), 32 ); + move16(); + + *q_pred_coeffs = s_min( *q_pred_coeffs, q_ppPred_coeffs_re[i][b] ); + move16(); + *q_dm_fv_re = s_min( *q_dm_fv_re, dm_v_re_q[i][b] ); + move16(); + } + } + FOR( i = 0; i < pred_dim; i++ ) + { + FOR( b = start_band; b < end_band; b++ ) + { + ppPred_coeffs_re[i][b] = L_shr( ppPred_coeffs_re[i][b], sub( q_ppPred_coeffs_re[i][b], *q_pred_coeffs ) ); + move32(); + ppDM_Fv_re[i][b] = L_shr( ppDM_Fv_re[i][b], sub( dm_v_re_q[i][b], *q_dm_fv_re ) ); move32(); } } - *q_pred_coeffs = sub( tmp_shift, 2 ); - move16(); - *q_dm_fv_re = sub( tmp_shift, 2 ); - move16(); } return; } -#endif // IVAS_FLOAT_FIXED - -/*-----------------------------------------------------------------------------------------* - * Function ivas_get_Wscaling_factor() - * +static void ivas_get_pred_coeffs_fx( + Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + Word32 ppPred_coeffs_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], + Word32 ppDM_Fv_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], + const Word16 in_chans, + const Word16 start_band, + const Word16 end_band, + const Word16 active_w, + const Word16 active_w_vlbr, + const Word16 dtx_vad, + const Word16 from_dirac, + const Word16 dyn_active_w_flag, + const Word16 res_ind, + Word16 *q_pred_coeffs, + Word16 *q_dm_fv_re ) +{ + Word16 i, j, k, b, p; + Word32 abs_value; + Word32 w_norm_fac; + Word32 one_in_q; + Word32 div_factor[IVAS_MAX_NUM_BANDS]; + Word16 pred_dim = sub( in_chans, 1 ); + Word16 tmp_shift, prev_tmp_shift, s_div, div_shift; + + IF( EQ_16( from_dirac, 1 ) ) + { + w_norm_fac = ONE_IN_Q29; + move32(); + } + ELSE + { + w_norm_fac = 3 * ONE_IN_Q29; + move32(); + } + tmp_shift = Q30; + move16(); + IF( active_w == 0 ) + { + Word32 pPred_temp[IVAS_MAX_NUM_BANDS]; + Word16 q_pred_temp; + prev_tmp_shift = 31; + move16(); + + set32_fx( pPred_temp, 0, IVAS_MAX_NUM_BANDS ); + FOR( k = start_band; k < end_band; k++ ) + { + div_factor[k] = L_max( 1, cov_real[0][0][k] ); + move32(); + tmp_shift = Q30; + move16(); + IF( NE_32( cov_real[0][0][k], ONE_IN_Q30 ) ) + { + div_factor[k] = L_deposit_l( BASOP_Util_Divide3232_Scale( ONE_IN_Q31, div_factor[k], &s_div ) ); + move32(); + IF( s_div < 0 ) + { + div_shift = add( 15, s_div ); + tmp_shift = Q30; + move16(); + } + ELSE + { + div_shift = 15; + move16(); + tmp_shift = sub( Q30, s_div ); + } + div_factor[k] = L_shl( div_factor[k], div_shift ); // Q = tmp_shift + move16(); + + IF( LT_16( tmp_shift, prev_tmp_shift ) ) + { + FOR( p = start_band; p < k; p++ ) + { + div_factor[p] = L_shr( div_factor[p], sub( prev_tmp_shift, tmp_shift ) ); + move32(); + } + prev_tmp_shift = tmp_shift; + move16(); + } + ELSE IF( GT_16( tmp_shift, prev_tmp_shift ) ) + { + div_factor[k] = L_shr( div_factor[k], sub( tmp_shift, prev_tmp_shift ) ); + move32(); + tmp_shift = prev_tmp_shift; + move16(); + } + } + } + + FOR( i = 0; i < pred_dim; i++ ) + { + FOR( k = start_band; k < end_band; k++ ) + { + ppPred_coeffs_re[i][k] = Mpy_32_32( cov_real[add( i, 1 )][0][k], div_factor[k] ); // Q30 + temp_shift - 31 => tmp_shift - 1 + move32(); + + // IVAS_CALCULATE_SQ_ABS_N( ppPred_coeffs_re[i][k], abs_value ); + abs_value = Mpy_32_32( ppPred_coeffs_re[i][k], ppPred_coeffs_re[i][k] ); // Q = 2*tmp_shift - 2 - 31 + + pPred_temp[k] = L_add( pPred_temp[k], abs_value ); // Q= 2*tmp_shift - 2 - 31 + move32(); + } + } + *q_pred_coeffs = sub( tmp_shift, 1 ); + move16(); + + FOR( k = start_band; k < end_band; k++ ) + { + q_pred_temp = sub( 31, sub( shl( *q_pred_coeffs, 1 ), 31 ) ); + pPred_temp[k] = Sqrt32( pPred_temp[k], &q_pred_temp ); + move32(); + + IF( LT_16( q_pred_temp, 1 ) ) + { + pPred_temp[k] = L_shr( pPred_temp[k], add( abs_s( q_pred_temp ), 1 ) ); // Q30 + move32(); + q_pred_temp = 1; + move16(); + } + ELSE IF( GT_16( q_pred_temp, 1 ) ) + { + pPred_temp[k] = L_shl( pPred_temp[k], sub( abs_s( q_pred_temp ), 1 ) ); // Q30 + move32(); + q_pred_temp = 1; + move16(); + } + + one_in_q = L_shl( 1, sub( 31, q_pred_temp ) ); + + IF( LT_32( one_in_q, pPred_temp[k] ) ) + { + div_factor[k] = pPred_temp[k]; + move32(); + + div_factor[k] = L_deposit_l( BASOP_Util_Divide3232_Scale( one_in_q, div_factor[k], &s_div ) ); + move32(); + IF( s_div < 0 ) + { + div_shift = add( 15, s_div ); + tmp_shift = Q30; + move16(); + } + ELSE + { + div_shift = 15; + move16(); + tmp_shift = sub( Q30, s_div ); + } + div_factor[k] = L_shl( div_factor[k], div_shift ); // Q = tmp_shift + move32(); + } + ELSE + { + div_factor[k] = one_in_q; + move32(); + tmp_shift = sub( 31, q_pred_temp ); + } + + IF( LT_16( tmp_shift, prev_tmp_shift ) ) + { + FOR( p = start_band; p < k; p++ ) + { + div_factor[p] = L_shr( div_factor[p], sub( prev_tmp_shift, tmp_shift ) ); + move32(); + } + prev_tmp_shift = tmp_shift; + move16(); + } + ELSE IF( GT_16( tmp_shift, prev_tmp_shift ) ) + { + div_factor[k] = L_shr( div_factor[k], sub( tmp_shift, prev_tmp_shift ) ); + move32(); + tmp_shift = prev_tmp_shift; + move16(); + } + } + + FOR( i = 0; i < pred_dim; i++ ) + { + FOR( k = start_band; k < end_band; k++ ) + { + ppPred_coeffs_re[i][k] = Mpy_32_32( ppPred_coeffs_re[i][k], div_factor[k] ); // Q = q_pred_coeffs + tmp_shift -31 + move32(); + ppDM_Fv_re[i][k] = 0; + move32(); + } + } + *q_pred_coeffs = sub( add( *q_pred_coeffs, tmp_shift ), 31 ); + *q_dm_fv_re = 0; + move16(); + } + ELSE + { + Word32 dm_alpha[IVAS_MAX_NUM_BANDS], dm_v_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS]; + Word32 real[IVAS_SPAR_MAX_CH - 1], dm_beta_re = 0, dm_g[IVAS_MAX_NUM_BANDS]; + Word32 dm_f_local, dm_w, dm_y, DM_F[IVAS_MAX_NUM_BANDS]; + Word32 num_f, den_f, passive_g /*, inv_den_f*/; + Word32 activew_quad_thresh, g_th_sq; + Word32 L_tmp1, L_tmp2; + Word16 L_tmp2_q; + Word16 dm_alpha_e, den_f_e, s_dm_f; + prev_tmp_shift = 31; + dm_alpha_e = 0; + Word16 dm_beta_re_e = 0; + move32(); + move16(); + move16(); + move16(); + + + IF( EQ_16( dyn_active_w_flag, 1 ) ) + { + activew_quad_thresh = ONE_IN_Q29; + move32(); + } + ELSE + { + activew_quad_thresh = IVAS_LIN_ACTIVEW_QUAD_ACTIVEW_THRESH_Q29; + move32(); + } + g_th_sq = Mpy_32_32( activew_quad_thresh, activew_quad_thresh ); // Q27 + + set32_fx( dm_alpha, 0, IVAS_MAX_NUM_BANDS ); + + FOR( i = 1; i < in_chans; i++ ) + { + FOR( k = start_band; k < end_band; k++ ) + { + // IVAS_CALCULATE_SQ_ABS_N( cov_real[i][0][k], abs_value ); + abs_value = Mpy_32_32( cov_real[i][0][k], cov_real[i][0][k] ); // Q29 + dm_alpha[k] = L_add( dm_alpha[k], abs_value ); // Q29 + move32(); + } + } + + FOR( k = start_band; k < end_band; k++ ) + { + dm_alpha_e = 31 - Q29; + dm_alpha[k] = Sqrt32( dm_alpha[k], &dm_alpha_e ); + move32(); + + div_factor[k] = L_max( dm_alpha[k], 1 ); + move32(); + + div_factor[k] = L_deposit_l( BASOP_Util_Divide3232_Scale( ONE_IN_Q31, div_factor[k], &s_div ) ); + move32(); + IF( s_div < 0 ) + { + div_shift = add( 15, sub( s_div, dm_alpha_e ) ); + tmp_shift = Q30; + move16(); + } + ELSE + { + div_shift = 15; + move16(); + tmp_shift = sub( Q30, sub( s_div, dm_alpha_e ) ); + } + div_factor[k] = L_shl( div_factor[k], div_shift ); // Q = tmp_shift + move32(); + + IF( LT_16( tmp_shift, prev_tmp_shift ) ) + { + FOR( p = start_band; p < k; p++ ) + { + div_factor[p] = L_shr( div_factor[p], sub( prev_tmp_shift, tmp_shift ) ); + move32(); + } + prev_tmp_shift = tmp_shift; + move16(); + } + ELSE IF( GT_16( tmp_shift, prev_tmp_shift ) ) + { + div_factor[k] = L_shr( div_factor[k], sub( tmp_shift, prev_tmp_shift ) ); + move32(); + tmp_shift = prev_tmp_shift; + move16(); + } + } + + FOR( i = 0; i < pred_dim; i++ ) + { + FOR( k = start_band; k < end_band; k++ ) + { + dm_v_re[i][k] = Mpy_32_32( cov_real[i + 1][0][k], div_factor[k] ); // Q30 + Qb - 31 = tmp_shift - 1 + move32(); + } + } + + IF( dtx_vad == 0 ) + { + dm_f_local = IVAS_ACTIVEW_DM_F_DTX_Q30; + move32(); + } + ELSE + { + IF( active_w_vlbr ) + { + dm_f_local = IVAS_ACTIVEW_DM_F_VLBR_Q30; + move32(); + } + ELSE + { + dm_f_local = IVAS_ACTIVEW_DM_F_Q30; + move32(); + } + } + + FOR( b = start_band; b < end_band; b++ ) + { + set32_fx( real, 0, pred_dim ); + + FOR( j = 0; j < pred_dim; j++ ) + { + FOR( k = 1; k < in_chans; k++ ) + { + Word32 re; + + // IVAS_RMULT_FLOAT( cov_real[j + 1][k][b], dm_v_re[k - 1][b], re ); + re = Mpy_32_32( cov_real[add( j, 1 )][k][b], dm_v_re[sub( k, 1 )][b] ); // Q30 + Q_div_factor - 1 - 31 + real[j] = L_add( real[j], re ); // tmp_shift - 2 + move32(); + } + } + dm_beta_re = 0; + move32(); + FOR( k = 0; k < pred_dim; k++ ) + { + Word32 re; + // IVAS_RMULT_FLOAT( real[k], dm_v_re[k][b], re ); + re = Mpy_32_32( real[k], dm_v_re[k][b] ); // Q = 2*tmp_shift - 3 - 31 + dm_beta_re = L_add( dm_beta_re, re ); // Q = 2*tmp_shift - 3 - 31 + } + + dm_beta_re_e = sub( 31, ( sub( sub( shl( tmp_shift, 1 ), 3 ), 31 ) ) ); + dm_w = cov_real[0][0][b]; // Q30 + move32(); + den_f = L_max( dm_w, 1 ); + passive_g = L_deposit_l( BASOP_Util_Divide3232_Scale( dm_alpha[b], den_f, &s_div ) ); + + div_shift = add( ( sub( 15, ( sub( ( sub( 31, dm_alpha_e ) ), Q30 ) ) ) ), sub( s_div, 1 ) ); + passive_g = L_shl( passive_g, div_shift ); // Q = 29 + + IF( EQ_16( dyn_active_w_flag, 1 ) ) + { + dm_alpha[b] = 0; + move32(); + dm_w = 0; + move32(); + FOR( i = 0; i < pred_dim; i++ ) + { + dm_v_re[i][b] = 0; + move32(); + } + IF( NE_16( sub( tmp_shift, 1 ), 31 ) ) + { + dm_v_re[sub( res_ind, 1 )][b] = L_shl( 1, sub( tmp_shift, 1 ) ); + move32(); + } + ELSE + { + dm_v_re[sub( res_ind, 1 )][b] = MAX_32; + move32(); + } + passive_g = activew_quad_thresh; + move32(); + } + + IF( LT_32( passive_g, activew_quad_thresh ) ) + { + /*linear activeW*/ + dm_y = 0; + move32(); + + FOR( k = 1; k < in_chans; k++ ) + { + dm_y = L_add( dm_y, L_shr( cov_real[k][k][b], 2 ) ); // Q28 + } + den_f = L_max( dm_y, 1 ); // Q28 + den_f = L_max( den_f, Mpy_32_32( w_norm_fac, dm_w ) ); // Q28 + + DM_F[b] = L_deposit_l( BASOP_Util_Divide3232_Scale( Mpy_32_32( dm_f_local, dm_alpha[b] ), den_f, &s_div ) ); // Q30 + 31 - dm_alpha_e - 31 + den_f_e - 31 => den_f_e - dm_alpha_e - 1 + move32(); + + div_shift = add( ( sub( 15, ( sub( ( sub( 30, dm_alpha_e ) ), 28 ) ) ) ), s_div ); + + DM_F[b] = L_shl( DM_F[b], div_shift ); // Q30 + move32(); + + DM_F[b] = L_min( ONE_IN_Q30, DM_F[b] ); + move32(); + + L_tmp1 = L_add( L_shr( dm_w, 1 ), Mpy_32_32( dm_alpha[b], DM_F[b] ) ); /* Q 29*/ + L_tmp2 = Mpy_32_32( Mpy_32_32( DM_F[b], DM_F[b] ), dm_beta_re ); + L_tmp2_q = add( 29, sub( shl( tmp_shift, 1 ), 65 ) ); // simplified equation for calculating Q of L_tmp2 + L_tmp2 = L_shl( L_tmp2, sub( 29, L_tmp2_q ) ); + + den_f = L_add( L_tmp1, L_tmp2 ); // Q29 + den_f = L_max( den_f, 1 ); + + den_f_e = 31 - 29; + move16(); + L_tmp2 = Mpy_32_32( DM_F[b], dm_beta_re ); + L_tmp2_q = add( 30, sub( ( sub( shl( tmp_shift, 1 ), 34 ) ), 31 ) ); + L_tmp2 = L_shl( L_tmp2, ( sub( ( sub( 29, dm_alpha_e ) ), L_tmp2_q ) ) ); + L_tmp1 = L_shr( dm_alpha[b], ( sub( ( sub( 31, dm_alpha_e ) ), 29 ) ) ); + L_tmp1 = L_add( L_tmp1, L_tmp2 ); // Q29 + + dm_g[b] = L_deposit_l( BASOP_Util_Divide3232_Scale( L_tmp1, den_f, &s_div ) ); // Q29 + den_f_e - 31 + 15 - s_div + move32(); + div_shift = add( sub( 15, ( sub( 29, sub( 31, den_f_e ) ) ) ), s_div ); + dm_g[b] = L_shl( dm_g[b], div_shift ); // Q30 + move32(); + } + ELSE + { + Word32 sqrt_val; + Word16 val_e; + Word16 num_f_e; + + /* quadratic activeW */ + + num_f = BASOP_Util_Add_Mant32Exp( dm_beta_re, dm_beta_re_e, L_negate( L_shl( Mpy_32_32( dm_alpha[b], activew_quad_thresh ), 1 ) ), add( dm_alpha_e, ( 31 - Q29 ) ), &num_f_e ); + + sqrt_val = L_shl( Mpy_32_32( Mpy_32_32( dm_alpha[b], dm_alpha[b] ), g_th_sq ), 2 ); /*Q27*/ + val_e = 4; + move16(); + + sqrt_val = BASOP_Util_Add_Mant32Exp( sqrt_val, 4, Mpy_32_32( dm_beta_re, dm_beta_re ), 2 * dm_beta_re_e, &val_e ); + sqrt_val = BASOP_Util_Add_Mant32Exp( sqrt_val, val_e, L_negate( L_shl( Mpy_32_32( Mpy_32_32( dm_beta_re, g_th_sq ), dm_w ), 2 ) ), add( dm_beta_re_e, 4 + 1 ), &val_e ); + // val_e = norm_l( sqrt_val ); + sqrt_val = Sqrt32( sqrt_val, &val_e ); + IF( val_e < 0 ) + { + sqrt_val = L_shr( sqrt_val, abs_s( val_e ) ); + } + ELSE IF( val_e > 0 ) + { + sqrt_val = L_shl( sqrt_val, abs_s( val_e ) ); + val_e = 0; + move16(); + } + num_f = BASOP_Util_Add_Mant32Exp( num_f, num_f_e, sqrt_val, 0, &num_f_e ); + + den_f = L_shl( Mpy_32_32( dm_beta_re, g_th_sq ), 1 ); + den_f_e = add( dm_beta_re_e, 4 ); + den_f = L_max( den_f, 1 ); + dm_g[b] = activew_quad_thresh; // Q29 + move32(); + DM_F[b] = BASOP_Util_Divide3232_Scale_cadence( Mpy_32_32( dm_g[b], num_f ), den_f, &s_dm_f ); + move32(); + s_dm_f = add( s_dm_f, sub( add( 2, num_f_e ), den_f_e ) ); /*Resultant exp for DM_F s_dm_f +( 2 + num_f_e ) - den_f_e*/ + div_shift = sub( s_dm_f, 1 ); + DM_F[b] = L_shl( DM_F[b], div_shift ); // Q30 + move32(); + } + } + + FOR( i = 0; i < pred_dim; i++ ) + { + FOR( b = start_band; b < end_band; b++ ) + { + ppPred_coeffs_re[i][b] = Mpy_32_32( dm_v_re[i][b], dm_g[b] ); // Q = tmp_shift - 1 + 30 - 31 + move32(); + ppDM_Fv_re[i][b] = Mpy_32_32( dm_v_re[i][b], DM_F[b] ); + move32(); + } + } + *q_pred_coeffs = sub( tmp_shift, 2 ); + move16(); + *q_dm_fv_re = sub( tmp_shift, 2 ); + move16(); + } + + return; +} +#endif // IVAS_FLOAT_FIXED + + +/*-----------------------------------------------------------------------------------------* + * Function ivas_get_Wscaling_factor() + * * Calculation of scaling factor for post predicted W channel *-----------------------------------------------------------------------------------------*/ @@ -1248,6 +1985,118 @@ static void ivas_get_Wscaling_factor( #ifdef IVAS_FLOAT_FIXED +static void ivas_get_Wscaling_factor_enc_fx( + Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + Word16 *q_cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + Word32 pred_coeffs_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], + Word16 q_pred_coeffs_re, + Word32 ***mixer_mat, + Word16 q_mixer_mat, + const Word16 start_band, + const Word16 end_band, + const Word16 dtx_vad, + const Word16 num_ch, + const Word16 *pNum_dmx, + const Word16 bands_bw, + const Word16 active_w, + const Word16 active_w_vlbr, + Word32 *pWscale, + Word16 *q_pWscale, + const Word16 dyn_active_w_flag ) +{ + Word16 b, ch, q_tmp, q_postpred_cov_re; + Word32 dm_f_local, abs_val; + Word32 postpred_cov_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH]; + + q_postpred_cov_re = 0; + move16(); + + FOR( ch = 0; ch < IVAS_SPAR_MAX_CH; ch++ ) + { + set32_fx( postpred_cov_re[ch], 0, IVAS_SPAR_MAX_CH ); + } + + IF( dtx_vad == 0 ) + { + dm_f_local = IVAS_ACTIVEW_DM_F_SCALE_DTX_FX; // Q31 + move32(); + } + ELSE IF( active_w_vlbr != 0 ) + { + dm_f_local = IVAS_ACTIVEW_DM_F_SCALE_VLBR_FX; // Q31 + move32(); + } + ELSE + { + dm_f_local = IVAS_ACTIVEW_DM_F_SCALE_FX; // Q31 + move32(); + } + + FOR( b = start_band; b < end_band; b++ ) + { + pWscale[b] = 1; + move32(); + q_pWscale[b] = 0; + move16(); + + test(); + IF( EQ_16( active_w, 1 ) && ( dyn_active_w_flag == 0 ) ) + { + Word16 guard_bits, q_Gw_sq, q_g_sq, q_min, tmp_exp; + Word32 Gw_sq, g_sq, tmp; + + g_sq = 0; + move32(); + + IF( NE_16( num_ch, pNum_dmx[i_mult( b, bands_bw )] ) ) + { + ivas_calc_post_pred_per_band_enc_fx( cov_real, q_cov_real, mixer_mat, q_mixer_mat, num_ch, b, postpred_cov_re, &q_postpred_cov_re ); + } + + Gw_sq = BASOP_Util_Divide3232_Scale( cov_real[0][0][b], L_max( postpred_cov_re[0][0], IVAS_FIX_EPS ), &tmp_exp ); + q_Gw_sq = add( sub( 15, tmp_exp ), sub( q_cov_real[0][0][b], q_postpred_cov_re ) ); + + guard_bits = find_guarded_bits_fx( num_ch ); + + FOR( ch = 0; ch < sub( num_ch, 1 ); ch++ ) + { + abs_val = L_shr( Mpy_32_32( pred_coeffs_re[ch][b], pred_coeffs_re[ch][b] ), guard_bits ); + g_sq = L_add( g_sq, abs_val ); + } + q_g_sq = sub( add( q_pred_coeffs_re, q_pred_coeffs_re ), add( 31, guard_bits ) ); + + tmp = Mpy_32_32( ONE_IN_Q30 /*4 in Q28*/, Mpy_32_32( dm_f_local, g_sq ) ); + q_tmp = sub( q_g_sq, 3 ); + + q_min = s_min( q_Gw_sq, q_tmp ); + tmp = L_shr( tmp, sub( q_tmp, q_min ) ); + tmp = L_add( L_shr( Gw_sq, sub( q_Gw_sq, q_min ) ), tmp ); + + tmp_exp = sub( 31, q_min ); + tmp = Sqrt32( tmp, &tmp_exp ); + q_tmp = sub( 31, tmp_exp ); + + tmp_exp = sub( 31, q_Gw_sq ); + Gw_sq = Sqrt32( Gw_sq, &tmp_exp ); + q_Gw_sq = sub( 31, tmp_exp ); + + q_min = s_min( q_Gw_sq, q_tmp ); + Gw_sq = L_shr( Gw_sq, sub( q_Gw_sq, q_min ) ); + q_Gw_sq = q_min; + move16(); + + tmp = L_shr( tmp, sub( q_tmp, q_min ) ); + + pWscale[b] = L_add( Mpy_32_32( Gw_sq, ONE_IN_Q30 /* 0.5 in Q31*/ ), Mpy_32_32( tmp, ONE_IN_Q30 /* 0.5 in Q31*/ ) ); + move32(); + q_pWscale[b] = q_Gw_sq; + move16(); + } + } + + return; +} + static void ivas_get_Wscaling_factor_fx( Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], Word16 q_cov_real, @@ -1522,7 +2371,7 @@ void ivas_create_fullr_dmx_mat_fx( { FOR( b = start_band; b < end_band; b++ ) { - tmp_p2_re[j][j][b] = L_shl( 1, q_pred_coeffs_re ); + tmp_p2_re[j][j][b] = L_shl_sat( 1, q_pred_coeffs_re ); move32(); max_val_tmp_p2 = L_max( max_val_tmp_p2, L_abs( tmp_p2_re[j][j][b] ) ); } @@ -1722,33 +2571,198 @@ static void ivas_calc_post_pred_per_band( } } - /* num_ch x num_ch mult */ - for ( i = 0; i < num_ch; i++ ) + /* num_ch x num_ch mult */ + for ( i = 0; i < num_ch; i++ ) + { + for ( j = i; j < num_ch; j++ ) + { + for ( k = 0; k < num_ch; k++ ) + { + IVAS_RMULT_FLOAT( mixer_mat[i][k][band_idx], temp_mat[k][j], tmp_re ); + postpred_cov_re[i][j] += tmp_re; + } + } + } + + for ( i = 0; i < num_ch; i++ ) + { + for ( j = 0; j < i; j++ ) + { + postpred_cov_re[i][j] = postpred_cov_re[j][i]; + } + } + + return; +} + + +#ifdef IVAS_FLOAT_FIXED + +static void ivas_calc_post_pred_per_band_enc_fx( + Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + Word16 *q_cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + Word32 ***mixer_mat, + Word16 q_mixer_mat, + const Word16 num_ch, + const Word16 band_idx, + Word32 postpred_cov_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + Word16 *q_postpred_cov_re ) +{ + Word16 i, j, k, guard_bits, tmp, q_temp_mat[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], q_tmp_re, q_W_tmp; + Word32 dmx_mat_conj[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH]; + Word32 temp_mat[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH]; + Word32 max_val; + Word64 tmp_re, W_tmp; + Word16 q_postpred_cov_re_per_value[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH]; + + FOR( i = 0; i < num_ch; i++ ) + { + FOR( j = 0; j < num_ch; j++ ) + { + dmx_mat_conj[i][j] = mixer_mat[j][i][band_idx]; + move32(); + } + } + + FOR( i = 0; i < num_ch; i++ ) + { + set32_fx( temp_mat[i], 0, num_ch ); + set32_fx( postpred_cov_re[i], 0, num_ch ); + } + + max_val = 1; + move32(); + /* num_ch x num_ch mult */ + FOR( i = 0; i < num_ch; i++ ) + { + FOR( j = 0; j < num_ch; j++ ) + { + tmp_re = 0; + move64(); + q_tmp_re = 31; + move16(); + FOR( k = 0; k < num_ch; k++ ) + { + W_tmp = W_shr( W_mult0_32_32( cov_real[i][k][band_idx], dmx_mat_conj[k][j] ), q_mixer_mat ); + IF( LT_16( q_cov_real[i][k][band_idx], q_tmp_re ) ) + { + tmp_re = W_add( W_shr( tmp_re, sub( q_tmp_re, q_cov_real[i][k][band_idx] ) ), W_tmp ); + q_tmp_re = q_cov_real[i][k][band_idx]; + move16(); + } + ELSE + { + tmp_re = W_add( tmp_re, W_shr( W_tmp, sub( q_cov_real[i][k][band_idx], q_tmp_re ) ) ); + } + } + IF( tmp_re == 0 ) + { + q_temp_mat[i][j] = 31; + move16(); + temp_mat[i][j] = 0; + move32(); + } + ELSE + { + q_temp_mat[i][j] = q_tmp_re; + move16(); + q_tmp_re = W_norm( tmp_re ); + temp_mat[i][j] = W_extract_h( W_shl( tmp_re, q_tmp_re ) ); + move32(); + q_temp_mat[i][j] = sub( add( q_temp_mat[i][j], q_tmp_re ), 32 ); + move16(); + } + max_val = L_max( max_val, L_abs( temp_mat[i][j] ) ); + } + } + + guard_bits = find_guarded_bits_fx( num_ch ); + + tmp = norm_l( max_val ); + IF( LT_16( tmp, guard_bits ) ) + { + guard_bits = sub( guard_bits, tmp ); + } + ELSE + { + guard_bits = 0; + move16(); + } + + *q_postpred_cov_re = 31; + move16(); + /* num_ch x num_ch mult */ + FOR( i = 0; i < num_ch; i++ ) + { + FOR( j = i; j < num_ch; j++ ) + { + tmp_re = 0; + move64(); + q_tmp_re = 31; + move16(); + FOR( k = 0; k < num_ch; k++ ) + { + W_tmp = W_shr( W_mult0_32_32( mixer_mat[i][k][band_idx], temp_mat[k][j] ), guard_bits ); + q_W_tmp = sub( add( q_temp_mat[k][j], q_mixer_mat ), guard_bits ); + IF( LT_16( q_W_tmp, q_tmp_re ) ) + { + tmp_re = W_add( W_shr( tmp_re, sub( q_tmp_re, q_W_tmp ) ), W_tmp ); + q_tmp_re = q_W_tmp; + move16(); + } + ELSE + { + tmp_re = W_add( tmp_re, W_shr( W_tmp, sub( q_W_tmp, q_tmp_re ) ) ); + } + } + + if ( LT_64( W_abs( tmp_re ), L_shl( IVAS_FIX_EPS, guard_bits ) ) ) + { + tmp_re = 0; + move64(); + } + + q_postpred_cov_re_per_value[i][j] = q_tmp_re; + move16(); + q_tmp_re = W_norm( tmp_re ); + postpred_cov_re[i][j] = W_extract_h( W_shl( tmp_re, q_tmp_re ) ); + move32(); + q_postpred_cov_re_per_value[i][j] = sub( add( q_tmp_re, q_postpred_cov_re_per_value[i][j] ), 32 ); + move16(); + *q_postpred_cov_re = s_min( *q_postpred_cov_re, q_postpred_cov_re_per_value[i][j] ); + move16(); + } + } + + FOR( i = 0; i < num_ch; i++ ) { - for ( j = i; j < num_ch; j++ ) + FOR( j = i; j < num_ch; j++ ) { - for ( k = 0; k < num_ch; k++ ) + IF( postpred_cov_re[i][j] >= 0 ) { - IVAS_RMULT_FLOAT( mixer_mat[i][k][band_idx], temp_mat[k][j], tmp_re ); - postpred_cov_re[i][j] += tmp_re; + postpred_cov_re[i][j] = L_shr( postpred_cov_re[i][j], sub( q_postpred_cov_re_per_value[i][j], *q_postpred_cov_re ) ); + move32(); + } + ELSE + { + postpred_cov_re[i][j] = L_negate( L_shr( L_negate( postpred_cov_re[i][j] ), sub( q_postpred_cov_re_per_value[i][j], *q_postpred_cov_re ) ) ); + move32(); } } } - for ( i = 0; i < num_ch; i++ ) + FOR( i = 0; i < num_ch; i++ ) { - for ( j = 0; j < i; j++ ) + FOR( j = 0; j < i; j++ ) { postpred_cov_re[i][j] = postpred_cov_re[j][i]; + move32(); } } return; } - -#ifdef IVAS_FLOAT_FIXED - static void ivas_calc_post_pred_per_band_fx( Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], Word16 q_cov_real, @@ -1897,166 +2911,672 @@ static void ivas_calc_p_coeffs_per_band( set_zero( recon_uu_re[i], IVAS_SPAR_MAX_CH - IVAS_SPAR_MAX_DMX_CHS ); } - for ( i = num_dmx; i < num_ch; i++ ) - { - for ( j = num_dmx; j < num_ch; j++ ) - { - cov_uu_re[i - num_dmx][j - num_dmx] = postpred_cov_re[i][j]; - } - } + for ( i = num_dmx; i < num_ch; i++ ) + { + for ( j = num_dmx; j < num_ch; j++ ) + { + cov_uu_re[i - num_dmx][j - num_dmx] = postpred_cov_re[i][j]; + } + } + + if ( dtx_vad == 1 ) + { + for ( i = 1; i < num_dmx; i++ ) + { + for ( j = 1; j < num_dmx; j++ ) + { + cov_dd_re[i - 1][j - 1] = postpred_cov_re[i][j]; + } + } + + if ( num_dmx == 2 ) + { + float re1, re2; + + IVAS_RMULT_FLOAT( pSparMd->band_coeffs[b_ts_idx].C_re[0][0], cov_dd_re[0][0], re1 ); + IVAS_RMULT_FLOAT( pSparMd->band_coeffs[b_ts_idx].C_re[1][0], cov_dd_re[0][0], re2 ); + IVAS_RMULT_FLOAT( pSparMd->band_coeffs[b_ts_idx].C_re[0][0], re1, recon_uu_re[0][0] ); + IVAS_RMULT_FLOAT( pSparMd->band_coeffs[b_ts_idx].C_re[1][0], re1, recon_uu_re[0][1] ); + IVAS_RMULT_FLOAT( pSparMd->band_coeffs[b_ts_idx].C_re[0][0], re2, recon_uu_re[1][0] ); + IVAS_RMULT_FLOAT( pSparMd->band_coeffs[b_ts_idx].C_re[1][0], re2, recon_uu_re[1][1] ); + + for ( i = 0; i < 2; i++ ) + { + for ( j = 0; j < 2; j++ ) + { + cov_uu_re[i][j] -= recon_uu_re[i][j]; + } + } + } + else if ( num_dmx == 3 ) + { + float re1[2], re2; + set_f( re1, 0, 2 ); + + for ( j = 0; j < 2; j++ ) + { + for ( k = 0; k < 2; k++ ) + { + float re; + + IVAS_RMULT_FLOAT( pSparMd->band_coeffs[b_ts_idx].C_re[0][k], cov_dd_re[k][j], re ); + re1[j] += re; + } + } + + IVAS_RMULT_FLOAT( pSparMd->band_coeffs[b_ts_idx].C_re[0][0], re1[0], re2 ); + recon_uu_re[0][0] = re2; + IVAS_RMULT_FLOAT( pSparMd->band_coeffs[b_ts_idx].C_re[0][1], re1[1], re2 ); + recon_uu_re[0][0] += re2; + + cov_uu_re[0][0] -= recon_uu_re[0][0]; + } + else if ( num_dmx == 4 ) + { + /* Step 1: Multiply C * cov_dd * C' */ + float re1[3], re; + + for ( i = 0; i < num_ch - num_dmx; i++ ) + { + set_f( re1, 0, 3 ); + for ( m = 0; m < num_dmx - 1; m++ ) + { + for ( k = 0; k < num_dmx - 1; k++ ) + { + IVAS_RMULT_FLOAT( pSparMd->band_coeffs[b_ts_idx].C_re[i][k], cov_dd_re[k][m], re ); + re1[m] += re; + } + } + for ( j = 0; j < num_ch - num_dmx; j++ ) + { + for ( m = 0; m < num_dmx - 1; m++ ) + { + IVAS_RMULT_FLOAT( pSparMd->band_coeffs[b_ts_idx].C_re[j][m], re1[m], re ); + recon_uu_re[i][j] += re; + } + } + } + + /* Step 2: cov_uu - recon_uu */ + for ( i = 0; i < num_ch - num_dmx; i++ ) + { + for ( j = 0; j < num_ch - num_dmx; j++ ) + { + cov_uu_re[i][j] -= recon_uu_re[i][j]; + } + } + } + } + + p_norm_scaling = IVAS_P_NORM_SCALING; + + if ( ( dtx_vad == 0 ) && ( num_dmx == 1 ) ) + { + p_norm_scaling = IVAS_P_NORM_SCALING_DTX; + } + + trace = 0.0f; + + for ( i = num_dmx; i < num_ch; i++ ) + { + float tmp_out; + IVAS_CALCULATE_RABS( cov_uu_re[i - num_dmx][i - num_dmx], tmp_out ); + trace += tmp_out; + } + + factor = max( 1e-20f, postpred_cov_re[0][0] ); + factor = max( factor, ( p_norm_scaling * trace ) ); + factor = 1 / factor; + + /* normalise Hermitian (except for rounding) cov_uu */ + for ( i = num_dmx; i < num_ch; i++ ) + { + for ( j = num_dmx; j < num_ch; j++ ) + { + if ( i == j ) + { + /* force diagonal to be real */ + cov_uu_re[i - num_dmx][j - num_dmx] *= factor; + } + else + { + /* set off-diag elements to zero */ + cov_uu_re[i - num_dmx][j - num_dmx] = 0; + } + } + } + + /* take sqrt of max of diags and zero */ + for ( i = num_dmx; i < num_ch; i++ ) + { + cov_uu_re[i - num_dmx][i - num_dmx] = sqrtf( max( 0.0f, cov_uu_re[i - num_dmx][i - num_dmx] ) ); + /* cov_uu_im[i - num_dmx][i - num_dmx] = 0; */ + } + + /* save into MD struct */ + for ( i = num_dmx; i < num_ch; i++ ) + { + for ( j = num_dmx; j < num_ch; j++ ) + { + if ( i == j ) + { + pSparMd->band_coeffs[b_ts_idx].P_re[j - num_dmx] = cov_uu_re[i - num_dmx][j - num_dmx]; + } + } + } + } + + return; +} + +#ifdef IVAS_FLOAT_FIXED + +static void ivas_calc_p_coeffs_per_band_enc_fx( + ivas_spar_md_t *pSparMd, + const Word16 i_ts, + Word32 postpred_cov_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + Word16 q_postpred_cov_re, + const Word16 num_ch, + const Word16 dtx_vad, + const Word16 num_dmx, + const Word16 band_idx ) +{ + Word16 i, j, k; + Word16 m; + Word32 factor; + Word32 recon_uu_re[IVAS_SPAR_MAX_CH - IVAS_SPAR_MAX_DMX_CHS][IVAS_SPAR_MAX_CH - IVAS_SPAR_MAX_DMX_CHS]; + Word16 q_recon_uu_re[IVAS_SPAR_MAX_CH - IVAS_SPAR_MAX_DMX_CHS][IVAS_SPAR_MAX_CH - IVAS_SPAR_MAX_DMX_CHS]; + Word64 trace, W_tmp; + Word16 q_factor, q_tmp, q_tmp1; + Word32 tmp; + Word32 p_norm_scaling; + Word16 q_cov_uu_re, q_cov_dd_re; + Word32 cov_dd_re[IVAS_SPAR_MAX_CH - 1][IVAS_SPAR_MAX_CH - 1]; + Word32 cov_uu_re[IVAS_SPAR_MAX_CH - 1][IVAS_SPAR_MAX_CH - 1]; + Word16 q_cov_uu_re_per_value[IVAS_SPAR_MAX_CH - 1][IVAS_SPAR_MAX_CH - 1]; + Word16 b_ts_idx; + + b_ts_idx = add( band_idx, imult1616( i_ts, IVAS_MAX_NUM_BANDS ) ); + + IF( NE_16( num_dmx, num_ch ) ) + { + set32_fx( pSparMd->band_coeffs[b_ts_idx].P_re_fx, 0, IVAS_SPAR_MAX_CH - 1 ); + pSparMd->band_coeffs[b_ts_idx].q_P_re_fx = 0; + move16(); + FOR( i = 0; i < sub( IVAS_SPAR_MAX_CH, IVAS_SPAR_MAX_DMX_CHS ); i++ ) + { + set32_fx( recon_uu_re[i], 0, sub( IVAS_SPAR_MAX_CH, IVAS_SPAR_MAX_DMX_CHS ) ); + } + + FOR( i = num_dmx; i < num_ch; i++ ) + { + FOR( j = num_dmx; j < num_ch; j++ ) + { + cov_uu_re[sub( i, num_dmx )][sub( j, num_dmx )] = postpred_cov_re[i][j]; + move32(); + } + } + q_cov_uu_re = q_postpred_cov_re; + move16(); + + IF( EQ_16( dtx_vad, 1 ) ) + { + FOR( i = 1; i < num_dmx; i++ ) + { + FOR( j = 1; j < num_dmx; j++ ) + { + cov_dd_re[sub( i, 1 )][sub( j, 1 )] = postpred_cov_re[i][j]; + move32(); + } + } + q_cov_dd_re = q_postpred_cov_re; + move16(); + + Word16 q_C_re = pSparMd->band_coeffs[b_ts_idx].q_C_re_fx; + move16(); + + IF( EQ_16( num_dmx, 2 ) ) + { + Word32 re1, re2; + + W_tmp = W_mult0_32_32( pSparMd->band_coeffs[b_ts_idx].C_re_fx[0][0], cov_dd_re[0][0] ); + q_tmp1 = W_norm( W_tmp ); + re1 = W_extract_h( W_shl( W_tmp, q_tmp1 ) ); + q_tmp1 = sub( add( add( q_C_re, q_tmp1 ), q_cov_dd_re ), 32 ); + if ( W_tmp == 0 ) + { + q_tmp1 = 31; + move16(); + } + W_tmp = W_mult0_32_32( pSparMd->band_coeffs[b_ts_idx].C_re_fx[1][0], cov_dd_re[0][0] ); + q_tmp = W_norm( W_tmp ); + re2 = W_extract_h( W_shl( W_tmp, q_tmp ) ); + q_tmp = sub( add( add( q_C_re, q_tmp ), q_cov_dd_re ), 32 ); + if ( W_tmp == 0 ) + { + q_tmp = 31; + move16(); + } + + W_tmp = W_mult0_32_32( pSparMd->band_coeffs[b_ts_idx].C_re_fx[0][0], re1 ); + q_recon_uu_re[0][0] = W_norm( W_tmp ); + move16(); + recon_uu_re[0][0] = W_extract_h( W_shl( W_tmp, q_recon_uu_re[0][0] ) ); + move32(); + q_recon_uu_re[0][0] = sub( add( add( q_C_re, q_recon_uu_re[0][0] ), q_tmp1 ), 32 ); + move16(); + if ( W_tmp == 0 ) + { + q_recon_uu_re[0][0] = 31; + move16(); + } + + W_tmp = W_mult0_32_32( pSparMd->band_coeffs[b_ts_idx].C_re_fx[1][0], re1 ); + q_recon_uu_re[0][1] = W_norm( W_tmp ); + move16(); + recon_uu_re[0][1] = W_extract_h( W_shl( W_tmp, q_recon_uu_re[0][1] ) ); + move32(); + q_recon_uu_re[0][1] = sub( add( add( q_C_re, q_recon_uu_re[0][1] ), q_tmp1 ), 32 ); + move16(); + if ( W_tmp == 0 ) + { + q_recon_uu_re[0][1] = 31; + move16(); + } - if ( dtx_vad == 1 ) - { - for ( i = 1; i < num_dmx; i++ ) - { - for ( j = 1; j < num_dmx; j++ ) + W_tmp = W_mult0_32_32( pSparMd->band_coeffs[b_ts_idx].C_re_fx[0][0], re2 ); + q_recon_uu_re[1][0] = W_norm( W_tmp ); + move16(); + recon_uu_re[1][0] = W_extract_h( W_shl( W_tmp, q_recon_uu_re[1][0] ) ); + move32(); + q_recon_uu_re[1][0] = sub( add( add( q_C_re, q_recon_uu_re[1][0] ), q_tmp ), 32 ); + move16(); + if ( W_tmp == 0 ) { - cov_dd_re[i - 1][j - 1] = postpred_cov_re[i][j]; + q_recon_uu_re[1][0] = 31; + move16(); } - } - if ( num_dmx == 2 ) - { - float re1, re2; + W_tmp = W_mult0_32_32( pSparMd->band_coeffs[b_ts_idx].C_re_fx[1][0], re2 ); + q_recon_uu_re[1][1] = W_norm( W_tmp ); + move16(); + recon_uu_re[1][1] = W_extract_h( W_shl( W_tmp, q_recon_uu_re[1][1] ) ); + move32(); + q_recon_uu_re[1][1] = sub( add( add( q_C_re, q_recon_uu_re[1][1] ), q_tmp1 ), 32 ); + move16(); + if ( W_tmp == 0 ) + { + q_recon_uu_re[1][1] = 31; + move16(); + } - IVAS_RMULT_FLOAT( pSparMd->band_coeffs[b_ts_idx].C_re[0][0], cov_dd_re[0][0], re1 ); - IVAS_RMULT_FLOAT( pSparMd->band_coeffs[b_ts_idx].C_re[1][0], cov_dd_re[0][0], re2 ); - IVAS_RMULT_FLOAT( pSparMd->band_coeffs[b_ts_idx].C_re[0][0], re1, recon_uu_re[0][0] ); - IVAS_RMULT_FLOAT( pSparMd->band_coeffs[b_ts_idx].C_re[1][0], re1, recon_uu_re[0][1] ); - IVAS_RMULT_FLOAT( pSparMd->band_coeffs[b_ts_idx].C_re[0][0], re2, recon_uu_re[1][0] ); - IVAS_RMULT_FLOAT( pSparMd->band_coeffs[b_ts_idx].C_re[1][0], re2, recon_uu_re[1][1] ); + q_tmp = 31; + move16(); + FOR( i = 0; i < 2; i++ ) + { + FOR( j = 0; j < 2; j++ ) + { + q_tmp = s_min( q_tmp, q_recon_uu_re[i][j] ); + } + } + q_tmp = sub( s_min( q_tmp, q_cov_uu_re ), 1 ); - for ( i = 0; i < 2; i++ ) + FOR( i = 0; i < 2; i++ ) { - for ( j = 0; j < 2; j++ ) + FOR( j = 0; j < 2; j++ ) { - cov_uu_re[i][j] -= recon_uu_re[i][j]; + cov_uu_re[i][j] = L_sub( L_shr( cov_uu_re[i][j], sub( q_cov_uu_re, q_tmp ) ), L_shr( recon_uu_re[i][j], sub( q_recon_uu_re[i][j], q_tmp ) ) ); + move32(); } } + q_cov_uu_re = q_tmp; + move16(); } - else if ( num_dmx == 3 ) + ELSE IF( EQ_16( num_dmx, 3 ) ) { - float re1[2], re2; - set_f( re1, 0, 2 ); + Word32 re1[2], re2; + Word16 q_re1[2]; + set32_fx( re1, 0, 2 ); + set16_fx( q_re1, 31, 2 ); - for ( j = 0; j < 2; j++ ) + FOR( j = 0; j < 2; j++ ) { - for ( k = 0; k < 2; k++ ) + FOR( k = 0; k < 2; k++ ) { - float re; + Word32 re; + W_tmp = W_mult0_32_32( pSparMd->band_coeffs[b_ts_idx].C_re_fx[0][k], cov_dd_re[k][j] ); + q_tmp = sub( W_norm( W_tmp ), 1 ); + re = W_extract_h( W_shl( W_tmp, q_tmp ) ); + q_tmp = sub( add( add( q_C_re, q_tmp ), q_cov_dd_re ), 32 ); + if ( W_tmp == 0 ) + { + q_tmp = 31; + move16(); + } - IVAS_RMULT_FLOAT( pSparMd->band_coeffs[b_ts_idx].C_re[0][k], cov_dd_re[k][j], re ); - re1[j] += re; + IF( LT_16( q_tmp, q_re1[j] ) ) + { + re1[j] = L_shr( re1[j], sub( q_re1[j], q_tmp ) ); + move32(); + q_re1[j] = q_tmp; + move16(); + } + ELSE + { + re = L_shr( re, sub( q_tmp, q_re1[j] ) ); + } + re1[j] = L_add( re1[j], re ); + move32(); } } - IVAS_RMULT_FLOAT( pSparMd->band_coeffs[b_ts_idx].C_re[0][0], re1[0], re2 ); + W_tmp = W_mult0_32_32( pSparMd->band_coeffs[b_ts_idx].C_re_fx[0][0], re1[0] ); + q_tmp = sub( W_norm( W_tmp ), 1 ); + re2 = W_extract_h( W_shl( W_tmp, q_tmp ) ); + q_tmp = sub( add( add( q_C_re, q_tmp ), q_re1[0] ), 32 ); + if ( W_tmp == 0 ) + { + q_tmp = 31; + move16(); + } recon_uu_re[0][0] = re2; - IVAS_RMULT_FLOAT( pSparMd->band_coeffs[b_ts_idx].C_re[0][1], re1[1], re2 ); - recon_uu_re[0][0] += re2; + move32(); - cov_uu_re[0][0] -= recon_uu_re[0][0]; + W_tmp = W_mult0_32_32( pSparMd->band_coeffs[b_ts_idx].C_re_fx[0][1], re1[1] ); + q_tmp1 = sub( W_norm( W_tmp ), 1 ); + re2 = W_extract_h( W_shl( W_tmp, q_tmp1 ) ); + q_tmp1 = sub( add( add( q_C_re, q_tmp1 ), q_re1[1] ), 32 ); + if ( W_tmp == 0 ) + { + q_tmp1 = 31; + move16(); + } + + IF( LT_16( q_tmp, q_tmp1 ) ) + { + re2 = L_shr( re2, sub( q_tmp1, q_tmp ) ); + } + ELSE + { + recon_uu_re[0][0] = L_shr( recon_uu_re[0][0], sub( q_tmp, q_tmp1 ) ); + move32(); + q_tmp = q_tmp1; + move16(); + } + + recon_uu_re[0][0] = L_add( recon_uu_re[0][0], re2 ); + move32(); + + IF( LT_16( q_cov_uu_re, q_tmp ) ) + { + recon_uu_re[0][0] = L_shr( recon_uu_re[0][0], sub( q_tmp, q_cov_uu_re ) ); + move32(); + } + ELSE + { + FOR( i = num_dmx; i < num_ch; i++ ) + { + FOR( j = num_dmx; j < num_ch; j++ ) + { + cov_uu_re[sub( i, num_dmx )][sub( j, num_dmx )] = L_shr( cov_uu_re[sub( i, num_dmx )][sub( j, num_dmx )], sub( q_cov_uu_re, q_tmp ) ); + move32(); + } + } + q_cov_uu_re = q_tmp; + move16(); + } + + IF( recon_uu_re[0][0] != 0 ) + { + test(); + IF( W_norm( recon_uu_re[0][0] ) == 0 || W_norm( cov_uu_re[0][0] ) == 0 ) + { + FOR( i = num_dmx; i < num_ch; i++ ) + { + FOR( j = num_dmx; j < num_ch; j++ ) + { + cov_uu_re[sub( i, num_dmx )][sub( j, num_dmx )] = L_shr( cov_uu_re[sub( i, num_dmx )][sub( j, num_dmx )], 1 ); + move32(); + } + } + q_cov_uu_re = sub( q_cov_uu_re, 1 ); + recon_uu_re[0][0] = L_shr( recon_uu_re[0][0], 1 ); + move32(); + } + } + + cov_uu_re[0][0] = L_sub( cov_uu_re[0][0], recon_uu_re[0][0] ); + move32(); } - else if ( num_dmx == 4 ) + ELSE IF( EQ_16( num_dmx, 4 ) ) { /* Step 1: Multiply C * cov_dd * C' */ - float re1[3], re; + Word32 re1[3], re; + Word16 q_re1[3]; - for ( i = 0; i < num_ch - num_dmx; i++ ) + FOR( i = 0; i < num_ch - num_dmx; i++ ) { - set_f( re1, 0, 3 ); - for ( m = 0; m < num_dmx - 1; m++ ) + set32_fx( re1, 0, 3 ); + set16_fx( q_re1, 31, 3 ); + set16_fx( q_recon_uu_re[i], 31, IVAS_SPAR_MAX_CH - IVAS_SPAR_MAX_DMX_CHS ); + FOR( m = 0; m < num_dmx - 1; m++ ) { - for ( k = 0; k < num_dmx - 1; k++ ) + FOR( k = 0; k < num_dmx - 1; k++ ) { - IVAS_RMULT_FLOAT( pSparMd->band_coeffs[b_ts_idx].C_re[i][k], cov_dd_re[k][m], re ); - re1[m] += re; + W_tmp = W_mult0_32_32( pSparMd->band_coeffs[b_ts_idx].C_re_fx[i][k], cov_dd_re[k][m] ); + q_tmp = sub( W_norm( W_tmp ), 2 ); + re = W_extract_h( W_shl( W_tmp, q_tmp ) ); + q_tmp = sub( add( add( q_C_re, q_tmp ), q_cov_dd_re ), 32 ); + if ( W_tmp == 0 ) + { + q_tmp = 31; + move16(); + } + + IF( LT_16( q_tmp, q_re1[m] ) ) + { + re1[m] = L_shr( re1[m], sub( q_re1[m], q_tmp ) ); + move32(); + q_re1[m] = q_tmp; + move16(); + } + ELSE + { + re = L_shr( re, sub( q_tmp, q_re1[m] ) ); + } + IF( re != 0 ) + { + test(); + IF( W_norm( re ) == 0 || W_norm( re1[m] ) == 0 ) + { + re1[m] = L_shr( re1[m], 1 ); + move32(); + q_re1[m] = sub( q_re1[m], 1 ); + move16(); + re = L_shr( re, 1 ); + } + } + + re1[m] = L_add( re1[m], re ); + move32(); } } - for ( j = 0; j < num_ch - num_dmx; j++ ) + FOR( j = 0; j < num_ch - num_dmx; j++ ) { - for ( m = 0; m < num_dmx - 1; m++ ) + FOR( m = 0; m < num_dmx - 1; m++ ) { - IVAS_RMULT_FLOAT( pSparMd->band_coeffs[b_ts_idx].C_re[j][m], re1[m], re ); - recon_uu_re[i][j] += re; + W_tmp = W_mult0_32_32( pSparMd->band_coeffs[b_ts_idx].C_re_fx[j][m], re1[m] ); + q_tmp = sub( W_norm( W_tmp ), 2 ); + re = W_extract_h( W_shl( W_tmp, q_tmp ) ); + q_tmp = sub( add( add( q_C_re, q_tmp ), q_re1[m] ), 32 ); + if ( W_tmp == 0 ) + { + q_tmp = 31; + move16(); + } + + IF( LT_16( q_tmp, q_recon_uu_re[i][j] ) ) + { + recon_uu_re[i][j] = L_shr( recon_uu_re[i][j], sub( q_recon_uu_re[i][j], q_tmp ) ); + move32(); + q_recon_uu_re[i][j] = q_tmp; + move16(); + } + ELSE + { + re = L_shr( re, sub( q_tmp, q_recon_uu_re[i][j] ) ); + } + IF( re != 0 ) + { + test(); + IF( W_norm( re ) == 0 || W_norm( recon_uu_re[i][j] ) == 0 ) + { + re1[m] = L_shr( re1[m], 1 ); + move32(); + q_recon_uu_re[i][j] = sub( q_recon_uu_re[i][j], 1 ); + move16(); + re = L_shr( re, 1 ); + } + } + recon_uu_re[i][j] = L_add( recon_uu_re[i][j], re ); + move32(); } } } + q_tmp = 31; + move16(); + FOR( i = 0; i < num_ch - num_dmx; i++ ) + { + FOR( j = 0; j < num_ch - num_dmx; j++ ) + { + q_tmp = s_min( q_tmp, q_recon_uu_re[i][j] ); + } + } + q_tmp = sub( s_min( q_tmp, q_cov_uu_re ), 1 ); + /* Step 2: cov_uu - recon_uu */ - for ( i = 0; i < num_ch - num_dmx; i++ ) + FOR( i = 0; i < sub( num_ch, num_dmx ); i++ ) { - for ( j = 0; j < num_ch - num_dmx; j++ ) + FOR( j = 0; j < num_ch - num_dmx; j++ ) { - cov_uu_re[i][j] -= recon_uu_re[i][j]; + cov_uu_re[i][j] = L_sub( L_shr( cov_uu_re[i][j], sub( q_cov_uu_re, q_tmp ) ), L_shr( recon_uu_re[i][j], sub( q_recon_uu_re[i][j], q_tmp ) ) ); + move32(); } } + q_cov_uu_re = q_tmp; + move16(); } } - p_norm_scaling = IVAS_P_NORM_SCALING; + p_norm_scaling = IVAS_P_NORM_SCALING_FX; + move32(); - if ( ( dtx_vad == 0 ) && ( num_dmx == 1 ) ) + test(); + if ( ( dtx_vad == 0 ) && EQ_16( num_dmx, 1 ) ) { - p_norm_scaling = IVAS_P_NORM_SCALING_DTX; + p_norm_scaling = IVAS_P_NORM_SCALING_DTX_FX; + move32(); } - trace = 0.0f; + trace = 0; + move64(); - for ( i = num_dmx; i < num_ch; i++ ) + FOR( i = num_dmx; i < num_ch; i++ ) { - float tmp_out; - IVAS_CALCULATE_RABS( cov_uu_re[i - num_dmx][i - num_dmx], tmp_out ); - trace += tmp_out; + trace = W_add( trace, W_deposit32_l( L_abs( cov_uu_re[sub( i, num_dmx )][sub( i, num_dmx )] ) ) ); } - factor = max( 1e-20f, postpred_cov_re[0][0] ); - factor = max( factor, ( p_norm_scaling * trace ) ); - factor = 1 / factor; + factor = L_max( IVAS_FIX_EPS, postpred_cov_re[0][0] ); + q_factor = q_postpred_cov_re; + move16(); + IF( trace != 0 ) + { + q_factor = W_norm( trace ); + tmp = Mpy_32_32( p_norm_scaling, W_extract_h( W_shl( trace, q_factor ) ) ); + q_factor = sub( add( q_postpred_cov_re, q_factor ), 32 ); + IF( GT_16( q_factor, q_postpred_cov_re ) ) + { + tmp = L_shr( tmp, sub( q_factor, q_postpred_cov_re ) ); + q_factor = q_postpred_cov_re; + move16(); + } + ELSE + { + factor = L_shr( factor, sub( q_postpred_cov_re, q_factor ) ); + } + factor = L_max( factor, tmp ); + } + + Word16 factor_exp = 0; + move16(); + factor = BASOP_Util_Divide3232_Scale( 1, factor, &factor_exp ); + factor_exp = add( factor_exp, q_factor ); /* normalise Hermitian (except for rounding) cov_uu */ - for ( i = num_dmx; i < num_ch; i++ ) + FOR( i = num_dmx; i < num_ch; i++ ) { - for ( j = num_dmx; j < num_ch; j++ ) + FOR( j = num_dmx; j < num_ch; j++ ) { - if ( i == j ) + IF( EQ_16( i, j ) ) { /* force diagonal to be real */ - cov_uu_re[i - num_dmx][j - num_dmx] *= factor; + W_tmp = W_mult0_32_32( cov_uu_re[sub( i, num_dmx )][sub( j, num_dmx )], factor ); + q_tmp = 32; + move16(); + if ( W_tmp != 0 ) + { + q_tmp = W_norm( W_tmp ); + } + cov_uu_re[sub( i, num_dmx )][sub( j, num_dmx )] = W_extract_h( W_shl( W_mult0_32_32( cov_uu_re[sub( i, num_dmx )][sub( j, num_dmx )], factor ), q_tmp ) ); + move32(); + q_cov_uu_re_per_value[sub( i, num_dmx )][sub( j, num_dmx )] = sub( add( add( q_cov_uu_re, sub( 15, factor_exp ) ), q_tmp ), 32 ); + move16(); } - else + ELSE { /* set off-diag elements to zero */ - cov_uu_re[i - num_dmx][j - num_dmx] = 0; + cov_uu_re[sub( i, num_dmx )][sub( j, num_dmx )] = 0; + move32(); + q_cov_uu_re_per_value[sub( i, num_dmx )][sub( j, num_dmx )] = 0; + move16(); } } } + Word16 cov_uu_re_exp; + q_tmp = 31; + move16(); /* take sqrt of max of diags and zero */ - for ( i = num_dmx; i < num_ch; i++ ) + FOR( i = num_dmx; i < num_ch; i++ ) { - cov_uu_re[i - num_dmx][i - num_dmx] = sqrtf( max( 0.0f, cov_uu_re[i - num_dmx][i - num_dmx] ) ); - /* cov_uu_im[i - num_dmx][i - num_dmx] = 0; */ + cov_uu_re_exp = sub( 31, q_cov_uu_re_per_value[sub( i, num_dmx )][sub( i, num_dmx )] ); + cov_uu_re[sub( i, num_dmx )][sub( i, num_dmx )] = Sqrt32( L_max( 0, cov_uu_re[sub( i, num_dmx )][sub( i, num_dmx )] ), &cov_uu_re_exp ); + move32(); + q_cov_uu_re_per_value[sub( i, num_dmx )][sub( i, num_dmx )] = sub( 31, cov_uu_re_exp ); + move16(); + q_tmp = s_min( q_tmp, q_cov_uu_re_per_value[sub( i, num_dmx )][sub( i, num_dmx )] ); } /* save into MD struct */ - for ( i = num_dmx; i < num_ch; i++ ) + FOR( i = num_dmx; i < num_ch; i++ ) { - for ( j = num_dmx; j < num_ch; j++ ) + FOR( j = num_dmx; j < num_ch; j++ ) { - if ( i == j ) + IF( EQ_16( i, j ) ) { - pSparMd->band_coeffs[b_ts_idx].P_re[j - num_dmx] = cov_uu_re[i - num_dmx][j - num_dmx]; + pSparMd->band_coeffs[b_ts_idx].P_re_fx[sub( j, num_dmx )] = L_shr( cov_uu_re[sub( i, num_dmx )][sub( j, num_dmx )], sub( q_cov_uu_re_per_value[sub( i, num_dmx )][sub( j, num_dmx )], q_tmp ) ); + move32(); } } } + pSparMd->band_coeffs[b_ts_idx].q_P_re_fx = q_tmp; + move16(); } return; } -#ifdef IVAS_FLOAT_FIXED - static void ivas_calc_p_coeffs_per_band_fx( ivas_spar_md_t *pSparMd, const Word16 i_ts, @@ -2282,6 +3802,7 @@ static void ivas_calc_p_coeffs_per_band_fx( return; } + #endif // IVAS_FLOAT_FIXED @@ -2382,6 +3903,156 @@ static void ivas_calc_c_coeffs_per_band( #ifdef IVAS_FLOAT_FIXED +static void ivas_calc_c_coeffs_per_band_enc_fx( + ivas_spar_md_t *pSparMd, + const Word16 i_ts, + Word32 postpred_cov_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + Word16 q_post_pred_cov_re, + const Word16 num_ch, + const Word16 num_dmx, + const Word16 band_idx, + const Word16 dtx_vad ) +{ + Word16 i, j, k; + + /* worst case for cov_ud is actually 12 x 3 */ + Word32 cov_ud_re[IVAS_SPAR_MAX_CH - IVAS_SPAR_MAX_DMX_CHS][IVAS_SPAR_MAX_DMX_CHS - 1]; + Word32 cov_dd_re[FOA_CHANNELS - 1][FOA_CHANNELS - 1]; + Word32 cov_dd_re_inv[FOA_CHANNELS - 1][FOA_CHANNELS - 1]; + Word16 q_cov_dd_re_inv; + Word32 trace_cov_dd_re, max_val; + Word16 q_tmp; + Word32 abs_trace; + Word16 b_ts_idx; + + b_ts_idx = add( band_idx, imult1616( i_ts, IVAS_MAX_NUM_BANDS ) ); + + IF( dtx_vad == 0 ) + { + set32_fx( &pSparMd->band_coeffs[b_ts_idx].C_re_fx[0][0], 0, imult1616( sub( IVAS_SPAR_MAX_CH, IVAS_SPAR_MAX_DMX_CHS ), sub( IVAS_SPAR_MAX_DMX_CHS, 1 ) ) ); + pSparMd->band_coeffs[b_ts_idx].q_C_re_fx = 0; + move16(); + return; + } + + FOR( i = num_dmx; i < num_ch; i++ ) + { + FOR( j = 1; j < num_dmx; j++ ) + { + cov_ud_re[sub( i, num_dmx )][sub( j, 1 )] = postpred_cov_re[i][j]; + move32(); + } + } + + max_val = 0; + move32(); + + FOR( i = 1; i < num_dmx; i++ ) + { + FOR( j = 1; j < num_dmx; j++ ) + { + IF( EQ_16( i, j ) ) + { + max_val = L_max( max_val, postpred_cov_re[i][j] ); + } + cov_dd_re[sub( i, 1 )][sub( j, 1 )] = postpred_cov_re[i][j]; + move32(); + } + } + + trace_cov_dd_re = 0; + move32(); + + FOR( i = 0; i < sub( num_dmx, 1 ); i++ ) + { + trace_cov_dd_re = L_add( trace_cov_dd_re, Mpy_32_32( cov_dd_re[i][i], 10737418 /* 0.005f in Q31*/ ) ); + } + + abs_trace = L_abs( trace_cov_dd_re ); + + IF( LE_32( abs_trace, IVAS_FIX_EPS ) ) + { + /* protection from cases when variance of residual channels is very small */ + set32_fx( &pSparMd->band_coeffs[b_ts_idx].C_re_fx[0][0], 0, imult1616( sub( IVAS_SPAR_MAX_CH, IVAS_SPAR_MAX_DMX_CHS ), sub( IVAS_SPAR_MAX_DMX_CHS, 1 ) ) ); + pSparMd->band_coeffs[b_ts_idx].q_C_re_fx = 0; + move16(); + } + ELSE + { + q_tmp = 1; + move16(); + IF( norm_l( max_val ) > 0 ) + { + q_tmp = 0; + move16(); + } + trace_cov_dd_re = L_shr( trace_cov_dd_re, q_tmp ); + FOR( i = 0; i < sub( num_dmx, 1 ); i++ ) + { + FOR( j = 0; j < sub( num_dmx, 1 ); j++ ) + { + cov_dd_re[i][j] = L_shr( cov_dd_re[i][j], q_tmp ); // q_post_pred_cov_re - q_tmp + move32(); + } + } + + FOR( i = 0; i < sub( num_dmx, 1 ); i++ ) + { + cov_dd_re[i][i] = L_add( trace_cov_dd_re, cov_dd_re[i][i] ); + move32(); + } + test(); + IF( EQ_16( ivas_is_mat_inv_fx( cov_dd_re, q_post_pred_cov_re, sub( num_dmx, 1 ) ), 1 ) && LT_16( num_dmx, FOA_CHANNELS ) ) + { + set32_fx( &pSparMd->band_coeffs[b_ts_idx].C_re_fx[0][0], 0, imult1616( sub( IVAS_SPAR_MAX_CH, IVAS_SPAR_MAX_DMX_CHS ), sub( IVAS_SPAR_MAX_DMX_CHS, 1 ) ) ); + pSparMd->band_coeffs[b_ts_idx].q_C_re_fx = 0; + move16(); + } + ELSE + { + ivas_calc_mat_inv_fx( cov_dd_re, sub( q_post_pred_cov_re, q_tmp ), sub( num_dmx, 1 ), cov_dd_re_inv, &q_cov_dd_re_inv ); + + Word16 tmp; + Word64 W_max_val = 1; + move64(); + Word64 C_re_fx[IVAS_SPAR_MAX_CH - IVAS_SPAR_MAX_DMX_CHS][IVAS_SPAR_MAX_DMX_CHS - 1]; + + FOR( i = 0; i < sub( num_ch, num_dmx ); i++ ) + { + FOR( j = 0; j < sub( num_dmx, 1 ); j++ ) + { + C_re_fx[i][j] = 0; + move64(); + FOR( k = 0; k < sub( num_dmx, 1 ); k++ ) + { + C_re_fx[i][j] = W_add_nosat( C_re_fx[i][j], W_mult0_32_32( cov_ud_re[i][k], cov_dd_re_inv[k][j] ) ); + move64(); + } + IF( LT_64( W_max_val, W_abs( C_re_fx[i][j] ) ) ) + { + W_max_val = W_abs( C_re_fx[i][j] ); + } + } + } + + tmp = s_max( sub( 32, W_norm( W_max_val ) ), 0 ); + + FOR( i = 0; i < sub( num_ch, num_dmx ); i++ ) + { + FOR( j = 0; j < sub( num_dmx, 1 ); j++ ) + { + pSparMd->band_coeffs[b_ts_idx].C_re_fx[i][j] = W_extract_l( W_shr( C_re_fx[i][j], tmp ) ); + move32(); + } + } + pSparMd->band_coeffs[b_ts_idx].q_C_re_fx = sub( add( q_cov_dd_re_inv, q_post_pred_cov_re ), tmp ); + move16(); + } + } + + return; +} + static void ivas_calc_c_coeffs_per_band_fx( ivas_spar_md_t *pSparMd, const Word16 i_ts, @@ -2570,6 +4241,65 @@ void ivas_calc_c_p_coeffs( #ifdef IVAS_FLOAT_FIXED +void ivas_calc_c_p_coeffs_enc_fx( + ivas_spar_md_t *pSparMd, + Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + Word16 *q_cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + const Word16 i_ts, + Word32 ***mixer_mat, + Word16 q_mixer_mat, + const Word16 num_ch, + const Word16 num_dmx, + const Word16 band_idx, + const Word16 dtx_vad, + const Word16 compute_p_flag, + const Word16 dyn_active_w_flag ) +{ + Word16 i, j, q_postpred_cov_re; + Word32 postpred_cov_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH] = { 0 }; + + IF( NE_16( num_dmx, num_ch ) ) + { + ivas_calc_post_pred_per_band_enc_fx( cov_real, q_cov_real, mixer_mat, q_mixer_mat, num_ch, band_idx, postpred_cov_re, &q_postpred_cov_re ); + + IF( NE_16( num_dmx, 1 ) ) + { + ivas_calc_c_coeffs_per_band_enc_fx( pSparMd, i_ts, postpred_cov_re, q_postpred_cov_re, num_ch, num_dmx, band_idx, dtx_vad ); + } + + IF( dyn_active_w_flag ) + { + FOR( i = 0; i < sub( num_ch, num_dmx ); i++ ) + { + FOR( j = 0; j < sub( num_dmx, 1 ); j++ ) + { + pSparMd->band_coeffs[add( band_idx, imult1616( i_ts, IVAS_MAX_NUM_BANDS ) )].C_re_fx[i][j] = 0; + move32(); + } + } + pSparMd->band_coeffs[add( band_idx, imult1616( i_ts, IVAS_MAX_NUM_BANDS ) )].q_C_re_fx = 0; + move16(); + } + IF( EQ_16( compute_p_flag, 1 ) ) + { + ivas_calc_p_coeffs_per_band_enc_fx( pSparMd, i_ts, postpred_cov_re, q_postpred_cov_re, num_ch, dtx_vad, num_dmx, band_idx ); + } + + IF( dyn_active_w_flag ) + { + FOR( i = num_dmx; i < num_ch; i++ ) + { + pSparMd->band_coeffs[add( band_idx, imult1616( i_ts, IVAS_MAX_NUM_BANDS ) )].P_re_fx[sub( i, num_dmx )] = 0; + move32(); + } + pSparMd->band_coeffs[add( band_idx, imult1616( i_ts, IVAS_MAX_NUM_BANDS ) )].q_P_re_fx = 0; + move16(); + } + } + + return; +} + void ivas_calc_c_p_coeffs_fx( ivas_spar_md_t *pSparMd, Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], @@ -3184,6 +4914,85 @@ void ivas_compute_spar_params( } #ifdef IVAS_FLOAT_FIXED + +void ivas_compute_spar_params_enc_fx( + Word32 *cov_real_fx[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + Word16 *q_cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + Word32 dm_fv_re_fx[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], + Word16 *q_dm_fv_re, + const Word16 i_ts, + Word32 ***mixer_mat_fx, + Word16 *q_mixer_mat, + const Word16 start_band, + const Word16 end_band, + const Word16 dtx_vad, + const Word16 num_ch, + const Word16 bands_bw, + const Word16 active_w, + const Word16 active_w_vlbr, + ivas_spar_md_com_cfg *hSparCfg, + ivas_spar_md_t *hSparMd, + Word32 *pWscale, + Word16 *q_Wscale, + const Word16 from_dirac, + const Word16 dyn_active_w_flag ) +{ + Word16 b, i, ndm; + Word16 q_pred_coeffs_re; + Word32 pred_coeffs_re_fx[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS]; + + ivas_get_pred_coeffs_enc_fx( cov_real_fx, q_cov_real, pred_coeffs_re_fx, &q_pred_coeffs_re, dm_fv_re_fx, q_dm_fv_re, num_ch, start_band, end_band, active_w, active_w_vlbr, dtx_vad, from_dirac, dyn_active_w_flag, hSparMd->res_ind ); + + ivas_create_fullr_dmx_mat_fx( pred_coeffs_re_fx, q_pred_coeffs_re, dm_fv_re_fx, *q_dm_fv_re, mixer_mat_fx, q_mixer_mat, num_ch, start_band, end_band, active_w, hSparCfg ); + + ivas_get_Wscaling_factor_enc_fx( cov_real_fx, q_cov_real, pred_coeffs_re_fx, q_pred_coeffs_re, mixer_mat_fx, *q_mixer_mat, start_band, end_band, dtx_vad, num_ch, hSparCfg->num_dmx_chans_per_band, bands_bw, active_w, active_w_vlbr, pWscale, q_Wscale, dyn_active_w_flag ); + + FOR( b = start_band; b < end_band; b++ ) + { + Word16 tmp_exp, q_tmp, tmp; + IF( pWscale[b] == 0 ) + { + pWscale[b] = 1; + move32(); + q_Wscale[b] = 15; + move16(); + } + + Word16 onebyscale_fx = BASOP_Util_Divide3232_Scale( 1, pWscale[b], &tmp_exp ); + q_tmp = sub( sub( 15, tmp_exp ), q_Wscale[b] ); + + tmp = sub( add( q_pred_coeffs_re, q_tmp ), 15 ); + FOR( i = 0; i < sub( num_ch, 1 ); i++ ) + { + hSparMd->band_coeffs[add( b, imult1616( i_ts, IVAS_MAX_NUM_BANDS ) )].pred_re_fx[i] = Mpy_32_16_1( pred_coeffs_re_fx[i][b], onebyscale_fx ); + move32(); + } + // hSparMd->band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].q_pred_re_fx = sub(add(q_pred_coeffs, q_tmp), 15); + hSparMd->band_coeffs[add( b, imult1616( i_ts, IVAS_MAX_NUM_BANDS ) )].q_pred_re_fx = tmp; + move16(); + + FOR( i = 0; i < num_ch; i++ ) + { + mixer_mat_fx[0][i][b] = W_extract_l( W_shr( W_mult0_32_32( mixer_mat_fx[0][i][b], pWscale[b] ), q_Wscale[b] ) ); + move32(); + } + } + + FOR( b = start_band; b < end_band; b++ ) + { + ndm = hSparCfg->num_dmx_chans_per_band[imult1616( b, bands_bw )]; + move16(); + + IF( NE_16( ndm, num_ch ) ) + { + ivas_calc_c_p_coeffs_enc_fx( hSparMd, cov_real_fx, q_cov_real, i_ts, mixer_mat_fx, *q_mixer_mat, num_ch, ndm, b, dtx_vad, 1, dyn_active_w_flag ); + } + } + + return; +} + + void ivas_compute_spar_params_fx( Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], Word16 q_cov_real, diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index 9c2e272e4..20a851b29 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -6930,18 +6930,18 @@ void dec_pit_exc_ivas_fx( #ifdef IVAS_FLOAT_FIXED // pit_dec_fx.c -Word32 Mode2_pit_decode( /* o: floating pitch value */ +Word32 Mode2_pit_decode( /* o: pitch value Q16 */ const Word16 coder_type, /* i: coding model */ Word16 i_subfr, /* i: subframe index */ Word16 L_subfr, - Word16 **pt_indice, /* i/o: quantization indices pointer */ - Word16 *T0, /* i/o: close loop integer pitch */ - Word16 *T0_frac, /* o: close loop fractional part of the pitch */ - Word16 *T0_res, /* i/o: pitch resolution */ - Word16 *T0_min, /* i/o: lower limit for close-loop search */ - Word16 *T0_min_frac, /* i/o: lower limit for close-loop search */ - Word16 *T0_max, /* i/o: higher limit for close-loop search */ - Word16 *T0_max_frac, /* i/o: higher limit for close-loop search */ + Word16 **pt_indice, /* i/o: quantization indices pointer */ + Word16 *T0, /* i/o: close loop integer pitch Q0 */ + Word16 *T0_frac, /* o: close loop fractional part of the pitch Q0 */ + Word16 *T0_res, /* i/o: pitch resolution Q0 */ + Word16 *T0_min, /* i/o: lower limit for close-loop search Q0 */ + Word16 *T0_min_frac, /* i/o: lower limit for close-loop search Q0 */ + Word16 *T0_max, /* i/o: higher limit for close-loop search Q0 */ + Word16 *T0_max_frac, /* i/o: higher limit for close-loop search Q0 */ Word16 pit_min, Word16 pit_fr1, Word16 pit_fr1b, @@ -6950,9 +6950,9 @@ Word32 Mode2_pit_decode( /* o: floating pitch value Word16 pit_res_max ); void Mode2_abs_pit_dec( - Word16 *T0, /* o: integer pitch lag */ - Word16 *T0_frac, /* o: pitch fraction */ - Word16 *T0_res, /* o: pitch resolution */ + Word16 *T0, /* o: integer pitch lag Q0 */ + Word16 *T0_frac, /* o: pitch fraction Q0 */ + Word16 *T0_res, /* o: pitch resolution Q0 */ Word16 **pt_indice, /* i/o: pointer to Vector of Q indexes */ Word16 pit_min, Word16 pit_fr1, @@ -6960,11 +6960,11 @@ void Mode2_abs_pit_dec( Word16 pit_res_max ); void Mode2_delta_pit_dec( - Word16 *T0, /* o: integer pitch lag */ - Word16 *T0_frac, /* o: pitch fraction */ - Word16 T0_res, /* i: pitch resolution */ - Word16 *T0_min, /* i: delta search min */ - Word16 *T0_min_frac, /* i: delta search min */ + Word16 *T0, /* o: integer pitch lag Q0 */ + Word16 *T0_frac, /* o: pitch fraction Q0 */ + Word16 T0_res, /* i: pitch resolution Q0 */ + Word16 *T0_min, /* i: delta search min Q0 */ + Word16 *T0_min_frac, /* i: delta search min Q0 */ Word16 **pt_indice /* i/o: pointer to Vector of Q indexes */ ); @@ -7001,8 +7001,8 @@ Word16 pit_decode_ivas_fx( /* o : floating p Word16 *T0_min, /* i/o: delta search min for sf 2 & 4 */ Word16 *T0_max, /* i/o: delta search max for sf 2 & 4 */ const Word16 L_subfr, /* i : subframe length */ - const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag */ - const Word16 tdm_Pri_pitch_buf[] /* i : primary channel pitch buffer */ + const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag */ + const Word16 tdm_Pri_pitch_buf[] /* i : primary channel pitch buffer Q6 */ ); void pit_Q_dec_fx( @@ -7077,33 +7077,32 @@ void limit_T0_voiced( // inov_dec.c void inov_decode_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word32 core_brate, /* i : core bitrate */ - const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ - const Word16 L_frame, /* i : length of the frame */ - const Word16 sharpFlag, /* i : formant sharpening flag */ - const Word16 i_subfr, /* i : subframe index */ + Decoder_State *st_fx, /* i/o: decoder state structure */ + const Word32 core_brate, /* i : core bitrate Q0 */ + const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode Q0 */ + const Word16 L_frame, /* i : length of the frame Q0 */ + const Word16 sharpFlag, /* i : formant sharpening flag Q0 */ + const Word16 i_subfr, /* i : subframe index Q0 */ const Word16 *p_Aq, /* i : LP filter coefficients Q12 */ const Word16 tilt_code, /* i : tilt of the excitation of previous subframe Q15 */ const Word16 pt_pitch, /* i : pointer to current subframe fractional pitch Q6*/ - Word16 *code /* o : algebraic excitation */ - , - const Word16 L_subfr /* i : subframe length */ + Word16 *code, /* o : algebraic excitation Q12 */ + const Word16 L_subfr /* i : subframe length Q0 */ ); #ifdef IVAS_FLOAT_FIXED void inov_decode_ivas_fx( Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word32 core_brate, /* i : core bitrate */ - const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ - const Word16 L_frame, /* i : length of the frame */ - const Word16 sharpFlag, /* i : formant sharpening flag */ - const Word16 i_subfr, /* i : subframe index */ + const Word32 core_brate, /* i : core bitrate Q0 */ + const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode Q0 */ + const Word16 L_frame, /* i : length of the frame Q0 */ + const Word16 sharpFlag, /* i : formant sharpening flag Q0 */ + const Word16 i_subfr, /* i : subframe index Q0 */ const Word16 *p_Aq, /* i : LP filter coefficients Q12 */ const Word16 tilt_code, /* i : tilt of the excitation of previous subframe Q15 */ const Word16 pt_pitch, /* i : pointer to current subframe fractional pitch Q6*/ - Word16 *code, /* o : algebraic excitation */ - const Word16 L_subfr /* i : subframe length */ + Word16 *code, /* o : algebraic excitation Q12 */ + const Word16 L_subfr /* i : subframe length Q0 */ ); #endif #ifdef IVAS_FLOAT_FIXED @@ -7779,7 +7778,7 @@ void hvq_dec_fx( Decoder_State *st_fx, /* i/o: decoder state structure */ const Word16 num_bits, /* i : Number of available bits */ const Word32 core_brate, /* i : Core bit-rate */ - const Word16 *ynrm, /* i : Envelope coefficients */ + const Word16 *ynrm, /* i : Envelope coefficients Q0 */ Word16 *R, /* i/o: Bit allocation/updated bit allocation */ Word16 *noise_level, /* o : Noise level in Q15 */ Word16 *peak_idx, /* o : Peak position vector */ @@ -7976,19 +7975,21 @@ Word16 FEC_pos_dec_fx( // post_dec.h void post_decoder( Decoder_State *st, - Word16 synth_buf[], - Word16 pit_gain[], - Word16 pitch[], - Word16 signal_out[], - Word16 *bpf_noise_buf ); + Word16 synth_buf[], /* Q0 */ + Word16 pit_gain[], /* Q14 */ + Word16 pitch[], /* Q0 */ + Word16 signal_out[], /* Q0 */ + Word16 *bpf_noise_buf /* Q0 */ +); void post_decoder_ivas_fx( Decoder_State *st, - Word16 synth_buf[], - Word16 pit_gain[], - Word16 pitch[], - Word16 signal_out[], - Word16 *bpf_noise_buf ); + Word16 synth_buf[], // Q0 + Word16 pit_gain[], // Q14 + Word16 pitch[], // Q0 + Word16 signal_out[], // Q0 + Word16 *bpf_noise_buf // Q0 +); void cldfb_synth_set_bandsToZero( Decoder_State *st, @@ -8283,13 +8284,12 @@ void swb_hr_noise_fill_fx( #ifdef IVAS_FLOAT_FIXED // stat_noise_uv_dec_fx.c void stat_noise_uv_dec_fx( - Decoder_State *st_fx, /* i/o: Decoder static memory */ - Word16 *lsp_new, /* i : end-frame LSP vector */ - Word16 *lsp_mid, /* i : mid-frame LSP vector */ - Word16 *Aq, /* o : A(z) quantized for the 4 subframes */ - Word16 *exc2 /* i/o: excitation buffer */ - , - const Word16 uc_two_stage_flag /* i : flag indicating two-stage UC */ + Decoder_State *st_fx, /* i/o: Decoder static memory */ + Word16 *lsp_new, /* i : end-frame LSP vector Q15 */ + Word16 *lsp_mid, /* i : mid-frame LSP vector Q15 */ + Word16 *Aq, /* o : A(z) quantized for the 4 subframes Q = 14 - norm_s(Aq[0]) */ + Word16 *exc2, /* i/o: excitation buffer, Q = st_fx->Q_exc */ + const Word16 uc_two_stage_flag /* i : flag indicating two-stage UC */ ); #endif diff --git a/lib_com/rom_com.c b/lib_com/rom_com.c index a496c0dd1..450c166cb 100644 --- a/lib_com/rom_com.c +++ b/lib_com/rom_com.c @@ -34696,7 +34696,7 @@ const float PowerCB_NB[64][2] = { 0.95166016f, 1.0351563f, }, }; -const Word16 PowerCB_WB_fx[128] = +const Word16 PowerCB_WB_fx[128] = /* Q11 */ { -3371, -1712, -170, 350, @@ -34764,7 +34764,7 @@ const Word16 PowerCB_WB_fx[128] = 1238, 2446 }; -const Word16 PowerCB_NB_fx[128] = +const Word16 PowerCB_NB_fx[128] = /* Q11 */ { -3349, -2784, -784, 385, diff --git a/lib_com/rom_com.h b/lib_com/rom_com.h index 3bf5740f5..993e213b3 100644 --- a/lib_com/rom_com.h +++ b/lib_com/rom_com.h @@ -1401,8 +1401,8 @@ extern const Word16 AmpCB2_NB_fx[64 * ( NUM_ERB_NB - 13 )]; extern const float PowerCB_WB[64][2]; extern const float PowerCB_NB[64][2]; -extern const Word16 PowerCB_WB_fx[128]; -extern const Word16 PowerCB_NB_fx[128]; +extern const Word16 PowerCB_WB_fx[128]; // Q11 +extern const Word16 PowerCB_NB_fx[128]; // Q11 extern const float sinc[8][12]; extern const Word16 sinc_fx[8][12]; diff --git a/lib_dec/d_gain2p.c b/lib_dec/d_gain2p.c index bd2366c9a..59b879058 100644 --- a/lib_dec/d_gain2p.c +++ b/lib_dec/d_gain2p.c @@ -42,12 +42,13 @@ #include "rom_com.h" #include "wmc_auto.h" +#ifndef IVAS_FLOAT_FIXED /*--------------------------------------------------------------------------* * Mode2_gain_dec_mless_flt * * Decoding of pitch and codebook gains without updating long term energies *-------------------------------------------------------------------------*/ -#ifndef IVAS_FLOAT_FIXED + static void Mode2_gain_dec_mless_flt( const int16_t index, /* i : index of quantizer */ const float code[], /* i : Innovative code vector */ @@ -132,7 +133,6 @@ static void Mode2_gain_dec_mless_flt( return; } -#endif /*---------------------------------------------------------------------* @@ -140,7 +140,7 @@ static void Mode2_gain_dec_mless_flt( * * Decoding of pitch and codebook gains for Unvoiced mode *---------------------------------------------------------------------*/ -#ifndef IVAS_FLOAT_FIXED + static void gain_dec_uv( const int16_t index, /* i/o: Quantization index vector */ const float *code, /* i : algebraic code excitation */ @@ -179,15 +179,13 @@ static void gain_dec_uv( return; } -#endif - /*---------------------------------------------------------------------* * gain_dec_gacelp_uv * * Decoding of pitch and codebook gains for Unvoiced mode *---------------------------------------------------------------------*/ -#ifndef IVAS_FLOAT_FIXED + void gain_dec_gacelp_uv( int16_t index, /* i/o: Quantization index vector */ const float *code, /* i : algebraic code excitation */ @@ -239,15 +237,13 @@ void gain_dec_gacelp_uv( return; } -#endif - /*---------------------------------------------------------------------* * decode_acelp_gains * * *---------------------------------------------------------------------*/ -#ifndef IVAS_FLOAT_FIXED + void decode_acelp_gains( const float *code, const int16_t gains_mode, diff --git a/lib_dec/d_gain2p_fx.c b/lib_dec/d_gain2p_fx.c index b93accc72..fe916acf3 100644 --- a/lib_dec/d_gain2p_fx.c +++ b/lib_dec/d_gain2p_fx.c @@ -17,18 +17,19 @@ * private functions * *********************/ static Word32 calc_gcode0_fx( - Word16 *gcode0, - Word16 *exp_gcode0 ) + Word16 *gcode0, // Q8 + Word16 *exp_gcode0 // Q0 +) { Word32 L_tmp; /*gcode0 = (float)pow(10.0,(gcode0)*0.05);*/ /* predicted gain */ - L_tmp = L_mult( *gcode0, 5443 /*0.166096f Q15*/ ); - *exp_gcode0 = add( 1, extract_l( L_shr( L_tmp, 24 ) ) ); + L_tmp = L_mult( *gcode0, 5443 /*0.166096f Q15*/ ); // Q24 + *exp_gcode0 = add( 1, extract_l( L_shr( L_tmp, 24 ) ) ); // Q0 move16(); - L_tmp = L_lshl( L_tmp, 7 ); - L_tmp = L_and( 0x7FFFFFFF, L_tmp ); + L_tmp = L_lshl( L_tmp, 7 ); // Q31 + L_tmp = L_and( 0x7FFFFFFF, L_tmp ); // 0x7FFFFFFF-> 1 in Q31 L_tmp = Pow2( 30, round_fx( L_tmp ) ); *gcode0 = round_fx( L_tmp ); @@ -81,7 +82,6 @@ static void Mode2_gain_dec_mless_fx( /**gain_inov = 1.0f / (float)sqrt( ( dot_product( code, code, lcode ) + 0.01f ) / lcode);*/ L_tmp = calc_gain_inov( code, lcode, &L_tmp1, &exp_L_tmp1 ); - move16(); #ifdef BASOP_NOGLOB *gain_inov = round_fx_sat( L_shl_sat( L_tmp, 15 - 3 ) ); /* gain_inov in Q12 */ #else @@ -176,9 +176,8 @@ static void gain_dec_uv_fx( *-----------------------------------------------------------------*/ /* *gain_inov = 1.0f / (float)sqrt( ( dot_product( code, code, lcode ) + 0.01f ) / lcode );*/ L_tmp = calc_gain_inov( code, lcode, &L_tmp1, &exp_L_tmp1 ); - move16(); *gain_inov = round_fx( L_shl( L_tmp, 15 - 3 ) ); /* gain_inov in Q12 */ - + move16(); /*-----------------------------------------------------------------* * Decode pitch gain *-----------------------------------------------------------------*/ @@ -192,7 +191,7 @@ static void gain_dec_uv_fx( L_tmp = L_mac( -167197708l /*-0.166096*30.0f Q25*/, shl( index, 16 - 7 ), 10341 /*0.166096f*1.9f Q15*/ ); i = add( 1, extract_l( L_shr( L_tmp, 25 ) ) ); L_tmp = L_lshl( L_tmp, 6 ); - L_tmp = L_and( 0x7FFFFFFF, L_tmp ); + L_tmp = L_and( 0x7FFFFFFF, L_tmp ); // 0x7FFFFFFF ->1 in Q31 L_tmp = Pow2( 30, round_fx( L_tmp ) ); L_tmp = L_shl( L_tmp, sub( i, ( 31 - 16 ) ) ); /* Q16 */ @@ -290,7 +289,7 @@ static void gain_dec_gacelp_uv_fx( * past gains for error concealment *-----------------------------------------------------------------*/ index2 = shr( index, 5 ); - index = s_and( index, 0x1F ); + index = s_and( index, 0x1F ); // 0x1F -> 31 /**gain_code= (float)pow(10.f,(((index*1.25f)-20.f)/20.f))*gcode;*/ @@ -298,10 +297,10 @@ static void gain_dec_gacelp_uv_fx( i = add( 1, extract_l( L_shr( L_tmp, 25 ) ) ); L_tmp = L_lshl( L_tmp, 6 ); - L_tmp = L_and( 0x7FFFFFFF, L_tmp ); + L_tmp = L_and( 0x7FFFFFFF, L_tmp ); // 0x7FFFFFFF-> 1 in Q31 L_tmp = Pow2( 30, round_fx( L_tmp ) ); - L_tmp = L_shl( L_tmp, i - ( 31 - 16 ) ); /* Q16 */ + L_tmp = L_shl( L_tmp, sub( i, ( 31 - 16 ) ) ); /* Q16 */ /* *past_gcode = L_tmp * pred_nrg_frame; */ i = norm_l( L_tmp ); @@ -421,10 +420,10 @@ void d_gain_pred_fx( move16(); } - if ( GT_16( nrg_mode, 2 ) ) + IF( GT_16( nrg_mode, 2 ) ) { - move16(); *Es_pred = extract_l( L_mac( -335544320l /* -20.f Q24*/, indice, 224 /* 1.75f Q7*/ ) ); /*(Q8 - ((Q0*Q7)=Q8))*/ + move16(); } return; diff --git a/lib_dec/dec4t64.c b/lib_dec/dec4t64.c index 9563ac643..90e870436 100644 --- a/lib_dec/dec4t64.c +++ b/lib_dec/dec4t64.c @@ -41,12 +41,11 @@ #include "ivas_prot.h" #include "rom_com.h" #include "wmc_auto.h" - +#ifndef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* * Local function prototypes *-------------------------------------------------------------------*/ -#ifndef IVAS_FLOAT_FIXED static void add_pulses( const int16_t pos[], const int16_t nb_pulse, const int16_t track, float code[] ); static void dec_1p_N1( const int32_t index, const int16_t N, const int16_t offset, int16_t pos[] ); static void dec_2p_2N1( const int32_t index, const int16_t N, const int16_t offset, int16_t pos[] ); @@ -56,7 +55,6 @@ static void dec_4p_4N( const int32_t index, const int16_t N, const int16_t offse static void dec_5p_5N( const int32_t index, const int16_t N, const int16_t offset, int16_t pos[] ); static void dec_6p_6N2( const int32_t index, const int16_t N, const int16_t offset, int16_t pos[] ); static void fcb_decode_PI( int32_t code_index, int16_t sector_6p[], const int16_t pulse_num ); -#endif /*----------------------------------------------------------------------------------* * dec_acelp_4t64() @@ -73,7 +71,6 @@ static void fcb_decode_PI( int32_t code_index, int16_t sector_6p[], const int16_ * See cod4t64.c for more details of the algebraic code. *----------------------------------------------------------------------------------*/ -#ifndef IVAS_FLOAT_FIXED void dec_acelp_4t64( Decoder_State *st, /* i/o: decoder state structure */ int16_t nbbits, /* i : number of bits per codebook */ @@ -264,7 +261,6 @@ void dec_acelp_4t64( return; } -#endif /*-------------------------------------------------------* * add_pulses() @@ -272,7 +268,6 @@ void dec_acelp_4t64( * Add decoded pulses to the codeword *-------------------------------------------------------*/ -#ifndef IVAS_FLOAT_FIXED static void add_pulses( const int16_t pos[], /* i : pulse position */ const int16_t nb_pulse, /* i : nb. of pulses */ @@ -297,14 +292,13 @@ static void add_pulses( return; } -#endif /*-------------------------------------------------------* * dec_1p_N1() * * Decode 1 pulse with N+1 bits *-------------------------------------------------------*/ -#ifndef IVAS_FLOAT_FIXED + void dec_1p_N1( const int32_t index, /* i : quantization index */ const int16_t N, /* i : nb. of bits */ @@ -377,8 +371,6 @@ void dec_2p_2N1( return; } -#endif - /*-------------------------------------------------------* * dec_3p_3N1() @@ -386,7 +378,6 @@ void dec_2p_2N1( * Decode 3 pulses with 3*N+1 bits: *-------------------------------------------------------*/ -#ifndef IVAS_FLOAT_FIXED static void dec_3p_3N1( const int32_t index, /* i : quantization index */ const int16_t N, /* i : nb. of bits */ @@ -534,14 +525,13 @@ static void dec_5p_5N( return; } -#endif /*-------------------------------------------------------* * dec_6p_6N2() * * Decode 6 pulses with 6*N+2 bits: *-------------------------------------------------------*/ -#ifndef IVAS_FLOAT_FIXED + static void dec_6p_6N2( const int32_t index, /* i : quantization index */ const int16_t N, /* i : nb. of bits */ @@ -697,7 +687,7 @@ static void fcb_decode_position( return; } -#endif + /*---------------------------------------------------------------------* * fcb_decode_PI() @@ -706,7 +696,7 @@ static void fcb_decode_position( *---------------------------------------------------------------------*/ /*! r: return pulse position number */ -#ifndef IVAS_FLOAT_FIXED + static void fcb_decode_PI( int32_t code_index, /* i : fcb index information */ int16_t sector_6p[], /* o : decoded pulse position */ @@ -746,13 +736,12 @@ static void fcb_decode_PI( return; } -#endif + /*---------------------------------------------------------------------* * Read FCB index * *---------------------------------------------------------------------*/ -#ifndef IVAS_FLOAT_FIXED void D_ACELP_decode_43bit( uint16_t idxs[], float code[], @@ -788,7 +777,6 @@ void D_ACELP_decode_43bit( return; } -#endif /*-------------------------------------------------------* * dec_1p_N1() @@ -796,7 +784,6 @@ void D_ACELP_decode_43bit( * Decode 1 pulse with N+1 bits *-------------------------------------------------------*/ -#ifndef IVAS_FLOAT_FIXED static void dec_1p_N1_L_subfr( const int32_t index, /* i : quantization index */ const int16_t nb_pos, /* i : number of positions */ @@ -820,7 +807,6 @@ static void dec_1p_N1_L_subfr( return; } -#endif /*-------------------------------------------------------* * add_pulses() @@ -828,7 +814,7 @@ static void dec_1p_N1_L_subfr( * Add decoded pulses to the codeword *-------------------------------------------------------*/ -#ifndef IVAS_FLOAT_FIXED + static void add_pulses_L_subfr( const int16_t nb_pos, /* i : number of positions */ const int16_t pos[], /* i : pulse position */ @@ -854,14 +840,13 @@ static void add_pulses_L_subfr( return; } -#endif /*----------------------------------------------------------------------------------* * dec_acelp_fast() * * fast algebraic codebook decoder *----------------------------------------------------------------------------------*/ -#ifndef IVAS_FLOAT_FIXED + void dec_acelp_fast( Decoder_State *st, /* i/o: decoder state structure */ const int16_t cdk_index, /* i : codebook index */ diff --git a/lib_dec/dec4t64_fx.c b/lib_dec/dec4t64_fx.c index 517b4f0b2..32774bd8e 100644 --- a/lib_dec/dec4t64_fx.c +++ b/lib_dec/dec4t64_fx.c @@ -244,7 +244,7 @@ static void add_pulses_fx( const Word16 pos[], /* i: pulse position */ const Word16 nb_pulse, /* i: nb. of pulses */ const Word16 track, /* i: no. of the tracks */ - Word16 code[] /* i/o: decoded codevector */ + Word16 code[] /* i/o: decoded codevector Q9*/ ) { @@ -690,17 +690,17 @@ static void fcb_decode_position_fx( FOR( i = 0; i < pos_num - 1; i++ ) { /* k = PI_select_table[16-l][temp] - k ;*/ - k = L_sub( PI_select_table[L_sub( 16, l )][temp], k ); + k = L_sub( PI_select_table[( 16 - l )][temp], k ); - FOR( ; PI_select_table[L_sub( 16, l )][temp] >= k; l += 2 ); + FOR( ; PI_select_table[( 16 - l )][temp] >= k; l += 2 ); - IF( GT_32( k, PI_select_table[L_sub( 17, l )][temp] ) ) + IF( GT_32( k, PI_select_table[( 17 - l )][temp] ) ) { l = L_sub( l, 1 ); } /* k = PI_select_table[17-l][temp--] - k ;*/ - k = L_sub( PI_select_table[L_sub( 17, l )][temp], k ); + k = L_sub( PI_select_table[( 17 - l )][temp], k ); temp = sub( temp, 1 ); pos_vector[i] = extract_l( L_sub( l, 1 ) ); move16(); @@ -1067,7 +1067,7 @@ static void add_pulses_L_subfr_fx( const Word16 pos[], /* i : pulse position */ const Word16 nb_pulse, /* i : nb. of pulses */ const Word16 track, /* i : no. of the tracks */ - Word16 code[] /* i/o: decoded codevector */ + Word16 code[] /* i/o: decoded codevector Q12 */ ) { Word16 i, k; @@ -1095,7 +1095,7 @@ static void add_pulses_L_subfr_fx( void dec_acelp_fast_fx( Decoder_State *st, /* i/o: decoder state structure */ const Word16 cdk_index, /* i : codebook index */ - Word16 code[], /* o : algebraic (fixed) codebook excitation */ + Word16 code[], /* o : algebraic (fixed) codebook excitation Q9*/ const Word16 L_subfr /* i : subframe length */ ) { @@ -1204,19 +1204,19 @@ void dec_acelp_fast_fx( i0 = shl( s_and( shr( index, 7 ), ( NB_POS_FCB_2T_128 - 1 ) ), 1 ); i1 = add( shl( s_and( index, ( NB_POS_FCB_2T_128 - 1 ) ), 1 ), 1 ); - code[i0] = -512; + code[i0] = -512; //-1 in Q9 move16(); IF( EQ_16( s_and( index, 0x2000 ), 0 ) ) { - code[i0] = 512; + code[i0] = 512; // 1 in Q9 move16(); } - code[i1] = -512; + code[i1] = -512; //-1 in Q9 move16(); IF( EQ_16( s_and( index, 0x40 ), 0 ) ) { - code[i1] = 512; + code[i1] = 512; // 1 in Q9 move16(); } } diff --git a/lib_dec/dec_LPD_fx.c b/lib_dec/dec_LPD_fx.c index 7a8abdd83..8e65aaa8e 100644 --- a/lib_dec/dec_LPD_fx.c +++ b/lib_dec/dec_LPD_fx.c @@ -27,12 +27,12 @@ void decoder_LPD_fx( Word16 signal_outFB[], /* o : synthesis @output_FS */ Word16 *total_nbbits, /* i/o: number of bits / decoded bits */ Decoder_State *st, /* i/o: decoder memory state pointer */ - Word16 *bpf_noise_buf, /* i/o: BPF noise buffer */ + Word16 *bpf_noise_buf, /* i/o: BPF noise buffer Q0 */ Word16 bfi, /* i : BFI flag */ Word16 *bitsRead, /* o : number of read bits */ Word16 param[], /* o : buffer of parameters */ - Word16 *pitch_buf, /* i/o: floating pitch values for each subfr*/ - Word16 *voice_factors, /* o : voicing factors */ + Word16 *pitch_buf, /* i/o: floating pitch values for each subfr Q6*/ + Word16 *voice_factors, /* o : voicing factors Q15*/ Word16 *ptr_bwe_exc /* o : excitation for SWB TBE */ ) { @@ -171,11 +171,12 @@ void decoder_LPD_fx( move16(); st->flagGuidedAcelp = 0; move16(); - st->nbLostCmpt++; + st->nbLostCmpt = add( st->nbLostCmpt, 1 ); move16(); st->core_brate = st->last_core_brate; move16(); st->core = GetPLCModeDecision_fx( st ); + move16(); } } ELSE @@ -285,7 +286,7 @@ void decoder_LPD_fx( test(); test(); test(); - IF( EQ_16( st->core, ACELP_CORE ) && EQ_16( st->last_core, ACELP_CORE ) && LT_32( lsp_diff, 52428 ) && GT_32( lsp_diff, 3932 ) && EQ_16( st->next_coder_type, GENERIC ) && !st->prev_use_partial_copy && EQ_16( st->last_coder_type, UNVOICED ) && GE_16( st->rf_frame_type, RF_GENPRED ) ) + IF( ( st->core == ACELP_CORE ) && ( st->last_core == ACELP_CORE ) && LT_32( lsp_diff, 52428 ) && GT_32( lsp_diff, 3932 ) && EQ_16( st->next_coder_type, GENERIC ) && !st->prev_use_partial_copy && EQ_16( st->last_coder_type, UNVOICED ) && GE_16( st->rf_frame_type, RF_GENPRED ) ) { Copy( &lsp[0], &lsp[M], M ); } @@ -300,7 +301,7 @@ void decoder_LPD_fx( Copy( &lsf[( k + 1 ) * M], &xsfnew_uw[k * M], M ); } } - ELSE IF( ( hTcxDec->enableTcxLpc != 0 && NE_16( st->core, ACELP_CORE ) ) || ( bfi && st->use_partial_copy && EQ_16( st->rf_frame_type, RF_TCXFD ) ) ) + ELSE IF( ( hTcxDec->enableTcxLpc != 0 && ( st->core != ACELP_CORE ) ) || ( bfi && st->use_partial_copy && EQ_16( st->rf_frame_type, RF_TCXFD ) ) ) { Word16 tcx_lpc_cdk; test(); @@ -350,7 +351,7 @@ void decoder_LPD_fx( test(); test(); test(); - IF( EQ_16( st->prev_use_partial_copy, 1 ) && EQ_16( st->last_core, ACELP_CORE ) && EQ_16( st->core, ACELP_CORE ) && GE_16( st->prev_rf_frame_type, RF_GENPRED ) && EQ_16( st->coder_type, UNVOICED ) ) + IF( EQ_16( st->prev_use_partial_copy, 1 ) && ( st->last_core == ACELP_CORE ) && ( st->core == ACELP_CORE ) && GE_16( st->prev_rf_frame_type, RF_GENPRED ) && EQ_16( st->coder_type, UNVOICED ) ) { test(); IF( st->lpcQuantization && st->acelp_cfg.midLpc ) @@ -376,11 +377,11 @@ void decoder_LPD_fx( FOR( i = 0; i < M; i++ ) { move16(); - st->lsf_adaptive_mean_fx[i] = add( add( mult_r( st->lsfoldbfi1_fx[i], 10923 /*1.0f/3.0f Q15*/ ), mult_r( st->lsfoldbfi0_fx[i], 10923 /*1.0f/3.0f Q15*/ ) ), mult_r( xsfnew_uw[add( imult1616( k, M ), i )], 10923 /*1.0f/3.0f Q15*/ ) ); + st->lsf_adaptive_mean_fx[i] = add( add( mult_r( st->lsfoldbfi1_fx[i], 10923 /*1.0f/3.0f Q15*/ ), mult_r( st->lsfoldbfi0_fx[i], 10923 /*1.0f/3.0f Q15*/ ) ), mult_r( xsfnew_uw[( k * M ) + i], 10923 /*1.0f/3.0f Q15*/ ) ); move16(); st->lsfoldbfi1_fx[i] = st->lsfoldbfi0_fx[i]; move16(); - st->lsfoldbfi0_fx[i] = xsfnew_uw[add( imult1616( k, M ), i )]; + st->lsfoldbfi0_fx[i] = xsfnew_uw[( k * M ) + i]; } } } @@ -414,20 +415,20 @@ void decoder_LPD_fx( FOR( k = 0; k < st->numlpc; k++ ) { - Copy( &xsfnew_uw[k * M], &lsf[add( k, 1 ) * M], M ); + Copy( &xsfnew_uw[k * M], &lsf[( k + 1 ) * M], M ); IF( st->tcxonly ) { - E_LPC_lsf_lsp_conversion( &lsf[add( k, 1 ) * M], &lsp[add( k, 1 ) * M], M ); + E_LPC_lsf_lsp_conversion( &lsf[( k + 1 ) * M], &lsp[( k + 1 ) * M], M ); E_LPC_lsf_lsp_conversion( st->lsf_q_cng, st->lsp_q_cng, M ); } ELSE { - lsf2lsp_fx( &lsf[add( k, 1 ) * M], &lsp[add( k, 1 ) * M], M, st->sr_core ); + lsf2lsp_fx( &lsf[( k + 1 ) * M], &lsp[( k + 1 ) * M], M, st->sr_core ); lsf2lsp_fx( st->lsf_q_cng, st->lsp_q_cng, M, st->sr_core ); } - Copy( &lsp[add( k, 1 ) * M], &xspnew_uw[imult1616( k, M )], M ); + Copy( &lsp[( k + 1 ) * M], &xspnew_uw[( k * M )], M ); } } @@ -448,14 +449,14 @@ void decoder_LPD_fx( IF( st->enablePlcWaveadjust ) { - if ( EQ_16( st->core, ACELP_CORE ) ) + if ( ( st->core == ACELP_CORE ) ) { st->tonality_flag = 0; move16(); } if ( bfi ) { - st->plcInfo.nbLostCmpt++; + st->plcInfo.nbLostCmpt = add( st->plcInfo.nbLostCmpt, 1 ); move16(); } } @@ -485,6 +486,7 @@ void decoder_LPD_fx( IF( bfi == 0 ) { st->stab_fac_fx = lsf_stab_fx( &lsf[M], &lsf[0], 0, st->L_frame ); + move16(); } test(); @@ -537,7 +539,7 @@ void decoder_LPD_fx( test(); test(); test(); - if ( EQ_16( st->clas_dec, UNVOICED_CLAS ) || EQ_16( st->clas_dec, SIN_ONSET ) || EQ_16( st->clas_dec, INACTIVE_CLAS ) || EQ_16( st->coder_type, GENERIC ) || EQ_16( st->coder_type, TRANSITION ) ) + if ( ( st->clas_dec == UNVOICED_CLAS ) || EQ_16( st->clas_dec, SIN_ONSET ) || EQ_16( st->clas_dec, INACTIVE_CLAS ) || EQ_16( st->coder_type, GENERIC ) || EQ_16( st->coder_type, TRANSITION ) ) { st->relax_prev_lsf_interp = 1; move16(); @@ -565,7 +567,7 @@ void decoder_LPD_fx( } test(); - IF( bfi != 0 && NE_16( st->last_core, ACELP_CORE ) ) + IF( bfi != 0 && ( st->last_core != ACELP_CORE ) ) { /* PLC: [TCX: TD PLC] */ #ifdef IVAS_CODE_CNG_FIX185_PLC_FADEOUT @@ -616,8 +618,8 @@ void decoder_LPD_fx( { move16(); move16(); - st->mem_pitch_gain[sub( add( 2, ( sub( shl( st->nb_subfr, 1 ), 1 ) ) ), i )] = st->mem_pitch_gain[sub( add( 2, sub( st->nb_subfr, 1 ) ), i )]; - st->mem_pitch_gain[sub( add( 2, sub( st->nb_subfr, 1 ) ), i )] = pit_gain[i]; + st->mem_pitch_gain[2 + ( 2 * st->nb_subfr - 1 ) - i] = st->mem_pitch_gain[( ( 2 + ( st->nb_subfr - 1 ) ) - i )]; + st->mem_pitch_gain[2 + ( st->nb_subfr - 1 ) - i] = pit_gain[i]; } } } @@ -662,10 +664,12 @@ void decoder_LPD_fx( IF( st->tcxonly != 0 ) { st->stab_fac_fx = lsf_stab_fx( &lsf[M], &lsf[0], 0, L_FRAME ); + move16(); } ELSE { st->stab_fac_fx = lsf_stab_fx( &lsf[M], &lsf[0], 0, st->L_frame ); + move16(); } } @@ -724,16 +728,17 @@ void decoder_LPD_fx( /* Stability Factor */ IF( bfi == 0 ) { - st->stab_fac_fx = lsf_stab_fx( &lsf[( add( k, 1 ) ) * M], &lsf[k * M], 0, L_FRAME ); + st->stab_fac_fx = lsf_stab_fx( &lsf[( ( k + 1 ) ) * M], &lsf[k * M], 0, L_FRAME ); + move16(); } - E_LPC_f_lsp_a_conversion( &lsp[( add( k, 1 ) ) * M], Aq, M ); + E_LPC_f_lsp_a_conversion( &lsp[( ( k + 1 ) ) * M], Aq, M ); /* TCX decoder */ IGFDecRestoreTCX10SubFrameData( st->hIGFDec, k ); decoder_tcx_fx( st->hTcxCfg, prm, Aq, Aind, shr( L_frame, 1 ), shr( L_frameTCX, 1 ), - shr( st->hTcxCfg->tcx_coded_lines, 1 ), &synth[shr( imult1616( k, L_frame ), 1 )], &synthFB[shr( imult1616( k, L_frameTCX ), 1 )], st, st->coder_type, bfi, k, st->stab_fac_fx ); + shr( st->hTcxCfg->tcx_coded_lines, 1 ), &synth[k * L_frame / 2], &synthFB[k * L_frameTCX / 2], st, st->coder_type, bfi, k, st->stab_fac_fx ); } } @@ -756,7 +761,7 @@ void decoder_LPD_fx( test(); test(); test(); - IF( ( bfi || st->prev_bfi ) && st->plcInfo.Pitch_fx && ( EQ_16( st->plcInfo.concealment_method, TCX_NONTONAL ) ) ) + IF( ( bfi || st->prev_bfi ) && st->plcInfo.Pitch_fx && ( ( st->plcInfo.concealment_method == TCX_NONTONAL ) ) ) { lerp( synthFB, synth, L_frame, L_frameTCX ); test(); @@ -917,6 +922,7 @@ void decoder_LPD_fx( } /* use latest LPC set */ st->old_enr_LP = Enr_1_Az_fx( Aq + offset, L_SUBFR ); /*Q3*/ + move16(); } @@ -1001,7 +1007,7 @@ void decoder_LPD_fx( { if ( !bfi ) { - st->plcInfo.nbLostCmpt = extract_l( L_deposit_l( 0 ) ); + st->plcInfo.nbLostCmpt = 0; move16(); } diff --git a/lib_dec/dec_ace_fx.c b/lib_dec/dec_ace_fx.c index 1ba8222ea..81f2f14fd 100644 --- a/lib_dec/dec_ace_fx.c +++ b/lib_dec/dec_ace_fx.c @@ -22,15 +22,15 @@ void decoder_acelp_fx( Decoder_State *st, Word16 prm[], /* i : parameters */ Word16 A[], /* i : coefficients NxAz[M+1] */ - ACELP_config acelp_cfg, /* i : ACELP config */ + ACELP_config acelp_cfg, /* i : ACELP config Q12 */ Word16 synth[], /* i/o: synth[-2*LFAC..L_DIV] Q0 */ Word16 *pT, /* o : pitch for all subframe Q0 */ Word16 *pgainT, /* o : pitch gain for all subfr 1Q14 */ Word16 stab_fac, /* i : stability of isf */ - Word16 *pitch_buffer, /* o : pitch values for each subfr. */ - Word16 *voice_factors, /* o : voicing factors */ + Word16 *pitch_buffer, /* o : pitch values for each subfr. Q6 */ + Word16 *voice_factors, /* o : voicing factors Q15 */ const Word16 LSF_Q_prediction, /* i : LSF prediction mode */ - Word16 *bwe_exc /* o : excitation for SWB TBE */ + Word16 *bwe_exc /* o : excitation for SWB TBE Q_exc */ ) { Word16 i, j, i_subfr; @@ -46,7 +46,7 @@ void decoder_acelp_fx( Word32 pitch_buf[NB_SUBFR16k]; Word16 dummy_pitch_buf[NB_SUBFR16k]; Word16 gain_inov; - Word16 mem_back[M]; + Word16 mem_back[M]; // Q_mem_back Word16 update_flg; Word16 Q_mem_back; /*Q format of mem_back*/ Word16 h1[L_FRAME_16k / 4 + 1]; @@ -61,9 +61,12 @@ void decoder_acelp_fx( /*Q formats of buffers */ Word16 prev_Q_syn; Word32 gain_code2 = 0; + move32(); Word16 code2[L_SUBFR]; Word16 error = 0; - Word16 gain_preQ = 0; /* Gain of prequantizer excitation */ + move16(); + Word16 gain_preQ = 0; /* Gain of prequantizer excitation */ + move16(); Word16 code_preQ[L_SUBFR]; /* Prequantizer excitation */ Word16 lp_flag; @@ -96,6 +99,8 @@ void decoder_acelp_fx( move16(); move16(); move16(); + move16(); + move16(); gain_pit = 0; gain_code = 0; move16(); @@ -106,7 +111,9 @@ void decoder_acelp_fx( gain_code2 = 0; prev_gain_pit = 0; + move16(); tmp_noise = 0; + move16(); IF( EQ_16( st->nb_subfr, 4 ) ) { @@ -132,14 +139,16 @@ void decoder_acelp_fx( weights[3] = 8738 /*(float)4/15 Q15*/; weights[4] = 10923 /*float)5/15 Q15*/; } - st->Mode2_lp_gainp = L_deposit_l( 0 ); - st->Mode2_lp_gainc = L_deposit_l( 0 ); + st->Mode2_lp_gainp = 0; + move32(); + st->Mode2_lp_gainc = 0; + move32(); avoid_lpc_burst_on_recovery = 0; move16(); test(); test(); - IF( st->last_con_tcx && ( NE_16( st->L_frameTCX_past, st->L_frame ) ) && ( st->last_core != 0 ) ) + if ( st->last_con_tcx && ( NE_16( st->L_frameTCX_past, st->L_frame ) ) && ( st->last_core != 0 ) ) { avoid_lpc_burst_on_recovery = 1; move16(); @@ -152,9 +161,10 @@ void decoder_acelp_fx( /* Reset phase dispersion */ - IF( GT_16( st->last_core_bfi, ACELP_CORE ) ) + IF( st->last_core_bfi > ACELP_CORE ) { - st->dm_fx.prev_gain_code = L_deposit_l( 0 ); + st->dm_fx.prev_gain_code = 0; + move32(); set16_fx( st->dm_fx.prev_gain_pit, 0, 6 ); st->dm_fx.prev_state = 0; move16(); @@ -179,11 +189,11 @@ void decoder_acelp_fx( IF( LT_16( st->old_enr_LP, enr_LP ) ) { ratio = div_s( st->old_enr_LP, enr_LP ); /* Q15 */ - IF( LT_16( ratio, 26215 ) ) + IF( LT_16( ratio, 26215 /*.8f in Q15*/ ) ) { FOR( i = 0; i < L_EXC_MEM_DEC; i++ ) { - st->old_exc_fx[i] = mult_r( st->old_exc_fx[i], ratio ); + st->old_exc_fx[i] = mult_r( st->old_exc_fx[i], ratio ); // Q_exc move16(); } } @@ -203,7 +213,7 @@ void decoder_acelp_fx( exc = exc_buf + L_EXC_MEM_DEC; Copy( st->old_exc_fx, exc_buf, L_EXC_MEM_DEC ); *( exc + st->L_frame ) = 0; - + move16(); /* Init syn buffer */ syn = syn_buf + M; Copy( st->mem_syn2_fx, syn_buf, M ); @@ -212,7 +222,7 @@ void decoder_acelp_fx( * Fast recovery flag *------------------------------------------------------------------------*/ test(); - IF( st->prev_bfi && EQ_16( st->coder_type, VOICED ) ) + if ( st->prev_bfi && EQ_16( st->coder_type, VOICED ) ) { /*Force BPF to be applied fully*/ st->bpf_gain_param = 3; @@ -277,7 +287,7 @@ void decoder_acelp_fx( *-------------------------------------------------------*/ test(); - IF( EQ_16( st->use_partial_copy, 1 ) && st->acelp_cfg.gains_mode[idx] == 0 ) + if ( EQ_16( st->use_partial_copy, 1 ) && st->acelp_cfg.gains_mode[idx] == 0 ) { gain_pit = prev_gain_pit; move16(); @@ -338,7 +348,7 @@ void decoder_acelp_fx( move16(); T0_res = 1; move16(); - pitch_buf[idx] = L_deposit_h( L_SUBFR ); + pitch_buf[idx] = L_deposit_h( L_SUBFR ); // Q16 move32(); } @@ -347,7 +357,7 @@ void decoder_acelp_fx( tbe_celp_exc( st->L_frame, i_subfr, T0, T0_frac, &error, bwe_exc ); } - pitch_buffer[idx] = shl( add( shl( T0, 2 ), T0_frac ), 4 ); + pitch_buffer[idx] = shl( add( shl( T0, 2 ), T0_frac ), 4 ); // Q6 move16(); /*-------------------------------------------------------* @@ -386,7 +396,8 @@ void decoder_acelp_fx( } ELSE { - gain_code2 = L_deposit_l( 0 ); + gain_code2 = 0; + move32(); set16_fx( code2, 0, L_SUBFR ); } @@ -398,14 +409,16 @@ void decoder_acelp_fx( decode_acelp_gains_fx( code, acelp_cfg.gains_mode[idx], Es_pred, &gain_pit, &gain_code, &prm, &( st->past_gpit ), &( st->past_gcode ), &gain_inov, L_SUBFR, code2, &gain_code2 ); } - IF( st->use_partial_copy && st->rf_frame_type == RF_ALLPRED ) + test(); + if ( st->use_partial_copy && EQ_16( st->rf_frame_type, RF_ALLPRED ) ) { st->past_gcode = 0; move32(); } - IF( st->use_partial_copy && st->rf_frame_type == RF_NOPRED ) + test(); + if ( st->use_partial_copy && EQ_16( st->rf_frame_type, RF_NOPRED ) ) { - st->past_gpit = 67; + st->past_gpit = 67; //.004089f in Q14 move32(); } IF( st->igf != 0 ) @@ -449,21 +462,36 @@ void decoder_acelp_fx( * - Find the total excitation. * *-------------------------------------------------------*/ gain_code_tmp = gain_code; + move32(); gain_pit_tmp = gain_pit; - IF( i_subfr == 0 ) + move16(); + if ( i_subfr == 0 ) { gain_code_pre = 0; + move32(); } - IF( EQ_16( st->core, ACELP_CORE ) && EQ_16( st->last_core, ACELP_CORE ) && ( EQ_16( st->use_partial_copy, 1 ) || EQ_16( st->prev_use_partial_copy, 1 ) ) ) + test(); + test(); + test(); + IF( ( st->core == ACELP_CORE ) && ( st->last_core == ACELP_CORE ) && ( EQ_16( st->use_partial_copy, 1 ) || EQ_16( st->prev_use_partial_copy, 1 ) ) ) { - IF( i_subfr > 0 && GT_16( gain_pit, 20152 ) && GT_16( st->prev_tilt_code_dec_fx, 6553 ) && EQ_16( st->next_coder_type, VOICED ) && ( EQ_16( st->use_partial_copy, 1 ) || EQ_16( st->prev_use_partial_copy, 1 ) ) ) + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + IF( i_subfr > 0 && GT_16( gain_pit, 20152 /*1.23 in Q14*/ ) && GT_16( st->prev_tilt_code_dec_fx, 6553 /*1.23 in Q15*/ ) && EQ_16( st->next_coder_type, VOICED ) && ( EQ_16( st->use_partial_copy, 1 ) || EQ_16( st->prev_use_partial_copy, 1 ) ) ) { - gain_pit = mult( gain_pit, sub( 26214, mult( i_subfr, 51 ) ) ); + gain_pit = mult( gain_pit, sub( 26214 /*.8f in Q15*/, mult( i_subfr, 51 /*1.0f/640 in Q15*/ ) ) ); } ELSE IF( !st->prev_use_partial_copy && EQ_16( st->last_coder_type, UNVOICED ) && NE_16( st->next_coder_type, UNVOICED ) && LT_32( gain_code, gain_code_pre ) ) { gain_code = 0; + move32(); } } gain_code_pre = gain_code; @@ -475,17 +503,18 @@ void decoder_acelp_fx( tmp2 = shr( L_SUBFR, 1 ); FOR( j = 0; j < 2; j++ ) { - FOR( i = sub( tmp2, shr( L_SUBFR, 1 ) ); i < tmp2; i++ ) + FOR( i = ( tmp2 - ( L_SUBFR / 2 ) ); i < tmp2; i++ ) { /* code in Q9, gain_pit in Q14, gain_code in Q16; exc Q_new */ Ltmp = Mpy_32_16_1( gain_code2, code2[i] ); Ltmp = L_shl( Ltmp, add( 5, st->Q_exc ) ); Ltmp = L_mac( Ltmp, gain_pit, exc[i + i_subfr] ); #ifdef BASOP_NOGLOB - exc2[add( i, i_subfr )] = round_fx_sat( L_shl_sat( Ltmp, 1 ) ); + exc2[( i + i_subfr )] = round_fx_sat( L_shl_sat( Ltmp, 1 ) ); #else exc2[i + i_subfr] = round_fx( L_shl( Ltmp, 1 ) ); #endif + move16(); Ltmp2 = Mpy_32_16_1( gain_code, code[i] ); Ltmp2 = L_shl( Ltmp2, add( 5, st->Q_exc ) ); Ltmp = L_add( Ltmp, Ltmp2 ); @@ -497,10 +526,11 @@ void decoder_acelp_fx( #endif BASOP_SATURATE_WARNING_ON_EVS #ifdef BASOP_NOGLOB - exc[add( i, i_subfr )] = round_fx_sat( Ltmp ); + exc[( i + i_subfr )] = round_fx_sat( Ltmp ); #else exc[i + i_subfr] = round_fx( Ltmp ); #endif + move16(); } tmp2 = L_SUBFR; move16(); @@ -556,7 +586,7 @@ void decoder_acelp_fx( * - update pitch lag for guided ACELP * *----------------------------------------------------------*/ test(); - IF( st->enableGplc && EQ_16( shr( i_subfr, 6 ), sub( st->nb_subfr, 1 ) ) ) + if ( st->enableGplc && EQ_16( shr( i_subfr, 6 ), sub( st->nb_subfr, 1 ) ) ) { st->T0_4th = T0; move16(); @@ -611,8 +641,10 @@ void decoder_acelp_fx( /* impulse response level = gain introduced by synthesis+deemphasis */ Ltmp = Dot_productSq16HQ( 0, h1, L_SUBFR, &st->last_gain_syn_deemph_e ); st->last_gain_syn_deemph_e = add( st->last_gain_syn_deemph_e, 10 /*scaling of h1[0] and E_UTIL_synthesis * 2*/ ); + move16(); #ifdef BASOP_NOGLOB - st->last_gain_syn_deemph = round_fx_sat( Sqrt32( Ltmp, &st->last_gain_syn_deemph_e ) ); + st->last_gain_syn_deemph = round_fx_sat( Sqrt32( Ltmp, &st->last_gain_syn_deemph_e ) ); // Q(15-last_gain_syn_deemph_e - (16)) + move16(); #else st->last_gain_syn_deemph = round_fx( Sqrt32( Ltmp, &st->last_gain_syn_deemph_e ) ); #endif @@ -660,14 +692,14 @@ void decoder_acelp_fx( move16(); } - Scale_sig( mem_back, M, sub( st->Q_syn, Q_mem_back ) ); + Scale_sig( mem_back, M, sub( st->Q_syn, Q_mem_back ) ); // Q_syn force_scale_syn = 0; move16(); + test(); test(); - test(); - IF( ( EQ_16( st->clas_dec, ONSET ) ) || ( ( GE_16( st->last_good, VOICED_TRANSITION ) ) && ( LT_16( st->last_good, INACTIVE_CLAS ) ) ) ) + if ( ( EQ_16( st->clas_dec, ONSET ) ) || ( ( GE_16( st->last_good, VOICED_TRANSITION ) ) && ( LT_16( st->last_good, INACTIVE_CLAS ) ) ) ) { force_scale_syn = 1; move16(); @@ -704,11 +736,12 @@ void decoder_acelp_fx( FOR( i_subfr = 0; i_subfr < st->L_frame; i_subfr += L_SUBFR ) { Word16 idx = 0; + move16(); IF( i_subfr != 0 ) { idx = idiv1616( i_subfr, L_SUBFR ); } - *pT++ = round_fx( pitch_buf[idx] ); + *pT++ = round_fx( pitch_buf[idx] ); // Q0 } @@ -721,8 +754,10 @@ void decoder_acelp_fx( move16(); hTcxDec->tcxltp_third_last_pitch = hTcxDec->tcxltp_second_last_pitch; + move32(); hTcxDec->tcxltp_second_last_pitch = st->old_fpitch; - st->old_fpitch = pitch_buf[sub( shr( st->L_frame, 6 ), 1 )]; + move32(); + st->old_fpitch = pitch_buf[( ( st->L_frame >> 6 ) - 1 )]; move32(); diff --git a/lib_dec/dec_acelp_fx.c b/lib_dec/dec_acelp_fx.c index 8379eec7e..f65ee4bf7 100644 --- a/lib_dec/dec_acelp_fx.c +++ b/lib_dec/dec_acelp_fx.c @@ -24,7 +24,7 @@ static void D_ACELP_decode_arithtrack_fx( Word16 v[], Word32 s, Word16 p, Word16 *---------------------------------------------------------------------*/ void D_ACELP_indexing_fx( - Word16 code[], + Word16 code[], // Q9 PulseConfig config, Word16 num_tracks, Word16 index[], @@ -142,7 +142,7 @@ void D_ACELP_indexing_fx( ELSE { fcb_pulse_track_joint_decode_fx( idxs, wordcnt, index_n, pulsestrack, num_tracks ); - FOR( track = sub( num_tracks, 1 ); track >= 1; track-- ) + FOR( track = ( num_tracks - 1 ); track >= 1; track-- ) { pulses = pulsestrack[track]; move16(); @@ -152,12 +152,13 @@ void D_ACELP_indexing_fx( /* divide by number of possible states: rest is actual state and * the integer part goes to next track */ s = index_n[track]; + move32(); /* decode state to actual pulse positions on track */ D_ACELP_decode_arithtrack_fx( code + track, s, pulses, num_tracks, 16 ); } ELSE /* track is empty */ { - FOR( k = track; k < imult1616( 16, num_tracks ); k += num_tracks ) + FOR( k = track; k < ( 16 * num_tracks ); k += num_tracks ) { code[k] = 0; move16(); @@ -209,12 +210,12 @@ static void D_ACELP_decode_arithtrack_fx( Word16 v[], Word32 s, Word16 p, Word16 FOR( ; p; p-- ) /* one pulse placed, so one less left */ { - IF( LT_32( s, pulsestostates[k][sub( p, 1 )] ) ) + IF( LT_32( s, pulsestostates[k][p - 1] ) ) { BREAK; } - s = L_sub( s, pulsestostates[k][sub( p, 1 )] ); + s = L_sub( s, pulsestostates[k][p - 1] ); IF( v[idx] != 0 ) /* there is a pulse here already = sign is known */ { @@ -271,7 +272,7 @@ void fcb_pulse_track_joint_decode_fx( UWord16 *idxs, Word16 wordcnt, UWord32 *in hi_to_low[4] = 1; move16(); - IF( GE_16( indx_flag, track_num ) ) + if ( GE_16( indx_flag, track_num ) ) { hi_to_low[4] = 9; move16(); @@ -279,7 +280,7 @@ void fcb_pulse_track_joint_decode_fx( UWord16 *idxs, Word16 wordcnt, UWord32 *in hi_to_low[7] = 1; move16(); - IF( GE_16( indx_flag_2, 1 ) ) + if ( GE_16( indx_flag_2, 1 ) ) { hi_to_low[7] = 9; move16(); @@ -289,7 +290,8 @@ void fcb_pulse_track_joint_decode_fx( UWord16 *idxs, Word16 wordcnt, UWord32 *in { IF( GE_16( indx_flag, track_num ) ) { - index = L_deposit_l( 0 ); + index = 0; + move32(); IF( GE_16( indx_flag_2, 1 ) ) { FOR( track = sub( wordcnt, 1 ); track >= 6; track-- ) @@ -320,8 +322,9 @@ void fcb_pulse_track_joint_decode_fx( UWord16 *idxs, Word16 wordcnt, UWord32 *in } ELSE { - index = L_deposit_l( 0 ); - FOR( track = sub( wordcnt, 1 ); track >= 2; track-- ) + index = 0; + move32(); + FOR( track = ( wordcnt - 1 ); track >= 2; track-- ) { index = L_add( L_lshl( index, 16 ), (UWord32) idxs[track] ); } @@ -340,7 +343,7 @@ void fcb_pulse_track_joint_decode_fx( UWord16 *idxs, Word16 wordcnt, UWord32 *in pulse_num1 = pulse_num[track_num1]; move16(); index = L_add( L_lshl( index, hi_to_low[pulse_num1] ), L_lshr( index_n[track_num1], low_len[pulse_num1] ) ); - FOR( track = sub( track_num, 1 ); track > 0; track-- ) + FOR( track = ( track_num - 1 ); track > 0; track-- ) { track_num1 = sub( track, 1 ); pulse_num0 = pulse_num[track_num1]; @@ -361,8 +364,9 @@ void fcb_pulse_track_joint_decode_fx( UWord16 *idxs, Word16 wordcnt, UWord32 *in } ELSE { - index = L_deposit_l( 0 ); - FOR( track = sub( wordcnt, 1 ); track >= 0; track-- ) + index = 0; + move32(); + FOR( track = ( wordcnt - 1 ); track >= 0; track-- ) { index = (UWord32) W_add( UL_lshl( index, 16 ), (UWord32) idxs[track] ); } diff --git a/lib_dec/dec_acelp_tcx_main_fx.c b/lib_dec/dec_acelp_tcx_main_fx.c index ad7117763..9a14aaf7b 100644 --- a/lib_dec/dec_acelp_tcx_main_fx.c +++ b/lib_dec/dec_acelp_tcx_main_fx.c @@ -56,7 +56,7 @@ static void decode_frame_type_fx( Decoder_State *st { /* ZERO Frame */ - IF( EQ_32( st->total_brate, FRAME_NO_DATA ) ) + IF( ( st->total_brate == FRAME_NO_DATA ) ) { st->bwidth = st->last_bwidth; move16(); @@ -68,7 +68,8 @@ static void decode_frame_type_fx( Decoder_State *st ELSE IF( EQ_32( st->total_brate, SID_2k40 ) ) { st->cng_type = get_next_indice( st, 1 ); - IF( NE_16( st->cng_type, FD_CNG ) ) + move16(); + if ( NE_16( st->cng_type, FD_CNG ) ) { st->BER_detect = 1; move16(); @@ -83,7 +84,7 @@ static void decode_frame_type_fx( Decoder_State *st frame_len_indicator = get_next_indice( st, 1 ); IF( EQ_16( st->bwidth, NB ) ) { - IF( frame_len_indicator ) + if ( frame_len_indicator ) { st->BER_detect = 1; move16(); @@ -103,7 +104,7 @@ static void decode_frame_type_fx( Decoder_State *st st->L_frame = L_FRAME16k; move16(); test(); - IF( st->last_total_brate == ACELP_16k40 || st->last_total_brate == ACELP_24k40 ) + IF( EQ_32( st->last_total_brate, ACELP_16k40 ) || EQ_32( st->last_total_brate, ACELP_24k40 ) ) { st->total_brate = st->last_total_brate; move32(); @@ -152,12 +153,15 @@ static void decode_frame_type_fx( Decoder_State *st /* Get bandwidth mode */ st->bwidth = get_next_indice( st, FrameSizeConfig[frame_size_index].bandwidth_bits ); + move16(); st->bwidth = add( st->bwidth, FrameSizeConfig[frame_size_index].bandwidth_min ); + move16(); } ELSE { st->bwidth = add( st->bwidth, FrameSizeConfig[frame_size_index].bandwidth_min ); + move16(); } IF( GT_16( st->bwidth, FB ) ) @@ -184,7 +188,7 @@ static void decode_frame_type_fx( Decoder_State *st Word16 dummyBit; dummyBit = (Word8) get_next_indice( st, 1 ); move16(); - IF( dummyBit != 0 ) + if ( dummyBit != 0 ) { st->BER_detect = 1; move16(); @@ -201,7 +205,7 @@ static void decode_frame_type_fx( Decoder_State *st IF( NE_16( st->last_codec_mode, MODE2 ) || !st->BER_detect ) { /* Mode or Rate Change */ - test(); + test(); test(); IF( ( EQ_16( st->m_frame_type, ACTIVE_FRAME ) || EQ_16( st->m_frame_type, SID_FRAME ) ) && ( s_or( s_or( s_or( s_or( (Word16) NE_32( st->total_brate, st->last_total_brate ), (Word16) NE_16( st->bwidth, st->last_bwidth ) ), (Word16) EQ_16( st->last_codec_mode, MODE1 ) ), (Word16) NE_16( st->rf_flag, st->rf_flag_last ) ), st->force_lpd_reset ) ) ) @@ -229,6 +233,7 @@ static void decode_frame_type_fx( Decoder_State *st IF( EQ_16( st->bwidth, NB ) ) { st->cldfbSyn->bandsToZero = sub( st->cldfbSyn->no_channels, 10 ); + move16(); } ELSE { @@ -262,7 +267,7 @@ static void decode_frame_type_fx( Decoder_State *st { FOR( n = 0; n < shl( st->L_frame, 1 ); n++ ) { - st->hFdCngDec->hFdCngCom->olapBufferSynth[n] = mult_r( st->hFdCngDec->hFdCngCom->olapBufferSynth[n], 20480 ); + st->hFdCngDec->hFdCngCom->olapBufferSynth[n] = mult_r( st->hFdCngDec->hFdCngCom->olapBufferSynth[n], 20480 /*1.25f in Q14*/ ); move16(); } } @@ -270,7 +275,7 @@ static void decode_frame_type_fx( Decoder_State *st { FOR( n = 0; n < shl( st->L_frame, 1 ); n++ ) { - st->hFdCngDec->hFdCngCom->olapBufferSynth[n] = mult_r( shl( st->hFdCngDec->hFdCngCom->olapBufferSynth[n], 1 ), 26214 ); + st->hFdCngDec->hFdCngCom->olapBufferSynth[n] = mult_r( shl( st->hFdCngDec->hFdCngCom->olapBufferSynth[n], 1 ), 26214 /* 1/1.25 in Q15*/ ); move16(); } } @@ -301,12 +306,12 @@ static void decode_frame_type_fx( Decoder_State *st Word16 dec_acelp_tcx_frame_fx( Decoder_State *st, /* i/o: decoder state structure */ Word16 *concealWholeFrame, /* i/o: concealment flag */ - Word16 *pcmBuf, /* o : synthesis */ - Word16 *bpf_noise_buf, /* i/o: BPF noise buffer */ - Word16 *pcmbufFB, /* o : synthesis @output_FS */ - Word32 bwe_exc_extended[], /* i/o: bandwidth extended excitation */ - Word16 *voice_factors, /* o : voicing factors */ - Word16 pitch_buf[] /* o : floating pitch for each subframe */ + Word16 *pcmBuf, /* o : synthesis Q0 */ + Word16 *bpf_noise_buf, /* i/o: BPF noise buffer Qx */ + Word16 *pcmbufFB, /* o : synthesis @output_FS Qx */ + Word32 bwe_exc_extended[], /* i/o: bandwidth extended excitation Q0 */ + Word16 *voice_factors, /* o : voicing factors Q15 */ + Word16 pitch_buf[] /* o : floating pitch for each subframe Q6 */ #ifdef IVAS_CODE_CNG , STEREO_CNG_DEC_HANDLE hStereoCng /* i : stereo CNG handle */ @@ -352,10 +357,15 @@ Word16 dec_acelp_tcx_frame_fx( { Word16 m_frame_type = st->m_frame_type; + move16(); Word16 bwidth = st->bwidth; + move16(); Word16 cng_type = st->cng_type; + move16(); Word16 L_frame = st->L_frame; + move16(); Word32 total_brate = st->last_total_brate; + move32(); decode_frame_type_fx( st #ifdef IVAS_CODE_CNG @@ -383,7 +393,7 @@ Word16 dec_acelp_tcx_frame_fx( move16(); st->L_frame = L_frame; move16(); - IF( st->ini_frame != 0 ) + if ( st->ini_frame != 0 ) { st->total_brate = total_brate; move32(); @@ -398,7 +408,7 @@ Word16 dec_acelp_tcx_frame_fx( test(); test(); - IF( ( NE_16( st->bwidth, st->last_bwidth ) ) || ( NE_16( st->rf_flag, st->rf_flag_last ) ) || ( NE_32( st->total_brate, st->last_total_brate ) ) ) + if ( ( NE_16( st->bwidth, st->last_bwidth ) ) || ( NE_16( st->rf_flag, st->rf_flag_last ) ) || ( NE_32( st->total_brate, st->last_total_brate ) ) ) { st->force_lpd_reset = 1; move16(); @@ -412,6 +422,7 @@ Word16 dec_acelp_tcx_frame_fx( IF( st->ini_frame == 0 && st->hTcxCfg != NULL ) { st->hTcxCfg->tcx_coded_lines = getNumTcxCodedLines( SWB ); + move16(); } } ELSE diff --git a/lib_dec/dec_amr_wb_fx.c b/lib_dec/dec_amr_wb_fx.c index ea3fa74f5..5e047e425 100644 --- a/lib_dec/dec_amr_wb_fx.c +++ b/lib_dec/dec_amr_wb_fx.c @@ -17,12 +17,12 @@ void decod_amr_wb_fx( Decoder_State *st_fx, /* i/o: decoder static memory */ - const Word16 *Aq_fx, /* i : LP filter coefficients */ - Word16 *pitch_buf_fx, /* o : floating pitch values for each subframe */ - Word16 *exc_fx, /* i/o: adapt. excitation exc */ - Word16 *exc2_fx, /* i/o: adapt. excitation/total exc */ + const Word16 *Aq_fx, /* i : LP filter coefficients Q12 */ + Word16 *pitch_buf_fx, /* o : floating pitch values for each subframe Q6*/ + Word16 *exc_fx, /* i/o: adapt. excitation exc Qx */ + Word16 *exc2_fx, /* i/o: adapt. excitation/total exc Qx */ Word16 hf_gain_fx[NB_SUBFR], /* o : decoded HF gain */ - Word16 *voice_factors_fx, /* o : voicing factors */ + Word16 *voice_factors_fx, /* o : voicing factors Q15 */ Word16 *gain_buf /* o : floating pitch gain for each subframe Q14 */ ) { @@ -50,13 +50,14 @@ void decod_amr_wb_fx( p_Aq_fx = Aq_fx; /* pointer to interpolated LPC parameters */ pt_pitch_fx = pitch_buf_fx; /* pointer to the pitch buffer */ - L_Voice_fac_ave = L_deposit_l( 0 ); + L_Voice_fac_ave = 0; + move32(); pitch_limit_flag = 0; move16(); /* always restrained pitch Q range in IO mode */ lp_flag = NORMAL_OPERATION; move16(); /* always restrained pitch Q range in IO mode */ - IF( LT_32( st_fx->core_brate, ACELP_11k60 ) ) + if ( LT_32( st_fx->core_brate, ACELP_11k60 ) ) { lp_flag = LOW_PASS; move16(); /* always restrained pitch Q range in IO mode */ @@ -77,7 +78,6 @@ void decod_amr_wb_fx( 0, NULL #endif ); - move16(); /*--------------------------------------------------------------* * Find the adaptive codebook vector *--------------------------------------------------------------*/ @@ -139,7 +139,7 @@ void decod_amr_wb_fx( /*voice_fac = VF_0th_PARAM + VF_1st_PARAM * voice_fac + VF_2nd_PARAM * voice_fac * voice_fac;*/ L_tmp = L_mult( VF_2nd_PARAM_FX, mult_r( voice_fac_fx, voice_fac_fx ) ); L_tmp = L_mac( L_tmp, VF_1st_PARAM_FX, voice_fac_fx ); - voice_fac_fx = mac_r( L_tmp, VF_0th_PARAM_FX, 32767 ); + voice_fac_fx = mac_r( L_tmp, VF_0th_PARAM_FX, 32767 ); // 1.0f in Q15 Word16 idx; idx = 0; @@ -150,17 +150,17 @@ void decod_amr_wb_fx( } /*voice_factors[i_subfr/L_SUBFR] = min( max(0.0f, voice_fac), 1.0f);*/ - voice_factors_fx[idx] = s_min( s_max( 0, voice_fac_fx ), 32767 ); + voice_factors_fx[idx] = s_min( s_max( 0, voice_fac_fx ), 32767 /*1.0f in Q15*/ ); // Q15 move16(); p_Aq_fx += ( M + 1 ); pt_pitch_fx++; - L_Voice_fac_ave = L_mac( L_Voice_fac_ave, 8192, voice_fac_fx ); + L_Voice_fac_ave = L_mac( L_Voice_fac_ave, 8192, voice_fac_fx ); // .25f in Q15 gain_buf[idx] = gain_pit_fx; move16(); } - hAmrwb_IO->lt_voice_fac_fx = round_fx( L_Voice_fac_ave ); + hAmrwb_IO->lt_voice_fac_fx = round_fx( L_Voice_fac_ave ); // Q0 move16(); return; diff --git a/lib_dec/dec_gen_voic_fx.c b/lib_dec/dec_gen_voic_fx.c index f5fdb1dea..363c3a2d8 100644 --- a/lib_dec/dec_gen_voic_fx.c +++ b/lib_dec/dec_gen_voic_fx.c @@ -41,34 +41,41 @@ ivas_error decod_gen_voic_fx( Decoder_State *st_fx, /* i/o: decoder static memory */ const Word16 L_frame, /* i : length of the frame */ const Word16 sharpFlag_fx, /* i : formant sharpening flag */ - const Word16 *Aq_fx, /* i : LP filter coefficient */ - const Word16 Es_pred_fx, /* i : predicted scaled innov. energy */ + const Word16 *Aq_fx, /* i : LP filter coefficient Q12 */ + const Word16 Es_pred_fx, /* i : predicted scaled innov. energy Q8 */ const Word16 do_WI_fx, /* i : do interpolation after a FER */ - Word16 *pitch_buf_fx, /* o : floating pitch values for each subframe */ - Word16 *voice_factors_fx, /* o : voicing factors */ - Word16 *exc_fx, /* i/o: adapt. excitation exc */ - Word16 *exc2_fx, /* i/o: adapt. excitation/total exc */ - Word16 *bwe_exc_fx, /* o : excitation for SWB TBE */ + Word16 *pitch_buf_fx, /* o : floating pitch values for each subframe Q6 */ + Word16 *voice_factors_fx, /* o : voicing factors Q15 */ + Word16 *exc_fx, /* i/o: adapt. excitation exc Q_exc */ + Word16 *exc2_fx, /* i/o: adapt. excitation/total exc Q_exc */ + Word16 *bwe_exc_fx, /* o : excitation for SWB TBE Q_exc */ Word16 *unbits, /* number of unused bits */ - Word16 *gain_buf ) + Word16 *gain_buf /*Q14*/ +) { Word16 T0_fx, T0_frac_fx, T0_min_fx, T0_max_fx; /* integer pitch variables */ Word16 gain_pit_fx = 0; /* pitch gain Q14 */ - Word32 gain_code_fx = 0; /* gain/normalized gain of the algebraic excitation Q16 */ - Word32 norm_gain_code_fx = 0; /* normalized gain of the algebraic excitation Q16 */ - Word16 gain_inov_fx = 0; /* Innovation gain Q12 */ - Word32 gc_mem[NB_SUBFR - 1]; /* gain_code from previous subframes */ - Word16 gp_mem[NB_SUBFR - 1]; /* gain_pitch from previous subframes */ - Word16 voice_fac_fx; /* voicing factor Q15 */ - Word16 code_fx[L_SUBFR]; /* algebraic codevector Q12 */ + move16(); + Word32 gain_code_fx = 0; /* gain/normalized gain of the algebraic excitation Q16 */ + move32(); + Word32 norm_gain_code_fx = 0; /* normalized gain of the algebraic excitation Q16 */ + move32(); + Word16 gain_inov_fx = 0; /* Innovation gain Q12 */ + move16(); + Word32 gc_mem[NB_SUBFR - 1]; /* gain_code from previous subframes */ + Word16 gp_mem[NB_SUBFR - 1]; /* gain_pitch from previous subframes */ + Word16 voice_fac_fx; /* voicing factor Q15 */ + Word16 code_fx[L_SUBFR]; /* algebraic codevector Q12 */ const Word16 *p_Aq_fx; /* Pointer to frame LP coefficient Q12 */ Word16 *pt_pitch_fx; /* pointer to floating pitch Q6 */ Word16 i_subfr_fx, i; /* tmp variables */ Word16 error_fx = 0; - Word16 gain_preQ_fx = 0; /* Gain of prequantizer excitation */ + move16(); + Word16 gain_preQ_fx = 0; /* Gain of prequantizer excitation */ + move16(); Word16 code_preQ_fx[L_SUBFR]; /* Prequantizer excitation */ Word32 norm_gain_preQ_fx; Word16 pitch_limit_flag_fx; @@ -105,14 +112,8 @@ ivas_error decod_gen_voic_fx( MUSIC_POSTFILT_HANDLE hMusicPF; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif - move16(); - move16(); - move16(); - move16(); - move16(); - move16(); - move16(); hMusicPF = st_fx->hMusicPF; @@ -142,12 +143,10 @@ ivas_error decod_gen_voic_fx( * ACELP subframe loop *------------------------------------------------------------------*/ - p_Aq_fx = Aq_fx; - move16(); /* pointer to interpolated LPC parameters */ - pt_pitch_fx = pitch_buf_fx; - move16(); /* pointer to the pitch buffer */ + p_Aq_fx = Aq_fx; /* pointer to interpolated LPC parameters */ + pt_pitch_fx = pitch_buf_fx; /* pointer to the pitch buffer */ norm_gain_preQ_fx = 0; - move16(); + move32(); gain_preQ_fx = 0; move16(); set16_fx( code_preQ_fx, 0, L_SUBFR ); @@ -179,7 +178,7 @@ ivas_error decod_gen_voic_fx( *-----------------------------------------------------------------*/ test(); - IF( GE_32( st_fx->core_brate, MIN_BRATE_AVQ_EXC ) && NE_16( st_fx->coder_type, INACTIVE ) ) + IF( GE_32( st_fx->core_brate, MIN_BRATE_AVQ_EXC ) && ( st_fx->coder_type != INACTIVE ) ) { gain_code_fx = 0; move16(); @@ -209,14 +208,14 @@ ivas_error decod_gen_voic_fx( { gain_dec_mless_fx( st_fx, L_frame, st_fx->coder_type, i_subfr_fx, -1, code_fx, Es_pred_fx, &gain_pit_fx, &gain_code_fx, &gain_inov_fx, &norm_gain_code_fx ); } - st_fx->tilt_code_fx = est_tilt_fx( exc_fx + i_subfr_fx, gain_pit_fx, code_fx, gain_code_fx, &voice_fac_fx, st_fx->Q_exc ); + st_fx->tilt_code_fx = est_tilt_fx( exc_fx + i_subfr_fx, gain_pit_fx, code_fx, gain_code_fx, &voice_fac_fx, st_fx->Q_exc ); // Q15 move16(); /*-----------------------------------------------------------------* * Transform domain contribution decoding *-----------------------------------------------------------------*/ test(); - IF( GE_32( st_fx->core_brate, MAX_GSC_INACTIVE_BRATE ) && EQ_16( st_fx->coder_type, INACTIVE ) ) + IF( GE_32( st_fx->core_brate, MAX_GSC_INACTIVE_BRATE ) && ( st_fx->coder_type == INACTIVE ) ) { transf_cdbk_dec_fx( st_fx, harm_flag_acelp, i_subfr_fx, Es_pred_fx, gain_code_fx, &gain_preQ_fx, &norm_gain_preQ_fx, code_preQ_fx, unbits ); } @@ -266,20 +265,21 @@ ivas_error decod_gen_voic_fx( /* Compute exc2 */ #ifdef BASOP_NOGLOB - L_tmp = L_shl_sat( L_mult( gain_pit_fx, exc_fx[i + i_subfr_fx] ), 1 ); - exc2_fx[i + i_subfr_fx] = round_fx_sat( L_add_sat( L_tmp, Ltmp1 ) ); + L_tmp = L_shl_sat( L_mult( gain_pit_fx, exc_fx[i + i_subfr_fx] ), 1 ); // Q_exc+Q14+1+1 + exc2_fx[i + i_subfr_fx] = round_fx_sat( L_add_sat( L_tmp, Ltmp1 ) ); // Q_exc #else L_tmp = L_shl( L_mult( gain_pit_fx, exc_fx[i + i_subfr_fx] ), 1 ); exc2_fx[i + i_subfr_fx] = round_fx( L_add( L_tmp, Ltmp1 ) ); #endif - /* code in Q9, gain_pit in Q14 */ - L_tmp = L_mult( gain_code16, code_fx[i] ); + move16(); + /* gain_pit in Q14 */ + L_tmp = L_mult( gain_code16, code_fx[i] ); // Q_exc+Q9+1 #ifdef BASOP_NOGLOB - L_tmp = L_shl_sat( L_tmp, 5 ); - L_tmp = L_mac_sat( L_tmp, exc_fx[i + i_subfr_fx], gain_pit_fx ); - L_tmp = L_shl_sat( L_tmp, 1 ); /* saturation can occur here */ + L_tmp = L_shl_sat( L_tmp, 5 ); // Q_exc+Q9+1+5 + L_tmp = L_mac_sat( L_tmp, exc_fx[i + i_subfr_fx], gain_pit_fx ); // Q_exc+Q15 +1 + L_tmp = L_shl_sat( L_tmp, 1 ); /* saturation can occur here */ - exc_fx[i + i_subfr_fx] = round_fx_sat( L_add_sat( L_tmp, Ltmp1 ) ); + exc_fx[i + i_subfr_fx] = round_fx_sat( L_add_sat( L_tmp, Ltmp1 ) ); // Q_exc move16(); #else L_tmp = L_shl( L_tmp, 5 ); @@ -316,7 +316,7 @@ ivas_error decod_gen_voic_fx( *----------------------------------------------------------------*/ test(); - IF( GT_32( st_fx->core_brate, ACELP_32k ) || EQ_16( st_fx->coder_type, INACTIVE ) ) + IF( GT_32( st_fx->core_brate, ACELP_32k ) || ( st_fx->coder_type == INACTIVE ) ) { Copy( exc_fx + i_subfr_fx, exc2_fx + i_subfr_fx, L_SUBFR ); } @@ -327,9 +327,8 @@ ivas_error decod_gen_voic_fx( } p_Aq_fx += ( M + 1 ); - move16(); pt_pitch_fx++; - gain_buf[idx] = gain_pit_fx; + gain_buf[idx] = gain_pit_fx; // Q14 move16(); } @@ -371,9 +370,7 @@ ivas_error decod_gen_voic_fx( shft_curr = sub( st_fx->L_frame, rint_pitch ); /*Q0*/ p_exc = exc2_fx + shft_curr; - move16(); p_syn = syn_tmp_fx + shft_curr; - move16(); curr_res_nrg = L_deposit_l( 1 ); curr_spch_nrg = L_deposit_l( 1 ); @@ -394,22 +391,22 @@ ivas_error decod_gen_voic_fx( IF( prev_res_nrg > 0 ) { expa = norm_l( prev_res_nrg ); - fraca = extract_h( L_shl( prev_res_nrg, expa ) ); - expa = sub( 30, expa + ( 2 * st_fx->prev_Q_exc_fr ) ); + fraca = extract_h( L_shl( prev_res_nrg, expa ) ); /* 2*st_fx->prev_Q_exc_fr -16+expa +1*/ + expa = sub( 30, add( expa, ( shl( st_fx->prev_Q_exc_fr, 1 ) ) ) ); expb = norm_l( curr_res_nrg ); #ifdef BASOP_NOGLOB - fracb = round_fx_sat( L_shl_sat( curr_res_nrg, expb ) ); + fracb = round_fx_sat( L_shl_sat( curr_res_nrg, expb ) ); /* 2*st_fx->Q_exc +expb+1 -16*/ #else fracb = round_fx( L_shl( curr_res_nrg, expb ) ); #endif expb = sub( 30, add( expb, shl( st_fx->Q_exc, 1 ) ) ); scale = shr( sub( fraca, fracb ), 15 ); - fracb = shl( fracb, scale ); + fracb = shl( fracb, scale ); // Q(15-expb)+scale expb = sub( expb, scale ); - enratio = div_s( fracb, fraca ); + enratio = div_s( fracb, fraca ); // Q(15-(expb-expa)) exp1 = sub( expb, expa ); Qenratio = sub( 15, exp1 ); } @@ -425,22 +422,22 @@ ivas_error decod_gen_voic_fx( IF( prev_spch_nrg > 0 ) { expa = norm_l( prev_spch_nrg ); - fraca = extract_h( L_shl( prev_spch_nrg, expa ) ); + fraca = extract_h( L_shl( prev_spch_nrg, expa ) ); /* 2*st_fx->prev_Q_syn_fr +expa+1-16*/ expa = sub( 30, add( expa, shl( st_fx->prev_Q_syn_fr, 1 ) ) ); expb = norm_l( curr_spch_nrg ); #ifdef BASOP_NOGLOB - fracb = round_fx_sat( L_shl_sat( curr_spch_nrg, expb ) ); + fracb = round_fx_sat( L_shl_sat( curr_spch_nrg, expb ) ); /* 2*st_fx->Q_syn +expb-16 */ #else fracb = round_fx( L_shl( curr_spch_nrg, expb ) ); #endif expb = sub( 30, add( expb, shl( st_fx->Q_syn, 1 ) ) ); scale = shr( sub( fraca, fracb ), 15 ); - fracb = shl( fracb, scale ); + fracb = shl( fracb, scale ); // Q(15-expb) +scale expb = sub( expb, scale ); - sp_enratio = div_s( fracb, fraca ); + sp_enratio = div_s( fracb, fraca ); // Q(15-(expb-expa)) exp1 = sub( expb, expa ); Qsp_enratio = sub( 15, exp1 ); } @@ -461,7 +458,7 @@ ivas_error decod_gen_voic_fx( LT_16( shl_ro( enratio, sub( 10, Qenratio ), &Overflow ), 15360 ) && /*compare with 15.0 in Q10*/ GT_16( shl_ro( sp_enratio, sub( 15, Qsp_enratio ), &Overflow ), 4915 ) && /*compare with 0.15 in Q15*/ LT_16( st_fx->bfi_pitch_fx, 9600 ) && /*Q6*/ - LT_16( pitch_buf_fx[sub( NB_SUBFR16k, 1 )], 9600 ) ) /*Q6*/ + LT_16( pitch_buf_fx[NB_SUBFR16k - 1], 9600 ) ) /*Q6*/ #else IF( GT_16( shl_r( enratio, 15 - Qenratio ), 8192 ) && /*compare with 0.25 in Q15*/ LT_16( shl_r( enratio, 10 - Qenratio ), 15360 ) && /*compare with 15.0 in Q10*/ @@ -470,12 +467,12 @@ ivas_error decod_gen_voic_fx( pitch_buf_fx[sub( NB_SUBFR16k, 1 )] < 9600 ) /*Q6*/ #endif { - IF( ( error = DTFS_new_fx( &PREVP ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = DTFS_new_fx( &PREVP ) ), IVAS_ERR_OK ) ) { return error; } - IF( ( error = DTFS_new_fx( &CURRP ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = DTFS_new_fx( &CURRP ) ), IVAS_ERR_OK ) ) { return error; } @@ -492,14 +489,14 @@ ivas_error decod_gen_voic_fx( ph_offset_fx = 0; move16(); - if ( ( error = WIsyn_fx( *PREVP, CURRP, dummy2, &( ph_offset_fx ), out_fx, (Word16) st_fx->L_frame, 1, S_fx, C_fx, pf_temp1, pf_temp2, pf_temp, pf_n2 ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = WIsyn_fx( *PREVP, CURRP, dummy2, &( ph_offset_fx ), out_fx, (Word16) st_fx->L_frame, 1, S_fx, C_fx, pf_temp1, pf_temp2, pf_temp, pf_n2 ) ), IVAS_ERR_OK ) ) { return error; } - Copy_Scale_sig( out_fx, exc2_fx, st_fx->L_frame, st_fx->Q_exc ); - Copy_Scale_sig( out_fx, exc_fx, st_fx->L_frame, st_fx->Q_exc ); + Copy_Scale_sig( out_fx, exc2_fx, st_fx->L_frame, st_fx->Q_exc ); // Q_exc + Copy_Scale_sig( out_fx, exc_fx, st_fx->L_frame, st_fx->Q_exc ); // Q_exc /* update bwe_exc for SWB-TBE */ FOR( i_subfr_fx = 0; i_subfr_fx < L_frame; i_subfr_fx += L_SUBFR ) @@ -551,18 +548,18 @@ ivas_error decod_gen_voic_ivas_fx( Decoder_State *st_fx, /* i/o: decoder static memory */ const Word16 L_frame, /* i : length of the frame */ const Word16 sharpFlag_fx, /* i : formant sharpening flag */ - const Word16 *Aq_fx, /* i : LP filter coefficient */ - const Word16 Es_pred_fx, /* i : predicted scaled innov. energy */ + const Word16 *Aq_fx, /* i : LP filter coefficient Q12*/ + const Word16 Es_pred_fx, /* i : predicted scaled innov. energy Q8 */ const Word16 do_WI_fx, /* i : do interpolation after a FER */ - Word16 *pitch_buf_fx, /* o : Word16 pitch values for each subframe */ - Word16 *voice_factors_fx, /* o : voicing factors */ - Word16 *exc_fx, /* i/o: adapt. excitation exc */ - Word16 *exc2_fx, /* i/o: adapt. excitation/total exc */ - Word16 *bwe_exc_fx, /* o : excitation for SWB TBE */ + Word16 *pitch_buf_fx, /* o : Word16 pitch values for each subframe Q6*/ + Word16 *voice_factors_fx, /* o : voicing factors Q15 */ + Word16 *exc_fx, /* i/o: adapt. excitation exc Q_exc */ + Word16 *exc2_fx, /* i/o: adapt. excitation/total exc Q_exc */ + Word16 *bwe_exc_fx, /* o : excitation for SWB TBE Q_exc */ Word16 *unbits, /* number of unused bits */ Word16 *gain_buf, const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag */ - const Word16 tdm_Pri_pitch_buf[] /* i : primary channel pitch buffer */ + const Word16 tdm_Pri_pitch_buf[] /* i : primary channel pitch buffer Q6 */ ) { @@ -624,11 +621,11 @@ ivas_error decod_gen_voic_ivas_fx( gain_preQ_fx = 0; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif move16(); - move16(); - move16(); - move16(); + move32(); + move32(); move16(); move16(); move16(); @@ -661,12 +658,10 @@ ivas_error decod_gen_voic_ivas_fx( * ACELP subframe loop *------------------------------------------------------------------*/ - p_Aq_fx = Aq_fx; - move16(); /* pointer to interpolated LPC parameters */ - pt_pitch_fx = pitch_buf_fx; - move16(); /* pointer to the pitch buffer */ + p_Aq_fx = Aq_fx; /* pointer to interpolated LPC parameters */ + pt_pitch_fx = pitch_buf_fx; /* pointer to the pitch buffer */ norm_gain_preQ_fx = 0; - move16(); + move32(); gain_preQ_fx = 0; move16(); set16_fx( code_preQ_fx, 0, L_SUBFR ); @@ -701,7 +696,7 @@ ivas_error decod_gen_voic_ivas_fx( *-----------------------------------------------------------------*/ test(); - IF( GE_32( st_fx->core_brate, MIN_BRATE_AVQ_EXC ) && NE_16( st_fx->coder_type, INACTIVE ) ) + IF( GE_32( st_fx->core_brate, MIN_BRATE_AVQ_EXC ) && ( st_fx->coder_type != INACTIVE ) ) { gain_code_fx = 0; move16(); @@ -731,14 +726,14 @@ ivas_error decod_gen_voic_ivas_fx( { gain_dec_mless_fx( st_fx, L_frame, st_fx->coder_type, i_subfr_fx, -1, code_fx, Es_pred_fx, &gain_pit_fx, &gain_code_fx, &gain_inov_fx, &norm_gain_code_fx ); } - st_fx->tilt_code_fx = est_tilt_ivas_fx( exc_fx + i_subfr_fx, gain_pit_fx, code_fx, gain_code_fx, &voice_fac_fx, st_fx->Q_exc, L_SUBFR, 0 ); + st_fx->tilt_code_fx = est_tilt_ivas_fx( exc_fx + i_subfr_fx, gain_pit_fx, code_fx, gain_code_fx, &voice_fac_fx, st_fx->Q_exc, L_SUBFR, 0 ); // Q15 move16(); /*-----------------------------------------------------------------* * Transform domain contribution decoding *-----------------------------------------------------------------*/ test(); - IF( GE_32( st_fx->total_brate, MAX_GSC_INACTIVE_BRATE ) && EQ_16( st_fx->coder_type, INACTIVE ) ) + IF( GE_32( st_fx->total_brate, MAX_GSC_INACTIVE_BRATE ) && ( st_fx->coder_type == INACTIVE ) ) { transf_cdbk_dec_fx( st_fx, harm_flag_acelp, i_subfr_fx, Es_pred_fx, gain_code_fx, &gain_preQ_fx, &norm_gain_preQ_fx, code_preQ_fx, unbits ); } @@ -752,15 +747,31 @@ ivas_error decod_gen_voic_ivas_fx( IF( EQ_16( L_frame, L_FRAME ) ) /* Rescaling for 12.8k core */ { - Rescale_exc( hMusicPF->dct_post_old_exc_fx, &exc_fx[i_subfr_fx], ( bwe_exc_fx != NULL ) ? &bwe_exc_fx[i_subfr_fx * HIBND_ACB_L_FAC] : NULL, hGSCDec->last_exc_dct_in_fx, - L_SUBFR, L_SUBFR * HIBND_ACB_L_FAC, gain_code_fx, &( st_fx->Q_exc ), st_fx->Q_subfr, exc2_fx, i_subfr_fx, st_fx->coder_type ); + IF( ( bwe_exc_fx != NULL ) ) + { + Rescale_exc( hMusicPF->dct_post_old_exc_fx, &exc_fx[i_subfr_fx], &bwe_exc_fx[i_subfr_fx * HIBND_ACB_L_FAC], hGSCDec->last_exc_dct_in_fx, + L_SUBFR, L_SUBFR * HIBND_ACB_L_FAC, gain_code_fx, &( st_fx->Q_exc ), st_fx->Q_subfr, exc2_fx, i_subfr_fx, st_fx->coder_type ); + } + ELSE + { + Rescale_exc( hMusicPF->dct_post_old_exc_fx, &exc_fx[i_subfr_fx], NULL, hGSCDec->last_exc_dct_in_fx, + L_SUBFR, L_SUBFR * HIBND_ACB_L_FAC, gain_code_fx, &( st_fx->Q_exc ), st_fx->Q_subfr, exc2_fx, i_subfr_fx, st_fx->coder_type ); + } } ELSE /* Rescaling for 16k core */ { L_tmp_GC = L_max( gain_code_fx, L_shl( gain_preQ_fx, 16 ) ); /* Chose the maximum of gain_code or the prequantizer excitation x4 to keep some room*/ - Rescale_exc( hMusicPF->dct_post_old_exc_fx, &exc_fx[i_subfr_fx], ( bwe_exc_fx != NULL ) ? &bwe_exc_fx[i_subfr_fx * 2] : NULL, hGSCDec->last_exc_dct_in_fx, - L_SUBFR, L_SUBFR * 2, L_tmp_GC, &( st_fx->Q_exc ), st_fx->Q_subfr, exc2_fx, i_subfr_fx, st_fx->coder_type ); + IF( bwe_exc_fx != NULL ) + { + Rescale_exc( hMusicPF->dct_post_old_exc_fx, &exc_fx[i_subfr_fx], &bwe_exc_fx[i_subfr_fx * 2], hGSCDec->last_exc_dct_in_fx, + L_SUBFR, L_SUBFR * 2, L_tmp_GC, &( st_fx->Q_exc ), st_fx->Q_subfr, exc2_fx, i_subfr_fx, st_fx->coder_type ); + } + ELSE + { + Rescale_exc( hMusicPF->dct_post_old_exc_fx, &exc_fx[i_subfr_fx], NULL, hGSCDec->last_exc_dct_in_fx, + L_SUBFR, L_SUBFR * 2, L_tmp_GC, &( st_fx->Q_exc ), st_fx->Q_subfr, exc2_fx, i_subfr_fx, st_fx->coder_type ); + } } gain_code16 = round_fx( L_shl( gain_code_fx, st_fx->Q_exc ) ); /*Q_exc*/ @@ -793,21 +804,20 @@ ivas_error decod_gen_voic_ivas_fx( /* Compute exc2 */ #ifdef BASOP_NOGLOB L_tmp = L_shl_sat( L_mult( gain_pit_fx, exc_fx[i + i_subfr_fx] ), 1 ); - exc2_fx[i + i_subfr_fx] = round_fx_sat( L_add_sat( L_tmp, Ltmp1 ) ); - move16(); + exc2_fx[i + i_subfr_fx] = round_fx_sat( L_add_sat( L_tmp, Ltmp1 ) ); // Q_exc #else L_tmp = L_shl( L_mult( gain_pit_fx, exc_fx[i + i_subfr_fx] ), 1 ); exc2_fx[i + i_subfr_fx] = round_fx( L_add( L_tmp, Ltmp1 ) ); #endif - - /* code in Q9, gain_pit in Q14 */ - L_tmp = L_mult( gain_code16, code_fx[i] ); + move16(); + /* gain_pit in Q14 */ + L_tmp = L_mult( gain_code16, code_fx[i] ); // Q_exc+Q9+1 #ifdef BASOP_NOGLOB - L_tmp = L_shl_sat( L_tmp, 5 ); - L_tmp = L_mac_sat( L_tmp, exc_fx[i + i_subfr_fx], gain_pit_fx ); - L_tmp = L_shl_sat( L_tmp, 1 ); /* saturation can occur here */ + L_tmp = L_shl_sat( L_tmp, 5 ); // Q_exc+Q9+1+5 + L_tmp = L_mac_sat( L_tmp, exc_fx[i + i_subfr_fx], gain_pit_fx ); // Q_exc+16 + L_tmp = L_shl_sat( L_tmp, 1 ); /* saturation can occur here */ - exc_fx[i + i_subfr_fx] = round_fx_sat( L_add_sat( L_tmp, Ltmp1 ) ); + exc_fx[i + i_subfr_fx] = round_fx_sat( L_add_sat( L_tmp, Ltmp1 ) ); // Q_exc move16(); #else L_tmp = L_shl( L_tmp, 5 ); @@ -863,7 +873,7 @@ ivas_error decod_gen_voic_ivas_fx( p_Aq_fx += ( M + 1 ); move16(); pt_pitch_fx++; - gain_buf[idx] = gain_pit_fx; + gain_buf[idx] = gain_pit_fx; // Q14 move16(); } @@ -878,11 +888,11 @@ ivas_error decod_gen_voic_ivas_fx( p_exc = st_fx->hWIDec->old_exc2_fx + shft_prev; p_syn = st_fx->hWIDec->old_syn2_fx + shft_prev; - move16(); - move16(); - prev_res_nrg = L_deposit_l( 1 ); - prev_spch_nrg = L_deposit_l( 1 ); + prev_res_nrg = 1; + move32(); + prev_spch_nrg = 1; + move32(); FOR( i = 0; i < rint_bfi_pitch; i++ ) { #ifdef BASOP_NOGLOB @@ -905,12 +915,12 @@ ivas_error decod_gen_voic_ivas_fx( shft_curr = sub( st_fx->L_frame, rint_pitch ); /*Q0*/ p_exc = exc2_fx + shft_curr; - move16(); p_syn = syn_tmp_fx + shft_curr; - move16(); - curr_res_nrg = L_deposit_l( 1 ); - curr_spch_nrg = L_deposit_l( 1 ); + curr_res_nrg = 1; + move32(); + curr_spch_nrg = 1; + move32(); FOR( i = 0; i < rint_pitch; i++ ) { curr_res_nrg = L_mac0( curr_res_nrg, *p_exc, *p_exc ); /* 2*st_fx->Q_exc */ @@ -923,18 +933,18 @@ ivas_error decod_gen_voic_ivas_fx( IF( prev_res_nrg > 0 ) { expa = norm_l( prev_res_nrg ); - fraca = extract_h( L_shl( prev_res_nrg, expa ) ); + fraca = extract_h( L_shl( prev_res_nrg, expa ) ); /* 2*st_fx->prev_Q_exc_fr +expa -16*/ expa = sub( 30, add( expa, shl( st_fx->prev_Q_exc_fr, 1 ) ) ); expb = norm_l( curr_res_nrg ); - fracb = round_fx( L_shl( curr_res_nrg, expb ) ); + fracb = round_fx( L_shl( curr_res_nrg, expb ) ); /* 2*st_fx->prev_Q_exc_fr +expb -16*/ expb = sub( 30, add( expb, shl( st_fx->Q_exc, 1 ) ) ); scale = shr( sub( fraca, fracb ), 15 ); - fracb = shl( fracb, scale ); + fracb = shl( fracb, scale ); // Q(15-expb)+scale expb = sub( expb, scale ); - enratio = div_s( fracb, fraca ); + enratio = div_s( fracb, fraca ); // Q(15-(expb-expa) exp1 = sub( expb, expa ); Qenratio = sub( 15, exp1 ); } @@ -950,18 +960,18 @@ ivas_error decod_gen_voic_ivas_fx( IF( prev_spch_nrg > 0 ) { expa = norm_l( prev_spch_nrg ); - fraca = extract_h( L_shl( prev_spch_nrg, expa ) ); + fraca = extract_h( L_shl( prev_spch_nrg, expa ) ); /* 2*st_fx->prev_Q_syn_fr -16 +expa */ expa = sub( 30, add( expa, shl( st_fx->prev_Q_syn_fr, 1 ) ) ); expb = norm_l( curr_spch_nrg ); - fracb = round_fx( L_shl( curr_spch_nrg, expb ) ); + fracb = round_fx( L_shl( curr_spch_nrg, expb ) ); /* 2*st_fx->Q_syn +expb -16*/ expb = sub( 30, add( expb, shl( st_fx->Q_syn, 1 ) ) ); scale = shr( sub( fraca, fracb ), 15 ); - fracb = shl( fracb, scale ); + fracb = shl( fracb, scale ); // Q(15-expb)+scale expb = sub( expb, scale ); - sp_enratio = div_s( fracb, fraca ); + sp_enratio = div_s( fracb, fraca ); // Q(15-(expb-expa)) exp1 = sub( expb, expa ); Qsp_enratio = sub( 15, exp1 ); } @@ -982,7 +992,7 @@ ivas_error decod_gen_voic_ivas_fx( LT_16( shl_ro( enratio, sub( 10, Qenratio ), &Overflow ), 15360 ) && /*compare with 15.0 in Q10*/ GT_16( shl_ro( sp_enratio, sub( 15, Qsp_enratio ), &Overflow ), 4915 ) && /*compare with 0.15 in Q15*/ LT_16( st_fx->bfi_pitch_fx, 9600 ) && /*Q6*/ - LT_16( pitch_buf_fx[sub( NB_SUBFR16k, 1 )], 9600 ) ) /*Q6*/ + LT_16( pitch_buf_fx[( NB_SUBFR16k - 1 )], 9600 ) ) /*Q6*/ #else IF( GT_16( shl_r( enratio, 15 - Qenratio ), 8192 ) && /*compare with 0.25 in Q15*/ LT_16( shl_r( enratio, 10 - Qenratio ), 15360 ) && /*compare with 15.0 in Q10*/ @@ -991,12 +1001,12 @@ ivas_error decod_gen_voic_ivas_fx( pitch_buf_fx[sub( NB_SUBFR16k, 1 )] < 9600 ) /*Q6*/ #endif { - IF( ( error = DTFS_new_fx( &PREVP ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = DTFS_new_fx( &PREVP ) ), IVAS_ERR_OK ) ) { return error; } - IF( ( error = DTFS_new_fx( &CURRP ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = DTFS_new_fx( &CURRP ) ), IVAS_ERR_OK ) ) { return error; } @@ -1013,14 +1023,14 @@ ivas_error decod_gen_voic_ivas_fx( ph_offset_fx = 0; move16(); - IF( ( error = WIsyn_fx( *PREVP, CURRP, dummy2, &( ph_offset_fx ), out_fx, (Word16) st_fx->L_frame, 1, S_fx, C_fx, pf_temp1, pf_temp2, pf_temp, pf_n2 ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = WIsyn_fx( *PREVP, CURRP, dummy2, &( ph_offset_fx ), out_fx, (Word16) st_fx->L_frame, 1, S_fx, C_fx, pf_temp1, pf_temp2, pf_temp, pf_n2 ) ), IVAS_ERR_OK ) ) { return error; } - Copy_Scale_sig( out_fx, exc2_fx, st_fx->L_frame, st_fx->Q_exc ); - Copy_Scale_sig( out_fx, exc_fx, st_fx->L_frame, st_fx->Q_exc ); + Copy_Scale_sig( out_fx, exc2_fx, st_fx->L_frame, st_fx->Q_exc ); // Q_exc + Copy_Scale_sig( out_fx, exc_fx, st_fx->L_frame, st_fx->Q_exc ); // Q_exc /* update bwe_exc for SWB-TBE */ FOR( i_subfr_fx = 0; i_subfr_fx < L_frame; i_subfr_fx += L_SUBFR ) diff --git a/lib_dec/dec_higher_acelp_fx.c b/lib_dec/dec_higher_acelp_fx.c index 51a7ab962..febbaa477 100644 --- a/lib_dec/dec_higher_acelp_fx.c +++ b/lib_dec/dec_higher_acelp_fx.c @@ -35,6 +35,7 @@ void transf_cdbk_dec_fx( Word16 qdct; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif #ifdef IVAS_CODE Word16 avq_bit_sFlag; @@ -45,7 +46,7 @@ void transf_cdbk_dec_fx( avq_bit_sFlag = 0; move16(); - if ( GT_16( st_fx->element_mode, EVS_MONO ) ) + if ( ( st_fx->element_mode > EVS_MONO ) ) { move16(); avq_bit_sFlag = 1; @@ -55,7 +56,7 @@ void transf_cdbk_dec_fx( * Set bit-allocation *--------------------------------------------------------------*/ - nBits = st_fx->acelp_cfg.AVQ_cdk_bits[shr( i_subfr, 6 )]; + nBits = st_fx->acelp_cfg.AVQ_cdk_bits[( i_subfr >> 6 )]; move16(); /* increase # of AVQ allocated bits by unused bits from the previous subframe */ @@ -67,19 +68,19 @@ void transf_cdbk_dec_fx( index = (Word16) get_next_indice_fx( st_fx, G_AVQ_BITS ); - IF( EQ_16( st_fx->coder_type, INACTIVE ) ) + IF( ( st_fx->coder_type == INACTIVE ) ) { IF( GT_32( st_fx->core_brate, 56000 ) ) { - gain16 = usdequant_fx( index, G_AVQ_MIN_INACT_64k_Q12, G_AVQ_DELTA_INACT_64k_Q12 >> 1 ); + gain16 = usdequant_fx( index, G_AVQ_MIN_INACT_64k_Q12, G_AVQ_DELTA_INACT_64k_Q12 >> 1 ); // Q12 } ELSE IF( GT_32( st_fx->core_brate, 42000 ) ) { - gain16 = usdequant_fx( index, G_AVQ_MIN_INACT_48k_Q12, G_AVQ_DELTA_INACT_48k_Q12 >> 1 ); + gain16 = usdequant_fx( index, G_AVQ_MIN_INACT_48k_Q12, G_AVQ_DELTA_INACT_48k_Q12 >> 1 ); // Q12 } ELSE { - gain16 = usdequant_fx( index, G_AVQ_MIN_INACT_Q12, G_AVQ_DELTA_INACT_Q12 >> 1 ); + gain16 = usdequant_fx( index, G_AVQ_MIN_INACT_Q12, G_AVQ_DELTA_INACT_Q12 >> 1 ); // Q12 } L_tmp = Mult_32_16( gain_code, gain16 ); /* Q16 * Q12 - 15 -> Q13*/ @@ -97,17 +98,17 @@ void transf_cdbk_dec_fx( test(); IF( GT_32( st_fx->core_brate, ACELP_24k40 ) && LE_32( st_fx->core_brate, 42000 ) ) { - gain16 = gain_dequant_fx( index, G_AVQ_MIN_32kbps_Q15, G_AVQ_MAX_Q0, G_AVQ_BITS, &exp16 ); + gain16 = gain_dequant_fx( index, G_AVQ_MIN_32kbps_Q15, G_AVQ_MAX_Q0, G_AVQ_BITS, &exp16 ); // Q0 } ELSE { - gain16 = gain_dequant_fx( index, G_AVQ_MIN_Q15, G_AVQ_MAX_Q0, G_AVQ_BITS, &exp16 ); + gain16 = gain_dequant_fx( index, G_AVQ_MIN_Q15, G_AVQ_MAX_Q0, G_AVQ_BITS, &exp16 ); // Q0 } IF( Es_pred < 0 ) { - tmp16 = shr( negate( Es_pred ), 2 ); - L_tmp = L_mult( gain16, tmp16 ); /* Q0*Q8 -> Q9*/ + tmp16 = shr( negate( Es_pred ), 2 ); // Q8 + L_tmp = L_mult( gain16, tmp16 ); /* Q0*Q8 -> Q9*/ } ELSE { @@ -124,7 +125,7 @@ void transf_cdbk_dec_fx( test(); test(); test(); - IF( avq_bit_sFlag && GT_16( nBits, 85 ) && !harm_flag_acelp && ( EQ_16( st_fx->coder_type, GENERIC ) || EQ_16( st_fx->coder_type, TRANSITION ) || EQ_16( st_fx->coder_type, INACTIVE ) ) ) + IF( avq_bit_sFlag && GT_16( nBits, 85 ) && !harm_flag_acelp && ( EQ_16( st_fx->coder_type, GENERIC ) || EQ_16( st_fx->coder_type, TRANSITION ) || ( st_fx->coder_type == INACTIVE ) ) ) { trgtSvPos = 2; avq_bit_sFlag = 2; @@ -139,7 +140,7 @@ void transf_cdbk_dec_fx( #ifdef IVAS_CODE_AVQ AVQ_demuxdec_fx( st_fx, code_preQ, &nBits, 8, nq, avq_bit_sFlag, trgtSvPos ); Word16 q_Code_preQ; - IF( EQ_16( st_fx->element_mode, EVS_MONO ) ) + IF( ( st_fx->element_mode == EVS_MONO ) ) { q_Code_preQ = Q_AVQ_OUT_DEC; move16(); @@ -172,7 +173,7 @@ void transf_cdbk_dec_fx( test(); test(); - IF( EQ_16( st_fx->coder_type, INACTIVE ) || GT_32( st_fx->core_brate, MAX_BRATE_AVQ_EXC_TD ) || harm_flag_acelp ) + IF( ( st_fx->coder_type == INACTIVE ) || GT_32( st_fx->core_brate, MAX_BRATE_AVQ_EXC_TD ) || harm_flag_acelp ) { qdct = 0; move16(); @@ -203,7 +204,7 @@ void transf_cdbk_dec_fx( test(); test(); test(); - IF( st_fx->element_mode > EVS_MONO && NE_16( st_fx->coder_type, INACTIVE ) && GE_32( st_fx->core_brate, MIN_BRATE_AVQ_EXC ) && LE_32( st_fx->core_brate, MAX_BRATE_AVQ_EXC_TD ) && !harm_flag_acelp && code_preQ[0] != 0 ) + IF( st_fx->element_mode > EVS_MONO && ( st_fx->coder_type != INACTIVE ) && GE_32( st_fx->core_brate, MIN_BRATE_AVQ_EXC ) && LE_32( st_fx->core_brate, MAX_BRATE_AVQ_EXC_TD ) && !harm_flag_acelp && code_preQ[0] != 0 ) { // PMT("Fixed point taking accound of the scaling needs to be done here ") IF( GT_16( abs_s( st_fx->last_code_preq ), shl_sat( abs_s( code_preQ[0] ), 4 ) ) ) @@ -218,7 +219,7 @@ void transf_cdbk_dec_fx( } } - st_fx->last_code_preq = extract_h( code_preQ[L_SUBFR - 1] ); + st_fx->last_code_preq = extract_h( code_preQ[L_SUBFR - 1] ); // q_Code_preQ-16 move16(); #endif PREEMPH_FX( code_preQ, FAC_PRE_AVQ_FX, L_SUBFR, &st_fx->mem_preemp_preQ_fx ); diff --git a/lib_dec/dec_tcx.c b/lib_dec/dec_tcx.c index 79efe8356..f32a383a5 100644 --- a/lib_dec/dec_tcx.c +++ b/lib_dec/dec_tcx.c @@ -1,3 +1,4 @@ + /****************************************************************************************************** (C) 2022-2024 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, @@ -1559,7 +1560,7 @@ void decoder_tcx_tns_fx( const Word16 L_spec, const Word16 L_frame, const Word16 L_frameTCX, - Word32 x_fx[N_MAX], + Word32 x_fx[N_MAX], // Qx const Word16 fUseTns, /* i : flag that is set if TNS data is present */ STnsData *tnsData, const Word16 bfi, /* i : Bad frame indicator */ @@ -1947,9 +1948,10 @@ void decoder_tcx_imdct_fx( TCX_DEC_HANDLE hTcxDec = st->hTcxDec; TCX_CONFIG_HANDLE hTcxCfg = st->hTcxCfg; Word16 predictionGain_fx; - Word16 A_itf_fx[ITF_MAX_FILTER_ORDER + 1]; + Word16 A_itf_fx[ITF_MAX_FILTER_ORDER + 1]; // q_a_itf Word16 q_a_itf = 15; - Word16 x_e = 31 - q_x; + Word16 x_e = sub(31, q_x); + move16(); /*-----------------------------------------------------------------* * Initializations @@ -1963,18 +1965,23 @@ void decoder_tcx_imdct_fx( index = hTcxCfg->tcx_last_overlap_mode; /* backup last TCX overlap mode */ move16(); - IF( EQ_16( L_frame, shr( st->L_frame, 1 ) ) && NE_16( st->tcxonly, 0 ) && NE_16( frame_cnt, 0 ) && EQ_16( bfi, 0 ) && NE_16( st->last_core, ACELP_CORE ) ) + test(); + test(); + test(); + test(); + IF( EQ_16( L_frame, shr( st->L_frame, 1 ) ) && ( st->tcxonly != 0 ) && ( frame_cnt != 0 ) && ( bfi == 0 ) && ( st->last_core != ACELP_CORE ) ) { /* fix sub-window overlap */ hTcxCfg->tcx_last_overlap_mode = hTcxCfg->tcx_curr_overlap_mode; move16(); } - IF( NE_16( st->igf, 0 ) ) + IF( st->igf != 0 ) { proc = st->hIGFDec->flatteningTrigger; move16(); + test(); IF( proc && fUseTns != 0 ) { proc = 0; @@ -1998,18 +2005,32 @@ void decoder_tcx_imdct_fx( move16(); /* interleave again for ITF */ + test(); IF( EQ_16( L_frame, shr( st->L_frame, 1 ) ) && st->tcxonly ) { - IF( ( hTcxCfg->fIsTNSAllowed && NE_16( fUseTns, 0 ) && NE_16( bfi, 1 ) ) || GT_16( L_spec, L_frameTCX ) ) + test(); + test(); + test(); + IF( ( hTcxCfg->fIsTNSAllowed && ( fUseTns != 0 ) && NE_16( bfi, 1 ) ) || GT_16( L_spec, L_frameTCX ) ) { L = L_spec; move16(); } - IF( ( EQ_16( bfi, 0 ) && ( NE_16( hTcxCfg->tcx_last_overlap_mode, FULL_OVERLAP ) || - ( EQ_16( hTcxCfg->tcx_curr_overlap_mode, FULL_OVERLAP ) && EQ_16( frame_cnt, 0 ) && EQ_16( index, 0 ) ) ) ) || - ( NE_16( bfi, 0 ) && ( NE_16( hTcxCfg->tcx_last_overlap_mode, FULL_OVERLAP ) && - NE_16( hTcxCfg->tcx_curr_overlap_mode, FULL_OVERLAP ) ) ) ) + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + IF( ( ( bfi == 0 ) && ( ( hTcxCfg->tcx_last_overlap_mode != FULL_OVERLAP ) || + ( ( hTcxCfg->tcx_curr_overlap_mode == FULL_OVERLAP ) && ( frame_cnt == 0 ) && ( index == 0 ) ) ) ) || + ( ( bfi != 0 ) && ( ( hTcxCfg->tcx_last_overlap_mode != FULL_OVERLAP ) && + ( hTcxCfg->tcx_curr_overlap_mode != FULL_OVERLAP ) ) ) ) { isTCX5 = 1; move16(); @@ -2022,7 +2043,7 @@ void decoder_tcx_imdct_fx( { IF( EQ_16( st->hIGFDec->flag_sparse[j - IGF_START_MN], 2 ) ) { - x_itf_fx[j - IGF_START_MN] = x_fx[j]; + x_itf_fx[j - IGF_START_MN] = x_fx[j]; // q_x move32(); x_fx[j] = st->hIGFDec->virtualSpec_fx[j - IGF_START_MN]; move32(); @@ -2035,9 +2056,9 @@ void decoder_tcx_imdct_fx( FOR( j = startLine; j < endLine; j++ ) { - IF( st->hIGFDec->flag_sparse[j - IGF_START_MN] == 2 ) + IF( EQ_16( st->hIGFDec->flag_sparse[j - IGF_START_MN], 2 ) ) { - x_fx[j] = x_itf_fx[j - IGF_START_MN]; + x_fx[j] = x_itf_fx[j - IGF_START_MN]; // q_x move32(); } } @@ -2059,25 +2080,26 @@ void decoder_tcx_imdct_fx( IF( EQ_16( st->element_mode, IVAS_CPE_MDCT ) ) { set32_fx( x_tmp_fx, 0, L_FRAME_PLUS ); - Copy32( x_fx, x_tmp_fx, s_min( L_FRAME48k, s_max( L_spec, s_max( L_frame, L_frameTCX ) ) ) ); - Copy32( x_fx, xn_bufFB_fx, s_min( L_FRAME48k, s_max( L_spec, s_max( L_frame, L_frameTCX ) ) ) ); + Copy32( x_fx, x_tmp_fx, s_min( L_FRAME48k, s_max( L_spec, s_max( L_frame, L_frameTCX ) ) ) ); // q_x + Copy32( x_fx, xn_bufFB_fx, s_min( L_FRAME48k, s_max( L_spec, s_max( L_frame, L_frameTCX ) ) ) ); // q_x } - ELSE IF( EQ_16( st->element_mode, EVS_MONO ) ) + ELSE IF( ( st->element_mode == EVS_MONO ) ) { - Copy32( x_fx, xn_bufFB_fx, s_max( L_spec, s_max( L_frame, L_frameTCX ) ) ); + Copy32( x_fx, xn_bufFB_fx, s_max( L_spec, s_max( L_frame, L_frameTCX ) ) ); // q_x } ELSE { - Copy32( x_fx, x_tmp_fx, s_max( L_spec, s_max( L_frame, L_frameTCX ) ) ); - Copy32( x_fx, xn_bufFB_fx, s_max( L_spec, s_max( L_frame, L_frameTCX ) ) ); + Copy32( x_fx, x_tmp_fx, s_max( L_spec, s_max( L_frame, L_frameTCX ) ) ); // q_x + Copy32( x_fx, xn_bufFB_fx, s_max( L_spec, s_max( L_frame, L_frameTCX ) ) ); // q_x } - IF( NE_16( st->igf, 0 ) ) + IF( ( st->igf != 0 ) ) { set32_fx( xn_bufFB_fx + st->hIGFDec->infoIGFStartLine, 0, L_frameTCX - st->hIGFDec->infoIGFStartLine ); } - IF( st->element_mode != IVAS_CPE_DFT && !sba_dirac_stereo_flag ) + test(); + IF( NE_16(st->element_mode, IVAS_CPE_DFT) && !sba_dirac_stereo_flag ) { IMDCT_ivas_fx( xn_bufFB_fx, q_x, hTcxDec->syn_Overl, hTcxDec->syn_Overl_TDAC, xn_buf_fx, hTcxCfg->tcx_aldo_window_1, hTcxCfg->tcx_aldo_window_1_trunc, hTcxCfg->tcx_aldo_window_2, @@ -2086,18 +2108,22 @@ void decoder_tcx_imdct_fx( } /* Generate additional comfort noise to mask potential coding artefacts */ - IF( NE_16( st->flag_cna, 0 ) && NE_16( st->element_mode, IVAS_CPE_TD ) && NE_16( st->element_mode, IVAS_CPE_DFT ) && EQ_16( st->cna_dirac_flag, 0 ) ) + test(); + test(); + test(); + IF( ( st->flag_cna != 0 ) && NE_16( st->element_mode, IVAS_CPE_TD ) && NE_16( st->element_mode, IVAS_CPE_DFT ) && ( st->cna_dirac_flag == 0 ) ) { generate_masking_noise_mdct_ivas_fx( x_fx, &x_e, st->hFdCngDec->hFdCngCom ); FOR( Word16 ind = 0; ind < L_frame; ind++ ) { - x_fx[ind] = L_shr( x_fx[ind], sub( 31, add( x_e, q_x ) ) ); + x_fx[ind] = L_shr( x_fx[ind], sub( 31, add( x_e, q_x ) ) ); // q_x } } - IF( EQ_16( st->element_mode, IVAS_CPE_DFT ) || NE_16( sba_dirac_stereo_flag, 0 ) ) + test(); + IF( EQ_16( st->element_mode, IVAS_CPE_DFT ) || ( sba_dirac_stereo_flag != 0 ) ) { - Copy32( x_fx, xn_bufFB_fx, s_max( L_spec, s_max( L_frame, L_frameTCX ) ) ); + Copy32( x_fx, xn_bufFB_fx, s_max( L_spec, s_max( L_frame, L_frameTCX ) ) ); // q_x IMDCT_ivas_fx( xn_bufFB_fx, q_x, hTcxDec->syn_Overl, hTcxDec->syn_Overl_TDAC, xn_buf_fx, hTcxCfg->tcx_aldo_window_1, hTcxCfg->tcx_aldo_window_1_trunc, hTcxCfg->tcx_aldo_window_2, hTcxCfg->tcx_mdct_window_half, hTcxCfg->tcx_mdct_window_minimum, hTcxCfg->tcx_mdct_window_trans, hTcxCfg->tcx_mdct_window_half_length, hTcxCfg->tcx_mdct_window_min_length, index, kernelType, left_rect, tcx_offset, overlap, L_frame, L_frameTCX, shr( s_max( L_frameTCX, L_spec ), 1 ), L_frame_glob, frame_cnt, bfi, st->hHQ_core->old_out_LB_fx, 0, st, 0, acelp_zir_fx, q_win ); @@ -2105,9 +2131,10 @@ void decoder_tcx_imdct_fx( FOR( Word16 ind = 0; ind < L_MDCT_OVLP_MAX + L_FRAME_PLUS + L_MDCT_OVLP_MAX; ind++ ) { - xn_bufFB_fx_16[ind] = (Word16) L_shr( xn_bufFB_fx[ind], ( q_x - q_win ) ); + xn_bufFB_fx_16[ind] = extract_l( L_shr( xn_bufFB_fx[ind], sub( q_x, q_win ) ) ); // q_x + move16(); } - IF( NE_16( st->element_mode, EVS_MONO ) ) + IF( st->element_mode != EVS_MONO ) { IMDCT_ivas_fx( x_tmp_fx, q_x, hTcxDec->syn_OverlFB, hTcxDec->syn_Overl_TDACFB, xn_bufFB_fx_16, hTcxCfg->tcx_aldo_window_1_FB, hTcxCfg->tcx_aldo_window_1_FB_trunc, hTcxCfg->tcx_aldo_window_2_FB, hTcxCfg->tcx_mdct_window_halfFB, hTcxCfg->tcx_mdct_window_minimumFB, hTcxCfg->tcx_mdct_window_transFB, hTcxCfg->tcx_mdct_window_half_lengthFB, hTcxCfg->tcx_mdct_window_min_lengthFB, index, @@ -2121,12 +2148,13 @@ void decoder_tcx_imdct_fx( } FOR( Word16 ind = 0; ind < L_MDCT_OVLP_MAX + L_FRAME_PLUS + L_MDCT_OVLP_MAX; ind++ ) { - xn_bufFB_fx[ind] = L_shl( xn_bufFB_fx_16[ind], ( q_x - q_win ) ); + xn_bufFB_fx[ind] = L_shl( xn_bufFB_fx_16[ind], sub( q_x, q_win ) ); // Q_x } - IF( EQ_16( bfi, 0 ) ) + IF( ( bfi == 0 ) ) { Word16 res_m, res_e = 0; + move16(); st->second_last_tns_active = st->last_tns_active; move16(); st->last_tns_active = hTcxCfg->fIsTNSAllowed & fUseTns; @@ -2157,20 +2185,20 @@ void decoder_tcx_imdct_fx( } /* Update old_syn_overl */ - IF( EQ_16( hTcxCfg->last_aldo, 0 ) ) + IF( hTcxCfg->last_aldo == 0 ) { - Copy( xn_buf_fx + L_frame, hTcxDec->syn_Overl, overlap ); + Copy( xn_buf_fx + L_frame, hTcxDec->syn_Overl, overlap ); // Q(-2) FOR( Word16 ind = 0; ind < overlapFB; ind++ ) { - hTcxDec->syn_OverlFB[ind] = (Word16) L_shr( xn_bufFB_fx[add( ind, L_frameTCX )], sub( q_x, q_win ) ); + hTcxDec->syn_OverlFB[ind] = (Word16) L_shr( xn_bufFB_fx[( ind + L_frameTCX )], sub( q_x, q_win ) ); // q_x } } /* Output */ - Copy( xn_buf_fx + sub( shr( overlap, 1 ), tcx_offset ), synth_fx, L_frame_glob ); + Copy( xn_buf_fx + sub( shr( overlap, 1 ), tcx_offset ), synth_fx, L_frame_glob ); // Q(-2) FOR( Word16 ind = 0; ind < L_frameTCX_glob; ind++ ) { - synthFB_fx[ind] = (Word16) L_shr( xn_bufFB_fx[add( ind, sub( shr( overlapFB, 1 ), tcx_offsetFB ) )], sub( q_x, q_win ) ); + synthFB_fx[ind] = (Word16) L_shr( xn_bufFB_fx[( ind + ( ( overlapFB >> 1 ) - tcx_offsetFB ) )], sub( q_x, q_win ) ); // q_x } diff --git a/lib_dec/dec_tran_fx.c b/lib_dec/dec_tran_fx.c index f92ef8904..a9ea119ba 100644 --- a/lib_dec/dec_tran_fx.c +++ b/lib_dec/dec_tran_fx.c @@ -82,24 +82,22 @@ void decod_tran_fx( gain_code_fx = 0; /* Quantized algebraic codeebook gain */ move32(); - norm_gain_code_fx = 0; /* normalized algebraic codeebook gain */ + norm_gain_code_fx = 0; /* normalized algebraic codeebook gain Q16 */ move32(); - gain_pit_fx = 0; /* Quantized pitch gain */ + gain_pit_fx = 0; /* Quantized pitch gain Q14 */ move16(); gain_inov_fx = 0; /* inovation gain */ move16(); - gain_preQ_fx = 0; /* Gain of prequantizer excitation */ + gain_preQ_fx = 0; /* Gain of prequantizer excitation Q2 */ move16(); - gain_preQ_fx = 0; - move16(); - set16_fx( code_preQ_fx, 0, L_SUBFR ); + set16_fx( code_preQ_fx, 0, L_SUBFR ); // Q10 /*----------------------------------------------------------------* * ACELP subframe loop *----------------------------------------------------------------*/ - p_Aq_fx = Aq_fx; - pt_pitch_fx = pitch_buf_fx; + p_Aq_fx = Aq_fx; // Q12 + pt_pitch_fx = pitch_buf_fx; // Q6 Jopt_flag = 0; move16(); norm_gain_preQ_fx = 0; @@ -116,9 +114,9 @@ void decod_tran_fx( IF( i_subfr == 0 && GT_16( st_fx->Q_exc, 2 ) ) { tmp16 = sub( 2, st_fx->Q_exc ); - Scale_sig( exc_fx - L_EXC_MEM, L_EXC_MEM, tmp16 ); - Scale_sig( bwe_exc_fx - PIT16k_MAX * 2, PIT16k_MAX * 2, tmp16 ); - Scale_sig( hGSCDec->last_exc_dct_in_fx, L_FRAME, tmp16 ); + Scale_sig( exc_fx - L_EXC_MEM, L_EXC_MEM, tmp16 ); // Q2 + Scale_sig( bwe_exc_fx - PIT16k_MAX * 2, PIT16k_MAX * 2, tmp16 ); // Q2 + Scale_sig( hGSCDec->last_exc_dct_in_fx, L_FRAME, tmp16 ); // Q2 st_fx->Q_exc = add( st_fx->Q_exc, tmp16 ); move16(); } @@ -213,7 +211,7 @@ void decod_tran_fx( #endif IF( EQ_16( L_frame_fx, L_FRAME ) ) /* Rescaling for 12.8k core */ { - Rescale_exc( hMusicPF->dct_post_old_exc_fx, &exc_fx[i_subfr], &bwe_exc_fx[shr( imult1616( i_subfr, 2 * HIBND_ACB_L_FAC ), 1 )], hGSCDec->last_exc_dct_in_fx, + Rescale_exc( hMusicPF->dct_post_old_exc_fx, &exc_fx[i_subfr], &bwe_exc_fx[( ( i_subfr * 2 * HIBND_ACB_L_FAC ) >> 1 )], hGSCDec->last_exc_dct_in_fx, L_SUBFR, L_SUBFR * HIBND_ACB_L_FAC, gain_code_fx, &( st_fx->Q_exc ), st_fx->Q_subfr, exc2_fx, i_subfr, st_fx->coder_type ); } ELSE /* Rescaling for 16k core */ @@ -230,7 +228,7 @@ void decod_tran_fx( *-----------------------------------------------------------------*/ IF( GE_32( st_fx->core_brate, MIN_BRATE_AVQ_EXC ) ) { - IF( EQ_16( st_fx->element_mode, EVS_MONO ) ) + IF( ( st_fx->element_mode == EVS_MONO ) ) { tmp1_fx = add( 15 - Q_AVQ_OUT_DEC - 2, st_fx->Q_exc ); } @@ -296,9 +294,9 @@ void decod_tran_fx( } p_Aq_fx += ( M + 1 ); pt_pitch_fx++; - st_fx->tilt_code_dec_fx[tmp_idx] = st_fx->tilt_code_fx; + st_fx->tilt_code_dec_fx[tmp_idx] = st_fx->tilt_code_fx; // Q15 move16(); - gain_buf[tmp_idx] = gain_pit_fx; + gain_buf[tmp_idx] = gain_pit_fx; // Q14 move16(); } diff --git a/lib_dec/dec_uv_fx.c b/lib_dec/dec_uv_fx.c index 7edc512f7..231b0cb73 100644 --- a/lib_dec/dec_uv_fx.c +++ b/lib_dec/dec_uv_fx.c @@ -84,14 +84,14 @@ void decod_unvoiced_fx( Word16 tmp_idx = 0; move16(); - if ( i_subfr_fx != 0 ) + IF ( i_subfr_fx != 0 ) { tmp_idx = idiv1616( i_subfr_fx, L_SUBFR ); } voice_factors_fx[tmp_idx] = 0; move16(); - interp_code_5over2_fx( &exc_fx[i_subfr_fx], &bwe_exc_fx[shr( imult1616( i_subfr_fx, 2 * HIBND_ACB_L_FAC ), 1 )], L_SUBFR ); + interp_code_5over2_fx( &exc_fx[i_subfr_fx], &bwe_exc_fx[( ( i_subfr_fx * 2 * HIBND_ACB_L_FAC ) >> 1 )], L_SUBFR ); p_Aq_fx += ( M + 1 ); pt_pitch_fx++; @@ -217,7 +217,7 @@ void decod_unvoiced_ivas_fx( IF( EQ_16( st_fx->L_frame, L_FRAME ) ) { - Rescale_exc( st_fx->hMusicPF->dct_post_old_exc_fx, &exc_fx[i_subfr_fx], ( bwe_exc_fx != NULL ) ? &bwe_exc_fx[shr( imult1616( i_subfr_fx, 2 * HIBND_ACB_L_FAC ), 1 )] : NULL, st_fx->hGSCDec->last_exc_dct_in_fx, + Rescale_exc( st_fx->hMusicPF->dct_post_old_exc_fx, &exc_fx[i_subfr_fx], ( bwe_exc_fx != NULL ) ? &bwe_exc_fx[( ( i_subfr_fx * 2 * HIBND_ACB_L_FAC ) >> 1 )] : NULL, st_fx->hGSCDec->last_exc_dct_in_fx, L_SUBFR, L_SUBFR * HIBND_ACB_L_FAC, L_max( gain_code2_fx, gain_code_fx ), &( st_fx->Q_exc ), st_fx->Q_subfr, exc2_fx, i_subfr_fx, UNVOICED ); } ELSE @@ -262,7 +262,7 @@ void decod_unvoiced_ivas_fx( } voice_factors_fx[tmp_idx] = 0; move16(); - interp_code_5over2_fx( &exc_fx[i_subfr_fx], &bwe_exc_fx[shr( imult1616( i_subfr_fx, 2 * HIBND_ACB_L_FAC ), 1 )], L_SUBFR ); + interp_code_5over2_fx( &exc_fx[i_subfr_fx], &bwe_exc_fx[( ( i_subfr_fx * 2 * HIBND_ACB_L_FAC ) >> 1 )], L_SUBFR ); p_Aq_fx += ( M + 1 ); pt_pitch_fx++; diff --git a/lib_dec/dlpc_avq_fx.c b/lib_dec/dlpc_avq_fx.c index 1f4a7117b..c38d0b9a3 100644 --- a/lib_dec/dlpc_avq_fx.c +++ b/lib_dec/dlpc_avq_fx.c @@ -48,9 +48,9 @@ Word16 dlpc_avq_fx( move16(); LSF_Q[last + i] = 0; } - vlpc_1st_dec( p_index[0], &LSF_Q[last] ); + vlpc_1st_dec( p_index[0], &LSF_Q[last] ); // LSF_Q[last] -> Q2.56 p_index++; - vlpc_2st_dec( &LSF_Q[last], &p_index[0], 0, sr_core ); + vlpc_2st_dec( &LSF_Q[last], &p_index[0], 0, sr_core ); // Q2.56 nbi = add( 2, add( p_index[0], p_index[1] ) ); p_index += nbi; @@ -70,7 +70,7 @@ Word16 dlpc_avq_fx( move16(); LSF_Q[i] = 0; } - vlpc_1st_dec( p_index[0], &LSF_Q[0] ); + vlpc_1st_dec( p_index[0], &LSF_Q[0] ); ////Q2.56 p_index++; vlpc_2st_dec( &LSF_Q[0], &p_index[0], 0, sr_core ); } @@ -82,7 +82,7 @@ Word16 dlpc_avq_fx( move16(); LSF_Q[i] = LSF_Q[M + i]; } - vlpc_2st_dec( &LSF_Q[0], &p_index[0], 3, sr_core ); + vlpc_2st_dec( &LSF_Q[0], &p_index[0], 3, sr_core ); ////Q2.56 } nbi = add( 2, add( p_index[0], p_index[1] ) ); p_index += nbi; @@ -425,6 +425,7 @@ Word16 decode_lpc_avq_ivas_fx( test(); test(); test(); + test(); IF( NE_16( element_mode, IVAS_CPE_MDCT ) || ( !( sns_low_br_mode && ( ( stereo_mode == 0 ) || EQ_16( stereo_mode, 1 ) ) ) && !( ( q_type == 0 ) && EQ_16( param_lpc[j - 1], -2 ) ) ) ) { /* 2 bits to specify Q2,Q3,Q4,ext */ diff --git a/lib_dec/igf_dec_fx.c b/lib_dec/igf_dec_fx.c index 74299beae..463875a1c 100644 --- a/lib_dec/igf_dec_fx.c +++ b/lib_dec/igf_dec_fx.c @@ -38,45 +38,45 @@ static Word16 IGF_getScaleFactor32Cond( /**< ou Word32 tmp32; - x_max = 0; + x_max = 0; // Q31 move32(); - x_min = 0; + x_min = 0; // Q31 move32(); FOR( i = 0; i < len_x; i++ ) { - tmp32 = L_add( x[i], 0 ); /*L_and(x[i], cond[i]);*/ + tmp32 = L_add( x[i], 0 ); /*L_and(x[i], cond[i]);*/ // Q31 - if ( cond[i] == 0 ) + IF( cond[i] == 0 ) { - tmp32 = L_deposit_h( 0 ); + tmp32 = L_deposit_h( 0 ); // Q31 } - if ( tmp32 >= 0 ) + IF( tmp32 >= 0 ) { - x_max = L_max( x_max, tmp32 ); + x_max = L_max( x_max, tmp32 ); // Q31 } - if ( tmp32 < 0 ) + IF( tmp32 < 0 ) { - x_min = L_min( x_min, tmp32 ); + x_min = L_min( x_min, tmp32 ); // Q31 } } - i_max = 0x20; + i_max = 0x20; // Q0 move16(); - i_min = 0x20; + i_min = 0x20; // Q0 move16(); - if ( x_max != 0 ) + IF( x_max != 0 ) { - i_max = norm_l( x_max ); + i_max = norm_l( x_max ); // Q0 } - if ( x_min != 0 ) + IF( x_min != 0 ) { - i_min = norm_l( x_min ); + i_min = norm_l( x_min ); // Q0 } - i = s_and( s_min( i_max, i_min ), 0x1F ); + i = s_and( s_min( i_max, i_min ), 0x1F ); // Q0 return i; } @@ -87,7 +87,7 @@ measures TCX noise static Word16 IGF_replaceTCXNoise_1( /**< out: Q0 | number of noise bands */ const Word32 *in, /**< in: Q31 | MDCT spectrum */ Word16 s_l, /**< in: Q0 | noise headroom */ - const Word16 *TCXNoise, /**< in: | tcx noise indicator vector */ + const Word16 *TCXNoise, /**< in: Q0 | tcx noise indicator vector */ const Word16 start, /**< in: Q0 | start MDCT subband index */ const Word16 stop, /**< in: Q0 | stop MDCT subband index */ Word32 *totalNoiseNrg /**< out: | measured noise energy */ @@ -107,32 +107,30 @@ static Word16 IGF_replaceTCXNoise_1( /**< ou nE = 0; move32(); - FOR( sb = start; sb < stop; sb++ ) - { - IF( TCXNoise[sb] ) - { - tmp16 = extract_h( L_shl( in[sb], s_l ) ); - } - IF( TCXNoise[sb] ) - { - nE = L_mac( nE, tmp16, tmp16 ); - } - if ( TCXNoise[sb] ) - { - noise = add( noise, 1 ); - } - } + 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 +} +} - *totalNoiseNrg = nE; - move32(); +*totalNoiseNrg = nE; // Q31 + s_l +move32(); - return noise; +return noise; } static Word16 ivas_IGF_replaceTCXNoise_1_fx( /**< out: Q0 | number of noise bands */ const Word32 *in, /**< in: Q31 | MDCT spectrum */ Word16 s_l, /**< in: Q0 | noise headroom */ - const Word16 *TCXNoise, /**< in: | tcx noise indicator vector */ + const Word16 *TCXNoise, /**< in: Q0 | tcx noise indicator vector */ const Word16 start, /**< in: Q0 | start MDCT subband index */ const Word16 stop, /**< in: Q0 | stop MDCT subband index */ Word32 *totalNoiseNrg, /**< out: | measured noise energy */ @@ -156,15 +154,15 @@ static Word16 ivas_IGF_replaceTCXNoise_1_fx( /**< out: Q { IF( TCXNoise[sb] ) { - tmp16 = extract_h( L_shl( in[sb], s_l ) ); + tmp16 = extract_h( L_shl( in[sb], s_l ) ); // Q31 + s_l } IF( TCXNoise[sb] ) { - nE = W_mac_16_16( nE, tmp16, tmp16 ); + nE = W_mac_16_16( nE, tmp16, tmp16 ); // Q31 + s_l } - if ( TCXNoise[sb] ) + IF( TCXNoise[sb] ) { - noise = add( noise, 1 ); + noise = add( noise, 1 ); // Q0 } } @@ -181,7 +179,7 @@ static Word16 ivas_IGF_replaceTCXNoise_1_fx( /**< out: Q /**********************************************************************/ /* replaces TCX noise **************************************************************************/ -static void IGF_replaceTCXNoise_2( Word32 *in, /**< in/out: | MDCT spectrum */ +static void IGF_replaceTCXNoise_2( Word32 *in, /**< in/out: Q31 | MDCT spectrum */ const Word16 *TCXNoise, /**< in: Q0 | tcx noise indicator vector */ const Word16 start, /**< in: Q0 | start MDCT subband index */ const Word16 stop, /**< in: Q0 | stop MDCT subband index */ @@ -206,55 +204,55 @@ static void IGF_replaceTCXNoise_2( Word32 *in, /**< in { IF( TCXNoise[sb] ) { - val = Random( nfSeed ); + val = Random( nfSeed ); // Q0 } IF( TCXNoise[sb] ) { - in[sb] = L_deposit_l( val ); + in[sb] = L_deposit_l( val ); // Q0 move32(); } IF( TCXNoise[sb] ) { - val = shr( val, 5 ); + val = shr( val, 5 ); // Q-5 } IF( TCXNoise[sb] ) { - rE = L_mac( rE, val, val ); + rE = L_mac( rE, val, val ); // Q-9 } } - totalNoiseNrg = L_shr( totalNoiseNrg, 1 ); + totalNoiseNrg = L_shr( totalNoiseNrg, 1 ); // Q-9 /* make sure that rE is never 0 */ if ( rE == 0 ) { - rE = L_add( totalNoiseNrg, 0 ); /* save move32() -> use L_add(x, 0) = x; */ + rE = L_add( totalNoiseNrg, 0 ); /* save move32() -> use L_add(x, 0) = x; */ // Q-9 } /* if totalNoiseNrg == 0, then rE must be at least 0x00010000, otherwise division by 0 will occur */ if ( totalNoiseNrg == 0 ) { - rE = L_max( rE, 0x00010000 ); + rE = L_max( rE, 0x00010000 ); // Q-9 } /* make sure that rE is never smaller than totalNoiseNrg */ - L_tmp = L_sub( rE, totalNoiseNrg ); + L_tmp = L_sub( rE, totalNoiseNrg ); // Q-9 if ( L_tmp < 0 ) { - rE = totalNoiseNrg; /* save move32() -> use L_add(x, 0) = x; */ + rE = totalNoiseNrg; /* save move32() -> use L_add(x, 0) = x; */ // Q-9 move32(); } - g = getSqrtWord32( L_mult( divide3232( totalNoiseNrg, rE ), 8192 /*1.0f / 4.0f Q15*/ ) ); - g = shl( g, 1 ); + g = getSqrtWord32( L_mult( divide3232( totalNoiseNrg, rE ), 8192 /*1.0f / 4.0f Q15*/ ) ); // ((Q15 + Q15 + Q1) / 2) -> Q15 + g = shl( g, 1 ); // Q16 FOR( sb = start; sb < stop; sb++ ) { IF( TCXNoise[sb] ) { - in[sb] = L_shr( L_mult( extract_l( in[sb] ), g ), s_l ); + in[sb] = L_shr( L_mult( extract_l( in[sb] ), g ), s_l ); // Q15 + Q16 + Q1 - s_l move32(); } } @@ -293,12 +291,12 @@ static void IGF_replaceTCXNoise_2_new_ivas( Word32 *in, /**< in { IF( TCXNoise[sb] ) { - val = Random( nfSeed ); + val = Random( nfSeed ); // Q0 move16(); - in[sb] = L_deposit_l( val ); + in[sb] = L_deposit_l( val ); // Q0 move32(); - val = shr( val, 5 ); - rE = L_mac( rE, val, val ); + val = shr( val, 5 ); // Q-5 + rE = L_mac( rE, val, val ); // Q-9 n_noise_bands_tile = add( n_noise_bands_tile, 1 ); } } @@ -311,17 +309,17 @@ static void IGF_replaceTCXNoise_2_new_ivas( Word32 *in, /**< in /* make sure that rE is never 0 */ if ( rE == 0 ) { - rE = L_add( totalNoiseNrg, 0 ); /* save move32() -> use L_add(x, 0) = x; */ + rE = L_add( totalNoiseNrg, 0 ); /* save move32() -> use L_add(x, 0) = x; */ // Q31 - totalNoiseNrg_e } /* if totalNoiseNrg == 0, then rE must be at least 0x00010000, otherwise division by 0 will occur */ if ( totalNoiseNrg == 0 ) { - rE = L_max( rE, 0x00010000 ); + rE = L_max( rE, 0x00010000 ); // Q-9 } Word16 tmp, tmp_e; - L_tmp = Mpy_32_16_1( totalNoiseNrg, noise_band_ratio ); + L_tmp = Mpy_32_16_1( totalNoiseNrg, noise_band_ratio ); // Q31 - totalNoiseNrg_e tmp = BASOP_Util_Divide3232_Scale( L_tmp, rE, &tmp_e ); tmp_e = add( tmp_e, sub( totalNoiseNrg_e, 40 ) ); g = Sqrt16( tmp, &tmp_e ); @@ -349,13 +347,13 @@ static void IGF_replaceTCXNoise_2_new_ivas( Word32 *in, /**< in **************************************************************************/ static void IGF_replaceTCXNoise_2_new_ivas_with_var_shift( Word32 *in, /**< in/out: | MDCT spectrum */ Word16 *in_e_arr, /**< in/out: | MDCT spectrum exp */ - const Word16 *TCXNoise, /**< in: | tcx noise indicator vector */ - const Word16 start, /**< in: | start MDCT subband index */ - const Word16 stop, /**< in: | stop MDCT subband index */ + const Word16 *TCXNoise, /**< in: Q0 | tcx noise indicator vector */ + const Word16 start, /**< in: Q0 | start MDCT subband index */ + const Word16 stop, /**< in: Q0 | stop MDCT subband index */ Word32 totalNoiseNrg, /**< in: | measured noise energy */ Word16 totalNoiseNrg_e, /**< in: | measured noise energy exp */ - const Word16 n_noise_bands, /**< in: | number of noise bands in src */ - Word16 *nfSeed /**< in: | random generator noise seed */ + const Word16 n_noise_bands, /**< in: Q0 | number of noise bands in src */ + Word16 *nfSeed /**< in: Q0 | random generator noise seed */ ) { Word16 sb; @@ -377,14 +375,14 @@ static void IGF_replaceTCXNoise_2_new_ivas_with_var_shift( Word32 *in, { IF( TCXNoise[sb] ) { - val = Random( nfSeed ); + val = Random( nfSeed ); // Q0 move16(); - in[sb] = L_deposit_l( val ); + in[sb] = L_deposit_l( val ); // Q0 move32(); in_e_arr[sb] = 31; move16(); - val = shr( val, 5 ); - rE = L_mac( rE, val, val ); + val = shr( val, 5 ); // Q-5 + rE = L_mac( rE, val, val ); // Q-9 n_noise_bands_tile = add( n_noise_bands_tile, 1 ); } } @@ -397,17 +395,17 @@ static void IGF_replaceTCXNoise_2_new_ivas_with_var_shift( Word32 *in, /* make sure that rE is never 0 */ if ( rE == 0 ) { - rE = L_add( totalNoiseNrg, 0 ); /* save move32() -> use L_add(x, 0) = x; */ + rE = L_add( totalNoiseNrg, 0 ); /* save move32() -> use L_add(x, 0) = x; */ // Q31 - totalNoiseNrg_e } /* if totalNoiseNrg == 0, then rE must be at least 0x00010000, otherwise division by 0 will occur */ if ( totalNoiseNrg == 0 ) { - rE = L_max( rE, 0x00010000 ); + rE = L_max( rE, 0x00010000 ); // Q-9 } Word16 tmp, tmp_e; - L_tmp = Mpy_32_16_1( totalNoiseNrg, noise_band_ratio ); + L_tmp = Mpy_32_16_1( totalNoiseNrg, noise_band_ratio ); // Q31 - totalNoiseNrg_e tmp = BASOP_Util_Divide3232_Scale( L_tmp, rE, &tmp_e ); tmp_e = add( tmp_e, sub( totalNoiseNrg_e, 40 ) ); g = Sqrt16( tmp, &tmp_e ); @@ -441,23 +439,23 @@ static void IGF_decode_whitening_level( Decoder_State *st, Word16 tmp; - tmp = get_next_indice_fx( st, 1 ); + tmp = get_next_indice_fx( st, 1 ); // Q0 if ( tmp == 0 ) { - hPrivateData->currWhiteningLevel[p] = IGF_WHITENING_MID; + hPrivateData->currWhiteningLevel[p] = IGF_WHITENING_MID; // Q0 move16(); return; } - tmp = get_next_indice_fx( st, 1 ); - hPrivateData->currWhiteningLevel[p] = IGF_WHITENING_STRONG; + tmp = get_next_indice_fx( st, 1 ); // Q0 + hPrivateData->currWhiteningLevel[p] = IGF_WHITENING_STRONG; // Q0 move16(); if ( tmp == 0 ) { - hPrivateData->currWhiteningLevel[p] = IGF_WHITENING_OFF; + hPrivateData->currWhiteningLevel[p] = IGF_WHITENING_OFF; // Q0 move16(); } } @@ -469,7 +467,7 @@ static void IGF_decode_temp_flattening_trigger( Decoder_State *st, IGF_DEC_INSTANCE_HANDLE hInstance /**< in: | instance handle of IGF Deccoder */ ) { - hInstance->flatteningTrigger = get_next_indice_fx( st, 1 ); + hInstance->flatteningTrigger = get_next_indice_fx( st, 1 ); // Q0 move16(); } @@ -520,7 +518,7 @@ static void IGF_convert_exponent_per_idx_to_per_tile( H_IGF_GRID hGrid, FOR( j = start; j < stop; j++ ) { - igfSpec[j] = L_shr( igfSpec[j], sub( max_e, igfSpec_e_per_idx[j] ) ); + igfSpec[j] = L_shr( igfSpec[j], sub( max_e, igfSpec_e_per_idx[j] ) ); // Q31 - max_e move32(); } @@ -593,7 +591,7 @@ static void IGF_prep( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in FOR( i = strt_cpy; i < hGrid->startLine; i++ ) { - abs_sum = L_add( abs_sum, L_abs( src_spec[i] ) ); + abs_sum = L_add( abs_sum, L_abs( src_spec[i] ) ); // Q31 - src_spec_e } /* fill igf_spec with random noise */ @@ -604,7 +602,7 @@ static void IGF_prep( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in { FOR( i = strt_cpy; i < startLine; i++ ) { - igf_spec[tb++] = L_deposit_l( Random( hInfo->nfSeed ) ); /* 31Q0, fill LSBs */ + igf_spec[tb++] = L_deposit_l( Random( hInfo->nfSeed ) ); /* 31Q0, fill LSBs */ // Q0 move32(); } } @@ -612,7 +610,7 @@ static void IGF_prep( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in { FOR( i = strt_cpy; i < startLine; i++ ) { - igf_spec[tb++] = 0; + igf_spec[tb++] = 0; // Q0 move32(); } } @@ -672,7 +670,7 @@ static void IGF_prep( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in { FOR( tb = hGrid->swb_offset[sfb]; tb < hGrid->swb_offset[sfb + 1]; tb++ ) { - igf_spec[tb] = sel_spec[strt_cpy]; + igf_spec[tb] = sel_spec[strt_cpy]; // Q31 - igf_spec_e move32(); strt_cpy = add( strt_cpy, 1 ); } @@ -744,14 +742,14 @@ static void IGF_prep_ivas( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in strt_cpy = hGrid->sbWrap[tile_idx]; move16(); - IF( GT_16( element_mode, EVS_MONO ) ) + IF( element_mode > EVS_MONO ) { - tile_width = sub( hGrid->swb_offset[hGrid->sfbWrap[tile_idx + 1]], hGrid->swb_offset[hGrid->sfbWrap[tile_idx]] ); - stop = add( strt_cpy, tile_width ); + tile_width = sub( hGrid->swb_offset[hGrid->sfbWrap[tile_idx + 1]], hGrid->swb_offset[hGrid->sfbWrap[tile_idx]] ); // Q0 + stop = add( strt_cpy, tile_width ); // Q0 } ELSE { - stop = hGrid->startLine; + stop = hGrid->startLine; // Q0 move16(); } @@ -764,18 +762,18 @@ static void IGF_prep_ivas( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in FOR( i = strt_cpy; i < stop; i++ ) { - abs_sum = L_add_sat( abs_sum, L_abs( src_spec[i] ) ); /* saturation since it just checks if abs_sum is greater than zero*/ + abs_sum = L_add_sat( abs_sum, L_abs( src_spec[i] ) ); /* saturation since it just checks if abs_sum is greater than zero*/ // Q31 - src_spec_e } /* fill igf_spec with random noise */ - tb = hGrid->swb_offset[hGrid->sfbWrap[tile_idx]]; + tb = hGrid->swb_offset[hGrid->sfbWrap[tile_idx]]; // Q0 move16(); IF( abs_sum != 0 ) { FOR( i = strt_cpy; i < stop; i++ ) { - igf_spec[tb++] = L_deposit_l( Random( hInfo->nfSeed ) ); /* 31Q0, fill LSBs */ + igf_spec[tb++] = L_deposit_l( Random( hInfo->nfSeed ) ); /* 31Q0, fill LSBs */ // Q0 move32(); } } @@ -783,7 +781,7 @@ static void IGF_prep_ivas( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in { FOR( i = strt_cpy; i < stop; i++ ) { - igf_spec[tb++] = 0; + igf_spec[tb++] = 0; // Q0 move32(); } } @@ -797,7 +795,7 @@ static void IGF_prep_ivas( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in /* medium whitening detected */ IF( EQ_16( IGF_WHITENING_MID, hPrivateData->currWhiteningLevel[tile_idx] ) ) { - IF( GT_16( element_mode, EVS_MONO ) ) + IF( element_mode > EVS_MONO ) { IF( n_noise_bands != 0 ) { @@ -879,7 +877,7 @@ static void IGF_prep_ivas( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in { FOR( tb = hGrid->swb_offset[sfb]; tb < hGrid->swb_offset[sfb + 1]; tb++ ) { - igf_spec[tb] = sel_spec[strt_cpy]; + igf_spec[tb] = sel_spec[strt_cpy]; // Q31 - igf_spec_e move32(); strt_cpy = add( strt_cpy, 1 ); } @@ -895,9 +893,9 @@ prepare IGF spectrum in stereo static void IGF_prepStereo( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateDataL, /* i : IGF private data handle */ IGF_DEC_PRIVATE_DATA_HANDLE hPrivateDataR, /* i : IGF private data handle */ - const Word16 igfGridIdx, /* i : in case of CELP->TCX switching, use 1.25 framelength */ - const Word16 *TCXNoiseL, /* i : left TCX noise vector */ - const Word16 *TCXNoiseR, /* i : right TCX noise vector */ + const Word16 igfGridIdx, /* i : in case of CELP->TCX switching, use 1.25 framelength Q0 */ + const Word16 *TCXNoiseL, /* i : left TCX noise vector Q0 */ + const Word16 *TCXNoiseR, /* i : right TCX noise vector Q0 */ Word32 *igf_specL_fx, /* i/o: prepared left IGF spectrum */ Word16 *igf_specL_e_arr, /* i/o: prepared left IGF spectrum exponents for each index */ Word32 *igf_specR_fx, /* i/o: prepared right IGF spectrum */ @@ -906,7 +904,7 @@ static void IGF_prepStereo( const Word16 src_specL_e, /* i : left source spectrum exp */ const Word32 *src_specR_fx, /* i : right source spectrum */ const Word16 src_specR_e, /* i : right source spectrum exp */ - const Word16 *coreMsMask /* i : line wise ms Mask */ + const Word16 *coreMsMask /* i : line wise ms Mask Q0 */ ) { H_IGF_GRID hGrid; @@ -916,11 +914,15 @@ static void IGF_prepStereo( const Word32 c_fx = SQRT2_OVER_2_FIXED; // Q31 Word16 selectionL = 0; // 0 -> IGF, 1 -> pSpecFlat Word16 selectionR = 0; // 0 -> IGF, 1 -> pSpecFlat + move32(); + move16(); + move16(); hInfoL = &hPrivateDataL->igfInfo; hInfoR = &hPrivateDataR->igfInfo; hGrid = &hPrivateDataL->igfInfo.grid[igfGridIdx]; swb_offset = hGrid->swb_offset; + move16(); FOR( tile_idx = 0; tile_idx < hGrid->nTiles; tile_idx++ ) { @@ -938,7 +940,7 @@ static void IGF_prepStereo( FOR( tb = swb_offset[hGrid->sfbWrap[tile_idx]]; tb < swb_offset[hGrid->sfbWrap[tile_idx + 1]]; tb++ ) { - igf_specL_fx[tb] = L_deposit_l( Random( hInfoL->nfSeed ) ); /* 31Q0, fill LSBs */ + igf_specL_fx[tb] = L_deposit_l( Random( hInfoL->nfSeed ) ); /* 31Q0, fill LSBs */ // Q0 move32(); igf_specL_e_arr[tb] = 31; move16(); @@ -1059,8 +1061,8 @@ static void IGF_prepStereo( } ELSE /* MS/DR -> LR */ { - tmpL = Mpy_32_32( selL, c_fx ); - tmpR = Mpy_32_32( selR, c_fx ); + tmpL = Mpy_32_32( selL, c_fx ); // Q31 - selL_e + tmpR = Mpy_32_32( selR, c_fx ); // Q31 - selR_e igf_specL_fx[tb] = BASOP_Util_Add_Mant32Exp( tmpL, selL_e, tmpR, selR_e, &tmp_e ); move32(); igf_specL_e_arr[tb] = tmp_e; @@ -1071,8 +1073,8 @@ static void IGF_prepStereo( { IF( EQ_16( coreMsMask[strt_cpy], 0 ) ) /* LR->MS/DR */ { - tmpL = Mpy_32_32( selL, c_fx ); - tmpR = Mpy_32_32( selR, c_fx ); + tmpL = Mpy_32_32( selL, c_fx ); // Q31 - selL_e + tmpR = Mpy_32_32( selR, c_fx ); // Q31 - selR_e igf_specL_fx[tb] = BASOP_Util_Add_Mant32Exp( tmpL, selL_e, tmpR, selR_e, &tmp_e ); move32(); igf_specL_e_arr[tb] = tmp_e; @@ -1101,7 +1103,7 @@ static void IGF_prepStereo( FOR( tb = swb_offset[hGrid->sfbWrap[tile_idx]]; tb < swb_offset[hGrid->sfbWrap[tile_idx + 1]]; tb++ ) { - igf_specR_fx[tb] = L_deposit_l( Random( hInfoR->nfSeed ) ); /* 31Q0, fill LSBs */ + igf_specR_fx[tb] = L_deposit_l( Random( hInfoR->nfSeed ) ); /* 31Q0, fill LSBs */ // Q0 move32(); igf_specR_e_arr[tb] = 31; move16(); @@ -1225,8 +1227,8 @@ static void IGF_prepStereo( } ELSE /* MS/DR -> LR */ { - tmpL = Mpy_32_32( selL, c_fx ); - tmpR = Mpy_32_32( selR, c_fx ); + tmpL = Mpy_32_32( selL, c_fx ); // Q31 - selL_e + tmpR = Mpy_32_32( selR, c_fx ); // Q31 - selR_e igf_specR_fx[tb] = BASOP_Util_Add_Mant32Exp( tmpL, selL_e, L_negate( tmpR ), selR_e, &tmp_e ); move32(); igf_specR_e_arr[tb] = tmp_e; @@ -1237,8 +1239,8 @@ static void IGF_prepStereo( { IF( EQ_16( coreMsMask[strt_cpy], 0 ) ) /* LR->MS/DR */ { - tmpL = Mpy_32_32( selL, c_fx ); - tmpR = Mpy_32_32( selR, c_fx ); + tmpL = Mpy_32_32( selL, c_fx ); // Q31 - selL_e + tmpR = Mpy_32_32( selR, c_fx ); // Q31 - selR_e igf_specR_fx[tb] = BASOP_Util_Add_Mant32Exp( tmpL, selL_e, L_negate( tmpR ), selR_e, &tmp_e ); move32(); igf_specR_e_arr[tb] = tmp_e; @@ -1493,11 +1495,11 @@ static void IGF_appl( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in /* initialize variables */ - w0 = 6586; + w0 = 6586; // Q15 move16(); - w1 = 12747; + w1 = 12747; // Q15 move16(); - w2 = 13435; + w2 = 13435; // Q15 move16(); dE = 0; move16(); @@ -1571,8 +1573,8 @@ static void IGF_appl( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in { Carry = 0; move16(); -#ifdef BASOP_NOGLOB /* Critical Carry/Overflow*/ - L_tmp = L_add_co( L_tmp, energyTmp[tb], &Carry, &Overflow ); +#ifdef BASOP_NOGLOB /* Critical Carry/Overflow*/ + L_tmp = L_add_co( L_tmp, energyTmp[tb], &Carry, &Overflow ); // Q31 - dE_e Overflow = 0; move16(); L_c = L_macNs_co( L_c, 0, 0, &Carry, &Overflow ); @@ -1582,7 +1584,7 @@ static void IGF_appl( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in L_c = L_macNs( L_c, 0, 0 ); #endif } - L_tmp = norm_llQ31( L_c, L_tmp, &shift ); + L_tmp = norm_llQ31( L_c, L_tmp, &shift ); // Q31 /* float: dE = (float)sqrt(dE / 24.f); basop: */ shift = add( sub( shift, 4 ), dE_e ); /* x/24 = (x >> 4) * 1/1.5 */ dE = Sqrt16norm( extract_h( L_tmp ), &shift ); @@ -1610,7 +1612,7 @@ static void IGF_appl( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in FOR( sfb = start_sfb; sfb < stop_sfb; sfb += hopsize ) { tmp_loop = s_min( add( sfb, hopsize ), stop_sfb ); - FOR( tb = add( sfb, 1 ); tb < tmp_loop; tb++ ) + FOR( tb = sfb + 1; tb < tmp_loop; tb++ ) { sN[sfb] = BASOP_Util_Add_Mant32Exp( sN[sfb], sN_e[sfb], @@ -1642,7 +1644,7 @@ static void IGF_appl( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in width_e = sub( 15, shift ); /* initial value of width_e is 15, -> width = 15Q0 */ /* float: gn = 0.25f * igf_curr - 4.f; basop: */ - gn = hPrivateData->igf_curr[shr( sfb, 1 )]; + gn = hPrivateData->igf_curr[sfb >> 1]; // Q15 move16(); move16(); gn_e = 13; /* set exponent of igf_curr to 13 = 15 - 2; -> igf_curr = igf_curr * 0.25, virtual division by 4 */ @@ -1875,11 +1877,11 @@ static void IGF_appl( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in FOR( tb = 0; tb < hopsize; tb++ ) { /* calculate of the current sfb width */ - width = sub( hGrid->swb_offset[s_min( add( add( sfb, tb ), 1 ), stop_sfb )], /* 15Q0 | width is Q0 */ - hGrid->swb_offset[s_min( add( sfb, tb ), stop_sfb )] ); + width = sub( hGrid->swb_offset[min( sfb + tb + 1, stop_sfb )], /* 15Q0 | width is Q0 */ + hGrid->swb_offset[min( sfb + tb, stop_sfb )] ); - tmp = dS[s_min( add( sfb, tb ), sub( stop_sfb, 1 ) )]; - tmp_e = dS_e[s_min( add( sfb, tb ), sub( stop_sfb, 1 ) )]; + tmp = dS[min( sfb + tb, stop_sfb - 1 )]; + tmp_e = dS_e[min( sfb + tb, stop_sfb - 1 )]; move16(); move16(); @@ -1976,7 +1978,7 @@ static void IGF_appl( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in /*--- check gains /spectrum exponents for possible overflows --- */ /* get tile index */ - if ( LE_16( hGrid->sfbWrap[add( tileIdx, 1 )], sfb ) ) + IF( LE_16( hGrid->sfbWrap[tileIdx + 1], sfb ) ) { tileIdx = add( tileIdx, 1 ); } @@ -2026,7 +2028,7 @@ static void IGF_appl( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in FOR( sfb = start_sfb; sfb < stop_sfb; sfb++ ) { /* get tile index */ - if ( EQ_16( hGrid->sfbWrap[tileIdx + 1], sfb ) ) + IF( EQ_16( hGrid->sfbWrap[tileIdx + 1], sfb ) ) { tileIdx = add( tileIdx, 1 ); } @@ -2106,7 +2108,7 @@ static void IGF_appl( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in { shift = sub( L_tmp_e, *spectrum_e ); tmp = sub( sub( norm_l( L_tmp ), shift ), 32 ); - if ( tmp < 0 ) + IF( tmp < 0 ) { L_tmp2 = L_shl( L_tmp, shift ); } @@ -2119,7 +2121,7 @@ static void IGF_appl( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in { shift = sub( L_tmp_e, *virtualSpec_e ); tmp = sub( sub( norm_l( L_tmp ), shift ), 32 ); - if ( tmp < 0 ) + IF( tmp < 0 ) { L_tmp2 = L_shl( L_tmp, shift ); } @@ -2209,11 +2211,11 @@ static void IGF_appl_ivas( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in /* initialize variables */ - w0 = 6586; + w0 = 6586; // Q15 move16(); - w1 = 12747; + w1 = 12747; // Q15 move16(); - w2 = 13435; + w2 = 13435; // Q15 move16(); dE = 0; move16(); @@ -2289,8 +2291,8 @@ static void IGF_appl_ivas( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in { Carry = 0; move16(); -#ifdef BASOP_NOGLOB /* Critical Carry/Overflow*/ - L_tmp = L_add_co( L_tmp, energyTmp[tb], &Carry, &Overflow ); +#ifdef BASOP_NOGLOB /* Critical Carry/Overflow*/ + L_tmp = L_add_co( L_tmp, energyTmp[tb], &Carry, &Overflow ); // Q31 - dE_e Overflow = 0; L_c = L_macNs_co( L_c, 0, 0, &Carry, &Overflow ); #else @@ -2299,7 +2301,7 @@ static void IGF_appl_ivas( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in L_c = L_macNs( L_c, 0, 0 ); #endif } - L_tmp = norm_llQ31( L_c, L_tmp, &shift ); + L_tmp = norm_llQ31( L_c, L_tmp, &shift ); // Q31 /* float: dE = (float)sqrt(dE / 24.f); basop: */ shift = add( sub( shift, 4 ), dE_e ); /* x/24 = (x >> 4) * 1/1.5 */ dE = Sqrt16norm( extract_h( L_tmp ), &shift ); @@ -2331,7 +2333,7 @@ static void IGF_appl_ivas( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in FOR( sfb = start_sfb; sfb < stop_sfb; sfb += hopsize ) { tmp_loop = s_min( add( sfb, hopsize ), stop_sfb ); - FOR( tb = add( sfb, 1 ); tb < tmp_loop; tb++ ) + FOR( tb = sfb + 1; tb < tmp_loop; tb++ ) { sN[sfb] = BASOP_Util_Add_Mant32Exp( sN[sfb], sN_e[sfb], @@ -2346,9 +2348,7 @@ static void IGF_appl_ivas( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in &pN_e[sfb] ); move32(); sN[tb] = L_deposit_l( 0 ); - move32(); pN[tb] = L_deposit_l( 0 ); - move32(); } } } @@ -2365,7 +2365,7 @@ static void IGF_appl_ivas( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in width_e = sub( 15, shift ); /* initial value of width_e is 15, -> width = 15Q0 */ /* float: gn = 0.25f * igf_curr - 4.f; basop: */ - gn = hPrivateData->igf_curr[shr( sfb, 1 )]; + gn = hPrivateData->igf_curr[sfb >> 1]; // Q15 move16(); move16(); gn_e = 13; /* set exponent of igf_curr to 13 = 15 - 2; -> igf_curr = igf_curr * 0.25, virtual division by 4 */ @@ -2587,11 +2587,11 @@ static void IGF_appl_ivas( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in FOR( tb = 0; tb < hopsize; tb++ ) { /* calculate of the current sfb width */ - width = sub( hGrid->swb_offset[s_min( add( add( sfb, tb ), 1 ), stop_sfb )], /* 15Q0 | width is Q0 */ - hGrid->swb_offset[s_min( add( sfb, tb ), stop_sfb )] ); + width = sub( hGrid->swb_offset[min( sfb + tb + 1, stop_sfb )], /* 15Q0 | width is Q0 */ + hGrid->swb_offset[min( sfb + tb, stop_sfb )] ); - tmp = dS[s_min( add( sfb, tb ), sub( stop_sfb, 1 ) )]; - tmp_e = dS_e[s_min( add( sfb, tb ), sub( stop_sfb, 1 ) )]; + tmp = dS[min( sfb + tb, stop_sfb - 1 )]; + tmp_e = dS_e[min( sfb + tb, stop_sfb - 1 )]; move16(); move16(); @@ -2796,8 +2796,10 @@ static void IGF_appl_ivas( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in move16(); FOR( i = 0; i < hGrid->stopLine; i++ ) { - if ( spectrum[i] != 0 ) + IF( spectrum[i] != 0 ) + { max_e = s_max( max_e, sub( spec_e_arr[i], norm_l( spectrum[i] ) ) ); + } } FOR( i = 0; i < hGrid->stopLine; i++ ) { @@ -2811,8 +2813,10 @@ static void IGF_appl_ivas( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in move16(); FOR( i = hGrid->startLine - IGF_START_MN; i < hGrid->stopLine - IGF_START_MN; i++ ) { - if ( virtualSpec[i] ) + IF( virtualSpec[i] ) + { max_e = s_max( max_e, sub( vspec_e_arr[i], norm_l( virtualSpec[i] ) ) ); + } } FOR( i = hGrid->startLine - IGF_START_MN; i < hGrid->stopLine - IGF_START_MN; i++ ) { @@ -2864,9 +2868,9 @@ static void IGF_getWhiteSpectralData( const Word32 *in, /**< in } FOR( j = start; j < stop - level; j++ ) { - tmp_16 = extract_h( L_shl( in[j + level], s_l ) ); // in_e - s_l - ak = L_mac( ak, tmp_16, tmp_16 ); // 2 * (in_e - s_l) - ak_norm = Mpy_32_16_r( ak, 2185 ); + tmp_16 = extract_h( L_shl( in[j + level], s_l ) ); // e: in_e - s_l + ak = L_mac( ak, tmp_16, tmp_16 ); // e: 2 * (in_e - s_l) + ak_norm = Mpy_32_16_r( ak, 2185 /* 1/15 in Q15 */ ); // e: 2 * (in_e - s_l) tmp_16 = sub( 31, norm_l( ak_norm ) ); if ( ak == 0 ) @@ -2877,11 +2881,11 @@ static void IGF_getWhiteSpectralData( const Word32 *in, /**< in tmp_16 = s_min( 14, sub( 15, shr( tmp_16, 1 ) ) ); div = shl( 1, tmp_16 ); - out[j] = Mpy_32_16_1( L_shl( in[j], s_l ), div ); + out[j] = Mpy_32_16_1( L_shl( in[j], s_l ), div ); // e: in_e - s_l move32(); - tmp_16 = extract_h( L_shl( in[j - level], s_l ) ); - ak = L_msu( ak, tmp_16, tmp_16 ); + tmp_16 = extract_h( L_shl( in[j - level], s_l ) ); // e: in_e - s_l + ak = L_msu( ak, tmp_16, tmp_16 ); // e: 2 * (in_e - s_l) } nrm_i = 0; @@ -2889,7 +2893,7 @@ static void IGF_getWhiteSpectralData( const Word32 *in, /**< in FOR( ; j < stop; j++ ) { - ak_norm = Mpy_32_16_r( ak, nrm_tab[nrm_i++] ); + ak_norm = Mpy_32_16_r( ak, nrm_tab[nrm_i++] ); // e: 2 * (in_e - s_l) tmp_16 = sub( 31, norm_l( ak_norm ) ); if ( ak == 0 ) @@ -2907,10 +2911,10 @@ static void IGF_getWhiteSpectralData( const Word32 *in, /**< in move16(); } - out[j] = Mpy_32_16_1( L_shl( in[j], s_l ), div ); + out[j] = Mpy_32_16_1( L_shl( in[j], s_l ), div ); // e: in_e - s_l move32(); - tmp_16 = extract_h( L_shl( in[j - level], s_l ) ); - ak = L_msu( ak, tmp_16, tmp_16 ); + tmp_16 = extract_h( L_shl( in[j - level], s_l ) ); // e: in_e - s_l + ak = L_msu( ak, tmp_16, tmp_16 ); // e: 2 * (in_e - s_l) } } @@ -2923,12 +2927,12 @@ static void IGF_getWhiteSpectralData( const Word32 *in, /**< in static void IGF_getWhiteSpectralData_ivas( const Word32 *in, /* i : MDCT spectrum */ const Word16 in_e, /* i : MDCT spectrum exp */ - Word16 s_l, /* i : getScaleFactor32() of in */ + Word16 s_l, /* i : getScaleFactor32() of in Q0 */ Word32 *out, /* o : whitened spectrum */ Word16 *out_e, /* o : whitened spectrum exp */ - const Word16 start, /* i : start MDCT subband index */ - const Word16 stop, /* i : stop MDCT subband index */ - const Word16 level /* i : whitening strength */ + const Word16 start, /* i : start MDCT subband index Q0 */ + const Word16 stop, /* i : stop MDCT subband index Q0 */ + const Word16 level /* i : whitening strength Q0 */ ) { Word16 i; @@ -2963,8 +2967,8 @@ static void IGF_getWhiteSpectralData_ivas( move32(); FOR( j = i - level; j < i + level + 1; j++ ) { - tmp_16 = extract_h( L_shl( in[j], s_l ) ); - ak = L_mac( ak, tmp_16, tmp_16 ); + tmp_16 = extract_h( L_shl( in[j], s_l ) ); // e: in_e - s_l + ak = L_mac( ak, tmp_16, tmp_16 ); // e: 2 * (in_e - s_l) } ak = L_deposit_h( BASOP_Util_Divide3216_Scale( ak, add( shl( level, 1 ), 1 ), &tmp_e ) ); ak_e = add( tmp_e, sub( shl( sub( in_e, s_l ), 1 ), 15 ) ); // tmp_e + 2 * (in_e - s_l) - 15 @@ -2986,8 +2990,8 @@ static void IGF_getWhiteSpectralData_ivas( FOR( j = i - level; j < stop; j++ ) { - tmp_16 = extract_h( L_shl( in[j], s_l ) ); - ak = L_mac( ak, tmp_16, tmp_16 ); + tmp_16 = extract_h( L_shl( in[j], s_l ) ); // e: in_e - s_l + ak = L_mac( ak, tmp_16, tmp_16 ); // e: 2 * (in_e - s_l) } ak = L_deposit_h( BASOP_Util_Divide3216_Scale( ak, sub( stop, sub( i, level ) ), &tmp_e ) ); ak_e = add( tmp_e, sub( shl( sub( in_e, s_l ), 1 ), 15 ) ); // tmp_e + 2 * (in_e - s_l) - 15 @@ -3004,7 +3008,7 @@ static void IGF_getWhiteSpectralData_ivas( move16(); FOR( i = start; i < stop; i++ ) { - out[i] = L_shr( in[i], *out_e - out_e_arr[i] ); + out[i] = L_shr( in[i], sub( *out_e, out_e_arr[i] ) ); move32(); } @@ -3153,20 +3157,20 @@ void IGFDecReadData_ivas_fx( const IGF_DEC_INSTANCE_HANDLE hInstance, /**< in /* set/reset all values to default = IGF_WHITENING_OFF */ FOR( p = 0; p < IGF_MAX_TILES; p++ ) { - hPrivateData->currWhiteningLevel[p] = IGF_WHITENING_OFF; + hPrivateData->currWhiteningLevel[p] = IGF_WHITENING_OFF; // Q0 move16(); } IF( isIndepFrame == 0 ) { - tmp = get_next_indice_fx( st, 1 ); + tmp = get_next_indice_fx( st, 1 ); // Q0 } IF( tmp == 1 ) { FOR( p = 0; p < nT; p++ ) { - hPrivateData->currWhiteningLevel[p] = hPrivateData->prevWhiteningLevel[p]; + hPrivateData->currWhiteningLevel[p] = hPrivateData->prevWhiteningLevel[p]; // Q0 move16(); } } @@ -3181,7 +3185,7 @@ void IGFDecReadData_ivas_fx( const IGF_DEC_INSTANCE_HANDLE hInstance, /**< in } ELSE { - tmp = get_next_indice_fx( st, 1 ); + tmp = get_next_indice_fx( st, 1 ); // Q0 } IF( EQ_16( tmp, 1 ) ) @@ -3195,7 +3199,7 @@ void IGFDecReadData_ivas_fx( const IGF_DEC_INSTANCE_HANDLE hInstance, /**< in { FOR( p = 1; p < nT; p++ ) { - hPrivateData->currWhiteningLevel[p] = hPrivateData->currWhiteningLevel[0]; + hPrivateData->currWhiteningLevel[p] = hPrivateData->currWhiteningLevel[0]; // Q0 move16(); } } @@ -3204,7 +3208,7 @@ void IGFDecReadData_ivas_fx( const IGF_DEC_INSTANCE_HANDLE hInstance, /**< in /* save current level for concealment */ FOR( p = 0; p < IGF_MAX_TILES; p++ ) { - hPrivateData->prevWhiteningLevel[p] = hPrivateData->currWhiteningLevel[p]; + hPrivateData->prevWhiteningLevel[p] = hPrivateData->currWhiteningLevel[p]; // Q0 move16(); } @@ -3238,27 +3242,27 @@ void IGFDecReadData( const IGF_DEC_INSTANCE_HANDLE hInstance, /**< in: | ins /* set/reset all values to default = IGF_WHITENING_OFF */ FOR( p = 0; p < IGF_MAX_TILES; p++ ) { - hPrivateData->currWhiteningLevel[p] = IGF_WHITENING_OFF; + hPrivateData->currWhiteningLevel[p] = IGF_WHITENING_OFF; // Q0 move16(); } IF( isIndepFrame == 0 ) { - tmp = get_next_indice_fx( st, 1 ); + tmp = get_next_indice_fx( st, 1 ); // Q0 } IF( EQ_16( tmp, 1 ) ) { FOR( p = 0; p < nT; p++ ) { - hPrivateData->currWhiteningLevel[p] = hPrivateData->prevWhiteningLevel[p]; + hPrivateData->currWhiteningLevel[p] = hPrivateData->prevWhiteningLevel[p]; // Q0 move16(); } } ELSE { IGF_decode_whitening_level( st, hPrivateData, 0 ); - tmp = get_next_indice_fx( st, 1 ); + tmp = get_next_indice_fx( st, 1 ); // Q0 IF( EQ_16( tmp, 1 ) ) { FOR( p = 1; p < nT; p++ ) @@ -3270,7 +3274,7 @@ void IGFDecReadData( const IGF_DEC_INSTANCE_HANDLE hInstance, /**< in: | ins { FOR( p = 1; p < nT; p++ ) { - hPrivateData->currWhiteningLevel[p] = hPrivateData->currWhiteningLevel[0]; + hPrivateData->currWhiteningLevel[p] = hPrivateData->currWhiteningLevel[0]; // Q0 move16(); } } @@ -3279,7 +3283,7 @@ void IGFDecReadData( const IGF_DEC_INSTANCE_HANDLE hInstance, /**< in: | ins /* save current level for concealment */ FOR( p = 0; p < IGF_MAX_TILES; p++ ) { - hPrivateData->prevWhiteningLevel[p] = hPrivateData->currWhiteningLevel[p]; + hPrivateData->prevWhiteningLevel[p] = hPrivateData->currWhiteningLevel[p]; // Q0 move16(); } @@ -3312,7 +3316,7 @@ void IGFDecReadLevel( /**< ou hGrid = &hPrivateData->igfInfo.grid[igfGridIdx]; m_igfSfbStart = hGrid->startSfb; move16(); - IGFAllZero = get_next_indice_fx( st, 1 ); + IGFAllZero = get_next_indice_fx( st, 1 ); // Q0 IF( IGFAllZero == 0 ) { @@ -4256,7 +4260,7 @@ void IGFDecCopyLPCFlatSpectrum_fx( hPrivateData->pSpecFlat_exp = 30; move16(); - Copy_Scale_sig32( pSpectrumFlat, hPrivateData->pSpecFlat, hGrid->startLine, sub( pSpectrumFlat_exp, 20 ) ); + Copy_Scale_sig32( pSpectrumFlat, hPrivateData->pSpecFlat, hGrid->startLine, sub( pSpectrumFlat_exp, 20 ) ); // Q11 } } diff --git a/lib_dec/igf_scf_dec_fx.c b/lib_dec/igf_scf_dec_fx.c index e7e4fecb3..fe670df56 100644 --- a/lib_dec/igf_scf_dec_fx.c +++ b/lib_dec/igf_scf_dec_fx.c @@ -52,7 +52,7 @@ static Word16 quant_ctx_fx( result = s_min( abs_s( ctx ), IGF_CTX_OFFSET ); /* limit the absolute value to IGF_CTX_OFFSET */ - if ( ctx < 0 ) /* add the sign back, if needed */ + IF( ctx < 0 ) /* add the sign back, if needed */ { result = negate( result ); } @@ -90,7 +90,7 @@ static Word16 arith_decode_bits_fx( static Word16 arith_decode_residual_fx( IGFSCFDEC_INSTANCE_HANDLE hPrivateData, /* i/o: instance handle */ Decoder_State *st, /* i/o: pointer to decoder state */ - const UWord16 *cumulativeFrequencyTable, /* i: cumulative frequency table to be used */ + const UWord16 *cumulativeFrequencyTable, /* i: cumulative frequency table to be used Q0 */ Word16 tableOffset /* i: offset used to align the table */ ) { @@ -100,49 +100,49 @@ static Word16 arith_decode_residual_fx( move16(); /* decode one of the IGF_SYMBOLS_IN_TABLE == 27 alphabet symbols using the new raw AC function */ - val = ari_decode_14bits_s27_ext_fx( st, &hPrivateData->acState, cumulativeFrequencyTable ); + val = ari_decode_14bits_s27_ext_fx( st, &hPrivateData->acState, cumulativeFrequencyTable ); // Q0 /* meaning of the values of val: */ /* esc_{0} IGF_MIN_ENC_SEPARATE ... IGF_MAX_ENC_SEPARATE esc_{IGF_SYMBOLS_IN_TABLE - 1} */ test(); IF( ( val != 0 ) && ( NE_16( val, IGF_SYMBOLS_IN_TABLE - 1 ) ) ) { - x = add( val, -1 + IGF_MIN_ENC_SEPARATE ); /* (val - 1) + IGF_MIN_ENC_SEPARATE */ + x = add( val, -1 + IGF_MIN_ENC_SEPARATE ); /* (val - 1) + IGF_MIN_ENC_SEPARATE */ // Q0 - x = sub( x, tableOffset ); + x = sub( x, tableOffset ); // Q0 return x; } /* decode one of the tails of the distribution */ /* decode extra with 4 bits */ - extra = arith_decode_bits_fx( hPrivateData, st, 4 ); - IF( EQ_16( extra, 15 ) ) /* escape code 15 to indicate extra >= 15 */ + extra = arith_decode_bits_fx( hPrivateData, st, 4 ); // Q0 + IF( EQ_16( extra, 15 ) ) /* escape code 15 to indicate extra >= 15 */ { /* decode addtional extra with 6 bits */ - extra = arith_decode_bits_fx( hPrivateData, st, 6 ); - IF( EQ_16( extra, 63 ) ) /* escape code 63 to indicate extra >= 63 */ + extra = arith_decode_bits_fx( hPrivateData, st, 6 ); // Q0 + IF( EQ_16( extra, 63 ) ) /* escape code 63 to indicate extra >= 63 */ { /* decode safety extra with 7 bits */ - extra = arith_decode_bits_fx( hPrivateData, st, 7 ); + extra = arith_decode_bits_fx( hPrivateData, st, 7 ); // Q0 extra = add( 63, extra ); } - extra = add( 15, extra ); + extra = add( 15, extra ); // Q0 } - if ( val == 0 ) + IF( val == 0 ) { /* escape code 0 to indicate x <= IGF_MIN_ENC_SEPARATE - 1 */ - x = sub( IGF_MIN_ENC_SEPARATE - 1, extra ); + x = sub( IGF_MIN_ENC_SEPARATE - 1, extra ); // Q0 } - if ( EQ_16( val, IGF_SYMBOLS_IN_TABLE - 1 ) ) + IF( EQ_16( val, IGF_SYMBOLS_IN_TABLE - 1 ) ) { /* escape code (IGF_SYMBOLS_IN_TABLE - 1) to indicate x >= IGF_MAX_ENC_SEPARATE + 1 */ - x = add( IGF_MAX_ENC_SEPARATE + 1, extra ); + x = add( IGF_MAX_ENC_SEPARATE + 1, extra ); // Q0 } - x = sub( x, tableOffset ); + x = sub( x, tableOffset ); // Q0 return x; } @@ -193,7 +193,7 @@ static void decode_sfe_vector_fx( res = ari_decode_14bits_s27_ext_fx( st, &hPrivateData->acState, (const UWord16 *) hPrivateData->cf_se00 ); pred = arith_decode_bits_fx( hPrivateData, st, 2 ); /* LSBs as 2 bit raw */ - x[f] = add( shl( res, 2 ), pred ); + x[f] = add( shl( res, 2 ), pred ); // Q0 move16(); } ELSE IF( EQ_16( f, 1 ) ) @@ -203,8 +203,8 @@ static void decode_sfe_vector_fx( st, hPrivateData->cf_se01, hPrivateData->cf_off_se01 ); - x[f] = add( x[0], res ); - move16(); /* f - increment is 0, pred = b */ + x[f] = add( x[0], res ); // Q0 + move16(); /* f - increment is 0, pred = b */ } ELSE { @@ -219,8 +219,8 @@ static void decode_sfe_vector_fx( st, hPrivateData->cf_se02 + index1, hPrivateData->cf_off_se02[index2] ); - x[f] = add( x[prev_offset], res ); - move16(); /* pred = b */ + x[f] = add( x[prev_offset], res ); // Q0 + move16(); /* pred = b */ } } ELSE @@ -233,8 +233,8 @@ static void decode_sfe_vector_fx( st, hPrivateData->cf_se10, hPrivateData->cf_off_se10 ); - x[f] = add( prev_x[f], res ); - move16(); /* pred = a */ + x[f] = add( prev_x[f], res ); // Q0 + move16(); /* pred = a */ } ELSE { @@ -257,7 +257,7 @@ static void decode_sfe_vector_fx( st, hPrivateData->cf_se11 + index1, hPrivateData->cf_off_se11[index2] ); - x[f] = add( pred, res ); + x[f] = add( pred, res ); // Q0 move16(); } } @@ -301,7 +301,7 @@ main decoder function void IGFSCFDecoderDecode( IGFSCFDEC_INSTANCE_HANDLE hPublicData, /* i/o: handle to public data or NULL in case there was no instance created */ Decoder_State *st, /* i/o: pointer to decoder state */ - int16_t *sfe, /* o : ptr to an array which will contain the decoded quantized coefficients */ + Word16 *sfe, /* o : ptr to an array which will contain the decoded quantized coefficients */ const Word16 igfGridIdx, /* i : igf grid index see declaration of IGF_GRID_IDX for details */ const Word16 indepFlag /* i : if 1 on input the decoder will be forced to reset, if 0 on input the decoder will be forced to encode without a reset */ diff --git a/lib_dec/init_dec_fx.c b/lib_dec/init_dec_fx.c index 167da45f6..4cdefd6b0 100644 --- a/lib_dec/init_dec_fx.c +++ b/lib_dec/init_dec_fx.c @@ -86,29 +86,29 @@ ivas_error init_decoder_fx( set16_fx( st_fx->mem_MA_fx, 0, M ); - st_fx->dm_fx.prev_state = 0; - move16(); /* This corresponds to st_fx->dispMem in FLP */ - st_fx->dm_fx.prev_gain_code = L_deposit_l( 0 ); + st_fx->dm_fx.prev_state = 0; // Q0 + move16(); /* This corresponds to st_fx->dispMem in FLP */ + st_fx->dm_fx.prev_gain_code = L_deposit_l( 0 ); // Q16 FOR( i = 2; i < 8; i++ ) { - st_fx->dm_fx.prev_gain_pit[i - 2] = 0; + st_fx->dm_fx.prev_gain_pit[i - 2] = 0; // Q14 move16(); } - st_fx->tilt_code_fx = 0; + st_fx->tilt_code_fx = 0; // Q15 move16(); - st_fx->gc_threshold_fx = L_deposit_l( 0 ); + st_fx->gc_threshold_fx = L_deposit_l( 0 ); // Q16 st_fx->last_good = UNVOICED_CLAS; move16(); st_fx->clas_dec = UNVOICED_CLAS; move16(); - st_fx->lp_gainp_fx = 0; + st_fx->lp_gainp_fx = 0; // Q14 move16(); - st_fx->lp_gainc_fx = 0; + st_fx->lp_gainc_fx = 0; // Q3 move16(); - set16_fx( st_fx->old_exc_fx, 0, L_EXC_MEM_DEC ); + set16_fx( st_fx->old_exc_fx, 0, L_EXC_MEM_DEC ); // Q_exc /* AVQ pre-quantizer memory */ st_fx->mem_preemp_preQ_fx = 0; @@ -118,7 +118,7 @@ ivas_error init_decoder_fx( st_fx->use_acelp_preq = 0; move16(); - st_fx->mem_deemph_fx = 0; + st_fx->mem_deemph_fx = 0; // Q_syn move16(); /*-----------------------------------------------------------------* * SWB BWE parameters @@ -178,13 +178,12 @@ ivas_error init_decoder_fx( st_fx->hBWE_FD_HR = NULL; } set16_fx( st_fx->mem_syn1_fx, 0, M ); - move16(); set16_fx( st_fx->mem_syn2_fx, 0, M ); - st_fx->stab_fac_fx = 0; + st_fx->stab_fac_fx = 0; // Q15 move16(); - st_fx->stab_fac_smooth_fx = 0; + st_fx->stab_fac_smooth_fx = 0; // Q15 move16(); - set16_fx( st_fx->agc_mem_fx, 0, 2 ); + set16_fx( st_fx->agc_mem_fx, 0, 2 ); // Q0 set32_fx( st_fx->L_mem_hp_out_fx, 0, 5 ); set16_fx( st_fx->mem_syn3_fx, 0, M ); @@ -197,7 +196,7 @@ ivas_error init_decoder_fx( move16(); st_fx->GSC_noisy_speech = 0; move16(); - st_fx->last_voice_factor_fx = 0; + st_fx->last_voice_factor_fx = 0; // Q6 move16(); set16_fx( st_fx->prev_lpc_wb_fx, 0, LPC_SHB_ORDER_WB ); @@ -251,30 +250,31 @@ ivas_error init_decoder_fx( } Init_post_filter_fx( st_fx->hPFstat ); - st_fx->psf_lp_noise_fx = 0; + st_fx->psf_lp_noise_fx = 0; // Q8 + move16(); } ELSE { st_fx->hPFstat = NULL; } - st_fx->psf_lp_noise_fx = 0; + st_fx->psf_lp_noise_fx = 0; // Q8 move16(); /* FEC */ st_fx->scaling_flag = 0; move16(); - st_fx->lp_ener_FEC_av = 500000; + st_fx->lp_ener_FEC_av = 500000; // Q0 move32(); - st_fx->lp_ener_FEC_max = 500000; + st_fx->lp_ener_FEC_max = 500000; // Q0 move32(); st_fx->prev_bfi = 0; move16(); - st_fx->lp_ener_FER_fx = 15360; - move16(); /*60 in Q8*/ - st_fx->old_enr_LP = 0; + st_fx->lp_ener_FER_fx = 15360; // Q8 + move16(); /*60 in Q8*/ + st_fx->old_enr_LP = 0; // Q5 move16(); - st_fx->lp_ener_fx = L_deposit_l( 0 ); - st_fx->enr_old_fx = L_deposit_l( 0 ); + st_fx->lp_ener_fx = L_deposit_l( 0 ); // Q6 + st_fx->enr_old_fx = L_deposit_l( 0 ); // Q0 st_fx->bfi_pitch_fx = L_SUBFR_Q6; move16(); st_fx->bfi_pitch_frame = L_SUBFR; @@ -287,8 +287,8 @@ ivas_error init_decoder_fx( FOR( i = 0; i < 2 * NB_SUBFR16k; i++ ) { - st_fx->old_pitch_buf_fx[i] = L_SUBFR << 16; - move32(); /*15Q16*/ + st_fx->old_pitch_buf_fx[i] = L_SUBFR << 16; // Q16 + move32(); /*15Q16*/ } st_fx->upd_cnt = MAX_UPD_CNT; @@ -315,12 +315,12 @@ ivas_error init_decoder_fx( move16(); st_fx->act_count = 3; move16(); - Copy( st_fx->lsp_old_fx, st_fx->lspold_s_fx, M ); + Copy( st_fx->lsp_old_fx, st_fx->lspold_s_fx, M ); // Q15 st_fx->noimix_seed = RANDOM_INITSEED; move16(); - st_fx->min_alpha_fx = 32767; - move16(); /*1; Q15*/ - st_fx->exc_pe_fx = 0; + st_fx->min_alpha_fx = 32767; // Q15 + move16(); /*1; Q15*/ + st_fx->exc_pe_fx = 0; // Q_stat_noise move16(); #ifdef MSAN_FIX st_fx->Q_stat_noise = 31; @@ -370,14 +370,14 @@ ivas_error init_decoder_fx( move16(); /* RXDTX handeler previous frametype flag for G.192 format AMRWB SID_FIRST detection */ st_fx->first_CNG = 0; move16(); - Copy( st_fx->lsp_old_fx, st_fx->lspCNG_fx, M ); - st_fx->shb_cng_ener_fx = -1541; + Copy( st_fx->lsp_old_fx, st_fx->lspCNG_fx, M ); // Q15 + st_fx->shb_cng_ener_fx = -1541; // Q8 move16(); - st_fx->wb_cng_ener_fx = -1541; + st_fx->wb_cng_ener_fx = -1541; // Q8 move16(); - st_fx->last_wb_cng_ener_fx = -1541; + st_fx->last_wb_cng_ener_fx = -1541; // Q8 move16(); - st_fx->last_shb_cng_ener_fx = -1541; + st_fx->last_shb_cng_ener_fx = -1541; // Q8 move16(); st_fx->swb_cng_seed = RANDOM_INITSEED; move16(); @@ -388,13 +388,12 @@ ivas_error init_decoder_fx( move32(); st_fx->last_CNG_L_frame = L_FRAME; move16(); - move16(); FOR( i = 0; i < LPC_SHB_ORDER; i++ ) { - st_fx->lsp_shb_prev_fx[i] = lsp_shb_prev_tbl_fx[i]; + st_fx->lsp_shb_prev_fx[i] = lsp_shb_prev_tbl_fx[i]; // Q15 move16(); - st_fx->lsp_shb_prev_prev_fx[i] = st_fx->lsp_shb_prev_fx[i]; + st_fx->lsp_shb_prev_prev_fx[i] = st_fx->lsp_shb_prev_fx[i]; // Q15 move16(); } @@ -404,12 +403,12 @@ ivas_error init_decoder_fx( move16(); st_fx->trans_cnt_fx = 0; move16(); - st_fx->last_shb_ener_fx = 0; + st_fx->last_shb_ener_fx = 0; // Q8 move16(); /* HF (6-7kHz) BWE */ move16(); - st_fx->Q_stat_noise_ge = GE_SHIFT; + st_fx->Q_stat_noise_ge = GE_SHIFT; // Q of ge_sm_fx move16(); st_fx->cngTDLevel = 0; move16(); @@ -448,15 +447,12 @@ ivas_error init_decoder_fx( ELSE { st_fx->hHQ_nbfec = NULL; - move16(); } } ELSE { st_fx->hHQ_core = NULL; st_fx->hHQ_nbfec = NULL; - move16(); - move16(); } st_fx->Qprev_synth_buffer_fx = 15; move16(); @@ -521,7 +517,7 @@ ivas_error init_decoder_fx( move16(); move16(); - st_fx->tilt_wb_fx = 0; + st_fx->tilt_wb_fx = 0; // Q11 move16(); set16_fx( st_fx->prev_synth_buffer_fx, 0, NS2SA_FX2( 48000, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS ) ); @@ -557,14 +553,14 @@ ivas_error init_decoder_fx( st_fx->hBWE_TD = NULL; } - st_fx->tilt_swb_fx = 0; + st_fx->tilt_swb_fx = 0; // Q24 move16(); - st_fx->tilt_wb_fx = 0; + st_fx->tilt_wb_fx = 0; // Q11 move16(); - st_fx->prev_ener_shb_fx = 0; + st_fx->prev_ener_shb_fx = 0; // Q1 move16(); - st_fx->prev_enerLH_fx = 0; + st_fx->prev_enerLH_fx = 0; // Q1 move16(); st_fx->enerLH_fx = L_deposit_l( 0 ); st_fx->enerLL_fx = L_deposit_l( 0 ); @@ -578,7 +574,7 @@ ivas_error init_decoder_fx( move16(); st_fx->bws_cnt1 = N_NS2W_FRAMES; move16(); - st_fx->attenu_fx = 3277; + st_fx->attenu_fx = 3277; // Q15 move16(); st_fx->last_inner_frame = L_FRAME8k; move16(); @@ -1038,7 +1034,7 @@ ivas_error init_decoder_ivas_fx( FOR( i = 0; i < 2 * NB_SUBFR16k; i++ ) { - st_fx->old_pitch_buf_fx[i] = L_shl( L_SUBFR, 16 ); /*15Q16*/ + st_fx->old_pitch_buf_fx[i] = L_SUBFR << 16; /*15Q16*/ move32(); } @@ -1077,7 +1073,7 @@ ivas_error init_decoder_ivas_fx( st_fx->prev_coder_type = GENERIC; move16(); - st_fx->tilt_wb_fx = 0; + st_fx->tilt_wb_fx = 0; // Q11 move16(); st_fx->last_voice_factor_fx = 0; @@ -1341,11 +1337,11 @@ ivas_error init_decoder_ivas_fx( * WB/SWB bandwidth switching parameters *-----------------------------------------------------------------*/ - st_fx->tilt_swb_fx = 0; + st_fx->tilt_swb_fx = 0; // Q24 move16(); - st_fx->prev_ener_shb_fx = 0; + st_fx->prev_ener_shb_fx = 0; // Q1 move16(); - st_fx->prev_enerLH_fx = 0; + st_fx->prev_enerLH_fx = 0; // Q1 move16(); st_fx->enerLH_fx = L_deposit_l( 0 ); st_fx->enerLL_fx = L_deposit_l( 0 ); @@ -1359,7 +1355,7 @@ ivas_error init_decoder_ivas_fx( move16(); st_fx->bws_cnt1 = N_NS2W_FRAMES; move16(); - st_fx->attenu_fx = 3277; + st_fx->attenu_fx = 3277; // Q15 move16(); st_fx->last_inner_frame = L_FRAME8k; move16(); diff --git a/lib_dec/inov_dec_fx.c b/lib_dec/inov_dec_fx.c index 05f7f9809..96ebf8ec7 100644 --- a/lib_dec/inov_dec_fx.c +++ b/lib_dec/inov_dec_fx.c @@ -41,16 +41,16 @@ void inov_decode_fx( Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word32 core_brate, /* i : core bitrate */ - const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ - const Word16 L_frame, /* i : length of the frame */ - const Word16 sharpFlag, /* i : formant sharpening flag */ - const Word16 i_subfr, /* i : subframe index */ + const Word32 core_brate, /* i : core bitrate Q0 */ + const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode Q0 */ + const Word16 L_frame, /* i : length of the frame Q0 */ + const Word16 sharpFlag, /* i : formant sharpening flag Q0 */ + const Word16 i_subfr, /* i : subframe index Q0 */ const Word16 *p_Aq, /* i : LP filter coefficients Q12 */ const Word16 tilt_code, /* i : tilt of the excitation of previous subframe Q15 */ const Word16 pt_pitch, /* i : pointer to current subframe fractional pitch Q6*/ - Word16 *code, /* o : algebraic excitation */ - const Word16 L_subfr /* i : subframe length */ + Word16 *code, /* o : algebraic excitation Q12 */ + const Word16 L_subfr /* i : subframe length Q0 */ ) { Word16 nBits; @@ -85,7 +85,7 @@ void inov_decode_fx( { IF( EQ_16( L_subfr, 2 * L_SUBFR ) ) { - nBits = st_fx->acelp_cfg.fixed_cdk_index[i_subfr / L_subfr]; + nBits = st_fx->acelp_cfg.fixed_cdk_index[i_subfr / L_subfr]; // Q0 move16(); IF( EQ_16( nBits, 8 ) ) @@ -110,19 +110,19 @@ void inov_decode_fx( } ELSE { - wordcnt = shr( ACELP_FIXED_CDK_BITS( st_fx->acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR] ), 4 ); + wordcnt = shr( ACELP_FIXED_CDK_BITS( st_fx->acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR] ), 4 ); // Q0 move16(); - bitcnt = s_and( ACELP_FIXED_CDK_BITS( st_fx->acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR] ), 15 ); + bitcnt = s_and( ACELP_FIXED_CDK_BITS( st_fx->acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR] ), 15 ); // Q0 move16(); // PMT("CONDITION above is missing -> idchan") FOR( i = 0; i < wordcnt; i++ ) { - indexing_indices[i] = extract_l( get_next_indice_fx( st_fx, 16 ) ); + indexing_indices[i] = extract_l( get_next_indice_fx( st_fx, 16 ) ); // Q0 move16(); } IF( bitcnt ) { - indexing_indices[i] = extract_l( get_next_indice_fx( st_fx, bitcnt ) ); + indexing_indices[i] = extract_l( get_next_indice_fx( st_fx, bitcnt ) ); // Q0 move16(); } config = PulseConfTable[st_fx->acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR]]; @@ -136,7 +136,7 @@ void inov_decode_fx( } ELSE { - nBits = st_fx->acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR]; + nBits = st_fx->acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR]; // Q0 move16(); IF( EQ_16( nBits, 7 ) ) @@ -226,16 +226,16 @@ void inov_decode_fx( void inov_decode_ivas_fx( Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word32 core_brate, /* i : core bitrate */ - const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ - const Word16 L_frame, /* i : length of the frame */ - const Word16 sharpFlag, /* i : formant sharpening flag */ - const Word16 i_subfr, /* i : subframe index */ + const Word32 core_brate, /* i : core bitrate Q0 */ + const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode Q0 */ + const Word16 L_frame, /* i : length of the frame Q0 */ + const Word16 sharpFlag, /* i : formant sharpening flag Q0 */ + const Word16 i_subfr, /* i : subframe index Q0 */ const Word16 *p_Aq, /* i : LP filter coefficients Q12 */ const Word16 tilt_code, /* i : tilt of the excitation of previous subframe Q15 */ const Word16 pt_pitch, /* i : pointer to current subframe fractional pitch Q6*/ - Word16 *code, /* o : algebraic excitation */ - const Word16 L_subfr /* i : subframe length */ + Word16 *code, /* o : algebraic excitation Q12 */ + const Word16 L_subfr /* i : subframe length Q0 */ ) { Word16 nBits; @@ -270,7 +270,8 @@ void inov_decode_ivas_fx( { IF( EQ_16( L_subfr, 2 * L_SUBFR ) ) { - nBits = st_fx->acelp_cfg.fixed_cdk_index[i_subfr / L_subfr]; + nBits = st_fx->acelp_cfg.fixed_cdk_index[i_subfr / L_subfr]; // Q0 + move16(); IF( EQ_16( nBits, 8 ) ) { @@ -281,7 +282,7 @@ void inov_decode_ivas_fx( dec_acelp_fast_fx( st_fx, nBits, code, L_subfr ); } } - ELSE IF( ( EQ_16( st_fx->idchan, 1 ) && LE_16( st_fx->acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR], 7 ) ) || ( EQ_16( st_fx->idchan, 0 ) && LE_16( st_fx->acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR], 3 ) ) ) + ELSE IF( ( EQ_16( st_fx->idchan, 1 ) && LE_16( st_fx->acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR], 7 ) ) || ( ( st_fx->idchan == 0 ) && LE_16( st_fx->acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR], 3 ) ) ) { IF( st_fx->acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR] == 0 ) { @@ -294,18 +295,20 @@ void inov_decode_ivas_fx( } ELSE { - wordcnt = shr( ACELP_FIXED_CDK_BITS( st_fx->acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR] ), 4 ); + wordcnt = shr( ACELP_FIXED_CDK_BITS( st_fx->acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR] ), 4 ); // Q0 move16(); - bitcnt = ACELP_FIXED_CDK_BITS( st_fx->acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR] ) & 15; + bitcnt = s_and( ACELP_FIXED_CDK_BITS( st_fx->acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR] ), 15 ); // Q0 move16(); // PMT("CONDITION above is missing -> idchan") FOR( i = 0; i < wordcnt; i++ ) { - indexing_indices[i] = get_next_indice_fx( st_fx, 16 ); + indexing_indices[i] = get_next_indice_fx( st_fx, 16 ); // Q0 + move16(); } IF( bitcnt ) { - indexing_indices[i] = get_next_indice_fx( st_fx, bitcnt ); + indexing_indices[i] = get_next_indice_fx( st_fx, bitcnt ); // Q0 + move16(); } config = PulseConfTable[st_fx->acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR]]; D_ACELP_indexing_fx( code, config, NB_TRACK_FCB_4T, indexing_indices, &st_fx->BER_detect ); @@ -318,7 +321,7 @@ void inov_decode_ivas_fx( } ELSE { - nBits = st_fx->acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR]; + nBits = st_fx->acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR]; // Q0 move16(); IF( EQ_16( nBits, 7 ) ) diff --git a/lib_dec/ivas_mono_dmx_renderer.c b/lib_dec/ivas_mono_dmx_renderer.c index 57a658f4b..b6c8d0273 100644 --- a/lib_dec/ivas_mono_dmx_renderer.c +++ b/lib_dec/ivas_mono_dmx_renderer.c @@ -213,7 +213,7 @@ void ivas_mono_downmix_render_passive( #else void ivas_mono_downmix_render_passive_fx( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ - Word32 *output_f_fx[], /* i/o: synthesized core-coder transport channels/mono output */ + Word32 *output_f_fx[], /* i/o: synthesized core-coder transport channels/mono output Qin = 11/ Qout = 8*/ const Word16 output_frame /* i : output frame length */ ) { @@ -353,7 +353,7 @@ void ivas_mono_downmix_render_passive_fx( } ELSE { - eq_fx = 16384; + eq_fx = 16384; // 0.5.Q15 move16(); } @@ -415,7 +415,7 @@ void ivas_mono_stereo_downmix_mcmasa( #else void ivas_mono_stereo_downmix_mcmasa_fx( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ - Word32 *output_f_fx[], /* i/o: synthesized core-coder transport channels/mono or stereo output */ + Word32 *output_f_fx[], /* i/o: synthesized core-coder transport channels/mono or stereo output Q11*/ Word16 output_frame /* i : output frame length per channel */ ) { @@ -429,8 +429,8 @@ void ivas_mono_stereo_downmix_mcmasa_fx( test(); IF( EQ_16( st_ivas->hDecoderConfig->nchan_out, 2 ) && st_ivas->hOutSetup.separateChannelEnabled ) { - v_multc_acc_32_16( output_f_fx[st_ivas->hOutSetup.separateChannelIndex], INV_SQRT2_FX_Q15, output_f_fx[0], output_frame ); - v_multc_acc_32_16( output_f_fx[st_ivas->hOutSetup.separateChannelIndex], INV_SQRT2_FX_Q15, output_f_fx[1], output_frame ); + v_multc_acc_32_16( output_f_fx[st_ivas->hOutSetup.separateChannelIndex], INV_SQRT2_FX_Q15, output_f_fx[0], output_frame ); // Q11 + v_multc_acc_32_16( output_f_fx[st_ivas->hOutSetup.separateChannelIndex], INV_SQRT2_FX_Q15, output_f_fx[1], output_frame ); // Q11 } /* Mono downmix */ ELSE IF( EQ_16( st_ivas->hDecoderConfig->nchan_out, 1 ) ) @@ -438,7 +438,7 @@ void ivas_mono_stereo_downmix_mcmasa_fx( /* Downmix L and R to dmx_tmp */ FOR( i = 0; i < st_ivas->nchan_transport; i++ ) { - v_multc_acc_32_16( output_f_fx[i], INV_SQRT2_FX_Q15, dmx_tmp_fx, output_frame ); + v_multc_acc_32_16( output_f_fx[i], INV_SQRT2_FX_Q15, dmx_tmp_fx, output_frame ); // Q11 } /* Add center channel */ IF( st_ivas->hOutSetup.separateChannelEnabled ) @@ -447,7 +447,7 @@ void ivas_mono_stereo_downmix_mcmasa_fx( } /* Move to output */ - Copy32( dmx_tmp_fx, output_f_fx[0], output_frame ); + Copy32( dmx_tmp_fx, output_f_fx[0], output_frame ); // Q11 } return; @@ -483,13 +483,13 @@ void ivas_apply_non_diegetic_panning( #else void ivas_apply_non_diegetic_panning_fx( Word32 *output_f_fx[], /* i/o: core-coder transport mono channel/stereo output */ - const Word16 non_diegetic_pan_gain_fx, /* i : non-diegetic panning gain */ - const Word16 output_frame /* i : output frame length per channel */ + const Word16 non_diegetic_pan_gain_fx, /* i : non-diegetic panning gain Q15*/ + const Word16 output_frame /* i : output frame length per channel Q11*/ ) { Word16 pan_left_fx, pan_right_fx; - pan_left_fx = add( mult( non_diegetic_pan_gain_fx, 16348 ), 16348 ); + pan_left_fx = add( mult( non_diegetic_pan_gain_fx, 16384 ), 16384 ); // 0.5.Q15 = 16384 pan_right_fx = sub( 32767, pan_left_fx ); v_multc_fixed( output_f_fx[0], L_shl( L_deposit_l( pan_right_fx ), 16 ), output_f_fx[1], output_frame ); diff --git a/lib_dec/ivas_objectRenderer_internal.c b/lib_dec/ivas_objectRenderer_internal.c index ecc449182..e304edf6c 100644 --- a/lib_dec/ivas_objectRenderer_internal.c +++ b/lib_dec/ivas_objectRenderer_internal.c @@ -95,7 +95,7 @@ ivas_error ivas_td_binaural_open( #ifdef IVAS_FLOAT_FIXED ivas_error ivas_td_binaural_renderer_fx( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ - Word32 *output[], /* i/o: SCE channels / Binaural synthesis */ + Word32 *output[], /* i/o: SCE channels / Binaural synthesis Q11*/ const Word16 output_frame /* i : output frame length */ ) { @@ -169,9 +169,9 @@ ivas_error ivas_td_binaural_renderer( #ifdef IVAS_FLOAT_FIXED ivas_error ivas_td_binaural_renderer_sf_fx( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ - Word32 *output_fx[], /* i/o: SCE channels / Binaural synthesis */ - const int16_t n_samples_granularity /* i : granularity of the renderer/buffer */ + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + Word32 *output_fx[], /* i/o: SCE channels / Binaural synthesis Q11*/ + const Word16 n_samples_granularity /* i : granularity of the renderer/buffer */ ) { Word16 first_sf, last_sf, subframe_idx; @@ -245,7 +245,7 @@ ivas_error ivas_td_binaural_renderer_sf_fx( FOR( ch = 0; ch < st_ivas->hDecoderConfig->nchan_out; ch++ ) { - output_fx_local[ch] = output_fx[ch]; + output_fx_local[ch] = output_fx[ch]; // Q11 } slot_size = st_ivas->hTcBuffer->n_samples_granularity; @@ -342,7 +342,7 @@ ivas_error ivas_td_binaural_renderer_sf_fx( scale_sig32( tc_local_fx[i], st_ivas->hReverb->full_block_size, -4 ); // Q11 - 4 = Q7 } - IF( NE_32( ( error = ivas_reverb_process_fx( st_ivas->hReverb, st_ivas->transport_config, 0, tc_local_fx, p_reverb_signal_fx, 0 ) ), IVAS_ERR_OK ) ) + IF( NE_32( ( error = ivas_reverb_process_fx( st_ivas->hReverb, st_ivas->transport_config, 0, tc_local_fx, p_reverb_signal_fx, 0 ) ), IVAS_ERR_OK ) ) // Q(p_reverb_signal_fx) = 11 { return error; } @@ -370,7 +370,7 @@ ivas_error ivas_td_binaural_renderer_sf_fx( IF( st_ivas->hRenderConfig != NULL && EQ_32( st_ivas->hIntSetup.output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) ) { /* add reverb to rendered signals */ - v_add_32( reverb_signal_fx[0], output_fx_local[0], output_fx_local[0], output_frame ); + v_add_32( reverb_signal_fx[0], output_fx_local[0], output_fx_local[0], output_frame ); // Q11 v_add_32( reverb_signal_fx[1], output_fx_local[1], output_fx_local[1], output_frame ); } diff --git a/lib_dec/ivas_omasa_dec.c b/lib_dec/ivas_omasa_dec.c index bb0e65b26..4771a8055 100644 --- a/lib_dec/ivas_omasa_dec.c +++ b/lib_dec/ivas_omasa_dec.c @@ -131,16 +131,16 @@ ivas_error ivas_omasa_data_open_fx( { hMasaIsmData->ismPreprocMatrix_fx[ch][ch][bin] = 32767; /* 1.0f in Q15 */ move16(); - hMasaIsmData->ismPreprocMatrix_fx[1 - ch][ch][bin] = 0; + hMasaIsmData->ismPreprocMatrix_fx[1 - ch][ch][bin] = 0; // Q15 move16(); - hMasaIsmData->eneMoveIIR_fx[ch][bin] = 0; + hMasaIsmData->eneMoveIIR_fx[ch][bin] = 0; // Q22 move32(); - hMasaIsmData->enePreserveIIR_fx[ch][bin] = 0; + hMasaIsmData->enePreserveIIR_fx[ch][bin] = 0; // Q22 move32(); } - hMasaIsmData->preprocEneTarget_fx[bin] = 0; + hMasaIsmData->preprocEneTarget_fx[bin] = 0; // Q19 move32(); - hMasaIsmData->preprocEneRealized_fx[bin] = 0; + hMasaIsmData->preprocEneRealized_fx[bin] = 0; // Q19 move32(); } @@ -152,9 +152,9 @@ ivas_error ivas_omasa_data_open_fx( { hMasaIsmData->ism_is_edited[ch] = 0; move16(); - hMasaIsmData->q_elevation_old_fx[ch] = 0; + hMasaIsmData->q_elevation_old_fx[ch] = 0; // Q22 move32(); - hMasaIsmData->q_azimuth_old_fx[ch] = 0; + hMasaIsmData->q_azimuth_old_fx[ch] = 0; // Q22 move32(); } @@ -227,7 +227,7 @@ void ivas_omasa_data_close_fx( { FOR( i = 0; i < ( *hMasaIsmData )->delayBuffer_nchan; i++ ) { - free( ( *hMasaIsmData )->delayBuffer_fx[i] ); + free( ( *hMasaIsmData )->delayBuffer_fx[i] ); // Q11 } free( ( *hMasaIsmData )->delayBuffer_fx ); ( *hMasaIsmData )->delayBuffer_fx = NULL; @@ -253,7 +253,7 @@ ivas_error ivas_omasa_dec_config_fx( UWord16 *nSamplesRendered, /* o : number of samples flushed from the previous frame (JBM) */ Word16 *num_src, Word16 SrcInd[MAX_NUM_TDREND_CHANNELS], - Word16 *data /* o : output synthesis signal */ + Word16 *data /* o : output synthesis signal Qx*/ ) { Word16 k, sce_id, nSCE_old, nchan_hp20_old, numCldfbAnalyses_old, numCldfbSyntheses_old, n_MD; @@ -362,14 +362,14 @@ ivas_error ivas_omasa_dec_config_fx( FOR( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ ) { - ism_total_brate = L_add( ism_total_brate, sep_object_brate[sub( k, 2 )][sub( st_ivas->nSCE, 1 )] ); + ism_total_brate = L_add( ism_total_brate, sep_object_brate[k - 2][st_ivas->nSCE - 1] ); } brate_SCE = 0; move32(); IF( st_ivas->nSCE > 0 ) { - brate_SCE = sep_object_brate[sub( k, 2 )][sub( st_ivas->nSCE, 1 )]; + brate_SCE = sep_object_brate[k - 2][st_ivas->nSCE - 1]; move32(); } brate_CPE = L_sub( ivas_total_brate, ism_total_brate ); @@ -954,7 +954,7 @@ void ivas_set_surplus_brate_dec( tmp = idiv1616( bits_ism, st_ivas->nchan_ism ); } set16_fx( bits_element, tmp, st_ivas->nchan_ism ); - bits_element[sub( st_ivas->nchan_ism, 1 )] = add( bits_element[sub( st_ivas->nchan_ism, 1 )], bits_ism % st_ivas->nchan_ism ); + bits_element[st_ivas->nchan_ism - 1] = add( bits_element[st_ivas->nchan_ism - 1], bits_ism % st_ivas->nchan_ism ); move16(); bitbudget_to_brate( bits_element, element_brate, st_ivas->nchan_ism ); @@ -1136,12 +1136,12 @@ ivas_error ivas_omasa_ism_metadata_dec_fx( { // azimuth_ism = (int16_t) ( st_ivas->hIsmMetaData[n]->azimuth + 0.5f ); // elevation_ism = (int16_t) ( st_ivas->hIsmMetaData[n]->elevation + 0.5f ); - azimuth_ism = extract_l( L_shr_r( L_abs( st_ivas->hIsmMetaData[n]->azimuth_fx ), 22 ) ); + azimuth_ism = extract_l( L_shr_r( L_abs( st_ivas->hIsmMetaData[n]->azimuth_fx /*Q22*/ ), 22 ) ); // Q0 if ( st_ivas->hIsmMetaData[n]->azimuth_fx < 0 ) { azimuth_ism = negate( azimuth_ism ); } - elevation_ism = extract_l( L_shr_r( L_abs( st_ivas->hIsmMetaData[n]->elevation_fx ), 22 ) ); + elevation_ism = extract_l( L_shr_r( L_abs( st_ivas->hIsmMetaData[n]->elevation_fx /*Q22*/ ), 22 ) ); // Q0 if ( st_ivas->hIsmMetaData[n]->elevation_fx < 0 ) { elevation_ism = negate( elevation_ism ); @@ -1243,7 +1243,7 @@ void ivas_omasa_dirac_rend_jbm_fx( UWord16 *nSamplesRendered, /* o : number of samples rendered */ UWord16 *nSamplesAvailable, /* o : number of samples still to render */ const Word16 nchan_transport, /* i : number of transport channels */ - Word32 *output_f[] /* o : rendered time signal */ + Word32 *output_f[] /* o : rendered time signal Q11*/ ) { Word16 subframes_rendered; @@ -1367,15 +1367,15 @@ ivas_error ivas_omasa_dirac_td_binaural_jbm_fx( UWord16 *nSamplesRendered, /* o : number of samples rendered */ UWord16 *nSamplesAvailable, /* o : number of samples still to render */ const Word16 nchan_transport, /* i : number of transport channels */ - Word32 *output_fx[] /* o : rendered time signal */ + Word32 *output_fx[] /* o : rendered time signal Q11*/ ) { Word16 n; - Word16 gain_fx = OMASA_TDREND_MATCHING_GAIN_FX; + Word16 gain_fx = OMASA_TDREND_MATCHING_GAIN_FX; // Q15 move16(); ivas_error error; Word32 *tc_local_fx[MAX_TRANSPORT_CHANNELS]; - Word32 *p_sepobj_fx[MAX_NUM_OBJECTS]; + Word32 *p_sepobj_fx[MAX_NUM_OBJECTS]; // Q11 Word32 data_separated_objects_fx[MAX_NUM_OBJECTS][L_FRAME48k]; move16(); @@ -1393,7 +1393,7 @@ ivas_error ivas_omasa_dirac_td_binaural_jbm_fx( FOR( n = 0; n < st_ivas->nchan_ism; n++ ) { - tc_local_fx[n] = st_ivas->hTcBuffer->tc_fx[n + 2]; + tc_local_fx[n] = st_ivas->hTcBuffer->tc_fx[n + 2]; // Q11 v_multc_fixed_16( tc_local_fx[n], gain_fx, tc_local_fx[n], tcBufferSize ); delay_signal_fx( tc_local_fx[n], tcBufferSize, st_ivas->hMasaIsmData->delayBuffer_fx[n], st_ivas->hMasaIsmData->delayBuffer_size ); @@ -1449,13 +1449,13 @@ void ivas_omasa_rearrange_channels( } #else void ivas_omasa_rearrange_channels_fx( - Word32 *output[], /* o : output synthesis signal */ + Word32 *output[], /* o : output synthesis signal Q11*/ const Word16 nchan_transport_ism, /* o : number of ISM TCs */ const Word16 output_frame /* i : output frame length per channel */ ) { Word16 n; - Word32 tmp_buff[CPE_CHANNELS][L_FRAME48k]; + Word32 tmp_buff[CPE_CHANNELS][L_FRAME48k]; // Q11 Copy32( output[0], tmp_buff[0], output_frame ); Copy32( output[1], tmp_buff[1], output_frame ); diff --git a/lib_dec/ivas_osba_dec.c b/lib_dec/ivas_osba_dec.c index b45bd339c..d5fc88441 100644 --- a/lib_dec/ivas_osba_dec.c +++ b/lib_dec/ivas_osba_dec.c @@ -199,7 +199,7 @@ ivas_error ivas_osba_dirac_td_binaural_jbm_fx( const UWord16 nSamplesAsked, /* i : number of CLDFB slots requested */ UWord16 *nSamplesRendered, /* o : number of CLDFB slots rendered */ UWord16 *nSamplesAvailable, /* o : number of CLDFB slots still to render */ - Word32 *output_fx[], /* o : rendered time signal */ + Word32 *output_fx[], /* o : rendered time signal Q11*/ Word16 out_len /*Store the length of values in each channel*/ ) { @@ -232,7 +232,7 @@ ivas_error ivas_osba_dirac_td_binaural_jbm_fx( Word16 i; FOR( i = 0; i < nSamplesAsked; i++ ) { - output_fx[n][i] = L_add( L_shr( output_fx[add( channel_offset, n )][i], 1 ), L_shr( p_sepobj_fx[n][i], 1 ) ); + output_fx[n][i] = L_add( L_shr( output_fx[channel_offset + n][i], 1 ), L_shr( p_sepobj_fx[n][i], 1 ) ); move32(); } } @@ -355,7 +355,7 @@ ivas_error ivas_osba_render_sf_fx( const UWord16 nSamplesAsked, /* i : number of CLDFB slots requested */ UWord16 *nSamplesRendered, /* o : number of CLDFB slots rendered */ UWord16 *nSamplesAvailableNext, /* o : number of CLDFB slots still to render */ - Word32 *p_output[] /* o : rendered time signal */ + Word32 *p_output[] /* o : rendered time signal Q11*/ ) { Word16 n; @@ -370,7 +370,7 @@ ivas_error ivas_osba_render_sf_fx( FOR( n = 0; n < st_ivas->nchan_ism; n++ ) { - v_shr( p_output[n], Q11 - Q11, output_ism[n], nSamplesAsked ); + v_shr( p_output[n], Q11 - Q11, output_ism[n], nSamplesAsked ); // Q11 } IF( NE_32( ( error = ivas_sba_dec_render_fx( st_ivas, nSamplesAsked, nSamplesRendered, nSamplesAvailableNext, p_output, 960 ) ), IVAS_ERR_OK ) ) diff --git a/lib_dec/ivas_out_setup_conversion.c b/lib_dec/ivas_out_setup_conversion.c index d386b3c85..14da4b0fa 100644 --- a/lib_dec/ivas_out_setup_conversion.c +++ b/lib_dec/ivas_out_setup_conversion.c @@ -72,20 +72,20 @@ #ifdef IVAS_FLOAT_FIXED static void ivas_lssetupconversion_computeEQFactor_fx( - Word32 *outputEnergy, - Word32 *inputEnergy, + Word32 *outputEnergy, // Q0 + Word32 *inputEnergy, // Q0 Word32 *EQ ) { IF( GE_32( L_shr( *outputEnergy, 3 ), Mpy_32_32( LS_OUT_CONV_CLIP_FACTOR_MAX_SQ_Q28, *inputEnergy ) ) ) { - *EQ = L_shl_sat( LS_OUT_CONV_CLIP_FACTOR_MAX_Q29, 1 ); + *EQ = L_shl_sat( LS_OUT_CONV_CLIP_FACTOR_MAX_Q29, 1 ); // Q30 move32(); return; } IF( LE_32( L_shr( *outputEnergy, 3 ), Mpy_32_32( LS_OUT_CONV_CLIP_FACTOR_MIN_SQ_Q28, *inputEnergy ) ) ) { - *EQ = L_shl_sat( LS_OUT_CONV_CLIP_FACTOR_MIN_Q29, 1 ); + *EQ = L_shl_sat( LS_OUT_CONV_CLIP_FACTOR_MIN_Q29, 1 ); // Q30 move32(); return; } @@ -93,7 +93,7 @@ static void ivas_lssetupconversion_computeEQFactor_fx( test(); IF( ( *outputEnergy == 0 ) && ( *inputEnergy == 0 ) ) { - *EQ = ONE_IN_Q30; + *EQ = ONE_IN_Q30; // Q30 move32(); return; } @@ -360,7 +360,7 @@ static void get_custom_ls_conversion_matrix_fx( } ELSE { - hLsSetUpConversion->dmxMtx_fx[ch_in][ch_out] = tmp_gains[ch_out_woLFE]; + hLsSetUpConversion->dmxMtx_fx[ch_in][ch_out] = tmp_gains[ch_out_woLFE]; // Q30 move32(); } } @@ -488,12 +488,12 @@ static ivas_error get_ls_conversion_matrix_fx( { IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_MONO ) ) { - hLsSetUpConversion->dmxMtx_fx[ch_in][ch_out] = ls_conversion_cicpX_mono_fx[k][ch_out]; + hLsSetUpConversion->dmxMtx_fx[ch_in][ch_out] = ls_conversion_cicpX_mono_fx[k][ch_out]; // Q30 move32(); } ELSE { - hLsSetUpConversion->dmxMtx_fx[ch_in][ch_out] = ls_conversion_cicpX_stereo_fx[k][ch_out]; + hLsSetUpConversion->dmxMtx_fx[ch_in][ch_out] = ls_conversion_cicpX_stereo_fx[k][ch_out]; // Q30 move32(); } } @@ -520,7 +520,7 @@ static ivas_error get_ls_conversion_matrix_fx( { index = conversion_matrix_fx[k].index; move16(); - value = conversion_matrix_fx[k].value; + value = conversion_matrix_fx[k].value; // Q30 move16(); IF( index != 0 ) @@ -533,8 +533,9 @@ static ivas_error get_ls_conversion_matrix_fx( move16(); } ch_out = index % nchan_out; + move16(); - hLsSetUpConversion->dmxMtx_fx[ch_in][ch_out] = value; + hLsSetUpConversion->dmxMtx_fx[ch_in][ch_out] = value; // Q30 move32(); } } @@ -1026,14 +1027,14 @@ void ivas_ls_setup_conversion_fx( Decoder_Struct *st_ivas, /* i : IVAS decoder structure */ const Word16 input_chans, /* i : number of input channels to the renderer */ const Word16 output_frame, /* i : frame length */ - Word32 *input[], /* i : LS input/output synthesis signal */ - Word32 *output[] /* i/o: LS input/output synthesis signal */ + Word32 *input[], /* i : LS input/output synthesis signal Q16*/ + Word32 *output[] /* i/o: LS input/output synthesis signal Q16*/ ) { Word16 chInIdx, chOutIdx, idx; LSSETUP_CONVERSION_HANDLE hLsSetUpConversion; Word32 dmxCoeff, tmpVal; - Word32 output_tmp[MAX_OUTPUT_CHANNELS][L_FRAME48k]; + Word32 output_tmp[MAX_OUTPUT_CHANNELS][L_FRAME48k]; // Q16 push_wmops( "LS_Renderer" ); @@ -1207,8 +1208,8 @@ void ivas_ls_setup_conversion_process_mdct_fx( FOR( chInIdx = 0; chInIdx < inChannels; chInIdx++ ) { - x[chInIdx][0] = output[chInIdx]; - x[chInIdx][1] = output[chInIdx] + L_FRAME48k / 2; + x[chInIdx][0] = output[chInIdx]; // Q(q_output) + x[chInIdx][1] = output[chInIdx] + L_FRAME48k / 2; // Q(q_output) } /* Assign all the declared handles*/ @@ -1250,7 +1251,7 @@ void ivas_ls_setup_conversion_process_mdct_fx( FOR( chInIdx = 0; chInIdx < inChannels; chInIdx++ ) { - dmxCoeff = hLsSetUpConversion->dmxMtx_fx[chInIdx][chOutIdx]; + dmxCoeff = hLsSetUpConversion->dmxMtx_fx[chInIdx][chOutIdx]; // Q30 move32(); test(); @@ -1265,10 +1266,10 @@ void ivas_ls_setup_conversion_process_mdct_fx( /* Convert the signal resolution to TCX20 */ /* initially, set pointers to input; if conversion occurs in (sub)frame, set to convertRes */ - pTmp[0] = x[chInIdx][0]; + pTmp[0] = x[chInIdx][0]; // Q(q_output) sig[0] = pTmp[0]; pTmp[1] = x[chInIdx][1]; - sig[1] = pTmp[1]; + sig[1] = pTmp[1]; // Q(q_output) /* convert (sub)frames to higher frequency resolution */ IF( NE_16( transform_type[chInIdx][0], TCX_20 ) ) @@ -1295,7 +1296,7 @@ void ivas_ls_setup_conversion_process_mdct_fx( move32(); FOR( i = 1; i < frameSize - 1; i++ ) { - mdst[i] = L_sub( sig[0][i + 1], sig[0][i - 1] ); + mdst[i] = L_sub( sig[0][i + 1], sig[0][i - 1] ); // Q(q_output) } FOR( bandIdx = 0; bandIdx < hLsSetUpConversion->sfbCnt; bandIdx++ ) @@ -1361,9 +1362,9 @@ void ivas_ls_setup_conversion_process_mdct_fx( move32(); dmxEnergy[bandIdx] = L_add( Mpy_32_32( LS_OUT_CONV_SMOOTHING_FACTOR_Q31, dmxEnergy[bandIdx] ), Mpy_32_32( ( ONE_IN_Q31 - LS_OUT_CONV_SMOOTHING_FACTOR_Q31 ), hLsSetUpConversion->dmxEnergyPrev_fx[0][bandIdx] ) ); move32(); - hLsSetUpConversion->targetEnergyPrev_fx[0][bandIdx] = targetEnergy[bandIdx]; + hLsSetUpConversion->targetEnergyPrev_fx[0][bandIdx] = targetEnergy[bandIdx]; // exp( hLsSetUpConversion->te_prev_exp) (Q0 here) move32(); - hLsSetUpConversion->dmxEnergyPrev_fx[0][bandIdx] = dmxEnergy[bandIdx]; + hLsSetUpConversion->dmxEnergyPrev_fx[0][bandIdx] = dmxEnergy[bandIdx]; // exp( hLsSetUpConversion->dmx_prev_exp) (Q0) move32(); hLsSetUpConversion->te_prev_exp = 31; move16(); @@ -1399,7 +1400,7 @@ void ivas_ls_setup_conversion_process_mdct_fx( move16(); /* Compute Eq gains */ - ivas_lssetupconversion_computeEQFactor_fx( &targetEnergy[bandIdx], &dmxEnergy[bandIdx], &eqGain ); + ivas_lssetupconversion_computeEQFactor_fx( &targetEnergy[bandIdx], &dmxEnergy[bandIdx], &eqGain ); // Q(eqGain) = 30 FOR( binIdx = start; binIdx < stop; binIdx++ ) { x[chInIdx][0][binIdx] = Mpy_32_32( L_shl( x[chInIdx][0][binIdx], 1 ), eqGain ); // Q - 1 @@ -1870,15 +1871,16 @@ void ivas_ls_setup_conversion_process_mdct_param_mc_fx( { IF( NE_16( mct_chan_mode[idx], MCT_CHAN_MODE_IGNORE ) ) { - real_in_buffer_fx[add( i, i_mult( num_bands, idx ) )] = L_shr( sig_fx[idx][0][band], sub( max_e, x_e[idx][0] ) ); /*Setting the exponent to max_e*/ - imag_in_buffer_fx[add( i, i_mult( num_bands, idx ) )] = L_shr( mdst_fx[idx][band], sub( max_e, x_e[idx][0] ) ); /*Setting the exponent to max_e*/ + real_in_buffer_fx[i + ( num_bands * idx )] = L_shr( sig_fx[idx][0][band], sub( max_e, x_e[idx][0] ) ); /*Setting the exponent to max_e*/ + imag_in_buffer_fx[i + ( num_bands * idx )] = L_shr( mdst_fx[idx][band], sub( max_e, x_e[idx][0] ) ); /*Setting the exponent to max_e*/ move32(); move32(); } } } Word16 shift = 1; - FOR( i = 0; i < i_mult( num_bands, nchan_transport ); ++i ) + move16(); + FOR( i = 0; i < num_bands * nchan_transport; ++i ) { real_in_buffer_fx[i] = L_shr( real_in_buffer_fx[i], shift ); move32(); @@ -1898,11 +1900,13 @@ void ivas_ls_setup_conversion_process_mdct_param_mc_fx( FOR( bandIdx = 0; bandIdx < hLsSetUpConversion->sfbCnt; bandIdx++ ) { DMXEne_fx = 0; + move16(); set_zero_fx( cy_fx, MAX_CICP_CHANNELS * MAX_CICP_CHANNELS ); set_zero_fx( Nrqq_fx, MAX_OUTPUT_CHANNELS ); set_zero_fx( target_ch_ener_fx, MAX_OUTPUT_CHANNELS ); /* Step 1.2, get target channel energies for the transported format as in ivas_param_mc_get_mono_stereo_mixing_matrices(), Nrqq calculation */ ild_q_fx = hParamMC->icld_q_fx + imult1616( bandIdx, hParamMC->hMetadataPMC->ild_mapping_conf->ild_map_size_lfe ); + move16(); FOR( chInIdx = 0; chInIdx < nchan_transport_format; chInIdx++ ) { Word32 ref_ener_fx = 0; @@ -1914,7 +1918,7 @@ void ivas_ls_setup_conversion_process_mdct_param_mc_fx( { ref_channel_idx = hParamMC->hMetadataPMC->ild_mapping_conf->ref_channel_idx[chInIdx][ref_channel_cnt]; move16(); - ref_ener_fx = L_add( ref_ener_fx, cx_fx[bandIdx][add( ref_channel_idx, i_mult( ref_channel_idx, nchan_transport ) )] ); /*Exponent=output_exp*/ + ref_ener_fx = L_add( ref_ener_fx, cx_fx[bandIdx][ref_channel_idx + ( ref_channel_idx * nchan_transport )] ); /*Exponent=output_exp*/ } Word32 temp; temp = BASOP_util_Pow2( L_mult0( ild_q_fx[chInIdx], 2721 /*log2(10)*(2^13)/10*/ ), exp_in, &exp_out ); @@ -1927,17 +1931,17 @@ void ivas_ls_setup_conversion_process_mdct_param_mc_fx( { FOR( i = 0; i < nchan_transport_format; i++ ) { - target_ch_ener_fx[chOutIdx] = L_add( target_ch_ener_fx[chOutIdx], L_shl( Mpy_32_32( Nrqq_fx[i], hParamMC->ls_conv_dmx_matrix_fx[add( chOutIdx, i_mult( i, nchan_out ) )] ), 1 ) ); /*output_exp + 2*/ + target_ch_ener_fx[chOutIdx] = L_add( target_ch_ener_fx[chOutIdx], L_shl( Mpy_32_32( Nrqq_fx[i], hParamMC->ls_conv_dmx_matrix_fx[chOutIdx + ( i * nchan_out )] ), 1 ) ); /*output_exp + 2*/ move32(); } - cy_fx[add( chOutIdx, i_mult( nchan_out, chOutIdx ) )] = target_ch_ener_fx[chOutIdx]; + cy_fx[chOutIdx + ( nchan_out * chOutIdx )] = target_ch_ener_fx[chOutIdx]; move32(); } /* Step 1.4 final target energy for the band would then be the sum over the diagonal of Cy*/ FOR( chOutIdx = 0; chOutIdx < nchan_out; chOutIdx++ ) { - targetEnergy_fx[bandIdx] = L_add( targetEnergy_fx[bandIdx], cy_fx[add( chOutIdx, i_mult( nchan_out, chOutIdx ) )] ); /*exp=output_exp+2*/ + targetEnergy_fx[bandIdx] = L_add( targetEnergy_fx[bandIdx], cy_fx[chOutIdx + ( nchan_out * chOutIdx )] ); /*exp=output_exp+2*/ move32(); } @@ -2066,7 +2070,7 @@ void ivas_ls_setup_conversion_process_mdct_param_mc_fx( FOR( binIdx = start_tcx5; binIdx < stop_tcx5; binIdx++ ) { - x_fx[chInIdx][subFrameIdx][add( binIdx, shr( frameSize, 2 ) )] = L_shl( Mult_32_32( x_fx[chInIdx][subFrameIdx][add( binIdx, shr( frameSize, 2 ) )], eqGain_fx ), 1 ); + x_fx[chInIdx][subFrameIdx][binIdx + ( frameSize >> 2 )] = L_shl( Mult_32_32( x_fx[chInIdx][subFrameIdx][binIdx + ( frameSize >> 2 )], eqGain_fx ), 1 ); move32(); } } @@ -2416,8 +2420,8 @@ void ivas_ls_setup_conversion_process_mdct_param_mc( void ivas_lssetupconversion_process_param_mc_fx( Decoder_Struct *st_ivas, /* i/o: LS setup conversion renderer handle */ const Word16 num_timeslots, - Word32 Cldfb_RealBuffer_InOut[MAX_CICP_CHANNELS][PARAM_MC_MAX_NSLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX], /* i/o: LS signals */ - Word32 Cldfb_ImagBuffer_InOut[MAX_CICP_CHANNELS][PARAM_MC_MAX_NSLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX], /* i/o: LS signals */ + Word32 Cldfb_RealBuffer_InOut[MAX_CICP_CHANNELS][PARAM_MC_MAX_NSLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX], /* i/o: LS signals Q6*/ + Word32 Cldfb_ImagBuffer_InOut[MAX_CICP_CHANNELS][PARAM_MC_MAX_NSLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX], /* i/o: LS signals Q6*/ Word16 channel_active[MAX_CICP_CHANNELS] /* i : bitmap indicating which output channels are active */ ) { @@ -2463,15 +2467,15 @@ void ivas_lssetupconversion_process_param_mc_fx( { FOR( k = 0; k < hLsSetUpConversion->sfbCnt; ++k ) { - Cldfb_RealBuffer_InOut[i][slotIdx][k] = L_shl( Cldfb_RealBuffer_InOut[i][slotIdx][k], q_output ); - Cldfb_ImagBuffer_InOut[i][slotIdx][k] = L_shl( Cldfb_ImagBuffer_InOut[i][slotIdx][k], q_output ); + Cldfb_RealBuffer_InOut[i][slotIdx][k] = L_shl( Cldfb_RealBuffer_InOut[i][slotIdx][k], q_output ); // Q(6 + q_output) + Cldfb_ImagBuffer_InOut[i][slotIdx][k] = L_shl( Cldfb_ImagBuffer_InOut[i][slotIdx][k], q_output ); // Q(6 + q_output) } } /* copy buffers */ FOR( chInIdx = 0; chInIdx < inChannels; chInIdx++ ) { - Copy32( Cldfb_RealBuffer_InOut[chInIdx][slotIdx], Cldfb_RealBuffer_tmp[chInIdx], CLDFB_NO_CHANNELS_MAX ); - Copy32( Cldfb_ImagBuffer_InOut[chInIdx][slotIdx], Cldfb_ImagBuffer_tmp[chInIdx], CLDFB_NO_CHANNELS_MAX ); + Copy32( Cldfb_RealBuffer_InOut[chInIdx][slotIdx], Cldfb_RealBuffer_tmp[chInIdx], CLDFB_NO_CHANNELS_MAX ); // Q(6 + q_output) + Copy32( Cldfb_ImagBuffer_InOut[chInIdx][slotIdx], Cldfb_ImagBuffer_tmp[chInIdx], CLDFB_NO_CHANNELS_MAX ); // Q(6 + q_output) } /* set the buffers to zero */ FOR( chOutIdx = 0; chOutIdx < outChannels; chOutIdx++ ) @@ -2488,7 +2492,7 @@ void ivas_lssetupconversion_process_param_mc_fx( { FOR( chInIdx = 0; chInIdx < inChannels; chInIdx++ ) { - dmxCoeff = hLsSetUpConversion->dmxMtx_fx[chInIdx][chOutIdx]; + dmxCoeff = hLsSetUpConversion->dmxMtx_fx[chInIdx][chOutIdx]; // Q30 move32(); IF( dmxCoeff == 0 ) { @@ -2496,13 +2500,14 @@ void ivas_lssetupconversion_process_param_mc_fx( } ELSE { - channel_active[chOutIdx] |= 1; + channel_active[chOutIdx] = s_or( 1, channel_active[chOutIdx] ); + move16(); FOR( bandIdx = 0; bandIdx < hLsSetUpConversion->sfbCnt; bandIdx++ ) { - tmpDMXSig = Mpy_32_32( L_shl_sat( dmxCoeff, 1 ), Cldfb_RealBuffer_tmp[chInIdx][bandIdx] ); + tmpDMXSig = Mpy_32_32( L_shl_sat( dmxCoeff, 1 ), Cldfb_RealBuffer_tmp[chInIdx][bandIdx] ); // Q(6 + q_output) Cldfb_RealBuffer_InOut[chOutIdx][slotIdx][bandIdx] = L_add( Cldfb_RealBuffer_InOut[chOutIdx][slotIdx][bandIdx], tmpDMXSig ); move32(); - targetEnergy[chOutIdx][bandIdx] = L_add( targetEnergy[chOutIdx][bandIdx], Mpy_32_32( tmpDMXSig, tmpDMXSig ) ); + targetEnergy[chOutIdx][bandIdx] = L_add( targetEnergy[chOutIdx][bandIdx], Mpy_32_32( tmpDMXSig, tmpDMXSig ) ); // Q((6 + q_output)*2 - 31) move32(); tmpDMXSig = Mpy_32_32( L_shl_sat( dmxCoeff, 1 ), Cldfb_ImagBuffer_tmp[chInIdx][bandIdx] ); @@ -2522,12 +2527,12 @@ void ivas_lssetupconversion_process_param_mc_fx( { FOR( bandIdx = 0; bandIdx < hLsSetUpConversion->sfbCnt; bandIdx++ ) { - tmpReal = Cldfb_RealBuffer_InOut[chOutIdx][slotIdx][bandIdx]; + tmpReal = Cldfb_RealBuffer_InOut[chOutIdx][slotIdx][bandIdx]; // Q(6 + q_output) move32(); - tmpImag = Cldfb_ImagBuffer_InOut[chOutIdx][slotIdx][bandIdx]; + tmpImag = Cldfb_ImagBuffer_InOut[chOutIdx][slotIdx][bandIdx]; // Q(6 + q_output) move32(); - dmxEnergy[chOutIdx][bandIdx] = L_add( Mpy_32_32( tmpReal, tmpReal ), Mpy_32_32( tmpImag, tmpImag ) ); + dmxEnergy[chOutIdx][bandIdx] = L_add( Mpy_32_32( tmpReal, tmpReal ), Mpy_32_32( tmpImag, tmpImag ) ); // Q((6 + q_output)*2 - 31) move32(); } } @@ -2544,9 +2549,9 @@ void ivas_lssetupconversion_process_param_mc_fx( move32(); dmxEnergy[chOutIdx][bandIdx] = L_add( Mpy_32_32( LS_OUT_CONV_SMOOTHING_FACTOR_Q31, dmxEnergy[chOutIdx][bandIdx] ), Mpy_32_32( L_sub( ONE_IN_Q31, LS_OUT_CONV_SMOOTHING_FACTOR_Q31 ), hLsSetUpConversion->dmxEnergyPrev_fx[chOutIdx][bandIdx] ) ); move32(); - hLsSetUpConversion->targetEnergyPrev_fx[chOutIdx][bandIdx] = targetEnergy[chOutIdx][bandIdx]; + hLsSetUpConversion->targetEnergyPrev_fx[chOutIdx][bandIdx] = targetEnergy[chOutIdx][bandIdx]; // Q0 move32(); - hLsSetUpConversion->dmxEnergyPrev_fx[chOutIdx][bandIdx] = dmxEnergy[chOutIdx][bandIdx]; + hLsSetUpConversion->dmxEnergyPrev_fx[chOutIdx][bandIdx] = dmxEnergy[chOutIdx][bandIdx]; // Q0 move32(); hLsSetUpConversion->te_prev_exp = 31; move16(); @@ -2560,9 +2565,9 @@ void ivas_lssetupconversion_process_param_mc_fx( { FOR( k = 0; k < hLsSetUpConversion->sfbCnt; ++k ) { - Cldfb_RealBuffer_InOut[i][slotIdx][k] = L_shr( Cldfb_RealBuffer_InOut[i][slotIdx][k], q_output ); + Cldfb_RealBuffer_InOut[i][slotIdx][k] = L_shr( Cldfb_RealBuffer_InOut[i][slotIdx][k], q_output ); // Q6 move32(); - Cldfb_ImagBuffer_InOut[i][slotIdx][k] = L_shr( Cldfb_ImagBuffer_InOut[i][slotIdx][k], q_output ); + Cldfb_ImagBuffer_InOut[i][slotIdx][k] = L_shr( Cldfb_ImagBuffer_InOut[i][slotIdx][k], q_output ); // Q6 move32(); } } @@ -2574,7 +2579,7 @@ void ivas_lssetupconversion_process_param_mc_fx( { FOR( bandIdx = 0; bandIdx < hLsSetUpConversion->sfbCnt; bandIdx++ ) { - ivas_lssetupconversion_computeEQFactor_fx( &targetEnergy[chOutIdx][bandIdx], &dmxEnergy[chOutIdx][bandIdx], &EQ ); + ivas_lssetupconversion_computeEQFactor_fx( &targetEnergy[chOutIdx][bandIdx], &dmxEnergy[chOutIdx][bandIdx], &EQ ); // Q(EQ) = Q30 Cldfb_RealBuffer_InOut[chOutIdx][slotIdx][bandIdx] = Mpy_32_32( L_shl( Cldfb_RealBuffer_InOut[chOutIdx][slotIdx][bandIdx], 1 ), EQ ); move32(); Cldfb_ImagBuffer_InOut[chOutIdx][slotIdx][bandIdx] = Mpy_32_32( L_shl( Cldfb_ImagBuffer_InOut[chOutIdx][slotIdx][bandIdx], 1 ), EQ ); diff --git a/lib_dec/ivas_qmetadata_dec.c b/lib_dec/ivas_qmetadata_dec.c index 4de07342c..f213a059d 100644 --- a/lib_dec/ivas_qmetadata_dec.c +++ b/lib_dec/ivas_qmetadata_dec.c @@ -123,9 +123,9 @@ static int16_t read_coherence_data( uint16_t *bitstream, int16_t *p_bit_pos, IVA /*! r: number of bits read */ Word16 ivas_qmetadata_dec_decode( IVAS_QMETADATA_HANDLE hQMetaData, /* i/o: hQMetaData handle */ - UWord16 *bitstream, /* i : bitstream */ - Word16 *index, /* i/o: bitstream position */ - const Word16 hodirac_flag /* i : flag to indicate HO-DirAC mode */ + UWord16 *bitstream, /* i : bitstream Q0*/ + Word16 *index, /* i/o: bitstream position Q0*/ + const Word16 hodirac_flag /* i : flag to indicate HO-DirAC mode Q0*/ ) { Word16 d, b, m; @@ -171,7 +171,7 @@ Word16 ivas_qmetadata_dec_decode( IF( hQMetaData->coherence_flag ) { /* read if coherence is zero */ - all_coherence_zero = bitstream[( *index )--]; + all_coherence_zero = bitstream[( *index )--]; /*Q0*/ move16(); bits_no_dirs_coh = add( bits_no_dirs_coh, 1 ); } @@ -181,20 +181,20 @@ Word16 ivas_qmetadata_dec_decode( IF( EQ_32( hQMetaData->no_directions, 2 ) ) { /* Read which bands have 2 directions */ - hQMetaData->q_direction[1].cfg.nbands = hQMetaData->numTwoDirBands; + hQMetaData->q_direction[1].cfg.nbands = hQMetaData->numTwoDirBands; /*Q0*/ move16(); set_c( (Word8 *) hQMetaData->twoDirBands, 0, hQMetaData->q_direction[0].cfg.nbands ); d = *index; move16(); - dif_p[0] = ivas_qmetadata_DecodeExtendedGR( bitstream, index, MASA_MAXIMUM_CODING_SUBBANDS, 0 ); + dif_p[0] = ivas_qmetadata_DecodeExtendedGR( bitstream, index, MASA_MAXIMUM_CODING_SUBBANDS, 0 ); /*Q0*/ move16(); - p[0] = dif_p[0]; + p[0] = dif_p[0]; /*Q0*/ move16(); hQMetaData->twoDirBands[p[0]] = 1; move16(); FOR( b = 1; b < hQMetaData->numTwoDirBands; b++ ) { - dif_p[b] = ivas_qmetadata_DecodeExtendedGR( bitstream, index, MASA_MAXIMUM_CODING_SUBBANDS, 0 ); + dif_p[b] = ivas_qmetadata_DecodeExtendedGR( bitstream, index, MASA_MAXIMUM_CODING_SUBBANDS, 0 ); /*Q0*/ move16(); p[b] = add( add( p[b - 1], dif_p[b] ), 1 ); move16(); @@ -219,7 +219,7 @@ Word16 ivas_qmetadata_dec_decode( { IF( EQ_16( hQMetaData->twoDirBands[b], 1 ) ) { - dfRatio_bits[dir2band] = ivas_get_df_ratio_bits_hodirac( hQMetaData->q_direction[0].band_data[b].energy_ratio_index[0] ); + dfRatio_bits[dir2band] = ivas_get_df_ratio_bits_hodirac( hQMetaData->q_direction[0].band_data[b].energy_ratio_index[0] ); /*Q0*/ move16(); dir2band = add( dir2band, 1 ); } @@ -239,13 +239,13 @@ Word16 ivas_qmetadata_dec_decode( { IF( EQ_16( hQMetaData->twoDirBands[b], 1 ) ) { - dfRatio_bits[dir2band] = ivas_get_df_ratio_bits( hQMetaData->q_direction[0].band_data[b].energy_ratio_index[0] ); + dfRatio_bits[dir2band] = ivas_get_df_ratio_bits( hQMetaData->q_direction[0].band_data[b].energy_ratio_index[0] ); /*Q0*/ move16(); dir2band = add( dir2band, 1 ); } } - bits_diff_sum = add( bits_diff_sum, ivas_qmetadata_entropy_decode_df_ratio( bitstream, index, &( hQMetaData->q_direction[1] ), dfRatio_bits ) ); + bits_diff_sum = add( bits_diff_sum, ivas_qmetadata_entropy_decode_df_ratio( bitstream, index, &( hQMetaData->q_direction[1] ), dfRatio_bits ) ); /*Q0*/ } } @@ -265,14 +265,14 @@ Word16 ivas_qmetadata_dec_decode( diffRatio_fx = diffuseness_reconstructions_fx[hQMetaData->q_direction[0].band_data[b].energy_ratio_index[0]]; // Q30 move32(); - dfRatio_qsteps = shl( 1, dfRatio_bits[dir2band] ); + dfRatio_qsteps = shl( 1, dfRatio_bits[dir2band] ); /*1 << dfRatio_bits[dir2band]*/ /* already encoded as total and ratios in HO-DirAC */ IF( hodirac_flag ) { dfRatio_fx = usdequant_fx( hQMetaData->q_direction[1].band_data[dir2band].energy_ratio_index[0], 0 /* Q15 */, inv_dfRatio_qsteps[dfRatio_qsteps] ); // Q15 dir1ratio_fx = L_sub( ONE_IN_Q30, diffRatio_fx ); - dir2ratio_fx = L_shl( (Word32) dfRatio_fx, Q15 ); + dir2ratio_fx = L_shl( (Word32) dfRatio_fx, Q15 ); /*Q30*/ } ELSE { @@ -284,17 +284,17 @@ Word16 ivas_qmetadata_dec_decode( /* Requantize the 1 - dirRatio separately for each direction to obtain inverted dirRatio index. These are used in further decoding. */ - hQMetaData->q_direction[0].band_data[b].energy_ratio_index[0] = masa_sq_fx( L_sub( ONE_IN_Q30, dir1ratio_fx ), diffuseness_thresholds_fx, DIRAC_DIFFUSE_LEVELS ); + hQMetaData->q_direction[0].band_data[b].energy_ratio_index[0] = masa_sq_fx( L_sub( ONE_IN_Q30, dir1ratio_fx ), diffuseness_thresholds_fx, DIRAC_DIFFUSE_LEVELS ); /*Q0*/ move16(); IF( hodirac_flag ) { Word16 tmp_fx; - hQMetaData->q_direction[1].band_data[dir2band].energy_ratio_index[0] = usquant_fx( extract_h( dir2ratio_fx ), &tmp_fx, 0, INV_DIRAC_DIFFUSE_LEVELS_Q13, DIRAC_DIFFUSE_LEVELS ); + hQMetaData->q_direction[1].band_data[dir2band].energy_ratio_index[0] = usquant_fx( extract_h( dir2ratio_fx ), &tmp_fx, 0, INV_DIRAC_DIFFUSE_LEVELS_Q13, DIRAC_DIFFUSE_LEVELS ); /*Q0*/ move16(); } ELSE { - hQMetaData->q_direction[1].band_data[dir2band].energy_ratio_index[0] = masa_sq_fx( L_sub( ONE_IN_Q30, dir2ratio_fx ), diffuseness_thresholds_fx, DIRAC_DIFFUSE_LEVELS ); + hQMetaData->q_direction[1].band_data[dir2band].energy_ratio_index[0] = masa_sq_fx( L_sub( ONE_IN_Q30, dir2ratio_fx ), diffuseness_thresholds_fx, DIRAC_DIFFUSE_LEVELS ); /*Q0*/ move16(); } @@ -302,15 +302,15 @@ Word16 ivas_qmetadata_dec_decode( { hQMetaData->q_direction[0].band_data[b].energy_ratio_fx[m] = dir1ratio_fx; // Q30 move32(); - hQMetaData->q_direction[0].band_data[b].energy_ratio_index[m] = hQMetaData->q_direction[0].band_data[b].energy_ratio_index[0]; + hQMetaData->q_direction[0].band_data[b].energy_ratio_index[m] = hQMetaData->q_direction[0].band_data[b].energy_ratio_index[0]; /*Q0*/ move16(); } FOR( m = 0; m < hQMetaData->q_direction[1].cfg.nblocks; m++ ) { - hQMetaData->q_direction[1].band_data[dir2band].energy_ratio_fx[m] = dir2ratio_fx; + hQMetaData->q_direction[1].band_data[dir2band].energy_ratio_fx[m] = dir2ratio_fx; /*Q30*/ move32(); - hQMetaData->q_direction[1].band_data[dir2band].energy_ratio_index[m] = hQMetaData->q_direction[1].band_data[dir2band].energy_ratio_index[0]; + hQMetaData->q_direction[1].band_data[dir2band].energy_ratio_index[m] = hQMetaData->q_direction[1].band_data[dir2band].energy_ratio_index[0]; /*Q0*/ move16(); } @@ -319,13 +319,13 @@ Word16 ivas_qmetadata_dec_decode( ELSE { /* 1dir band */ - hQMetaData->q_direction[0].band_data[b].energy_ratio_fx[0] = L_sub( ONE_IN_Q30, diffuseness_reconstructions_fx[hQMetaData->q_direction[0].band_data[b].energy_ratio_index[0]] ); + hQMetaData->q_direction[0].band_data[b].energy_ratio_fx[0] = L_sub( ONE_IN_Q30, diffuseness_reconstructions_fx[hQMetaData->q_direction[0].band_data[b].energy_ratio_index[0]] ); /*Q30*/ move32(); FOR( m = 1; m < hQMetaData->q_direction[0].cfg.nblocks; m++ ) { - hQMetaData->q_direction[0].band_data[b].energy_ratio_fx[m] = hQMetaData->q_direction[0].band_data[b].energy_ratio_fx[0]; + hQMetaData->q_direction[0].band_data[b].energy_ratio_fx[m] = hQMetaData->q_direction[0].band_data[b].energy_ratio_fx[0]; /*Q30*/ move32(); - hQMetaData->q_direction[0].band_data[b].energy_ratio_index[m] = hQMetaData->q_direction[0].band_data[b].energy_ratio_index[0]; + hQMetaData->q_direction[0].band_data[b].energy_ratio_index[m] = hQMetaData->q_direction[0].band_data[b].energy_ratio_index[0]; /*Q0*/ move16(); } } @@ -336,13 +336,13 @@ Word16 ivas_qmetadata_dec_decode( /* With 1dir band, the decoded index is directly diffuseness and we can decode to direct-to-total ratio with 1 - diff. */ FOR( b = hQMetaData->q_direction[0].cfg.start_band; b < hQMetaData->q_direction[0].cfg.nbands; b++ ) { - hQMetaData->q_direction[0].band_data[b].energy_ratio_fx[0] = L_sub( ONE_IN_Q30, diffuseness_reconstructions_fx[hQMetaData->q_direction[0].band_data[b].energy_ratio_index[0]] ); + hQMetaData->q_direction[0].band_data[b].energy_ratio_fx[0] = L_sub( ONE_IN_Q30, diffuseness_reconstructions_fx[hQMetaData->q_direction[0].band_data[b].energy_ratio_index[0]] ); /*Q30*/ move32(); FOR( m = 1; m < hQMetaData->q_direction[0].cfg.nblocks; m++ ) { - hQMetaData->q_direction[0].band_data[b].energy_ratio_fx[m] = hQMetaData->q_direction[0].band_data[b].energy_ratio_fx[0]; + hQMetaData->q_direction[0].band_data[b].energy_ratio_fx[m] = hQMetaData->q_direction[0].band_data[b].energy_ratio_fx[0]; /*Q30*/ move32(); - hQMetaData->q_direction[0].band_data[b].energy_ratio_index[m] = hQMetaData->q_direction[0].band_data[b].energy_ratio_index[0]; + hQMetaData->q_direction[0].band_data[b].energy_ratio_index[m] = hQMetaData->q_direction[0].band_data[b].energy_ratio_index[0]; /*Q0*/ move16(); } } @@ -363,18 +363,18 @@ Word16 ivas_qmetadata_dec_decode( { Word16 index_dirRatio1Inv, index_dirRatio2Inv, index_dirRatio1Inv_mod, index_dirRatio2Inv_mod; - index_dirRatio1Inv = hQMetaData->q_direction[0].band_data[b].energy_ratio_index[0]; + index_dirRatio1Inv = hQMetaData->q_direction[0].band_data[b].energy_ratio_index[0]; /*Q0*/ move16(); - index_dirRatio2Inv = hQMetaData->q_direction[1].band_data[dir2band].energy_ratio_index[0]; + index_dirRatio2Inv = hQMetaData->q_direction[1].band_data[dir2band].energy_ratio_index[0]; /*Q0*/ move16(); masa_compensate_two_dir_energy_ratio_index_fx( index_dirRatio1Inv, index_dirRatio2Inv, &index_dirRatio1Inv_mod, &index_dirRatio2Inv_mod, hodirac_flag ); FOR( m = 0; m < hQMetaData->q_direction[0].cfg.nblocks; m++ ) { - hQMetaData->q_direction[0].band_data[b].energy_ratio_index_mod[m] = index_dirRatio1Inv_mod; + hQMetaData->q_direction[0].band_data[b].energy_ratio_index_mod[m] = index_dirRatio1Inv_mod; /*Q0*/ move16(); - hQMetaData->q_direction[0].band_data[b].bits_sph_idx[m] = bits_direction_masa[index_dirRatio1Inv_mod]; + hQMetaData->q_direction[0].band_data[b].bits_sph_idx[m] = bits_direction_masa[index_dirRatio1Inv_mod]; /*Q0*/ move16(); bits_dir_raw_pre[0] = add( bits_dir_raw_pre[0], hQMetaData->q_direction[0].band_data[b].bits_sph_idx[m] ); move16(); @@ -382,9 +382,9 @@ Word16 ivas_qmetadata_dec_decode( FOR( m = 0; m < hQMetaData->q_direction[1].cfg.nblocks; m++ ) { - hQMetaData->q_direction[1].band_data[dir2band].energy_ratio_index_mod[m] = index_dirRatio2Inv_mod; + hQMetaData->q_direction[1].band_data[dir2band].energy_ratio_index_mod[m] = index_dirRatio2Inv_mod; /*Q0*/ move16(); - hQMetaData->q_direction[1].band_data[dir2band].bits_sph_idx[m] = bits_direction_masa[index_dirRatio2Inv_mod]; + hQMetaData->q_direction[1].band_data[dir2band].bits_sph_idx[m] = bits_direction_masa[index_dirRatio2Inv_mod]; /*Q0*/ move16(); bits_dir_raw_pre[1] = add( bits_dir_raw_pre[1], hQMetaData->q_direction[1].band_data[dir2band].bits_sph_idx[m] ); move16(); @@ -396,9 +396,9 @@ Word16 ivas_qmetadata_dec_decode( { FOR( m = 0; m < hQMetaData->q_direction[0].cfg.nblocks; m++ ) { - hQMetaData->q_direction[0].band_data[b].energy_ratio_index_mod[m] = hQMetaData->q_direction[0].band_data[b].energy_ratio_index[0]; + hQMetaData->q_direction[0].band_data[b].energy_ratio_index_mod[m] = hQMetaData->q_direction[0].band_data[b].energy_ratio_index[0]; /*Q0*/ move16(); - hQMetaData->q_direction[0].band_data[b].bits_sph_idx[m] = bits_direction_masa[hQMetaData->q_direction[0].band_data[b].energy_ratio_index[0]]; + hQMetaData->q_direction[0].band_data[b].bits_sph_idx[m] = bits_direction_masa[hQMetaData->q_direction[0].band_data[b].energy_ratio_index[0]]; /*Q0*/ move16(); bits_dir_raw_pre[0] = add( bits_dir_raw_pre[0], hQMetaData->q_direction[0].band_data[b].bits_sph_idx[m] ); move16(); @@ -408,12 +408,12 @@ Word16 ivas_qmetadata_dec_decode( IF( EQ_32( hQMetaData->no_directions, 2 ) ) { - no_TF = add( i_mult2( hQMetaData->q_direction[0].cfg.nbands, hQMetaData->q_direction[0].cfg.nblocks ), i_mult2( hQMetaData->q_direction[1].cfg.nbands, hQMetaData->q_direction[1].cfg.nblocks ) ); - tmp32 = L_sub( L_deposit_h( sub( sub( hQMetaData->metadata_max_bits, bits_no_dirs_coh ), bits_diff_sum ) ), L_mult0( 17612 /* 4.2998046875f in Q12 */, shl( no_TF, 4 ) ) ); + no_TF = add( i_mult2( hQMetaData->q_direction[0].cfg.nbands, hQMetaData->q_direction[0].cfg.nblocks ), i_mult2( hQMetaData->q_direction[1].cfg.nbands, hQMetaData->q_direction[1].cfg.nblocks ) ); /*Q0*/ + tmp32 = L_sub( L_deposit_h( sub( sub( hQMetaData->metadata_max_bits, bits_no_dirs_coh ), bits_diff_sum ) ), L_mult0( 17612 /* 4.2998046875f in Q12 */, shl( no_TF, 4 ) ) ); /*Q16*/ test(); IF( !all_coherence_zero && GE_32( tmp32, L_deposit_h( MASA_MIN_BITS_SURR_COH ) ) ) { - bits_sur_coherence = read_surround_coherence( bitstream, index, hQMetaData ); + bits_sur_coherence = read_surround_coherence( bitstream, index, hQMetaData ); /*Q0*/ } ELSE { @@ -429,16 +429,16 @@ Word16 ivas_qmetadata_dec_decode( } } bits_no_dirs_coh = add( bits_no_dirs_coh, bits_sur_coherence ); - total_bits_1dir = extract_l( L_mult0( sub( hQMetaData->metadata_max_bits, bits_no_dirs_coh ), i_mult2( hQMetaData->q_direction[0].cfg.nbands, hQMetaData->q_direction[0].cfg.nblocks ) ) / no_TF ); + total_bits_1dir = extract_l( L_mult0( sub( hQMetaData->metadata_max_bits, bits_no_dirs_coh ), i_mult2( hQMetaData->q_direction[0].cfg.nbands, hQMetaData->q_direction[0].cfg.nblocks ) ) / no_TF ); /*Q0*/ } ELSE { - no_TF = i_mult2( hQMetaData->q_direction[0].cfg.nbands, hQMetaData->q_direction[0].cfg.nblocks ); - tmp32 = L_sub( L_deposit_h( sub( sub( hQMetaData->metadata_max_bits, bits_no_dirs_coh ), bits_diff_sum ) ), L_mult0( 17612 /* 4.2998046875f in Q12 */, shl( no_TF, 4 ) ) ); + no_TF = i_mult2( hQMetaData->q_direction[0].cfg.nbands, hQMetaData->q_direction[0].cfg.nblocks ); /*Q0*/ + tmp32 = L_sub( L_deposit_h( sub( sub( hQMetaData->metadata_max_bits, bits_no_dirs_coh ), bits_diff_sum ) ), L_mult0( 17612 /* 4.2998046875f in Q12 */, shl( no_TF, 4 ) ) ); /*Q16*/ test(); IF( !all_coherence_zero && GE_32( tmp32, L_deposit_h( MASA_MIN_BITS_SURR_COH ) ) ) { - bits_sur_coherence = read_surround_coherence( bitstream, index, hQMetaData ); + bits_sur_coherence = read_surround_coherence( bitstream, index, hQMetaData ); /*Q0*/ } ELSE { @@ -466,18 +466,18 @@ Word16 ivas_qmetadata_dec_decode( FOR( d = 0; d < hQMetaData->no_directions; d++ ) { q_direction = &hQMetaData->q_direction[d]; - nbands = q_direction->cfg.nbands; + nbands = q_direction->cfg.nbands; /*Q0*/ move16(); - nblocks = q_direction->cfg.nblocks; + nblocks = q_direction->cfg.nblocks; /*Q0*/ move16(); - start_band = q_direction->cfg.start_band; + start_band = q_direction->cfg.start_band; /*Q0*/ move16(); - diffuseness_index_max_ec_frame = diffuseness_index_max_ec_frame_pre[0]; + diffuseness_index_max_ec_frame = diffuseness_index_max_ec_frame_pre[0]; /*Q0*/ move16(); IF( d == 0 ) { - bits_diff = bits_diff_sum; + bits_diff = bits_diff_sum; /*Q0*/ move16(); } ELSE @@ -485,7 +485,7 @@ Word16 ivas_qmetadata_dec_decode( bits_diff = 0; move16(); } - bits_dir_raw = bits_dir_raw_pre[d]; + bits_dir_raw = bits_dir_raw_pre[d]; /*Q0*/ move16(); /* Read coherence, if any */ @@ -494,7 +494,7 @@ Word16 ivas_qmetadata_dec_decode( IF( all_coherence_zero == 0 ) { - bits_coherence = read_coherence_data_fx( bitstream, index, hQMetaData, d, 0 ); + bits_coherence = read_coherence_data_fx( bitstream, index, hQMetaData, d, 0 ); /*Q0*/ } ELSE { @@ -514,7 +514,7 @@ Word16 ivas_qmetadata_dec_decode( } /* Read 2D signaling*/ - q_direction->not_in_2D = bitstream[( *index )--]; + q_direction->not_in_2D = bitstream[( *index )--]; /*Q0*/ move16(); signal_bits = 1; move16(); @@ -545,7 +545,7 @@ Word16 ivas_qmetadata_dec_decode( { bits_dir = 0; move16(); - raw_flag[0] = bitstream[( *index )--]; + raw_flag[0] = bitstream[( *index )--]; /*Q0*/ move16(); bits_dir = add( bits_dir, 1 ); @@ -565,7 +565,7 @@ Word16 ivas_qmetadata_dec_decode( move16(); FOR( b = start_band; b < nbands; b++ ) { - raw_flag[b] = bitstream[( *index )--]; + raw_flag[b] = bitstream[( *index )--]; /*Q0*/ move16(); bits_dir = add( bits_dir, 1 ); } @@ -597,7 +597,7 @@ Word16 ivas_qmetadata_dec_decode( { FOR( j = 0; j < q_direction->cfg.nblocks; j++ ) { - bits_temp[i][j] = q_direction->band_data[i].bits_sph_idx[j]; + bits_temp[i][j] = q_direction->band_data[i].bits_sph_idx[j]; /*Q0*/ move16(); } } @@ -608,7 +608,7 @@ Word16 ivas_qmetadata_dec_decode( { FOR( j = 0; j < q_direction->cfg.nblocks; j++ ) { - q_direction->band_data[i].bits_sph_idx[j] = bits_temp[i][j]; + q_direction->band_data[i].bits_sph_idx[j] = bits_temp[i][j]; /*Q0*/ move16(); } } @@ -632,7 +632,7 @@ Word16 ivas_qmetadata_dec_decode( IF( hQMetaData->is_masa_ivas_format == 0 ) { - reduce_bits = sub( bits_dir_raw, sub( sub( sub( total_bits_1dir, bits_diff ), bits_coherence ), signal_bits ) ); + reduce_bits = sub( bits_dir_raw, sub( sub( sub( total_bits_1dir, bits_diff ), bits_coherence ), signal_bits ) ); /*Q0*/ ind_order[0] = -1; move16(); } @@ -640,7 +640,7 @@ Word16 ivas_qmetadata_dec_decode( { ind_order[0] = 0; move16(); - reduce_bits = s_min( add( i_mult2( nbands, nblocks ), MASA_BIT_REDUCT_PARAM ), sub( bits_dir_raw, sub( sub( sub( total_bits_1dir, bits_diff ), bits_coherence ), signal_bits ) ) ); + reduce_bits = s_min( add( i_mult2( nbands, nblocks ), MASA_BIT_REDUCT_PARAM ), sub( bits_dir_raw, sub( sub( sub( total_bits_1dir, bits_diff ), bits_coherence ), signal_bits ) ) ); /*Q0*/ IF( GT_16( reduce_bits, sub( bits_dir_raw, i_mult2( nbands, nblocks ) ) ) ) { reduce_bits = sub( bits_dir_raw, i_mult2( nbands, nblocks ) ); @@ -649,7 +649,7 @@ Word16 ivas_qmetadata_dec_decode( only_reduce_bits_direction_fx( &dummy, q_direction, reduce_bits, nbands, nblocks, ind_order ); /* Read directions */ - bits_dir = read_directions_fx( q_direction, (UWord8) nbands, (UWord8) nblocks, bitstream, index, ind_order ); + bits_dir = read_directions_fx( q_direction, (UWord8) nbands, (UWord8) nblocks, bitstream, index, ind_order ); /*Q0*/ } IF( bits_coherence > 0 ) @@ -671,7 +671,7 @@ Word16 ivas_qmetadata_dec_decode( } IF( d == 0 ) { - total_bits_1dir = sub( hQMetaData->metadata_max_bits, sub( start_index_0, *index ) ); + total_bits_1dir = sub( hQMetaData->metadata_max_bits, sub( start_index_0, *index ) ); /*Q0*/ } bits_dir_target = add( bits_dir_target, bits_dir_raw ); @@ -688,39 +688,39 @@ Word16 ivas_qmetadata_dec_decode( { IF( EQ_16( hQMetaData->twoDirBands[b], 1 ) ) { - Copy32( hQMetaData->q_direction[1].band_data[d].azimuth_fx, hQMetaData->q_direction[1].band_data[b].azimuth_fx, nblocks ); - Copy32( hQMetaData->q_direction[1].band_data[d].elevation_fx, hQMetaData->q_direction[1].band_data[b].elevation_fx, nblocks ); - Copy32( hQMetaData->q_direction[1].band_data[d].energy_ratio_fx, hQMetaData->q_direction[1].band_data[b].energy_ratio_fx, nblocks ); + Copy32( hQMetaData->q_direction[1].band_data[d].azimuth_fx, hQMetaData->q_direction[1].band_data[b].azimuth_fx, nblocks ); /*Q22*/ + Copy32( hQMetaData->q_direction[1].band_data[d].elevation_fx, hQMetaData->q_direction[1].band_data[b].elevation_fx, nblocks ); /*Q22*/ + Copy32( hQMetaData->q_direction[1].band_data[d].energy_ratio_fx, hQMetaData->q_direction[1].band_data[b].energy_ratio_fx, nblocks ); /*Q30*/ IF( LT_32( hQMetaData->q_direction[0].band_data[b].energy_ratio_index[0], 7 ) ) { FOR( m = 0; m < nblocks; m++ ) { - Word32 a1 = hQMetaData->q_direction[1].band_data[b].azimuth_fx[m]; + Word32 a1 = hQMetaData->q_direction[1].band_data[b].azimuth_fx[m]; /*Q22*/ move32(); - a1 = L_shr( hQMetaData->q_direction[1].band_data[b].azimuth_fx[m], 1 ); - Word32 b1 = hQMetaData->q_direction[0].band_data[b].azimuth_fx[m]; + a1 = L_shr( hQMetaData->q_direction[1].band_data[b].azimuth_fx[m], 1 ); /*Q21*/ + Word32 b1 = hQMetaData->q_direction[0].band_data[b].azimuth_fx[m]; /*Q22*/ move32(); - b1 = L_shr( hQMetaData->q_direction[0].band_data[b].azimuth_fx[m], 1 ); - Word32 c = L_shr( DEGREE_180_Q_22, 1 ); + b1 = L_shr( hQMetaData->q_direction[0].band_data[b].azimuth_fx[m], 1 ); /*Q21*/ + Word32 c = L_shr( DEGREE_180_Q_22, 1 ); /*Q21*/ a1 = L_add( a1, L_sub( b1, c ) ); IF( GE_32( a1, L_shr( DEGREE_180_Q_22, 1 ) ) ) { - a1 = L_sub( a1, L_shr( DEGREE_360_Q_22, 1 ) ); + a1 = L_sub( a1, L_shr( DEGREE_360_Q_22, 1 ) ); /*Q21*/ } IF( LT_32( a1, L_shr( -DEGREE_180_Q_22, 1 ) ) ) { - a1 = L_add( a1, L_shr( DEGREE_360_Q_22, 1 ) ); + a1 = L_add( a1, L_shr( DEGREE_360_Q_22, 1 ) ); /*Q21*/ } - hQMetaData->q_direction[1].band_data[b].azimuth_fx[m] = L_shl( a1, 1 ); + hQMetaData->q_direction[1].band_data[b].azimuth_fx[m] = L_shl( a1, 1 ); /*Q22*/ move32(); } } IF( hQMetaData->q_direction[1].coherence_band_data != NULL ) { - mvc2c( hQMetaData->q_direction[1].coherence_band_data[d].spread_coherence, hQMetaData->q_direction[1].coherence_band_data[b].spread_coherence, nblocks ); + mvc2c( hQMetaData->q_direction[1].coherence_band_data[d].spread_coherence, hQMetaData->q_direction[1].coherence_band_data[b].spread_coherence, nblocks ); /*Q0*/ } d = sub( d, 1 ); } @@ -744,12 +744,12 @@ Word16 ivas_qmetadata_dec_decode( { Word32 ratioSum_flt_fx; - ratioSum_flt_fx = L_add( hQMetaData->q_direction[0].band_data[b].energy_ratio_fx[0], hQMetaData->q_direction[1].band_data[b].energy_ratio_fx[0] ); + ratioSum_flt_fx = L_add( hQMetaData->q_direction[0].band_data[b].energy_ratio_fx[0], hQMetaData->q_direction[1].band_data[b].energy_ratio_fx[0] ); /*Q30*/ IF( GT_32( ratioSum_flt_fx, ONE_IN_Q30 ) ) { - set32_fx( hQMetaData->q_direction[0].band_data[b].energy_ratio_fx, L_shl( (Word32) divide3232( hQMetaData->q_direction[0].band_data[b].energy_ratio_fx[0], ratioSum_flt_fx ), 15 ) /* Q30 */, nblocks ); - set32_fx( hQMetaData->q_direction[1].band_data[b].energy_ratio_fx, L_shl( (Word32) divide3232( hQMetaData->q_direction[1].band_data[b].energy_ratio_fx[0], ratioSum_flt_fx ), 15 ) /* Q30 */, nblocks ); + set32_fx( hQMetaData->q_direction[0].band_data[b].energy_ratio_fx, L_shl( (Word32) divide3232( hQMetaData->q_direction[0].band_data[b].energy_ratio_fx[0], ratioSum_flt_fx ), 15 ) /* Q30 */, nblocks ); /*Q30*/ + set32_fx( hQMetaData->q_direction[1].band_data[b].energy_ratio_fx, L_shl( (Word32) divide3232( hQMetaData->q_direction[1].band_data[b].energy_ratio_fx[0], ratioSum_flt_fx ), 15 ) /* Q30 */, nblocks ); /*Q30*/ } } } @@ -761,12 +761,12 @@ Word16 ivas_qmetadata_dec_decode( IF( GT_16( bits_dir_used, bits_dir_target ) ) { - hQMetaData->dir_comp_ratio_fx = MAX_WORD16; + hQMetaData->dir_comp_ratio_fx = MAX_WORD16; /*Q15*/ move16(); } ELSE { - hQMetaData->dir_comp_ratio_fx = divide3232( bits_dir_used, bits_dir_target ); + hQMetaData->dir_comp_ratio_fx = divide3232( bits_dir_used, bits_dir_target ); /*Q15*/ } return sub( start_index_0, *index ); } @@ -1334,8 +1334,8 @@ int16_t ivas_qmetadata_dec_decode( #ifdef IVAS_FLOAT_FIXED Word16 ivas_qmetadata_dec_decode_hr_384_512( IVAS_QMETADATA_HANDLE hQMetaData, /* i/o: hQMetaData handle */ - UWord16 *bitstream, /* i : bitstream */ - Word16 *index, /* i/o: bitstream position */ + UWord16 *bitstream, /* i : bitstream Q0*/ + Word16 *index, /* i/o: bitstream position Q0*/ const SPHERICAL_GRID_DATA *sph_grid16, /* i : spherical grid for deindexing */ const Word16 bits_sph_idx, const Word16 bits_sp_coh, @@ -1357,11 +1357,11 @@ Word16 ivas_qmetadata_dec_decode_hr_384_512( /* read number of higher inactive/not encoded bands */ IF( bitstream[( *index )--] ) { - codedBands = sub( sub( MASA_MAXIMUM_CODING_SUBBANDS, ivas_qmetadata_DecodeExtendedGR( bitstream, index, MASA_MAXIMUM_CODING_SUBBANDS, 1 ) ), 1 ); + codedBands = sub( sub( MASA_MAXIMUM_CODING_SUBBANDS, ivas_qmetadata_DecodeExtendedGR( bitstream, index, MASA_MAXIMUM_CODING_SUBBANDS, 1 ) ), 1 ); /*Q0*/ } ELSE { - codedBands = MASA_MAXIMUM_CODING_SUBBANDS; + codedBands = MASA_MAXIMUM_CODING_SUBBANDS; /*Q0*/ move16(); } FOR( b = codedBands; b < ncoding_bands_config; b++ ) @@ -1419,10 +1419,10 @@ Word16 ivas_qmetadata_dec_decode_hr_384_512( move16(); } } - sf_nbands0 = hQMetaData->q_direction[0].cfg.nbands; + sf_nbands0 = hQMetaData->q_direction[0].cfg.nbands; /*Q0*/ move16(); - hQMetaData->q_direction[0].cfg.nbands = codedBands; + hQMetaData->q_direction[0].cfg.nbands = codedBands; /*Q0*/ move16(); /*Coherence flag decoding*/ @@ -1431,11 +1431,11 @@ Word16 ivas_qmetadata_dec_decode_hr_384_512( IF( hQMetaData->coherence_flag ) { /* read if coherence is zero */ - all_coherence_zero = bitstream[( *index )--]; + all_coherence_zero = bitstream[( *index )--]; /*Q0*/ move16(); } - hQMetaData->all_coherence_zero = (UWord8) all_coherence_zero; + hQMetaData->all_coherence_zero = (UWord8) all_coherence_zero; /*Q0*/ IF( EQ_32( hQMetaData->no_directions, 2 ) ) { @@ -1446,19 +1446,19 @@ Word16 ivas_qmetadata_dec_decode_hr_384_512( IF( EQ_16( bits_sph_idx, 11 ) && EQ_32( hQMetaData->no_directions, 2 ) ) { /* Read which bands have 2 directions */ - hQMetaData->q_direction[1].cfg.nbands = hQMetaData->numTwoDirBands; + hQMetaData->q_direction[1].cfg.nbands = hQMetaData->numTwoDirBands; /*Q0*/ move16(); - sf_nbands1 = hQMetaData->q_direction[1].cfg.nbands; + sf_nbands1 = hQMetaData->q_direction[1].cfg.nbands; /*Q0*/ move16(); if ( GT_16( hQMetaData->q_direction[1].cfg.nbands, codedBands ) ) { - hQMetaData->q_direction[1].cfg.nbands = codedBands; + hQMetaData->q_direction[1].cfg.nbands = codedBands; /*Q0*/ move16(); } set_c( (Word8 *) hQMetaData->twoDirBands, 0, hQMetaData->q_direction[0].cfg.nbands ); d = *index; move16(); - dif_p[0] = ivas_qmetadata_DecodeExtendedGR( bitstream, index, MASA_MAXIMUM_CODING_SUBBANDS, 0 ); + dif_p[0] = ivas_qmetadata_DecodeExtendedGR( bitstream, index, MASA_MAXIMUM_CODING_SUBBANDS, 0 ); /*Q0*/ move16(); p[0] = dif_p[0]; move16(); @@ -1466,7 +1466,7 @@ Word16 ivas_qmetadata_dec_decode_hr_384_512( move16(); FOR( b = 1; b < hQMetaData->q_direction[1].cfg.nbands; b++ ) { - dif_p[b] = ivas_qmetadata_DecodeExtendedGR( bitstream, index, MASA_MAXIMUM_CODING_SUBBANDS, 0 ); + dif_p[b] = ivas_qmetadata_DecodeExtendedGR( bitstream, index, MASA_MAXIMUM_CODING_SUBBANDS, 0 ); /*Q0*/ move16(); p[b] = add( add( p[b - 1], dif_p[b] ), 1 ); move16(); @@ -1478,11 +1478,11 @@ Word16 ivas_qmetadata_dec_decode_hr_384_512( test(); IF( EQ_16( bits_sph_idx, 16 ) && EQ_32( hQMetaData->no_directions, 2 ) ) { - sf_nbands1 = hQMetaData->q_direction[1].cfg.nbands; + sf_nbands1 = hQMetaData->q_direction[1].cfg.nbands; /*Q0*/ move16(); IF( GT_16( hQMetaData->q_direction[1].cfg.nbands, codedBands ) ) { - hQMetaData->q_direction[1].cfg.nbands = codedBands; + hQMetaData->q_direction[1].cfg.nbands = codedBands; /*Q0*/ move16(); } } @@ -1498,7 +1498,7 @@ Word16 ivas_qmetadata_dec_decode_hr_384_512( { FOR( m = 0; m < hQMetaData->q_direction[0].cfg.nblocks; m++ ) { - W_nrg_ratio[0][b][m] = W_sub( ONE_IN_Q62, diffuseness_reconstructions_hr_fx[hQMetaData->q_direction[0].band_data[b].energy_ratio_index[m]] ); + W_nrg_ratio[0][b][m] = W_sub( ONE_IN_Q62, diffuseness_reconstructions_hr_fx[hQMetaData->q_direction[0].band_data[b].energy_ratio_index[m]] ); /*Q62*/ move64(); } } @@ -1511,11 +1511,11 @@ Word16 ivas_qmetadata_dec_decode_hr_384_512( { FOR( m = 0; m < hQMetaData->q_direction[1].cfg.nblocks; m++ ) { - W_nrg_ratio[1][b][m] = W_sub( ONE_IN_Q62, diffuseness_reconstructions_hr_fx[hQMetaData->q_direction[1].band_data[b].energy_ratio_index[m]] ); + W_nrg_ratio[1][b][m] = W_sub( ONE_IN_Q62, diffuseness_reconstructions_hr_fx[hQMetaData->q_direction[1].band_data[b].energy_ratio_index[m]] ); /*Q62*/ move64(); /* Scale energy ratios that sum to over one */ - ratioSum = W_round64_L( W_add( W_nrg_ratio[0][b][m], W_nrg_ratio[1][b][m] ) ); + ratioSum = W_round64_L( W_add( W_nrg_ratio[0][b][m], W_nrg_ratio[1][b][m] ) ); /*Q30*/ IF( GT_32( ratioSum, ONE_IN_Q30 ) ) { @@ -1536,7 +1536,7 @@ Word16 ivas_qmetadata_dec_decode_hr_384_512( { IF( EQ_16( hQMetaData->twoDirBands[b], 1 ) ) { - pos_2dir_band[d] = b; + pos_2dir_band[d] = b; /*Q0*/ move16(); d = add( d, 1 ); } @@ -1551,16 +1551,16 @@ Word16 ivas_qmetadata_dec_decode_hr_384_512( FOR( m = 0; m < hQMetaData->q_direction[1].cfg.nblocks; m++ ) { - W_nrg_ratio[1][b][m] = W_sub( ONE_IN_Q62, diffuseness_reconstructions_hr_fx[hQMetaData->q_direction[1].band_data[b].energy_ratio_index[m]] ); + W_nrg_ratio[1][b][m] = W_sub( ONE_IN_Q62, diffuseness_reconstructions_hr_fx[hQMetaData->q_direction[1].band_data[b].energy_ratio_index[m]] ); /*Q62*/ move64(); - ratioSum = W_round64_L( W_add( W_nrg_ratio[0][pos_2dir_band[b]][m], W_nrg_ratio[1][b][m] ) ); + ratioSum = W_round64_L( W_add( W_nrg_ratio[0][pos_2dir_band[b]][m], W_nrg_ratio[1][b][m] ) ); /*Q30*/ IF( GT_32( ratioSum, ONE_IN_Q30 ) ) { - W_nrg_ratio[0][pos_2dir_band[b]][m] = W_shl( (Word64) ( W_nrg_ratio[0][pos_2dir_band[b]][m] / ratioSum ), 30 ); + W_nrg_ratio[0][pos_2dir_band[b]][m] = W_shl( (Word64) ( W_nrg_ratio[0][pos_2dir_band[b]][m] / ratioSum ), 30 ); /*Q62*/ move64(); - W_nrg_ratio[1][b][m] = W_shl( (Word64) ( W_nrg_ratio[1][b][m] / ratioSum ), 30 ); + W_nrg_ratio[1][b][m] = W_shl( (Word64) ( W_nrg_ratio[1][b][m] / ratioSum ), 30 ); /*Q62*/ move64(); } } @@ -1574,9 +1574,9 @@ Word16 ivas_qmetadata_dec_decode_hr_384_512( { FOR( m = 0; m < hQMetaData->q_direction[1].cfg.nblocks; m++ ) { - hQMetaData->q_direction[1].band_data[b].energy_ratio_index_mod[m] = hQMetaData->q_direction[1].band_data[b].energy_ratio_index[m]; + hQMetaData->q_direction[1].band_data[b].energy_ratio_index_mod[m] = hQMetaData->q_direction[1].band_data[b].energy_ratio_index[m]; /*Q0*/ move16(); - hQMetaData->q_direction[1].band_data[b].bits_sph_idx[m] = bits_sph_idx; + hQMetaData->q_direction[1].band_data[b].bits_sph_idx[m] = bits_sph_idx; /*Q0*/ move16(); } } @@ -1586,9 +1586,9 @@ Word16 ivas_qmetadata_dec_decode_hr_384_512( { FOR( m = 0; m < hQMetaData->q_direction[0].cfg.nblocks; m++ ) { - hQMetaData->q_direction[0].band_data[b].energy_ratio_index_mod[m] = hQMetaData->q_direction[0].band_data[b].energy_ratio_index[0]; + hQMetaData->q_direction[0].band_data[b].energy_ratio_index_mod[m] = hQMetaData->q_direction[0].band_data[b].energy_ratio_index[0]; /*Q0*/ move16(); - hQMetaData->q_direction[0].band_data[b].bits_sph_idx[m] = bits_sph_idx; + hQMetaData->q_direction[0].band_data[b].bits_sph_idx[m] = bits_sph_idx; /*Q0*/ move16(); } } @@ -1659,14 +1659,14 @@ Word16 ivas_qmetadata_dec_decode_hr_384_512( IF( EQ_16( hQMetaData->twoDirBands[b], 1 ) ) { - Copy32( hQMetaData->q_direction[1].band_data[d].azimuth_fx, hQMetaData->q_direction[1].band_data[b].azimuth_fx, nblocks ); - Copy32( hQMetaData->q_direction[1].band_data[d].elevation_fx, hQMetaData->q_direction[1].band_data[b].elevation_fx, nblocks ); - Copy32( hQMetaData->q_direction[1].band_data[d].energy_ratio_fx, hQMetaData->q_direction[1].band_data[b].energy_ratio_fx, nblocks ); + Copy32( hQMetaData->q_direction[1].band_data[d].azimuth_fx, hQMetaData->q_direction[1].band_data[b].azimuth_fx, nblocks ); /*Q22*/ + Copy32( hQMetaData->q_direction[1].band_data[d].elevation_fx, hQMetaData->q_direction[1].band_data[b].elevation_fx, nblocks ); /*Q22*/ + Copy32( hQMetaData->q_direction[1].band_data[d].energy_ratio_fx, hQMetaData->q_direction[1].band_data[b].energy_ratio_fx, nblocks ); /*Q30*/ Copy64( W_nrg_ratio[1][d], W_nrg_ratio[1][b], nblocks ); IF( hQMetaData->q_direction[1].coherence_band_data != NULL ) { - mvc2c( hQMetaData->q_direction[1].coherence_band_data[d].spread_coherence, hQMetaData->q_direction[1].coherence_band_data[b].spread_coherence, nblocks ); + mvc2c( hQMetaData->q_direction[1].coherence_band_data[d].spread_coherence, hQMetaData->q_direction[1].coherence_band_data[b].spread_coherence, nblocks ); /*Q0*/ } d = sub( d, 1 ); } @@ -1691,12 +1691,12 @@ Word16 ivas_qmetadata_dec_decode_hr_384_512( FOR( m = 0; m < hQMetaData->q_direction[0].cfg.nblocks; m++ ) { Word32 ratioSum; - ratioSum = W_round64_L( W_add( W_nrg_ratio[0][b][m], W_nrg_ratio[1][b][m] ) ); + ratioSum = W_round64_L( W_add( W_nrg_ratio[0][b][m], W_nrg_ratio[1][b][m] ) ); /*Q30*/ IF( GT_32( ratioSum, ONE_IN_Q30 ) ) { - W_nrg_ratio[0][b][m] = W_shl( (Word64) ( W_nrg_ratio[0][b][m] / ratioSum ), 30 ); + W_nrg_ratio[0][b][m] = W_shl( (Word64) ( W_nrg_ratio[0][b][m] / ratioSum ), 30 ); /*Q62*/ move64(); - W_nrg_ratio[1][b][m] = W_shl( (Word64) ( W_nrg_ratio[1][b][m] / ratioSum ), 30 ); + W_nrg_ratio[1][b][m] = W_shl( (Word64) ( W_nrg_ratio[1][b][m] / ratioSum ), 30 ); /*Q62*/ move64(); } } @@ -1708,7 +1708,7 @@ Word16 ivas_qmetadata_dec_decode_hr_384_512( { FOR( m = 0; m < hQMetaData->q_direction[0].cfg.nblocks; m++ ) { - hQMetaData->q_direction[0].band_data[b].energy_ratio_fx[m] = W_round64_L( W_nrg_ratio[0][b][m] ); + hQMetaData->q_direction[0].band_data[b].energy_ratio_fx[m] = W_round64_L( W_nrg_ratio[0][b][m] ); /*Q30*/ move32(); } } @@ -1729,7 +1729,7 @@ Word16 ivas_qmetadata_dec_decode_hr_384_512( { FOR( m = 0; m < hQMetaData->q_direction[1].cfg.nblocks; m++ ) { - hQMetaData->q_direction[1].band_data[b].energy_ratio_fx[m] = W_round64_L( W_nrg_ratio[1][b][m] ); + hQMetaData->q_direction[1].band_data[b].energy_ratio_fx[m] = W_round64_L( W_nrg_ratio[1][b][m] ); /*Q30*/ move32(); } } @@ -1747,15 +1747,15 @@ Word16 ivas_qmetadata_dec_decode_hr_384_512( /* Store status information for renderer use */ hQMetaData->ec_flag = 0; move16(); - hQMetaData->dir_comp_ratio_fx = MAX_WORD16; + hQMetaData->dir_comp_ratio_fx = MAX_WORD16; /*Q15*/ move16(); - hQMetaData->q_direction[0].cfg.nbands = sf_nbands0; + hQMetaData->q_direction[0].cfg.nbands = sf_nbands0; /*Q0*/ move16(); IF( EQ_32( hQMetaData->no_directions, 2 ) ) { - hQMetaData->q_direction[1].cfg.nbands = sf_nbands1; + hQMetaData->q_direction[1].cfg.nbands = sf_nbands1; /*Q0*/ move16(); } @@ -2105,11 +2105,11 @@ int16_t ivas_qmetadata_dec_decode_hr_384_512( #ifdef IVAS_FLOAT_FIXED Word16 ivas_qmetadata_dec_sid_decode( IVAS_QMETADATA_HANDLE hQMetaData, /* i/o: q_metadata handle */ - UWord16 *bitstream, /* i : bitstream */ - Word16 *index, /* i/o: bitstream position */ - const Word16 nchan_transport, /* i : number of transport channels */ - Word16 *element_mode, /* o : element mode */ - const Word16 ivas_format /* i : IVAS format */ + UWord16 *bitstream, /* i : bitstream Q0*/ + Word16 *index, /* i/o: bitstream position Q0*/ + const Word16 nchan_transport, /* i : number of transport channels Q0*/ + Word16 *element_mode, /* o : element mode Q0*/ + const Word16 ivas_format /* i : IVAS format Q0*/ ) { Word16 b, m, i; @@ -2142,7 +2142,7 @@ Word16 ivas_qmetadata_dec_sid_decode( test(); IF( EQ_16( ivas_format, MASA_FORMAT ) && EQ_16( nchan_transport, 2 ) ) { - b = bitstream[( *index )--]; + b = bitstream[( *index )--]; /*Q0*/ move16(); IF( b ) { @@ -2169,7 +2169,7 @@ Word16 ivas_qmetadata_dec_sid_decode( move16(); } - nblocks = q_direction->cfg.nblocks; /* only 1 block transmitted but up to 4 blocks re-generated */ + nblocks = q_direction->cfg.nblocks; /* only 1 block transmitted but up to 4 blocks re-generated Q0*/ move16(); start_band = 0; /* start from band 0 */ move16(); @@ -2177,7 +2177,7 @@ Word16 ivas_qmetadata_dec_sid_decode( /* Read 2D signaling*/ IF( NE_16( ivas_format, SBA_FORMAT ) ) { - q_direction->not_in_2D = bitstream[( *index )--]; + q_direction->not_in_2D = bitstream[( *index )--]; /*Q0*/ move16(); } ELSE @@ -2193,14 +2193,14 @@ Word16 ivas_qmetadata_dec_sid_decode( /* Decode diffuseness*/ FOR( b = start_band; b < nbands; b++ ) { - diffuseness_index[b] = (UWord16) L_add( ivas_qmetadata_DecodeQuasiUniform( bitstream, index, sub( DIRAC_DIFFUSE_LEVELS, 4 ) ), 4 ); + diffuseness_index[b] = (UWord16) L_add( ivas_qmetadata_DecodeQuasiUniform( bitstream, index, sub( DIRAC_DIFFUSE_LEVELS, 4 ) ), 4 ); /*Q0*/ move16(); - q_direction->band_data[b].energy_ratio_index[0] = diffuseness_index[b]; + q_direction->band_data[b].energy_ratio_index[0] = diffuseness_index[b]; /*Q0*/ move16(); - q_direction->band_data[b].bits_sph_idx[0] = bits_direction_masa[diffuseness_index[b]]; + q_direction->band_data[b].bits_sph_idx[0] = bits_direction_masa[diffuseness_index[b]]; /*Q0*/ move16(); - bits_dir = extract_l( L_add( bits_dir, q_direction->band_data[b].bits_sph_idx[0] ) ); - q_direction->band_data[b].azimuth_m_alphabet[0] = no_phi_masa[q_direction->band_data[b].bits_sph_idx[0] - 1][0]; + bits_dir = extract_l( L_add( bits_dir, q_direction->band_data[b].bits_sph_idx[0] ) ); /*Q0*/ + q_direction->band_data[b].azimuth_m_alphabet[0] = no_phi_masa[q_direction->band_data[b].bits_sph_idx[0] - 1][0]; /*Q0*/ move16(); } @@ -2260,7 +2260,7 @@ Word16 ivas_qmetadata_dec_sid_decode( /* Decode diffuseness*/ FOR( b = start_band; b < nbands; b++ ) { - diffuseness_index[b] = (UWord16) L_add( ivas_qmetadata_DecodeQuasiUniform( bitstream, index, DIRAC_DIFFUSE_LEVELS - 4 ), 4 ); + diffuseness_index[b] = (UWord16) L_add( ivas_qmetadata_DecodeQuasiUniform( bitstream, index, DIRAC_DIFFUSE_LEVELS - 4 ), 4 ); /*Q0*/ move16(); q_direction->band_data[b].energy_ratio_index[0] = diffuseness_index[b]; move16(); @@ -2273,11 +2273,11 @@ Word16 ivas_qmetadata_dec_sid_decode( FOR( b = start_band; b < nbands; b++ ) { - q_direction->band_data[b].energy_ratio_fx[0] = L_sub( ONE_IN_Q30, diffuseness_reconstructions_fx[diffuseness_index[b]] ); + q_direction->band_data[b].energy_ratio_fx[0] = L_sub( ONE_IN_Q30, diffuseness_reconstructions_fx[diffuseness_index[b]] ); /*Q30*/ move32(); FOR( i = 0; i < nblocks; i++ ) { - q_direction->band_data[b].energy_ratio_fx[i] = q_direction->band_data[b].energy_ratio_fx[0]; + q_direction->band_data[b].energy_ratio_fx[i] = q_direction->band_data[b].energy_ratio_fx[0]; /*Q30*/ move32(); } } @@ -2304,11 +2304,11 @@ Word16 ivas_qmetadata_dec_sid_decode( ivas_qmetadata_azimuth_elevation_to_direction_vector_fx( avg_azimuth_fx, avg_elevation_fx, avg_direction_vector_fx ); ivas_qmetadata_azimuth_elevation_to_direction_vector_fx( q_direction->band_data[b].azimuth_fx[nblocks - 1], q_direction->band_data[b].elevation_fx[nblocks - 1], direction_vector_fx ); - v_shr_32( direction_vector_fx, direction_vector_fx, 3, 5 ); - v_shr_32( avg_direction_vector_fx, avg_direction_vector_fx, 3, 5 ); + v_shr_32( direction_vector_fx, direction_vector_fx, 3, 5 ); /*Q25*/ + v_shr_32( avg_direction_vector_fx, avg_direction_vector_fx, 3, 5 ); /*Q25*/ FOR( m = 0; m < nblocks - 1; m++ ) { - v_add_32( direction_vector_fx, avg_direction_vector_fx, direction_vector_fx, 3 ); + v_add_32( direction_vector_fx, avg_direction_vector_fx, direction_vector_fx, 3 ); /*Q25*/ ivas_qmetadata_direction_vector_to_azimuth_elevation_fx( direction_vector_fx, sub( 30, 5 ), &q_direction->band_data[b].azimuth_fx[m], &q_direction->band_data[b].elevation_fx[m] ); } ivas_qmetadata_direction_vector_to_azimuth_elevation_fx( avg_direction_vector_fx, sub( 30, 5 ), &q_direction->band_data[b].azimuth_fx[nblocks - 1], &q_direction->band_data[b].elevation_fx[nblocks - 1] ); @@ -2324,14 +2324,14 @@ Word16 ivas_qmetadata_dec_sid_decode( q_direction->band_data[b].azimuth_m_alphabet[0] = shl( 1, extract_l( L_min( 5, q_direction->band_data[b].bits_sph_idx[0] ) ) ); move16(); } - q_direction->band_data[b].azimuth_index[0] = ivas_qmetadata_DecodeQuasiUniform( bitstream, index, q_direction->band_data[b].azimuth_m_alphabet[0] ); + q_direction->band_data[b].azimuth_index[0] = ivas_qmetadata_DecodeQuasiUniform( bitstream, index, q_direction->band_data[b].azimuth_m_alphabet[0] ); /*Q0*/ move16(); - q_direction->band_data[b].azimuth_index[0] = add( ivas_qmetadata_dereorder_generic( q_direction->band_data[b].azimuth_index[0] ), shr( q_direction->band_data[b].azimuth_m_alphabet[0], 1 ) ); + q_direction->band_data[b].azimuth_index[0] = add( ivas_qmetadata_dereorder_generic( q_direction->band_data[b].azimuth_index[0] ), shr( q_direction->band_data[b].azimuth_m_alphabet[0], 1 ) ); /*Q0*/ move16(); - temp_result = div_s( ( shl( q_direction->band_data[b].azimuth_index[0], 6 ) ), ( shl( q_direction->band_data[b].azimuth_m_alphabet[0], 6 ) ) ); - temp_result = Mpy_32_16_1( DEGREE_360_Q_22, (Word16) temp_result ); - avg_azimuth_fx = L_sub( temp_result, DEGREE_180_Q_22 ); + temp_result = div_s( ( shl( q_direction->band_data[b].azimuth_index[0], 6 ) ), ( shl( q_direction->band_data[b].azimuth_m_alphabet[0], 6 ) ) ); /*Q15*/ + temp_result = Mpy_32_16_1( DEGREE_360_Q_22, (Word16) temp_result ); /*Q22*/ + avg_azimuth_fx = L_sub( temp_result, DEGREE_180_Q_22 ); /*Q22*/ avg_elevation_fx = 0; move32(); @@ -2339,11 +2339,11 @@ Word16 ivas_qmetadata_dec_sid_decode( ivas_qmetadata_azimuth_elevation_to_direction_vector_fx( avg_azimuth_fx, avg_elevation_fx, avg_direction_vector_fx ); ivas_qmetadata_azimuth_elevation_to_direction_vector_fx( q_direction->band_data[b].azimuth_fx[nblocks - 1], q_direction->band_data[b].elevation_fx[nblocks - 1], direction_vector_fx ); - v_shr_32( direction_vector_fx, direction_vector_fx, 3, 5 ); - v_shr_32( avg_direction_vector_fx, avg_direction_vector_fx, 3, 5 ); + v_shr_32( direction_vector_fx, direction_vector_fx, 3, 5 ); /*Q25*/ + v_shr_32( avg_direction_vector_fx, avg_direction_vector_fx, 3, 5 ); /*Q25*/ FOR( m = 0; m < nblocks - 1; m++ ) { - v_add_32( direction_vector_fx, avg_direction_vector_fx, direction_vector_fx, 3 ); + v_add_32( direction_vector_fx, avg_direction_vector_fx, direction_vector_fx, 3 ); /*Q25*/ ivas_qmetadata_direction_vector_to_azimuth_elevation_fx( direction_vector_fx, 30 - 5, &q_direction->band_data[b].azimuth_fx[m], &q_direction->band_data[b].elevation_fx[m] ); } ivas_qmetadata_direction_vector_to_azimuth_elevation_fx( avg_direction_vector_fx, 30 - 5, &q_direction->band_data[b].azimuth_fx[nblocks - 1], &q_direction->band_data[b].elevation_fx[nblocks - 1] ); @@ -2598,9 +2598,9 @@ int16_t ivas_qmetadata_dec_sid_decode( #ifdef IVAS_FLOAT_FIXED static Word16 ivas_diffuseness_huff_ec_decode_fx( - const UWord16 *bitstream, - Word16 *index, - Word16 av ) + const UWord16 *bitstream, /*Q0*/ + Word16 *index, /*Q0*/ + Word16 av /*Q0*/ ) { Word16 val; @@ -2680,10 +2680,10 @@ static int16_t ivas_diffuseness_huff_ec_decode( *-------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED static Word16 ivas_qmetadata_entropy_decode_diffuseness( - UWord16 *bitstream, /* i : bitstream */ - Word16 *index, + UWord16 *bitstream, /* i : bitstream Q0*/ + Word16 *index, /*Q0*/ IVAS_QDIRECTION *q_direction, - UWord16 *diffuseness_index_max_ec_frame ) + UWord16 *diffuseness_index_max_ec_frame /*Q0*/ ) { Word16 b; UWord16 dif_min; @@ -2706,7 +2706,7 @@ static Word16 ivas_qmetadata_entropy_decode_diffuseness( move16(); FOR( b = 0; b < MASA_BITS_ER; b++ ) { - q_direction->band_data[0].energy_ratio_index[0] = (UWord16) L_add( L_shl( q_direction->band_data[0].energy_ratio_index[0], 1 ), bitstream[( *index )--] ); + q_direction->band_data[0].energy_ratio_index[0] = (UWord16) L_add( L_shl( q_direction->band_data[0].energy_ratio_index[0], 1 ), bitstream[( *index )--] ); /*Q0*/ move16(); } *diffuseness_index_max_ec_frame = 5; @@ -2722,21 +2722,21 @@ static Word16 ivas_qmetadata_entropy_decode_diffuseness( { IF( bitstream[( *index )--] ) /* dif_have_unique_value */ { - dif_min = ivas_qmetadata_DecodeQuasiUniform( bitstream, index, DIRAC_DIFFUSE_LEVELS ); /* dif_unique_value */ + dif_min = ivas_qmetadata_DecodeQuasiUniform( bitstream, index, DIRAC_DIFFUSE_LEVELS ); /* dif_unique_value Q0*/ FOR( b = start_band; b < nbands; b++ ) { - q_direction->band_data[b].energy_ratio_index[0] = dif_min; + q_direction->band_data[b].energy_ratio_index[0] = dif_min; /*Q0*/ move16(); } } ELSE /* all diffuseness values are dif_min_value or dif_min_value + 1 */ { - dif_min = ivas_qmetadata_DecodeQuasiUniform( bitstream, index, DIRAC_DIFFUSE_LEVELS - 1 ); /* dif_min_value */ + dif_min = ivas_qmetadata_DecodeQuasiUniform( bitstream, index, DIRAC_DIFFUSE_LEVELS - 1 ); /* dif_min_value Q0*/ FOR( b = start_band; b < nbands; b++ ) { - q_direction->band_data[b].energy_ratio_index[0] = (UWord16) L_add( dif_min, bitstream[( *index )--] ); /* dif_bit_offset_values */ + q_direction->band_data[b].energy_ratio_index[0] = (UWord16) L_add( dif_min, bitstream[( *index )--] ); /* dif_bit_offset_values Q0*/ move16(); } } @@ -2750,7 +2750,7 @@ static Word16 ivas_qmetadata_entropy_decode_diffuseness( move16(); FOR( b = 0; b < MASA_BITS_ER; b++ ) { - av = add( av, i_mult( (Word16) bitstream[( *index )--], shl( 1, sub( sub( MASA_BITS_ER, 1 ), b ) ) ) ); + av = add( av, i_mult( (Word16) bitstream[( *index )--], shl( 1, sub( sub( MASA_BITS_ER, 1 ), b ) ) ) ); /*Q0*/ } dif_min = DIRAC_DIFFUSE_LEVELS; @@ -2758,7 +2758,7 @@ static Word16 ivas_qmetadata_entropy_decode_diffuseness( /* read average removed data (average is added inside)*/ FOR( b = start_band; b < nbands; b++ ) { - q_direction->band_data[b].energy_ratio_index[0] = ivas_diffuseness_huff_ec_decode_fx( bitstream, index, av ); + q_direction->band_data[b].energy_ratio_index[0] = ivas_diffuseness_huff_ec_decode_fx( bitstream, index, av ); /*Q0*/ move16(); dif_min = (UWord16) L_min( dif_min, q_direction->band_data[b].energy_ratio_index[0] ); move16(); @@ -2772,7 +2772,7 @@ static Word16 ivas_qmetadata_entropy_decode_diffuseness( FOR( b = start_band; b < nbands; b++ ) { - q_direction->band_data[b].energy_ratio_index[0] = ivas_qmetadata_DecodeQuasiUniform( bitstream, index, DIRAC_DIFFUSE_LEVELS ); + q_direction->band_data[b].energy_ratio_index[0] = ivas_qmetadata_DecodeQuasiUniform( bitstream, index, DIRAC_DIFFUSE_LEVELS ); /*Q0*/ move16(); dif_min = (UWord16) L_min( dif_min, q_direction->band_data[b].energy_ratio_index[0] ); move16(); @@ -2895,8 +2895,8 @@ static int16_t ivas_qmetadata_entropy_decode_diffuseness( #ifdef IVAS_FLOAT_FIXED static Word16 ivas_qmetadata_entropy_decode_diffuseness_hr_512( - UWord16 *bitstream, /* i : bitstream */ - Word16 *index, + UWord16 *bitstream, /* i : bitstream Q0*/ + Word16 *index, /*Q0*/ IVAS_QDIRECTION *q_direction ) { Word16 b, k; @@ -2922,7 +2922,7 @@ static Word16 ivas_qmetadata_entropy_decode_diffuseness_hr_512( move16(); FOR( b = 0; b < MASA_BITS_ER_HR; b++ ) { - q_direction->band_data[0].energy_ratio_index[0] = (UWord16) L_add( (UWord16) L_shl( q_direction->band_data[0].energy_ratio_index[0], 1 ), bitstream[( *index )--] ); + q_direction->band_data[0].energy_ratio_index[0] = (UWord16) L_add( (UWord16) L_shl( q_direction->band_data[0].energy_ratio_index[0], 1 ), bitstream[( *index )--] ); /*Q0*/ move16(); } @@ -2933,7 +2933,7 @@ static Word16 ivas_qmetadata_entropy_decode_diffuseness_hr_512( { FOR( k = 0; k < nblocks; k++ ) { - q_direction->band_data[b].energy_ratio_index[k] = ivas_qmetadata_DecodeQuasiUniform( bitstream, index, HR_MASA_ER_LEVELS ); + q_direction->band_data[b].energy_ratio_index[k] = ivas_qmetadata_DecodeQuasiUniform( bitstream, index, HR_MASA_ER_LEVELS ); /*Q0*/ move16(); } } @@ -2990,10 +2990,10 @@ static int16_t ivas_qmetadata_entropy_decode_diffuseness_hr_512( *-------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED static Word16 ivas_qmetadata_entropy_decode_df_ratio( - UWord16 *bitstream, - Word16 *index, + UWord16 *bitstream, /*Q0*/ + Word16 *index, /*Q0*/ IVAS_QDIRECTION *q_direction, - Word16 *dfRatio_bits ) + Word16 *dfRatio_bits /*Q0*/ ) { Word16 b; Word16 bits_raw; @@ -3021,7 +3021,7 @@ static Word16 ivas_qmetadata_entropy_decode_df_ratio( FOR( b = 0; b < dfRatio_bits[0]; b++ ) { // q_direction->band_data[0].energy_ratio_index[0] = ( q_direction->band_data[0].energy_ratio_index[0] << 1 ) + bitstream[( *index )--]; - q_direction->band_data[0].energy_ratio_index[0] = (UWord16) L_add( L_shl( q_direction->band_data[0].energy_ratio_index[0], 1 ), bitstream[( *index )--] ); + q_direction->band_data[0].energy_ratio_index[0] = (UWord16) L_add( L_shl( q_direction->band_data[0].energy_ratio_index[0], 1 ), bitstream[( *index )--] ); /*Q0*/ move16(); } return dfRatio_bits[0]; @@ -3055,7 +3055,7 @@ static Word16 ivas_qmetadata_entropy_decode_df_ratio( ec_mode = 0; move16(); } - max_alphabet_size = shl( 1, max_dfRatio_bits ); + max_alphabet_size = shl( 1, max_dfRatio_bits ); /* 1 << max_dfRatio_bits */ dec_mode = 2; /* Default to raw decoding */ move16(); @@ -3088,27 +3088,27 @@ static Word16 ivas_qmetadata_entropy_decode_df_ratio( { FOR( b = start_band; b < nbands; b++ ) { - q_direction->band_data[b].energy_ratio_index[0] = ivas_qmetadata_DecodeQuasiUniform( bitstream, index, (UWord16) L_shl( 1, dfRatio_bits[b] ) ); + q_direction->band_data[b].energy_ratio_index[0] = ivas_qmetadata_DecodeQuasiUniform( bitstream, index, (UWord16) L_shl( 1, dfRatio_bits[b] ) ); /*Q0*/ move16(); } } ELSE IF( EQ_16( dec_mode, 1 ) ) /* One value decoding */ { - ratio_min = ivas_qmetadata_DecodeQuasiUniform( bitstream, index, max_alphabet_size ); /* dif_unique_value */ + ratio_min = ivas_qmetadata_DecodeQuasiUniform( bitstream, index, max_alphabet_size ); /* dif_unique_value Q0*/ FOR( b = start_band; b < nbands; b++ ) { - q_direction->band_data[b].energy_ratio_index[0] = ratio_min; + q_direction->band_data[b].energy_ratio_index[0] = ratio_min; /*Q0*/ move16(); } } ELSE /* Bandwise 1-bit diff decoding */ { - ratio_min = ivas_qmetadata_DecodeQuasiUniform( bitstream, index, max_alphabet_size - 1 ); /* dif_min_value */ + ratio_min = ivas_qmetadata_DecodeQuasiUniform( bitstream, index, max_alphabet_size - 1 ); /* dif_min_value Q0*/ FOR( b = start_band; b < nbands; b++ ) { - q_direction->band_data[b].energy_ratio_index[0] = (UWord16) L_add( ratio_min, bitstream[( *index )--] ); /* dif_bit_offset_values */ + q_direction->band_data[b].energy_ratio_index[0] = (UWord16) L_add( ratio_min, bitstream[( *index )--] ); /* dif_bit_offset_values Q0*/ move16(); } } @@ -3237,13 +3237,13 @@ static int16_t ivas_qmetadata_entropy_decode_df_ratio( *------------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED static Word16 ivas_qmetadata_entropy_decode_dir_fx( - IVAS_QDIRECTION *q_direction, /* i/o: quantized direction structure */ - UWord16 *bitstream, /* i : bitstream */ - Word16 *index, - const UWord16 diffuseness_index_max_ec_frame, - const Word16 nbands, - const Word16 start_band, - const Word16 hrmasa_flag /* i : flag indicating high-rate MASA MD coding*/ + IVAS_QDIRECTION *q_direction, /* i/o: quantized direction structure */ + UWord16 *bitstream, /* i : bitstream Q0*/ + Word16 *index, /*Q0*/ + const UWord16 diffuseness_index_max_ec_frame, /*Q0*/ + const Word16 nbands, /*Q0*/ + const Word16 start_band, /*Q0*/ + const Word16 hrmasa_flag /* i : flag indicating high-rate MASA MD coding Q0*/ ) { Word16 b, m; @@ -3281,19 +3281,19 @@ static Word16 ivas_qmetadata_entropy_decode_dir_fx( } ELSE { - diff_idx = q_direction->band_data[b].energy_ratio_index_mod[0]; + diff_idx = q_direction->band_data[b].energy_ratio_index_mod[0]; /*Q0*/ move16(); } diff_idx_min = s_min( diff_idx_min, diff_idx ); IF( NE_32( q_direction->cfg.mc_ls_setup, MC_LS_SETUP_INVALID ) ) { - elev_alph[b] = no_theta_masa[sub( bits_direction_masa[diff_idx], 3 )]; + elev_alph[b] = no_theta_masa[( bits_direction_masa[diff_idx] - 3 )]; /*Q0*/ move16(); } ELSE { - elev_alph[b] = sub( shl( no_theta_masa[sub( bits_direction_masa[diff_idx], 3 )], 1 ), 1 ); + elev_alph[b] = sub( shl( no_theta_masa[( bits_direction_masa[diff_idx] - 3 )], 1 ), 1 ); /*Q0*/ move16(); } @@ -3316,11 +3316,11 @@ static Word16 ivas_qmetadata_entropy_decode_dir_fx( q_direction->band_data[b].elevation_index[m] = 0; move16(); - azith_alph[b][m] = no_phi_masa[sub( bits_direction_masa[diff_idx], 1 )][0]; + azith_alph[b][m] = no_phi_masa[( bits_direction_masa[diff_idx] - 1 )][0]; /*Q0*/ move16(); - q_direction->band_data[b].azimuth_index[m] = ivas_qmetadata_DecodeQuasiUniform( bitstream, index, azith_alph[b][m] ); + q_direction->band_data[b].azimuth_index[m] = ivas_qmetadata_DecodeQuasiUniform( bitstream, index, azith_alph[b][m] ); /*Q0*/ move16(); - q_direction->band_data[b].azimuth_fx[m] = deindex_azimuth_fx( q_direction->band_data[b].azimuth_index[m], q_direction->band_data[b].bits_sph_idx[m], 0, 1, q_direction->cfg.mc_ls_setup ); + q_direction->band_data[b].azimuth_fx[m] = deindex_azimuth_fx( q_direction->band_data[b].azimuth_index[m], q_direction->band_data[b].bits_sph_idx[m], 0, 1, q_direction->cfg.mc_ls_setup ); /*Q22*/ move32(); } } @@ -3339,15 +3339,15 @@ static Word16 ivas_qmetadata_entropy_decode_dir_fx( { IF( NE_32( q_direction->cfg.mc_ls_setup, MC_LS_SETUP_INVALID ) ) { - avg_elevation_alphabet = no_theta_masa[sub( bits_direction_masa[diff_idx_min], 3 )]; + avg_elevation_alphabet = no_theta_masa[( bits_direction_masa[diff_idx_min] - 3 )]; /*Q0*/ move16(); - avg_elevation_idx = ivas_qmetadata_DecodeQuasiUniform( bitstream, index, avg_elevation_alphabet ); + avg_elevation_idx = ivas_qmetadata_DecodeQuasiUniform( bitstream, index, avg_elevation_alphabet ); /*Q0*/ } ELSE { - avg_elevation_alphabet = sub( shl( no_theta_masa[sub( bits_direction_masa[diff_idx_min], 3 )], 1 ), 1 ); + avg_elevation_alphabet = sub( shl( no_theta_masa[( bits_direction_masa[diff_idx_min] - 3 )], 1 ), 1 ); /*Q0*/ avg_elevation_idx = ivas_qmetadata_DecodeQuasiUniform( bitstream, index, avg_elevation_alphabet ); - avg_elevation_idx = add( ivas_qmetadata_dereorder_generic( avg_elevation_idx ), shr( avg_elevation_alphabet, 1 ) ); + avg_elevation_idx = add( ivas_qmetadata_dereorder_generic( avg_elevation_idx ), shr( avg_elevation_alphabet, 1 ) ); /*Q0*/ } gr_param_elev = ivas_qmetadata_DecodeQuasiUniform( bitstream, index, 4 + 1 ); @@ -3366,27 +3366,27 @@ static Word16 ivas_qmetadata_entropy_decode_dir_fx( } ELSE { - diff_idx = q_direction->band_data[b].energy_ratio_index_mod[0]; + diff_idx = q_direction->band_data[b].energy_ratio_index_mod[0]; /*Q0*/ move16(); } IF( NE_32( q_direction->cfg.mc_ls_setup, MC_LS_SETUP_INVALID ) ) { - avg_elevation_index_projected = ivas_chan_project_elevation_index( avg_elevation_idx, avg_elevation_alphabet, elev_alph[b] ); + avg_elevation_index_projected = ivas_chan_project_elevation_index( avg_elevation_idx, avg_elevation_alphabet, elev_alph[b] ); /*Q0*/ } ELSE { - avg_elevation_index_projected = ivas_dirac_project_elevation_index( avg_elevation_idx, avg_elevation_alphabet, elev_alph[b] ); + avg_elevation_index_projected = ivas_dirac_project_elevation_index( avg_elevation_idx, avg_elevation_alphabet, elev_alph[b] ); /*Q0*/ /*reorder elevation indexing*/ - tmp_index = sub( avg_elevation_index_projected, shr( elev_alph[b], 1 ) ); + tmp_index = sub( avg_elevation_index_projected, shr( elev_alph[b], 1 ) ); /*Q0*/ IF( tmp_index < 0 ) { - tmp_index = negate( tmp_index * 2 ); + tmp_index = negate( imult1616( tmp_index, 2 ) ); } ELSE IF( tmp_index > 0 ) { - tmp_index = sub( ( tmp_index * 2 ), 1 ); + tmp_index = sub( imult1616( tmp_index, 2 ), 1 ); } avg_elevation_index_projected = tmp_index; move16(); @@ -3394,23 +3394,23 @@ static Word16 ivas_qmetadata_entropy_decode_dir_fx( FOR( m = 0; m < nblocks; m++ ) { - q_direction->band_data[b].elevation_index[m] = avg_elevation_index_projected; + q_direction->band_data[b].elevation_index[m] = avg_elevation_index_projected; /*Q0*/ move16(); /*deduce aplhabet for azimuth*/ IF( NE_32( q_direction->cfg.mc_ls_setup, MC_LS_SETUP_INVALID ) ) { - azith_alph[b][m] = no_phi_masa[sub( bits_direction_masa[diff_idx], 1 )][q_direction->band_data[b].elevation_index[m]]; + azith_alph[b][m] = no_phi_masa[( bits_direction_masa[diff_idx] - 1 )][q_direction->band_data[b].elevation_index[m]]; /*Q0*/ move16(); } ELSE { - azith_alph[b][m] = no_phi_masa[sub( bits_direction_masa[diff_idx], 1 )][extract_l( L_shr( L_add( q_direction->band_data[b].elevation_index[m], 1 ), 1 ) )]; + azith_alph[b][m] = no_phi_masa[( bits_direction_masa[diff_idx] - 1 )][extract_l( L_shr( L_add( q_direction->band_data[b].elevation_index[m], 1 ), 1 ) )]; /*Q0*/ move16(); } /*decode elevation*/ - q_direction->band_data[b].elevation_fx[m] = deindex_elevation_fx( &q_direction->band_data[b].elevation_index[m], q_direction->band_data[b].bits_sph_idx[m], q_direction->cfg.mc_ls_setup ); + q_direction->band_data[b].elevation_fx[m] = deindex_elevation_fx( &q_direction->band_data[b].elevation_index[m], q_direction->band_data[b].bits_sph_idx[m], q_direction->cfg.mc_ls_setup ); /*Q22*/ move32(); } } @@ -3429,7 +3429,7 @@ static Word16 ivas_qmetadata_entropy_decode_dir_fx( } ELSE { - diff_idx = q_direction->band_data[b].energy_ratio_index_mod[0]; + diff_idx = q_direction->band_data[b].energy_ratio_index_mod[0]; /*Q0*/ move16(); } @@ -3438,11 +3438,11 @@ static Word16 ivas_qmetadata_entropy_decode_dir_fx( Word16 tmp_index; IF( NE_32( q_direction->cfg.mc_ls_setup, MC_LS_SETUP_INVALID ) ) { - avg_elevation_index_projected = ivas_chan_project_elevation_index( avg_elevation_idx, avg_elevation_alphabet, elev_alph[b] ); - tmp_index = ivas_qmetadata_DecodeExtendedGR( bitstream, index, sub( shl( elev_alph[b], 1 ), 1 ), gr_param_elev ); + avg_elevation_index_projected = ivas_chan_project_elevation_index( avg_elevation_idx, avg_elevation_alphabet, elev_alph[b] ); /*Q0*/ + tmp_index = ivas_qmetadata_DecodeExtendedGR( bitstream, index, sub( shl( elev_alph[b], 1 ), 1 ), gr_param_elev ); /*Q0*/ IF( s_and( tmp_index, 1 ) ) { - tmp_index = add( avg_elevation_index_projected, shr( add( tmp_index, 1 ), 1 ) ); + tmp_index = add( avg_elevation_index_projected, shr( add( tmp_index, 1 ), 1 ) ); /*Q0*/ } ELSE { @@ -3452,15 +3452,15 @@ static Word16 ivas_qmetadata_entropy_decode_dir_fx( move16(); /*deduce aplhabet for azimuth*/ - azith_alph[b][m] = no_phi_masa[sub( bits_direction_masa[diff_idx], 1 )][q_direction->band_data[b].elevation_index[m]]; + azith_alph[b][m] = no_phi_masa[( bits_direction_masa[diff_idx] - 1 )][q_direction->band_data[b].elevation_index[m]]; /*Q0*/ move16(); } ELSE { - avg_elevation_index_projected = ivas_dirac_project_elevation_index( avg_elevation_idx, avg_elevation_alphabet, elev_alph[b] ); + avg_elevation_index_projected = ivas_dirac_project_elevation_index( avg_elevation_idx, avg_elevation_alphabet, elev_alph[b] ); /*Q0*/ - tmp_index = ivas_qmetadata_DecodeExtendedGR( bitstream, index, elev_alph[b], gr_param_elev ); - tmp_index = ivas_qmetadata_ReorderElevationDecoded( tmp_index, avg_elevation_index_projected, elev_alph[b] ); + tmp_index = ivas_qmetadata_DecodeExtendedGR( bitstream, index, elev_alph[b], gr_param_elev ); /*Q0*/ + tmp_index = ivas_qmetadata_ReorderElevationDecoded( tmp_index, avg_elevation_index_projected, elev_alph[b] ); /*Q0*/ /*reorder elevation indexing*/ tmp_index = sub( tmp_index, elev_alph[b] / 2 ); @@ -3476,12 +3476,12 @@ static Word16 ivas_qmetadata_entropy_decode_dir_fx( move16(); /*deduce aplhabet for azimuth*/ - azith_alph[b][m] = no_phi_masa[sub( bits_direction_masa[diff_idx], 1 )][extract_l( L_shr( L_add( q_direction->band_data[b].elevation_index[m], 1 ), 1 ) )]; + azith_alph[b][m] = no_phi_masa[( bits_direction_masa[diff_idx] - 1 )][extract_l( L_shr( L_add( q_direction->band_data[b].elevation_index[m], 1 ), 1 ) )]; /*Q0*/ move16(); } /*decode elevation*/ - q_direction->band_data[b].elevation_fx[m] = deindex_elevation_fx( &q_direction->band_data[b].elevation_index[m], q_direction->band_data[b].bits_sph_idx[m], q_direction->cfg.mc_ls_setup ); + q_direction->band_data[b].elevation_fx[m] = deindex_elevation_fx( &q_direction->band_data[b].elevation_index[m], q_direction->band_data[b].bits_sph_idx[m], q_direction->cfg.mc_ls_setup ); /*Q22*/ move32(); } } @@ -3501,7 +3501,7 @@ static Word16 ivas_qmetadata_entropy_decode_dir_fx( } ELSE { - diff_idx = q_direction->band_data[b].energy_ratio_index_mod[0]; + diff_idx = q_direction->band_data[b].energy_ratio_index_mod[0]; /*Q0*/ move16(); } @@ -3513,17 +3513,17 @@ static Word16 ivas_qmetadata_entropy_decode_dir_fx( /*deduce alphabet for azimuth*/ IF( NE_32( q_direction->cfg.mc_ls_setup, MC_LS_SETUP_INVALID ) ) { - azith_alph[b][m] = no_phi_masa[sub( bits_direction_masa[diff_idx], 1 )][q_direction->band_data[b].elevation_index[m]]; + azith_alph[b][m] = no_phi_masa[( bits_direction_masa[diff_idx] - 1 )][q_direction->band_data[b].elevation_index[m]]; /*Q0*/ move16(); } ELSE { - azith_alph[b][m] = no_phi_masa[sub( bits_direction_masa[diff_idx], 1 )][add( q_direction->band_data[b].elevation_index[m], 1 ) / 2]; + azith_alph[b][m] = no_phi_masa[( bits_direction_masa[diff_idx] - 1 )][add( q_direction->band_data[b].elevation_index[m], 1 ) / 2]; /*Q0*/ move16(); } /*decode elevation*/ - q_direction->band_data[b].elevation_fx[m] = deindex_elevation_fx( &q_direction->band_data[b].elevation_index[m], q_direction->band_data[b].bits_sph_idx[m], q_direction->cfg.mc_ls_setup ); + q_direction->band_data[b].elevation_fx[m] = deindex_elevation_fx( &q_direction->band_data[b].elevation_index[m], q_direction->band_data[b].bits_sph_idx[m], q_direction->cfg.mc_ls_setup ); /*Q22*/ move32(); } } @@ -3531,14 +3531,14 @@ static Word16 ivas_qmetadata_entropy_decode_dir_fx( } /*Azimuth*/ - avg_azimuth_alphabet = no_phi_masa[sub( bits_direction_masa[diff_idx_min], 1 )][0]; /* average azimuth is quantized on the equatorial plane */ + avg_azimuth_alphabet = no_phi_masa[( bits_direction_masa[diff_idx_min] - 1 )][0]; /* average azimuth is quantized on the equatorial plane Q0*/ move16(); - avg_azimuth_index = ivas_qmetadata_DecodeQuasiUniform( bitstream, index, avg_azimuth_alphabet ); - avg_azimuth_index = ivas_qmetadata_dereorder_generic( avg_azimuth_index ); - avg_azimuth_index = add( avg_azimuth_index, shr( avg_azimuth_alphabet, 1 ) ); + avg_azimuth_index = ivas_qmetadata_DecodeQuasiUniform( bitstream, index, avg_azimuth_alphabet ); /*Q0*/ + avg_azimuth_index = ivas_qmetadata_dereorder_generic( avg_azimuth_index ); /*Q0*/ + avg_azimuth_index = add( avg_azimuth_index, shr( avg_azimuth_alphabet, 1 ) ); /*Q0*/ - gr_param_azith = ivas_qmetadata_DecodeQuasiUniform( bitstream, index, 5 + 1 ); - IF( EQ_32( gr_param_azith, 5 ) ) /* all the azimuth distances are zero */ + gr_param_azith = ivas_qmetadata_DecodeQuasiUniform( bitstream, index, 5 + 1 ); /*Q0*/ + IF( EQ_32( gr_param_azith, 5 ) ) /* all the azimuth distances are zero */ { FOR( b = start_band; b < nbands; b++ ) { @@ -3546,7 +3546,7 @@ static Word16 ivas_qmetadata_entropy_decode_dir_fx( { FOR( m = 0; m < nblocks; m++ ) { - q_direction->band_data[b].azimuth_index[m] = ivas_dirac_project_azimuth_index( avg_azimuth_index, avg_azimuth_alphabet, azith_alph[b][m] ); + q_direction->band_data[b].azimuth_index[m] = ivas_dirac_project_azimuth_index( avg_azimuth_index, avg_azimuth_alphabet, azith_alph[b][m] ); /*Q0*/ move16(); IF( EQ_16( azith_alph[b][m], 1 ) ) @@ -3556,7 +3556,7 @@ static Word16 ivas_qmetadata_entropy_decode_dir_fx( } ELSE { - q_direction->band_data[b].azimuth_fx[m] = deindex_azimuth_fx( q_direction->band_data[b].azimuth_index[m], q_direction->band_data[b].bits_sph_idx[m], q_direction->band_data[b].elevation_index[m], 0, q_direction->cfg.mc_ls_setup ); + q_direction->band_data[b].azimuth_fx[m] = deindex_azimuth_fx( q_direction->band_data[b].azimuth_index[m], q_direction->band_data[b].bits_sph_idx[m], q_direction->band_data[b].elevation_index[m], 0, q_direction->cfg.mc_ls_setup ); /*Q22*/ move32(); } } @@ -3579,15 +3579,15 @@ static Word16 ivas_qmetadata_entropy_decode_dir_fx( { IF( NE_32( q_direction->cfg.mc_ls_setup, MC_LS_SETUP_INVALID ) && EQ_16( idx, MASA_LIMIT_IDX_AVG_AZI ) && GT_16( nblocks, 1 ) ) { - use_adapt_avg = bitstream[*index]; + use_adapt_avg = bitstream[*index]; /*Q0*/ move16(); ( *index ) = sub( *index, 1 ); move16(); } - avg_azimuth_index_projected = ivas_dirac_project_azimuth_index( avg_azimuth_index, avg_azimuth_alphabet, azith_alph[b][m] ); - q_direction->band_data[b].azimuth_index[m] = ivas_qmetadata_DecodeExtendedGR( bitstream, index, azith_alph[b][m], gr_param_azith ); + avg_azimuth_index_projected = ivas_dirac_project_azimuth_index( avg_azimuth_index, avg_azimuth_alphabet, azith_alph[b][m] ); /*Q0*/ + q_direction->band_data[b].azimuth_index[m] = ivas_qmetadata_DecodeExtendedGR( bitstream, index, azith_alph[b][m], gr_param_azith ); /*Q0*/ move16(); - q_direction->band_data[b].azimuth_index[m] = ivas_qmetadata_ReorderElevationDecoded( q_direction->band_data[b].azimuth_index[m], avg_azimuth_index_projected, azith_alph[b][m] ); + q_direction->band_data[b].azimuth_index[m] = ivas_qmetadata_ReorderElevationDecoded( q_direction->band_data[b].azimuth_index[m], avg_azimuth_index_projected, azith_alph[b][m] ); /*Q0*/ move16(); IF( EQ_16( azith_alph[b][m], 1 ) ) @@ -3597,7 +3597,7 @@ static Word16 ivas_qmetadata_entropy_decode_dir_fx( } ELSE { - q_direction->band_data[b].azimuth_fx[m] = deindex_azimuth_fx( q_direction->band_data[b].azimuth_index[m], q_direction->band_data[b].bits_sph_idx[m], q_direction->band_data[b].elevation_index[m], 0, q_direction->cfg.mc_ls_setup ); + q_direction->band_data[b].azimuth_fx[m] = deindex_azimuth_fx( q_direction->band_data[b].azimuth_index[m], q_direction->band_data[b].bits_sph_idx[m], q_direction->band_data[b].elevation_index[m], 0, q_direction->cfg.mc_ls_setup ); /*Q22*/ move32(); } @@ -3607,8 +3607,8 @@ static Word16 ivas_qmetadata_entropy_decode_dir_fx( IF( LT_16( idx, MASA_LIMIT_IDX_AVG_AZI ) ) { ivas_qmetadata_azimuth_elevation_to_direction_vector_fx( q_direction->band_data[b].azimuth_fx[m], q_direction->band_data[b].elevation_fx[m], direction_vector_fx ); - v_shr_32( direction_vector_fx, direction_vector_fx, 3, 5 ); - v_add_32( avg_direction_vector_fx, direction_vector_fx, avg_direction_vector_fx, 3 ); + v_shr_32( direction_vector_fx, direction_vector_fx, 3, 5 ); /*Q25*/ + v_add_32( avg_direction_vector_fx, direction_vector_fx, avg_direction_vector_fx, 3 ); /*Q25*/ } ELSE { @@ -3618,16 +3618,16 @@ static Word16 ivas_qmetadata_entropy_decode_dir_fx( { FOR( Word16 l = 0; l < 3; l++ ) { - avg_direction_vector_fx[l] = L_shr( avg_direction_vector_fx[l], 1 ); + avg_direction_vector_fx[l] = L_shr( avg_direction_vector_fx[l], 1 ); /*0.5f*/ move32(); } } /*compute the average direction per already coded subband */ ivas_qmetadata_azimuth_elevation_to_direction_vector_fx( q_direction->band_data[b].azimuth_fx[m], q_direction->band_data[b].elevation_fx[m], direction_vector_fx ); - v_shr_32( direction_vector_fx, direction_vector_fx, 3, 5 ); - v_add_32( avg_direction_vector_fx, direction_vector_fx, avg_direction_vector_fx, 3 ); + v_shr_32( direction_vector_fx, direction_vector_fx, 3, 5 ); /*Q25*/ + v_add_32( avg_direction_vector_fx, direction_vector_fx, avg_direction_vector_fx, 3 ); /*Q25*/ ivas_qmetadata_direction_vector_to_azimuth_elevation_fx( avg_direction_vector_fx, 30 - 5, &avg_azimuth_fx, &avg_elevation_fx ); - avg_azimuth_index = quantize_phi_fx( L_add( avg_azimuth_fx, DEGREE_180_Q_22 ), 0, &avg_azimuth_fx, avg_azimuth_alphabet ); + avg_azimuth_index = quantize_phi_fx( L_add( avg_azimuth_fx, DEGREE_180_Q_22 ), 0, &avg_azimuth_fx, avg_azimuth_alphabet ); /*Q0*/ } } idx = add( idx, 1 ); @@ -3996,11 +3996,11 @@ static int16_t ivas_qmetadata_entropy_decode_dir( *------------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED static Word16 ivas_qmetadata_raw_decode_dir_512_fx( - IVAS_QDIRECTION *q_direction, /* i/o: quantized direction structure */ - UWord16 *bitstream, /* i : bitstream */ - Word16 *index, - const Word16 nbands, - const Word16 start_band, + IVAS_QDIRECTION *q_direction, /* i/o: quantized direction structure */ + UWord16 *bitstream, /* i : bitstream Q0*/ + Word16 *index, /*Q0*/ + const Word16 nbands, /*Q0*/ + const Word16 start_band, /*Q0*/ const SPHERICAL_GRID_DATA *sph_grid16 /* i : spherical grid for deindexing */ ) { @@ -4088,11 +4088,11 @@ static int16_t ivas_qmetadata_raw_decode_dir_512( #ifdef IVAS_FLOAT_FIXED static Word16 ivas_qmetadata_raw_decode_dir_fx( IVAS_QDIRECTION *q_direction, /* i/o: quantized direction structure */ - UWord16 *bitstream, /* i : bitstream */ - Word16 *index, - const Word16 nbands, - const Word16 start_band, - const Word16 hrmasa_flag /* i : flag indicating high-rate MASA MD coding*/ + UWord16 *bitstream, /* i : bitstream Q0*/ + Word16 *index, /*Q0*/ + const Word16 nbands, /*Q0*/ + const Word16 start_band, /*Q0*/ + const Word16 hrmasa_flag /* i : flag indicating high-rate MASA MD coding Q0*/ ) { Word16 b, m, azith_alph; @@ -4120,7 +4120,7 @@ static Word16 ivas_qmetadata_raw_decode_dir_fx( } ELSE { - diff_idx = q_direction->band_data[b].energy_ratio_index_mod[0]; + diff_idx = q_direction->band_data[b].energy_ratio_index_mod[0]; /*Q0*/ move16(); } @@ -4130,11 +4130,11 @@ static Word16 ivas_qmetadata_raw_decode_dir_fx( move32(); q_direction->band_data[b].elevation_index[m] = 0; move16(); - azith_alph = no_phi_masa[bits_direction_masa[diff_idx] - 1][0]; + azith_alph = no_phi_masa[bits_direction_masa[diff_idx] - 1][0]; /*Q0*/ move16(); - q_direction->band_data[b].azimuth_index[m] = ivas_qmetadata_DecodeQuasiUniform( bitstream, index, azith_alph ); + q_direction->band_data[b].azimuth_index[m] = ivas_qmetadata_DecodeQuasiUniform( bitstream, index, azith_alph ); /*Q0*/ move16(); - q_direction->band_data[b].azimuth_fx[m] = deindex_azimuth_fx( q_direction->band_data[b].azimuth_index[m], q_direction->band_data[b].bits_sph_idx[m], 0, 1, q_direction->cfg.mc_ls_setup ); + q_direction->band_data[b].azimuth_fx[m] = deindex_azimuth_fx( q_direction->band_data[b].azimuth_index[m], q_direction->band_data[b].bits_sph_idx[m], 0, 1, q_direction->cfg.mc_ls_setup ); /*Q22*/ move32(); } } @@ -4207,9 +4207,9 @@ static int16_t ivas_qmetadata_raw_decode_dir( /*! r: Value read from the bitstream */ #ifdef IVAS_FLOAT_FIXED static UWord16 ivas_qmetadata_DecodeQuasiUniform( - const UWord16 *bitstream, /* i : pointer to the bitstream to read */ - Word16 *index, /* i : position in the bitstream to start reading (gets updated with reading) */ - const UWord16 alphabet_size /* i : size of the alphabet, used to calculate the number of bits needed */ + const UWord16 *bitstream, /* i : pointer to the bitstream to read Q0*/ + Word16 *index, /* i : position in the bitstream to start reading (gets updated with reading) Q0*/ + const UWord16 alphabet_size /* i : size of the alphabet, used to calculate the number of bits needed Q0*/ ) { Word16 i, bits; @@ -4223,12 +4223,12 @@ static UWord16 ivas_qmetadata_DecodeQuasiUniform( move16(); FOR( i = 0; i < bits; i++ ) { - value = (UWord16) L_add( (UWord16) L_shl( value, 1 ), bitstream[( *index )--] ); + value = (UWord16) L_add( (UWord16) L_shl( value, 1 ), bitstream[( *index )--] ); /*Q0*/ } IF( GE_32( value, tresh ) ) { - value = (UWord16) L_add( (UWord16) L_sub( (UWord16) L_shl( value, 1 ), tresh ), bitstream[( *index )--] ); + value = (UWord16) L_add( (UWord16) L_sub( (UWord16) L_shl( value, 1 ), tresh ), bitstream[( *index )--] ); /*Q0*/ } return value; @@ -4273,7 +4273,7 @@ static uint16_t ivas_qmetadata_DecodeQuasiUniform( #ifdef IVAS_FLOAT_FIXED Word16 ivas_qmetadata_DecodeExtendedGR( - UWord16 *bitstream, /* i : pointer to the bitstream to read */ + UWord16 *bitstream, /* i : pointer to the bitstream to read Q0*/ Word16 *index, /* i/o: position in the bitstream to start reading (gets updated with reading) */ const Word16 alph_size, /* i : size of the alphabet, used to calculate the number of bits needed */ const Word16 gr_param /* i : GR parameter that indicates the limit for the most significant bits (msb) */ @@ -4283,10 +4283,10 @@ Word16 ivas_qmetadata_DecodeExtendedGR( UWord16 value; Word16 msb, lsb; - msb_size = shr( add( alph_size, sub( shl( 1, gr_param ), 1 ) ), gr_param ); /* ceil division */ + msb_size = shr( add( alph_size, sub( shl( 1, gr_param ), 1 ) ), gr_param ); /* ceil division Q0*/ IF( LE_16( msb_size, 3 ) ) { - value = ivas_qmetadata_DecodeQuasiUniform( bitstream, index, alph_size ); + value = ivas_qmetadata_DecodeQuasiUniform( bitstream, index, alph_size ); /*Q0*/ } ELSE { @@ -4303,7 +4303,7 @@ Word16 ivas_qmetadata_DecodeExtendedGR( IF( EQ_16( msb, sub( msb_size, 1 ) ) ) { - lsb = ivas_qmetadata_DecodeQuasiUniform( bitstream, index, sub( alph_size, shl( sub( msb_size, 1 ), gr_param ) ) ); + lsb = ivas_qmetadata_DecodeQuasiUniform( bitstream, index, sub( alph_size, shl( sub( msb_size, 1 ), gr_param ) ) ); /*Q0*/ } ELSE { @@ -4313,11 +4313,11 @@ Word16 ivas_qmetadata_DecodeExtendedGR( move16(); FOR( i = 0; i < gr_param; i++ ) { - lsb = extract_l( L_add( shl( lsb, 1 ), bitstream[( *index )--] ) ); + lsb = extract_l( L_add( shl( lsb, 1 ), bitstream[( *index )--] ) ); /*Q0*/ } } - value = (UWord16) add( shl( msb, gr_param ), lsb ); + value = (UWord16) add( shl( msb, gr_param ), lsb ); /*Q0*/ } return value; @@ -4378,15 +4378,15 @@ int16_t ivas_qmetadata_DecodeExtendedGR( /*! r: Elevation index as it will be read by the dequantizer */ #ifdef IVAS_FLOAT_FIXED static Word16 ivas_qmetadata_ReorderElevationDecoded( - const Word16 elev_dist, /* i : Distance to the average extracted from the bitstream */ - const Word16 elev_avg, /* i : Average value over time-blocks extracted from the bitstream */ - const Word16 elev_alph /* i : elevation alphabet */ + const Word16 elev_dist, /* i : Distance to the average extracted from the bitstream Q0*/ + const Word16 elev_avg, /* i : Average value over time-blocks extracted from the bitstream Q0*/ + const Word16 elev_alph /* i : elevation alphabet Q0*/ ) { Word16 dist_reorder; Word16 elev_index_reorder; - dist_reorder = ivas_qmetadata_dereorder_generic( elev_dist ); + dist_reorder = ivas_qmetadata_dereorder_generic( elev_dist ); /*Q0*/ elev_index_reorder = add( elev_avg, dist_reorder ); IF( elev_index_reorder < 0 ) @@ -4398,7 +4398,7 @@ static Word16 ivas_qmetadata_ReorderElevationDecoded( elev_index_reorder = sub( elev_index_reorder, elev_alph ); } - return elev_index_reorder; + return elev_index_reorder; /*Q0*/ } #else static int16_t ivas_qmetadata_ReorderElevationDecoded( @@ -4435,11 +4435,11 @@ static int16_t ivas_qmetadata_ReorderElevationDecoded( #ifdef IVAS_FLOAT_FIXED static Word16 read_directions_fx( IVAS_QDIRECTION *q_direction, /* i/o: quantized direction structure */ - const UWord8 coding_subbands, /* i : number of directions */ - const UWord8 masa_subframes, /* i : number of tiles */ - UWord16 *bitstream, /* i : bitstream to be read */ - Word16 *pbit_pos, - Word16 *ind_order ) + const UWord8 coding_subbands, /* i : number of directions Q0*/ + const UWord8 masa_subframes, /* i : number of tiles Q0*/ + UWord16 *bitstream, /* i : bitstream to be read Q0*/ + Word16 *pbit_pos, /*Q0*/ + Word16 *ind_order /*Q0*/ ) { Word16 j, k, allowed_bits, last_j, nbits, fixed_rate; Word16 i; @@ -4459,14 +4459,14 @@ static Word16 read_directions_fx( IF( GT_16( coding_subbands, 1 ) ) { - j = ind_order[sub( coding_subbands, 1 )]; + j = ind_order[( coding_subbands - 1 )]; move16(); allowed_bits = 0; move16(); FOR( k = 0; k < masa_subframes; k++ ) { - allowed_bits = extract_l( L_add( allowed_bits, q_direction->band_data[j].bits_sph_idx[k] ) ); + allowed_bits = extract_l( L_add( allowed_bits, q_direction->band_data[j].bits_sph_idx[k] ) ); /*Q0*/ } last_j = sub( j, (Word16) ( allowed_bits == 0 ) ); @@ -4475,7 +4475,7 @@ static Word16 read_directions_fx( { i = ind_order[j]; move16(); - bits_dir0 = (Word16 *) q_direction->band_data[i].bits_sph_idx; + bits_dir0 = (Word16 *) q_direction->band_data[i].bits_sph_idx; /*Q0*/ nbits = 0; move16(); @@ -4524,13 +4524,13 @@ static Word16 read_directions_fx( FOR( k = 0; k < masa_subframes; k++ ) { - q_direction->band_data[i].bits_sph_idx[k] = bits_dir0[k]; + q_direction->band_data[i].bits_sph_idx[k] = bits_dir0[k]; /*Q0*/ move16(); IF( GT_16( bits_dir0[k], 2 ) ) { IF( NE_32( q_direction->cfg.mc_ls_setup, MC_LS_SETUP_INVALID ) ) { - q_direction->band_data[i].elevation_m_alphabet[k] = no_theta_masa[bits_dir0[k] - 3]; + q_direction->band_data[i].elevation_m_alphabet[k] = no_theta_masa[bits_dir0[k] - 3]; /*Q0*/ move16(); } ELSE @@ -4550,7 +4550,7 @@ static Word16 read_directions_fx( { IF( EQ_32( byteBuffer, 1 ) ) { - nbits = read_common_direction_fx( bitstream, q_direction, i, masa_subframes, allowed_bits, &bit_pos ); + nbits = read_common_direction_fx( bitstream, q_direction, i, masa_subframes, allowed_bits, &bit_pos ); /*Q0*/ } ELSE { @@ -4581,9 +4581,9 @@ static Word16 read_directions_fx( { /* decode elevation */ - nbits = add( nbits, decode_elevation_fx( q_direction, bitstream, &bit_pos, i, masa_subframes ) ); + nbits = add( nbits, decode_elevation_fx( q_direction, bitstream, &bit_pos, i, masa_subframes ) ); /*Q0*/ /* decode azimuth */ - nbits = add( nbits, decode_azimuth_fx( q_direction, bitstream, &bit_pos, i, masa_subframes ) ); + nbits = add( nbits, decode_azimuth_fx( q_direction, bitstream, &bit_pos, i, masa_subframes ) ); /*Q0*/ } } } @@ -4600,7 +4600,7 @@ static Word16 read_directions_fx( } ELSE { - last_j = q_direction->cfg.start_band; + last_j = q_direction->cfg.start_band; /*Q0*/ move16(); } @@ -4609,15 +4609,15 @@ static Word16 read_directions_fx( { i = ind_order[j]; move16(); - bits_dir0 = (Word16 *) q_direction->band_data[i].bits_sph_idx; + bits_dir0 = (Word16 *) q_direction->band_data[i].bits_sph_idx; /*Q0*/ nbits = 0; move16(); - allowed_bits = sum16_fx( bits_dir0, q_direction->cfg.nblocks ); + allowed_bits = sum16_fx( bits_dir0, q_direction->cfg.nblocks ); /*Q0*/ test(); IF( allowed_bits > 0 && EQ_16( masa_subframes, 1 ) ) { - nbits = add( nbits, decode_fixed_rate_fx( q_direction, bitstream, &bit_pos, i, masa_subframes ) ); + nbits = add( nbits, decode_fixed_rate_fx( q_direction, bitstream, &bit_pos, i, masa_subframes ) ); /*Q0*/ } ELSE { @@ -4631,7 +4631,7 @@ static Word16 read_directions_fx( { IF( GT_16( bits_dir0[k], use_vq ) ) { - use_vq = bits_dir0[k]; + use_vq = bits_dir0[k]; /*Q0*/ move16(); max_nb_idx = k; move16(); @@ -4658,7 +4658,7 @@ static Word16 read_directions_fx( test(); IF( EQ_32( byteBuffer, 1 ) || LE_16( use_vq, 1 ) ) { - nbits = read_common_direction_fx( bitstream, q_direction, i, masa_subframes, allowed_bits, &bit_pos ); + nbits = read_common_direction_fx( bitstream, q_direction, i, masa_subframes, allowed_bits, &bit_pos ); /*Q0*/ } ELSE { @@ -4692,7 +4692,7 @@ static Word16 read_directions_fx( } } - nbits = decode_azimuth2D_fx( q_direction, bitstream, coding_subbands, &bit_pos, masa_subframes ); + nbits = decode_azimuth2D_fx( q_direction, bitstream, coding_subbands, &bit_pos, masa_subframes ); /*Q0*/ } nbits = sub( *pbit_pos, bit_pos ); *pbit_pos = bit_pos; @@ -4936,10 +4936,10 @@ static int16_t read_directions( #ifdef IVAS_FLOAT_FIXED static Word16 decode_azimuth_fx( IVAS_QDIRECTION *q_direction, /* i/o: quantized metadata structure */ - UWord16 *bitstream, /* i : bitstream to be read */ - Word16 *pbit_pos, /* i/o: current position in bitstream */ - const Word16 idx_subband, /* i : subband index */ - const Word16 masa_subframes /* i : number of tiles */ + UWord16 *bitstream, /* i : bitstream to be read Q0*/ + Word16 *pbit_pos, /* i/o: current position in bitstream Q0*/ + const Word16 idx_subband, /* i : subband index Q0*/ + const Word16 masa_subframes /* i : number of tiles Q0*/ ) { Word16 bit_pos, nbits, k; @@ -5006,18 +5006,18 @@ static Word16 decode_azimuth_fx( { byteBuffer = bitstream[bit_pos--]; move16(); - q_direction->band_data[idx_subband].azimuth_index[k] = byteBuffer; + q_direction->band_data[idx_subband].azimuth_index[k] = byteBuffer; /*Q0*/ move16(); - q_direction->band_data[idx_subband].azimuth_fx[k] = L_shl( L_mult0( q_direction->band_data[idx_subband].azimuth_index[k], -180 ), Q22 ); + q_direction->band_data[idx_subband].azimuth_fx[k] = L_shl( L_mult0( q_direction->band_data[idx_subband].azimuth_index[k], -180 ), Q22 ); /*Q22*/ move32(); } ELSE { - q_direction->band_data[idx_subband].azimuth_index[k] = ivas_qmetadata_DecodeExtendedGR( bitstream, &bit_pos, q_direction->band_data[idx_subband].azimuth_m_alphabet[k], sub( MASA_GR_ORD_AZ, (Word16) EQ_32( q_direction->band_data[idx_subband].bits_sph_idx[k], 2 ) ) ); + q_direction->band_data[idx_subband].azimuth_index[k] = ivas_qmetadata_DecodeExtendedGR( bitstream, &bit_pos, q_direction->band_data[idx_subband].azimuth_m_alphabet[k], sub( MASA_GR_ORD_AZ, (Word16) EQ_32( q_direction->band_data[idx_subband].bits_sph_idx[k], 2 ) ) ); /*Q0*/ move16(); - q_direction->band_data[idx_subband].azimuth_fx[k] = deindex_azimuth_fx( q_direction->band_data[idx_subband].azimuth_index[k], q_direction->band_data[idx_subband].bits_sph_idx[k], q_direction->band_data[idx_subband].elevation_index[k], 1, q_direction->cfg.mc_ls_setup ); + q_direction->band_data[idx_subband].azimuth_fx[k] = deindex_azimuth_fx( q_direction->band_data[idx_subband].azimuth_index[k], q_direction->band_data[idx_subband].bits_sph_idx[k], q_direction->band_data[idx_subband].elevation_index[k], 1, q_direction->cfg.mc_ls_setup ); /*Q22*/ move32(); } } @@ -5026,7 +5026,7 @@ static Word16 decode_azimuth_fx( ELSE { /* read bit to check if min removed encoding */ - byteBuffer = bitstream[bit_pos]; + byteBuffer = bitstream[bit_pos]; /*Q22*/ move16(); bit_pos = sub( bit_pos, 1 ); IF( byteBuffer == 0 ) /* regular GR coding5 */ @@ -5043,9 +5043,9 @@ static Word16 decode_azimuth_fx( { IF( GT_16( no_phi_masa[L_sub( q_direction->band_data[idx_subband].bits_sph_idx[k], 1 )][q_direction->band_data[idx_subband].elevation_index[k]], 1 ) ) { - q_direction->band_data[idx_subband].azimuth_index[k] = ivas_qmetadata_DecodeExtendedGR( bitstream, &bit_pos, q_direction->band_data[idx_subband].azimuth_m_alphabet[k], extract_l( L_sub( MASA_GR_ORD_AZ, byteBuffer ) ) ); + q_direction->band_data[idx_subband].azimuth_index[k] = ivas_qmetadata_DecodeExtendedGR( bitstream, &bit_pos, q_direction->band_data[idx_subband].azimuth_m_alphabet[k], extract_l( L_sub( MASA_GR_ORD_AZ, byteBuffer ) ) ); /*Q0*/ move16(); - q_direction->band_data[idx_subband].azimuth_fx[k] = deindex_azimuth_fx( q_direction->band_data[idx_subband].azimuth_index[k], q_direction->band_data[idx_subband].bits_sph_idx[k], q_direction->band_data[idx_subband].elevation_index[k], 1, q_direction->cfg.mc_ls_setup ); + q_direction->band_data[idx_subband].azimuth_fx[k] = deindex_azimuth_fx( q_direction->band_data[idx_subband].azimuth_index[k], q_direction->band_data[idx_subband].bits_sph_idx[k], q_direction->band_data[idx_subband].elevation_index[k], 1, q_direction->cfg.mc_ls_setup ); /*Q22*/ move32(); } ELSE @@ -5069,12 +5069,12 @@ static Word16 decode_azimuth_fx( { /* min removed GR coding */ /* read GR_order */ - byteBuffer = bitstream[bit_pos]; + byteBuffer = bitstream[bit_pos]; /*Q0*/ move16(); bit_pos = sub( bit_pos, 1 ); /* read min index value */ maximum_s( q_direction->band_data[idx_subband].azimuth_m_alphabet, masa_subframes, &max_val ); - min_idx = ivas_qmetadata_DecodeExtendedGR( bitstream, &bit_pos, max_val, MASA_GR_ORD_AZ ); + min_idx = ivas_qmetadata_DecodeExtendedGR( bitstream, &bit_pos, max_val, MASA_GR_ORD_AZ ); /*Q0*/ FOR( k = 0; k < masa_subframes; k++ ) { @@ -5082,11 +5082,11 @@ static Word16 decode_azimuth_fx( { IF( GT_16( no_phi_masa[q_direction->band_data[idx_subband].bits_sph_idx[k] - 1][q_direction->band_data[idx_subband].elevation_index[k]], 1 ) ) { - q_direction->band_data[idx_subband].azimuth_index[k] = ivas_qmetadata_DecodeExtendedGR( bitstream, &bit_pos, q_direction->band_data[idx_subband].azimuth_m_alphabet[k], extract_l( L_sub( MASA_GR_ORD_AZ - 1, byteBuffer ) ) ); + q_direction->band_data[idx_subband].azimuth_index[k] = ivas_qmetadata_DecodeExtendedGR( bitstream, &bit_pos, q_direction->band_data[idx_subband].azimuth_m_alphabet[k], extract_l( L_sub( MASA_GR_ORD_AZ - 1, byteBuffer ) ) ); /*Q0*/ move16(); - q_direction->band_data[idx_subband].azimuth_index[k] = (UWord16) L_add( q_direction->band_data[idx_subband].azimuth_index[k], min_idx ); + q_direction->band_data[idx_subband].azimuth_index[k] = (UWord16) L_add( q_direction->band_data[idx_subband].azimuth_index[k], min_idx ); /*Q0*/ move16(); - q_direction->band_data[idx_subband].azimuth_fx[k] = deindex_azimuth_fx( q_direction->band_data[idx_subband].azimuth_index[k], q_direction->band_data[idx_subband].bits_sph_idx[k], q_direction->band_data[idx_subband].elevation_index[k], 1, q_direction->cfg.mc_ls_setup ); + q_direction->band_data[idx_subband].azimuth_fx[k] = deindex_azimuth_fx( q_direction->band_data[idx_subband].azimuth_index[k], q_direction->band_data[idx_subband].bits_sph_idx[k], q_direction->band_data[idx_subband].elevation_index[k], 1, q_direction->cfg.mc_ls_setup ); /*Q22*/ move32(); } ELSE @@ -5278,10 +5278,10 @@ static int16_t decode_azimuth( #ifdef IVAS_FLOAT_FIXED static Word16 decode_elevation_fx( IVAS_QDIRECTION *q_direction, /* i/o: quantized metadata structure */ - UWord16 *bitstream, /* i : input bitstream */ - Word16 *pbit_pos, /* i/o: current position to be read in bitstream*/ - const Word16 j, /* i : subband index */ - const Word16 masa_subframes /* i : number of tiles */ + UWord16 *bitstream, /* i : input bitstream Q0*/ + Word16 *pbit_pos, /* i/o: current position to be read in bitstream Q0*/ + const Word16 j, /* i : subband index Q0*/ + const Word16 masa_subframes /* i : number of tiles Q0*/ ) { Word16 nr_NO_INDEX, nbits; @@ -5308,7 +5308,7 @@ static Word16 decode_elevation_fx( { IF( LE_32( q_direction->band_data[j].bits_sph_idx[k], 2 ) ) { - q_direction->band_data[j].elevation_index[k] = MASA_NO_INDEX; + q_direction->band_data[j].elevation_index[k] = MASA_NO_INDEX; /*Q0*/ move16(); nr_NO_INDEX = add( nr_NO_INDEX, 1 ); q_direction->band_data[j].elevation_fx[k] = 0; @@ -5320,12 +5320,12 @@ static Word16 decode_elevation_fx( { IF( NE_32( q_direction->cfg.mc_ls_setup, MC_LS_SETUP_INVALID ) ) { - q_direction->band_data[j].elevation_m_alphabet[k] = no_theta_masa[q_direction->band_data[j].bits_sph_idx[k] - 3]; + q_direction->band_data[j].elevation_m_alphabet[k] = no_theta_masa[q_direction->band_data[j].bits_sph_idx[k] - 3]; /*Q0*/ move16(); } ELSE { - q_direction->band_data[j].elevation_m_alphabet[k] = shl( no_theta_masa[q_direction->band_data[j].bits_sph_idx[k] - 3], 1 ) - 1; + q_direction->band_data[j].elevation_m_alphabet[k] = shl( no_theta_masa[q_direction->band_data[j].bits_sph_idx[k] - 3], 1 ) - 1; /*Q0*/ move16(); } } @@ -5346,7 +5346,7 @@ static Word16 decode_elevation_fx( IF( EQ_32( byteBuffer, 1 ) ) /* same value */ { /* read value */ - byteBuffer = bitstream[bit_pos]; + byteBuffer = bitstream[bit_pos]; /*Q0*/ move16(); bit_pos = sub( bit_pos, 1 ); byteBuffer = (UWord16) L_add( L_shl( byteBuffer, 1 ), bitstream[bit_pos] ); @@ -5359,9 +5359,9 @@ static Word16 decode_elevation_fx( { IF( LT_32( q_direction->band_data[j].elevation_index[k], MASA_NO_INDEX ) ) { - q_direction->band_data[j].elevation_index[k] = same_idx; + q_direction->band_data[j].elevation_index[k] = same_idx; /*Q0*/ move16(); - q_direction->band_data[j].elevation_fx[k] = deindex_elevation_fx( &q_direction->band_data[j].elevation_index[k], q_direction->band_data[j].bits_sph_idx[k], q_direction->cfg.mc_ls_setup ); + q_direction->band_data[j].elevation_fx[k] = deindex_elevation_fx( &q_direction->band_data[j].elevation_index[k], q_direction->band_data[j].bits_sph_idx[k], q_direction->cfg.mc_ls_setup ); /*Q22*/ move32(); } } @@ -5369,18 +5369,18 @@ static Word16 decode_elevation_fx( ELSE { /* not same; decode mean removed GR */ - byteBuffer = bitstream[bit_pos]; + byteBuffer = bitstream[bit_pos]; /*Q0*/ bit_pos = sub( bit_pos, 1 ); move16(); - GR_ord_elevation = extract_l( L_sub( MASA_GR_ORD_EL, byteBuffer ) ); + GR_ord_elevation = extract_l( L_sub( MASA_GR_ORD_EL, byteBuffer ) ); /*Q0*/ FOR( k = 0; k < masa_subframes; k++ ) { IF( LT_32( q_direction->band_data[j].elevation_index[k], MASA_NO_INDEX ) ) { - q_direction->band_data[j].elevation_index[k] = ivas_qmetadata_DecodeExtendedGR( bitstream, &bit_pos, q_direction->band_data[j].elevation_m_alphabet[k], GR_ord_elevation ); + q_direction->band_data[j].elevation_index[k] = ivas_qmetadata_DecodeExtendedGR( bitstream, &bit_pos, q_direction->band_data[j].elevation_m_alphabet[k], GR_ord_elevation ); /*Q0*/ move16(); - q_direction->band_data[j].elevation_fx[k] = deindex_elevation_fx( &q_direction->band_data[j].elevation_index[k], q_direction->band_data[j].bits_sph_idx[k], q_direction->cfg.mc_ls_setup ); + q_direction->band_data[j].elevation_fx[k] = deindex_elevation_fx( &q_direction->band_data[j].elevation_index[k], q_direction->band_data[j].bits_sph_idx[k], q_direction->cfg.mc_ls_setup ); /*Q22*/ move32(); } } @@ -5394,9 +5394,9 @@ static Word16 decode_elevation_fx( IF( LT_32( q_direction->band_data[j].elevation_index[k], MASA_NO_INDEX ) && LE_16( no_phi_masa[sub( q_direction->band_data[j].bits_sph_idx[k], 1 )][q_direction->band_data[j].elevation_index[k]], 1 ) ) { - q_direction->band_data[j].azimuth_index[k] = MASA_NO_INDEX; + q_direction->band_data[j].azimuth_index[k] = MASA_NO_INDEX; /*Q0*/ move16(); - q_direction->band_data[j].azimuth_m_alphabet[k] = 1; + q_direction->band_data[j].azimuth_m_alphabet[k] = 1; /*Q0*/ move16(); } ELSE @@ -5405,12 +5405,12 @@ static Word16 decode_elevation_fx( move16(); IF( LT_32( q_direction->band_data[j].elevation_index[k], MASA_NO_INDEX ) ) { - q_direction->band_data[j].azimuth_m_alphabet[k] = no_phi_masa[sub( q_direction->band_data[j].bits_sph_idx[k], 1 )][q_direction->band_data[j].elevation_index[k]]; + q_direction->band_data[j].azimuth_m_alphabet[k] = no_phi_masa[sub( q_direction->band_data[j].bits_sph_idx[k], 1 )][q_direction->band_data[j].elevation_index[k]]; /*Q0*/ move16(); } ELSE { - q_direction->band_data[j].azimuth_m_alphabet[k] = no_phi_masa[sub( q_direction->band_data[j].bits_sph_idx[k], 1 )][0]; + q_direction->band_data[j].azimuth_m_alphabet[k] = no_phi_masa[sub( q_direction->band_data[j].bits_sph_idx[k], 1 )][0]; /*Q0*/ move16(); q_direction->band_data[j].elevation_index[k] = 0; move16(); @@ -5548,10 +5548,10 @@ static int16_t decode_elevation( #ifdef IVAS_FLOAT_FIXED static Word16 decode_fixed_rate_fx( IVAS_QDIRECTION *q_direction, /* i/o: quantized metadata */ - const UWord16 *bitstream, /* i : bitstream to be read */ - Word16 *pbit_pos, /* i/o: position in bitstream */ - const Word16 b, /* i : subband index */ - const Word16 nblocks /* i : number of tiles in subband */ + const UWord16 *bitstream, /* i : bitstream to be read Q0*/ + Word16 *pbit_pos, /* i/o: position in bitstream Q0*/ + const Word16 b, /* i : subband index Q0*/ + const Word16 nblocks /* i : number of tiles in subband Q0*/ ) { Word16 nbits, m, i; @@ -5566,13 +5566,13 @@ static Word16 decode_fixed_rate_fx( move16(); FOR( i = 0; i < q_direction->band_data[b].bits_sph_idx[m]; i++ ) { - value = (UWord16) L_add( L_shl( value, 1 ), bitstream[( *pbit_pos )--] ); + value = (UWord16) L_add( L_shl( value, 1 ), bitstream[( *pbit_pos )--] ); /*Q0*/ move16(); } - q_direction->band_data[b].spherical_index[m] = value; + q_direction->band_data[b].spherical_index[m] = value; /*Q0*/ move16(); - nbits = extract_l( L_add( nbits, q_direction->band_data[b].bits_sph_idx[m] ) ); + nbits = extract_l( L_add( nbits, q_direction->band_data[b].bits_sph_idx[m] ) ); /*Q0*/ deindex_spherical_component_fx( q_direction->band_data[b].spherical_index[m], &q_direction->band_data[b].azimuth_fx[m], &q_direction->band_data[b].elevation_fx[m], &q_direction->band_data[b].azimuth_index[m], &q_direction->band_data[b].elevation_index[m], q_direction->band_data[b].bits_sph_idx[m], q_direction->cfg.mc_ls_setup ); } @@ -5628,10 +5628,10 @@ static int16_t decode_fixed_rate( #ifdef IVAS_FLOAT_FIXED static Word16 decode_azimuth2D_fx( IVAS_QDIRECTION *q_direction, /* i/o: quantized metadata structure */ - UWord16 *bitstream, /* i : bitstream to be read */ - const Word16 coding_subbands, /* i : number of subbands */ - Word16 *pbit_pos, - const Word16 no_frames ) + UWord16 *bitstream, /* i : bitstream to be read Q0*/ + const Word16 coding_subbands, /* i : number of subbands Q0*/ + Word16 *pbit_pos, /*Q0*/ + const Word16 no_frames /*Q0*/ ) { Word16 i, j, k; Word16 allowed_bits, nbits; @@ -5646,7 +5646,7 @@ static Word16 decode_azimuth2D_fx( move16(); FOR( j = 0; j < coding_subbands; j++ ) { - bits_dir0 = (Word16 *) q_direction->band_data[j].bits_sph_idx; + bits_dir0 = (Word16 *) q_direction->band_data[j].bits_sph_idx; /*Q0*/ allowed_bits = sum16_fx( bits_dir0, no_frames ); IF( allowed_bits > 0 ) @@ -5675,7 +5675,7 @@ static Word16 decode_azimuth2D_fx( set32_fx( q_direction->band_data[j].azimuth_fx, 0, no_frames ); FOR( k = 0; k < s_min( allowed_bits, no_frames ); k++ ) { - q_direction->band_data[j].azimuth_fx[k] = L_shl( L_mult0( -180, bitstream[bit_pos] ), Q22 ); + q_direction->band_data[j].azimuth_fx[k] = L_shl( L_mult0( -180, bitstream[bit_pos] ), Q22 ); /*Q22*/ move32(); bit_pos = sub( bit_pos, 1 ); nbits = add( nbits, 1 ); @@ -5683,7 +5683,7 @@ static Word16 decode_azimuth2D_fx( } ELSE { - nbits = add( nbits, read_truncGR_azimuth_fx( bitstream, q_direction, j, no_frames, &bit_pos ) ); + nbits = add( nbits, read_truncGR_azimuth_fx( bitstream, q_direction, j, no_frames, &bit_pos ) ); /*Q0*/ } } ELSE @@ -5694,7 +5694,7 @@ static Word16 decode_azimuth2D_fx( move16(); FOR( i = 0; i < bits_dir0[k]; i++ ) { - Buffer = (UWord16) L_add( L_shl( Buffer, 1 ), bitstream[bit_pos] ); + Buffer = (UWord16) L_add( L_shl( Buffer, 1 ), bitstream[bit_pos] ); /*Q0*/ bit_pos = sub( bit_pos, 1 ); } @@ -5702,15 +5702,15 @@ static Word16 decode_azimuth2D_fx( IF( NE_32( q_direction->cfg.mc_ls_setup, MC_LS_SETUP_INVALID ) ) { - q_direction->band_data[j].azimuth_fx[k] = L_sub( L_shl( 360, sub( Q22, bits_dir0[k] ) ) * Buffer, L_shl( 180, Q22 ) ); + q_direction->band_data[j].azimuth_fx[k] = L_sub( W_extract_l( W_mult0_32_32( L_shl( 360, sub( Q22, bits_dir0[k] ) ), Buffer ) ), L_shl( 180, Q22 ) ); /*Q22*/ move32(); q_direction->band_data[j].azimuth_fx[k] = companding_azimuth_fx( q_direction->band_data[j].azimuth_fx[k], q_direction->cfg.mc_ls_setup, - (Word16) GT_32( q_direction->band_data[j].elevation_fx[k], L_shl( MC_MASA_THR_ELEVATION, 22 ) ), -1 ); + (Word16) GT_32( q_direction->band_data[j].elevation_fx[k], L_shl( MC_MASA_THR_ELEVATION, 22 ) ), -1 ); /*Q22*/ move32(); } ELSE { - q_direction->band_data[j].azimuth_fx[k] = L_shl( 360, sub( Q22, bits_dir0[k] ) ) * Buffer - L_shl( 180, Q22 ); + q_direction->band_data[j].azimuth_fx[k] = L_sub( W_extract_l( W_mult0_32_32( L_shl( 360, sub( Q22, bits_dir0[k] ) ), Buffer ) ), L_shl( 180, Q22 ) ); /*Q22*/ move32(); } } @@ -5823,8 +5823,8 @@ static int16_t decode_azimuth2D( #ifdef IVAS_FLOAT_FIXED static void set_zero_direction_fx( IVAS_QDIRECTION *q_direction, - const Word16 idx_band, - const Word16 len ) + const Word16 idx_band, /*Q0*/ + const Word16 len /*Q0*/ ) { Word16 k; @@ -5874,11 +5874,11 @@ static void set_zero_direction( #ifdef IVAS_FLOAT_FIXED static Word16 read_truncGR_azimuth_fx( - UWord16 *bitstream, /* i : bitstream to be read */ + UWord16 *bitstream, /* i : bitstream to be read Q0*/ IVAS_QDIRECTION *q_direction, /* i/o: quantized metadata structure */ - const Word16 j, /* i : subband index */ - const Word16 no_subframes, /* i : number of tiles */ - Word16 *pbit_pos /* i/o: position in bitstream */ + const Word16 j, /* i : subband index Q0*/ + const Word16 no_subframes, /* i : number of tiles Q0*/ + Word16 *pbit_pos /* i/o: position in bitstream Q0*/ ) { Word16 i; @@ -5886,7 +5886,7 @@ static Word16 read_truncGR_azimuth_fx( UWord16 idx; Word16 no_symb, allowed_bits; - allowed_bits = sum16_fx( (Word16 *) q_direction->band_data[j].bits_sph_idx, no_subframes ); + allowed_bits = sum16_fx( (Word16 *) q_direction->band_data[j].bits_sph_idx, no_subframes ); /*Q0*/ nbits = 0; move16(); IF( LE_16( allowed_bits, add( no_subframes, 1 ) ) ) @@ -5900,7 +5900,7 @@ static Word16 read_truncGR_azimuth_fx( } ELSE { - q_direction->band_data[j].azimuth_fx[i] = ( -180 * ONE_IN_Q22 ); + q_direction->band_data[j].azimuth_fx[i] = ( -180 * ONE_IN_Q22 ); /*Q22*/ move32(); } nbits = add( nbits, 1 ); @@ -5928,21 +5928,21 @@ static Word16 read_truncGR_azimuth_fx( FOR( i = 0; i < no_subframes; i++ ) { idx = ivas_qmetadata_DecodeExtendedGR( bitstream, pbit_pos, no_symb, 0 ); - q_direction->band_data[j].azimuth_index[i] = idx; + q_direction->band_data[j].azimuth_index[i] = idx; /*Q0*/ move16(); IF( NE_16( q_direction->cfg.mc_ls_setup, MC_LS_SETUP_INVALID ) ) { - q_direction->band_data[j].azimuth_fx[i] = cb_azi_chan_fx[(UWord16) L_shr( (UWord16) L_add( idx, 1 ), 1 )]; + q_direction->band_data[j].azimuth_fx[i] = cb_azi_chan_fx[(UWord16) ( (UWord16) ( idx + 1 ) / 2 )]; /*Q22*/ move32(); IF( L_and( idx, 1 ) > 0 ) { - q_direction->band_data[j].azimuth_fx[i] = L_negate( q_direction->band_data[j].azimuth_fx[i] ); + q_direction->band_data[j].azimuth_fx[i] = L_negate( q_direction->band_data[j].azimuth_fx[i] ); /*Q22*/ move32(); } } ELSE { - q_direction->band_data[j].azimuth_fx[i] = azimuth_cb_fx[idx]; + q_direction->band_data[j].azimuth_fx[i] = azimuth_cb_fx[idx]; /*Q22*/ move32(); } } @@ -6030,12 +6030,12 @@ static int16_t read_truncGR_azimuth( /*! r: number of bits read */ #ifdef IVAS_FLOAT_FIXED static Word16 read_common_direction_fx( - UWord16 *bitstream, /* i : bitstream to be read */ + UWord16 *bitstream, /* i : bitstream to be read Q0*/ IVAS_QDIRECTION *q_direction, /* i/o: quantized direction structure */ - const Word16 j, /* i : subband index */ - const Word16 no_subframes, /* i : number of tiles */ - const Word16 bits_total, /* i : number of bits for subband directional data */ - Word16 *pbit_pos /* i/o: position in bitstream */ + const Word16 j, /* i : subband index Q0*/ + const Word16 no_subframes, /* i : number of tiles Q0*/ + const Word16 bits_total, /* i : number of bits for subband directional data Q0*/ + Word16 *pbit_pos /* i/o: position in bitstream Q0*/ ) { Word16 nbits; @@ -6059,10 +6059,10 @@ static Word16 read_common_direction_fx( { FOR( i = 0; i < s_min( no_subframes, bits_total ); i++ ) { - byteBuffer = bitstream[bit_pos--]; + byteBuffer = bitstream[bit_pos--]; /*Q0*/ move16(); /*qdirection->azimuth_index[j][i] = (uint16_t)byteBuffer; */ - q_direction->band_data[j].azimuth_fx[i] = azimuth_cb_fx[byteBuffer]; + q_direction->band_data[j].azimuth_fx[i] = azimuth_cb_fx[byteBuffer]; /*Q22*/ move32(); nbits = add( nbits, 1 ); } @@ -6074,7 +6074,7 @@ static Word16 read_common_direction_fx( } - byteBuffer = bitstream[bit_pos]; + byteBuffer = bitstream[bit_pos]; /*Q0*/ move16(); bit_pos = sub( bit_pos, 1 ); bits_el = 1; @@ -6083,7 +6083,7 @@ static Word16 read_common_direction_fx( /* elevation is already set to 0*/ IF( EQ_32( byteBuffer, 1 ) ) { - byteBuffer = bitstream[bit_pos--]; + byteBuffer = bitstream[bit_pos--]; /*Q0*/ move16(); bits_el = add( bits_el, 1 ); nbits = add( nbits, 1 ); @@ -6091,7 +6091,7 @@ static Word16 read_common_direction_fx( { FOR( i = 0; i < no_subframes; i++ ) { - q_direction->band_data[j].elevation_fx[i] = delta_theta_masa_fx[2]; + q_direction->band_data[j].elevation_fx[i] = delta_theta_masa_fx[2]; /*Q22*/ move32(); } } @@ -6105,7 +6105,7 @@ static Word16 read_common_direction_fx( { FOR( i = 0; i < no_subframes; i++ ) { - q_direction->band_data[j].elevation_fx[i] = L_negate( delta_theta_masa_fx[2] ); + q_direction->band_data[j].elevation_fx[i] = L_negate( delta_theta_masa_fx[2] ); /*Q22*/ move32(); } } @@ -6117,13 +6117,13 @@ static Word16 read_common_direction_fx( nbits = add( nbits, 1 ); IF( byteBuffer == 0 ) { - set32_fx( q_direction->band_data[j].elevation_fx, ( 90 * ONE_IN_Q22 ), no_subframes ); - set32_fx( q_direction->band_data[j].azimuth_fx, 0, no_subframes ); + set32_fx( q_direction->band_data[j].elevation_fx, ( 90 * ONE_IN_Q22 ), no_subframes ); /*Q22*/ + set32_fx( q_direction->band_data[j].azimuth_fx, 0, no_subframes ); /*Q22*/ } ELSE { - set32_fx( q_direction->band_data[j].elevation_fx, ( -90 * ONE_IN_Q22 ), no_subframes ); - set32_fx( q_direction->band_data[j].azimuth_fx, 0, no_subframes ); + set32_fx( q_direction->band_data[j].elevation_fx, ( -90 * ONE_IN_Q22 ), no_subframes ); /*Q22*/ + set32_fx( q_direction->band_data[j].azimuth_fx, 0, no_subframes ); /*Q22*/ } *pbit_pos = bit_pos; move16(); @@ -6133,18 +6133,18 @@ static Word16 read_common_direction_fx( } } - bits_el = sub( sum16_fx( (Word16 *) q_direction->band_data[j].bits_sph_idx, no_subframes ), bits_el ); + bits_el = sub( sum16_fx( (Word16 *) q_direction->band_data[j].bits_sph_idx, no_subframes ), bits_el ); /*Q0*/ IF( LE_16( bits_el, add( no_subframes, 1 ) ) ) { nbits = add( nbits, s_min( no_subframes, bits_el ) ); FOR( i = 0; i < s_min( no_subframes, bits_el ); i++ ) { - byteBuffer = bitstream[bit_pos]; + byteBuffer = bitstream[bit_pos]; /*Q0*/ move16(); bit_pos = sub( bit_pos, 1 ); /*qdirection->azimuth_index[j][i] = (uint16_t) byteBuffer; */ - q_direction->band_data[j].azimuth_fx[i] = azimuth_cb_fx[byteBuffer]; + q_direction->band_data[j].azimuth_fx[i] = azimuth_cb_fx[byteBuffer]; /*Q22*/ move32(); } } @@ -6279,9 +6279,9 @@ static int16_t read_common_direction( #ifdef IVAS_FLOAT_FIXED static void decode_spread_coherence_fx( IVAS_QMETADATA_HANDLE hQMetaData, /* i/o: quantized metadata structure */ - Word16 idx_d, /* i : direction index */ - const Word16 no_frames, /* i : number of time subframes */ - const Word16 hrmasa_flag /* i : flag indicating high-rate MASA MD coding */ + Word16 idx_d, /* i : direction index Q0*/ + const Word16 no_frames, /* i : number of time subframes Q0*/ + const Word16 hrmasa_flag /* i : flag indicating high-rate MASA MD coding Q0*/ ) { Word16 i, j; @@ -6309,21 +6309,21 @@ static void decode_spread_coherence_fx( { IF( LE_16( coding_subbands_0, 8 ) ) { - Copy( MASA_grouping_8_to_5, MASA_grouping, 8 ); + Copy( MASA_grouping_8_to_5, MASA_grouping, 8 ); /*Q0*/ } ELSE IF( LE_16( coding_subbands_0, 12 ) ) { - Copy( MASA_grouping_12_to_5, MASA_grouping, 12 ); + Copy( MASA_grouping_12_to_5, MASA_grouping, 12 ); /*Q0*/ } ELSE IF( LE_16( coding_subbands_0, 18 ) ) { - Copy( MASA_grouping_18_to_5, MASA_grouping, 18 ); + Copy( MASA_grouping_18_to_5, MASA_grouping, 18 ); /*Q0*/ } ELSE { IF( LE_16( coding_subbands_0, 24 ) ) { - Copy( MASA_grouping_24_to_5, MASA_grouping, 24 ); + Copy( MASA_grouping_24_to_5, MASA_grouping, 24 ); /*Q0*/ } } } @@ -6351,7 +6351,7 @@ static void decode_spread_coherence_fx( FOR( i = 0; i < coding_subbands; i++ ) { - var_azi_fx = var_32_fx( q_direction->band_data[i].azimuth_fx, no_frames, 22 ); + var_azi_fx = var_32_fx( q_direction->band_data[i].azimuth_fx, no_frames, 22 ); /*Q22*/ IF( hrmasa_flag ) { minimum_s( (Word16 *) ( q_direction->band_data[i].energy_ratio_index ), q_direction->cfg.nblocks, &min_index ); @@ -6359,13 +6359,13 @@ static void decode_spread_coherence_fx( } ELSE { - min_index = q_direction->band_data[i].energy_ratio_index[0]; + min_index = q_direction->band_data[i].energy_ratio_index[0]; /*Q0*/ move16(); } IF( LT_64( var_azi_fx, L_shl( MASA_DELTA_AZI_DCT0, 22 ) ) ) { - idx_sub_cb = i_mult( MASA_NO_CV_COH, min_index ); + idx_sub_cb = i_mult( MASA_NO_CV_COH, min_index ); /*Q0*/ } ELSE { @@ -6378,12 +6378,12 @@ static void decode_spread_coherence_fx( IF( LT_16( coding_subbands, coding_subbands_0 ) ) { assert( EQ_16( idx_d, 1 ) ); - dct_coh_fx[i][1] = coherence_cb1_masa_fx[L_add( L_mult0( MASA_grouping[two_dir_band[i]], MASA_NO_CV_COH1 ), q_direction->coherence_band_data[i].spread_coherence_dct1_index )]; + dct_coh_fx[i][1] = coherence_cb1_masa_fx[( ( MASA_grouping[two_dir_band[i]] * MASA_NO_CV_COH1 ) + q_direction->coherence_band_data[i].spread_coherence_dct1_index )]; /*Q21*/ move32(); } ELSE { - dct_coh_fx[i][1] = coherence_cb1_masa_fx[L_add( L_mult0( MASA_grouping[i], MASA_NO_CV_COH1 ), q_direction->coherence_band_data[i].spread_coherence_dct1_index )]; + dct_coh_fx[i][1] = coherence_cb1_masa_fx[( ( MASA_grouping[i] * MASA_NO_CV_COH1 ) + q_direction->coherence_band_data[i].spread_coherence_dct1_index )]; /*Q21*/ move32(); } @@ -6520,13 +6520,13 @@ static void decode_spread_coherence( /*! r: number of bits read */ #ifdef IVAS_FLOAT_FIXED static ivas_error read_huf( - Word16 *num_bits_read, - const UWord16 *bitstream, /* i : bitstream to be read */ - UWord16 *out, /* o : decoded value */ - const Word16 start_pos, /* i : starting position for reading */ - const Word16 len, /* i : number of codewords */ - const Word16 *huff_code, /* i : Huffman table */ - const Word16 max_len /* i : maximum codeword length */ + Word16 *num_bits_read, /*Q0*/ + const UWord16 *bitstream, /* i : bitstream to be read Q0*/ + UWord16 *out, /* o : decoded value Q0*/ + const Word16 start_pos, /* i : starting position for reading Q0*/ + const Word16 len, /* i : number of codewords Q0*/ + const Word16 *huff_code, /* i : Huffman table Q0*/ + const Word16 max_len /* i : maximum codeword length Q0*/ ) { Word16 done = 0, end_pos; @@ -6543,9 +6543,9 @@ static ivas_error read_huf( move16(); WHILE( !done && LT_16( nbits, max_len ) ) { - ByteBuffer = bitstream[end_pos--]; + ByteBuffer = bitstream[end_pos--]; /*Q0*/ move16(); - val = add( shl( val, 1 ), ByteBuffer & 1 ); + val = add( shl( val, 1 ), ByteBuffer & 1 ); /*Q0*/ nbits = add( nbits, 1 ); FOR( i = 0; i < len; i++ ) { @@ -6614,12 +6614,12 @@ static ivas_error read_huf( *-------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED static Word16 read_GR_min_removed_data( - UWord16 *bitstream, /* i : bitstream */ - Word16 *p_bit_pos, /* i : position in the bitstream */ - const Word16 *no_cv_vec, - const Word16 no_data, - Word16 *decoded_idx, - const Word16 no_symb ) + UWord16 *bitstream, /* i : bitstream Q0*/ + Word16 *p_bit_pos, /* i : position in the bitstream Q0*/ + const Word16 *no_cv_vec, /*Q0*/ + const Word16 no_data, /*Q0*/ + Word16 *decoded_idx, /*Q0*/ + const Word16 no_symb /*Q0*/ ) { Word16 j; Word16 bit_pos; @@ -6631,7 +6631,7 @@ static Word16 read_GR_min_removed_data( move16(); /* read GR order */ - byteBuffer = bitstream[bit_pos]; + byteBuffer = bitstream[bit_pos]; /*Q0*/ move16(); bit_pos = sub( bit_pos, 1 ); nbits = 1; @@ -6640,7 +6640,7 @@ static Word16 read_GR_min_removed_data( /* read min index */ bits_GR = bit_pos; move16(); - min_index = ivas_qmetadata_DecodeExtendedGR( bitstream, &bit_pos, no_symb, 0 ); + min_index = ivas_qmetadata_DecodeExtendedGR( bitstream, &bit_pos, no_symb, 0 ); /*Q0*/ nbits = add( nbits, sub( bits_GR, bit_pos ) ); /* read GR data */ @@ -6650,7 +6650,7 @@ static Word16 read_GR_min_removed_data( move16(); IF( GT_16( no_cv_vec[j], 1 ) ) { - decoded_idx[j] = ivas_qmetadata_DecodeExtendedGR( bitstream, &bit_pos, sub( no_cv_vec[j], min_index ), extract_l( L_and( byteBuffer, 1 ) ) ); + decoded_idx[j] = ivas_qmetadata_DecodeExtendedGR( bitstream, &bit_pos, sub( no_cv_vec[j], min_index ), extract_l( L_and( byteBuffer, 1 ) ) ); /*Q0*/ move16(); nbits = add( nbits, sub( bits_GR, bit_pos ) ); } @@ -6737,12 +6737,12 @@ static int16_t read_GR_min_removed_data( #ifdef IVAS_FLOAT_FIXED static Word16 decode_fixed_rate_composed_index_coherence_fx( - UWord16 *bitstream, /* i : bitstream */ - Word16 *p_bit_pos, /* i : position in the bitstream */ - const Word16 no_bands, - Word16 *no_cv_vec, - UWord16 *decoded_index, - const Word16 no_symb ) + UWord16 *bitstream, /* i : bitstream Q0*/ + Word16 *p_bit_pos, /* i : position in the bitstream Q0*/ + const Word16 no_bands, /*Q0*/ + Word16 *no_cv_vec, /*Q0*/ + UWord16 *decoded_index, /*Q0*/ + const Word16 no_symb /*Q0*/ ) { /* fixed rate */ UWord64 no_cb; @@ -6774,13 +6774,13 @@ static Word16 decode_fixed_rate_composed_index_coherence_fx( { IF( GT_16( no_cv_vec[j], no_vals_local ) ) { - no_cv_vec[j] = no_vals_local; + no_cv_vec[j] = no_vals_local; /*Q0*/ move16(); } } } - half_no_bands = shr( no_bands, 1 ); + half_no_bands = shr( no_bands, 1 ); /* no_bands / 2 */ IF( GT_16( sum16_fx( no_cv_vec, no_bands ), MASA_COH_LIMIT_2IDX ) ) { no_cb = 1; @@ -6788,7 +6788,7 @@ static Word16 decode_fixed_rate_composed_index_coherence_fx( FOR( j = 0; j < half_no_bands; j++ ) { - no_cb *= no_cv_vec[j]; + no_cb *= no_cv_vec[j]; /*Q0*/ move16(); } no_bits_vec = (Word16) ceil_log_2( no_cb ); @@ -6796,7 +6796,7 @@ static Word16 decode_fixed_rate_composed_index_coherence_fx( move64(); FOR( j = half_no_bands; j < no_bands; j++ ) { - no_cb *= no_cv_vec[j]; + no_cb *= no_cv_vec[j]; /*Q0*/ move16(); } no_bits_vec1 = (Word16) ceil_log_2( no_cb ); @@ -6807,7 +6807,7 @@ static Word16 decode_fixed_rate_composed_index_coherence_fx( move64(); FOR( j = 0; j < no_bands; j++ ) { - no_cb *= no_cv_vec[j]; + no_cb *= no_cv_vec[j]; /*Q0*/ move16(); } no_bits_vec = (Word16) ceil_log_2( no_cb ); @@ -6820,7 +6820,9 @@ static Word16 decode_fixed_rate_composed_index_coherence_fx( move64(); FOR( j = 0; j < no_bits_vec; j++ ) { - idx_fr = ( idx_fr << 1 ) + bitstream[bit_pos--]; + idx_fr = ( idx_fr << 1 ) + bitstream[bit_pos]; /*Q0*/ + bit_pos = sub( bit_pos, 1 ); + move64(); } nbits = add( nbits, no_bits_vec ); @@ -6831,7 +6833,9 @@ static Word16 decode_fixed_rate_composed_index_coherence_fx( move64(); FOR( j = 0; j < no_bits_vec1; j++ ) { - idx_fr = ( idx_fr << 1 ) + bitstream[bit_pos--]; + idx_fr = ( idx_fr << 1 ) + bitstream[bit_pos]; /*Q0*/ + bit_pos = sub( bit_pos, 1 ); + move64(); } nbits = add( nbits, no_bits_vec1 ); decode_combined_index_fx( idx_fr, &no_cv_vec[half_no_bands], &temp_index[half_no_bands], half_no_bands ); @@ -6842,7 +6846,9 @@ static Word16 decode_fixed_rate_composed_index_coherence_fx( move64(); FOR( j = 0; j < no_bits_vec; j++ ) { - idx_fr = ( idx_fr << 1 ) + bitstream[bit_pos--]; + idx_fr = ( idx_fr << 1 ) + bitstream[bit_pos]; /*Q0*/ + bit_pos = sub( bit_pos, 1 ); + move64(); } nbits = add( nbits, no_bits_vec ); decode_combined_index_fx( idx_fr, no_cv_vec, temp_index, no_bands ); @@ -6850,12 +6856,12 @@ static Word16 decode_fixed_rate_composed_index_coherence_fx( FOR( j = 0; j < no_bands; j++ ) { - decoded_index[j] = temp_index[j]; + decoded_index[j] = temp_index[j]; /*Q0*/ move16(); } nbits = sub( *p_bit_pos, bit_pos ); - *p_bit_pos = bit_pos; + *p_bit_pos = bit_pos; /*Q0*/ move16(); return nbits; @@ -6979,11 +6985,11 @@ static int16_t decode_fixed_rate_composed_index_coherence( /*! r: number of bits read */ #ifdef IVAS_FLOAT_FIXED static Word16 read_coherence_data_hr_512_fx( - UWord16 *bitstream, /* i : bitstream */ - Word16 *p_bit_pos, /* i : position in the bitstream */ + UWord16 *bitstream, /* i : bitstream Q0*/ + Word16 *p_bit_pos, /* i : position in the bitstream Q0*/ IVAS_QMETADATA *hQMetaData, /* i/o: quantized metadata structure */ - const Word16 idx_dir, /* i : direction index */ - const Word16 nbits_coh ) + const Word16 idx_dir, /* i : direction index Q0*/ + const Word16 nbits_coh /*Q0*/ ) { Word16 j, k, i; Word16 nbands, nblocks; @@ -7012,18 +7018,18 @@ static Word16 read_coherence_data_hr_512_fx( move16(); FOR( i = 0; i < nbits_coh; i++ ) { - min_index = add( shl( min_index, 1 ), bitstream[( *p_bit_pos )] ); + min_index = add( shl( min_index, 1 ), bitstream[( *p_bit_pos )] ); /*Q0*/ ( *p_bit_pos ) = sub( ( *p_bit_pos ), 1 ); move16(); } /* read GR param */ - GR_param = bitstream[( *p_bit_pos )]; + GR_param = bitstream[( *p_bit_pos )]; /*Q0*/ move16(); ( *p_bit_pos ) = sub( ( *p_bit_pos ), 1 ); move16(); FOR( j = 0; j < nbands; j++ ) { - decoded_idx = ivas_qmetadata_DecodeExtendedGR( bitstream, p_bit_pos, shl( cb_size, 1 ), GR_param ); + decoded_idx = ivas_qmetadata_DecodeExtendedGR( bitstream, p_bit_pos, shl( cb_size, 1 ), GR_param ); /*Q0*/ IF( EQ_16( s_and( decoded_idx, 1 ), 1 ) ) { decoded_idx = add( shr( add( decoded_idx, 1 ), 1 ), min_index ); @@ -7033,7 +7039,7 @@ static Word16 read_coherence_data_hr_512_fx( decoded_idx = add( negate( shr( decoded_idx, 1 ) ), min_index ); } decoded_idx_fx = L_shl( decoded_idx, 9 ); - hQMetaData->q_direction[idx_dir].coherence_band_data[j].spread_coherence[k] = (UWord8) L_add( Mpy_32_32( decoded_idx_fx, delta_fx ), L_shr( delta_fx, 23 ) ); + hQMetaData->q_direction[idx_dir].coherence_band_data[j].spread_coherence[k] = (UWord8) L_add( Mpy_32_32( decoded_idx_fx, delta_fx ), L_shr( delta_fx, 23 ) ); /*Q0*/ move16(); } } @@ -7044,21 +7050,21 @@ static Word16 read_coherence_data_hr_512_fx( move16(); FOR( i = 0; i < nbits_coh; i++ ) { - min_index = add( shl( min_index, 1 ), bitstream[( *p_bit_pos )] ); + min_index = add( shl( min_index, 1 ), bitstream[( *p_bit_pos )] ); /*Q0*/ ( *p_bit_pos ) = sub( ( *p_bit_pos ), 1 ); move16(); } /* read GR param */ - GR_param = bitstream[( *p_bit_pos )]; + GR_param = bitstream[( *p_bit_pos )]; /*Q0*/ move16(); ( *p_bit_pos ) = sub( ( *p_bit_pos ), 1 ); move16(); FOR( j = 0; j < nbands; j++ ) { - decoded_idx = add( ivas_qmetadata_DecodeExtendedGR( bitstream, p_bit_pos, cb_size - min_index, GR_param ), min_index ); - decoded_idx_fx = L_shl( decoded_idx, 9 ); - hQMetaData->q_direction[idx_dir].coherence_band_data[j].spread_coherence[k] = (UWord8) L_add( Mpy_32_32( decoded_idx_fx, delta_fx ), L_shr( delta_fx, 23 ) ); + decoded_idx = add( ivas_qmetadata_DecodeExtendedGR( bitstream, p_bit_pos, cb_size - min_index, GR_param ), min_index ); /*Q0*/ + decoded_idx_fx = L_shl( decoded_idx, 9 ); /*Q9*/ + hQMetaData->q_direction[idx_dir].coherence_band_data[j].spread_coherence[k] = (UWord8) L_add( Mpy_32_32( decoded_idx_fx, delta_fx ), L_shr( delta_fx, 23 ) ); /*Q0*/ move16(); } } @@ -7151,11 +7157,11 @@ static int16_t read_coherence_data_hr_512( /*! r: number of bits read */ #ifdef IVAS_FLOAT_FIXED static Word16 read_coherence_data_fx( - UWord16 *bitstream, /* i : bitstream */ - Word16 *p_bit_pos, /* i : position in the bitstream */ + UWord16 *bitstream, /* i : bitstream Q0*/ + Word16 *p_bit_pos, /* i : position in the bitstream Q0*/ IVAS_QMETADATA *hQMetaData, /* i/o: quantized metadata structure */ - const Word16 idx_dir, /* i : direction index */ - const Word16 hrmasa_flag /* i : flag indicating high-rate MASA MD coding*/ + const Word16 idx_dir, /* i : direction index Q0*/ + const Word16 hrmasa_flag /* i : flag indicating high-rate MASA MD coding Q0*/ ) { Word16 j; @@ -7180,7 +7186,7 @@ static Word16 read_coherence_data_fx( coding_subbands = hQMetaData->q_direction[idx_dir].cfg.nbands; move16(); - extra_cv = idiv1616( coding_subbands, MASA_FACTOR_CV_COH ); + extra_cv = idiv1616( coding_subbands, MASA_FACTOR_CV_COH ); /*Q0*/ move16(); q_direction = &( hQMetaData->q_direction[idx_dir] ); bit_pos = *p_bit_pos; @@ -7194,11 +7200,11 @@ static Word16 read_coherence_data_fx( { IF( hrmasa_flag ) { - idx_ER = extract_l( L_add( L_sub( 7, L_shr( q_direction->band_data[j].energy_ratio_index_mod[0], 1 ) ), extra_cv ) ); + idx_ER = extract_l( L_add( L_sub( 7, L_shr( q_direction->band_data[j].energy_ratio_index_mod[0], 1 ) ), extra_cv ) ); /*Q0*/ } ELSE { - idx_ER = extract_l( L_add( L_sub( 7, q_direction->band_data[j].energy_ratio_index_mod[0] ), extra_cv ) ); + idx_ER = extract_l( L_add( L_sub( 7, q_direction->band_data[j].energy_ratio_index_mod[0] ), extra_cv ) ); /*Q0*/ } no_cv_vec[j] = add( idx_ER, 1 ); move16(); @@ -7213,7 +7219,7 @@ static Word16 read_coherence_data_fx( return 0; } - byteBuffer = bitstream[bit_pos]; + byteBuffer = bitstream[bit_pos]; /*Q0*/ move16(); bit_pos = sub( bit_pos, 1 ); nbits = add( nbits, 1 ); @@ -7221,20 +7227,20 @@ static Word16 read_coherence_data_fx( IF( L_and( byteBuffer, 1 ) ) { /* decode GR min removed */ - nbits = add( nbits, read_GR_min_removed_data( bitstream, &bit_pos, no_cv_vec, coding_subbands, decoded_idx, MASA_MAX_NO_CV_SUR_COH + extra_cv ) ); + nbits = add( nbits, read_GR_min_removed_data( bitstream, &bit_pos, no_cv_vec, coding_subbands, decoded_idx, MASA_MAX_NO_CV_SUR_COH + extra_cv ) ); /*Q0*/ FOR( j = 0; j < coding_subbands; j++ ) { IF( GT_16( no_cv_vec[j], 1 ) ) { - num = i_mult( decoded_idx[j], 255 ); + num = i_mult( decoded_idx[j], 255 ); /*Q0*/ move16(); - den = extract_l( L_add( L_sub( 7, L_shr( q_direction->band_data[j].energy_ratio_index_mod[0], hrmasa_flag ) ), coding_subbands / MASA_FACTOR_CV_COH ) ); + den = extract_l( L_add( L_sub( 7, L_shr( q_direction->band_data[j].energy_ratio_index_mod[0], hrmasa_flag ) ), coding_subbands / MASA_FACTOR_CV_COH ) ); /*Q0*/ q_den = norm_s( den ); q_num = sub( norm_s( num ), 1 ); - res = div_s( shl( num, q_num ), shl( den, q_den ) ); + res = div_s( shl( num, q_num ), shl( den, q_den ) ); /*Q15*/ q_res = add( sub( 15, q_den ), q_num ); - res = L_shl( res, sub( 16, q_res ) ); - q_direction->coherence_band_data[j].spread_coherence[0] = (UWord8) ( round_fx( res ) ); + res = L_shl( res, sub( 16, q_res ) ); /*Q16*/ + q_direction->coherence_band_data[j].spread_coherence[0] = (UWord8) ( round_fx( res ) ); /*Q0*/ move16(); } ELSE @@ -7248,20 +7254,20 @@ static Word16 read_coherence_data_fx( { UWord16 decoded_index[MASA_MAXIMUM_CODING_SUBBANDS]; /* decode joint index */ - nbits = add( nbits, decode_fixed_rate_composed_index_coherence_fx( bitstream, &bit_pos, coding_subbands, no_cv_vec, decoded_index, add( MASA_NO_CV_COH, coding_subbands / MASA_FACTOR_CV_COH ) ) ); + nbits = add( nbits, decode_fixed_rate_composed_index_coherence_fx( bitstream, &bit_pos, coding_subbands, no_cv_vec, decoded_index, add( MASA_NO_CV_COH, coding_subbands / MASA_FACTOR_CV_COH ) ) ); /*Q0*/ FOR( j = 0; j < coding_subbands; j++ ) { IF( GT_16( no_cv_vec[j], 1 ) ) { - num = i_mult( decoded_index[j], 255 ); + num = i_mult( decoded_index[j], 255 ); /*Q0*/ move16(); - den = extract_l( L_add( L_sub( 7, L_shr( q_direction->band_data[j].energy_ratio_index_mod[0], hrmasa_flag ) ), coding_subbands / MASA_FACTOR_CV_COH ) ); + den = extract_l( L_add( L_sub( 7, L_shr( q_direction->band_data[j].energy_ratio_index_mod[0], hrmasa_flag ) ), coding_subbands / MASA_FACTOR_CV_COH ) ); /*Q0*/ q_den = norm_s( den ); q_num = sub( norm_s( num ), 1 ); - res = div_s( shl( num, q_num ), shl( den, q_den ) ); + res = div_s( shl( num, q_num ), shl( den, q_den ) ); /*Q15*/ q_res = add( sub( 15, q_den ), q_num ); - res = L_shl( res, sub( 16, q_res ) ); - q_direction->coherence_band_data[j].spread_coherence[0] = (UWord8) ( round_fx( res ) ); + res = L_shl( res, sub( 16, q_res ) ); /*Q16*/ + q_direction->coherence_band_data[j].spread_coherence[0] = (UWord8) ( round_fx( res ) ); /*Q0*/ move16(); } ELSE @@ -7278,14 +7284,14 @@ static Word16 read_coherence_data_fx( { IF( hrmasa_flag ) { - minimum_s( (Word16 *) ( q_direction->band_data[j].energy_ratio_index ), q_direction->cfg.nblocks, &min_index ); - no_cv_vec[j] = len_cb_dct0_masa[shr( min_index, 1 )]; - move16(); /* spread coherence DCT0*/ + minimum_s( (Word16 *) ( q_direction->band_data[j].energy_ratio_index ), q_direction->cfg.nblocks, &min_index ); /*Q0*/ + no_cv_vec[j] = len_cb_dct0_masa[( min_index / 2 )]; /*Q0*/ + move16(); /* spread coherence DCT0*/ } ELSE { - no_cv_vec[j] = len_cb_dct0_masa[q_direction->band_data[j].energy_ratio_index[0]]; - move16(); /* spread coherence DCT0*/ + no_cv_vec[j] = len_cb_dct0_masa[q_direction->band_data[j].energy_ratio_index[0]]; /*Q0*/ + move16(); /* spread coherence DCT0*/ } } @@ -7301,7 +7307,7 @@ static Word16 read_coherence_data_fx( move64(); } - no_bits_vec = ceil_log_2( no_cb ); // (int16_t)ceilf(logf((float)no_cb) * INV_LOG_2); + no_bits_vec = ceil_log_2( no_cb ); // (int16_t)ceilf(logf((float)no_cb) * INV_LOG_2); Q0 no_cb = 1; move64(); @@ -7311,13 +7317,14 @@ static Word16 read_coherence_data_fx( move64(); } - no_bits_vec1 = ceil_log_2( no_cb ); // (int16_t) ceilf( logf( (float) no_cb ) * INV_LOG_2 ); + no_bits_vec1 = ceil_log_2( no_cb ); // (int16_t) ceilf( logf( (float) no_cb ) * INV_LOG_2 ); Q0 dct0_index = 0; move64(); FOR( j = 0; j < no_bits_vec; j++ ) { - dct0_index = ( dct0_index << 1 ) + bitstream[bit_pos--]; + dct0_index = ( dct0_index << 1 ) + bitstream[bit_pos]; /*Q0*/ + bit_pos = sub( bit_pos, 1 ); move64(); } @@ -7330,7 +7337,8 @@ static Word16 read_coherence_data_fx( move64(); FOR( j = 0; j < no_bits_vec1; j++ ) { - dct0_index = ( dct0_index << 1 ) + bitstream[bit_pos--]; + dct0_index = ( dct0_index << 1 ) + bitstream[bit_pos]; /*Q0*/ + bit_pos = sub( bit_pos, 1 ); move64(); } @@ -7340,7 +7348,7 @@ static Word16 read_coherence_data_fx( FOR( j = 0; j < coding_subbands; j++ ) { - q_direction->coherence_band_data[j].spread_coherence_dct0_index = spr_coh_temp_index[j]; + q_direction->coherence_band_data[j].spread_coherence_dct0_index = spr_coh_temp_index[j]; /*Q0*/ move16(); } } @@ -7358,16 +7366,17 @@ static Word16 read_coherence_data_fx( move64(); } - no_bits_vec = ceil_log_2( no_cb ); // (int16_t)ceilf(logf((float)no_cb) * INV_LOG_2); + no_bits_vec = ceil_log_2( no_cb ); // (int16_t)ceilf(logf((float)no_cb) * INV_LOG_2); Q0 /* read joint index for DCT0 */ - no_bits_vec = ceil_log_2( no_cb ); // (int16_t)ceilf(logf((float)no_cb) * INV_LOG_2); + no_bits_vec = ceil_log_2( no_cb ); // (int16_t)ceilf(logf((float)no_cb) * INV_LOG_2); Q0 dct0_index = 0; move64(); FOR( j = 0; j < no_bits_vec; j++ ) { - dct0_index = ( dct0_index << 1 ) + bitstream[bit_pos--]; + dct0_index = ( dct0_index << 1 ) + bitstream[bit_pos]; /*Q0*/ + bit_pos = sub( bit_pos, 1 ); move64(); } @@ -7379,7 +7388,7 @@ static Word16 read_coherence_data_fx( FOR( j = 0; j < coding_subbands; j++ ) { - q_direction->coherence_band_data[j].spread_coherence_dct0_index = spr_coh_temp_index[j]; + q_direction->coherence_band_data[j].spread_coherence_dct0_index = spr_coh_temp_index[j]; /*Q0*/ move16(); } } @@ -7388,7 +7397,7 @@ static Word16 read_coherence_data_fx( FOR( j = 0; j < coding_subbands; j++ ) { bits_GR = bit_pos; - idx_dct1[j] = ivas_qmetadata_DecodeExtendedGR( bitstream, &bit_pos, shl( MASA_NO_CV_COH1, 1 ), 0 ); + idx_dct1[j] = ivas_qmetadata_DecodeExtendedGR( bitstream, &bit_pos, shl( MASA_NO_CV_COH1, 1 ), 0 ); /*Q0*/ move16(); nbits = add( nbits, sub( bits_GR, bit_pos ) ); } @@ -7404,12 +7413,12 @@ static Word16 read_coherence_data_fx( { IF( L_and( idx_dct1[j], 1 ) ) { - q_direction->coherence_band_data[j].spread_coherence_dct1_index = (UWord16) L_add( L_shr( L_add( idx_dct1[j], 1 ), 1 ), av_index ); + q_direction->coherence_band_data[j].spread_coherence_dct1_index = (UWord16) L_add( L_shr( L_add( idx_dct1[j], 1 ), 1 ), av_index ); /*Q0*/ move16(); } ELSE { - q_direction->coherence_band_data[j].spread_coherence_dct1_index = (UWord16) L_add( L_shr( -idx_dct1[j], 1 ), av_index ); + q_direction->coherence_band_data[j].spread_coherence_dct1_index = (UWord16) L_add( L_shr( L_negate( idx_dct1[j] ), 1 ), av_index ); /*Q0*/ move16(); } } @@ -7819,8 +7828,8 @@ static int16_t read_surround_coherence( } #else static Word16 read_surround_coherence( - UWord16 *bitstream, /* i : bitstream */ - Word16 *p_bit_pos, /* i : position in the bitstream */ + UWord16 *bitstream, /* i : bitstream Q0*/ + Word16 *p_bit_pos, /* i : position in the bitstream Q0*/ IVAS_QMETADATA *hQMetaData /* i/o: quantized metadata structure */ ) { @@ -7857,16 +7866,16 @@ static Word16 read_surround_coherence( idx = s_max( sub( d, 1 ), 0 ); IF( EQ_16( hQMetaData->twoDirBands[j], 1 ) ) { - error_ratio_surr = L_sub( L_sub( ONE_IN_Q30, q_direction[0].band_data[j].energy_ratio_fx[0] ), q_direction[1].band_data[idx].energy_ratio_fx[0] ); + error_ratio_surr = L_sub( L_sub( ONE_IN_Q30, q_direction[0].band_data[j].energy_ratio_fx[0] ), q_direction[1].band_data[idx].energy_ratio_fx[0] ); /*Q30*/ } ELSE { - error_ratio_surr = L_sub( ONE_IN_Q30, q_direction[0].band_data[j].energy_ratio_fx[0] ); + error_ratio_surr = L_sub( ONE_IN_Q30, q_direction[0].band_data[j].energy_ratio_fx[0] ); /*Q30*/ } } ELSE { - error_ratio_surr = L_sub( ONE_IN_Q30, q_direction[0].band_data[j].energy_ratio_fx[0] ); + error_ratio_surr = L_sub( ONE_IN_Q30, q_direction[0].band_data[j].energy_ratio_fx[0] ); /*Q30*/ } IF( error_ratio_surr <= 0 ) @@ -7875,12 +7884,12 @@ static Word16 read_surround_coherence( move32(); no_cv_vec[j] = 1; move16(); - idx_ER[j] = masa_sq_fx( 0, diffuseness_thresholds_fx, DIRAC_DIFFUSE_LEVELS ); + idx_ER[j] = masa_sq_fx( 0, diffuseness_thresholds_fx, DIRAC_DIFFUSE_LEVELS ); /*Q0*/ move16(); } ELSE { - idx_ER[j] = masa_sq_fx( error_ratio_surr, diffuseness_thresholds_fx, DIRAC_DIFFUSE_LEVELS ); + idx_ER[j] = masa_sq_fx( error_ratio_surr, diffuseness_thresholds_fx, DIRAC_DIFFUSE_LEVELS ); /*Q0*/ move16(); no_cv_vec[j] = add( idx_cb_sur_coh_masa[idx_ER[j]], 2 ); move16(); @@ -7906,7 +7915,7 @@ static Word16 read_surround_coherence( } /* read how the surround coherence is encoded */ - byteBuffer = bitstream[bit_pos]; + byteBuffer = bitstream[bit_pos]; /*Q0*/ bit_pos = sub( bit_pos, 1 ); move16(); bits_sur_coherence = add( bits_sur_coherence, 1 ); @@ -7915,14 +7924,14 @@ static Word16 read_surround_coherence( { /* GR decoding */ /* read GR order */ - byteBuffer = bitstream[bit_pos]; + byteBuffer = bitstream[bit_pos]; /*Q0*/ bit_pos = sub( bit_pos, 1 ); bits_sur_coherence = add( bits_sur_coherence, 1 ); /* read min index */ bits_GR = bit_pos; move16(); - min_index = ivas_qmetadata_DecodeExtendedGR( bitstream, &bit_pos, MASA_MAX_NO_CV_SUR_COH, 0 ); + min_index = ivas_qmetadata_DecodeExtendedGR( bitstream, &bit_pos, MASA_MAX_NO_CV_SUR_COH, 0 ); /*Q0*/ bits_sur_coherence = add( bits_sur_coherence, sub( bits_GR, bit_pos ) ); /* read GR data */ @@ -7933,7 +7942,7 @@ static Word16 read_surround_coherence( /* decoding for min removed */ IF( GT_16( no_cv_vec[j], 1 ) ) { - idx_sur_coh[j] = ivas_qmetadata_DecodeExtendedGR( bitstream, &bit_pos, sub( no_cv_vec[j], min_index ), ( byteBuffer & 1 ) ); + idx_sur_coh[j] = ivas_qmetadata_DecodeExtendedGR( bitstream, &bit_pos, sub( no_cv_vec[j], min_index ), ( byteBuffer & 1 ) ); /*Q30*/ move16(); bits_sur_coherence = add( bits_sur_coherence, sub( bits_GR, bit_pos ) ); } @@ -7948,16 +7957,16 @@ static Word16 read_surround_coherence( { IF( GT_16( no_cv_vec[j], 1 ) ) { - hQMetaData->surcoh_band_data[j].sur_coherence_index = add( idx_sur_coh[j], min_index ); + hQMetaData->surcoh_band_data[j].sur_coherence_index = add( idx_sur_coh[j], min_index ); /*Q0*/ move16(); } ELSE { - hQMetaData->surcoh_band_data[j].sur_coherence_index = idx_sur_coh[j]; + hQMetaData->surcoh_band_data[j].sur_coherence_index = idx_sur_coh[j]; /*Q0*/ move16(); } - hQMetaData->surcoh_band_data[j].surround_coherence[0] = sur_coherence_cb_masa[add( shl( idx_cb_sur_coh_masa[idx_ER[j]], 3 ), hQMetaData->surcoh_band_data[j].sur_coherence_index )]; + hQMetaData->surcoh_band_data[j].surround_coherence[0] = sur_coherence_cb_masa[( ( idx_cb_sur_coh_masa[idx_ER[j]] * 8 ) + hQMetaData->surcoh_band_data[j].sur_coherence_index )]; /*Q0*/ move16(); } } @@ -7971,7 +7980,7 @@ static Word16 read_surround_coherence( FOR( j = 0; j < coding_subbands; j++ ) { - hQMetaData->surcoh_band_data[j].sur_coherence_index = sur_coh_temp_index[j]; + hQMetaData->surcoh_band_data[j].sur_coherence_index = sur_coh_temp_index[j]; /*Q0*/ move16(); } @@ -7980,7 +7989,7 @@ static Word16 read_surround_coherence( { IF( GT_16( no_cv_vec[j], 1 ) ) { - hQMetaData->surcoh_band_data[j].surround_coherence[0] = sur_coherence_cb_masa[add( shl( idx_cb_sur_coh_masa[idx_ER[j]], 3 ), hQMetaData->surcoh_band_data[j].sur_coherence_index )]; + hQMetaData->surcoh_band_data[j].surround_coherence[0] = sur_coherence_cb_masa[( ( idx_cb_sur_coh_masa[idx_ER[j]] * 8 ) + hQMetaData->surcoh_band_data[j].sur_coherence_index )]; /*Q0*/ move16(); } ELSE @@ -7995,7 +8004,7 @@ static Word16 read_surround_coherence( { FOR( k = 1; k < MAX_PARAM_SPATIAL_SUBFRAMES; k++ ) { - hQMetaData->surcoh_band_data[j].surround_coherence[k] = hQMetaData->surcoh_band_data[j].surround_coherence[0]; + hQMetaData->surcoh_band_data[j].surround_coherence[k] = hQMetaData->surcoh_band_data[j].surround_coherence[0]; /*Q0*/ move16(); } } @@ -8181,10 +8190,10 @@ static int16_t read_surround_coherence_hr( } #else static Word16 read_surround_coherence_hr_fx( - UWord16 *bitstream, /* i : bitstream */ - Word16 *p_bit_pos, /* i : position in the bitstream */ + UWord16 *bitstream, /* i : bitstream Q0*/ + Word16 *p_bit_pos, /* i : position in the bitstream Q0*/ IVAS_QMETADATA *hQMetaData, /* i/o: quantized metadata structure */ - Word64 energy_ratio[][MASA_MAXIMUM_CODING_SUBBANDS][MAX_PARAM_SPATIAL_SUBFRAMES] ) + Word64 energy_ratio[][MASA_MAXIMUM_CODING_SUBBANDS][MAX_PARAM_SPATIAL_SUBFRAMES] /*Q62*/ ) { Word16 coding_subbands; Word16 no_cv_vec[MASA_MAXIMUM_CODING_SUBBANDS]; @@ -8216,15 +8225,15 @@ static Word16 read_surround_coherence_hr_fx( error_ratio_surr_fx = ONE_IN_Q62; IF( EQ_32( hQMetaData->no_directions, 2 ) ) { - d = add( d, hQMetaData->twoDirBands[j] ); + d = add( d, hQMetaData->twoDirBands[j] ); /*Q0*/ idx = s_max( sub( d, 1 ), 0 ); error_ratio_surr_fx = W_sub( W_sub( ONE_IN_Q62, energy_ratio[0][j][sf] ), - energy_ratio[1][idx][sf] * hQMetaData->twoDirBands[j] ); + energy_ratio[1][idx][sf] * hQMetaData->twoDirBands[j] ); /*Q62*/ } ELSE { - error_ratio_surr_fx = W_sub( ONE_IN_Q62, energy_ratio[0][j][sf] ); + error_ratio_surr_fx = W_sub( ONE_IN_Q62, energy_ratio[0][j][sf] ); /*Q62*/ } IF( LE_64( error_ratio_surr_fx, ( 461168601842 ) ) ) // 1e-7 in Q62 @@ -8238,8 +8247,10 @@ static Word16 read_surround_coherence_hr_fx( } ELSE { - idx_ER[j] = 7; // masa_sq( error_ratio_surr, diffuseness_thresholds, DIRAC_DIFFUSE_LEVELS ); - no_cv_vec[j] = idx_cb_sur_coh_masa[idx_ER[j]] + 2; + idx_ER[j] = 7; // masa_sq( error_ratio_surr, diffuseness_thresholds, DIRAC_DIFFUSE_LEVELS ); + no_cv_vec[j] = add( idx_cb_sur_coh_masa[idx_ER[j]], 2 ); /*Q0*/ + move16(); + move16(); } } @@ -8261,7 +8272,7 @@ static Word16 read_surround_coherence_hr_fx( ELSE { /* read how the surround coherence is encoded */ - byteBuffer = bitstream[bit_pos]; + byteBuffer = bitstream[bit_pos]; /*Q0*/ move16(); bit_pos = sub( bit_pos, 1 ); bits_sur_coherence = add( bits_sur_coherence, 1 ); @@ -8270,14 +8281,14 @@ static Word16 read_surround_coherence_hr_fx( { /* GR decoding */ /* read GR order */ - byteBuffer = bitstream[bit_pos]; + byteBuffer = bitstream[bit_pos]; /*Q0*/ move16(); bit_pos = sub( bit_pos, 1 ); bits_sur_coherence = add( bits_sur_coherence, 1 ); /* read min index */ bits_GR = bit_pos; - min_index = ivas_qmetadata_DecodeExtendedGR( bitstream, &bit_pos, MASA_MAX_NO_CV_SUR_COH, 0 ); + min_index = ivas_qmetadata_DecodeExtendedGR( bitstream, &bit_pos, MASA_MAX_NO_CV_SUR_COH, 0 ); /*Q0*/ bits_sur_coherence = add( bits_sur_coherence, sub( bits_GR, bit_pos ) ); /* read GR data */ @@ -8288,7 +8299,7 @@ static Word16 read_surround_coherence_hr_fx( /* decoding for min removed */ IF( GT_16( no_cv_vec[j], 1 ) ) { - idx_sur_coh[j] = ivas_qmetadata_DecodeExtendedGR( bitstream, &bit_pos, sub( no_cv_vec[j], min_index ), ( byteBuffer & 1 ) ); + idx_sur_coh[j] = ivas_qmetadata_DecodeExtendedGR( bitstream, &bit_pos, sub( no_cv_vec[j], min_index ), ( byteBuffer & 1 ) ); /*Q0*/ move16(); bits_sur_coherence = add( bits_sur_coherence, sub( bits_GR, bit_pos ) ); } @@ -8303,14 +8314,14 @@ static Word16 read_surround_coherence_hr_fx( { IF( GT_16( no_cv_vec[j], 1 ) ) { - hQMetaData->surcoh_band_data[j].sur_coherence_index = (UWord16) L_add( (Word32) idx_sur_coh[j], L_deposit_l( min_index ) ); + hQMetaData->surcoh_band_data[j].sur_coherence_index = (UWord16) L_add( (Word32) idx_sur_coh[j], L_deposit_l( min_index ) ); /*Q0*/ move16(); - hQMetaData->surcoh_band_data[j].surround_coherence[sf] = sur_coherence_cb_masa[L_add( L_mult0( idx_cb_sur_coh_masa[idx_ER[j]], MASA_MAX_NO_CV_SUR_COH ), hQMetaData->surcoh_band_data[j].sur_coherence_index )]; + hQMetaData->surcoh_band_data[j].surround_coherence[sf] = sur_coherence_cb_masa[( ( idx_cb_sur_coh_masa[idx_ER[j]] * MASA_MAX_NO_CV_SUR_COH ) + hQMetaData->surcoh_band_data[j].sur_coherence_index )]; move16(); } ELSE { - hQMetaData->surcoh_band_data[j].sur_coherence_index = idx_sur_coh[j]; + hQMetaData->surcoh_band_data[j].sur_coherence_index = idx_sur_coh[j]; /*Q0*/ move16(); hQMetaData->surcoh_band_data[j].surround_coherence[sf] = 0; move16(); @@ -8327,7 +8338,7 @@ static Word16 read_surround_coherence_hr_fx( FOR( j = 0; j < coding_subbands; j++ ) { - hQMetaData->surcoh_band_data[j].sur_coherence_index = sur_coh_temp_index[j]; + hQMetaData->surcoh_band_data[j].sur_coherence_index = sur_coh_temp_index[j]; /*Q0*/ move16(); } @@ -8336,7 +8347,7 @@ static Word16 read_surround_coherence_hr_fx( { IF( GT_16( no_cv_vec[j], 1 ) ) { - hQMetaData->surcoh_band_data[j].surround_coherence[sf] = sur_coherence_cb_masa[L_add( L_mult0( idx_cb_sur_coh_masa[idx_ER[j]], MASA_MAX_NO_CV_SUR_COH ), hQMetaData->surcoh_band_data[j].sur_coherence_index )]; + hQMetaData->surcoh_band_data[j].surround_coherence[sf] = sur_coherence_cb_masa[( ( idx_cb_sur_coh_masa[idx_ER[j]] * MASA_MAX_NO_CV_SUR_COH ) + hQMetaData->surcoh_band_data[j].sur_coherence_index )]; /*Q0*/ move16(); } ELSE @@ -8367,10 +8378,10 @@ static Word16 read_surround_coherence_hr_fx( #ifdef IVAS_FLOAT_FIXED static void decode_combined_index_fx( - UWord64 comb_index, /* i : index to be decoded */ - const Word16 *no_cv_vec, /* i : number of codewords for each element*/ - UWord16 *index, /* o : decoded indexes */ - const Word16 len /* i : number of elements */ + UWord64 comb_index, /* i : index to be decoded Q0*/ + const Word16 *no_cv_vec, /* i : number of codewords for each element Q0*/ + UWord16 *index, /* o : decoded indexes Q0*/ + const Word16 len /* i : number of elements Q0*/ ) { Word16 i; @@ -8426,12 +8437,12 @@ static void decode_combined_index( #ifdef IVAS_FLOAT_FIXED static void read_stream_dct_coeffs_omasa_fx( - Word16 *q_idx, + Word16 *q_idx, /*Q0*/ Word32 *q_dct_data_fx, - const Word16 len_stream, - UWord16 *bit_stream, - Word16 *index, - const Word16 first_line ) + const Word16 len_stream, /*Q0*/ + UWord16 *bit_stream, /*Q0*/ + Word16 *index, /*Q0*/ + const Word16 first_line /*Q0*/ ) { Word16 sign, nbits; Word16 i, j, i_min; @@ -8448,7 +8459,7 @@ static void read_stream_dct_coeffs_omasa_fx( IF( !first_line ) { /* read sign */ - sign = bit_stream[( *index )--]; + sign = bit_stream[( *index )--]; /*Q0*/ move16(); IF( !sign ) { @@ -8462,10 +8473,10 @@ static void read_stream_dct_coeffs_omasa_fx( /* read DCT 0 component */ FOR( i = 0; i < BITS_MASA2TOTTAL_DCT0; i++ ) { - q_idx[0] = add( shl( q_idx[0], 1 ), bit_stream[( *index )--] ); + q_idx[0] = add( shl( q_idx[0], 1 ), bit_stream[( *index )--] ); /*Q0*/ move16(); } - q_idx[0] = i_mult( q_idx[0], sign ); + q_idx[0] = i_mult( q_idx[0], sign ); /*Q0*/ move16(); IF( q_idx[0] != 0 ) @@ -8479,14 +8490,14 @@ static void read_stream_dct_coeffs_omasa_fx( move16(); FOR( i = 0; i < j; i++ ) { - i_min = extract_l( L_add( shl( i_min, 1 ), bit_stream[( *index )--] ) ); + i_min = extract_l( L_add( shl( i_min, 1 ), bit_stream[( *index )--] ) ); /*Q0*/ } nbits = add( nbits, j ); /* read GR orders */ - GR1 = extract_l( L_add( bit_stream[( *index )--], 1 ) ); + GR1 = extract_l( L_add( bit_stream[( *index )--], 1 ) ); /*Q0*/ IF( EQ_16( GR1, 2 ) ) { - GR2 = bit_stream[( *index )--]; + GR2 = bit_stream[( *index )--]; /*Q0*/ move16(); } ELSE @@ -8498,25 +8509,25 @@ static void read_stream_dct_coeffs_omasa_fx( /* read GR data */ FOR( i = 1; i <= i_min; i++ ) { - q_idx[i] = ivas_qmetadata_DecodeExtendedGR( bit_stream, index, 100, GR1 ); + q_idx[i] = ivas_qmetadata_DecodeExtendedGR( bit_stream, index, 100, GR1 ); /*Q0*/ move16(); } - FOR( i = add( i_min, 1 ); i < len_stream; i++ ) + FOR( i = ( i_min + 1 ); i < len_stream; i++ ) { - q_idx[i] = ivas_qmetadata_DecodeExtendedGR( bit_stream, index, 100, GR2 ); + q_idx[i] = ivas_qmetadata_DecodeExtendedGR( bit_stream, index, 100, GR2 ); /*Q0*/ move16(); } } ELSE { /* read GR order (only one) */ - GR1 = bit_stream[( *index )]; + GR1 = bit_stream[( *index )]; /*Q0*/ move16(); ( *index ) = sub( ( *index ), 1 ); move16(); FOR( i = 1; i < len_stream; i++ ) { - q_idx[i] = ivas_qmetadata_DecodeExtendedGR( bit_stream, index, 100, GR1 ); + q_idx[i] = ivas_qmetadata_DecodeExtendedGR( bit_stream, index, 100, GR1 ); /*Q0*/ move16(); } } @@ -8529,12 +8540,12 @@ static void read_stream_dct_coeffs_omasa_fx( { IF( s_and( q_idx[i], 1 ) == 0 ) { - q_dct_data_fx[i] = L_shl( Mpy_32_16_1( step, negate( shl( q_idx[i], 6 ) ) ), 2 ); + q_dct_data_fx[i] = L_shl( Mpy_32_16_1( step, negate( shl( q_idx[i], 6 ) ) ), 2 ); /*Q25*/ move32(); } ELSE { - q_dct_data_fx[i] = L_shl( Mpy_32_16_1( step, shl( q_idx[i] + 1, 6 ) ), 2 ); + q_dct_data_fx[i] = L_shl( Mpy_32_16_1( step, shl( q_idx[i] + 1, 6 ) ), 2 ); /*Q25*/ move32(); } } @@ -8648,11 +8659,11 @@ static void read_stream_dct_coeffs_omasa( #ifdef IVAS_FLOAT_FIXED void ivas_omasa_decode_masa_to_total_fx( - UWord16 *bit_stream, - Word16 *index, - Word32 masa_to_total_energy_ratio_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], - const Word16 nbands, - const Word16 nblocks ) + UWord16 *bit_stream, /*Q0*/ + Word16 *index, /*Q0*/ + Word32 masa_to_total_energy_ratio_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /*Q30*/ + const Word16 nbands, /*Q0*/ + const Word16 nblocks /*Q0*/ ) { Word16 i, j, k; Word16 q_idx[MAX_PARAM_SPATIAL_SUBFRAMES * MASA_FREQUENCY_BANDS]; @@ -8675,7 +8686,7 @@ void ivas_omasa_decode_masa_to_total_fx( set16_fx( q_idx, 0, i_mult( nbands, nblocks ) ); FOR( i = 0; i < n_streams; i++ ) { - read_stream_dct_coeffs_omasa_fx( &q_idx[L_mult0( i, len_stream )], &q_dct_data_fx[L_mult0( i, len_stream )], len_stream, bit_stream, index, i == 0 ); + read_stream_dct_coeffs_omasa_fx( &q_idx[( i * len_stream )], &q_dct_data_fx[( i * len_stream )], len_stream, bit_stream, index, i == 0 ); } /* inverse DCT2 transform */ @@ -8683,19 +8694,19 @@ void ivas_omasa_decode_masa_to_total_fx( { case 4: matrix_product_q30_fx( dct4_fx, nblocks, nblocks, 1, q_dct_data_fx, nblocks, 1, 0, dct_data_tmp_fx ); - Copy32( dct_data_tmp_fx, q_dct_data_fx, nblocks ); + Copy32( dct_data_tmp_fx, q_dct_data_fx, nblocks ); /*Q25*/ BREAK; case 5: matrix_product_q30_fx( dct5_fx, nbands, nbands, 1, q_dct_data_fx, nbands, 1, 0, dct_data_tmp_fx ); - Copy32( dct_data_tmp_fx, q_dct_data_fx, nbands ); + Copy32( dct_data_tmp_fx, q_dct_data_fx, nbands ); /*Q25*/ BREAK; case 8: matrix_product_q30_fx( dct8_fx, nbands, nbands, 1, q_dct_data_fx, nbands, 1, 0, dct_data_tmp_fx ); - Copy32( dct_data_tmp_fx, q_dct_data_fx, nbands ); + Copy32( dct_data_tmp_fx, q_dct_data_fx, nbands ); /*Q25*/ BREAK; case 12: matrix_product_q30_fx( dct12_fx, nbands, nbands, 1, q_dct_data_fx, nbands, 1, 0, dct_data_tmp_fx ); - Copy32( dct_data_tmp_fx, q_dct_data_fx, nbands ); + Copy32( dct_data_tmp_fx, q_dct_data_fx, nbands ); /*Q25*/ BREAK; case 20: matrix_product_fx( dct5_fx, nbands, nbands, 1, q_dct_data_fx, nbands, nblocks, 0, dct_data_tmp_fx ); @@ -8717,7 +8728,7 @@ void ivas_omasa_decode_masa_to_total_fx( { masa_to_total_energy_ratio_fx[i][j] = L_max( 0, q_dct_data_fx[k] ); // Q30 move32(); - masa_to_total_energy_ratio_fx[i][j] = L_min( ONE_IN_Q30, masa_to_total_energy_ratio_fx[i][j] ); + masa_to_total_energy_ratio_fx[i][j] = L_min( ONE_IN_Q30, masa_to_total_energy_ratio_fx[i][j] ); /*Q30*/ move32(); k = add( k, 1 ); } @@ -8729,7 +8740,7 @@ void ivas_omasa_decode_masa_to_total_fx( { FOR( j = 0; j < nbands; j++ ) { - masa_to_total_energy_ratio_fx[i][j] = masa_to_total_energy_ratio_fx[0][j]; + masa_to_total_energy_ratio_fx[i][j] = masa_to_total_energy_ratio_fx[0][j]; /*Q30*/ move32(); } } @@ -8741,7 +8752,7 @@ void ivas_omasa_decode_masa_to_total_fx( { FOR( i = 0; i < nblocks; i++ ) { - masa_to_total_energy_ratio_fx[i][j] = masa_to_total_energy_ratio_fx[i][0]; + masa_to_total_energy_ratio_fx[i][j] = masa_to_total_energy_ratio_fx[i][0]; /*Q30*/ move32(); } } diff --git a/lib_dec/ivas_spar_md_dec.c b/lib_dec/ivas_spar_md_dec.c index a2f308441..886db7651 100644 --- a/lib_dec/ivas_spar_md_dec.c +++ b/lib_dec/ivas_spar_md_dec.c @@ -261,8 +261,8 @@ ivas_error ivas_spar_md_dec_matrix_open( #else ivas_error ivas_spar_md_dec_matrix_open_fx( ivas_spar_md_dec_state_t *hMdDec, /* i/o: SPAR MD decoder handle */ - const Word16 num_channels, /* i : number of internal channels */ - const Word16 num_md_sub_frames /* i : number of MD subframes */ + const Word16 num_channels, /* i : number of internal channels Q0*/ + const Word16 num_md_sub_frames /* i : number of MD subframes Q0*/ ) { Word16 i, j; @@ -437,9 +437,9 @@ ivas_error ivas_spar_md_dec_matrix_open_fx( /*! r: number of MD subframes */ #ifdef IVAS_FLOAT_FIXED Word16 ivas_get_spar_dec_md_num_subframes( - const Word16 sba_order, /* i : Ambisonic (SBA) order */ - const Word32 ivas_total_brate, /* i : IVAS total bitrate */ - const Word32 ivas_last_active_brate /* i : IVAS last active bitrate */ + const Word16 sba_order, /* i : Ambisonic (SBA) order Q0*/ + const Word32 ivas_total_brate, /* i : IVAS total bitrate Q0*/ + const Word32 ivas_last_active_brate /* i : IVAS last active bitrate Q0*/ ) { Word16 num_subframes; @@ -464,7 +464,7 @@ Word16 ivas_get_spar_dec_md_num_subframes( move16(); } - return ( num_subframes ); + return ( num_subframes ); /*Q0*/ } #else int16_t ivas_get_spar_dec_md_num_subframes( @@ -504,10 +504,10 @@ int16_t ivas_get_spar_dec_md_num_subframes( ivas_error ivas_spar_md_dec_open( ivas_spar_md_dec_state_t **hMdDec_out, /* i/o: SPAR MD decoder handle */ const DECODER_CONFIG_HANDLE hDecoderConfig, /* i : configuration structure */ - const Word16 num_channels, /* i : number of internal channels */ - const Word16 sba_order, /* i : SBA order */ - const Word16 sid_format, /* i : SID format */ - const Word32 last_active_ivas_total_brate /* i : IVAS last active bitrate */ + const Word16 num_channels, /* i : number of internal channels Q0*/ + const Word16 sba_order, /* i : SBA order Q0*/ + const Word16 sid_format, /* i : SID format Q0*/ + const Word32 last_active_ivas_total_brate /* i : IVAS last active bitrate Q0*/ ) { ivas_spar_md_dec_state_t *hMdDec; @@ -522,7 +522,7 @@ ivas_error ivas_spar_md_dec_open( return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD decoder" ); } - num_md_sub_frames = ivas_get_spar_dec_md_num_subframes( sba_order, hDecoderConfig->ivas_total_brate, last_active_ivas_total_brate ); + num_md_sub_frames = ivas_get_spar_dec_md_num_subframes( sba_order, hDecoderConfig->ivas_total_brate, last_active_ivas_total_brate ); /*Q0*/ IF( NE_32( ( error = ivas_spar_md_dec_matrix_open_fx( hMdDec, num_channels, num_md_sub_frames ) ), IVAS_ERR_OK ) ) { @@ -533,7 +533,7 @@ ivas_error ivas_spar_md_dec_open( { IF( EQ_16( sid_format, SID_SBA_2TC ) ) { - hMdDec->table_idx = ivas_get_spar_table_idx( IVAS_48k, sba_order, SPAR_CONFIG_BW, NULL, NULL ); + hMdDec->table_idx = ivas_get_spar_table_idx( IVAS_48k, sba_order, SPAR_CONFIG_BW, NULL, NULL ); /*Q0*/ move16(); } ELSE @@ -681,7 +681,7 @@ void ivas_spar_md_dec_matrix_close( #else void ivas_spar_md_dec_matrix_close_fx( ivas_spar_md_dec_state_t *hMdDecoder, /* i/o: SPAR MD decoder handle */ - const Word16 num_channels /* i : number of internal channels */ + const Word16 num_channels /* i : number of internal channels Q0*/ ) { Word16 i, j; @@ -814,11 +814,11 @@ void ivas_spar_md_dec_close( return; } -Word32 pFC_8k[IVAS_MAX_NUM_BANDS] = { 33, 100, 166, 233, 300, 366, 433, 566, 866, 1333, 2033, 3233 }; -Word32 pFC_12k[IVAS_MAX_NUM_BANDS] = { 53, 160, 266, 373, 480, 586, 693, 906, 1386, 2133, 3253, 5173 }; -Word32 pFC_16k[IVAS_MAX_NUM_BANDS] = { 66, 200, 333, 466, 600, 733, 866, 1133, 1733, 2666, 4066, 6466 }; -Word32 pFC_32k[IVAS_MAX_NUM_BANDS] = { 133, 400, 666, 933, 1200, 1466, 1733, 2266, 3466, 5333, 8133, 12933 }; -Word32 pFC_48k[IVAS_MAX_NUM_BANDS] = { 199, 600, 1000, 1400, 1800, 2200, 2600, 3400, 5200, 8000, 12200, 19400 }; +Word32 pFC_8k[IVAS_MAX_NUM_BANDS] = { 33, 100, 166, 233, 300, 366, 433, 566, 866, 1333, 2033, 3233 }; /*Q0*/ +Word32 pFC_12k[IVAS_MAX_NUM_BANDS] = { 53, 160, 266, 373, 480, 586, 693, 906, 1386, 2133, 3253, 5173 }; /*Q0*/ +Word32 pFC_16k[IVAS_MAX_NUM_BANDS] = { 66, 200, 333, 466, 600, 733, 866, 1133, 1733, 2666, 4066, 6466 }; /*Q0*/ +Word32 pFC_32k[IVAS_MAX_NUM_BANDS] = { 133, 400, 666, 933, 1200, 1466, 1733, 2266, 3466, 5333, 8133, 12933 }; /*Q0*/ +Word32 pFC_48k[IVAS_MAX_NUM_BANDS] = { 199, 600, 1000, 1400, 1800, 2200, 2600, 3400, 5200, 8000, 12200, 19400 }; /*Q0*/ #ifndef IVAS_FLOAT_FIXED /*-----------------------------------------------------------------------------------------* @@ -921,8 +921,8 @@ ivas_error ivas_spar_md_dec_init( ivas_error ivas_spar_md_dec_init( ivas_spar_md_dec_state_t *hMdDec, /* i/o: SPAR MD decoder handle */ const DECODER_CONFIG_HANDLE hDecoderConfig, /* i : configuration structure */ - const Word16 num_channels, /* i : number of internal channels */ - const Word16 sba_order /* i : SBA order */ + const Word16 num_channels, /* i : number of internal channels Q0*/ + const Word16 sba_order /* i : SBA order Q0*/ ) { Word16 i, j; @@ -952,23 +952,23 @@ ivas_error ivas_spar_md_dec_init( IF( EQ_32( hDecoderConfig->output_Fs, 8000 ) ) { - pFC_fx = pFC_8k; + pFC_fx = pFC_8k; /*Q0*/ } ELSE IF( EQ_32( hDecoderConfig->output_Fs, 12800 ) ) { - pFC_fx = pFC_12k; + pFC_fx = pFC_12k; /*Q0*/ } ELSE IF( EQ_32( hDecoderConfig->output_Fs, 16000 ) ) { - pFC_fx = pFC_16k; + pFC_fx = pFC_16k; /*Q0*/ } ELSE IF( EQ_32( hDecoderConfig->output_Fs, 32000 ) ) { - pFC_fx = pFC_32k; + pFC_fx = pFC_32k; /*Q0*/ } ELSE IF( EQ_32( hDecoderConfig->output_Fs, 48000 ) ) { - pFC_fx = pFC_48k; + pFC_fx = pFC_48k; /*Q0*/ } ELSE { @@ -988,9 +988,9 @@ ivas_error ivas_spar_md_dec_init( } /* DTX quant init */ - PR_minmax_fx[0] = hMdDec->spar_md_cfg.quant_strat[0].PR.min_fx; + PR_minmax_fx[0] = hMdDec->spar_md_cfg.quant_strat[0].PR.min_fx; /*Q28*/ move32(); - PR_minmax_fx[1] = hMdDec->spar_md_cfg.quant_strat[0].PR.max_fx; + PR_minmax_fx[1] = hMdDec->spar_md_cfg.quant_strat[0].PR.max_fx; /*Q28*/ move32(); ivas_spar_quant_dtx_init_fx( &hMdDec->spar_md, PR_minmax_fx ); @@ -1058,17 +1058,17 @@ ivas_error ivas_spar_md_dec_init( static ivas_error ivas_spar_set_dec_config( ivas_spar_md_dec_state_t *hMdDec, const Word16 nchan_transport, - Word32 *pFC ) + Word32 *pFC /*Q0*/ ) { Word16 i, j, nchan, dmx_ch; FOR( i = 0; i < nchan_transport; i++ ) { - hMdDec->spar_md_cfg.max_freq_per_chan[i] = ivas_spar_br_table_consts[hMdDec->table_idx].fpcs; + hMdDec->spar_md_cfg.max_freq_per_chan[i] = ivas_spar_br_table_consts[hMdDec->table_idx].fpcs; /*Q0*/ move16(); } - nchan = ivas_sba_get_nchan_metadata_fx( ivas_spar_br_table_consts[hMdDec->table_idx].sba_order, ivas_spar_br_table_consts[hMdDec->table_idx].ivas_total_brate ); + nchan = ivas_sba_get_nchan_metadata_fx( ivas_spar_br_table_consts[hMdDec->table_idx].sba_order, ivas_spar_br_table_consts[hMdDec->table_idx].ivas_total_brate ); /*Q0*/ SWITCH( nchan ) { @@ -1090,7 +1090,7 @@ static ivas_error ivas_spar_set_dec_config( BREAK; } - hMdDec->spar_md_cfg.num_umx_chs = nchan; + hMdDec->spar_md_cfg.num_umx_chs = nchan; /*Q0*/ move16(); dmx_ch = 0; @@ -1107,13 +1107,13 @@ static ivas_error ivas_spar_set_dec_config( } } - hMdDec->spar_md_cfg.num_dmx_chans_per_band[i] = hMdDec->spar_md_cfg.nchan_transport; + hMdDec->spar_md_cfg.num_dmx_chans_per_band[i] = hMdDec->spar_md_cfg.nchan_transport; /*Q0*/ move16(); - hMdDec->spar_md_cfg.num_decorr_per_band[i] = sub( nchan, hMdDec->spar_md_cfg.nchan_transport ); + hMdDec->spar_md_cfg.num_decorr_per_band[i] = sub( nchan, hMdDec->spar_md_cfg.nchan_transport ); /*Q0*/ move16(); } - hMdDec->spar_md_cfg.nchan_transport = dmx_ch; + hMdDec->spar_md_cfg.nchan_transport = dmx_ch; /*Q0*/ move16(); return IVAS_ERR_OK; @@ -1248,11 +1248,11 @@ static void ivas_dec_mono_sba_handling_fx( { FOR( block = 0; block < MAX_PARAM_SPATIAL_SUBFRAMES; ++block ) { - Word32 azimuth_fx = st_ivas->hQMetaData->q_direction[0].band_data[b].azimuth_fx[block]; + Word32 azimuth_fx = st_ivas->hQMetaData->q_direction[0].band_data[b].azimuth_fx[block]; /*Q22*/ move32(); - Word32 elevation_fx = st_ivas->hQMetaData->q_direction[0].band_data[b].azimuth_fx[block]; + Word32 elevation_fx = st_ivas->hQMetaData->q_direction[0].band_data[b].azimuth_fx[block]; /*Q22*/ move32(); - Word32 energy_ratio_fx = st_ivas->hQMetaData->q_direction[0].band_data[0].energy_ratio_fx[block]; + Word32 energy_ratio_fx = st_ivas->hQMetaData->q_direction[0].band_data[0].energy_ratio_fx[block]; /*Q30*/ move32(); test(); @@ -1290,7 +1290,7 @@ static void ivas_dec_mono_sba_handling_fx( set32_fx( st_ivas->hSpatParamRendCom->energy_ratio2_fx[block], 0, st_ivas->hSpatParamRendCom->num_freq_bands ); } /* Set Diffuseness values to be 1.0 */ - set32_fx( st_ivas->hSpatParamRendCom->diffuseness_vector_fx[block], ONE_IN_Q30, st_ivas->hSpatParamRendCom->num_freq_bands ); + set32_fx( st_ivas->hSpatParamRendCom->diffuseness_vector_fx[block], ONE_IN_Q30, st_ivas->hSpatParamRendCom->num_freq_bands ); /*Q30*/ } } } @@ -1310,8 +1310,8 @@ static void ivas_dec_mono_sba_handling_fx( void ivas_spar_md_dec_process_fx( Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ Decoder_State *st0, /* i/o: decoder state structure - for bitstream handling */ - const Word16 num_bands_out, /* i : number of output bands */ - const Word16 sba_order /* i : Ambisonic (SBA) order */ + const Word16 num_bands_out, /* i : number of output bands Q0*/ + const Word16 sba_order /* i : Ambisonic (SBA) order Q0*/ ) { Word16 j, k, b, bw, dtx_vad, nB, i_ts; @@ -1334,28 +1334,28 @@ void ivas_spar_md_dec_process_fx( move16(); } - num_md_chs = ivas_sba_get_nchan_metadata_fx( sba_order, st_ivas->hDecoderConfig->ivas_total_brate ); + num_md_chs = ivas_sba_get_nchan_metadata_fx( sba_order, st_ivas->hDecoderConfig->ivas_total_brate ); /*Q0*/ - num_md_sub_frames = ivas_get_spar_dec_md_num_subframes( sba_order, st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->last_active_ivas_total_brate ); + num_md_sub_frames = ivas_get_spar_dec_md_num_subframes( sba_order, st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->last_active_ivas_total_brate ); /*Q0*/ test(); IF( GT_16( hMdDec->spar_md_cfg.nchan_transport, 1 ) && LE_16( hMdDec->spar_md_cfg.nchan_transport, 3 ) ) { hMdDec->spar_md.res_ind = 0; move16(); - dyn_active_w_flag = get_next_indice_fx( st0, 1 ); + dyn_active_w_flag = get_next_indice_fx( st0, 1 ); /*Q0*/ IF( EQ_16( dyn_active_w_flag, 1 ) ) { IF( EQ_16( hMdDec->spar_md_cfg.nchan_transport, 2 ) ) { - hMdDec->spar_md.res_ind = get_next_indice_fx( st0, 1 ); + hMdDec->spar_md.res_ind = get_next_indice_fx( st0, 1 ); /*Q0*/ move16(); - hMdDec->spar_md.res_ind = add( hMdDec->spar_md_cfg.nchan_transport, hMdDec->spar_md.res_ind ); + hMdDec->spar_md.res_ind = add( hMdDec->spar_md_cfg.nchan_transport, hMdDec->spar_md.res_ind ); /*Q0*/ move16(); } ELSE IF( EQ_16( hMdDec->spar_md_cfg.nchan_transport, 3 ) ) { - hMdDec->spar_md.res_ind = remix_order_set[hMdDec->spar_md_cfg.remix_unmix_order][hMdDec->spar_md_cfg.nchan_transport]; + hMdDec->spar_md.res_ind = remix_order_set[hMdDec->spar_md_cfg.remix_unmix_order][hMdDec->spar_md_cfg.nchan_transport]; /*Q0*/ move16(); } } @@ -1402,7 +1402,7 @@ void ivas_spar_md_dec_process_fx( { FOR( j = 0; j < IVAS_SPAR_MAX_CH - 1; j++ ) { - hMdDec->spar_md.band_coeffs[add( b, i_mult( i_ts, IVAS_MAX_NUM_BANDS ) )].pred_re_fx[j] = hMdDec->spar_md.band_coeffs[b].pred_re_fx[j]; + hMdDec->spar_md.band_coeffs[( b + ( i_ts * IVAS_MAX_NUM_BANDS ) )].pred_re_fx[j] = hMdDec->spar_md.band_coeffs[b].pred_re_fx[j]; /*Q22*/ move32(); } @@ -1410,14 +1410,14 @@ void ivas_spar_md_dec_process_fx( { FOR( k = 0; k < IVAS_SPAR_MAX_DMX_CHS - 1; k++ ) { - hMdDec->spar_md.band_coeffs[add( b, i_mult( i_ts, IVAS_MAX_NUM_BANDS ) )].C_re_fx[j][k] = hMdDec->spar_md.band_coeffs[b].C_re_fx[j][k]; + hMdDec->spar_md.band_coeffs[( b + ( i_ts * IVAS_MAX_NUM_BANDS ) )].C_re_fx[j][k] = hMdDec->spar_md.band_coeffs[b].C_re_fx[j][k]; /*Q22*/ move32(); } } FOR( j = 0; j < IVAS_SPAR_MAX_CH - 1; j++ ) { - hMdDec->spar_md.band_coeffs[add( b, i_mult( i_ts, IVAS_MAX_NUM_BANDS ) )].P_re_fx[j] = hMdDec->spar_md.band_coeffs[b].P_re_fx[j]; + hMdDec->spar_md.band_coeffs[add( b, i_mult( i_ts, IVAS_MAX_NUM_BANDS ) )].P_re_fx[j] = hMdDec->spar_md.band_coeffs[b].P_re_fx[j]; /*Q22*/ move32(); } } @@ -1634,9 +1634,9 @@ Word16 ivas_spar_chk_zero_coefs_fx( Word16 ndec, ndm; hMdDec = st_ivas->hSpar->hMdDec; - ndec = hMdDec->spar_md_cfg.num_decorr_per_band[0]; + ndec = hMdDec->spar_md_cfg.num_decorr_per_band[0]; /*Q0*/ move16(); - ndm = hMdDec->spar_md_cfg.num_dmx_chans_per_band[0]; + ndm = hMdDec->spar_md_cfg.num_dmx_chans_per_band[0]; /*Q0*/ move16(); FOR( b = 0; b < min( hMdDec->spar_md.num_bands, SPAR_DIRAC_SPLIT_START_BAND ); b++ ) @@ -1684,8 +1684,8 @@ Word16 ivas_spar_chk_zero_coefs_fx( #ifdef IVAS_FLOAT_FIXED void ivas_spar_smooth_md_dtx_fx( ivas_spar_md_dec_state_t *hMdDec, /* i/o: SPAR MD decoder handle */ - const Word16 num_bands_out, /* i : number of output bands */ - const Word16 num_md_sub_frames /* i : number of metadata subframes */ + const Word16 num_bands_out, /* i : number of output bands Q0*/ + const Word16 num_md_sub_frames /* i : number of metadata subframes Q0*/ ) { Word16 j, k, b, dmx_ch; @@ -1734,14 +1734,14 @@ void ivas_spar_smooth_md_dtx_fx( { FOR( b = 0; b < num_bands_out; b++ ) { - dmx_ch = hMdDec->spar_md_cfg.num_dmx_chans_per_band[b]; + dmx_ch = hMdDec->spar_md_cfg.num_dmx_chans_per_band[b]; /*Q0*/ move16(); FOR( j = 1; j < FOA_CHANNELS; j++ ) { FOR( k = dmx_ch; k < FOA_CHANNELS; k++ ) { - hMdDec->spar_coeffs.P_re_fx[j][k][add( b, i_mult( i_ts, IVAS_MAX_NUM_BANDS ) )] = hMdDec->spar_coeffs.P_re_fx[j][k][b]; /* Q22 */ + hMdDec->spar_coeffs.P_re_fx[j][k][( b + ( i_ts * IVAS_MAX_NUM_BANDS ) )] = hMdDec->spar_coeffs.P_re_fx[j][k][b]; /* Q22 */ move32(); } } @@ -1750,7 +1750,7 @@ void ivas_spar_smooth_md_dtx_fx( { FOR( k = 0; k < dmx_ch; k++ ) { - hMdDec->spar_coeffs.C_re_fx[j][k][add( b, i_mult( i_ts, IVAS_MAX_NUM_BANDS ) )] = hMdDec->spar_coeffs.C_re_fx[j][k][b]; /* Q22 */ + hMdDec->spar_coeffs.C_re_fx[j][k][( b + ( i_ts * IVAS_MAX_NUM_BANDS ) )] = hMdDec->spar_coeffs.C_re_fx[j][k][b]; /* Q22 */ move32(); } } @@ -1843,14 +1843,14 @@ void ivas_spar_smooth_md_dtx( #ifdef IVAS_FLOAT_FIXED void ivas_spar_setup_md_smoothing_fx( ivas_spar_md_dec_state_t *hMdDec, /* i/o: SPAR MD decoder handle */ - const Word16 num_bands_out, /* i : number of output bands */ - const Word16 num_md_sub_frames /* i : number of metadata subframes */ + const Word16 num_bands_out, /* i : number of output bands Q0*/ + const Word16 num_md_sub_frames /* i : number of metadata subframes Q0*/ ) { /* copy the coeffs */ Word16 num_channels, i, j, k; - num_channels = hMdDec->spar_md_cfg.num_umx_chs; + num_channels = hMdDec->spar_md_cfg.num_umx_chs; /*Q0*/ move16(); FOR( i = 0; i < num_channels; i++ ) @@ -1981,7 +1981,7 @@ void ivas_spar_update_md_hist_fx( { Word16 num_channels, i, j, k; - num_channels = hMdDec->spar_md_cfg.num_umx_chs; + num_channels = hMdDec->spar_md_cfg.num_umx_chs; /*Q0*/ move16(); FOR( i = 0; i < num_channels; i++ ) @@ -2327,14 +2327,14 @@ static void ivas_get_spar_matrices( static void ivas_get_spar_matrices_fx( ivas_spar_md_dec_state_t *hMdDec, - const Word16 num_bands_out, - const Word16 n_ts, - const Word16 bw, - const Word16 dtx_vad, - const Word16 nB, - const Word16 numch_out, - const Word16 active_w_vlbr, - const Word16 dyn_active_w_flag ) + const Word16 num_bands_out, /*Q0*/ + const Word16 n_ts, /*Q0*/ + const Word16 bw, /*Q0*/ + const Word16 dtx_vad, /*Q0*/ + const Word16 nB, /*Q0*/ + const Word16 numch_out, /*Q0*/ + const Word16 active_w_vlbr, /*Q0*/ + const Word16 dyn_active_w_flag /*Q0*/ ) { Word16 num_bands, dmx_ch, split_band; Word16 i, j, k, m, b, i_ts, active_w; @@ -2359,7 +2359,7 @@ static void ivas_get_spar_matrices_fx( { FOR( b = 0; b < num_bands; b++ ) { - hMdDec->mixer_mat_prev_fx[0][i][j][b] = hMdDec->mixer_mat_fx[i][j][b]; + hMdDec->mixer_mat_prev_fx[0][i][j][b] = hMdDec->mixer_mat_fx[i][j][b]; /*hMdDec->Q_mixer_mat*/ move32(); } } @@ -2397,8 +2397,8 @@ static void ivas_get_spar_matrices_fx( FOR( j = 0; j < numch_out; j++ ) { - set32_fx( &hMdDec->spar_coeffs.C_re_fx[i][j][i_mult( i_ts, IVAS_MAX_NUM_BANDS )], 0, IVAS_MAX_NUM_BANDS ); - set32_fx( &hMdDec->spar_coeffs.P_re_fx[i][j][i_mult( i_ts, IVAS_MAX_NUM_BANDS )], 0, IVAS_MAX_NUM_BANDS ); + set32_fx( &hMdDec->spar_coeffs.C_re_fx[i][j][( i_ts * IVAS_MAX_NUM_BANDS )], 0, IVAS_MAX_NUM_BANDS ); + set32_fx( &hMdDec->spar_coeffs.P_re_fx[i][j][( i_ts * IVAS_MAX_NUM_BANDS )], 0, IVAS_MAX_NUM_BANDS ); } } num_bands = s_min( num_bands, nB ); @@ -2409,7 +2409,7 @@ static void ivas_get_spar_matrices_fx( Word32 tmp_C1_re_fx[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH]; Word32 tmp_C2_re_fx[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH]; Word32 tmp_dm_re_fx[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH]; - dmx_ch = hMdDec->spar_md_cfg.num_dmx_chans_per_band[i_mult( bw, b )]; + dmx_ch = hMdDec->spar_md_cfg.num_dmx_chans_per_band[( bw * b )]; /*Q0*/ move16(); FOR( j = 0; j < numch_out; j++ ) @@ -2418,9 +2418,9 @@ static void ivas_get_spar_matrices_fx( set_zero_fx( tmp_C2_re_fx[j], numch_out ); set_zero_fx( tmp_dm_re_fx[j], numch_out ); - tmp_C1_re_fx[j][j] = ONE_IN_Q22; - tmp_C2_re_fx[j][j] = ONE_IN_Q22; - tmp_dm_re_fx[j][j] = ONE_IN_Q22; + tmp_C1_re_fx[j][j] = ONE_IN_Q22; /*Q22*/ + tmp_C2_re_fx[j][j] = ONE_IN_Q22; /*Q22*/ + tmp_dm_re_fx[j][j] = ONE_IN_Q22; /*Q22*/ move32(); move32(); move32(); @@ -2428,7 +2428,7 @@ static void ivas_get_spar_matrices_fx( FOR( j = 1; j < numch_out; j++ ) { - tmp_C1_re_fx[j][0] = hMdDec->spar_md.band_coeffs[add( b, i_mult( i_ts, IVAS_MAX_NUM_BANDS ) )].pred_re_fx[j - 1]; // Q.22 + tmp_C1_re_fx[j][0] = hMdDec->spar_md.band_coeffs[( b + ( i_ts * IVAS_MAX_NUM_BANDS ) )].pred_re_fx[j - 1]; // Q.22 move32(); } @@ -2437,7 +2437,7 @@ static void ivas_get_spar_matrices_fx( FOR( j = 1; j < numch_out; j++ ) { - tmp_C2_re_fx[0][j] = Mpy_32_32( active_w_dm_fac_fx, L_negate( hMdDec->spar_md.band_coeffs[add( b, i_mult( i_ts, IVAS_MAX_NUM_BANDS ) )].pred_re_fx[j - 1] ) ); // Q31 *Q22=Q22 + tmp_C2_re_fx[0][j] = Mpy_32_32( active_w_dm_fac_fx, L_negate( hMdDec->spar_md.band_coeffs[( b + ( i_ts * IVAS_MAX_NUM_BANDS ) )].pred_re_fx[j - 1] ) ); // Q31 *Q22=Q22 move32(); } re_fx = Mpy_32_32( tmp_C2_re_fx[0][1], tmp_C1_re_fx[1][0] ); // Q22 *Q22 =Q13 @@ -2456,22 +2456,22 @@ static void ivas_get_spar_matrices_fx( move32(); } - tmp_dm_re_fx[0][1] = tmp_C2_re_fx[0][1]; + tmp_dm_re_fx[0][1] = tmp_C2_re_fx[0][1]; /*Q22*/ move32(); - tmp_dm_re_fx[0][2] = tmp_C2_re_fx[0][2]; + tmp_dm_re_fx[0][2] = tmp_C2_re_fx[0][2]; /*Q22*/ move32(); - tmp_dm_re_fx[0][3] = tmp_C2_re_fx[0][3]; + tmp_dm_re_fx[0][3] = tmp_C2_re_fx[0][3]; /*Q22*/ move32(); - tmp_dm_re_fx[1][0] = tmp_C1_re_fx[1][0]; + tmp_dm_re_fx[1][0] = tmp_C1_re_fx[1][0]; /*Q22*/ move32(); - tmp_dm_re_fx[2][0] = tmp_C1_re_fx[2][0]; + tmp_dm_re_fx[2][0] = tmp_C1_re_fx[2][0]; /*Q22*/ move32(); - tmp_dm_re_fx[3][0] = tmp_C1_re_fx[3][0]; + tmp_dm_re_fx[3][0] = tmp_C1_re_fx[3][0]; /*Q22*/ move32(); IF( NE_16( hMdDec->spar_md_cfg.remix_unmix_order, 3 ) ) @@ -2506,7 +2506,7 @@ static void ivas_get_spar_matrices_fx( FOR( k = 0; k < dmx_ch; k++ ) { - tmpC_re_fx[k][k] = ONE_IN_Q22; + tmpC_re_fx[k][k] = ONE_IN_Q22; /*Q22*/ move32(); } @@ -2543,9 +2543,9 @@ static void ivas_get_spar_matrices_fx( { FOR( m = 0; m < numch_out; m++ ) { - re_fx = Mpy_32_32( hMdDec->mixer_mat_fx[j][m][add( b, i_mult( i_ts, IVAS_MAX_NUM_BANDS ) )], tmpP_re_fx[m][k] ); // Q30*Q22 - re_fx = L_shl( re_fx, 1 ); - hMdDec->spar_coeffs.P_re_fx[j][k][add( i_mult( b, bw ), i_mult( i_ts, IVAS_MAX_NUM_BANDS ) )] = L_add( hMdDec->spar_coeffs.P_re_fx[j][k][add( i_mult( b, bw ), i_mult( i_ts, IVAS_MAX_NUM_BANDS ) )], re_fx ); + re_fx = Mpy_32_32( hMdDec->mixer_mat_fx[j][m][( b + ( i_ts * IVAS_MAX_NUM_BANDS ) )], tmpP_re_fx[m][k] ); // Q30*Q22 = Q21 + re_fx = L_shl( re_fx, 1 ); /*Q22*/ + hMdDec->spar_coeffs.P_re_fx[j][k][( ( b * bw ) + ( i_ts * IVAS_MAX_NUM_BANDS ) )] = L_add( hMdDec->spar_coeffs.P_re_fx[j][k][( ( b * bw ) + ( i_ts * IVAS_MAX_NUM_BANDS ) )], re_fx ); /*Q22*/ move32(); } } @@ -2558,16 +2558,16 @@ static void ivas_get_spar_matrices_fx( { FOR( m = 0; m < numch_out; m++ ) { - re_fx = Mpy_32_32( hMdDec->mixer_mat_fx[j][m][add( b, i_mult( i_ts, IVAS_MAX_NUM_BANDS ) )], tmpC_re_fx[m][k] ); // Q30* Q22 - re_fx = L_shl( re_fx, 1 ); - hMdDec->spar_coeffs.C_re_fx[j][k][add( i_mult( b, bw ), i_mult( i_ts, IVAS_MAX_NUM_BANDS ) )] = L_add( hMdDec->spar_coeffs.C_re_fx[j][k][add( i_mult( b, bw ), i_mult( i_ts, IVAS_MAX_NUM_BANDS ) )], re_fx ); + re_fx = Mpy_32_32( hMdDec->mixer_mat_fx[j][m][( b + ( i_ts * IVAS_MAX_NUM_BANDS ) )], tmpC_re_fx[m][k] ); // Q30* Q22 = Q21 + re_fx = L_shl( re_fx, 1 ); /*Q22*/ + hMdDec->spar_coeffs.C_re_fx[j][k][( ( b * bw ) + ( i_ts * IVAS_MAX_NUM_BANDS ) )] = L_add( hMdDec->spar_coeffs.C_re_fx[j][k][( ( b * bw ) + ( i_ts * IVAS_MAX_NUM_BANDS ) )], re_fx ); /*Q22*/ move32(); } } } - hMdDec->spar_coeffs.C_re_fx[0][0][add( i_mult( b, bw ), i_mult( i_ts, IVAS_MAX_NUM_BANDS ) )] = - L_max( 0, hMdDec->spar_coeffs.C_re_fx[0][0][add( i_mult( b, bw ), i_mult( i_ts, IVAS_MAX_NUM_BANDS ) )] ); + hMdDec->spar_coeffs.C_re_fx[0][0][( ( b * bw ) + ( i_ts * IVAS_MAX_NUM_BANDS ) )] = + L_max( 0, hMdDec->spar_coeffs.C_re_fx[0][0][( ( b * bw ) + ( i_ts * IVAS_MAX_NUM_BANDS ) )] ); /*Q22*/ move32(); } } @@ -2575,7 +2575,7 @@ static void ivas_get_spar_matrices_fx( /* band mixing */ IF( EQ_16( bw, IVAS_RED_BAND_FACT ) ) { - FOR( b = 0; b < num_bands_out; b = add( b, bw ) ) + FOR( b = 0; b < num_bands_out; b = ( b + bw ) ) { dmx_ch = hMdDec->spar_md_cfg.num_dmx_chans_per_band[b]; move16(); @@ -2583,7 +2583,7 @@ static void ivas_get_spar_matrices_fx( { FOR( k = dmx_ch; k < numch_out; k++ ) { - hMdDec->spar_coeffs.P_re_fx[j][k][add( add( b, 1 ), i_mult( i_ts, IVAS_MAX_NUM_BANDS ) )] = hMdDec->spar_coeffs.P_re_fx[j][k][add( b, i_mult( i_ts, IVAS_MAX_NUM_BANDS ) )]; + hMdDec->spar_coeffs.P_re_fx[j][k][( ( b + 1 ) + ( i_ts * IVAS_MAX_NUM_BANDS ) )] = hMdDec->spar_coeffs.P_re_fx[j][k][( b + ( i_ts * IVAS_MAX_NUM_BANDS ) )]; /*Q22*/ move32(); } } @@ -2592,7 +2592,7 @@ static void ivas_get_spar_matrices_fx( { FOR( k = 0; k < dmx_ch; k++ ) { - hMdDec->spar_coeffs.C_re_fx[j][k][add( add( b, 1 ), i_mult( i_ts, IVAS_MAX_NUM_BANDS ) )] = hMdDec->spar_coeffs.C_re_fx[j][k][add( b, i_mult( i_ts, IVAS_MAX_NUM_BANDS ) )]; + hMdDec->spar_coeffs.C_re_fx[j][k][( ( b + 1 ) + ( i_ts * IVAS_MAX_NUM_BANDS ) )] = hMdDec->spar_coeffs.C_re_fx[j][k][( b + ( i_ts * IVAS_MAX_NUM_BANDS ) )]; /*Q22*/ move32(); } } @@ -2641,23 +2641,23 @@ static void ivas_mat_col_rearrange( *-----------------------------------------------------------------------------------------*/ static void ivas_mat_col_rearrange_fx( - Word32 in_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], - const Word16 order[IVAS_SPAR_MAX_CH], - const Word16 i_ts, - Word32 ***mixer_mat, - const Word16 bands, - const Word16 num_ch ) + Word32 in_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], /*Q22*/ + const Word16 order[IVAS_SPAR_MAX_CH], /*Q0*/ + const Word16 i_ts, /*Q0*/ + Word32 ***mixer_mat, /*Q30*/ + const Word16 bands, /*Q0*/ + const Word16 num_ch /*Q0*/ ) { Word16 i, j, idx; FOR( i = 0; i < num_ch; i++ ) { - idx = order[i]; + idx = order[i]; /*Q0*/ move16(); FOR( j = 0; j < num_ch; j++ ) { - mixer_mat[j][i][add( bands, i_mult( i_ts, IVAS_MAX_NUM_BANDS ) )] = L_shl_sat( in_re[j][idx], Q8 ); + mixer_mat[j][i][( bands + ( i_ts * IVAS_MAX_NUM_BANDS ) )] = L_shl_sat( in_re[j][idx], Q8 ); /*Q30*/ move32(); } } @@ -2674,10 +2674,10 @@ static void ivas_mat_col_rearrange_fx( #ifdef IVAS_FLOAT_FIXED void ivas_spar_dec_gen_umx_mat_fx( ivas_spar_md_dec_state_t *hMdDec, /* i/o: SPAR MD decoder handle */ - const Word16 nchan_transport, /* i : number of transport channels */ - const Word16 num_bands_out, /* i : number of output bands */ - const Word16 bfi, /* i : bad frame indicator */ - const Word16 num_md_sub_frames ) + const Word16 nchan_transport, /* i : number of transport channels Q0*/ + const Word16 num_bands_out, /* i : number of output bands Q0*/ + const Word16 bfi, /* i : bad frame indicator Q0*/ + const Word16 num_md_sub_frames /*Q0*/ ) { Word16 i, j, b, i_ts, num_out_ch; num_out_ch = hMdDec->spar_md_cfg.num_umx_chs; @@ -2692,7 +2692,7 @@ void ivas_spar_dec_gen_umx_mat_fx( { FOR( b = 0; b < num_bands_out; b++ ) { - hMdDec->mixer_mat_fx[i][j][add( b, i_mult( i_ts, IVAS_MAX_NUM_BANDS ) )] = L_shl_sat( hMdDec->spar_coeffs.C_re_fx[i][j][add( b, i_mult( i_ts, IVAS_MAX_NUM_BANDS ) )], Q8 ); + hMdDec->mixer_mat_fx[i][j][( b + ( i_ts * IVAS_MAX_NUM_BANDS ) )] = L_shl_sat( hMdDec->spar_coeffs.C_re_fx[i][j][( b + ( i_ts * IVAS_MAX_NUM_BANDS ) )], Q8 ); /*Q30*/ move32(); } } @@ -2703,7 +2703,7 @@ void ivas_spar_dec_gen_umx_mat_fx( { FOR( b = 0; b < num_bands_out; b++ ) { - hMdDec->mixer_mat_fx[i][j][add( b, i_mult( i_ts, IVAS_MAX_NUM_BANDS ) )] = L_shl_sat( hMdDec->spar_coeffs.P_re_fx[i][j][add( b, i_mult( i_ts, IVAS_MAX_NUM_BANDS ) )], Q8 ); + hMdDec->mixer_mat_fx[i][j][( b + ( i_ts * IVAS_MAX_NUM_BANDS ) )] = L_shl_sat( hMdDec->spar_coeffs.P_re_fx[i][j][( b + ( i_ts * IVAS_MAX_NUM_BANDS ) )], Q8 ); /*Q30*/ move32(); } } @@ -2717,7 +2717,7 @@ void ivas_spar_dec_gen_umx_mat_fx( { FOR( b = 0; b < num_bands_out; b++ ) { - hMdDec->mixer_mat_fx[i][j][add( b, i_mult( i_ts, IVAS_MAX_NUM_BANDS ) )] = L_shl_sat( hMdDec->spar_coeffs.C_re_fx[i][j][add( b, i_mult( i_ts, IVAS_MAX_NUM_BANDS ) )], Q8 ); + hMdDec->mixer_mat_fx[i][j][( b + ( i_ts * IVAS_MAX_NUM_BANDS ) )] = L_shl_sat( hMdDec->spar_coeffs.C_re_fx[i][j][( b + ( i_ts * IVAS_MAX_NUM_BANDS ) )], Q8 ); /*Q30*/ move32(); } } @@ -2791,47 +2791,47 @@ void ivas_spar_dec_gen_umx_mat( static void ivas_spar_md_band_upmix( ivas_band_coeffs_t *band_coeffs, - Word16 *nB, - Word16 *bands_bw, - Word16 *valid_bands, - Word16 bw_final, - Word16 ndec, - Word16 ndm ) + Word16 *nB, /*Q0*/ + Word16 *bands_bw, /*Q0*/ + Word16 *valid_bands, /*Q0*/ + Word16 bw_final, /*Q0*/ + Word16 ndec, /*Q0*/ + Word16 ndm /*Q0*/ ) { Word16 i, ii, jj, b, idx, bw_fact; - bw_fact = idiv1616( *bands_bw, bw_final ); + bw_fact = idiv1616( *bands_bw, bw_final ); /*Q0*/ FOR( i = sub( *nB, 1 ); i >= 0; i-- ) { FOR( b = sub( bw_fact, 1 ); b >= 0; b-- ) { - idx = add( i_mult( i, bw_fact ), b ); - FOR( ii = 0; ii < sub( add( ndec, ndm ), 1 ); ii++ ) + idx = add( i_mult( i, bw_fact ), b ); /*Q0*/ + FOR( ii = 0; ii < ( ( ndec + ndm ) - 1 ); ii++ ) { - band_coeffs[idx].pred_re_fx[ii] = band_coeffs[i].pred_re_fx[ii]; + band_coeffs[idx].pred_re_fx[ii] = band_coeffs[i].pred_re_fx[ii]; /*Q22*/ move32(); } FOR( ii = 0; ii < ndec; ii++ ) { FOR( jj = 0; jj < sub( ndm, 1 ); jj++ ) { - band_coeffs[idx].C_re_fx[ii][jj] = band_coeffs[i].C_re_fx[ii][jj]; + band_coeffs[idx].C_re_fx[ii][jj] = band_coeffs[i].C_re_fx[ii][jj]; /*Q22*/ move32(); } } FOR( jj = 0; jj < ndec; jj++ ) { - band_coeffs[idx].P_re_fx[jj] = band_coeffs[i].P_re_fx[jj]; + band_coeffs[idx].P_re_fx[jj] = band_coeffs[i].P_re_fx[jj]; /*Q22*/ move32(); } - valid_bands[idx] = valid_bands[i]; + valid_bands[idx] = valid_bands[i]; /*Q0*/ move16(); } } - *nB = idiv1616( i_mult( ( *nB ), ( *bands_bw ) ), bw_final ); + *nB = idiv1616( i_mult( ( *nB ), ( *bands_bw ) ), bw_final ); /*Q0*/ move16(); - *bands_bw = bw_final; + *bands_bw = bw_final; /*Q0*/ move16(); return; @@ -3081,11 +3081,11 @@ static void ivas_spar_dec_parse_md_bs( static void ivas_spar_dec_parse_md_bs_fx( ivas_spar_md_dec_state_t *hMdDec, Decoder_State *st0, - Word16 *nB, - Word16 *bands_bw, - Word16 *dtx_vad, - const Word32 ivas_total_brate, - const Word16 sba_inactive_mode ) + Word16 *nB, /*Q0*/ + Word16 *bands_bw, /*Q0*/ + Word16 *dtx_vad, /*Q0*/ + const Word32 ivas_total_brate, /*Q0*/ + const Word16 sba_inactive_mode /*Q0*/ ) { Word16 i, j, k, num_bands; Word16 ii, jj, ndec, ndm; @@ -3111,7 +3111,7 @@ static void ivas_spar_dec_parse_md_bs_fx( IF( GE_32( ivas_total_brate, BRATE_SPAR_Q_STRAT ) ) { /*only one bit written for quantization strategy to indicate either a fixed quantization strategy or dtx_vad==0 */ - qsi = get_next_indice_fx( st0, 1 ); + qsi = get_next_indice_fx( st0, 1 ); /*Q0*/ if ( EQ_32( qsi, 1 ) ) { *dtx_vad = 0; @@ -3144,14 +3144,14 @@ static void ivas_spar_dec_parse_md_bs_fx( move16(); } - hMdDec->dtx_vad = *dtx_vad; + hMdDec->dtx_vad = *dtx_vad; /*Q0*/ move16(); IF( *dtx_vad == 0 ) { *nB = SPAR_DTX_BANDS; move16(); - *bands_bw = idiv1616( num_bands, *nB ); + *bands_bw = idiv1616( num_bands, *nB ); /*Q0*/ move16(); FOR( i = 0; i < *nB; i++ ) @@ -3183,9 +3183,9 @@ static void ivas_spar_dec_parse_md_bs_fx( IF( NE_16( *bands_bw, 1 ) ) { - ndec = hMdDec->spar_md_cfg.num_decorr_per_band[0]; + ndec = hMdDec->spar_md_cfg.num_decorr_per_band[0]; /*Q0*/ move16(); - ndm = hMdDec->spar_md_cfg.num_dmx_chans_per_band[0]; + ndm = hMdDec->spar_md_cfg.num_dmx_chans_per_band[0]; /*Q0*/ move16(); ivas_spar_md_band_upmix( hMdDec->spar_md.band_coeffs, @@ -3202,7 +3202,7 @@ static void ivas_spar_dec_parse_md_bs_fx( qs = hMdDec->spar_md_cfg.quant_strat[qsi]; - strat = get_next_indice_fx( st0, 3 ); + strat = get_next_indice_fx( st0, 3 ); /*Q0*/ no_ec = 0; move16(); @@ -3211,7 +3211,7 @@ static void ivas_spar_dec_parse_md_bs_fx( { *bands_bw = add( strat, 1 ); move16(); - *nB = idiv1616( num_bands, *bands_bw ); + *nB = idiv1616( num_bands, *bands_bw ); /*Q0*/ move16(); FOR( i = 0; i < *nB; i++ ) { @@ -3225,7 +3225,7 @@ static void ivas_spar_dec_parse_md_bs_fx( { *bands_bw = sub( strat, 1 ); move16(); - *nB = idiv1616( num_bands, *bands_bw ); + *nB = idiv1616( num_bands, *bands_bw ); /*Q0*/ move16(); FOR( i = 0; i < *nB; i++ ) { @@ -3241,14 +3241,14 @@ static void ivas_spar_dec_parse_md_bs_fx( { *bands_bw = 2; move16(); - *nB = idiv1616( num_bands, *bands_bw ); + *nB = idiv1616( num_bands, *bands_bw ); /*Q0*/ move16(); FOR( i = 0; i < *nB; i++ ) { do_diff[i] = 0; move16(); - do_repeat[i] = extract_l( EQ_16( ( strat % 2 ), ( add( i, 1 ) % 2 ) ) ); + do_repeat[i] = extract_l( EQ_16( ( strat % 2 ), ( add( i, 1 ) % 2 ) ) ); /*Q0*/ move16(); } } @@ -3261,7 +3261,7 @@ static void ivas_spar_dec_parse_md_bs_fx( FOR( i = 0; i < *nB; i++ ) { - do_diff[i] = extract_l( NE_16( s_and( add( i, 1 ), 3 ), sub( strat, 4 ) ) ); + do_diff[i] = extract_l( NE_16( s_and( add( i, 1 ), 3 ), sub( strat, 4 ) ) ); /*Q0*/ move16(); do_repeat[i] = 0; move16(); @@ -3285,9 +3285,9 @@ static void ivas_spar_dec_parse_md_bs_fx( FOR( i = 0; i < *nB; i++ ) { - ndec = hMdDec->spar_md_cfg.num_decorr_per_band[i_mult( ( *bands_bw ), i )]; + ndec = hMdDec->spar_md_cfg.num_decorr_per_band[( ( *bands_bw ) * i )]; /*Q0*/ move16(); - ndm = hMdDec->spar_md_cfg.num_dmx_chans_per_band[i_mult( ( *bands_bw ), i )]; + ndm = hMdDec->spar_md_cfg.num_dmx_chans_per_band[( ( *bands_bw ) * i )]; /*Q0*/ move16(); ivas_deindex_real_index_fx( hMdDec->spar_md.band_coeffs_idx[i].pred_index_re, qs.PR.q_levels[0], qs.PR.min_fx, qs.PR.max_fx, hMdDec->spar_md.band_coeffs[i].pred_re_fx, sub( add( ndm, ndec ), 1 ) ); @@ -3298,7 +3298,7 @@ static void ivas_spar_dec_parse_md_bs_fx( { FOR( jj = 0; jj < sub( ndm, 1 ); jj++ ) { - quant_fx[j] = hMdDec->spar_md.band_coeffs[i].C_re_fx[ii][jj]; + quant_fx[j] = hMdDec->spar_md.band_coeffs[i].C_re_fx[ii][jj]; /*Q22*/ move32(); j = add( j, 1 ); } @@ -3312,7 +3312,7 @@ static void ivas_spar_dec_parse_md_bs_fx( { FOR( jj = 0; jj < sub( ndm, 1 ); jj++ ) { - hMdDec->spar_md.band_coeffs[i].C_re_fx[ii][jj] = quant_fx[j]; + hMdDec->spar_md.band_coeffs[i].C_re_fx[ii][jj] = quant_fx[j]; /*Q22*/ move32(); j = add( j, 1 ); } @@ -3321,19 +3321,19 @@ static void ivas_spar_dec_parse_md_bs_fx( ivas_deindex_real_index_fx( hMdDec->spar_md.band_coeffs_idx[i].decd_index_re, qs.P_r.q_levels[0], qs.P_r.min_fx, qs.P_r.max_fx, hMdDec->spar_md.band_coeffs[i].P_re_fx, sub( add( ndm, ndec ), 1 ) ); /* Store prior coefficient indices */ - FOR( j = 0; j < sub( add( ndm, ndec ), 1 ); j++ ) + FOR( j = 0; j < ( ( ndm + ndec ) - 1 ); j++ ) { - hMdDec->spar_md_prev.band_coeffs_idx[i].pred_index_re[j] = hMdDec->spar_md.band_coeffs_idx[i].pred_index_re[j]; + hMdDec->spar_md_prev.band_coeffs_idx[i].pred_index_re[j] = hMdDec->spar_md.band_coeffs_idx[i].pred_index_re[j]; /*Q0*/ move16(); } - FOR( j = 0; j < i_mult( ndec, sub( ndm, 1 ) ); j++ ) + FOR( j = 0; j < ( ndec * ( ndm - 1 ) ); j++ ) { - hMdDec->spar_md_prev.band_coeffs_idx[i].drct_index_re[j] = hMdDec->spar_md.band_coeffs_idx[i].drct_index_re[j]; + hMdDec->spar_md_prev.band_coeffs_idx[i].drct_index_re[j] = hMdDec->spar_md.band_coeffs_idx[i].drct_index_re[j]; /*Q0*/ move16(); } FOR( j = 0; j < ndec; j++ ) { - hMdDec->spar_md_prev.band_coeffs_idx[i].decd_index_re[j] = hMdDec->spar_md.band_coeffs_idx[i].decd_index_re[j]; + hMdDec->spar_md_prev.band_coeffs_idx[i].decd_index_re[j] = hMdDec->spar_md.band_coeffs_idx[i].decd_index_re[j]; /*Q0*/ move16(); } test(); @@ -3380,13 +3380,13 @@ static void ivas_spar_dec_parse_md_bs_fx( #ifdef IVAS_FLOAT_FIXED static void ivas_decode_arith_bs( ivas_spar_md_dec_state_t *hMdDec, - Decoder_State *st0, /* i/o: decoder state structure - for bitstream handling*/ - const UWord16 qsi, - const Word16 nB, - const Word16 bands_bw, - Word16 *pDo_diff, - const Word16 strat, - const Word32 ivas_total_brate ) + Decoder_State *st0, /* i/o: decoder state structure - for bitstream handling*/ + const UWord16 qsi, /*Q0*/ + const Word16 nB, /*Q0*/ + const Word16 bands_bw, /*Q0*/ + Word16 *pDo_diff, /*Q0*/ + const Word16 strat, /*Q0*/ + const Word32 ivas_total_brate /*Q0*/ ) { Word16 i, ndm, ndec; Word16 j; @@ -3430,7 +3430,7 @@ static void ivas_decode_arith_bs( } ELSE { - pred_cell_dims[i].dim1 = add( ndm, sub( ndec, 1 ) ); + pred_cell_dims[i].dim1 = add( ndm, sub( ndec, 1 ) ); /*Q0*/ move16(); IF( hMdDec->spar_hoa_md_flag && hMdDec->spar_hoa_dirac2spar_md_flag ) { @@ -3480,7 +3480,7 @@ static void ivas_decode_arith_bs( FOR( j = 0; j < pred_cell_dims[i].dim1; j++ ) { hMdDec->spar_md_prev.band_coeffs_idx_mapped[i].pred_index_re[j] = - hMdDec->spar_md_prev.band_coeffs_idx_mapped[i].pred_index_re[j + ( FOA_CHANNELS - 1 )]; + hMdDec->spar_md_prev.band_coeffs_idx_mapped[i].pred_index_re[j + ( FOA_CHANNELS - 1 )]; /*Q0*/ move16(); } } @@ -3504,7 +3504,7 @@ static void ivas_decode_arith_bs( FOR( j = pred_cell_dims[i].dim1 - 1; j >= 0; j-- ) { hMdDec->spar_md.band_coeffs_idx[i].pred_index_re[j + ( FOA_CHANNELS - 1 )] = - hMdDec->spar_md.band_coeffs_idx[i].pred_index_re[j]; + hMdDec->spar_md.band_coeffs_idx[i].pred_index_re[j]; /*Q0*/ move16(); } FOR( j = 0; j < FOA_CHANNELS - 1; j++ ) @@ -3554,8 +3554,8 @@ static void ivas_decode_arith_bs( static void ivas_fill_band_coeffs_idx( ivas_band_coeffs_ind_t *pBands_idx, - const Word16 nB, - Word16 *pSymbol_re, + const Word16 nB, /*Q0*/ + Word16 *pSymbol_re, /*Q0*/ ivas_cell_dim_t *pCell_dims, const ivas_coeffs_type_t coeff_type ) { @@ -3592,8 +3592,8 @@ static void ivas_fill_band_coeffs_idx( IF( NE_16( coeff_type, DECX_COEFF ) ) { - len = imult1616( pCell_dims[i].dim1, pCell_dims[i].dim2 ); - Copy( pSymbol_re, pPtr_idx, len ); + len = imult1616( pCell_dims[i].dim1, pCell_dims[i].dim2 ); /*Q0*/ + Copy( pSymbol_re, pPtr_idx, len ); /*Q0*/ pSymbol_re += len; } } @@ -3611,9 +3611,9 @@ static void ivas_fill_band_coeffs_idx( static void ivas_decode_huffman_bs( ivas_spar_md_dec_state_t *hMdDec, Decoder_State *st0, /* i/o: decoder state structure - for bitstream handling*/ - const UWord16 qsi, - const Word16 nB, - const Word16 bands_bw ) + const UWord16 qsi, /*Q0*/ + const Word16 nB, /*Q0*/ + const Word16 bands_bw /*Q0*/ ) { Word16 i, j; Word16 ndm, ndec; @@ -3621,13 +3621,13 @@ static void ivas_decode_huffman_bs( FOR( i = 0; i < nB; i++ ) { - ndm = hMdDec->spar_md_cfg.num_dmx_chans_per_band[bands_bw * i]; - ndec = hMdDec->spar_md_cfg.num_decorr_per_band[bands_bw * i]; + ndm = hMdDec->spar_md_cfg.num_dmx_chans_per_band[bands_bw * i]; /*Q0*/ + ndec = hMdDec->spar_md_cfg.num_decorr_per_band[bands_bw * i]; /*Q0*/ move16(); move16(); pred_dim = sub( add( ndec, ndm ), 1 ); - drct_dim = imult1616( ndec, sub( ndm, 1 ) ); + drct_dim = imult1616( ndec, sub( ndm, 1 ) ); /*Q0*/ decd_dim = ndec; pred_offset = 0; move16(); @@ -3674,13 +3674,13 @@ static void ivas_decode_huffman_bs( } static void ivas_spar_plc_get_band_age( - const Word16 *valid_bands, - Word16 *base_band_age, - const Word16 num_bands, - Word16 last_valid_band_idx[IVAS_MAX_NUM_BANDS], - Word16 valid_band_idx[IVAS_MAX_NUM_BANDS], - Word16 *all_valid, - Word16 *b_idx ) + const Word16 *valid_bands, /*Q0*/ + Word16 *base_band_age, /*Q0*/ + const Word16 num_bands, /*Q0*/ + Word16 last_valid_band_idx[IVAS_MAX_NUM_BANDS], /*Q0*/ + Word16 valid_band_idx[IVAS_MAX_NUM_BANDS], /*Q0*/ + Word16 *all_valid, /*Q0*/ + Word16 *b_idx /*Q0*/ ) { Word16 b, idx; @@ -3700,7 +3700,7 @@ static void ivas_spar_plc_get_band_age( } ELSE { - base_band_age[b] = add( base_band_age[b], 1 ); /* increment the age of invalid bands */ + 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 ) ) { @@ -3751,17 +3751,17 @@ static void ivas_spar_get_plc_interp_weights( #else static void ivas_spar_get_plc_interp_weights_fx( - Word16 valid_band_idx[IVAS_MAX_NUM_BANDS], - Word16 last_valid_band_idx, - Word16 idx, - Word16 b, - Word16 *w, - Word16 *id0, - Word16 *id1 ) + Word16 valid_band_idx[IVAS_MAX_NUM_BANDS], /*Q0*/ + Word16 last_valid_band_idx, /*Q0*/ + Word16 idx, /*Q0*/ + Word16 b, /*Q0*/ + Word16 *w, /*Q15*/ + Word16 *id0, /*Q0*/ + Word16 *id1 /*Q0*/ ) { IF( last_valid_band_idx < 0 ) /* Extrapolation */ { - *id1 = valid_band_idx[0]; + *id1 = valid_band_idx[0]; /*Q0*/ move16(); *id0 = 0; move16(); @@ -3770,18 +3770,18 @@ static void ivas_spar_get_plc_interp_weights_fx( } ELSE IF( EQ_16( last_valid_band_idx, idx ) ) /* Extrapolation */ { - *id1 = valid_band_idx[last_valid_band_idx]; + *id1 = valid_band_idx[last_valid_band_idx]; /*Q0*/ move16(); - *id0 = valid_band_idx[last_valid_band_idx]; + *id0 = valid_band_idx[last_valid_band_idx]; /*Q0*/ move16(); *w = 0; move16(); } ELSE /* Interpolation */ { - *id0 = valid_band_idx[last_valid_band_idx]; + *id0 = valid_band_idx[last_valid_band_idx]; /*Q0*/ move16(); - *id1 = valid_band_idx[last_valid_band_idx + 1]; + *id1 = valid_band_idx[last_valid_band_idx + 1]; /*Q0*/ move16(); IF( sub( b, *id0 ) == 0 ) { @@ -3790,7 +3790,7 @@ static void ivas_spar_get_plc_interp_weights_fx( } ELSE { - *w = divide3232( sub( b, *id0 ), sub( *id1, *id0 ) ); + *w = divide3232( sub( b, *id0 ), sub( *id1, *id0 ) ); /*Q0*/ move16(); } } @@ -3808,11 +3808,11 @@ static void ivas_spar_get_plc_interp_weights_fx( static void ivas_spar_md_fill_invalid_bands_fx( ivas_spar_dec_matrices_t *pSpar_coeffs, ivas_spar_dec_matrices_t *pSpar_coeffs_prev, - const Word16 *valid_bands, - Word16 *base_band_age, - const Word16 num_bands, - const Word16 num_channels, - const Word16 num_md_sub_frames ) + const Word16 *valid_bands, /*Q0*/ + Word16 *base_band_age, /*Q0*/ + const Word16 num_bands, /*Q0*/ + const Word16 num_channels, /*Q0*/ + const Word16 num_md_sub_frames /*Q0*/ ) { Word16 i, j, b, all_valid; Word16 valid_band_idx[IVAS_MAX_NUM_BANDS], idx = -1; @@ -3839,9 +3839,9 @@ static void ivas_spar_md_fill_invalid_bands_fx( { FOR( j = 0; j < num_channels; j++ ) { - pSpar_coeffs->C_re_fx[i][j][b] = L_add( Mpy_32_16_1( pSpar_coeffs->C_re_fx[i][j][id0], sub( MAX_WORD16, w_fx ) ), Mpy_32_16_1( pSpar_coeffs->C_re_fx[i][j][id1], w_fx ) ); + pSpar_coeffs->C_re_fx[i][j][b] = L_add( Mpy_32_16_1( pSpar_coeffs->C_re_fx[i][j][id0], sub( MAX_WORD16, w_fx ) ), Mpy_32_16_1( pSpar_coeffs->C_re_fx[i][j][id1], w_fx ) ); /*Q22*/ move32(); - pSpar_coeffs->P_re_fx[i][j][b] = L_add( Mpy_32_16_1( pSpar_coeffs->P_re_fx[i][j][id0], sub( MAX_WORD16, w_fx ) ), Mpy_32_16_1( pSpar_coeffs->P_re_fx[i][j][id1], w_fx ) ); + pSpar_coeffs->P_re_fx[i][j][b] = L_add( Mpy_32_16_1( pSpar_coeffs->P_re_fx[i][j][id0], sub( MAX_WORD16, w_fx ) ), Mpy_32_16_1( pSpar_coeffs->P_re_fx[i][j][id1], w_fx ) ); /*Q22*/ move32(); } } @@ -3854,9 +3854,9 @@ static void ivas_spar_md_fill_invalid_bands_fx( { FOR( j = 0; j < num_channels; j++ ) { - pSpar_coeffs->C_re_fx[i][j][b] = pSpar_coeffs_prev->C_re_fx[i][j][b]; + pSpar_coeffs->C_re_fx[i][j][b] = pSpar_coeffs_prev->C_re_fx[i][j][b]; /*Q22*/ move32(); - pSpar_coeffs->P_re_fx[i][j][b] = pSpar_coeffs_prev->P_re_fx[i][j][b]; + pSpar_coeffs->P_re_fx[i][j][b] = pSpar_coeffs_prev->P_re_fx[i][j][b]; /*Q22*/ move32(); } } @@ -3872,9 +3872,9 @@ static void ivas_spar_md_fill_invalid_bands_fx( { FOR( i_ts = 1; i_ts < num_md_sub_frames; i_ts++ ) { - pSpar_coeffs->C_re_fx[i][j][add( b, i_mult( i_ts, IVAS_MAX_NUM_BANDS ) )] = pSpar_coeffs->C_re_fx[i][j][b]; + pSpar_coeffs->C_re_fx[i][j][( b + ( i_ts * IVAS_MAX_NUM_BANDS ) )] = pSpar_coeffs->C_re_fx[i][j][b]; /*Q22*/ move32(); - pSpar_coeffs->P_re_fx[i][j][add( b, i_mult( i_ts, IVAS_MAX_NUM_BANDS ) )] = pSpar_coeffs->P_re_fx[i][j][b]; + pSpar_coeffs->P_re_fx[i][j][( b + ( i_ts * IVAS_MAX_NUM_BANDS ) )] = pSpar_coeffs->P_re_fx[i][j][b]; /*Q22*/ move32(); } } @@ -3969,10 +3969,10 @@ static void ivas_spar_md_fill_invalid_bands( static void ivas_spar_md_fill_invalid_bandcoeffs( ivas_band_coeffs_t *pBand_coeffs, ivas_band_coeffs_t *pBand_coeffs_prev, - const Word16 *valid_bands, - Word16 *base_band_age, - Word16 *first_valid_frame, - const Word16 num_bands ) + const Word16 *valid_bands, /*Q0*/ + Word16 *base_band_age, /*Q0*/ + Word16 *first_valid_frame, /*Q0*/ + const Word16 num_bands /*Q0*/ ) { Word16 j, k, b, all_valid; Word16 valid_band_idx[IVAS_MAX_NUM_BANDS], idx = -1; @@ -4001,7 +4001,7 @@ static void ivas_spar_md_fill_invalid_bandcoeffs( FOR( j = 0; j < IVAS_SPAR_MAX_CH - 1; j++ ) { - pBand_coeffs[b].pred_re_fx[j] = L_add( Mpy_32_16_1( pBand_coeffs[id0].pred_re_fx[j], sub( MAX_WORD16, w_fx ) ), Mpy_32_16_1( pBand_coeffs[id1].pred_re_fx[j], w_fx ) ); + pBand_coeffs[b].pred_re_fx[j] = L_add( Mpy_32_16_1( pBand_coeffs[id0].pred_re_fx[j], sub( MAX_WORD16, w_fx ) ), Mpy_32_16_1( pBand_coeffs[id1].pred_re_fx[j], w_fx ) ); /*Q22*/ move32(); } @@ -4009,14 +4009,14 @@ static void ivas_spar_md_fill_invalid_bandcoeffs( { FOR( k = 0; k < IVAS_SPAR_MAX_DMX_CHS - 1; k++ ) { - pBand_coeffs[b].C_re_fx[j][k] = L_add( Mpy_32_16_1( pBand_coeffs[id0].C_re_fx[j][k], sub( MAX_WORD16, w_fx ) ), Mpy_32_16_1( pBand_coeffs[id1].C_re_fx[j][k], w_fx ) ); + pBand_coeffs[b].C_re_fx[j][k] = L_add( Mpy_32_16_1( pBand_coeffs[id0].C_re_fx[j][k], sub( MAX_WORD16, w_fx ) ), Mpy_32_16_1( pBand_coeffs[id1].C_re_fx[j][k], w_fx ) ); /*Q22*/ move32(); } } FOR( j = 0; j < IVAS_SPAR_MAX_CH - 1; j++ ) { - pBand_coeffs[b].P_re_fx[j] = L_add( Mpy_32_16_1( pBand_coeffs[id0].P_re_fx[j], sub( MAX_WORD16, w_fx ) ), Mpy_32_16_1( pBand_coeffs[id1].P_re_fx[j], w_fx ) ); + pBand_coeffs[b].P_re_fx[j] = L_add( Mpy_32_16_1( pBand_coeffs[id0].P_re_fx[j], sub( MAX_WORD16, w_fx ) ), Mpy_32_16_1( pBand_coeffs[id1].P_re_fx[j], w_fx ) ); /*Q22*/ move32(); } } @@ -4026,7 +4026,7 @@ static void ivas_spar_md_fill_invalid_bandcoeffs( { FOR( j = 0; j < IVAS_SPAR_MAX_CH - 1; j++ ) { - pBand_coeffs[b].pred_re_fx[j] = pBand_coeffs_prev[b].pred_re_fx[j]; + pBand_coeffs[b].pred_re_fx[j] = pBand_coeffs_prev[b].pred_re_fx[j]; /*Q22*/ move32(); } @@ -4034,14 +4034,14 @@ static void ivas_spar_md_fill_invalid_bandcoeffs( { FOR( k = 0; k < IVAS_SPAR_MAX_DMX_CHS - 1; k++ ) { - pBand_coeffs[b].C_re_fx[j][k] = pBand_coeffs_prev[b].C_re_fx[j][k]; + pBand_coeffs[b].C_re_fx[j][k] = pBand_coeffs_prev[b].C_re_fx[j][k]; /*Q22*/ move32(); } } FOR( j = 0; j < IVAS_SPAR_MAX_CH - 1; j++ ) { - pBand_coeffs[b].P_re_fx[j] = pBand_coeffs_prev[b].P_re_fx[j]; + pBand_coeffs[b].P_re_fx[j] = pBand_coeffs_prev[b].P_re_fx[j]; /*Q22*/ move32(); } } @@ -4147,13 +4147,13 @@ static void ivas_spar_md_fill_invalid_bandcoeffs( #ifdef IVAS_FLOAT_FIXED static void ivas_spar_dec_compute_ramp_down_post_matrix_fx( ivas_spar_md_dec_state_t *hMdDec, - const Word16 num_bands_out, - const Word16 bfi, - const Word16 num_md_sub_frames ) + const Word16 num_bands_out, /*Q0*/ + const Word16 bfi, /*Q0*/ + const Word16 num_md_sub_frames /*Q0*/ ) { Word16 num_in_ch, num_out_ch, i, j, b; - num_in_ch = hMdDec->spar_md_cfg.num_umx_chs; - num_out_ch = hMdDec->spar_md_cfg.num_umx_chs; + num_in_ch = hMdDec->spar_md_cfg.num_umx_chs; /*Q0*/ + num_out_ch = hMdDec->spar_md_cfg.num_umx_chs; /*Q0*/ move16(); move16(); IF( bfi == 0 ) @@ -4170,7 +4170,7 @@ static void ivas_spar_dec_compute_ramp_down_post_matrix_fx( hMdDec->spar_plc_num_lost_frames = add( hMdDec->spar_plc_num_lost_frames, 1 ); move16(); - hMdDec->spar_plc_num_lost_frames = s_min( hMdDec->spar_plc_num_lost_frames, 100 ); /*hMdDec->spar_plc_num_lost_frames is always <=100*/ + hMdDec->spar_plc_num_lost_frames = s_min( hMdDec->spar_plc_num_lost_frames, 100 ); /*hMdDec->spar_plc_num_lost_frames is always <=100*/ /*Q0*/ move16(); IF( GT_16( hMdDec->spar_plc_num_lost_frames, ivas_spar_dec_plc_num_frames_keep ) ) /*if control enters then ivas_spar_dec_plc_num_frames_keep<100 */ @@ -4186,8 +4186,8 @@ static void ivas_spar_dec_compute_ramp_down_post_matrix_fx( norm_nff = norm_s( num_fade_frames ); gain_dB = negate( imult1616( s_min( num_fade_frames, ivas_spar_dec_plc_max_num_frames_ramp_down ), ivas_spar_dec_plc_per_frame_ramp_down_gain_dB ) ); /*abs(gain_dB)<99*/ /*Q(gain_dB)=7Q24*/ Word16 exp_gain = 0; - move16(); /*stores exponent for gain_fx*/ - gain_fx = BASOP_util_Pow2( Mult_32_16( imult3216( 13421773 /*=2^28/20*/, gain_dB ), 27213 /*=log2(10)*2^13*/ ), 5, &exp_gain ); + move16(); /*stores exponent for gain_fx*/ + gain_fx = BASOP_util_Pow2( Mult_32_16( imult3216( 13421773 /*=2^28/20*/, gain_dB ), 27213 /*=log2(10)*2^13*/ ), 5, &exp_gain ); /*Q_gain*/ Q_gain = sub( 31, exp_gain ); FOR( i = 0; i < IVAS_SPAR_MAX_CH; i++ ) { @@ -4208,7 +4208,7 @@ static void ivas_spar_dec_compute_ramp_down_post_matrix_fx( { FOR( b = 0; b < num_bands_out; b++ ) { - hMdDec->mixer_mat_fx[i][j][add( b, i_mult( i_ts, IVAS_MAX_NUM_BANDS ) )] = L_shl( Mult_32_32( hMdDec->mixer_mat_fx[i][j][add( b, i_mult( i_ts, IVAS_MAX_NUM_BANDS ) )], post_matrix_fx[i] ), sub( Q30, hMdDec->Q_mixer_mat ) ); // Q30 + hMdDec->mixer_mat_fx[i][j][( b + ( i_ts * IVAS_MAX_NUM_BANDS ) )] = L_shl( Mult_32_32( hMdDec->mixer_mat_fx[i][j][( b + ( i_ts * IVAS_MAX_NUM_BANDS ) )], post_matrix_fx[i] ), sub( Q30, hMdDec->Q_mixer_mat ) ); // Q30 move32(); } } @@ -4294,9 +4294,9 @@ static void ivas_spar_dec_compute_ramp_down_post_matrix( #ifdef IVAS_FLOAT_FIXED static void ivas_spar_unquant_dtx_indicies( ivas_spar_md_t *pSpar_md, - const Word16 nB, - const Word16 bw, - Word16 *ndm_per_band ) + const Word16 nB, /*Q0*/ + const Word16 bw, /*Q0*/ + Word16 *ndm_per_band /*Q0*/ ) { Word16 i, b; Word16 q_lvl; @@ -4304,34 +4304,34 @@ static void ivas_spar_unquant_dtx_indicies( Word16 idx; Word32 pr_min_max_fx[2]; - pr_min_max_fx[0] = pSpar_md->min_max_fx[0]; + pr_min_max_fx[0] = pSpar_md->min_max_fx[0]; /*Q28*/ move32(); - pr_min_max_fx[1] = pSpar_md->min_max_fx[1]; + pr_min_max_fx[1] = pSpar_md->min_max_fx[1]; /*Q28*/ move32(); FOR( b = 0; b < nB; b++ ) { FOR( i = 0; i < FOA_CHANNELS - 1; i++ ) { - q_lvl = dtx_pr_real_q_levels[sub( ndm_per_band[i_mult( bw, b )], 1 )][i]; + q_lvl = dtx_pr_real_q_levels[( ndm_per_band[( bw * b )] - 1 )][i]; /*Q0*/ move16(); - idx = pSpar_md->band_coeffs_idx[b].pred_index_re[i]; + idx = pSpar_md->band_coeffs_idx[b].pred_index_re[i]; /*Q0*/ move16(); ivas_deindex_real_index_fx( &idx, q_lvl, pr_min_max_fx[0], pr_min_max_fx[1], &val_fx, 1 ); - pSpar_md->band_coeffs[b].pred_re_fx[i] = val_fx; + pSpar_md->band_coeffs[b].pred_re_fx[i] = val_fx; /*Q22*/ move32(); } - FOR( i = 0; i < sub( FOA_CHANNELS, ndm_per_band[i_mult( bw, b )] ); i++ ) + FOR( i = 0; i < ( FOA_CHANNELS - ndm_per_band[( bw - b )] ); i++ ) { - q_lvl = dtx_pd_real_q_levels[sub( ndm_per_band[i_mult( bw, b )], 1 )][i]; + q_lvl = dtx_pd_real_q_levels[( ndm_per_band[( bw * b )] - 1 )][i]; /*Q0*/ move16(); - idx = pSpar_md->band_coeffs_idx[b].decd_index_re[i]; + idx = pSpar_md->band_coeffs_idx[b].decd_index_re[i]; /*Q0*/ move16(); ivas_deindex_real_index_fx( &idx, q_lvl, dtx_pd_real_min_max_fx[0], dtx_pd_real_min_max_fx[1], &val_fx, 1 ); - pSpar_md->band_coeffs[b].P_re_fx[i] = val_fx; + pSpar_md->band_coeffs[b].P_re_fx[i] = val_fx; /*Q22*/ move32(); } } @@ -4385,11 +4385,11 @@ static void ivas_spar_unquant_dtx_indicies( #ifdef IVAS_FLOAT_FIXED static void ivas_parse_parameter_bitstream_dtx( ivas_spar_md_t *pSpar_md, - Decoder_State *st0, /* i/o: decoder state structure - for bitstream handling*/ - const Word16 bw, - const Word16 num_bands, - Word16 *num_dmx_per_band, - Word16 *num_dec_per_band ) + Decoder_State *st0, /* i/o: decoder state structure - for bitstream handling*/ + const Word16 bw, /*Q0*/ + const Word16 num_bands, /*Q0*/ + Word16 *num_dmx_per_band, /*Q0*/ + Word16 *num_dec_per_band /*Q0*/ ) { Word16 i, j, ndec, ndm; Word32 val_fx; @@ -4398,18 +4398,18 @@ static void ivas_parse_parameter_bitstream_dtx( Word16 pr_q_lvls, pr, pd, pd_q_lvls, pr_pd_bits; Word16 zero_pad_bits, sid_bits_len; - sid_bits_len = st0->next_bit_pos; + sid_bits_len = st0->next_bit_pos; /*Q0*/ move16(); - pr_min_max_fx[0] = pSpar_md->min_max_fx[0]; + pr_min_max_fx[0] = pSpar_md->min_max_fx[0]; /*Q28*/ move32(); - pr_min_max_fx[1] = pSpar_md->min_max_fx[1]; + pr_min_max_fx[1] = pSpar_md->min_max_fx[1]; /*Q28*/ move32(); FOR( i = 0; i < num_bands; i++ ) { - ndec = num_dec_per_band[i_mult( bw, i )]; + ndec = num_dec_per_band[( bw * i )]; move16(); - ndm = num_dmx_per_band[i_mult( bw, i )]; + ndm = num_dmx_per_band[( bw * i )]; move16(); FOR( j = 0; j < FOA_CHANNELS - 1; j++ ) @@ -4417,13 +4417,13 @@ static void ivas_parse_parameter_bitstream_dtx( Word16 pr_idx_1, pr_idx_2, pd_idx_1, pd_idx_2; UWord16 value; - pr_idx_1 = pr_pr_idx_pairs[ndm - 1][j][0]; + pr_idx_1 = pr_pr_idx_pairs[ndm - 1][j][0]; /*Q0*/ move16(); - pr_idx_2 = pr_pr_idx_pairs[ndm - 1][j][1]; + pr_idx_2 = pr_pr_idx_pairs[ndm - 1][j][1]; /*Q0*/ move16(); - pd_idx_1 = pr_pd_idx_pairs[ndm - 1][j][0]; + pd_idx_1 = pr_pd_idx_pairs[ndm - 1][j][0]; /*Q0*/ move16(); - pd_idx_2 = pr_pd_idx_pairs[ndm - 1][j][1]; + pd_idx_2 = pr_pd_idx_pairs[ndm - 1][j][1]; /*Q0*/ move16(); test(); @@ -4431,7 +4431,7 @@ static void ivas_parse_parameter_bitstream_dtx( test(); IF( pr_idx_1 != 0 || pd_idx_1 != 0 || pr_idx_2 != 0 || pd_idx_2 != 0 ) { - pr_q_lvls = dtx_pr_real_q_levels[ndm - 1][pd_idx_1 - 1]; + pr_q_lvls = dtx_pr_real_q_levels[ndm - 1][pd_idx_1 - 1]; /*Q0*/ move16(); IF( GT_16( add( j, 1 ), ndec ) ) @@ -4441,17 +4441,17 @@ static void ivas_parse_parameter_bitstream_dtx( } ELSE { - pd_q_lvls = dtx_pd_real_q_levels[ndm - 1][pd_idx_2 - 1]; + pd_q_lvls = dtx_pd_real_q_levels[ndm - 1][pd_idx_2 - 1]; /*Q0*/ move16(); } - pr_pd_bits = ivas_get_bits_to_encode( L_mult0( pd_q_lvls, pr_q_lvls ) ); + pr_pd_bits = ivas_get_bits_to_encode( L_mult0( pd_q_lvls, pr_q_lvls ) ); /*Q0*/ - value = get_next_indice_fx( st0, pr_pd_bits ); + value = get_next_indice_fx( st0, pr_pd_bits ); /*Q0*/ IF( value != 0 ) { - pr = idiv1616( value, pd_q_lvls ); + pr = idiv1616( value, pd_q_lvls ); /*Q0*/ } ELSE { @@ -4459,23 +4459,23 @@ static void ivas_parse_parameter_bitstream_dtx( move16(); } pd = extract_l( L_sub( value, i_mult( pr, pd_q_lvls ) ) ); - val_fx = dtx_pd_real_min_max_fx[0]; + val_fx = dtx_pd_real_min_max_fx[0]; /*Q0*/ move32(); ivas_quantise_real_values_fx( &val_fx, pd_q_lvls, dtx_pd_real_min_max_fx[0], dtx_pd_real_min_max_fx[1], &idx, &val_fx, 1 ); pd = add( pd, idx ); - val_fx = pr_min_max_fx[0]; + val_fx = pr_min_max_fx[0]; /*Q28*/ move32(); ivas_quantise_real_values_fx( &val_fx, pr_q_lvls, pr_min_max_fx[0], pr_min_max_fx[1], &idx, &val_fx, 1 ); pr = add( pr, idx ); if ( LE_16( add( j, 1 ), ndec ) ) { - pSpar_md->band_coeffs_idx[i].decd_index_re[pd_idx_2 - 1] = pd; + pSpar_md->band_coeffs_idx[i].decd_index_re[pd_idx_2 - 1] = pd; /*Q0*/ move16(); } - pSpar_md->band_coeffs_idx[i].pred_index_re[pd_idx_1 - 1] = pr; + pSpar_md->band_coeffs_idx[i].pred_index_re[pd_idx_1 - 1] = pr; /*Q0*/ move16(); } } @@ -4633,12 +4633,12 @@ static ivas_error ivas_deindex_real_index( #else static ivas_error ivas_deindex_real_index_fx( - const Word16 *index, - const Word16 q_levels, - const Word32 min_value, - const Word32 max_value, - Word32 *quant, - const Word16 dim ) + const Word16 *index, /*Q0*/ + const Word16 q_levels, /*Q0*/ + const Word32 min_value, /*Q28*/ + const Word32 max_value, /*Q28*/ + Word32 *quant, /*Q22*/ + const Word16 dim /*Q0*/ ) { Word16 i; Word32 q_step_fx; @@ -4658,7 +4658,7 @@ static ivas_error ivas_deindex_real_index_fx( ELSE { q_step_fx = L_sub( max_value, min_value ); - q_step_fx = Mpy_32_32( q_step_fx, one_by_q_level[q_levels - 1] ); + q_step_fx = Mpy_32_32( q_step_fx, one_by_q_level[q_levels - 1] /*Q31*/ ); /*Q28*/ FOR( i = 0; i < dim; i++ ) { quant[i] = Mpy_32_32( L_shl( index[i], 31 - 6 ), q_step_fx ); //(25+28)-31 = 22 @@ -4949,10 +4949,10 @@ void ivas_spar_to_dirac( #else void ivas_spar_to_dirac_fx( Decoder_Struct *st_ivas, - ivas_spar_md_dec_state_t *hMdDec, /* i/o: SPAR MD decoder handle */ - const Word16 dtx_vad, /* i : DTX frame flag */ - const Word16 num_bands_out, /* i : number of output bands */ - const Word16 bw, /* i : band joining factor */ + ivas_spar_md_dec_state_t *hMdDec, /* i/o: SPAR MD decoder handle Q0*/ + const Word16 dtx_vad, /* i : DTX frame flag Q0*/ + const Word16 num_bands_out, /* i : number of output bands Q0*/ + const Word16 bw, /* i : band joining factor Q0*/ const Word16 dyn_active_w_flag ) { DIRAC_DEC_HANDLE hDirAC; @@ -4994,17 +4994,17 @@ void ivas_spar_to_dirac_fx( move16(); start_band = 0; move16(); - end_band = idiv1616( s_min( num_bands_out, SPAR_DIRAC_SPLIT_START_BAND ), bw ); + end_band = idiv1616( s_min( num_bands_out, SPAR_DIRAC_SPLIT_START_BAND ), bw ); /*Q0*/ hDirAC = st_ivas->hDirAC; hSpatParamRendCom = st_ivas->hSpatParamRendCom; - dirac_to_spar_md_bands = st_ivas->hSpar->dirac_to_spar_md_bands; + dirac_to_spar_md_bands = st_ivas->hSpar->dirac_to_spar_md_bands; /*Q0*/ move16(); IF( st_ivas->hSpar->enc_param_start_band > 0 ) { - enc_param_start_band = idiv1616( st_ivas->hSpar->enc_param_start_band, bw ); + enc_param_start_band = idiv1616( st_ivas->hSpar->enc_param_start_band, bw ); /*Q0*/ } ELSE { @@ -5044,13 +5044,13 @@ void ivas_spar_to_dirac_fx( Word32 PR_fx[3], Pd_fx[3], dvnorm_fx, g_pred_fx; Word16 q_g_pred; Word16 q_dvnorm; - PR_fx[0] = hMdDec->spar_md.band_coeffs[band].pred_re_fx[2]; + PR_fx[0] = hMdDec->spar_md.band_coeffs[band].pred_re_fx[2]; /*Q22*/ move32(); - PR_fx[1] = hMdDec->spar_md.band_coeffs[band].pred_re_fx[0]; + PR_fx[1] = hMdDec->spar_md.band_coeffs[band].pred_re_fx[0]; /*Q22*/ move32(); - PR_fx[2] = hMdDec->spar_md.band_coeffs[band].pred_re_fx[1]; + PR_fx[2] = hMdDec->spar_md.band_coeffs[band].pred_re_fx[1]; /*Q22*/ move32(); - g_pred_fx = L_add( L_add( Mpy_32_32( PR_fx[0], PR_fx[0] ), Mpy_32_32( PR_fx[1], PR_fx[1] ) ), Mpy_32_32( PR_fx[2], PR_fx[2] ) ); + g_pred_fx = L_add( L_add( Mpy_32_32( PR_fx[0], PR_fx[0] ), Mpy_32_32( PR_fx[1], PR_fx[1] ) ), Mpy_32_32( PR_fx[2], PR_fx[2] ) ); /*q_g_pred*/ q_g_pred = Q22 + Q22 - Q31; move16(); q_dvnorm = sub( Q31, q_g_pred ); @@ -5058,7 +5058,7 @@ void ivas_spar_to_dirac_fx( move16(); IF( LE_32( g_pred_fx, EPSILON_FIX ) ) { - dvx_fx[band] = ONE_IN_Q22; + dvx_fx[band] = ONE_IN_Q22; /*Q22*/ move32(); dvy_fx[band] = 0; move32(); @@ -5076,8 +5076,8 @@ void ivas_spar_to_dirac_fx( } ELSE { - dvnorm_fx = ISqrt32( g_pred_fx, &q_dvnorm ); - g_pred_fx = Sqrt32( g_pred_fx, &q_g_pred ); + dvnorm_fx = ISqrt32( g_pred_fx, &q_dvnorm ); /*Q31 - q_dvnorm*/ + g_pred_fx = Sqrt32( g_pred_fx, &q_g_pred ); /*Q31 - q_g_pred*/ IF( q_g_pred < 0 ) { g_pred_fx = L_shr( g_pred_fx, negate( q_g_pred ) ); @@ -5085,70 +5085,70 @@ void ivas_spar_to_dirac_fx( move16(); } - dvx_fx[band] = Mpy_32_32( PR_fx[0], dvnorm_fx ); + dvx_fx[band] = Mpy_32_32( PR_fx[0], dvnorm_fx ); /*q_1*/ move32(); - dvy_fx[band] = Mpy_32_32( PR_fx[1], dvnorm_fx ); + dvy_fx[band] = Mpy_32_32( PR_fx[1], dvnorm_fx ); /*q_1*/ move32(); - dvz_fx[band] = Mpy_32_32( PR_fx[2], dvnorm_fx ); + dvz_fx[band] = Mpy_32_32( PR_fx[2], dvnorm_fx ); /*q_1*/ move32(); Word16 q_1 = sub( add( 22, sub( 31, q_dvnorm ) ), 31 ); - Word32 temp = L_add( Mpy_32_32( dvx_fx[band], dvx_fx[band] ), Mpy_32_32( dvy_fx[band], dvy_fx[band] ) ); + Word32 temp = L_add( Mpy_32_32( dvx_fx[band], dvx_fx[band] ), Mpy_32_32( dvy_fx[band], dvy_fx[band] ) ); /*q2*/ Word16 q2 = sub( add( q_1, q_1 ), 31 ); Word16 q_temp = sub( 31, q2 ); radius_fx = Sqrt32( temp, &q_temp ); - Word16 check_azi_fx = BASOP_util_atan2( dvy_fx[band], dvx_fx[band], 0 ); - Word32 check_azi_fx_32 = L_shl( check_azi_fx, 16 ); + Word16 check_azi_fx = BASOP_util_atan2( dvy_fx[band], dvx_fx[band], 0 ); /*Q13*/ + Word32 check_azi_fx_32 = L_shl( check_azi_fx, 16 ); /*Q29*/ Word16 check_azi_fx_res; IF( check_azi_fx_32 < 0 ) { - check_azi_fx_res = negate( divide3232( L_negate( check_azi_fx_32 ), 1686629760 ) ); + check_azi_fx_res = negate( divide3232( L_negate( check_azi_fx_32 ), 1686629760 /*3.145f in Q29*/ ) ); /*Q15*/ } ELSE { - check_azi_fx_res = divide3232( check_azi_fx_32, 1686629760 ); + check_azi_fx_res = divide3232( check_azi_fx_32, 1686629760 /*3.145f in Q29*/ ); /*Q15*/ } - Word32 azi_intermediate = Mpy_32_16_1( DEGREE_180_Q_22, check_azi_fx_res ); - azi_intermediate = L_add( azi_intermediate, ONE_IN_Q21 ); + Word32 azi_intermediate = Mpy_32_16_1( DEGREE_180_Q_22, check_azi_fx_res ); /*Q22*/ + azi_intermediate = L_add( azi_intermediate, ONE_IN_Q21 ); /*Q22*/ Word16 azi_res; IF( azi_intermediate < 0 ) { - azi_res = negate( extract_l( L_shr( L_negate( azi_intermediate ), 22 ) ) ); + azi_res = negate( extract_l( L_shr( L_negate( azi_intermediate ), 22 ) ) ); /*Q0*/ } ELSE { - azi_res = extract_l( L_shr( azi_intermediate, 22 ) ); + azi_res = extract_l( L_shr( azi_intermediate, 22 ) ); /*Q0*/ } - Word16 check_ele_fx = BASOP_util_atan2( dvz_fx[band], radius_fx, sub( add( 9, q_dvnorm ), q_temp ) ); - Word32 check_ele_fx_32 = L_shl( check_ele_fx, 16 ); + Word16 check_ele_fx = BASOP_util_atan2( dvz_fx[band], radius_fx, sub( add( 9, q_dvnorm ), q_temp ) ); /*Q13*/ + Word32 check_ele_fx_32 = L_shl( check_ele_fx, 16 ); /*Q29*/ Word16 check_ele_fx_res; IF( check_azi_fx_32 < 0 ) { - check_ele_fx_res = negate( divide3232( L_negate( check_ele_fx_32 ), 1686629760 ) ); + check_ele_fx_res = negate( divide3232( L_negate( check_ele_fx_32 ), 1686629760 /*3.145f in Q29*/ ) ); /*Q15*/ } ELSE { - check_ele_fx_res = divide3232( check_ele_fx_32, 1686629760 ); + check_ele_fx_res = divide3232( check_ele_fx_32, 1686629760 /*3.145f in Q29*/ ); /*Q15*/ } - Word32 ele_intermediate = Mpy_32_16_1( DEGREE_180_Q_22, check_ele_fx_res ); - ele_intermediate = L_add( ele_intermediate, ONE_IN_Q21 ); + Word32 ele_intermediate = Mpy_32_16_1( DEGREE_180_Q_22, check_ele_fx_res ); /*Q22*/ + ele_intermediate = L_add( ele_intermediate, ONE_IN_Q21 ); /*Q22*/ Word16 ele_res; IF( ele_intermediate < 0 ) { - ele_res = negate( extract_l( L_shr( L_negate( ele_intermediate ), 22 ) ) ); + ele_res = negate( extract_l( L_shr( L_negate( ele_intermediate ), 22 ) ) ); /*Q0*/ } ELSE { - ele_res = extract_l( L_shr( ele_intermediate, 22 ) ); + ele_res = extract_l( L_shr( ele_intermediate, 22 ) ); /*Q0*/ } - azi[band] = s_max( -180, s_min( 180, azi_res ) ); + azi[band] = s_max( -180, s_min( 180, azi_res ) ); /*Q0*/ move16(); - ele[band] = s_max( -90, s_min( 180, ele_res ) ); + ele[band] = s_max( -90, s_min( 180, ele_res ) ); /*Q0*/ move16(); } @@ -5160,19 +5160,19 @@ void ivas_spar_to_dirac_fx( { IF( dtx_vad == 0 ) { - f_scale_fx = IVAS_ACTIVEW_DM_F_SCALE_DTX_FX; + f_scale_fx = IVAS_ACTIVEW_DM_F_SCALE_DTX_FX; /*Q31*/ move32(); } ELSE { IF( active_w_vlbr ) { - f_scale_fx = IVAS_ACTIVEW_DM_F_SCALE_VLBR_FX; + f_scale_fx = IVAS_ACTIVEW_DM_F_SCALE_VLBR_FX; /*Q31*/ move32(); } ELSE { - f_scale_fx = IVAS_ACTIVEW_DM_F_SCALE_FX; + f_scale_fx = IVAS_ACTIVEW_DM_F_SCALE_FX; /*Q31*/ move32(); } } @@ -5183,42 +5183,42 @@ void ivas_spar_to_dirac_fx( move32(); } - Word32 temp_result = Mpy_32_32( Mpy_32_32( f_scale_fx, g_pred_fx ), g_pred_fx ); + Word32 temp_result = Mpy_32_32( Mpy_32_32( f_scale_fx, g_pred_fx ), g_pred_fx ); /*Q31 - q_g_pred*/ temp_result = L_sub( L_shr( ONE_IN_Q31, q_g_pred ), temp_result ); - w_en_norm_fx = Mpy_32_32( temp_result, temp_result ); + w_en_norm_fx = Mpy_32_32( temp_result, temp_result ); /*q_w_en_norm_fx*/ q_w_en_norm_fx = add( q_g_pred, q_g_pred ); - Pd_fx[0] = hMdDec->spar_md.band_coeffs[band].P_re_fx[1]; + Pd_fx[0] = hMdDec->spar_md.band_coeffs[band].P_re_fx[1]; /*Q22*/ move32(); - Pd_fx[1] = hMdDec->spar_md.band_coeffs[band].P_re_fx[0]; + Pd_fx[1] = hMdDec->spar_md.band_coeffs[band].P_re_fx[0]; /*Q22*/ move32(); - Pd_fx[2] = hMdDec->spar_md.band_coeffs[band].P_re_fx[2]; + Pd_fx[2] = hMdDec->spar_md.band_coeffs[band].P_re_fx[2]; /*Q22*/ move32(); en_ratio_fx = L_add( L_add( Mpy_32_32( PR_fx[0], PR_fx[0] ), Mpy_32_32( PR_fx[1], PR_fx[1] ) ), Mpy_32_32( PR_fx[2], PR_fx[2] ) ); // 22+22-31 = 13 Word32 Pd_temp_res = L_add( L_add( Mpy_32_32( Pd_fx[0], Pd_fx[0] ), Mpy_32_32( Pd_fx[1], Pd_fx[1] ) ), Mpy_32_32( Pd_fx[2], Pd_fx[2] ) ); // q = 22+22-31 = 13 - res_pow_fx = L_add( L_shr( w_en_norm_fx, sub( sub( 31, q_w_en_norm_fx ), 13 ) ), L_add( en_ratio_fx, Pd_temp_res ) ); + res_pow_fx = L_add( L_shr( w_en_norm_fx, sub( sub( 31, q_w_en_norm_fx ), 13 ) ), L_add( en_ratio_fx, Pd_temp_res ) ); /*Q13*/ - res_pow_fx = L_shr( res_pow_fx, 1 ); + res_pow_fx = L_shr( res_pow_fx, 1 ); /*Q13*/ - hMdDec->spar_md.en_ratio_slow_fx[band] = L_add( Mpy_32_32( 1610612736, hMdDec->spar_md.en_ratio_slow_fx[band] ), Mpy_32_32( 536870912, en_ratio_fx ) ); + hMdDec->spar_md.en_ratio_slow_fx[band] = L_add( Mpy_32_32( 1610612736 /*0.75f in Q31*/, hMdDec->spar_md.en_ratio_slow_fx[band] ), Mpy_32_32( 536870912 /*0.25f in Q31*/, en_ratio_fx ) ); /*Q13*/ move32(); - hMdDec->spar_md.ref_pow_slow_fx[band] = L_add( Mpy_32_32( 1610612736, hMdDec->spar_md.ref_pow_slow_fx[band] ), Mpy_32_32( 536870912, res_pow_fx ) ); + hMdDec->spar_md.ref_pow_slow_fx[band] = L_add( Mpy_32_32( 1610612736 /*0.75f in Q31*/, hMdDec->spar_md.ref_pow_slow_fx[band] ), Mpy_32_32( 536870912 /*0.25f in Q31*/, res_pow_fx ) ); /*Q13*/ move32(); en_ratio_q = 31 - 13; move16(); - en_ratio_fx = Sqrt32( hMdDec->spar_md.en_ratio_slow_fx[band], &en_ratio_q ); + en_ratio_fx = Sqrt32( hMdDec->spar_md.en_ratio_slow_fx[band], &en_ratio_q ); /*Q31 - en_ratio_q*/ IF( en_ratio_q < 0 ) { - en_ratio_fx = L_shr( en_ratio_fx, negate( en_ratio_q ) ); + en_ratio_fx = L_shr( en_ratio_fx, negate( en_ratio_q ) ); /*Q31*/ en_ratio_q = 0; move16(); } - Word32 en_ratio_fx_scaled = L_shr( en_ratio_fx, ( sub( sub( 31, en_ratio_q ), 13 ) ) ); + Word32 en_ratio_fx_scaled = L_shr( en_ratio_fx, ( sub( sub( 31, en_ratio_q ), 13 ) ) ); /*Q13*/ IF( GT_32( en_ratio_fx_scaled, hMdDec->spar_md.ref_pow_slow_fx[band] ) ) { diffuseness_fx[band] = 0; @@ -5226,39 +5226,39 @@ void ivas_spar_to_dirac_fx( } ELSE IF( en_ratio_fx_scaled == 0 ) { - diffuseness_fx[band] = ONE_IN_Q30; + diffuseness_fx[band] = ONE_IN_Q30; /*1.0f in Q30*/ move32(); } ELSE IF( EQ_32( en_ratio_fx_scaled, hMdDec->spar_md.ref_pow_slow_fx[band] ) ) { - diffuseness_fx[band] = ONE_IN_Q30; + diffuseness_fx[band] = ONE_IN_Q30; /*1.0f in Q30*/ move32(); } ELSE { - en_ratio_fx = divide3232( en_ratio_fx_scaled, L_add( hMdDec->spar_md.ref_pow_slow_fx[band], EPSILON_FX ) ); - en_ratio_fx = L_shl( en_ratio_fx, 15 ); + en_ratio_fx = divide3232( en_ratio_fx_scaled, L_add( hMdDec->spar_md.ref_pow_slow_fx[band], EPSILON_FX ) ); /*Q15*/ + en_ratio_fx = L_shl( en_ratio_fx, 15 ); /*Q30*/ diffuseness_fx[band] = L_sub( ONE_IN_Q30, en_ratio_fx ); move32(); } } ELSE { - en_ratio_fx = L_add( L_add( Mpy_32_32( PR_fx[0], PR_fx[0] ), Mpy_32_32( PR_fx[1], PR_fx[1] ) ), Mpy_32_32( PR_fx[2], PR_fx[2] ) ); + en_ratio_fx = L_add( L_add( Mpy_32_32( PR_fx[0], PR_fx[0] ), Mpy_32_32( PR_fx[1], PR_fx[1] ) ), Mpy_32_32( PR_fx[2], PR_fx[2] ) ); /*Q13*/ - hMdDec->spar_md.en_ratio_slow_fx[band] = L_add( Mpy_32_32( 1610612736, hMdDec->spar_md.en_ratio_slow_fx[band] ), Mpy_32_32( 536870912, en_ratio_fx ) ); + hMdDec->spar_md.en_ratio_slow_fx[band] = L_add( Mpy_32_32( 1610612736 /*0.75f in Q31*/, hMdDec->spar_md.en_ratio_slow_fx[band] ), Mpy_32_32( 536870912 /*0.25f in Q31*/, en_ratio_fx ) ); move32(); en_ratio_q = 31 - 13; move16(); - en_ratio_fx = Sqrt32( hMdDec->spar_md.en_ratio_slow_fx[band], &en_ratio_q ); + en_ratio_fx = Sqrt32( hMdDec->spar_md.en_ratio_slow_fx[band], &en_ratio_q ); /*Q31 - en_ratio_q*/ IF( en_ratio_q < 0 ) { - en_ratio_fx = L_shr( en_ratio_fx, ( -en_ratio_q ) ); + en_ratio_fx = L_shr( en_ratio_fx, ( -en_ratio_q ) ); /*Q31*/ en_ratio_q = 0; move16(); } - Word32 en_ratio_fx_scaled = L_shr( en_ratio_fx, 1 ); + Word32 en_ratio_fx_scaled = L_shr( en_ratio_fx, 1 ); /*Q30*/ IF( GT_32( en_ratio_fx_scaled, ONE_IN_Q30 ) ) { diffuseness_fx[band] = 0; @@ -5266,7 +5266,7 @@ void ivas_spar_to_dirac_fx( } ELSE { - diffuseness_fx[band] = L_sub( ONE_IN_Q30, en_ratio_fx_scaled ); + diffuseness_fx[band] = L_sub( ONE_IN_Q30, en_ratio_fx_scaled ); /*Q30*/ move32(); } } @@ -5278,60 +5278,60 @@ void ivas_spar_to_dirac_fx( tmp_write_idx_param_band = hDirAC->spar_to_dirac_write_idx; move16(); - en_ratio_fx = L_sub( ONE_IN_Q30, diffuseness_fx[band] ); + en_ratio_fx = L_sub( ONE_IN_Q30, diffuseness_fx[band] ); /*Q30*/ masa_sq_fx( L_sub( ONE_IN_Q30, en_ratio_fx ), diffuseness_thresholds_fx, DIRAC_DIFFUSE_LEVELS ); - qmf_band_start = band_grouping[band]; + qmf_band_start = band_grouping[band]; /*Q0*/ move16(); - qmf_band_end = band_grouping[band + 1]; + qmf_band_end = band_grouping[band + 1]; /*Q0*/ move16(); FOR( block = 0; block < MAX_PARAM_SPATIAL_SUBFRAMES; block++ ) { Word16 ts_start, ts_end, ts; - ts_start = DirAC_block_grouping[block]; + ts_start = DirAC_block_grouping[block]; /*Q0*/ move16(); ts_end = DirAC_block_grouping[block + 1]; move16(); - FOR( b = qmf_band_start; b < qmf_band_end; b++ ) + FOR( b = qmf_band_start; b < qmf_band_end; b++ ) /*Q0*/ { - azi_dith = azi[band]; + azi_dith = azi[band]; /*Q0*/ move16(); - ele_dith = ele[band]; + ele_dith = ele[band]; /*Q0*/ move16(); - hSpatParamRendCom->energy_ratio1_fx[block][b] = en_ratio_fx; + hSpatParamRendCom->energy_ratio1_fx[block][b] = en_ratio_fx; /*Q30*/ move32(); - tmp_write_idx_band = tmp_write_idx_param_band; + tmp_write_idx_band = tmp_write_idx_param_band; /*Q0*/ move16(); IF( hDirAC->hConfig->dec_param_estim == FALSE ) { - hSpatParamRendCom->elevation[tmp_write_idx_band][b] = ele_dith; + hSpatParamRendCom->elevation[tmp_write_idx_band][b] = ele_dith; /*Q0*/ move16(); - hSpatParamRendCom->azimuth[tmp_write_idx_band][b] = azi_dith; + hSpatParamRendCom->azimuth[tmp_write_idx_band][b] = azi_dith; /*Q0*/ move16(); - hSpatParamRendCom->diffuseness_vector_fx[tmp_write_idx_band][b] = diffuseness_fx[band]; + hSpatParamRendCom->diffuseness_vector_fx[tmp_write_idx_band][b] = diffuseness_fx[band]; /*Q30*/ move32(); } ELSE { FOR( ts = ts_start; ts < ts_end; ts++ ) { - hSpatParamRendCom->elevation[tmp_write_idx_band][b] = ele_dith; + hSpatParamRendCom->elevation[tmp_write_idx_band][b] = ele_dith; /*Q0*/ move16(); - hSpatParamRendCom->azimuth[tmp_write_idx_band][b] = azi_dith; + hSpatParamRendCom->azimuth[tmp_write_idx_band][b] = azi_dith; /*Q0*/ move16(); - hSpatParamRendCom->diffuseness_vector_fx[tmp_write_idx_band][b] = diffuseness_fx[band]; + hSpatParamRendCom->diffuseness_vector_fx[tmp_write_idx_band][b] = diffuseness_fx[band]; /*Q30*/ move32(); - tmp_write_idx_band = add( tmp_write_idx_band, 1 ) % hSpatParamRendCom->dirac_md_buffer_length; + tmp_write_idx_band = add( tmp_write_idx_band, 1 ) % hSpatParamRendCom->dirac_md_buffer_length; /*Q0*/ move16(); } } @@ -5344,12 +5344,12 @@ void ivas_spar_to_dirac_fx( /* update buffer write index */ IF( hDirAC->hConfig->dec_param_estim == FALSE ) { - hDirAC->spar_to_dirac_write_idx = add( hDirAC->spar_to_dirac_write_idx, MAX_PARAM_SPATIAL_SUBFRAMES ) % hSpatParamRendCom->dirac_md_buffer_length; + hDirAC->spar_to_dirac_write_idx = add( hDirAC->spar_to_dirac_write_idx, MAX_PARAM_SPATIAL_SUBFRAMES ) % hSpatParamRendCom->dirac_md_buffer_length; /*Q0*/ move16(); } ELSE { - hDirAC->spar_to_dirac_write_idx = add( hDirAC->spar_to_dirac_write_idx, CLDFB_NO_COL_MAX ) % hSpatParamRendCom->dirac_md_buffer_length; + hDirAC->spar_to_dirac_write_idx = add( hDirAC->spar_to_dirac_write_idx, CLDFB_NO_COL_MAX ) % hSpatParamRendCom->dirac_md_buffer_length; /*Q0*/ move16(); } } @@ -5364,7 +5364,7 @@ void ivas_spar_to_dirac_fx( { Word16 dirac_band_idx; - dirac_band_idx = sub( dirac_to_spar_md_bands[band], enc_param_start_band ); + dirac_band_idx = sub( dirac_to_spar_md_bands[band], enc_param_start_band ); /*Q0*/ num_subframes = MAX_PARAM_SPATIAL_SUBFRAMES; move16(); @@ -5380,17 +5380,17 @@ void ivas_spar_to_dirac_fx( IF( st_ivas->hQMetaData->q_direction->band_data[dirac_band_idx].azimuth_fx[block] < 0 ) { st_ivas->hQMetaData->q_direction->band_data[dirac_band_idx].azimuth_fx[block] = - L_add( L_shl( 360, 22 ), st_ivas->hQMetaData->q_direction->band_data[dirac_band_idx].azimuth_fx[block] ); + L_add( L_shl( 360, 22 ), st_ivas->hQMetaData->q_direction->band_data[dirac_band_idx].azimuth_fx[block] ); /*Q22*/ move32(); } - azi_dirac_fx[band][block] = st_ivas->hQMetaData->q_direction->band_data[dirac_band_idx].azimuth_fx[block]; + azi_dirac_fx[band][block] = st_ivas->hQMetaData->q_direction->band_data[dirac_band_idx].azimuth_fx[block]; /*Q22*/ move32(); - ele_dirac_fx[band][block] = st_ivas->hQMetaData->q_direction->band_data[dirac_band_idx].elevation_fx[block]; + ele_dirac_fx[band][block] = st_ivas->hQMetaData->q_direction->band_data[dirac_band_idx].elevation_fx[block]; /*Q22*/ move32(); } - diffuseness_fx[band] = L_sub( ONE_IN_Q30, st_ivas->hQMetaData->q_direction->band_data[dirac_band_idx].energy_ratio_fx[0] ); + diffuseness_fx[band] = L_sub( ONE_IN_Q30, st_ivas->hQMetaData->q_direction->band_data[dirac_band_idx].energy_ratio_fx[0] ); /*Q30*/ move32(); } @@ -5415,7 +5415,7 @@ void ivas_spar_to_dirac_fx( { FOR( band = SPAR_DIRAC_SPLIT_START_BAND; band < IVAS_MAX_NUM_BANDS; band++ ) { - pred_re_20ms_fx[band][pred_idx] = hMdDec->spar_md.band_coeffs[band].pred_re_fx[pred_idx]; + pred_re_20ms_fx[band][pred_idx] = hMdDec->spar_md.band_coeffs[band].pred_re_fx[pred_idx]; /*Q22*/ move32(); } } @@ -5446,12 +5446,12 @@ void ivas_spar_to_dirac_fx( { FOR( i = 0; i < FOA_CHANNELS - 1; i++ ) /* pred coefficient index (index 0, 1, 2 predicts Y, Z, X respectively) */ { - hMdDec->spar_md.band_coeffs[add( band, i_mult( block, IVAS_MAX_NUM_BANDS ) )].pred_re_fx[i] = hMdDec->spar_md.band_coeffs[band].pred_re_fx[i]; + hMdDec->spar_md.band_coeffs[( band + ( block * IVAS_MAX_NUM_BANDS ) )].pred_re_fx[i] = hMdDec->spar_md.band_coeffs[band].pred_re_fx[i]; /*Q22*/ move32(); } FOR( i = 0; i < FOA_CHANNELS - 1; i++ ) /* pred coefficient index (index 0, 1, 2 predicts Y, Z, X respectively) */ { - hMdDec->spar_md.band_coeffs[add( band, i_mult( block, IVAS_MAX_NUM_BANDS ) )].P_re_fx[i] = hMdDec->spar_md.band_coeffs[band].P_re_fx[i]; + hMdDec->spar_md.band_coeffs[( band + ( block * IVAS_MAX_NUM_BANDS ) )].P_re_fx[i] = hMdDec->spar_md.band_coeffs[band].P_re_fx[i]; /*Q22*/ move32(); } } @@ -5468,7 +5468,7 @@ void ivas_spar_to_dirac_fx( IF( ivas_is_res_channel( add( pred_idx, 1 ), hMdDec->spar_md_cfg.nchan_transport ) ) { /* use 20ms coefficients only for residual channels */ - hMdDec->spar_md.band_coeffs[add( band, i_mult( block, IVAS_MAX_NUM_BANDS ) )].pred_re_fx[pred_idx] = pred_re_20ms_fx[band][pred_idx]; + hMdDec->spar_md.band_coeffs[( band + ( block * IVAS_MAX_NUM_BANDS ) )].pred_re_fx[pred_idx] = pred_re_20ms_fx[band][pred_idx]; /*Q22*/ move32(); } } diff --git a/lib_dec/ivas_stat_dec.h b/lib_dec/ivas_stat_dec.h index 4575cf543..07d7fd3c5 100644 --- a/lib_dec/ivas_stat_dec.h +++ b/lib_dec/ivas_stat_dec.h @@ -312,13 +312,13 @@ typedef struct stereo_dft_dec_data_struct #ifdef IVAS_FLOAT_FIXED Word32 smooth_dmx_nrg_fx[STEREO_DFT_BAND_MAX]; /* Q(q_smoothed_nrg) */ Word32 smooth_res_nrg_fx[STEREO_DFT_BAND_MAX]; /* Q(q_smoothed_nrg) */ - Word32 td_gain_fx[STEREO_DFT_CORE_HIST_MAX]; + Word32 td_gain_fx[STEREO_DFT_CORE_HIST_MAX]; /* Q(q_td_gain) */ #endif #ifdef IVAS_FLOAT_FIXED - Word32 hb_stefi_sig_fx[L_FRAME48k + NS2SA( 48000, STEREO_DFT_TD_STEFI_DELAY_NS )]; - Word32 hb_nrg_fx[STEREO_DFT_CORE_HIST_MAX]; - Word32 hb_nrg_subr_fx[STEREO_DFT_NBDIV]; + Word32 hb_stefi_sig_fx[L_FRAME48k + NS2SA( 48000, STEREO_DFT_TD_STEFI_DELAY_NS )]; /* Q(q_hb_stefi_sig_fx) */ + Word32 hb_nrg_fx[STEREO_DFT_CORE_HIST_MAX]; /* Q(q_hb_nrg) */ + Word32 hb_nrg_subr_fx[STEREO_DFT_NBDIV]; /* Q(q_hb_nrg_subr) */ Word16 Q_nrg_subr; Word16 prev_Q_stefi_sig; @@ -700,10 +700,10 @@ typedef struct param_ism_rendering { #ifdef IVAS_FLOAT_FIXED Word16 *proto_matrix_fx; - Word16 *interpolator_fx; /* Q15 */ - Word32 *Cldfb_RealBuffer_tc_fx; + Word16 *interpolator_fx; /* Q15 */ + Word32 *Cldfb_RealBuffer_tc_fx; /* Q31 - Cldfb_RealBuffer_tc_exp */ Word16 Cldfb_RealBuffer_tc_exp; - Word32 *Cldfb_ImagBuffer_tc_fx; + Word32 *Cldfb_ImagBuffer_tc_fx; /* Q31 - Cldfb_ImagBuffer_tc_exp */ Word16 Cldfb_ImagBuffer_tc_exp; Word32 mixing_matrix_lin_fx[CLDFB_NO_CHANNELS_MAX][PARAM_ISM_MAX_CHAN * PARAM_ISM_MAX_DMX]; Word16 exp_mixing_matrix_lin_fx[CLDFB_NO_CHANNELS_MAX]; @@ -1263,10 +1263,10 @@ typedef struct ivas_lfe_dec_data_structure typedef struct renderer_struct { #ifdef IVAS_FLOAT_FIXED - Word32 prev_gains_fx[MAX_CICP_CHANNELS - 1][MAX_OUTPUT_CHANNELS]; - Word16 *interpolator_fx; + Word32 prev_gains_fx[MAX_CICP_CHANNELS - 1][MAX_OUTPUT_CHANNELS]; /*Q30*/ + Word16 *interpolator_fx; /*Q15*/ Word16 interpolator_len; - Word32 gains_fx[MAX_CICP_CHANNELS - 1][MAX_OUTPUT_CHANNELS]; + Word32 gains_fx[MAX_CICP_CHANNELS - 1][MAX_OUTPUT_CHANNELS]; /*Q30*/ #else float prev_gains[MAX_CICP_CHANNELS - 1][MAX_OUTPUT_CHANNELS]; float *interpolator; @@ -1285,7 +1285,7 @@ typedef struct ivas_binaural_rendering_struct #ifndef IVAS_FLOAT_FIXED float *hoa_dec_mtx; /* pointer to HOA decoder mtx */ #else - Word32 *hoa_dec_mtx; /* pointer to HOA decoder mtx */ + Word32 *hoa_dec_mtx; /* pointer to HOA decoder mtx */ /*Q29*/ #endif int8_t rotInCldfb; /* Flag to enable rotation within bin Renderer in CLDFB*/ int16_t max_band; /* band upto which rendering is performed */ diff --git a/lib_dec/peak_vq_dec_fx.c b/lib_dec/peak_vq_dec_fx.c index d3fa428b2..9a3251836 100644 --- a/lib_dec/peak_vq_dec_fx.c +++ b/lib_dec/peak_vq_dec_fx.c @@ -28,7 +28,7 @@ void hvq_dec_fx( Decoder_State *st_fx, /* i/o: decoder state structure */ const Word16 num_bits, /* i : Number of available bits */ const Word32 core_brate, /* i : Core bit-rate */ - const Word16 *ynrm, /* i : Envelope coefficients */ + const Word16 *ynrm, /* i : Envelope coefficients Q0 */ Word16 *R, /* i/o: Bit allocation/updated bit allocation */ Word16 *noise_level, /* o : Noise level in Q15 */ Word16 *peak_idx, /* o : Peak position vector */ @@ -68,7 +68,7 @@ static void peak_vq_dec_fx( Word32 *coefs_out, /* o : Output coefficient vector Q12 */ const Word32 core_brate, /* i : Core bitrate */ const Word16 num_bits, /* i : Number of bits for HVQ */ - const Word16 *ynrm, /* i : Envelope coefficients */ + const Word16 *ynrm, /* i : Envelope coefficients Q0 */ Word16 *R, /* i/o: Bit allocation/updated bit allocation */ Word16 *vq_peak_idx, /* o : Peak position vector */ Word16 *Npeaks, /* o : Number of peaks */ @@ -241,8 +241,8 @@ static void peak_vq_dec_fx( move16(); } - peak_gains_fx[i] = dicn_pg_fx[pgain_difidx[i]]; - move32(); /* Q12 move16(); */ + peak_gains_fx[i] = dicn_pg_fx[pgain_difidx[i]]; // Q12 + move32(); if ( res_vec[vq_peak_idx[i]] < 0 ) { peak_gains_fx[i] = L_negate( peak_gains_fx[i] ); @@ -256,12 +256,12 @@ static void peak_vq_dec_fx( move16(); FOR( i = 0; i < vq_peaks; i++ ) { - peak_gains_fx[i] = L_shl( peak_gains_fx[i], 2 ); - move32(); /* Q12 */ + peak_gains_fx[i] = L_shl( peak_gains_fx[i], 2 ); // Q12 -> Q14 + move32(); /* Use floating point operation to deal with wide dynamic range. * 32-bit mantissa is used here. It should be even more accurate than * the floating-point reference code with 24-bit mantissa! */ - tmp = L_shl( dicn_pg_fx[pgain_difidx[i]], 2 ); + tmp = L_shl( dicn_pg_fx[pgain_difidx[i]], 2 ); // Q14 expPeakGains = norm_l( tmp ); manPeakGains = L_shl( tmp, expPeakGains ); Mpy_32_32_ss( manPeakGains, manPeakGains, &manPkEnrg, &lsb ); /* peak_gains square */ @@ -478,7 +478,7 @@ static Word16 hvq_dec_pos_fx( mode = get_next_indice_fx( st_fx, 1 ); num_bits = add( num_bits, 1 ); - IF( EQ_16( mode, HVQ_CP_DELTA ) ) + IF( ( mode == HVQ_CP_DELTA ) ) { huff_dec_fx( st_fx, num_peaks, HVQ_CP_HUFF_MAX_CODE, HVQ_CP_HUFF_NUM_LEN, hvq_cp_huff_thres, hvq_cp_huff_offset, hvq_cp_huff_tab, delta ); @@ -490,7 +490,7 @@ static Word16 hvq_dec_pos_fx( peak_idx[0] = sub( delta[0], HVQ_CP_HUFF_OFFSET ); move16(); /* safety check in case of bit errors */ - IF( peak_idx[0] < 2 ) + IF( LT_16( peak_idx[0], 2 ) ) { peak_idx[0] = 2; move16(); @@ -541,10 +541,10 @@ static Word16 hvq_dec_pos_fx( j = 0; move16(); /* safety check in case of bit errors */ - test(); FOR( i = 0; i < length && j < num_peaks; i++ ) { - if ( EQ_16( pos_vec[i], 1 ) ) + test(); + IF( EQ_16( pos_vec[i], 1 ) ) { pos_vec[i] = i_mult2( pos_vec[i], sign_vec[j++] ); move16(); @@ -605,7 +605,8 @@ static Word16 sparse_dec_pos_fx( move16(); } tmp = i_mult2( j, HVQ_CP_L1_LEN ); - FOR( i = sub( s_min( i_mult2( add( j, 1 ), HVQ_CP_L1_LEN ), length ), 1 ); i >= tmp; i-- ) + FOR( i = ( s_min( ( j + 1 ) * HVQ_CP_L1_LEN, length ) - 1 ); + i >= tmp; i-- ) { out[i] = s_and( val, 1 ); move16(); diff --git a/lib_dec/pit_dec_fx.c b/lib_dec/pit_dec_fx.c index a68cba5a8..a2b5a7618 100644 --- a/lib_dec/pit_dec_fx.c +++ b/lib_dec/pit_dec_fx.c @@ -17,18 +17,18 @@ * Decode pitch lag *----------------------------------------------------------*/ -Word32 Mode2_pit_decode( /* o: floating pitch value */ +Word32 Mode2_pit_decode( /* o: pitch value Q16 */ const Word16 coder_type, /* i: coding model */ Word16 i_subfr, /* i: subframe index */ Word16 L_subfr, - Word16 **pt_indice, /* i/o: quantization indices pointer */ - Word16 *T0, /* i/o: close loop integer pitch */ - Word16 *T0_frac, /* o: close loop fractional part of the pitch */ - Word16 *T0_res, /* i/o: pitch resolution */ - Word16 *T0_min, /* i/o: lower limit for close-loop search */ - Word16 *T0_min_frac, /* i/o: lower limit for close-loop search */ - Word16 *T0_max, /* i/o: higher limit for close-loop search */ - Word16 *T0_max_frac, /* i/o: higher limit for close-loop search */ + Word16 **pt_indice, /* i/o: quantization indices pointer */ + Word16 *T0, /* i/o: close loop integer pitch Q0 */ + Word16 *T0_frac, /* o: close loop fractional part of the pitch Q0 */ + Word16 *T0_res, /* i/o: pitch resolution Q0 */ + Word16 *T0_min, /* i/o: lower limit for close-loop search Q0 */ + Word16 *T0_min_frac, /* i/o: lower limit for close-loop search Q0 */ + Word16 *T0_max, /* i/o: higher limit for close-loop search Q0 */ + Word16 *T0_max_frac, /* i/o: higher limit for close-loop search Q0 */ Word16 pit_min, Word16 pit_fr1, Word16 pit_fr1b, @@ -156,8 +156,8 @@ Word32 Mode2_pit_decode( /* o: floating pitch value *-------------------------------------------------------*/ assert( *T0_res > 0 || *T0_res <= 6 ); - /*pitch = (float)(*T0) + (float)(*T0_frac)/(float)(*T0_res);*/ /* save subframe pitch values */ - pitch = L_mac( L_deposit_h( *T0 ), *T0_frac, inv_T0_res[*T0_res] ); + /*pitch = (float)(*T0) + (float)(*T0_frac)/(float)(*T0_res);*/ /* save subframe pitch values */ + pitch = L_mac( L_deposit_h( *T0 ), *T0_frac, inv_T0_res[*T0_res] ); // Q16 return pitch; @@ -171,9 +171,9 @@ Word32 Mode2_pit_decode( /* o: floating pitch value *---------------------------------------------------------------------*/ void Mode2_abs_pit_dec( - Word16 *T0, /* o: integer pitch lag */ - Word16 *T0_frac, /* o: pitch fraction */ - Word16 *T0_res, /* o: pitch resolution */ + Word16 *T0, /* o: integer pitch lag Q0 */ + Word16 *T0_frac, /* o: pitch fraction Q0 */ + Word16 *T0_res, /* o: pitch resolution Q0 */ Word16 **pt_indice, /* i/o: pointer to Vector of Q indexes */ Word16 pit_min, Word16 pit_fr1, @@ -197,14 +197,14 @@ void Mode2_abs_pit_dec( res = pit_res_max; move16(); - if ( EQ_16( pit_res_max, 6 ) ) + IF( EQ_16( pit_res_max, 6 ) ) { res = shr( res, 1 ); } *T0 = mult( index, inv_T0_res[res] ); move16(); - if ( EQ_16( pit_res_max, 6 ) ) + IF( EQ_16( pit_res_max, 6 ) ) { *T0 = shr( *T0, 1 ); move16(); @@ -250,11 +250,11 @@ void Mode2_abs_pit_dec( * Decode delta pitch *---------------------------------------------------------------------*/ void Mode2_delta_pit_dec( - Word16 *T0, /* o: integer pitch lag */ - Word16 *T0_frac, /* o: pitch fraction */ - Word16 T0_res, /* i: pitch resolution */ - Word16 *T0_min, /* i/o: delta search min */ - Word16 *T0_min_frac, /* i: delta search min */ + Word16 *T0, /* o: integer pitch lag Q0 */ + Word16 *T0_frac, /* o: pitch fraction Q0 */ + Word16 T0_res, /* i: pitch resolution Q0 */ + Word16 *T0_min, /* i/o: delta search min Q0 */ + Word16 *T0_min_frac, /* i: delta search min Q0 */ Word16 **pt_indice /* i/o: pointer to Vector of Q indexes */ ) { @@ -277,7 +277,7 @@ void Mode2_delta_pit_dec( *T0 = mult( add( index, *T0_min_frac ), inv_T0_res[res] ); move16(); - if ( EQ_16( T0_res, 6 ) ) + IF( EQ_16( T0_res, 6 ) ) { *T0 = shr( *T0, 1 ); move16(); @@ -614,12 +614,12 @@ Word16 pit_decode_ivas_fx( /* o : floating p Word16 *T0_min, /* i/o: delta search min for sf 2 & 4 */ Word16 *T0_max, /* i/o: delta search max for sf 2 & 4 */ const Word16 L_subfr, /* i : subframe length */ - const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag */ - const Word16 tdm_Pri_pitch_buf[] /* i : primary channel pitch buffer */ + const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag */ + const Word16 tdm_Pri_pitch_buf[] /* i : primary channel pitch buffer Q6 */ ) { Word16 pitch; /*Q2*/ - Word16 pitch_index, nBits, pit_flag; + Word16 pitch_index, nBits, pit_flag, tmp; pitch_index = 0; move16(); @@ -683,7 +683,8 @@ Word16 pit_decode_ivas_fx( /* o : floating p /* find the number of bits */ IF( i_subfr ) { - nBits = st_fx->acelp_cfg.pitch_bits[idiv1616( i_subfr, L_subfr )]; + tmp = idiv1616( i_subfr, L_subfr ); + nBits = st_fx->acelp_cfg.pitch_bits[tmp]; } ELSE { @@ -762,7 +763,7 @@ Word16 pit_decode_ivas_fx( /* o : floating p move16(); move16(); pit_tmp1 = tdm_Pri_pitch_buf[isubfridx]; /*tdm_Pri_pitch_buf in Q6 ->pit_tmp1 and 2 in Q6 too */ - pit_tmp2 = tdm_Pri_pitch_buf[shr( add( i_subfr, 1 ), 6 )]; + pit_tmp2 = tdm_Pri_pitch_buf[( i_subfr + 1 ) / L_SUBFR]; /*loc_T0 = (int16_t)(0.5f * tdm_Pri_pitch_buf[i_subfr / L_SUBFR] + 0.5f * tdm_Pri_pitch_buf[(i_subfr + L_SUBFR) / L_SUBFR]);*/ loc_T0 = mac_r( L_mult( 16384, pit_tmp1 ), 16384, pit_tmp2 ); /*loc_frac = (int16_t)(((0.5f * tdm_Pri_pitch_buf[i_subfr / L_SUBFR] + 0.5f * tdm_Pri_pitch_buf[(i_subfr + L_SUBFR) / L_SUBFR]) - loc_T0) * 4.0f);*/ @@ -771,6 +772,7 @@ Word16 pit_decode_ivas_fx( /* o : floating p { /*loc_T0 = (int16_t)tdm_Pri_pitch_buf[i_subfr / L_SUBFR];*/ loc_T0 = tdm_Pri_pitch_buf[isubfridx]; /*Q6*/ + move16(); /*loc_frac = (int16_t)((tdm_Pri_pitch_buf[i_subfr / L_SUBFR] - loc_T0) * 4.0f);*/ } loc_frac = shr( sub( loc_T0, shl( shr( loc_T0, 6 ), 6 ) ), 4 ); /* Final result in Q 2*/ @@ -1004,7 +1006,7 @@ void pit16k_Q_dec_fx( *T0 = add( PIT16k_FR2_EXTEND_10b, shr( index, 1 ) ); move16(); *T0_frac = sub( index, shl( sub( *T0, PIT16k_FR2_EXTEND_10b ), 1 ) ); - ( *T0_frac ) = shl( *T0_frac, 1 ); + ( *T0_frac ) = shl( *T0_frac, 1 ); //( *T0_frac ) *= 2; move16(); } } diff --git a/lib_dec/pitch_extr_fx.c b/lib_dec/pitch_extr_fx.c index 4831d087c..f1e69ae68 100644 --- a/lib_dec/pitch_extr_fx.c +++ b/lib_dec/pitch_extr_fx.c @@ -16,11 +16,11 @@ * ------------------- Q15 * PIT_MAX x Fact *-------------------------------------------------------------------*/ - +#ifndef IVAS_FLOAT_FIXED #define PIT_MAX_DIV_8k( num, fact ) ( -( num * 32768 ) / ( PIT_MAX_12k8 * fact ) ) #define PIT_MAX_DIV_12k8( num, fact ) ( -( num * 32768 ) / ( PIT_MAX_12k8 * fact ) ) #define PIT_MAX_DIV_16k( num, fact ) ( -( num * 32768 ) / ( PIT_MAX_16k * fact ) ) - +#endif /*-----------------------------------------------------------------* * Pitch prediction for frame erasure using linear fitting * @@ -76,7 +76,7 @@ void pitch_pred_linear_fit( { FOR( i = 0; i < 2 * NB_SUBFR + 2; i++ ) { - mem_lag[i] = old_pitch_buf[2 * NB_SUBFR + 1 - i]; + mem_lag[i] = old_pitch_buf[2 * NB_SUBFR + 1 - i]; // Q16 move32(); } } @@ -84,7 +84,7 @@ void pitch_pred_linear_fit( { FOR( i = 0; i < 2 * NB_SUBFR16k + 2; i++ ) { - mem_lag[i] = old_pitch_buf[2 * NB_SUBFR16k + 1 - i]; + mem_lag[i] = old_pitch_buf[2 * NB_SUBFR16k + 1 - i]; // Q16 move32(); } } diff --git a/lib_dec/post_dec_fx.c b/lib_dec/post_dec_fx.c index bf9e51a87..f37a86ea1 100644 --- a/lib_dec/post_dec_fx.c +++ b/lib_dec/post_dec_fx.c @@ -23,11 +23,12 @@ static void bass_pf_1sf_delay( Word16 *syn, Word16 *T_sf, Word16 *gainT_sf, Word void post_decoder( Decoder_State *st, - Word16 synth_buf[], - Word16 pit_gain[], - Word16 pitch[], - Word16 signal_out[], - Word16 *bpf_noise_buf ) + Word16 synth_buf[], /* Q0 */ + Word16 pit_gain[], /* Q14 */ + Word16 pitch[], /* Q0 */ + Word16 signal_out[], /* Q0 */ + Word16 *bpf_noise_buf /* Q0 */ +) { Word16 L_frame, nb_subfr; Word16 *synth, *synth2; @@ -81,7 +82,7 @@ void post_decoder( ELSE { /*Formant enhancement*/ - IF( EQ_16( st->last_bwidth, NB ) ) + IF( ( st->last_bwidth == NB ) ) { Copy( synth, synth2_pe, L_frame ); tmp = synth[-1]; @@ -106,7 +107,7 @@ void post_decoder( st->hPFstat->reset = 1; move16(); } - IF( EQ_16( st->bwidth, NB ) ) + IF( ( st->bwidth == NB ) ) { st->hPFstat->on = 1; move16(); @@ -174,11 +175,12 @@ void post_decoder( void post_decoder_ivas_fx( Decoder_State *st, - Word16 synth_buf[], - Word16 pit_gain[], - Word16 pitch[], - Word16 signal_out[], - Word16 *bpf_noise_buf ) + Word16 synth_buf[], // Q0 + Word16 pit_gain[], // Q14 + Word16 pitch[], // Q0 + Word16 signal_out[], // Q0 + Word16 *bpf_noise_buf // Q0 +) { Word16 L_frame, nb_subfr; Word16 *synth, *synth2; @@ -268,7 +270,7 @@ void post_decoder_ivas_fx( st->hPFstat->reset = 1; move16(); } - IF( EQ_16( st->bwidth, NB ) ) + IF( ( st->bwidth == NB ) ) { st->hPFstat->on = 1; move16(); @@ -406,12 +408,12 @@ static void bass_pf_1sf_delay( Word64 nrg64 = W_deposit32_l( nrg ); FOR( i = 0; i < lg; i++ ) { - tmp32 = L_mult( syn[sub( add( i, i_subfr ), T )], 0x4000 ); - tmp32 = L_mac( tmp32, syn[add( add( i, i_subfr ), T )], 0x4000 ); + tmp32 = L_mult( syn[( i + i_subfr ) - T], 0x4000 ); + tmp32 = L_mac( tmp32, syn[( i + i_subfr ) + T], 0x4000 ); tmp16 = round_fx( L_shl( tmp32, s1 ) ); /* Q0+s1 */ - tmp64 = W_mac0_16_16( tmp64, shl( syn[add( i, i_subfr )], s1 ), tmp16 ); /* Q0+2*s1 */ - nrg64 = W_mac0_16_16( nrg64, tmp16, tmp16 ); /* Q0+2*s1 */ + tmp64 = W_mac0_16_16( tmp64, shl( syn[i + i_subfr], s1 ), tmp16 ); /* Q0+2*s1 */ + nrg64 = W_mac0_16_16( nrg64, tmp16, tmp16 ); /* Q0+2*s1 */ } tmp = W_sat_l( tmp64 ); nrg = W_sat_l( nrg64 ); @@ -426,9 +428,9 @@ static void bass_pf_1sf_delay( Word64 nrg64 = W_deposit32_l( nrg ); FOR( i = lg; i < l_subfr; i++ ) { - tmp16 = shl( syn[sub( add( i, i_subfr ), T )], s1 ); /* Q0+s1 */ - tmp64 = W_mac0_16_16( tmp64, shl( syn[add( i, i_subfr )], s1 ), tmp16 ); /* Q0+2*s1 */ - nrg64 = W_mac0_16_16( nrg64, tmp16, tmp16 ); /* Q0+2*s1 */ + tmp16 = shl( syn[( i + i_subfr ) - T], s1 ); /* Q0+s1 */ + tmp64 = W_mac0_16_16( tmp64, shl( syn[i + i_subfr], s1 ), tmp16 ); /* Q0+2*s1 */ + nrg64 = W_mac0_16_16( nrg64, tmp16, tmp16 ); /* Q0+2*s1 */ } tmp = W_sat_l( tmp64 ); nrg = W_sat_l( nrg64 ); @@ -468,10 +470,10 @@ static void bass_pf_1sf_delay( Word64 ener2_64 = W_deposit32_l( ener2 ); FOR( i = 0; i < lg; i++ ) { - tmp32 = L_msu0( 0, gain, syn[sub( add( i, i_subfr ), T )] ); - tmp32 = L_msu0( tmp32, gain, syn[add( add( i, i_subfr ), T )] ); + tmp32 = L_msu0( 0, gain, syn[( i + i_subfr ) - T] ); + tmp32 = L_msu0( tmp32, gain, syn[( i + i_subfr ) + T] ); #ifdef BASOP_NOGLOB - tmp16 = mac_r_sat( tmp32, gain, syn[add( i, i_subfr )] ); /* Q0 */ + tmp16 = mac_r_sat( tmp32, gain, syn[i + i_subfr] ); /* Q0 */ #else tmp16 = mac_r( tmp32, gain, syn[i + i_subfr] ); /* Q0 */ #endif @@ -498,8 +500,8 @@ static void bass_pf_1sf_delay( FOR( i = lg; i < l_subfr; i++ ) { #ifdef BASOP_NOGLOB - tmp32 = L_mult0( gain, syn[add( i, i_subfr )] ); - tmp32 = L_msu0_sat( tmp32, gain, syn[sub( add( i, i_subfr ), T )] ); /* Q0 */ + tmp32 = L_mult0( gain, syn[i + i_subfr] ); + tmp32 = L_msu0_sat( tmp32, gain, syn[( i + i_subfr ) - T] ); /* Q0 */ tmp16 = round_fx_sat( tmp32 ); lp_error = Mpy_32_16_1( lp_error, 29491 /*0.9f Q15*/ ); @@ -582,11 +584,11 @@ static void bass_pf_1sf_delay( { FOR( i = 0; i < lg; i++ ) { - tmp32 = L_msu0( 0, tmp16, syn[sub( add( i, i_subfr ), T )] ); + tmp32 = L_msu0( 0, tmp16, syn[( i + i_subfr ) - T] ); #ifdef BASOP_NOGLOB - tmp32 = L_msu0_sat( tmp32, tmp16, syn[add( add( i, i_subfr ), T )] ); - tmp32 = L_mac_sat( tmp32, tmp16, syn[add( i, i_subfr )] ); - bpf_noise_buf[add( i, i_subfr )] = round_fx_sat( tmp32 ); /* Q0 */ + tmp32 = L_msu0_sat( tmp32, tmp16, syn[( i + i_subfr ) + T] ); + tmp32 = L_mac_sat( tmp32, tmp16, syn[i + i_subfr] ); + bpf_noise_buf[i + i_subfr] = round_fx_sat( tmp32 ); /* Q0 */ move16(); #else tmp32 = L_msu0( tmp32, tmp16, syn[i + i_subfr + T] ); @@ -600,10 +602,10 @@ static void bass_pf_1sf_delay( { FOR( i = lg; i < l_subfr; i++ ) { - tmp32 = L_mult0( tmp16, syn[add( i, i_subfr )] ); + tmp32 = L_mult0( tmp16, syn[i + i_subfr] ); #ifdef BASOP_NOGLOB - tmp32 = L_msu0_sat( tmp32, tmp16, syn[sub( add( i, i_subfr ), T )] ); - bpf_noise_buf[add( i, i_subfr )] = round_fx_sat( tmp32 ); /* Q0 */ + tmp32 = L_msu0_sat( tmp32, tmp16, syn[i + i_subfr - T] ); + bpf_noise_buf[i + i_subfr] = round_fx_sat( tmp32 ); /* Q0 */ move16(); #else tmp32 = L_msu0( tmp32, tmp16, syn[i + i_subfr - T] ); @@ -686,7 +688,7 @@ void cldfb_synth_set_bandsToZero( move16(); } - FOR( i = 0; i < sub( st->cldfbSyn->no_channels, st->cldfbSyn->bandsToZero ); i++ ) + FOR( i = 0; i < ( st->cldfbSyn->no_channels - st->cldfbSyn->bandsToZero ); i++ ) { nrgQ31 = 0; move32(); @@ -746,7 +748,7 @@ void cldfb_synth_set_bandsToZero( move16(); } - FOR( i = 0; i < sub( WBcnt, 1 ); i++ ) + FOR( i = 0; i < ( WBcnt - 1 ); i++ ) { st->flag_buffer[i] = st->flag_buffer[i + 1]; move16(); @@ -789,7 +791,8 @@ void cldfb_synth_set_bandsToZero( { test(); test(); - IF( ( st->perc_bwddec >= perc_detect || ( st->perc_bwddec >= perc_miss && st->last_flag_filter_NB ) ) && ( sum16_fx( st->flag_buffer, WBcnt ) != 0 ) ) /*decision hysterysis*/ + test(); + IF( ( GE_16( st->perc_bwddec, perc_detect ) || ( GE_16( st->perc_bwddec, perc_miss ) && st->last_flag_filter_NB ) ) && ( sum16_fx( st->flag_buffer, WBcnt ) != 0 ) ) /*decision hysterysis*/ { st->cldfbSyn->bandsToZero = sub( st->cldfbSyn->no_channels, 10 ); move16(); diff --git a/lib_dec/ppp_dec_fx.c b/lib_dec/ppp_dec_fx.c index 88cc99e2c..437927d7c 100644 --- a/lib_dec/ppp_dec_fx.c +++ b/lib_dec/ppp_dec_fx.c @@ -60,12 +60,12 @@ static void DTFS_dequant_cw_fx( IF( EQ_16( num_erb_fx, NUM_ERB_NB ) ) { - PowerCB_fx = PowerCB_NB_fx; + PowerCB_fx = PowerCB_NB_fx; // Q11 move16(); } ELSE IF( EQ_16( num_erb_fx, NUM_ERB_WB ) ) { - PowerCB_fx = PowerCB_WB_fx; + PowerCB_fx = PowerCB_WB_fx; // Q11 move16(); } @@ -75,11 +75,11 @@ static void DTFS_dequant_cw_fx( curr_erb_fx[0] = mult_r( curr_erb_fx[1], 9830 ); /* 0.3 inQ15 leaves curr_erb in Q13 */ move16(); - curr_erb_fx[sub( num_erb_fx, 2 )] = mult_r( curr_erb_fx[sub( num_erb_fx, 3 )], 9830 ); /* Q13 */ + curr_erb_fx[num_erb_fx - 2] = mult_r( curr_erb_fx[num_erb_fx - 3], 9830 ); /* Q13 */ move16(); - curr_erb_fx[sub( num_erb_fx, 1 )] = 0; + curr_erb_fx[num_erb_fx - 1] = 0; move16(); erb_slot_fx( X_fx->lag_fx, slot_fx, mfreq_fx, num_erb_fx ); @@ -101,9 +101,13 @@ static void DTFS_dequant_cw_fx( /* This logic adjusts difference between Q formats of both bands */ IF( n < 0 ) - rshiftHarmBand_fx( X_fx, 2828, X_fx->upper_cut_off_freq_fx, n ); + { + 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 ) ); + } DTFS_to_erb_fx( *X_fx, lasterbD_fx ); @@ -203,9 +207,13 @@ static void DTFS_dequant_cw_fx( IF( n < 0 ) - rshiftHarmBand_fx( X_fx, 2828, X_fx->upper_cut_off_freq_fx, n ); + { + 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 ) ); + } } /*===================================================================*/ /* FUNCTION : void ppp_quarter_decoder_fx () */ diff --git a/lib_dec/pvq_core_dec_fx.c b/lib_dec/pvq_core_dec_fx.c index 530c2c5b9..121c472fe 100644 --- a/lib_dec/pvq_core_dec_fx.c +++ b/lib_dec/pvq_core_dec_fx.c @@ -25,7 +25,7 @@ static void pvq_decode_band_fx( PVQ_DEC_HANDLE hPVQ, /* i/o: PVQ decoder handle */ Word16 *pulse_vector, /* i/o: decoded integer shape vector */ Word16 *npulses, /* i/o: number of pulses */ - Word16 *coefs_quant, /* i/o: decoded coefficients buffer */ + Word16 *coefs_quant, /* i/o: decoded coefficients buffer Qx */ const Word16 sfmsize, /* i : band length */ const Word16 band_bits, /* i : assigned bit budget */ Word16 *bits_left, /* i/o: number of bits / bits remaining */ @@ -112,14 +112,14 @@ static void pvq_decode_band_fx( void pvq_decode_frame_fx( Decoder_State *st_fx, - Word16 *coefs_quant, /* o : quantized coefficients */ + Word16 *coefs_quant, /* o : quantized coefficients Qx */ Word16 *npulses, /* o : number of pulses per band */ Word16 *pulse_vector, /* o : non-normalized pulse shapes */ const Word16 *sfm_start, /* i : indices of first coefficients in the bands */ const Word16 *sfm_end, /* i : indices of last coefficients in the bands */ const Word16 *sfmsize, /* i : band sizes */ const Word16 nb_sfm, /* i : total number of bands */ - const Word16 *R, /* i : bitallocation per band */ + const Word16 *R, /* i : bitallocation per band Q3 */ const Word16 pvq_bits, /* i : number of bits avaiable */ const Word16 core /* i : core */ ) @@ -134,6 +134,7 @@ void pvq_decode_frame_fx( Word16 strict_bits; PVQ_DEC_DATA pvq_dec; PVQ_DEC_HANDLE hPVQ = &pvq_dec; + move16(); rc_dec_init_fx( st_fx, hPVQ, pvq_bits ); @@ -174,8 +175,8 @@ void pvq_decode_frame_fx( move16(); IF( R[is] > 0 ) { - bandBitsAdjustment_fx( hPVQ->rc_num_bits, hPVQ->rc_range, bits, bands_to_code, bands_to_code - coded_bands, sfmsize[is], R[is], bit_pool, /* inputs */ - &band_bits, &bits_left, &bit_pool ); /* outputs */ + bandBitsAdjustment_fx( hPVQ->rc_num_bits, hPVQ->rc_range, bits, bands_to_code, sub( bands_to_code, coded_bands ), sfmsize[is], R[is], bit_pool, /* inputs */ + &band_bits, &bits_left, &bit_pool ); /* outputs */ pvq_decode_band_fx( st_fx, hPVQ, &pulse_vector[sfm_start[is]], &npulses[is], &coefs_quant[sfm_start[is]], sfmsize[is], band_bits, @@ -209,7 +210,7 @@ Word16 ivas_pvq_core_dec_fx( const Word16 *sfm_start, const Word16 *sfm_end, const Word16 *sfmsize, - Word16 coefs_quant[], /* o : output MDCT */ + Word16 coefs_quant[], /* o : output MDCT, Q_coefs */ Word16 *Q_coefs, Word16 bits_tot, Word16 nb_sfm, @@ -227,16 +228,16 @@ Word16 ivas_pvq_core_dec_fx( Word16 gain_bits_array[NB_SFM]; Word16 fg_pred[NB_SFM_MAX]; - IF( st_fx->hHQ_core != NULL ) + if ( st_fx->hHQ_core != NULL ) { st_fx->hHQ_core->ber_occured_in_pvq = 0; move16(); } - R_upd = shl( bits_tot, 3 ); + R_upd = shl( bits_tot, 3 ); // Q0 -> Q3 ivas_assign_gain_bits_fx( core, nb_sfm, sfmsize, R, gain_bits_array, &R_upd ); - pvq_bits = shr( R_upd, 3 ); + pvq_bits = shr( R_upd, 3 ); // Q3 -> Q0 pvq_decode_frame_fx( st_fx, coefs_quant, npulses, pulse_vector, sfm_start, sfm_end, sfmsize, nb_sfm, R, pvq_bits, core ); @@ -245,7 +246,7 @@ Word16 ivas_pvq_core_dec_fx( { FOR( i = 0; i < nb_sfm; i++ ) { - IF( LE_16( npulses[i], 0 ) ) + IF( ( npulses[i] <= 0 ) ) { Rs[i] = 0; move16(); /* Update Rs in case no pulses were assigned */ @@ -257,7 +258,7 @@ Word16 ivas_pvq_core_dec_fx( { ord[i] = i; move16(); - IF( LE_16( npulses[i], 0 ) ) + if ( ( npulses[i] <= 0 ) ) { R[i] = 0; move16(); /* Update in case no pulses were assigned */ @@ -272,7 +273,7 @@ Word16 ivas_pvq_core_dec_fx( fine_gain_dec_fx( st_fx, ord, nb_sfm, gain_bits_array, fg_pred ); IF( st_fx->hHQ_core != NULL ) { - IF( NE_16( st_fx->hHQ_core->ber_occured_in_pvq, 0 ) ) + IF( ( st_fx->hHQ_core->ber_occured_in_pvq != 0 ) ) { set16_fx( fg_pred, 1, nb_sfm ); /* low complex ECU action in case of detetected BER in PVQ decoding */ } @@ -307,16 +308,16 @@ Word16 pvq_core_dec_fx( Word16 gain_bits_array[NB_SFM]; Word16 fg_pred[NB_SFM_MAX]; - IF( st_fx->hHQ_core != NULL ) + if ( st_fx->hHQ_core != NULL ) { st_fx->hHQ_core->ber_occured_in_pvq = 0; move16(); } - R_upd = shl( bits_tot, 3 ); + R_upd = shl( bits_tot, 3 ); // Q0 -> Q3 assign_gain_bits_fx( core, nb_sfm, sfmsize, R, gain_bits_array, &R_upd ); - pvq_bits = shr( R_upd, 3 ); + pvq_bits = shr( R_upd, 3 ); // Q3 -> Q0 pvq_decode_frame_fx( st_fx, coefs_quant, npulses, pulse_vector, sfm_start, sfm_end, sfmsize, nb_sfm, R, pvq_bits, core ); @@ -375,7 +376,7 @@ void decode_energies_fx( Word16 *dim_part, Word16 *bits_part, Word16 *g_part, /* Q15 */ - short qband, + Word16 qband, Word16 *bits_left, Word16 dim, const Word16 strict_bits ) @@ -485,12 +486,13 @@ static void densitySymbolIndexDecode_fx( { /* odd density exit */ *index_phi = -1; + move16(); return; } sym_freq = L_deposit_l( 1 ); - angle = atan2_fx( SQRT_DIM_fx[opp_sz], SQRT_DIM_fx[near_sz] ); + angle = atan2_fx( SQRT_DIM_fx[opp_sz], SQRT_DIM_fx[near_sz] ); // Q13 #ifdef BASOP_NOGLOB angle = shl_o( angle, 1, &Overflow ); #else @@ -526,7 +528,7 @@ static void densitySymbolIndexDecode_fx( Mpy_32_16_ss( acc, density_c, &acc, &lsb ); acc = L_or( L_shl( acc, 16 ), L_and( lsb, 0xffffL ) ); /* Concatenate acc and lsb forming 48 bits; upshift 16 bits; keep 32 MSB. */ acc = L_shr( acc, 1 ); /* Compensate fractional mode multiply (Mpy_32_16_ss) */ - tot = L_add( L_add( acc, (Word32) density ), 1L ); + tot = L_add( L_add( acc, L_deposit_l( density ) ), 1L ); dec_freq = rc_decode_fx( &st_fx->BER_detect, hPVQ, tot ); @@ -577,7 +579,7 @@ static void densitySymbolIndexDecode_fx( tmp1 = L_mult0( tmp2, tmp2 ); tmp1 = L_add( tmp1, acc ); tmp2 = getSqrtWord32( tmp1 ); /* floor */ - if ( L_msu0( tmp1, tmp2, tmp2 ) != 0 ) + IF( L_msu0( tmp1, tmp2, tmp2 ) != 0 ) { tmp2 = add( tmp2, 1 ); /* convert to ceil */ } diff --git a/lib_dec/pvq_decode_fx.c b/lib_dec/pvq_decode_fx.c index ca8c8ed0a..5c97d8679 100644 --- a/lib_dec/pvq_decode_fx.c +++ b/lib_dec/pvq_decode_fx.c @@ -46,6 +46,8 @@ void pvq_decode_fx( { entry.lead_sign_ind = (Word16) rc_dec_bits_fx( st_fx, hPVQ, 1 ); entry.index = rc_dec_uniform_fx( st_fx, hPVQ, entry.size ); + move16(); + move32(); IF( st_fx->hHQ_core != NULL ) { @@ -66,6 +68,8 @@ void pvq_decode_fx( { entry.lead_sign_ind = (Word16) rc_dec_bits_fx( st_fx, hPVQ, 1 ); /* always a single sign bit */ entry.index = L_deposit_l( 0 ); + move16(); + move32(); } mpvq_decode_vec_fx( &entry, h_mem, y ); diff --git a/lib_dec/range_dec_fx.c b/lib_dec/range_dec_fx.c index e53e5cc58..d92e0d1d9 100644 --- a/lib_dec/range_dec_fx.c +++ b/lib_dec/range_dec_fx.c @@ -23,23 +23,26 @@ static Word16 rc_dec_read_fx( Decoder_State *st_fx, PVQ_DEC_HANDLE hPVQ ); void rc_dec_init_fx( Decoder_State *st_fx, /* i/o: Decoder State */ PVQ_DEC_HANDLE hPVQ, /* i/o: PVQ decoder handle */ - Word16 tot_bits /* i : Total bit budget */ + Word16 tot_bits /* i : Total bit budget Q0 */ ) { Word16 i; hPVQ->rc_low = L_deposit_l( 0 ); + move32(); hPVQ->rc_range = 0xffffffff; move32(); hPVQ->rc_num_bits = 0; move16(); hPVQ->rc_offset = add( tot_bits, st_fx->next_bit_pos ); + move16(); hPVQ->rc_end = hPVQ->rc_offset; move16(); FOR( i = 0; i < 4; i++ ) { hPVQ->rc_low = UL_addNsD( UL_lshl( hPVQ->rc_low, 8 ), UL_deposit_l( rc_dec_read_fx( st_fx, hPVQ ) ) ); + move32(); } } @@ -52,7 +55,7 @@ void rc_dec_init_fx( UWord32 rc_decode_fx( /* o : Decoded cumulative frequency */ Word16 *BER_detect, /* o : Bit error detection flag */ PVQ_DEC_HANDLE hPVQ, /* i/o: PVQ decoder handle */ - UWord32 tot /* i : Total cumulative frequency */ + UWord32 tot /* i : Total cumulative frequency Q0 */ ) { UWord32 inv, lsb, val, UL_tmp1, UL_tmp2; @@ -62,6 +65,7 @@ UWord32 rc_decode_fx( /* o : Decoded cumulative frequency inv = UL_inverse( tot, &exp ); Mpy_32_32_uu( hPVQ->rc_range, inv, &( hPVQ->rc_help ), &lsb ); /*0+exp-32*/ hPVQ->rc_help = UL_lshr( hPVQ->rc_help, sub( exp, 32 ) ); + move32(); exp_den = norm_ul( hPVQ->rc_help ); UL_tmp2 = UL_lshl( hPVQ->rc_help, exp_den ); @@ -76,7 +80,7 @@ UWord32 rc_decode_fx( /* o : Decoded cumulative frequency UL_tmp2 = UL_Mpy_32_32( UL_addNsD( val, 1 ), hPVQ->rc_help ); UL_tmp1 = UL_subNsD( hPVQ->rc_low, UL_tmp1 ); UL_tmp2 = UL_subNsD( hPVQ->rc_low, UL_tmp2 ); - if ( UL_tmp2 < UL_tmp1 ) + IF( LT_64( UL_tmp2, UL_tmp1 ) ) { val = UL_addNsD( val, 1 ); } @@ -108,13 +112,18 @@ void rc_dec_update_fx( { hPVQ->rc_low = UL_subNsD( hPVQ->rc_low, UL_Mpy_32_32( cum_freq, hPVQ->rc_help ) ); /*0+0*/ hPVQ->rc_range = UL_Mpy_32_32( hPVQ->rc_help, sym_freq ); + move32(); + move32(); - WHILE( hPVQ->rc_range < 1 << 24 ) + WHILE( LT_64( hPVQ->rc_range, 1 << 24 ) ) { L_sub( 0, 0 ); /* For comparision in while*/ hPVQ->rc_num_bits = add( hPVQ->rc_num_bits, 8 ); hPVQ->rc_low = UL_addNsD( UL_lshl( hPVQ->rc_low, 8 ), UL_deposit_l( rc_dec_read_fx( st_fx, hPVQ ) ) ); hPVQ->rc_range = UL_lshl( hPVQ->rc_range, 8 ); + move16(); + move32(); + move32(); } } @@ -133,17 +142,21 @@ Word32 rc_dec_bits_fx( /* i : Decoded value */ Word32 value; hPVQ->rc_num_bits = add( hPVQ->rc_num_bits, bits ); + move16(); IF( GT_16( bits, 16 ) ) { hPVQ->rc_offset = sub( hPVQ->rc_offset, sub( bits, 16 ) ); + move16(); value = UL_lshl( UL_deposit_l( get_indice( st_fx, hPVQ->rc_offset, sub( bits, 16 ) ) ), 16 ); hPVQ->rc_offset = sub( hPVQ->rc_offset, 16 ); + move16(); value = UL_or( value, UL_deposit_l( get_indice( st_fx, hPVQ->rc_offset, 16 ) ) ); } ELSE { hPVQ->rc_offset = sub( hPVQ->rc_offset, bits ); + move16(); value = UL_deposit_l( get_indice( st_fx, hPVQ->rc_offset, bits ) ); } @@ -164,7 +177,7 @@ UWord32 rc_dec_uniform_fx( /* i : Decoded value */ { UWord32 value; Word16 n; - n = sub( 32, norm_ul( tot - 1 ) ); + n = sub( 32, norm_ul( UL_subNsD( tot, 1 ) ) ); IF( LE_16( n, 8 ) ) { @@ -195,6 +208,7 @@ void rc_dec_finish_fx( ) { st_fx->next_bit_pos = hPVQ->rc_end; + move16(); } /*-------------------------------------------------------------------* diff --git a/lib_dec/rom_dec.c b/lib_dec/rom_dec.c index 8ae4a7462..a317678a4 100644 --- a/lib_dec/rom_dec.c +++ b/lib_dec/rom_dec.c @@ -49,11 +49,11 @@ #ifndef IVAS_FLOAT_FIXED const float h_low[5] = { -0.0125f, 0.1090f, 0.7813f, 0.1090f, -0.0125f }; #endif -const Word16 h_low_fx[5] = +const Word16 h_low_fx[5] = /* Q15 */ { -410, 3572, 25602, 3572, -410 }; -const Word16 inv_sqi[15] = +const Word16 inv_sqi[15] = /* Q15 */ { 8192, /* 1/4 */ 3641, /* 1/9 */ @@ -74,7 +74,7 @@ const Word16 inv_sqi[15] = /*-------------------------------------------------------------------* * index square used in fec_adapt_codebook *-------------------------------------------------------------------*/ -const Word16 sqi[15] = +const Word16 sqi[15] = /* Q0 */ { 4, /* 2 */ 9, /* 3 */ @@ -129,19 +129,19 @@ const float lsf_tab[LPC_SHB_ORDER] = 0.31293656f, 0.34594478f, 0.38072862f, 0.410051247f, 0.44525622f }; #endif -const Word16 lsf_tab_fx[LPC_SHB_ORDER] = +const Word16 lsf_tab_fx[LPC_SHB_ORDER] = /* Q15 */ { 2315, 3920, 5546, 6759, 7978, 10254, 11336, 12476, 13437, 14590 }; -const Word16 POW_ATT_TABLE0[OFF_FRAMES_LIMIT + 1] = +const Word16 POW_ATT_TABLE0[OFF_FRAMES_LIMIT + 1] = /* Q15 */ { 32767, 31293, 29885, 28540, 27255, 26029, 24857, 23738, 22670, 21650, 20675, 19745, 18856, 18007, 17197, 16423, 8211, 4106, 2053, 1026, 513, 257, 128, 64, 32, 16, 8, 4, 2, 1, 0 }; -const Word16 POW_ATT_TABLE1[OFF_FRAMES_LIMIT + 1] = +const Word16 POW_ATT_TABLE1[OFF_FRAMES_LIMIT + 1] = /* Q15 */ { 32767, 31656, 30581, 29543, 28540, 27571, 26635, 25731, 24857, 24013, 23198, 22410, 21650, 20915, 20205, 19519, 9759, 4880, 2440, 1220, @@ -150,7 +150,7 @@ const Word16 POW_ATT_TABLE1[OFF_FRAMES_LIMIT + 1] = /* frequency group start bins for transient analysis */ /* 125 375 750 1250 2000 4000 8000 16000 24000 */ const Word16 gw[LGW_MAX] = { 1, 3, 6, 10, 16, 32, 64, 128, 192 }; -const Word16 gw_fx[LGW_MAX] = { 1, 3, 6, 10, 16, 32, 64, 128, 192 }; /* frequency group start bins for transient analysis */ +const Word16 gw_fx[LGW_MAX] = { 1, 3, 6, 10, 16, 32, 64, 128, 192 }; /* Q0 frequency group start bins for transient analysis */ const Word16 gw_len_inv_fx[LGW_MAX - 1] = /* Q15 */ { @@ -226,7 +226,7 @@ const float w_hamm16k_2[L_TRANA16k/2] = }; #endif -const Word16 w_hamm48k_2_fx[L_TRANA48k / 2] = +const Word16 w_hamm48k_2_fx[L_TRANA48k / 2] = /* Q15 */ { 2621, 2623, 2630, 2640, 2654, 2672, 2694, 2721, 2751, 2785, 2824, 2866, 2913, 2963, 3017, 3076, @@ -254,7 +254,7 @@ const Word16 w_hamm48k_2_fx[L_TRANA48k / 2] = 32654, 32682, 32707, 32727, 32743, 32755, 32763, 32767 }; -const Word16 w_hamm32k_2_fx[L_TRANA32k / 2] = +const Word16 w_hamm32k_2_fx[L_TRANA32k / 2] = /* Q15 */ { 2621, 2626, 2640, 2663, 2695, 2736, 2786, 2845, 2913, 2991, 3077, 3172, 3276, 3388, 3509, 3639, @@ -274,7 +274,7 @@ const Word16 w_hamm32k_2_fx[L_TRANA32k / 2] = 32511, 32575, 32630, 32675, 32712, 32739, 32758, 32767 }; -const Word16 w_hamm16k_2_fx[L_TRANA16k / 2] = +const Word16 w_hamm16k_2_fx[L_TRANA16k / 2] = /* Q15 */ { 2621, 2640, 2695, 2787, 2916, 3080, 3281, 3516, 3787, 4091, 4429, 4799, 5201, 5633, 6095, 6585, @@ -285,7 +285,7 @@ const Word16 w_hamm16k_2_fx[L_TRANA16k / 2] = 28549, 29053, 29529, 29976, 30393, 30780, 31134, 31455, 31742, 31995, 32213, 32396, 32543, 32653, 32727, 32763 }; - +#ifndef IVAS_FLOAT_FIXED const float w_hamm_sana48k_2[L_PROT_HAMM_LEN2_48k] = { 0.080000000000000f, 0.080027462973758f, 0.080109848615839f, 0.080247147089046f, 0.080439341999361f, 0.080686410397899f, 0.080988322783646f, 0.081345043106986f, @@ -325,7 +325,8 @@ const float w_hamm_sana48k_2[L_PROT_HAMM_LEN2_48k] = 0.993417713086533f, 0.994237922201026f, 0.995003893384487f, 0.995715535176712f, 0.996372762604660f, 0.996975497192592f, 0.997523666971448f, 0.998017206487434f, 0.998456056809844f, 0.998840165538090f, 0.999169486807964f, 0.999443981297112f, 0.999663616229731f, 0.999828365380479f, 0.999938209077610f, 0.999993134205322f }; -const Word16 w_hamm_sana48k_2_fx[288] = +#endif +const Word16 w_hamm_sana48k_2_fx[288] = /* Q15 */ { 2621, 2622, 2625, 2630, 2636, 2644, 2654, 2666, 2679, 2694, 2711, 2730, 2751, 2773, 2797, 2823, @@ -364,6 +365,7 @@ const Word16 w_hamm_sana48k_2_fx[288] = 32552, 32579, 32604, 32628, 32649, 32669, 32687, 32703, 32717, 32730, 32741, 32750, 32757, 32762, 32766, 32767 }; +#ifndef IVAS_FLOAT_FIXED const float w_hamm_sana32k_2[L_PROT_HAMM_LEN2_32k] = { 0.080000000000000f, 0.080061898522781f, 0.080247577432747f, 0.080556986759243f, 0.080990043232791f, 0.081546630307495f, 0.082226598192408f, 0.083029763891845f, @@ -391,7 +393,7 @@ const float w_hamm_sana32k_2[L_PROT_HAMM_LEN2_32k] = 0.985208504353495f, 0.987046796215483f, 0.988764777050081f, 0.990361984507393f, 0.991837988740540f, 0.993192392521341f, 0.994424831347216f, 0.995534973539285f, 0.996522520331626f, 0.997387205951684f, 0.998128797691797f, 0.998747095971820f, 0.999241934392838f, 0.999613179781951f, 0.999860732228111f, 0.999984525109009f }; - +#endif const Word16 w_hamm_sana32k_2_fx[L_PROT_HAMM_LEN2_32k] = /* Q15 */ { 2621, 2623, 2630, 2640, 2654, 2672, 2694, 2721, @@ -419,7 +421,7 @@ const Word16 w_hamm_sana32k_2_fx[L_PROT_HAMM_LEN2_32k] = /* Q15 */ 32283, 32344, 32400, 32452, 32501, 32545, 32585, 32622, 32654, 32682, 32707, 32727, 32743, 32755, 32763, 32767 }; - +#ifndef IVAS_FLOAT_FIXED const float w_hamm_sana16k_2[L_PROT_HAMM_LEN2_16k] = { 0.080000000000000f, 0.080248875229243f, 0.080995231617495f, 0.082238261557724f, 0.083976620009229f, 0.086208425953062f, 0.088931264427414f, 0.092142189140766f, @@ -435,7 +437,7 @@ const float w_hamm_sana16k_2[L_PROT_HAMM_LEN2_16k] = 0.941486723514159f, 0.948653981707932f, 0.955379049234843f, 0.961654649126531f, 0.967473990768381f, 0.972830777247415f, 0.977719212165966f, 0.982134005913770f, 0.986070381391670f, 0.989524079180756f, 0.992491362151336f, 0.994969019506760f, 0.996954370257714f, 0.998445266123226f, 0.999440093855253f, 0.999937776984316f }; - +#endif const Word16 w_hamm_sana16k_2_fx[L_PROT_HAMM_LEN2_16k] = /* Q15 */ { 2621, 2630, 2654, 2695, 2752, 2825, 2914, 3019, @@ -471,8 +473,10 @@ const Word16 inv_tbl_2n_minus1[] = { -1, -1, /* Bits = 0 and 1 are not used */ /* er_dec_tcx.c */ +#ifndef IVAS_FLOAT_FIXED const float h_high3_32_flt[L_FIR_FER2] = {-0.0517f, -0.0587f, -0.0820f, -0.1024f, -0.1164f, 0.8786f, -0.1164f, -0.1024f, -0.0820f, -0.0587f, -0.0517f}; const float h_high3_16_flt[L_FIR_FER2] = { 0.f, -0.0205f, -0.0651f, -0.1256f, -0.1792f, 0.8028f, -0.1792f, -0.1256f, -0.0651f, -0.0205f, 0.f }; +#endif const Word16 h_high3_32[L_FIR_FER2] = { -1694/*-0.0517f Q15*/, -1923/*-0.0587f Q15*/, -2687/*-0.0820f Q15*/, -3355/*-0.1024f Q15*/, -3814/*-0.1164f Q15*/, 28790/*0.8786f Q15*/, -3814/*-0.1164f Q15*/, -3355/*-0.1024f Q15*/, -2687/*-0.0820f Q15*/, -1923/*-0.0587f Q15*/, -1694/*-0.0517f Q15*/ }; const Word16 h_high3_16[L_FIR_FER2] = { 0/* 0.f Q15*/, -672/*-0.0205f Q15*/, -2133/*-0.0651f Q15*/, -4116/*-0.1256f Q15*/, -5872/*-0.1792f Q15*/, 26306/*0.8028f Q15*/, -5872/*-0.1792f Q15*/, -4116/*-0.1256f Q15*/, -2133/*-0.0651f Q15*/, -672/*-0.0205f Q15*/, 0/* 0.f Q15*/ }; const Word16 T_256DIV_L_Frame[] = diff --git a/lib_dec/rom_dec.h b/lib_dec/rom_dec.h index 908a7f289..44f45905e 100644 --- a/lib_dec/rom_dec.h +++ b/lib_dec/rom_dec.h @@ -44,52 +44,55 @@ #ifndef IVAS_FLOAT_FIXED extern const float h_low[]; /* LP filter for filtering periodic part of excitation in artificial onset construction after FEC */ #endif -extern const Word16 h_low_fx[5]; -extern const Word16 inv_sqi[15]; -extern const Word16 sqi[15]; -extern const int16_t mult_avq_tab[]; -extern const int16_t shift_avq_tab[]; - -extern const int16_t hntable[55]; -extern const int16_t hetable[57]; -extern const int16_t hestable[15]; +extern const Word16 h_low_fx[5]; // Q15 +extern const Word16 inv_sqi[15]; // Q15 +extern const Word16 sqi[15]; // Q0 +extern const Word16 mult_avq_tab[]; // Q0 +extern const Word16 shift_avq_tab[]; // Q0 + +extern const Word16 hntable[55]; +extern const Word16 hetable[57]; +extern const Word16 hestable[15]; #ifndef IVAS_FLOAT_FIXED extern const float lsf_tab[LPC_SHB_ORDER]; #endif -extern const Word16 lsf_tab_fx[LPC_SHB_ORDER]; +extern const Word16 lsf_tab_fx[LPC_SHB_ORDER]; // Q15 -extern const Word16 POW_ATT_TABLE0[]; -extern const Word16 POW_ATT_TABLE1[]; -extern const int16_t gw[LGW_MAX]; -extern const Word16 gw_fx[LGW_MAX]; -extern const Word16 gw_len_inv_fx[LGW_MAX - 1]; +extern const Word16 POW_ATT_TABLE0[]; // Q15 +extern const Word16 POW_ATT_TABLE1[]; // Q15 +extern const Word16 gw[LGW_MAX]; // Q0 +extern const Word16 gw_fx[LGW_MAX]; // Q0 +extern const Word16 gw_len_inv_fx[LGW_MAX - 1]; // Q15 extern const Word16 GR_POW_HEADROOM[]; -extern const int16_t ivas_gwlpr[LGW_MAX]; +extern const Word16 ivas_gwlpr[LGW_MAX]; #ifndef IVAS_FLOAT_FIXED extern const float w_hamm48k_2[L_TRANA48k / 2]; extern const float w_hamm32k_2[L_TRANA32k / 2]; extern const float w_hamm16k_2[L_TRANA16k / 2]; #endif -extern const Word16 w_hamm48k_2_fx[]; -extern const Word16 w_hamm32k_2_fx[]; -extern const Word16 w_hamm16k_2_fx[]; - +extern const Word16 w_hamm48k_2_fx[]; // Q15 +extern const Word16 w_hamm32k_2_fx[]; // Q15 +extern const Word16 w_hamm16k_2_fx[]; // Q15 +#ifndef IVAS_FLOAT_FIXED extern const float w_hamm_sana32k_2[L_PROT_HAMM_LEN2_32k]; extern const float w_hamm_sana16k_2[L_PROT_HAMM_LEN2_16k]; extern const float w_hamm_sana48k_2[L_PROT_HAMM_LEN2_48k]; +#endif extern const Word16 swb_hr_inv_frm_len[4]; /* in Q19 */ extern const Word16 inv_tbl_2n_minus1[]; -extern const Word16 w_hamm_sana48k_2_fx[]; -extern const Word16 w_hamm_sana32k_2_fx[]; -extern const Word16 w_hamm_sana16k_2_fx[]; +extern const Word16 w_hamm_sana48k_2_fx[]; // Q15 +extern const Word16 w_hamm_sana32k_2_fx[]; // Q15 +extern const Word16 w_hamm_sana16k_2_fx[]; // Q15 +#ifndef IVAS_FLOAT_FIXED extern const float h_high3_32_flt[L_FIR_FER2]; extern const float h_high3_16_flt[L_FIR_FER2]; -extern const Word16 h_high3_32[L_FIR_FER2]; -extern const Word16 h_high3_16[L_FIR_FER2]; -extern const Word16 T_256DIV_L_Frame[]; +#endif +extern const Word16 h_high3_32[L_FIR_FER2]; // Q15 +extern const Word16 h_high3_16[L_FIR_FER2]; // Q15 +extern const Word16 T_256DIV_L_Frame[]; // Q0 -extern const Word16 pcmdsp_window_hann_960[960]; -extern const Word16 pcmdsp_window_hann_640[640]; +extern const Word16 pcmdsp_window_hann_960[960]; // Q15 +extern const Word16 pcmdsp_window_hann_640[640]; // Q15 #endif diff --git a/lib_dec/rst_dec_fx.c b/lib_dec/rst_dec_fx.c index f348b56bc..4a43c7fd3 100644 --- a/lib_dec/rst_dec_fx.c +++ b/lib_dec/rst_dec_fx.c @@ -16,9 +16,9 @@ *----------------------------------------------------------------------------------*/ void CNG_reset_dec_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - Word16 *pitch_buf, /* o : floating pitch for each subframe */ - Word16 *voice_factors /* o : voicing factors */ + Decoder_State *st_fx, /* i/o: decoder state structure */ + Word16 *pitch_buf, /* o : floating pitch for each subframe Q6 */ + Word16 *voice_factors /* o : voicing factors Q15 */ ) { Word16 tmp, exp; @@ -44,12 +44,12 @@ void CNG_reset_dec_fx( move16(); /* LP-filtered pitch gain set to 0 */ - st_fx->lp_gainp_fx = 0; + st_fx->lp_gainp_fx = 0; // Q14 move16(); /* convert CNG energy into CNG gain for ACELP FEC */ /* st->lp_gainc = sqrt( st->lp_ener ); */ - st_fx->lp_gainc_fx = 0; + st_fx->lp_gainc_fx = 0; // Q3 move16(); IF( st_fx->lp_ener_fx != 0 ) diff --git a/lib_dec/stat_dec.h b/lib_dec/stat_dec.h index b6d153746..9304dc325 100644 --- a/lib_dec/stat_dec.h +++ b/lib_dec/stat_dec.h @@ -130,8 +130,8 @@ typedef struct #endif Word32 msCurrentMinSubWindow[NPART_SHAPING]; - int16_t msLocalMinFlag[NPART_SHAPING]; - int16_t msNewMinFlag[NPART_SHAPING]; + Word16 msLocalMinFlag[NPART_SHAPING]; + Word16 msNewMinFlag[NPART_SHAPING]; #ifndef IVAS_FLOAT_FIXED float msPsdFirstMoment_float[NPART_SHAPING]; #endif @@ -159,10 +159,10 @@ typedef struct #endif Word16 msLogNoiseEst[NPART_SHAPING]; - int16_t npart_shaping; /* Number of partitions */ - int16_t nFFTpart_shaping; /* Number of hybrid spectral partitions */ - int16_t part_shaping[NPART_SHAPING]; /* Partition upper boundaries (band indices starting from 0) */ - int16_t midband_shaping[NPART_SHAPING]; /* Central band of each partition */ + Word16 npart_shaping; /* Number of partitions */ + Word16 nFFTpart_shaping; /* Number of hybrid spectral partitions */ + Word16 part_shaping[NPART_SHAPING]; /* Partition upper boundaries (band indices starting from 0) */ + Word16 midband_shaping[NPART_SHAPING]; /* Central band of each partition */ Word16 psize_shaping[NPART_SHAPING]; /* Partition sizes */ @@ -194,8 +194,8 @@ typedef struct #endif Word32 msPeriodog_ST_fx[NPART_SHAPING]; /* stereo CNA - short-term periodogram */ Word16 msPeriodog_ST_exp; /* exponent of stereo CNA - short-term periodogram */ - int16_t ms_last_inactive_bwidth; /* stereo CNA - bandwidth from the last inactive frame */ - int16_t ms_cnt_bw_up; /* stereo CNA - downward counter of frames since the last NB->WB switch */ + Word16 ms_last_inactive_bwidth; /* stereo CNA - bandwidth from the last inactive frame */ + Word16 ms_cnt_bw_up; /* stereo CNA - downward counter of frames since the last NB->WB switch */ #ifndef IVAS_FLOAT_FIXED float cna_LR_LT; /* stereo CNA - long-term L/R correlation factor calculated on stereo upmix */ #endif @@ -208,20 +208,20 @@ typedef struct float cna_g_state[STEREO_DFT_BAND_MAX]; /* stereo CNA - side gains from the last inactive frame */ float cna_cm[STEREO_DFT_BAND_MAX]; /* stereo CNA - coherence from the last inactive frame */ #endif - int16_t first_cna_noise_updated; /* stereo CNA - flag indicating that comfort noise has been properly initialized during warmup */ - int16_t first_cna_noise_update_cnt; /* stereo CNA - counter of CN initialization frames */ - int16_t cna_nbands; /* stereo CNA - number of frequency bands used by the CNA in DFT stereo mode */ + Word16 first_cna_noise_updated; /* stereo CNA - flag indicating that comfort noise has been properly initialized during warmup */ + Word16 first_cna_noise_update_cnt; /* stereo CNA - counter of CN initialization frames */ + Word16 cna_nbands; /* stereo CNA - number of frequency bands used by the CNA in DFT stereo mode */ - int16_t cna_band_limits[STEREO_DFT_BAND_MAX + 1]; /* stereo CNA - band limits used by the CNA in DFT stereo mode */ + Word16 cna_band_limits[STEREO_DFT_BAND_MAX + 1]; /* stereo CNA - band limits used by the CNA in DFT stereo mode */ #ifndef IVAS_FLOAT_FIXED float cna_act_fact; /* stereo CNA - long-term signal activity factor (0-1) */ #endif #ifndef IVAS_FLOAT_FIXED float cna_rescale_fact; /* stereo CNA - CN energy re-scaling factor to maintain decoded energy */ #endif - int16_t cna_seed; /* stereo CNA - seed for random CN generator */ + Word16 cna_seed; /* stereo CNA - seed for random CN generator */ - int16_t flag_dtx_mode; + Word16 flag_dtx_mode; #ifndef IVAS_FLOAT_FIXED float lp_speech_float; #endif @@ -239,7 +239,7 @@ typedef struct #endif Word16 msPeriodogBuf[MSBUFLEN * NPART_SHAPING]; - int16_t msPeriodogBufPtr; + Word16 msPeriodogBufPtr; Word32 smoothed_psd_fx[L_FRAME16k]; /* stereo CNA - periodogram smoothed with IIR filter */ #ifdef IVAS_FLOAT_FIXED @@ -258,17 +258,17 @@ typedef struct typedef struct { - int16_t L_frameTCX; + Word16 L_frameTCX; Word16 FrameSize; - int16_t Pitch; + Word16 Pitch; Word16 Pitch_fx; - int16_t T_bfi; + Word16 T_bfi; Word8 T_bfi_fx; - int16_t Transient[MAX_POST_LEN]; - int16_t TCX_Tonality[DEC_STATE_LEN]; + Word16 Transient[MAX_POST_LEN]; + Word16 TCX_Tonality[DEC_STATE_LEN]; #ifndef IVAS_FLOAT_FIXED float outx_new_n1; #endif @@ -300,7 +300,7 @@ typedef struct #endif Word32 ener_fx; - int16_t zp; + Word16 zp; Word16 zp_fx; #ifndef IVAS_FLOAT_FIXED float recovery_gain_float; @@ -311,14 +311,14 @@ typedef struct #endif Word16 step_concealgain_fx; - int16_t concealment_method; + Word16 concealment_method; - int16_t subframe; + Word16 subframe; Word16 subframe_fx; - int16_t nbLostCmpt; + Word16 nbLostCmpt; - int16_t seed; + Word16 seed; } T_PLCInfo, *T_PLCInfo_HANDLE; @@ -329,8 +329,8 @@ typedef struct typedef struct { - uint16_t nSamples; - uint16_t nSamplesCore; + UWord16 nSamples; + UWord16 nSamplesCore; Float32 *spectralData_float; Word16 *spectralData; @@ -345,17 +345,17 @@ typedef struct Word16 scaleFactors_max_e; Word16 gain_tcx_exp; - int16_t blockIsValid; - int16_t blockIsConcealed; - int16_t tonalConcealmentActive; + Word16 blockIsValid; + Word16 blockIsConcealed; + Word16 tonalConcealmentActive; } blockData; typedef struct { - uint16_t numIndexes; - uint16_t indexOfTonalPeak[MAX_NUMBER_OF_IDX]; - uint16_t lowerIndex[MAX_NUMBER_OF_IDX]; - uint16_t upperIndex[MAX_NUMBER_OF_IDX]; + UWord16 numIndexes; + UWord16 indexOfTonalPeak[MAX_NUMBER_OF_IDX]; + UWord16 lowerIndex[MAX_NUMBER_OF_IDX]; + UWord16 upperIndex[MAX_NUMBER_OF_IDX]; Word16 phaseDiff[MAX_NUMBER_OF_IDX]; // Q12 /* This one can be stored with 16 bits in range 0..2*PI */ @@ -371,10 +371,10 @@ typedef struct tonalmdctconceal { TCX_config *tcx_cfg; void *pMDSTData; - int16_t nSamples; - int16_t nSamplesCore; - int16_t nNonZeroSamples; - int16_t nScaleFactors; + Word16 nSamples; + Word16 nSamplesCore; + Word16 nNonZeroSamples; + Word16 nScaleFactors; #ifndef IVAS_FLOAT_FIXED float lastPitchLag_float; @@ -452,20 +452,20 @@ typedef struct tonalmdctconceal typedef struct { - int16_t bitsRead; /* after a call bitsRead contains the number of bits consumed by the decoder */ - int16_t prev[64]; /* no more than 64 SCFs for the IGF energy envelope of one block */ - int16_t scfCountLongBlock[IGF_NOF_GRIDS]; - int16_t t; - int32_t bitrate; - const uint16_t *cf_se00; - const uint16_t *cf_se01; - int16_t cf_off_se01; - const uint16_t *cf_se02; - const int16_t *cf_off_se02; - const uint16_t *cf_se10; - int16_t cf_off_se10; - const uint16_t *cf_se11; - const int16_t *cf_off_se11; + Word16 bitsRead; /* after a call bitsRead contains the number of bits consumed by the decoder */ + Word16 prev[64]; /* no more than 64 SCFs for the IGF energy envelope of one block */ + Word16 scfCountLongBlock[IGF_NOF_GRIDS]; + Word16 t; + Word32 bitrate; + const UWord16 *cf_se00; + const UWord16 *cf_se01; + Word16 cf_off_se01; + const UWord16 *cf_se02; + const Word16 *cf_off_se02; + const UWord16 *cf_se10; + Word16 cf_off_se10; + const UWord16 *cf_se11; + const Word16 *cf_off_se11; Tastat acState; } IGFSCFDEC_INSTANCE, *IGFSCFDEC_INSTANCE_HANDLE; @@ -488,11 +488,11 @@ typedef struct igfdec_private_data_struct Word16 igf_pN_e[IGF_MAX_SFB]; - int16_t igf_curr[IGF_MAX_SFB]; /* current igf energies */ - int16_t igf_prev[IGF_MAX_SFB]; /* needed for concealment or indepflag==0 */ - int16_t igf_curr_subframe[IGF_MAX_SUBFRAMES][IGF_TRANS_FAK][IGF_MAX_SFB]; /* current igf energies per subframe*/ - int16_t igf_prev_subframe[IGF_MAX_SUBFRAMES][IGF_MAX_SFB]; /* needed for concealment or indepflag==0 */ - int16_t igf_flatteningTrigger_subframe[IGF_MAX_SUBFRAMES]; + Word16 igf_curr[IGF_MAX_SFB]; /* current igf energies */ + Word16 igf_prev[IGF_MAX_SFB]; /* needed for concealment or indepflag==0 */ + Word16 igf_curr_subframe[IGF_MAX_SUBFRAMES][IGF_TRANS_FAK][IGF_MAX_SFB]; /* current igf energies per subframe*/ + Word16 igf_prev_subframe[IGF_MAX_SUBFRAMES][IGF_MAX_SFB]; /* needed for concealment or indepflag==0 */ + Word16 igf_flatteningTrigger_subframe[IGF_MAX_SUBFRAMES]; /* spectral whitening: */ #ifndef IVAS_FLOAT_FIXED @@ -503,19 +503,19 @@ typedef struct igfdec_private_data_struct Word32 pSpecFlatBuf_fx[IGF_START_MX]; /* Q31 | MDCT spectrum before LPC shaping */ Word16 pSpecFlat_exp; - int16_t restrict_hopsize; + Word16 restrict_hopsize; - int16_t currWhiteningLevel[IGF_MAX_TILES]; - int16_t prevWhiteningLevel[IGF_MAX_TILES]; /* needed for concealment */ - int16_t currWhiteningLevel_subframe[IGF_MAX_SUBFRAMES][IGF_MAX_TILES]; - int16_t prevWhiteningLevel_subframe[IGF_MAX_SUBFRAMES][IGF_MAX_TILES]; /* needed for concealment */ + Word16 currWhiteningLevel[IGF_MAX_TILES]; + Word16 prevWhiteningLevel[IGF_MAX_TILES]; /* needed for concealment */ + Word16 currWhiteningLevel_subframe[IGF_MAX_SUBFRAMES][IGF_MAX_TILES]; + Word16 prevWhiteningLevel_subframe[IGF_MAX_SUBFRAMES][IGF_MAX_TILES]; /* needed for concealment */ #ifndef IVAS_FLOAT_FIXED float totalNoiseNrg_float; #endif Word32 totalNoiseNrg; Word16 totalNoiseNrg_exp; - int16_t n_noise_bands; + Word16 n_noise_bands; Word16 headroom_TCX_noise_white; Word16 headroom_TCX_noise; @@ -524,29 +524,29 @@ typedef struct igfdec_private_data_struct #endif Word32 totalNoiseNrg_off; Word16 totalNoiseNrg_off_exp; - int16_t n_noise_bands_off; + Word16 n_noise_bands_off; /* IGF SCF decoding: */ IGFSCFDEC_INSTANCE hArithSCFdec; /* concealment: */ - int16_t frameLossCounter; + Word16 frameLossCounter; } IGFDEC_PRIVATE_DATA, *IGF_DEC_PRIVATE_DATA_HANDLE; typedef struct igfdec_instance_struct { - int16_t isIGFActive; - int16_t infoIGFAllZero; - int16_t infoIGFStopLine; - int16_t infoIGFStartLine; - int16_t infoIGFStopFreq; - int16_t infoIGFStartFreq; + Word16 isIGFActive; + Word16 infoIGFAllZero; + Word16 infoIGFStopLine; + Word16 infoIGFStartLine; + Word16 infoIGFStopFreq; + Word16 infoIGFStartFreq; Word16 *infoTCXNoise_ptr; Word16 infoTCXNoise_evs[IGF_START_MX]; - int16_t *flag_sparse; - int16_t flag_sparseBuf[N_MAX_TCX - IGF_START_MN]; + Word16 *flag_sparse; + Word16 flag_sparseBuf[N_MAX_TCX - IGF_START_MN]; #ifndef IVAS_FLOAT_FIXED float *virtualSpec_float; // needed in MCT path float virtualSpecBuf[N_MAX_TCX - IGF_START_MN]; @@ -555,7 +555,7 @@ typedef struct igfdec_instance_struct Word32 virtualSpec[N_MAX_TCX - IGF_START_MN]; /* Q31 | buffer for temp flattening */ Word16 virtualSpec_e; /* | exponent of virtualSpec */ - int16_t flatteningTrigger; + Word16 flatteningTrigger; IGFDEC_PRIVATE_DATA igfData; } IGFDEC_INSTANCE, *IGF_DEC_INSTANCE_HANDLE; @@ -589,14 +589,14 @@ typedef struct tec_dec_structure typedef struct tcx_ltp_dec_structure { /* TCX-LTP */ - int16_t tcxltp; + Word16 tcxltp; #ifndef IVAS_FLOAT_FIXED float tcxltp_gain_float; #endif Word16 tcxltp_gain; /* Q15 */ - int16_t tcxltp_pitch_int; - int16_t tcxltp_pitch_fr; + Word16 tcxltp_pitch_int; + Word16 tcxltp_pitch_fr; #ifndef IVAS_FLOAT_FIXED float tcxltp_mem_in_float[TCXLTP_MAX_DELAY]; #endif @@ -615,15 +615,15 @@ typedef struct tcx_ltp_dec_structure #endif - int16_t tcxltp_pitch_int_post_prev; - int16_t tcxltp_pitch_fr_post_prev; + Word16 tcxltp_pitch_int_post_prev; + Word16 tcxltp_pitch_fr_post_prev; #ifndef IVAS_FLOAT_FIXED float tcxltp_gain_post_prev_float; #endif // #ifndef IVAS_FLOAT_FIXED Word16 tcxltp_gain_post_prev; - int16_t tcxltp_filt_idx_prev; + Word16 tcxltp_filt_idx_prev; } TCX_LTP_DEC_DATA, *TCX_LTP_DEC_HANDLE; @@ -634,8 +634,8 @@ typedef struct tcx_ltp_dec_structure typedef struct tcx_dec_structure { - int16_t enableTcxLpc; /* global toggle for the TCX LPC quantizer */ - int16_t envWeighted; /* are is{p,f}_old[] weighted or not? */ + Word16 enableTcxLpc; /* global toggle for the TCX LPC quantizer */ + Word16 envWeighted; /* are is{p,f}_old[] weighted or not? */ /* tonal PLC */ #ifndef IVAS_FLOAT_FIXED @@ -650,20 +650,20 @@ typedef struct tcx_dec_structure #endif Word16 tcxltp_last_gain_unmodified; /* Q15 */ - int16_t tcx_hm_LtpPitchLag; - int16_t tcx_lpc_shaped_ari; + Word16 tcx_hm_LtpPitchLag; + Word16 tcx_lpc_shaped_ari; - int16_t pit_min_TCX; - int16_t pit_max_TCX; + Word16 pit_min_TCX; + Word16 pit_max_TCX; - int16_t L_frameTCX; + Word16 L_frameTCX; #ifndef IVAS_FLOAT_FIXED float old_excFB[L_FRAME48k]; /* old excitation FB */ #endif Word16 old_excFB_fx[L_FRAME48k]; /* old excitation FB */ - int16_t old_synth_len; - int16_t old_synth_lenFB; + Word16 old_synth_len; + Word16 old_synth_lenFB; #ifndef IVAS_FLOAT_FIXED float old_synth_float[OLD_SYNTH_INTERNAL_DEC]; /* synthesis memory */ #endif @@ -716,25 +716,25 @@ typedef struct tcx_dec_structure /*TCX resisual Q*/ - int16_t resQBits[NB_DIV]; /* number of bits read for the residual Quantization in TCX*/ + Word16 resQBits[NB_DIV]; /* number of bits read for the residual Quantization in TCX*/ /* PLC */ - int16_t noise_filling_index[NB_DIV]; /* PLC - last decoded noise filling index */ - int16_t tnsActive[NB_DIV]; + Word16 noise_filling_index[NB_DIV]; /* PLC - last decoded noise filling index */ + Word16 tnsActive[NB_DIV]; #ifndef IVAS_FLOAT_FIXED float ltpGainMemory[N_LTP_GAIN_MEMS]; /* for smoothing noiseTransWidth */ #endif Word16 ltpGainMemory_fx[N_LTP_GAIN_MEMS]; /* Q15 */ - uint16_t kernel_type[2]; /* transform kernel type in each subframe (MDCT or MDST) */ + UWord16 kernel_type[2]; /* transform kernel type in each subframe (MDCT or MDST) */ - int16_t prev_widow_left_rect; + Word16 prev_widow_left_rect; /* state variables for the minimum statistics used for PLC */ #ifndef IVAS_FLOAT_FIXED float CngLevelBackgroundTrace_bfi; /* PLC - long term gain estimate for background level, used for PLC fade out */ float NoiseLevelMemory_bfi[PLC_MIN_STAT_BUFF_SIZE]; #endif - int16_t NoiseLevelIndex_bfi; - int16_t CurrLevelIndex_bfi; + Word16 NoiseLevelIndex_bfi; + Word16 CurrLevelIndex_bfi; Word16 conCngLevelBackgroundTrace; /* Q15 long term gain estimate for background level, used for PLC fade out */ Word16 conCngLevelBackgroundTrace_e; @@ -774,7 +774,7 @@ typedef struct tcx_dec_structure #endif Word16 stepCompensate, stepCompensate_e; - int16_t tcxConceal_recalc_exc; + Word16 tcxConceal_recalc_exc; #ifndef IVAS_FLOAT_FIXED float cummulative_damping_tcx_float; #endif @@ -790,18 +790,18 @@ typedef struct tcx_dec_structure typedef struct gsc_dec_structure { - int16_t seed_tcx; /* AC mode (GSC) - seed for noise fill */ + Word16 seed_tcx; /* AC mode (GSC) - seed for noise fill */ - int16_t cor_strong_limit; /* AC mode (GSC) - Indicator about high spectral correlation per band */ - // Word16 cor_strong_limit; /* AC mode (GSC) - Indicator about high spectral correlation per band */ + Word16 cor_strong_limit; /* AC mode (GSC) - Indicator about high spectral correlation per band */ + // Word16 cor_strong_limit; /* AC mode (GSC) - Indicator about high spectral correlation per band */ #ifndef IVAS_FLOAT_FIXED float old_y_gain[MBANDS_GN16k]; /* AC mode (GSC) - AR mem for low rate gain quantization */ #endif Word16 old_y_gain_fx[MBANDS_GN16k]; /* AC mode (GSC) - AR mem for low rate gain quantization */ - int16_t noise_lev; /* AC mode (GSC) - noise level */ - // Word16 noise_lev; /* AC mode (GSC) - noise level Q0*/ + Word16 noise_lev; /* AC mode (GSC) - noise level */ + // Word16 noise_lev; /* AC mode (GSC) - noise level Q0*/ #ifndef IVAS_FLOAT_FIXED float lt_ener_per_band[MBANDS_GN16k]; @@ -818,8 +818,8 @@ typedef struct gsc_dec_structure #endif Word16 Last_GSC_spectrum_fx[L_FRAME16k]; /* AC mode (GSC) - Last good GSC spectrum */ - int16_t Last_GSC_pit_band_idx; /* AC mode (GSC) - Last pitch band index */ - // Word16 Last_GSC_pit_band_idx; /* AC mode (GSC) - Last pitch band index Q0*/ + Word16 Last_GSC_pit_band_idx; /* AC mode (GSC) - Last pitch band index */ + // Word16 Last_GSC_pit_band_idx; /* AC mode (GSC) - Last pitch band index Q0*/ #ifndef IVAS_FLOAT_FIXED float last_exc_dct_in[L_FRAME16k]; /* AC mode (GSC) - previous excitation */ @@ -831,8 +831,8 @@ typedef struct gsc_dec_structure #endif Word16 last_ener_fx; /* AC mode (GSC) - previous energy */ - int16_t last_bitallocation_band[6]; /* AC mode (GSC) - previous bit allocation of each band */ - // Word16 last_bitallocation_band[6]; /* AC mode (GSC) - previous bit allocation of each band */ + Word16 last_bitallocation_band[6]; /* AC mode (GSC) - previous bit allocation of each band */ + // Word16 last_bitallocation_band[6]; /* AC mode (GSC) - previous bit allocation of each band */ } GSC_DEC_DATA, *GSC_DEC_HANDLE; @@ -869,11 +869,11 @@ typedef struct ld_music_postfilt_structure #endif Word16 LDm_mem_etot_fx; /* LD music post-filter - total energy memory */ - int16_t LDm_last_music_flag; /* LD music post-filter - last music flag */ + Word16 LDm_last_music_flag; /* LD music post-filter - last music flag */ - int16_t LDm_nb_thr_1; /* LD music post-filter - number of consecutive frames of level 1 */ + Word16 LDm_nb_thr_1; /* LD music post-filter - number of consecutive frames of level 1 */ - int16_t LDm_nb_thr_3; + Word16 LDm_nb_thr_3; #ifndef IVAS_FLOAT_FIXED float dct_post_old_exc[DCT_L_POST - OFFSET2]; @@ -914,7 +914,7 @@ typedef struct ld_music_postfilt_structure #endif Word16 filt_lfE_fx[DCT_L_POST]; - int16_t last_nonfull_music; + Word16 last_nonfull_music; Word16 Old_ener_Q; /* Old energy scaling factor */ @@ -942,10 +942,10 @@ typedef struct bass_postfilt_structure #endif Word16 pst_lp_ener_fx; /* Bass post-filter - long-term energy Q8*/ - int16_t Track_on_hist[L_TRACK_HIST]; /* Bass post-filter - History of half frame usage */ + Word16 Track_on_hist[L_TRACK_HIST]; /* Bass post-filter - History of half frame usage */ - int16_t vibrato_hist[L_TRACK_HIST]; /* Bass post-filter - History of frames declared as vibrato */ - // Word16 vibrato_hist[L_TRACK_HIST]; /* Bass post-filter - History of frames declared as vibrato */ + Word16 vibrato_hist[L_TRACK_HIST]; /* Bass post-filter - History of frames declared as vibrato */ + // Word16 vibrato_hist[L_TRACK_HIST]; /* Bass post-filter - History of frames declared as vibrato */ #ifndef IVAS_FLOAT_FIXED float psf_att; /* Bass post-filter - post filter attenuation factor */ #endif @@ -964,27 +964,27 @@ typedef struct bass_postfilt_structure typedef struct td_cng_dec_structure { - int16_t cng_seed; /* DTX/CNG - seed for white noise random generator */ - // Word16 cng_seed; /*CNG and DTX - seed for white noise random generator*/ + Word16 cng_seed; /* DTX/CNG - seed for white noise random generator */ + // Word16 cng_seed; /*CNG and DTX - seed for white noise random generator*/ #ifndef IVAS_FLOAT_FIXED float Enew; /* DTX/CNG - decoded residual energy */ #endif Word32 Enew_fx; /* CNG and DTX - decoded residual energy Q6*/ - int16_t old_enr_index; /* DTX/CNG - index of last encoded CNG energy */ + Word16 old_enr_index; /* DTX/CNG - index of last encoded CNG energy */ - int16_t cng_ener_seed; /* DTX/CNG - seed for random generator for variation of excitation energy */ + Word16 cng_ener_seed; /* DTX/CNG - seed for random generator for variation of excitation energy */ - int16_t cng_ener_seed1; + Word16 cng_ener_seed1; - int16_t last_allow_cn_step; + Word16 last_allow_cn_step; - int16_t ho_hist_size; /* DTX/CNG - size of DTX hangover history buffer for averaging, <0,HO_HIST_SIZE> */ + Word16 ho_hist_size; /* DTX/CNG - size of DTX hangover history buffer for averaging, <0,HO_HIST_SIZE> */ - int16_t ho_hist_ptr; /* DTX/CNG - pointer for averaging buffers */ + Word16 ho_hist_ptr; /* DTX/CNG - pointer for averaging buffers */ - int32_t ho_sid_bw; /* DTX/CNG - SID bandwidth flags */ - // Word32 ho_sid_bw; /* CNG and DTX - SID bandwidth flags */ + Word32 ho_sid_bw; /* DTX/CNG - SID bandwidth flags */ + // Word32 ho_sid_bw; /* CNG and DTX - SID bandwidth flags */ #ifndef IVAS_FLOAT_FIXED float ho_lsp_hist[HO_HIST_SIZE * M]; /* DTX/CNG - old LSP buffer for averaging */ #endif @@ -999,12 +999,12 @@ typedef struct td_cng_dec_structure Word32 ho_env_hist_fx[HO_HIST_SIZE * NUM_ENV_CNG]; - int16_t act_cnt; /* DTX/CNG - counter of active frames */ + Word16 act_cnt; /* DTX/CNG - counter of active frames */ - int16_t ho_circ_size; /* DTX/CNG - size of DTX hangover history buffer for averaging, <0,HO_HIST_SIZE> */ + Word16 ho_circ_size; /* DTX/CNG - size of DTX hangover history buffer for averaging, <0,HO_HIST_SIZE> */ - int16_t ho_circ_ptr; /* DTX/CNG - pointer for averaging buffers */ - // Word16 ho_circ_ptr; /* CNG and DTX - pointer for averaging buffers */ + Word16 ho_circ_ptr; /* DTX/CNG - pointer for averaging buffers */ + // Word16 ho_circ_ptr; /* CNG and DTX - pointer for averaging buffers */ #ifndef IVAS_FLOAT_FIXED float ho_lsp_circ[HO_HIST_SIZE * M]; /* DTX/CNG - old LSP buffer for averaging */ @@ -1020,14 +1020,14 @@ typedef struct td_cng_dec_structure Word32 ho_env_circ_fx[HO_HIST_SIZE * NUM_ENV_CNG]; - int16_t num_ho; /* DTX/CNG - number of selected hangover frames */ + Word16 num_ho; /* DTX/CNG - number of selected hangover frames */ - int16_t ho_16k_lsp[HO_HIST_SIZE]; /* DTX/CNG - 16k LSPs flags */ - // Word16 ho_16k_lsp[HO_HIST_SIZE]; /* DTX/CNG - 16k LSPs flags */ + Word16 ho_16k_lsp[HO_HIST_SIZE]; /* DTX/CNG - 16k LSPs flags */ + // Word16 ho_16k_lsp[HO_HIST_SIZE]; /* DTX/CNG - 16k LSPs flags */ - int16_t act_cnt2; /* DTX/CNG - counter of active frames for CNG_mode switching */ - // Word16 act_cnt2; /* DTX/CNG - counter of active frames for CNG_mode switching */ + Word16 act_cnt2; /* DTX/CNG - counter of active frames for CNG_mode switching */ + // Word16 act_cnt2; /* DTX/CNG - counter of active frames for CNG_mode switching */ #ifndef IVAS_FLOAT_FIXED float old_env[20]; #endif @@ -1063,13 +1063,13 @@ typedef struct td_cng_dec_structure float last_wb_cng_ener; float last_shb_cng_ener; #endif - int16_t swb_cng_seed; + Word16 swb_cng_seed; #ifndef IVAS_FLOAT_FIXED float lsp_shb_prev_prev[LPC_SHB_ORDER]; float lsp_shb_prev[LPC_SHB_ORDER]; #endif - int16_t shb_dtx_count; - int16_t trans_cnt; + Word16 shb_dtx_count; + Word16 trans_cnt; #ifdef IVAS_FLOAT_FIXED Word16 interpol_3_2_cng_dec_fx[INTERP_3_2_MEM_LEN]; @@ -1083,7 +1083,7 @@ typedef struct td_cng_dec_structure Word16 lsp_shb_prev_prev_fx[LPC_SHB_ORDER]; // Q(14) #endif - int16_t burst_cnt; + Word16 burst_cnt; #ifndef IVAS_FLOAT_FIXED float last_shb_ener; #endif @@ -1103,7 +1103,7 @@ typedef struct td_cng_dec_structure typedef struct sc_vbr_dec_structure { - int16_t firstTime_voiceddec; + Word16 firstTime_voiceddec; /* DTFS variables */ #ifndef IVAS_FLOAT_FIXED @@ -1115,11 +1115,11 @@ typedef struct sc_vbr_dec_structure #endif Word16 dtfs_dec_b_fx[MAXLAG_WI]; /*Variable Q format in dtfs_dec_Q*/ - int16_t dtfs_dec_lag; + Word16 dtfs_dec_lag; - int16_t dtfs_dec_nH; + Word16 dtfs_dec_nH; - int16_t dtfs_dec_nH_4kHz; + Word16 dtfs_dec_nH_4kHz; #ifndef IVAS_FLOAT_FIXED float dtfs_dec_upper_cut_off_freq_of_interest; @@ -1172,7 +1172,7 @@ typedef struct sc_vbr_dec_structure Word16 shape3_filt_mem_dec_fx[10]; /* qfm currently Q0*/ - int16_t nelp_dec_seed; + Word16 nelp_dec_seed; Word16 FadeScale_fx; /*Q15*/ @@ -1185,24 +1185,24 @@ typedef struct sc_vbr_dec_structure typedef struct hq_nbfec_structure { - int16_t prev_last_core; /* !!! note: the parameter is identical to last_core in IVAS */ - // Word16 prev_last_core; /* !!! note: the parameter is identical to last_core in IVAS */ + Word16 prev_last_core; /* !!! note: the parameter is identical to last_core in IVAS */ + // Word16 prev_last_core; /* !!! note: the parameter is identical to last_core in IVAS */ #ifndef IVAS_FLOAT_FIXED float diff_energy; #endif Word16 diff_energy_fx; - int16_t stat_mode_out; + Word16 stat_mode_out; - int16_t stat_mode_old; + Word16 stat_mode_old; - int16_t phase_mat_flag; + Word16 phase_mat_flag; - int16_t phase_mat_next; + Word16 phase_mat_next; - int16_t old_Min_ind; + Word16 old_Min_ind; #ifndef IVAS_FLOAT_FIXED float old_auOut_2fr[L_FRAME8k * 2]; @@ -1232,16 +1232,16 @@ typedef struct hq_nbfec_structure /*Word16 old_hqswb_clas;*/ /* only used in inactive code, where it might probably be replaced by old_hqswb_clas_fx */ - int16_t HQ_FEC_seed; + Word16 HQ_FEC_seed; #ifndef IVAS_FLOAT_FIXED float energy_MA_Curr[2]; #endif Word16 energy_MA_Curr_fx[2]; - int16_t prev_sign_switch[HQ_FEC_SIGN_SFM]; + Word16 prev_sign_switch[HQ_FEC_SIGN_SFM]; - int16_t prev_sign_switch_2[HQ_FEC_SIGN_SFM]; + Word16 prev_sign_switch_2[HQ_FEC_SIGN_SFM]; #ifndef IVAS_FLOAT_FIXED float old_coeffs[L_FRAME8k]; /* HQ core - old coefficients (for FEC) */ @@ -1288,7 +1288,7 @@ typedef struct hq_dec_structure Word16 Q_old_wtda; Word16 Q_old_postdec; /*scaling of the output of core_switching_post_dec_fx() */ - int16_t last_hq_core_type; + Word16 last_hq_core_type; Word16 old_is_transient[3]; /* HQ core - previous transient flag (for FEC) */ @@ -1317,7 +1317,7 @@ typedef struct hq_dec_structure #ifndef IVAS_FLOAT_FIXED float prev_coeff_out[L_HQ_WB_BWE]; /* the highest coefficients of last frame */ #endif - int16_t prev_SWB_peak_pos[SPT_SHORTEN_SBNUM]; + Word16 prev_SWB_peak_pos[SPT_SHORTEN_SBNUM]; Word32 prev_coeff_out_fx[L_HQ_WB_BWE]; /* Q12 */ /* the coefficients of last frame */ Word16 prev_SWB_peak_pos_fx[SPT_SHORTEN_SBNUM]; @@ -1386,9 +1386,9 @@ typedef struct hq_dec_structure #endif Word16 wmold_hb_fx; /* Q15 */ - int16_t prevflag; + Word16 prevflag; - int16_t pastpre; + Word16 pastpre; Word16 prev_frm_hfe2; @@ -1477,9 +1477,9 @@ typedef struct hq_dec_structure Word16 ph_ecu_active; /* Set if Phase ECU was used in last bad frame */ - int16_t ni_seed_forfec; + Word16 ni_seed_forfec; - int16_t ber_occured_in_pvq; /* flag for BER detection from PVQ routines */ + Word16 ber_occured_in_pvq; /* flag for BER detection from PVQ routines */ } HQ_DEC_DATA, *HQ_DEC_HANDLE; @@ -1491,7 +1491,7 @@ typedef struct hq_dec_structure typedef struct zero_bwe_dec_structure { - int16_t seed2; /* HF (6-7kHz) BWE - seed for random signal generator */ + Word16 seed2; /* HF (6-7kHz) BWE - seed for random signal generator */ #ifndef IVAS_FLOAT_FIXED float mem_hp400[4]; /* HF (6-7kHz) BWE - hp400 filter memory */ @@ -1575,7 +1575,7 @@ typedef struct td_bwe_dec_structure #endif Word16 old_bwe_exc_fx[PIT16k_MAX * 2]; /*Q_exc*/ - int16_t bwe_seed[2]; + Word16 bwe_seed[2]; #ifndef IVAS_FLOAT_FIXED float bwe_non_lin_prev_scale; @@ -1649,7 +1649,7 @@ typedef struct td_bwe_dec_structure #endif Word16 prev_mix_factor_fx; /* mixing factor in the previous frame */ - int16_t syn_dm_phase; + Word16 syn_dm_phase; #ifndef IVAS_FLOAT_FIXED float fbbwe_hpf_mem[4][4]; @@ -1758,27 +1758,27 @@ typedef struct td_bwe_dec_structure /* quantized data */ - int16_t lsf_idx[NUM_Q_LSF]; + Word16 lsf_idx[NUM_Q_LSF]; - int16_t m_idx; + Word16 m_idx; - int16_t grid_idx; + Word16 grid_idx; - int16_t idxSubGains; + Word16 idxSubGains; - int16_t idxFrameGain; + Word16 idxFrameGain; - int16_t idx_shb_fr_gain; + Word16 idx_shb_fr_gain; - int16_t idx_res_gs[NB_SUBFR16k]; + Word16 idx_res_gs[NB_SUBFR16k]; - int16_t idx_mixFac; + Word16 idx_mixFac; - int16_t lsf_WB; + Word16 lsf_WB; - int16_t gFrame_WB; + Word16 gFrame_WB; - int16_t idxGain; + Word16 idxGain; #ifndef IVAS_FLOAT_FIXED float old_core_synth[L_FRAME16k]; @@ -1838,7 +1838,7 @@ typedef struct fd_bwe_dec_structure #endif Word16 mem_deemph_old_syn_fx; - int16_t prev_mode; + Word16 prev_mode; #ifndef IVAS_FLOAT_FIXED float prev_SWB_fenv[SWB_FENV]; @@ -1854,13 +1854,13 @@ typedef struct fd_bwe_dec_structure #endif Word32 prev_Energy_wb_fx; - int16_t prev_L_swb_norm; + Word16 prev_L_swb_norm; - int16_t Seed; + Word16 Seed; Word16 memExp1; - int16_t prev_frica_flag; + Word16 prev_frica_flag; #ifndef IVAS_FLOAT_FIXED float mem_imdct[L_FRAME48k]; @@ -1879,7 +1879,7 @@ typedef struct fd_bwe_dec_structure #endif Word16 prev_weight_fx; - int16_t prev_flag; + Word16 prev_flag; #ifndef IVAS_FLOAT_FIXED float last_wb_bwe_ener; @@ -1899,7 +1899,7 @@ typedef struct fd_bwe_dec_structure typedef struct hr_swb_bwe_dec_structure { - int16_t bwe_highrate_seed; + Word16 bwe_highrate_seed; Word16 bwe_highrate_seed_fx; #ifndef IVAS_FLOAT_FIXED @@ -1909,7 +1909,7 @@ typedef struct hr_swb_bwe_dec_structure Word16 t_audio_prev_fx_exp[NUM_TIME_SWITCHING_BLOCKS]; - int16_t old_is_transient_hr_bwe; + Word16 old_is_transient_hr_bwe; Word16 old_is_transient_hr_bwe_fx; #ifndef IVAS_FLOAT_FIXED @@ -1929,12 +1929,12 @@ typedef struct hr_swb_bwe_dec_structure typedef struct pvq_dec_structure { - uint32_t rc_low; - uint32_t rc_range; - uint32_t rc_help; - int16_t rc_num_bits; - int16_t rc_offset; - int16_t rc_end; + UWord32 rc_low; + UWord32 rc_range; + UWord32 rc_help; + Word16 rc_num_bits; + Word16 rc_offset; + Word16 rc_end; } PVQ_DEC_DATA, *PVQ_DEC_HANDLE; @@ -1960,7 +1960,7 @@ typedef struct amrwb_io_dec_structure #endif Word16 fmerit_w_sm_fx; /* HF BWE - fmerit parameter memory */ - int16_t frame_count; /* HF BWE - frame count */ + Word16 frame_count; /* HF BWE - frame count */ Word16 frame_count_fx; /* HF BWE - frame count */ #ifndef IVAS_FLOAT_FIXED float ne_min; /* HF BWE - minimum Noise gate - short-term energy */ @@ -1987,13 +1987,13 @@ typedef struct amrwb_io_dec_structure #endif Word16 unvoicing_sm_fx; /* HF BWE - smoothed unvoiced parameter */ - int16_t unvoicing_flag; /* HF BWE - unvoiced flag */ + Word16 unvoicing_flag; /* HF BWE - unvoiced flag */ Word16 unvoicing_flag_fx; /* HF BWE - unvoiced flag */ - int16_t voicing_flag; /* HF BWE - voiced flag */ + Word16 voicing_flag; /* HF BWE - voiced flag */ Word16 voicing_flag_fx; /* HF BWE - voiced flag */ - int16_t start_band_old; /* HF BWE - previous start point for copying frequency band */ + Word16 start_band_old; /* HF BWE - previous start point for copying frequency band */ Word16 start_band_old_fx; /* HF BWE - previous start point for copying frequency band */ #ifndef IVAS_FLOAT_FIXED float OptCrit_old; /* HF BWE - previous criterion value for deciding the start point */ @@ -2001,7 +2001,7 @@ typedef struct amrwb_io_dec_structure Word32 OptCrit_old_fx; /* HF BWE - previous criterion value for deciding the start point */ /* Improvement of unvoiced and audio signals in AMR-WB IO mode */ - int16_t UV_cnt; /* number of consecutives frames classified as UV */ + Word16 UV_cnt; /* number of consecutives frames classified as UV */ Word16 UV_cnt_fx; /* number of consecutives frames classified as UV */ #ifndef IVAS_FLOAT_FIXED float LT_UV_cnt; /* long-term consecutives frames classified as UV */ @@ -2051,75 +2051,75 @@ typedef struct Decoder_State * Common parameters *----------------------------------------------------------------------------------*/ - int16_t idchan; /* channel ID (audio channel number) */ - int16_t element_mode; /* element mode */ - int32_t element_brate; /* element bitrate */ - int16_t codec_mode; /* Mode 1 or 2 */ - int16_t mdct_sw_enable; /* MDCT switching enable flag */ - int16_t mdct_sw; /* MDCT switching indicator */ - int16_t last_codec_mode; /* last used codec mode */ + Word16 idchan; /* channel ID (audio channel number) */ + Word16 element_mode; /* element mode */ + Word32 element_brate; /* element bitrate */ + Word16 codec_mode; /* Mode 1 or 2 */ + Word16 mdct_sw_enable; /* MDCT switching enable flag */ + Word16 mdct_sw; /* MDCT switching indicator */ + Word16 last_codec_mode; /* last used codec mode */ - uint16_t *bit_stream; /* pointer to bitstream buffer */ + UWord16 *bit_stream; /* pointer to bitstream buffer */ - int16_t next_bit_pos; /* position of the next bit to be read from the bitstream */ + Word16 next_bit_pos; /* position of the next bit to be read from the bitstream */ Word16 bitstreamformat; /* Bitstream format flag (G.192/MIME/VOIP_G192_RTP/VOIP_RTPDUMP) */ Word16 sdp_hf_only; /* RTP payload format parameter: only Header-Full format without zero padding for size collision avoidance */ Word16 amrwb_rfc4867_flag; /* MIME from rfc4867 is used */ Word16 total_num_bits; /* == st->total_brate / 50 */ - int16_t BER_detect; /* flag to signal detected bit error in the bitstream */ + Word16 BER_detect; /* flag to signal detected bit error in the bitstream */ - int32_t output_Fs; /* output sampling rate */ + Word32 output_Fs; /* output sampling rate */ Word16 output_frame_fx; /* Output frame length Q0*/ - int32_t total_brate; /* total bitrate in kbps of the codec */ + Word32 total_brate; /* total bitrate in kbps of the codec */ - int32_t last_total_brate; /* last total bitrate in kbps of the codec */ - // Word32 last_total_brate_fx; /* last total bitrate in kbps of the codec Q0*/ + Word32 last_total_brate; /* last total bitrate in kbps of the codec */ + // Word32 last_total_brate_fx; /* last total bitrate in kbps of the codec Q0*/ - int32_t last_total_brate_ber; /* last total bitrate in kbps of the codec - used only when first frame is lost and BER is detected afterwards */ + Word32 last_total_brate_ber; /* last total bitrate in kbps of the codec - used only when first frame is lost and BER is detected afterwards */ - int16_t bits_frame_nominal; /* avg bits per frame on active frame */ - int32_t last_bits_frame_nominal; /* last avg bits per frame on active frame */ - int16_t flag_ACELP16k; /* flag indicating use of ACELP core at 16kHz internal sampling rate */ - int16_t bits_frame_channel; /* bits frame channel */ - int16_t side_bits_frame_channel; /* bits frame channel */ + Word16 bits_frame_nominal; /* avg bits per frame on active frame */ + Word32 last_bits_frame_nominal; /* last avg bits per frame on active frame */ + Word16 flag_ACELP16k; /* flag indicating use of ACELP core at 16kHz internal sampling rate */ + Word16 bits_frame_channel; /* bits frame channel */ + Word16 side_bits_frame_channel; /* bits frame channel */ - int16_t core; /* core (ACELP_CORE, TCX_20_CORE, TCX_10_CORE, HQ_CORE, AMR_WB_CORE) */ + Word16 core; /* core (ACELP_CORE, TCX_20_CORE, TCX_10_CORE, HQ_CORE, AMR_WB_CORE) */ - int16_t coder_type; /* coder type */ - int16_t transform_type[2]; /* TCX20/10/5 mode in each subframe */ + Word16 coder_type; /* coder type */ + Word16 transform_type[2]; /* TCX20/10/5 mode in each subframe */ - int32_t core_brate; /* core bitrate */ + Word32 core_brate; /* core bitrate */ - int32_t last_core_brate; /* previous frame core bitrate */ + Word32 last_core_brate; /* previous frame core bitrate */ - int16_t extl; /* extension layer */ + Word16 extl; /* extension layer */ - int16_t extl_orig; /* extension layer */ + Word16 extl_orig; /* extension layer */ - int16_t last_extl; /* previous extension layer */ + Word16 last_extl; /* previous extension layer */ - int32_t extl_brate; /* extension layer bitrate */ + Word32 extl_brate; /* extension layer bitrate */ - int32_t extl_brate_orig; /* extension layer bitrate */ + Word32 extl_brate_orig; /* extension layer bitrate */ - int16_t L_frame; /* ACELP core internal frame length */ + Word16 L_frame; /* ACELP core internal frame length */ - int16_t bwidth; /* encoded signal bandwidth */ + Word16 bwidth; /* encoded signal bandwidth */ - int16_t Opt_AMR_WB; /* flag indicating AMR-WB IO mode */ + Word16 Opt_AMR_WB; /* flag indicating AMR-WB IO mode */ Word16 Opt_VOIP_fx; /* flag indicating VOIP mode with JBM */ - int16_t ini_frame; /* initialization frames counter */ + Word16 ini_frame; /* initialization frames counter */ - int16_t prev_coder_type; /* coding type of last frame */ - int16_t low_rate_mode; /* low-rate mode flag */ - int16_t last_low_rate_mode; /* previous frame low-rate mode flag */ - int16_t inactive_coder_type_flag; /* inactive coder type flag (0 = AVQ / 1 = GSC) */ + Word16 prev_coder_type; /* coding type of last frame */ + Word16 low_rate_mode; /* low-rate mode flag */ + Word16 last_low_rate_mode; /* previous frame low-rate mode flag */ + Word16 inactive_coder_type_flag; /* inactive coder type flag (0 = AVQ / 1 = GSC) */ Word16 CNG_fx; /* RXDTX handler: CNG=1, nonCNG=0 */ Word16 prev_ft_speech_fx; /* RXDTX handler: previous frametype flag for G.192 format AMRWB SID_FIRST detection */ @@ -2167,13 +2167,13 @@ typedef struct Decoder_State Word16 stab_fac_smooth_fx; /* low-pass filtered stability factor Q15*/ - int16_t last_coder_type; /* previous coder type */ + Word16 last_coder_type; /* previous coder type */ Word16 agc_mem_fx[2]; /* memory of AGC for saturation control Q0*/ - int16_t mid_lsf_int; + Word16 mid_lsf_int; - int16_t safety_net; + Word16 safety_net; #ifndef IVAS_FLOAT_FIXED float stab_fac; /* LSF stability factor */ @@ -2198,11 +2198,11 @@ typedef struct Decoder_State Word32 L_mem_hp_out_fx[5]; /* hp filter memory for synthesis */ - int16_t GSC_noisy_speech; /* AC mode (GSC) - flag to indicate GSC on SWB noisy speech */ + Word16 GSC_noisy_speech; /* AC mode (GSC) - flag to indicate GSC on SWB noisy speech */ - int16_t GSC_IVAS_mode; /* AC mode (GSC) - GSC IVAS mode */ + Word16 GSC_IVAS_mode; /* AC mode (GSC) - GSC IVAS mode */ - int16_t Last_GSC_noisy_speech_flag; /* AC mode (GSC) - mem of the past flag to indicate GSC osn SWB noisy speech */ + Word16 Last_GSC_noisy_speech_flag; /* AC mode (GSC) - mem of the past flag to indicate GSC osn SWB noisy speech */ GSC_DEC_HANDLE hGSCDec; @@ -2217,17 +2217,17 @@ typedef struct Decoder_State ZERO_BWE_DEC_HANDLE hBWE_zero; /* HF (6-7kHz) BWE */ - int16_t unv_cnt; /* Stationary noise UV modification - unvoiced frame counter */ + Word16 unv_cnt; /* Stationary noise UV modification - unvoiced frame counter */ - int16_t uv_count; /* Stationary noise UV modification - unvoiced counter */ + Word16 uv_count; /* Stationary noise UV modification - unvoiced counter */ - int16_t act_count; /* Stationary noise UV modification - activation counter */ + Word16 act_count; /* Stationary noise UV modification - activation counter */ Word32 ge_sm_fx; /* Stationary noise UV modification - smoothed excitation gain Q(GE_SHIFT)*/ Word16 lspold_s_fx[M]; /* Stationary noise UV modification - old LSP vector Q15*/ - int16_t noimix_seed; /* Stationary noise UV modification - mixture seed */ + Word16 noimix_seed; /* Stationary noise UV modification - mixture seed */ Word16 min_alpha_fx; /* Stationary noise UV modification - minimum alpha Q15*/ @@ -2244,21 +2244,21 @@ typedef struct Decoder_State Word16 Q_stat_noise_ge; /* Q of ge_sm_fx */ - int16_t bfi; /* FEC - bad frame indicator */ + Word16 bfi; /* FEC - bad frame indicator */ - int16_t prev_bfi; /* FEC - previous bad frame indicator */ + Word16 prev_bfi; /* FEC - previous bad frame indicator */ - int16_t prev_old_bfi; /* FEC - previous old bad frame indicator */ + Word16 prev_old_bfi; /* FEC - previous old bad frame indicator */ - int16_t seed; /* FEC - seed for random generator for excitation */ - // Word16 seed_fx; /* FEC - seed for random generator for excitation Q0*/ + Word16 seed; /* FEC - seed for random generator for excitation */ + // Word16 seed_fx; /* FEC - seed for random generator for excitation Q0*/ #ifndef IVAS_FLOAT_FIXED float lp_ener_bfi; /* FEC - long-term active-signal average energy */ float lp_ener; /* FEC - low-pass filtered energy */ #endif - int16_t last_good; /* FEC - clas of last good received */ + Word16 last_good; /* FEC - clas of last good received */ Word16 lp_gainp_fx; /* FEC - low-pass filtered pitch gain Q14 */ @@ -2277,14 +2277,14 @@ typedef struct Decoder_State #endif // #ifndef IVAS_FLOAT_FIXED Word16 bfi_pitch_fx; /* FEC - pitch for FEC */ - int16_t bfi_pitch_frame; /* FEC - frame length when pitch for FEC is saved */ + Word16 bfi_pitch_frame; /* FEC - frame length when pitch for FEC is saved */ Word16 old_pitch_buf_16_fx[2 * NB_SUBFR16k + 2]; /* FEC - buffer of old subframe pitch values Q6 */ Word32 old_pitch_buf_fx[2 * NB_SUBFR16k + 2]; /* FEC - buffer of old subframe pitch values 15Q16 */ - int16_t upd_cnt; /* FEC - counter of frames since last update */ + Word16 upd_cnt; /* FEC - counter of frames since last update */ - int16_t scaling_flag; /* FEC - flag to indicate energy control of syn */ + Word16 scaling_flag; /* FEC - flag to indicate energy control of syn */ Word32 lp_ener_FEC_av; /* FEC - averaged voiced signal energy Q0 */ @@ -2292,8 +2292,8 @@ typedef struct Decoder_State Word16 old_enr_LP; /* FEC - LP filter gain Q5*/ - int16_t prev_nbLostCmpt; /* FEC - compt for number of consecutive lost frame at the previous frame*/ - int16_t mode_lvq; /* FEC - index for LSF mean vector*/ + Word16 prev_nbLostCmpt; /* FEC - compt for number of consecutive lost frame at the previous frame*/ + Word16 mode_lvq; /* FEC - index for LSF mean vector*/ #ifndef IVAS_FLOAT_FIXED float old_enr_LP_float; /* FEC - LP filter gain */ @@ -2310,21 +2310,21 @@ typedef struct Decoder_State Word16 lsf_adaptive_mean_fx[M]; /* FEC - adaptive mean LSF vector for FEC (Qx2.56)*/ - int16_t decision_hyst; /* FEC - hysteresis of the music/speech decision */ + Word16 decision_hyst; /* FEC - hysteresis of the music/speech decision */ Word16 lp_ener_FER_fx; /* FEC - long-term active-signal average energy Q8*/ WI_DEC_HANDLE hWIDec; - int16_t relax_prev_lsf_interp; + Word16 relax_prev_lsf_interp; #ifndef IVAS_FLOAT_FIXED float mem_syn_clas_estim[L_SYN_MEM_CLAS_ESTIM]; /* FEC - memory of the synthesis signal for frame class estimation */ #endif // #ifndef IVAS_FLOAT_FIXED Word16 mem_syn_clas_estim_fx[L_SYN_MEM_CLAS_ESTIM]; /* FEC - memory of the synthesis signal for frame class estimation */ - int16_t bpf_off; /* Bass post-filter - do not use BPF when this flag is set to 1 */ + Word16 bpf_off; /* Bass post-filter - do not use BPF when this flag is set to 1 */ BPF_DEC_HANDLE hBPF; /* Bass post-filter handle */ @@ -2337,8 +2337,8 @@ typedef struct Decoder_State HANDLE_CLDFB_FILTER_BANK cldfbSynHB; /* high band synthesis filter bank needed in SBA2Stereo DTX handling */ - int16_t last_active_bandsToZero_bwdec; - int16_t last_flag_filter_NB; + Word16 last_active_bandsToZero_bwdec; + Word16 last_flag_filter_NB; #ifndef IVAS_FLOAT_FIXED float perc_bwddec_float; @@ -2347,23 +2347,23 @@ typedef struct Decoder_State #endif // 0 Word16 perc_bwddec; /*Q14*/ - int16_t active_frame_cnt_bwddec; - int16_t flag_buffer[20]; - int16_t total_frame_cnt_bwddec; + Word16 active_frame_cnt_bwddec; + Word16 flag_buffer[20]; + Word16 total_frame_cnt_bwddec; Word32 avg_nrg_LT; Word16 Ng_ener_ST_fx; /* Noise gate - short-term energy Q8*/ - int16_t last_L_frame; /* ACELP@16kHz - last value of st->L_frame */ + Word16 last_L_frame; /* ACELP@16kHz - last value of st->L_frame */ Word16 mem_preemp_preQ_fx; /* ACELP@16kHz - prequantizer preemhasis memory */ - int16_t last_nq_preQ; /* ACELP@16kHz - AVQ subquantizer number of the last sub-band of the last subframe */ + Word16 last_nq_preQ; /* ACELP@16kHz - AVQ subquantizer number of the last sub-band of the last subframe */ - int16_t last_code_preq; /* ACELP@16kHz - last coefficient of the pre-quantizer contribution */ + Word16 last_code_preq; /* ACELP@16kHz - last coefficient of the pre-quantizer contribution */ - int16_t use_acelp_preq; /* ACELP@16kHz - flag of prequantizer usage */ + Word16 use_acelp_preq; /* ACELP@16kHz - flag of prequantizer usage */ /* NB and formant post-filter */ @@ -2380,35 +2380,35 @@ typedef struct Decoder_State Word16 last_voice_factor_fx; /* Q6*/ - int16_t old_bfi_cnt; /* HQ core - # of bfi until previous frame(for FEC) */ + Word16 old_bfi_cnt; /* HQ core - # of bfi until previous frame(for FEC) */ /*----------------------------------------------------------------------------------* * DTX and TD CNG parameters *----------------------------------------------------------------------------------*/ - int16_t first_CNG; /* DTX/CNG - first CNG frame flag */ + Word16 first_CNG; /* DTX/CNG - first CNG frame flag */ - int16_t cng_type; /* DTX/CNG - flag indicating LP or CLDFB based SID/CNG */ + Word16 cng_type; /* DTX/CNG - flag indicating LP or CLDFB based SID/CNG */ - int16_t last_vad; + Word16 last_vad; - int32_t last_active_brate; /* DTX/CNG - last active frame bitrate used for CNG_mode control */ + Word32 last_active_brate; /* DTX/CNG - last active frame bitrate used for CNG_mode control */ - int16_t last_CNG_L_frame; /* DTX/CNG - last CNG frame length */ - // Word16 last_CNG_L_frame_fx; /* DTX/CNG - last CNG frame length */ + Word16 last_CNG_L_frame; /* DTX/CNG - last CNG frame length */ + // Word16 last_CNG_L_frame_fx; /* DTX/CNG - last CNG frame length */ - int16_t CNG_mode; /* DTX/CNG - mode for DTX configuration */ - // Word16 CNG_mode_fx; /* DTX/CNG - mode for DTX configuration */ + Word16 CNG_mode; /* DTX/CNG - mode for DTX configuration */ + // Word16 CNG_mode_fx; /* DTX/CNG - mode for DTX configuration */ #ifndef IVAS_FLOAT_FIXED float lspCNG[M]; /* DTX/CNG - LP filtered ISPs */ #endif // #ifndef IVAS_FLOAT_FIXED Word16 lspCNG_fx[M]; /* CNG and DTX - LP filtered ISPs Q15*/ - int16_t active_cnt; + Word16 active_cnt; TD_CNG_DEC_HANDLE hTdCngDec; - int16_t masa_sid_format; + Word16 masa_sid_format; /*----------------------------------------------------------------------------------* * AMR-WB IO mode parameters @@ -2422,13 +2422,13 @@ typedef struct Decoder_State SC_VBR_DEC_HANDLE hSC_VBR; - int16_t last_ppp_mode_dec; + Word16 last_ppp_mode_dec; - int16_t ppp_mode_dec; + Word16 ppp_mode_dec; - int16_t last_nelp_mode_dec; + Word16 last_nelp_mode_dec; - int16_t nelp_mode_dec; + Word16 nelp_mode_dec; Word16 prev_gain_pit_dec_fx; /*Q14*/ @@ -2440,9 +2440,9 @@ typedef struct Decoder_State Word16 prev_tilt_code_dec_fx; /*Q15*/ - int16_t vbr_hw_BWE_disable_dec; + Word16 vbr_hw_BWE_disable_dec; - int16_t last_vbr_hw_BWE_disable_dec; + Word16 last_vbr_hw_BWE_disable_dec; /*----------------------------------------------------------------------------------* * channel-aware mode @@ -2450,21 +2450,21 @@ typedef struct Decoder_State Word16 tilt_code_dec_fx[NB_SUBFR16k]; - int16_t rf_frame_type; - int16_t use_partial_copy; - int16_t prev_use_partial_copy; - int16_t rf_flag; - int16_t rf_flag_last; + Word16 rf_frame_type; + Word16 use_partial_copy; + Word16 prev_use_partial_copy; + Word16 rf_flag; + Word16 rf_flag_last; - int16_t rf_fec_offset; - int16_t next_coder_type; - int16_t prev_rf_frame_type; - int16_t rf_target_bits; + Word16 rf_fec_offset; + Word16 next_coder_type; + Word16 prev_rf_frame_type; + Word16 rf_target_bits; - int16_t rf_indx_nelp_fid; - int16_t rf_indx_nelp_iG1; - int16_t rf_indx_nelp_iG2[2]; - int16_t rf_indx_tbeGainFr; + Word16 rf_indx_nelp_fid; + Word16 rf_indx_nelp_iG1; + Word16 rf_indx_nelp_iG2[2]; + Word16 rf_indx_tbeGainFr; /*----------------------------------------------------------------------------------* * HR SWB BWE parameters @@ -2479,12 +2479,12 @@ typedef struct Decoder_State HQ_DEC_HANDLE hHQ_core; - int16_t last_core; + Word16 last_core; - int16_t last_core_from_bs; /* last frame core as coded in TCX bitstream */ - // Word16 last_core_bs_fx; + Word16 last_core_from_bs; /* last frame core as coded in TCX bitstream */ + // Word16 last_core_bs_fx; - int16_t last_L_frame_ori; + Word16 last_L_frame_ori; Word16 previoussynth_fx[L_FRAME48k]; Word32 previoussynth_fx_32[L_FRAME48k]; @@ -2518,14 +2518,14 @@ typedef struct Decoder_State TD_BWE_DEC_HANDLE hBWE_TD; - int16_t old_bwe_delay; + Word16 old_bwe_delay; Word16 hb_prev_synth_buffer_fx[NS2SA( 48000, DELAY_BWE_TOTAL_NS )]; /* WB/SWB bandwidth switching */ - Word16 tilt_wb_fx; + Word16 tilt_wb_fx; // Q11 - Word16 tilt_swb_fx; + Word16 tilt_swb_fx; // Q24 #ifndef IVAS_FLOAT_FIXED float hb_prev_synth_buffer[NS2SA( 48000, DELAY_BWE_TOTAL_NS )]; @@ -2538,25 +2538,25 @@ typedef struct Decoder_State float enerLH; float enerLL; #endif - Word16 prev_ener_shb_fx; + Word16 prev_ener_shb_fx; // Q1 Word32 enerLH_fx; Word16 enerLH_fx_Q; - Word32 prev_enerLH_fx; + Word32 prev_enerLH_fx; // Q1 Word32 enerLL_fx; Word16 enerLL_fx_Q; - Word32 prev_enerLL_fx; + Word32 prev_enerLL_fx; // Q1 - int16_t prev_fractive; + Word16 prev_fractive; - int16_t prev_bws_cnt; + Word16 prev_bws_cnt; - int16_t bws_cnt; + Word16 bws_cnt; - int16_t bws_cnt1; + Word16 bws_cnt1; #ifndef IVAS_FLOAT_FIXED float attenu1; @@ -2564,9 +2564,9 @@ typedef struct Decoder_State #endif // #ifndef IVAS_FLOAT_FIXED Word16 attenu_fx; - int16_t last_inner_frame; + Word16 last_inner_frame; - int16_t last_bwidth; + Word16 last_bwidth; Word16 t_audio_q_fx[L_FRAME]; @@ -2654,19 +2654,19 @@ typedef struct Decoder_State * Mode 2 *----------------------------------------------------------------------------------*/ - int16_t force_lpd_reset; + Word16 force_lpd_reset; ACELP_config acelp_cfg; /* ACELP configuration set for each frame */ ACELP_config acelp_cfg_rf; /* ACELP configuration for RF frame */ TCX_CONFIG_HANDLE hTcxCfg; /* TCX config */ - int16_t bits_frame; /* bit per frame overall */ - int16_t bits_frame_core; /* bit per frame for the core */ - int16_t narrowBand; + Word16 bits_frame; /* bit per frame overall */ + Word16 bits_frame_core; /* bit per frame for the core */ + Word16 narrowBand; Word16 bits_common; /* read bits from header and LPC*/ - int16_t last_is_cng; + Word16 last_is_cng; #ifndef IVAS_FLOAT_FIXED float *acelp_zir; @@ -2676,16 +2676,16 @@ typedef struct Decoder_State #endif Word16 syn[M + 1]; - int16_t bpf_gain_param; /* bass post-filter gain factor parameter (0->noBpf)*/ + Word16 bpf_gain_param; /* bass post-filter gain factor parameter (0->noBpf)*/ - int16_t L_frame_past; - int16_t L_frameTCX_past; + Word16 L_frame_past; + Word16 L_frameTCX_past; Word16 lsfold_uw[M]; /* old lsf (unweighted) */ Word16 lspold_uw[M]; /* old lsp (unweighted) */ - int16_t seed_tcx_plc; /* seed memory (for random function in TCX PLC) */ + Word16 seed_tcx_plc; /* seed memory (for random function in TCX PLC) */ #ifndef IVAS_FLOAT_FIXED float lsfold_uw_float[M]; /* old lsf (unweighted) */ @@ -2720,7 +2720,7 @@ typedef struct Decoder_State Word16 mem_syn_unv_back[M]; /* filter memory for unvoiced synth */ - int16_t plcBackgroundNoiseUpdated; /* flag: Is background noise estimate updated? */ + Word16 plcBackgroundNoiseUpdated; /* flag: Is background noise estimate updated? */ #ifndef IVAS_FLOAT_FIXED float mem_syn_unv_back_float[M]; /* filter memory for unvoiced synth */ @@ -2737,19 +2737,19 @@ typedef struct Decoder_State /* variables for framing */ - int16_t nb_subfr; + Word16 nb_subfr; - int16_t fscale; - int16_t fscale_old; - int32_t sr_core; + Word16 fscale; + Word16 fscale_old; + Word32 sr_core; - int16_t pit_min; - int16_t pit_fr1; - int16_t pit_fr1b; - int16_t pit_fr2; - int16_t pit_max; - int16_t pit_res_max; - int16_t pit_res_max_past; + Word16 pit_min; + Word16 pit_fr1; + Word16 pit_fr1b; + Word16 pit_fr2; + Word16 pit_max; + Word16 pit_res_max; + Word16 pit_res_max_past; /*Preemphasis factor*/ Word16 preemph_fac; /*0Q15*/ @@ -2771,14 +2771,14 @@ typedef struct Decoder_State Word16 mem_Aq[( NB_SUBFR16k ) * ( M + 1 )]; /* Q12 */ /* Error concealment */ - int16_t last_core_bfi; /* PLC - mode in previous frame */ - int16_t nbLostCmpt; /* PLC - compt for number of consecutive lost frame */ + Word16 last_core_bfi; /* PLC - mode in previous frame */ + Word16 nbLostCmpt; /* PLC - compt for number of consecutive lost frame */ Word32 old_fpitch; /* last pitch of previous frame */ /*15Q16*/ Word32 old_fpitchFB; /* PLC - last pitch of previous FB frame (depends on output sr) */ /*15Q16*/ - int16_t clas_dec; /* PLC - frame class at the decoder */ + Word16 clas_dec; /* PLC - frame class at the decoder */ #ifndef IVAS_FLOAT_FIXED float old_fpitch_float; /* PLC - last pitch of previous frame (as transmitted) */ @@ -2790,7 +2790,7 @@ typedef struct Decoder_State #endif // #ifndef IVAS_FLOAT_FIXED Word16 mem_pitch_gain[2 * NB_SUBFR16k + 2]; /* Pitch gain memory Q14 */ - int16_t plc_use_future_lag; /* PLC - flag indicating if info (pitch lag / pitch gain) about future frame is usable */ + Word16 plc_use_future_lag; /* PLC - flag indicating if info (pitch lag / pitch gain) about future frame is usable */ Word32 Mode2_lp_gainc; /* 15Q16 low passed code gain used for concealment*/ Word32 Mode2_lp_gainp; /* 15Q16 low passed pitch gain used for concealment*/ @@ -2803,16 +2803,16 @@ typedef struct Decoder_State Word16 prev_widow_left_rect; - int16_t reset_mem_AR; + Word16 reset_mem_AR; Word16 classifier_Q_mem_syn; /*scalingfactor of mem_syn_clas_estim_fx in MODE2 */ - int16_t rate_switching_init; + Word16 rate_switching_init; /* LPC quantization */ - int16_t lpcQuantization; - int16_t numlpc; + Word16 lpcQuantization; + Word16 numlpc; /* Bandwidth */ #ifndef IVAS_FLOAT_FIXED @@ -2825,17 +2825,17 @@ typedef struct Decoder_State #endif // #ifndef IVAS_FLOAT_FIXED Word16 voice_fac; - int16_t tcxonly; + Word16 tcxonly; - int16_t last_ctx_hm_enabled; + Word16 last_ctx_hm_enabled; struct tonalmdctconceal tonalMDCTconceal; TonalMDCTConcealPtr hTonalMDCTConc; - int16_t tonal_mdct_plc_active; - int16_t last_tns_active; - int16_t second_last_tns_active; - int16_t second_last_core; + Word16 tonal_mdct_plc_active; + Word16 last_tns_active; + Word16 second_last_tns_active; + Word16 second_last_core; /* parameters for switching */ #ifndef IVAS_FLOAT_FIXED @@ -2843,7 +2843,7 @@ typedef struct Decoder_State #endif // #ifndef IVAS_FLOAT_FIXED Word16 mem_syn_r[L_SYN_MEM]; /*LPC synthesis memory needed for rate switching*/ - int16_t rate_switching_reset; + Word16 rate_switching_reset; Word16 bpf_noise_buf[L_FRAME_16k]; Word32 bpf_noise_buf_32[L_FRAME_16k]; @@ -2854,44 +2854,44 @@ typedef struct Decoder_State Word16 *p_bpf_noise_buf; Word32 *p_bpf_noise_buf_32; - int16_t enableGplc; - int16_t flagGuidedAcelp; - int16_t T0_4th; - int16_t guidedT0; + Word16 enableGplc; + Word16 flagGuidedAcelp; + Word16 T0_4th; + Word16 guidedT0; - int16_t enablePlcWaveadjust; - int16_t tonality_flag; + Word16 enablePlcWaveadjust; + Word16 tonality_flag; T_PLCInfo_HANDLE hPlcInfo; T_PLCInfo plcInfo; - int16_t VAD; - int16_t flag_cna; - int16_t last_flag_cna; + Word16 VAD; + Word16 flag_cna; + Word16 last_flag_cna; #ifndef IVAS_FLOAT_FIXED float lp_noise_float; #endif // #ifndef IVAS_FLOAT_FIXED Word32 lp_noise; - int16_t seed_acelp; - int16_t core_ext_mode; /*GC,VC,UC,TC: core extended mode used for PLC or Acelp-external modules.*/ + Word16 seed_acelp; + Word16 core_ext_mode; /*GC,VC,UC,TC: core extended mode used for PLC or Acelp-external modules.*/ - int16_t dec_glr; - int16_t dec_glr_idx; + Word16 dec_glr; + Word16 dec_glr_idx; DEC_MODE m_decodeMode; - uint8_t m_frame_type; /*ZERO_FRAME/SID_FRAME/ACTIVE_FRAME*/ - uint8_t m_old_frame_type; /*ZERO_FRAME/SID_FRAME/ACTIVE_FRAME*/ + UWord8 m_frame_type; /*ZERO_FRAME/SID_FRAME/ACTIVE_FRAME*/ + UWord8 m_old_frame_type; /*ZERO_FRAME/SID_FRAME/ACTIVE_FRAME*/ - int16_t old_ppp_mode; + Word16 old_ppp_mode; - int16_t con_tcx; - int16_t last_con_tcx; + Word16 con_tcx; + Word16 last_con_tcx; Word16 prev_Q_exc_fr; Word16 prev_Q_syn_fr; - int16_t writeFECoffset; + Word16 writeFECoffset; /*----------------------------------------------------------------------------------* * Frequency-domain-based CNG @@ -2904,7 +2904,7 @@ typedef struct Decoder_State *----------------------------------------------------------------------------------*/ IGF_DEC_INSTANCE_HANDLE hIGFDec; - int16_t igf; + Word16 igf; CLDFB_SCALE_FACTOR scaleFactor; @@ -2912,9 +2912,9 @@ typedef struct Decoder_State * TEC *----------------------------------------------------------------------------------*/ - int16_t tec_tfa; - int16_t tec_flag; - int16_t tfa_flag; + Word16 tec_tfa; + Word16 tec_flag; + Word16 tfa_flag; TEC_DEC_HANDLE hTECDec; #if 0 //not needed above structure has same variable @@ -2924,16 +2924,16 @@ typedef struct Decoder_State * IVAS parameters *----------------------------------------------------------------------------------*/ - int16_t tdm_LRTD_flag; /* LRTD stereo mode flag */ - int16_t cna_dirac_flag; /* CNA in DirAC flag */ - int16_t cng_sba_flag; /* CNG in SBA flag */ + Word16 tdm_LRTD_flag; /* LRTD stereo mode flag */ + Word16 cna_dirac_flag; /* CNA in DirAC flag */ + Word16 cng_sba_flag; /* CNG in SBA flag */ /* MCT Channel mode indication: LFE, ignore channel? */ // note_ : one extra value in evs ivas macro code MCT_CHAN_MODE mct_chan_mode; - int16_t cng_ism_flag; /* CNG in ISM format flag */ - int16_t is_ism_format; /* Indication whether the codec operates in ISM format */ + Word16 cng_ism_flag; /* CNG in ISM format flag */ + Word16 is_ism_format; /* Indication whether the codec operates in ISM format */ Word16 last_element_mode; /* element mode */ // Word16 coder_type; /* low-rate mode flag */ diff --git a/lib_dec/stat_noise_uv_dec_fx.c b/lib_dec/stat_noise_uv_dec_fx.c index c1749a536..6c7705cfc 100644 --- a/lib_dec/stat_noise_uv_dec_fx.c +++ b/lib_dec/stat_noise_uv_dec_fx.c @@ -13,12 +13,12 @@ * Modifies excitation signal in UC mode when the noise is stationary *---------------------------------------------------------*/ void stat_noise_uv_dec_fx( - Decoder_State *st_fx, /* i/o: Decoder static memory */ - Word16 *lsp_new, /* i : end-frame LSP vector */ - Word16 *lsp_mid, /* i : mid-frame LSP vector */ - Word16 *Aq, /* o : A(z) quantized for the 4 subframes */ - Word16 *exc2, /* i/o: excitation buffer */ - const Word16 uc_two_stage_flag /* i : flag indicating two-stage UC */ + Decoder_State *st_fx, /* i/o: Decoder static memory */ + Word16 *lsp_new, /* i : end-frame LSP vector Q15 */ + Word16 *lsp_mid, /* i : mid-frame LSP vector Q15 */ + Word16 *Aq, /* o : A(z) quantized for the 4 subframes Q = 14 - norm_s(Aq[0]) */ + Word16 *exc2, /* i/o: excitation buffer, Q = st_fx->Q_exc */ + const Word16 uc_two_stage_flag /* i : flag indicating two-stage UC */ ) { Word16 noisiness = 0, i; diff --git a/lib_enc/acelp_core_enc.c b/lib_enc/acelp_core_enc.c index 95a187a6e..a814ff029 100644 --- a/lib_enc/acelp_core_enc.c +++ b/lib_enc/acelp_core_enc.c @@ -168,7 +168,9 @@ ivas_error acelp_core_enc( // Word16 next_force_sf_bck_fx; Word32 q_env_fx[NUM_ENV_CNG]; // Word16 coder_type; - +#ifdef MSAN_FIX + set32_fx( q_env_fx, 0, NUM_ENV_CNG ); +#endif Word16 exc3_fx[L_FRAME16k]; Word16 syn1_fx[L_FRAME16k]; Word16 *tdm_Pri_pitch_buf_fx; diff --git a/lib_enc/ivas_core_enc.c b/lib_enc/ivas_core_enc.c index 6effecd94..d601c6fa2 100644 --- a/lib_enc/ivas_core_enc.c +++ b/lib_enc/ivas_core_enc.c @@ -1304,12 +1304,15 @@ ivas_error ivas_core_enc( f2me_buf_16( hCPE->hStereoICBWE->shbSynthRef, hCPE->hStereoICBWE->shbSynthRef_fx, &hCPE->hStereoICBWE->shbSynthRef_e, L_LOOK_16k ); // shb_speech_ref_e f2me( hCPE->hStereoICBWE->icbweRefEner, &hCPE->hStereoICBWE->icbweRefEner_fx, &hCPE->hStereoICBWE->icbweRefEner_e ); - scale_factor = Q_factor_arrL( hCPE->hStereoICBWE->lpSHBRef, LPC_SHB_ORDER + 1 ) - 1; scale_factor = s_min( scale_factor, Q_factor_arrL( hCPE->hStereoICBWE->mem_lpc_shbsynth_nonref, LPC_SHB_ORDER ) ); - floatToFixed_arr32( hCPE->hStereoICBWE->lpSHBRef, hCPE->hStereoICBWE->lpSHBRef_fx, scale_factor, LPC_SHB_ORDER + 1 ); floatToFixed_arr32( hCPE->hStereoICBWE->mem_lpc_shbsynth_nonref, hCPE->hStereoICBWE->mem_lpc_shbsynth_nonref_fx, scale_factor, LPC_SHB_ORDER ); +#ifdef MSAN_FIX + f2me_buf( hCPE->hStereoICBWE->lpSHBRef, hCPE->hStereoICBWE->lpSHBRef_fx, &hCPE->hStereoICBWE->lpSHBRef_e, LPC_SHB_ORDER + 1 ); +#else + scale_factor = Q_factor_arrL( hCPE->hStereoICBWE->lpSHBRef, LPC_SHB_ORDER + 1 ) - 1; + floatToFixed_arr32( hCPE->hStereoICBWE->lpSHBRef, hCPE->hStereoICBWE->lpSHBRef_fx, scale_factor, LPC_SHB_ORDER + 1 ); hCPE->hStereoICBWE->lpSHBRef_e = 31 - scale_factor; - +#endif #endif stereo_icBWE_enc_ivas_fx( hCPE, shb_speech_fx32, 31 - q_shb_speech_fx32, new_swb_speech_buffer_fx, 31 - q_new_swb_speech_buffer, voice_factors_fx32[0] ); diff --git a/lib_enc/ivas_core_pre_proc_front.c b/lib_enc/ivas_core_pre_proc_front.c index 917c185cd..3cdbd36a0 100644 --- a/lib_enc/ivas_core_pre_proc_front.c +++ b/lib_enc/ivas_core_pre_proc_front.c @@ -1091,7 +1091,19 @@ ivas_error pre_proc_front_ivas_fx( Word16 realBuffer16[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; Word16 imagBuffer16[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; Word32 realBuffer_fx[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; +#ifdef MSAN_FIX + for ( Word16 k = 0; k < CLDFB_NO_COL_MAX; k++ ) + { + set32_fx( realBuffer_fx[k], 0, CLDFB_NO_CHANNELS_MAX ); + } +#endif Word32 imagBuffer_fx[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; +#ifdef MSAN_FIX + for ( Word16 k = 0; k < CLDFB_NO_COL_MAX; k++ ) + { + set32_fx( imagBuffer_fx[k], 0, CLDFB_NO_CHANNELS_MAX ); + } +#endif Word16 sf_energySum[CLDFB_NO_CHANNELS_MAX]; Word16 max_e; diff --git a/lib_enc/ivas_cpe_enc.c b/lib_enc/ivas_cpe_enc.c index 62fb9ae70..7f79fdbc2 100644 --- a/lib_enc/ivas_cpe_enc.c +++ b/lib_enc/ivas_cpe_enc.c @@ -240,6 +240,9 @@ ivas_error ivas_cpe_enc( move16(); Word16 front_create_flag = 0; move16(); +#ifdef MSAN_FIX + set_f( band_energies_LR, 0, 2 * NB_BANDS ); +#endif #ifdef IVAS_FLOAT_FIXED_CONVERSIONS for ( n = 0; n < CPE_CHANNELS; n++ ) { diff --git a/lib_enc/ivas_spar_encoder.c b/lib_enc/ivas_spar_encoder.c index 582595208..6777a8527 100644 --- a/lib_enc/ivas_spar_encoder.c +++ b/lib_enc/ivas_spar_encoder.c @@ -933,14 +933,14 @@ static ivas_error ivas_spar_cov_md_process( { for ( i = 0; i < IVAS_SPAR_MAX_CH - 1; i++ ) { - hSpar->hMdEnc->spar_md.band_coeffs[b].P_re[i] = fixedToFloat_32( hSpar->hMdEnc->spar_md.band_coeffs[b].P_re_fx[i], Q22 ); - hSpar->hMdEnc->spar_md.band_coeffs[b].pred_re[i] = fixedToFloat_32( hSpar->hMdEnc->spar_md.band_coeffs[b].pred_re_fx[i], Q22 ); + hSpar->hMdEnc->spar_md.band_coeffs[b].P_re[i] = fixedToFloat_32( hSpar->hMdEnc->spar_md.band_coeffs[b].P_re_fx[i], hSpar->hMdEnc->spar_md.band_coeffs[b].q_P_re_fx ); + hSpar->hMdEnc->spar_md.band_coeffs[b].pred_re[i] = fixedToFloat_32( hSpar->hMdEnc->spar_md.band_coeffs[b].pred_re_fx[i], hSpar->hMdEnc->spar_md.band_coeffs[b].q_pred_re_fx ); } for ( i = 0; i < IVAS_SPAR_MAX_CH - IVAS_SPAR_MAX_DMX_CHS; i++ ) { for ( j = 0; j < IVAS_SPAR_MAX_DMX_CHS - 1; j++ ) { - hSpar->hMdEnc->spar_md.band_coeffs[b].C_re[i][j] = fixedToFloat_32( hSpar->hMdEnc->spar_md.band_coeffs[b].C_re_fx[i][j], Q22 ); + hSpar->hMdEnc->spar_md.band_coeffs[b].C_re[i][j] = fixedToFloat_32( hSpar->hMdEnc->spar_md.band_coeffs[b].C_re_fx[i][j], hSpar->hMdEnc->spar_md.band_coeffs[b].q_C_re_fx ); } } } diff --git a/lib_enc/ivas_spar_md_enc.c b/lib_enc/ivas_spar_md_enc.c index 4e8a5ba3f..13c9bdc0a 100644 --- a/lib_enc/ivas_spar_md_enc.c +++ b/lib_enc/ivas_spar_md_enc.c @@ -754,8 +754,8 @@ ivas_error ivas_spar_md_enc_process_fx( ) { Word32 pred_coeffs_re_fx[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS]; - float dm_fv_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS]; Word32 dm_fv_re_fx[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS]; + Word16 q_dm_fv_re; Word16 i, j, b, qsi, ndm, ndec, num_ch, num_quant_strats; Word32 pred_coeffs_re_local_fx[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS]; Word16 k, bwidth, num_bands, num_bands_full, num_bands_bw; @@ -768,7 +768,12 @@ ivas_error ivas_spar_md_enc_process_fx( Indice *ind_list_tmp; Word16 md_indices_allocated; Word16 max_num_indices_tmp; + Word32 Wscale_fx[IVAS_MAX_NUM_BANDS]; + Word16 q_Wscale[IVAS_MAX_NUM_BANDS]; +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS float Wscale[IVAS_MAX_NUM_BANDS]; + float dm_fv_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS]; +#endif /*extra 16 bits for arithmetic coder as overshoot check is after a symbol is written*/ md_indices_allocated = add( hMdEnc->spar_md_cfg.max_bits_per_blk, IVAS_SPAR_ARITH_OVERSHOOT_BITS ); @@ -919,7 +924,77 @@ ivas_error ivas_spar_md_enc_process_fx( } #endif +#ifdef IVAS_FLOAT_FIXED +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + + for ( i = 0; i < num_ch; i++ ) + { + for ( j = 0; j < num_ch; j++ ) + { + for ( k = 0; k < IVAS_MAX_NUM_BANDS; k++ ) + { + f2me( cov_real[i][j][k], &cov_real_fx[i][j][k], &cov_real_q[i][j][k] ); + cov_real_q[i][j][k] = 31 - cov_real_q[i][j][k]; + } + } + } + +#endif + ivas_compute_spar_params_enc_fx( cov_real_fx, cov_real_q, dm_fv_re_fx, &q_dm_fv_re, 0, hMdEnc->mixer_mat_fx, &hMdEnc->q_mixer_mat_fx, 0, nB, dtx_vad, num_ch, bands_bw, active_w, active_w_vlbr, &hMdEnc->spar_md_cfg, &hMdEnc->spar_md, Wscale_fx, q_Wscale, 0, dyn_active_w_flag ); +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + for ( i = 0; i < num_ch - 1; i++ ) + { + for ( j = 0; j < nB; j++ ) + { + dm_fv_re[i][j] = fixedToFloat_32( dm_fv_re_fx[i][j], q_dm_fv_re ); + } + } + for ( i = 0; i < num_ch; i++ ) + { + for ( j = 0; j < num_ch; j++ ) + { + for ( b = 0; b < nB; b++ ) + { + hMdEnc->mixer_mat[i][j][b] = fixedToFloat_32( hMdEnc->mixer_mat_fx[i][j][b], hMdEnc->q_mixer_mat_fx ); + } + } + } + Word16 q_tmp; + for ( b = 0; b < nB; b++ ) + { + Wscale[b] = fixedToFloat_32( Wscale_fx[b], q_Wscale[b] ); + for ( i = 0; i < num_ch - 1; i++ ) + { + q_tmp = hMdEnc->spar_md.band_coeffs[b].q_pred_re_fx; + hMdEnc->spar_md.band_coeffs[b].pred_re[i] = fixedToFloat_32( hMdEnc->spar_md.band_coeffs[b].pred_re_fx[i], q_tmp ); + } + + ndm = hMdEnc->spar_md_cfg.num_dmx_chans_per_band[b * bands_bw]; + if ( ndm != num_ch ) + { + for ( i = 0; i < num_ch - ndm; i++ ) + { + q_tmp = hMdEnc->spar_md.band_coeffs[b].q_P_re_fx; + hMdEnc->spar_md.band_coeffs[b].P_re[i] = fixedToFloat_32( hMdEnc->spar_md.band_coeffs[b].P_re_fx[i], q_tmp ); + } + if ( ndm != 1 ) + { + for ( i = 0; i < num_ch - ndm; i++ ) + { + for ( j = 0; j < ndm - 1; j++ ) + { + q_tmp = hMdEnc->spar_md.band_coeffs[b].q_C_re_fx; + hMdEnc->spar_md.band_coeffs[b].C_re[i][j] = fixedToFloat_32( hMdEnc->spar_md.band_coeffs[b].C_re_fx[i][j], q_tmp ); + } + } + } + } + } +#endif +#else ivas_compute_spar_params( cov_real, dm_fv_re, 0, hMdEnc->mixer_mat, 0, nB, dtx_vad, num_ch, bands_bw, active_w, active_w_vlbr, &hMdEnc->spar_md_cfg, &hMdEnc->spar_md, Wscale, 0, dyn_active_w_flag ); +#endif + #ifdef IVAS_FLOAT_FIXED_CONVERSIONS for ( b = 0; b < num_bands; b++ ) { @@ -1070,7 +1145,6 @@ ivas_error ivas_spar_md_enc_process_fx( hMdEnc->spar_md.band_coeffs[b].P_quant_re[ii] = fix_to_float( hMdEnc->spar_md.band_coeffs[b].P_quant_re_fx[ii], Q28 ); } } - Word32 Wscale_fx[IVAS_MAX_NUM_BANDS]; Word16 Wscale_e, dm_fv_re_q = Q31, mixer_q = Q31; f2me_buf( Wscale, Wscale_fx, &Wscale_e, (Word32) num_bands ); diff --git a/lib_rend/ivas_efap.c b/lib_rend/ivas_efap.c index 1b0f31f9b..ddaf6a41a 100644 --- a/lib_rend/ivas_efap.c +++ b/lib_rend/ivas_efap.c @@ -2626,6 +2626,10 @@ static void efap_panning_fx( move32(); P[1] = ele; move32(); + set32_fx( tmpBuff, 0, EFAP_MAX_CHAN_NUM ); + set32_fx( aziPoly, 0, EFAP_MAX_CHAN_NUM ); + set32_fx( elePoly, 0, EFAP_MAX_CHAN_NUM ); + set16_fx( chan, 0, EFAP_MAX_CHAN_NUM ); /* Finding in which polygon the point is */ polyIdx = get_poly_num_fx( P, polyData ); diff --git a/lib_rend/ivas_objectRenderer_vec.c b/lib_rend/ivas_objectRenderer_vec.c index 5491d10bc..a83637fc2 100644 --- a/lib_rend/ivas_objectRenderer_vec.c +++ b/lib_rend/ivas_objectRenderer_vec.c @@ -142,7 +142,7 @@ void TDREND_SPATIAL_VecNormalize( #ifdef IVAS_FLOAT_FIXED void TDREND_SPATIAL_VecNormalize_fx( - const Word32 *Vec_p_fx, /* i : Input vector Qx */ + const Word32 *Vec_p_fx, /* i : Input vector q */ Word16 q, /* i : Input vector Q-factor */ Word32 *VecNorm_p_fx /* o : Normalised output vector Q30 */ ) @@ -155,21 +155,21 @@ void TDREND_SPATIAL_VecNormalize_fx( exp = shl( sub( 31, q ), 1 ); scaler_fx = ISqrt32( sqrd_sum, &exp ); - VecNorm_p_fx[0] = Mpy_32_32( scaler_fx, Vec_p_fx[0] ); + VecNorm_p_fx[0] = Mpy_32_32( scaler_fx, Vec_p_fx[0] ); // Q: ( q + ( 31 - exp ) ) - 31 move32(); - VecNorm_p_fx[1] = Mpy_32_32( scaler_fx, Vec_p_fx[1] ); + VecNorm_p_fx[1] = Mpy_32_32( scaler_fx, Vec_p_fx[1] ); // Q: ( q + ( 31 - exp ) ) - 31 move32(); - VecNorm_p_fx[2] = Mpy_32_32( scaler_fx, Vec_p_fx[2] ); + VecNorm_p_fx[2] = Mpy_32_32( scaler_fx, Vec_p_fx[2] ); // Q: ( q + ( 31 - exp ) ) - 31 move32(); exp = add( exp, sub( 31, q ) ); // Since vector is normalised, all values will be <= 1. Hence making all values in Q30 shift = sub( exp, 1 ); - VecNorm_p_fx[0] = L_shl( VecNorm_p_fx[0], shift ); + VecNorm_p_fx[0] = L_shl( VecNorm_p_fx[0], shift ); // Q30 move32(); - VecNorm_p_fx[1] = L_shl( VecNorm_p_fx[1], shift ); + VecNorm_p_fx[1] = L_shl( VecNorm_p_fx[1], shift ); // Q30 move32(); - VecNorm_p_fx[2] = L_shl( VecNorm_p_fx[2], shift ); + VecNorm_p_fx[2] = L_shl( VecNorm_p_fx[2], shift ); // Q30 move32(); return; @@ -197,11 +197,11 @@ void TDREND_SPATIAL_VecMapToNewCoordSystem_fx( v_sub_32( Vec_p, TranslVec_p, LisRelPosAbs, 3 ); /* Evalute the relative Vec in the coordinates of the Orientation vectors, */ /* which form an orthonormal basis */ - MappedVec_p[0] = dotp_fixed( LisRelPosAbs, DirVec_p, 3 ); + MappedVec_p[0] = dotp_fixed( LisRelPosAbs, DirVec_p, 3 ); // Q: Qy + Qy - Q31 move32(); - MappedVec_p[1] = dotp_fixed( LisRelPosAbs, RightVec_p, 3 ); + MappedVec_p[1] = dotp_fixed( LisRelPosAbs, RightVec_p, 3 ); // Q: Qy + Qy - Q31 move32(); - MappedVec_p[2] = dotp_fixed( LisRelPosAbs, UpVec_p, 3 ); + MappedVec_p[2] = dotp_fixed( LisRelPosAbs, UpVec_p, 3 ); // Q: Qy + Qy - Q31 move32(); return; } @@ -285,15 +285,15 @@ int16_t TDREND_SPATIAL_EvalOrthonormOrient( #ifdef IVAS_FLOAT_FIXED Word16 TDREND_SPATIAL_EvalOrthonormOrient_fx( - Word32 *FrontVecON_p_fx, /* i/o: Normalized front vector Q30 */ - Word32 *UpVecON_p_fx, /* i/o: Normalized up vector Q30 */ - Word32 *RightVecON_p_fx, /* i/o: Normalized right vector Q30 */ - const Word32 *FrontVec_p_fx, /* i : Input front vector */ - const Word32 *UpVec_p_fx, /* i : Input up vector */ - const Word16 orient_q /* i : Input up Q-factor */ + Word32 *FrontVecON_p_fx, /* i/o: Normalized front vector Q30 */ + Word32 *UpVecON_p_fx, /* i/o: Normalized up vector Q30 */ + Word32 *RightVecON_p_fx, /* i/o: Normalized right vector Q30 */ + const Word32 *FrontVec_p_fx, /* i : Input front vector Qx */ + const Word32 *UpVec_p_fx, /* i : Input up vector orient_q */ + const Word16 orient_q /* i : Input up Q-factor */ ) { - Word32 tmp_fx[9]; + Word32 tmp_fx[9]; // Q30 Word16 orientation_updated; orientation_updated = FALSE; @@ -310,22 +310,22 @@ Word16 TDREND_SPATIAL_EvalOrthonormOrient_fx( /* Evaluate the orthonormal right vector */ /* through the cross product of the front and the up vectors */ - RightVecON_p_fx[0] = L_shl_sat( L_sub( Mpy_32_32( FrontVecON_p_fx[1], UpVec_p_fx[2] ), Mpy_32_32( FrontVecON_p_fx[2], UpVec_p_fx[1] ) ), 1 ); + RightVecON_p_fx[0] = L_shl_sat( L_sub( Mpy_32_32( FrontVecON_p_fx[1], UpVec_p_fx[2] ), Mpy_32_32( FrontVecON_p_fx[2], UpVec_p_fx[1] ) ), 1 ); // Q: ( Q30 + Q30 - Q31 ) + Q1 -> Q30 move32(); - RightVecON_p_fx[1] = L_shl_sat( L_sub( Mpy_32_32( FrontVecON_p_fx[2], UpVec_p_fx[0] ), Mpy_32_32( FrontVecON_p_fx[0], UpVec_p_fx[2] ) ), 1 ); + RightVecON_p_fx[1] = L_shl_sat( L_sub( Mpy_32_32( FrontVecON_p_fx[2], UpVec_p_fx[0] ), Mpy_32_32( FrontVecON_p_fx[0], UpVec_p_fx[2] ) ), 1 ); // Q: ( Q30 + Q30 - Q31 ) + Q1 -> Q30 move32(); - RightVecON_p_fx[2] = L_shl_sat( L_sub( Mpy_32_32( FrontVecON_p_fx[0], UpVec_p_fx[1] ), Mpy_32_32( FrontVecON_p_fx[1], UpVec_p_fx[0] ) ), 1 ); + RightVecON_p_fx[2] = L_shl_sat( L_sub( Mpy_32_32( FrontVecON_p_fx[0], UpVec_p_fx[1] ), Mpy_32_32( FrontVecON_p_fx[1], UpVec_p_fx[0] ) ), 1 ); // Q: ( Q30 + Q30 - Q31 ) + Q1 -> Q30 move32(); TDREND_SPATIAL_VecNormalize_fx( RightVecON_p_fx, orient_q, RightVecON_p_fx ); // RightVecON_p_fx -> Q30 /* Evaluate the orthonormal up vector */ /* through the cross product of the front and the right vectors */ - UpVecON_p_fx[0] = L_shl_sat( L_sub( Mpy_32_32( RightVecON_p_fx[1], FrontVecON_p_fx[2] ), Mpy_32_32( RightVecON_p_fx[2], FrontVecON_p_fx[1] ) ), 1 ); + UpVecON_p_fx[0] = L_shl_sat( L_sub( Mpy_32_32( RightVecON_p_fx[1], FrontVecON_p_fx[2] ), Mpy_32_32( RightVecON_p_fx[2], FrontVecON_p_fx[1] ) ), 1 ); // Q: ( Q30 + Q30 - Q31 ) + Q1 -> Q30 move32(); - UpVecON_p_fx[1] = L_shl_sat( L_sub( Mpy_32_32( RightVecON_p_fx[2], FrontVecON_p_fx[0] ), Mpy_32_32( RightVecON_p_fx[0], FrontVecON_p_fx[2] ) ), 1 ); + UpVecON_p_fx[1] = L_shl_sat( L_sub( Mpy_32_32( RightVecON_p_fx[2], FrontVecON_p_fx[0] ), Mpy_32_32( RightVecON_p_fx[0], FrontVecON_p_fx[2] ) ), 1 ); // Q: ( Q30 + Q30 - Q31 ) + Q1 -> Q30 move32(); - UpVecON_p_fx[2] = L_shl_sat( L_sub( Mpy_32_32( RightVecON_p_fx[0], FrontVecON_p_fx[1] ), Mpy_32_32( RightVecON_p_fx[1], FrontVecON_p_fx[0] ) ), 1 ); + UpVecON_p_fx[2] = L_shl_sat( L_sub( Mpy_32_32( RightVecON_p_fx[0], FrontVecON_p_fx[1] ), Mpy_32_32( RightVecON_p_fx[1], FrontVecON_p_fx[0] ) ), 1 ); // Q: ( Q30 + Q30 - Q31 ) + Q1 -> Q30 move32(); TDREND_SPATIAL_VecNormalize_fx( UpVecON_p_fx, orient_q, UpVecON_p_fx ); // UpVecON_p_fx -> Q30 diff --git a/lib_rend/ivas_omasa_ana.c b/lib_rend/ivas_omasa_ana.c index da163f570..1d7e191b4 100644 --- a/lib_rend/ivas_omasa_ana.c +++ b/lib_rend/ivas_omasa_ana.c @@ -124,7 +124,7 @@ ivas_error ivas_omasa_ana_open( Copy( MASA_band_grouping_24, hOMasa->band_grouping, 24 + 1 ); /* maxBin = (int16_t) ( input_Fs * INV_CLDFB_BANDWIDTH + 0.5f ); */ - maxBin = extract_l( Mpy_32_32( input_Fs, 2684355 /* INV_CLDFB_BANDWIDTH in Q31 */ ) ); + maxBin = extract_l( Mpy_32_32( input_Fs, 2684355 /* INV_CLDFB_BANDWIDTH in Q31 */ ) ); // Q: ( ( Q0 + Q31 ) - Q31 ) -> Q0 FOR( i = 1; i < hOMasa->nbands + 1; i++ ) { @@ -853,9 +853,9 @@ static void ivas_omasa_param_est_ana_fx( FOR( Word16 ind = 0; ind < CLDFB_NO_CHANNELS_MAX; ind++ ) { - Chnl_RealBuffer_fx[i][ind] = L_shr( Chnl_RealBuffer_fx[i][ind], 4 ); + Chnl_RealBuffer_fx[i][ind] = L_shr( Chnl_RealBuffer_fx[i][ind], 4 ); // Q: in_q - 4 move32(); - Chnl_ImagBuffer_fx[i][ind] = L_shr( Chnl_ImagBuffer_fx[i][ind], 4 ); + Chnl_ImagBuffer_fx[i][ind] = L_shr( Chnl_ImagBuffer_fx[i][ind], 4 ); // Q: in_q - 4 move32(); } @@ -875,8 +875,8 @@ static void ivas_omasa_param_est_ana_fx( { FOR( i = 0; i < nchan_ism; i++ ) { - L_tmp1 = Mpy_32_32( Chnl_RealBuffer_fx[i][j], Chnl_RealBuffer_fx[i][j] ); - L_tmp2 = Mpy_32_32( Chnl_ImagBuffer_fx[i][j], Chnl_ImagBuffer_fx[i][j] ); + L_tmp1 = Mpy_32_32( Chnl_RealBuffer_fx[i][j], Chnl_RealBuffer_fx[i][j] ); // Chnl_RealBuffer_q + Chnl_RealBuffer_q - 31 + L_tmp2 = Mpy_32_32( Chnl_ImagBuffer_fx[i][j], Chnl_ImagBuffer_fx[i][j] ); // Chnl_ImagBuffer_q + Chnl_ImagBuffer_q - 31 hOMasa->energy_fx[block_m_idx][band_m_idx] = L_add( hOMasa->energy_fx[block_m_idx][band_m_idx], L_add( L_tmp1, L_tmp2 ) ); // Chnl_RealBuffer_q + Chnl_RealBuffer_q - 31 move32(); hOMasa->energy_q = sub( add( Chnl_RealBuffer_q, Chnl_RealBuffer_q ), 31 ); @@ -893,39 +893,39 @@ static void ivas_omasa_param_est_ana_fx( FOR( i = 1; i < nchan_ism; i++ ) { - v_add_fixed( Chnl_RealBuffer_fx[i], Foa_RealBuffer_fx[0], Foa_RealBuffer_fx[0], num_freq_bins, 0 ); - v_add_fixed( Chnl_ImagBuffer_fx[i], Foa_ImagBuffer_fx[0], Foa_ImagBuffer_fx[0], num_freq_bins, 0 ); + v_add_fixed( Chnl_RealBuffer_fx[i], Foa_RealBuffer_fx[0], Foa_RealBuffer_fx[0], num_freq_bins, 0 ); // Q: Chnl_RealBuffer_q + v_add_fixed( Chnl_ImagBuffer_fx[i], Foa_ImagBuffer_fx[0], Foa_ImagBuffer_fx[0], num_freq_bins, 0 ); // Q: Chnl_ImagBuffer_q } /* Y */ - v_multc_fixed( Chnl_RealBuffer_fx[0], L_deposit_h( hOMasa->chnlToFoaMtx_fx[1][0] ), Foa_RealBuffer_fx[1], num_freq_bins ); - v_multc_fixed( Chnl_ImagBuffer_fx[0], L_deposit_h( hOMasa->chnlToFoaMtx_fx[1][0] ), Foa_ImagBuffer_fx[1], num_freq_bins ); + v_multc_fixed( Chnl_RealBuffer_fx[0], L_deposit_h( hOMasa->chnlToFoaMtx_fx[1][0] ), Foa_RealBuffer_fx[1], num_freq_bins ); // Q: Chnl_RealBuffer_q + v_multc_fixed( Chnl_ImagBuffer_fx[0], L_deposit_h( hOMasa->chnlToFoaMtx_fx[1][0] ), Foa_ImagBuffer_fx[1], num_freq_bins ); // Q: Chnl_ImagBuffer_q FOR( i = 1; i < nchan_ism; i++ ) { - v_multc_acc_32_16( Chnl_RealBuffer_fx[i], hOMasa->chnlToFoaMtx_fx[1][i], Foa_RealBuffer_fx[1], num_freq_bins ); - v_multc_acc_32_16( Chnl_ImagBuffer_fx[i], hOMasa->chnlToFoaMtx_fx[1][i], Foa_ImagBuffer_fx[1], num_freq_bins ); + v_multc_acc_32_16( Chnl_RealBuffer_fx[i], hOMasa->chnlToFoaMtx_fx[1][i], Foa_RealBuffer_fx[1], num_freq_bins ); // Q: Chnl_RealBuffer_q + v_multc_acc_32_16( Chnl_ImagBuffer_fx[i], hOMasa->chnlToFoaMtx_fx[1][i], Foa_ImagBuffer_fx[1], num_freq_bins ); // Q: Chnl_ImagBuffer_q } /* Z */ - v_multc_fixed( Chnl_RealBuffer_fx[0], L_deposit_h( hOMasa->chnlToFoaMtx_fx[2][0] ), Foa_RealBuffer_fx[2], num_freq_bins ); - v_multc_fixed( Chnl_ImagBuffer_fx[0], L_deposit_h( hOMasa->chnlToFoaMtx_fx[2][0] ), Foa_ImagBuffer_fx[2], num_freq_bins ); + v_multc_fixed( Chnl_RealBuffer_fx[0], L_deposit_h( hOMasa->chnlToFoaMtx_fx[2][0] ), Foa_RealBuffer_fx[2], num_freq_bins ); // Q: Chnl_RealBuffer_q + v_multc_fixed( Chnl_ImagBuffer_fx[0], L_deposit_h( hOMasa->chnlToFoaMtx_fx[2][0] ), Foa_ImagBuffer_fx[2], num_freq_bins ); // Q: Chnl_ImagBuffer_q FOR( i = 1; i < nchan_ism; i++ ) { - v_multc_acc_32_16( Chnl_RealBuffer_fx[i], hOMasa->chnlToFoaMtx_fx[2][i], Foa_RealBuffer_fx[2], num_freq_bins ); - v_multc_acc_32_16( Chnl_ImagBuffer_fx[i], hOMasa->chnlToFoaMtx_fx[2][i], Foa_ImagBuffer_fx[2], num_freq_bins ); + v_multc_acc_32_16( Chnl_RealBuffer_fx[i], hOMasa->chnlToFoaMtx_fx[2][i], Foa_RealBuffer_fx[2], num_freq_bins ); // Q: Chnl_RealBuffer_q + v_multc_acc_32_16( Chnl_ImagBuffer_fx[i], hOMasa->chnlToFoaMtx_fx[2][i], Foa_ImagBuffer_fx[2], num_freq_bins ); // Q: Chnl_ImagBuffer_q } - v_multc_fixed( Chnl_RealBuffer_fx[0], L_deposit_h( hOMasa->chnlToFoaMtx_fx[3][0] ), Foa_RealBuffer_fx[2], num_freq_bins ); - v_multc_fixed( Chnl_ImagBuffer_fx[0], L_deposit_h( hOMasa->chnlToFoaMtx_fx[3][0] ), Foa_ImagBuffer_fx[2], num_freq_bins ); + v_multc_fixed( Chnl_RealBuffer_fx[0], L_deposit_h( hOMasa->chnlToFoaMtx_fx[3][0] ), Foa_RealBuffer_fx[2], num_freq_bins ); // Q: Chnl_RealBuffer_q + v_multc_fixed( Chnl_ImagBuffer_fx[0], L_deposit_h( hOMasa->chnlToFoaMtx_fx[3][0] ), Foa_ImagBuffer_fx[2], num_freq_bins ); // Q: Chnl_ImagBuffer_q FOR( i = 1; i < nchan_ism; i++ ) { - v_multc_acc_32_16( Chnl_RealBuffer_fx[i], hOMasa->chnlToFoaMtx_fx[3][i], Foa_RealBuffer_fx[3], num_freq_bins ); - v_multc_acc_32_16( Chnl_ImagBuffer_fx[i], hOMasa->chnlToFoaMtx_fx[3][i], Foa_ImagBuffer_fx[3], num_freq_bins ); + v_multc_acc_32_16( Chnl_RealBuffer_fx[i], hOMasa->chnlToFoaMtx_fx[3][i], Foa_RealBuffer_fx[3], num_freq_bins ); // Q: Chnl_RealBuffer_q + v_multc_acc_32_16( Chnl_ImagBuffer_fx[i], hOMasa->chnlToFoaMtx_fx[3][i], Foa_ImagBuffer_fx[3], num_freq_bins ); // Q: Chnl_ImagBuffer_q } /* Direction estimation */ @@ -933,9 +933,9 @@ static void ivas_omasa_param_est_ana_fx( { FOR( j = 0; j < CLDFB_NO_CHANNELS_MAX; j++ ) { - Foa_RealBuffer_fx[i][j] = L_shr( Foa_RealBuffer_fx[i][j], 5 ); + Foa_RealBuffer_fx[i][j] = L_shr( Foa_RealBuffer_fx[i][j], 5 ); // Q: ( Chnl_RealBuffer_q - 5 ) move32(); - Foa_ImagBuffer_fx[i][j] = L_shr( Foa_ImagBuffer_fx[i][j], 5 ); + Foa_ImagBuffer_fx[i][j] = L_shr( Foa_ImagBuffer_fx[i][j], 5 ); // Q: ( Chnl_RealBuffer_q - 5 ) move32(); } } @@ -948,7 +948,7 @@ static void ivas_omasa_param_est_ana_fx( /* Power estimation for diffuseness */ - computeReferencePower_ana_fx( hOMasa->band_grouping, Foa_RealBuffer_fx, Foa_ImagBuffer_fx, reference_power_fx, num_freq_bands ); // 2*inputq - 30 + computeReferencePower_ana_fx( hOMasa->band_grouping, Foa_RealBuffer_fx, Foa_ImagBuffer_fx, reference_power_fx, num_freq_bands ); // 2 * inputq - 30 reference_power_q = sub( shl( Chnl_ImagBuffer_q, 1 ), 30 ); /* Fill buffers of length "averaging_length" time slots for intensity and energy */ @@ -960,33 +960,33 @@ static void ivas_omasa_param_est_ana_fx( FOR( i = 0; i < DIRAC_NUM_DIMS; i++ ) { /* only real part needed */ - Copy32( intensity_real_fx[i], &( hOMasa->buffer_intensity_real_fx[i][sub( index, 1 )][0] ), num_freq_bands ); + Copy32( intensity_real_fx[i], &( hOMasa->buffer_intensity_real_fx[i][index - 1][0] ), num_freq_bands ); // intensity_q } - hOMasa->buffer_intensity_real_q[sub( index, 1 )] = intensity_q; + hOMasa->buffer_intensity_real_q[index - 1] = intensity_q; move16(); - Copy32( reference_power_fx, &( hOMasa->buffer_energy_fx[i_mult( sub( index, 1 ), num_freq_bands )] ), num_freq_bands ); - hOMasa->buffer_energy_q[sub( index, 1 )] = reference_power_q; + Copy32( reference_power_fx, &( hOMasa->buffer_energy_fx[( index - 1 ) * num_freq_bands] ), num_freq_bands ); + hOMasa->buffer_energy_q[index - 1] = reference_power_q; move16(); computeDiffuseness_fixed( hOMasa->buffer_intensity_real_fx, hOMasa->buffer_energy_fx, num_freq_bands, diffuseness_vector_fx, hOMasa->buffer_intensity_real_q, hOMasa->buffer_energy_q, &diffuseness_q ); FOR( band_m_idx = 0; band_m_idx < hOMasa->nbands; band_m_idx++ ) { - norm_tmp_fx = Mpy_32_32( reference_power_fx[band_m_idx], L_sub( 1073741824, diffuseness_vector_fx[band_m_idx] ) ); // reference_power_q + 30 - 31 + norm_tmp_fx = Mpy_32_32( reference_power_fx[band_m_idx], L_sub( ONE_IN_Q30, diffuseness_vector_fx[band_m_idx] ) ); // reference_power_q + 30 - 31 norm_tmp_q = sub( add( reference_power_q, 30 ), 31 ); - hOMasa->direction_vector_m_fx[0][block_m_idx][band_m_idx] = L_add( hOMasa->direction_vector_m_fx[0][block_m_idx][band_m_idx], Mpy_32_32( norm_tmp_fx, direction_vector_fx[0][band_m_idx] ) ); + hOMasa->direction_vector_m_fx[0][block_m_idx][band_m_idx] = L_add( hOMasa->direction_vector_m_fx[0][block_m_idx][band_m_idx], Mpy_32_32( norm_tmp_fx, direction_vector_fx[0][band_m_idx] ) ); // Q: hOMasa->direction_vector_m_q: ( ( norm_tmp_q + direction_q ) - 31 ) move32(); - hOMasa->direction_vector_m_fx[1][block_m_idx][band_m_idx] = L_add( hOMasa->direction_vector_m_fx[0][block_m_idx][band_m_idx], Mpy_32_32( norm_tmp_fx, direction_vector_fx[1][band_m_idx] ) ); + hOMasa->direction_vector_m_fx[1][block_m_idx][band_m_idx] = L_add( hOMasa->direction_vector_m_fx[0][block_m_idx][band_m_idx], Mpy_32_32( norm_tmp_fx, direction_vector_fx[1][band_m_idx] ) ); // Q: hOMasa->direction_vector_m_q: ( ( norm_tmp_q + direction_q ) - 31 ) move32(); - hOMasa->direction_vector_m_fx[2][block_m_idx][band_m_idx] = L_add( hOMasa->direction_vector_m_fx[0][block_m_idx][band_m_idx], Mpy_32_32( norm_tmp_fx, direction_vector_fx[2][band_m_idx] ) ); + hOMasa->direction_vector_m_fx[2][block_m_idx][band_m_idx] = L_add( hOMasa->direction_vector_m_fx[0][block_m_idx][band_m_idx], Mpy_32_32( norm_tmp_fx, direction_vector_fx[2][band_m_idx] ) ); // Q: hOMasa->direction_vector_m_q: ( ( norm_tmp_q + direction_q ) - 31 ) move32(); hOMasa->direction_vector_m_q = sub( add( norm_tmp_q, direction_q ), 31 ); - diffuseness_m_fx[band_m_idx] = L_add( diffuseness_m_fx[band_m_idx], Mpy_32_32( reference_power_fx[band_m_idx], diffuseness_vector_fx[band_m_idx] ) ); + diffuseness_m_fx[band_m_idx] = L_add( diffuseness_m_fx[band_m_idx], Mpy_32_32( reference_power_fx[band_m_idx], diffuseness_vector_fx[band_m_idx] ) ); // diffuseness_m_q: ( ( reference_power_q + diffuseness_q ) - 31 ); move32(); diffuseness_m_q = sub( add( reference_power_q, diffuseness_q ), 31 ); renormalization_factor_diff_fx[band_m_idx] = L_add( renormalization_factor_diff_fx[band_m_idx], reference_power_fx[band_m_idx] ); @@ -1033,7 +1033,7 @@ static void ivas_omasa_param_est_ana_fx( diffuseness_m_fx[band_m_idx] = 0; move32(); } - energyRatio_fx[block_m_idx][band_m_idx] = L_sub( L_shl( 1, diffuseness_m_q ), diffuseness_m_fx[band_m_idx] ); + energyRatio_fx[block_m_idx][band_m_idx] = L_sub( L_shl( 1, diffuseness_m_q ), diffuseness_m_fx[band_m_idx] ); // Q: diffuseness_m_q move32(); } @@ -1092,8 +1092,8 @@ static void ivas_omasa_dmx_fx( FOR( i = 0; i < nchan_ism; i++ ) { - azimuth_fx = extract_l( L_shr( ism_azimuth_fx[i], Q22 ) ); - elevation_fx = extract_l( L_shr( ism_elevation_fx[i], Q22 ) ); + azimuth_fx = extract_l( L_shr( ism_azimuth_fx[i], Q22 ) ); // Q0 + elevation_fx = extract_l( L_shr( ism_elevation_fx[i], Q22 ) ); // Q0 ivas_ism_get_stereo_gains_fx( azimuth_fx, elevation_fx, &gains_fx[0], &gains_fx[1] ); @@ -1111,10 +1111,10 @@ static void ivas_omasa_dmx_fx( scale = BASOP_Util_Add_MantExp( 16384, 1, negate( g1_fx ), 0, &g2_fx ); tmp1 = mult( g1_fx, gains_fx[j] ); - tmp2 = mult( g2_fx, (Word16) L_shr( prev_gains_fx[i][j], 16 ) ); + tmp2 = mult( g2_fx, (Word16) L_shr( prev_gains_fx[i][j], 16 ) ); // Q: ( ( ( 15 - scale ) + ( Q31 - Q16 ) ) - Q15 ) -> ( 15 - scale ) scale = BASOP_Util_Add_MantExp( tmp1, 0, tmp2, scale, &tmp1 ); - L_tmp = data_in_f_fx[i][k]; + L_tmp = data_in_f_fx[i][k]; // data_in_q move32(); tmp_e = sub( 31, *data_in_q ); move16(); @@ -1139,7 +1139,7 @@ static void ivas_omasa_dmx_fx( FOR( l = 0; l < L_FRAME48k; l++ ) { - data_out_f_fx[j][l] = L_shr( data_out_f_fx[j][l], sub( max_e, in_e[l] ) ); + data_out_f_fx[j][l] = L_shr( data_out_f_fx[j][l], sub( max_e, in_e[l] ) ); // exponent: max_e, Q: ( 15 - max_e ) move32(); } data_e[j] = max_e; @@ -1165,7 +1165,7 @@ static void ivas_omasa_dmx_fx( { FOR( j = 0; j < input_frame; j++ ) { - data_out_f_fx[i][j] = L_shr( data_out_f_fx[i][j], sub( max_e, data_e[i] ) ); + data_out_f_fx[i][j] = L_shr( data_out_f_fx[i][j], sub( max_e, data_e[i] ) ); // exponent: max_e, Q: ( 15 - max_e ) move32(); } } @@ -1245,11 +1245,11 @@ static void ivas_omasa_dmx( *--------------------------------------------------------------------------*/ void computeIntensityVector_ana_fx( - const Word16 *band_grouping, /* i : Band grouping for estimation */ - Word32 Cldfb_RealBuffer[FOA_CHANNELS][CLDFB_NO_CHANNELS_MAX], /* i : Real part of input signal */ - Word32 Cldfb_ImagBuffer[FOA_CHANNELS][CLDFB_NO_CHANNELS_MAX], /* i : Imag part of input signal */ - const Word16 num_frequency_bands, /* i : Number of frequency bands */ - Word32 intensity_real[DIRAC_NUM_DIMS][MASA_FREQUENCY_BANDS] /* o : Intensity vector */ + const Word16 *band_grouping, /* i : Band grouping for estimation */ + Word32 Cldfb_RealBuffer[FOA_CHANNELS][CLDFB_NO_CHANNELS_MAX], /* i : Real part of input signal Qx */ + Word32 Cldfb_ImagBuffer[FOA_CHANNELS][CLDFB_NO_CHANNELS_MAX], /* i : Imag part of input sig Qx */ + const Word16 num_frequency_bands, /* i : Number of frequency bands */ + Word32 intensity_real[DIRAC_NUM_DIMS][MASA_FREQUENCY_BANDS] /* o : Intensity 2 * Qx -31 */ ) { /* Reminder @@ -1276,14 +1276,14 @@ void computeIntensityVector_ana_fx( FOR( j = brange[0]; j < brange[1]; j++ ) { - real = Cldfb_RealBuffer[0][j]; - img = Cldfb_ImagBuffer[0][j]; + real = Cldfb_RealBuffer[0][j]; // Qx + img = Cldfb_ImagBuffer[0][j]; // Qx /* Intensity is XYZ order, audio is WYZX order. */ - intensity_real[0][i] = L_add( intensity_real[0][i], L_add( Mpy_32_32( Cldfb_RealBuffer[3][j], real ), Mpy_32_32( Cldfb_ImagBuffer[3][j], img ) ) ); // output Q= 2* input_q -31 + intensity_real[0][i] = L_add( intensity_real[0][i], L_add( Mpy_32_32( Cldfb_RealBuffer[3][j], real ), Mpy_32_32( Cldfb_ImagBuffer[3][j], img ) ) ); // output Q = 2 * Qx -31 move32(); - intensity_real[1][i] = L_add( intensity_real[1][i], L_add( Mpy_32_32( Cldfb_RealBuffer[1][j], real ), Mpy_32_32( Cldfb_ImagBuffer[1][j], img ) ) ); // output Q= 2* input_q -31 + intensity_real[1][i] = L_add( intensity_real[1][i], L_add( Mpy_32_32( Cldfb_RealBuffer[1][j], real ), Mpy_32_32( Cldfb_ImagBuffer[1][j], img ) ) ); // output Q = 2 * Qx -31 move32(); - intensity_real[2][i] = L_add( intensity_real[2][i], L_add( Mpy_32_32( Cldfb_RealBuffer[2][j], real ), Mpy_32_32( Cldfb_ImagBuffer[2][j], img ) ) ); // output Q= 2* input_q -31 + intensity_real[2][i] = L_add( intensity_real[2][i], L_add( Mpy_32_32( Cldfb_RealBuffer[2][j], real ), Mpy_32_32( Cldfb_ImagBuffer[2][j], img ) ) ); // output Q = 2 * Qx -31 move32(); } } @@ -1345,11 +1345,11 @@ void computeIntensityVector_ana( *--------------------------------------------------------------------------*/ void computeReferencePower_ana_fx( - const Word16 *band_grouping, /* i : Band grouping for estimation */ - Word32 Cldfb_RealBuffer[FOA_CHANNELS][CLDFB_NO_CHANNELS_MAX], /* i : Real part of input signal */ - Word32 Cldfb_ImagBuffer[FOA_CHANNELS][CLDFB_NO_CHANNELS_MAX], /* i : Imag part of input signal */ - Word32 *reference_power, /* o : Estimated power */ - const Word16 num_freq_bands /* i : Number of frequency bands */ + const Word16 *band_grouping, /* i : Band grouping for estimation */ + Word32 Cldfb_RealBuffer[FOA_CHANNELS][CLDFB_NO_CHANNELS_MAX], /* i : Real part of input signal input_q */ + Word32 Cldfb_ImagBuffer[FOA_CHANNELS][CLDFB_NO_CHANNELS_MAX], /* i : Imag part of input signal input_q */ + Word32 *reference_power, /* o : Estimated power 2 * inputq - 31 */ + const Word16 num_freq_bands /* i : Number of frequency bands */ ) { Word16 brange[2]; diff --git a/lib_rend/ivas_orient_trk.c b/lib_rend/ivas_orient_trk.c index 7cc330e67..334f52ee3 100644 --- a/lib_rend/ivas_orient_trk.c +++ b/lib_rend/ivas_orient_trk.c @@ -125,13 +125,13 @@ void QuaternionProduct_fx( IVAS_QUATERNION tmp; // once verify// - tmp.w_fx = L_sub( ( L_sub( Mpy_32_32( q1.w_fx, q2.w_fx ), Mpy_32_32( q1.x_fx, q2.x_fx ) ) ), ( L_add( Mpy_32_32( q1.y_fx, q2.y_fx ), Mpy_32_32( q1.z_fx, q2.z_fx ) ) ) ); + tmp.w_fx = L_sub( ( L_sub( Mpy_32_32( q1.w_fx, q2.w_fx ), Mpy_32_32( q1.x_fx, q2.x_fx ) ) ), ( L_add( Mpy_32_32( q1.y_fx, q2.y_fx ), Mpy_32_32( q1.z_fx, q2.z_fx ) ) ) ); // ( q1.q_fact + q2.q_fact ) - 31 move32(); - tmp.x_fx = L_add( ( L_add( Mpy_32_32( q1.w_fx, q2.x_fx ), Mpy_32_32( q1.x_fx, q2.w_fx ) ) ), ( L_sub( Mpy_32_32( q1.y_fx, q2.z_fx ), Mpy_32_32( q1.z_fx, q2.y_fx ) ) ) ); + tmp.x_fx = L_add( ( L_add( Mpy_32_32( q1.w_fx, q2.x_fx ), Mpy_32_32( q1.x_fx, q2.w_fx ) ) ), ( L_sub( Mpy_32_32( q1.y_fx, q2.z_fx ), Mpy_32_32( q1.z_fx, q2.y_fx ) ) ) ); // ( q1.q_fact + q2.q_fact ) - 31 move32(); - tmp.y_fx = L_add( ( L_sub( Mpy_32_32( q1.w_fx, q2.y_fx ), Mpy_32_32( q1.x_fx, q2.z_fx ) ) ), ( L_add( Mpy_32_32( q1.y_fx, q2.w_fx ), Mpy_32_32( q1.z_fx, q2.x_fx ) ) ) ); + tmp.y_fx = L_add( ( L_sub( Mpy_32_32( q1.w_fx, q2.y_fx ), Mpy_32_32( q1.x_fx, q2.z_fx ) ) ), ( L_add( Mpy_32_32( q1.y_fx, q2.w_fx ), Mpy_32_32( q1.z_fx, q2.x_fx ) ) ) ); // ( q1.q_fact + q2.q_fact ) - 31 move32(); - tmp.z_fx = L_sub( ( L_add( Mpy_32_32( q1.w_fx, q2.z_fx ), Mpy_32_32( q1.x_fx, q2.y_fx ) ) ), ( L_sub( Mpy_32_32( q1.y_fx, q2.x_fx ), Mpy_32_32( q1.z_fx, q2.w_fx ) ) ) ); + tmp.z_fx = L_sub( ( L_add( Mpy_32_32( q1.w_fx, q2.z_fx ), Mpy_32_32( q1.x_fx, q2.y_fx ) ) ), ( L_sub( Mpy_32_32( q1.y_fx, q2.x_fx ), Mpy_32_32( q1.z_fx, q2.w_fx ) ) ) ); // ( q1.q_fact + q2.q_fact ) - 31 move32(); tmp.q_fact = sub( add( q1.q_fact, q2.q_fact ), 31 ); move16(); @@ -164,7 +164,7 @@ static Word32 QuaternionDotProduct_fx( Word32 result = 0; move32(); - result = L_add( ( L_add( Mpy_32_32( q1.x_fx, q2.x_fx ), Mpy_32_32( q1.y_fx, q2.y_fx ) ) ), ( L_add( Mpy_32_32( q1.z_fx, q2.z_fx ), Mpy_32_32( q1.w_fx, q2.w_fx ) ) ) ); + result = L_add( ( L_add( Mpy_32_32( q1.x_fx, q2.x_fx ), Mpy_32_32( q1.y_fx, q2.y_fx ) ) ), ( L_add( Mpy_32_32( q1.z_fx, q2.z_fx ), Mpy_32_32( q1.w_fx, q2.w_fx ) ) ) ); // ( q1.q_fact + q2.q_fact ) - 31 *q_fact = sub( add( q1.q_fact, q2.q_fact ), 31 ); move16(); @@ -223,13 +223,13 @@ static void QuaternionDivision_fx( result_q = sub( s_min( s_min( w_q, x_q ), s_min( y_q, z_q ) ), 1 ); // gaurdbits// - r->w_fx = L_shr( r->w_fx, sub( w_q, result_q ) ); + r->w_fx = L_shr( r->w_fx, sub( w_q, result_q ) ); // result_q move32(); - r->x_fx = L_shr( r->x_fx, sub( x_q, result_q ) ); + r->x_fx = L_shr( r->x_fx, sub( x_q, result_q ) ); // result_q move32(); - r->y_fx = L_shr( r->y_fx, sub( y_q, result_q ) ); + r->y_fx = L_shr( r->y_fx, sub( y_q, result_q ) ); // result_q move32(); - r->z_fx = L_shr( r->z_fx, sub( z_q, result_q ) ); + r->z_fx = L_shr( r->z_fx, sub( z_q, result_q ) ); // result_q move32(); r->q_fact = result_q; move16(); @@ -355,21 +355,21 @@ void QuaternionSlerp_fx( cosPhi = QuaternionDotProduct_fx( r1, r2, &q_dot ); q_min = s_min( r1.q_fact, r2.q_fact ); - r1.w_fx = L_shr( r1.w_fx, sub( r1.q_fact, q_min ) ); + r1.w_fx = L_shr( r1.w_fx, sub( r1.q_fact, q_min ) ); // q_min move32(); - r1.x_fx = L_shr( r1.x_fx, sub( r1.q_fact, q_min ) ); + r1.x_fx = L_shr( r1.x_fx, sub( r1.q_fact, q_min ) ); // q_min move32(); - r1.y_fx = L_shr( r1.y_fx, sub( r1.q_fact, q_min ) ); + r1.y_fx = L_shr( r1.y_fx, sub( r1.q_fact, q_min ) ); // q_min move32(); - r1.z_fx = L_shr( r1.z_fx, sub( r1.q_fact, q_min ) ); + r1.z_fx = L_shr( r1.z_fx, sub( r1.q_fact, q_min ) ); // q_min move32(); - r2.w_fx = L_shr( r2.w_fx, sub( r2.q_fact, q_min ) ); + r2.w_fx = L_shr( r2.w_fx, sub( r2.q_fact, q_min ) ); // q_min move32(); - r2.x_fx = L_shr( r2.x_fx, sub( r2.q_fact, q_min ) ); + r2.x_fx = L_shr( r2.x_fx, sub( r2.q_fact, q_min ) ); // q_min move32(); - r2.y_fx = L_shr( r2.y_fx, sub( r2.q_fact, q_min ) ); + r2.y_fx = L_shr( r2.y_fx, sub( r2.q_fact, q_min ) ); // q_min move32(); - r2.z_fx = L_shr( r2.z_fx, sub( r2.q_fact, q_min ) ); + r2.z_fx = L_shr( r2.z_fx, sub( r2.q_fact, q_min ) ); // q_min move32(); r1.q_fact = r2.q_fact = q_min; move16(); @@ -406,7 +406,7 @@ void QuaternionSlerp_fx( } ELSE { - temp_32 = L_sub( L_shr( ONE_IN_Q31, sub( 62, 2 * q_dot ) ), ( Mpy_32_32( cosPhi, cosPhi ) ) ); + temp_32 = L_sub( L_shr( ONE_IN_Q31, sub( 62, shl( q_dot, 1 ) ) ), ( Mpy_32_32( cosPhi, cosPhi ) ) ); // exp: sin_e sin_e = sub( 62, shl( q_dot, 1 ) ); sinPhi = Sqrt32( temp_32, &sin_e ); @@ -416,10 +416,12 @@ void QuaternionSlerp_fx( temp_16 = extract_h( temp_32 ); // Q13 s1 = getSineWord16R2( mult( temp_16, 20860 ) ); // Q15 + // 2 / pi in Q15 -> 20860 temp_32 = L_shl( Mpy_32_16_1( t_fx, phi ), 1 ); // Q29 temp_16 = extract_h( temp_32 ); // Q13 s2 = getSineWord16R2( mult( temp_16, 20860 ) ); // Q15 + // 2 / pi in Q15 -> 20860 tmp_quat.w_fx = L_add( Mpy_32_16_1( r1.w_fx, s1 ), Mpy_32_16_1( r2.w_fx, s2 ) ); // q_min move32(); @@ -606,11 +608,11 @@ static IVAS_VECTOR3 VectorSubtract_fx( z_qfact = sub( 31, e_result ); q_result = sub( s_min( s_min( x_qfact, y_qfact ), z_qfact ), 1 ); // guardbit// - result.x_fx = L_shr( result.x_fx, sub( x_qfact, q_result ) ); + result.x_fx = L_shr( result.x_fx, sub( x_qfact, q_result ) ); // q_result move32(); - result.y_fx = L_shr( result.y_fx, sub( y_qfact, q_result ) ); + result.y_fx = L_shr( result.y_fx, sub( y_qfact, q_result ) ); // q_result move32(); - result.z_fx = L_shr( result.z_fx, sub( z_qfact, q_result ) ); + result.z_fx = L_shr( result.z_fx, sub( z_qfact, q_result ) ); // q_result move32(); result.q_fact = q_result; move16(); @@ -645,11 +647,11 @@ static IVAS_VECTOR3 VectorCrossProduct_fx( { IVAS_VECTOR3 result_fx; - result_fx.x_fx = L_sub( Mpy_32_32( p1.y_fx, p2.z_fx ), Mpy_32_32( p1.z_fx, p2.y_fx ) ); + result_fx.x_fx = L_sub( Mpy_32_32( p1.y_fx, p2.z_fx ), Mpy_32_32( p1.z_fx, p2.y_fx ) ); // Q: ( p1.q_fact + p2.q_fact ) - 31 move32(); - result_fx.y_fx = L_sub( Mpy_32_32( p1.z_fx, p2.x_fx ), Mpy_32_32( p1.x_fx, p2.z_fx ) ); + result_fx.y_fx = L_sub( Mpy_32_32( p1.z_fx, p2.x_fx ), Mpy_32_32( p1.x_fx, p2.z_fx ) ); // Q: ( p1.q_fact + p2.q_fact ) - 31 move32(); - result_fx.z_fx = L_sub( Mpy_32_32( p1.x_fx, p2.y_fx ), Mpy_32_32( p1.y_fx, p2.x_fx ) ); + result_fx.z_fx = L_sub( Mpy_32_32( p1.x_fx, p2.y_fx ), Mpy_32_32( p1.y_fx, p2.x_fx ) ); // Q: ( p1.q_fact + p2.q_fact ) - 31 move32(); result_fx.q_fact = sub( add( p1.q_fact, p2.q_fact ), 31 ); move16(); @@ -680,7 +682,7 @@ static Word32 VectorDotProduct_fx( Word32 result_fx = 0; move32(); - result_fx = L_add( L_add( Mpy_32_32( p1.x_fx, p2.x_fx ), Mpy_32_32( p1.y_fx, p2.y_fx ) ), Mpy_32_32( p1.z_fx, p2.z_fx ) ); + result_fx = L_add( L_add( Mpy_32_32( p1.x_fx, p2.x_fx ), Mpy_32_32( p1.y_fx, p2.y_fx ) ), Mpy_32_32( p1.z_fx, p2.z_fx ) ); // // Q: ( p1.q_fact + p2.q_fact ) - 31 *q_fact = sub( add( p1.q_fact, p2.q_fact ), 31 ); move16(); @@ -707,7 +709,7 @@ static Word32 VectorLength_fx( { Word32 result_fx = 0; move32(); - result_fx = L_add( L_add( Mpy_32_32( p.x_fx, p.x_fx ), Mpy_32_32( p.y_fx, p.y_fx ) ), Mpy_32_32( p.z_fx, p.z_fx ) ); + result_fx = L_add( L_add( Mpy_32_32( p.x_fx, p.x_fx ), Mpy_32_32( p.y_fx, p.y_fx ) ), Mpy_32_32( p.z_fx, p.z_fx ) ); // // Q: ( p1.q_fact + p2.q_fact ) - 31 *q_fact = sub( add( p.q_fact, p.q_fact ), 31 ); move16(); @@ -758,11 +760,11 @@ static IVAS_VECTOR3 VectorNormalize_fx( z_qfact = sub( Q31, add( scale, sub( q_len, p.q_fact ) ) ); q_result = s_min( s_min( x_qfact, y_qfact ), z_qfact ); - result_fx.x_fx = L_shr( result_fx.x_fx, sub( x_qfact, q_result ) ); + result_fx.x_fx = L_shr( result_fx.x_fx, sub( x_qfact, q_result ) ); // Q: q_result move32(); - result_fx.y_fx = L_shr( result_fx.y_fx, sub( y_qfact, q_result ) ); + result_fx.y_fx = L_shr( result_fx.y_fx, sub( y_qfact, q_result ) ); // Q: q_result move32(); - result_fx.z_fx = L_shr( result_fx.z_fx, sub( z_qfact, q_result ) ); + result_fx.z_fx = L_shr( result_fx.z_fx, sub( z_qfact, q_result ) ); // Q: q_result move32(); result_fx.q_fact = q_result; move16(); @@ -1411,7 +1413,7 @@ ivas_error ivas_orient_trk_Process_fx( Word32 cutoffFrequency_fx, cutoff_prod; Word16 q_cutoff_prod = 0; move16(); - Word32 alpha_fx = L_shl( pOTR->alpha_fx, sub( Q30, pOTR->Q_alpha ) ); + Word32 alpha_fx = L_shl( pOTR->alpha_fx, sub( Q30, pOTR->Q_alpha ) ); // Q30 test(); IF( pOTR == NULL || pTrkRot == NULL ) @@ -1460,7 +1462,7 @@ ivas_error ivas_orient_trk_Process_fx( move16(); Word16 temp_result = BASOP_Util_Divide3232_Scale( angle_fx, pOTR->adaptationAngle_fx, &result_e ); relativeOrientationRate_fx = L_deposit_h( temp_result ); - Word32 one_fx = 1073741824; + Word32 one_fx = ONE_IN_Q30; move32(); IF( GT_32( relativeOrientationRate_fx, one_fx ) ) @@ -1493,7 +1495,7 @@ ivas_error ivas_orient_trk_Process_fx( temp_diff = sub( 31, q_cutoff_prod ); cutoff_prod = L_shl( cutoff_prod, temp_diff ); /* Compute adaptivity cutoff frequency: interpolate between minimum (center) and maximum (off-center) values */ - cutoffFrequency_fx = L_add( pOTR->centerAdaptationRate_fx, cutoff_prod ); + cutoffFrequency_fx = L_add( pOTR->centerAdaptationRate_fx, cutoff_prod ); // Q31 cutoff_prod = Mpy_32_32( cutoffFrequency_fx, PI2_C_Q28 ); q_cutoff_prod = ( ( 31 + 28 ) - 31 ); temp_result = BASOP_Util_Divide3232_Scale( cutoff_prod, updateRate_fx, &result_e ); diff --git a/lib_rend/ivas_prot_rend.h b/lib_rend/ivas_prot_rend.h index b3dde9603..a3c6d0e1b 100644 --- a/lib_rend/ivas_prot_rend.h +++ b/lib_rend/ivas_prot_rend.h @@ -1552,12 +1552,12 @@ void TDREND_SPATIAL_VecMapToNewCoordSystem( #ifdef IVAS_FLOAT_FIXED Word16 TDREND_SPATIAL_EvalOrthonormOrient_fx( - Word32 *FrontVecON_p_fx, /* i/o: Normalized front vector Q30 */ - Word32 *UpVecON_p_fx, /* i/o: Normalized up vector Q30 */ - Word32 *RightVecON_p_fx, /* i/o: Normalized right vector Q30 */ - const Word32 *FrontVec_p_fx, /* i : Input front vector */ - const Word32 *UpVec_p_fx, /* i : Input up vector */ - const Word16 orient_q /* i : Input up Q-factor */ + Word32 *FrontVecON_p_fx, /* i/o: Normalized front vector Q30 */ + Word32 *UpVecON_p_fx, /* i/o: Normalized up vector Q30 */ + Word32 *RightVecON_p_fx, /* i/o: Normalized right vector Q30 */ + const Word32 *FrontVec_p_fx, /* i : Input front vector Qx */ + const Word32 *UpVec_p_fx, /* i : Input up vector orient_q */ + const Word16 orient_q /* i : Input up Q-factor */ ); #endif /*! r: Flag if the orientation has been updated */ @@ -2751,11 +2751,11 @@ void ivas_omasa_ana_close( ); #ifdef IVAS_FLOAT_FIXED void computeIntensityVector_ana_fx( - const Word16 *band_grouping, /* i : Band grouping for estimation */ - Word32 Cldfb_RealBuffer[FOA_CHANNELS][CLDFB_NO_CHANNELS_MAX], /* i : Real part of input signal */ - Word32 Cldfb_ImagBuffer[FOA_CHANNELS][CLDFB_NO_CHANNELS_MAX], /* i : Imag part of input signal */ - const Word16 num_frequency_bands, /* i : Number of frequency bands */ - Word32 intensity_real[DIRAC_NUM_DIMS][MASA_FREQUENCY_BANDS] /* o : Intensity vector */ + const Word16 *band_grouping, /* i : Band grouping for estimation */ + Word32 Cldfb_RealBuffer[FOA_CHANNELS][CLDFB_NO_CHANNELS_MAX], /* i : Real part of input signal Qx */ + Word32 Cldfb_ImagBuffer[FOA_CHANNELS][CLDFB_NO_CHANNELS_MAX], /* i : Imag part of input signal Qx */ + const Word16 num_frequency_bands, /* i : Number of frequency bands */ + Word32 intensity_real[DIRAC_NUM_DIMS][MASA_FREQUENCY_BANDS] /* o : Intensity vector 2 * Qx -31 */ ); #endif void computeIntensityVector_ana( @@ -2767,11 +2767,11 @@ void computeIntensityVector_ana( ); #ifdef IVAS_FLOAT_FIXED void computeReferencePower_ana_fx( - const Word16 *band_grouping, /* i : Band grouping for estimation */ - Word32 Cldfb_RealBuffer[FOA_CHANNELS][CLDFB_NO_CHANNELS_MAX], /* i : Real part of input signal */ - Word32 Cldfb_ImagBuffer[FOA_CHANNELS][CLDFB_NO_CHANNELS_MAX], /* i : Imag part of input signal */ - Word32 *reference_power, /* o : Estimated power */ - const Word16 num_freq_bands /* i : Number of frequency bands */ + const Word16 *band_grouping, /* i : Band grouping for estimation */ + Word32 Cldfb_RealBuffer[FOA_CHANNELS][CLDFB_NO_CHANNELS_MAX], /* i : Real part of input signal input_q */ + Word32 Cldfb_ImagBuffer[FOA_CHANNELS][CLDFB_NO_CHANNELS_MAX], /* i : Imag part of input signal input_q */ + Word32 *reference_power, /* o : Estimated power */ + const Word16 num_freq_bands /* i : Number of frequency bands 2 * input_q - 31 */ ); #endif void computeReferencePower_ana( diff --git a/lib_rend/ivas_rom_rend.c b/lib_rend/ivas_rom_rend.c index caaea5173..3012dad11 100644 --- a/lib_rend/ivas_rom_rend.c +++ b/lib_rend/ivas_rom_rend.c @@ -1155,7 +1155,7 @@ const float ivas_reverb_default_DSR[IVAS_REVERB_DEFAULT_N_BANDS] = 6.2001e-08f, 2.8483e-08f, 2.6267e-08f }; -Word32 release_cnst_table[4][201] = // Q31 +const Word32 release_cnst_table[4][201] = // Q31 { { 1913946752, diff --git a/lib_rend/ivas_rom_rend.h b/lib_rend/ivas_rom_rend.h index 904078982..ff45a7955 100644 --- a/lib_rend/ivas_rom_rend.h +++ b/lib_rend/ivas_rom_rend.h @@ -49,15 +49,15 @@ extern const float diffuse_response_CICP6[5]; extern const float diffuse_response_CICP14[7]; extern const float diffuse_response_CICP16[9]; #else -extern const Word32 ls_azimuth_4d4_fx[8]; -extern const Word32 ls_elevation_4d4_fx[8]; -extern const Word16 diffuse_response_CICP6_fx[5]; -extern const Word16 diffuse_response_CICP14_fx[7]; -extern const Word16 diffuse_response_CICP16_fx[9]; +extern const Word32 ls_azimuth_4d4_fx[8]; /*Q-22*/ +extern const Word32 ls_elevation_4d4_fx[8]; /*Q-22*/ +extern const Word16 diffuse_response_CICP6_fx[5]; /*Q-15*/ +extern const Word16 diffuse_response_CICP14_fx[7]; /*Q-15*/ +extern const Word16 diffuse_response_CICP16_fx[9]; /*Q-15*/ #endif -extern const int16_t ap_pre_delay[DIRAC_DECORR_NUM_SPLIT_BANDS]; -extern const int16_t ap_filter_length[DIRAC_DECORR_NUM_SPLIT_BANDS]; +extern const Word16 ap_pre_delay[DIRAC_DECORR_NUM_SPLIT_BANDS]; +extern const Word16 ap_filter_length[DIRAC_DECORR_NUM_SPLIT_BANDS]; #ifndef IVAS_FLOAT_FIXED extern const float ap_lattice_delta_phi[DIRAC_MAX_NUM_DECORR_FILTERS * DIRAC_MAX_DECORR_FILTER_LEN]; extern const float ap_lattice_coeffs_1[DIRAC_DECORR_FILTER_LEN_1 * DIRAC_MAX_NUM_DECORR_FILTERS]; @@ -66,26 +66,26 @@ extern const float ap_lattice_coeffs_3[DIRAC_DECORR_FILTER_LEN_3 * DIRAC_MAX_NUM extern const float *const ap_lattice_coeffs[DIRAC_DECORR_NUM_SPLIT_BANDS]; extern const float ap_split_frequencies[DIRAC_DECORR_NUM_SPLIT_BANDS + 1]; #else -extern const Word16 ap_lattice_delta_phi_fx[DIRAC_MAX_NUM_DECORR_FILTERS * DIRAC_MAX_DECORR_FILTER_LEN]; -extern const Word16 ap_lattice_coeffs_1_fx[DIRAC_DECORR_FILTER_LEN_1 * DIRAC_MAX_NUM_DECORR_FILTERS]; -extern const Word16 ap_lattice_coeffs_2_fx[DIRAC_DECORR_FILTER_LEN_2 * DIRAC_MAX_NUM_DECORR_FILTERS]; -extern const Word16 ap_lattice_coeffs_3_fx[DIRAC_DECORR_FILTER_LEN_3 * DIRAC_MAX_NUM_DECORR_FILTERS]; +extern const Word16 ap_lattice_delta_phi_fx[DIRAC_MAX_NUM_DECORR_FILTERS * DIRAC_MAX_DECORR_FILTER_LEN]; /*Q-14*/ +extern const Word16 ap_lattice_coeffs_1_fx[DIRAC_DECORR_FILTER_LEN_1 * DIRAC_MAX_NUM_DECORR_FILTERS]; /*Q-15*/ +extern const Word16 ap_lattice_coeffs_2_fx[DIRAC_DECORR_FILTER_LEN_2 * DIRAC_MAX_NUM_DECORR_FILTERS]; /*Q-15*/ +extern const Word16 ap_lattice_coeffs_3_fx[DIRAC_DECORR_FILTER_LEN_3 * DIRAC_MAX_NUM_DECORR_FILTERS]; /*Q-15*/ extern const Word16 *const ap_lattice_coeffs_fx[DIRAC_DECORR_NUM_SPLIT_BANDS]; -extern const Word16 ap_split_frequencies_fx[DIRAC_DECORR_NUM_SPLIT_BANDS + 1]; +extern const Word16 ap_split_frequencies_fx[DIRAC_DECORR_NUM_SPLIT_BANDS + 1]; /*Q-14*/ #endif -extern const int16_t sba_map_tc[11]; -extern const int16_t sba_map_tc_512[11]; +extern const Word16 sba_map_tc[11]; /*Q-0*/ +extern const Word16 sba_map_tc_512[11]; /*Q-0*/ /*----------------------------------------------------------------------------------* * FASTCONV and PARAMETRIC binaural renderer ROM tables *----------------------------------------------------------------------------------*/ -extern const int16_t channelIndex_CICP6[5]; -extern const int16_t channelIndex_CICP12[7]; -extern const int16_t channelIndex_CICP14[7]; -extern const int16_t channelIndex_CICP16[9]; -extern const int16_t channelIndex_CICP19[11]; +extern const Word16 channelIndex_CICP6[5]; /*Q-0*/ +extern const Word16 channelIndex_CICP12[7]; /*Q-0*/ +extern const Word16 channelIndex_CICP14[7]; /*Q-0*/ +extern const Word16 channelIndex_CICP16[9]; /*Q-0*/ +extern const Word16 channelIndex_CICP19[11]; /*Q-0*/ #ifndef IVAS_FLOAT_FIXED /* These are equalization values for spread and surround coherent sounds, approximating the spectrum @@ -104,17 +104,17 @@ extern const float diffuseFieldCoherenceDifferenceZ[BINAURAL_COHERENCE_DIFFERENC #else /* These are equalization values for spread and surround coherent sounds, approximating the spectrum * for such sounds at anechoic multichannel listening. */ -extern const Word16 surCohEne_fx[MASA_NUM_DEFINED_SUR_SPR_COH_ENE_BINS]; -extern const Word16 spreadCohEne05_fx[MASA_NUM_DEFINED_SUR_SPR_COH_ENE_BINS]; -extern const Word16 spreadCohEne1_fx[MASA_NUM_DEFINED_SUR_SPR_COH_ENE_BINS]; +extern const Word16 surCohEne_fx[MASA_NUM_DEFINED_SUR_SPR_COH_ENE_BINS]; /*Q-13*/ +extern const Word16 spreadCohEne05_fx[MASA_NUM_DEFINED_SUR_SPR_COH_ENE_BINS]; /*Q-13*/ +extern const Word16 spreadCohEne1_fx[MASA_NUM_DEFINED_SUR_SPR_COH_ENE_BINS]; /*Q-14*/ /* Values for low-bit-rate equalization */ -extern const Word32 lowBitRateBinauralEQ_fx[LOW_BIT_RATE_BINAURAL_EQ_BINS]; +extern const Word32 lowBitRateBinauralEQ_fx[LOW_BIT_RATE_BINAURAL_EQ_BINS]; /*Q-31*/ /* Diffuse field binaural coherence directional adjustment values */ -extern const Word32 diffuseFieldCoherenceDifferenceX_fx[BINAURAL_COHERENCE_DIFFERENCE_BINS]; -extern const Word32 diffuseFieldCoherenceDifferenceY_fx[BINAURAL_COHERENCE_DIFFERENCE_BINS]; -extern const Word32 diffuseFieldCoherenceDifferenceZ_fx[BINAURAL_COHERENCE_DIFFERENCE_BINS]; +extern const Word32 diffuseFieldCoherenceDifferenceX_fx[BINAURAL_COHERENCE_DIFFERENCE_BINS]; /*Q-31*/ +extern const Word32 diffuseFieldCoherenceDifferenceY_fx[BINAURAL_COHERENCE_DIFFERENCE_BINS]; /*Q-31*/ +extern const Word32 diffuseFieldCoherenceDifferenceZ_fx[BINAURAL_COHERENCE_DIFFERENCE_BINS]; /*Q-31*/ #endif // IVAS_FLOAT_FIXED @@ -122,7 +122,7 @@ extern const Word32 diffuseFieldCoherenceDifferenceZ_fx[BINAURAL_COHERENCE_DIFFE * TD ISM Object renderer *----------------------------------------------------------------------------------*/ -extern const int16_t HRTF_MODEL_N_CPTS_VAR[HRTF_MODEL_N_SECTIONS]; +extern const Word16 HRTF_MODEL_N_CPTS_VAR[HRTF_MODEL_N_SECTIONS]; #ifndef IVAS_FLOAT_FIXED extern const float SincTable[321]; @@ -166,27 +166,27 @@ extern const float t_design_11_azimuth[70]; extern const float t_design_11_elevation[70]; #else /* SN3D norm (Fixed) */ -extern const Word32 norm_sn3d_hoa3_int[16]; +extern const Word32 norm_sn3d_hoa3_int[16]; /*Q-29*/ /* Order 11 t-design (Fixed) */ -extern const Word32 t_design_11_azimuth_int[70]; -extern const Word32 t_design_11_elevation_int[70]; +extern const Word32 t_design_11_azimuth_int[70]; /*Q-22*/ +extern const Word32 t_design_11_elevation_int[70]; /*Q-22*/ #endif /*----------------------------------------------------------------------* * Reverberator ROM tables *-----------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED -extern const Word32 ivas_reverb_default_fc_fx[]; -extern const Word32 ivas_reverb_default_RT60_fx[]; -extern const Word32 ivas_reverb_default_DSR_fx[]; +extern const Word32 ivas_reverb_default_fc_fx[]; /*Q-16*/ +extern const Word32 ivas_reverb_default_RT60_fx[]; /*Q-26*/ +extern const Word32 ivas_reverb_default_DSR_fx[]; /*Q-30*/ #endif extern const float ivas_reverb_default_fc[]; extern const float ivas_reverb_default_RT60[]; extern const float ivas_reverb_default_DSR[]; -extern Word32 release_cnst_table[4][201]; // Q31 +extern const Word32 release_cnst_table[4][201]; // Q31 /*----------------------------------------------------------------------------------* * Renderer SBA & MC enc/dec matrices @@ -208,8 +208,8 @@ extern const float ls_conversion_cicpX_stereo[12][2]; /* Mapping table of input config : output config with corresponding matrix */ extern const LS_CONVERSION_MAPPING ls_conversion_mapping[]; #else -extern const Word32 ls_conversion_cicpX_mono_fx[12][1]; -extern const Word32 ls_conversion_cicpX_stereo_fx[12][2]; +extern const Word32 ls_conversion_cicpX_mono_fx[12][1]; /*Q-30*/ +extern const Word32 ls_conversion_cicpX_stereo_fx[12][2]; /*Q-30*/ /* Mapping table of input config : output config with corresponding matrix */ extern const LS_CONVERSION_MAPPING_FX ls_conversion_mapping_fx[]; diff --git a/lib_rend/ivas_rotation.c b/lib_rend/ivas_rotation.c index 874fa8bf0..e68653484 100644 --- a/lib_rend/ivas_rotation.c +++ b/lib_rend/ivas_rotation.c @@ -272,7 +272,7 @@ void QuatToRotMat_fx( Word32 Rmat[3][3] /* o : real-space rotation matrix for this rotation 2*Qx-32 */ ) { - Word32 w = quat.w_fx; + Word32 w = quat.w_fx; // Qx move32(); Word32 x = quat.x_fx; move32(); @@ -288,7 +288,7 @@ void QuatToRotMat_fx( Word32 yy = L_shr( Mpy_32_32( y, y ), 1 ); Word32 zz = L_shr( Mpy_32_32( z, z ), 1 ); - Word32 wx = Mpy_32_32( w, x ); + Word32 wx = Mpy_32_32( w, x ); // 2 * Qx - 31 Word32 wz = Mpy_32_32( w, z ); Word32 wy = Mpy_32_32( w, y ); @@ -297,21 +297,21 @@ void QuatToRotMat_fx( Word32 yz = Mpy_32_32( y, z ); - Rmat[0][0] = L_sub( L_sub( L_add( ww, xx ), yy ), zz ); + Rmat[0][0] = L_sub( L_sub( L_add( ww, xx ), yy ), zz ); // 2 * Qx - 31 - 1 = 2*Qx-32 move32(); Rmat[0][1] = L_sub( xy, wz ); move32(); Rmat[0][2] = L_add( xz, wy ); move32(); - Rmat[1][0] = L_add( xy, wz ); + Rmat[1][0] = L_add( xy, wz ); // 2 * Qx - 32 move32(); Rmat[1][1] = L_sub( L_add( L_sub( ww, xx ), yy ), zz ); move32(); Rmat[1][2] = L_sub( yz, wx ); move32(); - Rmat[2][0] = L_sub( xz, wy ); + Rmat[2][0] = L_sub( xz, wy ); // 2 * Qx - 32 move32(); Rmat[2][1] = L_add( yz, wx ); move32(); @@ -372,13 +372,13 @@ void Euler2Quat( #else void Euler2Quat_fx( - const Word32 yaw, /* i : yaw (x) */ - const Word32 pitch, /* i : pitch (y) */ - const Word32 roll, /* i : roll (z) */ - IVAS_QUATERNION *quat /* o : quaternion describing the rotation */ + const Word32 yaw, /* i : yaw (x) Q22 */ + const Word32 pitch, /* i : pitch (y) Q22 */ + const Word32 roll, /* i : roll (z) Q22 */ + IVAS_QUATERNION *quat /* o : quaternion describing the rotation Q19 */ ) { - Word16 cr = getCosWord16( extract_l( L_shr_r( roll, 10 ) ) ); + Word16 cr = getCosWord16( extract_l( L_shr_r( roll, 10 ) ) ); // Q14 Word16 sr = getSinWord16( extract_l( L_shr_r( roll, 10 ) ) ); Word16 cp = getCosWord16( extract_l( L_shr_r( pitch, 10 ) ) ); Word16 sp = getSinWord16( extract_l( L_shr_r( pitch, 10 ) ) ); @@ -487,7 +487,7 @@ void rotateAziEle_fx( Word16 *azi, /* o : rotated azimuth Q0 */ Word16 *ele, /* o : rotated elevation Q0 */ Word32 Rmat_fx[3][3], /* i : real-space rotation matrix Q30*/ - const Word16 isPlanar /* i : is rotation planar and elevation meaningless? */ + const Word16 isPlanar /* i : is rotation planar and elevation meaningless? Q0*/ ) { Word16 n; @@ -511,19 +511,19 @@ void rotateAziEle_fx( } temp_16 = ele_in; move16(); - w_fx = cosine_table_Q31[abs_s( temp_16 )]; + w_fx = cosine_table_Q31[abs_s( temp_16 )]; // Q31 move32(); temp_16 = azi_in; move16(); - dv_fx[0] = Mpy_32_32( w_fx, cosine_table_Q31[abs_s( temp_16 )] ); + dv_fx[0] = Mpy_32_32( w_fx, cosine_table_Q31[abs_s( temp_16 )] ); // Q31 move32(); temp_16 = azi_in; move16(); - dv_fx[1] = Mpy_32_32( w_fx, sine_table_Q31[add( temp_16, 180 )] ); + dv_fx[1] = Mpy_32_32( w_fx, sine_table_Q31[add( temp_16, 180 )] ); // Q31 move32(); temp_16 = ele_in; move16(); - dv_fx[2] = sine_table_Q31[add( temp_16, 180 )]; + dv_fx[2] = sine_table_Q31[add( temp_16, 180 )]; // Q31 move32(); /*Rotation mtx multiplication*/ FOR( n = 0; n < 3; n++ ) @@ -538,7 +538,7 @@ void rotateAziEle_fx( move32(); x = dv_r_fx[0]; move32(); - radian = atan2_fx( L_abs( L_shr( y, 15 ) ), L_abs( L_shr( x, 15 ) ) ); + radian = atan2_fx( L_abs( L_shr( y, 15 ) ), L_abs( L_shr( x, 15 ) ) ); // Q14 if ( y <= 0 ) { @@ -549,11 +549,11 @@ void rotateAziEle_fx( { IF( radian < 0 ) { - angle = negate( add( 180, extract_l( L_shr( Mpy_32_16_1( _180_OVER_PI_Q25, radian ), ( 24 ) ) ) ) ); + angle = negate( add( 180, extract_l( L_shr( Mpy_32_16_1( _180_OVER_PI_Q25, radian ), ( 24 ) ) ) ) ); // Q0 } ELSE { - angle = sub( 180, extract_l( L_shr( Mpy_32_16_1( _180_OVER_PI_Q25, radian ), ( 24 ) ) ) ); + angle = sub( 180, extract_l( L_shr( Mpy_32_16_1( _180_OVER_PI_Q25, radian ), ( 24 ) ) ) ); // Q0 } IF( radian == 0 ) { @@ -565,7 +565,7 @@ void rotateAziEle_fx( } ELSE { - angle = extract_l( L_shr( Mpy_32_16_1( _180_OVER_PI_Q25, radian ), 24 ) ); + angle = extract_l( L_shr( Mpy_32_16_1( _180_OVER_PI_Q25, radian ), 24 ) ); // Q0 } *azi = s_max( -180, min( 180, angle ) ); @@ -578,7 +578,7 @@ void rotateAziEle_fx( move32(); x = sqrt_fx; move32(); - radian = atan2_fx( L_abs( L_shr( y, 15 ) ), L_abs( L_shr( x, 15 ) ) ); + radian = atan2_fx( L_abs( L_shr( y, 15 ) ), L_abs( L_shr( x, 15 ) ) ); // Q14 if ( y <= 0 ) { radian = negate( radian ); @@ -588,11 +588,11 @@ void rotateAziEle_fx( { IF( radian < 0 ) { - angle = negate( add( 180, extract_l( L_shr( Mpy_32_16_r( _180_OVER_PI_Q25, radian ), ( 24 ) ) ) ) ); + angle = negate( add( 180, extract_l( L_shr( Mpy_32_16_r( _180_OVER_PI_Q25, radian ), ( 24 ) ) ) ) ); // Q0 } ELSE { - angle = sub( 180, extract_l( L_shr( Mpy_32_16_r( _180_OVER_PI_Q25, radian ), ( 24 ) ) ) ); + angle = sub( 180, extract_l( L_shr( Mpy_32_16_r( _180_OVER_PI_Q25, radian ), ( 24 ) ) ) ); // Q0 } IF( radian == 0 ) { @@ -604,10 +604,10 @@ void rotateAziEle_fx( } ELSE { - angle = extract_l( L_shr( Mpy_32_16_r( _180_OVER_PI_Q25, radian ), ( 24 ) ) ); + angle = extract_l( L_shr( Mpy_32_16_r( _180_OVER_PI_Q25, radian ), ( 24 ) ) ); // Q0 } - *ele = s_max( -90, s_min( 90, angle ) ); + *ele = s_max( -90, s_min( 90, angle ) ); // Q0 move16(); } ELSE @@ -630,7 +630,7 @@ void rotateAziEle_fx_frac_az_el( Word32 *azi, /* o : rotated azimuth Q22 */ Word32 *ele, /* o : rotated elevation Q22 */ Word32 Rmat_fx[3][3], /* i : real-space rotation matrix Q30 */ - const Word16 isPlanar /* i : is rotation planar and elevation meaningless? */ + const Word16 isPlanar /* i : is rotation planar and elevation meaningless? Q0*/ ) { Word16 n, radian; // temp_16; @@ -654,8 +654,8 @@ void rotateAziEle_fx_frac_az_el( } azi_in_q13 = extract_l( L_shr( Mpy_32_32( azi_in, PI_OVER_180_FX ), Q9 ) ); ele_in_q13 = extract_l( L_shr( Mpy_32_32( ele_in, PI_OVER_180_FX ), Q9 ) ); - w_fx = getCosWord16( ele_in_q13 ); // Q14 - dv_fx[0] = L_mult( w_fx, getCosWord16( azi_in_q13 ) ); + w_fx = getCosWord16( ele_in_q13 ); // Q14 + dv_fx[0] = L_mult( w_fx, getCosWord16( azi_in_q13 ) ); // Q28 move32(); IF( EQ_32( dv_fx[0], ONE_IN_Q29 ) ) { @@ -667,7 +667,7 @@ void rotateAziEle_fx_frac_az_el( dv_fx[0] = L_shl( dv_fx[0], 2 ); move32(); } - dv_fx[1] = L_mult( w_fx, getSinWord16( azi_in_q13 ) ); + dv_fx[1] = L_mult( w_fx, getSinWord16( azi_in_q13 ) ); // Q28 move32(); IF( EQ_32( dv_fx[1], ONE_IN_Q30 ) ) { @@ -679,7 +679,7 @@ void rotateAziEle_fx_frac_az_el( dv_fx[1] = L_shl( dv_fx[1], 1 ); move32(); } - dv_fx[2] = L_deposit_l( getSinWord16( ele_in_q13 ) ); + dv_fx[2] = L_deposit_l( getSinWord16( ele_in_q13 ) ); // Q14 move32(); IF( EQ_32( dv_fx[2], ONE_IN_Q15 ) ) { @@ -726,7 +726,7 @@ void rotateAziEle_fx_frac_az_el( move32(); x = sqrt_fx; move32(); - radian = BASOP_util_atan2( y, x, 0 ); + radian = BASOP_util_atan2( y, x, 0 ); // Q13 angle = L_shr( Mpy_32_16_1( _180_OVER_PI_Q25, radian ), 1 ); // Q22 @@ -762,7 +762,7 @@ void rotateAziEle_fixed( Word32 *azi, /* o : rotated azimuth Q22 */ Word32 *ele, /* o : rotated elevation Q22 */ Word32 Rmat_fx[3][3], /* i : real-space rotation matrix Q30 */ - const Word16 isPlanar /* i : is rotation planar and elevation meaningless? */ + const Word16 isPlanar /* i : is rotation planar and elevation meaningless? Q0*/ ) { Word16 n, radian, temp_16; @@ -789,7 +789,7 @@ void rotateAziEle_fixed( move32(); temp_16 = azi_in; move16(); - dv_fx[0] = Mpy_32_32( w_fx, cosine_table_Q31[abs_s( temp_16 )] ); + dv_fx[0] = Mpy_32_32( w_fx, cosine_table_Q31[abs( temp_16 )] ); move32(); temp_16 = azi_in; move16(); @@ -815,7 +815,19 @@ void rotateAziEle_fixed( radian = BASOP_util_atan2( y, x, 0 ); // Q13 angle = L_shr( Mpy_32_16_1( _180_OVER_PI_Q25, radian ), 1 ); // Q22 - + /* Handeled roudning off operation*/ + IF( angle > 0 ) + { + temp = L_add( angle, ONE_IN_Q21 /* 0.5 in Q22*/ ); + temp_16 = extract_l( L_shr( temp, Q22 ) ); + angle = L_shl( temp_16, Q22 ); // Q22 + } + ELSE + { + temp = L_sub( angle, ONE_IN_Q21 /* 0.5 in Q22*/ ); + temp_16 = add( extract_l( L_shr( temp, Q22 ) ), 1 ); + angle = L_shl( temp_16, Q22 ); // Q22 + } *azi = L_max( L_shl( -180, 22 ), L_min( L_shl( 180, 22 ), angle ) ); // Q22 move32(); if ( LE_32( L_abs( *azi ), ONE_IN_Q22 ) ) @@ -830,7 +842,7 @@ void rotateAziEle_fixed( move32(); x = sqrt_fx; move32(); - radian = BASOP_util_atan2( y, x, 0 ); + radian = BASOP_util_atan2( y, x, 0 ); // Q13 angle = L_shr( Mpy_32_16_1( _180_OVER_PI_Q25, radian ), 1 ); // Q22 @@ -911,9 +923,9 @@ void rotateAziEle( void rotateFrame_shd( COMBINED_ORIENTATION_HANDLE hCombinedOrientationData, /* i : head and external orientation combined handle */ Word32 *output[], /* i/o: unrotated HOA3 signal buffer in TD Q11 */ - const Word16 subframe_len, /* i : subframe length per channel */ + const Word16 subframe_len, /* i : subframe length per channel Q0 */ const IVAS_OUTPUT_SETUP hTransSetup, /* i : format for rotation */ - const Word16 subframe_idx /* i : subframe index */ + const Word16 subframe_idx /* i : subframe index Q0 */ ) { // Not yet tested, no test cases entering the function. @@ -934,7 +946,7 @@ void rotateFrame_shd( SWITCH( subframe_len ) { case L_SUBFRAME_48k: - tmp = Q31_BY_SUB_FRAME_240; + tmp = Q31_BY_SUB_FRAME_240; // Q31 move32(); BREAK; case L_SUBFRAME_32k: @@ -989,7 +1001,7 @@ void rotateFrame_shd( FOR( m = m1; m < m2; m++ ) { /* crossfade with previous rotation gains */ - tmp = L_add( Mpy_32_32( Mpy_32_16_r( cross_fade[i], SHrotmat[n][m] ) /*Q30*/, output[m][add( offset, i )] /*Q11*/ ), Mpy_32_32( Mpy_32_16_r( L_sub( ONE_IN_Q31, cross_fade[i] ), SHrotmat_prev[n][m] ) /*Q30*/, output[m][add( offset, i )] /*Q11*/ ) ); + tmp = L_add( Mpy_32_32( Mpy_32_16_r( cross_fade[i], SHrotmat[n][m] ) /*Q30*/, output[m][offset + i] /*Q11*/ ), Mpy_32_32( Mpy_32_16_r( L_sub( ONE_IN_Q31, cross_fade[i] ), SHrotmat_prev[n][m] ) /*Q30*/, output[m][offset + i] /*Q11*/ ) ); tmpRot[n - m1] = L_add( L_shl( tmp, 1 ), tmpRot[n - m1] ); // Q11 } } @@ -997,7 +1009,7 @@ void rotateFrame_shd( /* write back the result */ FOR( n = m1; n < m2; n++ ) { - output[n][add( offset, i )] = tmpRot[n - m1]; // Q11 + output[n][offset + i] = tmpRot[n - m1]; // Q11 move32(); } m1 = m2; @@ -1028,7 +1040,7 @@ void rotateFrame_shd( MVR2R_WORD32( hCombinedOrientationData->Rmat_fx[subframe_idx][i], hCombinedOrientationData->Rmat_prev_fx[i], - 3 ); + 3 ); // Q14 } return; @@ -1239,8 +1251,8 @@ void rotateFrame_sd( test(); IF( hEFAPdata != NULL && ( NE_16( extract_l( L_shr( hTransSetup.ls_azimuth_fx[ch_in_woLFE], Q22 ) ), azimuth ) || NE_16( extract_l( L_shr( hTransSetup.ls_elevation_fx[ch_in_woLFE], Q22 ) ), elevation ) ) ) { - azimuth_fx = L_shl( L_deposit_l( azimuth ), Q22 ); - elevation_fx = L_shl( L_deposit_l( elevation ), Q22 ); + azimuth_fx = L_shl( L_deposit_l( azimuth ), Q22 ); // Q0->Q22 + elevation_fx = L_shl( L_deposit_l( elevation ), Q22 ); // Q0->Q22 efap_determine_gains_fx( hEFAPdata, tmp_gains_fx, azimuth_fx, elevation_fx, EFAP_MODE_EFAP ); @@ -1274,8 +1286,8 @@ void rotateFrame_sd( IF( hEFAPdata != NULL && ( NE_16( extract_l( L_shr( hTransSetup.ls_azimuth_fx[ch_in_woLFE], Q22 ) ), azimuth ) || NE_16( extract_l( L_shr( hTransSetup.ls_elevation_fx[ch_in_woLFE], Q22 ) ), elevation ) ) ) { - azimuth_fx = L_shl( L_deposit_l( azimuth ), Q22 ); - elevation_fx = L_shl( L_deposit_l( elevation ), Q22 ); + azimuth_fx = L_shl( L_deposit_l( azimuth ), Q22 ); // Q0->Q22 + elevation_fx = L_shl( L_deposit_l( elevation ), Q22 ); // Q0->Q22 efap_determine_gains_fx( hEFAPdata, tmp_gains_fx, azimuth_fx, elevation_fx, EFAP_MODE_EFAP ); FOR( ch_out = 0; ch_out < nchan; ch_out++ ) @@ -1327,14 +1339,14 @@ void rotateFrame_sd( FOR( i = 0; i < 3; i++ ) { MVR2R_WORD32( - hCombinedOrientationData->Rmat_fx[hCombinedOrientationData->subframe_idx][i], + hCombinedOrientationData->Rmat_fx[hCombinedOrientationData->subframe_idx][i], // Q30 hCombinedOrientationData->Rmat_prev_fx[i], 3 ); } /* copy to output */ FOR( ch_out = 0; ch_out < nchan; ch_out++ ) { - MVR2R_WORD32( &output_tmp_fx[ch_out][offset], &output[ch_out][offset], subframe_len ); + MVR2R_WORD32( &output_tmp_fx[ch_out][offset], &output[ch_out][offset], subframe_len ); // Q11 } pop_wmops(); @@ -1545,9 +1557,9 @@ void rotateFrame_shd_cldfb( move32(); FOR( m = m1; m < m2; m++ ) { - temp1 = Mpy_32_16_r( Cldfb_RealBuffer[m][i][iBand], SHrotmat[n][m] ); - temp2 = Mpy_32_16_r( Cldfb_ImagBuffer[m][i][iBand], SHrotmat[n][m] ); - realRot[n - m1] = L_add( temp1, realRot[n - m1] ); // Q(x + 14 - 15) + temp1 = Mpy_32_16_r( Cldfb_RealBuffer[m][i][iBand], SHrotmat[n][m] ); // Q(x + 14 - 15) + temp2 = Mpy_32_16_r( Cldfb_ImagBuffer[m][i][iBand], SHrotmat[n][m] ); // Q(x + 14 - 15) + realRot[n - m1] = L_add( temp1, realRot[n - m1] ); // Q(x + 14 - 15) move32(); imagRot[n - m1] = L_add( temp2, imagRot[n - m1] ); // Q(x + 14 - 15) move32(); @@ -1856,7 +1868,7 @@ void rotateFrame_sd_cldfb_fixed( ELSE { set32_fx( gains_fx[n], 0, nInChannels ); - gains_fx[n][n] = 0x7fffffff; // Q31 + gains_fx[n][n] = 0x7fffffff; // 1 in Q31 move32(); } } @@ -1868,7 +1880,7 @@ void rotateFrame_sd_cldfb_fixed( set32_fx( imagRot_fx[n], 0, shl( nb_band, 2 ) ); FOR( m = 0; m < nInChannels; m++ ) { - g1_fx = gains_fx[m][n]; + g1_fx = gains_fx[m][n]; // Q31 move32(); p_realRot_fx = realRot_fx[n]; p_imagRot_fx = imagRot_fx[n]; @@ -2505,13 +2517,13 @@ ivas_error combine_external_and_head_orientations( Word16 l_shift = 0; move16(); l_shift = s_min( s_min( Q_factor_L_32( hCombinedOrientationData->Quaternions[i].w_fx ), Q_factor_L_32( hCombinedOrientationData->Quaternions[i].x_fx ) ), s_min( Q_factor_L_32( hCombinedOrientationData->Quaternions[i].y_fx ), Q_factor_L_32( hCombinedOrientationData->Quaternions[i].z_fx ) ) ); - hCombinedOrientationData->Quaternions[i].w_fx = L_shl( hCombinedOrientationData->Quaternions[i].w_fx, l_shift ); + hCombinedOrientationData->Quaternions[i].w_fx = L_shl( hCombinedOrientationData->Quaternions[i].w_fx, l_shift ); // q_fact+l_shift move32(); - hCombinedOrientationData->Quaternions[i].x_fx = L_shl( hCombinedOrientationData->Quaternions[i].x_fx, l_shift ); + hCombinedOrientationData->Quaternions[i].x_fx = L_shl( hCombinedOrientationData->Quaternions[i].x_fx, l_shift ); // q_fact+l_shift move32(); - hCombinedOrientationData->Quaternions[i].y_fx = L_shl( hCombinedOrientationData->Quaternions[i].y_fx, l_shift ); + hCombinedOrientationData->Quaternions[i].y_fx = L_shl( hCombinedOrientationData->Quaternions[i].y_fx, l_shift ); // q_fact+l_shift move32(); - hCombinedOrientationData->Quaternions[i].z_fx = L_shl( hCombinedOrientationData->Quaternions[i].z_fx, l_shift ); + hCombinedOrientationData->Quaternions[i].z_fx = L_shl( hCombinedOrientationData->Quaternions[i].z_fx, l_shift ); // q_fact+l_shift move32(); hCombinedOrientationData->Quaternions[i].q_fact = add( hCombinedOrientationData->Quaternions[i].q_fact, l_shift ); move16(); @@ -2601,9 +2613,9 @@ ivas_error combine_external_and_head_orientations( /* Save the current orientations */ IF( hExtOrientationData != NULL ) { - IF( hExtOrientationData->enableExternalOrientation[sub( hExtOrientationData->num_subframes, 1 )] > 0 ) + IF( hExtOrientationData->enableExternalOrientation[hExtOrientationData->num_subframes - 1] > 0 ) { - hCombinedOrientationData->Quaternion_prev_extOrientation = hExtOrientationData->Quaternions[sub( hExtOrientationData->num_subframes, 1 )]; + hCombinedOrientationData->Quaternion_prev_extOrientation = hExtOrientationData->Quaternions[hExtOrientationData->num_subframes - 1]; } ELSE { @@ -2696,13 +2708,13 @@ ivas_error combine_external_and_head_orientations( FOR( i = 0; i < hCombinedOrientationData->num_subframes; i++ ) { l_shift = s_min( s_min( Q_factor_L_32( hCombinedOrientationData->Quaternions[i].w_fx ), Q_factor_L_32( hCombinedOrientationData->Quaternions[i].x_fx ) ), s_min( Q_factor_L_32( hCombinedOrientationData->Quaternions[i].y_fx ), Q_factor_L_32( hCombinedOrientationData->Quaternions[i].z_fx ) ) ); - hCombinedOrientationData->Quaternions[i].w_fx = L_shl( hCombinedOrientationData->Quaternions[i].w_fx, l_shift ); + hCombinedOrientationData->Quaternions[i].w_fx = L_shl( hCombinedOrientationData->Quaternions[i].w_fx, l_shift ); // q_fact+l_shift move32(); - hCombinedOrientationData->Quaternions[i].x_fx = L_shl( hCombinedOrientationData->Quaternions[i].x_fx, l_shift ); + hCombinedOrientationData->Quaternions[i].x_fx = L_shl( hCombinedOrientationData->Quaternions[i].x_fx, l_shift ); // q_fact+l_shift move32(); - hCombinedOrientationData->Quaternions[i].y_fx = L_shl( hCombinedOrientationData->Quaternions[i].y_fx, l_shift ); + hCombinedOrientationData->Quaternions[i].y_fx = L_shl( hCombinedOrientationData->Quaternions[i].y_fx, l_shift ); // q_fact+l_shift move32(); - hCombinedOrientationData->Quaternions[i].z_fx = L_shl( hCombinedOrientationData->Quaternions[i].z_fx, l_shift ); + hCombinedOrientationData->Quaternions[i].z_fx = L_shl( hCombinedOrientationData->Quaternions[i].z_fx, l_shift ); // q_fact+l_shift move32(); hCombinedOrientationData->Quaternions[i].q_fact = add( hCombinedOrientationData->Quaternions[i].q_fact, l_shift ); move16(); @@ -2989,7 +3001,7 @@ static void external_target_interpolation_fx( { IF( i > 0 ) { - IF( hExtOrientationData->enableExternalOrientation[sub( i, 1 )] == 0 ) + IF( hExtOrientationData->enableExternalOrientation[i - 1] == 0 ) { IVAS_QUATERNION identity; identity.w_fx = ONE_IN_Q31; @@ -3002,13 +3014,13 @@ static void external_target_interpolation_fx( move16(); hCombinedOrientationData->Quaternions_ext_interpolation_start = identity; } - ELSE IF( EQ_16( hExtOrientationData->enableExternalOrientation[sub( i, 1 )], 2 ) ) + ELSE IF( EQ_16( hExtOrientationData->enableExternalOrientation[i - 1], 2 ) ) { hCombinedOrientationData->Quaternions_ext_interpolation_start = hCombinedOrientationData->Quaternion_frozen_ext; } ELSE { - hCombinedOrientationData->Quaternions_ext_interpolation_start = hExtOrientationData->Quaternions[sub( i, 1 )]; + hCombinedOrientationData->Quaternions_ext_interpolation_start = hExtOrientationData->Quaternions[i - 1]; } } ELSE @@ -3187,10 +3199,10 @@ static bool are_orientations_same_fx( test(); test(); test(); - IF( EQ_16( Flag_1, 1 ) || - EQ_16( Flag_2, 1 ) || - EQ_16( Flag_3, 1 ) || - EQ_16( Flag_4, 1 ) ) + if ( EQ_16( Flag_1, 1 ) || + EQ_16( Flag_2, 1 ) || + EQ_16( Flag_3, 1 ) || + EQ_16( Flag_4, 1 ) ) { orientationsAreSame = false; move16(); @@ -3248,34 +3260,36 @@ static Word32 SHrot_p_fx( Word32 p = 0; move32(); - ri1 = SHrotmat[add( add( i, 1 ), 1 )][add( add( 1, 1 ), 1 )]; + ri1 = SHrotmat[i + 1 + 1][1 + 1 + 1]; // Q14 move16(); - rim1 = SHrotmat[add( add( i, 1 ), 1 )][add( add( -1, 1 ), 1 )]; + rim1 = SHrotmat[i + 1 + 1][-1 + 1 + 1]; // Q14 move16(); - ri0 = SHrotmat[add( add( i, 1 ), 1 )][add( 1, 1 )]; + ri0 = SHrotmat[i + 1 + 1][0 + 1 + 1]; // Q14 move16(); IF( EQ_16( b, -l ) ) { - R_lm1_1 = R_lm1[sub( add( a, l ), 1 )][0]; + R_lm1_1 = R_lm1[a + l - 1][0]; // Q14 move16(); - R_lm1_2 = R_lm1[sub( add( a, l ), 1 )][sub( shl( l, 1 ), 2 )]; + R_lm1_2 = R_lm1[a + l - 1][2 * l - 2]; // Q14 move16(); - p = L_mac0( L_mult0( ri1, R_lm1_1 ), rim1, R_lm1_2 ); + p = L_mac0( L_mult0( ri1, R_lm1_1 ), rim1, R_lm1_2 ); // Q28 } ELSE { IF( EQ_16( b, l ) ) { - R_lm1_1 = R_lm1[sub( add( a, l ), 1 )][sub( shl( l, 1 ), 2 )]; - R_lm1_2 = R_lm1[sub( add( a, l ), 1 )][0]; - p = L_msu0( L_mult0( ri1, R_lm1_1 ), rim1, R_lm1_2 ); + R_lm1_1 = R_lm1[a + l - 1][2 * l - 2]; // Q14 + move16(); + R_lm1_2 = R_lm1[a + l - 1][0]; // Q14 + move16(); + p = L_msu0( L_mult0( ri1, R_lm1_1 ), rim1, R_lm1_2 ); // Q28 } ELSE { - R_lm1_1 = R_lm1[sub( add( a, l ), 1 )][sub( add( b, l ), 1 )]; + R_lm1_1 = R_lm1[a + l - 1][b + l - 1]; move16(); - p = L_mult0( ri0, R_lm1_1 ); + p = L_mult0( ri0, R_lm1_1 ); // Q28 } } @@ -3450,9 +3464,9 @@ static Word32 SHrot_v_fx( d = 1; move16(); } - p0 = SHrot_p_fx( 1, l, sub( m, 1 ), n, SHrotmat, R_lm1 ); - p1 = SHrot_p_fx( -1, l, add( negate( m ), 1 ), n, SHrotmat, R_lm1 ); - result = Msub_32_16_r( Mpy_32_16_r( p0, square_root16_table[add( 1, d )] ), p1, shl( sub( 1, d ), 14 ) ); // Q27 + p0 = SHrot_p_fx( 1, l, sub( m, 1 ), n, SHrotmat, R_lm1 ); // Q28 + p1 = SHrot_p_fx( -1, l, add( negate( m ), 1 ), n, SHrotmat, R_lm1 ); // Q28 + result = Msub_32_16_r( Mpy_32_16_r( p0, square_root16_table[1 + d] ), p1, shl( sub( 1, d ), 14 ) ); // Q27 } ELSE { @@ -3465,7 +3479,7 @@ static Word32 SHrot_v_fx( } p0 = SHrot_p_fx( 1, l, add( m, 1 ), n, SHrotmat, R_lm1 ); p1 = SHrot_p_fx( -1, l, negate( add( m, 1 ) ), n, SHrotmat, R_lm1 ); - result = Madd_32_16_r( Mpy_32_16_r( p0, shl( sub( 1, d ), 14 ) ), p1, square_root16_table[add( 1, d )] ); // Q27 + result = Madd_32_16_r( Mpy_32_16_r( p0, shl( sub( 1, d ), 14 ) ), p1, square_root16_table[1 + d] ); // Q27 } } return result; // Q27 @@ -3490,15 +3504,15 @@ static Word32 SHrot_w_fx( { IF( m > 0 ) { - p0 = SHrot_p_fx( 1, l, add( m, 1 ), n, SHrotmat, R_lm1 ); - p1 = SHrot_p_fx( -1, l, negate( add( m, 1 ) ), n, SHrotmat, R_lm1 ); - result = L_add( p0, p1 ); + p0 = SHrot_p_fx( 1, l, add( m, 1 ), n, SHrotmat, R_lm1 ); // Q28 + p1 = SHrot_p_fx( -1, l, negate( add( m, 1 ) ), n, SHrotmat, R_lm1 ); // Q28 + result = L_add( p0, p1 ); // Q28 } ELSE { - p0 = SHrot_p_fx( 1, l, sub( m, 1 ), n, SHrotmat, R_lm1 ); - p1 = SHrot_p_fx( -1, l, sub( 1, m ), n, SHrotmat, R_lm1 ); - result = L_sub( p0, p1 ); + p0 = SHrot_p_fx( 1, l, sub( m, 1 ), n, SHrotmat, R_lm1 ); // Q28 + p1 = SHrot_p_fx( -1, l, sub( 1, m ), n, SHrotmat, R_lm1 ); // Q28 + result = L_sub( p0, p1 ); // Q28 } } @@ -3555,21 +3569,21 @@ void SHrotmatgen_fx( SHrotmat[0][0] = ONE_IN_Q14; move16(); - SHrotmat[1][1] = extract_h( Rmat[1][1] ); + SHrotmat[1][1] = extract_h( Rmat[1][1] ); // Q14 move16(); SHrotmat[1][2] = extract_h( Rmat[1][2] ); move16(); SHrotmat[1][3] = extract_h( Rmat[1][0] ); move16(); - SHrotmat[2][1] = extract_h( Rmat[2][1] ); + SHrotmat[2][1] = extract_h( Rmat[2][1] ); // Q14 move16(); SHrotmat[2][2] = extract_h( Rmat[2][2] ); move16(); SHrotmat[2][3] = extract_h( Rmat[2][0] ); move16(); - SHrotmat[3][1] = extract_h( Rmat[0][1] ); + SHrotmat[3][1] = extract_h( Rmat[0][1] ); // Q14 move16(); SHrotmat[3][2] = extract_h( Rmat[0][2] ); move16(); @@ -3580,7 +3594,7 @@ void SHrotmatgen_fx( { FOR( j = 0; j < 2 * 1 + 1; j++ ) { - R_lm1[i][j] = SHrotmat[i + 1][j + 1]; + R_lm1[i][j] = SHrotmat[i + 1][j + 1]; // Q14 move16(); } } @@ -3600,23 +3614,23 @@ void SHrotmatgen_fx( } absm = extract_l( L_abs( m ) ); - sql2mm2 = square_root30_q12[sub( imult1616( l, l ), imult1616( m, m ) )]; + sql2mm2 = square_root30_q12[l * l - m * m]; // Q12 move16(); - sqdabsm = square_root30_q12[imult1616( add( 1, d ), imult1616( sub( add( l, absm ), 1 ), add( l, absm ) ) )]; + sqdabsm = square_root30_q12[( 1 + d ) * ( l + absm - 1 ) * ( l + absm )]; // Q12 move16(); - sqlabsm = square_root30_q12[imult1616( sub( l, add( absm, 1 ) ), sub( l, absm ) )]; + sqlabsm = square_root30_q12[( ( l - ( absm + 1 ) ) * ( l - absm ) )]; // Q12 move16(); FOR( n = -l; n <= l; n++ ) { IF( EQ_16( abs_s( n ), l ) ) { - sqdenom = square_root30_q12[imult1616( shl( l, 1 ), sub( shl( l, 1 ), 1 ) )]; + sqdenom = square_root30_q12[( ( 2 * l ) * ( 2 * l - 1 ) )]; // Q12 move16(); } ELSE { - sqdenom = square_root30_q12[sub( imult1616( l, l ), imult1616( n, n ) )]; + sqdenom = square_root30_q12[( l * l - n * n )]; // Q12 move16(); } @@ -3641,7 +3655,7 @@ void SHrotmatgen_fx( w32_fx = Mpy_32_16_r( result, w ); // Q27 } // Addind and converting to 16 bit integer of Q14 - R_l[add( m, l )][add( n, l )] = extract_h( L_shl( L_add( L_add( L_shr( u32_fx, 1 ), v32_fx ), L_shr( w32_fx, 1 ) ), 4 ) ); // Q14 + R_l[m + l][n + l] = extract_h( L_shl( L_add( L_add( L_shr( u32_fx, 1 ), v32_fx ), L_shr( w32_fx, 1 ) ), 4 ) ); // Q14 move16(); } } @@ -3650,7 +3664,7 @@ void SHrotmatgen_fx( { FOR( j = 0; j < 2 * l + 1; j++ ) { - SHrotmat[add( band_idx, i )][add( band_idx, j )] = R_l[i][j]; + SHrotmat[band_idx + i][band_idx + j] = R_l[i][j]; // Q14 move16(); } } @@ -3832,7 +3846,7 @@ void ivas_combined_orientation_update_index( hCombinedOrientationData->cur_subframe_samples_rendered = add( hCombinedOrientationData->cur_subframe_samples_rendered, samples_rendered ); move16(); div_result = BASOP_Util_Divide3216_Scale( hCombinedOrientationData->cur_subframe_samples_rendered, hCombinedOrientationData->subframe_size, &exp ); - hCombinedOrientationData->subframe_idx = add( hCombinedOrientationData->subframe_idx, shl( div_result, exp + 1 ) ); + hCombinedOrientationData->subframe_idx = add( hCombinedOrientationData->subframe_idx, shl( div_result, add( exp, 1 ) ) ); move16(); hCombinedOrientationData->cur_subframe_samples_rendered = hCombinedOrientationData->cur_subframe_samples_rendered % hCombinedOrientationData->subframe_size; move16(); diff --git a/lib_rend/ivas_sba_rendering.c b/lib_rend/ivas_sba_rendering.c index 380faaf9f..4a23da243 100644 --- a/lib_rend/ivas_sba_rendering.c +++ b/lib_rend/ivas_sba_rendering.c @@ -111,8 +111,8 @@ void ivas_sba_prototype_renderer_fx( { FOR( Word16 j = 0; j < CLDFB_SLOTS_PER_SUBFRAME; j++ ) { - scale_sig32( inRe_fx[i][j], CLDFB_NO_CHANNELS_MAX, sub( norm_q, 2 ) ); - scale_sig32( inIm_fx[i][j], CLDFB_NO_CHANNELS_MAX, sub( norm_q, 2 ) ); + scale_sig32( inRe_fx[i][j], CLDFB_NO_CHANNELS_MAX, sub( norm_q, 2 ) ); // q_cldfb -> q_cldfb + 2 -norm_q + scale_sig32( inIm_fx[i][j], CLDFB_NO_CHANNELS_MAX, sub( norm_q, 2 ) ); // q_cldfb -> q_cldfb + 2 -norm_q q_cldfb[i][j] = sub( add( q_cldfb[i][j], norm_q ), 2 ); move16(); } @@ -170,7 +170,7 @@ void ivas_sba_prototype_renderer_fx( { spar_band = bin2band->p_cldfb_map_to_spar_band[cldfb_band]; move16(); - cldfb_par_fx = mixer_mat_fx[out_ch][in_ch][spar_band]; // q30 + cldfb_par_fx = mixer_mat_fx[out_ch][in_ch][spar_band]; // hMdDec->Q_mixer_matrix move32(); } ELSE @@ -180,12 +180,12 @@ void ivas_sba_prototype_renderer_fx( FOR( spar_band = bin2band->p_spar_start_bands[cldfb_band]; spar_band < num_spar_bands; spar_band++ ) { /* accumulate contributions from all SPAR bands */ - cldfb_par_fx = L_add_sat( cldfb_par_fx, Mpy_32_32( mixer_mat_fx[out_ch][in_ch][spar_band], bin2band->pp_cldfb_weights_per_spar_band_fx[cldfb_band][spar_band] ) ); // q30 + cldfb_par_fx = L_add_sat( cldfb_par_fx, Mpy_32_32( mixer_mat_fx[out_ch][in_ch][spar_band], bin2band->pp_cldfb_weights_per_spar_band_fx[cldfb_band][spar_band] ) ); // hMdDec->Q_mixer_matrix } } - out_re_fx[out_ch] = L_add_sat( out_re_fx[out_ch], Mpy_32_32( inRe_fx[in_ch][ts][cldfb_band], cldfb_par_fx ) ); // q30+q_cldfb[i][j]; - out_im_fx[out_ch] = L_add_sat( out_im_fx[out_ch], Mpy_32_32( inIm_fx[in_ch][ts][cldfb_band], cldfb_par_fx ) ); // q30+q_cldfb[i][j + out_re_fx[out_ch] = L_add_sat( out_re_fx[out_ch], Mpy_32_32( inRe_fx[in_ch][ts][cldfb_band], cldfb_par_fx ) ); // hMdDec->Q_mixer_matrix+q_cldfb[i][j] -31 + out_im_fx[out_ch] = L_add_sat( out_im_fx[out_ch], Mpy_32_32( inIm_fx[in_ch][ts][cldfb_band], cldfb_par_fx ) ); // hMdDec->Q_mixer_matrix+q_cldfb[i][j] -31 move32(); move32(); } @@ -194,8 +194,8 @@ void ivas_sba_prototype_renderer_fx( /*update CLDFB data with the parameter-modified data*/ FOR( out_ch = firstOutCh; out_ch < outChEnd; out_ch++ ) { - inRe_fx[out_ch][ts][cldfb_band] = L_shl_sat( out_re_fx[out_ch], 1 ); // q30+q_cldfb[i][j]; + q1 //to keep constat q to entire buffer - inIm_fx[out_ch][ts][cldfb_band] = L_shl_sat( out_im_fx[out_ch], 1 ); + inRe_fx[out_ch][ts][cldfb_band] = L_shl_sat( out_re_fx[out_ch], 1 ); // hMdDec->Q_mixer_matrix+q_cldfb[i][j] -31 +1; + q1 //to keep constat q to entire buffer + inIm_fx[out_ch][ts][cldfb_band] = L_shl_sat( out_im_fx[out_ch], 1 ); // hMdDec->Q_mixer_matrix+q_cldfb[i][j] -31 +1; + q1 //to keep constat q to entire buffer move32(); move32(); } @@ -216,10 +216,10 @@ void ivas_sba_prototype_renderer_fx( move16(); hSpar->i_subframe = s_min( hSpar->i_subframe, MAX_PARAM_SPATIAL_SUBFRAMES ); move16(); - Copy32( hSpar->hMdDec->mixer_mat_prev_fx[1][0][0], hSpar->hMdDec->mixer_mat_prev_fx[0][0][0], IVAS_MAX_FB_MIXER_OUT_CH * IVAS_MAX_FB_MIXER_IN_CH * IVAS_MAX_NUM_BANDS ); - Copy32( hSpar->hMdDec->mixer_mat_prev_fx[2][0][0], hSpar->hMdDec->mixer_mat_prev_fx[1][0][0], IVAS_MAX_FB_MIXER_OUT_CH * IVAS_MAX_FB_MIXER_IN_CH * IVAS_MAX_NUM_BANDS ); - Copy32( hSpar->hMdDec->mixer_mat_prev_fx[3][0][0], hSpar->hMdDec->mixer_mat_prev_fx[2][0][0], IVAS_MAX_FB_MIXER_OUT_CH * IVAS_MAX_FB_MIXER_IN_CH * IVAS_MAX_NUM_BANDS ); - Copy32( hSpar->hMdDec->mixer_mat_prev_fx[4][0][0], hSpar->hMdDec->mixer_mat_prev_fx[3][0][0], IVAS_MAX_FB_MIXER_OUT_CH * IVAS_MAX_FB_MIXER_IN_CH * IVAS_MAX_NUM_BANDS ); + Copy32( hSpar->hMdDec->mixer_mat_prev_fx[1][0][0], hSpar->hMdDec->mixer_mat_prev_fx[0][0][0], IVAS_MAX_FB_MIXER_OUT_CH * IVAS_MAX_FB_MIXER_IN_CH * IVAS_MAX_NUM_BANDS ); // Q_mixer_mat + Copy32( hSpar->hMdDec->mixer_mat_prev_fx[2][0][0], hSpar->hMdDec->mixer_mat_prev_fx[1][0][0], IVAS_MAX_FB_MIXER_OUT_CH * IVAS_MAX_FB_MIXER_IN_CH * IVAS_MAX_NUM_BANDS ); // Q_mixer_mat + Copy32( hSpar->hMdDec->mixer_mat_prev_fx[3][0][0], hSpar->hMdDec->mixer_mat_prev_fx[2][0][0], IVAS_MAX_FB_MIXER_OUT_CH * IVAS_MAX_FB_MIXER_IN_CH * IVAS_MAX_NUM_BANDS ); // Q_mixer_mat + Copy32( hSpar->hMdDec->mixer_mat_prev_fx[4][0][0], hSpar->hMdDec->mixer_mat_prev_fx[3][0][0], IVAS_MAX_FB_MIXER_OUT_CH * IVAS_MAX_FB_MIXER_IN_CH * IVAS_MAX_NUM_BANDS ); // Q_mixer_mat FOR( out_ch = 0; out_ch < numch_out; out_ch++ ) { @@ -252,9 +252,9 @@ void ivas_sba_prototype_renderer_fx( Word32 temp_signal_fx[CLDFB_NO_CHANNELS_MAX]; FOR( Word16 idx = 0; idx < CLDFB_NO_CHANNELS_MAX; idx++ ) { - temp_signal_fx[idx] = L_add( L_shr( inRe_fx[0][ts][idx], 1 ), L_shr( inRe_fx[1][ts][idx], 1 ) ); + temp_signal_fx[idx] = L_add( L_shr( inRe_fx[0][ts][idx], 1 ), L_shr( inRe_fx[1][ts][idx], 1 ) ); // q_cldfb[][]-1 move32(); - inRe_fx[1][ts][idx] = L_sub( L_shr( inRe_fx[0][ts][idx], 1 ), L_shr( inRe_fx[1][ts][idx], 1 ) ); + inRe_fx[1][ts][idx] = L_sub( L_shr( inRe_fx[0][ts][idx], 1 ), L_shr( inRe_fx[1][ts][idx], 1 ) ); // q_cldfb[][]-1 move32(); inRe_fx[0][ts][idx] = temp_signal_fx[idx]; move32(); @@ -262,9 +262,9 @@ void ivas_sba_prototype_renderer_fx( FOR( Word16 idx = 0; idx < CLDFB_NO_CHANNELS_MAX; idx++ ) { - temp_signal_fx[idx] = L_add( L_shr( inIm_fx[0][ts][idx], 1 ), L_shr( inIm_fx[1][ts][idx], 1 ) ); + temp_signal_fx[idx] = L_add( L_shr( inIm_fx[0][ts][idx], 1 ), L_shr( inIm_fx[1][ts][idx], 1 ) ); // q_cldfb[][]-1 move32(); - inIm_fx[1][ts][idx] = L_sub( L_shr( inIm_fx[0][ts][idx], 1 ), L_shr( inIm_fx[1][ts][idx], 1 ) ); + inIm_fx[1][ts][idx] = L_sub( L_shr( inIm_fx[0][ts][idx], 1 ), L_shr( inIm_fx[1][ts][idx], 1 ) ); // q_cldfb[][]-1 move32(); inIm_fx[0][ts][idx] = temp_signal_fx[idx]; move32(); -- GitLab From dcda39c4082a8674b079fc5e6373ec179368c12a Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Tue, 22 Oct 2024 22:10:18 +0530 Subject: [PATCH 021/128] Clang formatting changes --- lib_dec/dec_tcx.c | 6 +++--- lib_dec/dec_uv_fx.c | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib_dec/dec_tcx.c b/lib_dec/dec_tcx.c index f32a383a5..3481c797d 100644 --- a/lib_dec/dec_tcx.c +++ b/lib_dec/dec_tcx.c @@ -1950,7 +1950,7 @@ void decoder_tcx_imdct_fx( Word16 predictionGain_fx; Word16 A_itf_fx[ITF_MAX_FILTER_ORDER + 1]; // q_a_itf Word16 q_a_itf = 15; - Word16 x_e = sub(31, q_x); + Word16 x_e = sub( 31, q_x ); move16(); /*-----------------------------------------------------------------* @@ -2017,7 +2017,7 @@ void decoder_tcx_imdct_fx( move16(); } - test(); + test(); test(); test(); test(); @@ -2099,7 +2099,7 @@ void decoder_tcx_imdct_fx( } test(); - IF( NE_16(st->element_mode, IVAS_CPE_DFT) && !sba_dirac_stereo_flag ) + IF( NE_16( st->element_mode, IVAS_CPE_DFT ) && !sba_dirac_stereo_flag ) { IMDCT_ivas_fx( xn_bufFB_fx, q_x, hTcxDec->syn_Overl, hTcxDec->syn_Overl_TDAC, xn_buf_fx, hTcxCfg->tcx_aldo_window_1, hTcxCfg->tcx_aldo_window_1_trunc, hTcxCfg->tcx_aldo_window_2, diff --git a/lib_dec/dec_uv_fx.c b/lib_dec/dec_uv_fx.c index 231b0cb73..bdddeb791 100644 --- a/lib_dec/dec_uv_fx.c +++ b/lib_dec/dec_uv_fx.c @@ -84,7 +84,7 @@ void decod_unvoiced_fx( Word16 tmp_idx = 0; move16(); - IF ( i_subfr_fx != 0 ) + IF( i_subfr_fx != 0 ) { tmp_idx = idiv1616( i_subfr_fx, L_SUBFR ); } -- GitLab From 9fce618c817ee978d9e9986f002d324f0a412994 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Wed, 23 Oct 2024 10:53:01 +0530 Subject: [PATCH 022/128] Q info addition for decoder and renderer files - 1 --- lib_com/prot_fx.h | 183 ++++---- lib_dec/dec_pit_exc_fx.c | 25 +- lib_dec/dec_post_fx.c | 278 ++++++------ lib_dec/dec_ppp_fx.c | 2 +- lib_dec/dec_prm_fx.c | 579 +++++++++++++----------- lib_dec/dec_tcx_fx.c | 187 ++++---- lib_dec/decision_matrix_dec_fx.c | 93 ++-- lib_dec/gs_dec_amr_wb_fx.c | 184 ++++---- lib_dec/gs_dec_fx.c | 398 ++++++++-------- lib_dec/hdecnrm_fx.c | 162 +++---- lib_dec/ivas_stereo_dft_dec_fx.c | 4 +- lib_dec/stat_dec.h | 2 +- lib_rend/ivas_prot_rend.h | 56 +-- lib_rend/ivas_reverb_delay_line.c | 60 +-- lib_rend/ivas_reverb_fft_filter.c | 117 ++--- lib_rend/ivas_rom_binaural_crend_head.c | 4 +- lib_rend/ivas_rom_rend.c | 10 +- 17 files changed, 1207 insertions(+), 1137 deletions(-) diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index 20a851b29..1a1b8a81a 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -827,7 +827,7 @@ void compute_poly_product_fx( Word16 *coef, Word32 *p, Word16 order ); void dec_prm_hm_fx( Decoder_State *st, - Word16 *prm_hm, + Word16 *prm_hm, /* Q0 */ const Word16 L_frame ); void msvq_dec( const Word16 *const *cb, /* i : Codebook (indexed cb[*stages][levels][p]) (0Q15) */ @@ -6358,9 +6358,9 @@ void TonalMDCTConceal_SaveTimeSignal( // decision_matrix_dec_fx.c void decision_matrix_dec_fx( Decoder_State *st, /* i/o: decoder state structure */ - Word16 *sharpFlag, /* o : formant sharpening flag */ - Word16 *hq_core_type, /* o : HQ core type */ - Word16 *core_switching_flag /* o : ACELP->HQ switching frame flag */ + Word16 *sharpFlag, /* o : formant sharpening flag Q0 */ + Word16 *hq_core_type, /* o : HQ core type Q0 */ + Word16 *core_switching_flag /* o : ACELP->HQ switching frame flag Q0 */ ); // hf_synth_fx.c @@ -6627,60 +6627,60 @@ void PulseResynchronization_fx( // gs_dec_fx.c void decod_audio_fx( Decoder_State *st_fx, /* i/o: decoder static memory */ - Word16 dct_epit[], /* o : GSC excitation in DCT domain */ - const Word16 *Aq, /* i : LP filter coefficient */ - Word16 *pitch_buf, /* o : floating pitch values for each subframe */ - Word16 *voice_factors, /* o : voicing factors */ - Word16 *exc, /* i/o: adapt. excitation exc */ - Word16 *exc2, /* i/o: adapt. excitation/total exc */ - Word16 *bwe_exc, /* o : excitation for SWB TBE */ - Word16 *lsf_new /* i : ISFs at the end of the frame */ + Word16 dct_epit[], /* o : GSC excitation in DCT domain Qx*/ + const Word16 *Aq, /* i : LP filter coefficient Q12*/ + Word16 *pitch_buf, /* o : floating pitch values for each subframe Q6*/ + Word16 *voice_factors, /* o : voicing factors Q15*/ + Word16 *exc, /* i/o: adapt. excitation exc Q_exc*/ + Word16 *exc2, /* i/o: adapt. excitation/total exc Q_exc*/ + Word16 *bwe_exc, /* o : excitation for SWB TBE Q_exc*/ + Word16 *lsf_new /* i : ISFs at the end of the frame Qx*/ , Word16 *gain_buf /*Q14*/ ); void decod_audio_ivas_fx( - Decoder_State *st_fx, /* i/o: decoder static memory */ - Word16 dct_epit[], /* o : GSC excitation in DCT domain */ - const Word16 *Aq, /* i : LP filter coefficient */ - Word16 *pitch_buf, /* o : floating pitch values for each subframe */ - Word16 *voice_factors, /* o : voicing factors */ - Word16 *exc, /* i/o: adapt. excitation exc */ - Word16 *exc2, /* i/o: adapt. excitation/total exc */ - Word16 *bwe_exc, /* o : excitation for SWB TBE */ - Word16 *lsf_new /* i : ISFs at the end of the frame */ + Decoder_State *st_fx, /* i/o: decoder static memory */ + Word16 dct_epit[], /* o : GSC excitation in DCT domain Qx*/ + const Word16 *Aq, /* i : LP filter coefficient Q12*/ + Word16 *pitch_buf, /* o : Word16 pitch values for each subframe Q6*/ + Word16 *voice_factors, /* o : voicing factors Q15*/ + Word16 *exc, /* i/o: adapt. excitation exc Q_exc*/ + Word16 *exc2, /* i/o: adapt. excitation/total exc Q_exc*/ + Word16 *bwe_exc, /* o : excitation for SWB TBE Q_exc*/ + Word16 *lsf_new /* i : ISFs at the end of the frame Qx*/ , Word16 *gain_buf, /*Q14*/ - const Word16 tdm_lp_reuse_flag, /* i : LPC reuse flag */ - const Word16 tdm_low_rate_mode, /* i : secondary channel low rate mode flag */ - const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag */ - const Word16 tdm_Pri_pitch_buf[] /* i : primary channel pitch buffer */ + const Word16 tdm_lp_reuse_flag, /* i : LPC reuse flag Q0*/ + const Word16 tdm_low_rate_mode, /* i : secondary channel low rate mode flag Q0*/ + const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag Q0*/ + const Word16 tdm_Pri_pitch_buf[] /* i : primary channel pitch buffer Q6*/ ); void gsc_dec_fx( - Decoder_State *st_fx, /* i/o: State structure */ - Word16 exc_dct_in[], /* i/o: dct of pitch-only excitation / total excitation */ - const Word16 pit_band_idx, /* i : bin position of the cut-off frequency */ - const Word16 Diff_len, /* i : Lenght of the difference signal (before pure spectral)*/ - const Word16 bits_used, /* i : Number of bit used before frequency Q */ - const Word16 nb_subfr, /* i : Number of subframe considered */ - const Word16 coder_type, /* i : coding type */ - Word16 *last_bin, /* i : last bin of bit allocation */ - const Word16 *lsf_new, /* i : ISFs at the end of the frame */ - Word16 *exc_wo_nf, /* o : excitation (in f domain) without noisefill */ + Decoder_State *st_fx, /* i/o: State structure */ + Word16 exc_dct_in[], /* i/o: dct of pitch-only excitation / total excitation Q_exc*/ + const Word16 pit_band_idx, /* i : bin position of the cut-off frequency Q0*/ + const Word16 Diff_len, /* i : Lenght of the difference signal (before pure spectral) Q0*/ + const Word16 bits_used, /* i : Number of bit used before frequency Q Q0*/ + const Word16 nb_subfr, /* i : Number of subframe considered Q0*/ + const Word16 coder_type, /* i : coding type Q0*/ + Word16 *last_bin, /* i : last bin of bit allocation Q0*/ + const Word16 *lsf_new, /* i : ISFs at the end of the frame Qx*/ + Word16 *exc_wo_nf, /* o : excitation (in f domain) without noisefill Q_exc*/ Word16 Q_exc ); void gsc_dec_ivas_fx( Decoder_State *st_fx, /* i/o: State structure */ - Word16 exc_dct_in[], /* i/o: dct of pitch-only excitation / total excitation */ - const Word16 pit_band_idx, /* i : bin position of the cut-off frequency */ - const Word16 Diff_len, /* i : Lenght of the difference signal (before pure spectral)*/ - const Word16 bits_used, /* i : Number of bit used before frequency Q */ - const Word16 nb_subfr, /* i : Number of subframe considered */ - const Word16 coder_type, /* i : coding type */ - Word16 *last_bin, /* i : last bin of bit allocation */ - const Word16 *lsf_new, /* i : ISFs at the end of the frame */ - Word16 *exc_wo_nf, /* o : excitation (in f domain) without noisefill */ + Word16 exc_dct_in[], /* i/o: dct of pitch-only excitation / total excitation Q_exc*/ + const Word16 pit_band_idx, /* i : bin position of the cut-off frequency ` Q0*/ + const Word16 Diff_len, /* i : Lenght of the difference signal (before pure spectral) Q0*/ + const Word16 bits_used, /* i : Number of bit used before frequency Q Q0*/ + const Word16 nb_subfr, /* i : Number of subframe considered Q0*/ + const Word16 coder_type, /* i : coding type Q0*/ + Word16 *last_bin, /* i : last bin of bit allocation Q0*/ + const Word16 *lsf_new, /* i : ISFs at the end of the frame Qx*/ + Word16 *exc_wo_nf, /* o : excitation (in f domain) without noisefill Q_exc*/ Word16 *Q_exc ); void GSC_dec_init( @@ -7647,8 +7647,8 @@ void dequantize_norms_fx( // hdecnrm_fx.c void hdecnrm_fx( Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word16 numNorms, /* (i) number of norms */ - Word16 *index ); /* (o) indices of quantized norms */ + const Word16 numNorms, /* (i) number of norms Q0*/ + Word16 *index ); /* (o) indices of quantized norms Q0*/ Word16 decode_huff_context_fx( @@ -7658,31 +7658,32 @@ Word16 decode_huff_context_fx( void hdecnrm_context_fx( Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word16 N, - Word16 *index, - Word16 *n_length ); + const Word16 N, /* Q0 */ + Word16 *index, /* Q0 */ + Word16 *n_length /* Q0 */ +); void hdecnrm_resize_fx( Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word16 N, /* (i) number of SFMs */ - Word16 *index /* (o) norm quantization index vector */ + const Word16 N, /* (i) number of SFMs Q0*/ + Word16 *index /* (o) norm quantization index vector Q0*/ ); void huff_dec_fx( Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word16 N, /* i : Number of codewords to decode */ - const Word16 buffer_len, /* i : Number of bits to read */ - const Word16 num_lengths, /* i : Number of different huffman codeword lengths */ - const Word16 *thres, /* i : Threshold of first codeword of each length */ - const Word16 *offset, /* i : Offset for first codeword */ - const Word16 *huff_tab, /* i : Huffman table order by codeword lengths */ - Word16 *index /* o : Decoded index */ + const Word16 N, /* i : Number of codewords to decode Q0*/ + const Word16 buffer_len, /* i : Number of bits to read Q0*/ + const Word16 num_lengths, /* i : Number of different huffman codeword lengths Q0*/ + const Word16 *thres, /* i : Threshold of first codeword of each length Q0*/ + const Word16 *offset, /* i : Offset for first codeword Q0*/ + const Word16 *huff_tab, /* i : Huffman table order by codeword lengths Q0*/ + Word16 *index /* o : Decoded index Q0*/ ); void hdecnrm_tran_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word16 N, /* i : number of norms */ - Word16 *index /* o : indices of quantized norms */ + Decoder_State *st_fx, /* i/o: decoder state structure */ + const Word16 N, /* i : number of norms Q0*/ + Word16 *index /* o : indices of quantized norms Q0*/ ); #endif @@ -8129,24 +8130,24 @@ void music_postfilt_init( // gs_dec_amr_wb.c void improv_amr_wb_gs_fx( - const Word16 clas, /* i : signal frame class */ - const Word16 coder_type, /* i : coder type */ - const Word32 core_brate, /* i : bitrate allocated to the core */ - Word16 *seed_tcx, /* i/o: Seed used for noise generation */ - Word16 *old_Aq_fx, /* i/o: old LPC filter coefficient */ - Word16 *mem_syn2_fx, /* i/o: synthesis memory */ - const Word16 lt_voice_fac_fx, /* i/o: long term voice factor Q15 */ - const Word16 locattack, /* i : Flag for a detected attack */ - Word16 *Aq_fx, /* i/o: Decoded LP filter coefficient */ - Word16 *exc2_fx, /* i/o: Decoded complete excitation */ - const Word16 Q_exc2, /* i : Exponent of Exc2 */ - Word16 *mem_tmp_fx, /* i/o: synthesis temporary memory */ - Word16 *syn_fx, /* o: Decoded synthesis to be updated */ - const Word16 Q_syn, /* i : Synthesis scaling Q0 */ - const Word16 *pitch_buf_fx, /* i : Decoded pitch buffer */ - const Word16 Last_ener_fx, /* i : Last energy (Q8) */ - const Word16 rate_switching_reset, /* i : rate switching reset flag */ - const Word16 last_coder_type /* i : Last coder_type */ + const Word16 clas, /* i : signal frame class Q0*/ + const Word16 coder_type, /* i : coder type Q0*/ + const Word32 core_brate, /* i : bitrate allocated to the core Q0*/ + Word16 *seed_tcx, /* i/o: Seed used for noise generation Q0*/ + Word16 *old_Aq_fx, /* i/o: old LPC filter coefficient q_old_Aq*/ + Word16 *mem_syn2_fx, /* i/o: synthesis memory Q_syn*/ + const Word16 lt_voice_fac_fx, /* i/o: long term voice factor Q14*/ + const Word16 locattack, /* i : Flag for a detected attack Q0*/ + Word16 *Aq_fx, /* i/o: Decoded LP filter coefficient q_Aq*/ + Word16 *exc2_fx, /* i/o: Decoded complete excitation Q_exc2*/ + const Word16 Q_exc2, /* i : Exponent of Exc2 */ + Word16 *mem_tmp_fx, /* i/o: synthesis temporary memory Q_syn*/ + Word16 *syn_fx, /* o: Decoded synthesis to be updated Q_syn*/ + const Word16 Q_syn, /* i : Synthesis scaling */ + const Word16 *pitch_buf_fx, /* i : Decoded pitch buffer Q6*/ + const Word16 Last_ener_fx, /* i : Last energy (Q8) Q0*/ + const Word16 rate_switching_reset, /* i : rate switching reset flag Q0*/ + const Word16 last_coder_type /* i : Last coder_type Q0*/ #ifdef ADD_IVAS_GS_DEC_IMPR , const Word16 VeryLowRateSTflag /* i : Enable the noise enhancement for very low rate stereo generic mode */ @@ -8715,13 +8716,13 @@ void getTCXparam_fx( Decoder_State *st, /* i/o: Decoder State handle */ Decoder_State *st0, /* i : bitstream */ CONTEXT_HM_CONFIG hm_cfg, /* i/o: HM config */ - Word16 param[], /* o : decoded parameters */ - const Word16 bits_common, /* i : number of common bits */ - const Word16 start_bit_pos, /* i : position of the start bit */ - const Word16 *no_param_tns, /* i : number of TNS parameters per subframe */ - Word16 p_param[2], /* o : pointer to parameters for next round of bs reading*/ - Word16 nTnsBitsTCX10[2], - const Word16 pre_past_flag ); + Word16 param[], /* o : decoded parameters Q0 */ + const Word16 bits_common, /* i : number of common bits Q0 */ + const Word16 start_bit_pos, /* i : position of the start bit Q0 */ + const Word16 *no_param_tns, /* i : number of TNS parameters per subframe Q0 */ + Word16 p_param[2], /* o : pointer to parameters for next round of bs reading Q0 */ + Word16 nTnsBitsTCX10[2], /*Q0*/ + const Word16 pre_past_flag /*Q0*/ ); void dec_prm_fx( Word16 *coder_type, Word16 param[], /* (o) : decoded parameters */ @@ -8732,11 +8733,11 @@ void dec_prm_fx( Word16 *bitsRead ); void getLPCparam_fx( - Decoder_State *st, /* i/o: decoder memory state */ - Word16 param_lpc[], /* o : LTP parameters */ - Decoder_State *st0, /* i : bitstream */ - const Word16 ch, /* i : channel */ - const Word16 sns_low_br_mode /* i : SNS low-bitrate mode */ + Decoder_State *st, /* i/o: decoder memory state */ + Word16 param_lpc[], /* o : LTP parameters Q0 */ + Decoder_State *st0, /* i : bitstream */ + const Word16 ch, /* i : channel Q0 */ + const Word16 sns_low_br_mode /* i : SNS low-bitrate mode Q0 */ ); // ari_hm_fx.c diff --git a/lib_dec/dec_pit_exc_fx.c b/lib_dec/dec_pit_exc_fx.c index 3328839ea..d04dc1b30 100644 --- a/lib_dec/dec_pit_exc_fx.c +++ b/lib_dec/dec_pit_exc_fx.c @@ -21,7 +21,7 @@ /*--------------------------------------------------------------------------*/ /* OUTPUT ARGUMENTS : */ /* _ (Word16*) pitch_buf_fx : floating pitch values for each subframe Q6 */ -/* _ (Word16*) code_fx : innovation */ +/* _ (Word16*) code_fx : innovation Q12 */ /*--------------------------------------------------------------------------*/ /* INPUT/OUTPUT ARGUMENTS : */ /* Decoder_State_fx *st_fx : decoder state structure */ @@ -80,6 +80,7 @@ void dec_pit_exc_fx( Word16 gp_mem[NB_SUBFR - 1]; /* gain_pitch from previous subframes */ #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move16(); #endif use_fcb = 0; @@ -269,7 +270,7 @@ void dec_pit_exc_fx( * Find the total excitation *----------------------------------------------------------------------*/ - Rescale_exc( hMusicPF->dct_post_old_exc_fx, &exc_fx[i_subfr_fx], &bwe_exc_fx[shr( imult1616( i_subfr_fx, 2 * HIBND_ACB_L_FAC ), 1 )], hGSCDec->last_exc_dct_in_fx, + Rescale_exc( hMusicPF->dct_post_old_exc_fx, &exc_fx[i_subfr_fx], &bwe_exc_fx[( i_subfr_fx * ( 2 * HIBND_ACB_L_FAC ) ) / 2], hGSCDec->last_exc_dct_in_fx, L_subfr_fx, shr( imult1616( L_subfr_fx, 2 * HIBND_ACB_L_FAC ), 1 ), gain_code_fx, &( st_fx->Q_exc ), st_fx->Q_subfr, NULL, i_subfr_fx, coder_type ); gain_code16 = round_fx( L_shl( gain_code_fx, st_fx->Q_exc ) ); /*Q_exc*/ @@ -285,8 +286,8 @@ void dec_pit_exc_fx( FOR( i = 0; i < L_subfr_fx; i++ ) { #ifdef BASOP_NOGLOB - L_tmp = L_shl_sat( L_mult( gain_pit_fx, exc_fx[add( i, i_subfr_fx )] ), 1 ); /*Q16+Q_exc*/ - exc_fx[i + i_subfr_fx] = round_fx_sat( L_tmp ); /*Q_exc*/ + L_tmp = L_shl_sat( L_mult( gain_pit_fx, exc_fx[i + i_subfr_fx] ), 1 ); /*Q16+Q_exc*/ + exc_fx[i + i_subfr_fx] = round_fx_sat( L_tmp ); /*Q_exc*/ #else L_tmp = L_shl( L_mult( gain_pit_fx, exc_fx[i + i_subfr_fx] ), 1 ); /*Q16+Q_exc*/ exc_fx[i + i_subfr_fx] = round_fx( L_tmp ); /*Q_exc*/ @@ -300,7 +301,7 @@ void dec_pit_exc_fx( FOR( i = 0; i < L_subfr_fx; i++ ) { - L_tmp = L_mult( gain_pitx2, exc_fx[add( i, i_subfr_fx )] ); /*Q16+Q_exc*/ + L_tmp = L_mult( gain_pitx2, exc_fx[i + i_subfr_fx] ); /*Q16+Q_exc*/ #ifdef BASOP_NOGLOB exc_fx[i + i_subfr_fx] = round_fx_sat( L_tmp ); /*Q_exc*/ #else @@ -695,7 +696,7 @@ void dec_pit_exc_ivas_fx( move16(); } #ifdef BASOP_NOGLOB - gain_code_fx = L_mult0( s_max( sub( 32767, shl_o( gain_pit_fx, 1, &Overflow ) ), 16384 ), st_fx->lp_gainc_fx ); /* Use gain pitch and past gain code as an indicator to help finding the best scaling value. gain_code_fx used a temp var*/ + gain_code_fx = L_mult0( s_max( sub( 32767, shl_o( gain_pit_fx, 1, &Overflow ) ), 16384 /*0.5.Q15*/ ), st_fx->lp_gainc_fx ); /* Use gain pitch and past gain code as an indicator to help finding the best scaling value. gain_code_fx used a temp var*/ #else gain_code_fx = L_mult0( s_max( sub( 32767, shl( gain_pit_fx, 1 ) ), 16384 ), st_fx->lp_gainc_fx ); /* Use gain pitch and past gain code as an indicator to help finding the best scaling value. gain_code_fx used a temp var*/ #endif @@ -704,7 +705,7 @@ void dec_pit_exc_ivas_fx( /*----------------------------------------------------------------------* * Find the total excitation *----------------------------------------------------------------------*/ - Rescale_exc( hMusicPF->dct_post_old_exc_fx, &exc_fx[i_subfr_fx], &bwe_exc_fx[shr( imult1616( i_subfr_fx, 2 * HIBND_ACB_L_FAC ), 1 )], hGSCDec->last_exc_dct_in_fx, + Rescale_exc( hMusicPF->dct_post_old_exc_fx, &exc_fx[i_subfr_fx], &bwe_exc_fx[( i_subfr_fx * ( 2 * HIBND_ACB_L_FAC ) ) / 2], hGSCDec->last_exc_dct_in_fx, L_subfr_fx, shr( imult1616( L_subfr_fx, 2 * HIBND_ACB_L_FAC ), 1 ), gain_code_fx, &( st_fx->Q_exc ), st_fx->Q_subfr, NULL, i_subfr_fx, coder_type ); gain_code16 = round_fx( L_shl( gain_code_fx, st_fx->Q_exc ) ); /*Q_exc*/ @@ -726,8 +727,8 @@ void dec_pit_exc_ivas_fx( { FOR( i = 0; i < L_subfr_fx; i++ ) { - L_tmp = L_shl( L_mult( gain_pit_fx, exc_fx[add( i, i_subfr_fx )] ), 1 ); /*Q16+Q_exc*/ - exc_fx[add( i, i_subfr_fx )] = round_fx( L_tmp ); /*Q_exc*/ + L_tmp = L_shl( L_mult( gain_pit_fx, exc_fx[i + i_subfr_fx] ), 1 ); /*Q16+Q_exc*/ + exc_fx[i + i_subfr_fx] = round_fx( L_tmp ); /*Q_exc*/ move16(); } } @@ -737,8 +738,8 @@ void dec_pit_exc_ivas_fx( FOR( i = 0; i < L_subfr_fx; i++ ) { - L_tmp = L_mult( gain_pitx2, exc_fx[add( i, i_subfr_fx )] ); /*Q16+Q_exc*/ - exc_fx[add( i, i_subfr_fx )] = round_fx( L_tmp ); /*Q_exc*/ + L_tmp = L_mult( gain_pitx2, exc_fx[i + i_subfr_fx] ); /*Q16+Q_exc*/ + exc_fx[i + i_subfr_fx] = round_fx( L_tmp ); /*Q_exc*/ move16(); } } @@ -859,7 +860,7 @@ void dec_pit_exc_ivas_fx( p_Aq_fx += 4 * ( M + 1 ); /* update gains for FEC - equivalent to lp_gain_updt() */ - st_fx->lp_gainp_fx = gain_pit_fx; + st_fx->lp_gainp_fx = gain_pit_fx; // Q14 move16(); st_fx->lp_gainc_fx = 0; move16(); diff --git a/lib_dec/dec_post_fx.c b/lib_dec/dec_post_fx.c index 977146b34..296b5cef7 100644 --- a/lib_dec/dec_post_fx.c +++ b/lib_dec/dec_post_fx.c @@ -103,7 +103,7 @@ void nb_post_filt_fx( /* update long-term background noise energy during inactive frames */ IF( EQ_16( coder_type, INACTIVE ) ) { - *psf_lp_noise = round_fx( L_mac( L_mult( 31130, *psf_lp_noise ), 26214 /*0.05 Q19*/, shl( tmp_noise, 4 ) ) ); /*Q8*Q15 + Q19*Q4 -> Q8 */ + *psf_lp_noise = round_fx( L_mac( L_mult( 31130 /*0.95.Q15*/, *psf_lp_noise ), 26214 /*0.05 Q19*/, shl( tmp_noise, 4 ) ) ); /*Q8*Q15 + Q19*Q4 -> Q8 */ } } @@ -112,17 +112,17 @@ void nb_post_filt_fx( IF( hPFstat->reset ) { set16_fx( hPFstat->mem_res2, 0, DECMEM_RES2 ); - Copy( &Synth[L_frame - L_SYN_MEM], hPFstat->mem_pf_in, L_SYN_MEM ); + Copy( &Synth[L_frame - L_SYN_MEM], hPFstat->mem_pf_in, L_SYN_MEM ); // Qsyn Copy( &Synth[L_frame - L_SYN_MEM], hPFstat->mem_stp, L_SYN_MEM ); - hPFstat->gain_prec = 16384; + hPFstat->gain_prec = 16384; // 1.Q14 move16(); hPFstat->reset = 0; move16(); return; } Pf_in = &pf_in_buffer[M]; - Copy( hPFstat->mem_pf_in + L_SYN_MEM - M, &Pf_in[-M], M ); - Copy( Synth, Pf_in, L_frame ); + Copy( hPFstat->mem_pf_in + L_SYN_MEM - M, &Pf_in[-M], M ); // Qsyn + Copy( Synth, Pf_in, L_frame ); // Qsyn Copy( &Synth[L_frame - L_SYN_MEM], hPFstat->mem_pf_in, L_SYN_MEM ); /* deactivation of the post filter in case of AUDIO because it causes problems to singing sequences */ IF( EQ_16( coder_type, AUDIO ) ) @@ -137,13 +137,13 @@ void nb_post_filt_fx( /* run the post filter */ - p_Aq = Aq; + p_Aq = Aq; // Q12 move16(); j = 0; move16(); FOR( i = 0; i < L_frame; i += L_SUBFR ) { - T0_first = Pitch_buf[j]; + T0_first = Pitch_buf[j]; // Q6 move16(); Dec_postfilt_fx( hPFstat, T0_first, &Pf_in[i], p_Aq, &Synth[i], Post_G1, Post_G2, Gain_factor, disable_hpf ); @@ -180,26 +180,26 @@ void nb_post_filt_fx( *----------------------------------------------------------------------------*/ static void Dec_postfilt_fx( PFSTAT_HANDLE hPFstat, /* i : core decoder parameters */ - const Word16 t0, /* i : pitch delay given by coder */ - const Word16 *signal_ptr, /* i : input signal (pointer to current subframe */ - const Word16 *coeff, /* i : LPC coefficients for current subframe */ - Word16 *sig_out, /* o : postfiltered output */ - const Word16 gamma1, /* i : short term postfilt. den. weighting factor */ - const Word16 gamma2, /* i : short term postfilt. num. weighting factor */ + const Word16 t0, /* i : pitch delay given by coder Q6 */ + const Word16 *signal_ptr, /* i : input signal (pointer to current subframe Q0 */ + const Word16 *coeff, /* i : LPC coefficients for current subframe Q12 */ + Word16 *sig_out, /* o : postfiltered output Q15*/ + const Word16 gamma1, /* i : short term postfilt. den. weighting factor Q15*/ + const Word16 gamma2, /* i : short term postfilt. num. weighting factor Q15*/ const Word16 Gain_factor, /* i : Gain Factor (Q15) */ const Word16 disable_hpf ) { /* Local variables and arrays */ - Word16 apond1[M + 1]; /* s.t. denominator coeff. */ - Word16 apond2[LONG_H_ST]; + Word16 apond1[M + 1]; /* s.t. denominator coeff. Q12*/ + Word16 apond2[LONG_H_ST]; // Q12 Word16 sig_ltp[L_SUBFR + 1]; /* H0 output signal */ - Word16 res2[SIZ_RES2]; + Word16 res2[SIZ_RES2]; // Q0 Word16 *sig_ltp_ptr; Word16 *res2_ptr; Word16 *ptr_mem_stp; - Word16 parcor0; + Word16 parcor0; // Q15 /* Init pointers and restore memories */ @@ -259,7 +259,7 @@ static void Dec_postfilt_fx( void formant_post_filt_fx( PFSTAT_HANDLE hPFstat, /* i : core decoder parameters */ Word16 *synth_in, /* i : 12k8 synthesis */ - Word16 *Aq, /* i : LP filter coefficient */ + Word16 *Aq, /* i : LP filter coefficient Q12 */ Word16 *synth_out, /* i/o: input signal */ Word16 L_frame, Word32 lp_noise, /* (i) : background noise energy (15Q16) */ @@ -269,7 +269,7 @@ void formant_post_filt_fx( { Word16 i_subfr; Word16 *p_Aq; - Word16 post_G1, post_G2; + Word16 post_G1, post_G2; // Q15 /*default parameter for noisy speech and high bit-rates*/ @@ -351,7 +351,7 @@ void formant_post_filt_fx( } /* Reset post filter */ - if ( hPFstat->reset != 0 ) + IF( hPFstat->reset != 0 ) { post_G1 = MAX16B; move16(); @@ -361,7 +361,7 @@ void formant_post_filt_fx( move16(); Copy( &synth_in[L_frame - L_SYN_MEM], hPFstat->mem_pf_in, L_SYN_MEM ); Copy( &synth_in[L_frame - L_SYN_MEM], hPFstat->mem_stp, L_SYN_MEM ); - hPFstat->gain_prec = 16384; + hPFstat->gain_prec = 16384; // 1.Q14 move16(); Copy( synth_in, synth_out, L_frame ); @@ -373,7 +373,7 @@ void formant_post_filt_fx( Copy( &synth_in[L_frame - L_SYN_MEM], hPFstat->mem_pf_in, L_SYN_MEM ); move16(); - p_Aq = Aq; + p_Aq = Aq; // Q12 FOR( i_subfr = 0; i_subfr < L_frame; i_subfr += L_SUBFR ) { Dec_formant_postfilt_fx( hPFstat, &synth_in[i_subfr], p_Aq, &synth_out[i_subfr], post_G1, post_G2 ); @@ -385,7 +385,7 @@ void formant_post_filt_fx( void formant_post_filt_ivas_fx( PFSTAT_HANDLE hPFstat, /* i : core decoder parameters */ Word16 *synth_in, /* i : 12k8 synthesis */ - Word16 *Aq, /* i : LP filter coefficient */ + Word16 *Aq, /* i : LP filter coefficient Q12 */ Word16 *synth_out, /* i/o: input signal */ Word16 L_frame, Word32 lp_noise, /* (i) : background noise energy (15Q16) */ @@ -477,7 +477,7 @@ void formant_post_filt_ivas_fx( } /* Reset post filter */ - if ( hPFstat->reset != 0 ) + IF( hPFstat->reset != 0 ) { post_G1 = MAX16B; move16(); @@ -487,7 +487,7 @@ void formant_post_filt_ivas_fx( move16(); Copy( &synth_in[L_frame - L_SYN_MEM], hPFstat->mem_pf_in, L_SYN_MEM ); Copy( &synth_in[L_frame - L_SYN_MEM], hPFstat->mem_stp, L_SYN_MEM ); - hPFstat->gain_prec = 16384; + hPFstat->gain_prec = 16384; // 1.Q14 move16(); Copy( synth_in, synth_out, L_frame ); @@ -499,7 +499,7 @@ void formant_post_filt_ivas_fx( Copy( &synth_in[L_frame - L_SYN_MEM], hPFstat->mem_pf_in, L_SYN_MEM ); move16(); - p_Aq = Aq; + p_Aq = Aq; // Q12 FOR( i_subfr = 0; i_subfr < L_frame; i_subfr += L_SUBFR ) { Dec_formant_postfilt_ivas_fx( hPFstat, &synth_in[i_subfr], p_Aq, &synth_out[i_subfr], post_G1, post_G2 ); @@ -524,19 +524,19 @@ void formant_post_filt_ivas_fx( *----------------------------------------------------------------------------*/ static void Dec_formant_postfilt_fx( PFSTAT_HANDLE hPFstat, /* i : core decoder parameters */ - Word16 *signal_ptr, /* i : input signal (pointer to current subframe */ - Word16 *coeff, /* i : LPC coefficients for current subframe */ + Word16 *signal_ptr, /* i : input signal (pointer to current subframe Q14*/ + Word16 *coeff, /* i : LPC coefficients for current subframe Q12 */ Word16 *sig_out, /* o : postfiltered output */ - Word16 gamma1, /* i : short term postfilt. den. weighting factor*/ - Word16 gamma2 /* i : short term postfilt. num. weighting factor*/ + Word16 gamma1, /* i : short term postfilt. den. weighting factor Q15*/ + Word16 gamma2 /* i : short term postfilt. num. weighting factor Q15*/ ) { /* Local variables and arrays */ - Word16 apond1[M + 1]; /* s.t. denominator coeff. */ - Word16 apond2[LONG_H_ST]; - Word16 res2[L_SUBFR]; - Word16 resynth[L_SUBFR + 1]; - Word16 parcor0; + Word16 apond1[M + 1]; /* s.t. denominator coeff. Q12*/ + Word16 apond2[LONG_H_ST]; // Q12 + Word16 res2[L_SUBFR]; // Q14 + Word16 resynth[L_SUBFR + 1]; // Qy + Word16 parcor0; // Q15 Word16 i, max; Word16 scale_down; @@ -545,14 +545,14 @@ static void Dec_formant_postfilt_fx( weight_a_fx( coeff, apond2, gamma2, M ); set16_fx( &apond2[M + 1], 0, LONG_H_ST - ( M + 1 ) ); - max = abs_s( signal_ptr[0] ); + max = abs_s( signal_ptr[0] ); // Q14 FOR( i = 1; i < L_SUBFR; i++ ) { max = s_max( max, abs_s( signal_ptr[i] ) ); } scale_down = 0; move16(); - if ( GT_16( max, 16384 ) ) + if ( GT_16( max, 16384 /*1.Q14*/ ) ) { scale_down = 1; move16(); @@ -604,19 +604,19 @@ static void Dec_formant_postfilt_fx( #ifdef IVAS_FLOAT_FIXED static void Dec_formant_postfilt_ivas_fx( PFSTAT_HANDLE hPFstat, /* i : core decoder parameters */ - Word16 *signal_ptr, /* i : input signal (pointer to current subframe */ - Word16 *coeff, /* i : LPC coefficients for current subframe */ + Word16 *signal_ptr, /* i : input signal (pointer to current subframe Q14*/ + Word16 *coeff, /* i : LPC coefficients for current subframe Q12 */ Word16 *sig_out, /* o : postfiltered output */ - Word16 gamma1, /* i : short term postfilt. den. weighting factor*/ - Word16 gamma2 /* i : short term postfilt. num. weighting factor*/ + Word16 gamma1, /* i : short term postfilt. den. weighting factor Q15*/ + Word16 gamma2 /* i : short term postfilt. num. weighting factor Q15*/ ) { /* Local variables and arrays */ - Word16 apond1[M + 1]; /* s.t. denominator coeff. */ - Word16 apond2[LONG_H_ST]; - Word16 res2[L_SUBFR]; - Word16 resynth[L_SUBFR + 1]; - Word16 parcor0; + Word16 apond1[M + 1]; /* s.t. denominator coeff. Q12*/ + Word16 apond2[LONG_H_ST]; // Q12 + Word16 res2[L_SUBFR]; // Q14 + Word16 resynth[L_SUBFR + 1]; // Qy + Word16 parcor0; // Q15 Word16 i, max; Word16 scale_down; @@ -625,14 +625,14 @@ static void Dec_formant_postfilt_ivas_fx( weight_a_fx( coeff, apond2, gamma2, M ); set16_fx( &apond2[M + 1], 0, LONG_H_ST - ( M + 1 ) ); - max = abs_s( signal_ptr[0] ); + max = abs_s( signal_ptr[0] ); // Q14 FOR( i = 1; i < L_SUBFR; i++ ) { max = s_max( max, abs_s( signal_ptr[i] ) ); } scale_down = 0; move16(); - if ( GT_16( max, 16384 ) ) + if ( GT_16( max, 16384 /*1.Q14*/ ) ) { scale_down = 1; move16(); @@ -693,7 +693,7 @@ static void modify_pst_param_fx( Word16 *g1, /* o : Gamma1 used in post filter Q15 */ Word16 *g2, /* o : Gamma1 used in post filter Q15 */ const Word16 coder_type, /* i : Vad information decoded in UV frame */ - Word16 *gain_factor /* o : Gain factor applied in post filtering */ + Word16 *gain_factor /* o : Gain factor applied in post filtering Q15 */ ) { Word16 tmp; @@ -758,9 +758,9 @@ static void modify_pst_param_fx( * Perform harmonic postfilter *----------------------------------------------------------------------------*/ static void pst_ltp_fx( - Word16 t0, /* i : pitch delay given by coder */ - Word16 *ptr_sig_in, /* i : postfilter i filter (residu2) */ - Word16 *ptr_sig_pst0, /* o : harmonic postfilter o */ + Word16 t0, /* i : pitch delay given by coder Q6 */ + Word16 *ptr_sig_in, /* i : postfilter i filter (residu2) Qx */ + Word16 *ptr_sig_pst0, /* o : harmonic postfilter o Qx */ Word16 gain_factor /* i : Gain Factor (Q15) */ ) { @@ -790,8 +790,8 @@ static void pst_ltp_fx( /* i signal justified on 13 bits */ - ptr_sig = ptr_sig_in - DECMEM_RES2; - nb_sh_sig = getScaleFactor16( ptr_sig, add( DECMEM_RES2, L_SUBFR ) ); + ptr_sig = ptr_sig_in - DECMEM_RES2; // Qx + nb_sh_sig = getScaleFactor16( ptr_sig, DECMEM_RES2 + L_SUBFR ); nb_sh_sig = sub( 3, nb_sh_sig ); FOR( i = 0; i < DECMEM_RES2 + L_SUBFR; i++ ) @@ -814,7 +814,7 @@ static void pst_ltp_fx( { IF( phase == 0 ) { - ptr_y_up = ptr_sig_in - ltpdel; + ptr_y_up = ptr_sig_in - ltpdel; // Qx } ELSE { @@ -890,7 +890,7 @@ static void pst_ltp_fx( /* gain_plt += (1.0f-gain_plt) * gain_factor */ /* gain_plt = gain_plt + gain_factor - gain_plt*gain_factor */ #ifdef BASOP_NOGLOB - gain_plt = msu_ro( L_msu( L_deposit_h( gain_plt ), gain_plt, gain_factor ), -32768, gain_factor, &Overflow ); + gain_plt = msu_ro( L_msu( L_deposit_h( gain_plt ), gain_plt, gain_factor ), -32768, gain_factor, &Overflow ); // Q15 #else gain_plt = msu_r( L_msu( L_deposit_h( gain_plt ), gain_plt, gain_factor ), -32768, gain_factor ); #endif @@ -906,12 +906,12 @@ static void pst_ltp_fx( * Computes best (shortest) integer LTP delay + fine search *---------------------------------------------------------------------------*/ static void search_del_fx( - Word16 t0, /* i : pitch delay given by coder */ + Word16 t0, /* i : pitch delay given by coder Q0 */ Word16 *ptr_sig_in, /* i : i signal (with delay line) */ Word16 *ltpdel, /* o : delay = *ltpdel - *phase / f_up */ Word16 *phase, /* o : phase */ - Word16 *num_gltp, /* o : 16 bits numerator of LTP gain */ - Word16 *den_gltp, /* o : 16 bits denominator of LTP gain */ + Word16 *num_gltp, /* o : 16 bits numerator of LTP gain Q(sh_num_gltp) */ + Word16 *den_gltp, /* o : 16 bits denominator of LTP gain Q(sh_den_gltp) */ Word16 *sh_num_gltp, /* o : justification for num_gltp */ Word16 *sh_den_gltp, /* o : justification for den_gltp */ Word16 *y_up, /* o : LT delayed signal if fract. delay */ @@ -933,10 +933,10 @@ static void search_del_fx( Word16 *ptr1, *ptr_y_up; Word16 i, n; - Word16 num, den0, den1; + Word16 num /*Q(sh_num)*/, den0 /*Q(sh_den)*/, den1 /*Q(sh_den)*/; Word16 den_max, num_max; Word32 L_numsq_max; - Word16 ener; + Word16 ener; // Q(sh_ener) Word16 sh_num, sh_den, sh_ener; Word16 i_max, lambda, phi, phi_max, ioff; Word16 temp; @@ -1320,7 +1320,7 @@ static void search_del_fx( } ELSE { - if ( temp > 0 ) + IF( temp > 0 ) { L_temp1 = L_shr( L_temp1, temp ); } @@ -1365,10 +1365,10 @@ static void search_del_fx( * Perform long term postfilter *----------------------------------------------------------------------------*/ static void filt_plt_fx( - Word16 *s_in, /* i : i signal with past */ - Word16 *s_ltp, /* i : filtered signal with gain 1 */ - Word16 *s_out, /* o : signal */ - Word16 gain_plt /* i : filter gain */ + Word16 *s_in, /* i : i signal with past Qx */ + Word16 *s_ltp, /* i : filtered signal with gain 1 Qx*/ + Word16 *s_out, /* o : signal Qx */ + Word16 gain_plt /* i : filter gain Q15 */ ) { @@ -1379,15 +1379,15 @@ static void filt_plt_fx( Word16 gain_plt_1; - gain_plt_1 = sub( 32767, gain_plt ); - gain_plt_1 = add( gain_plt_1, 1 ); /* 2**15 (1 - g) */ + gain_plt_1 = sub( 32767, gain_plt ); // Q15 + gain_plt_1 = add( gain_plt_1, 1 ); /* 2**15 (1 - g) */ FOR( n = 0; n < L_SUBFR; n++ ) { /* s_out(n) = gain_plt x s_in(n) + gain_plt_1 x s_ltp(n) */ - L_acc = L_mult( gain_plt, s_in[n] ); - s_out[n] = mac_r( L_acc, gain_plt_1, s_ltp[n] ); - move16(); /* no overflow */ + L_acc = L_mult( gain_plt, s_in[n] ); // Qx + Q15 + 1 + s_out[n] = mac_r( L_acc, gain_plt_1, s_ltp[n] ); // Qx + move16(); /* no overflow */ } @@ -1406,8 +1406,8 @@ static void compute_ltp_l_fx( Word16 ltpdel, /* i : delay factor */ Word16 phase, /* i : phase factor */ Word16 *y_up, /* i : delayed signal */ - Word16 *num, /* i : numerator of LTP gain */ - Word16 *den, /* i : denominator of LTP gain */ + Word16 *num, /* i : numerator of LTP gain Q(sh_num) */ + Word16 *den, /* i : denominator of LTP gain Q(sh_den) */ Word16 *sh_num, /* i : justification factor of num */ Word16 *sh_den /* i : justification factor of den */ ) @@ -1420,7 +1420,7 @@ static void compute_ltp_l_fx( temp = sub( phase, 1 ); temp = shl( temp, L2_LH2_L ); - ptr_h = tab_hup_l_fx + temp; /* tab_hup_l_fx + LH2_L * (phase-1) */ + ptr_h = tab_hup_l_fx + temp; /* tab_hup_l_fx + LH2_L * (phase-1) */ // Q15 temp = sub( LH_UP_L, ltpdel ); ptr2 = s_in + temp; @@ -1459,6 +1459,7 @@ static void compute_ltp_l_fx( *num = extract_l( L_acc ); *sh_num = temp; move16(); + move16(); } /* Compute den */ @@ -1477,6 +1478,7 @@ static void compute_ltp_l_fx( *den = extract_l( L_acc ); *sh_den = temp; move16(); + move16(); return; @@ -1490,12 +1492,12 @@ static void compute_ltp_l_fx( * and gain2 = num2 * 2** sh_num2 / den2 * 2** sh_den2 *----------------------------------------------------------------------------*/ static Word16 select_ltp_fx( /* o : 1 = 1st gain, 2 = 2nd gain */ - Word16 num1, /* i : numerator of gain1 */ - Word16 den1, /* i : denominator of gain1 */ + Word16 num1, /* i : numerator of gain1 Q(sh_num1) */ + Word16 den1, /* i : denominator of gain1 Q(sh_den1) */ Word16 sh_num1, /* i : just. factor for num1 */ Word16 sh_den1, /* i : just. factor for den1 */ - Word16 num2, /* i : numerator of gain2 */ - Word16 den2, /* i : denominator of gain2 */ + Word16 num2, /* i : numerator of gain2 Q(sh_num2) */ + Word16 den2, /* i : denominator of gain2 Q(sh_den2) */ Word16 sh_num2, /* i : just. factor for num2 */ Word16 sh_den2 /* i : just. factor for den2 */ ) @@ -1506,7 +1508,7 @@ static Word16 select_ltp_fx( /* o : 1 = 1st gain, 2 = 2nd gain Word16 temp1, temp2; - if ( den2 == 0 ) + IF( den2 == 0 ) { return 1; } @@ -1526,11 +1528,11 @@ static Word16 select_ltp_fx( /* o : 1 = 1st gain, 2 = 2nd gain temp2 = add( temp2, sh_den1 ); temp2 = sub( temp2, temp1 ); - if ( temp2 > 0 ) + IF( temp2 > 0 ) { L_temp1 = L_shr( L_temp1, temp2 ); /* temp2 > 0 */ } - if ( temp2 < 0 ) + IF( temp2 < 0 ) { L_temp2 = L_shl( L_temp2, temp2 ); /* temp2 < 0 */ } @@ -1555,10 +1557,10 @@ static Word16 select_ltp_fx( /* o : 1 = 1st gain, 2 = 2nd gain * SUMn (abs (h[n])) and computes parcor0 *---------------------------------------------------------------------------- */ static void calc_st_filt_local_fx( - Word16 *apond2, /* i : coefficients of numerator */ - Word16 *apond1, /* i : coefficients of denominator */ - Word16 *parcor0, /* o : 1st parcor calcul. on composed filter */ - Word16 *sig_ltp_ptr, /* i/o: i of 1/A(gamma1) : scaled by 1/g0 */ + Word16 *apond2, /* i : coefficients of numerator Q12 */ + Word16 *apond1, /* i : coefficients of denominator Q12 */ + Word16 *parcor0, /* o : 1st parcor calcul. on composed filter Q15*/ + Word16 *sig_ltp_ptr, /* i/o: i of 1/A(gamma1) : scaled by 1/g0 Qx */ Word16 *mem_zero /* i : All zero memory */ ) { @@ -1579,20 +1581,20 @@ static void calc_st_filt_local_fx( Calc_rc0_h( h, parcor0 ); /* compute g0 */ - L_g0 = L_mult0( 1, abs_s( h[0] ) ); + L_g0 = L_mult0( 1, abs_s( h[0] ) ); // Q12 FOR( i = 1; i < LONG_H_ST; i++ ) { - L_g0 = L_mac0( L_g0, 1, abs_s( h[i] ) ); + L_g0 = L_mac0( L_g0, 1, abs_s( h[i] ) ); // Q12 } - g0 = extract_h( L_shl( L_g0, 14 ) ); + g0 = extract_h( L_shl( L_g0, 14 ) ); // Q10 /* Scale signal i of 1/A(gamma1) */ - IF( GT_16( g0, 1024 ) ) + IF( GT_16( g0, 1024 ) ) /*1024 = 1.Q10*/ { - temp = div_s( 1024, g0 ); /* temp = 2**15 / gain0 */ + temp = div_s( 1024, g0 ); /* temp => Q15 / gain0 */ /*1024 = 1.Q10*/ FOR( i = 0; i < L_SUBFR; i++ ) { - sig_ltp_ptr[i] = mult_r( sig_ltp_ptr[i], temp ); + sig_ltp_ptr[i] = mult_r( sig_ltp_ptr[i], temp ); // Qx move16(); } } @@ -1603,17 +1605,17 @@ static void calc_st_filt_local_fx( #ifdef IVAS_FLOAT_FIXED static void calc_st_filt_ivas_fx( - Word16 *apond2, /* i : coefficients of numerator */ - Word16 *apond1, /* i : coefficients of denominator */ - Word16 *parcor0, /* o : 1st parcor calcul. on composed filter */ - Word16 *sig_ltp_ptr, /* i/o: i of 1/A(gamma1) : scaled by 1/g0 */ + Word16 *apond2, /* i : coefficients of numerator Q12 */ + Word16 *apond1, /* i : coefficients of denominator Q12 */ + Word16 *parcor0, /* o : 1st parcor calcul. on composed filter Q15 */ + Word16 *sig_ltp_ptr, /* i/o: i of 1/A(gamma1) : scaled by 1/g0 Qx*/ Word16 *mem_zero, /* i : All zero memory */ const Word16 extl /* i : extension layer info */ ) { Word32 L_g0; - Word16 h[LONG_H_ST]; + Word16 h[LONG_H_ST]; // Q12 Word16 g0, temp; Word16 i; @@ -1635,20 +1637,20 @@ static void calc_st_filt_ivas_fx( Calc_rc0_h( h, parcor0 ); /* compute g0 */ - L_g0 = L_mult0( 1, abs_s( h[0] ) ); + L_g0 = L_mult0( 1, abs_s( h[0] ) ); // Q12 FOR( i = 1; i < LONG_H_ST; i++ ) { - L_g0 = L_mac0( L_g0, 1, abs_s( h[i] ) ); + L_g0 = L_mac0( L_g0, 1, abs_s( h[i] ) ); // Q12 } - g0 = extract_h( L_shl( L_g0, 14 ) ); + g0 = extract_h( L_shl( L_g0, 14 ) ); // Q10 /* Scale signal i of 1/A(gamma1) */ - IF( GT_16( g0, 1024 ) ) + IF( GT_16( g0, 1024 ) ) /*1024 = 1.Q10*/ { - temp = div_s( 1024, g0 ); /* temp = 2**15 / gain0 */ + temp = div_s( 1024, g0 ); /* temp => Q15 / gain0 */ /*1024 = 1.Q10*/ FOR( i = 0; i < L_SUBFR; i++ ) { - sig_ltp_ptr[i] = mult_r( sig_ltp_ptr[i], temp ); + sig_ltp_ptr[i] = mult_r( sig_ltp_ptr[i], temp ); // Qx move16(); } } @@ -1685,34 +1687,34 @@ void Filt_mu_fx( IF( parcor0 > 0 ) { - mu = mult_r( parcor0, GAMMA3_PLUS_FX ); + mu = mult_r( parcor0, GAMMA3_PLUS_FX ); // Q15 /* GAMMA3_PLUS_FX < 0.5 */ sh_fact = 14; move16(); /* sh_fact */ fact = (Word16) 0x4000; - move16(); /* 2**sh_fact */ + move16(); /* Q(sh_fact) */ L_fact = (Word32) L_deposit_l( 0x2000 ); /* fact >> 1 */ } ELSE { - mu = mult_r( parcor0, GAMMA3_MINUS_FX ); + mu = mult_r( parcor0, GAMMA3_MINUS_FX ); // Q15 /* GAMMA3_MINUS_FX < 0.9375 */ sh_fact = 11; move16(); /* sh_fact */ fact = (Word16) 0x0800; - move16(); /* 2**sh_fact */ + move16(); /* Q(sh_fact) */ L_fact = (Word32) L_deposit_l( 0x0400 ); /* fact >> 1 */ } temp = sub( 1, abs_s( mu ) ); BASOP_SATURATE_WARNING_OFF_EVS; #ifdef BASOP_NOGLOB - mu2 = add_o( 32767, temp, &Overflow ); /* 2**15 (1 - |mu|) */ + mu2 = add_o( 32767, temp, &Overflow ); /* Q15 (1 - |mu|) */ #else mu2 = add( 32767, temp ); /* 2**15 (1 - |mu|) */ #endif BASOP_SATURATE_WARNING_ON_EVS; - ga = div_s( fact, mu2 ); /* 2**sh_fact / (1 - |mu|) */ + ga = div_s( fact, mu2 ); /* Q(sh_fact) / (1 - |mu|) */ ptrs = sig_in; /* points on sig_in(-1) */ @@ -1748,7 +1750,7 @@ void Filt_mu_fx( void Filt_mu_ivas_fx( Word16 *sig_in, /* i : signal (beginning at sample -1) */ Word16 *sig_out, /* o : signal with tilt */ - Word16 parcor0, /* i : parcor0 (mu = parcor0 * gamma3) */ + Word16 parcor0, /* i : parcor0 (mu = parcor0 * gamma3) Q15 */ Word16 L_subfr, /* i : the length of subframe */ const Word16 extl ) { @@ -1768,58 +1770,58 @@ void Filt_mu_ivas_fx( { IF( parcor0 > 0 ) { - mu = mult_r( parcor0, GAMMA3_PLUS_WB_FX ); + mu = mult_r( parcor0, GAMMA3_PLUS_WB_FX ); // Q15 /* GAMMA3_PLUS_FX < 0.5 */ sh_fact = 14; move16(); /* sh_fact */ fact = (Word16) 0x4000; - move16(); /* 2**sh_fact */ - L_fact = (Word32) L_deposit_l( 0x2000 ); /* fact >> 1 */ + move16(); /* Q(sh_fact) */ + L_fact = L_deposit_l( 0x2000 ); /* fact >> 1 */ } ELSE { - mu = mult_r( parcor0, GAMMA3_MINUS_WB_FX ); + mu = mult_r( parcor0, GAMMA3_MINUS_WB_FX ); // Q15 /* GAMMA3_MINUS_FX < 0.9375 */ sh_fact = 11; move16(); /* sh_fact */ fact = (Word16) 0x0800; - move16(); /* 2**sh_fact */ - L_fact = (Word32) L_deposit_l( 0x0400 ); /* fact >> 1 */ + move16(); /* Q(sh_fact) */ + L_fact = L_deposit_l( 0x0400 ); /* fact >> 1 */ } } ELSE { IF( parcor0 > 0 ) { - mu = mult_r( parcor0, GAMMA3_PLUS_FX ); + mu = mult_r( parcor0, GAMMA3_PLUS_FX ); // Q15 /* GAMMA3_PLUS_FX < 0.5 */ sh_fact = 14; move16(); /* sh_fact */ fact = (Word16) 0x4000; - move16(); /* 2**sh_fact */ - L_fact = (Word32) L_deposit_l( 0x2000 ); /* fact >> 1 */ + move16(); /* Q(sh_fact) */ + L_fact = L_deposit_l( 0x2000 ); /* fact >> 1 */ } ELSE { - mu = mult_r( parcor0, GAMMA3_MINUS_FX ); + mu = mult_r( parcor0, GAMMA3_MINUS_FX ); // Q15 /* GAMMA3_MINUS_FX < 0.9375 */ sh_fact = 11; move16(); /* sh_fact */ fact = (Word16) 0x0800; - move16(); /* 2**sh_fact */ - L_fact = (Word32) L_deposit_l( 0x0400 ); /* fact >> 1 */ + move16(); /* Q(sh_fact) */ + L_fact = L_deposit_l( 0x0400 ); /* fact >> 1 */ } } temp = sub( 1, abs_s( mu ) ); BASOP_SATURATE_WARNING_OFF_EVS; #ifdef BASOP_NOGLOB - mu2 = add_o( 32767, temp, &Overflow ); /* 2**15 (1 - |mu|) */ + mu2 = add_o( 32767, temp, &Overflow ); /* Q15 (1 - |mu|) */ #else mu2 = add( 32767, temp ); /* 2**15 (1 - |mu|) */ #endif BASOP_SATURATE_WARNING_ON_EVS; - ga = div_s( fact, mu2 ); /* 2**sh_fact / (1 - |mu|) */ + ga = div_s( fact, mu2 ); /* Q(sh_fact) / (1 - |mu|) */ ptrs = sig_in; /* points on sig_in(-1) */ @@ -1854,9 +1856,9 @@ void Filt_mu_ivas_fx( * gain[n] = AGC_FAC_FX * gain[n-1] + (1 - AGC_FAC_FX) g_in/g_out *---------------------------------------------------------------------------*/ void scale_st_fx( - const Word16 *sig_in, /* i : postfilter i signal */ - Word16 *sig_out, /* i/o: postfilter o signal */ - Word16 *gain_prec, /* i/o: last value of gain for subframe */ + const Word16 *sig_in, /* i : postfilter i signal Qx */ + Word16 *sig_out, /* i/o: postfilter o signal Qx */ + Word16 *gain_prec, /* i/o: last value of gain for subframe Q14*/ Word16 L_subfr ) { Word32 L_acc, L_temp; @@ -1871,11 +1873,11 @@ void scale_st_fx( L_acc = L_deposit_l( 0 ); FOR( i = 0; i < L_subfr; i++ ) { - if ( sig_in[i] > 0 ) + IF( sig_in[i] > 0 ) { L_acc = L_mac0( L_acc, 1, sig_in[i] ); } - if ( sig_in[i] < 0 ) + IF( sig_in[i] < 0 ) { L_acc = L_msu0( L_acc, 1, sig_in[i] ); } @@ -1948,6 +1950,7 @@ void scale_st_fx( L_temp = L_shl( L_temp, 1 ); sig_out[i] = round_fx( L_temp ); #endif + move16(); } *gain_prec = gain; move16(); @@ -1963,26 +1966,26 @@ void scale_st_fx( *---------------------------------------------------------------------------*/ void blend_subfr2_fx( - Word16 *sigIn1, - Word16 *sigIn2, - Word16 *sigOut ) + Word16 *sigIn1, // Qx + Word16 *sigIn2, // Qx + Word16 *sigOut // Qx +) { - Word16 fac1 = 32768 - 512; - Word16 fac2 = 0 + 512; - Word16 step = 1024; + Word16 fac1 = 32768 - 512; // 1.Q15 - ( 1.Q15 / L_SUBFR ); + Word16 fac2 = 0 + 512; // 0.Q15 + ( 1.Q15 / L_SUBFR ); + Word16 step = 1024; // 1.Q15 / ( L_SUBFR / 2 ); Word16 i; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; -#endif move16(); +#endif move16(); move16(); move16(); FOR( i = 0; i < L_SUBFR / 2; i++ ) { #ifdef BASOP_NOGLOB - sigOut[i] = mac_ro( L_mult_o( fac1, sigIn1[i], &Overflow ), fac2, sigIn2[i], &Overflow ); - move16(); + sigOut[i] = mac_ro( L_mult_o( fac1, sigIn1[i], &Overflow ), fac2, sigIn2[i], &Overflow ); // Qx fac1 = sub_o( fac1, step, &Overflow ); fac2 = add_o( fac2, step, &Overflow ); #else @@ -1990,6 +1993,7 @@ void blend_subfr2_fx( fac1 = sub( fac1, step ); fac2 = add( fac2, step ); #endif + move16(); } return; diff --git a/lib_dec/dec_ppp_fx.c b/lib_dec/dec_ppp_fx.c index d37efa4c7..189ecc2b7 100644 --- a/lib_dec/dec_ppp_fx.c +++ b/lib_dec/dec_ppp_fx.c @@ -70,7 +70,7 @@ ivas_error decod_ppp_fx( /* call voiced decoder at this point */ FOR( k = 0; k < M; k++ ) { - p_Aq_curr_fx[k] = Aq_fx[add( k, ( 3 * ( M + 1 ) ) + 1 )]; + p_Aq_curr_fx[k] = Aq_fx[( k + ( 3 * ( M + 1 ) ) + 1 )]; move16(); /*Q12 */ } diff --git a/lib_dec/dec_prm_fx.c b/lib_dec/dec_prm_fx.c index 7b923ab72..194e6bba6 100644 --- a/lib_dec/dec_prm_fx.c +++ b/lib_dec/dec_prm_fx.c @@ -20,10 +20,10 @@ void getLPCparam_fx( Decoder_State *st, /* i/o: decoder memory state */ - Word16 param_lpc[], /* o : LTP parameters */ + Word16 param_lpc[], /* o : LTP parameters Q0 */ Decoder_State *st0, /* i : bitstream */ - const Word16 ch, /* i : channel */ - const Word16 sns_low_br_mode /* i : SNS low-bitrate mode */ + const Word16 ch, /* i : channel Q0 */ + const Word16 sns_low_br_mode /* i : SNS low-bitrate mode Q0 */ ) { IF( st->use_partial_copy == 0 ) @@ -59,9 +59,9 @@ void getLPCparam_fx( { test(); test(); - IF( EQ_32( st->sr_core, INT_FS_16k ) && EQ_16( st->coder_type, VOICED ) && EQ_16( st->core, ACELP_CORE ) ) + IF( EQ_32( st->sr_core, INT_FS_16k ) && EQ_16( st->coder_type, VOICED ) && ( st->core == ACELP_CORE ) ) { - assert( EQ_16( st->element_mode, EVS_MONO ) ); + assert( st->element_mode == EVS_MONO ); lsf_bctcvq_decprm( st0, param_lpc ); } ELSE @@ -82,21 +82,21 @@ void getLPCparam_fx( test(); IF( EQ_16( st->rf_frame_type, RF_TCXFD ) ) { - param_lpc[0] = 0; + param_lpc[0] = 0; // Q0 move16(); - param_lpc[1] = get_next_indice_fx( st0, lsf_numbits[0] ); /* VQ 1 */ + param_lpc[1] = get_next_indice_fx( st0, lsf_numbits[0] ); /* VQ 1 */ // Q0 move16(); - param_lpc[2] = get_next_indice_fx( st0, lsf_numbits[1] ); /* VQ 2 */ + param_lpc[2] = get_next_indice_fx( st0, lsf_numbits[1] ); /* VQ 2 */ // Q0 move16(); - param_lpc[3] = get_next_indice_fx( st0, lsf_numbits[2] ); /* VQ 3 */ + param_lpc[3] = get_next_indice_fx( st0, lsf_numbits[2] ); /* VQ 3 */ // Q0 move16(); } ELSE IF( GE_16( st->rf_frame_type, RF_ALLPRED ) && LE_16( st->rf_frame_type, RF_NELP ) ) { /* LSF indices */ - param_lpc[0] = get_next_indice_fx( st0, 8 ); /* VQ 1 */ + param_lpc[0] = get_next_indice_fx( st0, 8 ); /* VQ 1 */ // Q0 move16(); - param_lpc[1] = get_next_indice_fx( st0, 8 ); /* VQ 2 */ + param_lpc[1] = get_next_indice_fx( st0, 8 ); /* VQ 2 */ // Q0 move16(); } } @@ -106,7 +106,7 @@ void getLPCparam_fx( void dec_prm_hm_fx( Decoder_State *st, - Word16 *prm_hm, + Word16 *prm_hm, /* Q0 */ const Word16 L_frame ) { Word16 tmp; @@ -127,7 +127,7 @@ void dec_prm_hm_fx( move16(); /* Flag */ - prm_hm[0] = get_next_indice_fx( st, 1 ); + prm_hm[0] = get_next_indice_fx( st, 1 ); // Q0 move16(); IF( prm_hm[0] != 0 ) @@ -161,13 +161,13 @@ void getTCXparam_fx( Decoder_State *st, /* i/o: Decoder State handle */ Decoder_State *st0, /* i : bitstream */ CONTEXT_HM_CONFIG hm_cfg, /* i/o: HM config */ - Word16 param[], /* o : decoded parameters */ - const Word16 bits_common, /* i : number of common bits */ - const Word16 start_bit_pos, /* i : position of the start bit */ - const Word16 *no_param_tns, /* i : number of TNS parameters per subframe */ - Word16 p_param[2], /* o : pointer to parameters for next round of bs reading*/ - Word16 nTnsBitsTCX10[2], - const Word16 pre_past_flag ) + Word16 param[], /* o : decoded parameters Q0 */ + const Word16 bits_common, /* i : number of common bits Q0 */ + const Word16 start_bit_pos, /* i : position of the start bit Q0 */ + const Word16 *no_param_tns, /* i : number of TNS parameters per subframe Q0 */ + Word16 p_param[2], /* o : pointer to parameters for next round of bs reading Q0 */ + Word16 nTnsBitsTCX10[2], /*Q0*/ + const Word16 pre_past_flag /*Q0*/ ) { Word16 ix, j, k, core, last_core, nSubframes; Word16 lg, lgFB, flag_ctx_hm, hm_size; @@ -243,7 +243,7 @@ void getTCXparam_fx( IGFDecReadData( st->hIGFDec, st0, IGF_GRID_LB_SHORT, 1 - k ); IGFDecStoreTCX10SubFrameData( st->hIGFDec, k ); - nbits_igf = add( nbits_igf, sub( st0->next_bit_pos, ix ) ); + nbits_igf = add( nbits_igf, sub( st0->next_bit_pos, ix ) ); // Q0 } } /* loop over subframes */ @@ -251,35 +251,35 @@ void getTCXparam_fx( { flag_ctx_hm = 0; move16(); - prm = param + imult1616( k, DEC_NPRM_DIV ); + prm = param + k * DEC_NPRM_DIV; j = 0; move16(); - nbits_tcx = sub( st0->next_bit_pos, start_bit_pos ); + nbits_tcx = sub( st0->next_bit_pos, start_bit_pos ); // Q0 test(); test(); - IF( pre_part && st->enablePlcWaveadjust && EQ_16( k, ( nSubframes - 1 ) ) ) + IF( pre_part && st->enablePlcWaveadjust && EQ_16( k, sub( nSubframes, 1 ) ) ) { - st->tonality_flag = get_next_indice_fx( st0, 1 ); + st->tonality_flag = get_next_indice_fx( st0, 1 ); // Q0 move16(); } IF( post_part ) { /* TCX Gain */ - prm[j] = get_next_indice_fx( st0, NBITS_TCX_GAIN ); - j = add( j, 1 ); + prm[j] = get_next_indice_fx( st0, NBITS_TCX_GAIN ); // Q0 + j = add( j, 1 ); // Q0 move16(); /* TCX Noise Filling = NBITS_NOISE_FILL_LEVEL bits */ - prm[j] = get_next_indice_fx( st0, NBITS_NOISE_FILL_LEVEL ); - j = add( j, 1 ); + prm[j] = get_next_indice_fx( st0, NBITS_NOISE_FILL_LEVEL ); // Q0 + j = add( j, 1 ); // Q0 move16(); } ELSE { - j = add( j, 1 + NOISE_FILL_RANGES ); + j = add( j, 1 + NOISE_FILL_RANGES ); // Q0 } /* LTP data */ @@ -289,24 +289,24 @@ void getTCXparam_fx( test(); IF( ( k == 0 ) && ( hTcxLtpDec->tcxltp || GT_32( st->sr_core, 25600 ) ) ) /* PLC pitch info for HB */ { - prm[j] = get_next_indice_fx( st0, 1 ); + prm[j] = get_next_indice_fx( st0, 1 ); // Q0 move16(); IF( prm[j] ) { - prm[add( j, 1 )] = get_next_indice_fx( st0, 9 ); + prm[add( j, 1 )] = get_next_indice_fx( st0, 9 ); // Q0 move16(); - prm[add( j, 2 )] = get_next_indice_fx( st0, 2 ); + prm[add( j, 2 )] = get_next_indice_fx( st0, 2 ); // Q0 move16(); - tcxltp_prm_0 = prm[j]; + tcxltp_prm_0 = prm[j]; // Q0 move16(); - tcxltp_prm_1 = prm[j + 1]; + tcxltp_prm_1 = prm[j + 1]; // Q0 move16(); - tcxltp_prm_2 = prm[j + 2]; + tcxltp_prm_2 = prm[j + 2]; // Q0 move16(); } - st->BER_detect = st->BER_detect | tcx_ltp_decode_params( &prm[j], &( hTcxLtpDec->tcxltp_pitch_int ), &( hTcxLtpDec->tcxltp_pitch_fr ), &( hTcxLtpDec->tcxltp_gain ), st->pit_min, st->pit_fr1, st->pit_fr2, st->pit_max, st->pit_res_max ); + st->BER_detect = s_or( st->BER_detect, tcx_ltp_decode_params( &prm[j], &( hTcxLtpDec->tcxltp_pitch_int ), &( hTcxLtpDec->tcxltp_pitch_fr ), &( hTcxLtpDec->tcxltp_gain ), st->pit_min, st->pit_fr1, st->pit_fr2, st->pit_max, st->pit_res_max ) ); // Q0 move16(); - hTcxDec->tcxltp_last_gain_unmodified = hTcxLtpDec->tcxltp_gain; + hTcxDec->tcxltp_last_gain_unmodified = hTcxLtpDec->tcxltp_gain; // Q15 move16(); test(); @@ -316,45 +316,45 @@ void getTCXparam_fx( // To be done at the end Word32 tmp32 = L_shl( L_mult0( st->L_frame, st->pit_res_max ), 1 + kLtpHmFractionalResolution + 1 ); Word16 tmp1 = add( imult1616( hTcxLtpDec->tcxltp_pitch_int, st->pit_res_max ), hTcxLtpDec->tcxltp_pitch_fr ); - hTcxDec->tcx_hm_LtpPitchLag = div_l( tmp32, tmp1 ); + hTcxDec->tcx_hm_LtpPitchLag = div_l( tmp32, tmp1 ); // Q15 move16(); } ELSE { - hTcxDec->tcx_hm_LtpPitchLag = -1; + hTcxDec->tcx_hm_LtpPitchLag = -1; // Q15 move16(); } - j = add( j, 3 ); + j = add( j, 3 ); // Q0 } ELSE { - prm[j] = tcxltp_prm_0; - j = add( j, 1 ); + prm[j] = tcxltp_prm_0; // Q0 + j = add( j, 1 ); // Q0 move16(); - prm[j] = tcxltp_prm_1; - j = add( j, 1 ); + prm[j] = tcxltp_prm_1; // Q0 + j = add( j, 1 ); // Q0 move16(); - prm[j] = tcxltp_prm_2; - j = add( j, 1 ); + prm[j] = tcxltp_prm_2; // Q0 + j = add( j, 1 ); // Q0 move16(); } } /* TCX spectral data */ - lg = shr( st->L_frame, sub( nSubframes, 1 ) ); - lgFB = shr( st->hTcxCfg->tcx_coded_lines, sub( nSubframes, 1 ) ); + lg = shr( st->L_frame, sub( nSubframes, 1 ) ); // Q0 + lgFB = shr( st->hTcxCfg->tcx_coded_lines, sub( nSubframes, 1 ) ); // Q0 test(); test(); IF( post_part && ( k == 0 ) && EQ_16( st->last_core_from_bs, ACELP_CORE ) ) { /* ACE->TCX transition */ - lg = add( lg, st->hTcxCfg->tcx_offset ); - lgFB = add( lgFB, shr( lgFB, sub( 3, nSubframes ) ) ); + lg = add( lg, st->hTcxCfg->tcx_offset ); // Q0 + lgFB = add( lgFB, shr( lgFB, sub( 3, nSubframes ) ) ); // Q0 - if ( st->hTcxCfg->lfacNext < 0 ) + IF( st->hTcxCfg->lfacNext < 0 ) { - lg = sub( lg, st->hTcxCfg->lfacNext ); + lg = sub( lg, st->hTcxCfg->lfacNext ); // Q0 } } @@ -384,33 +384,41 @@ void getTCXparam_fx( move16(); IF( no_param_tns ) { - ix = get_next_indice_fx( st0, 1 ); /* common_tns_data[] for subframe k */ + ix = get_next_indice_fx( st0, 1 ); /* common_tns_data[] for subframe k */ // Q0 } IF( ix ) { - prm[j] = imult1616( no_param_tns[k], -1 ); /* - signals common TNS and its size */ + prm[j] = imult1616( no_param_tns[k], -1 ); /* - signals common TNS and its size */ // Q0 move16(); - nTnsParams = no_param_tns[k]; + nTnsParams = no_param_tns[k]; // Q0 move16(); } ELSE { ReadTnsData_ivas_fx( st->hTcxCfg->pCurrentTnsConfig, st0, &nTnsBits, prm + j, &nTnsParams ); } - hTcxDec->tnsActive[k] = 0; + hTcxDec->tnsActive[k] = 0; // Q0 move16(); if ( prm[j] != 0 ) { - hTcxDec->tnsActive[k] = nTnsParams; + hTcxDec->tnsActive[k] = nTnsParams; // Q0 move16(); } - if ( nTnsBitsTCX10 != NULL ) + IF( nTnsBitsTCX10 != NULL ) { - nTnsBitsTCX10[k] = add( nTnsBits, ( no_param_tns ? 1 : 0 ) ); - move16(); + IF( no_param_tns ) + { + nTnsBitsTCX10[k] = add( nTnsBits, 1 ); // Q0 + move16(); + } + ELSE + { + nTnsBitsTCX10[k] = add( nTnsBits, 0 ); // Q0 + move16(); + } } - j = add( j, nTnsParams ); + j = add( j, nTnsParams ); // Q0 } IF( post_part ) @@ -418,46 +426,46 @@ void getTCXparam_fx( IF( EQ_16( core, TCX_20_CORE ) ) { // Q-factor of TcxBandwidth is 15 : derived from getTcxBandwidth function - hm_size = mult( st->TcxBandwidth, shl( lg, 1 ) ); + hm_size = mult( st->TcxBandwidth, shl( lg, 1 ) ); // Q0 test(); - IF( hTcxDec->tcx_lpc_shaped_ari && NE_16( st->last_core_from_bs, ACELP_CORE ) ) + IF( hTcxDec->tcx_lpc_shaped_ari && ( st->last_core_from_bs != ACELP_CORE ) ) { dec_prm_hm_fx( st0, &prm[j], hm_size ); } - nbits_tcx = sub( st->bits_frame_core, sub( st0->next_bit_pos, start_bit_pos ) ); + nbits_tcx = sub( st->bits_frame_core, sub( st0->next_bit_pos, start_bit_pos ) ); // Q0 } ELSE { - hm_size = mult( st->TcxBandwidth, shl( lgFB, 1 ) ); - nbits_tcx = sub( shr( sub( add( sub( sub( st->bits_frame_core, bits_common ), nbits_igf ), 1 ), k ), 1 ), sub( sub( st0->next_bit_pos, start_bit_pos ), nbits_tcx ) ); + hm_size = mult( st->TcxBandwidth, shl( lgFB, 1 ) ); // Q0 + nbits_tcx = sub( shr( sub( add( sub( sub( st->bits_frame_core, bits_common ), nbits_igf ), 1 ), k ), 1 ), sub( sub( st0->next_bit_pos, start_bit_pos ), nbits_tcx ) ); // Q0 } /*Context HM flag*/ test(); test(); - IF( st->hTcxCfg->ctx_hm && !( EQ_16( st->last_core_from_bs, ACELP_CORE ) && ( k == 0 ) ) ) + IF( st->hTcxCfg->ctx_hm && !( ( st->last_core_from_bs == ACELP_CORE ) && ( k == 0 ) ) ) { - useHarmonicModel = get_next_indice_fx( st0, 1 ); - prm[j] = useHarmonicModel; + useHarmonicModel = get_next_indice_fx( st0, 1 ); // Q0 + prm[j] = useHarmonicModel; // Q0 move16(); - nbits_tcx = sub( nbits_tcx, 1 ); + nbits_tcx = sub( nbits_tcx, 1 ); // Q0 IF( useHarmonicModel ) { ix = DecodeIndex_fx( st0, (Word16) GE_16( hm_size, 256 ), prm + add( j, 1 ) ); - flag_ctx_hm = 1; + flag_ctx_hm = 1; // Q0 move16(); PeriodicityIndex = *( prm + add( j, 1 ) ); - IF( EQ_16( st->element_mode, EVS_MONO ) ) + IF( st->element_mode == EVS_MONO ) { ConfigureContextHm( lgFB, nbits_tcx, PeriodicityIndex, hTcxDec->tcx_hm_LtpPitchLag, &hm_cfg ); } - nbits_tcx = sub( nbits_tcx, ix ); + nbits_tcx = sub( nbits_tcx, ix ); // Q0 } } } - j = add( j, NPRM_CTX_HM ); + j = add( j, NPRM_CTX_HM ); // Q0 /* read IGF payload */ test(); @@ -465,31 +473,39 @@ void getTCXparam_fx( { IF( st->igf ) { - ix = st->next_bit_pos; + ix = st->next_bit_pos; // Q0 move16(); - IGFDecReadLevel( st->hIGFDec, st0, ( EQ_16( st->last_core_from_bs, ACELP_CORE ) ) ? IGF_GRID_LB_TRAN : IGF_GRID_LB_NORM, 1 ); - IGFDecReadData( st->hIGFDec, st0, ( EQ_16( st->last_core_from_bs, ACELP_CORE ) ) ? IGF_GRID_LB_TRAN : IGF_GRID_LB_NORM, 1 ); + IF( st->last_core_from_bs == ACELP_CORE ) + { + IGFDecReadLevel( st->hIGFDec, st0, IGF_GRID_LB_TRAN, 1 ); + IGFDecReadData( st->hIGFDec, st0, IGF_GRID_LB_TRAN, 1 ); + } + ELSE + { + IGFDecReadLevel( st->hIGFDec, st0, IGF_GRID_LB_NORM, 1 ); + IGFDecReadData( st->hIGFDec, st0, IGF_GRID_LB_NORM, 1 ); + } - nbits_tcx = sub( nbits_tcx, sub( st0->next_bit_pos, ix ) ); + nbits_tcx = sub( nbits_tcx, sub( st0->next_bit_pos, ix ) ); // Q0 } - nbits_tcx = sub( st->bits_frame_core, sub( st0->next_bit_pos, start_bit_pos ) ); + nbits_tcx = sub( st->bits_frame_core, sub( st0->next_bit_pos, start_bit_pos ) ); // Q0 } ELSE IF( p_param != NULL ) { - p_param[k] = j; + p_param[k] = j; // Q0 move16(); } } ELSE { - j = p_param[k]; + j = p_param[k]; // Q0 move16(); - nbits_tcx = st->bits_frame_channel; + nbits_tcx = st->bits_frame_channel; // Q0 move16(); if ( EQ_16( st->core, TCX_10_CORE ) ) { - nbits_tcx = sub( nTnsBitsTCX10[k], NBITS_TCX_GAIN + NOISE_FILL_RANGES * NBITS_NOISE_FILL_LEVEL ); + nbits_tcx = sub( nTnsBitsTCX10[k], NBITS_TCX_GAIN + NOISE_FILL_RANGES * NBITS_NOISE_FILL_LEVEL ); // Q0 } } @@ -498,36 +514,52 @@ void getTCXparam_fx( test(); IF( hTcxDec->tcx_lpc_shaped_ari && EQ_16( core, TCX_20_CORE ) ) { - prm[j] = nbits_tcx; /* store length of buffer */ - j = add( j, 1 ); + prm[j] = nbits_tcx; /* store length of buffer */ // Q0 + j = add( j, 1 ); // Q0 move16(); prms = &prm[j]; FOR( ix = 0; ix < nbits_tcx; ix++ ) { - prms[ix] = get_next_indice_1_fx( st0 ); + prms[ix] = get_next_indice_1_fx( st0 ); // Q0 } FOR( ix = 0; ix < 32; ix++ ) { - prms[add( ix, nbits_tcx )] = 1; + prms[ix + nbits_tcx] = 1; // Q0 + move16(); } - move16(); - j = add( j, nbits_tcx ); + j = add( j, nbits_tcx ); // Q0 } ELSE { - IF( GT_16( st->element_mode, EVS_MONO ) ) + IF( st->element_mode > EVS_MONO ) { IF( useHarmonicModel ) { ConfigureContextHm( lgFB, nbits_tcx, PeriodicityIndex, hTcxDec->tcx_hm_LtpPitchLag, &hm_cfg ); } - hTcxDec->resQBits[k] = RCcontextMapping_decode2_no_mem_s17_LCS_fx( st0, prm + j, lgFB, nbits_tcx, imult1616( NPRM_RESQ, st->hTcxCfg->resq ), flag_ctx_hm ? &hm_cfg : NULL ); - move16(); + IF( flag_ctx_hm ) + { + hTcxDec->resQBits[k] = RCcontextMapping_decode2_no_mem_s17_LCS_fx( st0, prm + j, lgFB, nbits_tcx, imult1616( NPRM_RESQ, st->hTcxCfg->resq ), &hm_cfg ); // Q0 + move16(); + } + ELSE + { + hTcxDec->resQBits[k] = RCcontextMapping_decode2_no_mem_s17_LCS_fx( st0, prm + j, lgFB, nbits_tcx, imult1616( NPRM_RESQ, st->hTcxCfg->resq ), NULL ); // Q0 + move16(); + } } ELSE { - hTcxDec->resQBits[k] = ACcontextMapping_decode2_no_mem_s17_LC( st0, prm + j, lgFB, nbits_tcx, imult1616( NPRM_RESQ, st->hTcxCfg->resq ), flag_ctx_hm ? &hm_cfg : NULL ); - move16(); + IF( flag_ctx_hm ) + { + hTcxDec->resQBits[k] = ACcontextMapping_decode2_no_mem_s17_LC( st0, prm + j, lgFB, nbits_tcx, imult1616( NPRM_RESQ, st->hTcxCfg->resq ), &hm_cfg ); // Q0 + move16(); + } + ELSE + { + hTcxDec->resQBits[k] = ACcontextMapping_decode2_no_mem_s17_LC( st0, prm + j, lgFB, nbits_tcx, imult1616( NPRM_RESQ, st->hTcxCfg->resq ), NULL ); // Q0 + move16(); + } } } } @@ -545,9 +577,9 @@ void getTCXparam_fx( *-----------------------------------------------------------------*/ void dec_prm_fx( Word16 *coder_type, - Word16 param[], /* (o) : decoded parameters */ - Word16 param_lpc[], /* (o) : LPC parameters */ - Word16 *total_nbbits, /* i/o : number of bits / decoded bits */ + Word16 param[], /* (o) : decoded parameters Q0 */ + Word16 param_lpc[], /* (o) : LPC parameters Q0 */ + Word16 *total_nbbits, /* i/o : number of bits / decoded bits Q0 */ Decoder_State *st, Word16 L_frame, Word16 *bitsRead ) @@ -613,17 +645,17 @@ void dec_prm_fx( IF( EQ_16( st->rf_flag, 1 ) ) { /*Inherent adjustment to accommodate the compact packing used in the RF mode*/ - start_bit_pos = sub( st->next_bit_pos, 2 ); + start_bit_pos = sub( st->next_bit_pos, 2 ); // Q0 } ELSE { - start_bit_pos = st->next_bit_pos; + start_bit_pos = st->next_bit_pos; // Q0 move16(); } } /* Framing parameters */ - nb_subfr = st->nb_subfr; + nb_subfr = st->nb_subfr; // Q0 move16(); /* Initialize pointers */ @@ -646,12 +678,12 @@ void dec_prm_fx( /* Modes (ACE_GC, ACE_UC, TCX20, TCX10...) */ IF( st->tcxonly ) { - st->core = add( get_next_indice_fx( st, 1 ), 1 ); + st->core = add( get_next_indice_fx( st, 1 ), 1 ); // Q0 move16(); - ind = get_next_indice_fx( st, 2 ); + ind = get_next_indice_fx( st, 2 ); // Q0 st->clas_dec = ONSET; move16(); - if ( ind == 0 ) + IF( ind == 0 ) { st->clas_dec = UNVOICED_CLAS; move16(); @@ -683,7 +715,7 @@ void dec_prm_fx( /* 2 bits instead of 3 as TCX is already signaled */ st->core = TCX_20_CORE; move16(); - st->hTcxCfg->coder_type = get_next_indice_fx( st, 2 ); + st->hTcxCfg->coder_type = get_next_indice_fx( st, 2 ); // Q0 move16(); *coder_type = st->hTcxCfg->coder_type; move16(); @@ -694,7 +726,7 @@ void dec_prm_fx( { IF( get_next_indice_1_fx( st ) != 0 ) /* TCX */ { - tmp = get_next_indice_fx( st, 3 ); + tmp = get_next_indice_fx( st, 3 ); // Q0 assert( !( tmp & 4 ) || !"HQ_CORE encountered in dec_prm_fx" ); st->core = TCX_20_CORE; move16(); @@ -707,7 +739,7 @@ void dec_prm_fx( { st->core = ACELP_CORE; move16(); - *coder_type = get_next_indice_fx( st, 2 ); + *coder_type = get_next_indice_fx( st, 2 ); // Q0 move16(); } } @@ -736,7 +768,7 @@ void dec_prm_fx( { st->core = ACELP_CORE; move16(); - *coder_type = get_next_indice_fx( st, 3 ); + *coder_type = get_next_indice_fx( st, 3 ); // Q0 move16(); IF( GE_16( *coder_type, ACELP_MODE_MAX ) ) { @@ -752,22 +784,22 @@ void dec_prm_fx( } test(); - if ( ( st->igf != 0 ) && EQ_16( st->core, ACELP_CORE ) ) + IF( ( st->igf != 0 ) && ( st->core == ACELP_CORE ) ) { - st->bits_frame_core = sub( st->bits_frame_core, get_tbe_bits_fx( st->total_brate, st->bwidth, st->rf_flag ) ); + st->bits_frame_core = sub( st->bits_frame_core, get_tbe_bits_fx( st->total_brate, st->bwidth, st->rf_flag ) ); // Q0 move16(); } - if ( EQ_16( st->rf_flag, 1 ) ) + IF( EQ_16( st->rf_flag, 1 ) ) { - st->bits_frame_core = sub( st->bits_frame_core, add( st->rf_target_bits, 1 ) ); /* +1 as flag-bit not considered in rf_target_bits */ + st->bits_frame_core = sub( st->bits_frame_core, add( st->rf_target_bits, 1 ) ); /* +1 as flag-bit not considered in rf_target_bits */ // Q0 move16(); } /* Inactive frame detection on non-DTX mode */ st->VAD = 1; move16(); - if ( EQ_16( *coder_type, INACTIVE ) ) + if ( *coder_type == INACTIVE ) { st->VAD = 0; move16(); @@ -778,7 +810,7 @@ void dec_prm_fx( st->core_ext_mode = *coder_type; move16(); - if ( EQ_16( *coder_type, INACTIVE ) ) + if ( *coder_type == INACTIVE ) { st->core_ext_mode = UNVOICED; move16(); @@ -789,7 +821,7 @@ void dec_prm_fx( move16(); test(); test(); - IF( ( NE_16( st->core, ACELP_CORE ) || st->hTcxCfg->lfacNext > 0 ) && st->use_partial_copy == 0 ) + IF( ( ( st->core != ACELP_CORE ) || st->hTcxCfg->lfacNext > 0 ) && st->use_partial_copy == 0 ) { st->last_core_from_bs = get_next_indice_fx( st, 1 ); move16(); @@ -812,8 +844,8 @@ void dec_prm_fx( IF( EQ_16( st->core, TCX_10_CORE ) ) { st->last_core = TCX_20_CORE; - st->last_core_from_bs = TCX_20_CORE; move16(); + st->last_core_from_bs = TCX_20_CORE; move16(); } } @@ -828,14 +860,14 @@ void dec_prm_fx( Mpy_32_16_ss( st->total_brate, 5243, &L_tmp, &lsb ); /* 5243 is 1/50 in Q18. (0+18-15=3) */ num_bits = extract_l( L_shr( L_tmp, 3 ) ); /* Q0 */ - get_next_indice_tmp_fx( st, sub( sub( sub( add( start_bit_pos, num_bits ), st->rf_target_bits ), 3 ), st->next_bit_pos ) ); + get_next_indice_tmp_fx( st, sub( sub( sub( add( start_bit_pos, num_bits ), st->rf_target_bits ), 3 ), st->next_bit_pos ) ); // Q0 } IF( st->use_partial_copy == 0 ) { /* Set the last overlap mode based on the previous and current frame type and coded overlap mode */ test(); - IF( ( EQ_16( st->last_core, ACELP_CORE ) ) || ( EQ_16( st->last_core, AMR_WB_CORE ) ) ) + IF( ( st->last_core == ACELP_CORE ) || ( EQ_16( st->last_core, AMR_WB_CORE ) ) ) { st->hTcxCfg->tcx_last_overlap_mode = TRANSITION_OVERLAP; move16(); @@ -853,7 +885,7 @@ void dec_prm_fx( st->hTcxCfg->tcx_last_overlap_mode = st->hTcxCfg->tcx_curr_overlap_mode; move16(); test(); - if ( ( NE_16( st->core, TCX_10_CORE ) ) && ( EQ_16( st->hTcxCfg->tcx_curr_overlap_mode, FULL_OVERLAP ) ) ) + if ( ( NE_16( st->core, TCX_10_CORE ) ) && ( st->hTcxCfg->tcx_curr_overlap_mode == FULL_OVERLAP ) ) { st->hTcxCfg->tcx_last_overlap_mode = ALDO_WINDOW; move16(); @@ -864,12 +896,12 @@ void dec_prm_fx( st->hTcxCfg->tcx_curr_overlap_mode = ALDO_WINDOW; move16(); - IF( NE_16( st->core, ACELP_CORE ) ) + IF( st->core != ACELP_CORE ) { tmp = 0; move16(); /* if current TCX mode is not 0 (full overlap), read another bit */ - if ( get_next_indice_fx( st, 1 ) ) + IF( get_next_indice_fx( st, 1 ) ) { tmp = add( 2, get_next_indice_fx( st, 1 ) ); } @@ -880,7 +912,7 @@ void dec_prm_fx( test(); test(); test(); - if ( ( EQ_16( st->core, TCX_20_CORE ) ) && ( tmp == 0 ) && ( NE_16( st->last_core, ACELP_CORE ) ) && ( NE_16( st->last_core, AMR_WB_CORE ) ) ) + if ( ( EQ_16( st->core, TCX_20_CORE ) ) && ( tmp == 0 ) && ( st->last_core != ACELP_CORE ) && ( NE_16( st->last_core, AMR_WB_CORE ) ) ) { st->hTcxCfg->tcx_curr_overlap_mode = ALDO_WINDOW; move16(); @@ -897,28 +929,28 @@ void dec_prm_fx( search_range = 8; move16(); - st->flagGuidedAcelp = get_next_indice_fx( st, 1 ); + st->flagGuidedAcelp = get_next_indice_fx( st, 1 ); // Q0 move16(); pitchDiff = 0; move16(); IF( st->flagGuidedAcelp ) { - pitchDiff = get_next_indice_fx( st, bits_per_subfr ); + pitchDiff = get_next_indice_fx( st, bits_per_subfr ); // Q0 move16(); - st->guidedT0 = sub( pitchDiff, search_range ); + st->guidedT0 = sub( pitchDiff, search_range ); // Q0 move16(); } test(); if ( ( pitchDiff == 0 ) && st->flagGuidedAcelp ) { - st->flagGuidedAcelp = 0; + st->flagGuidedAcelp = 0; // Q0 move16(); } } ELSE { - st->flagGuidedAcelp = 0; + st->flagGuidedAcelp = 0; // Q0 move16(); } @@ -926,9 +958,9 @@ void dec_prm_fx( { move16(); st->dec_glr_idx = -1; - if ( EQ_16( st->core, ACELP_CORE ) ) + IF( st->core == ACELP_CORE ) { - st->dec_glr_idx = get_next_indice_fx( st, G_LPC_RECOVERY_BITS ); + st->dec_glr_idx = get_next_indice_fx( st, G_LPC_RECOVERY_BITS ); // Q0 move16(); } } @@ -962,7 +994,7 @@ void dec_prm_fx( /* Decode LPC parameters */ test(); - IF( hTcxDec->enableTcxLpc && NE_16( st->core, ACELP_CORE ) ) + IF( hTcxDec->enableTcxLpc && ( st->core != ACELP_CORE ) ) { Word16 tcx_lpc_cdk; tcx_lpc_cdk = tcxlpc_get_cdk( *coder_type ); @@ -984,7 +1016,7 @@ void dec_prm_fx( { test(); test(); - IF( EQ_32( st->sr_core, 16000 ) && EQ_16( *coder_type, VOICED ) && EQ_16( st->core, ACELP_CORE ) ) + IF( EQ_32( st->sr_core, 16000 ) && EQ_16( *coder_type, VOICED ) && ( st->core == ACELP_CORE ) ) { lsf_bctcvq_decprm( st, param_lpc ); } @@ -1007,26 +1039,26 @@ void dec_prm_fx( test(); IF( EQ_16( st->rf_frame_type, RF_TCXFD ) ) { - param_lpc[0] = 0; + param_lpc[0] = 0; // Q0 move16(); - param_lpc[1] = get_next_indice_fx( st, lsf_numbits[0] ); /* VQ 1 */ + param_lpc[1] = get_next_indice_fx( st, lsf_numbits[0] ); /* VQ 1 */ // Q0 move16(); - param_lpc[2] = get_next_indice_fx( st, lsf_numbits[1] ); /* VQ 2 */ + param_lpc[2] = get_next_indice_fx( st, lsf_numbits[1] ); /* VQ 2 */ // Q0 move16(); - param_lpc[3] = get_next_indice_fx( st, lsf_numbits[2] ); /* VQ 3 */ + param_lpc[3] = get_next_indice_fx( st, lsf_numbits[2] ); /* VQ 3 */ // Q0 move16(); } ELSE IF( GE_16( st->rf_frame_type, RF_ALLPRED ) && LE_16( st->rf_frame_type, RF_NELP ) ) { /* LSF indices */ - param_lpc[0] = get_next_indice_fx( st, 8 ); /* VQ 1 */ + param_lpc[0] = get_next_indice_fx( st, 8 ); /* VQ 1 */ // Q0 move16(); - param_lpc[1] = get_next_indice_fx( st, 8 ); /* VQ 2 */ + param_lpc[1] = get_next_indice_fx( st, 8 ); /* VQ 2 */ // Q0 move16(); } } - st->bits_common = sub( st->next_bit_pos, start_bit_pos ); + st->bits_common = sub( st->next_bit_pos, start_bit_pos ); // Q0 move16(); @@ -1035,7 +1067,7 @@ void dec_prm_fx( *--------------------------------------------------------------------------------*/ test(); test(); - IF( EQ_16( st->core, ACELP_CORE ) && ( st->use_partial_copy == 0 ) ) + IF( ( st->core == ACELP_CORE ) && ( st->use_partial_copy == 0 ) ) { /* Target Bits */ acelp_target_bits = sub( st->bits_frame_core, st->bits_common ); @@ -1053,23 +1085,23 @@ void dec_prm_fx( } /* Adaptive BPF (2 bits)*/ - n = ACELP_BPF_BITS[st->acelp_cfg.bpf_mode]; + n = ACELP_BPF_BITS[st->acelp_cfg.bpf_mode]; // Q0 move16(); - st->bpf_gain_param = shl( st->acelp_cfg.bpf_mode, 1 ); - if ( n != 0 ) + st->bpf_gain_param = shl( st->acelp_cfg.bpf_mode, 1 ); // Q0 + IF( n != 0 ) { - st->bpf_gain_param = get_next_indice_fx( st, n ); + st->bpf_gain_param = get_next_indice_fx( st, n ); // Q0 move16(); } /* Mean energy (2 or 3 bits) */ - n = ACELP_NRG_BITS[st->acelp_cfg.nrg_mode]; + n = ACELP_NRG_BITS[st->acelp_cfg.nrg_mode]; // Q0 move16(); - if ( n != 0 ) + IF( n != 0 ) { - prm[j] = get_next_indice_fx( st, n ); - j = add( j, 1 ); + prm[j] = get_next_indice_fx( st, n ); // Q0 + j = add( j, 1 ); // Q0 move16(); } @@ -1077,63 +1109,63 @@ void dec_prm_fx( FOR( sfr = 0; sfr < nb_subfr; sfr++ ) { /* Pitch lag (4, 5, 6, 8 or 9 bits) */ - n = ACELP_LTP_BITS_SFR[st->acelp_cfg.ltp_mode][sfr]; + n = ACELP_LTP_BITS_SFR[st->acelp_cfg.ltp_mode][sfr]; // Q0 move16(); IF( n != 0 ) { - prm[j] = get_next_indice_fx( st, n ); - j = add( j, 1 ); + prm[j] = get_next_indice_fx( st, n ); // Q0 + j = add( j, 1 ); // Q0 move16(); } /* Adaptive codebook filtering (1 bit) */ IF( EQ_16( st->acelp_cfg.ltf_mode, 2 ) ) { - prm[j] = get_next_indice_fx( st, 1 ); - j = add( j, 1 ); + prm[j] = get_next_indice_fx( st, 1 ); // Q0 + j = add( j, 1 ); // Q0 move16(); } /* Innovative codebook */ { /* Decode pulse positions. */ - j_old = j; + j_old = j; // Q0 move16(); - wordcnt = shr( ACELP_FIXED_CDK_BITS( st->acelp_cfg.fixed_cdk_index[sfr] ), 4 ); - bitcnt = s_and( ACELP_FIXED_CDK_BITS( st->acelp_cfg.fixed_cdk_index[sfr] ), 0xF ); + wordcnt = shr( ACELP_FIXED_CDK_BITS( st->acelp_cfg.fixed_cdk_index[sfr] ), 4 ); // Q0 + bitcnt = s_and( ACELP_FIXED_CDK_BITS( st->acelp_cfg.fixed_cdk_index[sfr] ), 0xF ); // Q0 /* sanity check for testing - not instrumented */ test(); IF( GE_16( st->acelp_cfg.fixed_cdk_index[sfr], ACELP_FIXED_CDK_NB ) || ( st->acelp_cfg.fixed_cdk_index[sfr] < 0 ) ) { - st->acelp_cfg.fixed_cdk_index[sfr] = 0; + st->acelp_cfg.fixed_cdk_index[sfr] = 0; // Q0 move16(); - st->BER_detect = 1; + st->BER_detect = 1; // Q0 move16(); } FOR( ix = 0; ix < wordcnt; ix++ ) { - prm[j] = (Word16) get_next_indice_fx( st, 16 ); - j = add( j, 1 ); + prm[j] = (Word16) get_next_indice_fx( st, 16 ); // Q0 + j = add( j, 1 ); // Q0 move16(); } - if ( bitcnt ) + IF( bitcnt ) { - prm[j] = get_next_indice_fx( st, bitcnt ); + prm[j] = get_next_indice_fx( st, bitcnt ); // Q0 move16(); } - j = add( j_old, 8 ); + j = add( j_old, 8 ); // Q0 } /* Gains (5b, 6b or 7b / subfr) */ - n = ACELP_GAINS_BITS[st->acelp_cfg.gains_mode[sfr]]; + n = ACELP_GAINS_BITS[st->acelp_cfg.gains_mode[sfr]]; // Q0 move16(); - prm[j] = get_next_indice_fx( st, n ); - j = add( j, 1 ); + prm[j] = get_next_indice_fx( st, n ); // Q0 + j = add( j, 1 ); // Q0 move16(); } /*end of subfr loop*/ } @@ -1157,43 +1189,44 @@ void dec_prm_fx( IF( EQ_16( st->rf_frame_type, RF_NELP ) ) { /* NELP gain indices */ - st->rf_indx_nelp_iG1 = get_next_indice_fx( st, 5 ); - st->rf_indx_nelp_iG2[0] = get_next_indice_fx( st, 6 ); + st->rf_indx_nelp_iG1 = get_next_indice_fx( st, 5 ); // Q0 move16(); - st->rf_indx_nelp_iG2[1] = get_next_indice_fx( st, 6 ); + st->rf_indx_nelp_iG2[0] = get_next_indice_fx( st, 6 ); // Q0 + move16(); + st->rf_indx_nelp_iG2[1] = get_next_indice_fx( st, 6 ); // Q0 move16(); /* NELP filter selection index */ - st->rf_indx_nelp_fid = get_next_indice_fx( st, 2 ); + st->rf_indx_nelp_fid = get_next_indice_fx( st, 2 ); // Q0 move16(); /* tbe gainFr */ - st->rf_indx_tbeGainFr = get_next_indice_fx( st, 5 ); + st->rf_indx_tbeGainFr = get_next_indice_fx( st, 5 ); // Q0 move16(); } ELSE { /* rf_frame_type ALL_PRED: 4, NO_PRED: 5, GEN_PRED: 6*/ /* ES pred */ - prm[j] = get_next_indice_fx( st, 3 ); + prm[j] = get_next_indice_fx( st, 3 ); // Q0 move16(); - j = add( j, 1 ); + j = add( j, 1 ); // Q0 - ltp_mode = ACELP_LTP_MODE[1][1][st->rf_frame_type]; + ltp_mode = ACELP_LTP_MODE[1][1][st->rf_frame_type]; // Q0 move16(); - gains_mode = ACELP_GAINS_MODE[1][1][st->rf_frame_type]; + gains_mode = ACELP_GAINS_MODE[1][1][st->rf_frame_type]; // Q0 move16(); /* Subframe parameters */ FOR( sfr = 0; sfr < nb_subfr; sfr++ ) { /* Pitch lag (5, or 8 bits) */ - n = ACELP_LTP_BITS_SFR[ltp_mode][sfr]; + n = ACELP_LTP_BITS_SFR[ltp_mode][sfr]; // Q0 move16(); IF( n != 0 ) { - prm[j] = get_next_indice_fx( st, n ); - j = add( j, 1 ); + prm[j] = get_next_indice_fx( st, n ); // Q0 + j = add( j, 1 ); // Q0 move16(); } @@ -1205,24 +1238,24 @@ void dec_prm_fx( { /* NOTE: FCB actual bits need to be backed up as well */ /*n = ACELP_FIXED_CDK_BITS(st->rf_indx_fcb[fec_offset][sfr]) & 15;*/ - prm[j] = get_next_indice_fx( st, 7 ); + prm[j] = get_next_indice_fx( st, 7 ); // Q0 move16(); - j = add( j, 8 ); + j = add( j, 8 ); // Q0 } /* Gains (5b, 6b or 7b / subfr) */ test(); IF( sfr == 0 || EQ_16( sfr, 2 ) ) { - n = ACELP_GAINS_BITS[gains_mode]; + n = ACELP_GAINS_BITS[gains_mode]; // Q0 move16(); - prm[j] = get_next_indice_fx( st, n ); - j = add( j, 1 ); + prm[j] = get_next_indice_fx( st, n ); // Q0 + j = add( j, 1 ); // Q0 move16(); } } - st->rf_indx_tbeGainFr = get_next_indice_fx( st, 2 ); + st->rf_indx_tbeGainFr = get_next_indice_fx( st, 2 ); // Q0 move16(); } } @@ -1238,18 +1271,18 @@ void dec_prm_fx( if ( st->enablePlcWaveadjust ) { - st->tonality_flag = get_next_indice_fx( st, 1 ); + st->tonality_flag = get_next_indice_fx( st, 1 ); // Q0 move16(); } /* TCX Gain = 7 bits */ - prm[j] = get_next_indice_fx( st, 7 ); - j = add( j, 1 ); + prm[j] = get_next_indice_fx( st, 7 ); // Q0 + j = add( j, 1 ); // Q0 move16(); /* TCX Noise Filling = NBITS_NOISE_FILL_LEVEL bits */ - prm[j] = get_next_indice_fx( st, NBITS_NOISE_FILL_LEVEL ); - j = add( j, 1 ); + prm[j] = get_next_indice_fx( st, NBITS_NOISE_FILL_LEVEL ); // Q0 + j = add( j, 1 ); // Q0 move16(); /* LTP data */ @@ -1258,31 +1291,31 @@ void dec_prm_fx( IF( hTcxLtpDec->tcxltp != 0 || GT_32( st->sr_core, 25600 ) ) { - prm[j] = get_next_indice_fx( st, 1 ); + prm[j] = get_next_indice_fx( st, 1 ); // Q0 move16(); IF( prm[j] ) { - prm[j + 1] = get_next_indice_fx( st, 9 ); + prm[j + 1] = get_next_indice_fx( st, 9 ); // Q0 move16(); - prm[j + 2] = get_next_indice_fx( st, 2 ); + prm[j + 2] = get_next_indice_fx( st, 2 ); // Q0 move16(); } - st->BER_detect = st->BER_detect | - tcx_ltp_decode_params( &prm[j], - &( hTcxLtpDec->tcxltp_pitch_int ), - &( hTcxLtpDec->tcxltp_pitch_fr ), - &( hTcxLtpDec->tcxltp_gain ), - st->pit_min, - st->pit_fr1, - st->pit_fr2, - st->pit_max, - st->pit_res_max ); + st->BER_detect = s_or( st->BER_detect, + tcx_ltp_decode_params( &prm[j], + &( hTcxLtpDec->tcxltp_pitch_int ), + &( hTcxLtpDec->tcxltp_pitch_fr ), + &( hTcxLtpDec->tcxltp_gain ), + st->pit_min, + st->pit_fr1, + st->pit_fr2, + st->pit_max, + st->pit_res_max ) ); - hTcxDec->tcx_hm_LtpPitchLag = -1; + hTcxDec->tcx_hm_LtpPitchLag = -1; // Q15 move16(); - hTcxDec->tcxltp_last_gain_unmodified = hTcxLtpDec->tcxltp_gain; + hTcxDec->tcxltp_last_gain_unmodified = hTcxLtpDec->tcxltp_gain; // Q15 move16(); test(); @@ -1290,12 +1323,12 @@ void dec_prm_fx( { Word32 tmp32 = L_shl( L_mult0( st->L_frame, st->pit_res_max ), 1 + kLtpHmFractionalResolution + 1 ); Word16 tmp1 = add( imult1616( hTcxLtpDec->tcxltp_pitch_int, st->pit_res_max ), hTcxLtpDec->tcxltp_pitch_fr ); - hTcxDec->tcx_hm_LtpPitchLag = div_l( tmp32, tmp1 ); + hTcxDec->tcx_hm_LtpPitchLag = div_l( tmp32, tmp1 ); // Q15 move16(); } } - j = add( j, 3 ); + j = add( j, 3 ); // Q0 /* TCX spectral data */ lg = L_frame; @@ -1303,16 +1336,16 @@ void dec_prm_fx( lgFB = st->hTcxCfg->tcx_coded_lines; move16(); - IF( EQ_16( st->last_core_from_bs, ACELP_CORE ) ) + IF( st->last_core_from_bs == ACELP_CORE ) { /* ACE->TCX transition */ - lg = add( lg, st->hTcxCfg->tcx_offset ); + lg = add( lg, st->hTcxCfg->tcx_offset ); // Q0 if ( st->hTcxCfg->lfacNext < 0 ) { - lg = sub( lg, st->hTcxCfg->lfacNext ); + lg = sub( lg, st->hTcxCfg->lfacNext ); // Q0 } - lgFB = add( lgFB, shr( lgFB, 2 ) ); + lgFB = add( lgFB, shr( lgFB, 2 ) ); // Q0 } /* TNS data */ @@ -1326,7 +1359,7 @@ void dec_prm_fx( SetTnsConfig( st->hTcxCfg, 1, (Word16) EQ_16( st->last_core_from_bs, ACELP_CORE ) ); ReadTnsData( st->hTcxCfg->pCurrentTnsConfig, st, &nTnsBits, prm + j, &nTnsParams ); - j = add( j, nTnsParams ); + j = add( j, nTnsParams ); // Q0 } hm_size = shl( mult( st->TcxBandwidth, lg ), 1 ); @@ -1337,18 +1370,18 @@ void dec_prm_fx( } nbits_tcx = sub( st->bits_frame_core, sub( st->next_bit_pos, start_bit_pos ) ); - if ( st->enableGplc != 0 ) + IF( st->enableGplc != 0 ) { - nbits_tcx = sub( nbits_tcx, 7 ); + nbits_tcx = sub( nbits_tcx, 7 ); // Q0 } /*Context HM flag*/ test(); - IF( st->hTcxCfg->ctx_hm && NE_16( st->last_core_from_bs, ACELP_CORE ) ) + IF( st->hTcxCfg->ctx_hm && ( st->last_core_from_bs != ACELP_CORE ) ) { - prm[j] = get_next_indice_fx( st, 1 ); + prm[j] = get_next_indice_fx( st, 1 ); // Q0 move16(); - nbits_tcx = sub( nbits_tcx, 1 ); + nbits_tcx = sub( nbits_tcx, 1 ); // Q0 IF( prm[j] ) { @@ -1375,10 +1408,10 @@ void dec_prm_fx( hTcxDec->tcx_hm_LtpPitchLag, &hm_cfg ); - nbits_tcx = sub( nbits_tcx, NumIndexBits ); + nbits_tcx = sub( nbits_tcx, NumIndexBits ); // Q0 } } - j = add( j, NPRM_CTX_HM ); + j = add( j, NPRM_CTX_HM ); // Q0 /* read IGF payload */ IF( st->igf ) @@ -1386,7 +1419,7 @@ void dec_prm_fx( n = st->next_bit_pos; move16(); - IF( EQ_16( st->last_core_from_bs, ACELP_CORE ) ) + IF( st->last_core_from_bs == ACELP_CORE ) { IGFDecReadLevel( st->hIGFDec, st, IGF_GRID_LB_TRAN, 1 ); IGFDecReadData( st->hIGFDec, st, IGF_GRID_LB_TRAN, 1 ); @@ -1397,22 +1430,22 @@ void dec_prm_fx( IGFDecReadData( st->hIGFDec, st, IGF_GRID_LB_NORM, 1 ); } - nbits_tcx = sub( nbits_tcx, sub( st->next_bit_pos, n ) ); + nbits_tcx = sub( nbits_tcx, sub( st->next_bit_pos, n ) ); // Q0 } - nbits_tcx = sub( st->bits_frame_core, sub( st->next_bit_pos, start_bit_pos ) ); + nbits_tcx = sub( st->bits_frame_core, sub( st->next_bit_pos, start_bit_pos ) ); // Q0 IF( hTcxDec->tcx_lpc_shaped_ari != 0 ) { - prm[j] = nbits_tcx; /* store length of buffer */ - j = add( j, 1 ); + prm[j] = nbits_tcx; /* store length of buffer */ // Q0 + j = add( j, 1 ); // Q0 move16(); prms = &prm[j]; FOR( ix = 0; ix < nbits_tcx; ix++ ) { - prms[ix] = get_next_indice_1_fx( st ); + prms[ix] = get_next_indice_1_fx( st ); // Q0 move16(); } set16_fx( prms + nbits_tcx, 1, 32 ); - j = add( j, nbits_tcx ); + j = add( j, nbits_tcx ); // Q0 } ELSE { @@ -1423,9 +1456,9 @@ void dec_prm_fx( phm_cfg = &hm_cfg; move16(); } - hTcxDec->resQBits[0] = ACcontextMapping_decode2_no_mem_s17_LC( st, prm + j, lgFB, nbits_tcx, NPRM_RESQ * st->hTcxCfg->resq, phm_cfg ); + hTcxDec->resQBits[0] = ACcontextMapping_decode2_no_mem_s17_LC( st, prm + j, lgFB, nbits_tcx, imult1616( NPRM_RESQ, st->hTcxCfg->resq ), phm_cfg ); // Q0 move16(); - j = add( j, lg ); + j = add( j, lg ); // Q0 } } @@ -1434,7 +1467,7 @@ void dec_prm_fx( IF( GE_16( st->rf_frame_type, RF_TCXFD ) && LE_16( st->rf_frame_type, RF_TCXTD2 ) && EQ_16( st->use_partial_copy, 1 ) ) { /* classification */ - ind = get_next_indice_fx( st, 2 ); + ind = get_next_indice_fx( st, 2 ); // Q0 st->clas_dec = ONSET; move16(); @@ -1465,7 +1498,7 @@ void dec_prm_fx( IF( EQ_16( st->rf_frame_type, RF_TCXFD ) ) { /* TCX Gain = 7 bits */ - hTcxDec->old_gaintcx_bfi = get_next_indice_fx( st, 7 ); + hTcxDec->old_gaintcx_bfi = get_next_indice_fx( st, 7 ); // Q0 move16(); } ELSE @@ -1476,19 +1509,19 @@ void dec_prm_fx( test(); IF( EQ_16( st->rf_frame_type, RF_TCXTD2 ) || EQ_16( st->rf_frame_type, RF_TCXTD1 ) ) { - prm_ltp[0] = 1; - move16(); /* LTP active*/ - prm_ltp[1] = get_next_indice_fx( st, 9 ); - prm_ltp[2] = 3; - move16(); /* max ampl. quantizer output (2bits), anyway not used later*/ + prm_ltp[0] = 1; // Q0 + move16(); /* LTP active*/ + prm_ltp[1] = get_next_indice_fx( st, 9 ); // Q0 + prm_ltp[2] = 3; // Q0 + move16(); /* max ampl. quantizer output (2bits), anyway not used later*/ IF( st->prev_bfi == 0 ) { - st->BER_detect = st->BER_detect | - tcx_ltp_decode_params( &prm_ltp[0], &( hTcxLtpDec->tcxltp_pitch_int ), &( hTcxLtpDec->tcxltp_pitch_fr ), &( hTcxLtpDec->tcxltp_gain ), - st->pit_min, st->pit_fr1, st->pit_fr2, st->pit_max, st->pit_res_max ); + st->BER_detect = s_or( st->BER_detect, + tcx_ltp_decode_params( &prm_ltp[0], &( hTcxLtpDec->tcxltp_pitch_int ), &( hTcxLtpDec->tcxltp_pitch_fr ), &( hTcxLtpDec->tcxltp_gain ), + st->pit_min, st->pit_fr1, st->pit_fr2, st->pit_max, st->pit_res_max ) ); move16(); - hTcxDec->tcxltp_last_gain_unmodified = hTcxLtpDec->tcxltp_gain; + hTcxDec->tcxltp_last_gain_unmodified = hTcxLtpDec->tcxltp_gain; // Q15 move16(); } } @@ -1536,22 +1569,22 @@ void dec_prm_fx( j = 0; move16(); - nbits_tcx = sub( st->next_bit_pos, start_bit_pos ); + nbits_tcx = sub( st->next_bit_pos, start_bit_pos ); // Q0 test(); - if ( st->enablePlcWaveadjust && k ) + IF( st->enablePlcWaveadjust && k ) { - st->tonality_flag = get_next_indice_fx( st, 1 ); + st->tonality_flag = get_next_indice_fx( st, 1 ); // Q0 move16(); } /* TCX Gain = 7 bits */ - prm[j] = get_next_indice_fx( st, 7 ); - j = add( j, 1 ); + prm[j] = get_next_indice_fx( st, 7 ); // Q0 + j = add( j, 1 ); // Q0 move16(); /* TCX Noise Filling = NBITS_NOISE_FILL_LEVEL bits */ - prm[j] = get_next_indice_fx( st, NBITS_NOISE_FILL_LEVEL ); - j = add( j, 1 ); + prm[j] = get_next_indice_fx( st, NBITS_NOISE_FILL_LEVEL ); // Q0 + j = add( j, 1 ); // Q0 move16(); /* LTP data */ @@ -1559,22 +1592,22 @@ void dec_prm_fx( test(); IF( ( k == 0 ) && ( ( hTcxLtpDec->tcxltp != 0 ) || ( GT_32( st->sr_core, 25600 ) ) ) ) { - prm[j] = get_next_indice_fx( st, 1 ); + prm[j] = get_next_indice_fx( st, 1 ); // Q0 move16(); IF( prm[j] ) { - prm[j + 1] = get_next_indice_fx( st, 9 ); + prm[j + 1] = get_next_indice_fx( st, 9 ); // Q0 move16(); - prm[j + 2] = get_next_indice_fx( st, 2 ); + prm[j + 2] = get_next_indice_fx( st, 2 ); // Q0 move16(); - tcxltp_prm_0 = prm[j]; + tcxltp_prm_0 = prm[j]; // Q0 move16(); - tcxltp_prm_1 = prm[j + 1]; + tcxltp_prm_1 = prm[j + 1]; // Q0 move16(); - tcxltp_prm_2 = prm[j + 2]; + tcxltp_prm_2 = prm[j + 2]; // Q0 move16(); } @@ -1590,32 +1623,32 @@ void dec_prm_fx( st->pit_res_max ) ); move16(); - hTcxDec->tcxltp_last_gain_unmodified = hTcxLtpDec->tcxltp_gain; + hTcxDec->tcxltp_last_gain_unmodified = hTcxLtpDec->tcxltp_gain; // Q15 move16(); - hTcxDec->tcx_hm_LtpPitchLag = -1; + hTcxDec->tcx_hm_LtpPitchLag = -1; // Q15 move16(); - j = add( j, 3 ); + j = add( j, 3 ); // Q0 } ELSE { - prm[j] = tcxltp_prm_0; - j = add( j, 1 ); + prm[j] = tcxltp_prm_0; // Q0 + j = add( j, 1 ); // Q0 move16(); - prm[j] = tcxltp_prm_1; - j = add( j, 1 ); + prm[j] = tcxltp_prm_1; // Q0 + j = add( j, 1 ); // Q0 move16(); - prm[j] = tcxltp_prm_2; - j = add( j, 1 ); + prm[j] = tcxltp_prm_2; // Q0 + j = add( j, 1 ); // Q0 move16(); } /* TCX spectral data */ - lg = shr( L_frame, 1 ); - lgFB = shr( st->hTcxCfg->tcx_coded_lines, 1 ); + lg = shr( L_frame, 1 ); // Q0 + lgFB = shr( st->hTcxCfg->tcx_coded_lines, 1 ); // Q0 test(); - IF( k == 0 && EQ_16( st->last_core_from_bs, ACELP_CORE ) ) + IF( k == 0 && ( st->last_core_from_bs == ACELP_CORE ) ) { /* ACE->TCX transition */ lg = add( lg, st->hTcxCfg->tcx_offset ); @@ -1656,31 +1689,31 @@ void dec_prm_fx( hm_size = shl( mult( st->TcxBandwidth, lgFB ), 1 ); /*compute target bits*/ - nbits_tcx = sub( shr( sub( add( sub( sub( st->bits_frame_core, st->bits_common ), nbits_igf ), 1 ), k ), 1 ), sub( sub( st->next_bit_pos, start_bit_pos ), nbits_tcx ) ); + nbits_tcx = sub( shr( sub( add( sub( sub( st->bits_frame_core, st->bits_common ), nbits_igf ), 1 ), k ), 1 ), sub( sub( st->next_bit_pos, start_bit_pos ), nbits_tcx ) ); // Q0 /*Context HM flag*/ test(); test(); - IF( st->hTcxCfg->ctx_hm && !( EQ_16( st->last_core_from_bs, ACELP_CORE ) && ( k == 0 ) ) ) + IF( st->hTcxCfg->ctx_hm && !( ( st->last_core_from_bs == ACELP_CORE ) && ( k == 0 ) ) ) { - prm[j] = get_next_indice_fx( st, 1 ); + prm[j] = get_next_indice_fx( st, 1 ); // Q0 move16(); - nbits_tcx = sub( nbits_tcx, 1 ); + nbits_tcx = sub( nbits_tcx, 1 ); // Q0 move16(); IF( prm[j] ) /* Read PeriodicityIndex */ { - Word16 NumIndexBits = DecodeIndex_fx( st, (Word16) GE_16( hm_size, 256 ), prm + j + 1 ); + Word16 NumIndexBits = DecodeIndex_fx( st, (Word16) GE_16( hm_size, 256 ), prm + j + 1 ); // Q0 flag_ctx_hm = 1; move16(); ConfigureContextHm( lgFB, nbits_tcx, *( prm + j + 1 ), -1, &hm_cfg ); - nbits_tcx = sub( nbits_tcx, NumIndexBits ); + nbits_tcx = sub( nbits_tcx, NumIndexBits ); // Q0 } } - j = add( j, NPRM_CTX_HM ); + j = add( j, NPRM_CTX_HM ); // Q0 phm_cfg = NULL; move16(); if ( flag_ctx_hm ) @@ -1688,9 +1721,9 @@ void dec_prm_fx( phm_cfg = &hm_cfg; move16(); } - hTcxDec->resQBits[k] = ACcontextMapping_decode2_no_mem_s17_LC( st, prm + j, lgFB, nbits_tcx, NPRM_RESQ * st->hTcxCfg->resq, phm_cfg ); + hTcxDec->resQBits[k] = ACcontextMapping_decode2_no_mem_s17_LC( st, prm + j, lgFB, nbits_tcx, imult1616( NPRM_RESQ, st->hTcxCfg->resq ), phm_cfg ); // Q0 move16(); - j = add( j, lgFB ); + j = add( j, lgFB ); // Q0 } /* k, window index */ } @@ -1701,10 +1734,10 @@ void dec_prm_fx( { st->BER_detect = 1; move16(); - st->next_bit_pos = add( start_bit_pos, sub( *total_nbbits, bitsRead[0] ) ); + st->next_bit_pos = add( start_bit_pos, sub( *total_nbbits, bitsRead[0] ) ); // Q0 move16(); } - bitsRead[0] = sub( st->next_bit_pos, start_bit_pos ); + bitsRead[0] = sub( st->next_bit_pos, start_bit_pos ); // Q0 move16(); } diff --git a/lib_dec/dec_tcx_fx.c b/lib_dec/dec_tcx_fx.c index 53b688e72..35a417a6c 100644 --- a/lib_dec/dec_tcx_fx.c +++ b/lib_dec/dec_tcx_fx.c @@ -1613,9 +1613,9 @@ void decoder_tcx_post_fx( Decoder_State *st_fx, #ifdef IVAS_FLOAT_FIXED void decoder_tcx_post_ivas_fx( Decoder_State *st_fx, - Word16 *synth, - Word16 *synthFB, - Word16 *A, + Word16 *synth, // Qx + Word16 *synthFB, // Qx + Word16 *A, // Q: 14 - norm_s(A[0]) Word16 bfi, Word16 MCT_flag ) { @@ -1684,7 +1684,7 @@ void decoder_tcx_post_ivas_fx( Decoder_State *st_fx, { tmp32 = L_shl( tmp32_1 /*Q28*/, -( 28 - 15 ) ); /*16Q15*/ #ifdef BASOP_NOGLOB - synthFB[i] = round_fx_sat( L_shl_sat( Mpy_32_16_1( tmp32, synthFB[i] ), 16 ) ); + synthFB[i] = round_fx_sat( L_shl_sat( Mpy_32_16_1( tmp32, synthFB[i] ), 16 ) ); // Qx #else synthFB[i] = round_fx( L_shl( Mpy_32_16_1( tmp32, synthFB[i] ), 16 ) ); #endif @@ -1696,8 +1696,8 @@ void decoder_tcx_post_ivas_fx( Decoder_State *st_fx, tmp32_2 /*stepCompensate*/ = L_shl_r( L_deposit_h( hTcxDec->stepCompensate ), sub( hTcxDec->stepCompensate_e, 31 - 28 ) ); /*Q28*/ FOR( i = 0; i < st_fx->L_frame; i++ ) { - tmp32 = L_shl( tmp32_1 /*Q28*/, -( 28 - 15 ) ); /*16Q15*/ - xn_buf[i] = extract_l( Mpy_32_16_1( tmp32, xn_buf[i] ) ); + tmp32 = L_shl( tmp32_1 /*Q28*/, -( 28 - 15 ) ); /*16Q15*/ + xn_buf[i] = extract_l( Mpy_32_16_1( tmp32, xn_buf[i] ) ); // Qx move16(); tmp32_1 = L_sub( tmp32_1, tmp32_2 ); } @@ -1843,7 +1843,7 @@ void decoder_tcx_post_ivas_fx( Decoder_State *st_fx, } } - if ( ( EQ_16( st_fx->nbLostCmpt, 1 ) ) ) + IF( ( EQ_16( st_fx->nbLostCmpt, 1 ) ) ) { hTcxDec->conceal_eof_gain32 = ONE_IN_Q30 /*1.0f Q30*/; move32(); @@ -1878,14 +1878,14 @@ void decoder_tcx_post_ivas_fx( Decoder_State *st_fx, FOR( i = 0; i < hTcxDec->L_frameTCX; i++ ) { tmp_shift = conceal_eof_gainFB_e; - synthFB[i] = round_fx_sat( L_shl_sat( Mpy_32_16_1( conceal_eof_gainFB, synthFB[i] ), tmp_shift ) ); + synthFB[i] = round_fx_sat( L_shl_sat( Mpy_32_16_1( conceal_eof_gainFB, synthFB[i] ), tmp_shift ) ); // Qx move16(); - conceal_eof_gainFB = BASOP_Util_Add_Mant32Exp( conceal_eof_gainFB, conceal_eof_gainFB_e, L_negate( stepFB ), stepFB_e, &conceal_eof_gainFB_e ); + conceal_eof_gainFB = BASOP_Util_Add_Mant32Exp( conceal_eof_gainFB, conceal_eof_gainFB_e, L_negate( stepFB ), stepFB_e, &conceal_eof_gainFB_e ); // Q: 31 - conceal_eof_gainFB_e } } FOR( i = 0; i < st_fx->L_frame; i++ ) { - xn_buf[i] = round_fx_sat( L_shl_sat( Mpy_32_16_1( hTcxDec->conceal_eof_gain32, xn_buf[i] ), hTcxDec->conceal_eof_gain_e ) ); + xn_buf[i] = round_fx_sat( L_shl_sat( Mpy_32_16_1( hTcxDec->conceal_eof_gain32, xn_buf[i] ), hTcxDec->conceal_eof_gain_e ) ); // Qx move16(); hTcxDec->conceal_eof_gain32 = BASOP_Util_Add_Mant32Exp( hTcxDec->conceal_eof_gain32, hTcxDec->conceal_eof_gain_e, L_negate( step ), step_e, &hTcxDec->conceal_eof_gain_e ); move32(); @@ -1956,16 +1956,16 @@ void decoder_tcx_post_ivas_fx( Decoder_State *st_fx, st_fx->bfi_pitch_frame = st_fx->L_frame; move16(); - st_fx->mem_pitch_gain[add( shl( st_fx->nb_subfr, 1 ), 1 )] = st_fx->mem_pitch_gain[st_fx->nb_subfr + 1]; + st_fx->mem_pitch_gain[st_fx->nb_subfr * 2 + 1] = st_fx->mem_pitch_gain[st_fx->nb_subfr + 1]; // Q14 move16(); - st_fx->mem_pitch_gain[shl( st_fx->nb_subfr, 1 )] = st_fx->mem_pitch_gain[st_fx->nb_subfr]; + st_fx->mem_pitch_gain[st_fx->nb_subfr * 2] = st_fx->mem_pitch_gain[st_fx->nb_subfr]; // Q14 move16(); FOR( i = 0; i < st_fx->nb_subfr; i++ ) { - st_fx->mem_pitch_gain[sub( sub( shl( st_fx->nb_subfr, 1 ), 1 ), i )] = st_fx->mem_pitch_gain[sub( sub( st_fx->nb_subfr, 1 ), i )]; + st_fx->mem_pitch_gain[( st_fx->nb_subfr * 2 - 1 ) - i] = st_fx->mem_pitch_gain[st_fx->nb_subfr - 1 - i]; // Q14 move16(); - st_fx->mem_pitch_gain[sub( sub( st_fx->nb_subfr, 1 ), i )] = shr( hTcxDec->tcxltp_last_gain_unmodified, 1 ); /* Q14 */ + st_fx->mem_pitch_gain[st_fx->nb_subfr - 1 - i] = shr( hTcxDec->tcxltp_last_gain_unmodified, 1 ); /* Q14 */ move16(); } } @@ -2049,7 +2049,7 @@ void IMDCT_fx( Word32 *x, Word16 x_e, Word16 *old_syn_overl, Word16 *syn_Overl_T /* number of zero for ALDO windows*/ tmp32 = L_add( st->sr_core, 0 ); - if ( fullbandScale != 0 ) + IF( fullbandScale != 0 ) { tmp32 = L_add( st->output_Fs, 0 ); } @@ -2057,7 +2057,7 @@ void IMDCT_fx( Word32 *x, Word16 x_e, Word16 *old_syn_overl, Word16 *syn_Overl_T tmp_offset = 0; move16(); - if ( tcx_offset < 0 ) + IF( tcx_offset < 0 ) { tmp_offset = negate( tcx_offset ); } @@ -2258,9 +2258,9 @@ void IMDCT_fx( Word32 *x, Word16 x_e, Word16 *old_syn_overl, Word16 *syn_Overl_T L_win ); /* extra folding-out on left side of win, for perfect reconstruction */ - FOR( w = shr( overlap, 1 ); w < overlap; w++ ) + FOR( w = ( overlap / 2 ); w < overlap; w++ ) { - xn_buf[sub( sub( overlap, 1 ), w )] = negate( xn_buf[w] ); + xn_buf[( ( overlap - 1 ) - w )] = negate( xn_buf[w] ); move16(); } @@ -2745,8 +2745,8 @@ void IMDCT_fx( Word32 *x, Word16 x_e, Word16 *old_syn_overl, Word16 *syn_Overl_T FOR( ; i < tcx_mdct_window_half_length; i++ ) { #ifdef BASOP_NOGLOB - xn_buf[i + tmp1] = mult_r_sat( xn_buf[i + tmp1], tcx_mdct_window_half[sub( sub( tcx_mdct_window_half_length, 1 ), i )].v.re ); - xn_buf[i + tmp1] = add_sat( xn_buf[i + tmp1], mult_r_sat( hTcxDec->syn_OverlFB[i], mult_r_sat( tcx_mdct_window_half[sub( sub( tcx_mdct_window_half_length, 1 ), i )].v.im, tcx_mdct_window_half[sub( sub( tcx_mdct_window_half_length, 1 ), i )].v.im ) ) ); + xn_buf[i + tmp1] = mult_r_sat( xn_buf[i + tmp1], tcx_mdct_window_half[( ( tcx_mdct_window_half_length - 1 ) - i )].v.re ); + xn_buf[i + tmp1] = add_sat( xn_buf[i + tmp1], mult_r_sat( hTcxDec->syn_OverlFB[i], mult_r_sat( tcx_mdct_window_half[( ( tcx_mdct_window_half_length - 1 ) - i )].v.im, tcx_mdct_window_half[tcx_mdct_window_half_length - 1 - i].v.im ) ) ); #else xn_buf[i + tmp1] = mult_r( xn_buf[i + tmp1], tcx_mdct_window_half[tcx_mdct_window_half_length - 1 - i].v.re ); xn_buf[i + tmp1] = add( xn_buf[i + tmp1], mult_r( hTcxDec->syn_OverlFB[i], mult_r( tcx_mdct_window_half[tcx_mdct_window_half_length - 1 - i].v.im, tcx_mdct_window_half[tcx_mdct_window_half_length - 1 - i].v.im ) ) ); @@ -2774,8 +2774,8 @@ void IMDCT_fx( Word32 *x, Word16 x_e, Word16 *old_syn_overl, Word16 *syn_Overl_T FOR( ; i < tcx_mdct_window_half_length; i++ ) { #ifdef BASOP_NOGLOB - xn_buf[i + tmp1] = mult_r_sat( xn_buf[i + tmp1], tcx_mdct_window_half[sub( sub( tcx_mdct_window_half_length, 1 ), i )].v.re ); - xn_buf[i + tmp1] = add_sat( xn_buf[i + tmp1], mult_r_sat( hTcxDec->syn_Overl[i], mult_r_sat( tcx_mdct_window_half[sub( sub( tcx_mdct_window_half_length, 1 ), i )].v.im, tcx_mdct_window_half[sub( sub( tcx_mdct_window_half_length, 1 ), i )].v.im ) ) ); + xn_buf[i + tmp1] = mult_r_sat( xn_buf[i + tmp1], tcx_mdct_window_half[tcx_mdct_window_half_length - 1 - i].v.re ); + xn_buf[i + tmp1] = add_sat( xn_buf[i + tmp1], mult_r_sat( hTcxDec->syn_Overl[i], mult_r_sat( tcx_mdct_window_half[tcx_mdct_window_half_length - 1 - i].v.im, tcx_mdct_window_half[tcx_mdct_window_half_length - 1 - i].v.im ) ) ); #else xn_buf[i + tmp1] = mult_r( xn_buf[i + tmp1], tcx_mdct_window_half[tcx_mdct_window_half_length - 1 - i].v.re ); xn_buf[i + tmp1] = add( xn_buf[i + tmp1], mult_r( hTcxDec->syn_Overl[i], mult_r( tcx_mdct_window_half[tcx_mdct_window_half_length - 1 - i].v.im, tcx_mdct_window_half[tcx_mdct_window_half_length - 1 - i].v.im ) ) ); @@ -2836,7 +2836,7 @@ void IMDCT_ivas_fx( exp = 0; move16(); nz = BASOP_Util_Divide3216_Scale( c, L_frameTCX, &exp ); - exp = exp + ( 31 - 15 ); + exp = add( exp, ( 31 - 15 ) ); nz = shr( nz, sub( 15, exp ) ); // Q0 test(); @@ -2852,7 +2852,7 @@ void IMDCT_ivas_fx( fac = Mpy_32_16_1( hTcxDec->conceal_eof_gain32, st->last_concealed_gain_syn_deemph ); // q = 31 - hTcxDec->conceal_eof_gain_e FOR( Word16 ind = 0; ind < overlap; ind++ ) { - old_syn_overl_fx[ind] = extract_l( L_shl_sat( Mpy_32_32( old_syn_overl_fx[ind], fac ), hTcxDec->conceal_eof_gain_e ) ); + old_syn_overl_fx[ind] = extract_l( L_shl_sat( Mpy_32_32( old_syn_overl_fx[ind], fac ), hTcxDec->conceal_eof_gain_e ) ); // Q(-2) move16(); } } @@ -2998,17 +2998,17 @@ void IMDCT_ivas_fx( /* extra folding-out on left side of win, for perfect reconstruction */ IF( GE_16( kernel_type, MDCT_II ) ) { - FOR( w = shr( overlap, 1 ); w < overlap; w++ ) + FOR( w = overlap / 2; w < overlap; w++ ) { - xn_buf_fx[sub( sub( overlap, 1 ), w )] = xn_buf_fx[w]; + xn_buf_fx[overlap - 1 - w] = xn_buf_fx[w]; move16(); } } ELSE { - FOR( w = shr( overlap, 1 ); w < overlap; w++ ) + FOR( w = overlap / 2; w < overlap; w++ ) { - xn_buf_fx[sub( sub( overlap, 1 ), w )] = negate( xn_buf_fx[w] ); + xn_buf_fx[overlap - 1 - w] = negate( xn_buf_fx[w] ); move16(); } } @@ -3068,7 +3068,7 @@ void IMDCT_ivas_fx( FOR( Word16 ind = 0; ind < L_frame; ind++ ) { - tmp_fx_32[ind] = L_shl( Mpy_32_16_1( xn_buf_fx_32[shr( overlap, 1 ) + nz + ind], res_m ), res_e ); + tmp_fx_32[ind] = L_shl( Mpy_32_16_1( xn_buf_fx_32[( overlap / 2 ) + nz + ind], res_m ), res_e ); move32(); } q_tmp_fx_32 = q_xn_buf_fx_32; @@ -3103,7 +3103,7 @@ void IMDCT_ivas_fx( FOR( Word16 ind = 0; ind < L_frame; ind++ ) { - tmp_fx_32[ind] = Mpy_32_16_1( xn_buf_fx_32[shr( overlap, 1 ) + nz + ind], res_m ); + tmp_fx_32[ind] = Mpy_32_16_1( xn_buf_fx_32[( overlap / 2 ) + nz + ind], res_m ); move32(); } q_tmp_fx_32 = sub( q_xn_buf_fx_32, res_e ); @@ -3111,7 +3111,7 @@ void IMDCT_ivas_fx( FOR( Word16 ind = 0; ind < L_frame; ind++ ) { - xn_buf_fx[add( add( ind, shr( overlap, 1 ) ), nz )] = (Word16) L_shr( xn_buf_fx_32[add( add( ind, shr( overlap, 1 ) ), nz )], sub( q_xn_buf_fx_32, q_win ) ); + xn_buf_fx[( ind + ( overlap / 2 ) ) + nz] = (Word16) L_shr( xn_buf_fx_32[( ind + ( overlap / 2 ) ) + nz], sub( q_xn_buf_fx_32, q_win ) ); move16(); } @@ -3135,13 +3135,13 @@ void IMDCT_ivas_fx( IF( tcx_offset < 0 ) { - acelp_mem_len = -tcx_offset; + acelp_mem_len = negate( tcx_offset ); } ELSE { acelp_mem_len = 0; + move16(); } - move16(); IF( EQ_16( kernel_type, MDST_IV ) ) { @@ -3183,7 +3183,7 @@ void IMDCT_ivas_fx( lev_dur_fx( &st->old_Aq_12_8_fx_32[0], &r_fx[0], M, NULL, 28 /*Q(st->q_old_Aq_12_8_fx_32)*/, add( add( shl( q_buf, 1 ), q_r ), 1 ) ); FOR( Word16 ind = 0; ind <= M; ind++ ) { - st->old_Aq_12_8_fx[ind] = (Word16) L_shr( st->old_Aq_12_8_fx_32[ind], 16 ); + st->old_Aq_12_8_fx[ind] = (Word16) L_shr( st->old_Aq_12_8_fx_32[ind], 16 ); // Q28 -> Q12 move16(); } } @@ -3215,9 +3215,9 @@ void IMDCT_ivas_fx( FOR( i = 0; i < sub( overlap, tcx_mdct_window_min_length ); i++ ) { #ifdef BASOP_NOGLOB - xn_buf_fx[add( i, sub( shr( overlap, 1 ), tcx_offset ) )] = add_sat( xn_buf_fx[add( i, sub( shr( overlap, 1 ), tcx_offset ) )], old_out_fx[add( i, nz )] ); + xn_buf_fx[( i + ( ( overlap / 2 ) - tcx_offset ) )] = add_sat( xn_buf_fx[( i + ( ( overlap / 2 ) - tcx_offset ) )], old_out_fx[( i + nz )] ); // Q(-2) #else - xn_buf_fx[add( i, sub( shr( overlap, 1 ), tcx_offset ) )] = add( xn_buf_fx[add( i, sub( shr( overlap, 1 ), tcx_offset ) )], old_out_fx[add( i, nz )] ); + xn_buf_fx[( i + ( ( overlap / 2 ) - tcx_offset ) )] = add( xn_buf_fx[( i + ( ( overlap / 2 ) - tcx_offset ) )], old_out_fx[( i + nz )] ); #endif move16(); } @@ -3232,49 +3232,49 @@ void IMDCT_ivas_fx( FOR( ; i < overlap; i++ ) /* perfectly reconstructing ALDO shortening */ { #ifdef BASOP_NOGLOB - xn_buf_fx[sub( add( i, shr( overlap, 1 ) ), tcx_offset )] = add_sat( xn_buf_fx[sub( add( i, shr( overlap, 1 ) ), tcx_offset )], old_out_fx[add( i, nz )] ); + xn_buf_fx[( ( i + ( overlap / 2 ) ) - tcx_offset )] = add_sat( xn_buf_fx[( ( i + ( overlap / 2 ) ) - tcx_offset )], old_out_fx[( i + nz )] ); // Q(-2) #else - xn_buf_fx[sub( add( i, shr( overlap, 1 ) ), tcx_offset )] = add( xn_buf_fx[sub( add( i, shr( overlap, 1 ) ), tcx_offset )], old_out_fx[add( i, nz )] ); + xn_buf_fx[( ( i + ( overlap / 2 ) ) - tcx_offset )] = add( xn_buf_fx[( ( i + ( overlap / 2 ) ) - tcx_offset )], old_out_fx[( i + nz )] ); // Q(-2) #endif move16(); } - FOR( i = 0; i < shr( tcx_mdct_window_min_length, 1 ); i++ ) + FOR( i = 0; i < ( tcx_mdct_window_min_length / 2 ); i++ ) { #ifdef BASOP_NOGLOB - xn_buf_fx[add( sub( add( i, shr( overlap, 1 ) ), tcx_offset ), overlap )] = add_sat( xn_buf_fx[add( sub( add( i, shr( overlap, 1 ) ), tcx_offset ), overlap )], mult_r( old_out_fx[add( add( i, nz ), overlap )], tcx_mdct_window_minimum_fx[i].v.re ) ); + xn_buf_fx[( ( ( i + ( overlap / 2 ) ) - tcx_offset ) + overlap )] = add_sat( xn_buf_fx[( ( ( i + ( overlap / 2 ) ) - tcx_offset ) + overlap )], mult_r( old_out_fx[( ( i + nz ) + overlap )], tcx_mdct_window_minimum_fx[i].v.re ) ); // Q(-2) #else - xn_buf_fx[add( sub( add( i, shr( overlap, 1 ) ), tcx_offset ), overlap )] = add( xn_buf_fx[add( sub( add( i, shr( overlap, 1 ) ), tcx_offset ), overlap )], mult_r( old_out_fx[add( add( i, nz ), overlap )], tcx_mdct_window_minimum_fx[i].v.re ) ); + xn_buf_fx[( ( ( i + ( overlap / 2 ) ) - tcx_offset ) + overlap )] = add( xn_buf_fx[( ( ( i + ( overlap / 2 ) ) - tcx_offset ) + overlap )], mult_r( old_out_fx[( ( i + nz ) + overlap )], tcx_mdct_window_minimum_fx[i].v.re ) ); #endif move16(); } FOR( ; i < tcx_mdct_window_min_length; i++ ) { #ifdef BASOP_NOGLOB - xn_buf_fx[add( sub( add( i, shr( overlap, 1 ) ), tcx_offset ), overlap )] = add_sat( xn_buf_fx[add( sub( add( i, shr( overlap, 1 ) ), tcx_offset ), overlap )], mult_r( old_out_fx[add( add( i, nz ), overlap )], tcx_mdct_window_minimum_fx[sub( tcx_mdct_window_min_length, add( 1, i ) )].v.im ) ); + xn_buf_fx[( ( ( i + ( overlap / 2 ) ) - tcx_offset ) + overlap )] = add_sat( xn_buf_fx[( ( ( i + ( overlap / 2 ) ) - tcx_offset ) + overlap )], mult_r( old_out_fx[( ( i + nz ) + overlap )], tcx_mdct_window_minimum_fx[( tcx_mdct_window_min_length - ( 1 + i ) )].v.im ) ); // Q(-2) #else - xn_buf_fx[add( sub( add( i, shr( overlap, 1 ) ), tcx_offset ), overlap )] = add( xn_buf_fx[add( sub( add( i, shr( overlap, 1 ) ), tcx_offset ), overlap )], mult_r( old_out_fx[add( add( i, nz ), overlap )], tcx_mdct_window_minimum_fx[sub( tcx_mdct_window_min_length, add( 1, i ) )].v.im ) ); + xn_buf_fx[( ( ( i + ( overlap / 2 ) ) - tcx_offset ) + overlap )] = add( xn_buf_fx[( ( ( i + ( overlap / 2 ) ) - tcx_offset ) + overlap )], mult_r( old_out_fx[( ( i + nz ) + overlap )], tcx_mdct_window_minimum_fx[( tcx_mdct_window_min_length - ( 1 + i ) )].v.im ) ); #endif move16(); } } ELSE { - FOR( ; i < sub( overlap, shr( tcx_mdct_window_min_length, 1 ) ); i++ ) + FOR( ; i < ( overlap - ( tcx_mdct_window_min_length / 2 ) ); i++ ) { #ifdef BASOP_NOGLOB - xn_buf_fx[sub( add( i, shr( overlap, 1 ) ), tcx_offset )] = add_sat( xn_buf_fx[sub( add( i, shr( overlap, 1 ) ), tcx_offset )], mult_r( old_out_fx[add( i, nz )], tcx_mdct_window_minimum_fx[add( sub( tcx_mdct_window_min_length, overlap ), i )].v.re ) ); + xn_buf_fx[( ( i + ( overlap / 2 ) ) - tcx_offset )] = add_sat( xn_buf_fx[( ( i + ( overlap / 2 ) ) - tcx_offset )], mult_r( old_out_fx[( i + nz )], tcx_mdct_window_minimum_fx[( ( tcx_mdct_window_min_length - overlap ) + i )].v.re ) ); // Q(-2) #else - xn_buf_fx[sub( add( i, shr( overlap, 1 ) ), tcx_offset )] = add( xn_buf_fx[sub( add( i, shr( overlap, 1 ) ), tcx_offset )], mult_r( old_out_fx[add( i, nz )], tcx_mdct_window_minimum_fx[add( sub( tcx_mdct_window_min_length, overlap ), i )].v.re ) ); + xn_buf_fx[( ( i + ( overlap / 2 ) ) - tcx_offset )] = add( xn_buf_fx[( ( i + ( overlap / 2 ) ) - tcx_offset )], mult_r( old_out_fx[( i + nz )], tcx_mdct_window_minimum_fx[( ( tcx_mdct_window_min_length - overlap ) + i )].v.re ) ); #endif move16(); } FOR( ; i < overlap; i++ ) { #ifdef BASOP_NOGLOB - xn_buf_fx[add( i, sub( shr( overlap, 1 ), tcx_offset ) )] = add_sat( xn_buf_fx[sub( add( i, shr( overlap, 1 ) ), tcx_offset )], mult_r( old_out_fx[add( i, nz )], tcx_mdct_window_minimum_fx[sub( overlap, add( 1, i ) )].v.im ) ); + xn_buf_fx[( i + ( ( overlap / 2 ) - tcx_offset ) )] = add_sat( xn_buf_fx[( ( i + ( overlap / 2 ) ) - tcx_offset )], mult_r( old_out_fx[( i + nz )], tcx_mdct_window_minimum_fx[( overlap - ( 1 + i ) )].v.im ) ); // Q(-2) #else - xn_buf_fx[add( i, sub( shr( overlap, 1 ), tcx_offset ) )] = add( xn_buf_fx[sub( add( i, shr( overlap, 1 ) ), tcx_offset )], mult_r( old_out_fx[add( i, nz )], tcx_mdct_window_minimum_fx[sub( overlap, add( 1, i ) )].v.im ) ); + xn_buf_fx[( i + ( ( overlap / 2 ) - tcx_offset ) )] = add( xn_buf_fx[( ( i + ( overlap / 2 ) ) - tcx_offset )], mult_r( old_out_fx[( i + nz )], tcx_mdct_window_minimum_fx[( overlap - ( 1 + i ) )].v.im ) ); #endif move16(); } @@ -3286,12 +3286,12 @@ void IMDCT_ivas_fx( IF( bfi != 0 ) { - FOR( i = 0; i < shr( tcx_mdct_window_half_length, 1 ); i++ ) + FOR( i = 0; i < ( tcx_mdct_window_half_length / 2 ); i++ ) { #ifdef BASOP_NOGLOB - xn_buf_fx[sub( add( i, shr( overlap, 1 ) ), tcx_offset )] = add_sat( xn_buf_fx[sub( add( i, shr( overlap, 1 ) ), tcx_offset )], mult_r( old_syn_overl_fx[i], tcx_mdct_window_half_fx[i].v.re ) ); + xn_buf_fx[( ( i + ( overlap / 2 ) ) - tcx_offset )] = add_sat( xn_buf_fx[( ( i + ( overlap / 2 ) ) - tcx_offset )], mult_r( old_syn_overl_fx[i], tcx_mdct_window_half_fx[i].v.re ) ); // Q(-2) #else - xn_buf_fx[sub( add( i, shr( overlap, 1 ) ), tcx_offset )] = add( xn_buf_fx[sub( add( i, shr( overlap, 1 ) ), tcx_offset )], mult_r( old_syn_overl_fx[i], tcx_mdct_window_half_fx[i].v.re ) ); + xn_buf_fx[( ( i + ( overlap / 2 ) ) - tcx_offset )] = add( xn_buf_fx[( ( i + ( overlap / 2 ) ) - tcx_offset )], mult_r( old_syn_overl_fx[i], tcx_mdct_window_half_fx[i].v.re ) ); #endif move16(); @@ -3299,9 +3299,9 @@ void IMDCT_ivas_fx( FOR( ; i < tcx_mdct_window_half_length; i++ ) { #ifdef BASOP_NOGLOB - xn_buf_fx[sub( add( i, shr( overlap, 1 ) ), tcx_offset )] = add_sat( xn_buf_fx[sub( add( i, shr( overlap, 1 ) ), tcx_offset )], mult_r( old_syn_overl_fx[i], tcx_mdct_window_half_fx[sub( tcx_mdct_window_half_length, add( 1, i ) )].v.im ) ); + xn_buf_fx[( ( i + ( overlap / 2 ) ) - tcx_offset )] = add_sat( xn_buf_fx[( ( i + ( overlap / 2 ) ) - tcx_offset )], mult_r( old_syn_overl_fx[i], tcx_mdct_window_half_fx[( tcx_mdct_window_half_length - ( 1 + i ) )].v.im ) ); // Q(-2) #else - xn_buf_fx[sub( add( i, shr( overlap, 1 ) ), tcx_offset )] = add( xn_buf_fx[sub( add( i, shr( overlap, 1 ) ), tcx_offset )], mult_r( old_syn_overl_fx[i], tcx_mdct_window_half_fx[sub( tcx_mdct_window_half_length, add( 1, i ) )].v.im ) ); + xn_buf_fx[( ( i + ( overlap / 2 ) ) - tcx_offset )] = add( xn_buf_fx[( ( i + ( overlap / 2 ) ) - tcx_offset )], mult_r( old_syn_overl_fx[i], tcx_mdct_window_half_fx[( tcx_mdct_window_half_length - ( 1 + i ) )].v.im ) ); #endif move16(); } @@ -3310,7 +3310,7 @@ void IMDCT_ivas_fx( { FOR( i = 0; i < overlap; i++ ) { - xn_buf_fx[i] = add_sat( xn_buf_fx[i], old_syn_overl_fx[i] ); + xn_buf_fx[i] = add_sat( xn_buf_fx[i], old_syn_overl_fx[i] ); // Q(-2) move16(); } } @@ -3319,9 +3319,9 @@ void IMDCT_ivas_fx( FOR( i = 0; i < overlap; i++ ) { #ifdef BASOP_NOGLOB - xn_buf_fx[add( i, shr( overlap, 1 ) )] = add_sat( xn_buf_fx[add( i, shr( overlap, 1 ) )], old_syn_overl_fx[i] ); + xn_buf_fx[( i + ( overlap / 2 ) )] = add_sat( xn_buf_fx[( i + ( overlap / 2 ) )], old_syn_overl_fx[i] ); // Q(-2) #else - xn_buf_fx[add( i, shr( overlap, 1 ) )] = add( xn_buf_fx[add( i, shr( overlap, 1 ) )], old_syn_overl_fx[i] ); + xn_buf_fx[( i + ( overlap / 2 ) )] = add( xn_buf_fx[( i + ( overlap / 2 ) )], old_syn_overl_fx[i] ); #endif move16(); } @@ -3347,7 +3347,7 @@ void IMDCT_ivas_fx( { FOR( i = 0; i < nz; i++ ) { - old_out_fx[add( add( nz, overlap ), i )] = negate( mult_r( xn_buf_fx[sub( L_frame, add( 1, i ) )], tcx_aldo_window_1_fx[sub( nz, add( 1, i ) )] ) ); + old_out_fx[( ( nz + overlap ) + i )] = negate( mult_r( xn_buf_fx[( L_frame - ( 1 + i ) )], tcx_aldo_window_1_fx[( nz - ( 1 + i ) )] ) ); // Q(-2) move16(); } } @@ -3355,7 +3355,7 @@ void IMDCT_ivas_fx( { FOR( i = 0; i < nz; i++ ) { - old_out_fx[add( add( nz, overlap ), i )] = mult_r( xn_buf_fx[sub( L_frame, add( 1, i ) )], tcx_aldo_window_1_fx[sub( nz, add( 1, i ) )] ); + old_out_fx[( ( nz + overlap ) + i )] = mult_r( xn_buf_fx[( L_frame - ( 1 + i ) )], tcx_aldo_window_1_fx[( nz - ( 1 + i ) )] ); // Q(-2) move16(); } } @@ -3378,41 +3378,41 @@ void IMDCT_ivas_fx( { IF( FB_flag != 0 ) { - FOR( i = 0; i < shr( tcx_mdct_window_half_length, 1 ); i++ ) + FOR( i = 0; i < ( tcx_mdct_window_half_length / 2 ); i++ ) { - xn_buf_fx[sub( add( i, shr( overlap, 1 ) ), tcx_offset )] = mult_r( xn_buf_fx[sub( add( i, shr( overlap, 1 ) ), tcx_offset )], tcx_mdct_window_half_fx[i].v.im ); - xn_buf_fx[sub( add( i, shr( overlap, 1 ) ), tcx_offset )] = add_sat( xn_buf_fx[sub( add( i, shr( overlap, 1 ) ), 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 ) ); + 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[sub( add( i, shr( overlap, 1 ) ), tcx_offset )] = mult_r( xn_buf_fx[sub( add( i, shr( overlap, 1 ) ), tcx_offset )], tcx_mdct_window_half_fx[sub( tcx_mdct_window_half_length, add( 1, i ) )].v.re ); - xn_buf_fx[sub( add( i, shr( overlap, 1 ) ), tcx_offset )] = add_sat( xn_buf_fx[sub( add( i, shr( overlap, 1 ) ), tcx_offset )], mult_r( mult_r( hTcxDec->syn_OverlFB[i], tcx_mdct_window_half_fx[sub( tcx_mdct_window_half_length, add( 1, i ) )].v.im ), tcx_mdct_window_half_fx[sub( tcx_mdct_window_half_length, add( 1, i ) )].v.im ) ); + 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 < shr( tcx_mdct_window_half_length, 1 ); i++ ) + FOR( i = 0; i < ( tcx_mdct_window_half_length / 2 ); i++ ) { - xn_buf_fx[sub( add( i, shr( overlap, 1 ) ), tcx_offset )] = mult_r( xn_buf_fx[sub( add( i, shr( overlap, 1 ) ), tcx_offset )], tcx_mdct_window_half_fx[i].v.im ); + 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 ); #ifdef BASOP_NOGLOB - xn_buf_fx[sub( add( i, shr( overlap, 1 ) ), tcx_offset )] = add_sat( xn_buf_fx[sub( add( i, shr( overlap, 1 ) ), 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 ) ); + 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) #else - xn_buf_fx[sub( add( i, shr( overlap, 1 ) ), tcx_offset )] = add( xn_buf_fx[sub( add( i, shr( overlap, 1 ) ), 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 ) ); + xn_buf_fx[( ( i + ( overlap / 2 ) ) - tcx_offset )] = add( 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 ) ); #endif move16(); move16(); } FOR( ; i < tcx_mdct_window_half_length; i++ ) { - xn_buf_fx[sub( add( i, shr( overlap, 1 ) ), tcx_offset )] = mult_r( xn_buf_fx[sub( add( i, shr( overlap, 1 ) ), tcx_offset )], tcx_mdct_window_half_fx[sub( tcx_mdct_window_half_length, add( 1, i ) )].v.re ); + 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 ); #ifdef BASOP_NOGLOB - xn_buf_fx[sub( add( i, shr( overlap, 1 ) ), tcx_offset )] = add_sat( xn_buf_fx[sub( add( i, shr( overlap, 1 ) ), tcx_offset )], mult_r( mult_r( hTcxDec->syn_Overl[i], tcx_mdct_window_half_fx[sub( tcx_mdct_window_half_length, add( 1, i ) )].v.im ), tcx_mdct_window_half_fx[sub( tcx_mdct_window_half_length, add( 1, 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[( 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) #else - xn_buf_fx[sub( add( i, shr( overlap, 1 ) ), tcx_offset )] = add( xn_buf_fx[sub( add( i, shr( overlap, 1 ) ), tcx_offset )], mult_r( mult_r( hTcxDec->syn_Overl[i], tcx_mdct_window_half_fx[sub( tcx_mdct_window_half_length, add( 1, i ) )].v.im ), tcx_mdct_window_half_fx[sub( tcx_mdct_window_half_length, add( 1, i ) )].v.im ) ); + xn_buf_fx[( ( i + ( overlap / 2 ) ) - tcx_offset )] = add( 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 ) ); #endif move16(); move16(); @@ -3536,7 +3536,16 @@ void init_tcx_info_fx( } ELSE { - IGFDecUpdateInfo_ivas_fx( st->hIGFDec, frame_cnt, ( st->last_core == ACELP_CORE || ( *left_rect && st->bfi ) ) ? IGF_GRID_LB_TRAN : IGF_GRID_LB_NORM ); + test(); + test(); + IF( st->last_core == ACELP_CORE || ( *left_rect && st->bfi ) ) + { + IGFDecUpdateInfo_ivas_fx( st->hIGFDec, frame_cnt, IGF_GRID_LB_TRAN ); + } + ELSE + { + IGFDecUpdateInfo_ivas_fx( st->hIGFDec, frame_cnt, IGF_GRID_LB_NORM ); + } } } } @@ -3593,6 +3602,7 @@ void decoder_tcx_IGF_mono_fx( test(); IF( NE_16( L_frame, shr( st->L_frame, 1 ) ) && st->tcxonly ) { + test(); test(); IF( EQ_16( st->last_core, ACELP_CORE ) || ( left_rect && bfi ) ) { @@ -3664,7 +3674,7 @@ void decoder_tcx_IGF_stereo_fx( FOR( sfb = 0; sfb < sfbConf->sfbCnt; sfb++ ) { - set16_fx( &coreMsMask[sfbConf->sfbOffset[sfb]], ms_mask[k][sfb], sfbConf->sfbOffset[sfb + 1] - sfbConf->sfbOffset[sfb] ); + set16_fx( &coreMsMask[sfbConf->sfbOffset[sfb]], ms_mask[k][sfb], sub( sfbConf->sfbOffset[sfb + 1], sfbConf->sfbOffset[sfb] ) ); } test(); @@ -3756,10 +3766,10 @@ void decoder_tcx_IGF_stereo_fx( void decoder_tcx_ivas_fx( Decoder_State *st, Word16 prm[], - Word16 A_fx[], - Word16 Aind[], - Word16 synth_fx[], - Word16 synthFB_fx[], + Word16 A_fx[], // Q: 14 - norm_s(A_fx[0]) + Word16 Aind[], // Q: 14 - norm_s(Aind[0]) + Word16 synth_fx[], // Q_syn + Word16 synthFB_fx[], // Q_syn const Word16 bfi, const Word16 frame_cnt, const Word16 sba_dirac_stereo_flag ) @@ -4038,9 +4048,16 @@ void decoder_tcx_invQ_fx( prm_sqQ = prm_target + 1; move16(); - tcx_arith_decode_envelope_ivas_fx( st, x, x_e, L_frame, L_spec, Aind, *prm_target, prm_sqQ, (Word16) NE_16( st->last_core_from_bs, ACELP_CORE ), prm_hm, /* HM parameter area */ hTcxDec->tcx_hm_LtpPitchLag, &arith_bits, &signaling_bits, ( st->bwidth > WB ) ? 1 : 0 ); + IF( GT_32( st->bwidth, WB ) ) + { + tcx_arith_decode_envelope_ivas_fx( st, x, x_e, L_frame, L_spec, Aind, *prm_target, prm_sqQ, (Word16) NE_16( st->last_core_from_bs, ACELP_CORE ), prm_hm, /* HM parameter area */ hTcxDec->tcx_hm_LtpPitchLag, &arith_bits, &signaling_bits, 1 ); + } + ELSE + { + tcx_arith_decode_envelope_ivas_fx( st, x, x_e, L_frame, L_spec, Aind, *prm_target, prm_sqQ, (Word16) NE_16( st->last_core_from_bs, ACELP_CORE ), prm_hm, /* HM parameter area */ hTcxDec->tcx_hm_LtpPitchLag, &arith_bits, &signaling_bits, 0 ); + } - hTcxDec->resQBits[frame_cnt] = *prm_target - arith_bits; + hTcxDec->resQBits[frame_cnt] = sub( *prm_target, arith_bits ); move16(); /* Noise filling seed */ @@ -4098,7 +4115,7 @@ void decoder_tcx_invQ_fx( move16(); } - FOR( i = start_zeroing; i < max( L_frame, L_frameTCX ); i++ ) + FOR( i = start_zeroing; i < s_max( L_frame, L_frameTCX ); i++ ) { x[i] = 0; move32(); @@ -4171,7 +4188,7 @@ void decoder_tcx_invQ_fx( hTcxDec->old_gaintcx_bfi_e = *gain_tcx_e; move16(); - hTcxDec->cummulative_damping_tcx = MAX16B; + hTcxDec->cummulative_damping_tcx = MAX16B; // 1 in Q15 move16(); } ELSE /* bfi = 1 */ @@ -4211,7 +4228,7 @@ void decoder_tcx_invQ_fx( move16(); } - hTcxDec->damping = ONE_IN_Q14; + hTcxDec->damping = ONE_IN_Q14; // Q14 move16(); } ELSE @@ -4257,7 +4274,7 @@ void decoder_tcx_invQ_fx( gamma = add( mult_r( hTcxDec->cummulative_damping_tcx, sub( gamma1, MAX16B ) ), MAX16B ); } - IF( st->element_mode != IVAS_CPE_MDCT ) + IF( NE_16( st->element_mode, IVAS_CPE_MDCT ) ) { weight_a_fx( A, Ap, gamma, M ); lpc2mdct_2( Ap, M, NULL, NULL, gainlpc2, gainlpc2_e, FDNS_NPTS ); @@ -4295,7 +4312,7 @@ void decoder_tcx_invQ_fx( move16(); tmp32 = Sqrt32( tmp32, &st->last_gain_syn_deemph_e ); #ifdef BASOP_NOGLOB - st->last_gain_syn_deemph = round_fx_o( tmp32, &Overflow ); + st->last_gain_syn_deemph = round_fx_o( tmp32, &Overflow ); // Q15 #else last_gain_syn_deemph_fx = round_fx( tmp32 ); #endif @@ -4689,7 +4706,7 @@ void decoder_tcx_noisefilling_fx( } /* get the starting location of the subframe in the frame */ - if ( EQ_16( st->core, TCX_10_CORE ) ) + IF( EQ_16( st->core, TCX_10_CORE ) ) { st->hPlcInfo->subframe = extract_l( L_mult0( frame_cnt, L_frameTCX_glob ) ); move16(); @@ -4904,7 +4921,7 @@ void decoder_tcx_noisefilling_fx( } } - if ( st->igf ) + IF( st->igf ) { *st->hIGFDec->igfData.igfInfo.nfSeed = extract_l( L_add( L_mult0( nf_seed, 31821 ), 13849 ) ); move16(); diff --git a/lib_dec/decision_matrix_dec_fx.c b/lib_dec/decision_matrix_dec_fx.c index 66c7440b1..5d9beccff 100644 --- a/lib_dec/decision_matrix_dec_fx.c +++ b/lib_dec/decision_matrix_dec_fx.c @@ -20,9 +20,9 @@ #ifdef IVAS_FLOAT_FIXED void decision_matrix_dec_fx( Decoder_State *st, /* i/o: decoder state structure */ - Word16 *sharpFlag, /* o : formant sharpening flag */ - Word16 *hq_core_type, /* o : HQ core type */ - Word16 *core_switching_flag /* o : ACELP->HQ switching frame flag */ + Word16 *sharpFlag, /* o : formant sharpening flag Q0 */ + Word16 *hq_core_type, /* o : HQ core type Q0 */ + Word16 *core_switching_flag /* o : ACELP->HQ switching frame flag Q0 */ ) { Word16 start_idx; @@ -60,24 +60,24 @@ void decision_matrix_dec_fx( ELSE { test(); - IF( EQ_32( st->total_brate, FRAME_NO_DATA ) || EQ_32( st->total_brate, SID_2k40 ) ) + IF( ( st->total_brate == FRAME_NO_DATA ) || EQ_32( st->total_brate, SID_2k40 ) ) { st->core = ACELP_CORE; move16(); st->core_brate = st->total_brate; move32(); - IF( NE_32( st->total_brate, FRAME_NO_DATA ) ) + IF( st->total_brate != FRAME_NO_DATA ) { - st->cng_type = get_next_indice_fx( st, 1 ); + st->cng_type = get_next_indice_fx( st, 1 ); // Q0 - IF( EQ_16( st->cng_type, LP_CNG ) ) + IF( st->cng_type == LP_CNG ) { st->L_frame = L_FRAME; move16(); - tmp16 = get_next_indice_fx( st, 1 ); - IF( EQ_16( tmp16, 1 ) ) + tmp16 = get_next_indice_fx( st, 1 ); // Q0 + if ( EQ_16( tmp16, 1 ) ) { st->L_frame = L_FRAME16k; move16(); @@ -85,14 +85,14 @@ void decision_matrix_dec_fx( } ELSE { - st->bwidth = get_next_indice_fx( st, 2 ); + st->bwidth = get_next_indice_fx( st, 2 ); // Q0 - tmp16 = get_next_indice_fx( st, 1 ); + tmp16 = get_next_indice_fx( st, 1 ); // Q0 move16(); st->L_frame = L_FRAME16k; move16(); - IF( tmp16 == 0 ) + if ( tmp16 == 0 ) { st->L_frame = L_FRAME; move16(); @@ -101,7 +101,7 @@ void decision_matrix_dec_fx( } test(); - IF( GE_32( st->output_Fs, 32000 ) && GE_16( st->bwidth, SWB ) ) + if ( GE_32( st->output_Fs, 32000 ) && GE_16( st->bwidth, SWB ) ) { st->extl = SWB_CNG; move16(); @@ -110,7 +110,7 @@ void decision_matrix_dec_fx( test(); test(); test(); - IF( EQ_32( st->total_brate, FRAME_NO_DATA ) && st->prev_bfi && !st->bfi && GT_16( st->L_frame, L_FRAME16k ) ) + if ( ( st->total_brate == FRAME_NO_DATA ) && st->prev_bfi && !st->bfi && GT_16( st->L_frame, L_FRAME16k ) ) { st->L_frame = st->last_CNG_L_frame; move16(); @@ -128,23 +128,27 @@ void decision_matrix_dec_fx( move32(); st->L_frame = L_FRAME; move16(); - st->fscale = sr2fscale_fx( INT_FS_FX ); + st->fscale = sr2fscale_fx( INT_FS_FX ); // Q0 move16(); IF( st->ini_frame == 0 ) { /* avoid switching of internal ACELP Fs in the very first frame */ st->last_L_frame = st->L_frame; + move16(); st->last_core = st->core; + move16(); st->last_core_brate = st->core_brate; + move32(); st->last_extl = st->extl; + move16(); } st->vbr_hw_BWE_disable_dec = 1; move16(); - get_next_indice_fx( st, 1 ); + get_next_indice_fx( st, 1 ); // Q0 - ppp_nelp_mode = get_next_indice_fx( st, 2 ); + ppp_nelp_mode = get_next_indice_fx( st, 2 ); // Q0 /* 0 - PPP_NB, 1 - PPP_WB, 2 - NELP_NB, 3 - NELP_WB */ IF( ppp_nelp_mode == 0 ) @@ -201,11 +205,11 @@ void decision_matrix_dec_fx( ELSE IF( GE_32( st->total_brate, ACELP_24k40 ) && LE_32( st->total_brate, ACELP_64k ) ) { /* read the ACELP/HQ core selection bit */ - temp_core = get_next_indice_fx( st, 1 ); + temp_core = get_next_indice_fx( st, 1 ); // Q0 st->core = HQ_CORE; move16(); - IF( temp_core == 0 ) + if ( temp_core == 0 ) { st->core = ACELP_CORE; move16(); @@ -217,7 +221,7 @@ void decision_matrix_dec_fx( * Read ACELP signaling bits from the bitstream *-----------------------------------------------------------------*/ - IF( EQ_16( st->core, ACELP_CORE ) ) + IF( st->core == ACELP_CORE ) { /* find the section in the ACELP signaling table corresponding to bitrate */ start_idx = 0; @@ -231,7 +235,7 @@ void decision_matrix_dec_fx( move16(); start_idx = 0; move16(); - break; + BREAK; } } @@ -242,7 +246,7 @@ void decision_matrix_dec_fx( nBits = extract_l( acelp_sig_tbl[start_idx] ); start_idx = add( start_idx, 1 ); - start_idx = add( start_idx, get_next_indice_fx( st, nBits ) ); + start_idx = add( start_idx, get_next_indice_fx( st, nBits ) ); // Q0 IF( GE_16( start_idx, MAX_ACELP_SIG ) ) { ind = 0; @@ -257,17 +261,19 @@ void decision_matrix_dec_fx( move32(); /* convert signaling indice into signaling information */ - st->coder_type = extract_l( L_and( ind, 0x7L ) ); + st->coder_type = extract_l( L_and( ind, 0x7L ) ); // Q0 IF( EQ_16( st->coder_type, LR_MDCT ) ) { st->core = HQ_CORE; move16(); - st->bwidth = extract_l( L_and( L_shr( ind, 3 ), 0x7L ) ); + st->bwidth = extract_l( L_and( L_shr( ind, 3 ), 0x7L ) ); // Q0 + move16(); } ELSE { - st->bwidth = extract_l( L_and( L_shr( ind, 3 ), 0x7L ) ); - *sharpFlag = extract_l( L_and( L_shr( ind, 6 ), 0x1L ) ); + st->bwidth = extract_l( L_and( L_shr( ind, 3 ), 0x7L ) ); // Q0 + move16(); + *sharpFlag = extract_l( L_and( L_shr( ind, 6 ), 0x1L ) ); // Q0 move16(); } } @@ -292,11 +298,11 @@ void decision_matrix_dec_fx( IF( ( st->BER_detect ) || ( GE_32( ind, 1 << 7 ) ) || ( LE_32( st->total_brate, ACELP_13k20 ) && EQ_16( st->bwidth, FB ) ) || - ( GE_32( st->total_brate, ACELP_32k ) && EQ_16( st->bwidth, NB ) ) || - ( GE_32( st->total_brate, ACELP_32k ) && !( EQ_16( st->coder_type, GENERIC ) || EQ_16( st->coder_type, TRANSITION ) || EQ_16( st->coder_type, INACTIVE ) ) ) || - ( LT_32( st->total_brate, ACELP_13k20 ) && NE_16( st->bwidth, NB ) && EQ_16( st->coder_type, LR_MDCT ) ) || + ( GE_32( st->total_brate, ACELP_32k ) && ( st->bwidth == NB ) ) || + ( GE_32( st->total_brate, ACELP_32k ) && !( EQ_16( st->coder_type, GENERIC ) || EQ_16( st->coder_type, TRANSITION ) || ( st->coder_type == INACTIVE ) ) ) || + ( LT_32( st->total_brate, ACELP_13k20 ) && ( st->bwidth != NB ) && EQ_16( st->coder_type, LR_MDCT ) ) || ( GE_32( st->total_brate, ACELP_13k20 ) && EQ_16( st->coder_type, UNVOICED ) ) || - ( GE_32( st->total_brate, ACELP_13k20 ) && EQ_16( st->coder_type, AUDIO ) && EQ_16( st->bwidth, NB ) ) ) + ( GE_32( st->total_brate, ACELP_13k20 ) && EQ_16( st->coder_type, AUDIO ) && ( st->bwidth == NB ) ) ) { st->BER_detect = 0; move16(); @@ -413,7 +419,7 @@ void decision_matrix_dec_fx( test(); IF( EQ_16( st->core, ACELP_CORE ) && EQ_16( st->bwidth, WB ) && LT_32( st->total_brate, ACELP_9k60 ) ) { - IF( st->vbr_hw_BWE_disable_dec == 0 ) + if ( st->vbr_hw_BWE_disable_dec == 0 ) { st->extl = WB_BWE; move16(); @@ -422,7 +428,7 @@ void decision_matrix_dec_fx( ELSE IF( EQ_16( st->core, ACELP_CORE ) && EQ_16( st->bwidth, WB ) && GE_32( st->total_brate, ACELP_9k60 ) && LE_32( st->total_brate, ACELP_16k40 ) ) { /* read the WB TBE/BWE selection bit */ - tmp16 = get_next_indice_fx( st, 1 ); + tmp16 = get_next_indice_fx( st, 1 ); // Q0 IF( EQ_16( tmp16, 1 ) ) { st->extl = WB_BWE; @@ -444,7 +450,7 @@ void decision_matrix_dec_fx( { st->extl = SWB_BWE_HIGHRATE; move16(); - IF( EQ_16( st->bwidth, FB ) ) + if ( EQ_16( st->bwidth, FB ) ) { st->extl = FB_BWE_HIGHRATE; move16(); @@ -471,7 +477,7 @@ void decision_matrix_dec_fx( move16(); st->extl_brate = SWB_TBE_1k6; move32(); - IF( GE_32( st->total_brate, ACELP_24k40 ) ) + if ( GE_32( st->total_brate, ACELP_24k40 ) ) { st->extl_brate = SWB_TBE_2k8; move32(); @@ -504,6 +510,7 @@ void decision_matrix_dec_fx( /* set core bitrate */ st->core_brate = L_sub( st->total_brate, st->extl_brate ); + move32(); /*-----------------------------------------------------------------* * Read HQ signaling bits from the bitstream @@ -516,11 +523,11 @@ void decision_matrix_dec_fx( IF( NE_16( st->mdct_sw, MODE2 ) ) { /* skip the HQ/TCX core switching flag */ - get_next_indice_tmp_fx( st, 1 ); + get_next_indice_tmp_fx( st, 1 ); // Q0 } /* read ACELP->HQ core switching flag */ - *core_switching_flag = get_next_indice_fx( st, 1 ); + *core_switching_flag = get_next_indice_fx( st, 1 ); // Q0 IF( EQ_16( *core_switching_flag, 1 ) ) { @@ -530,8 +537,8 @@ void decision_matrix_dec_fx( /* read ACELP L_frame info */ st->last_L_frame = L_FRAME16k; move16(); - tmp16 = get_next_indice_fx( st, 1 ); - IF( tmp16 == 0 ) + tmp16 = get_next_indice_fx( st, 1 ); // Q0 + if ( tmp16 == 0 ) { st->last_L_frame = L_FRAME; move16(); @@ -544,7 +551,7 @@ void decision_matrix_dec_fx( /* read/set band-width (needed for different I/O sampling rate support) */ IF( GT_32( st->total_brate, ACELP_16k40 ) ) { - tmp16 = get_next_indice_fx( st, 2 ); + tmp16 = get_next_indice_fx( st, 2 ); // Q0 IF( tmp16 == 0 ) { @@ -574,7 +581,7 @@ void decision_matrix_dec_fx( test(); test(); test(); - IF( ( GE_32( st->total_brate, ACELP_24k40 ) && EQ_16( st->bwidth, NB ) ) || + IF( ( GE_32( st->total_brate, ACELP_24k40 ) && ( st->bwidth == NB ) ) || ( EQ_16( st->core, HQ_CORE ) && LE_32( st->total_brate, LRMDCT_CROSSOVER_POINT ) && EQ_16( st->bwidth, FB ) ) ) { st->bfi = 1; @@ -644,7 +651,7 @@ void decision_matrix_dec_fx( test(); test(); test(); - IF( EQ_32( st->core_brate, FRAME_NO_DATA ) ) + IF( st->core_brate == FRAME_NO_DATA ) { /* prevent "L_frame" changes in CNG segments */ st->L_frame = st->last_L_frame; @@ -670,14 +677,16 @@ void decision_matrix_dec_fx( st->nb_subfr = NB_SUBFR; move16(); - IF( EQ_16( st->L_frame, L_FRAME16k ) ) + if ( EQ_16( st->L_frame, L_FRAME16k ) ) { st->nb_subfr = NB_SUBFR16k; move16(); } #if 1 // def ADD_IVAS_BWE 0> NEEDED for IO with conf_acelp1 st->extl_orig = st->extl; + move16(); st->extl_brate_orig = st->extl_brate; + move32(); #endif test(); IF( EQ_32( st->output_Fs, 8000 ) ) diff --git a/lib_dec/gs_dec_amr_wb_fx.c b/lib_dec/gs_dec_amr_wb_fx.c index d57411ff4..9778acec0 100644 --- a/lib_dec/gs_dec_amr_wb_fx.c +++ b/lib_dec/gs_dec_amr_wb_fx.c @@ -49,9 +49,9 @@ static void gs_dec_amr_wb_fx( const long core_brate, Word16 *seed_tcx, const Wor *-------------------------------------------------------------------*/ static void NoiseFill_fx( - Word16 *exc_diffQ_fx, /* i/o: Noise per band */ - Word16 *seed_tcx, /* i : Seed for noise */ - const Word16 Mbands_gn, /* i : number of bands */ + Word16 *exc_diffQ_fx, /* i/o: Noise per band Q_out*/ + Word16 *seed_tcx, /* i : Seed for noise Q0*/ + const Word16 Mbands_gn, /* i : number of bands Q0*/ const Word16 Q_out /* i : Q of exc_diffQ_fx[] */ ) { @@ -60,16 +60,16 @@ static void NoiseFill_fx( Word16 fact; CurBin = 0; move16(); - fact = shr( 24576 /*0.75f*/, sub( 15, Q_out ) ); + fact = shr( 24576 /*0.75f in Q15*/, sub( 15, Q_out ) ); /* Q_out */ FOR( i_band = 0; i_band < Mbands_gn; i_band++ ) { EndBin = add( CurBin, crit_bins[i_band] ); FOR( ; CurBin < EndBin; CurBin++ ) { - L_temp = L_mult( Random( seed_tcx ), fact ); - L_temp = L_msu( L_temp, exc_diffQ_fx[CurBin], -32768 ); - exc_diffQ_fx[CurBin] = round_fx( L_temp ); + L_temp = L_mult( Random( seed_tcx ), fact ); /* Q15 + Q_out + 1 */ + L_temp = L_msu( L_temp, exc_diffQ_fx[CurBin], -32768 ); /* Q15 + Q_out + 1*/ + exc_diffQ_fx[CurBin] = round_fx( L_temp ); /* Q_out */ move16(); } } @@ -84,9 +84,9 @@ static void NoiseFill_fx( *-------------------------------------------------------------------*/ static void Ener_per_band_fx( - const Word16 exc_diff_fx[], /* i : target signal */ - const Word16 exc_diff_exp, /* i : Exponent of exc_diff_fx */ - Word32 y_gain4_fx[] /* o : Energy per band to quantize Q16 */ + const Word16 exc_diff_fx[], /* i : target signal exp(exc_diff_exp)*/ + const Word16 exc_diff_exp, /* i : Exponent of exc_diff_fx */ + Word32 y_gain4_fx[] /* o : Energy per band to quantize Q16*/ ) { const Word16 *ptr16; @@ -96,29 +96,29 @@ static void Ener_per_band_fx( exp = shl( exc_diff_exp, 1 ); /* To Get 0.01f in Q of (exc_diff_exp-1)^2 */ - L_epsilon = L_shr( 42949673L, sub( 32 + ENER_FX_Q_GUARD * 2, exp ) ); + L_epsilon = L_shr( 42949673L, sub( 32 + ENER_FX_Q_GUARD * 2, exp ) ); /* Q16 */ ptr16 = exc_diff_fx; FOR( j = 0; j < CRIT_NOIS_BAND; j++ ) { - temp = shr( *ptr16++, ENER_FX_Q_GUARD ); - L_temp = L_mac0( L_epsilon, temp, temp ); + temp = shr( *ptr16++, ENER_FX_Q_GUARD ); /* Q15 - exc_diff_exp + Q1 */ + L_temp = L_mac0( L_epsilon, temp, temp ); /* Q16 */ FOR( i = 1; i < crit_bins[j]; i++ ) { - temp = shr( *ptr16++, ENER_FX_Q_GUARD ); - L_temp = L_mac0( L_temp, temp, temp ); + temp = shr( *ptr16++, ENER_FX_Q_GUARD ); /* Q15 - exc_diff_exp + Q1 */ + L_temp = L_mac0( L_temp, temp, temp ); /* Q16 */ } L_temp2 = L_mult0( 1, 6554 ); /* sqrt of 0.01f in Q16*/ IF( L_temp != 0 ) /* avoid executing sqrt of 0 (because a div_s is used to invert and then call inv_sqrt) */ { L_temp2 = Sqrt_Ratio32( L_temp, exp, 1, 0, &i ); #ifdef BASOP_NOGLOB - L_temp2 = L_shr_sat( L_temp2, sub( 15 - ENER_FX_Q_GUARD, i ) ); + L_temp2 = L_shr_sat( L_temp2, sub( 15 - ENER_FX_Q_GUARD, i ) ); /* Q16 */ #else L_temp2 = L_shr( L_temp2, sub( 15 - ENER_FX_Q_GUARD, i ) ); #endif } - y_gain4_fx[j] = L_temp2; + y_gain4_fx[j] = L_temp2; /* Q16 */ move32(); } @@ -133,9 +133,9 @@ static void Ener_per_band_fx( *-------------------------------------------------------------------*/ static void Apply_gain_fx( - Word16 exc_diffQ_fx[], /* i/o: Quantized excitation */ - Word32 L_Ener_per_bd_iQ[], /* i : Target ener per band */ - Word32 L_Ener_per_bd_yQ[] /* i : Ener per band for norm vector */ + Word16 exc_diffQ_fx[], /* i/o: Quantized excitation Qx*/ + Word32 L_Ener_per_bd_iQ[], /* i : Target ener per band Q16*/ + Word32 L_Ener_per_bd_yQ[] /* i : Ener per band for norm vector Qx*/ , const Word16 Q_out ) { @@ -154,11 +154,11 @@ static void Apply_gain_fx( move16(); FOR( i_band = 0; i_band < CRIT_NOIS_BAND; i_band++ ) { - EndBin = add( CurBin, crit_bins[i_band] ); + EndBin = add( CurBin, crit_bins[i_band] ); /* Q0 */ y_gain_exp = norm_l( L_Ener_per_bd_yQ[i_band] ); exp3 = norm_l( L_Ener_per_bd_iQ[i_band] ); /* use 'exp3' as temporary exponent of 'L_Ener_per_bd_iQ[]' */ #ifdef BASOP_NOGLOB - y_gain_fx = round_fx_sat( Div_flt32_flt32( L_shl_sat( L_Ener_per_bd_iQ[i_band], exp3 ), exp3, L_shl_sat( L_Ener_per_bd_yQ[i_band], y_gain_exp ), y_gain_exp, &y_gain_exp ) ); + y_gain_fx = round_fx_sat( Div_flt32_flt32( L_shl_sat( L_Ener_per_bd_iQ[i_band], exp3 ), exp3, L_shl_sat( L_Ener_per_bd_yQ[i_band], y_gain_exp ), y_gain_exp, &y_gain_exp ) ); /* y_gain_exp - 31 + Q_out */ #else y_gain_fx = round_fx( Div_flt32_flt32( L_shl( L_Ener_per_bd_iQ[i_band], exp3 ), exp3, L_shl( L_Ener_per_bd_yQ[i_band], y_gain_exp ), y_gain_exp, &y_gain_exp ) ); #endif @@ -172,9 +172,9 @@ static void Apply_gain_fx( { FOR( ; CurBin < EndBin; CurBin++ ) { - L_temp = L_mult( exc_diffQ_fx[CurBin], y_gain_fx ); - L_temp = L_shr( L_temp, y_gain_exp ); - exc_diffQ_fx[CurBin] = round_fx( L_temp ); + L_temp = L_mult( exc_diffQ_fx[CurBin], y_gain_fx ); /* Q16 + Q_out + y_gain_exp */ + L_temp = L_shr( L_temp, y_gain_exp ); /* Q_out + 16 */ + exc_diffQ_fx[CurBin] = round_fx( L_temp ); /* Q_out */ move16(); } } @@ -190,29 +190,29 @@ static void Apply_gain_fx( *-------------------------------------------------------------------*/ static void normalize_spec_fx( - Word16 fac_up_fx, /* i : Core bitrate (Q8) */ - Word16 fy_norm_fx[], /* i/o: Frequency quantized parameter (Q8) */ - const Word16 L_frame, /* i : Section lenght */ - const Word16 Q_out /* i : Q of fy_norm_fx[] */ + Word16 fac_up_fx, /* i : Core bitrate (Q8)*/ + Word16 fy_norm_fx[], /* i/o: Frequency quantized parameter (Q8)*/ + const Word16 L_frame, /* i : Section lenght Q0*/ + const Word16 Q_out /* i : Q of fy_norm_fx[] */ ) { Word16 idx, j; Word32 L_temp; Word16 temp, exp; - idx = emaximum_fx( 0 /* Exponent is not Important */, fy_norm_fx, L_frame, &L_temp ); + idx = emaximum_fx( 0 /* Exponent is not Important */, fy_norm_fx, L_frame, &L_temp ); /* Q0 */ exp = sub( Q_out, 8 /*Q8 of Fac Up/down*/ ); - temp = Invert16( abs_s( fy_norm_fx[idx] ), &exp ); - L_temp = L_mult( temp, fac_up_fx ); + temp = Invert16( abs_s( fy_norm_fx[idx] ), &exp ); /* Q15 + exp */ + L_temp = L_mult( temp, fac_up_fx ); /* Q15 + exp + Q8 + 1 */ exp = sub( 15, exp ); #ifdef BASOP_NOGLOB - L_temp = L_shl_sat( L_temp, exp ); + L_temp = L_shl_sat( L_temp, exp ); /* Q24 + Q_out */ #else L_temp = L_shl( L_temp, exp ); #endif FOR( j = 0; j < L_frame; j++ ) { - fy_norm_fx[j] = round_fx( Mult_32_16( L_temp, fy_norm_fx[j] ) ); + fy_norm_fx[j] = round_fx( Mult_32_16( L_temp, fy_norm_fx[j] ) ); /* Q_out */ move16(); } @@ -226,16 +226,16 @@ static void normalize_spec_fx( *-------------------------------------------------------------------*/ static void gs_dec_amr_wb_fx( - const long core_brate, /* i : bitrate allocated to the core */ - Word16 *seed_tcx, /* i/o: seed used for noise generation */ - const Word16 dct_in_fx[], /* i : cdt of residual signal */ + const long core_brate, /* i : bitrate allocated to the core Q0*/ + Word16 *seed_tcx, /* i/o: seed used for noise generation Q0*/ + const Word16 dct_in_fx[], /* i : cdt of residual signal Q_dct_in*/ const Word16 Q_dct_in, /* i : Exponent of dct_in_fx */ - Word16 dct_out_fx[], /* o : dct of pitch only excitation */ + Word16 dct_out_fx[], /* o : dct of pitch only excitation Q_dct_out*/ Word16 Q_dct_out, /* o : Exponent of dct_out_fx */ - const Word16 pitch_fx[], /* i : pitch buffer */ - const Word16 voice_fac, /* i : gain pitch Q15 */ - const Word16 clas, /* i : signal frame class */ - const Word16 coder_type /* i : coder type */ + const Word16 pitch_fx[], /* i : pitch buffer Q6*/ + const Word16 voice_fac, /* i : gain pitch Q15*/ + const Word16 clas, /* i : signal frame class Q0*/ + const Word16 coder_type /* i : coder type Q0*/ #ifdef ADD_IVAS_GS_DEC_IMPR , const Word16 VeryLowRateSTflag /* i : Enable the noise enhancement for very low rate stereo generic mode */ @@ -266,7 +266,7 @@ static void gs_dec_amr_wb_fx( FOR( i = 0; i < CRIT_NOIS_BAND; i++ ) { #ifdef BASOP_NOGLOB - temp = s_max( round_fx_sat( Ener_per_bd_iQ_fx[i] ), temp ); + temp = s_max( round_fx_sat( Ener_per_bd_iQ_fx[i] ), temp ); /* Q0 */ #else temp = s_max( round_fx( Ener_per_bd_iQ_fx[i] ), temp ); #endif @@ -278,7 +278,7 @@ static void gs_dec_amr_wb_fx( { FOR( i = 0; i < CRIT_NOIS_BAND; i++ ) { - Ener_per_bd_iQ_fx[i] = Mult_32_16( Ener_per_bd_iQ_fx[i], crit_bins_corr_fx[i] ); + Ener_per_bd_iQ_fx[i] = Mult_32_16( Ener_per_bd_iQ_fx[i], crit_bins_corr_fx[i] ); /* Q16 */ move32(); } } @@ -287,16 +287,16 @@ static void gs_dec_amr_wb_fx( /*--------------------------------------------------------------------------------------* * Find the lenght of the temporal contribution, with a minimum contribution of 1.2kHz *--------------------------------------------------------------------------------------*/ - temp = s_min( pitch_fx[0], pitch_fx[1] ); - temp = s_min( temp, pitch_fx[2] ); - temp = s_min( temp, pitch_fx[3] ); + temp = s_min( pitch_fx[0], pitch_fx[1] ); /* Q6 */ + temp = s_min( temp, pitch_fx[2] ); /* Q6 */ + temp = s_min( temp, pitch_fx[3] ); /* Q6 */ /* etmp14 = 12800.0f/(temp/16.0f)*8.0f */ exp = 6; /* Pitch in Q6*/ move16(); - temp = Invert16( temp, &exp ); - L_temp = L_mult( temp, 12800 ); - L_temp = L_shl( L_temp, sub( 3, exp ) ); /* *8.0f */ + temp = Invert16( temp, &exp ); /* Q15 */ + L_temp = L_mult( temp, 12800 ); /* Q15 */ + L_temp = L_shl( L_temp, sub( 3, exp ) ); /* *8.0f */ /* Q15 */ #ifdef ADD_IVAS_GS_DEC_IMPR test(); test(); @@ -305,27 +305,27 @@ static void gs_dec_amr_wb_fx( if ( GE_32( core_brate, ACELP_12k65 ) ) #endif { - L_temp = L_shl( L_temp, 1 ); + L_temp = L_shl( L_temp, 1 ); /* Q16 */ } /* (Word16)(etmp14+0.5f) */ - mDiff_len = round_fx( L_temp ); + mDiff_len = round_fx( L_temp ); /* Q0 */ temp = 32767; move16(); L_temp = L_deposit_l( 0 ); FOR( i = 0; i < CRIT_NOIS_BAND; i++ ) { - temp2 = sub( crit_bands_loc_fx[i], mDiff_len ); - temp2 = abs_s( temp2 ); + temp2 = sub( crit_bands_loc_fx[i], mDiff_len ); /* Q0 */ + temp2 = abs_s( temp2 ); /* Q0 */ if ( GT_16( temp, temp2 ) ) { - L_temp = L_msu( L_temp, crit_bins[i], -32768 ); + L_temp = L_msu( L_temp, crit_bins[i], -32768 ); /* Q16 */ } - temp = s_min( temp, temp2 ); + temp = s_min( temp, temp2 ); /* Q0 */ } - mDiff_len = s_max( round_fx( L_temp ), BIN_1k2 ); + mDiff_len = s_max( round_fx( L_temp ), BIN_1k2 ); /* Q0 */ #ifdef ADD_IVAS_GS_DEC_IMPR @@ -334,12 +334,12 @@ static void gs_dec_amr_wb_fx( Copy( dct_in_fx, exc_diffQ, L_FRAME ); /* normalization of the spectrum and noise fill */ - normalize_spec_fx( 1 * 256, exc_diffQ + mDiff_len, L_FRAME - mDiff_len, NORMALIZE_SPECS_Q_OUT ); + normalize_spec_fx( 1 * 256, exc_diffQ + mDiff_len, sub( L_FRAME, mDiff_len ), NORMALIZE_SPECS_Q_OUT ); } ELSE #endif { - Copy( dct_in_fx, exc_diffQ_fx, mDiff_len ); + Copy( dct_in_fx, exc_diffQ_fx, mDiff_len ); /* Q_dct_in */ set16_fx( exc_diffQ_fx + mDiff_len, 0, sub( L_FRAME, mDiff_len ) ); /* normalization of the spectrum and noise fill*/ @@ -356,7 +356,7 @@ static void gs_dec_amr_wb_fx( * Compute tilt factor and amplify HF accordingly *--------------------------------------------------------------------------------------*/ - temp = mult_r( sub( 32767, voice_fac ), 16384 ); /* Q15 */ + temp = mult_r( sub( 32767 /* 1.0 in Q15 */, voice_fac ), 16384 /* 0.5 in Q15 */ ); /* Q15 */ FOR( i = 240; i < L_FRAME; i++ ) { temp2 = msu_r( -7680 * 65536, -17564, shl( i, 6 ) ); /*-15 in Q9; -0.067 in Q18 and i in Q6= Q9 */ @@ -374,7 +374,7 @@ static void gs_dec_amr_wb_fx( * Copy to the output vector *--------------------------------------------------------------------------------------*/ - Copy( exc_diffQ_fx, dct_out_fx, L_FRAME ); + Copy( exc_diffQ_fx, dct_out_fx, L_FRAME ); /* Q_dct_out */ return; } @@ -386,24 +386,24 @@ static void gs_dec_amr_wb_fx( * unvoiced and audio signals (used only in AMR-WB IO mode) *-------------------------------------------------------------------*/ void improv_amr_wb_gs_fx( - const Word16 clas, /* i : signal frame class */ - const Word16 coder_type, /* i : coder type */ - const Word32 core_brate, /* i : bitrate allocated to the core */ - Word16 *seed_tcx, /* i/o: Seed used for noise generation */ - Word16 *old_Aq_fx, /* i/o: old LPC filter coefficient */ - Word16 *mem_syn2_fx, /* i/o: synthesis memory */ - const Word16 lt_voice_fac_fx, /* i/o: long term voice factor Q14 */ - const Word16 locattack, /* i : Flag for a detected attack */ - Word16 *Aq_fx, /* i/o: Decoded LP filter coefficient */ - Word16 *exc2_fx, /* i/o: Decoded complete excitation */ - const Word16 Q_exc2, /* i : Exponent of Exc2 */ - Word16 *mem_tmp_fx, /* i/o: synthesis temporary memory */ - Word16 *syn_fx, /* o: Decoded synthesis to be updated */ - const Word16 Q_syn, /* i : Synthesis scaling Q0 */ - const Word16 *pitch_buf_fx, /* i : Decoded pitch buffer Q6 */ - const Word16 Last_ener_fx, /* i : Last energy (Q8) */ - const Word16 rate_switching_reset, /* i : rate switching reset flag */ - const Word16 last_coder_type /* i : Last coder_type */ + const Word16 clas, /* i : signal frame class Q0*/ + const Word16 coder_type, /* i : coder type Q0*/ + const Word32 core_brate, /* i : bitrate allocated to the core Q0*/ + Word16 *seed_tcx, /* i/o: Seed used for noise generation Q0*/ + Word16 *old_Aq_fx, /* i/o: old LPC filter coefficient q_old_Aq*/ + Word16 *mem_syn2_fx, /* i/o: synthesis memory Q_syn*/ + const Word16 lt_voice_fac_fx, /* i/o: long term voice factor Q14*/ + const Word16 locattack, /* i : Flag for a detected attack Q0*/ + Word16 *Aq_fx, /* i/o: Decoded LP filter coefficient q_Aq*/ + Word16 *exc2_fx, /* i/o: Decoded complete excitation Q_exc2*/ + const Word16 Q_exc2, /* i : Exponent of Exc2 */ + Word16 *mem_tmp_fx, /* i/o: synthesis temporary memory Q_syn*/ + Word16 *syn_fx, /* o: Decoded synthesis to be updated Q_syn*/ + const Word16 Q_syn, /* i : Synthesis scaling */ + const Word16 *pitch_buf_fx, /* i : Decoded pitch buffer Q6*/ + const Word16 Last_ener_fx, /* i : Last energy (Q8) Q0*/ + const Word16 rate_switching_reset, /* i : rate switching reset flag Q0*/ + const Word16 last_coder_type /* i : Last coder_type Q0*/ #ifdef ADD_IVAS_GS_DEC_IMPR , const Word16 VeryLowRateSTflag /* i : Enable the noise enhancement for very low rate stereo generic mode */ @@ -449,7 +449,7 @@ void improv_amr_wb_gs_fx( * generic audio sound * LP filter smoothing for inactive parts *------------------------------------------------------------*/ - *seed_tcx = extract_l( L_mult0( pitch_buf_fx[0], pitch_buf_fx[3] ) ); + *seed_tcx = extract_l( L_mult0( pitch_buf_fx[0], pitch_buf_fx[3] ) ); /* Q0 */ move16(); /* last_coder_type == UNVOICED should be understand as INACTIVE, but it is forced to UNVOICED in update_dec */ test(); @@ -460,36 +460,36 @@ void improv_amr_wb_gs_fx( FOR( i = 0; i < NB_SUBFR; i++ ) { - Copy( Aq_fx, Aq_orig, NB_SUBFR * ( M + 1 ) ); + Copy( Aq_fx, Aq_orig, NB_SUBFR * ( M + 1 ) ); /* q_Aq */ - exp_a = norm_s( Aq_fx[imult1616( i, ( M + 1 ) )] ); - exp_b = norm_s( old_Aq_fx[imult1616( i, ( M + 1 ) )] ); + exp_a = norm_s( Aq_fx[i * ( M + 1 )] ); + exp_b = norm_s( old_Aq_fx[i * ( M + 1 )] ); exp_diff = sub( exp_a, exp_b ); IF( exp_diff > 0 ) { - Scale_sig( &old_Aq_fx[imult1616( i, ( M + 1 ) )], ( M + 1 ), negate( exp_diff ) ); + Scale_sig( &old_Aq_fx[i * ( M + 1 )], ( M + 1 ), negate( exp_diff ) ); /* exp_b */ } ELSE { - Scale_sig( &Aq_fx[imult1616( i, ( M + 1 ) )], ( M + 1 ), exp_diff ); + Scale_sig( &Aq_fx[i * ( M + 1 )], ( M + 1 ), exp_diff ); /* exp_a */ } - FOR( j = imult1616( i, ( M + 1 ) ); j < imult1616( add( i, 1 ), ( M + 1 ) ); j++ ) + FOR( j = i * ( M + 1 ); j < ( i + 1 ) * ( M + 1 ); j++ ) { - Aq_fx[j] = round_fx( L_mac( L_mult( ALP_FX, old_Aq_fx[j] ), MALP_FX, Aq_fx[j] ) ); + Aq_fx[j] = round_fx( L_mac( L_mult( ALP_FX, old_Aq_fx[j] ), MALP_FX, Aq_fx[j] ) ); /* q_Aq */ move16(); } } /* check the smoothed LP filter stability */ - enr_LP_old = Enr_1_Az_fx( old_Aq_fx, L_SUBFR ); + enr_LP_old = Enr_1_Az_fx( old_Aq_fx, L_SUBFR ); /* Q3 */ Overflow = 0; move16(); FOR( i = 0; i < NB_SUBFR; i++ ) { #ifdef BASOP_NOGLOB - enr_LP_new = Enr_1_Az_fx_o( Aq_fx + imult1616( i, ( M + 1 ) ), L_SUBFR, &Overflow ); + enr_LP_new = Enr_1_Az_fx_o( Aq_fx + imult1616( i, ( M + 1 ) ), L_SUBFR, &Overflow ); /* Q3 */ #else enr_LP_new = Enr_1_Az_fx( Aq_fx + i * ( M + 1 ), L_SUBFR ); #endif @@ -497,14 +497,14 @@ void improv_amr_wb_gs_fx( IF( GT_16( shr( enr_LP_new, 7 ), enr_LP_old ) || Overflow ) { /* filter is unstable, do not modify the excitation */ - Copy( Aq_orig, Aq_fx, NB_SUBFR * ( M + 1 ) ); + Copy( Aq_orig, Aq_fx, NB_SUBFR * ( M + 1 ) ); /* q_Aq */ Overflow = 0; move16(); return; } - enr_LP_old = enr_LP_new; + enr_LP_old = enr_LP_new; /* Q3 */ move16(); } } @@ -527,7 +527,7 @@ void improv_amr_wb_gs_fx( * Redo core synthesis at 12k8 Hz with the modified excitation *------------------------------------------------------------*/ - Copy( mem_tmp_fx, mem_syn2_fx, M ); + Copy( mem_tmp_fx, mem_syn2_fx, M ); /* Q_syn */ syn_12k8_fx( L_FRAME, Aq_fx, exc2_fx, syn_fx, mem_syn2_fx, 1, Q_exc2, Q_syn ); } diff --git a/lib_dec/gs_dec_fx.c b/lib_dec/gs_dec_fx.c index 9a10f0862..7af4b5c40 100644 --- a/lib_dec/gs_dec_fx.c +++ b/lib_dec/gs_dec_fx.c @@ -34,14 +34,14 @@ /*==========================================================================*/ void decod_audio_fx( Decoder_State *st_fx, /* i/o: decoder static memory */ - Word16 dct_epit[], /* o : GSC excitation in DCT domain */ - const Word16 *Aq, /* i : LP filter coefficient */ - Word16 *pitch_buf, /* o : floating pitch values for each subframe */ - Word16 *voice_factors, /* o : voicing factors */ - Word16 *exc, /* i/o: adapt. excitation exc */ - Word16 *exc2, /* i/o: adapt. excitation/total exc */ - Word16 *bwe_exc, /* o : excitation for SWB TBE */ - Word16 *lsf_new /* i : ISFs at the end of the frame */ + Word16 dct_epit[], /* o : GSC excitation in DCT domain Qx*/ + const Word16 *Aq, /* i : LP filter coefficient Q12*/ + Word16 *pitch_buf, /* o : floating pitch values for each subframe Q6*/ + Word16 *voice_factors, /* o : voicing factors Q15*/ + Word16 *exc, /* i/o: adapt. excitation exc Q_exc*/ + Word16 *exc2, /* i/o: adapt. excitation/total exc Q_exc*/ + Word16 *bwe_exc, /* o : excitation for SWB TBE Q_exc*/ + Word16 *lsf_new /* i : ISFs at the end of the frame Qx*/ , Word16 *gain_buf /*Q14*/ ) @@ -71,7 +71,7 @@ void decod_audio_fx( move16(); /* decode GSC attack flag (used to reduce possible pre-echo) */ - gsc_attack_flag = (Word16) get_next_indice_fx( st_fx, 1 ); + gsc_attack_flag = (Word16) get_next_indice_fx( st_fx, 1 ); /* Q0 */ move16(); /* decode GSC SWB speech flag */ @@ -83,7 +83,7 @@ void decod_audio_fx( ( st_fx->element_mode > EVS_MONO && st_fx->total_brate > MIN_BRATE_GSC_NOISY_FLAG && st_fx->bwidth >= SWB && !st_fx->flag_ACELP16k ) ) ) ) #endif { - st_fx->GSC_noisy_speech = (Word16) get_next_indice_fx( st_fx, 1 ); + st_fx->GSC_noisy_speech = (Word16) get_next_indice_fx( st_fx, 1 ); /* Q0 */ move16(); } @@ -92,9 +92,9 @@ void decod_audio_fx( test(); IF( st_fx->GSC_noisy_speech && LT_16( st_fx->bwidth, SWB ) && st_fx->GSC_IVAS_mode == 0 ) { - st_fx->BER_detect = 1; + st_fx->BER_detect = 1; /* Q0 */ move16(); - st_fx->GSC_noisy_speech = 0; + st_fx->GSC_noisy_speech = 0; /* Q0 */ move16(); } /* set bit-allocation */ @@ -114,11 +114,11 @@ void decod_audio_fx( IF( EQ_16( st_fx->GSC_noisy_speech, 1 ) ) #endif { - nb_subfr = NB_SUBFR; + nb_subfr = NB_SUBFR; /* Q0 */ move16(); hGSCDec->cor_strong_limit = 0; move16(); - hGSCDec->noise_lev = NOISE_LEVEL_SP3; + hGSCDec->noise_lev = NOISE_LEVEL_SP3; /* Q0 */ move16(); #ifdef ADD_LRTD if ( st_fx->GSC_IVAS_mode >= 1 ) @@ -144,12 +144,12 @@ void decod_audio_fx( { IF( LE_32( st_fx->core_brate, ACELP_8k00 ) ) { - hGSCDec->noise_lev = add( (Word16) get_next_indice_fx( st_fx, 2 ), NOISE_LEVEL_SP2 ); + hGSCDec->noise_lev = add( (Word16) get_next_indice_fx( st_fx, 2 ), NOISE_LEVEL_SP2 ); /* Q0 */ move16(); } ELSE { - hGSCDec->noise_lev = add( (Word16) get_next_indice_fx( st_fx, 3 ), NOISE_LEVEL_SP0 ); + hGSCDec->noise_lev = add( (Word16) get_next_indice_fx( st_fx, 3 ), NOISE_LEVEL_SP0 ); /* Q0 */ move16(); } @@ -165,7 +165,7 @@ void decod_audio_fx( else #endif { - hGSCDec->cor_strong_limit = 1; + hGSCDec->cor_strong_limit = 1; /* Q0 */ move16(); nb_subfr = SWNB_SUBFR; move16(); @@ -180,12 +180,12 @@ void decod_audio_fx( nbits = 2; } #endif - nb_frame_flg = (Word16) get_next_indice_fx( st_fx, nbits ); + nb_frame_flg = (Word16) get_next_indice_fx( st_fx, nbits ); /* Q0 */ move16(); IF( s_and( nb_frame_flg, 0x1 ) == 0 ) { - nb_subfr = 2 * SWNB_SUBFR; + nb_subfr = 2 * SWNB_SUBFR; /* Q0 */ move16(); hGSCDec->cor_strong_limit = 0; move16(); @@ -216,29 +216,29 @@ void decod_audio_fx( IF( LT_32( st_fx->core_brate, CFREQ_BITRATE ) ) { - nbits = 3; + nbits = 3; /* Q0 */ move16(); test(); if ( LT_32( st_fx->core_brate, ACELP_9k60 ) && st_fx->coder_type == INACTIVE ) { - nbits = 1; + nbits = 1; /* Q0 */ move16(); } } ELSE { - nbits = 4; + nbits = 4; /* Q0 */ move16(); } test(); IF( LT_32( st_fx->core_brate, ACELP_9k60 ) && st_fx->coder_type != INACTIVE ) { - pit_band_idx = 1; + pit_band_idx = 1; /* Q0 */ move16(); } ELSE { - pit_band_idx = (Word16) get_next_indice_fx( st_fx, nbits ); + pit_band_idx = (Word16) get_next_indice_fx( st_fx, nbits ); /* Q0 */ move16(); } @@ -246,26 +246,26 @@ void decod_audio_fx( { IF( LT_32( st_fx->core_brate, ACELP_9k60 ) ) { - pit_band_idx = 7 + BAND1k2; - move16(); /* At low rate, if pitch model is chosen, then for to be use on extented and constant frequency range */ + pit_band_idx = 7 + BAND1k2; /* Q0 */ + move16(); /* At low rate, if pitch model is chosen, then for to be use on extented and constant frequency range */ } ELSE { - pit_band_idx = add( pit_band_idx, BAND1k2 ); + pit_band_idx = add( pit_band_idx, BAND1k2 ); /* Q0 */ } /* detect bit errors in the bitstream */ IF( GT_16( pit_band_idx, 13 ) ) /* The maximum decodable index is 10 + BAND1k2 (3) = 13 */ { - pit_band_idx = 13; + pit_band_idx = 13; /* Q0 */ move16(); - st_fx->BER_detect = 1; + st_fx->BER_detect = 1; /* Q0 */ move16(); } - Diff_len = mfreq_loc_div_25[pit_band_idx]; + Diff_len = mfreq_loc_div_25[pit_band_idx]; /* Q0 */ move16(); } - hGSCDec->Last_GSC_pit_band_idx = pit_band_idx; + hGSCDec->Last_GSC_pit_band_idx = pit_band_idx; /* Q0 */ move16(); @@ -288,7 +288,7 @@ void decod_audio_fx( #endif { Word16 indice; - nbits = Es_pred_bits_tbl[BIT_ALLOC_IDX_fx( st_fx->core_brate, GENERIC, -1, -1 )]; + nbits = Es_pred_bits_tbl[BIT_ALLOC_IDX_fx( st_fx->core_brate, GENERIC, -1, -1 )]; /* Q0 */ move16(); if ( st_fx->element_mode > EVS_MONO ) { @@ -296,7 +296,7 @@ void decod_audio_fx( move16(); } - indice = get_next_indice_fx( st_fx, nbits ); + indice = get_next_indice_fx( st_fx, nbits ); /* Q0 */ Es_pred_dec_fx( &Es_pred, indice, nbits, 0 ); } @@ -312,28 +312,28 @@ void decod_audio_fx( IF( LT_16( low_pit, 64 ) ) { - pit_band_idx = 9 + BAND1k2; + pit_band_idx = 9 + BAND1k2; /* Q0 */ move16(); if ( st_fx->bwidth == NB ) { - pit_band_idx = 7 + BAND1k2; + pit_band_idx = 7 + BAND1k2; /* Q0 */ move16(); } } ELSE IF( LT_16( low_pit, 128 ) ) { - pit_band_idx = 5 + BAND1k2; + pit_band_idx = 5 + BAND1k2; /* Q0 */ move16(); } ELSE { - pit_band_idx = 3 + BAND1k2; + pit_band_idx = 3 + BAND1k2; /* Q0 */ move16(); } - Diff_len = mfreq_loc_div_25[pit_band_idx]; + Diff_len = mfreq_loc_div_25[pit_band_idx]; /* Q0 */ move16(); - hGSCDec->Last_GSC_pit_band_idx = pit_band_idx; + hGSCDec->Last_GSC_pit_band_idx = pit_band_idx; /* Q0 */ move16(); } @@ -346,18 +346,18 @@ void decod_audio_fx( * Reset unvaluable part of the adaptive (pitch) excitation contribution *---------------------------------------------------------------*/ - max_len = sub( st_fx->L_frame, Diff_len ); + max_len = sub( st_fx->L_frame, Diff_len ); /* Q0 */ if ( st_fx->bwidth == NB ) { - max_len = sub( 160, Diff_len ); + max_len = sub( 160, Diff_len ); /* Q0 */ } Len = 80; move16(); if ( LT_16( max_len, 80 ) ) { - Len = max_len; + Len = max_len; /* Q0 */ move16(); } @@ -366,7 +366,7 @@ void decod_audio_fx( { FOR( i = 0; i < max_len; i++ ) { - dct_epit[add( i, Diff_len )] = 0; + dct_epit[i + Diff_len] = 0; move16(); } } @@ -374,47 +374,47 @@ void decod_audio_fx( { FOR( i = 0; i < Len; i++ ) { - dct_epit[add( i, Diff_len )] = mult_r( dct_epit[add( i, Diff_len )], sm_table_fx[i] ); + dct_epit[i + Diff_len] = mult_r( dct_epit[i + Diff_len], sm_table_fx[i] ); /* Qx */ move16(); } FOR( ; i < max_len; i++ ) { - dct_epit[add( i, Diff_len )] = 0; + dct_epit[i + Diff_len] = 0; move16(); } } // PMT("in the rare case of 4 subfr, bfi_pitch_fx might be wrong") - st_fx->bfi_pitch_fx = mean_fx( pitch_buf, nb_subfr ); + st_fx->bfi_pitch_fx = mean_fx( pitch_buf, nb_subfr ); /* Q6 */ move16(); - st_fx->bfi_pitch_frame = st_fx->L_frame; + st_fx->bfi_pitch_frame = st_fx->L_frame; /* Q0 */ move16(); - Diff_len = add( Diff_len, 1 ); + Diff_len = add( Diff_len, 1 ); /* Q0 */ st_fx->bpf_off = 0; move16(); } ELSE { /* No adaptive (pitch) excitation contribution */ - st_fx->bpf_off = 1; + st_fx->bpf_off = 1; /* Q0 */ move16(); set16_fx( dct_epit, 0, st_fx->L_frame ); IF( EQ_16( st_fx->L_frame, L_FRAME16k ) ) { - set16_fx( pitch_buf, shl( L_SUBFR16k, 6 ), NB_SUBFR16k ); + set16_fx( pitch_buf, L_SUBFR16k * 64, NB_SUBFR16k ); } ELSE { - set16_fx( pitch_buf, shl( L_SUBFR, 6 ), NB_SUBFR ); + set16_fx( pitch_buf, L_SUBFR * 64, NB_SUBFR ); } set16_fx( gain_buf, 0, NB_SUBFR16k ); - st_fx->bfi_pitch_fx = shl( L_SUBFR, 6 ); + st_fx->bfi_pitch_fx = L_SUBFR * 64; move16(); - st_fx->bfi_pitch_frame = st_fx->L_frame; + st_fx->bfi_pitch_frame = st_fx->L_frame; /* Q0 */ move16(); st_fx->lp_gainp_fx = 0; move16(); @@ -434,7 +434,7 @@ void decod_audio_fx( /* find the current total number of bits used */ - tmp_nb_bits_tot = st_fx->next_bit_pos; + tmp_nb_bits_tot = st_fx->next_bit_pos; /* Q0 */ move16(); #ifdef IVAS_CODE if ( st_fx->extl_brate_fx_orig > 0 ) @@ -443,7 +443,7 @@ void decod_audio_fx( #endif { /* subtract 1 bit for TBE/BWE BWE flag (bit counted in extl_brate) */ - tmp_nb_bits_tot = sub( tmp_nb_bits_tot, 1 ); + tmp_nb_bits_tot = sub( tmp_nb_bits_tot, 1 ); /* Q0 */ } @@ -456,7 +456,7 @@ void decod_audio_fx( if ( st_fx->coder_type == INACTIVE && LE_32( st_fx->core_brate, ACELP_9k60 ) ) #endif { - tmp_nb_bits_tot = add( tmp_nb_bits_tot, 5 ); + tmp_nb_bits_tot = add( tmp_nb_bits_tot, 5 ); /* Q0 */ } #ifdef ADD_LRTD @@ -502,8 +502,8 @@ void decod_audio_fx( * Updates *--------------------------------------------------------------------------------------*/ - Copy( exc, exc2, st_fx->L_frame ); - Copy( exc_wo_nf, exc, st_fx->L_frame ); + Copy( exc, exc2, st_fx->L_frame ); /* Q_exc */ + Copy( exc_wo_nf, exc, st_fx->L_frame ); /* Q_exc */ /*--------------------------------------------------------------------------------------* * Channel aware mode parameters @@ -537,21 +537,21 @@ void decod_audio_fx( /* _ None */ /*==========================================================================*/ void decod_audio_ivas_fx( - Decoder_State *st_fx, /* i/o: decoder static memory */ - Word16 dct_epit[], /* o : GSC excitation in DCT domain */ - const Word16 *Aq, /* i : LP filter coefficient */ - Word16 *pitch_buf, /* o : Word16 pitch values for each subframe */ - Word16 *voice_factors, /* o : voicing factors */ - Word16 *exc, /* i/o: adapt. excitation exc */ - Word16 *exc2, /* i/o: adapt. excitation/total exc */ - Word16 *bwe_exc, /* o : excitation for SWB TBE */ - Word16 *lsf_new /* i : ISFs at the end of the frame */ + Decoder_State *st_fx, /* i/o: decoder static memory */ + Word16 dct_epit[], /* o : GSC excitation in DCT domain Qx*/ + const Word16 *Aq, /* i : LP filter coefficient Q12*/ + Word16 *pitch_buf, /* o : Word16 pitch values for each subframe Q6*/ + Word16 *voice_factors, /* o : voicing factors Q15*/ + Word16 *exc, /* i/o: adapt. excitation exc Q_exc*/ + Word16 *exc2, /* i/o: adapt. excitation/total exc Q_exc*/ + Word16 *bwe_exc, /* o : excitation for SWB TBE Q_exc*/ + Word16 *lsf_new /* i : ISFs at the end of the frame Qx*/ , Word16 *gain_buf, /*Q14*/ - const Word16 tdm_lp_reuse_flag, /* i : LPC reuse flag */ - const Word16 tdm_low_rate_mode, /* i : secondary channel low rate mode flag */ - const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag */ - const Word16 tdm_Pri_pitch_buf[] /* i : primary channel pitch buffer */ + const Word16 tdm_lp_reuse_flag, /* i : LPC reuse flag Q0*/ + const Word16 tdm_low_rate_mode, /* i : secondary channel low rate mode flag Q0*/ + const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag Q0*/ + const Word16 tdm_Pri_pitch_buf[] /* i : primary channel pitch buffer Q6*/ ) { Word16 tmp_nb_bits_tot, pit_band_idx; @@ -579,7 +579,7 @@ void decod_audio_ivas_fx( move16(); /* decode GSC attack flag (used to reduce possible pre-echo) */ - gsc_attack_flag = (Word16) get_next_indice_fx( st_fx, 1 ); + gsc_attack_flag = (Word16) get_next_indice_fx( st_fx, 1 ); /* Q0 */ move16(); /* decode GSC SWB speech flag */ @@ -597,7 +597,7 @@ void decod_audio_ivas_fx( ( st_fx->element_mode > EVS_MONO && GT_32( st_fx->total_brate, MIN_BRATE_GSC_NOISY_FLAG ) && GE_16( st_fx->bwidth, SWB ) && !st_fx->flag_ACELP16k ) ) ) ) #endif { - st_fx->GSC_noisy_speech = (Word16) get_next_indice_fx( st_fx, 1 ); + st_fx->GSC_noisy_speech = (Word16) get_next_indice_fx( st_fx, 1 ); /* Q0 */ move16(); } @@ -606,7 +606,7 @@ void decod_audio_ivas_fx( test(); IF( st_fx->GSC_noisy_speech && LT_16( st_fx->bwidth, SWB ) && st_fx->GSC_IVAS_mode == 0 ) { - st_fx->BER_detect = 1; + st_fx->BER_detect = 1; /* Q0 */ move16(); st_fx->GSC_noisy_speech = 0; move16(); @@ -628,11 +628,11 @@ void decod_audio_ivas_fx( IF( EQ_16( st_fx->GSC_noisy_speech, 1 ) ) #endif { - nb_subfr = NB_SUBFR; + nb_subfr = NB_SUBFR; /* Q0 */ move16(); hGSCDec->cor_strong_limit = 0; move16(); - hGSCDec->noise_lev = NOISE_LEVEL_SP3; + hGSCDec->noise_lev = NOISE_LEVEL_SP3; /* Q0 */ move16(); #if 1 // def ADD_LRTD IF( GE_16( st_fx->GSC_IVAS_mode, 1 ) ) @@ -640,20 +640,20 @@ void decod_audio_ivas_fx( test(); if ( LT_32( st_fx->core_brate, GSC_L_RATE_STG ) && LT_32( st_fx->GSC_IVAS_mode, 3 ) ) { - nb_subfr = 2; + nb_subfr = 2; /* Q0 */ move16(); } - hGSCDec->noise_lev = NOISE_LEVEL_SP2; + hGSCDec->noise_lev = NOISE_LEVEL_SP2; /* Q0 */ move16(); IF( EQ_16( st_fx->GSC_IVAS_mode, 3 ) ) /* Music like */ { - hGSCDec->noise_lev = NOISE_LEVEL_SP0; + hGSCDec->noise_lev = NOISE_LEVEL_SP0; /* Q0 */ move16(); } ELSE IF( st_fx->GSC_noisy_speech == 0 ) /* speech like but not noisy */ { - hGSCDec->noise_lev = NOISE_LEVEL_SP3; + hGSCDec->noise_lev = NOISE_LEVEL_SP3; /* Q0 */ move16(); } } @@ -663,12 +663,12 @@ void decod_audio_ivas_fx( { IF( LE_32( st_fx->core_brate, ACELP_8k00 ) ) { - hGSCDec->noise_lev = add( (Word16) get_next_indice_fx( st_fx, 2 ), NOISE_LEVEL_SP2 ); + hGSCDec->noise_lev = add( (Word16) get_next_indice_fx( st_fx, 2 ), NOISE_LEVEL_SP2 ); /* Q0 */ move16(); } ELSE { - hGSCDec->noise_lev = add( (Word16) get_next_indice_fx( st_fx, 3 ), NOISE_LEVEL_SP0 ); + hGSCDec->noise_lev = add( (Word16) get_next_indice_fx( st_fx, 3 ), NOISE_LEVEL_SP0 ); /* Q0 */ move16(); } @@ -682,30 +682,30 @@ void decod_audio_ivas_fx( { hGSCDec->cor_strong_limit = 0; move16(); - nb_subfr = 1; + nb_subfr = 1; /* Q0 */ move16(); } ELSE #endif { - hGSCDec->cor_strong_limit = 1; + hGSCDec->cor_strong_limit = 1; /* Q0 */ move16(); - nb_subfr = SWNB_SUBFR; + nb_subfr = SWNB_SUBFR; /* Q0 */ move16(); IF( GE_32( st_fx->core_brate, ACELP_9k60 ) ) { - nbits = 1; + nbits = 1; /* Q0 */ move16(); #if 1 // def ADD_LRTD test(); if ( EQ_16( st_fx->L_frame, L_FRAME16k ) && GE_32( st_fx->core_brate, MIN_RATE_4SBFR ) ) { - nbits = 2; + nbits = 2; /* Q0 */ move16(); } #endif - nb_frame_flg = (Word16) get_next_indice_fx( st_fx, nbits ); + nb_frame_flg = (Word16) get_next_indice_fx( st_fx, nbits ); /* Q0 */ move16(); test(); @@ -725,7 +725,7 @@ void decod_audio_ivas_fx( if ( EQ_16( shr( nb_frame_flg, 1 ), 1 ) ) { - nb_subfr = shl( nb_subfr, 1 ); + nb_subfr = shl( nb_subfr, 1 ); /* Q0 */ } #endif } @@ -735,7 +735,7 @@ void decod_audio_ivas_fx( test(); if ( EQ_16( st_fx->L_frame, L_FRAME16k ) && EQ_16( nb_subfr, NB_SUBFR ) ) { - nb_subfr = NB_SUBFR16k; + nb_subfr = NB_SUBFR16k; /* Q0 */ move16(); } #endif @@ -745,29 +745,29 @@ void decod_audio_ivas_fx( IF( LT_32( st_fx->core_brate, CFREQ_BITRATE ) ) { - nbits = 3; + nbits = 3; /* Q0 */ move16(); test(); if ( LT_32( st_fx->core_brate, ACELP_9k60 ) && ( st_fx->coder_type == INACTIVE ) ) { - nbits = 1; + nbits = 1; /* Q0 */ move16(); } } ELSE { - nbits = 4; + nbits = 4; /* Q0 */ move16(); } test(); IF( LT_32( st_fx->core_brate, ACELP_9k60 ) && st_fx->coder_type != INACTIVE ) { - pit_band_idx = 1; + pit_band_idx = 1; /* Q0 */ move16(); } ELSE { - pit_band_idx = (Word16) get_next_indice_fx( st_fx, nbits ); + pit_band_idx = (Word16) get_next_indice_fx( st_fx, nbits ); /* Q0 */ move16(); } @@ -775,26 +775,26 @@ void decod_audio_ivas_fx( { IF( LT_32( st_fx->core_brate, ACELP_9k60 ) ) { - pit_band_idx = 7 + BAND1k2; - move16(); /* At low rate, if pitch model is chosen, then for to be use on extented and constant frequency range */ + pit_band_idx = 7 + BAND1k2; /* Q0 */ + move16(); /* At low rate, if pitch model is chosen, then for to be use on extented and constant frequency range */ } ELSE { - pit_band_idx = add( pit_band_idx, BAND1k2 ); + pit_band_idx = add( pit_band_idx, BAND1k2 ); /* Q0 */ } /* detect bit errors in the bitstream */ IF( GT_16( pit_band_idx, 13 ) ) /* The maximum decodable index is 10 + BAND1k2 (3) = 13 */ { - pit_band_idx = 13; + pit_band_idx = 13; /* Q0 */ move16(); - st_fx->BER_detect = 1; + st_fx->BER_detect = 1; /* Q0 */ move16(); } - Diff_len = mfreq_loc_div_25[pit_band_idx]; + Diff_len = mfreq_loc_div_25[pit_band_idx]; /* Q0 */ move16(); } - hGSCDec->Last_GSC_pit_band_idx = pit_band_idx; + hGSCDec->Last_GSC_pit_band_idx = pit_band_idx; /* Q0 */ move16(); @@ -824,15 +824,15 @@ void decod_audio_ivas_fx( #endif { Word16 indice; - nbits = Es_pred_bits_tbl[BIT_ALLOC_IDX_fx( st_fx->core_brate, GENERIC, -1, -1 )]; + nbits = Es_pred_bits_tbl[BIT_ALLOC_IDX_fx( st_fx->core_brate, GENERIC, -1, -1 )]; /* Q0 */ move16(); if ( st_fx->element_mode > EVS_MONO ) { - nbits = 5; + nbits = 5; /* Q0 */ move16(); } - indice = get_next_indice_fx( st_fx, nbits ); + indice = get_next_indice_fx( st_fx, nbits ); /* Q0 */ Es_pred_dec_fx( &Es_pred, indice, nbits, 0 ); } @@ -848,28 +848,28 @@ void decod_audio_ivas_fx( IF( LT_16( low_pit, 64 ) ) { - pit_band_idx = 9 + BAND1k2; + pit_band_idx = 9 + BAND1k2; /* Q0 */ move16(); if ( st_fx->bwidth == NB ) { - pit_band_idx = 7 + BAND1k2; + pit_band_idx = 7 + BAND1k2; /* Q0 */ move16(); } } ELSE IF( LT_16( low_pit, 128 ) ) { - pit_band_idx = 5 + BAND1k2; + pit_band_idx = 5 + BAND1k2; /* Q0 */ move16(); } ELSE { - pit_band_idx = 3 + BAND1k2; + pit_band_idx = 3 + BAND1k2; /* Q0 */ move16(); } - Diff_len = mfreq_loc_div_25[pit_band_idx]; + Diff_len = mfreq_loc_div_25[pit_band_idx]; /* Q0 */ move16(); - hGSCDec->Last_GSC_pit_band_idx = pit_band_idx; + hGSCDec->Last_GSC_pit_band_idx = pit_band_idx; /* Q0 */ move16(); } @@ -882,18 +882,18 @@ void decod_audio_ivas_fx( * Reset unvaluable part of the adaptive (pitch) excitation contribution *---------------------------------------------------------------*/ - max_len = sub( st_fx->L_frame, Diff_len ); + max_len = sub( st_fx->L_frame, Diff_len ); /* Q0 */ if ( st_fx->bwidth == NB ) { - max_len = sub( 160, Diff_len ); + max_len = sub( 160, Diff_len ); /* Q0 */ } Len = 80; move16(); if ( LT_16( max_len, 80 ) ) { - Len = max_len; + Len = max_len; /* Q0 */ move16(); } @@ -902,7 +902,7 @@ void decod_audio_ivas_fx( { FOR( i = 0; i < max_len; i++ ) { - dct_epit[add( i, Diff_len )] = 0; + dct_epit[i + Diff_len] = 0; move16(); } } @@ -910,23 +910,23 @@ void decod_audio_ivas_fx( { FOR( i = 0; i < Len; i++ ) { - dct_epit[add( i, Diff_len )] = mult_r( dct_epit[add( i, Diff_len )], sm_table_fx[i] ); + dct_epit[i + Diff_len] = mult_r( dct_epit[i + Diff_len], sm_table_fx[i] ); /* Qx */ move16(); } FOR( ; i < max_len; i++ ) { - dct_epit[add( i, Diff_len )] = 0; + dct_epit[i + Diff_len] = 0; move16(); } } // PMT("in the rare case of 4 subfr, bfi_pitch_fx might be wrong") - st_fx->bfi_pitch_fx = mean_fx( pitch_buf, nb_subfr ); + st_fx->bfi_pitch_fx = mean_fx( pitch_buf, nb_subfr ); /* Q6 */ move16(); - st_fx->bfi_pitch_frame = st_fx->L_frame; + st_fx->bfi_pitch_frame = st_fx->L_frame; /* Q0 */ move16(); - Diff_len = add( Diff_len, 1 ); + Diff_len = add( Diff_len, 1 ); /* Q0 */ st_fx->bpf_off = 0; move16(); } @@ -939,18 +939,18 @@ void decod_audio_ivas_fx( IF( EQ_16( st_fx->L_frame, L_FRAME16k ) ) { - set16_fx( pitch_buf, shl( L_SUBFR16k, 6 ), NB_SUBFR16k ); + set16_fx( pitch_buf, ( L_SUBFR16k * 64 ), NB_SUBFR16k ); } ELSE { - set16_fx( pitch_buf, shl( L_SUBFR, 6 ), NB_SUBFR ); + set16_fx( pitch_buf, L_SUBFR * 64, NB_SUBFR ); } set16_fx( gain_buf, 0, NB_SUBFR16k ); - st_fx->bfi_pitch_fx = shl( L_SUBFR, 6 ); + st_fx->bfi_pitch_fx = L_SUBFR * 64; move16(); - st_fx->bfi_pitch_frame = st_fx->L_frame; + st_fx->bfi_pitch_frame = st_fx->L_frame; /* Q0 */ move16(); st_fx->lp_gainp_fx = 0; move16(); @@ -970,7 +970,7 @@ void decod_audio_ivas_fx( /* find the current total number of bits used */ - tmp_nb_bits_tot = st_fx->next_bit_pos; + tmp_nb_bits_tot = st_fx->next_bit_pos; /* Q0 */ move16(); #if 1 // def IVAS_CODE if ( st_fx->extl_brate_orig > 0 ) @@ -979,7 +979,7 @@ void decod_audio_ivas_fx( #endif { /* subtract 1 bit for TBE/BWE BWE flag (bit counted in extl_brate) */ - tmp_nb_bits_tot = sub( tmp_nb_bits_tot, 1 ); + tmp_nb_bits_tot = sub( tmp_nb_bits_tot, 1 ); /* Q0 */ } @@ -991,16 +991,16 @@ void decod_audio_ivas_fx( if ( EQ_16( st_fx->coder_type, INACTIVE ) && LE_32( st_fx->core_brate, ACELP_9k60 ) ) #endif { - tmp_nb_bits_tot = add( tmp_nb_bits_tot, 5 ); + tmp_nb_bits_tot = add( tmp_nb_bits_tot, 5 ); /* Q0 */ } #if 1 // ydef ADD_LRTD IF( EQ_16( st_fx->idchan, 1 ) ) { - tmp_nb_bits_tot = add( tmp_nb_bits_tot, TDM_SIGNAL_BITS_READ_FROM_THE_END_OF_BS ); + tmp_nb_bits_tot = add( tmp_nb_bits_tot, TDM_SIGNAL_BITS_READ_FROM_THE_END_OF_BS ); /* Q0 */ if ( EQ_16( st_fx->tdm_LRTD_flag, 1 ) ) { - tmp_nb_bits_tot = sub( tmp_nb_bits_tot, STEREO_BITS_TCA ); + tmp_nb_bits_tot = sub( tmp_nb_bits_tot, STEREO_BITS_TCA ); /* Q0 */ } } #endif @@ -1012,11 +1012,11 @@ void decod_audio_ivas_fx( Q_exc_old = sub( Q_exc_old, st_fx->Q_exc ); IF( st_fx->hGSCDec ) { - Scale_sig( st_fx->hGSCDec->last_exc_dct_in_fx, L_FRAME16k, Q_exc_old ); + Scale_sig( st_fx->hGSCDec->last_exc_dct_in_fx, L_FRAME16k, Q_exc_old ); /* Q_exc_old */ } IF( bwe_exc ) { - Scale_sig( bwe_exc - PIT16k_MAX * 2, ( PIT16k_MAX + ( L_FRAME16k + 1 ) + L_SUBFR16k ) * 2, Q_exc_old ); + Scale_sig( bwe_exc - PIT16k_MAX * 2, ( PIT16k_MAX + ( L_FRAME16k + 1 ) + L_SUBFR16k ) * 2, Q_exc_old ); /* Q_exc_old */ } } /*--------------------------------------------------------------------------------------* @@ -1051,8 +1051,8 @@ void decod_audio_ivas_fx( * Updates *--------------------------------------------------------------------------------------*/ - Copy( exc, exc2, st_fx->L_frame ); - Copy( exc_wo_nf, exc, st_fx->L_frame ); + Copy( exc, exc2, st_fx->L_frame ); /* Q_exc */ + Copy( exc_wo_nf, exc, st_fx->L_frame ); /* Q_exc */ /*--------------------------------------------------------------------------------------* * Channel aware mode parameters @@ -1088,15 +1088,15 @@ void decod_audio_ivas_fx( /*==========================================================================*/ void gsc_dec_fx( Decoder_State *st_fx, /* i/o: State structure */ - Word16 exc_dct_in[], /* i/o: dct of pitch-only excitation / total excitation */ - const Word16 pit_band_idx, /* i : bin position of the cut-off frequency */ - const Word16 Diff_len, /* i : Lenght of the difference signal (before pure spectral)*/ - const Word16 bits_used, /* i : Number of bit used before frequency Q */ - const Word16 nb_subfr, /* i : Number of subframe considered */ - const Word16 coder_type, /* i : coding type */ - Word16 *last_bin, /* i : last bin of bit allocation */ - const Word16 *lsf_new, /* i : ISFs at the end of the frame */ - Word16 *exc_wo_nf, /* o : excitation (in f domain) without noisefill */ + Word16 exc_dct_in[], /* i/o: dct of pitch-only excitation / total excitation Q_exc*/ + const Word16 pit_band_idx, /* i : bin position of the cut-off frequency Q0*/ + const Word16 Diff_len, /* i : Lenght of the difference signal (before pure spectral) Q0*/ + const Word16 bits_used, /* i : Number of bit used before frequency Q Q0*/ + const Word16 nb_subfr, /* i : Number of subframe considered Q0*/ + const Word16 coder_type, /* i : coding type Q0*/ + Word16 *last_bin, /* i : last bin of bit allocation Q0*/ + const Word16 *lsf_new, /* i : ISFs at the end of the frame Qx*/ + Word16 *exc_wo_nf, /* o : excitation (in f domain) without noisefill Q_exc*/ Word16 Q_exc ) { Word16 i, j, bit, nb_subbands, pvq_len; @@ -1127,6 +1127,8 @@ void gsc_dec_fx( Word16 seed_init; GSC_DEC_HANDLE hGSCDec; hGSCDec = st_fx->hGSCDec; + move16(); + move16(); move16(); // for Mbands_gn move16(); // for Qexc_diffQ @@ -1164,8 +1166,8 @@ void gsc_dec_fx( IF( st_fx->bfi || st_fx->BER_detect ) { /* copy old gain */ - Copy( hGSCDec->old_y_gain_fx, Ener_per_bd_iQ, Mbands_gn ); - mean_gain = mult_r( st_fx->lp_gainc_fx, 3277 ); /*Q3*/ + Copy( hGSCDec->old_y_gain_fx, Ener_per_bd_iQ, Mbands_gn ); /* Q_old_gain */ + mean_gain = mult_r( st_fx->lp_gainc_fx, 3277 ); /*Q3*/ FOR( i = 0; i < Mbands_gn; i++ ) { Ener_per_bd_iQ[i] = add( Ener_per_bd_iQ[i], shl( mean_gain, 9 ) ); /*Q12*/ @@ -1202,7 +1204,7 @@ void gsc_dec_fx( mean_gain = gsc_gaindec_fx( st_fx, Ener_per_bd_iQ, brate_intermed_tbl[i], hGSCDec->old_y_gain_fx, coder_type, st_fx->bwidth ); #else - mean_gain = gsc_gaindec_fx( st_fx, Ener_per_bd_iQ, st_fx->core_brate, hGSCDec->old_y_gain_fx, coder_type, st_fx->bwidth ); + mean_gain = gsc_gaindec_fx( st_fx, Ener_per_bd_iQ, st_fx->core_brate, hGSCDec->old_y_gain_fx, coder_type, st_fx->bwidth ); /* Q12 */ #endif st_fx->lp_gainc_fx = mult_r( 640, mean_gain ); /*10 in Q6 x Q12 -> lp_gainc in Q3 */ move16(); @@ -1239,13 +1241,13 @@ void gsc_dec_fx( FOR( i = 0; i < st_fx->L_frame; i++ ) { L_tmp = L_shr( L_mult( Random( &hGSCDec->seed_tcx ), 26214 ), 5 ); /*Q10*/ - L_tmp = L_mac( L_tmp, hGSCDec->Last_GSC_spectrum_fx[i], 6554 ); - hGSCDec->Last_GSC_spectrum_fx[i] = round_fx( L_tmp ); /*Q10*/ + L_tmp = L_mac( L_tmp, hGSCDec->Last_GSC_spectrum_fx[i], 6554 ); /* Q10 */ + hGSCDec->Last_GSC_spectrum_fx[i] = round_fx( L_tmp ); /*Q10*/ move16(); } } - Copy( hGSCDec->Last_GSC_spectrum_fx, exc_diffQ, st_fx->L_frame ); + Copy( hGSCDec->Last_GSC_spectrum_fx, exc_diffQ, st_fx->L_frame ); /* Q10 */ FOR( i = 0; i < st_fx->L_frame; i++ ) { @@ -1271,7 +1273,7 @@ void gsc_dec_fx( #endif { pvq_core_dec_fx( st_fx, gsc_sfm_start, gsc_sfm_end, gsc_sfm_size, concat_out, &Q_tmp, bit, nb_subbands, bits_per_bands, NULL, inpulses_fx, imaxpulse_fx, ACELP_CORE ); - Scale_sig( concat_out, gsc_sfm_end[nb_subbands - 1], sub( Q_PVQ_OUT, Q_tmp ) ); + Scale_sig( concat_out, gsc_sfm_end[nb_subbands - 1], sub( Q_PVQ_OUT, Q_tmp ) ); /* Q_PVQ_OUT */ } seed_init = 0; move16(); @@ -1290,34 +1292,34 @@ void gsc_dec_fx( /* Reorder Q bands */ FOR( j = 0; j < nb_subbands; j++ ) { - Copy( concat_out + j * 16, exc_diffQ + max_ener_band[j] * 16, 16 ); + Copy( concat_out + shl( j, 4 ), exc_diffQ + shl( max_ener_band[j], 4 ), 16 ); /* Q_PVQ_OUT */ - *last_bin = s_max( *last_bin, max_ener_band[j] ); + *last_bin = s_max( *last_bin, max_ener_band[j] ); /* Q0 */ move16(); - bitallocation_band[max_ener_band[j]] = 1; + bitallocation_band[max_ener_band[j]] = 1; /* Q0 */ move16(); - seed_init = add( seed_init, inpulses_fx[j] ); + seed_init = add( seed_init, inpulses_fx[j] ); /* Q0 */ } test(); IF( NE_16( st_fx->last_coder_type, AUDIO ) /* First audio frame */ && NE_16( st_fx->last_coder_type, UNVOICED ) ) /* last_coder_type == INACTIVE is overwritten in update_dec to UNVOICED */ { - FOR( j = 0; j < shl( nb_subbands, 4 ); j++ ) + FOR( j = 0; j < nb_subbands * 16; j++ ) { IF( concat_out[j] > 0 ) { - seed_init = extract_l( L_shl( seed_init, 3 ) ); + seed_init = extract_l( L_shl( seed_init, 3 ) ); /* Q0 */ } if ( concat_out[j] < 0 ) { - seed_init = add( seed_init, 3 ); + seed_init = add( seed_init, 3 ); /* Q0 */ move16(); } } - hGSCDec->seed_tcx = seed_init; + hGSCDec->seed_tcx = seed_init; /* Q0 */ move16(); } test(); @@ -1325,18 +1327,18 @@ void gsc_dec_fx( { if ( exc_diffQ[L_FRAME8k - 2] != 0 ) { - bitallocation_exc[0] = 1; + bitallocation_exc[0] = 1; /* Q0 */ move16(); } if ( exc_diffQ[L_FRAME8k - 1] != 0 ) { - bitallocation_exc[1] = 1; + bitallocation_exc[1] = 1; /* Q0 */ move16(); } } - Copy( exc_diffQ, hGSCDec->Last_GSC_spectrum_fx, st_fx->L_frame ); + Copy( exc_diffQ, hGSCDec->Last_GSC_spectrum_fx, st_fx->L_frame ); /* Q_PVQ_OUT */ /*--------------------------------------------------------------------------------------* * Skip adaptive (pitch) contribution frequency band (no noise added over the time contribution) @@ -1413,15 +1415,15 @@ void gsc_dec_fx( /*==========================================================================*/ void gsc_dec_ivas_fx( Decoder_State *st_fx, /* i/o: State structure */ - Word16 exc_dct_in[], /* i/o: dct of pitch-only excitation / total excitation */ - const Word16 pit_band_idx, /* i : bin position of the cut-off frequency */ - const Word16 Diff_len, /* i : Lenght of the difference signal (before pure spectral)*/ - const Word16 bits_used, /* i : Number of bit used before frequency Q */ - const Word16 nb_subfr, /* i : Number of subframe considered */ - const Word16 coder_type, /* i : coding type */ - Word16 *last_bin, /* i : last bin of bit allocation */ - const Word16 *lsf_new, /* i : ISFs at the end of the frame */ - Word16 *exc_wo_nf, /* o : excitation (in f domain) without noisefill */ + Word16 exc_dct_in[], /* i/o: dct of pitch-only excitation / total excitation Q_exc*/ + const Word16 pit_band_idx, /* i : bin position of the cut-off frequency ` Q0*/ + const Word16 Diff_len, /* i : Lenght of the difference signal (before pure spectral) Q0*/ + const Word16 bits_used, /* i : Number of bit used before frequency Q Q0*/ + const Word16 nb_subfr, /* i : Number of subframe considered Q0*/ + const Word16 coder_type, /* i : coding type Q0*/ + Word16 *last_bin, /* i : last bin of bit allocation Q0*/ + const Word16 *lsf_new, /* i : ISFs at the end of the frame Qx*/ + Word16 *exc_wo_nf, /* o : excitation (in f domain) without noisefill Q_exc*/ Word16 *Q_exc ) { Word16 i, j, bit, nb_subbands, pvq_len; @@ -1470,12 +1472,12 @@ void gsc_dec_ivas_fx( test(); if ( coder_type == INACTIVE && ( EQ_16( st_fx->tdm_LRTD_flag, 1 ) || EQ_16( st_fx->element_mode, IVAS_SCE ) ) && LE_32( st_fx->core_brate, GSC_LRES_GAINQ_LIMIT ) ) { - bit = add( bit, GSC_LRES_NB_NITS ); + bit = add( bit, GSC_LRES_NB_NITS ); /* Q0 */ } if ( EQ_16( st_fx->L_frame, L_FRAME16k ) ) { - Mbands_gn = MBANDS_GN16k; + Mbands_gn = MBANDS_GN16k; /* Q0 */ move16(); } #endif @@ -1489,8 +1491,8 @@ void gsc_dec_ivas_fx( IF( st_fx->bfi || st_fx->BER_detect ) { /* copy old gain */ - Copy( hGSCDec->old_y_gain_fx, Ener_per_bd_iQ, Mbands_gn ); - mean_gain = mult_r( st_fx->lp_gainc_fx, 3277 ); /*Q3*/ + Copy( hGSCDec->old_y_gain_fx, Ener_per_bd_iQ, Mbands_gn ); /* Q_old_gain */ + mean_gain = mult_r( st_fx->lp_gainc_fx, 3277 ); /*Q3*/ FOR( i = 0; i < Mbands_gn; i++ ) { Ener_per_bd_iQ[i] = add( Ener_per_bd_iQ[i], shl( mean_gain, 9 ) ); /*Q12*/ @@ -1512,7 +1514,7 @@ void gsc_dec_ivas_fx( { break; } - i = add( i, 1 ); + i++; } test(); @@ -1521,9 +1523,9 @@ void gsc_dec_ivas_fx( if ( st_fx->element_mode > EVS_MONO && EQ_16( coder_type, AUDIO ) && LE_32( st_fx->core_brate, STEREO_GSC_BIT_RATE_ALLOC ) && EQ_32( brate_intermed_tbl[i], ACELP_9k60 ) ) /* Bit allocation is mapped to 8 kb/s instead of 9.6 kb/s in this case */ { - i = sub( i, 1 ); + i--; } - mean_gain = gsc_gaindec_ivas_fx( st_fx, Ener_per_bd_iQ, brate_intermed_tbl[i], hGSCDec->old_y_gain_fx, coder_type, st_fx->bwidth ); + mean_gain = gsc_gaindec_ivas_fx( st_fx, Ener_per_bd_iQ, brate_intermed_tbl[i], hGSCDec->old_y_gain_fx, coder_type, st_fx->bwidth ); /* Q3 */ #else mean_gain = gsc_gaindec_fx( st_fx, Ener_per_bd_iQ, st_fx->core_brate, hGSCDec->old_y_gain_fx, coder_type, st_fx->bwidth ); @@ -1563,13 +1565,13 @@ void gsc_dec_ivas_fx( FOR( i = 0; i < st_fx->L_frame; i++ ) { L_tmp = L_shr( L_mult( Random( &hGSCDec->seed_tcx ), 26214 ), 5 ); /*Q10*/ - L_tmp = L_mac( L_tmp, hGSCDec->Last_GSC_spectrum_fx[i], 6554 ); - hGSCDec->Last_GSC_spectrum_fx[i] = round_fx( L_tmp ); /*Q10*/ + L_tmp = L_mac( L_tmp, hGSCDec->Last_GSC_spectrum_fx[i], 6554 ); /* Q10 */ + hGSCDec->Last_GSC_spectrum_fx[i] = round_fx( L_tmp ); /*Q10*/ move16(); } } - Copy( hGSCDec->Last_GSC_spectrum_fx, exc_diffQ, st_fx->L_frame ); + Copy( hGSCDec->Last_GSC_spectrum_fx, exc_diffQ, st_fx->L_frame ); /* Q10 */ FOR( i = 0; i < st_fx->L_frame; i++ ) { @@ -1595,7 +1597,7 @@ void gsc_dec_ivas_fx( #endif { pvq_core_dec_fx( st_fx, gsc_sfm_start, gsc_sfm_end, gsc_sfm_size, concat_out, &Q_tmp, bit, nb_subbands, bits_per_bands, NULL, inpulses_fx, imaxpulse_fx, ACELP_CORE ); - Scale_sig( concat_out, gsc_sfm_end[nb_subbands - 1], sub( Q_PVQ_OUT, Q_tmp ) ); + Scale_sig( concat_out, gsc_sfm_end[nb_subbands - 1], sub( Q_PVQ_OUT, Q_tmp ) ); /* Q_PVQ_OUT */ } seed_init = 0; move16(); @@ -1603,7 +1605,7 @@ void gsc_dec_ivas_fx( #if 1 // def ADD_LRTD max_eq = 0; move16(); - max_eq_val = 32767; + max_eq_val = 32767; /* 1.0f in Q15 */ move16(); test(); @@ -1616,7 +1618,7 @@ void gsc_dec_ivas_fx( Word16 temp_max_eq = add( abs_s( concat_out[j] ), 10 ) /*0.01f in Q10*/; if ( LE_16( temp_max_eq, ONE_IN_Q10 ) ) { - max_eq = max_eq_val; + max_eq = max_eq_val; /* Q15 */ move16(); } ELSE @@ -1624,22 +1626,22 @@ void gsc_dec_ivas_fx( Word16 exp = 5; move16(); max_eq = Inv16( temp_max_eq, &exp ); - max_eq = shl( max_eq, exp ); + max_eq = shl( max_eq, exp ); /* Q15 */ } } #endif /* Reorder Q bands */ FOR( j = 0; j < nb_subbands; j++ ) { - Copy( concat_out + imult1616( j, 16 ), exc_diffQ + imult1616( max_ener_band[j], 16 ), 16 ); + Copy( concat_out + imult1616( j, 16 ), exc_diffQ + imult1616( max_ener_band[j], 16 ), 16 ); /* Q_PVQ_OUT */ - *last_bin = s_max( *last_bin, max_ener_band[j] ); + *last_bin = s_max( *last_bin, max_ener_band[j] ); /* Q0 */ move16(); - bitallocation_band[max_ener_band[j]] = 1; + bitallocation_band[max_ener_band[j]] = 1; /* Q0 */ move16(); - seed_init = add( seed_init, inpulses_fx[j] ); + seed_init = add( seed_init, inpulses_fx[j] ); /* Q0 */ } test(); IF( NE_16( st_fx->last_coder_type, AUDIO ) /* First audio frame */ @@ -1649,19 +1651,19 @@ void gsc_dec_ivas_fx( { IF( concat_out[j] > 0 ) { - seed_init = extract_l( L_shl( seed_init, 3 ) ); + seed_init = extract_l( L_shl( seed_init, 3 ) ); /* Q0 */ } if ( concat_out[j] < 0 ) { #ifdef BASOP_NOGLOB_TMP_715 - seed_init = add_sat( seed_init, 3 ); + seed_init = add_sat( seed_init, 3 ); /* Q0 */ #else seed_init = add( seed_init, 3 ); #endif } } - hGSCDec->seed_tcx = seed_init; + hGSCDec->seed_tcx = seed_init; /* Q0 */ move16(); } test(); @@ -1669,18 +1671,18 @@ void gsc_dec_ivas_fx( { if ( exc_diffQ[L_FRAME8k - 2] != 0 ) { - bitallocation_exc[0] = 1; + bitallocation_exc[0] = 1; /* Q0 */ move16(); } if ( exc_diffQ[L_FRAME8k - 1] != 0 ) { - bitallocation_exc[1] = 1; + bitallocation_exc[1] = 1; /* Q0 */ move16(); } } - Copy( exc_diffQ, hGSCDec->Last_GSC_spectrum_fx, st_fx->L_frame ); + Copy( exc_diffQ, hGSCDec->Last_GSC_spectrum_fx, st_fx->L_frame ); /* Q_PVQ_OUT */ /*--------------------------------------------------------------------------------------* * Skip adaptive (pitch) contribution frequency band (no noise added over the time contribution) @@ -1698,7 +1700,7 @@ void gsc_dec_ivas_fx( { // PMT("GSC FIX point to be done here") // exc_diffQ[i] *= max_eq; - exc_diffQ[i] = mult_r( exc_diffQ[i], max_eq ); + exc_diffQ[i] = mult_r( exc_diffQ[i], max_eq ); /* Q_PVQ_OUT */ move16(); } } @@ -1708,7 +1710,7 @@ void gsc_dec_ivas_fx( { // PMT("GSC FIX point to be done here") // exc_diffQ[i] *= max_eq; - exc_diffQ[i] = mult_r( exc_diffQ[i], max_eq ); + exc_diffQ[i] = mult_r( exc_diffQ[i], max_eq ); /* Q_PVQ_OUT */ move16(); } } @@ -1744,12 +1746,12 @@ void GSC_dec_init( GSC_DEC_HANDLE hGSCDec /* i/o: GSC data handle */ ) { - hGSCDec->seed_tcx = 15687; + hGSCDec->seed_tcx = 15687; /* Q0 */ hGSCDec->cor_strong_limit = 1; move16(); move16(); - hGSCDec->noise_lev = NOISE_LEVEL_SP0; + hGSCDec->noise_lev = NOISE_LEVEL_SP0; /* Q0 */ hGSCDec->Last_GSC_pit_band_idx = 0; move16(); move16(); @@ -1778,7 +1780,7 @@ void GSC_dec_init_ivas_fx( GSC_DEC_HANDLE hGSCDec /* i/o: GSC data handle */ ) { - hGSCDec->seed_tcx = 15687; + hGSCDec->seed_tcx = 15687; /* Q0 */ move16(); hGSCDec->cor_strong_limit = 1; move16(); diff --git a/lib_dec/hdecnrm_fx.c b/lib_dec/hdecnrm_fx.c index 9c8b6fa01..291aa87fb 100644 --- a/lib_dec/hdecnrm_fx.c +++ b/lib_dec/hdecnrm_fx.c @@ -13,18 +13,18 @@ /* Huffman decoding for indices of quantized norms */ /*--------------------------------------------------------------------------*/ void hdecnrm_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word16 numNorms, /* i : number of norms */ - Word16 *index ) /* o : indices of quantized norms */ + Decoder_State *st_fx, /* i/o: decoder state structure */ + const Word16 numNorms, /* i : number of norms Q0*/ + Word16 *index ) /* o : indices of quantized norms Q0*/ { Word16 i, j, k, n, m; Word16 temp; Word16 *pidx; - pidx = index; + pidx = index; /* Q0 */ - m = sub( numNorms, 1 ); + m = sub( numNorms, 1 ); /* Q0 */ FOR( i = 0; i < m; i++ ) { j = (Word16) 0; @@ -34,51 +34,51 @@ void hdecnrm_fx( if ( get_next_indice_1_fx( st_fx ) != 0 ) { - j = (Word16) 1; + j = (Word16) 1; /* Q0 */ move16(); } if ( get_next_indice_1_fx( st_fx ) != 0 ) { - k = (Word16) 1; + k = (Word16) 1; /* Q0 */ move16(); } - n = add( shl( j, 1 ), k ); - j = shl( j, 2 ); - temp = sub( add( 16, n ), j ); + n = add( shl( j, 1 ), k ); /* Q0 */ + j = shl( j, 2 ); /* Q0 */ + temp = sub( add( 16, n ), j ); /* Q0 */ IF( get_next_indice_1_fx( st_fx ) != 0 ) { - temp = add( add( 12, n ), j ); + temp = add( add( 12, n ), j ); /* Q0 */ IF( get_next_indice_1_fx( st_fx ) != 0 ) { j = (Word16) 0; move16(); if ( get_next_indice_1_fx( st_fx ) != 0 ) { - j = 1; + j = 1; /* Q0 */ move16(); } - temp = add( 8, n ); + temp = add( 8, n ); /* Q0 */ if ( j != 0 ) { - temp = add( temp, 12 ); + temp = add( temp, 12 ); /* Q0 */ } IF( get_next_indice_1_fx( st_fx ) != 0 ) { - temp = n; + temp = n; /* Q0 */ move16(); if ( get_next_indice_1_fx( st_fx ) != 0 ) { - temp = add( 4, n ); + temp = add( 4, n ); /* Q0 */ } if ( j != 0 ) { - temp = add( temp, 24 ); + temp = add( temp, 24 ); /* Q0 */ } } } } - *pidx++ = temp; + *pidx++ = temp; /* Q0 */ move16(); } @@ -96,9 +96,10 @@ void hdecnrm_fx( /*--------------------------------------------------------------------------*/ Word16 decode_huff_context_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word16 *hufftab, - Word16 *rbits ) + Decoder_State *st_fx, /* i/o: decoder state structure */ + const Word16 *hufftab, /* Q0 */ + Word16 *rbits /* Q0 */ +) { Word16 tmp_l, tmp_h; Word32 hufftab_idx; @@ -106,11 +107,11 @@ Word16 decode_huff_context_fx( hufftab_idx = L_deposit_l( 0 ); WHILE( hufftab[hufftab_idx] > 0 ) { - tmp_h = shr( hufftab[hufftab_idx], 4 ); - tmp_l = sub( hufftab[hufftab_idx], shl( tmp_h, 4 ) ); - *rbits = add( *rbits, tmp_l ); + tmp_h = shr( hufftab[hufftab_idx], 4 ); /* Q0 */ + tmp_l = sub( hufftab[hufftab_idx], shl( tmp_h, 4 ) ); /* Q0 */ + *rbits = add( *rbits, tmp_l ); /* Q0 */ move16(); - hufftab_idx = L_add( hufftab_idx, L_add( L_deposit_l( tmp_h ), get_next_indice_fx( st_fx, tmp_l ) ) ); + hufftab_idx = L_add( hufftab_idx, L_add( L_deposit_l( tmp_h ), get_next_indice_fx( st_fx, tmp_l ) ) ); /* Q0 */ } return negate( hufftab[hufftab_idx] ); } @@ -129,20 +130,21 @@ Word16 decode_huff_context_fx( void hdecnrm_context_fx( Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word16 N, - Word16 *index, - Word16 *n_length ) + const Word16 N, /* Q0 */ + Word16 *index, /* Q0 */ + Word16 *n_length /* Q0 */ +) { Word16 i, prevj, tmp; - prevj = add( index[0], OFFSET_NORM ); + prevj = add( index[0], OFFSET_NORM ); /* Q0 */ FOR( i = 1; i < N; i++ ) { IF( GT_16( prevj, HTH_NORM ) ) { /* above */ - tmp = decode_huff_context_fx( st_fx, hntable, n_length ); - index[i] = sub( 31, tmp ); + tmp = decode_huff_context_fx( st_fx, hntable, n_length ); /* Q0 */ + index[i] = sub( 31, tmp ); /* Q0 */ move16(); } ELSE @@ -150,17 +152,17 @@ void hdecnrm_context_fx( IF( LT_16( prevj, LTH_NORM ) ) { /* less */ - index[i] = decode_huff_context_fx( st_fx, hntable, n_length ); + index[i] = decode_huff_context_fx( st_fx, hntable, n_length ); /* Q0 */ move16(); } ELSE { /* equal */ - index[i] = decode_huff_context_fx( st_fx, hetable, n_length ); + index[i] = decode_huff_context_fx( st_fx, hetable, n_length ); /* Q0 */ move16(); } } - prevj = index[i]; + prevj = index[i]; /* Q0 */ move16(); } return; @@ -168,17 +170,17 @@ void hdecnrm_context_fx( void hdecnrm_resize_fx( Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word16 N, /* (i) number of SFMs */ - Word16 *index /* (o) norm quantization index vector */ + const Word16 N, /* (i) number of SFMs Q0*/ + Word16 *index /* (o) norm quantization index vector Q0*/ ) { Word16 i, j, k, m; Word16 temp; Word16 *pidx; - pidx = index; + pidx = index; /* Q0 */ - m = sub( N, 1 ); + m = sub( N, 1 ); /* Q0 */ move16(); FOR( i = 0; i < m; i++ ) { @@ -191,7 +193,7 @@ void hdecnrm_resize_fx( { IF( get_next_indice_1_fx( st_fx ) != 0 ) { - k = add( k, 1 ); + k = add( k, 1 ); /* Q0 */ move16(); } ELSE @@ -202,31 +204,31 @@ void hdecnrm_resize_fx( IF( EQ_16( k, 11 ) ) { - temp = 25; + temp = 25; /* Q0 */ move16(); } ELSE IF( EQ_16( k, 10 ) ) { - temp = 5; + temp = 5; /* Q0 */ move16(); } ELSE IF( EQ_16( k, 9 ) ) { - temp = 6; + temp = 6; /* Q0 */ move16(); } ELSE{ IF( get_next_indice_1_fx( st_fx ) != 0 ){ - temp = add( 16, k ); + temp = add( 16, k ); /* Q0 */ } ELSE { - temp = sub( 15, k ); + temp = sub( 15, k ); /* Q0 */ move16(); } } -*pidx++ = temp; +*pidx++ = temp; /* Q0 */ move16(); } @@ -241,20 +243,20 @@ return; void huff_dec_fx( Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word16 N, /* i : Number of codewords to decode */ - const Word16 buffer_len, /* i : Number of bits to read */ - const Word16 num_lengths, /* i : Number of different huffman codeword lengths */ - const Word16 *thres, /* i : Threshold of first codeword of each length */ - const Word16 *offset, /* i : Offset for first codeword */ - const Word16 *huff_tab, /* i : Huffman table order by codeword lengths */ - Word16 *index /* o : Decoded index */ + const Word16 N, /* i : Number of codewords to decode Q0*/ + const Word16 buffer_len, /* i : Number of bits to read Q0*/ + const Word16 num_lengths, /* i : Number of different huffman codeword lengths Q0*/ + const Word16 *thres, /* i : Threshold of first codeword of each length Q0*/ + const Word16 *offset, /* i : Offset for first codeword Q0*/ + const Word16 *huff_tab, /* i : Huffman table order by codeword lengths Q0*/ + Word16 *index /* o : Decoded index Q0*/ ) { Word16 i, j, k; UWord16 val; Word16 last_bits; - last_bits = buffer_len; + last_bits = buffer_len; /* Q0 */ move16(); val = 0; @@ -263,24 +265,24 @@ void huff_dec_fx( move16(); FOR( i = 0; i < N; i++ ) { - last_bits = sub( buffer_len, j ); - val = (UWord16) L_shl( val, last_bits ); - val = (UWord16) L_and( val, sub( lshl( 1, buffer_len ), 1 ) ); - val = (UWord16) L_or( val, get_next_indice_fx( st_fx, last_bits ) ); + last_bits = sub( buffer_len, j ); /* Q0 */ + val = (UWord16) L_shl( val, last_bits ); /* Q0 */ + val = (UWord16) L_and( val, sub( lshl( 1, buffer_len ), 1 ) ); /* Q0 */ + val = (UWord16) L_or( val, get_next_indice_fx( st_fx, last_bits ) ); /* Q0 */ /* Find codeword length */ - j = sub( num_lengths, 1 ); + j = sub( num_lengths, 1 ); /* Q0 */ WHILE( LT_16( val, thres[j] ) ) { - j = sub( j, 1 ); + j = sub( j, 1 ); /* Q0 */ } - k = lshr( sub( val, thres[j] ), j ); - *index++ = huff_tab[add( offset[j], k )]; + k = lshr( sub( val, thres[j] ), j ); /* Q0 */ + *index++ = huff_tab[offset[j] + k]; /* Q0 */ move16(); } /* Put back unused bits */ - st_fx->next_bit_pos = sub( st_fx->next_bit_pos, j ); + st_fx->next_bit_pos = sub( st_fx->next_bit_pos, j ); /* Q0 */ move16(); return; @@ -293,9 +295,9 @@ void huff_dec_fx( *--------------------------------------------------------------------------*/ void hdecnrm_tran_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word16 N, /* i : number of norms */ - Word16 *index /* o : indices of quantized norms */ + Decoder_State *st_fx, /* i/o: decoder state structure */ + const Word16 N, /* i : number of norms Q0*/ + Word16 *index /* o : indices of quantized norms Q0*/ ) { Word16 i, j, k, n, m; @@ -303,9 +305,9 @@ void hdecnrm_tran_fx( Word16 *pidx; Word16 l; - pidx = index; + pidx = index; /* Q0 */ - m = sub( N, 1 ); + m = sub( N, 1 ); /* Q0 */ FOR( i = 0; i < m; i++ ) { j = 0; @@ -314,20 +316,20 @@ void hdecnrm_tran_fx( move16(); if ( get_next_indice_1_fx( st_fx ) != 0 ) { - j = 1; + j = 1; /* Q0 */ move16(); } if ( get_next_indice_1_fx( st_fx ) != 0 ) { - k = 1; + k = 1; /* Q0 */ move16(); } /*n = k * 2 + j; */ - n = add( shl( k, 1 ), j ); + n = add( shl( k, 1 ), j ); /* Q0 */ /*l = k * 4; */ - l = shl( k, 2 ); + l = shl( k, 2 ); /* Q0 */ test(); test(); test(); @@ -335,22 +337,22 @@ void hdecnrm_tran_fx( test(); IF( ( j == 0 && k == 0 ) || ( EQ_16( j, 1 ) && k == 0 ) || ( EQ_16( j, 1 ) && EQ_16( k, 1 ) ) ) { - temp = sub( add( 15, l ), n ); + temp = sub( add( 15, l ), n ); /* Q0 */ } ELSE{ IF( get_next_indice_1_fx( st_fx ) != 0 ){ - temp = sub( add( 15, n ), l ); + temp = sub( add( 15, n ), l ); /* Q0 */ } ELSE { - temp = sub( add( 15, l ), n ); + temp = sub( add( 15, l ), n ); /* Q0 */ IF( get_next_indice_1_fx( st_fx ) != 0 ) { FOR( k = 0; k < 3; ) { IF( get_next_indice_1_fx( st_fx ) != 0 ) { - k = add( k, 1 ); + k++; /* Q0 */ } ELSE { @@ -364,22 +366,22 @@ void hdecnrm_tran_fx( temp = sub( temp, 5 ); if ( EQ_16( k, 3 ) ) { - temp = sub( temp, 1 ); + temp = sub( temp, 1 ); /* Q0 */ } } ELSE IF( EQ_16( k, 1 ) ) { - temp = add( temp, 1 ); + temp = add( temp, 1 ); /* Q0 */ } ELSE { - temp = add( temp, 2 ); + 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 ); + temp = add( temp, 1 ); /* Q0 */ } } } @@ -387,7 +389,7 @@ void hdecnrm_tran_fx( } } -*pidx++ = temp; +*pidx++ = temp; /* Q0 */ move16(); } diff --git a/lib_dec/ivas_stereo_dft_dec_fx.c b/lib_dec/ivas_stereo_dft_dec_fx.c index 1c5a15e28..71aaec7df 100644 --- a/lib_dec/ivas_stereo_dft_dec_fx.c +++ b/lib_dec/ivas_stereo_dft_dec_fx.c @@ -3127,14 +3127,14 @@ void stereo_dft_generate_res_pred_fx( move32(); FOR( i = max( hStereoDft->band_limits[b], bin0 ); i < min( hStereoDft->band_limits[b + 1], STEREO_DFT32MS_N_32k / 2 ); i++ ) { - dmx_nrg = L_add( dmx_nrg, Madd_32_32( Mpy_32_32( pDFT_DMX[2 * i], pDFT_DMX[2 * i] ), pDFT_DMX[2 * i + 1], pDFT_DMX[2 * i + 1] ) ); /* 2 * q_dft - 31 */ + dmx_nrg = L_add( dmx_nrg, L_shr( Madd_32_32( Mpy_32_32( pDFT_DMX[2 * i], pDFT_DMX[2 * i] ), pDFT_DMX[2 * i + 1], pDFT_DMX[2 * i + 1] ), 1 ) ); /* 2 * q_dft - 31 - 1 */ DFT_PRED_RES[2 * i] = L_add( L_shl( Mpy_32_16_1( hStereoDft->DFT_past_DMX_fx[d_short_ind][2 * i], g_short ), q_shift0 ), L_shl( Mpy_32_16_1( hStereoDft->DFT_past_DMX_fx[d_long_ind][2 * i], g_long ), q_shift1 ) ); /* q_dft */ move32(); DFT_PRED_RES[2 * i + 1] = L_add( L_shl( Mpy_32_16_1( hStereoDft->DFT_past_DMX_fx[d_short_ind][2 * i + 1], g_short ), q_shift0 ), L_shl( Mpy_32_16_1( hStereoDft->DFT_past_DMX_fx[d_long_ind][2 * i + 1], g_long ), q_shift1 ) ); /* q_dft */ move32(); - past_dmx_nrg = L_add( past_dmx_nrg, Madd_32_32( Mpy_32_32( DFT_PRED_RES[2 * i], DFT_PRED_RES[2 * i] ), DFT_PRED_RES[2 * i + 1], DFT_PRED_RES[2 * i + 1] ) ); /* 2 * q_dft - 31 */ + past_dmx_nrg = L_add( past_dmx_nrg, L_shr( Madd_32_32( Mpy_32_32( DFT_PRED_RES[2 * i], DFT_PRED_RES[2 * i] ), DFT_PRED_RES[2 * i + 1], DFT_PRED_RES[2 * i + 1] ), 1 ) ); /* 2 * q_dft - 31 -1 */ } op1 = L_deposit_h( BASOP_Util_Divide3232_Scale( ( EPSILON_FIX + dmx_nrg ), ( EPSILON_FIX + past_dmx_nrg ), &q_div ) ); /* q_div + 16 */ q_norm_fac = q_div; diff --git a/lib_dec/stat_dec.h b/lib_dec/stat_dec.h index 9304dc325..cc6f7c5be 100644 --- a/lib_dec/stat_dec.h +++ b/lib_dec/stat_dec.h @@ -778,7 +778,7 @@ typedef struct tcx_dec_structure #ifndef IVAS_FLOAT_FIXED float cummulative_damping_tcx_float; #endif - Word16 cummulative_damping_tcx; + Word16 cummulative_damping_tcx; // Q15 } TCX_DEC_DATA, *TCX_DEC_HANDLE; diff --git a/lib_rend/ivas_prot_rend.h b/lib_rend/ivas_prot_rend.h index a3c6d0e1b..033086191 100644 --- a/lib_rend/ivas_prot_rend.h +++ b/lib_rend/ivas_prot_rend.h @@ -1872,10 +1872,10 @@ ivas_error ivas_reverb_process( ); #ifdef IVAS_FLOAT_FIXED void ivas_rev_delay_line_init( - ivas_rev_delay_line_t *pDelay, /* o : the delay line to initialize */ - Word32 *memory_buffer, /* i : the memory buffer to use for the delay line */ - const UWord16 delay, /* i : the delay */ - const UWord16 maxdelay /* i : maximum delay to be supported */ + ivas_rev_delay_line_t *pDelay, /* o : the delay line to initialize */ + Word32 *memory_buffer, /* i : the memory buffer to use for the delay line Q11 */ + const UWord16 delay, /* i : the delay */ + const UWord16 maxdelay /* i : maximum delay to be supported */ ); #else void ivas_rev_delay_line_init( @@ -1887,13 +1887,13 @@ void ivas_rev_delay_line_init( #endif #ifdef IVAS_FLOAT_FIXED /*! r: sample gotten out of delay line, and amplified by set gain */ -Word32 ivas_rev_delay_line_get_sample_fx( - ivas_rev_delay_line_t *pDelay /* i/o: the delay line */ +Word32 ivas_rev_delay_line_get_sample_fx( /* Q11 */ + ivas_rev_delay_line_t *pDelay /* i/o: the delay line */ ); void ivas_rev_delay_line_feed_sample_fx( - ivas_rev_delay_line_t *pDelay, /* i : the delay line */ - Word32 input /* i : the sample to feed */ + ivas_rev_delay_line_t *pDelay, /* i : the delay line */ + Word32 input /* i : the sample to feed Q11 */ ); void ivas_rev_delay_line_get_sample_blk_fx( @@ -1903,9 +1903,9 @@ void ivas_rev_delay_line_get_sample_blk_fx( ); void ivas_rev_delay_line_feed_sample_blk_fx( - ivas_rev_delay_line_t *pDelay, /* i/o: the delay line */ - const UWord16 blk_size, /* i : number of samples in the input data block */ - Word32 *input /* i : the samples to feed */ + ivas_rev_delay_line_t *pDelay, /* i/o: the delay line */ + const UWord16 blk_size, /* i : number of samples in the input data block */ + Word32 *input /* i : the samples to feed Q11 */ ); #else /*! r: sample gotten out of delay line, and amplified by set gain */ @@ -1987,20 +1987,20 @@ void ivas_reverb_t2f_f2t_ClearHistory( ivas_reverb_t2f_f2t_t *t2f_f2t ); #ifdef IVAS_FLOAT_FIXED -void ivas_reverb_t2f_f2t_in_fx( - ivas_reverb_t2f_f2t_t *t2f_f2t, - Word32 *input_L, - Word32 *input_R, - Word32 *buffer_L, - Word32 *buffer_R +void ivas_reverb_t2f_f2t_in_fx( + ivas_reverb_t2f_f2t_t *t2f_f2t, + Word32 *input_L, // i: Qx + Word32 *input_R, // i: Qx + Word32 *buffer_L, // o: Qx + 1 + Word32 *buffer_R // o: Qx + 1 ); void ivas_reverb_t2f_f2t_out_fx( ivas_reverb_t2f_f2t_t *t2f_f2t, - Word32 *buffer_L, - Word32 *buffer_R, - Word32 *output_L, - Word32 *output_R + Word32 *buffer_L, // i/o: Qx + Word32 *buffer_R, // i/o: Qx + Word32 *output_L, // i/o: Qx + Word32 *output_R // i/o: Qx ); #else void ivas_reverb_t2f_f2t_in( @@ -2025,12 +2025,12 @@ Word16 ivas_reverb_fft_filter_init( ); void ivas_reverb_fft_filter_ComplexMul_fx( - ivas_reverb_fft_filter_t *fft_filter, - Word32 *buffer + ivas_reverb_fft_filter_t *fft_filter, /* i */ + Word32 *buffer /* i/o: Qx */ ); void ivas_reverb_fft_filter_CrossMix_fx( - Word32 *buffer0, - Word32 *buffer1, + Word32 *buffer0, // i/o: Qx + Word32 *buffer1, // i/o: Qx const Word16 fft_size ); #else @@ -2057,9 +2057,9 @@ void ivas_reverb_fft_filter_ConvertFFTWF_2_FFTR( ); #ifdef IVAS_FLOAT_FIXED void ivas_reverb_fft_filter_ConvertFFTWF_2_FFTR_fx( - rv_fftwf_type_complex_fx *spectrum, - Word32 *fft_real, - const Word16 fft_size); + rv_fftwf_type_complex_fx *spectrum, // i: Qx + Word32 *fft_real, // o: Qx + const Word16 fft_size); void ivas_reverb_define_window_fft_fx( Word32 *pWindow, //output in Q31 const Word16 transitionStart, diff --git a/lib_rend/ivas_reverb_delay_line.c b/lib_rend/ivas_reverb_delay_line.c index 32599fd27..9025b1597 100644 --- a/lib_rend/ivas_reverb_delay_line.c +++ b/lib_rend/ivas_reverb_delay_line.c @@ -48,10 +48,10 @@ *-----------------------------------------------------------------------------------------*/ void ivas_rev_delay_line_init( - ivas_rev_delay_line_t *pDelay, /* o : the delay line to initialize */ - Word32 *memory_buffer, /* i : the memory buffer to use for the delay line */ - const UWord16 delay, /* i : the delay */ - const UWord16 maxdelay /* i : maximum delay to be supported */ + ivas_rev_delay_line_t *pDelay, /* o : the delay line to initialize */ + Word32 *memory_buffer, /* i : the memory buffer to use for the delay line Q11 */ + const UWord16 delay, /* i : the delay */ + const UWord16 maxdelay /* i : maximum delay to be supported */ ) { pDelay->MaxDelay = maxdelay; @@ -85,11 +85,11 @@ void ivas_rev_delay_line_init( *-----------------------------------------------------------------------------------------*/ void ivas_rev_delay_line_feed_sample_fx( - ivas_rev_delay_line_t *pDelay, /* i : the delay line */ - Word32 input /* i : the sample to feed */ + ivas_rev_delay_line_t *pDelay, /* i : the delay line */ + Word32 input /* i : the sample to feed Q11 */ ) { - pDelay->pBuffer_fx[pDelay->BufferPos] = input; + pDelay->pBuffer_fx[pDelay->BufferPos] = input; // Q11 pDelay->BufferPos = u_extract_l( UL_addNsD( pDelay->BufferPos, 1 ) ); move16(); @@ -223,9 +223,9 @@ void ivas_rev_delay_line_feed_sample_blk( *-----------------------------------------------------------------------------------------*/ void ivas_rev_delay_line_feed_sample_blk_fx( - ivas_rev_delay_line_t *pDelay, /* i/o: the delay line */ - const UWord16 blk_size, /* i : number of samples in the input data block */ - Word32 *input /* i : the samples to feed */ + ivas_rev_delay_line_t *pDelay, /* i/o: the delay line */ + const UWord16 blk_size, /* i : number of samples in the input data block */ + Word32 *input /* i : the samples to feed Q11 */ ) { Word32 *pDst, *pSrc; @@ -246,14 +246,14 @@ void ivas_rev_delay_line_feed_sample_blk_fx( pDst = &pDelay->pBuffer_fx[pos]; FOR( i = 0; i < blk_size_1; i++ ) { - pDst[i] = input[i]; + pDst[i] = input[i]; // Q11 move32(); } - pDst = &pDelay->pBuffer_fx[0]; - pSrc = &input[blk_size_1]; + pDst = &pDelay->pBuffer_fx[0]; // Q11 + pSrc = &input[blk_size_1]; // Q11 FOR( i = 0; i < blk_size_2; i++ ) { - pDst[i] = pSrc[i]; + pDst[i] = pSrc[i]; // Q11 move32(); } pos = blk_size_2; @@ -261,10 +261,10 @@ void ivas_rev_delay_line_feed_sample_blk_fx( } ELSE /* copy only 1 data block directly if it fits in the buffer */ { - pDst = &pDelay->pBuffer_fx[pos]; + pDst = &pDelay->pBuffer_fx[pos]; // Q11 FOR( i = 0; i < blk_size; i++ ) { - pDst[i] = input[i]; + pDst[i] = input[i]; // Q11 move32(); } pos = (UWord16) L_add( pos, blk_size ); @@ -289,8 +289,8 @@ void ivas_rev_delay_line_feed_sample_blk_fx( *-----------------------------------------------------------------------------------------*/ /*! r: sample gotten out of delay line, and amplified by set gain */ -Word32 ivas_rev_delay_line_get_sample_fx( - ivas_rev_delay_line_t *pDelay /* i/o: the delay line */ +Word32 ivas_rev_delay_line_get_sample_fx( /* Q11 */ + ivas_rev_delay_line_t *pDelay /* i/o: the delay line */ ) { IF( EQ_16( pDelay->Gain_fx, ONE_IN_Q14 ) ) @@ -301,7 +301,7 @@ Word32 ivas_rev_delay_line_get_sample_fx( ELSE { - return ( L_shl( Mpy_32_16_r( pDelay->pBuffer_fx[pDelay->BufferPos], pDelay->Gain_fx ), 1 ) ); + return ( L_shl( Mpy_32_16_r( pDelay->pBuffer_fx[pDelay->BufferPos], pDelay->Gain_fx ), 1 ) ); // Q11 + Q14 - 15 + 1 = Q11 } } /*-----------------------------------------------------------------------------------------* @@ -311,9 +311,9 @@ Word32 ivas_rev_delay_line_get_sample_fx( *-----------------------------------------------------------------------------------------*/ void ivas_rev_delay_line_get_sample_blk_fx( - ivas_rev_delay_line_t *pDelay, /* i : the delay line */ - const UWord16 blk_size, /* i : number of samples in the data block */ - Word32 *output /* i/o: amples gotten out of delay line, and amplified by set gainin */ + ivas_rev_delay_line_t *pDelay, /* i : the delay line */ + const UWord16 blk_size, /* i : number of samples in the data block */ + Word32 *output /* i/o: amples gotten out of delay line, and amplified by set gainin Q11 */ ) { Word32 *pDst, *pSrc; @@ -334,16 +334,16 @@ void ivas_rev_delay_line_get_sample_blk_fx( move16(); blk_size_2 = (UWord16) L_sub( blk_size, blk_size_1 ); move16(); - pSrc = &pDelay->pBuffer_fx[pos]; + pSrc = &pDelay->pBuffer_fx[pos]; // Q11 IF( EQ_16( gain, ONE_IN_Q14 ) ) { FOR( i = 0; i < blk_size_1; i++ ) { - output[i] = pSrc[i]; + output[i] = pSrc[i]; // Q11 move32(); } - pSrc = &pDelay->pBuffer_fx[0]; - pDst = &output[blk_size_1]; + pSrc = &pDelay->pBuffer_fx[0]; // Q11 + pDst = &output[blk_size_1]; // Q11 FOR( i = 0; i < blk_size_2; i++ ) { pDst[i] = pSrc[i]; @@ -354,14 +354,14 @@ void ivas_rev_delay_line_get_sample_blk_fx( { FOR( i = 0; i < blk_size_1; i++ ) { - output[i] = L_shl( Mpy_32_16_r( pSrc[i], gain ), 1 ); + output[i] = L_shl( Mpy_32_16_r( pSrc[i], gain ), 1 ); // Q11 + Q14 - 15 + 1 = Q11 move32(); } pSrc = &pDelay->pBuffer_fx[0]; pDst = &output[blk_size_1]; FOR( i = 0; i < blk_size_2; i++ ) { - pDst[i] = L_shl( Mpy_32_16_r( pSrc[i], gain ), 1 ); + pDst[i] = L_shl( Mpy_32_16_r( pSrc[i], gain ), 1 ); // Q11 + Q14 - 15 + 1 = Q11 move32(); } } @@ -374,7 +374,7 @@ void ivas_rev_delay_line_get_sample_blk_fx( { FOR( i = 0; i < blk_size; i++ ) { - output[i] = pSrc[i]; + output[i] = pSrc[i]; // Q11 move32(); } } @@ -382,7 +382,7 @@ void ivas_rev_delay_line_get_sample_blk_fx( { FOR( i = 0; i < blk_size; i++ ) { - output[i] = L_shl( Mpy_32_16_r( pSrc[i], gain ), 1 ); + output[i] = L_shl( Mpy_32_16_r( pSrc[i], gain ), 1 ); // Q11 + Q14 - 15 + 1 = Q11 move32(); } } diff --git a/lib_rend/ivas_reverb_fft_filter.c b/lib_rend/ivas_reverb_fft_filter.c index 2e9ce6cda..bae4d3f36 100644 --- a/lib_rend/ivas_reverb_fft_filter.c +++ b/lib_rend/ivas_reverb_fft_filter.c @@ -139,8 +139,8 @@ uint16_t int_log2( *-----------------------------------------------------------------------------------------*/ static void fft_wrapper_2ch_fx( - Word32 *buffer_L_fx, - Word32 *buffer_R_fx, + Word32 *buffer_L_fx, // input Q: Qx -> output Q: (Qx + 1) + Word32 *buffer_R_fx, // input Q: Qx -> output Q: (Qx + 1) const Word16 fft_size ) { const Word16 half_sz = shr( fft_size, 1 ); @@ -149,27 +149,27 @@ static void fft_wrapper_2ch_fx( DoRTFTn_fx_ivas( buffer_L_fx, buffer_R_fx, fft_size ); /* separating left and right channel spectra */ - buffer_L_fx[0] = L_shl( buffer_L_fx[0], 1 ); + buffer_L_fx[0] = L_shl( buffer_L_fx[0], 1 ); // Qx + 1 move32(); - buffer_R_fx[0] = L_shl( buffer_R_fx[0], 1 ); + buffer_R_fx[0] = L_shl( buffer_R_fx[0], 1 ); // Qx + 1 move32(); FOR( k = 1; k < half_sz; k++ ) { mirror_k = sub( fft_size, k ); - left_re_fx = ( L_add( buffer_L_fx[k], buffer_L_fx[mirror_k] ) ); - left_im_fx = ( L_sub( buffer_R_fx[k], buffer_R_fx[mirror_k] ) ); + left_re_fx = ( L_add( buffer_L_fx[k], buffer_L_fx[mirror_k] ) ); // Qx + 1 + left_im_fx = ( L_sub( buffer_R_fx[k], buffer_R_fx[mirror_k] ) ); // Qx + 1 - right_re_fx = ( L_add( buffer_R_fx[k], buffer_R_fx[mirror_k] ) ); - right_im_fx = L_negate( ( L_sub( buffer_L_fx[k], buffer_L_fx[mirror_k] ) ) ); + right_re_fx = ( L_add( buffer_R_fx[k], buffer_R_fx[mirror_k] ) ); // Qx + 1 + right_im_fx = L_negate( ( L_sub( buffer_L_fx[k], buffer_L_fx[mirror_k] ) ) ); // Qx + 1 - buffer_L_fx[k] = left_re_fx; + buffer_L_fx[k] = left_re_fx; // Qx + 1 move32(); - buffer_R_fx[k] = right_re_fx; + buffer_R_fx[k] = right_re_fx; // Qx + 1 move32(); - buffer_L_fx[mirror_k] = left_im_fx; + buffer_L_fx[mirror_k] = left_im_fx; // Qx + 1 move32(); - buffer_R_fx[mirror_k] = right_im_fx; + buffer_R_fx[mirror_k] = right_im_fx; // Qx + 1 move32(); } @@ -221,8 +221,8 @@ static void fft_wrapper_2ch( *-----------------------------------------------------------------------------------------*/ static void ifft_wrapper_2ch_fx( - Word32 *buffer_L, - Word32 *buffer_R, + Word32 *buffer_L, // i/o: Qx + Word32 *buffer_R, // i/o: Qx const Word16 fft_size ) { Word32 buffer_L_re, buffer_L_im, buffer_R_re, buffer_R_im; @@ -234,22 +234,22 @@ static void ifft_wrapper_2ch_fx( { mirror_k = sub( fft_size, k ); - buffer_L_re = buffer_L[k]; + buffer_L_re = buffer_L[k]; // Qx move32(); - buffer_L_im = buffer_L[mirror_k]; + buffer_L_im = buffer_L[mirror_k]; // Qx move32(); - buffer_R_re = buffer_R[k]; + buffer_R_re = buffer_R[k]; // Qx move32(); - buffer_R_im = buffer_R[mirror_k]; + buffer_R_im = buffer_R[mirror_k]; // Qx move32(); - buffer_L[k] = L_add( buffer_L_re, buffer_R_im ); + buffer_L[k] = L_add( buffer_L_re, buffer_R_im ); // Qx move32(); - buffer_L[mirror_k] = L_sub( buffer_L_re, buffer_R_im ); + buffer_L[mirror_k] = L_sub( buffer_L_re, buffer_R_im ); // Qx move32(); - buffer_R[k] = L_sub( buffer_R_re, buffer_L_im ); + buffer_R[k] = L_sub( buffer_R_re, buffer_L_im ); // Qx move32(); - buffer_R[mirror_k] = L_add( buffer_R_re, buffer_L_im ); + buffer_R[mirror_k] = L_add( buffer_R_re, buffer_L_im ); // Qx move32(); } @@ -441,26 +441,26 @@ void ivas_reverb_t2f_f2t_ClearHistory( void ivas_reverb_t2f_f2t_in_fx( ivas_reverb_t2f_f2t_t *t2f_f2t, - Word32 *input_L, - Word32 *input_R, - Word32 *buffer_L, - Word32 *buffer_R ) + Word32 *input_L, // i: Qx + Word32 *input_R, // i: Qx + Word32 *buffer_L, // o: Qx + 1 + Word32 *buffer_R ) // o: Qx + 1 { Word16 i; Word16 hlen = t2f_f2t->hist_size; move16(); Word16 bsiz = t2f_f2t->block_size; move16(); - Word32 *hist_L = t2f_f2t->fft_history_L_fx; - Word32 *hist_R = t2f_f2t->fft_history_R_fx; + Word32 *hist_L = t2f_f2t->fft_history_L_fx; // Qx + Word32 *hist_R = t2f_f2t->fft_history_R_fx; // Qx Word32 *pL, *pR; /* copy history to buffer */ FOR( i = 0; i < hlen; i++ ) { - buffer_L[i] = hist_L[i]; + buffer_L[i] = hist_L[i]; // Qx move16(); - buffer_R[i] = hist_R[i]; + buffer_R[i] = hist_R[i]; // Qx move16(); } @@ -469,9 +469,9 @@ void ivas_reverb_t2f_f2t_in_fx( pR = &buffer_R[hlen]; FOR( i = 0; i < bsiz; i++ ) { - pL[i] = input_L[i]; + pL[i] = input_L[i]; // Qx move32(); - pR[i] = input_R[i]; + pR[i] = input_R[i]; // Qx move32(); } @@ -480,14 +480,14 @@ void ivas_reverb_t2f_f2t_in_fx( pR = &buffer_R[bsiz]; FOR( i = 0; i < hlen; i++ ) { - hist_L[i] = pL[i]; + hist_L[i] = pL[i]; // Qx move32(); - hist_R[i] = pR[i]; + hist_R[i] = pR[i]; // Qx move32(); } /* do FFT */ - fft_wrapper_2ch_fx( buffer_L, buffer_R, t2f_f2t->fft_size ); + fft_wrapper_2ch_fx( buffer_L, buffer_R, t2f_f2t->fft_size ); // Qx -> Qx + 1 return; } @@ -552,10 +552,10 @@ void ivas_reverb_t2f_f2t_in( void ivas_reverb_t2f_f2t_out_fx( ivas_reverb_t2f_f2t_t *t2f_f2t, - Word32 *buffer_L, - Word32 *buffer_R, - Word32 *output_L, - Word32 *output_R ) + Word32 *buffer_L, // i/o: Qx + Word32 *buffer_R, // i/o: Qx + Word32 *output_L, // i/o: Qx + Word32 *output_R ) // i/o: Qx { Word16 i; Word32 *pL = &buffer_L[t2f_f2t->hist_size]; @@ -565,9 +565,9 @@ void ivas_reverb_t2f_f2t_out_fx( FOR( i = 0; i < t2f_f2t->block_size; i++ ) { - output_L[i] = pL[i]; + output_L[i] = pL[i]; // Qx move32(); - output_R[i] = pR[i]; + output_R[i] = pR[i]; // Qx move32(); } @@ -654,8 +654,9 @@ int16_t ivas_reverb_fft_filter_init( *-----------------------------------------------------------------------------------------*/ void ivas_reverb_fft_filter_ComplexMul_fx( - ivas_reverb_fft_filter_t *fft_filter, - Word32 *buffer ) + ivas_reverb_fft_filter_t *fft_filter, /* i */ + Word32 *buffer /* i/o: Qx */ +) { Word16 f_spec, h, i, j; Word32 *spec; @@ -665,18 +666,18 @@ void ivas_reverb_fft_filter_ComplexMul_fx( h = shr( f_spec, 1 ); spec = fft_filter->fft_spectrum_fx; - buffer[0] = Mpy_32_32( spec[0], buffer[0] ); /* real multiply f0 DC */ + buffer[0] = Mpy_32_32( spec[0], buffer[0] ); /* real multiply f0 DC */ // Q31 + Qx - 31 = Qx move32(); - buffer[h] = Mpy_32_32( spec[h], buffer[h] ); /* real multiply f_spec Nyquist */ + buffer[h] = Mpy_32_32( spec[h], buffer[h] ); /* real multiply f_spec Nyquist */ // Q31 + Qx - 31 = Qx move32(); j = sub( f_spec, 1 ); FOR( i = 1; i < h; i++ ) /*actual complex multiply in loop */ { t = buffer[i]; move32(); - buffer[i] = L_sub( Mpy_32_32( t, spec[i] ), Mpy_32_32( buffer[j], spec[j] ) ); + buffer[i] = L_sub( Mpy_32_32( t, spec[i] ), Mpy_32_32( buffer[j], spec[j] ) ); // Qx + Q31 - 31 = Qx move32(); - buffer[j] = L_add( Mpy_32_32( t, spec[j] ), Mpy_32_32( buffer[j], spec[i] ) ); + buffer[j] = L_add( Mpy_32_32( t, spec[j] ), Mpy_32_32( buffer[j], spec[i] ) ); // Qx + Q31 - 31 = Qx move32(); j = sub( j, 1 ); } @@ -723,22 +724,22 @@ void ivas_reverb_fft_filter_ComplexMul( *-----------------------------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED void ivas_reverb_fft_filter_ConvertFFTWF_2_FFTR_fx( - rv_fftwf_type_complex_fx *spectrum, - Word32 *fft_real, + rv_fftwf_type_complex_fx *spectrum, // i: Qx + Word32 *fft_real, // o: Qx const Word16 fft_size ) { Word16 i, h; h = shr( fft_size, 1 ); - fft_real[0] = spectrum[0][0]; + fft_real[0] = spectrum[0][0]; // Qx move32(); - fft_real[h] = spectrum[h][0]; + fft_real[h] = spectrum[h][0]; // Qx move32(); FOR( i = 1; i < h; i++ ) { - fft_real[i] = spectrum[i][0]; + fft_real[i] = spectrum[i][0]; // Qx move32(); - fft_real[sub( fft_size, i )] = spectrum[i][1]; + fft_real[fft_size - i] = spectrum[i][1]; // Qx move32(); } @@ -775,8 +776,8 @@ void ivas_reverb_fft_filter_ConvertFFTWF_2_FFTR( *-----------------------------------------------------------------------------------------*/ void ivas_reverb_fft_filter_CrossMix_fx( - Word32 *buffer0, - Word32 *buffer1, + Word32 *buffer0, // i/o: Qx + Word32 *buffer1, // i/o: Qx const Word16 fft_size ) { Word32 t; @@ -784,11 +785,11 @@ void ivas_reverb_fft_filter_CrossMix_fx( FOR( i = 0; i < fft_size; i++ ) { - t = buffer0[i]; + t = buffer0[i]; // Qx move32(); - buffer0[i] = L_add( t, buffer1[i] ); + buffer0[i] = L_add( t, buffer1[i] ); // Qx move32(); - buffer1[i] = L_sub( t, buffer1[i] ); + buffer1[i] = L_sub( t, buffer1[i] ); // Qx move32(); } diff --git a/lib_rend/ivas_rom_binaural_crend_head.c b/lib_rend/ivas_rom_binaural_crend_head.c index a34162e49..d688ccded 100644 --- a/lib_rend/ivas_rom_binaural_crend_head.c +++ b/lib_rend/ivas_rom_binaural_crend_head.c @@ -678,7 +678,7 @@ const Word32 *CRendBin_Combined_HRIR_coeff_diffuse_im_16kHz_fx[BINAURAL_CHANNELS #ifndef IVAS_FLOAT_FIXED const float CRendBin_FOA_HRIR_latency_s = 0.000020834f; #else -const Word32 CRendBin_FOA_HRIR_latency_s_fx = 44741; +const Word32 CRendBin_FOA_HRIR_latency_s_fx = 44741; // Q31 #endif // IVAS_FLOAT_FIXED /* Sample Rate = 48000 */ @@ -904,7 +904,7 @@ const Word32 *CRendBin_FOA_HRIR_coeff_diffuse_im_16kHz_fx[BINAURAL_CHANNELS]={NU #ifndef IVAS_FLOAT_FIXED const float CRendBin_HOA2_HRIR_latency_s = 0.000020834f; #else -const Word32 CRendBin_HOA2_HRIR_latency_s_fx = 44741; +const Word32 CRendBin_HOA2_HRIR_latency_s_fx = 44741; // Q31 #endif // IVAS_FLOAT_FIXED /* Sample Rate = 48000 */ diff --git a/lib_rend/ivas_rom_rend.c b/lib_rend/ivas_rom_rend.c index 3012dad11..ae3482a4f 100644 --- a/lib_rend/ivas_rom_rend.c +++ b/lib_rend/ivas_rom_rend.c @@ -204,9 +204,9 @@ const float * const ap_lattice_coeffs[DIRAC_DECORR_NUM_SPLIT_BANDS] = }; #else -const Word16 ap_lattice_coeffs_1_fx[330] = { 26061, 16472, 6699, 13650, 15061, 8862, -6617, 917, 2222, -1724, -1270, -1880, 671, 12048, -19454, 17487, 6635, -63, 6392, -6044, -7663, 7474, -10790, -11098, -2611, 1716, -310, 5859, 6253, -15691, 1442, 25837, 4375, -5690, 17871, 22329, 10907, 9656, 10658, 1560, 5157, 3810, 7175, -6201, -10400, -24696, 25309, -16625, 9076, -22700, 7612, -11624, -511, -7309, 10174, -1147, 2810, -16383, 7053, 6599, -16238, -9884, 6439, 10687, -19476, 10319, 21911, 2511, 1497, -4089, -6660, -9738, 4122, -5881, -6611, 5279, 12977, 8745, 11684, 15995, -1843, 4563, -9712, -3697, 1225, -12039, -7087, -9088, 12760, 3772, -7879, -8880, 13982, -362, 4974, 8306, 7397, 16341, -4468, 14516, -9994, -1025, -352, 5581, 16268, -4583, -7929, -3435, 9645, -2219, -16128, -15978, 1192, 3584, 12981, -11562, -6747, -2719, -15172, -10135, 848, -3029, -4100, -5115, -160, 5847, 2935, 1468, 7805, -10227, -12802, -5850, 14890, 12681, -12742, -6481, 1164, 14922, -1782, 12452, 9534, 1599, 2576, 7265, -7128, 3974, -12998, -7159, -4170, -8831, -11279, -15238, -13808, -852, 7259, 11861, -11411, 9666, 11998, 2315, -2819, 8261, 5113, -2057, 13401, 7944, -9888, -2167, 12735, -15146, -5206, 7562, -3053, 1542, 2405, -10977, 751, 11619, 2372, 638, 11039, -15746, 5579, 8508, -12896, -11422, -3570, 9137, 12631, 11870, -10444, 11872, 9467, 9542, -9110, -14722, -9453, -13565, -13280, -9671, -8031, 82, 9433, 11410, -5844, -6767, 11504, -15800, 699, -16128, 1593, 14853, 3576, 7621, -15524, 4603, 11551, -3231, 4822, -1828, 3530, -7570, 11708, 11404, 7615, -10642, 5324, 1888, -1990, -319, -7346, -9252, -2144, 2119, 9187, -9335, -15417, 638, -14493, 12360, 14659, -9519, 11322, 12130, -10260, 3918, 9830, 13336, -9106, 14648, 6383, 5167, -7320, -4822, 12421, -7089, 4520, -13014, 2421, -8949, -14517, -5515, 11346, 1230, 2142, 5370, -4014, 11975, -10365, 3842, -9872, 5558, -11025, 8844, -13767, -10855, 16335, -12878, -15144, -10587, 15432, -11778, 8661, 7104, 16167, 4963, -10539, 15217, -11654, 13775, 6039, -9900, 4474, -8285, 6353, 9790, 7825, -12658, -5963, -2533, 4090, -8630, 12766, 147, 11134, 13605, 12378, 13114, 11548, -124, -6046, 14199, -7784, 4839, 13343, 2215, -8169, -11600, 10516, 13959, 10144, -6215, -6863, 5209, -2684, 12675, 5851, -13341, 7280, -4885, }; -const Word16 ap_lattice_coeffs_2_fx[132] = { 20764, 22321, -1619, 9395, 4784, 4436, -13439, -6775, -21527, -3334, 14296, 11135, -4305, -25354, -9883, 10733, 10886, 6745, 23514, -18100, -4919, 1787, 7848, -21249, -23653, 6205, 2234, 203, 2523, 1267, 13874, -3560, 14157, -13586, 9104, 13712, 2549, -9275, -11698, 151, -14504, -12200, 13216, 7963, 10301, 14565, 11387, 16254, 3552, 15380, -5579, 10692, 5641, 14428, 1914, 11130, -6388, 16096, -9217, -1412, -15810, -10977, -11015, 6437, -5394, 14499, -4429, -11612, 14815, -10198, -11391, 16329, -9469, 12334, -5830, 6407, 10940, -5003, 1744, 15000, 14499, 7708, -11310, -9374, 5093, 13283, 7113, -3537, 350, 12090, -16330, -16246, -7060, -3075, 10494, -453, 16036, 15427, -2157, 11366, 893, 4918, 15860, -16298, 5531, -16182, -5686, 10966, 8658, -13914, -10319, 8293, 13021, -16107, -14867, -15183, -626, 11, 10336, 15477, 3117, 9285, -7375, -3924, -15626, 1229, 11041, 16204, -2051, 5821, 15200, 16032, }; -const Word16 ap_lattice_coeffs_3_fx[66] = { 621, -6953, 13851, -13128, -3502, -805, 4587, 9161, 1060, 20726, 18957, -24071, 563, 433, -908, -11578, -15799, -16097, 14975, 5410, 15391, -6412, 14421, -15642, 11802, -16074, 15880, -5694, 247, 9115, 14234, 1977, -6347, -1104, 16260, 96, -15756, -3589, -760, 10639, -9570, -11670, -12012, 12481, -9887, 3614, 12575, 9960, -16373, -11455, 10969, -662, -14092, -5069, -12161, 10947, 11367, -5465, -7506, 3865, 11183, 16071, 16176, -12049, 13976, -1499, }; +const Word16 ap_lattice_coeffs_1_fx[330] /* Q15 */ = { 26061, 16472, 6699, 13650, 15061, 8862, -6617, 917, 2222, -1724, -1270, -1880, 671, 12048, -19454, 17487, 6635, -63, 6392, -6044, -7663, 7474, -10790, -11098, -2611, 1716, -310, 5859, 6253, -15691, 1442, 25837, 4375, -5690, 17871, 22329, 10907, 9656, 10658, 1560, 5157, 3810, 7175, -6201, -10400, -24696, 25309, -16625, 9076, -22700, 7612, -11624, -511, -7309, 10174, -1147, 2810, -16383, 7053, 6599, -16238, -9884, 6439, 10687, -19476, 10319, 21911, 2511, 1497, -4089, -6660, -9738, 4122, -5881, -6611, 5279, 12977, 8745, 11684, 15995, -1843, 4563, -9712, -3697, 1225, -12039, -7087, -9088, 12760, 3772, -7879, -8880, 13982, -362, 4974, 8306, 7397, 16341, -4468, 14516, -9994, -1025, -352, 5581, 16268, -4583, -7929, -3435, 9645, -2219, -16128, -15978, 1192, 3584, 12981, -11562, -6747, -2719, -15172, -10135, 848, -3029, -4100, -5115, -160, 5847, 2935, 1468, 7805, -10227, -12802, -5850, 14890, 12681, -12742, -6481, 1164, 14922, -1782, 12452, 9534, 1599, 2576, 7265, -7128, 3974, -12998, -7159, -4170, -8831, -11279, -15238, -13808, -852, 7259, 11861, -11411, 9666, 11998, 2315, -2819, 8261, 5113, -2057, 13401, 7944, -9888, -2167, 12735, -15146, -5206, 7562, -3053, 1542, 2405, -10977, 751, 11619, 2372, 638, 11039, -15746, 5579, 8508, -12896, -11422, -3570, 9137, 12631, 11870, -10444, 11872, 9467, 9542, -9110, -14722, -9453, -13565, -13280, -9671, -8031, 82, 9433, 11410, -5844, -6767, 11504, -15800, 699, -16128, 1593, 14853, 3576, 7621, -15524, 4603, 11551, -3231, 4822, -1828, 3530, -7570, 11708, 11404, 7615, -10642, 5324, 1888, -1990, -319, -7346, -9252, -2144, 2119, 9187, -9335, -15417, 638, -14493, 12360, 14659, -9519, 11322, 12130, -10260, 3918, 9830, 13336, -9106, 14648, 6383, 5167, -7320, -4822, 12421, -7089, 4520, -13014, 2421, -8949, -14517, -5515, 11346, 1230, 2142, 5370, -4014, 11975, -10365, 3842, -9872, 5558, -11025, 8844, -13767, -10855, 16335, -12878, -15144, -10587, 15432, -11778, 8661, 7104, 16167, 4963, -10539, 15217, -11654, 13775, 6039, -9900, 4474, -8285, 6353, 9790, 7825, -12658, -5963, -2533, 4090, -8630, 12766, 147, 11134, 13605, 12378, 13114, 11548, -124, -6046, 14199, -7784, 4839, 13343, 2215, -8169, -11600, 10516, 13959, 10144, -6215, -6863, 5209, -2684, 12675, 5851, -13341, 7280, -4885, }; +const Word16 ap_lattice_coeffs_2_fx[132] /* Q15 */ = { 20764, 22321, -1619, 9395, 4784, 4436, -13439, -6775, -21527, -3334, 14296, 11135, -4305, -25354, -9883, 10733, 10886, 6745, 23514, -18100, -4919, 1787, 7848, -21249, -23653, 6205, 2234, 203, 2523, 1267, 13874, -3560, 14157, -13586, 9104, 13712, 2549, -9275, -11698, 151, -14504, -12200, 13216, 7963, 10301, 14565, 11387, 16254, 3552, 15380, -5579, 10692, 5641, 14428, 1914, 11130, -6388, 16096, -9217, -1412, -15810, -10977, -11015, 6437, -5394, 14499, -4429, -11612, 14815, -10198, -11391, 16329, -9469, 12334, -5830, 6407, 10940, -5003, 1744, 15000, 14499, 7708, -11310, -9374, 5093, 13283, 7113, -3537, 350, 12090, -16330, -16246, -7060, -3075, 10494, -453, 16036, 15427, -2157, 11366, 893, 4918, 15860, -16298, 5531, -16182, -5686, 10966, 8658, -13914, -10319, 8293, 13021, -16107, -14867, -15183, -626, 11, 10336, 15477, 3117, 9285, -7375, -3924, -15626, 1229, 11041, 16204, -2051, 5821, 15200, 16032, }; +const Word16 ap_lattice_coeffs_3_fx[66] /* Q15 */ = { 621, -6953, 13851, -13128, -3502, -805, 4587, 9161, 1060, 20726, 18957, -24071, 563, 433, -908, -11578, -15799, -16097, 14975, 5410, 15391, -6412, 14421, -15642, 11802, -16074, 15880, -5694, 247, 9115, 14234, 1977, -6347, -1104, 16260, 96, -15756, -3589, -760, 10639, -9570, -11670, -12012, 12481, -9887, 3614, 12575, 9960, -16373, -11455, 10969, -662, -14092, -5069, -12161, 10947, 11367, -5465, -7506, 3865, 11183, 16071, 16176, -12049, 13976, -1499, }; const Word16 * const ap_lattice_coeffs_fx[DIRAC_DECORR_NUM_SPLIT_BANDS] = { @@ -269,7 +269,7 @@ const float surCohEne[MASA_NUM_DEFINED_SUR_SPR_COH_ENE_BINS] = 3.0903f, 2.0053f, 1.0860f, 0.8072f, 0.7079f }; #else -const Word16 surCohEne_fx[MASA_NUM_DEFINED_SUR_SPR_COH_ENE_BINS] = +const Word16 surCohEne_fx[MASA_NUM_DEFINED_SUR_SPR_COH_ENE_BINS] /* Q13 */ = { 25315, 16427, 8896, 6612, 5799 }; @@ -302,7 +302,7 @@ const float lowBitRateBinauralEQ[LOW_BIT_RATE_BINAURAL_EQ_BINS] = 0.979f, 0.893f, 0.762f, 0.615f, 0.52f, 0.48f, 0.477f, 0.477f, 0.48f, 0.501f, 0.546f, 0.602f, 0.652f, 0.664f, 0.652f, 0.639f, 0.635f }; #else -const Word32 lowBitRateBinauralEQ_fx[LOW_BIT_RATE_BINAURAL_EQ_BINS] = +const Word32 lowBitRateBinauralEQ_fx[LOW_BIT_RATE_BINAURAL_EQ_BINS] /* Q31 */ = { 2102386432, 1917702912, 1636382592, 1320702464, 1116691456, 1030792128, 1024349696, 1024349696, 1030792128, 1075889280, 1172526080, 1292785152, 1400159360, 1425929088, 1400159360, 1372242048, 1363652096 -- GitLab From 7b6cf17a7e0165faa2f8c5d9db9d9f9fa2217416 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Wed, 23 Oct 2024 13:29:47 +0530 Subject: [PATCH 023/128] Q information for decoder and renderer files - 2 --- lib_dec/dlpc_stoch_fx.c | 30 +- lib_dec/er_dec_acelp_fx.c | 234 ++--- lib_dec/er_dec_tcx_fx.c | 372 ++++---- lib_dec/ivas_decision_matrix_dec.c | 13 +- lib_dec/ivas_dirac_dec.c | 405 +++++---- lib_dec/ivas_dirac_output_synthesis_cov.c | 206 ++--- lib_dec/tonalMDCTconcealment.c | 58 +- lib_dec/tonalMDCTconcealment_fx.c | 506 +++++------ lib_dec/transition_dec_fx.c | 52 +- lib_dec/updt_dec_fx.c | 87 +- lib_dec/vlpc_1st_dec_fx.c | 6 +- lib_dec/vlpc_2st_dec_fx.c | 2 +- lib_dec/voiced_dec_fx.c | 12 +- lib_dec/waveadjust_fec_dec_fx.c | 130 +-- lib_rend/ivas_dirac_output_synthesis_dec.c | 965 +++++++++++---------- 15 files changed, 1578 insertions(+), 1500 deletions(-) diff --git a/lib_dec/dlpc_stoch_fx.c b/lib_dec/dlpc_stoch_fx.c index e06a2d515..6583c91de 100644 --- a/lib_dec/dlpc_stoch_fx.c +++ b/lib_dec/dlpc_stoch_fx.c @@ -15,14 +15,14 @@ void lpc_unquantize_fx( Decoder_State *st, - Word16 *lsf, - Word16 *lsp, + Word16 *lsf, /*x2.56*/ + Word16 *lsp, /*Q15*/ const Word16 m, - Word16 *param_lpc, - Word16 *lspmid, - Word16 *lsfmid, + Word16 *param_lpc, /*Q0*/ + Word16 *lspmid, /*Q15*/ + Word16 *lsfmid, /*x2.56*/ Word16 coder_type, - Word16 *LSF_Q_prediction /* o : LSF prediction mode */ + Word16 *LSF_Q_prediction /* o : LSF prediction mode Q0*/ ) { Word16 nb_indices, k; @@ -31,15 +31,15 @@ void lpc_unquantize_fx( nb_indices = 0; /* to avoid compilation warnings */ move16(); - Copy( st->lsf_old_fx, &lsf[0], m ); - Copy( st->lsp_old_fx, &lsp[0], m ); + Copy( st->lsf_old_fx, &lsf[0], m ); /*x2.56*/ + Copy( st->lsp_old_fx, &lsp[0], m ); /*x2.56*/ IF( st->lpcQuantization == 0 ) { - nb_indices = dlpc_avq_fx( param_lpc, &lsf[m], st->numlpc, st->sr_core ); + nb_indices = dlpc_avq_fx( param_lpc, &lsf[m], st->numlpc, st->sr_core ); /*Q0*/ FOR( k = 0; k < st->numlpc; k++ ) { - E_LPC_lsf_lsp_conversion( &lsf[imult1616( add( k, 1 ), m )], &lsp[imult1616( add( k, 1 ), m )], m ); + E_LPC_lsf_lsp_conversion( &lsf[( ( k + 1 ) * m )], &lsp[( ( k + 1 ) * m )], m ); /*Q15*/ } } ELSE IF( EQ_16( st->lpcQuantization, 1 ) ) @@ -76,7 +76,7 @@ void lpc_unquantize_fx( } } - lsf2lsp_fx( &lsf[m], &lsp[m], M, st->sr_core ); + lsf2lsp_fx( &lsf[m], &lsp[m], M, st->sr_core ); /*Q15*/ } ELSE { @@ -87,7 +87,7 @@ void lpc_unquantize_fx( move16(); FOR( i = nb_indices - 1; i >= 0; i-- ) { - st->seed_acelp = extract_l( L_mac0( L_mac0( 13849, shr( st->seed_acelp, 1 ), 31821 ), param_lpc[i], 31821 ) ); + st->seed_acelp = extract_l( L_mac0( L_mac0( 13849 /*Q0*/, shr( st->seed_acelp, 1 ), 31821 /*Q0*/ ), param_lpc[i], 31821 /*Q0*/ ) ); /*Q0*/ } /* Decoded mid-frame isf */ @@ -96,9 +96,9 @@ void lpc_unquantize_fx( test(); IF( st->lpcQuantization && st->acelp_cfg.midLpc && EQ_16( st->core, ACELP_CORE ) && st->rate_switching_reset == 0 ) { - midlsf_dec( &lsf[0], &lsf[m], param_lpc[nb_indices], lsfmid, coder_type, &( st->mid_lsf_int ), st->prev_bfi, st->safety_net ); - reorder_lsf_fx( lsfmid, LSF_GAP_MID_FX, M, st->sr_core ); - lsf2lsp_fx( lsfmid, lspmid, M, st->sr_core ); + midlsf_dec( &lsf[0], &lsf[m], param_lpc[nb_indices], lsfmid, coder_type, &( st->mid_lsf_int ), st->prev_bfi, st->safety_net ); /*3Q12*/ + reorder_lsf_fx( lsfmid, LSF_GAP_MID_FX, M, st->sr_core ); /*x2.56*/ + lsf2lsp_fx( lsfmid, lspmid, M, st->sr_core ); /*Q15*/ } diff --git a/lib_dec/er_dec_acelp_fx.c b/lib_dec/er_dec_acelp_fx.c index b093fb129..3d2fdee1c 100644 --- a/lib_dec/er_dec_acelp_fx.c +++ b/lib_dec/er_dec_acelp_fx.c @@ -37,11 +37,11 @@ void con_acelp_fx( Word16 *pgainT, /*mem_syn >rescaling done */ - Word16 *pitch_buffer, - Word16 *voice_factors, - Word16 *bwe_exc ) + const Word16 *Qf_exc, /*mem_syn >rescaling done */ + Word16 *pitch_buffer, /* Q0 */ + Word16 *voice_factors, /* Q6 */ + Word16 *bwe_exc /* Qx */ ) { Word16 i_subfr, i, T0; /*Q0*/ @@ -115,12 +115,12 @@ void con_acelp_fx( *------------------------------------------------------------------------*/ /* set ACELP synthesis memory */ - Copy( st->mem_syn2_fx, mem_syn, M ); + Copy( st->mem_syn2_fx, mem_syn, M ); /* Q_syn */ /* set excitation memory*/ - harmonic_exc_buf = buf + M; - exc = harmonic_exc_buf + L_EXC_MEM_DEC; - Copy( st->old_exc_fx, harmonic_exc_buf, L_EXC_MEM_DEC ); + harmonic_exc_buf = buf + M; /*Qf_exc*/ + exc = harmonic_exc_buf + L_EXC_MEM_DEC; /*Qf_exc*/ + Copy( st->old_exc_fx, harmonic_exc_buf, L_EXC_MEM_DEC ); /*Q_exc*/ exc[st->L_frame] = 0; move16(); @@ -139,7 +139,7 @@ void con_acelp_fx( &st->old_fpitch, &predPitchLag, st->pit_min, st->pit_max, st->mem_pitch_gain, 0, st->plc_use_future_lag, &extrapolationFailed, st->nb_subfr ); - T0 = round_fx( predPitchLag ); + T0 = round_fx( predPitchLag ); /*Q0*/ IF( extrapolationFailed != 0 ) { @@ -160,7 +160,7 @@ void con_acelp_fx( l = shl( L_SUBFR, 1 ); FOR( i = 0; i < l; i++ ) { - exc[i] = exc[sub( i, st->guidedT0 )]; + exc[i] = exc[( i - st->guidedT0 )]; /*Qf_exc*/ move16(); } } @@ -171,11 +171,11 @@ void con_acelp_fx( move16(); } - tmp_tc = st->old_fpitch; - move32(); /* take the previous frame last pitch*/ + tmp_tc = st->old_fpitch; /*15Q16*/ + move32(); /* take the previous frame last pitch*/ if ( nSubframes > 0 ) { - tmp_tc = L_deposit_h( st->guidedT0 ); /* take the transmit pitch*/ + tmp_tc = L_deposit_h( st->guidedT0 ); /* take the transmit pitch*/ /* Q16 */ } /* PLC: [ACELP: Fade-out] @@ -201,7 +201,7 @@ void con_acelp_fx( * Last pitch cycle of the previous frame is repeatedly copied. * *---------------------------------------------------------------*/ - Tc = round_fx( tmp_tc ); + Tc = round_fx( tmp_tc ); /* Q0 */ BASOP_SATURATE_WARNING_OFF_EVS /*if this ever saturates, it doesn't matter*/ #ifdef BASOP_NOGLOB tmp = sub( shl_sat( abs_s( sub( T0, Tc ) ), 6 ), mult( 19661 /*0.15f Q17*/, shl_sat( Tc, 4 ) ) /*Q6*/ ); @@ -221,16 +221,16 @@ void con_acelp_fx( pt_exc = exc; if ( st->enableGplc != 0 ) { - pt_exc = &exc[imult1616( nSubframes, L_SUBFR )]; + pt_exc = &exc[( nSubframes * L_SUBFR )]; /*Qf_exc*/ } - pt1_exc = pt_exc - Tc; + pt1_exc = pt_exc - Tc; /*Qf_exc*/ IF( fUseExtrapolatedPitch != 0 ) { /* Required because later pt1_exc[1] used in filtering points to exc[0]. To make it safe also for GPL pt_exc is used instead of exc */ pt_exc[0] = 0; move16(); - pt_exc = harmonic_exc_buf; + pt_exc = harmonic_exc_buf; /*Qf_exc*/ assert( pt_exc < pt1_exc - 1 ); } @@ -249,10 +249,10 @@ void con_acelp_fx( { /* *pt_exc++ = ( lpFiltAdapt[0] * pt1_exc[-1] + lpFiltAdapt[1] * pt1_exc[0] + lpFiltAdapt[2] * pt1_exc[1]);*/ - tmp_32 = L_mult( lpFiltAdapt[0], pt1_exc[-1] ); - tmp_32 = L_mac( tmp_32, lpFiltAdapt[1], pt1_exc[0] ); - tmp_16 = mac_r( tmp_32, lpFiltAdapt[2], pt1_exc[1] ); - *pt_exc = tmp_16; + tmp_32 = L_mult( lpFiltAdapt[0], pt1_exc[-1] ); /*Q16 + Qf_exc*/ + tmp_32 = L_mac( tmp_32, lpFiltAdapt[1], pt1_exc[0] ); /*Q16 + Qf_exc*/ + tmp_16 = mac_r( tmp_32, lpFiltAdapt[2], pt1_exc[1] ); /*Qf_exc*/ + *pt_exc = tmp_16; /*Qf_exc*/ move16(); pt_exc++; pt1_exc++; @@ -263,20 +263,20 @@ void con_acelp_fx( /* copy the first pitch cycle without low-pass filtering */ FOR( i = 0; i < Tc; i++ ) { - *pt_exc++ = *pt1_exc++; + *pt_exc++ = *pt1_exc++; /*Qf_exc*/ move16(); } } if ( fUseExtrapolatedPitch != 0 ) { - pt1_exc = harmonic_exc_buf; + pt1_exc = harmonic_exc_buf; /*Qf_exc*/ } l = add( st->L_frame, sub( imult1616( L_SUBFR, sub( 1, nSubframes ) ), Tc ) ); FOR( i = 0; i < l; i++ ) { - *pt_exc++ = *pt1_exc++; + *pt_exc++ = *pt1_exc++; /*Qf_exc*/ move16(); } @@ -287,9 +287,9 @@ void con_acelp_fx( IF( nSubframes > 0 ) { - pitch_buf[0] = L_deposit_h( st->guidedT0 ); + pitch_buf[0] = L_deposit_h( st->guidedT0 ); /*Q16*/ move32(); - pitch_buf[1] = L_deposit_h( st->guidedT0 ); + pitch_buf[1] = L_deposit_h( st->guidedT0 ); /*Q16*/ move32(); } @@ -301,7 +301,7 @@ void con_acelp_fx( if ( EQ_16( st->nb_subfr, 5 ) ) { /* for guided acelp cases and nSubframes=2, set pitch_buf[4] to avoid memory_access issues in post_decoder() */ - pitch_buf[4] = pitch_buf[3]; + pitch_buf[4] = pitch_buf[3]; /*Q16*/ move32(); } } @@ -315,7 +315,7 @@ void con_acelp_fx( } ELSE { - set32_fx( pitch_buf, st->old_fpitch, st->nb_subfr ); + set32_fx( pitch_buf, st->old_fpitch, st->nb_subfr ); /*15Q16*/ } } @@ -323,8 +323,8 @@ void con_acelp_fx( * PLC: [ACELP: adaptive codebook] * PLC: Create the harmonic part needed for the overlap-add. *------------------------------------------------------------*/ - pt_exc = exc + st->L_frame; - pt1_exc = pt_exc - T0; + pt_exc = exc + st->L_frame; /*Qf_exc*/ + pt1_exc = pt_exc - T0; /*Qf_exc*/ if ( T0 == 0 ) { pt1_exc = pt_exc - Tc; @@ -343,11 +343,11 @@ void con_acelp_fx( IF( fUseExtrapolatedPitch != 0 ) { - st->old_fpitch = predPitchLag; + st->old_fpitch = predPitchLag; /*Q16*/ move32(); if ( EQ_16( st->flagGuidedAcelp, 1 ) ) { - st->old_fpitch = L_deposit_h( T0 ); + st->old_fpitch = L_deposit_h( T0 ); /*Q16*/ move32(); } } @@ -371,8 +371,8 @@ void con_acelp_fx( /* mapping: floor(( 0.824[15Q15]-x[15Q0]*0.0733[0Q15] )*4) */ - pc = Mpy_32_16_1( L_shl( pc, 1 ) /*precompensate Q14 from table*/, /*15Q16*/ - T_256DIV_L_Frame[L_shr( L_msu0( 54000, shr( st->L_frame, 5 ), 2402 ), 15 - 2 )] ); + pc = Mpy_32_16_1( L_shl( pc, 1 ) /*precompensate Q14 from table*/, /*15Q16*/ + T_256DIV_L_Frame[L_shr( L_msu0( 54000, shr( st->L_frame, 5 ), 2402 ), 15 - 2 )] ); /*Q16*/ test(); test(); /*test();*/ @@ -421,9 +421,9 @@ void con_acelp_fx( { BASOP_SATURATE_WARNING_OFF_EVS #ifdef BASOP_NOGLOB - exc[i] = mult_r( exc[i], shl_sat( gain, 1 ) ); /*overflow is first iteration because gain may be 1 after shift*/ + exc[i] = mult_r( exc[i], shl_sat( gain, 1 ) ); /*overflow is first iteration because gain may be 1 after shift*/ /*Qf_exc*/ #else - exc[i] = mult_r( exc[i], shl( gain, 1 ) ); /*overflow is first iteration because gain may be 1 after shift*/ + exc[i] = mult_r( exc[i], shl( gain, 1 ) ); /*overflow is first iteration because gain may be 1 after shift*/ /*Qf_exc*/ #endif BASOP_SATURATE_WARNING_ON_EVS move16(); @@ -436,9 +436,9 @@ void con_acelp_fx( { BASOP_SATURATE_WARNING_OFF_EVS #ifdef BASOP_NOGLOB - exc[i] = mult_r( exc[i], shl_sat( gain, 1 ) ); /*overflow is first iteration because gain may become 1 due to shift*/ + exc[i] = mult_r( exc[i], shl_sat( gain, 1 ) ); /*overflow is first iteration because gain may become 1 due to shift*/ /*Qf_exc*/ #else - exc[i] = mult_r( exc[i], shl( gain, 1 ) ); /*overflow is first iteration because gain may become 1 due to shift*/ + exc[i] = mult_r( exc[i], shl( gain, 1 ) ); /*overflow is first iteration because gain may become 1 due to shift*/ /*Qf_exc*/ #endif BASOP_SATURATE_WARNING_ON_EVS move16(); @@ -449,12 +449,12 @@ void con_acelp_fx( { pT[i] = round_fx( pitch_buf[i] ); /*Q0*/ move16(); - pitch_buffer[i] = round_fx( pitch_buf[i] ); + pitch_buffer[i] = round_fx( pitch_buf[i] ); /*Q0*/ move16(); } /* update old exc without random part*/ - Copy( harmonic_exc_buf + st->L_frame, st->old_exc_fx, L_EXC_MEM_DEC ); + Copy( harmonic_exc_buf + st->L_frame, st->old_exc_fx, L_EXC_MEM_DEC ); /*Qf_exc*/ } ELSE { @@ -468,9 +468,9 @@ void con_acelp_fx( move32(); pgainT[i] = 0; move16(); - pT[i] = L_SUBFR; + pT[i] = L_SUBFR; /*Q0*/ move16(); - pitch_buffer[i] = L_SUBFR; + pitch_buffer[i] = L_SUBFR; /*Q0*/ move16(); } @@ -486,7 +486,7 @@ void con_acelp_fx( * * search for "Scale from randomized buffer to excitation buffer" *-----------------------------------------------------------------*/ - noise_buf = buf; + noise_buf = buf; /*Qf_exc*/ tmpSeed = st->seed_acelp; move16(); l = add( st->L_frame, sub( l_fir_fer, 1 ) ); @@ -516,7 +516,7 @@ void con_acelp_fx( /* PLC: [ACELP: Fade-out] * PLC: retrieve background level */ - tmp2 = shl( div_s( st->L_frame, shl( L_SUBFR, 3 ) ), 3 - 15 ); + tmp2 = shl( div_s( st->L_frame, shl( L_SUBFR, 3 ) ), 3 - 15 ); /*Q0*/ tmp = 32767 /*1.0f Q15*/; @@ -545,11 +545,11 @@ void con_acelp_fx( #ifdef BASOP_NOGLOB ftmp = round_fx_sat( L_shl_sat( gain_32, 1 ) ); /*Q0*/ #else - ftmp = round_fx( L_shl( gain_32, 1 ) ); /*Q0*/ + ftmp = round_fx( L_shl( gain_32, 1 ) ); /*Q0*/ #endif BASOP_SATURATE_WARNING_OFF_EVS #ifdef BASOP_NOGLOB - tmp_16 = sub( shl_sat( gainCNG, sub( gainCNG_e, 5 /*Q5*/ ) ), ftmp ); + tmp_16 = sub( shl_sat( gainCNG, sub( gainCNG_e, 5 /*Q5*/ ) ), ftmp ); /*Q0*/ #else tmp_16 = sub( shl( gainCNG, sub( gainCNG_e, 5 /*Q5*/ ) ), ftmp ); #endif @@ -594,7 +594,7 @@ void con_acelp_fx( s2 = sub( s2, 4 - 15 ); /*->Q15*/ s_16 = BASOP_Util_Add_MantExp( tmp_16, s_16, tmp2, s2, &tmp_16 ); - st->Mode2_lp_gainc = L_shl( L_deposit_l( tmp_16 ), add( s_16, 1 ) ); + st->Mode2_lp_gainc = L_shl( L_deposit_l( tmp_16 ), add( s_16, 1 ) ); /*Q16*/ move32(); test(); IF( ( EQ_16( st->last_good, UNVOICED_TRANSITION ) ) && ( EQ_16( coder_type, GENERIC ) ) ) @@ -607,13 +607,13 @@ void con_acelp_fx( highPassFiltering_fx( st->last_good, add( st->L_frame, shr( l_fir_fer, 1 ) ), noise_buf, hp_filt, l_fir_fer ); - pt_exc = noise_buf + shr( l_fir_fer, 1 ); + pt_exc = noise_buf + shr( l_fir_fer, 1 ); /*Qf_exc*/ /*** Find energy normalization factor ***/ /*gain_inov = 1.0f / (float)sqrt( dot_product( pt_exc, pt_exc, st->L_frame ) / st->L_frame );*/ /* normalize energy */ /*<--- FLC*/ - BASOP_SATURATE_WARNING_OFF_EVS /*norm_llQ31 at the end of Dot_productSq16HQ may throw an overflow, but result is okay*/ - tmp_32 = Dot_productSq16HQ( 0, pt_exc, st->L_frame, &s_32 ); + BASOP_SATURATE_WARNING_OFF_EVS /*norm_llQ31 at the end of Dot_productSq16HQ may throw an overflow, but result is okay*/ + tmp_32 = Dot_productSq16HQ( 0, pt_exc, st->L_frame, &s_32 ); /*Q31*/ BASOP_SATURATE_WARNING_ON_EVS s_32 = add( s_32, 31 - 1 ); /*scalingfactor is twice the headroom (at noise insertion onto the buffer), -1 (because of mult) +31 (Result is Q31) +s_32 (output scalingfactor of dot_product)*/ @@ -629,7 +629,7 @@ void con_acelp_fx( { s_gain_inov = s_32; move16(); - tmp_32 = ISqrt32( tmp_32, &s_gain_inov ); + tmp_32 = ISqrt32( tmp_32, &s_gain_inov ); /* Q31 - s_gain_inov */ } ELSE { @@ -640,7 +640,7 @@ void con_acelp_fx( } - gain_inov = round_fx( tmp_32 ); /*Inverse sqrt*/ /* Q15 * 2^s_gain_inov */ + gain_inov = round_fx( tmp_32 ); /*Inverse sqrt*/ /* Q15 * 2^s_gain_inov */ /* Q15 - s_gain_inov */ /* PLC: [ACELP: Fade-out] * PLC: Linearly attenuate the gain through the frame */ @@ -661,12 +661,12 @@ void con_acelp_fx( Word16 tilt_code; /*tilt_code = (float)(0.10f*(1.0f + st->voice_fac));*/ - tilt_code = mac_r( 214748368l /*0.1f Q31*/, 3277 /*0.1f Q15*/, st->voice_fac ); + tilt_code = mac_r( 214748368l /*0.1f Q31*/, 3277 /*0.1f Q15*/, st->voice_fac ); /*Q15*/ gain_inov = mult_r( gain_inov, sub( 32767 /*1.0f Q15*/, tilt_code ) ); /* Q15 * 2^s_gain_inov */ } - pt_exc = noise_buf; + pt_exc = noise_buf; /*Qf_exc*/ /* non-causal ringing of the FIR filter */ @@ -690,9 +690,9 @@ void con_acelp_fx( g_e = norm_s( round_fx( L_shl( Mpy_32_16_1( st->Mode2_lp_gainc, gain_inov ), add( 15, s_gain_inov ) ) ) ); /* norm_s for gain*gain_inov at the end of the following loops */ #endif g_e = s_min( norm_s( gain_16 ), g_e ); - gain_16 = shl( gain_16, g_e ); - gain_32 = L_shl( gain_32, g_e ); - step_32 = L_shl( step_32, g_e ); + gain_16 = shl( gain_16, g_e ); /*Q15 + g_e*/ + gain_32 = L_shl( gain_32, g_e ); /*Q31 + g_e*/ + step_32 = L_shl( step_32, g_e ); /*Q31 + g_e*/ l = shr( l_fir_fer, 1 ); FOR( i = 0; i < l; i++ ) { @@ -711,7 +711,7 @@ void con_acelp_fx( pt_exc++; gain_32 = L_sub( gain_32, step_32 ); - gain_16 = round_fx( gain_32 ); + gain_16 = round_fx( gain_32 ); /*Q15*/ } l = add( shr( st->L_frame, 1 ), shr( l_fir_fer, 1 ) ); @@ -735,36 +735,36 @@ void con_acelp_fx( IF( LT_16( st->last_good, UNVOICED_TRANSITION ) ) { - bufferCopyFx( noise_buf + shr( l_fir_fer, 1 ), exc, add( st->L_frame, shr( st->L_frame, 1 ) ), 0, *Qf_exc, negate( g_e ), 0 ); /*copy between different formats*/ - Copy( harmonic_exc_buf + st->L_frame, st->old_exc_fx, L_EXC_MEM_DEC ); - Copy( exc, exc_unv, add( st->L_frame, shr( st->L_frame, 1 ) ) ); /* Update exc_unv */ + bufferCopyFx( noise_buf + shr( l_fir_fer, 1 ), exc, add( st->L_frame, shr( st->L_frame, 1 ) ), 0, *Qf_exc, negate( g_e ), 0 ); /*copy between different formats*/ /*Qf_exc*/ + Copy( harmonic_exc_buf + st->L_frame, st->old_exc_fx, L_EXC_MEM_DEC ); /*Qf_exc*/ + Copy( exc, exc_unv, add( st->L_frame, shr( st->L_frame, 1 ) ) ); /* Update exc_unv */ /*Qf_exc*/ } ELSE { /* Update exc_unv */ - bufferCopyFx( noise_buf + shr( l_fir_fer, 1 ), exc_unv, add( st->L_frame, shr( st->L_frame, 1 ) ), 0, *Qf_exc, negate( g_e ), 0 ); /*copy between different formats*/ + bufferCopyFx( noise_buf + shr( l_fir_fer, 1 ), exc_unv, add( st->L_frame, shr( st->L_frame, 1 ) ), 0, *Qf_exc, negate( g_e ), 0 ); /*copy between different formats*/ /*Qf_exc*/ } /* Compute total excitation in noisebuffer to save memories */ IF( GE_16( st->last_good, UNVOICED_TRANSITION ) ) { - Vr_add( exc, exc_unv, noise_buf, add( st->L_frame, 1 ) ); + Vr_add( exc, exc_unv, noise_buf, add( st->L_frame, 1 ) ); /*Qf_exc*/ } ELSE { - noise_buf = exc_unv; + noise_buf = exc_unv; /*Qf_exc*/ } IF( st->hBWE_TD != NULL ) { IF( EQ_16( st->L_frame, L_FRAME ) ) { interp_code_5over2_fx( noise_buf, bwe_exc, st->L_frame ); - set16_fx( voice_factors, st->last_voice_factor_fx, NB_SUBFR ); + set16_fx( voice_factors, st->last_voice_factor_fx, NB_SUBFR ); /* Q6 */ } ELSE { interp_code_4over2_fx( noise_buf, bwe_exc, st->L_frame ); - set16_fx( voice_factors, st->last_voice_factor_fx, NB_SUBFR16k ); + set16_fx( voice_factors, st->last_voice_factor_fx, NB_SUBFR16k ); /* Q6 */ } } /*----------------------------------------------------------* @@ -773,13 +773,13 @@ void con_acelp_fx( /* Init syn buffer */ syn = buf + M; - Copy( st->mem_syn2_fx, buf, M ); + Copy( st->mem_syn2_fx, buf, M ); /*Q_syn*/ IF( EQ_16( st->nbLostCmpt, 1 ) ) { IF( LT_16( st->last_good, UNVOICED_TRANSITION ) ) { - Copy( st->mem_syn2_fx, mem_syn_unv, M ); + Copy( st->mem_syn2_fx, mem_syn_unv, M ); /*Q_syn*/ } ELSE { @@ -788,7 +788,7 @@ void con_acelp_fx( } ELSE { - Copy( st->mem_syn_unv_back, mem_syn_unv, M ); + Copy( st->mem_syn_unv_back, mem_syn_unv, M ); /*Q_syn*/ } /* voiced synth */ @@ -810,11 +810,11 @@ void con_acelp_fx( /* i_subfr / L_SUBFR */ tmp_16 = shr( i_subfr, Q6 ); /* gain_lpc[i_subfr/L_SUBFR] = 1.f/(float)sqrt(dotp( h1, h1, L_SUBFR)); */ - tmp_32 = Dot_productSq16HQ( 0, h1, L_SUBFR, &gain_lpc_e[tmp_16] ); + tmp_32 = Dot_productSq16HQ( 0, h1, L_SUBFR, &gain_lpc_e[tmp_16] ); /*Q31*/ tmp_32 = L_max( tmp_32, 1 ); gain_lpc_e[tmp_16] = add( gain_lpc_e[tmp_16], shl( scale_h1, 1 ) ); move16(); - gain_lpc[tmp_16] = round_fx( ISqrt32( tmp_32, &gain_lpc_e[tmp_16] ) ); + gain_lpc[tmp_16] = round_fx( ISqrt32( tmp_32, &gain_lpc_e[tmp_16] ) ); /* Q15 - gain_lpc_e[tmp_16] */ move16(); p_A += ( M + 1 ); /* Pointer move */ @@ -826,10 +826,10 @@ void con_acelp_fx( { /* i_subfr / L_SUBFR */ tmp_16 = shr( i_subfr, Q6 ); - g = mult_r( st->last_gain_syn_deemph, gain_lpc[tmp_16] ); + g = mult_r( st->last_gain_syn_deemph, gain_lpc[tmp_16] ); /* Q15 - gain_lpc_e[tmp_16] */ #ifdef BASOP_NOGLOB g_e = add_sat( st->last_gain_syn_deemph_e, gain_lpc_e[tmp_16] ); - g = shl_sat( g, g_e ); + g = shl_sat( g, g_e ); /* Q15 */ #else g_e = add( st->last_gain_syn_deemph_e, gain_lpc_e[tmp_16] ); g = shl( g, g_e ); @@ -838,14 +838,14 @@ void con_acelp_fx( FOR( i = 0; i < L_SUBFR; i++ ) { /* exc[i_subfr + i] *= st->last_gain_syn_deemph*gain_lpc[j]; */ - exc[i_subfr + i] = mult_r( exc[add( i_subfr, i )], g ); + exc[i_subfr + i] = mult_r( exc[( i_subfr + i )], g ); /*Qf_exc*/ move16(); } } l = add( st->L_frame, shr( st->L_frame, 1 ) ); FOR( i = st->L_frame; i < l; i++ ) { - exc[i] = mult_r( exc[i], g ); + exc[i] = mult_r( exc[i], g ); /*Qf_exc*/ move16(); } @@ -866,7 +866,7 @@ void con_acelp_fx( E_UTIL_synthesis( synthScaling, p_A, &exc[i_subfr], &syn[i_subfr], L_SUBFR, mem_syn, 1, M ); p_A += ( M + 1 ); } - Copy( mem_syn, mem_syn2, M ); + Copy( mem_syn, mem_syn2, M ); /*Qf_syn + s_16*/ /* synthesize ola*/ E_UTIL_synthesis( synthScaling, p_A - ( M + 1 ), &exc[i_subfr], &syn[i_subfr], shr( st->L_frame, 1 ), mem_syn2, 0, M ); } @@ -875,8 +875,8 @@ void con_acelp_fx( IF( GT_16( st->nbLostCmpt, 5 ) && ( s_16 > 0 ) ) { /*scale back mem_syn, exc and synthesis*/ - Scale_sig( mem_syn, M, negate( s_16 ) ); - Scale_sig( syn, add( shr( st->L_frame, 1 ), st->L_frame ), negate( s_16 ) ); + Scale_sig( mem_syn, M, negate( s_16 ) ); /* Qf_syn */ + Scale_sig( syn, add( shr( st->L_frame, 1 ), st->L_frame ), negate( s_16 ) ); /* Qf_syn */ /*Scale_sig(exc, add(shr(st->L_frame,1),st->L_frame) ,negate(s_16));*/ } @@ -900,11 +900,11 @@ void con_acelp_fx( /* i_subfr / L_SUBFR */ tmp_16 = shr( i_subfr, Q6 ); /* gain_lpc[i_subfr/L_SUBFR] = 1.f/(float)sqrt(dotp( h1, h1, L_SUBFR)); */ - tmp_32 = Dot_productSq16HQ( 0, h1, L_SUBFR, &gain_lpc_e[tmp_16] ); + tmp_32 = Dot_productSq16HQ( 0, h1, L_SUBFR, &gain_lpc_e[tmp_16] ); /*Q31*/ tmp_32 = L_max( tmp_32, 1 ); gain_lpc_e[tmp_16] = add( gain_lpc_e[tmp_16], shl( scale_h1, 1 ) ); move16(); - gain_lpc[tmp_16] = round_fx( ISqrt32( tmp_32, &gain_lpc_e[tmp_16] ) ); + gain_lpc[tmp_16] = round_fx( ISqrt32( tmp_32, &gain_lpc_e[tmp_16] ) ); /* Q15 - gain_lpc_e[tmp_16] */ move16(); p_A += ( M + 1 ); /* Pointer move */ @@ -916,24 +916,24 @@ void con_acelp_fx( { /* i_subfr / L_SUBFR */ tmp_16 = shr( i_subfr, Q6 ); - g = mult_r( st->last_gain_syn_deemph, gain_lpc[tmp_16] ); + g = mult_r( st->last_gain_syn_deemph, gain_lpc[tmp_16] ); /* Q15 - gain_lpc_e[tmp_16] */ g_e = add( st->last_gain_syn_deemph_e, gain_lpc_e[tmp_16] ); #ifdef BASOP_NOGLOB - g = shl_sat( g, g_e ); + g = shl_sat( g, g_e ); /*Q15*/ #else g = shl( g, g_e ); #endif FOR( i = 0; i < L_SUBFR; i++ ) { /* exc[i_subfr + i] *= st->last_gain_syn_deemph*gain_lpc[j]; */ - exc_unv[add( i_subfr, i )] = mult_r( exc_unv[add( i_subfr, i )], g ); + exc_unv[( i_subfr + i )] = mult_r( exc_unv[add( i_subfr, i )], g ); /*Qf_exc*/ move16(); } } l = add( st->L_frame, shr( st->L_frame, 1 ) ); FOR( i = st->L_frame; i < l; i++ ) { - exc_unv[i] = mult_r( exc_unv[i], g ); + exc_unv[i] = mult_r( exc_unv[i], g ); /*Qf_exc*/ move16(); } @@ -950,18 +950,18 @@ void con_acelp_fx( p_A = st->Aq_cng; /*in case of more than 5 consecutive concealed frames, improve precision of synthesis*/ - memsynPrecission_fx( st->nbLostCmpt, mem_syn_unv, exc_unv, st->L_frame, &s_16 ); + memsynPrecission_fx( st->nbLostCmpt, mem_syn_unv, exc_unv, st->L_frame, &s_16 ); /*Qf_syn + s_16*/ FOR( i_subfr = 0; i_subfr < st->L_frame; i_subfr += L_SUBFR ) { E_UTIL_synthesis( synthScaling, p_A, &exc_unv[i_subfr], &syn_unv[i_subfr], L_SUBFR, mem_syn_unv, 1, M ); p_A += ( M + 1 ); } - Copy( mem_syn_unv, st->mem_syn_unv_back, M ); + Copy( mem_syn_unv, st->mem_syn_unv_back, M ); /*Qf_syn + s_16*/ IF( LT_16( st->last_good, UNVOICED_TRANSITION ) ) { - Copy( mem_syn_unv, mem_syn, M ); + Copy( mem_syn_unv, mem_syn, M ); /*Qf_syn + s_16*/ /* unvoiced for ola */ E_UTIL_synthesis( synthScaling, p_A - ( M + 1 ), &exc_unv[i_subfr], &syn_unv[i_subfr], shr( st->L_frame, 1 ), mem_syn_unv, 0, M ); } @@ -970,18 +970,18 @@ void con_acelp_fx( IF( GT_16( st->nbLostCmpt, 5 ) && ( s_16 > 0 ) ) { /*scale back mem_syn_unv, exc_unv and synthesis*/ - Scale_sig( mem_syn_unv, M, negate( s_16 ) ); + Scale_sig( mem_syn_unv, M, negate( s_16 ) ); /*Qf_syn*/ IF( LT_16( st->last_good, UNVOICED_TRANSITION ) ) { - Scale_sig( mem_syn, M, negate( s_16 ) ); - Scale_sig( syn_unv, add( shr( st->L_frame, 1 ), st->L_frame ), negate( s_16 ) ); + Scale_sig( mem_syn, M, negate( s_16 ) ); /*Qf_syn*/ + Scale_sig( syn_unv, add( shr( st->L_frame, 1 ), st->L_frame ), negate( s_16 ) ); /*Qf_syn*/ } ELSE { - Scale_sig( syn_unv, st->L_frame, negate( s_16 ) ); + Scale_sig( syn_unv, st->L_frame, negate( s_16 ) ); /*Qf_syn*/ } - Scale_sig( st->mem_syn_unv_back, M, negate( s_16 ) ); + Scale_sig( st->mem_syn_unv_back, M, negate( s_16 ) ); /*Qf_syn*/ /*Scale_sig(exc_unv, add(shr(st->L_frame,1),st->L_frame) ,negate(s_16));*/ } @@ -992,7 +992,7 @@ void con_acelp_fx( FOR( i = 0; i < st->L_frame; i++ ) { #ifdef BASOP_NOGLOB - syn[i] = add_sat( syn[i], syn_unv[i] ); + syn[i] = add_sat( syn[i], syn_unv[i] ); /*Qf_syn*/ #else syn[i] = add( syn[i], syn_unv[i] ); #endif @@ -1001,7 +1001,7 @@ void con_acelp_fx( } ELSE { - Copy( syn_unv, syn, add( st->L_frame, shr( st->L_frame, 1 ) ) ); + Copy( syn_unv, syn, add( st->L_frame, shr( st->L_frame, 1 ) ) ); /*Qf_syn*/ } @@ -1072,21 +1072,21 @@ void con_acelp_fx( } /* Update Pitch Lag memory */ - Copy32( &st->old_pitch_buf_fx[st->nb_subfr], st->old_pitch_buf_fx, st->nb_subfr ); - Copy32( pitch_buf, &st->old_pitch_buf_fx[st->nb_subfr], st->nb_subfr ); + Copy32( &st->old_pitch_buf_fx[st->nb_subfr], st->old_pitch_buf_fx, st->nb_subfr ); /*15Q16*/ + Copy32( pitch_buf, &st->old_pitch_buf_fx[st->nb_subfr], st->nb_subfr ); /*15Q16*/ /*updating enr_old parameters*/ frame_ener_fx( st->L_frame, st->last_good, syn, round_fx( tmp_tc ), &( st->enr_old_fx ), 1, 0, 0, 0 ); #ifdef BASOP_NOGLOB - st->enr_old_fx = L_shl_sat( st->enr_old_fx, shl( negate( Qf_syn ), 1 ) ); + st->enr_old_fx = L_shl_sat( st->enr_old_fx, shl( negate( Qf_syn ), 1 ) ); /*Q0*/ #else st->enr_old_fx = L_shl( st->enr_old_fx, shl( negate( Qf_syn ), 1 ) ); #endif move32(); /* update ACELP synthesis memory */ - Copy( mem_syn, st->mem_syn2_fx, M ); - Copy( syn + st->L_frame - L_SYN_MEM, st->mem_syn_r, L_SYN_MEM ); + Copy( mem_syn, st->mem_syn2_fx, M ); /*Qf_syn*/ + Copy( syn + st->L_frame - L_SYN_MEM, st->mem_syn_r, L_SYN_MEM ); /*Qf_syn*/ /*Q_mem_syn_new = Q_mem_syn;*/ /*NOT "+synthScaling", cause mem_syn format is not changed*/ /* Deemphasis and output synth */ @@ -1103,13 +1103,13 @@ void con_acelp_fx( bufferCopyFx( syn + st->L_frame, hTcxDec->syn_Overl_TDAC, shr( st->L_frame, 1 ), 0 /*Qf_syn*/, -1 /*Qf_old_xnq*/, 0, 0 /*Q_old_xnq*/ ); hTcxDec->Q_syn_Overl_TDAC = add( st->Q_syn, -1 ); move16(); - Copy( syn + sub( st->L_frame, M + 1 ), st->syn, 1 + M ); + Copy( syn + sub( st->L_frame, M + 1 ), st->syn, 1 + M ); /*Qf_syn*/ /* update old_Aq */ - Copy( p_A - ( M + 1 ), st->old_Aq_12_8_fx, M + 1 ); + Copy( p_A - ( M + 1 ), st->old_Aq_12_8_fx, M + 1 ); /*Q12*/ - Copy( syn + st->L_frame, hTcxDec->syn_Overl, shr( st->L_frame, 1 ) ); + Copy( syn + st->L_frame, hTcxDec->syn_Overl, shr( st->L_frame, 1 ) ); /*Qf_syn*/ /* create aliasing and windowing */ @@ -1119,7 +1119,7 @@ void con_acelp_fx( st->hTcxCfg->tcx_curr_overlap_mode = FULL_OVERLAP; move16(); - n = extract_h( L_mult( st->L_frame, 9216 /*(float)N_ZERO_MDCT_NS/(float)FRAME_SIZE_NS Q15*/ ) ); + n = extract_h( L_mult( st->L_frame, 9216 /*(float)N_ZERO_MDCT_NS/(float)FRAME_SIZE_NS Q15*/ ) ); /*Q0*/ hHQ_core->Q_old_wtda_LB = getScaleFactor16( syn + sub( st->L_frame, n ), sub( st->L_frame, n ) ); @@ -1128,15 +1128,15 @@ void con_acelp_fx( bufferCopyFx( syn + sub( st->L_frame, n ), hHQ_core->old_out_LB_fx, sub( st->L_frame, n ), 0, 0, hHQ_core->Q_old_wtda_LB, 0 ); FOR( i = 0; i < W2; i++ ) { - hHQ_core->old_out_LB_fx[add( i, n )] = round_fx( Mpy_32_16_1( L_mult( w[i].v.re, w[i].v.re ), hHQ_core->old_out_LB_fx[add( i, n )] ) ); + hHQ_core->old_out_LB_fx[( i + n )] = round_fx( Mpy_32_16_1( L_mult( w[i].v.re, w[i].v.re ), hHQ_core->old_out_LB_fx[( i + n )] ) ); /* hHQ_core->q_old_outLB_fx */ move16(); } FOR( ; i < W1; i++ ) { - hHQ_core->old_out_LB_fx[i + n] = round_fx( Mpy_32_16_1( L_mult( w[sub( W2, add( 1, sub( i, W2 ) ) )].v.im, w[sub( W2, add( 1, sub( i, W2 ) ) )].v.im ), hHQ_core->old_out_LB_fx[add( i, n )] ) ); + hHQ_core->old_out_LB_fx[i + n] = round_fx( Mpy_32_16_1( L_mult( w[( W2 - ( 1 + ( i - W2 ) ) )].v.im, w[( W2 - ( 1 + ( i - W2 ) ) )].v.im ), hHQ_core->old_out_LB_fx[( i + n )] ) ); /* hHQ_core->q_old_outLB_fx */ move16(); } - set16_fx( &hHQ_core->old_out_LB_fx[add( W1, n )], 0, n ); + set16_fx( &hHQ_core->old_out_LB_fx[( W1 + n )], 0, n ); hHQ_core->Q_old_wtda = hHQ_core->Q_old_wtda_LB; move16(); @@ -1144,38 +1144,38 @@ void con_acelp_fx( FOR( i = 0; i < W2; i++ ) { - buf[i] = mult_r( hTcxDec->syn_Overl_TDAC[i], w[i].v.re ); + buf[i] = mult_r( hTcxDec->syn_Overl_TDAC[i], w[i].v.re ); /*hTcxDec->Q_syn_Overl_TDAC*/ move16(); } FOR( ; i < W1; i++ ) { - buf[i] = mult_r( hTcxDec->syn_Overl_TDAC[i], w[sub( sub( W1, 1 ), i )].v.im ); + buf[i] = mult_r( hTcxDec->syn_Overl_TDAC[i], w[( ( W1 - 1 ) - i )].v.im ); /*hTcxDec->Q_syn_Overl_TDAC*/ move16(); } FOR( i = 0; i < W2; i++ ) { - hTcxDec->syn_Overl_TDAC[i] = add( buf[i], buf[sub( sub( W1, 1 ), i )] ); /* A-D */ + hTcxDec->syn_Overl_TDAC[i] = add( buf[i], buf[( ( W1 - 1 ) - i )] ); /* A-D */ /*hTcxDec->Q_syn_Overl_TDAC*/ move16(); } /*-2*/ FOR( i = 0; i < W2; i++ ) { - hTcxDec->syn_Overl_TDAC[add( W2, i )] = add( buf[add( W2, i )], buf[sub( sub( sub( W1, 1 ), W2 ), i )] ); /* B-C */ + hTcxDec->syn_Overl_TDAC[( W2 + i )] = add( buf[( W2 + i )], buf[( ( ( W1 - 1 ) - W2 ) - i )] ); /* B-C */ /*hTcxDec->Q_syn_Overl_TDAC*/ move16(); } FOR( i = 0; i < W2; i++ ) { - hTcxDec->syn_Overl_TDAC[i] = mult_r( hTcxDec->syn_Overl_TDAC[i], w[i].v.re ); + hTcxDec->syn_Overl_TDAC[i] = mult_r( hTcxDec->syn_Overl_TDAC[i], w[i].v.re ); /*hTcxDec->Q_syn_Overl_TDAC*/ move16(); } FOR( ; i < W1; i++ ) { - hTcxDec->syn_Overl_TDAC[i] = mult_r( hTcxDec->syn_Overl_TDAC[i], w[sub( sub( W1, 1 ), i )].v.im ); + hTcxDec->syn_Overl_TDAC[i] = mult_r( hTcxDec->syn_Overl_TDAC[i], w[( ( W1 - 1 ) - i )].v.im ); /*hTcxDec->Q_syn_Overl_TDAC*/ move16(); } @@ -1192,7 +1192,7 @@ void con_acelp_fx( lerp( exc, st->hWIDec->old_exc2_fx, L_EXC_MEM, st->L_frame ); lerp( syn, st->hWIDec->old_syn2_fx, L_EXC_MEM, st->L_frame ); } - st->bfi_pitch_fx = shl( round_fx( pitch_buf[sub( st->nb_subfr, 1 )] ), 6 ); + st->bfi_pitch_fx = shl( round_fx( pitch_buf[( st->nb_subfr - 1 )] ), 6 ); /*Q6*/ st->bfi_pitch_frame = st->L_frame; move16(); move16(); @@ -1200,7 +1200,7 @@ void con_acelp_fx( return; } -static void memsynPrecission_fx( Word16 nbLostCmpt, Word16 *mem_syn, Word16 *exc, Word16 len, Word16 *s_16 ) +static void memsynPrecission_fx( Word16 nbLostCmpt, Word16 *mem_syn /*Qx*/, Word16 *exc /*Qx*/, Word16 len, Word16 *s_16 ) { IF( GT_16( nbLostCmpt, 5 ) ) { @@ -1242,8 +1242,8 @@ static void memsynPrecission_fx( Word16 nbLostCmpt, Word16 *mem_syn, Word16 *exc } *s_16 = s_max( sub( s_min( sf_exc, sf_mem_syn ), 5 ), 0 ) /*5 bits of headroom, scaling not smaller than 0*/; move16(); - Scale_sig( mem_syn, M, *s_16 ); - Scale_sig( exc, add( shr( len, 1 ), len ), *s_16 ); + Scale_sig( mem_syn, M, *s_16 ); /*Qx + s_16*/ + Scale_sig( exc, add( shr( len, 1 ), len ), *s_16 ); /*Qx + s_16*/ } } } diff --git a/lib_dec/er_dec_tcx_fx.c b/lib_dec/er_dec_tcx_fx.c index 4158368c6..1a1dbce92 100644 --- a/lib_dec/er_dec_tcx_fx.c +++ b/lib_dec/er_dec_tcx_fx.c @@ -14,7 +14,7 @@ /***************************************************** calcGainc calculates st->lp_gainc ******************************************************/ -static void calcGainc_fx( Word16 *exc, Word16 Q_exc, Word32 old_fpitch, Word16 L_subfr, Word32 lp_gainp, Word32 *lp_gainc ) +static void calcGainc_fx( Word16 *exc, Word16 Q_exc, Word32 old_fpitch /*Q16*/, Word16 L_subfr /*Q0*/, Word32 lp_gainp /*Q16*/, Word32 *lp_gainc /*Q16*/ ) { Word32 L_c; Word16 tmp16, tmp16_2, tmp16_3, tmp_e, tmp2_e, tmp_loop, i; @@ -49,7 +49,7 @@ static void calcGainc_fx( Word16 *exc, Word16 Q_exc, Word32 old_fpitch, Word16 L /*st->lp_gainc += ( exc[i-2*L_subfr] - st->Mode2_lp_gainp * exc[i-2*L_subfr-(int)(st->old_fpitch+0.5f)] ) * ( exc[i-2*L_subfr] - st->Mode2_lp_gainp * exc[i-2*L_subfr-(int)(st->old_fpitch+0.5f)] );*/ #ifdef BASOP_NOGLOB - tmp16_3 = sub_o( exc[sub( i, shl( L_subfr, 1 ) )] /*Q1*/, mult_r( tmp16_2 /*Q15*/, exc[sub( sub( i, shl( L_subfr, 1 ) ), tmp16 )] /*Q1*/ ) /*Q1*/, &Overflow ); + tmp16_3 = sub_o( exc[( i - ( L_subfr * 2 ) )] /*Q1*/, mult_r( tmp16_2 /*Q15*/, exc[( ( i - ( L_subfr * 2 ) ) - tmp16 )] /*Q1*/ ) /*Q1*/, &Overflow ); #else tmp16_3 = sub( exc[sub( i, shl( L_subfr, 1 ) )] /*Q1*/, mult_r( tmp16_2 /*Q15*/, exc[sub( sub( i, shl( L_subfr, 1 ) ), tmp16 )] /*Q1*/ ) /*Q1*/ ); #endif @@ -61,7 +61,7 @@ static void calcGainc_fx( Word16 *exc, Word16 Q_exc, Word32 old_fpitch, Word16 L Overflow = 0; move16(); #ifdef BASOP_NOGLOB - L_c = L_macNs_co( L_c, 0, 0, &Carry, &Overflow ); /*Accumulate Carrys*/ + L_c = L_macNs_co( L_c, 0, 0, &Carry, &Overflow ); /*Accumulate Carrys Q-1*/ #else L_c = L_macNs( L_c, 0, 0 ); /*Accumulate Carrys*/ #endif @@ -81,7 +81,7 @@ static void calcGainc_fx( Word16 *exc, Word16 Q_exc, Word32 old_fpitch, Word16 L move32(); } -static void calcGainc2_fx( Word16 *exc, Word16 Q_exc, Word16 L_subfr, Word32 *lp_gainc ) +static void calcGainc2_fx( Word16 *exc, Word16 Q_exc, Word16 L_subfr /*Q0*/, Word32 *lp_gainc /*Q16*/ ) { Word16 i, cnt, tmp16, tmp_e, tmp2_e; Word32 L_c, L_acc, L_tmp; @@ -106,15 +106,15 @@ static void calcGainc2_fx( Word16 *exc, Word16 Q_exc, Word16 L_subfr, Word32 *lp FOR( i = 0; i < cnt; i++ ) { /* *gainc += ( exc[i-2*L_subfr] ) * ( exc[i-2*L_subfr]); */ -#ifdef BASOP_NOGLOB /* Critical Carry/Overflow */ - L_acc = L_macNs_co( L_acc, exc[sub( i, shl( L_subfr, 1 ) )] /*Q1*/, exc[sub( i, shl( L_subfr, 1 ) )] /*Q1*/, &Carry, &Overflow ); /*Q3*/ +#ifdef BASOP_NOGLOB /* Critical Carry/Overflow */ + L_acc = L_macNs_co( L_acc, exc[( i - ( L_subfr * 2 ) )] /*Q1*/, exc[( i - ( L_subfr * 2 ) )] /*Q1*/, &Carry, &Overflow ); /*Q3*/ #else L_acc = L_macNs( L_acc, exc[sub( i, shl( L_subfr, 1 ) )] /*Q1*/, exc[sub( i, shl( L_subfr, 1 ) )] /*Q1*/ ); /*Q3*/ #endif Overflow = 0; move16(); #ifdef BASOP_NOGLOB /* Critical Carry/Overflow */ - L_c = L_macNs_co( L_c, 0, 0, &Carry, &Overflow ); /* Accumulate Carrys */ + L_c = L_macNs_co( L_c, 0, 0, &Carry, &Overflow ); /* Accumulate Carrys Q-1*/ #else L_c = L_macNs( L_c, 0, 0 ); /* Accumulate Carrys */ #endif @@ -144,16 +144,16 @@ con_tcx *******************************************************/ void con_tcx_fx( - Decoder_State *st, /* i/o: coder memory state */ - Word16 synth[] /* i/o: synth[] */ /*Q0 */ + Decoder_State *st, /* i/o: coder memory state */ + Word16 synth[] /* i/o: synth[] Q0*/ #ifdef IVAS_CODE_CON_TCX , - const Word16 coh, /* i : coherence of stereo signal */ - Word16 *noise_seed, /* i/o: noise seed for stereo */ - const Word16 only_left /* i : TD-PLC only in left channel */ + const Word16 coh, /* i : coherence of stereo signal Q14*/ + Word16 *noise_seed, /* i/o: noise seed for stereo Q0*/ + const Word16 only_left /* i : TD-PLC only in left channel Q0*/ #ifdef IVAS_CODE_CNG_FIX185_PLC_FADEOUT , - const float *A_cng /* i : CNG LP filter coefficients */ + const float *A_cng /* i : CNG LP filter coefficients Q14*/ #endif #endif @@ -211,20 +211,20 @@ void con_tcx_fx( move16(); /* Framing parameters */ - L_frame = hTcxDec->L_frameTCX; + L_frame = hTcxDec->L_frameTCX; /*Q0*/ move16(); /* L_subfr = st->L_frameTCX/st->nb_subfr */ - L_subfr = mult_r( hTcxDec->L_frameTCX, div_s( 1, st->nb_subfr ) ); + L_subfr = mult_r( hTcxDec->L_frameTCX, div_s( 1, st->nb_subfr ) ); /*Q0*/ assert( L_subfr == hTcxDec->L_frameTCX / st->nb_subfr ); move32(); - w = st->hTcxCfg->tcx_mdct_windowFB; /*pointer - no need to instrument*/ + w = st->hTcxCfg->tcx_mdct_windowFB; /*pointer - no need to instrument Q15*/ W1 = st->hTcxCfg->tcx_mdct_window_lengthFB; move16(); W2 = shr( st->hTcxCfg->tcx_mdct_window_lengthFB, 1 ); W12 = shr( W1, 1 ); /* take the previous frame last pitch */ - Tc = round_fx( st->old_fpitchFB ); + Tc = round_fx( st->old_fpitchFB ); /*Q0*/ set16_fx( buf, 0, OLD_EXC_SIZE_DEC + L_FRAME_MAX + L_FRAME_MAX / NB_SUBFR + 1 + L_FRAME_MAX / 2 ); /* initialize buf with 0 */ @@ -237,37 +237,37 @@ void con_tcx_fx( FOR( i = 0; i < 2 * NB_SUBFR16k + 2; i++ ) { - old_pitch_buf[i] = L_shl( Mpy_32_16_1( st->old_pitch_buf_fx[i], c ), s ); + old_pitch_buf[i] = L_shl( Mpy_32_16_1( st->old_pitch_buf_fx[i], c ), s ); /*Q16*/ move32(); } /* set excitation memory*/ - exc = buf + OLD_EXC_SIZE_DEC; - tmp_deemph = synth[-1]; + exc = buf + OLD_EXC_SIZE_DEC; /*Q_exc*/ + tmp_deemph = synth[-1]; /*Q0*/ move16(); - pre_emph_buf = synth[-1]; + pre_emph_buf = synth[-1]; /*Q0*/ move16(); test(); IF( ( EQ_16( st->nbLostCmpt, 1 ) ) || hTcxDec->tcxConceal_recalc_exc ) { /* apply pre-emphasis to the signal */ - mem = synth[sub( -( add( add( shr( L_frame, 1 ), hTcxDec->pit_max_TCX ), M + M ) ), 1 )]; + mem = synth[( -( ( ( ( L_frame / 2 ) + hTcxDec->pit_max_TCX ) + M + M ) ) - 1 )]; /*Q0*/ move16(); - Q_exc = E_UTIL_f_preemph3( &( synth[-add( add( shr( L_frame, 1 ), hTcxDec->pit_max_TCX ), 2 * M )] ), st->preemph_fac, add( add( shr( L_frame, 1 ), hTcxDec->pit_max_TCX ), shl( M, 1 ) ), &mem, 1 ); + Q_exc = E_UTIL_f_preemph3( &( synth[-( ( ( L_frame / 2 ) + hTcxDec->pit_max_TCX ) + 2 * M )] ), st->preemph_fac, add( add( shr( L_frame, 1 ), hTcxDec->pit_max_TCX ), shl( M, 1 ) ), &mem, 1 ); st->Mode2_lp_gainc = L_deposit_l( 0 ); - st->Mode2_lp_gainp = get_gain2( synth - shl( L_subfr, 1 ), synth - add( shl( L_subfr, 1 ), Tc ), shl( L_subfr, 1 ) ); + st->Mode2_lp_gainp = get_gain2( synth - shl( L_subfr, 1 ), synth - add( shl( L_subfr, 1 ), Tc ), shl( L_subfr, 1 ) ); /*Q16*/ - st->Mode2_lp_gainp = L_max( st->Mode2_lp_gainp, 0 ); - st->Mode2_lp_gainp = L_min( st->Mode2_lp_gainp, 65536l /*1.0f Q16*/ ); - st->Mode2_lp_gainp = L_shl( st->Mode2_lp_gainp, 13 ); + st->Mode2_lp_gainp = L_max( st->Mode2_lp_gainp, 0 ); /*Q16*/ + st->Mode2_lp_gainp = L_min( st->Mode2_lp_gainp, 65536l /*1.0f Q16*/ ); /*Q16*/ + st->Mode2_lp_gainp = L_shl( st->Mode2_lp_gainp, 13 ); /*Q29*/ - ana_window = buf; + ana_window = buf; /*Q15*/ ham_cos_window( ana_window, mult( L_frame, 24576 /*0.75f Q15*/ ), shr( L_frame, 2 ) ); /* Autocorrelation */ - autocorr_fx( &( synth[sub( -L_frame, 1 )] ), M, r_h, r_l, &Q_r, L_frame, ana_window, 0, 0 ); + autocorr_fx( &( synth[( -L_frame - 1 )] ), M, r_h, r_l, &Q_r, L_frame, ana_window, 0, 0 ); /* Lag windowing */ lag_wind( r_h, r_l, M, st->output_Fs, LAGW_STRONG ); @@ -276,7 +276,7 @@ void con_tcx_fx( E_LPC_lev_dur( r_h, r_l, A_local, NULL, M, NULL ); /* copy for multiple frame loss */ - Copy( A_local, st->old_Aq_12_8_fx, M + 1 ); + Copy( A_local, st->old_Aq_12_8_fx, M + 1 ); /*Q12*/ /* Residu */ assert( ( 2 * L_subfr + Tc + 1 + M ) <= hTcxDec->old_synth_lenFB ); @@ -284,8 +284,8 @@ void con_tcx_fx( BASOP_SATURATE_WARNING_OFF_EVS /*saturation possible in case of spiky synthesis*/ Residu3_fx( A_local, - &( synth[-add( add( add( shl( L_subfr, 1 ), Tc ), 1 ), M )] ), /*Qx = Q0*/ - &( exc[-add( add( add( shl( L_subfr, 1 ), Tc ), 1 ), M )] ), /*Qx+1 = Q1*/ + &( synth[-( ( add( ( L_subfr * 2 ), Tc ) + 1 ) + M )] ), /*Qx = Q0*/ + &( exc[-( ( add( ( L_subfr * 2 ), Tc ) + 1 ) + M )] ), /*Qx+1 = Q1*/ add( add( add( shl( L_subfr, 1 ), Tc ), 1 ), M ), 1 ); BASOP_SATURATE_WARNING_ON_EVS @@ -293,20 +293,20 @@ void con_tcx_fx( ELSE { /* apply pre-emphasis to the signal */ - mem = synth[sub( -L_frame, 1 )]; + mem = synth[( -L_frame - 1 )]; /*Q0*/ move16(); Q_exc = E_UTIL_f_preemph3( &( synth[-L_frame] ), st->preemph_fac, L_frame, &mem, 1 ); - Copy( st->old_Aq_12_8_fx, A_local, M + 1 ); + Copy( st->old_Aq_12_8_fx, A_local, M + 1 ); /*Q12*/ offset = shr( L_frame, 1 ); IF( GE_16( st->last_good, UNVOICED_TRANSITION ) ) { tmp16 = s_max( sub( Tc, shr( L_frame, 1 ) ), 0 ); - Copy_Scale_sig( hTcxDec->old_excFB_fx, &( exc[-tmp16] ), add( offset, tmp16 ), sub( Q_exc, st->Q_exc ) ); + Copy_Scale_sig( hTcxDec->old_excFB_fx, &( exc[-tmp16] ), add( offset, tmp16 ), sub( Q_exc, st->Q_exc ) ); /*Q_exc*/ } ELSE { - Copy_Scale_sig( hTcxDec->old_excFB_fx, &( exc[-shl( L_subfr, 1 )] ), add( shl( L_subfr, 1 ), offset ), sub( Q_exc, st->Q_exc ) ); + Copy_Scale_sig( hTcxDec->old_excFB_fx, &( exc[-( L_subfr * 2 )] ), add( shl( L_subfr, 1 ), offset ), sub( Q_exc, st->Q_exc ) ); /*Q_exc*/ } } @@ -344,9 +344,9 @@ void con_tcx_fx( tcxltp_pitch_tmp = L_add( L_deposit_h( hTcxLtpDec->tcxltp_pitch_int ), L_shl( L_deposit_l( div_s( hTcxLtpDec->tcxltp_pitch_fr, st->pit_res_max ) ), 1 ) ); /*15Q16*/ scale_tmp = mult_r( hTcxDec->L_frameTCX, getInvFrameLen( st->L_frame ) ); /*getInvFrameLen()->9Q6*/ tmp_shift = norm_s( scale_tmp ); - predPitchLag = L_shl( Mpy_32_16_1( tcxltp_pitch_tmp, shl( scale_tmp, tmp_shift ) ), sub( 9, tmp_shift ) ); + predPitchLag = L_shl( Mpy_32_16_1( tcxltp_pitch_tmp, shl( scale_tmp, tmp_shift ) ), sub( 9, tmp_shift ) ); /*Q16*/ - T0 = round_fx( predPitchLag ); + T0 = round_fx( predPitchLag ); /*Q0*/ test(); test(); @@ -372,7 +372,7 @@ void con_tcx_fx( &extrapolationFailed, st->nb_subfr ); - T0 = round_fx( predPitchLag ); + T0 = round_fx( predPitchLag ); /*Q0*/ test(); test(); test(); @@ -386,12 +386,12 @@ void con_tcx_fx( fLowPassFilter = 0; move16(); - pt_exc = exc + offset; - pt1_exc = pt_exc - Tc; + pt_exc = exc + offset; /*Q_exc*/ + pt1_exc = pt_exc - Tc; /*Q_exc*/ if ( fUseExtrapolatedPitch != 0 ) { - pt_exc = buf; + pt_exc = buf; /*Q_exc*/ } test(); IF( LT_16( st->stab_fac_fx, 32767 /*1.f Q15*/ ) && EQ_16( st->nbLostCmpt, 1 ) ) @@ -414,7 +414,7 @@ void con_tcx_fx( 0 /* 0.0000f Q15*/, pt1_exc[2] ), -1442 /*-0.0440f Q15*/, pt1_exc[3] ), 0 /* 0.0000f Q15*/, pt1_exc[4] ), - 174 /* 0.0053f Q15*/, pt1_exc[5] ); + 174 /* 0.0053f Q15*/, pt1_exc[5] ); /*Q_exc*/ #else *pt_exc++ = mac_r( L_mac( L_mac( L_mac( L_mac( L_mac( L_mac( L_mac( L_mac( L_mac( L_mult( 174 /* 0.0053f Q15*/, pt1_exc[-5] ), @@ -449,7 +449,7 @@ void con_tcx_fx( 590 /* 0.0180f Q15*/, pt1_exc[2] ), -459 /*-0.0140f Q15*/, pt1_exc[3] ), -121 /*-0.0037f Q15*/, pt1_exc[4] ), - -174 /*-0.0053f Q15*/, pt1_exc[5] ); + -174 /*-0.0053f Q15*/, pt1_exc[5] ); /*Q_exc*/ #else *pt_exc++ = mac_r( L_mac( L_mac( L_mac( L_mac( L_mac( L_mac( L_mac( L_mac( L_mac( L_mult( -174 /*-0.0053f Q15*/, pt1_exc[-5] ), @@ -477,7 +477,7 @@ void con_tcx_fx( /* copy the first pitch cycle without low-pass filtering */ FOR( i = 0; i < Tc; i++ ) { - *pt_exc++ = *pt1_exc++; + *pt_exc++ = *pt1_exc++; /*Q_exc*/ move16(); } fLowPassFilter = 1; @@ -486,12 +486,12 @@ void con_tcx_fx( if ( fUseExtrapolatedPitch != 0 ) { - pt1_exc = buf; + pt1_exc = buf; /*Q_exc*/ } tmp16 = add( sub( L_frame, imult1616( fLowPassFilter, Tc ) ), L_subfr ); FOR( i = 0; i < tmp16; i++ ) { - *pt_exc++ = *pt1_exc++; + *pt_exc++ = *pt1_exc++; /*Q_exc*/ move16(); } @@ -512,7 +512,7 @@ void con_tcx_fx( } ELSE { - set32_fx( pitch_buf, st->old_fpitch, st->nb_subfr ); + set32_fx( pitch_buf, st->old_fpitch, st->nb_subfr ); /*Q16*/ } IF( EQ_16( st->nbLostCmpt, 1 ) ) @@ -530,14 +530,14 @@ void con_tcx_fx( tmp_loop = shr( L_frame, 1 ); FOR( i = 0; i < tmp_loop; i++ ) { - *pt_exc++ = *pt1_exc++; + *pt_exc++ = *pt1_exc++; /*Q_exc*/ move16(); } } if ( fUseExtrapolatedPitch != 0 ) { - st->old_fpitchFB = predPitchLag; + st->old_fpitchFB = predPitchLag; /*Q16*/ move32(); } st->bpf_gain_param = 0; @@ -599,7 +599,7 @@ void con_tcx_fx( #ifdef BASOP_NOGLOB exc[i] = mult_r( exc[i], round_fx_sat( gain32 ) ) /*Q1*/; move16(); - gain32 = L_sub_sat( gain32, step32 ); + gain32 = L_sub_sat( gain32, step32 ); /*Q31*/ #else exc[i] = mult_r( exc[i], round_fx( gain32 ) ) /*Q1*/; move16(); @@ -608,8 +608,8 @@ void con_tcx_fx( } /* update old exc without random part */ - offset = s_max( sub( round_fx( st->old_fpitchFB ), shr( L_frame, 1 ) ), 0 ); - Copy( exc + sub( L_frame, offset ), hTcxDec->old_excFB_fx, add( shr( L_frame, 1 ), offset ) ); + offset = s_max( sub( round_fx( st->old_fpitchFB ), shr( L_frame, 1 ) ), 0 ); /*Q0*/ + Copy( exc + sub( L_frame, offset ), hTcxDec->old_excFB_fx, add( shr( L_frame, 1 ), offset ) ); /*Q_exc*/ /* copy old_exc as 16kHz for acelp decoding */ IF( EQ_16( st->nbLostCmpt, 1 ) ) { @@ -617,7 +617,7 @@ void con_tcx_fx( } ELSE { - Copy( st->old_exc_fx + L_FRAME16k, st->old_exc_fx, L_FRAME16k / 2 ); + Copy( st->old_exc_fx + L_FRAME16k, st->old_exc_fx, L_FRAME16k / 2 ); /*Q_exc*/ lerp( exc, st->old_exc_fx + L_FRAME16k / 2, L_FRAME16k, L_frame ); } st->Q_exc = Q_exc; @@ -631,8 +631,8 @@ void con_tcx_fx( { calcGainc2_fx( &exc[0], Q_exc, L_subfr, &( st->Mode2_lp_gainc ) ); } - set32_fx( pitch_buf, L_deposit_h( L_SUBFR ), st->nb_subfr ); - /* PLC: calculate damping factor */ + set32_fx( pitch_buf, L_deposit_h( L_SUBFR ), st->nb_subfr ); /*Q16*/ + /* PLC: calculate damping factor */ #ifdef IVAS_CODE_CNG_FIX185_PLC_FADEOUT alpha = 1.0f; if ( st->element_mode == IVAS_CPE_MDCT && st->nbLostCmpt >= MDCT_ST_PLC_FADEOUT_START_FRAME ) @@ -699,7 +699,7 @@ void con_tcx_fx( FOR( i = 0; i < tmp_loop; i++ ) { Random( &tmpSeed ); - noise[i] = shr( tmpSeed, noise_e ); + noise[i] = shr( tmpSeed, noise_e ); /*Q: -noise_e*/ move16(); } st->seed_acelp = tmpSeed; @@ -709,7 +709,7 @@ void con_tcx_fx( FOR( ; i < tmp_loop; i++ ) { Random( &tmpSeed ); - noise[i] = shr( tmpSeed, noise_e ); + noise[i] = shr( tmpSeed, noise_e ); /*Q: -noise_e*/ move16(); } } @@ -733,7 +733,7 @@ void con_tcx_fx( { FOR( i = 0; i < L_FIR_FER2; i++ ) { - hp_filt[i] = h_high3_16[i]; + hp_filt[i] = h_high3_16[i]; /*Q15*/ move16(); } } @@ -741,7 +741,7 @@ void con_tcx_fx( { FOR( i = 0; i < L_FIR_FER2; i++ ) { - hp_filt[i] = h_high3_32[i]; + hp_filt[i] = h_high3_32[i]; /*Q15*/ move16(); } } @@ -762,7 +762,7 @@ void con_tcx_fx( move32(); FOR( j = 11; j > 0; j-- ) { - L_tmp2 = L_mac( L_tmp2, noise[add( i, sub( L_FIR_FER2, j ) )], hp_filt[sub( L_FIR_FER2, j )] ); + L_tmp2 = L_mac( L_tmp2, noise[( i + sub( L_FIR_FER2, j ) )], hp_filt[( L_FIR_FER2 - j )] ); } L_tmp2 = Mpy_32_16_1( L_tmp2, st->cummulative_damping /*Q15*/ ); /*Q0, noise_e*/ noise[i] = mac_r( L_tmp2, gain_tmp, noise[i] ); /*Q15, noise_e*/ @@ -784,7 +784,7 @@ void con_tcx_fx( #else tmp16 = 32767; move16(); - gainSynthDeemph = getLevelSynDeemph_fx( &( tmp16 ), A_local, M, shr( L_frame, 2 ), st->preemph_fac, 1, &gainSynthDeemph_e ); + gainSynthDeemph = getLevelSynDeemph_fx( &( tmp16 ), A_local, M, shr( L_frame, 2 ), st->preemph_fac, 1, &gainSynthDeemph_e ); /*Q5*/ #endif IF( st->tcxonly != 0 ) { @@ -820,10 +820,10 @@ void con_tcx_fx( test(); if ( EQ_16( st->rf_frame_type, RF_TCXTD1 ) && EQ_16( st->use_partial_copy, 1 ) ) { - gain32 = Mpy_32_16_1( gain32, 22938 /*0.7f Q15*/ ); + gain32 = Mpy_32_16_1( gain32, 22938 /*0.7f Q15*/ ); /*Q16*/ } -#ifdef BASOP_NOGLOB /* Critical Overflow */ - L_tmp = L_shl_sat( gain32, 1 ); +#ifdef BASOP_NOGLOB /* Critical Overflow */ + L_tmp = L_shl_sat( gain32, 1 ); /*Q16*/ #else L_tmp = L_shl( gain32, 1 ); #endif @@ -838,8 +838,8 @@ void con_tcx_fx( L_tmp = Mpy_32_16_1( st->Mode2_lp_gainc, alpha ) /*Q15*/; L_tmp2 = L_mult( sub( 16384 /*1.f Q14*/, alpha ) /*Q14*/, gainCNG /*Q15,gainCNG_e*/ ); /*Q30,gainCNG_e*/ - st->Mode2_lp_gainc = BASOP_Util_Add_Mant32Exp( L_tmp, 31 - 15, L_tmp2, add( gainCNG_e, 31 - 30 ), &tmp_e ); /*Q31*/ - st->Mode2_lp_gainc = L_shl( st->Mode2_lp_gainc, sub( tmp_e, 31 - 16 ) ); + st->Mode2_lp_gainc = BASOP_Util_Add_Mant32Exp( L_tmp, 31 - 15, L_tmp2, add( gainCNG_e, 31 - 30 ), &tmp_e ); /*Q31-tmp_e*/ + st->Mode2_lp_gainc = L_shl( st->Mode2_lp_gainc, sub( tmp_e, 31 - 16 ) ); /*Q16*/ move32(); move32(); @@ -864,7 +864,7 @@ void con_tcx_fx( test(); IF( EQ_16( st->last_good, UNVOICED_CLAS ) && NE_16( st->core_ext_mode, UNVOICED ) ) { - gain_inov = mult_r( gain_inov, 26214 /*0.8f Q15*/ ); + gain_inov = mult_r( gain_inov, 26214 /*0.8f Q15*/ ); /*Q30*/ } ELSE IF( !( EQ_16( st->last_good, UNVOICED_CLAS ) || EQ_16( st->last_good, UNVOICED_TRANSITION ) ) ) { @@ -901,7 +901,7 @@ void con_tcx_fx( step32_tmp = L_shl( step32 /*Q25*/, sub( tmp_e, 25 - 16 ) ); /*Q16,-tmp_e*/ FOR( i = 0; i < tmp16; i++ ) /* Actual filtered random part of excitation */ { - *pt_exc = mult_r( *pt_exc, gain_tmp ); + *pt_exc = mult_r( *pt_exc, gain_tmp ); /*Q-15,noise_e+gain_inov_e-tmp_e*/ move16(); pt_exc++; gain32 = L_sub( gain32 /*Q16,-tmp_e*/, step32_tmp ); /*Q16,-tmp_e*/ @@ -910,7 +910,7 @@ void con_tcx_fx( tmp16 = shr( L_frame, 1 ); FOR( i = 0; i < tmp16; i++ ) /* causal ringing of the FIR filter */ { - *pt_exc = mult_r( *pt_exc, gain_tmp ); + *pt_exc = mult_r( *pt_exc, gain_tmp ); /*Q-15,noise_e+gain_inov_e-tmp_e*/ move16(); pt_exc++; } @@ -938,7 +938,7 @@ void con_tcx_fx( ELSE { bufferCopyFx( noise + L_FIR_FER2 / 2, exc, add( L_frame, shr( L_frame, 1 ) ), 0 /*Q_noise*/, noise_e, Q_exc, 0 /*exc_e*/ ); - Copy( exc + sub( L_frame, shl( L_subfr, 1 ) ), hTcxDec->old_excFB_fx, add( shl( L_subfr, 1 ), shr( L_frame, 1 ) ) ); + Copy( exc + sub( L_frame, shl( L_subfr, 1 ) ), hTcxDec->old_excFB_fx, add( shl( L_subfr, 1 ), shr( L_frame, 1 ) ) ); /*Q_exc*/ /* copy old_exc as 16kHz for acelp decoding */ IF( EQ_16( st->nbLostCmpt, 1 ) ) { @@ -946,7 +946,7 @@ void con_tcx_fx( } ELSE { - Copy( st->old_exc_fx + L_FRAME16k, st->old_exc_fx, L_FRAME16k / 2 ); + Copy( st->old_exc_fx + L_FRAME16k, st->old_exc_fx, L_FRAME16k / 2 ); /*Q_exc*/ lerp( exc, st->old_exc_fx + L_FRAME16k / 2, L_FRAME16k, L_frame ); } st->Q_exc = Q_exc; @@ -956,15 +956,15 @@ void con_tcx_fx( /*buf[OLD_EXC_SIZE_DEC;3/2 L_frame] Q1*/ /* Update Pitch Lag memory */ - Copy32( &st->old_pitch_buf_fx[st->nb_subfr], st->old_pitch_buf_fx, st->nb_subfr ); - Copy32( pitch_buf, &st->old_pitch_buf_fx[st->nb_subfr], st->nb_subfr ); + Copy32( &st->old_pitch_buf_fx[st->nb_subfr], st->old_pitch_buf_fx, st->nb_subfr ); /*Q16*/ + Copy32( pitch_buf, &st->old_pitch_buf_fx[st->nb_subfr], st->nb_subfr ); /*Q16*/ /*----------------------------------------------------------* * - compute the synthesis speech * *----------------------------------------------------------*/ - syn = buf + M; - Copy( synth - M, buf, M ); + syn = buf + M; /*Q_syn*/ + Copy( synth - M, buf, M ); /*Q_syn*/ new_Q = sub( Q_exc, 3 ); new_Q = s_max( new_Q, -1 ); @@ -977,10 +977,10 @@ void con_tcx_fx( Q_syn = tmp16; move16(); - Copy_Scale_sig( buf, mem_syn, M, exp_scale ); + Copy_Scale_sig( buf, mem_syn, M, exp_scale ); /*Q: tmp16*/ #ifdef BASOP_NOGLOB - tmp_deemph = shl_sat( tmp_deemph, Q_syn ); + tmp_deemph = shl_sat( tmp_deemph, Q_syn ); /*Q_syn*/ #else tmp_deemph = shl( tmp_deemph, Q_syn ); #endif @@ -1031,37 +1031,37 @@ void con_tcx_fx( /*buf[0;M-1] Q0: mem_syn*/ /*buf[M;3/2 L_frame-1] Q-1: syn*/ - n = extract_h( L_mult( L_frame, 9216 /*(float)N_ZERO_MDCT_NS/(float)FRAME_SIZE_NS Q15*/ ) ); + n = extract_h( L_mult( L_frame, 9216 /*(float)N_ZERO_MDCT_NS/(float)FRAME_SIZE_NS Q15*/ ) ); /*q0*/ /* update ACELP synthesis memory */ mem_syn_r_size_old = shr( L_frame, 4 ); /* replace 1.25/20.0 by shr(4) */ /* copy mem_syn as 16kHz */ mem_syn_r_size_new = shr( L_FRAME16k, 4 ); /* replace 1.25/20.0 by shr(4) */ - Copy( syn + sub( L_frame, L_SYN_MEM ), st->mem_syn_r, L_SYN_MEM ); + Copy( syn + sub( L_frame, L_SYN_MEM ), st->mem_syn_r, L_SYN_MEM ); /*Q_syn*/ lerp( st->mem_syn_r + sub( L_SYN_MEM, mem_syn_r_size_old ), st->mem_syn_r + sub( L_SYN_MEM, mem_syn_r_size_new ), mem_syn_r_size_new, mem_syn_r_size_old ); - Copy( st->mem_syn_r + L_SYN_MEM - M, st->mem_syn2_fx, M ); + Copy( st->mem_syn_r + L_SYN_MEM - M, st->mem_syn2_fx, M ); /*Q_syn*/ /* Deemphasis and output synth and ZIR */ deemph_fx( syn, st->preemph_fac, add( L_frame, shr( L_frame, 1 ) ), &tmp_deemph ); - bufferCopyFx( syn + sub( L_frame, M + 1 ), st->syn, 1 + M, Q_syn, 0, 0, 0 ); + bufferCopyFx( syn + sub( L_frame, M + 1 ), st->syn, 1 + M, Q_syn, 0, 0, 0 ); /*Q_syn*/ lerp( syn + sub( L_frame, shr( L_frame, 1 ) ), hTcxDec->old_syn_Overl, shr( st->L_frame, 1 ), shr( L_frame, 1 ) ); - Copy( syn + sub( L_frame, n ), hHQ_core->old_out_fx, sub( L_frame, n ) ); + Copy( syn + sub( L_frame, n ), hHQ_core->old_out_fx, sub( L_frame, n ) ); /*Q_syn*/ FOR( i = 0; i < W12; i++ ) { - hHQ_core->old_out_fx[add( i, n )] = round_fx( Mpy_32_16_1( L_mult( w[i].v.re, w[i].v.re ), hHQ_core->old_out_fx[add( i, n )] ) ); + hHQ_core->old_out_fx[( i + n )] = round_fx( Mpy_32_16_1( L_mult( w[i].v.re, w[i].v.re ), hHQ_core->old_out_fx[( i + n )] ) ); /*Q_syn*/ move16(); } FOR( ; i < W1; i++ ) { - hHQ_core->old_out_fx[add( i, n )] = round_fx( Mpy_32_16_1( L_mult( w[sub( sub( W12, 1 ), sub( i, W12 ) )].v.im, w[sub( sub( W12, 1 ), sub( i, W12 ) )].v.im ), hHQ_core->old_out_fx[add( i, n )] ) ); + hHQ_core->old_out_fx[( i + n )] = round_fx( Mpy_32_16_1( L_mult( w[( ( W12 - 1 ) - ( i - W12 ) )].v.im, w[( ( W12 - 1 ) - ( i - W12 ) )].v.im ), hHQ_core->old_out_fx[( i + n )] ) ); /*Q_syn*/ move16(); } - set16_fx( &hHQ_core->old_out_fx[add( W1, n )], 0, n ); + set16_fx( &hHQ_core->old_out_fx[( W1 + n )], 0, n ); hHQ_core->Q_old_wtda = Q_syn; move16(); @@ -1069,10 +1069,10 @@ void con_tcx_fx( /* As long as there is no synth scaling factor introduced, which is given to the outside, there might occur overflows here */ BASOP_SATURATE_WARNING_OFF_EVS - bufferCopyFx( syn, synth, L_frame, Q_syn, 0, 0, 0 ); + bufferCopyFx( syn, synth, L_frame, Q_syn, 0, 0, 0 ); /*Q_syn*/ BASOP_SATURATE_WARNING_ON_EVS - Copy_Scale_sig( syn + L_frame, hTcxDec->syn_OverlFB, shr( L_frame, 1 ), negate( Q_syn ) ); + Copy_Scale_sig( syn + L_frame, hTcxDec->syn_OverlFB, shr( L_frame, 1 ), negate( Q_syn ) ); /*Q0*/ /* copy total excitation exc2 as 16kHz for acelp mode1 decoding */ IF( st->hWIDec != NULL ) @@ -1082,7 +1082,7 @@ void con_tcx_fx( } #ifdef BASOP_NOGLOB - st->bfi_pitch_fx /*Q6*/ = round_fx_sat( L_shl_sat( pitch_buf[sub( st->nb_subfr, 1 )] /*15Q16*/, 6 /*Q6*/ ) ); + st->bfi_pitch_fx /*Q6*/ = round_fx_sat( L_shl_sat( pitch_buf[( st->nb_subfr - 1 )] /*15Q16*/, 6 /*Q6*/ ) ); #else st->bfi_pitch_fx /*Q6*/ = round_fx( L_shl( pitch_buf[sub( st->nb_subfr, 1 )] /*15Q16*/, 6 /*Q6*/ ) ); #endif @@ -1097,12 +1097,12 @@ void con_tcx_fx( FOR( i = 0; i < W12; i++ ) { - buf[i] = mult_r( hTcxDec->syn_Overl_TDACFB[i], w[i].v.re ); + buf[i] = mult_r( hTcxDec->syn_Overl_TDACFB[i], w[i].v.re ); /*hTcxDec->Q_syn_Overl_TDACFB*/ move16(); } FOR( ; i < W1; i++ ) { - buf[i] = mult_r( hTcxDec->syn_Overl_TDACFB[i], w[sub( sub( W12, 1 ), sub( i, W12 ) )].v.im ); + buf[i] = mult_r( hTcxDec->syn_Overl_TDACFB[i], w[( ( W12 - 1 ) - ( i - W12 ) )].v.im ); /*hTcxDec->Q_syn_Overl_TDACFB*/ move16(); } @@ -1110,7 +1110,7 @@ void con_tcx_fx( FOR( i = 0; i < W2; i++ ) { #ifdef BASOP_NOGLOB - hTcxDec->syn_Overl_TDACFB[i] = add_sat( buf[i], buf[sub( sub( W1, 1 ), i )] ); + hTcxDec->syn_Overl_TDACFB[i] = add_sat( buf[i], buf[( ( W1 - 1 ) - i )] ); /*hTcxDec->Q_syn_Overl_TDACFB*/ #else hTcxDec->syn_Overl_TDACFB[i] = add( buf[i], buf[sub( sub( W1, 1 ), i )] ); #endif @@ -1120,7 +1120,7 @@ void con_tcx_fx( FOR( i = 0; i < W2; i++ ) { #ifdef BASOP_NOGLOB - hTcxDec->syn_Overl_TDACFB[add( W2, i )] = add_sat( buf[add( W2, i )], buf[sub( sub( sub( W1, 1 ), W2 ), i )] ); + hTcxDec->syn_Overl_TDACFB[( W2 + i )] = add_sat( buf[( W2 + i )], buf[( ( ( W1 - 1 ) - W2 ) - i )] ); /*hTcxDec->Q_syn_Overl_TDACFB*/ #else hTcxDec->syn_Overl_TDACFB[add( W2, i )] = add( buf[add( W2, i )], buf[sub( sub( sub( W1, 1 ), W2 ), i )] ); #endif @@ -1129,23 +1129,23 @@ void con_tcx_fx( FOR( i = 0; i < W12; i++ ) { - hTcxDec->syn_Overl_TDACFB[i] = mult_r( hTcxDec->syn_Overl_TDACFB[i], w[i].v.re ); + hTcxDec->syn_Overl_TDACFB[i] = mult_r( hTcxDec->syn_Overl_TDACFB[i], w[i].v.re ); /*hTcxDec->Q_syn_Overl_TDACFB*/ move16(); } FOR( ; i < W1; i++ ) { - hTcxDec->syn_Overl_TDACFB[i] = mult_r( hTcxDec->syn_Overl_TDACFB[i], w[sub( sub( W12, 1 ), sub( i, W12 ) )].v.im ); + hTcxDec->syn_Overl_TDACFB[i] = mult_r( hTcxDec->syn_Overl_TDACFB[i], w[( ( W12 - 1 ) - ( i - W12 ) )].v.im ); /*hTcxDec->Q_syn_Overl_TDACFB*/ move16(); } st->hTcxCfg->tcx_curr_overlap_mode = FULL_OVERLAP; move16(); - synth[-1] = pre_emph_buf; + synth[-1] = pre_emph_buf; /*Q0*/ move16(); /* update memory for low band */ - Scale_sig( hTcxDec->old_syn_Overl, shr( st->L_frame, 1 ), sub( -1, Q_syn ) ); + Scale_sig( hTcxDec->old_syn_Overl, shr( st->L_frame, 1 ), sub( -1, Q_syn ) ); /*Q_syn*/ lerp( hTcxDec->syn_OverlFB, hTcxDec->syn_Overl, shr( st->L_frame, 1 ), shr( L_frame, 1 ) ); lerp( hTcxDec->syn_Overl_TDACFB, hTcxDec->syn_Overl_TDAC, shr( st->L_frame, 1 ), shr( L_frame, 1 ) ); hTcxDec->Q_syn_Overl_TDAC = hTcxDec->Q_syn_Overl_TDACFB; @@ -1163,10 +1163,10 @@ void con_tcx_ivas_fx( Decoder_State *st, /* i/o: coder memory state */ Word16 synth[], /* i/o: synth[] */ /*Q0 */ - const Word16 coh, /* i : coherence of stereo signal */ - Word16 *noise_seed, /* i/o: noise seed for stereo */ - const Word16 only_left, /* i : TD-PLC only in left channel */ - const Word16 *A_cng /* i : CNG LP filter coefficients */ + const Word16 coh, /* i : coherence of stereo signal Q14*/ + Word16 *noise_seed, /* i/o: noise seed for stereo Q0*/ + const Word16 only_left, /* i : TD-PLC only in left channel Q0*/ + const Word16 *A_cng /* i : CNG LP filter coefficients Q14*/ ) { Word16 i, s, c, L_frame, L_subfr, fLowPassFilter, T0; @@ -1224,16 +1224,16 @@ void con_tcx_ivas_fx( L_frame = hTcxDec->L_frameTCX; move16(); /* L_subfr = st->L_frameTCX/st->nb_subfr */ - L_subfr = mult_r( hTcxDec->L_frameTCX, div_s( 1, st->nb_subfr ) ); + L_subfr = mult_r( hTcxDec->L_frameTCX, div_s( 1, st->nb_subfr ) ); /*Q0*/ assert( L_subfr == hTcxDec->L_frameTCX / st->nb_subfr ); - w = st->hTcxCfg->tcx_mdct_windowFB; /*pointer - no need to instrument*/ + w = st->hTcxCfg->tcx_mdct_windowFB; /*pointer - no need to instrument Q15*/ W1 = st->hTcxCfg->tcx_mdct_window_lengthFB; move16(); W2 = shr( st->hTcxCfg->tcx_mdct_window_lengthFB, 1 ); W12 = shr( W1, 1 ); /* take the previous frame last pitch */ - Tc = round_fx( st->old_fpitchFB ); + Tc = round_fx( st->old_fpitchFB ); /*Q0*/ set16_fx( buf, 0, OLD_EXC_SIZE_DEC + L_FRAME_MAX + L_FRAME_MAX / NB_SUBFR + 1 + L_FRAME_MAX / 2 ); /* initialize buf with 0 */ @@ -1246,22 +1246,22 @@ void con_tcx_ivas_fx( FOR( i = 0; i < 2 * NB_SUBFR16k + 2; i++ ) { - old_pitch_buf[i] = L_shl( Mpy_32_16_1( st->old_pitch_buf_fx[i], c ), s ); + old_pitch_buf[i] = L_shl( Mpy_32_16_1( st->old_pitch_buf_fx[i], c ), s ); /*Q16*/ move32(); } /* set excitation memory*/ exc = buf + OLD_EXC_SIZE_DEC; - tmp_deemph = synth[-1]; + tmp_deemph = synth[-1]; /*Q0*/ move16(); - pre_emph_buf = synth[-1]; + pre_emph_buf = synth[-1]; /*Q0*/ move16(); test(); IF( ( EQ_16( st->nbLostCmpt, 1 ) ) || hTcxDec->tcxConceal_recalc_exc ) { /* apply pre-emphasis to the signal */ - mem = synth[sub( -add( add( shr( L_frame, 1 ), hTcxDec->pit_max_TCX ), M + M ), 1 )]; + mem = synth[( -( ( ( L_frame / 2 ) + hTcxDec->pit_max_TCX ) + M + M ) - 1 )]; /*Q0*/ move16(); Q_exc = E_UTIL_f_preemph3( &( synth[-add( add( shr( L_frame, 1 ), hTcxDec->pit_max_TCX ), 2 * M )] ), st->preemph_fac, add( add( shr( L_frame, 1 ), hTcxDec->pit_max_TCX ), shl( M, 1 ) ), &mem, 1 ); st->Mode2_lp_gainc = L_deposit_l( 0 ); @@ -1269,18 +1269,18 @@ void con_tcx_ivas_fx( st->Mode2_lp_gainp = get_gain2( synth - shl( L_subfr, 1 ), synth - add( shl( L_subfr, 1 ), Tc ), shl( L_subfr, 1 ) ); move32(); - st->Mode2_lp_gainp = L_max( st->Mode2_lp_gainp, 0 ); - st->Mode2_lp_gainp = L_min( st->Mode2_lp_gainp, 65536l /*1.0f Q16*/ ); - st->Mode2_lp_gainp = L_shl( st->Mode2_lp_gainp, 13 ); + st->Mode2_lp_gainp = L_max( st->Mode2_lp_gainp, 0 ); /*Q16*/ + st->Mode2_lp_gainp = L_min( st->Mode2_lp_gainp, 65536l /*1.0f Q16*/ ); /*Q16*/ + st->Mode2_lp_gainp = L_shl( st->Mode2_lp_gainp, 13 ); /*Q29*/ move32(); move32(); move32(); - ana_window = buf; + ana_window = buf; /*Q15*/ ham_cos_window( ana_window, mult( L_frame, 24576 /*0.75f Q15*/ ), shr( L_frame, 2 ) ); /* Autocorrelation */ - autocorr_fx( &( synth[sub( -L_frame, 1 )] ), M, r_h, r_l, &Q_r, L_frame, ana_window, 0, 0 ); + autocorr_fx( &( synth[( -L_frame - 1 )] ), M, r_h, r_l, &Q_r, L_frame, ana_window, 0, 0 ); /* Lag windowing */ lag_wind( r_h, r_l, M, st->output_Fs, LAGW_STRONG ); @@ -1289,7 +1289,7 @@ void con_tcx_ivas_fx( E_LPC_lev_dur( r_h, r_l, A_local, NULL, M, NULL ); /* copy for multiple frame loss */ - Copy( A_local, st->old_Aq_12_8_fx, M + 1 ); + Copy( A_local, st->old_Aq_12_8_fx, M + 1 ); /*Q14*/ /* Residu */ assert( ( 2 * L_subfr + Tc + 1 + M ) <= hTcxDec->old_synth_lenFB ); @@ -1306,20 +1306,20 @@ void con_tcx_ivas_fx( ELSE { /* apply pre-emphasis to the signal */ - mem = synth[sub( -L_frame, 1 )]; + mem = synth[( -L_frame - 1 )]; /*Q0*/ move16(); Q_exc = E_UTIL_f_preemph3( &( synth[-L_frame] ), st->preemph_fac, L_frame, &mem, 1 ); - Copy( st->old_Aq_12_8_fx, A_local, M + 1 ); + Copy( st->old_Aq_12_8_fx, A_local, M + 1 ); /*Q14*/ offset = shr( L_frame, 1 ); IF( GE_16( st->last_good, UNVOICED_TRANSITION ) ) { tmp16 = s_max( Tc - shr( L_frame, 1 ), 0 ); - Copy_Scale_sig( hTcxDec->old_excFB_fx, &( exc[-tmp16] ), add( offset, tmp16 ), sub( Q_exc, st->Q_exc ) ); + Copy_Scale_sig( hTcxDec->old_excFB_fx, &( exc[-tmp16] ), add( offset, tmp16 ), sub( Q_exc, st->Q_exc ) ); /*Q_exc*/ } ELSE { - Copy_Scale_sig( hTcxDec->old_excFB_fx, &( exc[-shl( L_subfr, 1 )] ), add( shl( L_subfr, 1 ), offset ), sub( Q_exc, st->Q_exc ) ); + Copy_Scale_sig( hTcxDec->old_excFB_fx, &( exc[-( L_subfr * 2 )] ), add( shl( L_subfr, 1 ), offset ), sub( Q_exc, st->Q_exc ) ); /*Q_exc*/ } } @@ -1358,9 +1358,9 @@ void con_tcx_ivas_fx( scale_tmp = mult_r( hTcxDec->L_frameTCX, getInvFrameLen( st->L_frame ) ); /*getInvFrameLen()->9Q6*/ tmp_shift = norm_s( scale_tmp ); - predPitchLag = L_shl( Mpy_32_16_1( tcxltp_pitch_tmp, shl( scale_tmp, tmp_shift ) ), sub( 9, tmp_shift ) ); + predPitchLag = L_shl( Mpy_32_16_1( tcxltp_pitch_tmp, shl( scale_tmp, tmp_shift ) ), sub( 9, tmp_shift ) ); /*Q16*/ - T0 = round_fx( predPitchLag ); + T0 = round_fx( predPitchLag ); /*Q0*/ test(); test(); @@ -1401,12 +1401,12 @@ void con_tcx_ivas_fx( fLowPassFilter = 0; move16(); - pt_exc = exc + offset; - pt1_exc = pt_exc - Tc; + pt_exc = exc + offset; /*Q_exc*/ + pt1_exc = pt_exc - Tc; /*Q_exc*/ if ( fUseExtrapolatedPitch != 0 ) { - pt_exc = buf; + pt_exc = buf; /*Q_exc*/ } test(); IF( LT_16( st->stab_fac_fx, 32767 /*1.f Q15*/ ) && EQ_16( st->nbLostCmpt, 1 ) ) @@ -1428,7 +1428,7 @@ void con_tcx_ivas_fx( 0 /* 0.0000f Q15*/, pt1_exc[2] ), -1442 /*-0.0440f Q15*/, pt1_exc[3] ), 0 /* 0.0000f Q15*/, pt1_exc[4] ), - 174 /* 0.0053f Q15*/, pt1_exc[5] ); + 174 /* 0.0053f Q15*/, pt1_exc[5] ); /*Q_exc*/ move16(); pt1_exc++; } @@ -1448,7 +1448,7 @@ void con_tcx_ivas_fx( 590 /* 0.0180f Q15*/, pt1_exc[2] ), -459 /*-0.0140f Q15*/, pt1_exc[3] ), -121 /*-0.0037f Q15*/, pt1_exc[4] ), - -174 /*-0.0053f Q15*/, pt1_exc[5] ); + -174 /*-0.0053f Q15*/, pt1_exc[5] ); /*Q_exc*/ move16(); pt1_exc++; } @@ -1462,7 +1462,7 @@ void con_tcx_ivas_fx( /* copy the first pitch cycle without low-pass filtering */ FOR( i = 0; i < Tc; i++ ) { - *pt_exc++ = *pt1_exc++; + *pt_exc++ = *pt1_exc++; /*Q_exc*/ move16(); } fLowPassFilter = 1; @@ -1476,7 +1476,7 @@ void con_tcx_ivas_fx( tmp16 = add( sub( L_frame, imult1616( fLowPassFilter, Tc ) ), L_subfr ); FOR( i = 0; i < tmp16; i++ ) { - *pt_exc++ = *pt1_exc++; + *pt_exc++ = *pt1_exc++; /*Q_exc*/ move16(); } @@ -1497,7 +1497,7 @@ void con_tcx_ivas_fx( } ELSE { - set32_fx( pitch_buf, st->old_fpitch, st->nb_subfr ); + set32_fx( pitch_buf, st->old_fpitch, st->nb_subfr ); /*Q16*/ } IF( EQ_16( st->nbLostCmpt, 1 ) ) @@ -1505,24 +1505,24 @@ void con_tcx_ivas_fx( pt_exc = exc + L_frame; IF( T0 == 0 ) { - pt1_exc = pt_exc - Tc; + pt1_exc = pt_exc - Tc; /*Q_exc*/ } ELSE { - pt1_exc = pt_exc - T0; + pt1_exc = pt_exc - T0; /*Q_exc*/ } tmp_loop = shr( L_frame, 1 ); FOR( i = 0; i < tmp_loop; i++ ) { - *pt_exc++ = *pt1_exc++; + *pt_exc++ = *pt1_exc++; /*Q_exc*/ move16(); } } if ( fUseExtrapolatedPitch != 0 ) { - st->old_fpitchFB = predPitchLag; + st->old_fpitchFB = predPitchLag; /*Q16*/ move32(); } st->bpf_gain_param = 0; @@ -1584,7 +1584,7 @@ void con_tcx_ivas_fx( #ifdef BASOP_NOGLOB exc[i] = mult_r( exc[i], round_fx_sat( gain32 ) ) /*Q1*/; move16(); - gain32 = L_sub_sat( gain32, step32 ); + gain32 = L_sub_sat( gain32, step32 ); /*Q31*/ #else exc[i] = mult_r( exc[i], round_fx( gain32 ) ) /*Q1*/; move16(); @@ -1593,8 +1593,8 @@ void con_tcx_ivas_fx( } /* update old exc without random part */ - offset = s_max( sub( round_fx( st->old_fpitchFB ), shr( L_frame, 1 ) ), 0 ); - Copy( exc + sub( L_frame, offset ), hTcxDec->old_excFB_fx, add( shr( L_frame, 1 ), offset ) ); + offset = s_max( sub( round_fx( st->old_fpitchFB ), shr( L_frame, 1 ) ), 0 ); /*Q0*/ + Copy( exc + sub( L_frame, offset ), hTcxDec->old_excFB_fx, add( shr( L_frame, 1 ), offset ) ); /*Q_exc*/ /* copy old_exc as 16kHz for acelp decoding */ IF( EQ_16( st->nbLostCmpt, 1 ) ) { @@ -1602,7 +1602,7 @@ void con_tcx_ivas_fx( } ELSE { - Copy( st->old_exc_fx + L_FRAME16k, st->old_exc_fx, L_FRAME16k / 2 ); + Copy( st->old_exc_fx + L_FRAME16k, st->old_exc_fx, L_FRAME16k / 2 ); /*Q_exc*/ lerp( exc, st->old_exc_fx + L_FRAME16k / 2, L_FRAME16k, L_frame ); } st->Q_exc = Q_exc; @@ -1616,8 +1616,8 @@ void con_tcx_ivas_fx( { calcGainc2_fx( &exc[0], Q_exc, L_subfr, &( st->Mode2_lp_gainc ) ); } - set32_fx( pitch_buf, L_deposit_h( L_SUBFR ), st->nb_subfr ); - /* PLC: calculate damping factor */ + set32_fx( pitch_buf, L_deposit_h( L_SUBFR ), st->nb_subfr ); /*Q16*/ + /* PLC: calculate damping factor */ #ifdef IVAS_CODE_CNG_FIX185_PLC_FADEOUT alpha = 1.0f; if ( st->element_mode == IVAS_CPE_MDCT && st->nbLostCmpt >= MDCT_ST_PLC_FADEOUT_START_FRAME ) @@ -1645,7 +1645,7 @@ void con_tcx_ivas_fx( Word16 e; tmpSeed1 = *noise_seed; - noise = buf; + noise = buf; /*Q15*/ noise_e = 2; move16(); e = 0; @@ -1653,9 +1653,9 @@ void con_tcx_ivas_fx( alpha_coh = 0; move16(); - IF( NE_16( coh, 16384 ) ) + IF( NE_16( coh, 16384 /*1.0f in Q14*/ ) ) { - alpha_coh = Sqrt16( div_s( sub( 16384, coh ), add( 16384, coh ) ), &e ); + alpha_coh = Sqrt16( div_s( sub( 16384 /*1.0f in Q14*/, coh ), add( 16384 /*1.0f in Q14*/, coh ) ), &e ); /* Q15 - e */ } if ( EQ_16( st->idchan, 1 ) ) { @@ -1688,7 +1688,7 @@ void con_tcx_ivas_fx( ELSE #endif /*IVAS_CODE_CON_TCX*/ { - tmpSeed = st->seed_acelp; + tmpSeed = st->seed_acelp; /*Q0*/ move16(); noise = buf; noise_e = 1; /*set exponent of noise to 1*/ @@ -1698,7 +1698,7 @@ void con_tcx_ivas_fx( FOR( i = 0; i < tmp_loop; i++ ) { Random( &tmpSeed ); - noise[i] = shr( tmpSeed, noise_e ); + noise[i] = shr( tmpSeed, noise_e ); /*Q: -noise_e*/ move16(); } st->seed_acelp = tmpSeed; @@ -1708,7 +1708,7 @@ void con_tcx_ivas_fx( FOR( ; i < tmp_loop; i++ ) { Random( &tmpSeed ); - noise[i] = shr( tmpSeed, noise_e ); + noise[i] = shr( tmpSeed, noise_e ); /*Q: -noise_e*/ move16(); } } @@ -1732,7 +1732,7 @@ void con_tcx_ivas_fx( { FOR( i = 0; i < L_FIR_FER2; i++ ) { - hp_filt[i] = h_high3_16[i]; + hp_filt[i] = h_high3_16[i]; /*Q15*/ move16(); } } @@ -1740,7 +1740,7 @@ void con_tcx_ivas_fx( { FOR( i = 0; i < L_FIR_FER2; i++ ) { - hp_filt[i] = h_high3_32[i]; + hp_filt[i] = h_high3_32[i]; /*Q15*/ move16(); } } @@ -1761,7 +1761,7 @@ void con_tcx_ivas_fx( move32(); FOR( j = 11; j > 0; j-- ) { - L_tmp2 = L_mac( L_tmp2, noise[add( i, sub( L_FIR_FER2, j ) )], hp_filt[sub( L_FIR_FER2, j )] ); + L_tmp2 = L_mac( L_tmp2, noise[( i + ( L_FIR_FER2 - j ) )], hp_filt[sub( L_FIR_FER2, j )] ); } L_tmp2 = Mpy_32_16_1( L_tmp2, st->cummulative_damping /*Q15*/ ); /*Q0, noise_e*/ noise[i] = mac_r( L_tmp2, gain_tmp, noise[i] ); /*Q15, noise_e*/ @@ -1776,11 +1776,11 @@ void con_tcx_ivas_fx( move16(); IF( A_cng != NULL ) { - gainSynthDeemph = shr( getLevelSynDeemph_fx( &( tmp16 ), A_cng, M, shr( L_frame, 2 ), st->preemph_fac, 1, &gainSynthDeemph_e ), 2 ); + gainSynthDeemph = shr( getLevelSynDeemph_fx( &( tmp16 ), A_cng, M, shr( L_frame, 2 ), st->preemph_fac, 1, &gainSynthDeemph_e ), 2 ); /*Q13*/ } ELSE { - gainSynthDeemph = getLevelSynDeemph_fx( &( tmp16 ), A_local, M, shr( L_frame, 2 ), st->preemph_fac, 1, &gainSynthDeemph_e ); + gainSynthDeemph = getLevelSynDeemph_fx( &( tmp16 ), A_local, M, shr( L_frame, 2 ), st->preemph_fac, 1, &gainSynthDeemph_e ); /*Q13*/ } #else tmp16 = 32767; @@ -1807,7 +1807,7 @@ void con_tcx_ivas_fx( { // gainCNG *= 1.f - (float)(st->nbLostCmpt - MDCT_ST_PLC_FADEOUT_MAX_CONC_FRAME) / MDCT_ST_PLC_FADEOUT_TO_ZERO_LEN; L_tmp = L_sub( ONE_IN_Q31, imult3216( 107374182 /* 1 / MDCT_ST_PLC_FADEOUT_TO_ZERO_LEN in Q31*/, sub( st->nbLostCmpt, MDCT_ST_PLC_FADEOUT_MAX_CONC_FRAME ) ) ); /* Q31 */ - gainCNG = extract_l( Mpy_32_32( gainCNG, L_tmp ) ); + gainCNG = extract_l( Mpy_32_32( gainCNG, L_tmp ) ); /*Q15-gainCNG_e*/ } } #endif @@ -1824,9 +1824,9 @@ void con_tcx_ivas_fx( gain32 = L_add( st->Mode2_lp_gainc, 0 ); /* start-of-the-frame gain - Q16*/ IF( EQ_16( st->rf_frame_type, RF_TCXTD1 ) && EQ_16( st->use_partial_copy, 1 ) ) { - gain32 = Mpy_32_16_1( gain32, 22938 /*0.7f Q15*/ ); + gain32 = Mpy_32_16_1( gain32, 22938 /*0.7f Q15*/ ); /*Q16*/ } - L_tmp = L_shl( gain32, 1 ); + L_tmp = L_shl( gain32, 1 ); /*Q16*/ IF( GT_32( L_shl( L_deposit_h( gainCNG ), sub( gainCNG_e, 31 - 16 ) /*Q16*/ ), L_tmp ) ) { @@ -1839,8 +1839,8 @@ void con_tcx_ivas_fx( L_tmp = Mpy_32_16_1( st->Mode2_lp_gainc, alpha ) /*Q15*/; L_tmp2 = L_mult( sub( 16384 /*1.f Q14*/, alpha ) /*Q14*/, gainCNG /*Q15,gainCNG_e*/ ); /*Q30,gainCNG_e*/ - st->Mode2_lp_gainc = BASOP_Util_Add_Mant32Exp( L_tmp, 31 - 15, L_tmp2, add( gainCNG_e, 31 - 30 ), &tmp_e ); /*Q31*/ - st->Mode2_lp_gainc = L_shl( st->Mode2_lp_gainc, sub( tmp_e, 31 - 16 ) ); + st->Mode2_lp_gainc = BASOP_Util_Add_Mant32Exp( L_tmp, 31 - 15, L_tmp2, add( gainCNG_e, 31 - 30 ), &tmp_e ); /*Q31-tmp_e*/ + st->Mode2_lp_gainc = L_shl( st->Mode2_lp_gainc, sub( tmp_e, 31 - 16 ) ); /*Q16*/ move32(); move32(); @@ -1873,7 +1873,7 @@ void con_tcx_ivas_fx( test(); IF( EQ_16( st->last_good, UNVOICED_CLAS ) && NE_16( st->core_ext_mode, UNVOICED ) ) { - gain_inov = mult_r( gain_inov, 26214 /*0.8f Q15*/ ); + gain_inov = mult_r( gain_inov, 26214 /*0.8f Q15*/ ); /*Q30*/ } ELSE IF( !( EQ_16( st->last_good, UNVOICED_CLAS ) || EQ_16( st->last_good, UNVOICED_TRANSITION ) ) ) { @@ -1907,7 +1907,7 @@ void con_tcx_ivas_fx( step32_tmp = L_shl( step32 /*Q25*/, sub( tmp_e, 25 - 16 ) ); /*Q16,-tmp_e*/ FOR( i = 0; i < tmp16; i++ ) /* Actual filtered random part of excitation */ { - *pt_exc = mult_r( *pt_exc, gain_tmp ); + *pt_exc = mult_r( *pt_exc, gain_tmp ); /*Q-15,noise_e+gain_inov_e-tmp_e*/ move16(); pt_exc++; gain32 = L_sub( gain32 /*Q16,-tmp_e*/, step32_tmp ); /*Q16,-tmp_e*/ @@ -1916,7 +1916,7 @@ void con_tcx_ivas_fx( tmp16 = shr( L_frame, 1 ); FOR( i = 0; i < tmp16; i++ ) /* causal ringing of the FIR filter */ { - *pt_exc = mult_r( *pt_exc, gain_tmp ); + *pt_exc = mult_r( *pt_exc, gain_tmp ); /*Q-15,noise_e+gain_inov_e-tmp_e*/ move16(); pt_exc++; } @@ -1944,7 +1944,7 @@ void con_tcx_ivas_fx( ELSE { bufferCopyFx( noise + L_FIR_FER2 / 2, exc, add( L_frame, shr( L_frame, 1 ) ), 0 /*Q_noise*/, noise_e, Q_exc, 0 /*exc_e*/ ); - Copy( exc + sub( L_frame, shl( L_subfr, 1 ) ), hTcxDec->old_excFB_fx, add( shl( L_subfr, 1 ), shr( L_frame, 1 ) ) ); + Copy( exc + sub( L_frame, shl( L_subfr, 1 ) ), hTcxDec->old_excFB_fx, add( shl( L_subfr, 1 ), shr( L_frame, 1 ) ) ); /*Q_exc*/ /* copy old_exc as 16kHz for acelp decoding */ IF( EQ_16( st->nbLostCmpt, 1 ) ) { @@ -1952,7 +1952,7 @@ void con_tcx_ivas_fx( } ELSE { - Copy( st->old_exc_fx + L_FRAME16k, st->old_exc_fx, L_FRAME16k / 2 ); + Copy( st->old_exc_fx + L_FRAME16k, st->old_exc_fx, L_FRAME16k / 2 ); /*Q_exc*/ lerp( exc, st->old_exc_fx + L_FRAME16k / 2, L_FRAME16k, L_frame ); } st->Q_exc = Q_exc; @@ -1962,15 +1962,15 @@ void con_tcx_ivas_fx( /*buf[OLD_EXC_SIZE_DEC;3/2 L_frame] Q1*/ /* Update Pitch Lag memory */ - Copy32( &st->old_pitch_buf_fx[st->nb_subfr], st->old_pitch_buf_fx, st->nb_subfr ); - Copy32( pitch_buf, &st->old_pitch_buf_fx[st->nb_subfr], st->nb_subfr ); + Copy32( &st->old_pitch_buf_fx[st->nb_subfr], st->old_pitch_buf_fx, st->nb_subfr ); /*Q16*/ + Copy32( pitch_buf, &st->old_pitch_buf_fx[st->nb_subfr], st->nb_subfr ); /*Q16*/ /*----------------------------------------------------------* * - compute the synthesis speech * *----------------------------------------------------------*/ - syn = buf + M; - Copy( synth - M, buf, M ); + syn = buf + M; /*Q_syn*/ + Copy( synth - M, buf, M ); /*Q_syn*/ new_Q = sub( Q_exc, 3 ); new_Q = s_max( new_Q, -1 ); @@ -1984,7 +1984,7 @@ void con_tcx_ivas_fx( Q_syn = tmp16; move16(); - Copy_Scale_sig( buf, mem_syn, M, exp_scale ); + Copy_Scale_sig( buf, mem_syn, M, exp_scale ); /* Q: tmp16 */ #ifdef BASOP_NOGLOB tmp_deemph = shl_sat( tmp_deemph, Q_syn ); @@ -2001,11 +2001,11 @@ void con_tcx_ivas_fx( { Word16 alpha_delayed; - alpha_delayed = 16384; + alpha_delayed = 16384; /*1.0f in Q14*/ move16(); IF( GT_16( st->nbLostCmpt, MDCT_ST_PLC_FADEOUT_DELAY_4_LSP_FADE ) ) { - alpha_delayed = Damping_fact_fx( st->core_ext_mode, st->nbLostCmpt - MDCT_ST_PLC_FADEOUT_DELAY_4_LSP_FADE, st->last_good, st->stab_fac_fx, &( st->Mode2_lp_gainp ), ACELP_CORE ); + alpha_delayed = Damping_fact_fx( st->core_ext_mode, st->nbLostCmpt - MDCT_ST_PLC_FADEOUT_DELAY_4_LSP_FADE, st->last_good, st->stab_fac_fx, &( st->Mode2_lp_gainp ), ACELP_CORE ); /*Q14*/ } test(); @@ -2013,13 +2013,13 @@ void con_tcx_ivas_fx( { Word16 lsp_local[M], lsp_fade[M], alpha_inv; - alpha_inv = sub( 16384, alpha_delayed ); + alpha_inv = sub( 16384 /*Q.0f in Q14*/, alpha_delayed ); /*Q14*/ E_LPC_a_lsp_conversion( A_local, lsp_local, lsp_local, M ); FOR( i = 0; i < M; i++ ) { - lsp_fade[i] = add( mult_r( alpha_delayed, lsp_local[i] ), mult_r( alpha_inv, st->lspold_cng[i] ) ); + lsp_fade[i] = add( mult_r( alpha_delayed, lsp_local[i] ), mult_r( alpha_inv, st->lspold_cng[i] ) ); /*Q14*/ move16(); } @@ -2043,37 +2043,37 @@ void con_tcx_ivas_fx( /*buf[0;M-1] Q0: mem_syn*/ /*buf[M;3/2 L_frame-1] Q-1: syn*/ - n = extract_h( L_mult( L_frame, 9216 /*(float)N_ZERO_MDCT_NS/(float)FRAME_SIZE_NS Q15*/ ) ); + n = extract_h( L_mult( L_frame, 9216 /*(float)N_ZERO_MDCT_NS/(float)FRAME_SIZE_NS Q15*/ ) ); /*Q0*/ /* update ACELP synthesis memory */ mem_syn_r_size_old = shr( L_frame, 4 ); /* replace 1.25/20.0 by shr(4) */ /* copy mem_syn as 16kHz */ mem_syn_r_size_new = shr( L_FRAME16k, 4 ); /* replace 1.25/20.0 by shr(4) */ - Copy( syn + sub( L_frame, L_SYN_MEM ), st->mem_syn_r, L_SYN_MEM ); + Copy( syn + sub( L_frame, L_SYN_MEM ), st->mem_syn_r, L_SYN_MEM ); /*Q_syn*/ lerp( st->mem_syn_r + sub( L_SYN_MEM, mem_syn_r_size_old ), st->mem_syn_r + sub( L_SYN_MEM, mem_syn_r_size_new ), mem_syn_r_size_new, mem_syn_r_size_old ); - Copy( st->mem_syn_r + L_SYN_MEM - M, st->mem_syn2_fx, M ); + Copy( st->mem_syn_r + L_SYN_MEM - M, st->mem_syn2_fx, M ); /*Q_syn*/ /* Deemphasis and output synth and ZIR */ deemph_fx( syn, st->preemph_fac, add( L_frame, shr( L_frame, 1 ) ), &tmp_deemph ); - bufferCopyFx( syn + sub( L_frame, M + 1 ), st->syn, 1 + M, Q_syn, 0, 0, 0 ); + bufferCopyFx( syn + sub( L_frame, M + 1 ), st->syn, 1 + M, Q_syn, 0, 0, 0 ); /*Q_syn*/ lerp( syn + sub( L_frame, shr( L_frame, 1 ) ), hTcxDec->old_syn_Overl, shr( st->L_frame, 1 ), shr( L_frame, 1 ) ); - Copy( syn + sub( L_frame, n ), hHQ_core->old_out_fx, sub( L_frame, n ) ); + Copy( syn + sub( L_frame, n ), hHQ_core->old_out_fx, sub( L_frame, n ) ); /*Q_syn*/ FOR( i = 0; i < W12; i++ ) { - hHQ_core->old_out_fx[add( i, n )] = round_fx( Mpy_32_16_1( L_mult( w[i].v.re, w[i].v.re ), hHQ_core->old_out_fx[add( i, n )] ) ); + hHQ_core->old_out_fx[( i + n )] = round_fx( Mpy_32_16_1( L_mult( w[i].v.re, w[i].v.re ), hHQ_core->old_out_fx[( i + n )] ) ); /*Q_syn*/ move16(); } FOR( ; i < W1; i++ ) { - hHQ_core->old_out_fx[add( i, n )] = round_fx( Mpy_32_16_1( L_mult( w[sub( sub( W12, 1 ), sub( i, W12 ) )].v.im, w[sub( sub( W12, 1 ), sub( i, W12 ) )].v.im ), hHQ_core->old_out_fx[add( i, n )] ) ); + hHQ_core->old_out_fx[( i + n )] = round_fx( Mpy_32_16_1( L_mult( w[( ( W12 - 1 ) - ( i - W12 ) )].v.im, w[( ( W12 - 1 ) - ( i - W12 ) )].v.im ), hHQ_core->old_out_fx[( i + n )] ) ); /*Q_syn*/ move16(); } - set16_fx( &hHQ_core->old_out_fx[add( W1, n )], 0, n ); + set16_fx( &hHQ_core->old_out_fx[( W1 + n )], 0, n ); hHQ_core->Q_old_wtda = Q_syn; move16(); @@ -2081,10 +2081,10 @@ void con_tcx_ivas_fx( /* As long as there is no synth scaling factor introduced, which is given to the outside, there might occur overflows here */ BASOP_SATURATE_WARNING_OFF_EVS - bufferCopyFx( syn, synth, L_frame, Q_syn, 0, 0, 0 ); + bufferCopyFx( syn, synth, L_frame, Q_syn, 0, 0, 0 ); /*Q_syn*/ BASOP_SATURATE_WARNING_ON_EVS - Copy_Scale_sig( syn + L_frame, hTcxDec->syn_OverlFB, shr( L_frame, 1 ), negate( Q_syn ) ); + Copy_Scale_sig( syn + L_frame, hTcxDec->syn_OverlFB, shr( L_frame, 1 ), negate( Q_syn ) ); /*Q0*/ /* copy total excitation exc2 as 16kHz for acelp mode1 decoding */ IF( st->hWIDec != NULL ) @@ -2109,49 +2109,49 @@ void con_tcx_ivas_fx( FOR( i = 0; i < W12; i++ ) { - buf[i] = mult_r( hTcxDec->syn_Overl_TDACFB[i], w[i].v.re ); + buf[i] = mult_r( hTcxDec->syn_Overl_TDACFB[i], w[i].v.re ); /*hTcxDec->Q_syn_Overl_TDACFB*/ move16(); } FOR( ; i < W1; i++ ) { - buf[i] = mult_r( hTcxDec->syn_Overl_TDACFB[i], w[sub( sub( W12, 1 ), sub( i, W12 ) )].v.im ); + buf[i] = mult_r( hTcxDec->syn_Overl_TDACFB[i], w[( ( W12 - 1 ) - ( i - W12 ) )].v.im ); /*hTcxDec->Q_syn_Overl_TDACFB*/ move16(); } FOR( i = 0; i < W2; i++ ) { - hTcxDec->syn_Overl_TDACFB[i] = add_sat( buf[i], buf[sub( sub( W1, 1 ), i )] ); + hTcxDec->syn_Overl_TDACFB[i] = add_sat( buf[i], buf[( ( W1 - 1 ) - i )] ); /*hTcxDec->Q_syn_Overl_TDACFB*/ move16(); } FOR( i = 0; i < W2; i++ ) { - hTcxDec->syn_Overl_TDACFB[add( W2, i )] = add_sat( buf[add( W2, i )], buf[sub( sub( sub( W1, 1 ), W2 ), i )] ); + hTcxDec->syn_Overl_TDACFB[( W2 + i )] = add_sat( buf[( W2 + i )], buf[( ( ( W1 - 1 ) - W2 ) - i )] ); /*hTcxDec->Q_syn_Overl_TDACFB*/ move16(); } FOR( i = 0; i < W12; i++ ) { - hTcxDec->syn_Overl_TDACFB[i] = mult_r( hTcxDec->syn_Overl_TDACFB[i], w[i].v.re ); + hTcxDec->syn_Overl_TDACFB[i] = mult_r( hTcxDec->syn_Overl_TDACFB[i], w[i].v.re ); /*hTcxDec->Q_syn_Overl_TDACFB*/ move16(); } FOR( ; i < W1; i++ ) { - hTcxDec->syn_Overl_TDACFB[i] = mult_r( hTcxDec->syn_Overl_TDACFB[i], w[sub( sub( W12, 1 ), sub( i, W12 ) )].v.im ); + hTcxDec->syn_Overl_TDACFB[i] = mult_r( hTcxDec->syn_Overl_TDACFB[i], w[( ( W12 - 1 ) - ( i - W12 ) )].v.im ); /*hTcxDec->Q_syn_Overl_TDACFB*/ move16(); } st->hTcxCfg->tcx_curr_overlap_mode = FULL_OVERLAP; move16(); - synth[-1] = pre_emph_buf; + synth[-1] = pre_emph_buf; /*Q0*/ move16(); /* update memory for low band */ st->Q_syn = 0; move16(); - Scale_sig( hTcxDec->old_syn_Overl, shr( st->L_frame, 1 ), sub( -1, Q_syn ) ); + Scale_sig( hTcxDec->old_syn_Overl, shr( st->L_frame, 1 ), sub( -1, Q_syn ) ); /*Q_syn*/ lerp( hTcxDec->syn_OverlFB, hTcxDec->syn_Overl, shr( st->L_frame, 1 ), shr( L_frame, 1 ) ); lerp( hTcxDec->syn_Overl_TDACFB, hTcxDec->syn_Overl_TDAC, shr( st->L_frame, 1 ), shr( L_frame, 1 ) ); hTcxDec->Q_syn_Overl_TDAC = hTcxDec->Q_syn_Overl_TDACFB; diff --git a/lib_dec/ivas_decision_matrix_dec.c b/lib_dec/ivas_decision_matrix_dec.c index 0a4e950f6..ec8de4900 100644 --- a/lib_dec/ivas_decision_matrix_dec.c +++ b/lib_dec/ivas_decision_matrix_dec.c @@ -514,7 +514,7 @@ void ivas_decision_matrix_dec_fx( test(); test(); test(); - IF( ( st->idchan == 0 && ( EQ_32( st->total_brate, FRAME_NO_DATA ) || EQ_32( st->total_brate, SID_2k40 ) ) ) || ( EQ_16( st->element_mode, IVAS_CPE_MDCT ) && LE_32( st->total_brate, SID_2k40 ) ) ) + IF( ( st->idchan == 0 && ( ( st->total_brate == FRAME_NO_DATA ) || EQ_32( st->total_brate, SID_2k40 ) ) ) || ( EQ_16( st->element_mode, IVAS_CPE_MDCT ) && LE_32( st->total_brate, SID_2k40 ) ) ) { st->core = ACELP_CORE; move16(); @@ -578,7 +578,7 @@ void ivas_decision_matrix_dec_fx( test(); test(); test(); - if ( EQ_32( st->total_brate, FRAME_NO_DATA ) && st->prev_bfi && !st->bfi && GT_16( st->L_frame, L_FRAME16k ) ) + if ( ( st->total_brate == FRAME_NO_DATA ) && st->prev_bfi && !st->bfi && GT_16( st->L_frame, L_FRAME16k ) ) { st->L_frame = st->last_CNG_L_frame; move16(); @@ -654,6 +654,7 @@ void ivas_decision_matrix_dec_fx( { *sharpFlag = 0; move16(); + test(); if ( EQ_16( st->coder_type, GENERIC ) || EQ_16( st->coder_type, VOICED ) ) { *sharpFlag = 1; @@ -678,6 +679,7 @@ void ivas_decision_matrix_dec_fx( IF( LT_32( element_brate, FRMT_SHP_MIN_BRATE_IVAS ) ) { st->coder_type = get_next_indice_fx( st, 3 ); + move16(); *sharpFlag = 0; move16(); @@ -694,9 +696,10 @@ void ivas_decision_matrix_dec_fx( { /* get coder_type info */ st->coder_type = get_next_indice_fx( st, 3 ); - + move16(); /* get sharpening flag */ *sharpFlag = get_next_indice_fx( st, 1 ); + move16(); } } } @@ -785,7 +788,7 @@ void ivas_decision_matrix_dec_fx( ELSE { st->extl = SWB_TBE; - move32(); + move16(); st->extl_brate = SWB_TBE_1k6; move32(); test(); @@ -878,7 +881,7 @@ void ivas_decision_matrix_dec_fx( test(); test(); test(); - if ( GE_16( st->element_mode, IVAS_CPE_DFT ) && EQ_16( st->core, ACELP_CORE ) && ( EQ_16( st->extl, SWB_TBE ) || EQ_16( st->extl, FB_TBE ) ) && !( EQ_16( st->element_mode, IVAS_CPE_TD ) && st->tdm_LRTD_flag ) ) + if ( GE_16( st->element_mode, IVAS_CPE_DFT ) && ( st->core == ACELP_CORE ) && ( EQ_16( st->extl, SWB_TBE ) || EQ_16( st->extl, FB_TBE ) ) && !( EQ_16( st->element_mode, IVAS_CPE_TD ) && st->tdm_LRTD_flag ) ) { icbwe_brate = L_add( icbwe_brate, STEREO_ICBWE_MSFLAG_BITS * FRAMES_PER_SEC ); } diff --git a/lib_dec/ivas_dirac_dec.c b/lib_dec/ivas_dirac_dec.c index a127cd1a4..155e03a17 100644 --- a/lib_dec/ivas_dirac_dec.c +++ b/lib_dec/ivas_dirac_dec.c @@ -278,6 +278,7 @@ static ivas_error ivas_dirac_rend_config_fx( IF( EQ_16( st_ivas->ivas_format, SBA_FORMAT ) || EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) { st_ivas->nchan_transport = ivas_sba_get_nchan_metadata_fx( st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate ); + move16(); } nchan_transport = st_ivas->nchan_transport; @@ -312,7 +313,7 @@ static ivas_error ivas_dirac_rend_config_fx( Copy32( hDirACRend->hOutSetup.ls_elevation_fx, ls_elevation_fx, nchan_out_woLFE ); } - IF( EQ_16( hDirACRend->hOutSetup.ambisonics_order, negate( (Word16) 1 ) ) ) + IF( EQ_16( hDirACRend->hOutSetup.ambisonics_order, -1 ) ) { hDirACRend->hOutSetup.ambisonics_order = SBA_HOA3_ORDER; /* Order 3 is used by default in DirAC for SHD processing */ move16(); @@ -340,6 +341,7 @@ static ivas_error ivas_dirac_rend_config_fx( { /* Remove the channel of the separated signal from the output setup of the spatial synthesis */ hDirACRend->hOutSetup.nchan_out_woLFE = sub( hDirACRend->hOutSetup.nchan_out_woLFE, 1 ); + move16(); nchan_out_woLFE = hDirACRend->hOutSetup.nchan_out_woLFE; move16(); Copy32( &ls_azimuth_fx[hDirACRend->hOutSetup.separateChannelIndex + 1], &ls_azimuth_fx[hDirACRend->hOutSetup.separateChannelIndex], sub( nchan_out_woLFE, hDirACRend->hOutSetup.separateChannelIndex ) ); @@ -470,7 +472,9 @@ static ivas_error ivas_dirac_rend_config_fx( /* Directional and diffuses components in SHD */ /* Diffuseness components up to 1st order */ hDirACRend->num_outputs_diff = mult0( ( add( s_min( hDirACRend->hOutSetup.ambisonics_order, 1 ), 1 ) ), ( add( s_min( hDirACRend->hOutSetup.ambisonics_order, 1 ), 1 ) ) ); + move16(); hDirACRend->num_outputs_dir = ivas_sba_get_nchan_fx( hDirACRend->hOutSetup.ambisonics_order, 0 ); + move16(); } ELSE IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_PSD_SHD ) ) { @@ -893,7 +897,7 @@ static ivas_error ivas_dirac_rend_config_fx( } test(); - IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_PSD_SHD ) || EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) + if ( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_PSD_SHD ) || EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) { hDirACRend->h_output_synthesis_psd_params.use_onset_filters = 0; move16(); @@ -934,6 +938,7 @@ static ivas_error ivas_dirac_rend_config_fx( } } hDirACRend->proto_frame_f_len = imult1616( 2, imult1616( hDirACRend->num_protos_diff, hSpatParamRendCom->num_freq_bands ) ); + move16(); } if ( EQ_16( flag_config, DIRAC_OPEN ) ) @@ -975,12 +980,13 @@ static ivas_error ivas_dirac_rend_config_fx( set32_fx( hDirACRend->buffer_energy_fx, 0, DIRAC_NO_COL_AVG_DIFF * CLDFB_NO_CHANNELS_MAX ); set16_fx( hDirACRend->q_buffer_energy, Q31, DIRAC_NO_COL_AVG_DIFF ); } - ELSE IF( ( EQ_16( flag_config, DIRAC_OPEN ) && EQ_16( hDirAC->hConfig->dec_param_estim, FALSE ) ) || ( EQ_16( flag_config, DIRAC_RECONFIGURE ) && ( EQ_16( hDirAC->hConfig->dec_param_estim, FALSE ) && EQ_16( dec_param_estim_old, TRUE ) ) ) ) + ELSE IF( ( EQ_16( flag_config, DIRAC_OPEN ) && hDirAC->hConfig->dec_param_estim == FALSE ) || ( EQ_16( flag_config, DIRAC_RECONFIGURE ) && ( ( hDirAC->hConfig->dec_param_estim == FALSE ) && EQ_16( dec_param_estim_old, TRUE ) ) ) ) { FOR( i = 0; i < DIRAC_NUM_DIMS; i++ ) { FOR( j = 0; j < DIRAC_NO_COL_AVG_DIFF; j++ ) { + test(); IF( EQ_16( flag_config, DIRAC_RECONFIGURE ) && hDirACRend->buffer_intensity_real_fx[i][j] ) { free( hDirACRend->buffer_intensity_real_fx[i][j] ); @@ -1702,7 +1708,7 @@ ivas_error ivas_dirac_dec_config_fx( move16(); test(); test(); - IF( EQ_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_FOA ) && EQ_16( st_ivas->ivas_format, SBA_FORMAT ) && !hodirac_flag ) + if ( EQ_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_FOA ) && EQ_16( st_ivas->ivas_format, SBA_FORMAT ) && !hodirac_flag ) { sparfoa_flag = 1; move16(); @@ -1829,7 +1835,7 @@ ivas_error ivas_dirac_dec_config_fx( /* This is required to keep BE in rate switching. This probably means that 1TC and 2TC MASA perform differently. */ test(); test(); - IF( st_ivas->hDiracDecBin->h_freq_domain_decorr_ap_params != NULL && !( st_ivas->ivas_format == MASA_FORMAT && st_ivas->nSCE > 0 ) ) + IF( st_ivas->hDiracDecBin->h_freq_domain_decorr_ap_params != NULL && !( EQ_32( st_ivas->ivas_format, MASA_FORMAT ) && st_ivas->nSCE > 0 ) ) { ivas_dirac_dec_decorr_close_fx( &st_ivas->hDiracDecBin->h_freq_domain_decorr_ap_params, &st_ivas->hDiracDecBin->h_freq_domain_decorr_ap_state ); // done } @@ -2029,7 +2035,7 @@ ivas_error ivas_dirac_dec_config( * * Close DirAC memories *------------------------------------------------------------------------*/ - +#ifndef IVAS_FLOAT_FIXED void ivas_dirac_dec_close( DIRAC_DEC_HANDLE *hDirAC_out ) { @@ -2055,7 +2061,7 @@ void ivas_dirac_dec_close( return; } -#ifdef IVAS_FLOAT_FIXED +#else void ivas_dirac_dec_close_fx( DIRAC_DEC_HANDLE *hDirAC_out ) { @@ -2112,6 +2118,7 @@ void ivas_dirac_dec_read_BS_fx( move16(); iDiv_and_mod_32( ivas_total_brate, FRAMES_PER_SEC, &quo, &rem, 0 ); st->next_bit_pos = extract_l( L_sub( quo, 1 ) ); + move16(); if ( last_bit_pos > 0 ) { st->next_bit_pos = last_bit_pos; @@ -2155,7 +2162,7 @@ void ivas_dirac_dec_read_BS_fx( } FOR( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) { - FOR( j = sub( orig_dirac_bands, 2 ); j >= 0; j-- ) + FOR( j = ( orig_dirac_bands - 2 ); j >= 0; j-- ) { hQMetaData->q_direction[0].band_data[j].azimuth_fx[i] = hQMetaData->q_direction[0].band_data[0].azimuth_fx[0]; move32(); @@ -2239,7 +2246,7 @@ void ivas_dirac_dec_read_BS_fx( } FOR( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) { - FOR( j = sub( orig_dirac_bands, 2 ); j >= 0; j-- ) + FOR( j = ( orig_dirac_bands - 2 ); j >= 0; j-- ) { hQMetaData->q_direction[0].band_data[j].azimuth_fx[i] = hQMetaData->q_direction[0].band_data[0].azimuth_fx[0]; move32(); @@ -2421,7 +2428,7 @@ void ivas_qmetadata_to_dirac_fx( const Word32 ivas_total_brate, /* i : IVAS total bitrate */ const IVAS_FORMAT ivas_format, /* i : IVAS format */ const Word16 hodirac_flag, /* i : flag to indicate HO-DirAC mode */ - Word16 *dirac_to_spar_md_bands /* o : DirAC->SPAR MD bands */ + Word16 *dirac_to_spar_md_bands /* o : DirAC->SPAR MD bands Q0*/ ) { Word16 block, band; @@ -2435,16 +2442,20 @@ void ivas_qmetadata_to_dirac_fx( Word16 *band_grouping; Word16 start_band; Word16 nbands = 0; + move16(); Word16 nblocks = 0; + move16(); Word16 qBand_idx; Word16 idx_sec = 0; + move16(); Word16 no_secs = 1; + move16(); q_direction = &( hQMetaData->q_direction[0] ); hSpatParamRendCom->numParametricDirections = hQMetaData->no_directions; move16(); hSpatParamRendCom->numSimultaneousDirections = add( hSpatParamRendCom->numParametricDirections, hSpatParamRendCom->numIsmDirections ); - + move16(); test(); IF( hMasa != NULL && GT_32( ivas_total_brate, IVAS_SID_5k2 ) ) { @@ -2642,7 +2653,6 @@ void ivas_qmetadata_to_dirac_fx( move16(); tmp_write_idx_band = add( tmp_write_idx_band, 1 ) % hSpatParamRendCom->dirac_md_buffer_length; - move16(); } } } @@ -2668,7 +2678,6 @@ void ivas_qmetadata_to_dirac_fx( IF( EQ_32( ivas_format, SBA_FORMAT ) ) { qBand_idx = sub( dirac_to_spar_md_bands[band], start_band ); - move16(); } ELSE { @@ -2740,14 +2749,13 @@ void ivas_qmetadata_to_dirac_fx( Word16 exp_factor = 0; move16(); a = rand_triangular_signed_fx( seed_ptr, &exp_factor ); // q = exp_factor - move16(); + tmp1 = mult( a, dirac_dithering_azi_scale_fx[diff_idx] ); // exp_factor + 5 Word32 tmp1_32 = L_deposit_h( tmp1 ); Word16 final_1_exp; Word32 final_1_32 = BASOP_Util_Add_Mant32Exp( azimuth_fx, 9, tmp1_32, exp_factor + 5, &final_1_exp ); - b_tmp = rand_triangular_signed_fx( seed_ptr, &exp_factor ); // q = exp_factor - move16(); + b_tmp = rand_triangular_signed_fx( seed_ptr, &exp_factor ); // q = exp_factor tmp4 = mult( b_tmp, dirac_dithering_ele_scale_fx[diff_idx] ); // exp_factor + 4 Word32 tmp4_32 = L_deposit_h( tmp4 ); @@ -2758,8 +2766,8 @@ void ivas_qmetadata_to_dirac_fx( final_1_32 = BASOP_Util_Add_Mant32Exp( final_1_32, final_1_exp, ONE_IN_Q30, 0, &final_1_exp ); /*0.5 in q31*/ final_2_32 = BASOP_Util_Add_Mant32Exp( final_2_32, final_2_exp, ONE_IN_Q30, 0, &final_2_exp ); - azi = extract_h( L_shr( final_1_32, 31 - final_1_exp - 16 ) ); - ele = extract_h( L_shr( final_2_32, 31 - final_2_exp - 16 ) ); + azi = extract_h( L_shr( final_1_32, sub( sub( 31, final_1_exp ), 16 ) ) ); + ele = extract_h( L_shr( final_2_32, sub( sub( 31, final_2_exp ), 16 ) ) ); /*addition of one to compensate precision loss*/ if ( azi < 0 ) @@ -2836,7 +2844,7 @@ void ivas_qmetadata_to_dirac_fx( } } tmp_write_idx_param_band = add( tmp_write_idx_param_band, 1 ) % hSpatParamRendCom->dirac_md_buffer_length; - move16(); + } /* for ( block =...) */ } /* for ( band = ...) */ @@ -2875,7 +2883,7 @@ void ivas_qmetadata_to_dirac_fx( } /* update buffer write index */ hSpatParamRendCom->dirac_bs_md_write_idx = add( hSpatParamRendCom->dirac_bs_md_write_idx, MAX_PARAM_SPATIAL_SUBFRAMES ) % hSpatParamRendCom->dirac_md_buffer_length; - + move16(); return; } #else @@ -3296,6 +3304,7 @@ void ivas_dirac_dec_set_md_map( } iDiv_and_mod_32( W_extract_l( W_shl_nosat( tmp_fx, 16 ) ), hSpatParamRendCom->subframe_nbslots[sf_idx], &quo, &rem, 0 ); hSpatParamRendCom->render_to_md_map[sf_idx] = add( round_fx( quo ), hSpatParamRendCom->dirac_read_idx ) % hSpatParamRendCom->dirac_md_buffer_length; + move16(); } set16_fx( &hSpatParamRendCom->render_to_md_map[hSpatParamRendCom->nb_subframes], 0, sub( MAX_JBM_SUBFRAMES_5MS * JBM_CLDFB_SLOTS_IN_SUBFRAME, hSpatParamRendCom->nb_subframes ) ); @@ -3458,15 +3467,12 @@ void ivas_dirac_dec_set_md_map_fx( norm_num = norm_l( tmp_fx ); num = L_shl( tmp_fx, norm_num ); exp_num = sub( exp_num, norm_num ); - move16(); norm_denom = norm_s( hSpatParamRendCom->subframe_nbslots[sf_idx] ); denom = shl( hSpatParamRendCom->subframe_nbslots[sf_idx], norm_denom ); exp_denom = sub( exp_denom, norm_denom ); - move16(); exp = sub( exp_num, exp_denom ); - move16(); IF( GT_32( num, L_deposit_l( denom ) ) ) { @@ -3478,7 +3484,7 @@ void ivas_dirac_dec_set_md_map_fx( ans_fix_32 = BASOP_Util_Add_Mant32Exp( ans, exp, L_deposit_h( hSpatParamRendCom->dirac_read_idx ), 15 /*31 - 16*/, &exp_final ); ans_fix_16 = round_fx( L_shr( ans_fix_32, sub( sub( Q31, exp_final ), Q16 ) ) ); - hSpatParamRendCom->render_to_md_map[sf_idx] = ans_fix_16 % hSpatParamRendCom->dirac_md_buffer_length; + hSpatParamRendCom->render_to_md_map[sf_idx] = ans_fix_16 % hSpatParamRendCom->dirac_md_buffer_length; // Q0 move16(); } set16_fx( &hSpatParamRendCom->render_to_md_map[hSpatParamRendCom->nb_subframes], 0, sub( MAX_JBM_SUBFRAMES_5MS * JBM_CLDFB_SLOTS_IN_SUBFRAME, hSpatParamRendCom->nb_subframes ) ); @@ -3500,7 +3506,7 @@ void ivas_dirac_dec_render_fx( const UWord16 nSamplesAsked, /* i : number of CLDFB slots requested */ UWord16 *nSamplesRendered, /* o : number of CLDFB slots rendered */ UWord16 *nSamplesAvailableNext, /* o : number of CLDFB slots still to render */ - Word32 *output_fx[] /* o : rendered time signal */ + Word32 *output_fx[] /* o : rendered time signal Q(6-1)*/ ) { Word16 slots_to_render, first_sf, last_sf, subframe_idx; @@ -3520,7 +3526,7 @@ void ivas_dirac_dec_render_fx( set_zero_fx( output_f_local_fx[ch], nSamplesAsked ); } slot_size = NS2SA( st_ivas->hDecoderConfig->output_Fs, CLDFB_SLOT_NS ); // cL - move16(); + /* loop for synthesis, assume we always have to render in multiples of 5ms subframes with spills */ slots_to_render = s_min( sub( hSpatParamRendCom->num_slots, hSpatParamRendCom->slots_rendered ), idiv1616( nSamplesAsked, slot_size ) ); @@ -3537,7 +3543,6 @@ void ivas_dirac_dec_render_fx( { slots_to_render = sub( slots_to_render, hSpatParamRendCom->subframe_nbslots[last_sf] ); last_sf = add( last_sf, 1 ); - move16(); } FOR( subframe_idx = first_sf; subframe_idx < last_sf; subframe_idx++ ) @@ -3563,7 +3568,7 @@ void ivas_dirac_dec_render_fx( { test(); test(); - IF( !( L_and( ( st_ivas->hDirACRend->hOutSetup.separateChannelEnabled ), ( L_or( EQ_16( st_ivas->hDirACRend->hOutSetup.separateChannelIndex, ch ), EQ_16( add( st_ivas->hDirACRend->hOutSetup.separateChannelIndex, 1 ), ch ) ) ) ) ) ) + IF( !( ( st_ivas->hDirACRend->hOutSetup.separateChannelEnabled ) && ( ( EQ_16( st_ivas->hDirACRend->hOutSetup.separateChannelIndex, ch ) || EQ_16( add( st_ivas->hDirACRend->hOutSetup.separateChannelIndex, 1 ), ch ) ) ) ) ) { Copy32( output_f_local_buff_fx[ch], output_fx[ch], *nSamplesRendered ); } @@ -3572,16 +3577,16 @@ void ivas_dirac_dec_render_fx( IF( EQ_16( hSpatParamRendCom->slots_rendered, hSpatParamRendCom->num_slots ) ){ IF( EQ_16( st_ivas->hDirAC->hConfig->dec_param_estim, 1 ) ){ temp = add( hSpatParamRendCom->dirac_read_idx, DEFAULT_JBM_CLDFB_TIMESLOTS ); - hSpatParamRendCom->dirac_read_idx = sub( temp, i_mult( idiv1616( temp, hSpatParamRendCom->dirac_md_buffer_length ), hSpatParamRendCom->dirac_md_buffer_length ) ); + hSpatParamRendCom->dirac_read_idx = sub( temp, i_mult( idiv1616( temp, hSpatParamRendCom->dirac_md_buffer_length ), hSpatParamRendCom->dirac_md_buffer_length ) ); // Q0 } ELSE { temp = add( hSpatParamRendCom->dirac_read_idx, DEFAULT_JBM_SUBFRAMES_5MS ); - hSpatParamRendCom->dirac_read_idx = sub( temp, i_mult( idiv1616( temp, hSpatParamRendCom->dirac_md_buffer_length ), hSpatParamRendCom->dirac_md_buffer_length ) ); + hSpatParamRendCom->dirac_read_idx = sub( temp, i_mult( idiv1616( temp, hSpatParamRendCom->dirac_md_buffer_length ), hSpatParamRendCom->dirac_md_buffer_length ) ); // Q0 } } -*nSamplesAvailableNext = i_mult( sub( hSpatParamRendCom->num_slots, hSpatParamRendCom->slots_rendered ), slot_size ); +*nSamplesAvailableNext = i_mult( sub( hSpatParamRendCom->num_slots, hSpatParamRendCom->slots_rendered ), slot_size ); // Q0 move16(); return; @@ -3677,11 +3682,12 @@ void ivas_dirac_dec_render( *------------------------------------------------------------------------*/ void ivas_dirac_dec_render_sf_fx( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ - Word32 *output_buf_fx[], /* i/o: synthesized core-coder transport channels/DirAC output */ - const Word16 nchan_transport, /* i : number of transport channels */ - Word32 *pppQMfFrame_ts_re_fx[IVAS_MAX_FB_MIXER_IN_CH][CLDFB_NO_COL_MAX], - Word32 *pppQMfFrame_ts_im_fx[IVAS_MAX_FB_MIXER_IN_CH][CLDFB_NO_COL_MAX] ) + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + Word32 *output_buf_fx[], /* i/o: synthesized core-coder transport channels/DirAC output Q(6-1)*/ + const Word16 nchan_transport, /* i : number of transport channels */ + Word32 *pppQMfFrame_ts_re_fx[IVAS_MAX_FB_MIXER_IN_CH][CLDFB_NO_COL_MAX], /*Q6*/ + Word32 *pppQMfFrame_ts_im_fx[IVAS_MAX_FB_MIXER_IN_CH][CLDFB_NO_COL_MAX] /*Q6*/ +) { Word16 i, ch, idx_in, idx_lfe; DIRAC_DEC_HANDLE hDirAC; @@ -3785,15 +3791,16 @@ void ivas_dirac_dec_render_sf_fx( } test(); - IF( L_or( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_PSD_LS ), EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_PSD_SHD ) ) ) + IF( ( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_PSD_LS ) || EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_PSD_SHD ) ) ) { IF( hDirACRend->h_output_synthesis_psd_params.max_band_decorr != 0 ) { DIRAC_OUTPUT_SYNTHESIS_STATE *state = &( hDirACRend->h_output_synthesis_psd_state ); tmp1 = L_norm_arr( state->proto_power_diff_smooth_fx, state->proto_power_diff_smooth_len ); - scale_sig32( state->proto_power_diff_smooth_fx, state->proto_power_diff_smooth_len, tmp1 ); + scale_sig32( state->proto_power_diff_smooth_fx, state->proto_power_diff_smooth_len, tmp1 ); // Q(proto_power_diff_smooth_q + tmp1) state->proto_power_diff_smooth_q = add( state->proto_power_diff_smooth_q, tmp1 ); + move16(); } } @@ -3813,7 +3820,7 @@ void ivas_dirac_dec_render_sf_fx( IF( h_dirac_output_synthesis_params->use_onset_filters && ( NE_16( hDirAC->hConfig->dec_param_estim, TRUE ) && NE_32( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) ) { tmp1 = getScaleFactor32( h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx, imult1616( num_channels_dir, hSpatParamRendCom->num_freq_bands ) ); - scale_sig32( h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx, imult1616( num_channels_dir, hSpatParamRendCom->num_freq_bands ), sub( tmp1, h_dirac_output_synthesis_state->q_cy_auto_diff_smooth ) ); + scale_sig32( h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx, imult1616( num_channels_dir, hSpatParamRendCom->num_freq_bands ), sub( tmp1, h_dirac_output_synthesis_state->q_cy_auto_diff_smooth ) ); // tmp1 h_dirac_output_synthesis_state->q_cy_auto_diff_smooth = tmp1; move16(); } @@ -3823,18 +3830,20 @@ void ivas_dirac_dec_render_sf_fx( { Word16 shift; shift = L_norm_arr( h_dirac_output_synthesis_state->cy_auto_dir_smooth_fx, imult1616( num_channels_dir, hSpatParamRendCom->num_freq_bands ) ); - scale_sig32( h_dirac_output_synthesis_state->cy_auto_dir_smooth_fx, imult1616( num_channels_dir, hSpatParamRendCom->num_freq_bands ), shift ); + scale_sig32( h_dirac_output_synthesis_state->cy_auto_dir_smooth_fx, imult1616( num_channels_dir, hSpatParamRendCom->num_freq_bands ), shift ); // h_dirac_output_synthesis_state->q_cy_auto_dir_smooth + shift h_dirac_output_synthesis_state->q_cy_auto_dir_smooth = add( h_dirac_output_synthesis_state->q_cy_auto_dir_smooth, shift ); - + move16(); shift = L_norm_arr( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx, imult1616( num_channels_dir, hSpatParamRendCom->num_freq_bands ) ); - scale_sig32( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx, imult1616( num_channels_dir, hSpatParamRendCom->num_freq_bands ), shift ); + scale_sig32( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx, imult1616( num_channels_dir, hSpatParamRendCom->num_freq_bands ), shift ); // h_dirac_output_synthesis_state->q_cy_auto_dir_smooth + shift h_dirac_output_synthesis_state->q_cy_cross_dir_smooth = add( h_dirac_output_synthesis_state->q_cy_cross_dir_smooth, shift ); - + move16(); tmp1 = L_norm_arr( h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx, imult1616( num_channels_dir, hSpatParamRendCom->num_freq_bands ) ); - scale_sig32( h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx, imult1616( num_channels_dir, hSpatParamRendCom->num_freq_bands ), tmp1 ); + scale_sig32( h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx, imult1616( num_channels_dir, hSpatParamRendCom->num_freq_bands ), tmp1 ); // h_dirac_output_synthesis_state->q_cy_auto_dir_smooth + tmp1 h_dirac_output_synthesis_state->q_cy_auto_diff_smooth = add( h_dirac_output_synthesis_state->q_cy_auto_diff_smooth, tmp1 ); + move16(); } + test(); test(); IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) ) @@ -3845,7 +3854,7 @@ void ivas_dirac_dec_render_sf_fx( move16(); } } - ELSE IF( !L_or( EQ_16( st_ivas->ivas_format, SBA_FORMAT ), EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) ) + ELSE IF( !( EQ_16( st_ivas->ivas_format, SBA_FORMAT ) || EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) ) { Word16 outchannels; idx_lfe = 0; @@ -3877,7 +3886,7 @@ void ivas_dirac_dec_render_sf_fx( FOR( ch = 0; ch < outchannels; ch++ ) { test(); - IF( L_and( hDirACRend->hOutSetup.num_lfe > 0, ( EQ_16( hDirACRend->hOutSetup.index_lfe[idx_lfe], ch ) ) ) ) + IF( ( hDirACRend->hOutSetup.num_lfe > 0 && ( EQ_16( hDirACRend->hOutSetup.index_lfe[idx_lfe], ch ) ) ) ) { IF( LT_16( idx_lfe, sub( hDirACRend->hOutSetup.num_lfe, 1 ) ) ) { @@ -3890,10 +3899,12 @@ void ivas_dirac_dec_render_sf_fx( { FOR( ch = 0; ch < outchannels; ch++ ) { + test(); test(); - IF( L_and( hDirACRend->hOutSetup.num_lfe > 0, ( EQ_16( hDirACRend->hOutSetup.index_lfe[idx_lfe], ch ) ) ) ) + IF( ( hDirACRend->hOutSetup.num_lfe > 0 && ( EQ_16( hDirACRend->hOutSetup.index_lfe[idx_lfe], ch ) ) ) ) { + test(); IF( EQ_16( st_ivas->mc_mode, MC_MODE_MCMASA ) && !hDirACRend->hOutSetup.separateChannelEnabled ) { Word16 cldfbSynIdx; @@ -3925,7 +3936,7 @@ void ivas_dirac_dec_render_sf_fx( size_ho = size; move16(); } - scale_sig32( hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_fx, size, sub( Q26, hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_q ) ); + scale_sig32( hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_fx, size, sub( Q26, hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_q ) ); // Q26 hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_q = Q26; move16(); @@ -3933,49 +3944,51 @@ void ivas_dirac_dec_render_sf_fx( { Word16 shift; shift = L_norm_arr( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_fx, size_ho ); - scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_fx, size_ho, shift ); + scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_fx, size_ho, shift ); // Q(hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth + shift) hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth = add( hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth, shift ); + move16(); - scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev_fx, size_ho, sub( Q26, hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev ) ); + scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev_fx, size_ho, sub( Q26, hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev ) ); // Q26 hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev = Q26; move16(); - scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_fx, imult1616( hDirACRend->num_outputs_diff, hDirACRend->h_output_synthesis_psd_params.max_band_decorr ), sub( Q26, hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth ) ); + scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_fx, imult1616( hDirACRend->num_outputs_diff, hDirACRend->h_output_synthesis_psd_params.max_band_decorr ), sub( Q26, hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth ) ); // Q26 hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth = Q26; move16(); - scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_prev_fx, imult1616( hDirACRend->num_outputs_diff, hDirACRend->h_output_synthesis_psd_params.max_band_decorr ), sub( Q26, hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth_prev ) ); + scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_prev_fx, imult1616( hDirACRend->num_outputs_diff, hDirACRend->h_output_synthesis_psd_params.max_band_decorr ), sub( Q26, hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth_prev ) ); // Q26 hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth_prev = Q26; move16(); } ELSE { Word16 shift; - scale_sig32( hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_fx, imult1616( hSpatParamRendCom->num_freq_bands, hDirACRend->hOutSetup.nchan_out_woLFE ), sub( Q26, hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_q ) ); + scale_sig32( hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_fx, imult1616( hSpatParamRendCom->num_freq_bands, hDirACRend->hOutSetup.nchan_out_woLFE ), sub( Q26, hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_q ) ); // Q26 hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_q = Q26; move16(); shift = L_norm_arr( hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_prev_fx, size_ho ); - scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_prev_fx, size_ho, shift ); + scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_prev_fx, size_ho, shift ); // Q( hDirACRend->h_output_synthesis_psd_state.q_cy_auto_dir_smooth_prev+ shift) hDirACRend->h_output_synthesis_psd_state.q_cy_auto_dir_smooth_prev = add( hDirACRend->h_output_synthesis_psd_state.q_cy_auto_dir_smooth_prev, shift ); - + move16(); shift = L_norm_arr( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev_fx, size_ho ); - scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev_fx, size_ho, shift ); + scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev_fx, size_ho, shift ); // Q(hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev + shift) hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev = add( hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev, shift ); - + move16(); tmp1 = L_norm_arr( hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_prev_fx, imult1616( hSpatParamRendCom->num_freq_bands, hDirACRend->hOutSetup.nchan_out_woLFE ) ); - scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_prev_fx, imult1616( hSpatParamRendCom->num_freq_bands, hDirACRend->hOutSetup.nchan_out_woLFE ), tmp1 ); + scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_prev_fx, imult1616( hSpatParamRendCom->num_freq_bands, hDirACRend->hOutSetup.nchan_out_woLFE ), tmp1 ); // Q(hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth_prev+ tmp1) hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth_prev = add( hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth_prev, tmp1 ); - + move16(); tmp1 = L_norm_arr( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_fx, imult1616( hDirACRend->num_protos_dir, hSpatParamRendCom->num_freq_bands ) ); - scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_fx, imult1616( hDirACRend->num_protos_dir, hSpatParamRendCom->num_freq_bands ), tmp1 ); + scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_fx, imult1616( hDirACRend->num_protos_dir, hSpatParamRendCom->num_freq_bands ), tmp1 ); // Q(hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q tmp1) hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q = add( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q, tmp1 ); - + move16(); IF( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_fx != 0 ) { tmp1 = L_norm_arr( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_fx, imult1616( hDirACRend->h_output_synthesis_psd_params.max_band_decorr, hDirACRend->hOutSetup.nchan_out_woLFE ) ); - scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_fx, imult1616( hDirACRend->h_output_synthesis_psd_params.max_band_decorr, hDirACRend->hOutSetup.nchan_out_woLFE ), tmp1 ); + scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_fx, imult1616( hDirACRend->h_output_synthesis_psd_params.max_band_decorr, hDirACRend->hOutSetup.nchan_out_woLFE ), tmp1 ); // Q(hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_q+ tmp1) hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_q = add( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_q, tmp1 ); + move16(); } } @@ -4001,7 +4014,7 @@ void ivas_dirac_dec_render_sf_fx( subframe_idx = hSpatParamRendCom->subframes_rendered; move16(); - IF( EQ_16( hDirAC->hConfig->dec_param_estim, FALSE ) ) + IF( ( hDirAC->hConfig->dec_param_estim == FALSE ) ) { md_idx = hSpatParamRendCom->render_to_md_map[subframe_idx]; move16(); @@ -4013,7 +4026,7 @@ void ivas_dirac_dec_render_sf_fx( } /* copy parameters into local buffers*/ - IF( EQ_16( hDirAC->hConfig->dec_param_estim, FALSE ) ) + IF( ( hDirAC->hConfig->dec_param_estim == FALSE ) ) { Copy32( hSpatParamRendCom->diffuseness_vector_fx[hSpatParamRendCom->render_to_md_map[subframe_idx]], diffuseness_vector_fx, hSpatParamRendCom->num_freq_bands ); q_diffuseness_vector = Q30; @@ -4028,7 +4041,7 @@ void ivas_dirac_dec_render_sf_fx( move16(); } - IF( hDirACRend->synthesisConf != DIRAC_SYNTHESIS_GAIN_SHD ) + IF( NE_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) { set_zero_fx( reference_power_smooth_fx, hSpatParamRendCom->num_freq_bands ); } @@ -4046,7 +4059,7 @@ void ivas_dirac_dec_render_sf_fx( { num_freq_bands = hDirAC->band_grouping[hDirAC->hConfig->enc_param_start_band]; move16(); - IF( EQ_16( hDirAC->hConfig->dec_param_estim, FALSE ) ) + IF( ( hDirAC->hConfig->dec_param_estim == FALSE ) ) { rotateAziEle_DirAC_fx( azimuth, elevation, num_freq_bands, hSpatParamRendCom->num_freq_bands, p_Rmat_fx ); } @@ -4055,13 +4068,14 @@ void ivas_dirac_dec_render_sf_fx( ELSE { p_Rmat_fx = 0; + move32(); } - IF( EQ_16( hDirAC->hConfig->dec_param_estim, FALSE ) ) + IF( ( hDirAC->hConfig->dec_param_estim == FALSE ) ) { Word16 *masa_band_mapping; /* compute response */ - IF( hDirACRend->synthesisConf != DIRAC_SYNTHESIS_GAIN_SHD ) + IF( NE_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) { ivas_dirac_dec_compute_power_factors_fx( hSpatParamRendCom->num_freq_bands, diffuseness_vector_fx, @@ -4089,7 +4103,7 @@ void ivas_dirac_dec_render_sf_fx( surCohRatio_fx[i] = BASOP_Util_Divide3232_Scale( surCohEner_fx, ( L_add( EPSILLON_FX, L_add( dirEne_fx, surCohEner_fx ) ) ), &temp_q ); move32(); - surCohRatio_fx[i] = L_shl( surCohRatio_fx[i], temp_q ); + surCohRatio_fx[i] = L_shl( surCohRatio_fx[i], temp_q ); // Q31 move32(); } } @@ -4114,13 +4128,16 @@ void ivas_dirac_dec_render_sf_fx( &max_exp_direct, &max_exp_diffusion ); hDirACRend->h_output_synthesis_psd_state.direct_power_factor_q = sub( Q31, max_exp_direct ); + move16(); hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_q = sub( Q31, max_exp_diffusion ); + move16(); IF( coherence_flag ) { FOR( i = 0; i < hSpatParamRendCom->num_freq_bands; i++ ) { surCohRatio_fx[i] = L_deposit_l( hSpatParamRendCom->surroundingCoherence_fx[md_idx][i] ); + move32(); } } ELSE @@ -4176,7 +4193,7 @@ void ivas_dirac_dec_render_sf_fx( } test(); - IF( L_and( EQ_16( st_ivas->ivas_format, MASA_ISM_FORMAT ), EQ_16( nchan_transport, 2 ) ) ) + IF( ( EQ_16( st_ivas->ivas_format, MASA_ISM_FORMAT ) && EQ_16( nchan_transport, 2 ) ) ) { FOR( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[subframe_idx]; slot_idx++ ) { @@ -4198,7 +4215,7 @@ void ivas_dirac_dec_render_sf_fx( } test(); - IF( L_and( NE_16( st_ivas->ism_mode, ISM_MASA_MODE_DISC ), NE_16( st_ivas->ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) ) ) + IF( ( NE_16( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) && NE_16( st_ivas->ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) ) ) { ivas_omasa_preProcessStereoTransportsForMovedObjects_fx( st_ivas, Cldfb_RealBuffer_Temp_fx, Cldfb_ImagBuffer_Temp_fx, &cldfb_buf_q, hSpatParamRendCom->num_freq_bands, subframe_idx ); } @@ -4219,7 +4236,7 @@ void ivas_dirac_dec_render_sf_fx( } test(); test(); - IF( L_or( EQ_16( st_ivas->ivas_format, SBA_FORMAT ), EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) ) + IF( ( EQ_16( st_ivas->ivas_format, SBA_FORMAT ) || EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) ) { FOR( ch = 0; ch < nchan_transport; ch++ ) { @@ -4229,7 +4246,7 @@ void ivas_dirac_dec_render_sf_fx( q_cldfb = Q6; move16(); } - ELSE IF( L_and( EQ_16( st_ivas->ivas_format, MASA_ISM_FORMAT ), EQ_16( nchan_transport, 2 ) ) ) + ELSE IF( ( EQ_16( st_ivas->ivas_format, MASA_ISM_FORMAT ) && EQ_16( nchan_transport, 2 ) ) ) { FOR( ch = 0; ch < nchan_transport; ch++ ) { @@ -4260,13 +4277,16 @@ void ivas_dirac_dec_render_sf_fx( test(); test(); test(); - IF( EQ_16( st_ivas->nchan_transport, 1 ) && st_ivas->hSCE[0]->hCoreCoder[0] != NULL && st_ivas->hSCE[0]->hCoreCoder[0]->cna_dirac_flag && !( L_or( EQ_16( st_ivas->ivas_format, SBA_FORMAT ), EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) ) ) + IF( EQ_16( st_ivas->nchan_transport, 1 ) && st_ivas->hSCE[0]->hCoreCoder[0] != NULL && st_ivas->hSCE[0]->hCoreCoder[0]->cna_dirac_flag && !( ( EQ_16( st_ivas->ivas_format, SBA_FORMAT ) || EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) ) ) { Decoder_State *st = st_ivas->hSCE[0]->hCoreCoder[0]; Word16 Q_input = Q11; move16(); q_temp_cldfb = Q11; move16(); + test(); + test(); + test(); generate_masking_noise_dirac_ivas_fx( st->hFdCngDec->hFdCngCom, st_ivas->cldfbAnaDec[1], st_ivas->hTcBuffer->tc_fx[1], @@ -4274,9 +4294,9 @@ void ivas_dirac_dec_render_sf_fx( Cldfb_ImagBuffer_fx[1][0], index_slot, st->cna_dirac_flag && st->flag_cna, - ( L_or( EQ_32( st->core_brate, FRAME_NO_DATA ), EQ_32( st->core_brate, SID_2k40 ) ) ) && EQ_16( st->cng_type, FD_CNG ) && st->cng_sba_flag, Q_input, &q_temp_cldfb ); - Scale_sig32( Cldfb_RealBuffer_fx[1][0], CLDFB_NO_CHANNELS_MAX, sub( Q6, q_temp_cldfb ) ); - Scale_sig32( Cldfb_ImagBuffer_fx[1][0], CLDFB_NO_CHANNELS_MAX, sub( Q6, q_temp_cldfb ) ); + ( ( ( st->core_brate == FRAME_NO_DATA ) || EQ_32( st->core_brate, SID_2k40 ) ) ) && EQ_16( st->cng_type, FD_CNG ) && st->cng_sba_flag, Q_input, &q_temp_cldfb ); + Scale_sig32( Cldfb_RealBuffer_fx[1][0], CLDFB_NO_CHANNELS_MAX, sub( Q6, q_temp_cldfb ) ); // Q6 + Scale_sig32( Cldfb_ImagBuffer_fx[1][0], CLDFB_NO_CHANNELS_MAX, sub( Q6, q_temp_cldfb ) ); // Q6 } /* LFE synthesis */ @@ -4450,6 +4470,7 @@ void ivas_dirac_dec_render_sf_fx( ELSE { hDirACRend->index_buffer_intensity = add( sub( hDirACRend->index_buffer_intensity, i_mult( idiv1616( hDirACRend->index_buffer_intensity, DIRAC_NO_COL_AVG_DIFF ), DIRAC_NO_COL_AVG_DIFF ) ), 1 ); /* averaging_length = 32 */ + move16(); } index = hDirACRend->index_buffer_intensity; @@ -4494,7 +4515,7 @@ void ivas_dirac_dec_render_sf_fx( hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_q, hDirACRend->num_protos_diff, hDirACRend->proto_index_diff, - &hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_fx[add( imult1616( imult1616( imult1616( slot_idx, 2 ), hSpatParamRendCom->num_freq_bands ), hDirACRend->num_outputs_diff ), imult1616( imult1616( 2, hSpatParamRendCom->num_freq_bands ), s_min( 4, nchan_transport ) ) )], + &hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_fx[( ( ( slot_idx * 2 ) * hSpatParamRendCom->num_freq_bands ) * hDirACRend->num_outputs_diff ) + ( ( 2 * hSpatParamRendCom->num_freq_bands ) * s_min( 4, nchan_transport ) )], &hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_q, onset_filter_fx, hDirACRend->h_freq_domain_decorr_ap_params, @@ -4508,8 +4529,9 @@ void ivas_dirac_dec_render_sf_fx( ELSE { scale = L_norm_arr( hDirACRend->proto_frame_f_fx, proto_length ); - Scale_sig32( hDirACRend->proto_frame_f_fx, proto_length, scale ); + Scale_sig32( hDirACRend->proto_frame_f_fx, proto_length, scale ); // Q(proto_frame_f_q+scale) hDirACRend->proto_frame_f_q = add( hDirACRend->proto_frame_f_q, scale ); + move16(); ivas_dirac_dec_decorr_process_fx( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_diff, hDirACRend->num_protos_diff, @@ -4556,7 +4578,7 @@ void ivas_dirac_dec_render_sf_fx( * output synthesis *-----------------------------------------------------------------*/ test(); - IF( L_or( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_PSD_LS ), EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_PSD_SHD ) ) ) + IF( ( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_PSD_LS ) || EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_PSD_SHD ) ) ) { DIRAC_OUTPUT_SYNTHESIS_STATE *state; Word16 diffuse_start; @@ -4564,13 +4586,13 @@ void ivas_dirac_dec_render_sf_fx( diffuse_start = i_mult( i_mult( slot_idx, 2 ), i_mult( hDirACRend->h_output_synthesis_psd_params.max_band_decorr, hDirACRend->hOutSetup.nchan_out_woLFE ) ); exp = getScaleFactor32( hDirACRend->proto_frame_dec_f_fx, hDirACRend->proto_frame_dec_f_len ); - scale_sig32( hDirACRend->proto_frame_dec_f_fx, hDirACRend->proto_frame_dec_f_len, exp ); + scale_sig32( hDirACRend->proto_frame_dec_f_fx, hDirACRend->proto_frame_dec_f_len, exp ); // hDirACRend->proto_frame_dec_f_q + exp hDirACRend->proto_frame_dec_f_q = add( hDirACRend->proto_frame_dec_f_q, exp ); - + move16(); exp = getScaleFactor32( state->proto_diffuse_buffer_f_fx, diffuse_start ); - scale_sig32( state->proto_diffuse_buffer_f_fx, diffuse_start, exp ); + scale_sig32( state->proto_diffuse_buffer_f_fx, diffuse_start, exp ); // state->proto_diffuse_buffer_f_q + exp state->proto_diffuse_buffer_f_q = add( state->proto_diffuse_buffer_f_q, exp ); - + move16(); /*Compute diffuse prototypes*/ ivas_dirac_dec_compute_diffuse_proto_fx( hDirACRend, hSpatParamRendCom->num_freq_bands, slot_idx ); } @@ -4589,47 +4611,49 @@ void ivas_dirac_dec_render_sf_fx( test(); test(); - IF( L_and( h_dirac_output_synthesis_params->use_onset_filters, L_and( NE_16( hDirAC->hConfig->dec_param_estim, TRUE ), NE_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) ) ) + IF( ( h_dirac_output_synthesis_params->use_onset_filters && ( NE_16( hDirAC->hConfig->dec_param_estim, TRUE ) && NE_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) ) ) { - Scale_sig32( h_dirac_output_synthesis_state->diffuse_power_factor_fx, h_dirac_output_synthesis_state->diff_dir_power_factor_len, sub( Q31, h_dirac_output_synthesis_state->diffuse_power_factor_q ) ); + Scale_sig32( h_dirac_output_synthesis_state->diffuse_power_factor_fx, h_dirac_output_synthesis_state->diff_dir_power_factor_len, sub( Q31, h_dirac_output_synthesis_state->diffuse_power_factor_q ) ); // Q31 h_dirac_output_synthesis_state->diffuse_power_factor_q = Q31; move16(); exp = getScaleFactor32( h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx, i_mult( num_channels_dir, hSpatParamRendCom->num_freq_bands ) ); - scale_sig32( h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx, i_mult( num_channels_dir, hSpatParamRendCom->num_freq_bands ), exp ); + scale_sig32( h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx, i_mult( num_channels_dir, hSpatParamRendCom->num_freq_bands ), exp ); // h_dirac_output_synthesis_state->q_cy_auto_diff_smooth + exp h_dirac_output_synthesis_state->q_cy_auto_diff_smooth = add( h_dirac_output_synthesis_state->q_cy_auto_diff_smooth, exp ); + move16(); } test(); - IF( L_and( EQ_16( hDirAC->hConfig->dec_param_estim, TRUE ), NE_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) ) + IF( ( EQ_16( hDirAC->hConfig->dec_param_estim, TRUE ) && NE_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) ) { - scale_sig32( h_dirac_output_synthesis_state->direct_power_factor_fx, h_dirac_output_synthesis_state->diff_dir_power_factor_len, sub( Q31, h_dirac_output_synthesis_state->direct_power_factor_q ) ); + scale_sig32( h_dirac_output_synthesis_state->direct_power_factor_fx, h_dirac_output_synthesis_state->diff_dir_power_factor_len, sub( Q31, h_dirac_output_synthesis_state->direct_power_factor_q ) ); // Q31 h_dirac_output_synthesis_state->direct_power_factor_q = Q31; move16(); - scale_sig32( h_dirac_output_synthesis_state->diffuse_power_factor_fx, h_dirac_output_synthesis_state->diff_dir_power_factor_len, sub( Q31, h_dirac_output_synthesis_state->diffuse_power_factor_q ) ); + scale_sig32( h_dirac_output_synthesis_state->diffuse_power_factor_fx, h_dirac_output_synthesis_state->diff_dir_power_factor_len, sub( Q31, h_dirac_output_synthesis_state->diffuse_power_factor_q ) ); // Q31 h_dirac_output_synthesis_state->diffuse_power_factor_q = Q31; move16(); - scale_sig32( h_dirac_output_synthesis_state->direct_responses_fx, i_mult( num_channels_dir, hSpatParamRendCom->num_freq_bands ), sub( Q31, h_dirac_output_synthesis_state->direct_responses_q ) ); + scale_sig32( h_dirac_output_synthesis_state->direct_responses_fx, i_mult( num_channels_dir, hSpatParamRendCom->num_freq_bands ), sub( Q31, h_dirac_output_synthesis_state->direct_responses_q ) ); // Q31 h_dirac_output_synthesis_state->direct_responses_q = Q31; move16(); - scale_sig32( h_dirac_output_synthesis_state->direct_responses_square_fx, i_mult( num_channels_dir, hSpatParamRendCom->num_freq_bands ), sub( Q31, h_dirac_output_synthesis_state->direct_responses_square_q ) ); + scale_sig32( h_dirac_output_synthesis_state->direct_responses_square_fx, i_mult( num_channels_dir, hSpatParamRendCom->num_freq_bands ), sub( Q31, h_dirac_output_synthesis_state->direct_responses_square_q ) ); // Q31 h_dirac_output_synthesis_state->direct_responses_square_q = Q31; move16(); exp = getScaleFactor32( h_dirac_output_synthesis_state->cy_auto_dir_smooth_fx, i_mult( num_channels_dir, hSpatParamRendCom->num_freq_bands ) ); - scale_sig32( h_dirac_output_synthesis_state->cy_auto_dir_smooth_fx, i_mult( num_channels_dir, hSpatParamRendCom->num_freq_bands ), exp ); + scale_sig32( h_dirac_output_synthesis_state->cy_auto_dir_smooth_fx, i_mult( num_channels_dir, hSpatParamRendCom->num_freq_bands ), exp ); // h_dirac_output_synthesis_state->q_cy_auto_dir_smooth, exp h_dirac_output_synthesis_state->q_cy_auto_dir_smooth = add( h_dirac_output_synthesis_state->q_cy_auto_dir_smooth, exp ); - + move16(); exp = getScaleFactor32( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx, i_mult( num_channels_dir, hSpatParamRendCom->num_freq_bands ) ); - scale_sig32( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx, i_mult( num_channels_dir, hSpatParamRendCom->num_freq_bands ), exp ); + scale_sig32( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx, i_mult( num_channels_dir, hSpatParamRendCom->num_freq_bands ), exp ); // h_dirac_output_synthesis_state->q_cy_auto_dir_smooth+ exp h_dirac_output_synthesis_state->q_cy_cross_dir_smooth = add( h_dirac_output_synthesis_state->q_cy_cross_dir_smooth, exp ); - + move16(); exp = getScaleFactor32( h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx, i_mult( num_channels_dir, hSpatParamRendCom->num_freq_bands ) ); - scale_sig32( h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx, i_mult( num_channels_dir, hSpatParamRendCom->num_freq_bands ), exp ); + scale_sig32( h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx, i_mult( num_channels_dir, hSpatParamRendCom->num_freq_bands ), exp ); // h_dirac_output_synthesis_state->q_cy_auto_diff_smooth+ exp h_dirac_output_synthesis_state->q_cy_auto_diff_smooth = add( h_dirac_output_synthesis_state->q_cy_auto_diff_smooth, exp ); + move16(); } test(); @@ -4685,13 +4709,13 @@ void ivas_dirac_dec_render_sf_fx( IF( LT_16( q_diffuseness_vector, hSpatParamRendCom->q_diffuseness_vector ) ) { - scale_sig32( hSpatParamRendCom->diffuseness_vector_fx[md_idx], hSpatParamRendCom->num_freq_bands, sub( q_diffuseness_vector, hSpatParamRendCom->q_diffuseness_vector ) ); + scale_sig32( hSpatParamRendCom->diffuseness_vector_fx[md_idx], hSpatParamRendCom->num_freq_bands, sub( q_diffuseness_vector, hSpatParamRendCom->q_diffuseness_vector ) ); // q_diffuseness_vector hSpatParamRendCom->q_diffuseness_vector = q_diffuseness_vector; move16(); } ELSE { - scale_sig32( diffuseness_vector_fx, hSpatParamRendCom->num_freq_bands, sub( hSpatParamRendCom->q_diffuseness_vector, q_diffuseness_vector ) ); + scale_sig32( diffuseness_vector_fx, hSpatParamRendCom->num_freq_bands, sub( hSpatParamRendCom->q_diffuseness_vector, q_diffuseness_vector ) ); // q_diffuseness_vector q_diffuseness_vector = hSpatParamRendCom->q_diffuseness_vector; move16(); } @@ -4702,13 +4726,13 @@ void ivas_dirac_dec_render_sf_fx( { IF( LT_16( q_reference_power_smooth, DirAC_mem.reference_power_q ) ) { - scale_sig32( reference_power_fx, hSpatParamRendCom->num_freq_bands, sub( q_reference_power_smooth, DirAC_mem.reference_power_q ) ); + scale_sig32( reference_power_fx, hSpatParamRendCom->num_freq_bands, sub( q_reference_power_smooth, DirAC_mem.reference_power_q ) ); // q_reference_power_smooth DirAC_mem.reference_power_q = q_reference_power_smooth; move16(); } ELSE { - scale_sig32( reference_power_smooth_fx, hSpatParamRendCom->num_freq_bands, sub( DirAC_mem.reference_power_q, q_reference_power_smooth ) ); + scale_sig32( reference_power_smooth_fx, hSpatParamRendCom->num_freq_bands, sub( DirAC_mem.reference_power_q, q_reference_power_smooth ) ); // reference_power_q q_reference_power_smooth = DirAC_mem.reference_power_q; move16(); } @@ -4728,17 +4752,17 @@ void ivas_dirac_dec_render_sf_fx( { offset = i_mult( i_mult( slot_idx, 2 ), i_mult( hSpatParamRendCom->num_freq_bands, nchan_transport ) ); buff_len = i_mult( 2, i_mult( nchan_transport, hSpatParamRendCom->num_freq_bands ) ); - scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_fx + offset, buff_len, sub( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q, q_proto_direct_buffer[slot_idx] ) ); + scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_fx + offset, buff_len, sub( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q, q_proto_direct_buffer[slot_idx] ) ); // proto_direct_buffer_f_q offset = i_mult( i_mult( slot_idx, 2 ), i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_diff ) ); - buff_len = 2 * hDirACRend->num_outputs_diff * hSpatParamRendCom->num_freq_bands; - scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_fx + offset, buff_len, sub( hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_q, q_proto_diffuse_buffer[slot_idx] ) ); + buff_len = i_mult( 2, i_mult( hDirACRend->num_outputs_diff, hSpatParamRendCom->num_freq_bands ) ); + scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_fx + offset, buff_len, sub( hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_q, q_proto_diffuse_buffer[slot_idx] ) ); // proto_diffuse_buffer_f_q } ELSE IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_MONO ) ) { offset = i_mult( slot_idx, i_mult( 4, hSpatParamRendCom->num_freq_bands ) ); buff_len = i_mult( 4, hSpatParamRendCom->num_freq_bands ); - scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_fx + offset, buff_len, sub( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q, q_proto_direct_buffer[slot_idx] ) ); + scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_fx + offset, buff_len, sub( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q, q_proto_direct_buffer[slot_idx] ) ); // proto_direct_buffer_f_q } ELSE { @@ -4750,7 +4774,7 @@ void ivas_dirac_dec_render_sf_fx( case 4: offset = i_mult( i_mult( slot_idx, 2 ), i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_diff ) ); buff_len = i_mult( 2, i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_diff ) ); - scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_fx + offset, buff_len, sub( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q, q_proto_direct_buffer[slot_idx] ) ); + scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_fx + offset, buff_len, sub( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q, q_proto_direct_buffer[slot_idx] ) ); // proto_direct_buffer_f_q BREAK; case 2: IF( hDirACRend->hOutSetup.is_loudspeaker_setup ) @@ -4763,16 +4787,17 @@ void ivas_dirac_dec_render_sf_fx( offset = i_mult( i_mult( i_mult( slot_idx, 2 ), hSpatParamRendCom->num_freq_bands ), 2 ); buff_len = i_mult( 4, hSpatParamRendCom->num_freq_bands ); } - scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_fx + offset, buff_len, sub( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q, q_proto_direct_buffer[slot_idx] ) ); + scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_fx + offset, buff_len, sub( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q, q_proto_direct_buffer[slot_idx] ) ); // proto_direct_buffer_f_q BREAK; case 1: offset = i_mult( slot_idx, i_mult( 2, hSpatParamRendCom->num_freq_bands ) ); buff_len = i_mult( 2, hSpatParamRendCom->num_freq_bands ); - scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_fx + offset, buff_len, sub( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q, q_proto_direct_buffer[slot_idx] ) ); + scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_fx + offset, buff_len, sub( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q, q_proto_direct_buffer[slot_idx] ) ); // proto_direct_buffer_f_q BREAK; } } q_proto_direct_buffer[slot_idx] = hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q; + move16(); } ivas_dirac_dec_output_synthesis_get_interpolator_fx( &hDirACRend->h_output_synthesis_psd_params, hSpatParamRendCom->subframe_nbslots[subframe_idx] ); @@ -4792,44 +4817,45 @@ void ivas_dirac_dec_render_sf_fx( { IF( NE_16( hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth, Q26 ) ) { - Scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_fx, size_ho, sub( Q26, hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth ) ); + Scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_fx, size_ho, sub( Q26, hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth ) ); // Q26 hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth = Q26; + move16(); } IF( NE_16( hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev, Q26 ) ) { - scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev_fx, size_ho, sub( Q26, hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev ) ); + scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev_fx, size_ho, sub( Q26, hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev ) ); // Q26 } IF( NE_16( hDirACRend->h_output_synthesis_psd_state.direct_power_factor_q, Q31 ) ) { - Scale_sig32( hDirACRend->h_output_synthesis_psd_state.direct_power_factor_fx, h_dirac_output_synthesis_state->diff_dir_power_factor_len, sub( Q31, hDirACRend->h_output_synthesis_psd_state.direct_power_factor_q ) ); + Scale_sig32( hDirACRend->h_output_synthesis_psd_state.direct_power_factor_fx, h_dirac_output_synthesis_state->diff_dir_power_factor_len, sub( Q31, hDirACRend->h_output_synthesis_psd_state.direct_power_factor_q ) ); // Q31 } IF( NE_16( hDirACRend->h_output_synthesis_psd_state.direct_responses_q, Q31 ) ) { - Scale_sig32( hDirACRend->h_output_synthesis_psd_state.direct_responses_fx, size_ho, sub( Q31, hDirACRend->h_output_synthesis_psd_state.direct_responses_q ) ); + Scale_sig32( hDirACRend->h_output_synthesis_psd_state.direct_responses_fx, size_ho, sub( Q31, hDirACRend->h_output_synthesis_psd_state.direct_responses_q ) ); // Q31 } IF( NE_16( hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_q, Q31 ) ) { - Scale_sig32( hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_fx, h_dirac_output_synthesis_state->diff_dir_power_factor_len, sub( Q31, hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_q ) ); + Scale_sig32( hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_fx, h_dirac_output_synthesis_state->diff_dir_power_factor_len, sub( Q31, hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_q ) ); // Q31 } IF( NE_16( hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth, Q26 ) ) { - scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_fx, i_mult( hDirACRend->num_outputs_diff, hDirACRend->h_output_synthesis_psd_params.max_band_decorr ), sub( Q26, hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth ) ); + scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_fx, i_mult( hDirACRend->num_outputs_diff, hDirACRend->h_output_synthesis_psd_params.max_band_decorr ), sub( Q26, hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth ) ); // Q26 } IF( NE_16( hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth_prev, Q26 ) ) { - scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_prev_fx, i_mult( hDirACRend->num_outputs_diff, hDirACRend->h_output_synthesis_psd_params.max_band_decorr ), sub( Q26, hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth_prev ) ); + scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_prev_fx, i_mult( hDirACRend->num_outputs_diff, hDirACRend->h_output_synthesis_psd_params.max_band_decorr ), sub( Q26, hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth_prev ) ); // Q26 } IF( NE_16( q_diffuseness_vector, Q30 ) ) { - scale_sig32( diffuseness_vector_fx, hSpatParamRendCom->num_freq_bands, sub( Q30, q_diffuseness_vector ) ); + scale_sig32( diffuseness_vector_fx, hSpatParamRendCom->num_freq_bands, sub( Q30, q_diffuseness_vector ) ); // Q30 } IF( NE_16( hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_q, Q26 ) ) { - scale_sig32( hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_fx, size, sub( Q26, hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_q ) ); + scale_sig32( hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_fx, size, sub( Q26, hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_q ) ); // Q26 } IF( NE_16( hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_q, Q26 ) ) { - scale_sig32( hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_fx, i_mult( hDirACRend->num_outputs_diff, hDirACRend->h_output_synthesis_psd_params.max_band_decorr ), sub( Q26, hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_q ) ); + scale_sig32( hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_fx, i_mult( hDirACRend->num_outputs_diff, hDirACRend->h_output_synthesis_psd_params.max_band_decorr ), sub( Q26, hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_q ) ); // Q26 } ivas_dirac_dec_output_synthesis_process_subframe_gain_shd_fx( Cldfb_RealBuffer_fx, @@ -4852,8 +4878,8 @@ void ivas_dirac_dec_render_sf_fx( { FOR( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[subframe_idx]; slot_idx++ ) { - scale_sig32( Cldfb_RealBuffer_fx[ch][slot_idx], hSpatParamRendCom->num_freq_bands, sub( Q6, add( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q, sub( hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev, 33 ) ) ) ); - scale_sig32( Cldfb_ImagBuffer_fx[ch][slot_idx], hSpatParamRendCom->num_freq_bands, sub( Q6, add( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q, sub( hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev, 33 ) ) ) ); + scale_sig32( Cldfb_RealBuffer_fx[ch][slot_idx], hSpatParamRendCom->num_freq_bands, sub( Q6, add( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q, sub( hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev, 33 ) ) ) ); // Q6 + scale_sig32( Cldfb_ImagBuffer_fx[ch][slot_idx], hSpatParamRendCom->num_freq_bands, sub( Q6, add( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q, sub( hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev, 33 ) ) ) ); // Q6 } } } @@ -4863,8 +4889,8 @@ void ivas_dirac_dec_render_sf_fx( { FOR( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[subframe_idx]; slot_idx++ ) { - scale_sig32( Cldfb_RealBuffer_fx[ch][slot_idx], hSpatParamRendCom->num_freq_bands, sub( Q6, add( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q, sub( hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev, 33 ) ) ) ); - scale_sig32( Cldfb_ImagBuffer_fx[ch][slot_idx], hSpatParamRendCom->num_freq_bands, sub( Q6, add( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q, sub( hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev, 33 ) ) ) ); + scale_sig32( Cldfb_RealBuffer_fx[ch][slot_idx], hSpatParamRendCom->num_freq_bands, sub( Q6, add( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q, sub( hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev, 33 ) ) ) ); // Q6 + scale_sig32( Cldfb_ImagBuffer_fx[ch][slot_idx], hSpatParamRendCom->num_freq_bands, sub( Q6, add( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q, sub( hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev, 33 ) ) ) ); // Q6 } } } @@ -4884,37 +4910,37 @@ void ivas_dirac_dec_render_sf_fx( IF( NE_16( hDirACRend->h_output_synthesis_psd_state.direct_power_factor_q, Q31 ) ) { - Scale_sig32( hDirACRend->h_output_synthesis_psd_state.direct_power_factor_fx, h_dirac_output_synthesis_state->diff_dir_power_factor_len, sub( Q31, hDirACRend->h_output_synthesis_psd_state.direct_power_factor_q ) ); + Scale_sig32( hDirACRend->h_output_synthesis_psd_state.direct_power_factor_fx, h_dirac_output_synthesis_state->diff_dir_power_factor_len, sub( Q31, hDirACRend->h_output_synthesis_psd_state.direct_power_factor_q ) ); // Q31 } IF( NE_16( hDirACRend->h_output_synthesis_psd_state.direct_responses_q, Q31 ) ) { - Scale_sig32( hDirACRend->h_output_synthesis_psd_state.direct_responses_fx, size, sub( Q31, hDirACRend->h_output_synthesis_psd_state.direct_responses_q ) ); + Scale_sig32( hDirACRend->h_output_synthesis_psd_state.direct_responses_fx, size, sub( Q31, hDirACRend->h_output_synthesis_psd_state.direct_responses_q ) ); // Q31 } IF( NE_16( hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_q, Q31 ) ) { - Scale_sig32( hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_fx, h_dirac_output_synthesis_state->diff_dir_power_factor_len, sub( Q31, hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_q ) ); + Scale_sig32( hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_fx, h_dirac_output_synthesis_state->diff_dir_power_factor_len, sub( Q31, hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_q ) ); // Q31 } IF( NE_16( q_diffuseness_vector, Q31 ) ) { - Scale_sig32( diffuseness_vector_fx, hSpatParamRendCom->num_freq_bands, sub( Q31, q_diffuseness_vector ) ); + Scale_sig32( diffuseness_vector_fx, hSpatParamRendCom->num_freq_bands, sub( Q31, q_diffuseness_vector ) ); // Q31 } IF( NE_16( hDirACRend->h_output_synthesis_psd_state.direct_responses_square_q, Q31 ) ) { - Scale_sig32( hDirACRend->h_output_synthesis_psd_state.direct_responses_square_fx, i_mult( hDirACRend->num_outputs_dir, hSpatParamRendCom->num_freq_bands ), sub( Q31, hDirACRend->h_output_synthesis_psd_state.direct_responses_square_q ) ); + Scale_sig32( hDirACRend->h_output_synthesis_psd_state.direct_responses_square_fx, i_mult( hDirACRend->num_outputs_dir, hSpatParamRendCom->num_freq_bands ), sub( Q31, hDirACRend->h_output_synthesis_psd_state.direct_responses_square_q ) ); // Q31 } exp = L_norm_arr( reference_power_smooth_fx, hSpatParamRendCom->num_freq_bands ); - scale_sig32( reference_power_smooth_fx, hSpatParamRendCom->num_freq_bands, exp ); + scale_sig32( reference_power_smooth_fx, hSpatParamRendCom->num_freq_bands, exp ); // q_reference_power_smooth + exp q_reference_power_smooth = add( q_reference_power_smooth, exp ); IF( LT_16( q_reference_power_smooth, hDirACRend->h_output_synthesis_psd_state.reference_power_smooth_prev_q ) ) { - scale_sig32( hDirACRend->h_output_synthesis_psd_state.reference_power_smooth_prev_fx, hSpatParamRendCom->num_freq_bands, sub( q_reference_power_smooth, hDirACRend->h_output_synthesis_psd_state.reference_power_smooth_prev_q ) ); + scale_sig32( hDirACRend->h_output_synthesis_psd_state.reference_power_smooth_prev_fx, hSpatParamRendCom->num_freq_bands, sub( q_reference_power_smooth, hDirACRend->h_output_synthesis_psd_state.reference_power_smooth_prev_q ) ); // q_reference_power_smooth hDirACRend->h_output_synthesis_psd_state.reference_power_smooth_prev_q = q_reference_power_smooth; move16(); } ELSE { - scale_sig32( reference_power_smooth_fx, hSpatParamRendCom->num_freq_bands, sub( hDirACRend->h_output_synthesis_psd_state.reference_power_smooth_prev_q, q_reference_power_smooth ) ); + scale_sig32( reference_power_smooth_fx, hSpatParamRendCom->num_freq_bands, sub( hDirACRend->h_output_synthesis_psd_state.reference_power_smooth_prev_q, q_reference_power_smooth ) ); // reference_power_smooth_prev_q q_reference_power_smooth = hDirACRend->h_output_synthesis_psd_state.reference_power_smooth_prev_q; move16(); } @@ -4923,49 +4949,52 @@ void ivas_dirac_dec_render_sf_fx( { IF( LT_16( hDirACRend->masa_stereo_type_detect->q_subtract_power_y, hDirACRend->masa_stereo_type_detect->q_subtract_power_y_smooth ) ) { - hDirACRend->masa_stereo_type_detect->subtract_power_y_smooth_fx = L_shr( hDirACRend->masa_stereo_type_detect->subtract_power_y_smooth_fx, sub( hDirACRend->masa_stereo_type_detect->q_subtract_power_y_smooth, hDirACRend->masa_stereo_type_detect->q_subtract_power_y ) ); + hDirACRend->masa_stereo_type_detect->subtract_power_y_smooth_fx = L_shr( hDirACRend->masa_stereo_type_detect->subtract_power_y_smooth_fx, sub( hDirACRend->masa_stereo_type_detect->q_subtract_power_y_smooth, hDirACRend->masa_stereo_type_detect->q_subtract_power_y ) ); // q_subtract_power_y + move32(); hDirACRend->masa_stereo_type_detect->q_subtract_power_y_smooth = hDirACRend->masa_stereo_type_detect->q_subtract_power_y; move16(); } ELSE { - hDirACRend->masa_stereo_type_detect->subtract_power_y_fx = L_shr( hDirACRend->masa_stereo_type_detect->subtract_power_y_fx, sub( hDirACRend->masa_stereo_type_detect->q_subtract_power_y, hDirACRend->masa_stereo_type_detect->q_subtract_power_y_smooth ) ); + hDirACRend->masa_stereo_type_detect->subtract_power_y_fx = L_shr( hDirACRend->masa_stereo_type_detect->subtract_power_y_fx, sub( hDirACRend->masa_stereo_type_detect->q_subtract_power_y, hDirACRend->masa_stereo_type_detect->q_subtract_power_y_smooth ) ); // q_subtract_power_y + move32(); hDirACRend->masa_stereo_type_detect->q_subtract_power_y = hDirACRend->masa_stereo_type_detect->q_subtract_power_y_smooth; move16(); } } exp = getScaleFactor32( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_fx, proto_power_smooth_len ); - scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_fx, proto_power_smooth_len, exp ); + scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_fx, proto_power_smooth_len, exp ); // Q(hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q + exp) hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q = add( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q, exp ); - + move16(); IF( LT_16( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q, hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q ) ) { - scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_fx, i_mult( hDirACRend->num_protos_dir, hSpatParamRendCom->num_freq_bands ), sub( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q, hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q ) ); + scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_fx, i_mult( hDirACRend->num_protos_dir, hSpatParamRendCom->num_freq_bands ), sub( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q, hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q ) ); // proto_power_smooth_q hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q = hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q; move16(); } ELSE { - scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_fx, i_mult( hDirACRend->num_protos_dir, hSpatParamRendCom->num_freq_bands ), sub( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q, hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q ) ); + scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_fx, i_mult( hDirACRend->num_protos_dir, hSpatParamRendCom->num_freq_bands ), sub( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q, hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q ) ); // proto_power_smooth_prev_q hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q = hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q; move16(); } exp = getScaleFactor32( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_fx, i_mult( hDirACRend->h_output_synthesis_psd_params.max_band_decorr, hDirACRend->hOutSetup.nchan_out_woLFE ) ); - scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_fx, i_mult( hDirACRend->h_output_synthesis_psd_params.max_band_decorr, hDirACRend->hOutSetup.nchan_out_woLFE ), exp ); + scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_fx, i_mult( hDirACRend->h_output_synthesis_psd_params.max_band_decorr, hDirACRend->hOutSetup.nchan_out_woLFE ), exp ); // Q(hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_q + exp) hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_q = add( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_q, exp ); + move16(); IF( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_fx != 0 ) { IF( LT_16( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_q, hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_q ) ) { - scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_fx, i_mult( hDirACRend->h_output_synthesis_psd_params.max_band_decorr, hDirACRend->hOutSetup.nchan_out_woLFE ), sub( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_q, hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_q ) ); + scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_fx, i_mult( hDirACRend->h_output_synthesis_psd_params.max_band_decorr, hDirACRend->hOutSetup.nchan_out_woLFE ), sub( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_q, hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_q ) ); // proto_power_diff_smooth_q hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_q = hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_q; move16(); } ELSE { - scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_fx, i_mult( hDirACRend->h_output_synthesis_psd_params.max_band_decorr, hDirACRend->hOutSetup.nchan_out_woLFE ), sub( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_q, hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_q ) ); + scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_fx, i_mult( hDirACRend->h_output_synthesis_psd_params.max_band_decorr, hDirACRend->hOutSetup.nchan_out_woLFE ), sub( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_q, hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_q ) ); // proto_power_diff_smooth_prev_q hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_q = hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_q; move16(); } @@ -4973,15 +5002,15 @@ void ivas_dirac_dec_render_sf_fx( IF( NE_16( hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_q, Q26 ) ) { - scale_sig32( hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_fx, size, sub( Q26, hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_q ) ); + scale_sig32( hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_fx, size, sub( Q26, hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_q ) ); // Q26 } IF( NE_16( hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_q, Q26 ) ) { - scale_sig32( hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_fx, i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->hOutSetup.nchan_out_woLFE ), sub( Q26, hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_q ) ); + scale_sig32( hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_fx, i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->hOutSetup.nchan_out_woLFE ), sub( Q26, hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_q ) ); // Q26 } IF( hDirACRend->proto_signal_decorr_on ) { - Scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_fx, hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_len, sub( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q, hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_q ) ); + Scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_fx, hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_len, sub( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q, hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_q ) ); // proto_direct_buffer_f_q hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_q = hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q; move16(); } @@ -5015,8 +5044,8 @@ void ivas_dirac_dec_render_sf_fx( { FOR( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[subframe_idx]; slot_idx++ ) { - scale_sig32( Cldfb_RealBuffer_fx[ch][slot_idx], hSpatParamRendCom->num_freq_bands, sub( Q6, q_Cldfb ) ); - scale_sig32( Cldfb_ImagBuffer_fx[ch][slot_idx], hSpatParamRendCom->num_freq_bands, sub( Q6, q_Cldfb ) ); + scale_sig32( Cldfb_RealBuffer_fx[ch][slot_idx], hSpatParamRendCom->num_freq_bands, sub( Q6, q_Cldfb ) ); // Q6 + scale_sig32( Cldfb_ImagBuffer_fx[ch][slot_idx], hSpatParamRendCom->num_freq_bands, sub( Q6, q_Cldfb ) ); // Q6 } } } @@ -5030,12 +5059,12 @@ void ivas_dirac_dec_render_sf_fx( test(); test(); - IF( L_or( EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ), EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) ) ) + IF( ( EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) || EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) ) ) { /* render objects in combined format onto the CICP19 channels for BINAURAL_ROOM_IR */ test(); test(); - IF( L_and( L_and( EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ), EQ_16( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) ), EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) ) ) + IF( ( ( EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) && EQ_16( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) ) && EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) ) ) { Word16 in_ch; FOR( in_ch = 0; in_ch < st_ivas->nchan_ism; in_ch++ ) @@ -5092,7 +5121,7 @@ void ivas_dirac_dec_render_sf_fx( for ( j = 0, j2 = 0; j < nchan_out_woLFE; j++, j2++ ) { test(); - IF( L_and( st_ivas->hIntSetup.num_lfe > 0, ( EQ_16( st_ivas->hIntSetup.index_lfe[lfe_index], j ) ) ) ) + IF( ( st_ivas->hIntSetup.num_lfe > 0 && ( EQ_16( st_ivas->hIntSetup.index_lfe[lfe_index], j ) ) ) ) { IF( LT_16( lfe_index, sub( st_ivas->hIntSetup.num_lfe, 1 ) ) ) { @@ -5109,28 +5138,30 @@ void ivas_dirac_dec_render_sf_fx( prev_gain_fx = st_ivas->hIsmRendererData->prev_gains_fx[i][j]; move32(); test(); - IF( L_or( L_abs( gain_fx ) > 0, L_abs( prev_gain_fx ) > 0 ) ) + IF( ( L_abs( gain_fx ) > 0 || L_abs( prev_gain_fx ) > 0 ) ) { Word32 *tc_re_fx, *tc_im_fx; Word16 *w1_fx, w2_fx; w1_fx = &st_ivas->hIsmRendererData->interpolator_fx[interp_offset]; - tc_re_fx = pppQMfFrame_ts_re_fx[add( nchan_transport, i )][0]; + tc_re_fx = pppQMfFrame_ts_re_fx[nchan_transport + i][0]; move32(); - tc_im_fx = pppQMfFrame_ts_im_fx[add( nchan_transport, i )][0]; + tc_im_fx = pppQMfFrame_ts_im_fx[nchan_transport + i][0]; move32(); FOR( k = 0; k < n_slots_to_render; k++ ) { Word32 g_fx; w2_fx = sub( MAX16B, *w1_fx ); - g_fx = L_add( Mpy_32_16_1( gain_fx, *w1_fx ), Mpy_32_16_1( prev_gain_fx, w2_fx ) ); + g_fx = L_add( Mpy_32_16_1( gain_fx, *w1_fx ), Mpy_32_16_1( prev_gain_fx, w2_fx ) ); // Q15 FOR( l = 0; l < hSpatParamRendCom->num_freq_bands; l++ ) { Word32 tmp; tmp = Mpy_32_32( g_fx, *tc_re_fx ); - Cldfb_RealBuffer_fx[j2][0][add( i_mult( k, hSpatParamRendCom->num_freq_bands ), l )] = L_add( Cldfb_RealBuffer_fx[j2][0][add( i_mult( k, hSpatParamRendCom->num_freq_bands ), l )], tmp ); + Cldfb_RealBuffer_fx[j2][0][k * hSpatParamRendCom->num_freq_bands + l] = L_add( Cldfb_RealBuffer_fx[j2][0][k * hSpatParamRendCom->num_freq_bands + l], tmp ); + move32(); tc_re_fx++; tmp = Mpy_32_32( g_fx, *tc_im_fx ); - Cldfb_ImagBuffer_fx[j2][0][add( i_mult( k, hSpatParamRendCom->num_freq_bands ), l )] = L_add( Cldfb_ImagBuffer_fx[j2][0][add( i_mult( k, hSpatParamRendCom->num_freq_bands ), l )], tmp ); + Cldfb_ImagBuffer_fx[j2][0][k * hSpatParamRendCom->num_freq_bands + l] = L_add( Cldfb_ImagBuffer_fx[j2][0][k * hSpatParamRendCom->num_freq_bands + l], tmp ); + move32(); tc_re_fx++; } w1_fx += hSpatParamRendCom->num_freq_bands; @@ -5159,14 +5190,14 @@ void ivas_dirac_dec_render_sf_fx( Cldfb_RealBuffer_Binaural_fx, Cldfb_ImagBuffer_Binaural_fx, Cldfb_RealBuffer_fx, Cldfb_ImagBuffer_fx, &input_q ); - Scale_sig32( Cldfb_RealBuffer_Binaural_fx[0][0], i_mult( BINAURAL_CHANNELS, i_mult( MAX_PARAM_SPATIAL_SUBFRAMES, CLDFB_NO_CHANNELS_MAX ) ), sub( Q6, input_q ) ); - Scale_sig32( Cldfb_ImagBuffer_Binaural_fx[0][0], i_mult( BINAURAL_CHANNELS, i_mult( MAX_PARAM_SPATIAL_SUBFRAMES, CLDFB_NO_CHANNELS_MAX ) ), sub( Q6, input_q ) ); + Scale_sig32( Cldfb_RealBuffer_Binaural_fx[0][0], i_mult( BINAURAL_CHANNELS, i_mult( MAX_PARAM_SPATIAL_SUBFRAMES, CLDFB_NO_CHANNELS_MAX ) ), sub( Q6, input_q ) ); // Q6 + Scale_sig32( Cldfb_ImagBuffer_Binaural_fx[0][0], i_mult( BINAURAL_CHANNELS, i_mult( MAX_PARAM_SPATIAL_SUBFRAMES, CLDFB_NO_CHANNELS_MAX ) ), sub( Q6, input_q ) ); // Q6 /* Inverse CLDFB*/ FOR( ch = 0; ch < st_ivas->hDecoderConfig->nchan_out; ch++ ) { /* open CLDFB buffer up to CLDFB_NO_CHANNELS_MAX bands for 48kHz */ - Word32 *synth_fx = &output_buf_fx[ch][i_mult( index_slot, hSpatParamRendCom->num_freq_bands )]; + Word32 *synth_fx = &output_buf_fx[ch][index_slot * hSpatParamRendCom->num_freq_bands]; Word32 *RealBuffer_fx[MAX_PARAM_SPATIAL_SUBFRAMES]; Word32 *ImagBuffer_fx[MAX_PARAM_SPATIAL_SUBFRAMES]; FOR( i = 0; i < hSpatParamRendCom->subframe_nbslots[subframe_idx]; i++ ) @@ -5177,8 +5208,8 @@ void ivas_dirac_dec_render_sf_fx( move32(); } - scale_sig32( st_ivas->cldfbSynDec[ch]->cldfb_state_fx, st_ivas->cldfbSynDec[ch]->p_filter_length, sub( sub( Q6, 1 ), st_ivas->cldfbSynDec[ch]->Q_cldfb_state ) ); - st_ivas->cldfbSynDec[ch]->Q_cldfb_state = sub( Q6, 1 ); + scale_sig32( st_ivas->cldfbSynDec[ch]->cldfb_state_fx, st_ivas->cldfbSynDec[ch]->p_filter_length, sub( ( Q6 - 1 ), st_ivas->cldfbSynDec[ch]->Q_cldfb_state ) ); // Q6-1 + st_ivas->cldfbSynDec[ch]->Q_cldfb_state = ( Q6 - 1 ); move16(); cldfbSynthesis_ivas_fx( RealBuffer_fx, ImagBuffer_fx, synth_fx, i_mult( hSpatParamRendCom->num_freq_bands, hSpatParamRendCom->subframe_nbslots[subframe_idx] ), st_ivas->cldfbSynDec[ch] ); @@ -5191,14 +5222,17 @@ void ivas_dirac_dec_render_sf_fx( move16(); IF( GT_16( samplesToProcess, -1 ) ) { - no_col = s_min( no_col, ( add( samplesToProcess, sub( st_ivas->cldfbSynDec[ch]->no_channels, 1 ) ) ) / st_ivas->cldfbSynDec[ch]->no_channels ); + Word16 tmp, tmp_e; + tmp = BASOP_Util_Divide1616_Scale( add( samplesToProcess, sub( st_ivas->cldfbSynDec[ch]->no_channels, 1 ) ), st_ivas->cldfbSynDec[ch]->no_channels, &tmp_e ); + tmp = shr( tmp, 15 - tmp_e ); + no_col = s_min( no_col, tmp ); } Word16 synth_len = imult1616( no_col, no_channels ); - scale_sig32( synth_fx, synth_len, sub( Q11, sub( Q6, 1 ) ) ); + scale_sig32( synth_fx, synth_len, ( Q11 - ( Q6 - 1 ) ) ); // Q11 } } - ELSE IF( L_or( EQ_16( st_ivas->ivas_format, SBA_FORMAT ), EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) ) + ELSE IF( ( EQ_16( st_ivas->ivas_format, SBA_FORMAT ) || EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) ) { FOR( ch = 0; ch < hDirACRend->hOutSetup.nchan_out_woLFE; ch++ ) { @@ -5252,9 +5286,10 @@ void ivas_dirac_dec_render_sf_fx( Copy32( &( output_buf_fx[LFE_CHANNEL][subframe_start_sample] ), tmp_lfe_fx, num_samples_subframe ); FOR( ch = 0; ch < outchannels; ch++ ) { + test(); test(); - IF( L_and( hDirACRend->hOutSetup.num_lfe > 0, ( EQ_16( hDirACRend->hOutSetup.index_lfe[idx_lfe], ch ) ) ) ) + IF( ( hDirACRend->hOutSetup.num_lfe > 0 && ( EQ_16( hDirACRend->hOutSetup.index_lfe[idx_lfe], ch ) ) ) ) { /* Move the LFE channel to the correct place */ Copy32( tmp_lfe_fx, &( output_buf_fx[ch][subframe_start_sample] ), num_samples_subframe ); @@ -5297,9 +5332,10 @@ void ivas_dirac_dec_render_sf_fx( { FOR( ch = 0; ch < outchannels; ch++ ) { + test(); test(); - IF( L_and( hDirACRend->hOutSetup.num_lfe > 0, ( EQ_16( hDirACRend->hOutSetup.index_lfe[idx_lfe], ch ) ) ) ) + IF( ( hDirACRend->hOutSetup.num_lfe > 0 && ( EQ_16( hDirACRend->hOutSetup.index_lfe[idx_lfe], ch ) ) ) ) { test(); test(); @@ -5307,18 +5343,18 @@ void ivas_dirac_dec_render_sf_fx( { FOR( i = 0; i < hSpatParamRendCom->subframe_nbslots[subframe_idx]; i++ ) { - RealBuffer_fx[i] = Cldfb_RealBuffer_fx[sub( MAX_OUTPUT_CHANNELS, 1 )][i]; + RealBuffer_fx[i] = Cldfb_RealBuffer_fx[MAX_OUTPUT_CHANNELS - 1][i]; move32(); - ImagBuffer_fx[i] = Cldfb_ImagBuffer_fx[sub( MAX_OUTPUT_CHANNELS, 1 )][i]; + ImagBuffer_fx[i] = Cldfb_ImagBuffer_fx[MAX_OUTPUT_CHANNELS - 1][i]; move32(); } Word16 cldfbSynIdx = add( hDirACRend->hOutSetup.nchan_out_woLFE, idx_lfe ); Word16 samplesToProcess = i_mult( hSpatParamRendCom->num_freq_bands, hSpatParamRendCom->subframe_nbslots[subframe_idx] ); - Word32 *p_out = &( output_buf_fx[ch][i_mult( index_slot, hSpatParamRendCom->num_freq_bands )] ); - - scale_sig32( st_ivas->cldfbSynDec[cldfbSynIdx]->cldfb_state_fx, st_ivas->cldfbSynDec[cldfbSynIdx]->p_filter_length, sub( sub( Q6, 1 ), st_ivas->cldfbSynDec[cldfbSynIdx]->Q_cldfb_state ) ); - st_ivas->cldfbSynDec[cldfbSynIdx]->Q_cldfb_state = sub( Q6, 1 ); + Word32 *p_out = &( output_buf_fx[ch][index_slot * hSpatParamRendCom->num_freq_bands] ); + scale_sig32( st_ivas->cldfbSynDec[cldfbSynIdx]->cldfb_state_fx, st_ivas->cldfbSynDec[cldfbSynIdx]->p_filter_length, sub( ( Q6 - 1 ), st_ivas->cldfbSynDec[cldfbSynIdx]->Q_cldfb_state ) ); // Q6-1 + st_ivas->cldfbSynDec[cldfbSynIdx]->Q_cldfb_state = ( Q6 - 1 ); + move16(); cldfbSynthesis_ivas_fx( RealBuffer_fx, ImagBuffer_fx, p_out, samplesToProcess, st_ivas->cldfbSynDec[cldfbSynIdx] ); // Calculating length of output @@ -5328,11 +5364,14 @@ void ivas_dirac_dec_render_sf_fx( move16(); IF( GT_16( samplesToProcess, -1 ) ) { - no_col = s_min( no_col, ( add( samplesToProcess, sub( st_ivas->cldfbSynDec[cldfbSynIdx]->no_channels, 1 ) ) ) / st_ivas->cldfbSynDec[cldfbSynIdx]->no_channels ); + Word16 tmp, tmp_e; + tmp = BASOP_Util_Divide1616_Scale( add( samplesToProcess, sub( st_ivas->cldfbSynDec[cldfbSynIdx]->no_channels, 1 ) ), st_ivas->cldfbSynDec[cldfbSynIdx]->no_channels, &tmp_e ); + tmp = shr( tmp, 15 - tmp_e ); + no_col = s_min( no_col, tmp ); } Word16 synth_len = imult1616( no_col, no_channels ); - scale_sig32( p_out, synth_len, sub( Q11, sub( Q6, 1 ) ) ); + scale_sig32( p_out, synth_len, ( Q11 - ( Q6 - 1 ) ) ); // Q11 } ELSE IF( EQ_16( st_ivas->mc_mode, MC_MODE_MCMASA ) && hDirACRend->hOutSetup.separateChannelEnabled ) { @@ -5340,7 +5379,7 @@ void ivas_dirac_dec_render_sf_fx( } ELSE { - set32_fx( &( output_buf_fx[ch][i_mult( index_slot, hSpatParamRendCom->num_freq_bands )] ), 0, imult1616( hSpatParamRendCom->subframe_nbslots[subframe_idx], hSpatParamRendCom->num_freq_bands ) ); + set32_fx( &( output_buf_fx[ch][index_slot * hSpatParamRendCom->num_freq_bands] ), 0, imult1616( hSpatParamRendCom->subframe_nbslots[subframe_idx], hSpatParamRendCom->num_freq_bands ) ); } IF( LT_16( idx_lfe, sub( hDirACRend->hOutSetup.num_lfe, 1 ) ) ) { @@ -5373,13 +5412,16 @@ void ivas_dirac_dec_render_sf_fx( move16(); IF( GT_16( samplesToProcess, -1 ) ) { - no_col = s_min( no_col, ( add( samplesToProcess, sub( st_ivas->cldfbSynDec[idx_in]->no_channels, 1 ) ) ) / st_ivas->cldfbSynDec[idx_in]->no_channels ); + Word16 tmp, tmp_e; + tmp = BASOP_Util_Divide1616_Scale( add( samplesToProcess, sub( st_ivas->cldfbSynDec[idx_in]->no_channels, 1 ) ), st_ivas->cldfbSynDec[idx_in]->no_channels, &tmp_e ); + tmp = shr( tmp, 15 - tmp_e ); + no_col = s_min( no_col, tmp ); } out_len = imult1616( no_col, no_channels ); // Scaling cldfb_state to Q6-1 - scale_sig32( st_ivas->cldfbSynDec[idx_in]->cldfb_state_fx, st_ivas->cldfbSynDec[idx_in]->p_filter_length, sub( sub( Q6, 1 ), st_ivas->cldfbSynDec[idx_in]->Q_cldfb_state ) ); - st_ivas->cldfbSynDec[idx_in]->Q_cldfb_state = sub( Q6, 1 ); + scale_sig32( st_ivas->cldfbSynDec[idx_in]->cldfb_state_fx, st_ivas->cldfbSynDec[idx_in]->p_filter_length, sub( ( Q6 - 1 ), st_ivas->cldfbSynDec[idx_in]->Q_cldfb_state ) ); + st_ivas->cldfbSynDec[idx_in]->Q_cldfb_state = ( Q6 - 1 ); move16(); cldfbSynthesis_ivas_fx( RealBuffer_fx, ImagBuffer_fx, p_out, samplesToProcess, st_ivas->cldfbSynDec[idx_in] ); @@ -5394,7 +5436,9 @@ void ivas_dirac_dec_render_sf_fx( } hSpatParamRendCom->slots_rendered = add( hSpatParamRendCom->slots_rendered, hSpatParamRendCom->subframe_nbslots[subframe_idx] ); + move16(); hSpatParamRendCom->subframes_rendered = add( hSpatParamRendCom->subframes_rendered, 1 ); + move16(); IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) @@ -5411,7 +5455,7 @@ void ivas_dirac_dec_render_sf_fx( { FOR( i = 0; i < st_ivas->hDecoderConfig->nchan_out; i++ ) { - scale_sig32( st_ivas->cldfbSynDec[i]->cldfb_state_fx, st_ivas->cldfbSynDec[i]->cldfb_size, sub( Q11, st_ivas->cldfbSynDec[i]->Q_cldfb_state ) ); + scale_sig32( st_ivas->cldfbSynDec[i]->cldfb_state_fx, st_ivas->cldfbSynDec[i]->cldfb_size, sub( Q11, st_ivas->cldfbSynDec[i]->Q_cldfb_state ) ); // Q11 st_ivas->cldfbSynDec[i]->Q_cldfb_state = Q11; move16(); } @@ -5451,7 +5495,7 @@ void ivas_dirac_dec_render_sf_fx( FOR( ch = 0; ch < outchannels; ch++ ) { test(); - IF( L_and( hDirACRend->hOutSetup.num_lfe > 0, ( EQ_16( hDirACRend->hOutSetup.index_lfe[idx_lfe], ch ) ) ) ) + IF( ( hDirACRend->hOutSetup.num_lfe > 0 && ( EQ_16( hDirACRend->hOutSetup.index_lfe[idx_lfe], ch ) ) ) ) { IF( LT_16( idx_lfe, sub( hDirACRend->hOutSetup.num_lfe, 1 ) ) ) { @@ -5464,22 +5508,23 @@ void ivas_dirac_dec_render_sf_fx( { FOR( ch = 0; ch < outchannels; ch++ ) { + test(); test(); - IF( L_and( hDirACRend->hOutSetup.num_lfe > 0, ( EQ_16( hDirACRend->hOutSetup.index_lfe[idx_lfe], ch ) ) ) ) + IF( ( hDirACRend->hOutSetup.num_lfe > 0 && ( EQ_16( hDirACRend->hOutSetup.index_lfe[idx_lfe], ch ) ) ) ) { test(); IF( EQ_16( st_ivas->mc_mode, MC_MODE_MCMASA ) && !hDirACRend->hOutSetup.separateChannelEnabled ) { Word16 cldfbSynIdx = add( hDirACRend->hOutSetup.nchan_out_woLFE, idx_lfe ); - scale_sig32( st_ivas->cldfbSynDec[cldfbSynIdx]->cldfb_state_fx, st_ivas->cldfbSynDec[cldfbSynIdx]->cldfb_size, sub( Q11, st_ivas->cldfbSynDec[cldfbSynIdx]->Q_cldfb_state ) ); + scale_sig32( st_ivas->cldfbSynDec[cldfbSynIdx]->cldfb_state_fx, st_ivas->cldfbSynDec[cldfbSynIdx]->cldfb_size, sub( Q11, st_ivas->cldfbSynDec[cldfbSynIdx]->Q_cldfb_state ) ); // Q11 st_ivas->cldfbSynDec[cldfbSynIdx]->Q_cldfb_state = Q11; move16(); } } ELSE IF( ( hDirACRend->hOutSetup.separateChannelEnabled == 0 ) || NE_16( hDirACRend->hOutSetup.separateChannelIndex, ch ) ) { - scale_sig32( st_ivas->cldfbSynDec[idx_in]->cldfb_state_fx, st_ivas->cldfbSynDec[idx_in]->cldfb_size, sub( Q11, st_ivas->cldfbSynDec[idx_in]->Q_cldfb_state ) ); + scale_sig32( st_ivas->cldfbSynDec[idx_in]->cldfb_state_fx, st_ivas->cldfbSynDec[idx_in]->cldfb_size, sub( Q11, st_ivas->cldfbSynDec[idx_in]->Q_cldfb_state ) ); // Q11 st_ivas->cldfbSynDec[idx_in]->Q_cldfb_state = Q11; move16(); idx_in = add( idx_in, 1 ); diff --git a/lib_dec/ivas_dirac_output_synthesis_cov.c b/lib_dec/ivas_dirac_output_synthesis_cov.c index 4af727672..4bcfdc3e6 100644 --- a/lib_dec/ivas_dirac_output_synthesis_cov.c +++ b/lib_dec/ivas_dirac_output_synthesis_cov.c @@ -70,7 +70,7 @@ ivas_error ivas_dirac_dec_output_synthesis_cov_open_fx( const Word16 num_param_bands_residual, /* i : number of parameter bands with a residual mixing matrix (i.e. decorrelation */ const Word16 nchan_in, /* i : number of input (transport) channels */ const Word16 nchan_out, /* i : number of output channels */ - const Word32 *proto_matrix /* i : the prototype (upmix) matrix (only used if mode == 1) */ + const Word32 *proto_matrix /* i : the prototype (upmix) matrix (only used if mode == 1) Q(15-proto_matrix_e) */ ) { Word16 idx; @@ -89,7 +89,7 @@ ivas_error ivas_dirac_dec_output_synthesis_cov_open_fx( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis covariance\n" ) ); } h_dirac_output_synthesis_params->proto_matrix_len = imult1616( nchan_out, nchan_in ); - + move16(); /* cov buffers */ FOR( idx = 0; idx < num_param_bands; idx++ ) { @@ -116,6 +116,7 @@ ivas_error ivas_dirac_dec_output_synthesis_cov_open_fx( } set_zero_fx( h_dirac_output_synthesis_state->mixing_matrix_fx[idx], imult1616( nchan_out, nchan_in ) ); h_dirac_output_synthesis_state->mixing_matrix_len = i_mult( nchan_out, nchan_in ); + move16(); } FOR( ; idx < CLDFB_NO_CHANNELS_MAX; idx++ ) { @@ -139,6 +140,7 @@ ivas_error ivas_dirac_dec_output_synthesis_cov_open_fx( } set_zero_fx( h_dirac_output_synthesis_state->mixing_matrix_res_fx[idx], imult1616( nchan_out, nchan_out ) ); h_dirac_output_synthesis_state->mixing_matrix_res_len = i_mult( nchan_out, nchan_out ); + move16(); } FOR( ; idx < CLDFB_NO_CHANNELS_MAX; idx++ ) { @@ -194,6 +196,7 @@ ivas_error ivas_dirac_dec_output_synthesis_cov_open_fx( FOR( idx = 1; idx <= interp_length; ++idx ) { h_dirac_output_synthesis_params->interpolator_fx[idx - 1] = div_s( idx, interp_length ); + move16(); } Copy32( proto_matrix, h_dirac_output_synthesis_params->proto_matrix_fx, imult1616( nchan_in, nchan_out ) ); h_dirac_output_synthesis_params->proto_matrix_e = 5; @@ -734,13 +737,13 @@ void ivas_dirac_dec_output_synthesis_cov_param_mc_collect_slot( *-------------------------------------------------------------------*/ #ifdef FIX_835_PARAMMC_BUFFER_VALUES void ivas_dirac_dec_output_synthesis_cov_param_mc_collect_slot_fx( - Word32 *RealBuffer_fx, /* i : input channel filter bank samples (real part) */ + Word32 *RealBuffer_fx, /* i : input channel filter bank samples (real part) Q(31- RealBuffer_e)*/ Word16 RealBuffer_e, /* i : exponent input channel filter bank samples (real part)*/ - Word32 *ImagBuffer_fx, /* i : input channel filter bank samples (imaginary part */ + Word32 *ImagBuffer_fx, /* i : input channel filter bank samples (imaginary part Q(ImagBuffer_e)*/ Word16 ImagBuffer_e, /* i : exponent input channel filter bank samples (real part)*/ - Word32 cx_fx[PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS], /* o : accumulated input covariance (real part) */ + Word32 cx_fx[PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS], /* o : accumulated input covariance (real part) Q(31- cx_e)*/ Word16 *cx_e, /* i : exponent for accumulated input covariance (real part) */ - Word32 cx_imag_fx[PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS], /* o : accumulated input covariance (imaginary part) */ + Word32 cx_imag_fx[PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS], /* o : accumulated input covariance (imaginary part) Q(31- cx_imag_e)*/ Word16 *cx_imag_e, /* i : exponent accumulated input covariance (imag part) */ PARAM_MC_DEC_HANDLE hParamMC, /* i : handle to Parametric MC state */ const Word16 param_band, /* i : parameter band */ @@ -777,9 +780,9 @@ void ivas_dirac_dec_output_synthesis_cov_param_mc_collect_slot_fx( band = add( brange[0], band_idx ); FOR( ch_idx = 0; ch_idx < nchan_in; ch_idx++ ) { - real_in_buffer_fx[add( band_idx, imult1616( num_bands, ch_idx ) )] = RealBuffer_fx[add( imult1616( ch_idx, hParamMC->num_freq_bands ), band )]; + real_in_buffer_fx[band_idx + num_bands * ch_idx] = RealBuffer_fx[band + hParamMC->num_freq_bands * ch_idx]; move32(); - imag_in_buffer_fx[add( band_idx, imult1616( num_bands, ch_idx ) )] = ImagBuffer_fx[add( imult1616( ch_idx, hParamMC->num_freq_bands ), band )]; + imag_in_buffer_fx[band_idx + num_bands * ch_idx] = ImagBuffer_fx[band + hParamMC->num_freq_bands * ch_idx]; move32(); } } @@ -788,8 +791,8 @@ void ivas_dirac_dec_output_synthesis_cov_param_mc_collect_slot_fx( move16(); imag_in_e = ImagBuffer_e; move16(); - shift_real = sub( L_norm_arr( real_in_buffer_fx, imult1616( num_bands, nchan_in ) ), find_guarded_bits_fx( num_bands + 1 ) ); - shift_imag = sub( L_norm_arr( imag_in_buffer_fx, imult1616( num_bands, nchan_in ) ), find_guarded_bits_fx( num_bands + 1 ) ); + shift_real = sub( L_norm_arr( real_in_buffer_fx, imult1616( num_bands, nchan_in ) ), find_guarded_bits_fx( add( num_bands, 1 ) ) ); + shift_imag = sub( L_norm_arr( imag_in_buffer_fx, imult1616( num_bands, nchan_in ) ), find_guarded_bits_fx( add( num_bands, 1 ) ) ); real_in_e = sub( real_in_e, shift_real ); imag_in_e = sub( imag_in_e, shift_imag ); @@ -799,9 +802,9 @@ void ivas_dirac_dec_output_synthesis_cov_param_mc_collect_slot_fx( FOR( i = 0; i < num_bands * nchan_in; ++i ) { - real_in_buffer_fx[i] = L_shr( real_in_buffer_fx[i], sub( output_e, RealBuffer_e ) ); + real_in_buffer_fx[i] = L_shr( real_in_buffer_fx[i], sub( output_e, RealBuffer_e ) ); // Q(31-output_e) move32(); - imag_in_buffer_fx[i] = L_shr( imag_in_buffer_fx[i], sub( output_e, ImagBuffer_e ) ); + imag_in_buffer_fx[i] = L_shr( imag_in_buffer_fx[i], sub( output_e, ImagBuffer_e ) ); // Q(31-output_e) move32(); } @@ -831,10 +834,10 @@ void ivas_dirac_dec_output_synthesis_cov_param_mc_collect_slot_fx( FOR( j = 0; j < PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS; j++ ) { L_tmp = BASOP_Util_Add_Mant32Exp( cx_fx[j], cx_init_e, 0, 0, &tmp1_e ); - cx_fx[j] = L_shr( L_tmp, sub( tmp1, tmp1_e ) ); + cx_fx[j] = L_shr( L_tmp, sub( tmp1, tmp1_e ) ); // Q(31-tmp1) move32(); L_tmp = BASOP_Util_Add_Mant32Exp( cx_imag_fx[j], cx_init_imag_e, 0, 0, &tmp2_e ); - cx_imag_fx[j] = L_shr( L_tmp, sub( tmp2, tmp2_e ) ); + cx_imag_fx[j] = L_shr( L_tmp, sub( tmp2, tmp2_e ) ); // Q(31-tmp2) move32(); } @@ -1095,13 +1098,13 @@ void ivas_dirac_dec_output_synthesis_cov_param_mc_synthesise_slot( } #else void ivas_dirac_dec_output_synthesis_cov_param_mc_synthesise_slot_fx( - Word32 *Cldfb_RealBuffer_in_fx, - Word32 *Cldfb_ImagBuffer_in_fx, - Word32 Cldfb_RealBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* o : output channel filter bank samples (real part) */ - Word32 Cldfb_ImagBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* o : output channel filter bank samples (imaginary part) */ - Word32 *mixing_matrix_fx[], /* i : parameter band wise mixing matrices (direct part) */ + Word32 *Cldfb_RealBuffer_in_fx, /*Q6*/ + Word32 *Cldfb_ImagBuffer_in_fx, /*Q6*/ + Word32 Cldfb_RealBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* o : output channel filter bank samples (real part) Q6*/ + Word32 Cldfb_ImagBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* o : output channel filter bank samples (imaginary part) Q6*/ + Word32 *mixing_matrix_fx[], /* i : parameter band wise mixing matrices (direct part) Q(31-mixing_matrix_e)*/ Word16 *mixing_matrix_e, /* i : parameter band wise mixing matrices (direct part) */ - Word32 *mixing_matrix_res_fx[], /* i : parameter band wise mixing matrices (residual part) */ + Word32 *mixing_matrix_res_fx[], /* i : parameter band wise mixing matrices (residual part) Q(31-mixing_matrix_res_e)*/ Word16 *mixing_matrix_res_e, /* i : parameter band wise mixing matrices (residual part) */ const UWord16 slot_idx_sfr, /* i : time slot index for the current slot within the current subframe */ const UWord16 slot_idx_tot, /* i : time slot index for the current slot within the frame */ @@ -1118,6 +1121,7 @@ void ivas_dirac_dec_output_synthesis_cov_param_mc_synthesise_slot_fx( Word16 mixing_matrix_smooth_e; Word32 mixing_matrix_res_smooth_fx[MAX_CICP_CHANNELS * MAX_CICP_CHANNELS]; Word16 mixing_matrix_res_smooth_e = 0; + move16(); Word32 mixing_matrix_buffer_fx[MAX_CICP_CHANNELS * MAX_CICP_CHANNELS]; Word16 mixing_matrix_buffer_e; Word32 input_f_real_fx[PARAM_MC_MAX_TRANSPORT_CHANS]; @@ -1145,7 +1149,7 @@ void ivas_dirac_dec_output_synthesis_cov_param_mc_synthesise_slot_fx( move16(); brange[0] = hParamMC->band_grouping[param_band_idx]; move16(); - brange[1] = hParamMC->band_grouping[add( param_band_idx, 1 )]; + brange[1] = hParamMC->band_grouping[( param_band_idx + 1 )]; move16(); if ( LT_16( brange[0], hParamMC->h_output_synthesis_params.max_band_decorr ) ) @@ -1191,7 +1195,7 @@ void ivas_dirac_dec_output_synthesis_cov_param_mc_synthesise_slot_fx( assert( LT_16( band, hParamMC->h_output_synthesis_params.max_band_decorr ) ); FOR( ch_idx = 0; ch_idx < nY; ch_idx++ ) { - diff_f_real_fx[ch_idx] = Cldfb_RealBuffer_fx[ch_idx][slot_idx_sfr][band]; // Q6 + diff_f_real_fx[ch_idx] = Cldfb_RealBuffer_fx[ch_idx][slot_idx_sfr][band]; move32(); diff_f_imag_fx[ch_idx] = Cldfb_ImagBuffer_fx[ch_idx][slot_idx_sfr][band]; move32(); @@ -1200,17 +1204,17 @@ void ivas_dirac_dec_output_synthesis_cov_param_mc_synthesise_slot_fx( /* apply residual mixing */ matrix_product_mant_exp_fx( mixing_matrix_res_smooth_fx, mixing_matrix_res_smooth_e, nY, nY, 0, diff_f_real_fx, 25, nY, 1, 0, output_f_real_fx, &output_f_real_e ); - scale_sig32( output_f_real_fx, nY, sub( Q6, sub( Q31, output_f_real_e ) ) ); + scale_sig32( output_f_real_fx, nY, sub( Q6, sub( Q31, output_f_real_e ) ) ); // Q6 matrix_product_mant_exp_fx( mixing_matrix_res_smooth_fx, mixing_matrix_res_smooth_e, nY, nY, 0, diff_f_imag_fx, 25, nY, 1, 0, output_f_imag_fx, &output_f_imag_e ); - scale_sig32( output_f_imag_fx, nY, sub( Q6, sub( Q31, output_f_imag_e ) ) ); + scale_sig32( output_f_imag_fx, nY, sub( Q6, sub( Q31, output_f_imag_e ) ) ); // Q6 FOR( ch_idx = 0; ch_idx < nY; ch_idx++ ) { Cldfb_RealBuffer_fx[ch_idx][slot_idx_sfr][band] = output_f_real_fx[ch_idx]; // Q6 move32(); - Cldfb_ImagBuffer_fx[ch_idx][slot_idx_sfr][band] = output_f_imag_fx[ch_idx]; + Cldfb_ImagBuffer_fx[ch_idx][slot_idx_sfr][band] = output_f_imag_fx[ch_idx]; // Q6 move32(); } } @@ -1229,20 +1233,20 @@ void ivas_dirac_dec_output_synthesis_cov_param_mc_synthesise_slot_fx( FOR( ch_idx = 0; ch_idx < nX; ch_idx++ ) { - input_f_real_fx[ch_idx] = Cldfb_RealBuffer_in_fx[add( imult1616( ch_idx, hParamMC->num_freq_bands ), band )]; // Q6 + input_f_real_fx[ch_idx] = Cldfb_RealBuffer_in_fx[ch_idx * hParamMC->num_freq_bands + band]; // Q6 move32(); - input_f_imag_fx[ch_idx] = Cldfb_ImagBuffer_in_fx[add( imult1616( ch_idx, hParamMC->num_freq_bands ), band )]; + input_f_imag_fx[ch_idx] = Cldfb_ImagBuffer_in_fx[ch_idx * hParamMC->num_freq_bands + band]; // Q6 move32(); } /* apply mixing matrix */ matrix_product_mant_exp_fx( mixing_matrix_smooth_fx, mixing_matrix_smooth_e, nY, nX, 0, input_f_real_fx, 25, nX, 1, 0, output_f_real_fx, &output_f_real_e ); - scale_sig32( output_f_real_fx, MAX_CICP_CHANNELS, sub( 6, sub( 31, output_f_real_e ) ) ); + scale_sig32( output_f_real_fx, MAX_CICP_CHANNELS, sub( 6, sub( 31, output_f_real_e ) ) ); // Q6 matrix_product_mant_exp_fx( mixing_matrix_smooth_fx, mixing_matrix_smooth_e, nY, nX, 0, input_f_imag_fx, 25, nX, 1, 0, output_f_imag_fx, &output_f_imag_e ); - scale_sig32( output_f_imag_fx, MAX_CICP_CHANNELS, sub( 6, sub( 31, output_f_imag_e ) ) ); + scale_sig32( output_f_imag_fx, MAX_CICP_CHANNELS, sub( 6, sub( 31, output_f_imag_e ) ) ); // Q6 /* collect output */ FOR( ch_idx = 0; ch_idx < nY; ch_idx++ ) @@ -1529,20 +1533,20 @@ int16_t computeMixingMatrices( Word16 computeMixingMatrices_fx( const Word16 num_inputs, /* i : number of input channels */ const Word16 num_outputs, /* i : number of output channels */ - const Word32 *Cx, /* i : input channel covariance matrix */ + const Word32 *Cx, /* i : input channel covariance matrix Q(31-Cx_e) */ Word16 Cx_e, - const Word32 *Cy, /* i : target covariance matrix */ + const Word32 *Cy, /* i : target covariance matrix Q(31-Cy_e) */ Word16 Cy_e, - const Word32 *Q, /* i : prototype matrix (usually a upmix matrix) */ + const Word32 *Q, /* i : prototype matrix (usually a upmix matrix) Q_fx_e */ Word16 Q_fx_e, const Word16 energy_compensation_flag, /* i : flag indicating that the energy compensation should be performed (i.e. no residual mixing matrix will follow) */ const Word32 reg_Sx_fx, /* i : regularization factor for the input channel singular values */ Word16 reg_Sx_e, - const Word32 reg_ghat_fx, /* i : regularization factor for the normalization matrix */ + const Word32 reg_ghat_fx, /* i : regularization factor for the normalization matrix Q(31-reg_ghat_e) */ Word16 reg_ghat_e, - Word32 *mixing_matrix_fx, /* o : resulting mixing matrix */ + Word32 *mixing_matrix_fx, /* o : resulting mixing matrix Q(31-mixing_matrix_out_e) */ Word16 *mixing_matrix_out_e, - Word32 *Cr_fx, /* o : residual covariance matrix */ + Word32 *Cr_fx, /* o : residual covariance matrix Q(31-Cr_e) */ Word16 *Cr_e ) { Word16 i, j; @@ -1650,9 +1654,9 @@ Word16 computeMixingMatrices_fx( tmp_e = svd_s_buffer_e[j]; move16(); L_tmp = Sqrt32( svd_s_buffer_fx[j], &tmp_e ); - Ky_fx[add( i, imult1616( j, lengthCy ) )] = Mpy_32_32( svd_u_buffer_fx[i][j], L_tmp ); + Ky_fx[i + ( j * lengthCy )] = Mpy_32_32( svd_u_buffer_fx[i][j], L_tmp ); // Q(31-tmp_e) move32(); - Ky_fx_e[add( i, imult1616( j, lengthCy ) )] = tmp_e; + Ky_fx_e[i + ( j * lengthCy )] = tmp_e; move16(); } } @@ -1674,9 +1678,9 @@ Word16 computeMixingMatrices_fx( tmp_e = svd_s_buffer_e[j]; move16(); L_tmp = Sqrt32( svd_s_buffer_fx[j], &tmp_e ); - Kx_fx[add( i, imult1616( j, lengthCx ) )] = Mpy_32_32( svd_u_buffer_fx[i][j], L_tmp ); + Kx_fx[( i + ( j * lengthCx ) )] = Mpy_32_32( svd_u_buffer_fx[i][j], L_tmp ); // Q(31-tmp_e) move32(); - Kx_fx_e[add( i, imult1616( j, lengthCx ) )] = tmp_e; + Kx_fx_e[( i + ( j * lengthCx ) )] = tmp_e; move16(); } } @@ -1686,7 +1690,7 @@ Word16 computeMixingMatrices_fx( { tmp_e = svd_s_buffer_e[i]; move16(); - svd_s_buffer_fx[i] = Sqrt32( svd_s_buffer_fx[i], &tmp_e ); + svd_s_buffer_fx[i] = Sqrt32( svd_s_buffer_fx[i], &tmp_e ); // Q(31-tmp_e) move32(); svd_s_buffer_e[i] = tmp_e; move16(); @@ -1744,9 +1748,9 @@ Word16 computeMixingMatrices_fx( scale = add( scale, sub( Q31, svd_s_buffer_e[i] ) ); FOR( j = 0; j < lengthCx; ++j ) { - Kx_reg_inv_fx[add( i, imult1616( j, lengthCx ) )] = Mpy_32_16_1( svd_u_buffer_fx[j][i], reg_fac_fx ); + Kx_reg_inv_fx[i + j * lengthCx] = Mpy_32_16_1( svd_u_buffer_fx[j][i], reg_fac_fx ); // Q(31-scale) move32(); - Kx_reg_inv_e[add( i, imult1616( j, lengthCx ) )] = scale; + Kx_reg_inv_e[i + j * lengthCx] = scale; move16(); } } @@ -1780,7 +1784,7 @@ Word16 computeMixingMatrices_fx( #endif } #ifdef FIX_827_HIGH_MLD - L_tmp = Mpy_32_32( limit_fx, reg_ghat_fx ); + L_tmp = Mpy_32_32( limit_fx, reg_ghat_fx ); // limit_e+ reg_ghat_e limit_fx = L_add( L_tmp, EPSILON_FX ); limit_e = add( limit_e, reg_ghat_e ); #endif @@ -1798,7 +1802,7 @@ Word16 computeMixingMatrices_fx( move16(); } - tmp = BASOP_Util_Divide3232_Scale( Cy_fx[add( i, imult1616( i, lengthCy ) )], Cy_hat_diag_fx[i], &exp ); + tmp = BASOP_Util_Divide3232_Scale( Cy_fx[( i + ( i * lengthCy ) )], Cy_hat_diag_fx[i], &exp ); exp = add( exp, sub( Cy_fx_e, Cy_hat_diag_buff_e[i] ) ); L_tmp = Sqrt32( L_deposit_h( tmp ), &exp ); G_hat_fx[i] = L_tmp; @@ -1839,7 +1843,7 @@ Word16 computeMixingMatrices_fx( FOR( i = 0; i < lengthCy * lengthCx; i++ ) { - mat_mult_buffer1_fx[i] = L_shr( mat_mult_buffer1_fx[i], sub( exp, mat_mult_buffer1_fx_e[i] ) ); + mat_mult_buffer1_fx[i] = L_shr( mat_mult_buffer1_fx[i], sub( exp, mat_mult_buffer1_fx_e[i] ) ); // Q(31-exp) move32(); } @@ -1919,7 +1923,7 @@ Word16 computeMixingMatrices_fx( FOR( i = 0; i < lengthCy * lengthCx; i++ ) { - mixing_matrix_fx[i] = L_shr( mixing_matrix_fx[i], sub( exp, mixing_matrix_fx_e[i] ) ); + mixing_matrix_fx[i] = L_shr( mixing_matrix_fx[i], sub( exp, mixing_matrix_fx_e[i] ) ); // Q(31-exp) move32(); } @@ -1943,11 +1947,11 @@ Word16 computeMixingMatrices_fx( } /* Avoid Meaningless negative main diagonal elements */ - IF( BASOP_Util_Cmp_Mant32Exp( Cr_fx[add( i, imult1616( i, lengthCy ) )], exp, 0, 0 ) < 0 ) + IF( BASOP_Util_Cmp_Mant32Exp( Cr_fx[i + ( i * lengthCy )], exp, 0, 0 ) < 0 ) { - Cr_fx[add( i, imult1616( i, lengthCy ) )] = 0; + Cr_fx[i + ( i * lengthCy )] = 0; move32(); - Cr_e_arr[add( i, imult1616( i, lengthCy ) )] = 0; + Cr_e_arr[i + ( i * lengthCy )] = 0; move16(); } } @@ -1965,7 +1969,7 @@ Word16 computeMixingMatrices_fx( FOR( i = 0; i < lengthCy * lengthCy; i++ ) { - Cr_fx[i] = L_shr( Cr_fx[i], sub( exp, Cr_e_arr[i] ) ); + Cr_fx[i] = L_shr( Cr_fx[i], sub( exp, Cr_e_arr[i] ) ); // Q(31-exp) move32(); } @@ -1985,7 +1989,7 @@ Word16 computeMixingMatrices_fx( FOR( i = 0; i < lengthCy * lengthCy; i++ ) { - mat_mult_buffer2_fx[i] = L_shr( mat_mult_buffer2_fx[i], sub( exp, mat_mult_buffer2_fx_e[i] ) ); + mat_mult_buffer2_fx[i] = L_shr( mat_mult_buffer2_fx[i], sub( exp, mat_mult_buffer2_fx_e[i] ) ); // Q(31-exp) move32(); } @@ -2005,16 +2009,16 @@ Word16 computeMixingMatrices_fx( { /* Avoid correction for very small energies, main diagonal elements of Cy_tilde_p may be negative */ - IF( BASOP_Util_Cmp_Mant32Exp( Cy_tilde_p_fx[add( i, imult1616( i, lengthCy ) )], mat_mult_buffer2_e, 0, 0 ) < 0 ) + IF( BASOP_Util_Cmp_Mant32Exp( Cy_tilde_p_fx[i + ( i * lengthCy )], mat_mult_buffer2_e, 0, 0 ) < 0 ) { - adj_fx_p[i] = 1073741824; + adj_fx_p[i] = 1073741824; // 1.0f in Q30 move32(); adj_e[i] = 1; move16(); } ELSE { - tmp = BASOP_Util_Divide3232_Scale( Cy_fx[add( i, imult1616( i, lengthCy ) )], L_add( Cy_tilde_p_fx[add( i, imult1616( i, lengthCy ) )], EPSILON_FX ), &exp ); + tmp = BASOP_Util_Divide3232_Scale( Cy_fx[i + ( i * lengthCy )], L_add( Cy_tilde_p_fx[i + ( i * lengthCy )], EPSILON_FX ), &exp ); exp = add( exp, sub( Cy_fx_e, mat_mult_buffer2_e ) ); L_tmp = L_deposit_h( tmp ); L_tmp = Sqrt32( L_tmp, &exp ); @@ -2026,7 +2030,7 @@ Word16 computeMixingMatrices_fx( IF( BASOP_Util_Cmp_Mant32Exp( adj_fx_p[i], adj_e[i], 1073741824, 3 ) > 0 ) { - adj_fx_p[i] = 1073741824; + adj_fx_p[i] = 1073741824; // 1.0f in Q30 move32(); adj_e[i] = 3; move16(); @@ -2046,7 +2050,7 @@ Word16 computeMixingMatrices_fx( FOR( i = 0; i < lengthCy; i++ ) { - adj_fx[i] = L_shr( adj_fx_p[i], sub( exp, adj_e[i] ) ); + adj_fx[i] = L_shr( adj_fx_p[i], sub( exp, adj_e[i] ) ); // Q(31-exp) move32(); } adj_fx_e = exp; @@ -2054,7 +2058,7 @@ Word16 computeMixingMatrices_fx( diag_matrix_product_fx( adj_fx, adj_fx_e, lengthCy, mixing_matrix_fx, mixing_matrix_e, lengthCy, lengthCx, 0, mat_mult_buffer3_fx, &mat_mult_buffer3_e ); - Copy32( mat_mult_buffer3_fx, mixing_matrix_fx, imult1616( lengthCx, lengthCy ) ); + Copy32( mat_mult_buffer3_fx, mixing_matrix_fx, imult1616( lengthCx, lengthCy ) ); // Q(31-mat_mult_buffer3_e) mixing_matrix_e = mat_mult_buffer3_e; move16(); } @@ -2271,15 +2275,15 @@ int16_t computeMixingMatricesResidual( #else Word16 computeMixingMatricesResidual_fx( const Word32 num_outputs, /* i : number of output channels */ - const Word32 *Cx_fx, /* i : vector containing the diagonal diffuse prototype covariance */ + const Word32 *Cx_fx, /* i : vector containing the diagonal diffuse prototype covariance Q(31-Cx_e) */ const Word16 Cx_e, - const Word32 *Cy_fx, /* i : matrix containing the missing cov (Cr from computeMixingMatrices()) */ + const Word32 *Cy_fx, /* i : matrix containing the missing cov (Cr from computeMixingMatrices()) Q(31-Cy_fx_e) */ const Word16 Cy_fx_e, - const Word32 reg_Sx_fx, /* i : regularization factor for the input channel singular values */ + const Word32 reg_Sx_fx, /* i : regularization factor for the input channel singular values Q(31-reg_Sx_e) */ const Word16 reg_Sx_e, - const Word32 reg_ghat_fx, /* i : regularization factor for the normalization matrix */ + const Word32 reg_ghat_fx, /* i : regularization factor for the normalization matrix Q(31-reg_ghat_e) */ const Word16 reg_ghat_e, - Word32 *mixing_matrix_fx, /* o : resulting residual mixing matrix */ + Word32 *mixing_matrix_fx, /* o : resulting residual mixing matrix Q(31-mixing_matrix_ret_e) */ Word16 *mixing_matrix_ret_e ) { Word16 i, j; @@ -2359,7 +2363,7 @@ Word16 computeMixingMatricesResidual_fx( tmp_e = svd_s_buffer_e[j]; move16(); L_tmp = Sqrt32( svd_s_buffer_fx[j], &tmp_e ); - Ky_fx[i + j * lengthCy] = Mpy_32_32( svd_u_buffer_fx[i][j], L_tmp ); + Ky_fx[i + j * lengthCy] = Mpy_32_32( svd_u_buffer_fx[i][j], L_tmp ); // Q(31-tmp_e) move32(); Ky_fx_e[i + j * lengthCy] = tmp_e; move16(); @@ -2382,6 +2386,7 @@ Word16 computeMixingMatricesResidual_fx( exp = Cx_e; move16(); Kx_fx[i] = Sqrt32( Cx_fx[i], &exp ); + move32(); Kx_fx_e[i] = exp; move16(); } @@ -2405,7 +2410,7 @@ Word16 computeMixingMatricesResidual_fx( } } - L_tmp = Mpy_32_32( limit_fx, reg_Sx_fx ); + L_tmp = Mpy_32_32( limit_fx, reg_Sx_fx ); // limit_e + reg_Sx_e L_tmp = L_add( L_tmp, EPSILLON_FX ); limit_fx = L_tmp; move16(); @@ -2427,10 +2432,11 @@ Word16 computeMixingMatricesResidual_fx( exp = limit_e; move16(); } - tmp = BASOP_Util_Divide3232_Scale( 1073741824, div_tmp, &scale ); + tmp = BASOP_Util_Divide3232_Scale( 1073741824, div_tmp, &scale ); // 1073741824 -> 1.0f in Q30 scale = add( scale, sub( Q1, exp ) ); Kx_reg_inv_fx[i] = L_deposit_h( tmp ); + move32(); Kx_reg_inv_e[i] = scale; move16(); } @@ -2449,7 +2455,7 @@ Word16 computeMixingMatricesResidual_fx( *-----------------------------------------------------------------*/ /* Computing Cy_hat_diag */ - Copy32( Cx_fx, Cy_hat_diag_fx, extract_l( num_outputs ) ); + Copy32( Cx_fx, Cy_hat_diag_fx, extract_l( num_outputs ) ); // Q(31-Cx_e) Cy_hat_diag_e = Cx_e; move16(); @@ -2464,7 +2470,7 @@ Word16 computeMixingMatricesResidual_fx( } } - L_tmp = Mpy_32_32( limit_fx, reg_ghat_fx ); + L_tmp = Mpy_32_32( limit_fx, reg_ghat_fx ); // Q(limit_e+reg_ghat_e) limit_fx = L_add( L_tmp, EPSILON_FX ); limit_e = add( limit_e, reg_ghat_e ); @@ -2496,7 +2502,7 @@ Word16 computeMixingMatricesResidual_fx( FOR( i = 0; i < num_outputs; i++ ) { - L_tmp = Mpy_32_32( Kx_fx[i], G_hat_fx[i] ); + L_tmp = Mpy_32_32( Kx_fx[i], G_hat_fx[i] ); // Q(31-(Kx_fx_e+G_hag_e)) Kx_fx[i] = L_tmp; move32(); Kx_fx_e[i] = add( Kx_fx_e[i], G_hat_e[i] ); @@ -2511,10 +2517,11 @@ Word16 computeMixingMatricesResidual_fx( FOR( j = 0; j < num_outputs; j++ ) { - L_tmp = Mpy_32_32( Ky_fx[add( i, imult1616( j, extract_l( num_outputs ) ) )], fac_fx ); - mat_mult_buffer1_fx[add( i, imult1616( j, extract_l( num_outputs ) ) )] = L_tmp; + L_tmp = Mpy_32_32( Ky_fx[i + j * num_outputs], fac_fx ); // Q(31-(Ky_fx_e+Kx_fx_e)) + mat_mult_buffer1_fx[i + j * num_outputs] = L_tmp; move32(); - mat_mult_buffer1_buff_e[add( i, imult1616( j, extract_l( num_outputs ) ) )] = extract_l( L_add( Ky_fx_e[add( i, imult1616( j, extract_l( num_outputs ) ) )], Kx_fx_e[i] ) ); + mat_mult_buffer1_buff_e[i + j * num_outputs] = extract_l( L_add( Ky_fx_e[i + j * num_outputs], Kx_fx_e[i] ) ); + move16(); } } @@ -2531,7 +2538,7 @@ Word16 computeMixingMatricesResidual_fx( FOR( i = 0; i < num_outputs * num_outputs; i++ ) { - mat_mult_buffer1_fx[i] = L_shr( mat_mult_buffer1_fx[i], sub( mat_mult_buffer1_e, mat_mult_buffer1_buff_e[i] ) ); + mat_mult_buffer1_fx[i] = L_shr( mat_mult_buffer1_fx[i], sub( mat_mult_buffer1_e, mat_mult_buffer1_buff_e[i] ) ); // Q(31-mat_mult_buffer1_e) move32(); } @@ -2572,11 +2579,11 @@ Word16 computeMixingMatricesResidual_fx( FOR( j = 0; j < num_outputs; j++ ) { #ifdef FIX_827_HIGH_MLD - L_tmp = Mpy_32_32( mat_mult_buffer1_fx[add( j, imult1616( i, extract_l( num_outputs ) ) )], fac_fx ); - mixing_matrix_fx[add( j, imult1616( i, extract_l( num_outputs ) ) )] = L_tmp; + L_tmp = Mpy_32_32( mat_mult_buffer1_fx[j + i * num_outputs], fac_fx ); // Q(31-mat_mult_buffer1_e+Kx_reg_inv_e) + mixing_matrix_fx[j + i * num_outputs] = L_tmp; #else - L_tmp = Mpy_32_32( mat_mult_buffer1_fx[add( j, imult1616( j, extract_l( num_outputs ) ) )], fac_fx ); - mixing_matrix_fx[add( j, imult1616( j, extract_l( num_outputs ) ) )] = L_tmp; + L_tmp = Mpy_32_32( mat_mult_buffer1_fx[j + j * num_outputs], fac_fx ); // mat_mult_buffer1_e+Kx_reg_inv_e + mixing_matrix_fx[j + j * num_outputs] = L_tmp; #endif move32(); mixing_matrix_fx_e[j + i * num_outputs] = add( mat_mult_buffer1_buff_e[j + i * num_outputs], Kx_reg_inv_e[i] ); @@ -2608,7 +2615,7 @@ Word16 computeMixingMatricesResidual_fx( FOR( i = 0; i < num_outputs * num_outputs; i++ ) { - mixing_matrix_fx[i] = L_shr( mixing_matrix_fx[i], sub( exp, mixing_matrix_fx_e[i] ) ); + mixing_matrix_fx[i] = L_shr( mixing_matrix_fx[i], sub( exp, mixing_matrix_fx_e[i] ) ); // Q(31-exp) move32(); } mixing_matrix_e = exp; @@ -2627,7 +2634,7 @@ Word16 computeMixingMatricesResidual_fx( FOR( i = 0; i < num_outputs * num_outputs; i++ ) { - mat_mult_buffer1_fx[i] = L_shr( mat_mult_buffer1_fx[i], sub( exp, mat_mult_buffer1_buff_e[i] ) ); + mat_mult_buffer1_fx[i] = L_shr( mat_mult_buffer1_fx[i], sub( exp, mat_mult_buffer1_buff_e[i] ) ); // Q(31-exp) move32(); } mat_mult_buffer1_e = exp; @@ -2643,14 +2650,15 @@ Word16 computeMixingMatricesResidual_fx( FOR( i = 0; i < lengthCy; ++i ) { - tmp = BASOP_Util_Divide3232_Scale( Cy_fx[add( i, imult1616( lengthCy, i ) )], L_add( Cy_tilde_fx[i], EPSILON_FX ), &scale ); + tmp = BASOP_Util_Divide3232_Scale( Cy_fx[i + ( lengthCy * i )], L_add( Cy_tilde_fx[i], EPSILON_FX ), &scale ); scale = add( scale, sub( Cy_fx_e, Cy_tilde_e ) ); adj_fx_p[i] = Sqrt32( L_deposit_h( tmp ), &scale ); + move32(); adj_buff_e[i] = scale; move16(); - IF( BASOP_Util_Cmp_Mant32Exp( adj_fx_p[i], scale, 1073741824, 3 ) > 0 ) + IF( BASOP_Util_Cmp_Mant32Exp( adj_fx_p[i], scale, 1073741824, 3 ) > 0 ) // 1073741824 -> 1.0f in Q30 { - adj_fx_p[i] = 1073741824; + adj_fx_p[i] = 1073741824; // 1.0f in Q30 move32(); adj_buff_e[i] = 3; move16(); @@ -2672,7 +2680,7 @@ Word16 computeMixingMatricesResidual_fx( FOR( i = 0; i < lengthCy; i++ ) { - adj_fx[i] = L_shr( adj_fx_p[i], sub( adj_e, adj_buff_e[i] ) ); + adj_fx[i] = L_shr( adj_fx_p[i], sub( adj_e, adj_buff_e[i] ) ); // Q(31-adj_e) move32(); } @@ -2698,19 +2706,19 @@ Word16 computeMixingMatricesISM_fx( const Word16 num_inputs, const Word16 num_responses, const Word16 num_outputs, - const Word32 *responses_fx, + const Word32 *responses_fx, /*Q(31-responses_e) */ const Word16 responses_e, - const Word32 *ener_fx, + const Word32 *ener_fx, /*Q(31-ener_e) */ const Word16 ener_e, - const Word32 *Cx_diag_fx, + const Word32 *Cx_diag_fx, /*Q(31-diag_e) */ const Word16 Cx_diag_e, - const Word32 *Cy_diag_fx, + const Word32 *Cy_diag_fx, /*Q(31-diag_e) */ const Word16 Cy_diag_e, const Word16 *Q_16fx, // Q15 const Word16 energy_compensation_flag, - const Word32 reg_Sx_fx, - const Word32 reg_ghat_fx, - Word32 *mixing_matrix_fx, + const Word32 reg_Sx_fx, /*Q0*/ + const Word32 reg_ghat_fx, /*Q0*/ + Word32 *mixing_matrix_fx, /*Q(31-mixing_matrix_e) */ Word16 *mixing_matrix_e ) { Word16 i, out; @@ -2743,7 +2751,7 @@ Word16 computeMixingMatricesISM_fx( push_wmops( "dirac_cov_mix_mat" ); out = EXIT_SUCCESS; - move32(); + move16(); lengthCx = num_inputs; move16(); lengthCy = num_outputs; @@ -2787,13 +2795,13 @@ Word16 computeMixingMatricesISM_fx( } FOR( i = 0; i < lengthCx; i++ ) { - Kx_fx[i] = L_shr_r( Kx_fx[i], sub( Kx_e, temp_e[i] ) ); + Kx_fx[i] = L_shr_r( Kx_fx[i], sub( Kx_e, temp_e[i] ) ); // Q(31-Kx_e) move32(); } /* Regularization of Sx */ maximum_32_fx( Kx_fx, lengthCx, &limit_fx ); - limit_fx = Mpy_32_32( limit_fx, reg_Sx_fx ); + limit_fx = Mpy_32_32( limit_fx, reg_Sx_fx ); // Cy_hat_diag_e + reg_ghat_e FOR( i = 0; i < lengthCx; ++i ) { @@ -2845,7 +2853,7 @@ Word16 computeMixingMatricesISM_fx( } FOR( i = 0; i < lengthCx; i++ ) { - Kx_reg_inv_fx[i] = L_shr_r( Kx_reg_inv_fx[i], sub( Kx_reg_inv_e, temp_e[i] ) ); + Kx_reg_inv_fx[i] = L_shr_r( Kx_reg_inv_fx[i], sub( Kx_reg_inv_e, temp_e[i] ) ); // Q(31- Kx_reg_inv_e) move32(); } @@ -2893,7 +2901,7 @@ Word16 computeMixingMatricesISM_fx( } } - limit_fx = Mpy_32_32( limit_fx, reg_ghat_fx ); + limit_fx = Mpy_32_32( limit_fx, reg_ghat_fx ); // Cy_hat_diag_e + reg_ghat_e /* Computing G_hat */ FOR( i = 0; i < lengthCy; ++i ) @@ -2940,7 +2948,7 @@ Word16 computeMixingMatricesISM_fx( } FOR( i = 0; i < lengthCy; i++ ) { - G_hat_fx[i] = L_shr_r( G_hat_fx[i], sub( G_hat_e, temp_e[i] ) ); + G_hat_fx[i] = L_shr_r( G_hat_fx[i], sub( G_hat_e, temp_e[i] ) ); // Q(31-G_hat_e) move32(); } @@ -3006,7 +3014,7 @@ Word16 computeMixingMatricesISM_fx( FOR( i = 0; i < lengthCy; ++i ) { /* Avoid correction for very small energies, main diagonal elements of Cy_tilde_p may be negative */ - IF( Cy_tilde_p_fx[add( i, imult1616( i, lengthCy ) )] < 0 ) + IF( Cy_tilde_p_fx[( i + ( i * lengthCy ) )] < 0 ) { adj_fx[i] = MAX_32; move32(); @@ -3017,9 +3025,9 @@ Word16 computeMixingMatricesISM_fx( { IF( Cy_diag_fx[i] ) { - IF( Cy_tilde_p_fx[add( i, imult1616( i, lengthCy ) )] ) + IF( Cy_tilde_p_fx[i + ( i * lengthCy )] ) { - adj_fx[i] = BASOP_Util_Divide3232_Scale_cadence( Cy_diag_fx[i], Cy_tilde_p_fx[add( i, imult1616( i, lengthCy ) )], &temp_e[i] ); + adj_fx[i] = BASOP_Util_Divide3232_Scale_cadence( Cy_diag_fx[i], Cy_tilde_p_fx[i + ( i * lengthCy )], &temp_e[i] ); move32(); temp_e[i] = add( temp_e[i], sub( Cy_diag_e, mat_mult_buffer2_e ) ); move16(); @@ -3061,7 +3069,7 @@ Word16 computeMixingMatricesISM_fx( } FOR( i = 0; i < lengthCy; i++ ) { - adj_fx[i] = L_shr_r( adj_fx[i], sub( adj_e, temp_e[i] ) ); + adj_fx[i] = L_shr_r( adj_fx[i], sub( adj_e, temp_e[i] ) ); // Q(31-adj_e) move32(); } diff --git a/lib_dec/tonalMDCTconcealment.c b/lib_dec/tonalMDCTconcealment.c index f27836c0e..9bb027025 100644 --- a/lib_dec/tonalMDCTconcealment.c +++ b/lib_dec/tonalMDCTconcealment.c @@ -960,15 +960,15 @@ void TonalMDCTConceal_SaveTimeSignal_ivas( #ifdef IVAS_FLOAT_FIXED void TonalMdctConceal_create_concealment_noise_ivas_fx( - Word32 concealment_noise[L_FRAME48k], + Word32 concealment_noise[L_FRAME48k], // Q31-concealment_noise_exp Word16 *concealment_noise_exp, CPE_DEC_HANDLE hCPE, - const Word16 L_frameTCX, - const Word16 L_frame, - const Word16 idchan, - const Word16 subframe_idx, - const Word16 core, - const Word16 crossfade_gain, + const Word16 L_frameTCX, // Q0 + const Word16 L_frame, // Q0 + const Word16 idchan, // Q0 + const Word16 subframe_idx, // Q0 + const Word16 core, // Q0 + const Word16 crossfade_gain, // Q15 const TONALMDCTCONC_NOISE_GEN_MODE noise_gen_mode ) { STEREO_MDCT_DEC_DATA_HANDLE hStereoMdct; @@ -1027,10 +1027,10 @@ void TonalMdctConceal_create_concealment_noise_ivas_fx( /* first lost frame is handled separately */ IF( !hTonalMDCTConc->lastBlockData.blockIsConcealed ) { - *rnd = add( 1977, idchan ); + *rnd = add( 1977, idchan ); // Q0 move16(); /* will be set twice when looping over two channels, but does not matter */ - *rnd_c = 1979; + *rnd_c = 1979; // Q0 move16(); } @@ -1042,7 +1042,7 @@ void TonalMdctConceal_create_concealment_noise_ivas_fx( { *rnd = own_random( rnd ); move16(); - concealment_noise[i] = *rnd; + concealment_noise[i] = *rnd; // Q31-concealment_noise_exp move32(); } *concealment_noise_exp = 31; @@ -1052,7 +1052,7 @@ void TonalMdctConceal_create_concealment_noise_ivas_fx( return; } - save_rnd_c = *rnd_c; + save_rnd_c = *rnd_c; // Q0 move16(); c_e = 1; @@ -1067,13 +1067,13 @@ void TonalMdctConceal_create_concealment_noise_ivas_fx( { IF( LT_16( c_e, c_inv_e ) ) { - c = shr( c, sub( c_inv_e, c_e ) ); + c = shr( c, sub( c_inv_e, c_e ) ); // Q0 c_e = c_inv_e; move16(); } ELSE { - c_inv = shr( c_inv, sub( c_e, c_inv_e ) ); + c_inv = shr( c_inv, sub( c_e, c_inv_e ) ); // Q0 } } @@ -1105,7 +1105,7 @@ void TonalMdctConceal_create_concealment_noise_ivas_fx( { noise_shape_buffer_e[i] = hFdCngCom->cngNoiseLevelExp; move16(); - noise_shape_buffer[i] = Sqrt32( *( cngNoiseLevelPtr ), &noise_shape_buffer_e[i] ); + noise_shape_buffer[i] = Sqrt32( *( cngNoiseLevelPtr ), &noise_shape_buffer_e[i] ); // Q31-noise_shape_buffer_e[i] move32(); noise_shape_buffer_common_exp = s_max( noise_shape_buffer_e[i], noise_shape_buffer_common_exp ); } @@ -1115,33 +1115,33 @@ void TonalMdctConceal_create_concealment_noise_ivas_fx( IF( NE_16( noise_shape_buffer_common_exp, noise_shape_buffer_e[i] ) ) { - noise_shape_buffer[i] = L_shr( noise_shape_buffer[i], sub( noise_shape_buffer_common_exp, noise_shape_buffer_e[i] ) ); + noise_shape_buffer[i] = L_shr( noise_shape_buffer[i], sub( noise_shape_buffer_common_exp, noise_shape_buffer_e[i] ) ); // Q31- (noise_shape_buffer_common_exp-noise_shape_buffer_e[i]) move32(); } } - last_scf = Sqrt32( *( cngNoiseLevelPtr - inc ), &last_scf_e ); + last_scf = Sqrt32( *( cngNoiseLevelPtr - inc ), &last_scf_e ); // Q31-last_scf_e IF( LT_16( noise_shape_buffer_common_exp, last_scf_e ) ) { - Scale_sig32( noise_shape_buffer, stop_idx, sub( noise_shape_buffer_common_exp, last_scf_e ) ); + Scale_sig32( noise_shape_buffer, stop_idx, sub( noise_shape_buffer_common_exp, last_scf_e ) ); // Q31- (noise_shape_buffer_common_exp-last_scf_e) noise_shape_buffer_common_exp = last_scf_e; move16(); } ELSE { - last_scf = L_shl( last_scf, sub( last_scf_e, noise_shape_buffer_common_exp ) ); + last_scf = L_shl( last_scf, sub( last_scf_e, noise_shape_buffer_common_exp ) ); // Q31-(last_scf_e-noise_shape_buffer_common_exp) } FOR( ; i < max_noise_line; i++ ) { - noise_shape_buffer[i] = last_scf; + noise_shape_buffer[i] = last_scf; // Q31 - noise_shape_buffer_common_exp move32(); } /* fill the noise vector */ - hTonalMDCTConc->curr_noise_nrg = MDCT_ST_PLC_FADEOUT_MIN_NOISE_NRG_Q31; + hTonalMDCTConc->curr_noise_nrg = MDCT_ST_PLC_FADEOUT_MIN_NOISE_NRG_Q31; // Q31 move32(); hTonalMDCTConc->curr_noise_nrg_exp = 0; move16(); @@ -1160,17 +1160,17 @@ void TonalMdctConceal_create_concealment_noise_ivas_fx( FOR( i = 0; i < max_noise_line; i++ ) { - *rnd = own_random( rnd ); + *rnd = own_random( rnd ); // Q0 *rnd_c = own_random( rnd_c ); move16(); move16(); - concealment_noise[i] = Mpy_32_32( L_add( L_shr( L_mult( c_inv, *rnd ), 1 ), L_shr( L_mult( c, *rnd_c ), 1 ) ), noise_shape_buffer[i] ); + concealment_noise[i] = Mpy_32_32( L_add( L_shr( L_mult( c_inv, *rnd ), 1 ), L_shr( L_mult( c, *rnd_c ), 1 ) ), noise_shape_buffer[i] ); // Q31 - *concealment_noise_exp move32(); IF( concealment_noise[i] != 0 ) { - hTonalMDCTConc->curr_noise_nrg = BASOP_Util_Add_Mant32Exp( hTonalMDCTConc->curr_noise_nrg, hTonalMDCTConc->curr_noise_nrg_exp, Mpy_32_32( concealment_noise[i], concealment_noise[i] ), shl( *concealment_noise_exp, 1 ), &temp_e ); + hTonalMDCTConc->curr_noise_nrg = BASOP_Util_Add_Mant32Exp( hTonalMDCTConc->curr_noise_nrg, hTonalMDCTConc->curr_noise_nrg_exp, Mpy_32_32( concealment_noise[i], concealment_noise[i] ), shl( *concealment_noise_exp, 1 ), &temp_e ); // Q31-temp_e } hTonalMDCTConc->curr_noise_nrg_exp = temp_e; move16(); @@ -1181,8 +1181,8 @@ void TonalMdctConceal_create_concealment_noise_ivas_fx( /* current channel is TCX10 and the other is TCX20 -> generate noise for "half-length" spectrum, but "increment" mid seed twice, to have the same seed in mid as the other (TCX20) channel for next frame */ FOR( i = 0; i < max_noise_line; i++ ) { - *rnd = own_random( rnd ); - *rnd_c = own_random( rnd_c ); + *rnd = own_random( rnd ); // Q0 + *rnd_c = own_random( rnd_c ); // Q0 move16(); move16(); @@ -1190,7 +1190,7 @@ void TonalMdctConceal_create_concealment_noise_ivas_fx( move32(); IF( concealment_noise[i] != 0 ) { - hTonalMDCTConc->curr_noise_nrg = BASOP_Util_Add_Mant32Exp( hTonalMDCTConc->curr_noise_nrg, hTonalMDCTConc->curr_noise_nrg_exp, Mpy_32_32( concealment_noise[i], concealment_noise[i] ), shl( *concealment_noise_exp, 1 ), &temp_e ); + hTonalMDCTConc->curr_noise_nrg = BASOP_Util_Add_Mant32Exp( hTonalMDCTConc->curr_noise_nrg, hTonalMDCTConc->curr_noise_nrg_exp, Mpy_32_32( concealment_noise[i], concealment_noise[i] ), shl( *concealment_noise_exp, 1 ), &temp_e ); // Q31-temp_e } hTonalMDCTConc->curr_noise_nrg_exp = temp_e; move16(); @@ -1521,11 +1521,11 @@ void TonalMdctConceal_whiten_noise_shape_ivas_fx( sns_interpolate_scalefactors_fx( scfs_int, scf, ENC ); sns_interpolate_scalefactors_fx( scfs_bg, scf, DEC ); - scfs_for_shaping = &scfs_int[0]; + scfs_for_shaping = &scfs_int[0]; // Q16 } ELSE /* whitening_mode == ON_FIRST_GOOD_FRAME */ { - scfs_for_shaping = &scfs_bg[0]; + scfs_for_shaping = &scfs_bg[0]; // Q16 } IF( sum32_sat( scfs_for_shaping, FDNS_NPTS ) > 0 ) @@ -1537,7 +1537,7 @@ void TonalMdctConceal_whiten_noise_shape_ivas_fx( { FOR( i = 0; i < sub( stop_idx, start_idx ); i++ ) { - hFdCngCom->cngNoiseLevel[i] = L_shr( whitenend_noise_shape[start_idx + i], sub( add( q_wns, hFdCngCom->cngNoiseLevelExp ), 30 ) ); + hFdCngCom->cngNoiseLevel[i] = L_shr( whitenend_noise_shape[start_idx + i], sub( add( q_wns, hFdCngCom->cngNoiseLevelExp ), 30 ) ); //(q_wns + 1) move32(); } } diff --git a/lib_dec/tonalMDCTconcealment_fx.c b/lib_dec/tonalMDCTconcealment_fx.c index fa49a85f3..b46d0abd5 100644 --- a/lib_dec/tonalMDCTconcealment_fx.c +++ b/lib_dec/tonalMDCTconcealment_fx.c @@ -118,8 +118,8 @@ ivas_error TonalMDCTConceal_Init( move16(); move16(); /* just the second half of the second last pcm output is needed */ - hTonalMDCTConc->secondLastPcmOut = &hTonalMDCTConc->timeDataBuffer[sub( ( 3 * L_FRAME_MAX ) / 2, shr( imult1616( 3, ( s_min( L_FRAME_MAX, nSamples ) ) ), 1 ) )]; - hTonalMDCTConc->lastPcmOut = &hTonalMDCTConc->timeDataBuffer[sub( ( 3 * L_FRAME_MAX ) / 2, s_min( L_FRAME_MAX, nSamples ) )]; + hTonalMDCTConc->secondLastPcmOut = &hTonalMDCTConc->timeDataBuffer[( 3 * L_FRAME_MAX ) / 2 - ( 3 * ( min( L_FRAME_MAX, nSamples ) ) / 2 )]; + hTonalMDCTConc->lastPcmOut = &hTonalMDCTConc->timeDataBuffer[( 3 * L_FRAME_MAX ) / 2 - min( L_FRAME_MAX, nSamples )]; /* If the second last frame was lost, we reuse saved TonalComponentsInfo and don't update pcm buffers */ assert( sizeof( *hTonalMDCTConc->pTCI ) <= ( hTonalMDCTConc->lastPcmOut - hTonalMDCTConc->timeDataBuffer ) * sizeof( hTonalMDCTConc->timeDataBuffer[0] ) ); @@ -231,8 +231,8 @@ ivas_error TonalMDCTConceal_Init_ivas_fx( move16(); move16(); /* just the second half of the second last pcm output is needed */ - hTonalMDCTConc->secondLastPcmOut = &hTonalMDCTConc->timeDataBuffer[sub( ( 3 * L_FRAME_MAX ) / 2, imult1616( 3, shr( s_min( L_FRAME_MAX, nSamples ), 1 ) ) )]; - hTonalMDCTConc->lastPcmOut = &hTonalMDCTConc->timeDataBuffer[sub( ( 3 * L_FRAME_MAX ) / 2, s_min( L_FRAME_MAX, nSamples ) )]; + hTonalMDCTConc->secondLastPcmOut = &hTonalMDCTConc->timeDataBuffer[( 3 * L_FRAME_MAX ) / 2 - ( 3 * min( L_FRAME_MAX, nSamples ) / 2 )]; + hTonalMDCTConc->lastPcmOut = &hTonalMDCTConc->timeDataBuffer[( 3 * L_FRAME_MAX ) / 2 - min( L_FRAME_MAX, nSamples )]; /* If the second last frame was lost, we reuse saved TonalComponentsInfo and don't update pcm buffers */ assert( sizeof( *hTonalMDCTConc->pTCI ) <= ( hTonalMDCTConc->lastPcmOut - hTonalMDCTConc->timeDataBuffer ) * sizeof( hTonalMDCTConc->timeDataBuffer[0] ) ); @@ -240,11 +240,11 @@ ivas_error TonalMDCTConceal_Init_ivas_fx( } void TonalMDCTConceal_SaveFreqSignal( TonalMDCTConcealPtr hTonalMDCTConc, - const Word32 *mdctSpectrum, + const Word32 *mdctSpectrum, // Q31-mdctSpectrum_exp const Word16 mdctSpectrum_exp, - Word16 nNewSamples, - Word16 nNewSamplesCore, - const Word16 *scaleFactors, + Word16 nNewSamples, // Q0 + Word16 nNewSamplesCore, // Q0 + const Word16 *scaleFactors, // Q31-scaleFactors_exp const Word16 *scaleFactors_exp, const Word16 gain_tcx_exp #ifdef IVAS_CODE_CNG_FIX185_PLC_FADEOUT @@ -375,7 +375,7 @@ void TonalMDCTConceal_SaveFreqSignal( FOR( i = 0; i < nNewSamples; i++ ) { - hTonalMDCTConc->lastBlockData.spectralData[i] = extract_h( L_shl( mdctSpectrum[i], s ) ); + hTonalMDCTConc->lastBlockData.spectralData[i] = extract_h( L_shl( mdctSpectrum[i], s ) ); // Q31-(mdctSpectrum_exp-s) move16(); } hTonalMDCTConc->lastBlockData.spectralData_exp = sub( mdctSpectrum_exp, s ); @@ -390,14 +390,14 @@ void TonalMDCTConceal_SaveFreqSignal( void TonalMDCTConceal_SaveFreqSignal_ivas_fx( TonalMDCTConcealPtr hTonalMDCTConc, - const Word32 *mdctSpectrum, - const Word16 mdctSpectrum_exp, - const Word16 nNewSamples, - const Word16 nNewSamplesCore, - const Word16 *scaleFactors, - const Word16 *scaleFactors_exp, - const Word16 gain_tcx_exp, - const Word16 infoIGFStartLine ) + const Word32 *mdctSpectrum, // Q31-mdctSpectrum_exp + const Word16 mdctSpectrum_exp, // Q0 + const Word16 nNewSamples, // Q0 + const Word16 nNewSamplesCore, // Q0 + const Word16 *scaleFactors, // Q15 - *scaleFactors_exp + const Word16 *scaleFactors_exp, // Q0 + const Word16 gain_tcx_exp, // Q0 + const Word16 infoIGFStartLine ) // Q0 { Word16 *temp; Word16 nOldSamples, temp_exp, s, i, max_exp; @@ -496,7 +496,7 @@ void TonalMDCTConceal_SaveFreqSignal_ivas_fx( { Word16 tmp = extract_h( mdctSpectrum[i] ); hTonalMDCTConc->last_block_nrg = L_add( hTonalMDCTConc->last_block_nrg, - L_shr( L_mult0( tmp, tmp ), 16 ) ); + L_shr( L_mult0( tmp, tmp ), 16 ) ); // Q31-last_block_nrg_exp move32(); } hTonalMDCTConc->last_block_nrg_exp = sub( 31, sub( shl( sub( 15, mdctSpectrum_exp ), 1 ), 16 ) ); @@ -526,7 +526,7 @@ void TonalMDCTConceal_SaveFreqSignal_ivas_fx( tmp = 1; move16(); } - hTonalMDCTConc->lastBlockData.spectralData[i] = extract_h( L_shl( mdctSpectrum[i], s ) ); + hTonalMDCTConc->lastBlockData.spectralData[i] = extract_h( L_shl( mdctSpectrum[i], s ) ); // 31 - mdctSpectrum_exp +s -16 = 15-(mdctSpectrum_exp -s) move16(); test(); @@ -549,9 +549,9 @@ void TonalMDCTConceal_SaveFreqSignal_ivas_fx( TONALMDCTCONCEAL_ERROR TonalMDCTConceal_UpdateState( TonalMDCTConcealPtr hTonalMDCTConc, - Word16 nNewSamples, - Word32 pitchLag, - Word16 badBlock, + Word16 nNewSamples, // Q0 + Word32 pitchLag, // Qx + Word16 badBlock, // Q0 Word8 tonalConcealmentActive ) { Word8 newBlockIsValid; @@ -596,8 +596,8 @@ TONALMDCTCONCEAL_ERROR TonalMDCTConceal_UpdateState( TonalMDCTConcealPtr hTonalM } static void FindPhases( /* o: currenc phase [-pi;pi] 2Q13 */ TonalMDCTConcealPtr const hTonalMDCTConc, /* i: pointer to internal structure */ - Word32 secondLastMDCT[], /* i: MDST spectrum data */ - Word32 secondLastMDST[], /* i: MDCT spectrum data */ + Word32 secondLastMDCT[], /* i: MDST spectrum data Qx +31 -diff_exp */ + Word32 secondLastMDST[], /* i: MDCT spectrum data Qx */ Word16 diff_exp ) /* i: exp_MDST - exp_MDCT */ { Word16 i; @@ -614,7 +614,7 @@ static void FindPhases( /* o: currenc /* in contrast to the float code, the parameter secondLastMDST[l] needs not to be negated - due to a different implementation of the MDST */ - *pCurrentPhase++ = BASOP_util_atan2( secondLastMDST[l], secondLastMDCT[l], diff_exp ); + *pCurrentPhase++ = BASOP_util_atan2( secondLastMDST[l], secondLastMDCT[l], diff_exp ); // Q13 move16(); } } @@ -630,7 +630,7 @@ static void FindPhases( /* o: currenc static void FindPhaseDifferences( /* o: Phase difference [-pi;pi] 2Q13*/ TonalMDCTConcealPtr const hTonalMDCTConc, /* i: Pointer to internal structure */ - Word32 powerSpectrum[] ) /* i: Power spectrum data */ + Word32 powerSpectrum[] ) /* i: Power spectrum data Qx */ { Word16 i, k; Word16 *phaseDiff; @@ -684,7 +684,7 @@ static void FindPhaseDifferences( /* o phaseDiff[i] = (float)atan(a) * (bandwidth/2.0f);*/ /*max divi=44.8 & sf=6*/ divi = BASOP_Util_Divide3232_uu_1616_Scale( powerSpectrum[k - 1], powerSpectrum[k + 1], &sf ); - Q = BASOP_Util_fPow( L_deposit_h( divi ), sf, G, 0, &sf ); + Q = BASOP_Util_fPow( L_deposit_h( divi ), sf, G, 0, &sf ); // Q31-sf L_tmp = Mpy_32_16_1( Q, s ); sfn = sub( sf, 2 ); @@ -743,11 +743,11 @@ static void FindPhaseDifferences( /* o #ifdef IVAS_FLOAT_FIXED static void ivas_CalcPowerSpecAndDetectTonalComponents_fx( TonalMDCTConcealPtr const hTonalMDCTConc, - Word32 secondLastMDST[], + Word32 secondLastMDST[], // Q31 - secondLastMDST_exp Word16 secondLastMDST_exp, - Word32 secondLastMDCT[], + Word32 secondLastMDCT[], // Q31 - secondLastMDCT_exp Word16 secondLastMDCT_exp, - Word32 const pitchLag, + Word32 const pitchLag, /*15Q16*/ const PsychoacousticParameters *psychParamsCurrent, Word16 element_mode ) { @@ -823,14 +823,14 @@ static void ivas_CalcPowerSpecAndDetectTonalComponents_fx( /*sqrtFLOAT(powerSpectrum, powerSpectrum, nSamples);*/ old_exp = powerSpectrum_exp; move16(); - powerSpectrum_exp = mult_r( sub( powerSpectrum_exp, 2 ), 1 << 14 ); /*remove 2 bits of headroom from CalcPowerSpec*/ + powerSpectrum_exp = mult_r( sub( powerSpectrum_exp, 2 ), ( 1 << 14 ) ); /*remove 2 bits of headroom from CalcPowerSpec*/ FOR( i = 0; i < nSamples; i++ ) { tmp_exp = old_exp; move16(); powerSpectrum[i] = Sqrt32( powerSpectrum[i], &tmp_exp ); move32(); - powerSpectrum[i] = L_shr( powerSpectrum[i], sub( powerSpectrum_exp, tmp_exp ) ); + powerSpectrum[i] = L_shr( powerSpectrum[i], sub( powerSpectrum_exp, tmp_exp ) ); // Q31-(powerSpectrum_exp-tmp_exp) move32(); } @@ -838,7 +838,7 @@ static void ivas_CalcPowerSpecAndDetectTonalComponents_fx( { invScaleFactors_exp[i] = hTonalMDCTConc->secondLastBlockData.scaleFactors_exp[i]; move16(); - invScaleFactors[i] = Inv16( hTonalMDCTConc->secondLastBlockData.scaleFactors[i], &invScaleFactors_exp[i] ); + invScaleFactors[i] = Inv16( hTonalMDCTConc->secondLastBlockData.scaleFactors[i], &invScaleFactors_exp[i] ); // Q31-invScaleFactors_exp[i] move16(); } @@ -868,19 +868,19 @@ static void ivas_CalcPowerSpecAndDetectTonalComponents_fx( } IF( LT_16( old_power_spectrum_q, power_spectrum_q ) ) { - Scale_sig32( powerSpectrum, length, sub( old_power_spectrum_q, power_spectrum_q ) ); + Scale_sig32( powerSpectrum, length, sub( old_power_spectrum_q, power_spectrum_q ) ); // Q(old_power_spectrum_q-power_spectrum_q) } ELSE { - Scale_sig32( powerSpectrum + length, sub( nSamples, length ), sub( power_spectrum_q, old_power_spectrum_q ) ); + Scale_sig32( powerSpectrum + length, sub( nSamples, length ), sub( power_spectrum_q, old_power_spectrum_q ) ); // Q(power_spectrum_q - old_power_spectrum_q) powerSpectrum_exp = sub( 31, power_spectrum_q ); } - Scale_sig32( powerSpectrum, nSamples, -3 ); /*Adding guard bits*/ + Scale_sig32( powerSpectrum, nSamples, -3 ); /*Adding guard bits*/ // Q(31 - powerSpectrum_exp )-3 powerSpectrum_exp = add( powerSpectrum_exp, 3 ); FOR( i = hTonalMDCTConc->nSamplesCore; i < nSamples; i++ ) { #ifdef BASOP_NOGLOB - powerSpectrum[i] = L_shl_sat( Mpy_32_16_1( powerSpectrum[i], invScaleFactors[nBands - 1] ), invScaleFactors_exp[nBands - 1] ); + powerSpectrum[i] = L_shl_sat( Mpy_32_16_1( powerSpectrum[i], invScaleFactors[nBands - 1] ), invScaleFactors_exp[nBands - 1] ); // Q(31 - powerSpectrum_exp) #else powerSpectrum[i] = L_shl( Mpy_32_16_1( powerSpectrum[i], invScaleFactors[nBands - 1] ), invScaleFactors_exp[nBands - 1] ); #endif @@ -895,7 +895,7 @@ static void ivas_CalcPowerSpecAndDetectTonalComponents_fx( FOR( i = 0; i < nSamples; i++ ) { #ifdef BASOP_NOGLOB - hTonalMDCTConc->secondLastPowerSpectrum[i] = round_fx_o( powerSpectrum[i], &Overflow ); + hTonalMDCTConc->secondLastPowerSpectrum[i] = round_fx_o( powerSpectrum[i], &Overflow ); // Q31 - powerSpectrum_exp #else hTonalMDCTConc->secondLastPowerSpectrum[i] = round_fx( powerSpectrum[i] ); #endif @@ -910,11 +910,11 @@ static void ivas_CalcPowerSpecAndDetectTonalComponents_fx( static void CalcPowerSpecAndDetectTonalComponents( TonalMDCTConcealPtr const hTonalMDCTConc, - Word32 secondLastMDST[], + Word32 secondLastMDST[], // Q31-secondLastMDST_exp Word16 secondLastMDST_exp, - Word32 secondLastMDCT[], + Word32 secondLastMDCT[], // Q31-secondLastMDCT_exp Word16 secondLastMDCT_exp, - Word32 const pitchLag, + Word32 const pitchLag, /*15Q16*/ Word16 element_mode #ifdef IVAS_CODE_MDCT_GSHAPE , @@ -995,8 +995,8 @@ static void CalcPowerSpecAndDetectTonalComponents( { tmp_exp = old_exp; move16(); - powerSpectrum[i] = Sqrt32( powerSpectrum[i], &tmp_exp ); - powerSpectrum[i] = L_shr( powerSpectrum[i], sub( powerSpectrum_exp, tmp_exp ) ); + powerSpectrum[i] = Sqrt32( powerSpectrum[i], &tmp_exp ); // Q31- tmp_exp + powerSpectrum[i] = L_shr( powerSpectrum[i], sub( powerSpectrum_exp, tmp_exp ) ); // Q31- tmp_exp move32(); } @@ -1005,7 +1005,7 @@ static void CalcPowerSpecAndDetectTonalComponents( move16(); move16(); invScaleFactors_exp[i] = hTonalMDCTConc->secondLastBlockData.scaleFactors_exp[i]; - invScaleFactors[i] = Inv16( hTonalMDCTConc->secondLastBlockData.scaleFactors[i], &invScaleFactors_exp[i] ); + invScaleFactors[i] = Inv16( hTonalMDCTConc->secondLastBlockData.scaleFactors[i], &invScaleFactors_exp[i] ); // Q31 - invScaleFactors_exp[i] } @@ -1027,7 +1027,7 @@ static void CalcPowerSpecAndDetectTonalComponents( FOR( i = hTonalMDCTConc->nSamplesCore; i < nSamples; i++ ) { #ifdef BASOP_NOGLOB - powerSpectrum[i] = L_shl_sat( Mpy_32_16_1( powerSpectrum[i], invScaleFactors[FDNS_NPTS - 1] ), invScaleFactors_exp[FDNS_NPTS - 1] ); + powerSpectrum[i] = L_shl_sat( Mpy_32_16_1( powerSpectrum[i], invScaleFactors[FDNS_NPTS - 1] ), invScaleFactors_exp[FDNS_NPTS - 1] ); // powerSpectrum_exp+ 2*invScaleFactors_exp -15 #else powerSpectrum[i] = L_shl( Mpy_32_16_1( powerSpectrum[i], invScaleFactors[FDNS_NPTS - 1] ), invScaleFactors_exp[FDNS_NPTS - 1] ); #endif @@ -1038,7 +1038,7 @@ static void CalcPowerSpecAndDetectTonalComponents( FOR( i = 0; i < nSamples; i++ ) { #ifdef BASOP_NOGLOB - hTonalMDCTConc->secondLastPowerSpectrum[i] = round_fx_o( powerSpectrum[i], &Overflow ); + hTonalMDCTConc->secondLastPowerSpectrum[i] = round_fx_o( powerSpectrum[i], &Overflow ); // Q31-powerSpectrum_exp #else hTonalMDCTConc->secondLastPowerSpectrum[i] = round_fx( powerSpectrum[i] ); #endif @@ -1055,8 +1055,8 @@ static void CalcPowerSpecAndDetectTonalComponents( static void CalcMDXT( const TonalMDCTConcealPtr hTonalMDCTConc, const Word16 type, - const Word16 *timeSignal, - Word32 *mdxtOutput, + const Word16 *timeSignal, // Qx + Word32 *mdxtOutput, // Q31-mdxtOutput_e Word16 *mdxtOutput_e ) { Word16 windowedTimeSignal[L_FRAME_PLUS + 2 * L_MDCT_OVLP_MAX]; @@ -1082,7 +1082,7 @@ static void CalcMDXT( void TonalMDCTConceal_Detect( const TonalMDCTConcealPtr hTonalMDCTConc, - const Word32 pitchLag, + const Word32 pitchLag, /*15Q16*/ Word16 *numIndices, Word16 element_mode #ifdef IVAS_CODE_MDCT_GSHAPE @@ -1184,8 +1184,8 @@ void TonalMDCTConceal_Detect( /* multFLOAT(powerSpectrum, powerSpectrum, powerSpectrum, nSamples); */ FOR( i = 0; i < nSamples; i++ ) { - Word32 const t = L_shl( powerSpectrum[i], powerSpectrum_exp ); - powerSpectrum[i] = Mpy_32_32( t, t ); + Word32 const t = L_shl( powerSpectrum[i], powerSpectrum_exp ); // Q(31-secondLastMDST_exp+powerSpectrum_exp) + powerSpectrum[i] = Mpy_32_32( t, t ); // Q2*(31-secondLastMDST_exp+powerSpectrum_exp) -31 move32(); } @@ -1225,7 +1225,7 @@ void TonalMDCTConceal_Detect( #ifdef IVAS_FLOAT_FIXED void TonalMDCTConceal_Detect_ivas_fx( const TonalMDCTConcealPtr hTonalMDCTConc, - const Word32 pitchLag, + const Word32 pitchLag, /*15Q16*/ Word16 *numIndices, const PsychoacousticParameters *psychParamsCurrent, Word16 element_mode ) @@ -1328,8 +1328,8 @@ void TonalMDCTConceal_Detect_ivas_fx( /* multFLOAT(powerSpectrum, powerSpectrum, powerSpectrum, nSamples); */ FOR( i = 0; i < nSamples; i++ ) { - Word32 const t = L_shl( powerSpectrum[i], powerSpectrum_exp ); - powerSpectrum[i] = Mpy_32_32( t, t ); + Word32 const t = L_shl( powerSpectrum[i], powerSpectrum_exp ); // Q(31-secondLastMDST_exp+powerSpectrum_exp) + powerSpectrum[i] = Mpy_32_32( t, t ); // Q(31-secondLastMDST_exp+powerSpectrum_exp) move32(); } } @@ -1345,8 +1345,8 @@ void TonalMDCTConceal_Detect_ivas_fx( FOR( i = 0; i < nSamples; i++ ) { - Word32 const t = L_shl( powerSpectrum[i], -3 ); - powerSpectrum[i] = Mpy_32_32( t, t ); + Word32 const t = L_shl( powerSpectrum[i], -3 ); // Q31 - powerSpectrum_exp -3 + powerSpectrum[i] = Mpy_32_32( t, t ); // 2*(Q31 - powerSpectrum_exp -3)-31 move32(); } } @@ -1387,17 +1387,17 @@ void TonalMDCTConceal_Detect_ivas_fx( void TonalMDCTConceal_InsertNoise_ivas_fx( const TonalMDCTConcealPtr hTonalMDCTConc, /*IN */ - Word32 *mdctSpectrum, + Word32 *mdctSpectrum, // Q31-mdctSpectrum_exp Word16 *mdctSpectrum_exp, const Word16 tonalConcealmentActive, - Word16 *pSeed, /*IN/OUT*/ - const Word16 tiltCompFactor, - const Word16 crossfadeGain_const, - const Word32 concealment_noise[L_FRAME48k], + Word16 *pSeed, /*IN/OUT*/ + const Word16 tiltCompFactor, // Q15 + const Word16 crossfadeGain_const, // Q15 + const Word32 concealment_noise[L_FRAME48k], // Q31-concealment_noise_e const Word16 concealment_noise_e, - const Word32 cngLevelBackgroundTrace_bfi, + const Word32 cngLevelBackgroundTrace_bfi, // Q31-cngLevelBackgroundTrace_bfi_e const Word16 cngLevelBackgroundTrace_bfi_e, - const Word16 crossOverFreq ) + const Word16 crossOverFreq ) // Q0 { Word16 i, l, ld, fac; Word16 rnd; @@ -1438,11 +1438,11 @@ void TonalMDCTConceal_InsertNoise_ivas_fx( move32(); inv_exp = 15; move16(); - inv_samples = Inv16( hTonalMDCTConc->lastBlockData.nSamples, &inv_exp ); - tiltFactor = round_fx( BASOP_Util_fPow( L_max( L_tmp, L_deposit_h( tiltCompFactor ) ), 0, L_deposit_h( inv_samples ), inv_exp, &exp ) ); - BASOP_SATURATE_WARNING_OFF_EVS /*next op may result in 32768*/ + inv_samples = Inv16( hTonalMDCTConc->lastBlockData.nSamples, &inv_exp ); // Q31-inv_exp + tiltFactor = round_fx( BASOP_Util_fPow( L_max( L_tmp, L_deposit_h( tiltCompFactor ) ), 0, L_deposit_h( inv_samples ), inv_exp, &exp ) ); // Q15 - exp + BASOP_SATURATE_WARNING_OFF_EVS /*next op may result in 32768*/ #ifdef BASOP_NOGLOB - tiltFactor = shl_sat( tiltFactor, exp ); + tiltFactor = shl_sat( tiltFactor, exp ); // Q15 #else tiltFactor = shl( tiltFactor, exp ); #endif @@ -1474,19 +1474,19 @@ void TonalMDCTConceal_InsertNoise_ivas_fx( { IF( concealment_noise[i] > 0 ) { - mdctSpectrum[i] = L_shl( L_deposit_l( hTonalMDCTConc->lastBlockData.spectralData[i] ), 16 ); + mdctSpectrum[i] = L_shl( L_deposit_l( hTonalMDCTConc->lastBlockData.spectralData[i] ), 16 ); // Q31-spectralData_exp move32(); } ELSE { - mdctSpectrum[i] = L_negate( L_shl( L_deposit_l( hTonalMDCTConc->lastBlockData.spectralData[i] ), 16 ) ); + mdctSpectrum[i] = L_negate( L_shl( L_deposit_l( hTonalMDCTConc->lastBlockData.spectralData[i] ), 16 ) ); // Q31-spectralData_exp move32(); } } FOR( l = crossOverFreq; l < hTonalMDCTConc->lastBlockData.nSamples; l++ ) { - mdctSpectrum[l] = L_shl( L_deposit_l( hTonalMDCTConc->lastBlockData.spectralData[l] ), 16 ); + mdctSpectrum[l] = L_shl( L_deposit_l( hTonalMDCTConc->lastBlockData.spectralData[l] ), 16 ); // Q31-spectralData_exp move32(); } @@ -1508,14 +1508,14 @@ void TonalMDCTConceal_InsertNoise_ivas_fx( num = L_shl( cngLevelBackgroundTrace_bfi, ld ); exp_num = sub( exp_num, ld ); ld = norm_l( hTonalMDCTConc->curr_noise_nrg ); - den = L_shl( hTonalMDCTConc->curr_noise_nrg, ld ); + den = L_shl( hTonalMDCTConc->curr_noise_nrg, ld ); // Q31- curr_noise_nrg_exp + ld exp_den = sub( exp_den, ld ); exp = sub( exp_num, exp_den ); IF( GT_32( num, den ) ) { - num = L_shr( num, 1 ); + num = L_shr( num, 1 ); // Q31-exp -1 exp = add( exp, 1 ); } #ifdef BASOP_NOGLOB @@ -1533,13 +1533,13 @@ void TonalMDCTConceal_InsertNoise_ivas_fx( { IF( exp > 0 ) { - g = shr( g, exp ); + g = shr( g, exp ); // Q15-exp *mdctSpectrum_exp = hTonalMDCTConc->lastBlockData.spectralData_exp; move16(); } ELSE { - crossfadeGain = shl( crossfadeGain, exp ); + crossfadeGain = shl( crossfadeGain, exp ); // Q15 - e_crossfadeGain + exp e_crossfadeGain = sub( e_crossfadeGain, exp ); *mdctSpectrum_exp = sub( hTonalMDCTConc->lastBlockData.spectralData_exp, exp ); move16(); @@ -1568,25 +1568,25 @@ void TonalMDCTConceal_InsertNoise_ivas_fx( FOR( i = 0; i < crossOverFreq; i++ ) { - Word16 x = hTonalMDCTConc->lastBlockData.spectralData[i]; + Word16 x = hTonalMDCTConc->lastBlockData.spectralData[i]; // Q15 - spectralData_exp move16(); - Word32 y = concealment_noise[i]; + Word32 y = concealment_noise[i]; // Q31-concealment_noise_e move32(); IF( g > 0 ) { - L_tmp = Mpy_32_16_1( y, g ); + L_tmp = Mpy_32_16_1( y, g ); // Q31-concealment_noise_e- spectralData_exp } - L_tmp2 = L_msu( L_tmp, crossfadeGain, x ); + 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 ); + L_tmp2 = L_mac( L_tmp, crossfadeGain, x ); // Q15 - e_crossfadeGain + Q15 - spectralData_exp } - mdctSpectrum[i] = L_shl( L_tmp2, exp ); + mdctSpectrum[i] = L_shl( L_tmp2, exp ); // Q15 - e_crossfadeGain + Q15 - spectralData_exp + exp move32(); - hTonalMDCTConc->faded_signal_nrg = L_add( hTonalMDCTConc->faded_signal_nrg, Mpy_32_32( mdctSpectrum[i], mdctSpectrum[i] ) ); + hTonalMDCTConc->faded_signal_nrg = L_add( hTonalMDCTConc->faded_signal_nrg, Mpy_32_32( mdctSpectrum[i], mdctSpectrum[i] ) ); // Q31- faded_signal_nrg_exp move32(); } FOR( i = crossOverFreq; i < hTonalMDCTConc->lastBlockData.nSamples; i++ ) @@ -1621,11 +1621,11 @@ void TonalMDCTConceal_InsertNoise_ivas_fx( { Word16 x = hTonalMDCTConc->lastBlockData.spectralData[l]; move16(); - Word32 y = concealment_noise[l]; + Word32 y = concealment_noise[l];//concealment_noise_e move32(); last_block_nrg_correct = L_add( last_block_nrg_correct, Mpy_32_16_1( L_msu( 0, x, fac ), x ) ); // exp = 2 * x_exp + ld - y = L_negate( Mpy_32_32( y, y ) ); - hTonalMDCTConc->curr_noise_nrg = BASOP_Util_Add_Mant32Exp( hTonalMDCTConc->curr_noise_nrg, hTonalMDCTConc->curr_noise_nrg_exp, y, 2 * concealment_noise_e, &hTonalMDCTConc->curr_noise_nrg_exp ); + y = L_negate( Mpy_32_32( y, y ) );//Q31-2* concealment_noise_e + hTonalMDCTConc->curr_noise_nrg = BASOP_Util_Add_Mant32Exp( hTonalMDCTConc->curr_noise_nrg, hTonalMDCTConc->curr_noise_nrg_exp, y, 2 * concealment_noise_e, &hTonalMDCTConc->curr_noise_nrg_exp ); // Q31- hTonalMDCTConc->curr_noise_nrg_exp move32(); } } @@ -1639,12 +1639,12 @@ void TonalMDCTConceal_InsertNoise_ivas_fx( { IF( GT_32( concealment_noise[l], 0 ) ) { - mdctSpectrum[l] = L_shl( L_deposit_l( hTonalMDCTConc->lastBlockData.spectralData[l] ), 16 ); + mdctSpectrum[l] = L_shl( L_deposit_l( hTonalMDCTConc->lastBlockData.spectralData[l] ), 16 ); // hTonalMDCTConc->lastBlockData.spectralData_exp move32(); } ELSE { - mdctSpectrum[l] = L_negate( L_shl( L_deposit_l( hTonalMDCTConc->lastBlockData.spectralData[l] ), 16 ) ); + mdctSpectrum[l] = L_negate( L_shl( L_deposit_l( hTonalMDCTConc->lastBlockData.spectralData[l] ), 16 ) ); // hTonalMDCTConc->lastBlockData.spectralData_exp move32(); } } @@ -1654,12 +1654,12 @@ void TonalMDCTConceal_InsertNoise_ivas_fx( { IF( concealment_noise[l] > 0 ) { - mdctSpectrum[l] = L_shl( L_deposit_l( hTonalMDCTConc->lastBlockData.spectralData[l] ), 16 ); + mdctSpectrum[l] = L_shl( L_deposit_l( hTonalMDCTConc->lastBlockData.spectralData[l] ), 16 ); // hTonalMDCTConc->lastBlockData.spectralData_exp move32(); } ELSE { - mdctSpectrum[l] = L_negate( L_shl( L_deposit_l( hTonalMDCTConc->lastBlockData.spectralData[l] ), 16 ) ); + mdctSpectrum[l] = L_negate( L_shl( L_deposit_l( hTonalMDCTConc->lastBlockData.spectralData[l] ), 16 ) ); // hTonalMDCTConc->lastBlockData.spectralData_exp move32(); } } @@ -1669,19 +1669,19 @@ void TonalMDCTConceal_InsertNoise_ivas_fx( { IF( concealment_noise[l] > 0 ) { - mdctSpectrum[l] = L_shl( L_deposit_l( hTonalMDCTConc->lastBlockData.spectralData[l] ), 16 ); + mdctSpectrum[l] = L_shl( L_deposit_l( hTonalMDCTConc->lastBlockData.spectralData[l] ), 16 ); // hTonalMDCTConc->lastBlockData.spectralData_exp move32(); } ELSE { - mdctSpectrum[l] = L_negate( L_shl( L_deposit_l( hTonalMDCTConc->lastBlockData.spectralData[l] ), 16 ) ); + mdctSpectrum[l] = L_negate( L_shl( L_deposit_l( hTonalMDCTConc->lastBlockData.spectralData[l] ), 16 ) ); // hTonalMDCTConc->lastBlockData.spectralData_exp move32(); } } FOR( l = crossOverFreq; l < hTonalMDCTConc->lastBlockData.nSamples; l++ ) { - mdctSpectrum[l] = L_shl( L_deposit_l( hTonalMDCTConc->lastBlockData.spectralData[l] ), 16 ); + mdctSpectrum[l] = L_shl( L_deposit_l( hTonalMDCTConc->lastBlockData.spectralData[l] ), 16 ); // hTonalMDCTConc->lastBlockData.spectralData_exp move32(); } @@ -1700,17 +1700,17 @@ void TonalMDCTConceal_InsertNoise_ivas_fx( move16(); ld = norm_l( cngLevelBackgroundTrace_bfi ); - num = L_shl( cngLevelBackgroundTrace_bfi, ld ); + num = L_shl( cngLevelBackgroundTrace_bfi, ld ); // Q15 - exp_num + ld exp_num = sub( exp_num, ld ); ld = norm_l( hTonalMDCTConc->curr_noise_nrg ); - den = L_shl( hTonalMDCTConc->curr_noise_nrg, ld ); + den = L_shl( hTonalMDCTConc->curr_noise_nrg, ld ); // Q15 - exp_den + ld exp_den = sub( exp_den, ld ); exp = sub( exp_num, exp_den ); IF( GT_32( num, den ) ) { - num = L_shr( num, 1 ); + num = L_shr( num, 1 ); // Q31- exp -1 exp = add( exp, 1 ); } tmp = div_l( num, round_fx( den ) ); @@ -1725,13 +1725,13 @@ void TonalMDCTConceal_InsertNoise_ivas_fx( { IF( GT_16( exp, 0 ) ) { - g = shr( g, exp ); + g = shr( g, exp ); // Q15- exp *mdctSpectrum_exp = hTonalMDCTConc->lastBlockData.spectralData_exp; move16(); } ELSE { - crossfadeGain = shl( crossfadeGain, exp ); + crossfadeGain = shl( crossfadeGain, exp ); // Q15 - e_crossfadeGain e_crossfadeGain = sub( e_crossfadeGain, exp ); *mdctSpectrum_exp = add( e_crossfadeGain, hTonalMDCTConc->lastBlockData.spectralData_exp ); move16(); @@ -1760,25 +1760,25 @@ void TonalMDCTConceal_InsertNoise_ivas_fx( FOR( l = 0; l < hTonalMDCTConc->pTCI->lowerIndex[0]; l++ ) { - Word16 x = hTonalMDCTConc->lastBlockData.spectralData[l]; + Word16 x = hTonalMDCTConc->lastBlockData.spectralData[l]; // Q15 - spectralData_exp move16(); - Word32 y = concealment_noise[l]; + Word32 y = concealment_noise[l]; // Q31-concealment_noise_e move32(); IF( g > 0 ) { - L_tmp = Mpy_32_16_1( y, g ); + L_tmp = Mpy_32_16_1( y, g ); // Q31-concealment_noise_e- spectralData_exp } - L_tmp2 = L_msu( L_tmp, crossfadeGain, x ); + 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 ); + L_tmp2 = L_mac( L_tmp, crossfadeGain, x ); // Q15 - e_crossfadeGain + Q15 - spectralData_exp } - mdctSpectrum[l] = L_shl( L_tmp2, exp ); + mdctSpectrum[l] = L_shl( L_tmp2, exp ); // Q15 - e_crossfadeGain + Q15 - spectralData_exp + exp move32(); - hTonalMDCTConc->faded_signal_nrg = L_add( hTonalMDCTConc->faded_signal_nrg, Mpy_32_32( mdctSpectrum[l], mdctSpectrum[l] ) ); + hTonalMDCTConc->faded_signal_nrg = L_add( hTonalMDCTConc->faded_signal_nrg, Mpy_32_32( mdctSpectrum[l], mdctSpectrum[l] ) ); // Q31 - 2*mdctSpectrum_exp move32(); } @@ -1786,41 +1786,41 @@ void TonalMDCTConceal_InsertNoise_ivas_fx( { FOR( l = hTonalMDCTConc->pTCI->upperIndex[i - 1] + 1; l < hTonalMDCTConc->pTCI->lowerIndex[i]; l++ ) { - Word16 x = hTonalMDCTConc->lastBlockData.spectralData[l]; + Word16 x = hTonalMDCTConc->lastBlockData.spectralData[l]; // Q15 - spectralData_exp move16(); - Word32 y = concealment_noise[l]; + Word32 y = concealment_noise[l]; // Q31-concealment_noise_e move32(); L_tmp = Mpy_32_16_1( y, g ); - L_tmp2 = L_msu( L_tmp, crossfadeGain, x ); + 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 ); + L_tmp2 = L_mac( L_tmp, crossfadeGain, x ); // Q15 - e_crossfadeGain + Q15 - spectralData_exp } - mdctSpectrum[l] = L_shl( L_tmp2, exp ); + mdctSpectrum[l] = L_shl( L_tmp2, exp ); // Q15 - e_crossfadeGain + Q15 - spectralData_exp + exp move32(); - hTonalMDCTConc->faded_signal_nrg = L_add( hTonalMDCTConc->faded_signal_nrg, Mpy_32_32( mdctSpectrum[l], mdctSpectrum[l] ) ); + hTonalMDCTConc->faded_signal_nrg = L_add( hTonalMDCTConc->faded_signal_nrg, Mpy_32_32( mdctSpectrum[l], mdctSpectrum[l] ) ); // Q31- 2*mdctSpectrum_exp } } FOR( l = hTonalMDCTConc->pTCI->upperIndex[hTonalMDCTConc->pTCI->numIndexes - 1] + 1; l < crossOverFreq; l++ ) { - Word16 x = hTonalMDCTConc->lastBlockData.spectralData[l]; + Word16 x = hTonalMDCTConc->lastBlockData.spectralData[l]; // Q15 - spectralData_exp move16(); - Word32 y = concealment_noise[l]; + Word32 y = concealment_noise[l]; // Q31-concealment_noise_e move32(); - L_tmp = Mpy_32_16_1( y, g ); - L_tmp2 = L_msu( L_tmp, crossfadeGain, x ); + L_tmp = Mpy_32_16_1( y, g ); // Q31-concealment_noise_e- 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 ); + L_tmp2 = L_mac( L_tmp, crossfadeGain, x ); // Q15 - e_crossfadeGain + Q15 - spectralData_exp } - mdctSpectrum[l] = L_shl( L_tmp2, exp ); + mdctSpectrum[l] = L_shl( L_tmp2, exp ); // Q15 - e_crossfadeGain + Q15 - spectralData_exp + exp move32(); - hTonalMDCTConc->faded_signal_nrg = L_add( hTonalMDCTConc->faded_signal_nrg, Mpy_32_32( mdctSpectrum[l], mdctSpectrum[l] ) ); + hTonalMDCTConc->faded_signal_nrg = L_add( hTonalMDCTConc->faded_signal_nrg, Mpy_32_32( mdctSpectrum[l], mdctSpectrum[l] ) ); // Q31- 2*mdctSpectrum_exp move32(); } @@ -1845,26 +1845,26 @@ void TonalMDCTConceal_InsertNoise_ivas_fx( Word16 num_exp, den_exp; Word32 num, den; - num = BASOP_Util_Add_Mant32Exp( hTonalMDCTConc->last_block_nrg, hTonalMDCTConc->last_block_nrg_exp, L_negate( last_block_nrg_correct ), last_block_nrg_correct_e, &num_exp ); + num = BASOP_Util_Add_Mant32Exp( hTonalMDCTConc->last_block_nrg, hTonalMDCTConc->last_block_nrg_exp, L_negate( last_block_nrg_correct ), last_block_nrg_correct_e, &num_exp ); // Q31-num_exp - den = hTonalMDCTConc->faded_signal_nrg; + den = hTonalMDCTConc->faded_signal_nrg; // Q31 - hTonalMDCTConc->faded_signal_nrg_exp move32(); den_exp = hTonalMDCTConc->faded_signal_nrg_exp; move16(); ld = norm_l( num ); - num = L_shl( num, ld ); + num = L_shl( num, ld ); // Q31-num_exp + ld num_exp = sub( num_exp, ld ); ld = norm_l( den ); - den = L_shl( den, ld ); + den = L_shl( den, ld ); // Q31-den_exp + ld den_exp = sub( den_exp, ld ); exp = sub( num_exp, den_exp ); IF( GT_32( num, den ) ) { - num = L_shr( num, 1 ); + num = L_shr( num, 1 ); // Q31- exp -1 exp = add( exp, 1 ); } tmp = div_l( num, round_fx( den ) ); @@ -1872,7 +1872,7 @@ void TonalMDCTConceal_InsertNoise_ivas_fx( FOR( i = 0; i < crossOverFreq; i++ ) { - mdctSpectrum[i] = Mpy_32_16_1( mdctSpectrum[i], tmp ); + mdctSpectrum[i] = Mpy_32_16_1( mdctSpectrum[i], tmp ); // Q31-(*mdctSpectrum_exp+exp) move32(); } *mdctSpectrum_exp = add( *mdctSpectrum_exp, exp ); @@ -1914,20 +1914,20 @@ void TonalMDCTConceal_InsertNoise_ivas_fx( IF( nrgWhiteNoise > 0 ) { ld = norm_l( nrgNoiseInLastFrame ); - nrgNoiseInLastFrame = L_shl( nrgNoiseInLastFrame, ld ); + nrgNoiseInLastFrame = L_shl( nrgNoiseInLastFrame, ld ); // Q31- exp_last + ld exp_last = sub( exp_last, ld ); ld = norm_l( nrgWhiteNoise ); - nrgWhiteNoise = L_shl( nrgWhiteNoise, ld ); + nrgWhiteNoise = L_shl( nrgWhiteNoise, ld ); // Q31 - exp_noise + ld exp_noise = sub( exp_noise, ld ); exp = sub( exp_last, exp_noise ); IF( GT_32( nrgNoiseInLastFrame, nrgWhiteNoise ) ) { - nrgNoiseInLastFrame = L_shr( nrgNoiseInLastFrame, 1 ); + nrgNoiseInLastFrame = L_shr( nrgNoiseInLastFrame, 1 ); // Q31-exp -1 exp = add( exp, 1 ); } - tmp = div_l( nrgNoiseInLastFrame, round_fx( nrgWhiteNoise ) ); + tmp = div_l( nrgNoiseInLastFrame, round_fx( nrgWhiteNoise ) ); // Q15 tmp = Sqrt16( tmp, &exp ); g = mult_r( g, tmp ); // exponent of g = exp @@ -1937,13 +1937,13 @@ void TonalMDCTConceal_InsertNoise_ivas_fx( IF( exp > 0 ) { - g = shr( g, exp ); + g = shr( g, exp ); // Q15 - exp *mdctSpectrum_exp = hTonalMDCTConc->lastBlockData.spectralData_exp; move16(); } ELSE { - crossfadeGain = shl( crossfadeGain, exp ); + crossfadeGain = shl( crossfadeGain, exp ); // Q15-e_crossfadeGain+ exp e_crossfadeGain = sub( e_crossfadeGain, exp ); *mdctSpectrum_exp = add( e_crossfadeGain, hTonalMDCTConc->lastBlockData.spectralData_exp ); move16(); @@ -1964,29 +1964,29 @@ void TonalMDCTConceal_InsertNoise_ivas_fx( } FOR( i = 0; i < crossOverFreq; i++ ) { - Word16 const x = hTonalMDCTConc->lastBlockData.spectralData[i]; + Word16 const x = hTonalMDCTConc->lastBlockData.spectralData[i]; // Q15 - spectralData_exp move16(); - Word32 const y = mdctSpectrum[i]; + Word32 const y = mdctSpectrum[i]; // Q31-mdctSpectrum_exp move32(); IF( g > 0 ) { - L_tmp = Mpy_32_16_1( y, g ); + L_tmp = Mpy_32_16_1( y, g ); // Q31-mdctSpectrum_exp- spectralData_exp } - L_tmp2 = L_msu( L_tmp, crossfadeGain, x ); + 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 ); + L_tmp2 = L_mac( L_tmp, crossfadeGain, x ); // Q15 - e_crossfadeGain + Q15 - spectralData_exp } - mdctSpectrum[i] = L_shl( L_tmp2, exp ); + mdctSpectrum[i] = L_shl( L_tmp2, exp ); // Q15 - e_crossfadeGain + Q15 - spectralData_exp + exp move32(); } } exp = sub( hTonalMDCTConc->lastBlockData.spectralData_exp, sub( *mdctSpectrum_exp, 16 ) ); FOR( i = crossOverFreq; i < hTonalMDCTConc->lastBlockData.nSamples; i++ ) { - mdctSpectrum[i] = L_shl( L_deposit_l( hTonalMDCTConc->lastBlockData.spectralData[i] ), exp ); + mdctSpectrum[i] = L_shl( L_deposit_l( hTonalMDCTConc->lastBlockData.spectralData[i] ), exp ); // Q15 - spectralData_exp + exp move32(); } } @@ -2002,12 +2002,12 @@ ELSE fac = shr( -32768, ld ); FOR( l = 0; l < hTonalMDCTConc->pTCI->lowerIndex[0]; l++ ) { - Word16 x = hTonalMDCTConc->lastBlockData.spectralData[l]; + Word16 x = hTonalMDCTConc->lastBlockData.spectralData[l]; // Q15 - spectralData_exp move16(); Word32 y; - rnd = extract_l( L_mac0( 13849, rnd, 31821 ) ); - y = L_mult( tilt, rnd ); // 15Q16 + rnd = extract_l( L_mac0( 13849, rnd, 31821 ) ); // Q0 + y = L_mult( tilt, rnd ); // 15Q16 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 @@ -2036,12 +2036,12 @@ ELSE } FOR( l = hTonalMDCTConc->pTCI->upperIndex[i - 1] + 1; l < hTonalMDCTConc->pTCI->lowerIndex[i]; l++ ) { - Word16 x = hTonalMDCTConc->lastBlockData.spectralData[l]; + Word16 x = hTonalMDCTConc->lastBlockData.spectralData[l]; // Q15 - spectralData_exp move16(); Word32 y; - rnd = extract_l( L_mac0( 13849, rnd, 31821 ) ); - y = L_mult( tilt, rnd ); + rnd = extract_l( L_mac0( 13849, rnd, 31821 ) ); // Q0 + y = L_mult( tilt, rnd ); // 15Q16 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 @@ -2067,20 +2067,20 @@ ELSE FOR( l = add( hTonalMDCTConc->pTCI->upperIndex[hTonalMDCTConc->pTCI->numIndexes - 1], 1 ); l < crossOverFreq; l++ ) { - Word16 x = hTonalMDCTConc->lastBlockData.spectralData[l]; + Word16 x = hTonalMDCTConc->lastBlockData.spectralData[l]; // Q15 - spectralData_exp move16(); Word32 y; - rnd = extract_l( L_mac0( 13849, rnd, 31821 ) ); - y = L_mult( tilt, rnd ); + rnd = extract_l( L_mac0( 13849, rnd, 31821 ) ); // Q0 + y = L_mult( tilt, rnd ); // 15Q16 - nrgNoiseInLastFrame = L_add( nrgNoiseInLastFrame, Mpy_32_16_1( L_msu( 0, x, fac ), x ) ); - x = round_fx( y ); - nrgWhiteNoise = L_add( nrgWhiteNoise, Mpy_32_16_1( L_msu( 0, x, fac ), x ) ); + 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) mdctSpectrum[l] = y; /* 15Q16 L_deposit_l(y);*/ move32(); - tilt = mult_r( tilt, tiltFactor ); + tilt = mult_r( tilt, tiltFactor ); // Q15 } IF( EQ_32( nrgNoiseInLastFrame, 0 ) ) @@ -2095,17 +2095,17 @@ ELSE exp_noise = add( ld, shl( 15, 1 ) ); ld = norm_l( nrgNoiseInLastFrame ); - nrgNoiseInLastFrame = L_shl( nrgNoiseInLastFrame, ld ); + nrgNoiseInLastFrame = L_shl( nrgNoiseInLastFrame, ld ); // Q31-exp_last+ld exp_last = sub( exp_last, ld ); ld = norm_l( nrgWhiteNoise ); - nrgWhiteNoise = L_shl( nrgWhiteNoise, ld ); + nrgWhiteNoise = L_shl( nrgWhiteNoise, ld ); // Q31 - exp_noise + ld exp_noise = sub( exp_noise, ld ); exp = sub( exp_last, exp_noise ); IF( GT_32( nrgNoiseInLastFrame, nrgWhiteNoise ) ) { - nrgNoiseInLastFrame = L_shr( nrgNoiseInLastFrame, 1 ); + nrgNoiseInLastFrame = L_shr( nrgNoiseInLastFrame, 1 ); // Q31 - Qexp -1 exp = add( exp, 1 ); } tmp = div_l( nrgNoiseInLastFrame, extract_h( nrgWhiteNoise ) ); @@ -2117,7 +2117,7 @@ ELSE exp = sub( ld, exp ); IF( exp > 0 ) { - g = shr( g, exp ); + g = shr( g, exp ); // Q15 - exp *mdctSpectrum_exp = hTonalMDCTConc->lastBlockData.spectralData_exp; move16(); } @@ -2144,22 +2144,22 @@ ELSE FOR( l = 0; l < hTonalMDCTConc->pTCI->lowerIndex[0]; l++ ) { - Word16 const x = hTonalMDCTConc->lastBlockData.spectralData[l]; + Word16 const x = hTonalMDCTConc->lastBlockData.spectralData[l]; // Q15 - spectralData_exp move16(); - Word32 const y = mdctSpectrum[l]; + Word32 const y = mdctSpectrum[l]; // Q31-mdctSpectrum_exp move32(); - IF( GT_16( g, 0 ) ) + IF( g > 0 ) { - L_tmp = Mpy_32_16_1( y, g ); + L_tmp = Mpy_32_16_1( y, g ); // Q31-mdctSpectrum_exp- spectralData_exp } - L_tmp2 = L_msu( L_tmp, crossfadeGain, x ); - IF( GT_32( y, 0 ) ) + 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 ); + L_tmp2 = L_mac( L_tmp, crossfadeGain, x ); // Q15 - e_crossfadeGain + Q15 - spectralData_exp } - mdctSpectrum[l] = L_shl( L_tmp2, exp ); + mdctSpectrum[l] = L_shl( L_tmp2, exp ); // Q15 - e_crossfadeGain + Q15 - spectralData_exp + exp move32(); } @@ -2167,22 +2167,22 @@ ELSE { FOR( l = hTonalMDCTConc->pTCI->upperIndex[i - 1] + 1; l < hTonalMDCTConc->pTCI->lowerIndex[i]; l++ ) { - Word16 const x = hTonalMDCTConc->lastBlockData.spectralData[l]; + Word16 const x = hTonalMDCTConc->lastBlockData.spectralData[l]; // Q15 - spectralData_exp move16(); - Word32 const y = mdctSpectrum[l]; + Word32 const y = mdctSpectrum[l]; // Q31-mdctSpectrum_exp move32(); - IF( GT_16( g, 0 ) ) + IF( g > 0 ) { - L_tmp = Mpy_32_16_1( y, g ); + L_tmp = Mpy_32_16_1( y, g ); // Q31-mdctSpectrum_exp- spectralData_exp } - L_tmp2 = L_msu( L_tmp, crossfadeGain, x ); - IF( GT_32( y, 0 ) ) + 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 ); + L_tmp2 = L_mac( L_tmp, crossfadeGain, x ); // Q15 - e_crossfadeGain + Q15 - spectralData_exp } - mdctSpectrum[l] = L_shl( L_tmp2, exp ); + mdctSpectrum[l] = L_shl( L_tmp2, exp ); // Q15 - e_crossfadeGain + Q15 - spectralData_exp + exp move32(); } } @@ -2202,29 +2202,29 @@ ELSE FOR( l = add( hTonalMDCTConc->pTCI->upperIndex[hTonalMDCTConc->pTCI->numIndexes - 1], 1 ); l < crossOverFreq; l++ ) { - Word16 const x = hTonalMDCTConc->lastBlockData.spectralData[l]; + Word16 const x = hTonalMDCTConc->lastBlockData.spectralData[l]; // Q15 - spectralData_exp move16(); - Word32 const y = mdctSpectrum[l]; + Word32 const y = mdctSpectrum[l]; // Q31-mdctSpectrum_exp move32(); IF( GT_16( g, 0 ) ) { - L_tmp = Mpy_32_16_1( y, g ); + L_tmp = Mpy_32_16_1( y, g ); // Q31-mdctSpectrum_exp- spectralData_exp } - L_tmp2 = L_msu( L_tmp, crossfadeGain, x ); + 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 ); + L_tmp2 = L_mac( L_tmp, crossfadeGain, x ); // Q15 - e_crossfadeGain + Q15 - spectralData_exp } - mdctSpectrum[l] = L_shl( L_tmp2, exp ); + 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 ); + mdctSpectrum[l] = L_shl( L_deposit_l( hTonalMDCTConc->lastBlockData.spectralData[l] ), exp ); // Q15 - spectralData_exp move32(); } } @@ -2241,12 +2241,12 @@ return; void TonalMDCTConceal_InsertNoise( const TonalMDCTConcealPtr hTonalMDCTConc, /*IN */ - Word32 *mdctSpectrum, /*OUT*/ + Word32 *mdctSpectrum, // Q31- *mdctSpectrum_exp /*OUT*/ Word16 *mdctSpectrum_exp, /*OUT*/ const Word16 tonalConcealmentActive, - Word16 *pSeed, /*IN/OUT*/ - const Word16 tiltCompFactor, - Word16 crossfadeGain, + Word16 *pSeed, /*IN/OUT*/ + const Word16 tiltCompFactor, // Q15 + Word16 crossfadeGain, // Q15 #ifdef IVAS_CODE_CNG_FIX185_PLC_FADEOUT const Word16concealment_noise[L_FRAME48k], const float cngLevelBackgroundTrace_bfi, @@ -2488,7 +2488,7 @@ void TonalMDCTConceal_InsertNoise( tiltFactor = round_fx( BASOP_Util_fPow( L_max( L_tmp, L_deposit_h( tiltCompFactor ) ), 0, L_deposit_h( inv_samples ), inv_exp, &exp ) ); BASOP_SATURATE_WARNING_OFF_EVS /*next op may result in 32768*/ #ifdef BASOP_NOGLOB - tiltFactor = shl_sat( tiltFactor, exp ); + tiltFactor = shl_sat( tiltFactor, exp ); // Q15- 2*exp #else tiltFactor = shl( tiltFactor, exp ); #endif @@ -2510,20 +2510,20 @@ void TonalMDCTConceal_InsertNoise( FOR( i = 0; i < crossOverFreq; i++ ) { - Word16 x = hTonalMDCTConc->lastBlockData.spectralData[i]; + Word16 x = hTonalMDCTConc->lastBlockData.spectralData[i]; // Q15 - spectralData_exp move16(); Word32 y; - rnd = extract_l( L_mac0( 13849, rnd, 31821 ) ); - y = L_mult( tilt, rnd ); + rnd = extract_l( L_mac0( 13849, rnd, 31821 ) ); // Q0 + y = L_mult( tilt, rnd ); /* 15Q16 */ - nrgNoiseInLastFrame = L_add( nrgNoiseInLastFrame, Mpy_32_16_1( L_msu( 0, x, fac ), x ) ); - x = round_fx( y ); - nrgWhiteNoise = L_add( nrgWhiteNoise, Mpy_32_16_1( L_msu( 0, x, fac ), x ) ); + 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) mdctSpectrum[i] = y; /* 15Q16 */ move32(); - tilt = mult_r( tilt, tiltFactor ); + tilt = mult_r( tilt, tiltFactor ); // Q15 } IF( nrgNoiseInLastFrame == 0 ) @@ -2540,17 +2540,17 @@ void TonalMDCTConceal_InsertNoise( IF( nrgWhiteNoise > 0 ) { ld = norm_l( nrgNoiseInLastFrame ); - nrgNoiseInLastFrame = L_shl( nrgNoiseInLastFrame, ld ); + nrgNoiseInLastFrame = L_shl( nrgNoiseInLastFrame, ld ); // Q31-exp_last + ld exp_last = sub( exp_last, ld ); ld = norm_l( nrgWhiteNoise ); - nrgWhiteNoise = L_shl( nrgWhiteNoise, ld ); + nrgWhiteNoise = L_shl( nrgWhiteNoise, ld ); // Q31-exp_noise + ld exp_noise = sub( exp_noise, ld ); exp = sub( exp_last, exp_noise ); IF( GT_32( nrgNoiseInLastFrame, nrgWhiteNoise ) ) { - nrgNoiseInLastFrame = L_shr( nrgNoiseInLastFrame, 1 ); + nrgNoiseInLastFrame = L_shr( nrgNoiseInLastFrame, 1 ); // Q31- exp - 1 exp = add( exp, 1 ); } tmp = div_l( nrgNoiseInLastFrame, round_fx( nrgWhiteNoise ) ); @@ -2591,27 +2591,27 @@ void TonalMDCTConceal_InsertNoise( { Word16 const x = hTonalMDCTConc->lastBlockData.spectralData[i]; move16(); - Word32 const y = mdctSpectrum[i]; + Word32 const y = mdctSpectrum[i]; // Q31-mdctSpectrum_exp move32(); if ( g > 0 ) { - L_tmp = Mpy_32_16_1( y, g ); + L_tmp = Mpy_32_16_1( y, g ); // Q31-mdctSpectrum_exp- spectralData_exp } - L_tmp2 = L_msu( L_tmp, crossfadeGain, x ); + 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 ); + L_tmp2 = L_mac( L_tmp, crossfadeGain, x ); // Q15 - e_crossfadeGain + Q15 - spectralData_exp } - mdctSpectrum[i] = L_shl( L_tmp2, exp ); + mdctSpectrum[i] = L_shl( L_tmp2, exp ); // Q15 - e_crossfadeGain + Q15 - spectralData_exp + exp move32(); } } exp = sub( hTonalMDCTConc->lastBlockData.spectralData_exp, sub( *mdctSpectrum_exp, 16 ) ); FOR( i = crossOverFreq; i < hTonalMDCTConc->lastBlockData.nSamples; i++ ) { - mdctSpectrum[i] = L_shl( L_deposit_l( hTonalMDCTConc->lastBlockData.spectralData[i] ), exp ); + mdctSpectrum[i] = L_shl( L_deposit_l( hTonalMDCTConc->lastBlockData.spectralData[i] ), exp ); // Q15 - spectralData_exp + exp move32(); } } @@ -2630,20 +2630,20 @@ void TonalMDCTConceal_InsertNoise( fac = shr( -32768, ld ); FOR( l = 0; l < hTonalMDCTConc->pTCI->lowerIndex[0]; l++ ) { - Word16 x = hTonalMDCTConc->lastBlockData.spectralData[l]; + Word16 x = hTonalMDCTConc->lastBlockData.spectralData[l]; // Q15 - spectralData_exp move16(); Word32 y; - rnd = extract_l( L_mac0( 13849, rnd, 31821 ) ); - y = L_mult( tilt, rnd ); + rnd = extract_l( L_mac0( 13849, rnd, 31821 ) ); // Q0 + y = L_mult( tilt, rnd ); // 15Q16 - nrgNoiseInLastFrame = L_add( nrgNoiseInLastFrame, Mpy_32_16_1( L_msu( 0, x, fac ), x ) ); - x = round_fx( y ); - nrgWhiteNoise = L_add( nrgWhiteNoise, Mpy_32_16_1( L_msu( 0, x, fac ), x ) ); + 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) mdctSpectrum[l] = y; /* 15Q16 L_deposit_l(y);*/ move32(); - tilt = mult_r( tilt, tiltFactor ); + tilt = mult_r( tilt, tiltFactor ); // Q15 } FOR( i = 1; i < hTonalMDCTConc->pTCI->numIndexes; i++ ) @@ -2661,27 +2661,27 @@ void TonalMDCTConceal_InsertNoise( FOR( l = hTonalMDCTConc->pTCI->upperIndex[i - 1] + 1; l < hTonalMDCTConc->pTCI->lowerIndex[i]; l++ ) { - Word16 x = hTonalMDCTConc->lastBlockData.spectralData[l]; + Word16 x = hTonalMDCTConc->lastBlockData.spectralData[l]; // Q15 - spectralData_exp move16(); Word32 y; - rnd = extract_l( L_mac0( 13849, rnd, 31821 ) ); - y = L_mult( tilt, rnd ); + rnd = extract_l( L_mac0( 13849, rnd, 31821 ) ); // Q0 + y = L_mult( tilt, rnd ); // 15Q16 - nrgNoiseInLastFrame = L_add( nrgNoiseInLastFrame, Mpy_32_16_1( L_msu( 0, x, fac ), x ) ); - x = round_fx( y ); - nrgWhiteNoise = L_add( nrgWhiteNoise, Mpy_32_16_1( L_msu( 0, x, fac ), x ) ); + 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) mdctSpectrum[l] = y; /* 15Q16 L_deposit_l(y);*/ move32(); - tilt = mult_r( tilt, tiltFactor ); + tilt = mult_r( tilt, tiltFactor ); // Q15 } } tmp = round_fx( BASOP_Util_fPow( L_deposit_h( tiltFactor ), 0, L_deposit_h( (UWord16) 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*/ #ifdef BASOP_NOGLOB - tmp = shl_sat( tmp, exp ); + tmp = shl_sat( tmp, exp ); // Q15 - 2*exp #else tmp = shl( tmp, exp ); #endif @@ -2690,20 +2690,20 @@ void TonalMDCTConceal_InsertNoise( FOR( l = add( hTonalMDCTConc->pTCI->upperIndex[hTonalMDCTConc->pTCI->numIndexes - 1], 1 ); l < crossOverFreq; l++ ) { - Word16 x = hTonalMDCTConc->lastBlockData.spectralData[l]; + Word16 x = hTonalMDCTConc->lastBlockData.spectralData[l]; // Q15 - spectralData_exp move16(); Word32 y; - rnd = extract_l( L_mac0( 13849, rnd, 31821 ) ); - y = L_mult( tilt, rnd ); + rnd = extract_l( L_mac0( 13849, rnd, 31821 ) ); // Q0 + y = L_mult( tilt, rnd ); // 15Q16 - nrgNoiseInLastFrame = L_add( nrgNoiseInLastFrame, Mpy_32_16_1( L_msu( 0, x, fac ), x ) ); - x = round_fx( y ); - nrgWhiteNoise = L_add( nrgWhiteNoise, Mpy_32_16_1( L_msu( 0, x, fac ), x ) ); + 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) mdctSpectrum[l] = y; /* 15Q16 L_deposit_l(y);*/ move32(); - tilt = mult_r( tilt, tiltFactor ); + tilt = mult_r( tilt, tiltFactor ); // Q15 } IF( nrgNoiseInLastFrame == 0 ) @@ -2718,17 +2718,17 @@ void TonalMDCTConceal_InsertNoise( exp_noise = add( ld, shl( 15, 1 ) ); ld = norm_l( nrgNoiseInLastFrame ); - nrgNoiseInLastFrame = L_shl( nrgNoiseInLastFrame, ld ); + nrgNoiseInLastFrame = L_shl( nrgNoiseInLastFrame, ld ); // Q31 - exp_last + ld exp_last = sub( exp_last, ld ); ld = norm_l( nrgWhiteNoise ); - nrgWhiteNoise = L_shl( nrgWhiteNoise, ld ); + nrgWhiteNoise = L_shl( nrgWhiteNoise, ld ); // Q31 - exp_last + ld exp_noise = sub( exp_noise, ld ); exp = sub( exp_last, exp_noise ); IF( GT_32( nrgNoiseInLastFrame, nrgWhiteNoise ) ) { - nrgNoiseInLastFrame = L_shr( nrgNoiseInLastFrame, 1 ); + nrgNoiseInLastFrame = L_shr( nrgNoiseInLastFrame, 1 ); // Q31 - exp -1 exp = add( exp, 1 ); } tmp = div_l( nrgNoiseInLastFrame, round_fx( nrgWhiteNoise ) ); @@ -2766,22 +2766,22 @@ void TonalMDCTConceal_InsertNoise( FOR( l = 0; l < hTonalMDCTConc->pTCI->lowerIndex[0]; l++ ) { - Word16 const x = hTonalMDCTConc->lastBlockData.spectralData[l]; + Word16 const x = hTonalMDCTConc->lastBlockData.spectralData[l]; // Q15 - spectralData_exp move16(); - Word32 const y = mdctSpectrum[l]; + Word32 const y = mdctSpectrum[l]; // Q31-mdctSpectrum_exp move32(); if ( g > 0 ) { - L_tmp = Mpy_32_16_1( y, g ); + L_tmp = Mpy_32_16_1( y, g ); // Q31-mdctSpectrum_exp- spectralData_exp } - L_tmp2 = L_msu( L_tmp, crossfadeGain, x ); + 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 ); + L_tmp2 = L_mac( L_tmp, crossfadeGain, x ); // Q15 - e_crossfadeGain + Q15 - spectralData_exp } - mdctSpectrum[l] = L_shl( L_tmp2, exp ); + mdctSpectrum[l] = L_shl( L_tmp2, exp ); // Q15 - e_crossfadeGain + Q15 - spectralData_exp + exp move32(); } @@ -2789,22 +2789,22 @@ void TonalMDCTConceal_InsertNoise( { FOR( l = hTonalMDCTConc->pTCI->upperIndex[i - 1] + 1; l < hTonalMDCTConc->pTCI->lowerIndex[i]; l++ ) { - Word16 const x = hTonalMDCTConc->lastBlockData.spectralData[l]; + Word16 const x = hTonalMDCTConc->lastBlockData.spectralData[l]; // Q15 - spectralData_exp move16(); - Word32 const y = mdctSpectrum[l]; + Word32 const y = mdctSpectrum[l]; // Q31-mdctSpectrum_exp move32(); if ( g > 0 ) { - L_tmp = Mpy_32_16_1( y, g ); + L_tmp = Mpy_32_16_1( y, g ); // Q31-mdctSpectrum_exp- spectralData_exp } - L_tmp2 = L_msu( L_tmp, crossfadeGain, x ); + 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 ); + L_tmp2 = L_mac( L_tmp, crossfadeGain, x ); // Q15 - e_crossfadeGain + Q15 - spectralData_exp } - mdctSpectrum[l] = L_shl( L_tmp2, exp ); + mdctSpectrum[l] = L_shl( L_tmp2, exp ); // Q15 - e_crossfadeGain + Q15 - spectralData_exp + exp move32(); } } @@ -2824,29 +2824,29 @@ void TonalMDCTConceal_InsertNoise( FOR( l = add( hTonalMDCTConc->pTCI->upperIndex[hTonalMDCTConc->pTCI->numIndexes - 1], 1 ); l < crossOverFreq; l++ ) { - Word16 const x = hTonalMDCTConc->lastBlockData.spectralData[l]; + Word16 const x = hTonalMDCTConc->lastBlockData.spectralData[l]; // Q15 - spectralData_exp move16(); - Word32 const y = mdctSpectrum[l]; + Word32 const y = mdctSpectrum[l]; // Q31-mdctSpectrum_exp move32(); if ( g > 0 ) { - L_tmp = Mpy_32_16_1( y, g ); + L_tmp = Mpy_32_16_1( y, g ); // Q31-mdctSpectrum_exp- spectralData_exp } - L_tmp2 = L_msu( L_tmp, crossfadeGain, x ); + 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 ); + L_tmp2 = L_mac( L_tmp, crossfadeGain, x ); // Q15 - e_crossfadeGain + Q15 - spectralData_exp } - mdctSpectrum[l] = L_shl( L_tmp2, exp ); + 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 ); + mdctSpectrum[l] = L_shl( L_deposit_l( hTonalMDCTConc->lastBlockData.spectralData[l] ), exp ); // Q15 - spectralData_exp + exp move32(); } } @@ -2860,7 +2860,7 @@ void TonalMDCTConceal_InsertNoise( void TonalMDCTConceal_Apply( const TonalMDCTConcealPtr hTonalMDCTConc, /*IN */ - Word32 *mdctSpectrum, /*IN/OUT*/ + Word32 *mdctSpectrum, // Q31-*mdctSpectrum_exp /*IN/OUT*/ Word16 *mdctSpectrum_exp /*IN */ #ifdef IVAS_CODE_MDCT_GSHAPE , @@ -2964,7 +2964,7 @@ void TonalMDCTConceal_Apply( #ifdef IVAS_FLOAT_FIXED void TonalMDCTConceal_Apply_ivas_fx( TonalMDCTConcealPtr hTonalMDCTConc, /*IN */ - Word32 *mdctSpectrum, /*IN/OUT*/ + Word32 *mdctSpectrum, // Q31-*mdctSpectrum_exp /*IN/OUT*/ Word16 mdctSpectrum_exp[L_FRAME_MAX], /*IN */ const PsychoacousticParameters *psychParamsCurrent ) @@ -2990,7 +2990,7 @@ void TonalMDCTConceal_Apply_ivas_fx( /* Creating 32-bit scaleFactors with common exponent. */ FOR( i = 0; i < FDNS_NPTS; i++ ) { - scaleFactors[i] = L_shr( L_deposit_h( hTonalMDCTConc->secondLastBlockData.scaleFactors[i] ), sub( hTonalMDCTConc->secondLastBlockData.scaleFactors_max_e, hTonalMDCTConc->secondLastBlockData.scaleFactors_exp[i] ) ); + scaleFactors[i] = L_shr( L_deposit_h( hTonalMDCTConc->secondLastBlockData.scaleFactors[i] ), sub( hTonalMDCTConc->secondLastBlockData.scaleFactors_max_e, hTonalMDCTConc->secondLastBlockData.scaleFactors_exp[i] ) ); // Q31- scaleFactors_max_e+scaleFactors_exp[i] move32(); } @@ -3004,7 +3004,7 @@ void TonalMDCTConceal_Apply_ivas_fx( FOR( i = 0; i < nSamples; i++ ) { - powerSpectrum[i] = L_deposit_h( tmp_secondLastPowerSpectrum[i] ); + powerSpectrum[i] = L_deposit_h( tmp_secondLastPowerSpectrum[i] ); // Q31 - secondLastPowerSpectrum_exp move16(); } powerSpectrum_exp = tmp_secondLastPowerSpectrum_exp; @@ -3030,7 +3030,7 @@ void TonalMDCTConceal_Apply_ivas_fx( q_ps = sub( q_ps, 1 ); FOR( Word16 c = 0; c < hTonalMDCTConc->nSamplesCore; c++ ) { - powerSpectrum[c] = L_shr( powerSpectrum[c], 1 ); + powerSpectrum[c] = L_shr( powerSpectrum[c], 1 ); // q_ps -1 move32(); } @@ -3038,7 +3038,7 @@ void TonalMDCTConceal_Apply_ivas_fx( q_sf = sub( q_sf, 1 ); FOR( Word16 c = 0; c < FDNS_NPTS; c++ ) { - scaleFactors[c] = L_shr( scaleFactors[c], 1 ); + scaleFactors[c] = L_shr( scaleFactors[c], 1 ); // q_sf - 1 move32(); } @@ -3057,7 +3057,7 @@ void TonalMDCTConceal_Apply_ivas_fx( FOR( Word16 c = hTonalMDCTConc->nSamplesCore; c < nSamples; c++ ) { - powerSpectrum[c] = Mpy_32_16_1( powerSpectrum[c], hTonalMDCTConc->secondLastBlockData.scaleFactors[nBands - 1] ); + powerSpectrum[c] = Mpy_32_16_1( powerSpectrum[c], hTonalMDCTConc->secondLastBlockData.scaleFactors[nBands - 1] ); // Q31 -(exp_right + scaleFactors_exp[]) move32(); } exp_right = add( exp_right, hTonalMDCTConc->secondLastBlockData.scaleFactors_exp[nBands - 1] ); @@ -3071,12 +3071,12 @@ void TonalMDCTConceal_Apply_ivas_fx( test(); IF( GE_16( c, hTonalMDCTConc->nSamplesCore ) && LT_16( c, nSamples ) && GT_16( max_e, exp_right ) ) { - powerSpectrum[c] = L_shr( powerSpectrum[c], sub( max_e, exp_right ) ); + powerSpectrum[c] = L_shr( powerSpectrum[c], sub( max_e, exp_right ) ); // Q31-max_e move32(); } ELSE IF( ( LT_16( c, hTonalMDCTConc->nSamplesCore ) || GT_16( c, nSamples ) ) && GT_16( max_e, exp_left ) ) { - powerSpectrum[c] = L_shr( powerSpectrum[c], sub( max_e, exp_left ) ); + powerSpectrum[c] = L_shr( powerSpectrum[c], sub( max_e, exp_left ) ); // Q31-max_e move32(); } } @@ -3146,7 +3146,7 @@ void TonalMDCTConceal_Apply_ivas_fx( void TonalMDCTConceal_SaveTimeSignal( TonalMDCTConcealPtr hTonalMDCTConc, - Word16 *timeSignal, + Word16 *timeSignal, // Qx Word16 nNewSamples ) @@ -3164,13 +3164,13 @@ void TonalMDCTConceal_SaveTimeSignal( return; } static void CalcPowerSpec( - const Word32 *mdctSpec, /* i: MDCT spectrum Q31,mdctSpec_exp */ + const Word32 *mdctSpec, /* i: MDCT spectrum Q31-mdctSpec_exp */ const Word16 mdctSpec_exp, /* i: exponent of MDCT spectrum */ - const Word32 *mdstSpec, /* i: MDST spectrum Q31,mdstSpec_exp */ + const Word32 *mdstSpec, /* i: MDST spectrum Q31-mdstSpec_exp */ const Word16 mdstSpec_exp, /* i: exponent of MDST spectrum */ const Word16 nSamples, /* i: frame size */ const Word16 floorPowerSpectrum, /* i: lower limit for power spectrum bins Q0 */ - Word32 *powerSpec, /* o: power spectrum */ + Word32 *powerSpec, /* o: power spectrum Q31- powerSpec_exp */ Word16 *powerSpec_exp ) /* o: exponent of power spectrum */ { Word16 k, s1, s2, tmp; diff --git a/lib_dec/transition_dec_fx.c b/lib_dec/transition_dec_fx.c index 73342e64c..ab6a76cac 100644 --- a/lib_dec/transition_dec_fx.c +++ b/lib_dec/transition_dec_fx.c @@ -37,19 +37,19 @@ static void tc_dec_fx( Decoder_State *st_fx, const Word16 L_frame, Word16 exc[], void transition_dec_fx( Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ - const Word16 L_frame, /* i : length of the frame */ - const Word16 i_subfr, /* i : subframe index */ - const Word16 tc_subfr, /* i : TC subframe index */ - Word16 *Jopt_flag, /* i : joint optimization flag */ - Word16 *exc, /* o : excitation signal */ - Word16 *T0, /* o : close loop integer pitch */ - Word16 *T0_frac, /* o : close loop fractional part of the pitch */ - Word16 *T0_min, /* i/o: delta search min for sf 2 & 4 */ - Word16 *T0_max, /* i/o: delta search max for sf 2 & 4 */ - Word16 **pt_pitch, /* o : floating pitch values */ - Word16 *position, /* i/o: first glottal impulse position in frame */ - Word16 *bwe_exc, /* o : excitation for SWB TBE */ + const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode Q0 */ + const Word16 L_frame, /* i : length of the frame Q0 */ + const Word16 i_subfr, /* i : subframe index Q0 */ + const Word16 tc_subfr, /* i : TC subframe index Q0 */ + Word16 *Jopt_flag, /* i : joint optimization flag Q0*/ + Word16 *exc, /* o : excitation signal Q0 */ + Word16 *T0, /* o : close loop integer pitch Q0 */ + Word16 *T0_frac, /* o : close loop fractional part of the pitch Q0*/ + Word16 *T0_min, /* i/o: delta search min for sf 2 & 4 Q0 */ + Word16 *T0_max, /* i/o: delta search max for sf 2 & 4 Q0 */ + Word16 **pt_pitch, /* o : floating pitch values Q6 */ + Word16 *position, /* i/o: first glottal impulse position in frame Q0*/ + Word16 *bwe_exc, /* o : excitation for SWB TBE Q_exc */ Word16 *Q_exc /*i/o : scaling of excitation */ ) { @@ -110,8 +110,8 @@ void transition_dec_fx( /* glottal shape codebook contribution construction */ tc_dec_fx( st_fx, L_frame, exc, T0, T0_frac, i_subfr, tc_subfr, position, bwe_exc, Q_exc ); - **pt_pitch = shl( add( shl( *T0, 2 ), *T0_frac ), 4 ); - move16(); /* save subframe pitch values Q6 */ + **pt_pitch = shl( add( shl( *T0, 2 ), *T0_frac ), 4 ); // Q6 + move16(); /* save subframe pitch values Q6 */ *Jopt_flag = 1; move16(); @@ -620,14 +620,14 @@ void transition_dec_fx( static void tc_dec_fx( Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word16 L_frame, /* i : length of the frame */ - Word16 exc[], /* o : glottal codebook contribution */ - Word16 *T0, /* o : close-loop pitch period */ - Word16 *T0_frac, /* o : close-loop pitch period - fractional part */ - const Word16 i_subfr, /* i : subframe index */ - const Word16 tc_subfr, /* i : TC subframe index */ - Word16 *position, /* o : first glottal impulse position in frame */ - Word16 bwe_exc[], /* o : excitation for SWB TBE */ + const Word16 L_frame, /* i : length of the frame Q0*/ + Word16 exc[], /* o : glottal codebook contribution Q0*/ + Word16 *T0, /* o : close-loop pitch period Q0 */ + Word16 *T0_frac, /* o : close-loop pitch period - fractional part Q0 */ + const Word16 i_subfr, /* i : subframe index Q0*/ + const Word16 tc_subfr, /* i : TC subframe index Q0 */ + Word16 *position, /* o : first glottal impulse position in frame Q0*/ + Word16 bwe_exc[], /* o : excitation for SWB TBE Q_exc */ Word16 *Q_exc /*i/o : scaling of excitation */ ) { @@ -829,9 +829,9 @@ return; * TC subframe classification decoding *-------------------------------------------------------------------*/ -Word16 tc_classif_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word16 L_frame /* i : length of the frame */ +Word16 tc_classif_fx( /*o: Q0*/ + Decoder_State *st_fx, /* i/o: decoder state structure */ + const Word16 L_frame /* i : length of the frame Q0 */ ) { Word16 tc_subfr, indice; diff --git a/lib_dec/updt_dec_fx.c b/lib_dec/updt_dec_fx.c index 4c8df0899..d21bde643 100644 --- a/lib_dec/updt_dec_fx.c +++ b/lib_dec/updt_dec_fx.c @@ -17,14 +17,14 @@ *-------------------------------------------------------------------*/ void updt_dec_fx( Decoder_State *st_fx, /* i/o: state structure */ - const Word16 *old_exc_fx, /* i : buffer of excitation */ - const Word16 *pitch_buf_fx, /* i : fixed point pitch values for each subframe */ - const Word16 Es_pred, /* i : predicited scaled innovation energy */ - const Word16 *Aq, /* i : A(z) quantized for all subframes */ - const Word16 *lsf_new_fx, /* i : current frame LSF vector */ - const Word16 *lsp_new_fx, /* i : current frame LSP vector */ - const Word16 voice_factors[], /* i : voicing factors */ - const Word16 *old_bwe_exc_fx, /* i : buffer of excitation */ + const Word16 *old_exc_fx, /* i : buffer of excitation Q_exc */ + const Word16 *pitch_buf_fx, /* i : fixed point pitch values for each subframe Q6*/ + const Word16 Es_pred, /* i : predicited scaled innovation energy Q8*/ + const Word16 *Aq, /* i : A(z) quantized for all subframes Q12 */ + const Word16 *lsf_new_fx, /* i : current frame LSF vector Qlog2(2.56)*/ + const Word16 *lsp_new_fx, /* i : current frame LSP vector Q15*/ + const Word16 voice_factors[], /* i : voicing factors Q15*/ + const Word16 *old_bwe_exc_fx, /* i : buffer of excitation Q_syn*/ const Word16 *gain_buf /* i : fixed point pitch gain for each subframe Q14*/ ) { @@ -85,7 +85,7 @@ void updt_dec_fx( /* overwrite previous coding type to help FEC */ st_fx->last_coder_type = UNVOICED; move16(); - st_fx->last_voice_factor_fx = voice_factors[NB_SUBFR - 1]; + st_fx->last_voice_factor_fx = voice_factors[NB_SUBFR - 1]; // Q15 move16(); } @@ -131,32 +131,32 @@ void updt_dec_fx( Copy32( &st_fx->old_pitch_buf_fx[len], st_fx->old_pitch_buf_fx, len ); FOR( i = 0; i < len; i++ ) { - st_fx->old_pitch_buf_fx[len + i] = L_mult0( pitch_buf_fx[i], 1 << 10 ); + st_fx->old_pitch_buf_fx[len + i] = L_mult0( pitch_buf_fx[i], 1 << 10 ); /* 15Q16 */ move32(); } Copy( &st_fx->mem_pitch_gain[2], &st_fx->mem_pitch_gain[add( st_fx->L_frame / L_SUBFR, 2 )], st_fx->L_frame / L_SUBFR ); IF( EQ_16( st_fx->L_frame, L_FRAME ) ) { - st_fx->mem_pitch_gain[2] = gain_buf[3]; + st_fx->mem_pitch_gain[2] = gain_buf[3]; // Q14 move16(); - st_fx->mem_pitch_gain[3] = gain_buf[2]; + st_fx->mem_pitch_gain[3] = gain_buf[2]; // Q14 move16(); - st_fx->mem_pitch_gain[4] = gain_buf[1]; + st_fx->mem_pitch_gain[4] = gain_buf[1]; // Q14 move16(); - st_fx->mem_pitch_gain[5] = gain_buf[0]; + st_fx->mem_pitch_gain[5] = gain_buf[0]; // Q14 move16(); } ELSE { - st_fx->mem_pitch_gain[2] = gain_buf[4]; + st_fx->mem_pitch_gain[2] = gain_buf[4]; // Q14 move16(); - st_fx->mem_pitch_gain[3] = gain_buf[3]; + st_fx->mem_pitch_gain[3] = gain_buf[3]; // Q14 move16(); - st_fx->mem_pitch_gain[4] = gain_buf[2]; + st_fx->mem_pitch_gain[4] = gain_buf[2]; // Q14 move16(); - st_fx->mem_pitch_gain[5] = gain_buf[1]; + st_fx->mem_pitch_gain[5] = gain_buf[1]; // Q14 move16(); - st_fx->mem_pitch_gain[6] = gain_buf[0]; + st_fx->mem_pitch_gain[6] = gain_buf[0]; // Q14 move16(); } @@ -268,7 +268,7 @@ void updt_IO_switch_dec_fx( fb_tbe_reset_synth_fx( hBWE_TD->fbbwe_hpf_mem_fx, hBWE_TD->fbbwe_hpf_mem_fx_Q, &hBWE_TD->prev_fbbwe_ratio_fx ); } hBWE_FD->prev_Energy_wb_fx = L_deposit_l( 0 ); - hBWE_FD->prev_weight_fx = 6554; + hBWE_FD->prev_weight_fx = 6554; /*0.2 in Q15*/ move16(); } @@ -294,7 +294,7 @@ void updt_IO_switch_dec_fx( /* reset the unvoiced/audio signal improvement memories */ if ( st_fx->hGSCDec != NULL ) { - st_fx->hGSCDec->seed_tcx = 15687; + st_fx->hGSCDec->seed_tcx = 15687; // Q0 move16(); } st_fx->hAmrwb_IO->UV_cnt_fx = 30; @@ -396,22 +396,22 @@ void updt_IO_switch_dec_fx( void updt_bw_switching_fx( Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word16 *synth, /* i : fixed point synthesis signal */ + const Word16 *synth, /* i : fixed point synthesis signal Qpost */ const Word16 Qpost ) { test(); IF( EQ_32( st_fx->output_Fs, 32000 ) && EQ_16( st_fx->bwidth, SWB ) ) { #ifdef BASOP_NOGLOB - st_fx->tilt_swb_fx = round_fx_sat( L_shl_sat( calc_tilt_bwe_fx( synth, Qpost, L_FRAME32k ), 3 ) ); + st_fx->tilt_swb_fx = round_fx_sat( L_shl_sat( calc_tilt_bwe_fx( synth, Qpost, L_FRAME32k ), 3 ) ); // Q27 - 16 = Q11 #else st_fx->tilt_swb_fx = round_fx( L_shl( calc_tilt_bwe_fx( synth, Qpost, L_FRAME32k ), 3 ) ); #endif } - st_fx->prev_enerLH_fx = st_fx->enerLH_fx; + st_fx->prev_enerLH_fx = st_fx->enerLH_fx; // enerLH_fx_Q move32(); - st_fx->prev_enerLL_fx = st_fx->enerLL_fx; + st_fx->prev_enerLL_fx = st_fx->enerLL_fx; // enerLL_fx_Q move32(); st_fx->last_bwidth = st_fx->bwidth; move32(); @@ -453,7 +453,7 @@ void updt_dec_common_fx( Decoder_State *st_fx, /* i/o: decoder state structure */ Word16 hq_core_type_fx, /* i : HQ core type */ const Word16 concealWholeFrameTmp, /* i : concealWholeFrameTmp flag */ - const Word16 *synth, /* i : decoded synthesis */ + const Word16 *synth, /* i : decoded synthesis Qpostd */ const Word16 Qpostd /* i : Synthesis Q value */ ) @@ -771,7 +771,7 @@ void updt_dec_common_fx( #ifdef IVAS_FLOAT_FIXED static void ivas_updt_bw_switching_fx( Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word32 *synth, /* i : fixed point synthesis signal */ + const Word32 *synth, /* i : fixed point synthesis signal Qpost */ const Word16 Qpost ) { test(); @@ -784,9 +784,9 @@ static void ivas_updt_bw_switching_fx( #endif } - st_fx->prev_enerLH_fx = st_fx->enerLH_fx; + st_fx->prev_enerLH_fx = st_fx->enerLH_fx; // enerLH_fx_Q move32(); - st_fx->prev_enerLL_fx = st_fx->enerLL_fx; + st_fx->prev_enerLL_fx = st_fx->enerLL_fx; // enerLL_fx_Q move32(); st_fx->last_bwidth = st_fx->bwidth; move32(); @@ -818,13 +818,13 @@ static void ivas_updt_bw_switching_fx( return; } -static Word32 sum_32_32_fx( const Word32 *x, Word16 length ) +static Word32 sum_32_32_fx( const Word32 *x, Word16 length ) // Qx { Word64 sum = 0; Word16 i; FOR( i = 0; i < length; i++ ) { - sum = W_add( sum, W_mult_32_32( x[i], x[i] ) ); + sum = W_add( sum, W_mult_32_32( x[i], x[i] ) ); // 2*Qx -1 } return W_round64_L( sum ); } @@ -833,7 +833,7 @@ void ivas_updt_dec_common_fx( Decoder_State *st_fx, /* i/o: decoder state structure */ Word16 hq_core_type_fx, /* i : HQ core type */ const Word16 concealWholeFrameTmp, /* i : concealWholeFrameTmp flag */ - const Word32 *synth, /* i : decoded synthesis Q(Qpostd) */ + const Word32 *synth, /* i : decoded synthesis Qpostd */ const Word16 Qpostd /* i : Synthesis Q value */ ) @@ -996,22 +996,22 @@ void ivas_updt_dec_common_fx( Word16 q_div = sub( Q31, shl( Qpostd, 1 ) ); Word16 output_frame = NS2SA_FX2( st_fx->output_Fs, FRAME_SIZE_NS ); move16(); - Word32 sum_val = sum_32_32_fx( synth, output_frame ); + Word32 sum_val = sum_32_32_fx( synth, output_frame ); // 2*Q_syn -1 Word32 div_val = BASOP_Util_Divide3232_Scale( sum_val, output_frame, &q_div ); Word32 log_energy = L_add( L_shl( L_deposit_l( add( q_div, sub( Q31, shl( Qpostd, 1 ) ) ) ), Q15 ), - L_shr( BASOP_Util_Log2( L_shl( L_add( div_val, EPSILON_FX ), Q16 ) ), Q10 ) ); - Word32 log_energy_diff = L_abs( L_sub( st_fx->log_energy_old_fx, log_energy ) ); - st_fx->log_energy_old_fx = log_energy; + L_shr( BASOP_Util_Log2( L_shl( L_add( div_val, EPSILON_FX ), Q16 ) ), Q10 ) ); // Q15 + Word32 log_energy_diff = L_abs( L_sub( st_fx->log_energy_old_fx, log_energy ) ); // Q15 + st_fx->log_energy_old_fx = log_energy; // Q15 move32(); - st_fx->log_energy_diff_lt_fx = Madd_32_16( Mpy_32_16_1( log_energy_diff, ENV_SMOOTH_FAC_FX ), st_fx->log_energy_diff_lt_fx, sub( MAX_16, ENV_SMOOTH_FAC_FX ) ); + st_fx->log_energy_diff_lt_fx = Madd_32_16( Mpy_32_16_1( log_energy_diff, ENV_SMOOTH_FAC_FX ), st_fx->log_energy_diff_lt_fx, sub( MAX_16, ENV_SMOOTH_FAC_FX ) ); // Q15 IF( EQ_16( st_fx->core, HQ_CORE ) ) { - st_fx->stab_fac_fx = extract_l( L_min( MAX_16, L_add( L_shr( STAB_FAC_EST1_FX, Q15 ), Madd_32_32( Mpy_32_16_1( STAB_FAC_EST2_FX, st_fx->hHQ_core->mem_env_delta ), STAB_FAC_EST3_FX, st_fx->log_energy_diff_lt_fx ) ) ) ); - st_fx->stab_fac_fx = s_max( 0, st_fx->stab_fac_fx ); + st_fx->stab_fac_fx = extract_l( L_min( MAX_16, L_add( L_shr( STAB_FAC_EST1_FX, Q15 ), Madd_32_32( Mpy_32_16_1( STAB_FAC_EST2_FX, st_fx->hHQ_core->mem_env_delta ), STAB_FAC_EST3_FX, st_fx->log_energy_diff_lt_fx ) ) ) ); // Q15 + st_fx->stab_fac_fx = s_max( 0, st_fx->stab_fac_fx ); // Q15 } st_fx->stab_fac_smooth_lt_fx = extract_h( L_add( L_mult( ENV_SMOOTH_FAC_FX, st_fx->stab_fac_fx ), - L_mult( sub( MAX_16, ENV_SMOOTH_FAC_FX ), st_fx->stab_fac_smooth_lt_fx ) ) ); + L_mult( sub( MAX_16, ENV_SMOOTH_FAC_FX ), st_fx->stab_fac_smooth_lt_fx ) ) ); // Q15 } #endif @@ -1209,9 +1209,10 @@ void ivas_updt_dec_common_fx( void update_decoder_LPD_cng( Decoder_State *st, Word16 coder_type, - Word16 *timeDomainBuffer, - Word16 *A, - Word16 *bpf_noise_buf ) + Word16 *timeDomainBuffer, /*QtimeDomainBuffer*/ + Word16 *A, /*Q12*/ + Word16 *bpf_noise_buf /*Qbpf_noise_buf*/ +) { Word16 i; Word16 lsp[M], lsf[M]; diff --git a/lib_dec/vlpc_1st_dec_fx.c b/lib_dec/vlpc_1st_dec_fx.c index ad2c3fc2c..cd79792c2 100644 --- a/lib_dec/vlpc_1st_dec_fx.c +++ b/lib_dec/vlpc_1st_dec_fx.c @@ -11,17 +11,17 @@ #ifdef IVAS_FLOAT_FIXED void vlpc_1st_dec( Word16 index, /* input: codebook index */ - Word16 *lsfq ) /* i/o: i:prediction o:quantized lsf */ + Word16 *lsfq ) /* i/o: i:prediction o:quantized lsf 14Q1*1.28 */ { Word16 i; const Word16 *p_dico; assert( index < 256 ); - p_dico = &dico_lsf_abs_8b[index * M]; + p_dico = &dico_lsf_abs_8b[index * M]; /*14Q1*1.28*/ FOR( i = 0; i < M; i++ ) { - lsfq[i] = add( lsfq[i], *p_dico ); + lsfq[i] = add( lsfq[i], *p_dico ); /*14Q1*1.28*/ move16(); p_dico++; } diff --git a/lib_dec/vlpc_2st_dec_fx.c b/lib_dec/vlpc_2st_dec_fx.c index 6aacd0974..74b53369c 100644 --- a/lib_dec/vlpc_2st_dec_fx.c +++ b/lib_dec/vlpc_2st_dec_fx.c @@ -12,7 +12,7 @@ #ifdef IVAS_FLOAT_FIXED void vlpc_2st_dec( - Word16 *lsfq, /* i/o: i:1st stage o:1st+2nd stage */ + Word16 *lsfq, /* i/o: i:1st stage o:1st+2nd stage 14Q1*1.28*/ Word16 *indx, /* i : index[] (4 bits per words) */ Word16 mode, /* i : 0=abs, >0=rel */ Word32 sr_core /* i : internal sampling rate */ diff --git a/lib_dec/voiced_dec_fx.c b/lib_dec/voiced_dec_fx.c index 761f904ea..c9ef8b473 100644 --- a/lib_dec/voiced_dec_fx.c +++ b/lib_dec/voiced_dec_fx.c @@ -43,11 +43,11 @@ /*===================================================================*/ ivas_error ppp_voiced_decoder_fx( Decoder_State *st_fx, /* i/o: state structure */ - Word16 *out_fx, /* o : residual signal */ - const Word16 *lpc2_fx, /* i : current frame LPC */ - Word16 *exc_fx, /* i : previous frame excitation */ - Word16 *pitch, /* o : fixed point pitch values for each subframe */ - Word16 bfi /* i : Frame error rate */ + Word16 *out_fx, /* o : residual signal Q0*/ + const Word16 *lpc2_fx, /* i : current frame LPC Q12*/ + Word16 *exc_fx, /* i : previous frame excitation Q0*/ + Word16 *pitch, /* o : fixed point pitch values for each subframe Q6*/ + Word16 bfi /* i : Frame error rate Q0*/ ) { Word16 k, delta_lag_D = 0, temp, Ql, Qh, diff; @@ -258,7 +258,7 @@ ivas_error ppp_voiced_decoder_fx( Ltemp = DTFS_setEngyHarm_fx( 2828, upper_cut_off_freq_of_interest, 2828, upper_cut_off_freq, 1, 0, &Qh, TMPDTFS_FX ); - Ltemp = log10_fx( Ltemp ); + Ltemp = log10_fx( Ltemp ); // Q23 #ifdef BASOP_NOGLOB Ltemp = L_add_sat( L_sub_sat( Ltemp, Ltemp_q ), logLag ); /* Ltemp=10*log10(lag*eng), Q23 */ hSC_VBR->lastHgainD_fx = round_fx_sat( L_shl_sat( (Word32) Mpy_32_16( extract_h( Ltemp ), extract_l( Ltemp ), 0x6666 ), 1 ) ); /* Q11 */ diff --git a/lib_dec/waveadjust_fec_dec_fx.c b/lib_dec/waveadjust_fec_dec_fx.c index b090b22e5..070447cd4 100644 --- a/lib_dec/waveadjust_fec_dec_fx.c +++ b/lib_dec/waveadjust_fec_dec_fx.c @@ -19,12 +19,12 @@ Word16 get_voicing_x( Word16 *s_LP, Word16 pitch, Word32 covMax, Word16 maxConv_ Word32 con_Log10( Word32 i_s32Val, Word16 i_s16Q ); Word16 Spl_GetScalingSquare_x( const Word16 *in_vector, const Word16 in_vector_length, Word16 times ); -Word16 vadmin( Word16 a, Word16 b ) +Word16 vadmin( Word16 a, Word16 b ) /*i/o: Qx */ { return s_min( a, b ); } -void set_state( Word16 *state, Word16 num, Word16 N ) +void set_state( Word16 *state, Word16 num, Word16 N ) /*i/o: Qx */ { Word16 i, tmp; @@ -38,7 +38,7 @@ void set_state( Word16 *state, Word16 num, Word16 N ) move16(); } -void concealment_update_x( Word16 bfi, Word16 curr_mode, Word16 tonality, Word32 *invkoef, Word16 *invkoef_scale, void *_plcInfo ) +void concealment_update_x( Word16 bfi, Word16 curr_mode, Word16 tonality, Word32 *invkoef /*Qinvkoef_scale*/, Word16 *invkoef_scale, void *_plcInfo ) { T_PLCInfo *plcInfo = (T_PLCInfo *) _plcInfo; Word32 *data_reci2 = plcInfo->data_reci2_fx; @@ -99,46 +99,46 @@ void concealment_update_x( Word16 bfi, Word16 curr_mode, Word16 tonality, Word32 return; } -static Word16 zero_pass_w32_x( const Word16 *s, const Word16 N ) +static Word16 zero_pass_w32_x( const Word16 *s, const Word16 N ) /* i: Qx*/ /* o: 2*Qx-31*/ { Word16 i; Word32 temp, zp = L_deposit_l( 0 ); FOR( i = 1; i < N; i++ ) { - temp = L_mac0( -1L, s[i], s[i - 1] ); - zp = L_sub( zp, L_shr( temp, 31 ) ); + temp = L_mac0( -1L, s[i], s[i - 1] ); // 2*Qx + zp = L_sub( zp, L_shr( temp, 31 ) ); // 2*Qx-31 } return extract_l( zp ); } -Word16 Sqrt_x_fast( Word32 value ) +Word16 Sqrt_x_fast( Word32 value /*Qvalue*/ ) /*o : Q11-(2*norm+1)*/ { Word16 norm; Word16 result, index; norm = sub( 23, norm_l( value ) ); index = extract_l( L_shr_r( value, add( norm, s_and( norm, 1 ) ) ) ); - result = shr( sqrt_table_pitch_search[index], sub( 11, shr( add( norm, 1 ), 1 ) ) ); + result = shr( sqrt_table_pitch_search[index], sub( 11, shr( add( norm, 1 ), 1 ) ) ); // Q11-(2*norm+1) return result; } -Word32 dot_w32_accuracy_x( Word16 *s1, Word16 *s2, Word16 nbits, Word16 N ) +Word32 dot_w32_accuracy_x( Word16 *s1 /*Qs1*/, Word16 *s2 /*Qs2*/, Word16 nbits, Word16 N ) { Word16 i; Word32 eng = L_deposit_l( 0 ), temp; FOR( i = 0; i < N; i++ ) { - temp = L_mult0( s1[i], s2[i] ); - eng = L_add( eng, L_shr( temp, nbits ) ); + temp = L_mult0( s1[i], s2[i] ); /*Qs1+ Qs2*/ + eng = L_add( eng, L_shr( temp, nbits ) ); /*Qs1+ Qs2-nbits*/ } return eng; } -Word16 int_div_s_x( Word16 a, Word16 b ) +Word16 int_div_s_x( Word16 a, Word16 b ) /*i/o : Q0*/ { Word16 result = 0; Word16 norm, left = 0, i; @@ -170,7 +170,7 @@ Word16 int_div_s_x( Word16 a, Word16 b ) return result; } -Word16 GetW32Norm_x( Word32 *s, Word16 N ) +Word16 GetW32Norm_x( Word32 *s, Word16 N ) /*i : Qx, o: Q0*/ { Word32 smax = L_deposit_l( 0 ); Word16 smax_norm, i; @@ -185,7 +185,7 @@ Word16 GetW32Norm_x( Word32 *s, Word16 N ) return smax_norm; } -Word16 harmo_x( Word32 *X, Word16 Framesize, Word16 pitch ) +Word16 harmo_x( Word32 *X, Word16 Framesize, Word16 pitch ) /*i : Qx, o: Q15*/ { Word16 h, k, result = 0; Word32 ener = L_deposit_l( 0 ), ener_harmo = L_deposit_l( 0 ); @@ -229,7 +229,7 @@ Word16 harmo_x( Word32 *X, Word16 Framesize, Word16 pitch ) return result; } -static Word16 get_low_freq_eng_rate_x( Word32 *mdct_data, +static Word16 get_low_freq_eng_rate_x( Word32 *mdct_data, /*i: Qx*/ /*o: Q0*/ Word16 curr_mode, Word16 N ) { @@ -276,7 +276,7 @@ static Word16 get_low_freq_eng_rate_x( Word32 *mdct_data, return ( L_sub( low_eng, smax ) <= 0 ); } -void LpFilter2_x( Word16 *x, Word16 *y, Word16 N ) +void LpFilter2_x( Word16 *x, Word16 *y, Word16 N ) /*i/o : Qx*/ { Word16 i; Word16 smax, norm; @@ -305,7 +305,7 @@ void LpFilter2_x( Word16 *x, Word16 *y, Word16 N ) } } -void sig_tilt_x( Word16 *s, Word16 FrameSize, Word32 *enr1, Word32 *enr2 ) +void sig_tilt_x( Word16 *s /*Qx*/, Word16 FrameSize, Word32 *enr1 /*2*Qx-nbits*/, Word32 *enr2 /*2*Qx-nbits*/ ) { Word16 subFrameSize, shIFt; Word16 *p1, *p2; @@ -323,7 +323,7 @@ void sig_tilt_x( Word16 *s, Word16 FrameSize, Word32 *enr1, Word32 *enr2 ) move32(); } -void get_maxConv_and_pitch_x( Word16 *s_LP, Word16 s, Word16 e, Word16 N, Word32 *maxConv, Word16 *maxConv_bits, Word16 *pitch ) +void get_maxConv_and_pitch_x( Word16 *s_LP /*Qx*/, Word16 s /*Q0*/, Word16 e /*Q0*/, Word16 N, Word32 *maxConv /*2*Qx-nbits*/, Word16 *maxConv_bits, Word16 *pitch /*Q0*/ ) { Word16 t, cov_size, size = N; Word32 tmp_sigma = L_deposit_l( 0 ), cov_max_sigma = L_deposit_l( 0 ); @@ -399,7 +399,7 @@ void get_maxConv_and_pitch_x( Word16 *s_LP, Word16 s, Word16 e, Word16 N, Word32 move16(); } -Word16 get_voicing_x( Word16 *s_LP, Word16 pitch, Word32 covMax, Word16 maxConv_bits, Word16 Framesize ) +Word16 get_voicing_x( Word16 *s_LP /*Qx*/, Word16 pitch /*Q0*/, Word32 covMax /*2*Qx-nbits*/, Word16 maxConv_bits, Word16 Framesize ) /*o : Q15*/ { Word32 eng1 = L_deposit_l( 0 ), eng2 = L_deposit_l( 0 ); Word16 voicing, norm; @@ -447,7 +447,7 @@ Word16 get_voicing_x( Word16 *s_LP, Word16 pitch, Word32 covMax, Word16 maxConv_ } } -void pitch_modify_x( Word16 *s_LP, Word16 *voicing, Word16 *pitch, Word16 FrameSize ) +void pitch_modify_x( Word16 *s_LP /*Qx*/, Word16 *voicing /*Q15*/, Word16 *pitch /*Q0*/, Word16 FrameSize ) { Word32 eng1, eng2, eng3; Word16 shIFt = shr( *pitch, 1 ); @@ -513,7 +513,7 @@ void pitch_modify_x( Word16 *s_LP, Word16 *voicing, Word16 *pitch, Word16 FrameS } } -Word16 Is_Periodic_x( Word32 *mdct_data, Word16 cov_max, Word16 zp, Word32 ener, Word32 ener_mean, Word16 pitch, Word16 Framesize ) +Word16 Is_Periodic_x( Word32 *mdct_data /*Qx*/, Word16 cov_max /*Q15*/, Word16 zp, Word32 ener /*Q8*/, Word32 ener_mean /*Q8*/, Word16 pitch /*Q0*/, Word16 Framesize ) /*o: Q0*/ { Word16 flag = 0; Word16 harm; @@ -561,7 +561,7 @@ Word16 Is_Periodic_x( Word32 *mdct_data, Word16 cov_max, Word16 zp, Word32 ener, return flag; } -Word16 get_conv_relation_x( Word16 *s_LP, Word16 shIFt, Word16 N ) +Word16 get_conv_relation_x( Word16 *s_LP /*Qx*/, Word16 shIFt, Word16 N ) /*o :Q0*/ { Word32 eng1, eng2, eng3; Word16 eng1_w, eng2_w; @@ -607,14 +607,14 @@ Word16 get_conv_relation_x( Word16 *s_LP, Word16 shIFt, Word16 N ) return tmp; } -static Word16 pitch_search_fx( Word16 *s, /* lastPcmOut */ - Word16 *outx_new, +static Word16 pitch_search_fx( Word16 *s /*Qs*/, /* lastPcmOut */ + Word16 *outx_new /*Qoutx_new*/, Word16 Framesize, - Word16 *voicing, - Word16 zp, - Word32 ener, - Word32 ener_mean, - Word32 *mdct_data, + Word16 *voicing /*Q15*/, + Word16 zp, /*Q0*/ + Word32 ener /*Q8*/, + Word32 ener_mean /*Q8*/, + Word32 *mdct_data /*Qmdct*/, Word16 curr_mode ) { Word16 pitch = 0; @@ -901,14 +901,14 @@ void concealment_init_ivas_fx( #endif // IVAS_FLOAT_FIXED static Word16 own_random_fix( /* o : output random value */ - Word16 *seed /* i/o: random seed */ + Word16 *seed /* i/o: random seed Q0 */ ) { *seed = extract_l( L_mac0( 13849L, *seed, 31821 ) ); return ( *seed ); } -void concealment_decode_fix( Word16 curr_mode, Word32 *invkoef, Word16 *invkoef_scale, void *_plcInfo ) +void concealment_decode_fix( Word16 curr_mode, Word32 *invkoef /*Qinvkoef_scale*/, Word16 *invkoef_scale, void *_plcInfo ) { T_PLCInfo *plcInfo = (T_PLCInfo *) _plcInfo; Word16 i; @@ -940,7 +940,7 @@ void concealment_decode_fix( Word16 curr_mode, Word32 *invkoef, Word16 *invkoef_ } -Word16 Spl_GetScalingSquare_x( const Word16 *in_vector, const Word16 in_vector_length, Word16 times ) +Word16 Spl_GetScalingSquare_x( const Word16 *in_vector /*Qin_vector*/, const Word16 in_vector_length, Word16 times ) /*o : Q0*/ { Word16 nbits = sub( 15, norm_s( times ) ) /*Spl_GetSizeInBits_x(times)*/; Word16 i; @@ -973,7 +973,7 @@ Word16 Spl_GetScalingSquare_x( const Word16 *in_vector, const Word16 in_vector_l } -Word32 Spl_Energy_x( const Word16 *vector, const Word16 vector_length, Word16 *scale_factor ) +Word32 Spl_Energy_x( const Word16 *vector /*Qvector*/, const Word16 vector_length, Word16 *scale_factor ) { Word32 en = L_deposit_l( 0 ); Word32 i; @@ -990,7 +990,7 @@ Word32 Spl_Energy_x( const Word16 *vector, const Word16 vector_length, Word16 *s return en; } -void Log10OfEnergy_x( const Word16 *s, Word32 *enerlogval, const Word16 len ) +void Log10OfEnergy_x( const Word16 *s /* Qs */, Word32 *enerlogval /* Q8 */, const Word16 len ) { Word32 energy = L_deposit_l( 0 ), tmp2 = L_deposit_l( 0 ); Word16 shfts = 0; @@ -1013,7 +1013,7 @@ void Log10OfEnergy_x( const Word16 *s, Word32 *enerlogval, const Word16 len ) } } -static Word32 fnLog2( Word32 L_Input ) +static Word32 fnLog2( Word32 L_Input /*QL_Input*/ ) /*o :Q26*/ { Word16 swC0 = -0x2b2a, swC1 = 0x7fc5, swC2 = -0x54d0; @@ -1067,7 +1067,7 @@ static Word32 fnLog2( Word32 L_Input ) return ( LwIn ); } -static Word32 fnLog10( Word32 L_Input ) +static Word32 fnLog10( Word32 L_Input /*QL_Input*/ ) /*o :Q26*/ { Word16 Scale = 9864; /* 0.30103 = log10(2) */ @@ -1088,7 +1088,7 @@ static Word32 fnLog10( Word32 L_Input ) return ( LwIn ); } -Word32 con_Log10( Word32 i_s32Val, Word16 i_s16Q ) +Word32 con_Log10( Word32 i_s32Val /*Qi_s32Val*/, Word16 i_s16Q /*Q0*/ ) /*o; Q26*/ { Word32 s32Out; Word32 s32Correct; /* corrected (31-q)*log10(2) */ @@ -1111,7 +1111,7 @@ Word32 con_Log10( Word32 i_s32Val, Word16 i_s16Q ) return s32Out; } -void concealment_update2_x( const Word16 *outx_new, void *_plcInfo, const Word16 FrameSize ) +void concealment_update2_x( const Word16 *outx_new /*Qoutx_new*/, void *_plcInfo, const Word16 FrameSize ) { T_PLCInfo *plcInfo = (T_PLCInfo *) _plcInfo; @@ -1129,7 +1129,7 @@ void concealment_update2_x( const Word16 *outx_new, void *_plcInfo, const Word16 return; } -static Word16 array_max_indx_fx( Word16 *s, Word16 N ) +static Word16 array_max_indx_fx( Word16 *s /*Qs*/, Word16 N ) { Word16 i, indx = 0; move16(); @@ -1145,7 +1145,7 @@ static Word16 array_max_indx_fx( Word16 *s, Word16 N ) } Word16 ffr_getSfWord16( /* o: measured headroom in range [0..15], 0 IF all x[i] == 0 */ - Word16 *x, /* i: array containing 16-bit data */ + Word16 *x, /* i: array containing 16-bit data Qx*/ Word16 len_x ) /* i: length of the array to scan */ { Word16 i, i_min, i_max; @@ -1189,7 +1189,7 @@ Word16 ffr_getSfWord16( /* o: measured headroom in range [0..15], return i; } -static Word16 OverlapAdd_fx( Word16 *pitch125_data, Word16 *sbuf, Word16 n, Word16 pitch, Word16 Framesize ) +static Word16 OverlapAdd_fx( Word16 *pitch125_data /*Qx*/, Word16 *sbuf /*Qx*/, Word16 n, Word16 pitch /*Q0*/, Word16 Framesize ) { Word16 n1, n2, s, s16MaxCoefNorm, s16MaxCoefNorm2, tmp16; Word16 i; @@ -1236,12 +1236,12 @@ static Word16 OverlapAdd_fx( Word16 *pitch125_data, Word16 *sbuf, Word16 n, Word return pitch; } -static void add_noise( Word16 *const sbuf, - Word16 *const outx_new_n1, - Word16 const *const noise_seg, +static void add_noise( Word16 *const sbuf, /*Qsbuf*/ + Word16 *const outx_new_n1, /*Q0*/ + Word16 const *const noise_seg, /*Q0*/ Word16 const Len, - Word16 *const gain, - Word16 const *const gain_n, + Word16 *const gain, /*Q15*/ + Word16 const *const gain_n, /*Q15*/ Word8 const firstFrame ) { Word16 i; @@ -1283,18 +1283,18 @@ static void add_noise( Word16 *const sbuf, return; } -static Word16 waveform_adj_fix( Word16 *overlapbuf, - Word16 *outdata2, - Word16 *outx_new, - Word16 *data_noise, - Word16 *outx_new_n1, - Word16 *nsapp_gain, - Word16 *nsapp_gain_n, +static Word16 waveform_adj_fix( Word16 *overlapbuf, /*Qoverlapbuf*/ + Word16 *outdata2, /*Qoutdata2*/ + Word16 *outx_new, /*Qoutx_new*/ + Word16 *data_noise, /*Qoutx_new*/ + Word16 *outx_new_n1, /*Q0*/ + Word16 *nsapp_gain, /*Q15*/ + Word16 *nsapp_gain_n, /*Q15*/ Word16 Framesize, Word8 T_bfi, - Word16 voicing, + Word16 voicing, /*Q15*/ Word16 curr_mode, - Word16 pitch ) + Word16 pitch /*Q0*/ ) { Word16 i, zp1, zp2, Framesizediv2, s16MaxCoefNorm; Word16 sbuf[L_FRAME_MAX]; @@ -1429,15 +1429,15 @@ static Word16 waveform_adj_fix( Word16 *overlapbuf, return pitch; } -void waveform_adj2_fix( Word16 *overlapbuf, - Word16 *outx_new, - Word16 *data_noise, - Word16 *outx_new_n1, - Word16 *nsapp_gain, - Word16 *nsapp_gain_n, - Word16 *recovery_gain, - Word16 step_concealgain, - Word16 pitch, +void waveform_adj2_fix( Word16 *overlapbuf, /*Qoverlapbuf*/ + Word16 *outx_new, /*Qoutx_new*/ + Word16 *data_noise, /*Qoutx_new*/ + Word16 *outx_new_n1, /*Q0*/ + Word16 *nsapp_gain, /*Q15*/ + Word16 *nsapp_gain_n, /*Q15*/ + Word16 *recovery_gain, /*Q14*/ + Word16 step_concealgain, /*Q15*/ + Word16 pitch, /*Q0*/ Word16 Framesize, Word16 delay, Word16 bfi_cnt, @@ -1612,7 +1612,7 @@ void waveform_adj2_fix( Word16 *overlapbuf, return; } -void concealment_signal_tuning_fx( Word16 bfi, Word16 curr_mode, Word16 *outx_new_fx, void *_plcInfo, Word16 nbLostCmpt, Word16 pre_bfi, Word16 *OverlapBuf_fx, Word16 past_core_mode, Word16 *outdata2_fx, Decoder_State *st ) +void concealment_signal_tuning_fx( Word16 bfi, Word16 curr_mode, Word16 *outx_new_fx /*Qoutx_new_fx*/, void *_plcInfo, Word16 nbLostCmpt, Word16 pre_bfi, Word16 *OverlapBuf_fx /*QOverlapBuf_fx*/, Word16 past_core_mode, Word16 *outdata2_fx /*Qoutdata2_fx*/, Decoder_State *st ) { T_PLCInfo *plcInfo = (T_PLCInfo *) _plcInfo; Word16 FrameSize = plcInfo->FrameSize; diff --git a/lib_rend/ivas_dirac_output_synthesis_dec.c b/lib_rend/ivas_dirac_output_synthesis_dec.c index 4c93bcdc1..ef7f34e82 100644 --- a/lib_rend/ivas_dirac_output_synthesis_dec.c +++ b/lib_rend/ivas_dirac_output_synthesis_dec.c @@ -54,18 +54,24 @@ * Local constants *------------------------------------------------------------------------*/ -#define DIRAC_AVG_LENGTH_SYNTH_MS 20 /*averaging length in ms for DirAC synthesis*/ -#define DIRAC_ALPHA_MAX 0.1f -#define DIRAC_ALPHA_MAX_Q15 3276 +#define DIRAC_AVG_LENGTH_SYNTH_MS 20 /*averaging length in ms for DirAC synthesis*/ +#ifndef IVAS_FLOAT_FIXED +#define DIRAC_ALPHA_MAX 0.1f +#endif +#define DIRAC_ALPHA_MAX_Q15 3276 /*0.1f q15*/ #define DIRAC_AVG_LENGTH_SYNTH_MS_FAST 10 -#define DIRAC_ALPHA_MAX_FAST 0.12f -#define DIRAC_ALPHA_MAX_FAST_Q15 3932 -#define DIRECTION_SMOOTHNESS_ALPHA 0.01f -#define DIRECTION_SMOOTHNESS_ALPHA_Q31 ( 21474836 ) +#ifndef IVAS_FLOAT_FIXED +#define DIRAC_ALPHA_MAX_FAST 0.12f +#endif +#define DIRAC_ALPHA_MAX_FAST_Q15 3932 /*0.12f q15*/ +#ifndef IVAS_FLOAT_FIXED +#define DIRECTION_SMOOTHNESS_ALPHA 0.01f +#endif +#define DIRECTION_SMOOTHNESS_ALPHA_Q31 ( 21474836 ) /*0.01f q31*/ #ifdef IVAS_FLOAT_FIXED -#define POINT_3679_Q31 790059234 -#define POINT_1175_Q31 252329329 +#define POINT_3679_Q31 790059234 /*.3679 q31*/ +#define POINT_1175_Q31 252329329 /*.1175 q31*/ #endif /*------------------------------------------------------------------------- @@ -83,7 +89,7 @@ static void computeTargetPSDs_diffuse_subframe_fx( const Word16 num_channels, co static void computeTargetPSDs_diffuse_with_onsets_fx( const Word16 num_channels, const Word16 num_freq_bands, const Word16 num_decorr_freq_bands, const Word16 *proto_frame_diff_index, const Word32 *diffuse_power_factor, const Word32 *reference_power, const Word16 *q_reference_power, const Word32 *diffuse_responses_square, const Word32 *onset_filter, Word32 *cy_auto_diff_smooth, Word16 *q_cy_auto_diff_smooth ); -static void computeAlphaSynthesis_fx( Word16 *alpha_synthesis_fx, const Word16 averaging_length_ms, const Word16 maxAlpha_fx, Word16 *numAlphas, const Word16 slot_size, const Word16 num_freq_bands, Word16 *frequency_axis_fx, const Word32 output_Fs ); +static void computeAlphaSynthesis_fx( Word16 *alpha_synthesis_fx /*q15*/, const Word16 averaging_length_ms, const Word16 maxAlpha_fx /*q15*/, Word16 *numAlphas, const Word16 slot_size, const Word16 num_freq_bands, Word16 *frequency_axis_fx /*q0*/, const Word32 output_Fs ); static void spreadCoherencePanningHoa_fx( const Word16 azimuth, const Word16 elevation, const Word16 spreadCoh_fx, Word32 *direct_response_fx, Word16 *Q_direct_response_hoa, const Word16 num_channels_dir, const Word16 ambisonics_order ); @@ -321,7 +327,7 @@ ivas_error ivas_dirac_dec_output_synthesis_open_fx( { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n" ) ); } - Copy( temp_alpha_synthesis_fx, dirac_output_synthesis_params->alpha_synthesis_fx, dirac_output_synthesis_params->numAlphas ); + Copy( temp_alpha_synthesis_fx, dirac_output_synthesis_params->alpha_synthesis_fx, dirac_output_synthesis_params->numAlphas ); /*q15*/ computeAlphaSynthesis_fx( temp_alpha_synthesis_fx, DIRAC_AVG_LENGTH_SYNTH_MS_FAST, DIRAC_ALPHA_MAX_FAST_Q15, &dirac_output_synthesis_params->numAlphasFast, hSpatParamRendCom->slot_size, hSpatParamRendCom->num_freq_bands, hDirACRend->frequency_axis_fx, output_Fs ); @@ -329,7 +335,7 @@ ivas_error ivas_dirac_dec_output_synthesis_open_fx( { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n" ) ); } - Copy( temp_alpha_synthesis_fx, dirac_output_synthesis_params->alpha_synthesis_fast_fx, dirac_output_synthesis_params->numAlphasFast ); + Copy( temp_alpha_synthesis_fx, dirac_output_synthesis_params->alpha_synthesis_fast_fx, dirac_output_synthesis_params->numAlphasFast ); /*q15*/ IF( ( dirac_output_synthesis_state->reference_power_smooth_prev_fx = (Word32 *) malloc( hSpatParamRendCom->num_freq_bands * sizeof( Word32 ) ) ) == NULL ) { @@ -377,10 +383,10 @@ ivas_error ivas_dirac_dec_output_synthesis_open_fx( FOR( ch_idx = 0; ch_idx < num_diffuse_responses; ++ch_idx ) { /*dirac_output_synthesis_state->diffuse_responses_square[ch_idx] = pow(dirac_output_synthesis_params->diffuse_response_function[ch_idx]/max_response, 2.0f);*/ - tmp_fx = hDirACRend->diffuse_response_function_fx[ch_idx]; + tmp_fx = hDirACRend->diffuse_response_function_fx[ch_idx]; /*q15*/ move16(); - dirac_output_synthesis_state->diffuse_responses_square_fx[ch_idx] = L_mult( tmp_fx, tmp_fx ); /* Q15 + Q15 -> Q31 */ + dirac_output_synthesis_state->diffuse_responses_square_fx[ch_idx] = L_mult( tmp_fx, tmp_fx ); /* Q15 + Q15 + 1 -> Q31 */ move32(); } } @@ -418,28 +424,28 @@ ivas_error ivas_dirac_dec_output_synthesis_open_fx( { diff_nrg_fx = L_shr( L_mult0( hDirACRend->diffuse_response_function_fx[ch_idx], hDirACRend->diffuse_response_function_fx[ch_idx] ), gaurd_bits ); // Q30 - gaurd_bits - diff_nrg_total_fx = L_add( diff_nrg_total_fx, diff_nrg_fx ); + diff_nrg_total_fx = L_add( diff_nrg_total_fx, diff_nrg_fx ); // Q30 - gaurd_bits /* is it a transport channel?*/ test(); if ( ch_idx == 0 || hDirACRend->proto_index_dir[ch_idx] != 0 ) { - diff_nrg_trans_fx = L_add( diff_nrg_trans_fx, diff_nrg_fx ); + diff_nrg_trans_fx = L_add( diff_nrg_trans_fx, diff_nrg_fx ); // Q30 - gaurd_bits } /* is it a decorrelated or transport channel?*/ if ( LT_16( ch_idx, hDirACRend->num_outputs_diff ) ) { - diff_nrg_decorr_fx = L_add( diff_nrg_decorr_fx, diff_nrg_fx ); + diff_nrg_decorr_fx = L_add( diff_nrg_decorr_fx, diff_nrg_fx ); // Q30 - gaurd_bits } } Word16 exp_1 = 0, exp_2 = 0, tmp; move16(); move16(); - tmp = BASOP_Util_Divide3232_Scale( diff_nrg_total_fx, diff_nrg_trans_fx, &exp_1 ); // (Q15 - exp_diff) + tmp = BASOP_Util_Divide3232_Scale( diff_nrg_total_fx, diff_nrg_trans_fx, &exp_1 ); // Q(15 - exp_1) dirac_output_synthesis_params->diffuse_compensation_factor_fx = L_shl( L_deposit_l( tmp ), add( Q12, exp_1 ) ); // Q27 move32(); - tmp = BASOP_Util_Divide3232_Scale( diff_nrg_total_fx, diff_nrg_decorr_fx, &exp_2 ); // (Q15 - exp_diff) + tmp = BASOP_Util_Divide3232_Scale( diff_nrg_total_fx, diff_nrg_decorr_fx, &exp_2 ); // (Q15 - exp_2) dirac_output_synthesis_params->diffuse_compensation_factor_decorr_fx = L_shl( L_deposit_l( tmp ), add( Q14, exp_2 ) ); // Q29 move32(); } @@ -1319,17 +1325,17 @@ void ivas_dirac_dec_output_synthesis_process_slot( } #else void ivas_dirac_dec_output_synthesis_process_slot_fx( - const Word32 *reference_power, /* i : Estimated power */ - const Word16 q_reference_power, /* i : Estimated power */ - const Word32 *onset, /* i : onset filter */ + const Word32 *reference_power, /* i : Estimated power Q(q_reference_power)*/ + const Word16 q_reference_power, /* i : Estimated power Q */ + const Word32 *onset, /* i : onset filter Q31*/ const Word16 *azimuth, const Word16 *elevation, - const Word32 *diffuseness, + const Word32 *diffuseness, /* Q(q_diffuseness)*/ Word16 q_diffuseness, SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom, /* i/o: common spatial renderer data handle */ DIRAC_REND_HANDLE hDirACRend, /* i/o: DirAC renderer handle */ const Word16 sh_rot_max_order, - const Word32 *p_Rmat, /* i : rotation matrix */ + const Word32 *p_Rmat, /* i : rotation matrix Q30*/ const VBAP_HANDLE hVBAPdata, /* i : VBAP structure */ const IVAS_OUTPUT_SETUP hOutSetup, /* i : output setup structure */ const Word16 nchan_transport, /* i : number of transport channels*/ @@ -1348,7 +1354,7 @@ void ivas_dirac_dec_output_synthesis_process_slot_fx( h_dirac_output_synthesis_params = &( hDirACRend->h_output_synthesis_psd_params ); h_dirac_output_synthesis_state = &( hDirACRend->h_output_synthesis_psd_state ); - h_dirac_output_synthesis_state->onset_filter_fx = onset; + h_dirac_output_synthesis_state->onset_filter_fx = onset; /*Q31*/ /*-----------------------------------------------------------------* * processing @@ -1390,14 +1396,14 @@ void ivas_dirac_dec_output_synthesis_process_slot_fx( IF( h_dirac_output_synthesis_state->direct_responses_square_fx ) { - Scale_sig32( h_dirac_output_synthesis_state->direct_responses_square_fx, imult1616( num_channels_dir, num_freq_bands ), sub( 31, h_dirac_output_synthesis_state->direct_responses_square_q ) ); + Scale_sig32( h_dirac_output_synthesis_state->direct_responses_square_fx, imult1616( num_channels_dir, num_freq_bands ), sub( 31, h_dirac_output_synthesis_state->direct_responses_square_q ) ); /* h_dirac_output_synthesis_state->direct_responses_square_q->Q31*/ h_dirac_output_synthesis_state->direct_responses_square_q = 31; move16(); } - Scale_sig32( hDirACRend->h_output_synthesis_psd_state.direct_responses_fx, i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_dir ), sub( 31, h_dirac_output_synthesis_state->direct_responses_q ) ); + Scale_sig32( hDirACRend->h_output_synthesis_psd_state.direct_responses_fx, i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_dir ), sub( 31, h_dirac_output_synthesis_state->direct_responses_q ) ); /*h_dirac_output_synthesis_state->direct_responses_q->Q31*/ IF( hodirac_flag ) { - Scale_sig32( &hDirACRend->h_output_synthesis_psd_state.direct_responses_fx[i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_dir )], i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_dir ), sub( 31, h_dirac_output_synthesis_state->direct_responses_q ) ); + Scale_sig32( &hDirACRend->h_output_synthesis_psd_state.direct_responses_fx[hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_dir], i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_dir ), sub( 31, h_dirac_output_synthesis_state->direct_responses_q ) ); /*h_dirac_output_synthesis_state->direct_responses_q->Q31*/ } h_dirac_output_synthesis_state->direct_responses_q = 31; move16(); @@ -1409,23 +1415,23 @@ void ivas_dirac_dec_output_synthesis_process_slot_fx( { IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) { - v_multc_fixed( hSpatParamRendCom->energy_ratio1_fx[md_idx], -MAX_32, aux_buf, num_freq_bands ); - v_addc_fixed( aux_buf, ONE_IN_Q30, aux_buf, num_freq_bands ); + v_multc_fixed( hSpatParamRendCom->energy_ratio1_fx[md_idx], -MAX_32 /*-1 Q31*/, aux_buf, num_freq_bands ); /* 30 + 31 - 31 -> 30 */ + v_addc_fixed( aux_buf, ONE_IN_Q30 /*1 Q30*/, aux_buf, num_freq_bands ); /*30*/ Copy32( hSpatParamRendCom->energy_ratio1_fx[md_idx], h_dirac_output_synthesis_state->direct_power_factor_fx, - num_freq_bands ); + num_freq_bands ); /*Q30*/ Copy32( aux_buf, h_dirac_output_synthesis_state->diffuse_power_factor_fx, - num_freq_bands ); + num_freq_bands ); /*Q30*/ - v_multc_fixed( hSpatParamRendCom->energy_ratio2_fx[md_idx], -MAX_32, aux_buf, num_freq_bands ); - v_addc_fixed( aux_buf, ONE_IN_Q30, aux_buf, num_freq_bands ); + v_multc_fixed( hSpatParamRendCom->energy_ratio2_fx[md_idx], -MAX_32 /*-1 Q31*/, aux_buf, num_freq_bands ); /*30+31-31->30*/ + v_addc_fixed( aux_buf, ONE_IN_Q30 /*1 Q30*/, aux_buf, num_freq_bands ); /*30*/ Copy32( hSpatParamRendCom->energy_ratio2_fx[md_idx], &h_dirac_output_synthesis_state->direct_power_factor_fx[hSpatParamRendCom->num_freq_bands], - num_freq_bands ); + num_freq_bands ); /*Q30*/ Copy32( aux_buf, &h_dirac_output_synthesis_state->diffuse_power_factor_fx[hSpatParamRendCom->num_freq_bands], - num_freq_bands ); + num_freq_bands ); /*Q30*/ h_dirac_output_synthesis_state->diffuse_power_factor_q = 30; move16(); @@ -1462,14 +1468,14 @@ void ivas_dirac_dec_output_synthesis_process_slot_fx( { IF( h_dirac_output_synthesis_state->direct_responses_square_fx ) { - Scale_sig32( h_dirac_output_synthesis_state->direct_responses_square_fx, imult1616( num_channels_dir, num_freq_bands ), sub( 31, h_dirac_output_synthesis_state->direct_responses_square_q ) ); + Scale_sig32( h_dirac_output_synthesis_state->direct_responses_square_fx, imult1616( num_channels_dir, num_freq_bands ), sub( 31, h_dirac_output_synthesis_state->direct_responses_square_q ) ); /*h_dirac_output_synthesis_state->direct_responses_square_q->Q31*/ h_dirac_output_synthesis_state->direct_responses_square_q = 31; move16(); } - Scale_sig32( hDirACRend->h_output_synthesis_psd_state.direct_responses_fx, i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_dir ), sub( 31, h_dirac_output_synthesis_state->direct_responses_q ) ); + Scale_sig32( hDirACRend->h_output_synthesis_psd_state.direct_responses_fx, i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_dir ), sub( 31, h_dirac_output_synthesis_state->direct_responses_q ) ); /*h_dirac_output_synthesis_state->direct_responses_q->Q31*/ IF( hodirac_flag ) { - Scale_sig32( &hDirACRend->h_output_synthesis_psd_state.direct_responses_fx[i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_dir )], i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_dir ), sub( 31, h_dirac_output_synthesis_state->direct_responses_q ) ); + Scale_sig32( &hDirACRend->h_output_synthesis_psd_state.direct_responses_fx[hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_dir], i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_dir ), sub( 31, h_dirac_output_synthesis_state->direct_responses_q ) ); /*h_dirac_output_synthesis_state->direct_responses_q->Q31*/ } h_dirac_output_synthesis_state->direct_responses_q = 31; move16(); @@ -1487,13 +1493,13 @@ void ivas_dirac_dec_output_synthesis_process_slot_fx( h_dirac_output_synthesis_state->diffuse_power_factor_q = sub( 31, h_dirac_output_synthesis_state->diffuse_power_factor_q ); v_multc_fixed( h_dirac_output_synthesis_state->direct_power_factor_fx, - ONE_IN_Q29, + ONE_IN_Q29 /*0.25f Q31*/, h_dirac_output_synthesis_state->direct_power_factor_fx, - num_freq_bands ); + num_freq_bands ); /*h_dirac_output_synthesis_state->direct_power_factor_q+Q31-Q31->h_dirac_output_synthesis_state->direct_power_factor_q*/ v_multc_fixed( h_dirac_output_synthesis_state->diffuse_power_factor_fx, - ONE_IN_Q29, + ONE_IN_Q29 /*0.25f Q31*/, h_dirac_output_synthesis_state->diffuse_power_factor_fx, - num_freq_bands ); + num_freq_bands ); /*h_dirac_output_synthesis_state->diffuse_power_factor_q+Q31-Q31->h_dirac_output_synthesis_state->diffuse_power_factor_q*/ /*Direct gain*/ @@ -1519,9 +1525,9 @@ void ivas_dirac_dec_output_synthesis_process_slot_fx( /*Directonal sound gain nrg compensation*/ FOR( k = 0; k < num_freq_bands_diff; k++ ) { - a = h_dirac_output_synthesis_state->direct_responses_fx[add( i_mult( ch_idx, num_freq_bands ), k )]; // Q = h_dirac_output_synthesis_state->q_direct_responses + a = h_dirac_output_synthesis_state->direct_responses_fx[ch_idx * num_freq_bands + k]; // Q = h_dirac_output_synthesis_state->q_direct_responses move32(); - IF( reference_power[add( k, num_freq_bands )] == 0 ) + IF( reference_power[k + num_freq_bands] == 0 ) { b = 0; move16(); @@ -1530,68 +1536,68 @@ void ivas_dirac_dec_output_synthesis_process_slot_fx( } ELSE { - b = BASOP_Util_Divide3232_Scale( reference_power[add( k, num_freq_bands )], L_add( reference_power[add( k, imult1616( add( ch_idx, 1 ), num_freq_bands ) )], EPSILON_FX ), &b_exp ); + b = BASOP_Util_Divide3232_Scale( reference_power[k + num_freq_bands], L_add( reference_power[k + ( ch_idx + 1 ) * num_freq_bands], EPSILON_FX ), &b_exp ); /*Q(15-b_exp)*/ } - c = L_add( ONE_IN_Q29, Mpy_32_16_1( L_sub( h_dirac_output_synthesis_params->diffuse_compensation_factor_decorr_fx, ONE_IN_Q29 ), 5461 ) ); /*Diffuseness modellling nrg compensation*/ /* 1.0 / 6.0 = 5461 in Q15*/ + c = L_add( ONE_IN_Q29 /*1 Q29*/, Mpy_32_16_1( L_sub( h_dirac_output_synthesis_params->diffuse_compensation_factor_decorr_fx, ONE_IN_Q29 /*1 Q29*/ ), 5461 /*1.0 / 6.0 Q15*/ ) ); /*Diffuseness modellling nrg compensation*/ /*Q29*/ - mpy_a_a_b = Mpy_32_32( a, Mpy_32_16_1( a, b ) ); // Q = (h_dirac_output_synthesis_state->q_direct_responses + (31 - b_exp) - 31) + (h_dirac_output_synthesis_state->q_direct_responses) - 31 - mpy_diff_aab = Mpy_32_32( L_sub( L_shl( 1, q_diffuseness ), diffuseness[k] ), mpy_a_a_b ); // Q = 2*(h_dirac_output_synthesis_state->q_direct_responses) - b_exp - 31 + q_diffuseness -31 - mpy_diff_c = Mpy_32_32( diffuseness[k], c ); // Q = q_diffuseness - 2 + mpy_a_a_b = Mpy_32_32( a, Mpy_32_16_1( a, b ) ); // Q = (h_dirac_output_synthesis_state->q_direct_responses + (15 - b_exp) - 15) + (h_dirac_output_synthesis_state->q_direct_responses) - 31 + mpy_diff_aab = Mpy_32_32( L_sub( L_shl( 1, q_diffuseness ), diffuseness[k] ), mpy_a_a_b ); // Q(q_diff_aab) = 2*(h_dirac_output_synthesis_state->q_direct_responses) - b_exp - 31 + q_diffuseness -31 + mpy_diff_c = Mpy_32_32( diffuseness[k], c ); // Q(q_diff_c) = q_diffuseness - 2 - q_diff_aab = add( sub( add( h_dirac_output_synthesis_state->direct_responses_q, sub( 31, b_exp ) ), 31 ), add( sub( h_dirac_output_synthesis_state->direct_responses_q, 31 ), sub( q_diffuseness, 31 ) ) ); + q_diff_aab = add( sub( add( h_dirac_output_synthesis_state->direct_responses_q, sub( 15, b_exp ) ), 15 ), add( sub( h_dirac_output_synthesis_state->direct_responses_q, 31 ), sub( q_diffuseness, 31 ) ) ); q_diff_c = sub( q_diffuseness, 2 ); test(); IF( mpy_diff_c != 0 && mpy_diff_aab != 0 ) { - sqr_inp = BASOP_Util_Add_Mant32Exp( mpy_diff_c, sub( 31, q_diff_c ), mpy_diff_aab, sub( 31, q_diff_aab ), &sqr_exp ); + sqr_inp = BASOP_Util_Add_Mant32Exp( mpy_diff_c, sub( 31, q_diff_c ), mpy_diff_aab, sub( 31, q_diff_aab ), &sqr_exp ); /*Q(31-sqr_exp)*/ } ELSE { IF( mpy_diff_c == 0 ) { - sqr_inp = mpy_diff_aab; + sqr_inp = mpy_diff_aab; /*Q(q_diff_aab)*/ move32(); sqr_exp = sub( 31, q_diff_aab ); } ELSE { - sqr_inp = mpy_diff_c; + sqr_inp = mpy_diff_c; /*Q(q_diff_c)*/ move32(); sqr_exp = sub( 31, q_diff_c ); } } - sqr = Sqrt32( sqr_inp, &sqr_exp ); - sqr = L_shr( sqr, 2 ); - IF( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )] != 0 ) + sqr = Sqrt32( sqr_inp, &sqr_exp ); /*Q(31-sqr_exp)*/ + sqr = L_shr( sqr, 2 ); /*Q(31-sqr_exp)*/ + IF( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k] != 0 ) { IF( LT_16( sub( 31, sqr_exp ), h_dirac_output_synthesis_state->q_cy_cross_dir_smooth ) ) { - h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )] = L_shr( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )], sub( h_dirac_output_synthesis_state->q_cy_cross_dir_smooth, sub( 31, sqr_exp ) ) ); + h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k] = L_shr( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k], sub( h_dirac_output_synthesis_state->q_cy_cross_dir_smooth, sub( 31, sqr_exp ) ) ); /*h_dirac_output_synthesis_state->q_cy_cross_dir_smooth-> (31-sqr_exp) */ move32(); - Q_temp_cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )] = sub( 31, sqr_exp ); + Q_temp_cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k] = sub( 31, sqr_exp ); move16(); } ELSE { - sqr = L_shr( sqr, sub( sub( 31, sqr_exp ), h_dirac_output_synthesis_state->q_cy_cross_dir_smooth ) ); - Q_temp_cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )] = h_dirac_output_synthesis_state->q_cy_cross_dir_smooth; + sqr = L_shr( sqr, sub( sub( 31, sqr_exp ), h_dirac_output_synthesis_state->q_cy_cross_dir_smooth ) ); /*( 31- sqr_exp )-> h_dirac_output_synthesis_state->q_cy_cross_dir_smooth*/ + Q_temp_cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k] = h_dirac_output_synthesis_state->q_cy_cross_dir_smooth; move16(); } - h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )] = L_add( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )], sqr ); + h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k] = L_add( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k], sqr ); /*Q_temp_cy_cross_dir_smooth_fx*/ move32(); } ELSE { - h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )] = L_add( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )], sqr ); + h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k] = L_add( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k], sqr ); /*31-sqr_exp*/ move32(); - Q_temp_cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )] = sub( 31, sqr_exp ); + Q_temp_cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k] = sub( 31, sqr_exp ); move16(); } } FOR( ; k < num_freq_bands; k++ ) { - a = h_dirac_output_synthesis_state->direct_responses_fx[add( i_mult( ch_idx, num_freq_bands ), k )]; // Q = h_dirac_output_synthesis_state->q_direct_responses + a = h_dirac_output_synthesis_state->direct_responses_fx[ch_idx * num_freq_bands + k]; // Q = h_dirac_output_synthesis_state->q_direct_responses move32(); IF( reference_power[k + num_freq_bands] == 0 ) { @@ -1602,37 +1608,37 @@ void ivas_dirac_dec_output_synthesis_process_slot_fx( } ELSE { - IF( reference_power[add( k, imult1616( add( ch_idx, 1 ), num_freq_bands ) )] == 0 ) + IF( reference_power[k + ( ch_idx + 1 ) * num_freq_bands] == 0 ) { - b = MAXVAL_WORD16; + b = MAXVAL_WORD16; /*Q(-9)*/ move16(); b_exp = 40; move16(); } ELSE { - b = BASOP_Util_Divide3232_Scale( reference_power[k + num_freq_bands], reference_power[add( k, imult1616( add( ch_idx, 1 ), num_freq_bands ) )], &b_exp ); + b = BASOP_Util_Divide3232_Scale( reference_power[k + num_freq_bands], reference_power[k + ( ch_idx + 1 ) * num_freq_bands], &b_exp ); /*q(15-b_exp)*/ } } - c = L_add( ONE_IN_Q29, Mpy_32_16_1( L_sub( h_dirac_output_synthesis_params->diffuse_compensation_factor_decorr_fx, ONE_IN_Q29 ), 5461 ) ); /*Diffuseness modellling nrg compensation*/ /* 1.0 / 6.0 = 5461 in Q15*/ + c = L_add( ONE_IN_Q29 /*1 Q29*/, Mpy_32_16_1( L_sub( h_dirac_output_synthesis_params->diffuse_compensation_factor_decorr_fx, ONE_IN_Q29 /*1 Q29*/ ), 5461 ) ); /*Diffuseness modellling nrg compensation*/ /* 1.0 / 6.0 = 5461 in Q15*/ /*Q29*/ - mpy_a_a_b = Mpy_32_32( a, Mpy_32_16_1( a, b ) ); // Q = (h_dirac_output_synthesis_state->q_direct_responses + (31 - b_exp) - 31) + (h_dirac_output_synthesis_state->q_direct_responses) - 31 + mpy_a_a_b = Mpy_32_32( a, Mpy_32_16_1( a, b ) ); // Q = (h_dirac_output_synthesis_state->q_direct_responses + (15 - b_exp) - 15) + (h_dirac_output_synthesis_state->q_direct_responses) - 31 mpy_diff_aab = Mpy_32_32( L_sub( L_shl( 1, q_diffuseness ), diffuseness[k] ), mpy_a_a_b ); // Q = 2*(h_dirac_output_synthesis_state->q_direct_responses) - b_exp - 31 + q_diffuseness -31 mpy_diff_c = Mpy_32_32( diffuseness[k], c ); // Q = q_diffuseness - 2 - q_diff_aab = add( h_dirac_output_synthesis_state->direct_responses_q + sub( sub( 31, b_exp ), 31 ), add( sub( h_dirac_output_synthesis_state->direct_responses_q, 31 ), sub( q_diffuseness, 31 ) ) ); + q_diff_aab = add( h_dirac_output_synthesis_state->direct_responses_q + sub( sub( 15, b_exp ), 15 ), add( sub( h_dirac_output_synthesis_state->direct_responses_q, 31 ), sub( q_diffuseness, 31 ) ) ); q_diff_c = sub( q_diffuseness, 2 ); test(); IF( mpy_diff_c != 0 && mpy_diff_aab != 0 ) { - sqr_inp = BASOP_Util_Add_Mant32Exp( mpy_diff_c, sub( 31, q_diff_c ), mpy_diff_aab, sub( 31, q_diff_aab ), &sqr_exp ); + sqr_inp = BASOP_Util_Add_Mant32Exp( mpy_diff_c, sub( 31, q_diff_c ), mpy_diff_aab, sub( 31, q_diff_aab ), &sqr_exp ); /*q(31-sqr_exp)*/ } ELSE { IF( mpy_diff_c == 0 ) { - sqr_inp = mpy_diff_aab; + sqr_inp = mpy_diff_aab; /*q_diff_aab*/ move32(); sqr_exp = sub( 31, q_diff_aab ); } @@ -1640,34 +1646,34 @@ void ivas_dirac_dec_output_synthesis_process_slot_fx( { sqr_inp = mpy_diff_c; move32(); - sqr_exp = sub( 31, q_diff_c ); + sqr_exp = sub( 31, q_diff_c ); /*q_diff_c*/ } } - sqr = Sqrt32( sqr_inp, &sqr_exp ); - sqr = L_shr( sqr, 2 ); - IF( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )] != 0 ) + sqr = Sqrt32( sqr_inp, &sqr_exp ); /*Q(31-sqr_exp)*/ + sqr = L_shr( sqr, 2 ); /*Q(31-sqr_exp)*/ + IF( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k] != 0 ) { IF( LT_16( sub( 31, sqr_exp ), h_dirac_output_synthesis_state->q_cy_cross_dir_smooth ) ) { - h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )] = L_shr( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )], sub( h_dirac_output_synthesis_state->q_cy_cross_dir_smooth, sub( 31, sqr_exp ) ) ); + h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k] = L_shr( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k], sub( h_dirac_output_synthesis_state->q_cy_cross_dir_smooth, sub( 31, sqr_exp ) ) ); /*h_dirac_output_synthesis_state->q_cy_cross_dir_smooth->Q( 31- sqr_exp )*/ move32(); - Q_temp_cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )] = sub( 31, sqr_exp ); + Q_temp_cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k] = sub( 31, sqr_exp ); move16(); } ELSE { - sqr = L_shr( sqr, sub( sub( 31, sqr_exp ), h_dirac_output_synthesis_state->q_cy_cross_dir_smooth ) ); - Q_temp_cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )] = h_dirac_output_synthesis_state->q_cy_cross_dir_smooth; + sqr = L_shr( sqr, sub( sub( 31, sqr_exp ), h_dirac_output_synthesis_state->q_cy_cross_dir_smooth ) ); /*Q(31- sqr_exp)->h_dirac_output_synthesis_state->q_cy_cross_dir_smooth*/ + Q_temp_cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k] = h_dirac_output_synthesis_state->q_cy_cross_dir_smooth; move16(); } - h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )] = L_add( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )], sqr ); + h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k] = L_add( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k], sqr ); /*Q_temp_cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k]*/ move32(); } ELSE { - h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )] = L_add( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )], sqr ); + h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k] = L_add( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k], sqr ); /*Q(31- sqr_exp)*/ move32(); - Q_temp_cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )] = sub( 31, sqr_exp ); + Q_temp_cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k] = sub( 31, sqr_exp ); move16(); } } @@ -1679,73 +1685,74 @@ void ivas_dirac_dec_output_synthesis_process_slot_fx( /*Diffuseness modellling nrg compensation*/ FOR( k = 0; k < num_freq_bands_diff; k++ ) { - mpy_diff = Mpy_32_32( diffuseness[k], L_sub( h_dirac_output_synthesis_params->diffuse_compensation_factor_decorr_fx, ONE_IN_Q29 ) ); // Q = q_diff - 1 - sqr_inp = L_add( L_shl( 1, sub( q_diffuseness, 1 ) ), mpy_diff ); + /*diffuseness[k] * 0.5f * ( h_dirac_output_synthesis_params->diffuse_compensation_factor_decorr - 1.f ) )*/ + mpy_diff = Mpy_32_32( diffuseness[k], L_sub( h_dirac_output_synthesis_params->diffuse_compensation_factor_decorr_fx /*q29=0.5 * q30*/, ONE_IN_Q29 /*0.5 Q30*/ ) /*q30*/ ); // Q = q_diffuseness - 1 + sqr_inp = L_add( L_shl( 1, sub( q_diffuseness, 1 ) ), mpy_diff ); // Q = q_diffuseness - 1 sqr_exp = sub( 31, sub( q_diffuseness, 1 ) ); - sqr = Sqrt32( sqr_inp, &sqr_exp ); - sqr = L_shr( sqr, 2 ); - IF( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )] != 0 ) + sqr = Sqrt32( sqr_inp, &sqr_exp ); /*Q(31-sqr_exp)*/ + sqr = L_shr( sqr, 2 ); /*Q(31-sqr_exp)*/ + IF( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k] != 0 ) { IF( LT_16( sub( 31, sqr_exp ), h_dirac_output_synthesis_state->q_cy_cross_dir_smooth ) ) { - h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )] = L_shr( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )], sub( h_dirac_output_synthesis_state->q_cy_cross_dir_smooth, sub( 31, sqr_exp ) ) ); + h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k] = L_shr( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k], sub( h_dirac_output_synthesis_state->q_cy_cross_dir_smooth, sub( 31, sqr_exp ) ) ); /*h_dirac_output_synthesis_state->q_cy_cross_dir_smooth->Q(31- sqr_exp)*/ move32(); - Q_temp_cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )] = sub( 31, sqr_exp ); + Q_temp_cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k] = sub( 31, sqr_exp ); move16(); } ELSE { - sqr = L_shr( sqr, sub( sub( 31, sqr_exp ), h_dirac_output_synthesis_state->q_cy_cross_dir_smooth ) ); - Q_temp_cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )] = h_dirac_output_synthesis_state->q_cy_cross_dir_smooth; + sqr = L_shr( sqr, sub( sub( 31, sqr_exp ), h_dirac_output_synthesis_state->q_cy_cross_dir_smooth ) ); /*Q(31-sqr_exp)->h_dirac_output_synthesis_state->q_cy_cross_dir_smooth*/ + Q_temp_cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k] = h_dirac_output_synthesis_state->q_cy_cross_dir_smooth; move16(); } - h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )] = L_add( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )], sqr ); + h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k] = L_add( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k], sqr ); /*Q_temp_cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k]*/ move32(); } ELSE { - h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )] = L_add( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )], sqr ); + h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k] = L_add( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k], sqr ); /*Q(31-sqr_exp)*/ move32(); - Q_temp_cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )] = sub( 31, sqr_exp ); + Q_temp_cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k] = sub( 31, sqr_exp ); move16(); } } FOR( ; k < num_freq_bands; k++ ) { - mpy_diff = Mpy_32_32( diffuseness[k], L_sub( h_dirac_output_synthesis_params->diffuse_compensation_factor_decorr_fx, ONE_IN_Q29 ) ); // Q = q_diff - 1 - sqr_inp = L_add( L_shl( 1, sub( q_diffuseness, 1 ) ), mpy_diff ); + mpy_diff = Mpy_32_32( diffuseness[k], L_sub( h_dirac_output_synthesis_params->diffuse_compensation_factor_decorr_fx, ONE_IN_Q29 /*1 Q29*/ ) ); // Q = q_diffuseness - 1 + sqr_inp = L_add( L_shl( 1, sub( q_diffuseness, 1 ) ), mpy_diff ); // Q = q_diffuseness - 1 sqr_exp = sub( 31, sub( q_diffuseness, 1 ) ); - sqr = Sqrt32( sqr_inp, &sqr_exp ); - sqr = L_shr( sqr, 2 ); - IF( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )] != 0 ) + sqr = Sqrt32( sqr_inp, &sqr_exp ); /*Q(31-sqr_exp)*/ + sqr = L_shr( sqr, 2 ); /*Q(31-sqr_exp)*/ + IF( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k] != 0 ) { IF( LT_16( sub( 31, sqr_exp ), h_dirac_output_synthesis_state->q_cy_cross_dir_smooth ) ) { - h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )] = L_shr( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )], sub( h_dirac_output_synthesis_state->q_cy_cross_dir_smooth, sub( 31, sqr_exp ) ) ); + h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k] = L_shr( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k], sub( h_dirac_output_synthesis_state->q_cy_cross_dir_smooth, sub( 31, sqr_exp ) ) ); /*h_dirac_output_synthesis_state->q_cy_cross_dir_smooth, Q( 31- sqr_exp )*/ move32(); - Q_temp_cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )] = sub( 31, sqr_exp ); + Q_temp_cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k] = sub( 31, sqr_exp ); move16(); } ELSE { - sqr = L_shr( sqr, sub( sub( 31, sqr_exp ), h_dirac_output_synthesis_state->q_cy_cross_dir_smooth ) ); - Q_temp_cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )] = h_dirac_output_synthesis_state->q_cy_cross_dir_smooth; + sqr = L_shr( sqr, sub( sub( 31, sqr_exp ), h_dirac_output_synthesis_state->q_cy_cross_dir_smooth ) ); /*Q( 31- sqr_exp ), h_dirac_output_synthesis_state->q_cy_cross_dir_smooth*/ + Q_temp_cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k] = h_dirac_output_synthesis_state->q_cy_cross_dir_smooth; move16(); } - h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )] = L_add( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )], sqr ); + h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k] = L_add( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k], sqr ); /*Q_temp_cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k]*/ move32(); } ELSE { - h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )] = L_add( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )], sqr ); + h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k] = L_add( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k], sqr ); /*Q(31-sqr_exp)*/ move32(); - Q_temp_cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )] = sub( 31, sqr_exp ); + Q_temp_cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k] = sub( 31, sqr_exp ); move16(); } } } } - Word16 temp = MAX_16; + Word16 temp = MAX_16; /*q0*/ move16(); tmp16 = imult1616( num_freq_bands, num_channels_dir ); FOR( Word16 kk = 0; kk < tmp16; kk++ ) @@ -1756,7 +1763,7 @@ void ivas_dirac_dec_output_synthesis_process_slot_fx( move16(); FOR( Word16 kk = 0; kk < tmp16; kk++ ) { - h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[kk] = L_shl( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[kk], sub( temp, Q_temp_cy_cross_dir_smooth_fx[kk] ) ); + h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[kk] = L_shl( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[kk], sub( temp, Q_temp_cy_cross_dir_smooth_fx[kk] ) ); /*Q_temp_cy_cross_dir_smooth_fx[kk]->temp*/ move32(); } free( Q_temp_cy_cross_dir_smooth_fx ); @@ -1766,7 +1773,7 @@ void ivas_dirac_dec_output_synthesis_process_slot_fx( { FOR( Word16 kk = 0; kk < tmp16; kk++ ) { - h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[kk] = L_shl( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[kk], sub( temp_q, h_dirac_output_synthesis_state->q_cy_cross_dir_smooth ) ); + h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[kk] = L_shl( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[kk], sub( temp_q, h_dirac_output_synthesis_state->q_cy_cross_dir_smooth ) ); /*h_dirac_output_synthesis_state->q_cy_cross_dir_smooth ->temp_q*/ move32(); } h_dirac_output_synthesis_state->q_cy_cross_dir_smooth = temp_q; @@ -1775,33 +1782,37 @@ void ivas_dirac_dec_output_synthesis_process_slot_fx( FOR( ch_idx = s_min( 4, nchan_transport ); ch_idx < num_channels_dir; ch_idx++ ) { v_mult_fixed( h_dirac_output_synthesis_state->direct_power_factor_fx, - &h_dirac_output_synthesis_state->direct_responses_fx[i_mult( ch_idx, num_freq_bands )], + &h_dirac_output_synthesis_state->direct_responses_fx[ch_idx * num_freq_bands], aux_buf, - num_freq_bands ); + num_freq_bands ); /*temp_q*/ IF( NE_16( temp_q, h_dirac_output_synthesis_state->q_cy_cross_dir_smooth ) ) { - Scale_sig32( aux_buf, num_freq_bands, sub( h_dirac_output_synthesis_state->q_cy_cross_dir_smooth, temp_q ) ); + Scale_sig32( aux_buf, num_freq_bands, sub( h_dirac_output_synthesis_state->q_cy_cross_dir_smooth, temp_q ) ); /*temp_q->(h_dirac_output_synthesis_state->q_cy_cross_dir_smooth)*/ } v_add_fixed( aux_buf, - &h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[imult1616( ch_idx, num_freq_bands )], - &h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[imult1616( ch_idx, num_freq_bands )], - num_freq_bands, 0 ); // Todo:Hdrm + &h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[ch_idx * num_freq_bands], + &h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[ch_idx * num_freq_bands], + num_freq_bands, 0 ); /*Q(h_dirac_output_synthesis_state->q_cy_cross_dir_smooth)*/ } /*Diffuse gain*/ FOR( ch_idx = s_min( 4, nchan_transport ); ch_idx < num_channels_diff; ch_idx++ ) { - v_multc_fixed( h_dirac_output_synthesis_state->diffuse_power_factor_fx, - hDirACRend->diffuse_response_function_fx[ch_idx], - aux_buf, - num_freq_bands_diff ); - + v_multc_fixed_16( h_dirac_output_synthesis_state->diffuse_power_factor_fx, + hDirACRend->diffuse_response_function_fx[ch_idx], + aux_buf, + num_freq_bands_diff ); /* h_dirac_output_synthesis_state->diffuse_power_factor_q+15-15*/ + temp_q = h_dirac_output_synthesis_state->diffuse_power_factor_q; + IF( NE_16( temp_q, h_dirac_output_synthesis_state->q_cy_auto_diff_smooth ) ) + { + Scale_sig32( aux_buf, num_freq_bands, sub( h_dirac_output_synthesis_state->q_cy_auto_diff_smooth, temp_q ) ); /*temp_q->(h_dirac_output_synthesis_state->q_cy_auto_diff_smooth)*/ + } v_add_fixed( aux_buf, - &h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx[imult1616( ch_idx, num_freq_bands_diff )], - &h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx[imult1616( ch_idx, num_freq_bands_diff )], - num_freq_bands_diff, 0 ); // Todo:Hdrm + &h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx[ch_idx * num_freq_bands_diff], + &h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx[ch_idx * num_freq_bands_diff], + num_freq_bands_diff, 0 ); /*h_dirac_output_synthesis_state->q_cy_auto_diff_smooth*/ } return; @@ -1815,8 +1826,8 @@ void ivas_dirac_dec_output_synthesis_process_slot_fx( h_dirac_output_synthesis_state->direct_power_factor_fx, h_dirac_output_synthesis_state->diffuse_power_factor_fx ); - Scale_sig32( h_dirac_output_synthesis_state->direct_power_factor_fx, num_freq_bands, 2 ); - Scale_sig32( h_dirac_output_synthesis_state->diffuse_power_factor_fx, num_freq_bands, 2 ); + Scale_sig32( h_dirac_output_synthesis_state->direct_power_factor_fx, num_freq_bands, 2 ); /*q29->q31*/ + Scale_sig32( h_dirac_output_synthesis_state->diffuse_power_factor_fx, num_freq_bands, 2 ); /*q29->q31*/ h_dirac_output_synthesis_state->diffuse_power_factor_q = 31; move16(); h_dirac_output_synthesis_state->direct_power_factor_q = 31; @@ -1928,32 +1939,32 @@ void ivas_dirac_dec_output_synthesis_process_subframe_gain_shd_fx( /*Direct gain*/ FOR( ch_idx = 0; ch_idx < nchan_transport_foa; ch_idx++ ) { - v_multc_fixed( diffuseness, // Q30 - ONE_IN_Q31, // Q31 - &h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[imult1616( ch_idx, num_freq_bands )], // Q30 + v_multc_fixed( diffuseness, // Q30 + ONE_IN_Q31, // Q31 + &h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[ch_idx * num_freq_bands], // Q30 num_freq_bands ); - v_multc_fixed( &h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[imult1616( ch_idx, num_freq_bands )], // Q30 - L_sub( h_dirac_output_synthesis_params.diffuse_compensation_factor_fx, ONE_IN_Q27 ), // Q27 - &h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[imult1616( ch_idx, num_freq_bands )], // Q26 + v_multc_fixed( &h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[ch_idx * num_freq_bands], // Q30 + L_sub( h_dirac_output_synthesis_params.diffuse_compensation_factor_fx, ONE_IN_Q27 ), // Q27 + &h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[ch_idx * num_freq_bands], // Q26 num_freq_bands ); FOR( l = 0; l < num_freq_bands; l++ ) { exp = Q31 - Q26; - h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[add( imult1616( ch_idx, num_freq_bands ), l )] = - Sqrt32( L_add( ONE_IN_Q26, h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[add( imult1616( ch_idx, num_freq_bands ), l )] ), + h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + l] = + Sqrt32( L_add( ONE_IN_Q26 /*1 in Q26*/, h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + l] ), &exp ); // (Q31 - exp) move32(); } // Scale to bring in common Q-factor q_com = s_min( h_dirac_output_synthesis_state.q_cy_cross_dir_smooth_prev, sub( Q31, exp ) ); - Scale_sig32( &h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[imult1616( ch_idx, num_freq_bands )], + Scale_sig32( &h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[ch_idx * num_freq_bands], num_freq_bands, - sub( q_com, sub( Q31, exp ) ) ); - Scale_sig32( &h_dirac_output_synthesis_state.cy_cross_dir_smooth_prev_fx[imult1616( ch_idx, num_freq_bands )], + sub( q_com, sub( Q31, exp ) ) ); /*Q( Q31- exp)->q_com*/ + Scale_sig32( &h_dirac_output_synthesis_state.cy_cross_dir_smooth_prev_fx[ch_idx * num_freq_bands], num_freq_bands, - sub( q_com, h_dirac_output_synthesis_state.q_cy_cross_dir_smooth_prev ) ); + sub( q_com, h_dirac_output_synthesis_state.q_cy_cross_dir_smooth_prev ) ); /*h_dirac_output_synthesis_state.q_cy_cross_dir_smooth_prev->q_com*/ } /*Directional gain*/ @@ -1963,38 +1974,38 @@ void ivas_dirac_dec_output_synthesis_process_subframe_gain_shd_fx( { aux_buf[l] = L_sub( ONE_IN_Q30, diffuseness[l] ); // Q30 move32(); - ratio_float[l] = L_sub( ONE_IN_Q31, h_dirac_output_synthesis_state.direct_power_factor_fx[add( num_freq_bands, l )] ); // Q31 + ratio_float[l] = L_sub( ONE_IN_Q31, h_dirac_output_synthesis_state.direct_power_factor_fx[num_freq_bands + l] ); // Q31 move32(); - ratio_float[add( l, num_freq_bands )] = L_sub( ONE_IN_Q31, ratio_float[l] ); // Q31 + ratio_float[l + num_freq_bands] = L_sub( ONE_IN_Q31, ratio_float[l] ); // Q31 move32(); } v_mult_fixed( aux_buf, ratio_float, ratio_float, num_freq_bands ); //(Q30, Q31) -> Q30 v_mult_fixed( aux_buf, &ratio_float[num_freq_bands], &ratio_float[num_freq_bands], num_freq_bands ); //(Q30, Q31) -> Q30 - v_mult_fixed( ratio_float, // Q30 - &h_dirac_output_synthesis_state.direct_responses_fx[imult1616( ch_idx, num_freq_bands )], // Q31 - &h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[imult1616( ch_idx, num_freq_bands )], //(Q30, Q31) -> Q30 + v_mult_fixed( ratio_float, // Q30 + &h_dirac_output_synthesis_state.direct_responses_fx[ch_idx * num_freq_bands], // Q31 + &h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[ch_idx * num_freq_bands], //(Q30, Q31) -> Q30 num_freq_bands ); - v_mult_fixed( &ratio_float[num_freq_bands], // Q30 - &h_dirac_output_synthesis_state.direct_responses_fx[add( imult1616( ch_idx, num_freq_bands ), imult1616( num_freq_bands, num_channels_dir ) )], // Q31 - &h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[add( imult1616( ch_idx, num_freq_bands ), imult1616( num_freq_bands, num_channels_dir ) )], //(Q30, Q31) -> Q30 + v_mult_fixed( &ratio_float[num_freq_bands], // Q30 + &h_dirac_output_synthesis_state.direct_responses_fx[ch_idx * num_freq_bands + num_freq_bands * num_channels_dir], // Q31 + &h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + num_freq_bands * num_channels_dir], //(Q30, Q31) -> Q30 num_freq_bands ); // Scale to bring in common Q-factor q_com = s_min( h_dirac_output_synthesis_state.q_cy_cross_dir_smooth_prev, Q30 ); - Scale_sig32( &h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[imult1616( ch_idx, num_freq_bands )], + Scale_sig32( &h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[ch_idx * num_freq_bands], num_freq_bands, - sub( q_com, Q30 ) ); - Scale_sig32( &h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[add( imult1616( ch_idx, num_freq_bands ), imult1616( num_freq_bands, num_channels_dir ) )], + sub( q_com, Q30 ) ); /*Q30->q_com*/ + Scale_sig32( &h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + num_freq_bands * num_channels_dir], num_freq_bands, - sub( q_com, Q30 ) ); - Scale_sig32( &h_dirac_output_synthesis_state.cy_cross_dir_smooth_prev_fx[imult1616( ch_idx, num_freq_bands )], + sub( q_com, Q30 ) ); /*Q30->q_com*/ + Scale_sig32( &h_dirac_output_synthesis_state.cy_cross_dir_smooth_prev_fx[ch_idx * num_freq_bands], num_freq_bands, - sub( q_com, h_dirac_output_synthesis_state.q_cy_cross_dir_smooth_prev ) ); - Scale_sig32( &h_dirac_output_synthesis_state.cy_cross_dir_smooth_prev_fx[add( imult1616( ch_idx, num_freq_bands ), imult1616( num_freq_bands, num_channels_dir ) )], + sub( q_com, h_dirac_output_synthesis_state.q_cy_cross_dir_smooth_prev ) ); /*h_dirac_output_synthesis_state.q_cy_cross_dir_smooth_prev->q_com*/ + Scale_sig32( &h_dirac_output_synthesis_state.cy_cross_dir_smooth_prev_fx[ch_idx * num_freq_bands + num_freq_bands * num_channels_dir], num_freq_bands, - sub( q_com, h_dirac_output_synthesis_state.q_cy_cross_dir_smooth_prev ) ); + sub( q_com, h_dirac_output_synthesis_state.q_cy_cross_dir_smooth_prev ) ); /*h_dirac_output_synthesis_state.q_cy_cross_dir_smooth_prev->q_com*/ } h_dirac_output_synthesis_state.q_cy_cross_dir_smooth = q_com; @@ -2005,19 +2016,19 @@ void ivas_dirac_dec_output_synthesis_process_subframe_gain_shd_fx( /*Diffuse gain*/ FOR( ch_idx = nchan_transport_foa; ch_idx < num_channels_diff; ch_idx++ ) { - v_multc_fixed_16( h_dirac_output_synthesis_state.diffuse_power_factor_fx, // Q31 - hDirACRend->diffuse_response_function_fx[ch_idx], // Q15 - &h_dirac_output_synthesis_state.cy_auto_diff_smooth_fx[imult1616( ch_idx, num_freq_bands_diff )], // Q31 + v_multc_fixed_16( h_dirac_output_synthesis_state.diffuse_power_factor_fx, // Q31 + hDirACRend->diffuse_response_function_fx[ch_idx], // Q15 + &h_dirac_output_synthesis_state.cy_auto_diff_smooth_fx[ch_idx * num_freq_bands_diff], // Q31 num_freq_bands_diff ); // Scale to bring in common Q-factor q_com = s_min( h_dirac_output_synthesis_state.q_cy_auto_diff_smooth_prev, Q31 ); - Scale_sig32( &h_dirac_output_synthesis_state.cy_auto_diff_smooth_fx[imult1616( ch_idx, num_freq_bands_diff )], + Scale_sig32( &h_dirac_output_synthesis_state.cy_auto_diff_smooth_fx[ch_idx * num_freq_bands_diff], num_freq_bands_diff, - sub( q_com, Q31 ) ); - Scale_sig32( &h_dirac_output_synthesis_state.cy_auto_diff_smooth_prev_fx[imult1616( ch_idx, num_freq_bands_diff )], + sub( q_com, Q31 ) ); /*q31->q_com*/ + Scale_sig32( &h_dirac_output_synthesis_state.cy_auto_diff_smooth_prev_fx[ch_idx * num_freq_bands_diff], num_freq_bands_diff, - sub( q_com, h_dirac_output_synthesis_state.q_cy_auto_diff_smooth_prev ) ); + sub( q_com, h_dirac_output_synthesis_state.q_cy_auto_diff_smooth_prev ) ); /* h_dirac_output_synthesis_state.q_cy_auto_diff_smooth_prev->q_com*/ } h_dirac_output_synthesis_state.q_cy_auto_diff_smooth = q_com; @@ -2030,54 +2041,54 @@ void ivas_dirac_dec_output_synthesis_process_subframe_gain_shd_fx( /*Direct gain*/ FOR( ch_idx = 0; ch_idx < nchan_transport_foa; ch_idx++ ) { - v_mult_fixed( h_dirac_output_synthesis_state.diffuse_power_factor_fx, // Q31 - h_dirac_output_synthesis_state.diffuse_power_factor_fx, // Q31 - &h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[imult1616( ch_idx, num_freq_bands )], // Q31 + v_mult_fixed( h_dirac_output_synthesis_state.diffuse_power_factor_fx, // Q31 + h_dirac_output_synthesis_state.diffuse_power_factor_fx, // Q31 + &h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[ch_idx * num_freq_bands], // Q31 num_freq_bands ); - v_multc_fixed( &h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[imult1616( ch_idx, num_freq_bands )], // Q31 + v_multc_fixed( &h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[ch_idx * num_freq_bands], // Q31 L_sub( L_shr( h_dirac_output_synthesis_params.diffuse_compensation_factor_decorr_fx, Q3 ), ONE_IN_Q26 ), // Q26 - &h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[imult1616( ch_idx, num_freq_bands )], // Q26 + &h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[ch_idx * num_freq_bands], // Q26 num_freq_bands_diff ); - v_multc_fixed( &h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[add( imult1616( ch_idx, num_freq_bands ), num_freq_bands_diff )], // Q31 - L_sub( L_shr( h_dirac_output_synthesis_params.diffuse_compensation_factor_fx, Q1 ), ONE_IN_Q26 ), // Q26 - &h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[add( imult1616( ch_idx, num_freq_bands ), num_freq_bands_diff )], // Q26 + v_multc_fixed( &h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + num_freq_bands_diff], // Q31 + L_sub( L_shr( h_dirac_output_synthesis_params.diffuse_compensation_factor_fx, Q1 ), ONE_IN_Q26 ), // Q26 + &h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + num_freq_bands_diff], // Q26 num_freq_bands - num_freq_bands_diff ); FOR( l = 0; l < num_freq_bands; l++ ) { exp = Q31 - Q26; - h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[add( imult1616( ch_idx, num_freq_bands ), l )] = - Sqrt32( L_add( ONE_IN_Q26, h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[add( imult1616( ch_idx, num_freq_bands ), l )] ), + h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + l] = + Sqrt32( L_add( ONE_IN_Q26, h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + l] ), &exp ); // (Q31 - exp) move32(); } // Scale to bring in common Q-factor q_com = s_min( h_dirac_output_synthesis_state.q_cy_cross_dir_smooth_prev, sub( Q31, exp ) ); - Scale_sig32( &h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[imult1616( ch_idx, num_freq_bands )], + Scale_sig32( &h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[ch_idx * num_freq_bands], num_freq_bands, - sub( q_com, sub( Q31, exp ) ) ); - Scale_sig32( &h_dirac_output_synthesis_state.cy_cross_dir_smooth_prev_fx[imult1616( ch_idx, num_freq_bands )], + sub( q_com, sub( Q31, exp ) ) ); /*( Q31- exp )->q_com*/ + Scale_sig32( &h_dirac_output_synthesis_state.cy_cross_dir_smooth_prev_fx[ch_idx * num_freq_bands], num_freq_bands, - sub( q_com, h_dirac_output_synthesis_state.q_cy_cross_dir_smooth_prev ) ); + sub( q_com, h_dirac_output_synthesis_state.q_cy_cross_dir_smooth_prev ) ); /*h_dirac_output_synthesis_state.q_cy_cross_dir_smooth_prev->q_com*/ } /*Directional gain*/ FOR( ch_idx = nchan_transport_foa; ch_idx < num_channels_dir; ch_idx++ ) { - v_mult_fixed( h_dirac_output_synthesis_state.direct_power_factor_fx, // Q31 - &h_dirac_output_synthesis_state.direct_responses_fx[imult1616( ch_idx, num_freq_bands )], // Q31 - &h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[imult1616( ch_idx, num_freq_bands )], // Q31 + v_mult_fixed( h_dirac_output_synthesis_state.direct_power_factor_fx, // Q31 + &h_dirac_output_synthesis_state.direct_responses_fx[ch_idx * num_freq_bands], // Q31 + &h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[ch_idx * num_freq_bands], // Q31 num_freq_bands ); // Scale to bring in common Q-factor q_com = s_min( h_dirac_output_synthesis_state.q_cy_cross_dir_smooth_prev, Q31 ); - Scale_sig32( &h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[imult1616( ch_idx, num_freq_bands )], + Scale_sig32( &h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[ch_idx * num_freq_bands], num_freq_bands, - sub( q_com, Q31 ) ); - Scale_sig32( &h_dirac_output_synthesis_state.cy_cross_dir_smooth_prev_fx[imult1616( ch_idx, num_freq_bands )], + sub( q_com, Q31 ) ); /*q31->q_com*/ + Scale_sig32( &h_dirac_output_synthesis_state.cy_cross_dir_smooth_prev_fx[ch_idx * num_freq_bands], num_freq_bands, - sub( q_com, h_dirac_output_synthesis_state.q_cy_cross_dir_smooth_prev ) ); + sub( q_com, h_dirac_output_synthesis_state.q_cy_cross_dir_smooth_prev ) ); /*h_dirac_output_synthesis_state.q_cy_cross_dir_smooth_prev->q_com*/ } h_dirac_output_synthesis_state.q_cy_cross_dir_smooth = q_com; @@ -2088,19 +2099,19 @@ void ivas_dirac_dec_output_synthesis_process_subframe_gain_shd_fx( /*Diffuse gain*/ FOR( ch_idx = nchan_transport_foa; ch_idx < num_channels_diff; ch_idx++ ) { - v_multc_fixed_16( h_dirac_output_synthesis_state.diffuse_power_factor_fx, // Q31 - hDirACRend->diffuse_response_function_fx[ch_idx], // Q15 - &h_dirac_output_synthesis_state.cy_auto_diff_smooth_fx[imult1616( ch_idx, num_freq_bands_diff )], // Q31 + v_multc_fixed_16( h_dirac_output_synthesis_state.diffuse_power_factor_fx, // Q31 + hDirACRend->diffuse_response_function_fx[ch_idx], // Q15 + &h_dirac_output_synthesis_state.cy_auto_diff_smooth_fx[ch_idx * num_freq_bands_diff], // Q31 num_freq_bands_diff ); // Scale to bring in common Q-factor q_com = s_min( h_dirac_output_synthesis_state.q_cy_auto_diff_smooth_prev, Q31 ); - Scale_sig32( &h_dirac_output_synthesis_state.cy_auto_diff_smooth_fx[imult1616( ch_idx, num_freq_bands_diff )], + Scale_sig32( &h_dirac_output_synthesis_state.cy_auto_diff_smooth_fx[ch_idx * num_freq_bands_diff], num_freq_bands_diff, - sub( q_com, Q31 ) ); - Scale_sig32( &h_dirac_output_synthesis_state.cy_auto_diff_smooth_prev_fx[imult1616( ch_idx, num_freq_bands_diff )], + sub( q_com, Q31 ) ); /*q31->q_com*/ + Scale_sig32( &h_dirac_output_synthesis_state.cy_auto_diff_smooth_prev_fx[ch_idx * num_freq_bands_diff], num_freq_bands_diff, - sub( q_com, h_dirac_output_synthesis_state.q_cy_auto_diff_smooth_prev ) ); + sub( q_com, h_dirac_output_synthesis_state.q_cy_auto_diff_smooth_prev ) ); /*h_dirac_output_synthesis_state.q_cy_auto_diff_smooth_prev->q_com*/ } h_dirac_output_synthesis_state.q_cy_auto_diff_smooth = q_com; @@ -2228,9 +2239,9 @@ void ivas_dirac_dec_output_synthesis_process_subframe_gain_shd_fx( p_gains_dir_prev = h_dirac_output_synthesis_state.gains_dir_prev_fx; FOR( ch_idx = 0; ch_idx < num_channels_dir; ch_idx++ ) { - Scale_sig32( &h_dirac_output_synthesis_state.gains_dir_prev_fx[imult1616( ch_idx, num_freq_bands )], + Scale_sig32( &h_dirac_output_synthesis_state.gains_dir_prev_fx[ch_idx * num_freq_bands], num_freq_bands, - sub( h_dirac_output_synthesis_state.q_cy_cross_dir_smooth_prev, h_dirac_output_synthesis_state.gains_dir_prev_q ) ); + sub( h_dirac_output_synthesis_state.q_cy_cross_dir_smooth_prev, h_dirac_output_synthesis_state.gains_dir_prev_q ) ); /*h_dirac_output_synthesis_state.gains_dir_prev_q->h_dirac_output_synthesis_state.q_cy_cross_dir_smooth_prev*/ } h_dirac_output_synthesis_state.gains_dir_prev_q = h_dirac_output_synthesis_state.q_cy_cross_dir_smooth_prev; move16(); @@ -2239,14 +2250,14 @@ void ivas_dirac_dec_output_synthesis_process_subframe_gain_shd_fx( { p_proto_diff = h_dirac_output_synthesis_state.proto_diffuse_buffer_f_fx + shl( i_mult( buf_idx, i_mult( num_freq_bands, num_channels_diff ) ), Q1 ) + - shl( i_mult( ch_idx, num_freq_bands ), Q1 ); + shl( ch_idx * num_freq_bands, Q1 ); FOR( l = 0; l < num_freq_bands; l++ ) { g = Madd_32_32( Mpy_32_32( g1, ( *( p_gains_dir++ ) ) ), g2, ( *( p_gains_dir_prev++ ) ) ); // (Q31, p_gains_dir_q) -> (p_gains_dir_q) - output_real[add( imult1616( l, num_channels_dir ), ch_idx )] = Mpy_32_32( g, ( *( p_proto_diff++ ) ) ); // (p_gains_dir_q, p_proto_diff_q) -> (p_gains_dir_q + p_proto_diff_q - 31) + output_real[l * num_channels_dir + ch_idx] = Mpy_32_32( g, ( *( p_proto_diff++ ) ) ); // (p_gains_dir_q, p_proto_diff_q) -> (p_gains_dir_q + p_proto_diff_q - 31) move32(); - output_imag[add( imult1616( l, num_channels_dir ), ch_idx )] = Mpy_32_32( g, ( *( p_proto_diff++ ) ) ); // (p_gains_dir_q, p_proto_diff_q) -> (p_gains_dir_q + p_proto_diff_q - 31) + output_imag[l * num_channels_dir + ch_idx] = Mpy_32_32( g, ( *( p_proto_diff++ ) ) ); // (p_gains_dir_q, p_proto_diff_q) -> (p_gains_dir_q + p_proto_diff_q - 31) move32(); } } @@ -2274,7 +2285,7 @@ void ivas_dirac_dec_output_synthesis_process_subframe_gain_shd_fx( p_gains_dir_prev++; // ((p_gains_dir_q, p_proto_dir_q) >> 1) -> (p_gains_dir_q + p_proto_dir_q - 31) - output_real[add( imult1616( l, num_channels_dir ), ch_idx )] = + output_real[l * num_channels_dir + ch_idx] = Madd_32_32( Mpy_32_32( gs1, ( L_add( Mpy_32_32( 1903158016 /* 1.772454e+00f / 2 in Q31 */, ( *p_proto ) ), Mpy_32_32( 1098788992 /* 1.023327e+00f / 2 in Q31 */, ( *p_proto2 ) ) ) ) ), /* s1 */ gs2, L_sub( Mpy_32_32( 1903158016 /* 1.772454e+00f / 2 in Q31 */, ( *p_proto ) ), Mpy_32_32( 1098788992 /* 1.023327e+00f / 2 in Q31 */, ( *p_proto2 ) ) ) ); /* s2 */ @@ -2283,7 +2294,7 @@ void ivas_dirac_dec_output_synthesis_process_subframe_gain_shd_fx( p_proto2++; // ((p_gains_dir_q, p_proto_dir_q) >> 1) -> (p_gains_dir_q + p_proto_dir_q - 31) - output_imag[add( imult1616( l, num_channels_dir ), ch_idx )] = + output_imag[l * num_channels_dir + ch_idx] = Madd_32_32( Mpy_32_32( gs1, ( L_add( Mpy_32_32( 1903158016 /* 1.772454e+00f / 2 in Q31 */, ( *p_proto ) ), Mpy_32_32( 1098788992 /* 1.023327e+00f / 2 in Q31 */, ( *p_proto2 ) ) ) ) ), gs2, L_sub( Mpy_32_32( 1903158016 /* 1.772454e+00f / 2 in Q31 */, ( *p_proto ) ), Mpy_32_32( 1098788992 /* 1.023327e+00f / 2 in Q31 */, ( *p_proto2 ) ) ) ); @@ -2302,9 +2313,9 @@ void ivas_dirac_dec_output_synthesis_process_subframe_gain_shd_fx( p_gains_dir++; p_gains_dir_prev++; - output_real[add( imult1616( l, num_channels_dir ), ch_idx )] = L_shl( *( p_proto++ ), sub( h_dirac_output_synthesis_state.q_cy_cross_dir_smooth_prev, 31 ) ); // p_proto_dir_q -> (p_gains_dir_q + p_proto_dir_q - 31) + output_real[l * num_channels_dir + ch_idx] = L_shl( *( p_proto++ ), sub( h_dirac_output_synthesis_state.q_cy_cross_dir_smooth_prev, 31 ) ); // p_proto_dir_q -> (p_gains_dir_q + p_proto_dir_q - 31) move32(); - output_imag[add( imult1616( l, num_channels_dir ), ch_idx )] = L_shl( *( p_proto++ ), sub( h_dirac_output_synthesis_state.q_cy_cross_dir_smooth_prev, 31 ) ); // p_proto_dir_q -> (p_gains_dir_q + p_proto_dir_q - 31) + output_imag[l * num_channels_dir + ch_idx] = L_shl( *( p_proto++ ), sub( h_dirac_output_synthesis_state.q_cy_cross_dir_smooth_prev, 31 ) ); // p_proto_dir_q -> (p_gains_dir_q + p_proto_dir_q - 31) move32(); } } @@ -2320,9 +2331,9 @@ void ivas_dirac_dec_output_synthesis_process_subframe_gain_shd_fx( { g = Madd_32_32( Mpy_32_32( g1, ( *( p_gains_dir++ ) ) ), g2, ( *( p_gains_dir_prev++ ) ) ); // (Q31, p_gains_dir_q) -> (p_gains_dir_q) - output_real[add( imult1616( l, num_channels_dir ), ch_idx )] = Mpy_32_32( g, ( *( p_proto++ ) ) ); // (p_gains_dir_q, p_proto_dir_q) -> (p_gains_dir_q + p_proto_dir_q - 31) + output_real[l * num_channels_dir + ch_idx] = Mpy_32_32( g, ( *( p_proto++ ) ) ); // (p_gains_dir_q, p_proto_dir_q) -> (p_gains_dir_q + p_proto_dir_q - 31) move32(); - output_imag[add( imult1616( l, num_channels_dir ), ch_idx )] = Mpy_32_32( g, ( *( p_proto++ ) ) ); // (p_gains_dir_q, p_proto_dir_q) -> (p_gains_dir_q + p_proto_dir_q - 31) + output_imag[l * num_channels_dir + ch_idx] = Mpy_32_32( g, ( *( p_proto++ ) ) ); // (p_gains_dir_q, p_proto_dir_q) -> (p_gains_dir_q + p_proto_dir_q - 31) move32(); } } @@ -2333,9 +2344,9 @@ void ivas_dirac_dec_output_synthesis_process_subframe_gain_shd_fx( p_gains_dir++; p_gains_dir_prev++; - output_real[add( imult1616( l, num_channels_dir ), ch_idx )] = L_shl( *( p_proto++ ), sub( h_dirac_output_synthesis_state.q_cy_cross_dir_smooth_prev, 31 ) ); // p_proto_dir_q -> (p_gains_dir_q + p_proto_dir_q - 31) + output_real[l * num_channels_dir + ch_idx] = L_shl( *( p_proto++ ), sub( h_dirac_output_synthesis_state.q_cy_cross_dir_smooth_prev, 31 ) ); // p_proto_dir_q -> (p_gains_dir_q + p_proto_dir_q - 31) move32(); - output_imag[add( imult1616( l, num_channels_dir ), ch_idx )] = L_shl( *( p_proto++ ), sub( h_dirac_output_synthesis_state.q_cy_cross_dir_smooth_prev, 31 ) ); // p_proto_dir_q -> (p_gains_dir_q + p_proto_dir_q - 31) + output_imag[l * num_channels_dir + ch_idx] = L_shl( *( p_proto++ ), sub( h_dirac_output_synthesis_state.q_cy_cross_dir_smooth_prev, 31 ) ); // p_proto_dir_q -> (p_gains_dir_q + p_proto_dir_q - 31) move32(); } } @@ -2347,9 +2358,9 @@ void ivas_dirac_dec_output_synthesis_process_subframe_gain_shd_fx( p_gains_diff_prev = h_dirac_output_synthesis_state.gains_diff_prev_fx + i_mult( nchan_transport_foa, num_freq_bands_diff ); FOR( ch_idx = nchan_transport_foa; ch_idx < num_channels_diff; ch_idx++ ) { - Scale_sig32( &h_dirac_output_synthesis_state.gains_diff_prev_fx[imult1616( ch_idx, num_freq_bands_diff )], + Scale_sig32( &h_dirac_output_synthesis_state.gains_diff_prev_fx[ch_idx * num_freq_bands_diff], num_freq_bands_diff, - sub( h_dirac_output_synthesis_state.q_cy_auto_diff_smooth_prev, h_dirac_output_synthesis_state.gains_diff_prev_q ) ); + sub( h_dirac_output_synthesis_state.q_cy_auto_diff_smooth_prev, h_dirac_output_synthesis_state.gains_diff_prev_q ) ); /*h_dirac_output_synthesis_state.gains_diff_prev_q->h_dirac_output_synthesis_state.q_cy_auto_diff_smooth_prev*/ } h_dirac_output_synthesis_state.gains_diff_prev_q = h_dirac_output_synthesis_state.q_cy_auto_diff_smooth_prev; move16(); @@ -2369,14 +2380,14 @@ void ivas_dirac_dec_output_synthesis_process_subframe_gain_shd_fx( g = Madd_32_32( Mpy_32_32( g1, ( *( p_gains_diff++ ) ) ), g2, ( *( p_gains_diff_prev++ ) ) ); // (Q31, p_gains_diff_q) -> p_gains_diff_q // ((p_gains_diff_q, p_proto_diff_q) >> Q1) -> (p_gains_diff_q + p_proto_diff_q - 31) - output_real[add( imult1616( l, num_channels_dir ), hDirACRend->sba_map_tc[ch_idx] )] = - Madd_32_32( output_real[add( imult1616( l, num_channels_dir ), hDirACRend->sba_map_tc[ch_idx] )], + output_real[l * num_channels_dir + hDirACRend->sba_map_tc[ch_idx]] = + Madd_32_32( output_real[l * num_channels_dir + hDirACRend->sba_map_tc[ch_idx]], g, ( *( p_proto++ ) ) ); move32(); // ((p_gains_diff_q, p_proto_diff_q) >> Q1) -> (p_gains_diff_q + p_proto_diff_q - 31) - output_imag[add( imult1616( l, num_channels_dir ), hDirACRend->sba_map_tc[ch_idx] )] = - Madd_32_32( output_imag[add( imult1616( l, num_channels_dir ), hDirACRend->sba_map_tc[ch_idx] )], + output_imag[l * num_channels_dir + hDirACRend->sba_map_tc[ch_idx]] = + Madd_32_32( output_imag[l * num_channels_dir + hDirACRend->sba_map_tc[ch_idx]], g, ( *( p_proto++ ) ) ); move32(); } @@ -2396,6 +2407,7 @@ void ivas_dirac_dec_output_synthesis_process_subframe_gain_shd_fx( *-----------------------------------------------------------------*/ test(); + /*q=(p_gains_dir_q + p_proto_dir_q - 31)*/ IF( hDirACRend->hOutSetup.is_loudspeaker_setup && hDirACRend->hoa_decoder != NULL ) { Word32 *p_real, *p_imag; @@ -2405,8 +2417,8 @@ void ivas_dirac_dec_output_synthesis_process_subframe_gain_shd_fx( FOR( ch_idx = 0; ch_idx < hDirACRend->hOutSetup.nchan_out_woLFE; ch_idx++ ) { - p_real = RealBuffer[ch_idx][buf_idx]; - p_imag = ImagBuffer[ch_idx][buf_idx]; + p_real = RealBuffer[ch_idx][buf_idx]; /*q - Q2*/ + p_imag = ImagBuffer[ch_idx][buf_idx]; /*q - Q2*/ FOR( l = 0; l < num_freq_bands; l++ ) { @@ -2433,9 +2445,9 @@ void ivas_dirac_dec_output_synthesis_process_subframe_gain_shd_fx( { FOR( l = 0; l < num_freq_bands; l++ ) { - RealBuffer[ch_idx][buf_idx][l] = L_shr( output_real[add( imult1616( l, num_channels_dir ), ch_idx )], Q2 ); + RealBuffer[ch_idx][buf_idx][l] = L_shr( output_real[l * num_channels_dir + ch_idx], Q2 ); /* q - Q2*/ move32(); - ImagBuffer[ch_idx][buf_idx][l] = L_shr( output_imag[add( imult1616( l, num_channels_dir ), ch_idx )], Q2 ); + ImagBuffer[ch_idx][buf_idx][l] = L_shr( output_imag[l * num_channels_dir + ch_idx], Q2 ); /* q - Q2*/ move32(); } } @@ -2449,16 +2461,16 @@ void ivas_dirac_dec_output_synthesis_process_subframe_gain_shd_fx( /* store estimates for next synthesis block */ IF( hodirac_flag ) { - Copy32( h_dirac_output_synthesis_state.cy_cross_dir_smooth_prev_fx, h_dirac_output_synthesis_state.gains_dir_prev_fx, imult1616( num_freq_bands, num_channels_dir ) * DIRAC_HO_NUMSECTORS ); + Copy32( h_dirac_output_synthesis_state.cy_cross_dir_smooth_prev_fx, h_dirac_output_synthesis_state.gains_dir_prev_fx, imult1616( num_freq_bands, num_channels_dir ) * DIRAC_HO_NUMSECTORS ); /*h_dirac_output_synthesis_state.q_cy_cross_dir_smooth_prev*/ } ELSE { - Copy32( h_dirac_output_synthesis_state.cy_cross_dir_smooth_prev_fx, h_dirac_output_synthesis_state.gains_dir_prev_fx, imult1616( num_freq_bands, num_channels_dir ) ); + Copy32( h_dirac_output_synthesis_state.cy_cross_dir_smooth_prev_fx, h_dirac_output_synthesis_state.gains_dir_prev_fx, imult1616( num_freq_bands, num_channels_dir ) ); /*h_dirac_output_synthesis_state.q_cy_cross_dir_smooth_prev*/ } *q_cy_cross_dir_smooth_prev = h_dirac_output_synthesis_state.q_cy_cross_dir_smooth_prev; move16(); - Copy32( h_dirac_output_synthesis_state.cy_auto_diff_smooth_prev_fx, h_dirac_output_synthesis_state.gains_diff_prev_fx, imult1616( num_freq_bands_diff, num_channels_diff ) ); + Copy32( h_dirac_output_synthesis_state.cy_auto_diff_smooth_prev_fx, h_dirac_output_synthesis_state.gains_diff_prev_fx, imult1616( num_freq_bands_diff, num_channels_diff ) ); /* h_dirac_output_synthesis_state.q_cy_auto_diff_smooth_prev*/ *q_cy_auto_diff_smooth_prev = h_dirac_output_synthesis_state.q_cy_auto_diff_smooth_prev; move16(); @@ -2925,15 +2937,15 @@ void ivas_dirac_dec_output_synthesis_process_subframe_gain_shd( *------------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED void ivas_dirac_dec_output_synthesis_process_subframe_psd_ls_fx( - Word32 RealBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* i : LS signals */ - Word32 ImagBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* i : LS signals */ + Word32 RealBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* i : LS signals Q(q_Cldfb)*/ + Word32 ImagBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* i : LS signals Q(q_Cldfb)*/ SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom, /* i/o: common spatial renderer data handle */ DIRAC_REND_HANDLE hDirACRend, /* i/o: DirAC renderer handle */ const Word16 nbslots, /* i : number of slots to process */ - Word32 *diffuseness_vector, /* i : diffuseness (needed for direction smoothing)*/ - Word32 *reference_power_smooth, + Word32 *diffuseness_vector, /* i : diffuseness (needed for direction smoothing) Q(31)*/ + Word32 *reference_power_smooth, /*Q(q_reference_power_smooth)*/ Word16 *q_reference_power_smooth, - Word32 qualityBasedSmFactor, + Word32 qualityBasedSmFactor, /*Q(31)*/ const Word16 enc_param_start_band, Word16 *q_Cldfb ) { @@ -3036,11 +3048,11 @@ void ivas_dirac_dec_output_synthesis_process_subframe_psd_ls_fx( IF( diff_start_band != 0 ) { q_com = s_min( *q_reference_power_smooth, h_dirac_output_synthesis_state->q_cy_auto_diff_smooth ); - scale_sig32( reference_power_smooth, num_freq_bands, sub( q_com, *q_reference_power_smooth ) ); - scale_sig32( h_dirac_output_synthesis_state->reference_power_smooth_prev_fx, num_freq_bands, sub( q_com, *q_reference_power_smooth ) ); + scale_sig32( reference_power_smooth, num_freq_bands, sub( q_com, *q_reference_power_smooth ) ); /**q_reference_power_smooth->q_com*/ + scale_sig32( h_dirac_output_synthesis_state->reference_power_smooth_prev_fx, num_freq_bands, sub( q_com, *q_reference_power_smooth ) ); /**q_reference_power_smooth->q_com*/ scale_sig32( h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx, i_mult( num_freq_bands, nchan_target_psds ), - sub( q_com, h_dirac_output_synthesis_state->q_cy_auto_diff_smooth ) ); + sub( q_com, h_dirac_output_synthesis_state->q_cy_auto_diff_smooth ) ); /*h_dirac_output_synthesis_state->q_cy_auto_diff_smooth -> q_com*/ *q_reference_power_smooth = q_com; move16(); h_dirac_output_synthesis_state->reference_power_smooth_prev_q = q_com; @@ -3095,7 +3107,7 @@ void ivas_dirac_dec_output_synthesis_process_subframe_psd_ls_fx( q_target_power_y1 = add( sub( Q31, exp1 ), sub( q_com, sub( Q31, exp ) ) ); q_target_power_y1 = sub( q_target_power_y1, 1 ); - target_power_y = L_add( L_shl( target_power_y, sub( s_min( q_target_power_y1, q_target_power_y ), q_target_power_y ) ), L_shl( target_power_y1, sub( s_min( q_target_power_y1, q_target_power_y ), q_target_power_y1 ) ) ); + target_power_y = L_add( L_shl( target_power_y, sub( s_min( q_target_power_y1, q_target_power_y ), q_target_power_y ) ), L_shl( target_power_y1, sub( s_min( q_target_power_y1, q_target_power_y ), q_target_power_y1 ) ) ); /*min(q_target_power_y1, q_target_power_y )*/ exp = s_min( q_target_power_y1, q_target_power_y ); } ELSE @@ -3190,8 +3202,8 @@ void ivas_dirac_dec_output_synthesis_process_subframe_psd_ls_fx( exp = 0; move16(); - tmp = BASOP_Util_Divide3232_Scale( weightedDirectionSmoothness, L_add( sumWeight, EPSILON_FX ), &exp ); - smoothedDirectionSmoothness = L_shl_sat( L_deposit_l( tmp ), add( sub( Q31, Q15 ), exp ) ); // Q31 + tmp = BASOP_Util_Divide3232_Scale( weightedDirectionSmoothness, L_add( sumWeight, EPSILON_FX ), &exp ); /*Q(15-exp)*/ + smoothedDirectionSmoothness = L_shl_sat( L_deposit_l( tmp ), add( sub( Q31, Q15 ), exp ) ); // Q31 h_dirac_output_synthesis_state->direction_smoothness_prev_fx[l] = smoothedDirectionSmoothness; // Q31 move32(); @@ -3235,20 +3247,20 @@ void ivas_dirac_dec_output_synthesis_process_subframe_psd_ls_fx( IF( EQ_32( *( p_power_smooth_prev ), EPSILON_FX ) ) { p_power_smooth_prev++; - L_tmp = BASOP_Util_Divide3232_Scale_cadence( ONE_IN_Q31, EPSILON_FX, &exp ); - exp_arr[add( i_mult( k, num_freq_bands ), l )] = exp; + L_tmp = BASOP_Util_Divide3232_Scale_cadence( ONE_IN_Q31, EPSILON_FX, &exp ); /*Q=31-(exp-(31-q_proto_power_smooth))*/ + exp_arr[k * num_freq_bands + l] = exp; move16(); - *( p_power_smooth++ ) = L_tmp; + *( p_power_smooth++ ) = L_tmp; /*Q=31-(exp-(31-q_proto_power_smooth))*/ move32(); } ELSE { - L_tmp = BASOP_Util_Divide3232_Scale_cadence( ONE_IN_Q31, *( p_power_smooth_prev++ ), &exp ); - exp_arr[add( i_mult( k, num_freq_bands ), l )] = exp; + L_tmp = BASOP_Util_Divide3232_Scale_cadence( ONE_IN_Q31, *( p_power_smooth_prev++ ), &exp ); /*Q=31-(exp-(31-q_proto_power_smooth))*/ + exp_arr[k * num_freq_bands + l] = exp; move16(); - *( p_power_smooth++ ) = L_tmp; + *( p_power_smooth++ ) = L_tmp; /*Q=31-(exp-(31-q_proto_power_smooth))*/ move32(); } } @@ -3264,9 +3276,9 @@ void ivas_dirac_dec_output_synthesis_process_subframe_psd_ls_fx( { FOR( l = 0; l < num_freq_bands; l++ ) { - IF( GT_16( exp_arr[add( i_mult( k, num_freq_bands ), l )], min_exp ) ) + IF( GT_16( exp_arr[k * num_freq_bands + l], min_exp ) ) { - min_exp = exp_arr[add( i_mult( k, num_freq_bands ), l )]; + min_exp = exp_arr[k * num_freq_bands + l]; move16(); } } @@ -3279,7 +3291,7 @@ void ivas_dirac_dec_output_synthesis_process_subframe_psd_ls_fx( { FOR( l = 0; l < num_freq_bands; l++ ) { - *p_power_smooth = L_shr( *p_power_smooth, sub( min_exp, exp_arr[add( i_mult( k, num_freq_bands ), l )] ) ); + *p_power_smooth = L_shr( *p_power_smooth, sub( min_exp, exp_arr[k * num_freq_bands + l] ) ); /*(31-(exp-(31-q_proto_power_smooth)))->(31-(min_exp-(31-q_proto_power_smooth)))*/ move32(); p_power_smooth++; q_tmp = add( sub( Q31, min_exp ), sub( Q31, h_dirac_output_synthesis_state->proto_power_smooth_q ) ); @@ -3305,12 +3317,12 @@ void ivas_dirac_dec_output_synthesis_process_subframe_psd_ls_fx( { q_cy_auto_dir_smooth_prev_local[k] = getScaleFactor32( p_cy_auto_dir_smooth_prev + imult1616( k, num_freq_bands ), num_freq_bands ); move16(); - scale_sig32( p_cy_auto_dir_smooth_prev + imult1616( k, num_freq_bands ), num_freq_bands, q_cy_auto_dir_smooth_prev_local[k] ); + scale_sig32( p_cy_auto_dir_smooth_prev + imult1616( k, num_freq_bands ), num_freq_bands, q_cy_auto_dir_smooth_prev_local[k] ); /*q_cy_auto_dir_smooth_prev_local[k]+h_dirac_output_synthesis_state -> q_cy_auto_dir_smooth_prev*/ q_cy_auto_dir_smooth_prev_local[k] = add( q_cy_auto_dir_smooth_prev_local[k], h_dirac_output_synthesis_state->q_cy_auto_dir_smooth_prev ); move16(); q_com = s_min( q_cy_auto_dir_smooth_local[k], q_cy_auto_dir_smooth_prev_local[k] ); - scale_sig32( p_cy_auto_dir_smooth + imult1616( k, num_freq_bands ), num_freq_bands, sub( q_com, q_cy_auto_dir_smooth_local[k] ) ); - scale_sig32( p_cy_auto_dir_smooth_prev + imult1616( k, num_freq_bands ), num_freq_bands, sub( q_com, q_cy_auto_dir_smooth_prev_local[k] ) ); + scale_sig32( p_cy_auto_dir_smooth + imult1616( k, num_freq_bands ), num_freq_bands, sub( q_com, q_cy_auto_dir_smooth_local[k] ) ); /*q_cy_auto_dir_smooth_local -> q_com*/ + scale_sig32( p_cy_auto_dir_smooth_prev + imult1616( k, num_freq_bands ), num_freq_bands, sub( q_com, q_cy_auto_dir_smooth_prev_local[k] ) ); /*q_cy_auto_dir_smooth_prev_local -> q_com*/ q_cy_auto_dir_smooth_local[k] = q_cy_auto_dir_smooth_prev_local[k] = q_com; move16(); move16(); @@ -3320,8 +3332,8 @@ void ivas_dirac_dec_output_synthesis_process_subframe_psd_ls_fx( p_cy_cross_dir_smooth = h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx; p_cy_cross_dir_smooth_prev = h_dirac_output_synthesis_state->cy_cross_dir_smooth_prev_fx; q_com = s_min( h_dirac_output_synthesis_state->q_cy_cross_dir_smooth, h_dirac_output_synthesis_state->q_cy_cross_dir_smooth_prev ); - scale_sig32( p_cy_cross_dir_smooth, imult1616( nchan_out_woLFE, num_freq_bands ), sub( q_com, h_dirac_output_synthesis_state->q_cy_cross_dir_smooth ) ); - scale_sig32( p_cy_cross_dir_smooth_prev, imult1616( nchan_out_woLFE, num_freq_bands ), sub( q_com, h_dirac_output_synthesis_state->q_cy_cross_dir_smooth_prev ) ); + scale_sig32( p_cy_cross_dir_smooth, imult1616( nchan_out_woLFE, num_freq_bands ), sub( q_com, h_dirac_output_synthesis_state->q_cy_cross_dir_smooth ) ); /*h_dirac_output_synthesis_state->q_cy_cross_dir_smooth -> q_com*/ + scale_sig32( p_cy_cross_dir_smooth_prev, imult1616( nchan_out_woLFE, num_freq_bands ), sub( q_com, h_dirac_output_synthesis_state->q_cy_cross_dir_smooth_prev ) ); /*h_dirac_output_synthesis_state->q_cy_cross_dir_smooth_prev -> q_com*/ h_dirac_output_synthesis_state->q_cy_cross_dir_smooth = h_dirac_output_synthesis_state->q_cy_cross_dir_smooth_prev = q_com; move16(); move16(); @@ -3329,8 +3341,8 @@ void ivas_dirac_dec_output_synthesis_process_subframe_psd_ls_fx( p_cy_auto_diff_smooth = h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx; p_cy_auto_diff_smooth_prev = h_dirac_output_synthesis_state->cy_auto_diff_smooth_prev_fx; q_com = s_min( h_dirac_output_synthesis_state->q_cy_auto_diff_smooth, h_dirac_output_synthesis_state->q_cy_auto_diff_smooth_prev ); - scale_sig32( p_cy_auto_diff_smooth, imult1616( nchan_out_woLFE, num_freq_bands ), sub( q_com, h_dirac_output_synthesis_state->q_cy_auto_diff_smooth ) ); - scale_sig32( p_cy_auto_diff_smooth_prev, imult1616( nchan_out_woLFE, num_freq_bands ), sub( q_com, h_dirac_output_synthesis_state->q_cy_auto_diff_smooth_prev ) ); + scale_sig32( p_cy_auto_diff_smooth, imult1616( nchan_out_woLFE, num_freq_bands ), sub( q_com, h_dirac_output_synthesis_state->q_cy_auto_diff_smooth ) ); /*h_dirac_output_synthesis_state->q_cy_auto_diff_smooth -> q_com*/ + scale_sig32( p_cy_auto_diff_smooth_prev, imult1616( nchan_out_woLFE, num_freq_bands ), sub( q_com, h_dirac_output_synthesis_state->q_cy_auto_diff_smooth_prev ) ); /*h_dirac_output_synthesis_state->q_cy_auto_diff_smooth_prev -> q_com*/ h_dirac_output_synthesis_state->q_cy_auto_diff_smooth = h_dirac_output_synthesis_state->q_cy_auto_diff_smooth_prev = q_com; move16(); move16(); @@ -3352,7 +3364,7 @@ void ivas_dirac_dec_output_synthesis_process_subframe_psd_ls_fx( Mpy_32_32( g2, ( *( p_cy_cross_dir_smooth_prev ) ) ) ); // (Q31, q_cy_cross_dir_smooth_prev) -> q_cy_cross_dir_smooth_prev move32(); - power_smooth_temp = L_shl( *p_power_smooth, norm_l( *p_power_smooth ) ); + power_smooth_temp = L_shl( *p_power_smooth, norm_l( *p_power_smooth ) ); // proto_power_smooth_q + norm_l( *p_power_smooth ) L_tmp = Mpy_32_32( power_smooth_temp, ( *( p_cy_auto_dir_smooth_prev++ ) ) ); // proto_power_smooth_q + norm_l( *p_power_smooth ) ) + q_cy_auto_dir_smooth_prev_local - 31 exp = sub( Q31, sub( add( add( h_dirac_output_synthesis_state->proto_power_smooth_q, norm_l( *p_power_smooth ) ), q_cy_auto_dir_smooth_prev_local[k] ), @@ -3371,13 +3383,13 @@ void ivas_dirac_dec_output_synthesis_process_subframe_psd_ls_fx( } ELSE IF( GT_32( *( p_gains_dir ), W_extract_h( W_shl( W_mult_32_32( DIRAC_GAIN_LIMIT_Q26, L_shl( 1, h_dirac_output_synthesis_state->gains_dir_prev_q ) ), Q5 ) ) ) ) { - *( p_gains_dir ) = W_extract_h( W_shl( W_mult_32_32( DIRAC_GAIN_LIMIT_Q26, L_shl( 1, h_dirac_output_synthesis_state->gains_dir_prev_q ) ), Q5 ) ); + *( p_gains_dir ) = W_extract_h( W_shl( W_mult_32_32( DIRAC_GAIN_LIMIT_Q26, L_shl( 1, h_dirac_output_synthesis_state->gains_dir_prev_q ) ), Q5 ) ); /*26 + h_dirac_output_synthesis_state->gains_dir_prev_q + 1 + 5 - 32 -> h_dirac_output_synthesis_state->gains_dir_prev_q*/ move32(); } IF( *( p_cy_cross_dir_smooth_prev++ ) < 0 ) { - *( p_gains_dir ) = L_negate( *( p_gains_dir ) ); + *( p_gains_dir ) = L_negate( *( p_gains_dir ) ); /*h_dirac_output_synthesis_state->gains_dir_prev_q*/ move32(); } p_gains_dir++; @@ -3406,9 +3418,9 @@ void ivas_dirac_dec_output_synthesis_process_subframe_psd_ls_fx( *( p_gains_diff ) = 0; move32(); } - ELSE IF( GT_32( *( p_gains_diff ), W_extract_h( W_shl( W_mult_32_32( DIRAC_GAIN_LIMIT_Q26, L_shl( 1, h_dirac_output_synthesis_state->gains_diff_prev_q ) ), Q5 ) ) ) ) + ELSE IF( GT_32( *( p_gains_diff ), W_extract_h( W_shl( W_mult_32_32( DIRAC_GAIN_LIMIT_Q26, L_shl( 1, h_dirac_output_synthesis_state->gains_diff_prev_q ) ), Q5 ) ) ) ) /*h_dirac_output_synthesis_state->gains_diff_prev_q*/ { - *( p_gains_diff ) = W_extract_h( W_shl( W_mult_32_32( DIRAC_GAIN_LIMIT_Q26, L_shl( 1, h_dirac_output_synthesis_state->gains_diff_prev_q ) ), Q5 ) ); + *( p_gains_diff ) = W_extract_h( W_shl( W_mult_32_32( DIRAC_GAIN_LIMIT_Q26, L_shl( 1, h_dirac_output_synthesis_state->gains_diff_prev_q ) ), Q5 ) ); /*h_dirac_output_synthesis_state->gains_diff_prev_q*/ move32(); } p_gains_diff++; @@ -3422,10 +3434,10 @@ void ivas_dirac_dec_output_synthesis_process_subframe_psd_ls_fx( move32(); g2 = L_sub( ONE_IN_Q31, g1 ); // Q31 W_temp = W_add( W_mult_32_32( g1, ( *( p_cy_auto_dir_smooth++ ) ) ), - W_mult_32_32( g2, ( *( p_cy_auto_dir_smooth_prev ) ) ) ); + W_mult_32_32( g2, ( *( p_cy_auto_dir_smooth_prev ) ) ) ); /*32+q_cy_auto_dir_smooth_prev_local*/ q_tmp = W_norm( W_temp ); - L_tmp = W_extract_h( W_shl( W_temp, q_tmp ) ); // q_cy_auto_dir_smooth_prev_local + q_tmp - *( p_cy_auto_dir_smooth_prev++ ) = L_shr_r( L_tmp, q_tmp ); + L_tmp = W_extract_h( W_shl( W_temp, q_tmp ) ); // q_cy_auto_dir_smooth_prev_local + q_tmp + *( p_cy_auto_dir_smooth_prev++ ) = L_shr_r( L_tmp, q_tmp ); // q_cy_auto_dir_smooth_prev_local move32(); *( p_cy_cross_dir_smooth_prev ) = L_add( Mpy_32_32( g1, ( *( p_cy_cross_dir_smooth++ ) ) ), @@ -3448,15 +3460,15 @@ void ivas_dirac_dec_output_synthesis_process_subframe_psd_ls_fx( *( p_gains_dir ) = 0; move32(); } - ELSE IF( GT_32( *( p_gains_dir ), W_extract_h( W_shl( W_mult_32_32( DIRAC_GAIN_LIMIT_Q26, L_shl( 1, h_dirac_output_synthesis_state->gains_dir_prev_q ) ), Q5 ) ) ) ) + ELSE IF( GT_32( *( p_gains_dir ), W_extract_h( W_shl( W_mult_32_32( DIRAC_GAIN_LIMIT_Q26, L_shl( 1, h_dirac_output_synthesis_state->gains_dir_prev_q ) ), Q5 ) ) ) ) /*gains_dir_prev_q*/ { - *( p_gains_dir ) = W_extract_h( W_shl( W_mult_32_32( DIRAC_GAIN_LIMIT_Q26, L_shl( 1, h_dirac_output_synthesis_state->gains_dir_prev_q ) ), Q5 ) ); + *( p_gains_dir ) = W_extract_h( W_shl( W_mult_32_32( DIRAC_GAIN_LIMIT_Q26, L_shl( 1, h_dirac_output_synthesis_state->gains_dir_prev_q ) ), Q5 ) ); /*gains_dir_prev_q*/ move32(); } IF( *( p_cy_cross_dir_smooth_prev++ ) < 0 ) { - *( p_gains_dir ) = L_negate( *( p_gains_dir ) ); + *( p_gains_dir ) = L_negate( *( p_gains_dir ) ); /*gains_dir_prev_q*/ move32(); } p_gains_dir++; @@ -3466,14 +3478,14 @@ void ivas_dirac_dec_output_synthesis_process_subframe_psd_ls_fx( Mpy_32_32( g2, ( *( p_cy_auto_diff_smooth_prev ) ) ) ); // (Q31, q_cy_auto_diff_smooth_prev) -> q_cy_auto_diff_smooth_prev move32(); - power_smooth_temp = L_shl( *p_power_smooth, norm_l( *p_power_smooth ) ); + power_smooth_temp = L_shl( *p_power_smooth, norm_l( *p_power_smooth ) ); // proto_power_smooth_q + norm_l( *p_power_smooth ) L_tmp = Mpy_32_32( power_smooth_temp, ( *( p_cy_auto_diff_smooth_prev++ ) ) ); // proto_power_smooth_q + norm_l( *p_power_smooth ) ) + q_cy_auto_diff_smooth_prev - 31 exp = sub( Q31, sub( add( add( h_dirac_output_synthesis_state->proto_power_smooth_q, norm_l( *p_power_smooth ) ), h_dirac_output_synthesis_state->q_cy_auto_diff_smooth_prev ), Q31 ) ); p_power_smooth++; - *( p_gains_diff ) = Sqrt32( L_tmp, &exp ); + *( p_gains_diff ) = Sqrt32( L_tmp, &exp ); /*31-exp*/ move32(); *( p_gains_diff ) = L_shl_sat( *( p_gains_diff ), sub( h_dirac_output_synthesis_state->gains_diff_prev_q, sub( Q31, exp ) ) ); // gains_diff_prev_q move32(); @@ -3483,9 +3495,9 @@ void ivas_dirac_dec_output_synthesis_process_subframe_psd_ls_fx( *( p_gains_diff ) = 0; move32(); } - ELSE IF( GT_32( *( p_gains_diff ), W_extract_h( W_shl( W_mult_32_32( DIRAC_GAIN_LIMIT_Q26, L_shl( 1, h_dirac_output_synthesis_state->gains_diff_prev_q ) ), Q5 ) ) ) ) + ELSE IF( GT_32( *( p_gains_diff ), W_extract_h( W_shl( W_mult_32_32( DIRAC_GAIN_LIMIT_Q26, L_shl( 1, h_dirac_output_synthesis_state->gains_diff_prev_q ) ), Q5 ) ) ) ) // gains_diff_prev_q { - *( p_gains_diff ) = W_extract_h( W_shl( W_mult_32_32( DIRAC_GAIN_LIMIT_Q26, L_shl( 1, h_dirac_output_synthesis_state->gains_diff_prev_q ) ), Q5 ) ); + *( p_gains_diff ) = W_extract_h( W_shl( W_mult_32_32( DIRAC_GAIN_LIMIT_Q26, L_shl( 1, h_dirac_output_synthesis_state->gains_diff_prev_q ) ), Q5 ) ); // gains_diff_prev_q move32(); } p_gains_diff++; @@ -3567,7 +3579,7 @@ void ivas_dirac_dec_output_synthesis_process_subframe_psd_ls_fx( { g = L_add( Mpy_32_32( g1, *( p_gain_1++ ) ), Mpy_32_32( g2, *( p_gain_2++ ) ) ); // (Q31, gains_diff_prev_q) -> gains_diff_prev_q Cldfb_RealBuffer64_fx[k][buf_idx][l] = W_add( Cldfb_RealBuffer64_fx[k][buf_idx][l], - W_mult0_32_32( g, ( *( p_power_smooth++ ) ) ) ); // (gains_diff_prev_q, q_proto_direct_buffer) >> Q1 -> gains_diff_prev_q + q_proto_direct_buffer - 32 + W_mult0_32_32( g, ( *( p_power_smooth++ ) ) ) ); // (gains_diff_prev_q, q_proto_direct_buffer) -> gains_diff_prev_q + q_proto_direct_buffer move64(); if ( LT_64( W_temp, W_abs( Cldfb_RealBuffer64_fx[k][buf_idx][l] ) ) ) @@ -3576,12 +3588,12 @@ void ivas_dirac_dec_output_synthesis_process_subframe_psd_ls_fx( } Cldfb_ImagBuffer64_fx[k][buf_idx][l] = W_add( Cldfb_ImagBuffer64_fx[k][buf_idx][l], - W_mult0_32_32( g, ( *( p_power_smooth++ ) ) ) ); // (gains_diff_prev_q, q_proto_direct_buffer) >> Q1 -> gains_diff_prev_q + q_proto_direct_buffer - 32 + W_mult0_32_32( g, ( *( p_power_smooth++ ) ) ) ); // (gains_diff_prev_q, q_proto_direct_buffer) -> gains_diff_prev_q + q_proto_direct_buffer move64(); if ( LT_64( W_temp, W_abs( Cldfb_ImagBuffer64_fx[k][buf_idx][l] ) ) ) { - W_temp = W_abs( Cldfb_ImagBuffer64_fx[k][buf_idx][l] ); + W_temp = W_abs( Cldfb_ImagBuffer64_fx[k][buf_idx][l] ); // gains_diff_prev_q + q_proto_direct_buffer } } } @@ -3593,9 +3605,9 @@ void ivas_dirac_dec_output_synthesis_process_subframe_psd_ls_fx( { FOR( l = 0; l < num_freq_bands; l++ ) { - RealBuffer[k][buf_idx][l] = W_extract_h( W_shl( Cldfb_RealBuffer64_fx[k][buf_idx][l], q_align ) ); + RealBuffer[k][buf_idx][l] = W_extract_h( W_shl( Cldfb_RealBuffer64_fx[k][buf_idx][l], q_align ) ); /*( ( ( h_dirac_output_synthesis_state->proto_direct_buffer_f_q+h_dirac_output_synthesis_state->gains_dir_prev_q )+ q_align )- 32 )*/ move32(); - ImagBuffer[k][buf_idx][l] = W_extract_h( W_shl( Cldfb_ImagBuffer64_fx[k][buf_idx][l], q_align ) ); + ImagBuffer[k][buf_idx][l] = W_extract_h( W_shl( Cldfb_ImagBuffer64_fx[k][buf_idx][l], q_align ) ); /*( ( ( h_dirac_output_synthesis_state->proto_direct_buffer_f_q+h_dirac_output_synthesis_state->gains_dir_prev_q )+ q_align )- 32 )*/ move32(); } } @@ -3609,8 +3621,8 @@ void ivas_dirac_dec_output_synthesis_process_subframe_psd_ls_fx( *-----------------------------------------------------------------*/ /* store estimates for next synthesis block */ - Copy32( gains_dir, h_dirac_output_synthesis_state->gains_dir_prev_fx, imult1616( num_freq_bands, nchan_out_woLFE ) ); - Copy32( gains_diff, h_dirac_output_synthesis_state->gains_diff_prev_fx, imult1616( num_freq_bands, nchan_out_woLFE ) ); + Copy32( gains_dir, h_dirac_output_synthesis_state->gains_dir_prev_fx, imult1616( num_freq_bands, nchan_out_woLFE ) ); /*gains_dir_prev_q*/ + Copy32( gains_diff, h_dirac_output_synthesis_state->gains_diff_prev_fx, imult1616( num_freq_bands, nchan_out_woLFE ) ); /*gains_diff_prev_q*/ /* reset values */ set_zero_fx( h_dirac_output_synthesis_state->proto_power_smooth_fx, imult1616( num_freq_bands, num_protos_dir ) ); @@ -3622,7 +3634,7 @@ void ivas_dirac_dec_output_synthesis_process_subframe_psd_ls_fx( minimum_fx( q_cy_auto_dir_smooth_prev_local, nchan_out_woLFE, &h_dirac_output_synthesis_state->q_cy_auto_dir_smooth_prev ); FOR( k = 0; k < nchan_out_woLFE; k++ ) { - scale_sig32( h_dirac_output_synthesis_state->cy_auto_dir_smooth_prev_fx + ( k * num_freq_bands ), num_freq_bands, sub( h_dirac_output_synthesis_state->q_cy_auto_dir_smooth_prev, q_cy_auto_dir_smooth_prev_local[k] ) ); + scale_sig32( h_dirac_output_synthesis_state->cy_auto_dir_smooth_prev_fx + ( k * num_freq_bands ), num_freq_bands, sub( h_dirac_output_synthesis_state->q_cy_auto_dir_smooth_prev, q_cy_auto_dir_smooth_prev_local[k] ) ); /*q_cy_auto_dir_smooth_prev_local[k] -> h_dirac_output_synthesis_state->q_cy_auto_dir_smooth_prev*/ } set_zero_fx( h_dirac_output_synthesis_state->cy_auto_dir_smooth_fx, imult1616( num_freq_bands, nchan_out_woLFE ) ); @@ -4003,9 +4015,9 @@ void ivas_dirac_dec_output_synthesis_process_subframe_psd_ls( #ifdef IVAS_FLOAT_FIXED static void ivas_dirac_dec_get_response_split_order_fx( - const Word16 azimuth, - const Word16 elevation, - Word32 *response, + const Word16 azimuth, /*q0*/ + const Word16 elevation, /*q0*/ + Word32 *response, /*q_response*/ const Word16 shd_rot_max_order, const Word32 *p_Rmat /* Q30 */, Word16 *q_response ) @@ -4040,13 +4052,13 @@ static void ivas_dirac_dec_get_response_split_order_fx( IF( GT_16( index_elevation, 90 ) ) { - e = -ONE_IN_Q14; + e = -ONE_IN_Q14; /*-1 in Q14*/ move16(); el = sub( 180, index_elevation ); } ELSE { - e = ONE_IN_Q14; + e = ONE_IN_Q14; /*1 in Q14*/ move16(); el = index_elevation; move16(); @@ -4055,21 +4067,21 @@ static void ivas_dirac_dec_get_response_split_order_fx( IF( GT_16( index_azimuth, 180 ) ) { az = sub( 360, index_azimuth ); - f = -ONE_IN_Q30; + f = -ONE_IN_Q30; /*-1 Q30*/ move32(); } ELSE { az = index_azimuth; move16(); - f = ONE_IN_Q30; + f = ONE_IN_Q30; /*1 Q30*/ move32(); } // dirac_gains_trg_term_int Q30 cos_1 = L_shr( dirac_gains_trg_term_int[az][0], 1 ); // Q29 cos_2 = L_shl( Mpy_32_32( cos_1, cos_1 ), 2 ); // Q29 - sin_1 = Mpy_32_32( f, dirac_gains_trg_term_int[az][1] ); // Q29] + sin_1 = Mpy_32_32( f, dirac_gains_trg_term_int[az][1] ); // Q29 cos_az[0] = cos_1; // Q29 move32(); @@ -4173,13 +4185,13 @@ static void ivas_dirac_dec_get_response_split_order_fx( IF( GT_16( index_elevation, 90 ) ) { - e = -ONE_IN_Q14; + e = -ONE_IN_Q14; /*-1 Q14*/ move16(); el = sub( 180, index_elevation ); } ELSE { - e = ONE_IN_Q14; + e = ONE_IN_Q14; /*1 Q14*/ move16(); el = index_elevation; move16(); @@ -4188,14 +4200,14 @@ static void ivas_dirac_dec_get_response_split_order_fx( IF( GT_16( index_azimuth, 180 ) ) { az = sub( 360, index_azimuth ); - f = -ONE_IN_Q30; + f = -ONE_IN_Q30; /*-1 Q30*/ move32(); } ELSE { az = index_azimuth; move16(); - f = ONE_IN_Q30; + f = ONE_IN_Q30; /*1 Q30*/ move32(); } @@ -4452,10 +4464,10 @@ void ivas_dirac_dec_compute_directional_responses_fx( const Word16 *azimuth, const Word16 *elevation, const Word16 md_idx, - const Word32 *surCohRatio_fx, + const Word32 *surCohRatio_fx, /*i:Q_surCohRatio*/ Word16 Q_surCohRatio, const Word16 shd_rot_max_order, /* i : split-order rotation method */ - const Word32 *p_Rmat, /* i : rotation matrix */ + const Word32 *p_Rmat, /* i : rotation matrix Q30*/ const Word16 hodirac_flag /* i : flag to indicate HO-DirAC mode */ ) { @@ -4515,9 +4527,9 @@ void ivas_dirac_dec_compute_directional_responses_fx( move16(); IF( EQ_16( hSpatParamRendCom->numParametricDirections, 2 ) ) { - azimuth2 = hSpatParamRendCom->azimuth2[md_idx]; + azimuth2 = hSpatParamRendCom->azimuth2[md_idx]; /*q0*/ move16(); - elevation2 = hSpatParamRendCom->elevation2[md_idx]; + elevation2 = hSpatParamRendCom->elevation2[md_idx]; /*q0*/ move16(); } @@ -4527,11 +4539,15 @@ void ivas_dirac_dec_compute_directional_responses_fx( FOR( k = 0; k < hSpatParamRendCom->num_freq_bands; ++k ) { + test(); if ( masa_band_mapping != NULL && EQ_16( k, MASA_band_grouping_24[masa_band_mapping[add( codingBand, 1 )]] ) ) { codingBand = add( codingBand, 1 ); } + test(); + test(); + test(); IF( masa_band_mapping != NULL && GT_16( k, MASA_band_grouping_24[masa_band_mapping[codingBand]] ) && LT_16( k, MASA_band_grouping_24[masa_band_mapping[add( codingBand, 1 )]] ) && NE_16( k, hDirACRend->h_output_synthesis_psd_params.max_band_decorr ) ) @@ -4541,20 +4557,20 @@ void ivas_dirac_dec_compute_directional_responses_fx( { mvr2r_inc_fixed( &hDirACRend->h_output_synthesis_psd_state.direct_responses_square_fx[k - 1], hSpatParamRendCom->num_freq_bands, &hDirACRend->h_output_synthesis_psd_state.direct_responses_square_fx[k], - hSpatParamRendCom->num_freq_bands, num_channels_dir ); + hSpatParamRendCom->num_freq_bands, num_channels_dir ); /*direct_response_square_q*/ } mvr2r_inc_fixed( &hDirACRend->h_output_synthesis_psd_state.direct_responses_fx[k - 1], hSpatParamRendCom->num_freq_bands, &hDirACRend->h_output_synthesis_psd_state.direct_responses_fx[k], - hSpatParamRendCom->num_freq_bands, num_channels_dir ); + hSpatParamRendCom->num_freq_bands, num_channels_dir ); /*direct_response_q*/ } ELSE { /* HOA3 PANNING */ IF( EQ_16( hDirACRend->panningConf, DIRAC_PANNING_HOA3 ) ) { - set32_fx( direct_response_hoa_fx, ONE_IN_Q29, MAX_OUTPUT_CHANNELS ); - set32_fx( direct_response_dir2_fx, ONE_IN_Q29, MAX_OUTPUT_CHANNELS ); + set32_fx( direct_response_hoa_fx, ONE_IN_Q29, MAX_OUTPUT_CHANNELS ); /*q29*/ + set32_fx( direct_response_dir2_fx, ONE_IN_Q29, MAX_OUTPUT_CHANNELS ); /*q29*/ Q_direct_response_hoa = Q29; move16(); @@ -4590,11 +4606,11 @@ void ivas_dirac_dec_compute_directional_responses_fx( test(); IF( masa_band_mapping == NULL && EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) { - mvr2r_inc_fixed( direct_response_hoa_fx, 1, &hDirACRend->h_output_synthesis_psd_state.direct_responses_fx[k], hSpatParamRendCom->num_freq_bands, num_channels_dir ); + mvr2r_inc_fixed( direct_response_hoa_fx, 1, &hDirACRend->h_output_synthesis_psd_state.direct_responses_fx[k], hSpatParamRendCom->num_freq_bands, num_channels_dir ); /*Q_direct_response_hoa*/ IF( hodirac_flag ) { - mvr2r_inc_fixed( direct_response_dir2_fx, 1, &hDirACRend->h_output_synthesis_psd_state.direct_responses_fx[add( k, i_mult( hSpatParamRendCom->num_freq_bands, num_channels_dir ) )], hSpatParamRendCom->num_freq_bands, num_channels_dir ); + mvr2r_inc_fixed( direct_response_dir2_fx, 1, &hDirACRend->h_output_synthesis_psd_state.direct_responses_fx[k + hSpatParamRendCom->num_freq_bands * num_channels_dir], hSpatParamRendCom->num_freq_bands, num_channels_dir ); /*Q_direct_response_dir2*/ } } ELSE IF( ( ( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) && ( masa_band_mapping != NULL ) ) || @@ -4603,7 +4619,7 @@ void ivas_dirac_dec_compute_directional_responses_fx( /* Synthesize the first direction */ IF( GT_16( Q_direct_response_hoa, Q29 ) ) { - Scale_sig32( direct_response_hoa_fx, MAX_OUTPUT_CHANNELS, sub( Q_direct_response_hoa, Q29 ) ); + Scale_sig32( direct_response_hoa_fx, MAX_OUTPUT_CHANNELS, sub( Q_direct_response_hoa, Q29 ) ); /*Q_direct_response_hoa->q29*/ Q_direct_response_hoa = Q29; move16(); exp_direct_response_hoa = sub( 31, Q_direct_response_hoa ); @@ -4617,7 +4633,7 @@ void ivas_dirac_dec_compute_directional_responses_fx( { IF( GT_16( Q_direct_response_dir2, Q29 ) ) { - Scale_sig32( direct_response_dir2_fx, MAX_OUTPUT_CHANNELS, sub( Q_direct_response_dir2, Q29 ) ); + Scale_sig32( direct_response_dir2_fx, MAX_OUTPUT_CHANNELS, sub( Q_direct_response_dir2, Q29 ) ); /*Q_direct_response_dir2->q29*/ Q_direct_response_dir2 = Q29; move16(); exp_direct_response_dir2 = sub( 31, Q_direct_response_dir2 ); @@ -4627,7 +4643,7 @@ void ivas_dirac_dec_compute_directional_responses_fx( exp_direct_response_hoa = sub( 31, Q_direct_response_hoa ); /* Combine gains from the two directions */ - totalDirect_fx = L_add( hSpatParamRendCom->energy_ratio1_fx[md_idx][k], hSpatParamRendCom->energy_ratio2_fx[md_idx][k] ); + totalDirect_fx = L_add( hSpatParamRendCom->energy_ratio1_fx[md_idx][k], hSpatParamRendCom->energy_ratio2_fx[md_idx][k] ); /*q30*/ IF( totalDirect_fx == 0 ) { totalDirect_fx = EPSILON_FIX; @@ -4635,12 +4651,12 @@ void ivas_dirac_dec_compute_directional_responses_fx( } Word16 var_a, var_b, exp_1, exp_2; - var_a = BASOP_Util_Divide3232_Scale( hSpatParamRendCom->energy_ratio1_fx[md_idx][k], totalDirect_fx, &exp_1 ); - var_b = BASOP_Util_Divide3232_Scale( hSpatParamRendCom->energy_ratio2_fx[md_idx][k], totalDirect_fx, &exp_2 ); + var_a = BASOP_Util_Divide3232_Scale( hSpatParamRendCom->energy_ratio1_fx[md_idx][k], totalDirect_fx, &exp_1 ); /*15-exp_1*/ + var_b = BASOP_Util_Divide3232_Scale( hSpatParamRendCom->energy_ratio2_fx[md_idx][k], totalDirect_fx, &exp_2 ); /*15-exp_2*/ - directRatio_fx[0] = L_deposit_h( var_a ); + directRatio_fx[0] = L_deposit_h( var_a ); /*15-exp_1+16*/ move32(); - directRatio_fx[1] = L_deposit_h( var_b ); + directRatio_fx[1] = L_deposit_h( var_b ); /*15-exp_2+16*/ move32(); Word32 temp_a; @@ -4650,13 +4666,13 @@ void ivas_dirac_dec_compute_directional_responses_fx( FOR( l = 0; l < num_channels_dir; l++ ) { - direct_response_hoa_fx[l] = Mpy_32_32( direct_response_hoa_fx[l], directRatio_fx[0] ); + direct_response_hoa_fx[l] = Mpy_32_32( direct_response_hoa_fx[l], directRatio_fx[0] ); /*Q(Q_direct_response_hoa+31-exp_1-31)*/ move32(); exp_arr[l] = add( exp_1, sub( 31, Q_direct_response_hoa ) ); move16(); - temp_a = Mpy_32_32( directRatio_fx[1], direct_response_dir2_fx[l] ); + temp_a = Mpy_32_32( directRatio_fx[1], direct_response_dir2_fx[l] ); /*Q(Q_direct_response_dir2+31-exp_2-31)*/ exp_temp_a = add( exp_2, sub( 31, Q_direct_response_dir2 ) ); - direct_response_hoa_fx[l] = BASOP_Util_Add_Mant32Exp( direct_response_hoa_fx[l], exp_arr[l], temp_a, exp_temp_a, &final_exp ); + direct_response_hoa_fx[l] = BASOP_Util_Add_Mant32Exp( direct_response_hoa_fx[l], exp_arr[l], temp_a, exp_temp_a, &final_exp ); /*Q(31-final_exp)*/ move32(); exp_arr[l] = final_exp; move16(); @@ -4667,7 +4683,7 @@ void ivas_dirac_dec_compute_directional_responses_fx( maximum_fx( exp_arr, MAX_OUTPUT_CHANNELS, &max_exp ); FOR( l = 0; l < MAX_OUTPUT_CHANNELS; l++ ) { - direct_response_hoa_fx[l] = L_shr( direct_response_hoa_fx[l], sub( max_exp, exp_arr[l] ) ); + direct_response_hoa_fx[l] = L_shr( direct_response_hoa_fx[l], sub( max_exp, exp_arr[l] ) ); /*Q(31-exp_arr[l])->Q(31-max_exp)*/ move32(); } exp_direct_response_hoa = max_exp; @@ -4707,8 +4723,8 @@ void ivas_dirac_dec_compute_directional_responses_fx( set16_fx( exp_arr, 0, MAX_OUTPUT_CHANNELS ); FOR( l = 0; l < num_channels_dir; l++ ) { - temp_1 = Mpy_32_32( direct_response_temp_fx[l], hMasaIsm->energy_ratio_ism_fx[dir][md_idx][k] ); // Q28 - direct_response_ism_fx[l] = BASOP_Util_Add_Mant32Exp( direct_response_ism_fx[l], exp_direct_response_ism, temp_1, exp_direct_response_temp + 1, &exp_temp ); + temp_1 = Mpy_32_32( direct_response_temp_fx[l], hMasaIsm->energy_ratio_ism_fx[dir][md_idx][k] ); // Q28 + direct_response_ism_fx[l] = BASOP_Util_Add_Mant32Exp( direct_response_ism_fx[l], exp_direct_response_ism, temp_1, add( exp_direct_response_temp, 1 ), &exp_temp ); //(31-exp_temp) move32(); exp_arr[l] = exp_temp; move16(); @@ -4718,38 +4734,38 @@ void ivas_dirac_dec_compute_directional_responses_fx( maximum_fx( exp_arr, num_channels_dir, &max_exp ); FOR( l = 0; l < num_channels_dir; l++ ) { - direct_response_ism_fx[l] = L_shr( direct_response_ism_fx[l], max_exp - exp_arr[l] ); + direct_response_ism_fx[l] = L_shr( direct_response_ism_fx[l], sub( max_exp, exp_arr[l] ) ); /*Q(31- exp_arr[l])->Q(31-max_exp)*/ move32(); } exp_direct_response_ism = max_exp; move16(); } Word16 exp_1, exp_2; - masaDirect_fx = hSpatParamRendCom->energy_ratio1_fx[md_idx][k]; + masaDirect_fx = hSpatParamRendCom->energy_ratio1_fx[md_idx][k]; /*q30*/ move32(); if ( masaDirect_fx == 0 ) { - masaDirect_fx = L_add( masaDirect_fx, EPSILLON_FX ); + masaDirect_fx = L_add( masaDirect_fx, EPSILLON_FX ); /*q30*/ } if ( EQ_16( hSpatParamRendCom->numParametricDirections, 2 ) ) { - masaDirect_fx = L_add( masaDirect_fx, hSpatParamRendCom->energy_ratio2_fx[md_idx][k] ); + masaDirect_fx = L_add( masaDirect_fx, hSpatParamRendCom->energy_ratio2_fx[md_idx][k] ); /*q30*/ } - ismDirect_fx = hMasaIsm->energy_ratio_ism_fx[0][md_idx][k]; + ismDirect_fx = hMasaIsm->energy_ratio_ism_fx[0][md_idx][k]; /*q30*/ move32(); FOR( dir = 1; dir < hSpatParamRendCom->numIsmDirections; dir++ ) { - ismDirect_fx = L_add( ismDirect_fx, hMasaIsm->energy_ratio_ism_fx[dir][md_idx][k] ); + ismDirect_fx = L_add( ismDirect_fx, hMasaIsm->energy_ratio_ism_fx[dir][md_idx][k] ); /*q30*/ } - totalDirect_fx = L_add_sat( masaDirect_fx, ismDirect_fx ); // saturating as 1.0 (Q30) + 1.0 (Q30) is observed + totalDirect_fx = L_add_sat( masaDirect_fx, ismDirect_fx ); /*q30*/ // saturating as 1.0 (Q30) + 1.0 (Q30) is observed Word16 var_a = 0, var_b = 0; - var_a = BASOP_Util_Divide3232_Scale( masaDirect_fx, totalDirect_fx, &exp_1 ); - var_b = BASOP_Util_Divide3232_Scale( ismDirect_fx, totalDirect_fx, &exp_2 ); - directRatio_fx[0] = L_deposit_h( var_a ); + var_a = BASOP_Util_Divide3232_Scale( masaDirect_fx, totalDirect_fx, &exp_1 ); /*Q(15-exp_1)*/ + var_b = BASOP_Util_Divide3232_Scale( ismDirect_fx, totalDirect_fx, &exp_2 ); /*q(15-exp_2)*/ + directRatio_fx[0] = L_deposit_h( var_a ); // Q(31-exp_1) move32(); - directRatio_fx[1] = L_deposit_h( var_b ); + directRatio_fx[1] = L_deposit_h( var_b ); // Q(31-exp_2) move32(); Word32 temp_2, temp_3; @@ -4757,14 +4773,14 @@ void ivas_dirac_dec_compute_directional_responses_fx( set16_fx( exp_arr, exp_direct_response_hoa, MAX_OUTPUT_CHANNELS ); FOR( l = 0; l < num_channels_dir; l++ ) { - direct_response_hoa_fx[l] = Mpy_32_32( direct_response_hoa_fx[l], directRatio_fx[0] ); + direct_response_hoa_fx[l] = Mpy_32_32( direct_response_hoa_fx[l], directRatio_fx[0] ); /*31-exp_direct_response_hoa+31-exp_1-31*/ move32(); exp_arr[l] = add( exp_direct_response_hoa, exp_1 ); move16(); - temp_2 = Mpy_32_32( directRatio_fx[1], direct_response_ism_fx[l] ); - temp_3 = BASOP_Util_Add_Mant32Exp( direct_response_hoa_fx[l], exp_arr[l], temp_2, exp_2 + exp_direct_response_ism, &exp_temp_3 ); + temp_2 = Mpy_32_32( directRatio_fx[1], direct_response_ism_fx[l] ); /*31-exp_direct_response_ism+31-exp_2-31*/ + temp_3 = BASOP_Util_Add_Mant32Exp( direct_response_hoa_fx[l], exp_arr[l], temp_2, add( exp_2, exp_direct_response_ism ), &exp_temp_3 ); /*31-exp_temp_3*/ - direct_response_hoa_fx[l] = temp_3; + direct_response_hoa_fx[l] = temp_3; /*31-exp_temp_3*/ move32(); exp_arr[l] = exp_temp_3; move16(); @@ -4775,7 +4791,7 @@ void ivas_dirac_dec_compute_directional_responses_fx( maximum_fx( exp_arr, num_channels_dir, &max_exp ); FOR( l = 0; l < num_channels_dir; l++ ) { - direct_response_hoa_fx[l] = L_shr( direct_response_hoa_fx[l], sub( max_exp, exp_arr[l] ) ); + direct_response_hoa_fx[l] = L_shr( direct_response_hoa_fx[l], sub( max_exp, exp_arr[l] ) ); /*q(31-exp_arr[l])->q(31-max_exp)*/ move32(); } Q_direct_response_hoa = sub( 31, max_exp ); @@ -4794,9 +4810,9 @@ void ivas_dirac_dec_compute_directional_responses_fx( { exp = 0; move16(); - var_a = BASOP_Util_Add_Mant32Exp( ONE_IN_Q30, 1, L_negate( surCohRatio_fx[k] ), exp_surCohRatio, &exp ); - var_b = Sqrt32( var_a, &exp ); - direct_response_hoa_fx[l] = Mpy_32_32( direct_response_hoa_fx[l], var_b ); + var_a = BASOP_Util_Add_Mant32Exp( ONE_IN_Q30 /*1 Q30*/, 1, L_negate( surCohRatio_fx[k] ), exp_surCohRatio, &exp ); /*q(31-exp)*/ + var_b = Sqrt32( var_a, &exp ); /*31-exp*/ + direct_response_hoa_fx[l] = Mpy_32_32( direct_response_hoa_fx[l], var_b ); /*Q_direct_response_hoa+31-exp-31*/ move32(); exp_arr[l] = add( sub( 31, Q_direct_response_hoa ), exp ); move16(); @@ -4806,7 +4822,7 @@ void ivas_dirac_dec_compute_directional_responses_fx( maximum_fx( exp_arr, MAX_OUTPUT_CHANNELS, &max_exp ); FOR( l = 0; l < MAX_OUTPUT_CHANNELS; l++ ) { - direct_response_hoa_fx[l] = L_shr( direct_response_hoa_fx[l], sub( max_exp, exp_arr[l] ) ); + direct_response_hoa_fx[l] = L_shr( direct_response_hoa_fx[l], sub( max_exp, exp_arr[l] ) ); /*q(31-exp_arr[l])->q(31-max_exp)*/ move32(); } Q_direct_response_hoa = sub( 31, max_exp ); @@ -4816,36 +4832,36 @@ void ivas_dirac_dec_compute_directional_responses_fx( Q_direct_response_hoa = sub( Q31, exp_direct_response_hoa ); - Scale_sig32( direct_response_hoa_fx, MAX_OUTPUT_CHANNELS, sub( Q29, Q_direct_response_hoa ) ); + Scale_sig32( direct_response_hoa_fx, MAX_OUTPUT_CHANNELS, sub( Q29, Q_direct_response_hoa ) ); /*Q_direct_response_hoa->q29*/ direct_response_q = Q29; move16(); direct_response_fx = direct_response_hoa_fx; IF( NE_32( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) { - v_mult_fixed( direct_response_fx, direct_response_fx, direct_response_square_fx, num_channels_dir ); + v_mult_fixed( direct_response_fx, direct_response_fx, direct_response_square_fx, num_channels_dir ); /*Q(2*direct_response_q-31)*/ direct_response_square_q = sub( add( direct_response_q, direct_response_q ), 31 ); - mvr2r_inc_fixed( direct_response_square_fx, 1, &hDirACRend->h_output_synthesis_psd_state.direct_responses_square_fx[k], hSpatParamRendCom->num_freq_bands, num_channels_dir ); + mvr2r_inc_fixed( direct_response_square_fx, 1, &hDirACRend->h_output_synthesis_psd_state.direct_responses_square_fx[k], hSpatParamRendCom->num_freq_bands, num_channels_dir ); /*direct_response_square_q*/ IF( EQ_16( transport_signal_type, MASA_STEREO_SPACED_MICS ) ) { - direct_response_fx[0] = ONE_IN_Q29; + direct_response_fx[0] = ONE_IN_Q29; /*q29*/ move32(); test(); IF( GE_16( k, dipole_freq_range[0] ) && LT_16( k, dipole_freq_range[1] ) ) { - direct_response_fx[1] = ONE_IN_Q29; + direct_response_fx[1] = ONE_IN_Q29; /*q29*/ move32(); } } ELSE { - set32_fx( direct_response_fx, ONE_IN_Q29, hDirACRend->num_protos_ambi ); + set32_fx( direct_response_fx, ONE_IN_Q29, hDirACRend->num_protos_ambi ); /*q29*/ } } - mvr2r_inc_fixed( direct_response_fx, 1, &hDirACRend->h_output_synthesis_psd_state.direct_responses_fx[k], hSpatParamRendCom->num_freq_bands, num_channels_dir ); + mvr2r_inc_fixed( direct_response_fx, 1, &hDirACRend->h_output_synthesis_psd_state.direct_responses_fx[k], hSpatParamRendCom->num_freq_bands, num_channels_dir ); /*q29*/ } ELSE { @@ -4867,7 +4883,7 @@ void ivas_dirac_dec_compute_directional_responses_fx( normalizePanningGains_fx( direct_response_dir2_fx, &Q_direct_response_dir2, num_channels_dir ); /* Combine gains from the two directions */ - Word32 test = L_add( hSpatParamRendCom->energy_ratio1_fx[md_idx][k], hSpatParamRendCom->energy_ratio2_fx[md_idx][k] ); + Word32 test = L_add( hSpatParamRendCom->energy_ratio1_fx[md_idx][k], hSpatParamRendCom->energy_ratio2_fx[md_idx][k] ); /*q30*/ IF( test == 0 ) { @@ -4875,16 +4891,16 @@ void ivas_dirac_dec_compute_directional_responses_fx( } ELSE { - totalDirect_fx = test; + totalDirect_fx = test; // q30 move32(); } Word16 var_1, var_2, exp_1, exp_2; - var_1 = BASOP_Util_Divide3232_Scale( hSpatParamRendCom->energy_ratio1_fx[md_idx][k], totalDirect_fx, &exp_1 ); - var_2 = BASOP_Util_Divide3232_Scale( hSpatParamRendCom->energy_ratio2_fx[md_idx][k], totalDirect_fx, &exp_2 ); + var_1 = BASOP_Util_Divide3232_Scale( hSpatParamRendCom->energy_ratio1_fx[md_idx][k], totalDirect_fx, &exp_1 ); // 15-exp_1 + var_2 = BASOP_Util_Divide3232_Scale( hSpatParamRendCom->energy_ratio2_fx[md_idx][k], totalDirect_fx, &exp_2 ); // 15-exp_2 - directRatio_fx[0] = L_deposit_h( var_1 ); + directRatio_fx[0] = L_deposit_h( var_1 ); // 31-exp_1 move32(); - directRatio_fx[1] = L_deposit_h( var_2 ); + directRatio_fx[1] = L_deposit_h( var_2 ); // 31-exp_2 move32(); Word32 var_a; @@ -4904,7 +4920,7 @@ void ivas_dirac_dec_compute_directional_responses_fx( var_a = Mpy_32_32( directRatio_fx[1], direct_response_dir2_fx[l] ); // exp_direct_response_dir2 + exp_2 exp_tmp = 0; move16(); - direct_response_ls_fx[l] = BASOP_Util_Add_Mant32Exp( temp, add( exp_direct_response_ls, exp_1 ), var_a, add( exp_direct_response_dir2, exp_2 ), &exp_tmp ); + direct_response_ls_fx[l] = BASOP_Util_Add_Mant32Exp( temp, add( exp_direct_response_ls, exp_1 ), var_a, add( exp_direct_response_dir2, exp_2 ), &exp_tmp ); // q(31-exp_tmp) move32(); exp_table[l] = exp_tmp; move16(); @@ -4914,7 +4930,7 @@ void ivas_dirac_dec_compute_directional_responses_fx( FOR( i = 0; i < MAX_OUTPUT_CHANNELS; i++ ) { - direct_response_ls_fx[i] = L_shr( direct_response_ls_fx[i], sub( exp_max, exp_table[i] ) ); + direct_response_ls_fx[i] = L_shr( direct_response_ls_fx[i], sub( exp_max, exp_table[i] ) ); /*(q(31-exp_table[i])->q(31-exp_max))*/ move32(); } Q_direct_response_ls = sub( 31, exp_max ); @@ -4953,8 +4969,8 @@ void ivas_dirac_dec_compute_directional_responses_fx( Word16 Q_arr[MAX_OUTPUT_CHANNELS], exp_tmp; FOR( l = 0; l < num_channels_dir; l++ ) { - tmp = Mpy_32_32( direct_response_temp_fx[l], hMasaIsm->energy_ratio_ism_fx[dir][md_idx][k] ); // Q30 * 2 - 31 - direct_response_ism_fx[l] = BASOP_Util_Add_Mant32Exp( direct_response_ism_fx[l], 0, tmp, 31 - ( 60 - 31 ), &exp_tmp ); + tmp = Mpy_32_32( direct_response_temp_fx[l], hMasaIsm->energy_ratio_ism_fx[dir][md_idx][k] ); // Q30 * 2 - 31 + direct_response_ism_fx[l] = BASOP_Util_Add_Mant32Exp( direct_response_ism_fx[l], 0, tmp, 31 - ( 60 - 31 ), &exp_tmp ); // q(31-exp_tmp) move32(); Q_arr[l] = sub( 31, exp_tmp ); move16(); @@ -4964,7 +4980,7 @@ void ivas_dirac_dec_compute_directional_responses_fx( minimum_fx( Q_arr, num_channels_dir, &Q_min ); FOR( i = 0; i < num_channels_dir; i++ ) { - direct_response_ism_fx[i] = L_shr( direct_response_ism_fx[i], sub( Q_arr[i], Q_min ) ); + direct_response_ism_fx[i] = L_shr( direct_response_ism_fx[i], sub( Q_arr[i], Q_min ) ); // Q_arr[i]->Q_min move32(); } Q_direct_response_temp = Q_min; @@ -4973,31 +4989,31 @@ void ivas_dirac_dec_compute_directional_responses_fx( } Word16 exp_1, exp_2; - masaDirect_fx = hSpatParamRendCom->energy_ratio1_fx[md_idx][k]; + masaDirect_fx = hSpatParamRendCom->energy_ratio1_fx[md_idx][k]; // q30 move32(); IF( masaDirect_fx == 0 ) { - masaDirect_fx = L_add( masaDirect_fx, EPSILLON_FX ); + masaDirect_fx = L_add( masaDirect_fx, EPSILLON_FX ); // q30 } IF( EQ_32( hSpatParamRendCom->numParametricDirections, 2 ) ) { - masaDirect_fx = L_add( masaDirect_fx, hSpatParamRendCom->energy_ratio2_fx[md_idx][k] ); + masaDirect_fx = L_add( masaDirect_fx, hSpatParamRendCom->energy_ratio2_fx[md_idx][k] ); // q30 } - ismDirect_fx = hMasaIsm->energy_ratio_ism_fx[0][md_idx][k]; + ismDirect_fx = hMasaIsm->energy_ratio_ism_fx[0][md_idx][k]; // q30 move32(); FOR( dir = 1; dir < hSpatParamRendCom->numIsmDirections; dir++ ) { - ismDirect_fx = L_add( ismDirect_fx, hMasaIsm->energy_ratio_ism_fx[dir][md_idx][k] ); + ismDirect_fx = L_add( ismDirect_fx, hMasaIsm->energy_ratio_ism_fx[dir][md_idx][k] ); // q30 } - totalDirect_fx = L_add_sat( masaDirect_fx, ismDirect_fx ); // saturating as 1.0 (Q30) + 1.0 (Q30) is observed + totalDirect_fx = L_add_sat( masaDirect_fx, ismDirect_fx ); // q30 // saturating as 1.0 (Q30) + 1.0 (Q30) is observed Word16 var_a, var_b; - var_a = BASOP_Util_Divide3232_Scale( masaDirect_fx, totalDirect_fx, &exp_1 ); - var_b = BASOP_Util_Divide3232_Scale( ismDirect_fx, totalDirect_fx, &exp_2 ); - directRatio_fx[0] = L_deposit_h( var_a ); + var_a = BASOP_Util_Divide3232_Scale( masaDirect_fx, totalDirect_fx, &exp_1 ); // 15-exp_1 + var_b = BASOP_Util_Divide3232_Scale( ismDirect_fx, totalDirect_fx, &exp_2 ); // 15- exp_2 + directRatio_fx[0] = L_deposit_h( var_a ); // 31- exp_1 move32(); - directRatio_fx[1] = L_deposit_h( var_b ); + directRatio_fx[1] = L_deposit_h( var_b ); // 31 - exp_2 move32(); Word32 temp_2, temp_3; @@ -5005,14 +5021,14 @@ void ivas_dirac_dec_compute_directional_responses_fx( set16_fx( exp_arr, exp_direct_response_ls, MAX_OUTPUT_CHANNELS ); FOR( l = 0; l < num_channels_dir; l++ ) { - direct_response_ls_fx[l] = Mpy_32_32( direct_response_ls_fx[l], directRatio_fx[0] ); + direct_response_ls_fx[l] = Mpy_32_32( direct_response_ls_fx[l], directRatio_fx[0] ); // q(31-exp_direct_response_ls+31-exp_1-31) move32(); exp_arr[l] = add( exp_direct_response_ls, exp_1 ); move16(); - temp_2 = Mpy_32_32( directRatio_fx[1], direct_response_ism_fx[l] ); - temp_3 = BASOP_Util_Add_Mant32Exp( direct_response_ls_fx[l], exp_arr[l], temp_2, exp_2 + 31 - Q_direct_response_temp, &exp_temp_3 ); + temp_2 = Mpy_32_32( directRatio_fx[1], direct_response_ism_fx[l] ); // q(Q_direct_response_temp+31-exp_2-31) + temp_3 = BASOP_Util_Add_Mant32Exp( direct_response_ls_fx[l], exp_arr[l], temp_2, add( exp_2, sub( 31, Q_direct_response_temp ) ), &exp_temp_3 ); // 31-exp_temp_3 - direct_response_ls_fx[l] = temp_3; + direct_response_ls_fx[l] = temp_3; // 31-exp_temp_3 move32(); exp_arr[l] = exp_temp_3; move16(); @@ -5023,7 +5039,7 @@ void ivas_dirac_dec_compute_directional_responses_fx( maximum_fx( exp_arr, num_channels_dir, &max_exp ); FOR( l = 0; l < num_channels_dir; l++ ) { - direct_response_ls_fx[l] = L_shr( direct_response_ls_fx[l], sub( max_exp, exp_arr[l] ) ); + direct_response_ls_fx[l] = L_shr( direct_response_ls_fx[l], sub( max_exp, exp_arr[l] ) ); /*q(31-exp_arr[l])->q(31-max_exp)*/ move16(); } Q_direct_response_ls = sub( 31, max_exp ); @@ -5035,6 +5051,7 @@ void ivas_dirac_dec_compute_directional_responses_fx( } /* Synthesize surrounding coherence */ + test(); IF( surCohRatio_fx != NULL && surCohRatio_fx[k] > 0 ) { Word16 num_channels_surrCoh; @@ -5052,9 +5069,9 @@ void ivas_dirac_dec_compute_directional_responses_fx( { exp_temp = 0; move16(); - temp = BASOP_Util_Add_Mant32Exp( ONE_IN_Q30, 1, L_negate( surCohRatio_fx[k] ), exp_surCohRatio, &exp_temp ); - temp = Sqrt32( temp, &exp_temp ); - direct_response_ls_fx[l] = Mpy_32_32( direct_response_ls_fx[l], temp ); // exp_direct_response_ls + exp_temp + temp = BASOP_Util_Add_Mant32Exp( ONE_IN_Q30 /*1 Q30*/, 1, L_negate( surCohRatio_fx[k] ), exp_surCohRatio, &exp_temp ); // q(31-exp_temp) + temp = Sqrt32( temp, &exp_temp ); // q(31-exp_temp) + direct_response_ls_fx[l] = Mpy_32_32( direct_response_ls_fx[l], temp ); // Q31-(exp_direct_response_ls + exp_temp) move32(); exp_arr[l] = add( exp_direct_response_ls, exp_temp ); @@ -5063,25 +5080,25 @@ void ivas_dirac_dec_compute_directional_responses_fx( { exp_temp_a = 0; move16(); - temp_a = BASOP_Util_Divide3216_Scale( surCohRatio_fx[k], num_channels_surrCoh, &exp_temp_a ); + temp_a = BASOP_Util_Divide3216_Scale( surCohRatio_fx[k], num_channels_surrCoh, &exp_temp_a ); /*15-(exp_temp_a+exp_surCohRatio-15)*/ exp_temp_a = add( exp_temp_a, sub( exp_surCohRatio, 15 ) ); - temp_a = Sqrt16( temp_a, &exp_temp_a ); + temp_a = Sqrt16( temp_a, &exp_temp_a ); /*15-temp_a*/ final_exp = 0; move16(); - final = BASOP_Util_Add_Mant32Exp( direct_response_ls_fx[l], exp_arr[l], L_deposit_h( temp_a ), exp_temp_a, &final_exp ); - direct_response_ls_fx[l] = final; + final = BASOP_Util_Add_Mant32Exp( direct_response_ls_fx[l], exp_arr[l], L_deposit_h( temp_a ), exp_temp_a, &final_exp ); /*31-final_exp*/ + direct_response_ls_fx[l] = final; /*31-final_exp*/ move32(); exp_arr[l] = final_exp; move16(); } } - max_exp = MIN16B; + max_exp = MIN16B; /*Q0*/ move16(); maximum_fx( exp_arr, MAX_OUTPUT_CHANNELS, &max_exp ); FOR( l = 0; l < MAX_OUTPUT_CHANNELS; l++ ) { - direct_response_ls_fx[l] = L_shr( direct_response_ls_fx[l], sub( max_exp, exp_arr[l] ) ); + direct_response_ls_fx[l] = L_shr( direct_response_ls_fx[l], sub( max_exp, exp_arr[l] ) ); /*Q(31-exp_arr[l])->Q(31-max_exp)*/ move32(); } @@ -5093,17 +5110,17 @@ void ivas_dirac_dec_compute_directional_responses_fx( normalizePanningGains_fx( direct_response_ls_fx, &Q_direct_response_ls, num_channels_dir ); exp_direct_response_ls = sub( 31, Q_direct_response_ls ); - Scale_sig32( direct_response_ls_fx, MAX_OUTPUT_CHANNELS, sub( Q29, Q_direct_response_ls ) ); + Scale_sig32( direct_response_ls_fx, MAX_OUTPUT_CHANNELS, sub( Q29, Q_direct_response_ls ) ); /*Q_direct_response_ls->Q29*/ direct_response_q = Q29; move16(); /* Set computed gains */ direct_response_fx = direct_response_ls_fx; - v_mult_fixed( direct_response_fx, direct_response_fx, direct_response_square_fx, num_channels_dir ); + v_mult_fixed( direct_response_fx, direct_response_fx, direct_response_square_fx, num_channels_dir ); /*2*direct_response_q-31*/ direct_response_square_q = sub( add( direct_response_q, direct_response_q ), 31 ); - mvr2r_inc_fixed( direct_response_square_fx, 1, &hDirACRend->h_output_synthesis_psd_state.direct_responses_square_fx[k], hSpatParamRendCom->num_freq_bands, num_channels_dir ); - mvr2r_inc_fixed( direct_response_fx, 1, &hDirACRend->h_output_synthesis_psd_state.direct_responses_fx[k], hSpatParamRendCom->num_freq_bands, num_channels_dir ); + mvr2r_inc_fixed( direct_response_square_fx, 1, &hDirACRend->h_output_synthesis_psd_state.direct_responses_square_fx[k], hSpatParamRendCom->num_freq_bands, num_channels_dir ); /*direct_response_square_q*/ + mvr2r_inc_fixed( direct_response_fx, 1, &hDirACRend->h_output_synthesis_psd_state.direct_responses_fx[k], hSpatParamRendCom->num_freq_bands, num_channels_dir ); /*direct_response_q*/ } ELSE { @@ -5459,9 +5476,9 @@ void ivas_dirac_dec_compute_directional_responses( #ifdef IVAS_FLOAT_FIXED void ivas_dirac_dec_compute_gain_factors_fx( const Word16 num_freq_bands, - const Word32 *diffuseness_fx, - Word32 *direct_gain_factor, - Word32 *diffuse_gain_factor, + const Word32 *diffuseness_fx, /*i:q30*/ + Word32 *direct_gain_factor, /*o:exponent is max_exp_direct*/ + Word32 *diffuse_gain_factor, /*o:exponent is max_exp_diffusion*/ Word16 *max_exp_direct_fx, Word16 *max_exp_diffusion ) { @@ -5475,9 +5492,9 @@ void ivas_dirac_dec_compute_gain_factors_fx( move16(); exp2 = 1; move16(); - direct_gain_factor[i] = Sqrt32( L_sub( ONE_IN_Q30, diffuseness_fx[i] ), &exp1 ); + direct_gain_factor[i] = Sqrt32( L_sub( ONE_IN_Q30 /*1 Q30*/, diffuseness_fx[i] ), &exp1 ); /*31-exp1*/ move32(); - diffuse_gain_factor[i] = Sqrt32( diffuseness_fx[i], &exp2 ); + diffuse_gain_factor[i] = Sqrt32( diffuseness_fx[i], &exp2 ); /*31-exp2*/ move32(); exp_direct_gain_factor[i] = exp1; move16(); @@ -5486,9 +5503,9 @@ void ivas_dirac_dec_compute_gain_factors_fx( } /*make common exp for both buffers*/ - Word16 max_exp_direct = MIN16B; + Word16 max_exp_direct = MIN16B; /*Q0*/ move16(); - Word16 max_exp_diffuse = MIN16B; + Word16 max_exp_diffuse = MIN16B; /*Q0*/ move16(); FOR( i = 0; i < num_freq_bands; i++ ) { @@ -5503,9 +5520,9 @@ void ivas_dirac_dec_compute_gain_factors_fx( FOR( i = 0; i < num_freq_bands; i++ ) { - direct_gain_factor[i] = L_shr( direct_gain_factor[i], sub( max_exp_direct, exp_direct_gain_factor[i] ) ); + direct_gain_factor[i] = L_shr( direct_gain_factor[i], sub( max_exp_direct, exp_direct_gain_factor[i] ) ); /*Q(31-max_exp_direct)*/ move32(); - diffuse_gain_factor[i] = L_shr( diffuse_gain_factor[i], sub( max_exp_diffuse, exp_diffuse_gain_factor[i] ) ); + diffuse_gain_factor[i] = L_shr( diffuse_gain_factor[i], sub( max_exp_diffuse, exp_diffuse_gain_factor[i] ) ); /*Q(31-max_exp_diffuse)*/ move32(); } @@ -5569,8 +5586,8 @@ void ivas_dirac_dec_compute_power_factors_fx( const Word16 num_freq_bands, const Word32 *diffuseness_fx, // Q3O const Word16 max_band_decorr, - Word32 *direct_power_factor, - Word32 *diffuse_power_factor ) + Word32 *direct_power_factor, /*input is q30 and ouput is q29*/ + Word32 *diffuse_power_factor /*input is q30 and ouput is q29*/ ) { Word16 i; @@ -5630,12 +5647,12 @@ void ivas_lfe_synth_with_filters_fx( /* Delay the separated channel to sync the LFE synthesis with the DirAC rendering */ delay = hMasaLfeSynth->delayBuffer_syncDirAC_size; move16(); - delay_signal_fx( data_fx[separateChannelIndex], output_frame, hMasaLfeSynth->delayBuffer_syncDirAC_fx, delay ); + delay_signal_fx( data_fx[separateChannelIndex], output_frame, hMasaLfeSynth->delayBuffer_syncDirAC_fx, delay ); /*q11*/ /* Filterbank for dividing the separated channel to LFE frequencies and higher frequencies */ lowpassCoef_fx_exp = 15; move16(); - lowpassCoef_fx = Inv16( hMasaLfeSynth->ringBufferSize, &lowpassCoef_fx_exp ); + lowpassCoef_fx = Inv16( hMasaLfeSynth->ringBufferSize, &lowpassCoef_fx_exp ); /*15-lowpassCoef_fx_exp*/ FOR( i = 0; i < output_frame; i++ ) { hMasaLfeSynth->lowpassSum_fx = L_add( hMasaLfeSynth->lowpassSum_fx, L_shl( Mpy_32_16_1( L_sub( data_fx[separateChannelIndex][i], hMasaLfeSynth->lfeSynthRingBuffer_fx[hMasaLfeSynth->ringBufferLoPointer] ), lowpassCoef_fx ), lowpassCoef_fx_exp ) ); // Q11 @@ -5685,7 +5702,7 @@ void ivas_lfe_synth_with_filters_fx( Word16 tmp_shift = W_norm( W_tmp ); - W_tmp = W_shl( W_tmp, tmp_shift ); + W_tmp = W_shl( W_tmp, tmp_shift ); /*Q22+tmp_shift*/ Word16 tmp_q = sub( add( Q22, tmp_shift ), 32 ); Word16 tmp_exp; @@ -5716,62 +5733,62 @@ void ivas_lfe_synth_with_filters_fx( IF( EQ_16( BASOP_Util_Cmp_Mant32Exp( hMasaLfeSynth->targetEneLfeSmooth_fx, sub( Q31, hMasaLfeSynth->targetEneLfeSmooth_q ), /*EPSILON + */ hMasaLfeSynth->transportEneSmooth_fx, sub( Q31, hMasaLfeSynth->transportEneSmooth_q ) ), 1 ) ) { - lfeGain_fx = MAX_16; + lfeGain_fx = MAX_16; /* 1.0 in q15*/ move16(); } ELSE { - lfeGain_fx = extract_h( BASOP_Util_Divide3232_Scale_cadence( hMasaLfeSynth->targetEneLfeSmooth_fx, L_add( EPSILON_FX, hMasaLfeSynth->transportEneSmooth_fx ), &lfeGain_fx_exp ) ); + lfeGain_fx = extract_h( BASOP_Util_Divide3232_Scale_cadence( hMasaLfeSynth->targetEneLfeSmooth_fx, L_add( EPSILON_FX, hMasaLfeSynth->transportEneSmooth_fx ), &lfeGain_fx_exp ) ); /*Q(31-(lfeGain_fx_exp+hMasaLfeSynth->transportEneSmooth_q-hMasaLfeSynth->targetEneLfeSmooth_q))-16*/ lfeGain_fx_exp = add( sub( hMasaLfeSynth->transportEneSmooth_q, hMasaLfeSynth->targetEneLfeSmooth_q ), lfeGain_fx_exp ); - lfeGain_fx = Sqrt16( lfeGain_fx, &lfeGain_fx_exp ); - lfeGain_fx = shl_r( lfeGain_fx, lfeGain_fx_exp ); // Q15 + lfeGain_fx = Sqrt16( lfeGain_fx, &lfeGain_fx_exp ); // Q15-lfeGain_fx_exp + lfeGain_fx = shl_r( lfeGain_fx, lfeGain_fx_exp ); // Q15 } IF( EQ_16( BASOP_Util_Cmp_Mant32Exp( hMasaLfeSynth->targetEneTransSmooth_fx, sub( Q31, hMasaLfeSynth->targetEneTransSmooth_q ), /*EPSILON + */ hMasaLfeSynth->transportEneSmooth_fx, sub( Q31, hMasaLfeSynth->transportEneSmooth_q ) ), 1 ) ) { - transportGain_fx = MAX_16; + transportGain_fx = MAX_16; // q15 move16(); } ELSE { Flag overFlow; - transportGain_fx = BASOP_Util_Divide3232_Scale( hMasaLfeSynth->targetEneTransSmooth_fx, /*EPSILON + */ hMasaLfeSynth->transportEneSmooth_fx, &transportGain_fx_exp ); + transportGain_fx = BASOP_Util_Divide3232_Scale( hMasaLfeSynth->targetEneTransSmooth_fx, /*EPSILON + */ hMasaLfeSynth->transportEneSmooth_fx, &transportGain_fx_exp ); /*Q=15-(transportGain_fx_exp+hMasaLfeSynth->transportEneSmooth_q-hMasaLfeSynth->targetEneTransSmooth_q)*/ transportGain_fx_exp = add( sub( hMasaLfeSynth->transportEneSmooth_q, hMasaLfeSynth->targetEneTransSmooth_q ), transportGain_fx_exp ); - transportGain_fx = Sqrt16( transportGain_fx, &transportGain_fx_exp ); + transportGain_fx = Sqrt16( transportGain_fx, &transportGain_fx_exp ); // q15-transportGain_fx_exp transportGain_fx = shl_ro( transportGain_fx, transportGain_fx_exp, &overFlow ); // Q15 } j = 0; move16(); FOR( i = mrange[0]; i < mrange[1]; i++ ) { - Word32 L_tmp1 = L_mult( transportGain_fx, hMasaLfeSynth->interpolator_fx[j] ); // Q31 - Word32 L_tmp2 = L_mult( hMasaLfeSynth->transportGainPrev_fx, sub( MAX_16, hMasaLfeSynth->interpolator_fx[j] ) ); // Q31 - data_fx[separateChannelIndex][i] = L_add( Mpy_32_32( L_add( L_tmp1, L_tmp2 ), lowPassSignal_fx[i] ), highPassSignal_fx[i] ); + Word32 L_tmp1 = L_mult( transportGain_fx, hMasaLfeSynth->interpolator_fx[j] ); // Q31 + Word32 L_tmp2 = L_mult( hMasaLfeSynth->transportGainPrev_fx, sub( MAX_16, hMasaLfeSynth->interpolator_fx[j] ) ); // Q31 + data_fx[separateChannelIndex][i] = L_add( Mpy_32_32( L_add( L_tmp1, L_tmp2 ), lowPassSignal_fx[i] ), highPassSignal_fx[i] ); /*q31+q11-q31->q11*/ move32(); - Word32 L_tmp3 = L_mult( lfeGain_fx, hMasaLfeSynth->interpolator_fx[j] ); // Q31 - Word32 L_tmp4 = L_mult( hMasaLfeSynth->lfeGainPrev_fx, sub( MAX_16, hMasaLfeSynth->interpolator_fx[j] ) ); - data_fx[lfeChannelIndex][i] = Mpy_32_32( L_add( L_tmp3, L_tmp4 ), lowPassSignal_fx[i] ); + Word32 L_tmp3 = L_mult( lfeGain_fx, hMasaLfeSynth->interpolator_fx[j] ); // Q31 + Word32 L_tmp4 = L_mult( hMasaLfeSynth->lfeGainPrev_fx, sub( MAX_16, hMasaLfeSynth->interpolator_fx[j] ) ); /*q31*/ + data_fx[lfeChannelIndex][i] = Mpy_32_32( L_add( L_tmp3, L_tmp4 ), lowPassSignal_fx[i] ); /*q31+q11-q31->q11*/ move32(); j = add( j, 1 ); } - hMasaLfeSynth->lfeGainPrev_fx = lfeGain_fx; + hMasaLfeSynth->lfeGainPrev_fx = lfeGain_fx; /*q15*/ move16(); - hMasaLfeSynth->transportGainPrev_fx = transportGain_fx; + hMasaLfeSynth->transportGainPrev_fx = transportGain_fx; /*q15*/ move16(); } /* Lowpass filter for removing remaining mid and high frequencies from the LFE signal */ lowpassCoef_fx_exp = 15; move16(); - lowpassCoef_fx = Inv16( hMasaLfeSynth->ringBufferSize2, &lowpassCoef_fx_exp ); + lowpassCoef_fx = Inv16( hMasaLfeSynth->ringBufferSize2, &lowpassCoef_fx_exp ); // q15-lowpassCoef_fx_exp FOR( i = 0; i < output_frame; i++ ) { hMasaLfeSynth->lowpassSum2_fx = L_add( hMasaLfeSynth->lowpassSum2_fx, L_shl_r( L_sub( Mpy_32_16_1( data_fx[lfeChannelIndex][i], lowpassCoef_fx ), Mpy_32_16_1( hMasaLfeSynth->lfeSynthRingBuffer2_fx[hMasaLfeSynth->ringBufferLoPointer2], lowpassCoef_fx ) ), - lowpassCoef_fx_exp ) ); + lowpassCoef_fx_exp ) ); /*q11+15-lowpassCoef_fx_exp-15+lowpassCoef_fx_exp->q11*/ move32(); - hMasaLfeSynth->lfeSynthRingBuffer2_fx[hMasaLfeSynth->ringBufferLoPointer2] = data_fx[lfeChannelIndex][i]; + hMasaLfeSynth->lfeSynthRingBuffer2_fx[hMasaLfeSynth->ringBufferLoPointer2] = data_fx[lfeChannelIndex][i]; /*q11*/ move32(); hMasaLfeSynth->ringBufferLoPointer2 = sub( hMasaLfeSynth->ringBufferLoPointer2, 1 ); @@ -5782,14 +5799,14 @@ void ivas_lfe_synth_with_filters_fx( move16(); } - data_fx[lfeChannelIndex][i] = hMasaLfeSynth->lowpassSum2_fx; + data_fx[lfeChannelIndex][i] = hMasaLfeSynth->lowpassSum2_fx; /*q11*/ move32(); } /* Delay the separated channel to match the delay of the lowpass filter */ delay = hMasaLfeSynth->delayBuffer_syncLp_size; move16(); - delay_signal_fx( data_fx[separateChannelIndex], output_frame, hMasaLfeSynth->delayBuffer_syncLp_fx, delay ); + delay_signal_fx( data_fx[separateChannelIndex], output_frame, hMasaLfeSynth->delayBuffer_syncLp_fx, delay ); /*q11*/ return; } @@ -5912,14 +5929,14 @@ void ivas_lfe_synth_with_filters( static void computeTargetPSDs_direct_fx( const Word16 num_channels, const Word16 num_freq_bands, - const Word32 *direct_power_factor, - const Word32 *reference_power, + const Word32 *direct_power_factor, /*q31*/ + const Word32 *reference_power, /*q_reference_power*/ const Word16 *q_reference_power, - const Word32 *direct_responses, - const Word32 *direct_responses_square, - Word32 *cy_auto_dir_smooth, + const Word32 *direct_responses, /*q31*/ + const Word32 *direct_responses_square, /*q31*/ + Word32 *cy_auto_dir_smooth, /*q_cy_auto_dir_smooth*/ Word16 *q_cy_auto_dir_smooth, - Word32 *cy_cross_dir_smooth, + Word32 *cy_cross_dir_smooth, /*q_cy_cross_dir_smooth*/ Word16 *q_cy_cross_dir_smooth ) { Word16 ch_idx, cur_idx; @@ -5999,14 +6016,14 @@ static void computeTargetPSDs_direct( static void computeTargetPSDs_direct_subframe_fx( const Word16 num_channels, const Word16 num_freq_bands, - const Word32 *direct_power_factor, - const Word32 *reference_power, + const Word32 *direct_power_factor, /*q31*/ + const Word32 *reference_power, /*q_reference_power*/ const Word16 *q_reference_power, - const Word32 *direct_responses, - const Word32 *direct_responses_square, - Word32 *cy_auto_dir_smooth, + const Word32 *direct_responses, /*q31*/ + const Word32 *direct_responses_square, /*q31*/ + Word32 *cy_auto_dir_smooth, /*q_cy_auto_dir_smooth*/ Word16 *q_cy_auto_dir_smooth, - Word32 *cy_cross_dir_smooth, + Word32 *cy_cross_dir_smooth, /*q_cy_cross_dir_smooth*/ Word16 *q_cy_cross_dir_smooth ) { Word16 ch_idx, cur_idx, i, q_tmp; @@ -6028,14 +6045,17 @@ static void computeTargetPSDs_direct_subframe_fx( move64(); FOR( i = 0; i < num_freq_bands; i++ ) { - W_tmp[i] = W_mult_32_32( direct_power[i], direct_responses_square[cur_idx + i] ); // (q_reference_power, Q31) + 1 + W_tmp[i] = W_mult_32_32( direct_power[i], direct_responses_square[cur_idx + i] ); // q_reference_power + Q31 + 1 move64(); - W_max = W_max < W_abs( W_tmp[i] ) ? W_abs( W_tmp[i] ) : W_max; + IF( LT_64( W_max, W_abs( W_tmp[i] ) ) ) + { + W_max = W_abs( W_tmp[i] ); + } } q_tmp = W_norm( W_max ); FOR( i = 0; i < num_freq_bands; i++ ) { - cy_auto_dir_smooth[cur_idx + i] = W_extract_h( W_shl( W_tmp[i], q_tmp ) ); + cy_auto_dir_smooth[cur_idx + i] = W_extract_h( W_shl( W_tmp[i], q_tmp ) ); /*q_reference_power+q_tmp*/ move32(); } q_cy_auto_dir_smooth[ch_idx] = add( *q_reference_power, q_tmp ); @@ -6086,11 +6106,11 @@ static void computeTargetPSDs_diffuse_fx( const Word16 num_channels, const Word16 num_freq_bands, const Word16 start_band, - const Word32 *diffuse_power_factor, - const Word32 *reference_power, + const Word32 *diffuse_power_factor, /*q31*/ + const Word32 *reference_power, /*q_reference_power*/ const Word16 *q_reference_power, - const Word32 *diffuse_responses_square, - Word32 *cy_auto_diff_smooth, + const Word32 *diffuse_responses_square, /*Q31*/ + Word32 *cy_auto_diff_smooth, /*q_cy_auto_diff_smooth*/ Word16 *q_cy_auto_diff_smooth ) { Word16 ch_idx, cur_idx; @@ -6109,10 +6129,10 @@ static void computeTargetPSDs_diffuse_fx( { cur_idx = imult1616( ch_idx, num_freq_bands ); - v_multc_fixed( &diffuse_power[start_band], diffuse_responses_square[ch_idx], aux_buffer_res, sub( num_freq_bands, start_band ) ); /* Q31 + Q(q_reference_power) - Q31 = Q(q_reference_power) */ - scale_sig32( aux_buffer_res, sub( num_freq_bands, start_band ), sub( common_q, *q_reference_power ) ); /* Q(common_q) */ - scale_sig32( &cy_auto_diff_smooth[add( cur_idx, start_band )], sub( num_freq_bands, start_band ), sub( common_q, *q_cy_auto_diff_smooth ) ); /* Q(common_q) */ - v_add_fixed( &cy_auto_diff_smooth[add( cur_idx, start_band )], aux_buffer_res, &cy_auto_diff_smooth[add( cur_idx, start_band )], sub( num_freq_bands, start_band ), Q1 ); /* Q(common_q) - Q1 */ + v_multc_fixed( &diffuse_power[start_band], diffuse_responses_square[ch_idx], aux_buffer_res, sub( num_freq_bands, start_band ) ); /* Q31 + Q(q_reference_power) - Q31 = Q(q_reference_power) */ + scale_sig32( aux_buffer_res, sub( num_freq_bands, start_band ), sub( common_q, *q_reference_power ) ); /* Q(common_q) */ + scale_sig32( &cy_auto_diff_smooth[cur_idx + start_band], sub( num_freq_bands, start_band ), sub( common_q, *q_cy_auto_diff_smooth ) ); /* Q(common_q) */ + v_add_fixed( &cy_auto_diff_smooth[cur_idx + start_band], aux_buffer_res, &cy_auto_diff_smooth[cur_idx + start_band], sub( num_freq_bands, start_band ), Q1 ); /* Q(common_q) - Q1 */ } /* Q adjustment */ @@ -6158,11 +6178,11 @@ static void computeTargetPSDs_diffuse_subframe_fx( const Word16 num_channels, const Word16 num_freq_bands, const Word16 start_band, - const Word32 *diffuse_power_factor, - const Word32 *reference_power, + const Word32 *diffuse_power_factor, /*q31*/ + const Word32 *reference_power, /*q_reference_power*/ const Word16 *q_reference_power, - const Word32 *diffuse_responses_square, - Word32 *cy_auto_diff_smooth, + const Word32 *diffuse_responses_square, /*q31*/ + Word32 *cy_auto_diff_smooth, /*q_cy_auto_diff_smooth*/ Word16 *q_cy_auto_diff_smooth ) { Word16 ch_idx, cur_idx; @@ -6176,7 +6196,7 @@ static void computeTargetPSDs_diffuse_subframe_fx( { cur_idx = imult1616( ch_idx, num_freq_bands ); - v_multc_fixed( &diffuse_power[start_band], diffuse_responses_square[ch_idx], &cy_auto_diff_smooth[add( cur_idx, start_band )], sub( num_freq_bands, start_band ) ); // (q_reference_power, Q31) -> q_reference_power + v_multc_fixed( &diffuse_power[start_band], diffuse_responses_square[ch_idx], &cy_auto_diff_smooth[cur_idx + start_band], sub( num_freq_bands, start_band ) ); // (q_reference_power, Q31) -> q_reference_power } *q_cy_auto_diff_smooth = *q_reference_power; @@ -6219,12 +6239,12 @@ static void computeTargetPSDs_diffuse_with_onsets_fx( const Word16 num_freq_bands, const Word16 num_decorr_freq_bands, const Word16 *proto_frame_diff_index, - const Word32 *diffuse_power_factor, - const Word32 *reference_power, + const Word32 *diffuse_power_factor, /*q31*/ + const Word32 *reference_power, /* q_reference_power */ const Word16 *q_reference_power, - const Word32 *diffuse_responses_square, - const Word32 *onset_filter, - Word32 *cy_auto_diff_smooth, + const Word32 *diffuse_responses_square, /*q31*/ + const Word32 *onset_filter, /*q31*/ + Word32 *cy_auto_diff_smooth, /*q_cy_auto_diff_smooth*/ Word16 *q_cy_auto_diff_smooth ) { Word16 ch_idx, cur_idx, diff_idx; @@ -6328,7 +6348,7 @@ static void computeTargetPSDs_diffuse_with_onsets( #ifdef IVAS_FLOAT_FIXED -static void computeAlphaSynthesis_fx( Word16 *alpha_synthesis_fx, const Word16 averaging_length_ms, const Word16 maxAlpha_fx, Word16 *numAlphas, const Word16 slot_size, const Word16 num_freq_bands, Word16 *frequency_axis_fx, const Word32 output_Fs ) +static void computeAlphaSynthesis_fx( Word16 *alpha_synthesis_fx /*q15*/, const Word16 averaging_length_ms, const Word16 maxAlpha_fx /*q15*/, Word16 *numAlphas, const Word16 slot_size, const Word16 num_freq_bands, Word16 *frequency_axis_fx /*q0*/, const Word32 output_Fs ) { Word16 k; Word16 avg_length_f_ms_fx; @@ -6341,28 +6361,29 @@ static void computeAlphaSynthesis_fx( Word16 *alpha_synthesis_fx, const Word16 a IF( averaging_length_ms == 0 ) { - set16_fx( alpha_synthesis_fx, MAX16B, num_freq_bands ); + set16_fx( alpha_synthesis_fx, MAX16B, num_freq_bands ); /*q15*/ } ELSE { FOR( k = 0; k < num_freq_bands; k++ ) { Word16 faxis_idx = s_max( k, 1 ); + // avg_length_f_ms = 1000.f * (float)averaging_length_ms / fabsf(frequency_axis[faxis_idx]); Word16 tmp_exp = 0; - Word16 tmp_1 = BASOP_Util_Divide1616_Scale( averaging_length_ms, frequency_axis_fx[faxis_idx], &tmp_exp ); - Word16 tmp_2 = mult( tmp_1, 1000 ); // 15 - tmp_exp + 0 -15 = -tmp_exp (Q-fac) - avg_length_f_ms_fx = tmp_2; + Word16 tmp_1 = BASOP_Util_Divide1616_Scale( averaging_length_ms, frequency_axis_fx[faxis_idx], &tmp_exp ); /*Q(15-(tmp_exp+15-15))*/ + Word16 tmp_2 = mult( tmp_1, 1000 ); // 15 - tmp_exp + 0 -15 = -tmp_exp (Q-fac) + avg_length_f_ms_fx = tmp_2; // Q(-tmp_exp) move16(); move16(); - + /* alpha_synthesis[k] = min( (float) slot_size / ( avg_length_f_ms * (float) output_Fs / 1000.f ), 1.0f );*/ Word32 tmp_3 = Mpy_32_16_1( output_Fs, avg_length_f_ms_fx ); // 0 - tmp_exp - 15 (Q-fac) Word16 tmp_exp_3; - Word16 tmp_4 = BASOP_Util_Divide3232_Scale( tmp_3, 1000, &tmp_exp_3 ); + Word16 tmp_4 = BASOP_Util_Divide3232_Scale( tmp_3, 1000, &tmp_exp_3 ); /*tmp_exp_4 stores resultant exponent*/ Word16 tmp_exp_4 = sub( add( tmp_exp_3, add( add( 31, tmp_exp ), 15 ) ), 31 ); Word16 tmp_exp_5; - Word16 tmp_5 = BASOP_Util_Divide1616_Scale( slot_size, tmp_4, &tmp_exp_5 ); + Word16 tmp_5 = BASOP_Util_Divide1616_Scale( slot_size, tmp_4, &tmp_exp_5 ); /*res_exp stores resultant exponent*/ Word16 res_exp = sub( add( tmp_exp_5, 15 ), tmp_exp_4 ); Word16 flag = BASOP_Util_Cmp_Mant32Exp( L_deposit_h( tmp_5 ), res_exp, 1, 31 ); @@ -6373,7 +6394,7 @@ static void computeAlphaSynthesis_fx( Word16 *alpha_synthesis_fx, const Word16 a } ELSE { - alpha_synthesis_fx[k] = MAX16B; + alpha_synthesis_fx[k] = MAX16B; /*q15*/ move16(); } @@ -6381,7 +6402,7 @@ static void computeAlphaSynthesis_fx( Word16 *alpha_synthesis_fx, const Word16 a test(); IF( flag2 == 0 || EQ_16( flag2, 1 ) ) { - alpha_synthesis_fx[k] = maxAlpha_fx; + alpha_synthesis_fx[k] = maxAlpha_fx; /*q15*/ move16(); *numAlphas = add( k, 1 ); move16(); @@ -6441,9 +6462,9 @@ static void computeAlphaSynthesis( static void spreadCoherencePanningHoa_fx( const Word16 azimuth, const Word16 elevation, - const Word16 spreadCoh_fx, /*Q15*/ - Word32 *direct_response_fx, /*Q29*/ - Word16 *Q_direct_response, /*Q29*/ + const Word16 spreadCoh_fx, /*i:Q15*/ + Word32 *direct_response_fx, /*i/o:Q_direct_response*/ + Word16 *Q_direct_response, /*i/o:stores q for direct_response_fx*/ const Word16 num_channels_dir, const Word16 ambisonics_order ) { @@ -6454,18 +6475,18 @@ static void spreadCoherencePanningHoa_fx( Word32 gainCenter_fx; Word32 gainSide_fx; - ivas_dirac_dec_get_response_fx( azimuth, elevation, direct_response_fx, ambisonics_order, *Q_direct_response ); + ivas_dirac_dec_get_response_fx( azimuth, elevation, direct_response_fx /*Q_direct_response*/, ambisonics_order, *Q_direct_response ); Word16 exp_Gain_side, exp_Gain_center; IF( spreadCoh_fx > 0 ) { - ivas_dirac_dec_get_response_fx( add( azimuth, 30 ), elevation, direct_response_left_fx, ambisonics_order, *Q_direct_response ); - ivas_dirac_dec_get_response_fx( add( azimuth, 330 ), elevation, direct_response_right_fx, ambisonics_order, *Q_direct_response ); + ivas_dirac_dec_get_response_fx( add( azimuth, 30 ), elevation, direct_response_left_fx /*Q_direct_response*/, ambisonics_order, *Q_direct_response ); + ivas_dirac_dec_get_response_fx( add( azimuth, 330 ), elevation, direct_response_right_fx /*Q_direct_response*/, ambisonics_order, *Q_direct_response ); Word16 var_a, var_b, exp_a; - IF( LT_16( spreadCoh_fx, ONE_IN_Q14 ) ) + IF( LT_16( spreadCoh_fx, ONE_IN_Q14 /*0.5 q15*/ ) ) { /*gainCenter = (3 - 4*spreadCoh )/3*/ var_a = sub( 24576 /*3 in Q13*/, spreadCoh_fx ); // Q13 @@ -6480,16 +6501,16 @@ static void spreadCoherencePanningHoa_fx( } ELSE { - var_a = shl( sub( 16384 /*2 in Q13*/, shr( spreadCoh_fx, 2 ) ), 1 ); + var_a = shl( sub( 16384 /*2 in Q13*/, shr( spreadCoh_fx, 2 ) ), 1 ); // q13 exp_a = 15 - Q13; move16(); - var_a = Inv16( var_a, &exp_a ); - gainSide_fx = L_deposit_h( var_a ); // Q14 + 16 = Q30 //exp_a + var_a = Inv16( var_a, &exp_a ); // 15-exp_a + gainSide_fx = L_deposit_h( var_a ); // 15-exp_a + 16 = Q31 -exp_a exp_Gain_side = exp_a; move16(); var_b = sub( 8192 /*2 in Q12*/, shr( spreadCoh_fx, 2 ) /*Q14*/ ); // exp => 3 - gainCenter_fx = L_deposit_h( mult( var_b, var_a ) ); // Q13 + 16 = Q29 // 3 + exp_a + gainCenter_fx = L_deposit_h( mult( var_b, var_a ) ); // 15-exp_a + 12-15+16=>28-exp_a = // 3 + exp_a exp_Gain_center = add( 3, exp_a ); } @@ -6503,7 +6524,7 @@ static void spreadCoherencePanningHoa_fx( mpy2 = Mpy_32_32( direct_response_fx[i], gainCenter_fx ); // 31 - Q_direct_response + exp_Gain_Center exp = 0; move16(); - direct_response_fx[i] = BASOP_Util_Add_Mant32Exp( mpy1, 31 - *Q_direct_response + exp_Gain_side, mpy2, add( sub( 31, *Q_direct_response ), exp_Gain_center ), &exp ); + direct_response_fx[i] = BASOP_Util_Add_Mant32Exp( mpy1, add( sub( 31, *Q_direct_response ), exp_Gain_side ), mpy2, add( sub( 31, *Q_direct_response ), exp_Gain_center ), &exp ); // 31-exp move32(); exp_arr[i] = exp; move16(); @@ -6516,7 +6537,7 @@ static void spreadCoherencePanningHoa_fx( } FOR( i = 0; i < 16; i++ ) { - direct_response_fx[i] = L_shr( direct_response_fx[i], sub( max_val, exp_arr[i] ) ); + direct_response_fx[i] = L_shr( direct_response_fx[i], sub( max_val, exp_arr[i] ) ); // Q(31-exp_arr[i])->q(31-max_val) move32(); } *Q_direct_response = sub( 31, max_val ); @@ -6572,11 +6593,11 @@ static void spreadCoherencePanningHoa( #ifdef IVAS_FLOAT_FIXED static void spreadCoherencePanningVbap_fx( - const Word16 azimuth, - const Word16 elevation, - const Word16 spreadCoh_fx, - Word32 *direct_response_fx, - Word16 *Q_direct_response, + const Word16 azimuth, /*i:q0*/ + const Word16 elevation, /*i:q0*/ + const Word16 spreadCoh_fx, /*i:q15*/ + Word32 *direct_response_fx, /*i/o:Q_direct_response*/ + Word16 *Q_direct_response, /*o: stores q for direct_response_fx*/ const Word16 num_channels_dir, const VBAP_HANDLE hVBAPdata ) { @@ -6602,14 +6623,14 @@ static void spreadCoherencePanningVbap_fx( } set32_fx( direct_response_fx, 0, MAX_OUTPUT_CHANNELS ); - vbap_determine_gains_fx( hVBAPdata, direct_response_fx, azimuth, elevation, 0 ); + vbap_determine_gains_fx( hVBAPdata, direct_response_fx /*q29*/, azimuth, elevation, 0 ); *Q_direct_response = Q29; move16(); IF( spreadCoh_fx > 0 ) { - vbap_determine_gains_fx( hVBAPdata, direct_response_left_fx, add( azimuth, 30 ), elevation, 0 ); - vbap_determine_gains_fx( hVBAPdata, direct_response_right_fx, sub( azimuth, 30 ), elevation, 0 ); + vbap_determine_gains_fx( hVBAPdata, direct_response_left_fx /*q29*/, add( azimuth, 30 ), elevation, 0 ); + vbap_determine_gains_fx( hVBAPdata, direct_response_right_fx /*q29*/, sub( azimuth, 30 ), elevation, 0 ); Word32 var1 = 0; move32(); @@ -6703,8 +6724,8 @@ static void spreadCoherencePanningVbap( #ifdef IVAS_FLOAT_FIXED static void normalizePanningGains_fx( - Word32 *direct_response_fx, - Word16 *q_direct_res, + Word32 *direct_response_fx, /*i/o:resultant q is q_direct_res*/ + Word16 *q_direct_res, /*i/o: stores q for direct_response_fx*/ const Word16 num_channels_dir ) { Word32 energySum_fx; @@ -6714,7 +6735,7 @@ static void normalizePanningGains_fx( move16(); Word16 gb = find_guarded_bits_fx( num_channels_dir ); - energySum_fx = sum2_f_32_fx( direct_response_fx, num_channels_dir, gb ); + energySum_fx = sum2_f_32_fx( direct_response_fx, num_channels_dir, gb ); // exp_energySum stores resultant exponent IF( GT_16( *q_direct_res, Q31 ) ) { exp_energySum = add( shl( sub( Q31, *q_direct_res ), 1 ), gb ); @@ -6723,17 +6744,17 @@ static void normalizePanningGains_fx( IF( energySum_fx > 0 ) { - normVal_fx = ISqrt32( energySum_fx, &exp_energySum ); + normVal_fx = ISqrt32( energySum_fx, &exp_energySum ); // 31-exp_energySum } ELSE { - energySum_fx = BASOP_Util_Add_Mant32Exp( energySum_fx, exp_energySum, ONE_IN_Q30, 1, &exp_energySum ); - normVal_fx = ISqrt32( energySum_fx, &exp_energySum ); + energySum_fx = BASOP_Util_Add_Mant32Exp( energySum_fx, exp_energySum, ONE_IN_Q30, 1, &exp_energySum ); // 31-exp_energySum + normVal_fx = ISqrt32( energySum_fx, &exp_energySum ); // 31-exp_energySum } FOR( i = 0; i < num_channels_dir; i++ ) { - direct_response_fx[i] = Mpy_32_32( direct_response_fx[i], normVal_fx ); + direct_response_fx[i] = Mpy_32_32( direct_response_fx[i], normVal_fx ); // q_direct_res stores resultant q for the same move32(); } Word16 exp = add( sub( Q31, *q_direct_res ), exp_energySum ); -- GitLab From 8a552db21379224392a5451afbd1ba62c6997cf3 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Wed, 23 Oct 2024 14:05:53 +0530 Subject: [PATCH 024/128] Clang formatting changes --- lib_dec/tonalMDCTconcealment_fx.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib_dec/tonalMDCTconcealment_fx.c b/lib_dec/tonalMDCTconcealment_fx.c index b46d0abd5..adb73de03 100644 --- a/lib_dec/tonalMDCTconcealment_fx.c +++ b/lib_dec/tonalMDCTconcealment_fx.c @@ -1621,10 +1621,10 @@ void TonalMDCTConceal_InsertNoise_ivas_fx( { Word16 x = hTonalMDCTConc->lastBlockData.spectralData[l]; move16(); - Word32 y = concealment_noise[l];//concealment_noise_e + Word32 y = concealment_noise[l]; // concealment_noise_e move32(); - last_block_nrg_correct = L_add( last_block_nrg_correct, Mpy_32_16_1( L_msu( 0, x, fac ), x ) ); // exp = 2 * x_exp + ld - y = L_negate( Mpy_32_32( y, y ) );//Q31-2* concealment_noise_e + last_block_nrg_correct = L_add( last_block_nrg_correct, Mpy_32_16_1( L_msu( 0, x, fac ), x ) ); // exp = 2 * x_exp + ld + y = L_negate( Mpy_32_32( y, y ) ); // Q31-2* concealment_noise_e hTonalMDCTConc->curr_noise_nrg = BASOP_Util_Add_Mant32Exp( hTonalMDCTConc->curr_noise_nrg, hTonalMDCTConc->curr_noise_nrg_exp, y, 2 * concealment_noise_e, &hTonalMDCTConc->curr_noise_nrg_exp ); // Q31- hTonalMDCTConc->curr_noise_nrg_exp move32(); } -- GitLab From 342430c51e3a9d5cd060ba9cfc04d73eeec1ead2 Mon Sep 17 00:00:00 2001 From: Adriana Vasilache Date: Tue, 17 Sep 2024 01:20:00 +0300 Subject: [PATCH 025/128] fix 853 fixed point --- lib_com/options.h | 2 +- lib_dec/ivas_masa_dec.c | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/lib_com/options.h b/lib_com/options.h index 87f712150..424110028 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -191,7 +191,7 @@ #define FIX_924_IGF_ROUNDFX_SAT #define FIX_930_JBM_BUFSIZE_MULT /* FhG: Fix 930, Word16 too small for apa_buffer_size */ #define NONBE_FIX_943_PORT_1208_DFT_STEREO_PLC_BURST /* Ericsson: BASOP Issue 943, Float Issue 1208, fix for overflow of sample offset counter for burst error in DFT Stereo PLC. */ - +#define FIX_853_DECODE_MASA_ISM_AZIMUTH_PREC /* Nokia: Fixes ivas_decode_masaism_metadata decision logic change due to precision difference; needs corresponding fix in floating point */ /* ################## End DEVELOPMENT switches ######################### */ /* clang-format on */ diff --git a/lib_dec/ivas_masa_dec.c b/lib_dec/ivas_masa_dec.c index 6903773ed..eb805a80c 100644 --- a/lib_dec/ivas_masa_dec.c +++ b/lib_dec/ivas_masa_dec.c @@ -5585,6 +5585,10 @@ static Word16 ivas_decode_masaism_metadata_fx( Word16 tmp_e; delta_phi = L_deposit_h( BASOP_Util_Divide1616_Scale( 180, no_phi_masa[bits_ism[obj] - 1][idx_el], &tmp_e ) ); delta_phi = L_shr( delta_phi, sub( 9, tmp_e ) ); /* to maintain Q22 */ +#ifdef FIX_853_DECODE_MASA_ISM_AZIMUTH_PREC + delta_phi = L_shr( delta_phi, 22 ); + delta_phi = L_shl( delta_phi, 22 ); +#endif IF( GT_32( L_sub( azimuth, hMasaIsmData->q_azimuth_old_fx[obj] ), delta_phi ) ) { azimuth = L_sub( azimuth, delta_phi ); -- GitLab From a7542956e41d112aa34c37569572f974d21661e9 Mon Sep 17 00:00:00 2001 From: Adriana Vasilache Date: Sat, 28 Sep 2024 16:48:44 +0300 Subject: [PATCH 026/128] fix 853 basop --- lib_dec/ivas_masa_dec.c | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/lib_dec/ivas_masa_dec.c b/lib_dec/ivas_masa_dec.c index eb805a80c..f49c5556c 100644 --- a/lib_dec/ivas_masa_dec.c +++ b/lib_dec/ivas_masa_dec.c @@ -5522,7 +5522,12 @@ static Word16 ivas_decode_masaism_metadata_fx( Word16 nb_bits_read; Word32 delta_phi; // Q22 Word16 meta_write_index; +#if 1 + static FILE *pF = NULL; + if ( pF == NULL ) + pF = fopen( "./direction.txt", "w" ); +#endif nb_bits_read = *next_bit_pos; move16(); nbands = hQMetaData->q_direction->cfg.nbands; @@ -5585,19 +5590,46 @@ static Word16 ivas_decode_masaism_metadata_fx( Word16 tmp_e; delta_phi = L_deposit_h( BASOP_Util_Divide1616_Scale( 180, no_phi_masa[bits_ism[obj] - 1][idx_el], &tmp_e ) ); delta_phi = L_shr( delta_phi, sub( 9, tmp_e ) ); /* to maintain Q22 */ + #if 0 #ifdef FIX_853_DECODE_MASA_ISM_AZIMUTH_PREC - delta_phi = L_shr( delta_phi, 22 ); - delta_phi = L_shl( delta_phi, 22 ); + delta_phi = L_shr( delta_phi, 20 ); + delta_phi = L_shl( delta_phi, 20 ); +#endif + #endif +#if 1 + fprintf( pF, "azimuth = %4.2f delta_phi = %4.2f obj = %d \n", (float) azimuth / (float) 4194304, (float) delta_phi / (float) 4194304, obj ); #endif +#ifdef FIX_853_DECODE_MASA_ISM_AZIMUTH_PREC + Word32 tmp_32; + Word64 tmp_64; + tmp_32 = L_sub( azimuth, hMasaIsmData->q_azimuth_old_fx[obj] ); + tmp_64 = W_mult_32_16( tmp_32, no_phi_masa[bits_ism[obj] - 1][idx_el] ); + + + IF( GT_64( tmp_64, (DEGREE_360_Q_22 + 83886) ) ) /* >= 360 in Q22 + 0.02 in Q22, because there is an additional shift left in W_mult_32_16*/ +#else IF( GT_32( L_sub( azimuth, hMasaIsmData->q_azimuth_old_fx[obj] ), delta_phi ) ) +#endif { azimuth = L_sub( azimuth, delta_phi ); +#if 1 + fprintf( pF, "azimuth = %3.1f obj = %d 1 \n", (float) azimuth / (float) 4194304, obj ); +#endif } ELSE { +#ifdef FIX_853_DECODE_MASA_ISM_AZIMUTH_PREC + + IF( GT_64( -DEGREE_360_Q_22 - 83886, tmp_64 ) ) +#else if ( GT_32( L_sub( hMasaIsmData->q_azimuth_old_fx[obj], azimuth ), delta_phi ) ) +#endif { azimuth = L_add( azimuth, delta_phi ); +#if 1 + fprintf( pF, "azimuth = %3.1f obj = %d -1 \n", (float) azimuth / (float) 4194304, obj ); +#endif + } } } -- GitLab From e2801e12b3a46564a28f5996a1162eacb01be4ee Mon Sep 17 00:00:00 2001 From: Adriana Vasilache Date: Sat, 28 Sep 2024 17:53:05 +0300 Subject: [PATCH 027/128] fix 853 basop --- lib_com/ivas_cnst.h | 5 ++++- lib_dec/ivas_masa_dec.c | 24 ++++-------------------- 2 files changed, 8 insertions(+), 21 deletions(-) diff --git a/lib_com/ivas_cnst.h b/lib_com/ivas_cnst.h index 5fef65816..1356d695e 100644 --- a/lib_com/ivas_cnst.h +++ b/lib_com/ivas_cnst.h @@ -1353,7 +1353,10 @@ enum #define MASA_JBM_RINGBUFFER_FRAMES 3 - +#ifdef FIX_853_DECODE_MASA_ISM_AZIMUTH_PREC +#define TOLERANCE_360_Q22 1510033326 /* 360 in Q22 + 0.02 in Q22*/ +#define MINUS_TOLERANCE_360_Q22 -1510033326 /* - (360 in Q22 + 0.02 in Q22) */ +#endif typedef enum { MASA_STEREO_NOT_DEFINED, diff --git a/lib_dec/ivas_masa_dec.c b/lib_dec/ivas_masa_dec.c index f49c5556c..a1a7c5728 100644 --- a/lib_dec/ivas_masa_dec.c +++ b/lib_dec/ivas_masa_dec.c @@ -5590,46 +5590,30 @@ static Word16 ivas_decode_masaism_metadata_fx( Word16 tmp_e; delta_phi = L_deposit_h( BASOP_Util_Divide1616_Scale( 180, no_phi_masa[bits_ism[obj] - 1][idx_el], &tmp_e ) ); delta_phi = L_shr( delta_phi, sub( 9, tmp_e ) ); /* to maintain Q22 */ - #if 0 -#ifdef FIX_853_DECODE_MASA_ISM_AZIMUTH_PREC - delta_phi = L_shr( delta_phi, 20 ); - delta_phi = L_shl( delta_phi, 20 ); -#endif - #endif -#if 1 - fprintf( pF, "azimuth = %4.2f delta_phi = %4.2f obj = %d \n", (float) azimuth / (float) 4194304, (float) delta_phi / (float) 4194304, obj ); -#endif + #ifdef FIX_853_DECODE_MASA_ISM_AZIMUTH_PREC Word32 tmp_32; Word64 tmp_64; tmp_32 = L_sub( azimuth, hMasaIsmData->q_azimuth_old_fx[obj] ); tmp_64 = W_mult_32_16( tmp_32, no_phi_masa[bits_ism[obj] - 1][idx_el] ); - - IF( GT_64( tmp_64, (DEGREE_360_Q_22 + 83886) ) ) /* >= 360 in Q22 + 0.02 in Q22, because there is an additional shift left in W_mult_32_16*/ + IF( GT_64( tmp_64, TOLERANCE_360_Q22 ) ) /* >= 360 in Q22 (because there is an additional shift left in W_mult_32_16) + 0.02 in Q22 to counteract for precision loss, */ #else IF( GT_32( L_sub( azimuth, hMasaIsmData->q_azimuth_old_fx[obj] ), delta_phi ) ) #endif { azimuth = L_sub( azimuth, delta_phi ); -#if 1 - fprintf( pF, "azimuth = %3.1f obj = %d 1 \n", (float) azimuth / (float) 4194304, obj ); -#endif } ELSE { #ifdef FIX_853_DECODE_MASA_ISM_AZIMUTH_PREC - IF( GT_64( -DEGREE_360_Q_22 - 83886, tmp_64 ) ) + IF( GT_64( MINUS_TOLERANCE_360_Q22, tmp_64 ) ) #else if ( GT_32( L_sub( hMasaIsmData->q_azimuth_old_fx[obj], azimuth ), delta_phi ) ) #endif { - azimuth = L_add( azimuth, delta_phi ); -#if 1 - fprintf( pF, "azimuth = %3.1f obj = %d -1 \n", (float) azimuth / (float) 4194304, obj ); -#endif - + azimuth = L_add( azimuth, delta_phi ); } } } -- GitLab From f2c82000e89a82af976397b321c482382720f51f Mon Sep 17 00:00:00 2001 From: Adriana Vasilache Date: Sun, 29 Sep 2024 09:36:29 +0300 Subject: [PATCH 028/128] fix clang --- lib_dec/ivas_masa_dec.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/lib_dec/ivas_masa_dec.c b/lib_dec/ivas_masa_dec.c index a1a7c5728..eea31e559 100644 --- a/lib_dec/ivas_masa_dec.c +++ b/lib_dec/ivas_masa_dec.c @@ -5584,20 +5584,20 @@ static Word16 ivas_decode_masaism_metadata_fx( test(); test(); test(); - // if ( azimuth * hMasaIsmData->q_azimuth_old[obj] > 0 ) + /* if ( azimuth * hMasaIsmData->q_azimuth_old[obj] > 0 ) */ IF( ( ( azimuth > 0 ) && ( hMasaIsmData->q_azimuth_old_fx[obj] > 0 ) ) || ( ( azimuth < 0 ) && ( hMasaIsmData->q_azimuth_old_fx[obj] < 0 ) ) ) { Word16 tmp_e; delta_phi = L_deposit_h( BASOP_Util_Divide1616_Scale( 180, no_phi_masa[bits_ism[obj] - 1][idx_el], &tmp_e ) ); delta_phi = L_shr( delta_phi, sub( 9, tmp_e ) ); /* to maintain Q22 */ -#ifdef FIX_853_DECODE_MASA_ISM_AZIMUTH_PREC +#ifdef FIX_853_DECODE_MASA_ISM_AZIMUTH_PREC Word32 tmp_32; Word64 tmp_64; tmp_32 = L_sub( azimuth, hMasaIsmData->q_azimuth_old_fx[obj] ); tmp_64 = W_mult_32_16( tmp_32, no_phi_masa[bits_ism[obj] - 1][idx_el] ); - IF( GT_64( tmp_64, TOLERANCE_360_Q22 ) ) /* >= 360 in Q22 (because there is an additional shift left in W_mult_32_16) + 0.02 in Q22 to counteract for precision loss, */ + IF( GT_64( tmp_64, TOLERANCE_360_Q22 ) ) /* >= 360 in Q22 (because there is an additional shift left in W_mult_32_16) + 0.02 in Q22 to counteract for precision loss, */ #else IF( GT_32( L_sub( azimuth, hMasaIsmData->q_azimuth_old_fx[obj] ), delta_phi ) ) #endif @@ -5607,13 +5607,12 @@ static Word16 ivas_decode_masaism_metadata_fx( ELSE { #ifdef FIX_853_DECODE_MASA_ISM_AZIMUTH_PREC - IF( GT_64( MINUS_TOLERANCE_360_Q22, tmp_64 ) ) #else if ( GT_32( L_sub( hMasaIsmData->q_azimuth_old_fx[obj], azimuth ), delta_phi ) ) #endif { - azimuth = L_add( azimuth, delta_phi ); + azimuth = L_add( azimuth, delta_phi ); } } } -- GitLab From 0bbf2c7cd5140d12728312054c52bd515cdbb391 Mon Sep 17 00:00:00 2001 From: Adriana Vasilache Date: Tue, 8 Oct 2024 14:21:57 +0300 Subject: [PATCH 029/128] remove debug code from issue 853 --- lib_dec/ivas_masa_dec.c | 5 ----- 1 file changed, 5 deletions(-) diff --git a/lib_dec/ivas_masa_dec.c b/lib_dec/ivas_masa_dec.c index eea31e559..13e970f85 100644 --- a/lib_dec/ivas_masa_dec.c +++ b/lib_dec/ivas_masa_dec.c @@ -5522,12 +5522,7 @@ static Word16 ivas_decode_masaism_metadata_fx( Word16 nb_bits_read; Word32 delta_phi; // Q22 Word16 meta_write_index; -#if 1 - static FILE *pF = NULL; - if ( pF == NULL ) - pF = fopen( "./direction.txt", "w" ); -#endif nb_bits_read = *next_bit_pos; move16(); nbands = hQMetaData->q_direction->cfg.nbands; -- GitLab From ce60a2351b70dcfc9ccc264e5cca341d960732a9 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Wed, 23 Oct 2024 17:22:46 +0530 Subject: [PATCH 030/128] Fix for 3GPP issue 885: Crashes in stereo BASOP decoder with error pattern from complexity measurement --- lib_dec/swb_tbe_dec.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib_dec/swb_tbe_dec.c b/lib_dec/swb_tbe_dec.c index c519d51b1..c5c1bed29 100644 --- a/lib_dec/swb_tbe_dec.c +++ b/lib_dec/swb_tbe_dec.c @@ -1862,8 +1862,8 @@ void ivas_swb_tbe_dec_fx( FOR( i = 0; i < L_SHB_LAHEAD; i++ ) { - L_tmp = Mult_32_16( Lscale, shaped_shb_excitation_fx[i] ); /* Q_bwe_exc + (31-exp) - 15 */ - shaped_shb_excitation_fx[i] = round_fx( L_shl( L_tmp, exp ) ); /* Q_bwe_exc */ + L_tmp = Mult_32_16( Lscale, shaped_shb_excitation_fx[i] ); /* Q_bwe_exc + (31-exp) - 15 */ + shaped_shb_excitation_fx[i] = round_fx_sat( L_shl_sat( L_tmp, exp ) ); /* Q_bwe_exc */ move16(); } IF( exp < 0 ) @@ -1883,8 +1883,8 @@ void ivas_swb_tbe_dec_fx( #endif temp_fx = sub( 32767 /*1.0f Q15*/, temp_fx ); Lscale = L_add( Mult_32_16( Lscale, temp_fx ), L_tmp1 ); - L_tmp = Mult_32_16( Lscale, shaped_shb_excitation_fx[i] ); /* Q_bwe_exc + (31-exp) - 15 */ - shaped_shb_excitation_fx[i] = round_fx( L_shl( L_tmp, exp ) ); /* Q_bwe_exc */ + L_tmp = Mult_32_16( Lscale, shaped_shb_excitation_fx[i] ); /* Q_bwe_exc + (31-exp) - 15 */ + shaped_shb_excitation_fx[i] = round_fx_sat( L_shl_sat( L_tmp, exp ) ); /* Q_bwe_exc */ move16(); } } -- GitLab From e8a625a2c6d4b32e1551335707107972f49dd0c4 Mon Sep 17 00:00:00 2001 From: Archit Tamarapu Date: Wed, 23 Oct 2024 14:56:41 +0200 Subject: [PATCH 031/128] add missing pop_wmops(); in ivas_vbap.c --- lib_rend/ivas_vbap.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib_rend/ivas_vbap.c b/lib_rend/ivas_vbap.c index 3d62f5952..91587f46d 100644 --- a/lib_rend/ivas_vbap.c +++ b/lib_rend/ivas_vbap.c @@ -467,6 +467,8 @@ ivas_error vbap_init_data_fx( } } + pop_wmops(); + IF( is_success ) { *hVBAPdata = vbap; -- GitLab From 26f383a19d482046934efc5e6d21a8c5bb31798a Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Thu, 24 Oct 2024 09:19:14 +0530 Subject: [PATCH 032/128] Q-information update for lib_dec and lib_rend files --- lib_com/common_api_types.h | 14 +- lib_com/ivas_prot.h | 10 +- lib_com/ivas_tools.c | 21 +- lib_com/tools.c | 6 +- lib_dec/lead_deindexing_fx.c | 4 +- lib_dec/lib_dec.h | 22 +- lib_dec/lib_dec_fx.c | 164 +++++----- lib_dec/lp_exc_d_fx.c | 8 +- lib_rend/ivas_efap.c | 2 +- lib_rend/ivas_prot_rend.h | 22 +- lib_rend/ivas_stat_rend.h | 16 +- lib_rend/ivas_vbap.c | 537 +++++++++++++++--------------- lib_rend/lib_rend.c | 617 +++++++++++++++++++---------------- lib_rend/lib_rend.h | 194 +++++------ 14 files changed, 862 insertions(+), 775 deletions(-) diff --git a/lib_com/common_api_types.h b/lib_com/common_api_types.h index 3e8a963cd..ed75c249b 100644 --- a/lib_com/common_api_types.h +++ b/lib_com/common_api_types.h @@ -119,13 +119,13 @@ typedef struct _IVAS_ENC_CHANNEL_AWARE_CONFIG typedef struct _IVAS_ISM_METADATA { #ifdef IVAS_FLOAT_FIXED - Word32 azimuth_fx; - Word32 elevation_fx; - Word16 radius_fx; - Word32 spread_fx; - Word32 gainFactor_fx; - Word32 yaw_fx; - Word32 pitch_fx; + Word32 azimuth_fx; /* Q22 */ + Word32 elevation_fx; /* Q22 */ + Word16 radius_fx; /* Q9 */ + Word32 spread_fx; /* Q22 */ + Word32 gainFactor_fx; /* Q31 */ + Word32 yaw_fx; /* Q22 */ + Word32 pitch_fx; /* Q22 */ #endif float azimuth; float elevation; diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index 876313d1b..db7ec4ee2 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -7570,11 +7570,11 @@ void panning_wrap_angles( float *ele_wrapped /* o : wrapped elevation component */ ); #ifdef IVAS_FLOAT_FIXED -void panning_wrap_angles_fixed( - const Word32 azi_deg, /* i : azimuth in degrees for panning direction (positive left) */ - const Word32 ele_deg, /* i : elevation in degrees for panning direction (positive up) */ - Word32 *azi_wrapped, /* o : wrapped azimuth component */ - Word32 *ele_wrapped /* o : wrapped elevation component */ +void panning_wrap_angles_fx( + const Word32 azi_deg, /* i : azimuth in degrees for panning direction (positive left) Q22 */ + const Word32 ele_deg, /* i : elevation in degrees for panning direction (positive up) Q22 */ + Word32 *azi_wrapped, /* o : wrapped azimuth component Q22 */ + Word32 *ele_wrapped /* o : wrapped elevation component Q22 */ ); #endif void v_sort_ind( diff --git a/lib_com/ivas_tools.c b/lib_com/ivas_tools.c index 76e84cc9a..20cce673c 100644 --- a/lib_com/ivas_tools.c +++ b/lib_com/ivas_tools.c @@ -2938,8 +2938,8 @@ static float wrap_azi( } #ifdef IVAS_FLOAT_FIXED /* helper function for panning_wrap_angles */ -static Word32 wrap_azi_fixed( - const Word32 azi_deg ) +static Word32 wrap_azi_fx( + const Word32 azi_deg /* Q22 */ ) { Word32 azi = azi_deg; move32(); @@ -3027,19 +3027,18 @@ void panning_wrap_angles( } #ifdef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* - * panning_wrap_angles_fixed() + * panning_wrap_angles_fx() * * Wrap angles for amplitude panning to the range: * azimuth = (-180, 180] * elevation = [-90, 90] * Considers direction changes from large elevation values *-------------------------------------------------------------------*/ -void panning_wrap_angles_fixed( - const Word32 azi_deg, /* i : azimuth in degrees for panning direction (positive left) */ - const Word32 ele_deg, /* i : elevation in degrees for panning direction (positive up) */ - Word32 *azi_wrapped, /* o : wrapped azimuth component */ - Word32 *ele_wrapped /* o : wrapped elevation component */ - +void panning_wrap_angles_fx( + const Word32 azi_deg, /* i : azimuth in degrees for panning direction (positive left) Q22 */ + const Word32 ele_deg, /* i : elevation in degrees for panning direction (positive up) Q22 */ + Word32 *azi_wrapped, /* o : wrapped azimuth component Q22 */ + Word32 *ele_wrapped /* o : wrapped elevation component Q22 */ ) { Word32 azi, ele; @@ -3053,7 +3052,7 @@ void panning_wrap_angles_fixed( { *ele_wrapped = ele; move32(); - *azi_wrapped = wrap_azi_fixed( azi ); + *azi_wrapped = wrap_azi_fx( azi ); move32(); return; } @@ -3093,7 +3092,7 @@ void panning_wrap_angles_fixed( ele = L_sub( -ANGLE_180_DEG_Q22, ele ); } } - *azi_wrapped = wrap_azi_fixed( azi ); + *azi_wrapped = wrap_azi_fx( azi ); move32(); *ele_wrapped = ele; move32(); diff --git a/lib_com/tools.c b/lib_com/tools.c index 0222d6cc4..072cfa767 100644 --- a/lib_com/tools.c +++ b/lib_com/tools.c @@ -1101,9 +1101,9 @@ float dotp( /*! r: dot product of x[] and y[] */ Word32 dotp_fixed( - const Word32 x[], /* i : vector x[] */ - const Word32 y[], /* i : vector y[] */ - const Word16 n /* i : vector length */ + const Word32 x[], /* i : vector x[] Qx */ + const Word32 y[], /* i : vector y[] Qy */ + const Word16 n /* i : vector length */ ) { Word16 i; diff --git a/lib_dec/lead_deindexing_fx.c b/lib_dec/lead_deindexing_fx.c index 068d60bb1..4c13ee392 100644 --- a/lib_dec/lead_deindexing_fx.c +++ b/lib_dec/lead_deindexing_fx.c @@ -277,7 +277,7 @@ static void fcb_decode_pos_fx( FOR( i = 0; i < tmp_loop; i++ ) { select_table23 = select_table22[temp1]; - select_table24 = &select_table23[sub( pulse_num, l )]; + select_table24 = &select_table23[pulse_num - l]; k = sub( *select_table24, k ); WHILE( LE_16( k, *select_table24 ) ) @@ -286,7 +286,7 @@ static void fcb_decode_pos_fx( select_table24--; } - k = sub( select_table23[sub( temp2, l )], k ); + k = sub( select_table23[temp2 - l], k ); pos_vector[i] = sub( l, 1 ); move16(); temp1 = sub( temp1, 1 ); diff --git a/lib_dec/lib_dec.h b/lib_dec/lib_dec.h index 93604547b..e44092fb6 100644 --- a/lib_dec/lib_dec.h +++ b/lib_dec/lib_dec.h @@ -430,7 +430,7 @@ ivas_error IVAS_DEC_Configure( const IVAS_HEAD_ORIENT_TRK_T orientation_tracking, /* i : head orientation tracking type */ const Word16 renderConfigEnabled, /* i : enable Renderer config. file for binaural output */ const Word16 Opt_non_diegetic_pan, /* i : diegetic or not */ - const Word16 non_diegetic_pan_gain_fx, /* i : non diegetic panning gain */ + const Word16 non_diegetic_pan_gain_fx, /* i : non diegetic panning gain Q15 */ const Word16 Opt_dpid_on, /* i : enable directivity pattern option */ const UWord16 acousticEnvironmentId, /* i : Acoustic environment ID */ const Word16 delayCompensationEnabled /* i : enable delay compensation */ @@ -455,7 +455,7 @@ ivas_error IVAS_DEC_FeedFrame_Serial( ivas_error IVAS_DEC_GetSamples( IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ const Word16 nSamplesAsked, /* i : number of samples wanted by the caller */ - Word16 *pcmBuf, /* i/o: buffer for decoded PCM output. The memory must already be allocated and be able to hold the expected number of output samples, based on frame size and number of output channels */ + Word16 *pcmBuf, /* i/o: buffer for decoded PCM output. The memory must already be allocated and be able to hold the expected number of output samples, based on frame size and number of output channels Q0 */ Word16 *nOutSamples, /* o : number of samples per channel written to output buffer */ bool *needNewFrame /* o : indication that the decoder needs a new frame */ ); @@ -527,14 +527,14 @@ ivas_error IVAS_DEC_VoIP_SetScale( ivas_error IVAS_DEC_TSM_SetQuality( IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ - const Word16 quality /* i : target TSM quality */ + const Word16 quality /* i : target TSM quality Q14 */ ); /*! r: error code */ ivas_error IVAS_DEC_VoIP_GetSamples( IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ UWord16 nSamplesPerChannel, /* i : number of samples per channel requested to be written to output buffer */ - Word16 *pcmBuf, /* i/o: buffer for decoded PCM output. The memory must already be allocated and be able to hold the expected number of output samples, based on frame size and number of output channels */ + Word16 *pcmBuf, /* i/o: buffer for decoded PCM output. The memory must already be allocated and be able to hold the expected number of output samples, based on frame size and number of output channels Q0 */ const UWord32 systemTimestamp_ms /* i : current system timestamp */ #ifdef SUPPORT_JBM_TRACEFILE , JbmTraceFileWriterFn jbmWriterFn, @@ -545,7 +545,7 @@ ivas_error IVAS_DEC_VoIP_GetSamples( ivas_error IVAS_DEC_Flush( IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ const Word16 nSamplesPerChannel, /* i : number of samples per channel requested to be written to output buffer */ - Word16 *pcmBuf, /* i/o: buffer for decoded PCM output. The memory must already be allocated and be able to hold the expected number of output samples, based on frame size and number of output channels */ + Word16 *pcmBuf, /* i/o: buffer for decoded PCM output. The memory must already be allocated and be able to hold the expected number of output samples, based on frame size and number of output channels Q0 */ Word16 *nSamplesFlushed /* o : number of samples flushed */ ); @@ -571,12 +571,12 @@ ivas_error IVAS_DEC_GetRenderFramesize( ivas_error IVAS_DEC_GetRenderFramesizeSamples( IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ - Word16 *render_framesize /* o : render framesize in samples */ + Word16 *render_framesize /* o : render framesize in samples Q0 */ ); ivas_error IVAS_DEC_GetReferencesUpdateFrequency( IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ - Word16 *update_frequency /* o : update frequency */ + Word16 *update_frequency /* o : update frequency Q0 */ ); ivas_error IVAS_DEC_GetNumOrientationSubframes( @@ -586,7 +586,7 @@ ivas_error IVAS_DEC_GetNumOrientationSubframes( ivas_error IVAS_DEC_GetRenderFramesizeMs( IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ - UWord32 *render_framesize /* o : render framesize in samples */ + UWord32 *render_framesize /* o : render framesize in samples Q0 */ ); @@ -678,7 +678,7 @@ ivas_error IVAS_DEC_HasDecodedFirstGoodFrame( /*! r: error code */ ivas_error IVAS_DEC_GetPcmFrameSize( IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ - Word32 *pcmFrameSize /* o : total size of the PCM output frame. This takes into account the number of output channels */ + Word32 *pcmFrameSize /* o : total size of the PCM output frame. This takes into account the number of output channels Q0 */ ); /*! r: true if decoder has no data in VoIP jitter buffer */ @@ -689,8 +689,8 @@ bool IVAS_DEC_VoIP_IsEmpty( ivas_error IVAS_DEC_VoIP_Get_CA_offset( IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ - Word16 *optimum_offset, - Word16 *FEC_hi + Word16 *optimum_offset, //Q0 + Word16 *FEC_hi //Q0 ); #ifdef SUPPORT_JBM_TRACEFILE diff --git a/lib_dec/lib_dec_fx.c b/lib_dec/lib_dec_fx.c index d3e26547e..05fd52bfb 100644 --- a/lib_dec/lib_dec_fx.c +++ b/lib_dec/lib_dec_fx.c @@ -295,7 +295,7 @@ static void init_decoder_config( hDecoderConfig->Opt_RendConfigCustom = 0; hDecoderConfig->orientation_tracking = IVAS_HEAD_ORIENT_TRK_NONE; hDecoderConfig->Opt_non_diegetic_pan = 0; - hDecoderConfig->non_diegetic_pan_gain_fx = 0; + hDecoderConfig->non_diegetic_pan_gain_fx = 0; // Q15 hDecoderConfig->Opt_tsm = 0; hDecoderConfig->Opt_delay_comp = 0; hDecoderConfig->Opt_ExternalOrientation = 0; @@ -418,7 +418,7 @@ ivas_error IVAS_DEC_Configure( const IVAS_HEAD_ORIENT_TRK_T orientation_tracking, /* i : head orientation tracking type */ const Word16 renderConfigEnabled, /* i : enable Renderer config. file for binaural output */ const Word16 Opt_non_diegetic_pan, /* i : diegetic or not */ - const Word16 non_diegetic_pan_gain_fx, /* i : non diegetic panning gain */ + const Word16 non_diegetic_pan_gain_fx, /* i : non diegetic panning gain Q15 */ const Word16 Opt_dpid_on, /* i : enable directivity pattern option */ const UWord16 acousticEnvironmentId, /* i : Acoustic environment ID */ const Word16 delayCompensationEnabled /* i : enable delay compensation */ @@ -489,7 +489,7 @@ ivas_error IVAS_DEC_Configure( hDecoderConfig->Opt_HRTF_binary = hrtfReaderEnabled; hDecoderConfig->Opt_RendConfigCustom = renderConfigEnabled; hDecoderConfig->Opt_non_diegetic_pan = Opt_non_diegetic_pan; - hDecoderConfig->non_diegetic_pan_gain_fx = non_diegetic_pan_gain_fx; + hDecoderConfig->non_diegetic_pan_gain_fx = non_diegetic_pan_gain_fx; // Q15 hDecoderConfig->Opt_delay_comp = delayCompensationEnabled; hDecoderConfig->Opt_ExternalOrientation = enableExternalOrientation; hDecoderConfig->Opt_dpid_on = Opt_dpid_on; @@ -571,11 +571,11 @@ Word16 get_render_frame_size_ms( } ELSE IF( EQ_16( render_framesize, IVAS_RENDER_FRAMESIZE_10MS ) ) { - return shl( ( 1000 / ( FRAMES_PER_SEC * IVAS_MAX_PARAM_SPATIAL_SUBFRAMES ) ), 1 ); + return ( ( 1000 / ( FRAMES_PER_SEC * IVAS_MAX_PARAM_SPATIAL_SUBFRAMES ) ) << 1 ); } ELSE IF( EQ_16( render_framesize, IVAS_RENDER_FRAMESIZE_20MS ) ) { - return shl( ( 1000 / ( FRAMES_PER_SEC * IVAS_MAX_PARAM_SPATIAL_SUBFRAMES ) ), 2 ); + return ( ( 1000 / ( FRAMES_PER_SEC * IVAS_MAX_PARAM_SPATIAL_SUBFRAMES ) ) << 2 ); } return 0; } @@ -637,7 +637,7 @@ ivas_error IVAS_DEC_GetRenderFramesize( ivas_error IVAS_DEC_GetRenderFramesizeSamples( IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ - Word16 *render_framesize /* o : render framesize in samples */ + Word16 *render_framesize /* o : render framesize in samples Q0 */ ) { Word16 tmp; @@ -679,7 +679,7 @@ ivas_error IVAS_DEC_GetRenderFramesizeSamples( ivas_error IVAS_DEC_GetRenderFramesizeMs( IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ - UWord32 *render_framesize /* o : render framesize in samples */ + UWord32 *render_framesize /* o : render framesize in samples Q0 */ ) { test(); @@ -703,7 +703,7 @@ ivas_error IVAS_DEC_GetRenderFramesizeMs( ivas_error IVAS_DEC_GetReferencesUpdateFrequency( IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ - Word16 *update_frequency /* o : update frequency */ + Word16 *update_frequency /* o : update frequency Q0 */ ) { test(); @@ -937,7 +937,7 @@ ivas_error IVAS_DEC_FeedFrame_Serial( IF( EQ_16( (Word16) hIvasDec->mode, IVAS_DEC_MODE_EVS ) && hIvasDec->hVoIP != NULL && hIvasDec->hVoIP->hCurrentDataUnit != NULL && - NE_16( (Word16) hIvasDec->hVoIP->hCurrentDataUnit->partial_frame, 0 ) ) + ( (Word16) hIvasDec->hVoIP->hCurrentDataUnit->partial_frame != 0 ) ) { DEC_CORE_HANDLE st = hIvasDec->st_ivas->hSCE[0]->hCoreCoder[0]; st->codec_mode = MODE2; @@ -969,7 +969,7 @@ ivas_error IVAS_DEC_FeedFrame_Serial( ivas_error IVAS_DEC_GetSamples( IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ const Word16 nSamplesAsked, /* i : number of samples wanted by the caller */ - Word16 *pcmBuf, /* i/o: buffer for decoded PCM output. The memory must already be allocated and be able to hold the expected number of output samples, based on frame size and number of output channels */ + Word16 *pcmBuf, /* i/o: buffer for decoded PCM output. The memory must already be allocated and be able to hold the expected number of output samples, based on frame size and number of output channels Q0 */ Word16 *nOutSamples, /* o : number of samples per channel written to output buffer */ bool *needNewFrame /* o :indication that the decoder needs a new frame */ ) @@ -1090,33 +1090,33 @@ ivas_error IVAS_DEC_GetSamples( Word16 tmp_apaExecBuffer[APA_BUF]; IF( EQ_16( (Word16) hIvasDec->mode, IVAS_DEC_MODE_EVS ) ) { - for ( int i = 0; i < APA_BUF_PER_CHANNEL * nTransportChannels; ++i ) + FOR( Word16 i = 0; i < APA_BUF_PER_CHANNEL * nTransportChannels; ++i ) { - tmp_apaExecBuffer[i] = extract_l( L_shr( hIvasDec->apaExecBuffer_fx[i], Q11 ) ); + tmp_apaExecBuffer[i] = extract_l( L_shr( hIvasDec->apaExecBuffer_fx[i], Q11 ) ); // Q0 } IF( apa_exec_fx( hIvasDec->hTimeScaler, tmp_apaExecBuffer, (UWord16) imult3216( hIvasDec->nSamplesFrame, nTransportChannels ), (UWord16) hIvasDec->tsm_max_scaling, tmp_apaExecBuffer, &nTimeScalerOutSamples ) != 0 ) { return IVAS_ERR_UNKNOWN; } - for ( int i = 0; i < APA_BUF_PER_CHANNEL * nTransportChannels; ++i ) + FOR( Word16 i = 0; i < APA_BUF_PER_CHANNEL * nTransportChannels; ++i ) { - hIvasDec->apaExecBuffer_fx[i] = L_shl( tmp_apaExecBuffer[i], Q11 ); + hIvasDec->apaExecBuffer_fx[i] = L_shl( tmp_apaExecBuffer[i], Q11 ); // Q11 } } ELSE { - for ( int i = 0; i < APA_BUF_PER_CHANNEL * nTransportChannels; ++i ) + FOR( Word16 i = 0; i < APA_BUF_PER_CHANNEL * nTransportChannels; ++i ) { - tmp_apaExecBuffer[i] = extract_l( L_shr( hIvasDec->apaExecBuffer_fx[i], Q12 ) ); + tmp_apaExecBuffer[i] = extract_l( L_shr( hIvasDec->apaExecBuffer_fx[i], Q12 ) ); // Q(-1) } IF( apa_exec_ivas_fx( hIvasDec->hTimeScaler, tmp_apaExecBuffer, (UWord16) imult3216( hIvasDec->nSamplesFrame, nTransportChannels ), (UWord16) hIvasDec->tsm_max_scaling, tmp_apaExecBuffer, &nTimeScalerOutSamples ) != 0 ) { return IVAS_ERR_UNKNOWN; } - for ( int i = 0; i < APA_BUF_PER_CHANNEL * nTransportChannels; ++i ) + FOR( Word16 i = 0; i < APA_BUF_PER_CHANNEL * nTransportChannels; ++i ) { - hIvasDec->apaExecBuffer_fx[i] = L_shl( tmp_apaExecBuffer[i], Q12 ); + hIvasDec->apaExecBuffer_fx[i] = L_shl( tmp_apaExecBuffer[i], Q12 ); // Q11 } } assert( LE_32( (Word32) nTimeScalerOutSamples, APA_BUF ) ); @@ -1189,7 +1189,7 @@ static ivas_error IVAS_DEC_Setup( UWord8 *nTransportChannels, /* o : number of decoded transport PCM channels */ UWord8 *nOutChannels, /* o : number of decoded out channels (PCM or CLDFB) */ UWord16 *nSamplesRendered, /* o : number of samples flushed from the last frame */ - Word16 *data /* o : output synthesis signal */ + Word16 *data /* o : output synthesis signal Q0 */ ) { ivas_error error; @@ -1258,7 +1258,7 @@ static ivas_error IVAS_DEC_Setup( test(); test(); test(); - IF( is_DTXrate( ivas_total_brate ) == 0 && st_ivas->ivas_format == MASA_ISM_FORMAT && GT_16( st_ivas->ini_frame, 0 ) && ( GT_32( ivas_total_brate, IVAS_SID_5k2 ) && NE_32( ivas_total_brate, st_ivas->hDecoderConfig->last_ivas_total_brate ) ) && st_ivas->ini_active_frame == 0 ) + IF( is_DTXrate( ivas_total_brate ) == 0 && EQ_16( (Word16) st_ivas->ivas_format, MASA_ISM_FORMAT ) && GT_16( st_ivas->ini_frame, 0 ) && ( GT_32( ivas_total_brate, IVAS_SID_5k2 ) && NE_32( ivas_total_brate, st_ivas->hDecoderConfig->last_ivas_total_brate ) ) && st_ivas->ini_active_frame == 0 ) { IF( st_ivas->hSpar ) { @@ -1317,7 +1317,7 @@ static ivas_error IVAS_DEC_Setup( test(); test(); test(); - IF( is_DTXrate( ivas_total_brate ) == 0 && st_ivas->ivas_format == MASA_ISM_FORMAT && st_ivas->ini_frame > 0 && ( GT_32( ivas_total_brate, IVAS_SID_5k2 ) && NE_32( ivas_total_brate, st_ivas->hDecoderConfig->last_ivas_total_brate ) ) && st_ivas->ini_active_frame == 0 ) + IF( is_DTXrate( ivas_total_brate ) == 0 && EQ_16( (Word16) st_ivas->ivas_format, MASA_ISM_FORMAT ) && st_ivas->ini_frame > 0 && ( GT_32( ivas_total_brate, IVAS_SID_5k2 ) && NE_32( ivas_total_brate, st_ivas->hDecoderConfig->last_ivas_total_brate ) ) && st_ivas->ini_active_frame == 0 ) { IF( EQ_16( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) ) { @@ -1363,7 +1363,7 @@ static ivas_error IVAS_DEC_Setup( static ivas_error IVAS_DEC_GetTcSamples( IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ - Word32 *pcmBuf_fx, /* i/o: buffer for decoded PCM output. The memory must already be allocated and be able to hold the expected number of output samples, based on frame size and number of output channels */ + Word32 *pcmBuf_fx, /* i/o: buffer for decoded PCM output. The memory must already be allocated and be able to hold the expected number of output samples, based on frame size and number of output channels Q11 */ Word16 *nOutSamples /* o : number of samples per channel written to output buffer */ ) { @@ -1403,7 +1403,7 @@ static ivas_error IVAS_DEC_GetTcSamples( FOR( n = 0; n < ivas_get_nchan_buffers_dec_ivas_fx( st_ivas, st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate ); n++ ) { set32_fx( st_ivas->p_output_fx[n], 0, L_FRAME48k ); - st_ivas->hTcBuffer->tc_fx[n] = st_ivas->p_output_fx[n]; + st_ivas->hTcBuffer->tc_fx[n] = st_ivas->p_output_fx[n]; // Q11 } } @@ -1463,13 +1463,13 @@ static ivas_error IVAS_DEC_GetTcSamples( /*note : cldfb_size here signifies the original size which was assigned to cldfb_state_fx buffer not its current size*/ IF( sts[n]->cldfbAna != NULL ) { - scale_sig32( sts[n]->cldfbAna->cldfb_state_fx, sts[n]->cldfbAna->cldfb_size, sub( Q11, Q10 ) ); + scale_sig32( sts[n]->cldfbAna->cldfb_state_fx, sts[n]->cldfbAna->cldfb_size, sub( Q11, Q10 ) ); // Q11 sts[n]->cldfbAna->Q_cldfb_state = Q11; move16(); } IF( sts[n]->cldfbSyn != NULL ) { - scale_sig32( sts[n]->cldfbSyn->cldfb_state_fx, sts[n]->cldfbSyn->cldfb_size, sub( Q11, Q4 ) ); + scale_sig32( sts[n]->cldfbSyn->cldfb_state_fx, sts[n]->cldfbSyn->cldfb_size, sub( Q11, Q4 ) ); // Q11 sts[n]->cldfbSyn->Q_cldfb_state = Q11; move16(); } @@ -1498,7 +1498,7 @@ static ivas_error IVAS_DEC_RendererFeedTcSamples( IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ const Word16 nSamplesForRendering, /* i : number of TC samples wanted from the renderer */ Word16 *nSamplesResidual, /* o : number of samples not fitting into the renderer grid and buffer for the next call */ - Word32 *pcmBuf /* i/o: buffer for decoded PCM output. The memory must already be allocated and be able to hold the expected number of output samples, based on frame size and number of output channels */ + Word32 *pcmBuf /* i/o: buffer for decoded PCM output. The memory must already be allocated and be able to hold the expected number of output samples, based on frame size and number of output channels Q11*/ ) { Decoder_Struct *st_ivas; @@ -1529,7 +1529,8 @@ static ivas_error IVAS_DEC_GetRenderedSamples( const UWord16 nSamplesForRendering, /* i : number of TC samples wanted from the renderer */ UWord16 *nSamplesRendered, /* o : number of samples rendered */ UWord16 *nSamplesAvailableNext, /* o : number of samples still available in the renerer pipeline */ - Word16 *pcmBuf ) + Word16 *pcmBuf // Q0 +) { Decoder_Struct *st_ivas; ivas_error error; @@ -1768,23 +1769,23 @@ ivas_error IVAS_DEC_GetObjectMetadata( IF( hIsmMeta == NULL || zero_flag ) { - metadata->azimuth_fx = 0; - metadata->elevation_fx = 0; - metadata->radius_fx = 512; - metadata->yaw_fx = 0; - metadata->pitch_fx = 0; - metadata->spread_fx = 0; - metadata->gainFactor_fx = ONE_IN_Q31; + metadata->azimuth_fx = 0; // Q22 + metadata->elevation_fx = 0; // Q22 + metadata->radius_fx = 512; // Q9 + metadata->yaw_fx = 0; // Q22 + metadata->pitch_fx = 0; // Q22 + metadata->spread_fx = 0; // Q22 + metadata->gainFactor_fx = ONE_IN_Q31; // Q31 metadata->non_diegetic_flag = 0; } ELSE { - metadata->azimuth_fx = hIsmMeta->azimuth_fx; - metadata->elevation_fx = hIsmMeta->elevation_fx; - metadata->radius_fx = hIsmMeta->radius_fx; - metadata->yaw_fx = hIsmMeta->yaw_fx; - metadata->pitch_fx = hIsmMeta->pitch_fx; - metadata->spread_fx = 0; + metadata->azimuth_fx = hIsmMeta->azimuth_fx; // Q22 + metadata->elevation_fx = hIsmMeta->elevation_fx; // Q22 + metadata->radius_fx = hIsmMeta->radius_fx; // Q9 + metadata->yaw_fx = hIsmMeta->yaw_fx; // Q22 + metadata->pitch_fx = hIsmMeta->pitch_fx; // Q22 + metadata->spread_fx = 0; // Q22 metadata->gainFactor_fx = ONE_IN_Q31; metadata->non_diegetic_flag = hIsmMeta->non_diegetic_flag; } @@ -1940,18 +1941,18 @@ ivas_error IVAS_DEC_FeedHeadTrackData( Word32 updateRate_fx = 1677721600; // value is 200 in Q23 move32(); - orientation.w_fx = L_shl( orientation.w_fx, sub( Q29, orientation.q_fact ) ); - orientation.x_fx = L_shl( orientation.x_fx, sub( Q29, orientation.q_fact ) ); - orientation.y_fx = L_shl( orientation.y_fx, sub( Q29, orientation.q_fact ) ); - orientation.z_fx = L_shl( orientation.z_fx, sub( Q29, orientation.q_fact ) ); - hHeadTrackData->OrientationTracker->refRot.w_fx = L_shl( hHeadTrackData->OrientationTracker->refRot.w_fx, sub( Q29, hHeadTrackData->OrientationTracker->refRot.q_fact ) ); - hHeadTrackData->OrientationTracker->refRot.x_fx = L_shl( hHeadTrackData->OrientationTracker->refRot.x_fx, sub( Q29, hHeadTrackData->OrientationTracker->refRot.q_fact ) ); - hHeadTrackData->OrientationTracker->refRot.y_fx = L_shl( hHeadTrackData->OrientationTracker->refRot.y_fx, sub( Q29, hHeadTrackData->OrientationTracker->refRot.q_fact ) ); - hHeadTrackData->OrientationTracker->refRot.z_fx = L_shl( hHeadTrackData->OrientationTracker->refRot.z_fx, sub( Q29, hHeadTrackData->OrientationTracker->refRot.q_fact ) ); - hHeadTrackData->OrientationTracker->absAvgRot.w_fx = L_shl( hHeadTrackData->OrientationTracker->absAvgRot.w_fx, sub( Q29, hHeadTrackData->OrientationTracker->absAvgRot.q_fact ) ); - hHeadTrackData->OrientationTracker->absAvgRot.x_fx = L_shl( hHeadTrackData->OrientationTracker->absAvgRot.x_fx, sub( Q29, hHeadTrackData->OrientationTracker->absAvgRot.q_fact ) ); - hHeadTrackData->OrientationTracker->absAvgRot.y_fx = L_shl( hHeadTrackData->OrientationTracker->absAvgRot.y_fx, sub( Q29, hHeadTrackData->OrientationTracker->absAvgRot.q_fact ) ); - hHeadTrackData->OrientationTracker->absAvgRot.z_fx = L_shl( hHeadTrackData->OrientationTracker->absAvgRot.z_fx, sub( Q29, hHeadTrackData->OrientationTracker->absAvgRot.q_fact ) ); + orientation.w_fx = L_shl( orientation.w_fx, sub( Q29, orientation.q_fact ) ); // Q29 + orientation.x_fx = L_shl( orientation.x_fx, sub( Q29, orientation.q_fact ) ); // Q29 + orientation.y_fx = L_shl( orientation.y_fx, sub( Q29, orientation.q_fact ) ); // Q29 + orientation.z_fx = L_shl( orientation.z_fx, sub( Q29, orientation.q_fact ) ); // Q29 + hHeadTrackData->OrientationTracker->refRot.w_fx = L_shl( hHeadTrackData->OrientationTracker->refRot.w_fx, sub( Q29, hHeadTrackData->OrientationTracker->refRot.q_fact ) ); // Q29 + hHeadTrackData->OrientationTracker->refRot.x_fx = L_shl( hHeadTrackData->OrientationTracker->refRot.x_fx, sub( Q29, hHeadTrackData->OrientationTracker->refRot.q_fact ) ); // Q29 + hHeadTrackData->OrientationTracker->refRot.y_fx = L_shl( hHeadTrackData->OrientationTracker->refRot.y_fx, sub( Q29, hHeadTrackData->OrientationTracker->refRot.q_fact ) ); // Q29 + hHeadTrackData->OrientationTracker->refRot.z_fx = L_shl( hHeadTrackData->OrientationTracker->refRot.z_fx, sub( Q29, hHeadTrackData->OrientationTracker->refRot.q_fact ) ); // Q29 + hHeadTrackData->OrientationTracker->absAvgRot.w_fx = L_shl( hHeadTrackData->OrientationTracker->absAvgRot.w_fx, sub( Q29, hHeadTrackData->OrientationTracker->absAvgRot.q_fact ) ); // Q29 + hHeadTrackData->OrientationTracker->absAvgRot.x_fx = L_shl( hHeadTrackData->OrientationTracker->absAvgRot.x_fx, sub( Q29, hHeadTrackData->OrientationTracker->absAvgRot.q_fact ) ); // Q29 + hHeadTrackData->OrientationTracker->absAvgRot.y_fx = L_shl( hHeadTrackData->OrientationTracker->absAvgRot.y_fx, sub( Q29, hHeadTrackData->OrientationTracker->absAvgRot.q_fact ) ); // Q29 + hHeadTrackData->OrientationTracker->absAvgRot.z_fx = L_shl( hHeadTrackData->OrientationTracker->absAvgRot.z_fx, sub( Q29, hHeadTrackData->OrientationTracker->absAvgRot.q_fact ) ); // Q29 orientation.q_fact = Q29; hHeadTrackData->OrientationTracker->refRot.q_fact = Q29; @@ -2004,10 +2005,10 @@ ivas_error IVAS_DEC_FeedRefRotData( pOtr = hIvasDec->st_ivas->hHeadTrackData->OrientationTracker; - pOtr->refRot.w_fx = rotation.w_fx; - pOtr->refRot.x_fx = rotation.x_fx; - pOtr->refRot.z_fx = rotation.z_fx; - pOtr->refRot.y_fx = rotation.y_fx; + pOtr->refRot.w_fx = rotation.w_fx; // rotation.q_fact + pOtr->refRot.x_fx = rotation.x_fx; // rotation.q_fact + pOtr->refRot.z_fx = rotation.z_fx; // rotation.q_fact + pOtr->refRot.y_fx = rotation.y_fx; // rotation.q_fact pOtr->refRot.q_fact = rotation.q_fact; move32(); @@ -2140,15 +2141,16 @@ ivas_error IVAS_DEC_FeedCustomLsData( hLsSetupCustom->num_spk = hLsCustomData.num_spk; move16(); - Copy32( hLsCustomData.azimuth_fx, hLsSetupCustom->ls_azimuth_fx, hLsCustomData.num_spk ); - Copy32( hLsCustomData.elevation_fx, hLsSetupCustom->ls_elevation_fx, hLsCustomData.num_spk ); + Copy32( hLsCustomData.azimuth_fx, hLsSetupCustom->ls_azimuth_fx, hLsCustomData.num_spk ); // Q22 + Copy32( hLsCustomData.elevation_fx, hLsSetupCustom->ls_elevation_fx, hLsCustomData.num_spk ); // Q22 /* Set planar flag */ is_planar = 1; move16(); FOR( i = 0; i < hLsCustomData.num_spk; i++ ) { - IF( is_planar && hLsSetupCustom->ls_elevation_fx[i] != 0 ) + test(); + if ( is_planar && hLsSetupCustom->ls_elevation_fx[i] != 0 ) { is_planar = 0; move16(); @@ -2282,9 +2284,9 @@ static ivas_error copyRendererConfigStruct( hRCout->roomAcoustics.acousticPreDelay_fx = hRCin->roomAcoustics.acousticPreDelay_fx; hRCout->roomAcoustics.inputPreDelay_fx = hRCin->roomAcoustics.inputPreDelay_fx; - Copy32( hRCin->roomAcoustics.pFc_input_fx, hRCout->roomAcoustics.pFc_input_fx, CLDFB_NO_CHANNELS_MAX ); - Copy32( hRCin->roomAcoustics.pAcoustic_rt60_fx, hRCout->roomAcoustics.pAcoustic_rt60_fx, CLDFB_NO_CHANNELS_MAX ); - Copy32( hRCin->roomAcoustics.pAcoustic_dsr_fx, hRCout->roomAcoustics.pAcoustic_dsr_fx, CLDFB_NO_CHANNELS_MAX ); + Copy32( hRCin->roomAcoustics.pFc_input_fx, hRCout->roomAcoustics.pFc_input_fx, CLDFB_NO_CHANNELS_MAX ); // Q16 + Copy32( hRCin->roomAcoustics.pAcoustic_rt60_fx, hRCout->roomAcoustics.pAcoustic_rt60_fx, CLDFB_NO_CHANNELS_MAX ); // Q26 + Copy32( hRCin->roomAcoustics.pAcoustic_dsr_fx, hRCout->roomAcoustics.pAcoustic_dsr_fx, CLDFB_NO_CHANNELS_MAX ); // Q30 Copy( hRCin->directivity_fx, hRCout->directivity_fx, 3 * MAX_NUM_OBJECTS ); hRCout->roomAcoustics.use_er = hRCin->roomAcoustics.use_er; hRCout->roomAcoustics.lowComplexity = hRCin->roomAcoustics.lowComplexity; @@ -2382,9 +2384,9 @@ ivas_error IVAS_DEC_FeedRenderConfig( move32(); } - Copy32( renderConfig.roomAcoustics.pFc_input_fx, hRenderConfig->roomAcoustics.pFc_input_fx, CLDFB_NO_CHANNELS_MAX ); - Copy32( renderConfig.roomAcoustics.pAcoustic_rt60_fx, hRenderConfig->roomAcoustics.pAcoustic_rt60_fx, CLDFB_NO_CHANNELS_MAX ); - Copy32( renderConfig.roomAcoustics.pAcoustic_dsr_fx, hRenderConfig->roomAcoustics.pAcoustic_dsr_fx, CLDFB_NO_CHANNELS_MAX ); + Copy32( renderConfig.roomAcoustics.pFc_input_fx, hRenderConfig->roomAcoustics.pFc_input_fx, CLDFB_NO_CHANNELS_MAX ); // Q16 + Copy32( renderConfig.roomAcoustics.pAcoustic_rt60_fx, hRenderConfig->roomAcoustics.pAcoustic_rt60_fx, CLDFB_NO_CHANNELS_MAX ); // Q26 + Copy32( renderConfig.roomAcoustics.pAcoustic_dsr_fx, hRenderConfig->roomAcoustics.pAcoustic_dsr_fx, CLDFB_NO_CHANNELS_MAX ); // Q30 Copy( renderConfig.directivity_fx, hRenderConfig->directivity_fx, 3 * MAX_NUM_OBJECTS ); @@ -2444,7 +2446,7 @@ ivas_error IVAS_DEC_GetDelay( nSamples[1] = NS2SA_FX2( hDecoderConfig->output_Fs, get_delay_fx( DEC, hDecoderConfig->output_Fs, st_ivas->ivas_format, st_ivas->cldfbAnaDec[0] ) ); move16(); - nSamples[2] = (Word16) W_round64_L( W_mult0_32_32( L_shl( st_ivas->binaural_latency_ns, 1 ), out_fs_fx ) ); + nSamples[2] = extract_l( W_round64_L( W_mult0_32_32( L_shl( st_ivas->binaural_latency_ns, 1 ), out_fs_fx ) ) ); move16(); nSamples[0] = add( nSamples[1], nSamples[2] ); move16(); @@ -2496,7 +2498,7 @@ ivas_error IVAS_DEC_HasDecodedFirstGoodFrame( ivas_error IVAS_DEC_GetPcmFrameSize( IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ - Word32 *pcmFrameSize /* o : total size of the PCM output frame. This takes into account the number of output channels */ + Word32 *pcmFrameSize /* o : total size of the PCM output frame. This takes into account the number of output channels Q0 */ ) { test(); @@ -2572,7 +2574,7 @@ static void bsCompactToSerial( const UWord8 *compact, UWord16 *serial, UWord16 n /* Add 4 padding bytes required by core coder */ FOR( i = 0; i < 4 * 8; ++i ) { - serial[L_add( num_bits, (Word32) i )] = 0; + serial[( num_bits + i )] = 0; move16(); } #undef WMC_TOOL_SKIP @@ -2696,7 +2698,7 @@ ivas_error IVAS_DEC_VoIP_SetScale( error = IVAS_ERR_OK; move32(); - IF( EQ_16( hIvasDec->st_ivas->hDecoderConfig->Opt_tsm, false ) ) + IF( hIvasDec->st_ivas->hDecoderConfig->Opt_tsm == false ) { return IVAS_ERR_TSM_NOT_ENABLED; } @@ -2719,7 +2721,7 @@ ivas_error IVAS_DEC_VoIP_SetScale( ivas_error IVAS_DEC_TSM_SetQuality( IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ - const Word16 quality /* i : target TSM quality */ + const Word16 quality /* i : target TSM quality Q14 */ ) { ivas_error error; @@ -2727,13 +2729,14 @@ ivas_error IVAS_DEC_TSM_SetQuality( error = IVAS_ERR_OK; move32(); - IF( EQ_16( hIvasDec->st_ivas->hDecoderConfig->Opt_tsm, false ) ) + IF( hIvasDec->st_ivas->hDecoderConfig->Opt_tsm == false ) { return IVAS_ERR_TSM_NOT_ENABLED; } ELSE { - hIvasDec->tsm_quality = quality; + hIvasDec->tsm_quality = quality; // Q14 + move16(); } return error; @@ -2749,7 +2752,7 @@ ivas_error IVAS_DEC_TSM_SetQuality( ivas_error IVAS_DEC_VoIP_GetSamples( IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ UWord16 nSamplesPerChannel, /* i : number of samples per channel requested to be written to output buffer */ - Word16 *pcmBuf, /* i/o: buffer for decoded PCM output. The memory must already be allocated and be able to hold the expected number of output samples, based on frame size and number of output channels */ + Word16 *pcmBuf, /* i/o: buffer for decoded PCM output. The memory must already be allocated and be able to hold the expected number of output samples, based on frame size and number of output channels Q0 */ const UWord32 systemTimestamp_ms /* i : current system timestamp */ #ifdef SUPPORT_JBM_TRACEFILE , @@ -2804,7 +2807,7 @@ ivas_error IVAS_DEC_VoIP_GetSamples( extBufferedSamples = add( nSamplesRendered, nSamplesBuffered ); Word16 exp; extBufferedTime_ms = BASOP_Util_Divide3232_Scale( imult3216( extBufferedSamples, 1000 ), hDecoderConfig->output_Fs, &exp ); - extBufferedTime_ms = (UWord32) W_shr( extBufferedTime_ms, 15 - exp ); + extBufferedTime_ms = (UWord32) W_shr( extBufferedTime_ms, sub( 15, exp ) ); // Q0 dataUnit = NULL; /* pop one access unit from the jitter buffer */ @@ -2959,7 +2962,7 @@ ivas_error IVAS_DEC_VoIP_GetSamples( ivas_error IVAS_DEC_Flush( IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ const Word16 nSamplesPerChannel, /* i : number of samples per channel requested to be written to output buffer */ - Word16 *pcmBuf, /* i/o: buffer for decoded PCM output. The memory must already be allocated and be able to hold the expected number of output samples, based on frame size and number of output channels */ + Word16 *pcmBuf, /* i/o: buffer for decoded PCM output. The memory must already be allocated and be able to hold the expected number of output samples, based on frame size and number of output channels Q0 */ Word16 *nSamplesFlushed /* o : number of samples flushed */ ) { @@ -3462,8 +3465,9 @@ void IVAS_DEC_PrintDisclaimer( void ) static ivas_error evs_dec_main_fx( Decoder_Struct *st_ivas, const Word16 nOutSamples, - Word32 *Buf_fx, - Word16 *pcmBuf ) + Word32 *Buf_fx, // Q11 + Word16 *pcmBuf // Q0 +) { DEC_CORE_HANDLE *hCoreCoder; Word16 mixer_left_fx, mixer_right_fx; @@ -3477,13 +3481,13 @@ static ivas_error evs_dec_main_fx( hCoreCoder[0]->total_num_bits = st_ivas->num_bits; move16(); move32(); - hCoreCoder[0]->output_frame_fx = extract_l( Mult_32_16( hCoreCoder[0]->output_Fs, 0x0290 ) ); + hCoreCoder[0]->output_frame_fx = extract_l( Mult_32_16( hCoreCoder[0]->output_Fs, 0x0290 /*Q0*/ ) ); // Q0 move16(); mdct_switching_dec( hCoreCoder[0] ); FOR( ch = 0; ch < MAX_OUTPUT_CHANNELS_IN_DIEGETIC_PAN; ch++ ) { - p_output_fx[ch] = st_ivas->p_output_fx[ch]; + p_output_fx[ch] = st_ivas->p_output_fx[ch]; // Q0 } /* run the main EVS decoding routine */ @@ -3538,7 +3542,7 @@ static ivas_error evs_dec_main_fx( move16(); IF( EQ_16( st_ivas->renderer_type, RENDERER_NON_DIEGETIC_DOWNMIX ) ) { - mixer_left_fx = add( shr( st_ivas->hDecoderConfig->non_diegetic_pan_gain_fx, Q1 ), ONE_IN_Q14 ); + mixer_left_fx = add( shr( st_ivas->hDecoderConfig->non_diegetic_pan_gain_fx, Q1 ), ONE_IN_Q14 ); // Q14 mixer_right_fx = sub( MAX16B, mixer_left_fx ); v_multc_fixed_16( p_output_fx[0], mixer_right_fx, p_output_fx[1], nOutSamples ); /* Q11 */ diff --git a/lib_dec/lp_exc_d_fx.c b/lib_dec/lp_exc_d_fx.c index e0bcb2c60..cb94c47f7 100644 --- a/lib_dec/lp_exc_d_fx.c +++ b/lib_dec/lp_exc_d_fx.c @@ -57,7 +57,7 @@ void lp_filt_exc_dec_fx( lp_flag = (Word16) get_next_indice_fx( st_fx, 1 ); } } - IF( EQ_16( lp_flag, LOW_PASS ) ) + IF( lp_flag == LOW_PASS ) { /* pointer positioning to avoid doing it inside the loop */ test(); @@ -76,9 +76,9 @@ void lp_filt_exc_dec_fx( FOR( i = 0; i < L_subfr; i++ ) { - L_tmp = L_mult( fac_n, exc[add( sub( i, 1 ), i_subfr )] ); - L_tmp = L_mac( L_tmp, fac_m, exc[add( i /*+ 0 */, i_subfr )] ); - code[i] = mac_r( L_tmp, fac_n, exc[add( add( i, 1 ), i_subfr )] ); + L_tmp = L_mult( fac_n, exc[( ( i - 1 ) + i_subfr )] ); + L_tmp = L_mac( L_tmp, fac_m, exc[( i /*+ 0 */ + i_subfr )] ); + code[i] = mac_r( L_tmp, fac_n, exc[( ( i + 1 ) + i_subfr )] ); move16(); } diff --git a/lib_rend/ivas_efap.c b/lib_rend/ivas_efap.c index ddaf6a41a..e9f7d3d33 100644 --- a/lib_rend/ivas_efap.c +++ b/lib_rend/ivas_efap.c @@ -384,7 +384,7 @@ void efap_determine_gains_fx( set32_fx( hEFAPdata->bufferLong_fx, 0, hEFAPdata->vtxData.numVtx ); /* Wrap angles to correct range */ - panning_wrap_angles_fixed( azi_deg, ele_deg, &azi_wrap_int, &ele_wrap_int ); + panning_wrap_angles_fx( azi_deg, ele_deg, &azi_wrap_int, &ele_wrap_int ); /* Panning */ efap_panning_fx( azi_wrap_int, ele_wrap_int, &hEFAPdata->polyData, hEFAPdata->bufferLong_fx ); diff --git a/lib_rend/ivas_prot_rend.h b/lib_rend/ivas_prot_rend.h index 033086191..8a9e8185d 100644 --- a/lib_rend/ivas_prot_rend.h +++ b/lib_rend/ivas_prot_rend.h @@ -254,19 +254,21 @@ void efap_determine_gains( #ifdef IVAS_FLOAT_FIXED ivas_error vbap_init_data_fx( - VBAP_HANDLE *hVBAPdata, /* i/o: handle for VBAP data structure that will be initialized */ - const Word32 *speaker_node_azi_deg, /* i : vector of speaker node azimuths (positive left) */ - const Word32 *speaker_node_ele_deg, /* i : vector of speaker node elevations (positive up) */ - const Word16 num_speaker_nodes, /* i : number of speaker nodes in the set */ - const IVAS_FORMAT ivas_format /* i : IVAS format */ + VBAP_HANDLE *hVBAPdata, /* i/o: handle for VBAP data structure that will be initialized */ + const Word32 *speaker_node_azi_deg_fx, /* i : vector of speaker node azimuths (positive left) Q22 */ + const Word32 *speaker_node_ele_deg_fx, /* i : vector of speaker node elevations (positive up) Q22 */ + const Word16 num_speaker_nodes, /* i : number of speaker nodes in the set */ + const IVAS_FORMAT ivas_format /* i : IVAS format */ ); + void vbap_determine_gains_fx( - const VBAP_HANDLE hVBAPdata, /* i : prepared VBAP structure */ - Word32 *gains_fx, /* o : gain vector for loudspeakers for given direction */ - const Word16 azi_deg, /* i : azimuth in degrees for panning direction (positive left) */ - const Word16 ele_deg, /* i : elevation in degrees for panning direction (positive up) */ - const Word16 use_object_mode /* i : select between object mode panning and spatial mode panning */ + const VBAP_HANDLE hVBAPdata, /* i : prepared VBAP structure */ + Word32 *gains_fx, /* o : gain vector for loudspeakers for given direction Q29 */ + const Word16 azi_deg, /* i : azimuth in degrees for panning direction (positive left) Q0 */ + const Word16 ele_deg, /* i : elevation in degrees for panning direction (positive up) Q0 */ + const Word16 use_object_mode /* i : select between object mode panning and spatial mode panning */ ); + void vbap_free_data_fx( VBAP_HANDLE *hVBAPdata /* i/o: VBAP handle to be freed */ ); diff --git a/lib_rend/ivas_stat_rend.h b/lib_rend/ivas_stat_rend.h index 03b8fd46e..49808bdd1 100644 --- a/lib_rend/ivas_stat_rend.h +++ b/lib_rend/ivas_stat_rend.h @@ -780,12 +780,12 @@ typedef struct vbap_data_structure Word16 bottom_virtual_speaker_node_index; Word16 back_virtual_speaker_node_index; #ifdef IVAS_FLOAT_FIXED - Word16 *bottom_virtual_speaker_node_division_gains_fx; - Word16 *top_virtual_speaker_node_division_gains_fx; - Word16 *back_virtual_speaker_node_division_gains_fx; - Word16 *object_mode_bottom_virtual_speaker_node_division_gains_fx; - Word16 *object_mode_top_virtual_speaker_node_division_gains_fx; - Word16 *object_mode_back_virtual_speaker_node_division_gains_fx; + Word16 *bottom_virtual_speaker_node_division_gains_fx; /* Q16 */ + Word16 *top_virtual_speaker_node_division_gains_fx; /* Q16 */ + Word16 *back_virtual_speaker_node_division_gains_fx; /* Q16 */ + Word16 *object_mode_bottom_virtual_speaker_node_division_gains_fx; /* Q16 */ + Word16 *object_mode_top_virtual_speaker_node_division_gains_fx; /* Q16 */ + Word16 *object_mode_back_virtual_speaker_node_division_gains_fx; /* Q16 */ #else float *bottom_virtual_speaker_node_division_gains; float *top_virtual_speaker_node_division_gains; @@ -2350,8 +2350,8 @@ typedef struct ivas_LS_setup_custom { Word16 is_planar_setup; /* flag to indicate if setup is planar or not */ Word16 num_spk; /* number of custom loudspeakers */ - Word32 ls_azimuth_fx[MAX_OUTPUT_CHANNELS]; /* custom loudspeaker azimuths */ - Word32 ls_elevation_fx[MAX_OUTPUT_CHANNELS]; /* custom loudspeaker elevations */ + Word32 ls_azimuth_fx[MAX_OUTPUT_CHANNELS]; /* custom loudspeaker azimuths Q22 */ + Word32 ls_elevation_fx[MAX_OUTPUT_CHANNELS]; /* custom loudspeaker elevations Q22 */ Word16 num_lfe; /* number of LFE channels */ Word16 lfe_idx[MAX_OUTPUT_CHANNELS]; /* index for LFE channel insertion */ Word16 separate_ch_found; /* flag to indicate if a center channel was found */ diff --git a/lib_rend/ivas_vbap.c b/lib_rend/ivas_vbap.c index 3d62f5952..9f4612947 100644 --- a/lib_rend/ivas_vbap.c +++ b/lib_rend/ivas_vbap.c @@ -94,8 +94,8 @@ typedef struct connection_option Word16 chA; Word16 chB; #ifdef IVAS_FLOAT_FIXED - Word32 arc_weighted_fx; - Word32 arc_fx; + Word32 arc_weighted_fx; /* Q29 */ + Word32 arc_fx; /* Q29 */ #else float arc; float arc_weighted; @@ -115,9 +115,9 @@ enum SpeakerNodeGroup typedef struct vbap_speaker_node_structure { #ifdef IVAS_FLOAT_FIXED - Word32 azi_deg_fx; - Word32 ele_deg_fx; - Word32 unit_vec_fx[3]; + Word32 azi_deg_fx; /* Q22 */ + Word32 ele_deg_fx; /* Q22 */ + Word32 unit_vec_fx[3]; /* Q30 */ #else float azi_deg; float ele_deg; @@ -137,13 +137,13 @@ static UWord8 vector_matrix_multiply_3x3_fx( const Word16 *src_vector, Word32 ma static UWord8 vector_matrix_multiply_3x3_32_fx( const Word32 *src_vector, Word32 matrix[3][3], Word32 *result, Word16 q_matrix ); -static void init_speaker_node_direction_data_fx( VBAP_SPEAKER_NODE *speaker_node_data, const Word32 *speaker_node_azi_deg_fx, const Word32 *speaker_node_ele_deg_fx, const int16_t num_speaker_nodes ); +static void init_speaker_node_direction_data_fx( VBAP_SPEAKER_NODE *speaker_node_data, const Word32 *speaker_node_azi_deg_fx, const Word32 *speaker_node_ele_deg_fx, const Word16 num_speaker_nodes ); static Word16 determine_virtual_surface_triplets_fx( const Word16 num_speaker_nodes, const VBAP_SPEAKER_NODE *speaker_node_data, Word16 connections[][2], const Word16 max_num_connections, VBAP_VS_TRIPLET *triplets, Word16 initial_search_indices[VBAP_NUM_SEARCH_SECTORS], enum SpeakerNodeGroup allowed_group ); -static void determine_initial_search_indices_fx( const int16_t num_triplets, const Word32 triplet_azidegs_fx[VBAP_MAX_NUM_TRIPLETS], int16_t initial_search_indices[VBAP_NUM_SEARCH_SECTORS] ); +static void determine_initial_search_indices_fx( const Word16 num_triplets, const Word32 triplet_azidegs_fx[VBAP_MAX_NUM_TRIPLETS], Word16 initial_search_indices[VBAP_NUM_SEARCH_SECTORS] ); -static ivas_error determine_connections_fx( const Word16 num_speaker_nodes, const VBAP_SPEAKER_NODE *speaker_node_data, Word16 connections[][2], const Word16 max_num_connections, Word16 *group1_count, Word16 *group2_start, int16_t *group2_count ); +static ivas_error determine_connections_fx( const Word16 num_speaker_nodes, const VBAP_SPEAKER_NODE *speaker_node_data, Word16 connections[][2], const Word16 max_num_connections, Word16 *group1_count, Word16 *group2_start, Word16 *group2_count ); static void formulate_horizontal_connections_fx( const VBAP_SPEAKER_NODE *speaker_node_data, const Word16 num_speaker_nodes, Word16 connections[][2], Word16 *connection_write_index ); @@ -157,7 +157,7 @@ static enum VirtualSpeakerNodeType check_need_of_virtual_speaker_node_fx( VBAP_H static Word16 determine_best_triplet_and_gains_fx( VBAP_SEARCH_STRUCT *search_struct, const Word16 panning_unit_vec_fx[3], const Word16 azi_deg, Word32 gains_fx[3] ); -static void determine_virtual_speaker_node_division_gains_fx( const Word16 virtual_speaker_node_index, Word16 *virtual_node_division_gains_fx, Word16 *max_exp, int16_t connections[][2], const enum VirtualSpeakerNodeType type, const Word16 max_num_connections, const Word16 num_speaker_nodes, const Word16 use_object_mode ); +static void determine_virtual_speaker_node_division_gains_fx( const Word16 virtual_speaker_node_index, Word16 *virtual_node_division_gains_fx, Word16 connections[][2], const enum VirtualSpeakerNodeType type, const Word16 max_num_connections, const Word16 num_speaker_nodes, const Word16 use_object_mode ); static void reorder_triplets_fx( VBAP_VS_TRIPLET *triplets, const Word16 *target_order, const Word16 num_triplets ); #else @@ -193,13 +193,14 @@ static void reorder_triplets( VBAP_VS_TRIPLET *triplets, const int16_t *target_o * * Initialize VBAP data structure for the speaker node set *-------------------------------------------------------------------------*/ + #ifdef IVAS_FLOAT_FIXED ivas_error vbap_init_data_fx( - VBAP_HANDLE *hVBAPdata, /* i/o: handle for VBAP data structure that will be initialized */ - const Word32 *speaker_node_azi_deg_fx, /* i : vector of speaker node azimuths (positive left) */ - const Word32 *speaker_node_ele_deg_fx, /* i : vector of speaker node elevations (positive up) */ - const Word16 num_speaker_nodes, /* i : number of speaker nodes in the set */ - const IVAS_FORMAT ivas_format /* i : IVAS format */ + VBAP_HANDLE *hVBAPdata, /* i/o: handle for VBAP data structure that will be initialized */ + const Word32 *speaker_node_azi_deg_fx, /* i : vector of speaker node azimuths (positive left) Q22 */ + const Word32 *speaker_node_ele_deg_fx, /* i : vector of speaker node elevations (positive up) Q22 */ + const Word16 num_speaker_nodes, /* i : number of speaker nodes in the set */ + const IVAS_FORMAT ivas_format /* i : IVAS format */ ) { /* Variables */ @@ -213,8 +214,8 @@ ivas_error vbap_init_data_fx( enum VirtualSpeakerNodeType virtual_bottom_type; enum VirtualSpeakerNodeType virtual_back_type; - Word32 speaker_node_azi_deg_internal_fx[VBAP_MAX_NUM_SPEAKER_NODES]; - Word32 speaker_node_ele_deg_internal_fx[VBAP_MAX_NUM_SPEAKER_NODES]; + Word32 speaker_node_azi_deg_internal_fx[VBAP_MAX_NUM_SPEAKER_NODES]; /* Q22 */ + Word32 speaker_node_ele_deg_internal_fx[VBAP_MAX_NUM_SPEAKER_NODES]; /* Q22 */ VBAP_SPEAKER_NODE speaker_node_data[VBAP_MAX_NUM_SPEAKER_NODES]; VBAP_DATA *vbap; @@ -299,7 +300,7 @@ ivas_error vbap_init_data_fx( is_success &= vbap->object_mode_bottom_virtual_speaker_node_division_gains_fx != NULL; } speaker_node_azi_deg_internal_fx[vbap->bottom_virtual_speaker_node_index] = 0; - speaker_node_ele_deg_internal_fx[vbap->bottom_virtual_speaker_node_index] = -377487360; /*-90.0f in Q22*/ + speaker_node_ele_deg_internal_fx[vbap->bottom_virtual_speaker_node_index] = -377487360; /* -90.0f in Q22 */ move32(); move32(); } @@ -323,7 +324,7 @@ ivas_error vbap_init_data_fx( is_success &= vbap->object_mode_top_virtual_speaker_node_division_gains_fx != NULL; } speaker_node_azi_deg_internal_fx[vbap->top_virtual_speaker_node_index] = 0; - speaker_node_ele_deg_internal_fx[vbap->top_virtual_speaker_node_index] = 377487360; /*90.0f in Q22*/ + speaker_node_ele_deg_internal_fx[vbap->top_virtual_speaker_node_index] = 377487360; /* 90.0f in Q22 */ move32(); move16(); } @@ -346,24 +347,14 @@ ivas_error vbap_init_data_fx( set16_fx( vbap->object_mode_back_virtual_speaker_node_division_gains_fx, 0, num_speaker_nodes ); is_success &= vbap->object_mode_back_virtual_speaker_node_division_gains_fx != NULL; } - speaker_node_azi_deg_internal_fx[vbap->back_virtual_speaker_node_index] = 754974720; + speaker_node_azi_deg_internal_fx[vbap->back_virtual_speaker_node_index] = 754974720; /* 180.0f in Q22 */ speaker_node_ele_deg_internal_fx[vbap->back_virtual_speaker_node_index] = 0; move32(); move16(); } + init_speaker_node_direction_data_fx( speaker_node_data, speaker_node_azi_deg_internal_fx, speaker_node_ele_deg_internal_fx, vbap->num_speaker_nodes_internal ); -#ifdef TRUE0 - /*TODO: Clean up of update float buffers*/ - for ( int ch = 0; ch < vbap->num_speaker_nodes_internal; ch++ ) - { - speaker_node_data[ch].unit_vec[0] = fix_to_float( speaker_node_data[ch].unit_vec_fx[0], Q30 ); - speaker_node_data[ch].unit_vec[1] = fix_to_float( speaker_node_data[ch].unit_vec_fx[1], Q30 ); - speaker_node_data[ch].unit_vec[2] = fix_to_float( speaker_node_data[ch].unit_vec_fx[2], Q30 ); - speaker_node_data[ch].ele_deg = fix_to_float( speaker_node_data[ch].ele_deg_fx, Q22 ); - speaker_node_data[ch].azi_deg = fix_to_float( speaker_node_data[ch].azi_deg_fx, Q22 ); - } -#endif /* Allocate and determine node-node connections */ max_num_connections = mult0( ( sub( vbap->num_speaker_nodes_internal, 2 ) ), 3 ); /* Theoretical maximum */ @@ -382,10 +373,12 @@ ivas_error vbap_init_data_fx( Word16 speaker_nodes_horiz_internal = 0; move16(); UWord8 loop_done = 0; + move16(); /* Count nodes in different groups to reserve correct memory */ FOR( ch = 0; ch < vbap->num_speaker_nodes_internal && !loop_done; ch++ ) { + test(); SWITCH( speaker_node_data[ch].group ) { case SPEAKER_NODE_ALL: @@ -411,21 +404,21 @@ ivas_error vbap_init_data_fx( } } - IF( ( vbap->search_struct[0].triplets = (VBAP_VS_TRIPLET *) malloc( ( ( speaker_nodes_group1_internal - 2 ) * 2 - ( max( 0, ( speaker_nodes_horiz_internal - 2 ) ) ) ) * sizeof( VBAP_VS_TRIPLET ) ) ) == NULL ) + IF( ( vbap->search_struct[0].triplets = (VBAP_VS_TRIPLET *) malloc( ( ( speaker_nodes_group1_internal - 2 ) * 2 - ( s_max( 0, ( speaker_nodes_horiz_internal - 2 ) ) ) ) * sizeof( VBAP_VS_TRIPLET ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for VBAP data\n" ) ); } - is_success &= vbap->search_struct[0].triplets != NULL; + is_success = s_and( is_success, vbap->search_struct[0].triplets != NULL ); IF( speaker_nodes_group2_internal > 0 ) { vbap->num_search_structs = 2; move16(); - IF( ( vbap->search_struct[1].triplets = (VBAP_VS_TRIPLET *) malloc( ( ( speaker_nodes_group2_internal - 2 ) * 2 - ( max( 0, ( speaker_nodes_horiz_internal - 2 ) ) ) ) * sizeof( VBAP_VS_TRIPLET ) ) ) == NULL ) + IF( ( vbap->search_struct[1].triplets = (VBAP_VS_TRIPLET *) malloc( ( ( speaker_nodes_group2_internal - 2 ) * 2 - ( s_max( 0, ( speaker_nodes_horiz_internal - 2 ) ) ) ) * sizeof( VBAP_VS_TRIPLET ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for VBAP data\n" ) ); } - is_success &= vbap->search_struct[1].triplets != NULL; + is_success = s_and( is_success, vbap->search_struct[1].triplets != NULL ); } ELSE { @@ -441,29 +434,29 @@ ivas_error vbap_init_data_fx( { /* If all speaker nodes belong to ALL set, then we only create one triplet set and search structure */ vbap->search_struct[0].num_triplets = determine_virtual_surface_triplets_fx( vbap->num_speaker_nodes_internal, speaker_node_data, connections, max_num_connections, vbap->search_struct[0].triplets, vbap->search_struct[0].initial_search_indices, SPEAKER_NODE_ALL ); + move16(); } ELSE { /* Otherwise, we have two sets and can handle them separately for more opmitized processing. */ vbap->search_struct[0].num_triplets = determine_virtual_surface_triplets_fx( vbap->num_speaker_nodes_internal, speaker_node_data, connections, connection_group1_count, vbap->search_struct[0].triplets, vbap->search_struct[0].initial_search_indices, SPEAKER_NODE_BOTTOM_HALF ); + move16(); vbap->search_struct[1].num_triplets = determine_virtual_surface_triplets_fx( vbap->num_speaker_nodes_internal, speaker_node_data, connections + connection_group2_start, connection_group2_count, vbap->search_struct[1].triplets, vbap->search_struct[1].initial_search_indices, SPEAKER_NODE_TOP_HALF ); + move16(); } } /* Determine how the virtual node gains should be distributed to real nodes, if necessary (checked within function). */ IF( is_success ) { - Word16 max_exp = 31; - move16(); - - determine_virtual_speaker_node_division_gains_fx( vbap->top_virtual_speaker_node_index, vbap->top_virtual_speaker_node_division_gains_fx, &max_exp, connections, virtual_top_type, max_num_connections, num_speaker_nodes, 0 ); - determine_virtual_speaker_node_division_gains_fx( vbap->bottom_virtual_speaker_node_index, vbap->bottom_virtual_speaker_node_division_gains_fx, &max_exp, connections, virtual_bottom_type, max_num_connections, num_speaker_nodes, 0 ); - determine_virtual_speaker_node_division_gains_fx( vbap->back_virtual_speaker_node_index, vbap->back_virtual_speaker_node_division_gains_fx, &max_exp, connections, virtual_back_type, max_num_connections, num_speaker_nodes, 0 ); + determine_virtual_speaker_node_division_gains_fx( vbap->top_virtual_speaker_node_index, vbap->top_virtual_speaker_node_division_gains_fx, connections, virtual_top_type, max_num_connections, num_speaker_nodes, 0 ); + determine_virtual_speaker_node_division_gains_fx( vbap->bottom_virtual_speaker_node_index, vbap->bottom_virtual_speaker_node_division_gains_fx, connections, virtual_bottom_type, max_num_connections, num_speaker_nodes, 0 ); + determine_virtual_speaker_node_division_gains_fx( vbap->back_virtual_speaker_node_index, vbap->back_virtual_speaker_node_division_gains_fx, connections, virtual_back_type, max_num_connections, num_speaker_nodes, 0 ); IF( EQ_32( ivas_format, MASA_ISM_FORMAT ) ) { - determine_virtual_speaker_node_division_gains_fx( vbap->top_virtual_speaker_node_index, vbap->object_mode_top_virtual_speaker_node_division_gains_fx, &max_exp, connections, virtual_top_type == NO_VIRTUAL_SPEAKER_NODE ? NO_VIRTUAL_SPEAKER_NODE : VIRTUAL_SPEAKER_NODE_DISTRIBUTE_ENERGY, max_num_connections, num_speaker_nodes, 1 ); - determine_virtual_speaker_node_division_gains_fx( vbap->bottom_virtual_speaker_node_index, vbap->object_mode_bottom_virtual_speaker_node_division_gains_fx, &max_exp, connections, virtual_bottom_type == NO_VIRTUAL_SPEAKER_NODE ? NO_VIRTUAL_SPEAKER_NODE : VIRTUAL_SPEAKER_NODE_DISTRIBUTE_ENERGY, max_num_connections, num_speaker_nodes, 1 ); - determine_virtual_speaker_node_division_gains_fx( vbap->back_virtual_speaker_node_index, vbap->object_mode_back_virtual_speaker_node_division_gains_fx, &max_exp, connections, virtual_back_type == NO_VIRTUAL_SPEAKER_NODE ? NO_VIRTUAL_SPEAKER_NODE : VIRTUAL_SPEAKER_NODE_DISTRIBUTE_ENERGY, max_num_connections, num_speaker_nodes, 1 ); + determine_virtual_speaker_node_division_gains_fx( vbap->top_virtual_speaker_node_index, vbap->object_mode_top_virtual_speaker_node_division_gains_fx, connections, virtual_top_type == NO_VIRTUAL_SPEAKER_NODE ? NO_VIRTUAL_SPEAKER_NODE : VIRTUAL_SPEAKER_NODE_DISTRIBUTE_ENERGY, max_num_connections, num_speaker_nodes, 1 ); + determine_virtual_speaker_node_division_gains_fx( vbap->bottom_virtual_speaker_node_index, vbap->object_mode_bottom_virtual_speaker_node_division_gains_fx, connections, virtual_bottom_type == NO_VIRTUAL_SPEAKER_NODE ? NO_VIRTUAL_SPEAKER_NODE : VIRTUAL_SPEAKER_NODE_DISTRIBUTE_ENERGY, max_num_connections, num_speaker_nodes, 1 ); + determine_virtual_speaker_node_division_gains_fx( vbap->back_virtual_speaker_node_index, vbap->object_mode_back_virtual_speaker_node_division_gains_fx, connections, virtual_back_type == NO_VIRTUAL_SPEAKER_NODE ? NO_VIRTUAL_SPEAKER_NODE : VIRTUAL_SPEAKER_NODE_DISTRIBUTE_ENERGY, max_num_connections, num_speaker_nodes, 1 ); } } @@ -730,6 +723,8 @@ ivas_error vbap_init_data( return IVAS_ERR_OK; } #endif + + /*-------------------------------------------------------------------------* * vbap_free_data() * @@ -843,33 +838,33 @@ void vbap_free_data( *-------------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED void vbap_determine_gains_fx( - const VBAP_HANDLE hVBAPdata, /* i : prepared VBAP structure */ - Word32 *gains_fx, /* o : gain vector for loudspeakers for given direction */ - const Word16 azi_deg, /* i : azimuth in degrees for panning direction (positive left) */ - const Word16 ele_deg, /* i : elevation in degrees for panning direction (positive up) */ - const Word16 use_object_mode /* i : select between object mode panning and spatial mode panning */ + const VBAP_HANDLE hVBAPdata, /* i : prepared VBAP structure */ + Word32 *gains_fx, /* o : gain vector for loudspeakers for given direction Q29 */ + const Word16 azi_deg, /* i : azimuth in degrees for panning direction (positive left) Q0 */ + const Word16 ele_deg, /* i : elevation in degrees for panning direction (positive up) Q0 */ + const Word16 use_object_mode /* i : select between object mode panning and spatial mode panning */ ) { /* This function formulates gains for the given angle. The triplet-selection has been pre-formulated. */ Word16 ch, ch2; Word16 triplet_ch; Word16 triplet_index; - Word16 panning_unit_vec_fx[3]; - Word32 gain_triplet_fx[3]; + Word16 panning_unit_vec_fx[3]; /* Q15 */ + Word32 gain_triplet_fx[3]; /* Q16 */ Word32 norm_value_fx; Word32 gain_ene_fx; - Word32 azi_norm; - Word32 ele_norm; - Word32 azi_temp_fx; - Word32 ele_temp_fx; + Word16 azi_norm; /* Q15 */ + Word16 ele_norm; /* Q15 */ + Word32 azi_temp_fx; /* Q22 */ + Word32 ele_temp_fx; /* Q22 */ Word16 num_speaker_nodes; Word16 bottom_virtual_speaker_node_index; Word16 top_virtual_speaker_node_index; Word16 back_virtual_speaker_node_index; VBAP_VS_TRIPLET *selected_triplet; - Word16 *bottom_virtual_speaker_node_division_gains_fx; - Word16 *top_virtual_speaker_node_division_gains_fx; - Word16 *back_virtual_speaker_node_division_gains_fx; + Word16 *bottom_virtual_speaker_node_division_gains_fx; /* Q16 */ + Word16 *top_virtual_speaker_node_division_gains_fx; /* Q16 */ + Word16 *back_virtual_speaker_node_division_gains_fx; /* Q16 */ push_wmops( "vbap_gains" ); @@ -895,13 +890,14 @@ void vbap_determine_gains_fx( back_virtual_speaker_node_division_gains_fx = hVBAPdata->back_virtual_speaker_node_division_gains_fx; } - panning_wrap_angles_fixed( L_shl( azi_deg, 22 ), L_shl( ele_deg, 22 ), &azi_temp_fx, &ele_temp_fx ); - azi_norm = L_shr( Mpy_32_32( azi_temp_fx, 5965232 ), 7 ); - ele_norm = L_shr( Mpy_32_32( ele_temp_fx, 5965232 ), 7 ); + panning_wrap_angles_fx( L_shl( azi_deg, Q22 ), L_shl( ele_deg, Q22 ), &azi_temp_fx, &ele_temp_fx ); + azi_norm = extract_l( L_shr( Mpy_32_32( azi_temp_fx, ONE_BY_360_Q31 ), Q7 ) ); /* Q15 */ + ele_norm = extract_l( L_shr( Mpy_32_32( ele_temp_fx, ONE_BY_360_Q31 ), Q7 ) ); /* Q15 */ - panning_unit_vec_fx[0] = mult( getCosWord16R2( (Word16) azi_norm ), getCosWord16R2( (Word16) ele_norm ) ); - panning_unit_vec_fx[1] = mult( getSineWord16R2( (Word16) azi_norm ), getCosWord16R2( (Word16) ele_norm ) ); - panning_unit_vec_fx[2] = getSineWord16R2( (Word16) ele_norm ); + panning_unit_vec_fx[0] = mult( getCosWord16R2( azi_norm ), getCosWord16R2( ele_norm ) ); /* Q15 */ + panning_unit_vec_fx[1] = mult( getSineWord16R2( azi_norm ), getCosWord16R2( ele_norm ) ); /* Q15 */ + panning_unit_vec_fx[2] = getSineWord16R2( ele_norm ); /* Q15 */ + move16(); move16(); move16(); @@ -911,13 +907,11 @@ void vbap_determine_gains_fx( IF( EQ_16( hVBAPdata->num_search_structs, 2 ) && ele_deg > 0 ) { triplet_index = determine_best_triplet_and_gains_fx( &( hVBAPdata->search_struct[1] ), panning_unit_vec_fx, azi_deg, gain_triplet_fx ); - move16(); selected_triplet = &hVBAPdata->search_struct[1].triplets[triplet_index]; } ELSE { triplet_index = determine_best_triplet_and_gains_fx( &( hVBAPdata->search_struct[0] ), panning_unit_vec_fx, azi_deg, gain_triplet_fx ); - move16(); selected_triplet = &hVBAPdata->search_struct[0].triplets[triplet_index]; } @@ -926,14 +920,14 @@ void vbap_determine_gains_fx( move32(); FOR( ch = 0; ch < 3; ch++ ) { - gain_ene_fx = L_add( gain_ene_fx, Mpy_32_32( gain_triplet_fx[ch], gain_triplet_fx[ch] ) ); // 2q -31 = 27 + gain_ene_fx = L_add( gain_ene_fx, Mpy_32_32( gain_triplet_fx[ch], gain_triplet_fx[ch] ) ); /* Q(2 * VBAP_VS_TRIPLET.q_inverse_matrix - 31) */ } - norm_value_fx = Isqrt( L_shr( gain_ene_fx, 1 ) ); // q = 47 - hVBAPdata->search_struct[0].triplets->q_inverse_matrix = 18 + norm_value_fx = Isqrt( L_shr( gain_ene_fx, 1 ) ); /* Q(31 - (2 * VBAP_VS_TRIPLET.q_inverse_matrix - 31 - 1) / 2 ) = Q(47 - VBAP_VS_TRIPLET.q_inverse_matrix) */ FOR( ch = 0; ch < 3; ch++ ) { - gain_triplet_fx[ch] = Mpy_32_32( gain_triplet_fx[ch], norm_value_fx ); // Q16 + gain_triplet_fx[ch] = Mpy_32_32( gain_triplet_fx[ch], norm_value_fx ); /* 47 - VBAP_VS_TRIPLET.q_inverse_matrix + VBAP_VS_TRIPLET.q_inverse_matrix - 31 = Q16 */ move32(); /* Sanity check for rounding issues */ @@ -956,7 +950,7 @@ void vbap_determine_gains_fx( { FOR( ch2 = 0; ch2 < num_speaker_nodes; ch2++ ) { - gains_fx[ch2] = L_add( gains_fx[ch2], L_shl( Mpy_32_16_1( gain_triplet_fx[ch], bottom_virtual_speaker_node_division_gains_fx[ch2] ), 12 ) ); // Q29 + gains_fx[ch2] = L_add( gains_fx[ch2], L_shl( Mpy_32_16_1( gain_triplet_fx[ch], bottom_virtual_speaker_node_division_gains_fx[ch2] ), Q12 ) ); /* Q16 + Q16 - Q15 + Q12 = Q29 */ move32(); } } @@ -964,7 +958,7 @@ void vbap_determine_gains_fx( { FOR( ch2 = 0; ch2 < num_speaker_nodes; ch2++ ) { - gains_fx[ch2] = L_add( gains_fx[ch2], L_shl( Mpy_32_16_1( gain_triplet_fx[ch], top_virtual_speaker_node_division_gains_fx[ch2] ), 12 ) ); // Q29 + gains_fx[ch2] = L_add( gains_fx[ch2], L_shl( Mpy_32_16_1( gain_triplet_fx[ch], top_virtual_speaker_node_division_gains_fx[ch2] ), Q12 ) ); /* Q16 + Q16 - Q15 + Q12 = Q29 */ move32(); } } @@ -972,13 +966,13 @@ void vbap_determine_gains_fx( { FOR( ch2 = 0; ch2 < num_speaker_nodes; ch2++ ) { - gains_fx[ch2] = L_add( gains_fx[ch2], L_shl( Mpy_32_16_1( gain_triplet_fx[ch], back_virtual_speaker_node_division_gains_fx[ch2] ), 12 ) ); // Q29 + gains_fx[ch2] = L_add( gains_fx[ch2], L_shl( Mpy_32_16_1( gain_triplet_fx[ch], back_virtual_speaker_node_division_gains_fx[ch2] ), Q12 ) ); /* Q16 + Q16 - Q15 + Q12 = Q29 */ move32(); } } ELSE { - gains_fx[triplet_ch] = L_add( gains_fx[triplet_ch], L_shl( gain_triplet_fx[ch], 13 ) ); // Q29 + gains_fx[triplet_ch] = L_add( gains_fx[triplet_ch], L_shl( gain_triplet_fx[ch], Q13 ) ); /* Q16 + Q13 = Q29 */ move32(); } } @@ -1126,11 +1120,12 @@ void vbap_determine_gains( * * 3-by-3 vector cross product *-------------------------------------------------------------------------*/ + #ifdef IVAS_FLOAT_FIXED static void vbap_crossp_fx( - const Word32 *vec1_fx, /* i : input vector 1 */ - const Word32 *vec2_fx, /* i : input vector 2 */ - Word32 *crossProduct_fx /* o : cross product output */ + const Word32 *vec1_fx, /* i : input vector 1 Qx */ + const Word32 *vec2_fx, /* i : input vector 2 Qy */ + Word32 *crossProduct_fx /* o : cross product output Qx + Qy - 31 */ ) { @@ -1168,43 +1163,43 @@ static void vbap_crossp( #ifdef IVAS_FLOAT_FIXED /*! r: Status result if triplet is usable for panning. Allows early exit. */ static UWord8 vector_matrix_multiply_3x3_fx( - const Word16 *src_vector, /* i : input vector */ - Word32 matrix[3][3], /* i : input matrix */ - Word32 *result, /* o : output vector */ + const Word16 *src_vector, /* i : input vector Q15 */ + Word32 matrix[3][3], /* i : input matrix Q(q_matrix) */ + Word32 *result, /* o : output vector Q(q_matrix) */ Word16 q_matrix ) { - result[0] = Mpy_32_16_1( matrix[0][0], src_vector[0] ); // q = q_matrix - result[0] = L_add( result[0], Mpy_32_16_1( matrix[1][0], src_vector[1] ) ); - result[0] = L_add( result[0], Mpy_32_16_1( matrix[2][0], src_vector[2] ) ); + result[0] = Mpy_32_16_1( matrix[0][0], src_vector[0] ); /* Q(q_matrix) */ + result[0] = L_add( result[0], Mpy_32_16_1( matrix[1][0], src_vector[1] ) ); /* Q(q_matrix) */ + result[0] = L_add( result[0], Mpy_32_16_1( matrix[2][0], src_vector[2] ) ); /* Q(q_matrix) */ move32(); move32(); move32(); - IF( LT_32( result[0], Mpy_32_16_1( L_lshl( 1, q_matrix ), -327 ) ) ) // 327 = 0.01 in Q = 15 + IF( LT_32( result[0], Mpy_32_16_1( L_lshl( 1, q_matrix ), -327 /* -0.01 in Q15 */ ) ) ) { return 0; } - result[1] = Mpy_32_16_1( matrix[0][1], src_vector[0] ); - result[1] = L_add( result[1], Mpy_32_16_1( matrix[1][1], src_vector[1] ) ); - result[1] = L_add( result[1], Mpy_32_16_1( matrix[2][1], src_vector[2] ) ); + result[1] = Mpy_32_16_1( matrix[0][1], src_vector[0] ); /* Q(q_matrix) */ + result[1] = L_add( result[1], Mpy_32_16_1( matrix[1][1], src_vector[1] ) ); /* Q(q_matrix) */ + result[1] = L_add( result[1], Mpy_32_16_1( matrix[2][1], src_vector[2] ) ); /* Q(q_matrix) */ move32(); move32(); move32(); - IF( LT_32( result[1], Mpy_32_16_1( L_shl( 1, q_matrix ), -327 ) ) ) + IF( LT_32( result[1], Mpy_32_16_1( L_shl( 1, q_matrix ), -327 /* -0.01 in Q15 */ ) ) ) { return 0; } - result[2] = Mpy_32_16_1( matrix[0][2], src_vector[0] ); - result[2] = L_add( result[2], Mpy_32_16_1( matrix[1][2], src_vector[1] ) ); - result[2] = L_add( result[2], Mpy_32_16_1( matrix[2][2], src_vector[2] ) ); + result[2] = Mpy_32_16_1( matrix[0][2], src_vector[0] ); /* Q(q_matrix) */ + result[2] = L_add( result[2], Mpy_32_16_1( matrix[1][2], src_vector[1] ) ); /* Q(q_matrix) */ + result[2] = L_add( result[2], Mpy_32_16_1( matrix[2][2], src_vector[2] ) ); /* Q(q_matrix) */ move32(); move32(); move32(); - IF( LT_32( result[2], Mpy_32_16_1( L_shl( 1, q_matrix ), -327 ) ) ) + IF( LT_32( result[2], Mpy_32_16_1( L_shl( 1, q_matrix ), -327 /* -0.01 in Q15 */ ) ) ) { return 0; } @@ -1213,42 +1208,42 @@ static UWord8 vector_matrix_multiply_3x3_fx( } static UWord8 vector_matrix_multiply_3x3_32_fx( - const Word32 *src_vector, /* i : input vector */ - Word32 matrix[3][3], /* i : input matrix */ - Word32 *result, /* o : output vector */ + const Word32 *src_vector, /* i : input vector Q30 */ + Word32 matrix[3][3], /* i : input matrix Q(q_matrix) */ + Word32 *result, /* o : output vector Q(q_matrix - 1) */ Word16 q_matrix ) { - result[0] = Mpy_32_32( matrix[0][0], src_vector[0] ); // q = ( q_matrix + 30 ) - 31 - result[0] = L_add( result[0], Mpy_32_32( matrix[1][0], src_vector[1] ) ); - result[0] = L_add( result[0], Mpy_32_32( matrix[2][0], src_vector[2] ) ); + result[0] = Mpy_32_32( matrix[0][0], src_vector[0] ); /* Q(q_matrix - 1) */ + result[0] = L_add( result[0], Mpy_32_32( matrix[1][0], src_vector[1] ) ); /* Q(q_matrix - 1) */ + result[0] = L_add( result[0], Mpy_32_32( matrix[2][0], src_vector[2] ) ); /* Q(q_matrix - 1) */ move32(); move32(); move32(); - IF( LT_32( result[0], Mpy_32_32( L_shl( 1, ( sub( q_matrix, 1 ) ) ), -21474836 ) ) ) // 21474836 = 0.01 in Q = 31 + IF( LT_32( result[0], Mpy_32_32( L_shl( 1, ( sub( q_matrix, 1 ) ) ), -21474836 /* -0.01 in Q31 */ ) ) ) { return 0; } - result[1] = Mpy_32_32( matrix[0][1], src_vector[0] ); - result[1] = L_add( result[1], Mpy_32_32( matrix[1][1], src_vector[1] ) ); - result[1] = L_add( result[1], Mpy_32_32( matrix[2][1], src_vector[2] ) ); + result[1] = Mpy_32_32( matrix[0][1], src_vector[0] ); /* Q(q_matrix - 1) */ + result[1] = L_add( result[1], Mpy_32_32( matrix[1][1], src_vector[1] ) ); /* Q(q_matrix - 1) */ + result[1] = L_add( result[1], Mpy_32_32( matrix[2][1], src_vector[2] ) ); /* Q(q_matrix - 1) */ move32(); move32(); move32(); - IF( LT_32( result[1], Mpy_32_32( L_shl( 1, ( sub( q_matrix, 1 ) ) ), -21474836 ) ) ) // 21474836 = 0.01 in Q = 31 + IF( LT_32( result[1], Mpy_32_32( L_shl( 1, ( sub( q_matrix, 1 ) ) ), -21474836 /* -0.01 in Q31 */ ) ) ) { return 0; } - result[2] = Mpy_32_32( matrix[0][2], src_vector[0] ); - result[2] = L_add( result[2], Mpy_32_32( matrix[1][2], src_vector[1] ) ); - result[2] = L_add( result[2], Mpy_32_32( matrix[2][2], src_vector[2] ) ); + result[2] = Mpy_32_32( matrix[0][2], src_vector[0] ); /* Q(q_matrix - 1) */ + result[2] = L_add( result[2], Mpy_32_32( matrix[1][2], src_vector[1] ) ); /* Q(q_matrix - 1) */ + result[2] = L_add( result[2], Mpy_32_32( matrix[2][2], src_vector[2] ) ); /* Q(q_matrix - 1) */ move32(); move32(); move32(); - IF( LT_32( result[2], Mpy_32_32( L_shl( 1, ( sub( q_matrix, 1 ) ) ), -21474836 ) ) ) // 21474836 = 0.01 in Q = 31 + IF( LT_32( result[2], Mpy_32_32( L_shl( 1, ( sub( q_matrix, 1 ) ) ), -21474836 /* -0.01 in Q31 */ ) ) ) { return 0; } @@ -1292,8 +1287,8 @@ static uint8_t vector_matrix_multiply_3x3( return 1; } - #endif + /*----------------------------------------------------------------------------------------------* * determine_best_triplet_and_gains() * @@ -1301,14 +1296,12 @@ static uint8_t vector_matrix_multiply_3x3( *----------------------------------------------------------------------------------------------*/ /*! r: triplet id */ - - #ifdef IVAS_FLOAT_FIXED static Word16 determine_best_triplet_and_gains_fx( - VBAP_SEARCH_STRUCT *search_struct, /* i : VBAP search struct */ - const Word16 panning_unit_vec_fx[3], /* i : panning unit vector */ - const Word16 azi_deg, /* i : panning azimuth */ - Word32 gains_fx[3] /* o : panning gains */ + VBAP_SEARCH_STRUCT *search_struct, /* i : VBAP search struct */ + const Word16 panning_unit_vec_fx[3], /* i : panning unit vector Q15 */ + const Word16 azi_deg, /* i : panning azimuth */ + Word32 gains_fx[3] /* o : panning gains Q(VBAP_VS_TRIPLET.q_inverse_matrix) */ ) { Word16 i, tr, k; @@ -1334,13 +1327,23 @@ static Word16 determine_best_triplet_and_gains_fx( * the chosen four sectors. */ IF( GT_16( abs_s( azi_deg ), 90 ) ) { - sector = azi_deg < 0 ? 2 : 1; + sector = 1; move16(); + if ( azi_deg < 0 ) + { + sector = 2; + move16(); + } } ELSE { - sector = azi_deg < 0 ? 3 : 0; + sector = 0; move16(); + if ( azi_deg < 0 ) + { + sector = 3; + move16(); + } } first_triplet = search_struct->initial_search_indices[sector]; move16(); @@ -1355,7 +1358,6 @@ static Word16 determine_best_triplet_and_gains_fx( IF( triplet_ok ) { min_gain_this_fx = L_min( ( L_min( unnormalized_gains_fx[0], unnormalized_gains_fx[1] ) ), unnormalized_gains_fx[2] ); - move32(); IF( GT_32( min_gain_this_fx, best_min_gain_fx ) ) { @@ -1365,7 +1367,7 @@ static Word16 determine_best_triplet_and_gains_fx( move16(); FOR( k = 0; k < 3; k++ ) { - gains_fx[k] = unnormalized_gains_fx[k]; + gains_fx[k] = unnormalized_gains_fx[k]; /* Q(VBAP_VS_TRIPLET.q_inverse_matrix) */ move32(); } IF( best_min_gain_fx >= 0 ) @@ -1472,21 +1474,22 @@ static int16_t determine_best_triplet_and_gains( return best_triplet; } #endif + /*-------------------------------------------------------------------------* * determine_virtual_speaker_node_division_gains() * * Determines how the virtual node gains are distributed to real nodes *-------------------------------------------------------------------------*/ + #ifdef IVAS_FLOAT_FIXED static void determine_virtual_speaker_node_division_gains_fx( - const Word16 virtual_speaker_node_index, /* i : virtual speaker node index */ - Word16 *virtual_node_division_gains_fx, - Word16 *max_exp, - Word16 connections[][2], /* i : vector of all connections */ - const enum VirtualSpeakerNodeType type, /* i : virtual speaker node typel */ - const Word16 max_num_connections, /* i : max number of connections */ - const Word16 num_speaker_nodes, /* i : max number of speaker nodes */ - const Word16 use_object_mode /* i : use VBAP in object panning mode vs. spatial panning mode */ + const Word16 virtual_speaker_node_index, /* i : virtual speaker node index */ + Word16 *virtual_node_division_gains_fx, /* o : virtual speaker node division gains Q16 */ + Word16 connections[][2], /* i : vector of all connections */ + const enum VirtualSpeakerNodeType type, /* i : virtual speaker node typel */ + const Word16 max_num_connections, /* i : max number of connections */ + const Word16 num_speaker_nodes, /* i : max number of speaker nodes */ + const Word16 use_object_mode /* i : use VBAP in object panning mode vs. spatial panning mode */ ) { /* When node type is VIRTUAL_SPEAKER_NODE_DISTRIBUTE_ENERGY, the gains of the virtual node @@ -1536,7 +1539,7 @@ static void determine_virtual_speaker_node_division_gains_fx( Word16 guard_bits = find_guarded_bits_fx( num_speaker_nodes ); FOR( ch = 0; ch < num_speaker_nodes; ch++ ) { - sum_val_fx = add( sum_val_fx, shr( virtual_node_division_gains_fx[ch], guard_bits ) ); // Q10 + sum_val_fx = add( sum_val_fx, shr( virtual_node_division_gains_fx[ch], guard_bits ) ); } Word16 final_exp = 0, res_exp; Word32 tmp_1, tmp_2, tmp_3; @@ -1545,7 +1548,7 @@ static void determine_virtual_speaker_node_division_gains_fx( { IF( virtual_node_division_gains_fx[ch] != 0 ) { - BASOP_Util_Divide_MantExp( virtual_node_division_gains_fx[ch], 1, sum_val_fx, add( guard_bits, 1 ), &virtual_node_division_gains_fx[ch], &final_exp ); // Q15 + BASOP_Util_Divide_MantExp( virtual_node_division_gains_fx[ch], 1, sum_val_fx, add( guard_bits, 1 ), &virtual_node_division_gains_fx[ch], &final_exp ); } ELSE { @@ -1565,9 +1568,9 @@ static void determine_virtual_speaker_node_division_gains_fx( } ELSE { - Word32 tmp32 = L_deposit_h( virtual_node_division_gains_fx[ch] ); // q is 15-final_exp// ldep -> 31-final_exp (q) + Word32 tmp32 = L_deposit_h( virtual_node_division_gains_fx[ch] ); tmp_1 = L_add( BASOP_Util_Log2( tmp32 ), L_shl( ( sub( 31, sub( 31, final_exp ) ) ), 25 ) ); // Q25 - tmp_2 = Mpy_32_32( 26843546 /*0.8f in Q25*/, tmp_1 ); + tmp_2 = Mpy_32_32( 26843546 /* 0.8f in Q25 */, tmp_1 ); tmp_3 = BASOP_util_Pow2( tmp_2, Q31 - Q19, &res_exp ); exp_virtual_node_division_gains[ch] = res_exp; move16(); @@ -1577,10 +1580,9 @@ static void determine_virtual_speaker_node_division_gains_fx( } } /*make a common exp*/ - *max_exp = -1; /*Q16*/ FOR( i = 0; i < num_speaker_nodes; i++ ) { - virtual_node_division_gains_fx[i] = shr( virtual_node_division_gains_fx[i], sub( *max_exp, exp_virtual_node_division_gains[i] ) ); + virtual_node_division_gains_fx[i] = shr( virtual_node_division_gains_fx[i], sub( -1, exp_virtual_node_division_gains[i] ) ); /* Q16 */ move16(); } } @@ -1662,13 +1664,13 @@ static void determine_virtual_speaker_node_division_gains( #ifdef IVAS_FLOAT_FIXED static enum VirtualSpeakerNodeType check_need_of_virtual_speaker_node_fx( VBAP_HANDLE hVBAPdata, /* i/o: VBAP structure */ - const Word32 *speaker_node_azi_deg_fx, /* i : vector of speaker node azimuths */ - const Word32 *speaker_node_ele_deg_fx, /* i : vector of speaker node elevations */ + const Word32 *speaker_node_azi_deg_fx, /* i : vector of speaker node azimuths Q22 */ + const Word32 *speaker_node_ele_deg_fx, /* i : vector of speaker node elevations Q22 */ enum SpeakerNodeGroup group /* i : group of speaker nodes where this belongs */ ) { Word16 ch; - Word32 max_elevation_fx = 0; + Word32 max_elevation_fx = 0; /* Q22 */ Word16 Flag1, Flag2, Flag3; move32(); @@ -1677,17 +1679,17 @@ static enum VirtualSpeakerNodeType check_need_of_virtual_speaker_node_fx( { Word16 virtual_back_needed = 1; move16(); - const Word16 virtual_back_epsilon_fx = -573; /* -0.0175f Q15*/ + const Word16 virtual_back_epsilon_fx = -573; /* -0.0175f in Q15 */ move16(); FOR( ch = 0; ch < hVBAPdata->num_speaker_nodes; ch++ ) { Flag1 = BASOP_Util_Cmp_Mant32Exp( speaker_node_ele_deg_fx[ch], Q31 - Q22, 23040 /*45.0f Q9*/, Q31 - Q9 ); - IF( EQ_16( Flag1, (Word16) -1 ) ) + IF( EQ_16( Flag1, -1 ) ) { Word16 azi_temp; - azi_temp = extract_l( L_shr( Mpy_32_32( speaker_node_azi_deg_fx[ch], ONE_BY_180_Q31 ), Q8 ) ); /* Q15 */ - Word16 cos_res = getCosWord16R2( azi_temp ); // Q15 + azi_temp = extract_l( L_shr( Mpy_32_32( speaker_node_azi_deg_fx[ch], ONE_BY_360_Q31 ), Q7 ) ); /* Q15 */ + Word16 cos_res = getCosWord16R2( azi_temp ); /* Q15 */ IF( LT_16( cos_res, virtual_back_epsilon_fx ) ) { @@ -1729,7 +1731,7 @@ static enum VirtualSpeakerNodeType check_need_of_virtual_speaker_node_fx( } } } - Flag2 = BASOP_Util_Cmp_Mant32Exp( max_elevation_fx, Q31 - Q22, 23039 /*44.9990005 Q9*/, Q31 - Q9 ); + Flag2 = BASOP_Util_Cmp_Mant32Exp( max_elevation_fx, Q31 - Q22, 23039 /* 44.9990005 in Q9 */, Q31 - Q9 ); IF( EQ_16( Flag2, 1 ) ) { return NO_VIRTUAL_SPEAKER_NODE; @@ -1749,7 +1751,7 @@ static enum VirtualSpeakerNodeType check_need_of_virtual_speaker_node_fx( hVBAPdata->num_speaker_nodes_internal = add( hVBAPdata->num_speaker_nodes_internal, 1 ); move16(); - Flag3 = BASOP_Util_Cmp_Mant32Exp( max_elevation_fx, Q31 - Q22, 20478 /*19.9990005 Q10*/, Q31 - Q10 ); + Flag3 = BASOP_Util_Cmp_Mant32Exp( max_elevation_fx, Q31 - Q22, 20478 /* 19.9990005 in Q10 */, Q31 - Q10 ); IF( EQ_16( Flag3, 1 ) ) { @@ -1849,31 +1851,28 @@ static enum VirtualSpeakerNodeType check_need_of_virtual_speaker_node( #ifdef IVAS_FLOAT_FIXED static void init_speaker_node_direction_data_fx( - VBAP_SPEAKER_NODE *speaker_node_data, /* o : storage for speaker node data */ - const Word32 *speaker_node_azi_deg_fx, /* i : vector of speaker node azimuths */ - const Word32 *speaker_node_ele_deg_fx, /* i : vector of speaker node elevations */ - const Word16 num_speaker_nodes /* i : number of speaker nodes */ + VBAP_SPEAKER_NODE *speaker_node_data, /* o : storage for speaker node data */ + const Word32 *speaker_node_azi_deg_fx, /* i : vector of speaker node azimuths Q22 */ + const Word32 *speaker_node_ele_deg_fx, /* i : vector of speaker node elevations Q22 */ + const Word16 num_speaker_nodes /* i : number of speaker nodes */ ) { Word16 ch; - - Word16 azi_rad_fx = 0; - Word16 ele_rad_fx = 0; - + Word16 azi_rad_fx; + Word16 ele_rad_fx; Word16 num_horiz = 0; UWord8 in_all_mode = TRUE; - move32(); - move32(); - move32(); move16(); + move16(); + FOR( ch = 0; ch < num_speaker_nodes; ch++ ) { speaker_node_data[ch].azi_deg_fx = speaker_node_azi_deg_fx[ch]; move32(); - azi_rad_fx = extract_l( L_shr( Mpy_32_32( speaker_node_azi_deg_fx[ch], ONE_BY_180_Q31 ), Q8 ) ); + azi_rad_fx = extract_l( L_shr( Mpy_32_32( speaker_node_azi_deg_fx[ch], ONE_BY_360_Q31 ), Q7 ) ); /* Q15 */ test(); - IF( GE_32( L_shr( speaker_node_ele_deg_fx[ch], 22 ), -5 ) && LE_32( L_shr( speaker_node_ele_deg_fx[ch], 22 ), 5 ) ) + IF( GE_32( L_shr( speaker_node_ele_deg_fx[ch], Q22 ), -5 ) && LE_32( L_shr( speaker_node_ele_deg_fx[ch], Q22 ), 5 ) ) { speaker_node_data[ch].ele_deg_fx = 0; move32(); @@ -1887,7 +1886,7 @@ static void init_speaker_node_direction_data_fx( { speaker_node_data[ch].ele_deg_fx = speaker_node_ele_deg_fx[ch]; move32(); - ele_rad_fx = extract_l( L_shr( Mpy_32_32( speaker_node_ele_deg_fx[ch], ONE_BY_180_Q31 ), Q8 ) ); + ele_rad_fx = extract_l( L_shr( Mpy_32_32( speaker_node_ele_deg_fx[ch], ONE_BY_360_Q31 ), Q7 ) ); /* Q15 */ IF( ele_rad_fx < 0 ) { @@ -1901,11 +1900,11 @@ static void init_speaker_node_direction_data_fx( } } - speaker_node_data[ch].unit_vec_fx[0] = L_shr( L_mult( getCosWord16R2( azi_rad_fx ), getCosWord16R2( ele_rad_fx ) ), 1 ); // Q30 (add one gaurd bit , buffer being used in Q30) + speaker_node_data[ch].unit_vec_fx[0] = L_shr( L_mult( getCosWord16R2( azi_rad_fx ), getCosWord16R2( ele_rad_fx ) ), 1 ); /* Q15 + Q15 + Q1 - Q1 = Q30 */ move32(); - speaker_node_data[ch].unit_vec_fx[1] = L_shr( L_mult( getSineWord16R2( azi_rad_fx ), getCosWord16R2( ele_rad_fx ) ), 1 ); // Q30 + speaker_node_data[ch].unit_vec_fx[1] = L_shr( L_mult( getSineWord16R2( azi_rad_fx ), getCosWord16R2( ele_rad_fx ) ), 1 ); /* Q15 + Q15 + Q1 - Q1 = Q30 */ move32(); - speaker_node_data[ch].unit_vec_fx[2] = L_shr( L_deposit_h( getSineWord16R2( ele_rad_fx ) ), 1 ); // Q30 + speaker_node_data[ch].unit_vec_fx[2] = L_shr( L_deposit_h( getSineWord16R2( ele_rad_fx ) ), 1 ); /* Q15 + Q16 - Q1 = Q30 */ move32(); } /* Check for largest horizontal gap if there are at least 3 horizontal speaker nodes */ @@ -1921,18 +1920,19 @@ static void init_speaker_node_direction_data_fx( move16(); FOR( ch = 0; ch < num_speaker_nodes && i < num_horiz; ch++ ) { + test(); IF( EQ_16( speaker_node_data[ch].group, SPEAKER_NODE_HORIZONTAL ) ) { Word16 exp1; - Word32 Mant2 = BASOP_Util_Add_Mant32Exp( speaker_node_azi_deg_fx[ch], 31 - 22, 23040, 31 - 6, &exp1 ); + Word32 Mant2 = BASOP_Util_Add_Mant32Exp( speaker_node_azi_deg_fx[ch], Q31 - Q22, 23040 /* 360.0f in Q6 */, Q31 - Q6, &exp1 ); IF( L_shr( speaker_node_azi_deg_fx[ch], 22 ) < 0 ) { - horiz_azi[i] = (UWord16) L_shr( Mant2, sub( 31, exp1 ) ); + horiz_azi[i] = (UWord16) L_shr( Mant2, sub( 31, exp1 ) ); /* Q0 */ } ELSE { - horiz_azi[i] = (UWord16) L_shr( speaker_node_azi_deg_fx[ch], 22 ); + horiz_azi[i] = (UWord16) L_shr( speaker_node_azi_deg_fx[ch], Q22 ); /* Q0 */ } i = add( i, 1 ); } @@ -1944,7 +1944,7 @@ static void init_speaker_node_direction_data_fx( /* Find largest gap. Initialize with the wrap over gap. */ largest_gap = add( sub( horiz_azi[0], horiz_azi[num_horiz - 1] ), 360 ); - FOR( ch = 0; ch < sub( num_horiz, 1 ); ch++ ) + FOR( ch = 0; ch < num_horiz - 1; ch++ ) { temp = sub( horiz_azi[ch + 1], horiz_azi[ch] ); if ( GT_16( temp, largest_gap ) ) @@ -2082,26 +2082,25 @@ static void init_speaker_node_direction_data( #ifdef IVAS_FLOAT_FIXED static void matrix_inverse_3x3_32_fx( - const Word32 **input_matrix_fx, /* i : input matrix */ - Word32 inverse_matrix_fx[3][3], /* o : output matrix */ + const Word32 **input_matrix_fx, /* i : input matrix Q30 */ + Word32 inverse_matrix_fx[3][3], /* o : output matrix Q(31 - exp_inv_mat) */ Word16 *exp_inv_mat ) { Word16 k; - Word32 determinant_fx; - Word32 cross_vec_fx[3]; + Word32 determinant_fx; /* Q28 */ + Word32 cross_vec_fx[3]; /* Q29 */ Word16 exp_inverse_matrix_fx[3][3]; vbap_crossp_fx( input_matrix_fx[1], input_matrix_fx[2], cross_vec_fx ); - determinant_fx = dotp_fixed( input_matrix_fx[0], cross_vec_fx, 3 ); // Q30 + Q29 - Q31 = Q28 + determinant_fx = dotp_fixed( input_matrix_fx[0], cross_vec_fx, 3 ); Word16 inv_mat_exp = 0; move16(); FOR( k = 0; k < 3; k++ ) { inverse_matrix_fx[k][0] = L_deposit_h( BASOP_Util_Divide3232_Scale( cross_vec_fx[k], determinant_fx, &inv_mat_exp ) ); - inv_mat_exp = add( inv_mat_exp, ( ( 31 - 29 ) - ( 31 - 28 ) ) ); - exp_inverse_matrix_fx[k][0] = inv_mat_exp; - move32(); + inv_mat_exp = add( inv_mat_exp, ( ( Q31 - Q29 ) - ( Q31 - Q28 ) ) ); + exp_inverse_matrix_fx[k][0] = inv_mat_exp; move16(); } @@ -2110,10 +2109,9 @@ static void matrix_inverse_3x3_32_fx( FOR( k = 0; k < 3; k++ ) { inverse_matrix_fx[k][1] = L_deposit_h( BASOP_Util_Divide3232_Scale( cross_vec_fx[k], determinant_fx, &inv_mat_exp ) ); - inv_mat_exp = add( inv_mat_exp, ( ( 31 - 29 ) - ( 31 - 28 ) ) ); - exp_inverse_matrix_fx[k][1] = inv_mat_exp; - move32(); + inv_mat_exp = add( inv_mat_exp, ( ( Q31 - Q29 ) - ( Q31 - Q28 ) ) ); + exp_inverse_matrix_fx[k][1] = inv_mat_exp; move16(); } @@ -2123,7 +2121,7 @@ static void matrix_inverse_3x3_32_fx( { inverse_matrix_fx[k][2] = L_deposit_h( BASOP_Util_Divide3232_Scale( cross_vec_fx[k], determinant_fx, &inv_mat_exp ) ); move32(); - inv_mat_exp = add( inv_mat_exp, ( ( 31 - 29 ) - ( 31 - 28 ) ) ); + inv_mat_exp = add( inv_mat_exp, ( ( Q31 - Q29 ) - ( Q31 - Q28 ) ) ); exp_inverse_matrix_fx[k][2] = inv_mat_exp; move16(); } @@ -2149,13 +2147,13 @@ static void matrix_inverse_3x3_32_fx( IF( LT_16( exp_inverse_matrix_fx[i][j], -15 ) && inverse_matrix_fx[i][j] != 0 ) { inverse_matrix_fx[i][j] = 1; - exp_inverse_matrix_fx[i][j] = 0; move32(); + exp_inverse_matrix_fx[i][j] = 0; move16(); } ELSE { - inverse_matrix_fx[i][j] = L_shr( inverse_matrix_fx[i][j], *exp_inv_mat - exp_inverse_matrix_fx[i][j] ); + inverse_matrix_fx[i][j] = L_shr( inverse_matrix_fx[i][j], sub( *exp_inv_mat, exp_inverse_matrix_fx[i][j] ) ); /* Q(31 - *exp_inv_mat) */ move32(); } } @@ -2205,37 +2203,41 @@ static void matrix_inverse_3x3( * Check if the given loudspeaker triplet is a valid one and store data when * valid triplet is found. *-------------------------------------------------------------------------*/ + #ifdef IVAS_FLOAT_FIXED static Word16 check_and_store_triplet_fx( - const Word16 chA, /* i : first channel index that forms the loudspeaker triplet */ - const Word16 chB, /* i : second channel index that forms the loudspeaker triplet */ - const Word16 chC, /* i : third channel index that forms the loudspeaker triplet */ - const Word16 num_speaker_nodes, /* i : number of speaker nodes */ - const VBAP_SPEAKER_NODE *speaker_node_data, /* i : speaker node data structure */ - VBAP_VS_TRIPLET *triplets, /* o : vector of virtual surface triplets */ - Word16 *triplet_index, /* i/o: index for the next free triplet slot */ - Word32 *triplet_azidegs_fx, - Word16 *triplet_order /* o : initial order of triplet indices */ + const Word16 chA, /* i : first channel index that forms the loudspeaker triplet */ + const Word16 chB, /* i : second channel index that forms the loudspeaker triplet */ + const Word16 chC, /* i : third channel index that forms the loudspeaker triplet */ + const Word16 num_speaker_nodes, /* i : number of speaker nodes */ + const VBAP_SPEAKER_NODE *speaker_node_data, /* i : speaker node data structure */ + VBAP_VS_TRIPLET *triplets, /* o : vector of virtual surface triplets */ + Word16 *triplet_index, /* i/o: index for the next free triplet slot */ + Word32 *triplet_azidegs_fx, /* o : center azimuths of the found triplets Q19 */ + Word16 *triplet_order /* o : initial order of triplet indices */ ) { Word16 ch_check; Word16 k; Word16 speaker_node_found_inside_triplet; UWord8 triplet_ok; + Word16 exp_inv_mat; - Word32 inverse_matrix_fx[3][3], unnormalized_gains_fx[3]; + Word32 inverse_matrix_fx[3][3] /* Q(31 - exp_inv_mat) */, unnormalized_gains_fx[3] /* Q(31 - exp_inv_mat - 1) */; set32_fx( unnormalized_gains_fx, 0, 3 ); - const Word32 *speaker_node_triplet_unit_vec_matrix_fx[3]; + const Word32 *speaker_node_triplet_unit_vec_matrix_fx[3]; /* Q30 */ /* Triplet found, determine inverse matrix for VBAP formulation */ speaker_node_triplet_unit_vec_matrix_fx[0] = speaker_node_data[chA].unit_vec_fx; + move32(); speaker_node_triplet_unit_vec_matrix_fx[1] = speaker_node_data[chB].unit_vec_fx; + move32(); speaker_node_triplet_unit_vec_matrix_fx[2] = speaker_node_data[chC].unit_vec_fx; - Word16 exp_inv_mat = 31; - move16(); + move32(); matrix_inverse_3x3_32_fx( speaker_node_triplet_unit_vec_matrix_fx, inverse_matrix_fx, &exp_inv_mat ); triplets[*triplet_index].q_inverse_matrix = sub( 31, exp_inv_mat ); + move16(); /* Check through all speaker nodes that none of them are within the triplet. * Node within the triplet is identified by that all three panning gains are positive. @@ -2248,7 +2250,7 @@ static Word16 check_and_store_triplet_fx( test(); IF( ( NE_16( ch_check, chA ) ) && NE_16( ch_check, chB ) && NE_16( ch_check, chC ) ) { - triplet_ok = vector_matrix_multiply_3x3_32_fx( speaker_node_data[ch_check].unit_vec_fx, inverse_matrix_fx, unnormalized_gains_fx, sub( 31, exp_inv_mat ) ); + triplet_ok = vector_matrix_multiply_3x3_32_fx( speaker_node_data[ch_check].unit_vec_fx, inverse_matrix_fx, unnormalized_gains_fx, sub( Q31, exp_inv_mat ) ); test(); test(); test(); @@ -2275,16 +2277,16 @@ static Word16 check_and_store_triplet_fx( Copy32( inverse_matrix_fx[k], triplets[*triplet_index].inverse_matrix_fx[k], 3 ); } /* Get center azimuth for fast search use */ - Word32 tmp_a = L_add( L_shr( L_add( speaker_node_data[chA].unit_vec_fx[1], speaker_node_data[chB].unit_vec_fx[1] ), 2 ), L_shr( speaker_node_data[chC].unit_vec_fx[1], 2 ) ); // Q28 + Word32 tmp_a = L_add( L_shr( L_add( speaker_node_data[chA].unit_vec_fx[1], speaker_node_data[chB].unit_vec_fx[1] ), Q2 ), L_shr( speaker_node_data[chC].unit_vec_fx[1], Q2 ) ); /* Q28 */ /*Condition to make tmp_a 0 to adress precision loss seen*/ - if ( EQ_32( tmp_a, -8193 ) ) + if ( EQ_32( tmp_a, -8193 /* -0.0000305 in Q28 */ ) ) { tmp_a = 0; move32(); } - Word32 tmp_b = L_add( L_shr( L_add( speaker_node_data[chA].unit_vec_fx[0], speaker_node_data[chB].unit_vec_fx[0] ), 2 ), L_shr( speaker_node_data[chC].unit_vec_fx[0], 2 ) ); // Q28 - Word16 tmp_tan = shr( BASOP_util_atan2( tmp_a, tmp_b, 0 ), Q13 - Q9 ); - triplet_azidegs_fx[*triplet_index] = L_mult( tmp_tan, 29335 /*_180_OVER_PI in Q9*/ ); // Q3 + Word32 tmp_b = L_add( L_shr( L_add( speaker_node_data[chA].unit_vec_fx[0], speaker_node_data[chB].unit_vec_fx[0] ), 2 ), L_shr( speaker_node_data[chC].unit_vec_fx[0], 2 ) ); /* Q28 */ + Word16 tmp_tan = shr( BASOP_util_atan2( tmp_a, tmp_b, 0 ), Q13 - Q9 ); /* Q9 */ + triplet_azidegs_fx[*triplet_index] = L_mult( tmp_tan, 29335 /*_180_OVER_PI in Q9*/ ); /* Q19 */ move32(); /* Store increasing order indices for the later sorting step. */ triplet_order[*triplet_index] = *triplet_index; @@ -2300,7 +2302,6 @@ static Word16 check_and_store_triplet_fx( return 0; } #else - static int16_t check_and_store_triplet( const int16_t chA, /* i : first channel index that forms the loudspeaker triplet */ const int16_t chB, /* i : second channel index that forms the loudspeaker triplet */ @@ -2399,7 +2400,7 @@ static Word16 determine_virtual_surface_triplets_fx( Word16 num_connected_to_chA; Word16 connected_to_chA[VBAP_MAX_NUM_SPEAKER_NODES]; Word16 connection_uses_left[VBAP_MAX_NUM_SPEAKER_NODES]; - Word32 triplet_azidegs_fx[VBAP_MAX_NUM_TRIPLETS]; + Word32 triplet_azidegs_fx[VBAP_MAX_NUM_TRIPLETS]; /* Q19 */ Word16 triplet_order[VBAP_MAX_NUM_TRIPLETS]; /* Each connection can be used exactly by two different virtual surface triplets. */ @@ -2441,12 +2442,24 @@ static Word16 determine_virtual_surface_triplets_fx( { Word16 connect_index_k = connected_to_chA[k]; move16(); - chB = EQ_16( connections[connect_index_k][0], chA ) ? connections[connect_index_k][1] : connections[connect_index_k][0]; + chB = connections[connect_index_k][0]; + move16(); + if ( EQ_16( connections[connect_index_k][0], chA ) ) + { + chB = connections[connect_index_k][1]; + move16(); + } FOR( l = k + 1; l < num_connected_to_chA; l++ ) { Word16 connect_index_l = connected_to_chA[l]; move16(); - chC = EQ_16( connections[connect_index_l][0], chA ) ? connections[connect_index_l][1] : connections[connect_index_l][0]; + chC = connections[connect_index_l][0]; + move16(); + if ( EQ_16( connections[connect_index_l][0], chA ) ) + { + chC = connections[connect_index_l][1]; + move16(); + } /* With chA, chB, and chC selected, we still need to find connection between chB and chC and verify that the triplet is valid */ FOR( m = 0; m < max_num_connections; m++ ) @@ -2485,7 +2498,7 @@ static Word16 determine_virtual_surface_triplets_fx( * each search sector for this search struct. */ v_sort_ind_fixed( triplet_azidegs_fx, triplet_order, num_triplets ); reorder_triplets_fx( triplets, triplet_order, num_triplets ); - determine_initial_search_indices_fx( num_triplets, triplet_azidegs_fx /*Q19*/, initial_search_indices ); + determine_initial_search_indices_fx( num_triplets, triplet_azidegs_fx, initial_search_indices ); return num_triplets; } @@ -2593,18 +2606,18 @@ static int16_t determine_virtual_surface_triplets( #ifdef IVAS_FLOAT_FIXED static void determine_initial_search_indices_fx( - const Word16 num_triplets, /* i : number of triplets */ - const Word32 triplet_azidegs_fx[VBAP_MAX_NUM_TRIPLETS], - Word16 initial_search_indices[VBAP_NUM_SEARCH_SECTORS] /* o : initial search indices */ + const Word16 num_triplets, /* i : number of triplets */ + const Word32 triplet_azidegs_fx[VBAP_MAX_NUM_TRIPLETS], /* i : azimuths of triplets (in degrees) Q19 */ + Word16 initial_search_indices[VBAP_NUM_SEARCH_SECTORS] /* o : initial search indices */ ) { Word16 i, j; - Word32 sector_reference_azideg_fx; - Word32 sector_border_start_azideg_fx; - Word32 sector_border_end_azideg_fx; + Word32 sector_reference_azideg_fx; /* Q0 */ + Word32 sector_border_start_azideg_fx; /* Q0 */ + Word32 sector_border_end_azideg_fx; /* Q0 */ Word16 best_index; Word32 min_azideg_diff_fx; - Word32 azideg_diff_fx; + Word32 azideg_diff_fx; /* Q19 */ FOR( i = 0; i < VBAP_NUM_SEARCH_SECTORS; i++ ) { @@ -2622,13 +2635,13 @@ static void determine_initial_search_indices_fx( { azideg_diff_fx = L_sub( L_shl( sector_reference_azideg_fx, Q19 ), triplet_azidegs_fx[j] ); - IF( GT_32( azideg_diff_fx, 94371840 ) ) + IF( GT_32( azideg_diff_fx, 94371840 /* 180.0f in Q19 */ ) ) { - azideg_diff_fx = L_sub( azideg_diff_fx, 188743680 ); + azideg_diff_fx = L_sub( azideg_diff_fx, 188743680 /* 360.0f in Q19 */ ); } - ELSE IF( LT_32( azideg_diff_fx, -94371840 ) ) + ELSE IF( LT_32( azideg_diff_fx, -94371840 /* -180.0f in Q19 */ ) ) { - azideg_diff_fx = L_add( azideg_diff_fx, 188743680 ); + azideg_diff_fx = L_add( azideg_diff_fx, 188743680 /* 360.0f in Q19 */ ); } azideg_diff_fx = L_abs( azideg_diff_fx ); @@ -2718,7 +2731,7 @@ static ivas_error determine_connections_fx( Word16 c; Word16 connection_write_index = 0; move16(); - Word32 non_crossing_plane_elevation_deg_fx[VBAP_MAX_PLANES]; + Word32 non_crossing_plane_elevation_deg_fx[VBAP_MAX_PLANES]; /* Q14 */ ivas_error error; @@ -2844,15 +2857,15 @@ static enum ConnectionClass determine_connection_class_fx( Word16 ch, k; const Word32 *p1_fx, *v2_fx; - Word32 v1v1_fx, v1v2_fx, v2v2_fx, v1p1_fx, v2p1_fx; - Word32 determinant_fx; + Word32 v1v1_fx, v1v2_fx, v2v2_fx, v1p1_fx, v2p1_fx; /* Q25, Q27, Q29, Q27, Q29 */ + Word32 determinant_fx; /* Q23 */ Word32 norm_distance_on_v1_fx; Word32 vec_diff_fx[3]; - Word32 v1_fx[3]; + Word32 v1_fx[3]; /* Q28 */ Word32 vTarget_fx[3]; Word32 energy_sum_fx; Word32 eq_value_fx; - Word32 uvecdot_fx; + Word32 uvecdot_fx; /* Q30 */ /* Check if connection passes through origin. This is not desired. * When this happens, unit vectors point in opposite directions. */ @@ -2885,9 +2898,10 @@ static enum ConnectionClass determine_connection_class_fx( FOR( k = 0; k < 3; k++ ) { - v1_fx[k] = L_sub( L_shr( node_data[chB].unit_vec_fx[k], 2 ), L_shr( node_data[chA].unit_vec_fx[k], 2 ) ); // q28 (Add two guard bit) + v1_fx[k] = L_sub( L_shr( node_data[chB].unit_vec_fx[k], 2 ), L_shr( node_data[chA].unit_vec_fx[k], 2 ) ); /* Q28 (Add two guard bit) */ + move32(); } - v2_fx = node_data[ch].unit_vec_fx; // q30 + v2_fx = node_data[ch].unit_vec_fx; // Q30 move32(); v1v1_fx = dotp_fixed( v1_fx, v1_fx, 3 ); // Q25 @@ -2939,13 +2953,13 @@ static enum ConnectionClass determine_connection_class_fx( FOR( k = 0; k < 3; k++ ) { var1 = Mpy_32_32( norm_distance_on_v1_fx, v1_fx[k] ); // Q(25 - exp) + Q28 - 31 - vTarget_fx[k] = BASOP_Util_Add_Mant32Exp( p1_fx[k], 1, var1, Q31 - ( Q25 - exp + Q28 - Q31 ), &exp_vTarget ); + vTarget_fx[k] = BASOP_Util_Add_Mant32Exp( p1_fx[k], 1, var1, sub( Q31, add( sub( Q25, exp ), Q28 - Q31 ) ), &exp_vTarget ); move16(); vTarget_fx_e[k] = exp_vTarget; move16(); var2 = Mpy_32_32( vTarget_fx[k], vTarget_fx[k] ); // 2*exp_vTarget - energy_sum_fx = BASOP_Util_Add_Mant32Exp( energy_sum_fx, exp_energy_sum, var2, 2 * exp_vTarget, &exp_energy_sum ); + energy_sum_fx = BASOP_Util_Add_Mant32Exp( energy_sum_fx, exp_energy_sum, var2, shl( exp_vTarget, 1 ), &exp_energy_sum ); vec_diff_fx[k] = BASOP_Util_Add_Mant32Exp( vTarget_fx[k], exp_vTarget, L_negate( v2_fx[k] ), 1, &exp_vec_diff ); move16(); vec_diff_e[k] = exp_vec_diff; @@ -2990,7 +3004,7 @@ static enum ConnectionClass determine_connection_class_fx( Word32 res = dotp_fixed( vTarget_fx, v2_fx, 3 ); // 31 - (max_vTarget_e + 2) + 30 - 31 = 28 - max_vTarget_e move32(); - IF( GT_32( res, L_shr( 2147054208, sub( 31, sub( 28, max_vTarget_e ) ) ) ) ) + IF( GT_32( res, L_shr( 2147054208 /* 0.9998f in Q31 */, sub( 31, sub( 28, max_vTarget_e ) ) ) ) ) { return CONNECTION_WITH_SPEAKER_NODE_BEHIND; } @@ -3001,10 +3015,10 @@ static enum ConnectionClass determine_connection_class_fx( Word32 vec_diff_dotp = dotp_fixed( vec_diff_fx, vec_diff_fx, 3 ); // exp : 2 * max_vec_diff_e + 4 move32(); Word32 var = Mpy_32_32( vec_diff_dotp, 51200 /*25.0f in Q11*/ ); // exp : 2 * max_vec_diff_e + 4 + 20 - Word16 Flag1 = BASOP_Util_Cmp_Mant32Exp( v1v1_fx, Q31 - Q25, var, 2 * max_vec_diff_e + 4 + 20 ); + Word16 Flag1 = BASOP_Util_Cmp_Mant32Exp( v1v1_fx, Q31 - Q25, var, add( shl( max_vec_diff_e, 1 ), 4 + 20 ) ); IF( EQ_16( Flag1, 1 ) ) { - IF( LT_32( L_abs( L_sub( node_data[chB].unit_vec_fx[2], node_data[chA].unit_vec_fx[2] ) ), 2147483 ) ) + IF( LT_32( L_abs( L_sub( node_data[chB].unit_vec_fx[2], node_data[chA].unit_vec_fx[2] ) ), 1073742 /* 0.001f in Q30 */ ) ) { return ELEVATED_PLANE_THIN_TRIANGLE_CONNECTION; } @@ -3240,10 +3254,10 @@ static void formulate_horizontal_connections( /*! r: truth value for crossing */ #ifdef IVAS_FLOAT_FIXED static Word16 check_plane_crossing_fx( - const Word32 ele1_deg_fx, /* i : speaker node 1 elevation */ - const Word32 ele2_deg_fx, /* i : speaker node 2 elevation */ - const Word16 num_non_crossing_planes, /* i : number of non-crossing planes */ - const Word32 *non_crossing_plane_elevation_deg_fx /* i : vector non-crossing plane elevations*/ + const Word32 ele1_deg_fx, /* i : speaker node 1 elevation Q22 */ + const Word32 ele2_deg_fx, /* i : speaker node 2 elevation Q22 */ + const Word16 num_non_crossing_planes, /* i : number of non-crossing planes */ + const Word32 *non_crossing_plane_elevation_deg_fx /* i : vector non-crossing plane elevations Q14 */ ) { /* Find if the connection crosses a non-crossing plane, with 1-degree threshold. */ @@ -3300,13 +3314,13 @@ static int16_t check_plane_crossing( *-------------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED static ivas_error get_half_sphere_connection_options_fx( - const VBAP_SPEAKER_NODE *speaker_node_data, /* i : speaker node data */ - const enum SpeakerNodeGroup group, /* i : speaker node group */ - const Word16 num_speaker_nodes, /* i : number of speaker nodes */ - const Word16 num_non_crossing_planes, /* i : number of non-crossing planes */ - const Word32 *non_crossing_plane_elevation_deg_fx, /* i : vector of non-crossing plane elevations */ - ConnectionOption **connection_options_pr, /* o : list of connection options */ - Word16 *num_connection_options /* o : number of connection options */ + const VBAP_SPEAKER_NODE *speaker_node_data, /* i : speaker node data */ + const enum SpeakerNodeGroup group, /* i : speaker node group */ + const Word16 num_speaker_nodes, /* i : number of speaker nodes */ + const Word16 num_non_crossing_planes, /* i : number of non-crossing planes */ + const Word32 *non_crossing_plane_elevation_deg_fx, /* i : vector of non-crossing plane elevations Q14 */ + ConnectionOption **connection_options_pr, /* o : list of connection options */ + Word16 *num_connection_options /* o : number of connection options */ ) { Word16 max_num_connection_options = 0; @@ -3380,8 +3394,8 @@ static ivas_error get_half_sphere_connection_options_fx( Word16 exp_uv = Q31 - Q27; move16(); one_minus_unit_vec_dotp_sq_root = Sqrt32( one_minus_unit_vec_dotp_sq, &exp_uv ); - acos_val = BASOP_util_atan2( one_minus_unit_vec_dotp_sq_root, unit_vec_dotp, exp_uv - 2 ); // Q13 - c_options[index].arc_fx = L_deposit_h( acos_val ); // Q29 + acos_val = BASOP_util_atan2( one_minus_unit_vec_dotp_sq_root, unit_vec_dotp, sub( exp_uv, 2 ) ); // Q13 + c_options[index].arc_fx = L_deposit_h( acos_val ); // Q29 move32(); c_options[index].arc_weighted_fx = c_options[index].arc_fx; // Q29 move32(); @@ -3397,7 +3411,7 @@ static ivas_error get_half_sphere_connection_options_fx( /* If the connection passes a pre-determined plane of speaker nodes, then add further penalty */ - IF( check_plane_crossing_fx( speaker_node_data[chA].ele_deg_fx /*q22*/, speaker_node_data[chB].ele_deg_fx, num_non_crossing_planes, non_crossing_plane_elevation_deg_fx ) ) + IF( check_plane_crossing_fx( speaker_node_data[chA].ele_deg_fx, speaker_node_data[chB].ele_deg_fx, num_non_crossing_planes, non_crossing_plane_elevation_deg_fx ) ) { c_options[index].arc_weighted_fx = L_shl( c_options[index].arc_weighted_fx, 1 ); move32(); @@ -3595,9 +3609,9 @@ static ivas_error formulate_half_sphere_connections_fx( const enum SpeakerNodeGroup group, /* i : speaker node group */ Word16 connections[][2], /* o : vector of connections */ Word16 *connection_write_index, - const Word16 max_num_connections, /* i : max number of connections */ - const Word16 num_non_crossing_planes, /* i : number of non-crossing planes */ - const Word32 *non_crossing_plane_elevation_deg_fx /* i : vector of non-crossing plane elevations */ + const Word16 max_num_connections, /* i : max number of connections */ + const Word16 num_non_crossing_planes, /* i : number of non-crossing planes */ + const Word32 *non_crossing_plane_elevation_deg_fx /* i : vector of non-crossing plane elevations Q14*/ ) { /* Variable initializations */ @@ -3607,11 +3621,11 @@ static ivas_error formulate_half_sphere_connections_fx( Word32 new_cross_fx[3]; Word32 planeCrossingVec_fx[3]; Word16 Q_planeCrossingVec; - Word32 new_arc_fx; - Word32 connection_arc_fx[( VBAP_MAX_NUM_SPEAKER_NODES - 2 ) * 3]; - Word32 connection_cross_fx[( VBAP_MAX_NUM_SPEAKER_NODES - 2 ) * 3][3]; + Word32 new_arc_fx; /* Q29 */ + Word32 connection_arc_fx[( VBAP_MAX_NUM_SPEAKER_NODES - 2 ) * 3]; /* Q29 */ + Word32 connection_cross_fx[( VBAP_MAX_NUM_SPEAKER_NODES - 2 ) * 3][3]; /* Q29 */ Word32 tmpFloat_fx; - Word32 cmp_arc_fx; + Word32 cmp_arc_fx; /* Q29 */ Word32 normVal_fx; Word16 angleCmp_fx; ConnectionOption *connection_options; @@ -3648,6 +3662,7 @@ static ivas_error formulate_half_sphere_connections_fx( move16(); WHILE( c_opt < num_connection_options && *connection_write_index < max_num_connections ) { + test(); chA = connection_options[c_opt].chA; move16(); chB = connection_options[c_opt].chB; @@ -3747,10 +3762,10 @@ static ivas_error formulate_half_sphere_connections_fx( sub_exp = 0, sub_exp_2 = 0, sub_final_exp = 0; var_a = BASOP_Util_Add_Mant32Exp( new_arc_fx, Q31 - Q29, L_negate( L_deposit_h( angleCmp_fx ) ), final_exp, &sub_exp ); - comp1 = BASOP_Util_Cmp_Mant32Exp( L_abs( var_a ), sub_exp, 21474836, 0 ); + comp1 = BASOP_Util_Cmp_Mant32Exp( L_abs( var_a ), sub_exp, 21474836 /* 0.01f in Q31 */, 0 ); var_b = BASOP_Util_Add_Mant32Exp( 25735, Q31 - Q12, L_negate( L_deposit_h( angleCmp_fx ) ), final_exp, &sub_exp_2 ); var_c = BASOP_Util_Add_Mant32Exp( new_arc_fx, Q31 - Q29, L_negate( var_b ), sub_exp_2, &sub_final_exp ); - comp2 = BASOP_Util_Cmp_Mant32Exp( L_abs( var_c ), sub_final_exp, 21474836, 0 ); + comp2 = BASOP_Util_Cmp_Mant32Exp( L_abs( var_c ), sub_final_exp, 21474836 /* 0.01f in Q31 */, 0 ); within_first_arc = 0; move16(); @@ -3771,7 +3786,7 @@ static ivas_error formulate_half_sphere_connections_fx( move32(); } /*update Q for planeCrossingVec */ - Q_planeCrossingVec = sub( sub( add( Q27, Q27 ), tmp_exp ), Q31 ); + Q_planeCrossingVec = sub( sub( Q27 + Q27, tmp_exp ), Q31 ); } /* Study if the crossing is also between arc cmp_chA-cmp_chB */ @@ -3803,13 +3818,13 @@ static ivas_error formulate_half_sphere_connections_fx( } one_minus_var1_sq = BASOP_Util_Add_Mant32Exp( ONE_IN_Q30, 1, L_negate( var1_sq ), exp_var1_sq, &final_exp_A ); var1_sqrt = Sqrt32( one_minus_var1_sq, &final_exp_A ); - var1_cos = BASOP_util_atan2( var1_sqrt, var1, final_exp_A - ( Q31 - ( Q_planeCrossingVec + Q30 - Q31 ) ) ); // Q13 + var1_cos = BASOP_util_atan2( var1_sqrt, var1, sub( final_exp_A, sub( Q31, add( Q_planeCrossingVec, Q30 - Q31 ) ) ) ); // Q13 angleCmp_fx = var1_cos; move16(); one_minus_var2_sq = BASOP_Util_Add_Mant32Exp( ONE_IN_Q30, 1, L_negate( var2_sq ), exp_var2_sq, &final_exp_B ); var2_sqrt = Sqrt32( one_minus_var2_sq, &final_exp_B ); - var2_cos = BASOP_util_atan2( var2_sqrt, var2, final_exp_B - ( Q31 - ( Q_planeCrossingVec + Q30 - Q31 ) ) ); // Q13 + var2_cos = BASOP_util_atan2( var2_sqrt, var2, sub( final_exp_B, sub( Q31, add( Q_planeCrossingVec, Q30 - Q31 ) ) ) ); // Q13 final_exp = BASOP_Util_Add_MantExp( angleCmp_fx, Q15 - Q13, var2_cos, Q15 - Q13, &angleCmp_fx ); @@ -3818,7 +3833,7 @@ static ivas_error formulate_half_sphere_connections_fx( move16(); move16(); var_a = BASOP_Util_Add_Mant32Exp( cmp_arc_fx, Q31 - Q29, L_negate( L_deposit_h( angleCmp_fx ) ), final_exp, &sub_exp ); - comp1 = BASOP_Util_Cmp_Mant32Exp( L_abs( var_a ), sub_exp, 21474836, 0 ); + comp1 = BASOP_Util_Cmp_Mant32Exp( L_abs( var_a ), sub_exp, 21474836 /* 0.01f in Q31 */, 0 ); if ( EQ_16( comp1, -1 ) ) { @@ -3839,13 +3854,13 @@ static ivas_error formulate_half_sphere_connections_fx( move16(); connections[*connection_write_index][1] = chB; move16(); - connection_arc_fx[*connection_write_index] = new_arc_fx; // Q29 + connection_arc_fx[*connection_write_index] = new_arc_fx; /* Q29 */ move16(); - connection_cross_fx[*connection_write_index][0] = new_cross_fx[0]; + connection_cross_fx[*connection_write_index][0] = new_cross_fx[0]; /* Q29 */ move16(); - connection_cross_fx[*connection_write_index][1] = new_cross_fx[1]; + connection_cross_fx[*connection_write_index][1] = new_cross_fx[1]; /* Q29 */ move16(); - connection_cross_fx[*connection_write_index][2] = new_cross_fx[2]; + connection_cross_fx[*connection_write_index][2] = new_cross_fx[2]; /* Q29 */ move16(); *connection_write_index = add( *connection_write_index, 1 ); } @@ -4013,15 +4028,15 @@ static ivas_error formulate_half_sphere_connections( #ifdef IVAS_FLOAT_FIXED static Word16 determine_non_crossing_planes_fx( - const Word16 num_speaker_nodes, /* i : number of speaker nodes */ - const VBAP_SPEAKER_NODE *node_data, /* i : speaker node data */ - Word32 *non_crossing_plane_elevation_deg_fx /* o : vector of non-crossing plane elevations */ + const Word16 num_speaker_nodes, /* i : number of speaker nodes */ + const VBAP_SPEAKER_NODE *node_data, /* i : speaker node data */ + Word32 *non_crossing_plane_elevation_deg_fx /* o : vector of non-crossing plane elevations Q14 */ ) { - Word32 next_ele_check_fx; - Word32 ele_check_fx; - Word32 max_gap_fx; - Word32 gap_to_next_ls_fx; + Word32 next_ele_check_fx; /* Q14 */ + Word32 ele_check_fx; /* Q14 */ + Word32 max_gap_fx; /* Q14 */ + Word32 gap_to_next_ls_fx; /* Q14 */ Word16 ch, ch_cmp; Word16 num_planes; @@ -4046,7 +4061,7 @@ static Word16 determine_non_crossing_planes_fx( tmp2 = L_sub( next_ele_check_fx, 16 /*VBAP_EPSILON in Q14*/ ); test(); test(); - IF( ( node_data[ch].group != SPEAKER_NODE_HORIZONTAL ) && GT_32( L_shr( node_data[ch].ele_deg_fx, 8 ), tmp1 ) && LT_32( L_shr( node_data[ch].ele_deg_fx, 8 ), tmp2 ) ) + IF( NE_32( node_data[ch].group, SPEAKER_NODE_HORIZONTAL ) && GT_32( L_shr( node_data[ch].ele_deg_fx, 8 ), tmp1 ) && LT_32( L_shr( node_data[ch].ele_deg_fx, 8 ), tmp2 ) ) { next_ele_check_fx = L_shr( node_data[ch].ele_deg_fx, 8 ); // shift due to comparision with 90.0f } @@ -4098,7 +4113,7 @@ static Word16 determine_non_crossing_planes_fx( test(); IF( LT_32( max_gap_fx, 2293776 /*Q14*/ ) && max_gap_fx > 0 ) { - non_crossing_plane_elevation_deg_fx[num_planes] = ele_check_fx; // q14 + non_crossing_plane_elevation_deg_fx[num_planes] = ele_check_fx; /* Q14 */ move32(); num_planes = add( num_planes, 1 ); IF( EQ_16( num_planes, VBAP_MAX_PLANES ) ) diff --git a/lib_rend/lib_rend.c b/lib_rend/lib_rend.c index a178953ba..90ac02ce1 100644 --- a/lib_rend/lib_rend.c +++ b/lib_rend/lib_rend.c @@ -133,7 +133,7 @@ typedef struct #ifndef IVAS_FLOAT_FIXED float gain; /* Linear, not in dB */ #else - Word32 gain_fx; /* Linear, not in dB */ + Word32 gain_fx; /* Linear, not in dB Q30 */ #endif rendering_context ctx; Word32 numNewSamplesPerChannel; /* Used to keep track how much new audio was fed before rendering current frame */ @@ -164,7 +164,7 @@ typedef struct rotation_matrix_fx rot_mat_prev_fx; #endif pan_vector prev_pan_gains; - int8_t firstFrameRendered; + Word8 firstFrameRendered; #ifndef IVAS_FLOAT_FIXED float *bufferData; #endif @@ -174,10 +174,10 @@ typedef struct float nonDiegeticPanGain; #endif #ifdef IVAS_FLOAT_FIXED - Word32 nonDiegeticPanGain_fx; + Word32 nonDiegeticPanGain_fx; /* Q31 */ #endif OMASA_ANA_HANDLE hOMasa; - uint16_t total_num_objects; + UWord16 total_num_objects; #ifdef IVAS_FLOAT_FIXED Word32 ism_metadata_delay_ms_fx; /* Q0 */ #else @@ -210,13 +210,13 @@ typedef struct Word16 numLfeChannels; bool pan_lfe; // float lfeInputGain; - Word32 lfeInputGain_fx; + Word32 lfeInputGain_fx; /* Q31 */ // float lfeOutputAzimuth; Word16 lfeOutputAzimuth_fx; // float lfeOutputElevation; Word16 lfeOutputElevation_fx; // IVAS_REND_LfePanMtx lfePanMtx; - IVAS_REND_LfePanMtx_fx lfePanMtx_fx; + IVAS_REND_LfePanMtx_fx lfePanMtx_fx; /* Q31 */ } lfe_routing; #else typedef struct @@ -236,16 +236,22 @@ typedef struct /* Full panning matrix. 1st index is input channel, 2nd index is output channel. All LFE channels should be included, both for inputs and outputs */ +#ifndef IVAS_FLOAT_FIXED pan_matrix panGains; - pan_matrix_fx panGains_fx; +#else + pan_matrix_fx panGains_fx; /* Q31 */ +#endif LSSETUP_CUSTOM_STRUCT customLsInput; EFAP_WRAPPER efapInWrapper; TDREND_WRAPPER tdRendWrapper; CREND_WRAPPER_HANDLE crendWrapper; REVERB_HANDLE hReverb; +#ifndef IVAS_FLOAT_FIXED rotation_gains rot_gains_prev; +#else rotation_gains_Word32 rot_gains_prev_fx; +#endif Word16 nonDiegeticPan; Word32 nonDiegeticPanGain_fx; lfe_routing lfeRouting; @@ -253,7 +259,7 @@ typedef struct #ifndef IVAS_FLOAT_FIXED float *bufferData; #endif - int16_t binauralDelaySmp; + Word16 binauralDelaySmp; #ifndef IVAS_FLOAT_FIXED float nonDiegeticPanGain; float *lfeDelayBuffer; @@ -292,12 +298,13 @@ typedef struct // pan_matrix hoaDecMtx; pan_matrix_fx hoaDecMtx_fx; CREND_WRAPPER_HANDLE crendWrapper; - rotation_gains rot_gains_prev; - rotation_gains_fx rot_gains_prev_fx; #ifndef IVAS_FLOAT_FIXED + rotation_gains rot_gains_prev; float *bufferData; -#endif +#else + rotation_gains_fx rot_gains_prev_fx; Word32 *bufferData_fx; +#endif DIRAC_ANA_HANDLE hDirAC; } input_sba; #else @@ -397,7 +404,7 @@ static void intermidiate_ext_dirac_render( *-------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED static ivas_error allocateInputBaseBufferData_fx( - Word32 **data, + Word32 **data, /* Qx */ const Word16 data_size ) { *data = (Word32 *) malloc( data_size * sizeof( Word32 ) ); @@ -424,7 +431,7 @@ static ivas_error allocateInputBaseBufferData( #endif #ifdef IVAS_FLOAT_FIXED static void freeInputBaseBufferData_fx( - Word32 **data ) + Word32 **data /* Qx */ ) { IF( *data != NULL ) { @@ -449,7 +456,7 @@ static void freeInputBaseBufferData( #endif #ifdef IVAS_FLOAT_FIXED static ivas_error allocateMcLfeDelayBuffer_fx( - Word32 **lfeDelayBuffer, + Word32 **lfeDelayBuffer, /* Qx */ const Word16 data_size ) { *lfeDelayBuffer = (Word32 *) malloc( data_size * sizeof( Word32 ) ); @@ -477,7 +484,7 @@ static ivas_error allocateMcLfeDelayBuffer( #endif #ifdef IVAS_FLOAT_FIXED static void freeMcLfeDelayBuffer_fx( - Word32 **lfeDelayBuffer ) + Word32 **lfeDelayBuffer /* Qx */ ) { IF( *lfeDelayBuffer != NULL ) { @@ -521,11 +528,6 @@ static IVAS_QUATERNION quaternionInit_fx( move16(); move16(); -#ifdef IVAS_FLOAT_FIXED_TO_BE_REMOVED - q.w = 1.0f; - q.x = q.y = q.z = 0.0f; -#endif - return q; } #else @@ -651,7 +653,7 @@ static void accumulate2dArrayToBuffer( /*! r: number of clipped output samples */ static Word32 limitRendererOutput_fx( IVAS_LIMITER_HANDLE hLimiter, /* i/o: limiter struct handle */ - Word32 *output, /* i/o: I/O buffer */ + Word32 *output, /* i/o: I/O buffer Q(q_factor) */ const Word16 output_frame, /* i : number of samples per channel in the buffer */ const Word32 threshold, /* i : signal amplitude above which limiting starts to be applied */ Word16 q_factor ) /* i : q factor of output samples */ @@ -1208,7 +1210,7 @@ static LSSETUP_CUSTOM_STRUCT defaultCustomLs( #ifdef IVAS_FLOAT_FIXED static ivas_error getSpeakerAzimuths_fx( AUDIO_CONFIG config, - const Word32 **azimuths ) + const Word32 **azimuths /* Q22 */ ) { SWITCH( config ) { @@ -1279,7 +1281,7 @@ static ivas_error getSpeakerAzimuths( #ifdef IVAS_FLOAT_FIXED static ivas_error getSpeakerElevations_fx( AUDIO_CONFIG config, - const Word32 **elevations ) + const Word32 **elevations /* Q22 */ ) { SWITCH( config ) { @@ -1514,8 +1516,8 @@ static ivas_error getNumNonLfeChannelsInSpeakerLayout( static ivas_error getMcConfigValues_fx( AUDIO_CONFIG inConfig, const LSSETUP_CUSTOM_STRUCT *pInCustomLs, - const Word32 **azimuth, - const Word32 **elevation, + const Word32 **azimuth, /* Q22 */ + const Word32 **elevation, /* Q22 */ Word16 *lfe_idx, Word16 *is_planar ) { @@ -1666,8 +1668,8 @@ static ivas_error initEfap( const LSSETUP_CUSTOM_STRUCT *pCustomLsOut ) { ivas_error error; - const Word32 *azimuths; - const Word32 *elevations; + const Word32 *azimuths; /* Q22 */ + const Word32 *elevations; /* Q22 */ Word16 numNonLfeChannels; test(); @@ -1798,11 +1800,11 @@ static ivas_error initEfap( #ifdef IVAS_FLOAT_FIXED static ivas_error getEfapGains_fx( EFAP_WRAPPER efapWrapper, - const Word32 azi, - const Word32 ele, - pan_vector_fx panGains ) + const Word32 azi, /* Q22 */ + const Word32 ele, /* Q22 */ + pan_vector_fx panGains /* Q31 */ ) { - pan_vector_fx tmpPanGains; /* tmp pan gain buffer without LFE channels */ + pan_vector_fx tmpPanGains; /* tmp pan gain buffer without LFE channels */ /* Q30 */ Word32 *readPtr; Word16 i; Word16 lfeCount; @@ -1826,7 +1828,7 @@ static ivas_error getEfapGains_fx( { panGains[i] = 0; move32(); - ++lfeCount; + lfeCount = add( lfeCount, 1 ); } ELSE { @@ -1947,7 +1949,7 @@ static ivas_error initHeadRotation_fx( IVAS_REND_HANDLE hIvasRend ) { Word16 i, crossfade_len; - Word32 tmp_fx; + Word32 tmp_fx; /* Q31 */ ivas_error error; /* Head rotation is enabled by default */ @@ -2117,7 +2119,7 @@ static void initRotGainsWord32_fx( return; } -#endif +#else static void initRotGains( rotation_gains rot_gains ) { @@ -2132,6 +2134,7 @@ static void initRotGains( return; } +#endif #ifdef IVAS_FLOAT_FIXED static void initRendInputBase_fx( input_base *inputBase, @@ -2232,6 +2235,7 @@ static IVAS_ISM_METADATA defaultObjectPosition( } #endif // IVAS_FLOAT_FIXED +#ifndef IVAS_FLOAT_FIXED static int8_t checkObjectPositionChanged( IVAS_ISM_METADATA *currentPos, IVAS_ISM_METADATA *previousPos ) @@ -2239,8 +2243,7 @@ static int8_t checkObjectPositionChanged( return !( fabs( currentPos->azimuth - previousPos->azimuth ) < EPSILON && fabs( currentPos->elevation - previousPos->elevation ) < EPSILON ); } - -#ifdef IVAS_FLOAT_FIXED +#else static Word8 checkObjectPositionChanged_fx( IVAS_ISM_METADATA *currentPos, IVAS_ISM_METADATA *previousPos ) @@ -2409,6 +2412,7 @@ static ivas_error setRendInputActiveIsm( initRendInputBase_fx( &inputIsm->base, inConfig, id, rendCtx, inputIsm->bufferData_fx, MAX_BUFFER_LENGTH ); inputIsm->firstFrameRendered = FALSE; + move16(); inputIsm->currentPos = defaultObjectPosition(); inputIsm->previousPos = defaultObjectPosition(); @@ -2662,7 +2666,7 @@ static void copyLsConversionMatrixToPanMatrix_fx( } ELSE { - panMatrix[inCh][outCh] = L_shl( lsConvMatrix[i].value, 1 ); + panMatrix[inCh][outCh] = L_shl( lsConvMatrix[i].value, 1 ); /* Q30 + Q1 = Q31 */ } move32(); } @@ -2670,7 +2674,6 @@ static void copyLsConversionMatrixToPanMatrix_fx( return; } #else - static void copyLsConversionMatrixToPanMatrix( const LS_CONVERSION_MATRIX *lsConvMatrix, pan_matrix panMatrix ) @@ -2695,6 +2698,8 @@ static void copyLsConversionMatrixToPanMatrix( return; } #endif + +#ifndef IVAS_FLOAT_FIXED static void setZeroPanMatrix( pan_matrix panMatrix ) { @@ -2707,7 +2712,7 @@ static void setZeroPanMatrix( return; } -#ifdef IVAS_FLOAT_FIXED +#else static void setZeroPanMatrix_fx( pan_matrix_fx panMatrix ) { @@ -2721,6 +2726,7 @@ static void setZeroPanMatrix_fx( return; } #endif + #ifdef IVAS_FLOAT_FIXED /* Note: this only sets non-zero elements, call setZeroPanMatrix() to init first. */ static void fillIdentityPanMatrix_fx( @@ -2850,7 +2856,7 @@ static ivas_error initMcPanGainsWithEfap_fx( Word16 i; Word16 numNonLfeInChannels; Word16 inLfeChIdx, outChIdx; - const Word32 *spkAzi, *spkEle; + const Word32 *spkAzi, *spkEle; /* Q22 */ ivas_error error; IF( NE_32( inputMc->base.inConfig, IVAS_AUDIO_CONFIG_LS_CUSTOM ) ) @@ -2895,14 +2901,14 @@ static ivas_error initMcPanGainsWithEfap_fx( { IF( EQ_16( i, inLfeChIdx ) ) { - ++outChIdx; + outChIdx = add( outChIdx, 1 ); } IF( NE_32( ( error = getEfapGains_fx( *inputMc->base.ctx.pEfapOutWrapper, spkAzi[i], spkEle[i], inputMc->panGains_fx[outChIdx] ) ), IVAS_ERR_OK ) ) { return error; } - ++outChIdx; + outChIdx = add( outChIdx, 1 ); } test(); @@ -3085,6 +3091,7 @@ static ivas_error initMcPanGainsWithMonoOut_fx( /* ls_conversion_cicpX_stereo contains gains for side speakers. * These should be skipped with 5.1+X inputs. */ skipSideSpeakers = false; + move16(); test(); if ( EQ_32( inputMc->base.inConfig, IVAS_AUDIO_CONFIG_5_1_2 ) || EQ_32( inputMc->base.inConfig, IVAS_AUDIO_CONFIG_5_1_4 ) ) { @@ -3121,7 +3128,7 @@ static ivas_error initMcPanGainsWithMonoOut_fx( inputMc->panGains_fx[writeIdx][0] = L_shl( ls_conversion_cicpX_mono_fx[readIdx][0], 1 ); // Q31 } move32(); - ++readIdx; + readIdx = add( readIdx, 1 ); } } @@ -3198,9 +3205,9 @@ static ivas_error initMcPanGainsWithStereoLookup_fx( * Use gains for center CICP speaker and return early. */ IF( EQ_32( inputMc->base.inConfig, IVAS_AUDIO_CONFIG_MONO ) ) { - inputMc->panGains_fx[0][0] = L_shl( ls_conversion_cicpX_stereo_fx[2][0], 1 ); // Q31 + inputMc->panGains_fx[0][0] = L_shl( ls_conversion_cicpX_stereo_fx[2][0], 1 ); /* Q30 + Q1 = Q31 */ move32(); - inputMc->panGains_fx[0][1] = L_shl( ls_conversion_cicpX_stereo_fx[2][1], 1 ); // Q31 + inputMc->panGains_fx[0][1] = L_shl( ls_conversion_cicpX_stereo_fx[2][1], 1 ); /* Q30 + Q1 = Q31 */ move32(); return IVAS_ERR_OK; } @@ -3237,7 +3244,7 @@ static ivas_error initMcPanGainsWithStereoLookup_fx( } ELSE { - inputMc->panGains_fx[writeIdx][0] = L_shl( ls_conversion_cicpX_stereo_fx[readIdx][0], 1 ); + inputMc->panGains_fx[writeIdx][0] = L_shl( ls_conversion_cicpX_stereo_fx[readIdx][0], 1 ); /* Q30 + Q1 = Q31 */ } move32(); @@ -3247,10 +3254,10 @@ static ivas_error initMcPanGainsWithStereoLookup_fx( } ELSE { - inputMc->panGains_fx[writeIdx][1] = L_shl( ls_conversion_cicpX_stereo_fx[readIdx][1], 1 ); + inputMc->panGains_fx[writeIdx][1] = L_shl( ls_conversion_cicpX_stereo_fx[readIdx][1], 1 ); /* Q30 + Q1 = Q31 */ } move32(); - ++readIdx; + readIdx = add( readIdx, 1 ); } return IVAS_ERR_OK; @@ -3449,7 +3456,7 @@ static ivas_error updateLfePanGainsForMcOut( } /* linear input gain */ - v_multc_fixed( inputMc->lfeRouting.lfePanMtx_fx[i], inputMc->lfeRouting.lfeInputGain_fx, inputMc->lfeRouting.lfePanMtx_fx[i], numOutChannels ); + v_multc_fixed( inputMc->lfeRouting.lfePanMtx_fx[i], inputMc->lfeRouting.lfeInputGain_fx, inputMc->lfeRouting.lfePanMtx_fx[i], numOutChannels ); /* Q31 */ } return error; @@ -3528,7 +3535,7 @@ static ivas_error updateLfePanGainsForAmbiOut( ivas_dirac_dec_get_response_fx( inputMc->lfeRouting.lfeOutputAzimuth_fx, inputMc->lfeRouting.lfeOutputElevation_fx, inputMc->lfeRouting.lfePanMtx_fx[i], outAmbiOrder, Q29 ); /* linear input gain */ - v_multc_fixed( inputMc->lfeRouting.lfePanMtx_fx[i], inputMc->lfeRouting.lfeInputGain_fx, inputMc->lfeRouting.lfePanMtx_fx[i], IVAS_MAX_OUTPUT_CHANNELS ); + v_multc_fixed( inputMc->lfeRouting.lfePanMtx_fx[i], inputMc->lfeRouting.lfeInputGain_fx, inputMc->lfeRouting.lfePanMtx_fx[i], IVAS_MAX_OUTPUT_CHANNELS ); /* Q31 */ } return error; @@ -3606,7 +3613,7 @@ static ivas_error updateMcPanGainsForMcOut( } ELSE { - inputMc->panGains_fx[0][0] = L_add( L_shr( inputMc->nonDiegeticPanGain_fx, 1 ), ONE_IN_Q30 ); + inputMc->panGains_fx[0][0] = L_add( L_shr( inputMc->nonDiegeticPanGain_fx, 1 ), ONE_IN_Q30 /* 0.5f in Q31 */ ); /* Q31 */ } move32(); inputMc->panGains_fx[0][1] = L_sub( ONE_IN_Q31, inputMc->panGains_fx[0][0] ); @@ -3713,7 +3720,7 @@ static ivas_error updateMcPanGainsForAmbiOut( { Word16 ch_in, ch_out, lfeIdx, i; Word16 numNonLfeInChannels, outAmbiOrder; - const Word32 *spkAzi_fx, *spkEle_fx; + const Word32 *spkAzi_fx, *spkEle_fx; /* Q22 */ ivas_error error; IF( NE_32( ( error = getAmbisonicsOrder_fx( outConfig, &outAmbiOrder ) ), IVAS_ERR_OK ) ) @@ -3768,11 +3775,11 @@ static ivas_error updateMcPanGainsForAmbiOut( } ELSE { - inputMc->panGains_fx[ch_out][i] = L_shl( temp, 2 ); + inputMc->panGains_fx[ch_out][i] = L_shl( temp, 2 ); /* Q29 + Q2 = Q31 */ move32(); } } - ++ch_in; + ch_in = add( ch_in, 1 ); } } ELSE @@ -3816,11 +3823,11 @@ static ivas_error updateMcPanGainsForAmbiOut( } ELSE { - inputMc->panGains_fx[ch_out][i] = L_shl( temp, 2 ); + inputMc->panGains_fx[ch_out][i] = L_shl( temp, 2 ); /* Q29 + Q2 = Q31 */ move32(); } } - ++ch_in; + ch_in = add( ch_in, 1 ); } } @@ -4053,11 +4060,13 @@ static ivas_error initMcBinauralRendering( IF( EQ_16( inConfig, IVAS_AUDIO_CONFIG_LS_CUSTOM ) && NE_16( outConfig, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) ) { useTDRend = TRUE; + move16(); } ELSE IF( ( EQ_16( inConfig, IVAS_AUDIO_CONFIG_5_1 ) || EQ_16( inConfig, IVAS_AUDIO_CONFIG_7_1 ) ) && ( inputMc->base.ctx.pHeadRotData->headRotEnabled ) ) { useTDRend = TRUE; + move16(); } } @@ -4177,8 +4186,8 @@ static ivas_error initMcBinauralRendering( Word16 exp = 0; move16(); Word16 var1 = BASOP_Util_Divide3232_Scale( *inputMc->base.ctx.pOutSampleRate, 1000000000, &exp ); - Word32 var2 = L_shr_r( Mpy_32_32( binauralDelayNs, L_deposit_h( var1 ) ), negate( exp ) ); // 31 + exp - inputMc->binauralDelaySmp = (Word16) var2; + Word32 var2 = L_shr_r( Mpy_32_32( binauralDelayNs, L_deposit_h( var1 ) ), negate( exp ) ); /* Q0 */ + inputMc->binauralDelaySmp = extract_l( var2 ); move16(); // inputMc->binauralDelaySmp = (int16_t) roundf( (float) binauralDelayNs * *inputMc->base.ctx.pOutSampleRate / 1000000000.f ); @@ -4406,6 +4415,7 @@ static lfe_routing defaultLfeRouting( case IVAS_AUDIO_CONFIG_LS_CUSTOM: FOR( i = 0; i < routing.numLfeChannels && i < customLsOut.num_lfe; ++i ) { + test(); routing.lfePanMtx_fx[i][customLsOut.lfe_idx[i]] = ONE_IN_Q31; move32(); } @@ -4507,7 +4517,6 @@ static ivas_error setRendInputActiveMc( } initRendInputBase_fx( &inputMc->base, inConfig, id, rendCtx, inputMc->bufferData_fx, MAX_BUFFER_LENGTH ); - setZeroPanMatrix( inputMc->panGains ); setZeroPanMatrix_fx( inputMc->panGains_fx ); inputMc->customLsInput = defaultCustomLs(); @@ -4516,7 +4525,6 @@ static ivas_error setRendInputActiveMc( inputMc->hReverb = NULL; inputMc->hMcMasa = NULL; - initRotGains( inputMc->rot_gains_prev ); initRotGainsWord32_fx( inputMc->rot_gains_prev_fx ); inputMc->lfeRouting = defaultLfeRouting( inConfig, inputMc->customLsInput, outConfig, *inputMc->base.ctx.pCustomLsOut ); set32_fx( inputMc->lfeDelayBuffer_fx, 0, MAX_BIN_DELAY_SAMPLES ); @@ -4747,7 +4755,7 @@ static ivas_error initSbaPanGainsForMcOut( { CONTINUE; /* nothing to be rendered to LFE */ } - inputSba->hoaDecMtx_fx[chInIdx][chOutIdx] = L_shl_sat( *readPtr++, 2 ); + inputSba->hoaDecMtx_fx[chInIdx][chOutIdx] = L_shl_sat( *readPtr++, Q2 ); /* Q29 + Q2 = Q31 */ move32(); } } @@ -4876,7 +4884,6 @@ static ivas_error updateSbaPanGains( rendering_context rendCtx; /* Reset to all zeros - some functions below only write non-zero elements. */ - // setZeroPanMatrix( inputSba->hoaDecMtx ); setZeroPanMatrix_fx( inputSba->hoaDecMtx_fx ); inConfig = inputSba->base.inConfig; @@ -5269,7 +5276,7 @@ static ivas_error setRendInputActiveMasa( } initRendInputBase_fx( &inputMasa->base, inConfig, id, rendCtx, inputMasa->bufferData_fx, MAX_BUFFER_LENGTH ); - IF( ( error = getAudioConfigNumChannels( inConfig, &numInChannels ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = getAudioConfigNumChannels( inConfig, &numInChannels ) ), IVAS_ERR_OK ) ) { return error; } @@ -5288,7 +5295,7 @@ static ivas_error setRendInputActiveMasa( temp = 2; } move16(); - IF( ( error = masaPrerendOpen_fx( &inputMasa->hMasaPrerend, temp, *( inputMasa->base.ctx.pOutSampleRate ) ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = masaPrerendOpen_fx( &inputMasa->hMasaPrerend, temp, *( inputMasa->base.ctx.pOutSampleRate ) ) ), IVAS_ERR_OK ) ) { return error; } @@ -5358,7 +5365,7 @@ ivas_error IVAS_REND_Open( const Word32 outputSampleRate, const AUDIO_CONFIG outConfig, const Word16 nonDiegeticPan, - const Word32 nonDiegeticPanGain, /*Q31*/ + const Word32 nonDiegeticPanGain, /* Q31 */ const Word16 num_subframes ) { Word16 i; @@ -5635,11 +5642,6 @@ static LSSETUP_CUSTOM_STRUCT makeCustomLsSetup( /* Copy layout description */ customLs.num_spk = rendCustomLsLayout.num_spk; move16(); - FOR( i = 0; i < rendCustomLsLayout.num_spk; i++ ) - { - customLs.ls_azimuth_fx[i] = (Word32) ( rendCustomLsLayout.azimuth[i] * ONE_IN_Q22 ); - customLs.ls_elevation_fx[i] = (Word32) ( rendCustomLsLayout.elevation[i] * ONE_IN_Q22 ); - } Copy32( rendCustomLsLayout.azimuth_fx, customLs.ls_azimuth_fx, rendCustomLsLayout.num_spk ); Copy32( rendCustomLsLayout.elevation_fx, customLs.ls_elevation_fx, rendCustomLsLayout.num_spk ); customLs.is_planar_setup = 1; @@ -6696,9 +6698,9 @@ ivas_error IVAS_REND_SetInputGain( } #else ivas_error IVAS_REND_SetInputGain_fx( - IVAS_REND_HANDLE hIvasRend, /* i/o: Renderer handle */ - const IVAS_REND_InputId inputId, /* i : ID of the input */ - const Word32 gain /* i : linear gain (not in dB) */ + IVAS_REND_HANDLE hIvasRend, /* i/o: Renderer handle */ + const IVAS_REND_InputId inputId, /* i : ID of the input */ + const Word32 gain /* i : linear gain (not in dB) Q30 */ ) { input_base *inputBase; @@ -6823,11 +6825,11 @@ ivas_error IVAS_REND_SetInputLfeMtx_fx( *-------------------------------------------------------------------*/ ivas_error IVAS_REND_SetInputLfePos_fx( - IVAS_REND_HANDLE hIvasRend, /* i/o: Renderer handle */ - const IVAS_REND_InputId inputId, /* i : ID of the input */ - const Word32 inputGain, /* i : Input gain to be applied to the LFE channel(s) */ - const Word16 outputAzimuth, /* i : Output azimuth position */ - const Word16 outputElevation /* i : Output elevation position */ + IVAS_REND_HANDLE hIvasRend, /* i/o: Renderer handle */ + const IVAS_REND_InputId inputId, /* i : ID of the input */ + const Word32 inputGain, /* i : Input gain to be applied to the LFE channel(s) Q31 */ + const Word16 outputAzimuth, /* i : Output azimuth position Q0 */ + const Word16 outputElevation /* i : Output elevation position Q0 */ ) { input_base *pInputBase; @@ -6854,11 +6856,11 @@ ivas_error IVAS_REND_SetInputLfePos_fx( pInputMc->lfeRouting.pan_lfe = true; move16(); - pInputMc->lfeRouting.lfeInputGain_fx = inputGain; // Q31 + pInputMc->lfeRouting.lfeInputGain_fx = inputGain; /* Q31 */ move32(); - pInputMc->lfeRouting.lfeOutputAzimuth_fx = (Word16) ( outputAzimuth ); // Q0 + pInputMc->lfeRouting.lfeOutputAzimuth_fx = outputAzimuth; /* Q0 */ move16(); - pInputMc->lfeRouting.lfeOutputElevation_fx = (Word16) ( outputElevation ); // Q0 + pInputMc->lfeRouting.lfeOutputElevation_fx = outputElevation; /* Q0 */ move16(); IF( NE_32( ( error = updateMcPanGains( pInputMc, hIvasRend->outputConfig ) ), IVAS_ERR_OK ) ) @@ -7160,6 +7162,13 @@ ivas_error IVAS_REND_GetDelay_fx( Word32 max_latency_ns; Word32 timescale_by_ns[7] = { 0, 17180, 34360, 0, 68719, 0, 103079 }; + move32(); + move32(); + move32(); + move32(); + move32(); + move32(); + move32(); /* Validate function arguments */ test(); @@ -7242,6 +7251,7 @@ ivas_error IVAS_REND_GetDelay_fx( IF( NE_32( hIvasRend->inputsMasa[i].base.inConfig, IVAS_AUDIO_CONFIG_INVALID ) ) { latency_ns = (Word32) ( IVAS_FB_DEC_DELAY_NS ); + move32(); max_latency_ns = L_max( max_latency_ns, latency_ns ); } } @@ -7508,7 +7518,9 @@ ivas_error IVAS_REND_FeedInputObjectMetadataToOMasa( /* Set position to OMasa struct */ hIvasRend->inputsIsm->hOMasa->ism_azimuth_fx[inputIndex] = objectPosition.azimuth_fx; + move32(); hIvasRend->inputsIsm->hOMasa->ism_elevation_fx[inputIndex] = objectPosition.elevation_fx; + move32(); return IVAS_ERR_OK; } @@ -7933,25 +7945,25 @@ ivas_error IVAS_REND_SetHeadRotation( rotQuat = headRot; } - Word32 updateRate_fx = 1677721600; // value is 200 in Q23 - rotQuat.w_fx = L_shl( rotQuat.w_fx, sub( Q29, rotQuat.q_fact ) ); - rotQuat.x_fx = L_shl( rotQuat.x_fx, sub( Q29, rotQuat.q_fact ) ); - rotQuat.y_fx = L_shl( rotQuat.y_fx, sub( Q29, rotQuat.q_fact ) ); - rotQuat.z_fx = L_shl( rotQuat.z_fx, sub( Q29, rotQuat.q_fact ) ); + Word32 updateRate_fx = 1677721600; // value is 200 in Q23 + rotQuat.w_fx = L_shl( rotQuat.w_fx, sub( Q29, rotQuat.q_fact ) ); /* Q29 */ + rotQuat.x_fx = L_shl( rotQuat.x_fx, sub( Q29, rotQuat.q_fact ) ); /* Q29 */ + rotQuat.y_fx = L_shl( rotQuat.y_fx, sub( Q29, rotQuat.q_fact ) ); /* Q29 */ + rotQuat.z_fx = L_shl( rotQuat.z_fx, sub( Q29, rotQuat.q_fact ) ); /* Q29 */ move32(); move32(); move32(); move32(); - hIvasRend->headRotData.hOrientationTracker->refRot.w_fx = L_shl( hIvasRend->headRotData.hOrientationTracker->refRot.w_fx, sub( Q29, hIvasRend->headRotData.hOrientationTracker->refRot.q_fact ) ); - hIvasRend->headRotData.hOrientationTracker->refRot.x_fx = L_shl( hIvasRend->headRotData.hOrientationTracker->refRot.x_fx, Q29 - hIvasRend->headRotData.hOrientationTracker->refRot.q_fact ); - hIvasRend->headRotData.hOrientationTracker->refRot.y_fx = L_shl( hIvasRend->headRotData.hOrientationTracker->refRot.y_fx, Q29 - hIvasRend->headRotData.hOrientationTracker->refRot.q_fact ); - hIvasRend->headRotData.hOrientationTracker->refRot.z_fx = L_shl( hIvasRend->headRotData.hOrientationTracker->refRot.z_fx, Q29 - hIvasRend->headRotData.hOrientationTracker->refRot.q_fact ); - hIvasRend->headRotData.hOrientationTracker->absAvgRot.w_fx = L_shl( hIvasRend->headRotData.hOrientationTracker->absAvgRot.w_fx, Q29 - hIvasRend->headRotData.hOrientationTracker->absAvgRot.q_fact ); - hIvasRend->headRotData.hOrientationTracker->absAvgRot.x_fx = L_shl( hIvasRend->headRotData.hOrientationTracker->absAvgRot.x_fx, Q29 - hIvasRend->headRotData.hOrientationTracker->absAvgRot.q_fact ); - hIvasRend->headRotData.hOrientationTracker->absAvgRot.y_fx = L_shl( hIvasRend->headRotData.hOrientationTracker->absAvgRot.y_fx, Q29 - hIvasRend->headRotData.hOrientationTracker->absAvgRot.q_fact ); - hIvasRend->headRotData.hOrientationTracker->absAvgRot.z_fx = L_shl( hIvasRend->headRotData.hOrientationTracker->absAvgRot.z_fx, Q29 - hIvasRend->headRotData.hOrientationTracker->absAvgRot.q_fact ); + hIvasRend->headRotData.hOrientationTracker->refRot.w_fx = L_shl( hIvasRend->headRotData.hOrientationTracker->refRot.w_fx, sub( Q29, hIvasRend->headRotData.hOrientationTracker->refRot.q_fact ) ); /* Q29 */ + hIvasRend->headRotData.hOrientationTracker->refRot.x_fx = L_shl( hIvasRend->headRotData.hOrientationTracker->refRot.x_fx, sub( Q29, hIvasRend->headRotData.hOrientationTracker->refRot.q_fact ) ); /* Q29 */ + hIvasRend->headRotData.hOrientationTracker->refRot.y_fx = L_shl( hIvasRend->headRotData.hOrientationTracker->refRot.y_fx, sub( Q29, hIvasRend->headRotData.hOrientationTracker->refRot.q_fact ) ); /* Q29 */ + hIvasRend->headRotData.hOrientationTracker->refRot.z_fx = L_shl( hIvasRend->headRotData.hOrientationTracker->refRot.z_fx, sub( Q29, hIvasRend->headRotData.hOrientationTracker->refRot.q_fact ) ); /* Q29 */ + hIvasRend->headRotData.hOrientationTracker->absAvgRot.w_fx = L_shl( hIvasRend->headRotData.hOrientationTracker->absAvgRot.w_fx, sub( Q29, hIvasRend->headRotData.hOrientationTracker->absAvgRot.q_fact ) ); /* Q29 */ + hIvasRend->headRotData.hOrientationTracker->absAvgRot.x_fx = L_shl( hIvasRend->headRotData.hOrientationTracker->absAvgRot.x_fx, sub( Q29, hIvasRend->headRotData.hOrientationTracker->absAvgRot.q_fact ) ); /* Q29 */ + hIvasRend->headRotData.hOrientationTracker->absAvgRot.y_fx = L_shl( hIvasRend->headRotData.hOrientationTracker->absAvgRot.y_fx, sub( Q29, hIvasRend->headRotData.hOrientationTracker->absAvgRot.q_fact ) ); /* Q29 */ + hIvasRend->headRotData.hOrientationTracker->absAvgRot.z_fx = L_shl( hIvasRend->headRotData.hOrientationTracker->absAvgRot.z_fx, sub( Q29, hIvasRend->headRotData.hOrientationTracker->absAvgRot.q_fact ) ); /* Q29 */ move32(); move32(); @@ -8504,8 +8516,8 @@ static void renderBufferChannelLerp( static void renderBufferChannelLerp_fx( const IVAS_REND_AudioBuffer inAudio, const Word32 inChannelIdx, - const Word32 *const gainsCurrent, - const Word32 *const gainsPrev, + const Word32 *const gainsCurrent, /* Q31 */ + const Word32 *const gainsPrev, /* Q31 */ IVAS_REND_AudioBuffer outAudio ) { const Word32 *inSmpl; @@ -8515,8 +8527,8 @@ static void renderBufferChannelLerp_fx( Word32 i; const Word32 *lastInSmpl; Word16 outChnlIdx; - Word32 currentGain; - Word32 previousGain; + Word32 currentGain; /* Q31 */ + Word32 previousGain; /* Q31 */ /* Pointer to behind last input sample */ lastInSmpl = getSmplPtr_fx( inAudio, inChannelIdx, inAudio.config.numSamplesPerChannel ); @@ -8524,9 +8536,17 @@ static void renderBufferChannelLerp_fx( FOR( outChnlIdx = 0; outChnlIdx < outAudio.config.numChannels; ++outChnlIdx ) { currentGain = gainsCurrent[outChnlIdx]; - previousGain = gainsPrev == NULL ? 0 : gainsPrev[outChnlIdx]; - move32(); move32(); + if ( gainsPrev == NULL ) + { + previousGain = 0; + move32(); + } + else + { + previousGain = gainsPrev[outChnlIdx]; + move32(); + } /* Process current output channel only if applying non-zero gains */ test(); @@ -8621,7 +8641,7 @@ static void renderBufferChannelLerp_fx( static void renderBufferChannel_fx( const IVAS_REND_AudioBuffer inAudio, const Word32 inChannelIdx, - const Word32 *const outputGains, + const Word32 *const outputGains, /* Q31 */ IVAS_REND_AudioBuffer outAudio ) { renderBufferChannelLerp_fx( inAudio, inChannelIdx, outputGains, NULL, outAudio ); @@ -8656,7 +8676,7 @@ static ivas_error chooseCrossfade( #else static ivas_error chooseCrossfade_fx( const IVAS_REND_HeadRotData *headRotData, - const Word32 **pCrossfade ) + const Word32 **pCrossfade /* Q31 */ ) { *pCrossfade = headRotData->crossfade_fx; @@ -8679,10 +8699,10 @@ static ivas_error rotateFrameMc_fx( { Word16 i; Word16 j; - const Word32 *crossfade; + const Word32 *crossfade; /* Q31 */ Word16 num_subframes; Word16 subframe_idx, subframe_len; - Word32 azimuth_fx, elevation_fx; + Word32 azimuth_fx, elevation_fx; /* Q22 */ Word16 is_planar_setup, lfe_idx; Word16 nchan; Word16 ch_in, ch_out; @@ -8691,10 +8711,10 @@ static ivas_error rotateFrameMc_fx( const Word32 *ls_azimuth, *ls_elevation; rotation_matrix_fx Rmat_fx; rotation_gains_Word32 gains; - Word32 tmp_gains[MAX_INPUT_CHANNELS]; + Word32 tmp_gains[MAX_INPUT_CHANNELS]; /* Q30 */ ivas_error error; push_wmops( "rotateFrameMc_fx" ); - IF( NE_32( ( error = chooseCrossfade_fx( headRotData, &crossfade ) ), IVAS_ERR_OK ) ) // Q31 + IF( NE_32( ( error = chooseCrossfade_fx( headRotData, &crossfade ) ), IVAS_ERR_OK ) ) { return error; } @@ -8770,10 +8790,8 @@ static ivas_error rotateFrameMc_fx( } /* input channel index without LFE */ - ch_in_woLFE = ( ( GT_16( lfe_idx, 0 ) ) && ( GE_16( ch_in, lfe_idx ) ) ) ? sub( ch_in, 1 ) : ch_in; - test(); - IF( ( GT_16( lfe_idx, 0 ) ) && ( GE_16( ch_in, lfe_idx ) ) ) + IF( ( lfe_idx > 0 ) && ( GE_16( ch_in, lfe_idx ) ) ) { ch_in_woLFE = sub( ch_in, 1 ); } @@ -8824,14 +8842,14 @@ static ivas_error rotateFrameMc_fx( { FOR( ch_in = 0; ch_in < nchan; ch_in++ ) { - writePtr = getSmplPtr_fx( outAudio, ch_out, imult1616( subframe_idx, subframe_len ) ); - readPtr = getSmplPtr_fx( inAudio, ch_in, imult1616( subframe_idx, subframe_len ) ); + writePtr = getSmplPtr_fx( outAudio, ch_out, imult1616( subframe_idx, subframe_len ) ); /* Qx */ + readPtr = getSmplPtr_fx( inAudio, ch_in, imult1616( subframe_idx, subframe_len ) ); /* Qx */ /* crossfade with previous rotation gains */ FOR( i = 0; i < subframe_len; i++ ) { *writePtr = - L_add( *writePtr, L_add( Mpy_32_32( ( *readPtr ), Mpy_32_32( ( ONE_IN_Q31 - crossfade[i] ), gains_prev[ch_in][ch_out] ) ), - Mpy_32_32( ( *readPtr ), Mpy_32_32( crossfade[i], gains[ch_in][ch_out] ) ) ) ); // Qinp -1 + L_add( *writePtr, L_add( Mpy_32_32( ( *readPtr ), Mpy_32_32( L_sub( ONE_IN_Q31, crossfade[i] ), gains_prev[ch_in][ch_out] ) ), + Mpy_32_32( ( *readPtr ), Mpy_32_32( crossfade[i], gains[ch_in][ch_out] ) ) ) ); /* Qx - 1 */ move32(); readPtr++; writePtr++; @@ -8997,28 +9015,28 @@ static ivas_error rotateFrameMc( #ifdef IVAS_FLOAT_FIXED static ivas_error rotateFrameSba_fx( - IVAS_REND_AudioBuffer inAudio, /* i : Input Audio buffer */ - const AUDIO_CONFIG inConfig, /* i : Input Audio config */ - const IVAS_REND_HeadRotData *headRotData, /* i : Head rotation data */ + IVAS_REND_AudioBuffer inAudio, /* i : Input Audio buffer */ + const AUDIO_CONFIG inConfig, /* i : Input Audio config */ + const IVAS_REND_HeadRotData *headRotData, /* i : Head rotation data */ const COMBINED_ORIENTATION_HANDLE *hCombinedOrientationData, /* i : Combined head and external orientations */ - Word16 gains_prev[MAX_INPUT_CHANNELS][MAX_INPUT_CHANNELS], /* i/o: Previous frame rotation gains */ - IVAS_REND_AudioBuffer outAudio /* o : Output Audio buffer */ + Word16 gains_prev[MAX_INPUT_CHANNELS][MAX_INPUT_CHANNELS], /* i/o: Previous frame rotation gains Q14 */ + IVAS_REND_AudioBuffer outAudio /* o : Output Audio buffer */ ) { Word16 i, l, n, m; Word16 m1, m2; Word16 shd_rot_max_order; - const Word32 *crossfade; + const Word32 *crossfade; /* Q31 */ Word16 num_subframes; Word16 subframe_idx, subframe_len; Word32 *writePtr; Word32 tmpRot[2 * HEADROT_ORDER + 1]; - Word16 gains[HEADROT_SHMAT_DIM][HEADROT_SHMAT_DIM]; + Word16 gains[HEADROT_SHMAT_DIM][HEADROT_SHMAT_DIM]; /* Q14 */ Word32 temp; - Word32 Rmat[3][3]; + Word32 Rmat[3][3]; /* Q30 */ ivas_error error; Word16 idx, exp; - Word32 cf, oneminuscf; + Word32 cf, oneminuscf; /* Q31 */ Word32 val; push_wmops( "rotateFrameSba" ); @@ -9052,7 +9070,7 @@ static ivas_error rotateFrameSba_fx( { FOR( l = 0; l < 3; l++ ) { - Rmat[i][l] = ( *hCombinedOrientationData )->Rmat_fx[subframe_idx][i][l]; // Q30 + Rmat[i][l] = ( *hCombinedOrientationData )->Rmat_fx[subframe_idx][i][l]; /* Q30 */ move32(); } } @@ -9091,14 +9109,14 @@ static ivas_error rotateFrameSba_fx( /* compute mtx-vector product for this l */ FOR( n = m1; n < m2; n++ ) { - tmpRot[sub( n, m1 )] = 0; + tmpRot[n - m1] = 0; move32(); FOR( m = m1; m < m2; m++ ) { - val = inAudio.data_fx[add( imult1616( m, inAudio.config.numSamplesPerChannel ), idx )]; + val = inAudio.data_fx[m * inAudio.config.numSamplesPerChannel + idx]; /* crossfade with previous rotation gains */ temp = Mpy_32_32( L_add( Mpy_32_16_r( cf, gains[n][m] ), ( Mpy_32_16_r( oneminuscf, gains_prev[n][m] ) ) ), val ); - tmpRot[sub( n, m1 )] = L_add( L_shl( temp, 1 ), tmpRot[sub( n, m1 )] ); // Qexp + tmpRot[n - m1] = L_add( L_shl( temp, 1 ), tmpRot[n - m1] ); move32(); move32(); } @@ -9107,19 +9125,19 @@ static ivas_error rotateFrameSba_fx( FOR( n = m1; n < m2; n++ ) { writePtr = getSmplPtr_fx( outAudio, n, idx ); - ( *writePtr ) = tmpRot[sub( n, m1 )]; + ( *writePtr ) = tmpRot[n - m1]; move32(); } m1 = m2; move16(); - m2 = add( m2, 2 * ( l + 1 ) + 1 ); + m2 = add( m2, add( shl( add( l, 1 ), 1 ), 1 ) ); } } /* move SHrotmat to SHrotmat_prev */ FOR( i = 0; i < HEADROT_SHMAT_DIM; i++ ) { - Copy( gains[i], gains_prev[i], HEADROT_SHMAT_DIM ); // Q14 + Copy( gains[i], gains_prev[i], HEADROT_SHMAT_DIM ); } } pop_wmops(); @@ -9261,7 +9279,7 @@ static ivas_error renderIsmToBinaural( FOR( i = 0; i < MAX_OUTPUT_CHANNELS; ++i ) { - Scale_sig32( tmpTDRendBuffer[i], L_FRAME48k, sub( 11, exp ) ); + Scale_sig32( tmpTDRendBuffer[i], L_FRAME48k, sub( Q11, exp ) ); /* Q11 */ } IF( NE_32( ( error = ivas_td_binaural_renderer_ext_fx( &ismInput->tdRendWrapper, ismInput->base.inConfig, NULL, ismInput->base.ctx.pCombinedOrientationData, &ismInput->currentPos, ismInput->hReverb, ism_md_subframe_update_ext, @@ -9273,7 +9291,7 @@ static ivas_error renderIsmToBinaural( FOR( i = 0; i < MAX_OUTPUT_CHANNELS; ++i ) { - Scale_sig32( tmpTDRendBuffer[i], L_FRAME48k, negate( sub( 11, exp ) ) ); + Scale_sig32( tmpTDRendBuffer[i], L_FRAME48k, negate( sub( Q11, exp ) ) ); /* Q(exp) */ } IF( ismInput->hReverb != NULL ) @@ -9282,7 +9300,7 @@ static ivas_error renderIsmToBinaural( { FOR( Word16 j = 0; j < outAudio.config.numSamplesPerChannel; j++ ) { - tmpTDRendBuffer[i][j] = L_shl( tmpTDRendBuffer[i][j], 2 ); + tmpTDRendBuffer[i][j] = L_shl( tmpTDRendBuffer[i][j], Q2 ); /* Q(exp + 2) */ move32(); } } @@ -9333,9 +9351,9 @@ static Word16 getNumSubframesInBuffer( const IVAS_REND_AudioBuffer *buffer, const Word32 sampleRate ) { - Word16 scale, temp = extract_l( Mpy_32_32( sampleRate, 10737418 ) ); // Q0 + Q31 - Q31 -> Q0 + Word16 scale, temp = extract_l( Mpy_32_32( sampleRate, 10737418 /* 1 / FRAMES_PER_SEC * MAX_PARAM_SPATIAL_SUBFRAMES in Q31 */ ) ); temp = BASOP_Util_Divide1616_Scale( buffer->config.numSamplesPerChannel, temp, &scale ); - temp = shr( temp, sub( 15, scale ) ); + temp = shr( temp, sub( 15, scale ) ); /* Q0 */ return temp; } #else @@ -9358,7 +9376,7 @@ static ivas_error renderIsmToBinauralRoom( { Word16 position_changed; Word16 i, j; - Word32 azi_rot, ele_rot; + Word32 azi_rot, ele_rot; /* Q22 */ Word16 subframe_idx; Word16 tmp; rotation_matrix_fx Rmat; @@ -9389,7 +9407,6 @@ static ivas_error renderIsmToBinauralRoom( { FOR( subframe_idx = 0; subframe_idx < ( *hCombinedOrientationData )->num_subframes; subframe_idx++ ) { - IF( ( *hCombinedOrientationData )->enableCombinedOrientation[subframe_idx] != 0 ) { combinedOrientationEnabled = 1; @@ -9459,7 +9476,9 @@ static ivas_error renderIsmToBinauralRoom( move32(); } + test(); position_changed = !ismInput->firstFrameRendered || checkObjectPositionChanged_fx( &rotatedPos, &rotatedPosPrev ); + move16(); /* set previous gains if this is the first frame */ IF( NE_32( ( error = getEfapGains_fx( *ismInput->base.ctx.pEfapOutWrapper, rotatedPosPrev.azimuth_fx, rotatedPosPrev.elevation_fx, ismInput->prev_pan_gains_fx ) ), IVAS_ERR_OK ) ) @@ -9493,11 +9512,20 @@ static ivas_error renderIsmToBinauralRoom( tmpMcBuffer.data_fx = malloc( imult1616( tmpMcBuffer.config.numSamplesPerChannel, tmpMcBuffer.config.numChannels ) * sizeof( Word32 ) ); set_zero_fx( tmpMcBuffer.data_fx, imult1616( tmpMcBuffer.config.numSamplesPerChannel, tmpMcBuffer.config.numChannels ) ); - - renderBufferChannelLerp_fx( ismInput->base.inputBuffer, 0, - position_changed ? currentPanGains : ismInput->prev_pan_gains_fx, - position_changed ? ismInput->prev_pan_gains_fx : NULL, - tmpMcBuffer ); + IF( position_changed ) + { + renderBufferChannelLerp_fx( ismInput->base.inputBuffer, 0, + currentPanGains, + ismInput->prev_pan_gains_fx, + tmpMcBuffer ); + } + ELSE + { + renderBufferChannelLerp_fx( ismInput->base.inputBuffer, 0, + ismInput->prev_pan_gains_fx, + NULL, + tmpMcBuffer ); + } copyBufferTo2dArray_fx( tmpMcBuffer, tmpRendBuffer ); @@ -9512,11 +9540,8 @@ static ivas_error renderIsmToBinauralRoom( Copy32( currentPanGains, ismInput->prev_pan_gains_fx, MAX_OUTPUT_CHANNELS ); } // Crend_process porting - move16(); CREND_HANDLE hCrend; hCrend = ismInput->crendWrapper->hCrend; - move16(); - move16(); IF( hCrend->reflections != NULL ) { test(); @@ -9524,7 +9549,7 @@ static ivas_error renderIsmToBinauralRoom( { FOR( i = 0; i < 150; i++ ) { - hCrend->reflections->shoebox_data.gains.data_fx[i] = L_shl( hCrend->reflections->shoebox_data.gains.data_fx[i], 9 ); + hCrend->reflections->shoebox_data.gains.data_fx[i] = L_shl( hCrend->reflections->shoebox_data.gains.data_fx[i], Q9 ); move32(); } } @@ -9735,7 +9760,7 @@ static ivas_error renderIsmToBinauralReverb( FOR( i = 0; i < MAX_OUTPUT_CHANNELS; ++i ) { - Scale_sig32( tmpRendBuffer_fx[i], L_FRAME48k, sub( 11, exp ) ); + Scale_sig32( tmpRendBuffer_fx[i], L_FRAME48k, sub( Q11, exp ) ); /* Q11 */ } IF( NE_32( ( error = ivas_td_binaural_renderer_ext_fx( &ismInput->tdRendWrapper, ismInput->base.inConfig, NULL, ismInput->base.ctx.pCombinedOrientationData, &ismInput->currentPos, ismInput->hReverb, ism_md_subframe_update_ext, *ismInput->base.ctx.pOutSampleRate, outAudio.config.numSamplesPerChannel, tmpRendBuffer_fx, &exp ) ), IVAS_ERR_OK ) ) @@ -9745,7 +9770,7 @@ static ivas_error renderIsmToBinauralReverb( FOR( i = 0; i < MAX_OUTPUT_CHANNELS; ++i ) { - Scale_sig32( tmpRendBuffer_fx[i], L_FRAME48k, negate( sub( 11, exp ) ) ); + Scale_sig32( tmpRendBuffer_fx[i], L_FRAME48k, negate( sub( 11, exp ) ) ); /* Q(exp) */ } IF( ismInput->hReverb != NULL ) @@ -9754,7 +9779,7 @@ static ivas_error renderIsmToBinauralReverb( { FOR( Word16 j = 0; j < outAudio.config.numSamplesPerChannel; j++ ) { - tmpRendBuffer_fx[i][j] = L_shl( tmpRendBuffer_fx[i][j], 2 ); + tmpRendBuffer_fx[i][j] = L_shl( tmpRendBuffer_fx[i][j], 2 ); /* Q(exp + 2) */ move16(); } } @@ -9799,26 +9824,31 @@ static ivas_error renderIsmToMc( const IVAS_REND_AudioBuffer outAudio ) { Word8 position_changed; - pan_vector_fx currentPanGains_fx; + pan_vector_fx currentPanGains_fx; /* Q31 */ ivas_error error; push_wmops( "renderIsmToMc" ); ismInput->currentPos.azimuth_fx = L_shl( L_shr( L_add( ismInput->currentPos.azimuth_fx, ONE_IN_Q21 ), Q22 ), Q22 ); + move32(); ismInput->currentPos.elevation_fx = L_shl( L_shr( L_add( ismInput->currentPos.elevation_fx, ONE_IN_Q21 ), Q22 ), Q22 ); + move32(); ismInput->previousPos.azimuth_fx = L_shl( L_shr( L_add( ismInput->previousPos.azimuth_fx, ONE_IN_Q21 ), Q22 ), Q22 ); + move32(); ismInput->previousPos.elevation_fx = L_shl( L_shr( L_add( ismInput->previousPos.elevation_fx, ONE_IN_Q21 ), Q22 ), Q22 ); + move32(); - position_changed = !ismInput->firstFrameRendered || checkObjectPositionChanged( &ismInput->currentPos, &ismInput->previousPos ); test(); + position_changed = !ismInput->firstFrameRendered || checkObjectPositionChanged_fx( &ismInput->currentPos, &ismInput->previousPos ); + move16(); IF( EQ_32( *ismInput->base.ctx.pOutConfig, IVAS_AUDIO_CONFIG_STEREO ) ) { IF( ismInput->nonDiegeticPan ) { - currentPanGains_fx[0] = L_add( L_shr( ismInput->nonDiegeticPanGain_fx, 1 ), ONE_IN_Q30 ); - currentPanGains_fx[1] = L_sub( ONE_IN_Q31, currentPanGains_fx[0] ); - ismInput->prev_pan_gains_fx[0] = currentPanGains_fx[0]; // Q31 - ismInput->prev_pan_gains_fx[1] = currentPanGains_fx[1]; // Q31 + currentPanGains_fx[0] = L_add( L_shr( ismInput->nonDiegeticPanGain_fx, 1 ), ONE_IN_Q30 ); /* Q31 */ + currentPanGains_fx[1] = L_sub( ONE_IN_Q31, currentPanGains_fx[0] ); /* Q31 */ + ismInput->prev_pan_gains_fx[0] = currentPanGains_fx[0]; /* Q31 */ + ismInput->prev_pan_gains_fx[1] = currentPanGains_fx[1]; /* Q31 */ move32(); move32(); move32(); @@ -9835,8 +9865,8 @@ static ivas_error renderIsmToMc( elevation_tmp = extract_l( L_shr( ismInput->currentPos.elevation_fx, Q22 ) ); ivas_ism_get_stereo_gains_fx( azimuth_tmp, elevation_tmp, &gains_fx[0], &gains_fx[1] ); - currentPanGains_fx[0] = L_deposit_h( gains_fx[0] ); // Q31 - currentPanGains_fx[1] = L_deposit_h( gains_fx[1] ); // Q31 + currentPanGains_fx[0] = L_deposit_h( gains_fx[0] ); /* Q31 */ + currentPanGains_fx[1] = L_deposit_h( gains_fx[1] ); /* Q31 */ move32(); move32(); @@ -9845,8 +9875,8 @@ static ivas_error renderIsmToMc( set32_fx( ismInput->prev_pan_gains_fx, 0, MAX_OUTPUT_CHANNELS ); ivas_ism_get_stereo_gains_fx( azimuth_tmp, elevation_tmp, &gains_fx[0], &gains_fx[1] ); - ismInput->prev_pan_gains_fx[0] = L_deposit_h( gains_fx[0] ); // Q31 - ismInput->prev_pan_gains_fx[1] = L_deposit_h( gains_fx[1] ); // Q31 + ismInput->prev_pan_gains_fx[0] = L_deposit_h( gains_fx[0] ); /* Q31 */ + ismInput->prev_pan_gains_fx[1] = L_deposit_h( gains_fx[1] ); /* Q31 */ move32(); move32(); } @@ -9885,10 +9915,20 @@ static ivas_error renderIsmToMc( /* Assume num channels in audio buffer to be 1. * This should have been validated in IVAS_REND_FeedInputAudio() */ - renderBufferChannelLerp_fx( ismInput->base.inputBuffer, 0, - position_changed ? currentPanGains_fx : ismInput->prev_pan_gains_fx, - position_changed ? ismInput->prev_pan_gains_fx : NULL, - outAudio ); + IF( position_changed ) + { + renderBufferChannelLerp_fx( ismInput->base.inputBuffer, 0, + currentPanGains_fx, + ismInput->prev_pan_gains_fx, + outAudio ); + } + ELSE + { + renderBufferChannelLerp_fx( ismInput->base.inputBuffer, 0, + ismInput->prev_pan_gains_fx, + NULL, + outAudio ); + } IF( position_changed ) { @@ -9989,6 +10029,7 @@ static ivas_error renderIsmToSba( pan_vector_fx currentPanGains_fx; ivas_error error; error = IVAS_ERR_OK; + move32(); ismInput->currentPos.azimuth_fx = L_shl( L_shr( L_add( ismInput->currentPos.azimuth_fx, ONE_IN_Q21 ), Q22 ), Q22 ); ismInput->currentPos.elevation_fx = L_shl( L_shr( L_add( ismInput->currentPos.elevation_fx, ONE_IN_Q21 ), Q22 ), Q22 ); @@ -10011,8 +10052,9 @@ static ivas_error renderIsmToSba( return error; } - position_changed = !ismInput->firstFrameRendered || checkObjectPositionChanged( &ismInput->currentPos, &ismInput->previousPos ); test(); + position_changed = !ismInput->firstFrameRendered || checkObjectPositionChanged_fx( &ismInput->currentPos, &ismInput->previousPos ); + move16(); /* set previous gains if this is the first frame */ Word16 azimuth_tmp, elevation_tmp; @@ -10028,7 +10070,7 @@ static ivas_error renderIsmToSba( Q29 ); FOR( i = 0; i < MAX_OUTPUT_CHANNELS; i++ ) { - ismInput->prev_pan_gains_fx[i] = L_shl_sat( ismInput->prev_pan_gains_fx[i], Q2 ); + ismInput->prev_pan_gains_fx[i] = L_shl_sat( ismInput->prev_pan_gains_fx[i], Q2 ); /* Q29 + Q2 = Q31 */ move32(); } } @@ -10046,22 +10088,31 @@ static ivas_error renderIsmToSba( Q29 ); FOR( i = 0; i < MAX_OUTPUT_CHANNELS; i++ ) { - currentPanGains_fx[i] = L_shl_sat( currentPanGains_fx[i], Q2 ); + currentPanGains_fx[i] = L_shl_sat( currentPanGains_fx[i], Q2 ); /* Q29 + Q2 = Q31 */ move32(); } } /* Assume num channels in audio buffer to be 1. * This should have been validated in IVAS_REND_FeedInputAudio() */ - renderBufferChannelLerp_fx( ismInput->base.inputBuffer, 0, - position_changed ? currentPanGains_fx : ismInput->prev_pan_gains_fx, - position_changed ? ismInput->prev_pan_gains_fx : NULL, - outAudio ); + IF( position_changed ) + { + renderBufferChannelLerp_fx( ismInput->base.inputBuffer, 0, + currentPanGains_fx, + ismInput->prev_pan_gains_fx, + outAudio ); + } + ELSE + { + renderBufferChannelLerp_fx( ismInput->base.inputBuffer, 0, + ismInput->prev_pan_gains_fx, + NULL, + outAudio ); + } IF( position_changed ) { Copy32( currentPanGains_fx, ismInput->prev_pan_gains_fx, MAX_OUTPUT_CHANNELS ); - // mvr2r( currentPanGains, ismInput->prev_pan_gains, MAX_OUTPUT_CHANNELS ); } pop_wmops(); @@ -10158,16 +10209,18 @@ static void renderIsmToMasa( FOR( i = 1; i < MAX_NUM_OBJECTS; i++ ) { - IF( LT_16( max_e, input_e[0] ) ) - max_e = input_e[i]; - move16(); + if ( LT_16( max_e, input_e[0] ) ) + { + max_e = input_e[i]; + move16(); + } } FOR( i = 0; i < MAX_NUM_OBJECTS; i++ ) { FOR( j = 0; j < L_FRAME48k; j++ ) { - tmpRendBuffer_fx[i][j] = L_shr( tmpRendBuffer_fx[i][j], add( sub( max_e, sub( 31, *outAudio.pq_fact ) ), guard_bits ) ); + tmpRendBuffer_fx[i][j] = L_shr( tmpRendBuffer_fx[i][j], add( sub( max_e, sub( 31, *outAudio.pq_fact ) ), guard_bits ) ); /* Q(31 - (max_e + guard_bits)) */ move32(); } } @@ -10232,10 +10285,10 @@ static ivas_error renderInputIsm( /* Apply input gain to new audio */ v_multc_fixed( inAudio.data_fx, ismInput->base.gain_fx, inAudio.data_fx, imult1616( inAudio.config.numSamplesPerChannel, inAudio.config.numChannels ) ); *outAudio.pq_fact = sub( *outAudio.pq_fact, Q1 ); - exp = *outAudio.pq_fact; - move16(); + exp = *outAudio.pq_fact; move16(); + /* set combined orientation subframe info to start info */ ivas_combined_orientation_set_to_start_index( *ismInput->base.ctx.pCombinedOrientationData ); @@ -10283,11 +10336,11 @@ static ivas_error renderInputIsm( } ismInput->firstFrameRendered = TRUE; + move16(); *outAudio.pq_fact = exp; - - move16(); move16(); + return error; } #else @@ -10382,7 +10435,7 @@ static ivas_error renderActiveInputsIsm( } FOR( Word16 j = 0; j < outAudio.config.numSamplesPerChannel * outAudio.config.numChannels; ++j ) { - outAudio.data_fx[j] = L_shl( outAudio.data_fx[j], sub( sub( input_q, 1 ), ( *outAudio.pq_fact ) ) ); + outAudio.data_fx[j] = L_shl( outAudio.data_fx[j], sub( sub( input_q, 1 ), ( *outAudio.pq_fact ) ) ); /* Q(input_q - 1) */ move32(); } *outAudio.pq_fact = sub( input_q, 1 ); @@ -10434,7 +10487,7 @@ static ivas_error renderLfeToBinaural_fx( assert( ( outAudio.config.numChannels == 2 ) && "Must be binaural output" ); push_wmops( "renderLfeToBinaural" ); - gain_fx = GAIN_LFE_WORD32; + gain_fx = GAIN_LFE_WORD32; /* 1.88364911f in Q30 */ move32(); IF( NE_32( mcInput->base.inConfig, IVAS_AUDIO_CONFIG_LS_CUSTOM ) ) @@ -10455,7 +10508,6 @@ static ivas_error renderLfeToBinaural_fx( /* --- Prepare LFE signal to be added to binaural output --- */ lfeInput = getSmplPtr_fx( mcInput->base.inputBuffer, lfe_idx, 0 ); - move32(); frame_size = mcInput->base.inputBuffer.config.numSamplesPerChannel; move16(); num_cpy_smpl_prev_frame = mcInput->binauralDelaySmp; @@ -10466,10 +10518,10 @@ static ivas_error renderLfeToBinaural_fx( assert( mcInput->binauralDelaySmp < frame_size ); /* Get delayed LFE signal from previous frame, apply gain and save in tmp buffer */ - v_multc_fixed( mcInput->lfeDelayBuffer_fx, gain_fx, tmpLfeBuffer, num_cpy_smpl_prev_frame ); // Qinp-1 + v_multc_fixed( mcInput->lfeDelayBuffer_fx, gain_fx, tmpLfeBuffer, num_cpy_smpl_prev_frame ); /* Qx - 1 */ /* Continue filling tmp buffer, now with LFE signal from current frame */ - v_multc_fixed( lfeInput, gain_fx, tmpLfeBuffer + num_cpy_smpl_prev_frame, num_cpy_smpl_cur_frame ); // Qinp-1 + v_multc_fixed( lfeInput, gain_fx, tmpLfeBuffer + num_cpy_smpl_prev_frame, num_cpy_smpl_cur_frame ); /* Qx - 1 */ /* Save remaining LFE samples of current frame for next frame */ MVR2R_WORD32( lfeInput + num_cpy_smpl_cur_frame, mcInput->lfeDelayBuffer_fx, num_cpy_smpl_prev_frame ); @@ -10479,8 +10531,7 @@ static ivas_error renderLfeToBinaural_fx( { FOR( i = 0; i < add( num_cpy_smpl_prev_frame, num_cpy_smpl_cur_frame ); i++ ) { - tmpLfeBuffer[i] = L_shr( tmpLfeBuffer[i], r_shift ); // out_q - + tmpLfeBuffer[i] = L_shr( tmpLfeBuffer[i], r_shift ); /* Q(out_q) */ move32(); } } @@ -10489,7 +10540,7 @@ static ivas_error renderLfeToBinaural_fx( { writePtr = getSmplPtr_fx( outAudio, ear_idx, 0 ); move32(); - v_add_fixed( writePtr, tmpLfeBuffer, writePtr, frame_size, 0 ); // out_q + v_add_fixed( writePtr, tmpLfeBuffer, writePtr, frame_size, 0 ); /* Q(out_q) */ } pop_wmops(); @@ -10608,7 +10659,7 @@ static ivas_error renderMcToBinaural( FOR( i = 0; i < MAX_OUTPUT_CHANNELS; ++i ) { - Scale_sig32( tmpRendBuffer_fx[i], L_FRAME48k, sub( 11, exp ) ); + Scale_sig32( tmpRendBuffer_fx[i], L_FRAME48k, sub( Q11, exp ) ); /* Q11 */ } IF( NE_32( ( error = ivas_td_binaural_renderer_ext_fx( &mcInput->tdRendWrapper, mcInput->base.inConfig, &mcInput->customLsInput, mcInput->base.ctx.pCombinedOrientationData, NULL, mcInput->hReverb, 0, *mcInput->base.ctx.pOutSampleRate, mcInput->base.inputBuffer.config.numSamplesPerChannel, tmpRendBuffer_fx, &exp ) ), @@ -10619,7 +10670,7 @@ static ivas_error renderMcToBinaural( FOR( i = 0; i < MAX_OUTPUT_CHANNELS; ++i ) { - Scale_sig32( tmpRendBuffer_fx[i], L_FRAME48k, -sub( Q11, exp ) ); + Scale_sig32( tmpRendBuffer_fx[i], L_FRAME48k, negate( sub( Q11, exp ) ) ); /* Q(exp) */ } } ELSE @@ -10791,9 +10842,8 @@ static ivas_error renderMcToBinauralRoom( inConfig = mcInput->base.inConfig; move32(); hCombinedOrientationData = mcInput->base.ctx.pCombinedOrientationData; - move32(); combinedOrientationEnabled = 0; - move32(); + move16(); IF( hCombinedOrientationData != NULL ) { FOR( subframe_idx = 0; subframe_idx < ( *hCombinedOrientationData )->num_subframes; subframe_idx++ ) @@ -10818,7 +10868,7 @@ static ivas_error renderMcToBinauralRoom( FOR( i = 0; i < MAX_OUTPUT_CHANNELS; ++i ) { - Scale_sig32( tmpRendBuffer[i], L_FRAME48k, sub( Q11, exp ) ); + Scale_sig32( tmpRendBuffer[i], L_FRAME48k, sub( Q11, exp ) ); /* Q11 */ } IF( NE_32( ( error = ivas_td_binaural_renderer_ext_fx( &mcInput->tdRendWrapper, mcInput->base.inConfig, &mcInput->customLsInput, mcInput->base.ctx.pCombinedOrientationData, NULL, mcInput->hReverb, @@ -10830,9 +10880,8 @@ static ivas_error renderMcToBinauralRoom( FOR( i = 0; i < MAX_OUTPUT_CHANNELS; ++i ) { - Scale_sig32( tmpRendBuffer[i], L_FRAME48k, -sub( Q11, exp ) ); + Scale_sig32( tmpRendBuffer[i], L_FRAME48k, negate( sub( Q11, exp ) ) ); /* Q(exp) */ } - //*outAudio.pq_fact = exp; } ELSE { @@ -11273,28 +11322,35 @@ static void renderMcToSba( } #endif +#ifdef IVAS_FLOAT_FIXED static void renderMcToMasa( input_mc *mcInput, IVAS_REND_AudioBuffer outAudio ) { -#ifdef IVAS_FLOAT_FIXED push_wmops( "renderMcToMasa" ); Word32 tmpRendBuffer_fx[MAX_OUTPUT_CHANNELS][L_FRAME48k]; copyBufferTo2dArray_fx( mcInput->base.inputBuffer, tmpRendBuffer_fx ); ivas_mcmasa_ana_fx( mcInput->hMcMasa, tmpRendBuffer_fx, *( outAudio.pq_fact ), mcInput->base.inputBuffer.config.numSamplesPerChannel, outAudio.config.numChannels, mcInput->base.inputBuffer.config.numChannels ); accumulate2dArrayToBuffer_fx( tmpRendBuffer_fx, &outAudio ); + pop_wmops(); + return; +} #else +static void renderMcToMasa( + input_mc *mcInput, + IVAS_REND_AudioBuffer outAudio ) +{ push_wmops( "renderMcToMasa" ); float tmpRendBuffer[MAX_OUTPUT_CHANNELS][L_FRAME48k]; copyBufferTo2dArray( mcInput->base.inputBuffer, tmpRendBuffer ); ivas_mcmasa_ana( mcInput->hMcMasa, tmpRendBuffer, mcInput->base.inputBuffer.config.numSamplesPerChannel, outAudio.config.numChannels, mcInput->base.inputBuffer.config.numChannels ); accumulate2dArrayToBuffer( tmpRendBuffer, &outAudio ); -#endif // IVAS_FLOAT_FIXED pop_wmops(); return; } +#endif #ifdef IVAS_FLOAT_FIXED static ivas_error renderInputMc( @@ -11317,6 +11373,7 @@ static ivas_error renderInputMc( move32(); v_multc_fixed( inAudio.data_fx, mcInput->base.gain_fx, inAudio.data_fx, inAudio.config.numSamplesPerChannel * inAudio.config.numChannels ); *outAudio.pq_fact = sub( *outAudio.pq_fact, Q1 ); // reducing the Q by 1 compensating for the v_mult_fixed done + move16(); /* set combined orientation subframe info to start info */ ivas_combined_orientation_set_to_start_index( *( mcInput->base.ctx.pCombinedOrientationData ) ); @@ -11595,7 +11652,7 @@ static ivas_error renderSbaToBinaural( tmpRotBuffer.data_fx = malloc( tmpRotBuffer.config.numSamplesPerChannel * tmpRotBuffer.config.numChannels * sizeof( Word32 ) ); /* copy input for in-place rotation */ - MVR2R_WORD32( sbaInput->base.inputBuffer.data_fx, tmpRotBuffer.data_fx, tmpRotBuffer.config.numChannels * tmpRotBuffer.config.numSamplesPerChannel ); + Copy32( sbaInput->base.inputBuffer.data_fx, tmpRotBuffer.data_fx, i_mult( tmpRotBuffer.config.numChannels, tmpRotBuffer.config.numSamplesPerChannel ) ); IF( NE_16( ( error = rotateFrameSba_fx( sbaInput->base.inputBuffer, sbaInput->base.inConfig, sbaInput->base.ctx.pHeadRotData, sbaInput->base.ctx.pCombinedOrientationData, sbaInput->rot_gains_prev_fx, tmpRotBuffer ) ), @@ -11765,7 +11822,7 @@ static ivas_error renderSbaToBinauralRoom( tmpRotBuffer.data_fx = malloc( imult1616( tmpRotBuffer.config.numSamplesPerChannel, tmpRotBuffer.config.numChannels ) * sizeof( Word32 ) ); /* copy input for in-place rotation */ - MVR2R_WORD32( sbaInput->base.inputBuffer.data_fx, tmpRotBuffer.data_fx, tmpRotBuffer.config.numChannels * tmpRotBuffer.config.numSamplesPerChannel ); + Copy32( sbaInput->base.inputBuffer.data_fx, tmpRotBuffer.data_fx, i_mult( tmpRotBuffer.config.numChannels, tmpRotBuffer.config.numSamplesPerChannel ) ); IF( NE_32( ( error = rotateFrameSba_fx( sbaInput->base.inputBuffer, sbaInput->base.inConfig, sbaInput->base.ctx.pHeadRotData, sbaInput->base.ctx.pCombinedOrientationData, @@ -11788,7 +11845,7 @@ static ivas_error renderSbaToBinauralRoom( tmpMcBuffer.config.numChannels = tmp; move16(); tmpMcBuffer.data_fx = malloc( tmpMcBuffer.config.numSamplesPerChannel * tmpMcBuffer.config.numChannels * sizeof( Word32 ) ); - set32_fx( tmpMcBuffer.data_fx, 0, tmpMcBuffer.config.numChannels * tmpMcBuffer.config.numSamplesPerChannel ); + set32_fx( tmpMcBuffer.data_fx, 0, i_mult( tmpMcBuffer.config.numChannels, tmpMcBuffer.config.numSamplesPerChannel ) ); IF( combinedOrientationEnabled ) { @@ -11980,7 +12037,7 @@ static ivas_error renderInputSba( *outAudio.pq_fact = outAudio.q_factor; move16(); /* Apply input gain to new audio */ - v_multc_fixed( inAudio.data_fx, sbaInput->base.gain_fx, inAudio.data_fx, inAudio.config.numSamplesPerChannel * inAudio.config.numChannels ); + v_multc_fixed( inAudio.data_fx, sbaInput->base.gain_fx, inAudio.data_fx, i_mult( inAudio.config.numSamplesPerChannel, inAudio.config.numChannels ) ); *outAudio.pq_fact = sub( *outAudio.pq_fact, 1 ); // to compensate for the qfactor reduction in gain multiplication. move16(); @@ -12149,9 +12206,9 @@ static void copyMasaMetadataToDiracRenderer_fx( { FOR( bin = MASA_band_grouping_24[band]; bin < MASA_band_grouping_24[band + 1] && bin < maxBin; bin++ ) { - hSpatParamRendCom->azimuth[meta_write_index][bin] = extract_l( L_shr( meta->directional_meta[0].azimuth_fx[sf][band], Q22 ) ); // Q22 -> Q0 + hSpatParamRendCom->azimuth[meta_write_index][bin] = extract_l( L_shr( meta->directional_meta[0].azimuth_fx[sf][band], Q22 ) ); /* Q22 - Q22 = Q0 */ move16(); - hSpatParamRendCom->elevation[meta_write_index][bin] = extract_l( L_shr( meta->directional_meta[0].elevation_fx[sf][band], Q22 ) ); // Q22 -> Q0 + hSpatParamRendCom->elevation[meta_write_index][bin] = extract_l( L_shr( meta->directional_meta[0].elevation_fx[sf][band], Q22 ) ); /* Q22 - Q22 = Q0 */ move16(); hSpatParamRendCom->energy_ratio1_fx[meta_write_index][bin] = meta->directional_meta[0].energy_ratio_fx[sf][band]; move32(); @@ -12164,9 +12221,9 @@ static void copyMasaMetadataToDiracRenderer_fx( IF( EQ_16( hSpatParamRendCom->numSimultaneousDirections, 2 ) ) { - hSpatParamRendCom->azimuth2[meta_write_index][bin] = extract_l( L_shr( meta->directional_meta[1].azimuth_fx[sf][band], Q22 ) ); // Q22 -> Q0 + hSpatParamRendCom->azimuth2[meta_write_index][bin] = extract_l( L_shr( meta->directional_meta[1].azimuth_fx[sf][band], Q22 ) ); /* Q22 - Q22 = Q0 */ move16(); - hSpatParamRendCom->elevation2[meta_write_index][bin] = extract_l( L_shr( meta->directional_meta[1].elevation_fx[sf][band], Q22 ) ); // Q22 -> Q0 + hSpatParamRendCom->elevation2[meta_write_index][bin] = extract_l( L_shr( meta->directional_meta[1].elevation_fx[sf][band], Q22 ) ); /* Q22 - Q22 = Q0 */ move16(); hSpatParamRendCom->energy_ratio2_fx[meta_write_index][bin] = meta->directional_meta[1].energy_ratio_fx[sf][band]; move32(); @@ -12179,7 +12236,7 @@ static void copyMasaMetadataToDiracRenderer_fx( } } - hSpatParamRendCom->dirac_bs_md_write_idx = ( hSpatParamRendCom->dirac_bs_md_write_idx + MAX_PARAM_SPATIAL_SUBFRAMES ) % hSpatParamRendCom->dirac_md_buffer_length; + hSpatParamRendCom->dirac_bs_md_write_idx = add( hSpatParamRendCom->dirac_bs_md_write_idx, MAX_PARAM_SPATIAL_SUBFRAMES ) % hSpatParamRendCom->dirac_md_buffer_length; move16(); return; @@ -12236,7 +12293,7 @@ static void renderMasaToMasa( IVAS_REND_AudioBuffer outAudio ) { Word16 sf, band, dir, numDirs; - Word32 ratioSum_fx; + Word32 ratioSum_fx; /* Q30 */ MASA_DECODER_EXT_OUT_META_HANDLE outMeta; MASA_METADATA_FRAME *inMeta; Word32 tmpBuffer_fx[MAX_OUTPUT_CHANNELS][L_FRAME48k]; @@ -12256,7 +12313,8 @@ static void renderMasaToMasa( move16(); move16(); /* Calculate energy */ - l_ts = masaInput->base.inputBuffer.config.numSamplesPerChannel / CLDFB_NO_COL_MAX; + // l_ts = masaInput->base.inputBuffer.config.numSamplesPerChannel / CLDFB_NO_COL_MAX; + l_ts = shr( masaInput->base.inputBuffer.config.numSamplesPerChannel, 4 ); numAnalysisChannels = masaInput->hMasaPrerend->num_Cldfb_instances; move16(); /* do processing over all CLDFB time slots */ @@ -12282,8 +12340,8 @@ static void renderMasaToMasa( cldfbAnalysis_ts_fx_fixed_q( &( tmpBuffer_fx[i][l_ts * ts] ), Chan_RealBuffer_fx[i], Chan_ImagBuffer_fx[i], l_ts, masaInput->hMasaPrerend->cldfbAnaEnc[i], &q_cldfb_out ); scale_factor = s_min( scale_factor, s_min( getScaleFactor32( Chan_RealBuffer_fx[i], CLDFB_NO_CHANNELS_MAX ), getScaleFactor32( Chan_ImagBuffer_fx[i], CLDFB_NO_CHANNELS_MAX ) ) ); scale_factor = sub( scale_factor, 1 ); - scale_sig32( Chan_RealBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, scale_factor ); // Q17 - scale_sig32( Chan_ImagBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, scale_factor ); // Q17 + scale_sig32( Chan_RealBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, scale_factor ); /* Q(q_cldfb_out + scale_factor) */ + scale_sig32( Chan_ImagBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, scale_factor ); /* Q(q_cldfb_out + scale_factor) */ } Word16 q_add = sub( 31, add( scale_factor, q_cldfb_out ) ); @@ -12298,8 +12356,8 @@ static void renderMasaToMasa( { FOR( i = 0; i < numAnalysisChannels; i++ ) { - Word32 temp = L_add( Mult_32_32( Chan_RealBuffer_fx[0][j], Chan_RealBuffer_fx[0][j] ), Mult_32_32( Chan_ImagBuffer_fx[0][j], Chan_ImagBuffer_fx[0][j] ) ); - masaInput->hMasaPrerend->energy_fx[block_m_idx][band_m_idx] = BASOP_Util_Add_Mant32Exp( masaInput->hMasaPrerend->energy_fx[block_m_idx][band_m_idx], tmp_energy_e[block_m_idx][band_m_idx], temp, ( 2 * q_add ), &tmp_energy_e[block_m_idx][band_m_idx] ); + Word32 temp = L_add( Mpy_32_32( Chan_RealBuffer_fx[0][j], Chan_RealBuffer_fx[0][j] ), Mpy_32_32( Chan_ImagBuffer_fx[0][j], Chan_ImagBuffer_fx[0][j] ) ); /* 2 * Q(q_cldfb_out + scale_factor) - 31 */ + masaInput->hMasaPrerend->energy_fx[block_m_idx][band_m_idx] = BASOP_Util_Add_Mant32Exp( masaInput->hMasaPrerend->energy_fx[block_m_idx][band_m_idx], tmp_energy_e[block_m_idx][band_m_idx], temp, shl( q_add, 1 ), &tmp_energy_e[block_m_idx][band_m_idx] ); move32(); } } @@ -12312,7 +12370,6 @@ static void renderMasaToMasa( move16(); FOR( j = 0; j < MASA_FREQUENCY_BANDS; j++ ) { - max_e = s_max( max_e, tmp_energy_e[i][j] ); } masaInput->hMasaPrerend->energy_e[i] = max_e; @@ -12320,7 +12377,7 @@ static void renderMasaToMasa( FOR( j = 0; j < MASA_FREQUENCY_BANDS; j++ ) { - masaInput->hMasaPrerend->energy_fx[i][j] = L_shr( masaInput->hMasaPrerend->energy_fx[i][j], sub( max_e, tmp_energy_e[i][j] ) ); + masaInput->hMasaPrerend->energy_fx[i][j] = L_shr( masaInput->hMasaPrerend->energy_fx[i][j], sub( max_e, tmp_energy_e[i][j] ) ); /* Q(31 - max_e) */ move32(); } } @@ -12329,7 +12386,7 @@ static void renderMasaToMasa( test(); IF( EQ_16( masaInput->base.inputBuffer.config.numChannels, 1 ) && EQ_16( outAudio.config.numChannels, 2 ) ) { - MVR2R_WORD32( tmpBuffer_fx[0], tmpBuffer_fx[1], masaInput->base.inputBuffer.config.numSamplesPerChannel ); + Copy32( tmpBuffer_fx[0], tmpBuffer_fx[1], masaInput->base.inputBuffer.config.numSamplesPerChannel ); } ELSE IF( EQ_16( masaInput->base.inputBuffer.config.numChannels, 2 ) && EQ_16( outAudio.config.numChannels, 1 ) ) { @@ -12378,14 +12435,16 @@ static void renderMasaToMasa( FOR( dir = 0; dir < numDirs; dir++ ) { tmp = BASOP_Util_Divide3232_Scale_cadence( inMeta->directional_meta[dir].energy_ratio_fx[sf][band], ratioSum_fx, &tmp_e ); - inMeta->directional_meta[dir].energy_ratio_fx[sf][band] = L_shl( tmp, sub( tmp_e, 1 ) ); // Q30 + inMeta->directional_meta[dir].energy_ratio_fx[sf][band] = L_shl( tmp, sub( tmp_e, 1 ) ); /* Q30 */ + move32(); } tmp_e = 0; move16(); tmp = 0; move32(); tmp = BASOP_Util_Divide3232_Scale_cadence( inMeta->common_meta.diffuse_to_total_ratio_fx[sf][band], ratioSum_fx, &tmp_e ); - inMeta->common_meta.diffuse_to_total_ratio_fx[sf][band] = L_shl( tmp, sub( tmp_e, 1 ) ); // Q30 + inMeta->common_meta.diffuse_to_total_ratio_fx[sf][band] = L_shl( tmp, sub( tmp_e, 1 ) ); /* Q30 */ + move32(); } } } @@ -12400,7 +12459,7 @@ static void renderMasaToMasa( { outMeta->directionIndex[dir][sf][band] = index_theta_phi_16_fx( &inMeta->directional_meta[dir].elevation_fx[sf][band], &inMeta->directional_meta[dir].azimuth_fx[sf][band], masaInput->hMasaPrerend->sph_grid16 ); outMeta->directToTotalRatio[dir][sf][band] = (UWord8) L_shr( inMeta->directional_meta[dir].energy_ratio_fx[sf][band], Q22 ); - outMeta->diffuseToTotalRatio[sf][band] -= outMeta->directToTotalRatio[dir][sf][band]; + outMeta->diffuseToTotalRatio[sf][band] = (UWord8) sub( outMeta->diffuseToTotalRatio[sf][band], outMeta->directToTotalRatio[dir][sf][band] ); outMeta->spreadCoherence[dir][sf][band] = (UWord8) shr( inMeta->directional_meta[dir].spread_coherence_fx[sf][band], Q7 ); move16(); @@ -12575,11 +12634,11 @@ static ivas_error renderInputMasa( *outAudio.pq_fact = outAudio.q_factor; move16(); /* Apply input gain to new audio */ - v_multc_fixed( inAudio.data_fx, masaInput->base.gain_fx, inAudio.data_fx, inAudio.config.numSamplesPerChannel * inAudio.config.numChannels ); + v_multc_fixed( inAudio.data_fx, masaInput->base.gain_fx, inAudio.data_fx, i_mult( inAudio.config.numSamplesPerChannel, inAudio.config.numChannels ) ); *outAudio.pq_fact = sub( *outAudio.pq_fact, 1 ); // to compensate for the qfactor reduction in gain multiplication. move16(); - maxBin = extract_l( Mpy_32_32( *masaInput->base.ctx.pOutSampleRate, INV_CLDFB_BANDWIDTH_Q31 ) ); + maxBin = extract_l( Mpy_32_32( *masaInput->base.ctx.pOutSampleRate, INV_CLDFB_BANDWIDTH_Q31 ) ); /* Q0 */ /* set combined orientation subframe info to start info */ ivas_combined_orientation_set_to_start_index( *( masaInput->base.ctx.pCombinedOrientationData ) ); @@ -12600,7 +12659,7 @@ static ivas_error renderInputMasa( copyBufferTo2dArray_fx( masaInput->base.inputBuffer, tmpBuffer_buff_fx ); num_subframes = BASOP_Util_Divide3232_Scale( L_mult0( masaInput->base.inputBuffer.config.numSamplesPerChannel, IVAS_NUM_FRAMES_PER_SEC * MAX_PARAM_SPATIAL_SUBFRAMES ), *masaInput->base.ctx.pOutSampleRate, &exp ); - num_subframes = shr( num_subframes, sub( 15, exp ) ); + num_subframes = shr( num_subframes, sub( 15, exp ) ); /* Q0 */ SWITCH( masaInput->hMasaExtRend->renderer_type ) { @@ -12611,10 +12670,11 @@ static ivas_error renderInputMasa( FOR( ch = 0; ch < masaInput->hMasaExtRend->hDirACRend->hOutSetup.nchan_out_woLFE + masaInput->hMasaExtRend->hDirACRend->hOutSetup.num_lfe; ch++ ) { masaInput->hMasaExtRend->cldfbAnaRend[0]->Q_cldfb_state = Q11; + move16(); } FOR( ch = 0; ch < MAX_OUTPUT_CHANNELS; ch++ ) { - Scale_sig32( tmpBuffer_buff_fx[ch], L_FRAME48k, sub( Q11, *outAudio.pq_fact ) ); + Scale_sig32( tmpBuffer_buff_fx[ch], L_FRAME48k, sub( Q11, *outAudio.pq_fact ) ); /* Q11 */ } ivas_masa_ext_dirac_render_fx( masaInput->hMasaExtRend, tmpBuffer_fx, num_subframes ); @@ -12623,8 +12683,9 @@ static ivas_error renderInputMasa( FOR( ch = 0; ch < masaInput->hMasaExtRend->hDirACRend->hOutSetup.nchan_out_woLFE + masaInput->hMasaExtRend->hDirACRend->hOutSetup.num_lfe; ch++ ) { - scale_sig32( masaInput->hMasaExtRend->cldfbSynRend[ch]->cldfb_state_fx, masaInput->hMasaExtRend->cldfbSynRend[ch]->cldfb_size, sub( Q11, masaInput->hMasaExtRend->cldfbSynRend[ch]->Q_cldfb_state ) ); + scale_sig32( masaInput->hMasaExtRend->cldfbSynRend[ch]->cldfb_state_fx, masaInput->hMasaExtRend->cldfbSynRend[ch]->cldfb_size, sub( Q11, masaInput->hMasaExtRend->cldfbSynRend[ch]->Q_cldfb_state ) ); /* Q11 */ masaInput->hMasaExtRend->cldfbSynRend[ch]->Q_cldfb_state = Q11; + move16(); } intermidiate_ext_dirac_render( masaInput->hMasaExtRend, 0 ); @@ -12635,8 +12696,8 @@ static ivas_error renderInputMasa( copyMasaMetadataToDiracRenderer_fx( &masaInput->masaMetadata, masaInput->hMasaExtRend->hSpatParamRendCom, maxBin ); - Scale_sig32( tmpBuffer_buff_fx[0], L_FRAME48k, sub( Q11, *outAudio.pq_fact ) ); - Scale_sig32( tmpBuffer_buff_fx[1], L_FRAME48k, sub( Q11, *outAudio.pq_fact ) ); + Scale_sig32( tmpBuffer_buff_fx[0], L_FRAME48k, sub( Q11, *outAudio.pq_fact ) ); /* Q11 */ + Scale_sig32( tmpBuffer_buff_fx[1], L_FRAME48k, sub( Q11, *outAudio.pq_fact ) ); /* Q11 */ ivas_masa_ext_rend_parambin_render_fx( masaInput->hMasaExtRend, *masaInput->base.ctx.pCombinedOrientationData, tmpBuffer_fx, num_subframes ); *outAudio.pq_fact = Q11; @@ -13157,7 +13218,7 @@ static ivas_error getSamplesInternal( test(); IF( EQ_32( getAudioConfigType( hIvasRend->outputConfig ), IVAS_REND_AUDIO_CONFIG_TYPE_BINAURAL ) && - NE_32( outAudio.config.numSamplesPerChannel * 1000, ( hIvasRend->num_subframes * BINAURAL_RENDERING_FRAME_SIZE_MS ) * hIvasRend->sampleRateOut ) ) + NE_32( L_mult0( outAudio.config.numSamplesPerChannel, 1000 ), imult3216( hIvasRend->sampleRateOut, i_mult( hIvasRend->num_subframes, BINAURAL_RENDERING_FRAME_SIZE_MS ) ) ) ) { return IVAS_ERROR( IVAS_ERR_INVALID_BUFFER_SIZE, "Binaural rendering requires specific frame size" ); } @@ -13581,13 +13642,13 @@ static ivas_error ivas_masa_ext_rend_dirac_rend_init( hDirACRend->hOutSetup.ls_elevation_fx = inputMasa->base.ctx.pCustomLsOut->ls_elevation_fx; hDirACRend->hOutSetup.num_lfe = inputMasa->base.ctx.pCustomLsOut->num_lfe; + move16(); hDirACRend->hOutSetup.index_lfe[0] = inputMasa->base.ctx.pCustomLsOut->lfe_idx[0]; + move16(); hDirACRend->hOutSetup.is_loudspeaker_setup = TRUE; - hDirACRend->hOutSetup.is_planar_setup = (Word8) inputMasa->base.ctx.pCustomLsOut->is_planar_setup; - move16(); - move16(); move16(); + hDirACRend->hOutSetup.is_planar_setup = (Word8) inputMasa->base.ctx.pCustomLsOut->is_planar_setup; move16(); } @@ -13605,7 +13666,8 @@ static ivas_error ivas_masa_ext_rend_dirac_rend_init( { hDirACRend->hOutSetup.ambisonics_order = SBA_HOA3_ORDER; /* Order 3 is used by default in DirAC for SHD processing */ move16(); - IF( EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_MONO ) || EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_STEREO ) ) + test(); + if ( EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_MONO ) || EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_STEREO ) ) { hDirACRend->hOutSetup.ambisonics_order = SBA_FOA_ORDER; move16(); @@ -13625,10 +13687,10 @@ static ivas_error ivas_masa_ext_rend_dirac_rend_init( IF( EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_MONO ) ) { hDirACRend->synthesisConf = DIRAC_SYNTHESIS_MONO; - hDirACRend->panningConf = DIRAC_PANNING_HOA3; - nchan_out_woLFE = 1; move32(); + hDirACRend->panningConf = DIRAC_PANNING_HOA3; move32(); + nchan_out_woLFE = 1; move16(); } ELSE IF( hDirACRend->hOutSetup.is_loudspeaker_setup ) @@ -13641,15 +13703,15 @@ static ivas_error ivas_masa_ext_rend_dirac_rend_init( ELSE IF( !hDirACRend->hOutSetup.is_loudspeaker_setup && GT_16( nchan_transport, 1 ) ) { hDirACRend->synthesisConf = DIRAC_SYNTHESIS_PSD_SHD; - hDirACRend->panningConf = DIRAC_PANNING_HOA3; move32(); + hDirACRend->panningConf = DIRAC_PANNING_HOA3; move32(); } ELSE { hDirACRend->synthesisConf = DIRAC_SYNTHESIS_GAIN_SHD; - hDirACRend->panningConf = DIRAC_PANNING_HOA3; move32(); + hDirACRend->panningConf = DIRAC_PANNING_HOA3; move32(); } @@ -13688,39 +13750,35 @@ static ivas_error ivas_masa_ext_rend_dirac_rend_init( { /* Directional and diffuses components in output LS format */ hDirACRend->num_outputs_diff = nchan_out_woLFE; - hDirACRend->num_outputs_dir = nchan_out_woLFE; move16(); + hDirACRend->num_outputs_dir = nchan_out_woLFE; move16(); } ELSE IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) { /* Directional and diffuses components in SHD */ /* Diffuseness components up to 1st order */ - hDirACRend->num_outputs_diff = imult1616( ( s_min( hDirACRend->hOutSetup.ambisonics_order, 1 ) + 1 ), ( add( s_min( hDirACRend->hOutSetup.ambisonics_order, 1 ), 1 ) ) ); + hDirACRend->num_outputs_diff = imult1616( add( s_min( hDirACRend->hOutSetup.ambisonics_order, 1 ), 1 ), ( add( s_min( hDirACRend->hOutSetup.ambisonics_order, 1 ), 1 ) ) ); hDirACRend->num_outputs_dir = ivas_sba_get_nchan_fx( hDirACRend->hOutSetup.ambisonics_order, 0 ); - move16(); - move16(); } ELSE IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_PSD_SHD ) ) { hDirACRend->num_outputs_diff = DIRAC_HOA_RENDERING_NUM_VIRT_DECORR_LS; - hDirACRend->num_outputs_dir = nchan_out_woLFE; move16(); + hDirACRend->num_outputs_dir = nchan_out_woLFE; move16(); } ELSE IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_MONO ) ) { hDirACRend->num_outputs_diff = 1; /* There is one output channel in mono */ - hDirACRend->num_outputs_dir = 2; /* Two channels are pre-rendered for stereo type detection */ move16(); + hDirACRend->num_outputs_dir = 2; /* Two channels are pre-rendered for stereo type detection */ move16(); } ELSE { assert( 0 && "DirAC: not existing synthesis methods!" ); } - move16(); - move16(); IF( ( hDirACRend->proto_index_dir = (Word16 *) malloc( sizeof( Word16 ) * hDirACRend->num_outputs_dir ) ) == NULL ) { @@ -13740,10 +13798,10 @@ static ivas_error ivas_masa_ext_rend_dirac_rend_init( IF( EQ_16( nchan_transport, 1 ) ) { hDirACRend->num_protos_ambi = 1; - hDirACRend->num_protos_dir = 1; - hDirACRend->num_protos_diff = 1; move16(); + hDirACRend->num_protos_dir = 1; move16(); + hDirACRend->num_protos_diff = 1; move16(); } ELSE IF( EQ_16( nchan_transport, 2 ) ) @@ -13751,33 +13809,33 @@ static ivas_error ivas_masa_ext_rend_dirac_rend_init( IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) { hDirACRend->num_protos_ambi = 2; - hDirACRend->num_protos_diff = 1; - hDirACRend->num_protos_dir = 2; - hDirACRend->proto_index_dir[1] = 1; move16(); + hDirACRend->num_protos_diff = 1; move16(); + hDirACRend->num_protos_dir = 2; move16(); + hDirACRend->proto_index_dir[1] = 1; move16(); } ELSE IF( EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_MONO ) ) { /* Following the foa rendering for code compatibility */ hDirACRend->num_protos_ambi = 2; - hDirACRend->num_protos_dir = 2; - hDirACRend->num_protos_diff = 3; - hDirACRend->proto_index_dir[0] = 0; - hDirACRend->proto_index_diff[0] = 0; move16(); + hDirACRend->num_protos_dir = 2; move16(); + hDirACRend->num_protos_diff = 3; move16(); + hDirACRend->proto_index_dir[0] = 0; move16(); + hDirACRend->proto_index_diff[0] = 0; move16(); } ELSE { hDirACRend->num_protos_ambi = 2; - hDirACRend->num_protos_diff = 3; move16(); + hDirACRend->num_protos_diff = 3; move16(); FOR( k = 0; k < hDirACRend->num_outputs_diff; k++ ) @@ -13806,8 +13864,8 @@ static ivas_error ivas_masa_ext_rend_dirac_rend_init( ELSE { hDirACRend->num_protos_dir = 2; - hDirACRend->proto_index_dir[1] = 1; move16(); + hDirACRend->proto_index_dir[1] = 1; move16(); } } @@ -13841,7 +13899,7 @@ static ivas_error ivas_masa_ext_rend_dirac_rend_init( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); } - set32_fx( hDirACRend->hoa_encoder_fx, 0, nchan_out_woLFE * hDirACRend->num_outputs_diff ); + set32_fx( hDirACRend->hoa_encoder_fx, 0, imult1616( nchan_out_woLFE, hDirACRend->num_outputs_diff ) ); compute_hoa_encoder_mtx_fx( ls_azimuth_fx, ls_elevation_fx, hDirACRend->hoa_encoder_fx, hDirACRend->num_outputs_diff, hDirACRend->hOutSetup.ambisonics_order ); } @@ -13874,7 +13932,7 @@ static ivas_error ivas_masa_ext_rend_dirac_rend_init( /* decorrelation */ hDirACRend->proto_signal_decorr_on = 1; move16(); - IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_MONO ) ) + if ( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_MONO ) ) { hDirACRend->proto_signal_decorr_on = 0; move16(); @@ -13906,7 +13964,7 @@ static ivas_error ivas_masa_ext_rend_dirac_rend_init( move16(); test(); - IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_PSD_SHD ) || EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) + if ( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_PSD_SHD ) || EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) { hDirACRend->h_output_synthesis_psd_params.use_onset_filters = 0; move16(); @@ -14466,8 +14524,8 @@ static ivas_error ivas_masa_ext_rend_parambin_init( /* Set common variables and defaults */ output_Fs = *( inputMasa->base.ctx.pOutSampleRate ); - nBins = inputMasa->hMasaExtRend->hSpatParamRendCom->num_freq_bands; move32(); + nBins = inputMasa->hMasaExtRend->hSpatParamRendCom->num_freq_bands; move16(); renderer_type = inputMasa->hMasaExtRend->renderer_type; move32(); @@ -14543,7 +14601,7 @@ static ivas_error ivas_masa_ext_rend_parambin_init( tmpFloat_fx = s_max( 0, sub( shl_sat( 1, sub( 15, tmp_e ) ), tmp ) ) /*max( 0.0f, 1.0f - binCenterFreq / 2700.0f )*/; /*Q30*/ tmp2 = extract_l( Mult_32_32( binCenterFreq_fx, 1952258 /*=2^31*180/(550)/360*/ ) % 32767 ); //*binCenterFreq_fx * EVS_PI / 550.0f*/ hDiracDecBin->diffuseFieldCoherence_fx[bin] = L_shl( L_mult0( divide3232( tmpFloat_fx, Mult_32_16( binCenterFreq_fx, 187 /*2^15*pi/550*/ ) ), getSineWord16R2( tmp2 ) ), tmp_e ); /*tmpFloat * sinf( binCenterFreq * EVS_PI / 550.0f ) / ( binCenterFreq * EVS_PI / 550.0f );*/ - hDiracDecBin->diffuseFieldCoherence_fx[bin] = L_shl( hDiracDecBin->diffuseFieldCoherence_fx[bin], 1 ); // Q31 + hDiracDecBin->diffuseFieldCoherence_fx[bin] = L_shl( hDiracDecBin->diffuseFieldCoherence_fx[bin], 1 ); /* Q31 */ move32(); move32(); } @@ -14606,7 +14664,7 @@ static ivas_error ivas_masa_ext_rend_parambin_init( return error; } /* External renderer uses constant regularization factor */ - hDiracDecBin->reqularizationFactor_fx = 6554; + hDiracDecBin->reqularizationFactor_fx = 6554; /* 0.4f in Q14 */ move16(); inputMasa->hMasaExtRend->hDiracDecBin = hDiracDecBin; @@ -15118,7 +15176,7 @@ static void intermidiate_ext_dirac_render( move16(); FOR( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[subframe_idx]; slot_idx++ ) { - Scale_sig32( hDirACRend->h_output_synthesis_psd_state.direct_responses_fx, i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_dir ), sub( Q30, hDirACRend->h_output_synthesis_psd_state.direct_responses_q ) ); + Scale_sig32( hDirACRend->h_output_synthesis_psd_state.direct_responses_fx, i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_dir ), sub( Q30, hDirACRend->h_output_synthesis_psd_state.direct_responses_q ) ); /* Q30 */ hDirACRend->h_output_synthesis_psd_state.direct_responses_q = Q30; move16(); } @@ -15126,22 +15184,22 @@ static void intermidiate_ext_dirac_render( IF( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_fx ) { Word16 shift = L_norm_arr( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_fx, hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_len ); - scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_fx, hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_len, shift ); + scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_fx, hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_len, shift ); /* Q(hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth + shift) */ hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth = add( hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth, shift ); move16(); } IF( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev_fx ) { Word16 shift = L_norm_arr( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev_fx, hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev_len ); - scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev_fx, hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev_len, shift ); + scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev_fx, hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev_len, shift ); /* Q(hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev + shift) */ hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev = add( hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev, shift ); move16(); } IF( hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_fx ) { - Word16 shift = L_norm_arr( hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_fx, hDirACRend->num_outputs_dir * hSpatParamRendCom->num_freq_bands ); - scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_fx, hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_len, shift ); + Word16 shift = L_norm_arr( hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_fx, imult1616( hDirACRend->num_outputs_dir, hSpatParamRendCom->num_freq_bands ) ); + scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_fx, hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_len, shift ); /* Q(hDirACRend->h_output_synthesis_psd_state.q_cy_auto_dir_smooth + shift) */ hDirACRend->h_output_synthesis_psd_state.q_cy_auto_dir_smooth = add( hDirACRend->h_output_synthesis_psd_state.q_cy_auto_dir_smooth, shift ); move16(); } @@ -15157,8 +15215,8 @@ static void intermidiate_ext_dirac_render( IF( h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx ) { - tmp = L_norm_arr( h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx, num_channels_dir * hSpatParamRendCom->num_freq_bands ); - scale_sig32( h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx, hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_len, tmp ); + tmp = L_norm_arr( h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx, imult1616( num_channels_dir, hSpatParamRendCom->num_freq_bands ) ); + scale_sig32( h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx, hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_len, tmp ); /* Q(h_dirac_output_synthesis_state->q_cy_auto_diff_smooth + tmp) */ h_dirac_output_synthesis_state->q_cy_auto_diff_smooth = add( h_dirac_output_synthesis_state->q_cy_auto_diff_smooth, tmp ); move16(); } @@ -15166,21 +15224,21 @@ static void intermidiate_ext_dirac_render( IF( hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_prev_fx ) { tmp = L_norm_arr( hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_prev_fx, hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_prev_len ); - scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_prev_fx, hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_prev_len, tmp ); + scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_prev_fx, hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_prev_len, tmp ); /* Q(hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth_prev + tmp) */ hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth_prev = add( hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth_prev, tmp ); move16(); } - scale_sig32( hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_fx, hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_len, Q26 - hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_q ); + scale_sig32( hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_fx, hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_len, sub( Q26, hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_q ) ); /* Q26 */ hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_q = Q26; move16(); - scale_sig32( hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_fx, hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_len, Q26 - hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_q ); + scale_sig32( hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_fx, hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_len, sub( Q26, hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_q ) ); /* Q26 */ hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_q = Q26; move16(); IF( hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_prev_fx ) { - Word16 shift = L_norm_arr( hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_prev_fx, hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_dir ); - scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_prev_fx, hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_prev_len, shift ); + Word16 shift = L_norm_arr( hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_prev_fx, imult1616( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_dir ) ); + scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_prev_fx, hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_prev_len, shift ); /* Q(hDirACRend->h_output_synthesis_psd_state.q_cy_auto_dir_smooth_prev + shift) */ hDirACRend->h_output_synthesis_psd_state.q_cy_auto_dir_smooth_prev = add( hDirACRend->h_output_synthesis_psd_state.q_cy_auto_dir_smooth_prev, shift ); move16(); } @@ -15188,7 +15246,7 @@ static void intermidiate_ext_dirac_render( IF( EQ_16( hDirACRend->proto_signal_decorr_on, 1 ) ) { tmp = L_norm_arr( hDirACRend->h_freq_domain_decorr_ap_state->decorr_buffer_fx, hDirACRend->h_freq_domain_decorr_ap_state->decorr_buffer_len ); - scale_sig32( hDirACRend->h_freq_domain_decorr_ap_state->decorr_buffer_fx, hDirACRend->h_freq_domain_decorr_ap_state->decorr_buffer_len, tmp ); + scale_sig32( hDirACRend->h_freq_domain_decorr_ap_state->decorr_buffer_fx, hDirACRend->h_freq_domain_decorr_ap_state->decorr_buffer_len, tmp ); /* Q(hDirACRend->h_freq_domain_decorr_ap_state->q_decorr_buffer + tmp) */ hDirACRend->h_freq_domain_decorr_ap_state->q_decorr_buffer = add( hDirACRend->h_freq_domain_decorr_ap_state->q_decorr_buffer, tmp ); move16(); } @@ -15224,8 +15282,9 @@ static void intermidiate_ext_dirac_render( Word16 hr_exp = sub( 31, shift ); - Scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_fx, hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_len, sub( sub( 31, hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_q ), hr_exp ) ); + Scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_fx, hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_len, sub( sub( 31, hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_q ), hr_exp ) ); /* Q(31 - hr_exp) */ hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_q = sub( 31, hr_exp ); + move16(); } FOR( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[subframe_idx]; slot_idx++ ) @@ -15242,25 +15301,25 @@ static void intermidiate_ext_dirac_render( IF( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_fx ) { - tmp = L_norm_arr( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_fx, hDirACRend->num_protos_dir * hSpatParamRendCom->num_freq_bands ); - scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_fx, hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_len, tmp ); + tmp = L_norm_arr( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_fx, imult1616( hDirACRend->num_protos_dir, hSpatParamRendCom->num_freq_bands ) ); + scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_fx, hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_len, tmp ); /* Q(hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q + tmp) */ hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q = add( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q, tmp ); move16(); - tmp = L_norm_arr( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_fx, hDirACRend->num_protos_dir * hSpatParamRendCom->num_freq_bands ); - scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_fx, hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_len, tmp ); + tmp = L_norm_arr( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_fx, imult1616( hDirACRend->num_protos_dir, hSpatParamRendCom->num_freq_bands ) ); + scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_fx, hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_len, tmp ); /* Q(hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q + tmp) */ hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q = add( tmp, hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q ); move16(); } tmp = L_norm_arr( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_fx, hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_len ); - scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_fx, hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_len, tmp ); + scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_fx, hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_len, tmp ); /* Q(hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_q + tmp) */ hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_q = add( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_q, tmp ); move16(); IF( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_fx != 0 ) { tmp = L_norm_arr( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_fx, hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_len ); - scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_fx, hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_len, tmp ); + scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_fx, hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_len, tmp ); /* Q(hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_q + tmp) */ hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_q = add( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_q, tmp ); move16(); } @@ -15272,7 +15331,7 @@ static void intermidiate_ext_dirac_render( /* CLDFB Analysis*/ FOR( ch = 0; ch < nchan_transport; ch++ ) { - scale_sig32( hMasaExtRend->cldfbAnaRend[ch]->cldfb_state_fx, hMasaExtRend->cldfbAnaRend[ch]->cldfb_size, sub( Q11, hMasaExtRend->cldfbAnaRend[0]->Q_cldfb_state ) ); + scale_sig32( hMasaExtRend->cldfbAnaRend[ch]->cldfb_state_fx, hMasaExtRend->cldfbAnaRend[ch]->cldfb_size, sub( Q11, hMasaExtRend->cldfbAnaRend[0]->Q_cldfb_state ) ); /* Q11 */ hMasaExtRend->cldfbAnaRend[ch]->Q_cldfb_state = Q11; move16(); } @@ -15280,7 +15339,7 @@ static void intermidiate_ext_dirac_render( FOR( ch = 0; ch < hDirACRend->hOutSetup.nchan_out_woLFE + hDirACRend->hOutSetup.num_lfe; ch++ ) { - scale_sig32( hMasaExtRend->cldfbSynRend[ch]->cldfb_state_fx, hMasaExtRend->cldfbSynRend[ch]->cldfb_size, sub( Q11, hMasaExtRend->cldfbSynRend[0]->Q_cldfb_state ) ); + scale_sig32( hMasaExtRend->cldfbSynRend[ch]->cldfb_state_fx, hMasaExtRend->cldfbSynRend[ch]->cldfb_size, sub( Q11, hMasaExtRend->cldfbSynRend[0]->Q_cldfb_state ) ); /* Q11 */ hMasaExtRend->cldfbSynRend[ch]->Q_cldfb_state = Q11; move16(); } diff --git a/lib_rend/lib_rend.h b/lib_rend/lib_rend.h index beb2af289..1d8c36cf5 100644 --- a/lib_rend/lib_rend.h +++ b/lib_rend/lib_rend.h @@ -133,12 +133,12 @@ typedef enum _IVAS_REND_COMPLEXITY_LEVEL #ifdef IVAS_FLOAT_FIXED ivas_error IVAS_REND_Open( - IVAS_REND_HANDLE *phIvasRend, /* i/o: Pointer to renderer handle */ - const Word32 outputSampleRate, /* i : output sampling rate */ - const IVAS_AUDIO_CONFIG outConfig, /* i : output audio config */ - const Word16 nonDiegeticPan, /* i : non-diegetic object flag */ - const Word32 nonDiegeticPanGain, /* i : non-diegetic panning gain */ - const Word16 num_subframes /* i : number of subframes */ + IVAS_REND_HANDLE *phIvasRend, /* i/o: Pointer to renderer handle */ + const Word32 outputSampleRate, /* i : output sampling rate */ + const IVAS_AUDIO_CONFIG outConfig, /* i : output audio config */ + const Word16 nonDiegeticPan, /* i : non-diegetic object flag */ + const Word32 nonDiegeticPanGain, /* i : non-diegetic panning gain Q31 */ + const Word16 num_subframes /* i : number of subframes */ ); #else ivas_error IVAS_REND_Open( @@ -149,7 +149,7 @@ ivas_error IVAS_REND_Open( const float nonDiegeticPanGain, /* i : non-diegetic panning gain */ const int16_t num_subframes /* i : number of subframes */ ); -#endif // IVAS_FLOAT_FIXED +#endif /* Note: this will reset custom LFE routings set for any MC input */ ivas_error IVAS_REND_ConfigureCustomOutputLoudspeakerLayout( @@ -160,30 +160,30 @@ ivas_error IVAS_REND_ConfigureCustomOutputLoudspeakerLayout( /* Functions to be called before/during rendering */ -#ifndef IVAS_FLOAT_FIXED +#ifdef IVAS_FLOAT_FIXED ivas_error IVAS_REND_NumOutChannels( IVAS_REND_CONST_HANDLE hIvasRend, /* i : Renderer handle */ - int16_t *numOutChannels /* o : number of output channels */ + Word16 *numOutChannels /* o : number of output channels */ +); + +ivas_error IVAS_REND_AddInput_fx( + IVAS_REND_HANDLE hIvasRend, /* i/o: Renderer handle */ + const IVAS_AUDIO_CONFIG inConfig, /* i : audio config for a new input */ + IVAS_REND_InputId *inputId /* o : ID of the new input */ ); #else ivas_error IVAS_REND_NumOutChannels( IVAS_REND_CONST_HANDLE hIvasRend, /* i : Renderer handle */ - Word16 *numOutChannels /* o : number of output channels */ + int16_t *numOutChannels /* o : number of output channels */ ); -#endif ivas_error IVAS_REND_AddInput( IVAS_REND_HANDLE hIvasRend, /* i/o: Renderer handle */ const IVAS_AUDIO_CONFIG inConfig, /* i : audio config for a new input */ IVAS_REND_InputId *inputId /* o : ID of the new input */ ); -#ifdef IVAS_FLOAT_FIXED -ivas_error IVAS_REND_AddInput_fx( - IVAS_REND_HANDLE hIvasRend, /* i/o: Renderer handle */ - const IVAS_AUDIO_CONFIG inConfig, /* i : audio config for a new input */ - IVAS_REND_InputId *inputId /* o : ID of the new input */ -); #endif + /* Note: this will reset any custom LFE routing set for the input */ ivas_error IVAS_REND_ConfigureCustomInputLoudspeakerLayout( IVAS_REND_HANDLE hIvasRend, /* i/o: Renderer handle */ @@ -191,24 +191,33 @@ ivas_error IVAS_REND_ConfigureCustomInputLoudspeakerLayout( const IVAS_CUSTOM_LS_DATA layout /* i : custom loudspeaker layout for input */ ); -ivas_error IVAS_REND_SetInputGain( - IVAS_REND_HANDLE hIvasRend, /* i/o: Renderer handle */ - const IVAS_REND_InputId inputId, /* i : ID of the input */ - const float gain /* i : linear gain (not in dB) */ -); #ifdef IVAS_FLOAT_FIXED ivas_error IVAS_REND_SetInputGain_fx( - IVAS_REND_HANDLE hIvasRend, /* i/o: Renderer handle */ - const IVAS_REND_InputId inputId, /* i : ID of the input */ - const Word32 gain /* i : linear gain (not in dB) */ + IVAS_REND_HANDLE hIvasRend, /* i/o: Renderer handle */ + const IVAS_REND_InputId inputId, /* i : ID of the input */ + const Word32 gain /* i : linear gain (not in dB) Q30 */ ); ivas_error IVAS_REND_SetInputLfeMtx_fx( - IVAS_REND_HANDLE hIvasRend, /* i/o: Renderer handle */ - const IVAS_REND_InputId inputId, /* i : ID of the input */ - const IVAS_REND_LfePanMtx_fx *lfePanMtx /* i : LFE panning matrix */ + IVAS_REND_HANDLE hIvasRend, /* i/o: Renderer handle */ + const IVAS_REND_InputId inputId, /* i : ID of the input */ + const IVAS_REND_LfePanMtx_fx *lfePanMtx /* i : LFE panning matrix */ +); + +ivas_error IVAS_REND_SetInputLfePos_fx( + IVAS_REND_HANDLE hIvasRend, /* i/o: Renderer handle */ + const IVAS_REND_InputId inputId, /* i : ID of the input */ + const Word32 inputGain, /* i : Input gain to be applied to the LFE channel(s) Q31 */ + const Word16 outputAzimuth, /* i : Output azimuth position Q0 */ + const Word16 outputElevation /* i : Output elevation position Q0 */ +); +#else +ivas_error IVAS_REND_SetInputGain( + IVAS_REND_HANDLE hIvasRend, /* i/o: Renderer handle */ + const IVAS_REND_InputId inputId, /* i : ID of the input */ + const float gain /* i : linear gain (not in dB) */ ); -#endif // IVAS_FLOAT_FIXED + ivas_error IVAS_REND_SetInputLfeMtx( IVAS_REND_HANDLE hIvasRend, /* i/o: Renderer handle */ const IVAS_REND_InputId inputId, /* i : ID of the input */ @@ -222,15 +231,8 @@ ivas_error IVAS_REND_SetInputLfePos( const float outputAzimuth, /* i : Output azimuth position */ const float outputElevation /* i : Output elevation position */ ); -#ifdef IVAS_FLOAT_FIXED -ivas_error IVAS_REND_SetInputLfePos_fx( - IVAS_REND_HANDLE hIvasRend, /* i/o: Renderer handle */ - const IVAS_REND_InputId inputId, /* i : ID of the input */ - const Word32 inputGain, /* i : Input gain to be applied to the LFE channel(s) */ - const Word16 outputAzimuth, /* i : Output azimuth position */ - const Word16 outputElevation /* i : Output elevation position */ -); -#endif // IVAS_FLOAT_FIXED +#endif + ivas_error IVAS_REND_RemoveInput( IVAS_REND_HANDLE hIvasRend, /* i/o: Renderer handle */ const IVAS_REND_InputId inputId /* i : ID of the input */ @@ -240,7 +242,13 @@ ivas_error IVAS_REND_RemoveInput( ivas_error IVAS_REND_GetInputNumChannels( IVAS_REND_CONST_HANDLE hIvasRend, /* i : Renderer handle */ const IVAS_REND_InputId inputId, /* i : ID of the input */ - Word16 *numChannels /* o : number of channels of the input */ + Word16 *numChannels /* o : number of channels of the input */ +); + +ivas_error IVAS_REND_GetDelay_fx( + IVAS_REND_CONST_HANDLE hIvasRend, /* i : Renderer state */ + Word16 *nSamples, /* o : Renderer delay in samples */ + Word32 *timeScale /* o : Time scale of the delay, equal to renderer output sampling rate */ ); #else ivas_error IVAS_REND_GetInputNumChannels( @@ -248,46 +256,47 @@ ivas_error IVAS_REND_GetInputNumChannels( const IVAS_REND_InputId inputId, /* i : ID of the input */ int16_t *numChannels /* o : number of channels of the input */ ); -#endif -#ifndef IVAS_FLOAT_FIXED ivas_error IVAS_REND_GetDelay( IVAS_REND_CONST_HANDLE hIvasRend, /* i : Renderer handle */ int16_t *nSamples, /* o : Renderer delay in samples */ int32_t *timeScale /* o : Time scale of the delay, equal to renderer output sampling rate */ ); -#else -ivas_error IVAS_REND_GetDelay( - IVAS_REND_CONST_HANDLE hIvasRend, /* i : Renderer handle */ - Word16 *nSamples, /* o : Renderer delay in samples */ - Word32 *timeScale /* o : Time scale of the delay, equal to renderer output sampling rate */ -); #endif -#ifdef IVAS_FLOAT_FIXED -ivas_error IVAS_REND_GetDelay_fx( - IVAS_REND_CONST_HANDLE hIvasRend, /* i : Renderer state */ - Word16 *nSamples, /* o : Renderer delay in samples */ - Word32 *timeScale /* o : Time scale of the delay, equal to renderer output sampling rate */ -); -#endif // IVAS_FLOAT_FIXED - /* Functions to be called during rendering */ -ivas_error IVAS_REND_FeedInputAudio( +#ifdef IVAS_FLOAT_FIXED +ivas_error IVAS_REND_FeedInputAudio_fx( IVAS_REND_HANDLE hIvasRend, /* i/o: Renderer handle */ const IVAS_REND_InputId inputId, /* i : ID of the input */ const IVAS_REND_ReadOnlyAudioBuffer inputAudio /* i : buffer with input audio */ ); -#ifdef IVAS_FLOAT_FIXED -ivas_error IVAS_REND_FeedInputAudio_fx( +ivas_error IVAS_REND_FeedInputObjectMetadata( + IVAS_REND_HANDLE hIvasRend, /* i/o: Renderer handle */ + const IVAS_REND_InputId inputId, /* i : ID of the input */ + const IVAS_ISM_METADATA objectPosition /* i : object position struct */ +); + +ivas_error IVAS_REND_FeedInputObjectMetadataToOMasa( + IVAS_REND_HANDLE hIvasRend, /* i/o: Renderer handle */ + const Word16 inputIndex, /* i : Index of the input */ + const IVAS_ISM_METADATA objectPosition /* i : object position struct */ +); + +ivas_error IVAS_REND_FeedInputObjectMetadataToOMasa( + IVAS_REND_HANDLE hIvasRend, /* i/o: Renderer handle */ + const Word16 inputIndex, /* i : Index of the input */ + const IVAS_ISM_METADATA objectPosition /* i : object position struct */ +); +#else +ivas_error IVAS_REND_FeedInputAudio( IVAS_REND_HANDLE hIvasRend, /* i/o: Renderer handle */ const IVAS_REND_InputId inputId, /* i : ID of the input */ const IVAS_REND_ReadOnlyAudioBuffer inputAudio /* i : buffer with input audio */ ); -#endif ivas_error IVAS_REND_FeedInputObjectMetadata( IVAS_REND_HANDLE hIvasRend, /* i/o: Renderer handle */ const IVAS_REND_InputId inputId, /* i : ID of the input */ @@ -300,6 +309,14 @@ ivas_error IVAS_REND_FeedInputObjectMetadataToOMasa( const IVAS_ISM_METADATA objectPosition /* i : object position struct */ ); +ivas_error IVAS_REND_FeedInputObjectMetadataToOMasa( + IVAS_REND_HANDLE hIvasRend, /* i/o: Renderer handle */ + const int16_t inputIndex, /* i : Index of the input */ + const IVAS_ISM_METADATA objectPosition /* i : object position struct */ +); +#endif + + ivas_error IVAS_REND_FeedInputMasaMetadata( IVAS_REND_HANDLE hIvasRend, /* i/o: Renderer handle */ const IVAS_REND_InputId inputId, /* i : ID of the input */ @@ -311,45 +328,40 @@ ivas_error IVAS_REND_InitConfig( const IVAS_AUDIO_CONFIG outAudioConfig /* i : output audioConfig */ ); -#ifndef IVAS_FLOAT_FIXED -int16_t IVAS_REND_GetRenderConfig( - IVAS_REND_HANDLE hIvasRend, /* i/o: IVAS decoder handle */ - const IVAS_RENDER_CONFIG_HANDLE hRCout /* o : Render configuration handle */ -); -#else +#ifdef IVAS_FLOAT_FIXED Word16 IVAS_REND_GetRenderConfig( IVAS_REND_HANDLE hIvasRend, /* i/o: IVAS decoder handle */ const IVAS_RENDER_CONFIG_HANDLE hRCout /* o : Render configuration handle */ ); -#endif -#ifndef IVAS_FLOAT_FIXED -int16_t IVAS_REND_FeedRenderConfig( +Word16 IVAS_REND_FeedRenderConfig( IVAS_REND_HANDLE hIvasRend, /* i/o: IVAS decoder handle */ const IVAS_RENDER_CONFIG_DATA renderConfig /* i : Render configuration struct */ ); + +ivas_error IVAS_REND_SetHeadRotation( + IVAS_REND_HANDLE hIvasRend, /* i/o: Renderer handle */ + const IVAS_QUATERNION headRot, /* i : head orientations for next rendering call */ + const IVAS_VECTOR3 Pos, /* i : listener positions for next rendering call */ + const Word16 sf_idx /* i : subframe index */ +); #else -Word16 IVAS_REND_FeedRenderConfig( +int16_t IVAS_REND_GetRenderConfig( IVAS_REND_HANDLE hIvasRend, /* i/o: IVAS decoder handle */ - const IVAS_RENDER_CONFIG_DATA renderConfig /* i : Render configuration struct */ + const IVAS_RENDER_CONFIG_HANDLE hRCout /* o : Render configuration handle */ ); -#endif +int16_t IVAS_REND_FeedRenderConfig( + IVAS_REND_HANDLE hIvasRend, /* i/o: IVAS decoder handle */ + const IVAS_RENDER_CONFIG_DATA renderConfig /* i : Render configuration struct */ +); -#ifndef IVAS_FLOAT_FIXED ivas_error IVAS_REND_SetHeadRotation( IVAS_REND_HANDLE hIvasRend, /* i/o: Renderer handle */ const IVAS_QUATERNION headRot, /* i : head orientations for next rendering call */ const IVAS_VECTOR3 Pos, /* i : listener positions for next rendering call */ const int16_t sf_idx /* i : subframe index */ ); -#else -ivas_error IVAS_REND_SetHeadRotation( - IVAS_REND_HANDLE hIvasRend, /* i/o: Renderer handle */ - const IVAS_QUATERNION headRot, /* i : head orientations for next rendering call */ - const IVAS_VECTOR3 Pos, /* i : listener positions for next rendering call */ - const Word16 sf_idx /* i : subframe index */ -); #endif /* Head rotation becomes enabled by calling IVAS_REND_SetHeadRotation. Use this to disable. */ @@ -433,31 +445,27 @@ ivas_error IVAS_REND_SetTotalNumberOfObjects( IVAS_REND_HANDLE hIvasRend, /* i/o: IVAS renderer handle */ const UWord16 total_num_objects /* i : total number of objects */ ); -#else -ivas_error IVAS_REND_SetTotalNumberOfObjects( - IVAS_REND_HANDLE hIvasRend, /* i/o: IVAS renderer handle */ - const uint16_t total_num_objects /* i : total number of objects */ -); -#endif -#ifdef IVAS_FLOAT_FIXED ivas_error IVAS_REND_SetIsmMetadataDelay( IVAS_REND_HANDLE hIvasRend, /* i/o: IVAS renderer handle */ const Word32 sync_md_delay /* i : Metadata Delay in ms to sync with audio delay */ ); -#else -ivas_error IVAS_REND_SetIsmMetadataDelay( - IVAS_REND_HANDLE hIvasRend, /* i/o: IVAS renderer handle */ - const float sync_md_delay /* i : Metadata Delay in ms to sync with audio delay */ -); -#endif -#ifdef IVAS_FLOAT_FIXED ivas_error IVAS_REND_GetNumAllObjects( IVAS_REND_CONST_HANDLE hIvasRend, /* i : Renderer handle */ Word16 *numChannels /* o : number of all objects */ ); #else +ivas_error IVAS_REND_SetTotalNumberOfObjects( + IVAS_REND_HANDLE hIvasRend, /* i/o: IVAS renderer handle */ + const uint16_t total_num_objects /* i : total number of objects */ +); + +ivas_error IVAS_REND_SetIsmMetadataDelay( + IVAS_REND_HANDLE hIvasRend, /* i/o: IVAS renderer handle */ + const float sync_md_delay /* i : Metadata Delay in ms to sync with audio delay */ +); + ivas_error IVAS_REND_GetNumAllObjects( IVAS_REND_CONST_HANDLE hIvasRend, /* i : Renderer handle */ int16_t *numChannels /* o : number of all objects */ -- GitLab From a6cce468a79921dc5ab775740a98668aad82fdc4 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Thu, 24 Oct 2024 12:32:27 +0530 Subject: [PATCH 033/128] Fix for 3gpp issue 903 --- lib_com/options.h | 1 + lib_dec/ivas_mdct_core_dec.c | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/lib_com/options.h b/lib_com/options.h index 424110028..819f2a42f 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -135,6 +135,7 @@ #define NONBE_MDCT_ST_DTX_SKIP_DEWHITENING_OF_NOISE_SHAPES_ON_SID_FRAMES /* FhG: issue 1133: skip de-whitening of bg noise shape after frameloss period if the first good frame is an SID */ #define NONBE_MDCT_ST_PLC_DO_NOT_SCALE_OLD_OUT_IF_FIRST_GOOD_IS_SID /* FhG: issue 1133: in TCX PLC, don't scale hHQ_core->old_out after applying fade to noise in burst frame error */ #define NON_BE_FIX_BASOP_819_THRESHOLD_MASA2TOTAL +#define FIX_903_ZERO_OUT_IMDCT_BUFFERS_FOR_MCT_IGNORE /* FhG: zero out all relevant imdct buffers in MCT decoding of channels with mct_chan_mode == MCT_CHAN_MODE_IGNORE */ /* ##################### End NON-BE switches ########################### */ #define FIX_740_HQ_CORE_OVA // Proposed fix to solve overlap and add issue for HQ_CORE diff --git a/lib_dec/ivas_mdct_core_dec.c b/lib_dec/ivas_mdct_core_dec.c index 90cb85cc3..7201bad8c 100644 --- a/lib_dec/ivas_mdct_core_dec.c +++ b/lib_dec/ivas_mdct_core_dec.c @@ -1862,6 +1862,15 @@ void ivas_mdct_core_reconstruct( { set_f( &synth[k * L_frame[ch]], 0.f, L_frame[ch] ); set_f( &synthFB[k * L_frame[ch]], 0.f, L_frameTCX[ch] ); +#ifdef FIX_903_ZERO_OUT_IMDCT_BUFFERS_FOR_MCT_IGNORE + /* Note: these buffers are not subframe-based, hence no indexing with k */ + set_f( &st->hHQ_core->old_outLB[0], 0.f, L_frame[ch] ); + set_f( &st->hHQ_core->old_out[0], 0.f, L_frameTCX[ch] ); + set_f( &st->hTcxDec->syn_Overl[0], 0.f, L_frame[ch] / 2 ); + set_f( &st->hTcxDec->syn_OverlFB[0], 0.f, L_frameTCX[ch] / 2 ); + set_f( &st->hTcxDec->syn_Overl_TDAC[0], 0.f, L_frame[ch] / 2 ); + set_f( &st->hTcxDec->syn_Overl_TDACFB[0], 0.f, L_frameTCX[ch] / 2 ); +#endif } } @@ -2093,6 +2102,15 @@ void ivas_mdct_core_reconstruct_fx( { set16_fx( &synth_fx[k * L_frame[ch]], 0, L_frame[ch] ); set16_fx( &synthFB_fx[k * L_frame[ch]], 0, L_frameTCX[ch] ); +#ifdef FIX_903_ZERO_OUT_IMDCT_BUFFERS_FOR_MCT_IGNORE + /* Note: these buffers are not subframe-based, hence no indexing with k */ + set16_fx( &st->hHQ_core->old_out_LB_fx[0], 0, L_frame[ch] ); + set16_fx( &st->hHQ_core->old_out_fx[0], 0, L_frameTCX[ch] ); + set16_fx( &st->hTcxDec->syn_Overl[0], 0, shr( L_frame[ch], 1 ) ); + set16_fx( &st->hTcxDec->syn_OverlFB[0], 0, shr( L_frameTCX[ch], 1 ) ); + set16_fx( &st->hTcxDec->syn_Overl_TDAC[0], 0, shr( L_frame[ch], 1 ) ); + set16_fx( &st->hTcxDec->syn_Overl_TDACFB[0], 0, shr( L_frameTCX[ch], 1 ) ); +#endif } } -- GitLab From d1458004d0e3822f33cd677d92c89e2d02c62afd Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Thu, 24 Oct 2024 13:51:44 +0530 Subject: [PATCH 034/128] Fix for 3GPP issue 948: High MLD value due to high energy in transients for MC 5.1 in MCT --- lib_dec/ivas_mct_dec.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib_dec/ivas_mct_dec.c b/lib_dec/ivas_mct_dec.c index 197c9f2a9..ae5057bc1 100644 --- a/lib_dec/ivas_mct_dec.c +++ b/lib_dec/ivas_mct_dec.c @@ -579,15 +579,15 @@ ivas_error ivas_mct_dec_fx( hdrm = getScaleFactor16( synth_fx[0], hCPE->hCoreCoder[0]->hTcxDec->L_frameTCX ); IF( hdrm != 0 ) { - sh = s_min( sub( e_sig[0], 15 ), hdrm ); + sh = s_min( sub( e_sig[0], 16 ), hdrm ); Scale_sig( synth_fx[0], hCPE->hCoreCoder[0]->hTcxDec->L_frameTCX, sh ); e_sig[0] = sub( e_sig[0], sh ); move16(); } - + hdrm = getScaleFactor16( synth_fx[1], hCPE->hCoreCoder[0]->hTcxDec->L_frameTCX ); IF( hdrm != 0 ) { - sh = s_min( sub( e_sig[1], 15 ), hdrm ); + sh = s_min( sub( e_sig[1], 16 ), hdrm ); Scale_sig( synth_fx[1], hCPE->hCoreCoder[1]->hTcxDec->L_frameTCX, sh ); e_sig[1] = sub( e_sig[1], sh ); move16(); @@ -616,11 +616,11 @@ ivas_error ivas_mct_dec_fx( IF( ( st_ivas->sba_dirac_stereo_flag != 0 ) && ( NE_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) || GE_16( cpe_id, sub( nCPE, 2 ) ) ) ) { - Copy_Scale_sig_16_32( synth_fx[n], synth_fx_32[n], L_FRAME48k, Q11 - 0 ); // Q11 + Copy_Scale_sig_16_32( synth_fx[n], synth_fx_32[n], L_FRAME48k, sub( Q11, ( sub( 15, e_sig[n] ) ) ) ); // Q11 Copy_Scale_sig_16_32( hCPE->hCoreCoder[n]->hHQ_core->old_out_fx, hCPE->hCoreCoder[n]->hHQ_core->oldOut_fx, output_frame, sub( Q11, hCPE->hCoreCoder[n]->hHQ_core->Q_old_wtda ) ); ivas_post_proc_fx( NULL, hCPE, n, synth_fx_32[n], NULL, output_frame, 1, Q11 ); #ifdef MSAN_FIX - Copy_Scale_sig_32_16( synth_fx_32[n], synth_fx[n], output_frame, 0 - Q11 ); // Q0 + Copy_Scale_sig_32_16( synth_fx_32[n], synth_fx[n], output_frame, sub( sub( 15, e_sig[n] ), Q11 ) ); // Q0 #else Copy_Scale_sig_32_16( synth_fx_32[n], synth_fx[n], L_FRAME48k, 0 - Q11 ); #endif @@ -630,7 +630,7 @@ ivas_error ivas_mct_dec_fx( Word16 output_mem_fx[L_FRAME48k]; IF( hCPE->output_mem_fx[1] != NULL ) { - Copy_Scale_sig_32_16( hCPE->output_mem_fx[1], output_mem_fx, NS2SA( sts[n]->output_Fs, 3125000 ), 0 - Q11 ); + Copy_Scale_sig_32_16( hCPE->output_mem_fx[1], output_mem_fx, NS2SA( sts[n]->output_Fs, 3125000 ), -Q11 ); } ELSE { -- GitLab From 76142da0269cc7a87a04285afb132bc83ac6f8b8 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Thu, 24 Oct 2024 14:07:12 +0530 Subject: [PATCH 035/128] SBA path functions conversion, ASAN and MSAN fixes, cleanup [x] spar process functions/ sub-functions conversion and integration [x] Cleanup of ivas_dirac_param_est_enc function [x] Few ASAN and MSAN fixes [x] Q-info updates for lib_dec and lib_rend files --- lib_com/ivas_fb_mixer.c | 220 ++++++- lib_com/ivas_prot.h | 35 +- lib_com/ivas_prot_fx.h | 20 +- lib_com/ivas_rom_com_fx.c | 106 ++-- lib_com/ivas_rom_com_fx.h | 4 +- lib_com/ivas_stat_com.h | 1 + lib_com/prot.h | 24 +- lib_com/prot_fx.h | 311 +++++----- lib_com/rom_com.c | 26 +- lib_com/rom_com_fx.c | 53 ++ lib_dec/er_scale_syn_fx.c | 16 +- lib_dec/er_sync_exc_fx.c | 140 ++--- lib_dec/er_util_fx.c | 102 ++-- lib_dec/hf_synth_fx.c | 591 +++++++++--------- lib_dec/hq_classifier_dec_fx.c | 32 +- lib_dec/hq_conf_fec_fx.c | 24 +- lib_dec/hq_core_dec_fx.c | 236 +++---- lib_dec/hq_env_dec_fx.c | 110 ++-- lib_dec/hq_hr_dec_fx.c | 112 ++-- lib_dec/swb_bwe_dec.c | 67 +- lib_dec/swb_bwe_dec_fx.c | 139 ++--- lib_dec/swb_bwe_dec_hr_fx.c | 105 ++-- lib_dec/swb_bwe_dec_lr_fx.c | 125 ++-- lib_dec/swb_tbe_dec.c | 153 +++-- lib_dec/swb_tbe_dec_fx.c | 153 +++-- lib_dec/syn_outp.c | 3 +- lib_dec/syn_outp_fx.c | 18 +- lib_dec/tcq_core_dec_fx.c | 47 +- lib_dec/tcx_utils_dec_fx.c | 87 ++- lib_dec/tns_base_dec_fx.c | 24 +- lib_enc/ivas_core_enc.c | 19 +- lib_enc/ivas_core_pre_proc_front.c | 3 + lib_enc/ivas_dirac_enc.c | 949 ++++++++++++----------------- lib_enc/ivas_mdct_core_enc.c | 5 + lib_enc/ivas_spar_encoder.c | 119 +++- lib_enc/ivas_spar_md_enc.c | 69 +++ lib_enc/ivas_stat_enc.h | 7 +- lib_enc/swb_pre_proc.c | 2 +- 38 files changed, 2270 insertions(+), 1987 deletions(-) diff --git a/lib_com/ivas_fb_mixer.c b/lib_com/ivas_fb_mixer.c index 9d54f3f0a..5da92e987 100644 --- a/lib_com/ivas_fb_mixer.c +++ b/lib_com/ivas_fb_mixer.c @@ -48,7 +48,7 @@ /*------------------------------------------------------------------------------------------* * Static functions declarations *------------------------------------------------------------------------------------------*/ - +static void ivas_cmult_fix( Word32 in1_re, Word32 in1_im, Word32 in2_re, Word32 in2_im, Word32 *out1_re, Word32 *out1_im ); static void ivas_get_active_bins( const int16_t **pActive_bins, const int16_t **pActive_bins_abs, const int16_t **pStart_offset, const int16_t **pStart_offset_ab, const int32_t sampling_rate ); static void ivas_get_ld_fb_resp( float **ppIdeal_FRs_re, float **ppIdeal_FRs_im, float **ppNew_FRs_re, float **ppNew_FRs_im, const int16_t *pActive_bins, const int16_t *pStart_offset, const int16_t num_bands, const int16_t delay, const int32_t sampling_rate ); #ifdef IVAS_FLOAT_FIXED @@ -426,6 +426,21 @@ ivas_error ivas_FB_mixer_open( set_f( hFbMixer->prior_mixer[i][j], 0, IVAS_MAX_NUM_BANDS ); } } + + Word32 *pTemp_mem_fx; + if ( ( pTemp_mem_fx = (Word32 *) malloc( sizeof( Word32 ) * fb_cfg->num_out_chans * max( fb_cfg->num_in_chans, fb_cfg->nchan_fb_in ) * IVAS_MAX_NUM_BANDS ) ) == NULL ) + { + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FB mixer" ); + } + for ( i = 0; i < fb_cfg->num_out_chans; i++ ) + { + for ( j = 0; j < fb_cfg->num_in_chans; j++ ) + { + hFbMixer->prior_mixer_fx[i][j] = pTemp_mem_fx; + pTemp_mem_fx += IVAS_MAX_NUM_BANDS; + set32_fx( hFbMixer->prior_mixer_fx[i][j], 0, IVAS_MAX_NUM_BANDS ); + } + } } if ( !spar_reconfig_flag ) @@ -506,6 +521,12 @@ ivas_error ivas_FB_mixer_open( { return error; } + Word16 index[IVAS_MAX_NUM_FB_BANDS]; + set16_fx( index, 0, IVAS_MAX_NUM_FB_BANDS ); + if ( ( error = ivas_filterbank_setup_fx( hFbMixer, sampling_rate, index ) ) != IVAS_ERR_OK ) + { + return error; + } } *hFbMixer_out = hFbMixer; @@ -1400,7 +1421,162 @@ void ivas_fb_mixer_cross_fading_fx( * * Filter bank process *-----------------------------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +void ivas_cmult_fix( Word32 in1_re, Word32 in1_im, Word32 in2_re, Word32 in2_im, Word32 *out1_re, Word32 *out1_im ) +{ + *out1_re = L_sub_sat( Mpy_32_32( in1_re, in2_re ), Mpy_32_32( in1_im, in2_im ) ); + *out1_im = L_add_sat( Mpy_32_32( in1_re, in2_im ), Mpy_32_32( in2_re, in1_im ) ); +} +void ivas_fb_mixer_process( + IVAS_FB_MIXER_HANDLE hFbMixer, /* i/o: FB mixer handle */ + Word32 ***mixer_mat_fx, /* i : mixer matrix */ + Word16 *q_mixer_mat_fx, /* i : mixer matrix */ + Word32 **ppOut_pcm_fx, /* o : output audio channels */ + Word16 *q_ppOut_pcm_fx, /*ppOut_pcm_fx resultant q*/ + const Word16 frame_len, /* i : frame length in samples */ + Word16 in_out_mixer_map[IVAS_MAX_FB_MIXER_OUT_CH][IVAS_MAX_SPAR_FB_MIXER_IN_CH] /* i/o: mixing mapping */ +) +{ + ivas_filterbank_t *pFb = hFbMixer->pFb; + Word16 num_bands = pFb->filterbank_num_bands; + move16(); + Word16 i, j, k, ch, hist; + + const Word32 *pFilterbank_bin_to_band_re_fx; + const Word32 *pFilterbank_bin_to_band_im_fx; + Word32 *pMdft_out_fx[2]; + Word32 *pOut_fr_re_fx, *pOut_fr_im_fx; + Word16 q_pOut_fr_fx = 31; + move16(); + Word32 Out_fr_re_fx[L_FRAME48k], Out_fr_im_fx[L_FRAME48k]; + Word32 Mdft_out_0_fx[L_FRAME48k * 2], Mdft_out_1_fx[L_FRAME48k * 2]; + + pOut_fr_re_fx = Out_fr_re_fx; + pOut_fr_im_fx = Out_fr_im_fx; + pMdft_out_fx[0] = Mdft_out_0_fx; + pMdft_out_fx[1] = Mdft_out_1_fx; + + FOR( ch = ( hFbMixer->fb_cfg->active_w_mixing == 0 ); ch < hFbMixer->fb_cfg->num_out_chans; ch++ ) + { + /* Run a loop of 2 to calculate current frame's filterbank output and prev frame's output */ + FOR( hist = 0; hist < 2; hist++ ) + { + set_zero_fx( pOut_fr_re_fx, frame_len ); + set_zero_fx( pOut_fr_im_fx, frame_len ); + q_pOut_fr_fx = 31; + move16(); + FOR( j = 0; j < hFbMixer->fb_cfg->num_in_chans; j++ ) + { + IF( in_out_mixer_map[ch][j] != 0 ) + { + + Word32 filterbank_mixer_bins_re_fx[L_FRAME48k]; + Word32 filterbank_mixer_bins_im_fx[L_FRAME48k]; + Word32 *pFb_inFR_re_fx = hFbMixer->ppFilterbank_inFR_re_fx[j]; + Word32 *pFb_inFR_im_fx = hFbMixer->ppFilterbank_inFR_im_fx[j]; + + set_zero_fx( filterbank_mixer_bins_re_fx, frame_len ); + set_zero_fx( filterbank_mixer_bins_im_fx, frame_len ); + + Word16 total_guard = find_guarded_bits_fx( num_bands ); + move16(); + FOR( i = 0; i < num_bands; i++ ) + { + Word16 start_offset = pFb->fb_consts.pFilterbank_bins_start_offset[i]; + move16(); + Word16 num_bins = pFb->fb_consts.pFilterbank_bins_per_band[i]; + move16(); + Word32 mixer_const_fx = hFbMixer->prior_mixer_fx[ch][j][i]; + move32(); + pFilterbank_bin_to_band_re_fx = pFb->fb_consts.ppFilterbank_FRs_fx[0][i]; + pFilterbank_bin_to_band_im_fx = pFb->fb_consts.ppFilterbank_FRs_fx[1][i]; + + FOR( k = start_offset; k < num_bins + start_offset; k++ ) + { + filterbank_mixer_bins_re_fx[k] = L_add_sat( filterbank_mixer_bins_re_fx[k], L_shr( Mpy_32_32( *pFilterbank_bin_to_band_re_fx, mixer_const_fx ), total_guard ) ); + move32(); + filterbank_mixer_bins_im_fx[k] = L_add_sat( filterbank_mixer_bins_im_fx[k], L_shr( Mpy_32_32( *pFilterbank_bin_to_band_im_fx, mixer_const_fx ), total_guard ) ); + move32(); + /*filterbank_mixer_bins_im_fx q 30 */ + /*mixer_const_fx q q_ppOut_pcm_fx */ + pFilterbank_bin_to_band_re_fx++; + pFilterbank_bin_to_band_im_fx++; + } + hFbMixer->prior_mixer_fx[ch][j][i] = mixer_mat_fx[ch][j][i]; + move32(); + } + Word16 res_q = 0; + move16(); + FOR( k = 0; k < frame_len; k++ ) + { + Word32 temp_out_re_fx, temp_out_im_fx; + + Word16 Fb_inFR_com_q = s_min( hFbMixer->q_ppFilterbank_inFR_re_fx[j], hFbMixer->q_ppFilterbank_inFR_im_fx[j] ); + Word32 inp_Fb_inFR_re, inp_Fb_inFR_im; + IF( NE_16( hFbMixer->q_ppFilterbank_inFR_re_fx[j], Fb_inFR_com_q ) ) + { + inp_Fb_inFR_re = L_shr( pFb_inFR_re_fx[k], sub( hFbMixer->q_ppFilterbank_inFR_re_fx[j], Fb_inFR_com_q ) ); + /*common q for real and imag hFbMixer->q_ppFilterbank_inFR_re_fx[j]*/ + } + ELSE + { + inp_Fb_inFR_re = pFb_inFR_re_fx[k]; + /*q hFbMixer->q_ppFilterbank_inFR_re_fx[j]*/ + move32(); + } + IF( NE_16( hFbMixer->q_ppFilterbank_inFR_im_fx[j], Fb_inFR_com_q ) ) + { + inp_Fb_inFR_im = L_shr( pFb_inFR_im_fx[k], sub( hFbMixer->q_ppFilterbank_inFR_im_fx[j], Fb_inFR_com_q ) ); + /*common q for real and imag hFbMixer->q_ppFilterbank_inFR_re_fx[j]*/ + } + ELSE + { + inp_Fb_inFR_im = pFb_inFR_im_fx[k]; + /*q hFbMixer->q_ppFilterbank_inFR_im_fx[j]*/ + move32(); + } + ivas_cmult_fix( filterbank_mixer_bins_re_fx[k], filterbank_mixer_bins_im_fx[k], inp_Fb_inFR_re, + inp_Fb_inFR_im, &temp_out_re_fx, &temp_out_im_fx ); + res_q = sub( add( sub( sub( add( 30, *q_mixer_mat_fx ), 31 ), total_guard ), Fb_inFR_com_q ), 31 ); + move16(); + Word16 q_check = s_min( q_pOut_fr_fx, res_q ); + move16(); + IF( NE_16( q_check, q_pOut_fr_fx ) ) + { + pOut_fr_re_fx[k] = L_shr( pOut_fr_re_fx[k], sub( q_pOut_fr_fx, q_check ) ); + move32(); + pOut_fr_im_fx[k] = L_shr( pOut_fr_im_fx[k], sub( q_pOut_fr_fx, q_check ) ); + move32(); + } + IF( q_check != res_q ) + { + temp_out_re_fx = L_shr( temp_out_re_fx, sub( res_q, q_check ) ); + temp_out_im_fx = L_shr( temp_out_im_fx, sub( res_q, q_check ) ); + } + res_q = q_check; + move16(); + pOut_fr_re_fx[k] = L_add_sat( pOut_fr_re_fx[k], temp_out_re_fx ); + move32(); + pOut_fr_im_fx[k] = L_add_sat( pOut_fr_im_fx[k], temp_out_im_fx ); + move32(); + } + q_pOut_fr_fx = res_q; + move16(); + } + } + ivas_imdft_fx( pOut_fr_re_fx, pOut_fr_im_fx, pMdft_out_fx[hist], frame_len ); + } + + ivas_fb_mixer_cross_fading_fx( hFbMixer, ppOut_pcm_fx, pMdft_out_fx[0], pMdft_out_fx[1], ch, frame_len, frame_len ); + q_ppOut_pcm_fx[ch] = q_pOut_fr_fx; + move16(); + } + + return; +} + +#else void ivas_fb_mixer_process( IVAS_FB_MIXER_HANDLE hFbMixer, /* i/o: FB mixer handle */ float ***mixer_mat, /* i : mixer matrix */ @@ -1415,13 +1591,27 @@ void ivas_fb_mixer_process( const float *pFilterbank_bin_to_band_re; const float *pFilterbank_bin_to_band_im; float *pMdft_out[2], *pOut_fr_re, *pOut_fr_im; +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + Word32 *pMdft_out_fx[2]; + Word32 **ppOut_pcm_fx = (Word32 **) malloc( hFbMixer->fb_cfg->num_out_chans * sizeof( Word32 * ) ); + for ( ch = 0; ch < hFbMixer->fb_cfg->num_out_chans; ch++ ) + { + ppOut_pcm_fx[ch] = (Word32 *) malloc( frame_len * sizeof( Word32 ) ); + } +#endif float Out_fr_re[L_FRAME48k], Out_fr_im[L_FRAME48k]; float Mdft_out_0[L_FRAME48k * 2], Mdft_out_1[L_FRAME48k * 2]; - +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + Word32 Mdft_out_0_fx[L_FRAME48k * 2], Mdft_out_1_fx[L_FRAME48k * 2]; +#endif pOut_fr_re = Out_fr_re; pOut_fr_im = Out_fr_im; pMdft_out[0] = Mdft_out_0; pMdft_out[1] = Mdft_out_1; +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + pMdft_out_fx[0] = Mdft_out_0_fx; + pMdft_out_fx[1] = Mdft_out_1_fx; +#endif for ( ch = ( hFbMixer->fb_cfg->active_w_mixing == 0 ); ch < hFbMixer->fb_cfg->num_out_chans; ch++ ) { @@ -1476,14 +1666,32 @@ void ivas_fb_mixer_process( ivas_imdft( pOut_fr_re, pOut_fr_im, pMdft_out[hist], frame_len ); } - +#ifndef IVAS_FLOAT_FIXED ivas_fb_mixer_cross_fading( hFbMixer, ppOut_pcm, pMdft_out[0], pMdft_out[1], ch, frame_len, frame_len ); +#else +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + Word16 q1 = Q_factor_arrL( pMdft_out[0], frame_len * 2 ); + Word16 q2 = Q_factor_arrL( pMdft_out[1], frame_len * 2 ); + Word16 q = s_min( q1, q2 ); + floatToFixed_arrL( pMdft_out[0], pMdft_out_fx[0], q, frame_len * 2 ); + floatToFixed_arrL( pMdft_out[1], pMdft_out_fx[1], q, frame_len * 2 ); +#endif + ivas_fb_mixer_cross_fading_fx( hFbMixer, ppOut_pcm_fx, pMdft_out_fx[0], pMdft_out_fx[1], ch, frame_len, frame_len ); +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + fixedToFloat_arrL( ppOut_pcm_fx[ch], ppOut_pcm[ch], q, frame_len ); +#endif +#endif } - +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + for ( ch = 0; ch < hFbMixer->fb_cfg->num_out_chans; ch++ ) + { + free( ppOut_pcm_fx[ch] ); + } + free( ppOut_pcm_fx ); +#endif return; } - - +#endif /*-----------------------------------------------------------------------------------------* * Function ivas_fb_mixer_get_in_out_mapping() * diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index db7ec4ee2..5e1214c42 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -4706,6 +4706,23 @@ int16_t ivas_chan_project_elevation_index( ); #endif +#ifdef IVAS_FLOAT_FIXED +void ivas_dirac_param_est_enc( + DIRAC_ENC_HANDLE hDirAC, + IVAS_QDIRECTION *q_direction, + const UWord8 useLowerRes, + Word32 *data_f_fx[], + Word32 **pp_fr_real_fx, + Word32 **pp_fr_imag_fx, + Word16 pp_fr_q, + const Word16 input_frame, + const IVAS_FORMAT ivas_format, + const Word16 hodirac_flag, + const Word16 nchan_fb_in, + Word16 *mono_frame_count, + Word16 *dirac_mono_flag +); +#else void ivas_dirac_param_est_enc( DIRAC_ENC_HANDLE hDirAC, IVAS_QDIRECTION *q_direction, @@ -4720,6 +4737,7 @@ void ivas_dirac_param_est_enc( int16_t *mono_frame_count, int16_t *dirac_mono_flag ); +#endif void ivas_sba_config( @@ -8409,14 +8427,25 @@ void ivas_fb_mixer_get_windowed_fr( const int16_t nchan_fb_in /* i : number of analysis channels */ ); +#ifdef IVAS_FLOAT_FIXED void ivas_fb_mixer_process( IVAS_FB_MIXER_HANDLE hFbMixer, /* i/o: FB mixer handle */ - float ***mixer_mat, /* i : mixer matrix */ - float **ppOut_pcm, /* o : output audio channels */ + Word32 ***mixer_mat_fx, /* i : mixer matrix in q_mixer_mat_fx */ + Word16 *q_mixer_mat_fx, /* i : mixer matrix */ + Word32 **ppOut_pcm_fx, /* o : output audio channels in ppOut_pcm_fx resultant */ + Word16 *q_ppOut_pcm_fx, /*ppOut_pcm_fx resultant q*/ const int16_t frame_len, /* i : frame length in samples */ int16_t in_out_mixer_map[IVAS_MAX_FB_MIXER_OUT_CH][IVAS_MAX_SPAR_FB_MIXER_IN_CH] /* i/o: mixing mapping */ ); - +#else +void ivas_fb_mixer_process( + IVAS_FB_MIXER_HANDLE hFbMixer, /* i/o: FB mixer handle */ + float ***mixer_mat, /* i : mixer matrix */ + float **ppOut_pcm, /* o : output audio channels */ + const int16_t frame_len, /* i : frame length in samples */ + int16_t in_out_mixer_map[IVAS_MAX_FB_MIXER_OUT_CH][IVAS_MAX_SPAR_FB_MIXER_IN_CH] /* i/o: mixing mapping */ +); +#endif void ivas_fb_mixer_get_in_out_mapping( const IVAS_FB_CFG *fb_cfg, /* i : FB config. handle */ int16_t in_out_mixer_map[IVAS_MAX_FB_MIXER_OUT_CH][IVAS_MAX_SPAR_FB_MIXER_IN_CH] /* i/o: mixing mapping */ diff --git a/lib_com/ivas_prot_fx.h b/lib_com/ivas_prot_fx.h index 07f548f32..121570bc3 100644 --- a/lib_com/ivas_prot_fx.h +++ b/lib_com/ivas_prot_fx.h @@ -1911,16 +1911,16 @@ void ivas_GenShapedWBExcitation_fx( const Word16 uv_flag, /* i : unvoiced flag */ const Word16 igf_flag ); -Word16 ivas_wb_bwe_dec_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word16 output[], /* i : suntehsis @ internal Fs */ - Word16 *synth_fx, /* i/o: ACELP core synthesis/final synthesis */ - Word16 *hb_synth_fx, /* o : SHB synthesis/final synthesis */ - const Word16 use_cldfb_for_dft, /* i : flag to use of CLDFB for DFT Stereo */ - const Word16 output_frame, /* i : frame length */ - Word16 *voice_factors_fx, /* i : voicing factors */ - const Word16 pitch_buf_fx[], /* i : pitch buffer */ - Word16 *Qpost ); +Word16 ivas_wb_bwe_dec_fx( /* o : Q_syn_hb*/ + Decoder_State *st_fx, /* i/o: decoder state structure */ + const Word16 output[], /* i : suntehsis @ internal Fs Q_input */ + Word16 *synth_fx, /* i/o: ACELP core synthesis/final synthesis Q0/Qpost */ + Word16 *hb_synth_fx, /* o : SHB synthesis/final synthesis Q_syn_hb */ + const Word16 use_cldfb_for_dft, /* i : flag to use of CLDFB for DFT Stereo */ + const Word16 output_frame, /* i : frame length */ + Word16 *voice_factors_fx, /* i : voicing factors Q15 */ + const Word16 pitch_buf_fx[], /* i : pitch buffer Q6 */ + Word16 *Qpost ); void ivas_param_ism_config_fx( PARAM_ISM_CONFIG_HANDLE hParamIsm, /* i/o: IVAS Param ISM Config Structure */ diff --git a/lib_com/ivas_rom_com_fx.c b/lib_com/ivas_rom_com_fx.c index 269c62d28..200c376cb 100644 --- a/lib_com/ivas_rom_com_fx.c +++ b/lib_com/ivas_rom_com_fx.c @@ -1634,46 +1634,76 @@ const Word32 shoebox_sin_cos_tbl_fx[11][2] = { { 0, 1073741824 }, // 0 { 759250112, -759250112 }, { -759250112, -759250112 } }; // 135, -135 //Q.30 -const Word32 delta_phi_val[90] = { - 0, 1509949440, 754974720, 503316480, 377487360, 301989888, - 251658240, 215707056, 188743680, 167772160, 150994944, - 137268128, 125829120, 116149960, 107853528, 100663296, - 94371840, 88820552, 83886080, 79471024, 75497472, - 71902352, 68634064, 65649976, 62914560, 60397976, - 58074980, 55924052, 53926764, 52067224, 50331648, - 48708048, 47185920, 45756044, 44410276, 43141412, - 41943040, 40809444, 39735512, 38716652, 37748736, - 36828036, 35951176, 35115104, 34317032, 33554432, - 32824988, 32126584, 31457280, 30815294, 30198988, - 29606852, 29037490, 28489612, 27962026, 27453626, - 26963382, 26490342, 26033612, 25592364, 25165824, - 24753270, 24354024, 23967452, 23592960, 23229992, - 22878022, 22536558, 22205138, 21883326, 21570706, - 21266894, 20971520, 20684238, 20404722, 20132660, - 19867756, 19609732, 19358326, 19113284, 18874368, - 18641352, 18414018, 18192162, 17975588, 17764112, - 17557552, 17355740, 17158516, 16965724 +const Word32 delta_phi_val[257] = { + 0, + 1509949440, 754974720, 503316480, 377487360, 301989888, 251658240, 215707056, 188743680, + 167772160, 150994944, 137268128, 125829120, 116149960, 107853528, 100663296, 94371840, + 88820552, 83886080, 79471024, 75497472, 71902352, 68634064, 65649976, 62914560, + 60397976, 58074980, 55924052, 53926764, 52067224, 50331648, 48708048, 47185920, + 45756044, 44410276, 43141412, 41943040, 40809444, 39735512, 38716652, 37748736, + 36828036, 35951176, 35115104, 34317032, 33554432, 32824988, 32126584, 31457280, + 30815294, 30198988, 29606852, 29037490, 28489612, 27962026, 27453626, 26963382, + 26490342, 26033612, 25592364, 25165824, 24753270, 24354024, 23967452, 23592960, + 23229992, 22878022, 22536558, 22205138, 21883326, 21570706, 21266894, 20971520, + 20684238, 20404722, 20132660, 19867756, 19609732, 19358326, 19113284, 18874368, + 18641352, 18414018, 18192162, 17975588, 17764112, 17557552, 17355740, 17158516, + 16965724, 16777216, 16592851, 16412494, 16236015, 16063292, 15894205, 15728640, + 15566489, 15407647, 15252015, 15099494, 14949994, 14803426, 14659703, 14518745, + 14380471, 14244806, 14111677, 13981013, 13852747, 13726813, 13603148, 13481691, + 13362384, 13245171, 13129995, 13016806, 12905551, 12796182, 12688651, 12582912, + 12478921, 12376635, 12276012, 12177012, 12079596, 11983726, 11889366, 11796480, + 11705034, 11614996, 11526332, 11439011, 11353003, 11268279, 11184811, 11102569, + 11021529, 10941663, 10862946, 10785353, 10708861, 10633447, 10559087, 10485760, + 10413444, 10342119, 10271765, 10202361, 10133889, 10066330, 9999665, 9933878, + 9868951, 9804866, 9741609, 9679163, 9617512, 9556642, 9496537, 9437184, + 9378568, 9320676, 9263493, 9207009, 9151209, 9096081, 9041613, 8987794, + 8934612, 8882056, 8830114, 8778776, 8728031, 8677870, 8628283, 8579258, + 8530788, 8482862, 8435472, 8388608, 8342262, 8296425, 8251090, 8206247, + 8161889, 8118007, 8074596, 8031646, 7989150, 7947102, 7905494, 7864320, + 7823572, 7783244, 7743330, 7703823, 7664718, 7626007, 7587685, 7549747, + 7512186, 7474997, 7438174, 7401713, 7365607, 7329851, 7294441, 7259372, + 7224638, 7190235, 7156158, 7122403, 7088964, 7055838, 7023020, 6990506, + 6958292, 6926373, 6894746, 6863406, 6832350, 6801574, 6771073, 6740845, + 6710886, 6681192, 6651759, 6622585, 6593665, 6564997, 6536577, 6508403, + 6480469, 6452775, 6425317, 6398091, 6371094, 6344325, 6317780, 6291456, + 6265350, 6239460, 6213783, 6188317, 6163059, 6138006, 6113155, 6088506, + 6064054, 6039798, 6015735, 5991863, 5968179, 5944683, 5921370, 5898240 }; -const Word32 inv_delta_phi_val[90] = { - 0, 5965232, 11930464, 17895697, 23860929, 29826161, - 35791394, 41756626, 47721858, 53687091, 59652323, - 65617555, 71582788, 77548020, 83513252, 89478485, - 95443717, 101408950, 107374182, 113339414, 119304647, - 125269879, 131235111, 137200344, 143165576, 149130808, - 155096041, 161061273, 167026505, 172991738, 178956970, - 184922203, 190887435, 196852667, 202817900, 208783132, - 214748364, 220713597, 226678829, 232644061, 238609294, - 244574526, 250539758, 256504991, 262470223, 268435456, - 274400688, 280365920, 286331153, 292296385, 298261617, - 304226850, 310192082, 316157314, 322122547, 328087779, - 334053011, 340018244, 345983476, 351948708, 357913941, - 363879173, 369844406, 375809638, 381774870, 387740103, - 393705335, 399670567, 405635800, 411601032, 417566264, - 423531497, 429496729, 435461961, 441427194, 447392426, - 453357659, 459322891, 465288123, 471253356, 477218588, - 483183820, 489149053, 495114285, 501079517, 507044750, - 513009982, 518975214, 524940447, 530905679 +const Word32 inv_delta_phi_val[257] = { + 0, + 5965232, 11930465, 17895698, 23860930, 29826162, 35791396, 41756628, 47721860, + 53687092, 59652324, 65617556, 71582792, 77548024, 83513256, 89478488, 95443720, + 101408952, 107374184, 113339416, 119304648, 125269880, 131235112, 137200352, 143165584, + 149130816, 155096048, 161061280, 167026512, 172991744, 178956976, 184922208, 190887440, + 196852672, 202817904, 208783136, 214748368, 220713600, 226678832, 232644064, 238609296, + 244574528, 250539760, 256504992, 262470224, 268435456, 274400704, 280365920, 286331168, + 292296384, 298261632, 304226848, 310192096, 316157312, 322122560, 328087776, 334053024, + 340018240, 345983488, 351948704, 357913952, 363879168, 369844416, 375809632, 381774880, + 387740096, 393705344, 399670560, 405635808, 411601024, 417566272, 423531488, 429496736, + 435461952, 441427200, 447392416, 453357664, 459322880, 465288128, 471253344, 477218592, + 483183808, 489149056, 495114272, 501079520, 507044736, 513009984, 518975200, 524940448, + 530905664, 536870912, 542836160, 548801408, 554766592, 560731840, 566697088, 572662336, + 578627520, 584592768, 590558016, 596523264, 602488448, 608453696, 614418944, 620384192, + 626349376, 632314624, 638279872, 644245120, 650210304, 656175552, 662140800, 668106048, + 674071232, 680036480, 686001728, 691966976, 697932160, 703897408, 709862656, 715827904, + 721793088, 727758336, 733723584, 739688832, 745654016, 751619264, 757584512, 763549760, + 769514944, 775480192, 781445440, 787410688, 793375872, 799341120, 805306368, 811271616, + 817236864, 823202048, 829167296, 835132544, 841097792, 847062976, 853028224, 858993472, + 864958720, 870923904, 876889152, 882854400, 888819648, 894784832, 900750080, 906715328, + 912680576, 918645760, 924611008, 930576256, 936541504, 942506688, 948471936, 954437184, + 960402432, 966367616, 972332864, 978298112, 984263360, 990228544, 996193792, 1002159040, + 1008124288, 1014089472, 1020054720, 1026019968, 1031985216, 1037950400, 1043915648, 1049880896, + 1055846144, 1061811328, 1067776576, 1073741824, 1079707008, 1085672320, 1091637504, 1097602816, + 1103568000, 1109533184, 1115498496, 1121463680, 1127428864, 1133394176, 1139359360, 1145324672, + 1151289856, 1157255040, 1163220352, 1169185536, 1175150720, 1181116032, 1187081216, 1193046528, + 1199011712, 1204976896, 1210942208, 1216907392, 1222872576, 1228837888, 1234803072, 1240768384, + 1246733568, 1252698752, 1258664064, 1264629248, 1270594432, 1276559744, 1282524928, 1288490240, + 1294455424, 1300420608, 1306385920, 1312351104, 1318316288, 1324281600, 1330246784, 1336212096, + 1342177280, 1348142464, 1354107776, 1360072960, 1366038272, 1372003456, 1377968640, 1383933952, + 1389899136, 1395864320, 1401829632, 1407794816, 1413760128, 1419725312, 1425690496, 1431655808, + 1437620992, 1443586176, 1449551488, 1455516672, 1461481984, 1467447168, 1473412352, 1479377664, + 1485342848, 1491308032, 1497273344, 1503238528, 1509203840, 1515169024, 1521134208, 1527099520 }; const Word32 dd_val[90] = { diff --git a/lib_com/ivas_rom_com_fx.h b/lib_com/ivas_rom_com_fx.h index 4cf61f9ae..6d4f50fa8 100644 --- a/lib_com/ivas_rom_com_fx.h +++ b/lib_com/ivas_rom_com_fx.h @@ -188,8 +188,8 @@ extern const Word16 ls_elevation_CICP19_idx[11]; extern const Word32 shoebox_sin_cos_tbl_fx[11][2]; -extern const Word32 delta_phi_val[90]; -extern const Word32 inv_delta_phi_val[90]; +extern const Word32 delta_phi_val[257]; +extern const Word32 inv_delta_phi_val[257]; extern const Word32 dd_val[90]; extern const Word32 cb_azi_chan_fx[]; // Q22 extern const Word16 cb_azi_chan_16fx[]; // Q0 diff --git a/lib_com/ivas_stat_com.h b/lib_com/ivas_stat_com.h index 5fdcf2bc1..a4d1065f4 100644 --- a/lib_com/ivas_stat_com.h +++ b/lib_com/ivas_stat_com.h @@ -871,6 +871,7 @@ typedef struct ivas_fb_mixer_state_structure Word16 q_ppFilterbank_inFR_im_fx[IVAS_MAX_FB_MIXER_IN_CH]; Word16 q_ppFilterbank_prior_input_fx[IVAS_MAX_FB_MIXER_IN_CH]; Word32 *prior_mixer_fx[IVAS_MAX_FB_MIXER_OUT_CH][IVAS_MAX_SPAR_FB_MIXER_IN_CH]; + Word16 q_prior_mixer_fx; #endif /* store sin part in const table (no need to store 1s and 0s, no need to do windowing for 1's and 0's as well) */ diff --git a/lib_com/prot.h b/lib_com/prot.h index d0fc8d2ff..d286851e0 100644 --- a/lib_com/prot.h +++ b/lib_com/prot.h @@ -240,11 +240,13 @@ void mvl2l( const int16_t n /* i : vector size */ ); +#ifndef IVAS_FLOAT_FIXED void AGC_dec( float x[], /* i/o: input/output vector */ float mem[], /* i/o: mem[2] should be init to [0,0] */ const int16_t n /* i : vector size */ ); +#endif /*! r: index of the maximum value in the input vector */ int16_t maximum( @@ -2792,13 +2794,13 @@ void GenTransition( void GenTransition_fixed( - TD_BWE_DEC_HANDLE hBWE_TD, /* i/o: TD BWE data handle */ - Word32 *outputHB_fx, /* o : synthesized HB transitions signal */ - const int32_t output_Fs, /* i : output sampling rate */ - const int16_t element_mode, /* i : element mode */ - const int16_t L_frame, /* i : ACELP frame length */ - const int16_t rf_flag, /* i : RF flag */ - const int32_t total_brate, /* i : total bitrate */ + TD_BWE_DEC_HANDLE hBWE_TD, /* i/o: TD BWE data handle */ + Word32 *outputHB_fx, /* o : synthesized HB transitions signal : Q11 */ + const Word32 output_Fs, /* i : output sampling rate : Q0 */ + const Word16 element_mode, /* i : element mode : Q0 */ + const Word16 L_frame, /* i : ACELP frame length : Q0 */ + const Word16 rf_flag, /* i : RF flag : Q0 */ + const Word32 total_brate, /* i : total bitrate : Q0 */ const Word16 prev_Qx ); void GenTransition_WB( @@ -2808,9 +2810,9 @@ void GenTransition_WB( ); void GenTransition_WB_fixed( - TD_BWE_DEC_HANDLE hBWE_TD, /* i/o: TD BWE data handle */ - Word32 *outputHB_fx, /* o : synthesized HB transitions signal */ - const int32_t output_Fs /* i : output sampling rate */ + TD_BWE_DEC_HANDLE hBWE_TD, /* i/o: TD BWE data handle */ + Word32 *outputHB_fx, /* o : synthesized HB transitions signal : Q11 */ + const Word32 output_Fs /* i : output sampling rate */ ); void td_bwe_dec_init( @@ -4923,11 +4925,13 @@ void dec_acelp_4t64( const int16_t Opt_AMR_WB /* i : flag indicating AMR-WB IO mode */ ); +#ifndef IVAS_FLOAT_FIXED uint32_t syn_output( float *synth, /* i/o: float synthesis signal */ const int16_t output_frame, /* i : output frame length */ int16_t *synth_out /* o : integer 16 bits synthesis signal */ ); +#endif void FEC_exc_estim( Decoder_State *st, /* i/o: Decoder static memory */ diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index 1a1b8a81a..da45e5743 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -6372,20 +6372,20 @@ void hf_synth_reset_fx( ); void hf_synth_fx( - ZERO_BWE_DEC_HANDLE hBWE_zero, /* i/o: handle to 0 bit BWE parameters */ - const Word32 core_brate, /* i : core bitrate */ - const Word16 output_frame, /* i : output frame length */ - const Word16 *Aq, /* i : quantized Az */ - const Word16 *exc, /* i : excitation at 12.8 kHz */ - Word16 *synth, /* i : 12.8kHz synthesis signal */ - Word16 *synth16k, /* o : 16kHz synthesis signal */ + ZERO_BWE_DEC_HANDLE hBWE_zero, /* i/o: handle to 0 bit BWE parameters */ + const Word32 core_brate, /* i : core bitrate Q0*/ + const Word16 output_frame, /* i : output frame length Q0*/ + const Word16 *Aq, /* i : quantized Az Q12*/ + const Word16 *exc, /* i : excitation at 12.8 kHz Q_exc*/ + Word16 *synth, /* i : 12.8kHz synthesis signal Q_syn2*/ + Word16 *synth16k, /* o : 16kHz synthesis signal Q_syn2*/ const Word16 Q_exc, /* i : excitation scaling */ const Word16 Q_syn2, /* i : synthesis scaling */ - Word16 *delay_syn_hf, /*i/o: HF synthesis memory */ + Word16 *delay_syn_hf, /*i/o: HF synthesis memory Q_syn2*/ Word16 *memExp1, /* o : HF excitation exponent */ - Word16 *mem_hp_interp, /* i/o: interpol. memory */ - const Word16 extl, /* i : flag indicating BWE */ - const Word16 CNG_mode /* i : CNG_mode */ + Word16 *mem_hp_interp, /* i/o: interpol. memory Qx*/ + const Word16 extl, /* i : flag indicating BWE Q0*/ + const Word16 CNG_mode /* i : CNG_mode Q0*/ ); void hf_synth_amr_wb_init_fx( @@ -6400,21 +6400,21 @@ void hf_synth_amr_wb_reset_fx( void hf_synth_amr_wb_fx( AMRWB_IO_DEC_HANDLE hAmrwb_IO, /* i/o: AMR-WB IO data handle */ ZERO_BWE_DEC_HANDLE hBWE_zero, /* o : zero BWE decoder handle */ - const Word32 core_brate, /* i : core bitrate */ - const Word16 output_frame, /* i : output frame length */ - const Word16 *Aq, /* i : quantized Az : Q12 */ - const Word16 *exc, /* i : excitation at 12.8 kHz : Q_exc */ - Word16 *synth, /* i/o: synthesis signal at 12.8k : Q_syn */ - Word16 *amr_io_class, /* i : signal class (determined by FEC algorithm) */ - Word16 *synth_out, /* i/o: output signal at output Fs : Q_out */ - Word16 fmerit, /* i : classify parameter from FEC : Q14 */ - const Word16 *hf_gain, /* i : decoded HF gain */ - const Word16 *voice_factors, /* i : voicing factors : Q15 */ - const Word16 pitch_buf[], /* i : pitch buffer : Q5 */ - const Word16 ng_ener_ST, /* i : Noise gate - short-term energy : Q8 */ - const Word16 *lsf_new, /* i : ISF vector : Q2 */ - const Word16 Q_exc, /* i : exc scaling */ - const Word16 Q_out /* i : Q_syn2-1 */ + const Word32 core_brate, /* i : core bitrate Q0*/ + const Word16 output_frame, /* i : output frame length Q0*/ + const Word16 *Aq, /* i : quantized Az : Q12*/ + const Word16 *exc, /* i : excitation at 12.8 kHz : Q_exc*/ + Word16 *synth, /* i/o: synthesis signal at 12.8k : Q_syn*/ + Word16 *amr_io_class, /* i : signal class (determined by FEC algorithm) Q0*/ + Word16 *synth_out, /* i/o: output signal at output Fs : Q_out*/ + Word16 fmerit, /* i : classify parameter from FEC : Q14*/ + const Word16 *hf_gain, /* i : decoded HF gain Q0*/ + const Word16 *voice_factors, /* i : voicing factors : Q15*/ + const Word16 pitch_buf[], /* i : pitch buffer : Q5*/ + const Word16 ng_ener_ST, /* i : Noise gate - short-term energy : Q8*/ + const Word16 *lsf_new, /* i : ISF vector : Q2*/ + const Word16 Q_exc, /* i : exc scaling */ + const Word16 Q_out /* i : Q_syn2-1 */ ); // dec_post_fx @@ -6518,19 +6518,20 @@ void init_tcx_cfg_fx( // syn_outp_fx.c void syn_output_fx( - const Word16 codec_mode, /* i : MODE1 or MODE2 */ - Word16 *synth, /* i/o: float synthesis signal */ - const Word16 output_frame, /* i : output frame length */ - Word16 *synth_out, /* o : integer 16 bits synthesis signal */ - const Word16 Q_syn2 /* i : Synthesis scaling factor */ + const Word16 codec_mode, /* i : MODE1 or MODE2 */ + Word16 *synth, /* i/o: fixed point synthesis signal Q_syn2 */ + const Word16 output_frame, /* i : output frame length */ + Word16 *synth_out, /* o : integer 16 bits synthesis signal Q_syn2 */ + const Word16 Q_syn2 /* i : Synthesis scaling factor */ ); void unscale_AGC( - const Word16 x[], - const Word16 Qx, - Word16 y[], - Word16 mem[], - const Word16 n ); + const Word16 x[], /* i: 16kHz synthesis Qx */ + const Word16 Qx, /* i: scale factor of x */ + Word16 y[], /* o: output vector Q0 */ + Word16 mem[], /* i/o: mem[2] should be init to [0,0] Q0 */ + const Word16 n /* i: vector size */ +); // bass_psfilter_fx.c void bass_psfilter_init_fx( @@ -7514,21 +7515,21 @@ void destroy_cldfb_decoder_fx( // swb_bwe_dec_fx.c Word16 WB_BWE_gain_deq_fx( Decoder_State *st_fx, /* i/o: decoder state structure */ - Word16 *WB_fenv ); - + Word16 *WB_fenv /*Q15*/ +); Word16 wb_bwe_dec_fx( #ifdef ADD_IVAS_BWE const Word16 output[], /* i : suntehsis @ internal Fs */ #endif - Word16 *synth_fx, /* i/o: ACELP core synthesis/final synthesis */ - Word16 *hb_synth_fx, /* o : SHB synthesis/final synthesis */ + Word16 *synth_fx, /* i/o: ACELP core synthesis/final synthesis Q0/Qpost */ + Word16 *hb_synth_fx, /* o : SHB synthesis/final synthesis Q_syn_hb */ #ifdef ADD_IVAS_BWE const Word16 use_cldfb_for_dft, /* i : flag to use of CLDFB for DFT Stereo */ #endif const Word16 output_frame, /* i : frame length */ - Word16 *voice_factors_fx, /* i : voicing factors */ - const Word16 pitch_buf_fx[], /* i : pitch buffer */ + Word16 *voice_factors_fx, /* i : voicing factors Q15 */ + const Word16 pitch_buf_fx[], /* i : pitch buffer Q6 */ Decoder_State *st_fx /* i/o: decoder state structure */ , Word16 *Qpost ); @@ -7542,19 +7543,19 @@ Word16 swb_bwe_gain_deq_fx( /* o : BWE class const Word16 hqswb_clas /* i : HQ BWE class */ ); -Word16 swb_bwe_dec_fx( +Word16 swb_bwe_dec_fx( /*o :Q_syn_hb*/ #ifdef ADD_IVAS_BWE - const Word16 output[], /* i : suntehsis @ internal Fs */ + const Word16 output[], /* i : suntehsis @ internal Fs */ #endif - Decoder_State *st_fx, /* i/o: decoder state structure */ - Word16 *synth_fx, /* i : ACELP core synthesis/final synthesis */ - Word16 *hb_synth, /* o : SHB synthesis/final synthesis */ + Decoder_State *st_fx, /* i/o: decoder state structure */ + Word16 *synth_fx, /* i/o: ACELP core synthesis/final synthesis (might be rescaled inside wtda() ) Q0/Qpost */ + Word16 *hb_synth_fx, /* o : SHB synthesis/final synthesis Q_syn_hb */ #ifdef ADD_IVAS_BWE - const Word16 use_cldfb_for_dft, /* i : flag to use of CLDFB for DFT Stereo */ + const Word16 use_cldfb_for_dft, /* i : flag to use of CLDFB for DFT Stereo */ #endif - const Word16 output_frame /* i : frame length */ - , - Word16 *Qpost ); + const Word16 output_frame /* i : frame length */ + , + Word16 *Qpost ); void fd_bwe_dec_init( Decoder_State *st_fx, /* i/o: decoder state structure */ @@ -7573,11 +7574,11 @@ void hq_core_enc_ivas_fx( // hq_core_dec_fx.c void hq_core_dec_fx( Decoder_State *st_fx, /* i/o: decoder state structure fx */ - Word16 synth[], /* o : output synthesis */ + Word16 synth[], /* o : output synthesis Q_synth*/ Word16 *Q_synth, /* o : Q value of synth */ - const Word16 output_frame, /* i : output frame length */ - const Word16 hq_core_type, /* i : HQ core type */ - const Word16 core_switching_flag /* i : ACELP->HQ switching frame flag */ + const Word16 output_frame, /* i : output frame length Q0*/ + const Word16 hq_core_type, /* i : HQ core type Q0*/ + const Word16 core_switching_flag /* i : ACELP->HQ switching frame flag Q0*/ ); void HQ_core_dec_init_fx( HQ_DEC_HANDLE hHQ_core /* i/o: HQ core data handle */ @@ -7623,24 +7624,24 @@ void hq_lr_dec_fx( ); // gq_env_dec_fx.c -Word16 decode_envelope_indices_fx( /* o : Number of bits */ +Word16 decode_envelope_indices_fx( /* o : Number of bits Q0*/ Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word16 start_norm, /* i : starting band index */ - const Word16 num_sfm, /* i : Number of subbands */ - const Word16 numnrmibits, /* i : Bitrate of fall-back coding mode */ - Word16 *difidx, /* o : Diff indices/encoded diff indices */ - const Word16 flag_HQ2 /* i : indicator of HQ2 core */ + const Word16 start_norm, /* i : starting band index Q0*/ + const Word16 num_sfm, /* i : Number of subbands Q0*/ + const Word16 numnrmibits, /* i : Bitrate of fall-back coding mode Q0*/ + Word16 *difidx, /* o : Diff indices/encoded diff indices Q0*/ + const Word16 flag_HQ2 /* i : indicator of HQ2 core Q0*/ , - const Word16 is_transient /* i : indicator of HQ_TRANSIENT */ + const Word16 is_transient /* i : indicator of HQ_TRANSIENT Q0*/ ); void dequantize_norms_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word16 start_norm, /* i : First SDE encoded norm */ - const Word16 num_sfm, /* i : Number of norms */ - const Word16 is_transient, /* i : Transient flag */ - Word16 *ynrm, /* o : Decoded norm indices */ - Word16 *normqlg2 /* o : Log2 of decoded norms */ + Decoder_State *st_fx, /* i/o: decoder state structure */ + const Word16 start_norm, /* i : First SDE encoded norm Q0*/ + const Word16 num_sfm, /* i : Number of norms Q0*/ + const Word16 is_transient, /* i : Transient flag Q0*/ + Word16 *ynrm, /* o : Decoded norm indices Q0*/ + Word16 *normqlg2 /* o : Log2 of decoded norms Q0*/ ); #ifdef IVAS_FLOAT_FIXED @@ -7690,20 +7691,21 @@ void hdecnrm_tran_fx( // tcq_core_dec_fx.c void tcq_core_LR_dec_fx( Decoder_State *st_fx, - Word16 *inp_vector_fx, - const Word16 bit_budget, - const Word16 bands, - const Word16 *band_start, - const Word16 *band_width, - Word32 *Rk_fx, - Word16 *npulses, - Word16 *k_sort, - const Word16 *p2a_flags, - const Word16 p2a_bands, - const Word16 *last_bitalloc, - const Word16 input_frame, - const Word16 adjustFlag, - const Word16 *is_transient ); + Word16 *inp_vector_fx, /*x5 */ + const Word16 bit_budget, /*Q0 */ + const Word16 BANDS, /*Q0 */ + const Word16 *band_start, /*Q0 */ + const Word16 *band_width, /*Q0 */ + Word32 *Rk_fx, /*Q16*/ + Word16 *npulses, /*Q0 */ + Word16 *k_sort, /*Q0 */ + const Word16 *p2a_flags, /*Q0 */ + const Word16 p2a_bands, /*Q0 */ + const Word16 *last_bitalloc, /*Q0 */ + const Word16 input_frame, /*Q0 */ + const Word16 adjustFlag, /*Q0 */ + const Word16 *is_transient /*Q0 */ +); // FEC_HQ_core_fx.c void HQ_FEC_processing_fx( @@ -7745,11 +7747,11 @@ void time_domain_FEC_HQ_fx( // hq_hr_dec_fx.c void hq_pred_hb_bws_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word16 *ynrm, /* i : norm quantization index vector */ - const Word16 length, /* i : frame length */ - const Word16 hqswb_clas, /* i : HQ SWB class */ - const Word16 *SWB_fenv /* i : SWB frequency envelopes Q1 */ + Decoder_State *st_fx, /* i/o: decoder state structure */ + const Word16 *ynrm, /* i : norm quantization index vector Q0*/ + const Word16 length, /* i : frame length Q0*/ + const Word16 hqswb_clas, /* i : HQ SWB class Q0*/ + const Word16 *SWB_fenv /* i : SWB frequency envelopes Q1*/ ); void hq_hr_dec_fx( @@ -7761,7 +7763,7 @@ void hq_hr_dec_fx( Word16 *is_transient, /* o : transient flag Q0 */ Word16 *hqswb_clas, /* o : HQ SWB class Q0 */ Word16 *SWB_fenv, /* o : SWB frequency envelopes Q1 */ - const Word16 core_switching_flag /* i : Core switching flag */ + const Word16 core_switching_flag /* i : Core switching flag Q1 */ ); // hq_classifier_dec_fx.c @@ -7804,12 +7806,12 @@ Word16 hvq_pvq_bitalloc_fx( // hq_conf_fec_fx.c void hq_configure_bfi_fx( - Word16 *nb_sfm, /* o : Number of sub bands Q0 */ - Word16 *num_Sb, /* o : Number of FEC sub bands ? Q0 */ - Word16 *num_bands_p, /* o : FEC sub bands Q0 */ - const Word16 **sfmsize, /* o : Subband bandwidths */ - const Word16 **sfm_start, /* o : Subband start coefficients */ - const Word16 **sfm_end /* o : Subband end coefficients */ + Word16 *nb_sfm, /* o : Number of sub bands Q0*/ + Word16 *num_Sb, /* o : Number of FEC sub bands ? Q0*/ + Word16 *num_bands_p, /* o : FEC sub bands Q0*/ + const Word16 **sfmsize, /* o : Subband bandwidths Q0*/ + const Word16 **sfm_start, /* o : Subband start coefficients Q0*/ + const Word16 **sfm_end /* o : Subband end coefficients Q0*/ ); // core_switching_dec_fx.c @@ -8255,14 +8257,14 @@ void tcxltp_dec_init_fx( const Word32 sr_core ); /* Q0 */ // swb_bwe_dec_hr_fx.c -Word16 swb_bwe_dec_hr_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word16 *syn_12k8_16k_fx, /* i : ACELP core synthesis @16kHz */ - const Word16 old_syn_exp, /* i : Exponent of core synthesis */ - Word16 *hb_synth_fx, /* o : SHB synthesis */ - const Word16 output_frame, /* i : frame length */ - const Word16 unbits, /* i : number of core unused bits */ - const Word16 pitch_buf[] /* i : pitch buffer */ +Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB synthesis */ + Decoder_State *st_fx, /* i/o: decoder state structure */ + const Word16 *syn_12k8_16k_fx, /* i : ACELP core synthesis @16kHz : Q(15 - exp) */ + const Word16 exp, /* i : Exponent of core synthesis */ + Word16 *hb_synth_fx, /* o : SHB synthesis : Q(15 - hb_synth_fx_exp)*/ + const Word16 output_frame, /* i : frame length */ + const Word16 unbits, /* i : number of core unused bits */ + const Word16 pitch_buf[] /* i : pitch buffer : Q6 */ ); void hr_bwe_dec_init( @@ -8517,26 +8519,26 @@ ivas_error decod_ppp_fx( // swb_bwe_dec_lr_fx.c void swb_bwe_dec_lr_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word32 L_m_core[], /* i : lowband synthesis */ - const Word16 QsL, /* i : Q value of m_core */ - Word32 L_m[], /* o : highband synthesis with lowband zeroed */ - const Word32 L_total_brate, /* i : total bitrate for selecting subband pattern */ - Word16 BANDS_fx, /* i : Number subbands/Frame */ - Word16 *band_start_fx, /* i : Band Start of each SB */ - Word16 *band_end_fx, /* i : Band end of each SB */ - Word32 *L_band_energy, /* i : Band energy of each SB : Qbe */ - Word16 Qbe, /* i : Q value of band energy */ - Word16 *p2a_flags_fx, /* i : HF tonal Indicator */ - const Word16 hqswb_clas_fx, /* i : class information */ - Word16 lowlength_fx, /* i : Lowband Length */ - Word16 highlength_fx, /* i : Highband Length */ - const Word16 har_bands_fx, /* i : Number of LF harmonic bands */ - Word16 *prev_frm_hfe2, /* i/o: */ - Word16 *prev_stab_hfe2, /* i/o: */ - Word16 band_width_fx[], /* i : subband bandwidth */ - const Word32 L_y2_ni[], /* i/o: Sparse filled corecoder */ - Word16 *ni_seed_fx /* i/o: random seed */ + Decoder_State *st_fx, /* i/o: decoder state structure */ + const Word32 L_m_core[], /* i : lowband synthesis : QsL */ + const Word16 QsL, /* i : Q value of m_core */ + Word32 L_m[], /* o : highband synthesis with lowband zeroed : QsL */ + const Word32 L_total_brate, /* i : total bitrate for selecting subband pattern */ + Word16 BANDS_fx, /* i : Number subbands/Frame : Q0 */ + Word16 *band_start_fx, /* i : Band Start of each SB : Q0 */ + Word16 *band_end_fx, /* i : Band end of each SB :Q0 */ + Word32 *L_band_energy, /* i : Band energy of each SB : Qbe */ + Word16 Qbe, /* i : Q value of band energy */ + Word16 *p2a_flags_fx, /* i : HF tonal Indicator : Q0 */ + const Word16 hqswb_clas_fx, /* i : class information : Q0 */ + Word16 lowlength_fx, /* i : Lowband Length : Q0 */ + Word16 highlength_fx, /* i : Highband Length : Q0 */ + const Word16 har_bands_fx, /* i : Number of LF harmonic bands : Q0 */ + Word16 *prev_frm_hfe2, /* i/o: : Q0 */ + Word16 *prev_stab_hfe2, /* i/o: : Q0 */ + Word16 band_width_fx[], /* i : subband bandwidth : Q0 */ + const Word32 L_y2_ni[], /* i/o: Sparse filled corecoder */ + Word16 *ni_seed_fx /* i/o: random seed : QsL */ ); #ifdef IVAS_FLOAT_FIXED @@ -9291,39 +9293,40 @@ void tcx_arith_decode_envelope_fx( // tcx_utils_dec_fx.c void tcx_decoder_memory_update( - Word16 *xn_buf, /* i: mdct output buffer */ - Word16 *synthout, /* i/o: synth */ - Word16 *A, /* i: Quantized LPC coefficients */ - Decoder_State *st, - Word8 fb /* i: fullband flag */ + Word16 *xn_buf, /* i/o: mdct output buffer used also as temporary buffer : Q0 */ + Word16 *synthout, /* o: synth : Q0 */ + Word16 *A, /* i: Quantized LPC coefficients : Q12*/ + Decoder_State *st, /* i/o: decoder memory state */ + Word8 fb /* i: fullband flag */ ); Word16 tcx_ari_res_invQ_spec( - Word32 x_Q[], /* i/o: quantized spectrum Q31-e */ - Word16 x_Q_e, /* i: quantized spectrum exponent Q0 */ - Word16 L_frame, /* i: number of lines Q0 */ - const Word16 prm[], /* i: bit-stream Q0 */ - Word16 target_bits, /* i: number of bits available Q0 */ - Word16 bits, /* i: number of bits used so far Q0 */ - Word16 deadzone, /* i: quantizer deadzone Q15 */ - const Word16 x_fac[] /* i: spectrum post-quantization factors Q14 */ + Word32 x_Q[], /* i/o: quantized spectrum Q(31-x_Q_e) */ + Word16 x_Q_e, /* i: quantized spectrum exponent Q0 */ + Word16 L_frame, /* i: number of lines Q0 */ + const Word16 prm[], /* i: bitstream Q0 */ + Word16 target_bits, /* i: number of bits available Q0 */ + Word16 bits, /* i: number of bits used so far Q0 */ + Word16 deadzone, /* i: quantizer deadzone Q15 */ + const Word16 x_fac[] /* i: spectrum post-quantization factors Q14 */ ); Word16 tcx_res_invQ_gain( - Word16 *gain_tcx, + Word16 *gain_tcx, /* i/o : gain_tcx_e*/ Word16 *gain_tcx_e, - Word16 *prm, + Word16 *prm, /*i*/ Word16 resQBits ); Word16 tcx_res_invQ_spec( - Word32 *x, + Word32 *x, /*Q(31 - x_e)*/ Word16 x_e, Word16 L_frame, Word16 *prm, Word16 resQBits, Word16 bits, - Word16 sq_round, - const Word16 lf_deemph_factors[] ); + Word16 sq_round, /*i : sq deadzone Q15*/ + const Word16 lf_deemph_factors[] /*i : LF deemphasis factors Q14*/ +); // er_dec_acelp_fx.c void con_acelp_fx( @@ -10461,24 +10464,24 @@ void v_sub32_fx( ); void ivas_swb_tbe_dec_fx( - Decoder_State *st, /* i/o: decoder state structure */ - STEREO_ICBWE_DEC_HANDLE hStereoICBWE, /* i/o: IC-BWE state structure */ - const Word32 *bwe_exc_extended_fx, /* i : bandwidth extended excitation */ + Decoder_State *st, /* i/o: decoder state structure */ + STEREO_ICBWE_DEC_HANDLE hStereoICBWE, /* i/o: IC-BWE state structure */ + const Word32 *bwe_exc_extended_fx, /* i : bandwidth extended excitation : Q_exc */ Word16 Q_exc, - const Word16 voice_factors_fx[], /* i : voicing factors */ - const Word32 old_syn_12k8_16k_fx[], /* i : low band synthesis */ - Word16 *White_exc16k_fx, /* o : shaped white excitation for the FB TBE */ - Word32 *synth_fx, /* o : SHB synthesis/final synthesis */ - Word16 *pitch_buf_fx, + const Word16 voice_factors_fx[], /* i : voicing factors : Q15 */ + const Word32 old_syn_12k8_16k_fx[], /* i : low band synthesis : old_syn_fx */ + Word16 *White_exc16k_fx, /* o : shaped white excitation for the FB TBE : Q_white_exc*/ + Word32 *synth_fx, /* o : SHB synthesis/final synthesis : Qx */ + Word16 *pitch_buf_fx, /* i : Q6 */ Word16 *Q_white_exc ); Word16 swb_bwe_dec_fx32( - Decoder_State *st, /* i/o: decoder state structure */ - Word32 output[], /* i : synthesis @internal Fs Q11 */ - Word32 *synth, /* i : ACELP core synthesis/final synthesis Q11 */ - Word32 *hb_synth, /* o : SHB synthesis/final synthesis */ - Word16 use_cldfb_for_dft, /* i : flag to use of CLDFB for DFT Stereo */ - Word16 output_frame /* i : frame length */ + Decoder_State *st_fx, /* i/o: decoder state structure */ + Word32 output_fx[], /* i : synthesis @internal Fs : Q11 */ + Word32 *synth_fx, /* i : ACELP core synthesis/final synthesis : Q11 */ + Word32 *hb_synth_fx, /* o : SHB synthesis/final synthesis : Q_syn_hb */ + Word16 use_cldfb_for_dft, /* i : flag to use of CLDFB for DFT Stereo */ + Word16 output_frame /* i : frame length */ ); ivas_error acelp_core_dec_ivas_fx( diff --git a/lib_com/rom_com.c b/lib_com/rom_com.c index 450c166cb..9047d8338 100644 --- a/lib_com/rom_com.c +++ b/lib_com/rom_com.c @@ -26312,23 +26312,7 @@ const float lsf_q_cb_3b[8] = 0.05307309f, 0.06137543f, 0.07216742f, 0.09013262f }; -const Word16 lsf_q_cb_4b_fx[16] = -{ - 589, 773, 914, 1043, - 1173, 1302, 1430, 1558, - 1698, 1843, 1973, 2103, - 2258, 2470, 2787, 3282 - -}; - -const Word16 lsf_q_cb_3b_fx[8] = -{ - 679, 976, 1245, 1491, - 1739, 2011, 2365, 2953 -}; - const float * const lsf_q_cb[NUM_Q_LSF] = { lsf_q_cb_4b, lsf_q_cb_4b, lsf_q_cb_3b, lsf_q_cb_3b, lsf_q_cb_3b }; -const Word16 * const lsf_q_cb_fx[NUM_Q_LSF] = { lsf_q_cb_4b_fx, lsf_q_cb_4b_fx, lsf_q_cb_3b_fx, lsf_q_cb_3b_fx, lsf_q_cb_3b_fx }; const int16_t lsf_q_cb_size[NUM_Q_LSF] = {16, 16, 8, 8, 8}; const int16_t lsf_q_num_bits[NUM_Q_LSF] = { 4, 4, 3, 3, 3 }; @@ -26344,16 +26328,8 @@ const float lsf_grid[4][5] = { 0.14185823f, 0.26648724f, 0.39740108f, 0.55685745f, 0.74688616f }, { 0.15416561f, 0.27238427f, 0.39376780f, 0.59287916f, 0.86613986f } }; -const Word16 lsf_grid_fx[4][5] = -{ - { 5242, 10229, 15516, 21804, 27540, }, - { 5117, 10059, 14949, 20478, 25493, }, - { 4648, 8732, 13022, 18247, 24474, }, - { 5052, 8925, 12903, 19427, 28382, } -}; -const float grid_smoothing[5] = { 0.2f, 0.35f, 0.5f, 0.75f, 0.8f }; -const Word16 grid_smoothing_fx[5] = { 6554, 11469, 16384, 24576, 26214 }; +const float grid_smoothing[5] = { 0.2f, 0.35f, 0.5f, 0.75f, 0.8f }; const float allpass_poles_3_ov_2_flt[9] = { diff --git a/lib_com/rom_com_fx.c b/lib_com/rom_com_fx.c index a1465dc53..39b94b308 100644 --- a/lib_com/rom_com_fx.c +++ b/lib_com/rom_com_fx.c @@ -6631,3 +6631,56 @@ const Word16 LP_assym_window_16k_fx[L_LP_16k] = { 0x0a40, 0x0a3d, }; + +/* 4-bit/3-bit TD SWB BWE differential LSF scalar quantizer tables */ +/*Q15*/ +const Word16 lsf_q_cb_4b_fx[16] = { + 589, 773, 914, 1043, + 1173, 1302, 1430, 1558, + 1698, 1843, 1973, 2103, + 2258, 2470, 2787, 3282 + +}; + +/*Q15*/ +const Word16 lsf_q_cb_3b_fx[8] = { + 679, 976, 1245, 1491, + 1739, 2011, 2365, 2953 +}; + +const Word16 *const lsf_q_cb_fx[NUM_Q_LSF] = { lsf_q_cb_4b_fx, lsf_q_cb_4b_fx, lsf_q_cb_3b_fx, lsf_q_cb_3b_fx, lsf_q_cb_3b_fx }; + +/*Q15*/ +const Word16 lsf_grid_fx[4][5] = { + { + 5242, + 10229, + 15516, + 21804, + 27540, + }, + { + 5117, + 10059, + 14949, + 20478, + 25493, + }, + { + 4648, + 8732, + 13022, + 18247, + 24474, + }, + { + 5052, + 8925, + 12903, + 19427, + 28382, + } +}; + +/*Q15*/ +const Word16 grid_smoothing_fx[5] = { 6554, 11469, 16384, 24576, 26214 }; diff --git a/lib_dec/er_scale_syn_fx.c b/lib_dec/er_scale_syn_fx.c index 2e5746ccf..509fd071b 100644 --- a/lib_dec/er_scale_syn_fx.c +++ b/lib_dec/er_scale_syn_fx.c @@ -57,8 +57,8 @@ Word16 Damping_fact_fx( /* o : damping factor IF( EQ_16( nbLostCmpt, 1 ) ) { /* If stable, do not decrease the energy, pitch gain = 0 */ - /* * (1.0f - 2.0f*_ALPHA_U_FX) + 2.0f*MODE2_ALPHA_U; */ /* [0.8, 1.0] */ - alpha = add( mult_r( stab_fac, sub( 16384, _ALPHA_U_FX ) ), _ALPHA_U_FX ); + /* * (1.0f - 2.0f*_ALPHA_U_FX) + 2.0f*MODE2_ALPHA_U; */ /* [0.8, 1.0] */ + alpha = add( mult_r( stab_fac, sub( 16384, _ALPHA_U_FX ) ), _ALPHA_U_FX ); /*Q14*/ } ELSE IF( EQ_16( nbLostCmpt, 2 ) ) { @@ -67,7 +67,7 @@ Word16 Damping_fact_fx( /* o : damping factor } ELSE { - alpha = mult_r( _ALPHA_U_FX, 16384 ); /*Q14*/ /* 0.4 go rapidly to CNG gain, pitch gain = 0 */ + alpha = mult_r( _ALPHA_U_FX, 16384 ); /*Q14*/ /* 0.4 go rapidly to CNG gain, pitch gain = 0 Q14*/ } } ELSE IF( EQ_16( last_good, UNVOICED_TRANSITION ) ) @@ -80,12 +80,12 @@ Word16 Damping_fact_fx( /* o : damping factor } ELSE IF( ( ( EQ_16( last_good, VOICED_CLAS ) ) || ( EQ_16( last_good, ONSET ) ) ) && ( LE_16( nbLostCmpt, 3 ) ) ) { - alpha = mult_r( _ALPHA_V_FX, 16384 ); /* constant for the first 3 erased frames */ + alpha = mult_r( _ALPHA_V_FX, 16384 ); /* constant for the first 3 erased frames Q14*/ } IF( GE_16( last_good, VOICED_CLAS ) ) { - lp_tmp = *lp_gainp; + lp_tmp = *lp_gainp; /*Q29*/ move32(); IF( EQ_16( nbLostCmpt, 1 ) ) /* if first erased frame in a block, reset harmonic gain */ @@ -96,7 +96,7 @@ Word16 Damping_fact_fx( /* o : damping factor /*BASOP_Util_Sqrt_MantExp(lp_gainp,&lp_gainp_E);*/ s_gainp = 31 - 29; move16(); - gain32 = Sqrt32( lp_tmp, &s_gainp ); + gain32 = Sqrt32( lp_tmp, &s_gainp ); /*Q31-s_gainp*/ #ifdef BASOP_NOGLOB gain = round_fx_o( L_shl_o( gain32, s_gainp, &Overflow ), &Overflow ); /* Q15*/ @@ -110,7 +110,7 @@ Word16 Damping_fact_fx( /* o : damping factor ELSE IF( EQ_16( nbLostCmpt, 2 ) ) { /*0.6 + 0.35*stab_fac*/ - alpha = mult_r( mac_r( 1288490240l /*0.6f Q31*/, 11469 /*0.35f Q15*/, stab_fac ), round_fx( L_shl( lp_tmp, 1 ) ) ); + alpha = mult_r( mac_r( 1288490240l /*0.6f Q31*/, 11469 /*0.35f Q15*/, stab_fac ), round_fx( L_shl( lp_tmp, 1 ) ) ); /*Q14*/ } ELSE { @@ -118,7 +118,7 @@ Word16 Damping_fact_fx( /* o : damping factor lp_tmp = Mpy_32_16_1( lp_tmp, mac_r( 1503238528l /*0.7f Q31*/, 6554 /*0.2f Q15*/, stab_fac ) ); /*2Q29*/ alpha = round_fx( L_shl( lp_tmp, 1 ) ); /*1Q14*/ } - *lp_gainp = lp_tmp; /*store*/ + *lp_gainp = lp_tmp; /*store Q29*/ move32(); } } diff --git a/lib_dec/er_sync_exc_fx.c b/lib_dec/er_sync_exc_fx.c index 268476821..ac04d048c 100644 --- a/lib_dec/er_sync_exc_fx.c +++ b/lib_dec/er_sync_exc_fx.c @@ -36,9 +36,9 @@ static Word16 GetMinimumPosition_fx( move16(); #endif - filterLength = s_min( filterLength, length ); - center = shr( filterLength, 1 ); - iMinEnergyPos = center; + filterLength = s_min( filterLength, length ); /*Q0*/ + center = shr( filterLength, 1 ); /*Q0*/ + iMinEnergyPos = center; /*Q0*/ move16(); IF( filterLength > 0 ) @@ -47,22 +47,22 @@ static Word16 GetMinimumPosition_fx( energy = L_deposit_l( 0 ); energy_old = L_deposit_l( 0 ); - cnt = sub( length, filterLength ); + cnt = sub( length, filterLength ); /*Q0*/ tmp_e = 0; move16(); FOR( i = 0; i < cnt; i++ ) { - tmp16 = shr( x[i], tmp_e ); + tmp16 = shr( x[i], tmp_e ); /*Qx*/ #ifdef BASOP_NOGLOB - energy = L_msu_sat( energy_old, tmp16, tmp16 ); + energy = L_msu_sat( energy_old, tmp16, tmp16 ); /*2Qx+1*/ #else energy = L_msu( energy_old, tmp16, tmp16 ); #endif - tmp16 = shr( x[add( i, filterLength )], tmp_e ); - BASOP_SATURATE_WARNING_OFF_EVS /*Saturation will be handled*/ + tmp16 = shr( x[( i + filterLength )], tmp_e ); /*Qx*/ + BASOP_SATURATE_WARNING_OFF_EVS /*Saturation will be handled*/ #ifdef BASOP_NOGLOB - energy = L_mac_sat( energy, tmp16, tmp16 ); + energy = L_mac_sat( energy, tmp16, tmp16 ); /*2Qx+1*/ #else energy = L_mac( energy, tmp16, tmp16 ); #endif @@ -71,7 +71,7 @@ static Word16 GetMinimumPosition_fx( /*if (energy == MAXVAL_WORD32)*/ BASOP_SATURATE_WARNING_OFF_EVS /*saturates if energy < 0*/ #ifdef BASOP_NOGLOB - tmptest = L_sub_o( energy, MAXVAL_WORD32, &Overflow ); + tmptest = L_sub_o( energy, MAXVAL_WORD32, &Overflow ); /*Q31*/ #else tmptest = L_sub( energy, MAXVAL_WORD32 ); #endif @@ -80,15 +80,15 @@ static Word16 GetMinimumPosition_fx( { tmp_e = add( tmp_e, 1 ); energy = L_shr( energy_old, 2 ); - tmp16 = shr( x[i], tmp_e ); - energy = L_msu( energy, tmp16, tmp16 ); - tmp16 = shr( x[add( i, filterLength )], tmp_e ); - energy = L_mac( energy, tmp16, tmp16 ); + tmp16 = shr( x[i], tmp_e ); /*Qx-1*/ + energy = L_msu( energy, tmp16, tmp16 ); /*2Qx-1*/ + tmp16 = shr( x[( i - filterLength )], tmp_e ); + energy = L_mac( energy, tmp16, tmp16 ); /*2Qx-1*/ } IF( energy < 0 ) { - iMinEnergyPos = add( i, center ); + iMinEnergyPos = add( i, center ); /*Q0*/ tmp_e = 0; move16(); energy = 0; @@ -98,7 +98,7 @@ static Word16 GetMinimumPosition_fx( } } - return iMinEnergyPos; + return iMinEnergyPos; /*Q0*/ } /*! @@ -108,7 +108,7 @@ static Word16 GetMinimumPosition_fx( */ static Word16 FindMaxPeak_fx( - Word16 /*float*/ const *x, /* 0; j-- ) { - *pt_dest++ = *pt_src++; + *pt_dest++ = *pt_src++; /*Qx*/ move16(); } /* Add some samples */ - ftmp = negate( mult( *pt_src, 1638 /*.05f Q15*/ ) ); + ftmp = negate( mult( *pt_src, 1638 /*.05f Q15*/ ) ); /*Qx*/ FOR( j = 0; j < points_by_pos[i]; j++ ) { - *pt_dest++ = ftmp; + *pt_dest++ = ftmp; /*Qx*/ move16(); - ftmp = negate( ftmp ); + ftmp = negate( ftmp ); /*Qx*/ } /* Prepare for the next loop iteration */ - last_min_pos = min_pos[i]; + last_min_pos = min_pos[i]; /*Q0*/ move16(); } /* Copy remaining length */ FOR( j = sub( L_frame, add( n_samples_to_add, last_min_pos ) ); j > 0; j-- ) { - *pt_dest++ = *pt_src++; + *pt_dest++ = *pt_src++; /*Qx*/ move16(); } } @@ -192,30 +192,30 @@ static void RemoveSamples_fx( Word16 /*int*/ last_min_pos, i, j; - pt_dest = new_exc + L_frame; - last_min_pos = sub( L_frame, n_samples_to_add ); + pt_dest = new_exc + L_frame; /*Qx*/ + last_min_pos = sub( L_frame, n_samples_to_add ); /*Q0*/ FOR( i = sub( nb_min, 1 ); i >= 0; i-- ) { /* Compute len to copy */ /* Copy section, removing some samples */ - pt_src = old_exc + last_min_pos; + pt_src = old_exc + last_min_pos; /*Qx*/ FOR( j = sub( last_min_pos, add( min_pos[i], points_by_pos[i] ) ); j > 0; j-- ) { - *--pt_dest = *--pt_src; + *--pt_dest = *--pt_src; /*Qx*/ move16(); } /* Prepare for the next loop iteration */ - last_min_pos = min_pos[i]; + last_min_pos = min_pos[i]; /*Q0*/ move16(); } /* Copy remaining length */ - pt_src = old_exc + last_min_pos; + pt_src = old_exc + last_min_pos; /*Qx*/ FOR( j = last_min_pos; j > 0; j-- ) { - *--pt_dest = *--pt_src; + *--pt_dest = *--pt_src; /*Qx*/ move16(); } } @@ -258,7 +258,7 @@ void PulseResynchronization_fx( test(); IF( src_exc != dst_exc && LE_16( nFrameLength, 1200 ) ) { - Copy( src_exc, dst_exc, nFrameLength ); + Copy( src_exc, dst_exc, nFrameLength ); /*Q15*/ } return; } @@ -282,7 +282,7 @@ void PulseResynchronization_fx( tmp16 = shl( tmp16, tmp_e ); /*Q0,-tmp_e*/ /*tmp16=roundedPitchStart*nSubframes*/ tmp_e = sub( 15, tmp_e ); tmp16 = Inv16( tmp16, &tmp_e ); /*Q15,tmp_e*/ /*tmp16=1.0/(roundedPitchStart*nSubframes)*/ - tmp32 = L_sub( pitchEnd, pitchStart ); + tmp32 = L_sub( pitchEnd, pitchStart ); /*Q16*/ tmp2_e = norm_l( tmp32 ); tmp32 = L_shl( tmp32, tmp2_e ); /*Q16,-tmp2_e*/ tmp32 = Mpy_32_16_1( tmp32, tmp16 ); /*Q16,tmp_e-tmp2_e*/ /*tmp32=pitchDelta*freqStart*/ @@ -290,7 +290,7 @@ void PulseResynchronization_fx( tmp16 = imult1616( nFrameLength, add( nSubframes, 1 ) ); /*Q0*/ /*tmp16=nFrameLength*(nSubframes+1)*/ tmp2_e = norm_s( tmp16 ); - tmp16 = shl( tmp16, tmp2_e ); + tmp16 = shl( tmp16, tmp2_e ); /*Q0+tmp2_e*/ tmp32 = Mpy_32_16_1( tmp32, tmp16 ); /*Q1 scaling (tmp_e-tmp2_e-1), -1 because of 0.5f*/ /*tmp32=0.5f*pitchDelta*nFrameLength*(nSubframes+1)*freqStart*/ tmp_e = sub( sub( tmp_e, tmp2_e ), 1 ); /* sum up all the scalings for tmp32 */ @@ -298,7 +298,7 @@ void PulseResynchronization_fx( /*samplesDelta -= nFrameLength*(1.0f-pitchStart*freqStart);*/ tmp2_e = norm_l( pitchStart ); - tmp32_a = L_shl( pitchStart, tmp2_e ); + tmp32_a = L_shl( pitchStart, tmp2_e ); /*Q16+tmp2_e*/ tmp32_a = Mpy_32_16_1( tmp32_a /*Q16,-tmp2_e*/, freqStart /*Q15,freqStart_e*/ ); /*Q16, scaling (freqStart_e-tmp2_e)*/ /*tmp32_a=pitchStart*freqStart*/ tmp16 = norm_l( tmp32_a ); tmp32_a = L_shl( tmp32_a, tmp16 ); @@ -314,7 +314,7 @@ void PulseResynchronization_fx( tmp32_a = L_add( L_shl( 1, sub( 31, tmp3_e ) ), tmp32_a ); /*Q31,tmp3_e*/ /*tmp32_a= 1.0f-pitchStart*freqStart*/ #endif tmp2_e = norm_s( nFrameLength ); - tmp16_a = shl( nFrameLength, tmp2_e ); + tmp16_a = shl( nFrameLength, tmp2_e ); /*Q0+tmp2_e*/ tmp32_a = Mpy_32_16_1( tmp32_a /*Q31,tmp3_e*/, tmp16_a /*Q0,-tmp2_e*/ ); /*Q16,tmp3_e-tmp2_e*/ /*tmp32_a= nFrameLength*(1.0f-pitchStart*freqStart)*/ tmp2_e = add( sub( tmp3_e, tmp2_e ), 15 ); samplesDelta = BASOP_Util_Add_Mant32Exp( tmp32, tmp_e, L_negate( tmp32_a ), tmp2_e, &samplesDelta_e ); /*Q31,samplesDelta_e*/ @@ -346,7 +346,7 @@ void PulseResynchronization_fx( tmp32 = L_shl( tmp32, tmp2_e ); tmp_e = sub( tmp_e, tmp2_e ); /*tmp32 = Q31,tmp_e*/ tmp2_e = norm_l( absPitchDiff ); - tmp32_b = L_shl( absPitchDiff, tmp2_e ); + tmp32_b = L_shl( absPitchDiff, tmp2_e ); /*Q16+tmp2_e*/ tmp_e = sub( tmp_e, tmp2_e ); tmp32 = Mpy_32_16_1( tmp32_b, round_fx( tmp32 ) ); /*Q16,tmp_e*/ /*tmp32 = absPitchDiff*(nFrameLength-samplesDelta)*/ tmp32_a = Mpy_32_16_1( L_abs( samplesDelta ) /*Q31,samplesDelta_e*/, roundedPitchStart /*Q0*/ ); /*Q16,samplesDelta_e*/ /*tmp32_a=fabs(samplesDelta)*roundedPitchStart*/ @@ -412,33 +412,33 @@ void PulseResynchronization_fx( /* Make sure that the number of samples increases */ IF( GT_32( L_deposit_h( roundedCycleDelta ), cycleDelta32 ) ) { - iDeltaSamples[i] = roundedCycleDelta; + iDeltaSamples[i] = roundedCycleDelta; /*Q0*/ move16(); - roundedCycleDelta = extract_h( cycleDelta32 ); /* cycleDelta32 should never be < 0 here */ - iDeltaSamples[i - 1] = roundedCycleDelta; + roundedCycleDelta = extract_h( cycleDelta32 ); /* cycleDelta32 should never be < 0 here Q0*/ + iDeltaSamples[i - 1] = roundedCycleDelta; /*Q0*/ move16(); } ELSE { - roundedCycleDelta = extract_h( cycleDelta32 ); /* cycleDelta32 should never be < 0 here */ - iDeltaSamples[i] = roundedCycleDelta; + roundedCycleDelta = extract_h( cycleDelta32 ); /* cycleDelta32 should never be < 0 here Q0*/ + iDeltaSamples[i] = roundedCycleDelta; /*Q0*/ move16(); } /*fractionalLeft = cycleDelta-roundedCycleDelta = cycleDelta-(int)cycleDelta;*/ fractionalLeft = lshr( extract_l( cycleDelta32 ), 1 ); /*Q15*/ /* cycleDelta32 should never be < 0 here */ nSamplesDeltaRemain = sub( nSamplesDeltaRemain, roundedCycleDelta ); } - iDeltaSamples[add( k, 1 )] = s_max( 0, nSamplesDeltaRemain ); + iDeltaSamples[( k + 1 )] = s_max( 0, nSamplesDeltaRemain ); move16(); - maxDeltaSamples = s_max( iDeltaSamples[k], iDeltaSamples[add( k, 1 )] ); /*Q0*/ + maxDeltaSamples = s_max( iDeltaSamples[k], iDeltaSamples[( k + 1 )] ); /*Q0*/ /* Find the location of the minimum energy between the first two pulses */ /*iMinPos1 = T0+GetMinimumPosition_fx(src_exc+T0, min(roundedPitchStart, (nSubframes+1)*nFrameLength/nSubframes-T0), maxDeltaSamples);*/ BASOP_Util_Divide_MantExp( add( nSubframes, 1 ), 15, nSubframes, 15, &tmp16, &tmp_e ); tmp32 = L_mult( nFrameLength /*Q0*/, tmp16 /*Q15,tmp_e*/ ); /*Q16,tmp_e*/ - tmp16 = round_fx( L_shl( tmp32, tmp_e ) ); - tmp16 = sub( tmp16, T0 ); + tmp16 = round_fx( L_shl( tmp32, tmp_e ) ); /*Q0*/ + tmp16 = sub( tmp16, T0 ); /*Q0*/ tmp16 = s_min( roundedPitchStart, tmp16 ); iMinPos1 = GetMinimumPosition_fx( @@ -455,26 +455,26 @@ void PulseResynchronization_fx( IF( GT_16( iMinPos1, add( roundedPitchStart, shr( iDeltaSamples[0], 1 ) ) ) ) { - iMinPos[0] = sub( iMinPos1, sub( roundedPitchStart, shr( iDeltaSamples[0], 1 ) ) ); + iMinPos[0] = sub( iMinPos1, sub( roundedPitchStart, shr( iDeltaSamples[0], 1 ) ) ); /*Q0*/ move16(); } ELSE { - iMinPos[0] = sub( GetMinimumPosition_fx( src_exc, T0, iDeltaSamples[0] ), shr( iDeltaSamples[0], 1 ) ); + iMinPos[0] = sub( GetMinimumPosition_fx( src_exc, T0, iDeltaSamples[0] ), shr( iDeltaSamples[0], 1 ) ); /*Q0*/ move16(); } /* Find the location of the minimum energy between the pulses */ FOR( i = 1; i <= k; i++ ) { - iMinPos[i] = add( iMinPos1, sub( imult1616( sub( i, 1 ), roundedPitchStart ), shr( iDeltaSamples[i], 1 ) ) ); + iMinPos[i] = add( iMinPos1, sub( imult1616( sub( i, 1 ), roundedPitchStart ), shr( iDeltaSamples[i], 1 ) ) ); /*Q0*/ move16(); } /* Find the location of the minimum energy after the last pulse */ - IF( LT_16( add( iMinPos1, add( imult1616( k, roundedPitchStart ), sub( iDeltaSamples[add( k, 1 )], shr( iDeltaSamples[add( k, 1 )], 1 ) ) ) ), sub( nFrameLength, nSamplesDelta ) ) ) + IF( LT_16( add( iMinPos1, add( imult1616( k, roundedPitchStart ), sub( iDeltaSamples[( k + 1 )], shr( iDeltaSamples[( k + 1 )], 1 ) ) ) ), sub( nFrameLength, nSamplesDelta ) ) ) { - iMinPos[add( k, 1 )] = add( iMinPos1, sub( imult1616( k, roundedPitchStart ), shr( iDeltaSamples[add( k, 1 )], 1 ) ) ); + iMinPos[( k + 1 )] = add( iMinPos1, sub( imult1616( k, roundedPitchStart ), shr( iDeltaSamples[( k + 1 )], 1 ) ) ); /*Q0*/ move16(); } ELSE @@ -482,18 +482,18 @@ void PulseResynchronization_fx( /*iMinPos[k+1] = T0+k*roundedPitchStart + GetMinimumPosition_fx(src_exc+T0+k*roundedPitchStart, nFrameLength-nSamplesDelta-(T0+k*roundedPitchStart), iDeltaSamples[k+1]) - iDeltaSamples[k+1]/2; */ - tmp16 = GetMinimumPosition_fx( src_exc + add( T0, imult1616( k, roundedPitchStart ) ), sub( nFrameLength, add( nSamplesDelta, add( T0, imult1616( k, roundedPitchStart ) ) ) ), iDeltaSamples[add( k, 1 )] ); + tmp16 = GetMinimumPosition_fx( src_exc + add( T0, imult1616( k, roundedPitchStart ) ), sub( nFrameLength, add( nSamplesDelta, add( T0, imult1616( k, roundedPitchStart ) ) ) ), iDeltaSamples[( k + 1 )] ); /*Q0*/ tmp16 = add( add( T0, imult1616( k, roundedPitchStart ) ), tmp16 ); - tmp16 = sub( tmp16, shr( iDeltaSamples[add( k, 1 )], 1 ) ); - iMinPos[add( k, 1 )] = tmp16; + tmp16 = sub( tmp16, shr( iDeltaSamples[( k + 1 )], 1 ) ); + iMinPos[( k + 1 )] = tmp16; move16(); } - IF( GT_16( add( iMinPos[add( k, 1 )], iDeltaSamples[add( k, 1 )] ), sub( nFrameLength, nSamplesDelta ) ) ) + IF( GT_16( add( iMinPos[( k + 1 )], iDeltaSamples[( k + 1 )] ), sub( nFrameLength, nSamplesDelta ) ) ) { - iDeltaSamples[k] = add( iDeltaSamples[k], add( iMinPos[add( k, 1 )], sub( iDeltaSamples[add( k, 1 )], sub( nFrameLength, nSamplesDelta ) ) ) ); + iDeltaSamples[k] = add( iDeltaSamples[k], add( iMinPos[( k + 1 )], sub( iDeltaSamples[( k + 1 )], sub( nFrameLength, nSamplesDelta ) ) ) ); /*Q0*/ move16(); - iDeltaSamples[add( k, 1 )] = sub( nFrameLength, add( nSamplesDelta, iMinPos[add( k, 1 )] ) ); + iDeltaSamples[( k + 1 )] = sub( nFrameLength, add( nSamplesDelta, iMinPos[( k + 1 )] ) ); /*Q0*/ move16(); } @@ -505,43 +505,43 @@ void PulseResynchronization_fx( /* Find the location of the minimum energy before the first pulse */ IF( GT_16( iMinPos1, roundedPitchStart ) ) { - iMinPos[0] = sub( iMinPos1, roundedPitchStart ); + iMinPos[0] = sub( iMinPos1, roundedPitchStart ); /*Q0*/ move16(); } ELSE { - iMinPos[0] = GetMinimumPosition_fx( src_exc, T0, iDeltaSamples[0] ); + iMinPos[0] = GetMinimumPosition_fx( src_exc, T0, iDeltaSamples[0] ); /*Q0*/ move16(); } /* Find the location of the minimum energy between the pulses */ FOR( i = 1; i <= k; i++ ) { - iMinPos[i] = iMinPos1; + iMinPos[i] = iMinPos1; /*Q0*/ move16(); - iMinPos1 = add( iMinPos1, roundedPitchStart ); + iMinPos1 = add( iMinPos1, roundedPitchStart ); /*Q0*/ } /* Find the location of the minimum energy after the last pulse */ IF( LT_16( iMinPos1, sub( nFrameLength, nSamplesDelta ) ) ) { - iMinPos[add( k, 1 )] = iMinPos1; + iMinPos[( k + 1 )] = iMinPos1; move16(); } ELSE { - tmp16 = GetMinimumPosition_fx( src_exc + add( T0, imult1616( k, roundedPitchStart ) ), sub( nFrameLength, add( nSamplesDelta, add( T0, imult1616( k, roundedPitchStart ) ) ) ), iDeltaSamples[add( k, 1 )] ); + tmp16 = GetMinimumPosition_fx( src_exc + add( T0, imult1616( k, roundedPitchStart ) ), sub( nFrameLength, add( nSamplesDelta, add( T0, imult1616( k, roundedPitchStart ) ) ) ), iDeltaSamples[( k + 1 )] ); /*Q0*/ tmp16 = add( add( tmp16, T0 ), imult1616( k, roundedPitchStart ) ); - iMinPos[add( k, 1 )] = tmp16; + iMinPos[( k + 1 )] = tmp16; /*Q0*/ move16(); } - IF( GT_16( add( iMinPos[add( k, 1 )], iDeltaSamples[add( k, 1 )] ), sub( nFrameLength, nSamplesDelta ) ) ) + IF( GT_16( add( iMinPos[( k + 1 )], iDeltaSamples[( k + 1 )] ), sub( nFrameLength, nSamplesDelta ) ) ) { - iDeltaSamples[k] = add( iDeltaSamples[k], add( iMinPos[add( k, 1 )], sub( iDeltaSamples[add( k, 1 )], sub( nFrameLength, nSamplesDelta ) ) ) ); + iDeltaSamples[k] = add( iDeltaSamples[k], add( iMinPos[( k + 1 )], sub( iDeltaSamples[( k + 1 )], sub( nFrameLength, nSamplesDelta ) ) ) ); /*Q0*/ move16(); - iDeltaSamples[add( k, 1 )] = sub( sub( nFrameLength, nSamplesDelta ), iMinPos[add( k, 1 )] ); + iDeltaSamples[( k + 1 )] = sub( sub( nFrameLength, nSamplesDelta ), iMinPos[( k + 1 )] ); /*Q0*/ move16(); } /* Add samples at the given positions */ diff --git a/lib_dec/er_util_fx.c b/lib_dec/er_util_fx.c index cc6a53cd2..c2c766d9e 100644 --- a/lib_dec/er_util_fx.c +++ b/lib_dec/er_util_fx.c @@ -61,7 +61,7 @@ void minimumStatistics_fx( #endif { BASOP_SATURATE_WARNING_ON_EVS - currentFrameLevel = PLC_MIN_CNG_LEV; + currentFrameLevel = PLC_MIN_CNG_LEV; /*Q15*/ move16(); currentFrameLevel_e = 0; move16(); @@ -73,13 +73,13 @@ void minimumStatistics_fx( IF( tmp >= 0 ) { /* aOpt = *noiseEstimate / *lastFrameLevel; */ - aOpt = BASOP_Util_Divide1616_Scale( *noiseEstimate, *lastFrameLevel, &aOpt_e ); + aOpt = BASOP_Util_Divide1616_Scale( *noiseEstimate, *lastFrameLevel, &aOpt_e ); /*Q16-aOpt_e*/ aOpt_e = add( aOpt_e, sub( noiseEstimate_e, *lastFrameLevel_e ) ); } ELSE { /* aOpt = *lastFrameLevel / *noiseEstimate; */ - aOpt = BASOP_Util_Divide1616_Scale( *lastFrameLevel, *noiseEstimate, &aOpt_e ); + aOpt = BASOP_Util_Divide1616_Scale( *lastFrameLevel, *noiseEstimate, &aOpt_e ); /*Q16-aOpt_e*/ aOpt_e = add( aOpt_e, sub( *lastFrameLevel_e, noiseEstimate_e ) ); } aOpt = mult_r( aOpt, aOpt ); /* Q15 */ @@ -90,7 +90,7 @@ void minimumStatistics_fx( move16(); } - *lastFrameLevel = currentFrameLevel; + *lastFrameLevel = currentFrameLevel; /*Qx*/ move16(); *lastFrameLevel_e = currentFrameLevel_e; move16(); @@ -100,7 +100,7 @@ void minimumStatistics_fx( move16(); if ( tmp == 0 ) { - tmp = PLC_MIN_STAT_BUFF_SIZE; + tmp = PLC_MIN_STAT_BUFF_SIZE; /*Q0*/ move16(); } /*f = msu_r(L_mult(aOpt, noiseLevelMemory[sub(tmp, 1)]), add(aOpt, 0x8000), currentFrameLevel);*/ @@ -128,7 +128,7 @@ void minimumStatistics_fx( assert( f >= 0 ); /* if current frame min is a new local min, set index to current index */ - p = *noiseLevelIndex; + p = *noiseLevelIndex; /*Q0*/ move16(); tmp2 = BASOP_Util_Add_MantExp( noiseLevelMemory[p], noiseLevelMemory_e[p], negate( f ), *new_noiseEstimate_e, &tmp ); IF( tmp >= 0 ) @@ -137,7 +137,7 @@ void minimumStatistics_fx( /*rescale noiseLevelMemory*/ setnoiseLevelMemory_fx( f, new_noiseEstimate_e, noiseLevelMemory_e, noiseLevelMemory, currLevelIndex ); - p = *currLevelIndex; + p = *currLevelIndex; /*Q0*/ move16(); } ELSE @@ -147,7 +147,7 @@ void minimumStatistics_fx( /* current min is not a new min, so check if min must be re-searched */ IF( NE_16( p, *currLevelIndex ) ) { - f = noiseLevelMemory[p]; /* min is still in memory, so return it */ + f = noiseLevelMemory[p]; /* min is still in memory, so return it Qx*/ move16(); *new_noiseEstimate_e = noiseLevelMemory_e[p]; move16(); @@ -164,7 +164,7 @@ void minimumStatistics_fx( move16(); } } - f = noiseLevelMemory[p]; + f = noiseLevelMemory[p]; /*Qx*/ move16(); *new_noiseEstimate_e = noiseLevelMemory_e[p]; move16(); @@ -172,10 +172,10 @@ void minimumStatistics_fx( } /* update local-minimum-value index and current circular-buffer index */ - *noiseLevelIndex = p; + *noiseLevelIndex = p; /*Q0*/ move16(); p = add( *currLevelIndex, 1 ); - *currLevelIndex = add( *currLevelIndex, 1 ); + *currLevelIndex = add( *currLevelIndex, 1 ); /*Q0*/ move16(); if ( EQ_16( *currLevelIndex, PLC_MIN_STAT_BUFF_SIZE ) ) { @@ -183,7 +183,7 @@ void minimumStatistics_fx( move16(); } - *noiseEstimate = f; + *noiseEstimate = f; /*Qx*/ move16(); } @@ -226,15 +226,15 @@ Word16 getLevelSynDeemph_fx( /*10Q5*/ move16(); /*calculate headroom for dotproduct*/ - Hr16 = sub( 15, norm_s( lenLpcExc ) ); + Hr16 = sub( 15, norm_s( lenLpcExc ) ); /*Q0*/ Q_h1 = s_max( sub( Q_h1, Hr16 ), 0 ); /*compensate synthesis scaling with Headroom as much as possible to retain as much precision as possible*/ /*Factor to be multiplied in order to calculate dotproduct with headroom*/ - tmp16 = shr( 32768 / 2, sub( Hr16, 1 ) ); + tmp16 = shr( 32768 / 2, sub( Hr16, 1 ) ); /*Q15*/ /*moved from inside loop, before synthesis*/ - h1Init[0] = mult_r( h1Init[0], tmp16 ); + h1Init[0] = mult_r( h1Init[0], tmp16 ); /*Q15*/ move16(); FOR( loop = 0; loop < numLoops; loop++ ) @@ -242,7 +242,7 @@ Word16 getLevelSynDeemph_fx( /*10Q5*/ set16_fx( h1, 0, lenLpcExc ); set16_fx( mem, 0, lpcorder ); - Copy( h1Init, h1, 1 ); + Copy( h1Init, h1, 1 ); /*Q15*/ /*h1 will be scaled down, Q_h1 */ E_UTIL_synthesis( Q_h1, A, h1, h1, lenLpcExc, mem, 0, lpcorder ); deemph_fx( h1, preemph_fac, lenLpcExc, &tmp ); @@ -250,10 +250,10 @@ Word16 getLevelSynDeemph_fx( /*10Q5*/ /* gain introduced by synthesis+deemphasis */ /*levelSynDeemphSub = (float)sqrt(dot_product( h1, h1, lenLpcExc));*/ - levelSynDeemphSub = Dot_product12_offs( h1, h1, lenLpcExc, &s16, 0 ); + levelSynDeemphSub = Dot_product12_offs( h1, h1, lenLpcExc, &s16, 0 ); /*Q31 - s16*/ s16 = sub( shl( add( Q_h1, Hr16 ), 1 ), sub( 30, s16 ) ); - levelSynDeemphSub = Sqrt32( levelSynDeemphSub, &s16 ); /*Q31*/ + levelSynDeemphSub = Sqrt32( levelSynDeemphSub, &s16 ); /*Q31 - s16*/ /* mean of the above across all subframes -- moved outta loop*/ /*levelSynDeemph += (1.0/(float)numLoops) * levelSynDeemphSub;*/ @@ -262,14 +262,14 @@ Word16 getLevelSynDeemph_fx( /*10Q5*/ if ( GT_16( numLoops, 1 ) ) { - tmp16 = div_s( 1, numLoops ); + tmp16 = div_s( 1, numLoops ); /*Q15*/ } levelSynDeemph = L_add( levelSynDeemph, L_shl( Mpy_32_16_1( levelSynDeemphSub, tmp16 ), sub( s16, 10 ) ) ); /*10Q21*/ } s16 = norm_l( levelSynDeemph ); - levelSynDeemph = L_shl( levelSynDeemph, s16 ); - *Exp = sub( 10, s16 ); /*Set exponent in order to transform returnvalue to Q15*/ + levelSynDeemph = L_shl( levelSynDeemph, s16 ); /*Q31*/ + *Exp = sub( 10, s16 ); /*Set exponent in order to transform returnvalue to Q15*/ move16(); #ifdef BASOP_NOGLOB @@ -281,10 +281,10 @@ Word16 getLevelSynDeemph_fx( /*10Q5*/ /* BASOP version: up to date with rev 7422 */ void genPlcFiltBWAdap_fx( - const Word32 sr_core, /* i : core sampling rate */ - Word16 *lpFiltAdapt, /* o : filter coefficients for filtering codebooks in case of flc */ - const Word16 type, /* i : type of filter, either 0 : lowpass or 1 : highpass */ - const Word16 alpha /* i : fade out factor [0 1) used decrease filter tilt */ + const Word32 sr_core, /* i : core sampling rate Q0*/ + Word16 *lpFiltAdapt, /* o : filter coefficients for filtering codebooks in case of flc Q15*/ + const Word16 type, /* i : type of filter, either 0 : lowpass or 1 : highpass Q0*/ + const Word16 alpha /* i : fade out factor [0 1) used decrease filter tilt Q15*/ ) { Word16 a, b, exp; @@ -305,17 +305,17 @@ void genPlcFiltBWAdap_fx( } ELSE { - a = mult_r( 13107 /*0.4000f Q15*/, alpha ); + a = mult_r( 13107 /*0.4000f Q15*/, alpha ); /*Q15*/ exp = 0; move16(); - b = Inv16( add( a, 16384 /*0.5f Q15*/ ), &exp ); - b = shr( b, sub( 1, exp ) ); - a = negate( mult_r( a, b ) ); - *lpFiltAdapt++ = a; + b = Inv16( add( a, 16384 /*0.5f Q15*/ ), &exp ); /*Q15 - exp*/ + b = shr( b, sub( 1, exp ) ); /*Q15*/ + a = negate( mult_r( a, b ) ); /*Q15*/ + *lpFiltAdapt++ = a; /*Q15*/ move16(); - *lpFiltAdapt++ = b; + *lpFiltAdapt++ = b; /*Q15*/ move16(); - *lpFiltAdapt = a; + *lpFiltAdapt = a; /*Q15*/ move16(); } } @@ -332,17 +332,17 @@ void genPlcFiltBWAdap_fx( } ELSE { - a = mult_r( 9218 /*0.2813f Q15*/, alpha ); + a = mult_r( 9218 /*0.2813f Q15*/, alpha ); /*Q15*/ exp = 0; move16(); - b = Inv16( add( a, 16384 /*0.5f Q15*/ ), &exp ); - b = shr( b, sub( 1, exp ) ); - a = negate( mult_r( a, b ) ); - *lpFiltAdapt++ = a; + b = Inv16( add( a, 16384 /*0.5f Q15*/ ), &exp ); /*Q15 - exp*/ + b = shr( b, sub( 1, exp ) ); /*Q15*/ + a = negate( mult_r( a, b ) ); /*Q15*/ + *lpFiltAdapt++ = a; /*Q15*/ move16(); - *lpFiltAdapt++ = b; + *lpFiltAdapt++ = b; /*Q15*/ move16(); - *lpFiltAdapt = a; + *lpFiltAdapt = a; /*Q15*/ move16(); } } @@ -355,11 +355,11 @@ void genPlcFiltBWAdap_fx( *-----------------------------------------------------------------*/ /*VERSIONINFO: This port is up to date with trunk rev. 32434*/ void highPassFiltering_fx( - const Word16 last_good, /* i: short last classification type */ - const Word16 L_buffer, /* i: int buffer length */ + const Word16 last_good, /* i: short last classification type Q0*/ + const Word16 L_buffer, /* i: int buffer length Q0*/ Word16 exc2[], /* i/o: Qx unvoiced excitation before the high pass filtering */ const Word16 hp_filt[], /* i: Q15 high pass filter coefficients */ - const Word16 l_fir_fer ) /* i: high pass filter length */ + const Word16 l_fir_fer ) /* i: high pass filter length Q0*/ { Word16 i; /*int*/ @@ -368,7 +368,7 @@ void highPassFiltering_fx( { FOR( i = 0; i < L_buffer; i++ ) { - exc2[i] = round_fx( L_sub( Dot_product( &exc2[i], hp_filt, l_fir_fer ), 1 ) ); + exc2[i] = round_fx( L_sub( Dot_product( &exc2[i], hp_filt, l_fir_fer ), 1 ) ); /*Qx*/ move16(); } } @@ -391,9 +391,9 @@ Word16 GetPLCModeDecision_ivas_fx( IF( EQ_16( st->flagGuidedAcelp, 1 ) ) { - st->old_pitch_buf_fx[shl( st->nb_subfr, 1 )] = L_deposit_h( st->guidedT0 ); + st->old_pitch_buf_fx[( st->nb_subfr * 2 )] = L_deposit_h( st->guidedT0 ); /*Q16*/ move32(); - st->old_pitch_buf_fx[add( shl( st->nb_subfr, 1 ), 1 )] = L_deposit_h( st->guidedT0 ); + st->old_pitch_buf_fx[( ( st->nb_subfr * 2 ) + 1 )] = L_deposit_h( st->guidedT0 ); /*Q16*/ move32(); st->mem_pitch_gain[0] = st->mem_pitch_gain[1] = 16384 /*1.f Q14*/; /*Q14*/ move16(); @@ -430,7 +430,7 @@ Word16 GetPLCModeDecision_ivas_fx( move16(); if ( GT_16( st->nbLostCmpt, 1 ) ) { - core = st->last_core_bfi; + core = st->last_core_bfi; /*Q0*/ move16(); } IF( EQ_16( st->nbLostCmpt, 1 ) ) @@ -462,7 +462,7 @@ Word16 GetPLCModeDecision_ivas_fx( pitch = L_deposit_h( 0 ); if ( hTcxDec->tcxltp_last_gain_unmodified > 0 ) { - pitch = L_add( st->old_fpitch, 0 ); + pitch = L_add( st->old_fpitch, 0 ); /*Q16*/ } // TonalMDCTConceal_Detect_ivas_fx(&st->tonalMDCTconceal, pitch, &numIndices // , (st->element_mode == IVAS_CPE_MDCT ? &(st->hTcxCfg->psychParamsTCX20) : st->hTcxCfg->psychParamsCurrent) @@ -503,7 +503,7 @@ Word16 GetPLCModeDecision_ivas_fx( } } } - return core; + return core; /*Q0*/ } #endif @@ -523,9 +523,9 @@ Word16 GetPLCModeDecision_fx( IF( EQ_16( st->flagGuidedAcelp, 1 ) ) { - st->old_pitch_buf_fx[shl( st->nb_subfr, 1 )] = L_deposit_h( st->guidedT0 ); + st->old_pitch_buf_fx[( st->nb_subfr * 2 )] = L_deposit_h( st->guidedT0 ); /*Q16*/ move32(); - st->old_pitch_buf_fx[add( shl( st->nb_subfr, 1 ), 1 )] = L_deposit_h( st->guidedT0 ); + st->old_pitch_buf_fx[( ( st->nb_subfr * 2 ) + 1 )] = L_deposit_h( st->guidedT0 ); /*Q16*/ move32(); st->mem_pitch_gain[0] = st->mem_pitch_gain[1] = 16384 /*1.f Q14*/; /*Q14*/ move16(); @@ -594,7 +594,7 @@ Word16 GetPLCModeDecision_fx( pitch = L_deposit_h( 0 ); if ( hTcxDec->tcxltp_last_gain_unmodified > 0 ) { - pitch = L_add( st->old_fpitch, 0 ); + pitch = L_add( st->old_fpitch, 0 ); /*Q16*/ } IF( st->element_mode == EVS_MONO ) { diff --git a/lib_dec/hf_synth_fx.c b/lib_dec/hf_synth_fx.c index 21989d052..9af04d1f2 100644 --- a/lib_dec/hf_synth_fx.c +++ b/lib_dec/hf_synth_fx.c @@ -90,20 +90,20 @@ void hf_synth_reset_fx( *---------------------------------------------------------------------*/ void hf_synth_fx( - ZERO_BWE_DEC_HANDLE hBWE_zero, /* i/o: handle to 0 bit BWE parameters */ - const Word32 core_brate, /* i : core bitrate */ - const Word16 output_frame, /* i : output frame length */ - const Word16 *Aq, /* i : quantized Az Q12 */ - const Word16 *exc, /* i : excitation at 12.8 kHz Q_exc */ - Word16 *synth, /* i : 12.8kHz synthesis signal Q_syn2 */ - Word16 *synth16k, /* o : 16kHz synthesis signal Q_syn2 */ + ZERO_BWE_DEC_HANDLE hBWE_zero, /* i/o: handle to 0 bit BWE parameters */ + const Word32 core_brate, /* i : core bitrate Q0*/ + const Word16 output_frame, /* i : output frame length Q0*/ + const Word16 *Aq, /* i : quantized Az Q12*/ + const Word16 *exc, /* i : excitation at 12.8 kHz Q_exc*/ + Word16 *synth, /* i : 12.8kHz synthesis signal Q_syn2*/ + Word16 *synth16k, /* o : 16kHz synthesis signal Q_syn2*/ const Word16 Q_exc, /* i : excitation scaling */ const Word16 Q_syn2, /* i : synthesis scaling */ - Word16 *delay_syn_hf, /*i/o: HF synthesis memory */ + Word16 *delay_syn_hf, /*i/o: HF synthesis memory Q_syn2*/ Word16 *memExp1, /* o : HF excitation exponent */ - Word16 *mem_hp_interp, /* i/o: interpol. memory */ - const Word16 extl, /* i : flag indicating BWE */ - const Word16 CNG_mode /* i : CNG_mode */ + Word16 *mem_hp_interp, /* i/o: interpol. memory Qx*/ + const Word16 extl, /* i : flag indicating BWE Q0*/ + const Word16 CNG_mode /* i : CNG_mode Q0*/ ) { const Word16 *p_Aq; @@ -112,13 +112,13 @@ void hf_synth_fx( output_subfr = output_frame / NB_SUBFR; move16(); - p_Aq = Aq; + p_Aq = Aq; /* Q12 */ FOR( i_subfr = 0; i_subfr < L_FRAME; i_subfr += L_SUBFR ) { hf_synthesis_fx( hBWE_zero, core_brate, output_subfr, p_Aq, &exc[i_subfr], Q_exc, &synth[i_subfr], &synth16k[imult3216( (Word32) i_subfr, output_subfr ) / L_SUBFR], Q_syn2, delay_syn_hf, memExp1, mem_hp_interp, extl, CNG_mode ); - p_Aq += ( M + 1 ); + p_Aq += ( M + 1 ); /* Q12 */ } return; @@ -176,19 +176,19 @@ void hf_synth_ivas_fx( static void hf_synthesis_fx( ZERO_BWE_DEC_HANDLE hBWE_zero, - const Word32 core_brate, /* i : core bitrate */ - const Word16 output_subfr, /* i : output sub-frame length */ - const Word16 Aq[], /* i : quantized Az Q12 */ - const Word16 exc[], /* i : excitation at 12.8 kHz Q_exc */ - const Word16 Q_exc, /* i : excitation scaling */ - Word16 synth[], /* i : 12.8kHz synthesis signal Q_syn */ - Word16 synth16k[], /* i/o: 16kHz synthesis signal Q_syn */ - const Word16 Q_syn, /* i : synthesis scaling */ - Word16 *delay_syn_hf, /* i/o: HF synthesis memory Q_syn */ + const Word32 core_brate, /* i : core bitrate Q0*/ + const Word16 output_subfr, /* i : output sub-frame length Q0*/ + const Word16 Aq[], /* i : quantized Az Q12*/ + const Word16 exc[], /* i : excitation at 12.8 kHz Q_exc*/ + const Word16 Q_exc, /* i : excitation scaling */ + Word16 synth[], /* i : 12.8kHz synthesis signal Q_syn*/ + Word16 synth16k[], /* i/o: 16kHz synthesis signal Q_syn*/ + const Word16 Q_syn, /* i : synthesis scaling */ + Word16 *delay_syn_hf, /* i/o: HF synthesis memory Q_syn*/ Word16 *memExp1, /* o : HF excitation scaling exponent */ - Word16 *mem_hp_interp, /* i/o: interpol. memory */ - const Word16 extl, /* i : flag indicating BWE */ - const Word16 CNG_mode /* i : CNG_mode */ + Word16 *mem_hp_interp, /* i/o: interpol. memory Qx*/ + const Word16 extl, /* i : flag indicating BWE Q0*/ + const Word16 CNG_mode /* i : CNG_mode Q0*/ ) { Word16 i; @@ -219,22 +219,22 @@ static void hf_synthesis_fx( *-----------------------------------------------------------------*/ /*ener = sum2_f( exc, L_SUBFR ) + 0.01f*/ - ener = extract_h( Dot_product12( exc, exc, L_SUBFR, &exp2 ) ); + ener = extract_h( Dot_product12( exc, exc, L_SUBFR, &exp2 ) ); /* Q15 */ exp2 = sub( exp2, add( Q_exc, Q_exc ) ); /*tmp = round_fx(Dot_product12(HF_exc, HF_exc, output_subfr, &exp1)); */ L_tmp = Dot_product12( HF_exc, HF_exc, L_SUBFR16k, &exp1 ); - tmp = round_fx( L_tmp ); + tmp = round_fx( L_tmp ); /* Q15 */ /* tmp = (float)(sqrt(ener/tmp)) */ /* scale is -1 if tmp > ener */ - scale = shr( sub( ener, tmp ), 15 ); - tmp = shl( tmp, scale ); + scale = shr( sub( ener, tmp ), 15 ); /* Q0 */ + tmp = shl( tmp, scale ); /* Q15 + scale*/ exp1 = sub( exp1, scale ); - tmp = div_s( tmp, ener ); + tmp = div_s( tmp, ener ); /* Q15 */ exp1 = sub( exp1, exp2 ); - L_tmp = L_deposit_h( tmp ); + L_tmp = L_deposit_h( tmp ); /* Q31 */ L_tmp = Isqrt_lc( L_tmp, &exp1 ); scale = round_fx( L_tmp ); /* Q18 when Q_exc=-1, HF_exc in Q-3 */ @@ -256,11 +256,11 @@ static void hf_synthesis_fx( /* i: synth in Q_syn */ /* o: synth in Q_syn-3 */ - L_tmp = L_mac( 1L, synth[0], synth[0] ); + L_tmp = L_mac( 1L, synth[0], synth[0] ); /* 2*(Q_syn-3)+1 */ FOR( i = 1; i < L_SUBFR; i++ ) { #ifdef BASOP_NOGLOB - L_tmp = L_mac_sat( L_tmp, synth[i], synth[i] ); + L_tmp = L_mac_sat( L_tmp, synth[i], synth[i] ); /* 2*(Q_syn-3)+1 */ #else L_tmp = L_mac( L_tmp, synth[i], synth[i] ); #endif @@ -269,11 +269,11 @@ static void hf_synthesis_fx( ener = extract_h( L_shl( L_tmp, tmp ) ); /* ener = r[0] */ /*ener in Q = 2*(Q_syn-3)+1 = Q-5 when Q_syn=0*/ - L_tmp = L_mac( 1L, synth[1], synth[0] ); + L_tmp = L_mac( 1L, synth[1], synth[0] ); /* 2*(Q_syn-3)+1 */ FOR( i = 2; i < L_SUBFR; i++ ) { #ifdef BASOP_NOGLOB - L_tmp = L_mac_sat( L_tmp, synth[i], synth[i - 1] ); + L_tmp = L_mac_sat( L_tmp, synth[i], synth[i - 1] ); /* 2*(Q_syn-3)+1 */ #else L_tmp = L_mac( L_tmp, synth[i], synth[i - 1] ); #endif @@ -287,7 +287,7 @@ static void hf_synthesis_fx( tmp = s_max( 0, tmp ); if ( tmp > 0 ) { - tmp = div_s( tmp, ener ); + tmp = div_s( tmp, ener ); /* Q15 */ } /*-----------------------------------------------------------------* @@ -296,7 +296,7 @@ static void hf_synthesis_fx( /* tmp = 1.0 - fac */ #ifdef BASOP_NOGLOB - tmp = add_o( 1, sub( 32767, tmp ), &Overflow ); + tmp = add_o( 1, sub( 32767 /* 1 in Q15 */, tmp ), &Overflow ); #else tmp = add( 1, sub( 32767, tmp ) ); #endif @@ -306,7 +306,7 @@ static void hf_synthesis_fx( /* emphasize HF noise in CNG */ /*fac *= 2.0f;*/ #ifdef BASOP_NOGLOB - tmp = add_o( tmp, tmp, &Overflow ); + tmp = add_o( tmp, tmp, &Overflow ); /* Q15 */ #else tmp = add( tmp, tmp ); #endif @@ -347,10 +347,10 @@ static void hf_synthesis_fx( /* delay by 5 samples @16kHz to compensate CLDFB resampling delay (20samples) and HP filtering delay (roughly 15 samples) */ delay = NS2SA_FX2( 16000, DELAY_CLDFB_NS ) - 15; - Copy( HF_syn + sub( L_SUBFR16k, delay ), temp_buffer, delay ); - Copy( HF_syn, HF_syn + delay, sub( L_SUBFR16k, delay ) ); - Copy( delay_syn_hf, HF_syn, delay ); - Copy( temp_buffer, delay_syn_hf, delay ); + Copy( HF_syn + sub( L_SUBFR16k, delay ), temp_buffer, delay ); /* Q_syn+exp1 */ + Copy( HF_syn, HF_syn + delay, sub( L_SUBFR16k, delay ) ); /* Q_syn+exp1 */ + Copy( delay_syn_hf, HF_syn, delay ); /* Q_syn */ + Copy( temp_buffer, delay_syn_hf, delay ); /* Q_syn */ /* interpolate the HF synthesis */ IF( EQ_16( output_subfr, L_SUBFR48k ) ) /* 48kHz sampled output */ @@ -360,12 +360,12 @@ static void hf_synthesis_fx( s = s_max( s_min( sub( s_min( Find_Max_Norm16( HF_syn, L_SUBFR16k ), Find_Max_Norm16( mem_hp_interp, INTERP_3_1_MEM_LEN - 3 ) ), 3 ), sub( Find_Max_Norm16( mem_hp_interp + INTERP_3_1_MEM_LEN - 3, 3 ), 1 ) ), 0 ); - Scale_sig( HF_syn, L_SUBFR16k, s ); - Scale_sig( mem_hp_interp, INTERP_3_1_MEM_LEN, s ); + Scale_sig( HF_syn, L_SUBFR16k, s ); /* Q_syn+exp1+s */ + Scale_sig( mem_hp_interp, INTERP_3_1_MEM_LEN, s ); /* Qx + s */ interpolate_3_over_1_allpass_fx( HF_syn, L_SUBFR16k, upsampled_HF_syn, mem_hp_interp ); - Scale_sig( upsampled_HF_syn, 3 * L_SUBFR16k, -s ); - Scale_sig( mem_hp_interp, INTERP_3_1_MEM_LEN, -s ); - Scale_sig( HF_syn, L_SUBFR16k, -s ); + Scale_sig( upsampled_HF_syn, 3 * L_SUBFR16k, -s ); /* Q_syn + exp1 + s */ + Scale_sig( mem_hp_interp, INTERP_3_1_MEM_LEN, -s ); /* Qx */ + Scale_sig( HF_syn, L_SUBFR16k, -s ); /* Q_syn+exp1 */ } Scale_sig( upsampled_HF_syn, L_SUBFR48k, -1 ); } @@ -374,17 +374,17 @@ static void hf_synthesis_fx( { Word16 s; s = s_max( sub( s_min( Find_Max_Norm16( HF_syn, L_SUBFR16k ), Find_Max_Norm16( mem_hp_interp, 2 * ALLPASSSECTIONS_STEEP ) ), 2 ), 0 ); - Scale_sig( HF_syn, L_SUBFR16k, s ); - Scale_sig( mem_hp_interp, 2 * ALLPASSSECTIONS_STEEP, s ); + Scale_sig( HF_syn, L_SUBFR16k, s ); /* Q_syn+exp1+s */ + Scale_sig( mem_hp_interp, 2 * ALLPASSSECTIONS_STEEP, s ); /* Qx + s */ Interpolate_allpass_steep_fx( HF_syn, mem_hp_interp, L_SUBFR16k, upsampled_HF_syn ); - Scale_sig( upsampled_HF_syn, 2 * L_SUBFR16k, -s ); - Scale_sig( mem_hp_interp, 2 * ALLPASSSECTIONS_STEEP, -s ); - Scale_sig( HF_syn, L_SUBFR16k, -s ); + Scale_sig( upsampled_HF_syn, 2 * L_SUBFR16k, -s ); /* Q_syn + exp1 */ + Scale_sig( mem_hp_interp, 2 * ALLPASSSECTIONS_STEEP, -s ); /* Qx */ + Scale_sig( HF_syn, L_SUBFR16k, -s ); /* Q_syn+exp1 */ } } ELSE /* 16kHz sampled output */ { - Copy( HF_syn, upsampled_HF_syn, L_SUBFR16k ); + Copy( HF_syn, upsampled_HF_syn, L_SUBFR16k ); /* Q_syn */ } Vr_add( synth16k, upsampled_HF_syn, synth16k, output_subfr ); @@ -630,11 +630,11 @@ static void hf_synthesis_ivas_fx( * (gain=4.0) *-------------------------------------------------------------------*/ static void filt_6k_7k_scale_fx( - Word16 signal[], /* i/o: signal */ - Word16 lg, /* i : length of input */ - Word16 mem[], /* i/o: memory (size=30) */ - Word16 fact, /* i : multiply factor */ - Word16 exp /* i : Mem Exponent */ + Word16 signal[], /* i/o: signal Qx*/ + Word16 lg, /* i : length of input Q0*/ + Word16 mem[], /* i/o: memory (size=30) exp*/ + Word16 fact, /* i : multiply factor Q0*/ + Word16 exp /* i : Mem Exponent */ ) { Word16 i, x[L_FRAME48k / NB_SUBFR + ( L_FIR - 1 )]; @@ -647,8 +647,8 @@ static void filt_6k_7k_scale_fx( FOR( i = 0; i < lg; i++ ) { - x[i + L_FIR - 1] = shr( mult( signal[i], fact ), 2 ); - move16(); /* gain of filter = 4 */ + x[i + L_FIR - 1] = shr( mult( signal[i], fact ), 2 ); /* Qx - 2 */ + move16(); /* gain of filter = 4 */ } FOR( i = 0; i < lg; i++ ) { @@ -659,20 +659,20 @@ static void filt_6k_7k_scale_fx( FOR( j = 0; j < 31; j++ ) { #ifdef BASOP_NOGLOB - L_tmp = L_mac_o( L_tmp, x[i + j], fir_6k_7k_fx[j], &Overflow ); + L_tmp = L_mac_o( L_tmp, x[i + j], fir_6k_7k_fx[j], &Overflow ); /* Q16 */ #else L_tmp = L_mac( L_tmp, x[i + j], fir_6k_7k_fx[j] ); #endif } #ifdef BASOP_NOGLOB - signal[i] = round_fx_o( L_tmp, &Overflow ); + signal[i] = round_fx_o( L_tmp, &Overflow ); /* Q0 */ move16(); #else signal[i] = round_fx( L_tmp ); #endif } - Copy( x + lg, mem, L_FIR - 1 ); + Copy( x + lg, mem, L_FIR - 1 ); /* Qx - 2 */ } /*-------------------------------------------------------------------* @@ -694,7 +694,7 @@ void hf_synth_amr_wb_init_fx( hAmrwb_IO->frame_count_fx = 0; move16(); hAmrwb_IO->ne_min_fx = -7680; - move16(); /*Q8*/ + move16(); /*-30.0f in Q8*/ hAmrwb_IO->fmerit_m_sm_fx = 0; move16(); hAmrwb_IO->voice_fac_amr_wb_hf = 0; @@ -702,7 +702,7 @@ void hf_synth_amr_wb_init_fx( hAmrwb_IO->unvoicing_fx = 0; move16(); hAmrwb_IO->unvoicing_sm_fx = 32767; - move16(); /*Q15*/ + move16(); /*1.0f in Q15*/ hAmrwb_IO->unvoicing_flag_fx = 0; move16(); hAmrwb_IO->voicing_flag_fx = 0; @@ -710,7 +710,7 @@ void hf_synth_amr_wb_init_fx( hAmrwb_IO->start_band_old_fx = 160; move16(); hAmrwb_IO->OptCrit_old_fx = 32768; - move32(); /*Q15*/ + move32(); /*1.0f in Q15*/ ; return; } @@ -746,7 +746,7 @@ void hf_synth_amr_wb_reset_fx( hAmrwb_IO->frame_count_fx = 0; move16(); hAmrwb_IO->ne_min_fx = -7680; - move16(); /*Q8*/ + move16(); /*-30.0f in Q8*/ hAmrwb_IO->fmerit_m_sm_fx = 0; move16(); hAmrwb_IO->voice_fac_amr_wb_hf = 0; @@ -754,7 +754,7 @@ void hf_synth_amr_wb_reset_fx( hAmrwb_IO->unvoicing_fx = 0; move16(); hAmrwb_IO->unvoicing_sm_fx = 32767; - move16(); /*Q15*/ + move16(); /*1.0f in Q15*/ hAmrwb_IO->unvoicing_flag_fx = 0; move16(); hAmrwb_IO->voicing_flag_fx = 0; @@ -762,7 +762,7 @@ void hf_synth_amr_wb_reset_fx( hAmrwb_IO->start_band_old_fx = 160; move16(); hAmrwb_IO->OptCrit_old_fx = 32768; - move32(); /*Q15*/ + move32(); /*1.0f in Q15*/ return; } @@ -776,21 +776,21 @@ void hf_synth_amr_wb_reset_fx( void hf_synth_amr_wb_fx( AMRWB_IO_DEC_HANDLE hAmrwb_IO, /* i/o: AMR-WB IO data handle */ ZERO_BWE_DEC_HANDLE hBWE_zero, /* o : zero BWE decoder handle */ - const Word32 core_brate, /* i : core bitrate */ - const Word16 output_frame, /* i : output frame length */ - const Word16 *Aq, /* i : quantized Az : Q12 */ - const Word16 *exc, /* i : excitation at 12.8 kHz : Q_exc */ - Word16 *synth, /* i/o: synthesis signal at 12.8k : Q_syn */ - Word16 *amr_io_class, /* i : signal class (determined by FEC algorithm) */ - Word16 *synth_out, /* i/o: output signal at output Fs : Q_out */ - Word16 fmerit, /* i : classify parameter from FEC : Q14 */ - const Word16 *hf_gain, /* i : decoded HF gain */ - const Word16 *voice_factors, /* i : voicing factors : Q15 */ - const Word16 pitch_buf[], /* i : pitch buffer : Q5 */ - const Word16 ng_ener_ST, /* i : Noise gate - short-term energy : Q8 */ - const Word16 *lsf_new, /* i : ISF vector : Q2 */ - const Word16 Q_exc, /* i : exc scaling */ - const Word16 Q_out /* i : Q_syn2-1 */ + const Word32 core_brate, /* i : core bitrate Q0*/ + const Word16 output_frame, /* i : output frame length Q0*/ + const Word16 *Aq, /* i : quantized Az : Q12*/ + const Word16 *exc, /* i : excitation at 12.8 kHz : Q_exc*/ + Word16 *synth, /* i/o: synthesis signal at 12.8k : Q_syn*/ + Word16 *amr_io_class, /* i : signal class (determined by FEC algorithm) Q0*/ + Word16 *synth_out, /* i/o: output signal at output Fs : Q_out*/ + Word16 fmerit, /* i : classify parameter from FEC : Q14*/ + const Word16 *hf_gain, /* i : decoded HF gain Q0*/ + const Word16 *voice_factors, /* i : voicing factors : Q15*/ + const Word16 pitch_buf[], /* i : pitch buffer : Q5*/ + const Word16 ng_ener_ST, /* i : Noise gate - short-term energy : Q8*/ + const Word16 *lsf_new, /* i : ISF vector : Q2*/ + const Word16 Q_exc, /* i : exc scaling */ + const Word16 Q_out /* i : Q_syn2-1 */ ) { Word16 core_type = 1; @@ -824,11 +824,12 @@ void hf_synth_amr_wb_fx( Word32 exc32[L_FRAME], dct_exc32[L_FRAME], dct_hb32[L_FRAME16k], exc16k32[L_FRAME16k]; Word16 q_tmp; Word16 gamma; + move16(); - Scale_sig( synth, L_FRAME, -3 ); + Scale_sig( synth, L_FRAME, -3 ); /* Q_syn - 3 */ - pt1 = synth + 1; - pt2 = synth; + pt1 = synth + 1; /* Q_syn - 3 */ + pt2 = synth; /* Q_syn - 3 */ pt3 = til; pt4 = til0; FOR( i = 0; i < NB_SUBFR; i++ ) @@ -836,9 +837,9 @@ void hf_synth_amr_wb_fx( enr1 = Dot_product( pt2, pt2, L_SUBFR ); /*2*(Q_syn-3)+1 */ enr2 = Dot_product( pt1, pt2, L_SUBFR - 1 ); /*2*(Q_syn-3)+1 */ - tmp1 = extract_h( enr1 ); + tmp1 = extract_h( enr1 ); /*2*(Q_syn-3) - 15 */ tmp1 = s_max( 1, tmp1 ); - tmp2 = extract_h( enr2 ); + tmp2 = extract_h( enr2 ); /*2*(Q_syn-3) - 15 */ exp = norm_s( tmp1 ); tmp1 = div_s( shl( 1, sub( 14, exp ) ), tmp1 ); /*Q(29-exp-2*(Q_syn-3)-1) */ @@ -852,7 +853,7 @@ void hf_synth_amr_wb_fx( pt2 += L_SUBFR; } - output_subfr = shr( output_frame, 2 ); + output_subfr = shr( output_frame, 2 ); /* Q0 */ if ( NE_16( *amr_io_class, 7 ) ) { @@ -863,8 +864,8 @@ void hf_synth_amr_wb_fx( /* modify LF parameters for excitation weighting or sub-frame gains calculating */ pitch_var_cur = 0; move16(); - pt6 = pitch_buf; - pt7 = pitch_buf + 1; + pt6 = pitch_buf; /* Q5 */ + pt7 = pitch_buf + 1; /* Q5 */ FOR( i = 0; i < 3; i++ ) { tmp1 = abs_s( sub( *pt6++, *pt7++ ) ); /*Q5 */ @@ -874,41 +875,41 @@ void hf_synth_amr_wb_fx( IF( GT_16( hAmrwb_IO->frame_count_fx, FRAME_COUNT_HF_SYNTH ) && *amr_io_class == UNVOICED_CLAS ) { hAmrwb_IO->frame_count_fx = 0; - hAmrwb_IO->ne_min_fx = -7680; + hAmrwb_IO->ne_min_fx = -7680; /* -30.0f in Q8 */ move16(); move16(); /*Q8; */ } ELSE { - hAmrwb_IO->frame_count_fx = s_min( hAmrwb_IO->frame_count_fx, 2 * FRAME_COUNT_HF_SYNTH - 1 ); + hAmrwb_IO->frame_count_fx = s_min( hAmrwb_IO->frame_count_fx, 2 * FRAME_COUNT_HF_SYNTH - 1 ); /* Q0 */ move16(); - hAmrwb_IO->frame_count_fx = add( hAmrwb_IO->frame_count_fx, 1 ); + hAmrwb_IO->frame_count_fx = add( hAmrwb_IO->frame_count_fx, 1 ); /* Q0 */ move16(); - hAmrwb_IO->ne_min_fx = s_min( hAmrwb_IO->ne_min_fx, ng_ener_ST ); + hAmrwb_IO->ne_min_fx = s_min( hAmrwb_IO->ne_min_fx, ng_ener_ST ); /* Q8 */ move16(); } pt6 = voice_factors; - L_tmp = L_mult( *pt6++, 4096 ); + L_tmp = L_mult( *pt6++, 4096 /* 0.25 IN Q14 */ ); /* Q30 */ FOR( i = 1; i < 4; i++ ) { - L_tmp = L_mac( L_tmp, *pt6++, 4096 ); + L_tmp = L_mac( L_tmp, *pt6++, 4096 /* 0.25 IN Q14 */ ); /* Q30 */ } - voice_fac = round_fx( L_tmp ); + voice_fac = round_fx( L_tmp ); /* Q14 */ /*fmerit_w = fmerit > 5734 ? 5734 : (fmerit < 2458 ? 2458 : fmerit); //Q14 */ - fmerit_w = s_min( fmerit, 5734 ); - fmerit_w = s_max( fmerit_w, 2458 ); + fmerit_w = s_min( fmerit, 5734 /* 0.35 IN Q14 */ ); /* Q14 */ + fmerit_w = s_max( fmerit_w, 2458 /* 0.15 IN Q14 */ ); /* Q14 */ if ( EQ_16( core_type, 1 ) ) { - fmerit_w = shr( fmerit_w, 1 ); /*Q14; */ + fmerit_w = shr( fmerit_w, 1 ); /* Q14 */ } #ifdef BASOP_NOGLOB - L_tmp = L_mult( fmerit_w, add_sat( 16384, voice_fac ) ); + L_tmp = L_mult( fmerit_w, add_sat( 16384, voice_fac ) ); /* Q14 */ #else L_tmp = L_mult( fmerit_w, add( 16384, voice_fac ) ); #endif @@ -920,17 +921,17 @@ void hf_synth_amr_wb_fx( move16(); - tmp1 = fmerit; + tmp1 = fmerit; /* Q14 */ move16(); - if ( LT_16( fmerit, 8192 ) ) + if ( LT_16( fmerit, 8192 /* 0.5 in Q14 */ ) ) { - tmp1 = 16384; + tmp1 = 16384; /* 1.0f in Q14 */ move16(); } fmerit_m = negate( add( -32768, tmp1 ) ); hAmrwb_IO->fmerit_m_sm_fx = add( shr( hAmrwb_IO->fmerit_m_sm_fx, 1 ), shr( fmerit_m, 1 ) ); /*Q14 */ move16(); - fmerit_m = hAmrwb_IO->fmerit_m_sm_fx; + fmerit_m = hAmrwb_IO->fmerit_m_sm_fx; /* Q14 */ move16(); pt1 = til; @@ -940,15 +941,15 @@ void hf_synth_amr_wb_fx( tmp = s_and( tmp, *pt1 ); if ( tmp < 0 ) { - *pt1 = 1638; + *pt1 = 1638; /* 0.2 in Q13 */ move16(); } - tmp1 = sub( 8192, *pt1 ); - *pt1 = s_max( 6554, tmp1 ); + tmp1 = sub( 8192 /* 1.0 in Q13 */, *pt1 ); /* Q13 */ + *pt1 = s_max( 6554 /* 0.8 in Q13 */, tmp1 ); /* Q13 */ move16(); - tmp1 = add( hAmrwb_IO->ne_min_fx, 7680 ); /*Q8 */ - tmp1 = mult_r( tmp1, 7340 ); /*Q20 - > 0.007 //Q13 */ + tmp1 = add( hAmrwb_IO->ne_min_fx, 7680 /* 30.0 in Q30 */ ); /*Q8 */ + tmp1 = mult_r( tmp1, 7340 ); /*Q20 - > 0.007 //Q13 */ *pt1 = add( *pt1, tmp1 ); move16(); /*Q13 */ @@ -979,19 +980,19 @@ void hf_synth_amr_wb_fx( q_tmp = Exp16Array( L_FRAME, exc ); qdct = sub( q_tmp, 1 ); - Copy_Scale_sig_16_32( exc, exc32, L_FRAME, qdct ); + Copy_Scale_sig_16_32( exc, exc32, L_FRAME, qdct ); /* Qexc + qdct */ qdct = add( qdct, Q_exc ); edct_fx( exc32, dct_exc32, L_FRAME, &qdct ); q_tmp = Exp32Array( L_FRAME, dct_exc32 ); q_tmp = sub( q_tmp, 16 ); - Copy_Scale_sig_32_16( dct_exc32, dct_exc, L_FRAME, q_tmp ); + Copy_Scale_sig_32_16( dct_exc32, dct_exc, L_FRAME, q_tmp ); /* qdct + qtmp */ qdct = add( qdct, q_tmp ); set16_fx( dct_hb, 0, L_FRAME16k ); - pt1 = &dct_hb[200]; - pt2 = &dct_exc[200]; + pt1 = &dct_hb[200]; /* qdct */ + pt2 = &dct_exc[200]; /* qdct */ FOR( i = 200; i < 240; i++ ) { *pt1++ = *pt2++; @@ -1014,10 +1015,10 @@ void hf_synth_amr_wb_fx( } hb_ener = dot_prod_satcontr( &dct_hb[240], &dct_hb[240], qdct, qdct, &q1, L_SUBFR16k ); - L_tmp = L_shl( L_mult( start_band, 205 ), 14 ); /*Q30 */ - tmp = round_fx( L_tmp ); /*Q14 */ - tmp = sub( 18022, tmp ); /*Q14 */ - fmerit_w = round_fx( L_shl( L_mult( fmerit_w, tmp ), 1 ) ); /*Q: 14+14+1+1-16 = 14 */ + L_tmp = L_shl( L_mult( start_band, 205 /* 0.00625f in Q15 */ ), 14 ); /*Q30 */ + tmp = round_fx( L_tmp ); /*Q14 */ + tmp = sub( 18022 /* 1.1f in Q14 */, tmp ); /*Q14 */ + fmerit_w = round_fx( L_shl( L_mult( fmerit_w, tmp ), 1 ) ); /*Q: 14+14+1+1-16 = 14 */ L_tmp = L_deposit_l( fmerit_w ); /*Q14 */ @@ -1027,15 +1028,15 @@ void hf_synth_amr_wb_fx( alpha = div_s( shl( 1, sub( 14, q2 ) ), tmp ); /*Q(29-q2-8); */ alpha = shl( alpha, sub( q2, 7 ) ); /*Q14 */ - beta = sub( 16384, fmerit_w ); /*Q14 */ + beta = sub( 16384 /* 1.0f in Q14 */, fmerit_w ); /*Q14 */ - L_tmp = L_mult( alpha, 31130 ); /*Q30 */ - gamma = round_fx( L_tmp ); /*Q14 */ - gamma = sub( 17203, gamma ); /*Q14 */ - gamma = s_min( 16384, gamma ); - gamma = s_max( 4915, gamma ); + L_tmp = L_mult( alpha, 31130 /* 0.95f in Q15 */ ); /*Q30 */ + gamma = round_fx( L_tmp ); /*Q14 */ + gamma = sub( 17203 /* 1.05f in Q14 */, gamma ); /*Q14 */ + gamma = s_min( 16384 /* 1.0f in Q14 */, gamma ); /* Q14 */ + gamma = s_max( 4915 /* 0.3f in Q14 */, gamma ); /* Q14 */ - IF( LT_16( beta, 16384 ) ) + IF( LT_16( beta, 16384 /* 1 in Q14 */ ) ) { L_tmp = 1; /*variable for tonal energy*/ move32(); @@ -1045,7 +1046,7 @@ void hf_synth_amr_wb_fx( pt3 = &dct_hb[240]; FOR( i = 0; i < 8; i++ ) { - fn = add( i, 8 ); + fn = add( i, 8 ); /* Q0 */ tmp1 = div_s( 1, fn ); /*Q15 */ tmp = 0; move16(); @@ -1060,11 +1061,11 @@ void hf_synth_amr_wb_fx( } *pt1 = round_fx( L_shl( L_mult( tmp, tmp1 ), 2 ) ); /*qdct */ move16(); - *pt2 = sub( *pt3, *pt1 ); + *pt2 = sub( *pt3, *pt1 ); /* qdct */ move16(); IF( *pt2 > 0 ) { - L_tmp = L_mac0( L_tmp, shr( *pt2, 1 ), shr( *pt2, 1 ) ); + L_tmp = L_mac0( L_tmp, shr( *pt2, 1 ), shr( *pt2, 1 ) ); /*2*qdct-2 */ } pt1++; pt2++; @@ -1072,8 +1073,8 @@ void hf_synth_amr_wb_fx( } FOR( ; i < L_SUBFR16k - 8; i++ ) { - fb = sub( i, 7 ); - fn = add( fb, 15 ); + fb = sub( i, 7 ); /* Q0 */ + fn = add( fb, 15 ); /* Q0 */ tmp = 0; move16(); pt4 = &dct_hb[fb + 240]; @@ -1092,7 +1093,7 @@ void hf_synth_amr_wb_fx( IF( *pt2 > 0 ) { #ifdef BASOP_NOGLOB - L_tmp = L_mac0_sat( L_tmp, shr( *pt2, 1 ), shr( *pt2, 1 ) ); + L_tmp = L_mac0_sat( L_tmp, shr( *pt2, 1 ), shr( *pt2, 1 ) ); /*2*qdct-2 */ #else L_tmp = L_mac0( L_tmp, shr( *pt2, 1 ), shr( *pt2, 1 ) ); #endif @@ -1103,11 +1104,11 @@ void hf_synth_amr_wb_fx( } FOR( ; i < L_SUBFR16k; i++ ) { - fb = sub( i, 7 ); + fb = sub( i, 7 ); /* Q0 */ tmp = 0; move16(); - fn = sub( L_SUBFR16k, fb ); - tmp1 = div_s( 1, fn ); /*Q15 */ + fn = sub( L_SUBFR16k, fb ); /* Q0 */ + tmp1 = div_s( 1, fn ); /*Q15 */ pt4 = &dct_hb[fb + 240]; FOR( j = fb; j < L_SUBFR16k; j++ ) { @@ -1172,11 +1173,11 @@ void hf_synth_amr_wb_fx( pt4++; } - ener = dot_prod_satcontr( &dct_hb[240], &dct_hb[240], qdct, qdct, &q2, L_SUBFR16k ); - scale = div_s( shl( 1, 14 ), hb_ener ); /*Q(29-q1) */ - L_tmp = L_mult( ener, scale ); /*30-q1+q2 */ - q2 = sub( q1, q2 ); /*30-q2 */ - scale = round_fx( Isqrt( L_shl( L_tmp, sub( q2, 24 ) ) ) ); /*Q12 */ + ener = dot_prod_satcontr( &dct_hb[240], &dct_hb[240], qdct, qdct, &q2, L_SUBFR16k ); /* q2 */ + scale = div_s( shl( 1, 14 ), hb_ener ); /*Q(29-q1) */ + L_tmp = L_mult( ener, scale ); /*30-q1+q2 */ + q2 = sub( q1, q2 ); /*30-q2 */ + scale = round_fx( Isqrt( L_shl( L_tmp, sub( q2, 24 ) ) ) ); /*Q12 */ #ifdef BASOP_NOGLOB scale = round_fx_sat( L_shl_sat( L_mult( scale, gamma ), 4 ) ); /*Q15 */ #else @@ -1191,23 +1192,23 @@ void hf_synth_amr_wb_fx( IF( EQ_32( core_brate, ACELP_6k60 ) ) { - filt_weight_coeff = 60; + filt_weight_coeff = 60; /* Q0 */ move16(); rev_filt_weight_coeff = 555; move16(); /* 1/(filt_weight_coeff-1) Q15 */ } ELSE IF( EQ_32( core_brate, ACELP_8k85 ) ) { - filt_weight_coeff = 40; + filt_weight_coeff = 40; /* Q0 */ move16(); - rev_filt_weight_coeff = 840; + rev_filt_weight_coeff = 840; /* 1/(filt_weight_coeff-1) Q15 */ move16(); } ELSE { - filt_weight_coeff = 20; + filt_weight_coeff = 20; /* Q0 */ move16(); - rev_filt_weight_coeff = 1725; + rev_filt_weight_coeff = 1725; /* 1/(filt_weight_coeff-1) Q15 */ move16(); } @@ -1223,7 +1224,7 @@ void hf_synth_amr_wb_fx( IF( EQ_32( core_brate, ACELP_23k85 ) ) { pt1 = dct_hb + 240; - tmp = sub( filt_weight_coeff, 80 ); + tmp = sub( filt_weight_coeff, 80 ); /* Q0 */ pt3 = filt_weight + tmp; FOR( i = 240; i < L_FRAME16k; i++ ) { @@ -1252,21 +1253,21 @@ void hf_synth_amr_wb_fx( { tmp = *pt6++; move16(); - *pt1++ = HP_gain_fx[tmp]; + *pt1++ = HP_gain_fx[tmp]; /* Q15 */ move16(); } } ELSE { pt1 = dct_hb + 240; - tmp = sub( filt_weight_coeff, 80 ); + tmp = sub( filt_weight_coeff, 80 ); /* Q0 */ pt3 = filt_weight + tmp; FOR( i = 240; i < L_FRAME16k; i++ ) { *pt1 = mult_r( *pt1, scale ); /*qdct */ IF( GT_16( i, 255 ) ) { - *pt1 = mult_r( 19505, *pt1 ); + *pt1 = mult_r( 19505 /* 0.6 in Q15 */, *pt1 ); move16(); } @@ -1281,25 +1282,25 @@ void hf_synth_amr_wb_fx( pt1 = dct_hb + 200; pt6 = filt_hp_fx; - pt7 = deem_tab_fx; + pt7 = deem_tab_fx; /* Q15 */ FOR( i = 200; i < 256; i++ ) { *pt1 = mult_r( *pt6++, *pt1 ); move16(); /*qdct */ *pt1 = mult_r( *pt7++, *pt1 ); - move16(); + move16(); /* qdct */ pt1++; } } q_tmp = Exp16Array( L_FRAME16k, dct_hb ); qhf = sub( q_tmp, 1 ); - Copy_Scale_sig_16_32( dct_hb, dct_hb32, L_FRAME16k, qhf ); + Copy_Scale_sig_16_32( dct_hb, dct_hb32, L_FRAME16k, qhf ); /* qhf + qdct */ qhf = add( qhf, qdct ); edct_fx( dct_hb32, exc16k32, L_FRAME16k, &qhf ); q_tmp = Exp32Array( L_FRAME16k, exc16k32 ); q_tmp = sub( q_tmp, 16 ); - Copy_Scale_sig_32_16( exc16k32, exc16k, L_FRAME16k, q_tmp ); + Copy_Scale_sig_32_16( exc16k32, exc16k, L_FRAME16k, q_tmp ); /* qhf + qtmp */ qhf = add( qhf, q_tmp ); ener = dot_prod_satcontr( exc, exc, Q_exc, Q_exc, &q1, L_FRAME ); @@ -1383,19 +1384,19 @@ void hf_synth_amr_wb_fx( return; } static void hf_synthesis_amr_wb_fx( - const Word32 core_brate, /* i : core bitrate : Q0 */ - const Word16 output_subfr, /* i : output sub-frame length : Q0 */ - const Word16 Ap[], /* i : quantized Aq : Q12 */ - Word16 exc16k[], /* i : excitation at 16 kHz : Qhf */ - Word16 synth_out[], /* i/o: synthesis signal at output Fs : Qo */ - Word16 *mem_syn_hf, /* i/o: HF synthesis memory : Qo */ - Word16 *delay_syn_hf, /* i/o: HF synthesis memory : Qo */ - Word16 *mem_hp_interp, /* i/o: interpol. memory : Qo */ - Word16 p_r, /* i : sub-frame gain : Q12 */ - Word16 HF_corr_gain, /* i : HF gain index : Q14 */ - Word16 til, /*Q14*/ - Word16 voice_factors, /*Q14*/ - const Word16 exc[], /* i : excitation at 12.8 kHz : Qi */ + const Word32 core_brate, /* i : core bitrate : Q0*/ + const Word16 output_subfr, /* i : output sub-frame length : Q0*/ + const Word16 Ap[], /* i : quantized Aq : Q12*/ + Word16 exc16k[], /* i : excitation at 16 kHz : qhf*/ + Word16 synth_out[], /* i/o: synthesis signal at output Fs : Q_out*/ + Word16 *mem_syn_hf, /* i/o: HF synthesis memory : Q_out*/ + Word16 *delay_syn_hf, /* i/o: HF synthesis memory : Q_out*/ + Word16 *mem_hp_interp, /* i/o: interpol. memory : Q_out*/ + Word16 p_r, /* i : sub-frame gain : Q12*/ + Word16 HF_corr_gain, /* i : HF gain index : Q14*/ + Word16 til, /* Q14 */ + Word16 voice_factors, /* Q14 */ + const Word16 exc[], /* i : excitation at 12.8 kHz : Qexc*/ const Word16 Q_exc, /*exc scaling*/ const Word16 Q_out, /*synth_out scaling*/ Word16 qhf /*exc16k scaling*/ @@ -1412,7 +1413,7 @@ static void hf_synthesis_amr_wb_fx( ener = dot_prod_satcontr( exc, exc, Q_exc, Q_exc, &q1, L_SUBFR ); tmp = dot_prod_satcontr( exc16k, exc16k, qhf, qhf, &q2, L_SUBFR16k ); - L_tmp = L_mult( ener, 6554 ); /*Q(q1+16) */ + L_tmp = L_mult( ener, 6554 /* 0.2 in Q15 */ ); /*Q(q1+16) */ q3 = norm_l( L_tmp ); L_tmp = L_shl( L_tmp, q3 ); /*Q(q1+q3+16) */ ener = extract_h( L_tmp ); /*Q(q1+q3); */ @@ -1463,14 +1464,14 @@ static void hf_synthesis_amr_wb_fx( scale = round_fx( Isqrt( L_shl( L_tmp, sub( q2, 24 ) ) ) ); /*Q12 */ #endif flag = negate( s_and( til, -0x8000 ) ); - if ( GT_16( scale, 4096 ) ) + if ( GT_16( scale, 4096 /* 1.0f in Q12 */ ) ) { flag = 1; move16(); } IF( flag ) { - Copy( exc2385, exc16k, L_SUBFR16k ); + Copy( exc2385, exc16k, L_SUBFR16k ); /* qhf */ } ELSE { @@ -1478,10 +1479,10 @@ static void hf_synthesis_amr_wb_fx( pt2 = exc2385; FOR( i = 0; i < L_SUBFR16k; i++ ) { - tmp = sub( 16348, shl( til, 1 ) ); /*Q14 */ - L_tmp = L_mult( tmp, sub( 26214, shr( voice_factors, 1 ) ) ); /*Q29*/ - tmp = round_fx( L_shr( L_tmp, 1 ) ); /*Q12*/ - tmp = s_min( tmp, 4096 ); + tmp = sub( 16348 /* 1 in Q14 */, shl( til, 1 ) ); /*Q14 */ + L_tmp = L_mult( tmp, sub( 26214 /* 1.6f in Q14 */, shr( voice_factors, 1 ) ) ); /*Q29*/ + tmp = round_fx( L_shr( L_tmp, 1 ) ); /*Q12*/ + tmp = s_min( tmp, 4096 /* 1 in Q12 */ ); tmp = s_max( tmp, scale ); *pt1++ = round_fx( L_shl( L_mult( *pt2++, tmp ), 3 ) ) /*qhf*/; move16(); @@ -1517,31 +1518,31 @@ static void hf_synthesis_amr_wb_fx( s = s_max( s_min( sub( s_min( Find_Max_Norm16( HF_syn, L_SUBFR16k ), Find_Max_Norm16( mem_hp_interp, INTERP_3_1_MEM_LEN - 3 ) ), 3 ), sub( Find_Max_Norm16( mem_hp_interp + INTERP_3_1_MEM_LEN - 3, 3 ), 1 ) ), 0 ); - Scale_sig( HF_syn, L_SUBFR16k, s ); - Scale_sig( mem_hp_interp, INTERP_3_1_MEM_LEN, s ); + Scale_sig( HF_syn, L_SUBFR16k, s ); /* Qout + s */ + Scale_sig( mem_hp_interp, INTERP_3_1_MEM_LEN, s ); /* Qout + s */ interpolate_3_over_1_allpass_fx( HF_syn, L_SUBFR16k, upsampled_HF_syn, mem_hp_interp ); - Scale_sig( upsampled_HF_syn, L_SUBFR48k, add( -s, -1 ) ); - Scale_sig( mem_hp_interp, INTERP_3_1_MEM_LEN, -s ); - Scale_sig( HF_syn, L_SUBFR16k, -s ); + Scale_sig( upsampled_HF_syn, L_SUBFR48k, add( -s, -1 ) ); /* Qout - 1 */ + Scale_sig( mem_hp_interp, INTERP_3_1_MEM_LEN, -s ); /* Qout */ + Scale_sig( HF_syn, L_SUBFR16k, -s ); /* Qout */ } ELSE IF( EQ_16( output_subfr, L_SUBFR32k ) ) /* 32kHz sampled output */ { Word16 s; s = s_max( sub( s_min( Find_Max_Norm16( HF_syn, L_SUBFR16k ), Find_Max_Norm16( mem_hp_interp, 2 * ALLPASSSECTIONS_STEEP ) ), 2 ), 0 ); - Scale_sig( HF_syn, L_SUBFR16k, s ); - Scale_sig( mem_hp_interp, 2 * ALLPASSSECTIONS_STEEP, s ); + Scale_sig( HF_syn, L_SUBFR16k, s ); /* Qout + s */ + Scale_sig( mem_hp_interp, 2 * ALLPASSSECTIONS_STEEP, s ); /* Qout + s */ Interpolate_allpass_steep_fx( HF_syn, mem_hp_interp, L_SUBFR16k, upsampled_HF_syn ); - Scale_sig( upsampled_HF_syn, 2 * L_SUBFR16k, -s ); - Scale_sig( mem_hp_interp, 2 * ALLPASSSECTIONS_STEEP, -s ); - Scale_sig( HF_syn, L_SUBFR16k, -s ); + Scale_sig( upsampled_HF_syn, 2 * L_SUBFR16k, -s ); /* Qout */ + Scale_sig( mem_hp_interp, 2 * ALLPASSSECTIONS_STEEP, -s ); /* Qout */ + Scale_sig( HF_syn, L_SUBFR16k, -s ); /* Qout */ } ELSE /* 16kHz sampled output */ { - Copy( HF_syn, upsampled_HF_syn, L_SUBFR16k ); + Copy( HF_syn, upsampled_HF_syn, L_SUBFR16k ); /* Qout */ } Vr_add( synth_out, upsampled_HF_syn, synth_out, output_subfr ); @@ -1550,15 +1551,15 @@ static void hf_synthesis_amr_wb_fx( } static Word16 EnhanceClass_fx( - const Word16 qq_fx, - const Word16 pp_fx, - const Word16 tilt0_fx, /* i : spectrum tilt */ - const Word16 tilt_fx, /* i : spectrum tilt */ - const Word16 voice_factor_fx, /* i : voice factor */ - Word16 *voice_fac_fx, /* i/o: smoothed voiced parameter */ - Word16 *unvoicing_fx, /* i/o: unvoiced parameter */ - Word16 *unvoicing_sm_fx, /* i/o: smoothed unvoiced parameter */ - Word16 *unvoicing_flag /* i/o: unvoiced flag */ + const Word16 qq_fx, /* Qx */ + const Word16 pp_fx, /* Qx */ + const Word16 tilt0_fx, /* i : spectrum tilt Q13*/ + const Word16 tilt_fx, /* i : spectrum tilt Q13*/ + const Word16 voice_factor_fx, /* i : voice factor Q15*/ + Word16 *voice_fac_fx, /* i/o: smoothed voiced parameter Q15*/ + Word16 *unvoicing_fx, /* i/o: unvoiced parameter Q15*/ + Word16 *unvoicing_sm_fx, /* i/o: smoothed unvoiced parameter Q15*/ + Word16 *unvoicing_flag /* i/o: unvoiced flag Q0*/ ) { Word16 unvoicing_tmp_fx; @@ -1571,41 +1572,41 @@ static Word16 EnhanceClass_fx( /* Decide (*unvoicing_flag) to allow BWE enhancement when qq>pp */ /**voice_fac_fx = add(mult_r(*voice_fac_fx, 24576), mult_r(voice_factor_fx, 8192)); //Q15 */ - *voice_fac_fx = round_fx( L_mac( L_mult( *voice_fac_fx, 24576 ), voice_factor_fx, 8192 ) ); /*Q15 */ + *voice_fac_fx = round_fx( L_mac( L_mult( *voice_fac_fx, 24576 /* 0.75 in Q15 */ ), voice_factor_fx, 8192 /* 0.25 in Q15 */ ) ); /*Q15 */ move16(); - tmp = mult_r( sub( 8192, tilt0_fx ), 16384 ); /*Q13 */ + tmp = mult_r( sub( 8192 /* 1.0f in Q13 */, tilt0_fx ), 16384 /* 1.0f in Q15 */ ); /*Q13 */ - L_tmp = L_sub( 32768, *voice_fac_fx ); /*Q15 */ + L_tmp = L_sub( 32768 /* 1.0 in Q15 */, *voice_fac_fx ); /*Q15 */ L_tmp = Mult_32_16( L_tmp, tmp ); /*Q13 */ tmp = extract_l( L_tmp ); /*Q13 */ tmp1 = mult_r( tilt_fx, 21845 ); /*Q15->1/1.5 ->Q13+15-15->Q13 */ - tmp1 = s_min( tmp1, 8192 ); + tmp1 = s_min( tmp1, 8192 /* 1.0f in Q13 */ ); L_tmp = L_mult( tmp, tmp1 ); /*Q13+Q13+1 */ unvoicing_tmp_fx = extract_l( L_shr( L_tmp, 12 ) ); /*Q15 */ /**unvoicing_fx = add(mult_r(16384, *unvoicing_fx), mult_r(16384, unvoicing_tmp_fx)); //Q15 */ - *unvoicing_fx = round_fx( L_mac( L_mult( 16384, *unvoicing_fx ), 16384, unvoicing_tmp_fx ) ); /*Q15 */ + *unvoicing_fx = round_fx( L_mac( L_mult( 16384 /* 0.5 in Q15 */, *unvoicing_fx ), 16384 /* 0.5 in Q15 */, unvoicing_tmp_fx ) ); /*Q15 */ move16(); IF( GT_16( *unvoicing_sm_fx, *unvoicing_fx ) ) { /**unvoicing_sm_fx = add(mult_r(29491, *unvoicing_sm_fx), mult_r(3277, *unvoicing_fx)); //Q15 */ - *unvoicing_sm_fx = round_fx( L_mac( L_mult( 29491, *unvoicing_sm_fx ), 3277, *unvoicing_fx ) ); /*Q15 */ + *unvoicing_sm_fx = round_fx( L_mac( L_mult( 29491 /* 0.9 in Q15 */, *unvoicing_sm_fx ), 3277 /* 0.1 in Q15 */, *unvoicing_fx ) ); /*Q15 */ move16(); } ELSE { /**unvoicing_sm_fx = add(mult_r(32440, *unvoicing_sm_fx), mult_r(328, *unvoicing_fx)); //Q15 */ - *unvoicing_sm_fx = round_fx( L_mac( L_mult( 32440, *unvoicing_sm_fx ), 328, *unvoicing_fx ) ); /*Q15 */ + *unvoicing_sm_fx = round_fx( L_mac( L_mult( 32440 /* 0.99 in Q15 */, *unvoicing_sm_fx ), 328 /* 0.01 in Q15 */, *unvoicing_fx ) ); /*Q15 */ move16(); } #ifdef BASOP_NOGLOB - if ( GT_16( sub_o( *unvoicing_fx, *unvoicing_sm_fx, &Overflow ), 3277 ) ) + if ( GT_16( sub_o( *unvoicing_fx, *unvoicing_sm_fx, &Overflow ), 3277 /* 0.1 in Q15 */ ) ) #else if ( GT_16( sub( *unvoicing_fx, *unvoicing_sm_fx ), 3277 ) ) #endif @@ -1615,7 +1616,7 @@ static Word16 EnhanceClass_fx( } #ifdef BASOP_NOGLOB - if ( LT_16( sub_o( *unvoicing_fx, *unvoicing_sm_fx, &Overflow ), 1638 ) ) + if ( LT_16( sub_o( *unvoicing_fx, *unvoicing_sm_fx, &Overflow ), 1638 /* 0.05 in Q15 */ ) ) #else if ( LT_16( sub( *unvoicing_fx, *unvoicing_sm_fx ), 1638 ) ) #endif @@ -1629,13 +1630,13 @@ static Word16 EnhanceClass_fx( static void envelope_fx( AMRWB_IO_DEC_HANDLE hAmrwb_IO, - const Word32 core_brate, /* i : core bitrate */ - const Word16 Aq_dyn_scal[], /* i : de-quant. LPC coefficents, dynamic scaling */ - Word16 Ap[], /* o : extended LPC coefficents, Q12 */ - Word16 *sub_gain, /* o : sub-frame gain, Q12 */ - Word16 tilt0, /* i : spectrum tilt, Q14 */ - Word16 tilt, /* i : spectrum tilt, Q13 */ - Word16 voice_factor /* i : voice factor, Q15 */ + const Word32 core_brate, /* i : core bitrate Q0*/ + const Word16 Aq_dyn_scal[], /* i : de-quant. LPC coefficents, dynamic scaling Q12*/ + Word16 Ap[], /* o : extended LPC coefficents, Q12*/ + Word16 *sub_gain, /* o : sub-frame gain, Q12*/ + Word16 tilt0, /* i : spectrum tilt, Q14*/ + Word16 tilt, /* i : spectrum tilt, Q13*/ + Word16 voice_factor /* i : voice factor, Q15*/ ) { @@ -1654,7 +1655,7 @@ static void envelope_fx( /* Aq has dynamic scaling go back to Q12 to make sure there's no overflow while calculating qx,qy*/ shift = sub( norm_s( Aq_dyn_scal[0] ), 2 ); - Copy_Scale_sig( Aq_dyn_scal, Aq, M + 1, shift ); + Copy_Scale_sig( Aq_dyn_scal, Aq, M + 1, shift ); /* Q12 + shift */ /* LPC envelope weighting */ IF( EQ_32( core_brate, ACELP_6k60 ) ) @@ -1670,17 +1671,17 @@ static void envelope_fx( shift = sub( norm_s( Ap[0] ), 2 ); IF( shift != 0 ) { - Scale_sig( Ap, M + 1, shift ); + Scale_sig( Ap, M + 1, shift ); /* Q12 + shift */ } /* LPC envelope level estimate */ L_tmp = 0; move32(); - pt1 = Ap; - pt2 = exp_tab_p_fx; + pt1 = Ap; /* Q12 */ + pt2 = exp_tab_p_fx; /* Q14 */ FOR( i = 0; i <= M; i++ ) { - L_tmp = L_mac( L_tmp, *pt1++, *pt2++ ); + L_tmp = L_mac( L_tmp, *pt1++, *pt2++ ); /* Q27 */ } q1 = norm_l( L_tmp ); L_tmp = L_shl( L_tmp, q1 ); /*Q(27+q1)*/ @@ -1688,11 +1689,11 @@ static void envelope_fx( L_tmp = L_deposit_l( 0 ); - pt1 = Ap; - pt2 = exp_tab_p_fx + 33; + pt1 = Ap; /* Q12 */ + pt2 = exp_tab_p_fx + 33; /* Q14 */ FOR( i = 0; i <= M; i++ ) { - L_tmp = L_mac( L_tmp, *pt1++, *pt2-- ); + L_tmp = L_mac( L_tmp, *pt1++, *pt2-- ); /* Q27 */ } q2 = norm_l( L_tmp ); shift = sub( q1, q2 ); @@ -1710,12 +1711,12 @@ static void envelope_fx( py = round_fx( L_shr( L_tmp, 1 ) ); /*Q(10+q1)*/ L_tmp = L_deposit_l( 0 ); - pt2 = Aq; - pt3 = exp_tab_q_fx; + pt2 = Aq; /* Q12 */ + pt3 = exp_tab_q_fx; /* Q14 */ FOR( i = 0; i <= M; i++ ) { #ifdef BASOP_NOGLOB - L_tmp = L_mac_sat( L_tmp, *pt2++, *pt3++ ); + L_tmp = L_mac_sat( L_tmp, *pt2++, *pt3++ ); /* Q27 */ #else L_tmp = L_mac( L_tmp, *pt2++, *pt3++ ); #endif @@ -1725,12 +1726,12 @@ static void envelope_fx( rx = round_fx( L_shr( L_tmp, 1 ) ); /*Q(10+q2)*/ L_tmp = L_deposit_l( 0 ); - pt2 = Aq; - pt3 = exp_tab_q_fx + 33; + pt2 = Aq; /* Q12 */ + pt3 = exp_tab_q_fx + 33; /* Q14 */ FOR( i = 0; i <= M; i++ ) { #ifdef BASOP_NOGLOB - L_tmp = L_mac_sat( L_tmp, *pt2++, *pt3-- ); + L_tmp = L_mac_sat( L_tmp, *pt2++, *pt3-- ); /* Q14 */ #else L_tmp = L_mac( L_tmp, *pt2++, *pt3-- ); #endif @@ -1765,21 +1766,21 @@ static void envelope_fx( rr = round_fx( Isqrt( L_shr( L_tmp, add( 11, shl( q2, 1 ) ) ) ) ); /*Q10*/ #endif Copy( Aq, As, 3 ); - IF( EQ_16( shr( As[2], 1 ), -2048 ) ) + IF( EQ_16( shr( As[2], 1 ), -2048 /* -1.0f in Q11 */ ) ) { - k2 = -2458; + k2 = -2458; /* -0.6f in Q12 */ move16(); - k1 = 4055; + k1 = 4055; /* 0.99f in Q12 */ move16(); if ( As[1] < 0 ) { - k1 = -k1; + k1 = -k1; /* Q12 */ move16(); } } ELSE { - k1 = add( 2048, shr( As[2], 1 ) ); /*Q11 */ + k1 = add( 2048 /* 1 in Q11 */, shr( As[2], 1 ) ); /*Q11 */ q1 = 11; move16(); q2 = norm_s( k1 ); @@ -1801,28 +1802,28 @@ static void envelope_fx( #endif k2 = As[2]; move16(); /*Q12 */ - if ( GT_16( k2, 2458 ) ) + if ( GT_16( k2, 2458 /* 0.6f in Q12 */ ) ) { - k2 = 2458; + k2 = 2458; /* 0.6f in Q12 */ move16(); } - if ( LT_16( k2, -2458 ) ) + if ( LT_16( k2, -2458 /* -0.6f in Q12 */ ) ) { - k2 = -2458; + k2 = -2458; /* -0.6f in Q12 */ move16(); } - if ( GT_16( k1, 4055 ) ) + if ( GT_16( k1, 4055 /* 0.99f in Q12 */ ) ) { - k1 = 4055; + k1 = 4055; /* 0.99f in Q12 */ move16(); } - if ( LT_16( k1, -4055 ) ) + if ( LT_16( k1, -4055 /* -0.99f in Q12 */ ) ) { - k1 = -4055; + k1 = -4055; /* -0.99f in Q12 */ move16(); } } - As[1] = add( 4096, k2 ); + As[1] = add( 4096 /* 1 in Q12 */, k2 ); move16(); L_tmp = L_mult( As[1], k1 ); /*Q25 */ As[1] = round_fx( L_shl( L_tmp, 3 ) ); /*Q12 */ @@ -1831,11 +1832,11 @@ static void envelope_fx( move16(); /*Q12 */ L_tmp = L_deposit_l( 0 ); - pt1 = As; - pt2 = exp_tab_q_fx; + pt1 = As; /* Q12 */ + pt2 = exp_tab_q_fx; /* Q14 */ FOR( i = 0; i < 3; i++ ) { - L_tmp = L_mac( L_tmp, *pt1++, *pt2++ ); + L_tmp = L_mac( L_tmp, *pt1++, *pt2++ ); /* Q27 */ } q1 = norm_l( L_tmp ); L_tmp = L_shl( L_tmp, q1 ); /*Q(27+q1)*/ @@ -1843,11 +1844,11 @@ static void envelope_fx( L_tmp = L_deposit_l( 0 ); - pt1 = As; - pt2 = exp_tab_q_fx + 33; + pt1 = As; /* Q12 */ + pt2 = exp_tab_q_fx + 33; /* Q14 */ FOR( i = 0; i < 3; i++ ) { - L_tmp = L_mac( L_tmp, *pt1++, *pt2-- ); + L_tmp = L_mac( L_tmp, *pt1++, *pt2-- ); /* Q27 */ } q2 = norm_l( L_tmp ); shift = sub( q1, q2 ); @@ -1865,11 +1866,11 @@ static void envelope_fx( qy = round_fx( L_shr( L_tmp, 1 ) ); /*Q(10+q1)*/ - L_tmp = L_mult( qx, qx ); - L_tmp = L_mac( L_tmp, qy, qy ); + L_tmp = L_mult( qx, qx ); /* Q21 + 2q1 */ + L_tmp = L_mac( L_tmp, qy, qy ); /* Q21 + 2q1 */ qq = round_fx( Isqrt( L_shr( L_tmp, add( 11, shl( q1, 1 ) ) ) ) ); /*Q10*/ - Unvoicing_flag = EnhanceClass_fx( rr, pp, tilt0, tilt, voice_factor, &hAmrwb_IO->voice_fac_amr_wb_hf, &hAmrwb_IO->unvoicing_fx, &hAmrwb_IO->unvoicing_sm_fx, &hAmrwb_IO->unvoicing_flag_fx ); + Unvoicing_flag = EnhanceClass_fx( rr, pp, tilt0, tilt, voice_factor, &hAmrwb_IO->voice_fac_amr_wb_hf, &hAmrwb_IO->unvoicing_fx, &hAmrwb_IO->unvoicing_sm_fx, &hAmrwb_IO->unvoicing_flag_fx ); /* Q0 */ alpha = 0; move16(); IF( Unvoicing_flag ) @@ -1886,31 +1887,31 @@ static void envelope_fx( hAmrwb_IO->prev_r_fx = rr; move16(); - L_tmp = L_mult( tilt, sub( 26214, shr( voice_factor, 1 ) ) ); /*Q28*/ + L_tmp = L_mult( tilt, sub( 26214 /* 1.6f in Q14 */, shr( voice_factor, 1 ) ) ); /*Q28*/ - L_tmp = L_min( L_tmp, 268435456 ); + L_tmp = L_min( L_tmp, 268435456 /* 1 in Q28 */ ); - L_tmp = Mult_32_16( L_tmp, rr ); /*Q23*/ - rr = round_fx( L_shl( L_tmp, 3 ) ); /*Q10*/ - L_tmp = L_mult( tilt, sub( 26214, shr( voice_factor, 1 ) ) ); /*Q28*/ - L_tmp = L_max( L_tmp, 268435456 ); + L_tmp = Mult_32_16( L_tmp, rr ); /*Q23*/ + rr = round_fx( L_shl( L_tmp, 3 ) ); /*Q10*/ + L_tmp = L_mult( tilt, sub( 26214 /* 1.6f in Q14 */, shr( voice_factor, 1 ) ) ); /*Q28*/ + L_tmp = L_max( L_tmp, 268435456 /* 1 in Q28 */ ); L_tmp = Mult_32_16( L_tmp, qq ); /*Q23*/ #ifdef BASOP_NOGLOB qq = round_fx_sat( L_shl_sat( L_tmp, 3 ) ); /*Q10*/ #else qq = round_fx( L_shl( L_tmp, 3 ) ); /*Q10*/ #endif - rr = s_min( rr, qq ); - rr = s_max( rr, pp ); + rr = s_min( rr, qq ); /* Q10 */ + rr = s_max( rr, pp ); /* Q10 */ } ELSE { test(); - IF( LT_16( rr, 1024 ) && LT_16( ( hAmrwb_IO->prev_r_fx ), 1024 ) ) + IF( LT_16( rr, 1024 /* 1 in Q10 */ ) && LT_16( ( hAmrwb_IO->prev_r_fx ), 1024 /* 1 in Q10 */ ) ) { L_tmp = L_mult( rr, rr ); /*Q21*/ tmp = round_fx( L_shl( L_tmp, 9 ) ); /*Q14*/ - L_tmp = L_sub( 2097152, L_tmp ); /*Q21*/ + L_tmp = L_sub( 2097152 /* 1 in Q21 */, L_tmp ); /*Q21*/ alpha = round_fx( L_shl( L_tmp, 9 ) ); /*Q14*/ L_tmp = L_mult( alpha, ( hAmrwb_IO->prev_r_fx ) ); /*Q25*/ L_tmp = L_mac( L_tmp, tmp, rr ); /*Q25*/ @@ -1924,9 +1925,9 @@ static void envelope_fx( hAmrwb_IO->prev_r_fx = rr; move16(); - L_tmp = L_mult( tilt, sub( 26214, shr( voice_factor, 1 ) ) ); /*Q28*/ + L_tmp = L_mult( tilt, sub( 26214 /* 1.6f in Q14 */, shr( voice_factor, 1 ) ) ); /*Q28*/ - L_tmp = L_min( L_tmp, 268435456 ); + L_tmp = L_min( L_tmp, 268435456 /* 1 in Q28 */ ); L_tmp = Mult_32_16( L_tmp, qq ); /*Q23*/ est_level1 = round_fx( L_shl( L_tmp, 3 ) ); /*Q10*/ @@ -1935,8 +1936,8 @@ static void envelope_fx( tmp = s_min( tmp, qq ); rr = s_min( tmp, rr ); - L_tmp = L_mult( abs_s( sub( tilt, 8192 ) ), sub( 26214, shr( voice_factor, 1 ) ) ); /*Q28*/ - L_tmp = L_add( L_tmp, 268435456 ); + L_tmp = L_mult( abs_s( sub( tilt, 8192 /* 1 in Q13 */ ) ), sub( 26214 /* 1.6 in Q14 */, shr( voice_factor, 1 ) ) ); /*Q28*/ + L_tmp = L_add( L_tmp, 268435456 /* 1 in Q28 */ ); L_tmp = Mult_32_16( L_tmp, rr ); /*Q23*/ est_level2 = round_fx( L_shl( L_tmp, 3 ) ); /*Q10*/ @@ -1949,7 +1950,7 @@ static void envelope_fx( L_tmp = L_mult( rr, tmp ); /*Q(30-q1-10+10) */ #ifdef BASOP_NOGLOB - *sub_gain = s_min( 20480, round_fx_sat( L_shl_sat( L_tmp, sub( q1, 2 ) ) ) ); /*Q12 */ + *sub_gain = s_min( 20480 /* 5.0f in Q12 */, round_fx_sat( L_shl_sat( L_tmp, sub( q1, 2 ) ) ) ); /*Q12 */ move16(); #else *sub_gain = s_min( 20480, round_fx( L_shl( L_tmp, sub( q1, 2 ) ) ) ); /*Q12 */ @@ -1963,15 +1964,15 @@ static void envelope_fx( * adaptively select the start band of bandwidth extension *---------------------------------------------------------------------*/ -void AdaptiveStartBand_fx( - Word16 *start_band, /* o : start point of copied band */ - const Word32 core_rate, /* i : core bitrate */ - const Word16 *lsf_fx, /* i : Q2 lsf frequency */ - const Word16 voicing_fac_fx, /* i : Q14 voicing factors */ - const Word16 clas, /* i : signal class (determined by FEC algorithm)*/ - Word16 *voicing_flag, - Word16 *start_band_old, - Word32 *OptCrit_old_fx /*i/o : Q15 */ +static void AdaptiveStartBand_fx( + Word16 *start_band, /* o : start point of copied band Q0*/ + const Word32 core_rate, /* i : core bitrate Q0*/ + const Word16 *lsf_fx, /* i : lsf frequency Q2*/ + const Word16 voicing_fac_fx, /* i : voicing factors Q14*/ + const Word16 clas, /* i : signal class (determined by FEC algorithm) Q0*/ + Word16 *voicing_flag, /* Q0 */ + Word16 *start_band_old, /* Q0 */ + Word32 *OptCrit_old_fx /*i/o : Q15 */ ) { Word16 i, pos, M2, voicing_flag_old; @@ -1985,19 +1986,19 @@ void AdaptiveStartBand_fx( move32(); // corresponding to initialization of OptCrit_fx /*voicing switching flag : to avoid switching start band frequently in VOICED or AUDIO area*/ - voicing_flag_old = *voicing_flag; + voicing_flag_old = *voicing_flag; /* Q0 */ move16(); test(); test(); test(); - if ( GT_16( voicing_fac_fx, 6554 ) || ( GT_16( voicing_fac_fx, 4915 ) && GE_16( clas, VOICED_CLAS ) ) || EQ_16( clas, AUDIO_CLAS ) ) + if ( GT_16( voicing_fac_fx, 6554 /* 0.4 in Q14 */ ) || ( GT_16( voicing_fac_fx, 4915 /* 0.3 in Q14 */ ) && GE_16( clas, VOICED_CLAS ) ) || EQ_16( clas, AUDIO_CLAS ) ) { - *voicing_flag = 1; + *voicing_flag = 1; /* Q0 */ move16(); } test(); - if ( LT_16( voicing_fac_fx, 3277 ) && LT_16( clas, VOICED_CLAS ) ) + if ( LT_16( voicing_fac_fx, 3277 /* 0.2 in Q14 */ ) && LT_16( clas, VOICED_CLAS ) ) { *voicing_flag = 0; move16(); @@ -2016,14 +2017,14 @@ void AdaptiveStartBand_fx( *pt1++ = sub( *pt2++, *pt3++ ); move16(); /*Q2 */ } - tmp1 = extract_l( Mult_32_16( core_rate, 27046 ) ); /*Q14 */ - L_tmp = L_shr( L_mult0( tmp1, 22370 ), 15 ); /*Q27->1/6000 ->Q26 */ - tmp2 = extract_l( L_tmp ); /*Q26 */ - W_fx = mult_r( tmp1, tmp2 ); /*Q25 */ + tmp1 = extract_l( Mult_32_16( core_rate, 27046 /* 0.00005 in Q29 */ ) ); /*Q14 */ + L_tmp = L_shr( L_mult0( tmp1, 22370 /* 1/6000 in Q27 */ ), 15 ); /*Q27->1/6000 ->Q26 */ + tmp2 = extract_l( L_tmp ); /*Q26 */ + W_fx = mult_r( tmp1, tmp2 ); /*Q25 */ IF( EQ_16( clas, AUDIO_CLAS ) ) { - W_fx = mult_r( W_fx, 24576 ); /*Q25 */ + W_fx = mult_r( W_fx, 24576 /* 0.75 in Q15 */ ); /*Q25 */ } pos = 2; @@ -2050,8 +2051,8 @@ void AdaptiveStartBand_fx( } /*do the procedure for i==2*/ - L_tmp = L_max( L_msu( 171798692, lsf_fx[2], W_fx ), 171799 ); /* Q2.56+25+1 */ - Crit_fx = Mult_32_16( L_tmp, lsf_diff_fx[2] ); /* Q2.56+25+1+2.56-15 = Q11+2.56+2.56 */ + L_tmp = L_max( L_msu( 171798692 /* 1 in Q2.56+25+1 */, lsf_fx[2], W_fx ), 171799 /* 0.001 in Q2.56+25+1 */ ); /* Q2.56+25+1 */ + Crit_fx = Mult_32_16( L_tmp, lsf_diff_fx[2] ); /* Q2.56+25+1+2.56-15 = Q11+2.56+2.56 */ OptCrit_fx = L_add( Crit_fx, 0 ); pos = 2; @@ -2062,37 +2063,37 @@ void AdaptiveStartBand_fx( pt1 = &lsf_diff_fx[3]; FOR( i = 3; i < M2; i++ ) { - L_tmp = L_max( L_msu( 171798692, *pt2++, W_fx ), 171799 ); /* Q2.56+25+1 */ + L_tmp = L_max( L_msu( 171798692 /* 1 in Q2.56+25+1 */, *pt2++, W_fx ), 171799 /* 0.001 in Q2.56+25+1 */ ); /* Q2.56+25+1 */ Crit_fx = Mult_32_16( L_tmp, *pt1++ ); /* Q2.56+25+1+2.56-15 = Q11+2.56+2.56 */ IF( LE_32( Crit_fx, OptCrit_fx ) ) { OptCrit_fx = L_add( Crit_fx, 0 ); /* Q11+2.56+2.56 */ - pos = i; + pos = i; /* Q0 */ move16(); } } - tmp1 = add( mult_r( lsf_fx[pos - 1], 256 ), mult_r( lsf_fx[pos], 256 ) ); - *start_band = s_min( s_max( sub( tmp1, 40 ), 40 ), 160 ); + tmp1 = add( mult_r( lsf_fx[pos - 1], 256 ), mult_r( lsf_fx[pos], 256 ) ); /* Q0 */ + *start_band = s_min( s_max( sub( tmp1, 40 ), 40 ), 160 ); /* Q0 */ move16(); - L_tmp = Mult_32_16( *OptCrit_old_fx, 22938 ); /* Q11+2.56+2.56 */ + L_tmp = Mult_32_16( *OptCrit_old_fx, 22938 /* 0.7 in Q15 */ ); /* Q11+2.56+2.56 */ test(); test(); test(); test(); IF( NE_16( voicing_flag_old, *voicing_flag ) || ( *voicing_flag == 0 && LT_32( OptCrit_fx, *OptCrit_old_fx ) ) || - ( LT_32( OptCrit_fx, L_tmp ) && GT_32( *OptCrit_old_fx, 858993 ) ) ) + ( LT_32( OptCrit_fx, L_tmp ) && GT_32( *OptCrit_old_fx, 858993 /* 64 in Q11+2.56+2.56 */ ) ) ) { - *OptCrit_old_fx = OptCrit_fx; + *OptCrit_old_fx = OptCrit_fx; /* Q15 */ move16(); test(); test(); if ( LT_16( abs_s( sub( ( *start_band ), ( *start_band_old ) ) ), 20 ) && EQ_16( *voicing_flag, 1 ) && EQ_16( voicing_flag_old, 1 ) ) { - *start_band = *start_band_old; + *start_band = *start_band_old; /* Q0 */ move16(); } } @@ -2101,29 +2102,29 @@ void AdaptiveStartBand_fx( test(); if ( LT_32( OptCrit_fx, ( *OptCrit_old_fx ) ) && EQ_16( ( *voicing_flag ), 1 ) ) { - *OptCrit_old_fx = OptCrit_fx; + *OptCrit_old_fx = OptCrit_fx; /* Q15 */ move16(); } - *start_band = *start_band_old; + *start_band = *start_band_old; /* Q0 */ move16(); } IF( EQ_16( clas, AUDIO_CLAS ) ) { - *start_band = s_min( *start_band, 120 ); + *start_band = s_min( *start_band, 120 ); /* Q0 */ move16(); } flag = sub( s_and( *start_band, 0x0001 ), 1 ); IF( flag == 0 ) { - *start_band = sub( *start_band, 1 ); + *start_band = sub( *start_band, 1 ); /* Q0 */ move16(); } } - *start_band_old = *start_band; + *start_band_old = *start_band; /* Q0 */ move16(); return; diff --git a/lib_dec/hq_classifier_dec_fx.c b/lib_dec/hq_classifier_dec_fx.c index ace2e535c..e67d5f663 100644 --- a/lib_dec/hq_classifier_dec_fx.c +++ b/lib_dec/hq_classifier_dec_fx.c @@ -26,11 +26,11 @@ Word16 ivas_hq_classifier_dec_fx( /* o : Consumed bits Word16 bits; Word32 max_brate; - max_brate = HQ_32k; + max_brate = HQ_32k; /* Q0 */ move32(); if ( st_fx->element_mode > EVS_MONO ) { - max_brate = HQ_48k; + max_brate = HQ_48k; /* Q0 */ move32(); } test(); @@ -38,21 +38,21 @@ Word16 ivas_hq_classifier_dec_fx( /* o : Consumed bits test(); IF( ( EQ_16( length, L_SPEC32k ) || EQ_16( length, L_SPEC48k ) ) && LE_32( core_brate, max_brate ) ) { - *hqswb_clas = (Word16) get_next_indice_fx( st_fx, 2 ); + *hqswb_clas = (Word16) get_next_indice_fx( st_fx, 2 ); /* Q0 */ move16(); bits = 2; move16(); } ELSE IF( EQ_16( length, L_SPEC16k_EXT ) || EQ_16( length, L_SPEC48k_EXT ) ) { - *hqswb_clas = HQ_NORMAL; + *hqswb_clas = HQ_NORMAL; /* Q0 */ bits = 0; move16(); move16(); } ELSE { - *hqswb_clas = get_next_indice_fx( st_fx, 1 ); + *hqswb_clas = get_next_indice_fx( st_fx, 1 ); /* Q0 */ move16(); bits = 1; move16(); @@ -62,7 +62,7 @@ Word16 ivas_hq_classifier_dec_fx( /* o : Consumed bits move16(); if ( EQ_16( *hqswb_clas, HQ_TRANSIENT ) ) { - *is_transient = 1; + *is_transient = 1; /* Q0 */ move16(); } @@ -71,12 +71,12 @@ Word16 ivas_hq_classifier_dec_fx( /* o : Consumed bits { IF( EQ_16( length, L_SPEC32k ) ) { - *hqswb_clas = HQ_GEN_SWB; + *hqswb_clas = HQ_GEN_SWB; /* Q0 */ move16(); } ELSE IF( EQ_16( length, L_SPEC48k ) ) { - *hqswb_clas = HQ_GEN_FB; + *hqswb_clas = HQ_GEN_FB; /* Q0 */ move16(); } } @@ -97,11 +97,11 @@ Word16 hq_classifier_dec_fx( /* o : Consumed bits Word16 bits; Word32 max_brate; - max_brate = HQ_32k; + max_brate = HQ_32k; /* Q0 */ move32(); if ( st_fx->element_mode > EVS_MONO ) { - max_brate = HQ_48k; + max_brate = HQ_48k; /* Q0 */ move32(); } #ifndef SOLVED_COMP_ENC_DEC @@ -116,21 +116,21 @@ Word16 hq_classifier_dec_fx( /* o : Consumed bits IF( ( EQ_16( length, L_SPEC32k ) || EQ_16( length, L_SPEC48k ) ) && LE_32( core_brate, max_brate ) ) #endif { - *hqswb_clas = get_next_indice( st_fx, 2 ); + *hqswb_clas = get_next_indice( st_fx, 2 ); /* Q0 */ move16(); bits = 2; move16(); } ELSE IF( EQ_16( length, L_SPEC16k_EXT ) || EQ_16( length, L_SPEC48k_EXT ) ) { - *hqswb_clas = HQ_NORMAL; + *hqswb_clas = HQ_NORMAL; /* Q0 */ bits = 0; move16(); move16(); } ELSE { - *hqswb_clas = get_next_indice( st_fx, 1 ); + *hqswb_clas = get_next_indice( st_fx, 1 ); /* Q0 */ move16(); bits = 1; move16(); @@ -140,7 +140,7 @@ Word16 hq_classifier_dec_fx( /* o : Consumed bits move16(); if ( EQ_16( *hqswb_clas, HQ_TRANSIENT ) ) { - *is_transient = 1; + *is_transient = 1; /* Q0 */ move16(); } @@ -149,7 +149,7 @@ Word16 hq_classifier_dec_fx( /* o : Consumed bits { IF( EQ_16( length, L_SPEC32k ) ) { - *hqswb_clas = HQ_GEN_SWB; + *hqswb_clas = HQ_GEN_SWB; /* Q0 */ move16(); } #ifndef SOLVED_COMP_ENC_DEC @@ -158,7 +158,7 @@ Word16 hq_classifier_dec_fx( /* o : Consumed bits ELSE IF( EQ_16( length, L_SPEC48k ) ) #endif { - *hqswb_clas = HQ_GEN_FB; + *hqswb_clas = HQ_GEN_FB; /* Q0 */ move16(); } } diff --git a/lib_dec/hq_conf_fec_fx.c b/lib_dec/hq_conf_fec_fx.c index dfc19c542..adcd83076 100644 --- a/lib_dec/hq_conf_fec_fx.c +++ b/lib_dec/hq_conf_fec_fx.c @@ -16,22 +16,22 @@ * Initialization of HQ bands and subframes *--------------------------------------------------------------------------*/ void hq_configure_bfi_fx( - Word16 *nb_sfm, /* o : Number of sub bands Q0 */ - Word16 *num_Sb, /* o : Number of FEC sub bands ? Q0 */ - Word16 *num_bands_p, /* o : FEC sub bands Q0 */ - const Word16 **sfmsize, /* o : Subband bandwidths */ - const Word16 **sfm_start, /* o : Subband start coefficients */ - const Word16 **sfm_end /* o : Subband end coefficients */ + Word16 *nb_sfm, /* o : Number of sub bands Q0*/ + Word16 *num_Sb, /* o : Number of FEC sub bands ? Q0*/ + Word16 *num_bands_p, /* o : FEC sub bands Q0*/ + const Word16 **sfmsize, /* o : Subband bandwidths Q0*/ + const Word16 **sfm_start, /* o : Subband start coefficients Q0*/ + const Word16 **sfm_end /* o : Subband end coefficients Q0*/ ) { - *num_Sb = MAX_SB_NB; + *num_Sb = MAX_SB_NB; /* Q0 */ move16(); - *nb_sfm = SFM_N_NB; + *nb_sfm = SFM_N_NB; /* Q0 */ move16(); - Copy( Num_bands_NB, num_bands_p, *num_Sb ); - *sfmsize = band_len_wb; - *sfm_start = band_start_wb; - *sfm_end = band_end_wb; + Copy( Num_bands_NB, num_bands_p, *num_Sb ); /* Q0 */ + *sfmsize = band_len_wb; /* Q0 */ + *sfm_start = band_start_wb; /* Q0 */ + *sfm_end = band_end_wb; /* Q0 */ move16(); move16(); move16(); diff --git a/lib_dec/hq_core_dec_fx.c b/lib_dec/hq_core_dec_fx.c index 9ff889997..de8d19e32 100644 --- a/lib_dec/hq_core_dec_fx.c +++ b/lib_dec/hq_core_dec_fx.c @@ -19,11 +19,11 @@ void hq_core_dec_fx( Decoder_State *st_fx, /* i/o: decoder state structure fx */ - Word16 synth[], /* o : output synthesis */ + Word16 synth[], /* o : output synthesis Q_synth*/ Word16 *Q_synth, /* o : Q value of synth */ - const Word16 output_frame, /* i : output frame length */ - const Word16 hq_core_type, /* i : HQ core type */ - const Word16 core_switching_flag /* i : ACELP->HQ switching frame flag */ + const Word16 output_frame, /* i : output frame length Q0*/ + const Word16 hq_core_type, /* i : HQ core type Q0*/ + const Word16 core_switching_flag /* i : ACELP->HQ switching frame flag Q0*/ ) { Word16 num_bits, is_transient, hqswb_clas, inner_frame; @@ -62,15 +62,17 @@ void hq_core_dec_fx( move16(); sfm_start = sfm_end = NULL; num_Sb = nb_sfm = 0; + move16(); + move16(); - st_fx->hTcxCfg->tcx_last_overlap_mode = st_fx->hTcxCfg->tcx_curr_overlap_mode; + st_fx->hTcxCfg->tcx_last_overlap_mode = st_fx->hTcxCfg->tcx_curr_overlap_mode; /* Q0 */ move16(); if ( EQ_16( st_fx->hTcxCfg->tcx_curr_overlap_mode, FULL_OVERLAP ) ) { - st_fx->hTcxCfg->tcx_last_overlap_mode = ALDO_WINDOW; + st_fx->hTcxCfg->tcx_last_overlap_mode = ALDO_WINDOW; /* Q0 */ move16(); } - st_fx->hTcxCfg->tcx_curr_overlap_mode = ALDO_WINDOW; + st_fx->hTcxCfg->tcx_curr_overlap_mode = ALDO_WINDOW; /* Q0 */ move16(); /*-------------------------------------------------------------------------- * Find the number of bits for transform-domain coding @@ -114,18 +116,18 @@ void hq_core_dec_fx( } #endif /* subtract signalling bits */ - num_bits = sub( num_bits, st_fx->next_bit_pos ); + num_bits = sub( num_bits, st_fx->next_bit_pos ); /* Q0 */ /* set FEC parameters */ - flag_uv = sub( 1, hHQ_core->HqVoicing ); + flag_uv = sub( 1, hHQ_core->HqVoicing ); /* Q0 */ /* subtract the number of bits for pitch & gain at higher bitrates */ test(); IF( !( core_switching_flag ) && GT_32( st_fx->core_brate, MINIMUM_RATE_TO_ENCODE_VOICING_FLAG ) ) { - hHQ_core->HqVoicing = get_next_indice( st_fx, 1 ); + hHQ_core->HqVoicing = get_next_indice( st_fx, 1 ); /* Q0 */ move16(); - num_bits = sub( num_bits, 1 ); + num_bits = sub( num_bits, 1 ); /* Q0 */ } ELSE { @@ -133,7 +135,7 @@ void hq_core_dec_fx( move16(); if ( GT_32( st_fx->core_brate, MINIMUM_RATE_TO_ENCODE_VOICING_FLAG ) ) { - hHQ_core->HqVoicing = 1; + hHQ_core->HqVoicing = 1; /* Q0 */ move16(); } } @@ -145,10 +147,10 @@ void hq_core_dec_fx( } /* set inner frame (== coded bandwidth) length */ - inner_frame = inner_frame_tbl[st_fx->bwidth]; + inner_frame = inner_frame_tbl[st_fx->bwidth]; /* Q0 */ move16(); #ifndef ADD_IVAS_HQ_CODE_L_SPEC - L_spec = inner_frame; + L_spec = inner_frame; /* Q0 */ #endif move16(); @@ -174,7 +176,7 @@ void hq_core_dec_fx( IF( EQ_16( st_fx->bfi, 1 ) ) { - is_transient = hHQ_core->old_is_transient[0]; + is_transient = hHQ_core->old_is_transient[0]; /* Q0 */ move16(); IF( GE_16( output_frame, L_FRAME16k ) ) /* Apply phase ecu for WB, SWB and FB */ { @@ -189,22 +191,22 @@ void hq_core_dec_fx( output_frame, sfm_start, sfm_end ); } - hHQ_core->old_is_transient[2] = hHQ_core->old_is_transient[1]; + hHQ_core->old_is_transient[2] = hHQ_core->old_is_transient[1]; /* Q0 */ move16(); - hHQ_core->old_is_transient[1] = hHQ_core->old_is_transient[0]; + hHQ_core->old_is_transient[1] = hHQ_core->old_is_transient[0]; /* Q0 */ move16(); IF( GE_16( output_frame, L_FRAME16k ) ) { /* keep st->previoussynth updated as in FEC_HQ_pitch_analysis but no LP analysis */ - delay_comp = NS2SA_FX2( st_fx->output_Fs, DELAY_CLDFB_NS ); + delay_comp = NS2SA_FX2( st_fx->output_Fs, DELAY_CLDFB_NS ); /* Q0 */ - Copy( st_fx->previoussynth_fx + delay_comp, st_fx->previoussynth_fx, sub( output_frame, delay_comp ) ); - Copy( st_fx->delay_buf_out_fx, st_fx->previoussynth_fx + output_frame - delay_comp, delay_comp ); + Copy( st_fx->previoussynth_fx + delay_comp, st_fx->previoussynth_fx, sub( output_frame, delay_comp ) ); /* Q0 */ + Copy( st_fx->delay_buf_out_fx, st_fx->previoussynth_fx + output_frame - delay_comp, delay_comp ); /* Q0 */ flag_uv = 1; move16(); /* disable costly pitch out synthesis in bfi frame */ - hHQ_core->HqVoicing = sub( 1, flag_uv ); /* safety setting for HQ->ACELP switch logic */ + hHQ_core->HqVoicing = sub( 1, flag_uv ); /* safety setting for HQ->ACELP switch logic Q0*/ set16_fx( hHQ_core->fer_samples_fx, 0, L_FRAME48k ); /* safety, create a known signal state for HQ->ACELP switch logic */ } } @@ -222,7 +224,7 @@ void hq_core_dec_fx( /* HQ low rate decoder */ hq_lr_dec_fx( st_fx, t_audio_q, inner_frame, num_bits, &is_transient ); - hqswb_clas = is_transient; + hqswb_clas = is_transient; /* Q0 */ move16(); Q_audio = 12; move16(); @@ -251,8 +253,8 @@ void hq_core_dec_fx( } ELSE { - tmp = mult_r( output_frame, 410 / 2 ); /* 1/8000 in Q15 */ - ener_match = hq_nominal_scaling_inv[tmp]; + tmp = mult_r( output_frame, 410 / 2 ); /* 1/8000 in Q15 */ + ener_match = hq_nominal_scaling_inv[tmp]; /* Q13 */ move16(); FOR( i = 0; i < inner_frame; i++ ) { @@ -280,7 +282,7 @@ void hq_core_dec_fx( IF( EQ_16( st_fx->bws_cnt1, N_NS2W_FRAMES ) ) { ener_match = 32767; - move16(); /*Q15*/ + move16(); /* 1.0f in Q15 */ } ELSE { @@ -291,11 +293,11 @@ void hq_core_dec_fx( { FOR( i = 0; i < NUM_TIME_SWITCHING_BLOCKS; i++ ) { - tmp_loop = mult( inner_frame, 8192 ); - FOR( j = mult( inner_frame_tbl[sub( st_fx->bwidth, 1 )], 8192 ); j < tmp_loop; j++ ) + tmp_loop = mult( inner_frame, 8192 /* 0.25 in Q15 */ ); + FOR( j = mult( inner_frame_tbl[st_fx->bwidth - 1], 8192 ); j < tmp_loop; j++ ) { - tmp = i_mult( i, inner_frame ); /*Q0*/ - tmp = mult( tmp, 8192 ); /*Q0*/ + tmp = i_mult( i, inner_frame ); /*Q0*/ + tmp = mult( tmp, 8192 /* 0.25 in Q15 */ ); /*Q0*/ tmp = add( tmp, j ); t_audio_q[tmp] = Mult_32_16( t_audio_q[tmp], ener_match ); move32(); /*Q12*/ @@ -304,7 +306,7 @@ void hq_core_dec_fx( } ELSE { - FOR( i = inner_frame_tbl[sub( st_fx->bwidth, 1 )]; i < inner_frame; i++ ) + FOR( i = inner_frame_tbl[st_fx->bwidth - 1]; i < inner_frame; i++ ) { t_audio_q[i] = Mult_32_16( t_audio_q[i], ener_match ); /*Q12*/ move32(); @@ -315,11 +317,11 @@ void hq_core_dec_fx( /* WB/SWB bandwidth switching */ IF( is_transient ) { - Copy_Scale_sig_32_16( &t_audio_q[240], st_fx->t_audio_q_fx, 80, -13 ); + Copy_Scale_sig_32_16( &t_audio_q[240], st_fx->t_audio_q_fx, 80, -13 ); /* -1Q */ } ELSE { - Copy_Scale_sig_32_16( t_audio_q, st_fx->t_audio_q_fx, L_FRAME, -13 ); + Copy_Scale_sig_32_16( t_audio_q, st_fx->t_audio_q_fx, L_FRAME, -13 ); /* -1Q */ } @@ -421,7 +423,7 @@ void hq_core_dec_fx( test(); IF( st_fx->bfi == 0 && st_fx->prev_bfi == 0 ) { - Copy_Scale_sig( hHQ_core->old_out_fx + N_ZERO_NB, hHQ_nbfec->prev_oldauOut_fx, output_frame - N_ZERO_NB, negate( hHQ_core->Q_old_wtda ) ); + Copy_Scale_sig( hHQ_core->old_out_fx + N_ZERO_NB, hHQ_nbfec->prev_oldauOut_fx, output_frame - N_ZERO_NB, negate( hHQ_core->Q_old_wtda ) ); /* 15 - exp_old_out - Q_old_wtda */ } ELSE IF( EQ_16( st_fx->prev_bfi, 1 ) ) { @@ -499,7 +501,7 @@ void hq_core_dec_fx( IF( !st_fx->bfi && st_fx->prev_bfi && GE_32( st_fx->last_total_brate, HQ_48k ) && EQ_16( st_fx->last_codec_mode, MODE2 ) && ( EQ_16( st_fx->last_core_bfi, TCX_20_CORE ) || EQ_16( st_fx->last_core_bfi, TCX_10_CORE ) ) && st_fx->plcInfo.concealment_method == TCX_NONTONAL && LT_32( st_fx->plcInfo.nbLostCmpt, 4 ) ) { #ifdef BASOP_NOGLOB - st_fx->plcInfo.recovery_gain = shl_sat( st_fx->plcInfo.recovery_gain, *Q_synth ); + st_fx->plcInfo.recovery_gain = shl_sat( st_fx->plcInfo.recovery_gain, *Q_synth ); /* Q14 + Q_synth */ move16(); #else st_fx->plcInfo.recovery_gain = shl( st_fx->plcInfo.recovery_gain, *Q_synth ); @@ -526,7 +528,7 @@ void hq_core_dec_fx( { hHQ_core->oldHqVoicing = 1; move16(); - Copy( gapsynth_fx, hHQ_core->oldgapsynth_fx, L_FRAME48k ); + Copy( gapsynth_fx, hHQ_core->oldgapsynth_fx, L_FRAME48k ); /* q_gapsynth */ } ELSE { @@ -548,9 +550,9 @@ void hq_core_dec_fx( IF( EQ_16( output_frame, L_FRAME8k ) ) { - Copy32( wtda_audio, hHQ_nbfec->oldIMDCTout_fx, L_FRAME8k / 2 ); - Copy( &hHQ_nbfec->old_auOut_2fr_fx[output_frame], hHQ_nbfec->old_auOut_2fr_fx, output_frame ); - Copy_Scale_sig( synth, &hHQ_nbfec->old_auOut_2fr_fx[output_frame], output_frame, negate( *Q_synth ) ); + Copy32( wtda_audio, hHQ_nbfec->oldIMDCTout_fx, L_FRAME8k / 2 ); /* q_wtda */ + Copy( &hHQ_nbfec->old_auOut_2fr_fx[output_frame], hHQ_nbfec->old_auOut_2fr_fx, output_frame ); /* q_old_auOut */ + Copy_Scale_sig( synth, &hHQ_nbfec->old_auOut_2fr_fx[output_frame], output_frame, negate( *Q_synth ) ); /* Q0 */ } /* prepare synthesis output buffer (as recent as possible) for HQ FEC */ @@ -558,11 +560,11 @@ void hq_core_dec_fx( { Word16 nbsubfr; /*nbsubfr = extract_l(L_mult0(st_fx->L_frame,FL2WORD16(1/L_SUBFR)));*/ - nbsubfr = 4; + nbsubfr = 4; /* Q0 */ move16(); if ( EQ_16( st_fx->L_frame, 320 ) ) { - nbsubfr = 5; + nbsubfr = 5; /* Q0 */ move16(); } @@ -572,9 +574,9 @@ void hq_core_dec_fx( { set32_fx( &st_fx->old_pitch_buf_fx[nbsubfr], ( L_SUBFR << 16 ), nbsubfr ); } - Copy32( &st_fx->old_pitch_buf_fx[nbsubfr], &st_fx->old_pitch_buf_fx[0], nbsubfr ); + Copy32( &st_fx->old_pitch_buf_fx[nbsubfr], &st_fx->old_pitch_buf_fx[0], nbsubfr ); /* 15Q16 */ set32_fx( &st_fx->old_pitch_buf_fx[nbsubfr], ( L_SUBFR << 16 ), nbsubfr ); - Copy( &st_fx->mem_pitch_gain[2], &st_fx->mem_pitch_gain[nbsubfr + 2], nbsubfr ); + Copy( &st_fx->mem_pitch_gain[2], &st_fx->mem_pitch_gain[nbsubfr + 2], nbsubfr ); /* Q14 */ set16_fx( &st_fx->mem_pitch_gain[2], 0, nbsubfr ); } #ifdef ADD_IVAS_HQ_CODE @@ -590,12 +592,12 @@ void hq_core_dec_fx( void ivas_hq_core_dec_fx( Decoder_State *st_fx, /* i/o: decoder state structure fx */ - Word16 synth[], /* o : output synthesis */ + Word16 synth[], /* o : output synthesis Q_synth*/ Word16 *Q_synth, /* o : Q value of synth */ - const Word16 output_frame, /* i : output frame length */ - const Word16 hq_core_type, /* i : HQ core type */ - const Word16 core_switching_flag, /* i : ACELP->HQ switching frame flag */ - Word16 output[], + const Word16 output_frame, /* i : output frame length Q0*/ + const Word16 hq_core_type, /* i : HQ core type Q0*/ + const Word16 core_switching_flag, /* i : ACELP->HQ switching frame flag Q0*/ + Word16 output[], /* Q_ouput */ Word16 *Q_output ) { Word16 num_bits, is_transient, hqswb_clas, inner_frame; @@ -656,14 +658,14 @@ void ivas_hq_core_dec_fx( hTcxDec = st_fx->hTcxDec; - st_fx->hTcxCfg->tcx_last_overlap_mode = st_fx->hTcxCfg->tcx_curr_overlap_mode; + st_fx->hTcxCfg->tcx_last_overlap_mode = st_fx->hTcxCfg->tcx_curr_overlap_mode; /* Q0 */ move16(); if ( EQ_16( st_fx->hTcxCfg->tcx_curr_overlap_mode, FULL_OVERLAP ) ) { - st_fx->hTcxCfg->tcx_last_overlap_mode = ALDO_WINDOW; + st_fx->hTcxCfg->tcx_last_overlap_mode = ALDO_WINDOW; /* Q0 */ move16(); } - st_fx->hTcxCfg->tcx_curr_overlap_mode = ALDO_WINDOW; + st_fx->hTcxCfg->tcx_curr_overlap_mode = ALDO_WINDOW; /* Q0 */ move16(); test(); test(); @@ -678,7 +680,7 @@ void ivas_hq_core_dec_fx( num_bits = extract_l( L_shr( L_tmp, 3 ) ); /*Q0 */ /* Set default spectrum length */ - L_spec = l_spec_tbl[st_fx->bwidth]; + L_spec = l_spec_tbl[st_fx->bwidth]; /* Q0 */ move16(); IF( !st_fx->bfi ) { @@ -686,7 +688,7 @@ void ivas_hq_core_dec_fx( { IF( NE_16( st_fx->element_mode, EVS_MONO ) ) { - L_spec = l_spec_ext_tbl[st_fx->bwidth]; + L_spec = l_spec_ext_tbl[st_fx->bwidth]; /* Q0 */ move16(); } ELSE @@ -706,18 +708,18 @@ void ivas_hq_core_dec_fx( acelp_plc_mdct_transition_fx( st_fx ); } /* subtract signalling bits */ - num_bits = sub( num_bits, st_fx->next_bit_pos ); + num_bits = sub( num_bits, st_fx->next_bit_pos ); /* Q0 */ /* set FEC parameters */ - flag_uv = sub( 1, hHQ_core->HqVoicing ); + flag_uv = sub( 1, hHQ_core->HqVoicing ); /* Q0 */ /* subtract the number of bits for pitch & gain at higher bitrates */ test(); IF( !( core_switching_flag ) && GT_32( st_fx->core_brate, MINIMUM_RATE_TO_ENCODE_VOICING_FLAG ) ) { - hHQ_core->HqVoicing = get_next_indice_fx( st_fx, 1 ); + hHQ_core->HqVoicing = get_next_indice_fx( st_fx, 1 ); /* Q0 */ move16(); - num_bits = sub( num_bits, 1 ); + num_bits = sub( num_bits, 1 ); /* Q0 */ } ELSE { @@ -725,7 +727,7 @@ void ivas_hq_core_dec_fx( move16(); if ( GT_32( st_fx->core_brate, MINIMUM_RATE_TO_ENCODE_VOICING_FLAG ) ) { - hHQ_core->HqVoicing = 1; + hHQ_core->HqVoicing = 1; /* Q0 */ move16(); } } @@ -737,7 +739,7 @@ void ivas_hq_core_dec_fx( } /* set inner frame (== coded bandwidth) length */ - inner_frame = inner_frame_tbl[st_fx->bwidth]; + inner_frame = inner_frame_tbl[st_fx->bwidth]; /* Q0 */ move16(); IF( EQ_16( st_fx->bfi, 0 ) ) @@ -746,7 +748,7 @@ void ivas_hq_core_dec_fx( move16(); if ( GE_16( output_frame, L_FRAME16k ) ) { - hHQ_core->ph_ecu_HqVoicing = hHQ_core->HqVoicing; + hHQ_core->ph_ecu_HqVoicing = hHQ_core->HqVoicing; /* Q0 */ move16(); } } @@ -762,7 +764,7 @@ void ivas_hq_core_dec_fx( IF( EQ_16( st_fx->bfi, 1 ) ) { - is_transient = hHQ_core->old_is_transient[0]; + is_transient = hHQ_core->old_is_transient[0]; /* Q0 */ move16(); IF( GE_16( output_frame, L_FRAME16k ) ) /* Apply phase ecu for WB, SWB and FB */ { @@ -777,22 +779,22 @@ void ivas_hq_core_dec_fx( output_frame, sfm_start, sfm_end ); } - hHQ_core->old_is_transient[2] = hHQ_core->old_is_transient[1]; + hHQ_core->old_is_transient[2] = hHQ_core->old_is_transient[1]; /* Q0 */ move16(); - hHQ_core->old_is_transient[1] = hHQ_core->old_is_transient[0]; + hHQ_core->old_is_transient[1] = hHQ_core->old_is_transient[0]; /* Q0 */ move16(); IF( GE_16( output_frame, L_FRAME16k ) ) { /* keep st->previoussynth updated as in FEC_HQ_pitch_analysis but no LP analysis */ - delay_comp = NS2SA_FX2( st_fx->output_Fs, DELAY_CLDFB_NS ); + delay_comp = NS2SA_FX2( st_fx->output_Fs, DELAY_CLDFB_NS ); /* Q0 */ - Copy( st_fx->previoussynth_fx + delay_comp, st_fx->previoussynth_fx, sub( output_frame, delay_comp ) ); - Copy( st_fx->delay_buf_out_fx, st_fx->previoussynth_fx + output_frame - delay_comp, delay_comp ); + Copy( st_fx->previoussynth_fx + delay_comp, st_fx->previoussynth_fx, sub( output_frame, delay_comp ) ); /* q_previoussynth */ + Copy( st_fx->delay_buf_out_fx, st_fx->previoussynth_fx + output_frame - delay_comp, delay_comp ); /* q_delay_buff */ flag_uv = 1; move16(); /* disable costly pitch out synthesis in bfi frame */ - hHQ_core->HqVoicing = sub( 1, flag_uv ); /* safety setting for HQ->ACELP switch logic */ + hHQ_core->HqVoicing = sub( 1, flag_uv ); /* safety setting for HQ->ACELP switch logic Q0*/ move16(); set16_fx( hHQ_core->fer_samples_fx, 0, L_FRAME48k ); /* safety, create a known signal state for HQ->ACELP switch logic */ } @@ -811,7 +813,7 @@ void ivas_hq_core_dec_fx( /* HQ low rate decoder */ hq_lr_dec_fx( st_fx, t_audio_q, inner_frame, num_bits, &is_transient ); - hqswb_clas = is_transient; + hqswb_clas = is_transient; /* Q0 */ move16(); Q_audio = 12; move16(); @@ -843,8 +845,8 @@ void ivas_hq_core_dec_fx( } ELSE { - tmp = mult_r( output_frame, 410 / 2 ); /* 1/8000 in Q15 */ - ener_match = hq_nominal_scaling_inv[tmp]; + tmp = mult_r( output_frame, 410 / 2 ); /* 1/8000 in Q15 */ + ener_match = hq_nominal_scaling_inv[tmp]; /* Q13 */ move16(); FOR( i = 0; i < inner_frame; i++ ) { @@ -872,7 +874,7 @@ void ivas_hq_core_dec_fx( IF( EQ_16( st_fx->bws_cnt1, N_NS2W_FRAMES ) ) { ener_match = 32767; - move16(); /*Q15*/ + move16(); /* 1.0f in Q15*/ } ELSE { @@ -883,11 +885,11 @@ void ivas_hq_core_dec_fx( { FOR( i = 0; i < NUM_TIME_SWITCHING_BLOCKS; i++ ) { - tmp_loop = mult( inner_frame, 8192 ); - FOR( j = mult( inner_frame_tbl[sub( st_fx->bwidth, 1 )], 8192 ); j < tmp_loop; j++ ) + tmp_loop = mult( inner_frame, 8192 /* 0.25 in Q15 */ ); /* Q0 */ + FOR( j = mult( inner_frame_tbl[st_fx->bwidth - 1], 8192 ); j < tmp_loop; j++ ) { - tmp = i_mult( i, inner_frame ); /*Q0*/ - tmp = mult( tmp, 8192 ); /*Q0*/ + tmp = i_mult( i, inner_frame ); /*Q0*/ + tmp = mult( tmp, 8192 /* 0.25 in Q15 */ ); /*Q0*/ tmp = add( tmp, j ); t_audio_q[tmp] = Mult_32_16( t_audio_q[tmp], ener_match ); move32(); /*Q12*/ @@ -896,7 +898,7 @@ void ivas_hq_core_dec_fx( } ELSE { - FOR( i = inner_frame_tbl[sub( st_fx->bwidth, 1 )]; i < inner_frame; i++ ) + FOR( i = inner_frame_tbl[st_fx->bwidth - 1]; i < inner_frame; i++ ) { t_audio_q[i] = Mult_32_16( t_audio_q[i], ener_match ); /*Q12*/ move32(); @@ -907,11 +909,11 @@ void ivas_hq_core_dec_fx( /* WB/SWB bandwidth switching */ IF( is_transient ) { - Copy_Scale_sig_32_16( &t_audio_q[240], st_fx->t_audio_q_fx, 80, -13 ); + Copy_Scale_sig_32_16( &t_audio_q[240], st_fx->t_audio_q_fx, 80, -13 ); /* -1Q */ } ELSE { - Copy_Scale_sig_32_16( t_audio_q, st_fx->t_audio_q_fx, L_FRAME, -13 ); + Copy_Scale_sig_32_16( t_audio_q, st_fx->t_audio_q_fx, L_FRAME, -13 ); /* -1Q */ } @@ -926,34 +928,34 @@ void ivas_hq_core_dec_fx( { /* Initializations for TCX MDCT framework, to be used for switching frame */ tcx_cfg = st_fx->hTcxCfg; - L_frameTCX_glob = hTcxDec->L_frameTCX; + L_frameTCX_glob = hTcxDec->L_frameTCX; /* Q0 */ move16(); - L_frame_glob = st_fx->L_frame; + L_frame_glob = st_fx->L_frame; /* Q0 */ move16(); - L_spec = hTcxDec->L_frameTCX; + L_spec = hTcxDec->L_frameTCX; /* Q0 */ move16(); - st_fx->fscale = sr2fscale_fx( st_fx->sr_core ); + st_fx->fscale = sr2fscale_fx( st_fx->sr_core ); /* Q0 */ // fscaleFB = sr2fscale( st_fx->output_Fs ); // encoderLookahead = ( L_LOOK_12k8 * st_fx->fscale ) / FSCALE_DENOM; // encoderLookaheadFB = ( L_LOOK_12k8 * fscaleFB ) / FSCALE_DENOM; - mdctWindowLength = getMdctWindowLength( st_fx->fscale ); + mdctWindowLength = getMdctWindowLength( st_fx->fscale ); /* Q0 */ Word16 temp, temp_e; temp = BASOP_Util_Divide3232_Scale( st_fx->output_Fs, st_fx->sr_core, &temp_e ); - mdctWindowLengthFB = extract_l( L_shr( L_mult0( temp, mdctWindowLength ), sub( 15, temp_e ) ) ); + mdctWindowLengthFB = extract_l( L_shr( L_mult0( temp, mdctWindowLength ), sub( 15, temp_e ) ) ); /* Q0 */ IF( core_switching_flag ) { - tcx_cfg->tcx_last_overlap_mode = TRANSITION_OVERLAP; + tcx_cfg->tcx_last_overlap_mode = TRANSITION_OVERLAP; /* Q0 */ move16(); - tcx_cfg->tcx_curr_overlap_mode = FULL_OVERLAP; + tcx_cfg->tcx_curr_overlap_mode = FULL_OVERLAP; /* Q0 */ move16(); } ELSE { - tcx_cfg->tcx_last_overlap_mode = ALDO_WINDOW; + tcx_cfg->tcx_last_overlap_mode = ALDO_WINDOW; /* Q0 */ move16(); - tcx_cfg->tcx_curr_overlap_mode = ALDO_WINDOW; + tcx_cfg->tcx_curr_overlap_mode = ALDO_WINDOW; /* Q0 */ move16(); - st_fx->last_core = HQ_CORE; /* Needed to decode non-transition frame */ + st_fx->last_core = HQ_CORE; /* Needed to decode non-transition frame Q0*/ move16(); } @@ -961,11 +963,11 @@ void ivas_hq_core_dec_fx( init_tcx_info_fx( st_fx, L_frame_glob, L_frameTCX_glob, 0, st_fx->bfi, &tcx_offset, &tcx_offsetFB, &L_frame, &L_frameTCX, &left_rect, &L_spec ); - overlap = tcx_cfg->tcx_mdct_window_length; + overlap = tcx_cfg->tcx_mdct_window_length; /* Q0 */ move16(); - overlapFB = tcx_cfg->tcx_mdct_window_lengthFB; + overlapFB = tcx_cfg->tcx_mdct_window_lengthFB; /* Q0 */ move16(); - index = tcx_cfg->tcx_last_overlap_mode; + index = tcx_cfg->tcx_last_overlap_mode; /* Q0 */ move16(); #ifndef MSAN_FIX @@ -978,9 +980,9 @@ void ivas_hq_core_dec_fx( left_rect, tcx_offset, overlap, L_frame, L_frameTCX, shr( s_max( L_frameTCX, L_spec ), 1 ), L_frame_glob, 0, st_fx->bfi, hHQ_core->old_out_LB_fx, &hHQ_core->Q_old_wtda_LB, st_fx, 0, acelp_zir ); // values till L_frame same - Scale_sig( wtda_audio_16 + L_frame, overlap, Q1 ); + Scale_sig( wtda_audio_16 + L_frame, overlap, Q1 ); /* q_wtda + 1 */ - Copy( wtda_audio_16 + sub( shr( overlap, 1 ), tcx_offset ), output, L_frame_glob ); + Copy( wtda_audio_16 + sub( shr( overlap, 1 ), tcx_offset ), output, L_frame_glob ); /* q_wtda + 1 */ /* FB synthesis */ temp = BASOP_Util_Divide3232_Scale( L_mult0( FSCALE_DENOM, L_frameTCX_glob ), L_frame_glob, &temp_e ); @@ -988,14 +990,14 @@ void ivas_hq_core_dec_fx( IMDCT_fx( t_audio_q, E_audio, hTcxDec->syn_OverlFB, hTcxDec->syn_Overl_TDACFB, wtda_audio_16, tcx_cfg->tcx_aldo_window_1_FB, tcx_cfg->tcx_aldo_window_1_FB_trunc, tcx_cfg->tcx_aldo_window_2_FB, tcx_cfg->tcx_mdct_window_halfFB, tcx_cfg->tcx_mdct_window_minimumFB, tcx_cfg->tcx_mdct_window_transFB, tcx_cfg->tcx_mdct_window_half_lengthFB, tcx_cfg->tcx_mdct_window_min_lengthFB, index, left_rect, tcx_offsetFB, overlapFB, L_frameTCX, L_frameTCX, shr( s_max( L_frameTCX, L_spec ), 1 ), L_frameTCX_glob, 0, st_fx->bfi, hHQ_core->old_out_fx, &hHQ_core->Q_old_wtda, st_fx, temp, acelp_zir ); - Scale_sig( wtda_audio_16 + L_frameTCX, overlapFB, Q1 ); + Scale_sig( wtda_audio_16 + L_frameTCX, overlapFB, Q1 ); /* q_wtda + 1 */ - Copy( wtda_audio_16 + sub( shr( overlapFB, 1 ), tcx_offsetFB ), synth, L_frameTCX_glob ); + Copy( wtda_audio_16 + sub( shr( overlapFB, 1 ), tcx_offsetFB ), synth, L_frameTCX_glob ); /* q_wtda */ - Copy_Scale_sig_16_32( wtda_audio_16, wtda_audio, 2 * L_FRAME48k, 12 ); + Copy_Scale_sig_16_32( wtda_audio_16, wtda_audio, 2 * L_FRAME48k, 12 ); /* q_wtda + 12 */ IF( !core_switching_flag ) { - st_fx->last_core = ACELP_CORE; /* Restore last core */ + st_fx->last_core = ACELP_CORE; /* Restore last core Q0*/ move16(); } } @@ -1036,9 +1038,9 @@ void ivas_hq_core_dec_fx( tmp = Sqrt16( tmp, &tmp_e ); ener_match = shr( tmp, sub( 2, tmp_e ) ); // Q13 - v_multc_fixed_16( t_audio_q, ener_match, t_audio_q, inner_frame ); // Q + v_multc_fixed_16( t_audio_q, ener_match, t_audio_q, inner_frame ); // Q10 - Scale_sig32( t_audio_q, inner_frame, Q2 ); + Scale_sig32( t_audio_q, inner_frame, Q2 ); // Q10 + Q2 Q_audio = Q_G_audio; move16(); Inverse_Transform( t_audio_q, &Q_audio, wtda_audio_LB, is_transient, st_fx->L_frame, inner_frame, st_fx->element_mode ); @@ -1052,7 +1054,7 @@ void ivas_hq_core_dec_fx( test(); IF( EQ_16( st_fx->bfi, 0 ) && st_fx->prev_bfi == 0 ) { - Copy_Scale_sig( hHQ_core->old_out_fx + N_ZERO_NB, hHQ_nbfec->prev_oldauOut_fx, output_frame - N_ZERO_NB, negate( hHQ_core->Q_old_wtda ) ); + Copy_Scale_sig( hHQ_core->old_out_fx + N_ZERO_NB, hHQ_nbfec->prev_oldauOut_fx, output_frame - N_ZERO_NB, negate( hHQ_core->Q_old_wtda ) ); /* 31 - exp_old_out - Q_old_wtda */ } ELSE IF( EQ_16( st_fx->prev_bfi, 1 ) ) { @@ -1129,7 +1131,7 @@ void ivas_hq_core_dec_fx( IF( !st_fx->bfi && st_fx->prev_bfi && GE_32( st_fx->last_total_brate, HQ_48k ) && EQ_16( st_fx->last_codec_mode, MODE2 ) && ( EQ_16( st_fx->last_core_bfi, TCX_20_CORE ) || EQ_16( st_fx->last_core_bfi, TCX_10_CORE ) ) && EQ_16( st_fx->plcInfo.concealment_method, TCX_NONTONAL ) && LT_32( st_fx->plcInfo.nbLostCmpt, 4 ) ) { #ifdef BASOP_NOGLOB - st_fx->plcInfo.recovery_gain = shl_sat( st_fx->plcInfo.recovery_gain, *Q_synth ); + st_fx->plcInfo.recovery_gain = shl_sat( st_fx->plcInfo.recovery_gain, *Q_synth ); /* Q15 */ #else st_fx->plcInfo.recovery_gain = shl( st_fx->plcInfo.recovery_gain, *Q_synth ); #endif @@ -1155,7 +1157,7 @@ void ivas_hq_core_dec_fx( { hHQ_core->oldHqVoicing = 1; move16(); - Copy( gapsynth_fx, hHQ_core->oldgapsynth_fx, L_FRAME48k ); + Copy( gapsynth_fx, hHQ_core->oldgapsynth_fx, L_FRAME48k ); /* q_gapsynth */ } ELSE { @@ -1177,9 +1179,9 @@ void ivas_hq_core_dec_fx( IF( EQ_16( output_frame, L_FRAME8k ) ) { - Copy32( wtda_audio, hHQ_nbfec->oldIMDCTout_fx, L_FRAME8k / 2 ); - Copy( &hHQ_nbfec->old_auOut_2fr_fx[output_frame], hHQ_nbfec->old_auOut_2fr_fx, output_frame ); - Copy_Scale_sig( synth, &hHQ_nbfec->old_auOut_2fr_fx[output_frame], output_frame, negate( *Q_synth ) ); + Copy32( wtda_audio, hHQ_nbfec->oldIMDCTout_fx, L_FRAME8k / 2 ); /* q_wtda */ + Copy( &hHQ_nbfec->old_auOut_2fr_fx[output_frame], hHQ_nbfec->old_auOut_2fr_fx, output_frame ); /* Q_old_auOut */ + Copy_Scale_sig( synth, &hHQ_nbfec->old_auOut_2fr_fx[output_frame], output_frame, negate( *Q_synth ) ); /* Q0 */ } /* prepare synthesis output buffer (as recent as possible) for HQ FEC */ @@ -1187,10 +1189,10 @@ void ivas_hq_core_dec_fx( { Word16 nbsubfr; /*nbsubfr = extract_l(L_mult0(st_fx->L_frame,FL2WORD16(1/L_SUBFR)));*/ - nbsubfr = 4; + nbsubfr = 4; /* Q0 */ if ( EQ_16( st_fx->L_frame, 320 ) ) { - nbsubfr = 5; + nbsubfr = 5; /* Q0 */ move16(); } @@ -1200,16 +1202,16 @@ void ivas_hq_core_dec_fx( { set32_fx( &st_fx->old_pitch_buf_fx[nbsubfr], ( L_SUBFR << 16 ), nbsubfr ); } - Copy32( &st_fx->old_pitch_buf_fx[nbsubfr], &st_fx->old_pitch_buf_fx[0], nbsubfr ); + Copy32( &st_fx->old_pitch_buf_fx[nbsubfr], &st_fx->old_pitch_buf_fx[0], nbsubfr ); /* 15Q16 */ set32_fx( &st_fx->old_pitch_buf_fx[nbsubfr], ( L_SUBFR << 16 ), nbsubfr ); - Copy( &st_fx->mem_pitch_gain[2], &st_fx->mem_pitch_gain[nbsubfr + 2], nbsubfr ); + Copy( &st_fx->mem_pitch_gain[2], &st_fx->mem_pitch_gain[nbsubfr + 2], nbsubfr ); /* Q14 */ set16_fx( &st_fx->mem_pitch_gain[2], 0, nbsubfr ); } /* Move LB excitation to old_exc memory in case of switch HQ->ACELP */ IF( st_fx->element_mode > EVS_MONO ) { - Copy_Scale_sig( output, tmp_out, st_fx->L_frame, -( *Q_output ) ); - Copy( tmp_out, st_fx->old_exc_fx + sub( L_EXC_MEM_DEC, st_fx->L_frame ), st_fx->L_frame ); + Copy_Scale_sig( output, tmp_out, st_fx->L_frame, negate( *Q_output ) ); /* Q0 */ + Copy( tmp_out, st_fx->old_exc_fx + sub( L_EXC_MEM_DEC, st_fx->L_frame ), st_fx->L_frame ); /* Q0 */ } return; } @@ -1238,7 +1240,7 @@ void HQ_core_dec_init_fx( move16(); move16(); - hHQ_core->last_hq_core_type = -1; + hHQ_core->last_hq_core_type = -1; /* Q0 */ move16(); set16_fx( hHQ_core->old_is_transient, 0, 3 ); @@ -1251,7 +1253,7 @@ void HQ_core_dec_init_fx( move16(); move16(); move16(); - hHQ_core->energy_lt_fx = 2457600; /*Q13*/ + hHQ_core->energy_lt_fx = 2457600; /*300.0f in Q13*/ hHQ_core->hq_generic_seed = RANDOM_INITSEED; set16_fx( hHQ_core->prev_noise_level_fx, 0, 2 ); hHQ_core->prev_hqswb_clas = HQ_NORMAL; @@ -1281,7 +1283,7 @@ void HQ_core_dec_init_fx( move16(); hHQ_core->prev_stab_hfe2 = 0; move16(); - hHQ_core->prev_ni_ratio_fx = 16384; /*Q15*/ + hHQ_core->prev_ni_ratio_fx = 16384; /*0.5 in Q15*/ move16(); set16_fx( hHQ_core->prev_En_sb_fx, 0, NB_SWB_SUBBANDS ); @@ -1309,9 +1311,9 @@ void HQ_core_dec_init_fx( set16_fx( hHQ_core->env_stab_state_p_fx, INV_NUM_ENV_STAB_PLC_STATES, NUM_ENV_STAB_PLC_STATES ); hHQ_core->envstabplc_hocnt = 0; move16(); - set16_fx( hHQ_core->mag_chg_1st_fx, 32767, LGW_MAX ); + set16_fx( hHQ_core->mag_chg_1st_fx, 32767 /* 1.0f in Q15 */, LGW_MAX ); set16_fx( hHQ_core->Xavg_fx, 0, LGW_MAX ); - hHQ_core->beta_mute_fx = BETA_MUTE_FAC_INI; + hHQ_core->beta_mute_fx = BETA_MUTE_FAC_INI; /* Q15 */ hHQ_core->last_fec = 0; hHQ_core->ph_ecu_HqVoicing = 0; hHQ_core->oldHqVoicing = 0; @@ -1343,7 +1345,7 @@ void HQ_nbfec_init_fx( { Word16 i, j; - hHQ_nbfec->prev_last_core = -1; + hHQ_nbfec->prev_last_core = -1; /* Q0 */ hHQ_nbfec->diff_energy_fx = 0; hHQ_nbfec->stat_mode_out = 0; hHQ_nbfec->stat_mode_old = 0; diff --git a/lib_dec/hq_env_dec_fx.c b/lib_dec/hq_env_dec_fx.c index 81385aaaa..677221f31 100644 --- a/lib_dec/hq_env_dec_fx.c +++ b/lib_dec/hq_env_dec_fx.c @@ -14,15 +14,15 @@ * Decode envelope indices *------------------------------------------------------------------------*/ -Word16 decode_envelope_indices_fx( /* o : Number of bits */ +Word16 decode_envelope_indices_fx( /* o : Number of bits Q0*/ Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word16 start_norm, /* i : starting band index */ - const Word16 num_sfm, /* i : Number of subbands */ - const Word16 numnrmibits, /* i : Bitrate of fall-back coding mode */ - Word16 *difidx, /* o : Diff indices/encoded diff indices */ - const Word16 flag_HQ2 /* i : indicator of HQ2 core */ + const Word16 start_norm, /* i : starting band index Q0*/ + const Word16 num_sfm, /* i : Number of subbands Q0*/ + const Word16 numnrmibits, /* i : Bitrate of fall-back coding mode Q0*/ + Word16 *difidx, /* o : Diff indices/encoded diff indices Q0*/ + const Word16 flag_HQ2 /* i : indicator of HQ2 core Q0*/ , - const Word16 is_transient /* i : indicator of HQ_TRANSIENT */ + const Word16 is_transient /* i : indicator of HQ_TRANSIENT Q0*/ ) { Word16 hcode_l; @@ -34,14 +34,14 @@ Word16 decode_envelope_indices_fx( /* o : Number of b test(); IF( EQ_16( flag_HQ2, LOW_RATE_HQ_CORE ) || EQ_16( flag_HQ2, LOW_RATE_HQ_CORE_TRAN ) ) { - LCmode = (Word16) get_next_indice_fx( st_fx, BITS_DE_HMODE ); - difidx[start_norm] = (Word16) get_next_indice_fx( st_fx, BITS_DE_FCOMP ); + LCmode = (Word16) get_next_indice_fx( st_fx, BITS_DE_HMODE ); /* Q0 */ + difidx[start_norm] = (Word16) get_next_indice_fx( st_fx, BITS_DE_FCOMP ); /* Q0 */ move16(); } ELSE { - LCmode = (Word16) get_next_indice_fx( st_fx, 2 ); - difidx[start_norm] = (Word16) get_next_indice_fx( st_fx, NORM0_BITS ); + LCmode = (Word16) get_next_indice_fx( st_fx, 2 ); /* Q0 */ + difidx[start_norm] = (Word16) get_next_indice_fx( st_fx, NORM0_BITS ); /* Q0 */ move16(); } @@ -53,10 +53,10 @@ Word16 decode_envelope_indices_fx( /* o : Number of b IF( EQ_16( LCmode, 1 ) ) { hdecnrm_tran_fx( st_fx, num_sfm, &difidx[start_norm + 1] ); - j = add( start_norm, num_sfm ); + j = add( start_norm, num_sfm ); /* Q0 */ FOR( i = start_norm + 1; i < j; i++ ) { - hcode_l = add( hcode_l, huffsizn_tran[difidx[i]] ); + hcode_l = add( hcode_l, huffsizn_tran[difidx[i]] ); /* Q0 */ } } ELSE @@ -74,68 +74,68 @@ Word16 decode_envelope_indices_fx( /* o : Number of b } ELSE IF( EQ_16( LCmode, 1 ) ) { - startNormPlus1 = add( start_norm, 1 ); + startNormPlus1 = add( start_norm, 1 ); /* Q0 */ hdecnrm_resize_fx( st_fx, num_sfm, &difidx[startNormPlus1] ); - pDifidx = &difidx[startNormPlus1]; + pDifidx = &difidx[startNormPlus1]; /* Q0 */ move16(); - numSfmMinus1 = sub( num_sfm, 1 ); + numSfmMinus1 = sub( num_sfm, 1 ); /* Q0 */ FOR( i = 0; i < numSfmMinus1; i++ ) { j = *pDifidx++; move16(); - hcode_l = add( hcode_l, resize_huffsizn[j] ); + hcode_l = add( hcode_l, resize_huffsizn[j] ); /* Q0 */ } - pDifidx1 = &difidx[startNormPlus1]; + pDifidx1 = &difidx[startNormPlus1]; /* Q0 */ move16(); - numSfmMinus2 = sub( num_sfm, 2 ); + numSfmMinus2 = sub( num_sfm, 2 ); /* Q0 */ FOR( i = 0; i < numSfmMinus2; i++ ) { - pDifidx = pDifidx1++; + pDifidx = pDifidx1++; /* Q0 */ move16(); IF( GT_16( *pDifidx, 17 ) ) { - offset = sub( *pDifidx, 17 ); - offset = s_min( offset, 3 ); - *pDifidx1 = sub( *pDifidx1, offset ); + offset = sub( *pDifidx, 17 ); /* Q0 */ + offset = s_min( offset, 3 ); /* Q0 */ + *pDifidx1 = sub( *pDifidx1, offset ); /* Q0 */ move16(); } ELSE IF( LT_16( *pDifidx, 13 ) ) { - offset = sub( *pDifidx, 13 ); - offset = s_max( offset, -3 ); - *pDifidx1 = sub( *pDifidx1, offset ); + offset = sub( *pDifidx, 13 ); /* Q0 */ + offset = s_max( offset, -3 ); /* Q0 */ + *pDifidx1 = sub( *pDifidx1, offset ); /* Q0 */ move16(); } } } ELSE IF( EQ_16( LCmode, 2 ) ) { - startNormPlus1 = add( start_norm, 1 ); + startNormPlus1 = add( start_norm, 1 ); /* Q0 */ hdecnrm_fx( st_fx, num_sfm, &difidx[start_norm + 1] ); - pDifidx = &difidx[startNormPlus1]; + pDifidx = &difidx[startNormPlus1]; /* Q0 */ move16(); - numSfmMinus1 = sub( num_sfm, 1 ); + numSfmMinus1 = sub( num_sfm, 1 ); /* Q0 */ FOR( i = 0; i < numSfmMinus1; i++ ) { - j = *pDifidx++; + j = *pDifidx++; /* Q0 */ move16(); - hcode_l = add( hcode_l, huffsizn[j] ); + hcode_l = add( hcode_l, huffsizn[j] ); /* Q0 */ } } ELSE { - startNormPlus1 = add( start_norm, 1 ); - numSfmMinus1 = sub( num_sfm, 1 ); - pDifidx = &difidx[startNormPlus1]; + startNormPlus1 = add( start_norm, 1 ); /* Q0 */ + numSfmMinus1 = sub( num_sfm, 1 ); /* Q0 */ + pDifidx = &difidx[startNormPlus1]; /* Q0 */ FOR( i = 0; i < numSfmMinus1; i++ ) { - *pDifidx++ = (Word16) get_next_indice_fx( st_fx, NORMI_BITS ); + *pDifidx++ = (Word16) get_next_indice_fx( st_fx, NORMI_BITS ); /* Q0 */ move16(); } - hcode_l = numnrmibits; + hcode_l = numnrmibits; /* Q0 */ move16(); } } @@ -152,12 +152,12 @@ Word16 decode_envelope_indices_fx( /* o : Number of b *------------------------------------------------------------------------*/ void dequantize_norms_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word16 start_norm, /* i : First SDE encoded norm */ - const Word16 num_sfm, /* i : Number of norms */ - const Word16 is_transient, /* i : Transient flag */ - Word16 *ynrm, /* o : Decoded norm indices */ - Word16 *normqlg2 /* o : Log2 of decoded norms */ + Decoder_State *st_fx, /* i/o: decoder state structure */ + const Word16 start_norm, /* i : First SDE encoded norm Q0*/ + const Word16 num_sfm, /* i : Number of norms Q0*/ + const Word16 is_transient, /* i : Transient flag Q0*/ + Word16 *ynrm, /* o : Decoded norm indices Q0*/ + Word16 *normqlg2 /* o : Log2 of decoded norms Q0*/ ) { Word16 i, j; @@ -165,28 +165,28 @@ void dequantize_norms_fx( Word16 *pYnrm, *pNormqlg2; /* First sub-frame */ - i = ynrm[start_norm]; + i = ynrm[start_norm]; /* Q0 */ move16(); - normqlg2[start_norm] = dicnlg2[i]; + normqlg2[start_norm] = dicnlg2[i]; /* Q0 */ move16(); /* Other sub-frames */ IF( is_transient ) { /* Recover quantization indices and quantized norms */ - idxbuf[0] = ynrm[0]; + idxbuf[0] = ynrm[0]; /* Q0 */ move16(); FOR( i = 1; i < num_sfm; i++ ) { - idxbuf[i] = sub( add( ynrm[i], idxbuf[i - 1] ), 15 ); + idxbuf[i] = sub( add( ynrm[i], idxbuf[i - 1] ), 15 ); /* Q0 */ move16(); /* safety check in case of bit errors */ test(); IF( idxbuf[i] < 0 || GT_16( idxbuf[i], 39 ) ) { - idxbuf[i] = 39; + idxbuf[i] = 39; /* Q0 */ move16(); - st_fx->BER_detect = 1; + st_fx->BER_detect = 1; /* Q0 */ move16(); } } @@ -195,26 +195,26 @@ void dequantize_norms_fx( } ELSE { - pYnrm = &ynrm[start_norm]; + pYnrm = &ynrm[start_norm]; /* Q0 */ move16(); - pNormqlg2 = &normqlg2[start_norm + 1]; + pNormqlg2 = &normqlg2[start_norm + 1]; /* Q0 */ move16(); FOR( i = 1; i < num_sfm; i++ ) { - j = sub( *pYnrm++, 15 ); + j = sub( *pYnrm++, 15 ); /* Q0 */ move16(); - *pYnrm = add( *pYnrm, j ); + *pYnrm = add( *pYnrm, j ); /* Q0 */ move16(); /* safety check in case of bit errors */ test(); IF( *pYnrm < 0 || GT_16( *pYnrm, 39 ) ) { - *pYnrm = 39; + *pYnrm = 39; /* Q0 */ move16(); - st_fx->BER_detect = 1; + st_fx->BER_detect = 1; /* Q0 */ move16(); } - *pNormqlg2++ = dicnlg2[*pYnrm]; + *pNormqlg2++ = dicnlg2[*pYnrm]; /* Q0 */ move16(); } } diff --git a/lib_dec/hq_hr_dec_fx.c b/lib_dec/hq_hr_dec_fx.c index 93b94a5c8..556006121 100644 --- a/lib_dec/hq_hr_dec_fx.c +++ b/lib_dec/hq_hr_dec_fx.c @@ -18,10 +18,10 @@ #ifdef IVAS_FLOAT_FIXED void ivas_hq_pred_hb_bws_fx( Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word16 *ynrm, /* i : norm quantization index vector */ - const Word16 length, /* i : frame length */ - const Word16 hqswb_clas, /* i : HQ SWB class */ - const Word16 *SWB_fenv /* i : SWB frequency envelopes Q1 */ + const Word16 *ynrm, /* i : norm quantization index vector Q0*/ + const Word16 length, /* i : frame length Q0*/ + const Word16 hqswb_clas, /* i : HQ SWB class Q0*/ + const Word16 *SWB_fenv /* i : SWB frequency envelopes Q1*/ ) { Word16 i; @@ -41,7 +41,7 @@ void ivas_hq_pred_hb_bws_fx( { L_tmp = L_add( L_tmp, dicn_fx[ynrm[i]] ); /*Q14*/ } - L_tmp = L_min( 8191, L_shr( L_tmp, 13 ) ); + L_tmp = L_min( 8191, L_shr( L_tmp, 13 ) ); /* Q1 */ st_fx->prev_ener_shb_fx = extract_l( L_tmp ); /*Q1*/ st_fx->prev_ener_shb_fx = mult( st_fx->prev_ener_shb_fx, 5461 ); /*Q1*/ move16(); @@ -71,11 +71,11 @@ void ivas_hq_pred_hb_bws_fx( } void hq_pred_hb_bws_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word16 *ynrm, /* i : norm quantization index vector */ - const Word16 length, /* i : frame length */ - const Word16 hqswb_clas, /* i : HQ SWB class */ - const Word16 *SWB_fenv /* i : SWB frequency envelopes Q1 */ + Decoder_State *st_fx, /* i/o: decoder state structure */ + const Word16 *ynrm, /* i : norm quantization index vector Q0*/ + const Word16 length, /* i : frame length Q0*/ + const Word16 hqswb_clas, /* i : HQ SWB class Q0*/ + const Word16 *SWB_fenv /* i : SWB frequency envelopes Q1*/ ) { Word16 i; @@ -99,7 +99,7 @@ void hq_pred_hb_bws_fx( L_tmp = L_add( L_tmp, dicn_fx[ynrm[i]] ); /*Q14*/ #endif } - L_tmp = L_min( 8191, L_shr( L_tmp, 13 ) ); + L_tmp = L_min( 8191, L_shr( L_tmp, 13 ) ); /* Q1 */ st_fx->prev_ener_shb_fx = extract_l( L_tmp ); /*Q1*/ st_fx->prev_ener_shb_fx = mult( st_fx->prev_ener_shb_fx, 5461 ); /*Q1*/ move16(); @@ -153,7 +153,7 @@ void ivas_hq_hr_dec_fx( Word16 *is_transient, /* o : transient flag Q0 */ Word16 *hqswb_clas, /* o : HQ SWB class Q0 */ Word16 *SWB_fenv, /* o : SWB frequency envelopes Q1 */ - const Word16 core_switching_flag /* i : Core switching flag */ + const Word16 core_switching_flag /* i : Core switching flag Q0 */ ) { Word16 nb_sfm; @@ -211,8 +211,8 @@ void ivas_hq_hr_dec_fx( * Decode classification *------------------------------------------------------------------*/ - bits = ivas_hq_classifier_dec_fx( st_fx, st_fx->core_brate, length, is_transient, hqswb_clas ); - bits_left = sub( num_bits, bits ); + bits = ivas_hq_classifier_dec_fx( st_fx, st_fx->core_brate, length, is_transient, hqswb_clas ); /* Q0 */ + bits_left = sub( num_bits, bits ); /* Q0 */ /*------------------------------------------------------------------* * set quantization parameters @@ -231,15 +231,15 @@ void ivas_hq_hr_dec_fx( test(); IF( !*is_transient && NE_16( *hqswb_clas, HQ_HVQ ) && !( EQ_16( length, L_FRAME16k ) && LE_32( st_fx->core_brate, HQ_32k ) ) ) { - nf_idx = get_next_indice_fx( st_fx, 2 ); + nf_idx = get_next_indice_fx( st_fx, 2 ); /* Q0 */ } /*------------------------------------------------------------------* * Decode envelope *------------------------------------------------------------------*/ - hcode_l = decode_envelope_indices_fx( st_fx, start_norm, num_env_bands, numnrmibits, ynrm, NORMAL_HQ_CORE, *is_transient ); - bits_left = sub( bits_left, add( hcode_l, NORM0_BITS + FLAGS_BITS ) ); + hcode_l = decode_envelope_indices_fx( st_fx, start_norm, num_env_bands, numnrmibits, ynrm, NORMAL_HQ_CORE, *is_transient ); /* Q0 */ + bits_left = sub( bits_left, add( hcode_l, NORM0_BITS + FLAGS_BITS ) ); /* Q0 */ dequantize_norms_fx( st_fx, start_norm, num_env_bands, *is_transient, ynrm, normqlg2 ); @@ -249,7 +249,7 @@ void ivas_hq_hr_dec_fx( hq_generic_exc_clas = swb_bwe_gain_deq_fx( st_fx, HQ_CORE, NULL, SWB_fenv, st_fx->core_brate >= HQ_32k, *hqswb_clas ); /* Use (st->core_brate >= HQ_32k) to be consistent with hq_configure */ IF( EQ_16( hq_generic_exc_clas, HQ_GENERIC_SP_EXC ) ) { - bits_left = add( bits_left, 1 ); /* conditional 1 bit saving for representing HQ GENERIC excitation class */ + bits_left = add( bits_left, 1 ); /* conditional 1 bit saving for representing HQ GENERIC excitation class Q0*/ } map_hq_generic_fenv_norm_fx( *hqswb_clas, SWB_fenv, ynrm, normqlg2, num_env_bands, nb_sfm, hq_generic_offset ); } @@ -257,8 +257,8 @@ void ivas_hq_hr_dec_fx( env_stab = 0; move16(); - csw_flag1 = s_and( core_switching_flag, (Word16) NE_16( st_fx->element_mode, EVS_MONO ) ); - csw_flag2 = s_and( csw_flag1, (Word16) EQ_16( length, L_SPEC32k_EXT ) ); + csw_flag1 = s_and( core_switching_flag, (Word16) ( st_fx->element_mode != EVS_MONO ) ); /* Q0 */ + csw_flag2 = s_and( csw_flag1, (Word16) EQ_16( length, L_SPEC32k_EXT ) ); /* Q0 */ test(); IF( EQ_16( *hqswb_clas, HQ_HVQ ) ) { @@ -267,7 +267,7 @@ void ivas_hq_hr_dec_fx( } ELSE IF( EQ_16( length, L_FRAME32k ) || csw_flag2 ) { - env_stab = env_stability_fx( ynrm, SFM_N_ENV_STAB, hHQ_core->mem_norm, &hHQ_core->mem_env_delta, csw_flag1 ); + env_stab = env_stability_fx( ynrm, SFM_N_ENV_STAB, hHQ_core->mem_norm, &hHQ_core->mem_env_delta, csw_flag1 ); /* Q15 */ } ELSE { @@ -286,16 +286,16 @@ void ivas_hq_hr_dec_fx( { IF( EQ_16( length, L_FRAME32k ) || csw_flag2 ) { - move16(); /* calculated stability */ - hHQ_core->env_stab_fx = env_stab; + move16(); /* calculated stability */ + hHQ_core->env_stab_fx = env_stab; /* Q15 */ } ELSE { - hHQ_core->env_stab_fx = env_stability_fx( ynrm, SFM_N_ENV_STAB_WB, hHQ_core->mem_norm_hqfec, &hHQ_core->mem_env_delta_hqfec, csw_flag1 ); + hHQ_core->env_stab_fx = env_stability_fx( ynrm, SFM_N_ENV_STAB_WB, hHQ_core->mem_norm_hqfec, &hHQ_core->mem_env_delta_hqfec, csw_flag1 ); /* Q15 */ move16(); } } - hHQ_core->env_stab_plc_fx = env_stab_smo_fx( s_min( hHQ_core->env_stab_fx, sub( 32767, stab_trans_fx[L_STAB_TBL - 1] ) ), hHQ_core->env_stab_state_p_fx, &hHQ_core->envstabplc_hocnt ); + hHQ_core->env_stab_plc_fx = env_stab_smo_fx( s_min( hHQ_core->env_stab_fx, sub( 32767 /* 1.0f in Q15 */, stab_trans_fx[L_STAB_TBL - 1] ) ), hHQ_core->env_stab_state_p_fx, &hHQ_core->envstabplc_hocnt ); /* Q0 */ move16(); /*------------------------------------------------------------------* @@ -309,20 +309,20 @@ void ivas_hq_hr_dec_fx( test(); IF( EQ_16( *hqswb_clas, HQ_GEN_SWB ) && st_fx->bws_cnt1 > 0 && LT_32( st_fx->core_brate, HQ_32k ) ) { - tmp = i_mult( st_fx->bws_cnt1, 1638 ); + tmp = i_mult( st_fx->bws_cnt1, 1638 /* 1/20 in Q15 */ ); move16(); IF( EQ_16( st_fx->L_frame, L_FRAME16k ) ) { FOR( n_band = 0; n_band < 4; n_band++ ) { - SWB_fenv[n_band] = mult_r( SWB_fenv[n_band], tmp ); + SWB_fenv[n_band] = mult_r( SWB_fenv[n_band], tmp ); /* Q1 */ move16(); } } FOR( n_band = 4; n_band < SWB_FENV; n_band++ ) { - SWB_fenv[n_band] = mult_r( SWB_fenv[n_band], tmp ); + SWB_fenv[n_band] = mult_r( SWB_fenv[n_band], tmp ); /* Q1 */ move16(); } } @@ -330,8 +330,8 @@ void ivas_hq_hr_dec_fx( test(); IF( EQ_16( *hqswb_clas, HQ_GEN_SWB ) || EQ_16( *hqswb_clas, HQ_GEN_FB ) ) { - b_delta_env = get_nor_delta_hf_fx( st_fx, ynrm, Rsubband, num_env_bands, nb_sfm, core_sfm ); - sum = sub( sum, b_delta_env ); + b_delta_env = get_nor_delta_hf_fx( st_fx, ynrm, Rsubband, num_env_bands, nb_sfm, core_sfm ); /* Q0 */ + sum = sub( sum, b_delta_env ); /* Q0 */ } /*------------------------------------------------------------------* @@ -350,10 +350,10 @@ void ivas_hq_hr_dec_fx( test(); IF( EQ_16( *hqswb_clas, HQ_HVQ ) || EQ_16( *hqswb_clas, HQ_HARMONIC ) ) { - subband_search_offset = subband_search_offsets_13p2kbps_Har; - wBands[0] = SWB_SB_BW_LEN0_16KBPS_HAR; + subband_search_offset = subband_search_offsets_13p2kbps_Har; /* Q0 */ + wBands[0] = SWB_SB_BW_LEN0_16KBPS_HAR; /* Q0 */ move16(); - wBands[1] = SWB_SB_BW_LEN1_16KBPS_HAR; + wBands[1] = SWB_SB_BW_LEN1_16KBPS_HAR; /* Q0 */ move16(); IF( EQ_16( *hqswb_clas, HQ_HARMONIC ) ) @@ -407,7 +407,7 @@ void ivas_hq_hr_dec_fx( ivas_hq_pred_hb_bws_fx( st_fx, ynrm, length, *hqswb_clas, SWB_fenv ); /* update */ - hHQ_core->prev_hqswb_clas = *hqswb_clas; + hHQ_core->prev_hqswb_clas = *hqswb_clas; /* Q0 */ move16(); return; @@ -422,7 +422,7 @@ void hq_hr_dec_fx( Word16 *is_transient, /* o : transient flag Q0 */ Word16 *hqswb_clas, /* o : HQ SWB class Q0 */ Word16 *SWB_fenv, /* o : SWB frequency envelopes Q1 */ - const Word16 core_switching_flag /* i : Core switching flag */ + const Word16 core_switching_flag /* i : Core switching flag Q0 */ ) { Word16 nb_sfm; @@ -500,25 +500,25 @@ void hq_hr_dec_fx( test(); IF( !*is_transient && NE_16( *hqswb_clas, HQ_HVQ ) && !( EQ_16( length, L_FRAME16k ) && LE_32( st_fx->core_brate, HQ_32k ) ) ) { - nf_idx = get_next_indice( st_fx, 2 ); + nf_idx = get_next_indice( st_fx, 2 ); /* Q0 */ } /*------------------------------------------------------------------* * Decode envelope *------------------------------------------------------------------*/ - hcode_l = decode_envelope_indices_fx( st_fx, start_norm, num_env_bands, numnrmibits, ynrm, NORMAL_HQ_CORE, *is_transient ); - bits_left = sub( bits_left, add( hcode_l, NORM0_BITS + FLAGS_BITS ) ); + hcode_l = decode_envelope_indices_fx( st_fx, start_norm, num_env_bands, numnrmibits, ynrm, NORMAL_HQ_CORE, *is_transient ); /* Q0 */ + bits_left = sub( bits_left, add( hcode_l, NORM0_BITS + FLAGS_BITS ) ); /* Q0 */ dequantize_norms_fx( st_fx, start_norm, num_env_bands, *is_transient, ynrm, normqlg2 ); test(); IF( EQ_16( *hqswb_clas, HQ_GEN_SWB ) || EQ_16( *hqswb_clas, HQ_GEN_FB ) ) { - hq_generic_exc_clas = swb_bwe_gain_deq_fx( st_fx, HQ_CORE, NULL, SWB_fenv, st_fx->core_brate >= HQ_32k, *hqswb_clas ); /* Use (st->core_brate >= HQ_32k) to be consistent with hq_configure */ + hq_generic_exc_clas = swb_bwe_gain_deq_fx( st_fx, HQ_CORE, NULL, SWB_fenv, st_fx->core_brate >= HQ_32k, *hqswb_clas ); /* Use (st->core_brate >= HQ_32k) to be consistent with hq_configure Q0*/ if ( EQ_16( hq_generic_exc_clas, HQ_GENERIC_SP_EXC ) ) { - bits_left = add( bits_left, 1 ); /* conditional 1 bit saving for representing HQ GENERIC excitation class */ + bits_left = add( bits_left, 1 ); /* conditional 1 bit saving for representing HQ GENERIC excitation class Q0*/ } map_hq_generic_fenv_norm_fx( *hqswb_clas, SWB_fenv, ynrm, normqlg2, num_env_bands, nb_sfm, hq_generic_offset ); } @@ -526,8 +526,8 @@ void hq_hr_dec_fx( env_stab = 0; move16(); - csw_flag1 = s_and( core_switching_flag, (Word16) ( st_fx->element_mode != EVS_MONO ) ); - csw_flag2 = s_and( csw_flag1, (Word16) EQ_16( length, L_SPEC32k_EXT ) ); + csw_flag1 = s_and( core_switching_flag, (Word16) ( st_fx->element_mode != EVS_MONO ) ); /* Q0 */ + csw_flag2 = s_and( csw_flag1, (Word16) EQ_16( length, L_SPEC32k_EXT ) ); /* Q0 */ test(); IF( EQ_16( *hqswb_clas, HQ_HVQ ) ) { @@ -536,7 +536,7 @@ void hq_hr_dec_fx( } ELSE IF( EQ_16( length, L_FRAME32k ) || csw_flag2 ) { - env_stab = env_stability_fx( ynrm, SFM_N_ENV_STAB, hHQ_core->mem_norm, &hHQ_core->mem_env_delta, csw_flag1 ); + env_stab = env_stability_fx( ynrm, SFM_N_ENV_STAB, hHQ_core->mem_norm, &hHQ_core->mem_env_delta, csw_flag1 ); /* Q0 */ } ELSE { @@ -556,16 +556,16 @@ void hq_hr_dec_fx( test(); IF( EQ_16( length, L_FRAME32k ) || csw_flag2 ) { - move16(); /* calculated stability */ - hHQ_core->env_stab_fx = env_stab; + move16(); /* calculated stability */ + hHQ_core->env_stab_fx = env_stab; /* Q15 */ } ELSE { - hHQ_core->env_stab_fx = env_stability_fx( ynrm, SFM_N_ENV_STAB_WB, hHQ_core->mem_norm_hqfec, &hHQ_core->mem_env_delta_hqfec, csw_flag1 ); + hHQ_core->env_stab_fx = env_stability_fx( ynrm, SFM_N_ENV_STAB_WB, hHQ_core->mem_norm_hqfec, &hHQ_core->mem_env_delta_hqfec, csw_flag1 ); /* Q15 */ move16(); } } - hHQ_core->env_stab_plc_fx = env_stab_smo_fx( s_min( hHQ_core->env_stab_fx, sub( 32767, stab_trans_fx[L_STAB_TBL - 1] ) ), hHQ_core->env_stab_state_p_fx, &hHQ_core->envstabplc_hocnt ); + hHQ_core->env_stab_plc_fx = env_stab_smo_fx( s_min( hHQ_core->env_stab_fx, sub( 32767, stab_trans_fx[L_STAB_TBL - 1] ) ), hHQ_core->env_stab_state_p_fx, &hHQ_core->envstabplc_hocnt ); /* Q0 */ /*------------------------------------------------------------------* * Bit allocation @@ -578,20 +578,20 @@ void hq_hr_dec_fx( test(); IF( EQ_16( *hqswb_clas, HQ_GEN_SWB ) && st_fx->bws_cnt1 > 0 && LT_32( st_fx->core_brate, HQ_32k ) ) { - tmp = i_mult( st_fx->bws_cnt1, 1638 ); + tmp = i_mult( st_fx->bws_cnt1, 1638 /* 1/20 in Q15 */ ); /* Q15 */ move16(); IF( EQ_16( st_fx->L_frame, L_FRAME16k ) ) { FOR( n_band = 0; n_band < 4; n_band++ ) { - SWB_fenv[n_band] = mult_r( SWB_fenv[n_band], tmp ); + SWB_fenv[n_band] = mult_r( SWB_fenv[n_band], tmp ); /* Q1 */ move16(); } } FOR( n_band = 4; n_band < SWB_FENV; n_band++ ) { - SWB_fenv[n_band] = mult_r( SWB_fenv[n_band], tmp ); + SWB_fenv[n_band] = mult_r( SWB_fenv[n_band], tmp ); /* Q1 */ move16(); } } @@ -599,8 +599,8 @@ void hq_hr_dec_fx( test(); IF( EQ_16( *hqswb_clas, HQ_GEN_SWB ) || EQ_16( *hqswb_clas, HQ_GEN_FB ) ) { - b_delta_env = get_nor_delta_hf_fx( st_fx, ynrm, Rsubband, num_env_bands, nb_sfm, core_sfm ); - sum = sub( sum, b_delta_env ); + b_delta_env = get_nor_delta_hf_fx( st_fx, ynrm, Rsubband, num_env_bands, nb_sfm, core_sfm ); /* Q0 */ + sum = sub( sum, b_delta_env ); /* Q0 */ } /*------------------------------------------------------------------* @@ -619,10 +619,10 @@ void hq_hr_dec_fx( test(); IF( EQ_16( *hqswb_clas, HQ_HVQ ) || EQ_16( *hqswb_clas, HQ_HARMONIC ) ) { - subband_search_offset = subband_search_offsets_13p2kbps_Har; - wBands[0] = SWB_SB_BW_LEN0_16KBPS_HAR; + subband_search_offset = subband_search_offsets_13p2kbps_Har; /* Q0 */ + wBands[0] = SWB_SB_BW_LEN0_16KBPS_HAR; /* Q0 */ move16(); - wBands[1] = SWB_SB_BW_LEN1_16KBPS_HAR; + wBands[1] = SWB_SB_BW_LEN1_16KBPS_HAR; /* Q0 */ move16(); IF( EQ_16( *hqswb_clas, HQ_HARMONIC ) ) @@ -676,7 +676,7 @@ void hq_hr_dec_fx( hq_pred_hb_bws_fx( st_fx, ynrm, length, *hqswb_clas, SWB_fenv ); /* update */ - hHQ_core->prev_hqswb_clas = *hqswb_clas; + hHQ_core->prev_hqswb_clas = *hqswb_clas; /* Q0 */ move16(); return; diff --git a/lib_dec/swb_bwe_dec.c b/lib_dec/swb_bwe_dec.c index a1f18d2da..34bb10fc8 100644 --- a/lib_dec/swb_bwe_dec.c +++ b/lib_dec/swb_bwe_dec.c @@ -218,9 +218,9 @@ static int16_t para_pred_bws( #endif #ifdef IVAS_FLOAT_FIXED static Word16 para_pred_bws_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - Word16 *signal_wb_fx, /* i : wideband frequency signal */ - Word16 *SWB_fenv_fx, /* o : frequency-domain BWE envelope */ + Decoder_State *st_fx, /* i/o: decoder state structure */ + Word16 *signal_wb_fx, /* i : wideband frequency signal Q_syn */ + Word16 *SWB_fenv_fx, /* o : frequency-domain BWE envelope Q1 */ Word16 Q_syn ) { Word16 i, j, k; @@ -242,7 +242,7 @@ static Word16 para_pred_bws_fx( k = 0; move16(); - input_hi_fx = &signal_wb_fx[SHARP_WIDTH]; + input_hi_fx = &signal_wb_fx[SHARP_WIDTH]; /*Q_syn*/ FOR( i = 0; i < 7; i++ ) { peak_fx = 0; @@ -251,9 +251,9 @@ static Word16 para_pred_bws_fx( move16(); FOR( j = 0; j < SHARP_WIDTH; j++ ) { - mag_fx = abs_s( *input_hi_fx ); - peak_fx = s_max( peak_fx, mag_fx ); - mean_fx[i] = L_add( mean_fx[i], L_deposit_l( mag_fx ) ); + mag_fx = abs_s( *input_hi_fx ); /*Q_syn*/ + peak_fx = s_max( peak_fx, mag_fx ); /*Q_syn*/ + mean_fx[i] = L_add( mean_fx[i], L_deposit_l( mag_fx ) ); /*Q_syn*/ move32(); input_hi_fx++; } @@ -275,7 +275,7 @@ static Word16 para_pred_bws_fx( } IF( tmp > 0 ) { - L_tmp = L_msu0( Mult_32_16( L_shl( mean_fx[i], 10 ), 18432 ), peak_fx, 4544 ); + L_tmp = L_msu0( Mult_32_16( L_shl( mean_fx[i], 10 ) /*Q_syn + 10*/, 18432 /*4.5f Q12*/ ), peak_fx /*Q_syn*/, 4544 /*35.5 (SHARP_WIDTH + 3.5f)Q7*/ ); if ( L_tmp < 0 ) { k = add( k, 1 ); @@ -287,11 +287,11 @@ static Word16 para_pred_bws_fx( avrg2_fx = L_deposit_l( 0 ); FOR( i = 1; i < 4; i++ ) { - avrg1_fx = L_add( avrg1_fx, mean_fx[i] ); - avrg2_fx = L_add( avrg2_fx, mean_fx[i + 3] ); + avrg1_fx = L_add( avrg1_fx, mean_fx[i] ); /*Q_syn*/ + avrg2_fx = L_add( avrg2_fx, mean_fx[i + 3] ); /*Q_syn*/ } - avrg1_fx = Mult_32_16( avrg1_fx, 10923 ); - avrg2_fx = Mult_32_16( avrg2_fx, 10923 ); /* 1/3 -> Q15 -> 10923 */ + avrg1_fx = Mult_32_16( avrg1_fx, 10923 /* 1/3 -> Q15 -> 10923 */ ); /*Q_syn + Q15 - 15*/ + avrg2_fx = Mult_32_16( avrg2_fx, 10923 /* 1/3 -> Q15 -> 10923 */ ); /*Q_syn + Q15 - 15*/ min_fx = L_add( 2147483647, 0 ); /*2^31 */ peak_32_fx = L_deposit_l( 0 ); @@ -303,7 +303,7 @@ static Word16 para_pred_bws_fx( IF( LT_16( exp, 16 ) ) { tmp_den = extract_l( L_shr( mean_fx[i], sub( 16, exp ) ) ); /*Qsyn - 16 + exp */ - tmp_num = extract_l( L_shr( avrg2_fx, sub( 15, exp ) ) ); /*//Qsyn - 16 + exp */ + tmp_num = extract_l( L_shr( avrg2_fx, sub( 15, exp ) ) ); /*Qsyn - 16 + exp */ } ELSE { @@ -315,16 +315,16 @@ static Word16 para_pred_bws_fx( tmp = i_mult( tmp_num, tmp_den ); /*Q15 */ - mean_fx[i] = Mult_32_16( mean_fx[i], tmp ); + mean_fx[i] = Mult_32_16( mean_fx[i], tmp ); /*Q_syn + Q15 - 15*/ move32(); } min_fx = L_min( min_fx, mean_fx[i] ); peak_32_fx = L_max( peak_32_fx, mean_fx[i] ); } - IF( GT_16( st_fx->tilt_wb_fx, 16384 ) ) + IF( GT_16( st_fx->tilt_wb_fx, 16384 /*8 in Q11*/ ) ) { - IF( GT_16( st_fx->tilt_wb_fx, 30720 ) ) + IF( GT_16( st_fx->tilt_wb_fx, 30720 /*15.0f in Q11*/ ) ) { min_fx = peak_32_fx; move32(); @@ -410,21 +410,21 @@ static Word16 para_pred_bws_fx( FOR( i = 0; i < SWB_FENV; i++ ) { test(); - IF( NE_16( st_fx->prev_coder_type, coder_type ) && GT_16( mult_r( SWB_fenv_fx[i], 16384 ), st_fx->prev_SWB_fenv_fx[i] ) ) + IF( NE_16( st_fx->prev_coder_type, coder_type ) && GT_16( mult_r( SWB_fenv_fx[i], 16384 /*1/2.0f in Q15*/ ), st_fx->prev_SWB_fenv_fx[i] ) ) { - SWB_fenv_fx[i] = round_fx( L_mac( L_mult( SWB_fenv_fx[i], 3277 ), st_fx->prev_SWB_fenv_fx[i], 29491 ) ); + SWB_fenv_fx[i] = round_fx( L_mac( L_mult( SWB_fenv_fx[i], 3277 /*0.1f in Q15*/ ), st_fx->prev_SWB_fenv_fx[i], 29491 /*0.9f in Q15*/ ) ); move16(); } ELSE { - SWB_fenv_fx[i] = round_fx( L_mac( L_mult( SWB_fenv_fx[i], st_fx->attenu_fx ), st_fx->prev_SWB_fenv_fx[i], sub( 32767, st_fx->attenu_fx ) ) ); + SWB_fenv_fx[i] = round_fx( L_mac( L_mult( SWB_fenv_fx[i], st_fx->attenu_fx ), st_fx->prev_SWB_fenv_fx[i], sub( 32767 /*1.0f in Q15*/, st_fx->attenu_fx ) ) ); move16(); } } - IF( LT_16( st_fx->attenu_fx, 29491 ) ) + IF( LT_16( st_fx->attenu_fx, 29491 /*0.9f in Q15*/ ) ) { - st_fx->attenu_fx = add( st_fx->attenu_fx, 1638 ); + st_fx->attenu_fx = add( st_fx->attenu_fx, 1638 /*0.05f in Q15*/ ); move16(); } } @@ -439,7 +439,7 @@ static Word16 para_pred_bws_fx( { FOR( i = 0; i < SWB_FENV; i++ ) { - if ( GT_16( mult_r( SWB_fenv_fx[i], 16384 ), st_fx->prev_SWB_fenv_fx[i] ) ) + if ( GT_16( mult_r( SWB_fenv_fx[i], 16384 /*0.5f in Q15*/ ), st_fx->prev_SWB_fenv_fx[i] ) ) { SWB_fenv_fx[i] = st_fx->prev_SWB_fenv_fx[i]; move16(); @@ -449,10 +449,10 @@ static Word16 para_pred_bws_fx( FOR( i = 0; i < SWB_FENV; i++ ) { - SWB_fenv_fx[i] = round_fx( L_mac( L_mult( SWB_fenv_fx[i], 29491 ), st_fx->prev_SWB_fenv_fx[i], 3277 ) ); + SWB_fenv_fx[i] = round_fx( L_mac( L_mult( SWB_fenv_fx[i], 29491 /*0.9f in Q15*/ ), st_fx->prev_SWB_fenv_fx[i], 3277 /*0.1f in Q15*/ ) ); move16(); } - st_fx->attenu_fx = 3277; + st_fx->attenu_fx = 3277; /*Q15*/ move16(); } @@ -1031,12 +1031,12 @@ void swb_bwe_dec_flt( #ifdef IVAS_FLOAT_FIXED Word16 swb_bwe_dec_fx32( - Decoder_State *st_fx, /* i/o: decoder state structure */ - Word32 output_fx[], /* i : synthesis @internal Fs Q11 */ - Word32 *synth_fx, /* i : ACELP core synthesis/final synthesis Q11 */ - Word32 *hb_synth_fx, /* o : SHB synthesis/final synthesis */ - Word16 use_cldfb_for_dft, /* i : flag to use of CLDFB for DFT Stereo */ - Word16 output_frame /* i : frame length */ + Decoder_State *st_fx, /* i/o: decoder state structure */ + Word32 output_fx[], /* i : synthesis @internal Fs : Q11 */ + Word32 *synth_fx, /* i : ACELP core synthesis/final synthesis : Q11 */ + Word32 *hb_synth_fx, /* o : SHB synthesis/final synthesis : Q_syn_hb */ + Word16 use_cldfb_for_dft, /* i : flag to use of CLDFB for DFT Stereo */ + Word16 output_frame /* i : frame length */ ) { Word16 L; @@ -1285,7 +1285,7 @@ Word16 swb_bwe_dec_fx32( { FOR( i = 0; i < SWB_TENV; i++ ) { - SWB_tenv_tmp_fx[i] = L_mult0( SWB_tenv_fx[i], 26214 ); + SWB_tenv_tmp_fx[i] = L_mult0( SWB_tenv_fx[i] /*Q0*/, 26214 /*0.8f Q15*/ ); // Q15 move32(); } @@ -1351,7 +1351,7 @@ Word16 swb_bwe_dec_fx32( FOR( i = 0; i < output_frame; i++ ) { - hb_synth_fx[i] = L_deposit_l( hb_synth_fx16[i] ); + hb_synth_fx[i] = L_deposit_l( hb_synth_fx16[i] ); // Q_syn_hb move32(); } @@ -1400,7 +1400,7 @@ void fd_bwe_dec_init_fx( ) { set16_fx( hBWE_FD->L_old_wtda_swb_fx, 0, L_FRAME48k ); - set16_fx( hBWE_FD->old_syn_12k8_16k_fx, 0, NS2SA( 16000, DELAY_FD_BWE_ENC_NS ) ); + set16_fx( hBWE_FD->old_syn_12k8_16k_fx, 0, NS2SA_FX2( 16000, DELAY_FD_BWE_ENC_NS ) ); hBWE_FD->prev_mode = NORMAL; move16(); hBWE_FD->prev_Energy_fx = 0; @@ -1420,7 +1420,6 @@ void fd_bwe_dec_init_fx( move16(); hBWE_FD->prev_Energy_wb_fx = 0; move32(); - hBWE_FD->mem_deemph_old_syn_fx = 0; move16(); diff --git a/lib_dec/swb_bwe_dec_fx.c b/lib_dec/swb_bwe_dec_fx.c index 765458a90..6e9fd80dc 100644 --- a/lib_dec/swb_bwe_dec_fx.c +++ b/lib_dec/swb_bwe_dec_fx.c @@ -21,9 +21,9 @@ * predict SWB parameters for bandwidth switching *-------------------------------------------------------------------*/ static Word16 para_pred_bws_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - Word16 *signal_wb_fx, /* i : wideband frequency signal */ - Word16 *SWB_fenv_fx, /* o : frequency-domain BWE envelope */ + Decoder_State *st_fx, /* i/o: decoder state structure */ + Word16 *signal_wb_fx, /* i : wideband frequency signal Q_syn*/ + Word16 *SWB_fenv_fx, /* o : frequency-domain BWE envelope Q1 */ Word16 Q_syn ) { Word16 i, j, k; @@ -45,7 +45,7 @@ static Word16 para_pred_bws_fx( k = 0; move16(); - input_hi_fx = &signal_wb_fx[SHARP_WIDTH]; + input_hi_fx = &signal_wb_fx[SHARP_WIDTH]; /*Q_syn*/ FOR( i = 0; i < 7; i++ ) { peak_fx = 0; @@ -54,13 +54,13 @@ static Word16 para_pred_bws_fx( move16(); FOR( j = 0; j < SHARP_WIDTH; j++ ) { - mag_fx = abs_s( *input_hi_fx ); - peak_fx = s_max( peak_fx, mag_fx ); + mag_fx = abs_s( *input_hi_fx ); /*Q_syn*/ + peak_fx = s_max( peak_fx, mag_fx ); /*Q_syn*/ /*IF (sub(mag_fx, peak_fx) > 0) */ /*{ */ /* peak_fx = mag_fx; */ /*} */ - mean_fx[i] = L_add( mean_fx[i], L_deposit_l( mag_fx ) ); + mean_fx[i] = L_add( mean_fx[i], L_deposit_l( mag_fx ) ); /*Q_syn*/ move32(); input_hi_fx++; } @@ -82,7 +82,7 @@ static Word16 para_pred_bws_fx( } IF( tmp > 0 ) { - L_tmp = L_msu0( Mult_32_16( L_shl( mean_fx[i], 10 ), 18432 ), peak_fx, 4544 ); + L_tmp = L_msu0( Mult_32_16( L_shl( mean_fx[i], 10 ) /*Q_syn + 10*/, 18432 /*4.5f Q12*/ ), peak_fx /*Q_syn*/, 4544 /*35.5 (SHARP_WIDTH + 3.5f)Q7*/ ); if ( L_tmp < 0 ) { k = add( k, 1 ); @@ -94,11 +94,11 @@ static Word16 para_pred_bws_fx( avrg2_fx = L_deposit_l( 0 ); FOR( i = 1; i < 4; i++ ) { - avrg1_fx = L_add( avrg1_fx, mean_fx[i] ); - avrg2_fx = L_add( avrg2_fx, mean_fx[i + 3] ); + avrg1_fx = L_add( avrg1_fx, mean_fx[i] ); /*Q_syn*/ + avrg2_fx = L_add( avrg2_fx, mean_fx[i + 3] ); /*Q_syn*/ } - avrg1_fx = Mult_32_16( avrg1_fx, 10923 ); - avrg2_fx = Mult_32_16( avrg2_fx, 10923 ); /* 1/3 -> Q15 -> 10923 */ + avrg1_fx = Mult_32_16( avrg1_fx, 10923 /* 1/3 -> Q15 -> 10923 */ ); /*Q_syn + Q15 - 15*/ + avrg2_fx = Mult_32_16( avrg2_fx, 10923 /* 1/3 -> Q15 -> 10923 */ ); /*Q_syn + Q15 - 15*/ min_fx = L_add( 2147483647, 0 ); /*2^31 */ peak_32_fx = L_deposit_l( 0 ); @@ -122,11 +122,11 @@ static Word16 para_pred_bws_fx( tmp = i_mult( tmp_num, tmp_den ); /*Q15 */ - mean_fx[i] = Mult_32_16( mean_fx[i], tmp ); + mean_fx[i] = Mult_32_16( mean_fx[i], tmp ); // Q_syn + Q15 - 15 move32(); } min_fx = L_min( min_fx, mean_fx[i] ); - peak_32_fx = L_max( peak_32_fx, mean_fx[i] ); + peak_32_fx = L_max( peak_32_fx, mean_fx[i] ); /*Q_syn*/ /*IF(L_sub(mean_fx[i], min_fx) < 0) */ /*{ */ /* min_fx = mean_fx[i]; */ @@ -137,9 +137,9 @@ static Word16 para_pred_bws_fx( /*} */ } - IF( GT_16( st_fx->tilt_wb_fx, 16384 ) ) + IF( GT_16( st_fx->tilt_wb_fx, 16384 /*8 in Q11*/ ) ) { - IF( GT_16( st_fx->tilt_wb_fx, 30720 ) ) + IF( GT_16( st_fx->tilt_wb_fx, 30720 /*15.0f in Q11*/ ) ) { min_fx = peak_32_fx; move32(); @@ -147,7 +147,7 @@ static Word16 para_pred_bws_fx( ELSE { tmp = extract_l( L_shr( L_mult0( st_fx->tilt_wb_fx, 17476 ), 14 ) ); /*Q15 */ - min_fx = Mult_32_16( peak_32_fx, tmp ); + min_fx = Mult_32_16( peak_32_fx, tmp ); /*Q_syn + Q15 - 15*/ } } @@ -272,7 +272,7 @@ static Word16 para_pred_bws_fx( SWB_fenv_fx[i] = round_fx( L_mac( L_mult( SWB_fenv_fx[i], 29491 ), st_fx->prev_SWB_fenv_fx[i], 3277 ) ); move16(); } - st_fx->attenu_fx = 3277; + st_fx->attenu_fx = 3277; /*Q15*/ move16(); } @@ -309,7 +309,8 @@ static Word16 para_pred_bws_fx( *-------------------------------------------------------------------*/ Word16 WB_BWE_gain_deq_fx( Decoder_State *st_fx, /* i/o: decoder state structure */ - Word16 *WB_fenv ) + Word16 *WB_fenv /* o : Q15 */ +) { Word16 mode; Word16 index, index2; @@ -320,25 +321,25 @@ Word16 WB_BWE_gain_deq_fx( mode = add( extract_l( get_next_indice_fx( st_fx, 1 ) ), 2 ); index2 = shl( index, 1 ); - L_tmp = L_shr( F_2_5_fx[index2], 1 ); - L_tmp = L_shl( L_tmp, 6 ); + L_tmp = L_shr( F_2_5_fx[index2] /*Q10*/, 1 ); + L_tmp = L_shl( L_tmp, 6 ); /*Q15*/ frac = L_Extract_lc( L_tmp, &exp ); tmp = extract_l( Pow2( 14, frac ) ); exp = sub( exp, 14 ); - WB_fenv[0] = shl( tmp, add( exp, 3 ) ); + WB_fenv[0] = shl( tmp, add( exp, 3 ) ); // Q15 move16(); - L_tmp = L_shr( F_2_5_fx[index2 + 1], 1 ); - L_tmp = L_shl( L_tmp, 6 ); + L_tmp = L_shr( F_2_5_fx[index2 + 1] /*Q10*/, 1 ); + L_tmp = L_shl( L_tmp, 6 ); /*Q15*/ frac = L_Extract_lc( L_tmp, &exp ); tmp = extract_l( Pow2( 14, frac ) ); exp = sub( exp, 14 ); - WB_fenv[1] = shl( tmp, add( exp, 3 ) ); + WB_fenv[1] = shl( tmp, add( exp, 3 ) ); // Q15 move16(); return ( mode ); @@ -349,16 +350,16 @@ Word16 WB_BWE_gain_deq_fx( * * WB BWE decoder (only for 16kHz signals) *-------------------------------------------------------------------*/ -Word16 ivas_wb_bwe_dec_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word16 output[], /* i : suntehsis @ internal Fs */ - Word16 *synth_fx, /* i/o: ACELP core synthesis/final synthesis */ - Word16 *hb_synth_fx, /* o : SHB synthesis/final synthesis */ - const Word16 use_cldfb_for_dft, /* i : flag to use of CLDFB for DFT Stereo */ - const Word16 output_frame, /* i : frame length */ - Word16 *voice_factors_fx, /* i : voicing factors */ - const Word16 pitch_buf_fx[], /* i : pitch buffer */ - Word16 *Qpost ) +Word16 ivas_wb_bwe_dec_fx( /* o : Q_syn_hb */ + Decoder_State *st_fx, /* i/o: decoder state structure */ + const Word16 output[], /* i : suntehsis @ internal Fs Q_input */ + Word16 *synth_fx, /* i/o: ACELP core synthesis/final synthesis Q0/Qpost */ + Word16 *hb_synth_fx, /* o : SHB synthesis/final synthesis Q_syn_hb */ + const Word16 use_cldfb_for_dft, /* i : flag to use of CLDFB for DFT Stereo */ + const Word16 output_frame, /* i : frame length */ + Word16 *voice_factors_fx, /* i : voicing factors Q15 */ + const Word16 pitch_buf_fx[], /* i : pitch buffer Q6 */ + Word16 *Qpost ) { Word16 mode; Word16 WB_fenv_fx[SWB_FENV]; @@ -449,7 +450,7 @@ Word16 ivas_wb_bwe_dec_fx( { /* de-quantization */ mode = WB_BWE_gain_deq_fx( st_fx, WB_fenv_fx ); - st_fx->last_wb_bwe_ener_fx = extract_l( Mpy_32_16_r( L_add( WB_fenv_fx[0], WB_fenv_fx[1] ), 16384 ) ); + st_fx->last_wb_bwe_ener_fx = extract_l( Mpy_32_16_r( L_add( WB_fenv_fx[0], WB_fenv_fx[1] ), 16384 /*0.5f in Q15*/ ) ); move16(); } ELSE @@ -536,15 +537,15 @@ Word16 wb_bwe_dec_fx( #ifdef ADD_IVAS_BWE const Word16 output[], /* i : suntehsis @ internal Fs */ #endif - Word16 *synth_fx, /* i/o: ACELP core synthesis/final synthesis */ - Word16 *hb_synth_fx, /* o : SHB synthesis/final synthesis */ + Word16 *synth_fx, /* i/o: ACELP core synthesis/final synthesis Q0/Qpost */ + Word16 *hb_synth_fx, /* o : SHB synthesis/final synthesis Q_syn_hb */ #ifdef ADD_IVAS_BWE - const Word16 use_cldfb_for_dft, /* i : flag to use of CLDFB for DFT Stereo */ + const Word16 use_cldfb_for_dft, /* i : flag to use of CLDFB for DFT Stereo */ #endif - const Word16 output_frame, /* i : frame length */ - Word16 *voice_factors_fx, /* i : voicing factors */ - const Word16 pitch_buf_fx[], /* i : pitch buffer */ - Decoder_State *st_fx /* i/o: decoder state structure */ + const Word16 output_frame, /* i : frame length */ + Word16 *voice_factors_fx, /* i : voicing factors Q15 */ + const Word16 pitch_buf_fx[], /* i : pitch buffer Q6 */ + Decoder_State *st_fx /* i/o: decoder state structure */ , Word16 *Qpost ) { @@ -706,12 +707,12 @@ Word16 wb_bwe_dec_fx( * Decoding of SWB parameters *-------------------------------------------------------------------*/ Word16 swb_bwe_gain_deq_fx( /* o : BWE class */ - Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word16 core, /* i : core */ - Word16 *SWB_tenv, /* o : Q0, time-domain BWE envelope */ - Word16 *SWB_fenv, /* o : Q1, frequency-domain BWE envelope */ - const Word16 hr_flag, /* i : high rate flag */ - const Word16 hqswb_clas /* i : HQ BWE class */ + Decoder_State *st_fx, /* i/o: decoder state structure */ + const Word16 core, /* i : core : Q0 */ + Word16 *SWB_tenv, /* o : time-domain BWE envelope : Q0 */ + Word16 *SWB_fenv, /* o : frequency-domain BWE envelope : Q1 */ + const Word16 hr_flag, /* i : high rate flag : Q0 */ + const Word16 hqswb_clas /* i : HQ BWE class : Q0 */ ) { Word16 index, mode, n_band; @@ -759,7 +760,7 @@ Word16 swb_bwe_gain_deq_fx( /* o : BWE class FOR( n_band = 0; n_band < DIM_TR1; n_band++ ) { /*Env_TR_Cdbk1_fx[ indice[0]*DIM_TR1+n_band]*/ - quant_tmp[2 * n_band] = Env_TR_Cdbk1_fx[add( tmp, n_band )]; /*Q8 */ + quant_tmp[2 * n_band] = Env_TR_Cdbk1_fx[tmp + n_band]; /*Q8 */ move16(); } @@ -848,8 +849,8 @@ Word16 swb_bwe_gain_deq_fx( /* o : BWE class move16(); } - Copy( &EnvCdbk11_fx[i_mult2( indice[0], DIM11 )], quant_tmp, DIM11 ); - Copy( &EnvCdbk1st_fx[i_mult2( indice[1], DIM1ST )], quant_tmp2, DIM1ST ); + Copy( &EnvCdbk11_fx[indice[0] * DIM11], quant_tmp, DIM11 ); + Copy( &EnvCdbk1st_fx[indice[1] * DIM1ST], quant_tmp2, DIM1ST ); Copy( &EnvCdbk2nd_fx[indice[2] * DIM2ND], quant_tmp2 + DIM1ST, DIM2ND ); FOR( n_band = 0; n_band < ( DIM11 - 1 ); n_band++ ) @@ -867,13 +868,13 @@ Word16 swb_bwe_gain_deq_fx( /* o : BWE class SWB_fenv[11] = quant_tmp[6]; move16(); - Copy( &EnvCdbk3rd_fx[i_mult( indice[3], DIM3RD )], quant_tmp2, DIM3RD ); - Copy( &EnvCdbk3rd_fx[i_mult( indice[4], DIM3RD )], quant_tmp2 + DIM3RD, DIM3RD ); + Copy( &EnvCdbk3rd_fx[indice[3] * DIM3RD], quant_tmp2, DIM3RD ); + Copy( &EnvCdbk3rd_fx[indice[4] * DIM3RD], quant_tmp2 + DIM3RD, DIM3RD ); FOR( n_band = 0; n_band < 5; n_band++ ) { #ifdef BASOP_NOGLOB - SWB_fenv[add( n_band * 2, 1 )] = add_sat( shr( add_sat( quant_tmp[n_band], quant_tmp[n_band + 1] ), 1 ), quant_tmp2[n_band + 1] ); + SWB_fenv[n_band * 2 + 1] = add_sat( shr( add_sat( quant_tmp[n_band], quant_tmp[n_band + 1] ), 1 ), quant_tmp2[n_band + 1] ); #else SWB_fenv[add( shl( n_band, 1 ), 1 )] = add( shr( add( quant_tmp[n_band], quant_tmp[n_band + 1] ), 1 ), quant_tmp2[n_band + 1] ); #endif @@ -896,7 +897,7 @@ Word16 swb_bwe_gain_deq_fx( /* o : BWE class FOR( n_band = 0; n_band < DIM12 - 1; n_band++ ) { #ifdef BASOP_NOGLOB - SWB_fenv[add( n_band * 2, 1 )] = add_sat( shr( add_sat( quant_tmp[n_band], quant_tmp[n_band + 1] ), 1 ), quant_tmp2[n_band] ); + SWB_fenv[n_band * 2 + 1] = add_sat( shr( add_sat( quant_tmp[n_band], quant_tmp[n_band + 1] ), 1 ), quant_tmp2[n_band] ); #else SWB_fenv[add( shl( n_band, 1 ), 1 )] = add( shr( add( quant_tmp[n_band], quant_tmp[n_band + 1] ), 1 ), quant_tmp2[n_band] ); #endif @@ -929,11 +930,11 @@ Word16 swb_bwe_gain_deq_fx( /* o : BWE class IF( EQ_16( hqswb_clas, HQ_GEN_FB ) ) { - Copy( &EnvCdbkFB_fx[i_mult2( indice[5], DIM_FB )], &SWB_fenv[nenv], DIM_FB ); /*Q7 */ + Copy( &EnvCdbkFB_fx[indice[5] * DIM_FB], &SWB_fenv[nenv], DIM_FB ); /*Q7 */ FOR( n_band = 0; n_band < DIM_FB; n_band++ ) { - tmp = add( SWB_fenv[add( n_band, nenv )], Mean_env_fb_fx[n_band] ); + tmp = add( SWB_fenv[n_band + nenv], Mean_env_fb_fx[n_band] ); L_tmp = L_mult( tmp, 21771 ); /* 0.166096 in Q17 -> Q25 */ L_tmp = L_shr( L_tmp, 9 ); /* From Q25 to Q16 */ frac = L_Extract_lc( L_tmp, &exp ); /* Extract exponent of L_tmp */ @@ -942,7 +943,7 @@ Word16 swb_bwe_gain_deq_fx( /* o : BWE class /* output of Pow2() will be: */ /* 16384 < Pow2() <= 32767 */ exp = sub( exp, 13 ); - SWB_fenv[add( n_band, nenv )] = shl( tmp, add( exp, 1 ) ); + SWB_fenv[n_band + nenv] = shl( tmp, add( exp, 1 ) ); move16(); } } @@ -958,19 +959,19 @@ Word16 swb_bwe_gain_deq_fx( /* o : BWE class * * SWB BWE decoder *-------------------------------------------------------------------*/ -Word16 swb_bwe_dec_fx( +Word16 swb_bwe_dec_fx( /*o :Q_syn_hb*/ #ifdef ADD_IVAS_BWE - const Word16 output[], /* i : suntehsis @ internal Fs */ + const Word16 output[], /* i : suntehsis @ internal Fs */ #endif - Decoder_State *st_fx, /* i/o: decoder state structure */ - Word16 *synth_fx, /* i/o: ACELP core synthesis/final synthesis (might be rescaled inside wtda() ) */ - Word16 *hb_synth_fx, /* o : SHB synthesis/final synthesis */ + Decoder_State *st_fx, /* i/o: decoder state structure */ + Word16 *synth_fx, /* i/o: ACELP core synthesis/final synthesis (might be rescaled inside wtda() ) Q0/Qpost */ + Word16 *hb_synth_fx, /* o : SHB synthesis/final synthesis Q_syn_hb */ #ifdef ADD_IVAS_BWE - const Word16 use_cldfb_for_dft, /* i : flag to use of CLDFB for DFT Stereo */ + const Word16 use_cldfb_for_dft, /* i : flag to use of CLDFB for DFT Stereo */ #endif - const Word16 output_frame /* i : frame length */ - , - Word16 *Qpost ) + const Word16 output_frame /* i : frame length */ + , + Word16 *Qpost ) { Word16 i, l_subfr; Word16 mode; @@ -1280,7 +1281,7 @@ void fd_bwe_dec_init( { hBWE_FD->old_wtda_wb_fx_exp = 0; move16(); - set16_fx( hBWE_FD->old_syn_12k8_16k_fx, 0, NS2SA( 16000, DELAY_FD_BWE_ENC_NS ) ); + set16_fx( hBWE_FD->old_syn_12k8_16k_fx, 0, NS2SA_FX2( 16000, DELAY_FD_BWE_ENC_NS ) ); set16_fx( hBWE_FD->L_old_wtda_swb_fx, 0, L_FRAME48k ); hBWE_FD->old_wtda_swb_fx_exp = 0; move16(); diff --git a/lib_dec/swb_bwe_dec_hr_fx.c b/lib_dec/swb_bwe_dec_hr_fx.c index 51880fe61..8b238e46c 100644 --- a/lib_dec/swb_bwe_dec_hr_fx.c +++ b/lib_dec/swb_bwe_dec_hr_fx.c @@ -26,6 +26,7 @@ two functions would be less efficient (Performance Wise) since the function here doesn't use 'Log2_norm_lc' at all versus gain_dequant_fx() which does. */ +#ifdef IVAS_FLOAT_FIXED static Word16 Gain_Dequant_HR( /* o: decoded gain (Q13) */ Word16 index, /* i: quantization index */ const Word16 min, /* i: value of lower limit (Q13) */ @@ -40,9 +41,9 @@ static Word16 Gain_Dequant_HR( /* o: decoded gain (Q13) L_mini = 0; /* no complexity counted, just to remove warning */ L_fact = 0; /* no complexity counted, just to remove warning */ - move32(); move32(); + IF( EQ_16( min, G_AVQ_MIN_FX ) ) { L_mini = MAKE_PSEUDO_FLT( 26214, 15 ); /* 0.8 in Q15 */ @@ -83,7 +84,7 @@ static Word16 Gain_Dequant_HR( /* o: decoded gain (Q13) /* c_mult = (float) ((levels-1)/(log10(max)-c_min));*/ /* gain = (float)pow( 10.0, (((float)index)/c_mult) + c_min );*/ - L_temp = L_mult0( extract_h( L_fact ), inv_tbl_2n_minus1[bits] ); + L_temp = L_mult0( extract_h( L_fact ), inv_tbl_2n_minus1[bits] ); // Q12 + Qx exp1 = norm_s( index ); index = shl( index, exp1 ); /* inv_tbl has variable Q, with Q0 being at [2]*/ @@ -100,7 +101,7 @@ static Word16 Gain_Dequant_HR( /* o: decoded gain (Q13) exp1 = sub( 30 - 16 - 15, p2_int ); exp1 = add( exp1, extract_l( L_mini ) ); - gain = round_fx( L_temp ); + gain = round_fx( L_temp ); // exp1 L_temp = L_mult( gain, extract_h( L_mini ) ); exp2 = norm_l( L_temp ); @@ -109,7 +110,7 @@ static Word16 Gain_Dequant_HR( /* o: decoded gain (Q13) gain = round_fx( L_temp ); exp1 = add( exp1, exp2 ); - *exp = exp1; + *exp = exp1; // gain_e move16(); return gain; @@ -122,7 +123,7 @@ static Word16 Gain_Dequant_HR( /* o: decoded gain (Q13) *-------------------------------------------------------------------*/ static Word16 TD_Postprocess( /* o : gain in Q15 */ - Word16 hb_synth_fx[], /* i/o: high-band synthesis */ + Word16 hb_synth_fx[], /* i/o: high-band synthesis Q(15 - hb_synth_fx_exp) */ const Word16 hb_synth_fx_exp, /* i : Q of high-band synthesis */ const Word16 input_frame, /* i : frame length */ const Word16 last_extl /* i : last extension layer */ @@ -251,14 +252,14 @@ static Word16 TD_Postprocess( /* o : gain in Q15 * HR SWB BWE decoder *-------------------------------------------------------------------*/ -Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB synthesis */ - Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word16 *syn_12k8_16k_fx, /* i : ACELP core synthesis @16kHz */ - const Word16 exp, /* i : Exponent of core synthesis */ - Word16 *hb_synth_fx, /* o : SHB synthesis */ - const Word16 output_frame, /* i : frame length */ - const Word16 unbits, /* i : number of core unused bits */ - const Word16 pitch_buf[] /* i : pitch buffer */ +Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB synthesis */ + Decoder_State *st_fx, /* i/o: decoder state structure */ + const Word16 *syn_12k8_16k_fx, /* i : ACELP core synthesis @16kHz : Q(15 - exp) */ + const Word16 exp, /* i : Exponent of core synthesis */ + Word16 *hb_synth_fx, /* o : SHB synthesis : Q(15 - hb_synth_fx_exp)*/ + const Word16 output_frame, /* i : frame length */ + const Word16 unbits, /* i : number of core unused bits */ + const Word16 pitch_buf[] /* i : pitch buffer : Q6 */ ) { Word16 i, j, k, nBits, nBits_total, nBits_block, Nsv, Nsv2, width_noncoded; @@ -413,9 +414,9 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB temp4 = add( temp4, t_audio_exp ); FOR( i = 0; i < tmpS; i++ ) { - L_temp = L_mult( alpha, hBWE_FD_HR->t_audio_prev_fx[add( i, ind1 )] ); + L_temp = L_mult( alpha, hBWE_FD_HR->t_audio_prev_fx[i + ind1] ); L_temp = L_shr( L_temp, temp4 ); - t_audio32[add( pos, i )] = L_temp; + t_audio32[pos + i] = L_temp; move32(); } ind1 = add( ind1, tmpS ); @@ -590,17 +591,17 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB IF( EQ_16( ind1, 1 ) ) { - en_noncoded = round_fx( L_mult0( en_noncoded, BWE_HR_TRANS_EN_LIMIT1_FX_Q16 ) ); + en_noncoded = round_fx( L_mult0( en_noncoded, BWE_HR_TRANS_EN_LIMIT1_FX_Q16 ) ); // Q9 } IF( EQ_16( ind1, 2 ) ) { - en_noncoded = round_fx( L_mult0( en_noncoded, BWE_HR_TRANS_EN_LIMIT2_FX_Q16 ) ); + en_noncoded = round_fx( L_mult0( en_noncoded, BWE_HR_TRANS_EN_LIMIT2_FX_Q16 ) ); // Q9 } IF( EQ_16( ind1, 3 ) ) { - en_noncoded = round_fx( L_mult0( en_noncoded, BWE_HR_TRANS_EN_LIMIT3_FX_Q16 ) ); + en_noncoded = round_fx( L_mult0( en_noncoded, BWE_HR_TRANS_EN_LIMIT3_FX_Q16 ) ); // Q9 } } @@ -621,7 +622,7 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB move16(); FOR( i = 0; i < i_mult( Nsv, WIDTH_BAND ); i++ ) { - t_audio[add( temp, i )] = shl( x_norm[i], t_audio_exp ); + t_audio[temp + i] = shl( x_norm[i], t_audio_exp ); move16(); } @@ -656,7 +657,7 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB /* reconstruct 14-16(20) kHz spectrum */ FOR( j = 0; j < tmpS; j++ ) { - *ptr32++ = L_shr( t_audio32[add( pos, j )], 1 ); + *ptr32++ = L_shr( t_audio32[pos + j], 1 ); move32(); } @@ -678,8 +679,8 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB temp2 = add( NUM_TRANS_END_FREQ_COEF_EFF, temp ); j = sub( tmpS, width_noncoded ); - ptr16 = &t_audio[add( temp2, j )]; - ptr32 = &t_audio32[add( temp2, j )]; + ptr16 = &t_audio[temp2 + j]; + ptr32 = &t_audio32[temp2 + j]; /* envelope denormalization of 14.4-16(20) kHz spectrum */ FOR( ; j < tmpS; j++ ) { @@ -763,7 +764,7 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB FOR( i = 0; i < j; i++ ) { - t_audio[add( temp, i )] = mult_r( t_audio[add( temp, i )], temp2 ); + t_audio[temp + i] = mult_r( t_audio[temp + i], temp2 ); move16(); } } @@ -787,18 +788,18 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB ind2 = (Word16) get_next_indice_fx( st_fx, NBITS_ENVELOPE_BWE_HR2 ); temp = shl( ind1, 1 ); - en_band[0] = swb_hr_env_code1_fx[temp]; + en_band[0] = swb_hr_env_code1_fx[temp]; // Q9 move16(); - en_band[1] = swb_hr_env_code1_fx[temp + 1]; + en_band[1] = swb_hr_env_code1_fx[temp + 1]; // Q9 move16(); temp = shl( ind2, 1 ); - en_band[2] = swb_hr_env_code2_fx[temp]; + en_band[2] = swb_hr_env_code2_fx[temp]; // Q9 move16(); - en_band[3] = swb_hr_env_code2_fx[temp + 1]; + en_band[3] = swb_hr_env_code2_fx[temp + 1]; // Q9 move16(); /*env = add(add(shr(en_band[0], 2), shr(en_band[1], 2)), add(shr(en_band[2], 2), shr(en_band[3], 2)));*/ - env = mac_r( L_mac( L_mac( L_mult( en_band[0], 8192 ), en_band[1], 8192 ), en_band[2], 8192 ), en_band[3], 8192 ); + env = mac_r( L_mac( L_mac( L_mult( en_band[0] /*Q9*/, 8192 /*0.25 in Q15*/ ) /*Q23*/, en_band[1], 8192 ), en_band[2], 8192 ), en_band[3], 8192 ); // Q23 /*---------------------------------------------------------------------* * choose sub-bands to be dequantized @@ -846,19 +847,19 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB if ( EQ_16( ind1, 1 ) ) { /* en_noncoded = BWE_HR_NONTRANS_EN_LIMIT1*(0.5*min_env) ==> 0.25*min_env */ - en_noncoded = mult_r( min_env, BWE_HR_NONTRANS_EN_LIMIT2_FX_Q15 / 2 ); + en_noncoded = mult_r( min_env, BWE_HR_NONTRANS_EN_LIMIT2_FX_Q15 / 2 ); // Q9 } IF( EQ_16( ind1, 2 ) ) { /* en_noncoded = 2.0*BWE_HR_NONTRANS_EN_LIMIT2*(0.5*min_env) ==> 1.2*min_env */ - en_noncoded = round_fx( L_shl( L_mult( BWE_HR_NONTRANS_EN_LIMIT2_FX_Q14, min_env ), 1 ) ); + en_noncoded = round_fx( L_shl( L_mult( BWE_HR_NONTRANS_EN_LIMIT2_FX_Q14, min_env ), 1 ) ); // Q9 } if ( EQ_16( ind1, 3 ) ) { /* en_noncoded = 2.0*BWE_HR_NONTRANS_EN_LIMIT3*(0.5*min_env) ==> 0.8*min_env */ - en_noncoded = mult_r( BWE_HR_NONTRANS_EN_LIMIT3_FX_Q15, min_env ); + en_noncoded = mult_r( BWE_HR_NONTRANS_EN_LIMIT3_FX_Q15, min_env ); // Q9 } } @@ -954,7 +955,7 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB { L_temp = L_mult( gain2_fx, *ptr16++ ); L_temp = L_shr( L_temp, temp2 ); /* go to Q't_audio' */ - t_audio_tmp[add( temp, j )] = round_fx( L_temp ); + t_audio_tmp[temp + j] = round_fx( L_temp ); } /* 'nq[i] = add(nq[i], nq2[incr])' replaced by 'nq[i] = nq2[incr]' because 'nq[i] == 0' */ nq[i] = nq2[incr]; @@ -978,9 +979,9 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB FOR( j = 0; j < WIDTH_BAND; j++ ) { L_temp = L_mult( gain2_fx, *ptr16++ ); - L_temp = L_msu( L_temp, t_audio_tmp[add( temp, j )], temp3 ); /* go to -Q't_audio' */ - L_temp = L_shr( L_temp, temp2 ); /* go to Q't_audio' */ - t_audio_tmp[add( temp, j )] = round_fx( L_temp ); + L_temp = L_msu( L_temp, t_audio_tmp[temp + j], temp3 ); /* go to -Q't_audio' */ + L_temp = L_shr( L_temp, temp2 ); /* go to Q't_audio' */ + t_audio_tmp[temp + j] = round_fx( L_temp ); } nq[i] = add( nq[i], nq2[incr] ); move16(); @@ -1043,7 +1044,7 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB { nq[j] = nq[i]; move16(); - j = j - 1; + j = sub( j, 1 ); } Copy( nq + ind2, nq + ind1, add( WIDTH_BAND, pos ) ); @@ -1271,7 +1272,8 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB /* Apply global gain */ if ( LE_16( nBits_total, NBITS_THRESH_BWE_HR ) ) { - gain_fx = mult_r( 27853, gain_fx ); /* 0.85 */ + gain_fx = mult_r( 27853, gain_fx ); /* 0.85 in exp_0 */ + // gain_e } ptr32 = &t_audio32[NUM_NONTRANS_START_FREQ_COEF]; @@ -1336,12 +1338,12 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB } ELSE { - st_fx->prev_ener_shb_fx = extract_h( L_shr( L_mult0( gain_fx, env ), 7 ) ); + st_fx->prev_ener_shb_fx = extract_h( L_shr( L_mult0( gain_fx, env ) /*gain_e + (31 - Q23)*/, 7 ) ); /*gain_e + 15*/ move16(); } FOR( i = 0; i < SWB_FENV; i++ ) { - st_fx->prev_SWB_fenv_fx[i] = st_fx->prev_ener_shb_fx; + st_fx->prev_SWB_fenv_fx[i] = st_fx->prev_ener_shb_fx; /*gain_e + 15*/ move16(); } @@ -1512,7 +1514,7 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB } } - hBWE_FD_HR->L_mem_EnergyLT_fx = L_EnergyLT; + hBWE_FD_HR->L_mem_EnergyLT_fx = L_EnergyLT; // exp_temp4 move32(); hBWE_FD_HR->mem_EnergyLT_fx_exp = temp4; move16(); @@ -1558,7 +1560,6 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB * * Initialize HR BWE state structure at the decoder *-------------------------------------------------------------------*/ -#ifdef IVAS_FLOAT_FIXED void hr_bwe_dec_init( HR_BWE_DEC_HANDLE hBWE_FD_HR /* i/o: HR BWE data handle */ ) @@ -1567,32 +1568,14 @@ void hr_bwe_dec_init( set16_fx( hBWE_FD_HR->t_audio_prev_fx_exp, 0, NUM_TIME_SWITCHING_BLOCKS ); /* one exp per switching block */ hBWE_FD_HR->old_is_transient_hr_bwe_fx = 0; move16(); - hBWE_FD_HR->bwe_highrate_seed_fx = 12345; + hBWE_FD_HR->bwe_highrate_seed_fx = 12345; /*0.75f in Q14*/ move16(); - hBWE_FD_HR->L_mem_EnergyLT_fx = L_deposit_h( 16384 ); + hBWE_FD_HR->L_mem_EnergyLT_fx = L_deposit_h( 16384 ); /*1.0f in Q30*/ move32(); hBWE_FD_HR->mem_EnergyLT_fx_exp = 40; move16(); /* set to a high exponent */ return; } -#else -void hr_bwe_dec_init( - HR_BWE_DEC_HANDLE hBWE_FD_HR /* i/o: HR BWE data handle */ -) -{ - set16_fx( hBWE_FD_HR->t_audio_prev_fx, 0, 2 * END_FREQ_BWE_FULL_FB / 50 - NUM_NONTRANS_START_FREQ_COEF ); - set16_fx( hBWE_FD_HR->t_audio_prev_fx_exp, 0, NUM_TIME_SWITCHING_BLOCKS ); /* one exp per switching block */ - hBWE_FD_HR->old_is_transient_hr_bwe_fx = 0; - move16(); - hBWE_FD_HR->bwe_highrate_seed_fx = 12345; - move16(); - - hBWE_FD_HR->L_mem_EnergyLT_fx = L_deposit_h( 16384 ); - hBWE_FD_HR->mem_EnergyLT_fx_exp = 40; - move16(); /* set to a high exponent */ - - return; -} #endif diff --git a/lib_dec/swb_bwe_dec_lr_fx.c b/lib_dec/swb_bwe_dec_lr_fx.c index f2aa60a59..b9bb17621 100644 --- a/lib_dec/swb_bwe_dec_lr_fx.c +++ b/lib_dec/swb_bwe_dec_lr_fx.c @@ -15,12 +15,12 @@ *-------------------------------------------------------------------*/ static void DecodeSWBGenericParameters_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - Word16 *lagIndices_fx, /* o : lowband index for each subband */ - const Word16 nBands_search_fx, /* i : number of subbnads for SSearch */ - const Word16 BANDS_fx, /* i : total number of subbands per frame */ - const Word16 *p2a_flags_fx, /* i : HF tonal flag */ - const Word16 hq_swb_clas_fx /* i : mode of operation HQ_NORMAL or HQ_HARMONIC */ + Decoder_State *st_fx, /* i/o: decoder state structure */ + Word16 *lagIndices_fx, /* o : lowband index for each subband :Q0 */ + const Word16 nBands_search_fx, /* i : number of subbnads for SSearch :Q0 */ + const Word16 BANDS_fx, /* i : total number of subbands per frame :Q0 */ + const Word16 *p2a_flags_fx, /* i : HF tonal flag :Q0 */ + const Word16 hq_swb_clas_fx /* i : mode of operation HQ_NORMAL or HQ_HARMONIC :Q0 */ ) { Word16 sb; @@ -35,16 +35,15 @@ static void DecodeSWBGenericParameters_fx( } ELSE { - IF( p2a_flags_fx[add( sub( BANDS_fx, NB_SWB_SUBBANDS ), sb )] == 0 ) + IF( p2a_flags_fx[BANDS_fx - NB_SWB_SUBBANDS + sb] == 0 ) { lagIndices_fx[sb] = (Word16) get_next_indice_fx( st_fx, bits_lagIndices_modeNormal[sb] ); - move16(); } ELSE { lagIndices_fx[sb] = 0; - move16(); } + move16(); } } @@ -61,32 +60,32 @@ static void DecodeSWBGenericParameters_fx( *-------------------------------------------------------------------*/ static void DecodeSWBSubbands_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - HQ_DEC_HANDLE hHQ_core, /* i/o: HQ decoder handle */ - Word32 *L_spectra, /* i/o: MDCT domain spectrum */ - Word16 QsL, /* i : Q value of spectra */ - const Word16 fLenLow_fx, /* i : lowband length */ - const Word16 fLenHigh_fx, /* i : highband length */ - const Word16 nBands_fx, /* i : number of subbands */ - const Word16 *sbWidth_fx, /* i : subband lengths */ - const Word16 *subband_offsets_fx, /* i : subband offsets */ - Word16 *lagIndices_fx, /* i : lowband index for each subband */ - Word16 *lagGains_fx, /* i : first gain for each subband */ - Word16 *QlagGains, /* i : Q value of lagGains */ - Word16 BANDS_fx, /* i : number subbands per frame */ - Word16 *band_start_fx, /* i : band start of each SB */ - Word16 *band_end_fx, /* i : band end of each SB */ - Word32 *L_band_energy, /* i : band energy of each SB */ - Word16 Qbe, /* i : Q value of band energy */ - Word16 *p2a_flags_fx, /* i : HF tonal indicator */ - const Word16 hqswb_clas_fx, /* i : class information */ - const Word16 har_bands_fx, /* i : number of LF harmonic bands */ - const Word16 *subband_search_offset_fx, /* i : Number of harmonic LF bands */ - Word16 *prev_frm_hfe2, /* i/o: */ - Word16 *prev_stab_hfe2, /* i/o: */ - Word16 band_width_fx[], /* i : subband band widths */ - const Word32 L_spectra_ni[], /* i/o: core coder with sparseness filled */ - Word16 *ni_seed_fx /* i/o: random seed for search buffer NI */ + Decoder_State *st_fx, /* i/o: decoder state structure */ + HQ_DEC_HANDLE hHQ_core, /* i/o: HQ decoder handle */ + Word32 *L_spectra, /* i/o: MDCT domain spectrum : QsL */ + Word16 QsL, /* i : Q value of spectra */ + const Word16 fLenLow_fx, /* i : lowband length : Q0 */ + const Word16 fLenHigh_fx, /* i : highband length : Q0 */ + const Word16 nBands_fx, /* i : number of subbands : Q0 */ + const Word16 *sbWidth_fx, /* i : subband lengths : Q0 */ + const Word16 *subband_offsets_fx, /* i : subband offsets : Q0 */ + Word16 *lagIndices_fx, /* i : lowband index for each subband : Q0 */ + Word16 *lagGains_fx, /* i : first gain for each subband QlagGains*/ + Word16 *QlagGains, /* i : Q value of lagGains */ + Word16 BANDS_fx, /* i : number subbands per frame : Q0 */ + Word16 *band_start_fx, /* i : band start of each SB : Q0 */ + Word16 *band_end_fx, /* i : band end of each SB : Q0 */ + Word32 *L_band_energy, /* i : band energy of each SB : Q0 */ + Word16 Qbe, /* i : Q value of band energy */ + Word16 *p2a_flags_fx, /* i : HF tonal indicator : Q0 */ + const Word16 hqswb_clas_fx, /* i : class information : Q0 */ + const Word16 har_bands_fx, /* i : number of LF harmonic bands : Q0 */ + const Word16 *subband_search_offset_fx, /* i : Number of harmonic LF bands : Q0 */ + Word16 *prev_frm_hfe2, /* i/o: : Q0 */ + Word16 *prev_stab_hfe2, /* i/o: : Q0 */ + Word16 band_width_fx[], /* i : subband band widths : Q0 */ + const Word32 L_spectra_ni[], /* i/o: core coder with sparseness filled : QsL */ + Word16 *ni_seed_fx /* i/o: random seed for search buffer NI : Q0 */ ) { Word16 i, k; @@ -179,7 +178,7 @@ static void DecodeSWBSubbands_fx( { FOR( i = band_start_fx[k]; i <= band_end_fx[k]; i++ ) { - L_spectra[i] = L_xSynth_har[sub( i, fLenLow_fx )]; + L_spectra[i] = L_xSynth_har[i - fLenLow_fx]; move32(); /* QsL */ } } @@ -192,7 +191,7 @@ static void DecodeSWBSubbands_fx( convert_lagIndices_pls2smp_fx( lagIndices_fx, nBands_fx, lagIndices_real_fx, sspectra_fx, sbWidth_fx, fLenLow_fx ); FOR( k = 0; k < nBands_fx; k++ ) { - if ( EQ_16( p2a_flags_fx[add( BANDS_fx - NB_SWB_SUBBANDS, k )], 1 ) ) + if ( EQ_16( p2a_flags_fx[BANDS_fx - NB_SWB_SUBBANDS + k], 1 ) ) { lagIndices_real_fx[k] = 0; move16(); @@ -200,12 +199,12 @@ static void DecodeSWBSubbands_fx( } GetlagGains_fx( sspectra_ni_fx, Qss, - &L_band_energy[sub( BANDS_fx, NB_SWB_SUBBANDS )], Qbe, + &L_band_energy[BANDS_fx - NB_SWB_SUBBANDS], Qbe, nBands_fx, sbWidth_fx, lagIndices_real_fx, fLenLow_fx, lagGains_fx, QlagGains ); FOR( k = 0; k < nBands_fx; k++ ) { - IF( EQ_16( p2a_flags_fx[add( BANDS_fx - NB_SWB_SUBBANDS, k )], 1 ) ) + IF( EQ_16( p2a_flags_fx[BANDS_fx - NB_SWB_SUBBANDS + k], 1 ) ) { lagGains_fx[k] = 0; move16(); @@ -214,7 +213,7 @@ static void DecodeSWBSubbands_fx( } ELSE { - lagGains_fx[k] = mult_r( lagGains_fx[k], 29491 ); /* lagGains[k]*0.9f; */ + lagGains_fx[k] = mult_r( lagGains_fx[k], 29491 /*0.9f in Q15*/ ); /* lagGains[k]*0.9f; */ move16(); } } @@ -223,7 +222,7 @@ static void DecodeSWBSubbands_fx( { L_th_g[k] = 0; move32(); - IF( p2a_flags_fx[add( BANDS_fx - NB_SWB_SUBBANDS, k )] == 0 ) + IF( p2a_flags_fx[BANDS_fx - NB_SWB_SUBBANDS + k] == 0 ) { L_th_g[k] = L_shl( L_mult( lagGains_fx[k], ss_min_fx ), sub( QsL, add( add( QlagGains[k], Qss ), 1 ) ) ); /* QlagGain+Qss -> Qs */ move32(); @@ -244,7 +243,7 @@ static void DecodeSWBSubbands_fx( { FOR( i = band_start_fx[k]; i <= band_end_fx[k]; i++ ) { - L_spectra[i] = L_xSynth_har[sub( i, fLenLow_fx )]; + L_spectra[i] = L_xSynth_har[i - fLenLow_fx]; move32(); /* QsL */ } } @@ -252,7 +251,7 @@ static void DecodeSWBSubbands_fx( { FOR( i = band_start_fx[k]; i <= band_end_fx[k]; i++ ) { - L_spectra[i] = L_spectra_ni[i]; + L_spectra[i] = L_spectra_ni[i]; /* QsL */ move32(); } } @@ -268,26 +267,26 @@ static void DecodeSWBSubbands_fx( * Main decoding routine of SWB BWE for the LR MDCT core *-------------------------------------------------------------------*/ void swb_bwe_dec_lr_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word32 L_m_core[], /* i : lowband synthesis */ - const Word16 QsL, /* i : Q value of m_core */ - Word32 L_m[], /* o : highband synthesis with lowband zeroed */ - const Word32 L_total_brate, /* i : total bitrate for selecting subband pattern */ - Word16 BANDS_fx, /* i : Number subbands/Frame */ - Word16 *band_start_fx, /* i : Band Start of each SB */ - Word16 *band_end_fx, /* i : Band end of each SB */ - Word32 *L_band_energy, /* i : Band energy of each SB : Qbe */ - Word16 Qbe, /* i : Q value of band energy */ - Word16 *p2a_flags_fx, /* i : HF tonal Indicator */ - const Word16 hqswb_clas_fx, /* i : class information */ - Word16 lowlength_fx, /* i : Lowband Length */ - Word16 highlength_fx, /* i : Highband Length */ - const Word16 har_bands_fx, /* i : Number of LF harmonic bands */ - Word16 *prev_frm_hfe2, /* i/o: */ - Word16 *prev_stab_hfe2, /* i/o: */ - Word16 band_width_fx[], /* i : subband bandwidth */ - const Word32 L_y2_ni[], /* i/o: Sparse filled corecoder */ - Word16 *ni_seed_fx /* i/o: random seed */ + Decoder_State *st_fx, /* i/o: decoder state structure */ + const Word32 L_m_core[], /* i : lowband synthesis : QsL */ + const Word16 QsL, /* i : Q value of m_core */ + Word32 L_m[], /* o : highband synthesis with lowband zeroed : QsL */ + const Word32 L_total_brate, /* i : total bitrate for selecting subband pattern */ + Word16 BANDS_fx, /* i : Number subbands/Frame : Q0 */ + Word16 *band_start_fx, /* i : Band Start of each SB : Q0 */ + Word16 *band_end_fx, /* i : Band end of each SB :Q0 */ + Word32 *L_band_energy, /* i : Band energy of each SB : Qbe */ + Word16 Qbe, /* i : Q value of band energy */ + Word16 *p2a_flags_fx, /* i : HF tonal Indicator : Q0 */ + const Word16 hqswb_clas_fx, /* i : class information : Q0 */ + Word16 lowlength_fx, /* i : Lowband Length : Q0 */ + Word16 highlength_fx, /* i : Highband Length : Q0 */ + const Word16 har_bands_fx, /* i : Number of LF harmonic bands : Q0 */ + Word16 *prev_frm_hfe2, /* i/o: : Q0 */ + Word16 *prev_stab_hfe2, /* i/o: : Q0 */ + Word16 band_width_fx[], /* i : subband bandwidth : Q0 */ + const Word32 L_y2_ni[], /* i/o: Sparse filled corecoder */ + Word16 *ni_seed_fx /* i/o: random seed : QsL */ ) { Word16 k; diff --git a/lib_dec/swb_tbe_dec.c b/lib_dec/swb_tbe_dec.c index c5c1bed29..3c788e784 100644 --- a/lib_dec/swb_tbe_dec.c +++ b/lib_dec/swb_tbe_dec.c @@ -466,10 +466,10 @@ void wb_tbe_dec( } #else static void calc_tilt_bwe_fx_loc( - const Word32 *sp_fx, /* i : input signal */ - Word32 *tilt_fx, /* o : signal tilt */ - Word16 *tilt_fx_q, /* o : signal tilt */ - const Word16 N /* i : signal length */ + const Word32 *sp_fx, /* i : input signal : Q11 */ + Word32 *tilt_fx, /* o : signal tilt : tilt_fx_q */ + Word16 *tilt_fx_q, /* o : signal tilt */ + const Word16 N /* i : signal length : Q0 */ ) { Word16 i; @@ -479,14 +479,14 @@ static void calc_tilt_bwe_fx_loc( move64(); FOR( i = 0; i < N; i++ ) { - r0_fx = W_add( r0_fx, W_shr( W_mult_32_32( sp_fx[i], sp_fx[i] ), 1 ) ); + r0_fx = W_add( r0_fx, W_shr( W_mult_32_32( sp_fx[i], sp_fx[i] ), 1 ) ); /*Q11*2 - 1*/ } - r1_fx = W_deposit32_l( abs( L_sub( sp_fx[1], sp_fx[0] ) ) ); + r1_fx = W_deposit32_l( abs( L_sub( sp_fx[1], sp_fx[0] ) ) ); /*Q11*/ FOR( i = 2; i < N; i++ ) { - IF( W_mult_32_32( L_sub( sp_fx[i], sp_fx[i - 1] ), L_sub( sp_fx[i - 1], sp_fx[i - 2] ) ) < 0 ) + IF( W_mult_32_32( L_sub( sp_fx[i], sp_fx[i - 1] ) /*Q11*/, L_sub( sp_fx[i - 1], sp_fx[i - 2] ) /*Q11*/ ) /*Q11 * 2 - 1*/ < 0 ) { - r1_fx = W_add( r1_fx, W_deposit32_l( abs( L_sub( sp_fx[i], sp_fx[i - 1] ) ) ) ); + r1_fx = W_add( r1_fx, W_deposit32_l( abs( L_sub( sp_fx[i], sp_fx[i - 1] ) ) ) ); /*Q11*/ } } Word16 headroom_left_r0 = W_norm( r0_fx ); @@ -494,7 +494,6 @@ static void calc_tilt_bwe_fx_loc( Word16 r0_q = 0, r1_q = 0; move16(); move16(); - // Word16 r0_bits_occ = 0, r1_bits_occ = 0; IF( LT_16( headroom_left_r0, 32 ) ) { r0_fx = W_shr( r0_fx, sub( 32, headroom_left_r0 ) ); @@ -553,7 +552,8 @@ static void calc_tilt_bwe_fx_loc( *-------------------------------------------------------------------*/ static void rescale_genSHB_mem_dec( Decoder_State *st_fx, - Word16 sf ) + Word16 sf /*Q0*/ +) { Word16 i; TD_BWE_DEC_HANDLE hBWE_TD; @@ -598,8 +598,8 @@ static void rescale_genSHB_mem_dec( static void gradientGainShape( Decoder_State *st_fx, - Word16 *GainShape_fx, - Word32 *GainFrame_fx ) + Word16 *GainShape_fx, /*Q15*/ + Word32 *GainFrame_fx /* Q18 */ ) { Word16 i, j, tmp; Word16 GainShapeTemp[NUM_SHB_SUBFR / 4]; @@ -617,7 +617,7 @@ static void gradientGainShape( move16(); /* Q14 */ GainGrad1[j] = sub( shr( st_fx->GainShape_Delay[j + 5], 1 ), shr( st_fx->GainShape_Delay[j + 4], 1 ) ); move16(); /* Q14 */ - GainGradFEC[j + 1] = add( mult_r( GainGrad0[j], 13107 ), mult_r( GainGrad1[j], 19660 ) ); + GainGradFEC[j + 1] = add( mult_r( GainGrad0[j], 13107 /*0.4f in Q15*/ ), mult_r( GainGrad1[j], 19660 /*0.6f in Q15*/ ) ); move16(); /* Q14 */ } @@ -628,14 +628,14 @@ static void gradientGainShape( IF( ( ( GT_16( shr( GainGrad1[2], 1 ), GainGrad1[1] ) ) && ( GT_16( shr( GainGrad1[1], 1 ), GainGrad1[0] ) ) ) || ( ( LT_16( shr( GainGrad1[2], 1 ), GainGrad1[1] ) ) && ( LT_16( shr( GainGrad1[1], 1 ), GainGrad1[0] ) ) ) ) { - GainGradFEC[0] = add( mult_r( GainGrad1[1], 3277 ), mult_r( GainGrad1[2], 29490 ) ); + GainGradFEC[0] = add( mult_r( GainGrad1[1], 3277 /*0.1f in Q15*/ ), mult_r( GainGrad1[2], 29490 /*0.9f in Q15*/ ) ); move16(); /* Q14 */ } ELSE { - GainGradFEC[0] = add( mult_r( GainGrad1[0], 6553 ), mult_r( GainGrad1[1], 9830 ) ); + GainGradFEC[0] = add( mult_r( GainGrad1[0], 6553 /*0.2f in Q15*/ ), mult_r( GainGrad1[1], 9830 /*0.3f in Q15*/ ) ); move16(); - GainGradFEC[0] = add( GainGradFEC[0], mult_r( GainGrad1[2], 16384 ) ); + GainGradFEC[0] = add( GainGradFEC[0], mult_r( GainGrad1[2], 16384 /*0.5f in Q15*/ ) ); move16(); /* Q14 */ } @@ -649,7 +649,7 @@ static void gradientGainShape( } ELSE IF( GainGradFEC[0] > 0 ) { - GainShapeTemp[0] = add( shr( st_fx->GainShape_Delay[7], 1 ), mult_r( GainGradFEC[0], 16384 ) ); + GainShapeTemp[0] = add( shr( st_fx->GainShape_Delay[7], 1 ), mult_r( GainGradFEC[0], 16384 /*0.5f in Q15*/ ) ); move16(); /* Q14 */ } ELSE @@ -668,7 +668,7 @@ static void gradientGainShape( { FOR( i = 1; i < NUM_SHB_SUBFR / 4; i++ ) { - GainShapeTemp[i] = add( GainShapeTemp[i - 1], mult_r( GainGradFEC[i], 26214 ) ); + GainShapeTemp[i] = add( GainShapeTemp[i - 1], mult_r( GainGradFEC[i], 26214 /*0.8f in Q15*/ ) ); move16(); /* GainShapeTemp[i-1] + 0.8* GainShapeTemp[i] */ GainShapeTemp[i] = s_max( GainShapeTemp[i], 328 /*0.01f Q15*/ ); move16(); @@ -681,7 +681,7 @@ static void gradientGainShape( { FOR( i = 1; i < NUM_SHB_SUBFR / 4; i++ ) { - GainShapeTemp[i] = add( GainShapeTemp[i - 1], mult_r( GainGradFEC[i], 6553 ) ); + GainShapeTemp[i] = add( GainShapeTemp[i - 1], mult_r( GainGradFEC[i], 6553 /*0.2f in Q15*/ ) ); move16(); /* GainShapeTemp[i-1] + 0.8* GainShapeTemp[i] */ GainShapeTemp[i] = s_max( GainShapeTemp[i], 328 /*0.01f Q15*/ ); move16(); /* Q14 */ @@ -709,17 +709,17 @@ static void gradientGainShape( { FOR( j = 0; j < 4; j++ ) { - tmp = mult_r( GainShapeTemp[i], 19660 ); /* GainShapeTemp[i]*0.6 */ + tmp = mult_r( GainShapeTemp[i], 19660 /*0.6f Q15*/ ); /* GainShapeTemp[i]*0.6 */ IF( GT_16( 8192, tmp ) ) { - GainShape_fx[add( i * 4, j )] = shl( tmp, 2 ); - move16(); /* (GainShapeTemp[i]*0.6)>>1 */ + GainShape_fx[i * 4 + j] = shl( tmp, 2 ); /*Q15*/ + move16(); /* (GainShapeTemp[i]*0.6)>>1 */ } ELSE { - GainShape_fx[add( i * 4, j )] = 32767; - move16(); /* Clipping here to avoid the a huge change of the code due to gain shape change */ + GainShape_fx[i * 4 + j] = 32767; /*Q15*/ + move16(); /* Clipping here to avoid the a huge change of the code due to gain shape change */ } } } @@ -734,17 +734,17 @@ static void gradientGainShape( { IF( LT_16( GainShapeTemp[i], 16384 ) ) { - GainShape_fx[add( i * 4, j )] = shl( GainShapeTemp[i], 1 ); + GainShape_fx[i * 4 + j] = shl( GainShapeTemp[i], 1 ); /*Q15*/ move16(); } ELSE { - GainShape_fx[add( i * 4, j )] = 32767; + GainShape_fx[i * 4 + j] = 32767; // 1.0f in Q15 move16(); } } } - hBWE_TD->GainAttn_fx = mult_r( hBWE_TD->GainAttn_fx, 31129 ); + hBWE_TD->GainAttn_fx = mult_r( hBWE_TD->GainAttn_fx, 31129 /*0.95f in Q15*/ ); /*Q15*/ move16(); } ELSE IF( GT_16( st_fx->nbLostCmpt, 1 ) ) @@ -753,11 +753,11 @@ static void gradientGainShape( { FOR( j = 0; j < 4; j++ ) { - GainShape_fx[add( i * 4, j )] = GainShapeTemp[i]; + GainShape_fx[i * 4 + j] = GainShapeTemp[i]; /*Q15*/ move16(); } } - hBWE_TD->GainAttn_fx = mult_r( hBWE_TD->GainAttn_fx, 16384 ); + hBWE_TD->GainAttn_fx = mult_r( hBWE_TD->GainAttn_fx, 16384 /*0.5f in Q15*/ ); /*Q15*/ move16(); } ELSE @@ -768,17 +768,17 @@ static void gradientGainShape( { IF( LT_16( GainShapeTemp[i], 16384 ) ) { - GainShape_fx[add( i * 4, j )] = shl( GainShapeTemp[i], 1 ); + GainShape_fx[i * 4 + j] = shl( GainShapeTemp[i], 1 ); /*Q15*/ move16(); } ELSE { - GainShape_fx[add( i * 4, j )] = 32767; + GainShape_fx[i * 4 + j] = 32767; /*Q15*/ move16(); } } } - hBWE_TD->GainAttn_fx = mult_r( hBWE_TD->GainAttn_fx, 27852 ); + hBWE_TD->GainAttn_fx = mult_r( hBWE_TD->GainAttn_fx, 27852 /*0.85f in Q15*/ ); /*Q15*/ move16(); } @@ -1012,15 +1012,15 @@ void find_max_mem_dec_m3( * SWB TBE decoder, 6 - 14 kHz (or 7.5 - 15.5 kHz) band decoding module *-------------------------------------------------------------------*/ void ivas_swb_tbe_dec_fx( - Decoder_State *st, /* i/o: decoder state structure */ - STEREO_ICBWE_DEC_HANDLE hStereoICBWE, /* i/o: IC-BWE state structure */ - const Word32 *bwe_exc_extended_fx, /* i : bandwidth extended excitation */ + Decoder_State *st, /* i/o: decoder state structure */ + STEREO_ICBWE_DEC_HANDLE hStereoICBWE, /* i/o: IC-BWE state structure */ + const Word32 *bwe_exc_extended_fx, /* i : bandwidth extended excitation : Q_exc */ Word16 Q_exc, - const Word16 voice_factors_fx[], /* i : voicing factors */ - const Word32 old_syn_12k8_16k_fx[], /* i : low band synthesis */ - Word16 *White_exc16k_fx, /* o : shaped white excitation for the FB TBE */ - Word32 *synth_fx, /* o : SHB synthesis/final synthesis */ - Word16 *pitch_buf_fx, + const Word16 voice_factors_fx[], /* i : voicing factors : Q15 */ + const Word32 old_syn_12k8_16k_fx[], /* i : low band synthesis : old_syn_fx */ + Word16 *White_exc16k_fx, /* o : shaped white excitation for the FB TBE : Q_white_exc*/ + Word32 *synth_fx, /* o : SHB synthesis/final synthesis : Qx */ + Word16 *pitch_buf_fx, /* i : Q6 */ Word16 *Q_white_exc ) { Word16 i, j, cnt, n; @@ -1136,7 +1136,7 @@ void ivas_swb_tbe_dec_fx( /* WB/SWB bandwidth switching */ test(); test(); - IF( ( GT_16( st->tilt_wb_fx, 10240 ) && ( st->clas_dec == UNVOICED_CLAS ) ) || GT_16( st->tilt_wb_fx, 20480 ) ) + IF( ( GT_16( st->tilt_wb_fx, 10240 /*5 in Q11*/ ) && ( EQ_16( st->clas_dec, UNVOICED_CLAS ) ) ) || GT_16( st->tilt_wb_fx, 20480 /*10 in Q11*/ ) ) { test(); test(); @@ -1155,21 +1155,20 @@ void ivas_swb_tbe_dec_fx( ) { is_fractive = 0; - move16(); } ELSE { is_fractive = 1; - move16(); } + move16(); } /* WB/SWB bandwidth switching */ IF( st->bws_cnt > 0 ) { - f_fx = 1489; /*Q15*/ + f_fx = 1489; /*1.0f / 22.0f in Q15*/ move16(); - inc_fx = 1489; /*Q15*/ + inc_fx = 1489; /*1.0f / 22.0f in Q15*/ move16(); IF( EQ_16( is_fractive, 1 ) ) @@ -1180,9 +1179,9 @@ void ivas_swb_tbe_dec_fx( { FOR( i = 0; i < LPC_SHB_ORDER; i++ ) { - hBWE_TD->lsp_prevfrm_fx[i] = f_fx; + hBWE_TD->lsp_prevfrm_fx[i] = f_fx; /*Q15*/ move16(); - f_fx = add( f_fx, inc_fx ); + f_fx = add( f_fx, inc_fx ); /*Q15*/ } } test(); @@ -1194,13 +1193,13 @@ void ivas_swb_tbe_dec_fx( test(); IF( ( NE_16( st->last_extl, SWB_TBE ) && NE_16( st->last_extl, FB_TBE ) && !( ( L_sub( L_shr( st->prev_enerLH_fx, 1 ), st->enerLH_fx ) < 0 ) && L_sub( st->prev_enerLH_fx, ( L_shr( st->enerLH_fx, 1 ) > 0 ) ) ) ) || st->last_core != ACELP_CORE || ( ( st->last_core == ACELP_CORE ) && GT_32( abs( L_sub( st->last_core_brate, st->core_brate ) ), 3600 ) ) || EQ_16( s_xor( is_fractive, st->prev_fractive ), 1 ) ) { - set16_fx( GainShape_fx, 11587, NUM_SHB_SUBFR ); + set16_fx( GainShape_fx, 11587, NUM_SHB_SUBFR ); /*0.3536f in Q15*/ } ELSE { - if ( GT_16( hBWE_TD->prev_GainShape_fx, 11587 ) ) + if ( GT_16( hBWE_TD->prev_GainShape_fx, 11587 ) ) /*0.3536f in Q15*/ { - hBWE_TD->prev_GainShape_fx = 11587; + hBWE_TD->prev_GainShape_fx = 11587; /*0.3536f in Q15*/ move16(); } set16_fx( GainShape_fx, hBWE_TD->prev_GainShape_fx, NUM_SHB_SUBFR ); @@ -1220,7 +1219,7 @@ void ivas_swb_tbe_dec_fx( move16(); FOR( i = 0; i < LPC_SHB_ORDER; i++ ) { - hBWE_TD->lsp_prevfrm_fx[i] = f_fx; + hBWE_TD->lsp_prevfrm_fx[i] = f_fx; /*Q15*/ move16(); f_fx = add( f_fx, inc_fx ); } @@ -1240,9 +1239,9 @@ void ivas_swb_tbe_dec_fx( move16(); FOR( i = 0; i < LPC_SHB_ORDER; i++ ) { - hBWE_TD->lsp_prevfrm_fx[i] = f_fx; + hBWE_TD->lsp_prevfrm_fx[i] = f_fx; /*Q15*/ move16(); - f_fx = add( f_fx, inc_fx ); + f_fx = add( f_fx, inc_fx ); /*Q15*/ } } Copy( hBWE_TD->lsp_prevfrm_fx, lsf_shb_fx, LPC_SHB_ORDER ); @@ -1267,7 +1266,7 @@ void ivas_swb_tbe_dec_fx( test(); IF( ( st->core == ACELP_CORE ) && ( st->last_core == ACELP_CORE ) && !st->prev_use_partial_copy && EQ_16( st->prev_coder_type, UNVOICED ) && NE_32( GainFrame_fx, hBWE_TD->GainFrame_prevfrm_fx ) && NE_16( st->next_coder_type, GENERIC ) && EQ_16( st->last_extl, SWB_TBE ) ) { - GainFrame_fx = L_add( Mult_32_16( hBWE_TD->GainFrame_prevfrm_fx, 26214 ), Mult_32_16( GainFrame_fx, 6553 ) ); + GainFrame_fx = L_add( Mult_32_16( hBWE_TD->GainFrame_prevfrm_fx, 26214 /*0.8f in Q15*/ ), Mult_32_16( GainFrame_fx, 6553 /*0.2f in Q15*/ ) ); } } ELSE @@ -1323,13 +1322,14 @@ void ivas_swb_tbe_dec_fx( IF( EQ_16( st->last_extl, SWB_TBE ) ) { GainFrame_fx = L_add( Mult_32_16( hBWE_TD->GainFrame_prevfrm_fx, temp_fx ), Mult_32_16( GainFrame_fx, sub( 32767, temp_fx ) ) ); + /*Q18*/ } IF( ( st->core == ACELP_CORE ) && ( st->last_core == ACELP_CORE ) ) { - if ( !st->prev_use_partial_copy && EQ_16( st->last_coder_type, VOICED ) && EQ_16( st->rf_frame_type, RF_GENPRED ) && GT_32( GainFrame_fx, 2097152 ) && LT_32( GainFrame_fx, 3059606 ) ) + if ( !st->prev_use_partial_copy && EQ_16( st->last_coder_type, VOICED ) && EQ_16( st->rf_frame_type, RF_GENPRED ) && GT_32( GainFrame_fx, 2097152 /*8.0f in Q18*/ ) && LT_32( GainFrame_fx, 3059606 /*11.67f in Q18*/ ) ) { - GainFrame_fx = Mult_32_16( GainFrame_fx, 9830 ); + GainFrame_fx = Mult_32_16( GainFrame_fx, 9830 /*0.3f in Q15*/ ); // Q18 } } } @@ -1360,7 +1360,7 @@ void ivas_swb_tbe_dec_fx( { FOR( j = 0; j < 4; j++ ) { - GainShape_fx[add( i * 4, j )] = mult_r( st->cummulative_damping, st->GainShape_Delay[4 + i] ); + GainShape_fx[i * 4 + j] = mult_r( st->cummulative_damping, st->GainShape_Delay[4 + i] ); move16(); } } @@ -1464,7 +1464,7 @@ void ivas_swb_tbe_dec_fx( Copy( &st->GainShape_Delay[4], &st->GainShape_Delay[0], NUM_SHB_SUBFR / 4 ); FOR( i = 0; i < NUM_SHB_SUBFR / 4; i++ ) { - st->GainShape_Delay[i + 4] = GainShape_fx[i * 4]; + st->GainShape_Delay[i + 4] = GainShape_fx[i * 4]; /*Q15*/ move16(); } @@ -2140,9 +2140,9 @@ void ivas_swb_tbe_dec_fx( IF( GT_32( L_shr( prev_ener_ratio_fx, 2 ), GainFrame_fx ) && ( ( EQ_16( st->codec_mode, MODE1 ) && GT_32( st->enerLL_fx, st->prev_enerLL_fx ) && GT_32( st->enerLH_fx, st->prev_enerLH_fx ) ) || EQ_16( st->codec_mode, MODE2 ) ) ) { test(); - IF( GT_16( tilt_swb_fec_fx, 20480 ) && GT_16( hBWE_TD->tilt_swb_fec_fx, 20480 ) ) + IF( GT_16( tilt_swb_fec_fx, 20480 /*10.0f in Q11*/ ) && GT_16( hBWE_TD->tilt_swb_fec_fx, 20480 /*10.0f in Q11*/ ) ) { - GainFrame_fx = L_min( L_add( Mult_32_16( prev_ener_ratio_fx, 26214 ), Mult_32_16( GainFrame_fx, 6554 ) ), L_shl( Mult_32_16( GainFrame_fx, 16384 ), 3 ) ); /*Q18*/ + GainFrame_fx = L_min( L_add( Mult_32_16( prev_ener_ratio_fx, 26214 /*0.8f in Q15*/ ), Mult_32_16( GainFrame_fx, 6554 /*0.2f in Q15*/ ) ), L_shl( Mult_32_16( GainFrame_fx, 16384 /*4.0f in Q12*/ ), 3 ) ); /*Q18*/ } ELSE { @@ -2154,11 +2154,11 @@ void ivas_swb_tbe_dec_fx( test(); IF( GT_16( tilt_swb_fec_fx, 20480 ) && GT_16( hBWE_TD->tilt_swb_fec_fx, 20480 ) ) { - GainFrame_fx = L_add( Mult_32_16( prev_ener_ratio_fx, 16384 ), Mult_32_16( GainFrame_fx, 16384 ) ); + GainFrame_fx = L_add( Mult_32_16( prev_ener_ratio_fx, 16384 /*0.5f in Q15*/ ), Mult_32_16( GainFrame_fx, 16384 /*0.5f in Q15*/ ) ); /* Q18 */ } ELSE { - GainFrame_fx = L_add( Mult_32_16( prev_ener_ratio_fx, 6554 ), Mult_32_16( GainFrame_fx, 26214 ) ); + GainFrame_fx = L_add( Mult_32_16( prev_ener_ratio_fx, 6554 /*0.2f in Q15*/ ), Mult_32_16( GainFrame_fx, 26214 /*0.8f in Q15*/ ) ); /* Q18 */ } } } @@ -2446,7 +2446,7 @@ void ivas_swb_tbe_dec_fx( { GainShape_fx[2 * j] = mult_r( GainShape_fx[2 * j], scale_fx ); move16(); - GainShape_fx[add( 2 * j, 1 )] = mult_r( GainShape_fx[add( 2 * j, 1 )], scale_fx ); + GainShape_fx[2 * j + 1] = mult_r( GainShape_fx[2 * j + 1], scale_fx ); move16(); FOR( i = 0; i < L_FRAME16k / 8; i++ ) { @@ -2573,7 +2573,7 @@ void ivas_swb_tbe_dec_fx( move16(); FOR( i = 0; i < 40; i++ ) { - shaped_shb_excitation_fx[add( i, j * 40 )] = shl( mult_r( shaped_shb_excitation_fx[add( i, j * 40 )], scale_fx ), 3 ); + shaped_shb_excitation_fx[i + j * L_FRAME16k / 8] = shl( mult_r( shaped_shb_excitation_fx[i + j * L_FRAME16k / 8], scale_fx ), 3 ); move16(); /* Q_bwe_exc +12+3 -15 =Q_bwe_exc*/ } @@ -2772,7 +2772,7 @@ void ivas_swb_tbe_dec_fx( if ( !st->bfi ) { - hBWE_TD->GainAttn_fx = 32767; + hBWE_TD->GainAttn_fx = 32767; /*1.0f in Q15*/ move16(); } } @@ -2784,7 +2784,7 @@ void ivas_swb_tbe_dec_fx( move32(); /*Q18*/ hBWE_TD->tilt_swb_fec_fx = tilt_swb_fec_fx; move16(); - hBWE_TD->GainAttn_fx = 32767; + hBWE_TD->GainAttn_fx = 32767; /*1.0f in Q15*/ move16(); } } @@ -4565,12 +4565,12 @@ void GenTransition( #ifdef IVAS_FLOAT_FIXED void GenTransition_fixed( TD_BWE_DEC_HANDLE hBWE_TD, /* i/o: TD BWE data handle */ - Word32 *outputHB_fx, /* o : synthesized HB transitions signal */ - const Word32 output_Fs, /* i : output sampling rate */ - const Word16 element_mode, /* i : element mode */ - const Word16 L_frame, /* i : ACELP frame length */ - const Word16 rf_flag, /* i : RF flag */ - const Word32 total_brate, /* i : total bitrate */ + Word32 *outputHB_fx, /* o : synthesized HB transitions signal : Q11 */ + const Word32 output_Fs, /* i : output sampling rate : Q0 */ + const Word16 element_mode, /* i : element mode : Q0 */ + const Word16 L_frame, /* i : ACELP frame length : Q0 */ + const Word16 rf_flag, /* i : RF flag : Q0 */ + const Word32 total_brate, /* i : total bitrate : Q0 */ const Word16 prev_Qx ) { Word16 i, length; @@ -4578,7 +4578,7 @@ void GenTransition_fixed( Word32 syn_overlap_32k_fx[2 * SHB_OVERLAP_LEN]; /* set targeted length of transition signal */ - length = i_mult( 2, NS2SA( output_Fs, DELAY_BWE_TOTAL_NS ) ); + length = i_mult( 2, NS2SA_FX2( output_Fs, DELAY_BWE_TOTAL_NS ) ); /* upsample overlap snippet */ Interpolate_allpass_steep_32( hBWE_TD->syn_overlap_fx_32, hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx_32, SHB_OVERLAP_LEN, syn_overlap_32k_fx ); @@ -4599,13 +4599,12 @@ void GenTransition_fixed( IF( i % 2 == 0 ) { syn_overlap_32k_fx[i] = L_negate( syn_overlap_32k_fx[i] ); - move32(); } ELSE { syn_overlap_32k_fx[i] = syn_overlap_32k_fx[i]; - move32(); } + move32(); } } @@ -4697,7 +4696,7 @@ void GenTransition_WB( #ifdef IVAS_FLOAT_FIXED void GenTransition_WB_fixed( TD_BWE_DEC_HANDLE hBWE_TD, /* i/o: TD BWE data handle */ - Word32 *outputHB_fx, /* o : synthesized HB transitions signal */ + Word32 *outputHB_fx, /* o : synthesized HB transitions signal : Q11 */ const Word32 output_Fs /* i : output sampling rate */ ) { @@ -4706,7 +4705,7 @@ void GenTransition_WB_fixed( Word32 upsampled_synth_fx[L_FRAME48k]; /* set targeted length of transition signal */ - length = i_mult( 2, NS2SA( output_Fs, DELAY_BWE_TOTAL_NS ) ); + length = i_mult( 2, NS2SA_FX2( output_Fs, DELAY_BWE_TOTAL_NS ) ); /* upsample overlap snippet */ Interpolate_allpass_steep_32( hBWE_TD->syn_overlap_fx_32, hBWE_TD->state_lsyn_filt_shb_fx_32, SHB_OVERLAP_LEN / 2, speech_buf_16k1_fx ); diff --git a/lib_dec/swb_tbe_dec_fx.c b/lib_dec/swb_tbe_dec_fx.c index 2e187546e..cb3ae52a8 100644 --- a/lib_dec/swb_tbe_dec_fx.c +++ b/lib_dec/swb_tbe_dec_fx.c @@ -633,11 +633,11 @@ void ResetSHBbuffer_Dec_fx( Decoder_State *st_fx /* i/o: SHB encoder structure * /*==========================================================================*/ void ivas_wb_tbe_dec_fx( Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word16 coder_type, /* i : coding type */ + const Word16 coder_type, /* i : coding type Q0 */ Word32 *bwe_exc_extended, /* i : bandwidth extended exciatation 2*Q_exc*/ const Word16 Q_exc, - const Word16 voice_factors[], /* i : voicing factors */ - Word16 *synth, /* o : WB synthesis/final synthesis */ + const Word16 voice_factors[], /* i : voicing factors Q15 */ + Word16 *synth, /* o : WB synthesis/final synthesis Q_synth */ Word16 *Q_synth ) { Word16 i; @@ -716,7 +716,7 @@ void ivas_wb_tbe_dec_fx( IF( ( st_fx->core == ACELP_CORE ) && ( st_fx->last_core == ACELP_CORE ) && !st_fx->prev_use_partial_copy && EQ_16( st_fx->prev_coder_type, UNVOICED ) && NE_32( GainFrame, hBWE_TD->GainFrame_prevfrm_fx ) && EQ_16( st_fx->last_extl, WB_TBE ) ) { /*GainFrame = 0.2f*GainFrame + 0.8f*st_fx->GainFrame_prevfrm_fx;*/ - GainFrame = L_add( Mult_32_16( hBWE_TD->GainFrame_prevfrm_fx, 26214 ), Mult_32_16( GainFrame, 6553 ) ); + GainFrame = L_add( Mult_32_16( hBWE_TD->GainFrame_prevfrm_fx /*Q18*/, 26214 /*0.8f in Q15*/ ), Mult_32_16( GainFrame /*Q18*/, 6553 /*0.2f in Q15*/ ) /*Q18+Q15 - 15*/ ); /*Q18*/ } } ELSE @@ -782,7 +782,7 @@ void ivas_wb_tbe_dec_fx( test(); IF( !st_fx->prev_use_partial_copy && EQ_16( st_fx->last_coder_type, VOICED ) && EQ_16( st_fx->rf_frame_type, RF_GENPRED ) && LT_16( st_fx->prev_tilt_code_dec_fx, 1497 ) && GT_16( st_fx->prev_tilt_code_dec_fx, 200 ) ) { - GainFrame = Mult_32_16( GainFrame, 9830 ); + GainFrame = Mult_32_16( GainFrame, 9830 /*0.3f in Q15*/ ); /*Q18*/ } } } @@ -806,12 +806,12 @@ void ivas_wb_tbe_dec_fx( } set16_fx( GainShape, RECIP_ROOT_EIGHT_FX, NUM_SHB_SUBFR / 2 ); - hBWE_TD->GainAttn_fx = mult_r( hBWE_TD->GainAttn_fx, 27853 ); + hBWE_TD->GainAttn_fx = mult_r( hBWE_TD->GainAttn_fx, 27853 /*0.85f in Q15*/ ); /*Q15*/ move16(); IF( EQ_16( st_fx->codec_mode, MODE1 ) ) { - GainFrame = Mult_32_16( hBWE_TD->GainFrame_prevfrm_fx, hBWE_TD->GainAttn_fx ); /*Q18*/ + GainFrame = Mult_32_16( hBWE_TD->GainFrame_prevfrm_fx /*Q18*/, hBWE_TD->GainAttn_fx /*Q15*/ ); /*Q15+Q18-15*/ } ELSE { @@ -835,7 +835,7 @@ void ivas_wb_tbe_dec_fx( lpc_wb[i] = negate( lpc_wb[i] ); move16(); } - lpc_wb[0] = 4096; + lpc_wb[0] = 4096; /*1.0f in Q12*/ move16(); } ELSE @@ -852,7 +852,7 @@ void ivas_wb_tbe_dec_fx( lpc_wb[i] = negate( lpc_wb[i] ); move16(); } - lpc_wb[0] = 4096; + lpc_wb[0] = 4096; /*1.0f in Q12*/ move16(); } @@ -1187,7 +1187,7 @@ void ivas_wb_tbe_dec_fx( FOR( i = 0; i < L_FRAME16k; i++ ) { - synth[i] = mult_r( error[i], 21299 ); + synth[i] = mult_r( error[i], 21299 /*0.65f in Q15*/ ); move16(); } @@ -1376,11 +1376,11 @@ void wb_tbe_dec_fx( move16(); FOR( i = 1; i < LPC_SHB_ORDER_LBR_WB; i++ ) { - hBWE_TD->lsp_prevfrm_fx[i] = add( hBWE_TD->lsp_prevfrm_fx[i - i], 3277 /*0.1f Q15*/ ); + hBWE_TD->lsp_prevfrm_fx[i] = add( hBWE_TD->lsp_prevfrm_fx[i - i], 3277 /*0.1f Q15*/ ); /*Q15*/ move16(); } } - Copy( hBWE_TD->lsp_prevfrm_fx, lsf_wb, LPC_SHB_ORDER_LBR_WB ); + Copy( hBWE_TD->lsp_prevfrm_fx, lsf_wb, LPC_SHB_ORDER_LBR_WB ); /*Q15*/ set16_fx( GainShape, RECIP_ROOT_EIGHT_FX, NUM_SHB_SUBFR / 2 ); IF( EQ_16( st_fx->rf_frame_type, RF_NELP ) ) @@ -1397,7 +1397,7 @@ void wb_tbe_dec_fx( IF( ( st_fx->core == ACELP_CORE ) && ( st_fx->last_core == ACELP_CORE ) && !st_fx->prev_use_partial_copy && EQ_16( st_fx->prev_coder_type, UNVOICED ) && NE_32( GainFrame, hBWE_TD->GainFrame_prevfrm_fx ) && EQ_16( st_fx->last_extl, WB_TBE ) ) { /*GainFrame = 0.2f*GainFrame + 0.8f*st_fx->GainFrame_prevfrm_fx;*/ - GainFrame = L_add( Mult_32_16( hBWE_TD->GainFrame_prevfrm_fx, 26214 ), Mult_32_16( GainFrame, 6553 ) ); + GainFrame = L_add( Mult_32_16( hBWE_TD->GainFrame_prevfrm_fx, 26214 ), Mult_32_16( GainFrame, 6553 ) ); /*Q18*/ } } ELSE @@ -1463,7 +1463,7 @@ void wb_tbe_dec_fx( test(); IF( !st_fx->prev_use_partial_copy && EQ_16( st_fx->last_coder_type, VOICED ) && EQ_16( st_fx->rf_frame_type, RF_GENPRED ) && LT_16( st_fx->prev_tilt_code_dec_fx, 1497 ) && GT_16( st_fx->prev_tilt_code_dec_fx, 200 ) ) { - GainFrame = Mult_32_16( GainFrame, 9830 ); + GainFrame = Mult_32_16( GainFrame, 9830 ); /*Q18*/ } } } @@ -1478,11 +1478,11 @@ void wb_tbe_dec_fx( { IF( EQ_32( st_fx->extl_brate, WB_TBE_0k35 ) ) { - Copy( hBWE_TD->lsp_prevfrm_fx, lsf_wb, LPC_SHB_ORDER_LBR_WB ); + Copy( hBWE_TD->lsp_prevfrm_fx, lsf_wb, LPC_SHB_ORDER_LBR_WB ); /*Q15*/ } ELSE { - Copy( hBWE_TD->lsp_prevfrm_fx, lsf_wb, LPC_SHB_ORDER_WB ); + Copy( hBWE_TD->lsp_prevfrm_fx, lsf_wb, LPC_SHB_ORDER_WB ); /*Q15*/ } set16_fx( GainShape, RECIP_ROOT_EIGHT_FX, NUM_SHB_SUBFR / 2 ); @@ -1971,18 +1971,18 @@ void wb_tbe_dec_fx( /* Update previous frame parameters for FEC */ IF( EQ_32( st_fx->extl_brate, WB_TBE_0k35 ) ) { - Copy( lsf_wb, hBWE_TD->lsp_prevfrm_fx, LPC_SHB_ORDER_LBR_WB ); + Copy( lsf_wb, hBWE_TD->lsp_prevfrm_fx, LPC_SHB_ORDER_LBR_WB ); /*Q15*/ } ELSE { - Copy( lsf_wb, hBWE_TD->lsp_prevfrm_fx, LPC_SHB_ORDER_WB ); + Copy( lsf_wb, hBWE_TD->lsp_prevfrm_fx, LPC_SHB_ORDER_WB ); /*Q15*/ } hBWE_TD->GainFrame_prevfrm_fx = GainFrame; /* Q18 */ move32(); IF( !st_fx->bfi ) { - hBWE_TD->GainAttn_fx = 32767; + hBWE_TD->GainAttn_fx = 32767; /*Q15*/ move16(); } @@ -3742,7 +3742,7 @@ void swb_tbe_dec_fx( if ( !st_fx->bfi ) { - hBWE_TD->GainAttn_fx = 32767; + hBWE_TD->GainAttn_fx = 32767; /*Q15*/ move16(); } } @@ -3754,7 +3754,7 @@ void swb_tbe_dec_fx( move16(); /*Q18*/ hBWE_TD->tilt_swb_fec_fx = tilt_swb_fec; move16(); - hBWE_TD->GainAttn_fx = 32767; + hBWE_TD->GainAttn_fx = 32767; /*Q15*/ move16(); } } @@ -3970,7 +3970,7 @@ static void gradientGainShape( static void Dequant_lower_LSF_fx( const Word16 lsf_idx[], /* i : LSF indices */ - Word16 lsf_q[] /* o : Quantized LSFs */ + Word16 lsf_q[] /* o : Quantized LSFs Q15*/ ) { Word16 i; @@ -3979,7 +3979,7 @@ static void Dequant_lower_LSF_fx( move16(); FOR( i = 1; i < NUM_Q_LSF; i++ ) { - lsf_q[i] = add( lsf_q_cb_fx[i][lsf_idx[i]], lsf_q[i - 1] ); + lsf_q[i] = add( lsf_q_cb_fx[i][lsf_idx[i]], lsf_q[i - 1] ); /*Q15*/ move16(); } @@ -3993,9 +3993,10 @@ static void Dequant_lower_LSF_fx( *-------------------------------------------------------------------*/ static void Map_higher_LSF_fx( - Word16 lsf_q[], /* i/o : Quantized lower LSFs */ - const Word16 m, /* i : Mirroring point */ - const Word16 grid_in[] /* i : Input LSF smoohthing grid */ ) + Word16 lsf_q[], /* i/o : Quantized lower LSFs Q15*/ + const Word16 m, /* i : Mirroring point Q15*/ + const Word16 grid_in[] /* i : Input LSF smoohthing grid Q15*/ +) { Word16 lsf_map[NUM_MAP_LSF]; Word16 grid[NUM_MAP_LSF]; @@ -4007,42 +4008,42 @@ static void Map_higher_LSF_fx( FOR( i = 0; i < NUM_MAP_LSF; i++ ) { - lsf_map[i] = sub( shl( m, 1 ), lsf_q[NUM_MAP_LSF - 1 - i] ); + lsf_map[i] = sub( shl( m, 1 ), lsf_q[NUM_MAP_LSF - 1 - i] ); /*Q15*/ move16(); } IF( GT_16( m, MAX_LSF_FX_BY_2 ) ) { - offset = lsf_map[0]; + offset = lsf_map[0]; /*Q15*/ move16(); scale = div_s( sub( MAX_LSF_FX, m ), m ); FOR( i = 0; i < NUM_MAP_LSF; i++ ) { - lsf_map[i] = add( mult_r( sub( lsf_map[i], offset ), scale ), offset ); + lsf_map[i] = add( mult_r( sub( lsf_map[i], offset ), scale ), offset ); /*Q15*/ move16(); } } - last_q_lsf = lsf_q[NUM_Q_LSF - 1]; + last_q_lsf = lsf_q[NUM_Q_LSF - 1]; /*Q15*/ move16(); scale = sub( MAX_LSF_FX, last_q_lsf ); FOR( i = 0; i < NUM_MAP_LSF; i++ ) { - grid[i] = add( mult_r( grid_in[i], scale ), last_q_lsf ); + grid[i] = add( mult_r( grid_in[i], scale ), last_q_lsf ); /*Q15*/ move16(); } FOR( i = 0; i < NUM_MAP_LSF; i++ ) { - lsf_smooth[i] = sub( mult_r( grid_smoothing_fx[i], grid[i] ), - mult_r( lsf_map[i], add( grid_smoothing_fx[i], -32768 /*-1.0f Q15*/ ) ) ); + lsf_smooth[i] = sub( mult_r( grid_smoothing_fx[i], grid[i] ) /*Q15*/, + mult_r( lsf_map[i], add( grid_smoothing_fx[i], -32768 /*-1.0f Q15*/ /*Q15*/ ) ) ); /*Q15*/ move16(); } FOR( i = 0; i < NUM_MAP_LSF; i++ ) { - lsf_q[NUM_Q_LSF + i] = lsf_smooth[i]; + lsf_q[NUM_Q_LSF + i] = lsf_smooth[i]; /*Q15*/ move16(); } @@ -4051,40 +4052,41 @@ static void Map_higher_LSF_fx( static void Dequant_mirror_point_fx( - const Word16 lsf_q[], /* i/o : Quantized lower LSFs */ - const Word16 m_idx, - /* i : Mirror point index */ Word16 *m /* i : Mirroring point */ ) + const Word16 lsf_q[], /* i/o : Quantized lower LSFs Q15*/ + const Word16 m_idx, /* i : Mirror point index Q0 */ + Word16 *m /* i : Mirroring point Q15*/ +) { - *m = add( mirror_point_q_cb_fx[m_idx], lsf_q[NUM_Q_LSF - 1] ); + *m = add( mirror_point_q_cb_fx[m_idx], lsf_q[NUM_Q_LSF - 1] ); /*Q15*/ move16(); return; } Word16 dotp_loc( - const Word16 x[], /* i : vector x[] */ - const Word32 y[], /* i : vector y[] */ + const Word16 x[], /* i : vector x[] Qx */ + const Word32 y[], /* i : vector y[] Qy */ const Word16 n /* i : vector length */ ) { Word16 i; Word32 suma; Word16 guarded_bits = find_guarded_bits_fx( n ); - suma = L_shr( Mpy_32_16_1( y[0], x[0] ), guarded_bits ); + suma = L_shr( Mpy_32_16_1( y[0], x[0] ), guarded_bits ); /*Qx + Qy - guarded_bits*/ FOR( i = 1; i < n; i++ ) { - suma = L_add( suma, L_shr( Mpy_32_16_1( y[i], x[i] ), guarded_bits ) ); + suma = L_add( suma, L_shr( Mpy_32_16_1( y[i], x[i] ), guarded_bits ) ); /*Qx + Qy - guarded_bits*/ } - suma = L_shl_sat( suma, guarded_bits ); + suma = L_shl_sat( suma, guarded_bits ); /*Qx + Qy*/ - return extract_h( suma ); + return extract_h( suma ); /*Qx + Qy - 16*/ } void ivas_dequantizeSHBparams_fx_9_1( Decoder_State *st_fx, - const Word16 extl, /* i : extension layer */ - Word32 extl_brate, /* i : extensiuon layer bitrate */ - Word16 *Q_lsf, /* o : SHB LSF from de-quantization Q15*/ + const Word16 extl, /* i : extension layer */ + Word32 extl_brate, /* i : extensiuon layer bitrate */ + Word16 *Q_lsf, /* o : SHB LSF from de-quantization Q15*/ Word16 *Q_subgain, /* o : SHB subframe gains from de-quantization Q15*/ Word32 *Q_framegrain, /* o : SHB frame gain from de-quantization Q18*/ Word16 *uv_flag, /* o : unvoiced flag*/ @@ -4281,13 +4283,10 @@ void ivas_dequantizeSHBparams_fx_9_1( *Q_mixFactors = 0; move16(); } - //*Q_mixFactors = 0; set16_fx( Q_shb_res_gshape, 0, 5 ); } /* LSFs */ - - test(); test(); test(); @@ -4327,13 +4326,13 @@ void ivas_dequantizeSHBparams_fx_9_1( set16_fx( lsf_q, 0, LPC_SHB_ORDER ); /* VQ part */ - num_bits_lvq = config_LSF_BWE[i_mult( sub( NUM_BITS_SHB_MSLVQ, nbits ), 3 )]; + num_bits_lvq = config_LSF_BWE[( NUM_BITS_SHB_MSLVQ - nbits ) * 3]; Idx = get_next_indice_fx( st_fx, num_bits_lvq ); v_add_16( lsf_q, cb_stage + i_mult( Idx, 6 ), lsf_q, 6 ); /* MSLVQ part */ - num_bits_lvq = sub( sub( nbits, num_bits_lvq ), config_LSF_BWE[add( i_mult( sub( NUM_BITS_SHB_MSLVQ, nbits ), 3 ), 2 )] ); - predictor_bits = config_LSF_BWE[add( i_mult( sub( NUM_BITS_SHB_MSLVQ, nbits ), 3 ), 2 )]; + num_bits_lvq = sub( sub( nbits, num_bits_lvq ), config_LSF_BWE[( NUM_BITS_SHB_MSLVQ - nbits ) * 3 + 2] ); + predictor_bits = config_LSF_BWE[( NUM_BITS_SHB_MSLVQ - nbits ) * 3 + 2]; Idx_pred = 0; move16(); @@ -4364,9 +4363,9 @@ void ivas_dequantizeSHBparams_fx_9_1( ELSE { Idx_pred = (Word16) get_next_indice_fx( st_fx, 1 ); - lsf_q[LATTICE_DIM] = dotp_loc( lsf_q, &LastCoefPred_1bit_fx[i_mult( 2 * ( LATTICE_DIM + 1 ), Idx_pred )], LATTICE_DIM ); + lsf_q[LATTICE_DIM] = dotp_loc( lsf_q, &LastCoefPred_1bit_fx[2 * ( LATTICE_DIM + 1 ) * Idx_pred], LATTICE_DIM ); move16(); - lsf_q[LATTICE_DIM + 1] = dotp_loc( lsf_q, &LastCoefPred_1bit_fx[add( i_mult( 2 * ( LATTICE_DIM + 1 ), Idx_pred ), LATTICE_DIM + 1 )], LATTICE_DIM ); + lsf_q[LATTICE_DIM + 1] = dotp_loc( lsf_q, &LastCoefPred_1bit_fx[2 * ( LATTICE_DIM + 1 ) * Idx_pred + LATTICE_DIM + 1], LATTICE_DIM ); move16(); } @@ -4541,15 +4540,15 @@ void ivas_dequantizeSHBparams_fx_9_1( static void dequantizeSHBparams_fx_9_1( Decoder_State *st_fx, - const Word16 extl, /* i : extension layer */ - Word32 extl_brate, /* i : extensiuon layer bitrate */ - Word16 *Q_lsf, /* o : SHB LSF from de-quantization Q15*/ + const Word16 extl, /* i : extension layer */ + Word32 extl_brate, /* i : extensiuon layer bitrate */ + Word16 *Q_lsf, /* o : SHB LSF from de-quantization Q15*/ Word16 *Q_subgain, /* o : SHB subframe gains from de-quantization Q15*/ Word32 *Q_framegrain, /* o : SHB frame gain from de-quantization Q18*/ Word16 *uv_flag, /* o : unvoiced flag*/ - Word32 *Q_shb_ener_sf, /* o : Q15 */ - Word16 *Q_shb_res_gshape, /* o : Q14 */ - Word16 *Q_mixFactors /* o : Q15 */ + Word32 *Q_shb_ener_sf, /* o : Q15*/ + Word16 *Q_shb_res_gshape, /* o : Q14*/ + Word16 *Q_mixFactors /* o : Q15*/ ) { Word16 i, j, idxLSF, idxSubGain, idxFrameGain; @@ -4841,10 +4840,10 @@ static void dequantizeSHBparams_fx_9_1( * FB TBE decoder, 14(resp. 15.5) - 20 kHz band decoding module *-------------------------------------------------------------------*/ void fb_tbe_dec_fx( - Decoder_State *st, /* i/o: encoder state structure */ - const Word16 fb_exc[], /* i : FB excitation from the SWB part */ + Decoder_State *st, /* i/o: encoder state structure */ + const Word16 fb_exc[], /* i : FB excitation from the SWB part Q_fb_exc */ Word16 Q_fb_exc, - Word16 *hb_synth, /* o : high-band synthesis */ + Word16 *hb_synth, /* o : high-band synthesis Q(15 - hb_synth_exp) */ Word16 hb_synth_exp ) { @@ -4903,11 +4902,11 @@ void fb_tbe_dec_fx( void fb_tbe_dec_ivas_fx( Decoder_State *st, /* i/o: encoder state structure */ - const Word16 fb_exc[], /* i : FB excitation from the SWB part */ + const Word16 fb_exc[], /* i : FB excitation from the SWB part Q_fb_exc */ Word16 Q_fb_exc, - Word32 *hb_synth, /* o : high-band synthesis */ + Word32 *hb_synth, /* o : high-band synthesis Q(15 - hb_synth_exp) */ Word16 hb_synth_exp, - Word16 *fb_synth_ref, + Word16 *fb_synth_ref, /*Q_fb_synth_ref*/ Word16 Q_fb_synth_ref, Word16 output_frame ) @@ -4978,7 +4977,7 @@ void fb_tbe_dec_ivas_fx( FOR( i = 0; i < L_FRAME48k; i++ ) { // hb_synth[i] = L_add( hb_synth[i], L_deposit_l(fb_synth[i])); - hb_synth[i] = L_add( hb_synth[i], L_shl( fb_synth[i], Q11 ) ); + hb_synth[i] = L_add( hb_synth[i], L_shl( fb_synth[i], Q11 ) ); // hb_synth_exp move16(); } return; @@ -5099,12 +5098,12 @@ void tbe_read_bitstream_fx( * switching from TBE to IGF *---------------------------------------------------------------------*/ void GenTransition_fx( - const Word16 *input, /* i : gain shape overlap buffer */ - const Word16 *old_hb_synth, /* i : synthesized HB from previous frame */ - Word16 length, /* i : targeted length of transition signal */ - Word16 *output, /* o : synthesized transitions signal */ - Word32 Hilbert_Mem[], /* i/o: memory */ - Word16 state_lsyn_filt_shb_local[], /* i/o: memory */ + const Word16 *input, /* i : gain shape overlap buffer Q11 */ + const Word16 *old_hb_synth, /* i : synthesized HB from previous frame Q(15 - hb_synth_fx_exp)*/ + Word16 length, /* i : targeted length of transition signal */ + Word16 *output, /* o : synthesized transitions signal st_fx->prev_Q_bwe_syn2 */ + Word32 Hilbert_Mem[], /* i/o: memory st_fx->prev_Q_bwe_syn2 */ + Word16 state_lsyn_filt_shb_local[], /* i/o: memory st_fx->prev_Q_bwe_syn2*/ Word16 mem_resamp_HB_32k[], /* i/o: memory */ Word16 *syn_dm_phase, Word32 target_fs, @@ -5446,7 +5445,7 @@ void td_bwe_dec_init_fx( const Word32 output_Fs /* i : output sampling rate */ ) { - int16_t i; + Word16 i; /* init. SHB buffers */; InitSWBdecBuffer_fx( st_fx ); @@ -5469,7 +5468,7 @@ void td_bwe_dec_init_fx( hBWE_TD->tilt_mem_fx = 0; move16(); - set16_fx( hBWE_TD->prev_lsf_diff_fx, 16384, LPC_SHB_ORDER - 2 ); + set16_fx( hBWE_TD->prev_lsf_diff_fx, 16384 /*0.5f in Q15*/, LPC_SHB_ORDER - 2 ); hBWE_TD->prev_tilt_para_fx = 0; move16(); set16_fx( hBWE_TD->cur_sub_Aq_fx, 0, M + 1 ); @@ -5503,10 +5502,8 @@ void td_bwe_dec_init_fx( hBWE_TD->fb_tbe_demph_fx = 0; move16(); - set16_fx( hBWE_TD->old_hb_synth_fx, 0, L_FRAME48k ); - hBWE_TD->prev_ener_fx = L_deposit_l( 0 ); move32(); diff --git a/lib_dec/syn_outp.c b/lib_dec/syn_outp.c index 65e36bc61..31cd8b109 100644 --- a/lib_dec/syn_outp.c +++ b/lib_dec/syn_outp.c @@ -47,7 +47,7 @@ * Output synthesis signal with compensation for saturation * returns number of clipped samples *-------------------------------------------------------------------*/ - +#ifndef IVAS_FLOAT_FIXED /*! r: number of clipped samples */ uint32_t syn_output( float *synth, /* i/o: float synthesis signal */ @@ -133,3 +133,4 @@ void AGC_dec( return; } +#endif diff --git a/lib_dec/syn_outp_fx.c b/lib_dec/syn_outp_fx.c index 7d51c4341..0d84c0c88 100644 --- a/lib_dec/syn_outp_fx.c +++ b/lib_dec/syn_outp_fx.c @@ -15,11 +15,11 @@ *-------------------------------------------------------------------*/ void syn_output_fx( - const Word16 codec_mode, /* i : MODE1 or MODE2 */ - Word16 *synth, /* i/o: fixed point synthesis signal */ - const Word16 output_frame, /* i : output frame length */ - Word16 *synth_out, /* o : integer 16 bits synthesis signal */ - const Word16 Q_syn2 /* i : Synthesis scaling factor */ + const Word16 codec_mode, /* i : MODE1 or MODE2 Q0 */ + Word16 *synth, /* i/o: fixed point synthesis signal Q_syn2 */ + const Word16 output_frame, /* i : output frame length Q0 */ + Word16 *synth_out, /* o : integer 16 bits synthesis signal Q_syn2 */ + const Word16 Q_syn2 /* i : Synthesis scaling factor */ ) { Word16 i, tmp; @@ -66,7 +66,7 @@ void unscale_AGC( const Word16 x[], /* i: 16kHz synthesis Qx */ const Word16 Qx, /* i: scale factor of x */ Word16 y[], /* o: output vector Q0 */ - Word16 mem[], /* i/o: mem[2] should be init to [0,0] */ + Word16 mem[], /* i/o: mem[2] should be init to [0,0] Q0 */ const Word16 n /* i: vector size */ ) { @@ -97,16 +97,16 @@ void unscale_AGC( move16(); IF( GT_16( max_val, tmp ) ) { - frame_fac = sub( 16384, div_s( shr( tmp, 1 ), max_val ) ); /* frame fac in Q15 */ + frame_fac = sub( 16384 /*0.5f in Q15*/, div_s( shr( tmp, 1 ), max_val ) ); /* frame fac in Q15 */ } /*----------------------------------------------------------------* * AGC *----------------------------------------------------------------*/ /* update AGC factor (slowly) */ - fac = mac_r( L_mult( 32440, mem[0] ), 328, frame_fac ); + fac = mac_r( L_mult( 32440 /*0.99f in Q15*/, mem[0] ) /*Q14*/, 328 /*0.01f in Q15*/, frame_fac /*Q15*/ ); - L_tmp = L_mult( x[0], 16384 ); + L_tmp = L_mult( x[0], 16384 /*1.0f in Q14*/ ); // Q13 L_tmp = L_msu0( L_tmp, fac, x[0] ); L_tmp = L_msu( L_tmp, fac, mem[1] ); L_tmp = L_shr( L_tmp, -1 ); /* saturation can occur here */ diff --git a/lib_dec/tcq_core_dec_fx.c b/lib_dec/tcq_core_dec_fx.c index 41c83c71e..0432f02a5 100644 --- a/lib_dec/tcq_core_dec_fx.c +++ b/lib_dec/tcq_core_dec_fx.c @@ -16,20 +16,21 @@ #ifdef IVAS_FLOAT_FIXED void tcq_core_LR_dec_fx( Decoder_State *st_fx, - Word16 *inp_vector_fx, /* x5 */ - const Word16 bit_budget, - const Word16 BANDS, - const Word16 *band_start, - const Word16 *band_width, - Word32 *Rk_fx, /* Q16 */ - Word16 *npulses, - Word16 *k_sort, - const Word16 *p2a_flags, - const Word16 p2a_bands, - const Word16 *last_bitalloc, - const Word16 input_frame, - const Word16 adjustFlag, - const Word16 *is_transient ) + Word16 *inp_vector_fx, /*Qx */ + const Word16 bit_budget, /*Q0 */ + const Word16 BANDS, /*Q0 */ + const Word16 *band_start, /*Q0 */ + const Word16 *band_width, /*Q0 */ + Word32 *Rk_fx, /*Q16*/ + Word16 *npulses, /*Q0 */ + Word16 *k_sort, /*Q0 */ + const Word16 *p2a_flags, /*Q0 */ + const Word16 p2a_bands, /*Q0 */ + const Word16 *last_bitalloc, /*Q0 */ + const Word16 input_frame, /*Q0 */ + const Word16 adjustFlag, /*Q0 */ + const Word16 *is_transient /*Q0 */ +) { Word16 i, j, k; Word32 Rk_sort_fx[NB_SFM]; @@ -141,7 +142,7 @@ void tcq_core_LR_dec_fx( { IF( Rk_fx[j] > 0 ) { - Rk_fx[j] = L_sub( Rk_fx[j], ar_div( bsub_fx, nzb ) ); + Rk_fx[j] = L_sub( Rk_fx[j], ar_div( bsub_fx, nzb ) ); /*Q16*/ move32(); IF( Rk_fx[j] < 0 ) { @@ -201,7 +202,7 @@ void tcq_core_LR_dec_fx( IF( LE_16( input_frame, L_FRAME16k ) && ( adjustFlag == 0 ) && ( *is_transient == 0 ) ) { surplus_fx = -131072; - move32(); /*16 */ + move32(); /*2 in Q16 */ bit_allocation_second_fx( Rk_fx, Rk_sort_fx, BANDS, band_width, k_sort, k_num, p2a_flags, p2a_bands, last_bitalloc, input_frame ); @@ -244,7 +245,7 @@ void tcq_core_LR_dec_fx( move16(); FOR( i = 0; i < band_width[k_sort[k]]; i++ ) { - inp_vector_fx[add( band_start[k_sort[k]], i )] = 0; + inp_vector_fx[band_start[k_sort[k]] + i] = 0; move16(); } IF( surplus_fx != 0 ) @@ -266,7 +267,7 @@ void tcq_core_LR_dec_fx( decode_mangitude_tcq_fx( pardec_fx, band_width[k_sort[k]], pulsesnum, nz, &positions_fx[band_start[k_sort[k]]], &inp_vector_fx[band_start[k_sort[k]]], &surplus_fx ); decode_signs_fx( pardec_fx, band_width[k_sort[k]], &inp_vector_fx[band_start[k_sort[k]]] ); } - nzbands--; + nzbands = sub( nzbands, 1 ); move16(); } ELSE IF( ( Rk_fx[k_sort[k]] > 0 ) && EQ_16( USQ_TCQ[k_sort[k]], 1 ) ) @@ -282,7 +283,7 @@ void tcq_core_LR_dec_fx( move16(); FOR( i = 0; i < band_width[k_sort[k]]; i++ ) { - inp_vector_fx[add( band_start[k_sort[k]], i )] = 0; + inp_vector_fx[band_start[k_sort[k]] + i] = 0; move16(); } IF( surplus_fx != 0 ) @@ -302,7 +303,7 @@ void tcq_core_LR_dec_fx( decode_magnitude_usq_fx( pardec_fx, band_width[k_sort[k]], pulsesnum, nz, &positions_fx[band_start[k_sort[k]]], &inp_vector_fx[band_start[k_sort[k]]] ); decode_signs_fx( pardec_fx, band_width[k_sort[k]], &inp_vector_fx[band_start[k_sort[k]]] ); } - nzbands--; + nzbands = sub( nzbands, 1 ); move16(); } ELSE @@ -311,7 +312,7 @@ void tcq_core_LR_dec_fx( move16(); FOR( i = 0; i < band_width[k_sort[k]]; i++ ) { - inp_vector_fx[add( band_start[k_sort[k]], i )] = 0; + inp_vector_fx[band_start[k_sort[k]] + i] = 0; move16(); } } @@ -403,7 +404,7 @@ void tcq_core_LR_dec_fx( move16(); FOR( i = 0; i < band_width[k_sort[k]]; i++ ) { - inp_vector_fx[add( band_start[k_sort[k]], i )] = 0; + inp_vector_fx[band_start[k_sort[k]] + i] = 0; move16(); } } @@ -436,7 +437,7 @@ void tcq_core_LR_dec_fx( move16(); FOR( i = 0; i < band_width[k_sort[k]]; i++ ) { - inp_vector_fx[add( band_start[k_sort[k]], i )] = 0; + inp_vector_fx[band_start[k_sort[k]] + i] = 0; move16(); } } diff --git a/lib_dec/tcx_utils_dec_fx.c b/lib_dec/tcx_utils_dec_fx.c index e4b56eca9..1c7bee57b 100644 --- a/lib_dec/tcx_utils_dec_fx.c +++ b/lib_dec/tcx_utils_dec_fx.c @@ -20,11 +20,11 @@ * *--------------------------------------------------------------*/ void tcx_decoder_memory_update( - Word16 *xn_buf, /* i/o: mdct output buffer used also as temporary buffer */ - Word16 *synthout, /* o: synth */ - Word16 *A, /* i: Quantized LPC coefficients */ - Decoder_State *st, /* i/o: decoder memory state */ - Word8 fb /* i: fullband flag */ + Word16 *xn_buf, /* i/o: mdct output buffer used also as temporary buffer : Q0 */ + Word16 *synthout, /* o: synth : Q0 */ + Word16 *A, /* i: Quantized LPC coefficients : Q12*/ + Decoder_State *st, /* i/o: decoder memory state */ + Word8 fb /* i: fullband flag */ ) { Word16 tmp; @@ -35,7 +35,7 @@ void tcx_decoder_memory_update( L_frame_glob = st->L_frame; move16(); - preemph = st->preemph_fac; + preemph = st->preemph_fac; // Q15 move16(); /* Output synth */ @@ -105,7 +105,7 @@ void tcx_decoder_memory_update( Residu3_fx( A, synth, st->old_exc_fx + sub( L_EXC_MEM_DEC, L_frame_glob ), L_frame_glob, 1 ); } /* Update old_Aq */ - Copy( A, st->old_Aq_12_8_fx, M + 1 ); + Copy( A, st->old_Aq_12_8_fx /*Q12*/, M + 1 ); #ifdef FIX_778_STEREO_BRATE_SWITCHING } #endif @@ -116,27 +116,22 @@ void tcx_decoder_memory_update( /* Returns: number of bits used (including "bits") */ Word16 tcx_ari_res_invQ_spec( - Word32 x_Q[], /* i/o: quantized spectrum Q31-e */ - Word16 x_Q_e, /* i: quantized spectrum exponent Q0 */ - Word16 L_frame, /* i: number of lines Q0 */ - const Word16 prm[], /* i: bitstream Q0 */ - Word16 target_bits, /* i: number of bits available Q0 */ - Word16 bits, /* i: number of bits used so far Q0 */ - Word16 deadzone, /* i: quantizer deadzone Q15 */ - const Word16 x_fac[] /* i: spectrum post-quantization factors Q14 */ + Word32 x_Q[], /* i/o: quantized spectrum Q(31-x_Q_e) */ + Word16 x_Q_e, /* i: quantized spectrum exponent Q0 */ + Word16 L_frame, /* i: number of lines Q0 */ + const Word16 prm[], /* i: bitstream Q0 */ + Word16 target_bits, /* i: number of bits available Q0 */ + Word16 bits, /* i: number of bits used so far Q0 */ + Word16 deadzone, /* i: quantizer deadzone Q15 */ + const Word16 x_fac[] /* i: spectrum post-quantization factors Q14 */ ) { - Word16 i, j, num_zeros; - Word16 zeros[L_FRAME_PLUS]; - Word16 fac_p, sign; + Word16 i, j, num_zeros, zeros[L_FRAME_PLUS], fac_p, sign, s; Word32 L_tmp; - Word16 s; - /* Limit the number of residual bits */ target_bits = s_min( target_bits, NPRM_RESQ ); - /* Requantize the spectrum line-by-line */ /* fac_m = deadzone * 0.5f; */ num_zeros = 0; @@ -157,7 +152,7 @@ Word16 tcx_ari_res_invQ_spec( sign = negate( sign ); /* x_Q[i] += sign*(prm[bits++] * 0.5f - fac_m); */ - x_Q[i] = L_sub( x_Q[i], L_shr( L_mult( sign, add( deadzone, lshl( prm[bits], 15 ) ) ), x_Q_e ) ); + x_Q[i] = L_sub( x_Q[i], L_shr( L_mult( sign, add( deadzone, lshl( prm[bits], 15 ) ) ), x_Q_e ) ); // x_Q_e move32(); bits = add( bits, 1 ); } @@ -196,7 +191,6 @@ Word16 tcx_ari_res_invQ_spec( bits = add( bits, 1 ); } - return bits; } /*--------------------------------------------------------------- @@ -205,14 +199,13 @@ Word16 tcx_ari_res_invQ_spec( * *--------------------------------------------------------------*/ Word16 tcx_res_invQ_gain( - Word16 *gain_tcx, + Word16 *gain_tcx, /* i/o : gain_tcx_e*/ Word16 *gain_tcx_e, - Word16 *prm, - Word16 resQBits ) + Word16 *prm, /*i : Q0 */ + Word16 resQBits /*i : Q0 */ +) { - Word16 bits; - Word16 gain, tmp1, tmp2; - + Word16 bits, gain, tmp1, tmp2; gain = *gain_tcx; move16(); @@ -255,14 +248,14 @@ Word16 tcx_res_invQ_gain( * *--------------------------------------------------------------*/ Word16 tcx_res_invQ_spec( - Word32 *x, + Word32 *x, /*Q(31 - x_e)*/ Word16 x_e, Word16 L_frame, Word16 *prm, Word16 resQBits, Word16 bits, - Word16 sq_round, - const Word16 lf_deemph_factors[] ) + Word16 sq_round, /*i : sq deadzone Q15*/ + const Word16 lf_deemph_factors[] /*i : LF deemphasis factors Q14*/ ) { Word16 i; Word16 fac_m, fac_p; @@ -275,9 +268,9 @@ Word16 tcx_res_invQ_spec( /* Requantize the spectrum line-by-line */ fac_m = shr( sq_round, 1 ); - fac_p = sub( 0x4000, fac_m ); + fac_p = sub( 0x4000 /*0.5f Q15*/, fac_m ); // Q15 - lf_deemph_factor = 0x4000; + lf_deemph_factor = 0x4000; /*0.5f Q15*/ move16(); s = sub( x_e, 1 ); @@ -290,11 +283,11 @@ Word16 tcx_res_invQ_spec( test(); test(); - IF( ( x[i] != 0 ) && ( ( lf_deemph_factors == NULL ) || ( GT_16( lf_deemph_factors[i], 0x2000 ) ) ) ) + IF( ( x[i] != 0 ) && ( ( lf_deemph_factors == NULL ) || ( GT_16( lf_deemph_factors[i], 0x2000 /*0.5f in Q14*/ ) ) ) ) { if ( lf_deemph_factors != NULL ) { - lf_deemph_factor = lf_deemph_factors[i]; + lf_deemph_factor = lf_deemph_factors[i]; // Q14 move16(); } @@ -306,13 +299,13 @@ Word16 tcx_res_invQ_spec( move32(); if ( x[i] > 0 ) - tmp = L_mult( fac_m, lf_deemph_factor ); + tmp = L_mult( fac_m, lf_deemph_factor ); // Q14+Q15-1 = Q28 if ( x[i] < 0 ) - tmp = L_mult( fac_p, lf_deemph_factor ); + tmp = L_mult( fac_p, lf_deemph_factor ); // Q14+Q15-1 = Q28 assert( tmp != 0 ); - x[i] = L_sub( x[i], L_shr( tmp, s ) ); + x[i] = L_sub( x[i], L_shr( tmp, s ) ); // Q(31 - x_e) move32(); } ELSE @@ -323,13 +316,13 @@ Word16 tcx_res_invQ_spec( move32(); if ( x[i] > 0 ) - tmp = L_mult( fac_p, lf_deemph_factor ); + tmp = L_mult( fac_p, lf_deemph_factor ); // Q14+Q15-1 = Q28 if ( x[i] < 0 ) - tmp = L_mult( fac_m, lf_deemph_factor ); + tmp = L_mult( fac_m, lf_deemph_factor ); // Q14+Q15-1 = Q28 assert( tmp != 0 ); - x[i] = L_add( x[i], L_shr( tmp, s ) ); + x[i] = L_add( x[i], L_shr( tmp, s ) ); // Q(31 - x_e) move32(); } bits = add( bits, 1 ); @@ -354,11 +347,11 @@ Word16 tcx_res_invQ_spec( { bits = add( bits, 1 ); - tmp = L_mult( 21627 /*1.32f Q14*/, fac_p ); + tmp = L_mult( 21627 /*1.32f Q14*/, fac_p /*Q15*/ ); // Q28 if ( prm[bits] == 0 ) tmp = L_negate( tmp ); - x[i] = L_shr( tmp, s ); + x[i] = L_shr( tmp, s ); // Q(31 - x_e) move32(); } bits = add( bits, 1 ); @@ -367,7 +360,7 @@ Word16 tcx_res_invQ_spec( } ELSE { - c = sub( 21627 /*0.66f Q15*/, mult_r( sq_round, 21627 /*0.66f Q15*/ ) ); + c = sub( 21627 /*0.66f Q15*/, mult_r( sq_round, 21627 /*0.66f Q15*/ ) ); // Q15 FOR( i = 0; i < L_frame; i++ ) { @@ -383,11 +376,11 @@ Word16 tcx_res_invQ_spec( { bits = add( bits, 1 ); - tmp = L_mult( c, lf_deemph_factors[i] ); + tmp = L_mult( c, lf_deemph_factors[i] ); // Q28 if ( prm[bits] == 0 ) tmp = L_negate( tmp ); - x[i] = L_shr( tmp, s ); + x[i] = L_shr( tmp, s ); // Q(31 - x_e) move32(); } bits = add( bits, 1 ); diff --git a/lib_dec/tns_base_dec_fx.c b/lib_dec/tns_base_dec_fx.c index 4f44dab85..4a68a49c2 100644 --- a/lib_dec/tns_base_dec_fx.c +++ b/lib_dec/tns_base_dec_fx.c @@ -35,9 +35,10 @@ Word16 ReadTnsData( STnsConfig const *pTnsConfig, Decoder_State *st, - Word16 *pnBits, - Word16 *stream, - Word16 *pnSize ) + Word16 *pnBits, /*Q0*/ + Word16 *stream, /*Q0*/ + Word16 *pnSize /*Q0*/ +) { Word16 start_bit_pos; @@ -97,13 +98,13 @@ Word16 ReadTnsData_ivas_fx( STnsConfig const *pTnsConfig, Decoder_State *st, - Word16 *pnBits, - Word16 *stream, - Word16 *pnSize ) + Word16 *pnBits, /*Q0*/ + Word16 *stream, /*Q0*/ + Word16 *pnSize /*Q0*/ +) { Word16 start_bit_pos; - move16(); start_bit_pos = st->next_bit_pos; @@ -143,7 +144,6 @@ ReadTnsData_ivas_fx( move16(); *pnBits = sub( st->next_bit_pos, start_bit_pos ); - #ifdef IVAS_CODE return; #else @@ -159,8 +159,8 @@ ReadTnsData_ivas_fx( Word16 DecodeTnsData( STnsConfig const *pTnsConfig, - Word16 const *stream, - Word16 *pnSize, + Word16 const *stream, /*Q0*/ + Word16 *pnSize, /*Q0*/ STnsData *pTnsData ) { Word16 result; @@ -215,8 +215,8 @@ Word16 DecodeTnsData( Word16 DecodeTnsData_ivas_fx( STnsConfig const *pTnsConfig, - Word16 const *stream, - Word16 *pnSize, + Word16 const *stream, /*Q0*/ + Word16 *pnSize, /*Q0*/ STnsData *pTnsData ) { Word16 result; diff --git a/lib_enc/ivas_core_enc.c b/lib_enc/ivas_core_enc.c index d601c6fa2..48e175a43 100644 --- a/lib_enc/ivas_core_enc.c +++ b/lib_enc/ivas_core_enc.c @@ -114,8 +114,8 @@ ivas_error ivas_core_enc( Word32 bwe_exc_extended_fx[CPE_CHANNELS][L_FRAME32k + NL_BUFF_OFFSET]; /* 2 * Q_new */ Word16 voice_factors_fx[CPE_CHANNELS][NB_SUBFR16k]; /* Q15 */ Word16 old_syn_12k8_16k_fx[CPE_CHANNELS][L_FRAME16k]; /* ACELP core synthesis at 12.8kHz or 16kHz to be used by the SWB BWE */ - Word16 *new_swb_speech_fx1; - Word16 new_swb_speech_buffer_fx1[L_FRAME48k + STEREO_DFT_OVL_MAX]; + Word16 *new_swb_speech_fx_16; + Word16 new_swb_speech_buffer_fx_16[L_FRAME48k + STEREO_DFT_OVL_MAX]; #endif int16_t Voicing_flag[CPE_CHANNELS]; #ifdef IVAS_FLOAT_FIXED_CONVERSIONS // required for float fixed conversions @@ -140,6 +140,9 @@ ivas_error ivas_core_enc( Word16 i; #endif + set32_fx( new_swb_speech_buffer_fx, 0, L_FRAME48k + STEREO_DFT_OVL_MAX ); + set16_fx( new_swb_speech_buffer_fx_16, 0, L_FRAME48k + STEREO_DFT_OVL_MAX ); + #ifdef MSAN_FIX FOR( i = 0; i < CPE_CHANNELS; i++ ) { @@ -906,7 +909,7 @@ ivas_error ivas_core_enc( new_swb_speech = new_swb_speech_buffer + STEREO_DFT_OVL_MAX; #ifdef IVAS_FLOAT_FIXED new_swb_speech_fx = new_swb_speech_buffer_fx + STEREO_DFT_OVL_MAX; - new_swb_speech_fx1 = new_swb_speech_buffer_fx1 + STEREO_DFT_OVL_MAX; + new_swb_speech_fx_16 = new_swb_speech_buffer_fx_16 + STEREO_DFT_OVL_MAX; #endif if ( !st->Opt_SC_VBR && input_Fs >= 32000 && st->hBWE_TD != NULL ) @@ -916,7 +919,7 @@ ivas_error ivas_core_enc( #ifdef IVAS_FLOAT_FIXED_CONVERSIONS Word32 realBuffer_fx[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; Word32 imagBuffer_fx[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; - Word16 new_swb_speech_16_fx[L_FRAME48k] = { 0 }; + // Word16 new_swb_speech_16_fx[L_FRAME48k] = { 0 }; Word16 use_shb32 = 0; Word16 q_realImagBuffer = Q_factor_arrL( (float *) &realBuffer[n][0][0], CLDFB_NO_COL_MAX * CLDFB_NO_CHANNELS_MAX ); q_realImagBuffer = s_min( q_realImagBuffer, Q_factor_arrL( (float *) &imagBuffer[n][0][0], CLDFB_NO_COL_MAX * CLDFB_NO_CHANNELS_MAX ) ); @@ -963,7 +966,7 @@ ivas_error ivas_core_enc( } #endif #endif - swb_pre_proc_ivas_fx( st, new_swb_speech_16_fx, new_swb_speech_fx, shb_speech_fx, shb_speech_fx_32, &use_shb32, realBuffer_fx, imagBuffer_fx, q_realImagBuffer, hCPE ); + swb_pre_proc_ivas_fx( st, new_swb_speech_fx_16, new_swb_speech_fx, shb_speech_fx, shb_speech_fx_32, &use_shb32, realBuffer_fx, imagBuffer_fx, q_realImagBuffer, hCPE ); #ifdef IVAS_FLOAT_FIXED_CONVERSIONS fixedToFloat_arr( (Word16 *) &st->hBWE_TD->old_speech_shb_fx[0], (float *) &st->hBWE_TD->old_speech_shb[0], 0, L_LOOK_16k + L_SUBFR16k ); fixedToFloat_arr( (Word16 *) &st->hBWE_FD->old_fdbwe_speech_fx[0], (float *) &st->hBWE_FD->old_fdbwe_speech[0], 0, L_FRAME48k ); @@ -973,7 +976,7 @@ ivas_error ivas_core_enc( st->hBWE_FD->old_input[ii] = (Word16) st->hBWE_FD->old_input_fx[ii]; } fixedToFloat_arrL32( (Word32 *) &st->cldfbSynTd->cldfb_state_fx[0], (float *) &st->cldfbSynTd->cldfb_state[0], q_realImagBuffer, st->cldfbSynTd->p_filter_length ); - fixedToFloat_arr( new_swb_speech_16_fx, new_swb_speech, 0, L_FRAME48k ); + fixedToFloat_arr( new_swb_speech_fx_16, new_swb_speech, 0, L_FRAME48k ); if ( use_shb32 == 0 ) { fixedToFloat_arr( shb_speech_fx, shb_speech, 0, L_FRAME16k ); @@ -1153,7 +1156,7 @@ ivas_error ivas_core_enc( for ( int ii = 0; ii < L_FRAME48k + STEREO_DFT_OVL_MAX; ii++ ) { - new_swb_speech_buffer_fx1[ii] = (Word16) new_swb_speech_buffer[ii]; + new_swb_speech_buffer_fx_16[ii] = (Word16) new_swb_speech_buffer[ii]; } for ( int ii = 0; ii < NS2SA( 48000, DELAY_FD_BWE_ENC_NS + DELAY_FIR_RESAMPL_NS ); ii++ ) { @@ -1161,7 +1164,7 @@ ivas_error ivas_core_enc( } #endif /* SWB(FB) BWE encoder */ - swb_bwe_enc_ivas_fx( st, last_element_mode, old_inp_12k8_fx, old_inp_16k_fx, old_syn_12k8_16k_fx[n], new_swb_speech_fx1, shb_speech_fx, q_shb_speech_fx, q_val ); + swb_bwe_enc_ivas_fx( st, last_element_mode, old_inp_12k8_fx, old_inp_16k_fx, old_syn_12k8_16k_fx[n], new_swb_speech_fx_16, shb_speech_fx, q_shb_speech_fx, q_val ); #ifdef IVAS_FLOAT_FIXED_CONVERSIONS if ( st->hBWE_FD != NULL ) { diff --git a/lib_enc/ivas_core_pre_proc_front.c b/lib_enc/ivas_core_pre_proc_front.c index 3cdbd36a0..b84e82262 100644 --- a/lib_enc/ivas_core_pre_proc_front.c +++ b/lib_enc/ivas_core_pre_proc_front.c @@ -2128,6 +2128,9 @@ ivas_error pre_proc_front_ivas_fx( } stab_fac = (float) ( (float) stab_fac_fx / 32767.0f ); + + free( old_inp_12k8_loc_fx ); + #endif if ( element_mode == IVAS_CPE_TD && st->idchan == 1 ) { diff --git a/lib_enc/ivas_dirac_enc.c b/lib_enc/ivas_dirac_enc.c index 7891a753b..2a10d92d7 100644 --- a/lib_enc/ivas_dirac_enc.c +++ b/lib_enc/ivas_dirac_enc.c @@ -138,6 +138,21 @@ ivas_error ivas_dirac_enc_open( } set_f( hDirAC->direction_vector_m[i][j], 0.0f, DIRAC_MAX_NBANDS ); } +#ifdef IVAS_FLOAT_FIXED + IF( ( hDirAC->direction_vector_m_fx[i] = (Word32 **) malloc( MAX_PARAM_SPATIAL_SUBFRAMES * sizeof( Word32 * ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); + } + + FOR( j = 0; j < MAX_PARAM_SPATIAL_SUBFRAMES; j++ ) + { + if ( ( hDirAC->direction_vector_m_fx[i][j] = (Word32 *) malloc( DIRAC_MAX_NBANDS * sizeof( Word32 ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); + } + set32_fx( hDirAC->direction_vector_m_fx[i][j], 0, DIRAC_MAX_NBANDS ); + } +#endif } hDirAC->no_col_avg_diff = (int16_t) ( DIRAC_NO_COL_AVG_DIFF_NS / dirac_slot_ns ); @@ -426,6 +441,10 @@ void ivas_dirac_enc_close( { free( hDirAC->direction_vector_m[i][j] ); hDirAC->direction_vector_m[i][j] = NULL; +#ifdef IVAS_FLOAT_FIXED + free( hDirAC->direction_vector_m_fx[i][j] ); + hDirAC->direction_vector_m_fx[i][j] = NULL; +#endif } for ( j = 0; j < hDirAC->no_col_avg_diff; j++ ) @@ -456,6 +475,10 @@ void ivas_dirac_enc_close( free( hDirAC->direction_vector_m[i] ); hDirAC->direction_vector_m[i] = NULL; +#ifdef IVAS_FLOAT_FIXED + free( hDirAC->direction_vector_m_fx[i] ); + hDirAC->direction_vector_m_fx[i] = NULL; +#endif } free( hDirAC->buffer_energy ); @@ -505,7 +528,159 @@ ivas_error ivas_dirac_enc( ivas_error error; push_wmops( "ivas_dirac_enc" ); - ivas_dirac_param_est_enc( hDirAC, hQMetaData->q_direction, hQMetaData->useLowerRes, data_f, ppIn_FR_real, ppIn_FR_imag, input_frame, ivas_format, hodirac_flag, hodirac_flag ? HOA2_CHANNELS : FOA_CHANNELS, &( hDirAC->mono_frame_count ), &( hQMetaData->dirac_mono_flag ) ); +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + /*---------------------------------------------- float to fixed ----------------------------------------------*/ + + set16_fx( (Word16 *) hDirAC->buffer_energy_q, 0, DIRAC_NO_COL_AVG_DIFF * DIRAC_MAX_NBANDS ); + set16_fx( (Word16 *) hDirAC->buffer_intensity_real_q, 0, DIRAC_NUM_DIMS * DIRAC_NO_COL_AVG_DIFF * DIRAC_MAX_NBANDS ); + Word16 block_m_idx; + Word16 band_m_idx; + Word16 nchan_fb_in = hodirac_flag ? HOA2_CHANNELS : FOA_CHANNELS; + Word16 nblocks = hQMetaData->useLowerRes ? 1 : MAX_PARAM_SPATIAL_SUBFRAMES; + + /* Find Q-factor */ + Word16 pcm_q; + Word16 pp_fr_q; + float max_val = 0; + for ( i = 0; i < nchan_fb_in; i++ ) + { + for ( j = 0; j < input_frame; j++ ) + { + max_val = max( max_val, (float) fabs( data_f[i][j] ) ); + } + } + pcm_q = Q_factor_L( max_val ); + + max_val = 0; + for ( i = 0; i < nchan_fb_in; i++ ) + { + for ( j = 0; j < input_frame; j++ ) + { + max_val = max( max_val, (float) fabs( ppIn_FR_real[i][j] ) ); + max_val = max( max_val, (float) fabs( ppIn_FR_imag[i][j] ) ); + } + } + pp_fr_q = Q_factor_L( max_val ); + + Word32 fr_real_fx[DIRAC_MAX_ANA_CHANS][L_FRAME48k * 2]; + Word32 fr_imag_fx[DIRAC_MAX_ANA_CHANS][L_FRAME48k * 2]; + Word32 data_f_buf[DIRAC_MAX_ANA_CHANS][L_FRAME48k]; + Word32 *pp_fr_real_fx[DIRAC_MAX_ANA_CHANS]; + Word32 *pp_fr_imag_fx[DIRAC_MAX_ANA_CHANS]; + Word32 *data_f_fx[DIRAC_MAX_ANA_CHANS]; + for ( i = 0; i < nchan_fb_in; i++ ) + { + data_f_fx[i] = data_f_buf[i]; + pp_fr_real_fx[i] = fr_real_fx[i]; + pp_fr_imag_fx[i] = fr_imag_fx[i]; + for ( j = 0; j < input_frame; j++ ) + { + data_f_fx[i][j] = float_to_fix( data_f[i][j], pcm_q ); + pp_fr_real_fx[i][j] = float_to_fix( ppIn_FR_real[i][j], pp_fr_q ); + pp_fr_imag_fx[i][j] = float_to_fix( ppIn_FR_imag[i][j], pp_fr_q ); + } + } + + for ( i = 0; i < DIRAC_NUM_DIMS; i++ ) + { + for ( j = 0; j < hDirAC->no_col_avg_diff; j++ ) + { + for ( int k = 0; k < hDirAC->hConfig->nbands; k++ ) + { + Word16 tmp; + f2me( hDirAC->buffer_intensity_real[i][j][k], &hDirAC->buffer_intensity_real_fx[i][j][k], &tmp ); + hDirAC->buffer_intensity_real_q[i][j][k] = 31 - tmp; + } + } + } + for ( i = 0; i < hDirAC->hConfig->nbands; i++ ) + { + for ( j = 0; j < hDirAC->no_col_avg_diff; j++ ) + { + Word16 tmp; + f2me( hDirAC->buffer_energy[i + j * hDirAC->hConfig->nbands], &hDirAC->buffer_energy_fx[i + j * hDirAC->hConfig->nbands], &tmp ); + hDirAC->buffer_energy_q[i + j * hDirAC->hConfig->nbands] = 31 - tmp; + } + } + + for ( i = 0; i < NUM_ANA_SECTORS * IVAS_MAX_NUM_BANDS; i++ ) + { + hDirAC->azi_prev_fx[i] = float_to_fix( hDirAC->azi_prev[i], Q23 ); + hDirAC->ele_prev_fx[i] = float_to_fix( hDirAC->ele_prev[i], Q23 ); + } + for ( i = 0; i < NUM_ANA_SECTORS; i++ ) + { + for ( j = 0; j < IVAS_MAX_NUM_BANDS; j++ ) + { + f2me( hDirAC->sec_I_vec_smth_x[i][j], &hDirAC->sec_I_vec_smth_x_fx[i][j], &hDirAC->sec_I_vec_smth_x_exp[i][j] ); + f2me( hDirAC->sec_I_vec_smth_y[i][j], &hDirAC->sec_I_vec_smth_y_fx[i][j], &hDirAC->sec_I_vec_smth_y_exp[i][j] ); + f2me( hDirAC->sec_I_vec_smth_z[i][j], &hDirAC->sec_I_vec_smth_z_fx[i][j], &hDirAC->sec_I_vec_smth_z_exp[i][j] ); + } + } +#endif + ivas_dirac_param_est_enc( hDirAC, hQMetaData->q_direction, hQMetaData->useLowerRes, data_f_fx, pp_fr_real_fx, pp_fr_imag_fx, pp_fr_q, input_frame, ivas_format, hodirac_flag, nchan_fb_in, &( hDirAC->mono_frame_count ), &( hQMetaData->dirac_mono_flag ) ); +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + /*---------------------------------------------- fixed to float ----------------------------------------------*/ + for ( block_m_idx = 0; block_m_idx < nblocks; block_m_idx++ ) + { + for ( band_m_idx = 0; band_m_idx < hDirAC->hConfig->nbands; band_m_idx++ ) + { + hQMetaData->q_direction->band_data[band_m_idx].azimuth[block_m_idx] = fix_to_float( hQMetaData->q_direction->band_data[band_m_idx].azimuth_fx[block_m_idx], Q22 ); + hQMetaData->q_direction->band_data[band_m_idx].elevation[block_m_idx] = fix_to_float( hQMetaData->q_direction->band_data[band_m_idx].elevation_fx[block_m_idx], Q22 ); + if ( hodirac_flag ) + { + hQMetaData->q_direction[1].band_data[band_m_idx].azimuth[block_m_idx] = fix_to_float( hQMetaData->q_direction[1].band_data[band_m_idx].azimuth_fx[block_m_idx], Q22 ); + hQMetaData->q_direction[1].band_data[band_m_idx].elevation[block_m_idx] = fix_to_float( hQMetaData->q_direction[1].band_data[band_m_idx].elevation_fx[block_m_idx], Q22 ); + hQMetaData->q_direction[1].band_data[band_m_idx].energy_ratio[block_m_idx] = fix_to_float( hQMetaData->q_direction[1].band_data[band_m_idx].energy_ratio_fx[block_m_idx], Q30 ); + } + else + { + hDirAC->direction_vector_m[0][block_m_idx][band_m_idx] = me2f( hDirAC->direction_vector_m_fx[0][block_m_idx][band_m_idx], hDirAC->direction_vector_m_exp[block_m_idx] ); + hDirAC->direction_vector_m[1][block_m_idx][band_m_idx] = me2f( hDirAC->direction_vector_m_fx[1][block_m_idx][band_m_idx], hDirAC->direction_vector_m_exp[block_m_idx] ); + hDirAC->direction_vector_m[2][block_m_idx][band_m_idx] = me2f( hDirAC->direction_vector_m_fx[2][block_m_idx][band_m_idx], hDirAC->direction_vector_m_exp[block_m_idx] ); + } + } + } + const int N_bands = hDirAC->hConfig->nbands; + for ( int i_sec = 0; i_sec < NUM_ANA_SECTORS; i_sec++ ) + { + for ( int i_band = 0; i_band < IVAS_MAX_NUM_BANDS; i_band++ ) + { + hDirAC->sec_I_vec_smth_x[i_sec][i_band] = me2f( hDirAC->sec_I_vec_smth_x_fx[i_sec][i_band], hDirAC->sec_I_vec_smth_x_exp[i_sec][i_band] ); + hDirAC->sec_I_vec_smth_y[i_sec][i_band] = me2f( hDirAC->sec_I_vec_smth_y_fx[i_sec][i_band], hDirAC->sec_I_vec_smth_y_exp[i_sec][i_band] ); + hDirAC->sec_I_vec_smth_z[i_sec][i_band] = me2f( hDirAC->sec_I_vec_smth_z_fx[i_sec][i_band], hDirAC->sec_I_vec_smth_z_exp[i_sec][i_band] ); + hDirAC->azi_prev[i_sec * N_bands + i_band] = fix_to_float( hDirAC->azi_prev_fx[i_sec * N_bands + i_band], Q23 ); + hDirAC->ele_prev[i_sec * N_bands + i_band] = fix_to_float( hDirAC->ele_prev_fx[i_sec * N_bands + i_band], Q23 ); + } + for ( int i_band = hDirAC->hConfig->enc_param_start_band; i_band < N_bands; i_band++ ) + { + hDirAC->energy_smth[i_sec][i_band] = me2f( hDirAC->energy_smth_fx[i_sec][i_band], hDirAC->energy_smth_exp[i_sec][i_band] ); + } + } + for ( band_m_idx = 0; band_m_idx < hDirAC->hConfig->nbands; band_m_idx++ ) + { + hDirAC->diffuseness_m[band_m_idx] = me2f( hDirAC->diffuseness_m_fx[band_m_idx], hDirAC->diffuseness_m_exp[band_m_idx] ); + me2f_buf( hQMetaData->q_direction->band_data[band_m_idx].energy_ratio_fx, 1, hQMetaData->q_direction->band_data[band_m_idx].energy_ratio, hQMetaData->q_direction->cfg.nblocks ); + } + for ( i = 0; i < DIRAC_NUM_DIMS; i++ ) + { + for ( j = 0; j < hDirAC->no_col_avg_diff; j++ ) + { + for ( int k = 0; k < N_bands; k++ ) + { + hDirAC->buffer_intensity_real[i][j][k] = me2f( hDirAC->buffer_intensity_real_fx[i][j][k], 31 - hDirAC->buffer_intensity_real_q[i][j][k] ); + } + } + } + for ( i = 0; i < hDirAC->hConfig->nbands; i++ ) + { + for ( j = 0; j < hDirAC->no_col_avg_diff; j++ ) + { + hDirAC->buffer_energy[i + j * hDirAC->hConfig->nbands] = me2f( hDirAC->buffer_energy_fx[i + j * hDirAC->hConfig->nbands], 31 - hDirAC->buffer_energy_q[i + j * hDirAC->hConfig->nbands] ); + } + } +#endif + if ( hQMetaData->q_direction->cfg.nbands > 0 ) { @@ -1400,9 +1575,10 @@ void ivas_dirac_param_est_enc( DIRAC_ENC_HANDLE hDirAC, IVAS_QDIRECTION *q_direction, const UWord8 useLowerRes, - float *data_f[], - float **pp_fr_real, - float **pp_fr_imag, + Word32 *data_f_fx[], + Word32 **pp_fr_real_fx, + Word32 **pp_fr_imag_fx, + Word16 pp_fr_q, const Word16 input_frame, const IVAS_FORMAT ivas_format, const Word16 hodirac_flag, @@ -1410,116 +1586,31 @@ void ivas_dirac_param_est_enc( Word16 *mono_frame_count, Word16 *dirac_mono_flag ) { -#ifdef IVAS_FLOAT_FIXED - Word32 *data_f_fx[DIRAC_MAX_ANA_CHANS]; - Word32 **pp_fr_real_fx; - Word32 **pp_fr_imag_fx; -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - /* Assign memory */ - Word16 nblocks = useLowerRes ? 1 : MAX_PARAM_SPATIAL_SUBFRAMES; - hDirAC->direction_vector_m_fx[0] = (Word32 **) malloc( nblocks * sizeof( Word32 * ) ); - hDirAC->direction_vector_m_fx[1] = (Word32 **) malloc( nblocks * sizeof( Word32 * ) ); - hDirAC->direction_vector_m_fx[2] = (Word32 **) malloc( nblocks * sizeof( Word32 * ) ); - for ( int block_m_idx = 0; block_m_idx < nblocks; block_m_idx++ ) - { - hDirAC->direction_vector_m_fx[0][block_m_idx] = (Word32 *) malloc( hDirAC->hConfig->nbands * sizeof( Word32 ) ); - hDirAC->direction_vector_m_fx[1][block_m_idx] = (Word32 *) malloc( hDirAC->hConfig->nbands * sizeof( Word32 ) ); - hDirAC->direction_vector_m_fx[2][block_m_idx] = (Word32 *) malloc( hDirAC->hConfig->nbands * sizeof( Word32 ) ); - } - - /* Find Q-factor */ - Word16 pcm_q; - Word16 pp_fr_q; - float max_val = 0; - for ( int i = 0; i < nchan_fb_in; i++ ) - { - for ( int j = 0; j < input_frame; j++ ) - { - max_val = max( max_val, (float) fabs( data_f[i][j] ) ); - } - } - pcm_q = Q_factor_L( max_val ); - - max_val = 0; - for ( int i = 0; i < nchan_fb_in; i++ ) - { - for ( int j = 0; j < input_frame; j++ ) - { - max_val = max( max_val, (float) fabs( pp_fr_real[i][j] ) ); - max_val = max( max_val, (float) fabs( pp_fr_imag[i][j] ) ); - } - } - pp_fr_q = Q_factor_L( max_val ); - - /* Float to fixed */ - pp_fr_real_fx = (Word32 **) calloc( nchan_fb_in, sizeof( Word32 * ) ); - pp_fr_imag_fx = (Word32 **) calloc( nchan_fb_in, sizeof( Word32 * ) ); - for ( int i = 0; i < nchan_fb_in; i++ ) - { - data_f_fx[i] = (Word32 *) calloc( input_frame, sizeof( Word32 ) ); - pp_fr_real_fx[i] = (Word32 *) calloc( input_frame, sizeof( Word32 ) ); - pp_fr_imag_fx[i] = (Word32 *) calloc( input_frame, sizeof( Word32 ) ); - for ( int j = 0; j < input_frame; j++ ) - { - data_f_fx[i][j] = float_to_fix( data_f[i][j], pcm_q ); - pp_fr_real_fx[i][j] = float_to_fix( pp_fr_real[i][j], pp_fr_q ); - pp_fr_imag_fx[i][j] = float_to_fix( pp_fr_imag[i][j], pp_fr_q ); - } - } -#endif - - Word16 i, d, ts, index, l_ts, num_freq_bands; + Word16 i, j, k, d, ts, index, l_ts, num_freq_bands; Word16 band_m_idx, block_m_idx; - float dir_v[DIRAC_NUM_DIMS]; -#ifdef IVAS_FLOAT_FIXED Word32 dir_v_fx[DIRAC_NUM_DIMS]; -#endif - float *pcm_in[DIRAC_MAX_ANA_CHANS]; - float Cldfb_RealBuffer[DIRAC_MAX_ANA_CHANS][DIRAC_NO_FB_BANDS_MAX]; - float Cldfb_ImagBuffer[DIRAC_MAX_ANA_CHANS][DIRAC_NO_FB_BANDS_MAX]; -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - for ( i = 0; i < DIRAC_MAX_ANA_CHANS; i++ ) - { - set_zero( Cldfb_RealBuffer[i], DIRAC_NO_FB_BANDS_MAX ); - set_zero( Cldfb_ImagBuffer[i], DIRAC_NO_FB_BANDS_MAX ); - } -#endif - float *p_Cldfb_RealBuffer[DIRAC_MAX_ANA_CHANS]; - float *p_Cldfb_ImagBuffer[DIRAC_MAX_ANA_CHANS]; Word32 *pcm_in_fx[DIRAC_MAX_ANA_CHANS]; Word32 Cldfb_RealBuffer_fx[DIRAC_MAX_ANA_CHANS][DIRAC_NO_FB_BANDS_MAX]; Word32 Cldfb_ImagBuffer_fx[DIRAC_MAX_ANA_CHANS][DIRAC_NO_FB_BANDS_MAX]; Word32 *p_Cldfb_RealBuffer_fx[DIRAC_MAX_ANA_CHANS]; Word32 *p_Cldfb_ImagBuffer_fx[DIRAC_MAX_ANA_CHANS]; Word16 cldfb_q; - float intensity_real[DIRAC_NUM_DIMS][DIRAC_MAX_NBANDS]; -#ifdef IVAS_FLOAT_FIXED Word32 intensity_real_fx[DIRAC_NUM_DIMS][DIRAC_MAX_NBANDS]; - Word16 intensity_real_q = 0; + Word16 intensity_real_q; Word32 direction_vector_fx[DIRAC_NUM_DIMS][DIRAC_MAX_NBANDS]; - Word16 direction_vector_q = 0; + Word16 direction_vector_q; Word32 diffuseness_vector_fx[DIRAC_MAX_NBANDS]; - Word16 diffuseness_vector_q = 0; - move16(); - move16(); - move16(); -#endif - float direction_vector[DIRAC_NUM_DIMS][DIRAC_MAX_NBANDS]; - float diffuseness_vector[DIRAC_MAX_NBANDS]; - float renormalization_factor[DIRAC_MAX_NBANDS]; - float renormalization_factor_diff[DIRAC_MAX_NBANDS]; + Word16 diffuseness_vector_q; Word32 renormalization_factor_fx[DIRAC_MAX_NBANDS]; + Word16 renormalization_factor_exp; Word32 renormalization_factor_diff_fx[DIRAC_MAX_NBANDS]; - float norm_tmp; + Word16 renormalization_factor_diff_exp[DIRAC_MAX_NBANDS]; + Word32 norm_tmp_fx; + Word16 norm_tmp_exp; Word16 mrange[2]; Word16 num_blocks; - float reference_power[CLDFB_NO_COL_MAX][DIRAC_NO_FB_BANDS_MAX]; Word32 reference_power_fx[CLDFB_NO_COL_MAX][DIRAC_NO_FB_BANDS_MAX]; Word16 reference_power_exp; - float azi_secs[2 * DIRAC_MAX_ANA_CHANS * DIRAC_MAX_NBANDS]; - float ele_secs[2 * DIRAC_MAX_ANA_CHANS * DIRAC_MAX_NBANDS]; - float diff_secs[2 * DIRAC_MAX_ANA_CHANS * DIRAC_MAX_NBANDS]; - float ene_secs[2 * DIRAC_MAX_ANA_CHANS * DIRAC_MAX_NBANDS]; Word32 azi_secs_fx[2 * DIRAC_MAX_ANA_CHANS * DIRAC_MAX_NBANDS]; Word32 ele_secs_fx[2 * DIRAC_MAX_ANA_CHANS * DIRAC_MAX_NBANDS]; Word32 diff_secs_fx[2 * DIRAC_MAX_ANA_CHANS * DIRAC_MAX_NBANDS]; @@ -1534,6 +1625,12 @@ void ivas_dirac_param_est_enc( /* Initialization */ cldfb_q = 0; move16(); + intensity_real_q = 0; + move16(); + direction_vector_q = 0; + move16(); + diffuseness_vector_q = 0; + move16(); l_ts = idiv1616( input_frame, MAX_PARAM_SPATIAL_SUBFRAMES ); IF( useLowerRes ) @@ -1553,7 +1650,11 @@ void ivas_dirac_param_est_enc( /* Need to initialize renormalization_factors, direction_m and diffuseness_m */ set_zero_fx( hDirAC->diffuseness_m_fx, hDirAC->hConfig->nbands ); + set16_zero_fx( hDirAC->diffuseness_m_exp, hDirAC->hConfig->nbands ); set_zero_fx( renormalization_factor_diff_fx, hDirAC->hConfig->nbands ); + set16_zero_fx( renormalization_factor_diff_exp, hDirAC->hConfig->nbands ); + reference_power_exp = 0; + move16(); set_zero_fx( azi_secs_fx, 2 * DIRAC_MAX_ANA_CHANS * DIRAC_MAX_NBANDS ); set_zero_fx( ele_secs_fx, 2 * DIRAC_MAX_ANA_CHANS * DIRAC_MAX_NBANDS ); @@ -1563,168 +1664,45 @@ void ivas_dirac_param_est_enc( set16_zero_fx( ene_secs_exp, 2 * DIRAC_MAX_ANA_CHANS * DIRAC_MAX_NBANDS ); /* Copy current frame to memory for delay compensation */ -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - /* assign memory */ - for ( i = 0; i < nchan_fb_in; i++ ) - { - pcm_in[i] = data_f[i]; - p_Cldfb_RealBuffer[i] = &Cldfb_RealBuffer[i][0]; - p_Cldfb_ImagBuffer[i] = &Cldfb_ImagBuffer[i][0]; - } -#endif FOR( i = 0; i < nchan_fb_in; i++ ) { pcm_in_fx[i] = data_f_fx[i]; p_Cldfb_RealBuffer_fx[i] = &Cldfb_RealBuffer_fx[i][0]; p_Cldfb_ImagBuffer_fx[i] = &Cldfb_ImagBuffer_fx[i][0]; } -#if 1 - /* using void temporarily to avoid null */ - (void) p_Cldfb_RealBuffer_fx; - (void) p_Cldfb_ImagBuffer_fx; - (void) p_Cldfb_RealBuffer; - (void) p_Cldfb_ImagBuffer; - (void) pcm_in_fx; - (void) pcm_in; -#endif - -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - /* Fixed to float */ - fixedToFloat_arrL( azi_secs_fx, azi_secs, 0, 2 * DIRAC_MAX_ANA_CHANS * DIRAC_MAX_NBANDS ); - fixedToFloat_arrL( ele_secs_fx, ele_secs, 0, 2 * DIRAC_MAX_ANA_CHANS * DIRAC_MAX_NBANDS ); - fixedToFloat_arrL( diff_secs_fx, diff_secs, 0, 2 * DIRAC_MAX_ANA_CHANS * DIRAC_MAX_NBANDS ); - fixedToFloat_arrL( ene_secs_fx, ene_secs, 0, 2 * DIRAC_MAX_ANA_CHANS * DIRAC_MAX_NBANDS ); - - fixedToFloat_arrL( hDirAC->diffuseness_m_fx, hDirAC->diffuseness_m, 0, hDirAC->hConfig->nbands ); - fixedToFloat_arrL( renormalization_factor_diff_fx, renormalization_factor_diff, 0, hDirAC->hConfig->nbands ); -#endif - -#else - int16_t i, d, ts, index, l_ts, num_freq_bands; - int16_t band_m_idx, block_m_idx; - float dir_v[DIRAC_NUM_DIMS]; - float *pcm_in[DIRAC_MAX_ANA_CHANS]; - float Cldfb_RealBuffer[DIRAC_MAX_ANA_CHANS][DIRAC_NO_FB_BANDS_MAX]; - float Cldfb_ImagBuffer[DIRAC_MAX_ANA_CHANS][DIRAC_NO_FB_BANDS_MAX]; - float *p_Cldfb_RealBuffer[DIRAC_MAX_ANA_CHANS]; - float *p_Cldfb_ImagBuffer[DIRAC_MAX_ANA_CHANS]; - float intensity_real[DIRAC_NUM_DIMS][DIRAC_MAX_NBANDS]; - float direction_vector[DIRAC_NUM_DIMS][DIRAC_MAX_NBANDS]; - float diffuseness_vector[DIRAC_MAX_NBANDS]; - float renormalization_factor[DIRAC_MAX_NBANDS]; - float renormalization_factor_diff[DIRAC_MAX_NBANDS]; - float norm_tmp; - int16_t mrange[2]; - int16_t num_blocks; - float reference_power[CLDFB_NO_COL_MAX][DIRAC_NO_FB_BANDS_MAX]; - float azi_secs[2 * DIRAC_MAX_ANA_CHANS * DIRAC_MAX_NBANDS]; - float ele_secs[2 * DIRAC_MAX_ANA_CHANS * DIRAC_MAX_NBANDS]; - float diff_secs[2 * DIRAC_MAX_ANA_CHANS * DIRAC_MAX_NBANDS]; - float ene_secs[2 * DIRAC_MAX_ANA_CHANS * DIRAC_MAX_NBANDS]; - - push_wmops( "dirac_enc_param_est" ); - num_freq_bands = hDirAC->hConfig->nbands; - - /* Initialization */ - l_ts = input_frame / MAX_PARAM_SPATIAL_SUBFRAMES; - if ( useLowerRes ) - { - q_direction->cfg.nblocks = 1; - num_blocks = 1; - } - else - { - q_direction->cfg.nblocks = MAX_PARAM_SPATIAL_SUBFRAMES; - num_blocks = MAX_PARAM_SPATIAL_SUBFRAMES; - } - - /* Need to initialize renormalization_factors, direction_m and diffuseness_m */ - for ( i = 0; i < hDirAC->hConfig->nbands; i++ ) - { - renormalization_factor_diff[i] = 0; - hDirAC->diffuseness_m[i] = 0; - } - - set_zero( azi_secs, 2 * DIRAC_MAX_ANA_CHANS * DIRAC_MAX_NBANDS ); - set_zero( ele_secs, 2 * DIRAC_MAX_ANA_CHANS * DIRAC_MAX_NBANDS ); - set_zero( diff_secs, 2 * DIRAC_MAX_ANA_CHANS * DIRAC_MAX_NBANDS ); - set_zero( ene_secs, 2 * DIRAC_MAX_ANA_CHANS * DIRAC_MAX_NBANDS ); - - /* Copy current frame to memory for delay compensation */ - for ( i = 0; i < nchan_fb_in; i++ ) - { - pcm_in[i] = data_f[i]; - p_Cldfb_RealBuffer[i] = &Cldfb_RealBuffer[i][0]; - p_Cldfb_ImagBuffer[i] = &Cldfb_ImagBuffer[i][0]; - } -#endif /* ifdef IVAS_FLOAT_FIXED */ /* do processing over all CLDFB time slots */ - for ( block_m_idx = 0; block_m_idx < num_blocks; block_m_idx++ ) + FOR( block_m_idx = 0; block_m_idx < num_blocks; block_m_idx++ ) { -#ifdef IVAS_FLOAT_FIXED mrange[0] = hDirAC->block_grouping[block_m_idx]; move16(); mrange[1] = hDirAC->block_grouping[add( block_m_idx, 1 )]; move16(); set32_fx( renormalization_factor_fx, EPSILON_FX, hDirAC->hConfig->nbands ); + renormalization_factor_exp = 0; + move16(); set_zero_fx( hDirAC->direction_vector_m_fx[0][block_m_idx], hDirAC->hConfig->nbands ); set_zero_fx( hDirAC->direction_vector_m_fx[1][block_m_idx], hDirAC->hConfig->nbands ); set_zero_fx( hDirAC->direction_vector_m_fx[2][block_m_idx], hDirAC->hConfig->nbands ); + hDirAC->direction_vector_m_exp[block_m_idx] = 0; + move16(); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - set_f( renormalization_factor, EPSILON, hDirAC->hConfig->nbands ); - fixedToFloat_arrL( hDirAC->direction_vector_m_fx[0][block_m_idx], hDirAC->direction_vector_m[0][block_m_idx], 0, hDirAC->hConfig->nbands ); - fixedToFloat_arrL( hDirAC->direction_vector_m_fx[1][block_m_idx], hDirAC->direction_vector_m[1][block_m_idx], 0, hDirAC->hConfig->nbands ); - fixedToFloat_arrL( hDirAC->direction_vector_m_fx[2][block_m_idx], hDirAC->direction_vector_m[2][block_m_idx], 0, hDirAC->hConfig->nbands ); -#endif + FOR( ts = mrange[0]; ts < mrange[1]; ts++ ) + { + IF( hDirAC->hFbMixer ) + { + ivas_fb_mixer_get_windowed_fr_fx( hDirAC->hFbMixer, pcm_in_fx, p_Cldfb_RealBuffer_fx, p_Cldfb_ImagBuffer_fx, l_ts, l_ts, hDirAC->hFbMixer->fb_cfg->num_in_chans, 0 ); -#else - mrange[0] = hDirAC->block_grouping[block_m_idx]; - mrange[1] = hDirAC->block_grouping[block_m_idx + 1]; - - for ( band_m_idx = 0; band_m_idx < hDirAC->hConfig->nbands; band_m_idx++ ) - { - renormalization_factor[band_m_idx] = EPSILON; - hDirAC->direction_vector_m[0][block_m_idx][band_m_idx] = 0; - hDirAC->direction_vector_m[1][block_m_idx][band_m_idx] = 0; - hDirAC->direction_vector_m[2][block_m_idx][band_m_idx] = 0; - } -#endif - - for ( ts = mrange[0]; ts < mrange[1]; ts++ ) - { - if ( hDirAC->hFbMixer ) - { -#ifdef IVAS_FLOAT_FIXED - ivas_fb_mixer_get_windowed_fr_fx( hDirAC->hFbMixer, pcm_in_fx, p_Cldfb_RealBuffer_fx, p_Cldfb_ImagBuffer_fx, l_ts, l_ts, hDirAC->hFbMixer->fb_cfg->num_in_chans, 0 ); - - ivas_fb_mixer_update_prior_input_fx( hDirAC->hFbMixer, pcm_in_fx, l_ts, hDirAC->hFbMixer->fb_cfg->num_in_chans ); + ivas_fb_mixer_update_prior_input_fx( hDirAC->hFbMixer, pcm_in_fx, l_ts, hDirAC->hFbMixer->fb_cfg->num_in_chans ); FOR( i = 0; i < nchan_fb_in; i++ ) { pcm_in_fx[i] += l_ts; } -#else - ivas_fb_mixer_get_windowed_fr( hDirAC->hFbMixer, pcm_in, p_Cldfb_RealBuffer, p_Cldfb_ImagBuffer, l_ts, l_ts, hDirAC->hFbMixer->fb_cfg->num_in_chans ); - - ivas_fb_mixer_update_prior_input( hDirAC->hFbMixer, pcm_in, l_ts, hDirAC->hFbMixer->fb_cfg->num_in_chans ); - - for ( i = 0; i < nchan_fb_in; i++ ) - { - pcm_in[i] += l_ts; - } -#endif } - else + ELSE { -#ifdef IVAS_FLOAT_FIXED - for ( i = 0; i < nchan_fb_in; i++ ) - { - mvr2r( &pp_fr_real[i][ts * l_ts], Cldfb_RealBuffer[i], l_ts ); - mvr2r( &pp_fr_imag[i][ts * l_ts], Cldfb_ImagBuffer[i], l_ts ); - } FOR( i = 0; i < nchan_fb_in; i++ ) { Copy32( &pp_fr_real_fx[i][imult1616( ts, l_ts )], Cldfb_RealBuffer_fx[i], l_ts ); @@ -1732,94 +1710,31 @@ void ivas_dirac_param_est_enc( } cldfb_q = pp_fr_q; move16(); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - FOR( i = 0; i < nchan_fb_in; i++ ) - { - fixedToFloat_arrL( Cldfb_ImagBuffer_fx[i], Cldfb_ImagBuffer[i], cldfb_q, l_ts ); - fixedToFloat_arrL( Cldfb_RealBuffer_fx[i], Cldfb_RealBuffer[i], cldfb_q, l_ts ); - } -#endif -#else - for ( i = 0; i < nchan_fb_in; i++ ) - { - mvr2r( &pp_fr_real[i][ts * l_ts], Cldfb_RealBuffer[i], l_ts ); - mvr2r( &pp_fr_imag[i][ts * l_ts], Cldfb_ImagBuffer[i], l_ts ); - } -#endif - } - -#ifndef IVAS_FLOAT_FIXED - computeReferencePower_enc( - hDirAC->band_grouping, - Cldfb_RealBuffer, - Cldfb_ImagBuffer, - reference_power[ts], - hDirAC->hConfig->enc_param_start_band, - num_freq_bands, - ivas_format, - hodirac_flag ? 0 : 1, - FOA_CHANNELS, - mono_frame_count, - dirac_mono_flag ); -#else -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - Word16 Q_Cldfb = 31; - FOR( Word16 x = 0; x < FOA_CHANNELS; x++ ) - { - FOR( Word16 k = 0; k < DIRAC_NO_FB_BANDS_MAX; k++ ) - { - Q_Cldfb = s_min( Q_Cldfb, Q_factor_L( Cldfb_RealBuffer[x][k] ) ); - } - } - Word16 guard = find_guarded_bits_fx( 16 ) / 2; // Guard bits to avoid the precision loss for the reference_power - Word16 e_reference; - - FOR( Word16 k = 0; k < FOA_CHANNELS; k++ ) - { - floatToFixed_arrL( Cldfb_RealBuffer[k], Cldfb_RealBuffer_fx[k], Q_Cldfb, DIRAC_NO_FB_BANDS_MAX ); - } - - FOR( Word16 k = 0; k < FOA_CHANNELS; k++ ) - { - floatToFixed_arrL( Cldfb_ImagBuffer[k], Cldfb_ImagBuffer_fx[k], Q_Cldfb, DIRAC_NO_FB_BANDS_MAX ); - } - - FOR( Word16 x = 0; x < FOA_CHANNELS; x++ ) - { - FOR( Word16 k = 0; k < DIRAC_NO_FB_BANDS_MAX; k++ ) - { - Cldfb_RealBuffer_fx[x][k] = L_shr( Cldfb_RealBuffer_fx[x][k], guard ); - Cldfb_ImagBuffer_fx[x][k] = L_shr( Cldfb_ImagBuffer_fx[x][k], guard ); - } } - Q_Cldfb = sub( Q_Cldfb, guard ); - Word16 hodirac_flag_temp = 1; + Word16 ref_power_w = 1; + move16(); IF( hodirac_flag ) { - hodirac_flag_temp = 0; + ref_power_w = 0; + move16(); } -#endif + computeReferencePower_enc_fx_dirac( hDirAC->band_grouping, Cldfb_RealBuffer_fx, Cldfb_ImagBuffer_fx, - sub( 31, Q_Cldfb ), + sub( 31, cldfb_q ), reference_power_fx[ts], - &e_reference, + &reference_power_exp, hDirAC->hConfig->enc_param_start_band, num_freq_bands, ivas_format, - hodirac_flag_temp, + ref_power_w, FOA_CHANNELS, mono_frame_count, dirac_mono_flag ); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - fixedToFloat_arrL( reference_power_fx[ts], reference_power[ts], 31 - e_reference, DIRAC_NO_FB_BANDS_MAX ); -#endif -#endif -#ifdef IVAS_FLOAT_FIXED computeIntensityVector_enc_fx( hDirAC, Cldfb_RealBuffer_fx, @@ -1828,29 +1743,10 @@ void ivas_dirac_param_est_enc( num_freq_bands, intensity_real_fx ); - // intensity_real_q = 2 * Q_Cldfb + 1 - 32; - intensity_real_q = sub( shl( Q_Cldfb, 1 ), 31 ); - move16(); - -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - for ( i = 0; i < DIRAC_NUM_DIMS; i++ ) - { - fixedToFloat_arrL( intensity_real_fx[i], intensity_real[i], intensity_real_q, num_freq_bands ); - } -#endif -#else - computeIntensityVector_enc( - hDirAC, - Cldfb_RealBuffer, - Cldfb_ImagBuffer, - hDirAC->hConfig->enc_param_start_band, - num_freq_bands, - intensity_real ); -#endif + intensity_real_q = sub( shl( cldfb_q, 1 ), 31 ); // 2 * Q_Cldfb + 1 - 32; - if ( !hodirac_flag ) + IF( !hodirac_flag ) { -#ifdef IVAS_FLOAT_FIXED computeDirectionVectors_fixed( intensity_real_fx[0], intensity_real_fx[1], @@ -1864,153 +1760,71 @@ void ivas_dirac_param_est_enc( direction_vector_q = Q30; move16(); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - for ( i = 0; i < DIRAC_NUM_DIMS; i++ ) - { - fixedToFloat_arrL( direction_vector_fx[i], direction_vector[i], direction_vector_q, num_freq_bands ); - } -#endif -#else - computeDirectionVectors( - intensity_real[0], - intensity_real[1], - intensity_real[2], - hDirAC->hConfig->enc_param_start_band, - num_freq_bands, - direction_vector[0], - direction_vector[1], - direction_vector[2] ); -#endif } -#ifdef IVAS_FLOAT_FIXED -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS -#define MAX_NUM_INDEX_INTENSITY ( 10 ) /* NOTE: arbitrary value. need to check exact max value of "index"*/ - Word32 buffer_intensity_real_fx[DIRAC_NUM_DIMS][MAX_NUM_INDEX_INTENSITY][DIRAC_MAX_NBANDS]; - Word32 buffer_energy_fx[MAX_NUM_INDEX_INTENSITY * DIRAC_MAX_NBANDS]; - max_val = 0; - Word32 tmp32; - for ( i = 0; i < DIRAC_NUM_DIMS; i++ ) - { - float tmpf; - maximumAbs( intensity_real[i], num_freq_bands, &tmpf ); - max_val = fmaxf( max_val, tmpf ); - } - Word16 intensity_real_exp; - f2me( max_val, &tmp32, &intensity_real_exp ); - for ( i = 0; i < DIRAC_NUM_DIMS; i++ ) - { - for ( int j = 0; j < num_freq_bands; j++ ) - { - intensity_real_fx[i][j] = (Word32) ( intensity_real[i][j] * powf( 2, 31.f - intensity_real_exp ) ); - } - } - f2me_buf( reference_power[ts], reference_power_fx[ts], &reference_power_exp, num_freq_bands ); -#endif /* fill buffers of length "averaging_length" time slots for intensity and energy */ hDirAC->index_buffer_intensity = add( ( hDirAC->index_buffer_intensity % hDirAC->no_col_avg_diff ), 1 ); /* averaging_length = 32 */ move16(); index = hDirAC->index_buffer_intensity; move16(); - assert( index <= MAX_NUM_INDEX_INTENSITY ); FOR( i = 0; i < DIRAC_NUM_DIMS; i++ ) { /* only real part needed */ - Copy32( intensity_real_fx[i], &( buffer_intensity_real_fx[i][sub( index, 1 )][0] ), num_freq_bands ); + Copy32( intensity_real_fx[i], &( hDirAC->buffer_intensity_real_fx[i][index - 1][0] ), num_freq_bands ); + set16_fx( &hDirAC->buffer_intensity_real_q[i][index - 1][0], intensity_real_q, num_freq_bands ); } - Copy32( reference_power_fx[ts], &( buffer_energy_fx[imult1616( sub( index, 1 ), num_freq_bands )] ), num_freq_bands ); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + Copy32( reference_power_fx[ts], &( hDirAC->buffer_energy_fx[( index - 1 ) * num_freq_bands] ), num_freq_bands ); + set16_fx( &hDirAC->buffer_energy_q[( index - 1 ) * num_freq_bands], sub( 31, reference_power_exp ), num_freq_bands ); + + Word16 buffer_intensity_real_single_q; + buffer_intensity_real_single_q = hDirAC->buffer_intensity_real_q[0][0][0]; + move16(); FOR( i = 0; i < DIRAC_NUM_DIMS; i++ ) { - me2f_buf( &buffer_intensity_real_fx[i][index - 1][0], intensity_real_exp, &hDirAC->buffer_intensity_real[i][index - 1][0], num_freq_bands ); - } - me2f_buf( &buffer_energy_fx[( index - 1 ) * num_freq_bands], reference_power_exp, &hDirAC->buffer_energy[( index - 1 ) * num_freq_bands], num_freq_bands ); -#endif -#else - /* fill buffers of length "averaging_length" time slots for intensity and energy */ - hDirAC->index_buffer_intensity = ( hDirAC->index_buffer_intensity % hDirAC->no_col_avg_diff ) + 1; /* averaging_length = 32 */ - index = hDirAC->index_buffer_intensity; - for ( i = 0; i < DIRAC_NUM_DIMS; i++ ) - { - /* only real part needed */ - mvr2r( intensity_real[i], &( hDirAC->buffer_intensity_real[i][index - 1][0] ), num_freq_bands ); + FOR( j = 0; j < hDirAC->no_col_avg_diff; j++ ) + { + FOR( k = 0; k < num_freq_bands; k++ ) + { + buffer_intensity_real_single_q = s_min( buffer_intensity_real_single_q, hDirAC->buffer_intensity_real_q[i][j][k] ); + } + } } - mvr2r( reference_power[ts], &( hDirAC->buffer_energy[( index - 1 ) * num_freq_bands] ), num_freq_bands ); -#endif - - -#ifdef IVAS_FLOAT_FIXED -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - Word16 buffer_intensity_real_q = 0; - float max_buffer_intensity_real_val = 0; - for ( i = 0; i < hDirAC->no_col_avg_diff; i++ ) + FOR( i = 0; i < DIRAC_NUM_DIMS; i++ ) { - for ( int j = 0; j < DIRAC_NUM_DIMS; j++ ) + FOR( j = 0; j < hDirAC->no_col_avg_diff; j++ ) { - for ( int k = 0; k < num_freq_bands; k++ ) + FOR( k = 0; k < num_freq_bands; k++ ) { - max_buffer_intensity_real_val = max( max_buffer_intensity_real_val, (float) fabs( hDirAC->buffer_intensity_real[j][i][k] ) ); + hDirAC->buffer_intensity_real_fx[i][j][k] = L_shl( hDirAC->buffer_intensity_real_fx[i][j][k], sub( buffer_intensity_real_single_q, hDirAC->buffer_intensity_real_q[i][j][k] ) ); + move32(); + hDirAC->buffer_intensity_real_q[i][j][k] = buffer_intensity_real_single_q; + move16(); } } } - Word32 tmp_var = 0; - Word16 buffer_intensity_real_buff_e = 0; - f2me( (float) fabs( max_buffer_intensity_real_val ), &tmp_var, &buffer_intensity_real_buff_e ); - buffer_intensity_real_q = sub( 31, buffer_intensity_real_buff_e ); - for ( i = 0; i < hDirAC->no_col_avg_diff; i++ ) + Word16 buffer_energy_single_q; + Word16 buffer_len; + buffer_len = imult1616( DIRAC_MAX_NBANDS, hDirAC->no_col_avg_diff ); + minimum_fx( hDirAC->buffer_energy_q, buffer_len, &buffer_energy_single_q ); + FOR( i = 0; i < buffer_len; i++ ) { - for ( int j = 0; j < DIRAC_NUM_DIMS; j++ ) - { - floatToFixed_arrL( hDirAC->buffer_intensity_real[j][i], hDirAC->buffer_intensity_real_fx[j][i], buffer_intensity_real_q, num_freq_bands ); - } + hDirAC->buffer_energy_fx[i] = L_shl( hDirAC->buffer_energy_fx[i], sub( buffer_energy_single_q, hDirAC->buffer_energy_q[i] ) ); + move32(); + hDirAC->buffer_energy_q[i] = buffer_energy_single_q; + move16(); } - Word16 buffer_energy_e = 0; - Word16 buffer_energy_q = 0; - move16(); - move16(); - f2me_buf( hDirAC->buffer_energy, hDirAC->buffer_energy_fx, &buffer_energy_e, DIRAC_MAX_NBANDS * hDirAC->no_col_avg_diff ); - buffer_energy_q = sub( 31, buffer_energy_e ); -#endif - Word16 *buffer_energy_buff_q = (Word16 *) malloc( DIRAC_MAX_NBANDS * hDirAC->no_col_avg_diff * sizeof( Word16 ) ); - Word16 *buffer_intensity_real_buff_q = (Word16 *) malloc( DIRAC_MAX_NBANDS * hDirAC->no_col_avg_diff * sizeof( Word16 ) ); - set16_fx( buffer_energy_buff_q, buffer_energy_q, DIRAC_MAX_NBANDS * hDirAC->no_col_avg_diff ); - set16_fx( buffer_intensity_real_buff_q, buffer_intensity_real_q, DIRAC_MAX_NBANDS * hDirAC->no_col_avg_diff ); + Word16 tmp_q_buffer_for_intensity[DIRAC_MAX_NBANDS * DIRAC_NO_COL_AVG_DIFF]; + Word16 tmp_q_buffer_for_energy[DIRAC_MAX_NBANDS * DIRAC_NO_COL_AVG_DIFF]; - computeDiffuseness_mdft_fx( hDirAC->buffer_intensity_real_fx, hDirAC->buffer_energy_fx, num_freq_bands, hDirAC->no_col_avg_diff, diffuseness_vector_fx, buffer_intensity_real_buff_q, buffer_energy_buff_q, &diffuseness_vector_q ); + set16_fx( tmp_q_buffer_for_intensity, buffer_intensity_real_single_q, buffer_len ); + set16_fx( tmp_q_buffer_for_energy, buffer_energy_single_q, buffer_len ); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - fixedToFloat_arrL( diffuseness_vector_fx, diffuseness_vector, diffuseness_vector_q, num_freq_bands ); -#endif - free( buffer_energy_buff_q ); - buffer_energy_buff_q = NULL; - free( buffer_intensity_real_buff_q ); - buffer_intensity_real_buff_q = NULL; -#else - computeDiffuseness_mdft( hDirAC->buffer_intensity_real, hDirAC->buffer_energy, num_freq_bands, hDirAC->no_col_avg_diff, diffuseness_vector ); -#endif + computeDiffuseness_mdft_fx( hDirAC->buffer_intensity_real_fx, hDirAC->buffer_energy_fx, num_freq_bands, hDirAC->no_col_avg_diff, diffuseness_vector_fx, tmp_q_buffer_for_intensity, tmp_q_buffer_for_energy, &diffuseness_vector_q ); - if ( hodirac_flag ) + IF( hodirac_flag ) { -#ifdef IVAS_FLOAT_FIXED - -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - for ( i = 0; i < NUM_ANA_SECTORS; i++ ) - { - for ( int j = 0; j < IVAS_MAX_NUM_BANDS; j++ ) - { - f2me( hDirAC->sec_I_vec_smth_x[i][j], &hDirAC->sec_I_vec_smth_x_fx[i][j], &hDirAC->sec_I_vec_smth_x_exp[i][j] ); - f2me( hDirAC->sec_I_vec_smth_y[i][j], &hDirAC->sec_I_vec_smth_y_fx[i][j], &hDirAC->sec_I_vec_smth_y_exp[i][j] ); - f2me( hDirAC->sec_I_vec_smth_z[i][j], &hDirAC->sec_I_vec_smth_z_fx[i][j], &hDirAC->sec_I_vec_smth_z_exp[i][j] ); - } - } - for ( i = 0; i < NUM_ANA_SECTORS * IVAS_MAX_NUM_BANDS; i++ ) - { - hDirAC->azi_prev_fx[i] = float_to_fix( hDirAC->azi_prev[i], Q23 ); - hDirAC->ele_prev_fx[i] = float_to_fix( hDirAC->ele_prev[i], Q23 ); - } -#endif calculate_hodirac_sector_parameters_fx( hDirAC, Cldfb_RealBuffer_fx, @@ -2026,189 +1840,188 @@ void ivas_dirac_param_est_enc( diff_secs_exp, ene_secs_fx, ene_secs_exp ); - -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - const int N_bands = hDirAC->hConfig->nbands; - for ( int i_sec = 0; i_sec < NUM_ANA_SECTORS; i_sec++ ) - { - for ( int i_band = hDirAC->hConfig->enc_param_start_band; i_band < N_bands; i_band++ ) - { - hDirAC->azi_prev[i_sec * N_bands + i_band] = fix_to_float( hDirAC->azi_prev_fx[i_sec * N_bands + i_band], Q23 ); - hDirAC->ele_prev[i_sec * N_bands + i_band] = fix_to_float( hDirAC->ele_prev_fx[i_sec * N_bands + i_band], Q23 ); - azi_secs[i_sec * N_bands + i_band] = fix_to_float( azi_secs_fx[i_sec * N_bands + i_band], Q23 ); - ele_secs[i_sec * N_bands + i_band] = fix_to_float( ele_secs_fx[i_sec * N_bands + i_band], Q23 ); - ene_secs[i_sec * N_bands + i_band] = me2f( ene_secs_fx[i_sec * N_bands + i_band], ene_secs_exp[i_sec * N_bands + i_band] ); - hDirAC->sec_I_vec_smth_x[i_sec][i_band] = me2f( hDirAC->sec_I_vec_smth_x_fx[i_sec][i_band], hDirAC->sec_I_vec_smth_x_exp[i_sec][i_band] ); - hDirAC->sec_I_vec_smth_y[i_sec][i_band] = me2f( hDirAC->sec_I_vec_smth_y_fx[i_sec][i_band], hDirAC->sec_I_vec_smth_y_exp[i_sec][i_band] ); - hDirAC->sec_I_vec_smth_z[i_sec][i_band] = me2f( hDirAC->sec_I_vec_smth_z_fx[i_sec][i_band], hDirAC->sec_I_vec_smth_z_exp[i_sec][i_band] ); - hDirAC->energy_smth[i_sec][i_band] = me2f( hDirAC->energy_smth_fx[i_sec][i_band], hDirAC->energy_smth_exp[i_sec][i_band] ); - diff_secs[i_sec * N_bands + i_band] = me2f( diff_secs_fx[i_sec * N_bands + i_band], diff_secs_exp[i_sec * N_bands + i_band] ); - } - } -#endif - -#else - calculate_hodirac_sector_parameters( - hDirAC, - Cldfb_RealBuffer, - Cldfb_ImagBuffer, - 0.20f, - hDirAC->band_grouping, - hDirAC->hConfig->nbands, - hDirAC->hConfig->enc_param_start_band, - azi_secs, - ele_secs, - diff_secs, - ene_secs ); -#endif } - if ( hodirac_flag ) + const Word16 gbits = 4; // 4 guard bits + move16(); + IF( hodirac_flag ) { - for ( band_m_idx = 0; band_m_idx < hDirAC->hConfig->nbands; band_m_idx++ ) + FOR( band_m_idx = 0; band_m_idx < hDirAC->hConfig->nbands; band_m_idx++ ) { - hDirAC->diffuseness_m[band_m_idx] += reference_power[ts][band_m_idx] * diffuseness_vector[band_m_idx]; - renormalization_factor_diff[band_m_idx] += reference_power[ts][band_m_idx]; + Word32 tmp_diff = L_shr( diffuseness_vector_fx[band_m_idx], sub( diffuseness_vector_q, 30 ) ); // diffueseness_vector_q -> Q30 + hDirAC->diffuseness_m_fx[band_m_idx] = BASOP_Util_Add_Mant32Exp( hDirAC->diffuseness_m_fx[band_m_idx], hDirAC->diffuseness_m_exp[band_m_idx], + Mpy_32_32( reference_power_fx[ts][band_m_idx], tmp_diff ), add( reference_power_exp, 1 ), &hDirAC->diffuseness_m_exp[band_m_idx] ); + move32(); + renormalization_factor_diff_fx[band_m_idx] = BASOP_Util_Add_Mant32Exp( renormalization_factor_diff_fx[band_m_idx], renormalization_factor_diff_exp[band_m_idx], reference_power_fx[ts][band_m_idx], reference_power_exp, &renormalization_factor_diff_exp[band_m_idx] ); + move32(); } } - else + ELSE { - for ( band_m_idx = 0; band_m_idx < hDirAC->hConfig->nbands; band_m_idx++ ) + FOR( band_m_idx = 0; band_m_idx < hDirAC->hConfig->nbands; band_m_idx++ ) { - norm_tmp = reference_power[ts][band_m_idx] * ( 1 - diffuseness_vector[band_m_idx] ); - - hDirAC->direction_vector_m[0][block_m_idx][band_m_idx] += norm_tmp * direction_vector[0][band_m_idx]; - hDirAC->direction_vector_m[1][block_m_idx][band_m_idx] += norm_tmp * direction_vector[1][band_m_idx]; - hDirAC->direction_vector_m[2][block_m_idx][band_m_idx] += norm_tmp * direction_vector[2][band_m_idx]; - renormalization_factor[band_m_idx] += norm_tmp; + Word32 tmp_diff = L_shr( diffuseness_vector_fx[band_m_idx], sub( diffuseness_vector_q, 30 ) ); // diffueseness_vector_q -> Q30 + norm_tmp_fx = Mpy_32_32( reference_power_fx[ts][band_m_idx], L_sub( ONE_IN_Q30, tmp_diff ) ); - hDirAC->diffuseness_m[band_m_idx] += reference_power[ts][band_m_idx] * diffuseness_vector[band_m_idx]; - renormalization_factor_diff[band_m_idx] += reference_power[ts][band_m_idx]; + hDirAC->direction_vector_m_fx[0][block_m_idx][band_m_idx] = L_add( hDirAC->direction_vector_m_fx[0][block_m_idx][band_m_idx], L_shr( Mpy_32_32( norm_tmp_fx, direction_vector_fx[0][band_m_idx] ), gbits ) ); + move32(); + hDirAC->direction_vector_m_fx[1][block_m_idx][band_m_idx] = L_add( hDirAC->direction_vector_m_fx[1][block_m_idx][band_m_idx], L_shr( Mpy_32_32( norm_tmp_fx, direction_vector_fx[1][band_m_idx] ), gbits ) ); + move32(); + hDirAC->direction_vector_m_fx[2][block_m_idx][band_m_idx] = L_add( hDirAC->direction_vector_m_fx[2][block_m_idx][band_m_idx], L_shr( Mpy_32_32( norm_tmp_fx, direction_vector_fx[2][band_m_idx] ), gbits ) ); + move32(); + renormalization_factor_fx[band_m_idx] = L_add( renormalization_factor_fx[band_m_idx], L_shr( norm_tmp_fx, gbits ) ); + move32(); + hDirAC->diffuseness_m_fx[band_m_idx] = BASOP_Util_Add_Mant32Exp( hDirAC->diffuseness_m_fx[band_m_idx], hDirAC->diffuseness_m_exp[band_m_idx], + Mpy_32_32( reference_power_fx[ts][band_m_idx], tmp_diff ), add( reference_power_exp, 1 ), &hDirAC->diffuseness_m_exp[band_m_idx] ); + move32(); + renormalization_factor_diff_fx[band_m_idx] = BASOP_Util_Add_Mant32Exp( renormalization_factor_diff_fx[band_m_idx], renormalization_factor_diff_exp[band_m_idx], + reference_power_fx[ts][band_m_idx], reference_power_exp, &renormalization_factor_diff_exp[band_m_idx] ); + move32(); } + norm_tmp_exp = add( reference_power_exp, 1 ); + hDirAC->direction_vector_m_exp[block_m_idx] = add( norm_tmp_exp, add( sub( 31, direction_vector_q ), gbits ) ); + move32(); + renormalization_factor_exp = add( norm_tmp_exp, gbits ); } } - if ( !hodirac_flag ) + IF( !hodirac_flag ) { - for ( band_m_idx = 0; band_m_idx < hDirAC->hConfig->nbands; band_m_idx++ ) + FOR( band_m_idx = 0; band_m_idx < hDirAC->hConfig->nbands; band_m_idx++ ) { - renormalization_factor[band_m_idx] = EPSILON; - for ( d = 0; d < DIRAC_NUM_DIMS; d++ ) - { - renormalization_factor[band_m_idx] += ( hDirAC->direction_vector_m[d][block_m_idx][band_m_idx] * hDirAC->direction_vector_m[d][block_m_idx][band_m_idx] ); - } - renormalization_factor[band_m_idx] = sqrtf( renormalization_factor[band_m_idx] ); + renormalization_factor_fx[band_m_idx] = EPSILON_FX; + move32(); + renormalization_factor_fx[band_m_idx] = L_add( renormalization_factor_fx[band_m_idx], Mpy_32_32( hDirAC->direction_vector_m_fx[0][block_m_idx][band_m_idx], hDirAC->direction_vector_m_fx[0][block_m_idx][band_m_idx] ) ); + move32(); + renormalization_factor_fx[band_m_idx] = L_add( renormalization_factor_fx[band_m_idx], Mpy_32_32( hDirAC->direction_vector_m_fx[1][block_m_idx][band_m_idx], hDirAC->direction_vector_m_fx[1][block_m_idx][band_m_idx] ) ); + move32(); + renormalization_factor_fx[band_m_idx] = L_add( renormalization_factor_fx[band_m_idx], Mpy_32_32( hDirAC->direction_vector_m_fx[2][block_m_idx][band_m_idx], hDirAC->direction_vector_m_fx[2][block_m_idx][band_m_idx] ) ); + move32(); + renormalization_factor_exp = shl( hDirAC->direction_vector_m_exp[block_m_idx], 1 ); // 2 * direction_vector_m_exp + renormalization_factor_fx[band_m_idx] = Sqrt32( renormalization_factor_fx[band_m_idx], &renormalization_factor_exp ); + move32(); - if ( renormalization_factor[band_m_idx] > EPSILON ) + IF( GT_32( renormalization_factor_fx[band_m_idx], EPSILON_FX ) ) { - hDirAC->direction_vector_m[0][block_m_idx][band_m_idx] /= renormalization_factor[band_m_idx]; - hDirAC->direction_vector_m[1][block_m_idx][band_m_idx] /= renormalization_factor[band_m_idx]; - hDirAC->direction_vector_m[2][block_m_idx][band_m_idx] /= renormalization_factor[band_m_idx]; + Word16 tmp_e; + Word32 tmp32; + + tmp32 = hDirAC->direction_vector_m_fx[0][block_m_idx][band_m_idx]; + move32(); + tmp32 = L_deposit_h( BASOP_Util_Divide3232_Scale( tmp32, renormalization_factor_fx[band_m_idx], &tmp_e ) ); + tmp_e = add( tmp_e, sub( hDirAC->direction_vector_m_exp[block_m_idx], renormalization_factor_exp ) ); + hDirAC->direction_vector_m_fx[0][block_m_idx][band_m_idx] = L_shr( tmp32, sub( 1, tmp_e ) ); // Q30 + move32(); + + tmp32 = hDirAC->direction_vector_m_fx[1][block_m_idx][band_m_idx]; + move32(); + tmp32 = L_deposit_h( BASOP_Util_Divide3232_Scale( tmp32, renormalization_factor_fx[band_m_idx], &tmp_e ) ); + tmp_e = add( tmp_e, sub( hDirAC->direction_vector_m_exp[block_m_idx], renormalization_factor_exp ) ); + hDirAC->direction_vector_m_fx[1][block_m_idx][band_m_idx] = L_shr( tmp32, sub( 1, tmp_e ) ); // Q30 + move32(); + + tmp32 = hDirAC->direction_vector_m_fx[2][block_m_idx][band_m_idx]; + move32(); + tmp32 = L_deposit_h( BASOP_Util_Divide3232_Scale( tmp32, renormalization_factor_fx[band_m_idx], &tmp_e ) ); + tmp_e = add( tmp_e, sub( hDirAC->direction_vector_m_exp[block_m_idx], renormalization_factor_exp ) ); + hDirAC->direction_vector_m_fx[2][block_m_idx][band_m_idx] = L_shr( tmp32, sub( 1, tmp_e ) ); // Q30 + move32(); } - else + ELSE { - hDirAC->direction_vector_m[0][block_m_idx][band_m_idx] = 1; - hDirAC->direction_vector_m[1][block_m_idx][band_m_idx] = 0; - hDirAC->direction_vector_m[2][block_m_idx][band_m_idx] = 0; + hDirAC->direction_vector_m_fx[0][block_m_idx][band_m_idx] = ONE_IN_Q30; + move32(); + hDirAC->direction_vector_m_fx[1][block_m_idx][band_m_idx] = 0; + move32(); + hDirAC->direction_vector_m_fx[2][block_m_idx][band_m_idx] = 0; + move32(); } + hDirAC->direction_vector_m_exp[block_m_idx] = 1; + move16(); /* save the elevation and azimuth values to be used later by the ivas_dirac_QuantizeParameters function */ - for ( d = 0; d < DIRAC_NUM_DIMS; d++ ) + FOR( d = 0; d < DIRAC_NUM_DIMS; d++ ) { - dir_v[d] = hDirAC->direction_vector_m[d][block_m_idx][band_m_idx]; + dir_v_fx[d] = hDirAC->direction_vector_m_fx[d][block_m_idx][band_m_idx]; // Q30 + move32(); } -#ifdef IVAS_FLOAT_FIXED -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - Word16 q_dir_e = 0; - f2me_buf( dir_v, dir_v_fx, &q_dir_e, 3 ); Scale_sig32( dir_v_fx, 3, -1 ); -#endif - ivas_qmetadata_direction_vector_to_azimuth_elevation_fx( dir_v_fx, - Q31 - q_dir_e, + Q30, &q_direction->band_data[band_m_idx].azimuth_fx[block_m_idx], &q_direction->band_data[band_m_idx].elevation_fx[block_m_idx] ); - -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - q_direction->band_data[band_m_idx].azimuth[block_m_idx] = fixedToFloat( q_direction->band_data[band_m_idx].azimuth_fx[block_m_idx], Q22 ); - q_direction->band_data[band_m_idx].elevation[block_m_idx] = fixedToFloat( q_direction->band_data[band_m_idx].elevation_fx[block_m_idx], Q22 ); -#endif -#else - ivas_qmetadata_direction_vector_to_azimuth_elevation( - dir_v, - &q_direction->band_data[band_m_idx].azimuth[block_m_idx], - &q_direction->band_data[band_m_idx].elevation[block_m_idx] ); -#endif } } /* Sectors */ - if ( hodirac_flag ) + IF( hodirac_flag ) { - for ( band_m_idx = 0; band_m_idx < hDirAC->hConfig->nbands; band_m_idx++ ) + FOR( band_m_idx = 0; band_m_idx < hDirAC->hConfig->nbands; band_m_idx++ ) { - q_direction->band_data[band_m_idx].azimuth[block_m_idx] = azi_secs[band_m_idx]; - q_direction->band_data[band_m_idx].elevation[block_m_idx] = ele_secs[band_m_idx]; - // q_direction->band_data[band_m_idx].energy_ratio[block_m_idx] = 1.f - diffuseness_vector[band_m_idx]; // set later + q_direction->band_data[band_m_idx].azimuth_fx[block_m_idx] = L_shr( azi_secs_fx[band_m_idx], 1 ); // Q23 -> Q22 + move32(); + q_direction->band_data[band_m_idx].elevation_fx[block_m_idx] = L_shr( ele_secs_fx[band_m_idx], 1 ); // Q23 -> Q22 + move32(); - q_direction[1].band_data[band_m_idx].azimuth[block_m_idx] = azi_secs[num_freq_bands + band_m_idx]; - q_direction[1].band_data[band_m_idx].elevation[block_m_idx] = ele_secs[num_freq_bands + band_m_idx]; - q_direction[1].band_data[band_m_idx].energy_ratio[block_m_idx] = ( 1.f - diff_secs[band_m_idx] ) / ( ( 1.f - diff_secs[band_m_idx] ) + ( 1.f - diff_secs[num_freq_bands + band_m_idx] ) + EPSILON ); - } - } - } + q_direction[1].band_data[band_m_idx].azimuth_fx[block_m_idx] = L_shr( azi_secs_fx[num_freq_bands + band_m_idx], 1 ); // Q23 -> Q22 + move32(); + q_direction[1].band_data[band_m_idx].elevation_fx[block_m_idx] = L_shr( ele_secs_fx[num_freq_bands + band_m_idx], 1 ); // Q23 -> Q22 + move32(); + Word32 x = L_sub( ONE_IN_Q30, L_shr( diff_secs_fx[band_m_idx], sub( 1, diff_secs_exp[band_m_idx] ) ) ); + Word32 y = L_sub( ONE_IN_Q30, L_shr( diff_secs_fx[num_freq_bands + band_m_idx], sub( 1, diff_secs_exp[num_freq_bands + band_m_idx] ) ) ); -#ifdef IVAS_FLOAT_FIXED - for ( block_m_idx = 0; block_m_idx < num_blocks; block_m_idx++ ) - { - free( hDirAC->direction_vector_m_fx[0][block_m_idx] ); - free( hDirAC->direction_vector_m_fx[1][block_m_idx] ); - free( hDirAC->direction_vector_m_fx[2][block_m_idx] ); + Word16 tmp16 = extract_h( L_add( x, y ) ); + Word32 tmp32; + IF( tmp16 == 0 ) + { + tmp32 = L_deposit_h( div_l( x, EPSILON_FX ) ); + } + ELSE + { + tmp32 = L_deposit_h( div_l( x, tmp16 ) ); + } + tmp32 = L_shr( tmp32, 1 ); // Q31 -> Q30 + } + } } - free( hDirAC->direction_vector_m_fx[0] ); - free( hDirAC->direction_vector_m_fx[1] ); - free( hDirAC->direction_vector_m_fx[2] ); -#endif /* Diffuseness */ - for ( band_m_idx = 0; band_m_idx < hDirAC->hConfig->nbands; band_m_idx++ ) + FOR( band_m_idx = 0; band_m_idx < hDirAC->hConfig->nbands; band_m_idx++ ) { - if ( renormalization_factor_diff[band_m_idx] > EPSILON ) + IF( GT_32( renormalization_factor_diff_fx[band_m_idx], EPSILON_FX ) ) { - hDirAC->diffuseness_m[band_m_idx] /= renormalization_factor_diff[band_m_idx]; + Word16 tmp_e; + hDirAC->diffuseness_m_fx[band_m_idx] = L_deposit_h( BASOP_Util_Divide3232_Scale( hDirAC->diffuseness_m_fx[band_m_idx], renormalization_factor_diff_fx[band_m_idx], &tmp_e ) ); + move32(); + tmp_e = add( tmp_e, sub( hDirAC->diffuseness_m_exp[band_m_idx], renormalization_factor_diff_exp[band_m_idx] ) ); + hDirAC->diffuseness_m_fx[band_m_idx] = L_shr( hDirAC->diffuseness_m_fx[band_m_idx], sub( 1, tmp_e ) ); // to Q30 + move32(); } - else + ELSE { - hDirAC->diffuseness_m[band_m_idx] = 0.f; + hDirAC->diffuseness_m_fx[band_m_idx] = 0; + move32(); } + hDirAC->diffuseness_m_exp[band_m_idx] = 1; + move16(); /* set coherence to zero and convert diffuseness to energy ratio*/ - set_f( q_direction->band_data[band_m_idx].energy_ratio, 1.f - hDirAC->diffuseness_m[band_m_idx], q_direction->cfg.nblocks ); + set32_fx( q_direction->band_data[band_m_idx].energy_ratio_fx, L_sub( ONE_IN_Q30, hDirAC->diffuseness_m_fx[band_m_idx] ), q_direction->cfg.nblocks ); - for ( block_m_idx = 0; block_m_idx < q_direction->cfg.nblocks; block_m_idx++ ) + FOR( block_m_idx = 0; block_m_idx < q_direction->cfg.nblocks; block_m_idx++ ) { - if ( q_direction->coherence_band_data != NULL ) + IF( q_direction->coherence_band_data != NULL ) { q_direction->coherence_band_data[band_m_idx].spread_coherence[block_m_idx] = 0; + move16(); } } } -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - for ( i = 0; i < nchan_fb_in; i++ ) - { - free( data_f_fx[i] ); - free( pp_fr_real_fx[i] ); - free( pp_fr_imag_fx[i] ); - } - free( pp_fr_real_fx ); - free( pp_fr_imag_fx ); -#endif - pop_wmops(); return; } diff --git a/lib_enc/ivas_mdct_core_enc.c b/lib_enc/ivas_mdct_core_enc.c index aecf4c9a9..f8787ab7d 100644 --- a/lib_enc/ivas_mdct_core_enc.c +++ b/lib_enc/ivas_mdct_core_enc.c @@ -2128,9 +2128,14 @@ void ivas_mdct_core_whitening_enc( bw_detect( st, NULL, st->hTcxEnc->spectrum[n], NULL, MC_FORMAT /*just cannot be ISM_FORMAT*/, mct_on ); #else #ifdef IVAS_FLOAT_FIXED_CONVERSIONS +#ifdef MSAN_FIX + q_spectrum = Q_factor_arr( st->hTcxEnc->spectrum[n], st->hTcxEnc->L_frameTCX / ( n + 1 ) ); + floatToFixed_arr( st->hTcxEnc->spectrum[n], spect_fx[n], q_spectrum, st->hTcxEnc->L_frameTCX / ( n + 1 ) ); +#else Word16 l_frame = (int16_t) ( st->input_Fs / FRAMES_PER_SEC ); q_spectrum = Q_factor_arr( st->hTcxEnc->spectrum[n], l_frame ); floatToFixed_arr( st->hTcxEnc->spectrum[n], spect_fx[n], q_spectrum, l_frame ); +#endif #endif bw_detect_fx( st, NULL, spect_fx[n], NULL, NULL, MC_FORMAT /*just cannot be ISM_FORMAT*/, mct_on ); #endif diff --git a/lib_enc/ivas_spar_encoder.c b/lib_enc/ivas_spar_encoder.c index 6777a8527..2ba611679 100644 --- a/lib_enc/ivas_spar_encoder.c +++ b/lib_enc/ivas_spar_encoder.c @@ -861,8 +861,15 @@ static ivas_error ivas_spar_cov_md_process( move32(); FOR( i = 1; i < nchan_inp; i++ ) { - Word32 tmp = L_deposit_h( BASOP_Util_Divide3232_Scale( cov_real_fx[i][i][b], cov_real_fx[0][0][b], &tmp_e ) ); - tmp_e = add( tmp_e, sub( sub( Q31, hSpar->hCovEnc->pCov_state->q_cov_real_per_band[i][i][b] ), sub( Q31, hSpar->hCovEnc->pCov_state->q_cov_real_per_band[0][0][b] ) ) ); + Word32 tmp = 0; + move32(); + tmp_e = 0; + move16(); + IF( cov_real_fx[0][0][b] != 0 ) + { + tmp = L_deposit_h( BASOP_Util_Divide3232_Scale( cov_real_fx[i][i][b], cov_real_fx[0][0][b], &tmp_e ) ); + tmp_e = add( tmp_e, sub( sub( Q31, hSpar->hCovEnc->pCov_state->q_cov_real_per_band[i][i][b] ), sub( Q31, hSpar->hCovEnc->pCov_state->q_cov_real_per_band[0][0][b] ) ) ); + } Wscale_d_fx[b] = BASOP_Util_Add_Mant32Exp( tmp, tmp_e, Wscale_d_fx[b], Wscale_d_e, &Wscale_d_e ); move32(); } @@ -1125,9 +1132,9 @@ static ivas_error ivas_spar_enc_process( { num_chs_alloc = 1; /* only W channel processed for predicting YZX */ } - FOR( Word16 m = 0; m < MAX_INPUT_CHANNELS + MAX_NUM_OBJECTS; m++ ) + FOR( Word16 m = 0; m <= nchan_fb_in + nchan_transport; m++ ) { - IF( data_f[m] != NULL && ( m <= nchan_fb_in + nchan_transport ) ) + IF( data_f[m] != NULL ) { q_data_fix[m] = Q_factor_arrL( data_f[m], input_frame ); floatToFixed_arrL( data_f[m], data_fix[m], q_data_fix[m], input_frame ); @@ -1325,9 +1332,73 @@ static ivas_error ivas_spar_enc_process( fprintf( fid, "%.6f\n", hSpar->hMdEnc->mixer_mat[1][0][band] ); } #endif +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + Word16 mixer_q = 31; + Word16 prior_mixer_q = 31; + Word32 num_channels = ivas_sba_get_nchan_metadata( sba_order, hEncoderConfig->ivas_total_brate ); + for ( i = 0; i < num_channels; i++ ) + { + for ( j = 0; j < num_channels; j++ ) + { + mixer_q = s_min( mixer_q, Q_factor_arrL( hSpar->hMdEnc->mixer_mat[i][j], IVAS_MAX_NUM_BANDS ) ); + } + } + for ( i = 0; i < hSpar->hFbMixer->fb_cfg->num_out_chans; i++ ) + { + for ( j = 0; j < hSpar->hFbMixer->fb_cfg->num_in_chans; j++ ) + { + prior_mixer_q = s_min( prior_mixer_q, Q_factor_arrL( hSpar->hFbMixer->prior_mixer[i][j], IVAS_MAX_NUM_BANDS ) ); + } + } + + mixer_q = s_min( mixer_q, prior_mixer_q ); + // both should have a common q as there are values being copied inside function + // or need to do loop for updating values for unused values + + for ( i = 0; i < num_channels; i++ ) + { + for ( j = 0; j < num_channels; j++ ) + { + floatToFixed_arrL32( hSpar->hMdEnc->mixer_mat[i][j], hSpar->hMdEnc->mixer_mat_fx[i][j], mixer_q, IVAS_MAX_NUM_BANDS ); + } + } + for ( i = 0; i < hSpar->hFbMixer->fb_cfg->num_out_chans; i++ ) + { + for ( j = 0; j < hSpar->hFbMixer->fb_cfg->num_in_chans; j++ ) + { + floatToFixed_arrL32( hSpar->hFbMixer->prior_mixer[i][j], hSpar->hFbMixer->prior_mixer_fx[i][j], mixer_q, IVAS_MAX_NUM_BANDS ); + } + } + + hSpar->hMdEnc->q_mixer_mat_fx = mixer_q; + hSpar->hFbMixer->q_prior_mixer_fx = mixer_q; + Word16 q_p_pcm_tmp_loc_fx[DIRAC_MAX_ANA_CHANS]; +#endif - ivas_fb_mixer_process( hSpar->hFbMixer, hSpar->hMdEnc->mixer_mat, p_pcm_tmp, input_frame, in_out_mixer_map ); + // both mixer_mat_fx and prior mixer_mat_fx should have a common q as there are values being copied inside function + // or need to do loop for updating values for unused values + ivas_fb_mixer_process( hSpar->hFbMixer, hSpar->hMdEnc->mixer_mat_fx, &hSpar->hMdEnc->q_mixer_mat_fx, p_pcm_tmp_fx, q_p_pcm_tmp_loc_fx, input_frame, in_out_mixer_map ); +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + for ( int ch = ( hSpar->hFbMixer->fb_cfg->active_w_mixing == 0 ); ch < hSpar->hFbMixer->fb_cfg->num_out_chans; ch++ ) + { + for ( int k = 0; k < input_frame; k++ ) + { + p_pcm_tmp[ch][k] = (float) fixedToFloat( p_pcm_tmp_fx[ch][k], q_p_pcm_tmp_loc_fx[ch] ); + } + } + + // hSpar->hMdEnc->q_mixer_mat_fx = mixer_q; + // hSpar->hFbMixer->q_prior_mixer_fx = mixer_q; + // should be same + for ( i = 0; i < hSpar->hFbMixer->fb_cfg->num_out_chans; i++ ) + { + for ( j = 0; j < hSpar->hFbMixer->fb_cfg->num_in_chans; j++ ) + { + fixedToFloat_arrL32( hSpar->hFbMixer->prior_mixer_fx[i][j], hSpar->hFbMixer->prior_mixer[i][j], hSpar->hFbMixer->q_prior_mixer_fx, IVAS_MAX_NUM_BANDS ); + } + } +#endif if ( hSpar->hFbMixer->fb_cfg->active_w_mixing == 0 ) { @@ -1337,7 +1408,7 @@ static ivas_error ivas_spar_enc_process( if ( hSpar->hMdEnc->spar_md.prior_dyn_active_w_flag != dyn_active_w_flag ) { float new_w[L_FRAME48k]; - + Word32 new_w_fx[L_FRAME48k]; /* delayed W */ mvr2r( wyzx_del_buf[0], p_pcm_tmp[0], num_del_samples ); mvr2r( data_f[0], p_pcm_tmp[0] + num_del_samples, input_frame - num_del_samples ); @@ -1347,11 +1418,47 @@ static ivas_error ivas_spar_enc_process( if ( hSpar->hMdEnc->spar_md.prior_dyn_active_w_flag == 0 && dyn_active_w_flag == 1 ) { +#ifndef IVAS_FLOAT_FIXED ivas_fb_mixer_cross_fading( hSpar->hFbMixer, p_pcm_tmp, p_pcm_tmp[0], new_w, 0, input_frame, 0 ); +#else +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + floatToFixed_arrL32( new_w, new_w_fx, Q11, input_frame ); + FOR( i = 0; i < hSpar->hFbMixer->fb_cfg->num_out_chans; i++ ) + { + p_pcm_tmp_fx[i] = &pcm_tmp_fx[i][0]; + floatToFixed_arrL32( p_pcm_tmp[i], p_pcm_tmp_fx[i], Q11, input_frame ); + } +#endif + ivas_fb_mixer_cross_fading_fx( hSpar->hFbMixer, p_pcm_tmp_fx, p_pcm_tmp_fx[0], new_w_fx, 0, input_frame, 0 ); +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + FOR( i = 0; i < hSpar->hFbMixer->fb_cfg->num_out_chans; i++ ) + { + fixedToFloat_arrL32( p_pcm_tmp_fx[i], p_pcm_tmp[i], Q11, input_frame ); + } +#endif +#endif } else if ( hSpar->hMdEnc->spar_md.prior_dyn_active_w_flag == 1 && dyn_active_w_flag == 0 ) { +#ifndef IVAS_FLOAT_FIXED ivas_fb_mixer_cross_fading( hSpar->hFbMixer, p_pcm_tmp, new_w, p_pcm_tmp[0], 0, input_frame, 0 ); +#else +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + floatToFixed_arrL32( new_w, new_w_fx, Q11, input_frame ); + FOR( i = 0; i < hSpar->hFbMixer->fb_cfg->num_out_chans; i++ ) + { + p_pcm_tmp_fx[i] = &pcm_tmp_fx[i][0]; + floatToFixed_arrL32( p_pcm_tmp[i], p_pcm_tmp_fx[i], Q11, input_frame ); + } +#endif + ivas_fb_mixer_cross_fading_fx( hSpar->hFbMixer, p_pcm_tmp_fx, new_w_fx, p_pcm_tmp_fx[0], 0, input_frame, 0 ); +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + FOR( i = 0; i < hSpar->hFbMixer->fb_cfg->num_out_chans; i++ ) + { + fixedToFloat_arrL32( p_pcm_tmp_fx[i], p_pcm_tmp[i], Q11, input_frame ); + } +#endif +#endif } } else diff --git a/lib_enc/ivas_spar_md_enc.c b/lib_enc/ivas_spar_md_enc.c index 13c9bdc0a..357e52230 100644 --- a/lib_enc/ivas_spar_md_enc.c +++ b/lib_enc/ivas_spar_md_enc.c @@ -299,6 +299,7 @@ ivas_error ivas_spar_md_enc_open_fx( * Deallocate SPAR MD encoder handle *------------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED void ivas_spar_md_enc_close( ivas_spar_md_enc_state_t **hMdEnc_in /* i/o: SPAR MD encoder handle */ ) @@ -331,12 +332,80 @@ void ivas_spar_md_enc_close( } free( hMdEnc->mixer_mat ); } +#ifdef IVAS_FLOAT_FIXED + IF( hMdEnc->mixer_mat_fx != NULL ) + { + FOR( i = 0; i < num_channels; i++ ) + { + FOR( j = 0; j < num_channels; j++ ) + { + free( hMdEnc->mixer_mat_fx[i][j] ); + } + free( hMdEnc->mixer_mat_fx[i] ); + } + free( hMdEnc->mixer_mat_fx ); + } +#endif free( *hMdEnc_in ); *hMdEnc_in = NULL; return; } +#else +void ivas_spar_md_enc_close( + ivas_spar_md_enc_state_t **hMdEnc_in /* i/o: SPAR MD encoder handle */ +) +{ + int16_t num_channels, i, j; + ivas_spar_md_enc_state_t *hMdEnc; + + if ( hMdEnc_in == NULL || *hMdEnc_in == NULL ) + { + return; + } + + hMdEnc = *hMdEnc_in; + num_channels = hMdEnc->num_umx_ch; + + if ( hMdEnc->spar_md.band_coeffs != NULL ) + { + free( hMdEnc->spar_md.band_coeffs ); + hMdEnc->spar_md.band_coeffs = NULL; + } + if ( hMdEnc->mixer_mat != NULL ) + { + for ( i = 0; i < num_channels; i++ ) + { + for ( j = 0; j < num_channels; j++ ) + { + free( hMdEnc->mixer_mat[i][j] ); + } + free( hMdEnc->mixer_mat[i] ); + } + free( hMdEnc->mixer_mat ); + } + + if ( hMdEnc->mixer_mat_local != NULL ) + { + for ( i = 0; i < num_channels; i++ ) + { + + for ( j = 0; j < num_channels; j++ ) + { + free( hMdEnc->mixer_mat_local[i][j] ); + } + free( hMdEnc->mixer_mat_local[i] ); + } + free( hMdEnc->mixer_mat_local ); + } + + free( *hMdEnc_in ); + *hMdEnc_in = NULL; + + return; +} +#endif /*-----------------------------------------------------------------------------------------* diff --git a/lib_enc/ivas_stat_enc.h b/lib_enc/ivas_stat_enc.h index 746d5712a..4c3eca4d9 100644 --- a/lib_enc/ivas_stat_enc.h +++ b/lib_enc/ivas_stat_enc.h @@ -942,8 +942,10 @@ typedef struct ivas_dirac_enc_data_structure float **direction_vector_m[DIRAC_NUM_DIMS]; /* Average direction vector */ float diffuseness_m[DIRAC_MAX_NBANDS]; #ifdef IVAS_FLOAT_FIXED - Word32 **direction_vector_m_fx[DIRAC_NUM_DIMS]; /* Average direction vector */ + Word32 **direction_vector_m_fx[DIRAC_NUM_DIMS]; /* Average direction vector */ + Word16 direction_vector_m_exp[MAX_PARAM_SPATIAL_SUBFRAMES]; // direction_vector_m_fx[i][j][k] will map to direction_vector_m_exp[j] exponent. Word32 diffuseness_m_fx[DIRAC_MAX_NBANDS]; + Word16 diffuseness_m_exp[DIRAC_MAX_NBANDS]; #endif int16_t band_grouping[DIRAC_MAX_NBANDS + 1]; int16_t block_grouping[5]; @@ -979,7 +981,9 @@ typedef struct ivas_dirac_enc_data_structure float *buffer_energy; #ifdef IVAS_FLOAT_FIXED Word32 **buffer_intensity_real_fx[DIRAC_NUM_DIMS]; + Word16 buffer_intensity_real_q[DIRAC_NUM_DIMS][DIRAC_NO_COL_AVG_DIFF][DIRAC_MAX_NBANDS]; Word32 *buffer_energy_fx; + Word16 buffer_energy_q[DIRAC_NO_COL_AVG_DIFF * DIRAC_MAX_NBANDS]; #endif /* Frame count for detecting mono */ @@ -1061,7 +1065,6 @@ typedef struct ivas_spar_md_enc_state_t Word16 HOA_md_ind[IVAS_SPAR_MAX_CH]; Word32 ***mixer_mat_fx; Word16 q_mixer_mat_fx; - Word32 ***mixer_mat_local_fx; } ivas_spar_md_enc_state_t; /* PCA structure */ diff --git a/lib_enc/swb_pre_proc.c b/lib_enc/swb_pre_proc.c index de6cafa55..b8c891d3c 100644 --- a/lib_enc/swb_pre_proc.c +++ b/lib_enc/swb_pre_proc.c @@ -567,7 +567,7 @@ void swb_pre_proc_ivas_fx( { Word16 out_start_ind, out_end_ind; stereo_dft_enc_synthesize_fx( hCPE->hStereoDft, new_swb_speech_fx, &out_start_ind, &out_end_ind, st->idchan, input_Fs, 32000, 0, NULL ); - Copy_Scale_sig32_16( new_swb_speech_fx, new_swb_speech, q_reImBuffer, L_FRAME48k ); + Copy_Scale_sig32_16( new_swb_speech_fx - STEREO_DFT_OVL_MAX, new_swb_speech - STEREO_DFT_OVL_MAX, q_reImBuffer, L_FRAME48k + STEREO_DFT_OVL_MAX ); Copy( new_swb_speech - Sample_Delay_SWB_BWE32k, hBWE_FD->old_input_fx, Sample_Delay_SWB_BWE32k ); } } -- GitLab From 3873dec200377f6bad939115c5be35ae601f1b14 Mon Sep 17 00:00:00 2001 From: Adriana Vasilache Date: Wed, 23 Oct 2024 12:09:44 +0300 Subject: [PATCH 036/128] fix 953 --- lib_com/options.h | 2 ++ lib_dec/ivas_masa_dec.c | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/lib_com/options.h b/lib_com/options.h index 819f2a42f..f1023d3b6 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -193,6 +193,8 @@ #define FIX_930_JBM_BUFSIZE_MULT /* FhG: Fix 930, Word16 too small for apa_buffer_size */ #define NONBE_FIX_943_PORT_1208_DFT_STEREO_PLC_BURST /* Ericsson: BASOP Issue 943, Float Issue 1208, fix for overflow of sample offset counter for burst error in DFT Stereo PLC. */ #define FIX_853_DECODE_MASA_ISM_AZIMUTH_PREC /* Nokia: Fixes ivas_decode_masaism_metadata decision logic change due to precision difference; needs corresponding fix in floating point */ +#define FIX_953_WRONG_ENERGY_RATIO_MASA_EXT /* Nok: Fix 953 wrong energy ratio value after shift and cast to Word8 */ + /* ################## End DEVELOPMENT switches ######################### */ /* clang-format on */ diff --git a/lib_dec/ivas_masa_dec.c b/lib_dec/ivas_masa_dec.c index 13e970f85..f3962ced2 100644 --- a/lib_dec/ivas_masa_dec.c +++ b/lib_dec/ivas_masa_dec.c @@ -4438,6 +4438,13 @@ static void create_masa_ext_out_meta_fx( move16(); FOR( dir = 0; dir < numDirections; dir++ ) { +#ifdef FIX_953_WRONG_ENERGY_RATIO_MASA_EXT + /* todo: not optimal, but less invasive */ + IF( EQ_32( hQMetaData->q_direction[dir].band_data[b_old].energy_ratio_fx[sf], ONE_IN_Q30 ) ) + { + hQMetaData->q_direction[dir].band_data[b_old].energy_ratio_fx[sf]--; + } +#endif UWord8 tmp = (UWord8) L_shr( hQMetaData->q_direction[dir].band_data[b_old].energy_ratio_fx[sf], Q30 - 8 ); // Q8 move16(); extOutMeta->diffuseToTotalRatio[sf][b_new] = (UWord8) sub( extOutMeta->diffuseToTotalRatio[sf][b_new], tmp ); // Q8 -- GitLab From 573d4978fe660cb0eabefa58560570217d8b412c Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Thu, 24 Oct 2024 13:51:44 +0530 Subject: [PATCH 037/128] Fix for 3GPP issue 948: High MLD value due to high energy in transients for MC 5.1 in MCT --- lib_dec/ivas_mct_dec.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib_dec/ivas_mct_dec.c b/lib_dec/ivas_mct_dec.c index 197c9f2a9..ae5057bc1 100644 --- a/lib_dec/ivas_mct_dec.c +++ b/lib_dec/ivas_mct_dec.c @@ -579,15 +579,15 @@ ivas_error ivas_mct_dec_fx( hdrm = getScaleFactor16( synth_fx[0], hCPE->hCoreCoder[0]->hTcxDec->L_frameTCX ); IF( hdrm != 0 ) { - sh = s_min( sub( e_sig[0], 15 ), hdrm ); + sh = s_min( sub( e_sig[0], 16 ), hdrm ); Scale_sig( synth_fx[0], hCPE->hCoreCoder[0]->hTcxDec->L_frameTCX, sh ); e_sig[0] = sub( e_sig[0], sh ); move16(); } - + hdrm = getScaleFactor16( synth_fx[1], hCPE->hCoreCoder[0]->hTcxDec->L_frameTCX ); IF( hdrm != 0 ) { - sh = s_min( sub( e_sig[1], 15 ), hdrm ); + sh = s_min( sub( e_sig[1], 16 ), hdrm ); Scale_sig( synth_fx[1], hCPE->hCoreCoder[1]->hTcxDec->L_frameTCX, sh ); e_sig[1] = sub( e_sig[1], sh ); move16(); @@ -616,11 +616,11 @@ ivas_error ivas_mct_dec_fx( IF( ( st_ivas->sba_dirac_stereo_flag != 0 ) && ( NE_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) || GE_16( cpe_id, sub( nCPE, 2 ) ) ) ) { - Copy_Scale_sig_16_32( synth_fx[n], synth_fx_32[n], L_FRAME48k, Q11 - 0 ); // Q11 + Copy_Scale_sig_16_32( synth_fx[n], synth_fx_32[n], L_FRAME48k, sub( Q11, ( sub( 15, e_sig[n] ) ) ) ); // Q11 Copy_Scale_sig_16_32( hCPE->hCoreCoder[n]->hHQ_core->old_out_fx, hCPE->hCoreCoder[n]->hHQ_core->oldOut_fx, output_frame, sub( Q11, hCPE->hCoreCoder[n]->hHQ_core->Q_old_wtda ) ); ivas_post_proc_fx( NULL, hCPE, n, synth_fx_32[n], NULL, output_frame, 1, Q11 ); #ifdef MSAN_FIX - Copy_Scale_sig_32_16( synth_fx_32[n], synth_fx[n], output_frame, 0 - Q11 ); // Q0 + Copy_Scale_sig_32_16( synth_fx_32[n], synth_fx[n], output_frame, sub( sub( 15, e_sig[n] ), Q11 ) ); // Q0 #else Copy_Scale_sig_32_16( synth_fx_32[n], synth_fx[n], L_FRAME48k, 0 - Q11 ); #endif @@ -630,7 +630,7 @@ ivas_error ivas_mct_dec_fx( Word16 output_mem_fx[L_FRAME48k]; IF( hCPE->output_mem_fx[1] != NULL ) { - Copy_Scale_sig_32_16( hCPE->output_mem_fx[1], output_mem_fx, NS2SA( sts[n]->output_Fs, 3125000 ), 0 - Q11 ); + Copy_Scale_sig_32_16( hCPE->output_mem_fx[1], output_mem_fx, NS2SA( sts[n]->output_Fs, 3125000 ), -Q11 ); } ELSE { -- GitLab From 786b6706ff48dc065df5fd8eb4fd4e3365424365 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Thu, 24 Oct 2024 14:07:12 +0530 Subject: [PATCH 038/128] SBA path functions conversion, ASAN and MSAN fixes, cleanup [x] spar process functions/ sub-functions conversion and integration [x] Cleanup of ivas_dirac_param_est_enc function [x] Few ASAN and MSAN fixes [x] Q-info updates for lib_dec and lib_rend files --- lib_com/ivas_fb_mixer.c | 220 ++++++- lib_com/ivas_prot.h | 35 +- lib_com/ivas_prot_fx.h | 20 +- lib_com/ivas_rom_com_fx.c | 106 ++-- lib_com/ivas_rom_com_fx.h | 4 +- lib_com/ivas_stat_com.h | 1 + lib_com/prot.h | 24 +- lib_com/prot_fx.h | 311 +++++----- lib_com/rom_com.c | 26 +- lib_com/rom_com_fx.c | 53 ++ lib_dec/er_scale_syn_fx.c | 16 +- lib_dec/er_sync_exc_fx.c | 140 ++--- lib_dec/er_util_fx.c | 102 ++-- lib_dec/hf_synth_fx.c | 591 +++++++++--------- lib_dec/hq_classifier_dec_fx.c | 32 +- lib_dec/hq_conf_fec_fx.c | 24 +- lib_dec/hq_core_dec_fx.c | 236 +++---- lib_dec/hq_env_dec_fx.c | 110 ++-- lib_dec/hq_hr_dec_fx.c | 112 ++-- lib_dec/swb_bwe_dec.c | 67 +- lib_dec/swb_bwe_dec_fx.c | 139 ++--- lib_dec/swb_bwe_dec_hr_fx.c | 105 ++-- lib_dec/swb_bwe_dec_lr_fx.c | 125 ++-- lib_dec/swb_tbe_dec.c | 153 +++-- lib_dec/swb_tbe_dec_fx.c | 153 +++-- lib_dec/syn_outp.c | 3 +- lib_dec/syn_outp_fx.c | 18 +- lib_dec/tcq_core_dec_fx.c | 47 +- lib_dec/tcx_utils_dec_fx.c | 87 ++- lib_dec/tns_base_dec_fx.c | 24 +- lib_enc/ivas_core_enc.c | 19 +- lib_enc/ivas_core_pre_proc_front.c | 3 + lib_enc/ivas_dirac_enc.c | 949 ++++++++++++----------------- lib_enc/ivas_mdct_core_enc.c | 5 + lib_enc/ivas_spar_encoder.c | 119 +++- lib_enc/ivas_spar_md_enc.c | 69 +++ lib_enc/ivas_stat_enc.h | 7 +- lib_enc/swb_pre_proc.c | 2 +- 38 files changed, 2270 insertions(+), 1987 deletions(-) diff --git a/lib_com/ivas_fb_mixer.c b/lib_com/ivas_fb_mixer.c index 9d54f3f0a..5da92e987 100644 --- a/lib_com/ivas_fb_mixer.c +++ b/lib_com/ivas_fb_mixer.c @@ -48,7 +48,7 @@ /*------------------------------------------------------------------------------------------* * Static functions declarations *------------------------------------------------------------------------------------------*/ - +static void ivas_cmult_fix( Word32 in1_re, Word32 in1_im, Word32 in2_re, Word32 in2_im, Word32 *out1_re, Word32 *out1_im ); static void ivas_get_active_bins( const int16_t **pActive_bins, const int16_t **pActive_bins_abs, const int16_t **pStart_offset, const int16_t **pStart_offset_ab, const int32_t sampling_rate ); static void ivas_get_ld_fb_resp( float **ppIdeal_FRs_re, float **ppIdeal_FRs_im, float **ppNew_FRs_re, float **ppNew_FRs_im, const int16_t *pActive_bins, const int16_t *pStart_offset, const int16_t num_bands, const int16_t delay, const int32_t sampling_rate ); #ifdef IVAS_FLOAT_FIXED @@ -426,6 +426,21 @@ ivas_error ivas_FB_mixer_open( set_f( hFbMixer->prior_mixer[i][j], 0, IVAS_MAX_NUM_BANDS ); } } + + Word32 *pTemp_mem_fx; + if ( ( pTemp_mem_fx = (Word32 *) malloc( sizeof( Word32 ) * fb_cfg->num_out_chans * max( fb_cfg->num_in_chans, fb_cfg->nchan_fb_in ) * IVAS_MAX_NUM_BANDS ) ) == NULL ) + { + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FB mixer" ); + } + for ( i = 0; i < fb_cfg->num_out_chans; i++ ) + { + for ( j = 0; j < fb_cfg->num_in_chans; j++ ) + { + hFbMixer->prior_mixer_fx[i][j] = pTemp_mem_fx; + pTemp_mem_fx += IVAS_MAX_NUM_BANDS; + set32_fx( hFbMixer->prior_mixer_fx[i][j], 0, IVAS_MAX_NUM_BANDS ); + } + } } if ( !spar_reconfig_flag ) @@ -506,6 +521,12 @@ ivas_error ivas_FB_mixer_open( { return error; } + Word16 index[IVAS_MAX_NUM_FB_BANDS]; + set16_fx( index, 0, IVAS_MAX_NUM_FB_BANDS ); + if ( ( error = ivas_filterbank_setup_fx( hFbMixer, sampling_rate, index ) ) != IVAS_ERR_OK ) + { + return error; + } } *hFbMixer_out = hFbMixer; @@ -1400,7 +1421,162 @@ void ivas_fb_mixer_cross_fading_fx( * * Filter bank process *-----------------------------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +void ivas_cmult_fix( Word32 in1_re, Word32 in1_im, Word32 in2_re, Word32 in2_im, Word32 *out1_re, Word32 *out1_im ) +{ + *out1_re = L_sub_sat( Mpy_32_32( in1_re, in2_re ), Mpy_32_32( in1_im, in2_im ) ); + *out1_im = L_add_sat( Mpy_32_32( in1_re, in2_im ), Mpy_32_32( in2_re, in1_im ) ); +} +void ivas_fb_mixer_process( + IVAS_FB_MIXER_HANDLE hFbMixer, /* i/o: FB mixer handle */ + Word32 ***mixer_mat_fx, /* i : mixer matrix */ + Word16 *q_mixer_mat_fx, /* i : mixer matrix */ + Word32 **ppOut_pcm_fx, /* o : output audio channels */ + Word16 *q_ppOut_pcm_fx, /*ppOut_pcm_fx resultant q*/ + const Word16 frame_len, /* i : frame length in samples */ + Word16 in_out_mixer_map[IVAS_MAX_FB_MIXER_OUT_CH][IVAS_MAX_SPAR_FB_MIXER_IN_CH] /* i/o: mixing mapping */ +) +{ + ivas_filterbank_t *pFb = hFbMixer->pFb; + Word16 num_bands = pFb->filterbank_num_bands; + move16(); + Word16 i, j, k, ch, hist; + + const Word32 *pFilterbank_bin_to_band_re_fx; + const Word32 *pFilterbank_bin_to_band_im_fx; + Word32 *pMdft_out_fx[2]; + Word32 *pOut_fr_re_fx, *pOut_fr_im_fx; + Word16 q_pOut_fr_fx = 31; + move16(); + Word32 Out_fr_re_fx[L_FRAME48k], Out_fr_im_fx[L_FRAME48k]; + Word32 Mdft_out_0_fx[L_FRAME48k * 2], Mdft_out_1_fx[L_FRAME48k * 2]; + + pOut_fr_re_fx = Out_fr_re_fx; + pOut_fr_im_fx = Out_fr_im_fx; + pMdft_out_fx[0] = Mdft_out_0_fx; + pMdft_out_fx[1] = Mdft_out_1_fx; + + FOR( ch = ( hFbMixer->fb_cfg->active_w_mixing == 0 ); ch < hFbMixer->fb_cfg->num_out_chans; ch++ ) + { + /* Run a loop of 2 to calculate current frame's filterbank output and prev frame's output */ + FOR( hist = 0; hist < 2; hist++ ) + { + set_zero_fx( pOut_fr_re_fx, frame_len ); + set_zero_fx( pOut_fr_im_fx, frame_len ); + q_pOut_fr_fx = 31; + move16(); + FOR( j = 0; j < hFbMixer->fb_cfg->num_in_chans; j++ ) + { + IF( in_out_mixer_map[ch][j] != 0 ) + { + + Word32 filterbank_mixer_bins_re_fx[L_FRAME48k]; + Word32 filterbank_mixer_bins_im_fx[L_FRAME48k]; + Word32 *pFb_inFR_re_fx = hFbMixer->ppFilterbank_inFR_re_fx[j]; + Word32 *pFb_inFR_im_fx = hFbMixer->ppFilterbank_inFR_im_fx[j]; + + set_zero_fx( filterbank_mixer_bins_re_fx, frame_len ); + set_zero_fx( filterbank_mixer_bins_im_fx, frame_len ); + + Word16 total_guard = find_guarded_bits_fx( num_bands ); + move16(); + FOR( i = 0; i < num_bands; i++ ) + { + Word16 start_offset = pFb->fb_consts.pFilterbank_bins_start_offset[i]; + move16(); + Word16 num_bins = pFb->fb_consts.pFilterbank_bins_per_band[i]; + move16(); + Word32 mixer_const_fx = hFbMixer->prior_mixer_fx[ch][j][i]; + move32(); + pFilterbank_bin_to_band_re_fx = pFb->fb_consts.ppFilterbank_FRs_fx[0][i]; + pFilterbank_bin_to_band_im_fx = pFb->fb_consts.ppFilterbank_FRs_fx[1][i]; + + FOR( k = start_offset; k < num_bins + start_offset; k++ ) + { + filterbank_mixer_bins_re_fx[k] = L_add_sat( filterbank_mixer_bins_re_fx[k], L_shr( Mpy_32_32( *pFilterbank_bin_to_band_re_fx, mixer_const_fx ), total_guard ) ); + move32(); + filterbank_mixer_bins_im_fx[k] = L_add_sat( filterbank_mixer_bins_im_fx[k], L_shr( Mpy_32_32( *pFilterbank_bin_to_band_im_fx, mixer_const_fx ), total_guard ) ); + move32(); + /*filterbank_mixer_bins_im_fx q 30 */ + /*mixer_const_fx q q_ppOut_pcm_fx */ + pFilterbank_bin_to_band_re_fx++; + pFilterbank_bin_to_band_im_fx++; + } + hFbMixer->prior_mixer_fx[ch][j][i] = mixer_mat_fx[ch][j][i]; + move32(); + } + Word16 res_q = 0; + move16(); + FOR( k = 0; k < frame_len; k++ ) + { + Word32 temp_out_re_fx, temp_out_im_fx; + + Word16 Fb_inFR_com_q = s_min( hFbMixer->q_ppFilterbank_inFR_re_fx[j], hFbMixer->q_ppFilterbank_inFR_im_fx[j] ); + Word32 inp_Fb_inFR_re, inp_Fb_inFR_im; + IF( NE_16( hFbMixer->q_ppFilterbank_inFR_re_fx[j], Fb_inFR_com_q ) ) + { + inp_Fb_inFR_re = L_shr( pFb_inFR_re_fx[k], sub( hFbMixer->q_ppFilterbank_inFR_re_fx[j], Fb_inFR_com_q ) ); + /*common q for real and imag hFbMixer->q_ppFilterbank_inFR_re_fx[j]*/ + } + ELSE + { + inp_Fb_inFR_re = pFb_inFR_re_fx[k]; + /*q hFbMixer->q_ppFilterbank_inFR_re_fx[j]*/ + move32(); + } + IF( NE_16( hFbMixer->q_ppFilterbank_inFR_im_fx[j], Fb_inFR_com_q ) ) + { + inp_Fb_inFR_im = L_shr( pFb_inFR_im_fx[k], sub( hFbMixer->q_ppFilterbank_inFR_im_fx[j], Fb_inFR_com_q ) ); + /*common q for real and imag hFbMixer->q_ppFilterbank_inFR_re_fx[j]*/ + } + ELSE + { + inp_Fb_inFR_im = pFb_inFR_im_fx[k]; + /*q hFbMixer->q_ppFilterbank_inFR_im_fx[j]*/ + move32(); + } + ivas_cmult_fix( filterbank_mixer_bins_re_fx[k], filterbank_mixer_bins_im_fx[k], inp_Fb_inFR_re, + inp_Fb_inFR_im, &temp_out_re_fx, &temp_out_im_fx ); + res_q = sub( add( sub( sub( add( 30, *q_mixer_mat_fx ), 31 ), total_guard ), Fb_inFR_com_q ), 31 ); + move16(); + Word16 q_check = s_min( q_pOut_fr_fx, res_q ); + move16(); + IF( NE_16( q_check, q_pOut_fr_fx ) ) + { + pOut_fr_re_fx[k] = L_shr( pOut_fr_re_fx[k], sub( q_pOut_fr_fx, q_check ) ); + move32(); + pOut_fr_im_fx[k] = L_shr( pOut_fr_im_fx[k], sub( q_pOut_fr_fx, q_check ) ); + move32(); + } + IF( q_check != res_q ) + { + temp_out_re_fx = L_shr( temp_out_re_fx, sub( res_q, q_check ) ); + temp_out_im_fx = L_shr( temp_out_im_fx, sub( res_q, q_check ) ); + } + res_q = q_check; + move16(); + pOut_fr_re_fx[k] = L_add_sat( pOut_fr_re_fx[k], temp_out_re_fx ); + move32(); + pOut_fr_im_fx[k] = L_add_sat( pOut_fr_im_fx[k], temp_out_im_fx ); + move32(); + } + q_pOut_fr_fx = res_q; + move16(); + } + } + ivas_imdft_fx( pOut_fr_re_fx, pOut_fr_im_fx, pMdft_out_fx[hist], frame_len ); + } + + ivas_fb_mixer_cross_fading_fx( hFbMixer, ppOut_pcm_fx, pMdft_out_fx[0], pMdft_out_fx[1], ch, frame_len, frame_len ); + q_ppOut_pcm_fx[ch] = q_pOut_fr_fx; + move16(); + } + + return; +} + +#else void ivas_fb_mixer_process( IVAS_FB_MIXER_HANDLE hFbMixer, /* i/o: FB mixer handle */ float ***mixer_mat, /* i : mixer matrix */ @@ -1415,13 +1591,27 @@ void ivas_fb_mixer_process( const float *pFilterbank_bin_to_band_re; const float *pFilterbank_bin_to_band_im; float *pMdft_out[2], *pOut_fr_re, *pOut_fr_im; +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + Word32 *pMdft_out_fx[2]; + Word32 **ppOut_pcm_fx = (Word32 **) malloc( hFbMixer->fb_cfg->num_out_chans * sizeof( Word32 * ) ); + for ( ch = 0; ch < hFbMixer->fb_cfg->num_out_chans; ch++ ) + { + ppOut_pcm_fx[ch] = (Word32 *) malloc( frame_len * sizeof( Word32 ) ); + } +#endif float Out_fr_re[L_FRAME48k], Out_fr_im[L_FRAME48k]; float Mdft_out_0[L_FRAME48k * 2], Mdft_out_1[L_FRAME48k * 2]; - +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + Word32 Mdft_out_0_fx[L_FRAME48k * 2], Mdft_out_1_fx[L_FRAME48k * 2]; +#endif pOut_fr_re = Out_fr_re; pOut_fr_im = Out_fr_im; pMdft_out[0] = Mdft_out_0; pMdft_out[1] = Mdft_out_1; +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + pMdft_out_fx[0] = Mdft_out_0_fx; + pMdft_out_fx[1] = Mdft_out_1_fx; +#endif for ( ch = ( hFbMixer->fb_cfg->active_w_mixing == 0 ); ch < hFbMixer->fb_cfg->num_out_chans; ch++ ) { @@ -1476,14 +1666,32 @@ void ivas_fb_mixer_process( ivas_imdft( pOut_fr_re, pOut_fr_im, pMdft_out[hist], frame_len ); } - +#ifndef IVAS_FLOAT_FIXED ivas_fb_mixer_cross_fading( hFbMixer, ppOut_pcm, pMdft_out[0], pMdft_out[1], ch, frame_len, frame_len ); +#else +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + Word16 q1 = Q_factor_arrL( pMdft_out[0], frame_len * 2 ); + Word16 q2 = Q_factor_arrL( pMdft_out[1], frame_len * 2 ); + Word16 q = s_min( q1, q2 ); + floatToFixed_arrL( pMdft_out[0], pMdft_out_fx[0], q, frame_len * 2 ); + floatToFixed_arrL( pMdft_out[1], pMdft_out_fx[1], q, frame_len * 2 ); +#endif + ivas_fb_mixer_cross_fading_fx( hFbMixer, ppOut_pcm_fx, pMdft_out_fx[0], pMdft_out_fx[1], ch, frame_len, frame_len ); +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + fixedToFloat_arrL( ppOut_pcm_fx[ch], ppOut_pcm[ch], q, frame_len ); +#endif +#endif } - +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + for ( ch = 0; ch < hFbMixer->fb_cfg->num_out_chans; ch++ ) + { + free( ppOut_pcm_fx[ch] ); + } + free( ppOut_pcm_fx ); +#endif return; } - - +#endif /*-----------------------------------------------------------------------------------------* * Function ivas_fb_mixer_get_in_out_mapping() * diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index db7ec4ee2..5e1214c42 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -4706,6 +4706,23 @@ int16_t ivas_chan_project_elevation_index( ); #endif +#ifdef IVAS_FLOAT_FIXED +void ivas_dirac_param_est_enc( + DIRAC_ENC_HANDLE hDirAC, + IVAS_QDIRECTION *q_direction, + const UWord8 useLowerRes, + Word32 *data_f_fx[], + Word32 **pp_fr_real_fx, + Word32 **pp_fr_imag_fx, + Word16 pp_fr_q, + const Word16 input_frame, + const IVAS_FORMAT ivas_format, + const Word16 hodirac_flag, + const Word16 nchan_fb_in, + Word16 *mono_frame_count, + Word16 *dirac_mono_flag +); +#else void ivas_dirac_param_est_enc( DIRAC_ENC_HANDLE hDirAC, IVAS_QDIRECTION *q_direction, @@ -4720,6 +4737,7 @@ void ivas_dirac_param_est_enc( int16_t *mono_frame_count, int16_t *dirac_mono_flag ); +#endif void ivas_sba_config( @@ -8409,14 +8427,25 @@ void ivas_fb_mixer_get_windowed_fr( const int16_t nchan_fb_in /* i : number of analysis channels */ ); +#ifdef IVAS_FLOAT_FIXED void ivas_fb_mixer_process( IVAS_FB_MIXER_HANDLE hFbMixer, /* i/o: FB mixer handle */ - float ***mixer_mat, /* i : mixer matrix */ - float **ppOut_pcm, /* o : output audio channels */ + Word32 ***mixer_mat_fx, /* i : mixer matrix in q_mixer_mat_fx */ + Word16 *q_mixer_mat_fx, /* i : mixer matrix */ + Word32 **ppOut_pcm_fx, /* o : output audio channels in ppOut_pcm_fx resultant */ + Word16 *q_ppOut_pcm_fx, /*ppOut_pcm_fx resultant q*/ const int16_t frame_len, /* i : frame length in samples */ int16_t in_out_mixer_map[IVAS_MAX_FB_MIXER_OUT_CH][IVAS_MAX_SPAR_FB_MIXER_IN_CH] /* i/o: mixing mapping */ ); - +#else +void ivas_fb_mixer_process( + IVAS_FB_MIXER_HANDLE hFbMixer, /* i/o: FB mixer handle */ + float ***mixer_mat, /* i : mixer matrix */ + float **ppOut_pcm, /* o : output audio channels */ + const int16_t frame_len, /* i : frame length in samples */ + int16_t in_out_mixer_map[IVAS_MAX_FB_MIXER_OUT_CH][IVAS_MAX_SPAR_FB_MIXER_IN_CH] /* i/o: mixing mapping */ +); +#endif void ivas_fb_mixer_get_in_out_mapping( const IVAS_FB_CFG *fb_cfg, /* i : FB config. handle */ int16_t in_out_mixer_map[IVAS_MAX_FB_MIXER_OUT_CH][IVAS_MAX_SPAR_FB_MIXER_IN_CH] /* i/o: mixing mapping */ diff --git a/lib_com/ivas_prot_fx.h b/lib_com/ivas_prot_fx.h index 07f548f32..121570bc3 100644 --- a/lib_com/ivas_prot_fx.h +++ b/lib_com/ivas_prot_fx.h @@ -1911,16 +1911,16 @@ void ivas_GenShapedWBExcitation_fx( const Word16 uv_flag, /* i : unvoiced flag */ const Word16 igf_flag ); -Word16 ivas_wb_bwe_dec_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word16 output[], /* i : suntehsis @ internal Fs */ - Word16 *synth_fx, /* i/o: ACELP core synthesis/final synthesis */ - Word16 *hb_synth_fx, /* o : SHB synthesis/final synthesis */ - const Word16 use_cldfb_for_dft, /* i : flag to use of CLDFB for DFT Stereo */ - const Word16 output_frame, /* i : frame length */ - Word16 *voice_factors_fx, /* i : voicing factors */ - const Word16 pitch_buf_fx[], /* i : pitch buffer */ - Word16 *Qpost ); +Word16 ivas_wb_bwe_dec_fx( /* o : Q_syn_hb*/ + Decoder_State *st_fx, /* i/o: decoder state structure */ + const Word16 output[], /* i : suntehsis @ internal Fs Q_input */ + Word16 *synth_fx, /* i/o: ACELP core synthesis/final synthesis Q0/Qpost */ + Word16 *hb_synth_fx, /* o : SHB synthesis/final synthesis Q_syn_hb */ + const Word16 use_cldfb_for_dft, /* i : flag to use of CLDFB for DFT Stereo */ + const Word16 output_frame, /* i : frame length */ + Word16 *voice_factors_fx, /* i : voicing factors Q15 */ + const Word16 pitch_buf_fx[], /* i : pitch buffer Q6 */ + Word16 *Qpost ); void ivas_param_ism_config_fx( PARAM_ISM_CONFIG_HANDLE hParamIsm, /* i/o: IVAS Param ISM Config Structure */ diff --git a/lib_com/ivas_rom_com_fx.c b/lib_com/ivas_rom_com_fx.c index 269c62d28..200c376cb 100644 --- a/lib_com/ivas_rom_com_fx.c +++ b/lib_com/ivas_rom_com_fx.c @@ -1634,46 +1634,76 @@ const Word32 shoebox_sin_cos_tbl_fx[11][2] = { { 0, 1073741824 }, // 0 { 759250112, -759250112 }, { -759250112, -759250112 } }; // 135, -135 //Q.30 -const Word32 delta_phi_val[90] = { - 0, 1509949440, 754974720, 503316480, 377487360, 301989888, - 251658240, 215707056, 188743680, 167772160, 150994944, - 137268128, 125829120, 116149960, 107853528, 100663296, - 94371840, 88820552, 83886080, 79471024, 75497472, - 71902352, 68634064, 65649976, 62914560, 60397976, - 58074980, 55924052, 53926764, 52067224, 50331648, - 48708048, 47185920, 45756044, 44410276, 43141412, - 41943040, 40809444, 39735512, 38716652, 37748736, - 36828036, 35951176, 35115104, 34317032, 33554432, - 32824988, 32126584, 31457280, 30815294, 30198988, - 29606852, 29037490, 28489612, 27962026, 27453626, - 26963382, 26490342, 26033612, 25592364, 25165824, - 24753270, 24354024, 23967452, 23592960, 23229992, - 22878022, 22536558, 22205138, 21883326, 21570706, - 21266894, 20971520, 20684238, 20404722, 20132660, - 19867756, 19609732, 19358326, 19113284, 18874368, - 18641352, 18414018, 18192162, 17975588, 17764112, - 17557552, 17355740, 17158516, 16965724 +const Word32 delta_phi_val[257] = { + 0, + 1509949440, 754974720, 503316480, 377487360, 301989888, 251658240, 215707056, 188743680, + 167772160, 150994944, 137268128, 125829120, 116149960, 107853528, 100663296, 94371840, + 88820552, 83886080, 79471024, 75497472, 71902352, 68634064, 65649976, 62914560, + 60397976, 58074980, 55924052, 53926764, 52067224, 50331648, 48708048, 47185920, + 45756044, 44410276, 43141412, 41943040, 40809444, 39735512, 38716652, 37748736, + 36828036, 35951176, 35115104, 34317032, 33554432, 32824988, 32126584, 31457280, + 30815294, 30198988, 29606852, 29037490, 28489612, 27962026, 27453626, 26963382, + 26490342, 26033612, 25592364, 25165824, 24753270, 24354024, 23967452, 23592960, + 23229992, 22878022, 22536558, 22205138, 21883326, 21570706, 21266894, 20971520, + 20684238, 20404722, 20132660, 19867756, 19609732, 19358326, 19113284, 18874368, + 18641352, 18414018, 18192162, 17975588, 17764112, 17557552, 17355740, 17158516, + 16965724, 16777216, 16592851, 16412494, 16236015, 16063292, 15894205, 15728640, + 15566489, 15407647, 15252015, 15099494, 14949994, 14803426, 14659703, 14518745, + 14380471, 14244806, 14111677, 13981013, 13852747, 13726813, 13603148, 13481691, + 13362384, 13245171, 13129995, 13016806, 12905551, 12796182, 12688651, 12582912, + 12478921, 12376635, 12276012, 12177012, 12079596, 11983726, 11889366, 11796480, + 11705034, 11614996, 11526332, 11439011, 11353003, 11268279, 11184811, 11102569, + 11021529, 10941663, 10862946, 10785353, 10708861, 10633447, 10559087, 10485760, + 10413444, 10342119, 10271765, 10202361, 10133889, 10066330, 9999665, 9933878, + 9868951, 9804866, 9741609, 9679163, 9617512, 9556642, 9496537, 9437184, + 9378568, 9320676, 9263493, 9207009, 9151209, 9096081, 9041613, 8987794, + 8934612, 8882056, 8830114, 8778776, 8728031, 8677870, 8628283, 8579258, + 8530788, 8482862, 8435472, 8388608, 8342262, 8296425, 8251090, 8206247, + 8161889, 8118007, 8074596, 8031646, 7989150, 7947102, 7905494, 7864320, + 7823572, 7783244, 7743330, 7703823, 7664718, 7626007, 7587685, 7549747, + 7512186, 7474997, 7438174, 7401713, 7365607, 7329851, 7294441, 7259372, + 7224638, 7190235, 7156158, 7122403, 7088964, 7055838, 7023020, 6990506, + 6958292, 6926373, 6894746, 6863406, 6832350, 6801574, 6771073, 6740845, + 6710886, 6681192, 6651759, 6622585, 6593665, 6564997, 6536577, 6508403, + 6480469, 6452775, 6425317, 6398091, 6371094, 6344325, 6317780, 6291456, + 6265350, 6239460, 6213783, 6188317, 6163059, 6138006, 6113155, 6088506, + 6064054, 6039798, 6015735, 5991863, 5968179, 5944683, 5921370, 5898240 }; -const Word32 inv_delta_phi_val[90] = { - 0, 5965232, 11930464, 17895697, 23860929, 29826161, - 35791394, 41756626, 47721858, 53687091, 59652323, - 65617555, 71582788, 77548020, 83513252, 89478485, - 95443717, 101408950, 107374182, 113339414, 119304647, - 125269879, 131235111, 137200344, 143165576, 149130808, - 155096041, 161061273, 167026505, 172991738, 178956970, - 184922203, 190887435, 196852667, 202817900, 208783132, - 214748364, 220713597, 226678829, 232644061, 238609294, - 244574526, 250539758, 256504991, 262470223, 268435456, - 274400688, 280365920, 286331153, 292296385, 298261617, - 304226850, 310192082, 316157314, 322122547, 328087779, - 334053011, 340018244, 345983476, 351948708, 357913941, - 363879173, 369844406, 375809638, 381774870, 387740103, - 393705335, 399670567, 405635800, 411601032, 417566264, - 423531497, 429496729, 435461961, 441427194, 447392426, - 453357659, 459322891, 465288123, 471253356, 477218588, - 483183820, 489149053, 495114285, 501079517, 507044750, - 513009982, 518975214, 524940447, 530905679 +const Word32 inv_delta_phi_val[257] = { + 0, + 5965232, 11930465, 17895698, 23860930, 29826162, 35791396, 41756628, 47721860, + 53687092, 59652324, 65617556, 71582792, 77548024, 83513256, 89478488, 95443720, + 101408952, 107374184, 113339416, 119304648, 125269880, 131235112, 137200352, 143165584, + 149130816, 155096048, 161061280, 167026512, 172991744, 178956976, 184922208, 190887440, + 196852672, 202817904, 208783136, 214748368, 220713600, 226678832, 232644064, 238609296, + 244574528, 250539760, 256504992, 262470224, 268435456, 274400704, 280365920, 286331168, + 292296384, 298261632, 304226848, 310192096, 316157312, 322122560, 328087776, 334053024, + 340018240, 345983488, 351948704, 357913952, 363879168, 369844416, 375809632, 381774880, + 387740096, 393705344, 399670560, 405635808, 411601024, 417566272, 423531488, 429496736, + 435461952, 441427200, 447392416, 453357664, 459322880, 465288128, 471253344, 477218592, + 483183808, 489149056, 495114272, 501079520, 507044736, 513009984, 518975200, 524940448, + 530905664, 536870912, 542836160, 548801408, 554766592, 560731840, 566697088, 572662336, + 578627520, 584592768, 590558016, 596523264, 602488448, 608453696, 614418944, 620384192, + 626349376, 632314624, 638279872, 644245120, 650210304, 656175552, 662140800, 668106048, + 674071232, 680036480, 686001728, 691966976, 697932160, 703897408, 709862656, 715827904, + 721793088, 727758336, 733723584, 739688832, 745654016, 751619264, 757584512, 763549760, + 769514944, 775480192, 781445440, 787410688, 793375872, 799341120, 805306368, 811271616, + 817236864, 823202048, 829167296, 835132544, 841097792, 847062976, 853028224, 858993472, + 864958720, 870923904, 876889152, 882854400, 888819648, 894784832, 900750080, 906715328, + 912680576, 918645760, 924611008, 930576256, 936541504, 942506688, 948471936, 954437184, + 960402432, 966367616, 972332864, 978298112, 984263360, 990228544, 996193792, 1002159040, + 1008124288, 1014089472, 1020054720, 1026019968, 1031985216, 1037950400, 1043915648, 1049880896, + 1055846144, 1061811328, 1067776576, 1073741824, 1079707008, 1085672320, 1091637504, 1097602816, + 1103568000, 1109533184, 1115498496, 1121463680, 1127428864, 1133394176, 1139359360, 1145324672, + 1151289856, 1157255040, 1163220352, 1169185536, 1175150720, 1181116032, 1187081216, 1193046528, + 1199011712, 1204976896, 1210942208, 1216907392, 1222872576, 1228837888, 1234803072, 1240768384, + 1246733568, 1252698752, 1258664064, 1264629248, 1270594432, 1276559744, 1282524928, 1288490240, + 1294455424, 1300420608, 1306385920, 1312351104, 1318316288, 1324281600, 1330246784, 1336212096, + 1342177280, 1348142464, 1354107776, 1360072960, 1366038272, 1372003456, 1377968640, 1383933952, + 1389899136, 1395864320, 1401829632, 1407794816, 1413760128, 1419725312, 1425690496, 1431655808, + 1437620992, 1443586176, 1449551488, 1455516672, 1461481984, 1467447168, 1473412352, 1479377664, + 1485342848, 1491308032, 1497273344, 1503238528, 1509203840, 1515169024, 1521134208, 1527099520 }; const Word32 dd_val[90] = { diff --git a/lib_com/ivas_rom_com_fx.h b/lib_com/ivas_rom_com_fx.h index 4cf61f9ae..6d4f50fa8 100644 --- a/lib_com/ivas_rom_com_fx.h +++ b/lib_com/ivas_rom_com_fx.h @@ -188,8 +188,8 @@ extern const Word16 ls_elevation_CICP19_idx[11]; extern const Word32 shoebox_sin_cos_tbl_fx[11][2]; -extern const Word32 delta_phi_val[90]; -extern const Word32 inv_delta_phi_val[90]; +extern const Word32 delta_phi_val[257]; +extern const Word32 inv_delta_phi_val[257]; extern const Word32 dd_val[90]; extern const Word32 cb_azi_chan_fx[]; // Q22 extern const Word16 cb_azi_chan_16fx[]; // Q0 diff --git a/lib_com/ivas_stat_com.h b/lib_com/ivas_stat_com.h index 5fdcf2bc1..a4d1065f4 100644 --- a/lib_com/ivas_stat_com.h +++ b/lib_com/ivas_stat_com.h @@ -871,6 +871,7 @@ typedef struct ivas_fb_mixer_state_structure Word16 q_ppFilterbank_inFR_im_fx[IVAS_MAX_FB_MIXER_IN_CH]; Word16 q_ppFilterbank_prior_input_fx[IVAS_MAX_FB_MIXER_IN_CH]; Word32 *prior_mixer_fx[IVAS_MAX_FB_MIXER_OUT_CH][IVAS_MAX_SPAR_FB_MIXER_IN_CH]; + Word16 q_prior_mixer_fx; #endif /* store sin part in const table (no need to store 1s and 0s, no need to do windowing for 1's and 0's as well) */ diff --git a/lib_com/prot.h b/lib_com/prot.h index d0fc8d2ff..d286851e0 100644 --- a/lib_com/prot.h +++ b/lib_com/prot.h @@ -240,11 +240,13 @@ void mvl2l( const int16_t n /* i : vector size */ ); +#ifndef IVAS_FLOAT_FIXED void AGC_dec( float x[], /* i/o: input/output vector */ float mem[], /* i/o: mem[2] should be init to [0,0] */ const int16_t n /* i : vector size */ ); +#endif /*! r: index of the maximum value in the input vector */ int16_t maximum( @@ -2792,13 +2794,13 @@ void GenTransition( void GenTransition_fixed( - TD_BWE_DEC_HANDLE hBWE_TD, /* i/o: TD BWE data handle */ - Word32 *outputHB_fx, /* o : synthesized HB transitions signal */ - const int32_t output_Fs, /* i : output sampling rate */ - const int16_t element_mode, /* i : element mode */ - const int16_t L_frame, /* i : ACELP frame length */ - const int16_t rf_flag, /* i : RF flag */ - const int32_t total_brate, /* i : total bitrate */ + TD_BWE_DEC_HANDLE hBWE_TD, /* i/o: TD BWE data handle */ + Word32 *outputHB_fx, /* o : synthesized HB transitions signal : Q11 */ + const Word32 output_Fs, /* i : output sampling rate : Q0 */ + const Word16 element_mode, /* i : element mode : Q0 */ + const Word16 L_frame, /* i : ACELP frame length : Q0 */ + const Word16 rf_flag, /* i : RF flag : Q0 */ + const Word32 total_brate, /* i : total bitrate : Q0 */ const Word16 prev_Qx ); void GenTransition_WB( @@ -2808,9 +2810,9 @@ void GenTransition_WB( ); void GenTransition_WB_fixed( - TD_BWE_DEC_HANDLE hBWE_TD, /* i/o: TD BWE data handle */ - Word32 *outputHB_fx, /* o : synthesized HB transitions signal */ - const int32_t output_Fs /* i : output sampling rate */ + TD_BWE_DEC_HANDLE hBWE_TD, /* i/o: TD BWE data handle */ + Word32 *outputHB_fx, /* o : synthesized HB transitions signal : Q11 */ + const Word32 output_Fs /* i : output sampling rate */ ); void td_bwe_dec_init( @@ -4923,11 +4925,13 @@ void dec_acelp_4t64( const int16_t Opt_AMR_WB /* i : flag indicating AMR-WB IO mode */ ); +#ifndef IVAS_FLOAT_FIXED uint32_t syn_output( float *synth, /* i/o: float synthesis signal */ const int16_t output_frame, /* i : output frame length */ int16_t *synth_out /* o : integer 16 bits synthesis signal */ ); +#endif void FEC_exc_estim( Decoder_State *st, /* i/o: Decoder static memory */ diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index 1a1b8a81a..da45e5743 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -6372,20 +6372,20 @@ void hf_synth_reset_fx( ); void hf_synth_fx( - ZERO_BWE_DEC_HANDLE hBWE_zero, /* i/o: handle to 0 bit BWE parameters */ - const Word32 core_brate, /* i : core bitrate */ - const Word16 output_frame, /* i : output frame length */ - const Word16 *Aq, /* i : quantized Az */ - const Word16 *exc, /* i : excitation at 12.8 kHz */ - Word16 *synth, /* i : 12.8kHz synthesis signal */ - Word16 *synth16k, /* o : 16kHz synthesis signal */ + ZERO_BWE_DEC_HANDLE hBWE_zero, /* i/o: handle to 0 bit BWE parameters */ + const Word32 core_brate, /* i : core bitrate Q0*/ + const Word16 output_frame, /* i : output frame length Q0*/ + const Word16 *Aq, /* i : quantized Az Q12*/ + const Word16 *exc, /* i : excitation at 12.8 kHz Q_exc*/ + Word16 *synth, /* i : 12.8kHz synthesis signal Q_syn2*/ + Word16 *synth16k, /* o : 16kHz synthesis signal Q_syn2*/ const Word16 Q_exc, /* i : excitation scaling */ const Word16 Q_syn2, /* i : synthesis scaling */ - Word16 *delay_syn_hf, /*i/o: HF synthesis memory */ + Word16 *delay_syn_hf, /*i/o: HF synthesis memory Q_syn2*/ Word16 *memExp1, /* o : HF excitation exponent */ - Word16 *mem_hp_interp, /* i/o: interpol. memory */ - const Word16 extl, /* i : flag indicating BWE */ - const Word16 CNG_mode /* i : CNG_mode */ + Word16 *mem_hp_interp, /* i/o: interpol. memory Qx*/ + const Word16 extl, /* i : flag indicating BWE Q0*/ + const Word16 CNG_mode /* i : CNG_mode Q0*/ ); void hf_synth_amr_wb_init_fx( @@ -6400,21 +6400,21 @@ void hf_synth_amr_wb_reset_fx( void hf_synth_amr_wb_fx( AMRWB_IO_DEC_HANDLE hAmrwb_IO, /* i/o: AMR-WB IO data handle */ ZERO_BWE_DEC_HANDLE hBWE_zero, /* o : zero BWE decoder handle */ - const Word32 core_brate, /* i : core bitrate */ - const Word16 output_frame, /* i : output frame length */ - const Word16 *Aq, /* i : quantized Az : Q12 */ - const Word16 *exc, /* i : excitation at 12.8 kHz : Q_exc */ - Word16 *synth, /* i/o: synthesis signal at 12.8k : Q_syn */ - Word16 *amr_io_class, /* i : signal class (determined by FEC algorithm) */ - Word16 *synth_out, /* i/o: output signal at output Fs : Q_out */ - Word16 fmerit, /* i : classify parameter from FEC : Q14 */ - const Word16 *hf_gain, /* i : decoded HF gain */ - const Word16 *voice_factors, /* i : voicing factors : Q15 */ - const Word16 pitch_buf[], /* i : pitch buffer : Q5 */ - const Word16 ng_ener_ST, /* i : Noise gate - short-term energy : Q8 */ - const Word16 *lsf_new, /* i : ISF vector : Q2 */ - const Word16 Q_exc, /* i : exc scaling */ - const Word16 Q_out /* i : Q_syn2-1 */ + const Word32 core_brate, /* i : core bitrate Q0*/ + const Word16 output_frame, /* i : output frame length Q0*/ + const Word16 *Aq, /* i : quantized Az : Q12*/ + const Word16 *exc, /* i : excitation at 12.8 kHz : Q_exc*/ + Word16 *synth, /* i/o: synthesis signal at 12.8k : Q_syn*/ + Word16 *amr_io_class, /* i : signal class (determined by FEC algorithm) Q0*/ + Word16 *synth_out, /* i/o: output signal at output Fs : Q_out*/ + Word16 fmerit, /* i : classify parameter from FEC : Q14*/ + const Word16 *hf_gain, /* i : decoded HF gain Q0*/ + const Word16 *voice_factors, /* i : voicing factors : Q15*/ + const Word16 pitch_buf[], /* i : pitch buffer : Q5*/ + const Word16 ng_ener_ST, /* i : Noise gate - short-term energy : Q8*/ + const Word16 *lsf_new, /* i : ISF vector : Q2*/ + const Word16 Q_exc, /* i : exc scaling */ + const Word16 Q_out /* i : Q_syn2-1 */ ); // dec_post_fx @@ -6518,19 +6518,20 @@ void init_tcx_cfg_fx( // syn_outp_fx.c void syn_output_fx( - const Word16 codec_mode, /* i : MODE1 or MODE2 */ - Word16 *synth, /* i/o: float synthesis signal */ - const Word16 output_frame, /* i : output frame length */ - Word16 *synth_out, /* o : integer 16 bits synthesis signal */ - const Word16 Q_syn2 /* i : Synthesis scaling factor */ + const Word16 codec_mode, /* i : MODE1 or MODE2 */ + Word16 *synth, /* i/o: fixed point synthesis signal Q_syn2 */ + const Word16 output_frame, /* i : output frame length */ + Word16 *synth_out, /* o : integer 16 bits synthesis signal Q_syn2 */ + const Word16 Q_syn2 /* i : Synthesis scaling factor */ ); void unscale_AGC( - const Word16 x[], - const Word16 Qx, - Word16 y[], - Word16 mem[], - const Word16 n ); + const Word16 x[], /* i: 16kHz synthesis Qx */ + const Word16 Qx, /* i: scale factor of x */ + Word16 y[], /* o: output vector Q0 */ + Word16 mem[], /* i/o: mem[2] should be init to [0,0] Q0 */ + const Word16 n /* i: vector size */ +); // bass_psfilter_fx.c void bass_psfilter_init_fx( @@ -7514,21 +7515,21 @@ void destroy_cldfb_decoder_fx( // swb_bwe_dec_fx.c Word16 WB_BWE_gain_deq_fx( Decoder_State *st_fx, /* i/o: decoder state structure */ - Word16 *WB_fenv ); - + Word16 *WB_fenv /*Q15*/ +); Word16 wb_bwe_dec_fx( #ifdef ADD_IVAS_BWE const Word16 output[], /* i : suntehsis @ internal Fs */ #endif - Word16 *synth_fx, /* i/o: ACELP core synthesis/final synthesis */ - Word16 *hb_synth_fx, /* o : SHB synthesis/final synthesis */ + Word16 *synth_fx, /* i/o: ACELP core synthesis/final synthesis Q0/Qpost */ + Word16 *hb_synth_fx, /* o : SHB synthesis/final synthesis Q_syn_hb */ #ifdef ADD_IVAS_BWE const Word16 use_cldfb_for_dft, /* i : flag to use of CLDFB for DFT Stereo */ #endif const Word16 output_frame, /* i : frame length */ - Word16 *voice_factors_fx, /* i : voicing factors */ - const Word16 pitch_buf_fx[], /* i : pitch buffer */ + Word16 *voice_factors_fx, /* i : voicing factors Q15 */ + const Word16 pitch_buf_fx[], /* i : pitch buffer Q6 */ Decoder_State *st_fx /* i/o: decoder state structure */ , Word16 *Qpost ); @@ -7542,19 +7543,19 @@ Word16 swb_bwe_gain_deq_fx( /* o : BWE class const Word16 hqswb_clas /* i : HQ BWE class */ ); -Word16 swb_bwe_dec_fx( +Word16 swb_bwe_dec_fx( /*o :Q_syn_hb*/ #ifdef ADD_IVAS_BWE - const Word16 output[], /* i : suntehsis @ internal Fs */ + const Word16 output[], /* i : suntehsis @ internal Fs */ #endif - Decoder_State *st_fx, /* i/o: decoder state structure */ - Word16 *synth_fx, /* i : ACELP core synthesis/final synthesis */ - Word16 *hb_synth, /* o : SHB synthesis/final synthesis */ + Decoder_State *st_fx, /* i/o: decoder state structure */ + Word16 *synth_fx, /* i/o: ACELP core synthesis/final synthesis (might be rescaled inside wtda() ) Q0/Qpost */ + Word16 *hb_synth_fx, /* o : SHB synthesis/final synthesis Q_syn_hb */ #ifdef ADD_IVAS_BWE - const Word16 use_cldfb_for_dft, /* i : flag to use of CLDFB for DFT Stereo */ + const Word16 use_cldfb_for_dft, /* i : flag to use of CLDFB for DFT Stereo */ #endif - const Word16 output_frame /* i : frame length */ - , - Word16 *Qpost ); + const Word16 output_frame /* i : frame length */ + , + Word16 *Qpost ); void fd_bwe_dec_init( Decoder_State *st_fx, /* i/o: decoder state structure */ @@ -7573,11 +7574,11 @@ void hq_core_enc_ivas_fx( // hq_core_dec_fx.c void hq_core_dec_fx( Decoder_State *st_fx, /* i/o: decoder state structure fx */ - Word16 synth[], /* o : output synthesis */ + Word16 synth[], /* o : output synthesis Q_synth*/ Word16 *Q_synth, /* o : Q value of synth */ - const Word16 output_frame, /* i : output frame length */ - const Word16 hq_core_type, /* i : HQ core type */ - const Word16 core_switching_flag /* i : ACELP->HQ switching frame flag */ + const Word16 output_frame, /* i : output frame length Q0*/ + const Word16 hq_core_type, /* i : HQ core type Q0*/ + const Word16 core_switching_flag /* i : ACELP->HQ switching frame flag Q0*/ ); void HQ_core_dec_init_fx( HQ_DEC_HANDLE hHQ_core /* i/o: HQ core data handle */ @@ -7623,24 +7624,24 @@ void hq_lr_dec_fx( ); // gq_env_dec_fx.c -Word16 decode_envelope_indices_fx( /* o : Number of bits */ +Word16 decode_envelope_indices_fx( /* o : Number of bits Q0*/ Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word16 start_norm, /* i : starting band index */ - const Word16 num_sfm, /* i : Number of subbands */ - const Word16 numnrmibits, /* i : Bitrate of fall-back coding mode */ - Word16 *difidx, /* o : Diff indices/encoded diff indices */ - const Word16 flag_HQ2 /* i : indicator of HQ2 core */ + const Word16 start_norm, /* i : starting band index Q0*/ + const Word16 num_sfm, /* i : Number of subbands Q0*/ + const Word16 numnrmibits, /* i : Bitrate of fall-back coding mode Q0*/ + Word16 *difidx, /* o : Diff indices/encoded diff indices Q0*/ + const Word16 flag_HQ2 /* i : indicator of HQ2 core Q0*/ , - const Word16 is_transient /* i : indicator of HQ_TRANSIENT */ + const Word16 is_transient /* i : indicator of HQ_TRANSIENT Q0*/ ); void dequantize_norms_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word16 start_norm, /* i : First SDE encoded norm */ - const Word16 num_sfm, /* i : Number of norms */ - const Word16 is_transient, /* i : Transient flag */ - Word16 *ynrm, /* o : Decoded norm indices */ - Word16 *normqlg2 /* o : Log2 of decoded norms */ + Decoder_State *st_fx, /* i/o: decoder state structure */ + const Word16 start_norm, /* i : First SDE encoded norm Q0*/ + const Word16 num_sfm, /* i : Number of norms Q0*/ + const Word16 is_transient, /* i : Transient flag Q0*/ + Word16 *ynrm, /* o : Decoded norm indices Q0*/ + Word16 *normqlg2 /* o : Log2 of decoded norms Q0*/ ); #ifdef IVAS_FLOAT_FIXED @@ -7690,20 +7691,21 @@ void hdecnrm_tran_fx( // tcq_core_dec_fx.c void tcq_core_LR_dec_fx( Decoder_State *st_fx, - Word16 *inp_vector_fx, - const Word16 bit_budget, - const Word16 bands, - const Word16 *band_start, - const Word16 *band_width, - Word32 *Rk_fx, - Word16 *npulses, - Word16 *k_sort, - const Word16 *p2a_flags, - const Word16 p2a_bands, - const Word16 *last_bitalloc, - const Word16 input_frame, - const Word16 adjustFlag, - const Word16 *is_transient ); + Word16 *inp_vector_fx, /*x5 */ + const Word16 bit_budget, /*Q0 */ + const Word16 BANDS, /*Q0 */ + const Word16 *band_start, /*Q0 */ + const Word16 *band_width, /*Q0 */ + Word32 *Rk_fx, /*Q16*/ + Word16 *npulses, /*Q0 */ + Word16 *k_sort, /*Q0 */ + const Word16 *p2a_flags, /*Q0 */ + const Word16 p2a_bands, /*Q0 */ + const Word16 *last_bitalloc, /*Q0 */ + const Word16 input_frame, /*Q0 */ + const Word16 adjustFlag, /*Q0 */ + const Word16 *is_transient /*Q0 */ +); // FEC_HQ_core_fx.c void HQ_FEC_processing_fx( @@ -7745,11 +7747,11 @@ void time_domain_FEC_HQ_fx( // hq_hr_dec_fx.c void hq_pred_hb_bws_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word16 *ynrm, /* i : norm quantization index vector */ - const Word16 length, /* i : frame length */ - const Word16 hqswb_clas, /* i : HQ SWB class */ - const Word16 *SWB_fenv /* i : SWB frequency envelopes Q1 */ + Decoder_State *st_fx, /* i/o: decoder state structure */ + const Word16 *ynrm, /* i : norm quantization index vector Q0*/ + const Word16 length, /* i : frame length Q0*/ + const Word16 hqswb_clas, /* i : HQ SWB class Q0*/ + const Word16 *SWB_fenv /* i : SWB frequency envelopes Q1*/ ); void hq_hr_dec_fx( @@ -7761,7 +7763,7 @@ void hq_hr_dec_fx( Word16 *is_transient, /* o : transient flag Q0 */ Word16 *hqswb_clas, /* o : HQ SWB class Q0 */ Word16 *SWB_fenv, /* o : SWB frequency envelopes Q1 */ - const Word16 core_switching_flag /* i : Core switching flag */ + const Word16 core_switching_flag /* i : Core switching flag Q1 */ ); // hq_classifier_dec_fx.c @@ -7804,12 +7806,12 @@ Word16 hvq_pvq_bitalloc_fx( // hq_conf_fec_fx.c void hq_configure_bfi_fx( - Word16 *nb_sfm, /* o : Number of sub bands Q0 */ - Word16 *num_Sb, /* o : Number of FEC sub bands ? Q0 */ - Word16 *num_bands_p, /* o : FEC sub bands Q0 */ - const Word16 **sfmsize, /* o : Subband bandwidths */ - const Word16 **sfm_start, /* o : Subband start coefficients */ - const Word16 **sfm_end /* o : Subband end coefficients */ + Word16 *nb_sfm, /* o : Number of sub bands Q0*/ + Word16 *num_Sb, /* o : Number of FEC sub bands ? Q0*/ + Word16 *num_bands_p, /* o : FEC sub bands Q0*/ + const Word16 **sfmsize, /* o : Subband bandwidths Q0*/ + const Word16 **sfm_start, /* o : Subband start coefficients Q0*/ + const Word16 **sfm_end /* o : Subband end coefficients Q0*/ ); // core_switching_dec_fx.c @@ -8255,14 +8257,14 @@ void tcxltp_dec_init_fx( const Word32 sr_core ); /* Q0 */ // swb_bwe_dec_hr_fx.c -Word16 swb_bwe_dec_hr_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word16 *syn_12k8_16k_fx, /* i : ACELP core synthesis @16kHz */ - const Word16 old_syn_exp, /* i : Exponent of core synthesis */ - Word16 *hb_synth_fx, /* o : SHB synthesis */ - const Word16 output_frame, /* i : frame length */ - const Word16 unbits, /* i : number of core unused bits */ - const Word16 pitch_buf[] /* i : pitch buffer */ +Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB synthesis */ + Decoder_State *st_fx, /* i/o: decoder state structure */ + const Word16 *syn_12k8_16k_fx, /* i : ACELP core synthesis @16kHz : Q(15 - exp) */ + const Word16 exp, /* i : Exponent of core synthesis */ + Word16 *hb_synth_fx, /* o : SHB synthesis : Q(15 - hb_synth_fx_exp)*/ + const Word16 output_frame, /* i : frame length */ + const Word16 unbits, /* i : number of core unused bits */ + const Word16 pitch_buf[] /* i : pitch buffer : Q6 */ ); void hr_bwe_dec_init( @@ -8517,26 +8519,26 @@ ivas_error decod_ppp_fx( // swb_bwe_dec_lr_fx.c void swb_bwe_dec_lr_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word32 L_m_core[], /* i : lowband synthesis */ - const Word16 QsL, /* i : Q value of m_core */ - Word32 L_m[], /* o : highband synthesis with lowband zeroed */ - const Word32 L_total_brate, /* i : total bitrate for selecting subband pattern */ - Word16 BANDS_fx, /* i : Number subbands/Frame */ - Word16 *band_start_fx, /* i : Band Start of each SB */ - Word16 *band_end_fx, /* i : Band end of each SB */ - Word32 *L_band_energy, /* i : Band energy of each SB : Qbe */ - Word16 Qbe, /* i : Q value of band energy */ - Word16 *p2a_flags_fx, /* i : HF tonal Indicator */ - const Word16 hqswb_clas_fx, /* i : class information */ - Word16 lowlength_fx, /* i : Lowband Length */ - Word16 highlength_fx, /* i : Highband Length */ - const Word16 har_bands_fx, /* i : Number of LF harmonic bands */ - Word16 *prev_frm_hfe2, /* i/o: */ - Word16 *prev_stab_hfe2, /* i/o: */ - Word16 band_width_fx[], /* i : subband bandwidth */ - const Word32 L_y2_ni[], /* i/o: Sparse filled corecoder */ - Word16 *ni_seed_fx /* i/o: random seed */ + Decoder_State *st_fx, /* i/o: decoder state structure */ + const Word32 L_m_core[], /* i : lowband synthesis : QsL */ + const Word16 QsL, /* i : Q value of m_core */ + Word32 L_m[], /* o : highband synthesis with lowband zeroed : QsL */ + const Word32 L_total_brate, /* i : total bitrate for selecting subband pattern */ + Word16 BANDS_fx, /* i : Number subbands/Frame : Q0 */ + Word16 *band_start_fx, /* i : Band Start of each SB : Q0 */ + Word16 *band_end_fx, /* i : Band end of each SB :Q0 */ + Word32 *L_band_energy, /* i : Band energy of each SB : Qbe */ + Word16 Qbe, /* i : Q value of band energy */ + Word16 *p2a_flags_fx, /* i : HF tonal Indicator : Q0 */ + const Word16 hqswb_clas_fx, /* i : class information : Q0 */ + Word16 lowlength_fx, /* i : Lowband Length : Q0 */ + Word16 highlength_fx, /* i : Highband Length : Q0 */ + const Word16 har_bands_fx, /* i : Number of LF harmonic bands : Q0 */ + Word16 *prev_frm_hfe2, /* i/o: : Q0 */ + Word16 *prev_stab_hfe2, /* i/o: : Q0 */ + Word16 band_width_fx[], /* i : subband bandwidth : Q0 */ + const Word32 L_y2_ni[], /* i/o: Sparse filled corecoder */ + Word16 *ni_seed_fx /* i/o: random seed : QsL */ ); #ifdef IVAS_FLOAT_FIXED @@ -9291,39 +9293,40 @@ void tcx_arith_decode_envelope_fx( // tcx_utils_dec_fx.c void tcx_decoder_memory_update( - Word16 *xn_buf, /* i: mdct output buffer */ - Word16 *synthout, /* i/o: synth */ - Word16 *A, /* i: Quantized LPC coefficients */ - Decoder_State *st, - Word8 fb /* i: fullband flag */ + Word16 *xn_buf, /* i/o: mdct output buffer used also as temporary buffer : Q0 */ + Word16 *synthout, /* o: synth : Q0 */ + Word16 *A, /* i: Quantized LPC coefficients : Q12*/ + Decoder_State *st, /* i/o: decoder memory state */ + Word8 fb /* i: fullband flag */ ); Word16 tcx_ari_res_invQ_spec( - Word32 x_Q[], /* i/o: quantized spectrum Q31-e */ - Word16 x_Q_e, /* i: quantized spectrum exponent Q0 */ - Word16 L_frame, /* i: number of lines Q0 */ - const Word16 prm[], /* i: bit-stream Q0 */ - Word16 target_bits, /* i: number of bits available Q0 */ - Word16 bits, /* i: number of bits used so far Q0 */ - Word16 deadzone, /* i: quantizer deadzone Q15 */ - const Word16 x_fac[] /* i: spectrum post-quantization factors Q14 */ + Word32 x_Q[], /* i/o: quantized spectrum Q(31-x_Q_e) */ + Word16 x_Q_e, /* i: quantized spectrum exponent Q0 */ + Word16 L_frame, /* i: number of lines Q0 */ + const Word16 prm[], /* i: bitstream Q0 */ + Word16 target_bits, /* i: number of bits available Q0 */ + Word16 bits, /* i: number of bits used so far Q0 */ + Word16 deadzone, /* i: quantizer deadzone Q15 */ + const Word16 x_fac[] /* i: spectrum post-quantization factors Q14 */ ); Word16 tcx_res_invQ_gain( - Word16 *gain_tcx, + Word16 *gain_tcx, /* i/o : gain_tcx_e*/ Word16 *gain_tcx_e, - Word16 *prm, + Word16 *prm, /*i*/ Word16 resQBits ); Word16 tcx_res_invQ_spec( - Word32 *x, + Word32 *x, /*Q(31 - x_e)*/ Word16 x_e, Word16 L_frame, Word16 *prm, Word16 resQBits, Word16 bits, - Word16 sq_round, - const Word16 lf_deemph_factors[] ); + Word16 sq_round, /*i : sq deadzone Q15*/ + const Word16 lf_deemph_factors[] /*i : LF deemphasis factors Q14*/ +); // er_dec_acelp_fx.c void con_acelp_fx( @@ -10461,24 +10464,24 @@ void v_sub32_fx( ); void ivas_swb_tbe_dec_fx( - Decoder_State *st, /* i/o: decoder state structure */ - STEREO_ICBWE_DEC_HANDLE hStereoICBWE, /* i/o: IC-BWE state structure */ - const Word32 *bwe_exc_extended_fx, /* i : bandwidth extended excitation */ + Decoder_State *st, /* i/o: decoder state structure */ + STEREO_ICBWE_DEC_HANDLE hStereoICBWE, /* i/o: IC-BWE state structure */ + const Word32 *bwe_exc_extended_fx, /* i : bandwidth extended excitation : Q_exc */ Word16 Q_exc, - const Word16 voice_factors_fx[], /* i : voicing factors */ - const Word32 old_syn_12k8_16k_fx[], /* i : low band synthesis */ - Word16 *White_exc16k_fx, /* o : shaped white excitation for the FB TBE */ - Word32 *synth_fx, /* o : SHB synthesis/final synthesis */ - Word16 *pitch_buf_fx, + const Word16 voice_factors_fx[], /* i : voicing factors : Q15 */ + const Word32 old_syn_12k8_16k_fx[], /* i : low band synthesis : old_syn_fx */ + Word16 *White_exc16k_fx, /* o : shaped white excitation for the FB TBE : Q_white_exc*/ + Word32 *synth_fx, /* o : SHB synthesis/final synthesis : Qx */ + Word16 *pitch_buf_fx, /* i : Q6 */ Word16 *Q_white_exc ); Word16 swb_bwe_dec_fx32( - Decoder_State *st, /* i/o: decoder state structure */ - Word32 output[], /* i : synthesis @internal Fs Q11 */ - Word32 *synth, /* i : ACELP core synthesis/final synthesis Q11 */ - Word32 *hb_synth, /* o : SHB synthesis/final synthesis */ - Word16 use_cldfb_for_dft, /* i : flag to use of CLDFB for DFT Stereo */ - Word16 output_frame /* i : frame length */ + Decoder_State *st_fx, /* i/o: decoder state structure */ + Word32 output_fx[], /* i : synthesis @internal Fs : Q11 */ + Word32 *synth_fx, /* i : ACELP core synthesis/final synthesis : Q11 */ + Word32 *hb_synth_fx, /* o : SHB synthesis/final synthesis : Q_syn_hb */ + Word16 use_cldfb_for_dft, /* i : flag to use of CLDFB for DFT Stereo */ + Word16 output_frame /* i : frame length */ ); ivas_error acelp_core_dec_ivas_fx( diff --git a/lib_com/rom_com.c b/lib_com/rom_com.c index 450c166cb..9047d8338 100644 --- a/lib_com/rom_com.c +++ b/lib_com/rom_com.c @@ -26312,23 +26312,7 @@ const float lsf_q_cb_3b[8] = 0.05307309f, 0.06137543f, 0.07216742f, 0.09013262f }; -const Word16 lsf_q_cb_4b_fx[16] = -{ - 589, 773, 914, 1043, - 1173, 1302, 1430, 1558, - 1698, 1843, 1973, 2103, - 2258, 2470, 2787, 3282 - -}; - -const Word16 lsf_q_cb_3b_fx[8] = -{ - 679, 976, 1245, 1491, - 1739, 2011, 2365, 2953 -}; - const float * const lsf_q_cb[NUM_Q_LSF] = { lsf_q_cb_4b, lsf_q_cb_4b, lsf_q_cb_3b, lsf_q_cb_3b, lsf_q_cb_3b }; -const Word16 * const lsf_q_cb_fx[NUM_Q_LSF] = { lsf_q_cb_4b_fx, lsf_q_cb_4b_fx, lsf_q_cb_3b_fx, lsf_q_cb_3b_fx, lsf_q_cb_3b_fx }; const int16_t lsf_q_cb_size[NUM_Q_LSF] = {16, 16, 8, 8, 8}; const int16_t lsf_q_num_bits[NUM_Q_LSF] = { 4, 4, 3, 3, 3 }; @@ -26344,16 +26328,8 @@ const float lsf_grid[4][5] = { 0.14185823f, 0.26648724f, 0.39740108f, 0.55685745f, 0.74688616f }, { 0.15416561f, 0.27238427f, 0.39376780f, 0.59287916f, 0.86613986f } }; -const Word16 lsf_grid_fx[4][5] = -{ - { 5242, 10229, 15516, 21804, 27540, }, - { 5117, 10059, 14949, 20478, 25493, }, - { 4648, 8732, 13022, 18247, 24474, }, - { 5052, 8925, 12903, 19427, 28382, } -}; -const float grid_smoothing[5] = { 0.2f, 0.35f, 0.5f, 0.75f, 0.8f }; -const Word16 grid_smoothing_fx[5] = { 6554, 11469, 16384, 24576, 26214 }; +const float grid_smoothing[5] = { 0.2f, 0.35f, 0.5f, 0.75f, 0.8f }; const float allpass_poles_3_ov_2_flt[9] = { diff --git a/lib_com/rom_com_fx.c b/lib_com/rom_com_fx.c index a1465dc53..39b94b308 100644 --- a/lib_com/rom_com_fx.c +++ b/lib_com/rom_com_fx.c @@ -6631,3 +6631,56 @@ const Word16 LP_assym_window_16k_fx[L_LP_16k] = { 0x0a40, 0x0a3d, }; + +/* 4-bit/3-bit TD SWB BWE differential LSF scalar quantizer tables */ +/*Q15*/ +const Word16 lsf_q_cb_4b_fx[16] = { + 589, 773, 914, 1043, + 1173, 1302, 1430, 1558, + 1698, 1843, 1973, 2103, + 2258, 2470, 2787, 3282 + +}; + +/*Q15*/ +const Word16 lsf_q_cb_3b_fx[8] = { + 679, 976, 1245, 1491, + 1739, 2011, 2365, 2953 +}; + +const Word16 *const lsf_q_cb_fx[NUM_Q_LSF] = { lsf_q_cb_4b_fx, lsf_q_cb_4b_fx, lsf_q_cb_3b_fx, lsf_q_cb_3b_fx, lsf_q_cb_3b_fx }; + +/*Q15*/ +const Word16 lsf_grid_fx[4][5] = { + { + 5242, + 10229, + 15516, + 21804, + 27540, + }, + { + 5117, + 10059, + 14949, + 20478, + 25493, + }, + { + 4648, + 8732, + 13022, + 18247, + 24474, + }, + { + 5052, + 8925, + 12903, + 19427, + 28382, + } +}; + +/*Q15*/ +const Word16 grid_smoothing_fx[5] = { 6554, 11469, 16384, 24576, 26214 }; diff --git a/lib_dec/er_scale_syn_fx.c b/lib_dec/er_scale_syn_fx.c index 2e5746ccf..509fd071b 100644 --- a/lib_dec/er_scale_syn_fx.c +++ b/lib_dec/er_scale_syn_fx.c @@ -57,8 +57,8 @@ Word16 Damping_fact_fx( /* o : damping factor IF( EQ_16( nbLostCmpt, 1 ) ) { /* If stable, do not decrease the energy, pitch gain = 0 */ - /* * (1.0f - 2.0f*_ALPHA_U_FX) + 2.0f*MODE2_ALPHA_U; */ /* [0.8, 1.0] */ - alpha = add( mult_r( stab_fac, sub( 16384, _ALPHA_U_FX ) ), _ALPHA_U_FX ); + /* * (1.0f - 2.0f*_ALPHA_U_FX) + 2.0f*MODE2_ALPHA_U; */ /* [0.8, 1.0] */ + alpha = add( mult_r( stab_fac, sub( 16384, _ALPHA_U_FX ) ), _ALPHA_U_FX ); /*Q14*/ } ELSE IF( EQ_16( nbLostCmpt, 2 ) ) { @@ -67,7 +67,7 @@ Word16 Damping_fact_fx( /* o : damping factor } ELSE { - alpha = mult_r( _ALPHA_U_FX, 16384 ); /*Q14*/ /* 0.4 go rapidly to CNG gain, pitch gain = 0 */ + alpha = mult_r( _ALPHA_U_FX, 16384 ); /*Q14*/ /* 0.4 go rapidly to CNG gain, pitch gain = 0 Q14*/ } } ELSE IF( EQ_16( last_good, UNVOICED_TRANSITION ) ) @@ -80,12 +80,12 @@ Word16 Damping_fact_fx( /* o : damping factor } ELSE IF( ( ( EQ_16( last_good, VOICED_CLAS ) ) || ( EQ_16( last_good, ONSET ) ) ) && ( LE_16( nbLostCmpt, 3 ) ) ) { - alpha = mult_r( _ALPHA_V_FX, 16384 ); /* constant for the first 3 erased frames */ + alpha = mult_r( _ALPHA_V_FX, 16384 ); /* constant for the first 3 erased frames Q14*/ } IF( GE_16( last_good, VOICED_CLAS ) ) { - lp_tmp = *lp_gainp; + lp_tmp = *lp_gainp; /*Q29*/ move32(); IF( EQ_16( nbLostCmpt, 1 ) ) /* if first erased frame in a block, reset harmonic gain */ @@ -96,7 +96,7 @@ Word16 Damping_fact_fx( /* o : damping factor /*BASOP_Util_Sqrt_MantExp(lp_gainp,&lp_gainp_E);*/ s_gainp = 31 - 29; move16(); - gain32 = Sqrt32( lp_tmp, &s_gainp ); + gain32 = Sqrt32( lp_tmp, &s_gainp ); /*Q31-s_gainp*/ #ifdef BASOP_NOGLOB gain = round_fx_o( L_shl_o( gain32, s_gainp, &Overflow ), &Overflow ); /* Q15*/ @@ -110,7 +110,7 @@ Word16 Damping_fact_fx( /* o : damping factor ELSE IF( EQ_16( nbLostCmpt, 2 ) ) { /*0.6 + 0.35*stab_fac*/ - alpha = mult_r( mac_r( 1288490240l /*0.6f Q31*/, 11469 /*0.35f Q15*/, stab_fac ), round_fx( L_shl( lp_tmp, 1 ) ) ); + alpha = mult_r( mac_r( 1288490240l /*0.6f Q31*/, 11469 /*0.35f Q15*/, stab_fac ), round_fx( L_shl( lp_tmp, 1 ) ) ); /*Q14*/ } ELSE { @@ -118,7 +118,7 @@ Word16 Damping_fact_fx( /* o : damping factor lp_tmp = Mpy_32_16_1( lp_tmp, mac_r( 1503238528l /*0.7f Q31*/, 6554 /*0.2f Q15*/, stab_fac ) ); /*2Q29*/ alpha = round_fx( L_shl( lp_tmp, 1 ) ); /*1Q14*/ } - *lp_gainp = lp_tmp; /*store*/ + *lp_gainp = lp_tmp; /*store Q29*/ move32(); } } diff --git a/lib_dec/er_sync_exc_fx.c b/lib_dec/er_sync_exc_fx.c index 268476821..ac04d048c 100644 --- a/lib_dec/er_sync_exc_fx.c +++ b/lib_dec/er_sync_exc_fx.c @@ -36,9 +36,9 @@ static Word16 GetMinimumPosition_fx( move16(); #endif - filterLength = s_min( filterLength, length ); - center = shr( filterLength, 1 ); - iMinEnergyPos = center; + filterLength = s_min( filterLength, length ); /*Q0*/ + center = shr( filterLength, 1 ); /*Q0*/ + iMinEnergyPos = center; /*Q0*/ move16(); IF( filterLength > 0 ) @@ -47,22 +47,22 @@ static Word16 GetMinimumPosition_fx( energy = L_deposit_l( 0 ); energy_old = L_deposit_l( 0 ); - cnt = sub( length, filterLength ); + cnt = sub( length, filterLength ); /*Q0*/ tmp_e = 0; move16(); FOR( i = 0; i < cnt; i++ ) { - tmp16 = shr( x[i], tmp_e ); + tmp16 = shr( x[i], tmp_e ); /*Qx*/ #ifdef BASOP_NOGLOB - energy = L_msu_sat( energy_old, tmp16, tmp16 ); + energy = L_msu_sat( energy_old, tmp16, tmp16 ); /*2Qx+1*/ #else energy = L_msu( energy_old, tmp16, tmp16 ); #endif - tmp16 = shr( x[add( i, filterLength )], tmp_e ); - BASOP_SATURATE_WARNING_OFF_EVS /*Saturation will be handled*/ + tmp16 = shr( x[( i + filterLength )], tmp_e ); /*Qx*/ + BASOP_SATURATE_WARNING_OFF_EVS /*Saturation will be handled*/ #ifdef BASOP_NOGLOB - energy = L_mac_sat( energy, tmp16, tmp16 ); + energy = L_mac_sat( energy, tmp16, tmp16 ); /*2Qx+1*/ #else energy = L_mac( energy, tmp16, tmp16 ); #endif @@ -71,7 +71,7 @@ static Word16 GetMinimumPosition_fx( /*if (energy == MAXVAL_WORD32)*/ BASOP_SATURATE_WARNING_OFF_EVS /*saturates if energy < 0*/ #ifdef BASOP_NOGLOB - tmptest = L_sub_o( energy, MAXVAL_WORD32, &Overflow ); + tmptest = L_sub_o( energy, MAXVAL_WORD32, &Overflow ); /*Q31*/ #else tmptest = L_sub( energy, MAXVAL_WORD32 ); #endif @@ -80,15 +80,15 @@ static Word16 GetMinimumPosition_fx( { tmp_e = add( tmp_e, 1 ); energy = L_shr( energy_old, 2 ); - tmp16 = shr( x[i], tmp_e ); - energy = L_msu( energy, tmp16, tmp16 ); - tmp16 = shr( x[add( i, filterLength )], tmp_e ); - energy = L_mac( energy, tmp16, tmp16 ); + tmp16 = shr( x[i], tmp_e ); /*Qx-1*/ + energy = L_msu( energy, tmp16, tmp16 ); /*2Qx-1*/ + tmp16 = shr( x[( i - filterLength )], tmp_e ); + energy = L_mac( energy, tmp16, tmp16 ); /*2Qx-1*/ } IF( energy < 0 ) { - iMinEnergyPos = add( i, center ); + iMinEnergyPos = add( i, center ); /*Q0*/ tmp_e = 0; move16(); energy = 0; @@ -98,7 +98,7 @@ static Word16 GetMinimumPosition_fx( } } - return iMinEnergyPos; + return iMinEnergyPos; /*Q0*/ } /*! @@ -108,7 +108,7 @@ static Word16 GetMinimumPosition_fx( */ static Word16 FindMaxPeak_fx( - Word16 /*float*/ const *x, /* 0; j-- ) { - *pt_dest++ = *pt_src++; + *pt_dest++ = *pt_src++; /*Qx*/ move16(); } /* Add some samples */ - ftmp = negate( mult( *pt_src, 1638 /*.05f Q15*/ ) ); + ftmp = negate( mult( *pt_src, 1638 /*.05f Q15*/ ) ); /*Qx*/ FOR( j = 0; j < points_by_pos[i]; j++ ) { - *pt_dest++ = ftmp; + *pt_dest++ = ftmp; /*Qx*/ move16(); - ftmp = negate( ftmp ); + ftmp = negate( ftmp ); /*Qx*/ } /* Prepare for the next loop iteration */ - last_min_pos = min_pos[i]; + last_min_pos = min_pos[i]; /*Q0*/ move16(); } /* Copy remaining length */ FOR( j = sub( L_frame, add( n_samples_to_add, last_min_pos ) ); j > 0; j-- ) { - *pt_dest++ = *pt_src++; + *pt_dest++ = *pt_src++; /*Qx*/ move16(); } } @@ -192,30 +192,30 @@ static void RemoveSamples_fx( Word16 /*int*/ last_min_pos, i, j; - pt_dest = new_exc + L_frame; - last_min_pos = sub( L_frame, n_samples_to_add ); + pt_dest = new_exc + L_frame; /*Qx*/ + last_min_pos = sub( L_frame, n_samples_to_add ); /*Q0*/ FOR( i = sub( nb_min, 1 ); i >= 0; i-- ) { /* Compute len to copy */ /* Copy section, removing some samples */ - pt_src = old_exc + last_min_pos; + pt_src = old_exc + last_min_pos; /*Qx*/ FOR( j = sub( last_min_pos, add( min_pos[i], points_by_pos[i] ) ); j > 0; j-- ) { - *--pt_dest = *--pt_src; + *--pt_dest = *--pt_src; /*Qx*/ move16(); } /* Prepare for the next loop iteration */ - last_min_pos = min_pos[i]; + last_min_pos = min_pos[i]; /*Q0*/ move16(); } /* Copy remaining length */ - pt_src = old_exc + last_min_pos; + pt_src = old_exc + last_min_pos; /*Qx*/ FOR( j = last_min_pos; j > 0; j-- ) { - *--pt_dest = *--pt_src; + *--pt_dest = *--pt_src; /*Qx*/ move16(); } } @@ -258,7 +258,7 @@ void PulseResynchronization_fx( test(); IF( src_exc != dst_exc && LE_16( nFrameLength, 1200 ) ) { - Copy( src_exc, dst_exc, nFrameLength ); + Copy( src_exc, dst_exc, nFrameLength ); /*Q15*/ } return; } @@ -282,7 +282,7 @@ void PulseResynchronization_fx( tmp16 = shl( tmp16, tmp_e ); /*Q0,-tmp_e*/ /*tmp16=roundedPitchStart*nSubframes*/ tmp_e = sub( 15, tmp_e ); tmp16 = Inv16( tmp16, &tmp_e ); /*Q15,tmp_e*/ /*tmp16=1.0/(roundedPitchStart*nSubframes)*/ - tmp32 = L_sub( pitchEnd, pitchStart ); + tmp32 = L_sub( pitchEnd, pitchStart ); /*Q16*/ tmp2_e = norm_l( tmp32 ); tmp32 = L_shl( tmp32, tmp2_e ); /*Q16,-tmp2_e*/ tmp32 = Mpy_32_16_1( tmp32, tmp16 ); /*Q16,tmp_e-tmp2_e*/ /*tmp32=pitchDelta*freqStart*/ @@ -290,7 +290,7 @@ void PulseResynchronization_fx( tmp16 = imult1616( nFrameLength, add( nSubframes, 1 ) ); /*Q0*/ /*tmp16=nFrameLength*(nSubframes+1)*/ tmp2_e = norm_s( tmp16 ); - tmp16 = shl( tmp16, tmp2_e ); + tmp16 = shl( tmp16, tmp2_e ); /*Q0+tmp2_e*/ tmp32 = Mpy_32_16_1( tmp32, tmp16 ); /*Q1 scaling (tmp_e-tmp2_e-1), -1 because of 0.5f*/ /*tmp32=0.5f*pitchDelta*nFrameLength*(nSubframes+1)*freqStart*/ tmp_e = sub( sub( tmp_e, tmp2_e ), 1 ); /* sum up all the scalings for tmp32 */ @@ -298,7 +298,7 @@ void PulseResynchronization_fx( /*samplesDelta -= nFrameLength*(1.0f-pitchStart*freqStart);*/ tmp2_e = norm_l( pitchStart ); - tmp32_a = L_shl( pitchStart, tmp2_e ); + tmp32_a = L_shl( pitchStart, tmp2_e ); /*Q16+tmp2_e*/ tmp32_a = Mpy_32_16_1( tmp32_a /*Q16,-tmp2_e*/, freqStart /*Q15,freqStart_e*/ ); /*Q16, scaling (freqStart_e-tmp2_e)*/ /*tmp32_a=pitchStart*freqStart*/ tmp16 = norm_l( tmp32_a ); tmp32_a = L_shl( tmp32_a, tmp16 ); @@ -314,7 +314,7 @@ void PulseResynchronization_fx( tmp32_a = L_add( L_shl( 1, sub( 31, tmp3_e ) ), tmp32_a ); /*Q31,tmp3_e*/ /*tmp32_a= 1.0f-pitchStart*freqStart*/ #endif tmp2_e = norm_s( nFrameLength ); - tmp16_a = shl( nFrameLength, tmp2_e ); + tmp16_a = shl( nFrameLength, tmp2_e ); /*Q0+tmp2_e*/ tmp32_a = Mpy_32_16_1( tmp32_a /*Q31,tmp3_e*/, tmp16_a /*Q0,-tmp2_e*/ ); /*Q16,tmp3_e-tmp2_e*/ /*tmp32_a= nFrameLength*(1.0f-pitchStart*freqStart)*/ tmp2_e = add( sub( tmp3_e, tmp2_e ), 15 ); samplesDelta = BASOP_Util_Add_Mant32Exp( tmp32, tmp_e, L_negate( tmp32_a ), tmp2_e, &samplesDelta_e ); /*Q31,samplesDelta_e*/ @@ -346,7 +346,7 @@ void PulseResynchronization_fx( tmp32 = L_shl( tmp32, tmp2_e ); tmp_e = sub( tmp_e, tmp2_e ); /*tmp32 = Q31,tmp_e*/ tmp2_e = norm_l( absPitchDiff ); - tmp32_b = L_shl( absPitchDiff, tmp2_e ); + tmp32_b = L_shl( absPitchDiff, tmp2_e ); /*Q16+tmp2_e*/ tmp_e = sub( tmp_e, tmp2_e ); tmp32 = Mpy_32_16_1( tmp32_b, round_fx( tmp32 ) ); /*Q16,tmp_e*/ /*tmp32 = absPitchDiff*(nFrameLength-samplesDelta)*/ tmp32_a = Mpy_32_16_1( L_abs( samplesDelta ) /*Q31,samplesDelta_e*/, roundedPitchStart /*Q0*/ ); /*Q16,samplesDelta_e*/ /*tmp32_a=fabs(samplesDelta)*roundedPitchStart*/ @@ -412,33 +412,33 @@ void PulseResynchronization_fx( /* Make sure that the number of samples increases */ IF( GT_32( L_deposit_h( roundedCycleDelta ), cycleDelta32 ) ) { - iDeltaSamples[i] = roundedCycleDelta; + iDeltaSamples[i] = roundedCycleDelta; /*Q0*/ move16(); - roundedCycleDelta = extract_h( cycleDelta32 ); /* cycleDelta32 should never be < 0 here */ - iDeltaSamples[i - 1] = roundedCycleDelta; + roundedCycleDelta = extract_h( cycleDelta32 ); /* cycleDelta32 should never be < 0 here Q0*/ + iDeltaSamples[i - 1] = roundedCycleDelta; /*Q0*/ move16(); } ELSE { - roundedCycleDelta = extract_h( cycleDelta32 ); /* cycleDelta32 should never be < 0 here */ - iDeltaSamples[i] = roundedCycleDelta; + roundedCycleDelta = extract_h( cycleDelta32 ); /* cycleDelta32 should never be < 0 here Q0*/ + iDeltaSamples[i] = roundedCycleDelta; /*Q0*/ move16(); } /*fractionalLeft = cycleDelta-roundedCycleDelta = cycleDelta-(int)cycleDelta;*/ fractionalLeft = lshr( extract_l( cycleDelta32 ), 1 ); /*Q15*/ /* cycleDelta32 should never be < 0 here */ nSamplesDeltaRemain = sub( nSamplesDeltaRemain, roundedCycleDelta ); } - iDeltaSamples[add( k, 1 )] = s_max( 0, nSamplesDeltaRemain ); + iDeltaSamples[( k + 1 )] = s_max( 0, nSamplesDeltaRemain ); move16(); - maxDeltaSamples = s_max( iDeltaSamples[k], iDeltaSamples[add( k, 1 )] ); /*Q0*/ + maxDeltaSamples = s_max( iDeltaSamples[k], iDeltaSamples[( k + 1 )] ); /*Q0*/ /* Find the location of the minimum energy between the first two pulses */ /*iMinPos1 = T0+GetMinimumPosition_fx(src_exc+T0, min(roundedPitchStart, (nSubframes+1)*nFrameLength/nSubframes-T0), maxDeltaSamples);*/ BASOP_Util_Divide_MantExp( add( nSubframes, 1 ), 15, nSubframes, 15, &tmp16, &tmp_e ); tmp32 = L_mult( nFrameLength /*Q0*/, tmp16 /*Q15,tmp_e*/ ); /*Q16,tmp_e*/ - tmp16 = round_fx( L_shl( tmp32, tmp_e ) ); - tmp16 = sub( tmp16, T0 ); + tmp16 = round_fx( L_shl( tmp32, tmp_e ) ); /*Q0*/ + tmp16 = sub( tmp16, T0 ); /*Q0*/ tmp16 = s_min( roundedPitchStart, tmp16 ); iMinPos1 = GetMinimumPosition_fx( @@ -455,26 +455,26 @@ void PulseResynchronization_fx( IF( GT_16( iMinPos1, add( roundedPitchStart, shr( iDeltaSamples[0], 1 ) ) ) ) { - iMinPos[0] = sub( iMinPos1, sub( roundedPitchStart, shr( iDeltaSamples[0], 1 ) ) ); + iMinPos[0] = sub( iMinPos1, sub( roundedPitchStart, shr( iDeltaSamples[0], 1 ) ) ); /*Q0*/ move16(); } ELSE { - iMinPos[0] = sub( GetMinimumPosition_fx( src_exc, T0, iDeltaSamples[0] ), shr( iDeltaSamples[0], 1 ) ); + iMinPos[0] = sub( GetMinimumPosition_fx( src_exc, T0, iDeltaSamples[0] ), shr( iDeltaSamples[0], 1 ) ); /*Q0*/ move16(); } /* Find the location of the minimum energy between the pulses */ FOR( i = 1; i <= k; i++ ) { - iMinPos[i] = add( iMinPos1, sub( imult1616( sub( i, 1 ), roundedPitchStart ), shr( iDeltaSamples[i], 1 ) ) ); + iMinPos[i] = add( iMinPos1, sub( imult1616( sub( i, 1 ), roundedPitchStart ), shr( iDeltaSamples[i], 1 ) ) ); /*Q0*/ move16(); } /* Find the location of the minimum energy after the last pulse */ - IF( LT_16( add( iMinPos1, add( imult1616( k, roundedPitchStart ), sub( iDeltaSamples[add( k, 1 )], shr( iDeltaSamples[add( k, 1 )], 1 ) ) ) ), sub( nFrameLength, nSamplesDelta ) ) ) + IF( LT_16( add( iMinPos1, add( imult1616( k, roundedPitchStart ), sub( iDeltaSamples[( k + 1 )], shr( iDeltaSamples[( k + 1 )], 1 ) ) ) ), sub( nFrameLength, nSamplesDelta ) ) ) { - iMinPos[add( k, 1 )] = add( iMinPos1, sub( imult1616( k, roundedPitchStart ), shr( iDeltaSamples[add( k, 1 )], 1 ) ) ); + iMinPos[( k + 1 )] = add( iMinPos1, sub( imult1616( k, roundedPitchStart ), shr( iDeltaSamples[( k + 1 )], 1 ) ) ); /*Q0*/ move16(); } ELSE @@ -482,18 +482,18 @@ void PulseResynchronization_fx( /*iMinPos[k+1] = T0+k*roundedPitchStart + GetMinimumPosition_fx(src_exc+T0+k*roundedPitchStart, nFrameLength-nSamplesDelta-(T0+k*roundedPitchStart), iDeltaSamples[k+1]) - iDeltaSamples[k+1]/2; */ - tmp16 = GetMinimumPosition_fx( src_exc + add( T0, imult1616( k, roundedPitchStart ) ), sub( nFrameLength, add( nSamplesDelta, add( T0, imult1616( k, roundedPitchStart ) ) ) ), iDeltaSamples[add( k, 1 )] ); + tmp16 = GetMinimumPosition_fx( src_exc + add( T0, imult1616( k, roundedPitchStart ) ), sub( nFrameLength, add( nSamplesDelta, add( T0, imult1616( k, roundedPitchStart ) ) ) ), iDeltaSamples[( k + 1 )] ); /*Q0*/ tmp16 = add( add( T0, imult1616( k, roundedPitchStart ) ), tmp16 ); - tmp16 = sub( tmp16, shr( iDeltaSamples[add( k, 1 )], 1 ) ); - iMinPos[add( k, 1 )] = tmp16; + tmp16 = sub( tmp16, shr( iDeltaSamples[( k + 1 )], 1 ) ); + iMinPos[( k + 1 )] = tmp16; move16(); } - IF( GT_16( add( iMinPos[add( k, 1 )], iDeltaSamples[add( k, 1 )] ), sub( nFrameLength, nSamplesDelta ) ) ) + IF( GT_16( add( iMinPos[( k + 1 )], iDeltaSamples[( k + 1 )] ), sub( nFrameLength, nSamplesDelta ) ) ) { - iDeltaSamples[k] = add( iDeltaSamples[k], add( iMinPos[add( k, 1 )], sub( iDeltaSamples[add( k, 1 )], sub( nFrameLength, nSamplesDelta ) ) ) ); + iDeltaSamples[k] = add( iDeltaSamples[k], add( iMinPos[( k + 1 )], sub( iDeltaSamples[( k + 1 )], sub( nFrameLength, nSamplesDelta ) ) ) ); /*Q0*/ move16(); - iDeltaSamples[add( k, 1 )] = sub( nFrameLength, add( nSamplesDelta, iMinPos[add( k, 1 )] ) ); + iDeltaSamples[( k + 1 )] = sub( nFrameLength, add( nSamplesDelta, iMinPos[( k + 1 )] ) ); /*Q0*/ move16(); } @@ -505,43 +505,43 @@ void PulseResynchronization_fx( /* Find the location of the minimum energy before the first pulse */ IF( GT_16( iMinPos1, roundedPitchStart ) ) { - iMinPos[0] = sub( iMinPos1, roundedPitchStart ); + iMinPos[0] = sub( iMinPos1, roundedPitchStart ); /*Q0*/ move16(); } ELSE { - iMinPos[0] = GetMinimumPosition_fx( src_exc, T0, iDeltaSamples[0] ); + iMinPos[0] = GetMinimumPosition_fx( src_exc, T0, iDeltaSamples[0] ); /*Q0*/ move16(); } /* Find the location of the minimum energy between the pulses */ FOR( i = 1; i <= k; i++ ) { - iMinPos[i] = iMinPos1; + iMinPos[i] = iMinPos1; /*Q0*/ move16(); - iMinPos1 = add( iMinPos1, roundedPitchStart ); + iMinPos1 = add( iMinPos1, roundedPitchStart ); /*Q0*/ } /* Find the location of the minimum energy after the last pulse */ IF( LT_16( iMinPos1, sub( nFrameLength, nSamplesDelta ) ) ) { - iMinPos[add( k, 1 )] = iMinPos1; + iMinPos[( k + 1 )] = iMinPos1; move16(); } ELSE { - tmp16 = GetMinimumPosition_fx( src_exc + add( T0, imult1616( k, roundedPitchStart ) ), sub( nFrameLength, add( nSamplesDelta, add( T0, imult1616( k, roundedPitchStart ) ) ) ), iDeltaSamples[add( k, 1 )] ); + tmp16 = GetMinimumPosition_fx( src_exc + add( T0, imult1616( k, roundedPitchStart ) ), sub( nFrameLength, add( nSamplesDelta, add( T0, imult1616( k, roundedPitchStart ) ) ) ), iDeltaSamples[( k + 1 )] ); /*Q0*/ tmp16 = add( add( tmp16, T0 ), imult1616( k, roundedPitchStart ) ); - iMinPos[add( k, 1 )] = tmp16; + iMinPos[( k + 1 )] = tmp16; /*Q0*/ move16(); } - IF( GT_16( add( iMinPos[add( k, 1 )], iDeltaSamples[add( k, 1 )] ), sub( nFrameLength, nSamplesDelta ) ) ) + IF( GT_16( add( iMinPos[( k + 1 )], iDeltaSamples[( k + 1 )] ), sub( nFrameLength, nSamplesDelta ) ) ) { - iDeltaSamples[k] = add( iDeltaSamples[k], add( iMinPos[add( k, 1 )], sub( iDeltaSamples[add( k, 1 )], sub( nFrameLength, nSamplesDelta ) ) ) ); + iDeltaSamples[k] = add( iDeltaSamples[k], add( iMinPos[( k + 1 )], sub( iDeltaSamples[( k + 1 )], sub( nFrameLength, nSamplesDelta ) ) ) ); /*Q0*/ move16(); - iDeltaSamples[add( k, 1 )] = sub( sub( nFrameLength, nSamplesDelta ), iMinPos[add( k, 1 )] ); + iDeltaSamples[( k + 1 )] = sub( sub( nFrameLength, nSamplesDelta ), iMinPos[( k + 1 )] ); /*Q0*/ move16(); } /* Add samples at the given positions */ diff --git a/lib_dec/er_util_fx.c b/lib_dec/er_util_fx.c index cc6a53cd2..c2c766d9e 100644 --- a/lib_dec/er_util_fx.c +++ b/lib_dec/er_util_fx.c @@ -61,7 +61,7 @@ void minimumStatistics_fx( #endif { BASOP_SATURATE_WARNING_ON_EVS - currentFrameLevel = PLC_MIN_CNG_LEV; + currentFrameLevel = PLC_MIN_CNG_LEV; /*Q15*/ move16(); currentFrameLevel_e = 0; move16(); @@ -73,13 +73,13 @@ void minimumStatistics_fx( IF( tmp >= 0 ) { /* aOpt = *noiseEstimate / *lastFrameLevel; */ - aOpt = BASOP_Util_Divide1616_Scale( *noiseEstimate, *lastFrameLevel, &aOpt_e ); + aOpt = BASOP_Util_Divide1616_Scale( *noiseEstimate, *lastFrameLevel, &aOpt_e ); /*Q16-aOpt_e*/ aOpt_e = add( aOpt_e, sub( noiseEstimate_e, *lastFrameLevel_e ) ); } ELSE { /* aOpt = *lastFrameLevel / *noiseEstimate; */ - aOpt = BASOP_Util_Divide1616_Scale( *lastFrameLevel, *noiseEstimate, &aOpt_e ); + aOpt = BASOP_Util_Divide1616_Scale( *lastFrameLevel, *noiseEstimate, &aOpt_e ); /*Q16-aOpt_e*/ aOpt_e = add( aOpt_e, sub( *lastFrameLevel_e, noiseEstimate_e ) ); } aOpt = mult_r( aOpt, aOpt ); /* Q15 */ @@ -90,7 +90,7 @@ void minimumStatistics_fx( move16(); } - *lastFrameLevel = currentFrameLevel; + *lastFrameLevel = currentFrameLevel; /*Qx*/ move16(); *lastFrameLevel_e = currentFrameLevel_e; move16(); @@ -100,7 +100,7 @@ void minimumStatistics_fx( move16(); if ( tmp == 0 ) { - tmp = PLC_MIN_STAT_BUFF_SIZE; + tmp = PLC_MIN_STAT_BUFF_SIZE; /*Q0*/ move16(); } /*f = msu_r(L_mult(aOpt, noiseLevelMemory[sub(tmp, 1)]), add(aOpt, 0x8000), currentFrameLevel);*/ @@ -128,7 +128,7 @@ void minimumStatistics_fx( assert( f >= 0 ); /* if current frame min is a new local min, set index to current index */ - p = *noiseLevelIndex; + p = *noiseLevelIndex; /*Q0*/ move16(); tmp2 = BASOP_Util_Add_MantExp( noiseLevelMemory[p], noiseLevelMemory_e[p], negate( f ), *new_noiseEstimate_e, &tmp ); IF( tmp >= 0 ) @@ -137,7 +137,7 @@ void minimumStatistics_fx( /*rescale noiseLevelMemory*/ setnoiseLevelMemory_fx( f, new_noiseEstimate_e, noiseLevelMemory_e, noiseLevelMemory, currLevelIndex ); - p = *currLevelIndex; + p = *currLevelIndex; /*Q0*/ move16(); } ELSE @@ -147,7 +147,7 @@ void minimumStatistics_fx( /* current min is not a new min, so check if min must be re-searched */ IF( NE_16( p, *currLevelIndex ) ) { - f = noiseLevelMemory[p]; /* min is still in memory, so return it */ + f = noiseLevelMemory[p]; /* min is still in memory, so return it Qx*/ move16(); *new_noiseEstimate_e = noiseLevelMemory_e[p]; move16(); @@ -164,7 +164,7 @@ void minimumStatistics_fx( move16(); } } - f = noiseLevelMemory[p]; + f = noiseLevelMemory[p]; /*Qx*/ move16(); *new_noiseEstimate_e = noiseLevelMemory_e[p]; move16(); @@ -172,10 +172,10 @@ void minimumStatistics_fx( } /* update local-minimum-value index and current circular-buffer index */ - *noiseLevelIndex = p; + *noiseLevelIndex = p; /*Q0*/ move16(); p = add( *currLevelIndex, 1 ); - *currLevelIndex = add( *currLevelIndex, 1 ); + *currLevelIndex = add( *currLevelIndex, 1 ); /*Q0*/ move16(); if ( EQ_16( *currLevelIndex, PLC_MIN_STAT_BUFF_SIZE ) ) { @@ -183,7 +183,7 @@ void minimumStatistics_fx( move16(); } - *noiseEstimate = f; + *noiseEstimate = f; /*Qx*/ move16(); } @@ -226,15 +226,15 @@ Word16 getLevelSynDeemph_fx( /*10Q5*/ move16(); /*calculate headroom for dotproduct*/ - Hr16 = sub( 15, norm_s( lenLpcExc ) ); + Hr16 = sub( 15, norm_s( lenLpcExc ) ); /*Q0*/ Q_h1 = s_max( sub( Q_h1, Hr16 ), 0 ); /*compensate synthesis scaling with Headroom as much as possible to retain as much precision as possible*/ /*Factor to be multiplied in order to calculate dotproduct with headroom*/ - tmp16 = shr( 32768 / 2, sub( Hr16, 1 ) ); + tmp16 = shr( 32768 / 2, sub( Hr16, 1 ) ); /*Q15*/ /*moved from inside loop, before synthesis*/ - h1Init[0] = mult_r( h1Init[0], tmp16 ); + h1Init[0] = mult_r( h1Init[0], tmp16 ); /*Q15*/ move16(); FOR( loop = 0; loop < numLoops; loop++ ) @@ -242,7 +242,7 @@ Word16 getLevelSynDeemph_fx( /*10Q5*/ set16_fx( h1, 0, lenLpcExc ); set16_fx( mem, 0, lpcorder ); - Copy( h1Init, h1, 1 ); + Copy( h1Init, h1, 1 ); /*Q15*/ /*h1 will be scaled down, Q_h1 */ E_UTIL_synthesis( Q_h1, A, h1, h1, lenLpcExc, mem, 0, lpcorder ); deemph_fx( h1, preemph_fac, lenLpcExc, &tmp ); @@ -250,10 +250,10 @@ Word16 getLevelSynDeemph_fx( /*10Q5*/ /* gain introduced by synthesis+deemphasis */ /*levelSynDeemphSub = (float)sqrt(dot_product( h1, h1, lenLpcExc));*/ - levelSynDeemphSub = Dot_product12_offs( h1, h1, lenLpcExc, &s16, 0 ); + levelSynDeemphSub = Dot_product12_offs( h1, h1, lenLpcExc, &s16, 0 ); /*Q31 - s16*/ s16 = sub( shl( add( Q_h1, Hr16 ), 1 ), sub( 30, s16 ) ); - levelSynDeemphSub = Sqrt32( levelSynDeemphSub, &s16 ); /*Q31*/ + levelSynDeemphSub = Sqrt32( levelSynDeemphSub, &s16 ); /*Q31 - s16*/ /* mean of the above across all subframes -- moved outta loop*/ /*levelSynDeemph += (1.0/(float)numLoops) * levelSynDeemphSub;*/ @@ -262,14 +262,14 @@ Word16 getLevelSynDeemph_fx( /*10Q5*/ if ( GT_16( numLoops, 1 ) ) { - tmp16 = div_s( 1, numLoops ); + tmp16 = div_s( 1, numLoops ); /*Q15*/ } levelSynDeemph = L_add( levelSynDeemph, L_shl( Mpy_32_16_1( levelSynDeemphSub, tmp16 ), sub( s16, 10 ) ) ); /*10Q21*/ } s16 = norm_l( levelSynDeemph ); - levelSynDeemph = L_shl( levelSynDeemph, s16 ); - *Exp = sub( 10, s16 ); /*Set exponent in order to transform returnvalue to Q15*/ + levelSynDeemph = L_shl( levelSynDeemph, s16 ); /*Q31*/ + *Exp = sub( 10, s16 ); /*Set exponent in order to transform returnvalue to Q15*/ move16(); #ifdef BASOP_NOGLOB @@ -281,10 +281,10 @@ Word16 getLevelSynDeemph_fx( /*10Q5*/ /* BASOP version: up to date with rev 7422 */ void genPlcFiltBWAdap_fx( - const Word32 sr_core, /* i : core sampling rate */ - Word16 *lpFiltAdapt, /* o : filter coefficients for filtering codebooks in case of flc */ - const Word16 type, /* i : type of filter, either 0 : lowpass or 1 : highpass */ - const Word16 alpha /* i : fade out factor [0 1) used decrease filter tilt */ + const Word32 sr_core, /* i : core sampling rate Q0*/ + Word16 *lpFiltAdapt, /* o : filter coefficients for filtering codebooks in case of flc Q15*/ + const Word16 type, /* i : type of filter, either 0 : lowpass or 1 : highpass Q0*/ + const Word16 alpha /* i : fade out factor [0 1) used decrease filter tilt Q15*/ ) { Word16 a, b, exp; @@ -305,17 +305,17 @@ void genPlcFiltBWAdap_fx( } ELSE { - a = mult_r( 13107 /*0.4000f Q15*/, alpha ); + a = mult_r( 13107 /*0.4000f Q15*/, alpha ); /*Q15*/ exp = 0; move16(); - b = Inv16( add( a, 16384 /*0.5f Q15*/ ), &exp ); - b = shr( b, sub( 1, exp ) ); - a = negate( mult_r( a, b ) ); - *lpFiltAdapt++ = a; + b = Inv16( add( a, 16384 /*0.5f Q15*/ ), &exp ); /*Q15 - exp*/ + b = shr( b, sub( 1, exp ) ); /*Q15*/ + a = negate( mult_r( a, b ) ); /*Q15*/ + *lpFiltAdapt++ = a; /*Q15*/ move16(); - *lpFiltAdapt++ = b; + *lpFiltAdapt++ = b; /*Q15*/ move16(); - *lpFiltAdapt = a; + *lpFiltAdapt = a; /*Q15*/ move16(); } } @@ -332,17 +332,17 @@ void genPlcFiltBWAdap_fx( } ELSE { - a = mult_r( 9218 /*0.2813f Q15*/, alpha ); + a = mult_r( 9218 /*0.2813f Q15*/, alpha ); /*Q15*/ exp = 0; move16(); - b = Inv16( add( a, 16384 /*0.5f Q15*/ ), &exp ); - b = shr( b, sub( 1, exp ) ); - a = negate( mult_r( a, b ) ); - *lpFiltAdapt++ = a; + b = Inv16( add( a, 16384 /*0.5f Q15*/ ), &exp ); /*Q15 - exp*/ + b = shr( b, sub( 1, exp ) ); /*Q15*/ + a = negate( mult_r( a, b ) ); /*Q15*/ + *lpFiltAdapt++ = a; /*Q15*/ move16(); - *lpFiltAdapt++ = b; + *lpFiltAdapt++ = b; /*Q15*/ move16(); - *lpFiltAdapt = a; + *lpFiltAdapt = a; /*Q15*/ move16(); } } @@ -355,11 +355,11 @@ void genPlcFiltBWAdap_fx( *-----------------------------------------------------------------*/ /*VERSIONINFO: This port is up to date with trunk rev. 32434*/ void highPassFiltering_fx( - const Word16 last_good, /* i: short last classification type */ - const Word16 L_buffer, /* i: int buffer length */ + const Word16 last_good, /* i: short last classification type Q0*/ + const Word16 L_buffer, /* i: int buffer length Q0*/ Word16 exc2[], /* i/o: Qx unvoiced excitation before the high pass filtering */ const Word16 hp_filt[], /* i: Q15 high pass filter coefficients */ - const Word16 l_fir_fer ) /* i: high pass filter length */ + const Word16 l_fir_fer ) /* i: high pass filter length Q0*/ { Word16 i; /*int*/ @@ -368,7 +368,7 @@ void highPassFiltering_fx( { FOR( i = 0; i < L_buffer; i++ ) { - exc2[i] = round_fx( L_sub( Dot_product( &exc2[i], hp_filt, l_fir_fer ), 1 ) ); + exc2[i] = round_fx( L_sub( Dot_product( &exc2[i], hp_filt, l_fir_fer ), 1 ) ); /*Qx*/ move16(); } } @@ -391,9 +391,9 @@ Word16 GetPLCModeDecision_ivas_fx( IF( EQ_16( st->flagGuidedAcelp, 1 ) ) { - st->old_pitch_buf_fx[shl( st->nb_subfr, 1 )] = L_deposit_h( st->guidedT0 ); + st->old_pitch_buf_fx[( st->nb_subfr * 2 )] = L_deposit_h( st->guidedT0 ); /*Q16*/ move32(); - st->old_pitch_buf_fx[add( shl( st->nb_subfr, 1 ), 1 )] = L_deposit_h( st->guidedT0 ); + st->old_pitch_buf_fx[( ( st->nb_subfr * 2 ) + 1 )] = L_deposit_h( st->guidedT0 ); /*Q16*/ move32(); st->mem_pitch_gain[0] = st->mem_pitch_gain[1] = 16384 /*1.f Q14*/; /*Q14*/ move16(); @@ -430,7 +430,7 @@ Word16 GetPLCModeDecision_ivas_fx( move16(); if ( GT_16( st->nbLostCmpt, 1 ) ) { - core = st->last_core_bfi; + core = st->last_core_bfi; /*Q0*/ move16(); } IF( EQ_16( st->nbLostCmpt, 1 ) ) @@ -462,7 +462,7 @@ Word16 GetPLCModeDecision_ivas_fx( pitch = L_deposit_h( 0 ); if ( hTcxDec->tcxltp_last_gain_unmodified > 0 ) { - pitch = L_add( st->old_fpitch, 0 ); + pitch = L_add( st->old_fpitch, 0 ); /*Q16*/ } // TonalMDCTConceal_Detect_ivas_fx(&st->tonalMDCTconceal, pitch, &numIndices // , (st->element_mode == IVAS_CPE_MDCT ? &(st->hTcxCfg->psychParamsTCX20) : st->hTcxCfg->psychParamsCurrent) @@ -503,7 +503,7 @@ Word16 GetPLCModeDecision_ivas_fx( } } } - return core; + return core; /*Q0*/ } #endif @@ -523,9 +523,9 @@ Word16 GetPLCModeDecision_fx( IF( EQ_16( st->flagGuidedAcelp, 1 ) ) { - st->old_pitch_buf_fx[shl( st->nb_subfr, 1 )] = L_deposit_h( st->guidedT0 ); + st->old_pitch_buf_fx[( st->nb_subfr * 2 )] = L_deposit_h( st->guidedT0 ); /*Q16*/ move32(); - st->old_pitch_buf_fx[add( shl( st->nb_subfr, 1 ), 1 )] = L_deposit_h( st->guidedT0 ); + st->old_pitch_buf_fx[( ( st->nb_subfr * 2 ) + 1 )] = L_deposit_h( st->guidedT0 ); /*Q16*/ move32(); st->mem_pitch_gain[0] = st->mem_pitch_gain[1] = 16384 /*1.f Q14*/; /*Q14*/ move16(); @@ -594,7 +594,7 @@ Word16 GetPLCModeDecision_fx( pitch = L_deposit_h( 0 ); if ( hTcxDec->tcxltp_last_gain_unmodified > 0 ) { - pitch = L_add( st->old_fpitch, 0 ); + pitch = L_add( st->old_fpitch, 0 ); /*Q16*/ } IF( st->element_mode == EVS_MONO ) { diff --git a/lib_dec/hf_synth_fx.c b/lib_dec/hf_synth_fx.c index 21989d052..9af04d1f2 100644 --- a/lib_dec/hf_synth_fx.c +++ b/lib_dec/hf_synth_fx.c @@ -90,20 +90,20 @@ void hf_synth_reset_fx( *---------------------------------------------------------------------*/ void hf_synth_fx( - ZERO_BWE_DEC_HANDLE hBWE_zero, /* i/o: handle to 0 bit BWE parameters */ - const Word32 core_brate, /* i : core bitrate */ - const Word16 output_frame, /* i : output frame length */ - const Word16 *Aq, /* i : quantized Az Q12 */ - const Word16 *exc, /* i : excitation at 12.8 kHz Q_exc */ - Word16 *synth, /* i : 12.8kHz synthesis signal Q_syn2 */ - Word16 *synth16k, /* o : 16kHz synthesis signal Q_syn2 */ + ZERO_BWE_DEC_HANDLE hBWE_zero, /* i/o: handle to 0 bit BWE parameters */ + const Word32 core_brate, /* i : core bitrate Q0*/ + const Word16 output_frame, /* i : output frame length Q0*/ + const Word16 *Aq, /* i : quantized Az Q12*/ + const Word16 *exc, /* i : excitation at 12.8 kHz Q_exc*/ + Word16 *synth, /* i : 12.8kHz synthesis signal Q_syn2*/ + Word16 *synth16k, /* o : 16kHz synthesis signal Q_syn2*/ const Word16 Q_exc, /* i : excitation scaling */ const Word16 Q_syn2, /* i : synthesis scaling */ - Word16 *delay_syn_hf, /*i/o: HF synthesis memory */ + Word16 *delay_syn_hf, /*i/o: HF synthesis memory Q_syn2*/ Word16 *memExp1, /* o : HF excitation exponent */ - Word16 *mem_hp_interp, /* i/o: interpol. memory */ - const Word16 extl, /* i : flag indicating BWE */ - const Word16 CNG_mode /* i : CNG_mode */ + Word16 *mem_hp_interp, /* i/o: interpol. memory Qx*/ + const Word16 extl, /* i : flag indicating BWE Q0*/ + const Word16 CNG_mode /* i : CNG_mode Q0*/ ) { const Word16 *p_Aq; @@ -112,13 +112,13 @@ void hf_synth_fx( output_subfr = output_frame / NB_SUBFR; move16(); - p_Aq = Aq; + p_Aq = Aq; /* Q12 */ FOR( i_subfr = 0; i_subfr < L_FRAME; i_subfr += L_SUBFR ) { hf_synthesis_fx( hBWE_zero, core_brate, output_subfr, p_Aq, &exc[i_subfr], Q_exc, &synth[i_subfr], &synth16k[imult3216( (Word32) i_subfr, output_subfr ) / L_SUBFR], Q_syn2, delay_syn_hf, memExp1, mem_hp_interp, extl, CNG_mode ); - p_Aq += ( M + 1 ); + p_Aq += ( M + 1 ); /* Q12 */ } return; @@ -176,19 +176,19 @@ void hf_synth_ivas_fx( static void hf_synthesis_fx( ZERO_BWE_DEC_HANDLE hBWE_zero, - const Word32 core_brate, /* i : core bitrate */ - const Word16 output_subfr, /* i : output sub-frame length */ - const Word16 Aq[], /* i : quantized Az Q12 */ - const Word16 exc[], /* i : excitation at 12.8 kHz Q_exc */ - const Word16 Q_exc, /* i : excitation scaling */ - Word16 synth[], /* i : 12.8kHz synthesis signal Q_syn */ - Word16 synth16k[], /* i/o: 16kHz synthesis signal Q_syn */ - const Word16 Q_syn, /* i : synthesis scaling */ - Word16 *delay_syn_hf, /* i/o: HF synthesis memory Q_syn */ + const Word32 core_brate, /* i : core bitrate Q0*/ + const Word16 output_subfr, /* i : output sub-frame length Q0*/ + const Word16 Aq[], /* i : quantized Az Q12*/ + const Word16 exc[], /* i : excitation at 12.8 kHz Q_exc*/ + const Word16 Q_exc, /* i : excitation scaling */ + Word16 synth[], /* i : 12.8kHz synthesis signal Q_syn*/ + Word16 synth16k[], /* i/o: 16kHz synthesis signal Q_syn*/ + const Word16 Q_syn, /* i : synthesis scaling */ + Word16 *delay_syn_hf, /* i/o: HF synthesis memory Q_syn*/ Word16 *memExp1, /* o : HF excitation scaling exponent */ - Word16 *mem_hp_interp, /* i/o: interpol. memory */ - const Word16 extl, /* i : flag indicating BWE */ - const Word16 CNG_mode /* i : CNG_mode */ + Word16 *mem_hp_interp, /* i/o: interpol. memory Qx*/ + const Word16 extl, /* i : flag indicating BWE Q0*/ + const Word16 CNG_mode /* i : CNG_mode Q0*/ ) { Word16 i; @@ -219,22 +219,22 @@ static void hf_synthesis_fx( *-----------------------------------------------------------------*/ /*ener = sum2_f( exc, L_SUBFR ) + 0.01f*/ - ener = extract_h( Dot_product12( exc, exc, L_SUBFR, &exp2 ) ); + ener = extract_h( Dot_product12( exc, exc, L_SUBFR, &exp2 ) ); /* Q15 */ exp2 = sub( exp2, add( Q_exc, Q_exc ) ); /*tmp = round_fx(Dot_product12(HF_exc, HF_exc, output_subfr, &exp1)); */ L_tmp = Dot_product12( HF_exc, HF_exc, L_SUBFR16k, &exp1 ); - tmp = round_fx( L_tmp ); + tmp = round_fx( L_tmp ); /* Q15 */ /* tmp = (float)(sqrt(ener/tmp)) */ /* scale is -1 if tmp > ener */ - scale = shr( sub( ener, tmp ), 15 ); - tmp = shl( tmp, scale ); + scale = shr( sub( ener, tmp ), 15 ); /* Q0 */ + tmp = shl( tmp, scale ); /* Q15 + scale*/ exp1 = sub( exp1, scale ); - tmp = div_s( tmp, ener ); + tmp = div_s( tmp, ener ); /* Q15 */ exp1 = sub( exp1, exp2 ); - L_tmp = L_deposit_h( tmp ); + L_tmp = L_deposit_h( tmp ); /* Q31 */ L_tmp = Isqrt_lc( L_tmp, &exp1 ); scale = round_fx( L_tmp ); /* Q18 when Q_exc=-1, HF_exc in Q-3 */ @@ -256,11 +256,11 @@ static void hf_synthesis_fx( /* i: synth in Q_syn */ /* o: synth in Q_syn-3 */ - L_tmp = L_mac( 1L, synth[0], synth[0] ); + L_tmp = L_mac( 1L, synth[0], synth[0] ); /* 2*(Q_syn-3)+1 */ FOR( i = 1; i < L_SUBFR; i++ ) { #ifdef BASOP_NOGLOB - L_tmp = L_mac_sat( L_tmp, synth[i], synth[i] ); + L_tmp = L_mac_sat( L_tmp, synth[i], synth[i] ); /* 2*(Q_syn-3)+1 */ #else L_tmp = L_mac( L_tmp, synth[i], synth[i] ); #endif @@ -269,11 +269,11 @@ static void hf_synthesis_fx( ener = extract_h( L_shl( L_tmp, tmp ) ); /* ener = r[0] */ /*ener in Q = 2*(Q_syn-3)+1 = Q-5 when Q_syn=0*/ - L_tmp = L_mac( 1L, synth[1], synth[0] ); + L_tmp = L_mac( 1L, synth[1], synth[0] ); /* 2*(Q_syn-3)+1 */ FOR( i = 2; i < L_SUBFR; i++ ) { #ifdef BASOP_NOGLOB - L_tmp = L_mac_sat( L_tmp, synth[i], synth[i - 1] ); + L_tmp = L_mac_sat( L_tmp, synth[i], synth[i - 1] ); /* 2*(Q_syn-3)+1 */ #else L_tmp = L_mac( L_tmp, synth[i], synth[i - 1] ); #endif @@ -287,7 +287,7 @@ static void hf_synthesis_fx( tmp = s_max( 0, tmp ); if ( tmp > 0 ) { - tmp = div_s( tmp, ener ); + tmp = div_s( tmp, ener ); /* Q15 */ } /*-----------------------------------------------------------------* @@ -296,7 +296,7 @@ static void hf_synthesis_fx( /* tmp = 1.0 - fac */ #ifdef BASOP_NOGLOB - tmp = add_o( 1, sub( 32767, tmp ), &Overflow ); + tmp = add_o( 1, sub( 32767 /* 1 in Q15 */, tmp ), &Overflow ); #else tmp = add( 1, sub( 32767, tmp ) ); #endif @@ -306,7 +306,7 @@ static void hf_synthesis_fx( /* emphasize HF noise in CNG */ /*fac *= 2.0f;*/ #ifdef BASOP_NOGLOB - tmp = add_o( tmp, tmp, &Overflow ); + tmp = add_o( tmp, tmp, &Overflow ); /* Q15 */ #else tmp = add( tmp, tmp ); #endif @@ -347,10 +347,10 @@ static void hf_synthesis_fx( /* delay by 5 samples @16kHz to compensate CLDFB resampling delay (20samples) and HP filtering delay (roughly 15 samples) */ delay = NS2SA_FX2( 16000, DELAY_CLDFB_NS ) - 15; - Copy( HF_syn + sub( L_SUBFR16k, delay ), temp_buffer, delay ); - Copy( HF_syn, HF_syn + delay, sub( L_SUBFR16k, delay ) ); - Copy( delay_syn_hf, HF_syn, delay ); - Copy( temp_buffer, delay_syn_hf, delay ); + Copy( HF_syn + sub( L_SUBFR16k, delay ), temp_buffer, delay ); /* Q_syn+exp1 */ + Copy( HF_syn, HF_syn + delay, sub( L_SUBFR16k, delay ) ); /* Q_syn+exp1 */ + Copy( delay_syn_hf, HF_syn, delay ); /* Q_syn */ + Copy( temp_buffer, delay_syn_hf, delay ); /* Q_syn */ /* interpolate the HF synthesis */ IF( EQ_16( output_subfr, L_SUBFR48k ) ) /* 48kHz sampled output */ @@ -360,12 +360,12 @@ static void hf_synthesis_fx( s = s_max( s_min( sub( s_min( Find_Max_Norm16( HF_syn, L_SUBFR16k ), Find_Max_Norm16( mem_hp_interp, INTERP_3_1_MEM_LEN - 3 ) ), 3 ), sub( Find_Max_Norm16( mem_hp_interp + INTERP_3_1_MEM_LEN - 3, 3 ), 1 ) ), 0 ); - Scale_sig( HF_syn, L_SUBFR16k, s ); - Scale_sig( mem_hp_interp, INTERP_3_1_MEM_LEN, s ); + Scale_sig( HF_syn, L_SUBFR16k, s ); /* Q_syn+exp1+s */ + Scale_sig( mem_hp_interp, INTERP_3_1_MEM_LEN, s ); /* Qx + s */ interpolate_3_over_1_allpass_fx( HF_syn, L_SUBFR16k, upsampled_HF_syn, mem_hp_interp ); - Scale_sig( upsampled_HF_syn, 3 * L_SUBFR16k, -s ); - Scale_sig( mem_hp_interp, INTERP_3_1_MEM_LEN, -s ); - Scale_sig( HF_syn, L_SUBFR16k, -s ); + Scale_sig( upsampled_HF_syn, 3 * L_SUBFR16k, -s ); /* Q_syn + exp1 + s */ + Scale_sig( mem_hp_interp, INTERP_3_1_MEM_LEN, -s ); /* Qx */ + Scale_sig( HF_syn, L_SUBFR16k, -s ); /* Q_syn+exp1 */ } Scale_sig( upsampled_HF_syn, L_SUBFR48k, -1 ); } @@ -374,17 +374,17 @@ static void hf_synthesis_fx( { Word16 s; s = s_max( sub( s_min( Find_Max_Norm16( HF_syn, L_SUBFR16k ), Find_Max_Norm16( mem_hp_interp, 2 * ALLPASSSECTIONS_STEEP ) ), 2 ), 0 ); - Scale_sig( HF_syn, L_SUBFR16k, s ); - Scale_sig( mem_hp_interp, 2 * ALLPASSSECTIONS_STEEP, s ); + Scale_sig( HF_syn, L_SUBFR16k, s ); /* Q_syn+exp1+s */ + Scale_sig( mem_hp_interp, 2 * ALLPASSSECTIONS_STEEP, s ); /* Qx + s */ Interpolate_allpass_steep_fx( HF_syn, mem_hp_interp, L_SUBFR16k, upsampled_HF_syn ); - Scale_sig( upsampled_HF_syn, 2 * L_SUBFR16k, -s ); - Scale_sig( mem_hp_interp, 2 * ALLPASSSECTIONS_STEEP, -s ); - Scale_sig( HF_syn, L_SUBFR16k, -s ); + Scale_sig( upsampled_HF_syn, 2 * L_SUBFR16k, -s ); /* Q_syn + exp1 */ + Scale_sig( mem_hp_interp, 2 * ALLPASSSECTIONS_STEEP, -s ); /* Qx */ + Scale_sig( HF_syn, L_SUBFR16k, -s ); /* Q_syn+exp1 */ } } ELSE /* 16kHz sampled output */ { - Copy( HF_syn, upsampled_HF_syn, L_SUBFR16k ); + Copy( HF_syn, upsampled_HF_syn, L_SUBFR16k ); /* Q_syn */ } Vr_add( synth16k, upsampled_HF_syn, synth16k, output_subfr ); @@ -630,11 +630,11 @@ static void hf_synthesis_ivas_fx( * (gain=4.0) *-------------------------------------------------------------------*/ static void filt_6k_7k_scale_fx( - Word16 signal[], /* i/o: signal */ - Word16 lg, /* i : length of input */ - Word16 mem[], /* i/o: memory (size=30) */ - Word16 fact, /* i : multiply factor */ - Word16 exp /* i : Mem Exponent */ + Word16 signal[], /* i/o: signal Qx*/ + Word16 lg, /* i : length of input Q0*/ + Word16 mem[], /* i/o: memory (size=30) exp*/ + Word16 fact, /* i : multiply factor Q0*/ + Word16 exp /* i : Mem Exponent */ ) { Word16 i, x[L_FRAME48k / NB_SUBFR + ( L_FIR - 1 )]; @@ -647,8 +647,8 @@ static void filt_6k_7k_scale_fx( FOR( i = 0; i < lg; i++ ) { - x[i + L_FIR - 1] = shr( mult( signal[i], fact ), 2 ); - move16(); /* gain of filter = 4 */ + x[i + L_FIR - 1] = shr( mult( signal[i], fact ), 2 ); /* Qx - 2 */ + move16(); /* gain of filter = 4 */ } FOR( i = 0; i < lg; i++ ) { @@ -659,20 +659,20 @@ static void filt_6k_7k_scale_fx( FOR( j = 0; j < 31; j++ ) { #ifdef BASOP_NOGLOB - L_tmp = L_mac_o( L_tmp, x[i + j], fir_6k_7k_fx[j], &Overflow ); + L_tmp = L_mac_o( L_tmp, x[i + j], fir_6k_7k_fx[j], &Overflow ); /* Q16 */ #else L_tmp = L_mac( L_tmp, x[i + j], fir_6k_7k_fx[j] ); #endif } #ifdef BASOP_NOGLOB - signal[i] = round_fx_o( L_tmp, &Overflow ); + signal[i] = round_fx_o( L_tmp, &Overflow ); /* Q0 */ move16(); #else signal[i] = round_fx( L_tmp ); #endif } - Copy( x + lg, mem, L_FIR - 1 ); + Copy( x + lg, mem, L_FIR - 1 ); /* Qx - 2 */ } /*-------------------------------------------------------------------* @@ -694,7 +694,7 @@ void hf_synth_amr_wb_init_fx( hAmrwb_IO->frame_count_fx = 0; move16(); hAmrwb_IO->ne_min_fx = -7680; - move16(); /*Q8*/ + move16(); /*-30.0f in Q8*/ hAmrwb_IO->fmerit_m_sm_fx = 0; move16(); hAmrwb_IO->voice_fac_amr_wb_hf = 0; @@ -702,7 +702,7 @@ void hf_synth_amr_wb_init_fx( hAmrwb_IO->unvoicing_fx = 0; move16(); hAmrwb_IO->unvoicing_sm_fx = 32767; - move16(); /*Q15*/ + move16(); /*1.0f in Q15*/ hAmrwb_IO->unvoicing_flag_fx = 0; move16(); hAmrwb_IO->voicing_flag_fx = 0; @@ -710,7 +710,7 @@ void hf_synth_amr_wb_init_fx( hAmrwb_IO->start_band_old_fx = 160; move16(); hAmrwb_IO->OptCrit_old_fx = 32768; - move32(); /*Q15*/ + move32(); /*1.0f in Q15*/ ; return; } @@ -746,7 +746,7 @@ void hf_synth_amr_wb_reset_fx( hAmrwb_IO->frame_count_fx = 0; move16(); hAmrwb_IO->ne_min_fx = -7680; - move16(); /*Q8*/ + move16(); /*-30.0f in Q8*/ hAmrwb_IO->fmerit_m_sm_fx = 0; move16(); hAmrwb_IO->voice_fac_amr_wb_hf = 0; @@ -754,7 +754,7 @@ void hf_synth_amr_wb_reset_fx( hAmrwb_IO->unvoicing_fx = 0; move16(); hAmrwb_IO->unvoicing_sm_fx = 32767; - move16(); /*Q15*/ + move16(); /*1.0f in Q15*/ hAmrwb_IO->unvoicing_flag_fx = 0; move16(); hAmrwb_IO->voicing_flag_fx = 0; @@ -762,7 +762,7 @@ void hf_synth_amr_wb_reset_fx( hAmrwb_IO->start_band_old_fx = 160; move16(); hAmrwb_IO->OptCrit_old_fx = 32768; - move32(); /*Q15*/ + move32(); /*1.0f in Q15*/ return; } @@ -776,21 +776,21 @@ void hf_synth_amr_wb_reset_fx( void hf_synth_amr_wb_fx( AMRWB_IO_DEC_HANDLE hAmrwb_IO, /* i/o: AMR-WB IO data handle */ ZERO_BWE_DEC_HANDLE hBWE_zero, /* o : zero BWE decoder handle */ - const Word32 core_brate, /* i : core bitrate */ - const Word16 output_frame, /* i : output frame length */ - const Word16 *Aq, /* i : quantized Az : Q12 */ - const Word16 *exc, /* i : excitation at 12.8 kHz : Q_exc */ - Word16 *synth, /* i/o: synthesis signal at 12.8k : Q_syn */ - Word16 *amr_io_class, /* i : signal class (determined by FEC algorithm) */ - Word16 *synth_out, /* i/o: output signal at output Fs : Q_out */ - Word16 fmerit, /* i : classify parameter from FEC : Q14 */ - const Word16 *hf_gain, /* i : decoded HF gain */ - const Word16 *voice_factors, /* i : voicing factors : Q15 */ - const Word16 pitch_buf[], /* i : pitch buffer : Q5 */ - const Word16 ng_ener_ST, /* i : Noise gate - short-term energy : Q8 */ - const Word16 *lsf_new, /* i : ISF vector : Q2 */ - const Word16 Q_exc, /* i : exc scaling */ - const Word16 Q_out /* i : Q_syn2-1 */ + const Word32 core_brate, /* i : core bitrate Q0*/ + const Word16 output_frame, /* i : output frame length Q0*/ + const Word16 *Aq, /* i : quantized Az : Q12*/ + const Word16 *exc, /* i : excitation at 12.8 kHz : Q_exc*/ + Word16 *synth, /* i/o: synthesis signal at 12.8k : Q_syn*/ + Word16 *amr_io_class, /* i : signal class (determined by FEC algorithm) Q0*/ + Word16 *synth_out, /* i/o: output signal at output Fs : Q_out*/ + Word16 fmerit, /* i : classify parameter from FEC : Q14*/ + const Word16 *hf_gain, /* i : decoded HF gain Q0*/ + const Word16 *voice_factors, /* i : voicing factors : Q15*/ + const Word16 pitch_buf[], /* i : pitch buffer : Q5*/ + const Word16 ng_ener_ST, /* i : Noise gate - short-term energy : Q8*/ + const Word16 *lsf_new, /* i : ISF vector : Q2*/ + const Word16 Q_exc, /* i : exc scaling */ + const Word16 Q_out /* i : Q_syn2-1 */ ) { Word16 core_type = 1; @@ -824,11 +824,12 @@ void hf_synth_amr_wb_fx( Word32 exc32[L_FRAME], dct_exc32[L_FRAME], dct_hb32[L_FRAME16k], exc16k32[L_FRAME16k]; Word16 q_tmp; Word16 gamma; + move16(); - Scale_sig( synth, L_FRAME, -3 ); + Scale_sig( synth, L_FRAME, -3 ); /* Q_syn - 3 */ - pt1 = synth + 1; - pt2 = synth; + pt1 = synth + 1; /* Q_syn - 3 */ + pt2 = synth; /* Q_syn - 3 */ pt3 = til; pt4 = til0; FOR( i = 0; i < NB_SUBFR; i++ ) @@ -836,9 +837,9 @@ void hf_synth_amr_wb_fx( enr1 = Dot_product( pt2, pt2, L_SUBFR ); /*2*(Q_syn-3)+1 */ enr2 = Dot_product( pt1, pt2, L_SUBFR - 1 ); /*2*(Q_syn-3)+1 */ - tmp1 = extract_h( enr1 ); + tmp1 = extract_h( enr1 ); /*2*(Q_syn-3) - 15 */ tmp1 = s_max( 1, tmp1 ); - tmp2 = extract_h( enr2 ); + tmp2 = extract_h( enr2 ); /*2*(Q_syn-3) - 15 */ exp = norm_s( tmp1 ); tmp1 = div_s( shl( 1, sub( 14, exp ) ), tmp1 ); /*Q(29-exp-2*(Q_syn-3)-1) */ @@ -852,7 +853,7 @@ void hf_synth_amr_wb_fx( pt2 += L_SUBFR; } - output_subfr = shr( output_frame, 2 ); + output_subfr = shr( output_frame, 2 ); /* Q0 */ if ( NE_16( *amr_io_class, 7 ) ) { @@ -863,8 +864,8 @@ void hf_synth_amr_wb_fx( /* modify LF parameters for excitation weighting or sub-frame gains calculating */ pitch_var_cur = 0; move16(); - pt6 = pitch_buf; - pt7 = pitch_buf + 1; + pt6 = pitch_buf; /* Q5 */ + pt7 = pitch_buf + 1; /* Q5 */ FOR( i = 0; i < 3; i++ ) { tmp1 = abs_s( sub( *pt6++, *pt7++ ) ); /*Q5 */ @@ -874,41 +875,41 @@ void hf_synth_amr_wb_fx( IF( GT_16( hAmrwb_IO->frame_count_fx, FRAME_COUNT_HF_SYNTH ) && *amr_io_class == UNVOICED_CLAS ) { hAmrwb_IO->frame_count_fx = 0; - hAmrwb_IO->ne_min_fx = -7680; + hAmrwb_IO->ne_min_fx = -7680; /* -30.0f in Q8 */ move16(); move16(); /*Q8; */ } ELSE { - hAmrwb_IO->frame_count_fx = s_min( hAmrwb_IO->frame_count_fx, 2 * FRAME_COUNT_HF_SYNTH - 1 ); + hAmrwb_IO->frame_count_fx = s_min( hAmrwb_IO->frame_count_fx, 2 * FRAME_COUNT_HF_SYNTH - 1 ); /* Q0 */ move16(); - hAmrwb_IO->frame_count_fx = add( hAmrwb_IO->frame_count_fx, 1 ); + hAmrwb_IO->frame_count_fx = add( hAmrwb_IO->frame_count_fx, 1 ); /* Q0 */ move16(); - hAmrwb_IO->ne_min_fx = s_min( hAmrwb_IO->ne_min_fx, ng_ener_ST ); + hAmrwb_IO->ne_min_fx = s_min( hAmrwb_IO->ne_min_fx, ng_ener_ST ); /* Q8 */ move16(); } pt6 = voice_factors; - L_tmp = L_mult( *pt6++, 4096 ); + L_tmp = L_mult( *pt6++, 4096 /* 0.25 IN Q14 */ ); /* Q30 */ FOR( i = 1; i < 4; i++ ) { - L_tmp = L_mac( L_tmp, *pt6++, 4096 ); + L_tmp = L_mac( L_tmp, *pt6++, 4096 /* 0.25 IN Q14 */ ); /* Q30 */ } - voice_fac = round_fx( L_tmp ); + voice_fac = round_fx( L_tmp ); /* Q14 */ /*fmerit_w = fmerit > 5734 ? 5734 : (fmerit < 2458 ? 2458 : fmerit); //Q14 */ - fmerit_w = s_min( fmerit, 5734 ); - fmerit_w = s_max( fmerit_w, 2458 ); + fmerit_w = s_min( fmerit, 5734 /* 0.35 IN Q14 */ ); /* Q14 */ + fmerit_w = s_max( fmerit_w, 2458 /* 0.15 IN Q14 */ ); /* Q14 */ if ( EQ_16( core_type, 1 ) ) { - fmerit_w = shr( fmerit_w, 1 ); /*Q14; */ + fmerit_w = shr( fmerit_w, 1 ); /* Q14 */ } #ifdef BASOP_NOGLOB - L_tmp = L_mult( fmerit_w, add_sat( 16384, voice_fac ) ); + L_tmp = L_mult( fmerit_w, add_sat( 16384, voice_fac ) ); /* Q14 */ #else L_tmp = L_mult( fmerit_w, add( 16384, voice_fac ) ); #endif @@ -920,17 +921,17 @@ void hf_synth_amr_wb_fx( move16(); - tmp1 = fmerit; + tmp1 = fmerit; /* Q14 */ move16(); - if ( LT_16( fmerit, 8192 ) ) + if ( LT_16( fmerit, 8192 /* 0.5 in Q14 */ ) ) { - tmp1 = 16384; + tmp1 = 16384; /* 1.0f in Q14 */ move16(); } fmerit_m = negate( add( -32768, tmp1 ) ); hAmrwb_IO->fmerit_m_sm_fx = add( shr( hAmrwb_IO->fmerit_m_sm_fx, 1 ), shr( fmerit_m, 1 ) ); /*Q14 */ move16(); - fmerit_m = hAmrwb_IO->fmerit_m_sm_fx; + fmerit_m = hAmrwb_IO->fmerit_m_sm_fx; /* Q14 */ move16(); pt1 = til; @@ -940,15 +941,15 @@ void hf_synth_amr_wb_fx( tmp = s_and( tmp, *pt1 ); if ( tmp < 0 ) { - *pt1 = 1638; + *pt1 = 1638; /* 0.2 in Q13 */ move16(); } - tmp1 = sub( 8192, *pt1 ); - *pt1 = s_max( 6554, tmp1 ); + tmp1 = sub( 8192 /* 1.0 in Q13 */, *pt1 ); /* Q13 */ + *pt1 = s_max( 6554 /* 0.8 in Q13 */, tmp1 ); /* Q13 */ move16(); - tmp1 = add( hAmrwb_IO->ne_min_fx, 7680 ); /*Q8 */ - tmp1 = mult_r( tmp1, 7340 ); /*Q20 - > 0.007 //Q13 */ + tmp1 = add( hAmrwb_IO->ne_min_fx, 7680 /* 30.0 in Q30 */ ); /*Q8 */ + tmp1 = mult_r( tmp1, 7340 ); /*Q20 - > 0.007 //Q13 */ *pt1 = add( *pt1, tmp1 ); move16(); /*Q13 */ @@ -979,19 +980,19 @@ void hf_synth_amr_wb_fx( q_tmp = Exp16Array( L_FRAME, exc ); qdct = sub( q_tmp, 1 ); - Copy_Scale_sig_16_32( exc, exc32, L_FRAME, qdct ); + Copy_Scale_sig_16_32( exc, exc32, L_FRAME, qdct ); /* Qexc + qdct */ qdct = add( qdct, Q_exc ); edct_fx( exc32, dct_exc32, L_FRAME, &qdct ); q_tmp = Exp32Array( L_FRAME, dct_exc32 ); q_tmp = sub( q_tmp, 16 ); - Copy_Scale_sig_32_16( dct_exc32, dct_exc, L_FRAME, q_tmp ); + Copy_Scale_sig_32_16( dct_exc32, dct_exc, L_FRAME, q_tmp ); /* qdct + qtmp */ qdct = add( qdct, q_tmp ); set16_fx( dct_hb, 0, L_FRAME16k ); - pt1 = &dct_hb[200]; - pt2 = &dct_exc[200]; + pt1 = &dct_hb[200]; /* qdct */ + pt2 = &dct_exc[200]; /* qdct */ FOR( i = 200; i < 240; i++ ) { *pt1++ = *pt2++; @@ -1014,10 +1015,10 @@ void hf_synth_amr_wb_fx( } hb_ener = dot_prod_satcontr( &dct_hb[240], &dct_hb[240], qdct, qdct, &q1, L_SUBFR16k ); - L_tmp = L_shl( L_mult( start_band, 205 ), 14 ); /*Q30 */ - tmp = round_fx( L_tmp ); /*Q14 */ - tmp = sub( 18022, tmp ); /*Q14 */ - fmerit_w = round_fx( L_shl( L_mult( fmerit_w, tmp ), 1 ) ); /*Q: 14+14+1+1-16 = 14 */ + L_tmp = L_shl( L_mult( start_band, 205 /* 0.00625f in Q15 */ ), 14 ); /*Q30 */ + tmp = round_fx( L_tmp ); /*Q14 */ + tmp = sub( 18022 /* 1.1f in Q14 */, tmp ); /*Q14 */ + fmerit_w = round_fx( L_shl( L_mult( fmerit_w, tmp ), 1 ) ); /*Q: 14+14+1+1-16 = 14 */ L_tmp = L_deposit_l( fmerit_w ); /*Q14 */ @@ -1027,15 +1028,15 @@ void hf_synth_amr_wb_fx( alpha = div_s( shl( 1, sub( 14, q2 ) ), tmp ); /*Q(29-q2-8); */ alpha = shl( alpha, sub( q2, 7 ) ); /*Q14 */ - beta = sub( 16384, fmerit_w ); /*Q14 */ + beta = sub( 16384 /* 1.0f in Q14 */, fmerit_w ); /*Q14 */ - L_tmp = L_mult( alpha, 31130 ); /*Q30 */ - gamma = round_fx( L_tmp ); /*Q14 */ - gamma = sub( 17203, gamma ); /*Q14 */ - gamma = s_min( 16384, gamma ); - gamma = s_max( 4915, gamma ); + L_tmp = L_mult( alpha, 31130 /* 0.95f in Q15 */ ); /*Q30 */ + gamma = round_fx( L_tmp ); /*Q14 */ + gamma = sub( 17203 /* 1.05f in Q14 */, gamma ); /*Q14 */ + gamma = s_min( 16384 /* 1.0f in Q14 */, gamma ); /* Q14 */ + gamma = s_max( 4915 /* 0.3f in Q14 */, gamma ); /* Q14 */ - IF( LT_16( beta, 16384 ) ) + IF( LT_16( beta, 16384 /* 1 in Q14 */ ) ) { L_tmp = 1; /*variable for tonal energy*/ move32(); @@ -1045,7 +1046,7 @@ void hf_synth_amr_wb_fx( pt3 = &dct_hb[240]; FOR( i = 0; i < 8; i++ ) { - fn = add( i, 8 ); + fn = add( i, 8 ); /* Q0 */ tmp1 = div_s( 1, fn ); /*Q15 */ tmp = 0; move16(); @@ -1060,11 +1061,11 @@ void hf_synth_amr_wb_fx( } *pt1 = round_fx( L_shl( L_mult( tmp, tmp1 ), 2 ) ); /*qdct */ move16(); - *pt2 = sub( *pt3, *pt1 ); + *pt2 = sub( *pt3, *pt1 ); /* qdct */ move16(); IF( *pt2 > 0 ) { - L_tmp = L_mac0( L_tmp, shr( *pt2, 1 ), shr( *pt2, 1 ) ); + L_tmp = L_mac0( L_tmp, shr( *pt2, 1 ), shr( *pt2, 1 ) ); /*2*qdct-2 */ } pt1++; pt2++; @@ -1072,8 +1073,8 @@ void hf_synth_amr_wb_fx( } FOR( ; i < L_SUBFR16k - 8; i++ ) { - fb = sub( i, 7 ); - fn = add( fb, 15 ); + fb = sub( i, 7 ); /* Q0 */ + fn = add( fb, 15 ); /* Q0 */ tmp = 0; move16(); pt4 = &dct_hb[fb + 240]; @@ -1092,7 +1093,7 @@ void hf_synth_amr_wb_fx( IF( *pt2 > 0 ) { #ifdef BASOP_NOGLOB - L_tmp = L_mac0_sat( L_tmp, shr( *pt2, 1 ), shr( *pt2, 1 ) ); + L_tmp = L_mac0_sat( L_tmp, shr( *pt2, 1 ), shr( *pt2, 1 ) ); /*2*qdct-2 */ #else L_tmp = L_mac0( L_tmp, shr( *pt2, 1 ), shr( *pt2, 1 ) ); #endif @@ -1103,11 +1104,11 @@ void hf_synth_amr_wb_fx( } FOR( ; i < L_SUBFR16k; i++ ) { - fb = sub( i, 7 ); + fb = sub( i, 7 ); /* Q0 */ tmp = 0; move16(); - fn = sub( L_SUBFR16k, fb ); - tmp1 = div_s( 1, fn ); /*Q15 */ + fn = sub( L_SUBFR16k, fb ); /* Q0 */ + tmp1 = div_s( 1, fn ); /*Q15 */ pt4 = &dct_hb[fb + 240]; FOR( j = fb; j < L_SUBFR16k; j++ ) { @@ -1172,11 +1173,11 @@ void hf_synth_amr_wb_fx( pt4++; } - ener = dot_prod_satcontr( &dct_hb[240], &dct_hb[240], qdct, qdct, &q2, L_SUBFR16k ); - scale = div_s( shl( 1, 14 ), hb_ener ); /*Q(29-q1) */ - L_tmp = L_mult( ener, scale ); /*30-q1+q2 */ - q2 = sub( q1, q2 ); /*30-q2 */ - scale = round_fx( Isqrt( L_shl( L_tmp, sub( q2, 24 ) ) ) ); /*Q12 */ + ener = dot_prod_satcontr( &dct_hb[240], &dct_hb[240], qdct, qdct, &q2, L_SUBFR16k ); /* q2 */ + scale = div_s( shl( 1, 14 ), hb_ener ); /*Q(29-q1) */ + L_tmp = L_mult( ener, scale ); /*30-q1+q2 */ + q2 = sub( q1, q2 ); /*30-q2 */ + scale = round_fx( Isqrt( L_shl( L_tmp, sub( q2, 24 ) ) ) ); /*Q12 */ #ifdef BASOP_NOGLOB scale = round_fx_sat( L_shl_sat( L_mult( scale, gamma ), 4 ) ); /*Q15 */ #else @@ -1191,23 +1192,23 @@ void hf_synth_amr_wb_fx( IF( EQ_32( core_brate, ACELP_6k60 ) ) { - filt_weight_coeff = 60; + filt_weight_coeff = 60; /* Q0 */ move16(); rev_filt_weight_coeff = 555; move16(); /* 1/(filt_weight_coeff-1) Q15 */ } ELSE IF( EQ_32( core_brate, ACELP_8k85 ) ) { - filt_weight_coeff = 40; + filt_weight_coeff = 40; /* Q0 */ move16(); - rev_filt_weight_coeff = 840; + rev_filt_weight_coeff = 840; /* 1/(filt_weight_coeff-1) Q15 */ move16(); } ELSE { - filt_weight_coeff = 20; + filt_weight_coeff = 20; /* Q0 */ move16(); - rev_filt_weight_coeff = 1725; + rev_filt_weight_coeff = 1725; /* 1/(filt_weight_coeff-1) Q15 */ move16(); } @@ -1223,7 +1224,7 @@ void hf_synth_amr_wb_fx( IF( EQ_32( core_brate, ACELP_23k85 ) ) { pt1 = dct_hb + 240; - tmp = sub( filt_weight_coeff, 80 ); + tmp = sub( filt_weight_coeff, 80 ); /* Q0 */ pt3 = filt_weight + tmp; FOR( i = 240; i < L_FRAME16k; i++ ) { @@ -1252,21 +1253,21 @@ void hf_synth_amr_wb_fx( { tmp = *pt6++; move16(); - *pt1++ = HP_gain_fx[tmp]; + *pt1++ = HP_gain_fx[tmp]; /* Q15 */ move16(); } } ELSE { pt1 = dct_hb + 240; - tmp = sub( filt_weight_coeff, 80 ); + tmp = sub( filt_weight_coeff, 80 ); /* Q0 */ pt3 = filt_weight + tmp; FOR( i = 240; i < L_FRAME16k; i++ ) { *pt1 = mult_r( *pt1, scale ); /*qdct */ IF( GT_16( i, 255 ) ) { - *pt1 = mult_r( 19505, *pt1 ); + *pt1 = mult_r( 19505 /* 0.6 in Q15 */, *pt1 ); move16(); } @@ -1281,25 +1282,25 @@ void hf_synth_amr_wb_fx( pt1 = dct_hb + 200; pt6 = filt_hp_fx; - pt7 = deem_tab_fx; + pt7 = deem_tab_fx; /* Q15 */ FOR( i = 200; i < 256; i++ ) { *pt1 = mult_r( *pt6++, *pt1 ); move16(); /*qdct */ *pt1 = mult_r( *pt7++, *pt1 ); - move16(); + move16(); /* qdct */ pt1++; } } q_tmp = Exp16Array( L_FRAME16k, dct_hb ); qhf = sub( q_tmp, 1 ); - Copy_Scale_sig_16_32( dct_hb, dct_hb32, L_FRAME16k, qhf ); + Copy_Scale_sig_16_32( dct_hb, dct_hb32, L_FRAME16k, qhf ); /* qhf + qdct */ qhf = add( qhf, qdct ); edct_fx( dct_hb32, exc16k32, L_FRAME16k, &qhf ); q_tmp = Exp32Array( L_FRAME16k, exc16k32 ); q_tmp = sub( q_tmp, 16 ); - Copy_Scale_sig_32_16( exc16k32, exc16k, L_FRAME16k, q_tmp ); + Copy_Scale_sig_32_16( exc16k32, exc16k, L_FRAME16k, q_tmp ); /* qhf + qtmp */ qhf = add( qhf, q_tmp ); ener = dot_prod_satcontr( exc, exc, Q_exc, Q_exc, &q1, L_FRAME ); @@ -1383,19 +1384,19 @@ void hf_synth_amr_wb_fx( return; } static void hf_synthesis_amr_wb_fx( - const Word32 core_brate, /* i : core bitrate : Q0 */ - const Word16 output_subfr, /* i : output sub-frame length : Q0 */ - const Word16 Ap[], /* i : quantized Aq : Q12 */ - Word16 exc16k[], /* i : excitation at 16 kHz : Qhf */ - Word16 synth_out[], /* i/o: synthesis signal at output Fs : Qo */ - Word16 *mem_syn_hf, /* i/o: HF synthesis memory : Qo */ - Word16 *delay_syn_hf, /* i/o: HF synthesis memory : Qo */ - Word16 *mem_hp_interp, /* i/o: interpol. memory : Qo */ - Word16 p_r, /* i : sub-frame gain : Q12 */ - Word16 HF_corr_gain, /* i : HF gain index : Q14 */ - Word16 til, /*Q14*/ - Word16 voice_factors, /*Q14*/ - const Word16 exc[], /* i : excitation at 12.8 kHz : Qi */ + const Word32 core_brate, /* i : core bitrate : Q0*/ + const Word16 output_subfr, /* i : output sub-frame length : Q0*/ + const Word16 Ap[], /* i : quantized Aq : Q12*/ + Word16 exc16k[], /* i : excitation at 16 kHz : qhf*/ + Word16 synth_out[], /* i/o: synthesis signal at output Fs : Q_out*/ + Word16 *mem_syn_hf, /* i/o: HF synthesis memory : Q_out*/ + Word16 *delay_syn_hf, /* i/o: HF synthesis memory : Q_out*/ + Word16 *mem_hp_interp, /* i/o: interpol. memory : Q_out*/ + Word16 p_r, /* i : sub-frame gain : Q12*/ + Word16 HF_corr_gain, /* i : HF gain index : Q14*/ + Word16 til, /* Q14 */ + Word16 voice_factors, /* Q14 */ + const Word16 exc[], /* i : excitation at 12.8 kHz : Qexc*/ const Word16 Q_exc, /*exc scaling*/ const Word16 Q_out, /*synth_out scaling*/ Word16 qhf /*exc16k scaling*/ @@ -1412,7 +1413,7 @@ static void hf_synthesis_amr_wb_fx( ener = dot_prod_satcontr( exc, exc, Q_exc, Q_exc, &q1, L_SUBFR ); tmp = dot_prod_satcontr( exc16k, exc16k, qhf, qhf, &q2, L_SUBFR16k ); - L_tmp = L_mult( ener, 6554 ); /*Q(q1+16) */ + L_tmp = L_mult( ener, 6554 /* 0.2 in Q15 */ ); /*Q(q1+16) */ q3 = norm_l( L_tmp ); L_tmp = L_shl( L_tmp, q3 ); /*Q(q1+q3+16) */ ener = extract_h( L_tmp ); /*Q(q1+q3); */ @@ -1463,14 +1464,14 @@ static void hf_synthesis_amr_wb_fx( scale = round_fx( Isqrt( L_shl( L_tmp, sub( q2, 24 ) ) ) ); /*Q12 */ #endif flag = negate( s_and( til, -0x8000 ) ); - if ( GT_16( scale, 4096 ) ) + if ( GT_16( scale, 4096 /* 1.0f in Q12 */ ) ) { flag = 1; move16(); } IF( flag ) { - Copy( exc2385, exc16k, L_SUBFR16k ); + Copy( exc2385, exc16k, L_SUBFR16k ); /* qhf */ } ELSE { @@ -1478,10 +1479,10 @@ static void hf_synthesis_amr_wb_fx( pt2 = exc2385; FOR( i = 0; i < L_SUBFR16k; i++ ) { - tmp = sub( 16348, shl( til, 1 ) ); /*Q14 */ - L_tmp = L_mult( tmp, sub( 26214, shr( voice_factors, 1 ) ) ); /*Q29*/ - tmp = round_fx( L_shr( L_tmp, 1 ) ); /*Q12*/ - tmp = s_min( tmp, 4096 ); + tmp = sub( 16348 /* 1 in Q14 */, shl( til, 1 ) ); /*Q14 */ + L_tmp = L_mult( tmp, sub( 26214 /* 1.6f in Q14 */, shr( voice_factors, 1 ) ) ); /*Q29*/ + tmp = round_fx( L_shr( L_tmp, 1 ) ); /*Q12*/ + tmp = s_min( tmp, 4096 /* 1 in Q12 */ ); tmp = s_max( tmp, scale ); *pt1++ = round_fx( L_shl( L_mult( *pt2++, tmp ), 3 ) ) /*qhf*/; move16(); @@ -1517,31 +1518,31 @@ static void hf_synthesis_amr_wb_fx( s = s_max( s_min( sub( s_min( Find_Max_Norm16( HF_syn, L_SUBFR16k ), Find_Max_Norm16( mem_hp_interp, INTERP_3_1_MEM_LEN - 3 ) ), 3 ), sub( Find_Max_Norm16( mem_hp_interp + INTERP_3_1_MEM_LEN - 3, 3 ), 1 ) ), 0 ); - Scale_sig( HF_syn, L_SUBFR16k, s ); - Scale_sig( mem_hp_interp, INTERP_3_1_MEM_LEN, s ); + Scale_sig( HF_syn, L_SUBFR16k, s ); /* Qout + s */ + Scale_sig( mem_hp_interp, INTERP_3_1_MEM_LEN, s ); /* Qout + s */ interpolate_3_over_1_allpass_fx( HF_syn, L_SUBFR16k, upsampled_HF_syn, mem_hp_interp ); - Scale_sig( upsampled_HF_syn, L_SUBFR48k, add( -s, -1 ) ); - Scale_sig( mem_hp_interp, INTERP_3_1_MEM_LEN, -s ); - Scale_sig( HF_syn, L_SUBFR16k, -s ); + Scale_sig( upsampled_HF_syn, L_SUBFR48k, add( -s, -1 ) ); /* Qout - 1 */ + Scale_sig( mem_hp_interp, INTERP_3_1_MEM_LEN, -s ); /* Qout */ + Scale_sig( HF_syn, L_SUBFR16k, -s ); /* Qout */ } ELSE IF( EQ_16( output_subfr, L_SUBFR32k ) ) /* 32kHz sampled output */ { Word16 s; s = s_max( sub( s_min( Find_Max_Norm16( HF_syn, L_SUBFR16k ), Find_Max_Norm16( mem_hp_interp, 2 * ALLPASSSECTIONS_STEEP ) ), 2 ), 0 ); - Scale_sig( HF_syn, L_SUBFR16k, s ); - Scale_sig( mem_hp_interp, 2 * ALLPASSSECTIONS_STEEP, s ); + Scale_sig( HF_syn, L_SUBFR16k, s ); /* Qout + s */ + Scale_sig( mem_hp_interp, 2 * ALLPASSSECTIONS_STEEP, s ); /* Qout + s */ Interpolate_allpass_steep_fx( HF_syn, mem_hp_interp, L_SUBFR16k, upsampled_HF_syn ); - Scale_sig( upsampled_HF_syn, 2 * L_SUBFR16k, -s ); - Scale_sig( mem_hp_interp, 2 * ALLPASSSECTIONS_STEEP, -s ); - Scale_sig( HF_syn, L_SUBFR16k, -s ); + Scale_sig( upsampled_HF_syn, 2 * L_SUBFR16k, -s ); /* Qout */ + Scale_sig( mem_hp_interp, 2 * ALLPASSSECTIONS_STEEP, -s ); /* Qout */ + Scale_sig( HF_syn, L_SUBFR16k, -s ); /* Qout */ } ELSE /* 16kHz sampled output */ { - Copy( HF_syn, upsampled_HF_syn, L_SUBFR16k ); + Copy( HF_syn, upsampled_HF_syn, L_SUBFR16k ); /* Qout */ } Vr_add( synth_out, upsampled_HF_syn, synth_out, output_subfr ); @@ -1550,15 +1551,15 @@ static void hf_synthesis_amr_wb_fx( } static Word16 EnhanceClass_fx( - const Word16 qq_fx, - const Word16 pp_fx, - const Word16 tilt0_fx, /* i : spectrum tilt */ - const Word16 tilt_fx, /* i : spectrum tilt */ - const Word16 voice_factor_fx, /* i : voice factor */ - Word16 *voice_fac_fx, /* i/o: smoothed voiced parameter */ - Word16 *unvoicing_fx, /* i/o: unvoiced parameter */ - Word16 *unvoicing_sm_fx, /* i/o: smoothed unvoiced parameter */ - Word16 *unvoicing_flag /* i/o: unvoiced flag */ + const Word16 qq_fx, /* Qx */ + const Word16 pp_fx, /* Qx */ + const Word16 tilt0_fx, /* i : spectrum tilt Q13*/ + const Word16 tilt_fx, /* i : spectrum tilt Q13*/ + const Word16 voice_factor_fx, /* i : voice factor Q15*/ + Word16 *voice_fac_fx, /* i/o: smoothed voiced parameter Q15*/ + Word16 *unvoicing_fx, /* i/o: unvoiced parameter Q15*/ + Word16 *unvoicing_sm_fx, /* i/o: smoothed unvoiced parameter Q15*/ + Word16 *unvoicing_flag /* i/o: unvoiced flag Q0*/ ) { Word16 unvoicing_tmp_fx; @@ -1571,41 +1572,41 @@ static Word16 EnhanceClass_fx( /* Decide (*unvoicing_flag) to allow BWE enhancement when qq>pp */ /**voice_fac_fx = add(mult_r(*voice_fac_fx, 24576), mult_r(voice_factor_fx, 8192)); //Q15 */ - *voice_fac_fx = round_fx( L_mac( L_mult( *voice_fac_fx, 24576 ), voice_factor_fx, 8192 ) ); /*Q15 */ + *voice_fac_fx = round_fx( L_mac( L_mult( *voice_fac_fx, 24576 /* 0.75 in Q15 */ ), voice_factor_fx, 8192 /* 0.25 in Q15 */ ) ); /*Q15 */ move16(); - tmp = mult_r( sub( 8192, tilt0_fx ), 16384 ); /*Q13 */ + tmp = mult_r( sub( 8192 /* 1.0f in Q13 */, tilt0_fx ), 16384 /* 1.0f in Q15 */ ); /*Q13 */ - L_tmp = L_sub( 32768, *voice_fac_fx ); /*Q15 */ + L_tmp = L_sub( 32768 /* 1.0 in Q15 */, *voice_fac_fx ); /*Q15 */ L_tmp = Mult_32_16( L_tmp, tmp ); /*Q13 */ tmp = extract_l( L_tmp ); /*Q13 */ tmp1 = mult_r( tilt_fx, 21845 ); /*Q15->1/1.5 ->Q13+15-15->Q13 */ - tmp1 = s_min( tmp1, 8192 ); + tmp1 = s_min( tmp1, 8192 /* 1.0f in Q13 */ ); L_tmp = L_mult( tmp, tmp1 ); /*Q13+Q13+1 */ unvoicing_tmp_fx = extract_l( L_shr( L_tmp, 12 ) ); /*Q15 */ /**unvoicing_fx = add(mult_r(16384, *unvoicing_fx), mult_r(16384, unvoicing_tmp_fx)); //Q15 */ - *unvoicing_fx = round_fx( L_mac( L_mult( 16384, *unvoicing_fx ), 16384, unvoicing_tmp_fx ) ); /*Q15 */ + *unvoicing_fx = round_fx( L_mac( L_mult( 16384 /* 0.5 in Q15 */, *unvoicing_fx ), 16384 /* 0.5 in Q15 */, unvoicing_tmp_fx ) ); /*Q15 */ move16(); IF( GT_16( *unvoicing_sm_fx, *unvoicing_fx ) ) { /**unvoicing_sm_fx = add(mult_r(29491, *unvoicing_sm_fx), mult_r(3277, *unvoicing_fx)); //Q15 */ - *unvoicing_sm_fx = round_fx( L_mac( L_mult( 29491, *unvoicing_sm_fx ), 3277, *unvoicing_fx ) ); /*Q15 */ + *unvoicing_sm_fx = round_fx( L_mac( L_mult( 29491 /* 0.9 in Q15 */, *unvoicing_sm_fx ), 3277 /* 0.1 in Q15 */, *unvoicing_fx ) ); /*Q15 */ move16(); } ELSE { /**unvoicing_sm_fx = add(mult_r(32440, *unvoicing_sm_fx), mult_r(328, *unvoicing_fx)); //Q15 */ - *unvoicing_sm_fx = round_fx( L_mac( L_mult( 32440, *unvoicing_sm_fx ), 328, *unvoicing_fx ) ); /*Q15 */ + *unvoicing_sm_fx = round_fx( L_mac( L_mult( 32440 /* 0.99 in Q15 */, *unvoicing_sm_fx ), 328 /* 0.01 in Q15 */, *unvoicing_fx ) ); /*Q15 */ move16(); } #ifdef BASOP_NOGLOB - if ( GT_16( sub_o( *unvoicing_fx, *unvoicing_sm_fx, &Overflow ), 3277 ) ) + if ( GT_16( sub_o( *unvoicing_fx, *unvoicing_sm_fx, &Overflow ), 3277 /* 0.1 in Q15 */ ) ) #else if ( GT_16( sub( *unvoicing_fx, *unvoicing_sm_fx ), 3277 ) ) #endif @@ -1615,7 +1616,7 @@ static Word16 EnhanceClass_fx( } #ifdef BASOP_NOGLOB - if ( LT_16( sub_o( *unvoicing_fx, *unvoicing_sm_fx, &Overflow ), 1638 ) ) + if ( LT_16( sub_o( *unvoicing_fx, *unvoicing_sm_fx, &Overflow ), 1638 /* 0.05 in Q15 */ ) ) #else if ( LT_16( sub( *unvoicing_fx, *unvoicing_sm_fx ), 1638 ) ) #endif @@ -1629,13 +1630,13 @@ static Word16 EnhanceClass_fx( static void envelope_fx( AMRWB_IO_DEC_HANDLE hAmrwb_IO, - const Word32 core_brate, /* i : core bitrate */ - const Word16 Aq_dyn_scal[], /* i : de-quant. LPC coefficents, dynamic scaling */ - Word16 Ap[], /* o : extended LPC coefficents, Q12 */ - Word16 *sub_gain, /* o : sub-frame gain, Q12 */ - Word16 tilt0, /* i : spectrum tilt, Q14 */ - Word16 tilt, /* i : spectrum tilt, Q13 */ - Word16 voice_factor /* i : voice factor, Q15 */ + const Word32 core_brate, /* i : core bitrate Q0*/ + const Word16 Aq_dyn_scal[], /* i : de-quant. LPC coefficents, dynamic scaling Q12*/ + Word16 Ap[], /* o : extended LPC coefficents, Q12*/ + Word16 *sub_gain, /* o : sub-frame gain, Q12*/ + Word16 tilt0, /* i : spectrum tilt, Q14*/ + Word16 tilt, /* i : spectrum tilt, Q13*/ + Word16 voice_factor /* i : voice factor, Q15*/ ) { @@ -1654,7 +1655,7 @@ static void envelope_fx( /* Aq has dynamic scaling go back to Q12 to make sure there's no overflow while calculating qx,qy*/ shift = sub( norm_s( Aq_dyn_scal[0] ), 2 ); - Copy_Scale_sig( Aq_dyn_scal, Aq, M + 1, shift ); + Copy_Scale_sig( Aq_dyn_scal, Aq, M + 1, shift ); /* Q12 + shift */ /* LPC envelope weighting */ IF( EQ_32( core_brate, ACELP_6k60 ) ) @@ -1670,17 +1671,17 @@ static void envelope_fx( shift = sub( norm_s( Ap[0] ), 2 ); IF( shift != 0 ) { - Scale_sig( Ap, M + 1, shift ); + Scale_sig( Ap, M + 1, shift ); /* Q12 + shift */ } /* LPC envelope level estimate */ L_tmp = 0; move32(); - pt1 = Ap; - pt2 = exp_tab_p_fx; + pt1 = Ap; /* Q12 */ + pt2 = exp_tab_p_fx; /* Q14 */ FOR( i = 0; i <= M; i++ ) { - L_tmp = L_mac( L_tmp, *pt1++, *pt2++ ); + L_tmp = L_mac( L_tmp, *pt1++, *pt2++ ); /* Q27 */ } q1 = norm_l( L_tmp ); L_tmp = L_shl( L_tmp, q1 ); /*Q(27+q1)*/ @@ -1688,11 +1689,11 @@ static void envelope_fx( L_tmp = L_deposit_l( 0 ); - pt1 = Ap; - pt2 = exp_tab_p_fx + 33; + pt1 = Ap; /* Q12 */ + pt2 = exp_tab_p_fx + 33; /* Q14 */ FOR( i = 0; i <= M; i++ ) { - L_tmp = L_mac( L_tmp, *pt1++, *pt2-- ); + L_tmp = L_mac( L_tmp, *pt1++, *pt2-- ); /* Q27 */ } q2 = norm_l( L_tmp ); shift = sub( q1, q2 ); @@ -1710,12 +1711,12 @@ static void envelope_fx( py = round_fx( L_shr( L_tmp, 1 ) ); /*Q(10+q1)*/ L_tmp = L_deposit_l( 0 ); - pt2 = Aq; - pt3 = exp_tab_q_fx; + pt2 = Aq; /* Q12 */ + pt3 = exp_tab_q_fx; /* Q14 */ FOR( i = 0; i <= M; i++ ) { #ifdef BASOP_NOGLOB - L_tmp = L_mac_sat( L_tmp, *pt2++, *pt3++ ); + L_tmp = L_mac_sat( L_tmp, *pt2++, *pt3++ ); /* Q27 */ #else L_tmp = L_mac( L_tmp, *pt2++, *pt3++ ); #endif @@ -1725,12 +1726,12 @@ static void envelope_fx( rx = round_fx( L_shr( L_tmp, 1 ) ); /*Q(10+q2)*/ L_tmp = L_deposit_l( 0 ); - pt2 = Aq; - pt3 = exp_tab_q_fx + 33; + pt2 = Aq; /* Q12 */ + pt3 = exp_tab_q_fx + 33; /* Q14 */ FOR( i = 0; i <= M; i++ ) { #ifdef BASOP_NOGLOB - L_tmp = L_mac_sat( L_tmp, *pt2++, *pt3-- ); + L_tmp = L_mac_sat( L_tmp, *pt2++, *pt3-- ); /* Q14 */ #else L_tmp = L_mac( L_tmp, *pt2++, *pt3-- ); #endif @@ -1765,21 +1766,21 @@ static void envelope_fx( rr = round_fx( Isqrt( L_shr( L_tmp, add( 11, shl( q2, 1 ) ) ) ) ); /*Q10*/ #endif Copy( Aq, As, 3 ); - IF( EQ_16( shr( As[2], 1 ), -2048 ) ) + IF( EQ_16( shr( As[2], 1 ), -2048 /* -1.0f in Q11 */ ) ) { - k2 = -2458; + k2 = -2458; /* -0.6f in Q12 */ move16(); - k1 = 4055; + k1 = 4055; /* 0.99f in Q12 */ move16(); if ( As[1] < 0 ) { - k1 = -k1; + k1 = -k1; /* Q12 */ move16(); } } ELSE { - k1 = add( 2048, shr( As[2], 1 ) ); /*Q11 */ + k1 = add( 2048 /* 1 in Q11 */, shr( As[2], 1 ) ); /*Q11 */ q1 = 11; move16(); q2 = norm_s( k1 ); @@ -1801,28 +1802,28 @@ static void envelope_fx( #endif k2 = As[2]; move16(); /*Q12 */ - if ( GT_16( k2, 2458 ) ) + if ( GT_16( k2, 2458 /* 0.6f in Q12 */ ) ) { - k2 = 2458; + k2 = 2458; /* 0.6f in Q12 */ move16(); } - if ( LT_16( k2, -2458 ) ) + if ( LT_16( k2, -2458 /* -0.6f in Q12 */ ) ) { - k2 = -2458; + k2 = -2458; /* -0.6f in Q12 */ move16(); } - if ( GT_16( k1, 4055 ) ) + if ( GT_16( k1, 4055 /* 0.99f in Q12 */ ) ) { - k1 = 4055; + k1 = 4055; /* 0.99f in Q12 */ move16(); } - if ( LT_16( k1, -4055 ) ) + if ( LT_16( k1, -4055 /* -0.99f in Q12 */ ) ) { - k1 = -4055; + k1 = -4055; /* -0.99f in Q12 */ move16(); } } - As[1] = add( 4096, k2 ); + As[1] = add( 4096 /* 1 in Q12 */, k2 ); move16(); L_tmp = L_mult( As[1], k1 ); /*Q25 */ As[1] = round_fx( L_shl( L_tmp, 3 ) ); /*Q12 */ @@ -1831,11 +1832,11 @@ static void envelope_fx( move16(); /*Q12 */ L_tmp = L_deposit_l( 0 ); - pt1 = As; - pt2 = exp_tab_q_fx; + pt1 = As; /* Q12 */ + pt2 = exp_tab_q_fx; /* Q14 */ FOR( i = 0; i < 3; i++ ) { - L_tmp = L_mac( L_tmp, *pt1++, *pt2++ ); + L_tmp = L_mac( L_tmp, *pt1++, *pt2++ ); /* Q27 */ } q1 = norm_l( L_tmp ); L_tmp = L_shl( L_tmp, q1 ); /*Q(27+q1)*/ @@ -1843,11 +1844,11 @@ static void envelope_fx( L_tmp = L_deposit_l( 0 ); - pt1 = As; - pt2 = exp_tab_q_fx + 33; + pt1 = As; /* Q12 */ + pt2 = exp_tab_q_fx + 33; /* Q14 */ FOR( i = 0; i < 3; i++ ) { - L_tmp = L_mac( L_tmp, *pt1++, *pt2-- ); + L_tmp = L_mac( L_tmp, *pt1++, *pt2-- ); /* Q27 */ } q2 = norm_l( L_tmp ); shift = sub( q1, q2 ); @@ -1865,11 +1866,11 @@ static void envelope_fx( qy = round_fx( L_shr( L_tmp, 1 ) ); /*Q(10+q1)*/ - L_tmp = L_mult( qx, qx ); - L_tmp = L_mac( L_tmp, qy, qy ); + L_tmp = L_mult( qx, qx ); /* Q21 + 2q1 */ + L_tmp = L_mac( L_tmp, qy, qy ); /* Q21 + 2q1 */ qq = round_fx( Isqrt( L_shr( L_tmp, add( 11, shl( q1, 1 ) ) ) ) ); /*Q10*/ - Unvoicing_flag = EnhanceClass_fx( rr, pp, tilt0, tilt, voice_factor, &hAmrwb_IO->voice_fac_amr_wb_hf, &hAmrwb_IO->unvoicing_fx, &hAmrwb_IO->unvoicing_sm_fx, &hAmrwb_IO->unvoicing_flag_fx ); + Unvoicing_flag = EnhanceClass_fx( rr, pp, tilt0, tilt, voice_factor, &hAmrwb_IO->voice_fac_amr_wb_hf, &hAmrwb_IO->unvoicing_fx, &hAmrwb_IO->unvoicing_sm_fx, &hAmrwb_IO->unvoicing_flag_fx ); /* Q0 */ alpha = 0; move16(); IF( Unvoicing_flag ) @@ -1886,31 +1887,31 @@ static void envelope_fx( hAmrwb_IO->prev_r_fx = rr; move16(); - L_tmp = L_mult( tilt, sub( 26214, shr( voice_factor, 1 ) ) ); /*Q28*/ + L_tmp = L_mult( tilt, sub( 26214 /* 1.6f in Q14 */, shr( voice_factor, 1 ) ) ); /*Q28*/ - L_tmp = L_min( L_tmp, 268435456 ); + L_tmp = L_min( L_tmp, 268435456 /* 1 in Q28 */ ); - L_tmp = Mult_32_16( L_tmp, rr ); /*Q23*/ - rr = round_fx( L_shl( L_tmp, 3 ) ); /*Q10*/ - L_tmp = L_mult( tilt, sub( 26214, shr( voice_factor, 1 ) ) ); /*Q28*/ - L_tmp = L_max( L_tmp, 268435456 ); + L_tmp = Mult_32_16( L_tmp, rr ); /*Q23*/ + rr = round_fx( L_shl( L_tmp, 3 ) ); /*Q10*/ + L_tmp = L_mult( tilt, sub( 26214 /* 1.6f in Q14 */, shr( voice_factor, 1 ) ) ); /*Q28*/ + L_tmp = L_max( L_tmp, 268435456 /* 1 in Q28 */ ); L_tmp = Mult_32_16( L_tmp, qq ); /*Q23*/ #ifdef BASOP_NOGLOB qq = round_fx_sat( L_shl_sat( L_tmp, 3 ) ); /*Q10*/ #else qq = round_fx( L_shl( L_tmp, 3 ) ); /*Q10*/ #endif - rr = s_min( rr, qq ); - rr = s_max( rr, pp ); + rr = s_min( rr, qq ); /* Q10 */ + rr = s_max( rr, pp ); /* Q10 */ } ELSE { test(); - IF( LT_16( rr, 1024 ) && LT_16( ( hAmrwb_IO->prev_r_fx ), 1024 ) ) + IF( LT_16( rr, 1024 /* 1 in Q10 */ ) && LT_16( ( hAmrwb_IO->prev_r_fx ), 1024 /* 1 in Q10 */ ) ) { L_tmp = L_mult( rr, rr ); /*Q21*/ tmp = round_fx( L_shl( L_tmp, 9 ) ); /*Q14*/ - L_tmp = L_sub( 2097152, L_tmp ); /*Q21*/ + L_tmp = L_sub( 2097152 /* 1 in Q21 */, L_tmp ); /*Q21*/ alpha = round_fx( L_shl( L_tmp, 9 ) ); /*Q14*/ L_tmp = L_mult( alpha, ( hAmrwb_IO->prev_r_fx ) ); /*Q25*/ L_tmp = L_mac( L_tmp, tmp, rr ); /*Q25*/ @@ -1924,9 +1925,9 @@ static void envelope_fx( hAmrwb_IO->prev_r_fx = rr; move16(); - L_tmp = L_mult( tilt, sub( 26214, shr( voice_factor, 1 ) ) ); /*Q28*/ + L_tmp = L_mult( tilt, sub( 26214 /* 1.6f in Q14 */, shr( voice_factor, 1 ) ) ); /*Q28*/ - L_tmp = L_min( L_tmp, 268435456 ); + L_tmp = L_min( L_tmp, 268435456 /* 1 in Q28 */ ); L_tmp = Mult_32_16( L_tmp, qq ); /*Q23*/ est_level1 = round_fx( L_shl( L_tmp, 3 ) ); /*Q10*/ @@ -1935,8 +1936,8 @@ static void envelope_fx( tmp = s_min( tmp, qq ); rr = s_min( tmp, rr ); - L_tmp = L_mult( abs_s( sub( tilt, 8192 ) ), sub( 26214, shr( voice_factor, 1 ) ) ); /*Q28*/ - L_tmp = L_add( L_tmp, 268435456 ); + L_tmp = L_mult( abs_s( sub( tilt, 8192 /* 1 in Q13 */ ) ), sub( 26214 /* 1.6 in Q14 */, shr( voice_factor, 1 ) ) ); /*Q28*/ + L_tmp = L_add( L_tmp, 268435456 /* 1 in Q28 */ ); L_tmp = Mult_32_16( L_tmp, rr ); /*Q23*/ est_level2 = round_fx( L_shl( L_tmp, 3 ) ); /*Q10*/ @@ -1949,7 +1950,7 @@ static void envelope_fx( L_tmp = L_mult( rr, tmp ); /*Q(30-q1-10+10) */ #ifdef BASOP_NOGLOB - *sub_gain = s_min( 20480, round_fx_sat( L_shl_sat( L_tmp, sub( q1, 2 ) ) ) ); /*Q12 */ + *sub_gain = s_min( 20480 /* 5.0f in Q12 */, round_fx_sat( L_shl_sat( L_tmp, sub( q1, 2 ) ) ) ); /*Q12 */ move16(); #else *sub_gain = s_min( 20480, round_fx( L_shl( L_tmp, sub( q1, 2 ) ) ) ); /*Q12 */ @@ -1963,15 +1964,15 @@ static void envelope_fx( * adaptively select the start band of bandwidth extension *---------------------------------------------------------------------*/ -void AdaptiveStartBand_fx( - Word16 *start_band, /* o : start point of copied band */ - const Word32 core_rate, /* i : core bitrate */ - const Word16 *lsf_fx, /* i : Q2 lsf frequency */ - const Word16 voicing_fac_fx, /* i : Q14 voicing factors */ - const Word16 clas, /* i : signal class (determined by FEC algorithm)*/ - Word16 *voicing_flag, - Word16 *start_band_old, - Word32 *OptCrit_old_fx /*i/o : Q15 */ +static void AdaptiveStartBand_fx( + Word16 *start_band, /* o : start point of copied band Q0*/ + const Word32 core_rate, /* i : core bitrate Q0*/ + const Word16 *lsf_fx, /* i : lsf frequency Q2*/ + const Word16 voicing_fac_fx, /* i : voicing factors Q14*/ + const Word16 clas, /* i : signal class (determined by FEC algorithm) Q0*/ + Word16 *voicing_flag, /* Q0 */ + Word16 *start_band_old, /* Q0 */ + Word32 *OptCrit_old_fx /*i/o : Q15 */ ) { Word16 i, pos, M2, voicing_flag_old; @@ -1985,19 +1986,19 @@ void AdaptiveStartBand_fx( move32(); // corresponding to initialization of OptCrit_fx /*voicing switching flag : to avoid switching start band frequently in VOICED or AUDIO area*/ - voicing_flag_old = *voicing_flag; + voicing_flag_old = *voicing_flag; /* Q0 */ move16(); test(); test(); test(); - if ( GT_16( voicing_fac_fx, 6554 ) || ( GT_16( voicing_fac_fx, 4915 ) && GE_16( clas, VOICED_CLAS ) ) || EQ_16( clas, AUDIO_CLAS ) ) + if ( GT_16( voicing_fac_fx, 6554 /* 0.4 in Q14 */ ) || ( GT_16( voicing_fac_fx, 4915 /* 0.3 in Q14 */ ) && GE_16( clas, VOICED_CLAS ) ) || EQ_16( clas, AUDIO_CLAS ) ) { - *voicing_flag = 1; + *voicing_flag = 1; /* Q0 */ move16(); } test(); - if ( LT_16( voicing_fac_fx, 3277 ) && LT_16( clas, VOICED_CLAS ) ) + if ( LT_16( voicing_fac_fx, 3277 /* 0.2 in Q14 */ ) && LT_16( clas, VOICED_CLAS ) ) { *voicing_flag = 0; move16(); @@ -2016,14 +2017,14 @@ void AdaptiveStartBand_fx( *pt1++ = sub( *pt2++, *pt3++ ); move16(); /*Q2 */ } - tmp1 = extract_l( Mult_32_16( core_rate, 27046 ) ); /*Q14 */ - L_tmp = L_shr( L_mult0( tmp1, 22370 ), 15 ); /*Q27->1/6000 ->Q26 */ - tmp2 = extract_l( L_tmp ); /*Q26 */ - W_fx = mult_r( tmp1, tmp2 ); /*Q25 */ + tmp1 = extract_l( Mult_32_16( core_rate, 27046 /* 0.00005 in Q29 */ ) ); /*Q14 */ + L_tmp = L_shr( L_mult0( tmp1, 22370 /* 1/6000 in Q27 */ ), 15 ); /*Q27->1/6000 ->Q26 */ + tmp2 = extract_l( L_tmp ); /*Q26 */ + W_fx = mult_r( tmp1, tmp2 ); /*Q25 */ IF( EQ_16( clas, AUDIO_CLAS ) ) { - W_fx = mult_r( W_fx, 24576 ); /*Q25 */ + W_fx = mult_r( W_fx, 24576 /* 0.75 in Q15 */ ); /*Q25 */ } pos = 2; @@ -2050,8 +2051,8 @@ void AdaptiveStartBand_fx( } /*do the procedure for i==2*/ - L_tmp = L_max( L_msu( 171798692, lsf_fx[2], W_fx ), 171799 ); /* Q2.56+25+1 */ - Crit_fx = Mult_32_16( L_tmp, lsf_diff_fx[2] ); /* Q2.56+25+1+2.56-15 = Q11+2.56+2.56 */ + L_tmp = L_max( L_msu( 171798692 /* 1 in Q2.56+25+1 */, lsf_fx[2], W_fx ), 171799 /* 0.001 in Q2.56+25+1 */ ); /* Q2.56+25+1 */ + Crit_fx = Mult_32_16( L_tmp, lsf_diff_fx[2] ); /* Q2.56+25+1+2.56-15 = Q11+2.56+2.56 */ OptCrit_fx = L_add( Crit_fx, 0 ); pos = 2; @@ -2062,37 +2063,37 @@ void AdaptiveStartBand_fx( pt1 = &lsf_diff_fx[3]; FOR( i = 3; i < M2; i++ ) { - L_tmp = L_max( L_msu( 171798692, *pt2++, W_fx ), 171799 ); /* Q2.56+25+1 */ + L_tmp = L_max( L_msu( 171798692 /* 1 in Q2.56+25+1 */, *pt2++, W_fx ), 171799 /* 0.001 in Q2.56+25+1 */ ); /* Q2.56+25+1 */ Crit_fx = Mult_32_16( L_tmp, *pt1++ ); /* Q2.56+25+1+2.56-15 = Q11+2.56+2.56 */ IF( LE_32( Crit_fx, OptCrit_fx ) ) { OptCrit_fx = L_add( Crit_fx, 0 ); /* Q11+2.56+2.56 */ - pos = i; + pos = i; /* Q0 */ move16(); } } - tmp1 = add( mult_r( lsf_fx[pos - 1], 256 ), mult_r( lsf_fx[pos], 256 ) ); - *start_band = s_min( s_max( sub( tmp1, 40 ), 40 ), 160 ); + tmp1 = add( mult_r( lsf_fx[pos - 1], 256 ), mult_r( lsf_fx[pos], 256 ) ); /* Q0 */ + *start_band = s_min( s_max( sub( tmp1, 40 ), 40 ), 160 ); /* Q0 */ move16(); - L_tmp = Mult_32_16( *OptCrit_old_fx, 22938 ); /* Q11+2.56+2.56 */ + L_tmp = Mult_32_16( *OptCrit_old_fx, 22938 /* 0.7 in Q15 */ ); /* Q11+2.56+2.56 */ test(); test(); test(); test(); IF( NE_16( voicing_flag_old, *voicing_flag ) || ( *voicing_flag == 0 && LT_32( OptCrit_fx, *OptCrit_old_fx ) ) || - ( LT_32( OptCrit_fx, L_tmp ) && GT_32( *OptCrit_old_fx, 858993 ) ) ) + ( LT_32( OptCrit_fx, L_tmp ) && GT_32( *OptCrit_old_fx, 858993 /* 64 in Q11+2.56+2.56 */ ) ) ) { - *OptCrit_old_fx = OptCrit_fx; + *OptCrit_old_fx = OptCrit_fx; /* Q15 */ move16(); test(); test(); if ( LT_16( abs_s( sub( ( *start_band ), ( *start_band_old ) ) ), 20 ) && EQ_16( *voicing_flag, 1 ) && EQ_16( voicing_flag_old, 1 ) ) { - *start_band = *start_band_old; + *start_band = *start_band_old; /* Q0 */ move16(); } } @@ -2101,29 +2102,29 @@ void AdaptiveStartBand_fx( test(); if ( LT_32( OptCrit_fx, ( *OptCrit_old_fx ) ) && EQ_16( ( *voicing_flag ), 1 ) ) { - *OptCrit_old_fx = OptCrit_fx; + *OptCrit_old_fx = OptCrit_fx; /* Q15 */ move16(); } - *start_band = *start_band_old; + *start_band = *start_band_old; /* Q0 */ move16(); } IF( EQ_16( clas, AUDIO_CLAS ) ) { - *start_band = s_min( *start_band, 120 ); + *start_band = s_min( *start_band, 120 ); /* Q0 */ move16(); } flag = sub( s_and( *start_band, 0x0001 ), 1 ); IF( flag == 0 ) { - *start_band = sub( *start_band, 1 ); + *start_band = sub( *start_band, 1 ); /* Q0 */ move16(); } } - *start_band_old = *start_band; + *start_band_old = *start_band; /* Q0 */ move16(); return; diff --git a/lib_dec/hq_classifier_dec_fx.c b/lib_dec/hq_classifier_dec_fx.c index ace2e535c..e67d5f663 100644 --- a/lib_dec/hq_classifier_dec_fx.c +++ b/lib_dec/hq_classifier_dec_fx.c @@ -26,11 +26,11 @@ Word16 ivas_hq_classifier_dec_fx( /* o : Consumed bits Word16 bits; Word32 max_brate; - max_brate = HQ_32k; + max_brate = HQ_32k; /* Q0 */ move32(); if ( st_fx->element_mode > EVS_MONO ) { - max_brate = HQ_48k; + max_brate = HQ_48k; /* Q0 */ move32(); } test(); @@ -38,21 +38,21 @@ Word16 ivas_hq_classifier_dec_fx( /* o : Consumed bits test(); IF( ( EQ_16( length, L_SPEC32k ) || EQ_16( length, L_SPEC48k ) ) && LE_32( core_brate, max_brate ) ) { - *hqswb_clas = (Word16) get_next_indice_fx( st_fx, 2 ); + *hqswb_clas = (Word16) get_next_indice_fx( st_fx, 2 ); /* Q0 */ move16(); bits = 2; move16(); } ELSE IF( EQ_16( length, L_SPEC16k_EXT ) || EQ_16( length, L_SPEC48k_EXT ) ) { - *hqswb_clas = HQ_NORMAL; + *hqswb_clas = HQ_NORMAL; /* Q0 */ bits = 0; move16(); move16(); } ELSE { - *hqswb_clas = get_next_indice_fx( st_fx, 1 ); + *hqswb_clas = get_next_indice_fx( st_fx, 1 ); /* Q0 */ move16(); bits = 1; move16(); @@ -62,7 +62,7 @@ Word16 ivas_hq_classifier_dec_fx( /* o : Consumed bits move16(); if ( EQ_16( *hqswb_clas, HQ_TRANSIENT ) ) { - *is_transient = 1; + *is_transient = 1; /* Q0 */ move16(); } @@ -71,12 +71,12 @@ Word16 ivas_hq_classifier_dec_fx( /* o : Consumed bits { IF( EQ_16( length, L_SPEC32k ) ) { - *hqswb_clas = HQ_GEN_SWB; + *hqswb_clas = HQ_GEN_SWB; /* Q0 */ move16(); } ELSE IF( EQ_16( length, L_SPEC48k ) ) { - *hqswb_clas = HQ_GEN_FB; + *hqswb_clas = HQ_GEN_FB; /* Q0 */ move16(); } } @@ -97,11 +97,11 @@ Word16 hq_classifier_dec_fx( /* o : Consumed bits Word16 bits; Word32 max_brate; - max_brate = HQ_32k; + max_brate = HQ_32k; /* Q0 */ move32(); if ( st_fx->element_mode > EVS_MONO ) { - max_brate = HQ_48k; + max_brate = HQ_48k; /* Q0 */ move32(); } #ifndef SOLVED_COMP_ENC_DEC @@ -116,21 +116,21 @@ Word16 hq_classifier_dec_fx( /* o : Consumed bits IF( ( EQ_16( length, L_SPEC32k ) || EQ_16( length, L_SPEC48k ) ) && LE_32( core_brate, max_brate ) ) #endif { - *hqswb_clas = get_next_indice( st_fx, 2 ); + *hqswb_clas = get_next_indice( st_fx, 2 ); /* Q0 */ move16(); bits = 2; move16(); } ELSE IF( EQ_16( length, L_SPEC16k_EXT ) || EQ_16( length, L_SPEC48k_EXT ) ) { - *hqswb_clas = HQ_NORMAL; + *hqswb_clas = HQ_NORMAL; /* Q0 */ bits = 0; move16(); move16(); } ELSE { - *hqswb_clas = get_next_indice( st_fx, 1 ); + *hqswb_clas = get_next_indice( st_fx, 1 ); /* Q0 */ move16(); bits = 1; move16(); @@ -140,7 +140,7 @@ Word16 hq_classifier_dec_fx( /* o : Consumed bits move16(); if ( EQ_16( *hqswb_clas, HQ_TRANSIENT ) ) { - *is_transient = 1; + *is_transient = 1; /* Q0 */ move16(); } @@ -149,7 +149,7 @@ Word16 hq_classifier_dec_fx( /* o : Consumed bits { IF( EQ_16( length, L_SPEC32k ) ) { - *hqswb_clas = HQ_GEN_SWB; + *hqswb_clas = HQ_GEN_SWB; /* Q0 */ move16(); } #ifndef SOLVED_COMP_ENC_DEC @@ -158,7 +158,7 @@ Word16 hq_classifier_dec_fx( /* o : Consumed bits ELSE IF( EQ_16( length, L_SPEC48k ) ) #endif { - *hqswb_clas = HQ_GEN_FB; + *hqswb_clas = HQ_GEN_FB; /* Q0 */ move16(); } } diff --git a/lib_dec/hq_conf_fec_fx.c b/lib_dec/hq_conf_fec_fx.c index dfc19c542..adcd83076 100644 --- a/lib_dec/hq_conf_fec_fx.c +++ b/lib_dec/hq_conf_fec_fx.c @@ -16,22 +16,22 @@ * Initialization of HQ bands and subframes *--------------------------------------------------------------------------*/ void hq_configure_bfi_fx( - Word16 *nb_sfm, /* o : Number of sub bands Q0 */ - Word16 *num_Sb, /* o : Number of FEC sub bands ? Q0 */ - Word16 *num_bands_p, /* o : FEC sub bands Q0 */ - const Word16 **sfmsize, /* o : Subband bandwidths */ - const Word16 **sfm_start, /* o : Subband start coefficients */ - const Word16 **sfm_end /* o : Subband end coefficients */ + Word16 *nb_sfm, /* o : Number of sub bands Q0*/ + Word16 *num_Sb, /* o : Number of FEC sub bands ? Q0*/ + Word16 *num_bands_p, /* o : FEC sub bands Q0*/ + const Word16 **sfmsize, /* o : Subband bandwidths Q0*/ + const Word16 **sfm_start, /* o : Subband start coefficients Q0*/ + const Word16 **sfm_end /* o : Subband end coefficients Q0*/ ) { - *num_Sb = MAX_SB_NB; + *num_Sb = MAX_SB_NB; /* Q0 */ move16(); - *nb_sfm = SFM_N_NB; + *nb_sfm = SFM_N_NB; /* Q0 */ move16(); - Copy( Num_bands_NB, num_bands_p, *num_Sb ); - *sfmsize = band_len_wb; - *sfm_start = band_start_wb; - *sfm_end = band_end_wb; + Copy( Num_bands_NB, num_bands_p, *num_Sb ); /* Q0 */ + *sfmsize = band_len_wb; /* Q0 */ + *sfm_start = band_start_wb; /* Q0 */ + *sfm_end = band_end_wb; /* Q0 */ move16(); move16(); move16(); diff --git a/lib_dec/hq_core_dec_fx.c b/lib_dec/hq_core_dec_fx.c index 9ff889997..de8d19e32 100644 --- a/lib_dec/hq_core_dec_fx.c +++ b/lib_dec/hq_core_dec_fx.c @@ -19,11 +19,11 @@ void hq_core_dec_fx( Decoder_State *st_fx, /* i/o: decoder state structure fx */ - Word16 synth[], /* o : output synthesis */ + Word16 synth[], /* o : output synthesis Q_synth*/ Word16 *Q_synth, /* o : Q value of synth */ - const Word16 output_frame, /* i : output frame length */ - const Word16 hq_core_type, /* i : HQ core type */ - const Word16 core_switching_flag /* i : ACELP->HQ switching frame flag */ + const Word16 output_frame, /* i : output frame length Q0*/ + const Word16 hq_core_type, /* i : HQ core type Q0*/ + const Word16 core_switching_flag /* i : ACELP->HQ switching frame flag Q0*/ ) { Word16 num_bits, is_transient, hqswb_clas, inner_frame; @@ -62,15 +62,17 @@ void hq_core_dec_fx( move16(); sfm_start = sfm_end = NULL; num_Sb = nb_sfm = 0; + move16(); + move16(); - st_fx->hTcxCfg->tcx_last_overlap_mode = st_fx->hTcxCfg->tcx_curr_overlap_mode; + st_fx->hTcxCfg->tcx_last_overlap_mode = st_fx->hTcxCfg->tcx_curr_overlap_mode; /* Q0 */ move16(); if ( EQ_16( st_fx->hTcxCfg->tcx_curr_overlap_mode, FULL_OVERLAP ) ) { - st_fx->hTcxCfg->tcx_last_overlap_mode = ALDO_WINDOW; + st_fx->hTcxCfg->tcx_last_overlap_mode = ALDO_WINDOW; /* Q0 */ move16(); } - st_fx->hTcxCfg->tcx_curr_overlap_mode = ALDO_WINDOW; + st_fx->hTcxCfg->tcx_curr_overlap_mode = ALDO_WINDOW; /* Q0 */ move16(); /*-------------------------------------------------------------------------- * Find the number of bits for transform-domain coding @@ -114,18 +116,18 @@ void hq_core_dec_fx( } #endif /* subtract signalling bits */ - num_bits = sub( num_bits, st_fx->next_bit_pos ); + num_bits = sub( num_bits, st_fx->next_bit_pos ); /* Q0 */ /* set FEC parameters */ - flag_uv = sub( 1, hHQ_core->HqVoicing ); + flag_uv = sub( 1, hHQ_core->HqVoicing ); /* Q0 */ /* subtract the number of bits for pitch & gain at higher bitrates */ test(); IF( !( core_switching_flag ) && GT_32( st_fx->core_brate, MINIMUM_RATE_TO_ENCODE_VOICING_FLAG ) ) { - hHQ_core->HqVoicing = get_next_indice( st_fx, 1 ); + hHQ_core->HqVoicing = get_next_indice( st_fx, 1 ); /* Q0 */ move16(); - num_bits = sub( num_bits, 1 ); + num_bits = sub( num_bits, 1 ); /* Q0 */ } ELSE { @@ -133,7 +135,7 @@ void hq_core_dec_fx( move16(); if ( GT_32( st_fx->core_brate, MINIMUM_RATE_TO_ENCODE_VOICING_FLAG ) ) { - hHQ_core->HqVoicing = 1; + hHQ_core->HqVoicing = 1; /* Q0 */ move16(); } } @@ -145,10 +147,10 @@ void hq_core_dec_fx( } /* set inner frame (== coded bandwidth) length */ - inner_frame = inner_frame_tbl[st_fx->bwidth]; + inner_frame = inner_frame_tbl[st_fx->bwidth]; /* Q0 */ move16(); #ifndef ADD_IVAS_HQ_CODE_L_SPEC - L_spec = inner_frame; + L_spec = inner_frame; /* Q0 */ #endif move16(); @@ -174,7 +176,7 @@ void hq_core_dec_fx( IF( EQ_16( st_fx->bfi, 1 ) ) { - is_transient = hHQ_core->old_is_transient[0]; + is_transient = hHQ_core->old_is_transient[0]; /* Q0 */ move16(); IF( GE_16( output_frame, L_FRAME16k ) ) /* Apply phase ecu for WB, SWB and FB */ { @@ -189,22 +191,22 @@ void hq_core_dec_fx( output_frame, sfm_start, sfm_end ); } - hHQ_core->old_is_transient[2] = hHQ_core->old_is_transient[1]; + hHQ_core->old_is_transient[2] = hHQ_core->old_is_transient[1]; /* Q0 */ move16(); - hHQ_core->old_is_transient[1] = hHQ_core->old_is_transient[0]; + hHQ_core->old_is_transient[1] = hHQ_core->old_is_transient[0]; /* Q0 */ move16(); IF( GE_16( output_frame, L_FRAME16k ) ) { /* keep st->previoussynth updated as in FEC_HQ_pitch_analysis but no LP analysis */ - delay_comp = NS2SA_FX2( st_fx->output_Fs, DELAY_CLDFB_NS ); + delay_comp = NS2SA_FX2( st_fx->output_Fs, DELAY_CLDFB_NS ); /* Q0 */ - Copy( st_fx->previoussynth_fx + delay_comp, st_fx->previoussynth_fx, sub( output_frame, delay_comp ) ); - Copy( st_fx->delay_buf_out_fx, st_fx->previoussynth_fx + output_frame - delay_comp, delay_comp ); + Copy( st_fx->previoussynth_fx + delay_comp, st_fx->previoussynth_fx, sub( output_frame, delay_comp ) ); /* Q0 */ + Copy( st_fx->delay_buf_out_fx, st_fx->previoussynth_fx + output_frame - delay_comp, delay_comp ); /* Q0 */ flag_uv = 1; move16(); /* disable costly pitch out synthesis in bfi frame */ - hHQ_core->HqVoicing = sub( 1, flag_uv ); /* safety setting for HQ->ACELP switch logic */ + hHQ_core->HqVoicing = sub( 1, flag_uv ); /* safety setting for HQ->ACELP switch logic Q0*/ set16_fx( hHQ_core->fer_samples_fx, 0, L_FRAME48k ); /* safety, create a known signal state for HQ->ACELP switch logic */ } } @@ -222,7 +224,7 @@ void hq_core_dec_fx( /* HQ low rate decoder */ hq_lr_dec_fx( st_fx, t_audio_q, inner_frame, num_bits, &is_transient ); - hqswb_clas = is_transient; + hqswb_clas = is_transient; /* Q0 */ move16(); Q_audio = 12; move16(); @@ -251,8 +253,8 @@ void hq_core_dec_fx( } ELSE { - tmp = mult_r( output_frame, 410 / 2 ); /* 1/8000 in Q15 */ - ener_match = hq_nominal_scaling_inv[tmp]; + tmp = mult_r( output_frame, 410 / 2 ); /* 1/8000 in Q15 */ + ener_match = hq_nominal_scaling_inv[tmp]; /* Q13 */ move16(); FOR( i = 0; i < inner_frame; i++ ) { @@ -280,7 +282,7 @@ void hq_core_dec_fx( IF( EQ_16( st_fx->bws_cnt1, N_NS2W_FRAMES ) ) { ener_match = 32767; - move16(); /*Q15*/ + move16(); /* 1.0f in Q15 */ } ELSE { @@ -291,11 +293,11 @@ void hq_core_dec_fx( { FOR( i = 0; i < NUM_TIME_SWITCHING_BLOCKS; i++ ) { - tmp_loop = mult( inner_frame, 8192 ); - FOR( j = mult( inner_frame_tbl[sub( st_fx->bwidth, 1 )], 8192 ); j < tmp_loop; j++ ) + tmp_loop = mult( inner_frame, 8192 /* 0.25 in Q15 */ ); + FOR( j = mult( inner_frame_tbl[st_fx->bwidth - 1], 8192 ); j < tmp_loop; j++ ) { - tmp = i_mult( i, inner_frame ); /*Q0*/ - tmp = mult( tmp, 8192 ); /*Q0*/ + tmp = i_mult( i, inner_frame ); /*Q0*/ + tmp = mult( tmp, 8192 /* 0.25 in Q15 */ ); /*Q0*/ tmp = add( tmp, j ); t_audio_q[tmp] = Mult_32_16( t_audio_q[tmp], ener_match ); move32(); /*Q12*/ @@ -304,7 +306,7 @@ void hq_core_dec_fx( } ELSE { - FOR( i = inner_frame_tbl[sub( st_fx->bwidth, 1 )]; i < inner_frame; i++ ) + FOR( i = inner_frame_tbl[st_fx->bwidth - 1]; i < inner_frame; i++ ) { t_audio_q[i] = Mult_32_16( t_audio_q[i], ener_match ); /*Q12*/ move32(); @@ -315,11 +317,11 @@ void hq_core_dec_fx( /* WB/SWB bandwidth switching */ IF( is_transient ) { - Copy_Scale_sig_32_16( &t_audio_q[240], st_fx->t_audio_q_fx, 80, -13 ); + Copy_Scale_sig_32_16( &t_audio_q[240], st_fx->t_audio_q_fx, 80, -13 ); /* -1Q */ } ELSE { - Copy_Scale_sig_32_16( t_audio_q, st_fx->t_audio_q_fx, L_FRAME, -13 ); + Copy_Scale_sig_32_16( t_audio_q, st_fx->t_audio_q_fx, L_FRAME, -13 ); /* -1Q */ } @@ -421,7 +423,7 @@ void hq_core_dec_fx( test(); IF( st_fx->bfi == 0 && st_fx->prev_bfi == 0 ) { - Copy_Scale_sig( hHQ_core->old_out_fx + N_ZERO_NB, hHQ_nbfec->prev_oldauOut_fx, output_frame - N_ZERO_NB, negate( hHQ_core->Q_old_wtda ) ); + Copy_Scale_sig( hHQ_core->old_out_fx + N_ZERO_NB, hHQ_nbfec->prev_oldauOut_fx, output_frame - N_ZERO_NB, negate( hHQ_core->Q_old_wtda ) ); /* 15 - exp_old_out - Q_old_wtda */ } ELSE IF( EQ_16( st_fx->prev_bfi, 1 ) ) { @@ -499,7 +501,7 @@ void hq_core_dec_fx( IF( !st_fx->bfi && st_fx->prev_bfi && GE_32( st_fx->last_total_brate, HQ_48k ) && EQ_16( st_fx->last_codec_mode, MODE2 ) && ( EQ_16( st_fx->last_core_bfi, TCX_20_CORE ) || EQ_16( st_fx->last_core_bfi, TCX_10_CORE ) ) && st_fx->plcInfo.concealment_method == TCX_NONTONAL && LT_32( st_fx->plcInfo.nbLostCmpt, 4 ) ) { #ifdef BASOP_NOGLOB - st_fx->plcInfo.recovery_gain = shl_sat( st_fx->plcInfo.recovery_gain, *Q_synth ); + st_fx->plcInfo.recovery_gain = shl_sat( st_fx->plcInfo.recovery_gain, *Q_synth ); /* Q14 + Q_synth */ move16(); #else st_fx->plcInfo.recovery_gain = shl( st_fx->plcInfo.recovery_gain, *Q_synth ); @@ -526,7 +528,7 @@ void hq_core_dec_fx( { hHQ_core->oldHqVoicing = 1; move16(); - Copy( gapsynth_fx, hHQ_core->oldgapsynth_fx, L_FRAME48k ); + Copy( gapsynth_fx, hHQ_core->oldgapsynth_fx, L_FRAME48k ); /* q_gapsynth */ } ELSE { @@ -548,9 +550,9 @@ void hq_core_dec_fx( IF( EQ_16( output_frame, L_FRAME8k ) ) { - Copy32( wtda_audio, hHQ_nbfec->oldIMDCTout_fx, L_FRAME8k / 2 ); - Copy( &hHQ_nbfec->old_auOut_2fr_fx[output_frame], hHQ_nbfec->old_auOut_2fr_fx, output_frame ); - Copy_Scale_sig( synth, &hHQ_nbfec->old_auOut_2fr_fx[output_frame], output_frame, negate( *Q_synth ) ); + Copy32( wtda_audio, hHQ_nbfec->oldIMDCTout_fx, L_FRAME8k / 2 ); /* q_wtda */ + Copy( &hHQ_nbfec->old_auOut_2fr_fx[output_frame], hHQ_nbfec->old_auOut_2fr_fx, output_frame ); /* q_old_auOut */ + Copy_Scale_sig( synth, &hHQ_nbfec->old_auOut_2fr_fx[output_frame], output_frame, negate( *Q_synth ) ); /* Q0 */ } /* prepare synthesis output buffer (as recent as possible) for HQ FEC */ @@ -558,11 +560,11 @@ void hq_core_dec_fx( { Word16 nbsubfr; /*nbsubfr = extract_l(L_mult0(st_fx->L_frame,FL2WORD16(1/L_SUBFR)));*/ - nbsubfr = 4; + nbsubfr = 4; /* Q0 */ move16(); if ( EQ_16( st_fx->L_frame, 320 ) ) { - nbsubfr = 5; + nbsubfr = 5; /* Q0 */ move16(); } @@ -572,9 +574,9 @@ void hq_core_dec_fx( { set32_fx( &st_fx->old_pitch_buf_fx[nbsubfr], ( L_SUBFR << 16 ), nbsubfr ); } - Copy32( &st_fx->old_pitch_buf_fx[nbsubfr], &st_fx->old_pitch_buf_fx[0], nbsubfr ); + Copy32( &st_fx->old_pitch_buf_fx[nbsubfr], &st_fx->old_pitch_buf_fx[0], nbsubfr ); /* 15Q16 */ set32_fx( &st_fx->old_pitch_buf_fx[nbsubfr], ( L_SUBFR << 16 ), nbsubfr ); - Copy( &st_fx->mem_pitch_gain[2], &st_fx->mem_pitch_gain[nbsubfr + 2], nbsubfr ); + Copy( &st_fx->mem_pitch_gain[2], &st_fx->mem_pitch_gain[nbsubfr + 2], nbsubfr ); /* Q14 */ set16_fx( &st_fx->mem_pitch_gain[2], 0, nbsubfr ); } #ifdef ADD_IVAS_HQ_CODE @@ -590,12 +592,12 @@ void hq_core_dec_fx( void ivas_hq_core_dec_fx( Decoder_State *st_fx, /* i/o: decoder state structure fx */ - Word16 synth[], /* o : output synthesis */ + Word16 synth[], /* o : output synthesis Q_synth*/ Word16 *Q_synth, /* o : Q value of synth */ - const Word16 output_frame, /* i : output frame length */ - const Word16 hq_core_type, /* i : HQ core type */ - const Word16 core_switching_flag, /* i : ACELP->HQ switching frame flag */ - Word16 output[], + const Word16 output_frame, /* i : output frame length Q0*/ + const Word16 hq_core_type, /* i : HQ core type Q0*/ + const Word16 core_switching_flag, /* i : ACELP->HQ switching frame flag Q0*/ + Word16 output[], /* Q_ouput */ Word16 *Q_output ) { Word16 num_bits, is_transient, hqswb_clas, inner_frame; @@ -656,14 +658,14 @@ void ivas_hq_core_dec_fx( hTcxDec = st_fx->hTcxDec; - st_fx->hTcxCfg->tcx_last_overlap_mode = st_fx->hTcxCfg->tcx_curr_overlap_mode; + st_fx->hTcxCfg->tcx_last_overlap_mode = st_fx->hTcxCfg->tcx_curr_overlap_mode; /* Q0 */ move16(); if ( EQ_16( st_fx->hTcxCfg->tcx_curr_overlap_mode, FULL_OVERLAP ) ) { - st_fx->hTcxCfg->tcx_last_overlap_mode = ALDO_WINDOW; + st_fx->hTcxCfg->tcx_last_overlap_mode = ALDO_WINDOW; /* Q0 */ move16(); } - st_fx->hTcxCfg->tcx_curr_overlap_mode = ALDO_WINDOW; + st_fx->hTcxCfg->tcx_curr_overlap_mode = ALDO_WINDOW; /* Q0 */ move16(); test(); test(); @@ -678,7 +680,7 @@ void ivas_hq_core_dec_fx( num_bits = extract_l( L_shr( L_tmp, 3 ) ); /*Q0 */ /* Set default spectrum length */ - L_spec = l_spec_tbl[st_fx->bwidth]; + L_spec = l_spec_tbl[st_fx->bwidth]; /* Q0 */ move16(); IF( !st_fx->bfi ) { @@ -686,7 +688,7 @@ void ivas_hq_core_dec_fx( { IF( NE_16( st_fx->element_mode, EVS_MONO ) ) { - L_spec = l_spec_ext_tbl[st_fx->bwidth]; + L_spec = l_spec_ext_tbl[st_fx->bwidth]; /* Q0 */ move16(); } ELSE @@ -706,18 +708,18 @@ void ivas_hq_core_dec_fx( acelp_plc_mdct_transition_fx( st_fx ); } /* subtract signalling bits */ - num_bits = sub( num_bits, st_fx->next_bit_pos ); + num_bits = sub( num_bits, st_fx->next_bit_pos ); /* Q0 */ /* set FEC parameters */ - flag_uv = sub( 1, hHQ_core->HqVoicing ); + flag_uv = sub( 1, hHQ_core->HqVoicing ); /* Q0 */ /* subtract the number of bits for pitch & gain at higher bitrates */ test(); IF( !( core_switching_flag ) && GT_32( st_fx->core_brate, MINIMUM_RATE_TO_ENCODE_VOICING_FLAG ) ) { - hHQ_core->HqVoicing = get_next_indice_fx( st_fx, 1 ); + hHQ_core->HqVoicing = get_next_indice_fx( st_fx, 1 ); /* Q0 */ move16(); - num_bits = sub( num_bits, 1 ); + num_bits = sub( num_bits, 1 ); /* Q0 */ } ELSE { @@ -725,7 +727,7 @@ void ivas_hq_core_dec_fx( move16(); if ( GT_32( st_fx->core_brate, MINIMUM_RATE_TO_ENCODE_VOICING_FLAG ) ) { - hHQ_core->HqVoicing = 1; + hHQ_core->HqVoicing = 1; /* Q0 */ move16(); } } @@ -737,7 +739,7 @@ void ivas_hq_core_dec_fx( } /* set inner frame (== coded bandwidth) length */ - inner_frame = inner_frame_tbl[st_fx->bwidth]; + inner_frame = inner_frame_tbl[st_fx->bwidth]; /* Q0 */ move16(); IF( EQ_16( st_fx->bfi, 0 ) ) @@ -746,7 +748,7 @@ void ivas_hq_core_dec_fx( move16(); if ( GE_16( output_frame, L_FRAME16k ) ) { - hHQ_core->ph_ecu_HqVoicing = hHQ_core->HqVoicing; + hHQ_core->ph_ecu_HqVoicing = hHQ_core->HqVoicing; /* Q0 */ move16(); } } @@ -762,7 +764,7 @@ void ivas_hq_core_dec_fx( IF( EQ_16( st_fx->bfi, 1 ) ) { - is_transient = hHQ_core->old_is_transient[0]; + is_transient = hHQ_core->old_is_transient[0]; /* Q0 */ move16(); IF( GE_16( output_frame, L_FRAME16k ) ) /* Apply phase ecu for WB, SWB and FB */ { @@ -777,22 +779,22 @@ void ivas_hq_core_dec_fx( output_frame, sfm_start, sfm_end ); } - hHQ_core->old_is_transient[2] = hHQ_core->old_is_transient[1]; + hHQ_core->old_is_transient[2] = hHQ_core->old_is_transient[1]; /* Q0 */ move16(); - hHQ_core->old_is_transient[1] = hHQ_core->old_is_transient[0]; + hHQ_core->old_is_transient[1] = hHQ_core->old_is_transient[0]; /* Q0 */ move16(); IF( GE_16( output_frame, L_FRAME16k ) ) { /* keep st->previoussynth updated as in FEC_HQ_pitch_analysis but no LP analysis */ - delay_comp = NS2SA_FX2( st_fx->output_Fs, DELAY_CLDFB_NS ); + delay_comp = NS2SA_FX2( st_fx->output_Fs, DELAY_CLDFB_NS ); /* Q0 */ - Copy( st_fx->previoussynth_fx + delay_comp, st_fx->previoussynth_fx, sub( output_frame, delay_comp ) ); - Copy( st_fx->delay_buf_out_fx, st_fx->previoussynth_fx + output_frame - delay_comp, delay_comp ); + Copy( st_fx->previoussynth_fx + delay_comp, st_fx->previoussynth_fx, sub( output_frame, delay_comp ) ); /* q_previoussynth */ + Copy( st_fx->delay_buf_out_fx, st_fx->previoussynth_fx + output_frame - delay_comp, delay_comp ); /* q_delay_buff */ flag_uv = 1; move16(); /* disable costly pitch out synthesis in bfi frame */ - hHQ_core->HqVoicing = sub( 1, flag_uv ); /* safety setting for HQ->ACELP switch logic */ + hHQ_core->HqVoicing = sub( 1, flag_uv ); /* safety setting for HQ->ACELP switch logic Q0*/ move16(); set16_fx( hHQ_core->fer_samples_fx, 0, L_FRAME48k ); /* safety, create a known signal state for HQ->ACELP switch logic */ } @@ -811,7 +813,7 @@ void ivas_hq_core_dec_fx( /* HQ low rate decoder */ hq_lr_dec_fx( st_fx, t_audio_q, inner_frame, num_bits, &is_transient ); - hqswb_clas = is_transient; + hqswb_clas = is_transient; /* Q0 */ move16(); Q_audio = 12; move16(); @@ -843,8 +845,8 @@ void ivas_hq_core_dec_fx( } ELSE { - tmp = mult_r( output_frame, 410 / 2 ); /* 1/8000 in Q15 */ - ener_match = hq_nominal_scaling_inv[tmp]; + tmp = mult_r( output_frame, 410 / 2 ); /* 1/8000 in Q15 */ + ener_match = hq_nominal_scaling_inv[tmp]; /* Q13 */ move16(); FOR( i = 0; i < inner_frame; i++ ) { @@ -872,7 +874,7 @@ void ivas_hq_core_dec_fx( IF( EQ_16( st_fx->bws_cnt1, N_NS2W_FRAMES ) ) { ener_match = 32767; - move16(); /*Q15*/ + move16(); /* 1.0f in Q15*/ } ELSE { @@ -883,11 +885,11 @@ void ivas_hq_core_dec_fx( { FOR( i = 0; i < NUM_TIME_SWITCHING_BLOCKS; i++ ) { - tmp_loop = mult( inner_frame, 8192 ); - FOR( j = mult( inner_frame_tbl[sub( st_fx->bwidth, 1 )], 8192 ); j < tmp_loop; j++ ) + tmp_loop = mult( inner_frame, 8192 /* 0.25 in Q15 */ ); /* Q0 */ + FOR( j = mult( inner_frame_tbl[st_fx->bwidth - 1], 8192 ); j < tmp_loop; j++ ) { - tmp = i_mult( i, inner_frame ); /*Q0*/ - tmp = mult( tmp, 8192 ); /*Q0*/ + tmp = i_mult( i, inner_frame ); /*Q0*/ + tmp = mult( tmp, 8192 /* 0.25 in Q15 */ ); /*Q0*/ tmp = add( tmp, j ); t_audio_q[tmp] = Mult_32_16( t_audio_q[tmp], ener_match ); move32(); /*Q12*/ @@ -896,7 +898,7 @@ void ivas_hq_core_dec_fx( } ELSE { - FOR( i = inner_frame_tbl[sub( st_fx->bwidth, 1 )]; i < inner_frame; i++ ) + FOR( i = inner_frame_tbl[st_fx->bwidth - 1]; i < inner_frame; i++ ) { t_audio_q[i] = Mult_32_16( t_audio_q[i], ener_match ); /*Q12*/ move32(); @@ -907,11 +909,11 @@ void ivas_hq_core_dec_fx( /* WB/SWB bandwidth switching */ IF( is_transient ) { - Copy_Scale_sig_32_16( &t_audio_q[240], st_fx->t_audio_q_fx, 80, -13 ); + Copy_Scale_sig_32_16( &t_audio_q[240], st_fx->t_audio_q_fx, 80, -13 ); /* -1Q */ } ELSE { - Copy_Scale_sig_32_16( t_audio_q, st_fx->t_audio_q_fx, L_FRAME, -13 ); + Copy_Scale_sig_32_16( t_audio_q, st_fx->t_audio_q_fx, L_FRAME, -13 ); /* -1Q */ } @@ -926,34 +928,34 @@ void ivas_hq_core_dec_fx( { /* Initializations for TCX MDCT framework, to be used for switching frame */ tcx_cfg = st_fx->hTcxCfg; - L_frameTCX_glob = hTcxDec->L_frameTCX; + L_frameTCX_glob = hTcxDec->L_frameTCX; /* Q0 */ move16(); - L_frame_glob = st_fx->L_frame; + L_frame_glob = st_fx->L_frame; /* Q0 */ move16(); - L_spec = hTcxDec->L_frameTCX; + L_spec = hTcxDec->L_frameTCX; /* Q0 */ move16(); - st_fx->fscale = sr2fscale_fx( st_fx->sr_core ); + st_fx->fscale = sr2fscale_fx( st_fx->sr_core ); /* Q0 */ // fscaleFB = sr2fscale( st_fx->output_Fs ); // encoderLookahead = ( L_LOOK_12k8 * st_fx->fscale ) / FSCALE_DENOM; // encoderLookaheadFB = ( L_LOOK_12k8 * fscaleFB ) / FSCALE_DENOM; - mdctWindowLength = getMdctWindowLength( st_fx->fscale ); + mdctWindowLength = getMdctWindowLength( st_fx->fscale ); /* Q0 */ Word16 temp, temp_e; temp = BASOP_Util_Divide3232_Scale( st_fx->output_Fs, st_fx->sr_core, &temp_e ); - mdctWindowLengthFB = extract_l( L_shr( L_mult0( temp, mdctWindowLength ), sub( 15, temp_e ) ) ); + mdctWindowLengthFB = extract_l( L_shr( L_mult0( temp, mdctWindowLength ), sub( 15, temp_e ) ) ); /* Q0 */ IF( core_switching_flag ) { - tcx_cfg->tcx_last_overlap_mode = TRANSITION_OVERLAP; + tcx_cfg->tcx_last_overlap_mode = TRANSITION_OVERLAP; /* Q0 */ move16(); - tcx_cfg->tcx_curr_overlap_mode = FULL_OVERLAP; + tcx_cfg->tcx_curr_overlap_mode = FULL_OVERLAP; /* Q0 */ move16(); } ELSE { - tcx_cfg->tcx_last_overlap_mode = ALDO_WINDOW; + tcx_cfg->tcx_last_overlap_mode = ALDO_WINDOW; /* Q0 */ move16(); - tcx_cfg->tcx_curr_overlap_mode = ALDO_WINDOW; + tcx_cfg->tcx_curr_overlap_mode = ALDO_WINDOW; /* Q0 */ move16(); - st_fx->last_core = HQ_CORE; /* Needed to decode non-transition frame */ + st_fx->last_core = HQ_CORE; /* Needed to decode non-transition frame Q0*/ move16(); } @@ -961,11 +963,11 @@ void ivas_hq_core_dec_fx( init_tcx_info_fx( st_fx, L_frame_glob, L_frameTCX_glob, 0, st_fx->bfi, &tcx_offset, &tcx_offsetFB, &L_frame, &L_frameTCX, &left_rect, &L_spec ); - overlap = tcx_cfg->tcx_mdct_window_length; + overlap = tcx_cfg->tcx_mdct_window_length; /* Q0 */ move16(); - overlapFB = tcx_cfg->tcx_mdct_window_lengthFB; + overlapFB = tcx_cfg->tcx_mdct_window_lengthFB; /* Q0 */ move16(); - index = tcx_cfg->tcx_last_overlap_mode; + index = tcx_cfg->tcx_last_overlap_mode; /* Q0 */ move16(); #ifndef MSAN_FIX @@ -978,9 +980,9 @@ void ivas_hq_core_dec_fx( left_rect, tcx_offset, overlap, L_frame, L_frameTCX, shr( s_max( L_frameTCX, L_spec ), 1 ), L_frame_glob, 0, st_fx->bfi, hHQ_core->old_out_LB_fx, &hHQ_core->Q_old_wtda_LB, st_fx, 0, acelp_zir ); // values till L_frame same - Scale_sig( wtda_audio_16 + L_frame, overlap, Q1 ); + Scale_sig( wtda_audio_16 + L_frame, overlap, Q1 ); /* q_wtda + 1 */ - Copy( wtda_audio_16 + sub( shr( overlap, 1 ), tcx_offset ), output, L_frame_glob ); + Copy( wtda_audio_16 + sub( shr( overlap, 1 ), tcx_offset ), output, L_frame_glob ); /* q_wtda + 1 */ /* FB synthesis */ temp = BASOP_Util_Divide3232_Scale( L_mult0( FSCALE_DENOM, L_frameTCX_glob ), L_frame_glob, &temp_e ); @@ -988,14 +990,14 @@ void ivas_hq_core_dec_fx( IMDCT_fx( t_audio_q, E_audio, hTcxDec->syn_OverlFB, hTcxDec->syn_Overl_TDACFB, wtda_audio_16, tcx_cfg->tcx_aldo_window_1_FB, tcx_cfg->tcx_aldo_window_1_FB_trunc, tcx_cfg->tcx_aldo_window_2_FB, tcx_cfg->tcx_mdct_window_halfFB, tcx_cfg->tcx_mdct_window_minimumFB, tcx_cfg->tcx_mdct_window_transFB, tcx_cfg->tcx_mdct_window_half_lengthFB, tcx_cfg->tcx_mdct_window_min_lengthFB, index, left_rect, tcx_offsetFB, overlapFB, L_frameTCX, L_frameTCX, shr( s_max( L_frameTCX, L_spec ), 1 ), L_frameTCX_glob, 0, st_fx->bfi, hHQ_core->old_out_fx, &hHQ_core->Q_old_wtda, st_fx, temp, acelp_zir ); - Scale_sig( wtda_audio_16 + L_frameTCX, overlapFB, Q1 ); + Scale_sig( wtda_audio_16 + L_frameTCX, overlapFB, Q1 ); /* q_wtda + 1 */ - Copy( wtda_audio_16 + sub( shr( overlapFB, 1 ), tcx_offsetFB ), synth, L_frameTCX_glob ); + Copy( wtda_audio_16 + sub( shr( overlapFB, 1 ), tcx_offsetFB ), synth, L_frameTCX_glob ); /* q_wtda */ - Copy_Scale_sig_16_32( wtda_audio_16, wtda_audio, 2 * L_FRAME48k, 12 ); + Copy_Scale_sig_16_32( wtda_audio_16, wtda_audio, 2 * L_FRAME48k, 12 ); /* q_wtda + 12 */ IF( !core_switching_flag ) { - st_fx->last_core = ACELP_CORE; /* Restore last core */ + st_fx->last_core = ACELP_CORE; /* Restore last core Q0*/ move16(); } } @@ -1036,9 +1038,9 @@ void ivas_hq_core_dec_fx( tmp = Sqrt16( tmp, &tmp_e ); ener_match = shr( tmp, sub( 2, tmp_e ) ); // Q13 - v_multc_fixed_16( t_audio_q, ener_match, t_audio_q, inner_frame ); // Q + v_multc_fixed_16( t_audio_q, ener_match, t_audio_q, inner_frame ); // Q10 - Scale_sig32( t_audio_q, inner_frame, Q2 ); + Scale_sig32( t_audio_q, inner_frame, Q2 ); // Q10 + Q2 Q_audio = Q_G_audio; move16(); Inverse_Transform( t_audio_q, &Q_audio, wtda_audio_LB, is_transient, st_fx->L_frame, inner_frame, st_fx->element_mode ); @@ -1052,7 +1054,7 @@ void ivas_hq_core_dec_fx( test(); IF( EQ_16( st_fx->bfi, 0 ) && st_fx->prev_bfi == 0 ) { - Copy_Scale_sig( hHQ_core->old_out_fx + N_ZERO_NB, hHQ_nbfec->prev_oldauOut_fx, output_frame - N_ZERO_NB, negate( hHQ_core->Q_old_wtda ) ); + Copy_Scale_sig( hHQ_core->old_out_fx + N_ZERO_NB, hHQ_nbfec->prev_oldauOut_fx, output_frame - N_ZERO_NB, negate( hHQ_core->Q_old_wtda ) ); /* 31 - exp_old_out - Q_old_wtda */ } ELSE IF( EQ_16( st_fx->prev_bfi, 1 ) ) { @@ -1129,7 +1131,7 @@ void ivas_hq_core_dec_fx( IF( !st_fx->bfi && st_fx->prev_bfi && GE_32( st_fx->last_total_brate, HQ_48k ) && EQ_16( st_fx->last_codec_mode, MODE2 ) && ( EQ_16( st_fx->last_core_bfi, TCX_20_CORE ) || EQ_16( st_fx->last_core_bfi, TCX_10_CORE ) ) && EQ_16( st_fx->plcInfo.concealment_method, TCX_NONTONAL ) && LT_32( st_fx->plcInfo.nbLostCmpt, 4 ) ) { #ifdef BASOP_NOGLOB - st_fx->plcInfo.recovery_gain = shl_sat( st_fx->plcInfo.recovery_gain, *Q_synth ); + st_fx->plcInfo.recovery_gain = shl_sat( st_fx->plcInfo.recovery_gain, *Q_synth ); /* Q15 */ #else st_fx->plcInfo.recovery_gain = shl( st_fx->plcInfo.recovery_gain, *Q_synth ); #endif @@ -1155,7 +1157,7 @@ void ivas_hq_core_dec_fx( { hHQ_core->oldHqVoicing = 1; move16(); - Copy( gapsynth_fx, hHQ_core->oldgapsynth_fx, L_FRAME48k ); + Copy( gapsynth_fx, hHQ_core->oldgapsynth_fx, L_FRAME48k ); /* q_gapsynth */ } ELSE { @@ -1177,9 +1179,9 @@ void ivas_hq_core_dec_fx( IF( EQ_16( output_frame, L_FRAME8k ) ) { - Copy32( wtda_audio, hHQ_nbfec->oldIMDCTout_fx, L_FRAME8k / 2 ); - Copy( &hHQ_nbfec->old_auOut_2fr_fx[output_frame], hHQ_nbfec->old_auOut_2fr_fx, output_frame ); - Copy_Scale_sig( synth, &hHQ_nbfec->old_auOut_2fr_fx[output_frame], output_frame, negate( *Q_synth ) ); + Copy32( wtda_audio, hHQ_nbfec->oldIMDCTout_fx, L_FRAME8k / 2 ); /* q_wtda */ + Copy( &hHQ_nbfec->old_auOut_2fr_fx[output_frame], hHQ_nbfec->old_auOut_2fr_fx, output_frame ); /* Q_old_auOut */ + Copy_Scale_sig( synth, &hHQ_nbfec->old_auOut_2fr_fx[output_frame], output_frame, negate( *Q_synth ) ); /* Q0 */ } /* prepare synthesis output buffer (as recent as possible) for HQ FEC */ @@ -1187,10 +1189,10 @@ void ivas_hq_core_dec_fx( { Word16 nbsubfr; /*nbsubfr = extract_l(L_mult0(st_fx->L_frame,FL2WORD16(1/L_SUBFR)));*/ - nbsubfr = 4; + nbsubfr = 4; /* Q0 */ if ( EQ_16( st_fx->L_frame, 320 ) ) { - nbsubfr = 5; + nbsubfr = 5; /* Q0 */ move16(); } @@ -1200,16 +1202,16 @@ void ivas_hq_core_dec_fx( { set32_fx( &st_fx->old_pitch_buf_fx[nbsubfr], ( L_SUBFR << 16 ), nbsubfr ); } - Copy32( &st_fx->old_pitch_buf_fx[nbsubfr], &st_fx->old_pitch_buf_fx[0], nbsubfr ); + Copy32( &st_fx->old_pitch_buf_fx[nbsubfr], &st_fx->old_pitch_buf_fx[0], nbsubfr ); /* 15Q16 */ set32_fx( &st_fx->old_pitch_buf_fx[nbsubfr], ( L_SUBFR << 16 ), nbsubfr ); - Copy( &st_fx->mem_pitch_gain[2], &st_fx->mem_pitch_gain[nbsubfr + 2], nbsubfr ); + Copy( &st_fx->mem_pitch_gain[2], &st_fx->mem_pitch_gain[nbsubfr + 2], nbsubfr ); /* Q14 */ set16_fx( &st_fx->mem_pitch_gain[2], 0, nbsubfr ); } /* Move LB excitation to old_exc memory in case of switch HQ->ACELP */ IF( st_fx->element_mode > EVS_MONO ) { - Copy_Scale_sig( output, tmp_out, st_fx->L_frame, -( *Q_output ) ); - Copy( tmp_out, st_fx->old_exc_fx + sub( L_EXC_MEM_DEC, st_fx->L_frame ), st_fx->L_frame ); + Copy_Scale_sig( output, tmp_out, st_fx->L_frame, negate( *Q_output ) ); /* Q0 */ + Copy( tmp_out, st_fx->old_exc_fx + sub( L_EXC_MEM_DEC, st_fx->L_frame ), st_fx->L_frame ); /* Q0 */ } return; } @@ -1238,7 +1240,7 @@ void HQ_core_dec_init_fx( move16(); move16(); - hHQ_core->last_hq_core_type = -1; + hHQ_core->last_hq_core_type = -1; /* Q0 */ move16(); set16_fx( hHQ_core->old_is_transient, 0, 3 ); @@ -1251,7 +1253,7 @@ void HQ_core_dec_init_fx( move16(); move16(); move16(); - hHQ_core->energy_lt_fx = 2457600; /*Q13*/ + hHQ_core->energy_lt_fx = 2457600; /*300.0f in Q13*/ hHQ_core->hq_generic_seed = RANDOM_INITSEED; set16_fx( hHQ_core->prev_noise_level_fx, 0, 2 ); hHQ_core->prev_hqswb_clas = HQ_NORMAL; @@ -1281,7 +1283,7 @@ void HQ_core_dec_init_fx( move16(); hHQ_core->prev_stab_hfe2 = 0; move16(); - hHQ_core->prev_ni_ratio_fx = 16384; /*Q15*/ + hHQ_core->prev_ni_ratio_fx = 16384; /*0.5 in Q15*/ move16(); set16_fx( hHQ_core->prev_En_sb_fx, 0, NB_SWB_SUBBANDS ); @@ -1309,9 +1311,9 @@ void HQ_core_dec_init_fx( set16_fx( hHQ_core->env_stab_state_p_fx, INV_NUM_ENV_STAB_PLC_STATES, NUM_ENV_STAB_PLC_STATES ); hHQ_core->envstabplc_hocnt = 0; move16(); - set16_fx( hHQ_core->mag_chg_1st_fx, 32767, LGW_MAX ); + set16_fx( hHQ_core->mag_chg_1st_fx, 32767 /* 1.0f in Q15 */, LGW_MAX ); set16_fx( hHQ_core->Xavg_fx, 0, LGW_MAX ); - hHQ_core->beta_mute_fx = BETA_MUTE_FAC_INI; + hHQ_core->beta_mute_fx = BETA_MUTE_FAC_INI; /* Q15 */ hHQ_core->last_fec = 0; hHQ_core->ph_ecu_HqVoicing = 0; hHQ_core->oldHqVoicing = 0; @@ -1343,7 +1345,7 @@ void HQ_nbfec_init_fx( { Word16 i, j; - hHQ_nbfec->prev_last_core = -1; + hHQ_nbfec->prev_last_core = -1; /* Q0 */ hHQ_nbfec->diff_energy_fx = 0; hHQ_nbfec->stat_mode_out = 0; hHQ_nbfec->stat_mode_old = 0; diff --git a/lib_dec/hq_env_dec_fx.c b/lib_dec/hq_env_dec_fx.c index 81385aaaa..677221f31 100644 --- a/lib_dec/hq_env_dec_fx.c +++ b/lib_dec/hq_env_dec_fx.c @@ -14,15 +14,15 @@ * Decode envelope indices *------------------------------------------------------------------------*/ -Word16 decode_envelope_indices_fx( /* o : Number of bits */ +Word16 decode_envelope_indices_fx( /* o : Number of bits Q0*/ Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word16 start_norm, /* i : starting band index */ - const Word16 num_sfm, /* i : Number of subbands */ - const Word16 numnrmibits, /* i : Bitrate of fall-back coding mode */ - Word16 *difidx, /* o : Diff indices/encoded diff indices */ - const Word16 flag_HQ2 /* i : indicator of HQ2 core */ + const Word16 start_norm, /* i : starting band index Q0*/ + const Word16 num_sfm, /* i : Number of subbands Q0*/ + const Word16 numnrmibits, /* i : Bitrate of fall-back coding mode Q0*/ + Word16 *difidx, /* o : Diff indices/encoded diff indices Q0*/ + const Word16 flag_HQ2 /* i : indicator of HQ2 core Q0*/ , - const Word16 is_transient /* i : indicator of HQ_TRANSIENT */ + const Word16 is_transient /* i : indicator of HQ_TRANSIENT Q0*/ ) { Word16 hcode_l; @@ -34,14 +34,14 @@ Word16 decode_envelope_indices_fx( /* o : Number of b test(); IF( EQ_16( flag_HQ2, LOW_RATE_HQ_CORE ) || EQ_16( flag_HQ2, LOW_RATE_HQ_CORE_TRAN ) ) { - LCmode = (Word16) get_next_indice_fx( st_fx, BITS_DE_HMODE ); - difidx[start_norm] = (Word16) get_next_indice_fx( st_fx, BITS_DE_FCOMP ); + LCmode = (Word16) get_next_indice_fx( st_fx, BITS_DE_HMODE ); /* Q0 */ + difidx[start_norm] = (Word16) get_next_indice_fx( st_fx, BITS_DE_FCOMP ); /* Q0 */ move16(); } ELSE { - LCmode = (Word16) get_next_indice_fx( st_fx, 2 ); - difidx[start_norm] = (Word16) get_next_indice_fx( st_fx, NORM0_BITS ); + LCmode = (Word16) get_next_indice_fx( st_fx, 2 ); /* Q0 */ + difidx[start_norm] = (Word16) get_next_indice_fx( st_fx, NORM0_BITS ); /* Q0 */ move16(); } @@ -53,10 +53,10 @@ Word16 decode_envelope_indices_fx( /* o : Number of b IF( EQ_16( LCmode, 1 ) ) { hdecnrm_tran_fx( st_fx, num_sfm, &difidx[start_norm + 1] ); - j = add( start_norm, num_sfm ); + j = add( start_norm, num_sfm ); /* Q0 */ FOR( i = start_norm + 1; i < j; i++ ) { - hcode_l = add( hcode_l, huffsizn_tran[difidx[i]] ); + hcode_l = add( hcode_l, huffsizn_tran[difidx[i]] ); /* Q0 */ } } ELSE @@ -74,68 +74,68 @@ Word16 decode_envelope_indices_fx( /* o : Number of b } ELSE IF( EQ_16( LCmode, 1 ) ) { - startNormPlus1 = add( start_norm, 1 ); + startNormPlus1 = add( start_norm, 1 ); /* Q0 */ hdecnrm_resize_fx( st_fx, num_sfm, &difidx[startNormPlus1] ); - pDifidx = &difidx[startNormPlus1]; + pDifidx = &difidx[startNormPlus1]; /* Q0 */ move16(); - numSfmMinus1 = sub( num_sfm, 1 ); + numSfmMinus1 = sub( num_sfm, 1 ); /* Q0 */ FOR( i = 0; i < numSfmMinus1; i++ ) { j = *pDifidx++; move16(); - hcode_l = add( hcode_l, resize_huffsizn[j] ); + hcode_l = add( hcode_l, resize_huffsizn[j] ); /* Q0 */ } - pDifidx1 = &difidx[startNormPlus1]; + pDifidx1 = &difidx[startNormPlus1]; /* Q0 */ move16(); - numSfmMinus2 = sub( num_sfm, 2 ); + numSfmMinus2 = sub( num_sfm, 2 ); /* Q0 */ FOR( i = 0; i < numSfmMinus2; i++ ) { - pDifidx = pDifidx1++; + pDifidx = pDifidx1++; /* Q0 */ move16(); IF( GT_16( *pDifidx, 17 ) ) { - offset = sub( *pDifidx, 17 ); - offset = s_min( offset, 3 ); - *pDifidx1 = sub( *pDifidx1, offset ); + offset = sub( *pDifidx, 17 ); /* Q0 */ + offset = s_min( offset, 3 ); /* Q0 */ + *pDifidx1 = sub( *pDifidx1, offset ); /* Q0 */ move16(); } ELSE IF( LT_16( *pDifidx, 13 ) ) { - offset = sub( *pDifidx, 13 ); - offset = s_max( offset, -3 ); - *pDifidx1 = sub( *pDifidx1, offset ); + offset = sub( *pDifidx, 13 ); /* Q0 */ + offset = s_max( offset, -3 ); /* Q0 */ + *pDifidx1 = sub( *pDifidx1, offset ); /* Q0 */ move16(); } } } ELSE IF( EQ_16( LCmode, 2 ) ) { - startNormPlus1 = add( start_norm, 1 ); + startNormPlus1 = add( start_norm, 1 ); /* Q0 */ hdecnrm_fx( st_fx, num_sfm, &difidx[start_norm + 1] ); - pDifidx = &difidx[startNormPlus1]; + pDifidx = &difidx[startNormPlus1]; /* Q0 */ move16(); - numSfmMinus1 = sub( num_sfm, 1 ); + numSfmMinus1 = sub( num_sfm, 1 ); /* Q0 */ FOR( i = 0; i < numSfmMinus1; i++ ) { - j = *pDifidx++; + j = *pDifidx++; /* Q0 */ move16(); - hcode_l = add( hcode_l, huffsizn[j] ); + hcode_l = add( hcode_l, huffsizn[j] ); /* Q0 */ } } ELSE { - startNormPlus1 = add( start_norm, 1 ); - numSfmMinus1 = sub( num_sfm, 1 ); - pDifidx = &difidx[startNormPlus1]; + startNormPlus1 = add( start_norm, 1 ); /* Q0 */ + numSfmMinus1 = sub( num_sfm, 1 ); /* Q0 */ + pDifidx = &difidx[startNormPlus1]; /* Q0 */ FOR( i = 0; i < numSfmMinus1; i++ ) { - *pDifidx++ = (Word16) get_next_indice_fx( st_fx, NORMI_BITS ); + *pDifidx++ = (Word16) get_next_indice_fx( st_fx, NORMI_BITS ); /* Q0 */ move16(); } - hcode_l = numnrmibits; + hcode_l = numnrmibits; /* Q0 */ move16(); } } @@ -152,12 +152,12 @@ Word16 decode_envelope_indices_fx( /* o : Number of b *------------------------------------------------------------------------*/ void dequantize_norms_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word16 start_norm, /* i : First SDE encoded norm */ - const Word16 num_sfm, /* i : Number of norms */ - const Word16 is_transient, /* i : Transient flag */ - Word16 *ynrm, /* o : Decoded norm indices */ - Word16 *normqlg2 /* o : Log2 of decoded norms */ + Decoder_State *st_fx, /* i/o: decoder state structure */ + const Word16 start_norm, /* i : First SDE encoded norm Q0*/ + const Word16 num_sfm, /* i : Number of norms Q0*/ + const Word16 is_transient, /* i : Transient flag Q0*/ + Word16 *ynrm, /* o : Decoded norm indices Q0*/ + Word16 *normqlg2 /* o : Log2 of decoded norms Q0*/ ) { Word16 i, j; @@ -165,28 +165,28 @@ void dequantize_norms_fx( Word16 *pYnrm, *pNormqlg2; /* First sub-frame */ - i = ynrm[start_norm]; + i = ynrm[start_norm]; /* Q0 */ move16(); - normqlg2[start_norm] = dicnlg2[i]; + normqlg2[start_norm] = dicnlg2[i]; /* Q0 */ move16(); /* Other sub-frames */ IF( is_transient ) { /* Recover quantization indices and quantized norms */ - idxbuf[0] = ynrm[0]; + idxbuf[0] = ynrm[0]; /* Q0 */ move16(); FOR( i = 1; i < num_sfm; i++ ) { - idxbuf[i] = sub( add( ynrm[i], idxbuf[i - 1] ), 15 ); + idxbuf[i] = sub( add( ynrm[i], idxbuf[i - 1] ), 15 ); /* Q0 */ move16(); /* safety check in case of bit errors */ test(); IF( idxbuf[i] < 0 || GT_16( idxbuf[i], 39 ) ) { - idxbuf[i] = 39; + idxbuf[i] = 39; /* Q0 */ move16(); - st_fx->BER_detect = 1; + st_fx->BER_detect = 1; /* Q0 */ move16(); } } @@ -195,26 +195,26 @@ void dequantize_norms_fx( } ELSE { - pYnrm = &ynrm[start_norm]; + pYnrm = &ynrm[start_norm]; /* Q0 */ move16(); - pNormqlg2 = &normqlg2[start_norm + 1]; + pNormqlg2 = &normqlg2[start_norm + 1]; /* Q0 */ move16(); FOR( i = 1; i < num_sfm; i++ ) { - j = sub( *pYnrm++, 15 ); + j = sub( *pYnrm++, 15 ); /* Q0 */ move16(); - *pYnrm = add( *pYnrm, j ); + *pYnrm = add( *pYnrm, j ); /* Q0 */ move16(); /* safety check in case of bit errors */ test(); IF( *pYnrm < 0 || GT_16( *pYnrm, 39 ) ) { - *pYnrm = 39; + *pYnrm = 39; /* Q0 */ move16(); - st_fx->BER_detect = 1; + st_fx->BER_detect = 1; /* Q0 */ move16(); } - *pNormqlg2++ = dicnlg2[*pYnrm]; + *pNormqlg2++ = dicnlg2[*pYnrm]; /* Q0 */ move16(); } } diff --git a/lib_dec/hq_hr_dec_fx.c b/lib_dec/hq_hr_dec_fx.c index 93b94a5c8..556006121 100644 --- a/lib_dec/hq_hr_dec_fx.c +++ b/lib_dec/hq_hr_dec_fx.c @@ -18,10 +18,10 @@ #ifdef IVAS_FLOAT_FIXED void ivas_hq_pred_hb_bws_fx( Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word16 *ynrm, /* i : norm quantization index vector */ - const Word16 length, /* i : frame length */ - const Word16 hqswb_clas, /* i : HQ SWB class */ - const Word16 *SWB_fenv /* i : SWB frequency envelopes Q1 */ + const Word16 *ynrm, /* i : norm quantization index vector Q0*/ + const Word16 length, /* i : frame length Q0*/ + const Word16 hqswb_clas, /* i : HQ SWB class Q0*/ + const Word16 *SWB_fenv /* i : SWB frequency envelopes Q1*/ ) { Word16 i; @@ -41,7 +41,7 @@ void ivas_hq_pred_hb_bws_fx( { L_tmp = L_add( L_tmp, dicn_fx[ynrm[i]] ); /*Q14*/ } - L_tmp = L_min( 8191, L_shr( L_tmp, 13 ) ); + L_tmp = L_min( 8191, L_shr( L_tmp, 13 ) ); /* Q1 */ st_fx->prev_ener_shb_fx = extract_l( L_tmp ); /*Q1*/ st_fx->prev_ener_shb_fx = mult( st_fx->prev_ener_shb_fx, 5461 ); /*Q1*/ move16(); @@ -71,11 +71,11 @@ void ivas_hq_pred_hb_bws_fx( } void hq_pred_hb_bws_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word16 *ynrm, /* i : norm quantization index vector */ - const Word16 length, /* i : frame length */ - const Word16 hqswb_clas, /* i : HQ SWB class */ - const Word16 *SWB_fenv /* i : SWB frequency envelopes Q1 */ + Decoder_State *st_fx, /* i/o: decoder state structure */ + const Word16 *ynrm, /* i : norm quantization index vector Q0*/ + const Word16 length, /* i : frame length Q0*/ + const Word16 hqswb_clas, /* i : HQ SWB class Q0*/ + const Word16 *SWB_fenv /* i : SWB frequency envelopes Q1*/ ) { Word16 i; @@ -99,7 +99,7 @@ void hq_pred_hb_bws_fx( L_tmp = L_add( L_tmp, dicn_fx[ynrm[i]] ); /*Q14*/ #endif } - L_tmp = L_min( 8191, L_shr( L_tmp, 13 ) ); + L_tmp = L_min( 8191, L_shr( L_tmp, 13 ) ); /* Q1 */ st_fx->prev_ener_shb_fx = extract_l( L_tmp ); /*Q1*/ st_fx->prev_ener_shb_fx = mult( st_fx->prev_ener_shb_fx, 5461 ); /*Q1*/ move16(); @@ -153,7 +153,7 @@ void ivas_hq_hr_dec_fx( Word16 *is_transient, /* o : transient flag Q0 */ Word16 *hqswb_clas, /* o : HQ SWB class Q0 */ Word16 *SWB_fenv, /* o : SWB frequency envelopes Q1 */ - const Word16 core_switching_flag /* i : Core switching flag */ + const Word16 core_switching_flag /* i : Core switching flag Q0 */ ) { Word16 nb_sfm; @@ -211,8 +211,8 @@ void ivas_hq_hr_dec_fx( * Decode classification *------------------------------------------------------------------*/ - bits = ivas_hq_classifier_dec_fx( st_fx, st_fx->core_brate, length, is_transient, hqswb_clas ); - bits_left = sub( num_bits, bits ); + bits = ivas_hq_classifier_dec_fx( st_fx, st_fx->core_brate, length, is_transient, hqswb_clas ); /* Q0 */ + bits_left = sub( num_bits, bits ); /* Q0 */ /*------------------------------------------------------------------* * set quantization parameters @@ -231,15 +231,15 @@ void ivas_hq_hr_dec_fx( test(); IF( !*is_transient && NE_16( *hqswb_clas, HQ_HVQ ) && !( EQ_16( length, L_FRAME16k ) && LE_32( st_fx->core_brate, HQ_32k ) ) ) { - nf_idx = get_next_indice_fx( st_fx, 2 ); + nf_idx = get_next_indice_fx( st_fx, 2 ); /* Q0 */ } /*------------------------------------------------------------------* * Decode envelope *------------------------------------------------------------------*/ - hcode_l = decode_envelope_indices_fx( st_fx, start_norm, num_env_bands, numnrmibits, ynrm, NORMAL_HQ_CORE, *is_transient ); - bits_left = sub( bits_left, add( hcode_l, NORM0_BITS + FLAGS_BITS ) ); + hcode_l = decode_envelope_indices_fx( st_fx, start_norm, num_env_bands, numnrmibits, ynrm, NORMAL_HQ_CORE, *is_transient ); /* Q0 */ + bits_left = sub( bits_left, add( hcode_l, NORM0_BITS + FLAGS_BITS ) ); /* Q0 */ dequantize_norms_fx( st_fx, start_norm, num_env_bands, *is_transient, ynrm, normqlg2 ); @@ -249,7 +249,7 @@ void ivas_hq_hr_dec_fx( hq_generic_exc_clas = swb_bwe_gain_deq_fx( st_fx, HQ_CORE, NULL, SWB_fenv, st_fx->core_brate >= HQ_32k, *hqswb_clas ); /* Use (st->core_brate >= HQ_32k) to be consistent with hq_configure */ IF( EQ_16( hq_generic_exc_clas, HQ_GENERIC_SP_EXC ) ) { - bits_left = add( bits_left, 1 ); /* conditional 1 bit saving for representing HQ GENERIC excitation class */ + bits_left = add( bits_left, 1 ); /* conditional 1 bit saving for representing HQ GENERIC excitation class Q0*/ } map_hq_generic_fenv_norm_fx( *hqswb_clas, SWB_fenv, ynrm, normqlg2, num_env_bands, nb_sfm, hq_generic_offset ); } @@ -257,8 +257,8 @@ void ivas_hq_hr_dec_fx( env_stab = 0; move16(); - csw_flag1 = s_and( core_switching_flag, (Word16) NE_16( st_fx->element_mode, EVS_MONO ) ); - csw_flag2 = s_and( csw_flag1, (Word16) EQ_16( length, L_SPEC32k_EXT ) ); + csw_flag1 = s_and( core_switching_flag, (Word16) ( st_fx->element_mode != EVS_MONO ) ); /* Q0 */ + csw_flag2 = s_and( csw_flag1, (Word16) EQ_16( length, L_SPEC32k_EXT ) ); /* Q0 */ test(); IF( EQ_16( *hqswb_clas, HQ_HVQ ) ) { @@ -267,7 +267,7 @@ void ivas_hq_hr_dec_fx( } ELSE IF( EQ_16( length, L_FRAME32k ) || csw_flag2 ) { - env_stab = env_stability_fx( ynrm, SFM_N_ENV_STAB, hHQ_core->mem_norm, &hHQ_core->mem_env_delta, csw_flag1 ); + env_stab = env_stability_fx( ynrm, SFM_N_ENV_STAB, hHQ_core->mem_norm, &hHQ_core->mem_env_delta, csw_flag1 ); /* Q15 */ } ELSE { @@ -286,16 +286,16 @@ void ivas_hq_hr_dec_fx( { IF( EQ_16( length, L_FRAME32k ) || csw_flag2 ) { - move16(); /* calculated stability */ - hHQ_core->env_stab_fx = env_stab; + move16(); /* calculated stability */ + hHQ_core->env_stab_fx = env_stab; /* Q15 */ } ELSE { - hHQ_core->env_stab_fx = env_stability_fx( ynrm, SFM_N_ENV_STAB_WB, hHQ_core->mem_norm_hqfec, &hHQ_core->mem_env_delta_hqfec, csw_flag1 ); + hHQ_core->env_stab_fx = env_stability_fx( ynrm, SFM_N_ENV_STAB_WB, hHQ_core->mem_norm_hqfec, &hHQ_core->mem_env_delta_hqfec, csw_flag1 ); /* Q15 */ move16(); } } - hHQ_core->env_stab_plc_fx = env_stab_smo_fx( s_min( hHQ_core->env_stab_fx, sub( 32767, stab_trans_fx[L_STAB_TBL - 1] ) ), hHQ_core->env_stab_state_p_fx, &hHQ_core->envstabplc_hocnt ); + hHQ_core->env_stab_plc_fx = env_stab_smo_fx( s_min( hHQ_core->env_stab_fx, sub( 32767 /* 1.0f in Q15 */, stab_trans_fx[L_STAB_TBL - 1] ) ), hHQ_core->env_stab_state_p_fx, &hHQ_core->envstabplc_hocnt ); /* Q0 */ move16(); /*------------------------------------------------------------------* @@ -309,20 +309,20 @@ void ivas_hq_hr_dec_fx( test(); IF( EQ_16( *hqswb_clas, HQ_GEN_SWB ) && st_fx->bws_cnt1 > 0 && LT_32( st_fx->core_brate, HQ_32k ) ) { - tmp = i_mult( st_fx->bws_cnt1, 1638 ); + tmp = i_mult( st_fx->bws_cnt1, 1638 /* 1/20 in Q15 */ ); move16(); IF( EQ_16( st_fx->L_frame, L_FRAME16k ) ) { FOR( n_band = 0; n_band < 4; n_band++ ) { - SWB_fenv[n_band] = mult_r( SWB_fenv[n_band], tmp ); + SWB_fenv[n_band] = mult_r( SWB_fenv[n_band], tmp ); /* Q1 */ move16(); } } FOR( n_band = 4; n_band < SWB_FENV; n_band++ ) { - SWB_fenv[n_band] = mult_r( SWB_fenv[n_band], tmp ); + SWB_fenv[n_band] = mult_r( SWB_fenv[n_band], tmp ); /* Q1 */ move16(); } } @@ -330,8 +330,8 @@ void ivas_hq_hr_dec_fx( test(); IF( EQ_16( *hqswb_clas, HQ_GEN_SWB ) || EQ_16( *hqswb_clas, HQ_GEN_FB ) ) { - b_delta_env = get_nor_delta_hf_fx( st_fx, ynrm, Rsubband, num_env_bands, nb_sfm, core_sfm ); - sum = sub( sum, b_delta_env ); + b_delta_env = get_nor_delta_hf_fx( st_fx, ynrm, Rsubband, num_env_bands, nb_sfm, core_sfm ); /* Q0 */ + sum = sub( sum, b_delta_env ); /* Q0 */ } /*------------------------------------------------------------------* @@ -350,10 +350,10 @@ void ivas_hq_hr_dec_fx( test(); IF( EQ_16( *hqswb_clas, HQ_HVQ ) || EQ_16( *hqswb_clas, HQ_HARMONIC ) ) { - subband_search_offset = subband_search_offsets_13p2kbps_Har; - wBands[0] = SWB_SB_BW_LEN0_16KBPS_HAR; + subband_search_offset = subband_search_offsets_13p2kbps_Har; /* Q0 */ + wBands[0] = SWB_SB_BW_LEN0_16KBPS_HAR; /* Q0 */ move16(); - wBands[1] = SWB_SB_BW_LEN1_16KBPS_HAR; + wBands[1] = SWB_SB_BW_LEN1_16KBPS_HAR; /* Q0 */ move16(); IF( EQ_16( *hqswb_clas, HQ_HARMONIC ) ) @@ -407,7 +407,7 @@ void ivas_hq_hr_dec_fx( ivas_hq_pred_hb_bws_fx( st_fx, ynrm, length, *hqswb_clas, SWB_fenv ); /* update */ - hHQ_core->prev_hqswb_clas = *hqswb_clas; + hHQ_core->prev_hqswb_clas = *hqswb_clas; /* Q0 */ move16(); return; @@ -422,7 +422,7 @@ void hq_hr_dec_fx( Word16 *is_transient, /* o : transient flag Q0 */ Word16 *hqswb_clas, /* o : HQ SWB class Q0 */ Word16 *SWB_fenv, /* o : SWB frequency envelopes Q1 */ - const Word16 core_switching_flag /* i : Core switching flag */ + const Word16 core_switching_flag /* i : Core switching flag Q0 */ ) { Word16 nb_sfm; @@ -500,25 +500,25 @@ void hq_hr_dec_fx( test(); IF( !*is_transient && NE_16( *hqswb_clas, HQ_HVQ ) && !( EQ_16( length, L_FRAME16k ) && LE_32( st_fx->core_brate, HQ_32k ) ) ) { - nf_idx = get_next_indice( st_fx, 2 ); + nf_idx = get_next_indice( st_fx, 2 ); /* Q0 */ } /*------------------------------------------------------------------* * Decode envelope *------------------------------------------------------------------*/ - hcode_l = decode_envelope_indices_fx( st_fx, start_norm, num_env_bands, numnrmibits, ynrm, NORMAL_HQ_CORE, *is_transient ); - bits_left = sub( bits_left, add( hcode_l, NORM0_BITS + FLAGS_BITS ) ); + hcode_l = decode_envelope_indices_fx( st_fx, start_norm, num_env_bands, numnrmibits, ynrm, NORMAL_HQ_CORE, *is_transient ); /* Q0 */ + bits_left = sub( bits_left, add( hcode_l, NORM0_BITS + FLAGS_BITS ) ); /* Q0 */ dequantize_norms_fx( st_fx, start_norm, num_env_bands, *is_transient, ynrm, normqlg2 ); test(); IF( EQ_16( *hqswb_clas, HQ_GEN_SWB ) || EQ_16( *hqswb_clas, HQ_GEN_FB ) ) { - hq_generic_exc_clas = swb_bwe_gain_deq_fx( st_fx, HQ_CORE, NULL, SWB_fenv, st_fx->core_brate >= HQ_32k, *hqswb_clas ); /* Use (st->core_brate >= HQ_32k) to be consistent with hq_configure */ + hq_generic_exc_clas = swb_bwe_gain_deq_fx( st_fx, HQ_CORE, NULL, SWB_fenv, st_fx->core_brate >= HQ_32k, *hqswb_clas ); /* Use (st->core_brate >= HQ_32k) to be consistent with hq_configure Q0*/ if ( EQ_16( hq_generic_exc_clas, HQ_GENERIC_SP_EXC ) ) { - bits_left = add( bits_left, 1 ); /* conditional 1 bit saving for representing HQ GENERIC excitation class */ + bits_left = add( bits_left, 1 ); /* conditional 1 bit saving for representing HQ GENERIC excitation class Q0*/ } map_hq_generic_fenv_norm_fx( *hqswb_clas, SWB_fenv, ynrm, normqlg2, num_env_bands, nb_sfm, hq_generic_offset ); } @@ -526,8 +526,8 @@ void hq_hr_dec_fx( env_stab = 0; move16(); - csw_flag1 = s_and( core_switching_flag, (Word16) ( st_fx->element_mode != EVS_MONO ) ); - csw_flag2 = s_and( csw_flag1, (Word16) EQ_16( length, L_SPEC32k_EXT ) ); + csw_flag1 = s_and( core_switching_flag, (Word16) ( st_fx->element_mode != EVS_MONO ) ); /* Q0 */ + csw_flag2 = s_and( csw_flag1, (Word16) EQ_16( length, L_SPEC32k_EXT ) ); /* Q0 */ test(); IF( EQ_16( *hqswb_clas, HQ_HVQ ) ) { @@ -536,7 +536,7 @@ void hq_hr_dec_fx( } ELSE IF( EQ_16( length, L_FRAME32k ) || csw_flag2 ) { - env_stab = env_stability_fx( ynrm, SFM_N_ENV_STAB, hHQ_core->mem_norm, &hHQ_core->mem_env_delta, csw_flag1 ); + env_stab = env_stability_fx( ynrm, SFM_N_ENV_STAB, hHQ_core->mem_norm, &hHQ_core->mem_env_delta, csw_flag1 ); /* Q0 */ } ELSE { @@ -556,16 +556,16 @@ void hq_hr_dec_fx( test(); IF( EQ_16( length, L_FRAME32k ) || csw_flag2 ) { - move16(); /* calculated stability */ - hHQ_core->env_stab_fx = env_stab; + move16(); /* calculated stability */ + hHQ_core->env_stab_fx = env_stab; /* Q15 */ } ELSE { - hHQ_core->env_stab_fx = env_stability_fx( ynrm, SFM_N_ENV_STAB_WB, hHQ_core->mem_norm_hqfec, &hHQ_core->mem_env_delta_hqfec, csw_flag1 ); + hHQ_core->env_stab_fx = env_stability_fx( ynrm, SFM_N_ENV_STAB_WB, hHQ_core->mem_norm_hqfec, &hHQ_core->mem_env_delta_hqfec, csw_flag1 ); /* Q15 */ move16(); } } - hHQ_core->env_stab_plc_fx = env_stab_smo_fx( s_min( hHQ_core->env_stab_fx, sub( 32767, stab_trans_fx[L_STAB_TBL - 1] ) ), hHQ_core->env_stab_state_p_fx, &hHQ_core->envstabplc_hocnt ); + hHQ_core->env_stab_plc_fx = env_stab_smo_fx( s_min( hHQ_core->env_stab_fx, sub( 32767, stab_trans_fx[L_STAB_TBL - 1] ) ), hHQ_core->env_stab_state_p_fx, &hHQ_core->envstabplc_hocnt ); /* Q0 */ /*------------------------------------------------------------------* * Bit allocation @@ -578,20 +578,20 @@ void hq_hr_dec_fx( test(); IF( EQ_16( *hqswb_clas, HQ_GEN_SWB ) && st_fx->bws_cnt1 > 0 && LT_32( st_fx->core_brate, HQ_32k ) ) { - tmp = i_mult( st_fx->bws_cnt1, 1638 ); + tmp = i_mult( st_fx->bws_cnt1, 1638 /* 1/20 in Q15 */ ); /* Q15 */ move16(); IF( EQ_16( st_fx->L_frame, L_FRAME16k ) ) { FOR( n_band = 0; n_band < 4; n_band++ ) { - SWB_fenv[n_band] = mult_r( SWB_fenv[n_band], tmp ); + SWB_fenv[n_band] = mult_r( SWB_fenv[n_band], tmp ); /* Q1 */ move16(); } } FOR( n_band = 4; n_band < SWB_FENV; n_band++ ) { - SWB_fenv[n_band] = mult_r( SWB_fenv[n_band], tmp ); + SWB_fenv[n_band] = mult_r( SWB_fenv[n_band], tmp ); /* Q1 */ move16(); } } @@ -599,8 +599,8 @@ void hq_hr_dec_fx( test(); IF( EQ_16( *hqswb_clas, HQ_GEN_SWB ) || EQ_16( *hqswb_clas, HQ_GEN_FB ) ) { - b_delta_env = get_nor_delta_hf_fx( st_fx, ynrm, Rsubband, num_env_bands, nb_sfm, core_sfm ); - sum = sub( sum, b_delta_env ); + b_delta_env = get_nor_delta_hf_fx( st_fx, ynrm, Rsubband, num_env_bands, nb_sfm, core_sfm ); /* Q0 */ + sum = sub( sum, b_delta_env ); /* Q0 */ } /*------------------------------------------------------------------* @@ -619,10 +619,10 @@ void hq_hr_dec_fx( test(); IF( EQ_16( *hqswb_clas, HQ_HVQ ) || EQ_16( *hqswb_clas, HQ_HARMONIC ) ) { - subband_search_offset = subband_search_offsets_13p2kbps_Har; - wBands[0] = SWB_SB_BW_LEN0_16KBPS_HAR; + subband_search_offset = subband_search_offsets_13p2kbps_Har; /* Q0 */ + wBands[0] = SWB_SB_BW_LEN0_16KBPS_HAR; /* Q0 */ move16(); - wBands[1] = SWB_SB_BW_LEN1_16KBPS_HAR; + wBands[1] = SWB_SB_BW_LEN1_16KBPS_HAR; /* Q0 */ move16(); IF( EQ_16( *hqswb_clas, HQ_HARMONIC ) ) @@ -676,7 +676,7 @@ void hq_hr_dec_fx( hq_pred_hb_bws_fx( st_fx, ynrm, length, *hqswb_clas, SWB_fenv ); /* update */ - hHQ_core->prev_hqswb_clas = *hqswb_clas; + hHQ_core->prev_hqswb_clas = *hqswb_clas; /* Q0 */ move16(); return; diff --git a/lib_dec/swb_bwe_dec.c b/lib_dec/swb_bwe_dec.c index a1f18d2da..34bb10fc8 100644 --- a/lib_dec/swb_bwe_dec.c +++ b/lib_dec/swb_bwe_dec.c @@ -218,9 +218,9 @@ static int16_t para_pred_bws( #endif #ifdef IVAS_FLOAT_FIXED static Word16 para_pred_bws_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - Word16 *signal_wb_fx, /* i : wideband frequency signal */ - Word16 *SWB_fenv_fx, /* o : frequency-domain BWE envelope */ + Decoder_State *st_fx, /* i/o: decoder state structure */ + Word16 *signal_wb_fx, /* i : wideband frequency signal Q_syn */ + Word16 *SWB_fenv_fx, /* o : frequency-domain BWE envelope Q1 */ Word16 Q_syn ) { Word16 i, j, k; @@ -242,7 +242,7 @@ static Word16 para_pred_bws_fx( k = 0; move16(); - input_hi_fx = &signal_wb_fx[SHARP_WIDTH]; + input_hi_fx = &signal_wb_fx[SHARP_WIDTH]; /*Q_syn*/ FOR( i = 0; i < 7; i++ ) { peak_fx = 0; @@ -251,9 +251,9 @@ static Word16 para_pred_bws_fx( move16(); FOR( j = 0; j < SHARP_WIDTH; j++ ) { - mag_fx = abs_s( *input_hi_fx ); - peak_fx = s_max( peak_fx, mag_fx ); - mean_fx[i] = L_add( mean_fx[i], L_deposit_l( mag_fx ) ); + mag_fx = abs_s( *input_hi_fx ); /*Q_syn*/ + peak_fx = s_max( peak_fx, mag_fx ); /*Q_syn*/ + mean_fx[i] = L_add( mean_fx[i], L_deposit_l( mag_fx ) ); /*Q_syn*/ move32(); input_hi_fx++; } @@ -275,7 +275,7 @@ static Word16 para_pred_bws_fx( } IF( tmp > 0 ) { - L_tmp = L_msu0( Mult_32_16( L_shl( mean_fx[i], 10 ), 18432 ), peak_fx, 4544 ); + L_tmp = L_msu0( Mult_32_16( L_shl( mean_fx[i], 10 ) /*Q_syn + 10*/, 18432 /*4.5f Q12*/ ), peak_fx /*Q_syn*/, 4544 /*35.5 (SHARP_WIDTH + 3.5f)Q7*/ ); if ( L_tmp < 0 ) { k = add( k, 1 ); @@ -287,11 +287,11 @@ static Word16 para_pred_bws_fx( avrg2_fx = L_deposit_l( 0 ); FOR( i = 1; i < 4; i++ ) { - avrg1_fx = L_add( avrg1_fx, mean_fx[i] ); - avrg2_fx = L_add( avrg2_fx, mean_fx[i + 3] ); + avrg1_fx = L_add( avrg1_fx, mean_fx[i] ); /*Q_syn*/ + avrg2_fx = L_add( avrg2_fx, mean_fx[i + 3] ); /*Q_syn*/ } - avrg1_fx = Mult_32_16( avrg1_fx, 10923 ); - avrg2_fx = Mult_32_16( avrg2_fx, 10923 ); /* 1/3 -> Q15 -> 10923 */ + avrg1_fx = Mult_32_16( avrg1_fx, 10923 /* 1/3 -> Q15 -> 10923 */ ); /*Q_syn + Q15 - 15*/ + avrg2_fx = Mult_32_16( avrg2_fx, 10923 /* 1/3 -> Q15 -> 10923 */ ); /*Q_syn + Q15 - 15*/ min_fx = L_add( 2147483647, 0 ); /*2^31 */ peak_32_fx = L_deposit_l( 0 ); @@ -303,7 +303,7 @@ static Word16 para_pred_bws_fx( IF( LT_16( exp, 16 ) ) { tmp_den = extract_l( L_shr( mean_fx[i], sub( 16, exp ) ) ); /*Qsyn - 16 + exp */ - tmp_num = extract_l( L_shr( avrg2_fx, sub( 15, exp ) ) ); /*//Qsyn - 16 + exp */ + tmp_num = extract_l( L_shr( avrg2_fx, sub( 15, exp ) ) ); /*Qsyn - 16 + exp */ } ELSE { @@ -315,16 +315,16 @@ static Word16 para_pred_bws_fx( tmp = i_mult( tmp_num, tmp_den ); /*Q15 */ - mean_fx[i] = Mult_32_16( mean_fx[i], tmp ); + mean_fx[i] = Mult_32_16( mean_fx[i], tmp ); /*Q_syn + Q15 - 15*/ move32(); } min_fx = L_min( min_fx, mean_fx[i] ); peak_32_fx = L_max( peak_32_fx, mean_fx[i] ); } - IF( GT_16( st_fx->tilt_wb_fx, 16384 ) ) + IF( GT_16( st_fx->tilt_wb_fx, 16384 /*8 in Q11*/ ) ) { - IF( GT_16( st_fx->tilt_wb_fx, 30720 ) ) + IF( GT_16( st_fx->tilt_wb_fx, 30720 /*15.0f in Q11*/ ) ) { min_fx = peak_32_fx; move32(); @@ -410,21 +410,21 @@ static Word16 para_pred_bws_fx( FOR( i = 0; i < SWB_FENV; i++ ) { test(); - IF( NE_16( st_fx->prev_coder_type, coder_type ) && GT_16( mult_r( SWB_fenv_fx[i], 16384 ), st_fx->prev_SWB_fenv_fx[i] ) ) + IF( NE_16( st_fx->prev_coder_type, coder_type ) && GT_16( mult_r( SWB_fenv_fx[i], 16384 /*1/2.0f in Q15*/ ), st_fx->prev_SWB_fenv_fx[i] ) ) { - SWB_fenv_fx[i] = round_fx( L_mac( L_mult( SWB_fenv_fx[i], 3277 ), st_fx->prev_SWB_fenv_fx[i], 29491 ) ); + SWB_fenv_fx[i] = round_fx( L_mac( L_mult( SWB_fenv_fx[i], 3277 /*0.1f in Q15*/ ), st_fx->prev_SWB_fenv_fx[i], 29491 /*0.9f in Q15*/ ) ); move16(); } ELSE { - SWB_fenv_fx[i] = round_fx( L_mac( L_mult( SWB_fenv_fx[i], st_fx->attenu_fx ), st_fx->prev_SWB_fenv_fx[i], sub( 32767, st_fx->attenu_fx ) ) ); + SWB_fenv_fx[i] = round_fx( L_mac( L_mult( SWB_fenv_fx[i], st_fx->attenu_fx ), st_fx->prev_SWB_fenv_fx[i], sub( 32767 /*1.0f in Q15*/, st_fx->attenu_fx ) ) ); move16(); } } - IF( LT_16( st_fx->attenu_fx, 29491 ) ) + IF( LT_16( st_fx->attenu_fx, 29491 /*0.9f in Q15*/ ) ) { - st_fx->attenu_fx = add( st_fx->attenu_fx, 1638 ); + st_fx->attenu_fx = add( st_fx->attenu_fx, 1638 /*0.05f in Q15*/ ); move16(); } } @@ -439,7 +439,7 @@ static Word16 para_pred_bws_fx( { FOR( i = 0; i < SWB_FENV; i++ ) { - if ( GT_16( mult_r( SWB_fenv_fx[i], 16384 ), st_fx->prev_SWB_fenv_fx[i] ) ) + if ( GT_16( mult_r( SWB_fenv_fx[i], 16384 /*0.5f in Q15*/ ), st_fx->prev_SWB_fenv_fx[i] ) ) { SWB_fenv_fx[i] = st_fx->prev_SWB_fenv_fx[i]; move16(); @@ -449,10 +449,10 @@ static Word16 para_pred_bws_fx( FOR( i = 0; i < SWB_FENV; i++ ) { - SWB_fenv_fx[i] = round_fx( L_mac( L_mult( SWB_fenv_fx[i], 29491 ), st_fx->prev_SWB_fenv_fx[i], 3277 ) ); + SWB_fenv_fx[i] = round_fx( L_mac( L_mult( SWB_fenv_fx[i], 29491 /*0.9f in Q15*/ ), st_fx->prev_SWB_fenv_fx[i], 3277 /*0.1f in Q15*/ ) ); move16(); } - st_fx->attenu_fx = 3277; + st_fx->attenu_fx = 3277; /*Q15*/ move16(); } @@ -1031,12 +1031,12 @@ void swb_bwe_dec_flt( #ifdef IVAS_FLOAT_FIXED Word16 swb_bwe_dec_fx32( - Decoder_State *st_fx, /* i/o: decoder state structure */ - Word32 output_fx[], /* i : synthesis @internal Fs Q11 */ - Word32 *synth_fx, /* i : ACELP core synthesis/final synthesis Q11 */ - Word32 *hb_synth_fx, /* o : SHB synthesis/final synthesis */ - Word16 use_cldfb_for_dft, /* i : flag to use of CLDFB for DFT Stereo */ - Word16 output_frame /* i : frame length */ + Decoder_State *st_fx, /* i/o: decoder state structure */ + Word32 output_fx[], /* i : synthesis @internal Fs : Q11 */ + Word32 *synth_fx, /* i : ACELP core synthesis/final synthesis : Q11 */ + Word32 *hb_synth_fx, /* o : SHB synthesis/final synthesis : Q_syn_hb */ + Word16 use_cldfb_for_dft, /* i : flag to use of CLDFB for DFT Stereo */ + Word16 output_frame /* i : frame length */ ) { Word16 L; @@ -1285,7 +1285,7 @@ Word16 swb_bwe_dec_fx32( { FOR( i = 0; i < SWB_TENV; i++ ) { - SWB_tenv_tmp_fx[i] = L_mult0( SWB_tenv_fx[i], 26214 ); + SWB_tenv_tmp_fx[i] = L_mult0( SWB_tenv_fx[i] /*Q0*/, 26214 /*0.8f Q15*/ ); // Q15 move32(); } @@ -1351,7 +1351,7 @@ Word16 swb_bwe_dec_fx32( FOR( i = 0; i < output_frame; i++ ) { - hb_synth_fx[i] = L_deposit_l( hb_synth_fx16[i] ); + hb_synth_fx[i] = L_deposit_l( hb_synth_fx16[i] ); // Q_syn_hb move32(); } @@ -1400,7 +1400,7 @@ void fd_bwe_dec_init_fx( ) { set16_fx( hBWE_FD->L_old_wtda_swb_fx, 0, L_FRAME48k ); - set16_fx( hBWE_FD->old_syn_12k8_16k_fx, 0, NS2SA( 16000, DELAY_FD_BWE_ENC_NS ) ); + set16_fx( hBWE_FD->old_syn_12k8_16k_fx, 0, NS2SA_FX2( 16000, DELAY_FD_BWE_ENC_NS ) ); hBWE_FD->prev_mode = NORMAL; move16(); hBWE_FD->prev_Energy_fx = 0; @@ -1420,7 +1420,6 @@ void fd_bwe_dec_init_fx( move16(); hBWE_FD->prev_Energy_wb_fx = 0; move32(); - hBWE_FD->mem_deemph_old_syn_fx = 0; move16(); diff --git a/lib_dec/swb_bwe_dec_fx.c b/lib_dec/swb_bwe_dec_fx.c index 765458a90..6e9fd80dc 100644 --- a/lib_dec/swb_bwe_dec_fx.c +++ b/lib_dec/swb_bwe_dec_fx.c @@ -21,9 +21,9 @@ * predict SWB parameters for bandwidth switching *-------------------------------------------------------------------*/ static Word16 para_pred_bws_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - Word16 *signal_wb_fx, /* i : wideband frequency signal */ - Word16 *SWB_fenv_fx, /* o : frequency-domain BWE envelope */ + Decoder_State *st_fx, /* i/o: decoder state structure */ + Word16 *signal_wb_fx, /* i : wideband frequency signal Q_syn*/ + Word16 *SWB_fenv_fx, /* o : frequency-domain BWE envelope Q1 */ Word16 Q_syn ) { Word16 i, j, k; @@ -45,7 +45,7 @@ static Word16 para_pred_bws_fx( k = 0; move16(); - input_hi_fx = &signal_wb_fx[SHARP_WIDTH]; + input_hi_fx = &signal_wb_fx[SHARP_WIDTH]; /*Q_syn*/ FOR( i = 0; i < 7; i++ ) { peak_fx = 0; @@ -54,13 +54,13 @@ static Word16 para_pred_bws_fx( move16(); FOR( j = 0; j < SHARP_WIDTH; j++ ) { - mag_fx = abs_s( *input_hi_fx ); - peak_fx = s_max( peak_fx, mag_fx ); + mag_fx = abs_s( *input_hi_fx ); /*Q_syn*/ + peak_fx = s_max( peak_fx, mag_fx ); /*Q_syn*/ /*IF (sub(mag_fx, peak_fx) > 0) */ /*{ */ /* peak_fx = mag_fx; */ /*} */ - mean_fx[i] = L_add( mean_fx[i], L_deposit_l( mag_fx ) ); + mean_fx[i] = L_add( mean_fx[i], L_deposit_l( mag_fx ) ); /*Q_syn*/ move32(); input_hi_fx++; } @@ -82,7 +82,7 @@ static Word16 para_pred_bws_fx( } IF( tmp > 0 ) { - L_tmp = L_msu0( Mult_32_16( L_shl( mean_fx[i], 10 ), 18432 ), peak_fx, 4544 ); + L_tmp = L_msu0( Mult_32_16( L_shl( mean_fx[i], 10 ) /*Q_syn + 10*/, 18432 /*4.5f Q12*/ ), peak_fx /*Q_syn*/, 4544 /*35.5 (SHARP_WIDTH + 3.5f)Q7*/ ); if ( L_tmp < 0 ) { k = add( k, 1 ); @@ -94,11 +94,11 @@ static Word16 para_pred_bws_fx( avrg2_fx = L_deposit_l( 0 ); FOR( i = 1; i < 4; i++ ) { - avrg1_fx = L_add( avrg1_fx, mean_fx[i] ); - avrg2_fx = L_add( avrg2_fx, mean_fx[i + 3] ); + avrg1_fx = L_add( avrg1_fx, mean_fx[i] ); /*Q_syn*/ + avrg2_fx = L_add( avrg2_fx, mean_fx[i + 3] ); /*Q_syn*/ } - avrg1_fx = Mult_32_16( avrg1_fx, 10923 ); - avrg2_fx = Mult_32_16( avrg2_fx, 10923 ); /* 1/3 -> Q15 -> 10923 */ + avrg1_fx = Mult_32_16( avrg1_fx, 10923 /* 1/3 -> Q15 -> 10923 */ ); /*Q_syn + Q15 - 15*/ + avrg2_fx = Mult_32_16( avrg2_fx, 10923 /* 1/3 -> Q15 -> 10923 */ ); /*Q_syn + Q15 - 15*/ min_fx = L_add( 2147483647, 0 ); /*2^31 */ peak_32_fx = L_deposit_l( 0 ); @@ -122,11 +122,11 @@ static Word16 para_pred_bws_fx( tmp = i_mult( tmp_num, tmp_den ); /*Q15 */ - mean_fx[i] = Mult_32_16( mean_fx[i], tmp ); + mean_fx[i] = Mult_32_16( mean_fx[i], tmp ); // Q_syn + Q15 - 15 move32(); } min_fx = L_min( min_fx, mean_fx[i] ); - peak_32_fx = L_max( peak_32_fx, mean_fx[i] ); + peak_32_fx = L_max( peak_32_fx, mean_fx[i] ); /*Q_syn*/ /*IF(L_sub(mean_fx[i], min_fx) < 0) */ /*{ */ /* min_fx = mean_fx[i]; */ @@ -137,9 +137,9 @@ static Word16 para_pred_bws_fx( /*} */ } - IF( GT_16( st_fx->tilt_wb_fx, 16384 ) ) + IF( GT_16( st_fx->tilt_wb_fx, 16384 /*8 in Q11*/ ) ) { - IF( GT_16( st_fx->tilt_wb_fx, 30720 ) ) + IF( GT_16( st_fx->tilt_wb_fx, 30720 /*15.0f in Q11*/ ) ) { min_fx = peak_32_fx; move32(); @@ -147,7 +147,7 @@ static Word16 para_pred_bws_fx( ELSE { tmp = extract_l( L_shr( L_mult0( st_fx->tilt_wb_fx, 17476 ), 14 ) ); /*Q15 */ - min_fx = Mult_32_16( peak_32_fx, tmp ); + min_fx = Mult_32_16( peak_32_fx, tmp ); /*Q_syn + Q15 - 15*/ } } @@ -272,7 +272,7 @@ static Word16 para_pred_bws_fx( SWB_fenv_fx[i] = round_fx( L_mac( L_mult( SWB_fenv_fx[i], 29491 ), st_fx->prev_SWB_fenv_fx[i], 3277 ) ); move16(); } - st_fx->attenu_fx = 3277; + st_fx->attenu_fx = 3277; /*Q15*/ move16(); } @@ -309,7 +309,8 @@ static Word16 para_pred_bws_fx( *-------------------------------------------------------------------*/ Word16 WB_BWE_gain_deq_fx( Decoder_State *st_fx, /* i/o: decoder state structure */ - Word16 *WB_fenv ) + Word16 *WB_fenv /* o : Q15 */ +) { Word16 mode; Word16 index, index2; @@ -320,25 +321,25 @@ Word16 WB_BWE_gain_deq_fx( mode = add( extract_l( get_next_indice_fx( st_fx, 1 ) ), 2 ); index2 = shl( index, 1 ); - L_tmp = L_shr( F_2_5_fx[index2], 1 ); - L_tmp = L_shl( L_tmp, 6 ); + L_tmp = L_shr( F_2_5_fx[index2] /*Q10*/, 1 ); + L_tmp = L_shl( L_tmp, 6 ); /*Q15*/ frac = L_Extract_lc( L_tmp, &exp ); tmp = extract_l( Pow2( 14, frac ) ); exp = sub( exp, 14 ); - WB_fenv[0] = shl( tmp, add( exp, 3 ) ); + WB_fenv[0] = shl( tmp, add( exp, 3 ) ); // Q15 move16(); - L_tmp = L_shr( F_2_5_fx[index2 + 1], 1 ); - L_tmp = L_shl( L_tmp, 6 ); + L_tmp = L_shr( F_2_5_fx[index2 + 1] /*Q10*/, 1 ); + L_tmp = L_shl( L_tmp, 6 ); /*Q15*/ frac = L_Extract_lc( L_tmp, &exp ); tmp = extract_l( Pow2( 14, frac ) ); exp = sub( exp, 14 ); - WB_fenv[1] = shl( tmp, add( exp, 3 ) ); + WB_fenv[1] = shl( tmp, add( exp, 3 ) ); // Q15 move16(); return ( mode ); @@ -349,16 +350,16 @@ Word16 WB_BWE_gain_deq_fx( * * WB BWE decoder (only for 16kHz signals) *-------------------------------------------------------------------*/ -Word16 ivas_wb_bwe_dec_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word16 output[], /* i : suntehsis @ internal Fs */ - Word16 *synth_fx, /* i/o: ACELP core synthesis/final synthesis */ - Word16 *hb_synth_fx, /* o : SHB synthesis/final synthesis */ - const Word16 use_cldfb_for_dft, /* i : flag to use of CLDFB for DFT Stereo */ - const Word16 output_frame, /* i : frame length */ - Word16 *voice_factors_fx, /* i : voicing factors */ - const Word16 pitch_buf_fx[], /* i : pitch buffer */ - Word16 *Qpost ) +Word16 ivas_wb_bwe_dec_fx( /* o : Q_syn_hb */ + Decoder_State *st_fx, /* i/o: decoder state structure */ + const Word16 output[], /* i : suntehsis @ internal Fs Q_input */ + Word16 *synth_fx, /* i/o: ACELP core synthesis/final synthesis Q0/Qpost */ + Word16 *hb_synth_fx, /* o : SHB synthesis/final synthesis Q_syn_hb */ + const Word16 use_cldfb_for_dft, /* i : flag to use of CLDFB for DFT Stereo */ + const Word16 output_frame, /* i : frame length */ + Word16 *voice_factors_fx, /* i : voicing factors Q15 */ + const Word16 pitch_buf_fx[], /* i : pitch buffer Q6 */ + Word16 *Qpost ) { Word16 mode; Word16 WB_fenv_fx[SWB_FENV]; @@ -449,7 +450,7 @@ Word16 ivas_wb_bwe_dec_fx( { /* de-quantization */ mode = WB_BWE_gain_deq_fx( st_fx, WB_fenv_fx ); - st_fx->last_wb_bwe_ener_fx = extract_l( Mpy_32_16_r( L_add( WB_fenv_fx[0], WB_fenv_fx[1] ), 16384 ) ); + st_fx->last_wb_bwe_ener_fx = extract_l( Mpy_32_16_r( L_add( WB_fenv_fx[0], WB_fenv_fx[1] ), 16384 /*0.5f in Q15*/ ) ); move16(); } ELSE @@ -536,15 +537,15 @@ Word16 wb_bwe_dec_fx( #ifdef ADD_IVAS_BWE const Word16 output[], /* i : suntehsis @ internal Fs */ #endif - Word16 *synth_fx, /* i/o: ACELP core synthesis/final synthesis */ - Word16 *hb_synth_fx, /* o : SHB synthesis/final synthesis */ + Word16 *synth_fx, /* i/o: ACELP core synthesis/final synthesis Q0/Qpost */ + Word16 *hb_synth_fx, /* o : SHB synthesis/final synthesis Q_syn_hb */ #ifdef ADD_IVAS_BWE - const Word16 use_cldfb_for_dft, /* i : flag to use of CLDFB for DFT Stereo */ + const Word16 use_cldfb_for_dft, /* i : flag to use of CLDFB for DFT Stereo */ #endif - const Word16 output_frame, /* i : frame length */ - Word16 *voice_factors_fx, /* i : voicing factors */ - const Word16 pitch_buf_fx[], /* i : pitch buffer */ - Decoder_State *st_fx /* i/o: decoder state structure */ + const Word16 output_frame, /* i : frame length */ + Word16 *voice_factors_fx, /* i : voicing factors Q15 */ + const Word16 pitch_buf_fx[], /* i : pitch buffer Q6 */ + Decoder_State *st_fx /* i/o: decoder state structure */ , Word16 *Qpost ) { @@ -706,12 +707,12 @@ Word16 wb_bwe_dec_fx( * Decoding of SWB parameters *-------------------------------------------------------------------*/ Word16 swb_bwe_gain_deq_fx( /* o : BWE class */ - Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word16 core, /* i : core */ - Word16 *SWB_tenv, /* o : Q0, time-domain BWE envelope */ - Word16 *SWB_fenv, /* o : Q1, frequency-domain BWE envelope */ - const Word16 hr_flag, /* i : high rate flag */ - const Word16 hqswb_clas /* i : HQ BWE class */ + Decoder_State *st_fx, /* i/o: decoder state structure */ + const Word16 core, /* i : core : Q0 */ + Word16 *SWB_tenv, /* o : time-domain BWE envelope : Q0 */ + Word16 *SWB_fenv, /* o : frequency-domain BWE envelope : Q1 */ + const Word16 hr_flag, /* i : high rate flag : Q0 */ + const Word16 hqswb_clas /* i : HQ BWE class : Q0 */ ) { Word16 index, mode, n_band; @@ -759,7 +760,7 @@ Word16 swb_bwe_gain_deq_fx( /* o : BWE class FOR( n_band = 0; n_band < DIM_TR1; n_band++ ) { /*Env_TR_Cdbk1_fx[ indice[0]*DIM_TR1+n_band]*/ - quant_tmp[2 * n_band] = Env_TR_Cdbk1_fx[add( tmp, n_band )]; /*Q8 */ + quant_tmp[2 * n_band] = Env_TR_Cdbk1_fx[tmp + n_band]; /*Q8 */ move16(); } @@ -848,8 +849,8 @@ Word16 swb_bwe_gain_deq_fx( /* o : BWE class move16(); } - Copy( &EnvCdbk11_fx[i_mult2( indice[0], DIM11 )], quant_tmp, DIM11 ); - Copy( &EnvCdbk1st_fx[i_mult2( indice[1], DIM1ST )], quant_tmp2, DIM1ST ); + Copy( &EnvCdbk11_fx[indice[0] * DIM11], quant_tmp, DIM11 ); + Copy( &EnvCdbk1st_fx[indice[1] * DIM1ST], quant_tmp2, DIM1ST ); Copy( &EnvCdbk2nd_fx[indice[2] * DIM2ND], quant_tmp2 + DIM1ST, DIM2ND ); FOR( n_band = 0; n_band < ( DIM11 - 1 ); n_band++ ) @@ -867,13 +868,13 @@ Word16 swb_bwe_gain_deq_fx( /* o : BWE class SWB_fenv[11] = quant_tmp[6]; move16(); - Copy( &EnvCdbk3rd_fx[i_mult( indice[3], DIM3RD )], quant_tmp2, DIM3RD ); - Copy( &EnvCdbk3rd_fx[i_mult( indice[4], DIM3RD )], quant_tmp2 + DIM3RD, DIM3RD ); + Copy( &EnvCdbk3rd_fx[indice[3] * DIM3RD], quant_tmp2, DIM3RD ); + Copy( &EnvCdbk3rd_fx[indice[4] * DIM3RD], quant_tmp2 + DIM3RD, DIM3RD ); FOR( n_band = 0; n_band < 5; n_band++ ) { #ifdef BASOP_NOGLOB - SWB_fenv[add( n_band * 2, 1 )] = add_sat( shr( add_sat( quant_tmp[n_band], quant_tmp[n_band + 1] ), 1 ), quant_tmp2[n_band + 1] ); + SWB_fenv[n_band * 2 + 1] = add_sat( shr( add_sat( quant_tmp[n_band], quant_tmp[n_band + 1] ), 1 ), quant_tmp2[n_band + 1] ); #else SWB_fenv[add( shl( n_band, 1 ), 1 )] = add( shr( add( quant_tmp[n_band], quant_tmp[n_band + 1] ), 1 ), quant_tmp2[n_band + 1] ); #endif @@ -896,7 +897,7 @@ Word16 swb_bwe_gain_deq_fx( /* o : BWE class FOR( n_band = 0; n_band < DIM12 - 1; n_band++ ) { #ifdef BASOP_NOGLOB - SWB_fenv[add( n_band * 2, 1 )] = add_sat( shr( add_sat( quant_tmp[n_band], quant_tmp[n_band + 1] ), 1 ), quant_tmp2[n_band] ); + SWB_fenv[n_band * 2 + 1] = add_sat( shr( add_sat( quant_tmp[n_band], quant_tmp[n_band + 1] ), 1 ), quant_tmp2[n_band] ); #else SWB_fenv[add( shl( n_band, 1 ), 1 )] = add( shr( add( quant_tmp[n_band], quant_tmp[n_band + 1] ), 1 ), quant_tmp2[n_band] ); #endif @@ -929,11 +930,11 @@ Word16 swb_bwe_gain_deq_fx( /* o : BWE class IF( EQ_16( hqswb_clas, HQ_GEN_FB ) ) { - Copy( &EnvCdbkFB_fx[i_mult2( indice[5], DIM_FB )], &SWB_fenv[nenv], DIM_FB ); /*Q7 */ + Copy( &EnvCdbkFB_fx[indice[5] * DIM_FB], &SWB_fenv[nenv], DIM_FB ); /*Q7 */ FOR( n_band = 0; n_band < DIM_FB; n_band++ ) { - tmp = add( SWB_fenv[add( n_band, nenv )], Mean_env_fb_fx[n_band] ); + tmp = add( SWB_fenv[n_band + nenv], Mean_env_fb_fx[n_band] ); L_tmp = L_mult( tmp, 21771 ); /* 0.166096 in Q17 -> Q25 */ L_tmp = L_shr( L_tmp, 9 ); /* From Q25 to Q16 */ frac = L_Extract_lc( L_tmp, &exp ); /* Extract exponent of L_tmp */ @@ -942,7 +943,7 @@ Word16 swb_bwe_gain_deq_fx( /* o : BWE class /* output of Pow2() will be: */ /* 16384 < Pow2() <= 32767 */ exp = sub( exp, 13 ); - SWB_fenv[add( n_band, nenv )] = shl( tmp, add( exp, 1 ) ); + SWB_fenv[n_band + nenv] = shl( tmp, add( exp, 1 ) ); move16(); } } @@ -958,19 +959,19 @@ Word16 swb_bwe_gain_deq_fx( /* o : BWE class * * SWB BWE decoder *-------------------------------------------------------------------*/ -Word16 swb_bwe_dec_fx( +Word16 swb_bwe_dec_fx( /*o :Q_syn_hb*/ #ifdef ADD_IVAS_BWE - const Word16 output[], /* i : suntehsis @ internal Fs */ + const Word16 output[], /* i : suntehsis @ internal Fs */ #endif - Decoder_State *st_fx, /* i/o: decoder state structure */ - Word16 *synth_fx, /* i/o: ACELP core synthesis/final synthesis (might be rescaled inside wtda() ) */ - Word16 *hb_synth_fx, /* o : SHB synthesis/final synthesis */ + Decoder_State *st_fx, /* i/o: decoder state structure */ + Word16 *synth_fx, /* i/o: ACELP core synthesis/final synthesis (might be rescaled inside wtda() ) Q0/Qpost */ + Word16 *hb_synth_fx, /* o : SHB synthesis/final synthesis Q_syn_hb */ #ifdef ADD_IVAS_BWE - const Word16 use_cldfb_for_dft, /* i : flag to use of CLDFB for DFT Stereo */ + const Word16 use_cldfb_for_dft, /* i : flag to use of CLDFB for DFT Stereo */ #endif - const Word16 output_frame /* i : frame length */ - , - Word16 *Qpost ) + const Word16 output_frame /* i : frame length */ + , + Word16 *Qpost ) { Word16 i, l_subfr; Word16 mode; @@ -1280,7 +1281,7 @@ void fd_bwe_dec_init( { hBWE_FD->old_wtda_wb_fx_exp = 0; move16(); - set16_fx( hBWE_FD->old_syn_12k8_16k_fx, 0, NS2SA( 16000, DELAY_FD_BWE_ENC_NS ) ); + set16_fx( hBWE_FD->old_syn_12k8_16k_fx, 0, NS2SA_FX2( 16000, DELAY_FD_BWE_ENC_NS ) ); set16_fx( hBWE_FD->L_old_wtda_swb_fx, 0, L_FRAME48k ); hBWE_FD->old_wtda_swb_fx_exp = 0; move16(); diff --git a/lib_dec/swb_bwe_dec_hr_fx.c b/lib_dec/swb_bwe_dec_hr_fx.c index 51880fe61..8b238e46c 100644 --- a/lib_dec/swb_bwe_dec_hr_fx.c +++ b/lib_dec/swb_bwe_dec_hr_fx.c @@ -26,6 +26,7 @@ two functions would be less efficient (Performance Wise) since the function here doesn't use 'Log2_norm_lc' at all versus gain_dequant_fx() which does. */ +#ifdef IVAS_FLOAT_FIXED static Word16 Gain_Dequant_HR( /* o: decoded gain (Q13) */ Word16 index, /* i: quantization index */ const Word16 min, /* i: value of lower limit (Q13) */ @@ -40,9 +41,9 @@ static Word16 Gain_Dequant_HR( /* o: decoded gain (Q13) L_mini = 0; /* no complexity counted, just to remove warning */ L_fact = 0; /* no complexity counted, just to remove warning */ - move32(); move32(); + IF( EQ_16( min, G_AVQ_MIN_FX ) ) { L_mini = MAKE_PSEUDO_FLT( 26214, 15 ); /* 0.8 in Q15 */ @@ -83,7 +84,7 @@ static Word16 Gain_Dequant_HR( /* o: decoded gain (Q13) /* c_mult = (float) ((levels-1)/(log10(max)-c_min));*/ /* gain = (float)pow( 10.0, (((float)index)/c_mult) + c_min );*/ - L_temp = L_mult0( extract_h( L_fact ), inv_tbl_2n_minus1[bits] ); + L_temp = L_mult0( extract_h( L_fact ), inv_tbl_2n_minus1[bits] ); // Q12 + Qx exp1 = norm_s( index ); index = shl( index, exp1 ); /* inv_tbl has variable Q, with Q0 being at [2]*/ @@ -100,7 +101,7 @@ static Word16 Gain_Dequant_HR( /* o: decoded gain (Q13) exp1 = sub( 30 - 16 - 15, p2_int ); exp1 = add( exp1, extract_l( L_mini ) ); - gain = round_fx( L_temp ); + gain = round_fx( L_temp ); // exp1 L_temp = L_mult( gain, extract_h( L_mini ) ); exp2 = norm_l( L_temp ); @@ -109,7 +110,7 @@ static Word16 Gain_Dequant_HR( /* o: decoded gain (Q13) gain = round_fx( L_temp ); exp1 = add( exp1, exp2 ); - *exp = exp1; + *exp = exp1; // gain_e move16(); return gain; @@ -122,7 +123,7 @@ static Word16 Gain_Dequant_HR( /* o: decoded gain (Q13) *-------------------------------------------------------------------*/ static Word16 TD_Postprocess( /* o : gain in Q15 */ - Word16 hb_synth_fx[], /* i/o: high-band synthesis */ + Word16 hb_synth_fx[], /* i/o: high-band synthesis Q(15 - hb_synth_fx_exp) */ const Word16 hb_synth_fx_exp, /* i : Q of high-band synthesis */ const Word16 input_frame, /* i : frame length */ const Word16 last_extl /* i : last extension layer */ @@ -251,14 +252,14 @@ static Word16 TD_Postprocess( /* o : gain in Q15 * HR SWB BWE decoder *-------------------------------------------------------------------*/ -Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB synthesis */ - Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word16 *syn_12k8_16k_fx, /* i : ACELP core synthesis @16kHz */ - const Word16 exp, /* i : Exponent of core synthesis */ - Word16 *hb_synth_fx, /* o : SHB synthesis */ - const Word16 output_frame, /* i : frame length */ - const Word16 unbits, /* i : number of core unused bits */ - const Word16 pitch_buf[] /* i : pitch buffer */ +Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB synthesis */ + Decoder_State *st_fx, /* i/o: decoder state structure */ + const Word16 *syn_12k8_16k_fx, /* i : ACELP core synthesis @16kHz : Q(15 - exp) */ + const Word16 exp, /* i : Exponent of core synthesis */ + Word16 *hb_synth_fx, /* o : SHB synthesis : Q(15 - hb_synth_fx_exp)*/ + const Word16 output_frame, /* i : frame length */ + const Word16 unbits, /* i : number of core unused bits */ + const Word16 pitch_buf[] /* i : pitch buffer : Q6 */ ) { Word16 i, j, k, nBits, nBits_total, nBits_block, Nsv, Nsv2, width_noncoded; @@ -413,9 +414,9 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB temp4 = add( temp4, t_audio_exp ); FOR( i = 0; i < tmpS; i++ ) { - L_temp = L_mult( alpha, hBWE_FD_HR->t_audio_prev_fx[add( i, ind1 )] ); + L_temp = L_mult( alpha, hBWE_FD_HR->t_audio_prev_fx[i + ind1] ); L_temp = L_shr( L_temp, temp4 ); - t_audio32[add( pos, i )] = L_temp; + t_audio32[pos + i] = L_temp; move32(); } ind1 = add( ind1, tmpS ); @@ -590,17 +591,17 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB IF( EQ_16( ind1, 1 ) ) { - en_noncoded = round_fx( L_mult0( en_noncoded, BWE_HR_TRANS_EN_LIMIT1_FX_Q16 ) ); + en_noncoded = round_fx( L_mult0( en_noncoded, BWE_HR_TRANS_EN_LIMIT1_FX_Q16 ) ); // Q9 } IF( EQ_16( ind1, 2 ) ) { - en_noncoded = round_fx( L_mult0( en_noncoded, BWE_HR_TRANS_EN_LIMIT2_FX_Q16 ) ); + en_noncoded = round_fx( L_mult0( en_noncoded, BWE_HR_TRANS_EN_LIMIT2_FX_Q16 ) ); // Q9 } IF( EQ_16( ind1, 3 ) ) { - en_noncoded = round_fx( L_mult0( en_noncoded, BWE_HR_TRANS_EN_LIMIT3_FX_Q16 ) ); + en_noncoded = round_fx( L_mult0( en_noncoded, BWE_HR_TRANS_EN_LIMIT3_FX_Q16 ) ); // Q9 } } @@ -621,7 +622,7 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB move16(); FOR( i = 0; i < i_mult( Nsv, WIDTH_BAND ); i++ ) { - t_audio[add( temp, i )] = shl( x_norm[i], t_audio_exp ); + t_audio[temp + i] = shl( x_norm[i], t_audio_exp ); move16(); } @@ -656,7 +657,7 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB /* reconstruct 14-16(20) kHz spectrum */ FOR( j = 0; j < tmpS; j++ ) { - *ptr32++ = L_shr( t_audio32[add( pos, j )], 1 ); + *ptr32++ = L_shr( t_audio32[pos + j], 1 ); move32(); } @@ -678,8 +679,8 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB temp2 = add( NUM_TRANS_END_FREQ_COEF_EFF, temp ); j = sub( tmpS, width_noncoded ); - ptr16 = &t_audio[add( temp2, j )]; - ptr32 = &t_audio32[add( temp2, j )]; + ptr16 = &t_audio[temp2 + j]; + ptr32 = &t_audio32[temp2 + j]; /* envelope denormalization of 14.4-16(20) kHz spectrum */ FOR( ; j < tmpS; j++ ) { @@ -763,7 +764,7 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB FOR( i = 0; i < j; i++ ) { - t_audio[add( temp, i )] = mult_r( t_audio[add( temp, i )], temp2 ); + t_audio[temp + i] = mult_r( t_audio[temp + i], temp2 ); move16(); } } @@ -787,18 +788,18 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB ind2 = (Word16) get_next_indice_fx( st_fx, NBITS_ENVELOPE_BWE_HR2 ); temp = shl( ind1, 1 ); - en_band[0] = swb_hr_env_code1_fx[temp]; + en_band[0] = swb_hr_env_code1_fx[temp]; // Q9 move16(); - en_band[1] = swb_hr_env_code1_fx[temp + 1]; + en_band[1] = swb_hr_env_code1_fx[temp + 1]; // Q9 move16(); temp = shl( ind2, 1 ); - en_band[2] = swb_hr_env_code2_fx[temp]; + en_band[2] = swb_hr_env_code2_fx[temp]; // Q9 move16(); - en_band[3] = swb_hr_env_code2_fx[temp + 1]; + en_band[3] = swb_hr_env_code2_fx[temp + 1]; // Q9 move16(); /*env = add(add(shr(en_band[0], 2), shr(en_band[1], 2)), add(shr(en_band[2], 2), shr(en_band[3], 2)));*/ - env = mac_r( L_mac( L_mac( L_mult( en_band[0], 8192 ), en_band[1], 8192 ), en_band[2], 8192 ), en_band[3], 8192 ); + env = mac_r( L_mac( L_mac( L_mult( en_band[0] /*Q9*/, 8192 /*0.25 in Q15*/ ) /*Q23*/, en_band[1], 8192 ), en_band[2], 8192 ), en_band[3], 8192 ); // Q23 /*---------------------------------------------------------------------* * choose sub-bands to be dequantized @@ -846,19 +847,19 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB if ( EQ_16( ind1, 1 ) ) { /* en_noncoded = BWE_HR_NONTRANS_EN_LIMIT1*(0.5*min_env) ==> 0.25*min_env */ - en_noncoded = mult_r( min_env, BWE_HR_NONTRANS_EN_LIMIT2_FX_Q15 / 2 ); + en_noncoded = mult_r( min_env, BWE_HR_NONTRANS_EN_LIMIT2_FX_Q15 / 2 ); // Q9 } IF( EQ_16( ind1, 2 ) ) { /* en_noncoded = 2.0*BWE_HR_NONTRANS_EN_LIMIT2*(0.5*min_env) ==> 1.2*min_env */ - en_noncoded = round_fx( L_shl( L_mult( BWE_HR_NONTRANS_EN_LIMIT2_FX_Q14, min_env ), 1 ) ); + en_noncoded = round_fx( L_shl( L_mult( BWE_HR_NONTRANS_EN_LIMIT2_FX_Q14, min_env ), 1 ) ); // Q9 } if ( EQ_16( ind1, 3 ) ) { /* en_noncoded = 2.0*BWE_HR_NONTRANS_EN_LIMIT3*(0.5*min_env) ==> 0.8*min_env */ - en_noncoded = mult_r( BWE_HR_NONTRANS_EN_LIMIT3_FX_Q15, min_env ); + en_noncoded = mult_r( BWE_HR_NONTRANS_EN_LIMIT3_FX_Q15, min_env ); // Q9 } } @@ -954,7 +955,7 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB { L_temp = L_mult( gain2_fx, *ptr16++ ); L_temp = L_shr( L_temp, temp2 ); /* go to Q't_audio' */ - t_audio_tmp[add( temp, j )] = round_fx( L_temp ); + t_audio_tmp[temp + j] = round_fx( L_temp ); } /* 'nq[i] = add(nq[i], nq2[incr])' replaced by 'nq[i] = nq2[incr]' because 'nq[i] == 0' */ nq[i] = nq2[incr]; @@ -978,9 +979,9 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB FOR( j = 0; j < WIDTH_BAND; j++ ) { L_temp = L_mult( gain2_fx, *ptr16++ ); - L_temp = L_msu( L_temp, t_audio_tmp[add( temp, j )], temp3 ); /* go to -Q't_audio' */ - L_temp = L_shr( L_temp, temp2 ); /* go to Q't_audio' */ - t_audio_tmp[add( temp, j )] = round_fx( L_temp ); + L_temp = L_msu( L_temp, t_audio_tmp[temp + j], temp3 ); /* go to -Q't_audio' */ + L_temp = L_shr( L_temp, temp2 ); /* go to Q't_audio' */ + t_audio_tmp[temp + j] = round_fx( L_temp ); } nq[i] = add( nq[i], nq2[incr] ); move16(); @@ -1043,7 +1044,7 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB { nq[j] = nq[i]; move16(); - j = j - 1; + j = sub( j, 1 ); } Copy( nq + ind2, nq + ind1, add( WIDTH_BAND, pos ) ); @@ -1271,7 +1272,8 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB /* Apply global gain */ if ( LE_16( nBits_total, NBITS_THRESH_BWE_HR ) ) { - gain_fx = mult_r( 27853, gain_fx ); /* 0.85 */ + gain_fx = mult_r( 27853, gain_fx ); /* 0.85 in exp_0 */ + // gain_e } ptr32 = &t_audio32[NUM_NONTRANS_START_FREQ_COEF]; @@ -1336,12 +1338,12 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB } ELSE { - st_fx->prev_ener_shb_fx = extract_h( L_shr( L_mult0( gain_fx, env ), 7 ) ); + st_fx->prev_ener_shb_fx = extract_h( L_shr( L_mult0( gain_fx, env ) /*gain_e + (31 - Q23)*/, 7 ) ); /*gain_e + 15*/ move16(); } FOR( i = 0; i < SWB_FENV; i++ ) { - st_fx->prev_SWB_fenv_fx[i] = st_fx->prev_ener_shb_fx; + st_fx->prev_SWB_fenv_fx[i] = st_fx->prev_ener_shb_fx; /*gain_e + 15*/ move16(); } @@ -1512,7 +1514,7 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB } } - hBWE_FD_HR->L_mem_EnergyLT_fx = L_EnergyLT; + hBWE_FD_HR->L_mem_EnergyLT_fx = L_EnergyLT; // exp_temp4 move32(); hBWE_FD_HR->mem_EnergyLT_fx_exp = temp4; move16(); @@ -1558,7 +1560,6 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB * * Initialize HR BWE state structure at the decoder *-------------------------------------------------------------------*/ -#ifdef IVAS_FLOAT_FIXED void hr_bwe_dec_init( HR_BWE_DEC_HANDLE hBWE_FD_HR /* i/o: HR BWE data handle */ ) @@ -1567,32 +1568,14 @@ void hr_bwe_dec_init( set16_fx( hBWE_FD_HR->t_audio_prev_fx_exp, 0, NUM_TIME_SWITCHING_BLOCKS ); /* one exp per switching block */ hBWE_FD_HR->old_is_transient_hr_bwe_fx = 0; move16(); - hBWE_FD_HR->bwe_highrate_seed_fx = 12345; + hBWE_FD_HR->bwe_highrate_seed_fx = 12345; /*0.75f in Q14*/ move16(); - hBWE_FD_HR->L_mem_EnergyLT_fx = L_deposit_h( 16384 ); + hBWE_FD_HR->L_mem_EnergyLT_fx = L_deposit_h( 16384 ); /*1.0f in Q30*/ move32(); hBWE_FD_HR->mem_EnergyLT_fx_exp = 40; move16(); /* set to a high exponent */ return; } -#else -void hr_bwe_dec_init( - HR_BWE_DEC_HANDLE hBWE_FD_HR /* i/o: HR BWE data handle */ -) -{ - set16_fx( hBWE_FD_HR->t_audio_prev_fx, 0, 2 * END_FREQ_BWE_FULL_FB / 50 - NUM_NONTRANS_START_FREQ_COEF ); - set16_fx( hBWE_FD_HR->t_audio_prev_fx_exp, 0, NUM_TIME_SWITCHING_BLOCKS ); /* one exp per switching block */ - hBWE_FD_HR->old_is_transient_hr_bwe_fx = 0; - move16(); - hBWE_FD_HR->bwe_highrate_seed_fx = 12345; - move16(); - - hBWE_FD_HR->L_mem_EnergyLT_fx = L_deposit_h( 16384 ); - hBWE_FD_HR->mem_EnergyLT_fx_exp = 40; - move16(); /* set to a high exponent */ - - return; -} #endif diff --git a/lib_dec/swb_bwe_dec_lr_fx.c b/lib_dec/swb_bwe_dec_lr_fx.c index f2aa60a59..b9bb17621 100644 --- a/lib_dec/swb_bwe_dec_lr_fx.c +++ b/lib_dec/swb_bwe_dec_lr_fx.c @@ -15,12 +15,12 @@ *-------------------------------------------------------------------*/ static void DecodeSWBGenericParameters_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - Word16 *lagIndices_fx, /* o : lowband index for each subband */ - const Word16 nBands_search_fx, /* i : number of subbnads for SSearch */ - const Word16 BANDS_fx, /* i : total number of subbands per frame */ - const Word16 *p2a_flags_fx, /* i : HF tonal flag */ - const Word16 hq_swb_clas_fx /* i : mode of operation HQ_NORMAL or HQ_HARMONIC */ + Decoder_State *st_fx, /* i/o: decoder state structure */ + Word16 *lagIndices_fx, /* o : lowband index for each subband :Q0 */ + const Word16 nBands_search_fx, /* i : number of subbnads for SSearch :Q0 */ + const Word16 BANDS_fx, /* i : total number of subbands per frame :Q0 */ + const Word16 *p2a_flags_fx, /* i : HF tonal flag :Q0 */ + const Word16 hq_swb_clas_fx /* i : mode of operation HQ_NORMAL or HQ_HARMONIC :Q0 */ ) { Word16 sb; @@ -35,16 +35,15 @@ static void DecodeSWBGenericParameters_fx( } ELSE { - IF( p2a_flags_fx[add( sub( BANDS_fx, NB_SWB_SUBBANDS ), sb )] == 0 ) + IF( p2a_flags_fx[BANDS_fx - NB_SWB_SUBBANDS + sb] == 0 ) { lagIndices_fx[sb] = (Word16) get_next_indice_fx( st_fx, bits_lagIndices_modeNormal[sb] ); - move16(); } ELSE { lagIndices_fx[sb] = 0; - move16(); } + move16(); } } @@ -61,32 +60,32 @@ static void DecodeSWBGenericParameters_fx( *-------------------------------------------------------------------*/ static void DecodeSWBSubbands_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - HQ_DEC_HANDLE hHQ_core, /* i/o: HQ decoder handle */ - Word32 *L_spectra, /* i/o: MDCT domain spectrum */ - Word16 QsL, /* i : Q value of spectra */ - const Word16 fLenLow_fx, /* i : lowband length */ - const Word16 fLenHigh_fx, /* i : highband length */ - const Word16 nBands_fx, /* i : number of subbands */ - const Word16 *sbWidth_fx, /* i : subband lengths */ - const Word16 *subband_offsets_fx, /* i : subband offsets */ - Word16 *lagIndices_fx, /* i : lowband index for each subband */ - Word16 *lagGains_fx, /* i : first gain for each subband */ - Word16 *QlagGains, /* i : Q value of lagGains */ - Word16 BANDS_fx, /* i : number subbands per frame */ - Word16 *band_start_fx, /* i : band start of each SB */ - Word16 *band_end_fx, /* i : band end of each SB */ - Word32 *L_band_energy, /* i : band energy of each SB */ - Word16 Qbe, /* i : Q value of band energy */ - Word16 *p2a_flags_fx, /* i : HF tonal indicator */ - const Word16 hqswb_clas_fx, /* i : class information */ - const Word16 har_bands_fx, /* i : number of LF harmonic bands */ - const Word16 *subband_search_offset_fx, /* i : Number of harmonic LF bands */ - Word16 *prev_frm_hfe2, /* i/o: */ - Word16 *prev_stab_hfe2, /* i/o: */ - Word16 band_width_fx[], /* i : subband band widths */ - const Word32 L_spectra_ni[], /* i/o: core coder with sparseness filled */ - Word16 *ni_seed_fx /* i/o: random seed for search buffer NI */ + Decoder_State *st_fx, /* i/o: decoder state structure */ + HQ_DEC_HANDLE hHQ_core, /* i/o: HQ decoder handle */ + Word32 *L_spectra, /* i/o: MDCT domain spectrum : QsL */ + Word16 QsL, /* i : Q value of spectra */ + const Word16 fLenLow_fx, /* i : lowband length : Q0 */ + const Word16 fLenHigh_fx, /* i : highband length : Q0 */ + const Word16 nBands_fx, /* i : number of subbands : Q0 */ + const Word16 *sbWidth_fx, /* i : subband lengths : Q0 */ + const Word16 *subband_offsets_fx, /* i : subband offsets : Q0 */ + Word16 *lagIndices_fx, /* i : lowband index for each subband : Q0 */ + Word16 *lagGains_fx, /* i : first gain for each subband QlagGains*/ + Word16 *QlagGains, /* i : Q value of lagGains */ + Word16 BANDS_fx, /* i : number subbands per frame : Q0 */ + Word16 *band_start_fx, /* i : band start of each SB : Q0 */ + Word16 *band_end_fx, /* i : band end of each SB : Q0 */ + Word32 *L_band_energy, /* i : band energy of each SB : Q0 */ + Word16 Qbe, /* i : Q value of band energy */ + Word16 *p2a_flags_fx, /* i : HF tonal indicator : Q0 */ + const Word16 hqswb_clas_fx, /* i : class information : Q0 */ + const Word16 har_bands_fx, /* i : number of LF harmonic bands : Q0 */ + const Word16 *subband_search_offset_fx, /* i : Number of harmonic LF bands : Q0 */ + Word16 *prev_frm_hfe2, /* i/o: : Q0 */ + Word16 *prev_stab_hfe2, /* i/o: : Q0 */ + Word16 band_width_fx[], /* i : subband band widths : Q0 */ + const Word32 L_spectra_ni[], /* i/o: core coder with sparseness filled : QsL */ + Word16 *ni_seed_fx /* i/o: random seed for search buffer NI : Q0 */ ) { Word16 i, k; @@ -179,7 +178,7 @@ static void DecodeSWBSubbands_fx( { FOR( i = band_start_fx[k]; i <= band_end_fx[k]; i++ ) { - L_spectra[i] = L_xSynth_har[sub( i, fLenLow_fx )]; + L_spectra[i] = L_xSynth_har[i - fLenLow_fx]; move32(); /* QsL */ } } @@ -192,7 +191,7 @@ static void DecodeSWBSubbands_fx( convert_lagIndices_pls2smp_fx( lagIndices_fx, nBands_fx, lagIndices_real_fx, sspectra_fx, sbWidth_fx, fLenLow_fx ); FOR( k = 0; k < nBands_fx; k++ ) { - if ( EQ_16( p2a_flags_fx[add( BANDS_fx - NB_SWB_SUBBANDS, k )], 1 ) ) + if ( EQ_16( p2a_flags_fx[BANDS_fx - NB_SWB_SUBBANDS + k], 1 ) ) { lagIndices_real_fx[k] = 0; move16(); @@ -200,12 +199,12 @@ static void DecodeSWBSubbands_fx( } GetlagGains_fx( sspectra_ni_fx, Qss, - &L_band_energy[sub( BANDS_fx, NB_SWB_SUBBANDS )], Qbe, + &L_band_energy[BANDS_fx - NB_SWB_SUBBANDS], Qbe, nBands_fx, sbWidth_fx, lagIndices_real_fx, fLenLow_fx, lagGains_fx, QlagGains ); FOR( k = 0; k < nBands_fx; k++ ) { - IF( EQ_16( p2a_flags_fx[add( BANDS_fx - NB_SWB_SUBBANDS, k )], 1 ) ) + IF( EQ_16( p2a_flags_fx[BANDS_fx - NB_SWB_SUBBANDS + k], 1 ) ) { lagGains_fx[k] = 0; move16(); @@ -214,7 +213,7 @@ static void DecodeSWBSubbands_fx( } ELSE { - lagGains_fx[k] = mult_r( lagGains_fx[k], 29491 ); /* lagGains[k]*0.9f; */ + lagGains_fx[k] = mult_r( lagGains_fx[k], 29491 /*0.9f in Q15*/ ); /* lagGains[k]*0.9f; */ move16(); } } @@ -223,7 +222,7 @@ static void DecodeSWBSubbands_fx( { L_th_g[k] = 0; move32(); - IF( p2a_flags_fx[add( BANDS_fx - NB_SWB_SUBBANDS, k )] == 0 ) + IF( p2a_flags_fx[BANDS_fx - NB_SWB_SUBBANDS + k] == 0 ) { L_th_g[k] = L_shl( L_mult( lagGains_fx[k], ss_min_fx ), sub( QsL, add( add( QlagGains[k], Qss ), 1 ) ) ); /* QlagGain+Qss -> Qs */ move32(); @@ -244,7 +243,7 @@ static void DecodeSWBSubbands_fx( { FOR( i = band_start_fx[k]; i <= band_end_fx[k]; i++ ) { - L_spectra[i] = L_xSynth_har[sub( i, fLenLow_fx )]; + L_spectra[i] = L_xSynth_har[i - fLenLow_fx]; move32(); /* QsL */ } } @@ -252,7 +251,7 @@ static void DecodeSWBSubbands_fx( { FOR( i = band_start_fx[k]; i <= band_end_fx[k]; i++ ) { - L_spectra[i] = L_spectra_ni[i]; + L_spectra[i] = L_spectra_ni[i]; /* QsL */ move32(); } } @@ -268,26 +267,26 @@ static void DecodeSWBSubbands_fx( * Main decoding routine of SWB BWE for the LR MDCT core *-------------------------------------------------------------------*/ void swb_bwe_dec_lr_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word32 L_m_core[], /* i : lowband synthesis */ - const Word16 QsL, /* i : Q value of m_core */ - Word32 L_m[], /* o : highband synthesis with lowband zeroed */ - const Word32 L_total_brate, /* i : total bitrate for selecting subband pattern */ - Word16 BANDS_fx, /* i : Number subbands/Frame */ - Word16 *band_start_fx, /* i : Band Start of each SB */ - Word16 *band_end_fx, /* i : Band end of each SB */ - Word32 *L_band_energy, /* i : Band energy of each SB : Qbe */ - Word16 Qbe, /* i : Q value of band energy */ - Word16 *p2a_flags_fx, /* i : HF tonal Indicator */ - const Word16 hqswb_clas_fx, /* i : class information */ - Word16 lowlength_fx, /* i : Lowband Length */ - Word16 highlength_fx, /* i : Highband Length */ - const Word16 har_bands_fx, /* i : Number of LF harmonic bands */ - Word16 *prev_frm_hfe2, /* i/o: */ - Word16 *prev_stab_hfe2, /* i/o: */ - Word16 band_width_fx[], /* i : subband bandwidth */ - const Word32 L_y2_ni[], /* i/o: Sparse filled corecoder */ - Word16 *ni_seed_fx /* i/o: random seed */ + Decoder_State *st_fx, /* i/o: decoder state structure */ + const Word32 L_m_core[], /* i : lowband synthesis : QsL */ + const Word16 QsL, /* i : Q value of m_core */ + Word32 L_m[], /* o : highband synthesis with lowband zeroed : QsL */ + const Word32 L_total_brate, /* i : total bitrate for selecting subband pattern */ + Word16 BANDS_fx, /* i : Number subbands/Frame : Q0 */ + Word16 *band_start_fx, /* i : Band Start of each SB : Q0 */ + Word16 *band_end_fx, /* i : Band end of each SB :Q0 */ + Word32 *L_band_energy, /* i : Band energy of each SB : Qbe */ + Word16 Qbe, /* i : Q value of band energy */ + Word16 *p2a_flags_fx, /* i : HF tonal Indicator : Q0 */ + const Word16 hqswb_clas_fx, /* i : class information : Q0 */ + Word16 lowlength_fx, /* i : Lowband Length : Q0 */ + Word16 highlength_fx, /* i : Highband Length : Q0 */ + const Word16 har_bands_fx, /* i : Number of LF harmonic bands : Q0 */ + Word16 *prev_frm_hfe2, /* i/o: : Q0 */ + Word16 *prev_stab_hfe2, /* i/o: : Q0 */ + Word16 band_width_fx[], /* i : subband bandwidth : Q0 */ + const Word32 L_y2_ni[], /* i/o: Sparse filled corecoder */ + Word16 *ni_seed_fx /* i/o: random seed : QsL */ ) { Word16 k; diff --git a/lib_dec/swb_tbe_dec.c b/lib_dec/swb_tbe_dec.c index c5c1bed29..3c788e784 100644 --- a/lib_dec/swb_tbe_dec.c +++ b/lib_dec/swb_tbe_dec.c @@ -466,10 +466,10 @@ void wb_tbe_dec( } #else static void calc_tilt_bwe_fx_loc( - const Word32 *sp_fx, /* i : input signal */ - Word32 *tilt_fx, /* o : signal tilt */ - Word16 *tilt_fx_q, /* o : signal tilt */ - const Word16 N /* i : signal length */ + const Word32 *sp_fx, /* i : input signal : Q11 */ + Word32 *tilt_fx, /* o : signal tilt : tilt_fx_q */ + Word16 *tilt_fx_q, /* o : signal tilt */ + const Word16 N /* i : signal length : Q0 */ ) { Word16 i; @@ -479,14 +479,14 @@ static void calc_tilt_bwe_fx_loc( move64(); FOR( i = 0; i < N; i++ ) { - r0_fx = W_add( r0_fx, W_shr( W_mult_32_32( sp_fx[i], sp_fx[i] ), 1 ) ); + r0_fx = W_add( r0_fx, W_shr( W_mult_32_32( sp_fx[i], sp_fx[i] ), 1 ) ); /*Q11*2 - 1*/ } - r1_fx = W_deposit32_l( abs( L_sub( sp_fx[1], sp_fx[0] ) ) ); + r1_fx = W_deposit32_l( abs( L_sub( sp_fx[1], sp_fx[0] ) ) ); /*Q11*/ FOR( i = 2; i < N; i++ ) { - IF( W_mult_32_32( L_sub( sp_fx[i], sp_fx[i - 1] ), L_sub( sp_fx[i - 1], sp_fx[i - 2] ) ) < 0 ) + IF( W_mult_32_32( L_sub( sp_fx[i], sp_fx[i - 1] ) /*Q11*/, L_sub( sp_fx[i - 1], sp_fx[i - 2] ) /*Q11*/ ) /*Q11 * 2 - 1*/ < 0 ) { - r1_fx = W_add( r1_fx, W_deposit32_l( abs( L_sub( sp_fx[i], sp_fx[i - 1] ) ) ) ); + r1_fx = W_add( r1_fx, W_deposit32_l( abs( L_sub( sp_fx[i], sp_fx[i - 1] ) ) ) ); /*Q11*/ } } Word16 headroom_left_r0 = W_norm( r0_fx ); @@ -494,7 +494,6 @@ static void calc_tilt_bwe_fx_loc( Word16 r0_q = 0, r1_q = 0; move16(); move16(); - // Word16 r0_bits_occ = 0, r1_bits_occ = 0; IF( LT_16( headroom_left_r0, 32 ) ) { r0_fx = W_shr( r0_fx, sub( 32, headroom_left_r0 ) ); @@ -553,7 +552,8 @@ static void calc_tilt_bwe_fx_loc( *-------------------------------------------------------------------*/ static void rescale_genSHB_mem_dec( Decoder_State *st_fx, - Word16 sf ) + Word16 sf /*Q0*/ +) { Word16 i; TD_BWE_DEC_HANDLE hBWE_TD; @@ -598,8 +598,8 @@ static void rescale_genSHB_mem_dec( static void gradientGainShape( Decoder_State *st_fx, - Word16 *GainShape_fx, - Word32 *GainFrame_fx ) + Word16 *GainShape_fx, /*Q15*/ + Word32 *GainFrame_fx /* Q18 */ ) { Word16 i, j, tmp; Word16 GainShapeTemp[NUM_SHB_SUBFR / 4]; @@ -617,7 +617,7 @@ static void gradientGainShape( move16(); /* Q14 */ GainGrad1[j] = sub( shr( st_fx->GainShape_Delay[j + 5], 1 ), shr( st_fx->GainShape_Delay[j + 4], 1 ) ); move16(); /* Q14 */ - GainGradFEC[j + 1] = add( mult_r( GainGrad0[j], 13107 ), mult_r( GainGrad1[j], 19660 ) ); + GainGradFEC[j + 1] = add( mult_r( GainGrad0[j], 13107 /*0.4f in Q15*/ ), mult_r( GainGrad1[j], 19660 /*0.6f in Q15*/ ) ); move16(); /* Q14 */ } @@ -628,14 +628,14 @@ static void gradientGainShape( IF( ( ( GT_16( shr( GainGrad1[2], 1 ), GainGrad1[1] ) ) && ( GT_16( shr( GainGrad1[1], 1 ), GainGrad1[0] ) ) ) || ( ( LT_16( shr( GainGrad1[2], 1 ), GainGrad1[1] ) ) && ( LT_16( shr( GainGrad1[1], 1 ), GainGrad1[0] ) ) ) ) { - GainGradFEC[0] = add( mult_r( GainGrad1[1], 3277 ), mult_r( GainGrad1[2], 29490 ) ); + GainGradFEC[0] = add( mult_r( GainGrad1[1], 3277 /*0.1f in Q15*/ ), mult_r( GainGrad1[2], 29490 /*0.9f in Q15*/ ) ); move16(); /* Q14 */ } ELSE { - GainGradFEC[0] = add( mult_r( GainGrad1[0], 6553 ), mult_r( GainGrad1[1], 9830 ) ); + GainGradFEC[0] = add( mult_r( GainGrad1[0], 6553 /*0.2f in Q15*/ ), mult_r( GainGrad1[1], 9830 /*0.3f in Q15*/ ) ); move16(); - GainGradFEC[0] = add( GainGradFEC[0], mult_r( GainGrad1[2], 16384 ) ); + GainGradFEC[0] = add( GainGradFEC[0], mult_r( GainGrad1[2], 16384 /*0.5f in Q15*/ ) ); move16(); /* Q14 */ } @@ -649,7 +649,7 @@ static void gradientGainShape( } ELSE IF( GainGradFEC[0] > 0 ) { - GainShapeTemp[0] = add( shr( st_fx->GainShape_Delay[7], 1 ), mult_r( GainGradFEC[0], 16384 ) ); + GainShapeTemp[0] = add( shr( st_fx->GainShape_Delay[7], 1 ), mult_r( GainGradFEC[0], 16384 /*0.5f in Q15*/ ) ); move16(); /* Q14 */ } ELSE @@ -668,7 +668,7 @@ static void gradientGainShape( { FOR( i = 1; i < NUM_SHB_SUBFR / 4; i++ ) { - GainShapeTemp[i] = add( GainShapeTemp[i - 1], mult_r( GainGradFEC[i], 26214 ) ); + GainShapeTemp[i] = add( GainShapeTemp[i - 1], mult_r( GainGradFEC[i], 26214 /*0.8f in Q15*/ ) ); move16(); /* GainShapeTemp[i-1] + 0.8* GainShapeTemp[i] */ GainShapeTemp[i] = s_max( GainShapeTemp[i], 328 /*0.01f Q15*/ ); move16(); @@ -681,7 +681,7 @@ static void gradientGainShape( { FOR( i = 1; i < NUM_SHB_SUBFR / 4; i++ ) { - GainShapeTemp[i] = add( GainShapeTemp[i - 1], mult_r( GainGradFEC[i], 6553 ) ); + GainShapeTemp[i] = add( GainShapeTemp[i - 1], mult_r( GainGradFEC[i], 6553 /*0.2f in Q15*/ ) ); move16(); /* GainShapeTemp[i-1] + 0.8* GainShapeTemp[i] */ GainShapeTemp[i] = s_max( GainShapeTemp[i], 328 /*0.01f Q15*/ ); move16(); /* Q14 */ @@ -709,17 +709,17 @@ static void gradientGainShape( { FOR( j = 0; j < 4; j++ ) { - tmp = mult_r( GainShapeTemp[i], 19660 ); /* GainShapeTemp[i]*0.6 */ + tmp = mult_r( GainShapeTemp[i], 19660 /*0.6f Q15*/ ); /* GainShapeTemp[i]*0.6 */ IF( GT_16( 8192, tmp ) ) { - GainShape_fx[add( i * 4, j )] = shl( tmp, 2 ); - move16(); /* (GainShapeTemp[i]*0.6)>>1 */ + GainShape_fx[i * 4 + j] = shl( tmp, 2 ); /*Q15*/ + move16(); /* (GainShapeTemp[i]*0.6)>>1 */ } ELSE { - GainShape_fx[add( i * 4, j )] = 32767; - move16(); /* Clipping here to avoid the a huge change of the code due to gain shape change */ + GainShape_fx[i * 4 + j] = 32767; /*Q15*/ + move16(); /* Clipping here to avoid the a huge change of the code due to gain shape change */ } } } @@ -734,17 +734,17 @@ static void gradientGainShape( { IF( LT_16( GainShapeTemp[i], 16384 ) ) { - GainShape_fx[add( i * 4, j )] = shl( GainShapeTemp[i], 1 ); + GainShape_fx[i * 4 + j] = shl( GainShapeTemp[i], 1 ); /*Q15*/ move16(); } ELSE { - GainShape_fx[add( i * 4, j )] = 32767; + GainShape_fx[i * 4 + j] = 32767; // 1.0f in Q15 move16(); } } } - hBWE_TD->GainAttn_fx = mult_r( hBWE_TD->GainAttn_fx, 31129 ); + hBWE_TD->GainAttn_fx = mult_r( hBWE_TD->GainAttn_fx, 31129 /*0.95f in Q15*/ ); /*Q15*/ move16(); } ELSE IF( GT_16( st_fx->nbLostCmpt, 1 ) ) @@ -753,11 +753,11 @@ static void gradientGainShape( { FOR( j = 0; j < 4; j++ ) { - GainShape_fx[add( i * 4, j )] = GainShapeTemp[i]; + GainShape_fx[i * 4 + j] = GainShapeTemp[i]; /*Q15*/ move16(); } } - hBWE_TD->GainAttn_fx = mult_r( hBWE_TD->GainAttn_fx, 16384 ); + hBWE_TD->GainAttn_fx = mult_r( hBWE_TD->GainAttn_fx, 16384 /*0.5f in Q15*/ ); /*Q15*/ move16(); } ELSE @@ -768,17 +768,17 @@ static void gradientGainShape( { IF( LT_16( GainShapeTemp[i], 16384 ) ) { - GainShape_fx[add( i * 4, j )] = shl( GainShapeTemp[i], 1 ); + GainShape_fx[i * 4 + j] = shl( GainShapeTemp[i], 1 ); /*Q15*/ move16(); } ELSE { - GainShape_fx[add( i * 4, j )] = 32767; + GainShape_fx[i * 4 + j] = 32767; /*Q15*/ move16(); } } } - hBWE_TD->GainAttn_fx = mult_r( hBWE_TD->GainAttn_fx, 27852 ); + hBWE_TD->GainAttn_fx = mult_r( hBWE_TD->GainAttn_fx, 27852 /*0.85f in Q15*/ ); /*Q15*/ move16(); } @@ -1012,15 +1012,15 @@ void find_max_mem_dec_m3( * SWB TBE decoder, 6 - 14 kHz (or 7.5 - 15.5 kHz) band decoding module *-------------------------------------------------------------------*/ void ivas_swb_tbe_dec_fx( - Decoder_State *st, /* i/o: decoder state structure */ - STEREO_ICBWE_DEC_HANDLE hStereoICBWE, /* i/o: IC-BWE state structure */ - const Word32 *bwe_exc_extended_fx, /* i : bandwidth extended excitation */ + Decoder_State *st, /* i/o: decoder state structure */ + STEREO_ICBWE_DEC_HANDLE hStereoICBWE, /* i/o: IC-BWE state structure */ + const Word32 *bwe_exc_extended_fx, /* i : bandwidth extended excitation : Q_exc */ Word16 Q_exc, - const Word16 voice_factors_fx[], /* i : voicing factors */ - const Word32 old_syn_12k8_16k_fx[], /* i : low band synthesis */ - Word16 *White_exc16k_fx, /* o : shaped white excitation for the FB TBE */ - Word32 *synth_fx, /* o : SHB synthesis/final synthesis */ - Word16 *pitch_buf_fx, + const Word16 voice_factors_fx[], /* i : voicing factors : Q15 */ + const Word32 old_syn_12k8_16k_fx[], /* i : low band synthesis : old_syn_fx */ + Word16 *White_exc16k_fx, /* o : shaped white excitation for the FB TBE : Q_white_exc*/ + Word32 *synth_fx, /* o : SHB synthesis/final synthesis : Qx */ + Word16 *pitch_buf_fx, /* i : Q6 */ Word16 *Q_white_exc ) { Word16 i, j, cnt, n; @@ -1136,7 +1136,7 @@ void ivas_swb_tbe_dec_fx( /* WB/SWB bandwidth switching */ test(); test(); - IF( ( GT_16( st->tilt_wb_fx, 10240 ) && ( st->clas_dec == UNVOICED_CLAS ) ) || GT_16( st->tilt_wb_fx, 20480 ) ) + IF( ( GT_16( st->tilt_wb_fx, 10240 /*5 in Q11*/ ) && ( EQ_16( st->clas_dec, UNVOICED_CLAS ) ) ) || GT_16( st->tilt_wb_fx, 20480 /*10 in Q11*/ ) ) { test(); test(); @@ -1155,21 +1155,20 @@ void ivas_swb_tbe_dec_fx( ) { is_fractive = 0; - move16(); } ELSE { is_fractive = 1; - move16(); } + move16(); } /* WB/SWB bandwidth switching */ IF( st->bws_cnt > 0 ) { - f_fx = 1489; /*Q15*/ + f_fx = 1489; /*1.0f / 22.0f in Q15*/ move16(); - inc_fx = 1489; /*Q15*/ + inc_fx = 1489; /*1.0f / 22.0f in Q15*/ move16(); IF( EQ_16( is_fractive, 1 ) ) @@ -1180,9 +1179,9 @@ void ivas_swb_tbe_dec_fx( { FOR( i = 0; i < LPC_SHB_ORDER; i++ ) { - hBWE_TD->lsp_prevfrm_fx[i] = f_fx; + hBWE_TD->lsp_prevfrm_fx[i] = f_fx; /*Q15*/ move16(); - f_fx = add( f_fx, inc_fx ); + f_fx = add( f_fx, inc_fx ); /*Q15*/ } } test(); @@ -1194,13 +1193,13 @@ void ivas_swb_tbe_dec_fx( test(); IF( ( NE_16( st->last_extl, SWB_TBE ) && NE_16( st->last_extl, FB_TBE ) && !( ( L_sub( L_shr( st->prev_enerLH_fx, 1 ), st->enerLH_fx ) < 0 ) && L_sub( st->prev_enerLH_fx, ( L_shr( st->enerLH_fx, 1 ) > 0 ) ) ) ) || st->last_core != ACELP_CORE || ( ( st->last_core == ACELP_CORE ) && GT_32( abs( L_sub( st->last_core_brate, st->core_brate ) ), 3600 ) ) || EQ_16( s_xor( is_fractive, st->prev_fractive ), 1 ) ) { - set16_fx( GainShape_fx, 11587, NUM_SHB_SUBFR ); + set16_fx( GainShape_fx, 11587, NUM_SHB_SUBFR ); /*0.3536f in Q15*/ } ELSE { - if ( GT_16( hBWE_TD->prev_GainShape_fx, 11587 ) ) + if ( GT_16( hBWE_TD->prev_GainShape_fx, 11587 ) ) /*0.3536f in Q15*/ { - hBWE_TD->prev_GainShape_fx = 11587; + hBWE_TD->prev_GainShape_fx = 11587; /*0.3536f in Q15*/ move16(); } set16_fx( GainShape_fx, hBWE_TD->prev_GainShape_fx, NUM_SHB_SUBFR ); @@ -1220,7 +1219,7 @@ void ivas_swb_tbe_dec_fx( move16(); FOR( i = 0; i < LPC_SHB_ORDER; i++ ) { - hBWE_TD->lsp_prevfrm_fx[i] = f_fx; + hBWE_TD->lsp_prevfrm_fx[i] = f_fx; /*Q15*/ move16(); f_fx = add( f_fx, inc_fx ); } @@ -1240,9 +1239,9 @@ void ivas_swb_tbe_dec_fx( move16(); FOR( i = 0; i < LPC_SHB_ORDER; i++ ) { - hBWE_TD->lsp_prevfrm_fx[i] = f_fx; + hBWE_TD->lsp_prevfrm_fx[i] = f_fx; /*Q15*/ move16(); - f_fx = add( f_fx, inc_fx ); + f_fx = add( f_fx, inc_fx ); /*Q15*/ } } Copy( hBWE_TD->lsp_prevfrm_fx, lsf_shb_fx, LPC_SHB_ORDER ); @@ -1267,7 +1266,7 @@ void ivas_swb_tbe_dec_fx( test(); IF( ( st->core == ACELP_CORE ) && ( st->last_core == ACELP_CORE ) && !st->prev_use_partial_copy && EQ_16( st->prev_coder_type, UNVOICED ) && NE_32( GainFrame_fx, hBWE_TD->GainFrame_prevfrm_fx ) && NE_16( st->next_coder_type, GENERIC ) && EQ_16( st->last_extl, SWB_TBE ) ) { - GainFrame_fx = L_add( Mult_32_16( hBWE_TD->GainFrame_prevfrm_fx, 26214 ), Mult_32_16( GainFrame_fx, 6553 ) ); + GainFrame_fx = L_add( Mult_32_16( hBWE_TD->GainFrame_prevfrm_fx, 26214 /*0.8f in Q15*/ ), Mult_32_16( GainFrame_fx, 6553 /*0.2f in Q15*/ ) ); } } ELSE @@ -1323,13 +1322,14 @@ void ivas_swb_tbe_dec_fx( IF( EQ_16( st->last_extl, SWB_TBE ) ) { GainFrame_fx = L_add( Mult_32_16( hBWE_TD->GainFrame_prevfrm_fx, temp_fx ), Mult_32_16( GainFrame_fx, sub( 32767, temp_fx ) ) ); + /*Q18*/ } IF( ( st->core == ACELP_CORE ) && ( st->last_core == ACELP_CORE ) ) { - if ( !st->prev_use_partial_copy && EQ_16( st->last_coder_type, VOICED ) && EQ_16( st->rf_frame_type, RF_GENPRED ) && GT_32( GainFrame_fx, 2097152 ) && LT_32( GainFrame_fx, 3059606 ) ) + if ( !st->prev_use_partial_copy && EQ_16( st->last_coder_type, VOICED ) && EQ_16( st->rf_frame_type, RF_GENPRED ) && GT_32( GainFrame_fx, 2097152 /*8.0f in Q18*/ ) && LT_32( GainFrame_fx, 3059606 /*11.67f in Q18*/ ) ) { - GainFrame_fx = Mult_32_16( GainFrame_fx, 9830 ); + GainFrame_fx = Mult_32_16( GainFrame_fx, 9830 /*0.3f in Q15*/ ); // Q18 } } } @@ -1360,7 +1360,7 @@ void ivas_swb_tbe_dec_fx( { FOR( j = 0; j < 4; j++ ) { - GainShape_fx[add( i * 4, j )] = mult_r( st->cummulative_damping, st->GainShape_Delay[4 + i] ); + GainShape_fx[i * 4 + j] = mult_r( st->cummulative_damping, st->GainShape_Delay[4 + i] ); move16(); } } @@ -1464,7 +1464,7 @@ void ivas_swb_tbe_dec_fx( Copy( &st->GainShape_Delay[4], &st->GainShape_Delay[0], NUM_SHB_SUBFR / 4 ); FOR( i = 0; i < NUM_SHB_SUBFR / 4; i++ ) { - st->GainShape_Delay[i + 4] = GainShape_fx[i * 4]; + st->GainShape_Delay[i + 4] = GainShape_fx[i * 4]; /*Q15*/ move16(); } @@ -2140,9 +2140,9 @@ void ivas_swb_tbe_dec_fx( IF( GT_32( L_shr( prev_ener_ratio_fx, 2 ), GainFrame_fx ) && ( ( EQ_16( st->codec_mode, MODE1 ) && GT_32( st->enerLL_fx, st->prev_enerLL_fx ) && GT_32( st->enerLH_fx, st->prev_enerLH_fx ) ) || EQ_16( st->codec_mode, MODE2 ) ) ) { test(); - IF( GT_16( tilt_swb_fec_fx, 20480 ) && GT_16( hBWE_TD->tilt_swb_fec_fx, 20480 ) ) + IF( GT_16( tilt_swb_fec_fx, 20480 /*10.0f in Q11*/ ) && GT_16( hBWE_TD->tilt_swb_fec_fx, 20480 /*10.0f in Q11*/ ) ) { - GainFrame_fx = L_min( L_add( Mult_32_16( prev_ener_ratio_fx, 26214 ), Mult_32_16( GainFrame_fx, 6554 ) ), L_shl( Mult_32_16( GainFrame_fx, 16384 ), 3 ) ); /*Q18*/ + GainFrame_fx = L_min( L_add( Mult_32_16( prev_ener_ratio_fx, 26214 /*0.8f in Q15*/ ), Mult_32_16( GainFrame_fx, 6554 /*0.2f in Q15*/ ) ), L_shl( Mult_32_16( GainFrame_fx, 16384 /*4.0f in Q12*/ ), 3 ) ); /*Q18*/ } ELSE { @@ -2154,11 +2154,11 @@ void ivas_swb_tbe_dec_fx( test(); IF( GT_16( tilt_swb_fec_fx, 20480 ) && GT_16( hBWE_TD->tilt_swb_fec_fx, 20480 ) ) { - GainFrame_fx = L_add( Mult_32_16( prev_ener_ratio_fx, 16384 ), Mult_32_16( GainFrame_fx, 16384 ) ); + GainFrame_fx = L_add( Mult_32_16( prev_ener_ratio_fx, 16384 /*0.5f in Q15*/ ), Mult_32_16( GainFrame_fx, 16384 /*0.5f in Q15*/ ) ); /* Q18 */ } ELSE { - GainFrame_fx = L_add( Mult_32_16( prev_ener_ratio_fx, 6554 ), Mult_32_16( GainFrame_fx, 26214 ) ); + GainFrame_fx = L_add( Mult_32_16( prev_ener_ratio_fx, 6554 /*0.2f in Q15*/ ), Mult_32_16( GainFrame_fx, 26214 /*0.8f in Q15*/ ) ); /* Q18 */ } } } @@ -2446,7 +2446,7 @@ void ivas_swb_tbe_dec_fx( { GainShape_fx[2 * j] = mult_r( GainShape_fx[2 * j], scale_fx ); move16(); - GainShape_fx[add( 2 * j, 1 )] = mult_r( GainShape_fx[add( 2 * j, 1 )], scale_fx ); + GainShape_fx[2 * j + 1] = mult_r( GainShape_fx[2 * j + 1], scale_fx ); move16(); FOR( i = 0; i < L_FRAME16k / 8; i++ ) { @@ -2573,7 +2573,7 @@ void ivas_swb_tbe_dec_fx( move16(); FOR( i = 0; i < 40; i++ ) { - shaped_shb_excitation_fx[add( i, j * 40 )] = shl( mult_r( shaped_shb_excitation_fx[add( i, j * 40 )], scale_fx ), 3 ); + shaped_shb_excitation_fx[i + j * L_FRAME16k / 8] = shl( mult_r( shaped_shb_excitation_fx[i + j * L_FRAME16k / 8], scale_fx ), 3 ); move16(); /* Q_bwe_exc +12+3 -15 =Q_bwe_exc*/ } @@ -2772,7 +2772,7 @@ void ivas_swb_tbe_dec_fx( if ( !st->bfi ) { - hBWE_TD->GainAttn_fx = 32767; + hBWE_TD->GainAttn_fx = 32767; /*1.0f in Q15*/ move16(); } } @@ -2784,7 +2784,7 @@ void ivas_swb_tbe_dec_fx( move32(); /*Q18*/ hBWE_TD->tilt_swb_fec_fx = tilt_swb_fec_fx; move16(); - hBWE_TD->GainAttn_fx = 32767; + hBWE_TD->GainAttn_fx = 32767; /*1.0f in Q15*/ move16(); } } @@ -4565,12 +4565,12 @@ void GenTransition( #ifdef IVAS_FLOAT_FIXED void GenTransition_fixed( TD_BWE_DEC_HANDLE hBWE_TD, /* i/o: TD BWE data handle */ - Word32 *outputHB_fx, /* o : synthesized HB transitions signal */ - const Word32 output_Fs, /* i : output sampling rate */ - const Word16 element_mode, /* i : element mode */ - const Word16 L_frame, /* i : ACELP frame length */ - const Word16 rf_flag, /* i : RF flag */ - const Word32 total_brate, /* i : total bitrate */ + Word32 *outputHB_fx, /* o : synthesized HB transitions signal : Q11 */ + const Word32 output_Fs, /* i : output sampling rate : Q0 */ + const Word16 element_mode, /* i : element mode : Q0 */ + const Word16 L_frame, /* i : ACELP frame length : Q0 */ + const Word16 rf_flag, /* i : RF flag : Q0 */ + const Word32 total_brate, /* i : total bitrate : Q0 */ const Word16 prev_Qx ) { Word16 i, length; @@ -4578,7 +4578,7 @@ void GenTransition_fixed( Word32 syn_overlap_32k_fx[2 * SHB_OVERLAP_LEN]; /* set targeted length of transition signal */ - length = i_mult( 2, NS2SA( output_Fs, DELAY_BWE_TOTAL_NS ) ); + length = i_mult( 2, NS2SA_FX2( output_Fs, DELAY_BWE_TOTAL_NS ) ); /* upsample overlap snippet */ Interpolate_allpass_steep_32( hBWE_TD->syn_overlap_fx_32, hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx_32, SHB_OVERLAP_LEN, syn_overlap_32k_fx ); @@ -4599,13 +4599,12 @@ void GenTransition_fixed( IF( i % 2 == 0 ) { syn_overlap_32k_fx[i] = L_negate( syn_overlap_32k_fx[i] ); - move32(); } ELSE { syn_overlap_32k_fx[i] = syn_overlap_32k_fx[i]; - move32(); } + move32(); } } @@ -4697,7 +4696,7 @@ void GenTransition_WB( #ifdef IVAS_FLOAT_FIXED void GenTransition_WB_fixed( TD_BWE_DEC_HANDLE hBWE_TD, /* i/o: TD BWE data handle */ - Word32 *outputHB_fx, /* o : synthesized HB transitions signal */ + Word32 *outputHB_fx, /* o : synthesized HB transitions signal : Q11 */ const Word32 output_Fs /* i : output sampling rate */ ) { @@ -4706,7 +4705,7 @@ void GenTransition_WB_fixed( Word32 upsampled_synth_fx[L_FRAME48k]; /* set targeted length of transition signal */ - length = i_mult( 2, NS2SA( output_Fs, DELAY_BWE_TOTAL_NS ) ); + length = i_mult( 2, NS2SA_FX2( output_Fs, DELAY_BWE_TOTAL_NS ) ); /* upsample overlap snippet */ Interpolate_allpass_steep_32( hBWE_TD->syn_overlap_fx_32, hBWE_TD->state_lsyn_filt_shb_fx_32, SHB_OVERLAP_LEN / 2, speech_buf_16k1_fx ); diff --git a/lib_dec/swb_tbe_dec_fx.c b/lib_dec/swb_tbe_dec_fx.c index 2e187546e..cb3ae52a8 100644 --- a/lib_dec/swb_tbe_dec_fx.c +++ b/lib_dec/swb_tbe_dec_fx.c @@ -633,11 +633,11 @@ void ResetSHBbuffer_Dec_fx( Decoder_State *st_fx /* i/o: SHB encoder structure * /*==========================================================================*/ void ivas_wb_tbe_dec_fx( Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word16 coder_type, /* i : coding type */ + const Word16 coder_type, /* i : coding type Q0 */ Word32 *bwe_exc_extended, /* i : bandwidth extended exciatation 2*Q_exc*/ const Word16 Q_exc, - const Word16 voice_factors[], /* i : voicing factors */ - Word16 *synth, /* o : WB synthesis/final synthesis */ + const Word16 voice_factors[], /* i : voicing factors Q15 */ + Word16 *synth, /* o : WB synthesis/final synthesis Q_synth */ Word16 *Q_synth ) { Word16 i; @@ -716,7 +716,7 @@ void ivas_wb_tbe_dec_fx( IF( ( st_fx->core == ACELP_CORE ) && ( st_fx->last_core == ACELP_CORE ) && !st_fx->prev_use_partial_copy && EQ_16( st_fx->prev_coder_type, UNVOICED ) && NE_32( GainFrame, hBWE_TD->GainFrame_prevfrm_fx ) && EQ_16( st_fx->last_extl, WB_TBE ) ) { /*GainFrame = 0.2f*GainFrame + 0.8f*st_fx->GainFrame_prevfrm_fx;*/ - GainFrame = L_add( Mult_32_16( hBWE_TD->GainFrame_prevfrm_fx, 26214 ), Mult_32_16( GainFrame, 6553 ) ); + GainFrame = L_add( Mult_32_16( hBWE_TD->GainFrame_prevfrm_fx /*Q18*/, 26214 /*0.8f in Q15*/ ), Mult_32_16( GainFrame /*Q18*/, 6553 /*0.2f in Q15*/ ) /*Q18+Q15 - 15*/ ); /*Q18*/ } } ELSE @@ -782,7 +782,7 @@ void ivas_wb_tbe_dec_fx( test(); IF( !st_fx->prev_use_partial_copy && EQ_16( st_fx->last_coder_type, VOICED ) && EQ_16( st_fx->rf_frame_type, RF_GENPRED ) && LT_16( st_fx->prev_tilt_code_dec_fx, 1497 ) && GT_16( st_fx->prev_tilt_code_dec_fx, 200 ) ) { - GainFrame = Mult_32_16( GainFrame, 9830 ); + GainFrame = Mult_32_16( GainFrame, 9830 /*0.3f in Q15*/ ); /*Q18*/ } } } @@ -806,12 +806,12 @@ void ivas_wb_tbe_dec_fx( } set16_fx( GainShape, RECIP_ROOT_EIGHT_FX, NUM_SHB_SUBFR / 2 ); - hBWE_TD->GainAttn_fx = mult_r( hBWE_TD->GainAttn_fx, 27853 ); + hBWE_TD->GainAttn_fx = mult_r( hBWE_TD->GainAttn_fx, 27853 /*0.85f in Q15*/ ); /*Q15*/ move16(); IF( EQ_16( st_fx->codec_mode, MODE1 ) ) { - GainFrame = Mult_32_16( hBWE_TD->GainFrame_prevfrm_fx, hBWE_TD->GainAttn_fx ); /*Q18*/ + GainFrame = Mult_32_16( hBWE_TD->GainFrame_prevfrm_fx /*Q18*/, hBWE_TD->GainAttn_fx /*Q15*/ ); /*Q15+Q18-15*/ } ELSE { @@ -835,7 +835,7 @@ void ivas_wb_tbe_dec_fx( lpc_wb[i] = negate( lpc_wb[i] ); move16(); } - lpc_wb[0] = 4096; + lpc_wb[0] = 4096; /*1.0f in Q12*/ move16(); } ELSE @@ -852,7 +852,7 @@ void ivas_wb_tbe_dec_fx( lpc_wb[i] = negate( lpc_wb[i] ); move16(); } - lpc_wb[0] = 4096; + lpc_wb[0] = 4096; /*1.0f in Q12*/ move16(); } @@ -1187,7 +1187,7 @@ void ivas_wb_tbe_dec_fx( FOR( i = 0; i < L_FRAME16k; i++ ) { - synth[i] = mult_r( error[i], 21299 ); + synth[i] = mult_r( error[i], 21299 /*0.65f in Q15*/ ); move16(); } @@ -1376,11 +1376,11 @@ void wb_tbe_dec_fx( move16(); FOR( i = 1; i < LPC_SHB_ORDER_LBR_WB; i++ ) { - hBWE_TD->lsp_prevfrm_fx[i] = add( hBWE_TD->lsp_prevfrm_fx[i - i], 3277 /*0.1f Q15*/ ); + hBWE_TD->lsp_prevfrm_fx[i] = add( hBWE_TD->lsp_prevfrm_fx[i - i], 3277 /*0.1f Q15*/ ); /*Q15*/ move16(); } } - Copy( hBWE_TD->lsp_prevfrm_fx, lsf_wb, LPC_SHB_ORDER_LBR_WB ); + Copy( hBWE_TD->lsp_prevfrm_fx, lsf_wb, LPC_SHB_ORDER_LBR_WB ); /*Q15*/ set16_fx( GainShape, RECIP_ROOT_EIGHT_FX, NUM_SHB_SUBFR / 2 ); IF( EQ_16( st_fx->rf_frame_type, RF_NELP ) ) @@ -1397,7 +1397,7 @@ void wb_tbe_dec_fx( IF( ( st_fx->core == ACELP_CORE ) && ( st_fx->last_core == ACELP_CORE ) && !st_fx->prev_use_partial_copy && EQ_16( st_fx->prev_coder_type, UNVOICED ) && NE_32( GainFrame, hBWE_TD->GainFrame_prevfrm_fx ) && EQ_16( st_fx->last_extl, WB_TBE ) ) { /*GainFrame = 0.2f*GainFrame + 0.8f*st_fx->GainFrame_prevfrm_fx;*/ - GainFrame = L_add( Mult_32_16( hBWE_TD->GainFrame_prevfrm_fx, 26214 ), Mult_32_16( GainFrame, 6553 ) ); + GainFrame = L_add( Mult_32_16( hBWE_TD->GainFrame_prevfrm_fx, 26214 ), Mult_32_16( GainFrame, 6553 ) ); /*Q18*/ } } ELSE @@ -1463,7 +1463,7 @@ void wb_tbe_dec_fx( test(); IF( !st_fx->prev_use_partial_copy && EQ_16( st_fx->last_coder_type, VOICED ) && EQ_16( st_fx->rf_frame_type, RF_GENPRED ) && LT_16( st_fx->prev_tilt_code_dec_fx, 1497 ) && GT_16( st_fx->prev_tilt_code_dec_fx, 200 ) ) { - GainFrame = Mult_32_16( GainFrame, 9830 ); + GainFrame = Mult_32_16( GainFrame, 9830 ); /*Q18*/ } } } @@ -1478,11 +1478,11 @@ void wb_tbe_dec_fx( { IF( EQ_32( st_fx->extl_brate, WB_TBE_0k35 ) ) { - Copy( hBWE_TD->lsp_prevfrm_fx, lsf_wb, LPC_SHB_ORDER_LBR_WB ); + Copy( hBWE_TD->lsp_prevfrm_fx, lsf_wb, LPC_SHB_ORDER_LBR_WB ); /*Q15*/ } ELSE { - Copy( hBWE_TD->lsp_prevfrm_fx, lsf_wb, LPC_SHB_ORDER_WB ); + Copy( hBWE_TD->lsp_prevfrm_fx, lsf_wb, LPC_SHB_ORDER_WB ); /*Q15*/ } set16_fx( GainShape, RECIP_ROOT_EIGHT_FX, NUM_SHB_SUBFR / 2 ); @@ -1971,18 +1971,18 @@ void wb_tbe_dec_fx( /* Update previous frame parameters for FEC */ IF( EQ_32( st_fx->extl_brate, WB_TBE_0k35 ) ) { - Copy( lsf_wb, hBWE_TD->lsp_prevfrm_fx, LPC_SHB_ORDER_LBR_WB ); + Copy( lsf_wb, hBWE_TD->lsp_prevfrm_fx, LPC_SHB_ORDER_LBR_WB ); /*Q15*/ } ELSE { - Copy( lsf_wb, hBWE_TD->lsp_prevfrm_fx, LPC_SHB_ORDER_WB ); + Copy( lsf_wb, hBWE_TD->lsp_prevfrm_fx, LPC_SHB_ORDER_WB ); /*Q15*/ } hBWE_TD->GainFrame_prevfrm_fx = GainFrame; /* Q18 */ move32(); IF( !st_fx->bfi ) { - hBWE_TD->GainAttn_fx = 32767; + hBWE_TD->GainAttn_fx = 32767; /*Q15*/ move16(); } @@ -3742,7 +3742,7 @@ void swb_tbe_dec_fx( if ( !st_fx->bfi ) { - hBWE_TD->GainAttn_fx = 32767; + hBWE_TD->GainAttn_fx = 32767; /*Q15*/ move16(); } } @@ -3754,7 +3754,7 @@ void swb_tbe_dec_fx( move16(); /*Q18*/ hBWE_TD->tilt_swb_fec_fx = tilt_swb_fec; move16(); - hBWE_TD->GainAttn_fx = 32767; + hBWE_TD->GainAttn_fx = 32767; /*Q15*/ move16(); } } @@ -3970,7 +3970,7 @@ static void gradientGainShape( static void Dequant_lower_LSF_fx( const Word16 lsf_idx[], /* i : LSF indices */ - Word16 lsf_q[] /* o : Quantized LSFs */ + Word16 lsf_q[] /* o : Quantized LSFs Q15*/ ) { Word16 i; @@ -3979,7 +3979,7 @@ static void Dequant_lower_LSF_fx( move16(); FOR( i = 1; i < NUM_Q_LSF; i++ ) { - lsf_q[i] = add( lsf_q_cb_fx[i][lsf_idx[i]], lsf_q[i - 1] ); + lsf_q[i] = add( lsf_q_cb_fx[i][lsf_idx[i]], lsf_q[i - 1] ); /*Q15*/ move16(); } @@ -3993,9 +3993,10 @@ static void Dequant_lower_LSF_fx( *-------------------------------------------------------------------*/ static void Map_higher_LSF_fx( - Word16 lsf_q[], /* i/o : Quantized lower LSFs */ - const Word16 m, /* i : Mirroring point */ - const Word16 grid_in[] /* i : Input LSF smoohthing grid */ ) + Word16 lsf_q[], /* i/o : Quantized lower LSFs Q15*/ + const Word16 m, /* i : Mirroring point Q15*/ + const Word16 grid_in[] /* i : Input LSF smoohthing grid Q15*/ +) { Word16 lsf_map[NUM_MAP_LSF]; Word16 grid[NUM_MAP_LSF]; @@ -4007,42 +4008,42 @@ static void Map_higher_LSF_fx( FOR( i = 0; i < NUM_MAP_LSF; i++ ) { - lsf_map[i] = sub( shl( m, 1 ), lsf_q[NUM_MAP_LSF - 1 - i] ); + lsf_map[i] = sub( shl( m, 1 ), lsf_q[NUM_MAP_LSF - 1 - i] ); /*Q15*/ move16(); } IF( GT_16( m, MAX_LSF_FX_BY_2 ) ) { - offset = lsf_map[0]; + offset = lsf_map[0]; /*Q15*/ move16(); scale = div_s( sub( MAX_LSF_FX, m ), m ); FOR( i = 0; i < NUM_MAP_LSF; i++ ) { - lsf_map[i] = add( mult_r( sub( lsf_map[i], offset ), scale ), offset ); + lsf_map[i] = add( mult_r( sub( lsf_map[i], offset ), scale ), offset ); /*Q15*/ move16(); } } - last_q_lsf = lsf_q[NUM_Q_LSF - 1]; + last_q_lsf = lsf_q[NUM_Q_LSF - 1]; /*Q15*/ move16(); scale = sub( MAX_LSF_FX, last_q_lsf ); FOR( i = 0; i < NUM_MAP_LSF; i++ ) { - grid[i] = add( mult_r( grid_in[i], scale ), last_q_lsf ); + grid[i] = add( mult_r( grid_in[i], scale ), last_q_lsf ); /*Q15*/ move16(); } FOR( i = 0; i < NUM_MAP_LSF; i++ ) { - lsf_smooth[i] = sub( mult_r( grid_smoothing_fx[i], grid[i] ), - mult_r( lsf_map[i], add( grid_smoothing_fx[i], -32768 /*-1.0f Q15*/ ) ) ); + lsf_smooth[i] = sub( mult_r( grid_smoothing_fx[i], grid[i] ) /*Q15*/, + mult_r( lsf_map[i], add( grid_smoothing_fx[i], -32768 /*-1.0f Q15*/ /*Q15*/ ) ) ); /*Q15*/ move16(); } FOR( i = 0; i < NUM_MAP_LSF; i++ ) { - lsf_q[NUM_Q_LSF + i] = lsf_smooth[i]; + lsf_q[NUM_Q_LSF + i] = lsf_smooth[i]; /*Q15*/ move16(); } @@ -4051,40 +4052,41 @@ static void Map_higher_LSF_fx( static void Dequant_mirror_point_fx( - const Word16 lsf_q[], /* i/o : Quantized lower LSFs */ - const Word16 m_idx, - /* i : Mirror point index */ Word16 *m /* i : Mirroring point */ ) + const Word16 lsf_q[], /* i/o : Quantized lower LSFs Q15*/ + const Word16 m_idx, /* i : Mirror point index Q0 */ + Word16 *m /* i : Mirroring point Q15*/ +) { - *m = add( mirror_point_q_cb_fx[m_idx], lsf_q[NUM_Q_LSF - 1] ); + *m = add( mirror_point_q_cb_fx[m_idx], lsf_q[NUM_Q_LSF - 1] ); /*Q15*/ move16(); return; } Word16 dotp_loc( - const Word16 x[], /* i : vector x[] */ - const Word32 y[], /* i : vector y[] */ + const Word16 x[], /* i : vector x[] Qx */ + const Word32 y[], /* i : vector y[] Qy */ const Word16 n /* i : vector length */ ) { Word16 i; Word32 suma; Word16 guarded_bits = find_guarded_bits_fx( n ); - suma = L_shr( Mpy_32_16_1( y[0], x[0] ), guarded_bits ); + suma = L_shr( Mpy_32_16_1( y[0], x[0] ), guarded_bits ); /*Qx + Qy - guarded_bits*/ FOR( i = 1; i < n; i++ ) { - suma = L_add( suma, L_shr( Mpy_32_16_1( y[i], x[i] ), guarded_bits ) ); + suma = L_add( suma, L_shr( Mpy_32_16_1( y[i], x[i] ), guarded_bits ) ); /*Qx + Qy - guarded_bits*/ } - suma = L_shl_sat( suma, guarded_bits ); + suma = L_shl_sat( suma, guarded_bits ); /*Qx + Qy*/ - return extract_h( suma ); + return extract_h( suma ); /*Qx + Qy - 16*/ } void ivas_dequantizeSHBparams_fx_9_1( Decoder_State *st_fx, - const Word16 extl, /* i : extension layer */ - Word32 extl_brate, /* i : extensiuon layer bitrate */ - Word16 *Q_lsf, /* o : SHB LSF from de-quantization Q15*/ + const Word16 extl, /* i : extension layer */ + Word32 extl_brate, /* i : extensiuon layer bitrate */ + Word16 *Q_lsf, /* o : SHB LSF from de-quantization Q15*/ Word16 *Q_subgain, /* o : SHB subframe gains from de-quantization Q15*/ Word32 *Q_framegrain, /* o : SHB frame gain from de-quantization Q18*/ Word16 *uv_flag, /* o : unvoiced flag*/ @@ -4281,13 +4283,10 @@ void ivas_dequantizeSHBparams_fx_9_1( *Q_mixFactors = 0; move16(); } - //*Q_mixFactors = 0; set16_fx( Q_shb_res_gshape, 0, 5 ); } /* LSFs */ - - test(); test(); test(); @@ -4327,13 +4326,13 @@ void ivas_dequantizeSHBparams_fx_9_1( set16_fx( lsf_q, 0, LPC_SHB_ORDER ); /* VQ part */ - num_bits_lvq = config_LSF_BWE[i_mult( sub( NUM_BITS_SHB_MSLVQ, nbits ), 3 )]; + num_bits_lvq = config_LSF_BWE[( NUM_BITS_SHB_MSLVQ - nbits ) * 3]; Idx = get_next_indice_fx( st_fx, num_bits_lvq ); v_add_16( lsf_q, cb_stage + i_mult( Idx, 6 ), lsf_q, 6 ); /* MSLVQ part */ - num_bits_lvq = sub( sub( nbits, num_bits_lvq ), config_LSF_BWE[add( i_mult( sub( NUM_BITS_SHB_MSLVQ, nbits ), 3 ), 2 )] ); - predictor_bits = config_LSF_BWE[add( i_mult( sub( NUM_BITS_SHB_MSLVQ, nbits ), 3 ), 2 )]; + num_bits_lvq = sub( sub( nbits, num_bits_lvq ), config_LSF_BWE[( NUM_BITS_SHB_MSLVQ - nbits ) * 3 + 2] ); + predictor_bits = config_LSF_BWE[( NUM_BITS_SHB_MSLVQ - nbits ) * 3 + 2]; Idx_pred = 0; move16(); @@ -4364,9 +4363,9 @@ void ivas_dequantizeSHBparams_fx_9_1( ELSE { Idx_pred = (Word16) get_next_indice_fx( st_fx, 1 ); - lsf_q[LATTICE_DIM] = dotp_loc( lsf_q, &LastCoefPred_1bit_fx[i_mult( 2 * ( LATTICE_DIM + 1 ), Idx_pred )], LATTICE_DIM ); + lsf_q[LATTICE_DIM] = dotp_loc( lsf_q, &LastCoefPred_1bit_fx[2 * ( LATTICE_DIM + 1 ) * Idx_pred], LATTICE_DIM ); move16(); - lsf_q[LATTICE_DIM + 1] = dotp_loc( lsf_q, &LastCoefPred_1bit_fx[add( i_mult( 2 * ( LATTICE_DIM + 1 ), Idx_pred ), LATTICE_DIM + 1 )], LATTICE_DIM ); + lsf_q[LATTICE_DIM + 1] = dotp_loc( lsf_q, &LastCoefPred_1bit_fx[2 * ( LATTICE_DIM + 1 ) * Idx_pred + LATTICE_DIM + 1], LATTICE_DIM ); move16(); } @@ -4541,15 +4540,15 @@ void ivas_dequantizeSHBparams_fx_9_1( static void dequantizeSHBparams_fx_9_1( Decoder_State *st_fx, - const Word16 extl, /* i : extension layer */ - Word32 extl_brate, /* i : extensiuon layer bitrate */ - Word16 *Q_lsf, /* o : SHB LSF from de-quantization Q15*/ + const Word16 extl, /* i : extension layer */ + Word32 extl_brate, /* i : extensiuon layer bitrate */ + Word16 *Q_lsf, /* o : SHB LSF from de-quantization Q15*/ Word16 *Q_subgain, /* o : SHB subframe gains from de-quantization Q15*/ Word32 *Q_framegrain, /* o : SHB frame gain from de-quantization Q18*/ Word16 *uv_flag, /* o : unvoiced flag*/ - Word32 *Q_shb_ener_sf, /* o : Q15 */ - Word16 *Q_shb_res_gshape, /* o : Q14 */ - Word16 *Q_mixFactors /* o : Q15 */ + Word32 *Q_shb_ener_sf, /* o : Q15*/ + Word16 *Q_shb_res_gshape, /* o : Q14*/ + Word16 *Q_mixFactors /* o : Q15*/ ) { Word16 i, j, idxLSF, idxSubGain, idxFrameGain; @@ -4841,10 +4840,10 @@ static void dequantizeSHBparams_fx_9_1( * FB TBE decoder, 14(resp. 15.5) - 20 kHz band decoding module *-------------------------------------------------------------------*/ void fb_tbe_dec_fx( - Decoder_State *st, /* i/o: encoder state structure */ - const Word16 fb_exc[], /* i : FB excitation from the SWB part */ + Decoder_State *st, /* i/o: encoder state structure */ + const Word16 fb_exc[], /* i : FB excitation from the SWB part Q_fb_exc */ Word16 Q_fb_exc, - Word16 *hb_synth, /* o : high-band synthesis */ + Word16 *hb_synth, /* o : high-band synthesis Q(15 - hb_synth_exp) */ Word16 hb_synth_exp ) { @@ -4903,11 +4902,11 @@ void fb_tbe_dec_fx( void fb_tbe_dec_ivas_fx( Decoder_State *st, /* i/o: encoder state structure */ - const Word16 fb_exc[], /* i : FB excitation from the SWB part */ + const Word16 fb_exc[], /* i : FB excitation from the SWB part Q_fb_exc */ Word16 Q_fb_exc, - Word32 *hb_synth, /* o : high-band synthesis */ + Word32 *hb_synth, /* o : high-band synthesis Q(15 - hb_synth_exp) */ Word16 hb_synth_exp, - Word16 *fb_synth_ref, + Word16 *fb_synth_ref, /*Q_fb_synth_ref*/ Word16 Q_fb_synth_ref, Word16 output_frame ) @@ -4978,7 +4977,7 @@ void fb_tbe_dec_ivas_fx( FOR( i = 0; i < L_FRAME48k; i++ ) { // hb_synth[i] = L_add( hb_synth[i], L_deposit_l(fb_synth[i])); - hb_synth[i] = L_add( hb_synth[i], L_shl( fb_synth[i], Q11 ) ); + hb_synth[i] = L_add( hb_synth[i], L_shl( fb_synth[i], Q11 ) ); // hb_synth_exp move16(); } return; @@ -5099,12 +5098,12 @@ void tbe_read_bitstream_fx( * switching from TBE to IGF *---------------------------------------------------------------------*/ void GenTransition_fx( - const Word16 *input, /* i : gain shape overlap buffer */ - const Word16 *old_hb_synth, /* i : synthesized HB from previous frame */ - Word16 length, /* i : targeted length of transition signal */ - Word16 *output, /* o : synthesized transitions signal */ - Word32 Hilbert_Mem[], /* i/o: memory */ - Word16 state_lsyn_filt_shb_local[], /* i/o: memory */ + const Word16 *input, /* i : gain shape overlap buffer Q11 */ + const Word16 *old_hb_synth, /* i : synthesized HB from previous frame Q(15 - hb_synth_fx_exp)*/ + Word16 length, /* i : targeted length of transition signal */ + Word16 *output, /* o : synthesized transitions signal st_fx->prev_Q_bwe_syn2 */ + Word32 Hilbert_Mem[], /* i/o: memory st_fx->prev_Q_bwe_syn2 */ + Word16 state_lsyn_filt_shb_local[], /* i/o: memory st_fx->prev_Q_bwe_syn2*/ Word16 mem_resamp_HB_32k[], /* i/o: memory */ Word16 *syn_dm_phase, Word32 target_fs, @@ -5446,7 +5445,7 @@ void td_bwe_dec_init_fx( const Word32 output_Fs /* i : output sampling rate */ ) { - int16_t i; + Word16 i; /* init. SHB buffers */; InitSWBdecBuffer_fx( st_fx ); @@ -5469,7 +5468,7 @@ void td_bwe_dec_init_fx( hBWE_TD->tilt_mem_fx = 0; move16(); - set16_fx( hBWE_TD->prev_lsf_diff_fx, 16384, LPC_SHB_ORDER - 2 ); + set16_fx( hBWE_TD->prev_lsf_diff_fx, 16384 /*0.5f in Q15*/, LPC_SHB_ORDER - 2 ); hBWE_TD->prev_tilt_para_fx = 0; move16(); set16_fx( hBWE_TD->cur_sub_Aq_fx, 0, M + 1 ); @@ -5503,10 +5502,8 @@ void td_bwe_dec_init_fx( hBWE_TD->fb_tbe_demph_fx = 0; move16(); - set16_fx( hBWE_TD->old_hb_synth_fx, 0, L_FRAME48k ); - hBWE_TD->prev_ener_fx = L_deposit_l( 0 ); move32(); diff --git a/lib_dec/syn_outp.c b/lib_dec/syn_outp.c index 65e36bc61..31cd8b109 100644 --- a/lib_dec/syn_outp.c +++ b/lib_dec/syn_outp.c @@ -47,7 +47,7 @@ * Output synthesis signal with compensation for saturation * returns number of clipped samples *-------------------------------------------------------------------*/ - +#ifndef IVAS_FLOAT_FIXED /*! r: number of clipped samples */ uint32_t syn_output( float *synth, /* i/o: float synthesis signal */ @@ -133,3 +133,4 @@ void AGC_dec( return; } +#endif diff --git a/lib_dec/syn_outp_fx.c b/lib_dec/syn_outp_fx.c index 7d51c4341..0d84c0c88 100644 --- a/lib_dec/syn_outp_fx.c +++ b/lib_dec/syn_outp_fx.c @@ -15,11 +15,11 @@ *-------------------------------------------------------------------*/ void syn_output_fx( - const Word16 codec_mode, /* i : MODE1 or MODE2 */ - Word16 *synth, /* i/o: fixed point synthesis signal */ - const Word16 output_frame, /* i : output frame length */ - Word16 *synth_out, /* o : integer 16 bits synthesis signal */ - const Word16 Q_syn2 /* i : Synthesis scaling factor */ + const Word16 codec_mode, /* i : MODE1 or MODE2 Q0 */ + Word16 *synth, /* i/o: fixed point synthesis signal Q_syn2 */ + const Word16 output_frame, /* i : output frame length Q0 */ + Word16 *synth_out, /* o : integer 16 bits synthesis signal Q_syn2 */ + const Word16 Q_syn2 /* i : Synthesis scaling factor */ ) { Word16 i, tmp; @@ -66,7 +66,7 @@ void unscale_AGC( const Word16 x[], /* i: 16kHz synthesis Qx */ const Word16 Qx, /* i: scale factor of x */ Word16 y[], /* o: output vector Q0 */ - Word16 mem[], /* i/o: mem[2] should be init to [0,0] */ + Word16 mem[], /* i/o: mem[2] should be init to [0,0] Q0 */ const Word16 n /* i: vector size */ ) { @@ -97,16 +97,16 @@ void unscale_AGC( move16(); IF( GT_16( max_val, tmp ) ) { - frame_fac = sub( 16384, div_s( shr( tmp, 1 ), max_val ) ); /* frame fac in Q15 */ + frame_fac = sub( 16384 /*0.5f in Q15*/, div_s( shr( tmp, 1 ), max_val ) ); /* frame fac in Q15 */ } /*----------------------------------------------------------------* * AGC *----------------------------------------------------------------*/ /* update AGC factor (slowly) */ - fac = mac_r( L_mult( 32440, mem[0] ), 328, frame_fac ); + fac = mac_r( L_mult( 32440 /*0.99f in Q15*/, mem[0] ) /*Q14*/, 328 /*0.01f in Q15*/, frame_fac /*Q15*/ ); - L_tmp = L_mult( x[0], 16384 ); + L_tmp = L_mult( x[0], 16384 /*1.0f in Q14*/ ); // Q13 L_tmp = L_msu0( L_tmp, fac, x[0] ); L_tmp = L_msu( L_tmp, fac, mem[1] ); L_tmp = L_shr( L_tmp, -1 ); /* saturation can occur here */ diff --git a/lib_dec/tcq_core_dec_fx.c b/lib_dec/tcq_core_dec_fx.c index 41c83c71e..0432f02a5 100644 --- a/lib_dec/tcq_core_dec_fx.c +++ b/lib_dec/tcq_core_dec_fx.c @@ -16,20 +16,21 @@ #ifdef IVAS_FLOAT_FIXED void tcq_core_LR_dec_fx( Decoder_State *st_fx, - Word16 *inp_vector_fx, /* x5 */ - const Word16 bit_budget, - const Word16 BANDS, - const Word16 *band_start, - const Word16 *band_width, - Word32 *Rk_fx, /* Q16 */ - Word16 *npulses, - Word16 *k_sort, - const Word16 *p2a_flags, - const Word16 p2a_bands, - const Word16 *last_bitalloc, - const Word16 input_frame, - const Word16 adjustFlag, - const Word16 *is_transient ) + Word16 *inp_vector_fx, /*Qx */ + const Word16 bit_budget, /*Q0 */ + const Word16 BANDS, /*Q0 */ + const Word16 *band_start, /*Q0 */ + const Word16 *band_width, /*Q0 */ + Word32 *Rk_fx, /*Q16*/ + Word16 *npulses, /*Q0 */ + Word16 *k_sort, /*Q0 */ + const Word16 *p2a_flags, /*Q0 */ + const Word16 p2a_bands, /*Q0 */ + const Word16 *last_bitalloc, /*Q0 */ + const Word16 input_frame, /*Q0 */ + const Word16 adjustFlag, /*Q0 */ + const Word16 *is_transient /*Q0 */ +) { Word16 i, j, k; Word32 Rk_sort_fx[NB_SFM]; @@ -141,7 +142,7 @@ void tcq_core_LR_dec_fx( { IF( Rk_fx[j] > 0 ) { - Rk_fx[j] = L_sub( Rk_fx[j], ar_div( bsub_fx, nzb ) ); + Rk_fx[j] = L_sub( Rk_fx[j], ar_div( bsub_fx, nzb ) ); /*Q16*/ move32(); IF( Rk_fx[j] < 0 ) { @@ -201,7 +202,7 @@ void tcq_core_LR_dec_fx( IF( LE_16( input_frame, L_FRAME16k ) && ( adjustFlag == 0 ) && ( *is_transient == 0 ) ) { surplus_fx = -131072; - move32(); /*16 */ + move32(); /*2 in Q16 */ bit_allocation_second_fx( Rk_fx, Rk_sort_fx, BANDS, band_width, k_sort, k_num, p2a_flags, p2a_bands, last_bitalloc, input_frame ); @@ -244,7 +245,7 @@ void tcq_core_LR_dec_fx( move16(); FOR( i = 0; i < band_width[k_sort[k]]; i++ ) { - inp_vector_fx[add( band_start[k_sort[k]], i )] = 0; + inp_vector_fx[band_start[k_sort[k]] + i] = 0; move16(); } IF( surplus_fx != 0 ) @@ -266,7 +267,7 @@ void tcq_core_LR_dec_fx( decode_mangitude_tcq_fx( pardec_fx, band_width[k_sort[k]], pulsesnum, nz, &positions_fx[band_start[k_sort[k]]], &inp_vector_fx[band_start[k_sort[k]]], &surplus_fx ); decode_signs_fx( pardec_fx, band_width[k_sort[k]], &inp_vector_fx[band_start[k_sort[k]]] ); } - nzbands--; + nzbands = sub( nzbands, 1 ); move16(); } ELSE IF( ( Rk_fx[k_sort[k]] > 0 ) && EQ_16( USQ_TCQ[k_sort[k]], 1 ) ) @@ -282,7 +283,7 @@ void tcq_core_LR_dec_fx( move16(); FOR( i = 0; i < band_width[k_sort[k]]; i++ ) { - inp_vector_fx[add( band_start[k_sort[k]], i )] = 0; + inp_vector_fx[band_start[k_sort[k]] + i] = 0; move16(); } IF( surplus_fx != 0 ) @@ -302,7 +303,7 @@ void tcq_core_LR_dec_fx( decode_magnitude_usq_fx( pardec_fx, band_width[k_sort[k]], pulsesnum, nz, &positions_fx[band_start[k_sort[k]]], &inp_vector_fx[band_start[k_sort[k]]] ); decode_signs_fx( pardec_fx, band_width[k_sort[k]], &inp_vector_fx[band_start[k_sort[k]]] ); } - nzbands--; + nzbands = sub( nzbands, 1 ); move16(); } ELSE @@ -311,7 +312,7 @@ void tcq_core_LR_dec_fx( move16(); FOR( i = 0; i < band_width[k_sort[k]]; i++ ) { - inp_vector_fx[add( band_start[k_sort[k]], i )] = 0; + inp_vector_fx[band_start[k_sort[k]] + i] = 0; move16(); } } @@ -403,7 +404,7 @@ void tcq_core_LR_dec_fx( move16(); FOR( i = 0; i < band_width[k_sort[k]]; i++ ) { - inp_vector_fx[add( band_start[k_sort[k]], i )] = 0; + inp_vector_fx[band_start[k_sort[k]] + i] = 0; move16(); } } @@ -436,7 +437,7 @@ void tcq_core_LR_dec_fx( move16(); FOR( i = 0; i < band_width[k_sort[k]]; i++ ) { - inp_vector_fx[add( band_start[k_sort[k]], i )] = 0; + inp_vector_fx[band_start[k_sort[k]] + i] = 0; move16(); } } diff --git a/lib_dec/tcx_utils_dec_fx.c b/lib_dec/tcx_utils_dec_fx.c index e4b56eca9..1c7bee57b 100644 --- a/lib_dec/tcx_utils_dec_fx.c +++ b/lib_dec/tcx_utils_dec_fx.c @@ -20,11 +20,11 @@ * *--------------------------------------------------------------*/ void tcx_decoder_memory_update( - Word16 *xn_buf, /* i/o: mdct output buffer used also as temporary buffer */ - Word16 *synthout, /* o: synth */ - Word16 *A, /* i: Quantized LPC coefficients */ - Decoder_State *st, /* i/o: decoder memory state */ - Word8 fb /* i: fullband flag */ + Word16 *xn_buf, /* i/o: mdct output buffer used also as temporary buffer : Q0 */ + Word16 *synthout, /* o: synth : Q0 */ + Word16 *A, /* i: Quantized LPC coefficients : Q12*/ + Decoder_State *st, /* i/o: decoder memory state */ + Word8 fb /* i: fullband flag */ ) { Word16 tmp; @@ -35,7 +35,7 @@ void tcx_decoder_memory_update( L_frame_glob = st->L_frame; move16(); - preemph = st->preemph_fac; + preemph = st->preemph_fac; // Q15 move16(); /* Output synth */ @@ -105,7 +105,7 @@ void tcx_decoder_memory_update( Residu3_fx( A, synth, st->old_exc_fx + sub( L_EXC_MEM_DEC, L_frame_glob ), L_frame_glob, 1 ); } /* Update old_Aq */ - Copy( A, st->old_Aq_12_8_fx, M + 1 ); + Copy( A, st->old_Aq_12_8_fx /*Q12*/, M + 1 ); #ifdef FIX_778_STEREO_BRATE_SWITCHING } #endif @@ -116,27 +116,22 @@ void tcx_decoder_memory_update( /* Returns: number of bits used (including "bits") */ Word16 tcx_ari_res_invQ_spec( - Word32 x_Q[], /* i/o: quantized spectrum Q31-e */ - Word16 x_Q_e, /* i: quantized spectrum exponent Q0 */ - Word16 L_frame, /* i: number of lines Q0 */ - const Word16 prm[], /* i: bitstream Q0 */ - Word16 target_bits, /* i: number of bits available Q0 */ - Word16 bits, /* i: number of bits used so far Q0 */ - Word16 deadzone, /* i: quantizer deadzone Q15 */ - const Word16 x_fac[] /* i: spectrum post-quantization factors Q14 */ + Word32 x_Q[], /* i/o: quantized spectrum Q(31-x_Q_e) */ + Word16 x_Q_e, /* i: quantized spectrum exponent Q0 */ + Word16 L_frame, /* i: number of lines Q0 */ + const Word16 prm[], /* i: bitstream Q0 */ + Word16 target_bits, /* i: number of bits available Q0 */ + Word16 bits, /* i: number of bits used so far Q0 */ + Word16 deadzone, /* i: quantizer deadzone Q15 */ + const Word16 x_fac[] /* i: spectrum post-quantization factors Q14 */ ) { - Word16 i, j, num_zeros; - Word16 zeros[L_FRAME_PLUS]; - Word16 fac_p, sign; + Word16 i, j, num_zeros, zeros[L_FRAME_PLUS], fac_p, sign, s; Word32 L_tmp; - Word16 s; - /* Limit the number of residual bits */ target_bits = s_min( target_bits, NPRM_RESQ ); - /* Requantize the spectrum line-by-line */ /* fac_m = deadzone * 0.5f; */ num_zeros = 0; @@ -157,7 +152,7 @@ Word16 tcx_ari_res_invQ_spec( sign = negate( sign ); /* x_Q[i] += sign*(prm[bits++] * 0.5f - fac_m); */ - x_Q[i] = L_sub( x_Q[i], L_shr( L_mult( sign, add( deadzone, lshl( prm[bits], 15 ) ) ), x_Q_e ) ); + x_Q[i] = L_sub( x_Q[i], L_shr( L_mult( sign, add( deadzone, lshl( prm[bits], 15 ) ) ), x_Q_e ) ); // x_Q_e move32(); bits = add( bits, 1 ); } @@ -196,7 +191,6 @@ Word16 tcx_ari_res_invQ_spec( bits = add( bits, 1 ); } - return bits; } /*--------------------------------------------------------------- @@ -205,14 +199,13 @@ Word16 tcx_ari_res_invQ_spec( * *--------------------------------------------------------------*/ Word16 tcx_res_invQ_gain( - Word16 *gain_tcx, + Word16 *gain_tcx, /* i/o : gain_tcx_e*/ Word16 *gain_tcx_e, - Word16 *prm, - Word16 resQBits ) + Word16 *prm, /*i : Q0 */ + Word16 resQBits /*i : Q0 */ +) { - Word16 bits; - Word16 gain, tmp1, tmp2; - + Word16 bits, gain, tmp1, tmp2; gain = *gain_tcx; move16(); @@ -255,14 +248,14 @@ Word16 tcx_res_invQ_gain( * *--------------------------------------------------------------*/ Word16 tcx_res_invQ_spec( - Word32 *x, + Word32 *x, /*Q(31 - x_e)*/ Word16 x_e, Word16 L_frame, Word16 *prm, Word16 resQBits, Word16 bits, - Word16 sq_round, - const Word16 lf_deemph_factors[] ) + Word16 sq_round, /*i : sq deadzone Q15*/ + const Word16 lf_deemph_factors[] /*i : LF deemphasis factors Q14*/ ) { Word16 i; Word16 fac_m, fac_p; @@ -275,9 +268,9 @@ Word16 tcx_res_invQ_spec( /* Requantize the spectrum line-by-line */ fac_m = shr( sq_round, 1 ); - fac_p = sub( 0x4000, fac_m ); + fac_p = sub( 0x4000 /*0.5f Q15*/, fac_m ); // Q15 - lf_deemph_factor = 0x4000; + lf_deemph_factor = 0x4000; /*0.5f Q15*/ move16(); s = sub( x_e, 1 ); @@ -290,11 +283,11 @@ Word16 tcx_res_invQ_spec( test(); test(); - IF( ( x[i] != 0 ) && ( ( lf_deemph_factors == NULL ) || ( GT_16( lf_deemph_factors[i], 0x2000 ) ) ) ) + IF( ( x[i] != 0 ) && ( ( lf_deemph_factors == NULL ) || ( GT_16( lf_deemph_factors[i], 0x2000 /*0.5f in Q14*/ ) ) ) ) { if ( lf_deemph_factors != NULL ) { - lf_deemph_factor = lf_deemph_factors[i]; + lf_deemph_factor = lf_deemph_factors[i]; // Q14 move16(); } @@ -306,13 +299,13 @@ Word16 tcx_res_invQ_spec( move32(); if ( x[i] > 0 ) - tmp = L_mult( fac_m, lf_deemph_factor ); + tmp = L_mult( fac_m, lf_deemph_factor ); // Q14+Q15-1 = Q28 if ( x[i] < 0 ) - tmp = L_mult( fac_p, lf_deemph_factor ); + tmp = L_mult( fac_p, lf_deemph_factor ); // Q14+Q15-1 = Q28 assert( tmp != 0 ); - x[i] = L_sub( x[i], L_shr( tmp, s ) ); + x[i] = L_sub( x[i], L_shr( tmp, s ) ); // Q(31 - x_e) move32(); } ELSE @@ -323,13 +316,13 @@ Word16 tcx_res_invQ_spec( move32(); if ( x[i] > 0 ) - tmp = L_mult( fac_p, lf_deemph_factor ); + tmp = L_mult( fac_p, lf_deemph_factor ); // Q14+Q15-1 = Q28 if ( x[i] < 0 ) - tmp = L_mult( fac_m, lf_deemph_factor ); + tmp = L_mult( fac_m, lf_deemph_factor ); // Q14+Q15-1 = Q28 assert( tmp != 0 ); - x[i] = L_add( x[i], L_shr( tmp, s ) ); + x[i] = L_add( x[i], L_shr( tmp, s ) ); // Q(31 - x_e) move32(); } bits = add( bits, 1 ); @@ -354,11 +347,11 @@ Word16 tcx_res_invQ_spec( { bits = add( bits, 1 ); - tmp = L_mult( 21627 /*1.32f Q14*/, fac_p ); + tmp = L_mult( 21627 /*1.32f Q14*/, fac_p /*Q15*/ ); // Q28 if ( prm[bits] == 0 ) tmp = L_negate( tmp ); - x[i] = L_shr( tmp, s ); + x[i] = L_shr( tmp, s ); // Q(31 - x_e) move32(); } bits = add( bits, 1 ); @@ -367,7 +360,7 @@ Word16 tcx_res_invQ_spec( } ELSE { - c = sub( 21627 /*0.66f Q15*/, mult_r( sq_round, 21627 /*0.66f Q15*/ ) ); + c = sub( 21627 /*0.66f Q15*/, mult_r( sq_round, 21627 /*0.66f Q15*/ ) ); // Q15 FOR( i = 0; i < L_frame; i++ ) { @@ -383,11 +376,11 @@ Word16 tcx_res_invQ_spec( { bits = add( bits, 1 ); - tmp = L_mult( c, lf_deemph_factors[i] ); + tmp = L_mult( c, lf_deemph_factors[i] ); // Q28 if ( prm[bits] == 0 ) tmp = L_negate( tmp ); - x[i] = L_shr( tmp, s ); + x[i] = L_shr( tmp, s ); // Q(31 - x_e) move32(); } bits = add( bits, 1 ); diff --git a/lib_dec/tns_base_dec_fx.c b/lib_dec/tns_base_dec_fx.c index 4f44dab85..4a68a49c2 100644 --- a/lib_dec/tns_base_dec_fx.c +++ b/lib_dec/tns_base_dec_fx.c @@ -35,9 +35,10 @@ Word16 ReadTnsData( STnsConfig const *pTnsConfig, Decoder_State *st, - Word16 *pnBits, - Word16 *stream, - Word16 *pnSize ) + Word16 *pnBits, /*Q0*/ + Word16 *stream, /*Q0*/ + Word16 *pnSize /*Q0*/ +) { Word16 start_bit_pos; @@ -97,13 +98,13 @@ Word16 ReadTnsData_ivas_fx( STnsConfig const *pTnsConfig, Decoder_State *st, - Word16 *pnBits, - Word16 *stream, - Word16 *pnSize ) + Word16 *pnBits, /*Q0*/ + Word16 *stream, /*Q0*/ + Word16 *pnSize /*Q0*/ +) { Word16 start_bit_pos; - move16(); start_bit_pos = st->next_bit_pos; @@ -143,7 +144,6 @@ ReadTnsData_ivas_fx( move16(); *pnBits = sub( st->next_bit_pos, start_bit_pos ); - #ifdef IVAS_CODE return; #else @@ -159,8 +159,8 @@ ReadTnsData_ivas_fx( Word16 DecodeTnsData( STnsConfig const *pTnsConfig, - Word16 const *stream, - Word16 *pnSize, + Word16 const *stream, /*Q0*/ + Word16 *pnSize, /*Q0*/ STnsData *pTnsData ) { Word16 result; @@ -215,8 +215,8 @@ Word16 DecodeTnsData( Word16 DecodeTnsData_ivas_fx( STnsConfig const *pTnsConfig, - Word16 const *stream, - Word16 *pnSize, + Word16 const *stream, /*Q0*/ + Word16 *pnSize, /*Q0*/ STnsData *pTnsData ) { Word16 result; diff --git a/lib_enc/ivas_core_enc.c b/lib_enc/ivas_core_enc.c index d601c6fa2..48e175a43 100644 --- a/lib_enc/ivas_core_enc.c +++ b/lib_enc/ivas_core_enc.c @@ -114,8 +114,8 @@ ivas_error ivas_core_enc( Word32 bwe_exc_extended_fx[CPE_CHANNELS][L_FRAME32k + NL_BUFF_OFFSET]; /* 2 * Q_new */ Word16 voice_factors_fx[CPE_CHANNELS][NB_SUBFR16k]; /* Q15 */ Word16 old_syn_12k8_16k_fx[CPE_CHANNELS][L_FRAME16k]; /* ACELP core synthesis at 12.8kHz or 16kHz to be used by the SWB BWE */ - Word16 *new_swb_speech_fx1; - Word16 new_swb_speech_buffer_fx1[L_FRAME48k + STEREO_DFT_OVL_MAX]; + Word16 *new_swb_speech_fx_16; + Word16 new_swb_speech_buffer_fx_16[L_FRAME48k + STEREO_DFT_OVL_MAX]; #endif int16_t Voicing_flag[CPE_CHANNELS]; #ifdef IVAS_FLOAT_FIXED_CONVERSIONS // required for float fixed conversions @@ -140,6 +140,9 @@ ivas_error ivas_core_enc( Word16 i; #endif + set32_fx( new_swb_speech_buffer_fx, 0, L_FRAME48k + STEREO_DFT_OVL_MAX ); + set16_fx( new_swb_speech_buffer_fx_16, 0, L_FRAME48k + STEREO_DFT_OVL_MAX ); + #ifdef MSAN_FIX FOR( i = 0; i < CPE_CHANNELS; i++ ) { @@ -906,7 +909,7 @@ ivas_error ivas_core_enc( new_swb_speech = new_swb_speech_buffer + STEREO_DFT_OVL_MAX; #ifdef IVAS_FLOAT_FIXED new_swb_speech_fx = new_swb_speech_buffer_fx + STEREO_DFT_OVL_MAX; - new_swb_speech_fx1 = new_swb_speech_buffer_fx1 + STEREO_DFT_OVL_MAX; + new_swb_speech_fx_16 = new_swb_speech_buffer_fx_16 + STEREO_DFT_OVL_MAX; #endif if ( !st->Opt_SC_VBR && input_Fs >= 32000 && st->hBWE_TD != NULL ) @@ -916,7 +919,7 @@ ivas_error ivas_core_enc( #ifdef IVAS_FLOAT_FIXED_CONVERSIONS Word32 realBuffer_fx[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; Word32 imagBuffer_fx[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; - Word16 new_swb_speech_16_fx[L_FRAME48k] = { 0 }; + // Word16 new_swb_speech_16_fx[L_FRAME48k] = { 0 }; Word16 use_shb32 = 0; Word16 q_realImagBuffer = Q_factor_arrL( (float *) &realBuffer[n][0][0], CLDFB_NO_COL_MAX * CLDFB_NO_CHANNELS_MAX ); q_realImagBuffer = s_min( q_realImagBuffer, Q_factor_arrL( (float *) &imagBuffer[n][0][0], CLDFB_NO_COL_MAX * CLDFB_NO_CHANNELS_MAX ) ); @@ -963,7 +966,7 @@ ivas_error ivas_core_enc( } #endif #endif - swb_pre_proc_ivas_fx( st, new_swb_speech_16_fx, new_swb_speech_fx, shb_speech_fx, shb_speech_fx_32, &use_shb32, realBuffer_fx, imagBuffer_fx, q_realImagBuffer, hCPE ); + swb_pre_proc_ivas_fx( st, new_swb_speech_fx_16, new_swb_speech_fx, shb_speech_fx, shb_speech_fx_32, &use_shb32, realBuffer_fx, imagBuffer_fx, q_realImagBuffer, hCPE ); #ifdef IVAS_FLOAT_FIXED_CONVERSIONS fixedToFloat_arr( (Word16 *) &st->hBWE_TD->old_speech_shb_fx[0], (float *) &st->hBWE_TD->old_speech_shb[0], 0, L_LOOK_16k + L_SUBFR16k ); fixedToFloat_arr( (Word16 *) &st->hBWE_FD->old_fdbwe_speech_fx[0], (float *) &st->hBWE_FD->old_fdbwe_speech[0], 0, L_FRAME48k ); @@ -973,7 +976,7 @@ ivas_error ivas_core_enc( st->hBWE_FD->old_input[ii] = (Word16) st->hBWE_FD->old_input_fx[ii]; } fixedToFloat_arrL32( (Word32 *) &st->cldfbSynTd->cldfb_state_fx[0], (float *) &st->cldfbSynTd->cldfb_state[0], q_realImagBuffer, st->cldfbSynTd->p_filter_length ); - fixedToFloat_arr( new_swb_speech_16_fx, new_swb_speech, 0, L_FRAME48k ); + fixedToFloat_arr( new_swb_speech_fx_16, new_swb_speech, 0, L_FRAME48k ); if ( use_shb32 == 0 ) { fixedToFloat_arr( shb_speech_fx, shb_speech, 0, L_FRAME16k ); @@ -1153,7 +1156,7 @@ ivas_error ivas_core_enc( for ( int ii = 0; ii < L_FRAME48k + STEREO_DFT_OVL_MAX; ii++ ) { - new_swb_speech_buffer_fx1[ii] = (Word16) new_swb_speech_buffer[ii]; + new_swb_speech_buffer_fx_16[ii] = (Word16) new_swb_speech_buffer[ii]; } for ( int ii = 0; ii < NS2SA( 48000, DELAY_FD_BWE_ENC_NS + DELAY_FIR_RESAMPL_NS ); ii++ ) { @@ -1161,7 +1164,7 @@ ivas_error ivas_core_enc( } #endif /* SWB(FB) BWE encoder */ - swb_bwe_enc_ivas_fx( st, last_element_mode, old_inp_12k8_fx, old_inp_16k_fx, old_syn_12k8_16k_fx[n], new_swb_speech_fx1, shb_speech_fx, q_shb_speech_fx, q_val ); + swb_bwe_enc_ivas_fx( st, last_element_mode, old_inp_12k8_fx, old_inp_16k_fx, old_syn_12k8_16k_fx[n], new_swb_speech_fx_16, shb_speech_fx, q_shb_speech_fx, q_val ); #ifdef IVAS_FLOAT_FIXED_CONVERSIONS if ( st->hBWE_FD != NULL ) { diff --git a/lib_enc/ivas_core_pre_proc_front.c b/lib_enc/ivas_core_pre_proc_front.c index 3cdbd36a0..b84e82262 100644 --- a/lib_enc/ivas_core_pre_proc_front.c +++ b/lib_enc/ivas_core_pre_proc_front.c @@ -2128,6 +2128,9 @@ ivas_error pre_proc_front_ivas_fx( } stab_fac = (float) ( (float) stab_fac_fx / 32767.0f ); + + free( old_inp_12k8_loc_fx ); + #endif if ( element_mode == IVAS_CPE_TD && st->idchan == 1 ) { diff --git a/lib_enc/ivas_dirac_enc.c b/lib_enc/ivas_dirac_enc.c index 7891a753b..2a10d92d7 100644 --- a/lib_enc/ivas_dirac_enc.c +++ b/lib_enc/ivas_dirac_enc.c @@ -138,6 +138,21 @@ ivas_error ivas_dirac_enc_open( } set_f( hDirAC->direction_vector_m[i][j], 0.0f, DIRAC_MAX_NBANDS ); } +#ifdef IVAS_FLOAT_FIXED + IF( ( hDirAC->direction_vector_m_fx[i] = (Word32 **) malloc( MAX_PARAM_SPATIAL_SUBFRAMES * sizeof( Word32 * ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); + } + + FOR( j = 0; j < MAX_PARAM_SPATIAL_SUBFRAMES; j++ ) + { + if ( ( hDirAC->direction_vector_m_fx[i][j] = (Word32 *) malloc( DIRAC_MAX_NBANDS * sizeof( Word32 ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); + } + set32_fx( hDirAC->direction_vector_m_fx[i][j], 0, DIRAC_MAX_NBANDS ); + } +#endif } hDirAC->no_col_avg_diff = (int16_t) ( DIRAC_NO_COL_AVG_DIFF_NS / dirac_slot_ns ); @@ -426,6 +441,10 @@ void ivas_dirac_enc_close( { free( hDirAC->direction_vector_m[i][j] ); hDirAC->direction_vector_m[i][j] = NULL; +#ifdef IVAS_FLOAT_FIXED + free( hDirAC->direction_vector_m_fx[i][j] ); + hDirAC->direction_vector_m_fx[i][j] = NULL; +#endif } for ( j = 0; j < hDirAC->no_col_avg_diff; j++ ) @@ -456,6 +475,10 @@ void ivas_dirac_enc_close( free( hDirAC->direction_vector_m[i] ); hDirAC->direction_vector_m[i] = NULL; +#ifdef IVAS_FLOAT_FIXED + free( hDirAC->direction_vector_m_fx[i] ); + hDirAC->direction_vector_m_fx[i] = NULL; +#endif } free( hDirAC->buffer_energy ); @@ -505,7 +528,159 @@ ivas_error ivas_dirac_enc( ivas_error error; push_wmops( "ivas_dirac_enc" ); - ivas_dirac_param_est_enc( hDirAC, hQMetaData->q_direction, hQMetaData->useLowerRes, data_f, ppIn_FR_real, ppIn_FR_imag, input_frame, ivas_format, hodirac_flag, hodirac_flag ? HOA2_CHANNELS : FOA_CHANNELS, &( hDirAC->mono_frame_count ), &( hQMetaData->dirac_mono_flag ) ); +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + /*---------------------------------------------- float to fixed ----------------------------------------------*/ + + set16_fx( (Word16 *) hDirAC->buffer_energy_q, 0, DIRAC_NO_COL_AVG_DIFF * DIRAC_MAX_NBANDS ); + set16_fx( (Word16 *) hDirAC->buffer_intensity_real_q, 0, DIRAC_NUM_DIMS * DIRAC_NO_COL_AVG_DIFF * DIRAC_MAX_NBANDS ); + Word16 block_m_idx; + Word16 band_m_idx; + Word16 nchan_fb_in = hodirac_flag ? HOA2_CHANNELS : FOA_CHANNELS; + Word16 nblocks = hQMetaData->useLowerRes ? 1 : MAX_PARAM_SPATIAL_SUBFRAMES; + + /* Find Q-factor */ + Word16 pcm_q; + Word16 pp_fr_q; + float max_val = 0; + for ( i = 0; i < nchan_fb_in; i++ ) + { + for ( j = 0; j < input_frame; j++ ) + { + max_val = max( max_val, (float) fabs( data_f[i][j] ) ); + } + } + pcm_q = Q_factor_L( max_val ); + + max_val = 0; + for ( i = 0; i < nchan_fb_in; i++ ) + { + for ( j = 0; j < input_frame; j++ ) + { + max_val = max( max_val, (float) fabs( ppIn_FR_real[i][j] ) ); + max_val = max( max_val, (float) fabs( ppIn_FR_imag[i][j] ) ); + } + } + pp_fr_q = Q_factor_L( max_val ); + + Word32 fr_real_fx[DIRAC_MAX_ANA_CHANS][L_FRAME48k * 2]; + Word32 fr_imag_fx[DIRAC_MAX_ANA_CHANS][L_FRAME48k * 2]; + Word32 data_f_buf[DIRAC_MAX_ANA_CHANS][L_FRAME48k]; + Word32 *pp_fr_real_fx[DIRAC_MAX_ANA_CHANS]; + Word32 *pp_fr_imag_fx[DIRAC_MAX_ANA_CHANS]; + Word32 *data_f_fx[DIRAC_MAX_ANA_CHANS]; + for ( i = 0; i < nchan_fb_in; i++ ) + { + data_f_fx[i] = data_f_buf[i]; + pp_fr_real_fx[i] = fr_real_fx[i]; + pp_fr_imag_fx[i] = fr_imag_fx[i]; + for ( j = 0; j < input_frame; j++ ) + { + data_f_fx[i][j] = float_to_fix( data_f[i][j], pcm_q ); + pp_fr_real_fx[i][j] = float_to_fix( ppIn_FR_real[i][j], pp_fr_q ); + pp_fr_imag_fx[i][j] = float_to_fix( ppIn_FR_imag[i][j], pp_fr_q ); + } + } + + for ( i = 0; i < DIRAC_NUM_DIMS; i++ ) + { + for ( j = 0; j < hDirAC->no_col_avg_diff; j++ ) + { + for ( int k = 0; k < hDirAC->hConfig->nbands; k++ ) + { + Word16 tmp; + f2me( hDirAC->buffer_intensity_real[i][j][k], &hDirAC->buffer_intensity_real_fx[i][j][k], &tmp ); + hDirAC->buffer_intensity_real_q[i][j][k] = 31 - tmp; + } + } + } + for ( i = 0; i < hDirAC->hConfig->nbands; i++ ) + { + for ( j = 0; j < hDirAC->no_col_avg_diff; j++ ) + { + Word16 tmp; + f2me( hDirAC->buffer_energy[i + j * hDirAC->hConfig->nbands], &hDirAC->buffer_energy_fx[i + j * hDirAC->hConfig->nbands], &tmp ); + hDirAC->buffer_energy_q[i + j * hDirAC->hConfig->nbands] = 31 - tmp; + } + } + + for ( i = 0; i < NUM_ANA_SECTORS * IVAS_MAX_NUM_BANDS; i++ ) + { + hDirAC->azi_prev_fx[i] = float_to_fix( hDirAC->azi_prev[i], Q23 ); + hDirAC->ele_prev_fx[i] = float_to_fix( hDirAC->ele_prev[i], Q23 ); + } + for ( i = 0; i < NUM_ANA_SECTORS; i++ ) + { + for ( j = 0; j < IVAS_MAX_NUM_BANDS; j++ ) + { + f2me( hDirAC->sec_I_vec_smth_x[i][j], &hDirAC->sec_I_vec_smth_x_fx[i][j], &hDirAC->sec_I_vec_smth_x_exp[i][j] ); + f2me( hDirAC->sec_I_vec_smth_y[i][j], &hDirAC->sec_I_vec_smth_y_fx[i][j], &hDirAC->sec_I_vec_smth_y_exp[i][j] ); + f2me( hDirAC->sec_I_vec_smth_z[i][j], &hDirAC->sec_I_vec_smth_z_fx[i][j], &hDirAC->sec_I_vec_smth_z_exp[i][j] ); + } + } +#endif + ivas_dirac_param_est_enc( hDirAC, hQMetaData->q_direction, hQMetaData->useLowerRes, data_f_fx, pp_fr_real_fx, pp_fr_imag_fx, pp_fr_q, input_frame, ivas_format, hodirac_flag, nchan_fb_in, &( hDirAC->mono_frame_count ), &( hQMetaData->dirac_mono_flag ) ); +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + /*---------------------------------------------- fixed to float ----------------------------------------------*/ + for ( block_m_idx = 0; block_m_idx < nblocks; block_m_idx++ ) + { + for ( band_m_idx = 0; band_m_idx < hDirAC->hConfig->nbands; band_m_idx++ ) + { + hQMetaData->q_direction->band_data[band_m_idx].azimuth[block_m_idx] = fix_to_float( hQMetaData->q_direction->band_data[band_m_idx].azimuth_fx[block_m_idx], Q22 ); + hQMetaData->q_direction->band_data[band_m_idx].elevation[block_m_idx] = fix_to_float( hQMetaData->q_direction->band_data[band_m_idx].elevation_fx[block_m_idx], Q22 ); + if ( hodirac_flag ) + { + hQMetaData->q_direction[1].band_data[band_m_idx].azimuth[block_m_idx] = fix_to_float( hQMetaData->q_direction[1].band_data[band_m_idx].azimuth_fx[block_m_idx], Q22 ); + hQMetaData->q_direction[1].band_data[band_m_idx].elevation[block_m_idx] = fix_to_float( hQMetaData->q_direction[1].band_data[band_m_idx].elevation_fx[block_m_idx], Q22 ); + hQMetaData->q_direction[1].band_data[band_m_idx].energy_ratio[block_m_idx] = fix_to_float( hQMetaData->q_direction[1].band_data[band_m_idx].energy_ratio_fx[block_m_idx], Q30 ); + } + else + { + hDirAC->direction_vector_m[0][block_m_idx][band_m_idx] = me2f( hDirAC->direction_vector_m_fx[0][block_m_idx][band_m_idx], hDirAC->direction_vector_m_exp[block_m_idx] ); + hDirAC->direction_vector_m[1][block_m_idx][band_m_idx] = me2f( hDirAC->direction_vector_m_fx[1][block_m_idx][band_m_idx], hDirAC->direction_vector_m_exp[block_m_idx] ); + hDirAC->direction_vector_m[2][block_m_idx][band_m_idx] = me2f( hDirAC->direction_vector_m_fx[2][block_m_idx][band_m_idx], hDirAC->direction_vector_m_exp[block_m_idx] ); + } + } + } + const int N_bands = hDirAC->hConfig->nbands; + for ( int i_sec = 0; i_sec < NUM_ANA_SECTORS; i_sec++ ) + { + for ( int i_band = 0; i_band < IVAS_MAX_NUM_BANDS; i_band++ ) + { + hDirAC->sec_I_vec_smth_x[i_sec][i_band] = me2f( hDirAC->sec_I_vec_smth_x_fx[i_sec][i_band], hDirAC->sec_I_vec_smth_x_exp[i_sec][i_band] ); + hDirAC->sec_I_vec_smth_y[i_sec][i_band] = me2f( hDirAC->sec_I_vec_smth_y_fx[i_sec][i_band], hDirAC->sec_I_vec_smth_y_exp[i_sec][i_band] ); + hDirAC->sec_I_vec_smth_z[i_sec][i_band] = me2f( hDirAC->sec_I_vec_smth_z_fx[i_sec][i_band], hDirAC->sec_I_vec_smth_z_exp[i_sec][i_band] ); + hDirAC->azi_prev[i_sec * N_bands + i_band] = fix_to_float( hDirAC->azi_prev_fx[i_sec * N_bands + i_band], Q23 ); + hDirAC->ele_prev[i_sec * N_bands + i_band] = fix_to_float( hDirAC->ele_prev_fx[i_sec * N_bands + i_band], Q23 ); + } + for ( int i_band = hDirAC->hConfig->enc_param_start_band; i_band < N_bands; i_band++ ) + { + hDirAC->energy_smth[i_sec][i_band] = me2f( hDirAC->energy_smth_fx[i_sec][i_band], hDirAC->energy_smth_exp[i_sec][i_band] ); + } + } + for ( band_m_idx = 0; band_m_idx < hDirAC->hConfig->nbands; band_m_idx++ ) + { + hDirAC->diffuseness_m[band_m_idx] = me2f( hDirAC->diffuseness_m_fx[band_m_idx], hDirAC->diffuseness_m_exp[band_m_idx] ); + me2f_buf( hQMetaData->q_direction->band_data[band_m_idx].energy_ratio_fx, 1, hQMetaData->q_direction->band_data[band_m_idx].energy_ratio, hQMetaData->q_direction->cfg.nblocks ); + } + for ( i = 0; i < DIRAC_NUM_DIMS; i++ ) + { + for ( j = 0; j < hDirAC->no_col_avg_diff; j++ ) + { + for ( int k = 0; k < N_bands; k++ ) + { + hDirAC->buffer_intensity_real[i][j][k] = me2f( hDirAC->buffer_intensity_real_fx[i][j][k], 31 - hDirAC->buffer_intensity_real_q[i][j][k] ); + } + } + } + for ( i = 0; i < hDirAC->hConfig->nbands; i++ ) + { + for ( j = 0; j < hDirAC->no_col_avg_diff; j++ ) + { + hDirAC->buffer_energy[i + j * hDirAC->hConfig->nbands] = me2f( hDirAC->buffer_energy_fx[i + j * hDirAC->hConfig->nbands], 31 - hDirAC->buffer_energy_q[i + j * hDirAC->hConfig->nbands] ); + } + } +#endif + if ( hQMetaData->q_direction->cfg.nbands > 0 ) { @@ -1400,9 +1575,10 @@ void ivas_dirac_param_est_enc( DIRAC_ENC_HANDLE hDirAC, IVAS_QDIRECTION *q_direction, const UWord8 useLowerRes, - float *data_f[], - float **pp_fr_real, - float **pp_fr_imag, + Word32 *data_f_fx[], + Word32 **pp_fr_real_fx, + Word32 **pp_fr_imag_fx, + Word16 pp_fr_q, const Word16 input_frame, const IVAS_FORMAT ivas_format, const Word16 hodirac_flag, @@ -1410,116 +1586,31 @@ void ivas_dirac_param_est_enc( Word16 *mono_frame_count, Word16 *dirac_mono_flag ) { -#ifdef IVAS_FLOAT_FIXED - Word32 *data_f_fx[DIRAC_MAX_ANA_CHANS]; - Word32 **pp_fr_real_fx; - Word32 **pp_fr_imag_fx; -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - /* Assign memory */ - Word16 nblocks = useLowerRes ? 1 : MAX_PARAM_SPATIAL_SUBFRAMES; - hDirAC->direction_vector_m_fx[0] = (Word32 **) malloc( nblocks * sizeof( Word32 * ) ); - hDirAC->direction_vector_m_fx[1] = (Word32 **) malloc( nblocks * sizeof( Word32 * ) ); - hDirAC->direction_vector_m_fx[2] = (Word32 **) malloc( nblocks * sizeof( Word32 * ) ); - for ( int block_m_idx = 0; block_m_idx < nblocks; block_m_idx++ ) - { - hDirAC->direction_vector_m_fx[0][block_m_idx] = (Word32 *) malloc( hDirAC->hConfig->nbands * sizeof( Word32 ) ); - hDirAC->direction_vector_m_fx[1][block_m_idx] = (Word32 *) malloc( hDirAC->hConfig->nbands * sizeof( Word32 ) ); - hDirAC->direction_vector_m_fx[2][block_m_idx] = (Word32 *) malloc( hDirAC->hConfig->nbands * sizeof( Word32 ) ); - } - - /* Find Q-factor */ - Word16 pcm_q; - Word16 pp_fr_q; - float max_val = 0; - for ( int i = 0; i < nchan_fb_in; i++ ) - { - for ( int j = 0; j < input_frame; j++ ) - { - max_val = max( max_val, (float) fabs( data_f[i][j] ) ); - } - } - pcm_q = Q_factor_L( max_val ); - - max_val = 0; - for ( int i = 0; i < nchan_fb_in; i++ ) - { - for ( int j = 0; j < input_frame; j++ ) - { - max_val = max( max_val, (float) fabs( pp_fr_real[i][j] ) ); - max_val = max( max_val, (float) fabs( pp_fr_imag[i][j] ) ); - } - } - pp_fr_q = Q_factor_L( max_val ); - - /* Float to fixed */ - pp_fr_real_fx = (Word32 **) calloc( nchan_fb_in, sizeof( Word32 * ) ); - pp_fr_imag_fx = (Word32 **) calloc( nchan_fb_in, sizeof( Word32 * ) ); - for ( int i = 0; i < nchan_fb_in; i++ ) - { - data_f_fx[i] = (Word32 *) calloc( input_frame, sizeof( Word32 ) ); - pp_fr_real_fx[i] = (Word32 *) calloc( input_frame, sizeof( Word32 ) ); - pp_fr_imag_fx[i] = (Word32 *) calloc( input_frame, sizeof( Word32 ) ); - for ( int j = 0; j < input_frame; j++ ) - { - data_f_fx[i][j] = float_to_fix( data_f[i][j], pcm_q ); - pp_fr_real_fx[i][j] = float_to_fix( pp_fr_real[i][j], pp_fr_q ); - pp_fr_imag_fx[i][j] = float_to_fix( pp_fr_imag[i][j], pp_fr_q ); - } - } -#endif - - Word16 i, d, ts, index, l_ts, num_freq_bands; + Word16 i, j, k, d, ts, index, l_ts, num_freq_bands; Word16 band_m_idx, block_m_idx; - float dir_v[DIRAC_NUM_DIMS]; -#ifdef IVAS_FLOAT_FIXED Word32 dir_v_fx[DIRAC_NUM_DIMS]; -#endif - float *pcm_in[DIRAC_MAX_ANA_CHANS]; - float Cldfb_RealBuffer[DIRAC_MAX_ANA_CHANS][DIRAC_NO_FB_BANDS_MAX]; - float Cldfb_ImagBuffer[DIRAC_MAX_ANA_CHANS][DIRAC_NO_FB_BANDS_MAX]; -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - for ( i = 0; i < DIRAC_MAX_ANA_CHANS; i++ ) - { - set_zero( Cldfb_RealBuffer[i], DIRAC_NO_FB_BANDS_MAX ); - set_zero( Cldfb_ImagBuffer[i], DIRAC_NO_FB_BANDS_MAX ); - } -#endif - float *p_Cldfb_RealBuffer[DIRAC_MAX_ANA_CHANS]; - float *p_Cldfb_ImagBuffer[DIRAC_MAX_ANA_CHANS]; Word32 *pcm_in_fx[DIRAC_MAX_ANA_CHANS]; Word32 Cldfb_RealBuffer_fx[DIRAC_MAX_ANA_CHANS][DIRAC_NO_FB_BANDS_MAX]; Word32 Cldfb_ImagBuffer_fx[DIRAC_MAX_ANA_CHANS][DIRAC_NO_FB_BANDS_MAX]; Word32 *p_Cldfb_RealBuffer_fx[DIRAC_MAX_ANA_CHANS]; Word32 *p_Cldfb_ImagBuffer_fx[DIRAC_MAX_ANA_CHANS]; Word16 cldfb_q; - float intensity_real[DIRAC_NUM_DIMS][DIRAC_MAX_NBANDS]; -#ifdef IVAS_FLOAT_FIXED Word32 intensity_real_fx[DIRAC_NUM_DIMS][DIRAC_MAX_NBANDS]; - Word16 intensity_real_q = 0; + Word16 intensity_real_q; Word32 direction_vector_fx[DIRAC_NUM_DIMS][DIRAC_MAX_NBANDS]; - Word16 direction_vector_q = 0; + Word16 direction_vector_q; Word32 diffuseness_vector_fx[DIRAC_MAX_NBANDS]; - Word16 diffuseness_vector_q = 0; - move16(); - move16(); - move16(); -#endif - float direction_vector[DIRAC_NUM_DIMS][DIRAC_MAX_NBANDS]; - float diffuseness_vector[DIRAC_MAX_NBANDS]; - float renormalization_factor[DIRAC_MAX_NBANDS]; - float renormalization_factor_diff[DIRAC_MAX_NBANDS]; + Word16 diffuseness_vector_q; Word32 renormalization_factor_fx[DIRAC_MAX_NBANDS]; + Word16 renormalization_factor_exp; Word32 renormalization_factor_diff_fx[DIRAC_MAX_NBANDS]; - float norm_tmp; + Word16 renormalization_factor_diff_exp[DIRAC_MAX_NBANDS]; + Word32 norm_tmp_fx; + Word16 norm_tmp_exp; Word16 mrange[2]; Word16 num_blocks; - float reference_power[CLDFB_NO_COL_MAX][DIRAC_NO_FB_BANDS_MAX]; Word32 reference_power_fx[CLDFB_NO_COL_MAX][DIRAC_NO_FB_BANDS_MAX]; Word16 reference_power_exp; - float azi_secs[2 * DIRAC_MAX_ANA_CHANS * DIRAC_MAX_NBANDS]; - float ele_secs[2 * DIRAC_MAX_ANA_CHANS * DIRAC_MAX_NBANDS]; - float diff_secs[2 * DIRAC_MAX_ANA_CHANS * DIRAC_MAX_NBANDS]; - float ene_secs[2 * DIRAC_MAX_ANA_CHANS * DIRAC_MAX_NBANDS]; Word32 azi_secs_fx[2 * DIRAC_MAX_ANA_CHANS * DIRAC_MAX_NBANDS]; Word32 ele_secs_fx[2 * DIRAC_MAX_ANA_CHANS * DIRAC_MAX_NBANDS]; Word32 diff_secs_fx[2 * DIRAC_MAX_ANA_CHANS * DIRAC_MAX_NBANDS]; @@ -1534,6 +1625,12 @@ void ivas_dirac_param_est_enc( /* Initialization */ cldfb_q = 0; move16(); + intensity_real_q = 0; + move16(); + direction_vector_q = 0; + move16(); + diffuseness_vector_q = 0; + move16(); l_ts = idiv1616( input_frame, MAX_PARAM_SPATIAL_SUBFRAMES ); IF( useLowerRes ) @@ -1553,7 +1650,11 @@ void ivas_dirac_param_est_enc( /* Need to initialize renormalization_factors, direction_m and diffuseness_m */ set_zero_fx( hDirAC->diffuseness_m_fx, hDirAC->hConfig->nbands ); + set16_zero_fx( hDirAC->diffuseness_m_exp, hDirAC->hConfig->nbands ); set_zero_fx( renormalization_factor_diff_fx, hDirAC->hConfig->nbands ); + set16_zero_fx( renormalization_factor_diff_exp, hDirAC->hConfig->nbands ); + reference_power_exp = 0; + move16(); set_zero_fx( azi_secs_fx, 2 * DIRAC_MAX_ANA_CHANS * DIRAC_MAX_NBANDS ); set_zero_fx( ele_secs_fx, 2 * DIRAC_MAX_ANA_CHANS * DIRAC_MAX_NBANDS ); @@ -1563,168 +1664,45 @@ void ivas_dirac_param_est_enc( set16_zero_fx( ene_secs_exp, 2 * DIRAC_MAX_ANA_CHANS * DIRAC_MAX_NBANDS ); /* Copy current frame to memory for delay compensation */ -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - /* assign memory */ - for ( i = 0; i < nchan_fb_in; i++ ) - { - pcm_in[i] = data_f[i]; - p_Cldfb_RealBuffer[i] = &Cldfb_RealBuffer[i][0]; - p_Cldfb_ImagBuffer[i] = &Cldfb_ImagBuffer[i][0]; - } -#endif FOR( i = 0; i < nchan_fb_in; i++ ) { pcm_in_fx[i] = data_f_fx[i]; p_Cldfb_RealBuffer_fx[i] = &Cldfb_RealBuffer_fx[i][0]; p_Cldfb_ImagBuffer_fx[i] = &Cldfb_ImagBuffer_fx[i][0]; } -#if 1 - /* using void temporarily to avoid null */ - (void) p_Cldfb_RealBuffer_fx; - (void) p_Cldfb_ImagBuffer_fx; - (void) p_Cldfb_RealBuffer; - (void) p_Cldfb_ImagBuffer; - (void) pcm_in_fx; - (void) pcm_in; -#endif - -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - /* Fixed to float */ - fixedToFloat_arrL( azi_secs_fx, azi_secs, 0, 2 * DIRAC_MAX_ANA_CHANS * DIRAC_MAX_NBANDS ); - fixedToFloat_arrL( ele_secs_fx, ele_secs, 0, 2 * DIRAC_MAX_ANA_CHANS * DIRAC_MAX_NBANDS ); - fixedToFloat_arrL( diff_secs_fx, diff_secs, 0, 2 * DIRAC_MAX_ANA_CHANS * DIRAC_MAX_NBANDS ); - fixedToFloat_arrL( ene_secs_fx, ene_secs, 0, 2 * DIRAC_MAX_ANA_CHANS * DIRAC_MAX_NBANDS ); - - fixedToFloat_arrL( hDirAC->diffuseness_m_fx, hDirAC->diffuseness_m, 0, hDirAC->hConfig->nbands ); - fixedToFloat_arrL( renormalization_factor_diff_fx, renormalization_factor_diff, 0, hDirAC->hConfig->nbands ); -#endif - -#else - int16_t i, d, ts, index, l_ts, num_freq_bands; - int16_t band_m_idx, block_m_idx; - float dir_v[DIRAC_NUM_DIMS]; - float *pcm_in[DIRAC_MAX_ANA_CHANS]; - float Cldfb_RealBuffer[DIRAC_MAX_ANA_CHANS][DIRAC_NO_FB_BANDS_MAX]; - float Cldfb_ImagBuffer[DIRAC_MAX_ANA_CHANS][DIRAC_NO_FB_BANDS_MAX]; - float *p_Cldfb_RealBuffer[DIRAC_MAX_ANA_CHANS]; - float *p_Cldfb_ImagBuffer[DIRAC_MAX_ANA_CHANS]; - float intensity_real[DIRAC_NUM_DIMS][DIRAC_MAX_NBANDS]; - float direction_vector[DIRAC_NUM_DIMS][DIRAC_MAX_NBANDS]; - float diffuseness_vector[DIRAC_MAX_NBANDS]; - float renormalization_factor[DIRAC_MAX_NBANDS]; - float renormalization_factor_diff[DIRAC_MAX_NBANDS]; - float norm_tmp; - int16_t mrange[2]; - int16_t num_blocks; - float reference_power[CLDFB_NO_COL_MAX][DIRAC_NO_FB_BANDS_MAX]; - float azi_secs[2 * DIRAC_MAX_ANA_CHANS * DIRAC_MAX_NBANDS]; - float ele_secs[2 * DIRAC_MAX_ANA_CHANS * DIRAC_MAX_NBANDS]; - float diff_secs[2 * DIRAC_MAX_ANA_CHANS * DIRAC_MAX_NBANDS]; - float ene_secs[2 * DIRAC_MAX_ANA_CHANS * DIRAC_MAX_NBANDS]; - - push_wmops( "dirac_enc_param_est" ); - num_freq_bands = hDirAC->hConfig->nbands; - - /* Initialization */ - l_ts = input_frame / MAX_PARAM_SPATIAL_SUBFRAMES; - if ( useLowerRes ) - { - q_direction->cfg.nblocks = 1; - num_blocks = 1; - } - else - { - q_direction->cfg.nblocks = MAX_PARAM_SPATIAL_SUBFRAMES; - num_blocks = MAX_PARAM_SPATIAL_SUBFRAMES; - } - - /* Need to initialize renormalization_factors, direction_m and diffuseness_m */ - for ( i = 0; i < hDirAC->hConfig->nbands; i++ ) - { - renormalization_factor_diff[i] = 0; - hDirAC->diffuseness_m[i] = 0; - } - - set_zero( azi_secs, 2 * DIRAC_MAX_ANA_CHANS * DIRAC_MAX_NBANDS ); - set_zero( ele_secs, 2 * DIRAC_MAX_ANA_CHANS * DIRAC_MAX_NBANDS ); - set_zero( diff_secs, 2 * DIRAC_MAX_ANA_CHANS * DIRAC_MAX_NBANDS ); - set_zero( ene_secs, 2 * DIRAC_MAX_ANA_CHANS * DIRAC_MAX_NBANDS ); - - /* Copy current frame to memory for delay compensation */ - for ( i = 0; i < nchan_fb_in; i++ ) - { - pcm_in[i] = data_f[i]; - p_Cldfb_RealBuffer[i] = &Cldfb_RealBuffer[i][0]; - p_Cldfb_ImagBuffer[i] = &Cldfb_ImagBuffer[i][0]; - } -#endif /* ifdef IVAS_FLOAT_FIXED */ /* do processing over all CLDFB time slots */ - for ( block_m_idx = 0; block_m_idx < num_blocks; block_m_idx++ ) + FOR( block_m_idx = 0; block_m_idx < num_blocks; block_m_idx++ ) { -#ifdef IVAS_FLOAT_FIXED mrange[0] = hDirAC->block_grouping[block_m_idx]; move16(); mrange[1] = hDirAC->block_grouping[add( block_m_idx, 1 )]; move16(); set32_fx( renormalization_factor_fx, EPSILON_FX, hDirAC->hConfig->nbands ); + renormalization_factor_exp = 0; + move16(); set_zero_fx( hDirAC->direction_vector_m_fx[0][block_m_idx], hDirAC->hConfig->nbands ); set_zero_fx( hDirAC->direction_vector_m_fx[1][block_m_idx], hDirAC->hConfig->nbands ); set_zero_fx( hDirAC->direction_vector_m_fx[2][block_m_idx], hDirAC->hConfig->nbands ); + hDirAC->direction_vector_m_exp[block_m_idx] = 0; + move16(); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - set_f( renormalization_factor, EPSILON, hDirAC->hConfig->nbands ); - fixedToFloat_arrL( hDirAC->direction_vector_m_fx[0][block_m_idx], hDirAC->direction_vector_m[0][block_m_idx], 0, hDirAC->hConfig->nbands ); - fixedToFloat_arrL( hDirAC->direction_vector_m_fx[1][block_m_idx], hDirAC->direction_vector_m[1][block_m_idx], 0, hDirAC->hConfig->nbands ); - fixedToFloat_arrL( hDirAC->direction_vector_m_fx[2][block_m_idx], hDirAC->direction_vector_m[2][block_m_idx], 0, hDirAC->hConfig->nbands ); -#endif + FOR( ts = mrange[0]; ts < mrange[1]; ts++ ) + { + IF( hDirAC->hFbMixer ) + { + ivas_fb_mixer_get_windowed_fr_fx( hDirAC->hFbMixer, pcm_in_fx, p_Cldfb_RealBuffer_fx, p_Cldfb_ImagBuffer_fx, l_ts, l_ts, hDirAC->hFbMixer->fb_cfg->num_in_chans, 0 ); -#else - mrange[0] = hDirAC->block_grouping[block_m_idx]; - mrange[1] = hDirAC->block_grouping[block_m_idx + 1]; - - for ( band_m_idx = 0; band_m_idx < hDirAC->hConfig->nbands; band_m_idx++ ) - { - renormalization_factor[band_m_idx] = EPSILON; - hDirAC->direction_vector_m[0][block_m_idx][band_m_idx] = 0; - hDirAC->direction_vector_m[1][block_m_idx][band_m_idx] = 0; - hDirAC->direction_vector_m[2][block_m_idx][band_m_idx] = 0; - } -#endif - - for ( ts = mrange[0]; ts < mrange[1]; ts++ ) - { - if ( hDirAC->hFbMixer ) - { -#ifdef IVAS_FLOAT_FIXED - ivas_fb_mixer_get_windowed_fr_fx( hDirAC->hFbMixer, pcm_in_fx, p_Cldfb_RealBuffer_fx, p_Cldfb_ImagBuffer_fx, l_ts, l_ts, hDirAC->hFbMixer->fb_cfg->num_in_chans, 0 ); - - ivas_fb_mixer_update_prior_input_fx( hDirAC->hFbMixer, pcm_in_fx, l_ts, hDirAC->hFbMixer->fb_cfg->num_in_chans ); + ivas_fb_mixer_update_prior_input_fx( hDirAC->hFbMixer, pcm_in_fx, l_ts, hDirAC->hFbMixer->fb_cfg->num_in_chans ); FOR( i = 0; i < nchan_fb_in; i++ ) { pcm_in_fx[i] += l_ts; } -#else - ivas_fb_mixer_get_windowed_fr( hDirAC->hFbMixer, pcm_in, p_Cldfb_RealBuffer, p_Cldfb_ImagBuffer, l_ts, l_ts, hDirAC->hFbMixer->fb_cfg->num_in_chans ); - - ivas_fb_mixer_update_prior_input( hDirAC->hFbMixer, pcm_in, l_ts, hDirAC->hFbMixer->fb_cfg->num_in_chans ); - - for ( i = 0; i < nchan_fb_in; i++ ) - { - pcm_in[i] += l_ts; - } -#endif } - else + ELSE { -#ifdef IVAS_FLOAT_FIXED - for ( i = 0; i < nchan_fb_in; i++ ) - { - mvr2r( &pp_fr_real[i][ts * l_ts], Cldfb_RealBuffer[i], l_ts ); - mvr2r( &pp_fr_imag[i][ts * l_ts], Cldfb_ImagBuffer[i], l_ts ); - } FOR( i = 0; i < nchan_fb_in; i++ ) { Copy32( &pp_fr_real_fx[i][imult1616( ts, l_ts )], Cldfb_RealBuffer_fx[i], l_ts ); @@ -1732,94 +1710,31 @@ void ivas_dirac_param_est_enc( } cldfb_q = pp_fr_q; move16(); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - FOR( i = 0; i < nchan_fb_in; i++ ) - { - fixedToFloat_arrL( Cldfb_ImagBuffer_fx[i], Cldfb_ImagBuffer[i], cldfb_q, l_ts ); - fixedToFloat_arrL( Cldfb_RealBuffer_fx[i], Cldfb_RealBuffer[i], cldfb_q, l_ts ); - } -#endif -#else - for ( i = 0; i < nchan_fb_in; i++ ) - { - mvr2r( &pp_fr_real[i][ts * l_ts], Cldfb_RealBuffer[i], l_ts ); - mvr2r( &pp_fr_imag[i][ts * l_ts], Cldfb_ImagBuffer[i], l_ts ); - } -#endif - } - -#ifndef IVAS_FLOAT_FIXED - computeReferencePower_enc( - hDirAC->band_grouping, - Cldfb_RealBuffer, - Cldfb_ImagBuffer, - reference_power[ts], - hDirAC->hConfig->enc_param_start_band, - num_freq_bands, - ivas_format, - hodirac_flag ? 0 : 1, - FOA_CHANNELS, - mono_frame_count, - dirac_mono_flag ); -#else -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - Word16 Q_Cldfb = 31; - FOR( Word16 x = 0; x < FOA_CHANNELS; x++ ) - { - FOR( Word16 k = 0; k < DIRAC_NO_FB_BANDS_MAX; k++ ) - { - Q_Cldfb = s_min( Q_Cldfb, Q_factor_L( Cldfb_RealBuffer[x][k] ) ); - } - } - Word16 guard = find_guarded_bits_fx( 16 ) / 2; // Guard bits to avoid the precision loss for the reference_power - Word16 e_reference; - - FOR( Word16 k = 0; k < FOA_CHANNELS; k++ ) - { - floatToFixed_arrL( Cldfb_RealBuffer[k], Cldfb_RealBuffer_fx[k], Q_Cldfb, DIRAC_NO_FB_BANDS_MAX ); - } - - FOR( Word16 k = 0; k < FOA_CHANNELS; k++ ) - { - floatToFixed_arrL( Cldfb_ImagBuffer[k], Cldfb_ImagBuffer_fx[k], Q_Cldfb, DIRAC_NO_FB_BANDS_MAX ); - } - - FOR( Word16 x = 0; x < FOA_CHANNELS; x++ ) - { - FOR( Word16 k = 0; k < DIRAC_NO_FB_BANDS_MAX; k++ ) - { - Cldfb_RealBuffer_fx[x][k] = L_shr( Cldfb_RealBuffer_fx[x][k], guard ); - Cldfb_ImagBuffer_fx[x][k] = L_shr( Cldfb_ImagBuffer_fx[x][k], guard ); - } } - Q_Cldfb = sub( Q_Cldfb, guard ); - Word16 hodirac_flag_temp = 1; + Word16 ref_power_w = 1; + move16(); IF( hodirac_flag ) { - hodirac_flag_temp = 0; + ref_power_w = 0; + move16(); } -#endif + computeReferencePower_enc_fx_dirac( hDirAC->band_grouping, Cldfb_RealBuffer_fx, Cldfb_ImagBuffer_fx, - sub( 31, Q_Cldfb ), + sub( 31, cldfb_q ), reference_power_fx[ts], - &e_reference, + &reference_power_exp, hDirAC->hConfig->enc_param_start_band, num_freq_bands, ivas_format, - hodirac_flag_temp, + ref_power_w, FOA_CHANNELS, mono_frame_count, dirac_mono_flag ); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - fixedToFloat_arrL( reference_power_fx[ts], reference_power[ts], 31 - e_reference, DIRAC_NO_FB_BANDS_MAX ); -#endif -#endif -#ifdef IVAS_FLOAT_FIXED computeIntensityVector_enc_fx( hDirAC, Cldfb_RealBuffer_fx, @@ -1828,29 +1743,10 @@ void ivas_dirac_param_est_enc( num_freq_bands, intensity_real_fx ); - // intensity_real_q = 2 * Q_Cldfb + 1 - 32; - intensity_real_q = sub( shl( Q_Cldfb, 1 ), 31 ); - move16(); - -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - for ( i = 0; i < DIRAC_NUM_DIMS; i++ ) - { - fixedToFloat_arrL( intensity_real_fx[i], intensity_real[i], intensity_real_q, num_freq_bands ); - } -#endif -#else - computeIntensityVector_enc( - hDirAC, - Cldfb_RealBuffer, - Cldfb_ImagBuffer, - hDirAC->hConfig->enc_param_start_band, - num_freq_bands, - intensity_real ); -#endif + intensity_real_q = sub( shl( cldfb_q, 1 ), 31 ); // 2 * Q_Cldfb + 1 - 32; - if ( !hodirac_flag ) + IF( !hodirac_flag ) { -#ifdef IVAS_FLOAT_FIXED computeDirectionVectors_fixed( intensity_real_fx[0], intensity_real_fx[1], @@ -1864,153 +1760,71 @@ void ivas_dirac_param_est_enc( direction_vector_q = Q30; move16(); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - for ( i = 0; i < DIRAC_NUM_DIMS; i++ ) - { - fixedToFloat_arrL( direction_vector_fx[i], direction_vector[i], direction_vector_q, num_freq_bands ); - } -#endif -#else - computeDirectionVectors( - intensity_real[0], - intensity_real[1], - intensity_real[2], - hDirAC->hConfig->enc_param_start_band, - num_freq_bands, - direction_vector[0], - direction_vector[1], - direction_vector[2] ); -#endif } -#ifdef IVAS_FLOAT_FIXED -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS -#define MAX_NUM_INDEX_INTENSITY ( 10 ) /* NOTE: arbitrary value. need to check exact max value of "index"*/ - Word32 buffer_intensity_real_fx[DIRAC_NUM_DIMS][MAX_NUM_INDEX_INTENSITY][DIRAC_MAX_NBANDS]; - Word32 buffer_energy_fx[MAX_NUM_INDEX_INTENSITY * DIRAC_MAX_NBANDS]; - max_val = 0; - Word32 tmp32; - for ( i = 0; i < DIRAC_NUM_DIMS; i++ ) - { - float tmpf; - maximumAbs( intensity_real[i], num_freq_bands, &tmpf ); - max_val = fmaxf( max_val, tmpf ); - } - Word16 intensity_real_exp; - f2me( max_val, &tmp32, &intensity_real_exp ); - for ( i = 0; i < DIRAC_NUM_DIMS; i++ ) - { - for ( int j = 0; j < num_freq_bands; j++ ) - { - intensity_real_fx[i][j] = (Word32) ( intensity_real[i][j] * powf( 2, 31.f - intensity_real_exp ) ); - } - } - f2me_buf( reference_power[ts], reference_power_fx[ts], &reference_power_exp, num_freq_bands ); -#endif /* fill buffers of length "averaging_length" time slots for intensity and energy */ hDirAC->index_buffer_intensity = add( ( hDirAC->index_buffer_intensity % hDirAC->no_col_avg_diff ), 1 ); /* averaging_length = 32 */ move16(); index = hDirAC->index_buffer_intensity; move16(); - assert( index <= MAX_NUM_INDEX_INTENSITY ); FOR( i = 0; i < DIRAC_NUM_DIMS; i++ ) { /* only real part needed */ - Copy32( intensity_real_fx[i], &( buffer_intensity_real_fx[i][sub( index, 1 )][0] ), num_freq_bands ); + Copy32( intensity_real_fx[i], &( hDirAC->buffer_intensity_real_fx[i][index - 1][0] ), num_freq_bands ); + set16_fx( &hDirAC->buffer_intensity_real_q[i][index - 1][0], intensity_real_q, num_freq_bands ); } - Copy32( reference_power_fx[ts], &( buffer_energy_fx[imult1616( sub( index, 1 ), num_freq_bands )] ), num_freq_bands ); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + Copy32( reference_power_fx[ts], &( hDirAC->buffer_energy_fx[( index - 1 ) * num_freq_bands] ), num_freq_bands ); + set16_fx( &hDirAC->buffer_energy_q[( index - 1 ) * num_freq_bands], sub( 31, reference_power_exp ), num_freq_bands ); + + Word16 buffer_intensity_real_single_q; + buffer_intensity_real_single_q = hDirAC->buffer_intensity_real_q[0][0][0]; + move16(); FOR( i = 0; i < DIRAC_NUM_DIMS; i++ ) { - me2f_buf( &buffer_intensity_real_fx[i][index - 1][0], intensity_real_exp, &hDirAC->buffer_intensity_real[i][index - 1][0], num_freq_bands ); - } - me2f_buf( &buffer_energy_fx[( index - 1 ) * num_freq_bands], reference_power_exp, &hDirAC->buffer_energy[( index - 1 ) * num_freq_bands], num_freq_bands ); -#endif -#else - /* fill buffers of length "averaging_length" time slots for intensity and energy */ - hDirAC->index_buffer_intensity = ( hDirAC->index_buffer_intensity % hDirAC->no_col_avg_diff ) + 1; /* averaging_length = 32 */ - index = hDirAC->index_buffer_intensity; - for ( i = 0; i < DIRAC_NUM_DIMS; i++ ) - { - /* only real part needed */ - mvr2r( intensity_real[i], &( hDirAC->buffer_intensity_real[i][index - 1][0] ), num_freq_bands ); + FOR( j = 0; j < hDirAC->no_col_avg_diff; j++ ) + { + FOR( k = 0; k < num_freq_bands; k++ ) + { + buffer_intensity_real_single_q = s_min( buffer_intensity_real_single_q, hDirAC->buffer_intensity_real_q[i][j][k] ); + } + } } - mvr2r( reference_power[ts], &( hDirAC->buffer_energy[( index - 1 ) * num_freq_bands] ), num_freq_bands ); -#endif - - -#ifdef IVAS_FLOAT_FIXED -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - Word16 buffer_intensity_real_q = 0; - float max_buffer_intensity_real_val = 0; - for ( i = 0; i < hDirAC->no_col_avg_diff; i++ ) + FOR( i = 0; i < DIRAC_NUM_DIMS; i++ ) { - for ( int j = 0; j < DIRAC_NUM_DIMS; j++ ) + FOR( j = 0; j < hDirAC->no_col_avg_diff; j++ ) { - for ( int k = 0; k < num_freq_bands; k++ ) + FOR( k = 0; k < num_freq_bands; k++ ) { - max_buffer_intensity_real_val = max( max_buffer_intensity_real_val, (float) fabs( hDirAC->buffer_intensity_real[j][i][k] ) ); + hDirAC->buffer_intensity_real_fx[i][j][k] = L_shl( hDirAC->buffer_intensity_real_fx[i][j][k], sub( buffer_intensity_real_single_q, hDirAC->buffer_intensity_real_q[i][j][k] ) ); + move32(); + hDirAC->buffer_intensity_real_q[i][j][k] = buffer_intensity_real_single_q; + move16(); } } } - Word32 tmp_var = 0; - Word16 buffer_intensity_real_buff_e = 0; - f2me( (float) fabs( max_buffer_intensity_real_val ), &tmp_var, &buffer_intensity_real_buff_e ); - buffer_intensity_real_q = sub( 31, buffer_intensity_real_buff_e ); - for ( i = 0; i < hDirAC->no_col_avg_diff; i++ ) + Word16 buffer_energy_single_q; + Word16 buffer_len; + buffer_len = imult1616( DIRAC_MAX_NBANDS, hDirAC->no_col_avg_diff ); + minimum_fx( hDirAC->buffer_energy_q, buffer_len, &buffer_energy_single_q ); + FOR( i = 0; i < buffer_len; i++ ) { - for ( int j = 0; j < DIRAC_NUM_DIMS; j++ ) - { - floatToFixed_arrL( hDirAC->buffer_intensity_real[j][i], hDirAC->buffer_intensity_real_fx[j][i], buffer_intensity_real_q, num_freq_bands ); - } + hDirAC->buffer_energy_fx[i] = L_shl( hDirAC->buffer_energy_fx[i], sub( buffer_energy_single_q, hDirAC->buffer_energy_q[i] ) ); + move32(); + hDirAC->buffer_energy_q[i] = buffer_energy_single_q; + move16(); } - Word16 buffer_energy_e = 0; - Word16 buffer_energy_q = 0; - move16(); - move16(); - f2me_buf( hDirAC->buffer_energy, hDirAC->buffer_energy_fx, &buffer_energy_e, DIRAC_MAX_NBANDS * hDirAC->no_col_avg_diff ); - buffer_energy_q = sub( 31, buffer_energy_e ); -#endif - Word16 *buffer_energy_buff_q = (Word16 *) malloc( DIRAC_MAX_NBANDS * hDirAC->no_col_avg_diff * sizeof( Word16 ) ); - Word16 *buffer_intensity_real_buff_q = (Word16 *) malloc( DIRAC_MAX_NBANDS * hDirAC->no_col_avg_diff * sizeof( Word16 ) ); - set16_fx( buffer_energy_buff_q, buffer_energy_q, DIRAC_MAX_NBANDS * hDirAC->no_col_avg_diff ); - set16_fx( buffer_intensity_real_buff_q, buffer_intensity_real_q, DIRAC_MAX_NBANDS * hDirAC->no_col_avg_diff ); + Word16 tmp_q_buffer_for_intensity[DIRAC_MAX_NBANDS * DIRAC_NO_COL_AVG_DIFF]; + Word16 tmp_q_buffer_for_energy[DIRAC_MAX_NBANDS * DIRAC_NO_COL_AVG_DIFF]; - computeDiffuseness_mdft_fx( hDirAC->buffer_intensity_real_fx, hDirAC->buffer_energy_fx, num_freq_bands, hDirAC->no_col_avg_diff, diffuseness_vector_fx, buffer_intensity_real_buff_q, buffer_energy_buff_q, &diffuseness_vector_q ); + set16_fx( tmp_q_buffer_for_intensity, buffer_intensity_real_single_q, buffer_len ); + set16_fx( tmp_q_buffer_for_energy, buffer_energy_single_q, buffer_len ); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - fixedToFloat_arrL( diffuseness_vector_fx, diffuseness_vector, diffuseness_vector_q, num_freq_bands ); -#endif - free( buffer_energy_buff_q ); - buffer_energy_buff_q = NULL; - free( buffer_intensity_real_buff_q ); - buffer_intensity_real_buff_q = NULL; -#else - computeDiffuseness_mdft( hDirAC->buffer_intensity_real, hDirAC->buffer_energy, num_freq_bands, hDirAC->no_col_avg_diff, diffuseness_vector ); -#endif + computeDiffuseness_mdft_fx( hDirAC->buffer_intensity_real_fx, hDirAC->buffer_energy_fx, num_freq_bands, hDirAC->no_col_avg_diff, diffuseness_vector_fx, tmp_q_buffer_for_intensity, tmp_q_buffer_for_energy, &diffuseness_vector_q ); - if ( hodirac_flag ) + IF( hodirac_flag ) { -#ifdef IVAS_FLOAT_FIXED - -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - for ( i = 0; i < NUM_ANA_SECTORS; i++ ) - { - for ( int j = 0; j < IVAS_MAX_NUM_BANDS; j++ ) - { - f2me( hDirAC->sec_I_vec_smth_x[i][j], &hDirAC->sec_I_vec_smth_x_fx[i][j], &hDirAC->sec_I_vec_smth_x_exp[i][j] ); - f2me( hDirAC->sec_I_vec_smth_y[i][j], &hDirAC->sec_I_vec_smth_y_fx[i][j], &hDirAC->sec_I_vec_smth_y_exp[i][j] ); - f2me( hDirAC->sec_I_vec_smth_z[i][j], &hDirAC->sec_I_vec_smth_z_fx[i][j], &hDirAC->sec_I_vec_smth_z_exp[i][j] ); - } - } - for ( i = 0; i < NUM_ANA_SECTORS * IVAS_MAX_NUM_BANDS; i++ ) - { - hDirAC->azi_prev_fx[i] = float_to_fix( hDirAC->azi_prev[i], Q23 ); - hDirAC->ele_prev_fx[i] = float_to_fix( hDirAC->ele_prev[i], Q23 ); - } -#endif calculate_hodirac_sector_parameters_fx( hDirAC, Cldfb_RealBuffer_fx, @@ -2026,189 +1840,188 @@ void ivas_dirac_param_est_enc( diff_secs_exp, ene_secs_fx, ene_secs_exp ); - -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - const int N_bands = hDirAC->hConfig->nbands; - for ( int i_sec = 0; i_sec < NUM_ANA_SECTORS; i_sec++ ) - { - for ( int i_band = hDirAC->hConfig->enc_param_start_band; i_band < N_bands; i_band++ ) - { - hDirAC->azi_prev[i_sec * N_bands + i_band] = fix_to_float( hDirAC->azi_prev_fx[i_sec * N_bands + i_band], Q23 ); - hDirAC->ele_prev[i_sec * N_bands + i_band] = fix_to_float( hDirAC->ele_prev_fx[i_sec * N_bands + i_band], Q23 ); - azi_secs[i_sec * N_bands + i_band] = fix_to_float( azi_secs_fx[i_sec * N_bands + i_band], Q23 ); - ele_secs[i_sec * N_bands + i_band] = fix_to_float( ele_secs_fx[i_sec * N_bands + i_band], Q23 ); - ene_secs[i_sec * N_bands + i_band] = me2f( ene_secs_fx[i_sec * N_bands + i_band], ene_secs_exp[i_sec * N_bands + i_band] ); - hDirAC->sec_I_vec_smth_x[i_sec][i_band] = me2f( hDirAC->sec_I_vec_smth_x_fx[i_sec][i_band], hDirAC->sec_I_vec_smth_x_exp[i_sec][i_band] ); - hDirAC->sec_I_vec_smth_y[i_sec][i_band] = me2f( hDirAC->sec_I_vec_smth_y_fx[i_sec][i_band], hDirAC->sec_I_vec_smth_y_exp[i_sec][i_band] ); - hDirAC->sec_I_vec_smth_z[i_sec][i_band] = me2f( hDirAC->sec_I_vec_smth_z_fx[i_sec][i_band], hDirAC->sec_I_vec_smth_z_exp[i_sec][i_band] ); - hDirAC->energy_smth[i_sec][i_band] = me2f( hDirAC->energy_smth_fx[i_sec][i_band], hDirAC->energy_smth_exp[i_sec][i_band] ); - diff_secs[i_sec * N_bands + i_band] = me2f( diff_secs_fx[i_sec * N_bands + i_band], diff_secs_exp[i_sec * N_bands + i_band] ); - } - } -#endif - -#else - calculate_hodirac_sector_parameters( - hDirAC, - Cldfb_RealBuffer, - Cldfb_ImagBuffer, - 0.20f, - hDirAC->band_grouping, - hDirAC->hConfig->nbands, - hDirAC->hConfig->enc_param_start_band, - azi_secs, - ele_secs, - diff_secs, - ene_secs ); -#endif } - if ( hodirac_flag ) + const Word16 gbits = 4; // 4 guard bits + move16(); + IF( hodirac_flag ) { - for ( band_m_idx = 0; band_m_idx < hDirAC->hConfig->nbands; band_m_idx++ ) + FOR( band_m_idx = 0; band_m_idx < hDirAC->hConfig->nbands; band_m_idx++ ) { - hDirAC->diffuseness_m[band_m_idx] += reference_power[ts][band_m_idx] * diffuseness_vector[band_m_idx]; - renormalization_factor_diff[band_m_idx] += reference_power[ts][band_m_idx]; + Word32 tmp_diff = L_shr( diffuseness_vector_fx[band_m_idx], sub( diffuseness_vector_q, 30 ) ); // diffueseness_vector_q -> Q30 + hDirAC->diffuseness_m_fx[band_m_idx] = BASOP_Util_Add_Mant32Exp( hDirAC->diffuseness_m_fx[band_m_idx], hDirAC->diffuseness_m_exp[band_m_idx], + Mpy_32_32( reference_power_fx[ts][band_m_idx], tmp_diff ), add( reference_power_exp, 1 ), &hDirAC->diffuseness_m_exp[band_m_idx] ); + move32(); + renormalization_factor_diff_fx[band_m_idx] = BASOP_Util_Add_Mant32Exp( renormalization_factor_diff_fx[band_m_idx], renormalization_factor_diff_exp[band_m_idx], reference_power_fx[ts][band_m_idx], reference_power_exp, &renormalization_factor_diff_exp[band_m_idx] ); + move32(); } } - else + ELSE { - for ( band_m_idx = 0; band_m_idx < hDirAC->hConfig->nbands; band_m_idx++ ) + FOR( band_m_idx = 0; band_m_idx < hDirAC->hConfig->nbands; band_m_idx++ ) { - norm_tmp = reference_power[ts][band_m_idx] * ( 1 - diffuseness_vector[band_m_idx] ); - - hDirAC->direction_vector_m[0][block_m_idx][band_m_idx] += norm_tmp * direction_vector[0][band_m_idx]; - hDirAC->direction_vector_m[1][block_m_idx][band_m_idx] += norm_tmp * direction_vector[1][band_m_idx]; - hDirAC->direction_vector_m[2][block_m_idx][band_m_idx] += norm_tmp * direction_vector[2][band_m_idx]; - renormalization_factor[band_m_idx] += norm_tmp; + Word32 tmp_diff = L_shr( diffuseness_vector_fx[band_m_idx], sub( diffuseness_vector_q, 30 ) ); // diffueseness_vector_q -> Q30 + norm_tmp_fx = Mpy_32_32( reference_power_fx[ts][band_m_idx], L_sub( ONE_IN_Q30, tmp_diff ) ); - hDirAC->diffuseness_m[band_m_idx] += reference_power[ts][band_m_idx] * diffuseness_vector[band_m_idx]; - renormalization_factor_diff[band_m_idx] += reference_power[ts][band_m_idx]; + hDirAC->direction_vector_m_fx[0][block_m_idx][band_m_idx] = L_add( hDirAC->direction_vector_m_fx[0][block_m_idx][band_m_idx], L_shr( Mpy_32_32( norm_tmp_fx, direction_vector_fx[0][band_m_idx] ), gbits ) ); + move32(); + hDirAC->direction_vector_m_fx[1][block_m_idx][band_m_idx] = L_add( hDirAC->direction_vector_m_fx[1][block_m_idx][band_m_idx], L_shr( Mpy_32_32( norm_tmp_fx, direction_vector_fx[1][band_m_idx] ), gbits ) ); + move32(); + hDirAC->direction_vector_m_fx[2][block_m_idx][band_m_idx] = L_add( hDirAC->direction_vector_m_fx[2][block_m_idx][band_m_idx], L_shr( Mpy_32_32( norm_tmp_fx, direction_vector_fx[2][band_m_idx] ), gbits ) ); + move32(); + renormalization_factor_fx[band_m_idx] = L_add( renormalization_factor_fx[band_m_idx], L_shr( norm_tmp_fx, gbits ) ); + move32(); + hDirAC->diffuseness_m_fx[band_m_idx] = BASOP_Util_Add_Mant32Exp( hDirAC->diffuseness_m_fx[band_m_idx], hDirAC->diffuseness_m_exp[band_m_idx], + Mpy_32_32( reference_power_fx[ts][band_m_idx], tmp_diff ), add( reference_power_exp, 1 ), &hDirAC->diffuseness_m_exp[band_m_idx] ); + move32(); + renormalization_factor_diff_fx[band_m_idx] = BASOP_Util_Add_Mant32Exp( renormalization_factor_diff_fx[band_m_idx], renormalization_factor_diff_exp[band_m_idx], + reference_power_fx[ts][band_m_idx], reference_power_exp, &renormalization_factor_diff_exp[band_m_idx] ); + move32(); } + norm_tmp_exp = add( reference_power_exp, 1 ); + hDirAC->direction_vector_m_exp[block_m_idx] = add( norm_tmp_exp, add( sub( 31, direction_vector_q ), gbits ) ); + move32(); + renormalization_factor_exp = add( norm_tmp_exp, gbits ); } } - if ( !hodirac_flag ) + IF( !hodirac_flag ) { - for ( band_m_idx = 0; band_m_idx < hDirAC->hConfig->nbands; band_m_idx++ ) + FOR( band_m_idx = 0; band_m_idx < hDirAC->hConfig->nbands; band_m_idx++ ) { - renormalization_factor[band_m_idx] = EPSILON; - for ( d = 0; d < DIRAC_NUM_DIMS; d++ ) - { - renormalization_factor[band_m_idx] += ( hDirAC->direction_vector_m[d][block_m_idx][band_m_idx] * hDirAC->direction_vector_m[d][block_m_idx][band_m_idx] ); - } - renormalization_factor[band_m_idx] = sqrtf( renormalization_factor[band_m_idx] ); + renormalization_factor_fx[band_m_idx] = EPSILON_FX; + move32(); + renormalization_factor_fx[band_m_idx] = L_add( renormalization_factor_fx[band_m_idx], Mpy_32_32( hDirAC->direction_vector_m_fx[0][block_m_idx][band_m_idx], hDirAC->direction_vector_m_fx[0][block_m_idx][band_m_idx] ) ); + move32(); + renormalization_factor_fx[band_m_idx] = L_add( renormalization_factor_fx[band_m_idx], Mpy_32_32( hDirAC->direction_vector_m_fx[1][block_m_idx][band_m_idx], hDirAC->direction_vector_m_fx[1][block_m_idx][band_m_idx] ) ); + move32(); + renormalization_factor_fx[band_m_idx] = L_add( renormalization_factor_fx[band_m_idx], Mpy_32_32( hDirAC->direction_vector_m_fx[2][block_m_idx][band_m_idx], hDirAC->direction_vector_m_fx[2][block_m_idx][band_m_idx] ) ); + move32(); + renormalization_factor_exp = shl( hDirAC->direction_vector_m_exp[block_m_idx], 1 ); // 2 * direction_vector_m_exp + renormalization_factor_fx[band_m_idx] = Sqrt32( renormalization_factor_fx[band_m_idx], &renormalization_factor_exp ); + move32(); - if ( renormalization_factor[band_m_idx] > EPSILON ) + IF( GT_32( renormalization_factor_fx[band_m_idx], EPSILON_FX ) ) { - hDirAC->direction_vector_m[0][block_m_idx][band_m_idx] /= renormalization_factor[band_m_idx]; - hDirAC->direction_vector_m[1][block_m_idx][band_m_idx] /= renormalization_factor[band_m_idx]; - hDirAC->direction_vector_m[2][block_m_idx][band_m_idx] /= renormalization_factor[band_m_idx]; + Word16 tmp_e; + Word32 tmp32; + + tmp32 = hDirAC->direction_vector_m_fx[0][block_m_idx][band_m_idx]; + move32(); + tmp32 = L_deposit_h( BASOP_Util_Divide3232_Scale( tmp32, renormalization_factor_fx[band_m_idx], &tmp_e ) ); + tmp_e = add( tmp_e, sub( hDirAC->direction_vector_m_exp[block_m_idx], renormalization_factor_exp ) ); + hDirAC->direction_vector_m_fx[0][block_m_idx][band_m_idx] = L_shr( tmp32, sub( 1, tmp_e ) ); // Q30 + move32(); + + tmp32 = hDirAC->direction_vector_m_fx[1][block_m_idx][band_m_idx]; + move32(); + tmp32 = L_deposit_h( BASOP_Util_Divide3232_Scale( tmp32, renormalization_factor_fx[band_m_idx], &tmp_e ) ); + tmp_e = add( tmp_e, sub( hDirAC->direction_vector_m_exp[block_m_idx], renormalization_factor_exp ) ); + hDirAC->direction_vector_m_fx[1][block_m_idx][band_m_idx] = L_shr( tmp32, sub( 1, tmp_e ) ); // Q30 + move32(); + + tmp32 = hDirAC->direction_vector_m_fx[2][block_m_idx][band_m_idx]; + move32(); + tmp32 = L_deposit_h( BASOP_Util_Divide3232_Scale( tmp32, renormalization_factor_fx[band_m_idx], &tmp_e ) ); + tmp_e = add( tmp_e, sub( hDirAC->direction_vector_m_exp[block_m_idx], renormalization_factor_exp ) ); + hDirAC->direction_vector_m_fx[2][block_m_idx][band_m_idx] = L_shr( tmp32, sub( 1, tmp_e ) ); // Q30 + move32(); } - else + ELSE { - hDirAC->direction_vector_m[0][block_m_idx][band_m_idx] = 1; - hDirAC->direction_vector_m[1][block_m_idx][band_m_idx] = 0; - hDirAC->direction_vector_m[2][block_m_idx][band_m_idx] = 0; + hDirAC->direction_vector_m_fx[0][block_m_idx][band_m_idx] = ONE_IN_Q30; + move32(); + hDirAC->direction_vector_m_fx[1][block_m_idx][band_m_idx] = 0; + move32(); + hDirAC->direction_vector_m_fx[2][block_m_idx][band_m_idx] = 0; + move32(); } + hDirAC->direction_vector_m_exp[block_m_idx] = 1; + move16(); /* save the elevation and azimuth values to be used later by the ivas_dirac_QuantizeParameters function */ - for ( d = 0; d < DIRAC_NUM_DIMS; d++ ) + FOR( d = 0; d < DIRAC_NUM_DIMS; d++ ) { - dir_v[d] = hDirAC->direction_vector_m[d][block_m_idx][band_m_idx]; + dir_v_fx[d] = hDirAC->direction_vector_m_fx[d][block_m_idx][band_m_idx]; // Q30 + move32(); } -#ifdef IVAS_FLOAT_FIXED -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - Word16 q_dir_e = 0; - f2me_buf( dir_v, dir_v_fx, &q_dir_e, 3 ); Scale_sig32( dir_v_fx, 3, -1 ); -#endif - ivas_qmetadata_direction_vector_to_azimuth_elevation_fx( dir_v_fx, - Q31 - q_dir_e, + Q30, &q_direction->band_data[band_m_idx].azimuth_fx[block_m_idx], &q_direction->band_data[band_m_idx].elevation_fx[block_m_idx] ); - -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - q_direction->band_data[band_m_idx].azimuth[block_m_idx] = fixedToFloat( q_direction->band_data[band_m_idx].azimuth_fx[block_m_idx], Q22 ); - q_direction->band_data[band_m_idx].elevation[block_m_idx] = fixedToFloat( q_direction->band_data[band_m_idx].elevation_fx[block_m_idx], Q22 ); -#endif -#else - ivas_qmetadata_direction_vector_to_azimuth_elevation( - dir_v, - &q_direction->band_data[band_m_idx].azimuth[block_m_idx], - &q_direction->band_data[band_m_idx].elevation[block_m_idx] ); -#endif } } /* Sectors */ - if ( hodirac_flag ) + IF( hodirac_flag ) { - for ( band_m_idx = 0; band_m_idx < hDirAC->hConfig->nbands; band_m_idx++ ) + FOR( band_m_idx = 0; band_m_idx < hDirAC->hConfig->nbands; band_m_idx++ ) { - q_direction->band_data[band_m_idx].azimuth[block_m_idx] = azi_secs[band_m_idx]; - q_direction->band_data[band_m_idx].elevation[block_m_idx] = ele_secs[band_m_idx]; - // q_direction->band_data[band_m_idx].energy_ratio[block_m_idx] = 1.f - diffuseness_vector[band_m_idx]; // set later + q_direction->band_data[band_m_idx].azimuth_fx[block_m_idx] = L_shr( azi_secs_fx[band_m_idx], 1 ); // Q23 -> Q22 + move32(); + q_direction->band_data[band_m_idx].elevation_fx[block_m_idx] = L_shr( ele_secs_fx[band_m_idx], 1 ); // Q23 -> Q22 + move32(); - q_direction[1].band_data[band_m_idx].azimuth[block_m_idx] = azi_secs[num_freq_bands + band_m_idx]; - q_direction[1].band_data[band_m_idx].elevation[block_m_idx] = ele_secs[num_freq_bands + band_m_idx]; - q_direction[1].band_data[band_m_idx].energy_ratio[block_m_idx] = ( 1.f - diff_secs[band_m_idx] ) / ( ( 1.f - diff_secs[band_m_idx] ) + ( 1.f - diff_secs[num_freq_bands + band_m_idx] ) + EPSILON ); - } - } - } + q_direction[1].band_data[band_m_idx].azimuth_fx[block_m_idx] = L_shr( azi_secs_fx[num_freq_bands + band_m_idx], 1 ); // Q23 -> Q22 + move32(); + q_direction[1].band_data[band_m_idx].elevation_fx[block_m_idx] = L_shr( ele_secs_fx[num_freq_bands + band_m_idx], 1 ); // Q23 -> Q22 + move32(); + Word32 x = L_sub( ONE_IN_Q30, L_shr( diff_secs_fx[band_m_idx], sub( 1, diff_secs_exp[band_m_idx] ) ) ); + Word32 y = L_sub( ONE_IN_Q30, L_shr( diff_secs_fx[num_freq_bands + band_m_idx], sub( 1, diff_secs_exp[num_freq_bands + band_m_idx] ) ) ); -#ifdef IVAS_FLOAT_FIXED - for ( block_m_idx = 0; block_m_idx < num_blocks; block_m_idx++ ) - { - free( hDirAC->direction_vector_m_fx[0][block_m_idx] ); - free( hDirAC->direction_vector_m_fx[1][block_m_idx] ); - free( hDirAC->direction_vector_m_fx[2][block_m_idx] ); + Word16 tmp16 = extract_h( L_add( x, y ) ); + Word32 tmp32; + IF( tmp16 == 0 ) + { + tmp32 = L_deposit_h( div_l( x, EPSILON_FX ) ); + } + ELSE + { + tmp32 = L_deposit_h( div_l( x, tmp16 ) ); + } + tmp32 = L_shr( tmp32, 1 ); // Q31 -> Q30 + } + } } - free( hDirAC->direction_vector_m_fx[0] ); - free( hDirAC->direction_vector_m_fx[1] ); - free( hDirAC->direction_vector_m_fx[2] ); -#endif /* Diffuseness */ - for ( band_m_idx = 0; band_m_idx < hDirAC->hConfig->nbands; band_m_idx++ ) + FOR( band_m_idx = 0; band_m_idx < hDirAC->hConfig->nbands; band_m_idx++ ) { - if ( renormalization_factor_diff[band_m_idx] > EPSILON ) + IF( GT_32( renormalization_factor_diff_fx[band_m_idx], EPSILON_FX ) ) { - hDirAC->diffuseness_m[band_m_idx] /= renormalization_factor_diff[band_m_idx]; + Word16 tmp_e; + hDirAC->diffuseness_m_fx[band_m_idx] = L_deposit_h( BASOP_Util_Divide3232_Scale( hDirAC->diffuseness_m_fx[band_m_idx], renormalization_factor_diff_fx[band_m_idx], &tmp_e ) ); + move32(); + tmp_e = add( tmp_e, sub( hDirAC->diffuseness_m_exp[band_m_idx], renormalization_factor_diff_exp[band_m_idx] ) ); + hDirAC->diffuseness_m_fx[band_m_idx] = L_shr( hDirAC->diffuseness_m_fx[band_m_idx], sub( 1, tmp_e ) ); // to Q30 + move32(); } - else + ELSE { - hDirAC->diffuseness_m[band_m_idx] = 0.f; + hDirAC->diffuseness_m_fx[band_m_idx] = 0; + move32(); } + hDirAC->diffuseness_m_exp[band_m_idx] = 1; + move16(); /* set coherence to zero and convert diffuseness to energy ratio*/ - set_f( q_direction->band_data[band_m_idx].energy_ratio, 1.f - hDirAC->diffuseness_m[band_m_idx], q_direction->cfg.nblocks ); + set32_fx( q_direction->band_data[band_m_idx].energy_ratio_fx, L_sub( ONE_IN_Q30, hDirAC->diffuseness_m_fx[band_m_idx] ), q_direction->cfg.nblocks ); - for ( block_m_idx = 0; block_m_idx < q_direction->cfg.nblocks; block_m_idx++ ) + FOR( block_m_idx = 0; block_m_idx < q_direction->cfg.nblocks; block_m_idx++ ) { - if ( q_direction->coherence_band_data != NULL ) + IF( q_direction->coherence_band_data != NULL ) { q_direction->coherence_band_data[band_m_idx].spread_coherence[block_m_idx] = 0; + move16(); } } } -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - for ( i = 0; i < nchan_fb_in; i++ ) - { - free( data_f_fx[i] ); - free( pp_fr_real_fx[i] ); - free( pp_fr_imag_fx[i] ); - } - free( pp_fr_real_fx ); - free( pp_fr_imag_fx ); -#endif - pop_wmops(); return; } diff --git a/lib_enc/ivas_mdct_core_enc.c b/lib_enc/ivas_mdct_core_enc.c index aecf4c9a9..f8787ab7d 100644 --- a/lib_enc/ivas_mdct_core_enc.c +++ b/lib_enc/ivas_mdct_core_enc.c @@ -2128,9 +2128,14 @@ void ivas_mdct_core_whitening_enc( bw_detect( st, NULL, st->hTcxEnc->spectrum[n], NULL, MC_FORMAT /*just cannot be ISM_FORMAT*/, mct_on ); #else #ifdef IVAS_FLOAT_FIXED_CONVERSIONS +#ifdef MSAN_FIX + q_spectrum = Q_factor_arr( st->hTcxEnc->spectrum[n], st->hTcxEnc->L_frameTCX / ( n + 1 ) ); + floatToFixed_arr( st->hTcxEnc->spectrum[n], spect_fx[n], q_spectrum, st->hTcxEnc->L_frameTCX / ( n + 1 ) ); +#else Word16 l_frame = (int16_t) ( st->input_Fs / FRAMES_PER_SEC ); q_spectrum = Q_factor_arr( st->hTcxEnc->spectrum[n], l_frame ); floatToFixed_arr( st->hTcxEnc->spectrum[n], spect_fx[n], q_spectrum, l_frame ); +#endif #endif bw_detect_fx( st, NULL, spect_fx[n], NULL, NULL, MC_FORMAT /*just cannot be ISM_FORMAT*/, mct_on ); #endif diff --git a/lib_enc/ivas_spar_encoder.c b/lib_enc/ivas_spar_encoder.c index 6777a8527..2ba611679 100644 --- a/lib_enc/ivas_spar_encoder.c +++ b/lib_enc/ivas_spar_encoder.c @@ -861,8 +861,15 @@ static ivas_error ivas_spar_cov_md_process( move32(); FOR( i = 1; i < nchan_inp; i++ ) { - Word32 tmp = L_deposit_h( BASOP_Util_Divide3232_Scale( cov_real_fx[i][i][b], cov_real_fx[0][0][b], &tmp_e ) ); - tmp_e = add( tmp_e, sub( sub( Q31, hSpar->hCovEnc->pCov_state->q_cov_real_per_band[i][i][b] ), sub( Q31, hSpar->hCovEnc->pCov_state->q_cov_real_per_band[0][0][b] ) ) ); + Word32 tmp = 0; + move32(); + tmp_e = 0; + move16(); + IF( cov_real_fx[0][0][b] != 0 ) + { + tmp = L_deposit_h( BASOP_Util_Divide3232_Scale( cov_real_fx[i][i][b], cov_real_fx[0][0][b], &tmp_e ) ); + tmp_e = add( tmp_e, sub( sub( Q31, hSpar->hCovEnc->pCov_state->q_cov_real_per_band[i][i][b] ), sub( Q31, hSpar->hCovEnc->pCov_state->q_cov_real_per_band[0][0][b] ) ) ); + } Wscale_d_fx[b] = BASOP_Util_Add_Mant32Exp( tmp, tmp_e, Wscale_d_fx[b], Wscale_d_e, &Wscale_d_e ); move32(); } @@ -1125,9 +1132,9 @@ static ivas_error ivas_spar_enc_process( { num_chs_alloc = 1; /* only W channel processed for predicting YZX */ } - FOR( Word16 m = 0; m < MAX_INPUT_CHANNELS + MAX_NUM_OBJECTS; m++ ) + FOR( Word16 m = 0; m <= nchan_fb_in + nchan_transport; m++ ) { - IF( data_f[m] != NULL && ( m <= nchan_fb_in + nchan_transport ) ) + IF( data_f[m] != NULL ) { q_data_fix[m] = Q_factor_arrL( data_f[m], input_frame ); floatToFixed_arrL( data_f[m], data_fix[m], q_data_fix[m], input_frame ); @@ -1325,9 +1332,73 @@ static ivas_error ivas_spar_enc_process( fprintf( fid, "%.6f\n", hSpar->hMdEnc->mixer_mat[1][0][band] ); } #endif +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + Word16 mixer_q = 31; + Word16 prior_mixer_q = 31; + Word32 num_channels = ivas_sba_get_nchan_metadata( sba_order, hEncoderConfig->ivas_total_brate ); + for ( i = 0; i < num_channels; i++ ) + { + for ( j = 0; j < num_channels; j++ ) + { + mixer_q = s_min( mixer_q, Q_factor_arrL( hSpar->hMdEnc->mixer_mat[i][j], IVAS_MAX_NUM_BANDS ) ); + } + } + for ( i = 0; i < hSpar->hFbMixer->fb_cfg->num_out_chans; i++ ) + { + for ( j = 0; j < hSpar->hFbMixer->fb_cfg->num_in_chans; j++ ) + { + prior_mixer_q = s_min( prior_mixer_q, Q_factor_arrL( hSpar->hFbMixer->prior_mixer[i][j], IVAS_MAX_NUM_BANDS ) ); + } + } + + mixer_q = s_min( mixer_q, prior_mixer_q ); + // both should have a common q as there are values being copied inside function + // or need to do loop for updating values for unused values + + for ( i = 0; i < num_channels; i++ ) + { + for ( j = 0; j < num_channels; j++ ) + { + floatToFixed_arrL32( hSpar->hMdEnc->mixer_mat[i][j], hSpar->hMdEnc->mixer_mat_fx[i][j], mixer_q, IVAS_MAX_NUM_BANDS ); + } + } + for ( i = 0; i < hSpar->hFbMixer->fb_cfg->num_out_chans; i++ ) + { + for ( j = 0; j < hSpar->hFbMixer->fb_cfg->num_in_chans; j++ ) + { + floatToFixed_arrL32( hSpar->hFbMixer->prior_mixer[i][j], hSpar->hFbMixer->prior_mixer_fx[i][j], mixer_q, IVAS_MAX_NUM_BANDS ); + } + } + + hSpar->hMdEnc->q_mixer_mat_fx = mixer_q; + hSpar->hFbMixer->q_prior_mixer_fx = mixer_q; + Word16 q_p_pcm_tmp_loc_fx[DIRAC_MAX_ANA_CHANS]; +#endif - ivas_fb_mixer_process( hSpar->hFbMixer, hSpar->hMdEnc->mixer_mat, p_pcm_tmp, input_frame, in_out_mixer_map ); + // both mixer_mat_fx and prior mixer_mat_fx should have a common q as there are values being copied inside function + // or need to do loop for updating values for unused values + ivas_fb_mixer_process( hSpar->hFbMixer, hSpar->hMdEnc->mixer_mat_fx, &hSpar->hMdEnc->q_mixer_mat_fx, p_pcm_tmp_fx, q_p_pcm_tmp_loc_fx, input_frame, in_out_mixer_map ); +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + for ( int ch = ( hSpar->hFbMixer->fb_cfg->active_w_mixing == 0 ); ch < hSpar->hFbMixer->fb_cfg->num_out_chans; ch++ ) + { + for ( int k = 0; k < input_frame; k++ ) + { + p_pcm_tmp[ch][k] = (float) fixedToFloat( p_pcm_tmp_fx[ch][k], q_p_pcm_tmp_loc_fx[ch] ); + } + } + + // hSpar->hMdEnc->q_mixer_mat_fx = mixer_q; + // hSpar->hFbMixer->q_prior_mixer_fx = mixer_q; + // should be same + for ( i = 0; i < hSpar->hFbMixer->fb_cfg->num_out_chans; i++ ) + { + for ( j = 0; j < hSpar->hFbMixer->fb_cfg->num_in_chans; j++ ) + { + fixedToFloat_arrL32( hSpar->hFbMixer->prior_mixer_fx[i][j], hSpar->hFbMixer->prior_mixer[i][j], hSpar->hFbMixer->q_prior_mixer_fx, IVAS_MAX_NUM_BANDS ); + } + } +#endif if ( hSpar->hFbMixer->fb_cfg->active_w_mixing == 0 ) { @@ -1337,7 +1408,7 @@ static ivas_error ivas_spar_enc_process( if ( hSpar->hMdEnc->spar_md.prior_dyn_active_w_flag != dyn_active_w_flag ) { float new_w[L_FRAME48k]; - + Word32 new_w_fx[L_FRAME48k]; /* delayed W */ mvr2r( wyzx_del_buf[0], p_pcm_tmp[0], num_del_samples ); mvr2r( data_f[0], p_pcm_tmp[0] + num_del_samples, input_frame - num_del_samples ); @@ -1347,11 +1418,47 @@ static ivas_error ivas_spar_enc_process( if ( hSpar->hMdEnc->spar_md.prior_dyn_active_w_flag == 0 && dyn_active_w_flag == 1 ) { +#ifndef IVAS_FLOAT_FIXED ivas_fb_mixer_cross_fading( hSpar->hFbMixer, p_pcm_tmp, p_pcm_tmp[0], new_w, 0, input_frame, 0 ); +#else +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + floatToFixed_arrL32( new_w, new_w_fx, Q11, input_frame ); + FOR( i = 0; i < hSpar->hFbMixer->fb_cfg->num_out_chans; i++ ) + { + p_pcm_tmp_fx[i] = &pcm_tmp_fx[i][0]; + floatToFixed_arrL32( p_pcm_tmp[i], p_pcm_tmp_fx[i], Q11, input_frame ); + } +#endif + ivas_fb_mixer_cross_fading_fx( hSpar->hFbMixer, p_pcm_tmp_fx, p_pcm_tmp_fx[0], new_w_fx, 0, input_frame, 0 ); +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + FOR( i = 0; i < hSpar->hFbMixer->fb_cfg->num_out_chans; i++ ) + { + fixedToFloat_arrL32( p_pcm_tmp_fx[i], p_pcm_tmp[i], Q11, input_frame ); + } +#endif +#endif } else if ( hSpar->hMdEnc->spar_md.prior_dyn_active_w_flag == 1 && dyn_active_w_flag == 0 ) { +#ifndef IVAS_FLOAT_FIXED ivas_fb_mixer_cross_fading( hSpar->hFbMixer, p_pcm_tmp, new_w, p_pcm_tmp[0], 0, input_frame, 0 ); +#else +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + floatToFixed_arrL32( new_w, new_w_fx, Q11, input_frame ); + FOR( i = 0; i < hSpar->hFbMixer->fb_cfg->num_out_chans; i++ ) + { + p_pcm_tmp_fx[i] = &pcm_tmp_fx[i][0]; + floatToFixed_arrL32( p_pcm_tmp[i], p_pcm_tmp_fx[i], Q11, input_frame ); + } +#endif + ivas_fb_mixer_cross_fading_fx( hSpar->hFbMixer, p_pcm_tmp_fx, new_w_fx, p_pcm_tmp_fx[0], 0, input_frame, 0 ); +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + FOR( i = 0; i < hSpar->hFbMixer->fb_cfg->num_out_chans; i++ ) + { + fixedToFloat_arrL32( p_pcm_tmp_fx[i], p_pcm_tmp[i], Q11, input_frame ); + } +#endif +#endif } } else diff --git a/lib_enc/ivas_spar_md_enc.c b/lib_enc/ivas_spar_md_enc.c index 13c9bdc0a..357e52230 100644 --- a/lib_enc/ivas_spar_md_enc.c +++ b/lib_enc/ivas_spar_md_enc.c @@ -299,6 +299,7 @@ ivas_error ivas_spar_md_enc_open_fx( * Deallocate SPAR MD encoder handle *------------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED void ivas_spar_md_enc_close( ivas_spar_md_enc_state_t **hMdEnc_in /* i/o: SPAR MD encoder handle */ ) @@ -331,12 +332,80 @@ void ivas_spar_md_enc_close( } free( hMdEnc->mixer_mat ); } +#ifdef IVAS_FLOAT_FIXED + IF( hMdEnc->mixer_mat_fx != NULL ) + { + FOR( i = 0; i < num_channels; i++ ) + { + FOR( j = 0; j < num_channels; j++ ) + { + free( hMdEnc->mixer_mat_fx[i][j] ); + } + free( hMdEnc->mixer_mat_fx[i] ); + } + free( hMdEnc->mixer_mat_fx ); + } +#endif free( *hMdEnc_in ); *hMdEnc_in = NULL; return; } +#else +void ivas_spar_md_enc_close( + ivas_spar_md_enc_state_t **hMdEnc_in /* i/o: SPAR MD encoder handle */ +) +{ + int16_t num_channels, i, j; + ivas_spar_md_enc_state_t *hMdEnc; + + if ( hMdEnc_in == NULL || *hMdEnc_in == NULL ) + { + return; + } + + hMdEnc = *hMdEnc_in; + num_channels = hMdEnc->num_umx_ch; + + if ( hMdEnc->spar_md.band_coeffs != NULL ) + { + free( hMdEnc->spar_md.band_coeffs ); + hMdEnc->spar_md.band_coeffs = NULL; + } + if ( hMdEnc->mixer_mat != NULL ) + { + for ( i = 0; i < num_channels; i++ ) + { + for ( j = 0; j < num_channels; j++ ) + { + free( hMdEnc->mixer_mat[i][j] ); + } + free( hMdEnc->mixer_mat[i] ); + } + free( hMdEnc->mixer_mat ); + } + + if ( hMdEnc->mixer_mat_local != NULL ) + { + for ( i = 0; i < num_channels; i++ ) + { + + for ( j = 0; j < num_channels; j++ ) + { + free( hMdEnc->mixer_mat_local[i][j] ); + } + free( hMdEnc->mixer_mat_local[i] ); + } + free( hMdEnc->mixer_mat_local ); + } + + free( *hMdEnc_in ); + *hMdEnc_in = NULL; + + return; +} +#endif /*-----------------------------------------------------------------------------------------* diff --git a/lib_enc/ivas_stat_enc.h b/lib_enc/ivas_stat_enc.h index 746d5712a..4c3eca4d9 100644 --- a/lib_enc/ivas_stat_enc.h +++ b/lib_enc/ivas_stat_enc.h @@ -942,8 +942,10 @@ typedef struct ivas_dirac_enc_data_structure float **direction_vector_m[DIRAC_NUM_DIMS]; /* Average direction vector */ float diffuseness_m[DIRAC_MAX_NBANDS]; #ifdef IVAS_FLOAT_FIXED - Word32 **direction_vector_m_fx[DIRAC_NUM_DIMS]; /* Average direction vector */ + Word32 **direction_vector_m_fx[DIRAC_NUM_DIMS]; /* Average direction vector */ + Word16 direction_vector_m_exp[MAX_PARAM_SPATIAL_SUBFRAMES]; // direction_vector_m_fx[i][j][k] will map to direction_vector_m_exp[j] exponent. Word32 diffuseness_m_fx[DIRAC_MAX_NBANDS]; + Word16 diffuseness_m_exp[DIRAC_MAX_NBANDS]; #endif int16_t band_grouping[DIRAC_MAX_NBANDS + 1]; int16_t block_grouping[5]; @@ -979,7 +981,9 @@ typedef struct ivas_dirac_enc_data_structure float *buffer_energy; #ifdef IVAS_FLOAT_FIXED Word32 **buffer_intensity_real_fx[DIRAC_NUM_DIMS]; + Word16 buffer_intensity_real_q[DIRAC_NUM_DIMS][DIRAC_NO_COL_AVG_DIFF][DIRAC_MAX_NBANDS]; Word32 *buffer_energy_fx; + Word16 buffer_energy_q[DIRAC_NO_COL_AVG_DIFF * DIRAC_MAX_NBANDS]; #endif /* Frame count for detecting mono */ @@ -1061,7 +1065,6 @@ typedef struct ivas_spar_md_enc_state_t Word16 HOA_md_ind[IVAS_SPAR_MAX_CH]; Word32 ***mixer_mat_fx; Word16 q_mixer_mat_fx; - Word32 ***mixer_mat_local_fx; } ivas_spar_md_enc_state_t; /* PCA structure */ diff --git a/lib_enc/swb_pre_proc.c b/lib_enc/swb_pre_proc.c index de6cafa55..b8c891d3c 100644 --- a/lib_enc/swb_pre_proc.c +++ b/lib_enc/swb_pre_proc.c @@ -567,7 +567,7 @@ void swb_pre_proc_ivas_fx( { Word16 out_start_ind, out_end_ind; stereo_dft_enc_synthesize_fx( hCPE->hStereoDft, new_swb_speech_fx, &out_start_ind, &out_end_ind, st->idchan, input_Fs, 32000, 0, NULL ); - Copy_Scale_sig32_16( new_swb_speech_fx, new_swb_speech, q_reImBuffer, L_FRAME48k ); + Copy_Scale_sig32_16( new_swb_speech_fx - STEREO_DFT_OVL_MAX, new_swb_speech - STEREO_DFT_OVL_MAX, q_reImBuffer, L_FRAME48k + STEREO_DFT_OVL_MAX ); Copy( new_swb_speech - Sample_Delay_SWB_BWE32k, hBWE_FD->old_input_fx, Sample_Delay_SWB_BWE32k ); } } -- GitLab From 0154deec75d1109cd9fb2a77ca1096c098ea5c26 Mon Sep 17 00:00:00 2001 From: Adriana Vasilache Date: Wed, 23 Oct 2024 12:09:44 +0300 Subject: [PATCH 039/128] fix 953 --- lib_com/options.h | 2 ++ lib_dec/ivas_masa_dec.c | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/lib_com/options.h b/lib_com/options.h index 819f2a42f..f1023d3b6 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -193,6 +193,8 @@ #define FIX_930_JBM_BUFSIZE_MULT /* FhG: Fix 930, Word16 too small for apa_buffer_size */ #define NONBE_FIX_943_PORT_1208_DFT_STEREO_PLC_BURST /* Ericsson: BASOP Issue 943, Float Issue 1208, fix for overflow of sample offset counter for burst error in DFT Stereo PLC. */ #define FIX_853_DECODE_MASA_ISM_AZIMUTH_PREC /* Nokia: Fixes ivas_decode_masaism_metadata decision logic change due to precision difference; needs corresponding fix in floating point */ +#define FIX_953_WRONG_ENERGY_RATIO_MASA_EXT /* Nok: Fix 953 wrong energy ratio value after shift and cast to Word8 */ + /* ################## End DEVELOPMENT switches ######################### */ /* clang-format on */ diff --git a/lib_dec/ivas_masa_dec.c b/lib_dec/ivas_masa_dec.c index 13e970f85..f3962ced2 100644 --- a/lib_dec/ivas_masa_dec.c +++ b/lib_dec/ivas_masa_dec.c @@ -4438,6 +4438,13 @@ static void create_masa_ext_out_meta_fx( move16(); FOR( dir = 0; dir < numDirections; dir++ ) { +#ifdef FIX_953_WRONG_ENERGY_RATIO_MASA_EXT + /* todo: not optimal, but less invasive */ + IF( EQ_32( hQMetaData->q_direction[dir].band_data[b_old].energy_ratio_fx[sf], ONE_IN_Q30 ) ) + { + hQMetaData->q_direction[dir].band_data[b_old].energy_ratio_fx[sf]--; + } +#endif UWord8 tmp = (UWord8) L_shr( hQMetaData->q_direction[dir].band_data[b_old].energy_ratio_fx[sf], Q30 - 8 ); // Q8 move16(); extOutMeta->diffuseToTotalRatio[sf][b_new] = (UWord8) sub( extOutMeta->diffuseToTotalRatio[sf][b_new], tmp ); // Q8 -- GitLab From 4c1b8ec4d3de2ba8f1809580e3105e655d043b5c Mon Sep 17 00:00:00 2001 From: Jan Kiene Date: Thu, 24 Oct 2024 15:00:25 +0200 Subject: [PATCH 040/128] make voip be test a manual test --- .gitlab-ci.yml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 56127eec7..f41d97839 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -40,6 +40,7 @@ variables: - 'sanitizer-stv' - 'pytest-renderer' - 'complexity' + - 'voip-be-test' default: @@ -85,6 +86,9 @@ workflow: - if: $CI_PIPELINE_SOURCE == 'web' && $MANUAL_PIPELINE_TYPE == 'complexity' variables: IVAS_PIPELINE_NAME: 'Complexity Measurement on $CI_COMMIT_BRANCH' + - if: $CI_PIPELINE_SOURCE == 'web' && $MANUAL_PIPELINE_TYPE == 'voip-be-test' + variables: + IVAS_PIPELINE_NAME: 'Voip BE test on $CI_COMMIT_BRANCH' - if: $CI_PIPELINE_SOURCE == 'schedule' # Scheduled in any branch variables: IVAS_PIPELINE_NAME: 'Scheduled pipeline: $CI_COMMIT_BRANCH' @@ -1054,11 +1058,13 @@ ivas-pytest-renderer: # Various other tests # --------------------------------------------------------------- +# TODO: actually run on MR once main problems are fixed voip-be-on-merge-request: extends: - .test-job-linux-needs-testv-dir rules: - - if: $CI_PIPELINE_SOURCE == 'merge_request_event' && $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "main" # only have MR pipelines for MRs to main + # - if: $CI_PIPELINE_SOURCE == 'merge_request_event' && $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "main" # only have MR pipelines for MRs to main + - if: $CI_PIPELINE_SOURCE == 'web' && $MANUAL_PIPELINE_TYPE == "voip-be-test" stage: test needs: ["build-codec-linux-make"] timeout: "10 minutes" -- GitLab From a40470201a978eb8397f16c103276b9f1cbc25f7 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Fri, 25 Oct 2024 11:36:50 +0530 Subject: [PATCH 041/128] Encoder LTV crash fix, MSAN/ASAN error fix and Q-info updates --- lib_com/ivas_mdct_imdct_fx.c | 162 +++++----- lib_com/ivas_prot.h | 7 + lib_com/ivas_prot_fx.h | 8 + lib_com/ivas_qmetadata_com.c | 15 +- lib_com/ivas_qspherical_com.c | 78 +++++ lib_com/ivas_rom_com_fx.c | 106 +++---- lib_com/ivas_rom_com_fx.h | 4 +- lib_com/ivas_spar_com.c | 19 +- lib_com/ivas_stat_com.h | 14 +- lib_com/modif_fs_fx.c | 6 +- lib_com/prot_fx.h | 86 +++--- lib_com/tcq_position_arith_fx.c | 2 +- lib_dec/hq_lr_dec_fx.c | 357 +++++++++++----------- lib_dec/lsf_dec_fx.c | 270 ++++++++--------- lib_dec/lsf_msvq_ma_dec_fx.c | 100 ++++--- lib_dec/nelp_dec_fx.c | 48 +-- lib_enc/init_enc.c | 4 + lib_enc/ivas_core_enc.c | 4 +- lib_enc/ivas_core_pre_proc.c | 4 +- lib_enc/ivas_dirac_enc.c | 118 ++++---- lib_enc/ivas_enc.c | 88 +++--- lib_enc/ivas_init_enc.c | 26 -- lib_enc/ivas_masa_enc.c | 175 ++++++++--- lib_enc/ivas_mc_param_enc.c | 4 + lib_enc/ivas_mcmasa_enc.c | 28 +- lib_enc/ivas_mct_enc.c | 26 -- lib_enc/ivas_qmetadata_enc.c | 12 +- lib_enc/ivas_qspherical_enc.c | 8 +- lib_enc/ivas_spar_encoder.c | 9 +- lib_enc/ivas_stat_enc.h | 13 +- lib_enc/ivas_stereo_cng_enc.c | 33 +- lib_rend/ivas_efap.c | 514 +++++++++++++++++--------------- 32 files changed, 1254 insertions(+), 1094 deletions(-) diff --git a/lib_com/ivas_mdct_imdct_fx.c b/lib_com/ivas_mdct_imdct_fx.c index c25f4fab4..37c525109 100644 --- a/lib_com/ivas_mdct_imdct_fx.c +++ b/lib_com/ivas_mdct_imdct_fx.c @@ -63,9 +63,9 @@ *-----------------------------------------------------------------------------------------*/ void ivas_tda_fx( - const Word32 *pIn, /* i : time domain buffer of size 2*length */ - Word32 *pOut, /* o : time domain buffer of size length */ - const Word16 length /* i : length of time alised signal buffer */ + const Word32 *pIn, /* i : time domain buffer of size 2*length Q10*/ + Word32 *pOut, /* o : time domain buffer of size length Q10 */ + const Word16 length /* i : length of time alised signal buffer Q0*/ ) { Word16 i; @@ -74,9 +74,9 @@ void ivas_tda_fx( FOR( i = 0; i < len_by_2; i++ ) { - pOut[i] = L_sub( pIn[add( len_by_2, i )], pIn[sub( sub( len_by_2, i ), 1 )] ); + pOut[i] = L_sub( pIn[len_by_2 + i], pIn[len_by_2 - i - 1] ); /* Q10*/ move32(); - pOut[add( len_by_2, i )] = L_add( pIn[sub( sub( i_mult( length, 2 ), i ), 1 )], pIn[add( length, i )] ); + pOut[len_by_2 + i] = L_add( pIn[length * 2 - i - 1], pIn[length + i] ); /* Q10*/ move32(); } @@ -91,32 +91,32 @@ void ivas_tda_fx( *-----------------------------------------------------------------------------------------*/ void ivas_dct_windowing_fx( - const Word16 fade_len, - const Word16 full_len, - const Word16 dct_len, - const Word16 zero_pad_len, - const Word32 *pWindow_coeffs, - const Word16 frame_len, - Word32 *pOut_buf, - Word32 *pBuffer_prev, - Word32 *pTemp_lfe ) + const Word16 fade_len, /*Q0*/ + const Word16 full_len, /*Q0*/ + const Word16 dct_len, /*Q0*/ + const Word16 zero_pad_len, /*Q0*/ + const Word32 *pWindow_coeffs, /*Q31*/ + const Word16 frame_len, /*Q0*/ + Word32 *pOut_buf, // Q10 + Word32 *pBuffer_prev, // Q10 + Word32 *pTemp_lfe ) // Q10 { Word16 i; Word16 rem_len; rem_len = 0; move16(); - Copy32( pBuffer_prev, pOut_buf + zero_pad_len, fade_len ); + Copy32( pBuffer_prev, pOut_buf + zero_pad_len, fade_len ); // Q10 - Copy32( pTemp_lfe, ( pOut_buf + add( fade_len, zero_pad_len ) ), dct_len ); + Copy32( pTemp_lfe, ( pOut_buf + add( fade_len, zero_pad_len ) ), dct_len ); // Q10 set32_fx( pOut_buf, 0, zero_pad_len ); - Copy32( ( pOut_buf + sub( full_len, fade_len ) ), pBuffer_prev, fade_len ); + Copy32( ( pOut_buf + sub( full_len, fade_len ) ), pBuffer_prev, fade_len ); // Q10 FOR( i = 0; i < fade_len; i++ ) { - pOut_buf[add( zero_pad_len, i )] = Mult_32_32( pOut_buf[add( zero_pad_len, i )], pWindow_coeffs[i] ); + pOut_buf[zero_pad_len + i] = Mult_32_32( pOut_buf[zero_pad_len + i], pWindow_coeffs[i] ); // Q10 move32(); } @@ -124,7 +124,7 @@ void ivas_dct_windowing_fx( FOR( i = 0; i < rem_len; i++ ) { - pOut_buf[add( add( i_mult( zero_pad_len, 3 ), fade_len ), i )] = Mult_32_32( pOut_buf[add( add( i_mult( zero_pad_len, 3 ), fade_len ), i )], pWindow_coeffs[sub( sub( fade_len, i ), 1 )] ); + pOut_buf[zero_pad_len * 3 + fade_len + i] = Mult_32_32( pOut_buf[zero_pad_len * 3 + fade_len + i], pWindow_coeffs[fade_len - i - 1] ); // Q10 move32(); } @@ -141,9 +141,9 @@ void ivas_dct_windowing_fx( *-----------------------------------------------------------------------------------------*/ void ivas_mdct_fx( - const Word32 *pIn, - Word32 *pOut, - const Word16 length, + const Word32 *pIn, // q_out + Word32 *pOut, // q_out + const Word16 length, // Q0 Word16 *q_out ) { const Word16 *pTwid_re, *pTwid_im; @@ -152,23 +152,23 @@ void ivas_mdct_fx( Word32 ivas_mdct_scaling_gain; len_by_2 = shr( length, 1 ); - ivas_mdct_scaling_gain = ivas_get_mdct_scaling_gain_fx( len_by_2 ); + ivas_mdct_scaling_gain = ivas_get_mdct_scaling_gain_fx( len_by_2 ); // Q46 ivas_get_twid_factors_fx1( length, &pTwid_re, &pTwid_im ); FOR( i = 0; i < len_by_2; i++ ) { - pOut[i] = L_sub( pIn[add( len_by_2, i )], pIn[sub( sub( len_by_2, i ), 1 )] ); + pOut[i] = L_sub( pIn[len_by_2 + i], pIn[len_by_2 - i - 1] ); // q_out move32(); - pOut[add( len_by_2, i )] = L_add( pIn[sub( sub( imult1616( length, 2 ), i ), 1 )], pIn[add( length, i )] ); + pOut[len_by_2 + i] = L_add( pIn[length * 2 - i - 1], pIn[length + i] ); // q_out move32(); } FOR( i = 0; i < len_by_2; i++ ) { - re[i] = L_negate( L_add( Mpy_32_16_1( pOut[2 * i], pTwid_re[i] ), Mpy_32_16_1( pOut[sub( sub( length, 1 ), imult1616( 2, i ) )], pTwid_im[i] ) ) ); + re[i] = L_negate( L_add( Mpy_32_16_1( pOut[2 * i], pTwid_re[i] ), Mpy_32_16_1( pOut[length - 1 - 2 * i], pTwid_im[i] ) ) ); // q_out move32(); - im[i] = L_sub( Mpy_32_16_1( pOut[sub( sub( length, 1 ), imult1616( 2, i ) )], pTwid_re[i] ), Mpy_32_16_1( pOut[2 * i], pTwid_im[i] ) ); + im[i] = L_sub( Mpy_32_16_1( pOut[length - 1 - 2 * i], pTwid_re[i] ), Mpy_32_16_1( pOut[2 * i], pTwid_im[i] ) ); // q_out move32(); } @@ -176,9 +176,9 @@ void ivas_mdct_fx( FOR( i = 0; i < len_by_2; i++ ) { - re[i] = Mult_32_32( re[i], ivas_mdct_scaling_gain ); + re[i] = Mult_32_32( re[i], ivas_mdct_scaling_gain ); // q_out+15 move32(); - im[i] = Mult_32_32( im[i], ivas_mdct_scaling_gain ); + im[i] = Mult_32_32( im[i], ivas_mdct_scaling_gain ); // q_out +15 move32(); } *q_out = add( *q_out, Q15 ); @@ -186,18 +186,18 @@ void ivas_mdct_fx( FOR( i = 0; i < len_by_2; i++ ) { Word32 tmp; - tmp = L_sub( Mpy_32_16_1( re[i], pTwid_re[i] ), Mpy_32_16_1( im[i], pTwid_im[i] ) ); - im[i] = L_add( Mpy_32_16_1( im[i], pTwid_re[i] ), Mpy_32_16_1( re[i], pTwid_im[i] ) ); + tmp = L_sub( Mpy_32_16_1( re[i], pTwid_re[i] ), Mpy_32_16_1( im[i], pTwid_im[i] ) ); // q_out + im[i] = L_add( Mpy_32_16_1( im[i], pTwid_re[i] ), Mpy_32_16_1( re[i], pTwid_im[i] ) ); // q_out move32(); - re[i] = tmp; + re[i] = tmp; // q_out move32(); } FOR( i = 0; i < len_by_2; i++ ) { - pOut[sub( sub( length, imult1616( 2, i ) ), 1 )] = re[i]; + pOut[length - 2 * i - 1] = re[i]; // q_out move32(); - pOut[2 * i] = im[i]; + pOut[2 * i] = im[i]; // q_out move32(); } @@ -212,33 +212,33 @@ void ivas_mdct_fx( *-----------------------------------------------------------------------------------------*/ static void ivas_ifft_cplx( - Word32 *re, - Word32 *im, - const Word16 length ) + Word32 *re, /*Q24*/ + Word32 *im, /*Q24*/ + const Word16 length /*Q0*/ ) { Word16 i; Word32 ivas_imdct_one_by_powergain; - ivas_imdct_one_by_powergain = IVAS_ONE_BY_IMDCT_SCALING_GAIN_Q16; + ivas_imdct_one_by_powergain = IVAS_ONE_BY_IMDCT_SCALING_GAIN_Q16; // Q16 move32(); /*re-arrange inputs to use fft as ifft */ - re[0] = Mult_32_32( re[0], ivas_imdct_one_by_powergain ); + re[0] = Mult_32_32( re[0], ivas_imdct_one_by_powergain ); // Q9 move32(); - im[0] = Mult_32_32( im[0], ivas_imdct_one_by_powergain ); + im[0] = Mult_32_32( im[0], ivas_imdct_one_by_powergain ); // Q9 move32(); - FOR( i = 1; i <= shr( length, 1 ); i++ ) + FOR( i = 1; i <= ( length / 2 ); i++ ) { Word32 tmp; - tmp = Mult_32_32( re[sub( length, i )], ivas_imdct_one_by_powergain ); - re[sub( length, i )] = Mult_32_32( re[i], ivas_imdct_one_by_powergain ); + tmp = Mult_32_32( re[length - i], ivas_imdct_one_by_powergain ); // Q9 + re[length - i] = Mult_32_32( re[i], ivas_imdct_one_by_powergain ); // Q9 move32(); - re[i] = tmp; + re[i] = tmp; //-Q6 move32(); - tmp = Mult_32_32( im[sub( length, i )], ivas_imdct_one_by_powergain ); - im[sub( length, i )] = Mult_32_32( im[i], ivas_imdct_one_by_powergain ); + tmp = Mult_32_32( im[length - i], ivas_imdct_one_by_powergain ); // Q9 + im[length - i] = Mult_32_32( im[i], ivas_imdct_one_by_powergain ); // Q9 move32(); - im[i] = tmp; + im[i] = tmp; // Q9 move32(); } @@ -255,9 +255,9 @@ static void ivas_ifft_cplx( *-----------------------------------------------------------------------------------------*/ void ivas_itda_fx( - const Word32 *re, /* i : time alised signal after IDCT */ + const Word32 *re, /* i : time alised signal after IDCT Q24 */ Word32 *pOut, /* o : time domain buffer of size 2*length */ - const Word16 length /* i : length of time alised signal buffer */ + const Word16 length /* i : length of time alised signal buffer Q0 */ ) { Word16 i; @@ -266,13 +266,13 @@ void ivas_itda_fx( FOR( i = 0; i < len_by_2; i++ ) { - pOut[i] = L_negate( re[sub( sub( len_by_2, i ), 1 )] ); + pOut[i] = L_negate( re[len_by_2 - i - 1] ); /*Q24 */ move32(); - pOut[add( len_by_2, i )] = re[i]; + pOut[add( len_by_2, i )] = re[i]; /*Q24 */ move32(); - pOut[add( length, i )] = re[add( len_by_2, i )]; + pOut[add( length, i )] = re[len_by_2 + i]; /*Q24 */ move32(); - pOut[add( imult1616( 3, len_by_2 ), i )] = re[sub( sub( length, i ), 1 )]; + pOut[3 * len_by_2 + i] = re[length - i - 1]; /*Q24 */ move32(); } @@ -287,9 +287,9 @@ void ivas_itda_fx( *-----------------------------------------------------------------------------------------*/ void ivas_imdct_fx( - const Word32 *pIn, - Word32 *pOut, - const Word16 length, + const Word32 *pIn, // Q24 + Word32 *pOut, // q_out Q9 + const Word16 length /*Q0*/, Word16 *q_out ) { const Word16 *pTwid_re, *pTwid_im; @@ -303,9 +303,9 @@ void ivas_imdct_fx( FOR( i = 0; i < len_by_2; i++ ) { - re[i] = L_add( Mpy_32_16_1( pIn[sub( sub( length, shl( i, 1 ) ), 1 )], pTwid_re[i] ), Mpy_32_16_1( pIn[2 * i], pTwid_im[i] ) ); /*stl_arr_index*/ + re[i] = L_add( Mpy_32_16_1( pIn[length - 2 * i - 1], pTwid_re[i] ), Mpy_32_16_1( pIn[2 * i], pTwid_im[i] ) ); /*stl_arr_index Q24*/ move32(); - im[i] = L_sub( Mpy_32_16_1( pIn[2 * i], pTwid_re[i] ), Mpy_32_16_1( pIn[sub( sub( length, shl( i, 1 ) ), 1 )], pTwid_im[i] ) ); /*stl_arr_index*/ + im[i] = L_sub( Mpy_32_16_1( pIn[2 * i], pTwid_re[i] ), Mpy_32_16_1( pIn[length - 2 * i - 1], pTwid_im[i] ) ); /*stl_arr_index Q24*/ move32(); } @@ -319,30 +319,30 @@ void ivas_imdct_fx( FOR( i = 0; i < len_by_2; i++ ) { Word32 tmp; - tmp = L_add( Mpy_32_16_1( re[i], pTwid_re[i] ), Mpy_32_16_1( im[i], pTwid_im[i] ) ); - im[i] = L_sub( Mpy_32_16_1( im[i], pTwid_re[i] ), Mpy_32_16_1( re[i], pTwid_im[i] ) ); + tmp = L_add( Mpy_32_16_1( re[i], pTwid_re[i] ), Mpy_32_16_1( im[i], pTwid_im[i] ) ); // Q9 + im[i] = L_sub( Mpy_32_16_1( im[i], pTwid_re[i] ), Mpy_32_16_1( re[i], pTwid_im[i] ) ); // Q9 move32(); - re[i] = tmp; + re[i] = tmp; // Q9 move32(); } FOR( i = ( len_by_2 - 1 ); i >= 0; i-- ) { - re[add( shl( i, 1 ), 1 )] = im[sub( sub( len_by_2, 1 ), i )]; + re[2 * i + 1] = im[( len_by_2 - 1 ) - i]; // Q9 move32(); - re[2 * i] = L_negate( re[i] ); + re[2 * i] = L_negate( re[i] ); // Q9 move32(); } FOR( i = 0; i < len_by_2; i++ ) { - pOut[i] = L_negate( re[sub( sub( len_by_2, i ), 1 )] ); + pOut[i] = L_negate( re[len_by_2 - i - 1] ); // Q9 move32(); - pOut[add( len_by_2, i )] = re[i]; + pOut[len_by_2 + i] = re[i]; // Q9 move32(); - pOut[add( length, i )] = re[add( len_by_2, i )]; + pOut[length + i] = re[len_by_2 + i]; // Q9 move32(); - pOut[add( imult1616( 3, len_by_2 ), i )] = re[sub( sub( length, i ), 1 )]; + pOut[3 * len_by_2 + i] = re[length - i - 1]; // Q9 move32(); } @@ -356,29 +356,29 @@ void ivas_imdct_fx( * Sets/Maps the fft twiddle tables based on fft length *-----------------------------------------------------------------------------------------*/ void ivas_get_twid_factors_fx1( - const Word16 length, - const Word16 **pTwid_re, - const Word16 **pTwid_im ) + const Word16 length, // Q0 + const Word16 **pTwid_re, // Q15 + const Word16 **pTwid_im ) // Q15 { IF( EQ_16( length, 480 ) ) { - *pTwid_re = (const Word16 *) &ivas_cos_twiddle_480_fx[0]; - *pTwid_im = (const Word16 *) &ivas_sin_twiddle_480_fx[0]; + *pTwid_re = (const Word16 *) &ivas_cos_twiddle_480_fx[0]; // Q15 + *pTwid_im = (const Word16 *) &ivas_sin_twiddle_480_fx[0]; // Q15 } ELSE IF( EQ_16( length, 320 ) ) { - *pTwid_re = (const Word16 *) &ivas_cos_twiddle_320_fx[0]; - *pTwid_im = (const Word16 *) &ivas_sin_twiddle_320_fx[0]; + *pTwid_re = (const Word16 *) &ivas_cos_twiddle_320_fx[0]; // Q15 + *pTwid_im = (const Word16 *) &ivas_sin_twiddle_320_fx[0]; // Q15 } ELSE IF( EQ_16( length, 160 ) ) { - *pTwid_re = (const Word16 *) &ivas_cos_twiddle_160_fx[0]; - *pTwid_im = (const Word16 *) &ivas_sin_twiddle_160_fx[0]; + *pTwid_re = (const Word16 *) &ivas_cos_twiddle_160_fx[0]; // Q15 + *pTwid_im = (const Word16 *) &ivas_sin_twiddle_160_fx[0]; // Q15 } ELSE IF( EQ_16( length, 80 ) ) { - *pTwid_re = (const Word16 *) &ivas_cos_twiddle_80_fx[0]; - *pTwid_im = (const Word16 *) &ivas_sin_twiddle_80_fx[0]; + *pTwid_re = (const Word16 *) &ivas_cos_twiddle_80_fx[0]; // Q15 + *pTwid_im = (const Word16 *) &ivas_sin_twiddle_80_fx[0]; // Q15 } ELSE { @@ -405,19 +405,19 @@ Word32 ivas_get_mdct_scaling_gain_fx( { case L_FRAME48k >> 2: { - gain = IVAS_MDCT_SCALING_GAIN_48k_Q46; + gain = IVAS_MDCT_SCALING_GAIN_48k_Q46; /*Q46*/ move32(); BREAK; } case L_FRAME32k >> 2: { - gain = IVAS_MDCT_SCALING_GAIN_32k_Q46; + gain = IVAS_MDCT_SCALING_GAIN_32k_Q46; /*Q46*/ move32(); BREAK; } case L_FRAME16k >> 2: { - gain = IVAS_MDCT_SCALING_GAIN_16k_Q46; + gain = IVAS_MDCT_SCALING_GAIN_16k_Q46; /*Q46*/ move32(); BREAK; } diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index 5e1214c42..a2aada6a9 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -4610,6 +4610,13 @@ Word16 quantize_phi_fx( Word32 *phi_hat, /* o : quantized azimuth */ const Word16 n /* i : azimuth codebook size */ ); + +Word16 quantize_phi_enc_fx( + Word32 phi, /* i : azimuth value */ + const Word16 flag_delta, /* i : flag indicating if the azimuth codebook is translated or not */ + Word32 *phi_hat, /* o : quantized azimuth */ + const Word16 n /* i : azimuth codebook size */ +); #endif /*! r: decoded elevation value */ float deindex_elevation( diff --git a/lib_com/ivas_prot_fx.h b/lib_com/ivas_prot_fx.h index 121570bc3..a9ca1f48d 100644 --- a/lib_com/ivas_prot_fx.h +++ b/lib_com/ivas_prot_fx.h @@ -3516,4 +3516,12 @@ void ivas_omasa_enc_close_fx( ivas_error ivas_omasa_enc_open_fx( Encoder_Struct *st_ivas /* i/o: IVAS encoder handle */ ); + +void ivas_masa_estimate_energy_fx( + MASA_ENCODER_HANDLE hMasa, /* i/o: MASA encoder structure */ + Word32 *data_fx[], /* i : Input audio channels Q(q_data) */ + const Word16 input_frame, /* i : frame length */ + const Word16 nchan_transport, /* i : number of MASA input/transport channels */ + Word16 q_data /* i : q for data_fx */ +); #endif diff --git a/lib_com/ivas_qmetadata_com.c b/lib_com/ivas_qmetadata_com.c index 3bcec831e..3bb90ec8d 100644 --- a/lib_com/ivas_qmetadata_com.c +++ b/lib_com/ivas_qmetadata_com.c @@ -177,13 +177,20 @@ ivas_error ivas_qmetadata_allocate_memory( FOR( j = 0; j < nbands; j++ ) { +#ifndef IVAS_FLOAT_FIXED set_zero( hQMetaData->q_direction[dir].band_data[j].elevation, MAX_PARAM_SPATIAL_SUBFRAMES ); -#ifdef IVAS_FLOAT_FIXED - set32_fx( hQMetaData->q_direction[dir].band_data[j].elevation_fx, 0, MAX_PARAM_SPATIAL_SUBFRAMES ); -#endif set_zero( hQMetaData->q_direction[dir].band_data[j].azimuth, MAX_PARAM_SPATIAL_SUBFRAMES ); -#ifdef IVAS_FLOAT_FIXED +#ifdef MSAN_FIX + set_zero( hQMetaData->q_direction[dir].band_data[j].q_elevation, MAX_PARAM_SPATIAL_SUBFRAMES ); + set_zero( hQMetaData->q_direction[dir].band_data[j].q_azimuth, MAX_PARAM_SPATIAL_SUBFRAMES ); +#endif +#else + set32_fx( hQMetaData->q_direction[dir].band_data[j].elevation_fx, 0, MAX_PARAM_SPATIAL_SUBFRAMES ); set32_fx( hQMetaData->q_direction[dir].band_data[j].azimuth_fx, 0, MAX_PARAM_SPATIAL_SUBFRAMES ); +#ifdef MSAN_FIX + set32_fx( hQMetaData->q_direction[dir].band_data[j].q_elevation_fx, 0, MAX_PARAM_SPATIAL_SUBFRAMES ); + set32_fx( hQMetaData->q_direction[dir].band_data[j].q_azimuth_fx, 0, MAX_PARAM_SPATIAL_SUBFRAMES ); +#endif #endif set_zero( hQMetaData->q_direction[dir].band_data[j].energy_ratio, MAX_PARAM_SPATIAL_SUBFRAMES ); #ifdef IVAS_FLOAT_FIXED diff --git a/lib_com/ivas_qspherical_com.c b/lib_com/ivas_qspherical_com.c index ab10cd57c..db931df0f 100644 --- a/lib_com/ivas_qspherical_com.c +++ b/lib_com/ivas_qspherical_com.c @@ -495,6 +495,84 @@ ELSE move32(); id_phi = add( id_phi, shr( n, 1 ) ); +return id_phi; +} + +Word16 quantize_phi_enc_fx( + Word32 phi, /* i : azimuth value, Q22 */ + const Word16 flag_delta, /* i : flag indicating if the azimuth codebook is translated or not */ + Word32 *phi_hat, /* o : quantized azimuth, Q22 */ + const Word16 n /* i : azimuth codebook size */ +) +{ + Word16 id_phi; + Word32 dd_fx; + Word32 delta_phi_fx; + Word32 inv_delta_phi_fx; + Word32 temp_res; + Word16 temp_e; + + delta_phi_fx = BASOP_Util_Divide3232_Scale_cadence( 360, n, &temp_e ); + delta_phi_fx = L_shl( delta_phi_fx, sub( temp_e, 9 ) ); + inv_delta_phi_fx = BASOP_Util_Divide3232_Scale_cadence( n, 360, &temp_e ); + + IF( EQ_16( n, 1 ) ) + { + *phi_hat = 0; + move32(); + + return 0; + } + + test(); + IF( EQ_16( flag_delta, 1 ) && GT_16( n, 2 ) ) + { + dd_fx = dd_val[n]; + move32(); + } + ELSE + { + dd_fx = 0; + move32(); + } + + temp_res = Mpy_32_32( L_sub( L_sub( phi, DEGREE_180_Q_22 ), dd_fx ), inv_delta_phi_fx ); + temp_res = L_shl( temp_res, temp_e ); + id_phi = round_fx( L_shr( temp_res, Q22 - Q16 ) ); + + assert( L_sub( L_abs( temp_res ), abs( id_phi ) * ONE_IN_Q22 ) <= ONE_IN_Q21 ); + + + IF( add( id_phi, shr( n, 1 ) ) < 0 ) + { + id_phi = add( id_phi, 1 ); + } + + IF( sub( id_phi, shr( n, 1 ) ) >= 0 ) + { + id_phi = negate( shr( n, 1 ) ); + } + + IF( EQ_16( id_phi, negate( add( shr( n, 1 ), ( n % 2 ) ) ) ) ) + { + id_phi = add( id_phi, ( 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 = L_add_sat( L_add_sat( ( id_phi * delta_phi_fx ), dd_fx ), DEGREE_180_Q_22 ); +move32(); +id_phi = add( id_phi, shr( n, 1 ) ); + return id_phi; } #endif diff --git a/lib_com/ivas_rom_com_fx.c b/lib_com/ivas_rom_com_fx.c index 200c376cb..269c62d28 100644 --- a/lib_com/ivas_rom_com_fx.c +++ b/lib_com/ivas_rom_com_fx.c @@ -1634,76 +1634,46 @@ const Word32 shoebox_sin_cos_tbl_fx[11][2] = { { 0, 1073741824 }, // 0 { 759250112, -759250112 }, { -759250112, -759250112 } }; // 135, -135 //Q.30 -const Word32 delta_phi_val[257] = { - 0, - 1509949440, 754974720, 503316480, 377487360, 301989888, 251658240, 215707056, 188743680, - 167772160, 150994944, 137268128, 125829120, 116149960, 107853528, 100663296, 94371840, - 88820552, 83886080, 79471024, 75497472, 71902352, 68634064, 65649976, 62914560, - 60397976, 58074980, 55924052, 53926764, 52067224, 50331648, 48708048, 47185920, - 45756044, 44410276, 43141412, 41943040, 40809444, 39735512, 38716652, 37748736, - 36828036, 35951176, 35115104, 34317032, 33554432, 32824988, 32126584, 31457280, - 30815294, 30198988, 29606852, 29037490, 28489612, 27962026, 27453626, 26963382, - 26490342, 26033612, 25592364, 25165824, 24753270, 24354024, 23967452, 23592960, - 23229992, 22878022, 22536558, 22205138, 21883326, 21570706, 21266894, 20971520, - 20684238, 20404722, 20132660, 19867756, 19609732, 19358326, 19113284, 18874368, - 18641352, 18414018, 18192162, 17975588, 17764112, 17557552, 17355740, 17158516, - 16965724, 16777216, 16592851, 16412494, 16236015, 16063292, 15894205, 15728640, - 15566489, 15407647, 15252015, 15099494, 14949994, 14803426, 14659703, 14518745, - 14380471, 14244806, 14111677, 13981013, 13852747, 13726813, 13603148, 13481691, - 13362384, 13245171, 13129995, 13016806, 12905551, 12796182, 12688651, 12582912, - 12478921, 12376635, 12276012, 12177012, 12079596, 11983726, 11889366, 11796480, - 11705034, 11614996, 11526332, 11439011, 11353003, 11268279, 11184811, 11102569, - 11021529, 10941663, 10862946, 10785353, 10708861, 10633447, 10559087, 10485760, - 10413444, 10342119, 10271765, 10202361, 10133889, 10066330, 9999665, 9933878, - 9868951, 9804866, 9741609, 9679163, 9617512, 9556642, 9496537, 9437184, - 9378568, 9320676, 9263493, 9207009, 9151209, 9096081, 9041613, 8987794, - 8934612, 8882056, 8830114, 8778776, 8728031, 8677870, 8628283, 8579258, - 8530788, 8482862, 8435472, 8388608, 8342262, 8296425, 8251090, 8206247, - 8161889, 8118007, 8074596, 8031646, 7989150, 7947102, 7905494, 7864320, - 7823572, 7783244, 7743330, 7703823, 7664718, 7626007, 7587685, 7549747, - 7512186, 7474997, 7438174, 7401713, 7365607, 7329851, 7294441, 7259372, - 7224638, 7190235, 7156158, 7122403, 7088964, 7055838, 7023020, 6990506, - 6958292, 6926373, 6894746, 6863406, 6832350, 6801574, 6771073, 6740845, - 6710886, 6681192, 6651759, 6622585, 6593665, 6564997, 6536577, 6508403, - 6480469, 6452775, 6425317, 6398091, 6371094, 6344325, 6317780, 6291456, - 6265350, 6239460, 6213783, 6188317, 6163059, 6138006, 6113155, 6088506, - 6064054, 6039798, 6015735, 5991863, 5968179, 5944683, 5921370, 5898240 +const Word32 delta_phi_val[90] = { + 0, 1509949440, 754974720, 503316480, 377487360, 301989888, + 251658240, 215707056, 188743680, 167772160, 150994944, + 137268128, 125829120, 116149960, 107853528, 100663296, + 94371840, 88820552, 83886080, 79471024, 75497472, + 71902352, 68634064, 65649976, 62914560, 60397976, + 58074980, 55924052, 53926764, 52067224, 50331648, + 48708048, 47185920, 45756044, 44410276, 43141412, + 41943040, 40809444, 39735512, 38716652, 37748736, + 36828036, 35951176, 35115104, 34317032, 33554432, + 32824988, 32126584, 31457280, 30815294, 30198988, + 29606852, 29037490, 28489612, 27962026, 27453626, + 26963382, 26490342, 26033612, 25592364, 25165824, + 24753270, 24354024, 23967452, 23592960, 23229992, + 22878022, 22536558, 22205138, 21883326, 21570706, + 21266894, 20971520, 20684238, 20404722, 20132660, + 19867756, 19609732, 19358326, 19113284, 18874368, + 18641352, 18414018, 18192162, 17975588, 17764112, + 17557552, 17355740, 17158516, 16965724 }; -const Word32 inv_delta_phi_val[257] = { - 0, - 5965232, 11930465, 17895698, 23860930, 29826162, 35791396, 41756628, 47721860, - 53687092, 59652324, 65617556, 71582792, 77548024, 83513256, 89478488, 95443720, - 101408952, 107374184, 113339416, 119304648, 125269880, 131235112, 137200352, 143165584, - 149130816, 155096048, 161061280, 167026512, 172991744, 178956976, 184922208, 190887440, - 196852672, 202817904, 208783136, 214748368, 220713600, 226678832, 232644064, 238609296, - 244574528, 250539760, 256504992, 262470224, 268435456, 274400704, 280365920, 286331168, - 292296384, 298261632, 304226848, 310192096, 316157312, 322122560, 328087776, 334053024, - 340018240, 345983488, 351948704, 357913952, 363879168, 369844416, 375809632, 381774880, - 387740096, 393705344, 399670560, 405635808, 411601024, 417566272, 423531488, 429496736, - 435461952, 441427200, 447392416, 453357664, 459322880, 465288128, 471253344, 477218592, - 483183808, 489149056, 495114272, 501079520, 507044736, 513009984, 518975200, 524940448, - 530905664, 536870912, 542836160, 548801408, 554766592, 560731840, 566697088, 572662336, - 578627520, 584592768, 590558016, 596523264, 602488448, 608453696, 614418944, 620384192, - 626349376, 632314624, 638279872, 644245120, 650210304, 656175552, 662140800, 668106048, - 674071232, 680036480, 686001728, 691966976, 697932160, 703897408, 709862656, 715827904, - 721793088, 727758336, 733723584, 739688832, 745654016, 751619264, 757584512, 763549760, - 769514944, 775480192, 781445440, 787410688, 793375872, 799341120, 805306368, 811271616, - 817236864, 823202048, 829167296, 835132544, 841097792, 847062976, 853028224, 858993472, - 864958720, 870923904, 876889152, 882854400, 888819648, 894784832, 900750080, 906715328, - 912680576, 918645760, 924611008, 930576256, 936541504, 942506688, 948471936, 954437184, - 960402432, 966367616, 972332864, 978298112, 984263360, 990228544, 996193792, 1002159040, - 1008124288, 1014089472, 1020054720, 1026019968, 1031985216, 1037950400, 1043915648, 1049880896, - 1055846144, 1061811328, 1067776576, 1073741824, 1079707008, 1085672320, 1091637504, 1097602816, - 1103568000, 1109533184, 1115498496, 1121463680, 1127428864, 1133394176, 1139359360, 1145324672, - 1151289856, 1157255040, 1163220352, 1169185536, 1175150720, 1181116032, 1187081216, 1193046528, - 1199011712, 1204976896, 1210942208, 1216907392, 1222872576, 1228837888, 1234803072, 1240768384, - 1246733568, 1252698752, 1258664064, 1264629248, 1270594432, 1276559744, 1282524928, 1288490240, - 1294455424, 1300420608, 1306385920, 1312351104, 1318316288, 1324281600, 1330246784, 1336212096, - 1342177280, 1348142464, 1354107776, 1360072960, 1366038272, 1372003456, 1377968640, 1383933952, - 1389899136, 1395864320, 1401829632, 1407794816, 1413760128, 1419725312, 1425690496, 1431655808, - 1437620992, 1443586176, 1449551488, 1455516672, 1461481984, 1467447168, 1473412352, 1479377664, - 1485342848, 1491308032, 1497273344, 1503238528, 1509203840, 1515169024, 1521134208, 1527099520 +const Word32 inv_delta_phi_val[90] = { + 0, 5965232, 11930464, 17895697, 23860929, 29826161, + 35791394, 41756626, 47721858, 53687091, 59652323, + 65617555, 71582788, 77548020, 83513252, 89478485, + 95443717, 101408950, 107374182, 113339414, 119304647, + 125269879, 131235111, 137200344, 143165576, 149130808, + 155096041, 161061273, 167026505, 172991738, 178956970, + 184922203, 190887435, 196852667, 202817900, 208783132, + 214748364, 220713597, 226678829, 232644061, 238609294, + 244574526, 250539758, 256504991, 262470223, 268435456, + 274400688, 280365920, 286331153, 292296385, 298261617, + 304226850, 310192082, 316157314, 322122547, 328087779, + 334053011, 340018244, 345983476, 351948708, 357913941, + 363879173, 369844406, 375809638, 381774870, 387740103, + 393705335, 399670567, 405635800, 411601032, 417566264, + 423531497, 429496729, 435461961, 441427194, 447392426, + 453357659, 459322891, 465288123, 471253356, 477218588, + 483183820, 489149053, 495114285, 501079517, 507044750, + 513009982, 518975214, 524940447, 530905679 }; const Word32 dd_val[90] = { diff --git a/lib_com/ivas_rom_com_fx.h b/lib_com/ivas_rom_com_fx.h index 6d4f50fa8..4cf61f9ae 100644 --- a/lib_com/ivas_rom_com_fx.h +++ b/lib_com/ivas_rom_com_fx.h @@ -188,8 +188,8 @@ extern const Word16 ls_elevation_CICP19_idx[11]; extern const Word32 shoebox_sin_cos_tbl_fx[11][2]; -extern const Word32 delta_phi_val[257]; -extern const Word32 inv_delta_phi_val[257]; +extern const Word32 delta_phi_val[90]; +extern const Word32 inv_delta_phi_val[90]; extern const Word32 dd_val[90]; extern const Word32 cb_azi_chan_fx[]; // Q22 extern const Word16 cb_azi_chan_16fx[]; // Q0 diff --git a/lib_com/ivas_spar_com.c b/lib_com/ivas_spar_com.c index 1cea89b76..9d21cfbb4 100644 --- a/lib_com/ivas_spar_com.c +++ b/lib_com/ivas_spar_com.c @@ -1341,24 +1341,23 @@ static void ivas_get_pred_coeffs_enc_fx( { tmp64 = W_shl( tmp64, tmp_shift ); } - L_tmp1 = W_extract_h( tmp64 ); // DM_F_q[b] + dm_alpha64_q[b] + tmp_shift - 32 - L_tmp1_q = sub( add( add( DM_F_q[b], dm_alpha64_q[b] ), tmp_shift ), 32 ); + L_tmp1 = W_extract_h( tmp64 ); // Q29 + dm_alpha64_q[b] + tmp_shift - 32 + L_tmp1_q = sub( add( add( Q29, dm_alpha64_q[b] ), tmp_shift ), 32 ); num_f = BASOP_Util_Add_Mant32Exp( dm_beta_re, sub( 31, dm_beta_re_q ), L_negate( L_tmp1 ), sub( 31, L_tmp1_q ), &num_f_e ); - sqrt_val = L_shl( Mpy_32_32( Mpy_32_32( dm_alpha[b], dm_alpha[b] ), g_th_sq ), 2 ); - val_e = sub( 31, sub( add( sub( shl( dm_alpha64_q[b], 1 ), 31 ), 27 ), 31 ) ); + sqrt_val = Mpy_32_32( Mpy_32_32( dm_alpha[b], dm_alpha[b] ), g_th_sq ); + val_e = sub( 31, sub( sub( add( sub( shl( dm_alpha64_q[b], 1 ), 31 ), 27 ), 31 ), 2 ) ); // reducing the Q by 2 instead of multiplication by 4 move16(); - - sqrt_val = BASOP_Util_Add_Mant32Exp( sqrt_val, val_e, Mpy_32_32( dm_beta_re, dm_beta_re ), sub( 31, shl( dm_beta_re_q, 1 ) ), &val_e ); - sqrt_val = BASOP_Util_Add_Mant32Exp( sqrt_val, val_e, L_negate( L_shl( Mpy_32_32( Mpy_32_32( dm_beta_re, g_th_sq ), dm_w ), 2 ) ), sub( 31, sub( add( sub( add( dm_beta_re_q, 27 ), 31 ), q_cov_real[0][0][b] ), 31 ) ), &val_e ); + sqrt_val = BASOP_Util_Add_Mant32Exp( sqrt_val, val_e, Mpy_32_32( dm_beta_re, dm_beta_re ), sub( 31, sub( shl( dm_beta_re_q, 1 ), 31 ) ), &val_e ); + sqrt_val = BASOP_Util_Add_Mant32Exp( sqrt_val, val_e, L_negate( Mpy_32_32( Mpy_32_32( dm_beta_re, g_th_sq ), dm_w ) ), sub( 31, sub( sub( add( sub( add( dm_beta_re_q, 27 ), 31 ), q_cov_real[0][0][b] ), 31 ), 2 ) ), &val_e ); // reducing the Q by 2 instead of multiplication by 4 // val_e = norm_l( sqrt_val ); sqrt_val = Sqrt32( sqrt_val, &val_e ); num_f = BASOP_Util_Add_Mant32Exp( num_f, num_f_e, sqrt_val, val_e, &num_f_e ); - den_f = L_shl( Mpy_32_32( dm_beta_re, g_th_sq ), 1 ); - den_f_e = add( sub( 31, dm_beta_re_q ), 4 ); + den_f = Mpy_32_32( dm_beta_re, g_th_sq ); + den_f_e = add( add( sub( 31, dm_beta_re_q ), 4 ), 1 ); // adding the exp with 1 instead of multiplication by 2 den_f = L_max( den_f, 1 ); dm_g[b] = activew_quad_thresh; // Q29 move32(); @@ -1366,7 +1365,7 @@ static void ivas_get_pred_coeffs_enc_fx( move16(); DM_F[b] = BASOP_Util_Divide3232_Scale_cadence( Mpy_32_32( dm_g[b], num_f ), den_f, &s_dm_f ); move32(); - DM_F_q[b] = add( s_dm_f, sub( add( 2, num_f_e ), den_f_e ) ); + DM_F_q[b] = sub( 31, add( s_dm_f, sub( add( 2, num_f_e ), den_f_e ) ) ); move16(); } } diff --git a/lib_com/ivas_stat_com.h b/lib_com/ivas_stat_com.h index a4d1065f4..4fde550bd 100644 --- a/lib_com/ivas_stat_com.h +++ b/lib_com/ivas_stat_com.h @@ -537,11 +537,12 @@ typedef struct typedef struct ivas_qdirection_band_data_struct { uint16_t spherical_index[MAX_PARAM_SPATIAL_SUBFRAMES]; +#ifndef IVAS_FLOAT_FIXED float azimuth[MAX_PARAM_SPATIAL_SUBFRAMES]; float elevation[MAX_PARAM_SPATIAL_SUBFRAMES]; -#ifdef IVAS_FLOAT_FIXED - Word32 azimuth_fx[MAX_PARAM_SPATIAL_SUBFRAMES]; /* Q22 */ - Word32 elevation_fx[MAX_PARAM_SPATIAL_SUBFRAMES]; /* Q22 */ +#else + Word32 azimuth_fx[MAX_PARAM_SPATIAL_SUBFRAMES]; /* Q22 */ + Word32 elevation_fx[MAX_PARAM_SPATIAL_SUBFRAMES]; /* Q22 */ #endif int16_t elevation_m_alphabet[MAX_PARAM_SPATIAL_SUBFRAMES]; int16_t azimuth_m_alphabet[MAX_PARAM_SPATIAL_SUBFRAMES]; @@ -557,11 +558,12 @@ typedef struct ivas_qdirection_band_data_struct uint16_t energy_ratio_index_mod[MAX_PARAM_SPATIAL_SUBFRAMES]; uint16_t azimuth_index[MAX_PARAM_SPATIAL_SUBFRAMES]; uint16_t elevation_index[MAX_PARAM_SPATIAL_SUBFRAMES]; +#ifndef IVAS_FLOAT_FIXED float q_azimuth[MAX_PARAM_SPATIAL_SUBFRAMES]; float q_elevation[MAX_PARAM_SPATIAL_SUBFRAMES]; -#ifdef IVAS_FLOAT_FIXED - Word32 q_azimuth_fx[MAX_PARAM_SPATIAL_SUBFRAMES]; /* Q22 */ - Word32 q_elevation_fx[MAX_PARAM_SPATIAL_SUBFRAMES]; /* Q22 */ +#else + Word32 q_azimuth_fx[MAX_PARAM_SPATIAL_SUBFRAMES]; /* Q22 */ + Word32 q_elevation_fx[MAX_PARAM_SPATIAL_SUBFRAMES]; /* Q22 */ #endif } IVAS_QDIRECTION_BAND_DATA; diff --git a/lib_com/modif_fs_fx.c b/lib_com/modif_fs_fx.c index 9c490a012..3cf2b645d 100644 --- a/lib_com/modif_fs_fx.c +++ b/lib_com/modif_fs_fx.c @@ -1709,8 +1709,8 @@ void decimate_2_over_3_allpass_fx( Word16 out, tmp; Word16 mem_fx_11, mem_fx_7, mem_fx_3; Word16 sc, input_fx[960]; - sc = s_min( s_min( sub( Find_Max_Norm16( input, len ), 2 ), sub( Find_Max_Norm16( mem_fx, 12 ), 2 ) ), sub( Find_Max_Norm16( lp_mem_fx, 6 ), 2 ) ); - Scale_sig( lp_mem_fx, 6, sc ); + sc = s_min( s_min( sub( Find_Max_Norm16( input, len ), 2 ), sub( Find_Max_Norm16( mem_fx, 12 ), 2 ) ), sub( Find_Max_Norm16( lp_mem_fx, 3 ), 2 ) ); + Scale_sig( lp_mem_fx, 3, sc ); Copy_Scale_sig( input, input_fx, len, sc ); Scale_sig( mem_fx, 12, sc ); out1 = out1_buff; @@ -1843,7 +1843,7 @@ void decimate_2_over_3_allpass_fx( Scale_sig( mem_fx, 12, negate( sc ) ); Scale_sig( out_fx, loop_len, negate( sc ) ); - Scale_sig( lp_mem_fx, 6, negate( sc ) ); + Scale_sig( lp_mem_fx, 3, negate( sc ) ); return; } diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index da45e5743..70d2f94b0 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -5860,17 +5860,17 @@ void td_bwe_dec_init_fx( // lsf_dec_fx.c void lsf_dec_fx( - Decoder_State *st_fx, /* i/o: State structure */ - const Word16 tc_subfr, /* i : TC subframe index */ - Word16 *Aq, /* o : quantized A(z) for 4 subframes */ - Word16 *LSF_Q_prediction, /* o : LSF prediction mode */ - Word16 *lsf_new, /* o : de-quantized LSF vector */ - Word16 *lsp_new, /* o : de-quantized LSP vector */ - Word16 *lsp_mid, /* o : de-quantized mid-frame LSP vector */ - const Word16 tdm_low_rate_mode /* i : secondary channel low rate mode flag */ + Decoder_State *st_fx, /* i/o: State structure */ + const Word16 tc_subfr, /* i : TC subframe index Q0*/ + Word16 *Aq, /* o : quantized A(z) for 4 subframes Q12*/ + Word16 *LSF_Q_prediction, /* o : LSF prediction mode Q0*/ + Word16 *lsf_new, /* o : de-quantized LSF vector Q(x2.56)*/ + Word16 *lsp_new, /* o : de-quantized LSP vector Q15*/ + Word16 *lsp_mid, /* o : de-quantized mid-frame LSP vector Q15*/ + const Word16 tdm_low_rate_mode /* i : secondary channel low rate mode flag Q0*/ #if defined LSF_RE_USE_SECONDARY_CHANNEL || defined FIX_798_LSF_SECONDARY_CH_MISSING_CODE , - const Word16 tdm_lsfQ_PCh[M] /* i : Q LSFs for primary channel */ + const Word16 tdm_lsfQ_PCh[M] /* i : Q LSFs for primary channel Qx*/ #endif ); @@ -5998,26 +5998,26 @@ Word32 dotp_me_fx( #endif void lsf_end_dec_fx( - Decoder_State *st, /* i/o: decoder state structure */ - Word16 mode2_flag, - const Word16 coder_type_org, /* i : coding type */ - const Word16 bwidth, /* i : i signal bandwidth */ - const Word16 nBits_in, /* i : number of bits used for ISF quantization*/ - Word16 *qlsf, /* o : quantized LSFs in the cosine domain */ - Word16 *lpc_param, - Word16 *LSF_Q_prediction, /* o : LSF prediction mode */ - Word16 *nb_indices + Decoder_State *st, /* i/o: decoder state structure */ + Word16 mode2_flag, /* Q0 */ + const Word16 coder_type_org, /* i : coding type Q0*/ + const Word16 bwidth, /* i : input signal bandwidth Q0*/ + const Word16 nBits_in, /* i : number of bits used for ISF quantization Q0*/ + Word16 *qlsf, /* o : quantized LSFs in the cosine domain Qx2.56*/ + Word16 *lpc_param, /* i : LPC parameters Q0*/ + Word16 *LSF_Q_prediction, /* o : LSF prediction mode Q0*/ + Word16 *nb_indices /* o : number of indices Q0*/ #if defined LSF_RE_USE_SECONDARY_CHANNEL || defined FIX_798_LSF_SECONDARY_CH_MISSING_CODE , - const Word16 tdm_lsfQ_PCh[M] + const Word16 tdm_lsfQ_PCh[M] /* i : Q LSFs for primary channel Qx*/ #endif ); void lsf_mid_dec_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - Word16 lsp_new[], /* i : quantized LSPs from frame endSQ15*/ - Word16 coder_type, /* i : Coder type */ - Word16 lsp_mid[] /* o : quantized LSPs Q15*/ + Decoder_State *st_fx, /* i/o: decoder state structure */ + Word16 lsp_new[], /* i : quantized LSPs from frame endS Q15*/ + Word16 coder_type, /* i : Coder type Q0*/ + Word16 lsp_mid[] /* o : quantized LSPs Q15*/ ); // cng_dec_fx.c @@ -7299,14 +7299,13 @@ void pvq_decode_fx( #ifdef IVAS_FLOAT_FIXED // nelp_dec_fx.c void nelp_decoder_fx( - Decoder_State *st, /* i/o: decoder static memory */ - Word16 *exc_nelp, /* o : adapt. excitation/total exc */ - Word16 *exc, /* o : adapt. excitation exc */ + Decoder_State *st_fx, /* i/o: decoder static memory */ + Word16 *exc_nelp, /* o : adapt. excitation/total exc Q0 */ + Word16 *exc, /* o : adapt. excitation exc Q_exc */ Word16 *Q_exc, - Word16 bfi, /* i : frame error rate */ - const Word16 coder_type /* i : coding type */ - , - Word16 *gain_buf /*Q14*/ + Word16 bfi, /* i : frame error rate Q0 */ + const Word16 coder_type, /* i : coding type Q0 */ + Word16 *gain_buf /* Q14 */ ); #endif @@ -8623,27 +8622,30 @@ void tcx_hm_decode( ); // lsf_msvq_ma_dec_fx.c -Word16 lsf_msvq_ma_decprm( Decoder_State *st, Word16 *param_lpc ); +Word16 lsf_msvq_ma_decprm( + Decoder_State *st, + Word16 *param_lpc /* Q0 */ +); Word16 lsf_bctcvq_decprm( Decoder_State *st, - Word16 *param_lpc + Word16 *param_lpc /* Q0 */ ); Word16 D_lsf_tcxlpc( - const Word16 indices[], /* (I) VQ indices */ - Word16 xsf_q[], /* (O) quantized xSF */ - Word16 xsf_q_ind[], /* (O) quantized xSF (w/o MA prediction) */ - Word16 narrowband, /* (I) narrowband flag */ - Word16 cdk, /* (I) codebook selector */ - Word16 mem_MA[] /* (I) MA memory */ + const Word16 indices[], /* i : VQ indices Q0*/ + Word16 lsf_q[], /* o : quantized LSF Q1*/ + Word16 lsp_q_ind[], /* o :quantized LSP (w/o MA prediction) Q1*/ + Word16 narrowband, /* i : narrowband flag Q0*/ + Word16 cdk, /* i : codebook selector Q0*/ + Word16 mem_MA[] /* i : MA memory Q1*/ ); Word16 dec_lsf_tcxlpc( - Decoder_State *st, /* (I/O) Decoder state */ - Word16 **indices, /* (O) Ptr to VQ indices */ - Word16 narrowband, /* (I) narrowband flag */ - Word16 cdk /* (I) codebook selector */ + Decoder_State *st, /* i/o: Decoder state */ + Word16 **indices, /* o : Ptr to VQ indices Q0*/ + Word16 narrowband, /* i : narrowband flag Q0*/ + Word16 cdk /* i : codebook selector Q0*/ ); // lsf_msvq_ma_fx.c diff --git a/lib_com/tcq_position_arith_fx.c b/lib_com/tcq_position_arith_fx.c index f72017940..fdac07f56 100644 --- a/lib_com/tcq_position_arith_fx.c +++ b/lib_com/tcq_position_arith_fx.c @@ -1739,7 +1739,7 @@ Word32 encode_position_ari_fx( /* Estimate TCQ bits */ bits_fx = L_sub( table_logcum_fx[size + 1], L_add( table_logcum_fx[nz + 1], table_logcum_fx[add( sub( size, nz ), 1 )] ) ); bits_fx = L_add( bits_fx, L_sub( btcq_fx, L_sub( table_logcum_fx[size + 1], L_add( table_logcum_fx[nz + 1], table_logcum_fx[add( sub( size, nz ), 1 )] ) ) ) ); - bits_fx = L_sub( bits_fx, L_sub( table_logcum_fx[pulses], L_add( table_logcum_fx[nz], table_logcum_fx[add( pulses, sub( nz, 1 ) )] ) ) ); + bits_fx = L_sub( bits_fx, L_sub( table_logcum_fx[pulses], L_add( table_logcum_fx[nz], table_logcum_fx[pulses - ( nz - 1 )] ) ) ); bits_fx = L_sub( bits_fx, nz ); *est_bits_frame_fx = L_add( *est_bits_frame_fx, bits_fx ); move32(); diff --git a/lib_dec/hq_lr_dec_fx.c b/lib_dec/hq_lr_dec_fx.c index 887f37d5c..c51a2fde5 100644 --- a/lib_dec/hq_lr_dec_fx.c +++ b/lib_dec/hq_lr_dec_fx.c @@ -36,7 +36,7 @@ static Word16 Calc_inv( Word32 L_tmp, Word16 *exp ) } ELSE { - tmp = 0x7fff; + tmp = 0x7fff; /* 1 in Q15 */ move16(); *exp = 0; move16(); @@ -51,16 +51,16 @@ static Word16 Calc_inv( Word32 L_tmp, Word16 *exp ) *--------------------------------------------------------------------------*/ static void spt_shorten_domain_set_dec_fx( - Decoder_State *st_fx, /* i: encoder state structure */ - const Word16 p2a_flags[], /* i: p2a anlysis information */ - const Word16 new_band_start[], /* i: new band start position */ - const Word16 new_band_end[], /* i: new band end position */ - const Word16 new_band_width[], /* i: new subband band width */ - const Word16 bands, /* i: total number of subbands */ - Word16 band_start[], /* o: band start position */ - Word16 band_end[], /* o: band end position */ - Word16 band_width[], /* o: sub band band width */ - Word16 *bit_budget /* i/o: bit budget */ + Decoder_State *st_fx, /* i: encoder state structure */ + const Word16 p2a_flags[], /* i: p2a anlysis information Q0*/ + const Word16 new_band_start[], /* i: new band start position Q0*/ + const Word16 new_band_end[], /* i: new band end position Q0*/ + const Word16 new_band_width[], /* i: new subband band width Q0*/ + const Word16 bands, /* i: total number of subbands Q0*/ + Word16 band_start[], /* o: band start position Q0*/ + Word16 band_end[], /* o: band end position Q0*/ + Word16 band_width[], /* o: sub band band width Q0*/ + Word16 *bit_budget /* i/o: bit budget Q0*/ ) { Word16 j, k; @@ -68,27 +68,28 @@ static void spt_shorten_domain_set_dec_fx( j = 0; move16(); - FOR( k = sub( bands, SPT_SHORTEN_SBNUM ); k < bands; k++ ) + FOR( k = bands - SPT_SHORTEN_SBNUM; k < bands; k++ ) { spt_shorten_flag[j] = 0; move16(); IF( EQ_16( p2a_flags[k], 1 ) ) { - spt_shorten_flag[j] = get_next_indice_fx( st_fx, 1 ); - *bit_budget = sub( *bit_budget, 1 ); + spt_shorten_flag[j] = get_next_indice_fx( st_fx, 1 ); /* Q0 */ + move16(); + *bit_budget = sub( *bit_budget, 1 ); /* Q0 */ move16(); IF( EQ_16( spt_shorten_flag[j], 1 ) ) { - band_start[k] = new_band_start[j]; + band_start[k] = new_band_start[j]; /* Q0 */ move16(); - band_end[k] = new_band_end[j]; + band_end[k] = new_band_end[j]; /* Q0 */ move16(); - band_width[k] = new_band_width[j]; + band_width[k] = new_band_width[j]; /* Q0 */ move16(); } } - j = add( j, 1 ); + j++; } return; @@ -131,12 +132,12 @@ void hq_lr_dec_fx( Word32 L_qint; /*Word16 Qqint=29;*/ - Word16 eref_fx /*, Qeref=10*/; - Word16 bit_alloc_weight_fx /*, Qbaw=13*/; - Word16 ld_slope_fx /*, Qldslope=15*/; - Word16 p2a_th_fx /*, Qp2ath=11*/; - Word16 pd_thresh_fx /*, Qpdth=15*/; - Word16 ni_coef_fx /*, Qnicoef=14*/; + Word16 eref_fx /* Qeref=10 */; + Word16 bit_alloc_weight_fx /* Qbaw=13 */; + Word16 ld_slope_fx /* Qldslope=15 */; + Word16 p2a_th_fx /* Qp2ath=11 */; + Word16 pd_thresh_fx /* Qpdth=15 */; + Word16 ni_coef_fx /* Qnicoef=14 */; Word32 L_Rk[BANDS_MAX]; Word16 bit_budget_fx; @@ -203,32 +204,32 @@ void hq_lr_dec_fx( test(); IF( EQ_16( st_fx->bwidth, SWB ) && ( EQ_32( L_bwe_br, HQ_16k40 ) || EQ_32( L_bwe_br, HQ_13k20 ) ) ) { - hqswb_clas_fx = get_next_indice_fx( st_fx, 2 ); - num_bits = sub( num_bits, 2 ); + hqswb_clas_fx = get_next_indice_fx( st_fx, 2 ); /* Q0 */ + num_bits = sub( num_bits, 2 ); /* Q0 */ *is_transient_fx = 0; move16(); if ( EQ_16( hqswb_clas_fx, HQ_TRANSIENT ) ) { - *is_transient_fx = 1; + *is_transient_fx = 1; /* Q0 */ move16(); } } ELSE { /* decode transient flag */ - *is_transient_fx = get_next_indice_fx( st_fx, 1 ); + *is_transient_fx = get_next_indice_fx( st_fx, 1 ); /* Q0 */ move16(); - num_bits = sub( num_bits, 1 ); + num_bits = sub( num_bits, 1 ); /* Q0 */ } /* Configure decoder for different bandwidths, bit rates, etc. */ hq2_core_configure_fx( inner_frame, num_bits, *is_transient_fx, &bands_fx, &length_fx, band_width, band_start, band_end, &L_qint, &eref_fx, &bit_alloc_weight_fx, &gqlevs_fx, &Ngq_fx, &p2a_bands_fx, &p2a_th_fx, &pd_thresh_fx, &ld_slope_fx, &ni_coef_fx, L_bwe_br ); - highlength_fx = band_end[bands_fx - 1]; + highlength_fx = band_end[bands_fx - 1]; /* Q0 */ move16(); - har_bands_fx = bands_fx; + har_bands_fx = bands_fx; /* Q0 */ move16(); test(); @@ -240,11 +241,11 @@ void hq_lr_dec_fx( test(); IF( EQ_16( hqswb_clas_fx, HQ_NORMAL ) || EQ_16( hqswb_clas_fx, HQ_HARMONIC ) ) { - num_bits = sub( num_bits, get_usebit_npswb_fx( hqswb_clas_fx ) ); + num_bits = sub( num_bits, get_usebit_npswb_fx( hqswb_clas_fx ) ); /* Q0 */ } if ( EQ_16( hqswb_clas_fx, HQ_NORMAL ) ) { - flag_spt_fx = 1; + flag_spt_fx = 1; /* Q0 */ move16(); } } @@ -257,26 +258,26 @@ void hq_lr_dec_fx( { j = 0; move16(); - FOR( k = sub( bands_fx, SPT_SHORTEN_SBNUM ); k < bands_fx; k++ ) + FOR( k = bands_fx - SPT_SHORTEN_SBNUM; k < bands_fx; k++ ) { hHQ_core->prev_SWB_peak_pos_fx[j] = 0; move16(); - j = add( j, 1 ); + j++; } } } /* Spectral energy calculation/quantization */ - ebits_fx = band_energy_dequant_fx( st_fx, L_band_energy, bands_fx, L_qint, eref_fx, *is_transient_fx ); + ebits_fx = band_energy_dequant_fx( st_fx, L_band_energy, bands_fx, L_qint, eref_fx, *is_transient_fx ); /* Q0 */ /* simple check: band_energy is too large, Abnormal Situation of bit errors */ FOR( k = 0; k < bands_fx; k++ ) { /* Max: 45.0(737279,Q14) at 32kHz, highest band, Min: -6.600037(-108135,Q14) at 8kHz(NB),8kbps, is_transient (-6.7f(-109772,Q14) is safty-threshold) */ test(); - IF( GT_32( L_band_energy[k], 737279L ) || LT_32( L_band_energy[k], -109772L ) ) + IF( GT_32( L_band_energy[k], 737279L /* 45.0 in Q14 */ ) || LT_32( L_band_energy[k], -109772L /* -6.7 in Q14 */ ) ) { - st_fx->BER_detect = 1; + st_fx->BER_detect = 1; /* Q0 */ move16(); set32_fx( L_yout, 0x0L, inner_frame ); return; @@ -285,9 +286,9 @@ void hq_lr_dec_fx( /* First pass bit budget for TCQ of spectral band information */ exp_norm = norm_s( gqlevs_fx ); - gqbits_fx = sub( 14, exp_norm ); + gqbits_fx = sub( 14, exp_norm ); /* Q0 */ - bit_budget_fx = sub( sub( num_bits, ebits_fx ), round_fx( L_shl( L_mult( Ngq_fx, gqbits_fx ), 15 ) ) ); /* (*num_bits) - (short) ceil (ebits) - Ngq * gqbits; */ + bit_budget_fx = sub( sub( num_bits, ebits_fx ), round_fx( L_shl( L_mult( Ngq_fx, gqbits_fx ), 15 ) ) ); /* (*num_bits) - (short) ceil (ebits) - Ngq * gqbits; Q0*/ pbits_fx = 0; @@ -302,8 +303,8 @@ void hq_lr_dec_fx( } ELSE { - pbits_fx = p2a_threshold_dequant_fx( st_fx, p2a_flags_fx, bands_fx, p2a_bands_fx ); - bit_budget_fx = sub( bit_budget_fx, pbits_fx ); + pbits_fx = p2a_threshold_dequant_fx( st_fx, p2a_flags_fx, bands_fx, p2a_bands_fx ); /* Q0 */ + bit_budget_fx = sub( bit_budget_fx, pbits_fx ); /* Q0 */ IF( EQ_16( hqswb_clas_fx, HQ_NORMAL ) ) { @@ -313,8 +314,8 @@ void hq_lr_dec_fx( } ELSE { - pbits_fx = p2a_threshold_dequant_fx( st_fx, p2a_flags_fx, bands_fx, p2a_bands_fx ); - bit_budget_fx = sub( bit_budget_fx, pbits_fx ); + pbits_fx = p2a_threshold_dequant_fx( st_fx, p2a_flags_fx, bands_fx, p2a_bands_fx ); /* Q0 */ + bit_budget_fx = sub( bit_budget_fx, pbits_fx ); /* Q0 */ } IF( EQ_16( flag_spt_fx, 1 ) ) @@ -328,7 +329,7 @@ void hq_lr_dec_fx( /* safety check in case of bit errors */ IF( LT_16( bit_budget_fx, 2 ) ) { - st_fx->BER_detect = 1; + st_fx->BER_detect = 1; /* Q0 */ move16(); set32_fx( L_yout, 0x0, inner_frame ); return; @@ -347,13 +348,13 @@ void hq_lr_dec_fx( Ep_fx[i] = L_shl_sat( L_tmp, s_max( sub( exp, 6 ), -31 ) ); /* Q -6 */ move32(); #else - Ep_fx[i] = L_shl( L_tmp, s_max( sub( exp, 6 ), -31 ) ); /* Q -6 */ + Ep_fx[i] = L_shl( L_tmp, s_max( sub( exp, 6 ), -31 ) ); /* Q -6 */ #endif } FOR( i = 0; i < bands_fx; i++ ) { - L_tmp2 = Ep_fx[i]; + L_tmp2 = Ep_fx[i]; /* Q -6 */ move32(); L_tmp = L_max( 1, L_tmp2 ); exp = norm_l( L_tmp ); @@ -375,7 +376,7 @@ void hq_lr_dec_fx( { exp2 = add( exp2, 1 ); } - tmp = div_s( tmp2, tmp ); + tmp = div_s( tmp2, tmp ); /* Q15 */ L_tmp = L_deposit_h( tmp ); L_tmp = Isqrt_lc( L_tmp, &exp2 ); /*Q(31-exp2) */ Ep_tmp_fx[i] = L_shr( L_tmp, sub( 15, exp2 ) ); /*Q13 */ @@ -395,20 +396,20 @@ void hq_lr_dec_fx( move16(); FOR( i = 0; i < 2; i++ ) { - last_bitalloc_max_band[i] = get_next_indice_fx( st_fx, 1 ); + last_bitalloc_max_band[i] = get_next_indice_fx( st_fx, 1 ); /* Q0 */ move16(); } - lowband = 6; + lowband = 6; /* Q0 */ move16(); - trans_bit_fx = 2; + trans_bit_fx = 2; /* Q0 */ move16(); - bit_budget_fx = sub( bit_budget_fx, trans_bit_fx ); + bit_budget_fx = sub( bit_budget_fx, trans_bit_fx ); /* Q0 */ gama_fx = 27852; move16(); /*Q15 0.85f; */ beta_fx = 17203; move16(); /*Q14 1.05f; */ - set16_fx( &p2a_flags_tmp[sub( bands_fx, trans_bit_fx )], 0, 2 ); + set16_fx( &p2a_flags_tmp[bands_fx - trans_bit_fx], 0, 2 ); IF( EQ_32( st_fx->core_brate, ACELP_13k20 ) ) { @@ -416,7 +417,7 @@ void hq_lr_dec_fx( move16(); /*14 1.25f; */ gama_fx = 31130; move16(); /*0.95f; */ - Copy( &p2a_flags_fx[sub( bands_fx, trans_bit_fx )], &p2a_flags_tmp[sub( bands_fx, trans_bit_fx )], trans_bit_fx ); + Copy( &p2a_flags_fx[bands_fx - trans_bit_fx], &p2a_flags_tmp[bands_fx - trans_bit_fx], trans_bit_fx ); } /* calculate the the low band/high band energy and the variance/avrage of the envelopes */ @@ -429,11 +430,11 @@ void hq_lr_dec_fx( IF( GE_16( i, lowband ) ) { #ifdef BASOP_NOGLOB - Ep_vari_fx = L_add_sat( Ep_vari_fx, L_abs( L_sub_sat( Ep_tmp_fx[i], Ep_tmp_fx[sub( i, 1 )] ) ) ); /*Q15 */ - Ep_avrg_fx = L_add_sat( Ep_avrg_fx, Ep_tmp_fx[i] ); /*Q15 */ + Ep_vari_fx = L_add_sat( Ep_vari_fx, L_abs( L_sub_sat( Ep_tmp_fx[i], Ep_tmp_fx[i - 1] ) ) ); /*Q15 */ + Ep_avrg_fx = L_add_sat( Ep_avrg_fx, Ep_tmp_fx[i] ); /*Q15 */ #else - Ep_vari_fx = L_add( Ep_vari_fx, L_abs( L_sub( Ep_tmp_fx[i], Ep_tmp_fx[sub( i, 1 )] ) ) ); /*Q15 */ - Ep_avrg_fx = L_add( Ep_avrg_fx, Ep_tmp_fx[i] ); /*Q15 */ + Ep_vari_fx = L_add( Ep_vari_fx, L_abs( L_sub( Ep_tmp_fx[i], Ep_tmp_fx[i - 1] ) ) ); /*Q15 */ + Ep_avrg_fx = L_add( Ep_avrg_fx, Ep_tmp_fx[i] ); /*Q15 */ #endif } ELSE @@ -441,7 +442,7 @@ void hq_lr_dec_fx( #ifdef BASOP_NOGLOB Ep_avrgL_fx = L_add_sat( Ep_avrgL_fx, Ep_tmp_fx[i] ); /*Q15 */ #else - Ep_avrgL_fx = L_add( Ep_avrgL_fx, Ep_tmp_fx[i] ); /*Q15 */ + Ep_avrgL_fx = L_add( Ep_avrgL_fx, Ep_tmp_fx[i] ); /*Q15 */ #endif if ( GT_32( Ep_tmp_fx[i], Ep_peak_fx ) ) { @@ -479,7 +480,7 @@ void hq_lr_dec_fx( } ELSE { - FOR( i = sub( bands_fx, trans_bit_fx ); i < bands_fx; i++ ) + FOR( i = bands_fx - trans_bit_fx; i < bands_fx; i++ ) { alpha_fx = 16384; move16(); /*Q14 */ @@ -554,7 +555,7 @@ void hq_lr_dec_fx( move32(); } } - lowband = 3; + lowband = 3; /* Q0 */ move16(); Ep_avrg_fx = L_deposit_l( 0 ); Ep_avrgL_fx = L_deposit_l( 0 ); @@ -605,17 +606,17 @@ void hq_lr_dec_fx( } ELSE IF( *is_transient_fx == 0 && EQ_16( inner_frame, L_FRAME16k ) ) { - bit_budget_fx = sub( bit_budget_fx, 2 ); /* bits in high bands to indicate the last 2 subbands is allocated bits or not */ + bit_budget_fx = sub( bit_budget_fx, 2 ); /* bits in high bands to indicate the last 2 subbands is allocated bits or not Q0*/ FOR( i = 0; i < 2; i++ ) { - last_bitalloc_max_band[i] = get_next_indice_fx( st_fx, 1 ); + last_bitalloc_max_band[i] = get_next_indice_fx( st_fx, 1 ); /* Q0 */ move16(); } FOR( i = 0; i < bands_fx; i++ ) { #ifdef BASOP_NOGLOB - Ep_tmp_fx[i] = L_shl_sat( Ep_tmp_fx[i], 2 ); + Ep_tmp_fx[i] = L_shl_sat( Ep_tmp_fx[i], 2 ); /* Q15 */ #else Ep_tmp_fx[i] = L_shl( Ep_tmp_fx[i], 2 ); #endif @@ -623,21 +624,21 @@ void hq_lr_dec_fx( } IF( EQ_32( st_fx->core_brate, ACELP_13k20 ) ) { - lowband = 8; + lowband = 8; /* Q0 */ move16(); - highband = 15; + highband = 15; /* Q0 */ move16(); - bw_low = sub( band_start[highband], band_start[lowband] ); - bw_high = sub( add( band_end[sub( bands_fx, 1 )], 1 ), band_start[highband] ); + bw_low = sub( band_start[highband], band_start[lowband] ); /* Q0 */ + bw_high = sub( add( band_end[bands_fx - 1], 1 ), band_start[highband] ); /* Q0 */ } ELSE { - lowband = 8; + lowband = 8; /* Q0 */ move16(); - highband = 16; + highband = 16; /* Q0 */ move16(); - bw_low = sub( band_start[highband], band_start[lowband] ); - bw_high = sub( add( band_end[sub( bands_fx, 1 )], 1 ), band_start[highband] ); + bw_low = sub( band_start[highband], band_start[lowband] ); /* Q0 */ + bw_high = sub( add( band_end[bands_fx - 1], 1 ), band_start[highband] ); /* Q0 */ } /* calculate the the low band/high band energy and the variance/avrage of the envelopes */ enerL_fx = L_deposit_l( 0 ); @@ -650,11 +651,11 @@ void hq_lr_dec_fx( IF( GE_16( i, lowband ) && add( sub( i, bands_fx ), p2a_bands_fx ) < 0 ) { #ifdef BASOP_NOGLOB - Ep_vari_fx = L_add_sat( Ep_vari_fx, L_abs( L_sub( Ep_tmp_fx[i], Ep_tmp_fx[sub( i, 1 )] ) ) ); /*Q15 */ - Ep_avrg_fx = L_add_sat( Ep_avrg_fx, Ep_tmp_fx[i] ); /*Q15 */ + Ep_vari_fx = L_add_sat( Ep_vari_fx, L_abs( L_sub( Ep_tmp_fx[i], Ep_tmp_fx[i - 1] ) ) ); /*Q15 */ + Ep_avrg_fx = L_add_sat( Ep_avrg_fx, Ep_tmp_fx[i] ); /*Q15 */ #else - Ep_vari_fx = L_add( Ep_vari_fx, L_abs( L_sub( Ep_tmp_fx[i], Ep_tmp_fx[sub( i, 1 )] ) ) ); /*Q15 */ - Ep_avrg_fx = L_add( Ep_avrg_fx, Ep_tmp_fx[i] ); /*Q15 */ + Ep_vari_fx = L_add( Ep_vari_fx, L_abs( L_sub( Ep_tmp_fx[i], Ep_tmp_fx[i - 1] ) ) ); /*Q15 */ + Ep_avrg_fx = L_add( Ep_avrg_fx, Ep_tmp_fx[i] ); /*Q15 */ #endif } @@ -663,7 +664,7 @@ void hq_lr_dec_fx( #ifdef BASOP_NOGLOB enerH_fx = L_add_sat( enerH_fx, L_shl_sat( Ep_fx[i], 2 ) ); /*Q0 */ #else - enerH_fx = L_add( enerH_fx, L_shl( Ep_fx[i], 2 ) ); /*Q0 */ + enerH_fx = L_add( enerH_fx, L_shl( Ep_fx[i], 2 ) ); /*Q0 */ #endif } ELSE IF( GE_16( i, lowband ) ) @@ -671,7 +672,7 @@ void hq_lr_dec_fx( #ifdef BASOP_NOGLOB enerL_fx = L_add_sat( enerL_fx, L_shl_sat( Ep_fx[i], 2 ) ); /*Q0 */ #else - enerL_fx = L_add( enerL_fx, L_shl( Ep_fx[i], 2 ) ); /*Q0 */ + enerL_fx = L_add( enerL_fx, L_shl( Ep_fx[i], 2 ) ); /*Q0 */ #endif } } @@ -685,7 +686,7 @@ void hq_lr_dec_fx( L_tmp = Mult_32_16( L_shl( enerH_fx, i ), shl( bw_low, j ) ); /* i + j -15 */ L_tmp2 = Mult_32_16( L_shl( enerL_fx, i ), shl( bw_high, j ) ); /*i + j -15 */ L_tmp2 = L_sub( L_tmp, L_tmp2 ); - FOR( i = sub( bands_fx, p2a_bands_fx ); i < bands_fx; i++ ) + FOR( i = bands_fx - p2a_bands_fx; i < bands_fx; i++ ) { test(); IF( EQ_16( p2a_flags_fx[i], 1 ) || L_tmp2 > 0 ) @@ -696,7 +697,7 @@ void hq_lr_dec_fx( #ifdef BASOP_NOGLOB tmp1 = extract_h( L_shl_sat( Ep_avrg_fx, 1 ) ); /*Q0 */ #else - tmp1 = extract_h( L_shl( Ep_avrg_fx, 1 ) ); /*Q0 */ + tmp1 = extract_h( L_shl( Ep_avrg_fx, 1 ) ); /*Q0 */ #endif IF( tmp1 != 0 ) { @@ -734,7 +735,7 @@ void hq_lr_dec_fx( IF( add( sub( i, bands_fx ), p2a_bands_fx ) > 0 ) { tmp = sub( bands_fx, p2a_bands_fx ); - IF( EQ_16( last_bitalloc_max_band[sub( i, add( tmp, 1 ) )], 1 ) ) + IF( EQ_16( last_bitalloc_max_band[i - ( tmp + 1 )], 1 ) ) { tmp = sub( tmp, lowband ); L_tmp = Mult_32_16( Ep_tmp_fx[i], tmp ); /*Q(15+0-15 = 0) */ @@ -887,11 +888,11 @@ void hq_lr_dec_fx( spt_shorten_domain_band_restore_fx( bands_fx, band_start, band_end, band_width, org_band_start, org_band_end, org_band_width ); } - Copy32( L_y2, L_y2_org, L_FRAME32k ); + Copy32( L_y2, L_y2_org, L_FRAME32k ); /* Q12 */ /* Inject noise into components having relatively low pulse energy per band */ ni_seed_fx = add( add( add( npulses_fx[0], npulses_fx[1] ), npulses_fx[2] ), npulses_fx[3] ); - Copy32( L_y2, L_y2_ni, band_end[bands_fx - 1] + 1 ); + Copy32( L_y2, L_y2_ni, band_end[bands_fx - 1] + 1 ); /* Q12 */ hq2_noise_inject_fx( L_y2_ni, band_start, band_end, band_width, Ep_fx, L_Rk, npulses_fx, ni_seed_fx, bands_fx, 0, bw_low, bw_high, enerL_fx, enerH_fx, hHQ_core->last_ni_gain_fx, hHQ_core->last_env_fx, &hHQ_core->last_max_pos_pulse, p2a_flags_fx, p2a_bands_fx, @@ -924,16 +925,16 @@ void hq_lr_dec_fx( } } } - Copy32( L_y2_ni, L_y2, lowlength_fx ); + Copy32( L_y2_ni, L_y2, lowlength_fx ); /* Q12 */ } ELSE { - Copy32( L_y2_ni, L_y2, add( band_end[bands_fx - 1], 1 ) ); /* HQ_TRANSIENT */ + Copy32( L_y2_ni, L_y2, add( band_end[bands_fx - 1], 1 ) ); /* HQ_TRANSIENT Q12*/ } } ELSE { - Copy32( L_y2_ni, L_y2, add( band_end[bands_fx - 1], 1 ) ); /* NB, WB */ + Copy32( L_y2_ni, L_y2, add( band_end[bands_fx - 1], 1 ) ); /* NB, WB Q12*/ } test(); @@ -942,7 +943,7 @@ void hq_lr_dec_fx( k1_fx = sub( bands_fx, 2 ); if ( NE_16( *is_transient_fx, 1 ) ) { - k1_fx = sub( bands_fx, 6 ); + k1_fx = sub( bands_fx, 6 ); /* Q1 */ } L_tmp = L_deposit_l( 0 ); FOR( i = k1_fx; i < bands_fx; i++ ) @@ -950,7 +951,7 @@ void hq_lr_dec_fx( tmp = div_s( 1, sub( bands_fx, k1_fx ) ); /*Q15 */ L_tmp = L_add( L_tmp, Mult_32_16( Ep_tmp_fx[i], tmp ) ); /*Q15 */ } - st_fx->prev_ener_shb_fx = extract_l( L_shr( L_tmp, 14 ) ); + st_fx->prev_ener_shb_fx = extract_l( L_shr( L_tmp, 14 ) ); /* Q1 */ move16(); } test(); @@ -972,26 +973,26 @@ void hq_lr_dec_fx( *--------------------------------------------------------------------------------------*/ static Word16 small_symbol_dec_tran_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - Word16 *qbidx, /* o : output of dequantized differential energy */ - const Word16 bands, /* i : number of bands */ - const Word16 is_transient /* i : transient flag */ + Decoder_State *st_fx, /* i/o: decoder state structure Q0*/ + Word16 *qbidx, /* o : output of dequantized differential energy Q0*/ + const Word16 bands, /* i : number of bands Q0*/ + const Word16 is_transient /* i : transient flag Q0*/ ) { Word16 i, bits; Word16 difidx[BANDS_MAX]; /* Decoding differential energies*/ - bits = decode_envelope_indices_fx( st_fx, 0, bands, 0, difidx, LOW_RATE_HQ_CORE_TRAN, is_transient ); - bits = add( bits, BITS_DE_FCOMP ); + bits = decode_envelope_indices_fx( st_fx, 0, bands, 0, difidx, LOW_RATE_HQ_CORE_TRAN, is_transient ); /* Q0 */ + bits = add( bits, BITS_DE_FCOMP ); /* Q0 */ /* counting 1 bit for band_energy_huff_coding_mode */ - bits = add( bits, BITS_DE_HMODE ); + bits = add( bits, BITS_DE_HMODE ); /* Q0 */ /* converting to original values */ FOR( i = 0; i < bands; i++ ) { - qbidx[i] = sub( difidx[i], LRMDCT_BE_OFFSET ); + qbidx[i] = sub( difidx[i], LRMDCT_BE_OFFSET ); /* Q0 */ move16(); } @@ -1005,41 +1006,41 @@ static Word16 small_symbol_dec_tran_fx( * Huffman decoding of differential energies (MSB and LSB) *--------------------------------------------------------------------------*/ -static Word16 small_symbol_dec_fx( /* o : bits */ +static Word16 small_symbol_dec_fx( /* o : bits Q0*/ Decoder_State *st_fx, /* i/o: decoder state structure */ - Word16 *qbidx, /* o : output of dequantized differential energy */ - const Word16 bands, /* i : number of bands */ + Word16 *qbidx, /* o : output of dequantized differential energy Q0*/ + const Word16 bands, /* i : number of bands Q0*/ const Word16 is_transient ) { Word16 i, LSB, bits; Word16 difidx[BANDS_MAX]; /* Decoding MSB bits */ - bits = decode_envelope_indices_fx( st_fx, 0, bands, 0, difidx, LOW_RATE_HQ_CORE, is_transient ); - bits = add( bits, BITS_DE_FCOMP ); + bits = decode_envelope_indices_fx( st_fx, 0, bands, 0, difidx, LOW_RATE_HQ_CORE, is_transient ); /* Q0 */ + bits = add( bits, BITS_DE_FCOMP ); /* Q0 */ /* counting 1 bit for band_energy_huff_coding_mode */ - bits = add( bits, BITS_DE_HMODE ); + bits = add( bits, BITS_DE_HMODE ); /* Q0 */ /* Decoding LSB bit packing */ FOR( i = 0; i < bands; ++i ) { - LSB = get_next_indice_fx( st_fx, BITS_DE_LSB ); - difidx[i] = s_or( shl( difidx[i], 1 ), LSB ); + LSB = get_next_indice_fx( st_fx, BITS_DE_LSB ); /* Q0 */ + difidx[i] = s_or( shl( difidx[i], 1 ), LSB ); /* Q0 */ move16(); } /* counting bits for LSB */ - bits = add( bits, bands ); + bits = add( bits, bands ); /* Q0 */ /* converting to original values */ FOR( i = 1; i < bands; ++i ) { - qbidx[i] = sub( difidx[i], DE_OFFSET1 ); + qbidx[i] = sub( difidx[i], DE_OFFSET1 ); /* Q0 */ move16(); } - qbidx[0] = sub( difidx[0], DE_OFFSET0 ); + qbidx[0] = sub( difidx[0], DE_OFFSET0 ); /* Q0 */ move16(); return ( bits ); @@ -1048,18 +1049,19 @@ static Word16 small_symbol_dec_fx( /* o : bits static Word16 decode_huff_8s_fx( Decoder_State *st_fx, - const Word16 *hufftab, - Word16 *rbits ) + const Word16 *hufftab, /* Q0 */ + Word16 *rbits /* Q0 */ +) { Word16 bit; WHILE( *hufftab > 0 ) { - *rbits = add( *rbits, s_and( *hufftab, 0xf ) ); + *rbits = add( *rbits, s_and( *hufftab, 0xf ) ); /* Q0 */ move16(); - bit = get_next_indice_fx( st_fx, s_and( *hufftab, 0xf ) ); + bit = get_next_indice_fx( st_fx, s_and( *hufftab, 0xf ) ); /* Q0 */ move16(); - hufftab += add( shr( *hufftab, 4 ), bit ); + hufftab += add( shr( *hufftab, 4 ), bit ); /* Q0 */ } return negate( *hufftab ); @@ -1067,8 +1069,8 @@ static Word16 decode_huff_8s_fx( static Word16 large_symbol_dec_fx( /* o : bits */ Decoder_State *st_fx, /* i/o: decoder state structure */ - Word16 *qbidx, /* o : output of dequantized differential energy */ - const Word16 bands /* i : number of bands */ + Word16 *qbidx, /* o : output of dequantized differential energy Q0*/ + const Word16 bands /* i : number of bands Q0*/ ) { Word16 i, bits; @@ -1077,29 +1079,29 @@ static Word16 large_symbol_dec_fx( /* o : bits Word16 pos_outlyer; Word16 ns2mode0, ns2mode1; - cntbits = BITS_DE_8SMODE; + cntbits = BITS_DE_8SMODE; /* Q0 */ move16(); - ns2mode = get_next_indice_fx( st_fx, BITS_DE_8SMODE ); + ns2mode = get_next_indice_fx( st_fx, BITS_DE_8SMODE ); /* Q0 */ IF( ns2mode == 0 ) { - ns2mode0 = get_next_indice_fx( st_fx, BITS_DE_8SMODE_N0 ); - ns2mode1 = get_next_indice_fx( st_fx, BITS_DE_8SMODE_N1 ); - cntbits = add( cntbits, BITS_DE_8SMODE_N0 + BITS_DE_8SMODE_N1 ); + ns2mode0 = get_next_indice_fx( st_fx, BITS_DE_8SMODE_N0 ); /* Q0 */ + ns2mode1 = get_next_indice_fx( st_fx, BITS_DE_8SMODE_N1 ); /* Q0 */ + cntbits = add( cntbits, BITS_DE_8SMODE_N0 + BITS_DE_8SMODE_N1 ); /* Q0 */ IF( ns2mode0 == 0 ) { IF( EQ_16( ns2mode1, 1 ) ) { - pos_outlyer = get_next_indice_fx( st_fx, BITS_DE_8SPOS ); - cntbits = add( cntbits, BITS_DE_8SPOS ); - qbidx[pos_outlyer] = sub( get_next_indice_fx( st_fx, BITS_ABS_ENG ), ABS_ENG_OFFSET ); + pos_outlyer = get_next_indice_fx( st_fx, BITS_DE_8SPOS ); /* Q0 */ + cntbits = add( cntbits, BITS_DE_8SPOS ); /* Q0 */ + qbidx[pos_outlyer] = sub( get_next_indice_fx( st_fx, BITS_ABS_ENG ), ABS_ENG_OFFSET ); /* Q0 */ move16(); - cntbits = add( cntbits, BITS_ABS_ENG ); + cntbits = add( cntbits, BITS_ABS_ENG ); /* Q0 */ } ELSE { - pos_outlyer = -1; + pos_outlyer = -1; /* Q0 */ move16(); } @@ -1107,84 +1109,84 @@ static Word16 large_symbol_dec_fx( /* o : bits { bits = 0; move16(); - qbidx[i] = sub( decode_huff_8s_fx( st_fx, hestable, &bits ), 4 ); + qbidx[i] = sub( decode_huff_8s_fx( st_fx, hestable, &bits ), 4 ); /* Q0 */ move16(); - cntbits = add( cntbits, bits ); + cntbits = add( cntbits, bits ); /* Q0 */ } - FOR( i = add( pos_outlyer, 1 ); i < bands; ++i ) + FOR( i = pos_outlyer + 1; i < bands; ++i ) { bits = 0; move16(); - qbidx[i] = sub( decode_huff_8s_fx( st_fx, hestable, &bits ), 4 ); + qbidx[i] = sub( decode_huff_8s_fx( st_fx, hestable, &bits ), 4 ); /* Q0 */ move16(); - cntbits = add( cntbits, bits ); + cntbits = add( cntbits, bits ); /* Q0 */ } } ELSE { IF( EQ_16( ns2mode1, 1 ) ) { - pos_outlyer = get_next_indice_fx( st_fx, BITS_DE_8SPOS ); - cntbits = add( cntbits, BITS_DE_8SPOS ); - qbidx[0] = sub( get_next_indice_fx( st_fx, BITS_ABS_ENG ), ABS_ENG_OFFSET ); + pos_outlyer = get_next_indice_fx( st_fx, BITS_DE_8SPOS ); /* Q0 */ + cntbits = add( cntbits, BITS_DE_8SPOS ); /* Q0 */ + qbidx[0] = sub( get_next_indice_fx( st_fx, BITS_ABS_ENG ), ABS_ENG_OFFSET ); /* Q0 */ move16(); - cntbits = add( cntbits, BITS_ABS_ENG ); - qbidx[pos_outlyer] = sub( get_next_indice_fx( st_fx, BITS_ABS_ENG ), ABS_ENG_OFFSET ); + cntbits = add( cntbits, BITS_ABS_ENG ); /* Q0 */ + qbidx[pos_outlyer] = sub( get_next_indice_fx( st_fx, BITS_ABS_ENG ), ABS_ENG_OFFSET ); /* Q0 */ move16(); - cntbits = add( cntbits, BITS_ABS_ENG ); + cntbits = add( cntbits, BITS_ABS_ENG ); /* Q0 */ } ELSE { pos_outlyer = 0; move16(); - qbidx[0] = sub( get_next_indice_fx( st_fx, BITS_ABS_ENG ), ABS_ENG_OFFSET ); + qbidx[0] = sub( get_next_indice_fx( st_fx, BITS_ABS_ENG ), ABS_ENG_OFFSET ); /* Q0 */ move16(); - cntbits = add( cntbits, BITS_ABS_ENG ); + cntbits = add( cntbits, BITS_ABS_ENG ); /* Q0 */ } FOR( i = 1; i < pos_outlyer; ++i ) { bits = 0; move16(); - qbidx[i] = sub( decode_huff_8s_fx( st_fx, hestable, &bits ), 4 ); + qbidx[i] = sub( decode_huff_8s_fx( st_fx, hestable, &bits ), 4 ); /* Q0 */ move16(); - cntbits = add( cntbits, bits ); + cntbits = add( cntbits, bits ); /* Q0 */ } FOR( i = pos_outlyer + 1; i < bands; ++i ) { bits = 0; move16(); - qbidx[i] = sub( decode_huff_8s_fx( st_fx, hestable, &bits ), 4 ); + qbidx[i] = sub( decode_huff_8s_fx( st_fx, hestable, &bits ), 4 ); /* Q0 */ move16(); - cntbits = add( cntbits, bits ); + cntbits = add( cntbits, bits ); /* Q0 */ } } } ELSE { - basic_shift = get_next_indice_fx( st_fx, BITS_MAX_DEPTH ); - cntbits = add( cntbits, BITS_MAX_DEPTH ); + basic_shift = get_next_indice_fx( st_fx, BITS_MAX_DEPTH ); /* Q0 */ + cntbits = add( cntbits, BITS_MAX_DEPTH ); /* Q0 */ FOR( i = 0; i < bands; ++i ) { bits = 0; move16(); - qbidx[i] = sub( decode_huff_8s_fx( st_fx, hestable, &bits ), 4 ); + qbidx[i] = sub( decode_huff_8s_fx( st_fx, hestable, &bits ), 4 ); /* Q0 */ move16(); - qbidx[i] = shl( qbidx[i], basic_shift ); + qbidx[i] = shl( qbidx[i], basic_shift ); /* Q0 */ move16(); - cntbits = add( cntbits, bits ); + cntbits = add( cntbits, bits ); /* Q0 */ } FOR( i = 0; i < bands; ++i ) { - LSB[0] = get_next_indice_fx( st_fx, basic_shift ); + LSB[0] = get_next_indice_fx( st_fx, basic_shift ); /* Q0 */ move16(); - qbidx[i] = add( qbidx[i], LSB[0] ); + qbidx[i] = add( qbidx[i], LSB[0] ); /* Q0 */ move16(); - cntbits = add( cntbits, basic_shift ); + cntbits = add( cntbits, basic_shift ); /* Q0 */ } } @@ -1199,12 +1201,13 @@ static Word16 large_symbol_dec_fx( /* o : bits *--------------------------------------------------------------------------*/ static Word16 band_energy_dequant_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - Word32 L_band_energy[], /* o : Q14 band energy */ - const Word16 bands_fx, - const Word32 L_qint, - const Word16 eref_fx, - const Word16 is_transient_fx ) + Decoder_State *st_fx, /* i/o: decoder state structure */ + Word32 L_band_energy[], /* o : band energy Q14*/ + const Word16 bands_fx, /* Q0 */ + const Word32 L_qint, /* Q0 */ + const Word16 eref_fx, /* Q0 */ + const Word16 is_transient_fx /* Q0 */ +) { Word16 k; Word16 deng_cmode; @@ -1221,28 +1224,28 @@ static Word16 band_energy_dequant_fx( /* parsing energy difference coding mode */ - deng_cmode = get_next_indice_fx( st_fx, BITS_DE_CMODE ); + deng_cmode = get_next_indice_fx( st_fx, BITS_DE_CMODE ); /* Q0 */ IF( deng_cmode == 0 ) { - deng_bits = large_symbol_dec_fx( st_fx, bq2_fx, bands_fx ); + deng_bits = large_symbol_dec_fx( st_fx, bq2_fx, bands_fx ); /* Q0 */ /* counting 1 bit for deng coding mode */ - deng_bits = add( deng_bits, BITS_DE_CMODE ); + deng_bits = add( deng_bits, BITS_DE_CMODE ); /* Q0 */ } ELSE { IF( is_transient_fx ) { - deng_bits = small_symbol_dec_tran_fx( st_fx, bq2_fx, bands_fx, is_transient_fx ); + deng_bits = small_symbol_dec_tran_fx( st_fx, bq2_fx, bands_fx, is_transient_fx ); /* Q0 */ } ELSE { - deng_bits = small_symbol_dec_fx( st_fx, bq2_fx, bands_fx, is_transient_fx ); + deng_bits = small_symbol_dec_fx( st_fx, bq2_fx, bands_fx, is_transient_fx ); /* Q0 */ } /* counting 1 bit for deng coding mode */ - deng_bits = add( deng_bits, BITS_DE_CMODE ); + deng_bits = add( deng_bits, BITS_DE_CMODE ); /* Q0 */ } exp_normd = norm_l( L_qint ); @@ -1281,10 +1284,10 @@ static Word16 band_energy_dequant_fx( *--------------------------------------------------------------------------*/ static Word16 p2a_threshold_dequant_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - Word16 *p2a_flags, /* o : tonaly indicator */ - const Word16 bands, /* i : number of subbands */ - const Word16 p2a_bands /* i : number of subbnads for computing tonality */ + Decoder_State *st_fx, /* i/o: decoder state structure */ + Word16 *p2a_flags, /* o : tonaly indicator Q0*/ + const Word16 bands, /* i : number of subbands Q0*/ + const Word16 p2a_bands /* i : number of subbnads for computing tonality Q0*/ ) { Word16 j, k; @@ -1292,17 +1295,17 @@ static Word16 p2a_threshold_dequant_fx( j = sub( bands, p2a_bands ); FOR( k = 0; k < j; k++ ) { - p2a_flags[k] = 1; + p2a_flags[k] = 1; /* Q0 */ move16(); } j = 0; move16(); - FOR( k = sub( bands, p2a_bands ); k < bands; k++ ) + FOR( k = bands - p2a_bands; k < bands; k++ ) { - p2a_flags[k] = get_next_indice_fx( st_fx, 1 ); + p2a_flags[k] = get_next_indice_fx( st_fx, 1 ); /* Q0 */ move16(); - j = add( j, 1 ); + j++; } return ( j ); @@ -1348,11 +1351,11 @@ static void mdct_spectrum_fine_gain_dec_fx( exp_normn = norm_l( L_qint ); exp_normn = sub( exp_normn, 1 ); exp_normd = norm_s( gqlevs ); - delta_fx = div_l( L_shl( L_qint, exp_normn ), shl( gqlevs, exp_normd ) ); - Qdelta = add( sub( exp_normn, exp_normd ), 28 ); /* 29+exp_normn-(exp_normd)-1; */ - L_delta = L_shl( L_deposit_h( delta_fx ), sub( 13, Qdelta ) ); + delta_fx = div_l( L_shl( L_qint, exp_normn ), shl( gqlevs, exp_normd ) ); /* Q15 */ + Qdelta = add( sub( exp_normn, exp_normd ), 28 ); /* 29+exp_normn-(exp_normd)-1; */ + L_delta = L_shl( L_deposit_h( delta_fx ), sub( 13, Qdelta ) ); /* Q18 - Qdelta */ - L_q = L_shr( L_sub( L_delta, L_qint ), 1 ); + L_q = L_shr( L_sub( L_delta, L_qint ), 1 ); /* Q -1*/ FOR( i = 0; i < gqlevs; i++ ) { @@ -1369,9 +1372,9 @@ static void mdct_spectrum_fine_gain_dec_fx( move16(); } - FOR( k = sub( bands, Ngq ); k < bands; k++ ) + FOR( k = bands - Ngq; k < bands; k++ ) { - imin_fx = get_next_indice_fx( st_fx, gqbits ); + imin_fx = get_next_indice_fx( st_fx, gqbits ); /* Q0 */ /*gamma = gain_table[imin]; */ gamma_fx = gain_table_fx[imin_fx]; @@ -1382,12 +1385,12 @@ static void mdct_spectrum_fine_gain_dec_fx( /* This IF statement for keeping same mantissa evenif y2 is plus or minus */ IF( L_y2[i] >= 0x0 ) { - L_y2[i] = L_shl( Mpy_32_16_1( L_y2[i], gamma_fx ), 1 ); + L_y2[i] = L_shl( Mpy_32_16_1( L_y2[i], gamma_fx ), 1 ); /* Q12 */ move32(); } ELSE { - L_y2[i] = L_negate( L_shl( Mpy_32_16_1( L_abs( L_y2[i] ), gamma_fx ), 1 ) ); + L_y2[i] = L_negate( L_shl( Mpy_32_16_1( L_abs( L_y2[i] ), gamma_fx ), 1 ) ); /* Q12 */ move32(); } } diff --git a/lib_dec/lsf_dec_fx.c b/lib_dec/lsf_dec_fx.c index 5d7313b21..a81e22f25 100644 --- a/lib_dec/lsf_dec_fx.c +++ b/lib_dec/lsf_dec_fx.c @@ -29,32 +29,32 @@ static void dqlsf_CNG_fx( Decoder_State *st_fx, Word16 *lsf_q ); ----------------------------------------------------------------------------------------*/ static void dqlsf_CNG_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - Word16 *lsf_q /* o : decoded LSFs */ + Decoder_State *st_fx, /* i/o: decoder state structure */ + Word16 *lsf_q /* o : decoded LSFs Q9*/ ) { Word16 indice[4]; Word16 ber_flag; - indice[0] = (Word16) get_next_indice_fx( st_fx, 4 ); + indice[0] = (Word16) get_next_indice_fx( st_fx, 4 ); /* Q0 */ move16(); - indice[1] = (Word16) get_next_indice_fx( st_fx, LEN_INDICE ); + indice[1] = (Word16) get_next_indice_fx( st_fx, LEN_INDICE ); /* Q0 */ move16(); - indice[2] = (Word16) get_next_indice_fx( st_fx, LSF_BITS_CNG - 4 - LEN_INDICE ); + indice[2] = (Word16) get_next_indice_fx( st_fx, LSF_BITS_CNG - 4 - LEN_INDICE ); /* Q0 */ move16(); /* deindex_lvq_cng decoder does not need to know the sampling rate, the sampling rate data is embedded inside the LSF coefficients */ IF( st_fx->element_mode == EVS_MONO ) { ber_flag = - deindex_lvq_cng_fx( &indice[1], lsf_q, indice[0], LSF_BITS_CNG - 4, &st_fx->offset_scale1_fx[0][0], &st_fx->offset_scale2_fx[0][0], &st_fx->no_scales_fx[0][0] ); + deindex_lvq_cng_fx( &indice[1], lsf_q, indice[0], LSF_BITS_CNG - 4, &st_fx->offset_scale1_fx[0][0], &st_fx->offset_scale2_fx[0][0], &st_fx->no_scales_fx[0][0] ); /* Q0 */ } ELSE { ber_flag = - deindex_lvq_cng_ivas_fx( &indice[1], lsf_q, indice[0], LSF_BITS_CNG - 4 ); + deindex_lvq_cng_ivas_fx( &indice[1], lsf_q, indice[0], LSF_BITS_CNG - 4 ); /* Q0 */ } - st_fx->BER_detect = s_or( ber_flag, st_fx->BER_detect ); + st_fx->BER_detect = s_or( ber_flag, st_fx->BER_detect ); /* Q0 */ move16(); /* The sampling frequency of the LP-CNG frame can be determined by checking the value of the highest order LSF coefficient (last coefficient). @@ -67,7 +67,7 @@ static void dqlsf_CNG_fx( test(); IF( ( ( EQ_16( st_fx->L_frame, L_FRAME16k ) ) && ( LE_16( lsf_q[M - 1], WB_LIMIT_LSF_FX ) ) ) || ( ( LT_16( st_fx->L_frame, L_FRAME16k ) ) && ( GT_16( lsf_q[M - 1], WB_LIMIT_LSF_FX ) ) ) ) { - st_fx->BER_detect = 1; + st_fx->BER_detect = 1; /* Q0 */ move16(); } @@ -102,17 +102,17 @@ static void dqlsf_CNG_fx( /* _ None */ /*===========================================================================*/ void lsf_dec_fx( - Decoder_State *st_fx, /* i/o: State structure */ - const Word16 tc_subfr, /* i : TC subframe index */ - Word16 *Aq, /* o : quantized A(z) for 4 subframes */ - Word16 *LSF_Q_prediction, /* o : LSF prediction mode */ - Word16 *lsf_new, /* o : de-quantized LSF vector */ - Word16 *lsp_new, /* o : de-quantized LSP vector */ - Word16 *lsp_mid, /* o : de-quantized mid-frame LSP vector */ - const Word16 tdm_low_rate_mode /* i : secondary channel low rate mode flag */ + Decoder_State *st_fx, /* i/o: State structure */ + const Word16 tc_subfr, /* i : TC subframe index Q0*/ + Word16 *Aq, /* o : quantized A(z) for 4 subframes Q12*/ + Word16 *LSF_Q_prediction, /* o : LSF prediction mode Q0*/ + Word16 *lsf_new, /* o : de-quantized LSF vector Q(x2.56)*/ + Word16 *lsp_new, /* o : de-quantized LSP vector Q15*/ + Word16 *lsp_mid, /* o : de-quantized mid-frame LSP vector Q15*/ + const Word16 tdm_low_rate_mode /* i : secondary channel low rate mode flag Q0*/ #if defined LSF_RE_USE_SECONDARY_CHANNEL || defined FIX_798_LSF_SECONDARY_CH_MISSING_CODE , - const Word16 tdm_lsfQ_PCh[M] /* i : Q LSFs for primary channel */ + const Word16 tdm_lsfQ_PCh[M] /* i : Q LSFs for primary channel Qx*/ #endif ) { @@ -132,13 +132,13 @@ void lsf_dec_fx( coder_type = st_fx->coder_type; if ( EQ_32( st_fx->core_brate, SID_2k40 ) ) { - coder_type = INACTIVE; + coder_type = INACTIVE; /* Q0 */ move16(); } test(); if ( EQ_16( coder_type, AUDIO ) && st_fx->GSC_IVAS_mode > 0 ) { - coder_type = GENERIC; + coder_type = GENERIC; /* Q0 */ move16(); } no_param_lpc = 0; @@ -149,7 +149,7 @@ void lsf_dec_fx( /* Find the number of bits for LSF quantization */ IF( EQ_32( st_fx->core_brate, SID_2k40 ) ) { - nBits = LSF_BITS_CNG; + nBits = LSF_BITS_CNG; /* Q0 */ move16(); } ELSE @@ -157,25 +157,25 @@ void lsf_dec_fx( test(); IF( st_fx->nelp_mode_dec == 0 && st_fx->ppp_mode_dec == 0 ) { - nBits = st_fx->acelp_cfg.lsf_bits; + nBits = st_fx->acelp_cfg.lsf_bits; /* Q0 */ move16(); } ELSE IF( EQ_16( st_fx->nelp_mode_dec, 1 ) ) { IF( EQ_16( coder_type, UNVOICED ) ) { - nBits = 30; + nBits = 30; /* Q0 */ move16(); if ( st_fx->bwidth == NB ) { - nBits = 32; + nBits = 32; /* Q0 */ move16(); } } } ELSE IF( EQ_16( st_fx->ppp_mode_dec, 1 ) ) { - nBits = 26; + nBits = 26; /* Q0 */ move16(); } } @@ -197,10 +197,10 @@ void lsf_dec_fx( { st_fx->seed_acelp = 0; move16(); - FOR( i = sub( no_param_lpc, 1 ); i >= 0; i-- ) + FOR( i = no_param_lpc - 1; i >= 0; i-- ) { /* rightshift before *seed_acelp+param_lpc[i] to avoid overflows*/ - st_fx->seed_acelp = extract_l( L_add( imult3216( 31821L, add( shr( ( st_fx->seed_acelp ), 1 ), param_lpc[i] ) ), 13849L ) ); + st_fx->seed_acelp = extract_l( L_add( imult3216( 31821L /* Q0 */, add( shr( ( st_fx->seed_acelp ), 1 ), param_lpc[i] ) ), 13849L /* Q0 */ ) ); /* Q0 */ move16(); // PMTE() /*IVAS_CODE to be completed */ } @@ -240,7 +240,7 @@ void lsf_dec_fx( FOR( i = 1; i < M; i++ ) { - st_fx->lsf_old_fx[i] = add( st_fx->lsf_old_fx[i - 1], lsf_diff ); + st_fx->lsf_old_fx[i] = add( st_fx->lsf_old_fx[i - 1], lsf_diff ); /* Q2.56 */ move16(); } lsf2lsp_fx( st_fx->lsf_old_fx, st_fx->lsp_old_fx, M, st_fx->sr_core ); @@ -252,8 +252,8 @@ void lsf_dec_fx( IF( st_fx->rate_switching_reset ) { /*extrapolation in case of unstable LSF convert*/ - Copy( lsp_new, st_fx->lsp_old_fx, M ); - Copy( lsf_new, st_fx->lsf_old_fx, M ); + Copy( lsp_new, st_fx->lsp_old_fx, M ); /* Q15 */ + Copy( lsf_new, st_fx->lsf_old_fx, M ); /* Q2.56 */ } { /* Mid-frame LSF decoding */ @@ -267,10 +267,10 @@ void lsf_dec_fx( { /* check, if LSP interpolation can be relaxed */ E_LPC_f_lsp_a_conversion( st_fx->lsp_old_fx, tmp_old, M ); - enr_old = Enr_1_Az_fx( tmp_old, 2 * L_SUBFR ); + enr_old = Enr_1_Az_fx( tmp_old, 2 * L_SUBFR ); /* Q3 */ E_LPC_f_lsp_a_conversion( lsp_new, tmp_new, M ); - enr_new = Enr_1_Az_fx( tmp_new, 2 * L_SUBFR ); + enr_new = Enr_1_Az_fx( tmp_new, 2 * L_SUBFR ); /* Q3 */ IF( LT_16( enr_new, mult_r( 9830 /*0.3 Q15*/, enr_old ) ) ) { @@ -293,8 +293,8 @@ void lsf_dec_fx( IF( EQ_16( st_fx->last_core, HQ_CORE ) && st_fx->core == ACELP_CORE ) { /* update old LSPs/LSFs in case of HQ->ACELP core switching */ - Copy( lsp_mid, st_fx->lsp_old_fx, M ); - lsp2lsf_fx( lsp_mid, st_fx->lsf_old_fx, M, st_fx->sr_core ); + Copy( lsp_mid, st_fx->lsp_old_fx, M ); /* Q15 */ + lsp2lsf_fx( lsp_mid, st_fx->lsf_old_fx, M, st_fx->sr_core ); /* Q15 */ } test(); IF( EQ_16( tdm_low_rate_mode, 1 ) && GT_16( coder_type, UNVOICED ) ) @@ -302,9 +302,9 @@ void lsf_dec_fx( // PMT("To be verified") IF( EQ_16( st_fx->active_cnt, 1 ) ) { - Copy( lsp_mid, st_fx->lsp_old_fx, M ); - lsp2lsf_fx( lsp_mid, st_fx->lsf_old_fx, M, st_fx->sr_core ); - Copy( lsp_new, lsp_mid, M ); + Copy( lsp_mid, st_fx->lsp_old_fx, M ); /* Q15 */ + lsp2lsf_fx( lsp_mid, st_fx->lsf_old_fx, M, st_fx->sr_core ); /* Q15 */ + Copy( lsp_new, lsp_mid, M ); /* Q15 */ } /* LSP interpolation and conversion of LSPs to A(z) - two-subframe mode */ @@ -326,7 +326,7 @@ void lsf_dec_fx( } ELSE { - st_fx->stab_fac_fx = lsf_stab_ivas_fx( lsf_new, st_fx->lsf_old_fx, 0, st_fx->L_frame ); + st_fx->stab_fac_fx = lsf_stab_ivas_fx( lsf_new, st_fx->lsf_old_fx, 0, st_fx->L_frame ); /* Q15 */ move16(); } @@ -369,18 +369,18 @@ void lsf_dec_fx( /*========================================================================*/ void lsf_end_dec_fx( - Decoder_State *st, /* i/o: decoder state structure */ - Word16 mode2_flag, - const Word16 coder_type_org, /* i : coding type */ - const Word16 bwidth, /* i : input signal bandwidth */ - const Word16 nBits_in, /* i : number of bits used for ISF quantization*/ - Word16 *qlsf, /* o : quantized LSFs in the cosine domain */ - Word16 *lpc_param, /* i : LPC parameters */ - Word16 *LSF_Q_prediction, /* o : LSF prediction mode */ - Word16 *nb_indices /* o : number of indices */ + Decoder_State *st, /* i/o: decoder state structure */ + Word16 mode2_flag, /* Q0 */ + const Word16 coder_type_org, /* i : coding type Q0*/ + const Word16 bwidth, /* i : input signal bandwidth Q0*/ + const Word16 nBits_in, /* i : number of bits used for ISF quantization Q0*/ + Word16 *qlsf, /* o : quantized LSFs in the cosine domain Qx2.56*/ + Word16 *lpc_param, /* i : LPC parameters Q0*/ + Word16 *LSF_Q_prediction, /* o : LSF prediction mode Q0*/ + Word16 *nb_indices /* o : number of indices Q0*/ #if defined LSF_RE_USE_SECONDARY_CHANNEL || defined FIX_798_LSF_SECONDARY_CH_MISSING_CODE , - const Word16 tdm_lsfQ_PCh[M] /* i : Q LSFs for primary channel */ + const Word16 tdm_lsfQ_PCh[M] /* i : Q LSFs for primary channel Qx*/ #endif ) { @@ -409,9 +409,9 @@ void lsf_end_dec_fx( #if defined LSF_RE_USE_SECONDARY_CHANNEL || defined FIX_798_LSF_SECONDARY_CH_MISSING_CODE Word16 pred3[M]; #endif - flag_1bit_gran = (Word16) GT_16( st->element_mode, EVS_MONO ); + flag_1bit_gran = (Word16) ( st->element_mode > EVS_MONO ); /* Q0 */ - nBits = nBits_in; + nBits = nBits_in; /* Q0 */ *nb_indices = 0; move16(); move16(); @@ -427,18 +427,18 @@ void lsf_end_dec_fx( #endif { /* this bit is used only for primary channel or mono */ - coder_type = (Word16) get_next_indice_fx( st, 1 ); - coder_type = add( coder_type, 2 ); + coder_type = (Word16) get_next_indice_fx( st, 1 ); /* Q0 */ + coder_type = add( coder_type, 2 ); /* Q0 */ test(); test(); if ( EQ_16( coder_type, GENERIC ) || ( EQ_16( coder_type, VOICED ) && EQ_16( flag_1bit_gran, 1 ) ) ) { - nBits = sub( nBits, 1 ); + nBits = sub( nBits, 1 ); /* Q0 */ } } ELSE { - coder_type = coder_type_org; + coder_type = coder_type_org; /* Q0 */ move16(); } @@ -475,16 +475,16 @@ void lsf_end_dec_fx( { /* if secondary channel predmode is set to be > 2 */ /*predmode += 3;*/ - predmode = add( predmode, 3 ); + predmode = add( predmode, 3 ); /* Q0 */ } #endif - p_lpc_param = lpc_param; + p_lpc_param = lpc_param; /* Q0 */ move16(); IF( predmode == 0 ) { - safety_net = 1; + safety_net = 1; /* Q0 */ move16(); } ELSE IF( predmode == 1 ) @@ -499,18 +499,18 @@ void lsf_end_dec_fx( IF( EQ_16( mode2_flag, 1 ) || EQ_16( st->core, TCX_20_CORE ) || EQ_16( st->core, TCX_10_CORE ) ) { /* read from param_lpc */ - safety_net = p_lpc_param[0]; + safety_net = p_lpc_param[0]; /* Q0 */ move16(); p_lpc_param++; - *nb_indices = add( *nb_indices, 1 ); + *nb_indices = add( *nb_indices, 1 ); /* Q0 */ } ELSE { - safety_net = (Word16) get_next_indice_fx( st, 1 ); + safety_net = (Word16) get_next_indice_fx( st, 1 ); /* Q0 */ } } - st->safety_net = safety_net; + st->safety_net = safety_net; /* Q0 */ move16(); /*--------------------------------------------------------------------------* @@ -523,9 +523,9 @@ void lsf_end_dec_fx( { /* use same AR prediction bit allocation for intra and inter modes*/ lsf_allocate_fx( sub( nBits, 1 ), mode_lvq, 9, &stages0, &stages1, levels0, levels1, bits0, bits1 ); - stages0 = stages1; - Copy( levels1, levels0, stages0 ); - Copy( bits1, bits0, stages0 ); + stages0 = stages1; /* Q0 */ + Copy( levels1, levels0, stages0 ); /* Q0 */ + Copy( bits1, bits0, stages0 ); /* Q0 */ } #endif @@ -538,24 +538,24 @@ void lsf_end_dec_fx( test(); IF( EQ_16( st->codec_mode, MODE2 ) || EQ_16( st->core, TCX_20_CORE ) || EQ_16( st->core, TCX_10_CORE ) ) { - *nb_indices = 10; + *nb_indices = 10; /* Q0 */ move16(); - TCQIdx[0] = safety_net; + TCQIdx[0] = safety_net; /* Q0 */ move16(); FOR( i = 1; i < *nb_indices; i++ ) { - TCQIdx[i] = *p_lpc_param++; + TCQIdx[i] = *p_lpc_param++; /* Q0 */ move16(); } } ELSE { - Bit_alloc1 = &BC_TCVQ_BIT_ALLOC_40B[1]; - TCQIdx[0] = safety_net; + Bit_alloc1 = &BC_TCVQ_BIT_ALLOC_40B[1]; /* Q0 */ + TCQIdx[0] = safety_net; /* Q0 */ move16(); FOR( i = 0; i < M / 2 + 3; i++ ) { - TCQIdx[i + 1] = get_next_indice_fx( st, Bit_alloc1[i] ); + TCQIdx[i + 1] = get_next_indice_fx( st, Bit_alloc1[i] ); /* Q0 */ move16(); } } @@ -564,20 +564,20 @@ void lsf_end_dec_fx( { IF( safety_net ) { - stages = stages0; + stages = stages0; /* Q0 */ move16(); - levels = levels0; + levels = levels0; /* Q0 */ move16(); - bits = bits0; + bits = bits0; /* Q0 */ move16(); } ELSE { - stages = stages1; + stages = stages1; /* Q0 */ move16(); - levels = levels1; + levels = levels1; /* Q0 */ move16(); - bits = bits1; + bits = bits1; /* Q0 */ move16(); } test(); @@ -586,19 +586,19 @@ void lsf_end_dec_fx( { FOR( i = 0; i < sub( stages, 1 ); i++ ) { - num_bits = bits[i]; + num_bits = bits[i]; /* Q0 */ move16(); - lindice[i + 1] = *p_lpc_param++; + lindice[i + 1] = *p_lpc_param++; /* Q0 */ move16(); } - cumleft = levels[stages - 1]; + cumleft = levels[stages - 1]; /* Q0 */ move16(); WHILE( cumleft > 0 ) { IF( GT_16( cumleft, LEN_INDICE ) ) { - cumleft = sub( cumleft, LEN_INDICE ); + cumleft = sub( cumleft, LEN_INDICE ); /* Q0 */ } ELSE { @@ -606,43 +606,43 @@ void lsf_end_dec_fx( move16(); } - lindice[i + 1] = *p_lpc_param++; + lindice[i + 1] = *p_lpc_param++; /* Q0 */ move16(); - i = add( i, 1 ); + i++; } - *nb_indices = add( *nb_indices, i ); + *nb_indices = add( *nb_indices, i ); /* Q0 */ move16(); } ELSE { FOR( i = 0; i < stages - 1; i++ ) { - num_bits = bits[i]; + num_bits = bits[i]; /* Q0 */ move16(); - lindice[i + 1] = (Word16) get_next_indice_fx( st, num_bits ); + lindice[i + 1] = (Word16) get_next_indice_fx( st, num_bits ); /* Q0 */ move16(); } - cumleft = levels[sub( stages, 1 )]; + cumleft = levels[stages - 1]; /* Q0 */ WHILE( cumleft > 0 ) { IF( GT_16( cumleft, LEN_INDICE ) ) { - cumleft = sub( cumleft, LEN_INDICE ); - num_bits = LEN_INDICE; + cumleft = sub( cumleft, LEN_INDICE ); /* Q0 */ + num_bits = LEN_INDICE; /* Q0 */ move16(); } ELSE { - num_bits = (Word16) cumleft; + num_bits = (Word16) cumleft; /* Q0 */ move16(); cumleft = 0; move16(); } - lindice[i + 1] = (Word16) get_next_indice_fx( st, num_bits ); + lindice[i + 1] = (Word16) get_next_indice_fx( st, num_bits ); /* Q0 */ move16(); - i = add( i, 1 ); + i++; } } } @@ -650,7 +650,7 @@ void lsf_end_dec_fx( { FOR( i = 0; i < M; i++ ) { - st->mem_AR_fx[i] = ModeMeans_fx[mode_lvq][i]; + st->mem_AR_fx[i] = ModeMeans_fx[mode_lvq][i]; /* Q2.56 */ move16(); } st->reset_mem_AR = 0; @@ -661,7 +661,7 @@ void lsf_end_dec_fx( * De-quantize LSF vector *------------------------------------------------------------------------------------------*/ - *LSF_Q_prediction = SAFETY_NET; + *LSF_Q_prediction = SAFETY_NET; /* Q0 */ move16(); /* VOICED_WB@16kHz */ test(); @@ -669,14 +669,14 @@ void lsf_end_dec_fx( IF( EQ_32( st->sr_core, INT_FS_16k ) && EQ_16( coder_type, VOICED ) && flag_1bit_gran == 0 ) { /* BC-TCVQ decoder */ - safety_net = qlsf_ARSN_tcvq_Dec_16k_fx( qlsf, TCQIdx, sub( nBits, 1 ) ); + safety_net = qlsf_ARSN_tcvq_Dec_16k_fx( qlsf, TCQIdx, sub( nBits, 1 ) ); /* Q0 */ /* Update mem_MA */ - Copy( qlsf, st->mem_MA_fx, M ); + Copy( qlsf, st->mem_MA_fx, M ); /* Q2.56 */ IF( safety_net ) { - Copy( ModeMeans_fx[mode_lvq], pred0, M ); + Copy( ModeMeans_fx[mode_lvq], pred0, M ); /* Q2.56 */ } ELSE { @@ -685,7 +685,7 @@ void lsf_end_dec_fx( pred0[i] = add( ModeMeans_fx[mode_lvq][i], mult( Predictors_fx[mode_lvq_p][i], ( sub( st->mem_AR_fx[i], ModeMeans_fx[mode_lvq][i] ) ) ) ); /* Q(x2.56)*/ move16(); } - *LSF_Q_prediction = AUTO_REGRESSIVE; + *LSF_Q_prediction = AUTO_REGRESSIVE; /* Q0 */ move16(); } Vr_add( qlsf, pred0, qlsf, M ); @@ -694,11 +694,11 @@ void lsf_end_dec_fx( { /* Safety-net */ - Copy( ModeMeans_fx[mode_lvq], pred0, M ); + Copy( ModeMeans_fx[mode_lvq], pred0, M ); /* Q2.56 */ /* for mem_MA update */ FOR( i = 0; i < M; i++ ) { - pred1[i] = add( pred0[i], mult_r( MU_MA_FX, st->mem_MA_fx[i] ) ); + pred1[i] = add( pred0[i], mult_r( MU_MA_FX, st->mem_MA_fx[i] ) ); /* Q2.56 */ move16(); } #if defined LSF_RE_USE_SECONDARY_CHANNEL || defined FIX_798_LSF_SECONDARY_CH_MISSING_CODE @@ -719,7 +719,7 @@ void lsf_end_dec_fx( /* intra mode*/ st->BER_detect = s_or( st->BER_detect, - vq_dec_lvq_ivas_fx( 0, qlsf, &lindice[1], stages0, M, 9, levels0[stages0 - 1] ) ); + vq_dec_lvq_ivas_fx( 0, qlsf, &lindice[1], stages0, M, 9, levels0[stages0 - 1] ) ); /* Q0 */ move16(); Vr_add( qlsf, pred3, qlsf, M ); @@ -730,15 +730,15 @@ void lsf_end_dec_fx( { IF( st->element_mode != EVS_MONO ) { - ber_flag = vq_dec_lvq_ivas_fx( 1, qlsf, &lindice[1], stages0, M, mode_lvq, levels0[stages0 - 1] ); + ber_flag = vq_dec_lvq_ivas_fx( 1, qlsf, &lindice[1], stages0, M, mode_lvq, levels0[stages0 - 1] ); /* Q0 */ } ELSE { ber_flag = vq_dec_lvq_fx( 1, qlsf, &lindice[1], stages0, M, mode_lvq, levels0[stages0 - 1], &st->offset_scale1_fx[0][0], &st->offset_scale2_fx[0][0], &st->offset_scale1_p_fx[0][0], &st->offset_scale2_p_fx[0][0], - &st->no_scales_fx[0][0], &st->no_scales_p_fx[0][0] ); + &st->no_scales_fx[0][0], &st->no_scales_p_fx[0][0] ); /* Q0 */ } - st->BER_detect = s_or( st->BER_detect, ber_flag ); + st->BER_detect = s_or( st->BER_detect, ber_flag ); /* Q0 */ move16(); Vr_add( qlsf, pred0, qlsf, M ); Vr_subt( qlsf, pred1, st->mem_MA_fx, M ); @@ -757,15 +757,15 @@ void lsf_end_dec_fx( #endif IF( st->element_mode != EVS_MONO ) { - ber_flag = vq_dec_lvq_ivas_fx( 0, qlsf, &lindice[1], stages1, M, mode_lvq_p, levels1[stages1 - 1] ); + ber_flag = vq_dec_lvq_ivas_fx( 0, qlsf, &lindice[1], stages1, M, mode_lvq_p, levels1[stages1 - 1] ); /* Q0 */ } ELSE { ber_flag = vq_dec_lvq_fx( 0, qlsf, &lindice[1], stages1, M, mode_lvq_p, levels1[stages1 - 1], &st->offset_scale1_fx[0][0], &st->offset_scale2_fx[0][0], &st->offset_scale1_p_fx[0][0], &st->offset_scale2_p_fx[0][0], - &st->no_scales_fx[0][0], &st->no_scales_p_fx[0][0] ); + &st->no_scales_fx[0][0], &st->no_scales_p_fx[0][0] ); /* Q0 */ } - st->BER_detect = s_or( st->BER_detect, ber_flag ); + st->BER_detect = s_or( st->BER_detect, ber_flag ); /* Q0 */ move16(); #if defined LSF_RE_USE_SECONDARY_CHANNEL || defined FIX_798_LSF_SECONDARY_CH_MISSING_CODE test(); @@ -774,9 +774,9 @@ void lsf_end_dec_fx( IF( EQ_16( predmode, 1 ) ) /* MA only */ #endif { - Copy( qlsf, st->mem_MA_fx, M ); - Vr_add( qlsf, pred1, qlsf, M ); - *LSF_Q_prediction = MOVING_AVERAGE; + Copy( qlsf, st->mem_MA_fx, M ); /* Q2.56 */ + Vr_add( qlsf, pred1, qlsf, M ); /* Q2.56 */ + *LSF_Q_prediction = MOVING_AVERAGE; /* Q0 */ move16(); } ELSE @@ -784,12 +784,12 @@ void lsf_end_dec_fx( /* AR */ FOR( i = 0; i < M; i++ ) { - pred2[i] = add( pred0[i], mult( Predictors_fx[mode_lvq_p][i], sub( st->mem_AR_fx[i], pred0[i] ) ) ); + pred2[i] = add( pred0[i], mult( Predictors_fx[mode_lvq_p][i], sub( st->mem_AR_fx[i], pred0[i] ) ) ); /* Q2.56 */ move16(); } Vr_add( qlsf, pred2, qlsf, M ); Vr_subt( qlsf, pred1, st->mem_MA_fx, M ); - *LSF_Q_prediction = AUTO_REGRESSIVE; + *LSF_Q_prediction = AUTO_REGRESSIVE; /* Q0 */ move16(); } } @@ -807,9 +807,9 @@ void lsf_end_dec_fx( /* Verify stability */ reorder_lsf_fx( qlsf, MODE1_LSF_GAP_FX, M, st->sr_core ); /* Update predictor memory */ - Copy( qlsf, st->mem_AR_fx, M ); + Copy( qlsf, st->mem_AR_fx, M ); /* Q2.56 */ - st->mode_lvq = mode_lvq; + st->mode_lvq = mode_lvq; /* Q0 */ move16(); @@ -839,10 +839,10 @@ void lsf_end_dec_fx( /* _ None */ /*========================================================================*/ void lsf_mid_dec_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - Word16 lsp_new[], /* i : quantized LSPs from frame endSQ15*/ - Word16 coder_type, /* i : Coder type */ - Word16 lsp_mid[] /* o : quantized LSPs Q15*/ + Decoder_State *st_fx, /* i/o: decoder state structure */ + Word16 lsp_new[], /* i : quantized LSPs from frame endS Q15*/ + Word16 coder_type, /* i : Coder type Q0*/ + Word16 lsp_mid[] /* o : quantized LSPs Q15*/ ) { Word16 j, idx; @@ -862,19 +862,19 @@ void lsf_mid_dec_fx( /* Codebook selection */ IF( EQ_16( st_fx->ppp_mode_dec, 1 ) ) { - nb_bits = 1; + nb_bits = 1; /* Q0 */ move16(); - ratio = &tbl_mid_voi_wb_1b_fx[0]; + ratio = &tbl_mid_voi_wb_1b_fx[0]; /* Q13 */ } ELSE IF( EQ_16( st_fx->nelp_mode_dec, 1 ) ) { - nb_bits = 4; + nb_bits = 4; /* Q0 */ move16(); - ratio = &tbl_mid_unv_wb_4b_fx[0]; + ratio = &tbl_mid_unv_wb_4b_fx[0]; /* Q13 */ } ELSE { - nb_bits = st_fx->acelp_cfg.mid_lsf_bits; + nb_bits = st_fx->acelp_cfg.mid_lsf_bits; /* Q0 */ move16(); /* codebook selection */ @@ -885,24 +885,24 @@ void lsf_mid_dec_fx( { case 5: { - ratio = tbl_mid_voi_wb_5b_fx; + ratio = tbl_mid_voi_wb_5b_fx; /* Q13 */ BREAK; } case 4: { - ratio = tbl_mid_voi_wb_4b_fx; + ratio = tbl_mid_voi_wb_4b_fx; /* Q13 */ BREAK; } case 1: { - ratio = tbl_mid_voi_wb_1b_fx; + ratio = tbl_mid_voi_wb_1b_fx; /* Q13 */ break; } } } - ELSE IF( coder_type == UNVOICED ) + ELSE IF( EQ_16( coder_type, UNVOICED ) ) { - ratio = tbl_mid_unv_wb_5b_fx; + ratio = tbl_mid_unv_wb_5b_fx; /* Q13 */ } ELSE { @@ -911,17 +911,17 @@ void lsf_mid_dec_fx( { case 5: { - ratio = tbl_mid_gen_wb_5b_fx; + ratio = tbl_mid_gen_wb_5b_fx; /* Q13 */ BREAK; } case 4: { - ratio = tbl_mid_gen_wb_4b_fx; + ratio = tbl_mid_gen_wb_4b_fx; /* Q13 */ break; } case 2: { - ratio = tbl_mid_gen_wb_2b_fx; + ratio = tbl_mid_gen_wb_2b_fx; /* Q13 */ BREAK; } } @@ -929,7 +929,7 @@ void lsf_mid_dec_fx( } /* Retrieve mid-frame LSF index */ - idx = (Word16) get_next_indice_fx( st_fx, nb_bits ); + idx = (Word16) get_next_indice_fx( st_fx, nb_bits ); /* Q0 */ /* Calculation of mid-LSF vector */ FOR( j = 0; j < M; j++ ) @@ -947,7 +947,7 @@ void lsf_mid_dec_fx( { IF( LT_16( qlsf[j], qlsf[j - 1] ) ) { - bad_spacing = 1; + bad_spacing = 1; /* Q0 */ move16(); BREAK; } @@ -970,7 +970,7 @@ void lsf_mid_dec_fx( test(); IF( j > 0 && LT_16( j, M ) && LT_16( qlsf[j], add( qlsf[j - 1], LSF_GAP_MID_FX ) ) ) { - qlsf[j] = add( qlsf[j - 1], LSF_GAP_MID_FX ); + qlsf[j] = add( qlsf[j - 1], LSF_GAP_MID_FX ); /* Q2.56 */ move16(); } } @@ -984,7 +984,7 @@ void lsf_mid_dec_fx( test(); IF( j > 0 && LT_16( j, M ) && LT_16( qlsf[j], add( qlsf[j - 1], LSF_GAP_MID_FX ) ) ) { - qlsf[j] = add( qlsf[j - 1], LSF_GAP_MID_FX ); + qlsf[j] = add( qlsf[j - 1], LSF_GAP_MID_FX ); /* Q2.56 */ move16(); } } @@ -993,7 +993,7 @@ void lsf_mid_dec_fx( if ( st_fx->prev_bfi ) { /* continue redoing mid-LSF interpolation with 0.4 in order not to propagate the error */ - st_fx->mid_lsf_int = 1; + st_fx->mid_lsf_int = 1; /* Q0 */ move16(); } diff --git a/lib_dec/lsf_msvq_ma_dec_fx.c b/lib_dec/lsf_msvq_ma_dec_fx.c index 167f71d4d..f57aee0e1 100644 --- a/lib_dec/lsf_msvq_ma_dec_fx.c +++ b/lib_dec/lsf_msvq_ma_dec_fx.c @@ -26,7 +26,10 @@ * *---------------------------------------------------------------------*/ -Word16 lsf_msvq_ma_decprm( Decoder_State *st, Word16 *param_lpc ) +Word16 lsf_msvq_ma_decprm( + Decoder_State *st, + Word16 *param_lpc /* Q0 */ +) { Word16 i, nbits_lpc, tmp; Word16 bits_midlpc; @@ -34,7 +37,7 @@ Word16 lsf_msvq_ma_decprm( Decoder_State *st, Word16 *param_lpc ) levels0[MAX_VQ_STAGES], levels1[MAX_VQ_STAGES], *bits; Word16 predmode, mode_lvq, mode_lvq_p, safety_net; - bits_midlpc = 5; + bits_midlpc = 5; /* Q0 */ move16(); test(); @@ -63,54 +66,54 @@ Word16 lsf_msvq_ma_decprm( Decoder_State *st, Word16 *param_lpc ) IF( EQ_16( predmode, 2 ) ) { /* there is choice between SN and AR prediction */ - safety_net = get_next_indice_fx( st, 1 ); + safety_net = get_next_indice_fx( st, 1 ); /* Q0 */ IF( EQ_16( safety_net, 1 ) ) { - stages = stages0; + stages = stages0; /* Q0 */ move16(); - bits = bits0; + bits = bits0; /* Q0 */ move16(); } ELSE { - stages = stages1; + stages = stages1; /* Q0 */ move16(); - bits = bits1; + bits = bits1; /* Q0 */ move16(); } - *param_lpc = safety_net; + *param_lpc = safety_net; /* Q0 */ move16(); param_lpc++; - nbits_lpc++; + nbits_lpc = add( nbits_lpc, 1 ); } ELSE { - stages = stages1; + stages = stages1; /* Q0 */ move16(); - bits = bits1; + bits = bits1; /* Q0 */ move16(); } - tmp = sub( stages, 1 ); + tmp = sub( stages, 1 ); /* Q0 */ FOR( i = 0; i < tmp; i++ ) { - *param_lpc = get_next_indice_fx( st, bits[i] ); + *param_lpc = get_next_indice_fx( st, bits[i] ); /* Q0 */ move16(); param_lpc++; - nbits_lpc = add( nbits_lpc, bits[i] ); + nbits_lpc = add( nbits_lpc, bits[i] ); /* Q0 */ } - *param_lpc = get_next_indice_fx( st, LEN_INDICE ); + *param_lpc = get_next_indice_fx( st, LEN_INDICE ); /* Q0 */ move16(); param_lpc++; - nbits_lpc = add( nbits_lpc, LEN_INDICE ); + nbits_lpc = add( nbits_lpc, LEN_INDICE ); /* Q0 */ - *param_lpc = get_next_indice_fx( st, sub( bits[i], LEN_INDICE ) ); + *param_lpc = get_next_indice_fx( st, sub( bits[i], LEN_INDICE ) ); /* Q0 */ move16(); param_lpc++; - nbits_lpc = add( nbits_lpc, sub( bits[i], LEN_INDICE ) ); + nbits_lpc = add( nbits_lpc, sub( bits[i], LEN_INDICE ) ); /* Q0 */ test(); @@ -118,9 +121,9 @@ Word16 lsf_msvq_ma_decprm( Decoder_State *st, Word16 *param_lpc ) IF( NE_16( st->coder_type, VOICED ) && st->core == 0 && st->acelp_cfg.midLpc ) { - *param_lpc = get_next_indice_fx( st, bits_midlpc ); + *param_lpc = get_next_indice_fx( st, bits_midlpc ); /* Q0 */ move16(); - nbits_lpc = add( nbits_lpc, bits_midlpc ); + nbits_lpc = add( nbits_lpc, bits_midlpc ); /* Q0 */ } return nbits_lpc; @@ -129,15 +132,16 @@ Word16 lsf_msvq_ma_decprm( Decoder_State *st, Word16 *param_lpc ) Word16 lsf_bctcvq_decprm( Decoder_State *st, - Word16 *param_lpc ) + Word16 *param_lpc /* Q0 */ +) { Word16 i, nbits_lpc; Word16 num_par; const Word16 *bits1; - num_par = 10; + num_par = 10; /* Q0 */ move16(); - bits1 = BC_TCVQ_BIT_ALLOC_40B; + bits1 = BC_TCVQ_BIT_ALLOC_40B; /* Q0 */ nbits_lpc = 0; move16(); @@ -145,10 +149,10 @@ Word16 lsf_bctcvq_decprm( FOR( i = 0; i < num_par; i++ ) { - *param_lpc = get_next_indice_fx( st, bits1[i] ); + *param_lpc = get_next_indice_fx( st, bits1[i] ); /* Q0 */ move16(); param_lpc++; - nbits_lpc = add( nbits_lpc, bits1[i] ); + nbits_lpc = add( nbits_lpc, bits1[i] ); /* Q0 */ } return nbits_lpc; @@ -156,12 +160,12 @@ Word16 lsf_bctcvq_decprm( /* Returns: number of indices */ Word16 D_lsf_tcxlpc( - const Word16 indices[], /* i : VQ indices */ - Word16 lsf_q[], /* o : quantized LSF */ - Word16 lsp_q_ind[], /* o :quantized LSP (w/o MA prediction) */ - Word16 narrowband, /* i : narrowband flag */ - Word16 cdk, /* i : codebook selector */ - Word16 mem_MA[] /* i : MA memory */ + const Word16 indices[], /* i : VQ indices Q0*/ + Word16 lsf_q[], /* o : quantized LSF Q1*/ + Word16 lsp_q_ind[], /* o :quantized LSP (w/o MA prediction) Q1*/ + Word16 narrowband, /* i : narrowband flag Q0*/ + Word16 cdk, /* i : codebook selector Q0*/ + Word16 mem_MA[] /* i : MA memory Q1*/ ) { Word16 i; @@ -171,7 +175,7 @@ Word16 D_lsf_tcxlpc( const Word16 *means; Word16 lsf_rem_q_ind[M]; - NumIndices = 1; + NumIndices = 1; /* Q0 */ move16(); msvq_dec( @@ -187,7 +191,7 @@ Word16 D_lsf_tcxlpc( #endif lsf_q ); - NumIndices = add( NumIndices, TCXLPC_NUMSTAGES ); + NumIndices = add( NumIndices, TCXLPC_NUMSTAGES ); /* Q0 */ FOR( i = 0; i < M; ++i ) { @@ -209,32 +213,32 @@ Word16 D_lsf_tcxlpc( 0, NULL, #endif lsf_rem_q_ind ); - NumIndices = add( NumIndices, TCXLPC_IND_NUMSTAGES ); + NumIndices = add( NumIndices, TCXLPC_IND_NUMSTAGES ); /* Q0 */ /* Add to MA-removed vector */ FOR( i = 0; i < M; ++i ) { - lsf_q_ind[i] = add( lsf_q_ind[i], lsf_rem_q_ind[i] ); + lsf_q_ind[i] = add( lsf_q_ind[i], lsf_rem_q_ind[i] ); /* Q1 */ move16(); } } /* Inter-frame prediction */ move16(); - means = lsf_means[narrowband]; + means = lsf_means[narrowband]; /* Q1 */ FOR( i = 0; i < M; ++i ) { - pred[i] = add( means[i], mult_r( MU_MA_FX, mem_MA[i] ) ); + pred[i] = add( means[i], mult_r( MU_MA_FX, mem_MA[i] ) ); /* Q1 */ move16(); } /* Add prediction */ FOR( i = 0; i < M; ++i ) { - lsf_q[i] = add( lsf_q[i], pred[i] ); + lsf_q[i] = add( lsf_q[i], pred[i] ); /* Q1 */ move16(); - lsf_q_ind[i] = add( lsf_q_ind[i], means[i] ); + lsf_q_ind[i] = add( lsf_q_ind[i], means[i] ); /* Q1 */ move16(); } @@ -251,26 +255,26 @@ Word16 D_lsf_tcxlpc( /* Returns: number of bits read */ Word16 dec_lsf_tcxlpc( - Decoder_State *st, /* i/o: Decoder state */ - Word16 **indices, /* o : Ptr to VQ indices */ - Word16 narrowband, /* i : narrowband flag */ - Word16 cdk /* i : codebook selector */ + Decoder_State *st, /* i/o: Decoder state */ + Word16 **indices, /* o : Ptr to VQ indices Q0*/ + Word16 narrowband, /* i : narrowband flag Q0*/ + Word16 cdk /* i : codebook selector Q0*/ ) { Word16 i, start_bit_pos; Word16 lsf_q_ind[M]; Word16 *flag; - flag = *indices; /* Save pointer */ + flag = *indices; /* Save pointer Q0*/ *flag = 0; move16(); /* Set flag to disabled */ ++*indices; - start_bit_pos = st->next_bit_pos; + start_bit_pos = st->next_bit_pos; /* Q0 */ move16(); FOR( i = 0; i < TCXLPC_NUMSTAGES; ++i ) { - **indices = get_next_indice_fx( st, lsf_numbits[i] ); + **indices = get_next_indice_fx( st, lsf_numbits[i] ); /* Q0 */ ++*indices; move16(); } @@ -290,13 +294,13 @@ Word16 dec_lsf_tcxlpc( lsf_q_ind ); /* Update flag */ - *flag = lsf_ind_is_active( lsf_q_ind, lsf_means[narrowband], narrowband, cdk ); + *flag = lsf_ind_is_active( lsf_q_ind, lsf_means[narrowband], narrowband, cdk ); /* Q0 */ move16(); IF( *flag ) { FOR( i = 0; i < TCXLPC_IND_NUMSTAGES; ++i ) { - **indices = get_next_indice_fx( st, lsf_ind_numbits[i] ); + **indices = get_next_indice_fx( st, lsf_ind_numbits[i] ); /* Q0 */ ++*indices; move16(); } diff --git a/lib_dec/nelp_dec_fx.c b/lib_dec/nelp_dec_fx.c index 1f103223e..a1e2bbf39 100644 --- a/lib_dec/nelp_dec_fx.c +++ b/lib_dec/nelp_dec_fx.c @@ -86,7 +86,15 @@ static void normalize_arr( Word16 *arr, Word16 *qf, Word16 size, Word16 hdr ) /* _ None */ /*===================================================================*/ -void nelp_decoder_fx( Decoder_State *st_fx, Word16 *exc_nelp, Word16 *exc, Word16 *Q_exc, Word16 bfi, const Word16 coder_type, Word16 *gain_buf ) +void nelp_decoder_fx( + Decoder_State *st_fx, + Word16 *exc_nelp, /* Q0 */ + Word16 *exc, /* Q_exc */ + Word16 *Q_exc, + Word16 bfi, /* Q0 */ + const Word16 coder_type, /* Q0 */ + Word16 *gain_buf /* Q14 */ +) { Word16 i, fid = 0; move16(); @@ -126,7 +134,7 @@ void nelp_decoder_fx( Decoder_State *st_fx, Word16 *exc_nelp, Word16 *exc, Word1 { IF( NE_16( st_fx->last_nelp_mode_dec, 1 ) ) { - BP1_ORDER = 7; + BP1_ORDER = 7; /* Q0 */ move16(); set32_fx( hSC_VBR->bp1_filt_mem_nb_dec_fx, 0, BP1_ORDER * 2 ); @@ -134,7 +142,7 @@ void nelp_decoder_fx( Decoder_State *st_fx, Word16 *exc_nelp, Word16 *exc, Word1 } ELSE IF( EQ_16( coder_type, UNVOICED ) && ( EQ_16( st_fx->bwidth, WB ) || EQ_16( st_fx->bwidth, SWB ) ) ) { - BP1_ORDER = 4; + BP1_ORDER = 4; /* Q0 */ move16(); IF( NE_16( st_fx->last_nelp_mode_dec, 1 ) ) { @@ -154,21 +162,21 @@ void nelp_decoder_fx( Decoder_State *st_fx, Word16 *exc_nelp, Word16 *exc, Word1 test(); IF( EQ_16( st_fx->rf_frame_type, RF_NELP ) && EQ_16( st_fx->use_partial_copy, 1 ) ) { - iG1 = st_fx->rf_indx_nelp_iG1; + iG1 = st_fx->rf_indx_nelp_iG1; /* Q0 */ move16(); - iG2[0] = st_fx->rf_indx_nelp_iG2[0]; + iG2[0] = st_fx->rf_indx_nelp_iG2[0]; /* Q0 */ move16(); - iG2[1] = st_fx->rf_indx_nelp_iG2[1]; + iG2[1] = st_fx->rf_indx_nelp_iG2[1]; /* Q0 */ move16(); } ELSE { /* Do Unvoiced/NELP Decoding */ - iG1 = (Word16) get_next_indice_fx( st_fx, 5 ); + iG1 = (Word16) get_next_indice_fx( st_fx, 5 ); /* Q0 */ move16(); - iG2[0] = (Word16) get_next_indice_fx( st_fx, 6 ); + iG2[0] = (Word16) get_next_indice_fx( st_fx, 6 ); /* Q0 */ move16(); - iG2[1] = (Word16) get_next_indice_fx( st_fx, 6 ); + iG2[1] = (Word16) get_next_indice_fx( st_fx, 6 ); /* Q0 */ move16(); } @@ -179,12 +187,12 @@ void nelp_decoder_fx( Decoder_State *st_fx, Word16 *exc_nelp, Word16 *exc, Word1 test(); IF( EQ_16( st_fx->rf_frame_type, RF_NELP ) && EQ_16( st_fx->use_partial_copy, 1 ) ) { - fid = st_fx->rf_indx_nelp_fid; + fid = st_fx->rf_indx_nelp_fid; /* Q0 */ move16(); } ELSE { - fid = (Word16) get_next_indice_fx( st_fx, 2 ); + fid = (Word16) get_next_indice_fx( st_fx, 2 ); /* Q0 */ move16(); } } @@ -202,7 +210,7 @@ void nelp_decoder_fx( Decoder_State *st_fx, Word16 *exc_nelp, Word16 *exc, Word1 max_exc_sqr = L_deposit_l( 0 ); FOR( i = 0; i < L_SUBFR; i++ ) { - max_exc_sqr = L_max( max_exc_sqr, exc_sqr[i] ); + max_exc_sqr = L_max( max_exc_sqr, exc_sqr[i] ); /*2*Q_exc */ } IF( max_exc_sqr != 0 ) { @@ -231,7 +239,7 @@ void nelp_decoder_fx( Decoder_State *st_fx, Word16 *exc_nelp, Word16 *exc, Word1 n = norm_l( Gain ); frac = round_fx( L_shl( Gain, n ) ); n = sub( add( n, 24 ), 30 ); - frac = div_s( 16384, frac ); + frac = div_s( 16384, frac ); /* Q15 */ Gain = Isqrt_lc( L_deposit_h( frac ), &n ); /*Q(31-n-exp) */ tmp = round_fx( L_shl( Gain, sub( add( n, exp ), 15 ) ) ); /*Q0 */ } @@ -272,7 +280,7 @@ void nelp_decoder_fx( Decoder_State *st_fx, Word16 *exc_nelp, Word16 *exc, Word1 test(); IF( EQ_16( coder_type, UNVOICED ) && ( EQ_16( st_fx->bwidth, WB ) || EQ_16( st_fx->bwidth, SWB ) ) ) { - BP1_ORDER = 4; + BP1_ORDER = 4; /* Q0 */ move16(); Scale_sig( hSC_VBR->bp1_filt_mem_wb_dec_fx, shl( BP1_ORDER, 1 ), qGain ); /* bring filter prev memory from Q0 to qGain */ pz_filter_sp_fx( bp1_num_coef_wb_fx, bp1_den_coef_wb_fx, ptr, ptr_tmp, hSC_VBR->bp1_filt_mem_wb_dec_fx, @@ -280,18 +288,18 @@ void nelp_decoder_fx( Decoder_State *st_fx, Word16 *exc_nelp, Word16 *exc, Word1 Scale_sig( hSC_VBR->bp1_filt_mem_wb_dec_fx, shl( BP1_ORDER, 1 ), negate( qGain ) ); /* bring filter prev memory from qGain to Q0 */ Scale_sig( ptr_tmp, L_FRAME, -qGain ); /* bring nelp_exc to Q0 */ - Copy( ptr_tmp, ptr, L_FRAME ); + Copy( ptr_tmp, ptr, L_FRAME ); /* Q0 */ } test(); IF( EQ_16( coder_type, UNVOICED ) && ( EQ_16( st_fx->bwidth, NB ) ) ) { - BP1_ORDER = 7; + BP1_ORDER = 7; /* Q0 */ move16(); FOR( i = 0; i < L_FRAME; i++ ) { - max_val = s_max( ptr[i], max_val ); + max_val = s_max( ptr[i], max_val ); /* Q0 */ } tmp = shl( BP1_ORDER, 1 ); FOR( i = 0; i < tmp; i++ ) @@ -306,13 +314,13 @@ void nelp_decoder_fx( Decoder_State *st_fx, Word16 *exc_nelp, Word16 *exc, Word1 IF( norm_val > 0 ) { - Scale_sig32( hSC_VBR->bp1_filt_mem_nb_dec_fx, shl( BP1_ORDER, 1 ), norm_val ); - Scale_sig( ptr, L_FRAME, norm_val ); + Scale_sig32( hSC_VBR->bp1_filt_mem_nb_dec_fx, shl( BP1_ORDER, 1 ), norm_val ); /* norm_val */ + Scale_sig( ptr, L_FRAME, norm_val ); /* norm_val + Q_exc */ *Q_exc = add( norm_val, *Q_exc ); move16(); } - BP1_ORDER = 7; + BP1_ORDER = 7; /* Q0 */ move16(); pz_filter_dp_fx( bp1_num_coef_nb_fx_order7, bp1_den_coef_nb_fx_order7, ptr, ptr_tmp, hSC_VBR->bp1_filt_mem_nb_dec_fx, BP1_ORDER, BP1_ORDER, L_FRAME, ( sub( 16, BP1_COEF_NB_QF_ORDER7 ) ) ); diff --git a/lib_enc/init_enc.c b/lib_enc/init_enc.c index cb326efb2..6e051302f 100644 --- a/lib_enc/init_enc.c +++ b/lib_enc/init_enc.c @@ -902,6 +902,10 @@ ivas_error init_encoder( st->hTcxEnc->spectrum[0] = st->hTcxEnc->spectrum_long; st->hTcxEnc->spectrum[1] = st->hTcxEnc->spectrum_long + N_TCX10_MAX; +#ifdef MSAN_FIX + set32_fx( st->hTcxEnc->spectrum_fx[0], 0, N_TCX10_MAX ); + set32_fx( st->hTcxEnc->spectrum_fx[1], 0, N_TCX10_MAX ); +#endif set_f( st->hTcxEnc->old_out, 0, L_FRAME32k ); /* MDCT selector */ diff --git a/lib_enc/ivas_core_enc.c b/lib_enc/ivas_core_enc.c index 48e175a43..20ac14fb6 100644 --- a/lib_enc/ivas_core_enc.c +++ b/lib_enc/ivas_core_enc.c @@ -1101,9 +1101,11 @@ ivas_error ivas_core_enc( fb_tbe_enc( st, st->input, fb_exc ); #else #ifdef IVAS_FLOAT_FIXED_CONVERSIONS +#ifndef MSAN_FIX Q_fb_exc = Q_factor_arr( fb_exc, L_FRAME16k ); floatToFixed_arr( fb_exc, fb_exc_fx, Q_fb_exc, L_FRAME16k ); - // Q_input is being calculated inside already +#endif + // Q_input is being calculated inside already Word16 Q_input = 0; floatToFixed_arr( st->input_buff, st->input_buff_fx, Q_input, L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ) ); Word16 len_old_input_fhb_fx = NS2SA( 48000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_12k8_NS + DELAY_FIR_RESAMPL_NS ) - L_FRAME48k / 2; diff --git a/lib_enc/ivas_core_pre_proc.c b/lib_enc/ivas_core_pre_proc.c index 9e8ba1410..7902d1cf8 100644 --- a/lib_enc/ivas_core_pre_proc.c +++ b/lib_enc/ivas_core_pre_proc.c @@ -1138,7 +1138,9 @@ ivas_error ivas_compute_core_buffers( Word16 inp16k_out_buf_fx[2][L_FRAME16k]; Word16 **inp16k_out_fx = (Word16 **) inp16k_out_buf_fx; Word16 new_inp_resamp16k_out_fx[L_FRAME16k]; - +#ifdef MSAN_FIX + set16_fx( new_inp_resamp16k_fx, 0, L_FRAME16k ); +#endif signal_in_32fx = st->input32_fx; signal_in_fx = st->input_fx; diff --git a/lib_enc/ivas_dirac_enc.c b/lib_enc/ivas_dirac_enc.c index 2a10d92d7..beeec44b7 100644 --- a/lib_enc/ivas_dirac_enc.c +++ b/lib_enc/ivas_dirac_enc.c @@ -625,12 +625,8 @@ ivas_error ivas_dirac_enc( { for ( band_m_idx = 0; band_m_idx < hDirAC->hConfig->nbands; band_m_idx++ ) { - hQMetaData->q_direction->band_data[band_m_idx].azimuth[block_m_idx] = fix_to_float( hQMetaData->q_direction->band_data[band_m_idx].azimuth_fx[block_m_idx], Q22 ); - hQMetaData->q_direction->band_data[band_m_idx].elevation[block_m_idx] = fix_to_float( hQMetaData->q_direction->band_data[band_m_idx].elevation_fx[block_m_idx], Q22 ); if ( hodirac_flag ) { - hQMetaData->q_direction[1].band_data[band_m_idx].azimuth[block_m_idx] = fix_to_float( hQMetaData->q_direction[1].band_data[band_m_idx].azimuth_fx[block_m_idx], Q22 ); - hQMetaData->q_direction[1].band_data[band_m_idx].elevation[block_m_idx] = fix_to_float( hQMetaData->q_direction[1].band_data[band_m_idx].elevation_fx[block_m_idx], Q22 ); hQMetaData->q_direction[1].band_data[band_m_idx].energy_ratio[block_m_idx] = fix_to_float( hQMetaData->q_direction[1].band_data[band_m_idx].energy_ratio_fx[block_m_idx], Q30 ); } else @@ -682,18 +678,51 @@ ivas_error ivas_dirac_enc( #endif - if ( hQMetaData->q_direction->cfg.nbands > 0 ) + IF( hQMetaData->q_direction->cfg.nbands > 0 ) { orig_dirac_bands = hQMetaData->q_direction[0].cfg.nbands; - if ( dtx_vad == 1 ) + IF( EQ_16( dtx_vad, 1 ) ) { /* WB 4TC mode bit : disable for now*/ push_next_indice( hMetaData, 0, 1 ); /* Set Energy Ratio to 0.0 if the mono flag is set, before the metadata is encoded */ - if ( hQMetaData->dirac_mono_flag ) + IF( hQMetaData->dirac_mono_flag ) { +#ifdef IVAS_FLOAT_FIXED + IF( EQ_16( dtx_vad, 1 ) ) + { + FOR( b = hQMetaData->q_direction->cfg.start_band; b < hQMetaData->q_direction->cfg.nbands; b++ ) + { + FOR( i_ts = 0; i_ts < hQMetaData->q_direction[0].cfg.nblocks; i_ts++ ) + { +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + hQMetaData->q_direction[0].band_data[b].energy_ratio[i_ts] = 0.0f; +#endif + hQMetaData->q_direction[0].band_data[b].energy_ratio_fx[i_ts] = 0; + hQMetaData->q_direction[0].band_data[b].azimuth_fx[i_ts] = 0; + hQMetaData->q_direction[0].band_data[b].elevation_fx[i_ts] = 0; + } + } + } + ELSE + { + FOR( b = hQMetaData->q_direction->cfg.start_band; b < hQMetaData->q_direction->cfg.nbands; b++ ) + { + FOR( i_ts = 0; i_ts < 1; i_ts++ ) + { +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + hQMetaData->q_direction[0].band_data[b].energy_ratio[i_ts] = 0.0f; +#endif + hQMetaData->q_direction[0].band_data[b].energy_ratio_fx[i_ts] = 0; + hQMetaData->q_direction[0].band_data[b].azimuth_fx[i_ts] = 0; + hQMetaData->q_direction[0].band_data[b].elevation_fx[i_ts] = 0; + } + } + } + +#else for ( b = hQMetaData->q_direction->cfg.start_band; b < hQMetaData->q_direction->cfg.nbands; b++ ) { for ( i_ts = 0; i_ts < ( ( dtx_vad == 1 ) ? hQMetaData->q_direction[0].cfg.nblocks : 1 ); i_ts++ ) @@ -703,6 +732,7 @@ ivas_error ivas_dirac_enc( hQMetaData->q_direction[0].band_data[b].elevation[i_ts] = 0.0f; } } +#endif } #ifdef IVAS_FLOAT_FIXED_CONVERSIONS @@ -711,8 +741,6 @@ ivas_error ivas_dirac_enc( for ( j = hQMetaData->q_direction[0].cfg.start_band; j < hQMetaData->q_direction[0].cfg.nbands; ++j ) { floatToFixed_arrL( hQMetaData->q_direction[i].band_data[j].energy_ratio, hQMetaData->q_direction[i].band_data[j].energy_ratio_fx, Q30, MAX_PARAM_SPATIAL_SUBFRAMES ); - floatToFixed_arrL( hQMetaData->q_direction[i].band_data[j].azimuth, hQMetaData->q_direction[i].band_data[j].azimuth_fx, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); - floatToFixed_arrL( hQMetaData->q_direction[i].band_data[j].elevation, hQMetaData->q_direction[i].band_data[j].elevation_fx, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); #ifndef MSAN_FIX floatToFixed_arrL( hQMetaData->q_direction[i].band_data[j].q_azimuth, hQMetaData->q_direction[i].band_data[j].q_azimuth_fx, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); floatToFixed_arrL( hQMetaData->q_direction[i].band_data[j].q_elevation, hQMetaData->q_direction[i].band_data[j].q_elevation_fx, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); @@ -720,7 +748,7 @@ ivas_error ivas_dirac_enc( } } #endif - if ( ( error = ivas_qmetadata_enc_encode_fx( hMetaData, hQMetaData, hodirac_flag ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_qmetadata_enc_encode_fx( hMetaData, hQMetaData, hodirac_flag ) ) != IVAS_ERR_OK ) { return error; } @@ -730,17 +758,14 @@ ivas_error ivas_dirac_enc( for ( j = hQMetaData->q_direction[0].cfg.start_band; j < hQMetaData->q_direction[0].cfg.nbands; ++j ) { fixedToFloat_arrL( hQMetaData->q_direction[i].band_data[j].energy_ratio_fx, hQMetaData->q_direction[i].band_data[j].energy_ratio, Q30, MAX_PARAM_SPATIAL_SUBFRAMES ); - /*fixedToFloat_arrL( hQMetaData->q_direction[i].band_data[j].azimuth_fx, hQMetaData->q_direction[i].band_data[j].azimuth, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); - fixedToFloat_arrL( hQMetaData->q_direction[i].band_data[j].elevation_fx, hQMetaData->q_direction[i].band_data[j].elevation, Q22, MAX_PARAM_SPATIAL_SUBFRAMES );*/ - fixedToFloat_arrL( hQMetaData->q_direction[i].band_data[j].q_azimuth_fx, hQMetaData->q_direction[i].band_data[j].q_azimuth, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); - fixedToFloat_arrL( hQMetaData->q_direction[i].band_data[j].q_elevation_fx, hQMetaData->q_direction[i].band_data[j].q_elevation, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); } } #endif } - else + ELSE { hQMetaData->q_direction[0].cfg.nbands = DIRAC_DTX_BANDS; + move16(); /* compute directions */ for ( i = 0; i < hQMetaData->q_direction[0].cfg.nblocks; i++ ) @@ -753,11 +778,6 @@ ivas_error ivas_dirac_enc( for ( j = 0; j < orig_dirac_bands - 1; j++ ) { #ifdef IVAS_FLOAT_FIXED - /*==========================================flt-2-fix======================================================*/ - hQMetaData->q_direction[0].band_data[j].azimuth_fx[i] = floatToFixed( hQMetaData->q_direction[0].band_data[j].azimuth[i], Q22 ); - hQMetaData->q_direction[0].band_data[j].elevation_fx[i] = floatToFixed( hQMetaData->q_direction[0].band_data[j].elevation[i], Q22 ); - /*==========================================flt-2-fix======================================================*/ - ivas_qmetadata_azimuth_elevation_to_direction_vector_fx( hQMetaData->q_direction[0].band_data[j].azimuth_fx[i], hQMetaData->q_direction[0].band_data[j].elevation_fx[i], &dir_fx[0] ); /*==========================================fix-2-flt======================================================*/ @@ -784,18 +804,18 @@ ivas_error ivas_dirac_enc( /*==========================================flt-2-fix======================================================*/ ivas_qmetadata_direction_vector_to_azimuth_elevation_fx( &avg_dir_fx[0], Q30, &hQMetaData->q_direction[0].band_data[0].azimuth_fx[i], &hQMetaData->q_direction[0].band_data[0].elevation_fx[i] ); - - /*==========================================fix-2-flt======================================================*/ - hQMetaData->q_direction[0].band_data[0].azimuth[i] = fixedToFloat( hQMetaData->q_direction[0].band_data[0].azimuth_fx[i], Q22 ); - hQMetaData->q_direction[0].band_data[0].elevation[i] = fixedToFloat( hQMetaData->q_direction[0].band_data[0].elevation_fx[i], Q22 ); - /*==========================================fix-2-flt======================================================*/ #else ivas_qmetadata_direction_vector_to_azimuth_elevation( &avg_dir[0], &hQMetaData->q_direction[0].band_data[0].azimuth[i], &hQMetaData->q_direction[0].band_data[0].elevation[i] ); #endif hQMetaData->q_direction[0].band_data[0].energy_ratio[i] = sqrtf( dotp( avg_dir, avg_dir, 3 ) ) / ( energySum + EPSILON ); +#ifdef IVAS_FLOAT_FIXED + hQMetaData->q_direction[0].band_data[1].azimuth_fx[i] = hQMetaData->q_direction[0].band_data[orig_dirac_bands - 1].azimuth_fx[i]; + hQMetaData->q_direction[0].band_data[1].elevation_fx[i] = hQMetaData->q_direction[0].band_data[orig_dirac_bands - 1].elevation_fx[i]; +#else hQMetaData->q_direction[0].band_data[1].azimuth[i] = hQMetaData->q_direction[0].band_data[orig_dirac_bands - 1].azimuth[i]; hQMetaData->q_direction[0].band_data[1].elevation[i] = hQMetaData->q_direction[0].band_data[orig_dirac_bands - 1].elevation[i]; +#endif hQMetaData->q_direction[0].band_data[1].energy_ratio[i] = hQMetaData->q_direction[0].band_data[orig_dirac_bands - 1].energy_ratio[i]; } @@ -804,62 +824,58 @@ ivas_error ivas_dirac_enc( /* encode SID parameters */ #ifdef IVAS_FLOAT_FIXED -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - IVAS_QDIRECTION *q_direction; - q_direction = &( hQMetaData->q_direction[0] ); - - FOR( b = 0; b < q_direction->cfg.nbands; b++ ) - { - FOR( int m = 0; m < q_direction->cfg.nblocks; m++ ) - { - q_direction->band_data[b].azimuth_fx[m] = floatToFixed( q_direction->band_data[b].azimuth[m], Q22 ); - q_direction->band_data[b].elevation_fx[m] = floatToFixed( q_direction->band_data[b].elevation[m], Q22 ); - } - } -#endif ivas_qmetadata_enc_sid_encode_fx( hMetaData, hQMetaData, -1, SBA_FORMAT ); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - FOR( b = 0; b < q_direction->cfg.nbands; b++ ) - { - q_direction->band_data[b].q_azimuth[0] = fixedToFloat( q_direction->band_data[b].q_azimuth_fx[0], Q22 ); - q_direction->band_data[b].q_elevation[0] = fixedToFloat( q_direction->band_data[b].q_elevation_fx[0], Q22 ); - } -#endif #else ivas_qmetadata_enc_sid_encode( hMetaData, hQMetaData, -1, SBA_FORMAT ); #endif } - for ( b = hQMetaData->q_direction->cfg.start_band; b < hQMetaData->q_direction->cfg.nbands; b++ ) + FOR( b = hQMetaData->q_direction->cfg.start_band; b < hQMetaData->q_direction->cfg.nbands; b++ ) { - for ( i_ts = 0; i_ts < ( ( dtx_vad == 1 ) ? hQMetaData->q_direction[0].cfg.nblocks : 1 ); i_ts++ ) + FOR( i_ts = 0; i_ts < ( ( dtx_vad == 1 ) ? hQMetaData->q_direction[0].cfg.nblocks : 1 ); i_ts++ ) { +#ifdef IVAS_FLOAT_FIXED + hQMetaData->q_direction->band_data[b].azimuth_fx[i_ts] = hQMetaData->q_direction->band_data[b].q_azimuth_fx[i_ts]; + hQMetaData->q_direction->band_data[b].elevation_fx[i_ts] = hQMetaData->q_direction->band_data[b].q_elevation_fx[i_ts]; +#else hQMetaData->q_direction->band_data[b].azimuth[i_ts] = hQMetaData->q_direction->band_data[b].q_azimuth[i_ts]; hQMetaData->q_direction->band_data[b].elevation[i_ts] = hQMetaData->q_direction->band_data[b].q_elevation[i_ts]; +#endif hQMetaData->q_direction[0].band_data[b].energy_ratio[0] = 1.0f - diffuseness_reconstructions[hQMetaData->q_direction[0].band_data[b].energy_ratio_index[0]]; } } - if ( dtx_vad == 0 ) + IF( dtx_vad == 0 ) { - for ( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) + FOR( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) { +#ifdef IVAS_FLOAT_FIXED + hQMetaData->q_direction[0].band_data[orig_dirac_bands - 1].azimuth_fx[i] = hQMetaData->q_direction[0].band_data[1].azimuth_fx[0]; + hQMetaData->q_direction[0].band_data[orig_dirac_bands - 1].elevation_fx[i] = hQMetaData->q_direction[0].band_data[1].elevation_fx[0]; +#else hQMetaData->q_direction[0].band_data[orig_dirac_bands - 1].azimuth[i] = hQMetaData->q_direction[0].band_data[1].azimuth[0]; hQMetaData->q_direction[0].band_data[orig_dirac_bands - 1].elevation[i] = hQMetaData->q_direction[0].band_data[1].elevation[0]; +#endif hQMetaData->q_direction[0].band_data[orig_dirac_bands - 1].energy_ratio[i] = hQMetaData->q_direction[0].band_data[1].energy_ratio[0]; } - for ( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) + FOR( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) { - for ( j = orig_dirac_bands - 2; j >= 0; j-- ) + FOR( j = orig_dirac_bands - 2; j >= 0; j-- ) { +#ifdef IVAS_FLOAT_FIXED + hQMetaData->q_direction[0].band_data[j].azimuth_fx[i] = hQMetaData->q_direction[0].band_data[0].azimuth_fx[0]; + hQMetaData->q_direction[0].band_data[j].elevation_fx[i] = hQMetaData->q_direction[0].band_data[0].elevation_fx[0]; +#else hQMetaData->q_direction[0].band_data[j].azimuth[i] = hQMetaData->q_direction[0].band_data[0].azimuth[0]; hQMetaData->q_direction[0].band_data[j].elevation[i] = hQMetaData->q_direction[0].band_data[0].elevation[0]; +#endif hQMetaData->q_direction[0].band_data[j].energy_ratio[i] = hQMetaData->q_direction[0].band_data[0].energy_ratio[0]; } } hQMetaData->q_direction->cfg.nbands = orig_dirac_bands; + move16(); } } diff --git a/lib_enc/ivas_enc.c b/lib_enc/ivas_enc.c index 978bb371f..c41736176 100644 --- a/lib_enc/ivas_enc.c +++ b/lib_enc/ivas_enc.c @@ -863,19 +863,27 @@ ivas_error ivas_enc( if ( st_ivas->hQMetaData != NULL && ivas_format == MASA_FORMAT ) { - ivas_masa_estimate_energy( st_ivas->hMasa, data_f, input_frame, st_ivas->nchan_transport ); /* energy-estimation uses TF-resolution: 4x24 */ - #ifdef IVAS_FLOAT_FIXED #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - for ( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) + for ( i = 0; i < st_ivas->nchan_transport; i++ ) { - for ( int j = 0; j < MASA_FREQUENCY_BANDS; j++ ) - { - f2me( st_ivas->hMasa->data.energy[i][j], &st_ivas->hMasa->data.energy_fx[i][j], &st_ivas->hMasa->data.energy_e[i][j] ); - } + floatToFixed_arrL( st_ivas->hMasa->data.cldfbAnaEnc[i]->cldfb_state, st_ivas->hMasa->data.cldfbAnaEnc[i]->cldfb_state_fx, Q11, st_ivas->hMasa->data.cldfbAnaEnc[i]->cldfb_state_length ); } +#endif -#endif // IVAS_FLOAT_FIXED_CONVERSIONS + ivas_masa_estimate_energy_fx( st_ivas->hMasa, data_fx, input_frame, st_ivas->nchan_transport, st_ivas->q_data_fx ); /* energy-estimation uses TF-resolution: 4x24 */ + +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + for ( i = 0; i < st_ivas->nchan_transport; i++ ) + { + fixedToFloat_arrL( st_ivas->hMasa->data.cldfbAnaEnc[i]->cldfb_state_fx, st_ivas->hMasa->data.cldfbAnaEnc[i]->cldfb_state, Q11, st_ivas->hMasa->data.cldfbAnaEnc[i]->cldfb_state_length ); + } +#endif +#else + ivas_masa_estimate_energy( st_ivas->hMasa, data_f, input_frame, st_ivas->nchan_transport ); /* energy-estimation uses TF-resolution: 4x24 */ +#endif + +#ifdef IVAS_FLOAT_FIXED if ( ( error = ivas_masa_enc_config_fx( st_ivas ) ) != IVAS_ERR_OK ) { return error; @@ -885,13 +893,9 @@ ivas_error ivas_enc( { for ( int band = 0; band < st_ivas->hMasa->config.numCodingBands; band++ ) { - fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[0].band_data[band].azimuth_fx, st_ivas->hQMetaData->q_direction[0].band_data[band].azimuth, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); - fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[0].band_data[band].elevation_fx, st_ivas->hQMetaData->q_direction[0].band_data[band].elevation, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[0].band_data[band].energy_ratio_fx, st_ivas->hQMetaData->q_direction[0].band_data[band].energy_ratio, Q30, MAX_PARAM_SPATIAL_SUBFRAMES ); if ( st_ivas->hQMetaData->no_directions == 2 ) { - fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[1].band_data[band].azimuth_fx, st_ivas->hQMetaData->q_direction[1].band_data[band].azimuth, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); - fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[1].band_data[band].elevation_fx, st_ivas->hQMetaData->q_direction[1].band_data[band].elevation, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[1].band_data[band].energy_ratio_fx, st_ivas->hQMetaData->q_direction[1].band_data[band].energy_ratio, Q30, MAX_PARAM_SPATIAL_SUBFRAMES ); } } @@ -951,32 +955,47 @@ ivas_error ivas_enc( float *data_separated_object; Word32 *data_separated_object_fx; - int16_t idx_separated_object; - int16_t flag_omasa_ener_brate; + Word16 idx_separated_object; + Word16 flag_omasa_ener_brate; flag_omasa_ener_brate = 0; + move16(); /* Stereo transport is used also with monoMASA, duplicate mono if monoMASA */ + IF( EQ_16( sub( st_ivas->hEncoderConfig->nchan_inp, hEncoderConfig->nchan_ism ), 1 ) ) + { + v_multc_fixed( data_fx[hEncoderConfig->nchan_ism], L_deposit_h( INV_SQRT2_FX_Q15 ) /* Q31 */, data_fx[hEncoderConfig->nchan_ism], input_frame ); + Copy32( data_fx[hEncoderConfig->nchan_ism], data_fx[hEncoderConfig->nchan_ism + 1], input_frame ); + } +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS if ( ( st_ivas->hEncoderConfig->nchan_inp - hEncoderConfig->nchan_ism ) == 1 ) { v_multc( data_f[hEncoderConfig->nchan_ism], 1.0f / SQRT2, data_f[hEncoderConfig->nchan_ism], input_frame ); mvr2r( data_f[hEncoderConfig->nchan_ism], data_f[hEncoderConfig->nchan_ism + 1], input_frame ); } - +#endif +#ifdef IVAS_FLOAT_FIXED +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + for ( i = 0; i < st_ivas->nchan_transport; i++ ) + { + floatToFixed_arrL( st_ivas->hMasa->data.cldfbAnaEnc[i]->cldfb_state, st_ivas->hMasa->data.cldfbAnaEnc[i]->cldfb_state_fx, Q11, st_ivas->hMasa->data.cldfbAnaEnc[i]->cldfb_state_length ); + } +#endif /* Estimate TF-tile energy for the input MASA stream */ - ivas_masa_estimate_energy( st_ivas->hMasa, &( data_f[hEncoderConfig->nchan_ism] ), input_frame, st_ivas->nchan_transport ); - + ivas_masa_estimate_energy_fx( st_ivas->hMasa, &( data_fx[hEncoderConfig->nchan_ism] ), input_frame, st_ivas->nchan_transport, st_ivas->q_data_fx ); -#ifdef IVAS_FLOAT_FIXED #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - for ( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) + for ( i = 0; i < st_ivas->nchan_transport; i++ ) { - for ( int j = 0; j < MASA_FREQUENCY_BANDS; j++ ) - { - f2me( st_ivas->hMasa->data.energy[i][j], &st_ivas->hMasa->data.energy_fx[i][j], &st_ivas->hMasa->data.energy_e[i][j] ); - } + fixedToFloat_arrL( st_ivas->hMasa->data.cldfbAnaEnc[i]->cldfb_state_fx, st_ivas->hMasa->data.cldfbAnaEnc[i]->cldfb_state, Q11, st_ivas->hMasa->data.cldfbAnaEnc[i]->cldfb_state_length ); } -#endif // IVAS_FLOAT_FIXED_CONVERSIONS +#endif +#else + /* Estimate TF-tile energy for the input MASA stream */ + ivas_masa_estimate_energy( st_ivas->hMasa, &( data_f[hEncoderConfig->nchan_ism] ), input_frame, st_ivas->nchan_transport ); +#endif + +#ifdef IVAS_FLOAT_FIXED if ( ( error = ivas_omasa_enc_config_fx( st_ivas ) ) != IVAS_ERR_OK ) { return error; @@ -986,13 +1005,9 @@ ivas_error ivas_enc( { for ( int band = 0; band < st_ivas->hMasa->config.numCodingBands; band++ ) { - fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[0].band_data[band].azimuth_fx, st_ivas->hQMetaData->q_direction[0].band_data[band].azimuth, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); - fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[0].band_data[band].elevation_fx, st_ivas->hQMetaData->q_direction[0].band_data[band].elevation, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[0].band_data[band].energy_ratio_fx, st_ivas->hQMetaData->q_direction[0].band_data[band].energy_ratio, Q30, MAX_PARAM_SPATIAL_SUBFRAMES ); if ( st_ivas->hQMetaData->no_directions == 2 ) { - fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[1].band_data[band].azimuth_fx, st_ivas->hQMetaData->q_direction[1].band_data[band].azimuth, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); - fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[1].band_data[band].elevation_fx, st_ivas->hQMetaData->q_direction[1].band_data[band].elevation, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[1].band_data[band].energy_ratio_fx, st_ivas->hQMetaData->q_direction[1].band_data[band].energy_ratio, Q30, MAX_PARAM_SPATIAL_SUBFRAMES ); } } @@ -1017,7 +1032,6 @@ ivas_error ivas_enc( /* Estimate MASA parameters for the objects */ #ifdef IVAS_FLOAT_FIXED_CONVERSIONS OMASA_ENC_HANDLE hOMasa = st_ivas->hOMasa; - MASA_ENCODER_HANDLE hMasa = st_ivas->hMasa; int16_t j; int16_t nchan_transport = st_ivas->nchan_transport; int16_t nchan_ism = hEncoderConfig->nchan_ism; @@ -1040,23 +1054,9 @@ ivas_error ivas_enc( { floatToFixed_arrL( hOMasa->cldfbAnaEnc[i]->cldfb_state, hOMasa->cldfbAnaEnc[i]->cldfb_state_fx, st_ivas->q_data_fx, hOMasa->cldfbAnaEnc[i]->cldfb_state_length ); } - for ( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) - { - for ( j = 0; j < MASA_FREQUENCY_BANDS; j++ ) - { - f2me( hMasa->data.energy[i][j], &hMasa->data.energy_fx[i][j], &hMasa->data.energy_e[i][j] ); - } - } #endif ivas_omasa_enc_fx( st_ivas->hOMasa, st_ivas->hMasa, st_ivas->hIsmMetaData, data_fx, st_ivas->q_data_fx, input_frame, st_ivas->nchan_transport, hEncoderConfig->nchan_ism, st_ivas->ism_mode, data_separated_object_fx, &idx_separated_object ); #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - for ( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) - { - for ( j = 0; j < MASA_FREQUENCY_BANDS; j++ ) - { - hMasa->data.energy[i][j] = me2f( hMasa->data.energy_fx[i][j], hMasa->data.energy_e[i][j] ); - } - } for ( i = 0; i < nchan_ism; i++ ) { fixedToFloat_arrL( hOMasa->cldfbAnaEnc[i]->cldfb_state_fx, hOMasa->cldfbAnaEnc[i]->cldfb_state, st_ivas->q_data_fx, hOMasa->cldfbAnaEnc[i]->cldfb_state_length ); @@ -1379,8 +1379,6 @@ ivas_error ivas_enc( { FOR( jj = 0; jj < nBlocks; jj++ ) { - st_ivas->hQMetaData->q_direction[0].band_data[ii].azimuth[jj] = fixedToFloat( st_ivas->hQMetaData->q_direction[0].band_data[ii].azimuth_fx[jj], Q22 ); - st_ivas->hQMetaData->q_direction[0].band_data[ii].elevation[jj] = fixedToFloat( st_ivas->hQMetaData->q_direction[0].band_data[ii].elevation_fx[jj], Q22 ); st_ivas->hQMetaData->q_direction[0].band_data[ii].energy_ratio[jj] = fixedToFloat( st_ivas->hQMetaData->q_direction[0].band_data[ii].energy_ratio_fx[jj], Q31 ); } } diff --git a/lib_enc/ivas_init_enc.c b/lib_enc/ivas_init_enc.c index 1d77e746c..b40665a98 100644 --- a/lib_enc/ivas_init_enc.c +++ b/lib_enc/ivas_init_enc.c @@ -1203,15 +1203,6 @@ ivas_error ivas_init_encoder( return error; } #else -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - for ( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) - { - for ( int j = 0; j < MASA_FREQUENCY_BANDS; j++ ) - { - f2me( st_ivas->hMasa->data.energy[i][j], &st_ivas->hMasa->data.energy_fx[i][j], &st_ivas->hMasa->data.energy_e[i][j] ); - } - } -#endif // IVAS_FLOAT_FIXED_CONVERSIONS if ( ( error = ivas_mcmasa_enc_open_fx( st_ivas ) ) != IVAS_ERR_OK ) { return error; @@ -1222,13 +1213,9 @@ ivas_error ivas_init_encoder( { for ( int band = 0; band < st_ivas->hMasa->config.numCodingBands; band++ ) { - fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[0].band_data[band].azimuth_fx, st_ivas->hQMetaData->q_direction[0].band_data[band].azimuth, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); - fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[0].band_data[band].elevation_fx, st_ivas->hQMetaData->q_direction[0].band_data[band].elevation, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[0].band_data[band].energy_ratio_fx, st_ivas->hQMetaData->q_direction[0].band_data[band].energy_ratio, Q30, MAX_PARAM_SPATIAL_SUBFRAMES ); if ( st_ivas->hQMetaData->no_directions == 2 ) { - fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[1].band_data[band].azimuth_fx, st_ivas->hQMetaData->q_direction[1].band_data[band].azimuth, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); - fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[1].band_data[band].elevation_fx, st_ivas->hQMetaData->q_direction[1].band_data[band].elevation, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[1].band_data[band].energy_ratio_fx, st_ivas->hQMetaData->q_direction[1].band_data[band].energy_ratio, Q30, MAX_PARAM_SPATIAL_SUBFRAMES ); } } @@ -1878,15 +1865,6 @@ ivas_error ivas_init_encoder_fx( return error; } #else -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - for ( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) - { - for ( int j = 0; j < MASA_FREQUENCY_BANDS; j++ ) - { - f2me( st_ivas->hMasa->data.energy[i][j], &st_ivas->hMasa->data.energy_fx[i][j], &st_ivas->hMasa->data.energy_e[i][j] ); - } - } -#endif // IVAS_FLOAT_FIXED_CONVERSIONS if ( ( error = ivas_mcmasa_enc_open_fx( st_ivas ) ) != IVAS_ERR_OK ) { return error; @@ -1897,13 +1875,9 @@ ivas_error ivas_init_encoder_fx( { for ( int band = 0; band < st_ivas->hMasa->config.numCodingBands; band++ ) { - fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[0].band_data[band].azimuth_fx, st_ivas->hQMetaData->q_direction[0].band_data[band].azimuth, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); - fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[0].band_data[band].elevation_fx, st_ivas->hQMetaData->q_direction[0].band_data[band].elevation, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[0].band_data[band].energy_ratio_fx, st_ivas->hQMetaData->q_direction[0].band_data[band].energy_ratio, Q30, MAX_PARAM_SPATIAL_SUBFRAMES ); if ( st_ivas->hQMetaData->no_directions == 2 ) { - fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[1].band_data[band].azimuth_fx, st_ivas->hQMetaData->q_direction[1].band_data[band].azimuth, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); - fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[1].band_data[band].elevation_fx, st_ivas->hQMetaData->q_direction[1].band_data[band].elevation, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[1].band_data[band].energy_ratio_fx, st_ivas->hQMetaData->q_direction[1].band_data[band].energy_ratio, Q30, MAX_PARAM_SPATIAL_SUBFRAMES ); } } diff --git a/lib_enc/ivas_masa_enc.c b/lib_enc/ivas_masa_enc.c index 97101e412..5438bc921 100644 --- a/lib_enc/ivas_masa_enc.c +++ b/lib_enc/ivas_masa_enc.c @@ -397,37 +397,15 @@ ivas_error ivas_masa_encode( ivas_error error; Word16 guard_bits, tmp; + guard_bits = find_guarded_bits_fx( 24 ); #ifdef IVAS_FLOAT_FIXED_CONVERSIONS for ( i = 0; i < hQMetaData->no_directions; i++ ) { for ( j = hQMetaData->q_direction[i].cfg.start_band; j < hQMetaData->q_direction[i].cfg.nbands; ++j ) { floatToFixed_arrL( hQMetaData->q_direction[i].band_data[j].energy_ratio, hQMetaData->q_direction[i].band_data[j].energy_ratio_fx, Q30, MAX_PARAM_SPATIAL_SUBFRAMES ); - floatToFixed_arrL( hQMetaData->q_direction[i].band_data[j].azimuth, hQMetaData->q_direction[i].band_data[j].azimuth_fx, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); - floatToFixed_arrL( hQMetaData->q_direction[i].band_data[j].elevation, hQMetaData->q_direction[i].band_data[j].elevation_fx, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); - floatToFixed_arrL( hQMetaData->q_direction[i].band_data[j].q_azimuth, hQMetaData->q_direction[i].band_data[j].q_azimuth_fx, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); - floatToFixed_arrL( hQMetaData->q_direction[i].band_data[j].q_elevation, hQMetaData->q_direction[i].band_data[j].q_elevation_fx, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); } } - hMasa->data.q_energy = Q31; - // guard_bits = find_guarded_bits_fx( 9 ); - guard_bits = find_guarded_bits_fx( 24 ); - for ( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) - { - hMasa->data.q_energy = s_min( hMasa->data.q_energy, L_get_q_buf1( hMasa->data.energy[i], MASA_FREQUENCY_BANDS ) ); - } - hMasa->data.q_energy -= guard_bits; - for ( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) - { - for ( j = 0; j < MASA_FREQUENCY_BANDS; j++ ) - { - hMasa->data.energy_e[i][j] = 31 - hMasa->data.q_energy; - } - } - for ( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) - { - floatToFixed_arrL32( hMasa->data.energy[i], hMasa->data.energy_fx[i], hMasa->data.q_energy, MASA_FREQUENCY_BANDS ); - } #endif masa_sid_descriptor = -1; @@ -487,28 +465,29 @@ ivas_error ivas_masa_encode( /* Combine frequency bands and sub-frames */ combine_freqbands_and_subframes_fx( hMasa ); + } - /* aligning the exponents */ - s = 0; - move16(); - FOR( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) - { - maximum_s( hMasa->data.energy_e[i], MASA_FREQUENCY_BANDS, &tmp ); - s = s_max( s, tmp ); - } - FOR( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) + /* aligning the exponents of energy_fx */ + s = 0; + move16(); + FOR( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) + { + maximum_s( hMasa->data.energy_e[i], MASA_FREQUENCY_BANDS, &tmp ); + s = s_max( s, tmp ); + } + s = add( s, guard_bits ); + FOR( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) + { + FOR( j = 0; j < MASA_FREQUENCY_BANDS; j++ ) { - FOR( j = 0; j < MASA_FREQUENCY_BANDS; j++ ) - { - hMasa->data.energy_fx[i][j] = L_shr( hMasa->data.energy_fx[i][j], sub( s, hMasa->data.energy_e[i][j] ) ); - hMasa->data.energy_e[i][j] = s; - move32(); - move16(); - } + hMasa->data.energy_fx[i][j] = L_shr( hMasa->data.energy_fx[i][j], sub( s, hMasa->data.energy_e[i][j] ) ); + hMasa->data.energy_e[i][j] = s; + move32(); + move16(); } - hMasa->data.q_energy = sub( 31, s ); - move16(); } + hMasa->data.q_energy = sub( 31, s ); + move16(); test(); test(); @@ -881,19 +860,11 @@ ivas_error ivas_masa_encode( } #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - for ( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) - { - fixedToFloat_arrL32( hMasa->data.energy_fx[i], hMasa->data.energy[i], hMasa->data.q_energy, MASA_FREQUENCY_BANDS ); - } for ( i = 0; i < hQMetaData->no_directions; i++ ) { for ( j = hQMetaData->q_direction[0].cfg.start_band; j < hQMetaData->q_direction[0].cfg.nbands; ++j ) { fixedToFloat_arrL( hQMetaData->q_direction[i].band_data[j].energy_ratio_fx, hQMetaData->q_direction[i].band_data[j].energy_ratio, Q30, MAX_PARAM_SPATIAL_SUBFRAMES ); - fixedToFloat_arrL( hQMetaData->q_direction[i].band_data[j].azimuth_fx, hQMetaData->q_direction[i].band_data[j].azimuth, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); - fixedToFloat_arrL( hQMetaData->q_direction[i].band_data[j].elevation_fx, hQMetaData->q_direction[i].band_data[j].elevation, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); - fixedToFloat_arrL( hQMetaData->q_direction[i].band_data[j].q_azimuth_fx, hQMetaData->q_direction[i].band_data[j].q_azimuth, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); - fixedToFloat_arrL( hQMetaData->q_direction[i].band_data[j].q_elevation_fx, hQMetaData->q_direction[i].band_data[j].q_elevation, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); } } #endif @@ -1265,8 +1236,113 @@ ivas_error ivas_masa_encode( return IVAS_ERR_OK; } #endif +#ifdef IVAS_FLOAT_FIXED +/*-----------------------------------------------------------------------* + * ivas_masa_estimate_energy_fx() + * + * + *-----------------------------------------------------------------------*/ +void ivas_masa_estimate_energy_fx( + MASA_ENCODER_HANDLE hMasa, /* i/o: MASA encoder structure */ + Word32 *data_fx[], /* i : Input audio channels Q(q_data) */ + const Word16 input_frame, /* i : frame length */ + const Word16 nchan_transport, /* i : number of MASA input/transport channels */ + Word16 q_data /* i : q for data_fx */ +) +{ + Word32 Input_RealBuffer[MASA_MAX_TRANSPORT_CHANNELS][CLDFB_NO_CHANNELS_MAX]; + Word32 Input_ImagBuffer[MASA_MAX_TRANSPORT_CHANNELS][CLDFB_NO_CHANNELS_MAX]; + Word16 block_m_idx, band_m_idx; + Word16 mrange[2], brange[2]; + Word16 i, j, ts, l_ts, maxBin; + Word64 energy_fx_temp[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; + Word16 scale = 63; + move16(); + Word16 q_buf; + maxBin = extract_l( Mpy_32_32( 134217728 /*CLDFB_NO_CHANNELS_MAX / L_FRAME48k in Q31*/, input_frame ) ); + l_ts = idiv1616( input_frame, CLDFB_NO_COL_MAX ); + FOR( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) + { + FOR( j = 0; j < MASA_FREQUENCY_BANDS; j++ ) + { + energy_fx_temp[i][j] = 0; + move64(); + } + } + + FOR( block_m_idx = 0; block_m_idx < MAX_PARAM_SPATIAL_SUBFRAMES; block_m_idx++ ) + { + mrange[0] = hMasa->config.block_grouping[block_m_idx]; + move16(); + mrange[1] = hMasa->config.block_grouping[block_m_idx + 1]; + move16(); + set_zero_fx( hMasa->data.energy_fx[block_m_idx], MASA_FREQUENCY_BANDS ); + set16_fx( hMasa->data.energy_e[block_m_idx], 0, MASA_FREQUENCY_BANDS ); + + FOR( ts = mrange[0]; ts < mrange[1]; ts++ ) + { + FOR( i = 0; i < nchan_transport; i++ ) + { + q_buf = q_data; + move16(); + cldfbAnalysis_ts_fx_fixed_q( &( data_fx[i][l_ts * ts] ), Input_RealBuffer[i], Input_ImagBuffer[i], l_ts, hMasa->data.cldfbAnaEnc[i], &q_buf ); // (q_data - 5) for Input_RealBuffer[i], Input_ImagBuffer[i] + } + + FOR( band_m_idx = 0; band_m_idx < MASA_FREQUENCY_BANDS; band_m_idx++ ) + { + brange[0] = hMasa->config.band_grouping[band_m_idx]; + move16(); + brange[1] = hMasa->config.band_grouping[band_m_idx + 1]; + move16(); + + FOR( i = 0; i < nchan_transport; i++ ) + { + IF( GT_16( brange[0], maxBin ) ) + { + hMasa->data.energy_fx[block_m_idx][band_m_idx] = 0; + move32(); + CONTINUE; + } + ELSE IF( GE_16( brange[1], maxBin ) ) + { + brange[1] = maxBin; + move16(); + } + + FOR( j = brange[0]; j < brange[1]; j++ ) + { + energy_fx_temp[block_m_idx][band_m_idx] = W_add( energy_fx_temp[block_m_idx][band_m_idx], W_mac_32_32( W_mult_32_32( Input_RealBuffer[i][j], Input_RealBuffer[i][j] ), Input_ImagBuffer[i][j], Input_ImagBuffer[i][j] ) ); // Q: 2 * (q_data - 5) + 1 for energy_fx_temp + move64(); + } + IF( energy_fx_temp[block_m_idx][band_m_idx] != 0 ) + { + scale = s_min( scale, W_norm( energy_fx_temp[block_m_idx][band_m_idx] ) ); // scale calculates minimum shift can be done across a buffer + } + } + } + } + } + + FOR( block_m_idx = 0; block_m_idx < MAX_PARAM_SPATIAL_SUBFRAMES; block_m_idx++ ) + { + FOR( band_m_idx = 0; band_m_idx < MASA_FREQUENCY_BANDS; band_m_idx++ ) + { + energy_fx_temp[block_m_idx][band_m_idx] = W_shl( energy_fx_temp[block_m_idx][band_m_idx], scale ); // Q: 2 * (q_data - 5) + 1 + scale + move64(); + hMasa->data.energy_fx[block_m_idx][band_m_idx] = W_extract_h( energy_fx_temp[block_m_idx][band_m_idx] ); // Q: 2 * (q_data - 5) + 1 + scale - 32 + move32(); + hMasa->data.energy_e[block_m_idx][band_m_idx] = sub( 31, add( add( imult1616( 2, q_data ), scale ), 1 - 10 - 32 ) ); + move16(); + } + } + hMasa->data.q_energy = add( add( imult1616( 2, q_data ), scale ), 1 - 10 - 32 ); + move16(); + + return; +} +#else /*-----------------------------------------------------------------------* * ivas_masa_estimate_energy() * @@ -1332,6 +1408,7 @@ void ivas_masa_estimate_energy( return; } +#endif /*-----------------------------------------------------------------------* diff --git a/lib_enc/ivas_mc_param_enc.c b/lib_enc/ivas_mc_param_enc.c index f74174689..024532450 100644 --- a/lib_enc/ivas_mc_param_enc.c +++ b/lib_enc/ivas_mc_param_enc.c @@ -887,7 +887,11 @@ void ivas_param_mc_enc_fx( { Word16 cpe_idx = shr( ch, 1 ); +#ifndef MSAN_FIX Copy_Scale_sig_32_16( data_dmx_fx[ch], data_dmx_fx16[ch], -Q1 - Q11, input_frame ); // Q11 -> Q(-1) +#else + Copy_Scale_sig_32_16( data_dmx_fx[ch], data_dmx_fx16[ch], input_frame, -Q1 - Q11 ); // Q11 -> Q(-1) +#endif RunTransientDetection_ivas_fx( data_dmx_fx16[ch], input_frame, st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet ); ivas_param_mc_transient_detection_fx( hParamMC, st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet, &bAttackPresent[ch], &attackIdx[ch] ); diff --git a/lib_enc/ivas_mcmasa_enc.c b/lib_enc/ivas_mcmasa_enc.c index 821450296..57de41384 100644 --- a/lib_enc/ivas_mcmasa_enc.c +++ b/lib_enc/ivas_mcmasa_enc.c @@ -1696,6 +1696,20 @@ void ivas_mcmasa_param_est_enc_fx( p_Chnl_ImagBuffer_fx[i] = &Chnl_ImagBuffer_fx[i][0]; } + /* initialising energy_fx */ + FOR( block_m_idx = 0; block_m_idx < MAX_PARAM_SPATIAL_SUBFRAMES; block_m_idx++ ) + { + FOR( i = 0; i < MASA_FREQUENCY_BANDS; i++ ) + { + hMasa->data.energy_fx[block_m_idx][i] = 0; + move32(); + hMasa->data.energy_e[block_m_idx][i] = 31; + move16(); + } + } + hMasa->data.q_energy = 0; + move16(); + /* do processing over all CLDFB time slots */ FOR( block_m_idx = 0; block_m_idx < MAX_PARAM_SPATIAL_SUBFRAMES; block_m_idx++ ) { @@ -1767,25 +1781,11 @@ void ivas_mcmasa_param_est_enc_fx( } /* Store energies for guiding metadata encoding */ - hMasa->data.energy_fx[block_m_idx][i] = 0; - move32(); - hMasa->data.energy_e[block_m_idx][i] = 31; - move16(); FOR( j = 0; j < numAnalysisChannels; j++ ) { move32(); hMasa->data.energy_fx[block_m_idx][i] = BASOP_Util_Add_Mant32Exp( hMasa->data.energy_fx[block_m_idx][i], hMasa->data.energy_e[block_m_idx][i], COVls[i].xr_fx[j][j], COVls[i].xr_e[j][j], &hMasa->data.energy_e[block_m_idx][i] ); } -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - IF( hMasa->data.energy_e[block_m_idx][i] < 31 ) - { - hMasa->data.energy[block_m_idx][i] = hMasa->data.energy_fx[block_m_idx][i] / (float) ( 1 << ( 31 - hMasa->data.energy_e[block_m_idx][i] ) ); - } - ELSE - { - hMasa->data.energy[block_m_idx][i] = hMasa->data.energy_fx[block_m_idx][i] * (float) ( 1 << ( hMasa->data.energy_e[block_m_idx][i] - 31 ) ); - } -#endif } IF( !hMcMasa->separateChannelEnabled ) diff --git a/lib_enc/ivas_mct_enc.c b/lib_enc/ivas_mct_enc.c index f326b1a32..aaa3dd260 100644 --- a/lib_enc/ivas_mct_enc.c +++ b/lib_enc/ivas_mct_enc.c @@ -1771,15 +1771,6 @@ static ivas_error ivas_mc_enc_reconfig( return error; } #ifdef IVAS_FLOAT_FIXED -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - for ( int i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) - { - for ( int j = 0; j < MASA_FREQUENCY_BANDS; j++ ) - { - f2me( st_ivas->hMasa->data.energy[i][j], &st_ivas->hMasa->data.energy_fx[i][j], &st_ivas->hMasa->data.energy_e[i][j] ); - } - } -#endif // IVAS_FLOAT_FIXED_CONVERSIONS if ( NE_32( ( error = ivas_mcmasa_enc_open_fx( st_ivas ) ), IVAS_ERR_OK ) ) { return error; @@ -1789,13 +1780,9 @@ static ivas_error ivas_mc_enc_reconfig( { for ( int band = 0; band < st_ivas->hMasa->config.numCodingBands; band++ ) { - fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[0].band_data[band].azimuth_fx, st_ivas->hQMetaData->q_direction[0].band_data[band].azimuth, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); - fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[0].band_data[band].elevation_fx, st_ivas->hQMetaData->q_direction[0].band_data[band].elevation, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[0].band_data[band].energy_ratio_fx, st_ivas->hQMetaData->q_direction[0].band_data[band].energy_ratio, Q30, MAX_PARAM_SPATIAL_SUBFRAMES ); if ( st_ivas->hQMetaData->no_directions == 2 ) { - fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[1].band_data[band].azimuth_fx, st_ivas->hQMetaData->q_direction[1].band_data[band].azimuth, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); - fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[1].band_data[band].elevation_fx, st_ivas->hQMetaData->q_direction[1].band_data[band].elevation, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[1].band_data[band].energy_ratio_fx, st_ivas->hQMetaData->q_direction[1].band_data[band].energy_ratio, Q30, MAX_PARAM_SPATIAL_SUBFRAMES ); } } @@ -1812,15 +1799,6 @@ static ivas_error ivas_mc_enc_reconfig( { /* reconfigure McMASA instance */ #ifdef IVAS_FLOAT_FIXED -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - for ( int i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) - { - for ( int j = 0; j < MASA_FREQUENCY_BANDS; j++ ) - { - f2me( st_ivas->hMasa->data.energy[i][j], &st_ivas->hMasa->data.energy_fx[i][j], &st_ivas->hMasa->data.energy_e[i][j] ); - } - } -#endif // IVAS_FLOAT_FIXED_CONVERSIONS if ( NE_32( ( error = ivas_mcmasa_enc_reconfig_fx( st_ivas ) ), IVAS_ERR_OK ) ) { return error; @@ -1830,13 +1808,9 @@ static ivas_error ivas_mc_enc_reconfig( { for ( int band = 0; band < st_ivas->hMasa->config.numCodingBands; band++ ) { - fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[0].band_data[band].azimuth_fx, st_ivas->hQMetaData->q_direction[0].band_data[band].azimuth, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); - fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[0].band_data[band].elevation_fx, st_ivas->hQMetaData->q_direction[0].band_data[band].elevation, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[0].band_data[band].energy_ratio_fx, st_ivas->hQMetaData->q_direction[0].band_data[band].energy_ratio, Q30, MAX_PARAM_SPATIAL_SUBFRAMES ); if ( st_ivas->hQMetaData->no_directions == 2 ) { - fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[1].band_data[band].azimuth_fx, st_ivas->hQMetaData->q_direction[1].band_data[band].azimuth, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); - fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[1].band_data[band].elevation_fx, st_ivas->hQMetaData->q_direction[1].band_data[band].elevation, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[1].band_data[band].energy_ratio_fx, st_ivas->hQMetaData->q_direction[1].band_data[band].energy_ratio, Q30, MAX_PARAM_SPATIAL_SUBFRAMES ); } } diff --git a/lib_enc/ivas_qmetadata_enc.c b/lib_enc/ivas_qmetadata_enc.c index 79a32e4a4..bde299111 100644 --- a/lib_enc/ivas_qmetadata_enc.c +++ b/lib_enc/ivas_qmetadata_enc.c @@ -2231,7 +2231,7 @@ Word16 quantize_direction2D_fx( } ELSE { - id_phi = quantize_phi_fx( L_add( phi, 180 << Q22 ), 0, phi_q, no_cw ); + id_phi = quantize_phi_enc_fx( L_add( phi, 180 << Q22 ), 0, phi_q, no_cw ); } *phi_q = L_sub( *phi_q, 180 << Q22 ); move32(); @@ -4257,7 +4257,7 @@ static Word16 ivas_qmetadata_entropy_encode_dir_fx( } } - avg_azimuth_index = (UWord16) ( quantize_phi_fx( L_add( avg_azimuth, 180 << Q22 ), 0, &avg_azimuth, avg_azimuth_alphabet ) ); + avg_azimuth_index = (UWord16) ( quantize_phi_enc_fx( L_add( avg_azimuth, 180 << Q22 ), 0, &avg_azimuth, avg_azimuth_alphabet ) ); /* Elevation only if not 2D */ IF( q_direction->not_in_2D > 0 ) @@ -4400,7 +4400,7 @@ static Word16 ivas_qmetadata_entropy_encode_dir_fx( { use_adapt_avg = calc_var_azi_fx( q_direction, diffuseness_index_max_ec_frame, L_sub( avg_azimuth, 180 << Q22 ), &avg_azimuth ); // 180.Q22 - avg_azimuth_index = (UWord16) ( quantize_phi_fx( L_add( avg_azimuth, 180 << Q22 ), 0, &avg_azimuth, avg_azimuth_alphabet ) ); + avg_azimuth_index = (UWord16) ( quantize_phi_enc_fx( L_add( avg_azimuth, 180 << Q22 ), 0, &avg_azimuth, avg_azimuth_alphabet ) ); } avg_azimuth_index_initial = avg_azimuth_index; /* avg_azimuth_index;*/ move16(); @@ -4478,7 +4478,7 @@ static Word16 ivas_qmetadata_entropy_encode_dir_fx( v_add_fixed( avg_direction_vector, direction_vector, avg_direction_vector, 3, 0 ); ivas_qmetadata_direction_vector_to_azimuth_elevation_fx( avg_direction_vector, Q22, &avg_azimuth, &avg_elevation ); - avg_azimuth_index_upd = quantize_phi_fx( L_add( avg_azimuth, 180 << Q22 ), 0, &avg_azimuth, avg_azimuth_alphabet ); + avg_azimuth_index_upd = quantize_phi_enc_fx( L_add( avg_azimuth, 180 << Q22 ), 0, &avg_azimuth, avg_azimuth_alphabet ); } idx = add( idx, 1 ); } @@ -5772,7 +5772,7 @@ static Word16 truncGR0_fx( FOR( i = 0; i < len; i++ ) { - data_idx[i] = quantize_phi_fx( L_add( data_fx[i], DEGREE_180_Q_22 ), 0, &data_hat_fx[i], 8 ); + data_idx[i] = quantize_phi_enc_fx( L_add( data_fx[i], DEGREE_180_Q_22 ), 0, &data_hat_fx[i], 8 ); move16(); data_hat_fx[i] = L_sub( data_hat_fx[i], DEGREE_180_Q_22 ); move32(); @@ -5796,7 +5796,7 @@ static Word16 truncGR0_fx( { bits = sub( bits, ivas_qmetadata_encode_extended_gr_length( data_idx[indx[i]], 8, 0 ) ); // data_idx[indx[i]] = quantize_phi( data[indx[i]] + 180, 0, &data_hat[indx[i]], 4 ); - data_idx[indx[i]] = quantize_phi_fx( L_add( data_fx[indx[i]], DEGREE_180_Q_22 ), 0, &data_hat_fx[indx[i]], 4 ); + data_idx[indx[i]] = quantize_phi_enc_fx( L_add( data_fx[indx[i]], DEGREE_180_Q_22 ), 0, &data_hat_fx[indx[i]], 4 ); move16(); // data_hat[indx[i]] -= 180; data_hat_fx[indx[i]] = L_sub( data_hat_fx[indx[i]], DEGREE_180_Q_22 ); diff --git a/lib_enc/ivas_qspherical_enc.c b/lib_enc/ivas_qspherical_enc.c index 74a787b2c..d2804108a 100644 --- a/lib_enc/ivas_qspherical_enc.c +++ b/lib_enc/ivas_qspherical_enc.c @@ -812,7 +812,7 @@ UWord16 quantize_direction_fx( } ELSE { - id_phi = quantize_phi_fx( L_add( phi, DEGREE_180_Q_22 ), 0, &phi_hat, no_phi_masa[no_bits - 1][0] ); + id_phi = quantize_phi_enc_fx( L_add( phi, DEGREE_180_Q_22 ), 0, &phi_hat, no_phi_masa[no_bits - 1][0] ); idx_sph = id_phi; *phi_q = L_sub( phi_hat, DEGREE_180_Q_22 ); id_phi_remap = ivas_qmetadata_reorder_generic( sub( id_phi, shr( no_phi_masa[no_bits - 1][0], 1 ) ) ); @@ -1339,7 +1339,7 @@ static Word32 quantize_theta_phi_fx( // Q22 } ELSE { - id_ph = quantize_phi_fx( phi, s_and( id_th, 1 ), phi_hat, no_phi_loc[id_th] ); + id_ph = quantize_phi_enc_fx( phi, s_and( id_th, 1 ), phi_hat, no_phi_loc[id_th] ); } } ELSE @@ -1362,7 +1362,7 @@ static Word32 quantize_theta_phi_fx( // Q22 theta_hat1 = theta_cb[id_th1]; move32(); - id_ph1 = quantize_phi_fx( phi, s_and( id_th1, 1 ), &phi_hat1, no_phi_loc[id_th1] ); + id_ph1 = quantize_phi_enc_fx( phi, s_and( id_th1, 1 ), &phi_hat1, no_phi_loc[id_th1] ); d_fx = direction_distance_cp_fx( abs_theta, theta_hat, theta_hat1, phi, *phi_hat, phi_hat1, &d1_fx ); @@ -1389,7 +1389,7 @@ static Word32 quantize_theta_phi_fx( // Q22 } ELSE { - id_ph = quantize_phi_fx( phi, s_and( id_th, 1 ), phi_hat, no_phi_loc[id_th] ); + id_ph = quantize_phi_enc_fx( phi, s_and( id_th, 1 ), phi_hat, no_phi_loc[id_th] ); } } diff --git a/lib_enc/ivas_spar_encoder.c b/lib_enc/ivas_spar_encoder.c index 2ba611679..d7857435a 100644 --- a/lib_enc/ivas_spar_encoder.c +++ b/lib_enc/ivas_spar_encoder.c @@ -1132,7 +1132,11 @@ static ivas_error ivas_spar_enc_process( { num_chs_alloc = 1; /* only W channel processed for predicting YZX */ } +#ifdef MSAN_FIX + FOR( Word16 m = 0; m < nchan_fb_in; m++ ) +#else FOR( Word16 m = 0; m <= nchan_fb_in + nchan_transport; m++ ) +#endif { IF( data_f[m] != NULL ) { @@ -1294,11 +1298,6 @@ static ivas_error ivas_spar_enc_process( for ( b = hSpar->enc_param_start_band; b < IVAS_MAX_NUM_BANDS; b++ ) { Word16 dirac_band_idx = hSpar->dirac_to_spar_md_bands[b] - hSpar->enc_param_start_band; - for ( i_ts = 0; i_ts < hQMetaData->q_direction->cfg.nblocks; i_ts++ ) - { - hQMetaData->q_direction->band_data[dirac_band_idx].azimuth_fx[i_ts] = float_to_fix( hQMetaData->q_direction->band_data[dirac_band_idx].azimuth[i_ts], Q22 ); - hQMetaData->q_direction->band_data[dirac_band_idx].elevation_fx[i_ts] = float_to_fix( hQMetaData->q_direction->band_data[dirac_band_idx].elevation[i_ts], Q22 ); - } hQMetaData->q_direction->band_data[dirac_band_idx].energy_ratio_fx[0] = float_to_fix( hQMetaData->q_direction->band_data[dirac_band_idx].energy_ratio[0], Q30 ); } #ifdef IVAS_FLOAT_FIXED_CONVERSIONS diff --git a/lib_enc/ivas_stat_enc.h b/lib_enc/ivas_stat_enc.h index 4c3eca4d9..8e8dc8f84 100644 --- a/lib_enc/ivas_stat_enc.h +++ b/lib_enc/ivas_stat_enc.h @@ -1296,16 +1296,17 @@ typedef struct ivas_masa_sync_struct typedef struct ivas_masa_encoder_data_struct { +#ifndef IVAS_FLOAT_FIXED float energy[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; -#ifdef IVAS_FLOAT_FIXED +#else Word32 energy_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; Word16 energy_e[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; - Word16 q_energy; // Common Q for all energy_fx elements + Word16 q_energy; // Common Q for all energy_fx elements #endif - int16_t num_Cldfb_instances; + Word16 num_Cldfb_instances; HANDLE_CLDFB_FILTER_BANK cldfbAnaEnc[MAX_NUM_ENC_CLDFB_INSTANCES]; - int16_t band_mapping[MASA_FREQUENCY_BANDS + 1]; - uint8_t twoDirBands[MASA_FREQUENCY_BANDS]; + Word16 band_mapping[MASA_FREQUENCY_BANDS + 1]; + UWord8 twoDirBands[MASA_FREQUENCY_BANDS]; SPHERICAL_GRID_DATA Sph_Grid16; #ifdef IVAS_FLOAT_FIXED Word32 importanceWeight_fx[MASA_FREQUENCY_BANDS]; /*q30*/ @@ -1319,7 +1320,7 @@ typedef struct ivas_masa_encoder_data_struct #else Word32 prevq_lfeToTotalEnergyRatio_fx; // Q31 #endif - int16_t prevq_lfeIndex; + Word16 prevq_lfeIndex; #ifndef IVAS_FLOAT_FIXED float onset_detector_1; diff --git a/lib_enc/ivas_stereo_cng_enc.c b/lib_enc/ivas_stereo_cng_enc.c index 91799b60a..a9dc30e44 100644 --- a/lib_enc/ivas_stereo_cng_enc.c +++ b/lib_enc/ivas_stereo_cng_enc.c @@ -325,12 +325,11 @@ void stereo_dft_enc_sid_coh_fx( Word16 zeropad; Word16 nr_of_sid_stereo_bits; Word16 coh_pred_index; - Word16 min_pred_err; - Word16 min_pred_err_e; + Word64 min_pred_err; Word16 pred_err; // Q13 Word16 res_index; Word16 i; - Word16 tmp; + Word32 tmp; const Word16 *pptr; Word16 pred; // Q13 Word16 cohBandq[STEREO_DFT_BAND_MAX / 2]; /* Reconstructed coherence values for intra-frame prediction Q15 */ @@ -355,37 +354,33 @@ void stereo_dft_enc_sid_coh_fx( IF( sub( sub( nr_of_sid_stereo_bits, *nb_bits ), STEREO_DFT_N_COH_ALPHA_BITS + STEREO_DFT_PRED_NBITS ) > 0 ) { - min_pred_err = 31250; - move32(); - min_pred_err_e = 20; - move16(); + min_pred_err = 134217728000000; // 1e6 in Q27 + move64(); coh_pred_index = -1; move16(); pptr = dft_cng_coh_pred_fx[0]; // Q13 FOR( k = 0; k < STEREO_DFT_N_COH_PRED; k++ ) { - pred_err = 0; - move16(); + Word64 pred_err64 = 0; + move64(); FOR( b = 1; b < nbands; b++ ) /* Set b=1 to skip first coefficient (same error would otherwise be added for all predictors: (cohBand[0] - 0).^2) */ { - pred = 0; - move16(); + Word64 pred64 = 0; + move64(); FOR( i = 0; i < b; i++ ) { // pred += ( *pptr++ ) * cohBand[i]; - pred = add( pred, mult_r( extract_h( cohBand[i] ), ( *pptr++ ) ) ); // Q13 + pred64 = W_mac_32_16( pred64, cohBand[i], *pptr++ ); // Q45 (31+13+1) } - tmp = sub( shr_r( extract_h( cohBand[b] ), 2 ), pred ); // Q13 + tmp = L_sub( L_shr( cohBand[b], 18 ), W_extract_h( pred64 ) ); // Q13 // pred_err += tmp * tmp; - pred_err = add( pred_err, shl( mult_r( tmp, tmp ), 2 ) ); // Q13 + pred_err64 = W_mac_32_32( pred_err64, tmp, tmp ); // Q27 } // if ( pred_err < min_pred_err ) /* Store best candidate */ - IF( BASOP_Util_Cmp_Mant32Exp( pred_err, 16, min_pred_err, add( min_pred_err_e, 16 ) ) < 0 ) /* Store best candidate */ + IF( LT_64( pred_err64, min_pred_err ) ) /* Store best candidate */ { - min_pred_err = pred_err; - move32(); - min_pred_err_e = 0; - move16(); + min_pred_err = pred_err64; // Q27 + move64(); coh_pred_index = k; move16(); } diff --git a/lib_rend/ivas_efap.c b/lib_rend/ivas_efap.c index e9f7d3d33..2d0b9e08d 100644 --- a/lib_rend/ivas_efap.c +++ b/lib_rend/ivas_efap.c @@ -55,8 +55,8 @@ #ifndef IVAS_FLOAT_FIXED #define POLY_THRESH 1e-4f #else -#define POLY_THRESH_Q29 53687 // Q29 -#define POLY_THRESH_Q28 26843 // Q28 +#define POLY_THRESH_Q29 53687LL // Q29 +#define POLY_THRESH_Q28 26843 // Q28 #endif #ifdef IVAS_FLOAT_FIXED #define Q22_1 4194304 @@ -83,7 +83,7 @@ static void sort_vertices( const EFAP_VERTEX *vertexArray, const int16_t *numVtx static void visible_edges( const EFAP_LS_TRIANGLE *triArray, const int16_t *visible, const int16_t numSurface, int16_t *numEdges, int16_t *edges ); #else static ivas_error poly_init_fx( EFAP *efap, const Word16 efip_flag ); -static ivas_error sphere_triangulation_fx( const Word16 numSpk, EFAP_VERTEX_DATA *vtxData, EFAP_POLYSET_DATA *polyData, Word32 ***dmTranspose, Word16 *numTot, const Word16 efip_flag ); +static ivas_error sphere_triangulation_fx( const Word16 numSpk, EFAP_VERTEX_DATA *vtxData, EFAP_POLYSET_DATA *polyData, Word32 ***dmTranspose /*q31*/, Word16 *numTot, const Word16 efip_flag ); static void initial_polyeder_fx( EFAP_VERTEX_DATA *vtxData, EFAP_LS_TRIANGLE *triArray, Word16 *numTri, Word16 *vtxInHull ); static void add_ghost_speakers_fx( EFAP_VERTEX *vertexArray, Word16 *numVtx, const Word16 efip_flag ); static void add_vertex_to_convex_hull_fx( const EFAP_VERTEX_DATA *vtxData, const Word16 vtxIdx, Word16 *vtxInHull, EFAP_LS_TRIANGLE *triArray, Word16 *szTri ); @@ -100,12 +100,12 @@ static void efap_panning( const float azi, const float ele, const EFAP_POLYSET_D static void get_poly_gains( const float azi, const float ele, const float aziPoly[EFAP_MAX_CHAN_NUM], const float elePoly[EFAP_MAX_CHAN_NUM], const int16_t numChan, float *buffer ); static float get_tri_gain( const float A[2], const float B[2], const float C[2], const float P_minus_A[2] ); #else -static void flip_plane_fx( const EFAP_VERTEX *vtxArray, Word16 *surface, const Word32 centroid[3] ); -static void remap_ghosts_fx( EFAP_VERTEX *vtxArray, EFAP_LS_TRIANGLE *triArray, Word16 numSpk, Word16 *numVertex, Word16 numTri, Word32 **downmixMatrix ); -static void vertex_init_fx( const Word32 *aziSpk, const Word32 *eleSpk, EFAP_VERTEX_DATA *efapVtxData ); -static void efap_panning_fx( const Word32 azi, const Word32 ele, const EFAP_POLYSET_DATA *polyData, Word32 *bufferL ); -static void get_poly_gains_fx( const Word32 azi, const Word32 ele, const Word32 aziPoly[EFAP_MAX_CHAN_NUM], const Word32 elePoly[EFAP_MAX_CHAN_NUM], const Word16 numChan, Word32 *buffer ); -static Word32 get_tri_gain_fx( const Word32 A[2], const Word32 B[2], const Word32 C[2], const Word32 P_minus_A[2] ); +static void flip_plane_fx( const EFAP_VERTEX *vtxArray, Word16 *surface, const Word32 centroid[3] /*q31*/ ); +static void remap_ghosts_fx( EFAP_VERTEX *vtxArray, EFAP_LS_TRIANGLE *triArray, Word16 numSpk, Word16 *numVertex, Word16 numTri, Word32 **downmixMatrix /*q31*/ ); +static void vertex_init_fx( const Word32 *aziSpk /*q22*/, const Word32 *eleSpk /*q22*/, EFAP_VERTEX_DATA *efapVtxData ); +static void efap_panning_fx( const Word32 azi /*q22*/, const Word32 ele /*q22*/, const EFAP_POLYSET_DATA *polyData, Word32 *bufferL /*q31*/ ); +static void get_poly_gains_fx( const Word32 azi /*q22*/, const Word32 ele /*q22*/, const Word32 aziPoly[EFAP_MAX_CHAN_NUM] /*q22*/, const Word32 elePoly[EFAP_MAX_CHAN_NUM] /*q22*/, const Word16 numChan, Word32 *buffer /*q31*/ ); +static Word32 get_tri_gain_fx( const Word32 A[2] /*q22*/, const Word32 B[2] /*q22*/, const Word32 C[2] /*q22*/, const Word32 P_minus_A[2] /*q22*/ ); #endif /*-----------------------------------------------------------------------* @@ -116,7 +116,7 @@ static Word32 get_tri_gain_fx( const Word32 A[2], const Word32 B[2], const Word3 static void add_vertex( EFAP_VERTEX *vtxArray, const float azi, const float ele, const int16_t pos, const EFAP_VTX_DMX_TYPE ); static void efap_sort_s( int16_t *x, int16_t *idx, const int16_t len ); #else -static void add_vertex_fx( EFAP_VERTEX *vtxArray, const Word32 azi, const Word32 ele, const Word16 pos, const EFAP_VTX_DMX_TYPE ); +static void add_vertex_fx( EFAP_VERTEX *vtxArray, const Word32 azi /*q22*/, const Word32 ele /*q22*/, const Word16 pos, const EFAP_VTX_DMX_TYPE ); static void efap_sort_s_fx( Word16 *x, Word16 *idx, const Word16 len ); #endif @@ -131,9 +131,9 @@ static void remove_vertex( EFAP_VERTEX *vtxArray, const int16_t idx, const int16 static int16_t get_neighbours( const EFAP_LS_TRIANGLE *triArray, const int16_t vtxIdx, const int16_t numTri, int16_t *neighbours ); #else static Word32 vertex_distance_fx( const EFAP_VERTEX *vtxArray, const EFAP_LS_TRIANGLE tri, const Word16 vtxIdx ); -static Word32 point_plane_distance_fx( const Word32 P1[3], const Word32 P2[3], const Word32 P3[3], const Word32 X[3] ); -static Word32 point_poly_distance_fx( const EFAP_POLYSET poly, const Word32 X[3] ); -static void efap_crossp_fx( const Word32 *v1, const Word32 *v2, Word32 *v ); +static Word32 point_plane_distance_fx( const Word32 P1[3] /*q31*/, const Word32 P2[3] /*q31*/, const Word32 P3[3] /*q31*/, const Word32 X[3] /*q31*/ ); +static Word32 point_poly_distance_fx( const EFAP_POLYSET poly, const Word32 X[3] /*q31*/ ); +static void efap_crossp_fx( const Word32 *v1 /*q30*/, const Word32 *v2 /*q30*/, Word32 *v /*q29*/ ); static Word16 find_int_in_tri_fx( const EFAP_LS_TRIANGLE *tri, const Word16 n, const Word16 r, Word16 *pos ); static void remove_vertex_fx( EFAP_VERTEX *vtxArray, const Word16 idx, const Word16 L ); static Word16 get_neighbours_fx( const EFAP_LS_TRIANGLE *triArray, const Word16 vtxIdx, const Word16 numTri, Word16 *neighbours ); @@ -145,7 +145,7 @@ static void matrix_times_row( float mat[EFAP_MAX_SIZE_TMP_BUFF][EFAP_MAX_SIZE_TM static void tri_to_poly( const EFAP_VERTEX *vtxArray, const EFAP_LS_TRIANGLE *triArray, const int16_t numVtx, const int16_t numTri, int16_t sortedChan[EFAP_MAX_POLY_SET][EFAP_MAX_CHAN_NUM], int16_t *outLengthPS, int16_t outLengthSorted[EFAP_MAX_POLY_SET] ); static int16_t compare_poly( int16_t *old, int16_t lenOld, int16_t *new, int16_t lenNew ); #else -static void matrix_times_row_fx( Word32 mat[EFAP_MAX_SIZE_TMP_BUFF][EFAP_MAX_SIZE_TMP_BUFF], const Word32 *vec, const Word16 L, Word32 *out ); +static void matrix_times_row_fx( Word32 mat[EFAP_MAX_SIZE_TMP_BUFF][EFAP_MAX_SIZE_TMP_BUFF] /*q31*/, const Word32 *vec /*q31*/, const Word16 L, Word32 *out /*q31*/ ); static void tri_to_poly_fx( const EFAP_VERTEX *vtxArray, const EFAP_LS_TRIANGLE *triArray, const Word16 numVtx, const Word16 numTri, Word16 sortedChan[EFAP_MAX_POLY_SET][EFAP_MAX_CHAN_NUM], Word16 *outLengthPS, Word16 outLengthSorted[EFAP_MAX_POLY_SET] ); static Word16 compare_poly_fx( Word16 *old, Word16 lenOld, Word16 *new, Word16 lenNew ); #endif @@ -160,11 +160,11 @@ static int16_t in_tri( float A[2], float B[2], float C[2], float P_minus_A[2] ); static void sph2cart( const float azi, const float ele, float *pos ); #else static void sort_channels_vertex_fx( const EFAP_VERTEX *vtxArray, const EFAP_LS_TRIANGLE *triArray, Word16 channels[EFAP_MAX_CHAN_NUM], const Word16 lengthChannels, Word16 idxTri ); -static Word32 efap_32mod32( const Word32 x, const Word32 y ); -static Word16 get_poly_num_fx( const Word32 P[2], const EFAP_POLYSET_DATA *polyData ); -static Word16 in_poly_fx( const Word32 P[2], const EFAP_POLYSET poly ); -static Word16 in_tri_fx( Word32 A[2], Word32 B[2], Word32 C[2], Word32 P_minus_A[2] ); -static void sph2cart_fx( const Word32 azi, const Word32 ele, Word32 *pos ); +static Word32 efap_32mod32( const Word32 x /*q22*/, const Word32 y /*q22*/ ); +static Word16 get_poly_num_fx( const Word32 P[2] /*q22*/, const EFAP_POLYSET_DATA *polyData ); +static Word16 in_poly_fx( const Word32 P[2] /*q22*/, const EFAP_POLYSET poly ); +static Word16 in_tri_fx( Word32 A[2] /*q22*/, Word32 B[2] /*q22*/, Word32 C[2] /*q22*/, Word32 P_minus_A[2] /*q22*/ ); +static void sph2cart_fx( const Word32 azi /*q22*/, const Word32 ele /*q22*/, Word32 *pos /*q31*/ ); #endif /*-----------------------------------------------------------------------* @@ -245,8 +245,8 @@ ivas_error efap_init_data_fx( move16(); /* Loudspeaker configuration */ - Copy32( speaker_node_azi_deg, efap->aziSpk, num_speaker_nodes ); - Copy32( speaker_node_ele_deg, efap->eleSpk, num_speaker_nodes ); + Copy32( speaker_node_azi_deg, efap->aziSpk, num_speaker_nodes ); // Q22 + Copy32( speaker_node_ele_deg, efap->eleSpk, num_speaker_nodes ); // Q22 /* Initialization of the vertex */ vertex_init_fx( efap->aziSpk, efap->eleSpk, &efap->vtxData ); @@ -384,10 +384,10 @@ void efap_determine_gains_fx( set32_fx( hEFAPdata->bufferLong_fx, 0, hEFAPdata->vtxData.numVtx ); /* Wrap angles to correct range */ - panning_wrap_angles_fx( azi_deg, ele_deg, &azi_wrap_int, &ele_wrap_int ); + panning_wrap_angles_fx( azi_deg, ele_deg, &azi_wrap_int, &ele_wrap_int ); // ouputs in q22 /* Panning */ - efap_panning_fx( azi_wrap_int, ele_wrap_int, &hEFAPdata->polyData, hEFAPdata->bufferLong_fx ); + efap_panning_fx( azi_wrap_int, ele_wrap_int, &hEFAPdata->polyData, hEFAPdata->bufferLong_fx ); // hEFAPdata->bufferLong_fx q31 IF( efap_mode == EFAP_MODE_EFAP ) { @@ -407,11 +407,11 @@ void efap_determine_gains_fx( } Word16 exp = 2; move16(); - normBuffer = ISqrt32( normBuffer, &exp ); + normBuffer = ISqrt32( normBuffer, &exp ); // Q=(31-exp) FOR( j = 0; j < hEFAPdata->numSpk; ++j ) { - hEFAPdata->bufferShort_fx[j] = Mpy_32_32( hEFAPdata->bufferShort_fx[j], normBuffer ); + hEFAPdata->bufferShort_fx[j] = Mpy_32_32( hEFAPdata->bufferShort_fx[j], normBuffer ); // Q=(30+31-exp-31)=>(30-exp) move32(); hEFAPdata->bufferShort_fx[j] = L_shl( hEFAPdata->bufferShort_fx[j], exp ); /* Q30 */ move32(); @@ -435,12 +435,12 @@ void efap_determine_gains_fx( } Word16 exp = 2; move16(); - normBuffer = Inv16( extract_l( L_shr( normBuffer, Q16 ) ), &exp ); + normBuffer = Inv16( extract_l( L_shr( normBuffer, Q16 ) ), &exp ); /*Q=(15-exp)*/ FOR( j = 0; j < hEFAPdata->numSpk; ++j ) { Word16 exp_temp = add( exp, 1 ); - hEFAPdata->bufferShort_fx[j] = Sqrt32( Mpy_32_16_1( hEFAPdata->bufferShort_fx[j], (Word16) normBuffer ), &exp_temp ); + hEFAPdata->bufferShort_fx[j] = Sqrt32( Mpy_32_16_1( hEFAPdata->bufferShort_fx[j], extract_l( normBuffer ) ) /*Q(30-exp)*/, &exp_temp ); // Q=(31-exp_temp) move32(); hEFAPdata->bufferShort_fx[j] = L_shl( hEFAPdata->bufferShort_fx[j], sub( exp_temp, 1 ) ); /* Q30 */ move32(); @@ -683,8 +683,8 @@ static ivas_error poly_init_fx( FOR( n = 0; n < efap->vtxData.numVtx; ++n ) { test(); - if ( GT_32( efap->vtxData.vertexArray[n].ele, L_sub( Q22_90_DEG, 4 ) ) || - LT_32( efap->vtxData.vertexArray[n].ele, L_sub( 4, Q22_90_DEG ) ) ) + if ( GT_32( efap->vtxData.vertexArray[n].ele /*Q22*/, ( Q22_90_DEG /*90.0 Q22*/ - 4 /*1e-6 Q22*/ ) ) || + LT_32( efap->vtxData.vertexArray[n].ele /*Q22*/, ( 4 /*1e-6 Q22*/ - Q22_90_DEG /*90.0 Q22*/ ) ) ) { efap->vtxData.vertexArray[n].isNaN = 1; move16(); @@ -722,35 +722,35 @@ static ivas_error poly_init_fx( maximum_l( efap->polyData.polysetArray[m].polyAzi, lengthTri2PolySorted[n], &tmpMax ); minimum_l( efap->polyData.polysetArray[m].polyAzi, lengthTri2PolySorted[n], &tmpMin ); - IF( GT_32( L_sub( tmpMax, tmpMin ), Q22_180_DEG ) /*180 in Q22*/ ) + IF( GT_32( L_sub( tmpMax /*q22*/, tmpMin /*q22*/ ), Q22_180_DEG /*180 in Q22*/ ) ) { FOR( j = 0; j < lengthTri2PolySorted[n]; ++j ) { assert( ( m + 2 < EFAP_MAX_POLY_SET ) && "EFAP: maximum polygons exceeded!" ); /* add two new polygons with azimuths wrapped to differing bounds */ - efap->polyData.polysetArray[add( m, 1 )].polyAzi[j] = efap_32mod32( efap->polyData.polysetArray[m].polyAzi[j], Q22_360_DEG ); /* Q22 */ + efap->polyData.polysetArray[m + 1].polyAzi[j] = efap_32mod32( efap->polyData.polysetArray[m].polyAzi[j] /*q22*/, Q22_360_DEG /*360 q22*/ ); /* Q22 */ move32(); - efap->polyData.polysetArray[add( m, 2 )].polyAzi[j] = L_sub( efap->polyData.polysetArray[add( m, 1 )].polyAzi[j], Q22_360_DEG ); /* Q22 */ + efap->polyData.polysetArray[m + 2].polyAzi[j] = L_sub( efap->polyData.polysetArray[m + 1].polyAzi[j] /*q22*/, Q22_360_DEG /*360 q22*/ ); /* Q22 */ move32(); /* Copy the rest of the fields */ - efap->polyData.polysetArray[add( m, 1 )].chan[j] = efap->polyData.polysetArray[m].chan[j]; + efap->polyData.polysetArray[m + 1].chan[j] = efap->polyData.polysetArray[m].chan[j]; move16(); - efap->polyData.polysetArray[add( m, 1 )].polyEle[j] = efap->polyData.polysetArray[m].polyEle[j]; /* Q22 */ + efap->polyData.polysetArray[m + 1].polyEle[j] = efap->polyData.polysetArray[m].polyEle[j]; /* Q22 */ move32(); - efap->polyData.polysetArray[add( m, 1 )].isNaN[j] = efap->polyData.polysetArray[m].isNaN[j]; + efap->polyData.polysetArray[m + 1].isNaN[j] = efap->polyData.polysetArray[m].isNaN[j]; move16(); - efap->polyData.polysetArray[add( m, 1 )].numChan = lengthTri2PolySorted[n]; + efap->polyData.polysetArray[m + 1].numChan = lengthTri2PolySorted[n]; move16(); - efap->polyData.polysetArray[add( m, 2 )].chan[j] = efap->polyData.polysetArray[m].chan[j]; + efap->polyData.polysetArray[m + 2].chan[j] = efap->polyData.polysetArray[m].chan[j]; move16(); - efap->polyData.polysetArray[add( m, 2 )].polyEle[j] = efap->polyData.polysetArray[m].polyEle[j]; /* Q22 */ + efap->polyData.polysetArray[m + 2].polyEle[j] = efap->polyData.polysetArray[m].polyEle[j]; /* Q22 */ move32(); - efap->polyData.polysetArray[add( m, 2 )].isNaN[j] = efap->polyData.polysetArray[m].isNaN[j]; + efap->polyData.polysetArray[m + 2].isNaN[j] = efap->polyData.polysetArray[m].isNaN[j]; move16(); - efap->polyData.polysetArray[add( m, 2 )].numChan = lengthTri2PolySorted[n]; + efap->polyData.polysetArray[m + 2].numChan = lengthTri2PolySorted[n]; move16(); } finalLength = add( finalLength, 2 ); @@ -928,7 +928,7 @@ static ivas_error sphere_triangulation_fx( *dmTranspose_fx = (Word32 **) p_dmTranspose; /* Remap Ghosts */ -remap_ghosts_fx( vtxData->vertexArray, polyData->triArray, numSpk, &vtxData->numVtx, polyData->numTri, *dmTranspose_fx ); +remap_ghosts_fx( vtxData->vertexArray, polyData->triArray, numSpk, &vtxData->numVtx, polyData->numTri, *dmTranspose_fx ); // dmTranspose_fx q31 return IVAS_ERR_OK; } @@ -1161,9 +1161,11 @@ static void initial_polyeder_fx( } /* 1. attempt to create an edge with nonzero length */ - WHILE( EQ_32( vtxData->vertexArray[tetrahedron[0]].azi, vtxData->vertexArray[tetrahedron[1]].azi ) && - EQ_32( vtxData->vertexArray[tetrahedron[0]].ele, vtxData->vertexArray[tetrahedron[1]].ele ) ) + test(); + WHILE( EQ_32( vtxData->vertexArray[tetrahedron[0]].azi /*q22*/, vtxData->vertexArray[tetrahedron[1]].azi /*q22*/ ) && + EQ_32( vtxData->vertexArray[tetrahedron[0]].ele /*q22*/, vtxData->vertexArray[tetrahedron[1]].ele /*q22*/ ) ) { + test(); tetrahedron[1] = add( tetrahedron[1], 1 ); move16(); assert( tetrahedron[1] < numVtx && "EFAP: convex hull construction failed, vertices are coincident!" ); @@ -1172,16 +1174,16 @@ static void initial_polyeder_fx( /* 2. attempt to create a triangle with nonzero area */ tmp = 0; move32(); - v_sub_fixed( vtxData->vertexArray[tetrahedron[1]].pos, vtxData->vertexArray[tetrahedron[0]].pos, tmp1, 3, 1 ); + v_sub_fixed( vtxData->vertexArray[tetrahedron[1]].pos, vtxData->vertexArray[tetrahedron[0]].pos, tmp1, 3, 1 ); // tmp1 Q(31-1) WHILE( LT_16( tetrahedron[2], numVtx ) ) { - v_sub_fixed( vtxData->vertexArray[tetrahedron[2]].pos, vtxData->vertexArray[tetrahedron[0]].pos, tmp2, 3, 1 ); - efap_crossp_fx( tmp1, tmp2, tmpCross ); // tmpCross Q29 + v_sub_fixed( vtxData->vertexArray[tetrahedron[2]].pos, vtxData->vertexArray[tetrahedron[0]].pos, tmp2, 3, 1 ); // tmp2 Q(31-1) + efap_crossp_fx( tmp1, tmp2, tmpCross ); // tmpCross Q29 FOR( i = 0; i < 3; i++ ) { tmp = L_add( tmp, Mpy_32_32( tmpCross[i], tmpCross[i] ) ); // tmp Q27 } - IF( GT_32( L_abs( tmp ), Mpy_32_32( POLY_THRESH_Q29, POLY_THRESH_Q29 ) ) ) /* compare tmp against POLY_THRESH^2 instead of sqrtf(tmp) */ + IF( GT_32( L_abs( tmp ), ( POLY_THRESH_Q29 /*1e-4f Q29*/ * POLY_THRESH_Q29 /*1e-4f Q29*/ ) >> 31 ) ) /* compare tmp against POLY_THRESH^2 instead of sqrtf(tmp) */ { BREAK; } @@ -1197,7 +1199,7 @@ static void initial_polyeder_fx( { v_sub_fixed( vtxData->vertexArray[tetrahedron[3]].pos, vtxData->vertexArray[tetrahedron[0]].pos, tmp3, 3, 1 ); // tmp3 Q30 tmp = dotp_fixed( tmp3, tmpCross, 3 ); // tmp Q28 - IF( GT_32( L_abs( tmp ), POLY_THRESH_Q28 ) ) + IF( GT_32( L_abs( tmp ), POLY_THRESH_Q28 /*1e-4f Q28*/ ) ) { BREAK; } @@ -1211,11 +1213,11 @@ static void initial_polyeder_fx( { vtxInHull[tetrahedron[i]] = 1; /* set vertex as added to hull*/ move16(); - centroid[0] = L_add( centroid[0], L_shr( vtxData->vertexArray[tetrahedron[i]].pos[0], Q2 ) ); + centroid[0] = L_add( centroid[0], L_shr( vtxData->vertexArray[tetrahedron[i]].pos[0], Q2 ) ); // Q29 move32(); - centroid[1] = L_add( centroid[1], L_shr( vtxData->vertexArray[tetrahedron[i]].pos[1], Q2 ) ); + centroid[1] = L_add( centroid[1], L_shr( vtxData->vertexArray[tetrahedron[i]].pos[1], Q2 ) ); // Q29 move32(); - centroid[2] = L_add( centroid[2], L_shr( vtxData->vertexArray[tetrahedron[i]].pos[2], Q2 ) ); + centroid[2] = L_add( centroid[2], L_shr( vtxData->vertexArray[tetrahedron[i]].pos[2], Q2 ) ); // Q29 move32(); } /* Executed below float operation @@ -1460,33 +1462,34 @@ static void add_ghost_speakers_fx( Word32 tmpAngleDiff[EFAP_MAX_SIZE_TMP_BUFF]; /* tmp array of angles differences */ Word32 sectors[EFAP_MAX_SIZE_TMP_BUFF]; /* Help us determine the zone where we should extend LS */ EFAP_VTX_DMX_TYPE vtxDmxType; + Word16 new_diff_e; vtxDmxType = EFAP_DMX_INTENSITY; move32(); numVertex = *numVtx; move16(); - maxAngle = 13421773; - move32(); //(1.f / 160.0f) in Q31 + maxAngle = 13421773; //(1.f / 160.0f) in Q31 + move32(); /* Extracting Azi and Ele for computation purposes */ FOR( i = 0; i < numVertex; ++i ) { - ele[i] = vertexArray[i].ele; + ele[i] = vertexArray[i].ele; // q22 move32(); } /* ADD VOG IF NECESSERAY (i.e. if the elevation of the highest LS is < 90 deg) */ a = 0; move16(); - maximum_l( ele, numVertex, &tmpEle ); + maximum_l( ele, numVertex, &tmpEle ); // tmpEle q22 lengthVertGhst = 0; move16(); - IF( LT_32( tmpEle, Q22_90_DEG ) ) + IF( LT_32( tmpEle, Q22_90_DEG /*90 q22*/ ) ) { IF( efip_flag ) { - IF( GT_32( tmpEle, Q22_45_DEG ) ) + IF( GT_32( tmpEle, Q22_45_DEG /*45 q22*/ ) ) { vtxDmxType = EFAP_DMX_NONE; move32(); @@ -1497,18 +1500,18 @@ static void add_ghost_speakers_fx( move32(); } } - add_vertex_fx( vertexArray, 0, Q22_90_DEG, add( numVertex, a ), vtxDmxType ); + add_vertex_fx( vertexArray, 0, Q22_90_DEG /*90 q22*/, add( numVertex, a ), vtxDmxType ); lengthVertGhst = add( lengthVertGhst, 1 ); a = add( a, 1 ); } /* ADD VOH IF NECESSERAY (i.e. if the elevation of the lowest LS is > -90 deg) */ - minimum_l( ele, numVertex, &tmpEle ); - IF( GT_32( tmpEle, -Q22_90_DEG ) ) + minimum_l( ele, numVertex, &tmpEle ); /*tmpEle q22*/ + IF( GT_32( tmpEle, -Q22_90_DEG /*90 q22*/ ) ) { IF( efip_flag ) { - IF( LT_32( tmpEle, -Q22_45_DEG ) ) + IF( LT_32( tmpEle, -Q22_45_DEG /*45 q22*/ ) ) { vtxDmxType = EFAP_DMX_NONE; move32(); @@ -1520,7 +1523,7 @@ static void add_ghost_speakers_fx( } } - add_vertex_fx( vertexArray, 0, -Q22_90_DEG, add( numVertex, a ), vtxDmxType ); + add_vertex_fx( vertexArray, 0, -Q22_90_DEG /*90 q22*/, add( numVertex, a ), vtxDmxType ); lengthVertGhst = add( lengthVertGhst, 1 ); a = add( a, 1 ); @@ -1532,9 +1535,9 @@ static void add_ghost_speakers_fx( FOR( i = 0; i < numVertex; ++i ) { - IF( LT_32( L_abs( vertexArray[i].ele ), Q22_45_DEG ) ) + IF( LT_32( L_abs( vertexArray[i].ele ), Q22_45_DEG /*45 q22*/ ) ) { - tmpAzi[k] = vertexArray[i].azi; + tmpAzi[k] = vertexArray[i].azi; // q22 move32(); k = add( k, 1 ); } @@ -1542,44 +1545,44 @@ static void add_ghost_speakers_fx( lengthHorGhst = 0; move16(); - IF( EQ_16( k, 0 ) ) /* no speakers found: add a triangle of ghost speakers */ + IF( k == 0 ) /* no speakers found: add a triangle of ghost speakers */ { add_vertex_fx( vertexArray, 0, 0, add( numVertex, a ), EFAP_DMX_INTENSITY ); - add_vertex_fx( vertexArray, Q22_120_DEG, 0, add( add( numVertex, a ), 1 ), EFAP_DMX_INTENSITY ); - add_vertex_fx( vertexArray, Q22_240_DEG, 0, add( add( numVertex, a ), 2 ), EFAP_DMX_INTENSITY ); + add_vertex_fx( vertexArray, Q22_120_DEG /*120 q22*/, 0, add( add( numVertex, a ), 1 ), EFAP_DMX_INTENSITY ); + add_vertex_fx( vertexArray, Q22_240_DEG /*240 q22*/, 0, add( add( numVertex, a ), 2 ), EFAP_DMX_INTENSITY ); a = add( a, 3 ); lengthHorGhst = add( lengthHorGhst, 3 ); } ELSE IF( EQ_16( k, 1 ) ) /* only one speaker found: add two ghost speakers to complete a triangle */ { - add_vertex_fx( vertexArray, L_add( tmpAzi[0], Q22_120_DEG ), 0, numVertex + a, EFAP_DMX_INTENSITY ); - add_vertex_fx( vertexArray, L_add( tmpAzi[0], Q22_240_DEG ), 0, numVertex + a + 1, EFAP_DMX_INTENSITY ); + add_vertex_fx( vertexArray, L_add( tmpAzi[0], Q22_120_DEG /*120 q22*/ ), 0, add( numVertex, a ), EFAP_DMX_INTENSITY ); + add_vertex_fx( vertexArray, L_add( tmpAzi[0], Q22_240_DEG /*240 q22*/ ), 0, add( add( numVertex, a ), 1 ), EFAP_DMX_INTENSITY ); a = add( a, 2 ); lengthHorGhst = add( lengthHorGhst, 2 ); } ELSE /* fill gaps greater than maxAngle */ { /* Here, k correspond to the number of LS whose ele is < 45 deg, should be = numVertex */ - sort_l( tmpAzi, k ); + sort_l( tmpAzi, k ); // tmpAzi q22 /* The next lines correspond to angle_diff = [azi(2:end), azi(1) + 360] - azi; in Matlab */ FOR( i = 0; i < k - 1; ++i ) { - tmpAngleDiff[i] = L_sub( tmpAzi[i + 1], tmpAzi[i] ); + tmpAngleDiff[i] = L_sub( tmpAzi[i + 1], tmpAzi[i] ); // q22 move32(); - sectors[i] = ceil_fixed( Mpy_32_32( tmpAngleDiff[i], maxAngle ), Q22 ); + sectors[i] = ceil_fixed( Mpy_32_32( tmpAngleDiff[i], maxAngle ), Q22 ); // q22 move32(); - IF( GT_32( sectors[i], Q22_1 ) ) + if ( GT_32( sectors[i], Q22_1 /*1 q22*/ ) ) { lengthHorGhst = add( lengthHorGhst, 1 ); } } - tmpAngleDiff[sub( k, 1 )] = L_sub( L_add( tmpAzi[0], Q22_360_DEG ), tmpAzi[sub( k, 1 )] ); + tmpAngleDiff[k - 1] = L_sub( L_add( tmpAzi[0], Q22_360_DEG /*360 q22*/ ), tmpAzi[k - 1] ); // q22 - sectors[sub( k, 1 )] = ceil_fixed( Mpy_32_32( tmpAngleDiff[sub( k, 1 )], maxAngle ), Q22 ); + sectors[k - 1] = ceil_fixed( Mpy_32_32( tmpAngleDiff[k - 1], maxAngle ), Q22 ); // q22 - IF( GT_32( sectors[sub( k, 1 )], Q22_1 ) ) + if ( GT_32( sectors[k - 1], Q22_1 /*1 q22*/ ) ) { lengthHorGhst = add( lengthHorGhst, 1 ); } @@ -1587,19 +1590,20 @@ static void add_ghost_speakers_fx( /* Adding new virtual speakers */ FOR( i = 0; i < k; ++i ) { - IF( GT_32( sectors[i], Q22_1 ) ) + IF( GT_32( sectors[i], Q22_1 /*1 q22*/ ) ) { - newDiff = tmpAngleDiff[i] / sectors[i]; - num_new = (Word16) L_shr( L_sub( sectors[i], Q22_1 ), Q22 ); + newDiff = BASOP_Util_Divide3232_Scale( tmpAngleDiff[i], sectors[i], &new_diff_e ); // Q=15-new_diff_e + newDiff = L_shl( newDiff, add( new_diff_e, 7 ) ); // q22 + num_new = extract_l( L_shr( L_sub( sectors[i], Q22_1 /*1 q22*/ ), Q22 ) ); // q0 FOR( j = 0; j < num_new; ++j ) { - newAzi = L_add( tmpAzi[i], L_shl( ( j + 1 ) * newDiff, Q22 ) ); + newAzi = L_add( tmpAzi[i], imult3216( newDiff, add( j, 1 ) ) ); // q22 add_vertex_fx( vertexArray, newAzi, 0, add( numVertex, a ), EFAP_DMX_INTENSITY ); a = add( a, 1 ); - IF( j > 0 ) + if ( j > 0 ) { lengthHorGhst = add( lengthHorGhst, 1 ); } @@ -1784,8 +1788,8 @@ static void add_vertex_to_convex_hull_fx( Word16 surface[3]; Word32 numHullVtx; Word32 centroid[3]; - const Word32 threshold = -268; - move32(); // -1e-6f in Q28 + const Word32 threshold = -268; // -1e-6f in Q28 + move32(); Word32 tmpDist; EFAP_LS_TRIANGLE triArrayNew[EFAP_MAX_POLY_SET]; Word16 tmp16, tmp_e; @@ -1806,30 +1810,30 @@ static void add_vertex_to_convex_hull_fx( IF( vtxInHull[i] ) { numHullVtx = L_add( numHullVtx, 1 ); - centroid[0] = L_add( centroid[0], L_shr( vtxData->vertexArray[i].pos[0], Q4 ) ); + centroid[0] = L_add( centroid[0], L_shr( vtxData->vertexArray[i].pos[0], Q4 ) ); // q27 move32(); - centroid[1] = L_add( centroid[1], L_shr( vtxData->vertexArray[i].pos[1], Q4 ) ); + centroid[1] = L_add( centroid[1], L_shr( vtxData->vertexArray[i].pos[1], Q4 ) ); // q27 move32(); - centroid[2] = L_add( centroid[2], L_shr( vtxData->vertexArray[i].pos[2], Q4 ) ); + centroid[2] = L_add( centroid[2], L_shr( vtxData->vertexArray[i].pos[2], Q4 ) ); // q27 move32(); } } /* numHullVtx = 1.0f / numHullVtx; */ - tmp16 = BASOP_Util_Divide3232_Scale( 1, numHullVtx, &tmp_e ); - tmp32 = L_shl_sat( tmp16, add( Q16, tmp_e ) ); /* Q31 */ + tmp16 = BASOP_Util_Divide3232_Scale( 1, numHullVtx, &tmp_e ); // q15-tmp_e + tmp32 = L_shl_sat( tmp16, add( Q16, tmp_e ) ); /* Q31 */ - centroid[0] = Mpy_32_32( centroid[0], tmp32 ); + centroid[0] = Mpy_32_32( centroid[0], tmp32 ); // q27 move32(); - centroid[1] = Mpy_32_32( centroid[1], tmp32 ); + centroid[1] = Mpy_32_32( centroid[1], tmp32 ); // q27 move32(); - centroid[2] = Mpy_32_32( centroid[1], tmp32 ); + centroid[2] = Mpy_32_32( centroid[1], tmp32 ); // q27 move32(); - centroid[0] = L_shl( centroid[0], 4 ); + centroid[0] = L_shl( centroid[0], 4 ); // q31 move32(); - centroid[1] = L_shl( centroid[1], 4 ); + centroid[1] = L_shl( centroid[1], 4 ); // q31 move32(); - centroid[2] = L_shl( centroid[2], 4 ); + centroid[2] = L_shl( centroid[2], 4 ); // q31 move32(); /* Processing */ @@ -1920,13 +1924,13 @@ static void visible_edges_fx( /* Finding the max vertex */ FOR( i = 0; i < numSurface; ++i ) { - tmpMax[i] = triArray[visible[i]].LS[0]; + tmpMax[i] = triArray[visible[i]].LS[0]; // q0 move16(); FOR( j = 1; j < 3; ++j ) { if ( LT_16( tmpMax[i], triArray[visible[i]].LS[j] ) ) { - tmpMax[i] = triArray[visible[i]].LS[j]; + tmpMax[i] = triArray[visible[i]].LS[j]; // q0 move16(); } } @@ -1977,7 +1981,7 @@ static void visible_edges_fx( { edges[k] = a; move16(); - edges[add( k, 1 )] = b; + edges[k + 1] = b; move16(); k = add( k, 2 ); } @@ -2117,7 +2121,7 @@ static void flip_plane( static void flip_plane_fx( const EFAP_VERTEX *vtxArray, /* i : Vertex array */ Word16 *surface, /* i/o: Surface/vertices to be flipped */ - const Word32 centroid[3] /* i : Centroid of convex hull from which to orient the planes outward */ + const Word32 centroid[3] /* i : Centroid of convex hull from which to orient the planes outward q31*/ ) { Word16 tmp; @@ -2127,7 +2131,7 @@ static void flip_plane_fx( vtxArray[surface[0]].pos, vtxArray[surface[1]].pos, vtxArray[surface[2]].pos, - centroid ); + centroid ); // q31 IF( dist > 0 ) { @@ -2319,9 +2323,10 @@ static void remap_ghosts_fx( Word32 tmpMat[EFAP_MAX_SIZE_TMP_BUFF][EFAP_MAX_SIZE_TMP_BUFF]; /* Q31 */ Word32 tmpNewMat[EFAP_MAX_SIZE_TMP_BUFF][EFAP_MAX_SIZE_TMP_BUFF]; /* Q31 */ Word32 tmpDist; - const Word32 thresh = 214748; + Word16 tmpDist_e; + const Word32 thresh = 214748; // 1e-4f in Q31 Word16 tmp16, tmp_e; - move32(); // 1e-4f in Q31 + move32(); set32_fx( tmpVec, 0, EFAP_MAX_SIZE_TMP_BUFF ); set32_fx( tmpVec2, 0, EFAP_MAX_SIZE_TMP_BUFF ); @@ -2333,7 +2338,7 @@ static void remap_ghosts_fx( IF( find_int_in_tri_fx( triArray, g, numTri, posFound ) == 0 ) { remove_vertex_fx( vtxArray, g, numVtx ); - --numVtx; + numVtx = sub( numVtx, 1 ); FOR( i = 0; i < numTri; ++i ) { FOR( j = 0; j < 3; ++j ) @@ -2361,9 +2366,9 @@ static void remap_ghosts_fx( set32_fx( tmpMat[i], 0, numTot ); set32_fx( tmpNewMat[i], 0, numTot ); - tmpMat[i][i] = ONE_IN_Q31; + tmpMat[i][i] = ONE_IN_Q31; // q31 move32(); - tmpNewMat[i][i] = ONE_IN_Q31; + tmpNewMat[i][i] = ONE_IN_Q31; // q31 move32(); } @@ -2382,8 +2387,8 @@ static void remap_ghosts_fx( } /* The neighbours are set to 1.0/tmpL */ - tmp16 = BASOP_Util_Divide3232_Scale( 1, tmpL, &tmp_e ); - inv_tmpL = L_shl_sat( tmp16, add( Q16, tmp_e ) ); /* Q31 */ + tmp16 = BASOP_Util_Divide3232_Scale( 1, tmpL, &tmp_e ); // Q=15-tmp_e + inv_tmpL = L_shl_sat( tmp16, add( Q16, tmp_e ) ); /* Q31 */ FOR( j = 0; j < tmpL; ++j ) { tmpMat[neighbours[j]][i] = inv_tmpL; /* Q31 */ @@ -2405,18 +2410,22 @@ static void remap_ghosts_fx( FOR( i = numSpk; i < numTot; ++i ) { - Copy32( tmpNewMat[i], tmpVec, numTot ); + Copy32( tmpNewMat[i], tmpVec, numTot ); // q31 - tmpDist = sum_l( &tmpVec[numSpk], sub( numTot, numSpk ) ); + tmpDist_e = 0; + move16(); + tmpDist = sum_32_fx( &tmpVec[numSpk], sub( numTot, numSpk ), &tmpDist_e ); // Q=31-tmpDist_e - WHILE( GT_32( tmpDist, thresh ) ) + WHILE( EQ_16( BASOP_Util_Cmp_Mant32Exp( tmpDist, tmpDist_e, thresh, 0 ), 1 ) ) { - matrix_times_row_fx( tmpMat, tmpVec, numTot, tmpVec2 ); - Copy32( tmpVec2, tmpVec, numTot ); + matrix_times_row_fx( tmpMat, tmpVec, numTot, tmpVec2 ); // tmpVec2 Q31 + Copy32( tmpVec2, tmpVec, numTot ); // Q31 set32_fx( tmpVec2, 0, numTot ); - tmpDist = sum_l( &tmpVec[numSpk], sub( numTot, numSpk ) ); + tmpDist_e = 0; + move16(); + tmpDist = sum_32_fx( &tmpVec[numSpk], sub( numTot, numSpk ), &tmpDist_e ); } - Copy32( tmpVec, tmpNewMat[i], numTot ); + Copy32( tmpVec, tmpNewMat[i], numTot ); // q31 } FOR( i = 0; i < numSpk; ++i ) @@ -2425,7 +2434,7 @@ static void remap_ghosts_fx( FOR( j = 0; j < numSpk; ++j ) { test(); - IF( tmpNewMat[j][i] == 0 || EQ_32( tmpNewMat[j][i], 0x7fffffff ) ) + IF( tmpNewMat[j][i] == 0 || EQ_32( tmpNewMat[j][i], 0x7fffffff /*q31*/ ) ) { downmixMatrixTranspose[j][i] = tmpNewMat[j][i]; /* Q31 */ move32(); @@ -2434,9 +2443,9 @@ static void remap_ghosts_fx( { Word16 exp = 0; move16(); - Word32 tmp_sqrt = Sqrt32( tmpNewMat[j][i], &exp ); - tmp_sqrt = L_shl( tmp_sqrt, exp ); - downmixMatrixTranspose[j][i] = tmp_sqrt; /* Q31 */ + Word32 tmp_sqrt = Sqrt32( tmpNewMat[j][i], &exp ); /*31-exp*/ + tmp_sqrt = L_shl( tmp_sqrt, exp ); /*q31*/ + downmixMatrixTranspose[j][i] = tmp_sqrt; /* Q31 */ move32(); } } @@ -2456,7 +2465,7 @@ static void remap_ghosts_fx( case EFAP_DMX_INTENSITY: default: test(); - IF( tmpNewMat[j][i] == 0 || EQ_32( tmpNewMat[j][i], ONE_IN_Q31 ) ) + IF( tmpNewMat[j][i] == 0 || EQ_32( tmpNewMat[j][i], ONE_IN_Q31 /*q31*/ ) ) { downmixMatrixTranspose[j][i] = tmpNewMat[j][i]; /* Q31 */ move32(); @@ -2465,9 +2474,9 @@ static void remap_ghosts_fx( { Word16 exp = 0; move16(); - Word32 tmp_sqrt = Sqrt32( tmpNewMat[j][i], &exp ); - tmp_sqrt = L_shl( tmp_sqrt, exp ); - downmixMatrixTranspose[j][i] = tmp_sqrt; /* Q31 */ + Word32 tmp_sqrt = Sqrt32( tmpNewMat[j][i], &exp ); /*31-exp*/ + tmp_sqrt = L_shl( tmp_sqrt, exp ); /*31*/ + downmixMatrixTranspose[j][i] = tmp_sqrt; /* Q31 */ move32(); } BREAK; @@ -2515,8 +2524,8 @@ static void vertex_init( *-------------------------------------------------------------------------*/ static void vertex_init_fx( - const Word32 *aziSpk, /* i : Azimuths of the LS setup */ - const Word32 *eleSpk, /* i : Elevations of the LS setup */ + const Word32 *aziSpk, /* i : Azimuths of the LS setup q22 */ + const Word32 *eleSpk, /* i : Elevations of the LS setup q22 */ EFAP_VERTEX_DATA *efapVtxData /* i/o: Vertex data structure that will be updated */ ) { @@ -2606,10 +2615,10 @@ static void efap_panning( *-------------------------------------------------------------------------*/ static void efap_panning_fx( - const Word32 azi, /* i : Value of the azimuth */ - const Word32 ele, /* i : Value of the elevation */ + const Word32 azi, /* i : Value of the azimuth q22 */ + const Word32 ele, /* i : Value of the elevation q22 */ const EFAP_POLYSET_DATA *polyData, /* i : Polygon data */ - Word32 *bufferL /* o : 1D array of length numSpk that will contain the tmp values */ + Word32 *bufferL /* o : 1D array of length numSpk that will contain the tmp values q31*/ ) { Word16 i; @@ -2622,9 +2631,9 @@ static void efap_panning_fx( Word32 normTmpBuff; Word32 P[2]; - P[0] = azi; + P[0] = azi; // q22 move32(); - P[1] = ele; + P[1] = ele; // q22 move32(); set32_fx( tmpBuff, 0, EFAP_MAX_CHAN_NUM ); set32_fx( aziPoly, 0, EFAP_MAX_CHAN_NUM ); @@ -2644,32 +2653,32 @@ static void efap_panning_fx( { chan[i] = polyData->polysetArray[polyIdx].chan[i]; move16(); - aziPoly[i] = polyData->polysetArray[polyIdx].polyAzi[i]; + aziPoly[i] = polyData->polysetArray[polyIdx].polyAzi[i]; // q22 move32(); if ( EQ_16( polyData->polysetArray[polyIdx].isNaN[i], 1 ) ) { - aziPoly[i] = P[0]; + aziPoly[i] = P[0]; // q22 move32(); } - elePoly[i] = polyData->polysetArray[polyIdx].polyEle[i]; + elePoly[i] = polyData->polysetArray[polyIdx].polyEle[i]; // q22 move32(); } /* Computing the gain for the polygon */ - get_poly_gains_fx( P[0], P[1], aziPoly, elePoly, numChan, tmpBuff ); + get_poly_gains_fx( P[0], P[1], aziPoly, elePoly, numChan, tmpBuff ); // tmpBuff q31 /* Computing the norm of the tmp buffer */ - normTmpBuff = dotp_fixed( tmpBuff, tmpBuff, numChan ); + normTmpBuff = dotp_fixed( tmpBuff, tmpBuff, numChan ); // q31 Word16 exp = 0; move16(); - normTmpBuff = ISqrt32( normTmpBuff, &exp ); + normTmpBuff = ISqrt32( normTmpBuff, &exp ); // Q=31-exp /* Updating the buffer structure */ FOR( i = 0; i < numChan; ++i ) { - bufferL[chan[i]] = Mpy_32_32( tmpBuff[i], normTmpBuff ); + bufferL[chan[i]] = Mpy_32_32( tmpBuff[i], normTmpBuff ); // 31+(31-exp)-31=>31-exp move32(); bufferL[chan[i]] = L_shl( bufferL[chan[i]], exp ); // Q31 move32(); @@ -2742,12 +2751,12 @@ static void get_poly_gains( *-------------------------------------------------------------------------*/ static void get_poly_gains_fx( - const Word32 azi, /* i : Value of the azimuth */ - const Word32 ele, /* i : Value of the elevation */ - const Word32 aziPoly[EFAP_MAX_CHAN_NUM], /* i : Azimuths of the considered polygons */ - const Word32 elePoly[EFAP_MAX_CHAN_NUM], /* i : Elevations of the considered polygons */ + const Word32 azi, /* i : Value of the azimuth q22 */ + const Word32 ele, /* i : Value of the elevation q22 */ + const Word32 aziPoly[EFAP_MAX_CHAN_NUM], /* i : Azimuths of the considered polygons q22 */ + const Word32 elePoly[EFAP_MAX_CHAN_NUM], /* i : Elevations of the considered polygons q22 */ const Word16 numChan, /* i : Length of aziPoly & elePoly */ - Word32 *buffer /* o : 1D array of length numSpk that will contain the tmp values */ + Word32 *buffer /* o : 1D array of length numSpk that will contain the tmp values q31*/ ) { Word16 i, j; @@ -2756,39 +2765,39 @@ static void get_poly_gains_fx( Word32 A[2], B[2], C[2]; Word32 P_minus_A[2]; - P[0] = azi; + P[0] = azi; // q22 move32(); - P[1] = ele; + P[1] = ele; // q22 move32(); /* Processing, we search for the triangle in which belong P, then we compute the gain */ FOR( i = 1; i < numChan + 1; ++i ) { - A[0] = aziPoly[i - 1]; + A[0] = aziPoly[i - 1]; // q22 move32(); - A[1] = elePoly[i - 1]; + A[1] = elePoly[i - 1]; // q22 move32(); - v_sub_fixed( P, A, P_minus_A, 2, 0 ); /* Precalculate value of (P-A) */ + v_sub_fixed( P, A, P_minus_A, 2, 0 ); /* Precalculate value of (P-A) q22*/ FOR( j = i; j < numChan - 2 + i; ++j ) { idx1 = add( 1, ( j % numChan ) ); idx2 = add( 1, ( idx1 % numChan ) ); - B[0] = aziPoly[sub( idx1, 1 )]; + B[0] = aziPoly[idx1 - 1]; // q22 move32(); - B[1] = elePoly[sub( idx1, 1 )]; + B[1] = elePoly[idx1 - 1]; // q22 move32(); - C[0] = aziPoly[sub( idx2, 1 )]; + C[0] = aziPoly[idx2 - 1]; // q22 move32(); - C[1] = elePoly[sub( idx2, 1 )]; + C[1] = elePoly[idx2 - 1]; // q22 move32(); IF( in_tri_fx( A, B, C, P_minus_A ) ) { - buffer[i - 1] = L_shl_sat( get_tri_gain_fx( A, B, C, P_minus_A ), Q12 ); + buffer[i - 1] = L_shl_sat( get_tri_gain_fx( A, B, C, P_minus_A ), Q18 ); // q13+q18->q31 move32(); BREAK; } @@ -2847,10 +2856,10 @@ static float get_tri_gain( *-------------------------------------------------------------------------*/ static Word32 get_tri_gain_fx( - const Word32 A[2], /* i : Coordinate of one apex of the triangle */ - const Word32 B[2], /* i : Coordinate of one apex of the triangle */ - const Word32 C[2], /* i : Coordinate of one apex of the triangle */ - const Word32 P_minus_A[2] /* i : Value of (P - A) */ + const Word32 A[2], /* i : Coordinate of one apex of the triangle q22*/ + const Word32 B[2], /* i : Coordinate of one apex of the triangle q22*/ + const Word32 C[2], /* i : Coordinate of one apex of the triangle q22*/ + const Word32 P_minus_A[2] /* i : Value of (P - A) q22 */ ) { Word32 N[2], tmpN[2]; @@ -2859,32 +2868,38 @@ static Word32 get_tri_gain_fx( Word32 gain; /* Processing */ - tmpN[0] = L_sub( B[1], C[1] ); + tmpN[0] = L_sub( B[1], C[1] ); // q22 move32(); - tmpN[1] = L_sub( C[0], B[0] ); + tmpN[1] = L_sub( C[0], B[0] ); // q22 move32(); - v_sub_fixed( B, A, tmpSub1, 2, 0 ); + v_sub_fixed( B, A, tmpSub1, 2, 0 ); // tmpSub1 q22 tmpDot1 = dotp_fixed( tmpN, tmpSub1, 2 ); // Q13 - Word16 exp = Q13; + Word16 exp = Q18; move16(); Word32 inv_tmpDot2 = L_shl( tmpDot1, norm_l( tmpDot1 ) ); exp = sub( exp, norm_l( tmpDot1 ) ); - Word16 inv_tmpDot1 = Inv16( (Word16) L_shr( inv_tmpDot2, Q16 ), &exp ); - v_multc_fixed( tmpN, L_shl( inv_tmpDot1, add( Q16, exp ) ), N, 2 ); + Word16 inv_tmpDot1 = Inv16( extract_h( inv_tmpDot2 ), &exp ); // 15-exp + v_multc_fixed( tmpN, L_shl( inv_tmpDot1, add( Q16, exp ) ), N, 2 ); // 22+31-31->22 - tmpDot2 = dotp_fixed( P_minus_A, N, 2 ); // Q18 + tmpDot2 = dotp_fixed( P_minus_A, N, 2 ); // 22+22-31->13 - gain = L_sub( 0x00040000, tmpDot2 ); + if ( EQ_32( tmpDot2, 8191 ) ) + { + tmpDot2 = 8192; // Q13 + move32(); + } + + gain = L_sub( 8192, tmpDot2 ); // Q13 /* Set gains <= -60dB to 0 to avoid problems in SVD */ - if ( LT_32( L_abs( gain ), 1 ) ) + if ( EQ_16( BASOP_Util_Cmp_Mant32Exp( L_abs( gain ), 18, 2147 /*1e-6 q31*/, 0 ), -1 ) ) { gain = 0; move32(); } - return gain; // Q18 + return gain; // Q13 } #endif @@ -2964,32 +2979,39 @@ static void add_vertex_fx( /* Updating the vertex array */ - tmp = efap_32mod32( L_sub( Q22_180_DEG, azi ), Q22_360_DEG ); - vtxArray[pos].azi = L_sub( Q22_180_DEG, tmp ); + tmp = efap_32mod32( L_sub( Q22_180_DEG /*180 q22*/, azi ), Q22_360_DEG /*360 q22*/ ); // q22 + vtxArray[pos].azi = L_sub( Q22_180_DEG /*180 q22*/, tmp ); // q22 move32(); - tmp = ( LT_32( Q22_180_DEG, ele ) ? Q22_180_DEG : ele ); + IF( LT_32( Q22_180_DEG /*180 q22*/, ele ) ) + tmp = Q22_180_DEG /*180 q22*/; + ELSE + tmp = ele; // Q22 move32(); - vtxArray[pos].ele = ( GT_32( -Q22_180_DEG, tmp ) ? -Q22_180_DEG : tmp ); + IF( GT_32( -Q22_180_DEG /*180 q22*/, tmp ) ) + vtxArray[pos].ele = -Q22_180_DEG /*180 q22*/; + ELSE + vtxArray[pos] + .ele = tmp; // q22 move32(); /* Converting spherical coordinates to cartesians, assuming radius = 1 */ - sph2cart_fx( vtxArray[pos].azi, vtxArray[pos].ele, &vtxArray[pos].pos[0] ); + sph2cart_fx( vtxArray[pos].azi, vtxArray[pos].ele, &vtxArray[pos].pos[0] ); // vtxArray[pos].pos[0] q31 /* Computing the index defined by idx = idxAziTmp + 181 * idxEleTmp */ /* IdxAziTmp */ - tmp = L_abs( L_sub( Q22_90_DEG, L_abs( vtxArray[pos].azi ) ) ); // Q22 - idxAziTmp = L_shr( anint_fixed( tmp, Q22 ), Q22 ); + tmp = L_abs( L_sub( Q22_90_DEG /*90 q22*/, L_abs( vtxArray[pos].azi ) ) ); // Q22 + idxAziTmp = L_shr( anint_fixed( tmp, Q22 ), Q22 ); // q22-q22->q0 /* IdxEleTmp */ - tmp = L_abs( vtxArray[pos].ele ); - idxEleTmp = tmp; + tmp = L_abs( vtxArray[pos].ele ); // q22 + idxEleTmp = tmp; // q22 move16(); - idxEleTmp = L_sub( Q22_90_DEG, idxEleTmp ); + idxEleTmp = L_sub( Q22_90_DEG /*90 q22*/, idxEleTmp ); // q22 /* Final Idx */ - vtxArray[pos].idx = add( extract_l( idxAziTmp ), i_mult( 181, extract_l( L_shr( idxEleTmp, Q22 ) ) ) ); + vtxArray[pos].idx = add( extract_l( idxAziTmp ), i_mult( 181, extract_l( L_shr( idxEleTmp, Q22 ) ) ) ); // q0 /* Setting the nan flag to 0 */ vtxArray[pos].isNaN = 0; @@ -3033,8 +3055,10 @@ static void efap_sort_s_fx( move16(); tempi = idx[i]; move16(); + test(); FOR( j = i + 1; ( j < len ) && ( tempr > x[j] ); j++ ) { + test(); x[j - 1] = x[j]; move16(); idx[j - 1] = idx[j]; @@ -3122,18 +3146,18 @@ static Word32 vertex_distance_fx( /* Assigning the coordinates to the vector */ FOR( i = 0; i < 3; ++i ) { - A[i] = vtxArray[tri.LS[0]].pos[i]; + A[i] = vtxArray[tri.LS[0]].pos[i]; // q31 move32(); - B[i] = vtxArray[tri.LS[1]].pos[i]; + B[i] = vtxArray[tri.LS[1]].pos[i]; // q31 move32(); - C[i] = vtxArray[tri.LS[2]].pos[i]; + C[i] = vtxArray[tri.LS[2]].pos[i]; // q31 move32(); - P[i] = vtxArray[vtxIdx].pos[i]; + P[i] = vtxArray[vtxIdx].pos[i]; // q31 move32(); } - return point_plane_distance_fx( A, B, C, P ); + return point_plane_distance_fx( A, B, C, P ); // q28 } #endif @@ -3166,16 +3190,16 @@ static float point_poly_distance( static Word32 point_poly_distance_fx( const EFAP_POLYSET poly, /* i : The polygon which forms a plane */ - const Word32 X[3] /* i : Cartesian coordinates of the point of interest */ + const Word32 X[3] /* i : Cartesian coordinates of the point of interest q31*/ ) { Word32 P1[3], P2[3], P3[3]; - sph2cart_fx( poly.polyAzi[0], poly.polyEle[0], &P1[0] ); - sph2cart_fx( poly.polyAzi[1], poly.polyEle[1], &P2[0] ); - sph2cart_fx( poly.polyAzi[2], poly.polyEle[2], &P3[0] ); + sph2cart_fx( poly.polyAzi[0], poly.polyEle[0], &P1[0] ); // P1[0] q31 + sph2cart_fx( poly.polyAzi[1], poly.polyEle[1], &P2[0] ); // P2[0] q31 + sph2cart_fx( poly.polyAzi[2], poly.polyEle[2], &P3[0] ); // P3[0] q31 - return point_plane_distance_fx( P1, P2, P3, X ); + return point_plane_distance_fx( P1, P2, P3, X ); // q28 } #endif @@ -3232,10 +3256,10 @@ static float point_plane_distance( *-------------------------------------------------------------------------*/ static Word32 point_plane_distance_fx( // returns output in Q28 - const Word32 P1[3], /* i : First point of the triangle that defines the planes */ - const Word32 P2[3], /* i : Second point of the triangle */ - const Word32 P3[3], /* i : Third point of the triangle */ - const Word32 X[3] /* i : The point of interest */ + const Word32 P1[3], /* i : First point of the triangle that defines the planes q31*/ + const Word32 P2[3], /* i : Second point of the triangle q31*/ + const Word32 P3[3], /* i : Third point of the triangle q31*/ + const Word32 X[3] /* i : The point of interest q31*/ ) { Word32 tmpCross1[3], tmpCross2[3]; @@ -3261,8 +3285,8 @@ static Word32 point_plane_distance_fx( // returns output in Q28 } /* Cross Product */ - v_sub_fixed( P1, P2, tmpCross1, 3, 1 ); - v_sub_fixed( P1, P3, tmpCross2, 3, 1 ); + v_sub_fixed( P1, P2, tmpCross1, 3, 1 ); // tmpCross1 q30 + v_sub_fixed( P1, P3, tmpCross2, 3, 1 ); // tmpCross2 q30 /* resultCross = cross(P1-P2,P1-P3) */ efap_crossp_fx( tmpCross1, tmpCross2, resultCross ); // Q29 @@ -3616,10 +3640,10 @@ static void matrix_times_row( *-------------------------------------------------------------------------*/ static void matrix_times_row_fx( - Word32 mat[EFAP_MAX_SIZE_TMP_BUFF][EFAP_MAX_SIZE_TMP_BUFF], /* i : The input matrix */ - const Word32 *vec, /* i : The input row vector */ + Word32 mat[EFAP_MAX_SIZE_TMP_BUFF][EFAP_MAX_SIZE_TMP_BUFF], /* i : The input matrix q31 */ + const Word32 *vec, /* i : The input row vector q31*/ const Word16 L, /* i : Row length */ - Word32 *out /* o : Output vector */ + Word32 *out /* o : Output vector q31 */ ) { Word16 i, j; @@ -3628,7 +3652,7 @@ static void matrix_times_row_fx( { FOR( j = 0; j < L; ++j ) { - out[i] = L_add( out[i], Mpy_32_32( mat[i][j], vec[j] ) ); + out[i] = L_add( out[i], Mpy_32_32( mat[i][j], vec[j] ) ); /*31+31-31=>31*/ move32(); } } @@ -3684,7 +3708,7 @@ static void tri_to_poly_fx( vtxArray[triArray[i].LS[2]].pos, vtxArray[j].pos ) ); // Q28 - IF( LT_32( dist, 268435 ) /* 1e-3f in Q28 */ ) + IF( LT_32( dist, 268435 /* 1e-3f in Q28 */ ) ) { assert( lenPoly < EFAP_MAX_CHAN_NUM && "EFAP: exceeded max polygon vertices!" ); poly[lenPoly] = j; @@ -4068,7 +4092,7 @@ static void sort_channels_vertex_fx( v_sub_fixed( P2, P1, tmpU, 3, 1 ); // tmpU Q30 Word16 exp1 = 2; move16(); - normU = ISqrt32( dotp_fixed( tmpU, tmpU, 3 ), &exp1 ); + normU = ISqrt32( dotp_fixed( tmpU, tmpU, 3 ) /*q29*/, &exp1 ); /*q=31-exp1*/ // normU = L_shl_sat( normU, exp ); //normU Q31 v_multc_fixed( tmpU, normU, U, 3 ); // U Q30 - exp1 @@ -4078,21 +4102,21 @@ static void sort_channels_vertex_fx( FOR( i = 0; i < 3; i++ ) { - tmpV2[i] = L_shl( tmpV2[i], add( Q2, shl( exp1, 1 ) ) ); + tmpV2[i] = L_shl( tmpV2[i], add( Q2, shl( exp1, 1 ) ) ); // q30 move32(); } v_sub_fixed( tmpV1, tmpV2, tmpV3, 3, 0 ); // tmpV3 Q30 Word16 exp2 = 2; move16(); - normV = ISqrt32( dotp_fixed( tmpV3, tmpV3, 3 ), &exp2 ); + normV = ISqrt32( dotp_fixed( tmpV3, tmpV3, 3 ) /*q29*/, &exp2 ); // q=31-exp2 v_multc_fixed( tmpV3, normV, V, 3 ); // V Q30 - exp2 /* Center of the first Triangle */ FOR( i = 0; i < 3; ++i ) { - MC[i] = L_shl( Mpy_32_32( L_add( L_add( L_shr( P1[i], Q2 ), L_shr( P2[i], Q2 ) ), L_shr( P3[i], Q2 ) ), 715827883 /* 1 / 3 in Q31 */ ), Q2 ); + MC[i] = L_shl( Mpy_32_32( L_add( L_add( L_shr( P1[i], Q2 ), L_shr( P2[i], Q2 ) ), L_shr( P3[i], Q2 ) ), 715827883 /* 1 / 3 in Q31 */ ), Q2 ); // q29+2=>q31 move32(); } @@ -4101,7 +4125,7 @@ static void sort_channels_vertex_fx( { FOR( j = 0; j < 3; ++j ) { - tmpP[j] = vtxArray[channels[i]].pos[j]; + tmpP[j] = vtxArray[channels[i]].pos[j]; // q31 move32(); } @@ -4156,19 +4180,19 @@ static float efap_fmodf( *-------------------------------------------------------------------------*/ static Word32 efap_32mod32( - const Word32 x, /* i : Dividend */ - const Word32 y /* i : Divisor */ + const Word32 x, /* i : Dividend q22*/ + const Word32 y /* i : Divisor q22 */ ) { - Word32 result = x % y; + Word32 result = x % y; // q22 move32(); IF( result >= 0 ) { - return result; + return result; // q22 } ELSE { - return L_add( result, y ); + return L_add( result, y ); // q22 } } #endif @@ -4238,7 +4262,7 @@ static int16_t get_poly_num( } #else static Word16 get_poly_num_fx( - const Word32 P[2], /* i : Azimuth and elevation of the point */ + const Word32 P[2], /* i : Azimuth and elevation of the point q22*/ const EFAP_POLYSET_DATA *polyData /* i : Polyset struct */ ) { @@ -4253,7 +4277,7 @@ static Word16 get_poly_num_fx( num_poly = 0; move16(); - sph2cart_fx( P[0], P[1], &pos[0] ); + sph2cart_fx( P[0], P[1], &pos[0] ); // pos[0] q31 /* Filter the polygon list with a fast 2d check */ FOR( i = 0; i < polyData->numPoly; ++i ) @@ -4261,7 +4285,7 @@ static Word16 get_poly_num_fx( IF( in_poly_fx( P, polyData->polysetArray[i] ) ) { /* select only polygons which are visible from the point */ - dist_tmp = point_poly_distance_fx( polyData->polysetArray[i], pos ); + dist_tmp = point_poly_distance_fx( polyData->polysetArray[i], pos ); // q28 IF( dist_tmp == 0 ) { return i; @@ -4270,7 +4294,7 @@ static Word16 get_poly_num_fx( { poly_tmp[num_poly] = i; move16(); - poly_dist[num_poly] = dist_tmp; + poly_dist[num_poly] = dist_tmp; // q28 move32(); num_poly = add( num_poly, 1 ); } @@ -4284,7 +4308,7 @@ static Word16 get_poly_num_fx( /* select the polygon with the smallest distance */ found_poly = poly_tmp[0]; move16(); - dist_tmp = poly_dist[0]; + dist_tmp = poly_dist[0]; // q28 move32(); FOR( i = 1; i < num_poly; i++ ) { @@ -4292,7 +4316,7 @@ static Word16 get_poly_num_fx( { found_poly = poly_tmp[i]; move16(); - dist_tmp = poly_dist[i]; + dist_tmp = poly_dist[i]; // q28 move32(); } } @@ -4374,7 +4398,7 @@ static int16_t in_poly( } #else static Word16 in_poly_fx( /* Angles are in Q22 */ - const Word32 P[2], /* i : Azimuth and elevation of the point */ + const Word32 P[2], /* i : Azimuth and elevation of the point q22*/ const EFAP_POLYSET poly /* i : Polyset struct */ ) { @@ -4397,45 +4421,45 @@ static Word16 in_poly_fx( /* Angles are in Q22 */ IF( poly.isNaN[0] ) { - A[0] = P[0]; + A[0] = P[0]; // q22 move32(); } ELSE { - A[0] = poly.polyAzi[0]; + A[0] = poly.polyAzi[0]; // q22 move32(); } - A[1] = poly.polyEle[0]; + A[1] = poly.polyEle[0]; // q22 move32(); - v_sub_fixed( P, A, P_minus_A, 2, 0 ); /* Precalculate value of (P-A) */ + v_sub_fixed( P, A, P_minus_A, 2, 0 ); /* Precalculate value of (P-A) q22*/ FOR( n = 1; n < sub( numVertices, 1 ); ++n ) { IF( poly.isNaN[n] ) { - B[0] = P[0]; + B[0] = P[0]; // q22 move32(); } ELSE { - B[0] = poly.polyAzi[n]; + B[0] = poly.polyAzi[n]; // q22 move32(); } - B[1] = poly.polyEle[n]; + B[1] = poly.polyEle[n]; // q22 move32(); IF( poly.isNaN[n + 1] ) { - C[0] = P[0]; + C[0] = P[0]; // q22 move32(); } ELSE { - C[0] = poly.polyAzi[n + 1]; + C[0] = poly.polyAzi[n + 1]; // q22 move32(); } - C[1] = poly.polyEle[n + 1]; + C[1] = poly.polyEle[n + 1]; // q22 move32(); IF( in_tri_fx( A, B, C, P_minus_A ) ) @@ -4509,10 +4533,10 @@ static int16_t in_tri( } #else static Word16 in_tri_fx( - Word32 A[2], /* i : Coordinate of one apex of the triangle */ - Word32 B[2], /* i : Coordinate of one apex of the triangle */ - Word32 C[2], /* i : Coordinate of one apex of the triangle */ - Word32 P_minus_A[2] /* i : Value of (P - A) */ + Word32 A[2], /* i : Coordinate of one apex of the triangle q22*/ + Word32 B[2], /* i : Coordinate of one apex of the triangle q22*/ + Word32 C[2], /* i : Coordinate of one apex of the triangle q22*/ + Word32 P_minus_A[2] /* i : Value of (P - A) q22*/ ) { Word32 tmpDot1[2], tmpDot2[2]; @@ -4521,7 +4545,7 @@ static Word16 in_tri_fx( Word16 tmp16, tmp_e; Word64 S[2]; /* Threshold adjusted */ - Word64 thresh_int = 21475; // 1e-6f in Q32 + Word64 thresh_int = 4295; // 1e-6f in Q32 move64(); /* @@ -4531,11 +4555,11 @@ static Word16 in_tri_fx( I'll just compute the determinant and if it's equal to 0, that means the two vectors are colinear */ - v_sub_fixed( B, A, tmpDot1, 2, 0 ); - v_sub_fixed( C, A, tmpDot2, 2, 0 ); + v_sub_fixed( B, A, tmpDot1, 2, 0 ); // tmpDot1 q22 + v_sub_fixed( C, A, tmpDot2, 2, 0 ); // tmpDot 2q22 /* Verification of the non-colinearity : Q22 * Q22 = Q13 */ - invFactor = L_sub( Mpy_32_32( tmpDot1[0], tmpDot2[1] ), Mpy_32_32( tmpDot1[1], tmpDot2[0] ) ); + invFactor = L_sub( Mpy_32_32( tmpDot1[0], tmpDot2[1] ), Mpy_32_32( tmpDot1[1], tmpDot2[0] ) ); /*q22+q22-q31->q13*/ IF( invFactor == 0 ) { @@ -4543,20 +4567,20 @@ static Word16 in_tri_fx( } /* invFactor = 1.f / invFactor; */ - tmp16 = BASOP_Util_Divide3232_Scale( ONE_IN_Q13, invFactor, &tmp_e ); - invFactor = L_shl_sat( tmp16, add( Q16, tmp_e ) ); /* Q31 */ + tmp16 = BASOP_Util_Divide3232_Scale( ONE_IN_Q13, invFactor, &tmp_e ); /*15-tmp_e*/ + invFactor = L_shl_sat( tmp16, add( Q16, tmp_e ) ); /* Q31 */ Word16 invFactor_exp = norm_l( invFactor ); - invFactor = L_shl( invFactor, invFactor_exp ); + invFactor = L_shl( invFactor, invFactor_exp ); // 31+invFactor_exp // Q22 = Q22 * Q31 - matInv[0][0] = Mpy_32_32( tmpDot2[1], invFactor ); + matInv[0][0] = Mpy_32_32( tmpDot2[1], invFactor ); // q=22+invFactor_exp move32(); - matInv[0][1] = Mpy_32_32( L_negate( tmpDot2[0] ), invFactor ); + matInv[0][1] = Mpy_32_32( L_negate( tmpDot2[0] ), invFactor ); // q=22+invFactor_exp move32(); - matInv[1][0] = Mpy_32_32( L_negate( tmpDot1[1] ), invFactor ); + matInv[1][0] = Mpy_32_32( L_negate( tmpDot1[1] ), invFactor ); // q=22+invFactor_exp move32(); - matInv[1][1] = Mpy_32_32( tmpDot1[0], invFactor ); + matInv[1][1] = Mpy_32_32( tmpDot1[0], invFactor ); // q=22+invFactor_exp move32(); /* Computing S (Q13 + matInv_exp_final[i] + P_minus_A_exp_final + invFactor_exp - 1 ) = @@ -4588,35 +4612,37 @@ static Word16 in_tri_fx( P_minus_A_exp_final = s_min( P_minus_A_exp[0], P_minus_A_exp[1] ); S[0] = L_add( L_shr( Mpy_32_32( L_shl( matInv[0][0], matInv_exp_final[0] ), L_shl( P_minus_A[0], P_minus_A_exp_final ) ), Q1 ), - L_shr( Mpy_32_32( L_shl( matInv[0][1], matInv_exp_final[0] ), L_shl( P_minus_A[1], P_minus_A_exp_final ) ), Q1 ) ); + L_shr( Mpy_32_32( L_shl( matInv[0][1], matInv_exp_final[0] ), L_shl( P_minus_A[1], P_minus_A_exp_final ) ), Q1 ) ); //(22+invFactor_exp+matInv_exp_final[0]+22+P_minus_A_exp_final-1)-31=>12+invFactor_exp+matInv_exp_final[0]+P_minus_A_exp_final move64(); S[1] = L_add( L_shr( Mpy_32_32( L_shl( matInv[1][0], matInv_exp_final[1] ), L_shl( P_minus_A[0], P_minus_A_exp_final ) ), Q1 ), - L_shr( Mpy_32_32( L_shl( matInv[1][1], matInv_exp_final[1] ), L_shl( P_minus_A[1], P_minus_A_exp_final ) ), Q1 ) ); + L_shr( Mpy_32_32( L_shl( matInv[1][1], matInv_exp_final[1] ), L_shl( P_minus_A[1], P_minus_A_exp_final ) ), Q1 ) ); //(22+invFactor_exp+matInv_exp_final[1]+22+P_minus_A_exp_final-1)-31=>12+invFactor_exp+matInv_exp_final[0]+P_minus_A_exp_final move64(); /* Checking if we are in the triangle; For the theory, check Christian Borss article, section 3.2 */ // Q32 S IF( sub( sub( sub( Q20, matInv_exp_final[0] ), P_minus_A_exp_final ), invFactor_exp ) < 0 ) { - S[0] = W_shr( S[0], sub( add( add( matInv_exp_final[0], P_minus_A_exp_final ), invFactor_exp ), Q20 ) ); + S[0] = W_shr( S[0], sub( add( add( matInv_exp_final[0], P_minus_A_exp_final ), invFactor_exp ), Q20 ) ); // q32 move64(); } ELSE { - S[0] = W_shl( S[0], sub( sub( sub( Q20, matInv_exp_final[0] ), P_minus_A_exp_final ), invFactor_exp ) ); + S[0] = W_shl( S[0], sub( sub( sub( Q20, matInv_exp_final[0] ), P_minus_A_exp_final ), invFactor_exp ) ); // q32 move64(); } IF( sub( sub( sub( Q20, matInv_exp_final[1] ), P_minus_A_exp_final ), invFactor_exp ) < 0 ) { - S[1] = W_shr( S[1], sub( add( add( matInv_exp_final[1], P_minus_A_exp_final ), invFactor_exp ), Q20 ) ); + S[1] = W_shr( S[1], sub( add( add( matInv_exp_final[1], P_minus_A_exp_final ), invFactor_exp ), Q20 ) ); // q32 move64(); } ELSE { - S[1] = W_shl( S[1], sub( sub( sub( Q20, matInv_exp_final[1] ), P_minus_A_exp_final ), invFactor_exp ) ); + S[1] = W_shl( S[1], sub( sub( sub( Q20, matInv_exp_final[1] ), P_minus_A_exp_final ), invFactor_exp ) ); // q32 move64(); } + test(); + test(); IF( LT_64( S[0], -thresh_int ) || LT_64( S[1], -thresh_int ) || GT_64( W_add( S[0], S[1] ), W_add( W_shl( 1, 32 ), thresh_int ) ) ) { return 0; -- GitLab From 27a86009296d3afa75575bb1779f09da01d316cb Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Fri, 25 Oct 2024 12:10:21 +0530 Subject: [PATCH 042/128] Fix for 3GPP issue 950: High MLD for ParamMC 5.1 at 48/64/80kbps or 7.1+4 at 128kbps --- lib_dec/ivas_jbm_dec.c | 11 ++++++----- lib_dec/ivas_mc_param_dec.c | 17 +++++++++++++++++ 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/lib_dec/ivas_jbm_dec.c b/lib_dec/ivas_jbm_dec.c index dcbd10839..106affd08 100644 --- a/lib_dec/ivas_jbm_dec.c +++ b/lib_dec/ivas_jbm_dec.c @@ -3302,24 +3302,25 @@ ivas_error ivas_jbm_dec_render_fx( move16(); } } - Word16 tempp; FOR( Word16 param_band_idx = 0; param_band_idx < st_ivas->hParamMC->num_param_bands_synth; param_band_idx++ ) { - tempp = getScaleFactor32( st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_fx[param_band_idx], imult1616( nchan_transport, nchan_out_cov ) ); - scale_sig32( st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_fx[param_band_idx], imult1616( nchan_transport, nchan_out_cov ), tempp ); // Q(31-(st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_exp[param_band_idx]- tempp)) + tempp = getScaleFactor32( st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_fx[param_band_idx], st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_len ); + scale_sig32( st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_fx[param_band_idx], st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_len, tempp ); // Q(31-(st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_exp[param_band_idx]- tempp)) st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_exp[param_band_idx] = sub( st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_exp[param_band_idx], tempp ); move16(); IF( LT_16( st_ivas->hParamMC->band_grouping[param_band_idx], st_ivas->hParamMC->h_output_synthesis_params.max_band_decorr ) ) { - tempp = getScaleFactor32( st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_fx[param_band_idx], imult1616( nchan_transport, nchan_out_cov ) ); - scale_sig32( st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_fx[param_band_idx], imult1616( nchan_transport, nchan_out_cov ), tempp ); // Q(31- (st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_exp[param_band_idx] - tempp)) + tempp = getScaleFactor32( st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_fx[param_band_idx], st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_len ); + scale_sig32( st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_fx[param_band_idx], st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_len, tempp ); // Q(31- (st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_exp[param_band_idx] - tempp)) st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_exp[param_band_idx] = sub( st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_exp[param_band_idx], tempp ); move16(); } } + ivas_param_mc_dec_render_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, p_output_fx, channel_active_fx ); + FOR( int ch = 0; ch < nchan_out_cldfb; ch++ ) { IF( st_ivas->cldfbSynDec[ch] ) diff --git a/lib_dec/ivas_mc_param_dec.c b/lib_dec/ivas_mc_param_dec.c index abf30acad..b9e9137a1 100644 --- a/lib_dec/ivas_mc_param_dec.c +++ b/lib_dec/ivas_mc_param_dec.c @@ -5392,6 +5392,7 @@ static void ivas_param_mc_get_mixing_matrices_fx( set_zero_fx( Cproto_fx, MAX_CICP_CHANNELS * MAX_CICP_CHANNELS ); set_zero_fx( mat_mult_buffer1_fx, MAX_CICP_CHANNELS * MAX_CICP_CHANNELS ); set_zero_fx( proto_matrix_noLFE_fx, PARAM_MC_MAX_TRANSPORT_CHANS * MAX_CICP_CHANNELS ); + set_zero_fx( mixing_matrix_local_fx, MAX_CICP_CHANNELS * PARAM_MC_MAX_TRANSPORT_CHANS ); #ifdef MSAN_FIX set_zero_fx( mixing_matrix_res_local_fx, MAX_CICP_CHANNELS * MAX_CICP_CHANNELS ); #endif @@ -5608,6 +5609,22 @@ static void ivas_param_mc_get_mixing_matrices_fx( /* Compute mixing matrix FOR residual */ computeMixingMatricesResidual_fx( nY_band, Cproto_diag_fx, Cproto_diag_e, Cr_fx, Cr_e, PARAM_MC_REG_SX_FX, 0, PARAM_MC_REG_GHAT_FX, 0, mixing_matrix_res_local_fx, &mixing_matrix_res_local_e ); + IF( NE_16( mixing_matrix_res_local_e, mixing_matrix_local_e ) ) + { + tmp = getScaleFactor32( mixing_matrix_local_fx, MAX_CICP_CHANNELS * PARAM_MC_MAX_TRANSPORT_CHANS ); + scale_sig32( mixing_matrix_local_fx, MAX_CICP_CHANNELS * PARAM_MC_MAX_TRANSPORT_CHANS, tmp ); + mixing_matrix_local_e = sub( mixing_matrix_local_e, tmp ); + + tmp = getScaleFactor32( mixing_matrix_res_local_fx, MAX_CICP_CHANNELS * MAX_CICP_CHANNELS ); + scale_sig32( mixing_matrix_res_local_fx, MAX_CICP_CHANNELS * MAX_CICP_CHANNELS, tmp ); + mixing_matrix_res_local_e = sub( mixing_matrix_res_local_e, tmp ); + + scale_sig32( mixing_matrix_local_fx, MAX_CICP_CHANNELS * PARAM_MC_MAX_TRANSPORT_CHANS, sub( mixing_matrix_local_e, s_max( mixing_matrix_local_e, mixing_matrix_res_local_e ) ) ); + scale_sig32( mixing_matrix_res_local_fx, MAX_CICP_CHANNELS * MAX_CICP_CHANNELS, sub( mixing_matrix_res_local_e, s_max( mixing_matrix_local_e, mixing_matrix_res_local_e ) ) ); + + mixing_matrix_res_local_e = mixing_matrix_local_e = s_max( mixing_matrix_local_e, mixing_matrix_res_local_e ); + move16(); + } IF( remove_lfe ) { set_zero_fx( mixing_matrix_res_fx[param_band_idx], imult1616( nY_cov, nY_cov ) ); -- GitLab From 0fe7c6b52e345d3e40175049458ad8951d684abd Mon Sep 17 00:00:00 2001 From: Archit Tamarapu Date: Fri, 25 Oct 2024 11:04:09 +0200 Subject: [PATCH 043/128] [fix] change loop variables to Word32 --- lib_dec/lib_dec_fx.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib_dec/lib_dec_fx.c b/lib_dec/lib_dec_fx.c index 05fd52bfb..9d1fb571c 100644 --- a/lib_dec/lib_dec_fx.c +++ b/lib_dec/lib_dec_fx.c @@ -1090,7 +1090,7 @@ ivas_error IVAS_DEC_GetSamples( Word16 tmp_apaExecBuffer[APA_BUF]; IF( EQ_16( (Word16) hIvasDec->mode, IVAS_DEC_MODE_EVS ) ) { - FOR( Word16 i = 0; i < APA_BUF_PER_CHANNEL * nTransportChannels; ++i ) + FOR( Word32 i = 0; i < APA_BUF_PER_CHANNEL * nTransportChannels; ++i ) { tmp_apaExecBuffer[i] = extract_l( L_shr( hIvasDec->apaExecBuffer_fx[i], Q11 ) ); // Q0 } @@ -1098,14 +1098,14 @@ ivas_error IVAS_DEC_GetSamples( { return IVAS_ERR_UNKNOWN; } - FOR( Word16 i = 0; i < APA_BUF_PER_CHANNEL * nTransportChannels; ++i ) + FOR( Word32 i = 0; i < APA_BUF_PER_CHANNEL * nTransportChannels; ++i ) { hIvasDec->apaExecBuffer_fx[i] = L_shl( tmp_apaExecBuffer[i], Q11 ); // Q11 } } ELSE { - FOR( Word16 i = 0; i < APA_BUF_PER_CHANNEL * nTransportChannels; ++i ) + FOR( Word32 i = 0; i < APA_BUF_PER_CHANNEL * nTransportChannels; ++i ) { tmp_apaExecBuffer[i] = extract_l( L_shr( hIvasDec->apaExecBuffer_fx[i], Q12 ) ); // Q(-1) } @@ -1114,7 +1114,7 @@ ivas_error IVAS_DEC_GetSamples( return IVAS_ERR_UNKNOWN; } - FOR( Word16 i = 0; i < APA_BUF_PER_CHANNEL * nTransportChannels; ++i ) + FOR( Word32 i = 0; i < APA_BUF_PER_CHANNEL * nTransportChannels; ++i ) { hIvasDec->apaExecBuffer_fx[i] = L_shl( tmp_apaExecBuffer[i], Q12 ); // Q11 } -- GitLab From 0c144928ad68fbddb66af131c37879eb46a02b85 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Fri, 25 Oct 2024 16:06:09 +0530 Subject: [PATCH 044/128] Fix for 3GPP issue 957: Assertion error in BWE of SCE decoding in OMASA [x] Adding saturation as suggested by PC group --- lib_com/swb_bwe_com_fx.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib_com/swb_bwe_com_fx.c b/lib_com/swb_bwe_com_fx.c index 0025812db..d56f1b784 100644 --- a/lib_com/swb_bwe_com_fx.c +++ b/lib_com/swb_bwe_com_fx.c @@ -3005,7 +3005,8 @@ void hq_generic_decoding_fx( { FOR( tmp3_fx = 5120; tmp3_fx > 1024; tmp3_fx -= 512 ) { - L_tmp1 = L_shl( Mult_32_16( *pit1_fx, tmp3_fx ), 5 ); /*15 + 5 + 10 -15 */ + /* Adding saturation suggested as fix for issue #957 */ + L_tmp1 = L_shl_sat( Mult_32_16( *pit1_fx, tmp3_fx ), 5 ); /*15 + 5 + 10 -15 */ *pit1_fx-- = L_tmp1; move32(); } -- GitLab From 7a52e2c2e6598e545a28b0538f1af040a72a6a65 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Mon, 28 Oct 2024 08:33:15 +0530 Subject: [PATCH 045/128] Encoder code cleanup, Q-info doc for decoder and renderer --- lib_dec/jbm_jb4_circularbuffer.c | 4 +- lib_dec/jbm_jb4_inputbuffer.c | 13 +- lib_dec/jbm_jb4sb.c | 53 +- lib_dec/jbm_pcmdsp_apa.c | 175 ++-- lib_dec/jbm_pcmdsp_apa.h | 8 +- lib_dec/jbm_pcmdsp_similarityestimation.c | 30 +- lib_dec/jbm_pcmdsp_similarityestimation.h | 17 +- lib_dec/jbm_pcmdsp_window.c | 4 +- lib_enc/analy_sp_fx.c | 2 + lib_enc/ivas_cpe_enc.c | 6 +- lib_enc/ivas_front_vad.c | 4 +- lib_enc/nois_est_fx.c | 3 +- lib_enc/vad_fx.c | 4 +- lib_rend/ivas_dirac_rend.c | 1054 +++++++++++---------- lib_rend/ivas_prot_rend.h | 106 +-- 15 files changed, 769 insertions(+), 714 deletions(-) diff --git a/lib_dec/jbm_jb4_circularbuffer.c b/lib_dec/jbm_jb4_circularbuffer.c index bf3cbb71b..6bff530be 100644 --- a/lib_dec/jbm_jb4_circularbuffer.c +++ b/lib_dec/jbm_jb4_circularbuffer.c @@ -207,7 +207,7 @@ JB4_CIRCULARBUFFER_ELEMENT JB4_CIRCULARBUFFER_Back( { JB4_CIRCULARBUFFER_ELEMENT ret; - IF( NE_32( h->writePos, 0U ) ) + IF( h->writePos != 0U ) { ret = h->data[h->writePos - 1]; move32(); @@ -408,7 +408,7 @@ void JB4_CIRCULARBUFFER_MinAndPercentile( /* init output variables */ minEle = h->data[h->readPos]; - + move32(); /* To calculate the percentile, a number of elements with the highest values are collected in maxElements in * ascending sorted order. This array has a size of nElementsToIgnore plus one. This additional element is the * lowest of all maxElements, and is called the percentile of all elements. */ diff --git a/lib_dec/jbm_jb4_inputbuffer.c b/lib_dec/jbm_jb4_inputbuffer.c index 25d02da35..f876c11c0 100644 --- a/lib_dec/jbm_jb4_inputbuffer.c +++ b/lib_dec/jbm_jb4_inputbuffer.c @@ -139,7 +139,6 @@ ivas_error JB4_INPUTBUFFER_Init( h->readPos = 0; move16(); h->compareFunction = compareFunction; - move16(); return IVAS_ERR_OK; } @@ -213,8 +212,8 @@ Word16 JB4_INPUTBUFFER_Enque( { IF( replace != 0 ) { - *replacedElement = h->data[L_add( h->readPos, middle ) % h->capacity]; - h->data[L_add( h->readPos, middle ) % h->capacity] = element; + *replacedElement = h->data[( h->readPos + middle ) % h->capacity]; + h->data[( h->readPos + middle ) % h->capacity] = element; return 0; } return 1; @@ -235,7 +234,7 @@ Word16 JB4_INPUTBUFFER_Enque( canMoveRight = (UWord16) LT_32( insertPos, h->writePos ); canMoveLeft = (UWord16) GT_32( insertPos, h->writePos ); } - + test(); assert( canMoveRight != 0 || canMoveLeft != 0 ); IF( canMoveRight ) @@ -260,7 +259,7 @@ Word16 JB4_INPUTBUFFER_Enque( /* move lower elements to the left and insert before insertPos */ FOR( j = 0; j < low; j++ ) { - h->data[L_add( L_sub( h->readPos, 1 ), j )] = h->data[L_add( h->readPos, j )]; + h->data[( h->readPos - 1 ) + j] = h->data[h->readPos + j]; } h->data[insertPos - 1] = element; @@ -337,12 +336,12 @@ JB4_INPUTBUFFER_ELEMENT JB4_INPUTBUFFER_Element( /* return h->data[(h->readPos + index) % h->capacity] without error handling */ IF( LT_32( L_add( h->readPos, index ), h->capacity ) ) { - ret = h->data[L_add( h->readPos, index )]; + ret = h->data[( h->readPos + index )]; } ELSE { /* wrap around */ - ret = h->data[L_sub( L_add( h->readPos, index ), h->capacity )]; + ret = h->data[( ( h->readPos + index ) - h->capacity )]; } return ret; diff --git a/lib_dec/jbm_jb4sb.c b/lib_dec/jbm_jb4sb.c index 44d6abe4b..36fef8f00 100644 --- a/lib_dec/jbm_jb4sb.c +++ b/lib_dec/jbm_jb4sb.c @@ -183,7 +183,7 @@ struct JB4 UWord32 FecOffWin[10]; UWord32 optimum_offset; - Word32 netLossRate_fx; + Word32 netLossRate_fx; // Q15 Word32 nPartialCopiesUsed; Word32 last_nLost; Word32 last_ntot; @@ -479,22 +479,22 @@ Word16 JB4_PushDataUnit( { IF( dataUnit->partialCopyOffset == 0 ) { - if ( h->rfOffset2Active > 0 ) + IF( h->rfOffset2Active > 0 ) { h->rfOffset2Active = sub( h->rfOffset2Active, 1 ); move16(); } - if ( h->rfOffset3Active > 0 ) + IF( h->rfOffset3Active > 0 ) { h->rfOffset3Active = sub( h->rfOffset3Active, 1 ); move16(); } - if ( h->rfOffset5Active > 0 ) + IF( h->rfOffset5Active > 0 ) { h->rfOffset5Active = sub( h->rfOffset5Active, 1 ); move16(); } - if ( h->rfOffset7Active > 0 ) + IF( h->rfOffset7Active > 0 ) { h->rfOffset7Active = sub( h->rfOffset7Active, 1 ); move16(); @@ -641,13 +641,13 @@ Word16 JB4_getFECoffset( Word16 JB4_FECoffset( JB4_HANDLE h ) { - IF( LT_32( h->netLossRate_fx, 1634 ) ) + IF( LT_32( h->netLossRate_fx, 1634 /*.05f in Q15*/ ) ) { - return (Word16) 0; + return 0; } ELSE { - return (Word16) 1; + return 1; } } @@ -663,7 +663,7 @@ Word16 JB4_PopDataUnit( Word16 ret; assert( sysTime >= h->prevPopSysTime ); - if ( GT_64( sysTime, W_add( h->prevPopSysTime, 20 ) ) ) + IF( GT_64( sysTime, W_add( h->prevPopSysTime, 20 ) ) ) { h->lastPlayoutOffset = L_add( h->lastPlayoutOffset, 20 ); move32(); @@ -780,6 +780,7 @@ static Word16 JB4_adaptPlayout( bool stretchTime; /* reset scale */ + test(); IF( scale == NULL || maxScaling == NULL ) { return -1; @@ -901,13 +902,9 @@ static void JB4_adaptActivePlayout( { IF( convertToLateLoss ) { -#ifndef IVAS_FLOAT_FIXED - JB4_dropFromBuffer( h ); -#else JB4_dropFromBuffer( h ); h->nLostOrStretched = L_add( h->nLostOrStretched, 1 ); move32(); -#endif } ELSE IF( dropEarly ) { @@ -924,8 +921,8 @@ static void JB4_adaptActivePlayout( Word32 temp = BASOP_Util_Divide3232_Scale_cadence( W_extract_l( W_sub( dropRateMax, dropRateMin ) ), W_extract_l( dropGapMax ), &exp ); /* limit gap to [gapMin,gapMax] and calculate current drop rate from gap */ Word64 temp2 = W_mult0_32_32( W_extract_l( JB4_MIN( gap, dropGapMax ) ), temp ); - Word64 temp3 = W_shr( temp2, 31 - exp ); - Word64 diff = W_sub( W_shl( temp3 + 1, 31 - exp ), temp2 ); + Word64 temp3 = W_shr( temp2, sub( 31, exp ) ); + Word64 diff = W_sub( W_shl( W_add( temp3, 1 ), sub( 31, exp ) ), temp2 ); if ( LE_64( diff, 21 ) ) { temp3 = W_add( temp3, 1 ); @@ -1124,7 +1121,7 @@ static Word16 JB4_inspectBufferForDropping( { Word16 temp, exp; temp = BASOP_Util_Divide3232_Scale( JB4_rtpTimeStampDiff( h->nextExpectedTs, firstTs ), (Word32) ( h->frameDuration ), &exp ); - seqNrDiff = L_shl( temp, sub( exp, 15 ) ); + seqNrDiff = L_shl( temp, sub( exp, 15 ) ); // Q0 } ELSE { @@ -1219,7 +1216,7 @@ static Word16 JB4_checkDtxDropping( Word16 temp, exp; temp = BASOP_Util_Divide3232_Scale( JB4_rtpTimeStampDiff( h->nextExpectedTs, firstDu->timeStamp ), (Word32) ( h->frameDuration ), &exp ); - seqNrDiff = L_shl( temp, exp - 15 ); + seqNrDiff = L_shl( temp, sub( exp, 15 ) ); // Q0 if ( seqNrDiff <= 0 ) { /* no not drop first active frame */ @@ -1270,7 +1267,7 @@ static void JB4_estimateShortTermJitter( { duration = (UWord32) W_sub( maxTime, minTime ); maxDuration = (UWord32) W_shl( h->timeScale, 2 ); - WHILE( GT_64( duration, maxDuration ) ) + WHILE( duration > maxDuration ) { JB4_CIRCULARBUFFER_Deque( h->stJitterFifo, &dequedElement ); JB4_CIRCULARBUFFER_Deque( h->stTimeStampFifo, &dequedElement ); @@ -1294,13 +1291,13 @@ static void JB4_estimateShortTermJitter( temp = BASOP_Util_Divide3232_Scale( maxElement, (Word32) h->frameDuration, &exp ); IF( exp < 0 ) { - temp = L_shl( temp, exp ); + temp = L_shl( temp, exp ); // Q31 exp = 0; move16(); } IF( temp != 0 ) { - temp = L_shr( ceil_fixed( temp, 15 - exp ), 15 - exp ); + temp = L_shr( ceil_fixed( temp, sub( 15, exp ) ), sub( 15, exp ) ); // Q31 } h->stJitter = (UWord32) W_mult0_32_32( temp, h->frameDuration ); move32(); @@ -1383,7 +1380,7 @@ static void JB4_popFromBuffer( maxval = h->FecOffWin[i]; move16(); h->optimum_offset = i; - move16(); + move32(); } h->FecOffWin[i] = 0; move32(); @@ -1404,7 +1401,7 @@ static void JB4_popFromBuffer( test(); IF( lost != 0 && total_rec != 0 ) { - h->netLossRate_fx = divide3232( lost, total_rec ); + h->netLossRate_fx = divide3232( lost, total_rec ); // Q15 } ELSE { @@ -1430,7 +1427,7 @@ static void JB4_popFromBuffer( test(); IF( frameoffset > 0 && LT_16( frameoffset, MAXOFFSET ) ) { - h->FecOffWin[frameoffset] = W_extract_l( W_add( h->FecOffWin[frameoffset], 1 ) ); + h->FecOffWin[frameoffset] = (UWord32) ( W_add( h->FecOffWin[frameoffset], 1 ) ); move32(); } } @@ -1503,7 +1500,7 @@ static void JB4_popFromBuffer( test(); IF( !tempDataUnit->partial_frame && !h->lastPoppedWasSilence ) { - frameoffset = extract_l( Mult_32_32( JB4_rtpTimeStampDiff( h->nextExpectedTs, tempDataUnit->timeStamp ), INV_20_Q31 ) ); + frameoffset = extract_l( Mult_32_32( JB4_rtpTimeStampDiff( h->nextExpectedTs, tempDataUnit->timeStamp ), INV_20_Q31 ) ); // Q0 test(); IF( ( frameoffset > 0 ) && LT_16( frameoffset, MAXOFFSET ) ) { @@ -1523,7 +1520,7 @@ static void JB4_popFromBuffer( /* separate concealments since last available pop in lost and stretched */ Word16 exp; nStretched = BASOP_Util_Divide3232_Scale( tsDiff, h->frameDuration, &exp ); - nStretched = (UWord32) W_shr( nStretched, sub( 15, exp ) ); + nStretched = (UWord32) W_shr( nStretched, sub( 15, exp ) ); // Q0 assert( h->nLostOrStretched >= nStretched ); h->nLost = (UWord32) W_add( h->nLost, W_sub( h->nLostOrStretched, nStretched ) ); /* jitter-induced insertion (e.g. buffer underflow) */ @@ -1622,7 +1619,7 @@ static void JB4_dropFromBuffer( /* separate concealments since last available pop in lost and stretched */ Word16 exp; nStretched = BASOP_Util_Divide3232_Scale( tsDiff, (Word32) h->frameDuration, &exp ); - nStretched = (UWord32) W_shr( nStretched, sub( 15, exp ) ); + nStretched = (UWord32) W_shr( nStretched, sub( 15, exp ) ); // Q0 assert( h->nLostOrStretched >= nStretched ); /* convert stretching followed by shrinking to late-loss */ @@ -1636,8 +1633,7 @@ static void JB4_dropFromBuffer( move32(); move32(); move32(); - move32(); - if ( !dataUnit->silenceIndicator ) + IF( !dataUnit->silenceIndicator ) { /* JBM induced removal of a speech frame (intentional frame dropping) */ h->jitterInducedConcealments = (UWord32) W_add( h->jitterInducedConcealments, 1 ); @@ -1752,6 +1748,7 @@ static Word16 JB4_inputBufferCompareFunction( Word16 result; *replaceWithNewElementIfEqual = 0; + move16(); newDataUnit = (JB4_DATAUNIT_HANDLE) newElement; arrayDataUnit = (JB4_DATAUNIT_HANDLE) arrayElement; diff = JB4_rtpTimeStampDiff( arrayDataUnit->timeStamp, newDataUnit->timeStamp ); diff --git a/lib_dec/jbm_pcmdsp_apa.c b/lib_dec/jbm_pcmdsp_apa.c index e5fc42d8d..1ddb7fee6 100644 --- a/lib_dec/jbm_pcmdsp_apa.c +++ b/lib_dec/jbm_pcmdsp_apa.c @@ -218,7 +218,7 @@ void apa_reset( ps->nFramesSinceSetScale = 0; move32(); ps->scale = 100; - move32(); + move16(); ps->p_min = 0; move16(); ps->l_search = 0; @@ -261,7 +261,7 @@ UWord8 apa_reconfigure( move16(); free( ps->buf_out_fx ); - ps->buf_out_fx = (Word16 *) malloc( sizeof( float ) * ps->buf_out_capacity ); + ps->buf_out_fx = (Word16 *) malloc( sizeof( Word16 ) * ps->buf_out_capacity ); IF( !ps->buf_out_fx ) { return 2; @@ -279,24 +279,24 @@ UWord8 apa_reconfigure( /* in the order of a pitch, set to 160 samples at 16 kHz */ /* used for windowing and as the correlation length, i.e., */ /* the size of the template segment. */ - ps->l_seg = (UWord16) imult3216( Mult_32_16( ps->rate, INV_100_Q15 ), (Word16) ps->num_channels ); + ps->l_seg = (UWord16) imult3216( Mult_32_16( ps->rate, INV_100_Q15 ), (Word16) ps->num_channels ); // Q0 move16(); /* set frame size */ /* set to 320 samples at 16 kHz */ - ps->l_frm = (UWord16) imult3216( Mult_32_16( ps->rate, INV_FRAME_PER_SEC_Q15 ), (Word16) ps->num_channels ); + ps->l_frm = (UWord16) imult3216( Mult_32_16( ps->rate, INV_FRAME_PER_SEC_Q15 ), (Word16) ps->num_channels ); // Q0 move16(); /* set minimum pitch */ /* set to 40 samples at 16 kHz */ /* (defines min change in number of samples, i.e., abs(l_in-l_out) >= p_min) */ - ps->p_min = (UWord16) imult3216( Mult_32_16( ps->rate, INV_400_Q15 ), (Word16) ps->num_channels ); + ps->p_min = (UWord16) imult3216( Mult_32_16( ps->rate, INV_400_Q15 ), (Word16) ps->num_channels ); // Q0 move16(); /* set search length */ /* must cover one pitch, set to 200 samples at 16 kHz */ /* (the resulting maximum pitch is then p_min+l_search = 240 samples at 16 kHz) */ - ps->l_search = (UWord16) imult3216( Mult_32_16( ps->rate, INV_80_Q15 ), (Word16) ps->num_channels ); + ps->l_search = (UWord16) imult3216( Mult_32_16( ps->rate, INV_80_Q15 ), (Word16) ps->num_channels ); // Q0 move16(); return 0; @@ -345,36 +345,34 @@ bool apa_set_rate( /* in the order of a pitch, set to 160 samples at 16 kHz */ /* used for windowing and as the correlation length, i.e., */ /* the size of the template segment. */ - ps->l_seg = (UWord16) imult3216( Mult_32_16( ps->rate, INV_100_Q15 ), ps->num_channels ); + ps->l_seg = (UWord16) imult3216( Mult_32_16( ps->rate, INV_100_Q15 ), ps->num_channels ); // Q0 move16(); /* init Hann window */ /* Note: l_win < APA_BUF_PER_CHANNEL is required */ /* Length of Hann window should be independent of * number of channels - same window applied to all channels */ - ps->l_halfwin = (UWord16) Mult_32_16( ps->rate, INV_100_Q15 ); - move16(); + ps->l_halfwin = (UWord16) Mult_32_16( ps->rate, INV_100_Q15 ); // Q0 move16(); /* set frame size */ /* set to 320 samples at 16 kHz */ - ps->l_frm = (UWord16) imult3216( ( Mult_32_16( ps->rate, INV_FRAME_PER_SEC_Q15 ) ), ps->num_channels ); + ps->l_frm = (UWord16) imult3216( ( Mult_32_16( ps->rate, INV_FRAME_PER_SEC_Q15 ) ), ps->num_channels ); // Q0 move16(); /* set minimum pitch */ /* set to 40 samples at 16 kHz */ /* (defines min change in number of samples, i.e., abs(l_in-l_out) >= p_min) */ - ps->p_min = (UWord16) imult3216( ( Mult_32_16( ps->rate, INV_400_Q15 ) ), ps->num_channels ); + ps->p_min = (UWord16) imult3216( ( Mult_32_16( ps->rate, INV_400_Q15 ) ), ps->num_channels ); // Q0 move16(); /* set search length */ /* must cover one pitch, set to 200 samples at 16 kHz */ /* (the resulting maximum pitch is then p_min+l_search = 240 samples at 16 kHz) */ - ps->l_search = (UWord16) imult3216( Mult_32_16( ps->rate, INV_80_Q15 ), ps->num_channels ); + ps->l_search = (UWord16) imult3216( Mult_32_16( ps->rate, INV_80_Q15 ), ps->num_channels ); // Q0 move16(); ps->win_fx = pcmdsp_window_hann_640; - move16(); ps->l_halfwin = 320; move16(); ps->win_incrementor = 1; @@ -382,14 +380,12 @@ bool apa_set_rate( IF( EQ_32( ps->rate, 48000 ) ) { ps->win_fx = pcmdsp_window_hann_960; - move16(); ps->l_halfwin = 480; move16(); } IF( EQ_32( ps->rate, 24000 ) ) { ps->win_fx = pcmdsp_window_hann_960; - move16(); ps->l_halfwin = 480; move16(); ps->win_incrementor = 2; @@ -533,12 +529,12 @@ bool apa_set_evs_compat_mode( */ bool apa_set_quality( apa_state_t *ps, - Word32 quality, + Word32 quality, // Q16 UWord16 qualityred, UWord16 qualityrise ) { assert( ps != NULL ); - assert( -131072 <= quality && quality <= 203161 ); + assert( -131072 /*-2.0f in Q16*/ <= quality && quality <= 203161 /*3.1f in Q16*/ ); assert( qualityred > 0 && qualityred <= 20 ); assert( qualityrise > 0 && qualityrise <= 20 ); @@ -670,10 +666,10 @@ bool apa_exit( */ UWord8 apa_exec_fx( apa_state_t *ps, /* i/o: state struct */ - const Word16 a_in[], /* i : input samples */ + const Word16 a_in[], /* i : input samples Q0 */ UWord16 l_in, /* i : number of input samples */ UWord16 maxScaling, /* i : allowed number of inserted/removed samples */ - Word16 a_out[], /* o : output samples */ + Word16 a_out[], /* o : output samples Q0*/ UWord16 *l_out /* o : number of output samples */ ) { @@ -789,7 +785,7 @@ UWord8 apa_exec_fx( IF( NE_32( l_frm_out, ps->l_frm ) ) { test(); - IF( NE_32( maxScaling, 0 ) && + IF( maxScaling != 0 && GT_32( abs_s( extract_l( L_sub( ps->l_frm, l_frm_out ) ) ), maxScaling ) ) { /* maxScaling exceeded -> discard scaled frame */ @@ -875,10 +871,10 @@ UWord8 apa_exec_fx( UWord8 apa_exec_ivas_fx( apa_state_t *ps, /* i/o: state struct */ - const Word16 a_in[], /* i : input samples */ + const Word16 a_in[], /* i : input samples Q(-1) */ UWord16 l_in, /* i : number of input samples */ UWord16 maxScaling, /* i : allowed number of inserted/removed samples */ - Word16 a_out[], /* o : output samples */ + Word16 a_out[], /* o : output samples Q(-1) */ UWord16 *l_out /* o : number of output samples */ ) { @@ -921,8 +917,6 @@ UWord8 apa_exec_ivas_fx( } /* get target length */ - test(); - test(); IF( GT_32( ps->scale, 100 ) ) { // expScaling = (int32_t) ( ( ps->l_frm * ( ps->scale - 100.0f ) / 100.0f ) * ( ps->nFramesSinceSetScale + 1 ) + 0.5f ); @@ -990,7 +984,7 @@ UWord8 apa_exec_ivas_fx( IF( NE_32( l_frm_out, ps->l_frm ) ) { test(); - IF( NE_32( maxScaling, 0 ) && + IF( ( maxScaling != 0 ) && GT_32( abs_s( extract_l( L_sub( ps->l_frm, l_frm_out ) ) ), maxScaling ) ) { /* maxScaling exceeded -> discard scaled frame */ @@ -1109,8 +1103,9 @@ static void get_scaling_quality_fx( const apa_state_t *ps, Word16 offset, Word16 corr_len, Word16 pitch, - Word16 *energydBQ8, - Word32 *qualityQ16 ) + Word16 *energydBQ8, // Q8 + Word32 *qualityQ16 // Q16 +) { Word32 energy, maxEnergy; Word32 qualityOfMaxEnergy; /* we measure the quality for all channels and select the one with highest energy */ @@ -1125,8 +1120,10 @@ static void get_scaling_quality_fx( const apa_state_t *ps, Word16 i; - maxEnergy = L_deposit_l( 0 ); - qualityOfMaxEnergy = L_deposit_l( 0 ); + maxEnergy = 0; + qualityOfMaxEnergy = 0; + move32(); + move32(); FOR( i = 0; i < ps->num_channels; i++ ) { @@ -1177,6 +1174,7 @@ static void get_scaling_quality_fx( const apa_state_t *ps, *qualityQ16 = L_shr( L_mac0( L_mult0( half_pitch_cn, three_halves_pitch_cn ), pitch_cn, double_pitch_cn ), 14 ); + move32(); BASOP_SATURATE_WARNING_OFF_EVS energy = L_add( L_add( L_add( pitch_energy, half_pitch_energy ), three_halves_pitch_energy ), double_pitch_energy ); BASOP_SATURATE_WARNING_ON_EVS @@ -1184,6 +1182,7 @@ static void get_scaling_quality_fx( const apa_state_t *ps, ELSE { *qualityQ16 = L_shl( L_deposit_l( pitch_cn ), 1 ); /* value is negative, thus pass it */ + move32(); energy = L_add( pitch_energy, 0 ); } @@ -1231,9 +1230,9 @@ Word16 apa_getQualityIncreaseForLowEnergy_fx( Word16 energydBQ8 ) { Word16 qualIncreaseMinEnergy, qualIncreaseMaxEnergy, qualIncForLowEnergy; /* Q8 */ - qualIncreaseMinEnergy = -65 * ( 1 << 8 ); + qualIncreaseMinEnergy = -65 * ( 1 << 8 ); // Q8 move16(); - qualIncreaseMaxEnergy = -40 * ( 1 << 8 ); + qualIncreaseMaxEnergy = -40 * ( 1 << 8 ); // Q8 move16(); qualIncForLowEnergy = 0; move16(); @@ -1370,7 +1369,7 @@ static Word8 logarithmic_search_fx( const apa_state_t *ps, inlen = add( sub( s_start_old, s_start ), s_len_old ); } } - WHILE( GT_16( css, 2 ) ); + WHILE( ( css > 2 ) ); return 0; } @@ -1422,8 +1421,8 @@ static Word16 find_synch_fx( apa_state_t *ps, Word16 fixed_pos, Word16 corr_len, Word16 offset, - Word16 *energydBQ8, - Word32 *qualityQ16, + Word16 *energydBQ8, // Q8 + Word32 *qualityQ16, // Q16 Word16 *synch_pos ) { assert( ( corr_len - 1 + s_start + s_len - 1 + offset ) < l_in ); @@ -1446,7 +1445,7 @@ static Word16 find_synch_fx( apa_state_t *ps, /* assert synch_pos is cleanly divisible by number of channels */ assert( *synch_pos % ps->num_channels == 0 ); - *qualityQ16 = L_deposit_l( 0 ); + *qualityQ16 = 0; move32(); get_scaling_quality_fx( ps, in, l_in, offset, corr_len, abs_s( sub( *synch_pos, fixed_pos ) ), energydBQ8, qualityQ16 ); @@ -1480,8 +1479,8 @@ static Word16 find_synch_fx( apa_state_t *ps, */ static bool copy_frm_fx( apa_state_t *ps, - const Word16 frm_in_fx[], - Word16 frm_out_fx[], + const Word16 frm_in_fx[], // Qx + Word16 frm_out_fx[], // Qx UWord16 *l_frm_out ) { UWord16 i; @@ -1530,9 +1529,9 @@ static bool copy_frm_fx( */ static bool shrink_frm_fx( apa_state_t *ps, - const Word16 frm_in_fx[], + const Word16 frm_in_fx[], // Qx UWord16 maxScaling, - Word16 frm_out_fx[], + Word16 frm_out_fx[], // Qx UWord16 *l_frm_out ) { bool findSynchResult = 0; @@ -1555,7 +1554,11 @@ static bool shrink_frm_fx( frm_in_fx += l_frm; /* set search range */ - s_start = ( ps->p_min / ps->num_channels ) * ps->num_channels; + // s_start = ( ps->p_min / ps->num_channels ) * ps->num_channels; + Word16 tmp, tmp_e; + tmp = BASOP_Util_Divide3232_Scale( ps->p_min, ps->num_channels, &tmp_e ); + tmp = shr( tmp, sub( 15, tmp_e ) ); + s_start = i_mult( tmp, extract_l( ps->num_channels ) ); s_end = add( s_start, extract_l( ps->l_search ) ); IF( GE_32( L_add( s_end, l_seg ), l_frm ) ) { @@ -1566,9 +1569,9 @@ static bool shrink_frm_fx( IF( isSilence_fx( frm_in_fx, l_seg, 10 ) ) { /* maximum scaling */ - energy_fx = -65 * ( 1 << 8 ); + energy_fx = -65 * ( 1 << 8 ); // Q8 move16(); - quality_fx = 5 << Q16; + quality_fx = 5 << Q16; // Q16 move32(); IF( ps->evs_compat_mode == false ) { @@ -1604,7 +1607,7 @@ static bool shrink_frm_fx( { /* find synch */ scaleSignal16( frm_in_fx, ps->frmInScaled, l_frm, ps->signalScaleForCorrelation ); - findSynchResult = find_synch_fx( ps, ps->frmInScaled, l_frm, s_start, (UWord16) ( s_end - s_start ), 0, l_seg, 0, &energy_fx, &quality_fx, &xtract ); + findSynchResult = find_synch_fx( ps, ps->frmInScaled, l_frm, s_start, (UWord16) ( sub( s_end, s_start ) ), 0, l_seg, 0, &energy_fx, &quality_fx, &xtract ); } /* assert synch_pos is cleanly divisible by number of channels */ @@ -1714,8 +1717,8 @@ static bool shrink_frm_fx( */ static bool extend_frm_fx( apa_state_t *ps, - const Word16 frm_in_fx[], - Word16 frm_out_fx[], + const Word16 frm_in_fx[], // Qx + Word16 frm_out_fx[], // Qx UWord16 *l_frm_out ) { bool findSynchResult = 0; @@ -1727,18 +1730,25 @@ static bool extend_frm_fx( UWord16 over[MAXN + 2]; Word16 l_rem; Word16 s_start = 0; + move16(); Word16 energy_fx; Word32 quality_fx = 0; + move32(); UWord16 l_frm, l_seg; const Word16 *fadeOut_fx, *fadeIn_fx; Word16 *out_fx; l_frm = ps->l_frm; l_seg = ps->l_seg; - + move16(); + move16(); /* number of segments/iterations */ l_frm_out_target = (UWord16) ( L_add( l_frm, L_shr( l_frm, 1 ) ) ); - N = ( l_frm_out_target / l_seg ) - 1; + //(l_frm_out_target/l_seg -1 ) + Word16 tmp, tmp_e; + tmp = BASOP_Util_Divide3232_Scale( l_frm_out_target, l_seg, &tmp_e ); + tmp = shr( tmp, sub( 15, tmp_e ) ); + N = sub( ( tmp ), 1 ); if ( LT_16( N, 1 ) ) { N = 1; @@ -1752,21 +1762,23 @@ static bool extend_frm_fx( /* s[n] are given relative to 2nd frame and point to the start of */ /* the search region. The first segment (n=1) will not be moved. */ /* Hence, the iterations will start with n=2. */ - s_min = -( ps->l_search ) - ( ps->p_min ); + s_min = extract_l( L_negate( L_add( ps->l_search, ps->p_min ) ) ); /* (make sure not to exceed array dimension) */ - if ( l_frm + s_min < 0 ) + IF( L_add( l_frm, s_min ) < 0 ) { - s_min = -( l_frm ); + s_min = extract_l( L_negate( l_frm ) ); } - s_max = l_frm - 2 * l_seg - ps->l_search; + s_max = extract_l( L_sub( L_sub( l_frm, L_shl( l_seg, 1 ) ), ps->l_search ) ); if ( s_max < s_min ) { N = 1; + move16(); } /* for just one segment start at s_min */ if ( N == 1 ) { s[2] = s_min; + move16(); } /* else, spread linear in between s_min and s_max */ /* (including s_min and s_max) */ @@ -1774,7 +1786,14 @@ static bool extend_frm_fx( { FOR( n = 2; n <= ( N + 1 ); n++ ) { - s[n] = s_min + ( ( s_max - s_min ) * ( n - 2 ) ) / ( N - 1 ); + // s[n] = s_min + ( ( s_max - s_min ) * ( n - 2 ) ) / ( N - 1 ); + Word16 tmp2, tmp2_e; + tmp2 = sub( s_max, s_min ); + tmp2 = i_mult( tmp2, extract_l( L_sub( n, 2 ) ) ); + tmp2 = BASOP_Util_Divide1616_Scale( tmp2, sub( N, 1 ), &tmp2_e ); + tmp2 = shr( tmp2, sub( 15, tmp2_e ) ); + s[n] = add( s_min, tmp2 ); + move16(); } } @@ -1782,34 +1801,39 @@ static bool extend_frm_fx( * Planning Phase */ - xtract[1] = -( l_seg ); /* make sync_start=0 in 1st iteration */ + xtract[1] = extract_l( L_negate( l_seg ) ); /* make sync_start=0 in 1st iteration */ + move16(); n = 2; - + move16(); /* define synch segment (to be correlated with search region) */ - sync_start = xtract[n - 1] + l_seg; + sync_start = extract_l( L_add( xtract[n - 1], l_seg ) ); over[n] = 1; /* will be reset if overlap is not required */ + move16(); /* check end of search region: should be at least p_min */ /* samples on the left of synch_start */ - IF( ( s[n] + ps->l_search ) < ( sync_start - ( ps->p_min ) ) ) + IF( LT_32( L_add( s[n], ps->l_search ), L_sub( sync_start, ( ps->p_min ) ) ) ) { s_start = s[n]; - s_end = s_start + ps->l_search; + move16(); + s_end = extract_l( L_add( s_start, ps->l_search ) ); } ELSE { /* shrink search region to enforce minimum shift */ - s_end = sync_start - ( ps->p_min ); - IF( s[n] + ps->l_search < sync_start ) + s_end = extract_l( L_sub( sync_start, ( ps->p_min ) ) ); + IF( LT_16( extract_l( L_add( s[n], ps->l_search ) ), sync_start ) ) { s_start = s[n]; /* just do it with normal start position */ + move16(); } - ELSE IF( n == ( N + 1 ) ) /* move search region left for last segment */ + ELSE IF( EQ_32( n, L_add( N, 1 ) ) ) /* move search region left for last segment */ { - s_start = s_end - ( ps->l_search - ps->p_min ); + s_start = extract_l( L_sub( s_end, L_sub( ps->l_search, ps->p_min ) ) ); } ELSE { over[n] = 0; /* don't search/overlap (just copy down) */ + move16(); } } @@ -1819,17 +1843,23 @@ static bool extend_frm_fx( IF( isSilence_fx( frm_in_fx, l_seg, 10 ) ) { /* maximum scaling */ - energy_fx = -65 * ( 1 << 8 ); + energy_fx = -65 * ( 1 << 8 ); // Q8 move16(); - quality_fx = 5 << 16; + quality_fx = 5 << 16; // Q16 move32(); - xtract[n] = s_start + ps->num_channels; + xtract[n] = extract_l( L_add( s_start, ps->num_channels ) ); + move16(); IF( ps->evs_compat_mode == false ) { /* take renderer buffer samples into accout */ - xtract[n] += ps->l_r_buf; + xtract[n] = extract_l( L_add( xtract[n], ps->l_r_buf ) ); /* snap to next renderer time slot border to resynchronize */ - xtract[n] -= ( ( N - 1 ) * l_seg - xtract[n] + ps->l_r_buf ) % ps->l_ts; + // xtract[n] -= ( ( N - 1 ) * l_seg - xtract[n] + ps->l_r_buf ) % ps->l_ts; + Word16 tmp3; + tmp3 = extract_l( L_add( L_sub( W_extract_l( W_mult0_32_32( L_sub( N, 1 ), l_seg ) ), xtract[n] ), ps->l_r_buf ) ); + xtract[n] = sub( xtract[n], tmp3 % ps->l_ts ); + move16(); + move16(); } } ELSE @@ -1838,15 +1868,15 @@ static bool extend_frm_fx( frmInScaled = ps->frmInScaled; assert( sizeof( ps->frmInScaled ) / sizeof( ps->frmInScaled[0] ) >= 2 * (size_t) l_frm ); scaleSignal16( frm_in_fx, frmInScaled, shl( l_frm, 1 ), ps->signalScaleForCorrelation ); - findSynchResult = find_synch_fx( ps, frmInScaled, 2 * l_frm, s_start, s_end - s_start, sync_start, l_seg, l_frm, &energy_fx, &quality_fx, &xtract[n] ); + findSynchResult = find_synch_fx( ps, frmInScaled, extract_l( L_shl( l_frm, 1 ) ), s_start, sub( s_end, s_start ), sync_start, l_seg, l_frm, &energy_fx, &quality_fx, &xtract[n] ); } /* assert synch_pos is cleanly divisible by number of channels */ assert( xtract[n] % ps->num_channels == 0 ); /* test for sufficient quality */ IF( LT_32( quality_fx, L_add( L_sub( ps->targetQuality_fx, - L_mult0( ps->bad_frame_count, 6554 ) ), - L_mult0( ps->good_frame_count, 13107 ) ) ) ) + L_mult0( ps->bad_frame_count, 6554 /*.1f in Q16*/ ) ), + L_mult0( ps->good_frame_count, 13107 /*.1f in Q16*/ ) ) ) ) { /* not sufficient */ over[n] = 0; @@ -1893,7 +1923,8 @@ static bool extend_frm_fx( /* Calculate output data */ FOR( n = 2; n <= N; n++ ) { - IF( over[n] && xtract[n - 1] + l_seg != xtract[n] ) + test(); + IF( over[n] && NE_16( extract_l( L_add( xtract[n - 1], l_seg ) ), xtract[n] ) ) { /* mix 2nd half of previous segment with 1st half of current segment */ fadeOut_fx = frm_in_fx + l_frm + xtract[n - 1] + l_seg; @@ -1933,7 +1964,7 @@ static bool extend_frm_fx( } /* set output length */ - *l_frm_out = ( N - 1 ) * l_seg + l_rem; - + *l_frm_out = (UWord16) ( W_mult0_32_32( L_sub( N, 1 ), L_add( l_seg, l_rem ) ) ); + move16(); return 0; } diff --git a/lib_dec/jbm_pcmdsp_apa.h b/lib_dec/jbm_pcmdsp_apa.h index c1654407c..42215ba16 100644 --- a/lib_dec/jbm_pcmdsp_apa.h +++ b/lib_dec/jbm_pcmdsp_apa.h @@ -144,8 +144,10 @@ bool apa_set_quality( apa_state_t *s, Word32 quality, UWord16 qualityred, UWord1 bool apa_exit( apa_state_t **s ); +#ifndef IVAS_FLOAT_FIXED uint8_t apa_exec( apa_state_t *s, const float a_in[], uint16_t l_in, uint16_t maxScaling, float a_out[], uint16_t *l_out ); -uint8_t apa_exec_ivas_fx( apa_state_t *s, const Word16 a_in[], uint16_t l_in, uint16_t maxScaling, Word16 a_out[], uint16_t *l_out ); -uint8_t apa_exec_fx( apa_state_t *s, const Word16 a_in[], uint16_t l_in, uint16_t maxScaling, Word16 a_out[], uint16_t *l_out ); - +#else +uint8_t apa_exec_ivas_fx( apa_state_t *s, const Word16 a_in[], UWord16 l_in, UWord16 maxScaling, Word16 a_out[], UWord16 *l_out ); +uint8_t apa_exec_fx( apa_state_t *s, const Word16 a_in[], UWord16 l_in, UWord16 maxScaling, Word16 a_out[], UWord16 *l_out ); +#endif #endif /* JBM_PCMDSP_APA_H */ diff --git a/lib_dec/jbm_pcmdsp_similarityestimation.c b/lib_dec/jbm_pcmdsp_similarityestimation.c index 435a5bb4b..6bf8c5c90 100644 --- a/lib_dec/jbm_pcmdsp_similarityestimation.c +++ b/lib_dec/jbm_pcmdsp_similarityestimation.c @@ -90,10 +90,11 @@ Word32 cross_correlation_subsampled_self_fx( const Word16 *signal, Word32 sum; Word16 i; - sum = L_deposit_l( 0 ); + sum = 0; + move32(); FOR( i = 0; i < corr_len; i += subsampling ) { - sum = L_mac0( sum, signal[add( x, i )], signal[add( y, i )] ); + sum = L_mac0( sum, signal[x + i], signal[y + i] ); } return sum; @@ -203,10 +204,12 @@ Word16 normalized_cross_correlation_self_fx( const Word16 *signal, signalX = &signal[x]; signalY = &signal[y]; - sumXY = L_deposit_l( 0 ); - sumXX = L_deposit_l( 0 ); - sumYY = L_deposit_l( 0 ); - + sumXY = 0; + sumXX = 0; + sumYY = 0; + move32(); + move32(); + move32(); FOR( i = 0; i < corr_len; i += subsampling ) { sumXY = L_mac0( sumXY, signalX[i], signalY[i] ); @@ -235,7 +238,7 @@ Word16 normalized_cross_correlation_self_fx( const Word16 *signal, { #ifdef FX_834_OVFL_JBM_CROSSCORR Flag Overflow = 0; - move16(); + move32(); #endif normCC = 0; move16(); @@ -293,10 +296,11 @@ Word32 cross_correlation_self_fx( const Word16 *signal, Word32 sum; Word16 i; - sum = L_deposit_l( 0 ); + sum = 0; + move32(); FOR( i = 0; i < corr_len; i++ ) { - sum = L_mac0( sum, signal[add( x, i )], signal[add( y, i )] ); + sum = L_mac0( sum, signal[x + i], signal[y + i] ); } return sum; @@ -320,7 +324,8 @@ Word8 isSilence_fx( const Word16 *signal, Word16 len, Word16 segments ) ret = 1; move16(); - energy = L_deposit_l( 0 ); + energy = 0; + move32(); samplesPerSegment = idiv1616U( len, segments ); /* calculate maxEnergy with factor 2 to reduce rounding error */ maxEnergy = L_mult0( samplesPerSegment, 37 ); /* 37 = 2 * exp10(-65.0 / 20) * 32768 */ @@ -337,13 +342,14 @@ Word8 isSilence_fx( const Word16 *signal, Word16 len, Word16 segments ) /* check energy of current segment */ /* 20 * log10(energy / 32768 / samplesPerSegment) > -65 * => energy > samplesPerSegment * 10 ^ (-65 / 20) * 32768 */ - if ( GT_32( energy, maxEnergy ) ) + IF( GT_32( energy, maxEnergy ) ) { ret = 0; move16(); BREAK; } - energy = L_deposit_l( 0 ); + energy = 0; + move32(); j = add( j, samplesPerSegment ); } } diff --git a/lib_dec/jbm_pcmdsp_similarityestimation.h b/lib_dec/jbm_pcmdsp_similarityestimation.h index 349189119..9a76a63f8 100644 --- a/lib_dec/jbm_pcmdsp_similarityestimation.h +++ b/lib_dec/jbm_pcmdsp_similarityestimation.h @@ -41,7 +41,7 @@ #include "options.h" #include "typedef.h" - +#ifndef IVAS_FLOAT_FIXED /* ******************************************************************************** * @@ -67,13 +67,11 @@ * ******************************************************************************** */ -#ifndef IVAS_FLOAT_FIXED float cross_correlation_self( const float *signal, uint16_t x, uint16_t y, uint16_t corr_len ); -#endif // !IVAS_FLOAT_FIXED /* ******************************************************************************** @@ -100,14 +98,12 @@ float cross_correlation_self( * ******************************************************************************** */ -#ifndef IVAS_FLOAT_FIXED float cross_correlation_subsampled_self( const float *signal, uint16_t x, uint16_t y, uint16_t corr_len, uint16_t subsampling ); -#endif /* ******************************************************************************** * @@ -144,7 +140,6 @@ float cross_correlation_subsampled_self( * ******************************************************************************** */ -#ifndef IVAS_FLOAT_FIXED float normalized_cross_correlation_self( const float *signal, uint16_t x, @@ -152,13 +147,13 @@ float normalized_cross_correlation_self( uint16_t corr_len, uint16_t subsampling, float *energy ); -#endif + /* Splits the signal into segments and checks if all of them have very low energy. */ bool isSilence( const float *signal, uint32_t len, uint32_t segments ); - +#else Word32 cross_correlation_subsampled_self_fx( const Word16 *signal, Word16 x, Word16 y, @@ -166,10 +161,9 @@ Word32 cross_correlation_subsampled_self_fx( const Word16 *signal, Word16 subsampling ); Word16 getSignalScaleForCorrelation( Word32 sampleRate ); -#ifdef IVAS_FLOAT_FIXED + void scaleSignal16( const Word16 *src, Word16 *dst, Word16 n, Word16 rightShift ); -#endif /* IVAS_FLOAT_FIXED */ Word16 normalized_cross_correlation_self_fx( const Word16 *signal, Word16 x, @@ -186,4 +180,5 @@ Word32 cross_correlation_self_fx( const Word16 *signal, Word8 isSilence_fx( const Word16 *signal, Word16 len, Word16 segments ); -#endif /* JBM_PCMDSP_SIMILARITYESTIMATION_H */ +#endif /* IVAS_FLOAT_FIXED */ +#endif /* JBM_PCMDSP_SIMILARITYESTIMATION_H */ \ No newline at end of file diff --git a/lib_dec/jbm_pcmdsp_window.c b/lib_dec/jbm_pcmdsp_window.c index a9ed3f82c..8df52a83e 100644 --- a/lib_dec/jbm_pcmdsp_window.c +++ b/lib_dec/jbm_pcmdsp_window.c @@ -41,7 +41,7 @@ #include "jbm_pcmdsp_window.h" #include "cnst.h" #include "wmc_auto.h" - +#ifndef IVAS_FLOAT_FIXED /*-----------------------------------------------------------------------* * hannWindow() * @@ -68,7 +68,7 @@ void hannWindow( return; } - +#endif /*-----------------------------------------------------------------------* * overlapAdd() diff --git a/lib_enc/analy_sp_fx.c b/lib_enc/analy_sp_fx.c index 82a77f602..2b7f40ce7 100644 --- a/lib_enc/analy_sp_fx.c +++ b/lib_enc/analy_sp_fx.c @@ -492,12 +492,14 @@ void ivas_analy_sp_fx( Scale_sig( fft_temp, L_FRAME_12k8, Scale_fac[i_subfr] ); r_fft_fx_lc( FFT_W128, SIZE_256, SIZE2_256, NUM_STAGE_256, fft_temp, pt_fft, 1 ); + Scale_sig( pt_fft, L_FFT, -1 ); // Q(-1) /*e_min_scaled = Q_new + QSCALE + 2*/ find_enr( pt_fft, pt_bands, lf_E + i_subfr * VOIC_BINS, &LEtot, min_band, max_band, add( Q_new, Scale_fac2 ), e_min_scaled, &Bin_E[i_subfr * L_FFT / 2], BIN, band_energies + i_subfr * NB_BANDS ); pt_bands += NB_BANDS; pt_fft += L_FFT; } + LEtot = L_shl_sat( LEtot, 2 ); // Q_new + Q_SCALE - 2 } ELSE { diff --git a/lib_enc/ivas_cpe_enc.c b/lib_enc/ivas_cpe_enc.c index 7f79fdbc2..89ae59101 100644 --- a/lib_enc/ivas_cpe_enc.c +++ b/lib_enc/ivas_cpe_enc.c @@ -296,8 +296,8 @@ ivas_error ivas_cpe_enc( fixedToFloat_arr( hCPE->hFrontVad[n]->mem_decim_fx, hCPE->hFrontVad[n]->mem_decim, Q_inp, 90 ); hCPE->hFrontVad[n]->mem_preemph = fixedToFloat( hCPE->hFrontVad[n]->mem_preemph_fx, Q_inp + Qband ); fixedToFloat_arr( hCPE->hFrontVad[n]->buffer_12k8_fx, hCPE->hFrontVad[n]->buffer_12k8, Q_buffer[n], 384 ); - fixedToFloat_arrL( fr_bands_fx[n], fr_bands[n], Q_buffer[n] + QSCALE + 2, 40 ); - fixedToFloat_arrL( lf_E_fx[n], lf_E[n], Q_buffer[n] + QSCALE, 148 ); + fixedToFloat_arrL( fr_bands_fx[n], fr_bands[n], Q_buffer[n] + QSCALE, 40 ); + fixedToFloat_arrL( lf_E_fx[n], lf_E[n], Q_buffer[n] + QSCALE - 2, 148 ); Etot_LR[n] = fixedToFloat( Etot_LR_fx[n], Q8 ); fixedToFloat_arrL( hCPE->hFrontVad[n]->hNoiseEst->bckr_fx, hCPE->hFrontVad[n]->hNoiseEst->bckr, Q_new_old + QSCALE, 20 ); @@ -317,7 +317,7 @@ ivas_error ivas_cpe_enc( } } // fixedToFloat_arrL( band_energies_fx, band_energies, Q_new + QSCALE + 2, 40 ); - fixedToFloat_arrL( &band_energies_LR_fx[0], &band_energies_LR[0], Q_buffer[1] + QSCALE + 2 - band_ener_guardbits, 40 ); + fixedToFloat_arrL( &band_energies_LR_fx[0], &band_energies_LR[0], Q_buffer[1] + QSCALE - band_ener_guardbits, 40 ); } #endif #else diff --git a/lib_enc/ivas_front_vad.c b/lib_enc/ivas_front_vad.c index 61e8f6e62..64296eb11 100644 --- a/lib_enc/ivas_front_vad.c +++ b/lib_enc/ivas_front_vad.c @@ -420,8 +420,8 @@ ivas_error front_vad_fx( noise_est_pre_32fx( Etot_fx, hFrontVads[0]->ini_frame, hFrontVad->hNoiseEst, 0, 0, 0 ); /* wb_vad */ - Scale_sig32( hFrontVads[n]->hNoiseEst->bckr_fx, Q_new + QSCALE - ( Q_new_old + QSCALE ), 20 ); - Scale_sig32( hFrontVads[n]->hNoiseEst->enrO_fx, Q_new + QSCALE - ( Q_new_old + QSCALE ), 20 ); + Scale_sig32( hFrontVads[n]->hNoiseEst->bckr_fx, NB_BANDS, Q_new + QSCALE - ( Q_new_old + QSCALE )); + Scale_sig32( hFrontVads[n]->hNoiseEst->enrO_fx, NB_BANDS, Q_new + QSCALE - ( Q_new_old + QSCALE )); hFrontVad->hNoiseEst->sign_dyn_lp_fx = extract_h( hFrontVad->hNoiseEst->sign_dyn_lp_32fx ); hFrontVad->hNoiseEst->Etot_v_h2_fx = extract_h( hFrontVad->hNoiseEst->Etot_v_h2_32fx ); hFrontVad->hVAD->vad_flag = wb_vad_ivas_fx( sts[n], fr_bands_fx[n], &dummy, &dummy, &dummy, &snr_sum_he_fx, &localVAD_HE_SAD[n], &dummy_short, Q_new, hFrontVad->hVAD, hFrontVad->hNoiseEst, hFrontVad->lp_speech_fx, hFrontVad->lp_noise_fx ); diff --git a/lib_enc/nois_est_fx.c b/lib_enc/nois_est_fx.c index c3af6c904..1bfc4a4bf 100644 --- a/lib_enc/nois_est_fx.c +++ b/lib_enc/nois_est_fx.c @@ -2785,7 +2785,8 @@ void noise_est_ivas_fx( { /* st->harm_cor_cnt = max(1, (short) round_f( (float) st->harm_cor_cnt / 4.0f )) ; */ - *st_harm_cor_cnt = s_max( 1, shr( add( *st_harm_cor_cnt, 2 ), 1 ) ); + *st_harm_cor_cnt = s_max( 1, shr( add( *st_harm_cor_cnt, 2 ), 2 ) ); + move16(); } diff --git a/lib_enc/vad_fx.c b/lib_enc/vad_fx.c index 6723304c7..18a71e294 100644 --- a/lib_enc/vad_fx.c +++ b/lib_enc/vad_fx.c @@ -2676,8 +2676,8 @@ Word16 wb_vad_ivas_fx( /*snr_sum_ol = 10.0f * (float)log10( hVAD->L_snr_sum_vad_fx );*/ snr_sum_ol = vad_snr_log_fx( hVAD->L_snr_sum_vad_fx, LG10 ); /* snr in Q8 */ } - ELSE IF( ( ( LE_16( st_fx->last_coder_type, UNVOICED ) ) && ( LT_32( L_snr_outlier, MAX_SNR_OUTLIER_2_FX ) ) && ( st_fx->Opt_SC_VBR != 0 ) ) || - ( ( LE_16( last_7k2_coder_type, UNVOICED ) ) && ( LT_32( L_snr_outlier, MAX_SNR_OUTLIER_2_FX ) ) && ( st_fx->Opt_SC_VBR == 0 ) ) ) + ELSE IF( ( ( LE_16( st_fx->last_coder_type, UNVOICED ) ) && ( LT_32( L_snr_outlier, MAX_SNR_OUTLIER_2_FX ) ) && ( st_fx->Opt_SC_VBR == 0 ) ) || + ( ( LE_16( last_7k2_coder_type, UNVOICED ) ) && ( LT_32( L_snr_outlier, MAX_SNR_OUTLIER_2_FX ) ) && ( st_fx->Opt_SC_VBR != 0 ) ) ) { /* thr1_ol = thr1 + (float)(1.0f - 0.04f * snr_outlier); */ diff --git a/lib_rend/ivas_dirac_rend.c b/lib_rend/ivas_dirac_rend.c index 9e8733d3f..af3d9000c 100644 --- a/lib_rend/ivas_dirac_rend.c +++ b/lib_rend/ivas_dirac_rend.c @@ -241,7 +241,7 @@ ivas_error ivas_dirac_allocate_parameters_fx( { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); } - set32_fx( hSpatParamRendCom->diffuseness_vector_fx[i], ONE_IN_Q30, hSpatParamRendCom->num_freq_bands ); + set32_fx( hSpatParamRendCom->diffuseness_vector_fx[i], ONE_IN_Q30, hSpatParamRendCom->num_freq_bands ); // q30 IF( ( hSpatParamRendCom->energy_ratio1_fx[i] = (Word32 *) malloc( hSpatParamRendCom->num_freq_bands * sizeof( Word32 ) ) ) == NULL ) { @@ -339,7 +339,10 @@ ivas_error ivas_spat_hSpatParamRendCom_config_fx( DIRAC_CONFIG_FLAG flag_config; SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom; - flag_config = EQ_32( flag_config_inp, DIRAC_RECONFIGURE_MODE ) ? DIRAC_RECONFIGURE : flag_config_inp; + IF( EQ_32( flag_config_inp, DIRAC_RECONFIGURE_MODE ) ) + flag_config = DIRAC_RECONFIGURE; + ELSE + flag_config = flag_config_inp; move32(); error = IVAS_ERR_OK; move32(); @@ -367,7 +370,7 @@ ivas_error ivas_spat_hSpatParamRendCom_config_fx( IF( EQ_32( flag_config, DIRAC_OPEN ) ) { /* hSpatParamRendCom->slot_size = (int16_t) ( ( output_Fs / FRAMES_PER_SEC ) / CLDFB_NO_COL_MAX ); */ - hSpatParamRendCom->slot_size = extract_l( Mpy_32_32( output_Fs, 2684355 /* 1 / ( FRAMES_PER_SEC * CLDFB_NO_COL_MAX) in Q31 */ ) ); + hSpatParamRendCom->slot_size = extract_l( Mpy_32_32( output_Fs, 2684355 /* 1 / ( FRAMES_PER_SEC * CLDFB_NO_COL_MAX) in Q31 */ ) ); // Q0+Q31-Q31=>Q0 move16(); set16_fx( hSpatParamRendCom->subframe_nbslots, 0, MAX_JBM_SUBFRAMES_5MS ); set16_fx( hSpatParamRendCom->subframe_nbslots, JBM_CLDFB_SLOTS_IN_SUBFRAME, DEFAULT_JBM_SUBFRAMES_5MS ); @@ -380,7 +383,7 @@ ivas_error ivas_spat_hSpatParamRendCom_config_fx( hSpatParamRendCom->num_slots = DEFAULT_JBM_SUBFRAMES_5MS * JBM_CLDFB_SLOTS_IN_SUBFRAME; move16(); /* hSpatParamRendCom->num_freq_bands = (int16_t) ( output_Fs * INV_CLDFB_BANDWIDTH + 0.5f ); */ - hSpatParamRendCom->num_freq_bands = extract_l( Mpy_32_32( output_Fs, 2684355 /* INV_CLDFB_BANDWIDTH in Q31 */ ) ); + hSpatParamRendCom->num_freq_bands = extract_l( Mpy_32_32( output_Fs, 2684355 /* INV_CLDFB_BANDWIDTH in Q31 */ ) ); // 0+31-31=>0 move16(); hSpatParamRendCom->numSimultaneousDirections = 0; move16(); @@ -454,7 +457,10 @@ ivas_error ivas_spat_hSpatParamRendCom_config_fx( Word16 num_slots_in_subfr, tmp; tmp = 1; move16(); - num_slots_in_subfr = dec_param_estim_flag ? CLDFB_NO_COL_MAX / MAX_PARAM_SPATIAL_SUBFRAMES : 1; + IF( dec_param_estim_flag ) + num_slots_in_subfr = CLDFB_NO_COL_MAX / MAX_PARAM_SPATIAL_SUBFRAMES; + ELSE + num_slots_in_subfr = 1; move16(); hSpatParamRendCom->dirac_md_buffer_length = MAX_PARAM_SPATIAL_SUBFRAMES + DELAY_DIRAC_PARAM_DEC_SFR; move16(); @@ -1890,9 +1896,9 @@ void ivas_dirac_free_mem( #ifdef IVAS_FLOAT_FIXED void compute_hoa_encoder_mtx_fx( - const Word32 *azimuth, - const Word32 *elevation, - Word32 *response_fx, + const Word32 *azimuth, /*q22*/ + const Word32 *elevation, /*q22*/ + Word32 *response_fx, /*q31*/ const Word16 num_responses, const Word16 ambisonics_order ) { @@ -1901,7 +1907,7 @@ void compute_hoa_encoder_mtx_fx( num_sh = ivas_sba_get_nchan_fx( ambisonics_order, 0 ); FOR( k = 0; k < num_responses; k++ ) { - ivas_dirac_dec_get_response_fx( shr( extract_h( azimuth[k] ), Q22 - Q16 ), shr( extract_h( elevation[k] ), Q22 - Q16 ), &response_fx[imult1616( k, num_sh )], ambisonics_order, Q31 ); /* Q31 */ + ivas_dirac_dec_get_response_fx( shr( extract_h( azimuth[k] ), Q22 - Q16 ), shr( extract_h( elevation[k] ), Q22 - Q16 ), &response_fx[k * num_sh], ambisonics_order, Q31 ); /* Q31 */ } return; @@ -1961,12 +1967,12 @@ void ivas_dirac_dec_get_frequency_axis_fx( Word16 k, const_part, scale; /* calc cldfb frequency axis */ - const_part = BASOP_Util_Divide3216_Scale( output_Fs, shl( num_freq_bands, 1 ), &scale ); - const_part = shr( const_part, sub( -1, scale ) ); + const_part = BASOP_Util_Divide3216_Scale( output_Fs, shl( num_freq_bands, 1 ), &scale ); // 15-(scale+31-15)=>-1-scale + const_part = shr( const_part, sub( -1, scale ) ); // q(-1-scale)->q0 FOR( k = 0; k < num_freq_bands; k++ ) { /* frequency_axis[k] = ((float)k + 0.5f) * const_part; */ - frequency_axis[k] = add( i_mult( k, const_part ), shr( const_part, 1 ) ); + frequency_axis[k] = add( i_mult( k, const_part ), shr( const_part, 1 ) ); /*q0*/ move16(); } @@ -2089,7 +2095,7 @@ void initDiffuseResponses( } #else void initDiffuseResponses_fx( - Word16 *diffuse_response_function_fx, + Word16 *diffuse_response_function_fx, /*q15*/ const Word16 num_channels, const AUDIO_CONFIG output_config, const IVAS_OUTPUT_SETUP hOutSetup, @@ -2107,7 +2113,7 @@ void initDiffuseResponses_fx( test(); IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_MONO ) ) { - diffuse_response_function_fx[0] = MAX16B; + diffuse_response_function_fx[0] = MAX16B; /*1 q15*/ move16(); diffuse_response_function_fx[1] = 18918 /*inv_sqrt(3.0f) oin Q15*/; move16(); @@ -2139,7 +2145,7 @@ void initDiffuseResponses_fx( IF( EQ_32( ivas_format, MC_FORMAT ) && ( EQ_32( transport_config, IVAS_AUDIO_CONFIG_5_1 ) || EQ_32( transport_config, IVAS_AUDIO_CONFIG_7_1 ) ) && EQ_32( output_config, IVAS_AUDIO_CONFIG_5_1_4 ) ) { num_horizontal_speakers = sub( num_channels, NUM_ELEVATED_SPEAKERS ); - Copy( diffuse_response_CICP6_fx, diffuse_response_function_fx, num_horizontal_speakers ); + Copy( diffuse_response_CICP6_fx, diffuse_response_function_fx, num_horizontal_speakers ); // q15 set16_fx( &diffuse_response_function_fx[num_horizontal_speakers], 0, NUM_ELEVATED_SPEAKERS ); *num_ele_spk_no_diffuse_rendering = NUM_ELEVATED_SPEAKERS; move16(); @@ -2149,24 +2155,24 @@ void initDiffuseResponses_fx( num_horizontal_speakers = sub( num_channels, NUM_ELEVATED_SPEAKERS ); exp_var1 = 15; move16(); - var1 = ISqrt16( num_horizontal_speakers, &exp_var1 ); - var1 = shr( var1, negate( exp_var1 ) ); // Q15 - set16_fx( diffuse_response_function_fx, var1, num_horizontal_speakers ); + var1 = ISqrt16( num_horizontal_speakers, &exp_var1 ); // q=15-exp_var1 + var1 = shr( var1, negate( exp_var1 ) ); // Q15 + set16_fx( diffuse_response_function_fx, var1, num_horizontal_speakers ); // q15 set16_fx( &diffuse_response_function_fx[num_horizontal_speakers], 0, NUM_ELEVATED_SPEAKERS ); *num_ele_spk_no_diffuse_rendering = NUM_ELEVATED_SPEAKERS; move16(); } ELSE IF( ( EQ_32( ivas_format, MASA_FORMAT ) || EQ_32( ivas_format, MASA_ISM_FORMAT ) || EQ_32( ivas_format, MC_FORMAT ) ) && EQ_32( output_config, IVAS_AUDIO_CONFIG_5_1 ) && EQ_16( num_channels, 5 ) ) { - Copy( diffuse_response_CICP6_fx, diffuse_response_function_fx, num_channels ); + Copy( diffuse_response_CICP6_fx, diffuse_response_function_fx, num_channels ); // q15 } ELSE IF( ( EQ_32( ivas_format, MASA_FORMAT ) || EQ_32( ivas_format, MASA_ISM_FORMAT ) || EQ_32( ivas_format, MC_FORMAT ) ) && EQ_32( output_config, IVAS_AUDIO_CONFIG_5_1_2 ) && EQ_16( num_channels, 7 ) ) { - Copy( diffuse_response_CICP14_fx, diffuse_response_function_fx, num_channels ); + Copy( diffuse_response_CICP14_fx, diffuse_response_function_fx, num_channels ); // q15 } ELSE IF( ( EQ_32( ivas_format, MASA_FORMAT ) || EQ_32( ivas_format, MASA_ISM_FORMAT ) || EQ_32( ivas_format, MC_FORMAT ) ) && ( EQ_32( output_config, IVAS_AUDIO_CONFIG_5_1_4 ) ) && EQ_16( num_channels, 9 ) ) { - Copy( diffuse_response_CICP16_fx, diffuse_response_function_fx, num_channels ); + Copy( diffuse_response_CICP16_fx, diffuse_response_function_fx, num_channels ); // q15 } ELSE IF( ( EQ_32( ivas_format, MASA_FORMAT ) || EQ_32( ivas_format, MASA_ISM_FORMAT ) || EQ_32( ivas_format, MC_FORMAT ) ) && EQ_32( output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) ) { @@ -2177,10 +2183,10 @@ void initDiffuseResponses_fx( move16(); FOR( i = 0; i < num_channels; i++ ) { - IF( LE_32( abs( hOutSetup.ls_elevation_fx[i] ), 20971520 ) /*5 in Q22*/ ) + IF( LE_32( L_abs( hOutSetup.ls_elevation_fx[i] /*q22*/ ), 20971520 /*5 in Q22*/ ) ) { num_horizontal_speakers = add( num_horizontal_speakers, 1 ); - diffuse_response_function_fx[i] = MAX16B; + diffuse_response_function_fx[i] = MAX16B; // q15 move16(); } ELSE @@ -2196,13 +2202,13 @@ void initDiffuseResponses_fx( { exp_var1 = 15; move16(); - Word16 num_horizontal_speakers_isq = ISqrt16( num_horizontal_speakers, &exp_var1 ); - num_horizontal_speakers_isq = shr( num_horizontal_speakers_isq, negate( exp_var1 ) ); + Word16 num_horizontal_speakers_isq = ISqrt16( num_horizontal_speakers, &exp_var1 ); // q15-exp_var1 + num_horizontal_speakers_isq = shr( num_horizontal_speakers_isq, negate( exp_var1 ) ); // q15 assert( 0 ); /*No stream hitting*/ FOR( i = 0; i < num_channels; i++ ) { - diffuse_response_function_fx[i] = shr( mult( diffuse_response_function_fx[i], num_horizontal_speakers_isq ), Q15 ); + diffuse_response_function_fx[i] = mult( diffuse_response_function_fx[i], num_horizontal_speakers_isq ); // q15 move16(); } } @@ -2211,9 +2217,9 @@ void initDiffuseResponses_fx( var1 = num_channels, exp_var1 = 15; move16(); move16(); - res = ISqrt16( var1, &exp_var1 ); - res = shr( res, negate( exp_var1 ) ); - set16_fx( diffuse_response_function_fx, res, num_channels ); + res = ISqrt16( var1, &exp_var1 ); // q=15-exp_var1 + res = shr( res, negate( exp_var1 ) ); // q=15 + set16_fx( diffuse_response_function_fx, res, num_channels ); // q15 *num_ele_spk_no_diffuse_rendering = 0; move16(); } @@ -2223,9 +2229,9 @@ void initDiffuseResponses_fx( var1 = num_channels, exp_var1 = 15; move16(); move16(); - res = ISqrt16( var1, &exp_var1 ); - res = shr( res, negate( exp_var1 ) ); - set16_fx( diffuse_response_function_fx, res, num_channels ); + res = ISqrt16( var1, &exp_var1 ); // q=15-exp_var1 + res = shr( res, negate( exp_var1 ) ); // q15 + set16_fx( diffuse_response_function_fx, res, num_channels ); // q15 } } ELSE @@ -2233,9 +2239,9 @@ void initDiffuseResponses_fx( var1 = num_channels, exp_var1 = 15; move16(); move16(); - res = ISqrt16( var1, &exp_var1 ); - res = shr( res, negate( exp_var1 ) ); - set16_fx( diffuse_response_function_fx, res, num_channels ); + res = ISqrt16( var1, &exp_var1 ); // q(15-exp_var1) + res = shr( res, negate( exp_var1 ) ); // q15 + set16_fx( diffuse_response_function_fx, res, num_channels ); // q15 } } ELSE @@ -2251,9 +2257,9 @@ void initDiffuseResponses_fx( var1 = j, exp_var1 = 15; move16(); move16(); - res = ISqrt16( var1, &exp_var1 ); - diffuse_response_function_fx[idx] = shr( res, negate( exp_var1 ) ); - idx = add( idx, 1 ); + res = ISqrt16( var1, &exp_var1 ); // q(15-exp_var1) + diffuse_response_function_fx[idx] = shr( res, negate( exp_var1 ) ); // q15 + idx = idx + 1; } } } @@ -2271,13 +2277,13 @@ void initDiffuseResponses_fx( #ifdef IVAS_FLOAT_FIXED void protoSignalComputation_shd_fx( - Word32 RealBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], - Word32 ImagBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], - Word32 *proto_direct_buffer_f_fx, + Word32 RealBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /*Q(q_cldfb)*/ + Word32 ImagBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /*Q(q_cldfb)*/ + Word32 *proto_direct_buffer_f_fx, /*Q(proto_direct_buffer_f_q)*/ Word16 *proto_direct_buffer_f_q, - Word32 *proto_diffuse_buffer_f_fx, + Word32 *proto_diffuse_buffer_f_fx, /*Q(proto_diffuse_buffer_f_q)*/ Word16 *proto_diffuse_buffer_f_q, - Word32 *reference_power_fx, + Word32 *reference_power_fx, /*Q(reference_power_q)*/ Word16 *reference_power_q, const Word16 slot_index, const Word16 num_inputs, @@ -2305,16 +2311,16 @@ void protoSignalComputation_shd_fx( q_shift = Q31; move16(); - p_proto_direct_buffer_fx = proto_direct_buffer_f_fx + i_mult( i_mult( slot_index, 2 ), i_mult( num_freq_bands, num_inputs ) ); - p_proto_diffuse_buffer_fx = proto_diffuse_buffer_f_fx + i_mult( i_mult( slot_index, 2 ), i_mult( num_freq_bands, num_outputs_diff ) ); + p_proto_direct_buffer_fx = proto_direct_buffer_f_fx + i_mult( i_mult( slot_index, 2 ), i_mult( num_freq_bands, num_inputs ) ); /*proto_direct_buffer_f_q*/ + p_proto_diffuse_buffer_fx = proto_diffuse_buffer_f_fx + i_mult( i_mult( slot_index, 2 ), i_mult( num_freq_bands, num_outputs_diff ) ); /*proto_diffuse_buffer_f_q*/ IF( EQ_16( num_inputs, 1 ) ) { FOR( l = 0; l < num_freq_bands; l++ ) { - p_proto_direct_buffer_fx[2 * l] = RealBuffer_fx[0][0][l]; + p_proto_direct_buffer_fx[2 * l] = RealBuffer_fx[0][0][l]; /*Q(q_cldfb)*/ move32(); - p_proto_direct_buffer_fx[add( 2 * l, 1 )] = ImagBuffer_fx[0][0][l]; + p_proto_direct_buffer_fx[2 * l + 1] = ImagBuffer_fx[0][0][l]; /*Q(q_cldfb)*/ move32(); } *proto_direct_buffer_f_q = q_cldfb; @@ -2328,19 +2334,19 @@ void protoSignalComputation_shd_fx( FOR( l = 0; l < num_freq_bands; l++ ) { - re1 = L_add( RealBuffer_fx[0][0][l], RealBuffer_fx[1][0][l] ); - im1 = L_add( ImagBuffer_fx[0][0][l], ImagBuffer_fx[1][0][l] ); + re1 = L_add( RealBuffer_fx[0][0][l], RealBuffer_fx[1][0][l] ); /*Q(q_cldfb)*/ + im1 = L_add( ImagBuffer_fx[0][0][l], ImagBuffer_fx[1][0][l] ); /*Q(q_cldfb)*/ - re2 = L_sub( RealBuffer_fx[0][0][l], RealBuffer_fx[1][0][l] ); - im2 = L_sub( ImagBuffer_fx[0][0][l], ImagBuffer_fx[1][0][l] ); + re2 = L_sub( RealBuffer_fx[0][0][l], RealBuffer_fx[1][0][l] ); /*Q(q_cldfb)*/ + im2 = L_sub( ImagBuffer_fx[0][0][l], ImagBuffer_fx[1][0][l] ); /*Q(q_cldfb)*/ - p_proto_direct_buffer_fx[2 * l] = re1; + p_proto_direct_buffer_fx[2 * l] = re1; /*Q(q_cldfb)*/ move32(); - p_proto_direct_buffer_fx[add( 2 * l, 1 )] = im1; + p_proto_direct_buffer_fx[2 * l + 1] = im1; /*Q(q_cldfb)*/ move32(); - p_proto_direct_buffer_fx[i_mult( 2, add( num_freq_bands, l ) )] = L_shl( Mpy_32_32( p_Rmat_fx[0], re2 ), Q1 ); // left shift is done to maintain constant Q factor for p_proto_direct_buffer_fx + p_proto_direct_buffer_fx[2 * ( num_freq_bands + l )] = L_shl( Mpy_32_32( p_Rmat_fx[0], re2 ), Q1 ); // left shift is done to maintain constant Q factor for p_proto_direct_buffer_fx =>Q(q_cldfb) move32(); - p_proto_direct_buffer_fx[add( i_mult( 2, add( num_freq_bands, l ) ), 1 )] = L_shl( Mpy_32_32( p_Rmat_fx[0], im2 ), Q1 ); // left shift is done to maintain constant Q factor for p_proto_direct_buffer_fx + p_proto_direct_buffer_fx[2 * ( num_freq_bands + l ) + 1] = L_shl( Mpy_32_32( p_Rmat_fx[0], im2 ), Q1 ); // left shift is done to maintain constant Q factor for p_proto_direct_buffer_fx => Q(q_cldfb) move32(); } *proto_direct_buffer_f_q = q_cldfb; @@ -2350,16 +2356,16 @@ void protoSignalComputation_shd_fx( { FOR( l = 0; l < num_freq_bands; l++ ) { - re1 = L_add( RealBuffer_fx[0][0][l], RealBuffer_fx[1][0][l] ); - im1 = L_add( ImagBuffer_fx[0][0][l], ImagBuffer_fx[1][0][l] ); + re1 = L_add( RealBuffer_fx[0][0][l], RealBuffer_fx[1][0][l] ); /*Q(q_cldfb)*/ + im1 = L_add( ImagBuffer_fx[0][0][l], ImagBuffer_fx[1][0][l] ); /*Q(q_cldfb)*/ - p_proto_direct_buffer_fx[2 * l] = re1; + p_proto_direct_buffer_fx[2 * l] = re1; /*Q(q_cldfb)*/ move32(); - p_proto_direct_buffer_fx[add( 2 * l, 1 )] = im1; + p_proto_direct_buffer_fx[2 * l + 1] = im1; /*Q(q_cldfb)*/ move32(); - p_proto_direct_buffer_fx[i_mult( 2, add( num_freq_bands, l ) )] = L_sub( RealBuffer_fx[0][0][l], RealBuffer_fx[1][0][l] ); + p_proto_direct_buffer_fx[2 * num_freq_bands + 2 * l] = L_sub( RealBuffer_fx[0][0][l], RealBuffer_fx[1][0][l] ); /*Q(q_cldfb)*/ move32(); - p_proto_direct_buffer_fx[add( i_mult( 2, add( num_freq_bands, l ) ), 1 )] = L_sub( ImagBuffer_fx[0][0][l], ImagBuffer_fx[1][0][l] ); + p_proto_direct_buffer_fx[2 * num_freq_bands + 2 * l + 1] = L_sub( ImagBuffer_fx[0][0][l], ImagBuffer_fx[1][0][l] ); /*Q(q_cldfb)*/ move32(); } } @@ -2368,10 +2374,10 @@ void protoSignalComputation_shd_fx( } ELSE IF( GE_16( num_inputs, 4 ) ) { - p_k_fx[0] = p_proto_direct_buffer_fx; - p_k_fx[1] = p_proto_direct_buffer_fx + i_mult( 2, num_freq_bands ); - p_k_fx[2] = p_proto_direct_buffer_fx + i_mult( 4, num_freq_bands ); - p_k_fx[3] = p_proto_direct_buffer_fx + i_mult( 6, num_freq_bands ); + p_k_fx[0] = p_proto_direct_buffer_fx; /*Q(proto_direct_buffer_f_q)*/ + p_k_fx[1] = p_proto_direct_buffer_fx + i_mult( 2, num_freq_bands ); /*Q(proto_direct_buffer_f_q)*/ + p_k_fx[2] = p_proto_direct_buffer_fx + i_mult( 4, num_freq_bands ); /*Q(proto_direct_buffer_f_q)*/ + p_k_fx[3] = p_proto_direct_buffer_fx + i_mult( 6, num_freq_bands ); /*Q(proto_direct_buffer_f_q)*/ Rmat_k[0] = 0; move16(); @@ -2399,50 +2405,50 @@ void protoSignalComputation_shd_fx( FOR( l = 0; l < num_freq_bands; l++ ) { - *p_k_fx[0] = L_shl( RealBuffer_fx[0][0][l], min_q_shift ); + *p_k_fx[0] = L_shl( RealBuffer_fx[0][0][l], min_q_shift ); /*Q(q_cldfb+min_q_shift)*/ move32(); - reference_power_fx[add( l, num_freq_bands )] = Mpy_32_32( *p_k_fx[0], *p_k_fx[0] ); + reference_power_fx[l + num_freq_bands] = Mpy_32_32( *p_k_fx[0], *p_k_fx[0] ); /*2*Q(q_cldfb+min_q_shift)-31*/ move32(); p_k_fx[0]++; - *p_k_fx[0] = L_shl( ImagBuffer_fx[0][0][l], min_q_shift ); + *p_k_fx[0] = L_shl( ImagBuffer_fx[0][0][l], min_q_shift ); /*Q(q_cldfb+min_q_shift)*/ move32(); - reference_power_fx[add( l, num_freq_bands )] = Madd_32_32( reference_power_fx[add( l, num_freq_bands )], *p_k_fx[0], *p_k_fx[0] ); + reference_power_fx[l + num_freq_bands] = Madd_32_32( reference_power_fx[l + num_freq_bands], *p_k_fx[0], *p_k_fx[0] ); /*2*Q(q_cldfb+min_q_shift)-31*/ move32(); p_k_fx[0]++; - reference_power_fx[l] = L_shr( reference_power_fx[add( l, num_freq_bands )], 1 ); + reference_power_fx[l] = L_shr( reference_power_fx[l + num_freq_bands], 1 ); /*2*Q(q_cldfb+min_q_shift)-31-1*/ move32(); FOR( k = 1; k < 4; k++ ) { - re1 = L_shl( RealBuffer_fx[1][0][l], min_q_shift ); - re2 = L_shl( RealBuffer_fx[2][0][l], min_q_shift ); - re3 = L_shl( RealBuffer_fx[3][0][l], min_q_shift ); - im1 = L_shl( ImagBuffer_fx[1][0][l], min_q_shift ); - im2 = L_shl( ImagBuffer_fx[2][0][l], min_q_shift ); - im3 = L_shl( ImagBuffer_fx[3][0][l], min_q_shift ); + re1 = L_shl( RealBuffer_fx[1][0][l], min_q_shift ); /*Q(q_cldfb+min_q_shift)*/ + re2 = L_shl( RealBuffer_fx[2][0][l], min_q_shift ); /*Q(q_cldfb+min_q_shift)*/ + re3 = L_shl( RealBuffer_fx[3][0][l], min_q_shift ); /*Q(q_cldfb+min_q_shift)*/ + im1 = L_shl( ImagBuffer_fx[1][0][l], min_q_shift ); /*Q(q_cldfb+min_q_shift)*/ + im2 = L_shl( ImagBuffer_fx[2][0][l], min_q_shift ); /*Q(q_cldfb+min_q_shift)*/ + im3 = L_shl( ImagBuffer_fx[3][0][l], min_q_shift ); /*Q(q_cldfb+min_q_shift)*/ idx = i_mult( 3, Rmat_k[k] ); idx1 = add( l, i_mult( add( k, 1 ), num_freq_bands ) ); - *p_k_fx[k] = Madd_32_32( Madd_32_32( Mpy_32_32( p_Rmat_fx[add( idx, 1 )], re1 ), p_Rmat_fx[add( idx, 2 )], re2 ), p_Rmat_fx[idx], re3 ); + *p_k_fx[k] = Madd_32_32( Madd_32_32( Mpy_32_32( p_Rmat_fx[idx + 1], re1 ), p_Rmat_fx[idx + 2], re2 ), p_Rmat_fx[idx], re3 ); /*Q(30 + q_cldfb+min_q_shift-31)=>Q(q_cldfb+min_q_shift-1)*/ move32(); - *p_k_fx[k] = L_shl( *p_k_fx[k], Q1 ); // left shift is done to maintain constant Q factor for p_k_fx + *p_k_fx[k] = L_shl( *p_k_fx[k], Q1 ); // left shift is done to maintain constant Q factor for p_k_fx Q(q_cldfb+min_q_shift) move32(); - reference_power_fx[idx1] = Mpy_32_32( *p_k_fx[k], *p_k_fx[k] ); + reference_power_fx[idx1] = Mpy_32_32( *p_k_fx[k], *p_k_fx[k] ); // Q(2*(q_cldfb + min_q_shift)-31) move32(); p_k_fx[k]++; - *p_k_fx[k] = Madd_32_32( Madd_32_32( Mpy_32_32( p_Rmat_fx[add( idx, 1 )], im1 ), p_Rmat_fx[add( idx, 2 )], im2 ), p_Rmat_fx[idx], im3 ); + *p_k_fx[k] = Madd_32_32( Madd_32_32( Mpy_32_32( p_Rmat_fx[idx + 1], im1 ), p_Rmat_fx[idx + 2], im2 ), p_Rmat_fx[idx], im3 ); /*Q(q_cldfb+min_q_shift-1)*/ move32(); - *p_k_fx[k] = L_shl( *p_k_fx[k], Q1 ); // left shift is done to maintain constant Q factor + *p_k_fx[k] = L_shl( *p_k_fx[k], Q1 ); // left shift is done to maintain constant Q factor Q(q_cldfb+min_q_shift) move32(); - reference_power_fx[idx1] = Mpy_32_32( *p_k_fx[k], *p_k_fx[k] ); + reference_power_fx[idx1] = Mpy_32_32( *p_k_fx[k], *p_k_fx[k] ); // Q(2*(q_cldfb + min_q_shift)-31) move32(); p_k_fx[k]++; - reference_power_fx[l] = L_add( reference_power_fx[l], L_shr( reference_power_fx[idx1], 1 ) ); + reference_power_fx[l] = L_add( reference_power_fx[l], L_shr( reference_power_fx[idx1], 1 ) ); /*2*Q(q_cldfb+min_q_shift)-31-1*/ move32(); } @@ -2451,9 +2457,9 @@ void protoSignalComputation_shd_fx( FOR( k = 1; k < 4; k++ ) { - RealBuffer_fx[k][0][l] = L_shr( p_proto_direct_buffer_fx[i_mult( 2, add( i_mult( k, num_freq_bands ), l ) )], sub( *proto_direct_buffer_f_q, q_cldfb ) ); + RealBuffer_fx[k][0][l] = L_shr( p_proto_direct_buffer_fx[2 * ( k * num_freq_bands + l )], sub( *proto_direct_buffer_f_q, q_cldfb ) ); // proto_direct_buffer_f_q -> q_cldfb move32(); - ImagBuffer_fx[k][0][l] = L_shr( p_proto_direct_buffer_fx[add( i_mult( 2, add( i_mult( k, num_freq_bands ), l ) ), 1 )], sub( *proto_direct_buffer_f_q, q_cldfb ) ); + ImagBuffer_fx[k][0][l] = L_shr( p_proto_direct_buffer_fx[2 * ( k * num_freq_bands + l ) + 1], sub( *proto_direct_buffer_f_q, q_cldfb ) ); // proto_direct_buffer_f_q -> q_cldfb move32(); } } @@ -2465,17 +2471,17 @@ void protoSignalComputation_shd_fx( { FOR( l = 0; l < num_freq_bands; l++ ) { - p_proto_direct_buffer_fx[i_mult( 2, add( i_mult( k, num_freq_bands ), l ) )] = RealBuffer_fx[k][0][l]; + p_proto_direct_buffer_fx[2 * ( k * num_freq_bands + l )] = RealBuffer_fx[k][0][l]; // q_cldfb move32(); - p_proto_direct_buffer_fx[add( i_mult( 2, add( i_mult( k, num_freq_bands ), l ) ), 1 )] = ImagBuffer_fx[k][0][l]; + p_proto_direct_buffer_fx[2 * ( k * num_freq_bands + l ) + 1] = ImagBuffer_fx[k][0][l]; // q_cldfb move32(); - re1 = L_shl( RealBuffer_fx[k][0][l], min_q_shift ); - im1 = L_shl( ImagBuffer_fx[k][0][l], min_q_shift ); + re1 = L_shl( RealBuffer_fx[k][0][l], min_q_shift ); // q_cldfb+min_q_shift + im1 = L_shl( ImagBuffer_fx[k][0][l], min_q_shift ); // q_cldfb+min_q_shift - reference_power_fx[add( l, i_mult( add( k, 1 ), num_freq_bands ) )] = Madd_32_32( Mpy_32_32( re1, re1 ), im1, im1 ); + reference_power_fx[l + ( k + 1 ) * num_freq_bands] = Madd_32_32( Mpy_32_32( re1, re1 ), im1, im1 ); // 2*(q_cldfb+min_q_shift)-31 move32(); - reference_power_fx[l] = L_add( reference_power_fx[l], L_shr( reference_power_fx[add( l, i_mult( add( k, 1 ), num_freq_bands ) )], 1 ) ); + reference_power_fx[l] = L_add( reference_power_fx[l], L_shr( reference_power_fx[l + ( k + 1 ) * num_freq_bands], 1 ) ); // 2*(q_cldfb+min_q_shift)-31-1 move32(); } } @@ -2490,9 +2496,9 @@ void protoSignalComputation_shd_fx( { FOR( l = 0; l < num_freq_bands; l++ ) { - p_proto_direct_buffer_fx[i_mult( 2, add( i_mult( k, num_freq_bands ), l ) )] = RealBuffer_fx[k][0][l]; + p_proto_direct_buffer_fx[2 * ( k * num_freq_bands + l )] = RealBuffer_fx[k][0][l]; // q_cldfb move32(); - p_proto_direct_buffer_fx[add( i_mult( 2, add( i_mult( k, num_freq_bands ), l ) ), 1 )] = ImagBuffer_fx[k][0][l]; + p_proto_direct_buffer_fx[2 * ( k * num_freq_bands + l ) + 1] = ImagBuffer_fx[k][0][l]; // q_cldfb move32(); } } @@ -2500,7 +2506,7 @@ void protoSignalComputation_shd_fx( /*Copy direct to diffuse proto*/ - Copy32( p_proto_direct_buffer_fx, p_proto_diffuse_buffer_fx, i_mult( i_mult( 2, num_freq_bands ), s_min( num_outputs_diff, num_inputs ) ) ); + Copy32( p_proto_direct_buffer_fx, p_proto_diffuse_buffer_fx, i_mult( i_mult( 2, num_freq_bands ), s_min( num_outputs_diff, num_inputs ) ) ); /*proto_diffuse_buffer_f_q -> proto_direct_buffer_f_q*/ *proto_diffuse_buffer_f_q = *proto_direct_buffer_f_q; move16(); @@ -2509,9 +2515,9 @@ void protoSignalComputation_shd_fx( /* Add comfort noise addition (CNA) to diffuse proto only*/ FOR( l = 0; l < num_freq_bands; l++ ) { - p_proto_diffuse_buffer_fx[i_mult( 2, l )] = L_add( p_proto_diffuse_buffer_fx[i_mult( 2, l )], RealBuffer_fx[1][0][l] ); + p_proto_diffuse_buffer_fx[2 * l] = L_add( p_proto_diffuse_buffer_fx[2 * l], RealBuffer_fx[1][0][l] ); // q_cldfb move32(); - p_proto_diffuse_buffer_fx[add( i_mult( 2, l ), 1 )] = L_add( p_proto_diffuse_buffer_fx[add( i_mult( 2, l ), 1 )], ImagBuffer_fx[1][0][l] ); + p_proto_diffuse_buffer_fx[2 * l + 1] = L_add( p_proto_diffuse_buffer_fx[2 * l + 1], ImagBuffer_fx[1][0][l] ); // q_cldfb move32(); } } @@ -2684,15 +2690,15 @@ void protoSignalComputation_shd( #ifdef IVAS_FLOAT_FIXED void protoSignalComputation1_fx( - Word32 RealBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], - Word32 ImagBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], - Word32 *proto_frame_f_fx, + Word32 RealBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /*q_cldfb*/ + Word32 ImagBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /*q_cldfb*/ + Word32 *proto_frame_f_fx, /*proto_frame_f_q*/ Word16 *proto_frame_f_q, - Word32 *proto_direct_buffer_f_fx, + Word32 *proto_direct_buffer_f_fx, /*proto_direct_buffer_f_q*/ Word16 *proto_direct_buffer_f_q, - Word32 *reference_power_fx, + Word32 *reference_power_fx, /*reference_power_q*/ Word16 *reference_power_q, - Word32 *proto_power_smooth_fx, + Word32 *proto_power_smooth_fx, /*proto_power_smooth_q*/ Word16 *proto_power_smooth_q, const Word16 slot_index, const Word16 num_outputs_diff, @@ -2709,7 +2715,7 @@ void protoSignalComputation1_fx( q_shift = Q31; move16(); - p_proto_buffer_fx = proto_direct_buffer_f_fx + i_mult( slot_index, i_mult( 2, num_freq_bands ) ); + p_proto_buffer_fx = proto_direct_buffer_f_fx + ( slot_index * ( 2 * num_freq_bands ) ); /*proto_direct_buffer_f_q*/ /* calculate the maximum shift possible for the bufferS RealBuffer_fx and ImagBuffer_fx*/ q_shift = L_norm_arr( RealBuffer_fx[0][0], num_freq_bands ); @@ -2723,48 +2729,48 @@ void protoSignalComputation1_fx( q_shift = getScaleFactor32( proto_power_smooth_fx, num_freq_bands ); q_shift = sub( q_shift, find_guarded_bits_fx( 2 ) ); - Scale_sig32( proto_power_smooth_fx, num_freq_bands, q_shift ); + Scale_sig32( proto_power_smooth_fx, num_freq_bands, q_shift ); /*proto_power_smooth_q+q_shift*/ *proto_power_smooth_q = add( *proto_power_smooth_q, q_shift ); proto_power_smooth_fx_q = *proto_power_smooth_q; move16(); FOR( l = 0; l < num_freq_bands; l++ ) { - re = L_shl( RealBuffer_fx[0][0][l], min_q_shift ); - im = L_shl( ImagBuffer_fx[0][0][l], min_q_shift ); + re = L_shl( RealBuffer_fx[0][0][l], min_q_shift ); // q_cldfb+min_q_shift + im = L_shl( ImagBuffer_fx[0][0][l], min_q_shift ); // q_cldfb+min_q_shift - reference_power_fx[l] = Madd_32_32( Mpy_32_32( re, re ), im, im ); + reference_power_fx[l] = Madd_32_32( Mpy_32_32( re, re ), im, im ); // 2*(q_cldfb+min_q_shift)-31 move32(); *reference_power_q = sub( add( add( q_cldfb, min_q_shift ), add( q_cldfb, min_q_shift ) ), 31 ); move16(); IF( LT_16( *reference_power_q, *proto_power_smooth_q ) ) { - proto_power_smooth_fx[l] = L_add( L_shr( proto_power_smooth_fx[l], sub( *proto_power_smooth_q, *reference_power_q ) ), reference_power_fx[l] ); + proto_power_smooth_fx[l] = L_add( L_shr( proto_power_smooth_fx[l], sub( *proto_power_smooth_q, *reference_power_q ) ), reference_power_fx[l] ); // reference_power_q move32(); proto_power_smooth_fx_q = *reference_power_q; move16(); } ELSE { - proto_power_smooth_fx[l] = L_add( proto_power_smooth_fx[l], L_shr( reference_power_fx[l], sub( *reference_power_q, *proto_power_smooth_q ) ) ); + proto_power_smooth_fx[l] = L_add( proto_power_smooth_fx[l], L_shr( reference_power_fx[l], sub( *reference_power_q, *proto_power_smooth_q ) ) ); // proto_power_smooth_q move32(); proto_power_smooth_fx_q = *proto_power_smooth_q; move16(); } - idx = i_mult( 2, l ); - p_proto_buffer_fx[idx] = RealBuffer_fx[0][0][l]; + idx = 2 * l; + p_proto_buffer_fx[idx] = RealBuffer_fx[0][0][l]; // q_cldfb move32(); - p_proto_buffer_fx[add( idx, 1 )] = ImagBuffer_fx[0][0][l]; + p_proto_buffer_fx[idx + 1] = ImagBuffer_fx[0][0][l]; // q_cldfb move32(); FOR( k = 0; k < num_outputs_diff; k++ ) { idx = add( i_mult( i_mult( 2, k ), num_freq_bands ), i_mult( 2, l ) ); - proto_frame_f_fx[idx] = RealBuffer_fx[0][0][l]; + proto_frame_f_fx[idx] = RealBuffer_fx[0][0][l]; // q_cldfb move32(); - proto_frame_f_fx[add( idx, 1 )] = ImagBuffer_fx[0][0][l]; + proto_frame_f_fx[idx + 1] = ImagBuffer_fx[0][0][l]; // q_cldfb move32(); } } @@ -2822,15 +2828,15 @@ void protoSignalComputation1( #ifdef IVAS_FLOAT_FIXED void protoSignalComputation2_fx( - Word32 RealBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], - Word32 ImagBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], - Word32 *proto_frame_f_fx, + Word32 RealBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /*q_cldfb*/ + Word32 ImagBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /*q_cldfb*/ + Word32 *proto_frame_f_fx, /*q_proto_frame_f*/ Word16 *q_proto_frame_f, - Word32 *proto_direct_buffer_f_fx, + Word32 *proto_direct_buffer_f_fx, /*q_proto_direct_buffer_f*/ Word16 *q_proto_direct_buffer_f, - Word32 *reference_power_fx, + Word32 *reference_power_fx, /*q_reference_power*/ Word16 *q_reference_power, - Word32 *proto_power_smooth_fx, + Word32 *proto_power_smooth_fx, /*q_proto_power_smooth*/ Word16 *q_proto_power_smooth, const Word16 isloudspeaker, const Word16 slot_index, @@ -2895,32 +2901,32 @@ void protoSignalComputation2_fx( IF( isloudspeaker ) { q_shift = getScaleFactor32( proto_power_smooth_fx, i_mult( 3, num_freq_bands ) ); - scale_sig32( proto_power_smooth_fx, i_mult( 3, num_freq_bands ), sub( q_shift, 1 ) ); + scale_sig32( proto_power_smooth_fx, i_mult( 3, num_freq_bands ), sub( q_shift, 1 ) ); // q_proto_power_smooth+q_shift-1 } ELSE { q_shift = getScaleFactor32( proto_power_smooth_fx, i_mult( 2, num_freq_bands ) ); - scale_sig32( proto_power_smooth_fx, i_mult( 2, num_freq_bands ), sub( q_shift, 1 ) ); + scale_sig32( proto_power_smooth_fx, i_mult( 2, num_freq_bands ), sub( q_shift, 1 ) ); // q_proto_power_smooth+q_shift-1 } *q_proto_power_smooth = add( *q_proto_power_smooth, sub( q_shift, 1 ) ); move16(); IF( isloudspeaker ) { - p_proto_buffer_fx = proto_direct_buffer_f_fx + i_mult( i_mult( i_mult( slot_index, 2 ), num_freq_bands ), 3 ); + p_proto_buffer_fx = proto_direct_buffer_f_fx + i_mult( i_mult( i_mult( slot_index, 2 ), num_freq_bands ), 3 ); // q_proto_direct_buffer_f q_temp = sub( add( add( q_cldfb, min_q_shift ), add( q_cldfb, min_q_shift ) ), 31 ); move16(); FOR( l = 0; l < num_freq_bands; l++ ) { - re1 = L_shl( RealBuffer_fx[0][0][l], min_q_shift ); - im1 = L_shl( ImagBuffer_fx[0][0][l], min_q_shift ); - re2 = L_shl( RealBuffer_fx[1][0][l], min_q_shift ); - im2 = L_shl( ImagBuffer_fx[1][0][l], min_q_shift ); + re1 = L_shl( RealBuffer_fx[0][0][l], min_q_shift ); // q_cldfb+min_q_shift + im1 = L_shl( ImagBuffer_fx[0][0][l], min_q_shift ); // q_cldfb+min_q_shift + re2 = L_shl( RealBuffer_fx[1][0][l], min_q_shift ); // q_cldfb+min_q_shift + im2 = L_shl( ImagBuffer_fx[1][0][l], min_q_shift ); // q_cldfb+min_q_shift - Real_aux_fx = L_add( re1, re2 ); - Imag_aux_fx = L_add( im1, im2 ); + Real_aux_fx = L_add( re1, re2 ); // q_cldfb+min_q_shift + Imag_aux_fx = L_add( im1, im2 ); // q_cldfb+min_q_shift // Left_power_fx = Madd_32_32( Mpy_32_32( re1, re1 ), im1, im1 ); W_tmp1 = W_add( W_mult0_32_32( re1, re1 ), W_mult0_32_32( im1, im1 ) ); // 2*(q_cldfb+min_q_shift) @@ -2932,77 +2938,77 @@ void protoSignalComputation2_fx( reference_power_64fx[l] = W_add( W_tmp1, W_tmp2 ); // 2*(q_cldfb+min_q_shift) move64(); - temp = Madd_32_32( Mpy_32_32( Real_aux_fx, Real_aux_fx ), Imag_aux_fx, Imag_aux_fx ); + temp = Madd_32_32( Mpy_32_32( Real_aux_fx, Real_aux_fx ), Imag_aux_fx, Imag_aux_fx ); // 2*(q_cldfb+min_q_shift)-31 IF( LT_16( q_temp, *q_proto_power_smooth ) ) { - proto_power_smooth_fx[l] = L_add( L_shr( proto_power_smooth_fx[l], sub( *q_proto_power_smooth, q_temp ) ), temp ); + proto_power_smooth_fx[l] = L_add( L_shr( proto_power_smooth_fx[l], sub( *q_proto_power_smooth, q_temp ) ), temp ); // q_temp move32(); } ELSE { - proto_power_smooth_fx[l] = L_add( proto_power_smooth_fx[l], L_shr( temp, sub( q_temp, *q_proto_power_smooth ) ) ); + proto_power_smooth_fx[l] = L_add( proto_power_smooth_fx[l], L_shr( temp, sub( q_temp, *q_proto_power_smooth ) ) ); // q_proto_power_smooth move32(); } - p_proto_buffer_fx[i_mult( 2, l )] = Real_aux_fx; + p_proto_buffer_fx[2 * l] = Real_aux_fx; // q_cldfb+min_q_shift move32(); - p_proto_buffer_fx[add( i_mult( 2, l ), 1 )] = Imag_aux_fx; + p_proto_buffer_fx[2 * l + 1] = Imag_aux_fx; // q_cldfb+min_q_shift move32(); - temp = Madd_32_32( Mpy_32_32( re1, re1 ), im1, im1 ); + temp = Madd_32_32( Mpy_32_32( re1, re1 ), im1, im1 ); // 2*(q_cldfb+min_q_shift)-31 IF( LT_16( q_temp, *q_proto_power_smooth ) ) { - proto_power_smooth_fx[add( l, num_freq_bands )] = L_add( L_shr( proto_power_smooth_fx[add( l, num_freq_bands )], sub( *q_proto_power_smooth, q_temp ) ), temp ); + proto_power_smooth_fx[l + num_freq_bands] = L_add( L_shr( proto_power_smooth_fx[l + num_freq_bands], sub( *q_proto_power_smooth, q_temp ) ), temp ); // q_temp move32(); } ELSE { - proto_power_smooth_fx[add( l, num_freq_bands )] = L_add( proto_power_smooth_fx[add( l, num_freq_bands )], L_shr( temp, sub( q_temp, *q_proto_power_smooth ) ) ); + proto_power_smooth_fx[l + num_freq_bands] = L_add( proto_power_smooth_fx[l + num_freq_bands], L_shr( temp, sub( q_temp, *q_proto_power_smooth ) ) ); // q_proto_power_smooth move32(); } - p_proto_buffer_fx[i_mult( 2, add( num_freq_bands, l ) )] = re1; + p_proto_buffer_fx[2 * ( num_freq_bands + l )] = re1; // q_cldfb+min_q_shift move32(); - p_proto_buffer_fx[add( i_mult( 2, add( num_freq_bands, l ) ), 1 )] = im1; + p_proto_buffer_fx[2 * ( num_freq_bands + l ) + 1] = im1; // q_cldfb+min_q_shift move32(); - temp = Madd_32_32( Mpy_32_32( re2, re2 ), im2, im2 ); + temp = Madd_32_32( Mpy_32_32( re2, re2 ), im2, im2 ); // 2*(q_cldfb+min_q_shift)-31 IF( LT_16( q_temp, *q_proto_power_smooth ) ) { - proto_power_smooth_fx[add( l, i_mult( 2, num_freq_bands ) )] = L_add( L_shr( proto_power_smooth_fx[add( l, i_mult( 2, num_freq_bands ) )], sub( *q_proto_power_smooth, q_temp ) ), temp ); + proto_power_smooth_fx[l + ( 2 * num_freq_bands )] = L_add( L_shr( proto_power_smooth_fx[l + ( 2 * num_freq_bands )], sub( *q_proto_power_smooth, q_temp ) ), temp ); // q_temp move32(); } ELSE { - proto_power_smooth_fx[add( l, i_mult( 2, num_freq_bands ) )] = L_add( proto_power_smooth_fx[add( l, i_mult( 2, num_freq_bands ) )], L_shr( temp, sub( q_temp, *q_proto_power_smooth ) ) ); + proto_power_smooth_fx[l + ( 2 * num_freq_bands )] = L_add( proto_power_smooth_fx[l + ( 2 * num_freq_bands )], L_shr( temp, sub( q_temp, *q_proto_power_smooth ) ) ); // q_proto_power_smooth move32(); } - p_proto_buffer_fx[add( i_mult( 4, num_freq_bands ), i_mult( 2, l ) )] = re2; + p_proto_buffer_fx[4 * num_freq_bands + 2 * l] = re2; // q_cldfb+min_q_shift move32(); - p_proto_buffer_fx[add( add( i_mult( 4, num_freq_bands ), i_mult( 2, l ) ), 1 )] = im2; + p_proto_buffer_fx[4 * num_freq_bands + 2 * l + 1] = im2; // q_cldfb+min_q_shift move32(); - proto_frame_f_fx[i_mult( 2, l )] = Real_aux_fx; + proto_frame_f_fx[2 * l] = Real_aux_fx; // q_cldfb+min_q_shift move32(); - proto_frame_f_fx[add( i_mult( 2, l ), 1 )] = Imag_aux_fx; + proto_frame_f_fx[2 * l + 1] = Imag_aux_fx; // q_cldfb+min_q_shift move32(); - proto_frame_f_fx[add( i_mult( 2, num_freq_bands ), i_mult( 2, l ) )] = re1; + proto_frame_f_fx[2 * num_freq_bands + 2 * l] = re1; // q_cldfb+min_q_shift move32(); - proto_frame_f_fx[add( add( i_mult( 2, num_freq_bands ), i_mult( 2, l ) ), 1 )] = im1; + proto_frame_f_fx[2 * num_freq_bands + 2 * l + 1] = im1; // q_cldfb+min_q_shift move32(); - proto_frame_f_fx[add( i_mult( 4, num_freq_bands ), i_mult( 2, l ) )] = re2; + proto_frame_f_fx[4 * num_freq_bands + 2 * l] = re2; // q_cldfb+min_q_shift move32(); - proto_frame_f_fx[add( add( i_mult( 4, num_freq_bands ), i_mult( 2, l ) ), 1 )] = im2; + proto_frame_f_fx[4 * num_freq_bands + 2 * l + 1] = im2; // q_cldfb+min_q_shift move32(); } } ELSE IF( stereo_type_detect != NULL ) { - p_proto_buffer_fx = proto_direct_buffer_f_fx + i_mult( i_mult( i_mult( slot_index, 2 ), num_freq_bands ), 2 ); + p_proto_buffer_fx = proto_direct_buffer_f_fx + ( slot_index * 4 * num_freq_bands ); // q_proto_direct_buffer_f left_bb_power_fx = 0; move32(); @@ -3025,7 +3031,7 @@ void protoSignalComputation2_fx( a_fx = 21474836; /*0.01 in Q31*/ /* Temporal smoothing coefficient */ move32(); - b_fx = L_sub( ONE_IN_Q31, a_fx ); /* Temporal smoothing coefficient */ + b_fx = L_sub( ONE_IN_Q31, a_fx ); /* Temporal smoothing coefficient q31*/ // a2_fx = 214748365; /*0.1 in Q31*/ /* Temporal smoothing coefficient */ // b2_fx = L_sub( ONE_IN_Q31, a2_fx ); /* Temporal smoothing coefficient */ @@ -3052,14 +3058,14 @@ void protoSignalComputation2_fx( FOR( l = 0; l < num_freq_bands; l++ ) { - re1 = L_shl( RealBuffer_fx[0][0][l], min_q_shift ); - im1 = L_shl( ImagBuffer_fx[0][0][l], min_q_shift ); - re2 = L_shl( RealBuffer_fx[1][0][l], min_q_shift ); - im2 = L_shl( ImagBuffer_fx[1][0][l], min_q_shift ); + re1 = L_shl( RealBuffer_fx[0][0][l], min_q_shift ); // q_cldfb+min_q_shift + im1 = L_shl( ImagBuffer_fx[0][0][l], min_q_shift ); // q_cldfb+min_q_shift + re2 = L_shl( RealBuffer_fx[1][0][l], min_q_shift ); // q_cldfb+min_q_shift + im2 = L_shl( ImagBuffer_fx[1][0][l], min_q_shift ); // q_cldfb+min_q_shift /* Compute sum signal */ - Real_aux_fx = L_add( re1, re2 ); - Imag_aux_fx = L_add( im1, im2 ); + Real_aux_fx = L_add( re1, re2 ); // q_cldfb+min_q_shift + Imag_aux_fx = L_add( im1, im2 ); // q_cldfb+min_q_shift /* Compute reference power */ // Left_power_fx = Madd_32_32( Mpy_32_32( re1, re1 ), im1, im1 ); @@ -3073,82 +3079,82 @@ void protoSignalComputation2_fx( reference_power_64fx[l] = W_add( W_tmp1, W_tmp2 ); // 2*(q_cldfb+min_q_shift) move64(); - left_bb_power_fx = L_add( left_bb_power_fx, Left_power_fx ); - right_bb_power_fx = L_add( right_bb_power_fx, Right_power_fx ); + left_bb_power_fx = L_add( left_bb_power_fx, Left_power_fx ); // 2*(q_cldfb+min_q_shift) -31 + right_bb_power_fx = L_add( right_bb_power_fx, Right_power_fx ); // 2*(q_cldfb+min_q_shift) -31 // total_bb_power_fx = L_add( total_bb_power_fx, reference_power_fx[l] ); - total_bb_power_fx = L_add( total_bb_power_fx, W_extract_l( W_shr( reference_power_64fx[l], 31 ) ) ); + total_bb_power_fx = L_add( total_bb_power_fx, W_extract_l( W_shr( reference_power_64fx[l], 31 ) ) ); // 2*(q_cldfb+min_q_shift) -31 IF( GT_16( l, MASA_HI_FREQ_START_BIN ) ) { - left_hi_power_fx = L_add( left_hi_power_fx, Left_power_fx ); - right_hi_power_fx = L_add( right_hi_power_fx, Right_power_fx ); + left_hi_power_fx = L_add( left_hi_power_fx, Left_power_fx ); // 2*(q_cldfb+min_q_shift) -31 + right_hi_power_fx = L_add( right_hi_power_fx, Right_power_fx ); // 2*(q_cldfb+min_q_shift) -31 // total_hi_power_fx = L_add( total_hi_power_fx, reference_power_fx[l] ); - total_hi_power_fx = L_add( total_hi_power_fx, W_extract_l( W_shr( reference_power_64fx[l], 31 ) ) ); + total_hi_power_fx = L_add( total_hi_power_fx, W_extract_l( W_shr( reference_power_64fx[l], 31 ) ) ); // 2*(q_cldfb+min_q_shift) -31 } IF( LT_16( l, s_min( num_freq_bands, MASA_SUM_FREQ_RANGE_BINS ) ) ) { - re_aux = L_shl( Real_aux_fx, sub( temp_q_shift, min_q_shift ) ); - im_aux = L_shl( Imag_aux_fx, sub( temp_q_shift, min_q_shift ) ); + re_aux = L_shl( Real_aux_fx, sub( temp_q_shift, min_q_shift ) ); // q_cldfb+temp_q_shift + im_aux = L_shl( Imag_aux_fx, sub( temp_q_shift, min_q_shift ) ); // q_cldfb+temp_q_shift - sum_power_fx = Madd_32_32( Mpy_32_32( re_aux, re_aux ), im_aux, im_aux ); - temp = Mpy_32_32( a_fx, sum_power_fx ); + sum_power_fx = Madd_32_32( Mpy_32_32( re_aux, re_aux ), im_aux, im_aux ); // 2*(q_cldfb+temp_q_shift)-31 + temp = Mpy_32_32( a_fx, sum_power_fx ); // 2*(q_cldfb+temp_q_shift)-31 IF( LT_16( q_temp2, stereo_type_detect->q_sum_power ) ) { - stereo_type_detect->sum_power_fx[l] = L_add( temp, L_shr( Mpy_32_32( b_fx, stereo_type_detect->sum_power_fx[l] ), sub( stereo_type_detect->q_sum_power, q_temp2 ) ) ); + stereo_type_detect->sum_power_fx[l] = L_add( temp, L_shr( Mpy_32_32( b_fx, stereo_type_detect->sum_power_fx[l] ), sub( stereo_type_detect->q_sum_power, q_temp2 ) ) ); // q_temp2 move32(); } ELSE { - stereo_type_detect->sum_power_fx[l] = L_add( L_shr( temp, sub( q_temp2, stereo_type_detect->q_sum_power ) ), Mpy_32_32( b_fx, stereo_type_detect->sum_power_fx[l] ) ); + stereo_type_detect->sum_power_fx[l] = L_add( L_shr( temp, sub( q_temp2, stereo_type_detect->q_sum_power ) ), Mpy_32_32( b_fx, stereo_type_detect->sum_power_fx[l] ) ); // stereo_type_detect->q_sum_power move32(); } - temp = Mpy_32_32( a_fx, W_extract_l( W_shr( reference_power_64fx[l], 31 ) ) ); + temp = Mpy_32_32( a_fx, W_extract_l( W_shr( reference_power_64fx[l], 31 ) ) ); // 2*(q_cldfb+min_q_shift) -31 IF( LT_16( q_temp, stereo_type_detect->q_total_power ) ) { - stereo_type_detect->total_power_fx[l] = L_add( temp, L_shr( Mpy_32_32( b_fx, stereo_type_detect->total_power_fx[l] ), sub( stereo_type_detect->q_total_power, q_temp ) ) ); + stereo_type_detect->total_power_fx[l] = L_add( temp, L_shr( Mpy_32_32( b_fx, stereo_type_detect->total_power_fx[l] ), sub( stereo_type_detect->q_total_power, q_temp ) ) ); // q_temp move32(); } ELSE { - stereo_type_detect->total_power_fx[l] = L_add( L_shr( temp, sub( q_temp, stereo_type_detect->q_total_power ) ), Mpy_32_32( b_fx, stereo_type_detect->total_power_fx[l] ) ); + stereo_type_detect->total_power_fx[l] = L_add( L_shr( temp, sub( q_temp, stereo_type_detect->q_total_power ) ), Mpy_32_32( b_fx, stereo_type_detect->total_power_fx[l] ) ); // stereo_type_detect->q_total_power move32(); } test(); IF( ( stereo_type_detect->sum_power_fx[l] == 0 ) && ( stereo_type_detect->total_power_fx[l] == 0 ) ) { - sum_total_ratio_fx[l] = MAX_16; + sum_total_ratio_fx[l] = MAX_16; // q15 move32(); } ELSE { - sum_total_ratio_fx[l] = BASOP_Util_Divide3232_Scale( stereo_type_detect->sum_power_fx[l], L_add( stereo_type_detect->total_power_fx[l], EPSILON_FX ), &exp ); + sum_total_ratio_fx[l] = BASOP_Util_Divide3232_Scale( stereo_type_detect->sum_power_fx[l], L_add( stereo_type_detect->total_power_fx[l], EPSILON_FX ), &exp ); // 15-(exp+s_min( stereo_type_detect->q_total_power, q_temp )-s_min( stereo_type_detect->q_sum_power, q_temp2 )) move32(); q_sum_total_ratio = add( sub( 15, exp ), sub( s_min( stereo_type_detect->q_sum_power, q_temp2 ), s_min( stereo_type_detect->q_total_power, q_temp ) ) ); - sum_total_ratio_fx[l] = L_shl( sum_total_ratio_fx[l], sub( Q15, q_sum_total_ratio ) ); + sum_total_ratio_fx[l] = L_shl( sum_total_ratio_fx[l], sub( Q15, q_sum_total_ratio ) ); // q15 move32(); } } IF( l == 0 ) { - RealSubtract_fx = L_sub( re1, re2 ); - ImagSubtract_fx = L_sub( im1, im2 ); + RealSubtract_fx = L_sub( re1, re2 ); // q_cldfb+min_q_shift + ImagSubtract_fx = L_sub( im1, im2 ); // q_cldfb+min_q_shift - temp = Madd_32_32( Mpy_32_32( RealSubtract_fx, RealSubtract_fx ), ImagSubtract_fx, ImagSubtract_fx ); + temp = Madd_32_32( Mpy_32_32( RealSubtract_fx, RealSubtract_fx ), ImagSubtract_fx, ImagSubtract_fx ); // 2*(q_cldfb+min_q_shift)-31 IF( LT_16( q_temp, stereo_type_detect->q_subtract_power_y ) ) { - stereo_type_detect->subtract_power_y_fx = L_add( L_shr( stereo_type_detect->subtract_power_y_fx, sub( stereo_type_detect->q_subtract_power_y, q_temp ) ), temp ); + stereo_type_detect->subtract_power_y_fx = L_add( L_shr( stereo_type_detect->subtract_power_y_fx, sub( stereo_type_detect->q_subtract_power_y, q_temp ) ), temp ); // q_temp move32(); stereo_type_detect->q_subtract_power_y = q_temp; move16(); } ELSE { - stereo_type_detect->subtract_power_y_fx = L_add( stereo_type_detect->subtract_power_y_fx, L_shr( temp, sub( q_temp, stereo_type_detect->q_subtract_power_y ) ) ); + stereo_type_detect->subtract_power_y_fx = L_add( stereo_type_detect->subtract_power_y_fx, L_shr( temp, sub( q_temp, stereo_type_detect->q_subtract_power_y ) ) ); // stereo_type_detect->q_subtract_power_y move32(); } } @@ -3160,46 +3166,46 @@ void protoSignalComputation2_fx( { IF( L_or( LT_16( l, sub( dipole_freq_range[1], 1 ) ), GE_16( l, MASA_SUM_PROTO_START_BIN ) ) ) { - Real_aux_fx = Madd_32_16( Mpy_32_16_1( Real_aux_fx, shr( interpolatorSpaced_fx, 1 ) ), Real_aux_fx, interpolatorDmx_fx ); - Imag_aux_fx = Madd_32_16( Mpy_32_16_1( Imag_aux_fx, shr( interpolatorSpaced_fx, 1 ) ), Imag_aux_fx, interpolatorDmx_fx ); + Real_aux_fx = Madd_32_16( Mpy_32_16_1( Real_aux_fx, shr( interpolatorSpaced_fx, 1 ) ), Real_aux_fx, interpolatorDmx_fx ); // q_cldfb+min_q_shift + Imag_aux_fx = Madd_32_16( Mpy_32_16_1( Imag_aux_fx, shr( interpolatorSpaced_fx, 1 ) ), Imag_aux_fx, interpolatorDmx_fx ); // q_cldfb+min_q_shift - temp = Madd_32_32( Mpy_32_32( Real_aux_fx, Real_aux_fx ), Imag_aux_fx, Imag_aux_fx ); + temp = Madd_32_32( Mpy_32_32( Real_aux_fx, Real_aux_fx ), Imag_aux_fx, Imag_aux_fx ); // 2*(q_cldfb+min_q_shift) -31 IF( LT_16( q_temp, *q_proto_power_smooth ) ) { - proto_power_smooth_fx[l] = L_add( L_shr( proto_power_smooth_fx[l], sub( *q_proto_power_smooth, q_temp ) ), temp ); + proto_power_smooth_fx[l] = L_add( L_shr( proto_power_smooth_fx[l], sub( *q_proto_power_smooth, q_temp ) ), temp ); // q_temp move32(); } ELSE { - proto_power_smooth_fx[l] = L_add( proto_power_smooth_fx[l], L_shr( temp, sub( q_temp, *q_proto_power_smooth ) ) ); + proto_power_smooth_fx[l] = L_add( proto_power_smooth_fx[l], L_shr( temp, sub( q_temp, *q_proto_power_smooth ) ) ); // q_proto_power_smooth move32(); } - p_proto_buffer_fx[2 * l] = Real_aux_fx; + p_proto_buffer_fx[2 * l] = Real_aux_fx; // q_cldfb+min_q_shift move32(); - p_proto_buffer_fx[add( 2 * l, 1 )] = Imag_aux_fx; + p_proto_buffer_fx[2 * l + 1] = Imag_aux_fx; // q_cldfb+min_q_shift move32(); } ELSE { - tempSpaced_fx = Madd_32_32( Mpy_32_32( re1, re1 ), im1, im1 ); - tempDmx_fx = Madd_32_32( Mpy_32_32( Real_aux_fx, Real_aux_fx ), Imag_aux_fx, Imag_aux_fx ); + tempSpaced_fx = Madd_32_32( Mpy_32_32( re1, re1 ), im1, im1 ); // 2*(q_cldfb+min_q_shift)-31 + tempDmx_fx = Madd_32_32( Mpy_32_32( Real_aux_fx, Real_aux_fx ), Imag_aux_fx, Imag_aux_fx ); // 2*(q_cldfb+min_q_shift)-31 - temp = Madd_32_16( Mpy_32_16_1( tempSpaced_fx, interpolatorSpaced_fx ), tempDmx_fx, interpolatorDmx_fx ); + temp = Madd_32_16( Mpy_32_16_1( tempSpaced_fx, interpolatorSpaced_fx ), tempDmx_fx, interpolatorDmx_fx ); // 2*(q_cldfb+min_q_shift)-31 IF( LT_16( q_temp, *q_proto_power_smooth ) ) { - proto_power_smooth_fx[l] = L_add( L_shr( proto_power_smooth_fx[l], sub( *q_proto_power_smooth, q_temp ) ), temp ); + proto_power_smooth_fx[l] = L_add( L_shr( proto_power_smooth_fx[l], sub( *q_proto_power_smooth, q_temp ) ), temp ); // q_temp move32(); } ELSE { - proto_power_smooth_fx[l] = L_add( proto_power_smooth_fx[l], L_shr( temp, sub( q_temp, *q_proto_power_smooth ) ) ); + proto_power_smooth_fx[l] = L_add( proto_power_smooth_fx[l], L_shr( temp, sub( q_temp, *q_proto_power_smooth ) ) ); // q_proto_power_smooth move32(); } - p_proto_buffer_fx[2 * l] = Madd_32_16( Mpy_32_16_1( re1, interpolatorSpaced_fx ), Real_aux_fx, interpolatorDmx_fx ); + p_proto_buffer_fx[2 * l] = Madd_32_16( Mpy_32_16_1( re1, interpolatorSpaced_fx ), Real_aux_fx, interpolatorDmx_fx ); // q_cldfb+min_q_shift move32(); - p_proto_buffer_fx[add( 2 * l, 1 )] = Madd_32_16( Mpy_32_16_1( im1, interpolatorSpaced_fx ), Imag_aux_fx, interpolatorDmx_fx ); + p_proto_buffer_fx[2 * l + 1] = Madd_32_16( Mpy_32_16_1( im1, interpolatorSpaced_fx ), Imag_aux_fx, interpolatorDmx_fx ); // q_cldfb+min_q_shift move32(); } } @@ -3207,62 +3213,62 @@ void protoSignalComputation2_fx( { IF( L_or( LT_16( l, sub( dipole_freq_range[1], 1 ) ), GE_16( l, MASA_SUM_PROTO_START_BIN ) ) ) { - Real_aux_fx = L_shr( Real_aux_fx, 1 ); - Imag_aux_fx = L_shr( Imag_aux_fx, 1 ); - temp = Madd_32_32( Mpy_32_32( Real_aux_fx, Real_aux_fx ), Imag_aux_fx, Imag_aux_fx ); + Real_aux_fx = L_shr( Real_aux_fx, 1 ); // q_cldfb+min_q_shift + Imag_aux_fx = L_shr( Imag_aux_fx, 1 ); // q_cldfb+min_q_shift + temp = Madd_32_32( Mpy_32_32( Real_aux_fx, Real_aux_fx ), Imag_aux_fx, Imag_aux_fx ); // 2*(q_cldfb+min_q_shift)-31 IF( LT_16( q_temp, *q_proto_power_smooth ) ) { - proto_power_smooth_fx[l] = L_add( L_shr( proto_power_smooth_fx[l], sub( *q_proto_power_smooth, q_temp ) ), temp ); + proto_power_smooth_fx[l] = L_add( L_shr( proto_power_smooth_fx[l], sub( *q_proto_power_smooth, q_temp ) ), temp ); // q_temp move32(); } ELSE { - proto_power_smooth_fx[l] = L_add( proto_power_smooth_fx[l], L_shr( temp, sub( q_temp, *q_proto_power_smooth ) ) ); + proto_power_smooth_fx[l] = L_add( proto_power_smooth_fx[l], L_shr( temp, sub( q_temp, *q_proto_power_smooth ) ) ); // q_proto_power_smooth move32(); } - p_proto_buffer_fx[2 * l] = Real_aux_fx; + p_proto_buffer_fx[2 * l] = Real_aux_fx; // q_cldfb+min_q_shift move32(); - p_proto_buffer_fx[add( 2 * l, 1 )] = Imag_aux_fx; + p_proto_buffer_fx[2 * l + 1] = Imag_aux_fx; // q_cldfb+min_q_shift move32(); } ELSE { - temp = Madd_32_32( Mpy_32_32( re1, re1 ), im1, im1 ); + temp = Madd_32_32( Mpy_32_32( re1, re1 ), im1, im1 ); // 2*(q_cldfb+min_q_shift)-31 IF( LT_16( q_temp, *q_proto_power_smooth ) ) { - proto_power_smooth_fx[l] = L_add( L_shr( proto_power_smooth_fx[l], sub( *q_proto_power_smooth, q_temp ) ), temp ); + proto_power_smooth_fx[l] = L_add( L_shr( proto_power_smooth_fx[l], sub( *q_proto_power_smooth, q_temp ) ), temp ); // q_temp move32(); } ELSE { - proto_power_smooth_fx[l] = L_add( proto_power_smooth_fx[l], L_shr( temp, sub( q_temp, *q_proto_power_smooth ) ) ); + proto_power_smooth_fx[l] = L_add( proto_power_smooth_fx[l], L_shr( temp, sub( q_temp, *q_proto_power_smooth ) ) ); // q_proto_power_smooth move32(); } - p_proto_buffer_fx[2 * l] = re1; + p_proto_buffer_fx[2 * l] = re1; // q_cldfb+min_q_shift move32(); - p_proto_buffer_fx[add( 2 * l, 1 )] = im1; + p_proto_buffer_fx[2 * l + 1] = im1; // q_cldfb+min_q_shift move32(); } } ELSE { - temp = Madd_32_32( Mpy_32_32( Real_aux_fx, Real_aux_fx ), Imag_aux_fx, Imag_aux_fx ); + temp = Madd_32_32( Mpy_32_32( Real_aux_fx, Real_aux_fx ), Imag_aux_fx, Imag_aux_fx ); // 2*(q_cldfb+min_q_shift)-31 IF( LT_16( q_temp, *q_proto_power_smooth ) ) { - proto_power_smooth_fx[l] = L_add( L_shr( proto_power_smooth_fx[l], sub( *q_proto_power_smooth, q_temp ) ), temp ); + proto_power_smooth_fx[l] = L_add( L_shr( proto_power_smooth_fx[l], sub( *q_proto_power_smooth, q_temp ) ), temp ); // q_temp move32(); } ELSE { - proto_power_smooth_fx[l] = L_add( proto_power_smooth_fx[l], L_shr( temp, sub( q_temp, *q_proto_power_smooth ) ) ); + proto_power_smooth_fx[l] = L_add( proto_power_smooth_fx[l], L_shr( temp, sub( q_temp, *q_proto_power_smooth ) ) ); // q_proto_power_smooth move32(); } - p_proto_buffer_fx[2 * l] = Real_aux_fx; + p_proto_buffer_fx[2 * l] = Real_aux_fx; // q_cldfb+min_q_shift move32(); - p_proto_buffer_fx[add( 2 * l, 1 )] = Imag_aux_fx; + p_proto_buffer_fx[2 * l + 1] = Imag_aux_fx; // q_cldfb+min_q_shift move32(); } @@ -3271,35 +3277,35 @@ void protoSignalComputation2_fx( { IF( LT_16( l, dipole_freq_range[0] ) ) { - p_proto_buffer_fx[i_mult( 2, add( num_freq_bands, l ) )] = Madd_32_16( Mpy_32_16_1( p_proto_buffer_fx[2 * l], interpolatorSpaced_fx ), L_sub( re1, re2 ), interpolatorDmx_fx ); + p_proto_buffer_fx[2 * ( num_freq_bands + l )] = Madd_32_16( Mpy_32_16_1( p_proto_buffer_fx[2 * l], interpolatorSpaced_fx ), L_sub( re1, re2 ), interpolatorDmx_fx ); // q_cldfb+min_q_shift move32(); - p_proto_buffer_fx[add( i_mult( 2, add( num_freq_bands, l ) ), 1 )] = Madd_32_16( Mpy_32_16_1( p_proto_buffer_fx[add( 2 * l, 1 )], interpolatorSpaced_fx ), L_sub( im1, im2 ), interpolatorDmx_fx ); + p_proto_buffer_fx[2 * ( num_freq_bands + l ) + 1] = Madd_32_16( Mpy_32_16_1( p_proto_buffer_fx[2 * l + 1], interpolatorSpaced_fx ), L_sub( im1, im2 ), interpolatorDmx_fx ); // q_cldfb+min_q_shift move32(); } ELSE IF( LT_16( l, dipole_freq_range[1] ) ) { - p_proto_buffer_fx[i_mult( 2, add( num_freq_bands, l ) )] = Madd_32_16( Mpy_32_16_1( L_sub( im1, im2 ), interpolatorSpaced_fx ), L_sub( re1, re2 ), interpolatorDmx_fx ); + p_proto_buffer_fx[2 * ( num_freq_bands + l )] = Madd_32_16( Mpy_32_16_1( L_sub( im1, im2 ), interpolatorSpaced_fx ), L_sub( re1, re2 ), interpolatorDmx_fx ); // q_cldfb+min_q_shift move32(); - p_proto_buffer_fx[add( i_mult( 2, add( num_freq_bands, l ) ), 1 )] = Madd_32_16( Mpy_32_16_1( -L_sub( re1, re2 ), interpolatorSpaced_fx ), L_sub( im1, im2 ), interpolatorDmx_fx ); + p_proto_buffer_fx[2 * ( num_freq_bands + l ) + 1] = Madd_32_16( Mpy_32_16_1( -L_sub( re1, re2 ), interpolatorSpaced_fx ), L_sub( im1, im2 ), interpolatorDmx_fx ); // q_cldfb+min_q_shift move32(); } ELSE { - p_proto_buffer_fx[i_mult( 2, add( num_freq_bands, l ) )] = Madd_32_16( Mpy_32_16_1( p_proto_buffer_fx[2 * l], interpolatorSpaced_fx ), L_sub( re1, re2 ), interpolatorDmx_fx ); + p_proto_buffer_fx[2 * ( num_freq_bands + l )] = Madd_32_16( Mpy_32_16_1( p_proto_buffer_fx[2 * l], interpolatorSpaced_fx ), L_sub( re1, re2 ), interpolatorDmx_fx ); // q_cldfb+min_q_shift move32(); - p_proto_buffer_fx[add( i_mult( 2, add( num_freq_bands, l ) ), 1 )] = Madd_32_16( Mpy_32_16_1( p_proto_buffer_fx[add( 2 * l, 1 )], interpolatorSpaced_fx ), L_sub( im1, im2 ), interpolatorDmx_fx ); + p_proto_buffer_fx[2 * ( num_freq_bands + l ) + 1] = Madd_32_16( Mpy_32_16_1( p_proto_buffer_fx[2 * l + 1], interpolatorSpaced_fx ), L_sub( im1, im2 ), interpolatorDmx_fx ); // q_cldfb+min_q_shift move32(); } - temp = Madd_32_32( Mpy_32_32( p_proto_buffer_fx[i_mult( 2, add( num_freq_bands, l ) )], p_proto_buffer_fx[i_mult( 2, add( num_freq_bands, l ) )] ), p_proto_buffer_fx[add( i_mult( 2, add( num_freq_bands, l ) ), 1 )], p_proto_buffer_fx[add( i_mult( 2, add( num_freq_bands, l ) ), 1 )] ); + temp = Madd_32_32( Mpy_32_32( p_proto_buffer_fx[2 * ( num_freq_bands + l )], p_proto_buffer_fx[2 * ( num_freq_bands + l )] ), p_proto_buffer_fx[2 * ( num_freq_bands + l ) + 1], p_proto_buffer_fx[2 * ( num_freq_bands + l ) + 1] ); // 2*(q_cldfb+min_q_shift)-31 IF( LT_16( q_temp, *q_proto_power_smooth ) ) { - proto_power_smooth_fx[add( l, num_freq_bands )] = L_add( L_shr( proto_power_smooth_fx[add( l, num_freq_bands )], sub( *q_proto_power_smooth, q_temp ) ), temp ); + proto_power_smooth_fx[l + num_freq_bands] = L_add( L_shr( proto_power_smooth_fx[l + num_freq_bands], sub( *q_proto_power_smooth, q_temp ) ), temp ); // q_temp move32(); } ELSE { - proto_power_smooth_fx[add( l, num_freq_bands )] = L_add( proto_power_smooth_fx[add( l, num_freq_bands )], L_shr( temp, sub( q_temp, *q_proto_power_smooth ) ) ); + proto_power_smooth_fx[l + num_freq_bands] = L_add( proto_power_smooth_fx[l + num_freq_bands], L_shr( temp, sub( q_temp, *q_proto_power_smooth ) ) ); // q_proto_power_smooth move32(); } } @@ -3307,74 +3313,74 @@ void protoSignalComputation2_fx( { IF( LT_16( l, dipole_freq_range[0] ) ) /* proto = W */ { - p_proto_buffer_fx[i_mult( 2, add( num_freq_bands, l ) )] = p_proto_buffer_fx[2 * l]; + p_proto_buffer_fx[2 * ( num_freq_bands + l )] = p_proto_buffer_fx[2 * l]; // q_cldfb+min_q_shift move32(); - p_proto_buffer_fx[add( i_mult( 2, add( num_freq_bands, l ) ), 1 )] = p_proto_buffer_fx[add( 2 * l, 1 )]; + p_proto_buffer_fx[2 * ( num_freq_bands + l ) + 1] = p_proto_buffer_fx[2 * l + 1]; // q_cldfb+min_q_shift move32(); - proto_power_smooth_fx[add( l, num_freq_bands )] = proto_power_smooth_fx[l]; + proto_power_smooth_fx[l + num_freq_bands] = proto_power_smooth_fx[l]; move32(); } ELSE IF( LT_16( l, dipole_freq_range[1] ) ) /* proto = -i * (x1-x2) * eq */ { - p_proto_buffer_fx[i_mult( 2, add( num_freq_bands, l ) )] = L_sub( im1, im2 ); + p_proto_buffer_fx[2 * ( num_freq_bands + l )] = L_sub( im1, im2 ); // q_cldfb+min_q_shift move32(); - p_proto_buffer_fx[add( i_mult( 2, add( num_freq_bands, l ) ), 1 )] = -L_sub( re1, re2 ); + p_proto_buffer_fx[2 * ( num_freq_bands + l ) + 1] = -L_sub( re1, re2 ); // q_cldfb+min_q_shift move32(); - temp = Madd_32_32( Mpy_32_32( p_proto_buffer_fx[i_mult( 2, add( num_freq_bands, l ) )], p_proto_buffer_fx[i_mult( 2, add( num_freq_bands, l ) )] ), p_proto_buffer_fx[add( i_mult( 2, add( num_freq_bands, l ) ), 1 )], p_proto_buffer_fx[add( i_mult( 2, add( num_freq_bands, l ) ), 1 )] ); + temp = Madd_32_32( Mpy_32_32( p_proto_buffer_fx[2 * ( num_freq_bands + l )], p_proto_buffer_fx[2 * ( num_freq_bands + l )] ), p_proto_buffer_fx[2 * ( num_freq_bands + l ) + 1], p_proto_buffer_fx[2 * ( num_freq_bands + l ) + 1] ); // 2*(q_cldfb+min_q_shift)-31 IF( LT_16( q_temp, *q_proto_power_smooth ) ) { - proto_power_smooth_fx[add( l, num_freq_bands )] = L_add( L_shr( proto_power_smooth_fx[add( l, num_freq_bands )], sub( *q_proto_power_smooth, q_temp ) ), temp ); + proto_power_smooth_fx[l + num_freq_bands] = L_add( L_shr( proto_power_smooth_fx[l + num_freq_bands], sub( *q_proto_power_smooth, q_temp ) ), temp ); // q_temp move32(); } ELSE { - proto_power_smooth_fx[add( l, num_freq_bands )] = L_add( proto_power_smooth_fx[add( l, num_freq_bands )], L_shr( temp, sub( q_temp, *q_proto_power_smooth ) ) ); + proto_power_smooth_fx[l + num_freq_bands] = L_add( proto_power_smooth_fx[l + num_freq_bands], L_shr( temp, sub( q_temp, *q_proto_power_smooth ) ) ); // q_proto_power_smooth move32(); } } ELSE /* proto = W */ { - p_proto_buffer_fx[i_mult( 2, add( num_freq_bands, l ) )] = p_proto_buffer_fx[2 * l]; + p_proto_buffer_fx[2 * ( num_freq_bands + l )] = p_proto_buffer_fx[2 * l]; // q_cldfb+min_q_shift move32(); - p_proto_buffer_fx[add( i_mult( 2, add( num_freq_bands, l ) ), 1 )] = p_proto_buffer_fx[add( 2 * l, 1 )]; + p_proto_buffer_fx[2 * ( num_freq_bands + l ) + 1] = p_proto_buffer_fx[2 * l + 1]; // q_cldfb+min_q_shift move32(); - proto_power_smooth_fx[add( l, num_freq_bands )] = proto_power_smooth_fx[l]; + proto_power_smooth_fx[l + num_freq_bands] = proto_power_smooth_fx[l]; // min( q_temp, *q_proto_power_smooth ) move32(); } } ELSE { - p_proto_buffer_fx[i_mult( 2, add( num_freq_bands, l ) )] = L_sub( re1, re2 ); + p_proto_buffer_fx[2 * ( num_freq_bands + l )] = L_sub( re1, re2 ); // q_cldfb+min_q_shift move32(); - p_proto_buffer_fx[add( i_mult( 2, add( num_freq_bands, l ) ), 1 )] = L_sub( im1, im2 ); + p_proto_buffer_fx[2 * ( num_freq_bands + l ) + 1] = L_sub( im1, im2 ); // q_cldfb+min_q_shift move32(); - temp = Madd_32_32( Mpy_32_32( p_proto_buffer_fx[i_mult( 2, add( num_freq_bands, l ) )], p_proto_buffer_fx[i_mult( 2, add( num_freq_bands, l ) )] ), p_proto_buffer_fx[add( i_mult( 2, add( num_freq_bands, l ) ), 1 )], p_proto_buffer_fx[add( i_mult( 2, add( num_freq_bands, l ) ), 1 )] ); + temp = Madd_32_32( Mpy_32_32( p_proto_buffer_fx[2 * ( num_freq_bands + l )], p_proto_buffer_fx[2 * ( num_freq_bands + l )] ), p_proto_buffer_fx[2 * ( num_freq_bands + l ) + 1], p_proto_buffer_fx[2 * ( num_freq_bands + l ) + 1] ); // 2*(q_cldfb+min_q_shift)-31 IF( LT_16( q_temp, *q_proto_power_smooth ) ) { - proto_power_smooth_fx[add( l, num_freq_bands )] = L_add( L_shr( proto_power_smooth_fx[add( l, num_freq_bands )], sub( *q_proto_power_smooth, q_temp ) ), temp ); + proto_power_smooth_fx[l + num_freq_bands] = L_add( L_shr( proto_power_smooth_fx[l + num_freq_bands], sub( *q_proto_power_smooth, q_temp ) ), temp ); // q_temp move32(); } ELSE { - proto_power_smooth_fx[add( l, num_freq_bands )] = L_add( proto_power_smooth_fx[add( l, num_freq_bands )], L_shr( temp, sub( q_temp, *q_proto_power_smooth ) ) ); + proto_power_smooth_fx[l + num_freq_bands] = L_add( proto_power_smooth_fx[l + num_freq_bands], L_shr( temp, sub( q_temp, *q_proto_power_smooth ) ) ); // q_proto_power_smooth move32(); } } /* Compute protos for decorrelation */ - proto_frame_f_fx[2 * l] = Real_aux_fx; + proto_frame_f_fx[2 * l] = Real_aux_fx; // q_cldfb+min_q_shift move32(); - proto_frame_f_fx[add( 2 * l, 1 )] = Imag_aux_fx; + proto_frame_f_fx[2 * l + 1] = Imag_aux_fx; // q_cldfb+min_q_shift move32(); - proto_frame_f_fx[add( i_mult( 2, num_freq_bands ), i_mult( 2, l ) )] = re1; + proto_frame_f_fx[2 * num_freq_bands + 2 * l] = re1; // q_cldfb+min_q_shift move32(); - proto_frame_f_fx[add( add( i_mult( 2, num_freq_bands ), i_mult( 2, l ) ), 1 )] = im1; + proto_frame_f_fx[2 * num_freq_bands + 2 * l + 1] = im1; // q_cldfb+min_q_shift move32(); - proto_frame_f_fx[add( i_mult( 4, num_freq_bands ), i_mult( 2, l ) )] = re2; + proto_frame_f_fx[4 * num_freq_bands + 2 * l] = re2; // q_cldfb+min_q_shift move32(); - proto_frame_f_fx[add( add( i_mult( 4, num_freq_bands ), i_mult( 2, l ) ), 1 )] = im2; + proto_frame_f_fx[4 * num_freq_bands + 2 * l + 1] = im2; // q_cldfb+min_q_shift move32(); } @@ -3397,67 +3403,67 @@ void protoSignalComputation2_fx( } } - temp = Mpy_32_32( a_fx, left_bb_power_fx ); + temp = Mpy_32_32( a_fx, left_bb_power_fx ); // 2*(q_cldfb+min_q_shift) -31 IF( LT_16( q_temp, stereo_type_detect->q_left_bb_power ) ) { - stereo_type_detect->left_bb_power_fx = L_add( temp, L_shr( Mpy_32_32( b_fx, stereo_type_detect->left_bb_power_fx ), sub( stereo_type_detect->q_left_bb_power, q_temp ) ) ); + stereo_type_detect->left_bb_power_fx = L_add( temp, L_shr( Mpy_32_32( b_fx, stereo_type_detect->left_bb_power_fx ), sub( stereo_type_detect->q_left_bb_power, q_temp ) ) ); // q_temp move32(); stereo_type_detect->q_left_bb_power = q_temp; move16(); } ELSE { - stereo_type_detect->left_bb_power_fx = L_add( L_shr( temp, sub( q_temp, stereo_type_detect->q_left_bb_power ) ), Mpy_32_32( b_fx, stereo_type_detect->left_bb_power_fx ) ); + stereo_type_detect->left_bb_power_fx = L_add( L_shr( temp, sub( q_temp, stereo_type_detect->q_left_bb_power ) ), Mpy_32_32( b_fx, stereo_type_detect->left_bb_power_fx ) ); // stereo_type_detect->q_left_bb_power move32(); } - temp = Mpy_32_32( a_fx, right_bb_power_fx ); + temp = Mpy_32_32( a_fx, right_bb_power_fx ); // 2*(q_cldfb+min_q_shift) -31 IF( LT_16( q_temp, stereo_type_detect->q_right_bb_power ) ) { - stereo_type_detect->right_bb_power_fx = L_add( temp, L_shr( Mpy_32_32( b_fx, stereo_type_detect->right_bb_power_fx ), sub( stereo_type_detect->q_right_bb_power, q_temp ) ) ); + stereo_type_detect->right_bb_power_fx = L_add( temp, L_shr( Mpy_32_32( b_fx, stereo_type_detect->right_bb_power_fx ), sub( stereo_type_detect->q_right_bb_power, q_temp ) ) ); // q_temp move32(); stereo_type_detect->q_right_bb_power = q_temp; move16(); } ELSE { - stereo_type_detect->right_bb_power_fx = L_add( L_shr( temp, sub( q_temp, stereo_type_detect->q_right_bb_power ) ), Mpy_32_32( b_fx, stereo_type_detect->right_bb_power_fx ) ); + stereo_type_detect->right_bb_power_fx = L_add( L_shr( temp, sub( q_temp, stereo_type_detect->q_right_bb_power ) ), Mpy_32_32( b_fx, stereo_type_detect->right_bb_power_fx ) ); // stereo_type_detect->q_right_bb_power move32(); } - temp = Mpy_32_32( a_fx, total_bb_power_fx ); + temp = Mpy_32_32( a_fx, total_bb_power_fx ); // 2*(q_cldfb+min_q_shift) -31 IF( LT_16( q_temp, stereo_type_detect->q_total_bb_power ) ) { - stereo_type_detect->total_bb_power_fx = L_add( temp, L_shr( Mpy_32_32( b_fx, stereo_type_detect->total_bb_power_fx ), sub( stereo_type_detect->q_total_bb_power, q_temp ) ) ); + stereo_type_detect->total_bb_power_fx = L_add( temp, L_shr( Mpy_32_32( b_fx, stereo_type_detect->total_bb_power_fx ), sub( stereo_type_detect->q_total_bb_power, q_temp ) ) ); // q_temp move32(); stereo_type_detect->q_total_bb_power = q_temp; move16(); } ELSE { - stereo_type_detect->total_bb_power_fx = L_add( L_shr( temp, sub( q_temp, stereo_type_detect->q_total_bb_power ) ), Mpy_32_32( b_fx, stereo_type_detect->total_bb_power_fx ) ); + stereo_type_detect->total_bb_power_fx = L_add( L_shr( temp, sub( q_temp, stereo_type_detect->q_total_bb_power ) ), Mpy_32_32( b_fx, stereo_type_detect->total_bb_power_fx ) ); // stereo_type_detect->q_total_bb_power move32(); } IF( LT_16( stereo_type_detect->q_left_bb_power, stereo_type_detect->q_right_bb_power ) ) { - lr_bb_power_fx = L_min( stereo_type_detect->left_bb_power_fx, L_shr( stereo_type_detect->right_bb_power_fx, sub( stereo_type_detect->q_right_bb_power, stereo_type_detect->q_left_bb_power ) ) ); + lr_bb_power_fx = L_min( stereo_type_detect->left_bb_power_fx, L_shr( stereo_type_detect->right_bb_power_fx, sub( stereo_type_detect->q_right_bb_power, stereo_type_detect->q_left_bb_power ) ) ); // stereo_type_detect->q_left_bb_power move32(); q_lr_bb_power = stereo_type_detect->q_left_bb_power; move16(); } ELSE { - lr_bb_power_fx = L_min( L_shr( stereo_type_detect->left_bb_power_fx, sub( stereo_type_detect->q_left_bb_power, stereo_type_detect->q_right_bb_power ) ), stereo_type_detect->right_bb_power_fx ); + lr_bb_power_fx = L_min( L_shr( stereo_type_detect->left_bb_power_fx, sub( stereo_type_detect->q_left_bb_power, stereo_type_detect->q_right_bb_power ) ), stereo_type_detect->right_bb_power_fx ); // stereo_type_detect->q_right_bb_power move32(); q_lr_bb_power = stereo_type_detect->q_right_bb_power; move16(); } q_lr_bb_power = sub( q_lr_bb_power, 1 ); /* = (lr_bb_power_fx * 2) */ - temp = BASOP_Util_Divide3232_Scale_cadence( lr_bb_power_fx, L_add( stereo_type_detect->total_bb_power_fx, EPSILON_FX ), &exp ); + temp = BASOP_Util_Divide3232_Scale_cadence( lr_bb_power_fx, L_add( stereo_type_detect->total_bb_power_fx, EPSILON_FX ), &exp ); // Q(31-(exp+stereo_type_detect->q_total_bb_power-q_lr_bb_power)) exp = sub( 31, add( sub( 31, exp ), sub( q_lr_bb_power, stereo_type_detect->q_total_bb_power ) ) ); - temp = BASOP_Util_Log2( temp ); + temp = BASOP_Util_Log2( temp ); // q25 IF( NE_32( temp, MIN_32 ) ) { temp = Mpy_32_32( L_add( L_shl( exp, Q25 ), temp ), LOG10_2_Q31 ); // Q25 @@ -3465,65 +3471,65 @@ void protoSignalComputation2_fx( // 20480 = 10 in Q11 lr_total_bb_ratio_fx = Mpy_32_16_1( temp, 20480 ); // Q21 - temp = Mpy_32_32( a_fx, left_hi_power_fx ); + temp = Mpy_32_32( a_fx, left_hi_power_fx ); // 2*(q_cldfb+min_q_shift) -31 IF( LT_16( q_temp, stereo_type_detect->q_left_hi_power ) ) { - stereo_type_detect->left_hi_power_fx = L_add( temp, L_shr( Mpy_32_32( b_fx, stereo_type_detect->left_hi_power_fx ), sub( stereo_type_detect->q_left_hi_power, q_temp ) ) ); + stereo_type_detect->left_hi_power_fx = L_add( temp, L_shr( Mpy_32_32( b_fx, stereo_type_detect->left_hi_power_fx ), sub( stereo_type_detect->q_left_hi_power, q_temp ) ) ); // q_temp move32(); stereo_type_detect->q_left_hi_power = q_temp; move16(); } ELSE { - stereo_type_detect->left_hi_power_fx = L_add( L_shr( temp, sub( q_temp, stereo_type_detect->q_left_hi_power ) ), Mpy_32_32( b_fx, stereo_type_detect->left_hi_power_fx ) ); + stereo_type_detect->left_hi_power_fx = L_add( L_shr( temp, sub( q_temp, stereo_type_detect->q_left_hi_power ) ), Mpy_32_32( b_fx, stereo_type_detect->left_hi_power_fx ) ); // stereo_type_detect->q_left_hi_power move32(); } - temp = Mpy_32_32( a_fx, right_hi_power_fx ); + temp = Mpy_32_32( a_fx, right_hi_power_fx ); // 2*(q_cldfb+min_q_shift) -31 IF( LT_16( q_temp, stereo_type_detect->q_right_hi_power ) ) { - stereo_type_detect->right_hi_power_fx = L_add( temp, L_shr( Mpy_32_32( b_fx, stereo_type_detect->right_hi_power_fx ), sub( stereo_type_detect->q_right_hi_power, q_temp ) ) ); + stereo_type_detect->right_hi_power_fx = L_add( temp, L_shr( Mpy_32_32( b_fx, stereo_type_detect->right_hi_power_fx ), sub( stereo_type_detect->q_right_hi_power, q_temp ) ) ); // q_temp move32(); stereo_type_detect->q_right_hi_power = q_temp; move16(); } ELSE { - stereo_type_detect->right_hi_power_fx = L_add( L_shr( temp, sub( q_temp, stereo_type_detect->q_right_hi_power ) ), Mpy_32_32( b_fx, stereo_type_detect->right_hi_power_fx ) ); + stereo_type_detect->right_hi_power_fx = L_add( L_shr( temp, sub( q_temp, stereo_type_detect->q_right_hi_power ) ), Mpy_32_32( b_fx, stereo_type_detect->right_hi_power_fx ) ); // stereo_type_detect->q_right_hi_power move32(); } - temp = Mpy_32_32( a_fx, total_hi_power_fx ); + temp = Mpy_32_32( a_fx, total_hi_power_fx ); // 2*(q_cldfb+min_q_shift) -31 IF( LT_16( q_temp, stereo_type_detect->q_total_hi_power ) ) { - stereo_type_detect->total_hi_power_fx = L_add( temp, L_shr( Mpy_32_32( b_fx, stereo_type_detect->total_hi_power_fx ), sub( stereo_type_detect->q_total_hi_power, q_temp ) ) ); + stereo_type_detect->total_hi_power_fx = L_add( temp, L_shr( Mpy_32_32( b_fx, stereo_type_detect->total_hi_power_fx ), sub( stereo_type_detect->q_total_hi_power, q_temp ) ) ); // q_temp move32(); stereo_type_detect->q_total_hi_power = q_temp; move16(); } ELSE { - stereo_type_detect->total_hi_power_fx = L_add( L_shr( temp, sub( q_temp, stereo_type_detect->q_total_hi_power ) ), Mpy_32_32( b_fx, stereo_type_detect->total_hi_power_fx ) ); + stereo_type_detect->total_hi_power_fx = L_add( L_shr( temp, sub( q_temp, stereo_type_detect->q_total_hi_power ) ), Mpy_32_32( b_fx, stereo_type_detect->total_hi_power_fx ) ); // stereo_type_detect->q_total_hi_power move32(); } IF( LT_16( stereo_type_detect->q_left_hi_power, stereo_type_detect->q_right_hi_power ) ) { - lr_hi_power_fx = L_min( stereo_type_detect->left_hi_power_fx, L_shr( stereo_type_detect->right_hi_power_fx, sub( stereo_type_detect->q_right_hi_power, stereo_type_detect->q_left_hi_power ) ) ); + lr_hi_power_fx = L_min( stereo_type_detect->left_hi_power_fx, L_shr( stereo_type_detect->right_hi_power_fx, sub( stereo_type_detect->q_right_hi_power, stereo_type_detect->q_left_hi_power ) ) ); // stereo_type_detect->q_left_hi_power move32(); q_lr_hi_power = stereo_type_detect->q_left_hi_power; } ELSE { - lr_hi_power_fx = L_min( L_shr( stereo_type_detect->left_hi_power_fx, sub( stereo_type_detect->q_left_hi_power, stereo_type_detect->q_right_hi_power ) ), stereo_type_detect->right_hi_power_fx ); + lr_hi_power_fx = L_min( L_shr( stereo_type_detect->left_hi_power_fx, sub( stereo_type_detect->q_left_hi_power, stereo_type_detect->q_right_hi_power ) ), stereo_type_detect->right_hi_power_fx ); // stereo_type_detect->q_right_hi_power move32(); q_lr_hi_power = stereo_type_detect->q_right_hi_power; } q_lr_hi_power = sub( q_lr_hi_power, 1 ); /* = (q_lr_hi_power * 2) */ - temp = BASOP_Util_Divide3232_Scale_cadence( lr_hi_power_fx, L_add( stereo_type_detect->total_hi_power_fx, EPSILON_FX ), &exp ); + temp = BASOP_Util_Divide3232_Scale_cadence( lr_hi_power_fx, L_add( stereo_type_detect->total_hi_power_fx, EPSILON_FX ), &exp ); // Q=31-(exp+ stereo_type_detect->q_total_hi_power-q_lr_hi_power) exp = sub( 31, add( sub( 31, exp ), sub( q_lr_hi_power, stereo_type_detect->q_total_hi_power ) ) ); - temp = BASOP_Util_Log2( temp ); + temp = BASOP_Util_Log2( temp ); // q25 IF( NE_32( temp, MIN_32 ) ) { temp = Mpy_32_32( L_add( L_shl( exp, Q25 ), temp ), LOG10_2_Q31 ); // Q25 @@ -3531,9 +3537,9 @@ void protoSignalComputation2_fx( // 20480 = 10 in Q11 lr_total_hi_ratio_fx = Mpy_32_16_1( temp, 20480 ); // Q21 - minimum_l( sum_total_ratio_fx, s_min( num_freq_bands, MASA_SUM_FREQ_RANGE_BINS ), &min_sum_total_ratio_fx ); + minimum_l( sum_total_ratio_fx, s_min( num_freq_bands, MASA_SUM_FREQ_RANGE_BINS ), &min_sum_total_ratio_fx ); // q_sum_total_ratio exp = sub( 31, q_sum_total_ratio ); - temp = BASOP_Util_Log2( min_sum_total_ratio_fx ); + temp = BASOP_Util_Log2( min_sum_total_ratio_fx ); // q25 IF( NE_32( temp, MIN_32 ) ) { temp = Mpy_32_32( L_add( L_shl( exp, Q25 ), temp ), LOG10_2_Q31 ); // Q25 @@ -3552,69 +3558,69 @@ void protoSignalComputation2_fx( } ELSE { - p_proto_buffer_fx = proto_direct_buffer_f_fx + i_mult( i_mult( i_mult( slot_index, 2 ), num_freq_bands ), 2 ); + p_proto_buffer_fx = proto_direct_buffer_f_fx + ( slot_index * num_freq_bands * 4 ); // q_proto_direct_buffer_f q_temp = sub( add( add( q_cldfb, min_q_shift ), add( q_cldfb, min_q_shift ) ), 31 ); FOR( l = 0; l < num_freq_bands; l++ ) { - re1 = L_shl( RealBuffer_fx[0][0][l], min_q_shift ); - re2 = L_shl( RealBuffer_fx[1][0][l], min_q_shift ); - im1 = L_shl( ImagBuffer_fx[0][0][l], min_q_shift ); - im2 = L_shl( ImagBuffer_fx[1][0][l], min_q_shift ); + re1 = L_shl( RealBuffer_fx[0][0][l], min_q_shift ); // q_cldfb+ min_q_shift + re2 = L_shl( RealBuffer_fx[1][0][l], min_q_shift ); // q_cldfb+ min_q_shift + im1 = L_shl( ImagBuffer_fx[0][0][l], min_q_shift ); // q_cldfb+ min_q_shift + im2 = L_shl( ImagBuffer_fx[1][0][l], min_q_shift ); // q_cldfb+ min_q_shift - Real_aux_fx = L_add( re1, re2 ); - Imag_aux_fx = L_add( im1, im2 ); + Real_aux_fx = L_add( re1, re2 ); // q_cldfb+ min_q_shift + Imag_aux_fx = L_add( im1, im2 ); // q_cldfb+ min_q_shift // reference_power_fx[l] = Madd_32_32( Mpy_32_32( Real_aux_fx, Real_aux_fx ), Imag_aux_fx, Imag_aux_fx ); - reference_power_64fx[l] = W_add( W_mult0_32_32( Real_aux_fx, Real_aux_fx ), W_mult0_32_32( Imag_aux_fx, Imag_aux_fx ) ); // 2*(q_cldfb+min_q_shift) + reference_power_64fx[l] = W_add( W_mult0_32_32( Real_aux_fx, Real_aux_fx ), W_mult0_32_32( Imag_aux_fx, Imag_aux_fx ) ); // q_temp move64(); IF( LT_16( q_temp, *q_proto_power_smooth ) ) { - proto_power_smooth_fx[l] = L_add( L_shr( proto_power_smooth_fx[l], sub( *q_proto_power_smooth, q_temp ) ), W_extract_l( W_shr( reference_power_64fx[l], 31 ) ) ); + proto_power_smooth_fx[l] = L_add( L_shr( proto_power_smooth_fx[l], sub( *q_proto_power_smooth, q_temp ) ), W_extract_l( W_shr( reference_power_64fx[l], 31 ) ) ); // q_temp move32(); } ELSE { - proto_power_smooth_fx[l] = L_add( proto_power_smooth_fx[l], L_shr( W_extract_l( W_shr( reference_power_64fx[l], 31 ) ), sub( q_temp, *q_proto_power_smooth ) ) ); + proto_power_smooth_fx[l] = L_add( proto_power_smooth_fx[l], L_shr( W_extract_l( W_shr( reference_power_64fx[l], 31 ) ), sub( q_temp, *q_proto_power_smooth ) ) ); // q_proto_power_smooth move32(); } - p_proto_buffer_fx[2 * l] = Real_aux_fx; + p_proto_buffer_fx[2 * l] = Real_aux_fx; // q_cldfb+ min_q_shift move32(); - p_proto_buffer_fx[add( 2 * l, 1 )] = Imag_aux_fx; + p_proto_buffer_fx[2 * l + 1] = Imag_aux_fx; // q_cldfb+ min_q_shift move32(); - p_proto_buffer_fx[i_mult( 2, add( num_freq_bands, l ) )] = L_sub( re1, re2 ); + p_proto_buffer_fx[2 * ( num_freq_bands + l )] = L_sub( re1, re2 ); // q_cldfb+ min_q_shift move32(); - p_proto_buffer_fx[add( i_mult( 2, add( num_freq_bands, l ) ), 1 )] = L_sub( im1, im2 ); + p_proto_buffer_fx[2 * ( num_freq_bands + l ) + 1] = L_sub( im1, im2 ); // q_cldfb+ min_q_shift move32(); - temp = Madd_32_32( Mpy_32_32( p_proto_buffer_fx[i_mult( 2, add( num_freq_bands, l ) )], p_proto_buffer_fx[i_mult( 2, add( num_freq_bands, l ) )] ), p_proto_buffer_fx[add( i_mult( 2, add( num_freq_bands, l ) ), 1 )], p_proto_buffer_fx[add( i_mult( 2, add( num_freq_bands, l ) ), 1 )] ); + temp = Madd_32_32( Mpy_32_32( p_proto_buffer_fx[2 * ( num_freq_bands + l )], p_proto_buffer_fx[2 * ( num_freq_bands + l )] ), p_proto_buffer_fx[2 * ( num_freq_bands + l ) + 1], p_proto_buffer_fx[2 * ( num_freq_bands + l ) + 1] ); // q_temp IF( LT_16( q_temp, *q_proto_power_smooth ) ) { - proto_power_smooth_fx[add( l, num_freq_bands )] = L_add( L_shr( proto_power_smooth_fx[add( l, num_freq_bands )], sub( *q_proto_power_smooth, q_temp ) ), temp ); + proto_power_smooth_fx[l + num_freq_bands] = L_add( L_shr( proto_power_smooth_fx[l + num_freq_bands], sub( *q_proto_power_smooth, q_temp ) ), temp ); // q_temp move32(); } ELSE { - proto_power_smooth_fx[add( l, num_freq_bands )] = L_add( proto_power_smooth_fx[add( l, num_freq_bands )], L_shr( temp, sub( q_temp, *q_proto_power_smooth ) ) ); + proto_power_smooth_fx[l + num_freq_bands] = L_add( proto_power_smooth_fx[l + num_freq_bands], L_shr( temp, sub( q_temp, *q_proto_power_smooth ) ) ); // q_proto_power_smooth move32(); } - proto_frame_f_fx[2 * l] = Real_aux_fx; + proto_frame_f_fx[2 * l] = Real_aux_fx; // q_cldfb+ min_q_shift move32(); - proto_frame_f_fx[add( 2 * l, 1 )] = Imag_aux_fx; + proto_frame_f_fx[2 * l + 1] = Imag_aux_fx; // q_cldfb+ min_q_shift move32(); - proto_frame_f_fx[add( i_mult( 2, num_freq_bands ), i_mult( 2, l ) )] = re1; + proto_frame_f_fx[2 * num_freq_bands + 2 * l] = re1; // q_cldfb+ min_q_shift move32(); - proto_frame_f_fx[add( add( i_mult( 2, num_freq_bands ), i_mult( 2, l ) ), 1 )] = im1; + proto_frame_f_fx[2 * num_freq_bands + 2 * l + 1] = im1; // q_cldfb+ min_q_shift move32(); - proto_frame_f_fx[add( i_mult( 4, num_freq_bands ), i_mult( 2, l ) )] = re2; + proto_frame_f_fx[4 * num_freq_bands + 2 * l] = re2; // q_cldfb+ min_q_shift move32(); - proto_frame_f_fx[add( add( i_mult( 4, num_freq_bands ), i_mult( 2, l ) ), 1 )] = im2; + proto_frame_f_fx[4 * num_freq_bands + 2 * l + 1] = im2; // q_cldfb+ min_q_shift move32(); } } @@ -3630,7 +3636,7 @@ void protoSignalComputation2_fx( } FOR( l = 0; l < num_freq_bands; l++ ) { - reference_power_fx[l] = W_extract_h( W_shl( reference_power_64fx[l], norm_shift ) ); + reference_power_fx[l] = W_extract_h( W_shl( reference_power_64fx[l], norm_shift ) ); // q_reference_power_64fx+norm_shift-32 move32(); } *q_reference_power = sub( add( q_reference_power_64fx, norm_shift ), 32 ); @@ -3976,20 +3982,20 @@ void protoSignalComputation2( #ifdef IVAS_FLOAT_FIXED void protoSignalComputation4_fx( - Word32 RealBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], - Word32 ImagBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], - Word32 *proto_frame_f_fx, + Word32 RealBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /*q_cldfb*/ + Word32 ImagBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /*q_cldfb*/ + Word32 *proto_frame_f_fx, /*proto_frame_f_q*/ Word16 *proto_frame_f_q, - Word32 *proto_direct_buffer_f_fx, + Word32 *proto_direct_buffer_f_fx, /*proto_direct_buffer_f_q*/ Word16 *proto_direct_buffer_f_q, - Word32 *reference_power_fx, + Word32 *reference_power_fx, /*reference_power_q*/ Word16 *reference_power_q, - Word32 *proto_power_smooth_fx, + Word32 *proto_power_smooth_fx, /*proto_power_smooth_q*/ Word16 *proto_power_smooth_q, const Word16 slot_index, const Word16 num_outputs_diff, const Word16 num_freq_bands, - const Word32 *mtx_hoa_decoder, + const Word32 *mtx_hoa_decoder, /*q29*/ const Word16 nchan_transport, const Word16 *sba_map_tc_ind, Word16 q_cldfb ) @@ -4026,12 +4032,12 @@ void protoSignalComputation4_fx( { FOR( l = 0; l < num_freq_bands; l++ ) { - re = L_shl( RealBuffer_fx[k][0][l], min_q_shift ); - im = L_shl( ImagBuffer_fx[k][0][l], min_q_shift ); + re = L_shl( RealBuffer_fx[k][0][l], min_q_shift ); // q_cldfb+min_q_shift + im = L_shl( ImagBuffer_fx[k][0][l], min_q_shift ); // q_cldfb+min_q_shift - sq_tmp_fx = Madd_32_32( Mpy_32_32( re, re ), im, im ); + sq_tmp_fx = Madd_32_32( Mpy_32_32( re, re ), im, im ); // 2*(q_cldfb+min_q_shift)-31 - reference_power_fx[l] = Madd_32_16( reference_power_fx[l], sq_tmp_fx, 16384 ); // 16384 = 0.5 in Q15 + reference_power_fx[l] = Madd_32_16( reference_power_fx[l], sq_tmp_fx, 16384 /*0.5 in Q15*/ ); // 2*(q_cldfb+min_q_shift)-31 move32(); } } @@ -4049,18 +4055,18 @@ void protoSignalComputation4_fx( idx = add( i_mult( i_mult( 2, l ), num_freq_bands ), i_mult( 2, k ) ); proto_frame_f_fx[idx] = 0; move32(); - proto_frame_f_fx[add( idx, 1 )] = 0; + proto_frame_f_fx[idx + 1] = 0; move32(); FOR( n = 0; n < nchan_transport; n++ ) { idx2 = add( i_mult( l, 16 ), sba_map_tc_ind[n] ); - re = L_shl( RealBuffer_fx[n][0][k], min_q_shift ); - im = L_shl( ImagBuffer_fx[n][0][k], min_q_shift ); + re = L_shl( RealBuffer_fx[n][0][k], min_q_shift ); // q_cldfb+min_q_shift + im = L_shl( ImagBuffer_fx[n][0][k], min_q_shift ); // q_cldfb+min_q_shift - proto_frame_f_fx[idx] = Madd_32_32( proto_frame_f_fx[idx], re, mtx_hoa_decoder[idx2] ); + proto_frame_f_fx[idx] = Madd_32_32( proto_frame_f_fx[idx], re, mtx_hoa_decoder[idx2] ); // q_cldfb+min_q_shift+29-31 => q_cldfb+min_q_shift-2 move32(); - proto_frame_f_fx[add( idx, 1 )] = Madd_32_32( proto_frame_f_fx[add( idx, 1 )], im, mtx_hoa_decoder[idx2] ); + proto_frame_f_fx[idx + 1] = Madd_32_32( proto_frame_f_fx[idx + 1], im, mtx_hoa_decoder[idx2] ); // q_cldfb+min_q_shift-2 move32(); } } @@ -4072,7 +4078,7 @@ void protoSignalComputation4_fx( min_q_shift = getScaleFactor32( proto_power_smooth_fx, i_mult( num_outputs_diff, num_freq_bands ) ); min_q_shift = sub( min_q_shift, find_guarded_bits_fx( 2 ) ); - Scale_sig32( proto_power_smooth_fx, i_mult( num_outputs_diff, num_freq_bands ), min_q_shift ); + Scale_sig32( proto_power_smooth_fx, i_mult( num_outputs_diff, num_freq_bands ), min_q_shift ); // proto_power_smooth_q+min_q_shift *proto_power_smooth_q = add( *proto_power_smooth_q, min_q_shift ); move16(); proto_power_smooth_fx_q = *proto_power_smooth_q; @@ -4082,40 +4088,40 @@ void protoSignalComputation4_fx( min_q_shift = getScaleFactor32( proto_frame_f_fx, i_mult( 2, i_mult( num_outputs_diff, num_freq_bands ) ) ); min_q_shift = sub( min_q_shift, find_guarded_bits_fx( 2 ) ); - Scale_sig32( proto_frame_f_fx, i_mult( 2, i_mult( num_outputs_diff, num_freq_bands ) ), min_q_shift ); + Scale_sig32( proto_frame_f_fx, i_mult( 2, i_mult( num_outputs_diff, num_freq_bands ) ), min_q_shift ); // proto_frame_f_q+min_q_shift *proto_frame_f_q = add( *proto_frame_f_q, min_q_shift ); move16(); offset = i_mult( i_mult( slot_index, 2 ), i_mult( num_freq_bands, num_outputs_diff ) ); - p_proto_buffer_fx = proto_direct_buffer_f_fx + offset; + p_proto_buffer_fx = proto_direct_buffer_f_fx + offset; // proto_direct_buffer_f_q FOR( k = 0; k < num_outputs_diff; k++ ) { FOR( l = 0; l < num_freq_bands; l++ ) { - idx = i_mult( 2, add( i_mult( k, num_freq_bands ), l ) ); + idx = 2 * ( k * num_freq_bands + l ); - sq_tmp_fx = Madd_32_32( Mpy_32_32( proto_frame_f_fx[idx], proto_frame_f_fx[idx] ), proto_frame_f_fx[add( idx, 1 )], proto_frame_f_fx[add( idx, 1 )] ); + sq_tmp_fx = Madd_32_32( Mpy_32_32( proto_frame_f_fx[idx], proto_frame_f_fx[idx] ), proto_frame_f_fx[idx + 1], proto_frame_f_fx[idx + 1] ); // 2*(proto_frame_f_q)-31 sq_tmp_q = sub( add( *proto_frame_f_q, *proto_frame_f_q ), 31 ); IF( LT_16( *proto_power_smooth_q, sq_tmp_q ) ) { - proto_power_smooth_fx[add( l, i_mult( k, num_freq_bands ) )] = L_add( proto_power_smooth_fx[add( l, i_mult( k, num_freq_bands ) )], L_shr( sq_tmp_fx, sub( sq_tmp_q, *proto_power_smooth_q ) ) ); + proto_power_smooth_fx[l + ( k * num_freq_bands )] = L_add( proto_power_smooth_fx[l + ( k * num_freq_bands )], L_shr( sq_tmp_fx, sub( sq_tmp_q, *proto_power_smooth_q ) ) ); // proto_power_smooth_q move32(); proto_power_smooth_fx_q = *proto_power_smooth_q; move16(); } ELSE { - proto_power_smooth_fx[add( l, i_mult( k, num_freq_bands ) )] = L_add( L_shr( proto_power_smooth_fx[add( l, i_mult( k, num_freq_bands ) )], sub( *proto_power_smooth_q, sq_tmp_q ) ), sq_tmp_fx ); + proto_power_smooth_fx[l + ( k * num_freq_bands )] = L_add( L_shr( proto_power_smooth_fx[l + ( k * num_freq_bands )], sub( *proto_power_smooth_q, sq_tmp_q ) ), sq_tmp_fx ); // sq_tmp_q move32(); proto_power_smooth_fx_q = sq_tmp_q; move16(); } - p_proto_buffer_fx[idx] = proto_frame_f_fx[idx]; + p_proto_buffer_fx[idx] = proto_frame_f_fx[idx]; // proto_frame_f_q move32(); - p_proto_buffer_fx[add( idx, 1 )] = proto_frame_f_fx[add( idx, 1 )]; + p_proto_buffer_fx[idx + 1] = proto_frame_f_fx[idx + 1]; // proto_frame_f_q move32(); } } @@ -4213,7 +4219,7 @@ void ivas_dirac_dec_compute_diffuse_proto_fx( Word32 *p_proto_diff_fx, *p_power_smooth_fx; Word32 *p_hoa_enc_fx; - proto_frame_dec_f_fx = hDirACRend->proto_frame_dec_f_fx; + proto_frame_dec_f_fx = hDirACRend->proto_frame_dec_f_fx; // hDirACRend->proto_frame_dec_f_q h_dirac_output_synthesis_params = &( hDirACRend->h_output_synthesis_psd_params ); h_dirac_output_synthesis_state = &( hDirACRend->h_output_synthesis_psd_state ); @@ -4225,17 +4231,18 @@ void ivas_dirac_dec_compute_diffuse_proto_fx( return; } - p_diff_buffer_fx = h_dirac_output_synthesis_state->proto_diffuse_buffer_f_fx + imult1616( shl( imult1616( slot_idx, num_freq_bands_diff ), 1 ), hDirACRend->hOutSetup.nchan_out_woLFE ); + p_diff_buffer_fx = h_dirac_output_synthesis_state->proto_diffuse_buffer_f_fx + ( ( ( slot_idx * num_freq_bands_diff ) << 1 ) * hDirACRend->hOutSetup.nchan_out_woLFE ); // proto_diffuse_buffer_f_q p_diff_buffer_1_fx = p_diff_buffer_fx + 1; - p_power_smooth_fx = h_dirac_output_synthesis_state->proto_power_diff_smooth_fx; + p_power_smooth_fx = h_dirac_output_synthesis_state->proto_power_diff_smooth_fx; // h_dirac_output_synthesis_state->proto_power_diff_smooth_q - Word16 diffuse_start = slot_idx * 2 * num_freq_bands_diff * hDirACRend->hOutSetup.nchan_out_woLFE; + Word16 diffuse_start = imult1616( slot_idx, shl( imult1616( num_freq_bands_diff, hDirACRend->hOutSetup.nchan_out_woLFE ), 1 ) ); Word16 diff_e, smooth_e, proto_e, max_e; Word32 diff_square, diff_square_1, diff_square_sum; Word16 diff_square_e; Word16 old_diff_e; diff_e = sub( 31, h_dirac_output_synthesis_state->proto_diffuse_buffer_f_q ); old_diff_e = diff_e; + move16(); smooth_e = sub( 31, h_dirac_output_synthesis_state->proto_power_diff_smooth_q ); proto_e = sub( 31, hDirACRend->proto_frame_dec_f_q ); @@ -4243,22 +4250,22 @@ void ivas_dirac_dec_compute_diffuse_proto_fx( { diff_square_e = add( shl( proto_e, 1 ), 1 ); max_e = add( s_max( diff_square_e, smooth_e ), 1 ); - Scale_sig32( p_power_smooth_fx, h_dirac_output_synthesis_state->proto_power_diff_smooth_len, sub( smooth_e, max_e ) ); + Scale_sig32( p_power_smooth_fx, h_dirac_output_synthesis_state->proto_power_diff_smooth_len, sub( smooth_e, max_e ) ); // 31-max_e FOR( k = 0; k < hDirACRend->hOutSetup.nchan_out_woLFE; k++ ) { - p_proto_diff_fx = proto_frame_dec_f_fx + shl( imult1616( k, num_freq_bands ), 1 ); + p_proto_diff_fx = proto_frame_dec_f_fx + shl( imult1616( k, num_freq_bands ), 1 ); // hDirACRend->proto_frame_dec_f_q FOR( l = 0; l < num_freq_bands_diff; l++ ) { - *p_diff_buffer_fx = *( p_proto_diff_fx++ ); + *p_diff_buffer_fx = *( p_proto_diff_fx++ ); // hDirACRend->proto_frame_dec_f_q move32(); - *p_diff_buffer_1_fx = *( p_proto_diff_fx++ ); + *p_diff_buffer_1_fx = *( p_proto_diff_fx++ ); // hDirACRend->proto_frame_dec_f_q move32(); diff_square = L_shr( Mpy_32_32( *p_diff_buffer_fx, *p_diff_buffer_fx ), 1 ); // 2 * proto_e + 1 diff_square_1 = L_shr( Mpy_32_32( *p_diff_buffer_1_fx, *p_diff_buffer_1_fx ), 1 ); // 2 * proto_e + 1 - diff_square_sum = L_add( diff_square, diff_square_1 ); - diff_square_sum = L_shr( diff_square_sum, sub( max_e, diff_square_e ) ); - *p_power_smooth_fx = L_add( *p_power_smooth_fx, diff_square_sum ); + diff_square_sum = L_add( diff_square, diff_square_1 ); // Q(31- diff_square_e) + diff_square_sum = L_shr( diff_square_sum, sub( max_e, diff_square_e ) ); // Q(31-max_e) + *p_power_smooth_fx = L_add( *p_power_smooth_fx, diff_square_sum ); // Q(31-max_e) move32(); p_power_smooth_fx++; @@ -4275,13 +4282,13 @@ void ivas_dirac_dec_compute_diffuse_proto_fx( Word16 gb = find_guarded_bits_fx( hDirACRend->num_outputs_diff ); diff_square_e = add( shl( add( proto_e, gb ), 1 ), 1 ); max_e = add( s_max( diff_square_e, smooth_e ), 1 ); - Scale_sig32( p_power_smooth_fx, h_dirac_output_synthesis_state->proto_power_diff_smooth_len, sub( smooth_e, max_e ) ); + Scale_sig32( p_power_smooth_fx, h_dirac_output_synthesis_state->proto_power_diff_smooth_len, sub( smooth_e, max_e ) ); // 31-max_e FOR( k = 0; k < hDirACRend->hOutSetup.nchan_out_woLFE; k++ ) { FOR( l = 0; l < num_freq_bands_diff; l++ ) { - p_hoa_enc_fx = hDirACRend->hoa_encoder_fx + k; - p_proto_diff_fx = proto_frame_dec_f_fx + shl( l, 1 ); + p_hoa_enc_fx = hDirACRend->hoa_encoder_fx + k; // q31 + p_proto_diff_fx = proto_frame_dec_f_fx + shl( l, 1 ); // hDirACRend->proto_frame_dec_f_q *p_diff_buffer_fx = 0; move32(); @@ -4291,19 +4298,19 @@ void ivas_dirac_dec_compute_diffuse_proto_fx( /*LS to HOA*/ FOR( m = 0; m < hDirACRend->num_outputs_diff; m++ ) { - *p_diff_buffer_fx = L_add( *p_diff_buffer_fx, L_shr( Mpy_32_32( *p_hoa_enc_fx, *p_proto_diff_fx ), gb ) ); + *p_diff_buffer_fx = L_add( *p_diff_buffer_fx, L_shr( Mpy_32_32( *p_hoa_enc_fx, *p_proto_diff_fx ), gb ) ); // hDirACRend->proto_frame_dec_f_q-gb move32(); - *p_diff_buffer_1_fx = L_add( *p_diff_buffer_1_fx, L_shr( Mpy_32_32( *p_hoa_enc_fx, *( p_proto_diff_fx + 1 ) ), gb ) ); + *p_diff_buffer_1_fx = L_add( *p_diff_buffer_1_fx, L_shr( Mpy_32_32( *p_hoa_enc_fx, *( p_proto_diff_fx + 1 ) ), gb ) ); // hDirACRend->proto_frame_dec_f_q-gb move32(); p_hoa_enc_fx += hDirACRend->hOutSetup.nchan_out_woLFE; p_proto_diff_fx += shl( num_freq_bands, 1 ); } - diff_square = L_shr( Mpy_32_32( *p_diff_buffer_fx, *p_diff_buffer_fx ), 1 ); // 2*(2 + proto_e + gb) + 1 - diff_square_1 = L_shr( Mpy_32_32( *p_diff_buffer_1_fx, *p_diff_buffer_1_fx ), 1 ); // 2*(2 + proto_e + gb) + 1 - diff_square_sum = L_add( diff_square, diff_square_1 ); - diff_square_sum = L_shr( diff_square_sum, sub( max_e, diff_square_e ) ); - *p_power_smooth_fx = L_add( *p_power_smooth_fx, diff_square_sum ); + diff_square = L_shr( Mpy_32_32( *p_diff_buffer_fx, *p_diff_buffer_fx ), 1 ); // 2*( proto_e + gb) + 1 + diff_square_1 = L_shr( Mpy_32_32( *p_diff_buffer_1_fx, *p_diff_buffer_1_fx ), 1 ); // 2*( proto_e + gb) + 1 + diff_square_sum = L_add( diff_square, diff_square_1 ); // 2*( proto_e + gb) + 1 + diff_square_sum = L_shr( diff_square_sum, sub( max_e, diff_square_e ) ); // 31-max_e + *p_power_smooth_fx = L_add( *p_power_smooth_fx, diff_square_sum ); // 31-max_e move32(); p_power_smooth_fx++; @@ -4318,10 +4325,10 @@ void ivas_dirac_dec_compute_diffuse_proto_fx( move16(); Word16 new_diff_e = s_max( diff_e, old_diff_e ); - Scale_sig32( h_dirac_output_synthesis_state->proto_diffuse_buffer_f_fx, diffuse_start, sub( old_diff_e, new_diff_e ) ); + Scale_sig32( h_dirac_output_synthesis_state->proto_diffuse_buffer_f_fx, diffuse_start, sub( old_diff_e, new_diff_e ) ); // 31-new_diff_e #ifdef MSAN_FIX Scale_sig32( h_dirac_output_synthesis_state->proto_diffuse_buffer_f_fx + diffuse_start, - i_mult( shl( num_freq_bands_diff, 1 ), hDirACRend->hOutSetup.nchan_out_woLFE ), sub( diff_e, new_diff_e ) ); + i_mult( shl( num_freq_bands_diff, 1 ), hDirACRend->hOutSetup.nchan_out_woLFE ), sub( diff_e, new_diff_e ) ); // 31-new_diff_e #else Scale_sig32( h_dirac_output_synthesis_state->proto_diffuse_buffer_f_fx + diffuse_start, sub( h_dirac_output_synthesis_state->proto_diffuse_buffer_f_len, diffuse_start ), sub( diff_e, new_diff_e ) ); @@ -4417,9 +4424,9 @@ void ivas_dirac_dec_compute_diffuse_proto( #ifdef IVAS_FLOAT_FIXED void computeDirectionAngles_fx( - Word32 *intensity_real_x_fx, - Word32 *intensity_real_y_fx, - Word32 *intensity_real_z_fx, + Word32 *intensity_real_x_fx, /*q_intensity_real*/ + Word32 *intensity_real_y_fx, /*q_intensity_real*/ + Word32 *intensity_real_z_fx, /*q_intensity_real*/ Word16 q_intensity_real, const Word16 num_frequency_bands, Word16 *azimuth, @@ -4441,28 +4448,28 @@ void computeDirectionAngles_fx( exp1 = norm_l( intensity_real_x_fx[k] ); exp2 = norm_l( intensity_real_y_fx[k] ); exp3 = norm_l( intensity_real_z_fx[k] ); - x_re = L_shl( intensity_real_x_fx[k], exp1 ); - y_re = L_shl( intensity_real_y_fx[k], exp2 ); - z_re = L_shl( intensity_real_z_fx[k], exp3 ); + x_re = L_shl( intensity_real_x_fx[k], exp1 ); /*q_intensity_real+exp1*/ + y_re = L_shl( intensity_real_y_fx[k], exp2 ); /*q_intensity_real+exp2*/ + z_re = L_shl( intensity_real_z_fx[k], exp3 ); /*q_intensity_real+exp3*/ - tmp1 = Mpy_32_32( x_re, x_re ); + tmp1 = Mpy_32_32( x_re, x_re ); /*2*(q_intensity_real+exp1)-31*/ q_tmp1 = sub( add( add( q_intensity_real, exp1 ), add( q_intensity_real, exp1 ) ), 31 ); - tmp2 = Mpy_32_32( y_re, y_re ); + tmp2 = Mpy_32_32( y_re, y_re ); /*2*(q_intensity_real+exp2)-31*/ q_tmp2 = sub( add( add( q_intensity_real, exp2 ), add( q_intensity_real, exp2 ) ), 31 ); - temp = BASOP_Util_Add_Mant32Exp( tmp1, sub( 31, q_tmp1 ), tmp2, sub( 31, q_tmp2 ), &exp ); + temp = BASOP_Util_Add_Mant32Exp( tmp1, sub( 31, q_tmp1 ), tmp2, sub( 31, q_tmp2 ), &exp ); // 31-exp - tmp2 = Mpy_32_32( z_re, z_re ); + tmp2 = Mpy_32_32( z_re, z_re ); /*2*(q_intensity_real+exp3)-31*/ q_tmp2 = sub( add( add( q_intensity_real, exp3 ), add( q_intensity_real, exp3 ) ), 31 ); - intensityNorm = BASOP_Util_Add_Mant32Exp( temp, exp, tmp2, sub( 31, q_tmp2 ), &exp ); + intensityNorm = BASOP_Util_Add_Mant32Exp( temp, exp, tmp2, sub( 31, q_tmp2 ), &exp ); // 31-exp q_intensityNorm = sub( 31, exp ); IF( LE_32( intensityNorm, EPSILON_FX ) ) { - intensityNorm = ONE_IN_Q30; + intensityNorm = ONE_IN_Q30; // q30 move32(); - x = ONE_IN_Q30; + x = ONE_IN_Q30; // q30 move32(); q_x = Q30; move16(); @@ -4477,31 +4484,31 @@ void computeDirectionAngles_fx( } ELSE { - temp = BASOP_Util_Divide3232_Scale_cadence( ONE_IN_Q30, intensityNorm, &exp ); + temp = BASOP_Util_Divide3232_Scale_cadence( ONE_IN_Q30, intensityNorm, &exp ); // Q=31-(exp-(30-q_intensityNorm)) exp = sub( exp, sub( Q30, q_intensityNorm ) ); - temp = Sqrt32( temp, &exp ); + temp = Sqrt32( temp, &exp ); // Q=31-exp q_temp = sub( 31, exp ); - x = Mpy_32_32( x_re, temp ); + x = Mpy_32_32( x_re, temp ); /*Q=q_intensity_real+exp1+q_temp-31*/ q_x = sub( add( add( q_intensity_real, exp1 ), q_temp ), 31 ); - y = Mpy_32_32( y_re, temp ); + y = Mpy_32_32( y_re, temp ); /*Q=q_intensity_real+exp2+q_temp-31*/ q_y = sub( add( add( q_intensity_real, exp2 ), q_temp ), 31 ); - z = Mpy_32_32( z_re, temp ); + z = Mpy_32_32( z_re, temp ); /*Q=q_intensity_real+exp3+q_temp-31*/ q_z = sub( add( add( q_intensity_real, exp3 ), q_temp ), 31 ); } - tmp1 = Mpy_32_32( x, x ); + tmp1 = Mpy_32_32( x, x ); /*Q=2*q_x-31*/ q_tmp1 = sub( add( q_x, q_x ), 31 ); - tmp2 = Mpy_32_32( y, y ); + tmp2 = Mpy_32_32( y, y ); /*Q=2*q_y-31*/ q_tmp2 = sub( add( q_y, q_y ), 31 ); - temp = BASOP_Util_Add_Mant32Exp( tmp1, sub( 31, q_tmp1 ), tmp2, sub( 31, q_tmp2 ), &exp ); - radius = Sqrt32( temp, &exp ); + temp = BASOP_Util_Add_Mant32Exp( tmp1, sub( 31, q_tmp1 ), tmp2, sub( 31, q_tmp2 ), &exp ); // Q=31-exp + radius = Sqrt32( temp, &exp ); // Q=31-exp - res = BASOP_util_atan2( y, x, sub( sub( 31, q_y ), sub( 31, q_x ) ) ); /* Q13 */ - res = add( s_max( -23040, s_min( 23040, mult( res, _180_OVER_PI_Q9 ) ) ), 64 ); /* Q7 */ - azimuth[k] = shr( abs_s( res ), Q7 ); /* Q0 */ + res = BASOP_util_atan2( y, x, sub( sub( 31, q_y ), sub( 31, q_x ) ) ); /* Q13 */ + res = add( s_max( -23040 /*-180 q7*/, s_min( 23040 /*180 q7*/, mult( res, _180_OVER_PI_Q9 /*180/pi q9*/ ) ) ), 64 /*0.5 q7*/ ); /* Q7 */ + azimuth[k] = shr( abs_s( res ), Q7 ); /* Q0 */ move16(); IF( res < 0 ) { @@ -4509,9 +4516,9 @@ void computeDirectionAngles_fx( move16(); } - res = BASOP_util_atan2( z, radius, sub( sub( 31, q_z ), exp ) ); /* Q13 */ - res = add( s_max( -11520, s_min( 23040, mult( res, _180_OVER_PI_Q9 ) ) ), 64 ); /* Q7 */ - elevation[k] = shr( abs_s( res ), Q7 ); /* Q0 */ + res = BASOP_util_atan2( z, radius, sub( sub( 31, q_z ), exp ) ); /* Q13 */ + res = add( s_max( -11520 /*-90 q7*/, s_min( 23040 /*180 q7*/, mult( res, _180_OVER_PI_Q9 /*180/pi q9*/ ) ) ), 64 /*0.5 q7*/ ); /* Q7 */ + elevation[k] = shr( abs_s( res ), Q7 ); /* Q0 */ move16(); IF( res < 0 ) { @@ -4719,28 +4726,28 @@ void ivas_masa_stereotype_detection_fx( Word32 lr_total_hi_temp_fx; Word32 temp; - lr_total_bb_ratio_db_fx = stereo_type_detect->lr_total_bb_ratio_db_fx; + lr_total_bb_ratio_db_fx = stereo_type_detect->lr_total_bb_ratio_db_fx; // q21 move32(); - lr_total_hi_ratio_db_fx = stereo_type_detect->lr_total_hi_ratio_db_fx; + lr_total_hi_ratio_db_fx = stereo_type_detect->lr_total_hi_ratio_db_fx; // q21 move32(); - min_sum_total_ratio_db_fx = stereo_type_detect->min_sum_total_ratio_db_fx; + min_sum_total_ratio_db_fx = stereo_type_detect->min_sum_total_ratio_db_fx; // q21 move32(); - subtract_target_ratio_db_fx = stereo_type_detect->subtract_target_ratio_db_fx; + subtract_target_ratio_db_fx = stereo_type_detect->subtract_target_ratio_db_fx; // q21 move32(); /* Determine if the determined features match the spaced mic type */ change_to_spaced_selection = 0; move16(); - IF( LT_32( subtract_target_ratio_db_fx, -THREE_Q21 ) ) + IF( LT_32( subtract_target_ratio_db_fx, -THREE_Q21 /*-3 q21*/ ) ) { /* subtract_temp = ( -subtract_target_ratio_db - 3.0f ) / 3.0f; */ - temp = L_sub( L_shr( -subtract_target_ratio_db_fx, 1 ), L_shr( THREE_Q21, 1 ) ); - subtract_temp_fx = Mpy_32_32( temp, 715827883 /* 1 / 3.0f in Q31 */ ); - subtract_temp_fx = L_shl( subtract_temp_fx, 1 ); /* Q21 */ + temp = L_sub( L_shr( -subtract_target_ratio_db_fx, 1 ), L_shr( THREE_Q21, 1 ) ); // q20 + subtract_temp_fx = Mpy_32_32( temp, 715827883 /* 1 / 3.0f in Q31 */ ); // q20 + subtract_temp_fx = L_shl( subtract_temp_fx, 1 ); /* Q21 */ /* min_sum_temp = max( -min_sum_total_ratio_db / 6.0f, 0.0f ); */ min_sum_temp_fx = Mpy_32_32_r( -min_sum_total_ratio_db_fx, 357913941 /* 1 / 6.0f in Q31 */ ); /* Q21 */ - min_sum_temp_fx = L_max( min_sum_temp_fx, 0 ); + min_sum_temp_fx = L_max( min_sum_temp_fx, 0 ); /*q21*/ /* lr_total_bb_temp = lr_total_bb_ratio_db / 6.0f; */ lr_total_bb_temp_fx = Mpy_32_32_r( lr_total_bb_ratio_db_fx, 357913941 /* 1 / 6.0f in Q31 */ ); /* Q21 */ @@ -4770,7 +4777,7 @@ void ivas_masa_stereotype_detection_fx( change_to_downmix_fx = L_add( L_add( subtract_temp_fx, min_sum_temp_fx ), lr_total_bb_temp_fx ); /* Q21 */ - IF( GE_32( change_to_downmix_fx, ONE_IN_Q21 ) ) + IF( GE_32( change_to_downmix_fx, ONE_IN_Q21 /*1 q21*/ ) ) { change_to_downmix_selection = 1; move16(); @@ -4791,7 +4798,7 @@ void ivas_masa_stereotype_detection_fx( change_to_downmix2_fx = L_add( L_add( subtract_temp_fx, min_sum_temp_fx ), lr_total_hi_temp_fx ); // Q21 - IF( GE_32( change_to_downmix2_fx, ONE_IN_Q21 ) ) + IF( GE_32( change_to_downmix2_fx, ONE_IN_Q21 /*1 q21*/ ) ) { change_to_downmix_selection = 1; move16(); @@ -4932,13 +4939,13 @@ void ivas_masa_stereotype_detection( #ifdef IVAS_FLOAT_FIXED void computeIntensityVector_dec_fx( - Word32 Cldfb_RealBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], - Word32 Cldfb_ImagBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], + Word32 Cldfb_RealBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /*q_cldfb*/ + Word32 Cldfb_ImagBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /*q_cldfb*/ Word16 q_cldfb, const Word16 num_frequency_bands, - Word32 *intensity_real_x_fx, - Word32 *intensity_real_y_fx, - Word32 *intensity_real_z_fx, + Word32 *intensity_real_x_fx, /*q_intensity_real*/ + Word32 *intensity_real_y_fx, /*q_intensity_real*/ + Word32 *intensity_real_z_fx, /*q_intensity_real*/ Word16 *q_intensity_real ) { /* @@ -4961,24 +4968,24 @@ void computeIntensityVector_dec_fx( FOR( i = 0; i < num_frequency_bands; ++i ) { - re1 = L_shl( Cldfb_RealBuffer_fx[0][0][i], min_q_shift ); - im1 = L_shl( Cldfb_ImagBuffer_fx[0][0][i], min_q_shift ); - re2 = L_shl( Cldfb_RealBuffer_fx[3][0][i], min_q_shift ); - im2 = L_shl( Cldfb_ImagBuffer_fx[3][0][i], min_q_shift ); + re1 = L_shl( Cldfb_RealBuffer_fx[0][0][i], min_q_shift ); /*q_cldfb+min_q_shift*/ + im1 = L_shl( Cldfb_ImagBuffer_fx[0][0][i], min_q_shift ); /*q_cldfb+min_q_shift*/ + re2 = L_shl( Cldfb_RealBuffer_fx[3][0][i], min_q_shift ); /*q_cldfb+min_q_shift*/ + im2 = L_shl( Cldfb_ImagBuffer_fx[3][0][i], min_q_shift ); /*q_cldfb+min_q_shift*/ - intensity_real_x_fx[i] = Madd_32_32( Mpy_32_32( re2, re1 ), im2, im1 ); + intensity_real_x_fx[i] = Madd_32_32( Mpy_32_32( re2, re1 ), im2, im1 ); /*2*(q_cldfb+min_q_shift)-31*/ move32(); - re2 = L_shl( Cldfb_RealBuffer_fx[1][0][i], min_q_shift ); - im2 = L_shl( Cldfb_ImagBuffer_fx[1][0][i], min_q_shift ); + re2 = L_shl( Cldfb_RealBuffer_fx[1][0][i], min_q_shift ); /*q_cldfb+min_q_shift*/ + im2 = L_shl( Cldfb_ImagBuffer_fx[1][0][i], min_q_shift ); /*q_cldfb+min_q_shift*/ - intensity_real_y_fx[i] = Madd_32_32( Mpy_32_32( re2, re1 ), im2, im1 ); + intensity_real_y_fx[i] = Madd_32_32( Mpy_32_32( re2, re1 ), im2, im1 ); /*2*(q_cldfb+min_q_shift)-31*/ move32(); - re2 = L_shl( Cldfb_RealBuffer_fx[2][0][i], min_q_shift ); - im2 = L_shl( Cldfb_ImagBuffer_fx[2][0][i], min_q_shift ); + re2 = L_shl( Cldfb_RealBuffer_fx[2][0][i], min_q_shift ); /*q_cldfb+min_q_shift*/ + im2 = L_shl( Cldfb_ImagBuffer_fx[2][0][i], min_q_shift ); /*q_cldfb+min_q_shift*/ - intensity_real_z_fx[i] = Madd_32_32( Mpy_32_32( re2, re1 ), im2, im1 ); + intensity_real_z_fx[i] = Madd_32_32( Mpy_32_32( re2, re1 ), im2, im1 ); /*2*(q_cldfb+min_q_shift)-31*/ move32(); } @@ -5026,10 +5033,10 @@ void computeIntensityVector_dec( #ifdef IVAS_FLOAT_FIXED void ivas_lfe_synth_with_cldfb_fx( MCMASA_LFE_SYNTH_DATA_HANDLE hMasaLfeSynth, - Word32 RealBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], - Word32 ImagBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], - Word32 RealBufferLfe_fx[MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], - Word32 ImagBufferLfe_fx[MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], + Word32 RealBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /*q_cldfb*/ + Word32 ImagBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /*q_cldfb*/ + Word32 RealBufferLfe_fx[MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /*q_cldfb*/ + Word32 ImagBufferLfe_fx[MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /*q_cldfb*/ const Word16 slot_index, const Word16 subframe_index, const Word16 nchan_transport, @@ -5045,6 +5052,7 @@ void ivas_lfe_synth_with_cldfb_fx( Word16 transportGain_q_fx, lfeGain_q_fx; Word16 exp, min_q_shift; Word32 re, im; + move16(); // temp_q exp = Q31; move16(); @@ -5069,89 +5077,89 @@ void ivas_lfe_synth_with_cldfb_fx( } min_q_shift = sub( sub( min_q_shift, find_guarded_bits_fx( nchan_transport ) ), 1 ); - re = L_shl( RealBuffer_fx[0][0][0], min_q_shift ); - im = L_shl( ImagBuffer_fx[0][0][0], min_q_shift ); + re = L_shl( RealBuffer_fx[0][0][0], min_q_shift ); // q_cldfb+min_q_shift + im = L_shl( ImagBuffer_fx[0][0][0], min_q_shift ); // q_cldfb+min_q_shift - protoLfeReal_fx = re; + protoLfeReal_fx = re; // q_cldfb+min_q_shift move32(); - protoLfeImag_fx = im; + protoLfeImag_fx = im; // q_cldfb+min_q_shift move32(); - transportEne_fx = Madd_32_32( Mpy_32_32( re, re ), im, im ); + transportEne_fx = Madd_32_32( Mpy_32_32( re, re ), im, im ); // 2*(q_cldfb+min_q_shift)-31 FOR( i = 1; i < nchan_transport; i++ ) { - re = L_shl( RealBuffer_fx[i][0][0], min_q_shift ); - im = L_shl( ImagBuffer_fx[i][0][0], min_q_shift ); + re = L_shl( RealBuffer_fx[i][0][0], min_q_shift ); // q_cldfb+min_q_shift + im = L_shl( ImagBuffer_fx[i][0][0], min_q_shift ); // q_cldfb+min_q_shift - protoLfeReal_fx = L_add( protoLfeReal_fx, re ); - protoLfeImag_fx = L_add( protoLfeImag_fx, im ); - transportEne_fx = L_add( transportEne_fx, Madd_32_32( Mpy_32_32( re, re ), im, im ) ); + protoLfeReal_fx = L_add( protoLfeReal_fx, re ); // q_cldfb+min_q_shift + protoLfeImag_fx = L_add( protoLfeImag_fx, im ); // q_cldfb+min_q_shift + transportEne_fx = L_add( transportEne_fx, Madd_32_32( Mpy_32_32( re, re ), im, im ) ); // 2*(q_cldfb+min_q_shift)-31 } transportEne_q = sub( add( add( q_cldfb, min_q_shift ), add( q_cldfb, min_q_shift ) ), 31 ); - protoLfeEne_fx = Madd_32_32( Mpy_32_32( protoLfeReal_fx, protoLfeReal_fx ), protoLfeImag_fx, protoLfeImag_fx ); + protoLfeEne_fx = Madd_32_32( Mpy_32_32( protoLfeReal_fx, protoLfeReal_fx ), protoLfeImag_fx, protoLfeImag_fx ); // 2*(q_cldfb+min_q_shift)-31 protoLfeEne_q = sub( add( add( q_cldfb, min_q_shift ), add( q_cldfb, min_q_shift ) ), 31 ); - targetEneLfe_fx = Mpy_32_16_1( transportEne_fx, hMasaLfeSynth->lfeToTotalEnergyRatio_fx[subframe_index] ); + targetEneLfe_fx = Mpy_32_16_1( transportEne_fx, hMasaLfeSynth->lfeToTotalEnergyRatio_fx[subframe_index] ); // targetEneLfe_q+14-15 targetEneLfe_q = sub( add( transportEne_q, Q14 ), 15 ); - temp = s_max( sub( ONE_IN_Q14, hMasaLfeSynth->lfeToTotalEnergyRatio_fx[subframe_index] ), 164 ); // 164 = 0.01 in Q14 - targetEneTrans_fx = Mpy_32_16_1( transportEne_fx, temp ); + temp = s_max( sub( ONE_IN_Q14 /*1 q14*/, hMasaLfeSynth->lfeToTotalEnergyRatio_fx[subframe_index] ), 164 /*0.01 in Q14*/ ); // q14 + targetEneTrans_fx = Mpy_32_16_1( transportEne_fx, temp ); /*transportEne_q+Q14 -15*/ targetEneTrans_q = sub( add( transportEne_q, Q14 ), 15 ); - hMasaLfeSynth->transportEneSmooth_fx = Mpy_32_16_1( hMasaLfeSynth->transportEneSmooth_fx, MCMASA_LFE_SYNTH_ALPHA_Q15 ); + hMasaLfeSynth->transportEneSmooth_fx = Mpy_32_16_1( hMasaLfeSynth->transportEneSmooth_fx, MCMASA_LFE_SYNTH_ALPHA_Q15 ); // hMasaLfeSynth->transportEneSmooth_q+15-15 move32(); - hMasaLfeSynth->protoLfeEneSmooth_fx = Mpy_32_16_1( hMasaLfeSynth->protoLfeEneSmooth_fx, MCMASA_LFE_SYNTH_ALPHA_Q15 ); + hMasaLfeSynth->protoLfeEneSmooth_fx = Mpy_32_16_1( hMasaLfeSynth->protoLfeEneSmooth_fx, MCMASA_LFE_SYNTH_ALPHA_Q15 ); // hMasaLfeSynth->protoLfeEneSmooth_q+15-15 move32(); - hMasaLfeSynth->targetEneLfeSmooth_fx = Mpy_32_16_1( hMasaLfeSynth->targetEneLfeSmooth_fx, MCMASA_LFE_SYNTH_ALPHA_Q15 ); + hMasaLfeSynth->targetEneLfeSmooth_fx = Mpy_32_16_1( hMasaLfeSynth->targetEneLfeSmooth_fx, MCMASA_LFE_SYNTH_ALPHA_Q15 ); // hMasaLfeSynth->targetEneLfeSmooth_q+15-15 move32(); - hMasaLfeSynth->targetEneTransSmooth_fx = Mpy_32_16_1( hMasaLfeSynth->targetEneTransSmooth_fx, MCMASA_LFE_SYNTH_ALPHA_Q15 ); + hMasaLfeSynth->targetEneTransSmooth_fx = Mpy_32_16_1( hMasaLfeSynth->targetEneTransSmooth_fx, MCMASA_LFE_SYNTH_ALPHA_Q15 ); // hMasaLfeSynth->targetEneTransSmooth_q+15-15 move32(); - hMasaLfeSynth->transportEneSmooth_fx = BASOP_Util_Add_Mant32Exp( hMasaLfeSynth->transportEneSmooth_fx, sub( 31, hMasaLfeSynth->transportEneSmooth_q ), transportEne_fx, sub( 31, transportEne_q ), &temp_q ); + hMasaLfeSynth->transportEneSmooth_fx = BASOP_Util_Add_Mant32Exp( hMasaLfeSynth->transportEneSmooth_fx, sub( 31, hMasaLfeSynth->transportEneSmooth_q ), transportEne_fx, sub( 31, transportEne_q ), &temp_q ); // 31-temp_q move32(); hMasaLfeSynth->transportEneSmooth_q = sub( 31, temp_q ); move16(); - hMasaLfeSynth->protoLfeEneSmooth_fx = BASOP_Util_Add_Mant32Exp( hMasaLfeSynth->protoLfeEneSmooth_fx, sub( 31, hMasaLfeSynth->protoLfeEneSmooth_q ), protoLfeEne_fx, sub( 31, protoLfeEne_q ), &temp_q ); + hMasaLfeSynth->protoLfeEneSmooth_fx = BASOP_Util_Add_Mant32Exp( hMasaLfeSynth->protoLfeEneSmooth_fx, sub( 31, hMasaLfeSynth->protoLfeEneSmooth_q ), protoLfeEne_fx, sub( 31, protoLfeEne_q ), &temp_q ); // 31-temp_q move32(); hMasaLfeSynth->protoLfeEneSmooth_q = sub( 31, temp_q ); move16(); - hMasaLfeSynth->targetEneLfeSmooth_fx = BASOP_Util_Add_Mant32Exp( hMasaLfeSynth->targetEneLfeSmooth_fx, sub( 31, hMasaLfeSynth->targetEneLfeSmooth_q ), targetEneLfe_fx, sub( 31, targetEneLfe_q ), &temp_q ); + hMasaLfeSynth->targetEneLfeSmooth_fx = BASOP_Util_Add_Mant32Exp( hMasaLfeSynth->targetEneLfeSmooth_fx, sub( 31, hMasaLfeSynth->targetEneLfeSmooth_q ), targetEneLfe_fx, sub( 31, targetEneLfe_q ), &temp_q ); // 31-temp_q move32(); hMasaLfeSynth->targetEneLfeSmooth_q = sub( 31, temp_q ); move16(); - hMasaLfeSynth->targetEneTransSmooth_fx = BASOP_Util_Add_Mant32Exp( hMasaLfeSynth->targetEneTransSmooth_fx, sub( 31, hMasaLfeSynth->targetEneTransSmooth_q ), targetEneTrans_fx, sub( 31, targetEneTrans_q ), &temp_q ); + hMasaLfeSynth->targetEneTransSmooth_fx = BASOP_Util_Add_Mant32Exp( hMasaLfeSynth->targetEneTransSmooth_fx, sub( 31, hMasaLfeSynth->targetEneTransSmooth_q ), targetEneTrans_fx, sub( 31, targetEneTrans_q ), &temp_q ); // 31-temp_q move32(); hMasaLfeSynth->targetEneTransSmooth_q = sub( 31, temp_q ); move16(); - temp = BASOP_Util_Divide3232_Scale( hMasaLfeSynth->targetEneLfeSmooth_fx, L_add( EPSILON_FX, hMasaLfeSynth->protoLfeEneSmooth_fx ), &temp_q ); + temp = BASOP_Util_Divide3232_Scale( hMasaLfeSynth->targetEneLfeSmooth_fx, L_add( EPSILON_FX, hMasaLfeSynth->protoLfeEneSmooth_fx ), &temp_q ); // 15-(temp_q-(hMasaLfeSynth->targetEneLfeSmooth_q-hMasaLfeSynth->protoLfeEneSmooth_q)) temp_q = add( sub( hMasaLfeSynth->targetEneLfeSmooth_q, hMasaLfeSynth->protoLfeEneSmooth_q ), sub( Q15, temp_q ) ); exp = sub( Q15, temp_q ); - lfeGain_fx = Sqrt16( temp, &exp ); + lfeGain_fx = Sqrt16( temp, &exp ); // 15-exp lfeGain_q_fx = sub( Q15, exp ); - IF( GT_32( L_shr( lfeGain_fx, sub( lfeGain_q_fx, Q14 ) ), ONE_IN_Q14 ) ) + IF( GT_32( L_shr( lfeGain_fx, sub( lfeGain_q_fx, Q14 ) ), ONE_IN_Q14 /*1 q14*/ ) ) { - lfeGain_fx = ONE_IN_Q14; + lfeGain_fx = ONE_IN_Q14; /*1 q14*/ move16(); lfeGain_q_fx = Q14; move16(); } - temp = BASOP_Util_Divide3232_Scale( hMasaLfeSynth->targetEneTransSmooth_fx, L_add( EPSILON_FX, hMasaLfeSynth->transportEneSmooth_fx ), &temp_q ); + temp = BASOP_Util_Divide3232_Scale( hMasaLfeSynth->targetEneTransSmooth_fx, L_add( EPSILON_FX, hMasaLfeSynth->transportEneSmooth_fx ), &temp_q ); // Q=15-(temp_q-(hMasaLfeSynth->targetEneTransSmooth_q-hMasaLfeSynth->transportEneSmooth_q)) temp_q = add( sub( hMasaLfeSynth->targetEneTransSmooth_q, hMasaLfeSynth->transportEneSmooth_q ), sub( Q15, temp_q ) ); exp = sub( Q15, temp_q ); - transportGain_fx = Sqrt16( temp, &exp ); + transportGain_fx = Sqrt16( temp, &exp ); // q=15-exp transportGain_q_fx = sub( Q15, exp ); - IF( GT_32( L_shr( transportGain_fx, sub( transportGain_q_fx, Q14 ) ), ONE_IN_Q14 ) ) + IF( GT_32( L_shr( transportGain_fx, sub( transportGain_q_fx, Q14 ) ), ONE_IN_Q14 /*1 q14*/ ) ) { - transportGain_fx = ONE_IN_Q14; + transportGain_fx = ONE_IN_Q14; /*1 q14*/ move16(); transportGain_q_fx = Q14; move16(); @@ -5251,7 +5259,7 @@ void rotateAziEle_DirAC_fx( Word16 *ele, /* i/o: array of elevation values */ const Word16 band1, /* i : bands to work on (lower limit) */ const Word16 band2, /* i : bands to work on (upper bound) */ - const Word32 *p_Rmat_fx /* i : pointer to real-space rotation matrix */ + const Word32 *p_Rmat_fx /* i : pointer to real-space rotation matrix q30*/ ) { Word16 b; @@ -5260,8 +5268,8 @@ void rotateAziEle_DirAC_fx( Word16 exp, temp; Word32 *ptr_sin, *ptr_cos; - ptr_sin = &sine_table_Q31[180]; // sin[x] = sine_table_Q31[180 + x] - ptr_cos = cosine_table_Q31; + ptr_sin = &sine_table_Q31[180]; // sin[x] = sine_table_Q31[180 + x] q31 + ptr_cos = cosine_table_Q31; // q31 push_wmops( "rotateAziEle_DirAC" ); @@ -5271,7 +5279,7 @@ void rotateAziEle_DirAC_fx( IF( GT_16( abs_s( ele[b] ), 180 ) ) { // cos(180 + x) = -cos(x) - w_fx = L_negate( ptr_cos[sub( abs_s( ele[b] ), 180 )] ); // Q31 + w_fx = L_negate( ptr_cos[abs( ele[b] ) - 180] ); // Q31 } ELSE { @@ -5282,11 +5290,11 @@ void rotateAziEle_DirAC_fx( IF( GT_16( abs_s( azi[b] ), 180 ) ) { // cos(180 + x) = -cos(x) - tmp = L_negate( ptr_cos[sub( abs_s( azi[b] ), 180 )] ); // Q31 + tmp = L_negate( ptr_cos[abs( azi[b] ) - 180] ); // Q31 } ELSE { - tmp = ptr_cos[abs_s( azi[b] )]; // Q31 + tmp = ptr_cos[abs( azi[b] )]; // Q31 move32(); } @@ -5296,13 +5304,13 @@ void rotateAziEle_DirAC_fx( IF( GT_16( azi[b], 180 ) ) { // sin(180 + x) = -sin(x) - tmp = L_negate( ptr_sin[sub( azi[b], 180 )] ); // Q31 + tmp = L_negate( ptr_sin[azi[b] - 180] ); // Q31 move32(); } ELSE IF( LT_16( azi[b], -180 ) ) { // sin(-(180 + x)) = sin(180 + x) = sinx - tmp = ptr_sin[sub( abs_s( azi[b] ), 180 )]; // Q31 + tmp = ptr_sin[abs( azi[b] ) - 180]; // Q31 move32(); } ELSE @@ -5315,13 +5323,13 @@ void rotateAziEle_DirAC_fx( IF( GT_16( ele[b], 180 ) ) { // sin(180 + x) = -sin(x) - dv_2_fx = L_negate( ptr_sin[sub( ele[b], 180 )] ); // Q31 + dv_2_fx = L_negate( ptr_sin[ele[b] - 180] ); // Q31 move32(); } ELSE IF( LT_16( ele[b], -180 ) ) { // sin(-(180 + x)) = -sin(180 + x) = sinx - dv_2_fx = ptr_sin[sub( abs_s( ele[b] ), 180 )]; // Q31 + dv_2_fx = ptr_sin[abs( ele[b] ) - 180]; // Q31 move32(); } ELSE @@ -5341,7 +5349,7 @@ void rotateAziEle_DirAC_fx( tmp = L_add( Mpy_32_32( dv_r_0_fx, dv_r_0_fx ), Mpy_32_32( dv_r_1_fx, dv_r_1_fx ) ); // Q27 exp = sub( 31, Q27 ); - tmp = Sqrt32( tmp, &exp ); + tmp = Sqrt32( tmp, &exp ); // q=31-exp temp = BASOP_util_atan2( dv_r_2_fx, tmp, sub( sub( 31, 29 ), exp ) ); // Q13 ele[b] = shr( mult( temp, _180_OVER_PI_Q9 ), 7 ); // Q0 move16(); @@ -5775,7 +5783,7 @@ static void ivas_masa_ext_dirac_render_sf( #else static void ivas_masa_ext_dirac_render_sf_fx( MASA_EXT_REND_HANDLE hMasaExtRend, /* i/o: IVAS decoder structure */ - Word32 *output_f_fx[] /* i/o: synthesized core-coder transport channels/DirAC output */ + Word32 *output_f_fx[] /* i/o: synthesized core-coder transport channels/DirAC output q11*/ ) { Word16 i, ch, idx_in, idx_lfe; @@ -5826,10 +5834,24 @@ static void ivas_masa_ext_dirac_render_sf_fx( DirAC_mem = hDirACRend->stack_mem; - onset_filter_fx = DirAC_mem.onset_filter_fx; - reference_power_fix = DirAC_mem.reference_power_fx; - reference_power_smooth_fx = ( DirAC_mem.reference_power_fx == NULL ) ? NULL : DirAC_mem.reference_power_fx + hSpatParamRendCom->num_freq_bands; - onset_filter_subframe_fx = ( DirAC_mem.onset_filter_fx == NULL ) ? NULL : DirAC_mem.onset_filter_fx + hSpatParamRendCom->num_freq_bands; + onset_filter_fx = DirAC_mem.onset_filter_fx; // q31 + reference_power_fix = DirAC_mem.reference_power_fx; // DirAC_mem.reference_power_q + IF( ( DirAC_mem.reference_power_fx == NULL ) ) + { + reference_power_smooth_fx = NULL; + } + ELSE + { + reference_power_smooth_fx = DirAC_mem.reference_power_fx + hSpatParamRendCom->num_freq_bands; // DirAC_mem.reference_power_q + } + IF( ( DirAC_mem.onset_filter_fx == NULL ) ) + { + onset_filter_subframe_fx = NULL; + } + ELSE + { + onset_filter_subframe_fx = DirAC_mem.onset_filter_fx + hSpatParamRendCom->num_freq_bands; // q31 + } coherence_flag = 1; /* There is always coherence assumed for ext rend of MASA */ move16(); /* Construct default MASA band mapping */ @@ -5857,7 +5879,7 @@ static void ivas_masa_ext_dirac_render_sf_fx( Copy( hSpatParamRendCom->azimuth[hSpatParamRendCom->render_to_md_map[subframe_idx]], azimuth, hSpatParamRendCom->num_freq_bands ); Copy( hSpatParamRendCom->elevation[hSpatParamRendCom->render_to_md_map[subframe_idx]], elevation, hSpatParamRendCom->num_freq_bands ); - Copy32( hSpatParamRendCom->diffuseness_vector_fx[hSpatParamRendCom->render_to_md_map[subframe_idx]], diffuseness_vector_fx, hSpatParamRendCom->num_freq_bands ); + Copy32( hSpatParamRendCom->diffuseness_vector_fx[hSpatParamRendCom->render_to_md_map[subframe_idx]], diffuseness_vector_fx, hSpatParamRendCom->num_freq_bands ); // q30 IF( NE_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) { @@ -5889,22 +5911,22 @@ static void ivas_masa_ext_dirac_render_sf_fx( move16(); FOR( i = 0; i < hSpatParamRendCom->num_freq_bands; i++ ) { - dirEne_fx = hDirACRend->h_output_synthesis_psd_state.direct_power_factor_fx[i]; + dirEne_fx = hDirACRend->h_output_synthesis_psd_state.direct_power_factor_fx[i]; // 29 move32(); - surCohEner_fx = Mpy_32_16_1( hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_fx[i], hSpatParamRendCom->surroundingCoherence_fx[md_idx][i] ); // Q.29 - hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_fx[i] = L_sub( hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_fx[i], surCohEner_fx ); + surCohEner_fx = Mpy_32_16_1( hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_fx[i], hSpatParamRendCom->surroundingCoherence_fx[md_idx][i] ); // Q.29 + hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_fx[i] = L_sub( hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_fx[i], surCohEner_fx ); // q29 move32(); - hDirACRend->h_output_synthesis_psd_state.direct_power_factor_fx[i] = L_add( hDirACRend->h_output_synthesis_psd_state.direct_power_factor_fx[i], surCohEner_fx ); + hDirACRend->h_output_synthesis_psd_state.direct_power_factor_fx[i] = L_add( hDirACRend->h_output_synthesis_psd_state.direct_power_factor_fx[i], surCohEner_fx ); // q29 move32(); - surCohRatio_fx[i] = L_deposit_h( BASOP_Util_Divide3232_Scale( surCohEner_fx, L_add( L_add( 1, dirEne_fx ), surCohEner_fx ), &surCohRatio_exp[i] ) ); + surCohRatio_fx[i] = L_deposit_h( BASOP_Util_Divide3232_Scale( surCohEner_fx, L_add( L_add( 1, dirEne_fx ), surCohEner_fx ), &surCohRatio_exp[i] ) ); // 31-surCohRatio_exp move32(); temp_exp = s_max( temp_exp, surCohRatio_exp[i] ); } FOR( i = 0; i < hSpatParamRendCom->num_freq_bands; i++ ) { - surCohRatio_fx[i] = L_shr( surCohRatio_fx[i], sub( temp_exp, surCohRatio_exp[i] ) ); + surCohRatio_fx[i] = L_shr( surCohRatio_fx[i], sub( temp_exp, surCohRatio_exp[i] ) ); // 31-temp_exp move32(); } Q_surCohRatio = sub( 31, temp_exp ); @@ -5932,7 +5954,7 @@ static void ivas_masa_ext_dirac_render_sf_fx( { FOR( i = 0; i < hSpatParamRendCom->num_freq_bands; i++ ) { - surCohRatio_fx[i] = L_deposit_h( hSpatParamRendCom->surroundingCoherence_fx[md_idx][i] ); + surCohRatio_fx[i] = L_deposit_h( hSpatParamRendCom->surroundingCoherence_fx[md_idx][i] ); // q31 move32(); } } @@ -6022,18 +6044,18 @@ static void ivas_masa_ext_dirac_render_sf_fx( move16(); IF( LT_16( DirAC_mem.reference_power_q, DirAC_mem.reference_power_smooth_q ) ) { - Scale_sig32( reference_power_fix + hSpatParamRendCom->num_freq_bands, sub( DirAC_mem.reference_power_len, hSpatParamRendCom->num_freq_bands ), sub( DirAC_mem.reference_power_q, DirAC_mem.reference_power_smooth_q ) ); + Scale_sig32( reference_power_fix + hSpatParamRendCom->num_freq_bands, sub( DirAC_mem.reference_power_len, hSpatParamRendCom->num_freq_bands ), sub( DirAC_mem.reference_power_q, DirAC_mem.reference_power_smooth_q ) ); // DirAC_mem.reference_power_q DirAC_mem.reference_power_smooth_q = DirAC_mem.reference_power_q; move16(); } ELSE { - Scale_sig32( reference_power_fix, hSpatParamRendCom->num_freq_bands, sub( DirAC_mem.reference_power_smooth_q, DirAC_mem.reference_power_q ) ); + Scale_sig32( reference_power_fix, hSpatParamRendCom->num_freq_bands, sub( DirAC_mem.reference_power_smooth_q, DirAC_mem.reference_power_q ) ); // DirAC_mem.reference_power_smooth_q DirAC_mem.reference_power_q = DirAC_mem.reference_power_smooth_q; move16(); } temp_proto_frame_q = sub( getScaleFactor32( hDirACRend->proto_frame_f_fx, hDirACRend->proto_frame_f_len ), 2 ); - Scale_sig32( hDirACRend->proto_frame_f_fx, hDirACRend->proto_frame_f_len, temp_proto_frame_q ); + Scale_sig32( hDirACRend->proto_frame_f_fx, hDirACRend->proto_frame_f_len, temp_proto_frame_q ); // hDirACRend->proto_frame_f_q+temp_proto_frame_q hDirACRend->proto_frame_f_q = add( hDirACRend->proto_frame_f_q, temp_proto_frame_q ); move16(); } @@ -6059,18 +6081,18 @@ static void ivas_masa_ext_dirac_render_sf_fx( move16(); IF( LT_16( DirAC_mem.reference_power_q, DirAC_mem.reference_power_smooth_q ) ) { - Scale_sig32( reference_power_fix + hSpatParamRendCom->num_freq_bands, sub( DirAC_mem.reference_power_len, hSpatParamRendCom->num_freq_bands ), sub( DirAC_mem.reference_power_q, DirAC_mem.reference_power_smooth_q ) ); + Scale_sig32( reference_power_fix + hSpatParamRendCom->num_freq_bands, sub( DirAC_mem.reference_power_len, hSpatParamRendCom->num_freq_bands ), sub( DirAC_mem.reference_power_q, DirAC_mem.reference_power_smooth_q ) ); // DirAC_mem.reference_power_q DirAC_mem.reference_power_smooth_q = DirAC_mem.reference_power_q; move16(); } ELSE { - Scale_sig32( reference_power_fix, hSpatParamRendCom->num_freq_bands, sub( DirAC_mem.reference_power_smooth_q, DirAC_mem.reference_power_q ) ); + Scale_sig32( reference_power_fix, hSpatParamRendCom->num_freq_bands, sub( DirAC_mem.reference_power_smooth_q, DirAC_mem.reference_power_q ) ); // DirAC_mem.reference_power_smooth_q DirAC_mem.reference_power_q = DirAC_mem.reference_power_smooth_q; move16(); } temp_proto_frame_q = sub( getScaleFactor32( hDirACRend->proto_frame_f_fx, hDirACRend->proto_frame_f_len ), 2 ); - Scale_sig32( hDirACRend->proto_frame_f_fx, hDirACRend->proto_frame_f_len, temp_proto_frame_q ); + Scale_sig32( hDirACRend->proto_frame_f_fx, hDirACRend->proto_frame_f_len, temp_proto_frame_q ); // hDirACRend->proto_frame_f_q+temp_proto_frame_q hDirACRend->proto_frame_f_q = add( hDirACRend->proto_frame_f_q, temp_proto_frame_q ); move16(); @@ -6093,19 +6115,19 @@ static void ivas_masa_ext_dirac_render_sf_fx( IF( LT_16( DirAC_mem.reference_power_q, DirAC_mem.reference_power_smooth_q ) ) { - Scale_sig32( reference_power_fix + hSpatParamRendCom->num_freq_bands, sub( DirAC_mem.reference_power_len, hSpatParamRendCom->num_freq_bands ), sub( DirAC_mem.reference_power_q, DirAC_mem.reference_power_smooth_q ) ); + Scale_sig32( reference_power_fix + hSpatParamRendCom->num_freq_bands, sub( DirAC_mem.reference_power_len, hSpatParamRendCom->num_freq_bands ), sub( DirAC_mem.reference_power_q, DirAC_mem.reference_power_smooth_q ) ); // DirAC_mem.reference_power_q DirAC_mem.reference_power_smooth_q = DirAC_mem.reference_power_q; move16(); } ELSE { - Scale_sig32( reference_power_fix, hSpatParamRendCom->num_freq_bands, sub( DirAC_mem.reference_power_smooth_q, DirAC_mem.reference_power_q ) ); + Scale_sig32( reference_power_fix, hSpatParamRendCom->num_freq_bands, sub( DirAC_mem.reference_power_smooth_q, DirAC_mem.reference_power_q ) ); // DirAC_mem.reference_power_smooth_q DirAC_mem.reference_power_q = DirAC_mem.reference_power_smooth_q; move16(); } temp_proto_frame_q = sub( getScaleFactor32( hDirACRend->proto_frame_f_fx, hDirACRend->proto_frame_f_len ), 2 ); - Scale_sig32( hDirACRend->proto_frame_f_fx, hDirACRend->proto_frame_f_len, temp_proto_frame_q ); + Scale_sig32( hDirACRend->proto_frame_f_fx, hDirACRend->proto_frame_f_len, temp_proto_frame_q ); // hDirACRend->proto_frame_f_q+temp_proto_frame_q hDirACRend->proto_frame_f_q = add( hDirACRend->proto_frame_f_q, temp_proto_frame_q ); move16(); @@ -6140,7 +6162,7 @@ static void ivas_masa_ext_dirac_render_sf_fx( v_multc_fixed( onset_filter_fx, 536870912 /* 0.25f in Q31 */, onset_filter_fx, hSpatParamRendCom->num_freq_bands ); /* Q31 */ v_add_fixed( onset_filter_fx, onset_filter_subframe_fx, onset_filter_subframe_fx, hSpatParamRendCom->num_freq_bands, 0 ); /* Q31 */ - p_onset_filter_fx = onset_filter_subframe_fx; + p_onset_filter_fx = onset_filter_subframe_fx; /*q31*/ } ELSE { @@ -6161,23 +6183,23 @@ static void ivas_masa_ext_dirac_render_sf_fx( hDirACRend->h_freq_domain_decorr_ap_params, hDirACRend->h_freq_domain_decorr_ap_state ); - hDirACRend->proto_frame_dec_f_fx = DirAC_mem.frame_dec_f_fx; + hDirACRend->proto_frame_dec_f_fx = DirAC_mem.frame_dec_f_fx; // DirAC_mem.frame_dec_f_q hDirACRend->proto_frame_dec_f_q = DirAC_mem.frame_dec_f_q; move16(); - p_onset_filter_fx = onset_filter_fx; + p_onset_filter_fx = onset_filter_fx; // q31 } } ELSE { IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) { - set32_fx( onset_filter_subframe_fx, ONE_IN_Q31, hSpatParamRendCom->num_freq_bands ); - p_onset_filter_fx = onset_filter_subframe_fx; + set32_fx( onset_filter_subframe_fx, ONE_IN_Q31, hSpatParamRendCom->num_freq_bands ); // q31 + p_onset_filter_fx = onset_filter_subframe_fx; // q31 } ELSE { /* no frequency domain decorrelation: use prototype frame */ - hDirACRend->proto_frame_dec_f_fx = hDirACRend->proto_frame_f_fx; + hDirACRend->proto_frame_dec_f_fx = hDirACRend->proto_frame_f_fx; // q31 hDirACRend->proto_frame_dec_f_q = hDirACRend->proto_frame_f_q; p_onset_filter_fx = NULL; } @@ -6193,11 +6215,11 @@ static void ivas_masa_ext_dirac_render_sf_fx( /* Compute diffuse prototypes */ ivas_dirac_dec_compute_diffuse_proto_fx( hDirACRend, hSpatParamRendCom->num_freq_bands, slot_idx ); } - Scale_sig32( h_dirac_output_synthesis_state->diffuse_power_factor_fx, hSpatParamRendCom->num_freq_bands, sub( 31, h_dirac_output_synthesis_state->diffuse_power_factor_q ) ); + Scale_sig32( h_dirac_output_synthesis_state->diffuse_power_factor_fx, hSpatParamRendCom->num_freq_bands, sub( 31, h_dirac_output_synthesis_state->diffuse_power_factor_q ) ); // q31 h_dirac_output_synthesis_state->diffuse_power_factor_q = Q31; move16(); - Scale_sig32( hDirACRend->h_output_synthesis_psd_state.direct_power_factor_fx, hSpatParamRendCom->num_freq_bands, sub( 31, hDirACRend->h_output_synthesis_psd_state.direct_power_factor_q ) ); + Scale_sig32( hDirACRend->h_output_synthesis_psd_state.direct_power_factor_fx, hSpatParamRendCom->num_freq_bands, sub( 31, hDirACRend->h_output_synthesis_psd_state.direct_power_factor_q ) ); // q31 hDirACRend->h_output_synthesis_psd_state.direct_power_factor_q = Q31; move16(); @@ -6221,12 +6243,12 @@ static void ivas_masa_ext_dirac_render_sf_fx( IF( NE_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) { - Scale_sig32( DirAC_mem.reference_power_fx, DirAC_mem.reference_power_len, -1 ); + Scale_sig32( DirAC_mem.reference_power_fx, DirAC_mem.reference_power_len, -1 ); // DirAC_mem.reference_power_q-1 DirAC_mem.reference_power_q = sub( DirAC_mem.reference_power_q, 1 ); move16(); DirAC_mem.reference_power_smooth_q = DirAC_mem.reference_power_q; move16(); - v_add_fixed( reference_power_fix, reference_power_smooth_fx, reference_power_smooth_fx, hSpatParamRendCom->num_freq_bands, 0 ); + v_add_fixed( reference_power_fix, reference_power_smooth_fx, reference_power_smooth_fx, hSpatParamRendCom->num_freq_bands, 0 ); // DirAC_mem.reference_power_smooth_q } } /*Rescaling proto_direct_buffer_f*/ @@ -6242,14 +6264,14 @@ static void ivas_masa_ext_dirac_render_sf_fx( { FOR( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[subframe_idx]; slot_idx++ ) { - Scale_sig32( &hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_fx[i_mult( slot_idx, idiv1616( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_len, hSpatParamRendCom->subframe_nbslots[subframe_idx] ) )], idiv1616( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_len, hSpatParamRendCom->subframe_nbslots[subframe_idx] ), sub( temp, proto_direct_buffer_f_temp_q[slot_idx] ) ); + Scale_sig32( &hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_fx[( slot_idx * ( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_len / hSpatParamRendCom->subframe_nbslots[subframe_idx] ) )], idiv1616( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_len, hSpatParamRendCom->subframe_nbslots[subframe_idx] ), sub( temp, proto_direct_buffer_f_temp_q[slot_idx] ) ); // temp } } ELSE { FOR( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[subframe_idx]; slot_idx++ ) { - Scale_sig32( &hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_fx[i_mult( slot_idx, idiv1616( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_len, hSpatParamRendCom->subframe_nbslots[subframe_idx] ) )], idiv1616( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_len, hSpatParamRendCom->subframe_nbslots[subframe_idx] ), sub( temp, proto_direct_buffer_f_temp_q[slot_idx] ) ); + Scale_sig32( &hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_fx[( slot_idx * ( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_len / hSpatParamRendCom->subframe_nbslots[subframe_idx] ) )], idiv1616( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_len, hSpatParamRendCom->subframe_nbslots[subframe_idx] ), sub( temp, proto_direct_buffer_f_temp_q[slot_idx] ) ); // temp } } hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q = temp; @@ -6259,13 +6281,13 @@ static void ivas_masa_ext_dirac_render_sf_fx( ivas_dirac_dec_output_synthesis_get_interpolator_fx( &hDirACRend->h_output_synthesis_psd_params, hSpatParamRendCom->subframe_nbslots[subframe_idx] ); /*Memories Scaling*/ - Scale_sig32( hDirACRend->h_output_synthesis_psd_state.direct_power_factor_fx, hSpatParamRendCom->num_freq_bands, sub( 31, hDirACRend->h_output_synthesis_psd_state.direct_power_factor_q ) ); + Scale_sig32( hDirACRend->h_output_synthesis_psd_state.direct_power_factor_fx, hSpatParamRendCom->num_freq_bands, sub( 31, hDirACRend->h_output_synthesis_psd_state.direct_power_factor_q ) ); // q31 hDirACRend->h_output_synthesis_psd_state.direct_power_factor_q = Q31; move16(); - Scale_sig32( hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_fx, hSpatParamRendCom->num_freq_bands, sub( 31, hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_q ) ); + Scale_sig32( hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_fx, hSpatParamRendCom->num_freq_bands, sub( 31, hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_q ) ); // q31 hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_q = Q31; move16(); - Scale_sig32( hDirACRend->h_output_synthesis_psd_state.direct_responses_fx, hDirACRend->num_outputs_dir * hSpatParamRendCom->num_freq_bands, sub( 31, hDirACRend->h_output_synthesis_psd_state.direct_responses_q ) ); + Scale_sig32( hDirACRend->h_output_synthesis_psd_state.direct_responses_fx, hDirACRend->num_outputs_dir * hSpatParamRendCom->num_freq_bands, sub( 31, hDirACRend->h_output_synthesis_psd_state.direct_responses_q ) ); // q31 hDirACRend->h_output_synthesis_psd_state.direct_responses_q = Q31; move16(); @@ -6276,27 +6298,27 @@ static void ivas_masa_ext_dirac_render_sf_fx( FOR( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[subframe_idx]; slot_idx++ ) { Scale_sig32( Cldfb_RealBuffer_fx[ch][slot_idx], - hSpatParamRendCom->num_freq_bands, sub( 6, q_cldfb ) ); + hSpatParamRendCom->num_freq_bands, sub( 6, q_cldfb ) ); // q6 Scale_sig32( Cldfb_ImagBuffer_fx[ch][slot_idx], - hSpatParamRendCom->num_freq_bands, sub( 6, q_cldfb ) ); + hSpatParamRendCom->num_freq_bands, sub( 6, q_cldfb ) ); // q6 } } q_cldfb = 6; move16(); - Scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_fx, hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_len, sub( 26, hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth ) ); + Scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_fx, hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_len, sub( 26, hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth ) ); // q26 hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth = Q26; move16(); - Scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_fx, hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_len, sub( 26, hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth ) ); + Scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_fx, hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_len, sub( 26, hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth ) ); // q26 hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth = Q26; move16(); - Scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_prev_fx, hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_prev_len, sub( 26, hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth_prev ) ); + Scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_prev_fx, hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_prev_len, sub( 26, hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth_prev ) ); // q26 hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth_prev = Q26; move16(); - Scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev_fx, hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev_len, sub( 26, hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev ) ); + Scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev_fx, hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev_len, sub( 26, hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev ) ); // q26 hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev = Q26; move16(); @@ -6326,8 +6348,8 @@ static void ivas_masa_ext_dirac_render_sf_fx( Word16 new_proto_diffuse_buffer_f_q = getScaleFactor32( hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_fx, hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_len ); Word16 new_proto_direct_buffer_f_q = getScaleFactor32( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_fx, hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_len ); - scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_fx, hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_len, new_proto_diffuse_buffer_f_q ); - scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_fx, hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_len, new_proto_direct_buffer_f_q ); + scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_fx, hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_len, new_proto_diffuse_buffer_f_q ); // hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_q + new_proto_diffuse_buffer_f_q + scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_fx, hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_len, new_proto_direct_buffer_f_q ); // hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q + new_proto_direct_buffer_f_q hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q = add( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q, new_proto_direct_buffer_f_q ); move16(); hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_q = add( hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_q, new_proto_diffuse_buffer_f_q ); @@ -6340,42 +6362,42 @@ static void ivas_masa_ext_dirac_render_sf_fx( FOR( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[subframe_idx]; slot_idx++ ) { scale_sig32( Cldfb_RealBuffer_fx[ch][slot_idx], - hSpatParamRendCom->num_freq_bands, sub( 11, q_cldfb ) ); + hSpatParamRendCom->num_freq_bands, sub( 11, q_cldfb ) ); // q11 scale_sig32( Cldfb_ImagBuffer_fx[ch][slot_idx], - hSpatParamRendCom->num_freq_bands, sub( 11, q_cldfb ) ); + hSpatParamRendCom->num_freq_bands, sub( 11, q_cldfb ) ); // q11 } } q_cldfb = 11; move16(); Word16 reference_power_temp_q = getScaleFactor32( DirAC_mem.reference_power_fx, DirAC_mem.reference_power_len ); - scale_sig32( DirAC_mem.reference_power_fx, DirAC_mem.reference_power_len, reference_power_temp_q ); + scale_sig32( DirAC_mem.reference_power_fx, DirAC_mem.reference_power_len, reference_power_temp_q ); /*DirAC_mem.reference_power_q + reference_power_temp_q*/ DirAC_mem.reference_power_q = add( DirAC_mem.reference_power_q, reference_power_temp_q ); move16(); DirAC_mem.reference_power_smooth_q = add( DirAC_mem.reference_power_q, reference_power_temp_q ); move16(); Word16 q_cy_auto_diff_smooth = getScaleFactor32( h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx, h_dirac_output_synthesis_state->cy_auto_diff_smooth_len ); - Scale_sig32( h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx, h_dirac_output_synthesis_state->cy_auto_diff_smooth_len, q_cy_auto_diff_smooth ); + Scale_sig32( h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx, h_dirac_output_synthesis_state->cy_auto_diff_smooth_len, q_cy_auto_diff_smooth ); // h_dirac_output_synthesis_state->q_cy_auto_diff_smooth+ q_cy_auto_diff_smooth h_dirac_output_synthesis_state->q_cy_auto_diff_smooth = add( h_dirac_output_synthesis_state->q_cy_auto_diff_smooth, q_cy_auto_diff_smooth ); move16(); - Scale_sig32( hDirACRend->h_output_synthesis_psd_state.direct_responses_square_fx, hDirACRend->num_outputs_dir * hSpatParamRendCom->num_freq_bands, sub( 31, hDirACRend->h_output_synthesis_psd_state.direct_responses_square_q ) ); + Scale_sig32( hDirACRend->h_output_synthesis_psd_state.direct_responses_square_fx, hDirACRend->num_outputs_dir * hSpatParamRendCom->num_freq_bands, sub( 31, hDirACRend->h_output_synthesis_psd_state.direct_responses_square_q ) ); // q31 hDirACRend->h_output_synthesis_psd_state.direct_responses_square_q = Q31; move16(); - Scale_sig32( h_dirac_output_synthesis_state->diffuse_power_factor_fx, hSpatParamRendCom->num_freq_bands, sub( 31, h_dirac_output_synthesis_state->diffuse_power_factor_q ) ); + Scale_sig32( h_dirac_output_synthesis_state->diffuse_power_factor_fx, hSpatParamRendCom->num_freq_bands, sub( 31, h_dirac_output_synthesis_state->diffuse_power_factor_q ) ); // q31 h_dirac_output_synthesis_state->diffuse_power_factor_q = Q31; move16(); - Scale_sig32( h_dirac_output_synthesis_state->direct_responses_fx, hSpatParamRendCom->num_freq_bands, sub( 31, h_dirac_output_synthesis_state->direct_responses_q ) ); + Scale_sig32( h_dirac_output_synthesis_state->direct_responses_fx, hSpatParamRendCom->num_freq_bands, sub( 31, h_dirac_output_synthesis_state->direct_responses_q ) ); // q31 h_dirac_output_synthesis_state->direct_responses_q = Q31; move16(); /*Q-adjustment*/ IF( hDirACRend->masa_stereo_type_detect ) { - hDirACRend->masa_stereo_type_detect->subtract_power_y_smooth_fx = L_shl( hDirACRend->masa_stereo_type_detect->subtract_power_y_smooth_fx, sub( s_min( hDirACRend->masa_stereo_type_detect->q_subtract_power_y_smooth, hDirACRend->masa_stereo_type_detect->q_subtract_power_y ), hDirACRend->masa_stereo_type_detect->q_subtract_power_y_smooth ) ); + hDirACRend->masa_stereo_type_detect->subtract_power_y_smooth_fx = L_shl( hDirACRend->masa_stereo_type_detect->subtract_power_y_smooth_fx, sub( s_min( hDirACRend->masa_stereo_type_detect->q_subtract_power_y_smooth, hDirACRend->masa_stereo_type_detect->q_subtract_power_y ), hDirACRend->masa_stereo_type_detect->q_subtract_power_y_smooth ) ); // s_min( hDirACRend->masa_stereo_type_detect->q_subtract_power_y_smooth, hDirACRend->masa_stereo_type_detect->q_subtract_power_y ) move32(); - hDirACRend->masa_stereo_type_detect->subtract_power_y_fx = L_shl( hDirACRend->masa_stereo_type_detect->subtract_power_y_fx, sub( s_min( hDirACRend->masa_stereo_type_detect->q_subtract_power_y_smooth, hDirACRend->masa_stereo_type_detect->q_subtract_power_y ), hDirACRend->masa_stereo_type_detect->q_subtract_power_y ) ); + hDirACRend->masa_stereo_type_detect->subtract_power_y_fx = L_shl( hDirACRend->masa_stereo_type_detect->subtract_power_y_fx, sub( s_min( hDirACRend->masa_stereo_type_detect->q_subtract_power_y_smooth, hDirACRend->masa_stereo_type_detect->q_subtract_power_y ), hDirACRend->masa_stereo_type_detect->q_subtract_power_y ) ); // s_min( hDirACRend->masa_stereo_type_detect->q_subtract_power_y_smooth, hDirACRend->masa_stereo_type_detect->q_subtract_power_y ) move32(); hDirACRend->masa_stereo_type_detect->q_subtract_power_y_smooth = s_min( hDirACRend->masa_stereo_type_detect->q_subtract_power_y_smooth, hDirACRend->masa_stereo_type_detect->q_subtract_power_y ); @@ -6384,25 +6406,25 @@ static void ivas_masa_ext_dirac_render_sf_fx( move16(); } - Scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_fx, hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_len, sub( s_min( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q, hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q ), hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q ) ); + Scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_fx, hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_len, sub( s_min( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q, hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q ), hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q ) ); // s_min( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q, hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q ) hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q = s_min( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q, hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q ); move16(); - Scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_fx, hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_len, sub( s_min( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q, hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q ), hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q ) ); + Scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_fx, hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_len, sub( s_min( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q, hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q ), hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q ) ); // s_min( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q, hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q ) hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q = s_min( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q, hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q ); move16(); Word16 proto_power_diff_smooth_prev_temp_q = getScaleFactor32( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_fx, hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_len ); - Scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_fx, hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_len, proto_power_diff_smooth_prev_temp_q ); + Scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_fx, hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_len, proto_power_diff_smooth_prev_temp_q ); // hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_q + proto_power_diff_smooth_prev_temp_q hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_q = add( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_q, proto_power_diff_smooth_prev_temp_q ); move16(); Word16 proto_power_diff_smooth_temp_q = getScaleFactor32( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_fx, hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_len ); - Scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_fx, hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_len, proto_power_diff_smooth_temp_q ); + Scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_fx, hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_len, proto_power_diff_smooth_temp_q ); // hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_q + proto_power_diff_smooth_temp_q hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_q = add( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_q, proto_power_diff_smooth_temp_q ); move16(); - Scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_fx, hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_len, sub( s_min( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_q, hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_q ), hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_q ) ); - Scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_fx, hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_len, sub( s_min( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_q, hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_q ), hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_q ) ); + Scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_fx, hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_len, sub( s_min( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_q, hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_q ), hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_q ) ); // s_min( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_q, hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_q ) + Scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_fx, hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_len, sub( s_min( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_q, hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_q ), hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_q ) ); // s_min( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_q, hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_q ) hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_q = s_min( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_q, hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_q ); move16(); hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_q = s_min( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_q, hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_q ); @@ -6412,8 +6434,8 @@ static void ivas_masa_ext_dirac_render_sf_fx( /*Buffer rescaling*/ - Scale_sig32( hDirACRend->h_output_synthesis_psd_state.reference_power_smooth_prev_fx, hSpatParamRendCom->num_freq_bands, sub( s_min( hDirACRend->h_output_synthesis_psd_state.reference_power_smooth_prev_q, DirAC_mem.reference_power_q ), hDirACRend->h_output_synthesis_psd_state.reference_power_smooth_prev_q ) ); - Scale_sig32( DirAC_mem.reference_power_fx, DirAC_mem.reference_power_len, sub( s_min( hDirACRend->h_output_synthesis_psd_state.reference_power_smooth_prev_q, DirAC_mem.reference_power_q ), DirAC_mem.reference_power_q ) ); + Scale_sig32( hDirACRend->h_output_synthesis_psd_state.reference_power_smooth_prev_fx, hSpatParamRendCom->num_freq_bands, sub( s_min( hDirACRend->h_output_synthesis_psd_state.reference_power_smooth_prev_q, DirAC_mem.reference_power_q ), hDirACRend->h_output_synthesis_psd_state.reference_power_smooth_prev_q ) ); // s_min( hDirACRend->h_output_synthesis_psd_state.reference_power_smooth_prev_q, DirAC_mem.reference_power_q ) + Scale_sig32( DirAC_mem.reference_power_fx, DirAC_mem.reference_power_len, sub( s_min( hDirACRend->h_output_synthesis_psd_state.reference_power_smooth_prev_q, DirAC_mem.reference_power_q ), DirAC_mem.reference_power_q ) ); // s_min( hDirACRend->h_output_synthesis_psd_state.reference_power_smooth_prev_q, DirAC_mem.reference_power_q ) hDirACRend->h_output_synthesis_psd_state.reference_power_smooth_prev_q = s_min( hDirACRend->h_output_synthesis_psd_state.reference_power_smooth_prev_q, DirAC_mem.reference_power_q ); move16(); @@ -6439,13 +6461,13 @@ static void ivas_masa_ext_dirac_render_sf_fx( move16(); IF( LT_16( DirAC_mem.reference_power_q, DirAC_mem.reference_power_smooth_q ) ) { - Scale_sig32( reference_power_fix + hSpatParamRendCom->num_freq_bands, sub( DirAC_mem.reference_power_len, hSpatParamRendCom->num_freq_bands ), sub( DirAC_mem.reference_power_q, DirAC_mem.reference_power_smooth_q ) ); + Scale_sig32( reference_power_fix + hSpatParamRendCom->num_freq_bands, sub( DirAC_mem.reference_power_len, hSpatParamRendCom->num_freq_bands ), sub( DirAC_mem.reference_power_q, DirAC_mem.reference_power_smooth_q ) ); // DirAC_mem.reference_power_q DirAC_mem.reference_power_smooth_q = DirAC_mem.reference_power_q; move16(); } ELSE { - Scale_sig32( reference_power_fix, hSpatParamRendCom->num_freq_bands, sub( DirAC_mem.reference_power_smooth_q, DirAC_mem.reference_power_q ) ); + Scale_sig32( reference_power_fix, hSpatParamRendCom->num_freq_bands, sub( DirAC_mem.reference_power_smooth_q, DirAC_mem.reference_power_q ) ); // DirAC_mem.reference_power_smooth_q DirAC_mem.reference_power_q = DirAC_mem.reference_power_smooth_q; move16(); } @@ -6482,9 +6504,9 @@ static void ivas_masa_ext_dirac_render_sf_fx( FOR( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[subframe_idx]; slot_idx++ ) { scale_sig32( Cldfb_RealBuffer_fx[ch][slot_idx], - hSpatParamRendCom->num_freq_bands, scale_factor ); + hSpatParamRendCom->num_freq_bands, scale_factor ); // q_cldfb+scale_factor scale_sig32( Cldfb_ImagBuffer_fx[ch][slot_idx], - hSpatParamRendCom->num_freq_bands, scale_factor ); + hSpatParamRendCom->num_freq_bands, scale_factor ); // q_cldfb+scale_factor } } q_cldfb = add( q_cldfb, scale_factor ); @@ -6503,7 +6525,7 @@ static void ivas_masa_ext_dirac_render_sf_fx( IF( hDirACRend->hOutSetup.num_lfe > 0 && ( EQ_16( hDirACRend->hOutSetup.index_lfe[idx_lfe], ch ) ) ) { /* No LFE for MASA rendering */ - set32_fx( &( output_f_fx[ch][imult1616( index_slot, hSpatParamRendCom->num_freq_bands )] ), 0, hSpatParamRendCom->subframe_nbslots[subframe_idx] * hSpatParamRendCom->num_freq_bands ); + set32_fx( &( output_f_fx[ch][index_slot * hSpatParamRendCom->num_freq_bands] ), 0, imult1616( hSpatParamRendCom->subframe_nbslots[subframe_idx], hSpatParamRendCom->num_freq_bands ) ); IF( LT_16( idx_lfe, sub( hDirACRend->hOutSetup.num_lfe, 1 ) ) ) { @@ -6514,17 +6536,17 @@ static void ivas_masa_ext_dirac_render_sf_fx( { /* open CLDFB buffer up to CLDFB_NO_CHANNELS_MAX bands for 48kHz */ Word16 q_out = sub( q_cldfb, 1 ); - scale_sig32( hMasaExtRend->cldfbSynRend[idx_in]->cldfb_state_fx, hMasaExtRend->cldfbSynRend[idx_in]->cldfb_state_length, sub( q_out, hMasaExtRend->cldfbSynRend[idx_in]->Q_cldfb_state ) ); + scale_sig32( hMasaExtRend->cldfbSynRend[idx_in]->cldfb_state_fx, hMasaExtRend->cldfbSynRend[idx_in]->cldfb_state_length, sub( q_out, hMasaExtRend->cldfbSynRend[idx_in]->Q_cldfb_state ) ); // q_out hMasaExtRend->cldfbSynRend[idx_in]->Q_cldfb_state = q_out; move16(); FOR( i = 0; i < hSpatParamRendCom->subframe_nbslots[subframe_idx]; i++ ) { - RealBuffer_fx[i] = Cldfb_RealBuffer_fx[idx_in][i]; - ImagBuffer_fx[i] = Cldfb_ImagBuffer_fx[idx_in][i]; + RealBuffer_fx[i] = Cldfb_RealBuffer_fx[idx_in][i]; // q_cldfb + ImagBuffer_fx[i] = Cldfb_ImagBuffer_fx[idx_in][i]; // q_cldfb } Word16 out_size = imult1616( hSpatParamRendCom->num_freq_bands, hSpatParamRendCom->subframe_nbslots[subframe_idx] ); cldfbSynthesis_ivas_fx( RealBuffer_fx, ImagBuffer_fx, &( output_f_fx[ch][index_slot * hSpatParamRendCom->num_freq_bands] ), out_size, hMasaExtRend->cldfbSynRend[idx_in] ); - scale_sig32( &( output_f_fx[ch][index_slot * hSpatParamRendCom->num_freq_bands] ), out_size, sub( 11, q_out ) ); + scale_sig32( &( output_f_fx[ch][index_slot * hSpatParamRendCom->num_freq_bands] ), out_size, sub( 11, q_out ) ); // q11 idx_in++; } } @@ -6580,7 +6602,7 @@ void ivas_masa_ext_dirac_render( #else void ivas_masa_ext_dirac_render_fx( MASA_EXT_REND_HANDLE hMasaExtRend, /* i/o: MASA renderer structure */ - Word32 *output_f[], /* i/o: input/output signals in time domain */ + Word32 *output_f[], /* i/o: input/output signals in time domain q11*/ const Word16 num_subframes /* i : number of subframes to render */ ) { @@ -6595,7 +6617,7 @@ void ivas_masa_ext_dirac_render_fx( FOR( n = 0; n < MAX_OUTPUT_CHANNELS; n++ ) { - output_f_local[n] = output_f[n]; + output_f_local[n] = output_f[n]; // q11 } hSpatParamRendCom->subframes_rendered = hSpatParamRendCom->dirac_read_idx; diff --git a/lib_rend/ivas_prot_rend.h b/lib_rend/ivas_prot_rend.h index 8a9e8185d..8752094ce 100644 --- a/lib_rend/ivas_prot_rend.h +++ b/lib_rend/ivas_prot_rend.h @@ -442,26 +442,26 @@ void ivas_dirac_free_mem_fx( ); void initDiffuseResponses_fx( - Word16 *diffuse_response_function_fx, - const int16_t num_channels, + Word16 *diffuse_response_function_fx, /*q15*/ + const Word16 num_channels, const AUDIO_CONFIG output_config, const IVAS_OUTPUT_SETUP hOutSetup, - const int16_t ambisonics_order, + const Word16 ambisonics_order, const IVAS_FORMAT ivas_format, - int16_t *num_ele_spk_no_diffuse_rendering, + Word16 *num_ele_spk_no_diffuse_rendering, const AUDIO_CONFIG transport_config ); #endif #ifdef IVAS_FLOAT_FIXED void computeIntensityVector_dec_fx( - Word32 Cldfb_RealBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], - Word32 Cldfb_ImagBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], + Word32 Cldfb_RealBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /*q_cldfb*/ + Word32 Cldfb_ImagBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /*q_cldfb*/ Word16 q_cldfb, const Word16 num_frequency_bands, - Word32 *intensity_real_x_fx, - Word32 *intensity_real_y_fx, - Word32 *intensity_real_z_fx, + Word32 *intensity_real_x_fx, /*q_intensity_real*/ + Word32 *intensity_real_y_fx, /*q_intensity_real*/ + Word32 *intensity_real_z_fx, /*q_intensity_real*/ Word16 *q_intensity_real ); #else @@ -476,19 +476,19 @@ void computeIntensityVector_dec( #endif #ifdef IVAS_FLOAT_FIXED void protoSignalComputation_shd_fx( - Word32 RealBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], - Word32 ImagBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], - Word32 *proto_direct_buffer_f_fx, + Word32 RealBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /*Q(q_cldfb)*/ + Word32 ImagBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /*Q(q_cldfb)*/ + Word32 *proto_direct_buffer_f_fx, /*Q(proto_direct_buffer_f_q)*/ Word16 *proto_direct_buffer_f_q, - Word32 *proto_diffuse_buffer_f_fx, + Word32 *proto_diffuse_buffer_f_fx, /*Q(proto_diffuse_buffer_f_q)*/ Word16 *proto_diffuse_buffer_f_q, - Word32 *reference_power_fx, + Word32 *reference_power_fx, /*Q(reference_power_q)*/ Word16 *reference_power_q, const Word16 slot_index, const Word16 num_inputs, const Word16 num_outputs_diff, const Word16 num_freq_bands, - Word32 *p_Rmat_fx, + Word32 *p_Rmat_fx, /* Q30 */ Word16 q_cldfb ); #endif @@ -507,15 +507,15 @@ void protoSignalComputation_shd( #ifdef IVAS_FLOAT_FIXED void protoSignalComputation1_fx( - Word32 RealBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], - Word32 ImagBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], - Word32 *proto_frame_f_fx, + Word32 RealBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /*q_cldfb*/ + Word32 ImagBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /*q_cldfb*/ + Word32 *proto_frame_f_fx, /*proto_frame_f_q*/ Word16 *proto_frame_f_q, - Word32 *proto_direct_buffer_f_fx, + Word32 *proto_direct_buffer_f_fx, /*proto_direct_buffer_f_q*/ Word16 *proto_direct_buffer_f_q, - Word32 *reference_power_fx, + Word32 *reference_power_fx, /*reference_power_q*/ Word16 *reference_power_q, - Word32 *proto_power_smooth_fx, + Word32 *proto_power_smooth_fx, /*proto_power_smooth_q*/ Word16 *proto_power_smooth_q, const Word16 slot_index, const Word16 num_outputs_diff, @@ -537,15 +537,15 @@ void protoSignalComputation1( #ifdef IVAS_FLOAT_FIXED void protoSignalComputation2_fx( - Word32 RealBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], - Word32 ImagBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], - Word32 *proto_frame_f_fx, + Word32 RealBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /*q_cldfb*/ + Word32 ImagBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /*q_cldfb*/ + Word32 *proto_frame_f_fx, /*q_proto_frame_f*/ Word16 *q_proto_frame_f, - Word32 *proto_direct_buffer_f_fx, + Word32 *proto_direct_buffer_f_fx, /*q_proto_direct_buffer_f*/ Word16 *q_proto_direct_buffer_f, - Word32 *reference_power_fx, + Word32 *reference_power_fx, /*q_reference_power*/ Word16 *q_reference_power, - Word32 *proto_power_smooth_fx, + Word32 *proto_power_smooth_fx, /*q_proto_power_smooth*/ Word16 *q_proto_power_smooth, const Word16 isloudspeaker, const Word16 slot_index, @@ -569,20 +569,20 @@ void protoSignalComputation2( #ifdef IVAS_FLOAT_FIXED void protoSignalComputation4_fx( - Word32 RealBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], - Word32 ImagBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], - Word32 *proto_frame_f_fx, + Word32 RealBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /*q_cldfb*/ + Word32 ImagBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /*q_cldfb*/ + Word32 *proto_frame_f_fx, /*proto_frame_f_q*/ Word16 *proto_frame_f_q, - Word32 *proto_direct_buffer_f_fx, + Word32 *proto_direct_buffer_f_fx, /*proto_direct_buffer_f_q*/ Word16 *proto_direct_buffer_f_q, - Word32 *reference_power_fx, + Word32 *reference_power_fx, /*reference_power_q*/ Word16 *reference_power_q, - Word32 *proto_power_smooth_fx, + Word32 *proto_power_smooth_fx, /*proto_power_smooth_q*/ Word16 *proto_power_smooth_q, const Word16 slot_index, const Word16 num_outputs_diff, const Word16 num_freq_bands, - const Word32 *mtx_hoa_decoder, + const Word32 *mtx_hoa_decoder, /*q29*/ const Word16 nchan_transport, const Word16 *sba_map_tc_ind, Word16 q_cldfb @@ -623,9 +623,9 @@ void ivas_dirac_dec_compute_diffuse_proto_fx( #ifdef IVAS_FLOAT_FIXED void computeDirectionAngles_fx( - Word32 *intensity_real_x_fx, - Word32 *intensity_real_y_fx, - Word32 *intensity_real_z_fx, + Word32 *intensity_real_x_fx, /*q_intensity_real*/ + Word32 *intensity_real_y_fx, /*q_intensity_real*/ + Word32 *intensity_real_z_fx, /*q_intensity_real*/ Word16 q_intensity_real, const Word16 num_frequency_bands, Word16 *azimuth, @@ -664,10 +664,10 @@ void ivas_masa_stereotype_detection( #ifdef IVAS_FLOAT_FIXED void ivas_lfe_synth_with_cldfb_fx( MCMASA_LFE_SYNTH_DATA_HANDLE hMasaLfeSynth, - Word32 RealBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], - Word32 ImagBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], - Word32 RealBufferLfe_fx[MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], - Word32 ImagBufferLfe_fx[MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], + Word32 RealBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /*q_cldfb*/ + Word32 ImagBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /*q_cldfb*/ + Word32 RealBufferLfe_fx[MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /*q_cldfb*/ + Word32 ImagBufferLfe_fx[MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /*q_cldfb*/ const Word16 slot_index, const Word16 subframe_index, const Word16 nchan_transport, @@ -688,11 +688,11 @@ void ivas_lfe_synth_with_cldfb( #ifdef IVAS_FLOAT_FIXED void rotateAziEle_DirAC_fx( - Word16 *azi, - Word16 *ele, - const Word16 band1, - const Word16 band2, - const Word32 *p_Rmat_fx + Word16 *azi, /* i/o: array of azimuth values */ + Word16 *ele, /* i/o: array of elevation values */ + const Word16 band1, /* i : bands to work on (lower limit) */ + const Word16 band2, /* i : bands to work on (upper bound) */ + const Word32 *p_Rmat_fx /* i : pointer to real-space rotation matrix q30*/ ); #endif void rotateAziEle_DirAC( @@ -953,11 +953,11 @@ void compute_hoa_encoder_mtx( #ifdef IVAS_FLOAT_FIXED void compute_hoa_encoder_mtx_fx( - const Word32 *azimuth, - const Word32 *elevation, - Word32 *response_fx, + const Word32 *azimuth, /*q22*/ + const Word32 *elevation, /*q22*/ + Word32 *response_fx, /*q31*/ const Word16 num_responses, - const Word16 ambisonics_order); + const Word16 ambisonics_order ); #endif #ifndef IVAS_FLOAT_FIXED @@ -1103,9 +1103,9 @@ void ivas_masa_ext_dirac_render( ); #else void ivas_masa_ext_dirac_render_fx( - MASA_EXT_REND_HANDLE hMasaExtRend, /* i/o: MASA renderer structure */ - Word32 *output_f[], /* i/o: input/output signals in time domain */ - const Word16 num_subframes /* i : number of subframes to render */ + MASA_EXT_REND_HANDLE hMasaExtRend, /* i/o: MASA renderer structure */ + Word32 *output_f[], /* i/o: input/output signals in time domain q11*/ + const Word16 num_subframes /* i : number of subframes to render */ ); #endif /*----------------------------------------------------------------------------------* -- GitLab From 8d6ed7a697a8f4846cfda0beb37a91263ad8743b Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Mon, 28 Oct 2024 09:51:32 +0530 Subject: [PATCH 046/128] Clang formatting correction for MR 715 --- lib_dec/jbm_pcmdsp_similarityestimation.h | 2 +- lib_enc/ivas_front_vad.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib_dec/jbm_pcmdsp_similarityestimation.h b/lib_dec/jbm_pcmdsp_similarityestimation.h index 9a76a63f8..7e18c3394 100644 --- a/lib_dec/jbm_pcmdsp_similarityestimation.h +++ b/lib_dec/jbm_pcmdsp_similarityestimation.h @@ -181,4 +181,4 @@ Word32 cross_correlation_self_fx( const Word16 *signal, Word8 isSilence_fx( const Word16 *signal, Word16 len, Word16 segments ); #endif /* IVAS_FLOAT_FIXED */ -#endif /* JBM_PCMDSP_SIMILARITYESTIMATION_H */ \ No newline at end of file +#endif /* JBM_PCMDSP_SIMILARITYESTIMATION_H */ diff --git a/lib_enc/ivas_front_vad.c b/lib_enc/ivas_front_vad.c index 64296eb11..a4f7731e1 100644 --- a/lib_enc/ivas_front_vad.c +++ b/lib_enc/ivas_front_vad.c @@ -420,8 +420,8 @@ ivas_error front_vad_fx( noise_est_pre_32fx( Etot_fx, hFrontVads[0]->ini_frame, hFrontVad->hNoiseEst, 0, 0, 0 ); /* wb_vad */ - Scale_sig32( hFrontVads[n]->hNoiseEst->bckr_fx, NB_BANDS, Q_new + QSCALE - ( Q_new_old + QSCALE )); - Scale_sig32( hFrontVads[n]->hNoiseEst->enrO_fx, NB_BANDS, Q_new + QSCALE - ( Q_new_old + QSCALE )); + Scale_sig32( hFrontVads[n]->hNoiseEst->bckr_fx, NB_BANDS, Q_new + QSCALE - ( Q_new_old + QSCALE ) ); + Scale_sig32( hFrontVads[n]->hNoiseEst->enrO_fx, NB_BANDS, Q_new + QSCALE - ( Q_new_old + QSCALE ) ); hFrontVad->hNoiseEst->sign_dyn_lp_fx = extract_h( hFrontVad->hNoiseEst->sign_dyn_lp_32fx ); hFrontVad->hNoiseEst->Etot_v_h2_fx = extract_h( hFrontVad->hNoiseEst->Etot_v_h2_32fx ); hFrontVad->hVAD->vad_flag = wb_vad_ivas_fx( sts[n], fr_bands_fx[n], &dummy, &dummy, &dummy, &snr_sum_he_fx, &localVAD_HE_SAD[n], &dummy_short, Q_new, hFrontVad->hVAD, hFrontVad->hNoiseEst, hFrontVad->lp_speech_fx, hFrontVad->lp_noise_fx ); -- GitLab From b081a0d8247c3e1e2c8799b73e36d3e75ad15f43 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Mon, 28 Oct 2024 10:45:54 +0530 Subject: [PATCH 047/128] Fix for 3GPP issue 949 --- lib_com/lpc_tools_fx.c | 214 ++++++++++++++++++++++++++++++++++++++++ lib_com/preemph_fx.c | 55 +++++++++++ lib_com/prot_fx.h | 4 + lib_dec/er_dec_tcx_fx.c | 7 +- 4 files changed, 277 insertions(+), 3 deletions(-) diff --git a/lib_com/lpc_tools_fx.c b/lib_com/lpc_tools_fx.c index 26a9549d6..bfb5d8ed1 100644 --- a/lib_com/lpc_tools_fx.c +++ b/lib_com/lpc_tools_fx.c @@ -579,6 +579,220 @@ Word16 E_LPC_lev_dur_stab( const Word16 Rh[], const Word16 Rl[], Word16 A[], Wor return ( flag ); } +Word16 E_LPC_lev_dur_ivas_fx( const Word16 Rh[], const Word16 Rl[], Word16 A[], Word32 epsP[], const Word16 order, Word16 *mem ) +{ + return ( E_LPC_lev_dur_stab_ivas_fx( Rh, Rl, A, epsP, order, mem, 32750 ) ); /* 0.99945 in Q15 */ +} + +Word16 E_LPC_lev_dur_stab_ivas_fx( const Word16 Rh[], const Word16 Rl[], Word16 A[], Word32 epsP[], const Word16 order, Word16 *mem, Word16 k_max ) +{ + Word16 i, j, k; + Word16 hi, lo; + Word16 Kh, Kl; /* reflection coefficient; hi and lo */ + Word16 alp_h, alp_l, alp_exp; /* Prediction gain; hi lo and exponent */ + Word32 t0, t1, t2; /* temporary variables */ + Word16 flag; + Word16 Ah[TCXLTP_LTP_ORDER + 1], Al[TCXLTP_LTP_ORDER + 1]; /* LPC coef. in double prec. */ +#ifdef BASOP_NOGLOB_DECLARE_LOCAL + Flag Overflow = 0; +#endif + + + BASOP_SATURATE_WARNING_OFF_EVS + if ( epsP != NULL ) + { + epsP[0] = L_Comp( Rh[0], Rl[0] ); + move32(); + } + + flag = 0; + move16(); + + /* K = A[1] = -R[1] / R[0] */ + t1 = L_Comp( Rh[1], Rl[1] ); /* R[1] in Q31 */ + t2 = L_abs( t1 ); /* abs R[1] */ + t0 = L_deposit_l( 0 ); + IF( Rh[0] != 0 ) + { + t0 = Div_32_opt( t2, Rh[0], Rl[0] ); /* R[1]/R[0] in Q31 */ + /* Cause a difference in MODE1 due to different implementation of div32*/ + } + if ( t1 > 0 ) + { + t0 = L_negate( t0 ); /* -R[1]/R[0] */ + } + Kl = L_Extract_lc( t0, &Kh ); /* K in DPF */ + t0 = L_shr( t0, 4 ); /* A[1] in Q27 */ + L_Extract( t0, &Ah[1], &Al[1] ); /* A[1] in DPF */ + + /* Alpha = R[0] * (1-K**2) */ + t0 = Sqr_32( Kh, Kl ); /* K*K in Q31 */ + t0 = L_abs( t0 ); /* Some case <0 !! */ + t0 = L_sub( (Word32) 0x7fffffffL, t0 ); /* 1 - K*K in Q31 */ + lo = L_Extract_lc( t0, &hi ); /* DPF format */ + t0 = Mpy_32( Rh[0], Rl[0], hi, lo ); /* Alpha in Q31 */ + if ( epsP != NULL ) + { + epsP[1] = t0; + move32(); + } + + /* Normalize Alpha */ + alp_exp = norm_l( t0 ); + t0 = L_shl( t0, alp_exp ); + alp_l = L_Extract_lc( t0, &alp_h ); + /* DPF format */ + + /*--------------------------------------* + * ITERATIONS I=2 to m + *--------------------------------------*/ + + FOR( i = 2; i <= order; i++ ) + { + /* t0 = SUM(R[j]*A[i-j], j=1, i-1) + R[i] */ + t0 = L_deposit_l( 0 ); + FOR( j = 1; j < i; j++ ) + { + t0 = Mac_32( t0, Rh[j], Rl[j], Ah[i - j], Al[i - j] ); + } + +#ifdef BASOP_NOGLOB + t0 = L_shl_o( t0, 4, &Overflow ); /* result in Q27 -> convert to Q31 */ +#else /* BASOP_NOGLOB */ + t0 = L_shl( t0, 4 ); /* result in Q27 -> convert to Q31 */ +#endif /* BASOP_NOGLOB */ + /* No overflow possible */ + + /* Compose and add R[i] in Q3 */ +#ifdef BASOP_NOGLOB + t0 = L_mac_o( t0, Rl[i], 1, &Overflow ); + t0 = L_msu_o( t0, Rh[i], -32768, &Overflow ); +#else /* BASOP_NOGLOB */ + t0 = L_mac( t0, Rl[i], 1 ); + t0 = L_msu( t0, Rh[i], -32768 ); +#endif /* BASOP_NOGLOB */ + + /* K = -t0 / Alpha */ + t1 = L_abs( t0 ); + t2 = L_deposit_l( 0 ); + IF( alp_h != 0 ) + { + t2 = Div_32_opt( t1, alp_h, alp_l ); /* abs(t0)/Alpha */ + /* Cause a difference in MODE1 due to different implementation of div32*/ + } + + if ( t0 > 0 ) + { + t2 = L_negate( t2 ); /* K =-t0/Alpha */ + } +#ifdef BASOP_NOGLOB + t2 = L_shl_o( t2, alp_exp, &Overflow ); /* denormalize; compare to Alpha */ +#else /* BASOP_NOGLOB */ + t2 = L_shl( t2, alp_exp ); /* denormalize; compare to Alpha */ +#endif /* BASOP_NOGLOB */ + test(); + if ( ( mem != NULL ) && ( ( GT_16( abs_s( extract_h( t2 ) ), k_max ) ) ) ) + { + flag = 1; + move16(); /* Test for unstable filter. If unstable keep old A(z) */ + } + test(); + if ( ( mem != NULL ) && ( ( LT_32( L_abs( t2 ), 5 ) ) ) ) + { + flag = 1; + move16(); /*R matrix not reliable (R saturated for many coeff), keep old A(z) */ + } + Kl = L_Extract_lc( t2, &Kh ); /* K in DPF */ + + /*------------------------------------------* + * Compute new LPC coeff. -> An[i] + * An[j]= A[j] + K*A[i-j] , j=1 to i-1 + * An[i]= K + *------------------------------------------*/ + + k = mult_r( i, 16384 ); + FOR( j = 1; j < k; j++ ) + { + /* Do two Iterations Together to Allow Direct Update of Ah & Al */ + t0 = Mac_32( L_Comp( Ah[j], Al[j] ), Kh, Kl, Ah[i - j], Al[i - j] ); + t1 = Mac_32( L_Comp( Ah[i - j], Al[i - j] ), Kh, Kl, Ah[j], Al[j] ); + L_Extract( t0, &Ah[j], &Al[j] ); + L_Extract( t1, &Ah[i - j], &Al[i - j] ); + } + IF( s_and( i, 1 ) == 0 ) + { + t0 = Mac_32( L_Comp( Ah[j], Al[j] ), Kh, Kl, Ah[i - j], Al[i - j] ); + L_Extract( t0, &Ah[j], &Al[j] ); + } + t2 = L_shr( t2, 4 ); /* t2 = K in Q31 ->convert to Q27 */ + L_Extract( t2, &Ah[i], &Al[i] ); /* An[i] in Q27 */ + + /* Alpha = Alpha * (1-K**2) */ +#ifdef BASOP_NOGLOB + t1 = L_mult_o( Kh, Kh, &Overflow ); /* K*K in Q31 */ +#else /* BASOP_NOGLOB */ + t1 = L_mult( Kh, Kh ); /* K*K in Q31 */ +#endif /* BASOP_NOGLOB */ + t0 = L_mac( t1, mult( Kh, Kl ), 2 ); + t0 = L_abs( t0 ); /* Some case <0 !! */ + t0 = L_sub( (Word32) 0x7fffffffL, t0 ); /* 1 - K*K in Q31 */ + lo = L_Extract_lc( t0, &hi ); /* DPF format */ + t0 = Mpy_32( alp_h, alp_l, hi, lo ); /* Alpha in Q31 */ + + + /* store denormalized alpha in epsP */ + t1 = L_shr( t0, alp_exp ); + if ( epsP != NULL ) + { + epsP[i] = t1; + move32(); + } + + /* Normalize Alpha */ + j = norm_l( t0 ); + t0 = L_shl( t0, j ); + alp_l = L_Extract_lc( t0, &alp_h ); /* DPF format */ + alp_exp = add( alp_exp, j ); /* Add normalization to alp_exp */ + } + + /* Adaptive scaling */ + t1 = L_deposit_l( 0 ); + FOR( i = 1; i <= order; i++ ) + { + t0 = L_Comp( Ah[i], Al[i] ); + t1 = L_max( t1, L_abs( t0 ) ); + } + k = s_min( sub( norm_l( t1 ), 1 ), 3 ); + A[0] = shl( 2048, k ); + move16(); + FOR( i = 1; i <= order; i++ ) + { + t0 = L_Comp( Ah[i], Al[i] ); +#ifdef BASOP_NOGLOB + A[i] = round_fx_o( L_shl_o( t0, k, &Overflow ), &Overflow ); +#else + A[i] = round_fx( L_shl( t0, k ) ); +#endif + move16(); + } + + BASOP_SATURATE_WARNING_ON_EVS + IF( mem != NULL ) + { + /* Enforce stable LPC filter - parcorr[0] and parcorr[1] are not LPC coeffiecients */ + IF( flag ) + { + Copy( mem, A, add( order, 1 ) ); + } + ELSE /* If stable LPC filter, store into memories */ + { + Copy( A, mem, add( order, 1 ) ); + } + } + + + return ( flag ); +} Word16 E_LPC_lev_dur_fx( const Word16 Rh[], const Word16 Rl[], Word32 A[], Word32 epsP[], const Word16 order, Word32 *mem ) { diff --git a/lib_com/preemph_fx.c b/lib_com/preemph_fx.c index 63de35dca..13a0b5e42 100644 --- a/lib_com/preemph_fx.c +++ b/lib_com/preemph_fx.c @@ -158,3 +158,58 @@ Word16 E_UTIL_f_preemph3( Word16 *signal, const Word16 mu, const Word16 lg, Word return Q_new; } + +Word16 E_UTIL_f_preemph3_ivas_fx( Word16 *signal, const Word16 mu, const Word16 lg, Word16 *mem, Word16 bits ) +{ + Word16 i, QVal, mus, tmp_fixed, Q_new; + Word32 L_tmp, L_maxloc; + + + QVal = shl( 1, sub( 15, bits ) ); + mus = shr( mu, bits ); + + L_tmp = L_mult( signal[0], QVal ); + L_tmp = L_msu( L_tmp, *mem, mus ); + L_maxloc = L_abs( L_tmp ); + + FOR( i = 1; i < lg; i++ ) + { + L_tmp = L_mult( signal[i], QVal ); + L_tmp = L_msu( L_tmp, signal[i - 1], mus ); + L_tmp = L_abs( L_tmp ); + L_maxloc = L_max( L_tmp, L_maxloc ); + } + + tmp_fixed = extract_h( L_maxloc ); + + Q_new = Q_MAX; + move16(); + IF( tmp_fixed != 0 ) + { + Q_new = sub( norm_s( tmp_fixed ), bits ); + Q_new = s_max( Q_new, 0 ); + Q_new = sub( s_min( Q_new, Q_MAX ), 1 ); + } + + tmp_fixed = signal[lg - 1]; + move16(); + + FOR( i = sub( lg, 1 ); i > 0; i-- ) + { + L_tmp = L_mult( signal[i], QVal ); + L_tmp = L_msu( L_tmp, signal[i - 1], mus ); + L_tmp = L_shl( L_tmp, Q_new ); + signal[i] = round_fx( L_tmp ); + move16(); + } + + L_tmp = L_mult( signal[0], QVal ); + L_tmp = L_msu( L_tmp, *mem, mus ); + L_tmp = L_shl( L_tmp, Q_new ); + signal[0] = round_fx( L_tmp ); + move16(); + *mem = tmp_fixed; + move16(); + + return Q_new; +} diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index 70d2f94b0..a148ab903 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -1114,6 +1114,9 @@ void autocorr_fx_32( Word16 E_LPC_lev_dur( const Word16 Rh[], const Word16 Rl[], Word16 A[], Word32 epsP[], const Word16 order, Word16 *parcorr ); Word16 E_LPC_lev_dur_stab( const Word16 Rh[], const Word16 Rl[], Word16 A[], Word32 epsP[], const Word16 order, Word16 *parcorr, Word16 k_max ); +Word16 E_LPC_lev_dur_ivas_fx( const Word16 Rh[], const Word16 Rl[], Word16 A[], Word32 epsP[], const Word16 order, Word16 *parcorr ); +Word16 E_LPC_lev_dur_stab_ivas_fx( const Word16 Rh[], const Word16 Rl[], Word16 A[], Word32 epsP[], const Word16 order, Word16 *parcorr, Word16 k_max ); + Word16 E_LPC_lev_dur_fx( const Word16 Rh[], const Word16 Rl[], Word32 A[], Word32 epsP[], const Word16 order, Word32 *mem ); Word16 E_LPC_lev_dur_stab_fx( const Word16 Rh[], const Word16 Rl[], Word32 A[], Word32 epsP[], const Word16 order, Word32 *mem, Word16 k_max ); @@ -2609,6 +2612,7 @@ void preemph_copy_fx( void E_UTIL_f_preemph2( Word16 shift, Word16 *signal, const Word16 mu, const Word16 lg, Word16 *mem ); Word16 E_UTIL_f_preemph3( Word16 *signal, const Word16 mu, const Word16 lg, Word16 *mem, Word16 bits ); +Word16 E_UTIL_f_preemph3_ivas_fx( Word16 *signal, const Word16 mu, const Word16 lg, Word16 *mem, Word16 bits ); // swb_bwe_com_fx.c Word16 WB_BWE_gain_pred_fx( Word16 *WB_fenv, /* o : WB frequency envelopes */ diff --git a/lib_dec/er_dec_tcx_fx.c b/lib_dec/er_dec_tcx_fx.c index 1a1dbce92..bbe1276f1 100644 --- a/lib_dec/er_dec_tcx_fx.c +++ b/lib_dec/er_dec_tcx_fx.c @@ -1263,7 +1263,7 @@ void con_tcx_ivas_fx( /* apply pre-emphasis to the signal */ mem = synth[( -( ( ( L_frame / 2 ) + hTcxDec->pit_max_TCX ) + M + M ) - 1 )]; /*Q0*/ move16(); - Q_exc = E_UTIL_f_preemph3( &( synth[-add( add( shr( L_frame, 1 ), hTcxDec->pit_max_TCX ), 2 * M )] ), st->preemph_fac, add( add( shr( L_frame, 1 ), hTcxDec->pit_max_TCX ), shl( M, 1 ) ), &mem, 1 ); + Q_exc = E_UTIL_f_preemph3_ivas_fx( &( synth[-add( add( shr( L_frame, 1 ), hTcxDec->pit_max_TCX ), 2 * M )] ), st->preemph_fac, add( add( shr( L_frame, 1 ), hTcxDec->pit_max_TCX ), shl( M, 1 ) ), &mem, 1 ); st->Mode2_lp_gainc = L_deposit_l( 0 ); st->Mode2_lp_gainp = get_gain2( synth - shl( L_subfr, 1 ), synth - add( shl( L_subfr, 1 ), Tc ), shl( L_subfr, 1 ) ); @@ -1286,7 +1286,7 @@ void con_tcx_ivas_fx( lag_wind( r_h, r_l, M, st->output_Fs, LAGW_STRONG ); /* Levinson Durbin */ - E_LPC_lev_dur( r_h, r_l, A_local, NULL, M, NULL ); + E_LPC_lev_dur_ivas_fx( r_h, r_l, A_local, NULL, M, NULL ); /* copy for multiple frame loss */ Copy( A_local, st->old_Aq_12_8_fx, M + 1 ); /*Q14*/ @@ -1308,7 +1308,7 @@ void con_tcx_ivas_fx( /* apply pre-emphasis to the signal */ mem = synth[( -L_frame - 1 )]; /*Q0*/ move16(); - Q_exc = E_UTIL_f_preemph3( &( synth[-L_frame] ), st->preemph_fac, L_frame, &mem, 1 ); + Q_exc = E_UTIL_f_preemph3_ivas_fx( &( synth[-L_frame] ), st->preemph_fac, L_frame, &mem, 1 ); Copy( st->old_Aq_12_8_fx, A_local, M + 1 ); /*Q14*/ offset = shr( L_frame, 1 ); @@ -2029,6 +2029,7 @@ void con_tcx_ivas_fx( } } #endif + E_UTIL_synthesis( sub( Q_exc, Q_syn ), A_local, -- GitLab From 90757f51146f38c9fe434f9e5976d0521a05ab55 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Mon, 28 Oct 2024 11:53:21 +0530 Subject: [PATCH 048/128] Fix for 3GPP issue 960: Decoder crash for OSBA_2ISM_HOA3 at 32kbps with FER in pitch_pred_linear_fit() --- lib_dec/pitch_extr_fx.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib_dec/pitch_extr_fx.c b/lib_dec/pitch_extr_fx.c index f1e69ae68..54ecc67d8 100644 --- a/lib_dec/pitch_extr_fx.c +++ b/lib_dec/pitch_extr_fx.c @@ -163,6 +163,9 @@ void pitch_pred_linear_fit( { Word32 t1, t2, t3, t4, t5, t6, t7; Word16 e1, e2, e3, e4, e5, e6, e7; +#ifdef BASOP_NOGLOB + Flag Overflow; +#endif t1 = L_mult0( pg[4], pg[3] ); /*Q24*/ /* t1 = pg[4]*pg[3] */ e1 = 7; move16(); @@ -185,8 +188,12 @@ void pitch_pred_linear_fit( t6 = BASOP_Util_Add_Mant32Exp( t3, e3, t4, e4, &e6 ); t7 = BASOP_Util_Add_Mant32Exp( t5, e5, t6, e6, &e7 ); /*Q31,e7*/ sum0_q = norm_l( t7 ); +#ifdef BASOP_NOGLOB + sum0 = round_fx_o( L_shl( t7, sum0_q ), &Overflow ); /*Q15,e7-sum0_q*/ +#else sum0 = round_fx( L_shl( t7, sum0_q ) ); /*Q15,e7-sum0_q*/ - sum0_q = add( 15, sub( sum0_q, e7 ) ); /* sum0 is now Qsum0_q*/ +#endif + sum0_q = add( 15, sub( sum0_q, e7 ) ); /* sum0 is now Qsum0_q*/ } pit = 0; -- GitLab From a9832a36cfb67cb68396ff3b13adceedf27e8917 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Mon, 28 Oct 2024 16:22:12 +0530 Subject: [PATCH 049/128] SBA path function integration, dirac enc cleanup, Q-info updates [x] spar_md_enc_process integration and cleanup [x] ivas_dirac_enc_cleanup [x] Q-info_updates --- lib_com/bitallocsum_fx.c | 10 +- lib_com/bits_alloc_fx.c | 197 ++-- lib_com/bitstream.c | 17 +- lib_com/bitstream_fx.c | 110 +- lib_com/ivas_dirac_com.c | 4 +- lib_com/ivas_prot.h | 119 +-- lib_com/ivas_qmetadata_com.c | 3 +- lib_com/ivas_spar_com.c | 1551 ++-------------------------- lib_com/ivas_spar_com_quant_util.c | 87 +- lib_com/ivas_stat_com.h | 26 +- lib_dec/gain_dec_fx.c | 442 ++++---- lib_dec/gaus_dec_fx.c | 44 +- lib_enc/ivas_dirac_enc.c | 534 ++++------ lib_enc/ivas_enc.c | 28 +- lib_enc/ivas_init_enc.c | 61 +- lib_enc/ivas_masa_enc.c | 19 - lib_enc/ivas_mct_enc.c | 26 - lib_enc/ivas_spar_encoder.c | 105 +- lib_enc/ivas_spar_md_enc.c | 361 +++---- lib_enc/ivas_stat_enc.h | 26 +- 20 files changed, 1096 insertions(+), 2674 deletions(-) diff --git a/lib_com/bitallocsum_fx.c b/lib_com/bitallocsum_fx.c index c8ad205e1..fa71c92f8 100644 --- a/lib_com/bitallocsum_fx.c +++ b/lib_com/bitallocsum_fx.c @@ -25,12 +25,12 @@ void bitallocsum_fx( Word16 total, tmp; Word16 diff; - total = (Word16) 0; + total = 0; move16(); FOR( i = 0; i < nb_sfm; i++ ) { - tmp = extract_l( L_mult0( R[i], sfmsize[i] ) ); - Rsubband[i] = shl( tmp, 3 ); + tmp = extract_l( L_mult0( R[i], sfmsize[i] ) ); // Q0 + Rsubband[i] = shl( tmp, 3 ); // Q3 move16(); total = add( total, tmp ); } @@ -40,7 +40,7 @@ void bitallocsum_fx( IF( LE_16( length, L_FRAME32k ) ) { diff = sub( num_bits, *sum ); - i = (Word16) 0; + i = 0; move16(); WHILE( diff > 0 ) { @@ -55,7 +55,7 @@ void bitallocsum_fx( i = add( i, 1 ); if ( GE_16( i, nb_sfm ) ) { - i = (Word16) 0; + i = 0; move16(); } } diff --git a/lib_com/bits_alloc_fx.c b/lib_com/bits_alloc_fx.c index 2e0c018c8..1c247a9fb 100644 --- a/lib_com/bits_alloc_fx.c +++ b/lib_com/bits_alloc_fx.c @@ -51,14 +51,10 @@ void BITS_ALLOC_init_config_acelp( { Word8 rate_mode_index; - - move16(); - move16(); - move16(); rate_mode_index = (Word8) GT_32( bit_rate, ACELP_9k60 ); pConfigAcelp->mode_index = rate_mode_index; - + move16(); /*LPC: midLpc should be swithced off?*/ pConfigAcelp->midLpc_enable = 1; @@ -155,7 +151,8 @@ Word16 BITS_ALLOC_config_acelp( } } - IF( L_and( EQ_16( band_index, 1 ), EQ_16( nb_subfr, 4 ) ) ) + test(); + IF( EQ_16( band_index, 1 ) && EQ_16( nb_subfr, 4 ) ) { IF( coder_type == INACTIVE ) { @@ -239,7 +236,8 @@ Word16 BITS_ALLOC_config_acelp( move16(); pConfigAcelp->ltf_bits = ACELP_LTF_BITS[pConfigAcelp->ltf_mode]; - IF( L_and( EQ_16( nb_subfr, 5 ), EQ_16( pConfigAcelp->ltf_bits, 4 ) ) ) + test(); + IF( EQ_16( nb_subfr, 5 ) && EQ_16( pConfigAcelp->ltf_bits, 4 ) ) { pConfigAcelp->ltf_bits = add( pConfigAcelp->ltf_bits, 1 ); move16(); @@ -369,14 +367,15 @@ static Word16 BITS_ALLOC_adjust_generic( bits_currsubframe = sub( add( i_mult2( sfr, bits_subframe2 ), bits_subframe2 ), bitsused ); /* try increasing mode while below threshold */ - WHILE( ( LT_16( k, sub( pulseconfig_size, 1 ) ) ) && ( LE_16( i_mult2( pulseconfigbits[k + 1], nb_subfr ), bits_currsubframe ) ) ) + test(); + WHILE( ( ( k < sub( pulseconfig_size, 1 ) ) ) && ( ( i_mult2( pulseconfigbits[k + 1], nb_subfr ) <= bits_currsubframe ) ) ) { test(); k = add( k, 1 ); } /* try decreasing mode until below threshold */ - WHILE( GT_16( i_mult2( pulseconfigbits[k], nb_subfr ), bits_currsubframe ) ) + WHILE( ( i_mult2( pulseconfigbits[k], nb_subfr ) > bits_currsubframe ) ) { k = sub( k, 1 ); @@ -442,7 +441,7 @@ static Word16 fcb_table( static ivas_error acelp_FCB_allocator( Word16 *nBits, /* i/o: available bit-budget */ - Word16 fixed_cdk_index[], /* o : codebook index */ + Word16 fixed_cdk_index[], /* o : codebook index Q0 */ Word16 nb_subfr, /* i : number of subframes */ const Word16 L_subfr, /* i : subframe length */ const Word16 coder_type, /* i : coder type */ @@ -464,7 +463,6 @@ static ivas_error acelp_FCB_allocator( move16(); p_fixed_cdk_index = fixed_cdk_index; - move16(); /* TRANSITION coding: first subframe bit-budget was already fixed, glottal pulse not in the first subframe */ test(); @@ -531,7 +529,6 @@ static ivas_error acelp_FCB_allocator( IF( cdbk >= 0 ) { nBits_tmp = fcb_table( cdbk, L_subfr ); - move16(); } ELSE { @@ -545,7 +542,7 @@ static ivas_error acelp_FCB_allocator( IF( LT_16( cdbk, ACELP_FIXED_CDK_NB - 1 ) ) { step = sub( fcb_table( add( cdbk, 1 ), L_subfr ), nBits_tmp ); - WHILE( GE_16( *nBits, step ) ) + WHILE( *nBits >= step ) { ( *p_fixed_cdk_index )++; *nBits = sub( *nBits, step ); @@ -558,14 +555,16 @@ static ivas_error acelp_FCB_allocator( test(); IF( GE_16( *nBits, step ) && cdbk >= 0 ) { - fixed_cdk_index[sfr]++; + fixed_cdk_index[sfr] = add( fixed_cdk_index[sfr], 1 ); + move16(); *nBits = sub( *nBits, step ); move16(); test(); IF( GE_16( *nBits, step ) && EQ_16( fixed_cdk_index[sfr + 1], sub( fixed_cdk_index[sfr], 1 ) ) ) { - sfr++; - fixed_cdk_index[sfr]++; + sfr = add( sfr, 1 ); + fixed_cdk_index[sfr] = add( fixed_cdk_index[sfr], 1 ); + move16(); *nBits = sub( *nBits, step ); move16(); } @@ -581,7 +580,7 @@ static ivas_error acelp_FCB_allocator( /* TRANSITION coding: allocate second highest FCBQ bit-budget to the last subframe */ IF( idiv1616( tc_subfr, L_SUBFR ) < sub( nb_subfr, 1 ) ) { - SWAP( fixed_cdk_index[sub( tc_subfr, L_SUBFR ) / L_SUBFR], fixed_cdk_index[nb_subfr - 1] ); + SWAP( fixed_cdk_index[( tc_subfr - L_SUBFR ) / L_SUBFR], fixed_cdk_index[nb_subfr - 1] ); } } @@ -603,7 +602,7 @@ static ivas_error acelp_FCB_allocator( static ivas_error acelp_FCB_allocator_ivas( Word16 *nBits, /* i/o: available bit-budget */ - Word16 fixed_cdk_index[], /* o : codebook index */ + Word16 fixed_cdk_index[], /* o : codebook index Q0 */ Word16 nb_subfr, /* i : number of subframes */ const Word16 L_subfr, /* i : subframe length */ const Word16 coder_type, /* i : coder type */ @@ -625,7 +624,6 @@ static ivas_error acelp_FCB_allocator_ivas( move16(); p_fixed_cdk_index = fixed_cdk_index; - move16(); /* TRANSITION coding: first subframe bit-budget was already fixed, glottal pulse not in the first subframe */ test(); @@ -681,7 +679,6 @@ static ivas_error acelp_FCB_allocator_ivas( IF( cdbk >= 0 ) { nBits_tmp = fcb_table( cdbk, L_subfr ); - move16(); } ELSE { @@ -695,7 +692,7 @@ static ivas_error acelp_FCB_allocator_ivas( IF( LT_16( cdbk, ACELP_FIXED_CDK_NB - 1 ) ) { step = sub( fcb_table( add( cdbk, 1 ), L_subfr ), nBits_tmp ); - WHILE( GE_16( *nBits, step ) ) + WHILE( *nBits >= step ) { ( *p_fixed_cdk_index )++; *nBits = sub( *nBits, step ); @@ -710,14 +707,16 @@ static ivas_error acelp_FCB_allocator_ivas( test(); IF( GE_16( *nBits, step ) && cdbk >= 0 ) { - fixed_cdk_index[sfr]++; + fixed_cdk_index[sfr] = add( fixed_cdk_index[sfr], 1 ); + move16(); *nBits = sub( *nBits, step ); move16(); test(); IF( GE_16( *nBits, step ) && EQ_16( fixed_cdk_index[sfr + 1], sub( fixed_cdk_index[sfr], 1 ) ) ) { - sfr++; - fixed_cdk_index[sfr]++; + sfr = add( sfr, 1 ); + fixed_cdk_index[sfr] = add( fixed_cdk_index[sfr], 1 ); + move16(); *nBits = sub( *nBits, step ); move16(); } @@ -732,7 +731,7 @@ static ivas_error acelp_FCB_allocator_ivas( SWAP( fixed_cdk_index[0], fixed_cdk_index[tc_subfr / L_SUBFR] ); /* TRANSITION coding: allocate second highest FCBQ bit-budget to the last subframe */ - IF( idiv1616( tc_subfr, L_SUBFR ) < sub( nb_subfr, 1 ) ) + IF( LT_16( idiv1616( tc_subfr, L_SUBFR ), sub( nb_subfr, 1 ) ) ) { SWAP( fixed_cdk_index[sub( tc_subfr, L_SUBFR ) / L_SUBFR], fixed_cdk_index[nb_subfr - 1] ); } @@ -879,7 +878,7 @@ ivas_error config_acelp1( i = 0; move16(); - WHILE( LT_16( i, SIZE_BRATE_INTERMED_TBL ) ) + WHILE( i < SIZE_BRATE_INTERMED_TBL ) { IF( EQ_32( core_brate_inp, brate_intermed_tbl[i] ) ) { @@ -895,14 +894,14 @@ ivas_error config_acelp1( BREAK; } - i++; + i = add( i, 1 ); } test(); test(); test(); - if ( EQ_16( element_mode, IVAS_CPE_TD ) && EQ_16( coder_type, AUDIO ) && - LE_32( core_brate_inp, STEREO_GSC_BIT_RATE_ALLOC ) && EQ_32( brate_intermed_tbl[i], ACELP_9k60 ) ) /* Bit allocation should be mapped to 8 kb/s instead of 9.6 kb/s in this case */ + IF( EQ_16( element_mode, IVAS_CPE_TD ) && EQ_16( coder_type, AUDIO ) && + LE_32( core_brate_inp, STEREO_GSC_BIT_RATE_ALLOC ) && EQ_32( brate_intermed_tbl[i], ACELP_9k60 ) ) /* Bit allocation should be mapped to 8 kb/s instead of 9.6 kb/s in this case */ { i = sub( i, 1 ); } @@ -910,14 +909,14 @@ ivas_error config_acelp1( core_brate = brate_intermed_tbl[i]; move32(); - if ( GT_16( element_mode, EVS_MONO ) ) + if ( element_mode > EVS_MONO ) { flag_hardcoded = 0; /* use automatic and flexible ACELP bit-budget allocation */ move16(); } test(); - if ( NE_16( core, ACELP_CORE ) && EQ_16( element_mode, EVS_MONO ) ) /* needed for mode1 core switching in EVS mono */ + if ( ( core != ACELP_CORE ) && ( element_mode == EVS_MONO ) ) /* needed for mode1 core switching in EVS mono */ { flag_hardcoded = 1; move16(); @@ -931,11 +930,11 @@ ivas_error config_acelp1( IF( !( EQ_16( coder_type, TRANSITION ) && NE_16( tc_subfr, -1 ) ) || EQ_16( enc_dec, DEC ) ) { /* Set the bit-budget */ - bits = extract_l( Mpy_32_32( core_brate_inp, ONE_BY_FRAMES_PER_SEC_Q31 ) ); + bits = extract_l( Mpy_32_32( core_brate_inp, ONE_BY_FRAMES_PER_SEC_Q31 ) ); // Q0 test(); test(); - if ( EQ_16( coder_type, TRANSITION ) && EQ_16( enc_dec, DEC ) && EQ_16( tc_call, 1 ) ) + IF( EQ_16( coder_type, TRANSITION ) && EQ_16( enc_dec, DEC ) && EQ_16( tc_call, 1 ) ) { bits = add( bits, *nBits_es_Pred ); /* equalize for 4th signaling bit estimated at the encoder in TC_0_192 */ } @@ -947,7 +946,7 @@ ivas_error config_acelp1( { bits = sub( bits, TDM_SIGNAL_BITS_READ_FROM_THE_END_OF_BS ); - if ( EQ_16( tdm_LRTD_flag, 1 ) ) + IF( EQ_16( tdm_LRTD_flag, 1 ) ) { bits = add( bits, STEREO_BITS_TCA ); } @@ -959,7 +958,7 @@ ivas_error config_acelp1( test(); test(); test(); - if ( extl_brate > 0 && ( EQ_16( extl, WB_TBE ) || EQ_16( extl, SWB_TBE ) || EQ_16( extl, FB_TBE ) || EQ_16( extl, WB_BWE ) || EQ_16( extl, SWB_BWE ) || EQ_16( extl, FB_BWE ) ) ) + IF( extl_brate > 0 && ( EQ_16( extl, WB_TBE ) || EQ_16( extl, SWB_TBE ) || EQ_16( extl, FB_TBE ) || EQ_16( extl, WB_BWE ) || EQ_16( extl, SWB_BWE ) || EQ_16( extl, FB_BWE ) ) ) { bits = sub( bits, 1 ); } @@ -976,7 +975,7 @@ ivas_error config_acelp1( test(); test(); test(); - if ( extl_brate > 0 && ( EQ_16( extl, WB_TBE ) || EQ_16( extl, SWB_TBE ) || EQ_16( extl, FB_TBE ) || EQ_16( extl, WB_BWE ) || EQ_16( extl, SWB_BWE ) || EQ_16( extl, FB_BWE ) ) ) + IF( extl_brate > 0 && ( EQ_16( extl, WB_TBE ) || EQ_16( extl, SWB_TBE ) || EQ_16( extl, FB_TBE ) || EQ_16( extl, WB_BWE ) || EQ_16( extl, SWB_BWE ) || EQ_16( extl, FB_BWE ) ) ) { /* extension layer signalling bit is counted in the extension layer bitbudget */ bits = add( bits, 1 ); @@ -1139,7 +1138,7 @@ ivas_error config_acelp1( test(); test(); - if ( GT_16( coder_type, UNVOICED ) && LT_16( coder_type, AUDIO ) && NE_16( coder_type, VOICED ) ) + IF( GT_16( coder_type, UNVOICED ) && LT_16( coder_type, AUDIO ) && NE_16( coder_type, VOICED ) ) { bits = sub( bits, FEC_BITS_CLS ); } @@ -1151,7 +1150,7 @@ ivas_error config_acelp1( acelp_cfg->FEC_mode = 2; move16(); test(); - if ( GT_16( coder_type, UNVOICED ) && LT_16( coder_type, AUDIO ) ) + IF( GT_16( coder_type, UNVOICED ) && LT_16( coder_type, AUDIO ) ) { bits = sub( bits, FEC_BITS_ENR ); } @@ -1163,7 +1162,7 @@ ivas_error config_acelp1( move16(); test(); - if ( GT_16( coder_type, UNVOICED ) && LT_16( coder_type, AUDIO ) ) + IF( GT_16( coder_type, UNVOICED ) && LT_16( coder_type, AUDIO ) ) { bits = sub( bits, FEC_BITS_POS ); } @@ -1190,7 +1189,7 @@ ivas_error config_acelp1( acelp_cfg->ltf_mode = FULL_BAND; move16(); } - ELSE IF( ( EQ_16( coder_type, GENERIC ) || EQ_16( coder_type, TRANSITION ) ) && core_brate < ACELP_11k60 ) + ELSE IF( ( EQ_16( coder_type, GENERIC ) || EQ_16( coder_type, TRANSITION ) ) && LT_32( core_brate, ACELP_11k60 ) ) { acelp_cfg->ltf_mode = LOW_PASS; move16(); @@ -1208,7 +1207,7 @@ ivas_error config_acelp1( { acelp_cfg->ltf_mode = NORMAL_OPERATION; move16(); - if ( coder_type != TRANSITION ) + IF( coder_type != TRANSITION ) { bits = sub( bits, nb_subfr ); } @@ -1229,11 +1228,11 @@ ivas_error config_acelp1( test(); test(); test(); - if ( ( ( EQ_16( coder_type, UNVOICED ) && !( *uc_two_stage_flag ) ) || ( coder_type == INACTIVE && LE_32( core_brate, ACELP_9k60 ) ) ) && ( idchan == 0 || element_mode == EVS_MONO ) ) + IF( ( ( EQ_16( coder_type, UNVOICED ) && !( *uc_two_stage_flag ) ) || ( coder_type == INACTIVE && LE_32( core_brate, ACELP_9k60 ) ) ) && ( idchan == 0 || element_mode == EVS_MONO ) ) { bits = sub( bits, NBITS_NOISENESS ); /* noiseness */ } - if ( EQ_16( coder_type, UNVOICED ) && !( *uc_two_stage_flag ) ) + IF( EQ_16( coder_type, UNVOICED ) && !( *uc_two_stage_flag ) ) { bits = sub( bits, 3 * NB_SUBFR ); /* tilt factor */ } @@ -1257,55 +1256,55 @@ ivas_error config_acelp1( { IF( EQ_16( tc_subfr, TC_0_0 ) ) { - if ( EQ_16( enc_dec, ENC ) ) + IF( enc_dec == ENC ) { bits = sub( bits, 1 ); /* TC signalling */ } - if ( EQ_16( acelp_cfg->ltf_mode, NORMAL_OPERATION ) ) + IF( EQ_16( acelp_cfg->ltf_mode, NORMAL_OPERATION ) ) { bits = sub( bits, 3 ); /* LP filtering flag */ } } ELSE IF( EQ_16( tc_subfr, TC_0_64 ) ) { - if ( EQ_16( enc_dec, ENC ) ) + IF( enc_dec == ENC ) { bits = sub( bits, 4 ); /* TC signalling */ } - if ( EQ_16( acelp_cfg->ltf_mode, NORMAL_OPERATION ) ) + IF( EQ_16( acelp_cfg->ltf_mode, NORMAL_OPERATION ) ) { bits = sub( bits, 3 ); /* LP filtering flag */ } } ELSE IF( EQ_16( tc_subfr, TC_0_128 ) ) { - if ( EQ_16( enc_dec, ENC ) ) + IF( enc_dec == ENC ) { bits = sub( bits, 4 ); /* TC signalling */ } - if ( EQ_16( acelp_cfg->ltf_mode, NORMAL_OPERATION ) ) + IF( EQ_16( acelp_cfg->ltf_mode, NORMAL_OPERATION ) ) { bits = sub( bits, 2 ); /* LP filtering flag */ } } ELSE IF( EQ_16( tc_subfr, TC_0_192 ) ) { - if ( EQ_16( enc_dec, ENC ) ) + IF( enc_dec == ENC ) { bits = sub( bits, 3 ); /* TC signalling */ } - if ( EQ_16( acelp_cfg->ltf_mode, NORMAL_OPERATION ) ) + IF( EQ_16( acelp_cfg->ltf_mode, NORMAL_OPERATION ) ) { bits = sub( bits, 1 ); /* LP filtering flag */ } } ELSE IF( EQ_16( tc_subfr, L_SUBFR ) ) { - if ( EQ_16( enc_dec, ENC ) ) + IF( enc_dec == ENC ) { bits = sub( bits, 3 ); /* TC signalling */ } @@ -1317,7 +1316,7 @@ ivas_error config_acelp1( } ELSE { - if ( EQ_16( enc_dec, ENC ) ) + IF( enc_dec == ENC ) { bits = sub( bits, 4 ); /* TC signalling */ } @@ -1330,7 +1329,7 @@ ivas_error config_acelp1( } ELSE /* L_frame == L_FRAME16k */ { - IF( EQ_16( enc_dec, ENC ) ) + IF( enc_dec == ENC ) { IF( LE_16( tc_subfr, 2 * L_SUBFR ) ) { @@ -1342,7 +1341,8 @@ ivas_error config_acelp1( } } - bits -= ( L_FRAME16k - tc_subfr - L_SUBFR ) / L_SUBFR; /* LP filtering flag */ + // bits -= ( L_FRAME16k - tc_subfr - L_SUBFR ) / L_SUBFR; /* LP filtering flag */ + bits = sub( bits, idiv1616_1( sub( L_FRAME16k - L_SUBFR, tc_subfr ), L_SUBFR ) ); /* LP filtering flag */ } /* glottal-shape codebook bits */ @@ -1371,7 +1371,7 @@ ivas_error config_acelp1( test(); test(); test(); - IF( EQ_16( element_mode, IVAS_CPE_TD ) && EQ_16( tdm_low_rate_mode, 1 ) && NE_16( coder_type, INACTIVE ) && NE_16( coder_type, UNVOICED ) ) /* GENERIC low rate mode for secondary channel */ + IF( EQ_16( element_mode, IVAS_CPE_TD ) && EQ_16( tdm_low_rate_mode, 1 ) && ( coder_type != INACTIVE ) && NE_16( coder_type, UNVOICED ) ) /* GENERIC low rate mode for secondary channel */ { set16_fx( acelp_cfg->pitch_bits, 0, NB_SUBFR16k ); set16_fx( acelp_cfg->gains_mode, 0, NB_SUBFR16k ); @@ -1387,6 +1387,7 @@ ivas_error config_acelp1( bits = sub( bits, acelp_cfg->pitch_bits[i] ); } acelp_cfg->gains_mode[i] = gain_bits_tbl[BIT_ALLOC_IDX_fx( ACELP_7k20, GENERIC, i_mult( i, L_SUBFR ), TC_SUBFR2IDX_fx( tc_subfr ) )]; + move16(); bits = sub( bits, acelp_cfg->gains_mode[i] ); } acelp_cfg->fcb_mode = 1; @@ -1422,6 +1423,7 @@ ivas_error config_acelp1( { IF( EQ_16( L_frame, L_FRAME ) ) { + test(); IF( EQ_16( tdm_Pitch_reuse_flag, 1 ) && EQ_16( idchan, 1 ) ) { acelp_cfg->pitch_bits[i] = 0; @@ -1501,8 +1503,7 @@ ivas_error config_acelp1( IF( EQ_16( coder_type, UNVOICED ) && !( *uc_two_stage_flag ) ) { i = idiv1616( bits, NB_SUBFR ); - move16(); - if ( i % 2 == 0 ) + IF( s_and( i, 1 ) == 0 ) { i = sub( i, 1 ); /* must be odd */ } @@ -1571,7 +1572,7 @@ ivas_error config_acelp1( move16(); } } - ELSE IF( element_mode != IVAS_CPE_TD && GSC_IVAS_mode > 0 && EQ_16( L_frame, L_FRAME16k ) ) + ELSE IF( NE_16( element_mode, IVAS_CPE_TD ) && GSC_IVAS_mode > 0 && EQ_16( L_frame, L_FRAME16k ) ) { bits = 100; /* 9 kbps for fcb */ move16(); @@ -1606,7 +1607,7 @@ ivas_error config_acelp1( test(); test(); - if ( GE_32( core_brate_inp, MIN_BRATE_AVQ_EXC ) && LE_32( core_brate_inp, MAX_BRATE_AVQ_EXC_TD ) && EQ_16( coder_type, GENERIC ) ) + IF( GE_32( core_brate_inp, MIN_BRATE_AVQ_EXC ) && LE_32( core_brate_inp, MAX_BRATE_AVQ_EXC_TD ) && EQ_16( coder_type, GENERIC ) ) { /* harm. flag ACELP AVQ */ bits = sub( bits, 1 ); @@ -1729,6 +1730,8 @@ ivas_error config_acelp1( test(); IF( flag_hardcoded && NE_32( core_brate, PPP_NELP_2k80 ) ) { + test(); + test(); /* unused bits */ IF( EQ_16( coder_type, AUDIO ) || ( coder_type == INACTIVE && LE_32( core_brate, ACELP_24k40 ) ) ) { @@ -1997,20 +2000,20 @@ ivas_error config_acelp1_IVAS( i = 0; move16(); - WHILE( LT_16( i, SIZE_BRATE_INTERMED_TBL ) ) + WHILE( i < SIZE_BRATE_INTERMED_TBL ) { IF( EQ_32( core_brate_inp, brate_intermed_tbl[i] ) ) { flag_hardcoded = 1; move16(); - break; + BREAK; } IF( LT_32( core_brate_inp, brate_intermed_tbl[i] ) ) { flag_hardcoded = 0; move16(); - break; + BREAK; } i = add( i, 1 ); @@ -2054,7 +2057,7 @@ ivas_error config_acelp1_IVAS( test(); test(); - if ( EQ_16( coder_type, TRANSITION ) && EQ_16( enc_dec, DEC ) && EQ_16( tc_call, 1 ) ) + IF( EQ_16( coder_type, TRANSITION ) && EQ_16( enc_dec, DEC ) && EQ_16( tc_call, 1 ) ) { bits = add( bits, *nBits_es_Pred ); /* equalize for 4th signaling bit estimated at the encoder in TC_0_192 */ } @@ -2066,7 +2069,7 @@ ivas_error config_acelp1_IVAS( { bits = sub( bits, TDM_SIGNAL_BITS_READ_FROM_THE_END_OF_BS ); - if ( EQ_16( tdm_LRTD_flag, 1 ) ) + IF( EQ_16( tdm_LRTD_flag, 1 ) ) { bits = add( bits, STEREO_BITS_TCA ); } @@ -2078,7 +2081,7 @@ ivas_error config_acelp1_IVAS( test(); test(); /* subtract TBE/BWE flag */ - if ( extl_brate > 0 && ( EQ_16( extl, WB_TBE ) || EQ_16( extl, SWB_TBE ) || EQ_16( extl, FB_TBE ) || EQ_16( extl, WB_BWE ) || EQ_16( extl, SWB_BWE ) || EQ_16( extl, FB_BWE ) ) ) + IF( extl_brate > 0 && ( EQ_16( extl, WB_TBE ) || EQ_16( extl, SWB_TBE ) || EQ_16( extl, FB_TBE ) || EQ_16( extl, WB_BWE ) || EQ_16( extl, SWB_BWE ) || EQ_16( extl, FB_BWE ) ) ) { bits = sub( bits, 1 ); } @@ -2095,7 +2098,7 @@ ivas_error config_acelp1_IVAS( test(); test(); test(); - if ( extl_brate > 0 && ( EQ_16( extl, WB_TBE ) || EQ_16( extl, SWB_TBE ) || EQ_16( extl, FB_TBE ) || EQ_16( extl, WB_BWE ) || EQ_16( extl, SWB_BWE ) || EQ_16( extl, FB_BWE ) ) ) + IF( extl_brate > 0 && ( EQ_16( extl, WB_TBE ) || EQ_16( extl, SWB_TBE ) || EQ_16( extl, FB_TBE ) || EQ_16( extl, WB_BWE ) || EQ_16( extl, SWB_BWE ) || EQ_16( extl, FB_BWE ) ) ) { /* extension layer signaling bit is counted in the extension layer bitbudget */ bits = add( bits, 1 ); @@ -2196,7 +2199,7 @@ ivas_error config_acelp1_IVAS( test(); test(); /* gain Q bit-budget - part 1 */ - IF( ( NE_16( coder_type, UNVOICED ) && NE_16( coder_type, AUDIO ) && NE_16( coder_type, INACTIVE ) && !( LE_32( core_brate, ACELP_8k00 ) && NE_16( coder_type, TRANSITION ) ) ) || ( EQ_16( coder_type, INACTIVE ) && GT_32( total_brate, MAX_GSC_INACTIVE_BRATE ) ) ) + IF( ( NE_16( coder_type, UNVOICED ) && NE_16( coder_type, AUDIO ) && ( coder_type != INACTIVE ) && !( LE_32( core_brate, ACELP_8k00 ) && NE_16( coder_type, TRANSITION ) ) ) || ( ( coder_type == INACTIVE ) && GT_32( total_brate, MAX_GSC_INACTIVE_BRATE ) ) ) { *nBits_es_Pred = Es_pred_bits_tbl[BIT_ALLOC_IDX( core_brate, coder_type, -1, -1 )]; move16(); @@ -2272,7 +2275,7 @@ ivas_error config_acelp1_IVAS( move16(); test(); - if ( GT_16( coder_type, UNVOICED ) && LT_16( coder_type, AUDIO ) ) + IF( GT_16( coder_type, UNVOICED ) && LT_16( coder_type, AUDIO ) ) { bits = sub( bits, FEC_BITS_ENR ); } @@ -2284,7 +2287,7 @@ ivas_error config_acelp1_IVAS( move16(); test(); - if ( GT_16( coder_type, UNVOICED ) && LT_16( coder_type, AUDIO ) ) + IF( GT_16( coder_type, UNVOICED ) && LT_16( coder_type, AUDIO ) ) { bits = sub( bits, FEC_BITS_POS ); } @@ -2351,12 +2354,12 @@ ivas_error config_acelp1_IVAS( test(); test(); test(); - if ( ( ( EQ_16( coder_type, UNVOICED ) && !( *uc_two_stage_flag ) ) || ( coder_type == INACTIVE && LE_32( core_brate, ACELP_9k60 ) ) ) && ( idchan == 0 || element_mode == EVS_MONO ) ) + IF( ( ( EQ_16( coder_type, UNVOICED ) && !( *uc_two_stage_flag ) ) || ( coder_type == INACTIVE && LE_32( core_brate, ACELP_9k60 ) ) ) && ( idchan == 0 || element_mode == EVS_MONO ) ) { bits = sub( bits, NBITS_NOISENESS ); /* noiseness */ } test(); - if ( EQ_16( coder_type, UNVOICED ) && !( *uc_two_stage_flag ) ) + IF( EQ_16( coder_type, UNVOICED ) && !( *uc_two_stage_flag ) ) { bits = sub( bits, ( 3 * NB_SUBFR ) ); /* tilt factor */ } @@ -2380,55 +2383,55 @@ ivas_error config_acelp1_IVAS( { IF( EQ_16( tc_subfr, TC_0_0 ) ) { - if ( enc_dec == ENC ) + IF( enc_dec == ENC ) { bits = sub( bits, 1 ); /* TC signaling */ } - if ( EQ_16( acelp_cfg->ltf_mode, NORMAL_OPERATION ) ) + IF( EQ_16( acelp_cfg->ltf_mode, NORMAL_OPERATION ) ) { bits = sub( bits, 3 ); /* LP filtering flag */ } } ELSE IF( EQ_16( tc_subfr, TC_0_64 ) ) { - if ( enc_dec == ENC ) + IF( enc_dec == ENC ) { bits = sub( bits, 4 ); /* TC signaling */ } - if ( EQ_16( acelp_cfg->ltf_mode, NORMAL_OPERATION ) ) + IF( EQ_16( acelp_cfg->ltf_mode, NORMAL_OPERATION ) ) { bits = sub( bits, 3 ); /* LP filtering flag */ } } ELSE IF( EQ_16( tc_subfr, TC_0_128 ) ) { - if ( enc_dec == ENC ) + IF( enc_dec == ENC ) { bits = sub( bits, 4 ); /* TC signaling */ } - if ( EQ_16( acelp_cfg->ltf_mode, NORMAL_OPERATION ) ) + IF( EQ_16( acelp_cfg->ltf_mode, NORMAL_OPERATION ) ) { bits = sub( bits, 2 ); /* LP filtering flag */ } } ELSE IF( EQ_16( tc_subfr, TC_0_192 ) ) { - if ( enc_dec == ENC ) + IF( enc_dec == ENC ) { bits = sub( bits, 3 ); /* TC signaling */ } - if ( EQ_16( acelp_cfg->ltf_mode, NORMAL_OPERATION ) ) + IF( EQ_16( acelp_cfg->ltf_mode, NORMAL_OPERATION ) ) { bits = sub( bits, 1 ); /* LP filtering flag */ } } ELSE IF( EQ_16( tc_subfr, L_SUBFR ) ) { - if ( enc_dec == ENC ) + IF( enc_dec == ENC ) { bits = sub( bits, 3 ); /* TC signaling */ } @@ -2441,7 +2444,7 @@ ivas_error config_acelp1_IVAS( } ELSE { - if ( enc_dec == ENC ) + IF( enc_dec == ENC ) { bits = sub( bits, 4 ); /* TC signaling */ } @@ -2455,7 +2458,7 @@ ivas_error config_acelp1_IVAS( } ELSE /* L_frame == L_FRAME16k */ { - if ( enc_dec == ENC ) + IF( enc_dec == ENC ) { IF( LE_16( tc_subfr, 2 * L_SUBFR ) ) { @@ -2568,10 +2571,10 @@ ivas_error config_acelp1_IVAS( } ELSE { - acelp_cfg->pitch_bits[i] = ACB_bits_16kHz_tbl[BIT_ALLOC_IDX_16KHZ( core_brate, coder_type, i * L_SUBFR, TC_SUBFR2IDX_16KHZ( tc_subfr ) )]; + acelp_cfg->pitch_bits[i] = ACB_bits_16kHz_tbl[BIT_ALLOC_IDX_16KHZ( core_brate, coder_type, i_mult( i, L_SUBFR ), TC_SUBFR2IDX_16KHZ( tc_subfr ) )]; move16(); } - acelp_cfg->gains_mode[i] = gain_bits_16kHz_tbl[BIT_ALLOC_IDX_16KHZ( core_brate, coder_type_sw, i * L_SUBFR, TC_SUBFR2IDX_16KHZ( tc_subfr ) )]; + acelp_cfg->gains_mode[i] = gain_bits_16kHz_tbl[BIT_ALLOC_IDX_16KHZ( core_brate, coder_type_sw, i_mult( i, L_SUBFR ), TC_SUBFR2IDX_16KHZ( tc_subfr ) )]; move16(); } @@ -2607,12 +2610,12 @@ ivas_error config_acelp1_IVAS( { IF( EQ_16( L_frame, L_FRAME ) ) { - acelp_cfg->fixed_cdk_index[i] = FCB_bits_tbl[BIT_ALLOC_IDX( core_brate, coder_type, i * L_SUBFR, TC_SUBFR2IDX( tc_subfr ) )]; + acelp_cfg->fixed_cdk_index[i] = FCB_bits_tbl[BIT_ALLOC_IDX( core_brate, coder_type, i_mult( i, L_SUBFR ), TC_SUBFR2IDX( tc_subfr ) )]; move16(); } ELSE /* L_frame == L_FRAME16k */ { - acelp_cfg->fixed_cdk_index[i] = FCB_bits_16kHz_tbl[BIT_ALLOC_IDX_16KHZ( core_brate, coder_type, i * L_SUBFR, TC_SUBFR2IDX_16KHZ( tc_subfr ) )]; + acelp_cfg->fixed_cdk_index[i] = FCB_bits_16kHz_tbl[BIT_ALLOC_IDX_16KHZ( core_brate, coder_type, i_mult( i, L_SUBFR ), TC_SUBFR2IDX_16KHZ( tc_subfr ) )]; move16(); } bits = sub( bits, acelp_cfg->fixed_cdk_index[i] ); @@ -2624,7 +2627,7 @@ ivas_error config_acelp1_IVAS( IF( EQ_16( coder_type, UNVOICED ) && !( *uc_two_stage_flag ) ) { i = idiv1616( bits, NB_SUBFR ); - if ( i % 2 == 0 ) + IF( s_and( i, 1 ) == 0 ) { i = sub( i, 1 ); /* must be odd */ } @@ -2708,7 +2711,7 @@ ivas_error config_acelp1_IVAS( { IF( flag_hardcoded ) { - acelp_cfg->AVQ_cdk_bits[i] = AVQ_bits_16kHz_tbl[BIT_ALLOC_IDX_16KHZ( core_brate, coder_type, i * L_SUBFR, TC_SUBFR2IDX_16KHZ( tc_subfr ) )]; + acelp_cfg->AVQ_cdk_bits[i] = AVQ_bits_16kHz_tbl[BIT_ALLOC_IDX_16KHZ( core_brate, coder_type, i_mult( i, L_SUBFR ), TC_SUBFR2IDX_16KHZ( tc_subfr ) )]; move16(); { bits = sub( bits, acelp_cfg->AVQ_cdk_bits[i] ); @@ -2720,7 +2723,7 @@ ivas_error config_acelp1_IVAS( test(); test(); - if ( GE_32( core_brate_inp, MIN_BRATE_AVQ_EXC ) && LE_32( core_brate_inp, MAX_BRATE_AVQ_EXC_TD ) && EQ_16( coder_type, GENERIC ) ) + IF( GE_32( core_brate_inp, MIN_BRATE_AVQ_EXC ) && LE_32( core_brate_inp, MAX_BRATE_AVQ_EXC_TD ) && EQ_16( coder_type, GENERIC ) ) { /* harm. flag ACELP AVQ */ bits = sub( bits, 1 ); @@ -2806,18 +2809,18 @@ ivas_error config_acelp1_IVAS( { IF( EQ_16( L_frame, L_FRAME16k ) ) { - acelp_cfg->pitch_bits[i] = ACB_bits_16kHz_tbl[BIT_ALLOC_IDX_16KHZ( Pitch_BR, Pitch_CT, i * L_SUBFR, 0 )]; + acelp_cfg->pitch_bits[i] = ACB_bits_16kHz_tbl[BIT_ALLOC_IDX_16KHZ( Pitch_BR, Pitch_CT, i_mult( i, L_SUBFR ), 0 )]; move16(); - acelp_cfg->fixed_cdk_index[i] = FCB_bits_tbl[BIT_ALLOC_IDX( Local_BR, LOCAL_CT, i * L_SUBFR, 0 )]; + acelp_cfg->fixed_cdk_index[i] = FCB_bits_tbl[BIT_ALLOC_IDX( Local_BR, LOCAL_CT, i_mult( i, L_SUBFR ), 0 )]; move16(); } ELSE { - acelp_cfg->pitch_bits[i] = ACB_bits_tbl[BIT_ALLOC_IDX( Pitch_BR, Pitch_CT, i * L_SUBFR, 0 )]; + acelp_cfg->pitch_bits[i] = ACB_bits_tbl[BIT_ALLOC_IDX( Pitch_BR, Pitch_CT, i_mult( i, L_SUBFR ), 0 )]; move16(); - acelp_cfg->fixed_cdk_index[i] = FCB_bits_tbl[BIT_ALLOC_IDX( Local_BR, LOCAL_CT, i * L_SUBFR, 0 )]; + acelp_cfg->fixed_cdk_index[i] = FCB_bits_tbl[BIT_ALLOC_IDX( Local_BR, LOCAL_CT, i_mult( i, L_SUBFR ), 0 )]; move16(); - acelp_cfg->gains_mode[i] = gain_bits_tbl[BIT_ALLOC_IDX( ACELP_7k20, LOCAL_CT, i * L_SUBFR, 0 )]; + acelp_cfg->gains_mode[i] = gain_bits_tbl[BIT_ALLOC_IDX( ACELP_7k20, LOCAL_CT, i_mult( i, L_SUBFR ), 0 )]; move16(); } } @@ -3098,7 +3101,7 @@ Word16 set_ACELP_flag( test(); test(); test(); - IF( EQ_16( element_mode, IVAS_CPE_DFT ) && ( idchan == 0 ) && LE_32( total_brate, SID_2k40 ) && EQ_16( bwidth, WB ) && EQ_16( cng_type, LP_CNG ) ) + IF( EQ_16( element_mode, IVAS_CPE_DFT ) && ( idchan == 0 ) && LE_32( total_brate, SID_2k40 ) && EQ_16( bwidth, WB ) && ( cng_type == LP_CNG ) ) { return 1; } @@ -3230,7 +3233,7 @@ Word16 set_ACELP_flag_IVAS( test(); test(); test(); - IF( EQ_16( element_mode, IVAS_CPE_DFT ) && ( idchan == 0 ) && LE_32( total_brate, SID_2k40 ) && EQ_16( bwidth, WB ) && EQ_16( cng_type, LP_CNG ) ) + IF( EQ_16( element_mode, IVAS_CPE_DFT ) && ( idchan == 0 ) && LE_32( total_brate, SID_2k40 ) && EQ_16( bwidth, WB ) && ( cng_type == LP_CNG ) ) { return 1; } diff --git a/lib_com/bitstream.c b/lib_com/bitstream.c index 7d892f8c8..584013e2b 100644 --- a/lib_com/bitstream.c +++ b/lib_com/bitstream.c @@ -698,6 +698,8 @@ Word16 get_ivas_max_num_indices_fx( const Word32 ivas_total_brate /* i : IVAS total bitrate */ ) { + test(); + test(); IF( EQ_16( ivas_format, STEREO_FORMAT ) ) { IF( LE_32( ivas_total_brate, IVAS_16k4 ) ) @@ -1179,6 +1181,7 @@ Word16 get_ivas_max_num_indices_metadata_fx( ) { /* set the maximum required number of metadata indices */ + test(); IF( EQ_16( ivas_format, MONO_FORMAT ) ) { return 0; @@ -1418,7 +1421,7 @@ ivas_error check_ind_list_limits( { /* reallocate the buffer of indices with increased limit */ - IF( ( error = ind_list_realloc( *hBstr->ivas_ind_list_zero, *( hBstr->ivas_max_num_indices ) + STEP_MAX_NUM_INDICES, hBstr->st_ivas ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ind_list_realloc( *hBstr->ivas_ind_list_zero, *( hBstr->ivas_max_num_indices ) + STEP_MAX_NUM_INDICES, hBstr->st_ivas ) ), IVAS_ERR_OK ) ) { return error; } @@ -1440,7 +1443,7 @@ ivas_error check_ind_list_limits( { /* no available empty slot -> need to re-allocate the buffer */ - IF( ( error = ind_list_realloc( *hBstr->ivas_ind_list_zero, *( hBstr->ivas_max_num_indices ) + STEP_MAX_NUM_INDICES, hBstr->st_ivas ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ind_list_realloc( *hBstr->ivas_ind_list_zero, *( hBstr->ivas_max_num_indices ) + STEP_MAX_NUM_INDICES, hBstr->st_ivas ) ), IVAS_ERR_OK ) ) { return error; } @@ -1532,7 +1535,7 @@ ivas_error push_indice( move32(); /* check the limits of the list of indices */ - IF( ( error = check_ind_list_limits( hBstr ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = check_ind_list_limits( hBstr ) ), IVAS_ERR_OK ) ) { return IVAS_ERROR( error, "Error occured in push_indice() while re-allocating the list of indices (frame %d) !\n" ); } @@ -1540,8 +1543,10 @@ ivas_error push_indice( /* find the location in the list of indices based on ID */ i = hBstr->nb_ind_tot; move16(); - WHILE( i > 0 && LT_16( id, hBstr->ind_list[i - 1].id ) ) + test(); + WHILE( i > 0 && ( id < hBstr->ind_list[i - 1].id ) ) { + test(); i = sub( i, 1 ); } @@ -1649,7 +1654,7 @@ ivas_error push_next_indice( /* check the limits of the list of indices */ - IF( ( error = check_ind_list_limits( hBstr ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = check_ind_list_limits( hBstr ) ), IVAS_ERR_OK ) ) { return error; } @@ -2102,7 +2107,7 @@ UWord16 get_indice_st( FOR( i = 0; i < nb_bits; i++ ) { value = shl( value, 1 ); - value = add( value, st->bit_stream[add( pos, i )] ); + value = add( value, st->bit_stream[pos + i] ); } return value; diff --git a/lib_com/bitstream_fx.c b/lib_com/bitstream_fx.c index 7ca1ddf81..7d7fa3fdd 100644 --- a/lib_com/bitstream_fx.c +++ b/lib_com/bitstream_fx.c @@ -176,7 +176,7 @@ static Word16 rate2AMRWB_IOmode( Word32 brate /* i: bitrate */ ) { - switch ( brate ) + SWITCH( brate ) { /* EVS AMR-WB IO modes */ case SID_1k75: @@ -289,7 +289,7 @@ void push_indice_fx( /* new indice - find an empty slot in the list */ i = id; move16(); - WHILE( NE_16( hBstr->ind_list[i].nb_bits, -1 ) ) + WHILE( hBstr->ind_list[i].nb_bits != -1 ) { i = add( i, 1 ); } @@ -506,7 +506,7 @@ UWord16 get_indice_fx( /* o : value of the indice */ FOR( i = 0; i < nb_bits; i++ ) { value = lshl( value, 1 ); - value = add( value, st_fx->bit_stream[add( pos, i )] ); + value = add( value, st_fx->bit_stream[pos + i] ); } return value; @@ -703,62 +703,65 @@ void write_indices_buf_fx( UWord8 header; Word16 isAmrWb = 0; - if ( st_fx->bitstreamformat == G192 ) + IF( st_fx->bitstreamformat == G192 ) { /*-----------------------------------------------------------------* * Encode Sync Header and Frame Length *-----------------------------------------------------------------*/ pt_stream = stream; - for ( i = 0; i < ( 2 + MAX_BITS_PER_FRAME ); ++i ) + FOR( i = 0; i < ( 2 + MAX_BITS_PER_FRAME ); ++i ) { stream[i] = 0; + move16(); } //*pt_stream++ = (Word16) SYNC_GOOD_FRAME; //*pt_stream++ = hBstr->nb_bits_tot; *num_bits = hBstr->nb_bits_tot; - + move16(); /*----------------------------------------------------------------* * Bitstream packing (conversion of individual indices into a serial stream) * Writing the serial stream into file *----------------------------------------------------------------*/ - for ( i = 0; i < MAX_NUM_INDICES; i++ ) + FOR( i = 0; i < MAX_NUM_INDICES; i++ ) { - if ( hBstr->ind_list[i].nb_bits != -1 ) + IF( NE_16( hBstr->ind_list[i].nb_bits, -1 ) ) { /* mask from MSB to LSB */ - mask = 1 << ( hBstr->ind_list[i].nb_bits - 1 ); + mask = L_shl( 1, ( sub( hBstr->ind_list[i].nb_bits, 1 ) ) ); /* write bit by bit */ - for ( k = 0; k < hBstr->ind_list[i].nb_bits; k++ ) + FOR( k = 0; k < hBstr->ind_list[i].nb_bits; k++ ) { - if ( hBstr->ind_list[i].value & mask ) + IF( L_and( hBstr->ind_list[i].value, mask ) ) { //*pt_stream++ = G192_BIN1; *pt_stream++ = 1; + move16(); } - else + ELSE { //*pt_stream++ = G192_BIN0; *pt_stream++ = 0; + move16(); } - mask >>= 1; + mask = L_shr( mask, 1 ); } } } } - else + ELSE { /* Create and write ToC header */ /* qbit always set to 1 on encoder side for AMRWBIO , no qbit in use for EVS, but set to 0(bad) */ - header = (UWord8) ( st_fx->Opt_AMR_WB << 5 | st_fx->Opt_AMR_WB << 4 | rate2EVSmode( hBstr->nb_bits_tot * 50, &isAmrWb ) ); + header = (UWord8) ( s_or( s_or( shl( st_fx->Opt_AMR_WB, 5 ), shl( st_fx->Opt_AMR_WB, 4 ) ), rate2EVSmode( i_mult( hBstr->nb_bits_tot, 50 ), &isAmrWb ) ) ); // fwrite(&header, sizeof(UWord8), 1, file); memcpy( out_buf, &header, sizeof( UWord8 ) ); *num_bits += sizeof( UWord8 ); /* Write speech bits */ // fwrite(pFrame, sizeof(UWord8), (pFrame_size + 7) >> 3, file); - memcpy( out_buf, pFrame, sizeof( UWord8 ) * ( ( pFrame_size + 7 ) >> 3 ) ); - *num_bits += sizeof( UWord8 ) * ( ( pFrame_size + 7 ) >> 3 ); + memcpy( out_buf, pFrame, sizeof( UWord8 ) * ( shr( add( pFrame_size, 7 ), 3 ) ) ); + *num_bits += sizeof( UWord8 ) * ( shr( ( add( pFrame_size, 7 ) ), 3 ) ); } /* Clearing of indices */ @@ -769,7 +772,7 @@ void write_indices_buf_fx( } - if ( st_fx->bitstreamformat == G192 ) + IF( st_fx->bitstreamformat == G192 ) { /* write the serial stream into file */ // fwrite(stream, sizeof(unsigned short), 2 + stream[1], file); @@ -783,6 +786,9 @@ void write_indices_buf_fx( hBstr->nb_bits_tot = 0; hBstr->next_ind_fx = 0; hBstr->last_ind_fx = -1; + move16(); + move16(); + move16(); return; } @@ -920,7 +926,7 @@ void indices_to_serial_generic( FOR( k = 0; k < ind_list[i].nb_bits; k++ ) { pack_bit( ind_list[i].value & mask, &pt_pFrame, &omask ); - j++; + j = add( j, 1 ); mask = L_shr( mask, 1 ); } nb_bits_tot = add( nb_bits_tot, ind_list[i].nb_bits ); @@ -1194,7 +1200,7 @@ void decision_matrix_core_dec( move16(); } /* SC-VBR */ - ELSE IF( st->total_brate == PPP_NELP_2k80 ) + ELSE IF( EQ_32( st->total_brate, PPP_NELP_2k80 ) ) { st->core = ACELP_CORE; move16(); @@ -1232,7 +1238,7 @@ void decision_matrix_core_dec( /* find the section in the ACELP signalling table corresponding to bitrate */ start_idx = 0; move16(); - WHILE( NE_32( acelp_sig_tbl[start_idx], st->total_brate ) ) + WHILE( acelp_sig_tbl[start_idx] != st->total_brate ) { start_idx = add( start_idx, 1 ); } @@ -1245,7 +1251,7 @@ void decision_matrix_core_dec( start_idx = add( start_idx, 1 ); /* retrieve the signalling indice */ - ind = acelp_sig_tbl[add( start_idx, get_next_indice_fx( st, nBits ) )]; + ind = acelp_sig_tbl[start_idx + get_next_indice_fx( st, nBits )]; st->bwidth = extract_l( L_and( L_shr( ind, 3 ), 0x7 ) ); move16(); @@ -1573,6 +1579,8 @@ Word16 read_indices_fx( /* o : 1 = reading OK, 0 = problem /* read the Sync Header field from the bitstream */ /* in case rew_flag is set, read until first good frame is encountered */ + test(); + test(); DO { /* read the Sync header */ @@ -1647,9 +1655,8 @@ Word16 read_indices_fx( /* o : 1 = reading OK, 0 = problem fprintf( stderr, "\nError, invalid number of bits read ! Exiting ! \n" ); exit( -1 ); } - test(); } - WHILE( rew_flag && ( st->bfi || LT_32( total_brate, 2800 ) ) ); + WHILE( rew_flag && ( st->bfi || ( total_brate < 2800 ) ) ); /* G.192 RX DTX handler*/ IF( !rew_flag ) @@ -1807,8 +1814,8 @@ Word16 read_indices_fx( /* o : 1 = reading OK, 0 = problem test(); test(); test(); - if ( ( ( st->CNG_fx != 0 ) && ( ( speech_bad != 0 ) || ( speech_lost != 0 ) ) ) || /* SP_BAD or SPEECH_LOST) --> stay in CNG */ - ( sid_upd_bad != 0 ) ) /* SID_UPD_BAD --> start CNG */ + IF( ( ( st->CNG_fx != 0 ) && ( ( speech_bad != 0 ) || ( speech_lost != 0 ) ) ) || /* SP_BAD or SPEECH_LOST) --> stay in CNG */ + ( sid_upd_bad != 0 ) ) /* SID_UPD_BAD --> start CNG */ { st->bfi = 0; move16(); @@ -1844,7 +1851,7 @@ Word16 read_indices_fx( /* o : 1 = reading OK, 0 = problem { rewind( file ); st->total_brate = total_brate; - move16(); + move32(); return 1; } @@ -1938,7 +1945,7 @@ static Word32 read_indices_mime_handle_dtx( /* SID_UPDATE check */ test(); - IF( total_brate == SID_1k75 || total_brate == SID_2k40 ) + IF( EQ_32( total_brate, SID_1k75 ) || EQ_32( total_brate, SID_2k40 ) ) { IF( st->bfi == 0 ) { @@ -2210,7 +2217,6 @@ Word16 read_indices_mime( /* o : 1 = reading OK, 0 = problem isAMRWB_IOmode = 1; move16(); qbit = s_and( shr( header, 2 ), 0x01 ); /* b2 bit (b7 is the F bit ) */ - move16(); st->bfi = !qbit; move16(); core_mode = s_and( shr( header, 3 ), 0x0F ); /* b6..b3 */ @@ -2382,8 +2388,14 @@ Word16 read_indices_mime( /* o : 1 = reading OK, 0 = problem IF( st->bfi == 0 ) { /* select MODE1 or MODE2 in MIME */ - decoder_selectCodec( st, total_brate, *st->bit_stream ? G192_BIN1 : G192_BIN0 ); - + IF( *st->bit_stream ) + { + decoder_selectCodec( st, total_brate, G192_BIN1 ); + } + ELSE + { + decoder_selectCodec( st, total_brate, G192_BIN0 ); + } /* a change of the total bitrate should not be known to the decoder, if the received frame was truly lost */ st->total_brate = total_brate; move32(); @@ -2523,9 +2535,9 @@ void get_rfFlag( /* find the section in the ACELP signalling table corresponding to bitrate */ start_idx = 0; move16(); - WHILE( NE_32( acelp_sig_tbl[start_idx], st->total_brate ) ) + WHILE( acelp_sig_tbl[start_idx] != st->total_brate ) { - start_idx++; + start_idx = add( start_idx, 1 ); assert( ( start_idx < MAX_ACELP_SIG ) && "ERROR: start_idx larger than acelp_sig_tbl[].\n" ); } @@ -2725,12 +2737,12 @@ void get_NextCoderType_fx( FOR( k = 0; k < ACELP_13k20 / 50; k++ ) { - bit_stream[k] = (UWord8) s_and( shr( bitsteam[k / 8], sub( 7, ( k % 8 ) ) ), 0x1 ); + bit_stream[k] = (UWord8) s_and( shr( bitsteam[k / 8], sub( 7, s_and( k, 7 ) ) ), 0x1 ); move16(); } start_idx = 0; move16(); - WHILE( NE_32( acelp_sig_tbl[start_idx], ACELP_13k20 ) ) + WHILE( acelp_sig_tbl[start_idx] != ACELP_13k20 ) { start_idx = add( start_idx, 1 ); assert( ( start_idx < MAX_ACELP_SIG ) && "ERROR: start_idx larger than acelp_sig_tbl[].\n" ); @@ -2741,7 +2753,7 @@ void get_NextCoderType_fx( tmp = 0; move16(); - nBits_tmp = (Word16) acelp_sig_tbl[start_idx++]; + nBits_tmp = extract_l( acelp_sig_tbl[start_idx++] ); move16(); FOR( k = 0; k < nBits_tmp; k++ ) { @@ -2749,7 +2761,7 @@ void get_NextCoderType_fx( tmp = add( tmp, bit_stream[k] ); } /* retrieve the signalling indice */ - *next_coder_type = s_and( (Word16) acelp_sig_tbl[add( start_idx, tmp )], 0x7 ); + *next_coder_type = s_and( extract_l( acelp_sig_tbl[start_idx + tmp] ), 0x7 ); move16(); } @@ -2806,7 +2818,6 @@ void read_indices_from_djb_fx( move16(); no_data = st->CNG_fx != 0; move16(); - move16(); } test(); @@ -2833,7 +2844,7 @@ void read_indices_from_djb_fx( FOR( k = 0; k < num_bits; k++ ) { test(); - IF( st->bitstreamformat == VOIP_RTPDUMP && isAMRWB_IOmode ) + IF( EQ_16( st->bitstreamformat, VOIP_RTPDUMP ) && isAMRWB_IOmode ) { st->bit_stream[sort_ptr[core_mode][k]] = unpack_bit( &pt_stream, &mask ); move16(); @@ -2877,7 +2888,15 @@ void read_indices_from_djb_fx( IF( NE_16( st->bfi, 1 ) ) { /* select Mode 1 or Mode 2 */ - decoder_selectCodec( st, total_brate, *st->bit_stream ? G192_BIN1 : G192_BIN0 ); + IF( *st->bit_stream ) + { + decoder_selectCodec( st, total_brate, G192_BIN1 ); + } + ELSE + { + decoder_selectCodec( st, total_brate, G192_BIN0 ); + } + /* a change of the total bitrate should not be known to the decoder, if the received frame was truly lost */ st->total_brate = total_brate; @@ -2908,7 +2927,7 @@ static UWord16 get_indice_preview( bitstreamShortPtr = bitstreamShort; FOR( i = 0; i < bitstreamSize; i++ ) { - *bitstreamShortPtr++ = s_and( shr( bitstream[i / 8], sub( 7, ( i % 8 ) ) ), 0x1 ); + *bitstreamShortPtr++ = s_and( shr( bitstream[i / 8], sub( 7, ( s_and( i, 7 ) ) ) ), 0x1 ); move16(); } @@ -2918,7 +2937,7 @@ static UWord16 get_indice_preview( FOR( i = 0; i < nb_bits; i++ ) { value = shl( value, 1 ); - value = add( value, bitstreamShort[add( pos, i )] ); + value = add( value, bitstreamShort[pos + i] ); } return value; } @@ -2952,7 +2971,7 @@ void evs_dec_previewFrame( /* find the section in the ACELP signalling table corresponding to bitrate */ start_idx = 0; move16(); - WHILE( NE_32( acelp_sig_tbl[start_idx], total_brate ) ) + WHILE( acelp_sig_tbl[start_idx] != total_brate ) { start_idx = add( start_idx, 1 ); assert( ( start_idx < MAX_ACELP_SIG ) && "ERROR: start_idx larger than acelp_sig_tbl[].\n" ); @@ -2961,11 +2980,10 @@ void evs_dec_previewFrame( /* skip the bitrate */ start_idx = add( start_idx, 1 ); /* retrieve the number of bits */ - nBits = (Word16) acelp_sig_tbl[start_idx++]; - move16(); + nBits = extract_l( acelp_sig_tbl[start_idx++] ); /* retrieve the signalling indice */ - ind = acelp_sig_tbl[add( start_idx, get_indice_preview( bitstream, bitstreamSize, 0, nBits ) )]; + ind = acelp_sig_tbl[( start_idx + get_indice_preview( bitstream, bitstreamSize, 0, nBits ) )]; move32(); /* convert signalling indice into RF flag. */ diff --git a/lib_com/ivas_dirac_com.c b/lib_com/ivas_dirac_com.c index 01a6d4828..2b696a4b1 100644 --- a/lib_com/ivas_dirac_com.c +++ b/lib_com/ivas_dirac_com.c @@ -2156,8 +2156,7 @@ void calculate_hodirac_sector_parameters_fx( return; } -#endif - +#else void calculate_hodirac_sector_parameters( DIRAC_ENC_HANDLE hDirAC, /* i : DirAC handle */ float RealBuffer[DIRAC_MAX_ANA_CHANS][DIRAC_NO_FB_BANDS_MAX], /* i : signal vector (L+1)^2 x N_bins, real part */ @@ -2350,6 +2349,7 @@ void calculate_hodirac_sector_parameters( return; } +#endif /*-----------------------------------------------------------------------* diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index a2aada6a9..75c7d206f 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -4934,19 +4934,47 @@ void ivas_sba2mc_cldfb_fixed( * DirAC prototypes *----------------------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +ivas_error ivas_dirac_enc_open_fx( + Encoder_Struct *st_ivas /* i/o: IVAS encoder handle */ +); +#else ivas_error ivas_dirac_enc_open( Encoder_Struct *st_ivas /* i/o: IVAS encoder handle */ ); +#endif ivas_error ivas_dirac_enc_reconfigure( Encoder_Struct *st_ivas /* i/o: IVAS encoder handle */ ); +#ifdef IVAS_FLOAT_FIXED +void ivas_dirac_enc_close_fx( + DIRAC_ENC_HANDLE *hDirAC, /* i/o: encoder DirAC handle */ + const Word32 input_Fs /* i : input sampling_rate */ +); +#else void ivas_dirac_enc_close( DIRAC_ENC_HANDLE *hDirAC, /* i/o: encoder DirAC handle */ const int32_t input_Fs /* i : input sampling_rate */ ); +#endif +#ifdef IVAS_FLOAT_FIXED +ivas_error ivas_dirac_enc_fx( + DIRAC_ENC_HANDLE hDirAC, /* i/o: encoder DirAC handle */ + IVAS_QMETADATA_HANDLE hQMetaData, /* i/o: q_metadata handle */ + BSTR_ENC_HANDLE hMetaData, /* i/o: Metadata bitstream handle */ + Word32 *data_f[], /* i/o: SBA channels */ + Word32 **ppIn_FR_real, /* o : real freq domain values */ + Word32 **ppIn_FR_imag, /* o : imag freq domain values */ + Word16 pp_fr_q, + const int16_t input_frame, /* i : input frame length */ + const int16_t dtx_vad, /* i : DTX vad flag */ + const IVAS_FORMAT ivas_format, /* i : ivas format */ + const int16_t hodirac_flag /* i : hodirac flag */ +); +#else ivas_error ivas_dirac_enc( DIRAC_ENC_HANDLE hDirAC, /* i/o: encoder DirAC handle */ IVAS_QMETADATA_HANDLE hQMetaData, /* i/o: q_metadata handle */ @@ -4959,6 +4987,7 @@ ivas_error ivas_dirac_enc( const IVAS_FORMAT ivas_format, /* i : ivas format */ const int16_t hodirac_flag /* i : hodirac flag */ ); +#endif ivas_error ivas_dirac_config( void *st_ivas, /* i/o: IVAS encoder/decoder state structure */ @@ -5179,8 +5208,7 @@ void calculate_hodirac_sector_parameters_fx( Word32 *ene_fx, /* o : array of sector energy values, flat */ Word16 *ene_exp /* o : array of sector energy exponents, flat */ ); -#endif - +#else void calculate_hodirac_sector_parameters( DIRAC_ENC_HANDLE hDirAC, float RealBuffer[DIRAC_MAX_ANA_CHANS][DIRAC_NO_FB_BANDS_MAX],/* i : signal vector (L+1)^2 x N_bins, real part */ @@ -5194,6 +5222,7 @@ void calculate_hodirac_sector_parameters( float *diff, /* o : array of sector diffuseness values, flat */ float *ene /* o : array of sector energy values, flat */ ); +#endif #ifdef IVAS_FLOAT_FIXED void ivas_mc_paramupmix_enc_fx( @@ -6239,19 +6268,17 @@ void ivas_spar_md_enc_close( ivas_error ivas_spar_md_enc_process_fx( ivas_spar_md_enc_state_t *hMdEnc, /* i/o: SPAR MD encoder handle */ const ENCODER_CONFIG_HANDLE hEncoderConfig, /* i : configuration structure */ - float *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], - float *cov_dtx_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], Word32 *cov_real_fx[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], Word16 *cov_real_q[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], Word32 *cov_dtx_real_fx[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], Word16 *cov_dtx_real_q[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], BSTR_ENC_HANDLE hMetaData, /* i/o: MetaData handle */ - const int16_t dtx_vad, - const int16_t nchan_inp, - const int16_t sba_order, /* i : Ambisonic (SBA) order */ + const Word16 dtx_vad, + const Word16 nchan_inp, + const Word16 sba_order, /* i : Ambisonic (SBA) order */ float *prior_mixer[IVAS_MAX_FB_MIXER_OUT_CH][IVAS_MAX_SPAR_FB_MIXER_IN_CH], /* i : prior mixer_matrix */ - const int16_t dyn_active_w_flag, /* i : flag to indicate dynamic active W */ - const int16_t dirac_mono_flag /* i : flag to indicate mono only mode in SBA */ + const Word16 dyn_active_w_flag, /* i : flag to indicate dynamic active W */ + const Word16 dirac_mono_flag /* i : flag to indicate mono only mode in SBA */ ); #else ivas_error ivas_spar_md_enc_process( @@ -6268,35 +6295,6 @@ ivas_error ivas_spar_md_enc_process( const int16_t dirac_mono_flag /* i : flag to indicate mono only mode in SBA */ ); #endif -void ivas_compute_spar_params( - float *pppCov_mat_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], - float dm_fv_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], - const int16_t i_ts, - float ***mixer_mat, - const int16_t start_band, - const int16_t end_band, - const int16_t dtx_vad, - const int16_t num_ch, - const int16_t bands_bw, - const int16_t active_w, - const int16_t active_w_vlbr, - ivas_spar_md_com_cfg *hSparCfg, - ivas_spar_md_t *hSparMd, - float *pWscale, - const int16_t from_dirac, - const int16_t dyn_active_w_flag -); - -void ivas_create_fullr_dmx_mat( - float pred_coeffs_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], - float dm_fv_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], - float ***mixer_mat, - const int16_t in_chans, - const int16_t start_band, - const int16_t end_band, - const int16_t active_w, - ivas_spar_md_com_cfg *hMdCfg -); #ifdef IVAS_FLOAT_FIXED void ivas_create_fullr_dmx_mat_fx( @@ -6314,19 +6312,6 @@ void ivas_create_fullr_dmx_mat_fx( ); #endif // IVAS_FLOAT_FIXED - -void ivas_calc_c_p_coeffs( - ivas_spar_md_t *pSparMd, - float *pppCov_mat_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], - const int16_t i_ts, - float ***mixer_mat, - const int16_t num_ch, - const int16_t num_dmx, - const int16_t band_idx, - const int16_t dtx_vad, - const int16_t compute_p_flag, - const int16_t dyn_active_w_flag -); #ifdef IVAS_FLOAT_FIXED void ivas_get_spar_md_from_dirac_fx( Word32 azi_dirac_fx[IVAS_MAX_NUM_BANDS][MAX_PARAM_SPATIAL_SUBFRAMES], // Q22 @@ -6347,23 +6332,6 @@ void ivas_get_spar_md_from_dirac_fx( const Word16 dyn_active_w_flag ); #endif -void ivas_get_spar_md_from_dirac( - float azi_dirac[IVAS_MAX_NUM_BANDS][MAX_PARAM_SPATIAL_SUBFRAMES], - float ele_dirac[IVAS_MAX_NUM_BANDS][MAX_PARAM_SPATIAL_SUBFRAMES], - float diffuseness[IVAS_MAX_NUM_BANDS], - const int16_t n_ts, - float ***mixer_mat, - ivas_spar_md_t *hSpar_md, - ivas_spar_md_com_cfg *hSpar_md_cfg, - const int16_t start_band, - const int16_t end_band, - const int16_t order, - const int16_t dtx_vad, - float Wscale_d[IVAS_MAX_NUM_BANDS], - const uint8_t useLowerRes, - const int16_t active_w_vlbr, - const int16_t dyn_active_w_flag -); /*! r: number of MD subframes */ #ifdef IVAS_FLOAT_FIXED @@ -7044,6 +7012,16 @@ void ivas_quantise_real_values_fx( Word32 *quant_fx, const Word16 dim); +void ivas_quantise_real_values_enc_fx_varq( + const Word32 *values_fx, + const Word16 q_levels, + const Word32 min_value_fx, + const Word32 max_value_fx, + Word16 *index, + Word32 *quant_fx, + const Word16 dim, + Word16 inp_q ); + void ivas_quantise_real_values_enc_fx( const Word32 *values_fx,//Q28 const Word16 q_levels, @@ -7102,11 +7080,6 @@ void ivas_copy_band_coeffs_idx_to_arr( ); #endif -void ivas_clear_band_coeffs( - ivas_band_coeffs_t *pband_coeffs, - const uint16_t num_bands -); - void ivas_clear_band_coeffs_fx( ivas_band_coeffs_t *pband_coeffs, const UWord16 num_bands); diff --git a/lib_com/ivas_qmetadata_com.c b/lib_com/ivas_qmetadata_com.c index 3bb90ec8d..a16a4be54 100644 --- a/lib_com/ivas_qmetadata_com.c +++ b/lib_com/ivas_qmetadata_com.c @@ -192,9 +192,10 @@ ivas_error ivas_qmetadata_allocate_memory( set32_fx( hQMetaData->q_direction[dir].band_data[j].q_azimuth_fx, 0, MAX_PARAM_SPATIAL_SUBFRAMES ); #endif #endif - set_zero( hQMetaData->q_direction[dir].band_data[j].energy_ratio, MAX_PARAM_SPATIAL_SUBFRAMES ); #ifdef IVAS_FLOAT_FIXED set32_fx( hQMetaData->q_direction[dir].band_data[j].energy_ratio_fx, 0, MAX_PARAM_SPATIAL_SUBFRAMES ); +#else + set_zero( hQMetaData->q_direction[dir].band_data[j].energy_ratio, MAX_PARAM_SPATIAL_SUBFRAMES ); #endif } } diff --git a/lib_com/ivas_spar_com.c b/lib_com/ivas_spar_com.c index 9d21cfbb4..f70a74d6e 100644 --- a/lib_com/ivas_spar_com.c +++ b/lib_com/ivas_spar_com.c @@ -154,17 +154,6 @@ static void ivas_calc_post_pred_per_band_fx( Word32 *cov_real[IVAS_SPAR_MAX_CH][ static Word16 ivas_is_mat_inv_fx( Word32 in_re[MAX_MAT_DIM][MAX_MAT_DIM], Word16 q_in_re, const Word16 dim ); static void ivas_calc_mat_inv_fx( Word32 in_re[MAX_MAT_DIM][MAX_MAT_DIM], Word16 q_in_re, const Word16 dim, Word32 out_re[MAX_MAT_DIM][MAX_MAT_DIM], Word16 *q_out_re ); #endif -static void ivas_get_pred_coeffs( float *pppCov_mat_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], float ppPred_coeffs_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], float ppDM_Fv_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], const int16_t in_chans, const int16_t start_band, const int16_t end_band, const int16_t active_w, const int16_t active_w_vlbr, const int16_t dtx_vad, const int16_t from_dirac, const int16_t dyn_active_w_flag, const int16_t res_ind ); - -static void ivas_reorder_array( float in_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH][IVAS_MAX_NUM_BANDS], const int16_t in_chans, const int16_t order[IVAS_SPAR_MAX_CH], float ***mixer_mat, const int16_t start_band, const int16_t end_band ); - -static void ivas_get_Wscaling_factor( float *pppCov_mat_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], float pred_coeffs_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], float ***mixer_mat, const int16_t start_band, const int16_t end_band, const int16_t dtx_vad, const int16_t num_ch, const int16_t *pNum_dmx, const int16_t bands_bw, const int16_t active_w, const int16_t active_w_vlbr, float *pWscale, const int16_t dyn_active_w_flag ); - -static void ivas_calc_post_pred_per_band( float *pppCov_mat_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], float ***mixer_mat, const int16_t num_ch, const int16_t band_idx, float postpred_cov_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH] ); - -static int16_t ivas_is_mat_inv( float in_re[MAX_MAT_DIM][MAX_MAT_DIM], const int16_t dim ); - -static void ivas_calc_mat_inv( float in_re[MAX_MAT_DIM][MAX_MAT_DIM], const int16_t dim, float out_re[MAX_MAT_DIM][MAX_MAT_DIM] ); /*-----------------------------------------------------------------------------------------* * Function ivas_get_bw_idx_from_sample_rate() @@ -528,212 +517,6 @@ Word16 ivas_get_sba_num_TCs_fx( * Calculation of prediction coefficients *-----------------------------------------------------------------------------------------*/ -static void ivas_get_pred_coeffs( - float *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], - float ppPred_coeffs_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], - float ppDM_Fv_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], - const int16_t in_chans, - const int16_t start_band, - const int16_t end_band, - const int16_t active_w, - const int16_t active_w_vlbr, - const int16_t dtx_vad, - const int16_t from_dirac, - const int16_t dyn_active_w_flag, - const int16_t res_ind ) -{ - int16_t i, j, k, b; - float abs_value; - float w_norm_fac; - float div_factor[IVAS_MAX_NUM_BANDS]; - int16_t pred_dim = in_chans - 1; - - w_norm_fac = ( from_dirac == 1 ) ? 1.0f : 3.0f; - - if ( active_w == 0 ) - { - float pPred_temp[IVAS_MAX_NUM_BANDS]; - - set_zero( pPred_temp, IVAS_MAX_NUM_BANDS ); - for ( k = start_band; k < end_band; k++ ) - { - div_factor[k] = max( 1e-20f, cov_real[0][0][k] ); - div_factor[k] = 1 / div_factor[k]; - } - - for ( i = 0; i < pred_dim; i++ ) - { - for ( k = start_band; k < end_band; k++ ) - { - ppPred_coeffs_re[i][k] = cov_real[i + 1][0][k] * div_factor[k]; - - IVAS_CALCULATE_SQ_ABS_N( ppPred_coeffs_re[i][k], abs_value ); - - pPred_temp[k] += abs_value; - } - } - - for ( k = start_band; k < end_band; k++ ) - { - pPred_temp[k] = sqrtf( pPred_temp[k] ); - div_factor[k] = max( 1.0f, pPred_temp[k] ); - div_factor[k] = 1 / div_factor[k]; - } - - for ( i = 0; i < pred_dim; i++ ) - { - for ( k = start_band; k < end_band; k++ ) - { - ppPred_coeffs_re[i][k] = ppPred_coeffs_re[i][k] * div_factor[k]; - ppDM_Fv_re[i][k] = 0; - } - } - } - else - { - float dm_alpha[IVAS_MAX_NUM_BANDS], dm_v_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS]; - float real[IVAS_SPAR_MAX_CH - 1], dm_beta_re = 0, dm_g[IVAS_MAX_NUM_BANDS]; - float dm_f_local, dm_w, dm_y, DM_F[IVAS_MAX_NUM_BANDS]; - float num_f, den_f, passive_g; - float activew_quad_thresh, g_th_sq; - - if ( dyn_active_w_flag == 1 ) - { - activew_quad_thresh = 1.0f; - } - else - { - activew_quad_thresh = IVAS_LIN_ACTIVEW_QUAD_ACTIVEW_THRESH; - } - g_th_sq = activew_quad_thresh * activew_quad_thresh; - - set_zero( dm_alpha, IVAS_MAX_NUM_BANDS ); - - for ( i = 1; i < in_chans; i++ ) - { - for ( k = start_band; k < end_band; k++ ) - { - IVAS_CALCULATE_SQ_ABS_N( cov_real[i][0][k], abs_value ); - dm_alpha[k] += abs_value; - } - } - - for ( k = start_band; k < end_band; k++ ) - { - dm_alpha[k] = sqrtf( dm_alpha[k] ); - div_factor[k] = max( dm_alpha[k], 1e-20f ); - div_factor[k] = 1 / div_factor[k]; - } - - for ( i = 0; i < pred_dim; i++ ) - { - for ( k = start_band; k < end_band; k++ ) - { - dm_v_re[i][k] = cov_real[i + 1][0][k] * div_factor[k]; - } - } - - if ( dtx_vad == 0 ) - { - dm_f_local = IVAS_ACTIVEW_DM_F_DTX; - } - else - { - dm_f_local = ( active_w_vlbr ) ? IVAS_ACTIVEW_DM_F_VLBR : IVAS_ACTIVEW_DM_F; - } - - for ( b = start_band; b < end_band; b++ ) - { - set_zero( real, pred_dim ); - - for ( j = 0; j < pred_dim; j++ ) - { - for ( k = 1; k < in_chans; k++ ) - { - float re; - - IVAS_RMULT_FLOAT( cov_real[j + 1][k][b], dm_v_re[k - 1][b], re ); - real[j] += re; - } - } - dm_beta_re = 0; - for ( k = 0; k < pred_dim; k++ ) - { - float re; - IVAS_RMULT_FLOAT( real[k], dm_v_re[k][b], re ); - dm_beta_re += re; - } - - dm_w = cov_real[0][0][b]; - den_f = max( dm_w, 1e-20f ); - passive_g = dm_alpha[b] / den_f; - - if ( dyn_active_w_flag == 1 ) - { - dm_alpha[b] = 0.0f; - dm_w = 0.0f; - for ( i = 0; i < pred_dim; i++ ) - { - dm_v_re[i][b] = 0.0f; - } - dm_v_re[res_ind - 1][b] = 1.0f; - passive_g = activew_quad_thresh; - } - - if ( passive_g < activew_quad_thresh ) - { - /*linear activeW*/ - dm_y = 0; - - for ( k = 1; k < in_chans; k++ ) - { - dm_y += cov_real[k][k][b]; - } - den_f = max( dm_y, 1e-20f ); - den_f = max( den_f, w_norm_fac * dm_w ); - DM_F[b] = ( dm_f_local * dm_alpha[b] ) / den_f; - DM_F[b] = min( 1.0f, DM_F[b] ); - - den_f = dm_w + ( 2 * dm_alpha[b] * DM_F[b] ) + ( DM_F[b] * DM_F[b] * dm_beta_re ); - den_f = max( den_f, 1e-20f ); - - dm_g[b] = ( dm_alpha[b] + ( DM_F[b] * dm_beta_re ) ) / den_f; - } - else - { - float sqrt_val; - - /* quadratic activeW */ - - num_f = ( dm_beta_re - ( 2 * dm_alpha[b] * activew_quad_thresh ) ); - - sqrt_val = 4 * dm_alpha[b] * dm_alpha[b] * g_th_sq; - sqrt_val += dm_beta_re * dm_beta_re; - sqrt_val -= 4 * dm_beta_re * g_th_sq * dm_w; - sqrt_val = sqrtf( sqrt_val ); - num_f += sqrt_val; - - den_f = 2 * dm_beta_re * g_th_sq; - den_f = max( den_f, 1e-20f ); - dm_g[b] = activew_quad_thresh; - DM_F[b] = ( dm_g[b] * num_f ) / den_f; - } - } - - for ( i = 0; i < pred_dim; i++ ) - { - for ( b = start_band; b < end_band; b++ ) - { - ppPred_coeffs_re[i][b] = dm_v_re[i][b] * dm_g[b]; - - ppDM_Fv_re[i][b] = dm_v_re[i][b] * DM_F[b]; - } - } - } - - return; -} - #ifdef IVAS_FLOAT_FIXED /*-----------------------------------------------------------------------------------------* * Function ivas_get_pred_coeffs_fx() @@ -801,13 +584,13 @@ static void ivas_get_pred_coeffs_enc_fx( { FOR( k = start_band; k < end_band; k++ ) { - tmp64 = W_mult_32_16( cov_real[add( i, 1 )][0][k], div_factor[k] ); + tmp64 = W_mult_32_16( cov_real[i + 1][0][k], div_factor[k] ); tmp_shift = W_norm( tmp64 ); IF( tmp64 != 0 ) { ppPred_coeffs_re[i][k] = W_extract_h( W_shl( tmp64, tmp_shift ) ); // 1 + q_cov_real[i+1][0][k] + tmp_shift + 15 - div_factor_e[k] - 32 move32(); - q_ppPred_coeffs_re[i][k] = add( sub( add( q_cov_real[add( i, 1 )][0][k], tmp_shift ), div_factor_e[k] ), 1 + 15 - 32 ); + q_ppPred_coeffs_re[i][k] = add( sub( add( q_cov_real[i + 1][0][k], tmp_shift ), div_factor_e[k] ), 1 + 15 - 32 ); move16(); } ELSE @@ -996,13 +779,13 @@ static void ivas_get_pred_coeffs_enc_fx( { FOR( k = start_band; k < end_band; k++ ) { - tmp64 = W_mult_32_16( cov_real[add( i, 1 )][0][k], div_factor[k] ); + tmp64 = W_mult_32_16( cov_real[i + 1][0][k], div_factor[k] ); tmp_shift = W_norm( tmp64 ); IF( tmp64 != 0 ) { dm_v_re[i][k] = W_extract_h( W_shl( tmp64, tmp_shift ) ); // 1 + q_cov_real[i+1][0][k] + tmp_shift + 15 - div_factor_e[k] - 32 move32(); - dm_v_re_q[i][k] = add( sub( add( q_cov_real[add( i, 1 )][0][k], tmp_shift ), div_factor_e[k] ), 1 + 15 - 32 ); + dm_v_re_q[i][k] = add( sub( add( q_cov_real[i + 1][0][k], tmp_shift ), div_factor_e[k] ), 1 + 15 - 32 ); move16(); } ELSE @@ -1044,11 +827,11 @@ static void ivas_get_pred_coeffs_enc_fx( FOR( k = 1; k < in_chans; k++ ) { // IVAS_RMULT_FLOAT( cov_real[j + 1][k][b], dm_v_re[k - 1][b], re ); - re = W_mult0_32_32( cov_real[add( j, 1 )][k][b], dm_v_re[sub( k, 1 )][b] ); + re = W_mult0_32_32( cov_real[j + 1][k][b], dm_v_re[k - 1][b] ); tmp_shift = W_norm( re ); IF( re != 0 ) { - q_tmp = sub( add( add( q_cov_real[add( j, 1 )][k][b], dm_v_re_q[sub( k, 1 )][b] ), tmp_shift ), 32 ); + q_tmp = sub( add( add( q_cov_real[j + 1][k][b], dm_v_re_q[k - 1][b] ), tmp_shift ), 32 ); } ELSE { @@ -1146,7 +929,7 @@ static void ivas_get_pred_coeffs_enc_fx( dm_v_re_q[i][b] = 31; move16(); } - dm_v_re[sub( res_ind, 1 )][b] = MAX_32; + dm_v_re[res_ind - 1][b] = MAX_32; move32(); dm_v_re_q[i][b] = 31; move16(); @@ -1525,7 +1308,7 @@ static void ivas_get_pred_coeffs_fx( { FOR( k = start_band; k < end_band; k++ ) { - ppPred_coeffs_re[i][k] = Mpy_32_32( cov_real[add( i, 1 )][0][k], div_factor[k] ); // Q30 + temp_shift - 31 => tmp_shift - 1 + ppPred_coeffs_re[i][k] = Mpy_32_32( cov_real[i + 1][0][k], div_factor[k] ); // Q30 + temp_shift - 31 => tmp_shift - 1 move32(); // IVAS_CALCULATE_SQ_ABS_N( ppPred_coeffs_re[i][k], abs_value ); @@ -1751,8 +1534,8 @@ static void ivas_get_pred_coeffs_fx( Word32 re; // IVAS_RMULT_FLOAT( cov_real[j + 1][k][b], dm_v_re[k - 1][b], re ); - re = Mpy_32_32( cov_real[add( j, 1 )][k][b], dm_v_re[sub( k, 1 )][b] ); // Q30 + Q_div_factor - 1 - 31 - real[j] = L_add( real[j], re ); // tmp_shift - 2 + re = Mpy_32_32( cov_real[j + 1][k][b], dm_v_re[k - 1][b] ); // Q30 + Q_div_factor - 1 - 31 + real[j] = L_add( real[j], re ); // tmp_shift - 2 move32(); } } @@ -1788,12 +1571,12 @@ static void ivas_get_pred_coeffs_fx( } IF( NE_16( sub( tmp_shift, 1 ), 31 ) ) { - dm_v_re[sub( res_ind, 1 )][b] = L_shl( 1, sub( tmp_shift, 1 ) ); + dm_v_re[res_ind - 1][b] = L_shl( 1, sub( tmp_shift, 1 ) ); move32(); } ELSE { - dm_v_re[sub( res_ind, 1 )][b] = MAX_32; + dm_v_re[res_ind - 1][b] = MAX_32; move32(); } passive_g = activew_quad_thresh; @@ -1917,71 +1700,6 @@ static void ivas_get_pred_coeffs_fx( * Calculation of scaling factor for post predicted W channel *-----------------------------------------------------------------------------------------*/ -static void ivas_get_Wscaling_factor( - float *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], - float pred_coeffs_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], - float ***mixer_mat, - const int16_t start_band, - const int16_t end_band, - const int16_t dtx_vad, - const int16_t num_ch, - const int16_t *pNum_dmx, - const int16_t bands_bw, - const int16_t active_w, - const int16_t active_w_vlbr, - float *pWscale, - const int16_t dyn_active_w_flag ) -{ - int16_t b, ch; - float dm_f_local, abs_val; - float postpred_cov_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH]; - - for ( ch = 0; ch < IVAS_SPAR_MAX_CH; ch++ ) - { - set_zero( postpred_cov_re[ch], IVAS_SPAR_MAX_CH ); - } - - if ( dtx_vad == 0 ) - { - dm_f_local = IVAS_ACTIVEW_DM_F_SCALE_DTX; - } - else - { - dm_f_local = ( active_w_vlbr ) ? IVAS_ACTIVEW_DM_F_SCALE_VLBR : IVAS_ACTIVEW_DM_F_SCALE; - } - - for ( b = start_band; b < end_band; b++ ) - { - pWscale[b] = 1; - - if ( ( active_w == 1 ) && ( dyn_active_w_flag == 0 ) ) - { - float Gw_sq, g_sq = 0; - - if ( num_ch != pNum_dmx[b * bands_bw] ) - { - ivas_calc_post_pred_per_band( cov_real, mixer_mat, num_ch, b, postpred_cov_re ); - } - - Gw_sq = cov_real[0][0][b] / max( postpred_cov_re[0][0], IVAS_FLT_EPS ); - - for ( ch = 0; ch < num_ch - 1; ch++ ) - { - IVAS_CALCULATE_SQ_ABS_N( pred_coeffs_re[ch][b], abs_val ); - - g_sq += abs_val; - } - - pWscale[b] = sqrtf( Gw_sq ); - pWscale[b] = pWscale[b] + sqrtf( Gw_sq + ( 4 * dm_f_local * g_sq ) ); - pWscale[b] *= 0.5f; - } - } - - return; -} - - #ifdef IVAS_FLOAT_FIXED static void ivas_get_Wscaling_factor_enc_fx( @@ -2033,9 +1751,9 @@ static void ivas_get_Wscaling_factor_enc_fx( FOR( b = start_band; b < end_band; b++ ) { - pWscale[b] = 1; + pWscale[b] = ONE_IN_Q31; move32(); - q_pWscale[b] = 0; + q_pWscale[b] = Q31; move16(); test(); @@ -2047,7 +1765,7 @@ static void ivas_get_Wscaling_factor_enc_fx( g_sq = 0; move32(); - IF( NE_16( num_ch, pNum_dmx[i_mult( b, bands_bw )] ) ) + IF( NE_16( num_ch, pNum_dmx[b * bands_bw] ) ) { ivas_calc_post_pred_per_band_enc_fx( cov_real, q_cov_real, mixer_mat, q_mixer_mat, num_ch, b, postpred_cov_re, &q_postpred_cov_re ); } @@ -2159,7 +1877,7 @@ static void ivas_get_Wscaling_factor_fx( g_sq = 0; move32(); - IF( NE_16( num_ch, pNum_dmx[i_mult( b, bands_bw )] ) ) + IF( NE_16( num_ch, pNum_dmx[b * bands_bw] ) ) { ivas_calc_post_pred_per_band_fx( cov_real, q_cov_real, mixer_mat, q_mixer_mat, num_ch, b, postpred_cov_re, &q_postpred_cov_re ); } @@ -2217,111 +1935,6 @@ static void ivas_get_Wscaling_factor_fx( * Calculation of downmix matrix *-----------------------------------------------------------------------------------------*/ -void ivas_create_fullr_dmx_mat( - float pred_coeffs_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], - float dm_fv_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], - float ***mixer_mat, - const int16_t in_chans, - const int16_t start_band, - const int16_t end_band, - const int16_t active_w, - ivas_spar_md_com_cfg *hMdCfg ) -{ - int16_t i, j, k, b; - const int16_t *order; - float tmp_p1_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH][IVAS_MAX_NUM_BANDS]; - float tmp_p2_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH][IVAS_MAX_NUM_BANDS]; - float down_mix_mat1_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH][IVAS_MAX_NUM_BANDS]; - int16_t remix_unmix_order; - int16_t nbands; - nbands = end_band - start_band; - remix_unmix_order = hMdCfg->remix_unmix_order; - - order = remix_order_set[remix_unmix_order]; - - for ( i = 0; i < in_chans; i++ ) - { - for ( j = 0; j < in_chans; j++ ) - { - set_zero( &tmp_p1_re[i][j][start_band], nbands ); - set_zero( &tmp_p2_re[i][j][start_band], nbands ); - set_zero( &down_mix_mat1_re[i][j][start_band], nbands ); - } - } - - for ( j = 0; j < in_chans; j++ ) - { - for ( b = start_band; b < end_band; b++ ) - { - tmp_p2_re[j][j][b] = 1.0f; - } - } - - for ( j = 1; j < in_chans; j++ ) - { - for ( b = start_band; b < end_band; b++ ) - { - tmp_p2_re[j][0][b] = -pred_coeffs_re[j - 1][b]; - } - } - - if ( active_w == 1 ) - { - for ( j = 0; j < in_chans; j++ ) - { - for ( b = start_band; b < end_band; b++ ) - { - tmp_p1_re[j][j][b] = 1.0f; - } - } - - for ( j = 1; j < in_chans; j++ ) - { - for ( b = start_band; b < end_band; b++ ) - { - tmp_p1_re[0][j][b] = dm_fv_re[j - 1][b]; - } - } - - /* 4x4 mult */ - for ( i = 0; i < in_chans; i++ ) - { - for ( j = 0; j < in_chans; j++ ) - { - for ( k = 0; k < in_chans; k++ ) - { - for ( b = start_band; b < end_band; b++ ) - { - float tmp_re; - IVAS_RMULT_FLOAT( tmp_p2_re[i][k][b], tmp_p1_re[k][j][b], tmp_re ); - down_mix_mat1_re[i][j][b] += tmp_re; - } - } - } - } - } - else - { - for ( j = 0; j < in_chans; j++ ) - { - for ( k = 0; k < in_chans; k++ ) - { - for ( b = start_band; b < end_band; b++ ) - { - down_mix_mat1_re[j][k][b] = tmp_p2_re[j][k][b]; - } - } - } - } - - if ( remix_unmix_order != 3 ) - { - ivas_reorder_array( down_mix_mat1_re, in_chans, order, mixer_mat, start_band, end_band ); - } - - return; -} - #ifdef IVAS_FLOAT_FIXED void ivas_create_fullr_dmx_mat_fx( @@ -2380,7 +1993,7 @@ void ivas_create_fullr_dmx_mat_fx( { FOR( b = start_band; b < end_band; b++ ) { - tmp_p2_re[j][0][b] = L_negate( pred_coeffs_re[sub( j, 1 )][b] ); + tmp_p2_re[j][0][b] = L_negate( pred_coeffs_re[j - 1][b] ); move32(); max_val_tmp_p2 = L_max( max_val_tmp_p2, L_abs( tmp_p2_re[j][0][b] ) ); } @@ -2408,7 +2021,7 @@ void ivas_create_fullr_dmx_mat_fx( { FOR( b = start_band; b < end_band; b++ ) { - tmp_p1_re[0][j][b] = dm_fv_re[sub( j, 1 )][b]; + tmp_p1_re[0][j][b] = dm_fv_re[j - 1][b]; move32(); max_val = L_max( max_val, L_abs( tmp_p1_re[0][j][b] ) ); } @@ -2469,32 +2082,6 @@ void ivas_create_fullr_dmx_mat_fx( * reorders the input matrix based on order *-----------------------------------------------------------------------------------------*/ -static void ivas_reorder_array( - float in_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH][IVAS_MAX_NUM_BANDS], - const int16_t in_chans, - const int16_t order[IVAS_SPAR_MAX_CH], - float ***mixer_mat, - const int16_t start_band, - const int16_t end_band ) -{ - int16_t i, j, b, idx; - - for ( i = 0; i < in_chans; i++ ) - { - idx = order[i]; - - for ( j = 0; j < in_chans; j++ ) - { - for ( b = start_band; b < end_band; b++ ) - { - mixer_mat[i][j][b] = in_re[idx][j][b]; - } - } - } - - return; -} - #ifdef IVAS_FLOAT_FIXED static void ivas_reorder_array_fx( Word32 in_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH][IVAS_MAX_NUM_BANDS], @@ -2531,70 +2118,6 @@ static void ivas_reorder_array_fx( * Calculate post pred mat per band *-----------------------------------------------------------------------------------------*/ -static void ivas_calc_post_pred_per_band( - float *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], - float ***mixer_mat, - const int16_t num_ch, - const int16_t band_idx, - float postpred_cov_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH] ) -{ - int16_t i, j, k; - float dmx_mat_conj[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH]; - float temp_mat[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH]; - float tmp_re; - - for ( i = 0; i < num_ch; i++ ) - { - for ( j = 0; j < num_ch; j++ ) - { - dmx_mat_conj[i][j] = mixer_mat[j][i][band_idx]; - } - } - - for ( i = 0; i < num_ch; i++ ) - { - set_zero( postpred_cov_re[i], num_ch ); - } - - /* num_ch x num_ch mult */ - for ( i = 0; i < num_ch; i++ ) - { - for ( j = 0; j < num_ch; j++ ) - { - temp_mat[i][j] = 0; - for ( k = 0; k < num_ch; k++ ) - { - IVAS_RMULT_FLOAT( cov_real[i][k][band_idx], dmx_mat_conj[k][j], tmp_re ); - temp_mat[i][j] += tmp_re; - } - } - } - - /* num_ch x num_ch mult */ - for ( i = 0; i < num_ch; i++ ) - { - for ( j = i; j < num_ch; j++ ) - { - for ( k = 0; k < num_ch; k++ ) - { - IVAS_RMULT_FLOAT( mixer_mat[i][k][band_idx], temp_mat[k][j], tmp_re ); - postpred_cov_re[i][j] += tmp_re; - } - } - } - - for ( i = 0; i < num_ch; i++ ) - { - for ( j = 0; j < i; j++ ) - { - postpred_cov_re[i][j] = postpred_cov_re[j][i]; - } - } - - return; -} - - #ifdef IVAS_FLOAT_FIXED static void ivas_calc_post_pred_per_band_enc_fx( @@ -2879,198 +2402,9 @@ static void ivas_calc_post_pred_per_band_fx( * * Calculate P coeffs per band *-----------------------------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED -static void ivas_calc_p_coeffs_per_band( - ivas_spar_md_t *pSparMd, - const int16_t i_ts, - float postpred_cov_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], - const int16_t num_ch, - const int16_t dtx_vad, - const int16_t num_dmx, - const int16_t band_idx ) -{ - int16_t i, j, k; - int16_t m; - float factor = 0; - float recon_uu_re[IVAS_SPAR_MAX_CH - IVAS_SPAR_MAX_DMX_CHS][IVAS_SPAR_MAX_CH - IVAS_SPAR_MAX_DMX_CHS]; - float trace = 0; - float p_norm_scaling = 0; - float cov_dd_re[IVAS_SPAR_MAX_CH - 1][IVAS_SPAR_MAX_CH - 1]; - float cov_uu_re[IVAS_SPAR_MAX_CH - 1][IVAS_SPAR_MAX_CH - 1]; - int16_t b_ts_idx; - - b_ts_idx = band_idx + i_ts * IVAS_MAX_NUM_BANDS; - - if ( num_dmx != num_ch ) - { - set_zero( pSparMd->band_coeffs[b_ts_idx].P_re, IVAS_SPAR_MAX_CH - 1 ); - set32_fx( pSparMd->band_coeffs[b_ts_idx].P_re_fx, 0, IVAS_SPAR_MAX_CH - 1 ); - for ( i = 0; i < IVAS_SPAR_MAX_CH - IVAS_SPAR_MAX_DMX_CHS; i++ ) - { - set_zero( recon_uu_re[i], IVAS_SPAR_MAX_CH - IVAS_SPAR_MAX_DMX_CHS ); - } - - for ( i = num_dmx; i < num_ch; i++ ) - { - for ( j = num_dmx; j < num_ch; j++ ) - { - cov_uu_re[i - num_dmx][j - num_dmx] = postpred_cov_re[i][j]; - } - } - - if ( dtx_vad == 1 ) - { - for ( i = 1; i < num_dmx; i++ ) - { - for ( j = 1; j < num_dmx; j++ ) - { - cov_dd_re[i - 1][j - 1] = postpred_cov_re[i][j]; - } - } - - if ( num_dmx == 2 ) - { - float re1, re2; - - IVAS_RMULT_FLOAT( pSparMd->band_coeffs[b_ts_idx].C_re[0][0], cov_dd_re[0][0], re1 ); - IVAS_RMULT_FLOAT( pSparMd->band_coeffs[b_ts_idx].C_re[1][0], cov_dd_re[0][0], re2 ); - IVAS_RMULT_FLOAT( pSparMd->band_coeffs[b_ts_idx].C_re[0][0], re1, recon_uu_re[0][0] ); - IVAS_RMULT_FLOAT( pSparMd->band_coeffs[b_ts_idx].C_re[1][0], re1, recon_uu_re[0][1] ); - IVAS_RMULT_FLOAT( pSparMd->band_coeffs[b_ts_idx].C_re[0][0], re2, recon_uu_re[1][0] ); - IVAS_RMULT_FLOAT( pSparMd->band_coeffs[b_ts_idx].C_re[1][0], re2, recon_uu_re[1][1] ); - - for ( i = 0; i < 2; i++ ) - { - for ( j = 0; j < 2; j++ ) - { - cov_uu_re[i][j] -= recon_uu_re[i][j]; - } - } - } - else if ( num_dmx == 3 ) - { - float re1[2], re2; - set_f( re1, 0, 2 ); - - for ( j = 0; j < 2; j++ ) - { - for ( k = 0; k < 2; k++ ) - { - float re; - - IVAS_RMULT_FLOAT( pSparMd->band_coeffs[b_ts_idx].C_re[0][k], cov_dd_re[k][j], re ); - re1[j] += re; - } - } - - IVAS_RMULT_FLOAT( pSparMd->band_coeffs[b_ts_idx].C_re[0][0], re1[0], re2 ); - recon_uu_re[0][0] = re2; - IVAS_RMULT_FLOAT( pSparMd->band_coeffs[b_ts_idx].C_re[0][1], re1[1], re2 ); - recon_uu_re[0][0] += re2; - - cov_uu_re[0][0] -= recon_uu_re[0][0]; - } - else if ( num_dmx == 4 ) - { - /* Step 1: Multiply C * cov_dd * C' */ - float re1[3], re; - - for ( i = 0; i < num_ch - num_dmx; i++ ) - { - set_f( re1, 0, 3 ); - for ( m = 0; m < num_dmx - 1; m++ ) - { - for ( k = 0; k < num_dmx - 1; k++ ) - { - IVAS_RMULT_FLOAT( pSparMd->band_coeffs[b_ts_idx].C_re[i][k], cov_dd_re[k][m], re ); - re1[m] += re; - } - } - for ( j = 0; j < num_ch - num_dmx; j++ ) - { - for ( m = 0; m < num_dmx - 1; m++ ) - { - IVAS_RMULT_FLOAT( pSparMd->band_coeffs[b_ts_idx].C_re[j][m], re1[m], re ); - recon_uu_re[i][j] += re; - } - } - } - - /* Step 2: cov_uu - recon_uu */ - for ( i = 0; i < num_ch - num_dmx; i++ ) - { - for ( j = 0; j < num_ch - num_dmx; j++ ) - { - cov_uu_re[i][j] -= recon_uu_re[i][j]; - } - } - } - } - - p_norm_scaling = IVAS_P_NORM_SCALING; - - if ( ( dtx_vad == 0 ) && ( num_dmx == 1 ) ) - { - p_norm_scaling = IVAS_P_NORM_SCALING_DTX; - } - - trace = 0.0f; - - for ( i = num_dmx; i < num_ch; i++ ) - { - float tmp_out; - IVAS_CALCULATE_RABS( cov_uu_re[i - num_dmx][i - num_dmx], tmp_out ); - trace += tmp_out; - } - - factor = max( 1e-20f, postpred_cov_re[0][0] ); - factor = max( factor, ( p_norm_scaling * trace ) ); - factor = 1 / factor; - - /* normalise Hermitian (except for rounding) cov_uu */ - for ( i = num_dmx; i < num_ch; i++ ) - { - for ( j = num_dmx; j < num_ch; j++ ) - { - if ( i == j ) - { - /* force diagonal to be real */ - cov_uu_re[i - num_dmx][j - num_dmx] *= factor; - } - else - { - /* set off-diag elements to zero */ - cov_uu_re[i - num_dmx][j - num_dmx] = 0; - } - } - } - - /* take sqrt of max of diags and zero */ - for ( i = num_dmx; i < num_ch; i++ ) - { - cov_uu_re[i - num_dmx][i - num_dmx] = sqrtf( max( 0.0f, cov_uu_re[i - num_dmx][i - num_dmx] ) ); - /* cov_uu_im[i - num_dmx][i - num_dmx] = 0; */ - } - - /* save into MD struct */ - for ( i = num_dmx; i < num_ch; i++ ) - { - for ( j = num_dmx; j < num_ch; j++ ) - { - if ( i == j ) - { - pSparMd->band_coeffs[b_ts_idx].P_re[j - num_dmx] = cov_uu_re[i - num_dmx][j - num_dmx]; - } - } - } - } - - return; -} - -#ifdef IVAS_FLOAT_FIXED - -static void ivas_calc_p_coeffs_per_band_enc_fx( +static void ivas_calc_p_coeffs_per_band_enc_fx( ivas_spar_md_t *pSparMd, const Word16 i_ts, Word32 postpred_cov_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], @@ -3111,7 +2445,7 @@ static void ivas_calc_p_coeffs_per_band_enc_fx( { FOR( j = num_dmx; j < num_ch; j++ ) { - cov_uu_re[sub( i, num_dmx )][sub( j, num_dmx )] = postpred_cov_re[i][j]; + cov_uu_re[i - num_dmx][j - num_dmx] = postpred_cov_re[i][j]; move32(); } } @@ -3124,7 +2458,7 @@ static void ivas_calc_p_coeffs_per_band_enc_fx( { FOR( j = 1; j < num_dmx; j++ ) { - cov_dd_re[sub( i, 1 )][sub( j, 1 )] = postpred_cov_re[i][j]; + cov_dd_re[i - 1][j - 1] = postpred_cov_re[i][j]; move32(); } } @@ -3317,7 +2651,7 @@ static void ivas_calc_p_coeffs_per_band_enc_fx( { FOR( j = num_dmx; j < num_ch; j++ ) { - cov_uu_re[sub( i, num_dmx )][sub( j, num_dmx )] = L_shr( cov_uu_re[sub( i, num_dmx )][sub( j, num_dmx )], sub( q_cov_uu_re, q_tmp ) ); + cov_uu_re[i - num_dmx][j - num_dmx] = L_shr( cov_uu_re[i - num_dmx][j - num_dmx], sub( q_cov_uu_re, q_tmp ) ); move32(); } } @@ -3334,7 +2668,7 @@ static void ivas_calc_p_coeffs_per_band_enc_fx( { FOR( j = num_dmx; j < num_ch; j++ ) { - cov_uu_re[sub( i, num_dmx )][sub( j, num_dmx )] = L_shr( cov_uu_re[sub( i, num_dmx )][sub( j, num_dmx )], 1 ); + cov_uu_re[i - num_dmx][j - num_dmx] = L_shr( cov_uu_re[i - num_dmx][j - num_dmx], 1 ); move32(); } } @@ -3483,7 +2817,7 @@ static void ivas_calc_p_coeffs_per_band_enc_fx( FOR( i = num_dmx; i < num_ch; i++ ) { - trace = W_add( trace, W_deposit32_l( L_abs( cov_uu_re[sub( i, num_dmx )][sub( i, num_dmx )] ) ) ); + trace = W_add( trace, W_deposit32_l( L_abs( cov_uu_re[i - num_dmx][i - num_dmx] ) ) ); } factor = L_max( IVAS_FIX_EPS, postpred_cov_re[0][0] ); @@ -3520,24 +2854,24 @@ static void ivas_calc_p_coeffs_per_band_enc_fx( IF( EQ_16( i, j ) ) { /* force diagonal to be real */ - W_tmp = W_mult0_32_32( cov_uu_re[sub( i, num_dmx )][sub( j, num_dmx )], factor ); + W_tmp = W_mult0_32_32( cov_uu_re[i - num_dmx][j - num_dmx], factor ); q_tmp = 32; move16(); if ( W_tmp != 0 ) { q_tmp = W_norm( W_tmp ); } - cov_uu_re[sub( i, num_dmx )][sub( j, num_dmx )] = W_extract_h( W_shl( W_mult0_32_32( cov_uu_re[sub( i, num_dmx )][sub( j, num_dmx )], factor ), q_tmp ) ); + cov_uu_re[i - num_dmx][j - num_dmx] = W_extract_h( W_shl( W_mult0_32_32( cov_uu_re[i - num_dmx][j - num_dmx], factor ), q_tmp ) ); move32(); - q_cov_uu_re_per_value[sub( i, num_dmx )][sub( j, num_dmx )] = sub( add( add( q_cov_uu_re, sub( 15, factor_exp ) ), q_tmp ), 32 ); + q_cov_uu_re_per_value[i - num_dmx][j - num_dmx] = sub( add( add( q_cov_uu_re, sub( 15, factor_exp ) ), q_tmp ), 32 ); move16(); } ELSE { /* set off-diag elements to zero */ - cov_uu_re[sub( i, num_dmx )][sub( j, num_dmx )] = 0; + cov_uu_re[i - num_dmx][j - num_dmx] = 0; move32(); - q_cov_uu_re_per_value[sub( i, num_dmx )][sub( j, num_dmx )] = 0; + q_cov_uu_re_per_value[i - num_dmx][j - num_dmx] = 0; move16(); } } @@ -3549,12 +2883,12 @@ static void ivas_calc_p_coeffs_per_band_enc_fx( /* take sqrt of max of diags and zero */ FOR( i = num_dmx; i < num_ch; i++ ) { - cov_uu_re_exp = sub( 31, q_cov_uu_re_per_value[sub( i, num_dmx )][sub( i, num_dmx )] ); - cov_uu_re[sub( i, num_dmx )][sub( i, num_dmx )] = Sqrt32( L_max( 0, cov_uu_re[sub( i, num_dmx )][sub( i, num_dmx )] ), &cov_uu_re_exp ); + cov_uu_re_exp = sub( 31, q_cov_uu_re_per_value[i - num_dmx][i - num_dmx] ); + cov_uu_re[i - num_dmx][i - num_dmx] = Sqrt32( L_max( 0, cov_uu_re[i - num_dmx][i - num_dmx] ), &cov_uu_re_exp ); move32(); - q_cov_uu_re_per_value[sub( i, num_dmx )][sub( i, num_dmx )] = sub( 31, cov_uu_re_exp ); + q_cov_uu_re_per_value[i - num_dmx][i - num_dmx] = sub( 31, cov_uu_re_exp ); move16(); - q_tmp = s_min( q_tmp, q_cov_uu_re_per_value[sub( i, num_dmx )][sub( i, num_dmx )] ); + q_tmp = s_min( q_tmp, q_cov_uu_re_per_value[i - num_dmx][i - num_dmx] ); } /* save into MD struct */ @@ -3564,12 +2898,12 @@ static void ivas_calc_p_coeffs_per_band_enc_fx( { IF( EQ_16( i, j ) ) { - pSparMd->band_coeffs[b_ts_idx].P_re_fx[sub( j, num_dmx )] = L_shr( cov_uu_re[sub( i, num_dmx )][sub( j, num_dmx )], sub( q_cov_uu_re_per_value[sub( i, num_dmx )][sub( j, num_dmx )], q_tmp ) ); + pSparMd->band_coeffs[b_ts_idx].P_re_fx[j - num_dmx] = L_shr( cov_uu_re[i - num_dmx][j - num_dmx], sub( q_cov_uu_re_per_value[i - num_dmx][j - num_dmx], Q28 ) ); move32(); } } } - pSparMd->band_coeffs[b_ts_idx].q_P_re_fx = q_tmp; + pSparMd->band_coeffs[b_ts_idx].q_P_re_fx = Q28; move16(); } @@ -3614,7 +2948,7 @@ static void ivas_calc_p_coeffs_per_band_fx( { FOR( j = num_dmx; j < num_ch; j++ ) { - cov_uu_re[sub( i, num_dmx )][sub( j, num_dmx )] = postpred_cov_re[i][j]; + cov_uu_re[i - num_dmx][j - num_dmx] = postpred_cov_re[i][j]; move32(); } } @@ -3627,7 +2961,7 @@ static void ivas_calc_p_coeffs_per_band_fx( { FOR( j = 1; j < num_dmx; j++ ) { - cov_dd_re[sub( i, 1 )][sub( j, 1 )] = postpred_cov_re[i][j]; + cov_dd_re[i - 1][j - 1] = postpred_cov_re[i][j]; move32(); } } @@ -3741,7 +3075,7 @@ static void ivas_calc_p_coeffs_per_band_fx( FOR( i = num_dmx; i < num_ch; i++ ) { - trace = L_add( trace, L_abs( cov_uu_re[sub( i, num_dmx )][sub( i, num_dmx )] ) ); + trace = L_add( trace, L_abs( cov_uu_re[i - num_dmx][i - num_dmx] ) ); } factor = L_max( IVAS_FIX_EPS, postpred_cov_re[0][0] ); @@ -3760,7 +3094,7 @@ static void ivas_calc_p_coeffs_per_band_fx( IF( EQ_16( i, j ) ) { /* force diagonal to be real */ - cov_uu_re[sub( i, num_dmx )][sub( j, num_dmx )] = W_extract_l( W_shr( W_mult0_32_32( cov_uu_re[sub( i, num_dmx )][sub( j, num_dmx )], factor ), tmp ) ); + cov_uu_re[i - num_dmx][j - num_dmx] = W_extract_l( W_shr( W_mult0_32_32( cov_uu_re[i - num_dmx][j - num_dmx], factor ), tmp ) ); move32(); } ELSE @@ -3777,8 +3111,8 @@ static void ivas_calc_p_coeffs_per_band_fx( FOR( i = num_dmx; i < num_ch; i++ ) { cov_uu_re_exp = sub( 31, q_cov_uu_re ); - cov_uu_re[sub( i, num_dmx )][sub( i, num_dmx )] = Sqrt32( L_max( 0, cov_uu_re[sub( i, num_dmx )][sub( i, num_dmx )] ), &cov_uu_re_exp ); - cov_uu_re[sub( i, num_dmx )][sub( i, num_dmx )] = L_shl( cov_uu_re[sub( i, num_dmx )][sub( i, num_dmx )], sub( q_cov_uu_re, sub( 31, cov_uu_re_exp ) ) ); + cov_uu_re[i - num_dmx][i - num_dmx] = Sqrt32( L_max( 0, cov_uu_re[i - num_dmx][i - num_dmx] ), &cov_uu_re_exp ); + cov_uu_re[i - num_dmx][i - num_dmx] = L_shl( cov_uu_re[i - num_dmx][i - num_dmx], sub( q_cov_uu_re, sub( 31, cov_uu_re_exp ) ) ); move32(); move32(); } @@ -3790,7 +3124,7 @@ static void ivas_calc_p_coeffs_per_band_fx( { IF( EQ_16( i, j ) ) { - pSparMd->band_coeffs[b_ts_idx].P_re_fx[sub( j, num_dmx )] = cov_uu_re[sub( i, num_dmx )][sub( j, num_dmx )]; + pSparMd->band_coeffs[b_ts_idx].P_re_fx[j - num_dmx] = cov_uu_re[i - num_dmx][j - num_dmx]; move32(); } } @@ -3810,96 +3144,6 @@ static void ivas_calc_p_coeffs_per_band_fx( * * Calculate C coeffs per band *-----------------------------------------------------------------------------------------*/ - -static void ivas_calc_c_coeffs_per_band( - ivas_spar_md_t *pSparMd, - const int16_t i_ts, - float postpred_cov_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], - const int16_t num_ch, - const int16_t num_dmx, - const int16_t band_idx, - const int16_t dtx_vad ) -{ - int16_t i, j, k; - - /* worst case for cov_ud is actually 12 x 3 */ - float cov_ud_re[IVAS_SPAR_MAX_CH - IVAS_SPAR_MAX_DMX_CHS][IVAS_SPAR_MAX_DMX_CHS - 1]; - float cov_dd_re[FOA_CHANNELS - 1][FOA_CHANNELS - 1]; - float cov_dd_re_inv[FOA_CHANNELS - 1][FOA_CHANNELS - 1]; - float trace_cov_dd_re = 0; - float abs_trace; - float re; - int16_t b_ts_idx; - - b_ts_idx = band_idx + i_ts * IVAS_MAX_NUM_BANDS; - - if ( dtx_vad == 0 ) - { - set_zero( &pSparMd->band_coeffs[b_ts_idx].C_re[0][0], ( IVAS_SPAR_MAX_CH - IVAS_SPAR_MAX_DMX_CHS ) * ( IVAS_SPAR_MAX_DMX_CHS - 1 ) ); - return; - } - - for ( i = num_dmx; i < num_ch; i++ ) - { - for ( j = 1; j < num_dmx; j++ ) - { - cov_ud_re[i - num_dmx][j - 1] = postpred_cov_re[i][j]; - } - } - - for ( i = 1; i < num_dmx; i++ ) - { - for ( j = 1; j < num_dmx; j++ ) - { - cov_dd_re[i - 1][j - 1] = postpred_cov_re[i][j]; - } - } - - for ( i = 0; i < num_dmx - 1; i++ ) - { - trace_cov_dd_re += cov_dd_re[i][i]; - } - trace_cov_dd_re *= 0.005f; - - IVAS_CALCULATE_RABS( trace_cov_dd_re, abs_trace ); - - if ( abs_trace < IVAS_FLT_EPS ) - { - /* protection from cases when variance of residual channels is very small */ - set_zero( &pSparMd->band_coeffs[b_ts_idx].C_re[0][0], ( IVAS_SPAR_MAX_CH - IVAS_SPAR_MAX_DMX_CHS ) * ( IVAS_SPAR_MAX_DMX_CHS - 1 ) ); - } - else - { - for ( i = 0; i < num_dmx - 1; i++ ) - { - cov_dd_re[i][i] += trace_cov_dd_re; - } - if ( ivas_is_mat_inv( cov_dd_re, num_dmx - 1 ) && ( num_dmx < FOA_CHANNELS ) ) - { - set_zero( &pSparMd->band_coeffs[b_ts_idx].C_re[0][0], ( IVAS_SPAR_MAX_CH - IVAS_SPAR_MAX_DMX_CHS ) * ( IVAS_SPAR_MAX_DMX_CHS - 1 ) ); - } - else - { - ivas_calc_mat_inv( cov_dd_re, num_dmx - 1, cov_dd_re_inv ); - - for ( i = 0; i < num_ch - num_dmx; i++ ) - { - for ( j = 0; j < num_dmx - 1; j++ ) - { - pSparMd->band_coeffs[b_ts_idx].C_re[i][j] = 0; - for ( k = 0; k < num_dmx - 1; k++ ) - { - IVAS_RMULT_FLOAT( cov_ud_re[i][k], cov_dd_re_inv[k][j], re ); - pSparMd->band_coeffs[b_ts_idx].C_re[i][j] += re; - } - } - } - } - } - - return; -} - #ifdef IVAS_FLOAT_FIXED static void ivas_calc_c_coeffs_per_band_enc_fx( @@ -3938,7 +3182,7 @@ static void ivas_calc_c_coeffs_per_band_enc_fx( { FOR( j = 1; j < num_dmx; j++ ) { - cov_ud_re[sub( i, num_dmx )][sub( j, 1 )] = postpred_cov_re[i][j]; + cov_ud_re[i - num_dmx][j - 1] = postpred_cov_re[i][j]; move32(); } } @@ -3954,7 +3198,7 @@ static void ivas_calc_c_coeffs_per_band_enc_fx( { max_val = L_max( max_val, postpred_cov_re[i][j] ); } - cov_dd_re[sub( i, 1 )][sub( j, 1 )] = postpred_cov_re[i][j]; + cov_dd_re[i - 1][j - 1] = postpred_cov_re[i][j]; move32(); } } @@ -4087,7 +3331,7 @@ static void ivas_calc_c_coeffs_per_band_fx( { FOR( j = 1; j < num_dmx; j++ ) { - cov_ud_re[sub( i, num_dmx )][sub( j, 1 )] = postpred_cov_re[i][j]; + cov_ud_re[i - num_dmx][j - 1] = postpred_cov_re[i][j]; move32(); } } @@ -4096,7 +3340,7 @@ static void ivas_calc_c_coeffs_per_band_fx( { FOR( j = 1; j < num_dmx; j++ ) { - cov_dd_re[sub( i, 1 )][sub( j, 1 )] = postpred_cov_re[i][j]; + cov_dd_re[i - 1][j - 1] = postpred_cov_re[i][j]; move32(); } } @@ -4187,57 +3431,6 @@ static void ivas_calc_c_coeffs_per_band_fx( * Calculation of C and P coeffs *-----------------------------------------------------------------------------------------*/ -void ivas_calc_c_p_coeffs( - ivas_spar_md_t *pSparMd, - float *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], - const int16_t i_ts, - float ***mixer_mat, - const int16_t num_ch, - const int16_t num_dmx, - const int16_t band_idx, - const int16_t dtx_vad, - const int16_t compute_p_flag, - const int16_t dyn_active_w_flag ) -{ - int16_t i, j; - float postpred_cov_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH]; - - if ( num_dmx != num_ch ) - { - ivas_calc_post_pred_per_band( cov_real, mixer_mat, num_ch, band_idx, postpred_cov_re ); - - if ( num_dmx != 1 ) - { - ivas_calc_c_coeffs_per_band( pSparMd, i_ts, postpred_cov_re, num_ch, num_dmx, band_idx, dtx_vad ); - } - - if ( dyn_active_w_flag ) - { - for ( i = 0; i < num_ch - num_dmx; i++ ) - { - for ( j = 0; j < num_dmx - 1; j++ ) - { - pSparMd->band_coeffs[band_idx + i_ts * IVAS_MAX_NUM_BANDS].C_re[i][j] = 0.0f; - } - } - } - if ( compute_p_flag == 1 ) - { - ivas_calc_p_coeffs_per_band( pSparMd, i_ts, postpred_cov_re, num_ch, dtx_vad, num_dmx, band_idx ); - } - - if ( dyn_active_w_flag ) - { - for ( i = num_dmx; i < num_ch; i++ ) - { - pSparMd->band_coeffs[band_idx + i_ts * IVAS_MAX_NUM_BANDS].P_re[i - num_dmx] = 0; - } - } - } - - return; -} - #ifdef IVAS_FLOAT_FIXED void ivas_calc_c_p_coeffs_enc_fx( @@ -4272,11 +3465,11 @@ void ivas_calc_c_p_coeffs_enc_fx( { FOR( j = 0; j < sub( num_dmx, 1 ); j++ ) { - pSparMd->band_coeffs[add( band_idx, imult1616( i_ts, IVAS_MAX_NUM_BANDS ) )].C_re_fx[i][j] = 0; + pSparMd->band_coeffs[band_idx + ( i_ts * IVAS_MAX_NUM_BANDS )].C_re_fx[i][j] = 0; move32(); } } - pSparMd->band_coeffs[add( band_idx, imult1616( i_ts, IVAS_MAX_NUM_BANDS ) )].q_C_re_fx = 0; + pSparMd->band_coeffs[band_idx + ( i_ts * IVAS_MAX_NUM_BANDS )].q_C_re_fx = 0; move16(); } IF( EQ_16( compute_p_flag, 1 ) ) @@ -4288,10 +3481,10 @@ void ivas_calc_c_p_coeffs_enc_fx( { FOR( i = num_dmx; i < num_ch; i++ ) { - pSparMd->band_coeffs[add( band_idx, imult1616( i_ts, IVAS_MAX_NUM_BANDS ) )].P_re_fx[sub( i, num_dmx )] = 0; + pSparMd->band_coeffs[band_idx + ( i_ts * IVAS_MAX_NUM_BANDS )].P_re_fx[i - num_dmx] = 0; move32(); } - pSparMd->band_coeffs[add( band_idx, imult1616( i_ts, IVAS_MAX_NUM_BANDS ) )].q_P_re_fx = 0; + pSparMd->band_coeffs[band_idx + ( i_ts * IVAS_MAX_NUM_BANDS )].q_P_re_fx = 0; move16(); } } @@ -4331,11 +3524,11 @@ void ivas_calc_c_p_coeffs_fx( { FOR( j = 0; j < sub( num_dmx, 1 ); j++ ) { - pSparMd->band_coeffs[add( band_idx, imult1616( i_ts, IVAS_MAX_NUM_BANDS ) )].C_re_fx[i][j] = 0; + pSparMd->band_coeffs[band_idx + ( i_ts * IVAS_MAX_NUM_BANDS )].C_re_fx[i][j] = 0; move32(); } } - pSparMd->band_coeffs[add( band_idx, imult1616( i_ts, IVAS_MAX_NUM_BANDS ) )].q_C_re_fx = 0; + pSparMd->band_coeffs[band_idx + ( i_ts * IVAS_MAX_NUM_BANDS )].q_C_re_fx = 0; move16(); } IF( EQ_16( compute_p_flag, 1 ) ) @@ -4347,10 +3540,10 @@ void ivas_calc_c_p_coeffs_fx( { FOR( i = num_dmx; i < num_ch; i++ ) { - pSparMd->band_coeffs[add( band_idx, imult1616( i_ts, IVAS_MAX_NUM_BANDS ) )].P_re_fx[sub( i, num_dmx )] = 0; + pSparMd->band_coeffs[band_idx + ( i_ts * IVAS_MAX_NUM_BANDS )].P_re_fx[i - num_dmx] = 0; move32(); } - pSparMd->band_coeffs[add( band_idx, imult1616( i_ts, IVAS_MAX_NUM_BANDS ) )].q_P_re_fx = 0; + pSparMd->band_coeffs[band_idx + ( i_ts * IVAS_MAX_NUM_BANDS )].q_P_re_fx = 0; move16(); } } @@ -4360,58 +3553,6 @@ void ivas_calc_c_p_coeffs_fx( #endif // IVAS_FLOAT_FIXED - -static void ivas_calc_mat_det( - double in_re[MAX_MAT_DIM][MAX_MAT_DIM], - const int16_t dim, - double *det_re ) -{ - if ( dim == IVAS_MAT_DIM_3 ) - { - double re1, re2, re; - IVAS_RMULT_DOUBLE( in_re[1][1], in_re[2][2], re1 ); - IVAS_RMULT_DOUBLE( in_re[1][2], in_re[2][1], re2 ); - re = re1 - re2; - - IVAS_RMULT_DOUBLE( in_re[0][0], re, re1 ); - - *det_re = re1; - - IVAS_RMULT_DOUBLE( in_re[1][0], in_re[2][2], re1 ); - IVAS_RMULT_DOUBLE( in_re[1][2], in_re[2][0], re2 ); - re = re1 - re2; - - IVAS_RMULT_DOUBLE( in_re[0][1], re, re1 ); - - *det_re -= re1; - - IVAS_RMULT_DOUBLE( in_re[1][0], in_re[2][1], re1 ); - IVAS_RMULT_DOUBLE( in_re[1][1], in_re[2][0], re2 ); - re = re1 - re2; - - IVAS_RMULT_DOUBLE( in_re[0][2], re, re1 ); - - *det_re += re1; - } - else if ( dim == IVAS_MAT_DIM_2 ) - { - double re1, re2; - IVAS_RMULT_DOUBLE( in_re[0][0], in_re[1][1], re1 ); - IVAS_RMULT_DOUBLE( in_re[0][1], in_re[1][0], re2 ); - *det_re = re1 - re2; - } - else if ( dim == IVAS_MAT_DIM_1 ) - { - *det_re = in_re[0][0]; - } - else - { - assert( !"matrix dimention not supported!" ); - } - - return; -} - #ifdef IVAS_FLOAT_FIXED static void ivas_calc_mat_det_fx( @@ -4488,36 +3629,6 @@ static void ivas_calc_mat_det_fx( * Calculate cofactor for invert matrix *-----------------------------------------------------------------------------------------*/ -static void ivas_get_mat_cofactor( - double in_re[MAX_MAT_DIM][MAX_MAT_DIM], - double out_re[MAX_MAT_DIM][MAX_MAT_DIM], - const int16_t row, - const int16_t col ) -{ - int16_t i, j; - int16_t r = 0, c = 0; - - for ( i = 0; i < MAX_MAT_DIM; i++ ) - { - for ( j = 0; j < MAX_MAT_DIM; j++ ) - { - if ( i != row && j != col ) - { - - out_re[r][c++] = in_re[i][j]; - } - } - if ( c == 2 ) - { - r++; - c = 0; - } - } - - return; -} - - #ifdef IVAS_FLOAT_FIXED static void ivas_get_mat_cofactor_fx( @@ -4563,99 +3674,6 @@ static void ivas_get_mat_cofactor_fx( * Calculate Invert of a matrix *-----------------------------------------------------------------------------------------*/ -static void ivas_calc_mat_inv( - float in_re[MAX_MAT_DIM][MAX_MAT_DIM], - const int16_t dim, - float out_re[MAX_MAT_DIM][MAX_MAT_DIM] ) -{ - double det; - int16_t i, j; - double dbl_in_re[MAX_MAT_DIM][MAX_MAT_DIM]; - double dbl_out_re[MAX_MAT_DIM][MAX_MAT_DIM]; - - for ( i = 0; i < dim; i++ ) - { - for ( j = 0; j < dim; j++ ) - { - dbl_in_re[i][j] = in_re[i][j]; - } - } - - if ( dim == IVAS_MAT_DIM_1 ) - { - det = ( dbl_in_re[0][0] * dbl_in_re[0][0] ); - /* assert to catch cases when input is singular matrix*/ - assert( det > 0 ); - det = 1 / det; - dbl_out_re[0][0] = dbl_in_re[0][0] * det; - } - else if ( dim == IVAS_MAT_DIM_2 ) - { - double det_re; - double re; - - ivas_calc_mat_det( dbl_in_re, dim, &det_re ); - det = ( det_re * det_re ); - /* assert to catch cases when input is singular matrix*/ - assert( det > 0 ); - det = 1 / det; - - IVAS_RMULT_DOUBLE( det_re, dbl_in_re[1][1], re ); - dbl_out_re[0][0] = re * det; - - IVAS_RMULT_DOUBLE( det_re, dbl_in_re[0][1], re ); - dbl_out_re[0][1] = -re * det; - - IVAS_RMULT_DOUBLE( det_re, dbl_in_re[1][0], re ); - dbl_out_re[1][0] = -re * det; - - IVAS_RMULT_DOUBLE( det_re, dbl_in_re[0][0], re ); - dbl_out_re[1][1] = re * det; - } - else if ( dim == IVAS_MAT_DIM_3 ) - { - double fac_re[IVAS_MAT_DIM_3][IVAS_MAT_DIM_3]; - double det_re; - int16_t sign = 1; - - ivas_calc_mat_det( dbl_in_re, dim, &det_re ); - det = det_re > 0 ? 1 / max( IVAS_DBL_EPS, det_re ) : min( det_re, -IVAS_DBL_EPS ); - - for ( i = 0; i < dim; i++ ) - { - for ( j = 0; j < dim; j++ ) - { - ivas_get_mat_cofactor( dbl_in_re, fac_re, i, j ); - ivas_calc_mat_det( fac_re, IVAS_MAT_DIM_2, &dbl_out_re[j][i] ); - dbl_out_re[j][i] = dbl_out_re[j][i] * det * sign; - - if ( ( ( i + j ) & 1 ) == 0 ) - { - sign = -1; - } - else - { - sign = 1; - } - } - } - } - else - { - assert( !"matrix dimension not supported!" ); - } - - for ( i = 0; i < dim; i++ ) - { - for ( j = 0; j < dim; j++ ) - { - out_re[i][j] = (float) dbl_out_re[i][j]; - } - } - - return; -} - #ifdef IVAS_FLOAT_FIXED static void ivas_calc_mat_inv_fx( @@ -4790,35 +3808,6 @@ static void ivas_calc_mat_inv_fx( * Check if matrix is invertible or not by checking if determinant is 0 or very close to 0 *-----------------------------------------------------------------------------------------*/ -static int16_t ivas_is_mat_inv( - float in_re[MAX_MAT_DIM][MAX_MAT_DIM], - const int16_t dim ) -{ - int16_t is_det_zero = 0; - double det, det_re; - int16_t i, j; - double dbl_in_re[MAX_MAT_DIM][MAX_MAT_DIM]; - - for ( i = 0; i < dim; i++ ) - { - for ( j = 0; j < dim; j++ ) - { - dbl_in_re[i][j] = in_re[i][j]; - } - } - - ivas_calc_mat_det( dbl_in_re, dim, &det_re ); - - det = ( det_re * det_re ); - - if ( det < IVAS_DBL_EPS ) - { - is_det_zero = 1; - } - - return is_det_zero; -} - #ifdef IVAS_FLOAT_FIXED static Word16 ivas_is_mat_inv_fx( @@ -4858,60 +3847,6 @@ static Word16 ivas_is_mat_inv_fx( * *-----------------------------------------------------------------------------------------*/ -void ivas_compute_spar_params( - float *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], - float dm_fv_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], - const int16_t i_ts, - float ***mixer_mat, - const int16_t start_band, - const int16_t end_band, - const int16_t dtx_vad, - const int16_t num_ch, - const int16_t bands_bw, - const int16_t active_w, - const int16_t active_w_vlbr, - ivas_spar_md_com_cfg *hSparCfg, - ivas_spar_md_t *hSparMd, - float *pWscale, - const int16_t from_dirac, - const int16_t dyn_active_w_flag ) -{ - float pred_coeffs_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS]; - int16_t b, i, ndm; - - ivas_get_pred_coeffs( cov_real, pred_coeffs_re, dm_fv_re, num_ch, start_band, end_band, active_w, active_w_vlbr, dtx_vad, from_dirac, dyn_active_w_flag, hSparMd->res_ind ); - - ivas_create_fullr_dmx_mat( pred_coeffs_re, dm_fv_re, mixer_mat, num_ch, start_band, end_band, active_w, hSparCfg ); - - ivas_get_Wscaling_factor( cov_real, pred_coeffs_re, mixer_mat, start_band, end_band, dtx_vad, num_ch, hSparCfg->num_dmx_chans_per_band, bands_bw, active_w, active_w_vlbr, pWscale, dyn_active_w_flag ); - - for ( b = start_band; b < end_band; b++ ) - { - float onebyscale = 1.0f / pWscale[b]; - for ( i = 0; i < num_ch - 1; i++ ) - { - hSparMd->band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].pred_re[i] = pred_coeffs_re[i][b] * onebyscale; - } - - for ( i = 0; i < num_ch; i++ ) - { - mixer_mat[0][i][b] *= pWscale[b]; - } - } - - for ( b = start_band; b < end_band; b++ ) - { - ndm = hSparCfg->num_dmx_chans_per_band[b * bands_bw]; - - if ( ndm != num_ch ) - { - ivas_calc_c_p_coeffs( hSparMd, cov_real, i_ts, mixer_mat, num_ch, ndm, b, dtx_vad, 1, dyn_active_w_flag ); - } - } - - return; -} - #ifdef IVAS_FLOAT_FIXED void ivas_compute_spar_params_enc_fx( @@ -4963,11 +3898,11 @@ void ivas_compute_spar_params_enc_fx( tmp = sub( add( q_pred_coeffs_re, q_tmp ), 15 ); FOR( i = 0; i < sub( num_ch, 1 ); i++ ) { - hSparMd->band_coeffs[add( b, imult1616( i_ts, IVAS_MAX_NUM_BANDS ) )].pred_re_fx[i] = Mpy_32_16_1( pred_coeffs_re_fx[i][b], onebyscale_fx ); + hSparMd->band_coeffs[b + ( i_ts * IVAS_MAX_NUM_BANDS )].pred_re_fx[i] = L_shl( Mpy_32_16_1( pred_coeffs_re_fx[i][b], onebyscale_fx ), sub( Q28, tmp ) ); move32(); } // hSparMd->band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].q_pred_re_fx = sub(add(q_pred_coeffs, q_tmp), 15); - hSparMd->band_coeffs[add( b, imult1616( i_ts, IVAS_MAX_NUM_BANDS ) )].q_pred_re_fx = tmp; + hSparMd->band_coeffs[( b + ( i_ts * IVAS_MAX_NUM_BANDS ) )].q_pred_re_fx = Q28; move16(); FOR( i = 0; i < num_ch; i++ ) @@ -4979,7 +3914,7 @@ void ivas_compute_spar_params_enc_fx( FOR( b = start_band; b < end_band; b++ ) { - ndm = hSparCfg->num_dmx_chans_per_band[imult1616( b, bands_bw )]; + ndm = hSparCfg->num_dmx_chans_per_band[( b * bands_bw )]; move16(); IF( NE_16( ndm, num_ch ) ) @@ -5034,22 +3969,22 @@ void ivas_compute_spar_params_fx( tmp = sub( add( q_pred_coeffs, q_tmp ), 15 ); FOR( i = 0; i < sub( num_ch, 1 ); i++ ) { - hSparMd->band_coeffs[add( b, imult1616( i_ts, IVAS_MAX_NUM_BANDS ) )].pred_re_fx[i] = Mpy_32_16_1( pred_coeffs_re[i][b], onebyscale_fx ); + hSparMd->band_coeffs[b + ( i_ts * IVAS_MAX_NUM_BANDS )].pred_re_fx[i] = Mpy_32_16_1( pred_coeffs_re[i][b], onebyscale_fx ); move32(); IF( tmp < 0 ) { tmp = negate( tmp ); - hSparMd->band_coeffs[add( b, imult1616( i_ts, IVAS_MAX_NUM_BANDS ) )].pred_re_fx[i] = L_shl( hSparMd->band_coeffs[add( b, imult1616( i_ts, IVAS_MAX_NUM_BANDS ) )].pred_re_fx[i], add( tmp, 22 ) ); + hSparMd->band_coeffs[b + ( i_ts * IVAS_MAX_NUM_BANDS )].pred_re_fx[i] = L_shl( hSparMd->band_coeffs[b + ( i_ts * IVAS_MAX_NUM_BANDS )].pred_re_fx[i], add( tmp, 22 ) ); move32(); } ELSE { - hSparMd->band_coeffs[add( b, imult1616( i_ts, IVAS_MAX_NUM_BANDS ) )].pred_re_fx[i] = L_shr( hSparMd->band_coeffs[add( b, imult1616( i_ts, IVAS_MAX_NUM_BANDS ) )].pred_re_fx[i], sub( tmp, 22 ) ); + hSparMd->band_coeffs[b + ( i_ts * IVAS_MAX_NUM_BANDS )].pred_re_fx[i] = L_shr( hSparMd->band_coeffs[b + ( i_ts * IVAS_MAX_NUM_BANDS )].pred_re_fx[i], sub( tmp, 22 ) ); move32(); } } // hSparMd->band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].q_pred_re_fx = sub(add(q_pred_coeffs, q_tmp), 15); - hSparMd->band_coeffs[add( b, imult1616( i_ts, IVAS_MAX_NUM_BANDS ) )].q_pred_re_fx = Q22; + hSparMd->band_coeffs[b + ( i_ts * IVAS_MAX_NUM_BANDS )].q_pred_re_fx = Q22; move16(); FOR( i = 0; i < num_ch; i++ ) @@ -5061,14 +3996,14 @@ void ivas_compute_spar_params_fx( FOR( b = start_band; b < end_band; b++ ) { - ndm = hSparCfg->num_dmx_chans_per_band[imult1616( b, bands_bw )]; + ndm = hSparCfg->num_dmx_chans_per_band[b * bands_bw]; move16(); IF( NE_16( ndm, num_ch ) ) { ivas_calc_c_p_coeffs_fx( hSparMd, cov_real, q_cov_real, i_ts, mixer_mat_fx, *q_mixer_mat, num_ch, ndm, b, dtx_vad, 1, dyn_active_w_flag ); - Word16 q_tmp = hSparMd->band_coeffs[add( b, imult1616( i_ts, IVAS_MAX_NUM_BANDS ) )].q_C_re_fx; + Word16 q_tmp = hSparMd->band_coeffs[b + ( i_ts * IVAS_MAX_NUM_BANDS )].q_C_re_fx; IF( NE_16( ndm, 1 ) ) { #ifdef MSAN_FIX @@ -5076,7 +4011,7 @@ void ivas_compute_spar_params_fx( { FOR( Word16 j = 0; j < sub( ndm, 1 ); j++ ) { - hSparMd->band_coeffs[add( b, imult1616( i_ts, IVAS_MAX_NUM_BANDS ) )].C_re_fx[i][j] = L_shr( hSparMd->band_coeffs[add( b, imult1616( i_ts, IVAS_MAX_NUM_BANDS ) )].C_re_fx[i][j], sub( q_tmp, 22 ) ); + hSparMd->band_coeffs[b + ( i_ts * IVAS_MAX_NUM_BANDS )].C_re_fx[i][j] = L_shr( hSparMd->band_coeffs[b + ( i_ts * IVAS_MAX_NUM_BANDS )].C_re_fx[i][j], sub( q_tmp, 22 ) ); move32(); } } @@ -5089,19 +4024,19 @@ void ivas_compute_spar_params_fx( } } #endif - hSparMd->band_coeffs[add( b, imult1616( i_ts, IVAS_MAX_NUM_BANDS ) )].q_C_re_fx = Q22; + hSparMd->band_coeffs[b + ( i_ts * IVAS_MAX_NUM_BANDS )].q_C_re_fx = Q22; move16(); } - q_tmp = hSparMd->band_coeffs[add( b, imult1616( i_ts, IVAS_MAX_NUM_BANDS ) )].q_P_re_fx; + q_tmp = hSparMd->band_coeffs[b + ( i_ts * IVAS_MAX_NUM_BANDS )].q_P_re_fx; move16(); FOR( Word16 j = 0; j < sub( IVAS_SPAR_MAX_CH, 1 ); j++ ) { - hSparMd->band_coeffs[add( b, imult1616( i_ts, IVAS_MAX_NUM_BANDS ) )].P_re_fx[j] = L_shr( hSparMd->band_coeffs[add( b, imult1616( i_ts, IVAS_MAX_NUM_BANDS ) )].P_re_fx[j], sub( q_tmp, 22 ) ); + hSparMd->band_coeffs[b + ( i_ts * IVAS_MAX_NUM_BANDS )].P_re_fx[j] = L_shr( hSparMd->band_coeffs[b + ( i_ts * IVAS_MAX_NUM_BANDS )].P_re_fx[j], sub( q_tmp, 22 ) ); move32(); } - hSparMd->band_coeffs[add( b, imult1616( i_ts, IVAS_MAX_NUM_BANDS ) )].q_P_re_fx = Q22; + hSparMd->band_coeffs[b + imult1616( i_ts, IVAS_MAX_NUM_BANDS )].q_P_re_fx = Q22; move16(); } } @@ -5206,13 +4141,13 @@ void ivas_get_spar_md_from_dirac_fx( Word32 P_norm_fx[3]; Word16 idx; - ndm = hSpar_md_cfg->num_dmx_chans_per_band[sub( start_band, 1 )]; + ndm = hSpar_md_cfg->num_dmx_chans_per_band[start_band - 1]; move16(); P_norm_fx[0] = 0; move32(); FOR( i = 0; i < max( 0, sub( foa_ch, ndm ) ); i++ ) { - P_norm_fx[0] = L_add( P_norm_fx[0], Mpy_32_32( hSpar_md->band_coeffs[sub( start_band, 1 )].P_re_fx[i], hSpar_md->band_coeffs[sub( start_band, 1 )].P_re_fx[i] ) ); + P_norm_fx[0] = L_add( P_norm_fx[0], Mpy_32_32( hSpar_md->band_coeffs[start_band - 1].P_re_fx[i], hSpar_md->band_coeffs[start_band - 1].P_re_fx[i] ) ); move32(); } P_norm_fx[0] = Mpy_32_32( L_shl( P_norm_fx[0], 3 ), diff_norm_order1_table[min( diff_norm_order1_fx, max( 0, sub( foa_ch, ndm ) ) )] ); @@ -5222,7 +4157,7 @@ void ivas_get_spar_md_from_dirac_fx( move32(); FOR( ; i < max( 0, sub( min( num_ch, hoa2_ch ), ndm ) ); i++ ) { - P_norm_fx[1] = L_add( P_norm_fx[1], Mpy_32_32( hSpar_md->band_coeffs[sub( start_band, 1 )].P_re_fx[i], hSpar_md->band_coeffs[sub( start_band, 1 )].P_re_fx[i] ) ); + P_norm_fx[1] = L_add( P_norm_fx[1], Mpy_32_32( hSpar_md->band_coeffs[start_band - 1].P_re_fx[i], hSpar_md->band_coeffs[start_band - 1].P_re_fx[i] ) ); move32(); } P_norm_fx[1] = Mpy_32_32( L_shl( P_norm_fx[1], 3 ), diff_norm_order2_table[min( diff_norm_order2_fx, max( 0, sub( min( num_ch, hoa2_ch ), ndm ) ) )] ); @@ -5232,7 +4167,7 @@ void ivas_get_spar_md_from_dirac_fx( move32(); FOR( ; i < sub( num_ch, ndm ); i++ ) { - P_norm_fx[2] = L_add( P_norm_fx[2], Mpy_32_32( hSpar_md->band_coeffs[sub( start_band, 1 )].P_re_fx[i], hSpar_md->band_coeffs[sub( start_band, 1 )].P_re_fx[i] ) ); + P_norm_fx[2] = L_add( P_norm_fx[2], Mpy_32_32( hSpar_md->band_coeffs[start_band - 1].P_re_fx[i], hSpar_md->band_coeffs[start_band - 1].P_re_fx[i] ) ); move32(); } P_norm_fx[2] = Mpy_32_32( L_shl( P_norm_fx[2], 3 ), diff_norm_order3_table[min( diff_norm_order3_fx, max( 0, sub( num_ch, ndm ) ) )] ); @@ -5240,8 +4175,8 @@ void ivas_get_spar_md_from_dirac_fx( FOR( i = 0; i < max( 0, sub( foa_ch, ndm ) ); i++ ) { - idx = sub( remix_order[add( i, ndm )], ndm ); - P_dir_fact_fx[idx] = Mpy_32_32( hSpar_md->band_coeffs[sub( start_band, 1 )].P_re_fx[i], hSpar_md->band_coeffs[sub( start_band, 1 )].P_re_fx[i] ); + idx = sub( remix_order[i + ndm], ndm ); + P_dir_fact_fx[idx] = Mpy_32_32( hSpar_md->band_coeffs[start_band - 1].P_re_fx[i], hSpar_md->band_coeffs[start_band - 1].P_re_fx[i] ); move32(); IF( P_dir_fact_fx[idx] == 0 ) { @@ -5258,8 +4193,8 @@ void ivas_get_spar_md_from_dirac_fx( } FOR( ; i < max( 0, sub( min( num_ch, hoa2_ch ), ndm ) ); i++ ) { - idx = sub( remix_order[add( i, ndm )], ndm ); - P_dir_fact_fx[idx] = Mpy_32_32( hSpar_md->band_coeffs[sub( start_band, 1 )].P_re_fx[i], hSpar_md->band_coeffs[sub( start_band, 1 )].P_re_fx[i] ); + idx = sub( remix_order[i + ndm], ndm ); + P_dir_fact_fx[idx] = Mpy_32_32( hSpar_md->band_coeffs[start_band - 1].P_re_fx[i], hSpar_md->band_coeffs[start_band - 1].P_re_fx[i] ); IF( P_dir_fact_fx[idx] == 0 ) { P_dir_fact_fx[idx] = 0; @@ -5275,8 +4210,8 @@ void ivas_get_spar_md_from_dirac_fx( } FOR( ; i < sub( num_ch, ndm ); i++ ) { - idx = sub( remix_order[add( i, ndm )], ndm ); - P_dir_fact_fx[idx] = Mpy_32_32( hSpar_md->band_coeffs[sub( start_band, 1 )].P_re_fx[i], hSpar_md->band_coeffs[sub( start_band, 1 )].P_re_fx[i] ); + idx = sub( remix_order[i + ndm], ndm ); + P_dir_fact_fx[idx] = Mpy_32_32( hSpar_md->band_coeffs[start_band - 1].P_re_fx[i], hSpar_md->band_coeffs[start_band - 1].P_re_fx[i] ); move32(); IF( P_dir_fact_fx[idx] == 0 ) { @@ -5574,7 +4509,7 @@ void ivas_get_spar_md_from_dirac_fx( IF( ( GE_16( i, ndm ) ) && ( EQ_16( dtx_vad, 1 ) ) ) { en_ratio_fac_sq = Mpy_32_32( en_ratio_fac_fx, en_ratio_fac_fx ); - cov_real_dirac_fx[i][j][band] = L_add( cov_real_dirac_fx[i][j][band], Mpy_32_32( L_sub( ONE_IN_Q31, en_ratio_fac_sq ), P_dir_fact_fx[sub( i, ndm )] ) ); + cov_real_dirac_fx[i][j][band] = L_add( cov_real_dirac_fx[i][j][band], Mpy_32_32( L_sub( ONE_IN_Q31, en_ratio_fac_sq ), P_dir_fact_fx[i - ndm] ) ); move32(); } ELSE @@ -5660,7 +4595,7 @@ void ivas_get_spar_md_from_dirac_fx( { FOR( j = 0; j < num_ch; j++ ) { - mixer_mat_fx[i][j][add( band, imult1616( i_ts, IVAS_MAX_NUM_BANDS ) )] = L_shl( ppMixer_mat_fx[i][j][band], sub( *q_mixer_mat_fx, q_ppMixer_mat ) ); + mixer_mat_fx[i][j][band + ( i_ts * IVAS_MAX_NUM_BANDS )] = L_shl( ppMixer_mat_fx[i][j][band], sub( *q_mixer_mat_fx, q_ppMixer_mat ) ); move32(); } } @@ -5669,7 +4604,7 @@ void ivas_get_spar_md_from_dirac_fx( { FOR( j = 0; j < num_ch; j++ ) { - mixer_mat_fx[i][j][add( band, imult1616( i_ts, IVAS_MAX_NUM_BANDS ) )] = 0; + mixer_mat_fx[i][j][band + ( i_ts * IVAS_MAX_NUM_BANDS )] = 0; move32(); } } @@ -5679,7 +4614,7 @@ void ivas_get_spar_md_from_dirac_fx( { FOR( j = 0; j < num_ch; j++ ) { - mixer_mat_fx[0][j][add( band, imult1616( i_ts, IVAS_MAX_NUM_BANDS ) )] = Mpy_32_32( L_shl( mixer_mat_fx[0][j][add( band, imult1616( i_ts, IVAS_MAX_NUM_BANDS ) )], 2 ), Wscale_d[band] ); + mixer_mat_fx[0][j][band + ( i_ts * IVAS_MAX_NUM_BANDS )] = Mpy_32_32( L_shl( mixer_mat_fx[0][j][band + ( i_ts * IVAS_MAX_NUM_BANDS )], 2 ), Wscale_d[band] ); move32(); } } @@ -5690,312 +4625,6 @@ void ivas_get_spar_md_from_dirac_fx( return; } #endif -/*-----------------------------------------------------------------------------------------* - * Function ivas_get_spar_md_from_dirac() - * - * - *-----------------------------------------------------------------------------------------*/ - -void ivas_get_spar_md_from_dirac( - float azi_dirac[IVAS_MAX_NUM_BANDS][MAX_PARAM_SPATIAL_SUBFRAMES], - float ele_dirac[IVAS_MAX_NUM_BANDS][MAX_PARAM_SPATIAL_SUBFRAMES], - float diffuseness[IVAS_MAX_NUM_BANDS], - const int16_t n_ts, - float ***mixer_mat, - ivas_spar_md_t *hSpar_md, - ivas_spar_md_com_cfg *hSpar_md_cfg, - const int16_t start_band, - const int16_t end_band, - const int16_t order, - const int16_t dtx_vad, - float Wscale_d[IVAS_MAX_NUM_BANDS], - const uint8_t useLowerRes, - const int16_t active_w_vlbr, - const int16_t dyn_active_w_flag ) -{ - int16_t num_ch, band, i, j; - int16_t block, ch; - float response_avg[MAX_OUTPUT_CHANNELS]; - float response[MAX_PARAM_SPATIAL_SUBFRAMES][MAX_OUTPUT_CHANNELS]; - float cov_real_dirac[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH][IVAS_MAX_NUM_BANDS]; - float *pCov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH]; - float dm_fv_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS]; - float Wscale[IVAS_MAX_NUM_BANDS]; - float mixer_mat_local[IVAS_MAX_FB_MIXER_OUT_CH][IVAS_MAX_SPAR_FB_MIXER_IN_CH][IVAS_MAX_NUM_BANDS]; - float **ppMixer_mat[IVAS_MAX_FB_MIXER_OUT_CH]; - float *pMixer_mat[IVAS_MAX_FB_MIXER_OUT_CH][IVAS_MAX_SPAR_FB_MIXER_IN_CH]; - float en_ratio_fac, diff_norm_order1, diff_norm_order2, diff_norm_order3; - int16_t active_w; - - int16_t ndm, foa_ch, hoa2_ch; - float P_dir_fact[IVAS_SPAR_MAX_CH - 1]; - const int16_t *remix_order; - - remix_order = remix_order_set[hSpar_md_cfg->remix_unmix_order]; - - num_ch = ivas_sba_get_nchan_metadata( order, IVAS_256k /*dummy value as order is always 1 in this function*/ ); - - hoa2_ch = ivas_sba_get_nchan_metadata( SBA_HOA2_ORDER, IVAS_256k /*dummy value as order is always 1 in this function*/ ); - - foa_ch = FOA_CHANNELS; - diff_norm_order1 = 3.0f; - diff_norm_order2 = 5.0f; - diff_norm_order3 = 7.0f; - - for ( i = 0; i < IVAS_MAX_FB_MIXER_OUT_CH; i++ ) - { - for ( j = 0; j < IVAS_MAX_SPAR_FB_MIXER_IN_CH; j++ ) - { - pMixer_mat[i][j] = mixer_mat_local[i][j]; - } - ppMixer_mat[i] = pMixer_mat[i]; - } - - if ( ( start_band >= 6 && hSpar_md_cfg->nchan_transport <= 2 && ( dtx_vad == 1 ) ) || ( useLowerRes && start_band >= 3 && hSpar_md_cfg->nchan_transport <= 2 && ( dtx_vad == 1 ) ) ) - { - float P_norm[3]; - int16_t idx; - - ndm = hSpar_md_cfg->num_dmx_chans_per_band[start_band - 1]; - P_norm[0] = 0.0f; - for ( i = 0; i < max( 0, foa_ch - ndm ); i++ ) - { - P_norm[0] += hSpar_md->band_coeffs[start_band - 1].P_re[i] * hSpar_md->band_coeffs[start_band - 1].P_re[i]; - } - P_norm[0] *= diff_norm_order1 / min( diff_norm_order1, max( 0, foa_ch - ndm ) ); - - P_norm[1] = 0.0f; - for ( ; i < max( 0, min( num_ch, hoa2_ch ) - ndm ); i++ ) - { - P_norm[1] += hSpar_md->band_coeffs[start_band - 1].P_re[i] * hSpar_md->band_coeffs[start_band - 1].P_re[i]; - } - P_norm[1] *= diff_norm_order2 / min( diff_norm_order2, max( 0, min( num_ch, hoa2_ch ) - ndm ) ); - - P_norm[2] = 0.0f; - for ( ; i < num_ch - ndm; i++ ) - { - P_norm[2] += hSpar_md->band_coeffs[start_band - 1].P_re[i] * hSpar_md->band_coeffs[start_band - 1].P_re[i]; - } - P_norm[2] *= diff_norm_order3 / min( diff_norm_order3, max( 0, num_ch - ndm ) ); - - for ( i = 0; i < max( 0, foa_ch - ndm ); i++ ) - { - idx = remix_order[i + ndm] - ndm; - P_dir_fact[idx] = hSpar_md->band_coeffs[start_band - 1].P_re[i] * hSpar_md->band_coeffs[start_band - 1].P_re[i]; - P_dir_fact[idx] = P_dir_fact[idx] / max( IVAS_FLT_EPS, P_norm[0] ); - } - for ( ; i < max( 0, min( num_ch, hoa2_ch ) - ndm ); i++ ) - { - idx = remix_order[i + ndm] - ndm; - P_dir_fact[idx] = hSpar_md->band_coeffs[start_band - 1].P_re[i] * hSpar_md->band_coeffs[start_band - 1].P_re[i]; - P_dir_fact[idx] = P_dir_fact[idx] / max( IVAS_FLT_EPS, P_norm[1] ); - } - for ( ; i < num_ch - ndm; i++ ) - { - idx = remix_order[i + ndm] - ndm; - P_dir_fact[idx] = hSpar_md->band_coeffs[start_band - 1].P_re[i] * hSpar_md->band_coeffs[start_band - 1].P_re[i]; - P_dir_fact[idx] = P_dir_fact[idx] / max( IVAS_FLT_EPS, P_norm[2] ); - } - } - - for ( int16_t i_ts = 0; i_ts < n_ts; i_ts++ ) - { - for ( band = start_band; band < end_band; band++ ) - { - ndm = hSpar_md_cfg->num_dmx_chans_per_band[band]; - - /*SPAR from DirAC*/ - set_f( response_avg, 0.0f, MAX_OUTPUT_CHANNELS ); - - if ( n_ts > 1 ) - { - ivas_dirac_dec_get_response( (int16_t) azi_dirac[band][i_ts], (int16_t) ele_dirac[band][i_ts], response_avg, order ); - } - else if ( useLowerRes ) - { - ivas_dirac_dec_get_response( (int16_t) azi_dirac[band][0], (int16_t) ele_dirac[band][0], response_avg, order ); - } - else - { - for ( block = 0; block < MAX_PARAM_SPATIAL_SUBFRAMES; block++ ) - { - ivas_dirac_dec_get_response( (int16_t) azi_dirac[band][block], (int16_t) ele_dirac[band][block], &( response[block][0] ), order ); - } - - /* average responses in all subframes*/ - { - float norm; - int16_t num_ch_order, hoa2_ch_order; - - num_ch_order = ivas_sba_get_nchan( order, 0 ); - hoa2_ch_order = ivas_sba_get_nchan( SBA_HOA2_ORDER, 0 ); - - for ( ch = 0; ch < num_ch_order; ch++ ) - { - for ( block = 0; block < MAX_PARAM_SPATIAL_SUBFRAMES; block++ ) - { - response_avg[ch] += response[block][ch]; - } - response_avg[ch] /= MAX_PARAM_SPATIAL_SUBFRAMES; - } - - /*normalize 1st order*/ - norm = 0.0f; - for ( ch = 1; ch < foa_ch; ch++ ) - { - norm += response_avg[ch] * response_avg[ch]; - } - norm = max( EPSILON, sqrtf( norm ) ); - for ( ch = 1; ch < foa_ch; ch++ ) - { - response_avg[ch] /= norm; - } - - /*normalize 2nd order*/ - norm = 0.0f; - for ( ch = foa_ch; ch < min( hoa2_ch_order, num_ch_order ); ch++ ) - { - norm += response_avg[ch] * response_avg[ch]; - } - norm = max( EPSILON, sqrtf( norm ) ); - for ( ch = foa_ch; ch < min( hoa2_ch_order, num_ch_order ); ch++ ) - { - response_avg[ch] /= norm; - } - - /*normalize 3rd order*/ - norm = 0.0f; - for ( ch = hoa2_ch_order; ch < num_ch_order; ch++ ) - { - norm += response_avg[ch] * response_avg[ch]; - } - norm = max( EPSILON, sqrtf( norm ) ); - for ( ch = hoa2_ch_order; ch < num_ch_order; ch++ ) - { - response_avg[ch] /= norm; - } - } - } - - for ( i = FOA_CHANNELS + 1; i < num_ch; i++ ) - { - response_avg[i] = response_avg[HOA_keep_ind[i]]; - } - - en_ratio_fac = ( 1.0f - diffuseness[band] ); - - for ( i = 0; i < num_ch; i++ ) - { - for ( j = 0; j < num_ch; j++ ) - { - if ( i == j ) - { - if ( i == 0 ) - { - cov_real_dirac[i][i][band] = 1.0f; - } - else - { - cov_real_dirac[i][j][band] = en_ratio_fac * response_avg[i] * response_avg[j]; - - if ( hSpar_md_cfg->nchan_transport <= 2 ) - { - - cov_real_dirac[i][j][band] *= en_ratio_fac; - if ( ( i >= ndm ) && ( dtx_vad == 1 ) ) - { - cov_real_dirac[i][j][band] += ( 1.0f - ( en_ratio_fac * en_ratio_fac ) ) * P_dir_fact[i - ndm]; - } - else - { - if ( i < foa_ch ) - { - cov_real_dirac[i][j][band] += ( 1.0f - ( en_ratio_fac * en_ratio_fac ) ) / diff_norm_order1; - } - else if ( i < hoa2_ch ) - { - cov_real_dirac[i][j][band] += ( 1.0f - ( en_ratio_fac * en_ratio_fac ) ) / diff_norm_order2; - } - else - { - cov_real_dirac[i][j][band] += ( 1.0f - ( en_ratio_fac * en_ratio_fac ) ) / diff_norm_order3; - } - } - } - else - { - if ( i < foa_ch ) - { - cov_real_dirac[i][j][band] += ( 1.0f - en_ratio_fac ) / diff_norm_order1; - } - else if ( i < hoa2_ch ) - { - cov_real_dirac[i][j][band] += ( 1.0f - en_ratio_fac ) / diff_norm_order2; - } - else - { - cov_real_dirac[i][j][band] += ( 1.0f - en_ratio_fac ) / diff_norm_order3; - } - } - } - } - else - { - cov_real_dirac[i][j][band] = en_ratio_fac * response_avg[i] * response_avg[j]; - } - } - } - } - - for ( i = 0; i < num_ch; i++ ) - { - for ( j = 0; j < num_ch; j++ ) - { - pCov_real[i][j] = cov_real_dirac[i][j]; - } - } - - - active_w = ( dyn_active_w_flag == 1 ) || ( hSpar_md_cfg->active_w == 1 ); - - ivas_compute_spar_params( pCov_real, dm_fv_re, i_ts, ppMixer_mat, start_band, end_band, dtx_vad, num_ch, 1, active_w, active_w_vlbr, hSpar_md_cfg, hSpar_md, Wscale, 1, dyn_active_w_flag ); - - if ( mixer_mat != NULL ) - { - for ( band = start_band; band < end_band; band++ ) - { - ndm = hSpar_md_cfg->num_dmx_chans_per_band[band]; - - for ( i = 0; i < ndm; i++ ) - { - for ( j = 0; j < num_ch; j++ ) - { - mixer_mat[i][j][band + i_ts * IVAS_MAX_NUM_BANDS] = ppMixer_mat[i][j][band]; - } - } - - for ( i = ndm; i < num_ch; i++ ) - { - for ( j = 0; j < num_ch; j++ ) - { - mixer_mat[i][j][band + i_ts * IVAS_MAX_NUM_BANDS] = 0.0f; - } - } - - if ( ( ndm == 1 ) && ( Wscale_d != NULL ) ) - { - for ( j = 0; j < num_ch; j++ ) - { - mixer_mat[0][j][band + i_ts * IVAS_MAX_NUM_BANDS] *= Wscale_d[band]; - } - } - } - } - } - - return; -} - /*------------------------------------------------------------------------- * ivas_dirac_dec_get_response() * @@ -8228,11 +6857,11 @@ void ivas_dirac_dec_get_response_fx( move16(); c_fx_better = local_result_table[el][a]; move32(); - response_fx[b] = L_shl_sat( Mpy_32_32( c_fx_better, sin_az_fx[sub( sub( l, m ), 1 )] ), sub( Q_out, 30 ) ); // Q_out + response_fx[b] = L_shl_sat( Mpy_32_32( c_fx_better, sin_az_fx[l - m - 1] ), sub( Q_out, 30 ) ); // Q_out move32(); b1 = sub( b1_2, m ); - response_fx[b1] = L_shl_sat( Mpy_32_32( c_fx_better, cos_az_fx[sub( sub( l, m ), 1 )] ), sub( Q_out, 30 ) ); // Q_out + response_fx[b1] = L_shl_sat( Mpy_32_32( c_fx_better, cos_az_fx[l - m - 1] ), sub( Q_out, 30 ) ); // Q_out move32(); } @@ -8247,10 +6876,10 @@ void ivas_dirac_dec_get_response_fx( { c_fx_better = L_negate( c_fx_better ); } - response_fx[b] = L_shl_sat( Mpy_32_32( c_fx_better, sin_az_fx[sub( sub( l, m ), 1 )] ), sub( Q_out, 30 ) ); // Q_out + response_fx[b] = L_shl_sat( Mpy_32_32( c_fx_better, sin_az_fx[l - m - 1] ), sub( Q_out, 30 ) ); // Q_out move32(); b1 = sub( b1_2, m ); - response_fx[b1] = L_shl_sat( Mpy_32_32( c_fx_better, cos_az_fx[sub( sub( l, m ), 1 )] ), sub( Q_out, 30 ) ); // Q_out + response_fx[b1] = L_shl_sat( Mpy_32_32( c_fx_better, cos_az_fx[l - m - 1] ), sub( Q_out, 30 ) ); // Q_out move32(); } @@ -8810,9 +7439,9 @@ void ivas_spar_bitrate_dist_fx( FOR( i = 0; i < nchan_transport; i++ ) { - core_bits_act[sub( sub( nchan_transport, 1 ), i )] = sub( core_bits_act[sub( sub( nchan_transport, 1 ), i )], min( overflow_bits, core_range_bits[sub( sub( nchan_transport, 1 ), i )] ) ); + core_bits_act[nchan_transport - 1 - i] = sub( core_bits_act[nchan_transport - 1 - i], min( overflow_bits, core_range_bits[nchan_transport - 1 - i] ) ); move16(); - overflow_bits = sub( overflow_bits, core_range_bits[sub( sub( nchan_transport, 1 ), i )] ); + overflow_bits = sub( overflow_bits, core_range_bits[nchan_transport - 1 - i] ); IF( overflow_bits <= 0 ) { @@ -8832,7 +7461,7 @@ void ivas_spar_bitrate_dist_fx( overflow_bits = sub( overflow_bits, overflow_bits_ch ); } - core_bits_act[sub( nchan_transport, 1 )] = sub( core_bits_act[sub( nchan_transport, 1 )], max( 0, overflow_bits ) ); + core_bits_act[nchan_transport - 1] = sub( core_bits_act[nchan_transport - 1], max( 0, overflow_bits ) ); move16(); } } diff --git a/lib_com/ivas_spar_com_quant_util.c b/lib_com/ivas_spar_com_quant_util.c index d26cd9bb8..3c7b4e620 100644 --- a/lib_com/ivas_spar_com_quant_util.c +++ b/lib_com/ivas_spar_com_quant_util.c @@ -90,6 +90,75 @@ void ivas_quantise_real_values( return; } +void ivas_quantise_real_values_enc_fx_varq( + const Word32 *values_fx, + const Word16 q_levels, + const Word32 min_value_fx, + const Word32 max_value_fx, + Word16 *index, + Word32 *quant_fx, + const Word16 dim, + Word16 inp_q ) +{ + Word16 i; + Word32 q_step_fx, one_by_q_step_fx; + test(); + IF( EQ_16( q_levels, 1 ) ) + { + FOR( i = 0; i < dim; i++ ) + { + quant_fx[i] = 0; + move32(); + index[i] = 0; + move16(); + } + } + ELSE IF( q_levels && NE_32( max_value_fx, min_value_fx ) ) + { + Word16 nor_q_level = norm_l( sub( q_levels, 1 ) ); + Word32 one_by_q_levels = divide3232( L_shl( 1, ( nor_q_level ) ), L_shl( sub( q_levels, 1 ), ( nor_q_level ) ) ); // Q15 + one_by_q_levels = L_shl( one_by_q_levels, 16 ); // Q31 + q_step_fx = Mpy_32_32( L_sub( max_value_fx, min_value_fx ), one_by_q_levels ); // Q28 + Word16 exp; + Word16 one_by_max_min = BASOP_Util_Divide3232_Scale( ONE_IN_Q28, L_sub( max_value_fx, min_value_fx ), &exp ); // Q(15-exp) + one_by_q_step_fx = L_mult0( sub( q_levels, 1 ), one_by_max_min ); // Q(15-exp) + Word32 val_fx; + IF( LT_16( inp_q, Q28 ) ) + { + FOR( i = 0; i < dim; i++ ) + { + val_fx = L_max( L_shr( min_value_fx, sub( Q28, inp_q ) ), L_min( values_fx[i], L_shr( max_value_fx, sub( Q28, inp_q ) ) ) ); // Q(inp_q) + val_fx = L_shl( val_fx, sub( Q28, inp_q ) ); // Q28 + index[i] = round_fx( L_shl( Mpy_32_32( one_by_q_step_fx, val_fx ), add( Q4, exp ) ) ); // Q0 + move16(); + quant_fx[i] = imult3216( q_step_fx, index[i] ); // Q28 + move32(); + } + } + ELSE + { + FOR( i = 0; i < dim; i++ ) + { + val_fx = L_max( min_value_fx, L_min( L_shr( values_fx[i], sub( inp_q, Q28 ) ), max_value_fx ) ); // Q28 + index[i] = round_fx( L_shl( Mpy_32_32( one_by_q_step_fx, val_fx ), add( Q4, exp ) ) ); // Q0 + move16(); + quant_fx[i] = imult3216( q_step_fx, index[i] ); // Q28 + move32(); + } + } + } + ELSE + { + FOR( i = 0; i < dim; i++ ) + { + quant_fx[i] = values_fx[i]; + move32(); + } + } + return; +} + + #ifdef IVAS_FLOAT_FIXED void ivas_quantise_real_values_fx( const Word32 *values_fx, @@ -640,24 +709,6 @@ void ivas_copy_band_coeffs_idx_to_arr( * * clear band coeffs array in SPAR MD *-----------------------------------------------------------------------------------------*/ -void ivas_clear_band_coeffs( - ivas_band_coeffs_t *pband_coeffs, - const uint16_t num_bands ) -{ - uint16_t i; - - for ( i = 0; i < num_bands; i++ ) - { - set_zero( (float *) pband_coeffs[i].C_re, ( IVAS_SPAR_MAX_CH - IVAS_SPAR_MAX_DMX_CHS ) * ( IVAS_SPAR_MAX_DMX_CHS - 1 ) ); - set_zero( (float *) pband_coeffs[i].P_re, ( IVAS_SPAR_MAX_CH - 1 ) ); - set_zero( (float *) pband_coeffs[i].C_quant_re, ( IVAS_SPAR_MAX_CH - IVAS_SPAR_MAX_DMX_CHS ) * ( IVAS_SPAR_MAX_DMX_CHS - 1 ) ); - set_zero( (float *) pband_coeffs[i].P_quant_re, ( IVAS_SPAR_MAX_CH - 1 ) ); - set_zero( pband_coeffs[i].pred_re, ( IVAS_SPAR_MAX_CH - 1 ) ); - set_zero( pband_coeffs[i].pred_quant_re, ( IVAS_SPAR_MAX_CH - 1 ) ); - } - - return; -} #ifdef IVAS_FLOAT_FIXED void ivas_clear_band_coeffs_fx( diff --git a/lib_com/ivas_stat_com.h b/lib_com/ivas_stat_com.h index 4fde550bd..bfe312557 100644 --- a/lib_com/ivas_stat_com.h +++ b/lib_com/ivas_stat_com.h @@ -191,22 +191,15 @@ typedef struct ivas_dirac_config_data_struct /* SPAR MD structures */ typedef struct ivas_band_coeffs_t { - float pred_re[IVAS_SPAR_MAX_CH - 1]; // 22 - float C_re[IVAS_SPAR_MAX_CH - IVAS_SPAR_MAX_DMX_CHS][IVAS_SPAR_MAX_DMX_CHS - 1]; // 22 - float P_re[IVAS_SPAR_MAX_CH - 1]; // 22 - float pred_quant_re[IVAS_SPAR_MAX_CH - 1]; - float C_quant_re[IVAS_SPAR_MAX_CH - IVAS_SPAR_MAX_DMX_CHS][IVAS_SPAR_MAX_DMX_CHS - 1]; - float P_quant_re[IVAS_SPAR_MAX_CH - 1]; - Word16 q_pred_re_fx; - Word32 pred_re_fx[IVAS_SPAR_MAX_CH - 1]; // Q28 + Word32 pred_re_fx[IVAS_SPAR_MAX_CH - 1]; // Q22 for dec Word16 q_C_re_fx; - Word32 C_re_fx[IVAS_SPAR_MAX_CH - IVAS_SPAR_MAX_DMX_CHS][IVAS_SPAR_MAX_DMX_CHS - 1]; + Word32 C_re_fx[IVAS_SPAR_MAX_CH - IVAS_SPAR_MAX_DMX_CHS][IVAS_SPAR_MAX_DMX_CHS - 1]; // Q22 for dec Word16 q_P_re_fx; - Word32 P_re_fx[IVAS_SPAR_MAX_CH - 1]; // Q28 - Word32 pred_quant_re_fx[IVAS_SPAR_MAX_CH - 1]; // Q28 + Word32 P_re_fx[IVAS_SPAR_MAX_CH - 1]; // Q22 for dec + Word32 pred_quant_re_fx[IVAS_SPAR_MAX_CH - 1]; Word32 C_quant_re_fx[IVAS_SPAR_MAX_CH - IVAS_SPAR_MAX_DMX_CHS][IVAS_SPAR_MAX_DMX_CHS - 1]; - Word32 P_quant_re_fx[IVAS_SPAR_MAX_CH - 1]; // Q28 + Word32 P_quant_re_fx[IVAS_SPAR_MAX_CH - 1]; } ivas_band_coeffs_t; typedef struct ivas_band_coeffs_ind_t @@ -547,9 +540,10 @@ typedef struct ivas_qdirection_band_data_struct int16_t elevation_m_alphabet[MAX_PARAM_SPATIAL_SUBFRAMES]; int16_t azimuth_m_alphabet[MAX_PARAM_SPATIAL_SUBFRAMES]; - float energy_ratio[MAX_PARAM_SPATIAL_SUBFRAMES]; #ifdef IVAS_FLOAT_FIXED Word32 energy_ratio_fx[MAX_PARAM_SPATIAL_SUBFRAMES]; /* Q30 */ +#else + float energy_ratio[MAX_PARAM_SPATIAL_SUBFRAMES]; #endif uint8_t distance[MAX_PARAM_SPATIAL_SUBFRAMES]; @@ -562,8 +556,8 @@ typedef struct ivas_qdirection_band_data_struct float q_azimuth[MAX_PARAM_SPATIAL_SUBFRAMES]; float q_elevation[MAX_PARAM_SPATIAL_SUBFRAMES]; #else - Word32 q_azimuth_fx[MAX_PARAM_SPATIAL_SUBFRAMES]; /* Q22 */ - Word32 q_elevation_fx[MAX_PARAM_SPATIAL_SUBFRAMES]; /* Q22 */ + Word32 q_azimuth_fx[MAX_PARAM_SPATIAL_SUBFRAMES]; /* Q22 */ + Word32 q_elevation_fx[MAX_PARAM_SPATIAL_SUBFRAMES]; /* Q22 */ #endif } IVAS_QDIRECTION_BAND_DATA; @@ -619,7 +613,7 @@ typedef struct ivas_masa_qmetadata_frame_struct #ifndef IVAS_FLOAT_FIXED float dir_comp_ratio; #else - Word16 dir_comp_ratio_fx; /* Q15 */ + Word16 dir_comp_ratio_fx; /* Q15 */ #endif uint8_t is_masa_ivas_format; diff --git a/lib_dec/gain_dec_fx.c b/lib_dec/gain_dec_fx.c index 61ef5f11a..e118b787d 100644 --- a/lib_dec/gain_dec_fx.c +++ b/lib_dec/gain_dec_fx.c @@ -43,25 +43,25 @@ void Es_pred_dec_fx( SWITCH( nb_bits ) { case 5: - *Es_pred = Es_pred_qua_5b_fx[enr_idx]; + *Es_pred = Es_pred_qua_5b_fx[enr_idx]; /*Q8*/ move16(); BREAK; case 4: - *Es_pred = Es_pred_qua_4b_fx[enr_idx]; + *Es_pred = Es_pred_qua_4b_fx[enr_idx]; /*Q8*/ move16(); BREAK; case 3: - *Es_pred = Es_pred_qua_3b_fx[enr_idx]; + *Es_pred = Es_pred_qua_3b_fx[enr_idx]; /*Q8*/ break; default: - *Es_pred = Es_pred_qua_5b_fx[enr_idx]; + *Es_pred = Es_pred_qua_5b_fx[enr_idx]; /*Q8*/ move16(); BREAK; } } ELSE { - *Es_pred = Es_pred_qua_4b_no_ltp_fx[enr_idx]; + *Es_pred = Es_pred_qua_4b_no_ltp_fx[enr_idx]; /*Q8*/ move16(); } } @@ -116,7 +116,7 @@ void gain_dec_tc_fx( /*----------------------------------------------------------------* * find number of bits for gain dequantization *----------------------------------------------------------------*/ - nBits = st_fx->acelp_cfg.gains_mode[shr( i_subfr_fx, 6 )]; + nBits = st_fx->acelp_cfg.gains_mode[( i_subfr_fx / 64 )]; move16(); /*-----------------------------------------------------------------* * calculate the predicted gain code @@ -124,13 +124,13 @@ void gain_dec_tc_fx( /*Ecode = (dotp( code, code, L_SUBFR) + 0.01f) / L_SUBFR; *gain_inov = 1.0f / (float)sqrt( Ecode );*/ - L_tmp = Dot_product12( code_fx, code_fx, L_SUBFR, &expg ); - expg = sub( expg, 18 + 6 ); /* exp: -18 (code in Q9), -6 (/L_SUBFR) */ + L_tmp = Dot_product12( code_fx, code_fx, L_SUBFR, &expg ); /*Q31 - expg*/ + expg = sub( expg, 18 + 6 ); /* exp: -18 (code in Q9), -6 (/L_SUBFR) */ expg2 = expg; move16(); L_tmp1 = L_tmp; /* sets to 'L_tmp' in 1 clock */ move32(); - L_tmp = Isqrt_lc( L_tmp, &expg ); + L_tmp = Isqrt_lc( L_tmp, &expg ); /*Q31 - expg*/ *gain_inov_fx = extract_h( L_shl( L_tmp, sub( expg, 3 ) ) ); move16(); /* gain_inov in Q12 */ @@ -138,7 +138,7 @@ void gain_dec_tc_fx( /* Ei = 10 * (float)log10( Ecode );*/ e_tmp = norm_l( L_tmp1 ); - f_tmp = Log2_norm_lc( L_shl( L_tmp1, e_tmp ) ); + f_tmp = Log2_norm_lc( L_shl( L_tmp1, e_tmp ) ); /*Q15*/ e_tmp = sub( expg2, add( 1, e_tmp ) ); L_tmp1 = Mpy_32_16( e_tmp, f_tmp, 12330 ); /* Q13 */ /* 10*log10(2) in Q12*/ Ei_fx = round_fx( L_shl( L_tmp1, 11 ) ); /* Q8 */ @@ -177,7 +177,7 @@ void gain_dec_tc_fx( } ELSE /* nBits == 3 */ { - wgain_code = tbl_gain_code_tc_fx[index]; + wgain_code = tbl_gain_code_tc_fx[index]; /*Q13*/ move16(); } @@ -188,18 +188,18 @@ void gain_dec_tc_fx( /* *gain_code *= gcode0;*/ L_tmp = L_mult( wgain_code, gcode0_fx ); /* Q13*Q0 -> Q14 */ #ifdef BASOP_NOGLOB - *gain_code_fx = L_shl_sat( L_tmp, add( exp_gcode0, 2 ) ); + *gain_code_fx = L_shl_sat( L_tmp, add( exp_gcode0, 2 ) ); /*Q16*/ #else *gain_code_fx = L_shl( L_tmp, add( exp_gcode0, 2 ) ); #endif - move32(); /* Q14 -> Q16 */ + move32(); /**norm_gain_code = *gain_code / *gain_inov;*/ expg = sub( norm_s( *gain_inov_fx ), 1 ); expg = s_max( expg, 0 ); tmp_fx = div_s( shr( 8192, expg ), *gain_inov_fx ); - *norm_gain_code_fx = L_shr( Mult_32_16( *gain_code_fx, tmp_fx ), sub( 1, expg ) ); + *norm_gain_code_fx = L_shr( Mult_32_16( *gain_code_fx, tmp_fx ), sub( 1, expg ) ); /*Q16*/ move32(); return; @@ -256,7 +256,7 @@ void gain_dec_tc_ivas_fx( /*----------------------------------------------------------------* * find number of bits for gain dequantization *----------------------------------------------------------------*/ - nBits = st_fx->acelp_cfg.gains_mode[shr( i_subfr_fx, 6 )]; + nBits = st_fx->acelp_cfg.gains_mode[( i_subfr_fx / 64 )]; move16(); /*-----------------------------------------------------------------* * calculate the predicted gain code @@ -264,13 +264,13 @@ void gain_dec_tc_ivas_fx( /*Ecode = (dotp( code, code, L_SUBFR) + 0.01f) / L_SUBFR; *gain_inov = 1.0f / (float)sqrt( Ecode );*/ - L_tmp = Dot_product12( code_fx, code_fx, L_SUBFR, &expg ); - expg = sub( expg, 18 + 6 ); /* exp: -18 (code in Q9), -6 (/L_SUBFR) */ + L_tmp = Dot_product12( code_fx, code_fx, L_SUBFR, &expg ); /*Q31 - expg*/ + expg = sub( expg, 18 + 6 ); /* exp: -18 (code in Q9), -6 (/L_SUBFR) */ expg2 = expg; move16(); L_tmp1 = L_tmp; /* sets to 'L_tmp' in 1 clock */ move32(); - L_tmp = Isqrt_lc( L_tmp, &expg ); + L_tmp = Isqrt_lc( L_tmp, &expg ); /*Q31 - expg*/ *gain_inov_fx = extract_h( L_shl( L_tmp, sub( expg, 3 ) ) ); move16(); /* gain_inov in Q12 */ @@ -278,7 +278,7 @@ void gain_dec_tc_ivas_fx( /* Ei = 10 * (float)log10( Ecode );*/ e_tmp = norm_l( L_tmp1 ); - f_tmp = Log2_norm_lc( L_shl( L_tmp1, e_tmp ) ); + f_tmp = Log2_norm_lc( L_shl( L_tmp1, e_tmp ) ); /*Q15*/ e_tmp = sub( expg2, add( 1, e_tmp ) ); L_tmp1 = Mpy_32_16( e_tmp, f_tmp, 12330 ); /* Q13 */ /* 10*log10(2) in Q12*/ Ei_fx = round_fx( L_shl( L_tmp1, 11 ) ); /* Q8 */ @@ -302,7 +302,7 @@ void gain_dec_tc_ivas_fx( *------------------------------------------------------------------------------------------*/ /* index = (Word16)get_indice( st_fx,"gain_code", i_subfr_fx, ACELP_CORE);move16();*/ - index = (Word16) get_next_indice_fx( st_fx, nBits ); + index = (Word16) get_next_indice_fx( st_fx, nBits ); /*Q0*/ IF( GT_16( nBits, 3 ) ) @@ -321,16 +321,16 @@ void gain_dec_tc_ivas_fx( *-----------------------------------------------------------------*/ /* *gain_code *= gcode0;*/ - L_tmp = L_mult( wgain_code, gcode0_fx ); /* Q12*Q0 -> Q13 */ - *gain_code_fx = L_shl( L_tmp, add( exp_gcode0, 3 ) ); - move32(); /* Q13 -> Q16 */ + L_tmp = L_mult( wgain_code, gcode0_fx ); /* Q12*Q0 -> Q13 */ + *gain_code_fx = L_shl( L_tmp, add( exp_gcode0, 3 ) ); /* Q13 -> Q16 */ + move32(); /**norm_gain_code = *gain_code / *gain_inov;*/ expg = sub( norm_s( *gain_inov_fx ), 1 ); expg = s_max( expg, 0 ); tmp_fx = div_s( shr( 8192, expg ), *gain_inov_fx ); - *norm_gain_code_fx = L_shr( Mult_32_16( *gain_code_fx, tmp_fx ), sub( 1, expg ) ); + *norm_gain_code_fx = L_shr( Mult_32_16( *gain_code_fx, tmp_fx ), sub( 1, expg ) ); /*Q16*/ move32(); return; @@ -388,7 +388,7 @@ void gain_dec_mless_fx( /*-----------------------------------------------------------------* * decode pitch gain *-----------------------------------------------------------------*/ - nBits = st_fx->acelp_cfg.gains_mode[shr( i_subfr_fx, 6 )]; + nBits = st_fx->acelp_cfg.gains_mode[( i_subfr_fx / 64 )]; move16(); test(); @@ -400,7 +400,7 @@ void gain_dec_mless_fx( ( EQ_16( tc_subfr_fx, 4 * L_SUBFR ) && EQ_16( i_subfr_fx, 4 * L_SUBFR ) && EQ_16( L_frame_fx, L_FRAME16k ) ) ) { /* decode pitch gain */ - index = (Word16) get_next_indice_fx( st_fx, shr( nBits, 1 ) ); + index = (Word16) get_next_indice_fx( st_fx, shr( nBits, 1 ) ); /*Q0*/ /*Ei = (G_PITCH_MAX_TC192 - G_PITCH_MIN_TC192) / ((1 << (nBits>>1)) - 1);*/ /* set quantization step */ tmp_fx = div_s( 1, sub( shl( 1, shr( nBits, 1 ) ), 1 ) ); /*Q15*/ @@ -413,20 +413,20 @@ void gain_dec_mless_fx( /* calculate the predicted gain code */ /*Ecode = (dotp( code, code, L_SUBFR) + 0.01f) / L_SUBFR; *gain_inov = 1.0f / (float)sqrt( Ecode );*/ - L_tmp = Dot_product12( code_fx, code_fx, L_SUBFR, &expg ); - expg = sub( expg, 18 + 6 ); /* exp: -18 (code in Q12), -6 (/L_SUBFR) */ + L_tmp = Dot_product12( code_fx, code_fx, L_SUBFR, &expg ); /*Q31 - expg*/ + expg = sub( expg, 18 + 6 ); /* exp: -18 (code in Q12), -6 (/L_SUBFR) */ expg2 = expg; move16(); L_tmp1 = L_tmp; /* sets to 'L_tmp' in 1 clock */ move32(); - L_tmp = Isqrt_lc( L_tmp, &expg ); + L_tmp = Isqrt_lc( L_tmp, &expg ); /*Q31 - expg*/ *gain_inov_fx = extract_h( L_shl( L_tmp, sub( expg, 3 ) ) ); /* gain_inov in Q12 */ move16(); /*Ei = 10 * (float)log10( Ecode );*/ e_tmp = norm_l( L_tmp1 ); - f_tmp = Log2_norm_lc( L_shl( L_tmp1, e_tmp ) ); + f_tmp = Log2_norm_lc( L_shl( L_tmp1, e_tmp ) ); /*Q15*/ e_tmp = sub( expg2, add( 1, e_tmp ) ); L_tmp1 = Mpy_32_16( e_tmp, f_tmp, 12330 ); /* Q13 */ /* 10*log10(2) in Q12*/ Ei_fx = round_fx( L_shl( L_tmp1, 11 ) ); /* Q8 */ @@ -454,7 +454,7 @@ void gain_dec_mless_fx( /* decode normalized codebook gain */ /*index = (short)get_indice( st_fx, "gain_code", i_subfr_fx, ACELP_CORE );move16();*/ - index = (Word16) get_next_indice_fx( st_fx, shr( add( nBits, 1 ), 1 ) ); + index = (Word16) get_next_indice_fx( st_fx, shr( add( nBits, 1 ), 1 ) ); /*Q0*/ move16(); /**gain_code = gain_dequant( index, G_CODE_MIN_TC192, G_CODE_MAX_TC192, (nBits+1)>>1 );*/ @@ -463,11 +463,11 @@ void gain_dec_mless_fx( /**gain_code *= gcode0;*/ L_tmp = L_mult( gain_code16, gcode0_fx ); /*Q0*Q0 -> Q1*/ #ifdef BASOP_NOGLOB - *gain_code_fx = L_shl_sat( L_tmp, add( add( expg, exp_gcode0 ), 15 ) ); + *gain_code_fx = L_shl_sat( L_tmp, add( add( expg, exp_gcode0 ), 15 ) ); /*Q16*/ #else *gain_code_fx = L_shl( L_tmp, add( add( expg, exp_gcode0 ), 15 ) ); #endif - move32(); /*Q16*/ + move32(); } ELSE { @@ -475,27 +475,27 @@ void gain_dec_mless_fx( { case 7: { - qua_table_fx = gain_qua_mless_7b_fx; + qua_table_fx = gain_qua_mless_7b_fx; /*Q14*/ BREAK; } case 6: { - qua_table_fx = gain_qua_mless_6b_fx; + qua_table_fx = gain_qua_mless_6b_fx; /*Q14*/ if ( st_fx->element_mode > EVS_MONO ) { // PMT("gain_qua_mless_6b_stereo to fixed point") - qua_table_fx = gain_qua_mless_6b_stereo_fx; + qua_table_fx = gain_qua_mless_6b_stereo_fx; /*Q14*/ } BREAK; } case 5: { - qua_table_fx = gain_qua_mless_5b_fx; + qua_table_fx = gain_qua_mless_5b_fx; /*Q14*/ BREAK; } default: { - qua_table_fx = gain_qua_mless_6b_fx; + qua_table_fx = gain_qua_mless_6b_fx; /*Q14*/ BREAK; } } @@ -509,26 +509,26 @@ void gain_dec_mless_fx( index = (Word16) get_next_indice_fx( st_fx, nBits ); move16(); - *gain_pit_fx = qua_table_fx[index * 2]; + *gain_pit_fx = qua_table_fx[index * 2]; /*Q14*/ move16(); /*Ecode = (dotp( code, code, L_SUBFR) + 0.01f) / L_SUBFR; *gain_inov = 1.0f / (float)sqrt( Ecode );*/ - L_tmp = Dot_product12( code_fx, code_fx, L_SUBFR, &expg ); - expg = sub( expg, 18 + 6 ); /* exp: -18 (code in Q9), -6 (/L_SUBFR) */ + L_tmp = Dot_product12( code_fx, code_fx, L_SUBFR, &expg ); /*Q31 - expg*/ + expg = sub( expg, 18 + 6 ); /* exp: -18 (code in Q9), -6 (/L_SUBFR) */ expg2 = expg; move16(); L_tmp1 = L_tmp; /* sets to 'L_tmp' in 1 clock */ move32(); - L_tmp = Isqrt_lc( L_tmp, &expg ); + L_tmp = Isqrt_lc( L_tmp, &expg ); /*Q31 - expg*/ *gain_inov_fx = extract_h( L_shl( L_tmp, sub( expg, 3 ) ) ); /* gain_inov in Q12 */ move16(); /*Ei = 10 * (float)log10( Ecode );*/ e_tmp = norm_l( L_tmp1 ); - f_tmp = Log2_norm_lc( L_shl( L_tmp1, e_tmp ) ); + f_tmp = Log2_norm_lc( L_shl( L_tmp1, e_tmp ) ); /*Q15*/ e_tmp = sub( expg2, add( 1, e_tmp ) ); L_tmp1 = Mpy_32_16( e_tmp, f_tmp, 12330 ); /* Q13 */ /* 10*log10(2) in Q12*/ Ei_fx = round_fx( L_shl( L_tmp1, 11 ) ); /* Q8 */ @@ -559,13 +559,13 @@ void gain_dec_mless_fx( *-----------------------------------------------------------------*/ /**gain_code = qua_table[index * 2 + 1] * gcode0;*/ - L_tmp = L_mult( qua_table_fx[add( shl( index, 1 ), 1 )], gcode0_fx ); /* Q9*Q0 -> Q10 */ + L_tmp = L_mult( qua_table_fx[( ( index * 2 ) + 1 )], gcode0_fx ); /* Q9*Q0 -> Q10 */ #ifdef BASOP_NOGLOB - *gain_code_fx = L_shl_sat( L_tmp, add( exp_gcode0, 6 ) ); + *gain_code_fx = L_shl_sat( L_tmp, add( exp_gcode0, 6 ) ); /*Q16*/ #else *gain_code_fx = L_shl( L_tmp, add( exp_gcode0, 6 ) ); #endif - move32(); /* Q10 -> Q16*/ + move32(); } /**norm_gain_code = *gain_code / *gain_inov;*/ @@ -573,7 +573,7 @@ void gain_dec_mless_fx( expg = s_max( expg, 0 ); tmp_fx = div_s( shr( 8192, expg ), *gain_inov_fx ); - *norm_gain_code_fx = L_shr( Mult_32_16( *gain_code_fx, tmp_fx ), sub( 1, expg ) ); + *norm_gain_code_fx = L_shr( Mult_32_16( *gain_code_fx, tmp_fx ), sub( 1, expg ) ); /*Q16*/ move32(); return; @@ -614,8 +614,8 @@ void gain_dec_lbr_fx( Word32 *gain_code_fx, /* o : quantized codebook gain Q16*/ Word16 *gain_inov_fx, /* o : gain of the innovation (used for normalization) Q12*/ Word32 *norm_gain_code_fx, /* o : norm. gain of the codebook excitation Q16*/ - Word32 gc_mem[], /* i/o: gain_code from previous subframes */ - Word16 gp_mem[], /* i/o: gain_pitch from previous subframes */ + Word32 gc_mem[], /* i/o: gain_code from previous subframes Q16*/ + Word16 gp_mem[], /* i/o: gain_pitch from previous subframes Q14*/ const Word16 L_subfr /* i : subfr lenght */ ) { @@ -634,14 +634,14 @@ void gain_dec_lbr_fx( { shift_L_subfr = add( shift_L_subfr, 1 ); } - L_tmp = Dot_product12( code_fx, code_fx, L_subfr, &expg ); - expg = sub( expg, add( 18, shift_L_subfr ) ); /* exp: -18 (code in Q9), -6 (/L_SUBFR) */ + L_tmp = Dot_product12( code_fx, code_fx, L_subfr, &expg ); /*Q31 - expg*/ + expg = sub( expg, add( 18, shift_L_subfr ) ); /* exp: -18 (code in Q9), -6 (/L_SUBFR) */ expg2 = expg; move16(); L_tmp2 = L_tmp; /* sets to 'L_tmp' in 1 clock */ move32(); - L_tmp = Isqrt_lc( L_tmp, &expg ); + L_tmp = Isqrt_lc( L_tmp, &expg ); /*Q31 - expg*/ *gain_inov_fx = extract_h( L_shl_sat( L_tmp, sub( expg, 3 ) ) ); /* gain_inov in Q12 */ move16(); @@ -686,9 +686,9 @@ void gain_dec_lbr_fx( } /* calculate predicted gain */ - aux_fx[0] = 4096; + aux_fx[0] = 4096; /*Q12*/ move16(); - aux_fx[1] = shl( ctype, 12 ); + aux_fx[1] = shl( ctype, 12 ); /*Q12*/ move16(); /* gcode0 = (float)pow(10, dotp(b, aux, n_pred) - 0.5f * (float)log10(Ecode)); @@ -696,7 +696,7 @@ void gain_dec_lbr_fx( gcode0 = (float)pow(10, 0.05(20 * dotp(b, aux, n_pred) - 10 * (float)log10(Ecode))); */ e_tmp = norm_l( L_tmp2 ); - f_tmp = Log2_norm_lc( L_shl( L_tmp2, e_tmp ) ); + f_tmp = Log2_norm_lc( L_shl( L_tmp2, e_tmp ) ); /*Q15*/ e_tmp = sub( expg2, add( 1, e_tmp ) ); L_tmp1 = Mpy_32_16( e_tmp, f_tmp, 12330 ); /* Q13 */ /* 10*log10(2) in Q12*/ @@ -724,33 +724,33 @@ void gain_dec_lbr_fx( /* retrieve the codebook index and calculate both gains */ /*index = (Word16)get_indice( st_fx,"gain", i_subfr, ACELP_CORE);move16();*/ - index = (Word16) get_next_indice_fx( st_fx, nBits ); + index = (Word16) get_next_indice_fx( st_fx, nBits ); /*Q0*/ move16(); - *gain_pit_fx = cdbk_fx[index * 2]; + *gain_pit_fx = cdbk_fx[index * 2]; /*Q14*/ move16(); - L_tmp = L_mult( cdbk_fx[add( shl( index, 1 ), 1 )], gcode0_fx ); /* Q9*Q0 -> Q10 */ + L_tmp = L_mult( cdbk_fx[( ( index * 2 ) + 1 )], gcode0_fx ); /* Q9*Q0 -> Q10 */ #ifdef BASOP_NOGLOB - *gain_code_fx = L_shl_sat( L_tmp, add( exp_gcode0, 6 ) ); + *gain_code_fx = L_shl_sat( L_tmp, add( exp_gcode0, 6 ) ); /* Q10 -> Q16*/ #else *gain_code_fx = L_shl( L_tmp, add( exp_gcode0, 6 ) ); #endif - move16(); /* Q10 -> Q16*/ + move16(); - gc_mem[0] = *gain_code_fx; - move32(); /*Q16*/ - gp_mem[0] = *gain_pit_fx; - move16(); /*Q14*/ + gc_mem[0] = *gain_code_fx; /*Q16*/ + move32(); + gp_mem[0] = *gain_pit_fx; /*Q14*/ + move16(); } ELSE IF( EQ_16( i_subfr, L_SUBFR ) || EQ_16( L_subfr, 2 * L_SUBFR ) ) { - b_fx = b_2sfr_fx; + b_fx = b_2sfr_fx; /*Q12*/ move16(); n_pred = 4; move16(); - cdbk_fx = gp_gamma_1sfr_6b_fx; + cdbk_fx = gp_gamma_1sfr_6b_fx; /*Q14/Q9 */ SWITCH( nBits ) { case 7: @@ -766,18 +766,18 @@ void gain_dec_lbr_fx( } /* calculate predicted gain */ - aux_fx[0] = 4096; + aux_fx[0] = 4096; /*Q12*/ move16(); - aux_fx[1] = shl( ctype, 12 ); + aux_fx[1] = shl( ctype, 12 ); /*Q12*/ move16(); /*aux_fx[2] = (float)log10(gc_mem[0]); = log2(gc_mem[0])*log10(2);*/ e_tmp = norm_l( gc_mem[0] ); - f_tmp = Log2_norm_lc( L_shl( gc_mem[0], e_tmp ) ); - e_tmp = sub( sub( 30, e_tmp ), 16 ); /*Q_format(gc_mem[0])=16*/ - L_tmp1 = Mpy_32_16( e_tmp, f_tmp, 9864 ); /* Q16 */ - aux_fx[2] = round_fx( L_shl( L_tmp1, 12 ) ); /* Q12 */ + f_tmp = Log2_norm_lc( L_shl( gc_mem[0], e_tmp ) ); /*Q15*/ + e_tmp = sub( sub( 30, e_tmp ), 16 ); /*Q_format(gc_mem[0])=16*/ + L_tmp1 = Mpy_32_16( e_tmp, f_tmp, 9864 ); /* Q16 */ + aux_fx[2] = round_fx( L_shl( L_tmp1, 12 ) ); /* Q12 */ move16(); aux_fx[3] = shr( gp_mem[0], 2 ); /*Q12*/ @@ -798,23 +798,23 @@ void gain_dec_lbr_fx( exp_gcode0 = sub( exp_gcode0, 14 ); /* retrieve the codebook index and calculate both gains */ - index = (Word16) get_next_indice_fx( st_fx, nBits ); + index = (Word16) get_next_indice_fx( st_fx, nBits ); /*Q0*/ move16(); - *gain_pit_fx = cdbk_fx[index * 2]; + *gain_pit_fx = cdbk_fx[index * 2]; /*Q14*/ move16(); - L_tmp = L_mult( cdbk_fx[add( shl( index, 1 ), 1 )], gcode0_fx ); /* Q9*Q0 -> Q10 */ + L_tmp = L_mult( cdbk_fx[( ( index * 2 ) + 1 )], gcode0_fx ); /* Q9*Q0 -> Q10 */ #ifdef BASOP_NOGLOB - *gain_code_fx = L_shl_sat( L_tmp, add( exp_gcode0, 6 ) ); + *gain_code_fx = L_shl_sat( L_tmp, add( exp_gcode0, 6 ) ); /*Q16*/ #else *gain_code_fx = L_shl( L_tmp, add( exp_gcode0, 6 ) ); #endif - move16(); /* Q10 -> Q16*/ + move16(); - gc_mem[1] = *gain_code_fx; + gc_mem[1] = *gain_code_fx; /*Q16*/ move32(); - gp_mem[1] = *gain_pit_fx; + gp_mem[1] = *gain_pit_fx; /*Q14*/ move16(); } ELSE IF( EQ_16( i_subfr, 2 * L_SUBFR ) ) @@ -824,41 +824,41 @@ void gain_dec_lbr_fx( n_pred = 6; move16(); - cdbk_fx = gp_gamma_3sfr_6b_fx; + cdbk_fx = gp_gamma_3sfr_6b_fx; /*Q14/Q9 */ if ( EQ_16( nBits, 7 ) ) { - cdbk_fx = gp_gamma_3sfr_7b_fx; + cdbk_fx = gp_gamma_3sfr_7b_fx; /*Q14*/ // PMT("verify if gp_gamma_3sfr_7b_fx is correct") } /* calculate predicted gain */ - aux_fx[0] = 4096; + aux_fx[0] = 4096; /*Q12*/ move16(); - aux_fx[1] = shl( ctype, 12 ); + aux_fx[1] = shl( ctype, 12 ); /*Q12*/ move16(); /*aux_fx[2] = (float)log10(gc_mem[0]); = log2(gc_mem[0])*log10(2);*/ e_tmp = norm_l( gc_mem[0] ); - f_tmp = Log2_norm_lc( L_shl( gc_mem[0], e_tmp ) ); - e_tmp = sub( sub( 30, e_tmp ), 16 ); /*Q_format(gc_mem[0])=16*/ - L_tmp1 = Mpy_32_16( e_tmp, f_tmp, 9864 ); /* Q16 */ - aux_fx[2] = round_fx( L_shl( L_tmp1, 12 ) ); /* Q12 */ + f_tmp = Log2_norm_lc( L_shl( gc_mem[0], e_tmp ) ); /*Q15*/ + e_tmp = sub( sub( 30, e_tmp ), 16 ); /*Q_format(gc_mem[0])=16*/ + L_tmp1 = Mpy_32_16( e_tmp, f_tmp, 9864 ); /* Q16 */ + aux_fx[2] = round_fx( L_shl( L_tmp1, 12 ) ); /* Q12 */ move16(); /*aux[3] = (float)log10(gc_mem[1]); = log2(gc_mem[1])*log10(2);*/ e_tmp = norm_l( gc_mem[1] ); - f_tmp = Log2_norm_lc( L_shl( gc_mem[1], e_tmp ) ); - e_tmp = sub( sub( 30, e_tmp ), 16 ); /*Q_format(gc_mem[1])=16*/ - L_tmp1 = Mpy_32_16( e_tmp, f_tmp, 9864 ); /* Q16 */ - aux_fx[3] = round_fx( L_shl( L_tmp1, 12 ) ); /* Q12 */ + f_tmp = Log2_norm_lc( L_shl( gc_mem[1], e_tmp ) ); /*Q15*/ + e_tmp = sub( sub( 30, e_tmp ), 16 ); /*Q_format(gc_mem[1])=16*/ + L_tmp1 = Mpy_32_16( e_tmp, f_tmp, 9864 ); /* Q16 */ + aux_fx[3] = round_fx( L_shl( L_tmp1, 12 ) ); /* Q12 */ move16(); - aux_fx[4] = shr( gp_mem[0], 2 ); + aux_fx[4] = shr( gp_mem[0], 2 ); /*Q12*/ move16(); - aux_fx[5] = shr( gp_mem[1], 2 ); + aux_fx[5] = shr( gp_mem[1], 2 ); /*Q12*/ move16(); /*-----------------------------------------------------------------* @@ -879,29 +879,29 @@ void gain_dec_lbr_fx( index = (Word16) get_next_indice_fx( st_fx, nBits ); move16(); - *gain_pit_fx = cdbk_fx[shl( index, 1 )]; + *gain_pit_fx = cdbk_fx[( index * 2 )]; /*Q14*/ move16(); - L_tmp = L_mult( cdbk_fx[add( shl( index, 1 ), 1 )], gcode0_fx ); /* Q9*Q0 -> Q10 */ + L_tmp = L_mult( cdbk_fx[( ( index * 2 ) + 1 )], gcode0_fx ); /* Q9*Q0 -> Q10 */ #ifdef BASOP_NOGLOB *gain_code_fx = L_shl_sat( L_tmp, add( exp_gcode0, 6 ) ); /* Q10 -> Q16*/ #else *gain_code_fx = L_shl( L_tmp, add( exp_gcode0, 6 ) ); /* Q10 -> Q16*/ #endif move32(); - gc_mem[2] = *gain_code_fx; + gc_mem[2] = *gain_code_fx; /*Q16*/ move32(); - gp_mem[2] = *gain_pit_fx; + gp_mem[2] = *gain_pit_fx; /*Q14*/ move16(); } ELSE IF( EQ_16( i_subfr, 3 * L_SUBFR ) ) { - b_fx = b_4sfr_fx; + b_fx = b_4sfr_fx; /*Q12*/ n_pred = 8; move16(); - cdbk_fx = gp_gamma_4sfr_6b_fx; + cdbk_fx = gp_gamma_4sfr_6b_fx; /*Q14*/ #ifdef IVAS_GAIN_MOD IF( EQ_16( nBits, 7 ) ) { @@ -911,36 +911,36 @@ void gain_dec_lbr_fx( #endif /* calculate predicted gain */ - aux_fx[0] = 4096; + aux_fx[0] = 4096; /*Q12*/ move16(); - aux_fx[1] = shl( ctype, 12 ); + aux_fx[1] = shl( ctype, 12 ); /*Q12*/ move16(); /*aux[2] = (float)log10(gc_mem[0]); = log2(gc_mem[0])*log10(2);*/ e_tmp = norm_l( gc_mem[0] ); - f_tmp = Log2_norm_lc( L_shl( gc_mem[0], e_tmp ) ); - e_tmp = sub( sub( 30, e_tmp ), 16 ); /*Q_format(gc_mem[0])=16*/ - L_tmp1 = Mpy_32_16( e_tmp, f_tmp, 9864 ); /* Q16 */ - aux_fx[2] = round_fx( L_shl( L_tmp1, 12 ) ); /* Q12 */ + f_tmp = Log2_norm_lc( L_shl( gc_mem[0], e_tmp ) ); /*Q15*/ + e_tmp = sub( sub( 30, e_tmp ), 16 ); /*Q_format(gc_mem[0])=16*/ + L_tmp1 = Mpy_32_16( e_tmp, f_tmp, 9864 ); /* Q16 */ + aux_fx[2] = round_fx( L_shl( L_tmp1, 12 ) ); /* Q12 */ move16(); /*aux[3] = (float)log10(gc_mem[1]); = log2(gc_mem[1])*log10(2);*/ e_tmp = norm_l( gc_mem[1] ); - f_tmp = Log2_norm_lc( L_shl( gc_mem[1], e_tmp ) ); - e_tmp = sub( sub( 30, e_tmp ), 16 ); /*Q_format(gc_mem[1])=16*/ - L_tmp1 = Mpy_32_16( e_tmp, f_tmp, 9864 ); /* Q16 */ - aux_fx[3] = round_fx( L_shl( L_tmp1, 12 ) ); /* Q12 */ + f_tmp = Log2_norm_lc( L_shl( gc_mem[1], e_tmp ) ); /*Q15*/ + e_tmp = sub( sub( 30, e_tmp ), 16 ); /*Q_format(gc_mem[1])=16*/ + L_tmp1 = Mpy_32_16( e_tmp, f_tmp, 9864 ); /* Q16 */ + aux_fx[3] = round_fx( L_shl( L_tmp1, 12 ) ); /* Q12 */ move16(); /*aux[4] = (float)log10(gc_mem[2]); = log2(gc_mem[2])*log10(2);*/ e_tmp = norm_l( gc_mem[2] ); - f_tmp = Log2_norm_lc( L_shl( gc_mem[2], e_tmp ) ); - e_tmp = sub( sub( 30, e_tmp ), 16 ); /*Q_format(gc_mem[2])=16*/ - L_tmp1 = Mpy_32_16( e_tmp, f_tmp, 9864 ); /* Q16 */ - aux_fx[4] = round_fx( L_shl( L_tmp1, 12 ) ); /* Q12 */ + f_tmp = Log2_norm_lc( L_shl( gc_mem[2], e_tmp ) ); /*Q15*/ + e_tmp = sub( sub( 30, e_tmp ), 16 ); /*Q_format(gc_mem[2])=16*/ + L_tmp1 = Mpy_32_16( e_tmp, f_tmp, 9864 ); /* Q16 */ + aux_fx[4] = round_fx( L_shl( L_tmp1, 12 ) ); /* Q12 */ move16(); aux_fx[5] = shr( gp_mem[0], 2 ); /*Q12*/ @@ -965,26 +965,26 @@ void gain_dec_lbr_fx( exp_gcode0 = sub( exp_gcode0, 14 ); /* retrieve the codebook index and calculate both gains */ - index = (Word16) get_next_indice_fx( st_fx, nBits ); + index = (Word16) get_next_indice_fx( st_fx, nBits ); /*Q0*/ move16(); - *gain_pit_fx = cdbk_fx[shl( index, 1 )]; + *gain_pit_fx = cdbk_fx[( index * 2 )]; /*Q14*/ move16(); - L_tmp = L_mult( cdbk_fx[add( shl( index, 1 ), 1 )], gcode0_fx ); /* Q9*Q0 -> Q10 */ + L_tmp = L_mult( cdbk_fx[( ( index * 2 ) + 1 )], gcode0_fx ); /* Q9*Q0 -> Q10 */ #ifdef BASOP_NOGLOB - *gain_code_fx = L_shl_sat( L_tmp, add( exp_gcode0, 6 ) ); + *gain_code_fx = L_shl_sat( L_tmp, add( exp_gcode0, 6 ) ); /*Q16*/ #else *gain_code_fx = L_shl( L_tmp, add( exp_gcode0, 6 ) ); #endif - move32(); /* Q10 -> Q16*/ + move32(); } /* *norm_gain_code = *gain_code / *gain_inov; */ expg = sub( norm_s( *gain_inov_fx ), 1 ); expg = s_max( expg, 0 ); - tmp_fx = div_s( shr( 8192, expg ), *gain_inov_fx ); - *norm_gain_code_fx = L_shr( Mult_32_16( *gain_code_fx, tmp_fx ), sub( 1, expg ) ); + tmp_fx = div_s( shr( 8192, expg ), *gain_inov_fx ); /*Q15*/ + *norm_gain_code_fx = L_shr( Mult_32_16( *gain_code_fx, tmp_fx ), sub( 1, expg ) ); /*Q16*/ move32(); return; @@ -1000,8 +1000,8 @@ void gain_dec_lbr_ivas_fx( Word32 *gain_code_fx, /* o : quantized codebook gain Q16*/ Word16 *gain_inov_fx, /* o : gain of the innovation (used for normalization) Q12*/ Word32 *norm_gain_code_fx, /* o : norm. gain of the codebook excitation Q16*/ - Word32 gc_mem[], /* i/o: gain_code from previous subframes */ - Word16 gp_mem[], /* i/o: gain_pitch from previous subframes */ + Word32 gc_mem[], /* i/o: gain_code from previous subframes Q16*/ + Word16 gp_mem[], /* i/o: gain_pitch from previous subframes Q14*/ const Word16 L_subfr /* i : subfr lenght */ ) { @@ -1020,14 +1020,14 @@ void gain_dec_lbr_ivas_fx( { shift_L_subfr = add( shift_L_subfr, 1 ); } - L_tmp = Dot_product12( code_fx, code_fx, L_subfr, &expg ); - expg = sub( expg, add( 18, shift_L_subfr ) ); /* exp: -18 (code in Q9), -6 (/L_SUBFR) */ + L_tmp = Dot_product12( code_fx, code_fx, L_subfr, &expg ); /*Q31 - expg*/ + expg = sub( expg, add( 18, shift_L_subfr ) ); /* exp: -18 (code in Q9), -6 (/L_SUBFR) */ expg2 = expg; move16(); L_tmp2 = L_tmp; /* sets to 'L_tmp' in 1 clock */ move32(); - L_tmp = Isqrt_lc( L_tmp, &expg ); + L_tmp = Isqrt_lc( L_tmp, &expg ); /*Q31 - expg*/ *gain_inov_fx = extract_h( L_shl_sat( L_tmp, sub( expg, 3 ) ) ); /* gain_inov in Q12 */ move16(); @@ -1048,11 +1048,11 @@ void gain_dec_lbr_ivas_fx( test(); IF( i_subfr == 0 ) { - b_fx = b_1sfr_fx; + b_fx = b_1sfr_fx; /*Q12*/ move16(); n_pred = 2; move16(); - cdbk_fx = gp_gamma_1sfr_6b_fx; + cdbk_fx = gp_gamma_1sfr_6b_fx; /*Q14*/ SWITCH( nBits ) { case 8: @@ -1073,9 +1073,9 @@ void gain_dec_lbr_ivas_fx( } /* calculate predicted gain */ - aux_fx[0] = 4096; + aux_fx[0] = 4096; /*Q12*/ move16(); - aux_fx[1] = shl( ctype, 12 ); + aux_fx[1] = shl( ctype, 12 ); /*Q12*/ move16(); /* gcode0 = (float)pow(10, dotp(b, aux, n_pred) - 0.5f * (float)log10(Ecode)); @@ -1083,7 +1083,7 @@ void gain_dec_lbr_ivas_fx( gcode0 = (float)pow(10, 0.05(20 * dotp(b, aux, n_pred) - 10 * (float)log10(Ecode))); */ e_tmp = norm_l( L_tmp2 ); - f_tmp = Log2_norm_lc( L_shl( L_tmp2, e_tmp ) ); + f_tmp = Log2_norm_lc( L_shl( L_tmp2, e_tmp ) ); /*Q15*/ e_tmp = sub( expg2, add( 1, e_tmp ) ); L_tmp1 = Mpy_32_16( e_tmp, f_tmp, 12330 ); /* Q13 */ /* 10*log10(2) in Q12*/ @@ -1111,33 +1111,33 @@ void gain_dec_lbr_ivas_fx( /* retrieve the codebook index and calculate both gains */ /*index = (Word16)get_indice( st_fx,"gain", i_subfr, ACELP_CORE);move16();*/ - index = (Word16) get_next_indice_fx( st_fx, nBits ); + index = (Word16) get_next_indice_fx( st_fx, nBits ); /*Q0*/ move16(); - *gain_pit_fx = cdbk_fx[index * 2]; + *gain_pit_fx = cdbk_fx[index * 2]; /*Q14*/ move16(); - L_tmp = L_mult( cdbk_fx[add( shl( index, 1 ), 1 )], gcode0_fx ); /* Q9*Q0 -> Q10 */ + L_tmp = L_mult( cdbk_fx[( ( index * 2 ) + 1 )], gcode0_fx ); /* Q9*Q0 -> Q10 */ #ifdef BASOP_NOGLOB - *gain_code_fx = L_shl_sat( L_tmp, add( exp_gcode0, 6 ) ); + *gain_code_fx = L_shl_sat( L_tmp, add( exp_gcode0, 6 ) ); /*Q16*/ #else *gain_code_fx = L_shl( L_tmp, add( exp_gcode0, 6 ) ); #endif - move16(); /* Q10 -> Q16*/ + move16(); - gc_mem[0] = *gain_code_fx; - move32(); /*Q16*/ - gp_mem[0] = *gain_pit_fx; - move16(); /*Q14*/ + gc_mem[0] = *gain_code_fx; /*Q16*/ + move32(); + gp_mem[0] = *gain_pit_fx; /*Q14*/ + move16(); } ELSE IF( EQ_16( i_subfr, L_SUBFR ) || EQ_16( L_subfr, 2 * L_SUBFR ) ) { - b_fx = b_2sfr_fx; + b_fx = b_2sfr_fx; /*Q12*/ move16(); n_pred = 4; move16(); - cdbk_fx = gp_gamma_1sfr_6b_fx; + cdbk_fx = gp_gamma_1sfr_6b_fx; /*Q14*/ SWITCH( nBits ) { case 7: @@ -1153,18 +1153,18 @@ void gain_dec_lbr_ivas_fx( } /* calculate predicted gain */ - aux_fx[0] = 4096; + aux_fx[0] = 4096; /*Q12*/ move16(); - aux_fx[1] = shl( ctype, 12 ); + aux_fx[1] = shl( ctype, 12 ); /*Q12*/ move16(); /*aux_fx[2] = (float)log10(gc_mem[0]); = log2(gc_mem[0])*log10(2);*/ e_tmp = norm_l( gc_mem[0] ); - f_tmp = Log2_norm_lc( L_shl( gc_mem[0], e_tmp ) ); - e_tmp = sub( sub( 30, e_tmp ), 16 ); /*Q_format(gc_mem[0])=16*/ - L_tmp1 = Mpy_32_16( e_tmp, f_tmp, 9864 ); /* Q16 */ - aux_fx[2] = round_fx( L_shl( L_tmp1, 12 ) ); /* Q12 */ + f_tmp = Log2_norm_lc( L_shl( gc_mem[0], e_tmp ) ); /*Q15*/ + e_tmp = sub( sub( 30, e_tmp ), 16 ); /*Q_format(gc_mem[0])=16*/ + L_tmp1 = Mpy_32_16( e_tmp, f_tmp, 9864 ); /* Q16 */ + aux_fx[2] = round_fx( L_shl( L_tmp1, 12 ) ); /* Q12 */ move16(); aux_fx[3] = shr( gp_mem[0], 2 ); /*Q12*/ @@ -1185,67 +1185,67 @@ void gain_dec_lbr_ivas_fx( exp_gcode0 = sub( exp_gcode0, 14 ); /* retrieve the codebook index and calculate both gains */ - index = (Word16) get_next_indice_fx( st_fx, nBits ); + index = (Word16) get_next_indice_fx( st_fx, nBits ); /*Q0*/ move16(); - *gain_pit_fx = cdbk_fx[index * 2]; + *gain_pit_fx = cdbk_fx[index * 2]; /*Q14*/ move16(); - L_tmp = L_mult( cdbk_fx[add( shl( index, 1 ), 1 )], gcode0_fx ); /* Q9*Q0 -> Q10 */ + L_tmp = L_mult( cdbk_fx[( ( index * 2 ) + 1 )], gcode0_fx ); /* Q9*Q0 -> Q10 */ #ifdef BASOP_NOGLOB - *gain_code_fx = L_shl_sat( L_tmp, add( exp_gcode0, 6 ) ); + *gain_code_fx = L_shl_sat( L_tmp, add( exp_gcode0, 6 ) ); /*Q16*/ #else *gain_code_fx = L_shl( L_tmp, add( exp_gcode0, 6 ) ); #endif - move16(); /* Q10 -> Q16*/ + move16(); - gc_mem[1] = *gain_code_fx; + gc_mem[1] = *gain_code_fx; /*Q16*/ move32(); - gp_mem[1] = *gain_pit_fx; + gp_mem[1] = *gain_pit_fx; /*Q14*/ move16(); } ELSE IF( EQ_16( i_subfr, 2 * L_SUBFR ) ) { - b_fx = b_3sfr_fx; + b_fx = b_3sfr_fx; /*Q12*/ move16(); n_pred = 6; move16(); - cdbk_fx = gp_gamma_3sfr_6b_fx; + cdbk_fx = gp_gamma_3sfr_6b_fx; /*Q14/Q9 */ if ( EQ_16( nBits, 7 ) ) { - cdbk_fx = gp_gamma_3sfr_7b_fx; + cdbk_fx = gp_gamma_3sfr_7b_fx; /*Q14*/ // PMT("verify if gp_gamma_3sfr_7b_fx is correct") } /* calculate predicted gain */ - aux_fx[0] = 4096; + aux_fx[0] = 4096; /*Q12*/ move16(); - aux_fx[1] = shl( ctype, 12 ); + aux_fx[1] = shl( ctype, 12 ); /*Q12*/ move16(); /*aux_fx[2] = (float)log10(gc_mem[0]); = log2(gc_mem[0])*log10(2);*/ e_tmp = norm_l( gc_mem[0] ); - f_tmp = Log2_norm_lc( L_shl( gc_mem[0], e_tmp ) ); - e_tmp = sub( sub( 30, e_tmp ), 16 ); /*Q_format(gc_mem[0])=16*/ - L_tmp1 = Mpy_32_16( e_tmp, f_tmp, 9864 ); /* Q16 */ - aux_fx[2] = round_fx( L_shl( L_tmp1, 12 ) ); /* Q12 */ + f_tmp = Log2_norm_lc( L_shl( gc_mem[0], e_tmp ) ); /*Q15*/ + e_tmp = sub( sub( 30, e_tmp ), 16 ); /*Q_format(gc_mem[0])=16*/ + L_tmp1 = Mpy_32_16( e_tmp, f_tmp, 9864 ); /* Q16 */ + aux_fx[2] = round_fx( L_shl( L_tmp1, 12 ) ); /* Q12 */ move16(); /*aux[3] = (float)log10(gc_mem[1]); = log2(gc_mem[1])*log10(2);*/ e_tmp = norm_l( gc_mem[1] ); - f_tmp = Log2_norm_lc( L_shl( gc_mem[1], e_tmp ) ); - e_tmp = sub( sub( 30, e_tmp ), 16 ); /*Q_format(gc_mem[1])=16*/ - L_tmp1 = Mpy_32_16( e_tmp, f_tmp, 9864 ); /* Q16 */ - aux_fx[3] = round_fx( L_shl( L_tmp1, 12 ) ); /* Q12 */ + f_tmp = Log2_norm_lc( L_shl( gc_mem[1], e_tmp ) ); /*Q15*/ + e_tmp = sub( sub( 30, e_tmp ), 16 ); /*Q_format(gc_mem[1])=16*/ + L_tmp1 = Mpy_32_16( e_tmp, f_tmp, 9864 ); /* Q16 */ + aux_fx[3] = round_fx( L_shl( L_tmp1, 12 ) ); /* Q12 */ move16(); - aux_fx[4] = shr( gp_mem[0], 2 ); + aux_fx[4] = shr( gp_mem[0], 2 ); /*Q12*/ move16(); - aux_fx[5] = shr( gp_mem[1], 2 ); + aux_fx[5] = shr( gp_mem[1], 2 ); /*Q12*/ move16(); /*-----------------------------------------------------------------* @@ -1263,70 +1263,70 @@ void gain_dec_lbr_ivas_fx( exp_gcode0 = sub( exp_gcode0, 14 ); /* retrieve the codebook index and calculate both gains */ - index = (Word16) get_next_indice_fx( st_fx, nBits ); + index = (Word16) get_next_indice_fx( st_fx, nBits ); /*Q0*/ move16(); - *gain_pit_fx = cdbk_fx[shl( index, 1 )]; + *gain_pit_fx = cdbk_fx[( index * 2 )]; move16(); - L_tmp = L_mult( cdbk_fx[add( shl( index, 1 ), 1 )], gcode0_fx ); /* Q9*Q0 -> Q10 */ + L_tmp = L_mult( cdbk_fx[( ( index * 2 ) + 1 )], gcode0_fx ); /* Q9*Q0 -> Q10 */ #ifdef BASOP_NOGLOB *gain_code_fx = L_shl_sat( L_tmp, add( exp_gcode0, 6 ) ); /* Q10 -> Q16*/ #else *gain_code_fx = L_shl( L_tmp, add( exp_gcode0, 6 ) ); /* Q10 -> Q16*/ #endif move32(); - gc_mem[2] = *gain_code_fx; + gc_mem[2] = *gain_code_fx; /*Q16*/ move32(); - gp_mem[2] = *gain_pit_fx; + gp_mem[2] = *gain_pit_fx; /*Q14*/ move16(); } ELSE IF( EQ_16( i_subfr, 3 * L_SUBFR ) ) { - b_fx = b_4sfr_fx; + b_fx = b_4sfr_fx; /*Q12*/ n_pred = 8; move16(); - cdbk_fx = gp_gamma_4sfr_6b_fx; + cdbk_fx = gp_gamma_4sfr_6b_fx; /*Q14*/ IF( EQ_16( nBits, 7 ) ) { - cdbk_fx = gp_gamma_4sfr_7b_fx; + cdbk_fx = gp_gamma_4sfr_7b_fx; /*Q14*/ // PMT( "verify if gp_gamma_4sfr_7b_fx is correct" ) } /* calculate predicted gain */ - aux_fx[0] = 4096; + aux_fx[0] = 4096; /*Q12*/ move16(); - aux_fx[1] = shl( ctype, 12 ); + aux_fx[1] = shl( ctype, 12 ); /*Q12*/ move16(); /*aux[2] = (float)log10(gc_mem[0]); = log2(gc_mem[0])*log10(2);*/ e_tmp = norm_l( gc_mem[0] ); - f_tmp = Log2_norm_lc( L_shl( gc_mem[0], e_tmp ) ); - e_tmp = sub( sub( 30, e_tmp ), 16 ); /*Q_format(gc_mem[0])=16*/ - L_tmp1 = Mpy_32_16( e_tmp, f_tmp, 9864 ); /* Q16 */ - aux_fx[2] = round_fx( L_shl( L_tmp1, 12 ) ); /* Q12 */ + f_tmp = Log2_norm_lc( L_shl( gc_mem[0], e_tmp ) ); /*Q15*/ + e_tmp = sub( sub( 30, e_tmp ), 16 ); /*Q_format(gc_mem[0])=16*/ + L_tmp1 = Mpy_32_16( e_tmp, f_tmp, 9864 ); /* Q16 */ + aux_fx[2] = round_fx( L_shl( L_tmp1, 12 ) ); /* Q12 */ move16(); /*aux[3] = (float)log10(gc_mem[1]); = log2(gc_mem[1])*log10(2);*/ e_tmp = norm_l( gc_mem[1] ); - f_tmp = Log2_norm_lc( L_shl( gc_mem[1], e_tmp ) ); - e_tmp = sub( sub( 30, e_tmp ), 16 ); /*Q_format(gc_mem[1])=16*/ - L_tmp1 = Mpy_32_16( e_tmp, f_tmp, 9864 ); /* Q16 */ - aux_fx[3] = round_fx( L_shl( L_tmp1, 12 ) ); /* Q12 */ + f_tmp = Log2_norm_lc( L_shl( gc_mem[1], e_tmp ) ); /*Q15*/ + e_tmp = sub( sub( 30, e_tmp ), 16 ); /*Q_format(gc_mem[1])=16*/ + L_tmp1 = Mpy_32_16( e_tmp, f_tmp, 9864 ); /* Q16 */ + aux_fx[3] = round_fx( L_shl( L_tmp1, 12 ) ); /* Q12 */ move16(); /*aux[4] = (float)log10(gc_mem[2]); = log2(gc_mem[2])*log10(2);*/ e_tmp = norm_l( gc_mem[2] ); - f_tmp = Log2_norm_lc( L_shl( gc_mem[2], e_tmp ) ); - e_tmp = sub( sub( 30, e_tmp ), 16 ); /*Q_format(gc_mem[2])=16*/ - L_tmp1 = Mpy_32_16( e_tmp, f_tmp, 9864 ); /* Q16 */ - aux_fx[4] = round_fx( L_shl( L_tmp1, 12 ) ); /* Q12 */ + f_tmp = Log2_norm_lc( L_shl( gc_mem[2], e_tmp ) ); /*Q15*/ + e_tmp = sub( sub( 30, e_tmp ), 16 ); /*Q_format(gc_mem[2])=16*/ + L_tmp1 = Mpy_32_16( e_tmp, f_tmp, 9864 ); /* Q16 */ + aux_fx[4] = round_fx( L_shl( L_tmp1, 12 ) ); /* Q12 */ move16(); aux_fx[5] = shr( gp_mem[0], 2 ); /*Q12*/ @@ -1353,24 +1353,24 @@ void gain_dec_lbr_ivas_fx( /* retrieve the codebook index and calculate both gains */ index = (Word16) get_next_indice_fx( st_fx, nBits ); move16(); - *gain_pit_fx = cdbk_fx[shl( index, 1 )]; + *gain_pit_fx = cdbk_fx[( index * 2 )]; /*Q14*/ move16(); - L_tmp = L_mult( cdbk_fx[add( shl( index, 1 ), 1 )], gcode0_fx ); /* Q9*Q0 -> Q10 */ + L_tmp = L_mult( cdbk_fx[( ( index * 2 ) + 1 )], gcode0_fx ); /* Q9*Q0 -> Q10 */ #ifdef BASOP_NOGLOB - *gain_code_fx = L_shl_sat( L_tmp, add( exp_gcode0, 6 ) ); + *gain_code_fx = L_shl_sat( L_tmp, add( exp_gcode0, 6 ) ); /*Q16*/ #else *gain_code_fx = L_shl( L_tmp, add( exp_gcode0, 6 ) ); #endif - move32(); /* Q10 -> Q16*/ + move32(); } /* *norm_gain_code = *gain_code / *gain_inov; */ expg = sub( norm_s( *gain_inov_fx ), 1 ); expg = s_max( expg, 0 ); - tmp_fx = div_s( shr( 8192, expg ), *gain_inov_fx ); - *norm_gain_code_fx = L_shr( Mult_32_16( *gain_code_fx, tmp_fx ), sub( 1, expg ) ); + tmp_fx = div_s( shr( 8192, expg ), *gain_inov_fx ); /*Q15*/ + *norm_gain_code_fx = L_shr( Mult_32_16( *gain_code_fx, tmp_fx ), sub( 1, expg ) ); /*Q15*/ move32(); return; @@ -1755,7 +1755,7 @@ void gain_dec_SQ_fx( * get number of bits *-----------------------------------------------------------------*/ - nBits = st_fx->acelp_cfg.gains_mode[shr( i_subfr, 6 )]; + nBits = st_fx->acelp_cfg.gains_mode[( i_subfr / 64 )]; move16(); /*-----------------------------------------------------------------* @@ -1786,7 +1786,7 @@ void gain_dec_SQ_fx( move16(); L_tmp1 = L_tmp; /* sets to 'L_tmp' in 1 clock */ move32(); - L_tmp = Isqrt_lc( L_tmp, &expg ); + L_tmp = Isqrt_lc( L_tmp, &expg ); /*Q31 - expg*/ *gain_inov = extract_h( L_shl( L_tmp, sub( expg, 3 ) ) ); /* gain_inov in Q12 */ move16(); @@ -1822,18 +1822,18 @@ void gain_dec_SQ_fx( L_tmp = L_mult( tmp16, gcode0 ); /* Q0*Q0 -> Q1*/ /**gain_code = L_shl(L_tmp,add(expg,15)); Q16*/ #ifdef BASOP_NOGLOB - *gain_code = L_shl_sat( L_tmp, add( add( expg, exp_gcode0 ), 15 ) ); + *gain_code = L_shl_sat( L_tmp, add( add( expg, exp_gcode0 ), 15 ) ); /*Q16*/ #else *gain_code = L_shl( L_tmp, add( add( expg, exp_gcode0 ), 15 ) ); #endif - move32(); /*Q16*/ + move32(); /**norm_gain_code = *gain_code / *gain_inov;*/ expg = sub( norm_s( *gain_inov ), 1 ); expg = s_max( expg, 0 ); - tmp16 = div_s( shr( 8192, expg ), *gain_inov ); - *norm_gain_code = L_shr( Mult_32_16( *gain_code, tmp16 ), sub( 1, expg ) ); + tmp16 = div_s( shr( 8192, expg ), *gain_inov ); /*Q15*/ + *norm_gain_code = L_shr( Mult_32_16( *gain_code, tmp16 ), sub( 1, expg ) ); /*Q16*/ move32(); return; @@ -1848,12 +1848,12 @@ void gain_dec_SQ_fx( void gain_dec_amr_wb_fx( Decoder_State *st_fx, /* i/o: decoder state structure */ const Word32 core_brate, /* i : core bitrate */ - Word16 *gain_pit, /* o : Quantized pitch gain */ - Word32 *gain_code, /* o : Quantized codeebook gain */ - Word16 *past_qua_en, /* i/o: gain quantization memory (4 words) */ - Word16 *gain_inov, /* o : unscaled innovation gain */ - const Word16 *code, /* i : algebraic code excitation */ - Word32 *norm_gain_code /* o : norm. gain of the codebook excitation */ + Word16 *gain_pit, /* o : Quantized pitch gain Q14*/ + Word32 *gain_code, /* o : Quantized codeebook gain Q16*/ + Word16 *past_qua_en, /* i/o: gain quantization memory (4 words) Q10*/ + Word16 *gain_inov, /* o : unscaled innovation gain Q12*/ + const Word16 *code, /* i : algebraic code excitation Q9*/ + Word32 *norm_gain_code /* o : norm. gain of the codebook excitation Q16*/ ) { Word16 i, index, index2; @@ -1871,9 +1871,9 @@ void gain_dec_amr_wb_fx( /**gain_inov = 1.0f/ (float)sqrt( ( dotp( code, code, L_SUBFR ) + 0.01f ) / L_SUBFR );*/ - L_tmp = Dot_product12( code, code, L_SUBFR, &expg ); - expg = sub( expg, 18 + 6 ); /* exp: -18 (code in Q9), -6 (/L_SUBFR) */ - L_tmp = Isqrt_lc( L_tmp, &expg ); + L_tmp = Dot_product12( code, code, L_SUBFR, &expg ); /*Q31 - expg*/ + expg = sub( expg, 18 + 6 ); /* exp: -18 (code in Q9), -6 (/L_SUBFR) */ + L_tmp = Isqrt_lc( L_tmp, &expg ); /*Q31 - expg*/ *gain_inov = extract_h( L_shl( L_tmp, sub( expg, 3 ) ) ); /* gain_inov in Q12 */ move16(); @@ -1939,23 +1939,23 @@ void gain_dec_amr_wb_fx( /*-----------------------------------------------------------------* * Decode code gain *-----------------------------------------------------------------*/ - qua_en = t_qua_gain[add( index2, 1 )]; + qua_en = t_qua_gain[( index2 + 1 )]; move16(); /* *gain_code = t_qua_gain[indice*2+1] * gcode0; */ - L_tmp = L_mult( qua_en, gcode0 ); /* Q11*Q0 -> Q12 */ - tmp = round_fx( L_tmp ); /* Q-4 */ - *gain_code = L_shl( L_tmp, add( exp_gcode0, 4 ) ); - move32(); /* Q12 -> Q16 */ + L_tmp = L_mult( qua_en, gcode0 ); /* Q11*Q0 -> Q12 */ + tmp = round_fx( L_tmp ); /* Q-4 */ + *gain_code = L_shl( L_tmp, add( exp_gcode0, 4 ) ); /* Q12 -> Q16 */ + move32(); /* adjust gain according to energy of code */ L_tmp = Mult_32_16( *gain_code, *gain_inov ); #ifdef BASOP_NOGLOB - *gain_code = L_shl_o( L_tmp, 3, &Overflow ); + *gain_code = L_shl_o( L_tmp, 3, &Overflow ); /* gcode_inov in Q12*/ #else *gain_code = L_shl( L_tmp, 3 ); #endif - move32(); /* gcode_inov in Q12*/ + move32(); /*-----------------------------------------------------------------* * update table of past quantized energies @@ -1989,8 +1989,8 @@ void gain_dec_amr_wb_fx( expg = sub( norm_s( *gain_inov ), 1 ); expg = s_max( expg, 0 ); - tmp = div_s( shr( 8192, expg ), *gain_inov ); - *norm_gain_code = L_shr( Mult_32_16( *gain_code, tmp ), sub( 1, expg ) ); + tmp = div_s( shr( 8192, expg ), *gain_inov ); /*Q15*/ + *norm_gain_code = L_shr( Mult_32_16( *gain_code, tmp ), sub( 1, expg ) ); /*Q16*/ move32(); return; diff --git a/lib_dec/gaus_dec_fx.c b/lib_dec/gaus_dec_fx.c index 5221e14f4..802cc3b41 100644 --- a/lib_dec/gaus_dec_fx.c +++ b/lib_dec/gaus_dec_fx.c @@ -53,7 +53,7 @@ void gaus_dec_fx( /*------------------------------------------------------------------------------------------* * Unvoiced : Gaussian codebook *------------------------------------------------------------------------------------------*/ - nb_bits = st_fx->acelp_cfg.fixed_cdk_index[shr( i_subfr, 6 )]; + nb_bits = st_fx->acelp_cfg.fixed_cdk_index[( i_subfr / 64 )]; move16(); gaus_dec2v_fx( st_fx, code, L_SUBFR, shr( nb_bits, 1 ) ); @@ -68,7 +68,7 @@ void gaus_dec_fx( *inv_gain_inov = extract_h( L_shl_sat( L_tmp, sub( exp, 3 ) ) ); /* inv_gain_inov in Q12 */ move16(); - nb_bits = st_fx->acelp_cfg.gains_mode[shr( i_subfr, 6 )]; + nb_bits = st_fx->acelp_cfg.gains_mode[( i_subfr / 64 )]; move16(); idx = (Word16) get_next_indice_fx( st_fx, nb_bits ); move16(); @@ -83,7 +83,7 @@ void gaus_dec_fx( move16(); } - *L_gain_code = gain_dec_gaus_fx( idx, nb_bits, -30, 190, *inv_gain_inov, L_norm_gain_code ); + *L_gain_code = gain_dec_gaus_fx( idx, nb_bits, -30, 190, *inv_gain_inov, L_norm_gain_code ); /*Q16*/ move32(); /* update LP filtered gains for the case of frame erasures */ @@ -102,7 +102,7 @@ void gaus_dec_fx( *tilt_code = 0; move16(); - *voice_fac = -32768; /* only unvoiced */ + *voice_fac = -32768; /* only unvoiced Q15 */ move16(); *gain_pit = 0; /* needed for BASS postfitler */ move16(); @@ -127,11 +127,11 @@ void gaus_dec_fx( L_SUBFR, L_SUBFR * 2, *L_gain_code, sQ_exc, sQsubfr, exc2, i_subfr, UNVOICED ); } - gain_code = round_fx( L_shl( *L_gain_code, *sQ_exc ) ); + gain_code = round_fx( L_shl( *L_gain_code, *sQ_exc ) ); /*sQ_exc*/ FOR( i = 0; i < L_SUBFR; i++ ) { L_tmp = L_shl( L_mult( gain_code, code[i] ), 6 /*3*/ ); - exc[add( i, i_subfr )] = round_fx( L_tmp ); + exc[( i + i_subfr )] = round_fx( L_tmp ); /*sQ_exc+3*/ move16(); } @@ -164,10 +164,10 @@ void gaus_dec2v_fx( const Word16 *pt1, *pt2; Word16 index_delta; - step = shr( 0x80, nb_bits ); + step = shr( 0x80, nb_bits ); /*Q0*/ - idx = (Word16) get_next_indice_fx( st_fx, add( shl( nb_bits, 1 ), 1 ) ); - index_delta = (Word16) get_next_indice_fx( st_fx, 3 ); + idx = (Word16) get_next_indice_fx( st_fx, add( shl( nb_bits, 1 ), 1 ) ); /*Q0*/ + index_delta = (Word16) get_next_indice_fx( st_fx, 3 ); /*Q0*/ move16(); move16(); @@ -175,7 +175,7 @@ void gaus_dec2v_fx( delta = shl( index_delta, STEP_DELTA_FX ); delta2 = mac_r( 16384 * 65536, shr( delta, 1 ), delta ); - inv_delta = div_s( 16384, delta2 ); + inv_delta = div_s( 16384, delta2 ); /*Q15*/ IF( delta > 0 ) { @@ -184,8 +184,8 @@ void gaus_dec2v_fx( FOR( i = 1; i < 190; i++ ) { /* gaus_dico2[i] = (gaus_dico_fx[i] - delta*gaus_dico_fx[i-1])/(1+delta*delta) */ - tmp16 = msu_r( L_deposit_h( gaus_dico_fx[i] ), delta, gaus_dico_fx[i - 1] ); - gaus_dico2_fx[i] = mult_r( tmp16, inv_delta ); + tmp16 = msu_r( L_deposit_h( gaus_dico_fx[i] ), delta, gaus_dico_fx[i - 1] ); /*Q12*/ + gaus_dico2_fx[i] = mult_r( tmp16, inv_delta ); /*Q12*/ move16(); } } @@ -198,14 +198,14 @@ void gaus_dec2v_fx( } } - pt1 = &gaus_dico2_fx[i_mult2( ind1, step )]; - pt2 = &gaus_dico2_fx[i_mult2( ind2, step )]; + pt1 = &gaus_dico2_fx[( ind1 * step )]; /*Q12*/ + pt2 = &gaus_dico2_fx[( ind2 * step )]; /*Q12*/ FOR( i = 0; i < lg; i++ ) { /* code is Q9, Gaussian codebook is Q12 */ /* code[i] = pt1[i] * sign1 + pt2[i] * sign2 */ - code[i] = add( mult( pt1[i], sign1 ), mult( pt2[i], sign2 ) ); + code[i] = add( mult( pt1[i], sign1 ), mult( pt2[i], sign2 ) ); /*Q12-exp*/ move16(); } @@ -242,9 +242,9 @@ static void dec_2pos_fx( index = shr( index, 1 ); - *ind1 = shr( index, log2_n ); + *ind1 = shr( index, log2_n ); /*Q0*/ move16(); - *ind2 = sub( index, shl( *ind1, log2_n ) ); + *ind2 = sub( index, shl( *ind1, log2_n ) ); /*Q0*/ move16(); *sign2 = *sign1; move16(); @@ -276,21 +276,21 @@ void gaus_L2_dec( Word32 tmp32; /*Generate white gaussian noise using central limit theorem method (N only 4 as E_util_random is not purely uniform)*/ - seed = *seed_acelp; + seed = *seed_acelp; /*Q0*/ move16(); FOR( i = 0; i < L_SUBFR; i++ ) { Random( &seed ); - tmp32 = L_mac( 0, seed, 1 << 9 ); + tmp32 = L_mac( 0, seed, 1 << 9 ); /*Q9*/ Random( &seed ); - tmp32 = L_mac( tmp32, seed, 1 << 9 ); + tmp32 = L_mac( tmp32, seed, 1 << 9 ); /*Q9*/ Random( &seed ); - code[i] = mac_r( tmp32, seed, 1 << 9 ); + code[i] = mac_r( tmp32, seed, 1 << 9 ); /*Q9*/ move16(); } - *seed_acelp = seed; + *seed_acelp = seed; /*Q0*/ move16(); /*Shape the gaussian excitation*/ diff --git a/lib_enc/ivas_dirac_enc.c b/lib_enc/ivas_dirac_enc.c index beeec44b7..45a008543 100644 --- a/lib_enc/ivas_dirac_enc.c +++ b/lib_enc/ivas_dirac_enc.c @@ -41,6 +41,7 @@ #include "ivas_prot_fx.h" #include "ivas_cnst.h" #include "ivas_rom_com.h" +#include "ivas_rom_com_fx.h" #include "wmc_auto.h" /*------------------------------------------------------------------------- @@ -65,80 +66,67 @@ static void computeIntensityVector_enc( DIRAC_ENC_HANDLE hDirAC, float Cldfb_Rea *------------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED -ivas_error ivas_dirac_enc_open( +ivas_error ivas_dirac_enc_open_fx( Encoder_Struct *st_ivas /* i/o: IVAS encoder handle */ ) { - int16_t i, j; + Word16 i, j; DIRAC_ENC_HANDLE hDirAC; - int32_t dirac_slot_ns; + Word32 dirac_slot_ns; ivas_error error; error = IVAS_ERR_OK; + move16(); - if ( ( hDirAC = (DIRAC_ENC_HANDLE) malloc( sizeof( DIRAC_ENC_DATA ) ) ) == NULL ) + IF( ( hDirAC = (DIRAC_ENC_HANDLE) malloc( sizeof( DIRAC_ENC_DATA ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); } - if ( ( hDirAC->hConfig = (DIRAC_CONFIG_DATA_HANDLE) malloc( sizeof( DIRAC_CONFIG_DATA ) ) ) == NULL ) + IF( ( hDirAC->hConfig = (DIRAC_CONFIG_DATA_HANDLE) malloc( sizeof( DIRAC_CONFIG_DATA ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC Config\n" ) ); } hDirAC->firstrun_sector_params = 1; - set_zero( hDirAC->sec_I_vec_smth_x[0], NUM_ANA_SECTORS * IVAS_MAX_NUM_BANDS ); - set_zero( hDirAC->sec_I_vec_smth_y[0], NUM_ANA_SECTORS * IVAS_MAX_NUM_BANDS ); - set_zero( hDirAC->sec_I_vec_smth_z[0], NUM_ANA_SECTORS * IVAS_MAX_NUM_BANDS ); - set_zero( hDirAC->azi_prev, NUM_ANA_SECTORS * IVAS_MAX_NUM_BANDS ); - set_zero( hDirAC->ele_prev, NUM_ANA_SECTORS * IVAS_MAX_NUM_BANDS ); - set_zero( hDirAC->energy_smth[0], NUM_ANA_SECTORS * IVAS_MAX_NUM_BANDS ); + move16(); + + set32_fx( hDirAC->sec_I_vec_smth_x_fx[0], 0, NUM_ANA_SECTORS * IVAS_MAX_NUM_BANDS ); + set16_fx( hDirAC->sec_I_vec_smth_x_exp[0], 0, NUM_ANA_SECTORS * IVAS_MAX_NUM_BANDS ); + set32_fx( hDirAC->sec_I_vec_smth_y_fx[0], 0, NUM_ANA_SECTORS * IVAS_MAX_NUM_BANDS ); + set16_fx( hDirAC->sec_I_vec_smth_y_exp[0], 0, NUM_ANA_SECTORS * IVAS_MAX_NUM_BANDS ); + set32_fx( hDirAC->sec_I_vec_smth_z_fx[0], 0, NUM_ANA_SECTORS * IVAS_MAX_NUM_BANDS ); + set16_fx( hDirAC->sec_I_vec_smth_z_exp[0], 0, NUM_ANA_SECTORS * IVAS_MAX_NUM_BANDS ); + set32_fx( hDirAC->energy_smth_fx[0], 0, NUM_ANA_SECTORS * IVAS_MAX_NUM_BANDS ); + set16_fx( hDirAC->energy_smth_exp[0], 0, NUM_ANA_SECTORS * IVAS_MAX_NUM_BANDS ); + set32_fx( hDirAC->ele_prev_fx, 0, NUM_ANA_SECTORS * IVAS_MAX_NUM_BANDS ); + set32_fx( hDirAC->azi_prev_fx, 0, NUM_ANA_SECTORS * IVAS_MAX_NUM_BANDS ); /*-----------------------------------------------------------------* * DirAC main configuration *-----------------------------------------------------------------*/ st_ivas->hDirAC = hDirAC; -#ifdef IVAS_FLOAT_FIXED IF( ( error = ivas_dirac_config_fx( (void *) st_ivas, ENC ) ) != IVAS_ERR_OK ) { return error; } -#else - if ( ( error = ivas_dirac_config( (void *) st_ivas, ENC ) ) != IVAS_ERR_OK ) - { - return error; - } -#endif /* set FB config. */ hDirAC->hFbMixer = NULL; - for ( i = 0; i < DIRAC_MAX_NBANDS + 1; i++ ) + FOR( i = 0; i < DIRAC_MAX_NBANDS + 1; i++ ) { /* adapt band grouping to from CLDFB to MDFT bands */ - hDirAC->band_grouping[i] *= CLDFB_TO_MDFT_FAC; + hDirAC->band_grouping[i] = imult1616( hDirAC->band_grouping[i], CLDFB_TO_MDFT_FAC ); + move16(); } dirac_slot_ns = DIRAC_SLOT_ENC_NS; - + move16(); /* initialize delay for SPAR/DirAC delay synchronization */ /* intensity 3-dim */ - for ( i = 0; i < DIRAC_NUM_DIMS; i++ ) + FOR( i = 0; i < DIRAC_NUM_DIMS; i++ ) { - if ( ( hDirAC->direction_vector_m[i] = (float **) malloc( MAX_PARAM_SPATIAL_SUBFRAMES * sizeof( float * ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); - } - - for ( j = 0; j < MAX_PARAM_SPATIAL_SUBFRAMES; j++ ) - { - if ( ( hDirAC->direction_vector_m[i][j] = (float *) malloc( DIRAC_MAX_NBANDS * sizeof( float ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); - } - set_f( hDirAC->direction_vector_m[i][j], 0.0f, DIRAC_MAX_NBANDS ); - } -#ifdef IVAS_FLOAT_FIXED IF( ( hDirAC->direction_vector_m_fx[i] = (Word32 **) malloc( MAX_PARAM_SPATIAL_SUBFRAMES * sizeof( Word32 * ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); @@ -146,38 +134,22 @@ ivas_error ivas_dirac_enc_open( FOR( j = 0; j < MAX_PARAM_SPATIAL_SUBFRAMES; j++ ) { - if ( ( hDirAC->direction_vector_m_fx[i][j] = (Word32 *) malloc( DIRAC_MAX_NBANDS * sizeof( Word32 ) ) ) == NULL ) + IF( ( hDirAC->direction_vector_m_fx[i][j] = (Word32 *) malloc( DIRAC_MAX_NBANDS * sizeof( Word32 ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); } set32_fx( hDirAC->direction_vector_m_fx[i][j], 0, DIRAC_MAX_NBANDS ); } -#endif } - hDirAC->no_col_avg_diff = (int16_t) ( DIRAC_NO_COL_AVG_DIFF_NS / dirac_slot_ns ); - for ( i = 0; i < DIRAC_NUM_DIMS; i++ ) - { - if ( ( hDirAC->buffer_intensity_real[i] = (float **) malloc( hDirAC->no_col_avg_diff * sizeof( float * ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); - } - for ( j = 0; j < hDirAC->no_col_avg_diff; j++ ) - { - if ( ( hDirAC->buffer_intensity_real[i][j] = (float *) malloc( DIRAC_MAX_NBANDS * sizeof( float ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); - } - set_f( hDirAC->buffer_intensity_real[i][j], 0.0f, DIRAC_MAX_NBANDS ); - } - } + Word16 tmp_e = 0; + move16(); + Word16 tmp = BASOP_Util_Divide3232_Scale( (Word32) DIRAC_NO_COL_AVG_DIFF_NS, dirac_slot_ns, &tmp_e ); + hDirAC->no_col_avg_diff = shr( tmp, sub( 15, tmp_e ) ); + + set16_fx( (Word16 *) hDirAC->buffer_energy_q, 0, DIRAC_NO_COL_AVG_DIFF * DIRAC_MAX_NBANDS ); + set16_fx( (Word16 *) hDirAC->buffer_intensity_real_q, 0, DIRAC_NUM_DIMS * DIRAC_NO_COL_AVG_DIFF * DIRAC_MAX_NBANDS ); - if ( ( hDirAC->buffer_energy = (float *) malloc( DIRAC_MAX_NBANDS * hDirAC->no_col_avg_diff * sizeof( float ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); - } - set_f( hDirAC->buffer_energy, 0.0f, DIRAC_MAX_NBANDS * hDirAC->no_col_avg_diff ); -#ifdef IVAS_FLOAT_FIXED FOR( i = 0; i < DIRAC_NUM_DIMS; i++ ) { IF( ( hDirAC->buffer_intensity_real_fx[i] = (Word32 **) malloc( hDirAC->no_col_avg_diff * sizeof( Word32 * ) ) ) == NULL ) @@ -191,6 +163,7 @@ ivas_error ivas_dirac_enc_open( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); } set32_fx( hDirAC->buffer_intensity_real_fx[i][j], 0, DIRAC_MAX_NBANDS ); + set16_fx( hDirAC->buffer_intensity_real_q[i][j], Q31, hDirAC->hConfig->nbands ); } } @@ -199,23 +172,28 @@ ivas_error ivas_dirac_enc_open( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); } set32_fx( hDirAC->buffer_energy_fx, 0, DIRAC_MAX_NBANDS * hDirAC->no_col_avg_diff ); -#endif + set16_fx( hDirAC->buffer_energy_q, Q31, DIRAC_MAX_NBANDS * hDirAC->no_col_avg_diff ); - if ( st_ivas->hQMetaData->useLowerRes ) + IF( st_ivas->hQMetaData->useLowerRes ) { hDirAC->block_grouping[0] = 0; hDirAC->block_grouping[1] = MAX_PARAM_SPATIAL_SUBFRAMES; + move16(); + move16(); } - else + ELSE { - mvs2s( DirAC_block_grouping_5ms_MDFT, hDirAC->block_grouping, MAX_PARAM_SPATIAL_SUBFRAMES + 1 ); + Copy( DirAC_block_grouping_5ms_MDFT, hDirAC->block_grouping, MAX_PARAM_SPATIAL_SUBFRAMES + 1 ); } hDirAC->index_buffer_intensity = 0; hDirAC->mono_frame_count = 0; + move16(); + move16(); st_ivas->hDirAC = hDirAC; st_ivas->hSpar->enc_param_start_band = st_ivas->hDirAC->hConfig->enc_param_start_band; + move16(); return error; } @@ -414,7 +392,66 @@ ivas_error ivas_dirac_enc_reconfigure( * * Close DirAC encoder handle *------------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +void ivas_dirac_enc_close_fx( + DIRAC_ENC_HANDLE *hDirAC_out, /* i/o: encoder DirAC handle */ + const Word32 input_Fs /* i : input sampling rate */ +) +{ + Word16 i, j; + DIRAC_ENC_HANDLE hDirAC; + IF( hDirAC_out == NULL || *hDirAC_out == NULL ) + { + return; + } + + hDirAC = *hDirAC_out; + + IF( hDirAC->hFbMixer != NULL ) + { + ivas_FB_mixer_close( &hDirAC->hFbMixer, input_Fs, 0 ); + } + /* intensity 3-dim */ + FOR( i = 0; i < DIRAC_NUM_DIMS; i++ ) + { + FOR( j = 0; j < MAX_PARAM_SPATIAL_SUBFRAMES; j++ ) + { + free( hDirAC->direction_vector_m_fx[i][j] ); + hDirAC->direction_vector_m_fx[i][j] = NULL; + } + + FOR( j = 0; j < hDirAC->no_col_avg_diff; j++ ) + { + IF( hDirAC->buffer_intensity_real_fx[i][j] != 0 ) + { + free( hDirAC->buffer_intensity_real_fx[i][j] ); + hDirAC->buffer_intensity_real_fx[i][j] = NULL; + } + } + + free( hDirAC->buffer_intensity_real_fx[i] ); + hDirAC->buffer_intensity_real_fx[i] = NULL; + + free( hDirAC->direction_vector_m_fx[i] ); + hDirAC->direction_vector_m_fx[i] = NULL; + } + + free( hDirAC->buffer_energy_fx ); + hDirAC->buffer_energy_fx = NULL; + + IF( hDirAC->hConfig != NULL ) + { + free( hDirAC->hConfig ); + hDirAC->hConfig = NULL; + } + + free( *hDirAC_out ); + *hDirAC_out = NULL; + + return; +} +#else void ivas_dirac_enc_close( DIRAC_ENC_HANDLE *hDirAC_out, /* i/o: encoder DirAC handle */ const int32_t input_Fs /* i : input sampling rate */ @@ -439,14 +476,16 @@ void ivas_dirac_enc_close( { for ( j = 0; j < MAX_PARAM_SPATIAL_SUBFRAMES; j++ ) { +#ifndef IVAS_FLOAT_FIXED free( hDirAC->direction_vector_m[i][j] ); hDirAC->direction_vector_m[i][j] = NULL; -#ifdef IVAS_FLOAT_FIXED +#else free( hDirAC->direction_vector_m_fx[i][j] ); hDirAC->direction_vector_m_fx[i][j] = NULL; #endif } +#ifndef IVAS_FLOAT_FIXED for ( j = 0; j < hDirAC->no_col_avg_diff; j++ ) { if ( hDirAC->buffer_intensity_real[i][j] != 0 ) @@ -459,7 +498,7 @@ void ivas_dirac_enc_close( free( hDirAC->buffer_intensity_real[i] ); hDirAC->buffer_intensity_real[i] = NULL; -#ifdef IVAS_FLOAT_FIXED +#else FOR( j = 0; j < hDirAC->no_col_avg_diff; j++ ) { IF( hDirAC->buffer_intensity_real_fx[i][j] != 0 ) @@ -473,16 +512,22 @@ void ivas_dirac_enc_close( hDirAC->buffer_intensity_real_fx[i] = NULL; #endif +#ifndef IVAS_FLOAT_FIXED free( hDirAC->direction_vector_m[i] ); hDirAC->direction_vector_m[i] = NULL; -#ifdef IVAS_FLOAT_FIXED +#else free( hDirAC->direction_vector_m_fx[i] ); hDirAC->direction_vector_m_fx[i] = NULL; #endif } +#ifndef IVAS_FLOAT_FIXED free( hDirAC->buffer_energy ); hDirAC->buffer_energy = NULL; +#else + free( hDirAC->buffer_energy_fx ); + hDirAC->buffer_energy_fx = NULL; +#endif if ( hDirAC->hConfig != NULL ) { @@ -495,7 +540,7 @@ void ivas_dirac_enc_close( return; } - +#endif /*------------------------------------------------------------------------- * ivas_dirac_enc() @@ -505,178 +550,30 @@ void ivas_dirac_enc_close( *------------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED -ivas_error ivas_dirac_enc( - DIRAC_ENC_HANDLE hDirAC, /* i/o: encoder DirAC handle */ - IVAS_QMETADATA_HANDLE hQMetaData, /* i/o: q_metadata handle */ - BSTR_ENC_HANDLE hMetaData, /* i/o: Metadata bitstream handle */ - float *data_f[], /* i/o: SBA channels */ - float **ppIn_FR_real, /* o : real freq domain values */ - float **ppIn_FR_imag, /* o : imag freq domain values */ - const int16_t input_frame, /* i : input frame length */ - const int16_t dtx_vad, /* i : DTX vad flag */ - const IVAS_FORMAT ivas_format, /* i : ivas format */ - const int16_t hodirac_flag /* i : hodirac flag */ +ivas_error ivas_dirac_enc_fx( + DIRAC_ENC_HANDLE hDirAC, /* i/o: encoder DirAC handle */ + IVAS_QMETADATA_HANDLE hQMetaData, /* i/o: q_metadata handle */ + BSTR_ENC_HANDLE hMetaData, /* i/o: Metadata bitstream handle */ + Word32 *data_f_fx[], /* i/o: SBA channels Qx */ + Word32 **pp_fr_real_fx, /* o : real freq domain values pp_fr_q */ + Word32 **pp_fr_imag_fx, /* o : imag freq domain values pp_fr_q */ + Word16 pp_fr_q, + const Word16 input_frame, /* i : input frame length Q0 */ + const Word16 dtx_vad, /* i : DTX vad flag Q0 */ + const IVAS_FORMAT ivas_format, /* i : ivas format */ + const Word16 hodirac_flag /* i : hodirac flag Q0 */ ) { - int16_t orig_dirac_bands; - float dir[3], avg_dir[3]; -#ifdef IVAS_FLOAT_FIXED + Word16 orig_dirac_bands; Word32 dir_fx[3], avg_dir_fx[3]; -#endif - float energySum, vecLen; - int16_t i, j, b, i_ts; + Word16 i, j, b, i_ts; ivas_error error; push_wmops( "ivas_dirac_enc" ); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - /*---------------------------------------------- float to fixed ----------------------------------------------*/ - - set16_fx( (Word16 *) hDirAC->buffer_energy_q, 0, DIRAC_NO_COL_AVG_DIFF * DIRAC_MAX_NBANDS ); - set16_fx( (Word16 *) hDirAC->buffer_intensity_real_q, 0, DIRAC_NUM_DIMS * DIRAC_NO_COL_AVG_DIFF * DIRAC_MAX_NBANDS ); - Word16 block_m_idx; - Word16 band_m_idx; Word16 nchan_fb_in = hodirac_flag ? HOA2_CHANNELS : FOA_CHANNELS; - Word16 nblocks = hQMetaData->useLowerRes ? 1 : MAX_PARAM_SPATIAL_SUBFRAMES; - - /* Find Q-factor */ - Word16 pcm_q; - Word16 pp_fr_q; - float max_val = 0; - for ( i = 0; i < nchan_fb_in; i++ ) - { - for ( j = 0; j < input_frame; j++ ) - { - max_val = max( max_val, (float) fabs( data_f[i][j] ) ); - } - } - pcm_q = Q_factor_L( max_val ); - - max_val = 0; - for ( i = 0; i < nchan_fb_in; i++ ) - { - for ( j = 0; j < input_frame; j++ ) - { - max_val = max( max_val, (float) fabs( ppIn_FR_real[i][j] ) ); - max_val = max( max_val, (float) fabs( ppIn_FR_imag[i][j] ) ); - } - } - pp_fr_q = Q_factor_L( max_val ); - - Word32 fr_real_fx[DIRAC_MAX_ANA_CHANS][L_FRAME48k * 2]; - Word32 fr_imag_fx[DIRAC_MAX_ANA_CHANS][L_FRAME48k * 2]; - Word32 data_f_buf[DIRAC_MAX_ANA_CHANS][L_FRAME48k]; - Word32 *pp_fr_real_fx[DIRAC_MAX_ANA_CHANS]; - Word32 *pp_fr_imag_fx[DIRAC_MAX_ANA_CHANS]; - Word32 *data_f_fx[DIRAC_MAX_ANA_CHANS]; - for ( i = 0; i < nchan_fb_in; i++ ) - { - data_f_fx[i] = data_f_buf[i]; - pp_fr_real_fx[i] = fr_real_fx[i]; - pp_fr_imag_fx[i] = fr_imag_fx[i]; - for ( j = 0; j < input_frame; j++ ) - { - data_f_fx[i][j] = float_to_fix( data_f[i][j], pcm_q ); - pp_fr_real_fx[i][j] = float_to_fix( ppIn_FR_real[i][j], pp_fr_q ); - pp_fr_imag_fx[i][j] = float_to_fix( ppIn_FR_imag[i][j], pp_fr_q ); - } - } - - for ( i = 0; i < DIRAC_NUM_DIMS; i++ ) - { - for ( j = 0; j < hDirAC->no_col_avg_diff; j++ ) - { - for ( int k = 0; k < hDirAC->hConfig->nbands; k++ ) - { - Word16 tmp; - f2me( hDirAC->buffer_intensity_real[i][j][k], &hDirAC->buffer_intensity_real_fx[i][j][k], &tmp ); - hDirAC->buffer_intensity_real_q[i][j][k] = 31 - tmp; - } - } - } - for ( i = 0; i < hDirAC->hConfig->nbands; i++ ) - { - for ( j = 0; j < hDirAC->no_col_avg_diff; j++ ) - { - Word16 tmp; - f2me( hDirAC->buffer_energy[i + j * hDirAC->hConfig->nbands], &hDirAC->buffer_energy_fx[i + j * hDirAC->hConfig->nbands], &tmp ); - hDirAC->buffer_energy_q[i + j * hDirAC->hConfig->nbands] = 31 - tmp; - } - } + move16(); - for ( i = 0; i < NUM_ANA_SECTORS * IVAS_MAX_NUM_BANDS; i++ ) - { - hDirAC->azi_prev_fx[i] = float_to_fix( hDirAC->azi_prev[i], Q23 ); - hDirAC->ele_prev_fx[i] = float_to_fix( hDirAC->ele_prev[i], Q23 ); - } - for ( i = 0; i < NUM_ANA_SECTORS; i++ ) - { - for ( j = 0; j < IVAS_MAX_NUM_BANDS; j++ ) - { - f2me( hDirAC->sec_I_vec_smth_x[i][j], &hDirAC->sec_I_vec_smth_x_fx[i][j], &hDirAC->sec_I_vec_smth_x_exp[i][j] ); - f2me( hDirAC->sec_I_vec_smth_y[i][j], &hDirAC->sec_I_vec_smth_y_fx[i][j], &hDirAC->sec_I_vec_smth_y_exp[i][j] ); - f2me( hDirAC->sec_I_vec_smth_z[i][j], &hDirAC->sec_I_vec_smth_z_fx[i][j], &hDirAC->sec_I_vec_smth_z_exp[i][j] ); - } - } -#endif ivas_dirac_param_est_enc( hDirAC, hQMetaData->q_direction, hQMetaData->useLowerRes, data_f_fx, pp_fr_real_fx, pp_fr_imag_fx, pp_fr_q, input_frame, ivas_format, hodirac_flag, nchan_fb_in, &( hDirAC->mono_frame_count ), &( hQMetaData->dirac_mono_flag ) ); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - /*---------------------------------------------- fixed to float ----------------------------------------------*/ - for ( block_m_idx = 0; block_m_idx < nblocks; block_m_idx++ ) - { - for ( band_m_idx = 0; band_m_idx < hDirAC->hConfig->nbands; band_m_idx++ ) - { - if ( hodirac_flag ) - { - hQMetaData->q_direction[1].band_data[band_m_idx].energy_ratio[block_m_idx] = fix_to_float( hQMetaData->q_direction[1].band_data[band_m_idx].energy_ratio_fx[block_m_idx], Q30 ); - } - else - { - hDirAC->direction_vector_m[0][block_m_idx][band_m_idx] = me2f( hDirAC->direction_vector_m_fx[0][block_m_idx][band_m_idx], hDirAC->direction_vector_m_exp[block_m_idx] ); - hDirAC->direction_vector_m[1][block_m_idx][band_m_idx] = me2f( hDirAC->direction_vector_m_fx[1][block_m_idx][band_m_idx], hDirAC->direction_vector_m_exp[block_m_idx] ); - hDirAC->direction_vector_m[2][block_m_idx][band_m_idx] = me2f( hDirAC->direction_vector_m_fx[2][block_m_idx][band_m_idx], hDirAC->direction_vector_m_exp[block_m_idx] ); - } - } - } - const int N_bands = hDirAC->hConfig->nbands; - for ( int i_sec = 0; i_sec < NUM_ANA_SECTORS; i_sec++ ) - { - for ( int i_band = 0; i_band < IVAS_MAX_NUM_BANDS; i_band++ ) - { - hDirAC->sec_I_vec_smth_x[i_sec][i_band] = me2f( hDirAC->sec_I_vec_smth_x_fx[i_sec][i_band], hDirAC->sec_I_vec_smth_x_exp[i_sec][i_band] ); - hDirAC->sec_I_vec_smth_y[i_sec][i_band] = me2f( hDirAC->sec_I_vec_smth_y_fx[i_sec][i_band], hDirAC->sec_I_vec_smth_y_exp[i_sec][i_band] ); - hDirAC->sec_I_vec_smth_z[i_sec][i_band] = me2f( hDirAC->sec_I_vec_smth_z_fx[i_sec][i_band], hDirAC->sec_I_vec_smth_z_exp[i_sec][i_band] ); - hDirAC->azi_prev[i_sec * N_bands + i_band] = fix_to_float( hDirAC->azi_prev_fx[i_sec * N_bands + i_band], Q23 ); - hDirAC->ele_prev[i_sec * N_bands + i_band] = fix_to_float( hDirAC->ele_prev_fx[i_sec * N_bands + i_band], Q23 ); - } - for ( int i_band = hDirAC->hConfig->enc_param_start_band; i_band < N_bands; i_band++ ) - { - hDirAC->energy_smth[i_sec][i_band] = me2f( hDirAC->energy_smth_fx[i_sec][i_band], hDirAC->energy_smth_exp[i_sec][i_band] ); - } - } - for ( band_m_idx = 0; band_m_idx < hDirAC->hConfig->nbands; band_m_idx++ ) - { - hDirAC->diffuseness_m[band_m_idx] = me2f( hDirAC->diffuseness_m_fx[band_m_idx], hDirAC->diffuseness_m_exp[band_m_idx] ); - me2f_buf( hQMetaData->q_direction->band_data[band_m_idx].energy_ratio_fx, 1, hQMetaData->q_direction->band_data[band_m_idx].energy_ratio, hQMetaData->q_direction->cfg.nblocks ); - } - for ( i = 0; i < DIRAC_NUM_DIMS; i++ ) - { - for ( j = 0; j < hDirAC->no_col_avg_diff; j++ ) - { - for ( int k = 0; k < N_bands; k++ ) - { - hDirAC->buffer_intensity_real[i][j][k] = me2f( hDirAC->buffer_intensity_real_fx[i][j][k], 31 - hDirAC->buffer_intensity_real_q[i][j][k] ); - } - } - } - for ( i = 0; i < hDirAC->hConfig->nbands; i++ ) - { - for ( j = 0; j < hDirAC->no_col_avg_diff; j++ ) - { - hDirAC->buffer_energy[i + j * hDirAC->hConfig->nbands] = me2f( hDirAC->buffer_energy_fx[i + j * hDirAC->hConfig->nbands], 31 - hDirAC->buffer_energy_q[i + j * hDirAC->hConfig->nbands] ); - } - } -#endif - IF( hQMetaData->q_direction->cfg.nbands > 0 ) { @@ -690,19 +587,18 @@ ivas_error ivas_dirac_enc( /* Set Energy Ratio to 0.0 if the mono flag is set, before the metadata is encoded */ IF( hQMetaData->dirac_mono_flag ) { -#ifdef IVAS_FLOAT_FIXED IF( EQ_16( dtx_vad, 1 ) ) { FOR( b = hQMetaData->q_direction->cfg.start_band; b < hQMetaData->q_direction->cfg.nbands; b++ ) { FOR( i_ts = 0; i_ts < hQMetaData->q_direction[0].cfg.nblocks; i_ts++ ) { -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - hQMetaData->q_direction[0].band_data[b].energy_ratio[i_ts] = 0.0f; -#endif hQMetaData->q_direction[0].band_data[b].energy_ratio_fx[i_ts] = 0; hQMetaData->q_direction[0].band_data[b].azimuth_fx[i_ts] = 0; hQMetaData->q_direction[0].band_data[b].elevation_fx[i_ts] = 0; + move32(); + move32(); + move32(); } } } @@ -712,136 +608,112 @@ ivas_error ivas_dirac_enc( { FOR( i_ts = 0; i_ts < 1; i_ts++ ) { -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - hQMetaData->q_direction[0].band_data[b].energy_ratio[i_ts] = 0.0f; -#endif hQMetaData->q_direction[0].band_data[b].energy_ratio_fx[i_ts] = 0; hQMetaData->q_direction[0].band_data[b].azimuth_fx[i_ts] = 0; hQMetaData->q_direction[0].band_data[b].elevation_fx[i_ts] = 0; + move32(); + move32(); + move32(); } } } - -#else - for ( b = hQMetaData->q_direction->cfg.start_band; b < hQMetaData->q_direction->cfg.nbands; b++ ) - { - for ( i_ts = 0; i_ts < ( ( dtx_vad == 1 ) ? hQMetaData->q_direction[0].cfg.nblocks : 1 ); i_ts++ ) - { - hQMetaData->q_direction[0].band_data[b].energy_ratio[i_ts] = 0.0f; - hQMetaData->q_direction[0].band_data[b].azimuth[i_ts] = 0.0f; - hQMetaData->q_direction[0].band_data[b].elevation[i_ts] = 0.0f; - } - } -#endif } -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - for ( i = 0; i < hQMetaData->no_directions; i++ ) - { - for ( j = hQMetaData->q_direction[0].cfg.start_band; j < hQMetaData->q_direction[0].cfg.nbands; ++j ) - { - floatToFixed_arrL( hQMetaData->q_direction[i].band_data[j].energy_ratio, hQMetaData->q_direction[i].band_data[j].energy_ratio_fx, Q30, MAX_PARAM_SPATIAL_SUBFRAMES ); -#ifndef MSAN_FIX - floatToFixed_arrL( hQMetaData->q_direction[i].band_data[j].q_azimuth, hQMetaData->q_direction[i].band_data[j].q_azimuth_fx, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); - floatToFixed_arrL( hQMetaData->q_direction[i].band_data[j].q_elevation, hQMetaData->q_direction[i].band_data[j].q_elevation_fx, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); -#endif - } - } -#endif IF( ( error = ivas_qmetadata_enc_encode_fx( hMetaData, hQMetaData, hodirac_flag ) ) != IVAS_ERR_OK ) { return error; } -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - for ( i = 0; i < hQMetaData->no_directions; i++ ) - { - for ( j = hQMetaData->q_direction[0].cfg.start_band; j < hQMetaData->q_direction[0].cfg.nbands; ++j ) - { - fixedToFloat_arrL( hQMetaData->q_direction[i].band_data[j].energy_ratio_fx, hQMetaData->q_direction[i].band_data[j].energy_ratio, Q30, MAX_PARAM_SPATIAL_SUBFRAMES ); - } - } -#endif } ELSE { hQMetaData->q_direction[0].cfg.nbands = DIRAC_DTX_BANDS; move16(); - /* compute directions */ - for ( i = 0; i < hQMetaData->q_direction[0].cfg.nblocks; i++ ) + FOR( i = 0; i < hQMetaData->q_direction[0].cfg.nblocks; i++ ) { - set_zero( dir, 3 ); - set_zero( avg_dir, 3 ); - energySum = 0.0f; + set32_fx( avg_dir_fx, 0, 3 ); + Word16 avg_dir_e = 0; + Word16 energySum_e = 0; + Word32 energySum_fx = 0; + move32(); + move16(); + move16(); /* combine all DirAC bands except the last one, handle last band separately, last band covers BW above WB */ - for ( j = 0; j < orig_dirac_bands - 1; j++ ) + FOR( j = 0; j < sub( orig_dirac_bands, 1 ); j++ ) { -#ifdef IVAS_FLOAT_FIXED ivas_qmetadata_azimuth_elevation_to_direction_vector_fx( hQMetaData->q_direction[0].band_data[j].azimuth_fx[i], hQMetaData->q_direction[0].band_data[j].elevation_fx[i], &dir_fx[0] ); - /*==========================================fix-2-flt======================================================*/ - fixedToFloat_arrL( dir_fx, dir, Q30, 3 ); - /*==========================================fix-2-flt======================================================*/ - -#else - ivas_qmetadata_azimuth_elevation_to_direction_vector( hQMetaData->q_direction[0].band_data[j].azimuth[i], hQMetaData->q_direction[0].band_data[j].elevation[i], &dir[0] ); -#endif - vecLen = hQMetaData->q_direction[0].band_data[j].energy_ratio[i] * hDirAC->buffer_energy[i * orig_dirac_bands + j]; - - avg_dir[0] += dir[0] * vecLen; - avg_dir[1] += dir[1] * vecLen; - avg_dir[2] += dir[2] * vecLen; - - energySum += hDirAC->buffer_energy[i * orig_dirac_bands + j]; + Word32 vecLen_fx = Mpy_32_32( hQMetaData->q_direction[0].band_data[j].energy_ratio_fx[i] /*Q30*/, hDirAC->buffer_energy_fx[i * orig_dirac_bands + j] ); + avg_dir_fx[0] = L_add( avg_dir_fx[0], Mpy_32_32( dir_fx[0], vecLen_fx ) ); // Q30 + hDirAC->buffer_energy_q[i * orig_dirac_bands + j] - 1 - 31 + avg_dir_fx[1] = L_add( avg_dir_fx[1], Mpy_32_32( dir_fx[1], vecLen_fx ) ); // Q30 + hDirAC->buffer_energy_q[i * orig_dirac_bands + j] - 1 - 31 + avg_dir_fx[2] = L_add( avg_dir_fx[2], Mpy_32_32( dir_fx[2], vecLen_fx ) ); // Q30 + hDirAC->buffer_energy_q[i * orig_dirac_bands + j] - 1 - 31 + move32(); + move32(); + move32(); + avg_dir_e = sub( 31, ( sub( add( Q30, hDirAC->buffer_energy_q[i * orig_dirac_bands + j] ), 1 - 31 ) ) ); + energySum_fx = BASOP_Util_Add_Mant32Exp( energySum_fx, energySum_e, hDirAC->buffer_energy_fx[i * orig_dirac_bands + j], sub( 31, hDirAC->buffer_energy_q[i * orig_dirac_bands + j] ), &energySum_e ); } -#ifdef IVAS_FLOAT_FIXED - /*==========================================flt-2-fix======================================================*/ - Word16 q_dir_e = 0; - f2me_buf( avg_dir, avg_dir_fx, &q_dir_e, 3 ); - Scale_sig32( avg_dir_fx, 3, -1 ); - /*==========================================flt-2-fix======================================================*/ + Word16 x = getScaleFactor32( avg_dir_fx, 3 ); + Scale_sig32( avg_dir_fx, 3, sub( x, 1 ) ); + avg_dir_e = sub( avg_dir_e, sub( x, 1 ) ); ivas_qmetadata_direction_vector_to_azimuth_elevation_fx( &avg_dir_fx[0], Q30, &hQMetaData->q_direction[0].band_data[0].azimuth_fx[i], &hQMetaData->q_direction[0].band_data[0].elevation_fx[i] ); -#else - ivas_qmetadata_direction_vector_to_azimuth_elevation( &avg_dir[0], &hQMetaData->q_direction[0].band_data[0].azimuth[i], &hQMetaData->q_direction[0].band_data[0].elevation[i] ); -#endif - hQMetaData->q_direction[0].band_data[0].energy_ratio[i] = sqrtf( dotp( avg_dir, avg_dir, 3 ) ) / ( energySum + EPSILON ); -#ifdef IVAS_FLOAT_FIXED + Word32 tmp = dotp_fixed( avg_dir_fx, avg_dir_fx, 3 ); // 2*avg_dir_e + Word16 tmp_e = shl( avg_dir_e, 1 ); + tmp = Sqrt32( tmp, &tmp_e ); + Word16 er_tmp_e = 0; + move16(); + Word16 er_tmp = 0; + move16(); + Word16 denom_e = 0; + move16(); + Word32 denom = BASOP_Util_Add_Mant32Exp( energySum_fx, energySum_e, EPSILON_FX_M, EPSILON_FX_E, &denom_e ); + + er_tmp = BASOP_Util_Divide3232_Scale( tmp, denom, &er_tmp_e ); + er_tmp_e = add( er_tmp_e, sub( tmp_e, denom_e ) ); + er_tmp = shr( er_tmp, sub( 1, ( er_tmp_e ) ) ); // Q14 + + hQMetaData->q_direction[0].band_data[0].energy_ratio_fx[i] = L_deposit_h( er_tmp ); // Q30 hQMetaData->q_direction[0].band_data[1].azimuth_fx[i] = hQMetaData->q_direction[0].band_data[orig_dirac_bands - 1].azimuth_fx[i]; hQMetaData->q_direction[0].band_data[1].elevation_fx[i] = hQMetaData->q_direction[0].band_data[orig_dirac_bands - 1].elevation_fx[i]; -#else - hQMetaData->q_direction[0].band_data[1].azimuth[i] = hQMetaData->q_direction[0].band_data[orig_dirac_bands - 1].azimuth[i]; - hQMetaData->q_direction[0].band_data[1].elevation[i] = hQMetaData->q_direction[0].band_data[orig_dirac_bands - 1].elevation[i]; -#endif - hQMetaData->q_direction[0].band_data[1].energy_ratio[i] = hQMetaData->q_direction[0].band_data[orig_dirac_bands - 1].energy_ratio[i]; + hQMetaData->q_direction[0].band_data[1].energy_ratio_fx[i] = hQMetaData->q_direction[0].band_data[orig_dirac_bands - 1].energy_ratio_fx[i]; + move32(); + move32(); + move32(); + move32(); } /* 1 bit to indicate mode MD coding : temp solution*/ push_next_indice( hMetaData, 1, 1 ); /* encode SID parameters */ -#ifdef IVAS_FLOAT_FIXED ivas_qmetadata_enc_sid_encode_fx( hMetaData, hQMetaData, -1, SBA_FORMAT ); -#else - ivas_qmetadata_enc_sid_encode( hMetaData, hQMetaData, -1, SBA_FORMAT ); -#endif } + Word16 len = 0; + move16(); + IF( EQ_16( dtx_vad, 1 ) ) + { + len = hQMetaData->q_direction[0].cfg.nblocks; + } + ELSE + { + len = 1; + } + move16(); FOR( b = hQMetaData->q_direction->cfg.start_band; b < hQMetaData->q_direction->cfg.nbands; b++ ) { - FOR( i_ts = 0; i_ts < ( ( dtx_vad == 1 ) ? hQMetaData->q_direction[0].cfg.nblocks : 1 ); i_ts++ ) + FOR( i_ts = 0; i_ts < len; i_ts++ ) { -#ifdef IVAS_FLOAT_FIXED hQMetaData->q_direction->band_data[b].azimuth_fx[i_ts] = hQMetaData->q_direction->band_data[b].q_azimuth_fx[i_ts]; hQMetaData->q_direction->band_data[b].elevation_fx[i_ts] = hQMetaData->q_direction->band_data[b].q_elevation_fx[i_ts]; -#else - hQMetaData->q_direction->band_data[b].azimuth[i_ts] = hQMetaData->q_direction->band_data[b].q_azimuth[i_ts]; - hQMetaData->q_direction->band_data[b].elevation[i_ts] = hQMetaData->q_direction->band_data[b].q_elevation[i_ts]; -#endif - hQMetaData->q_direction[0].band_data[b].energy_ratio[0] = 1.0f - diffuseness_reconstructions[hQMetaData->q_direction[0].band_data[b].energy_ratio_index[0]]; + hQMetaData->q_direction[0].band_data[b].energy_ratio_fx[0] = L_sub( ONE_IN_Q30, diffuseness_reconstructions_fx[hQMetaData->q_direction[0].band_data[b].energy_ratio_index[0]] ); + move32(); + move32(); + move32(); } } @@ -849,28 +721,24 @@ ivas_error ivas_dirac_enc( { FOR( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) { -#ifdef IVAS_FLOAT_FIXED hQMetaData->q_direction[0].band_data[orig_dirac_bands - 1].azimuth_fx[i] = hQMetaData->q_direction[0].band_data[1].azimuth_fx[0]; hQMetaData->q_direction[0].band_data[orig_dirac_bands - 1].elevation_fx[i] = hQMetaData->q_direction[0].band_data[1].elevation_fx[0]; -#else - hQMetaData->q_direction[0].band_data[orig_dirac_bands - 1].azimuth[i] = hQMetaData->q_direction[0].band_data[1].azimuth[0]; - hQMetaData->q_direction[0].band_data[orig_dirac_bands - 1].elevation[i] = hQMetaData->q_direction[0].band_data[1].elevation[0]; -#endif - hQMetaData->q_direction[0].band_data[orig_dirac_bands - 1].energy_ratio[i] = hQMetaData->q_direction[0].band_data[1].energy_ratio[0]; + hQMetaData->q_direction[0].band_data[orig_dirac_bands - 1].energy_ratio_fx[i] = hQMetaData->q_direction[0].band_data[1].energy_ratio_fx[0]; + move32(); + move32(); + move32(); } FOR( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) { - FOR( j = orig_dirac_bands - 2; j >= 0; j-- ) + FOR( j = sub( orig_dirac_bands, 2 ); j >= 0; j-- ) { -#ifdef IVAS_FLOAT_FIXED hQMetaData->q_direction[0].band_data[j].azimuth_fx[i] = hQMetaData->q_direction[0].band_data[0].azimuth_fx[0]; hQMetaData->q_direction[0].band_data[j].elevation_fx[i] = hQMetaData->q_direction[0].band_data[0].elevation_fx[0]; -#else - hQMetaData->q_direction[0].band_data[j].azimuth[i] = hQMetaData->q_direction[0].band_data[0].azimuth[0]; - hQMetaData->q_direction[0].band_data[j].elevation[i] = hQMetaData->q_direction[0].band_data[0].elevation[0]; -#endif - hQMetaData->q_direction[0].band_data[j].energy_ratio[i] = hQMetaData->q_direction[0].band_data[0].energy_ratio[0]; + hQMetaData->q_direction[0].band_data[j].energy_ratio_fx[i] = hQMetaData->q_direction[0].band_data[0].energy_ratio_fx[0]; + move32(); + move32(); + move32(); } } diff --git a/lib_enc/ivas_enc.c b/lib_enc/ivas_enc.c index c41736176..c3b8c7cbc 100644 --- a/lib_enc/ivas_enc.c +++ b/lib_enc/ivas_enc.c @@ -888,19 +888,6 @@ ivas_error ivas_enc( { return error; } -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - if ( st_ivas->hQMetaData->q_direction ) - { - for ( int band = 0; band < st_ivas->hMasa->config.numCodingBands; band++ ) - { - fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[0].band_data[band].energy_ratio_fx, st_ivas->hQMetaData->q_direction[0].band_data[band].energy_ratio, Q30, MAX_PARAM_SPATIAL_SUBFRAMES ); - if ( st_ivas->hQMetaData->no_directions == 2 ) - { - fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[1].band_data[band].energy_ratio_fx, st_ivas->hQMetaData->q_direction[1].band_data[band].energy_ratio, Q30, MAX_PARAM_SPATIAL_SUBFRAMES ); - } - } - } -#endif // IVAS_FLOAT_FIXED_CONVERSIONS #else if ( ( error = ivas_masa_enc_config( st_ivas ) ) != IVAS_ERR_OK ) { @@ -1000,19 +987,6 @@ ivas_error ivas_enc( { return error; } -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - if ( st_ivas->hQMetaData->q_direction ) - { - for ( int band = 0; band < st_ivas->hMasa->config.numCodingBands; band++ ) - { - fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[0].band_data[band].energy_ratio_fx, st_ivas->hQMetaData->q_direction[0].band_data[band].energy_ratio, Q30, MAX_PARAM_SPATIAL_SUBFRAMES ); - if ( st_ivas->hQMetaData->no_directions == 2 ) - { - fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[1].band_data[band].energy_ratio_fx, st_ivas->hQMetaData->q_direction[1].band_data[band].energy_ratio, Q30, MAX_PARAM_SPATIAL_SUBFRAMES ); - } - } - } -#endif // IVAS_FLOAT_FIXED_CONVERSIONS #else if ( ( error = ivas_omasa_enc_config( st_ivas ) ) != IVAS_ERR_OK ) { @@ -1379,7 +1353,7 @@ ivas_error ivas_enc( { FOR( jj = 0; jj < nBlocks; jj++ ) { - st_ivas->hQMetaData->q_direction[0].band_data[ii].energy_ratio[jj] = fixedToFloat( st_ivas->hQMetaData->q_direction[0].band_data[ii].energy_ratio_fx[jj], Q31 ); + st_ivas->hQMetaData->q_direction[0].band_data[ii].energy_ratio_fx[jj] = L_shr( st_ivas->hQMetaData->q_direction[0].band_data[ii].energy_ratio_fx[jj], 1 ); // Q31 -> Q30 } } #endif diff --git a/lib_enc/ivas_init_enc.c b/lib_enc/ivas_init_enc.c index b40665a98..3114ae478 100644 --- a/lib_enc/ivas_init_enc.c +++ b/lib_enc/ivas_init_enc.c @@ -859,10 +859,17 @@ ivas_error ivas_init_encoder( return error; } +#ifdef IVAS_FLOAT_FIXED + IF( ( error = ivas_dirac_enc_open_fx( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } +#else if ( ( error = ivas_dirac_enc_open( st_ivas ) ) != IVAS_ERR_OK ) { return error; } +#endif } else { @@ -1014,10 +1021,17 @@ ivas_error ivas_init_encoder( return error; } +#ifdef IVAS_FLOAT_FIXED + IF( ( error = ivas_dirac_enc_open_fx( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } +#else if ( ( error = ivas_dirac_enc_open( st_ivas ) ) != IVAS_ERR_OK ) { return error; } +#endif if ( st_ivas->ism_mode == ISM_MODE_NONE ) { @@ -1207,22 +1221,8 @@ ivas_error ivas_init_encoder( { return error; } - -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - if ( st_ivas->hQMetaData->q_direction != NULL ) - { - for ( int band = 0; band < st_ivas->hMasa->config.numCodingBands; band++ ) - { - fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[0].band_data[band].energy_ratio_fx, st_ivas->hQMetaData->q_direction[0].band_data[band].energy_ratio, Q30, MAX_PARAM_SPATIAL_SUBFRAMES ); - if ( st_ivas->hQMetaData->no_directions == 2 ) - { - fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[1].band_data[band].energy_ratio_fx, st_ivas->hQMetaData->q_direction[1].band_data[band].energy_ratio, Q30, MAX_PARAM_SPATIAL_SUBFRAMES ); - } - } - } #endif -#endif // IVAS_FLOAT_FIXED_CONVERSIONS #ifndef IVAS_FLOAT_FIXED ivas_mcmasa_split_brate( st_ivas->hMcMasa->separateChannelEnabled, ivas_total_brate, st_ivas->nSCE, st_ivas->nCPE, &brate_sce, &brate_cpe ); #else @@ -1530,11 +1530,17 @@ ivas_error ivas_init_encoder_fx( { return error; } - +#ifdef IVAS_FLOAT_FIXED + IF( ( error = ivas_dirac_enc_open_fx( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } +#else IF( ( error = ivas_dirac_enc_open( st_ivas ) ) != IVAS_ERR_OK ) { return error; } +#endif } ELSE { @@ -1679,10 +1685,17 @@ ivas_error ivas_init_encoder_fx( return error; } +#ifdef IVAS_FLOAT_FIXED + IF( ( error = ivas_dirac_enc_open_fx( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } +#else if ( ( error = ivas_dirac_enc_open( st_ivas ) ) != IVAS_ERR_OK ) { return error; } +#endif if ( st_ivas->ism_mode == ISM_MODE_NONE ) { @@ -1869,22 +1882,8 @@ ivas_error ivas_init_encoder_fx( { return error; } - -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - if ( st_ivas->hQMetaData->q_direction != NULL ) - { - for ( int band = 0; band < st_ivas->hMasa->config.numCodingBands; band++ ) - { - fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[0].band_data[band].energy_ratio_fx, st_ivas->hQMetaData->q_direction[0].band_data[band].energy_ratio, Q30, MAX_PARAM_SPATIAL_SUBFRAMES ); - if ( st_ivas->hQMetaData->no_directions == 2 ) - { - fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[1].band_data[band].energy_ratio_fx, st_ivas->hQMetaData->q_direction[1].band_data[band].energy_ratio, Q30, MAX_PARAM_SPATIAL_SUBFRAMES ); - } - } - } #endif -#endif // IVAS_FLOAT_FIXED_CONVERSIONS #ifndef IVAS_FLOAT_FIXED ivas_mcmasa_split_brate( st_ivas->hMcMasa->separateChannelEnabled, ivas_total_brate, st_ivas->nSCE, st_ivas->nCPE, &brate_sce, &brate_cpe ); #else @@ -2196,7 +2195,11 @@ void ivas_destroy_enc( ivas_qmetadata_close( &( st_ivas->hQMetaData ) ); /* DirAC handle */ +#ifdef IVAS_FLOAT_FIXED + ivas_dirac_enc_close_fx( &( st_ivas->hDirAC ), st_ivas->hEncoderConfig->input_Fs ); +#else ivas_dirac_enc_close( &( st_ivas->hDirAC ), st_ivas->hEncoderConfig->input_Fs ); +#endif /* ParamISM handle */ ivas_param_ism_enc_close( &( st_ivas->hParamIsm ), st_ivas->hEncoderConfig->input_Fs ); diff --git a/lib_enc/ivas_masa_enc.c b/lib_enc/ivas_masa_enc.c index 5438bc921..a8375d542 100644 --- a/lib_enc/ivas_masa_enc.c +++ b/lib_enc/ivas_masa_enc.c @@ -398,15 +398,6 @@ ivas_error ivas_masa_encode( Word16 guard_bits, tmp; guard_bits = find_guarded_bits_fx( 24 ); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - for ( i = 0; i < hQMetaData->no_directions; i++ ) - { - for ( j = hQMetaData->q_direction[i].cfg.start_band; j < hQMetaData->q_direction[i].cfg.nbands; ++j ) - { - floatToFixed_arrL( hQMetaData->q_direction[i].band_data[j].energy_ratio, hQMetaData->q_direction[i].band_data[j].energy_ratio_fx, Q30, MAX_PARAM_SPATIAL_SUBFRAMES ); - } - } -#endif masa_sid_descriptor = -1; h_orig_metadata = NULL; @@ -859,16 +850,6 @@ ivas_error ivas_masa_encode( move16(); } -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - for ( i = 0; i < hQMetaData->no_directions; i++ ) - { - for ( j = hQMetaData->q_direction[0].cfg.start_band; j < hQMetaData->q_direction[0].cfg.nbands; ++j ) - { - fixedToFloat_arrL( hQMetaData->q_direction[i].band_data[j].energy_ratio_fx, hQMetaData->q_direction[i].band_data[j].energy_ratio, Q30, MAX_PARAM_SPATIAL_SUBFRAMES ); - } - } -#endif - return IVAS_ERR_OK; } #else diff --git a/lib_enc/ivas_mct_enc.c b/lib_enc/ivas_mct_enc.c index aaa3dd260..472043f02 100644 --- a/lib_enc/ivas_mct_enc.c +++ b/lib_enc/ivas_mct_enc.c @@ -1775,19 +1775,6 @@ static ivas_error ivas_mc_enc_reconfig( { return error; } -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - if ( st_ivas->hQMetaData->q_direction != NULL ) - { - for ( int band = 0; band < st_ivas->hMasa->config.numCodingBands; band++ ) - { - fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[0].band_data[band].energy_ratio_fx, st_ivas->hQMetaData->q_direction[0].band_data[band].energy_ratio, Q30, MAX_PARAM_SPATIAL_SUBFRAMES ); - if ( st_ivas->hQMetaData->no_directions == 2 ) - { - fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[1].band_data[band].energy_ratio_fx, st_ivas->hQMetaData->q_direction[1].band_data[band].energy_ratio, Q30, MAX_PARAM_SPATIAL_SUBFRAMES ); - } - } - } -#endif // IVAS_FLOAT_FIXED_CONVERSIONS #else if ( ( error = ivas_mcmasa_enc_open( st_ivas ) ) != IVAS_ERR_OK ) { @@ -1803,19 +1790,6 @@ static ivas_error ivas_mc_enc_reconfig( { return error; } -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - if ( st_ivas->hQMetaData->q_direction != NULL ) - { - for ( int band = 0; band < st_ivas->hMasa->config.numCodingBands; band++ ) - { - fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[0].band_data[band].energy_ratio_fx, st_ivas->hQMetaData->q_direction[0].band_data[band].energy_ratio, Q30, MAX_PARAM_SPATIAL_SUBFRAMES ); - if ( st_ivas->hQMetaData->no_directions == 2 ) - { - fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[1].band_data[band].energy_ratio_fx, st_ivas->hQMetaData->q_direction[1].band_data[band].energy_ratio, Q30, MAX_PARAM_SPATIAL_SUBFRAMES ); - } - } - } -#endif // IVAS_FLOAT_FIXED_CONVERSIONS #else if ( ( error = ivas_mcmasa_enc_reconfig( st_ivas ) ) != IVAS_ERR_OK ) { diff --git a/lib_enc/ivas_spar_encoder.c b/lib_enc/ivas_spar_encoder.c index d7857435a..454b2305f 100644 --- a/lib_enc/ivas_spar_encoder.c +++ b/lib_enc/ivas_spar_encoder.c @@ -705,7 +705,14 @@ static ivas_error ivas_spar_cov_md_process( } ELSE { - ivas_spar_set_bitrate_config( &hSpar->hMdEnc->spar_md_cfg, table_idx, ( hSpar->hMdEnc->spar_hoa_md_flag ) ? IVAS_MAX_NUM_BANDS : SPAR_DIRAC_SPLIT_START_BAND, hSpar->hMdEnc->spar_hoa_dirac2spar_md_flag, 1, hEncoderConfig->Opt_PCA_ON, hSpar->AGC_Enable ); + Word16 num_bands = SPAR_DIRAC_SPLIT_START_BAND; + move16(); + if ( hSpar->hMdEnc->spar_hoa_md_flag != 0 ) + { + num_bands = IVAS_MAX_NUM_BANDS; + move16(); + } + ivas_spar_set_bitrate_config( &hSpar->hMdEnc->spar_md_cfg, table_idx, num_bands, hSpar->hMdEnc->spar_hoa_dirac2spar_md_flag, 1, hEncoderConfig->Opt_PCA_ON, hSpar->AGC_Enable ); } } @@ -737,9 +744,9 @@ static ivas_error ivas_spar_cov_md_process( FOR( b = hSpar->hFbMixer->pFb->filterbank_num_bands; b < IVAS_MAX_NUM_BANDS; b++ ) { cov_real_fx[i][j][b] = 0; - move16(); + move32(); cov_dtx_real_fx[i][j][b] = 0; - move16(); + move32(); } } IF( ( q_cov_real[i] = (Word16 *) malloc( sizeof( Word16 ) * nchan_inp ) ) == NULL ) @@ -810,7 +817,7 @@ static ivas_error ivas_spar_cov_md_process( IF( hSpar->hMdEnc->spar_hoa_md_flag == 0 ) { - IF( NE_32( ( error = ivas_spar_md_enc_process_fx( hSpar->hMdEnc, hEncoderConfig, cov_real, cov_dtx_real, cov_real_fx, hSpar->hCovEnc->pCov_state->q_cov_real_per_band, cov_dtx_real_fx, hSpar->hCovEnc->pCov_dtx_state->q_cov_real_per_band, hMetaData, dtx_vad, nchan_inp, sba_order, hSpar->hFbMixer->prior_mixer, *dyn_active_w_flag, hQMetaData->dirac_mono_flag ) ), IVAS_ERR_OK ) ) + IF( NE_32( ( error = ivas_spar_md_enc_process_fx( hSpar->hMdEnc, hEncoderConfig, cov_real_fx, hSpar->hCovEnc->pCov_state->q_cov_real_per_band, cov_dtx_real_fx, hSpar->hCovEnc->pCov_dtx_state->q_cov_real_per_band, hMetaData, dtx_vad, nchan_inp, sba_order, hSpar->hFbMixer->prior_mixer, *dyn_active_w_flag, hQMetaData->dirac_mono_flag ) ), IVAS_ERR_OK ) ) { return error; } @@ -847,9 +854,6 @@ static ivas_error ivas_spar_cov_md_process( test(); IF( GE_16( d_start_band, 6 ) && EQ_16( dtx_vad, 1 ) ) { -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - mvr2r( hSpar->hMdEnc->spar_md.band_coeffs[d_start_band - 1].P_quant_re, hSpar->hMdEnc->spar_md.band_coeffs[d_start_band - 1].P_re, IVAS_SPAR_MAX_CH - 1 ); -#endif Copy32( hSpar->hMdEnc->spar_md.band_coeffs[d_start_band - 1].P_quant_re_fx, hSpar->hMdEnc->spar_md.band_coeffs[d_start_band - 1].P_re_fx, IVAS_SPAR_MAX_CH - 1 ); } @@ -928,26 +932,21 @@ static ivas_error ivas_spar_cov_md_process( #ifdef IVAS_FLOAT_FIXED_CONVERSIONS for ( b = 0; b < IVAS_MAX_NUM_BANDS; b++ ) { - for ( i = 0; i < num_ch; i++ ) + for ( i = 0; i < IVAS_SPAR_MAX_CH - 1; i++ ) { - for ( j = 0; j < num_ch; j++ ) - { - hSpar->hMdEnc->mixer_mat[i][j][b] = fixedToFloat_32( hSpar->hMdEnc->mixer_mat_fx[i][j][b], hSpar->hMdEnc->q_mixer_mat_fx ); - } + hSpar->hMdEnc->spar_md.band_coeffs[b].P_re_fx[i] = L_shl( hSpar->hMdEnc->spar_md.band_coeffs[b].P_re_fx[i], Q6 ); + hSpar->hMdEnc->spar_md.band_coeffs[b].pred_re_fx[i] = L_shl( hSpar->hMdEnc->spar_md.band_coeffs[b].pred_re_fx[i], Q6 ); } + hSpar->hMdEnc->spar_md.band_coeffs[b].q_P_re_fx = Q28; + hSpar->hMdEnc->spar_md.band_coeffs[b].q_pred_re_fx = Q28; } for ( b = 0; b < IVAS_MAX_NUM_BANDS; b++ ) { - for ( i = 0; i < IVAS_SPAR_MAX_CH - 1; i++ ) - { - hSpar->hMdEnc->spar_md.band_coeffs[b].P_re[i] = fixedToFloat_32( hSpar->hMdEnc->spar_md.band_coeffs[b].P_re_fx[i], hSpar->hMdEnc->spar_md.band_coeffs[b].q_P_re_fx ); - hSpar->hMdEnc->spar_md.band_coeffs[b].pred_re[i] = fixedToFloat_32( hSpar->hMdEnc->spar_md.band_coeffs[b].pred_re_fx[i], hSpar->hMdEnc->spar_md.band_coeffs[b].q_pred_re_fx ); - } - for ( i = 0; i < IVAS_SPAR_MAX_CH - IVAS_SPAR_MAX_DMX_CHS; i++ ) + for ( i = 0; i < num_ch; i++ ) { - for ( j = 0; j < IVAS_SPAR_MAX_DMX_CHS - 1; j++ ) + for ( j = 0; j < num_ch; j++ ) { - hSpar->hMdEnc->spar_md.band_coeffs[b].C_re[i][j] = fixedToFloat_32( hSpar->hMdEnc->spar_md.band_coeffs[b].C_re_fx[i][j], hSpar->hMdEnc->spar_md.band_coeffs[b].q_C_re_fx ); + hSpar->hMdEnc->mixer_mat[i][j][b] = fixedToFloat_32( hSpar->hMdEnc->mixer_mat_fx[i][j][b], hSpar->hMdEnc->q_mixer_mat_fx ); } } } @@ -959,7 +958,7 @@ static ivas_error ivas_spar_cov_md_process( IF( hSpar->hMdEnc->spar_hoa_md_flag ) { - error = ivas_spar_md_enc_process_fx( hSpar->hMdEnc, hEncoderConfig, cov_real, cov_dtx_real, cov_real_fx, hSpar->hCovEnc->pCov_state->q_cov_real_per_band, cov_dtx_real_fx, hSpar->hCovEnc->pCov_dtx_state->q_cov_real_per_band, hMetaData, dtx_vad, nchan_inp, sba_order, hSpar->hFbMixer->prior_mixer, *dyn_active_w_flag, hQMetaData->dirac_mono_flag ); + error = ivas_spar_md_enc_process_fx( hSpar->hMdEnc, hEncoderConfig, cov_real_fx, hSpar->hCovEnc->pCov_state->q_cov_real_per_band, cov_dtx_real_fx, hSpar->hCovEnc->pCov_dtx_state->q_cov_real_per_band, hMetaData, dtx_vad, nchan_inp, sba_order, hSpar->hFbMixer->prior_mixer, *dyn_active_w_flag, hQMetaData->dirac_mono_flag ); } return error; @@ -1273,10 +1272,62 @@ static ivas_error ivas_spar_enc_process( hodirac_flag = ivas_get_hodirac_flag( ivas_total_brate, st_ivas->sba_analysis_order ); #endif +#ifdef IVAS_FLOAT_FIXED +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + Word16 pcm_q; + Word16 pp_fr_q; + float max_val = 0.0f; + /* Find Q-factor */ + for ( i = 0; i < nchan_fb_in; i++ ) + { + for ( j = 0; j < input_frame; j++ ) + { + max_val = max( max_val, (float) fabs( data_f[i][j] ) ); + } + } + pcm_q = Q_factor_L( max_val ); + + max_val = 0; + for ( i = 0; i < nchan_fb_in; i++ ) + { + for ( j = 0; j < input_frame; j++ ) + { + max_val = max( max_val, (float) fabs( ppIn_FR_real[i][j] ) ); + max_val = max( max_val, (float) fabs( ppIn_FR_imag[i][j] ) ); + } + } + pp_fr_q = Q_factor_L( max_val ); + + Word32 fr_real_fx[DIRAC_MAX_ANA_CHANS][L_FRAME48k * 2]; + Word32 fr_imag_fx[DIRAC_MAX_ANA_CHANS][L_FRAME48k * 2]; + Word32 data_f_buf[DIRAC_MAX_ANA_CHANS][L_FRAME48k]; + Word32 *pp_fr_real_fx[DIRAC_MAX_ANA_CHANS]; + Word32 *pp_fr_imag_fx[DIRAC_MAX_ANA_CHANS]; + Word32 *data_f_fx[DIRAC_MAX_ANA_CHANS]; + for ( i = 0; i < nchan_fb_in; i++ ) + { + data_f_fx[i] = data_f_buf[i]; + pp_fr_real_fx[i] = fr_real_fx[i]; + pp_fr_imag_fx[i] = fr_imag_fx[i]; + for ( j = 0; j < input_frame; j++ ) + { + data_f_fx[i][j] = float_to_fix( data_f[i][j], pcm_q ); + pp_fr_real_fx[i][j] = float_to_fix( ppIn_FR_real[i][j], pp_fr_q ); + pp_fr_imag_fx[i][j] = float_to_fix( ppIn_FR_imag[i][j], pp_fr_q ); + } + } +#endif + IF( ( error = ivas_dirac_enc_fx( st_ivas->hDirAC, hQMetaData, hMetaData, data_f_fx, pp_fr_real_fx, pp_fr_imag_fx, pp_fr_q, input_frame, dtx_vad, hEncoderConfig->ivas_format, hodirac_flag ) ) != IVAS_ERR_OK ) + { + return error; + } +#else + if ( ( error = ivas_dirac_enc( st_ivas->hDirAC, hQMetaData, hMetaData, data_f, ppIn_FR_real, ppIn_FR_imag, input_frame, dtx_vad, hEncoderConfig->ivas_format, hodirac_flag ) ) != IVAS_ERR_OK ) { return error; } +#endif /* Set Energy Ratio to 0.0 if the mono flag has been set */ if ( hQMetaData->dirac_mono_flag ) @@ -1285,7 +1336,11 @@ static ivas_error ivas_spar_enc_process( { for ( i_ts = 0; i_ts < ( ( dtx_vad == 1 ) ? hQMetaData->q_direction[0].cfg.nblocks : 1 ); i_ts++ ) { +#ifndef IVAS_FLOAT_FIXED hQMetaData->q_direction[0].band_data[b].energy_ratio[i_ts] = 0.0f; +#else + hQMetaData->q_direction[0].band_data[b].energy_ratio_fx[i_ts] = 0; +#endif } } } @@ -1294,19 +1349,11 @@ static ivas_error ivas_spar_enc_process( * Covariance and MD processing *-----------------------------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - - for ( b = hSpar->enc_param_start_band; b < IVAS_MAX_NUM_BANDS; b++ ) - { - Word16 dirac_band_idx = hSpar->dirac_to_spar_md_bands[b] - hSpar->enc_param_start_band; - hQMetaData->q_direction->band_data[dirac_band_idx].energy_ratio_fx[0] = float_to_fix( hQMetaData->q_direction->band_data[dirac_band_idx].energy_ratio[0], Q30 ); - } -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS for ( int ch_idx = 0; ch_idx < nchan_fb_in; ch_idx++ ) { floatToFixed_arrL32( ppIn_FR_real[ch_idx], ppIn_FR_real_fx[ch_idx], Q14 - gb, input_frame ); floatToFixed_arrL32( ppIn_FR_imag[ch_idx], ppIn_FR_imag_fx[ch_idx], Q14 - gb, input_frame ); } -#endif #endif if ( ( error = ivas_spar_cov_md_process( hEncoderConfig, st_ivas->hSpar, st_ivas->hQMetaData, hMetaData, nchan_inp, sba_order, ppIn_FR_real_fx, ppIn_FR_imag_fx, transient_det, dtx_vad, nchan_transport, &dyn_active_w_flag, Q14 - gb ) ) != IVAS_ERR_OK ) diff --git a/lib_enc/ivas_spar_md_enc.c b/lib_enc/ivas_spar_md_enc.c index 357e52230..1bfa16eaf 100644 --- a/lib_enc/ivas_spar_md_enc.c +++ b/lib_enc/ivas_spar_md_enc.c @@ -135,8 +135,7 @@ static void ivas_quant_p_per_band( ivas_band_coeffs_t *pband_coeffs, ivas_band_c #else static void ivas_quant_p_per_band_fx( ivas_band_coeffs_t *pband_coeffs, ivas_band_coeffs_ind_t *pBand_coeffs_idx, ivas_quant_strat_t *pQs, const Word16 num_ch ); #endif -static void ivas_quant_c_per_band( ivas_band_coeffs_t *pband_coeffs, ivas_band_coeffs_ind_t *pBand_coeffs_idx, ivas_quant_strat_t *pQs, const int16_t ndec, const int16_t ndm ); - +static void ivas_quant_c_per_band_fx( ivas_band_coeffs_t *pband_coeffs, ivas_band_coeffs_ind_t *pBand_coeffs_idx, ivas_quant_strat_t *pQs, const Word16 ndec, const Word16 ndm, const Word16 q_C ); #ifndef IVAS_FLOAT_FIXED static void ivas_quant_pred_coeffs_per_band( ivas_band_coeffs_t *pband_coeffs, ivas_band_coeffs_ind_t *pBand_coeffs_idx, ivas_quant_strat_t *pQs, const int16_t num_ch ); #else @@ -230,7 +229,7 @@ ivas_error ivas_spar_md_enc_open( hMdEnc->q_mixer_mat_fx = 0; #endif - if ( ( error = ivas_spar_md_enc_init( hMdEnc, hEncoderConfig, sba_order ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_spar_md_enc_init_fx( hMdEnc, hEncoderConfig, sba_order ) ) != IVAS_ERR_OK ) { return error; } @@ -438,8 +437,8 @@ ivas_error ivas_spar_md_enc_init( hMdEnc->spar_md.prior_dyn_active_w_flag = 0; - ivas_spar_set_bitrate_config( &hMdEnc->spar_md_cfg, table_idx, ( hMdEnc->spar_hoa_md_flag ) ? IVAS_MAX_NUM_BANDS : SPAR_DIRAC_SPLIT_START_BAND, - hMdEnc->spar_hoa_dirac2spar_md_flag, 1, hEncoderConfig->Opt_PCA_ON, ivas_agc_enc_get_flag( ivas_spar_br_table_consts[table_idx].nchan_transport ) ); + ivas_spar_set_bitrate_config_fx( &hMdEnc->spar_md_cfg, table_idx, ( hMdEnc->spar_hoa_md_flag ) ? IVAS_MAX_NUM_BANDS : SPAR_DIRAC_SPLIT_START_BAND, + hMdEnc->spar_hoa_dirac2spar_md_flag, 1, hEncoderConfig->Opt_PCA_ON, ivas_agc_enc_get_flag( ivas_spar_br_table_consts[table_idx].nchan_transport ) ); /* get FB coefficients */ for ( i = 0; i < IVAS_MAX_NUM_BANDS; i++ ) @@ -498,7 +497,7 @@ ivas_error ivas_spar_md_enc_init( } #endif - ivas_clear_band_coeffs( hMdEnc->spar_md.band_coeffs, IVAS_MAX_NUM_BANDS ); + ivas_clear_band_coeffs_fx( hMdEnc->spar_md.band_coeffs, IVAS_MAX_NUM_BANDS ); ivas_clear_band_coeff_idx( hMdEnc->spar_md.band_coeffs_idx, IVAS_MAX_NUM_BANDS ); ivas_clear_band_coeff_idx( hMdEnc->spar_md_prior.band_coeffs_idx, IVAS_MAX_NUM_BANDS ); ivas_clear_band_coeff_idx( hMdEnc->spar_md_prior.band_coeffs_idx_mapped, IVAS_MAX_NUM_BANDS ); @@ -578,6 +577,19 @@ ivas_error ivas_spar_md_enc_init_fx( } } } +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + FOR( i = 0; i < num_channels; i++ ) + { + FOR( j = 0; j < num_channels; j++ ) + { + FOR( k = 0; k < IVAS_MAX_NUM_BANDS; k++ ) + { + hMdEnc->mixer_mat[i][j][k] = 0.0f; + move32(); + } + } + } +#endif hMdEnc->q_mixer_mat_fx = 0; move16(); ivas_clear_band_coeffs_fx( hMdEnc->spar_md.band_coeffs, IVAS_MAX_NUM_BANDS ); @@ -775,21 +787,17 @@ static void ivas_band_mixing_fx( static void write_metadata_buffer( BSTR_ENC_HANDLE hMetaData_tmp, BSTR_ENC_HANDLE hMetaData, - const int16_t bit_pos_start, - const int16_t next_ind_start ) + const Word16 bit_pos_start, + const Word16 next_ind_start ) { - int16_t i; + Word16 i; - if ( hMetaData->nb_bits_tot > 0 ) + IF( hMetaData->nb_bits_tot > 0 ) { -#ifdef IVAS_FLOAT_FIXED restore_metadata_buffer_fx( hMetaData, next_ind_start, bit_pos_start ); -#else - restore_metadata_buffer( hMetaData, next_ind_start, bit_pos_start ); -#endif } - for ( i = 0; i < hMetaData_tmp->nb_ind_tot; i++ ) + FOR( i = 0; i < hMetaData_tmp->nb_ind_tot; i++ ) { push_next_indice( hMetaData, hMetaData_tmp->ind_list[i].value, hMetaData_tmp->ind_list[i].nb_bits ); } @@ -807,8 +815,6 @@ static void write_metadata_buffer( ivas_error ivas_spar_md_enc_process_fx( ivas_spar_md_enc_state_t *hMdEnc, /* i/o: SPAR MD encoder handle */ const ENCODER_CONFIG_HANDLE hEncoderConfig, /* i : configuration structure */ - float *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], - float *cov_dtx_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], Word32 *cov_real_fx[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], Word16 *cov_real_q[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], Word32 *cov_dtx_real_fx[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], @@ -839,10 +845,6 @@ ivas_error ivas_spar_md_enc_process_fx( Word16 max_num_indices_tmp; Word32 Wscale_fx[IVAS_MAX_NUM_BANDS]; Word16 q_Wscale[IVAS_MAX_NUM_BANDS]; -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - float Wscale[IVAS_MAX_NUM_BANDS]; - float dm_fv_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS]; -#endif /*extra 16 bits for arithmetic coder as overshoot check is after a symbol is written*/ md_indices_allocated = add( hMdEnc->spar_md_cfg.max_bits_per_blk, IVAS_SPAR_ARITH_OVERSHOOT_BITS ); @@ -957,16 +959,6 @@ ivas_error ivas_spar_md_enc_process_fx( bands_bw = 1; move16(); } -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - for ( b = 0; b < num_bands; b++ ) - { - for ( int ii = 0; ii < num_ch - 1; ii++ ) - { - hMdEnc->spar_md.band_coeffs[b].pred_re_fx[ii] = float_to_fix( hMdEnc->spar_md.band_coeffs[b].pred_re[ii], Q28 ); - hMdEnc->spar_md.band_coeffs[b].P_re_fx[ii] = float_to_fix( hMdEnc->spar_md.band_coeffs[b].P_re[ii], Q28 ); - } - } -#endif test(); IF( hMdEnc->spar_hoa_md_flag && hMdEnc->spar_hoa_dirac2spar_md_flag ) { @@ -974,106 +966,13 @@ ivas_error ivas_spar_md_enc_process_fx( { FOR( i = 0; i < DIRAC_TO_SPAR_HBR_PRED_CHS; i++ ) { - pred_coeffs_re_local_fx[i][b] = hMdEnc->spar_md.band_coeffs[b].pred_re_fx[i]; + pred_coeffs_re_local_fx[i][b] = hMdEnc->spar_md.band_coeffs[b].pred_re_fx[i]; // Q28 move32(); } } } -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - FOR( i = 0; i < nchan_inp; i++ ) - { - FOR( j = 0; j < nchan_inp; j++ ) - { - FOR( k = 0; k < IVAS_MAX_NUM_BANDS; k++ ) - { - cov_real[i][j][k] = me2f( cov_real_fx[i][j][k], sub( Q31, cov_real_q[i][j][k] ) ); - cov_dtx_real[i][j][k] = me2f( cov_dtx_real_fx[i][j][k], sub( Q31, cov_dtx_real_q[i][j][k] ) ); - } - } - } -#endif - -#ifdef IVAS_FLOAT_FIXED -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - - for ( i = 0; i < num_ch; i++ ) - { - for ( j = 0; j < num_ch; j++ ) - { - for ( k = 0; k < IVAS_MAX_NUM_BANDS; k++ ) - { - f2me( cov_real[i][j][k], &cov_real_fx[i][j][k], &cov_real_q[i][j][k] ); - cov_real_q[i][j][k] = 31 - cov_real_q[i][j][k]; - } - } - } - -#endif ivas_compute_spar_params_enc_fx( cov_real_fx, cov_real_q, dm_fv_re_fx, &q_dm_fv_re, 0, hMdEnc->mixer_mat_fx, &hMdEnc->q_mixer_mat_fx, 0, nB, dtx_vad, num_ch, bands_bw, active_w, active_w_vlbr, &hMdEnc->spar_md_cfg, &hMdEnc->spar_md, Wscale_fx, q_Wscale, 0, dyn_active_w_flag ); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - for ( i = 0; i < num_ch - 1; i++ ) - { - for ( j = 0; j < nB; j++ ) - { - dm_fv_re[i][j] = fixedToFloat_32( dm_fv_re_fx[i][j], q_dm_fv_re ); - } - } - for ( i = 0; i < num_ch; i++ ) - { - for ( j = 0; j < num_ch; j++ ) - { - for ( b = 0; b < nB; b++ ) - { - hMdEnc->mixer_mat[i][j][b] = fixedToFloat_32( hMdEnc->mixer_mat_fx[i][j][b], hMdEnc->q_mixer_mat_fx ); - } - } - } - Word16 q_tmp; - for ( b = 0; b < nB; b++ ) - { - Wscale[b] = fixedToFloat_32( Wscale_fx[b], q_Wscale[b] ); - for ( i = 0; i < num_ch - 1; i++ ) - { - q_tmp = hMdEnc->spar_md.band_coeffs[b].q_pred_re_fx; - hMdEnc->spar_md.band_coeffs[b].pred_re[i] = fixedToFloat_32( hMdEnc->spar_md.band_coeffs[b].pred_re_fx[i], q_tmp ); - } - ndm = hMdEnc->spar_md_cfg.num_dmx_chans_per_band[b * bands_bw]; - if ( ndm != num_ch ) - { - for ( i = 0; i < num_ch - ndm; i++ ) - { - q_tmp = hMdEnc->spar_md.band_coeffs[b].q_P_re_fx; - hMdEnc->spar_md.band_coeffs[b].P_re[i] = fixedToFloat_32( hMdEnc->spar_md.band_coeffs[b].P_re_fx[i], q_tmp ); - } - if ( ndm != 1 ) - { - for ( i = 0; i < num_ch - ndm; i++ ) - { - for ( j = 0; j < ndm - 1; j++ ) - { - q_tmp = hMdEnc->spar_md.band_coeffs[b].q_C_re_fx; - hMdEnc->spar_md.band_coeffs[b].C_re[i][j] = fixedToFloat_32( hMdEnc->spar_md.band_coeffs[b].C_re_fx[i][j], q_tmp ); - } - } - } - } - } -#endif -#else - ivas_compute_spar_params( cov_real, dm_fv_re, 0, hMdEnc->mixer_mat, 0, nB, dtx_vad, num_ch, bands_bw, active_w, active_w_vlbr, &hMdEnc->spar_md_cfg, &hMdEnc->spar_md, Wscale, 0, dyn_active_w_flag ); -#endif - -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - for ( b = 0; b < num_bands; b++ ) - { - for ( int ii = 0; ii < num_ch - 1; ii++ ) - { - hMdEnc->spar_md.band_coeffs[b].pred_re_fx[ii] = float_to_fix( hMdEnc->spar_md.band_coeffs[b].pred_re[ii], Q28 ); - hMdEnc->spar_md.band_coeffs[b].P_re_fx[ii] = float_to_fix( hMdEnc->spar_md.band_coeffs[b].P_re[ii], Q28 ); - } - } -#endif IF( dirac_mono_flag ) { Word16 i_ts; @@ -1091,7 +990,6 @@ ivas_error ivas_spar_md_enc_process_fx( { FOR( j = 0; j < ndm + ndec - 1; j++ ) { - hMdEnc->spar_md.band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].pred_re[j] = 0.0f; hMdEnc->spar_md.band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].pred_re_fx[j] = 0; move32(); } @@ -1099,7 +997,6 @@ ivas_error ivas_spar_md_enc_process_fx( { FOR( k = 0; k < ndm - 1; k++ ) { - hMdEnc->spar_md.band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].C_re[j][k] = 0.0f; hMdEnc->spar_md.band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].C_re_fx[j][k] = 0; move32(); } @@ -1107,7 +1004,6 @@ ivas_error ivas_spar_md_enc_process_fx( FOR( j = 0; j < ndec; j++ ) { - hMdEnc->spar_md.band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].P_re[j] = 0.0f; hMdEnc->spar_md.band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].P_re_fx[j] = 0; move32(); } @@ -1119,12 +1015,6 @@ ivas_error ivas_spar_md_enc_process_fx( move16(); FOR( qsi = 0; qsi < num_quant_strats; qsi++ ) { -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - hMdEnc->spar_md_cfg.quant_strat[qsi].P_r.min_fx = float_to_fix( hMdEnc->spar_md_cfg.quant_strat[qsi].P_r.min, Q28 ); - hMdEnc->spar_md_cfg.quant_strat[qsi].P_r.max_fx = float_to_fix( hMdEnc->spar_md_cfg.quant_strat[qsi].P_r.max, Q28 ); - hMdEnc->spar_md_cfg.quant_strat[qsi].PR.min_fx = float_to_fix( hMdEnc->spar_md_cfg.quant_strat[qsi].PR.min, Q28 ); - hMdEnc->spar_md_cfg.quant_strat[qsi].PR.max_fx = float_to_fix( hMdEnc->spar_md_cfg.quant_strat[qsi].PR.max, Q28 ); -#endif FOR( b = 0; b < num_bands; b++ ) { ndm = hMdEnc->spar_md_cfg.num_dmx_chans_per_band[b * bands_bw]; @@ -1172,7 +1062,7 @@ ivas_error ivas_spar_md_enc_process_fx( ivas_quant_strat_t qs; Word16 PR_step_e; qs = hMdEnc->spar_md_cfg.quant_strat[qsi]; - PR_uq = hMdEnc->spar_md.band_coeffs[b].pred_re_fx[i]; + PR_uq = hMdEnc->spar_md.band_coeffs[b].pred_re_fx[i]; // Q28 move32(); PR_step = BASOP_Util_Divide3216_Scale( L_sub( qs.PR.max_fx, qs.PR.min_fx ), sub( qs.PR.q_levels[0], 1 ), &PR_step_e ); PR_step_e = sub( PR_step_e, Q12 ); @@ -1205,47 +1095,11 @@ ivas_error ivas_spar_md_enc_process_fx( ivas_spar_quant_pred_coeffs_dtx_fx( &hMdEnc->spar_md, hMdEnc->spar_md.band_coeffs[b].pred_re_fx, ndm, hMdEnc->spar_md.band_coeffs_idx[b].pred_index_re, sub( num_ch, 1 ), hMdEnc->spar_md.band_coeffs[b].pred_quant_re_fx ); } } -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - for ( b = 0; b < num_bands; b++ ) - { - for ( int ii = 0; ii < IVAS_SPAR_MAX_CH - 1; ii++ ) - { - hMdEnc->spar_md.band_coeffs[b].pred_quant_re[ii] = fix_to_float( hMdEnc->spar_md.band_coeffs[b].pred_quant_re_fx[ii], Q28 ); - hMdEnc->spar_md.band_coeffs[b].P_quant_re[ii] = fix_to_float( hMdEnc->spar_md.band_coeffs[b].P_quant_re_fx[ii], Q28 ); - } - } - Word16 Wscale_e, dm_fv_re_q = Q31, mixer_q = Q31; - f2me_buf( Wscale, Wscale_fx, &Wscale_e, (Word32) num_bands ); - - for ( i = 0; i < num_ch - 1; i++ ) - { - dm_fv_re_q = s_min( dm_fv_re_q, Q_factor_arrL( dm_fv_re[i], num_bands ) ); - } - for ( i = 0; i < num_ch; i++ ) - { - for ( j = 0; j < num_ch; j++ ) - { - mixer_q = s_min( mixer_q, Q_factor_arrL( hMdEnc->mixer_mat[i][j], num_bands ) ); - } - } - mixer_q = mixer_q - Wscale_e; // Important - for ( i = 0; i < num_ch; i++ ) - { - for ( j = 0; j < num_ch; j++ ) - { - floatToFixed_arrL32( hMdEnc->mixer_mat[i][j], hMdEnc->mixer_mat_fx[i][j], mixer_q, num_bands ); - } - } - for ( i = 0; i < num_ch - 1; i++ ) - { - floatToFixed_arrL32( dm_fv_re[i], dm_fv_re_fx[i], dm_fv_re_q, num_bands ); - } -#endif FOR( i = 0; i < num_ch - 1; i++ ) { FOR( b = 0; b < num_bands; b++ ) { - pred_coeffs_re_fx[i][b] = L_shl( Mpy_32_32( Wscale_fx[b], hMdEnc->spar_md.band_coeffs[b].pred_quant_re_fx[i] ), Wscale_e ); + pred_coeffs_re_fx[i][b] = L_shl( Mpy_32_32( Wscale_fx[b], hMdEnc->spar_md.band_coeffs[b].pred_quant_re_fx[i] ), sub( Q31, q_Wscale[b] ) ); // Q28 move32(); } } @@ -1261,7 +1115,6 @@ ivas_error ivas_spar_md_enc_process_fx( pred_coeffs_re_fx[i][b] = pred_coeffs_re_local_fx[i][b]; move32(); hMdEnc->spar_md.band_coeffs[b].pred_quant_re_fx[i] = 0; - hMdEnc->spar_md.band_coeffs[b].pred_quant_re[i] = 0.0f; move32(); hMdEnc->spar_md.band_coeffs_idx[b].pred_index_re[i] = 0; move16(); @@ -1269,8 +1122,27 @@ ivas_error ivas_spar_md_enc_process_fx( } } - ivas_create_fullr_dmx_mat_fx( pred_coeffs_re_fx, Q28, dm_fv_re_fx, dm_fv_re_q, hMdEnc->mixer_mat_fx, &mixer_q, num_ch, 0, num_bands, active_w, &hMdEnc->spar_md_cfg ); - + ivas_create_fullr_dmx_mat_fx( pred_coeffs_re_fx, Q28, dm_fv_re_fx, q_dm_fv_re, hMdEnc->mixer_mat_fx, &hMdEnc->q_mixer_mat_fx, num_ch, 0, num_bands, active_w, &hMdEnc->spar_md_cfg ); + Word16 Wscale_e = Q31; + move16(); + /* Common q for Wscale buffer */ + FOR( b = 0; b < num_bands; b++ ) + { + if ( GT_16( Wscale_e, q_Wscale[b] ) ) + { + Wscale_e = q_Wscale[b]; + move16(); + } + } + FOR( b = 0; b < num_bands; b++ ) + { + Wscale_fx[b] = L_shr( Wscale_fx[b], sub( q_Wscale[b], Wscale_e ) ); // Q(Wscale_e) + move32(); + } + Wscale_e = sub( Q31, Wscale_e ); // Wscale_e is now exp of Wscale + /*mixer-q adjusted for Wscale multplication below */ + hMdEnc->q_mixer_mat_fx = sub( hMdEnc->q_mixer_mat_fx, Wscale_e ); + move16(); FOR( b = 0; b < num_bands; b++ ) { ndm = hMdEnc->spar_md_cfg.num_dmx_chans_per_band[b * bands_bw]; @@ -1280,16 +1152,18 @@ ivas_error ivas_spar_md_enc_process_fx( FOR( i = 0; i < num_ch; i++ ) { - hMdEnc->mixer_mat_fx[0][i][b] = L_shl( Mpy_32_32( hMdEnc->mixer_mat_fx[0][i][b], Wscale_fx[b] ), Wscale_e ); + hMdEnc->mixer_mat_fx[0][i][b] = Mpy_32_32( hMdEnc->mixer_mat_fx[0][i][b], Wscale_fx[b] ); move32(); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - hMdEnc->mixer_mat[0][i][b] = fix_to_float( hMdEnc->mixer_mat_fx[0][i][b], mixer_q ); -#endif + FOR( j = 1; j < num_ch; j++ ) + { + hMdEnc->mixer_mat_fx[j][i][b] = L_shr( hMdEnc->mixer_mat_fx[j][i][b], Wscale_e ); // Q(hMdEnc->q_mixer_mat_fx) + move32(); + } } - + test(); IF( NE_16( ndm, num_ch ) && NE_16( ndm, 1 ) ) { - ivas_calc_c_p_coeffs( &hMdEnc->spar_md, cov_real, 0, hMdEnc->mixer_mat, num_ch, ndm, b, dtx_vad, 0, dyn_active_w_flag ); + ivas_calc_c_p_coeffs_enc_fx( &hMdEnc->spar_md, cov_real_fx, cov_real_q, 0, hMdEnc->mixer_mat_fx, hMdEnc->q_mixer_mat_fx, num_ch, ndm, b, dtx_vad, 0, dyn_active_w_flag ); IF( dirac_mono_flag ) { @@ -1301,13 +1175,13 @@ ivas_error ivas_spar_md_enc_process_fx( { FOR( k = 0; k < ndm - 1; k++ ) { - hMdEnc->spar_md.band_coeffs[b].C_re[j][k] = 0.0f; + hMdEnc->spar_md.band_coeffs[b].C_re_fx[j][k] = 0; + move32(); } } } - - ivas_quant_c_per_band( &hMdEnc->spar_md.band_coeffs[b], &hMdEnc->spar_md.band_coeffs_idx[b], - &hMdEnc->spar_md_cfg.quant_strat[qsi], ndec, ndm ); + ivas_quant_c_per_band_fx( &hMdEnc->spar_md.band_coeffs[b], &hMdEnc->spar_md.band_coeffs_idx[b], + &hMdEnc->spar_md_cfg.quant_strat[qsi], ndec, ndm, hMdEnc->spar_md.band_coeffs[b].q_C_re_fx ); } } @@ -1324,88 +1198,107 @@ ivas_error ivas_spar_md_enc_process_fx( { for ( j = 0; j < num_ch; j++ ) { - fixedToFloat_arrL32( hMdEnc->mixer_mat_fx[i][j], hMdEnc->mixer_mat[i][j], mixer_q, IVAS_MAX_NUM_BANDS ); + fixedToFloat_arrL32( hMdEnc->mixer_mat_fx[i][j], hMdEnc->mixer_mat[i][j], hMdEnc->q_mixer_mat_fx, IVAS_MAX_NUM_BANDS ); } } #endif IF( dtx_vad == 0 ) { -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - hMdEnc->spar_md.min_max_fx[0] = float_to_fix( hMdEnc->spar_md.min_max[0], Q28 ); - hMdEnc->spar_md.min_max_fx[1] = float_to_fix( hMdEnc->spar_md.min_max[1], Q28 ); -#endif ivas_write_parameter_bitstream_dtx_fx( &hMdEnc->spar_md, hMetaData, hMdEnc->spar_md_cfg.num_dmx_chans_per_band, hMdEnc->spar_md_cfg.num_decorr_per_band, num_bands ); BREAK; } -#ifdef IVAS_FLOAT_FIXED ivas_select_next_strat_fx( hMdEnc->spar_md_cfg.prior_strat, cs, dmx_switch, dtx_vad ); -#else - ivas_select_next_strat( hMdEnc->spar_md_cfg.prior_strat, cs, dmx_switch, dtx_vad ); -#endif - for ( i = 0; i < MAX_CODING_STRATS; i++ ) + FOR( i = 0; i < MAX_CODING_STRATS; i++ ) { strat = cs[i]; - if ( strat != NO_STRAT ) + move16(); + IF( NE_16( strat, NO_STRAT ) ) { reset_indices_enc( &hMetaData_tmp, md_indices_allocated ); -#ifdef IVAS_FLOAT_FIXED ivas_write_spar_md_bitstream_fx( hMdEnc, num_bands, bands_bw, &hMetaData_tmp, hEncoderConfig->ivas_total_brate, strat, qsi ); -#else - ivas_write_spar_md_bitstream( hMdEnc, num_bands, bands_bw, &hMetaData_tmp, hEncoderConfig->ivas_total_brate, strat, qsi ); -#endif /*write to main buffer if its a valid bitstream*/ - if ( hMetaData_tmp.nb_bits_tot > 0 ) + IF( hMetaData_tmp.nb_bits_tot > 0 ) { - if ( hMetaData->nb_bits_tot == bit_pos_start || hMetaData_tmp.nb_bits_tot < ( hMetaData->nb_bits_tot - bit_pos_start ) ) + test(); + IF( EQ_16( hMetaData->nb_bits_tot, bit_pos_start ) || LT_16( hMetaData_tmp.nb_bits_tot, sub( hMetaData->nb_bits_tot, bit_pos_start ) ) ) { write_metadata_buffer( &hMetaData_tmp, hMetaData, bit_pos_start, next_ind_start ); code_strat = strat; + move16(); } - - if ( hMetaData->nb_bits_tot - bit_pos_start + ( ( ( hEncoderConfig->ivas_total_brate == IVAS_256k ) && ( sba_order == SBA_FOA_ORDER ) ) ? 1 : 0 ) <= hMdEnc->spar_md_cfg.tgt_bits_per_blk ) + Word16 add_bit; + test(); + IF( ( EQ_32( hEncoderConfig->ivas_total_brate, IVAS_256k ) && EQ_16( sba_order, SBA_FOA_ORDER ) ) ) + { + add_bit = 1; + move16(); + } + ELSE + { + add_bit = 0; + move16(); + } + IF( LE_16( add( sub( hMetaData->nb_bits_tot, bit_pos_start ), add_bit ), hMdEnc->spar_md_cfg.tgt_bits_per_blk ) ) { packed_ok = 1; - break; + move16(); + BREAK; } } } } - if ( packed_ok == 1 ) + IF( EQ_16( packed_ok, 1 ) ) { - break; + BREAK; } /*only if valid bitstream was written to main buffer*/ - if ( hMetaData->nb_bits_tot > bit_pos_start ) + IF( GT_16( hMetaData->nb_bits_tot, bit_pos_start ) ) { - if ( hMetaData->nb_bits_tot - bit_pos_start + ( ( ( hEncoderConfig->ivas_total_brate == IVAS_256k ) && ( sba_order == SBA_FOA_ORDER ) ) ? 1 : 0 ) <= hMdEnc->spar_md_cfg.max_bits_per_blk ) + Word16 add_bit; + test(); + IF( EQ_32( hEncoderConfig->ivas_total_brate, IVAS_256k ) && EQ_16( sba_order, SBA_FOA_ORDER ) ) + { + add_bit = 1; + move16(); + } + ELSE + { + add_bit = 0; + move16(); + } + IF( LE_16( add( sub( hMetaData->nb_bits_tot, bit_pos_start ), add_bit ), hMdEnc->spar_md_cfg.max_bits_per_blk ) ) { packed_ok = 1; - break; + move16(); + BREAK; } } } /* Reuse mixer matrix values for unsent bands */ - if ( ( hEncoderConfig->ivas_total_brate < IVAS_24k4 ) && ( code_strat > 3 ) ) + test(); + IF( ( LT_32( hEncoderConfig->ivas_total_brate, IVAS_24k4 ) ) && GT_16( code_strat, 3 ) ) { - for ( b = 0; b < num_bands * bands_bw; b += 2 * bands_bw ) + FOR( b = 0; b < num_bands * bands_bw; b += 2 * bands_bw ) { - if ( ( b == 0 ) && ( code_strat % 2 == 0 ) ) + test(); + IF( ( b == 0 ) && ( s_and( code_strat, 1 ) == 0 ) ) { - b += 2; + b = add( b, 2 ); } - for ( i = 0; i < 1; i++ ) + FOR( i = 0; i < 1; i++ ) { - for ( j = 0; j < 4; j++ ) + FOR( j = 0; j < 4; j++ ) { + // TODO once fb-mixer changes are final hMdEnc->mixer_mat[i][j][b] = prior_mixer[i][j][b]; hMdEnc->mixer_mat[i][j][b + 1] = prior_mixer[i][j][b + 1]; } @@ -3188,34 +3081,38 @@ static void ivas_quant_pred_coeffs_per_band( * * Quantization of cross prediction c coeffs for each band *-----------------------------------------------------------------------------------------*/ - -static void ivas_quant_c_per_band( +static void ivas_quant_c_per_band_fx( ivas_band_coeffs_t *pband_coeffs, ivas_band_coeffs_ind_t *pBand_coeffs_idx, ivas_quant_strat_t *pQs, - const int16_t ndec, - const int16_t ndm ) + const Word16 ndec, + const Word16 ndm, + const Word16 q_C ) { - int16_t i; - int16_t j, k; - float C_re[IVAS_SPAR_MAX_C_COEFF]; + Word16 i; + Word16 j, k; + Word32 C_re[IVAS_SPAR_MAX_C_COEFF]; k = 0; - for ( i = 0; i < ndec; i++ ) + move16(); + FOR( i = 0; i < ndec; i++ ) { - for ( j = 0; j < ndm - 1; j++ ) + FOR( j = 0; j < ndm - 1; j++ ) { - C_re[k] = pband_coeffs->C_re[i][j]; - k++; + C_re[k] = pband_coeffs->C_re_fx[i][j]; + move32(); + k = add( k, 1 ); } } - ivas_quantise_real_values( C_re, pQs->C.q_levels[0], pQs->C.min, pQs->C.max, pBand_coeffs_idx->drct_index_re, C_re, ndec * ( ndm - 1 ) ); + ivas_quantise_real_values_enc_fx_varq( C_re, pQs->C.q_levels[0], pQs->C.min_fx, pQs->C.max_fx, pBand_coeffs_idx->drct_index_re, C_re, ndec * ( ndm - 1 ), q_C ); k = 0; - for ( i = 0; i < ndec; i++ ) + move16(); + FOR( i = 0; i < ndec; i++ ) { - for ( j = 0; j < ndm - 1; j++ ) + FOR( j = 0; j < ndm - 1; j++ ) { - pband_coeffs->C_quant_re[i][j] = C_re[k]; - k++; + pband_coeffs->C_quant_re_fx[i][j] = C_re[k]; + move32(); + k = add( k, 1 ); } } diff --git a/lib_enc/ivas_stat_enc.h b/lib_enc/ivas_stat_enc.h index 8e8dc8f84..0286115d7 100644 --- a/lib_enc/ivas_stat_enc.h +++ b/lib_enc/ivas_stat_enc.h @@ -938,22 +938,20 @@ typedef struct ivas_dirac_enc_data_structure IVAS_FB_MIXER_HANDLE hFbMixer; /* DirAC parameter estimation */ - float **direction_vector[DIRAC_NUM_DIMS]; - float **direction_vector_m[DIRAC_NUM_DIMS]; /* Average direction vector */ - float diffuseness_m[DIRAC_MAX_NBANDS]; #ifdef IVAS_FLOAT_FIXED Word32 **direction_vector_m_fx[DIRAC_NUM_DIMS]; /* Average direction vector */ Word16 direction_vector_m_exp[MAX_PARAM_SPATIAL_SUBFRAMES]; // direction_vector_m_fx[i][j][k] will map to direction_vector_m_exp[j] exponent. Word32 diffuseness_m_fx[DIRAC_MAX_NBANDS]; Word16 diffuseness_m_exp[DIRAC_MAX_NBANDS]; +#else + float **direction_vector_m[DIRAC_NUM_DIMS]; /* Average direction vector */ + float **direction_vector[DIRAC_NUM_DIMS]; + float diffuseness_m[DIRAC_MAX_NBANDS]; #endif int16_t band_grouping[DIRAC_MAX_NBANDS + 1]; int16_t block_grouping[5]; int16_t firstrun_sector_params; - float sec_I_vec_smth_x[NUM_ANA_SECTORS][IVAS_MAX_NUM_BANDS]; - float sec_I_vec_smth_y[NUM_ANA_SECTORS][IVAS_MAX_NUM_BANDS]; - float sec_I_vec_smth_z[NUM_ANA_SECTORS][IVAS_MAX_NUM_BANDS]; #ifdef IVAS_FLOAT_FIXED Word32 sec_I_vec_smth_x_fx[NUM_ANA_SECTORS][IVAS_MAX_NUM_BANDS]; Word16 sec_I_vec_smth_x_exp[NUM_ANA_SECTORS][IVAS_MAX_NUM_BANDS]; @@ -961,29 +959,35 @@ typedef struct ivas_dirac_enc_data_structure Word16 sec_I_vec_smth_y_exp[NUM_ANA_SECTORS][IVAS_MAX_NUM_BANDS]; Word32 sec_I_vec_smth_z_fx[NUM_ANA_SECTORS][IVAS_MAX_NUM_BANDS]; Word16 sec_I_vec_smth_z_exp[NUM_ANA_SECTORS][IVAS_MAX_NUM_BANDS]; +#else + float sec_I_vec_smth_x[NUM_ANA_SECTORS][IVAS_MAX_NUM_BANDS]; + float sec_I_vec_smth_y[NUM_ANA_SECTORS][IVAS_MAX_NUM_BANDS]; + float sec_I_vec_smth_z[NUM_ANA_SECTORS][IVAS_MAX_NUM_BANDS]; #endif - float energy_smth[NUM_ANA_SECTORS][IVAS_MAX_NUM_BANDS]; - float azi_prev[NUM_ANA_SECTORS * IVAS_MAX_NUM_BANDS]; - float ele_prev[NUM_ANA_SECTORS * IVAS_MAX_NUM_BANDS]; #ifdef IVAS_FLOAT_FIXED Word32 energy_smth_fx[NUM_ANA_SECTORS][IVAS_MAX_NUM_BANDS]; Word16 energy_smth_exp[NUM_ANA_SECTORS][IVAS_MAX_NUM_BANDS]; Word32 azi_prev_fx[NUM_ANA_SECTORS * IVAS_MAX_NUM_BANDS]; Word32 ele_prev_fx[NUM_ANA_SECTORS * IVAS_MAX_NUM_BANDS]; +#else + float energy_smth[NUM_ANA_SECTORS][IVAS_MAX_NUM_BANDS]; + float azi_prev[NUM_ANA_SECTORS * IVAS_MAX_NUM_BANDS]; + float ele_prev[NUM_ANA_SECTORS * IVAS_MAX_NUM_BANDS]; #endif /* diffuseness */ int16_t index_buffer_intensity; int16_t no_col_avg_diff; - float **buffer_intensity_real[DIRAC_NUM_DIMS]; - float *buffer_energy; #ifdef IVAS_FLOAT_FIXED Word32 **buffer_intensity_real_fx[DIRAC_NUM_DIMS]; Word16 buffer_intensity_real_q[DIRAC_NUM_DIMS][DIRAC_NO_COL_AVG_DIFF][DIRAC_MAX_NBANDS]; Word32 *buffer_energy_fx; Word16 buffer_energy_q[DIRAC_NO_COL_AVG_DIFF * DIRAC_MAX_NBANDS]; +#else + float **buffer_intensity_real[DIRAC_NUM_DIMS]; + float *buffer_energy; #endif /* Frame count for detecting mono */ -- GitLab From c7d55a4db19d993a88dc8bc58b720359bf357ddc Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Mon, 28 Oct 2024 17:19:31 +0530 Subject: [PATCH 050/128] Fix for 3gpp issue 866 --- lib_com/fd_cng_com.c | 3 --- lib_com/fd_cng_com_fx.c | 2 -- lib_com/stat_com.h | 5 +---- lib_dec/acelp_core_dec_ivas_fx.c | 1 - lib_dec/fd_cng_dec.c | 21 +++++++++++---------- lib_dec/ivas_stereo_cng_dec.c | 6 +++--- lib_dec/ivas_stereo_mdct_core_dec_fx.c | 11 ++--------- lib_dec/ivas_tcx_core_dec.c | 10 +++------- 8 files changed, 20 insertions(+), 39 deletions(-) diff --git a/lib_com/fd_cng_com.c b/lib_com/fd_cng_com.c index 14c9b3c21..a03edf290 100644 --- a/lib_com/fd_cng_com.c +++ b/lib_com/fd_cng_com.c @@ -118,9 +118,6 @@ void initFdCngCom_flt( hFdCngCom->frame_type_previous = ACTIVE_FRAME; hFdCngCom->flag_noisy_speech = 0; hFdCngCom->likelihood_noisy_speech_flt = 0.f; -#ifdef IVAS_FLOAT_FIXED - hFdCngCom->likelihood_noisy_speech_32fx = 0; -#endif hFdCngCom->numCoreBands = 0; hFdCngCom->stopBand = 0; hFdCngCom->startBand = 0; diff --git a/lib_com/fd_cng_com_fx.c b/lib_com/fd_cng_com_fx.c index 8f5528014..e11d67d69 100644 --- a/lib_com/fd_cng_com_fx.c +++ b/lib_com/fd_cng_com_fx.c @@ -163,8 +163,6 @@ void ivas_initFdCngCom_fx( HANDLE_FD_CNG_COM hFdCngCom, Word16 scale ) set32_fx( hFdCngCom->olapBufferSynth2_fx, 0, FFTLEN ); set32_fx( hFdCngCom->exc_cng_32fx, 0, L_FRAME16k ); set16_fx( hFdCngCom->exc_cng, 0, L_FRAME16k ); - hFdCngCom->likelihood_noisy_speech_32fx = 0; - move32(); return; } diff --git a/lib_com/stat_com.h b/lib_com/stat_com.h index 7cc45ae38..97fec1041 100644 --- a/lib_com/stat_com.h +++ b/lib_com/stat_com.h @@ -532,10 +532,7 @@ typedef struct int16_t flag_noisy_speech; float likelihood_noisy_speech_flt; -#ifdef IVAS_FLOAT_FIXED - Word32 likelihood_noisy_speech_32fx; -#endif - Word16 likelihood_noisy_speech; + Word16 likelihood_noisy_speech; // Q15 #ifndef IVAS_FLOAT_FIXED float coherence_flt; /* inter-channel coherence of noise */ diff --git a/lib_dec/acelp_core_dec_ivas_fx.c b/lib_dec/acelp_core_dec_ivas_fx.c index 679120dbb..834691ce0 100644 --- a/lib_dec/acelp_core_dec_ivas_fx.c +++ b/lib_dec/acelp_core_dec_ivas_fx.c @@ -1552,7 +1552,6 @@ ivas_error acelp_core_dec_ivas_fx( st->hFdCngDec->hFdCngCom->likelihood_noisy_speech = add( st->hFdCngDec->hFdCngCom->likelihood_noisy_speech, 328 /*0.01 Q15*/ ); move16(); } - st->hFdCngDec->hFdCngCom->likelihood_noisy_speech_32fx = L_deposit_h( st->hFdCngDec->hFdCngCom->likelihood_noisy_speech ); move32(); } diff --git a/lib_dec/fd_cng_dec.c b/lib_dec/fd_cng_dec.c index 10c25db4d..0c3f8afd6 100644 --- a/lib_dec/fd_cng_dec.c +++ b/lib_dec/fd_cng_dec.c @@ -59,7 +59,7 @@ #define CNA_ACT_DN_FACT 0.7 /* downward updating factor for CNA during active frames */ #endif // IVAS_FLOAT_FIXED -#define DELTA_MASKING_NOISE_Q31 0 +#define DELTA_MASKING_NOISE_Q15 0 #define CNA_ACT_DN_LARGE_PARTITION 50 /* index of the first larger partition */ #define FIRST_CNA_NOISE_UPD_FRAMES 5 /* minimum number of CN initialization frames */ #define LOG_10_BASE_2 1783446566 /* Q29 */ @@ -1955,7 +1955,7 @@ void generate_masking_noise_ivas_fx( /* skip noise generating if level is very low, to avoid problems with possibly running into denormals */ *exp_out = Q15; move16(); - IF( GT_32( hFdCngCom->likelihood_noisy_speech_32fx, DELTA_MASKING_NOISE_Q31 ) ) + IF( GT_16( hFdCngCom->likelihood_noisy_speech, DELTA_MASKING_NOISE_Q15 ) ) { IF( NE_16( core, AMR_WB_CORE ) ) { @@ -1997,7 +1997,7 @@ void generate_masking_noise_ivas_fx( } /* Exclude clean speech */ - scale_fx = Mpy_32_32( scale_fx, hFdCngCom->likelihood_noisy_speech_32fx ); // Q30 + scale_fx = Mpy_32_16_1( scale_fx, hFdCngCom->likelihood_noisy_speech ); // Q30 /* Generate Gaussian random noise in real and imaginary parts of the FFT bins Amplitudes are adjusted to the estimated noise level cngNoiseLevel_flt in each bin */ @@ -2680,7 +2680,7 @@ void generate_masking_noise_lb_dirac_fx( IF( cna_flag ) { /* skip noise generating if level is very low, to avoid problems with possibly running into denormals */ - IF( GT_32( hFdCngCom->likelihood_noisy_speech_32fx, DELTA_MASKING_NOISE_Q31 ) ) + IF( GT_16( hFdCngCom->likelihood_noisy_speech, DELTA_MASKING_NOISE_Q15 ) ) { /* Compute additional CN level */ FOR( i = 0; i < 15; i++ ) @@ -2695,8 +2695,8 @@ void generate_masking_noise_lb_dirac_fx( } } - scale = L_deposit_h( scaleTable_cn_dirac[i].scale_ivas ); /* Q30 */ - scale = Mpy_32_32( scale, hFdCngCom->likelihood_noisy_speech_32fx ); /* Q30 */ + scale = L_deposit_h( scaleTable_cn_dirac[i].scale_ivas ); /* Q30 */ + scale = Mpy_32_16_1( scale, hFdCngCom->likelihood_noisy_speech ); /* Q30 */ } } @@ -2738,7 +2738,7 @@ void generate_masking_noise_lb_dirac_fx( FOR( ; ptr_level < cngNoiseLevel + sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ); ptr_level++ ) { rand_gauss_fx( ptr_r, seed, exp_out ); - Word16 exp2 = sub( 31, hFdCngCom->cngNoiseLevelExp ); + Word16 exp2 = hFdCngCom->cngNoiseLevelExp; Word32 mpy2 = Sqrt32( Mpy_32_32( scale, *ptr_level ), &exp2 ); ( *ptr_r ) = L_shl( Mpy_32_32( *ptr_r, mpy2 ), exp2 ); // hFdCngCom->fftBuffer_exp + exp2 - 31 move32(); @@ -2758,6 +2758,7 @@ void generate_masking_noise_lb_dirac_fx( /* Perform STFT synthesis */ SynthesisSTFT_dirac_fx( fftBuffer, tdBuffer + n_samples_start, hFdCngCom->olapBufferSynth2_fx, hFdCngCom->olapWinSyn_fx, n_samples_out_loop, hFdCngCom ); + scale_sig32( tdBuffer + n_samples_start, n_samples_out_loop, Q9 ); // Q2 -> Q11 } ELSE @@ -2935,7 +2936,7 @@ void generate_masking_noise_dirac_ivas_fx( } } - scale_fx = L_shr( scaleTable_cn_dirac[i].scale_ivas, Q3 ); /* Q11 */ + scale_fx = L_shr( L_deposit_h( scaleTable_cn_dirac[i].scale_ivas ), Q3 ); /* Q27 */ scale_fx = Mpy_32_16_1( scale_fx, hFdCngCom->likelihood_noisy_speech ); } } @@ -2959,11 +2960,11 @@ void generate_masking_noise_dirac_ivas_fx( /*HF CLDFB - CNA and/or FD-CNG*/ if ( fd_cng_flag ) { - scale_fx = L_add( scale_fx, 2048 ); // 1 in Q11 + scale_fx = L_add( scale_fx, ONE_IN_Q27 ); // 1 in Q27 } IF( scale_fx != 0 ) { - q_scale = 11; + q_scale = 27; move16(); q_shift = norm_l( scale_fx ); scale_fx = L_shl( scale_fx, q_shift ); diff --git a/lib_dec/ivas_stereo_cng_dec.c b/lib_dec/ivas_stereo_cng_dec.c index 7737a251d..60375dd78 100644 --- a/lib_dec/ivas_stereo_cng_dec.c +++ b/lib_dec/ivas_stereo_cng_dec.c @@ -1384,9 +1384,9 @@ static void stereo_dft_generate_comfort_noise_fx( move32(); st->hFdCngDec->hFdCngCom->flag_noisy_speech = extract_l( LT_32( L_shr( L_sub( st->hFdCngDec->lp_speech, st->hFdCngDec->lp_noise ), q_lp_noise ), 28 ) ); /* Q0 */ move16(); - st->hFdCngDec->hFdCngCom->likelihood_noisy_speech_32fx = L_add( Mpy_32_32( Q31_0_99, st->hFdCngDec->hFdCngCom->likelihood_noisy_speech_32fx ), - imult3216( Q31_0_01, st->hFdCngDec->hFdCngCom->flag_noisy_speech ) ); /* Q31 */ - move32(); + st->hFdCngDec->hFdCngCom->likelihood_noisy_speech = add( mult_r( 32440 /* 0.99 in Q15 */, st->hFdCngDec->hFdCngCom->likelihood_noisy_speech ), + mult_r( 328 /* 0.01 in Q15 */, st->hFdCngDec->hFdCngCom->flag_noisy_speech ) ); /* Q15 */ + move16(); } test(); diff --git a/lib_dec/ivas_stereo_mdct_core_dec_fx.c b/lib_dec/ivas_stereo_mdct_core_dec_fx.c index 6731b8b0d..155e207b8 100644 --- a/lib_dec/ivas_stereo_mdct_core_dec_fx.c +++ b/lib_dec/ivas_stereo_mdct_core_dec_fx.c @@ -535,11 +535,6 @@ void stereo_mdct_core_dec_fx( sts[ch]->hFdCngDec->hFdCngCom->cngNoiseLevelExp = sub( sts[ch]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, s ); } test(); - IF( sts[ch]->hFdCngDec && sts[ch]->hFdCngDec->hFdCngCom ) - { - sts[ch]->hFdCngDec->hFdCngCom->likelihood_noisy_speech = extract_h( sts[ch]->hFdCngDec->hFdCngCom->likelihood_noisy_speech_32fx ); /* 16 - q_likelihood_noisy_speech */ - } - test(); test(); IF( sts[ch]->igf != 0 && sts[ch]->hIGFDec && sts[ch]->hIGFDec->virtualSpec_fx ) { @@ -1066,10 +1061,8 @@ static void run_min_stats_fx( noisy_speech_detection_fx( st->hFdCngDec, st->VAD && st->m_frame_type == ACTIVE_FRAME, power_spec_16, sub( 15, power_spec_e ) ); - st->hFdCngDec->hFdCngCom->likelihood_noisy_speech_32fx = L_add( Mpy_32_32( Q31_0_99, st->hFdCngDec->hFdCngCom->likelihood_noisy_speech_32fx ), Mpy_32_32( st->hFdCngDec->hFdCngCom->flag_noisy_speech, Q31_0_01 ) ); /* q_likelihood_noisy_speech */ - st->hFdCngDec->hFdCngCom->likelihood_noisy_speech = extract_h( st->hFdCngDec->hFdCngCom->likelihood_noisy_speech_32fx ); /* q_likelihood_noisy_speech - 16 */ - move32(); - move32(); + st->hFdCngDec->hFdCngCom->likelihood_noisy_speech = add( mult_r( 32440 /* 0.99 in Q15 */, st->hFdCngDec->hFdCngCom->likelihood_noisy_speech ), mult_r( st->hFdCngDec->hFdCngCom->flag_noisy_speech, 328 /* 0.01 in Q15 */ ) ); /* Q15 */ + move16(); st->lp_noise = st->hFdCngDec->lp_noise; /* Q9.23 */ move32(); } diff --git a/lib_dec/ivas_tcx_core_dec.c b/lib_dec/ivas_tcx_core_dec.c index 4ac7c32a8..7930720f3 100644 --- a/lib_dec/ivas_tcx_core_dec.c +++ b/lib_dec/ivas_tcx_core_dec.c @@ -954,14 +954,10 @@ void stereo_tcx_core_dec_fx( IF( st->hFdCngDec != NULL && ( EQ_32( st->sr_core, INT_FS_12k8 ) || EQ_32( st->sr_core, INT_FS_16k ) ) && LE_32( st->total_brate, MAX_ACELP_BRATE ) ) { noisy_speech_detection_fx( st->hFdCngDec, st->VAD && EQ_16( st->m_frame_type, ACTIVE_FRAME ), signal_out_fx, 0 ); - - st->hFdCngDec->hFdCngCom->likelihood_noisy_speech_32fx = L_add( Mpy_32_32( Q31_0_99, st->hFdCngDec->hFdCngCom->likelihood_noisy_speech_32fx ), - imult3216( Q31_0_01, st->hFdCngDec->hFdCngCom->flag_noisy_speech ) ); /* Q31 */ - st->hFdCngDec->hFdCngCom->likelihood_noisy_speech = extract_h( st->hFdCngDec->hFdCngCom->likelihood_noisy_speech_32fx ); /* Q15 */ - st->lp_noise = st->hFdCngDec->lp_noise; /* Q9.23 */ - move32(); - move32(); + st->hFdCngDec->hFdCngCom->likelihood_noisy_speech = add( mult_r( 32440 /* 0.99f in Q15 */, st->hFdCngDec->hFdCngCom->likelihood_noisy_speech ), mult_r( st->hFdCngDec->hFdCngCom->flag_noisy_speech, 328 /* 0.01f in Q15 */ ) ); /* Q15 */ + st->lp_noise = st->hFdCngDec->lp_noise; /* Q9.23 */ move16(); + move32(); IF( NE_16( st->element_mode, IVAS_CPE_TD ) ) { -- GitLab From 08d9a3e192508bcefb91c9e4a5e29e8dc4b10145 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Mon, 28 Oct 2024 17:47:12 +0530 Subject: [PATCH 051/128] Fix for 3gpp issue 965: Decoder crash for OMASA ISM3_1TC at 24.4 kbps FER in stereo_icBWE_dec_fx() --- lib_dec/ivas_stereo_icbwe_dec.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib_dec/ivas_stereo_icbwe_dec.c b/lib_dec/ivas_stereo_icbwe_dec.c index 32751a338..b79d52d7e 100644 --- a/lib_dec/ivas_stereo_icbwe_dec.c +++ b/lib_dec/ivas_stereo_icbwe_dec.c @@ -789,6 +789,7 @@ void stereo_icBWE_dec_fx( } ELSE IF( EQ_16( st->element_mode, IVAS_CPE_DFT ) ) { + Word32 temp; hStereoICBWE->refChanIndx_bwe = L_CH_INDX; move16(); hStereoICBWE->prevSpecMapping_fx = 0; @@ -796,9 +797,9 @@ void stereo_icBWE_dec_fx( prevgsMapping_fx = hStereoICBWE->prevgsMapping_fx; move16(); - temp1_fx = shr( extract_h( hStereoDft->side_gain_fx[2 * STEREO_DFT_BAND_MAX + hStereoDft->nbands - 1] ), 1 ); - icbweM2Ref_fx = add( 16384 /*1.f in Q14*/, temp1_fx ); /* Q14 */ - gsMapping_fx = sub( 16384 /*1.f in Q14*/, temp1_fx ); /* Q14 */ + temp = L_shr( hStereoDft->side_gain_fx[2 * STEREO_DFT_BAND_MAX + hStereoDft->nbands - 1], 1 ); // Q30 + icbweM2Ref_fx = extract_h( L_add( ONE_IN_Q30, temp ) ); // Q14 + gsMapping_fx = extract_h( L_sub( ONE_IN_Q30, temp ) ); // Q14 winLen_fx = extract_l( Mpy_32_16_1( st->output_Fs, 41 ) ); //(int16_t)((SHB_OVERLAP_LEN * st->output_Fs) / 16000); Q0 winSlope_fx = div_s( 1, winLen_fx ); /* Q15 */ -- GitLab From f1b9b09f90d5ed135433661d1d0071e964625054 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Mon, 28 Oct 2024 19:32:04 +0530 Subject: [PATCH 052/128] MASA path cleanup, Q-info update for decoder/common files --- lib_com/ACcontextMapping.c | 18 +-- lib_com/ACcontextMapping_fx.c | 50 +++--- lib_com/ari_fx.c | 5 +- lib_com/ari_hm.c | 144 +++++++++--------- lib_com/ari_hm_fx.c | 128 ++++++++-------- lib_com/cldfb.c | 18 ++- lib_com/ivas_prot_fx.h | 23 +++ lib_com/ivas_qmetadata_com.c | 17 +-- lib_com/ivas_qspherical_com.c | 8 +- lib_com/prot.h | 38 ++--- lib_com/prot_fx.h | 69 +++++---- lib_enc/ivas_enc.c | 102 +++++++------ lib_enc/ivas_masa_enc.c | 245 +++++++++++++++++++++++++++++- lib_enc/ivas_qmetadata_enc.c | 277 ++++++++++++++++++++-------------- lib_enc/ivas_qspherical_enc.c | 9 +- lib_enc/lib_enc.c | 112 +++++++++++++- lib_rend/ivas_efap.c | 17 ++- 17 files changed, 872 insertions(+), 408 deletions(-) diff --git a/lib_com/ACcontextMapping.c b/lib_com/ACcontextMapping.c index 1af3286bf..15dcfc0be 100644 --- a/lib_com/ACcontextMapping.c +++ b/lib_com/ACcontextMapping.c @@ -67,21 +67,21 @@ int16_t get_next_coeff_mapped_ivas( } #else Word16 get_next_coeff_mapped_ivas( - Word16 ii[2], /* i/o: coefficient indexes */ - Word32 *pp, /* o : peak(1)/hole(0) indicator */ - Word16 *idx, /* o : index in unmapped domain */ - CONTEXT_HM_CONFIG *hm_cfg /* i : HM configuration */ + Word16 ii[2], /* i/o: coefficient indexes Q0*/ + Word32 *pp, /* o : peak(1)/hole(0) indicator Q0*/ + Word16 *idx, /* o : index in unmapped domain Q0*/ + CONTEXT_HM_CONFIG *hm_cfg /* i : HM configuration */ ) { UWord32 p; - p = s_and( sub( ii[1], hm_cfg->numPeakIndices ), sub( hm_cfg->indexBuffer[ii[1]], hm_cfg->indexBuffer[ii[0]] ) ); - p = UL_lshr( p, sub( sizeof( p ) * 8, 1 ) ); - *pp = p; + p = s_and( sub( ii[1], hm_cfg->numPeakIndices ), sub( hm_cfg->indexBuffer[ii[1]], hm_cfg->indexBuffer[ii[0]] ) ); /* Q0 */ + p = UL_lshr( p, sub( sizeof( p ) * 8, 1 ) ); /* Q0 */ + *pp = p; /* Q0 */ move32(); - *idx = ii[p]; + *idx = ii[p]; /* Q0 */ move16(); - ii[p] = add( ii[p], 1 ); + ii[p] = add( ii[p], 1 ); /* Q0 */ move16(); return hm_cfg->indexBuffer[*idx]; diff --git a/lib_com/ACcontextMapping_fx.c b/lib_com/ACcontextMapping_fx.c index d55bcd6ac..9fa89cb7e 100644 --- a/lib_com/ACcontextMapping_fx.c +++ b/lib_com/ACcontextMapping_fx.c @@ -11,15 +11,15 @@ /* Returns: index of next coefficient */ Word16 get_next_coeff_mapped( - Word16 ii[2], /* i/o: coefficient indexes */ - Word16 *pp, /* o : peak(1)/hole(0) indicator */ - Word16 *idx, /* o : index in unmapped domain */ - CONTEXT_HM_CONFIG *hm_cfg /* i : HM configuration */ + Word16 ii[2], /* i/o: coefficient indexes Q0*/ + Word16 *pp, /* o : peak(1)/hole(0) indicator Q0*/ + Word16 *idx, /* o : index in unmapped domain Q0*/ + CONTEXT_HM_CONFIG *hm_cfg /* i : HM configuration */ ) { Word16 p; - p = s_and( sub( ii[1], hm_cfg->numPeakIndices ), sub( hm_cfg->indexBuffer[ii[1]], hm_cfg->indexBuffer[ii[0]] ) ); + p = s_and( sub( ii[1], hm_cfg->numPeakIndices ), sub( hm_cfg->indexBuffer[ii[1]], hm_cfg->indexBuffer[ii[0]] ) ); /* Q0 */ if ( p > 0 ) { p = 0; @@ -30,63 +30,69 @@ Word16 get_next_coeff_mapped( p = 1; move16(); } - *pp = p; + *pp = p; /* Q0 */ move16(); - *idx = ii[p]; + *idx = ii[p]; /* Q0 */ move16(); - ii[p] = add( ii[p], 1 ); + ii[p] = add( ii[p], 1 ); /* Q0 */ move16(); return hm_cfg->indexBuffer[*idx]; } /* Returns: index of next coefficient */ Word16 get_next_coeff_unmapped( - Word16 ii[2], /* i/o: coefficient indexes */ - Word16 *pp, /* o : peak(1)/hole(0) indicator */ - Word16 *idx, /* o : index in unmapped domain */ - CONTEXT_HM_CONFIG *hm_cfg /* i : HM configuration */ + Word16 ii[2], /* i/o: coefficient indexes Q0*/ + Word16 *pp, /* o : peak(1)/hole(0) indicator Q0*/ + Word16 *idx, /* o : index in unmapped domain Q0*/ + CONTEXT_HM_CONFIG *hm_cfg /* i : HM configuration */ ) { (void) pp; (void) hm_cfg; - *idx = ii[0]; + *idx = ii[0]; /* Q0 */ move16(); - ii[0] = add( ii[0], 1 ); + ii[0] = add( ii[0], 1 ); /* Q0 */ move16(); return *idx; } -Word16 update_mixed_context( Word16 ctx, Word16 a ) +Word16 update_mixed_context( + Word16 ctx, /* Q0 */ + Word16 a /* Q0 */ +) { Word32 t32; Word16 t = 0; /* initialize just to avoid compiler warning */ - t32 = L_mac0( 1 - 13, s_and( a, ~1 ), add( shr( a, 2 ), 1 ) ); + t32 = L_mac0( 1 - 13, s_and( a, ~1 ), add( shr( a, 2 ), 1 ) ); /* Q0 */ if ( t32 <= 0 ) { - t = extract_l( t32 ); + t = extract_l( t32 ); /* Q0 */ } a = shr( a, 3 ); if ( t32 > 0 ) { - t = s_min( a, 2 ); + t = s_min( a, 2 ); /* Q0 */ } return add( shl( s_and( ctx, 0xf ), 4 ), add( t, 13 ) ); } #ifdef IVAS_FLOAT_FIXED -Word32 update_mixed_context_ivas_fx( Word32 ctx, Word16 a ) +Word32 update_mixed_context_ivas_fx( + Word32 ctx, /* Q0 */ + Word16 a /* Q0 */ +) { Word32 t32; - t32 = L_mac0( 1 - 13, s_and( a, ~1 ), add( shr( a, 2 ), 1 ) ); + t32 = L_mac0( 1 - 13, s_and( a, ~1 ), add( shr( a, 2 ), 1 ) ); /* Q0 */ - a = shr( a, 3 ); + a = shr( a, 3 ); /* Q0 */ IF( t32 > 0 ) { - t32 = L_min( a, 2 ); + t32 = L_min( a, 2 ); /* Q0 */ } return L_add( L_shl( L_and( ctx, 0xf ), 4 ), L_add( t32, 13 ) ); } diff --git a/lib_com/ari_fx.c b/lib_com/ari_fx.c index 3b36d10b3..aef9a6635 100644 --- a/lib_com/ari_fx.c +++ b/lib_com/ari_fx.c @@ -39,7 +39,10 @@ Word32 L_multi31x16_X2( Word16 xh, Word16 xl, Word16 y ) * * \return r*c */ -Word32 mul_sbc_14bits( Word32 r, Word16 c ) +Word32 mul_sbc_14bits( + Word32 r, /* Q0 */ + Word16 c /* Q0 */ +) { Word32 ret; diff --git a/lib_com/ari_hm.c b/lib_com/ari_hm.c index 8306376e2..159660927 100644 --- a/lib_com/ari_hm.c +++ b/lib_com/ari_hm.c @@ -101,12 +101,13 @@ void UnmapIndex_ivas( } void UnmapIndex_fx( - const Word16 PeriodicityIndex, - const Word16 Bandwidth, - const Word16 LtpPitchLag, - const Word8 SmallerLags, - Word16 *FractionalResolution, - Word32 *Lag ) + const Word16 PeriodicityIndex, /* Q0 */ + const Word16 Bandwidth, /* Q0 */ + const Word16 LtpPitchLag, /* Q0 */ + const Word8 SmallerLags, /* Q0 */ + Word16 *FractionalResolution, /* Q0 */ + Word32 *Lag /* Q0 */ +) { Word16 LtpPitchIndex, Multiplier; Word16 Lag16; @@ -114,54 +115,54 @@ void UnmapIndex_fx( test(); IF( ( LtpPitchLag > 0 ) && ( s_and( PeriodicityIndex, kLtpHmFlag ) != 0 ) ) { - LtpPitchIndex = shr( PeriodicityIndex, 9 ); - Multiplier = s_and( PeriodicityIndex, 0xff ); + LtpPitchIndex = shr( PeriodicityIndex, 9 ); /* Q0 */ + Multiplier = s_and( PeriodicityIndex, 0xff ); /* Q0 */ assert( 0 <= LtpPitchIndex && LtpPitchIndex <= 16 ); assert( 1 <= Multiplier && Multiplier <= ( 1 << NumRatioBits[Bandwidth][LtpPitchIndex] ) ); - *FractionalResolution = kLtpHmFractionalResolution; + *FractionalResolution = kLtpHmFractionalResolution; /* Q0 */ move16(); - *Lag = L_shr( L_mult0( LtpPitchLag, Ratios_fx[Bandwidth][LtpPitchIndex][Multiplier - 1] ), 8 ); + *Lag = L_shr( L_mult0( LtpPitchLag, Ratios_fx[Bandwidth][LtpPitchIndex][Multiplier - 1] ), 8 ); /* Q0 */ move32(); } ELSE { IF( LT_16( PeriodicityIndex, 16 ) ) { - *FractionalResolution = 3; + *FractionalResolution = 3; /* Q0 */ move16(); - Lag16 = add( PeriodicityIndex, GET_ADJ2( 0, 6, 3 ) ); + Lag16 = add( PeriodicityIndex, GET_ADJ2( 0, 6, 3 ) ); /* Q0 */ } ELSE IF( LT_16( PeriodicityIndex, 80 ) ) { - *FractionalResolution = 4; + *FractionalResolution = 4; /* Q0 */ move16(); - Lag16 = add( PeriodicityIndex, GET_ADJ2( 16, 8, 4 ) ); + Lag16 = add( PeriodicityIndex, GET_ADJ2( 16, 8, 4 ) ); /* Q0 */ } ELSE IF( LT_16( PeriodicityIndex, 208 ) ) { - *FractionalResolution = 3; + *FractionalResolution = 3; /* Q0 */ move16(); - Lag16 = add( PeriodicityIndex, GET_ADJ2( 80, 12, 3 ) ); + Lag16 = add( PeriodicityIndex, GET_ADJ2( 80, 12, 3 ) ); /* Q0 */ } ELSE { test(); IF( LT_16( PeriodicityIndex, 224 ) || SmallerLags != 0 ) { - *FractionalResolution = 1; + *FractionalResolution = 1; /* Q0 */ move16(); - Lag16 = add( PeriodicityIndex, GET_ADJ2( 208, 28, 1 ) ); + Lag16 = add( PeriodicityIndex, GET_ADJ2( 208, 28, 1 ) ); /* Q0 */ } ELSE { *FractionalResolution = 0; move16(); - Lag16 = add( PeriodicityIndex, GET_ADJ2( 224, 188, 0 ) ); + Lag16 = add( PeriodicityIndex, GET_ADJ2( 224, 188, 0 ) ); /* Q0 */ } } - *Lag = L_deposit_l( Lag16 ); + *Lag = L_deposit_l( Lag16 ); /* Q0 */ } } @@ -262,19 +263,20 @@ int16_t CountIndexBits_ivas( } Word16 CountIndexBits_fx( - Word16 Bandwidth, - Word16 PeriodicityIndex ) + Word16 Bandwidth, /* Q0 */ + Word16 PeriodicityIndex /* Q0 */ +) { Word16 result; Word16 PeriodicityIndexS; - result = 8; + result = 8; /* Q0 */ move16(); - PeriodicityIndexS = shr( PeriodicityIndex, 9 ); + PeriodicityIndexS = shr( PeriodicityIndex, 9 ); /* Q0 */ if ( s_and( PeriodicityIndex, kLtpHmFlag ) != 0 ) { - result = NumRatioBits[Bandwidth][PeriodicityIndexS]; + result = NumRatioBits[Bandwidth][PeriodicityIndexS]; /* Q0 */ move16(); } @@ -290,9 +292,9 @@ Word16 CountIndexBits_fx( *-------------------------------------------------------------------*/ Word16 tcx_hm_render_ivas( - const Word16 lag, /* i : pitch lag */ - const Word16 fract_res, /* i : fractional resolution of the lag */ - Word16 p[] /* o : harmonic model (Q13) */ + const Word16 lag, /* i : pitch lag Q0*/ + const Word16 fract_res, /* i : fractional resolution of the lag Q0*/ + Word16 p[] /* o : harmonic model Q13*/ ) { Word16 k; @@ -305,14 +307,14 @@ Word16 tcx_hm_render_ivas( tmp32 = Mpy_32_16_1( f0, -26474 ); tmp32 = L_shr_r( BASOP_Util_InvLog2( L_shl( tmp32, 7 ) ), 2 ); - tmp32 = L_sub( 603979776L, tmp32 ); - tmp32 = L_add( L_add( tmp32, tmp32 ), Mpy_32_16_1( tmp32, 26214 ) ); - height = round_fx( tmp32 ); /* Q13 */ + tmp32 = L_sub( 603979776L /* 1.125 in Q29 */, tmp32 ); /* Q29 */ + tmp32 = L_add( L_add( tmp32, tmp32 ), Mpy_32_16_1( tmp32, 26214 /* 0.8 in Q15 */ ) ); /* Q29 */ + height = round_fx( tmp32 ); /* Q13 */ tmp32 = Mpy_32_16_1( f0, -18910 ); - tmp32 = L_shr_r( BASOP_Util_InvLog2( L_shl( tmp32, 7 ) ), 2 ); - tmp32 = L_sub( 1395864371L, tmp32 ); - PeakDeviation = round_fx( tmp32 ); /* Q14 */ + tmp32 = L_shr_r( BASOP_Util_InvLog2( L_shl( tmp32, 7 ) ), 2 ); /* Q30 */ + tmp32 = L_sub( 1395864371L /* 1.3 in Q30 */, tmp32 ); /* Q30 */ + PeakDeviation = round_fx( tmp32 ); /* Q14 */ IF( sub( 13915, PeakDeviation ) > 0 ) { @@ -321,22 +323,22 @@ Word16 tcx_hm_render_ivas( } ELSE { - tmp = div_s( 13915, PeakDeviation ); - tmp = mult_r( tmp, tmp ); /* Q15 */ + tmp = div_s( 13915, PeakDeviation ); /* Q15 */ + tmp = mult_r( tmp, tmp ); /* Q15 */ } /* Render the prototype peak */ - p[kTcxHmParabolaHalfWidth] = height; + p[kTcxHmParabolaHalfWidth] = height; /* Q13 */ move16(); FOR( k = 1; k <= kTcxHmParabolaHalfWidth; ++k ) { - p[kTcxHmParabolaHalfWidth + k] = round_fx( Mpy_32_16_1( BASOP_Util_InvLog2( L_shl( L_mult0( mult0( negate( k ), k ), tmp ), 10 ) ), height ) ); + p[kTcxHmParabolaHalfWidth + k] = round_fx( Mpy_32_16_1( BASOP_Util_InvLog2( L_shl( L_mult0( mult0( negate( k ), k ), tmp ), 10 ) ), height ) ); /* Q13 */ } /* Mirror */ FOR( k = -kTcxHmParabolaHalfWidth; k < 0; ++k ) { - p[kTcxHmParabolaHalfWidth + k] = p[kTcxHmParabolaHalfWidth - k]; + p[kTcxHmParabolaHalfWidth + k] = p[kTcxHmParabolaHalfWidth - k]; /* Q13 */ } return 0; @@ -356,15 +358,15 @@ Word32 tcx_hm_render_fx( f0 = L_shl( lag, sub( 15, fract_res ) ); /* Q31 */ tmp32 = Mpy_32_16_1( f0, -26474 ); - tmp32 = L_shr_r( BASOP_Util_InvLog2( L_shl( tmp32, 7 ) ), 2 ); - tmp32 = L_sub( 603979776L, tmp32 ); - tmp32 = L_add( L_add( tmp32, tmp32 ), Mpy_32_16_1( tmp32, 26214 ) ); - height = round_fx( tmp32 ); /* Q13 */ + tmp32 = L_shr_r( BASOP_Util_InvLog2( L_shl( tmp32, 7 ) ), 2 ); /* Q29 */ + tmp32 = L_sub( 603979776L /* 1.125 in Q29 */, tmp32 ); /* Q29 */ + tmp32 = L_add( L_add( tmp32, tmp32 ), Mpy_32_16_1( tmp32, 26214 /* 0.8 in Q15 */ ) ); /* Q29 */ + height = round_fx( tmp32 ); /* Q13 */ tmp32 = Mpy_32_16_1( f0, -18910 ); - tmp32 = L_shr_r( BASOP_Util_InvLog2( L_shl( tmp32, 7 ) ), 2 ); - tmp32 = L_sub( 1395864371L, tmp32 ); - PeakDeviation = round_fx( tmp32 ); /* Q14 */ + tmp32 = L_shr_r( BASOP_Util_InvLog2( L_shl( tmp32, 7 ) ), 2 ); /* Q30 */ + tmp32 = L_sub( 1395864371L /* 1.3 in Q30 */, tmp32 ); /* Q30 */ + PeakDeviation = round_fx( tmp32 ); /* Q14 */ IF( GT_16( 13915, PeakDeviation ) ) { @@ -373,12 +375,12 @@ Word32 tcx_hm_render_fx( } ELSE { - tmp = div_s( 13915, PeakDeviation ); - tmp = mult_r( tmp, tmp ); /* Q15 */ + tmp = div_s( 13915, PeakDeviation ); /* Q15 */ + tmp = mult_r( tmp, tmp ); /* Q15 */ } - tmp = div_s( 13915, PeakDeviation ); - tmp = mult_r( tmp, tmp ); /* Q15 */ + tmp = div_s( 13915, PeakDeviation ); /* Q15 */ + tmp = mult_r( tmp, tmp ); /* Q15 */ /* Render the prototype peak */ p[kTcxHmParabolaHalfWidth] = height; @@ -386,12 +388,12 @@ Word32 tcx_hm_render_fx( FOR( k = 1; k <= kTcxHmParabolaHalfWidth; ++k ) { - p[kTcxHmParabolaHalfWidth + k] = round_fx( Mpy_32_16_1( BASOP_Util_InvLog2( L_shl( L_mult0( i_mult2( negate( k ), k ), tmp ), 10 ) ), height ) ); + p[kTcxHmParabolaHalfWidth + k] = round_fx( Mpy_32_16_1( BASOP_Util_InvLog2( L_shl( L_mult0( i_mult2( negate( k ), k ), tmp ), 10 ) ), height ) ); /* Q13 */ } /* Mirror */ FOR( k = -kTcxHmParabolaHalfWidth; k < 0; ++k ) { - p[kTcxHmParabolaHalfWidth + k] = p[kTcxHmParabolaHalfWidth - k]; + p[kTcxHmParabolaHalfWidth + k] = p[kTcxHmParabolaHalfWidth - k]; /* Q13 */ move16(); } @@ -405,12 +407,12 @@ Word32 tcx_hm_render_fx( *-------------------------------------------------------------------*/ void tcx_hm_modify_envelope_ivas( - const Word16 gain, /* i : HM gain (Q11) */ - const Word16 lag, - const Word16 fract_res, - const Word16 p[], /* i : harmonic model (Q13) */ - Word32 env[], /* i/o: envelope (Q16) */ - const Word16 L_frame /* i : number of spectral lines */ + const Word16 gain, /* i : HM gain Q11*/ + const Word16 lag, /* Q0 */ + const Word16 fract_res, /* Q0 */ + const Word16 p[], /* i : harmonic model Q13*/ + Word32 env[], /* i/o: envelope Q16*/ + const Word16 L_frame /* i : number of spectral lines Q0*/ ) { Word16 k, h, x; @@ -423,7 +425,7 @@ void tcx_hm_modify_envelope_ivas( FOR( k = 0; k < 2 * kTcxHmParabolaHalfWidth + 1; ++k ) { - inv_shape[k] = div_s( 512, add( 512, round_fx( L_mult( gain, p[k] ) ) ) ); + inv_shape[k] = div_s( 512 /* 1 in Q24 */, add( 512 /* 1 in Q24 */, round_fx( L_mult( gain, p[k] ) ) ) ); /* Q15 */ move16(); } @@ -435,11 +437,11 @@ void tcx_hm_modify_envelope_ivas( FOR( x = max( 0, k - kTcxHmParabolaHalfWidth ); x <= min( k + kTcxHmParabolaHalfWidth, L_frame - 1 ); ++x ) { - env[x] = Mpy_32_16_1( env[x], inv_shape[x - k + kTcxHmParabolaHalfWidth] ); + env[x] = Mpy_32_16_1( env[x], inv_shape[x - k + kTcxHmParabolaHalfWidth] ); /* Q16 */ move32(); } - ++h; - k = extract_l( L_shr( L_mult0( h, lag ), fract_res ) ); + h = add( h, 1 ); /* Q0 */ + k = extract_l( L_shr( L_mult0( h, lag ), fract_res ) ); /* Q0 */ } return; @@ -465,7 +467,7 @@ void tcx_hm_modify_envelope_fx( FOR( k = 0; k < 2 * kTcxHmParabolaHalfWidth + 1; ++k ) { /* Q24 = Q11 * Q13; 512 = 1.0 in Q24 format */ - inv_shape[k] = div_s( 512, add( 512, mult_r( gain, p[k] ) ) ); + inv_shape[k] = div_s( 512, add( 512, mult_r( gain, p[k] ) ) ); /* Q15 */ move16(); } @@ -473,21 +475,21 @@ void tcx_hm_modify_envelope_fx( move16(); k = extract_l( L_shr( lag, fract_res ) ); - L_frame_m1 = sub( L_frame, 1 ); - L_frame_for_loop = add( L_frame, kTcxHmParabolaHalfWidth - 1 ); + L_frame_m1 = sub( L_frame, 1 ); /* Q0 */ + L_frame_for_loop = add( L_frame, kTcxHmParabolaHalfWidth - 1 ); /* Q0 */ - WHILE( LE_16( k, L_frame_for_loop ) ) + WHILE( k <= L_frame_for_loop ) { - l1 = s_max( 0, sub( k, kTcxHmParabolaHalfWidth ) ); - l2 = s_min( add( k, kTcxHmParabolaHalfWidth ), L_frame_m1 ); + l1 = s_max( 0, sub( k, kTcxHmParabolaHalfWidth ) ); /* Q0 */ + l2 = s_min( add( k, kTcxHmParabolaHalfWidth ), L_frame_m1 ); /* Q0 */ FOR( x = l1; x <= l2; ++x ) { - env[x] = Mpy_32_16_1( env[x], inv_shape[x - k + kTcxHmParabolaHalfWidth] ); + env[x] = Mpy_32_16_1( env[x], inv_shape[x - k + kTcxHmParabolaHalfWidth] ); /* Q16 */ move32(); } - h = add( h, 1 ); - k = extract_l( L_shr( imult3216( lag, h ), fract_res ) ); + h = add( h, 1 ); /* Q0 */ + k = extract_l( L_shr( imult3216( lag, h ), fract_res ) ); /* Q0 */ } } diff --git a/lib_com/ari_hm_fx.c b/lib_com/ari_hm_fx.c index 767aea860..ea0c59972 100644 --- a/lib_com/ari_hm_fx.c +++ b/lib_com/ari_hm_fx.c @@ -13,12 +13,13 @@ #define GET_ADJ2( T, L, F ) ( ( ( L ) << ( F ) ) - ( T ) ) void UnmapIndex( - const Word16 PeriodicityIndex, - const Word16 Bandwidth, - const Word16 LtpPitchLag, - const Word16 SmallerLags, - Word16 *FractionalResolution, - Word32 *Lag ) + const Word16 PeriodicityIndex, /* Q0 */ + const Word16 Bandwidth, /* Q0 */ + const Word16 LtpPitchLag, /* Q0 */ + const Word16 SmallerLags, /* Q0 */ + Word16 *FractionalResolution, /* Q0 */ + Word32 *Lag /* Q0 */ +) { Word16 LtpPitchIndex, Multiplier; Word16 Lag16; @@ -26,65 +27,65 @@ void UnmapIndex( test(); IF( ( LtpPitchLag > 0 ) && ( s_and( PeriodicityIndex, kLtpHmFlag ) != 0 ) ) { - LtpPitchIndex = shr( PeriodicityIndex, 9 ); - Multiplier = s_and( PeriodicityIndex, 0xff ); + LtpPitchIndex = shr( PeriodicityIndex, 9 ); /* Q0 */ + Multiplier = s_and( PeriodicityIndex, 0xff ); /* Q0 */ assert( 0 <= LtpPitchIndex && LtpPitchIndex <= 16 ); assert( 1 <= Multiplier && Multiplier <= ( 1 << NumRatioBits[Bandwidth][LtpPitchIndex] ) ); - *FractionalResolution = kLtpHmFractionalResolution; + *FractionalResolution = kLtpHmFractionalResolution; /* Q0 */ move16(); - *Lag = L_shr( L_mult0( LtpPitchLag, Ratios_fx[Bandwidth][LtpPitchIndex][sub( Multiplier, 1 )] ), 8 ); + *Lag = L_shr( L_mult0( LtpPitchLag, Ratios_fx[Bandwidth][LtpPitchIndex][Multiplier - 1] ), 8 ); /* Q0 */ move32(); } ELSE { IF( LT_16( PeriodicityIndex, 16 ) ) { - *FractionalResolution = 3; + *FractionalResolution = 3; /* Q0 */ move16(); - Lag16 = add( PeriodicityIndex, GET_ADJ2( 0, 6, 3 ) ); + Lag16 = add( PeriodicityIndex, GET_ADJ2( 0, 6, 3 ) ); /* Q0 */ } ELSE IF( LT_16( PeriodicityIndex, 80 ) ) { - *FractionalResolution = 4; + *FractionalResolution = 4; /* Q0 */ move16(); - Lag16 = add( PeriodicityIndex, GET_ADJ2( 16, 8, 4 ) ); + Lag16 = add( PeriodicityIndex, GET_ADJ2( 16, 8, 4 ) ); /* Q0 */ } ELSE IF( LT_16( PeriodicityIndex, 208 ) ) { - *FractionalResolution = 3; + *FractionalResolution = 3; /* Q0 */ move16(); - Lag16 = add( PeriodicityIndex, GET_ADJ2( 80, 12, 3 ) ); + Lag16 = add( PeriodicityIndex, GET_ADJ2( 80, 12, 3 ) ); /* Q0 */ } ELSE { test(); IF( LT_16( PeriodicityIndex, 224 ) || SmallerLags != 0 ) { - *FractionalResolution = 1; + *FractionalResolution = 1; /* Q0 */ move16(); - Lag16 = add( PeriodicityIndex, GET_ADJ2( 208, 28, 1 ) ); + Lag16 = add( PeriodicityIndex, GET_ADJ2( 208, 28, 1 ) ); /* Q0 */ } ELSE { *FractionalResolution = 0; move16(); - Lag16 = add( PeriodicityIndex, GET_ADJ2( 224, 188, 0 ) ); + Lag16 = add( PeriodicityIndex, GET_ADJ2( 224, 188, 0 ) ); /* Q0 */ } } - *Lag = L_deposit_l( Lag16 ); + *Lag = L_deposit_l( Lag16 ); /* Q0 */ move32(); } } void ConfigureContextHm( - const Word16 NumCoeffs, /* (I) Number of coefficients */ - const Word16 TargetBits, /* (I) Target bit budget (excl. Done flag) */ - const Word16 PeriodicityIndex, /* (I) Pitch related index */ - const Word16 LtpPitchLag, /* (I) TCX-LTP pitch in F.D. */ - CONTEXT_HM_CONFIG *hm_cfg /* (O) Context-based harmonic model configuration */ + const Word16 NumCoeffs, /* (I) Number of coefficients Q0*/ + const Word16 TargetBits, /* (I) Target bit budget (excl. Done flag) Q0*/ + const Word16 PeriodicityIndex, /* (I) Pitch related index Q0*/ + const Word16 LtpPitchLag, /* (I) TCX-LTP pitch in F.D. Q0*/ + CONTEXT_HM_CONFIG *hm_cfg /* (O) Context-based harmonic model configuration */ ) { Word8 Bandwidth, SmallerLags; @@ -97,7 +98,7 @@ void ConfigureContextHm( move16(); if ( GE_16( NumCoeffs, 256 ) ) { - Bandwidth = 1; + Bandwidth = 1; /* Q0 */ move16(); } @@ -106,7 +107,7 @@ void ConfigureContextHm( test(); if ( ( LE_16( TargetBits, kSmallerLagsTargetBitsThreshold ) ) || ( Bandwidth == 0 ) ) { - SmallerLags = 1; + SmallerLags = 1; /* Q0 */ move16(); } @@ -117,28 +118,28 @@ void ConfigureContextHm( &FractionalResolution, &Lag ); /* Set up and fill peakIndices */ - hm_cfg->peakIndices = hm_cfg->indexBuffer; - tmp = hm_cfg->peakIndices; - Limit = L_shl( L_deposit_l( sub( NumCoeffs, 1 ) ), FractionalResolution ); + hm_cfg->peakIndices = hm_cfg->indexBuffer; /* Q0 */ + tmp = hm_cfg->peakIndices; /* Q0 */ + Limit = L_shl( L_deposit_l( sub( NumCoeffs, 1 ) ), FractionalResolution ); /* Q0 */ IF( LT_32( Lag, Limit ) ) { FOR( i = Lag; i < Limit; i += Lag ) { - Index = extract_l( L_shr( i, FractionalResolution ) ); - *tmp++ = sub( Index, 1 ); + Index = extract_l( L_shr( i, FractionalResolution ) ); /* Q0 */ + *tmp++ = sub( Index, 1 ); /* Q0 */ move16(); - *tmp++ = Index; + *tmp++ = Index; /* Q0 */ move16(); - *tmp++ = add( Index, 1 ); + *tmp++ = add( Index, 1 ); /* Q0 */ move16(); } } - hm_cfg->numPeakIndices = (Word16) ( tmp - hm_cfg->indexBuffer ); + hm_cfg->numPeakIndices = (Word16) ( tmp - hm_cfg->indexBuffer ); /* Q0 */ move16(); /* Set up and fill holeIndices */ - hm_cfg->holeIndices = hm_cfg->indexBuffer + hm_cfg->numPeakIndices; - tmp = hm_cfg->holeIndices; + hm_cfg->holeIndices = hm_cfg->indexBuffer + hm_cfg->numPeakIndices; /* Q0 */ + tmp = hm_cfg->holeIndices; /* Q0 */ Index = 0; move16(); IF( hm_cfg->numPeakIndices > 0 ) @@ -147,7 +148,7 @@ void ConfigureContextHm( { FOR( ; Index < hm_cfg->peakIndices[j]; ++Index ) { - *tmp++ = Index; + *tmp++ = Index; /* Q0 */ move16(); } Index = add( Index, 3 ); /* Skip the peak */ @@ -168,19 +169,20 @@ void ConfigureContextHm( } Word16 CountIndexBits( - Word16 Bandwidth, - Word16 PeriodicityIndex ) + Word16 Bandwidth, /* Q0 */ + Word16 PeriodicityIndex /* Q0 */ +) { Word16 result; Word16 PeriodicityIndexS; result = 8; move16(); - PeriodicityIndexS = shr( PeriodicityIndex, 9 ); + PeriodicityIndexS = shr( PeriodicityIndex, 9 ); /* Q0 */ if ( s_and( PeriodicityIndex, kLtpHmFlag ) != 0 ) { - result = NumRatioBits[Bandwidth][PeriodicityIndexS]; + result = NumRatioBits[Bandwidth][PeriodicityIndexS]; /* Q0 */ move16(); } @@ -202,15 +204,15 @@ Word32 tcx_hm_render( f0 = L_shl( lag, sub( 15, fract_res ) ); /* Q31 */ tmp32 = Mpy_32_16_1( f0, -26474 ); - tmp32 = L_shr_r( BASOP_Util_InvLog2( L_shl( tmp32, 7 ) ), 2 ); - tmp32 = L_sub( 603979776L, tmp32 ); - tmp32 = L_add( L_add( tmp32, tmp32 ), Mpy_32_16_1( tmp32, 26214 ) ); - height = round_fx( tmp32 ); /* Q13 */ + tmp32 = L_shr_r( BASOP_Util_InvLog2( L_shl( tmp32, 7 ) ), 2 ); /* Q29 */ + tmp32 = L_sub( 603979776L /* 1.125 in Q29 */, tmp32 ); /* Q29 */ + tmp32 = L_add( L_add( tmp32, tmp32 ), Mpy_32_16_1( tmp32, 26214 ) ); /* Q29 */ + height = round_fx( tmp32 ); /* Q13 */ tmp32 = Mpy_32_16_1( f0, -18910 ); - tmp32 = L_shr_r( BASOP_Util_InvLog2( L_shl( tmp32, 7 ) ), 2 ); - tmp32 = L_sub( 1395864371L, tmp32 ); - PeakDeviation = round_fx( tmp32 ); /* Q14 */ + tmp32 = L_shr_r( BASOP_Util_InvLog2( L_shl( tmp32, 7 ) ), 2 ); /* Q30 */ + tmp32 = L_sub( 1395864371L /* 1.3 in Q30 */, tmp32 ); /* Q30 */ + PeakDeviation = round_fx( tmp32 ); /* Q14 */ IF( GT_16( 13915, PeakDeviation ) ) { @@ -219,26 +221,26 @@ Word32 tcx_hm_render( } ELSE { - tmp = div_s( 13915, PeakDeviation ); - tmp = mult_r( tmp, tmp ); /* Q15 */ + tmp = div_s( 13915, PeakDeviation ); /* Q15 */ + tmp = mult_r( tmp, tmp ); /* Q15 */ } - tmp = div_s( 13915, PeakDeviation ); - tmp = mult_r( tmp, tmp ); /* Q15 */ + tmp = div_s( 13915, PeakDeviation ); /* Q15 */ + tmp = mult_r( tmp, tmp ); /* Q15 */ /* Render the prototype peak */ - p[kTcxHmParabolaHalfWidth] = height; + p[kTcxHmParabolaHalfWidth] = height; /* Q13 */ move16(); FOR( k = 1; k <= kTcxHmParabolaHalfWidth; ++k ) { - p[kTcxHmParabolaHalfWidth + k] = round_fx( Mpy_32_16_1( BASOP_Util_InvLog2( L_shl( L_mult0( i_mult2( negate( k ), k ), tmp ), 10 ) ), height ) ); + p[kTcxHmParabolaHalfWidth + k] = round_fx( Mpy_32_16_1( BASOP_Util_InvLog2( L_shl( L_mult0( i_mult2( negate( k ), k ), tmp ), 10 ) ), height ) ); /* Q13 */ move16(); } /* Mirror */ FOR( k = -kTcxHmParabolaHalfWidth; k < 0; ++k ) { - p[kTcxHmParabolaHalfWidth + k] = p[kTcxHmParabolaHalfWidth - k]; + p[kTcxHmParabolaHalfWidth + k] = p[kTcxHmParabolaHalfWidth - k]; /* Q13 */ move16(); } @@ -265,16 +267,16 @@ void tcx_hm_modify_envelope( FOR( k = 0; k < 2 * kTcxHmParabolaHalfWidth + 1; ++k ) { /* Q24 = Q11 * Q13; 512 = 1.0 in Q24 format */ - inv_shape[k] = div_s( 512, add( 512, mult_r( gain, p[k] ) ) ); + inv_shape[k] = div_s( 512, add( 512, mult_r( gain, p[k] ) ) ); /* Q15 */ move16(); } h = 1; move16(); - k = extract_l( L_shr( lag, fract_res ) ); + k = extract_l( L_shr( lag, fract_res ) ); /* Q0 */ - L_frame_m1 = sub( L_frame, 1 ); - L_frame_for_loop = add( L_frame, kTcxHmParabolaHalfWidth - 1 ); + L_frame_m1 = sub( L_frame, 1 ); /* Q0 */ + L_frame_for_loop = add( L_frame, kTcxHmParabolaHalfWidth - 1 ); /* Q0 */ WHILE( LE_16( k, L_frame_for_loop ) ) { @@ -282,11 +284,11 @@ void tcx_hm_modify_envelope( l2 = s_min( add( k, kTcxHmParabolaHalfWidth ), L_frame_m1 ); FOR( x = l1; x <= l2; ++x ) { - env[x] = Mpy_32_16_1( env[x], inv_shape[add( sub( x, k ), kTcxHmParabolaHalfWidth )] ); + env[x] = Mpy_32_16_1( env[x], inv_shape[( x - k ) + kTcxHmParabolaHalfWidth] ); /* Q16 */ move32(); } - h = add( h, 1 ); - k = extract_l( L_shr( imult3216( lag, h ), fract_res ) ); + h = add( h, 1 ); /* Q0 */ + k = extract_l( L_shr( imult3216( lag, h ), fract_res ) ); /* Q0 */ } } diff --git a/lib_com/cldfb.c b/lib_com/cldfb.c index 9568ab75a..4eae5458f 100644 --- a/lib_com/cldfb.c +++ b/lib_com/cldfb.c @@ -70,7 +70,7 @@ static float GetEnergyCldfb_ivas( float *energyValuesSum, float *energyLookahead * * Conduct complex multiplication *--------------------------------------------------------------------*/ - +#ifndef IVAS_FLOAT_FIXED static void cplxMult( float *yr, /* o : real output */ float *yi, /* o : imag output */ @@ -85,14 +85,14 @@ static void cplxMult( return; } - +#endif /*-------------------------------------------------------------------* * cldfbAnalysis_ivas() * * Conduct multiple overlap complex low delay MDCT *--------------------------------------------------------------------*/ - +#ifndef IVAS_FLOAT_FIXED void cldfbAnalysis_ivas( const float *timeIn, /* i : time buffer */ float **realBuffer, /* o : real value buffer */ @@ -260,7 +260,7 @@ void cldfbAnalysis_ivas( return; } - +#endif #ifdef IVAS_FLOAT_FIXED void cldfbAnalysis_ivas_fx( const Word32 *timeIn_fx, /* i : time buffer Qx */ @@ -477,7 +477,7 @@ void cldfbAnalysis_ivas_fx( * * *--------------------------------------------------------------------*/ - +#ifndef IVAS_FLOAT_FIXED void cldfbAnalysis_ts_ivas( const float *timeIn, /* i : time buffer */ float realBuffer[CLDFB_NO_CHANNELS_MAX], /* o : real value buffer */ @@ -691,7 +691,7 @@ void cldfbAnalysis_ts_ivas( return; } - +#endif #ifdef IVAS_FLOAT_FIXED void cldfbAnalysis_ts_fx( const Word32 *timeIn_fx, @@ -1238,7 +1238,7 @@ void cldfbAnalysis_ts_fx_fixed_q( * * Conduct inverse multple overlap cmplex low delay MDCT *--------------------------------------------------------------------*/ - +#ifndef IVAS_FLOAT_FIXED void cldfbSynthesis_ivas( float **realBuffer, /* i : real values */ float **imagBuffer, /* i : imag values */ @@ -1419,6 +1419,7 @@ void cldfbSynthesis_ivas( return; } +#endif #ifdef IVAS_FLOAT_FIXED void cldfbSynthesis_ivas_fx( Word32 **realBuffer_fx, /* i : real values Qx*/ @@ -3390,7 +3391,7 @@ void cldfb_restore_memory_ivas( * * Resets the memory of filter. *--------------------------------------------------------------------*/ - +#ifndef IVAS_FLOAT_FIXED void cldfb_reset_memory_ivas( HANDLE_CLDFB_FILTER_BANK hs /* i/o: filter bank handle */ ) @@ -3412,6 +3413,7 @@ void cldfb_reset_memory_ivas( return; } +#endif #ifdef IVAS_FLOAT_FIXED void cldfb_reset_memory_fx( HANDLE_CLDFB_FILTER_BANK hs /* i/o: filter bank handle */ diff --git a/lib_com/ivas_prot_fx.h b/lib_com/ivas_prot_fx.h index a9ca1f48d..4a0e4ddb1 100644 --- a/lib_com/ivas_prot_fx.h +++ b/lib_com/ivas_prot_fx.h @@ -3524,4 +3524,27 @@ void ivas_masa_estimate_energy_fx( const Word16 nchan_transport, /* i : number of MASA input/transport channels */ Word16 q_data /* i : q for data_fx */ ); + +void ivas_masa_enc_reconfigure_fx( + Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ +); + +ivas_error ivas_masa_encode_fx( + MASA_ENCODER_HANDLE hMasa, /* i/o: MASA encoder structure */ + IVAS_QMETADATA_HANDLE hQMetaData, /* i/o: q_metadata handle */ + BSTR_ENC_HANDLE hMetaData, /* i/o: Metadata bitstream handle */ + Word16 *nb_bits_metadata, /* o : number of metadata bits written */ + const Word16 nchan_transport, /* i : number of MASA input/transport channels */ + const IVAS_FORMAT ivas_format, /* i : IVAS format */ + const Word32 ivas_total_brate, /* i : IVAS total bitrate */ + const Word16 Opt_DTX_ON, /* i : DTX on flag */ + const Word16 element_mode, /* i : element mode */ + const ISM_MODE ism_mode, /* i : ISM format mode */ + const Word16 nchan_ism, /* i : number of ISM channels */ + ISM_METADATA_HANDLE hIsmMetaData[MAX_NUM_OBJECTS], /* i : ISM metadata handle */ + const Word16 idx_separated_object, /* i : index of the separated object */ + OMASA_ENC_HANDLE hOMasa, /* i : OMASA encoder handle */ + const Word16 ism_imp, /* i : importance of separated object */ + const Word16 flag_omasa_ener_brate /* i : less bitrate for objects in OMASA flag */ +); #endif diff --git a/lib_com/ivas_qmetadata_com.c b/lib_com/ivas_qmetadata_com.c index a16a4be54..552adb118 100644 --- a/lib_com/ivas_qmetadata_com.c +++ b/lib_com/ivas_qmetadata_com.c @@ -177,26 +177,13 @@ ivas_error ivas_qmetadata_allocate_memory( FOR( j = 0; j < nbands; j++ ) { -#ifndef IVAS_FLOAT_FIXED - set_zero( hQMetaData->q_direction[dir].band_data[j].elevation, MAX_PARAM_SPATIAL_SUBFRAMES ); - set_zero( hQMetaData->q_direction[dir].band_data[j].azimuth, MAX_PARAM_SPATIAL_SUBFRAMES ); -#ifdef MSAN_FIX - set_zero( hQMetaData->q_direction[dir].band_data[j].q_elevation, MAX_PARAM_SPATIAL_SUBFRAMES ); - set_zero( hQMetaData->q_direction[dir].band_data[j].q_azimuth, MAX_PARAM_SPATIAL_SUBFRAMES ); -#endif -#else set32_fx( hQMetaData->q_direction[dir].band_data[j].elevation_fx, 0, MAX_PARAM_SPATIAL_SUBFRAMES ); set32_fx( hQMetaData->q_direction[dir].band_data[j].azimuth_fx, 0, MAX_PARAM_SPATIAL_SUBFRAMES ); #ifdef MSAN_FIX set32_fx( hQMetaData->q_direction[dir].band_data[j].q_elevation_fx, 0, MAX_PARAM_SPATIAL_SUBFRAMES ); set32_fx( hQMetaData->q_direction[dir].band_data[j].q_azimuth_fx, 0, MAX_PARAM_SPATIAL_SUBFRAMES ); #endif -#endif -#ifdef IVAS_FLOAT_FIXED set32_fx( hQMetaData->q_direction[dir].band_data[j].energy_ratio_fx, 0, MAX_PARAM_SPATIAL_SUBFRAMES ); -#else - set_zero( hQMetaData->q_direction[dir].band_data[j].energy_ratio, MAX_PARAM_SPATIAL_SUBFRAMES ); -#endif } } @@ -1193,8 +1180,8 @@ void ivas_qmetadata_azimuth_elevation_to_direction_vector( } #else void ivas_qmetadata_azimuth_elevation_to_direction_vector_fx( - const Word32 az, /* i : azimuth */ - const Word32 el, /* i : elevation */ + const Word32 az, /* i : azimuth Q22 */ + const Word32 el, /* i : elevation Q22 */ Word32 *dv /* o : direction vector */ ) { diff --git a/lib_com/ivas_qspherical_com.c b/lib_com/ivas_qspherical_com.c index db931df0f..4c15510fe 100644 --- a/lib_com/ivas_qspherical_com.c +++ b/lib_com/ivas_qspherical_com.c @@ -293,14 +293,20 @@ void small_reduction_direction( { Word16 i, j, k; + test(); FOR( k = 0; ( k < 2 ) && ( *diff > 0 ); k++ ) { + test(); + test(); FOR( i = q_direction->cfg.start_band; ( i < q_direction->cfg.nbands ) && ( *diff > 0 ); i++ ) { + test(); IF( EQ_16( raw_flag[i], 1 ) ) { + test(); FOR( j = 0; ( j < q_direction->cfg.nblocks ) && ( *diff > 0 ); j++ ) { + test(); IF( GT_32( bits_dir[i][j], MASA_MIN_BITS_TF ) ) { bits_dir[i][j] = (UWord16) L_sub( bits_dir[i][j], 1 ); @@ -569,7 +575,7 @@ ELSE } } -*phi_hat = L_add_sat( L_add_sat( ( id_phi * delta_phi_fx ), dd_fx ), DEGREE_180_Q_22 ); +*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 ) ); diff --git a/lib_com/prot.h b/lib_com/prot.h index d286851e0..f895ef5f2 100644 --- a/lib_com/prot.h +++ b/lib_com/prot.h @@ -7926,12 +7926,13 @@ void UnmapIndex_ivas( int32_t *Lag ); void UnmapIndex_fx( - const Word16 PeriodicityIndex, - const Word16 Bandwidth, - const Word16 LtpPitchLag, - const Word8 SmallerLags, - Word16 *FractionalResolution, - Word32 *Lag ); + const Word16 PeriodicityIndex, /* Q0 */ + const Word16 Bandwidth, /* Q0 */ + const Word16 LtpPitchLag, /* Q0 */ + const Word8 SmallerLags, /* Q0 */ + Word16 *FractionalResolution, /* Q0 */ + Word32 *Lag /* Q0 */ +); /*! r: PeriodicityIndex */ int16_t SearchPeriodicityIndex( @@ -7962,8 +7963,9 @@ int16_t CountIndexBits_ivas( const int16_t PeriodicityIndex ); Word16 CountIndexBits_fx( - Word16 Bandwidth, /* 0: NB, 1: (S)WB */ - Word16 PeriodicityIndex ); + Word16 Bandwidth, /* 0: NB, 1: (S)WB Q0*/ + Word16 PeriodicityIndex /* Q0 */ +); int16_t DecodeIndex( Decoder_State *st, @@ -7973,10 +7975,10 @@ int16_t DecodeIndex( #define GET_ADJ( T, L ) GET_ADJ2( T, L, *FractionalResolution ) #define GET_ADJ2( T, L, F ) ( ( ( L ) << ( F ) ) - ( T ) ) -int16_t tcx_hm_render_ivas( - const int16_t lag, /* i : pitch lag */ - const int16_t fract_res, /* i : fractional resolution of the lag */ - Word16 p[] /* o : harmonic model (Q13) */ +Word16 tcx_hm_render_ivas( + const Word16 lag, /* i : pitch lag Q0*/ + const Word16 fract_res, /* i : fractional resolution of the lag Q0*/ + Word16 p[] /* o : harmonic model Q13*/ ); Word32 tcx_hm_render_fx( @@ -7986,12 +7988,12 @@ Word32 tcx_hm_render_fx( ); void tcx_hm_modify_envelope_ivas( - const Word16 gain, /* i : HM gain (Q11) */ - const int16_t lag, - const int16_t fract_res, - const Word16 p[], /* i : harmonic model (Q13) */ - Word32 env[], /* i/o: envelope (Q16) */ - const int16_t L_frame /* i : number of spectral lines */ + const Word16 gain, /* i : HM gain Q11*/ + const Word16 lag, /* Q0 */ + const Word16 fract_res, /* Q0 */ + const Word16 p[], /* i : harmonic model Q13*/ + Word32 env[], /* i/o: envelope Q16*/ + const Word16 L_frame /* i : number of spectral lines Q0*/ ); void tcx_hm_modify_envelope_fx( diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index a148ab903..942135fbd 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -5704,7 +5704,10 @@ Word16 IGFCommonFuncsIGFGetCFTables( ); // ari_fx.c Word32 L_multi31x16_X2( Word16 xh, Word16 xl, Word16 y ); -Word32 mul_sbc_14bits( Word32 r, Word16 c ); +Word32 mul_sbc_14bits( + Word32 r, /* Q0 */ + Word16 c /* Q0 */ +); // window.c void ham_cos_window( Word16 *fh, const Word16 n1, const Word16 n2 ); @@ -8750,26 +8753,28 @@ void getLPCparam_fx( // ari_hm_fx.c void UnmapIndex( - const Word16 PeriodicityIndex, - const Word16 Bandwidth, - const Word16 LtpPitchLag, - const Word16 SmallerLags, - Word16 *FractionalResolution, - Word32 *Lag ); + const Word16 PeriodicityIndex, /* Q0 */ + const Word16 Bandwidth, /* Q0 */ + const Word16 LtpPitchLag, /* Q0 */ + const Word16 SmallerLags, /* Q0 */ + Word16 *FractionalResolution, /* Q0 */ + Word32 *Lag /* Q0 */ +); void ConfigureContextHm( - const Word16 NumCoeffs, /* (I) Number of coefficients */ - const Word16 TargetBits, /* (I) Target bit budget (excl. Done flag) */ - const Word16 PeriodicityIndex, /* (I) Pitch related index */ - const Word16 LtpPitchLag, /* (I) TCX-LTP pitch in F.D. */ - CONTEXT_HM_CONFIG *hm_cfg /* (O) Context-based harmonic model configuration */ + const Word16 NumCoeffs, /* (I) Number of coefficients Q0*/ + const Word16 TargetBits, /* (I) Target bit budget (excl. Done flag) Q0*/ + const Word16 PeriodicityIndex, /* (I) Pitch related index Q0*/ + const Word16 LtpPitchLag, /* (I) TCX-LTP pitch in F.D. Q0*/ + CONTEXT_HM_CONFIG *hm_cfg /* (O) Context-based harmonic model configuration */ ); Word16 CountIndexBits( - Word16 Bandwidth, /* 0: NB, 1: (S)WB */ - Word16 PeriodicityIndex ); + Word16 Bandwidth, /* 0: NB, 1: (S)WB Q0*/ + Word16 PeriodicityIndex /* Q0 */ +); -int tcx_hm_render( +Word32 tcx_hm_render( Word32 lag, /* i: pitch lag Q0 */ Word16 fract_res, /* i: fractional resolution of the lag Q0 */ Word16 p[] /* o: harmonic model Q13 */ @@ -9035,23 +9040,29 @@ void lsf_weight_2st( const Word16 *lsfq, /* i : quantized lsf coefficients (3Q1 /* Returns: index of next coefficient */ Word16 get_next_coeff_mapped( - Word16 ii[2], /* i/o: coefficient indexes */ - Word16 *pp, /* o : peak(1)/hole(0) indicator */ - Word16 *idx, /* o : index in unmapped domain */ - CONTEXT_HM_CONFIG *hm_cfg /* i : HM configuration */ + Word16 ii[2], /* i/o: coefficient indexes Q0*/ + Word16 *pp, /* o : peak(1)/hole(0) indicator Q0*/ + Word16 *idx, /* o : index in unmapped domain Q0*/ + CONTEXT_HM_CONFIG *hm_cfg /* i : HM configuration */ ); /* Returns: index of next coefficient */ Word16 get_next_coeff_unmapped( - Word16 ii[2], /* i/o: coefficient indexes */ - Word16 *pp, /* o : peak(1)/hole(0) indicator */ - Word16 *idx, /* o : index in unmapped domain */ - CONTEXT_HM_CONFIG *hm_cfg /* i : HM configuration */ + Word16 ii[2], /* i/o: coefficient indexes Q0*/ + Word16 *pp, /* o : peak(1)/hole(0) indicator Q0*/ + Word16 *idx, /* o : index in unmapped domain Q0*/ + CONTEXT_HM_CONFIG *hm_cfg /* i : HM configuration */ ); -Word16 update_mixed_context( Word16 ctx, Word16 a ); +Word16 update_mixed_context( + Word16 ctx, /* Q0 */ + Word16 a /* Q0 */ +); -Word32 update_mixed_context_ivas_fx( Word32 ctx, Word16 a ); +Word32 update_mixed_context_ivas_fx( + Word32 ctx, /* Q0 */ + Word16 a /* Q0 */ +); // ACcontextMapping_dec_fx.c @@ -10847,10 +10858,10 @@ ivas_error push_next_bits( /*! r: index of next coefficient */ Word16 get_next_coeff_mapped_ivas( - Word16 ii[2], /* i/o: coefficient indexes */ - Word32 *pp, /* o : peak(1)/hole(0) indicator */ - Word16 *idx, /* o : index in unmapped domain */ - CONTEXT_HM_CONFIG *hm_cfg /* i : HM configuration */ + Word16 ii[2], /* i/o: coefficient indexes Q0*/ + Word32 *pp, /* o : peak(1)/hole(0) indicator Q0*/ + Word16 *idx, /* o : index in unmapped domain Q0*/ + CONTEXT_HM_CONFIG *hm_cfg /* i : HM configuration */ ); void RCcontextMapping_encode2_no_mem_s17_LCS_fx( diff --git a/lib_enc/ivas_enc.c b/lib_enc/ivas_enc.c index c3b8c7cbc..1a5a95af5 100644 --- a/lib_enc/ivas_enc.c +++ b/lib_enc/ivas_enc.c @@ -632,7 +632,7 @@ ivas_error ivas_enc( #else ivas_error ivas_enc( Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ - const Word16 *data, /* i : input signal */ + const Word16 *data, /* i : input signal Q0 */ const Word16 n_samples /* i : number of input samples */ ) { @@ -642,7 +642,9 @@ ivas_error ivas_enc( ENCODER_CONFIG_HANDLE hEncoderConfig; BSTR_ENC_HANDLE hMetaData; Word16 nb_bits_metadata[MAX_SCE + 1]; +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS float *data_f[MAX_INPUT_CHANNELS + MAX_NUM_OBJECTS]; +#endif Word32 *data_fx[MAX_INPUT_CHANNELS + MAX_NUM_OBJECTS]; Word32 ivas_total_brate; ivas_error error; @@ -685,7 +687,9 @@ ivas_error ivas_enc( FOR( n = 0; n < MAX_INPUT_CHANNELS + MAX_NUM_OBJECTS; n++ ) { +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS data_f[n] = st_ivas->p_data_f[n]; // float initialization to be removed +#endif data_fx[n] = st_ivas->p_data_fx[n]; } @@ -697,8 +701,10 @@ ivas_error ivas_enc( { FOR( i = 0; i < n_samples_chan; i++ ) { +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS data_f[n][i] = (float) data[i * nchan_inp + n]; // float initialization to be removed - data_fx[n][i] = L_mult0( data[add( imult1616( i, nchan_inp ), n )], shl( 1, st_ivas->q_data_fx ) ); +#endif + data_fx[n][i] = L_mult0( data[i * nchan_inp + n], shl( 1, st_ivas->q_data_fx ) ); move32(); } n = add( n, 1 ); @@ -708,7 +714,9 @@ ivas_error ivas_enc( { FOR( n = 0; n < nchan_inp; n++ ) { +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS set_f( data_f[n] + n_samples_chan, 0.0f, input_frame - n_samples_chan ); // float initialization to be removed +#endif set32_fx( data_fx[n] + n_samples_chan, 0, sub( input_frame, n_samples_chan ) ); } } @@ -741,19 +749,11 @@ ivas_error ivas_enc( test(); IF( ( EQ_32( ivas_format, SBA_FORMAT ) ) && !( GT_16( st_ivas->sba_analysis_order, 1 ) ) ) { -#ifndef IVAS_FLOAT_FIXED - hp20_flt( data_f[HOA_keep_ind[st_ivas->hSpar->hMdEnc->HOA_md_ind[i]]], input_frame, st_ivas->mem_hp20_in[i], input_Fs ); -#else hp20_fix32( data_fx[HOA_keep_ind[st_ivas->hSpar->hMdEnc->HOA_md_ind[i]]], input_frame, st_ivas->mem_hp20_in_fx[i], input_Fs ); -#endif } ELSE IF( !( EQ_32( ivas_format, MC_FORMAT ) && EQ_16( i, LFE_CHANNEL ) ) ) { -#ifndef IVAS_FLOAT_FIXED - hp20_flt( data_f[i], input_frame, st_ivas->mem_hp20_in[i], input_Fs ); // To be removed -#else hp20_fix32( data_fx[i], input_frame, st_ivas->mem_hp20_in_fx[i], input_Fs ); -#endif } } @@ -768,11 +768,8 @@ ivas_error ivas_enc( /*----------------------------------------------------------------* * write IVAS format signaling *----------------------------------------------------------------*/ -#ifndef IVAS_FLOAT_FIXED - ivas_write_format( st_ivas ); -#else ivas_write_format_fx( st_ivas ); -#endif + /*----------------------------------------------------------------* * Encoding *----------------------------------------------------------------*/ @@ -850,20 +847,28 @@ ivas_error ivas_enc( } } } - else if ( ivas_format == SBA_FORMAT || ivas_format == MASA_FORMAT ) + ELSE IF( EQ_32( ivas_format, SBA_FORMAT ) || EQ_32( ivas_format, MASA_FORMAT ) ) { /* MASA configuration */ - if ( ivas_format == MASA_FORMAT ) + IF( EQ_32( ivas_format, MASA_FORMAT ) ) { - ivas_masa_enc_reconfigure( st_ivas ); + ivas_masa_enc_reconfigure_fx( st_ivas ); } /* SBA/MASA metadata encoding and SBA/MASA metadata bitstream writing */ - hMetaData = ( st_ivas->nSCE > 0 ) ? st_ivas->hSCE[st_ivas->nSCE - 1]->hMetaData : st_ivas->hCPE[st_ivas->nCPE - 1]->hMetaData; + /* hMetaData = ( st_ivas->nSCE > 0 ) ? st_ivas->hSCE[st_ivas->nSCE - 1]->hMetaData : st_ivas->hCPE[st_ivas->nCPE - 1]->hMetaData; */ + IF( st_ivas->nSCE > 0 ) + { + hMetaData = st_ivas->hSCE[st_ivas->nSCE - 1]->hMetaData; + } + ELSE + { + hMetaData = st_ivas->hCPE[st_ivas->nCPE - 1]->hMetaData; + } - if ( st_ivas->hQMetaData != NULL && ivas_format == MASA_FORMAT ) + test(); + IF( st_ivas->hQMetaData != NULL && EQ_32( ivas_format, MASA_FORMAT ) ) { -#ifdef IVAS_FLOAT_FIXED #ifdef IVAS_FLOAT_FIXED_CONVERSIONS for ( i = 0; i < st_ivas->nchan_transport; i++ ) { @@ -879,65 +884,68 @@ ivas_error ivas_enc( fixedToFloat_arrL( st_ivas->hMasa->data.cldfbAnaEnc[i]->cldfb_state_fx, st_ivas->hMasa->data.cldfbAnaEnc[i]->cldfb_state, Q11, st_ivas->hMasa->data.cldfbAnaEnc[i]->cldfb_state_length ); } #endif -#else - ivas_masa_estimate_energy( st_ivas->hMasa, data_f, input_frame, st_ivas->nchan_transport ); /* energy-estimation uses TF-resolution: 4x24 */ -#endif -#ifdef IVAS_FLOAT_FIXED - if ( ( error = ivas_masa_enc_config_fx( st_ivas ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_masa_enc_config_fx( st_ivas ) ) != IVAS_ERR_OK ) { return error; } -#else - if ( ( error = ivas_masa_enc_config( st_ivas ) ) != IVAS_ERR_OK ) + + IF( EQ_16( st_ivas->nchan_transport, 2 ) ) { - return error; + IF( NE_32( ( error = ivas_masa_encode_fx( st_ivas->hMasa, st_ivas->hQMetaData, hMetaData, &nb_bits_metadata[0], st_ivas->nchan_transport, ivas_format, ivas_total_brate, hEncoderConfig->Opt_DTX_ON, st_ivas->hCPE[0]->element_mode, + ISM_MODE_NONE, -1, NULL, -1, NULL, 0, 0 ) ), + IVAS_ERR_OK ) ) + { + return error; + } } -#endif // IVAS_FLOAT_FIXED - - if ( ( error = ivas_masa_encode( st_ivas->hMasa, st_ivas->hQMetaData, hMetaData, &nb_bits_metadata[0], st_ivas->nchan_transport, ivas_format, ivas_total_brate, hEncoderConfig->Opt_DTX_ON, st_ivas->nchan_transport == 2 ? st_ivas->hCPE[0]->element_mode : -1, - ISM_MODE_NONE, -1, NULL, -1, NULL, 0, 0 ) ) != IVAS_ERR_OK ) + ELSE { - return error; + IF( NE_32( ( error = ivas_masa_encode_fx( st_ivas->hMasa, st_ivas->hQMetaData, hMetaData, &nb_bits_metadata[0], st_ivas->nchan_transport, ivas_format, ivas_total_brate, hEncoderConfig->Opt_DTX_ON, -1, + ISM_MODE_NONE, -1, NULL, -1, NULL, 0, 0 ) ), + IVAS_ERR_OK ) ) + { + return error; + } } } - else if ( ivas_format == SBA_FORMAT ) + ELSE IF( EQ_32( ivas_format, SBA_FORMAT ) ) { - if ( ( error = ivas_spar_enc( st_ivas, data_f, input_frame, nb_bits_metadata, hMetaData ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_spar_enc( st_ivas, data_f, input_frame, nb_bits_metadata, hMetaData ) ) != IVAS_ERR_OK ) { return error; } } - if ( ivas_format == SBA_FORMAT ) + IF( EQ_32( ivas_format, SBA_FORMAT ) ) { ivas_sba_getTCs( data_f, st_ivas, input_frame ); } /* core-coding of transport channels */ - if ( st_ivas->nSCE == 1 ) + IF( EQ_16( st_ivas->nSCE, 1 ) ) { - if ( ( error = ivas_sce_enc( st_ivas, 0, data_f[0], input_frame, nb_bits_metadata[0] ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_sce_enc( st_ivas, 0, data_f[0], input_frame, nb_bits_metadata[0] ) ) != IVAS_ERR_OK ) { return error; } } - else if ( st_ivas->nCPE == 1 ) /* Stereo DMX */ + ELSE IF( EQ_16( st_ivas->nCPE, 1 ) ) /* Stereo DMX */ { - if ( ( error = ivas_cpe_enc( st_ivas, 0, data_f[0], data_f[1], input_frame, nb_bits_metadata[0] ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_cpe_enc( st_ivas, 0, data_f[0], data_f[1], input_frame, nb_bits_metadata[0] ) ) != IVAS_ERR_OK ) { return error; } } - else if ( st_ivas->nCPE > 1 ) /* FOA/HOA format */ + ELSE IF( GT_16( st_ivas->nCPE, 1 ) ) /* FOA/HOA format */ { - if ( ( error = ivas_mct_enc( st_ivas, data_f, input_frame, nb_bits_metadata[0] ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_mct_enc( st_ivas, data_f, input_frame, nb_bits_metadata[0] ) ) != IVAS_ERR_OK ) { return error; } } } - else if ( ivas_format == MASA_ISM_FORMAT ) + ELSE IF( EQ_32( ivas_format, MASA_ISM_FORMAT ) ) { float *data_separated_object; Word32 *data_separated_object_fx; @@ -1085,8 +1093,8 @@ ivas_error ivas_enc( } /* Encode MASA parameters and write MASA metadata bitstream */ - if ( ( error = ivas_masa_encode( st_ivas->hMasa, st_ivas->hQMetaData, hMetaData, nb_bits_metadata, st_ivas->nchan_transport, ivas_format, ivas_total_brate, st_ivas->hEncoderConfig->Opt_DTX_ON, st_ivas->nchan_transport == 2 ? st_ivas->hCPE[0]->element_mode : -1, - st_ivas->ism_mode, hEncoderConfig->nchan_ism, st_ivas->hIsmMetaData, idx_separated_object, st_ivas->hOMasa, st_ivas->hIsmMetaData[0]->ism_imp, flag_omasa_ener_brate ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_masa_encode_fx( st_ivas->hMasa, st_ivas->hQMetaData, hMetaData, nb_bits_metadata, st_ivas->nchan_transport, ivas_format, ivas_total_brate, st_ivas->hEncoderConfig->Opt_DTX_ON, st_ivas->nchan_transport == 2 ? st_ivas->hCPE[0]->element_mode : -1, + st_ivas->ism_mode, hEncoderConfig->nchan_ism, st_ivas->hIsmMetaData, idx_separated_object, st_ivas->hOMasa, st_ivas->hIsmMetaData[0]->ism_imp, flag_omasa_ener_brate ) ) != IVAS_ERR_OK ) { return error; } @@ -1360,8 +1368,8 @@ ivas_error ivas_enc( #else ivas_mcmasa_enc( st_ivas->hMcMasa, st_ivas->hQMetaData, st_ivas->hMasa, data_f, input_frame, st_ivas->nchan_transport, nchan_inp ); #endif - if ( ( error = ivas_masa_encode( st_ivas->hMasa, st_ivas->hQMetaData, hMetaData, &nb_bits_metadata[0], st_ivas->nchan_transport, ivas_format, ivas_total_brate, 0, -1, - ISM_MODE_NONE, -1, NULL, -1, NULL, 0, 0 ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_masa_encode_fx( st_ivas->hMasa, st_ivas->hQMetaData, hMetaData, &nb_bits_metadata[0], st_ivas->nchan_transport, ivas_format, ivas_total_brate, 0, -1, + ISM_MODE_NONE, -1, NULL, -1, NULL, 0, 0 ) ) != IVAS_ERR_OK ) { return error; } diff --git a/lib_enc/ivas_masa_enc.c b/lib_enc/ivas_masa_enc.c index a8375d542..9b975d935 100644 --- a/lib_enc/ivas_masa_enc.c +++ b/lib_enc/ivas_masa_enc.c @@ -172,7 +172,132 @@ static void masa_metadata_direction_alignment( MASA_ENCODER_HANDLE hMasa ); * * open and initialize MASA encoder *-----------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +ivas_error ivas_masa_enc_open( + Encoder_Struct *st_ivas /* i/o: IVAS encoder handle */ +) +{ + Word16 i; + MASA_ENCODER_HANDLE hMasa; + ENCODER_CONFIG_HANDLE hEncoderConfig; + ivas_error error; + Word32 ism_total_brate; + + error = IVAS_ERR_OK; + move32(); + + IF( ( hMasa = (MASA_ENCODER_HANDLE) malloc( sizeof( MASA_ENCODER ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for MASA encoder\n" ) ); + } + + hEncoderConfig = st_ivas->hEncoderConfig; + + generate_gridEq_fx( &( hMasa->data.Sph_Grid16 ) ); + + test(); + IF( EQ_32( hEncoderConfig->ivas_format, MASA_FORMAT ) || EQ_32( hEncoderConfig->ivas_format, MASA_ISM_FORMAT ) ) + { + hMasa->data.num_Cldfb_instances = st_ivas->nchan_transport; + move16(); + } + ELSE + { + hMasa->data.num_Cldfb_instances = 0; + move16(); + } + + FOR( i = 0; i < hMasa->data.num_Cldfb_instances; i++ ) + { + IF( ( error = openCldfb_ivas_enc( &( hMasa->data.cldfbAnaEnc[i] ), CLDFB_ANALYSIS, hEncoderConfig->input_Fs, CLDFB_PROTOTYPE_5_00MS ) ) != IVAS_ERR_OK ) + { + return error; + } + } + + ism_total_brate = 0; + move32(); + test(); + test(); + test(); + test(); + IF( EQ_32( hEncoderConfig->ivas_format, MASA_ISM_FORMAT ) && st_ivas->nSCE > 0 && ( EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) || EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) || EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) ) ) + { + FOR( i = 0; i < st_ivas->nSCE; i++ ) + { + ism_total_brate = L_add( ism_total_brate, st_ivas->hSCE[i]->element_brate ); + } + } + + ivas_masa_set_elements_fx( st_ivas->hEncoderConfig->ivas_total_brate, st_ivas->mc_mode, st_ivas->nchan_transport, st_ivas->hQMetaData, &hEncoderConfig->element_mode_init, &st_ivas->nSCE, &st_ivas->nCPE, hEncoderConfig->ivas_format, st_ivas->ism_mode, ism_total_brate ); + + Copy( DirAC_block_grouping, hMasa->config.block_grouping, MAX_PARAM_SPATIAL_SUBFRAMES + 1 ); + Copy( MASA_band_grouping_24, hMasa->config.band_grouping, MASA_FREQUENCY_BANDS + 1 ); + + hMasa->data.onset_detector_1_fx = 0; + hMasa->data.onset_detector_2_fx = 0; + hMasa->data.q_onset_detector = 0; + move32(); + move32(); + move16(); + + set32_fx( hMasa->data.lfeToTotalEnergyRatio_fx, 0, MAX_PARAM_SPATIAL_SUBFRAMES ); + set16_fx( hMasa->data.lfeToTotalEnergyRatio_e, 0, MAX_PARAM_SPATIAL_SUBFRAMES ); + hMasa->data.prevq_lfeToTotalEnergyRatio_fx = 0; + move32(); + + hMasa->data.prevq_lfeIndex = 0; + move16(); + + hMasa->data.sync_state.prev_sim_stop = 0; + hMasa->data.sync_state.prev_offset = 0; + hMasa->data.sync_state.frame_mode = MASA_FRAME_4SF; + move16(); + move16(); + move32(); + + set_zero_fx( hMasa->data.dir_align_state.previous_azi_dir1_fx, MASA_FREQUENCY_BANDS ); + set_zero_fx( hMasa->data.dir_align_state.previous_ele_dir1_fx, MASA_FREQUENCY_BANDS ); + set_zero_fx( hMasa->data.dir_align_state.previous_azi_dir2_fx, MASA_FREQUENCY_BANDS ); + set_zero_fx( hMasa->data.dir_align_state.previous_ele_dir2_fx, MASA_FREQUENCY_BANDS ); + + IF( EQ_32( hEncoderConfig->ivas_format, MASA_ISM_FORMAT ) ) + { + OMASA_ENCODER_DATA_HANDLE hOmasaData; + + IF( ( hOmasaData = (OMASA_ENCODER_DATA_HANDLE) malloc( sizeof( OMASA_ENCODER_DATA_STATE ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for OMASA data encoder\n" ) ); + } + + FOR( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) + { + set32_fx( hOmasaData->masa_to_total_energy_ratio_fx[i], 0, MASA_FREQUENCY_BANDS ); + } + + hOmasaData->lp_noise_CPE_fx = -256; /* -1 in Q8 */ + move16(); + hOmasaData->omasa_stereo_sw_cnt = OMASA_STEREO_SW_CNT_MAX; + move16(); + + FOR( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) + { + set_zero_fx( hOmasaData->energy_ism_fx[i], MASA_FREQUENCY_BANDS ); + set16_fx( hOmasaData->energy_ism_fx_e[i], 0, MASA_FREQUENCY_BANDS ); + } + + hMasa->data.hOmasaData = hOmasaData; + } + ELSE + { + hMasa->data.hOmasaData = NULL; + } + + st_ivas->hMasa = hMasa; + return error; +} +#else ivas_error ivas_masa_enc_open( Encoder_Struct *st_ivas /* i/o: IVAS encoder handle */ ) @@ -326,14 +451,43 @@ ivas_error ivas_masa_enc_open( return error; } - +#endif /*-----------------------------------------------------------------------* * ivas_masa_enc_close() * * close MASA encoder *-----------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +void ivas_masa_enc_close( + MASA_ENCODER_HANDLE *hMasa /* i/o: MASA metadata structure */ +) +{ + Word16 i; + test(); + IF( hMasa == NULL || *hMasa == NULL ) + { + return; + } + + FOR( i = 0; i < ( *hMasa )->data.num_Cldfb_instances; i++ ) + { + deleteCldfb_ivas( &( ( *hMasa )->data.cldfbAnaEnc[i] ) ); + } + + IF( ( *hMasa )->data.hOmasaData != NULL ) + { + free( ( *hMasa )->data.hOmasaData ); + ( *hMasa )->data.hOmasaData = NULL; + } + + free( ( *hMasa ) ); + ( *hMasa ) = NULL; + + return; +} +#else void ivas_masa_enc_close( MASA_ENCODER_HANDLE *hMasa /* i/o: MASA metadata structure */ ) @@ -361,7 +515,7 @@ void ivas_masa_enc_close( return; } - +#endif /*-----------------------------------------------------------------------* * ivas_masa_encode() @@ -370,7 +524,7 @@ void ivas_masa_enc_close( *-----------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED -ivas_error ivas_masa_encode( +ivas_error ivas_masa_encode_fx( MASA_ENCODER_HANDLE hMasa, /* i/o: MASA encoder structure */ IVAS_QMETADATA_HANDLE hQMetaData, /* i/o: q_metadata handle */ BSTR_ENC_HANDLE hMetaData, /* i/o: Metadata bitstream handle */ @@ -1620,6 +1774,7 @@ ivas_error ivas_masa_enc_config_fx( maxBin = extract_l( Mpy_32_32( st_ivas->hEncoderConfig->input_Fs /*q0*/, INV_CLDFB_BANDWIDTH_Q31 /*Q31*/ ) ); /*q0+q31-q31->q0*/ maxBand = 0; move16(); + test(); WHILE( LE_16( maxBand, MASA_FREQUENCY_BANDS ) && LE_16( MASA_band_grouping_24[maxBand], maxBin ) ) { test(); @@ -1645,6 +1800,7 @@ ivas_error ivas_masa_enc_config_fx( Word16 continueLoop; continueLoop = 1; move16(); + test(); WHILE( GT_16( maxBand, 5 ) && continueLoop ) { test(); @@ -2862,7 +3018,7 @@ void ivas_masa_combine_directions_fx( move32(); } - if ( numSf != 1 ) + IF( NE_16( numSf, 1 ) ) { importance_fx[i] = L_shr( importance_fx[i], 2 ); move32(); @@ -4777,7 +4933,7 @@ static int16_t encode_lfe_to_total_energy_ratio( * * Reconfigure IVAS MASA encoder *-------------------------------------------------------------------*/ - +#ifndef IVAS_FLOAT_FIXED void ivas_masa_enc_reconfigure( Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ ) @@ -4845,7 +5001,86 @@ void ivas_masa_enc_reconfigure( return; } +#else +void ivas_masa_enc_reconfigure_fx( + Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ +) +{ + Word16 n, tmp; + Word16 sce_id, cpe_id; + Word32 ivas_total_brate; + Word32 ism_total_brate; + Word32 tmp_br, tmp_mod; + ivas_total_brate = st_ivas->hEncoderConfig->ivas_total_brate; + move32(); + + ism_total_brate = 0; + move32(); + test(); + test(); + test(); + test(); + IF( EQ_32( st_ivas->hEncoderConfig->ivas_format, MASA_ISM_FORMAT ) && st_ivas->nSCE > 0 && ( EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) || EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) || EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) ) ) + { + FOR( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ ) + { + ism_total_brate = L_add( ism_total_brate, st_ivas->hSCE[sce_id]->element_brate ); + } + } + + IF( NE_32( ivas_total_brate, st_ivas->hEncoderConfig->last_ivas_total_brate ) ) + { + iDiv_and_mod_32( ivas_total_brate, st_ivas->nchan_transport, &tmp_br, &tmp_mod, 0 ); + FOR( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ ) + { + copy_encoder_config_fx( st_ivas, st_ivas->hSCE[sce_id]->hCoreCoder[0], 0 ); + st_ivas->hSCE[sce_id]->element_brate = tmp_br; + st_ivas->hSCE[sce_id]->hCoreCoder[0]->total_brate = st_ivas->hSCE[sce_id]->element_brate; /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() */ + move32(); + move32(); + } + + FOR( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) + { + st_ivas->hCPE[cpe_id]->element_brate = imult3216( tmp_br, 2 ); //( ivas_total_brate / st_ivas->nchan_transport ) * CPE_CHANNELS; + move32(); + + IF( st_ivas->nCPE > 1 ) + { + tmp = 1; + } + ELSE + { + tmp = CPE_CHANNELS; + } + move16(); + /* prepare bitstream buffers */ + FOR( n = 0; n < CPE_CHANNELS; n++ ) + { + copy_encoder_config_fx( st_ivas, st_ivas->hCPE[cpe_id]->hCoreCoder[n], 0 ); + /* st_ivas->hCPE[cpe_id]->hCoreCoder[n]->total_brate = st_ivas->hCPE[cpe_id]->element_brate / ( st_ivas->nCPE > 1 ? 1 : CPE_CHANNELS ); */ + st_ivas->hCPE[cpe_id]->hCoreCoder[n]->total_brate = L_shr( st_ivas->hCPE[cpe_id]->element_brate, sub( tmp, 1 ) ); /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() */ + move32(); + } + + IF( LT_32( L_sub( ivas_total_brate, ism_total_brate ), MIN_BRATE_MDCT_STEREO ) ) + { + st_ivas->hCPE[cpe_id]->element_mode = IVAS_CPE_DFT; + } + ELSE + { + st_ivas->hCPE[cpe_id]->element_mode = IVAS_CPE_MDCT; + } + move16(); + } + + ivas_masa_set_elements_fx( ivas_total_brate, st_ivas->mc_mode, st_ivas->nchan_transport, st_ivas->hQMetaData, &tmp, &tmp, &tmp, st_ivas->hEncoderConfig->ivas_format, st_ivas->ism_mode, ism_total_brate ); + } + + return; +} +#endif /*-------------------------------------------------------------------* * average_masa_metadata() diff --git a/lib_enc/ivas_qmetadata_enc.c b/lib_enc/ivas_qmetadata_enc.c index bde299111..f34ae9ef0 100644 --- a/lib_enc/ivas_qmetadata_enc.c +++ b/lib_enc/ivas_qmetadata_enc.c @@ -558,7 +558,7 @@ ivas_error ivas_qmetadata_enc_encode_fx( move16(); /* This sets bit budget correctly for the second direction */ - IF( EQ_16( d, 0 ) ) + IF( d == 0 ) { bits_diff[d] = bits_diff_sum; move16(); @@ -714,6 +714,7 @@ ivas_error ivas_qmetadata_enc_encode_fx( } /* Requantized directions */ + test(); IF( LE_16( add( total_bits_1dir, bits_surround_coh ), hQMetaData->qmetadata_max_bit_req ) && GT_16( add( add( add( bits_dir[d], bits_diff[d] ), bits_coherence[d] ), bits_signaling[d] ), total_bits_1dir ) ) { @@ -1447,7 +1448,7 @@ ivas_error ivas_qmetadata_enc_encode_hr_384_512_fx( Word16 ndirections, d; Word16 all_coherence_zero; Word16 bits_ec; - Word32 azimuth_orig_fx[MASA_MAXIMUM_CODING_SUBBANDS][MAX_PARAM_SPATIAL_SUBFRAMES], elevation_orig_fx[MASA_MAXIMUM_CODING_SUBBANDS][MAX_PARAM_SPATIAL_SUBFRAMES]; + Word32 azimuth_orig_fx[MASA_MAXIMUM_CODING_SUBBANDS][MAX_PARAM_SPATIAL_SUBFRAMES], elevation_orig_fx[MASA_MAXIMUM_CODING_SUBBANDS][MAX_PARAM_SPATIAL_SUBFRAMES]; // Q22 ivas_error error; error = IVAS_ERR_OK; @@ -1487,7 +1488,7 @@ ivas_error ivas_qmetadata_enc_encode_hr_384_512_fx( move16(); FOR( i = hQMetaData->q_direction[1].cfg.start_band; i < hQMetaData->q_direction[1].cfg.nbands; i++ ) { - IF( hQMetaData->twoDirBands[i] == 1 ) + IF( EQ_16( hQMetaData->twoDirBands[i], 1 ) ) { Copy32( hQMetaData->q_direction[1].band_data[i].azimuth_fx, hQMetaData->q_direction[1].band_data[d].azimuth_fx, hQMetaData->q_direction[1].cfg.nblocks ); Copy32( hQMetaData->q_direction[1].band_data[i].elevation_fx, hQMetaData->q_direction[1].band_data[d].elevation_fx, hQMetaData->q_direction[1].cfg.nblocks ); @@ -1620,7 +1621,7 @@ void ivas_qmetadata_enc_sid_encode_fx( const Word16 ivas_format /* i : IVAS format */ ) { - Word16 b, m; + Word16 b, m, i; Word16 bit_pos_start; IVAS_QDIRECTION *q_direction; Word16 nbands, nblocks, start_band; @@ -1717,8 +1718,10 @@ void ivas_qmetadata_enc_sid_encode_fx( { WHILE( bits_delta > 0 ) { + test(); FOR( b = start_band; b < nbands && ( bits_delta > 0 ); b++ ) { + test(); IF( LT_16( q_direction->band_data[b].bits_sph_idx[0], 11 ) ) { bits_delta = sub( bits_delta, 1 ); @@ -1732,7 +1735,7 @@ void ivas_qmetadata_enc_sid_encode_fx( { FOR( b = start_band; b < nbands; b++ ) { - q_direction->band_data[b].azimuth_m_alphabet[0] = 1 << ( s_min( 8, q_direction->band_data[b].bits_sph_idx[0] ) ); + q_direction->band_data[b].azimuth_m_alphabet[0] = shl( 1, ( s_min( 8, q_direction->band_data[b].bits_sph_idx[0] ) ) ); move16(); } } @@ -1741,15 +1744,17 @@ void ivas_qmetadata_enc_sid_encode_fx( { WHILE( bits_delta < 0 ) { + test(); FOR( b = nbands - 1; b >= start_band && ( bits_delta < 0 ); b-- ) { + test(); IF( GE_16( q_direction->band_data[b].bits_sph_idx[0], 4 ) ) { bits_delta = add( bits_delta, 1 ); q_direction->band_data[b].bits_sph_idx[0] = sub( q_direction->band_data[b].bits_sph_idx[0], 1 ); IF( q_direction->not_in_2D == 0 ) { - q_direction->band_data[b].azimuth_m_alphabet[0] = 1 << ( s_min( 8, q_direction->band_data[b].bits_sph_idx[0] ) ); + q_direction->band_data[b].azimuth_m_alphabet[0] = shl( 1, ( s_min( 8, q_direction->band_data[b].bits_sph_idx[0] ) ) ); move16(); } } @@ -1765,10 +1770,11 @@ void ivas_qmetadata_enc_sid_encode_fx( bits_diff = add( bits_diff, ivas_qmetadata_encode_quasi_uniform_length( sub( q_direction->band_data[b].energy_ratio_index[0], 4 ), DIRAC_DIFFUSE_LEVELS - 4 ) ); q_direction->band_data[b].bits_sph_idx[0] = bits_direction_masa[q_direction->band_data[b].energy_ratio_index[0]]; move16(); + move16(); IF( q_direction->not_in_2D == 0 ) { - q_direction->band_data[b].azimuth_m_alphabet[0] = 1 << ( s_min( 5, q_direction->band_data[b].bits_sph_idx[0] ) ); + q_direction->band_data[b].azimuth_m_alphabet[0] = shl( 1, ( s_min( 5, q_direction->band_data[b].bits_sph_idx[0] ) ) ); move16(); bits_dir = add( bits_dir, ivas_qmetadata_encode_quasi_uniform_length( sub( q_direction->band_data[b].azimuth_m_alphabet[0], 1 ), q_direction->band_data[b].azimuth_m_alphabet[0] ) ); } @@ -1784,8 +1790,11 @@ void ivas_qmetadata_enc_sid_encode_fx( test(); WHILE( bits_delta < 0 && ( q_direction->not_in_2D > 0 ) ) { + test(); + test(); FOR( b = nbands - 1; b >= start_band && ( bits_delta < 0 ); b-- ) { + test(); IF( LT_16( q_direction->band_data[b].energy_ratio_index[0], ( DIRAC_DIFFUSE_LEVELS - 1 ) ) ) { bits_delta = add( bits_delta, q_direction->band_data[b].bits_sph_idx[0] ); @@ -1814,7 +1823,7 @@ void ivas_qmetadata_enc_sid_encode_fx( { /*compute the average direction */ ivas_qmetadata_azimuth_elevation_to_direction_vector_fx( q_direction->band_data[b].azimuth_fx[m], q_direction->band_data[b].elevation_fx[m], direction_vector_fx ); - FOR( int i = 0; i < 3; i++ ) + FOR( i = 0; i < 3; i++ ) { avg_direction_vector_fx[i] = L_add( avg_direction_vector_fx[i], L_shr( direction_vector_fx[i], 1 ) ); move32(); @@ -2227,13 +2236,13 @@ Word16 quantize_direction2D_fx( IF( NE_32( mc_format, MC_LS_SETUP_INVALID ) ) { - id_phi = quantize_phi_chan_compand_fx( L_add( phi, 180 << Q22 ), phi_q, no_cw, 0, mc_format ); + id_phi = quantize_phi_chan_compand_fx( L_add( phi, DEGREE_180_Q_22 ), phi_q, no_cw, 0, mc_format ); } ELSE { - id_phi = quantize_phi_enc_fx( L_add( phi, 180 << Q22 ), 0, phi_q, no_cw ); + id_phi = quantize_phi_enc_fx( L_add( phi, DEGREE_180_Q_22 ), 0, phi_q, no_cw ); } - *phi_q = L_sub( *phi_q, 180 << Q22 ); + *phi_q = L_sub( *phi_q, DEGREE_180_Q_22 ); move32(); *index_phi = ivas_qmetadata_reorder_generic( sub( id_phi, shr( no_cw, 1 ) ) ); @@ -2517,10 +2526,10 @@ static void ivas_qmetadata_quantize_diffuseness_nrg_ratios_hr_512( #ifdef IVAS_FLOAT_FIXED static void ivas_qmetadata_quantize_diffuseness_nrg_ratios_fx( IVAS_QMETADATA_HANDLE hQMetaData, - int16_t *needed_bits, - int16_t *nbits_diff, - int16_t *dfRatioBits, - const int16_t hodirac_flag ) + Word16 *needed_bits, + Word16 *nbits_diff, + Word16 *dfRatioBits, + const Word16 hodirac_flag ) { Word16 j, k, dir2band; Word16 index_dirRatio1Inv, index_dirRatio2Inv, index_dirRatio1Inv_mod, index_dirRatio2Inv_mod; @@ -2531,10 +2540,16 @@ static void ivas_qmetadata_quantize_diffuseness_nrg_ratios_fx( needed_bits[0] = 0; needed_bits[1] = 0; dir2band = 0; + move16(); + move16(); + move16(); + move16(); + move16(); FOR( j = hQMetaData->q_direction[0].cfg.start_band; j < hQMetaData->q_direction[0].cfg.nbands; ++j ) { - IF( hQMetaData->no_directions == 2 && hQMetaData->twoDirBands[j] == 1 ) + test(); + IF( EQ_16( hQMetaData->no_directions, 2 ) && EQ_16( hQMetaData->twoDirBands[j], 1 ) ) { Word32 diffRatio, dfRatio, dfRatioQ, diffRatioQ, dirRatio1Q, dirRatio2Q; /* Q30 */ Word32 dirRatio1, dirRatio2, sumRatio; /* Q30 */ @@ -2547,22 +2562,34 @@ static void ivas_qmetadata_quantize_diffuseness_nrg_ratios_fx( IF( hodirac_flag ) { /* already encoded as total and ratios in HO-DirAC */ - diffRatio = ( 1 << 30 ) - hQMetaData->q_direction[0].band_data[j].energy_ratio_fx[0]; + diffRatio = L_sub( ONE_IN_Q30, hQMetaData->q_direction[0].band_data[j].energy_ratio_fx[0] ); dfRatio = hQMetaData->q_direction[1].band_data[dir2band].energy_ratio_fx[0]; + move32(); + move32(); } ELSE { - // TODO dirRatio1 = hQMetaData->q_direction[0].band_data[j].energy_ratio_fx[0]; dirRatio2 = hQMetaData->q_direction[1].band_data[dir2band].energy_ratio_fx[0]; - sumRatio = dirRatio1 + dirRatio2; - diffRatio = ( 1 << 30 ) - sumRatio; - dfRatio = sumRatio < EPSILON_FIX ? ( 1 << 29 ) : ( (Word32) div_l( dirRatio1, extract_h( sumRatio ) ) << 15 ); + move32(); + move32(); + sumRatio = L_add( dirRatio1, dirRatio2 ); + diffRatio = L_sub( ONE_IN_Q30, sumRatio ); + IF( LT_32( sumRatio, EPSILON_FIX ) ) + { + dfRatio = ONE_IN_Q30 / 2; // 0.5 in Q30 + move32(); + } + ELSE + { + dfRatio = L_shl( L_deposit_l( div_l( dirRatio1, extract_h( sumRatio ) ) ), 15 ); // Q30 + } } index_diff = masa_sq_fx( diffRatio, diffuseness_thresholds_fx, DIRAC_DIFFUSE_LEVELS ); - diffRatioQ = diffuseness_reconstructions_fx[index_diff]; + diffRatioQ = diffuseness_reconstructions_fx[index_diff]; // Q30 + move32(); IF( hodirac_flag ) { @@ -2574,29 +2601,29 @@ static void ivas_qmetadata_quantize_diffuseness_nrg_ratios_fx( } dfRatioBits[dir2band] = dfRatio_bits; + move16(); - dfRatio_qsteps = ( 1 << dfRatio_bits ); + dfRatio_qsteps = shl( 1, dfRatio_bits ); IF( hodirac_flag ) { - // TODO Word16 dfRatioQ16; /* Q14 */ - dfRatio_index = usquant_fx( extract_h( dfRatio ), &dfRatioQ16, 0, ( div_s( 1, ( dfRatio_qsteps - 1 ) ) >> 2 ), dfRatio_qsteps ); - dfRatioQ = (Word32) dfRatioQ16 << 16; - dirRatio1Q = ( 1 << 30 ) - diffRatioQ; + dfRatio_index = usquant_fx( extract_h( dfRatio ), &dfRatioQ16, 0, shr( div_s( 1, sub( dfRatio_qsteps, 1 ) ), 2 ) /* Q13 */, dfRatio_qsteps ); + dfRatioQ = L_deposit_h( dfRatioQ16 ); // Q30 + dirRatio1Q = L_sub( ONE_IN_Q30, diffRatioQ ); // Q30 dirRatio2Q = dfRatioQ; + move32(); } ELSE { - // TODO Word16 dfRatioQ16; /* Q14 */ - dfRatio_index = usquant_fx( extract_h( dfRatio ), &dfRatioQ16, ( 1 << 13 ), ( div_s( 1, ( dfRatio_qsteps - 1 ) ) >> 3 ), dfRatio_qsteps ); + dfRatio_index = usquant_fx( extract_h( dfRatio ), &dfRatioQ16, ONE_IN_Q13, shr( div_s( 1, sub( dfRatio_qsteps, 1 ) ), 3 ) /* Q12 */, dfRatio_qsteps ); /* Direction quantization requires also separately quantized direct-to-total ratios. Thus, we calculate them. */ - dirRatio1Q = L_shl( Mpy_32_16_1( ( ( 1 << 30 ) - diffRatioQ ), dfRatioQ16 ), 1 ); - dirRatio2Q = ( ( 1 << 30 ) - diffRatioQ ) - dirRatio1Q; + dirRatio1Q = L_shl( Mpy_32_16_1( L_sub( ONE_IN_Q30, diffRatioQ ), dfRatioQ16 ), 1 ); // Q30 + dirRatio2Q = L_sub( L_sub( ONE_IN_Q30, diffRatioQ ), dirRatio1Q ); // Q30 } - index_dirRatio1Inv = masa_sq_fx( ( 1 << 30 ) - dirRatio1Q, diffuseness_thresholds_fx, DIRAC_DIFFUSE_LEVELS ); + index_dirRatio1Inv = masa_sq_fx( L_sub( ONE_IN_Q30, dirRatio1Q ), diffuseness_thresholds_fx, DIRAC_DIFFUSE_LEVELS ); /* Note: To save memory, we store temporarily index_diff and dfRatio_index into first and second direction * energy ratio index variables until they have been encoded. index_dirRatio1Inv and index_dirRatio2Inv are @@ -2605,26 +2632,31 @@ static void ivas_qmetadata_quantize_diffuseness_nrg_ratios_fx( { hQMetaData->q_direction[0].band_data[j].energy_ratio_index[k] = index_diff; hQMetaData->q_direction[0].band_data[j].energy_ratio_fx[k] = dirRatio1Q; + move16(); + move32(); } - nbits_diff[0] += MASA_BITS_ER; + nbits_diff[0] = add( nbits_diff[0], MASA_BITS_ER ); + move16(); IF( hodirac_flag ) { - // TODO Word16 tmp; /* Q14 */ - index_dirRatio2Inv = usquant_fx( extract_h( dirRatio2Q ), &tmp, 0, ( div_s( 1, ( DIRAC_DIFFUSE_LEVELS - 1 ) ) >> 2 ), DIRAC_DIFFUSE_LEVELS ); + index_dirRatio2Inv = usquant_fx( extract_h( dirRatio2Q ), &tmp, 0, shr( div_s( 1, ( DIRAC_DIFFUSE_LEVELS - 1 ) ), 2 ) /* Q13 */, DIRAC_DIFFUSE_LEVELS ); } - else + ELSE { - index_dirRatio2Inv = masa_sq_fx( ( 1 << 30 ) - dirRatio2Q, diffuseness_thresholds_fx, DIRAC_DIFFUSE_LEVELS ); + index_dirRatio2Inv = masa_sq_fx( L_sub( ONE_IN_Q30, dirRatio2Q ), diffuseness_thresholds_fx, DIRAC_DIFFUSE_LEVELS ); } FOR( k = 0; k < hQMetaData->q_direction[1].cfg.nblocks; k++ ) { hQMetaData->q_direction[1].band_data[dir2band].energy_ratio_index[k] = dfRatio_index; hQMetaData->q_direction[1].band_data[dir2band].energy_ratio_fx[k] = dirRatio2Q; + move16(); + move32(); } - nbits_diff[1] += dfRatio_bits; + nbits_diff[1] = add( nbits_diff[1], dfRatio_bits ); + move16(); /* Obtain compensated direct-to-total ratios for direction quantization. This compensates for the * fact that with 2dir data, it is harder to achieve separate high direct-to-total ratio values @@ -2636,33 +2668,45 @@ static void ivas_qmetadata_quantize_diffuseness_nrg_ratios_fx( { hQMetaData->q_direction[0].band_data[j].energy_ratio_index_mod[k] = index_dirRatio1Inv_mod; hQMetaData->q_direction[0].band_data[j].bits_sph_idx[k] = bits_direction_masa[index_dirRatio1Inv_mod]; + move16(); + move16(); } - needed_bits[0] += hQMetaData->q_direction[0].cfg.nblocks * bits_direction_masa[index_dirRatio1Inv_mod]; + needed_bits[0] = add( needed_bits[0], imult1616( hQMetaData->q_direction[0].cfg.nblocks, bits_direction_masa[index_dirRatio1Inv_mod] ) ); + move16(); FOR( k = 0; k < hQMetaData->q_direction[1].cfg.nblocks; k++ ) { hQMetaData->q_direction[1].band_data[dir2band].energy_ratio_index_mod[k] = index_dirRatio2Inv_mod; hQMetaData->q_direction[1].band_data[dir2band].bits_sph_idx[k] = bits_direction_masa[index_dirRatio2Inv_mod]; + move16(); + move16(); } - needed_bits[1] += hQMetaData->q_direction[1].cfg.nblocks * bits_direction_masa[index_dirRatio2Inv_mod]; + needed_bits[1] = add( needed_bits[1], imult1616( hQMetaData->q_direction[1].cfg.nblocks, bits_direction_masa[index_dirRatio2Inv_mod] ) ); + move16(); - dir2band++; + dir2band = add( dir2band, 1 ); } ELSE { - index_dirRatio1Inv = masa_sq_fx( ( 1 << 30 ) - hQMetaData->q_direction[0].band_data[j].energy_ratio_fx[0], diffuseness_thresholds_fx, DIRAC_DIFFUSE_LEVELS ); + index_dirRatio1Inv = masa_sq_fx( L_sub( ONE_IN_Q30, hQMetaData->q_direction[0].band_data[j].energy_ratio_fx[0] ), diffuseness_thresholds_fx, DIRAC_DIFFUSE_LEVELS ); FOR( k = 0; k < hQMetaData->q_direction[0].cfg.nblocks; k++ ) { hQMetaData->q_direction[0].band_data[j].energy_ratio_index[k] = index_dirRatio1Inv; hQMetaData->q_direction[0].band_data[j].energy_ratio_index_mod[k] = index_dirRatio1Inv; - hQMetaData->q_direction[0].band_data[j].energy_ratio_fx[k] = ( 1 << 30 ) - diffuseness_reconstructions_fx[index_dirRatio1Inv]; + hQMetaData->q_direction[0].band_data[j].energy_ratio_fx[k] = L_sub( ONE_IN_Q30, diffuseness_reconstructions_fx[index_dirRatio1Inv] ); hQMetaData->q_direction[0].band_data[j].bits_sph_idx[k] = bits_direction_masa[index_dirRatio1Inv]; + move16(); + move16(); + move32(); + move16(); } - nbits_diff[0] += MASA_BITS_ER; + nbits_diff[0] = add( nbits_diff[0], MASA_BITS_ER ); + move16(); - needed_bits[0] += hQMetaData->q_direction[0].cfg.nblocks * bits_direction_masa[index_dirRatio1Inv]; + needed_bits[0] = add( needed_bits[0], imult1616( hQMetaData->q_direction[0].cfg.nblocks, bits_direction_masa[index_dirRatio1Inv] ) ); + move16(); } } @@ -2836,7 +2880,7 @@ static Word16 ivas_diffuseness_huff_ec_encode_fx( { IF( idx > 0 ) { - push_next_indice( hMetaData, ( 1 << idx ) - 1, idx ); + push_next_indice( hMetaData, (UWord16) L_sub( L_shl( 1, idx ), 1 ), idx ); nbits = add( nbits, idx ); } push_next_indice( hMetaData, 0, 1 ); @@ -2845,7 +2889,7 @@ static Word16 ivas_diffuseness_huff_ec_encode_fx( ELSE { push_next_indice( hMetaData, 511, DIFF_EC_HUFF_GR0_LIMIT + 1 ); - push_next_indice( hMetaData, idx - DIFF_EC_HUFF_GR0_LIMIT - 1, 2 ); + push_next_indice( hMetaData, (UWord16) L_sub( idx, DIFF_EC_HUFF_GR0_LIMIT + 1 ), 2 ); nbits = add( nbits, DIFF_EC_HUFF_GR0_LIMIT + 3 ); } return nbits; @@ -2934,6 +2978,7 @@ static void ivas_diffuseness_huff_ec_prepare_fx( { ui_sh_idx[b] = sub( shl( sh_idx, 1 ), 1 ); } + move16(); if ( GE_32( ui_sh_idx[b], 2 * DIRAC_DIFFUSE_LEVELS - 3 ) ) { bits = 100; /* to avoid difference larger than 6 in absolute value */ @@ -3372,7 +3417,7 @@ static Word16 ivas_qmetadata_entropy_encode_df_ratio_fx( IF( EQ_16( min_index, max_index ) && ec_mode > 0 ) /* all values are equal */ { push_next_indice( hMetaData, 0, 1 ); /* Signal between EC and raw */ - if ( GT_16( ec_mode, 1 ) ) + IF( GT_16( ec_mode, 1 ) ) { /* Only use bit for signaling if necessary */ push_next_indice( hMetaData, 0, 1 ); /* Signal between one value or bandwise diff mode */ @@ -3384,11 +3429,11 @@ static Word16 ivas_qmetadata_entropy_encode_df_ratio_fx( { push_next_indice( hMetaData, 0, 1 ); push_next_indice( hMetaData, 1, 1 ); - ivas_qmetadata_encode_quasi_uniform( hMetaData, min_index, max_alphabet_size - 1 ); + ivas_qmetadata_encode_quasi_uniform( hMetaData, min_index, sub( max_alphabet_size, 1 ) ); FOR( b = start_band; b < nbands; b++ ) { - push_next_indice( hMetaData, q_direction->band_data[b].energy_ratio_index[0] - min_index, 1 ); /* Band-wise offset values */ + push_next_indice( hMetaData, sub( q_direction->band_data[b].energy_ratio_index[0], min_index ), 1 ); /* Band-wise offset values */ } } ELSE /* raw coding */ @@ -3747,7 +3792,7 @@ static Word16 GR_bits_azimuth_context( move16(); FOR( i = 0; i < no_data_in; i++ ) { - IF( data_in[i] < MASA_NO_INDEX ) + IF( LT_32( data_in[i], MASA_NO_INDEX ) ) { no_symb_local[no_data] = no_symb[i]; move16(); @@ -4257,7 +4302,7 @@ static Word16 ivas_qmetadata_entropy_encode_dir_fx( } } - avg_azimuth_index = (UWord16) ( quantize_phi_enc_fx( L_add( avg_azimuth, 180 << Q22 ), 0, &avg_azimuth, avg_azimuth_alphabet ) ); + avg_azimuth_index = (UWord16) ( quantize_phi_enc_fx( L_add( avg_azimuth, DEGREE_180_Q_22 ), 0, &avg_azimuth, avg_azimuth_alphabet ) ); /* Elevation only if not 2D */ IF( q_direction->not_in_2D > 0 ) @@ -4398,9 +4443,9 @@ static Word16 ivas_qmetadata_entropy_encode_dir_fx( test(); IF( GE_16( sub( nbands, start_band ), 5 ) && NE_32( q_direction->cfg.mc_ls_setup, MC_LS_SETUP_INVALID ) && GT_16( nblocks, 1 ) ) { - use_adapt_avg = calc_var_azi_fx( q_direction, diffuseness_index_max_ec_frame, L_sub( avg_azimuth, 180 << Q22 ), &avg_azimuth ); // 180.Q22 + use_adapt_avg = calc_var_azi_fx( q_direction, diffuseness_index_max_ec_frame, L_sub( avg_azimuth, DEGREE_180_Q_22 ), &avg_azimuth ); // 180.Q22 - avg_azimuth_index = (UWord16) ( quantize_phi_enc_fx( L_add( avg_azimuth, 180 << Q22 ), 0, &avg_azimuth, avg_azimuth_alphabet ) ); + avg_azimuth_index = (UWord16) ( quantize_phi_enc_fx( L_add( avg_azimuth, DEGREE_180_Q_22 ), 0, &avg_azimuth, avg_azimuth_alphabet ) ); } avg_azimuth_index_initial = avg_azimuth_index; /* avg_azimuth_index;*/ move16(); @@ -4526,7 +4571,7 @@ static Word16 ivas_qmetadata_entropy_encode_dir_fx( test(); test(); test(); - if ( NE_32( q_direction->cfg.mc_ls_setup, MC_LS_SETUP_INVALID ) && GT_16( dist_count, 4 ) && NE_16( gr_param_azimuth_best, 5 ) && GT_16( nblocks, 1 ) ) + IF( NE_32( q_direction->cfg.mc_ls_setup, MC_LS_SETUP_INVALID ) && GT_16( dist_count, 4 ) && NE_16( gr_param_azimuth_best, 5 ) && GT_16( nblocks, 1 ) ) { azimuth_bits_ec_best = add( azimuth_bits_ec_best, 1 ); } @@ -4598,7 +4643,7 @@ static Word16 ivas_qmetadata_entropy_encode_dir_fx( IF( NE_16( gr_param_azimuth_best, 5 ) ) /* not all zero */ { - FOR( idx = 0; idx < min( nblocks, dist_count ); idx++ ) + FOR( idx = 0; idx < s_min( nblocks, dist_count ); idx++ ) { test(); test(); @@ -5739,6 +5784,18 @@ static Word16 truncGR0_fx( Word32 diff_fx[MAX_PARAM_SPATIAL_SUBFRAMES]; Word16 indx[MAX_PARAM_SPATIAL_SUBFRAMES]; Word32 L_temp; + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); bits = 0; move16(); set_val_Word32( data_hat_fx, 0, len ); @@ -5781,7 +5838,7 @@ static Word16 truncGR0_fx( bits = add( bits, ivas_qmetadata_encode_extended_gr_length( data_idx[i], 8, 0 ) ); // diff[i] = -st[i] - ct[i] * cosf( PI_OVER_180 * ( data[i] - data_hat[i] ) ); /*(data[i] - data_hat[i])*(data[i] - data_hat[i]);*/ L_temp = L_deposit_h( getCosWord16R2( extract_l( L_shr( Mpy_32_16_1( L_sub( data_fx[i], data_hat_fx[i] ), 91 ), 7 ) ) ) ); // Q31 - diff_fx[i] = -L_add( L_shr( st_fx[i], 1 ), L_shr( Mpy_32_32( ct_fx[i], L_temp ), 1 ) ); // Q30 + diff_fx[i] = L_negate( L_add( L_shr( st_fx[i], 1 ), L_shr( Mpy_32_32( ct_fx[i], L_temp ), 1 ) ) ); // Q30 move32(); } @@ -5807,7 +5864,7 @@ static Word16 truncGR0_fx( // diff[indx[i]] = -st[i] - ct[i] * cosf( PI_OVER_180 * ( data[indx[i]] - data_hat[indx[i]] ) ); L_temp = L_deposit_h( getCosWord16R2( extract_l( L_shr( Mpy_32_16_1( L_sub( data_fx[indx[i]], data_hat_fx[indx[i]] ), 91 ), 7 ) ) ) ); // Q31 - diff_fx[indx[i]] = -L_add( L_shr( st_fx[i], 1 ), L_shr( Mpy_32_32( ct_fx[i], L_temp ), 1 ) ); // Q30 + diff_fx[indx[i]] = L_negate( L_add( L_shr( st_fx[i], 1 ), L_shr( Mpy_32_32( ct_fx[i], L_temp ), 1 ) ) ); // Q30 move32(); } IF( LE_16( bits, bits_allowed ) ) @@ -5848,7 +5905,7 @@ static Word16 truncGR0_fx( // diff[indx[i]] = -st[i] - ct[i] * cosf( PI_OVER_180 * ( data[indx[i]] - data_hat[indx[i]] ) ); L_temp = L_deposit_h( getCosWord16R2( extract_l( L_shr( Mpy_32_16_1( L_sub( data_fx[indx[i]], data_hat_fx[indx[i]] ), 91 ), 7 ) ) ) ); // Q31 - diff_fx[indx[i]] = -L_add( L_shr( st_fx[i], 1 ), L_shr( Mpy_32_32( ct_fx[i], L_temp ), 1 ) ); // Q30 + diff_fx[indx[i]] = L_negate( L_add( L_shr( st_fx[i], 1 ), L_shr( Mpy_32_32( ct_fx[i], L_temp ), 1 ) ) ); // Q30 move32(); } @@ -5866,7 +5923,7 @@ static Word16 truncGR0_fx( FOR( i = len - 1; i >= 0; i-- ) { - if ( data_idx[indx[i]] > 0 ) + IF( data_idx[indx[i]] > 0 ) { bits = sub( bits, data_idx[indx[i]] ); data_idx[indx[i]] = 0; @@ -6070,7 +6127,7 @@ static Word16 truncGR0_chan_fx( bits = add( bits, ivas_qmetadata_encode_extended_gr_length( data_idx[i], 9, 0 ) ); // diff[i] = -st[i] - ct[i] * cosf( ( data[i] - data_hat[i] ) * PI_OVER_180 ); L_temp = L_deposit_h( getCosWord16R2( extract_l( L_shr( Mpy_32_16_1( L_sub( data_fx[i], data_hat_fx[i] ), 91 ), 7 ) ) ) ); // Q31 - diff_fx[i] = -L_add( L_shr( st_fx[i], 1 ), L_shr( Mpy_32_32( ct_fx[i], L_temp ), 1 ) ); // Q30 + diff_fx[i] = L_negate( L_add( L_shr( st_fx[i], 1 ), L_shr( Mpy_32_32( ct_fx[i], L_temp ), 1 ) ) ); // Q30 move32(); } @@ -6083,18 +6140,18 @@ static Word16 truncGR0_chan_fx( move16(); idx_crt = -1; move16(); - MVR2R_WORD32( diff_fx, sort_diff_fx, len ); + Copy32( diff_fx, sort_diff_fx, len ); FOR( i = 0; i < len; i++ ) { IF( data_idx[i] > 0 ) { // sort_diff[i] = -st[i] - ct[i] * cosf( ( fabsf( data[i] ) - cb_azi_chan[( ( data_idx[i] + 1 ) >> 1 ) - 1] ) * PI_OVER_180 ); L_temp = L_deposit_h( getCosWord16R2( extract_l( L_shr( Mpy_32_16_1( L_sub( L_abs( data_fx[i] ), cb_azi_chan_fx[( ( data_idx[i] + 1 ) >> 1 ) - 1] ), 91 ), 7 ) ) ) ); // Q31 - sort_diff_fx[i] = -L_add( L_shr( st_fx[i], 1 ), L_shr( Mpy_32_32( ct_fx[i], L_temp ), 1 ) ); // Q30 // Q30 + sort_diff_fx[i] = L_negate( L_add( L_shr( st_fx[i], 1 ), L_shr( Mpy_32_32( ct_fx[i], L_temp ), 1 ) ) ); // Q30 move32(); sum_diff_fx = sum2_f_32_fx( sort_diff_fx, len, gb ); // Q(2*Q30-31-gb)= Q(Q29-gb) Word16 flag = BASOP_Util_Cmp_Mant32Exp( sum_diff_fx, sub( Q31, sub( Q29, gb ) ), min_diff_fx, min_diff_e ); - if ( EQ_16( flag, -1 ) ) + IF( EQ_16( flag, -1 ) ) { min_diff_fx = sum_diff_fx; move32(); @@ -6116,7 +6173,7 @@ static Word16 truncGR0_chan_fx( // diff[idx_crt] = -st[idx_crt] - ct[idx_crt] * cosf( ( data[idx_crt] - data_hat[idx_crt] ) * PI_OVER_180 ); L_temp = L_deposit_h( getCosWord16R2( extract_l( L_shr( Mpy_32_16_1( L_sub( data_fx[idx_crt], data_hat_fx[idx_crt] ), 91 ), 7 ) ) ) ); // Q31 - diff_fx[idx_crt] = -L_add( L_shr( st_fx[idx_crt], 1 ), L_shr( Mpy_32_32( ct_fx[idx_crt], L_temp ), 1 ) ); // Q30 + diff_fx[idx_crt] = L_negate( L_add( L_shr( st_fx[idx_crt], 1 ), L_shr( Mpy_32_32( ct_fx[idx_crt], L_temp ), 1 ) ) ); // Q30 move32(); } ELSE @@ -6127,7 +6184,7 @@ static Word16 truncGR0_chan_fx( IF( GT_16( bits, bits_allowed ) ) { - MVR2R_WORD32( diff_fx, sort_diff_fx, len ); + Copy32( diff_fx, sort_diff_fx, len ); sort_desc_ind_32_fx( sort_diff_fx, len, indx ); FOR( i = len - 1; i >= 0; i-- ) @@ -6360,7 +6417,7 @@ static Word16 common_direction_fx( // dist += ( elevation_orig[k] - theta_cb[i] ) * ( elevation_orig[k] - theta_cb[i] ); dist_fx = L_add( dist_fx, L_shr( Mpy_32_32( L_sub( elevation_orig_fx[k], theta_cb_fx[i] ), L_sub( elevation_orig_fx[k], theta_cb_fx[i] ) ), gb ) ); // Q(2*Q22-31) = Q13-gb } - if ( LT_32( L_shr( dist_fx, sub( sub( Q13, gb ), best_dist_q ) ), best_dist_fx ) ) + IF( LT_32( L_shr( dist_fx, sub( sub( Q13, gb ), best_dist_q ) ), best_dist_fx ) ) { id_th = i; move16(); @@ -6706,7 +6763,7 @@ static Word16 encode_directions_subband_fx( move16(); FOR( k = 0; k < no_subframes; k++ ) { - if ( GT_16( bits_dir0[k], use_vq ) ) + IF( GT_16( bits_dir0[k], use_vq ) ) { use_vq = bits_dir0[k]; move16(); @@ -6717,7 +6774,8 @@ static Word16 encode_directions_subband_fx( IF( GT_16( no_subframes, 1 ) ) { - if ( GT_16( use_vq, 1 ) && LE_16( use_vq, LIMIT_USE_COMMON ) ) + test(); + IF( GT_16( use_vq, 1 ) && LE_16( use_vq, LIMIT_USE_COMMON ) ) { bits_dir0[max_nb_idx] = sub( bits_dir0[max_nb_idx], 1 ); move16(); @@ -6753,8 +6811,8 @@ static Word16 encode_directions_subband_fx( IF( last_subband == 0 ) { - MVR2R_WORD32( elevation_orig_fx, q_direction->band_data[j].elevation_fx, no_subframes ); - MVR2R_WORD32( azimuth_orig_fx, q_direction->band_data[j].azimuth_fx, no_subframes ); + Copy32( elevation_orig_fx, q_direction->band_data[j].elevation_fx, no_subframes ); + Copy32( azimuth_orig_fx, q_direction->band_data[j].azimuth_fx, no_subframes ); joint_encoding_fx( q_direction, j, next_j, coding_subbands, bits_dir0, allowed_bits, hMetaData, &diff ); } ELSE @@ -6777,8 +6835,8 @@ static Word16 encode_directions_subband_fx( ELSE { /* there is only joint coding */ - MVR2R_WORD32( elevation_orig_fx, q_direction->band_data[j].elevation_fx, no_subframes ); - MVR2R_WORD32( azimuth_orig_fx, q_direction->band_data[j].azimuth_fx, no_subframes ); + Copy32( elevation_orig_fx, q_direction->band_data[j].elevation_fx, no_subframes ); + Copy32( azimuth_orig_fx, q_direction->band_data[j].azimuth_fx, no_subframes ); IF( last_subband == 0 ) { @@ -6805,8 +6863,8 @@ static Word16 encode_directions_subband_fx( { /* 1 subframe case */ /* there is only joint coding */ - MVR2R_WORD32( elevation_orig_fx, q_direction->band_data[j].elevation_fx, no_subframes ); - MVR2R_WORD32( azimuth_orig_fx, q_direction->band_data[j].azimuth_fx, no_subframes ); + Copy32( elevation_orig_fx, q_direction->band_data[j].elevation_fx, no_subframes ); + Copy32( azimuth_orig_fx, q_direction->band_data[j].azimuth_fx, no_subframes ); IF( last_subband == 0 ) { @@ -7341,6 +7399,7 @@ static ivas_error requantize_direction_EC_3_fx( } } + test(); IF( LE_16( use_vq, 3 ) && LE_16( allowed_bits, 11 ) ) { @@ -7480,14 +7539,10 @@ static void joint_encoding_fx( q_direction->band_data[j].bits_sph_idx[k] = bits_dir0[k]; move16(); -/* requantize the direction */ -#if 1 + /* requantize the direction */ q_direction->band_data[j].spherical_index[k] = quantize_direction_fx( q_direction->band_data[j].elevation_fx[k], q_direction->band_data[j].azimuth_fx[k], q_direction->band_data[j].bits_sph_idx[k], &q_direction->band_data[j].elevation_fx[k], &q_direction->band_data[j].azimuth_fx[k], &q_direction->band_data[j].elevation_index[k], &q_direction->band_data[j].azimuth_index[k], q_direction->cfg.mc_ls_setup ); -#else - q_direction->band_data[j].spherical_index[k] = quantize_direction( q_direction->band_data[j].elevation[k], q_direction->band_data[j].azimuth[k], q_direction->band_data[j].bits_sph_idx[k], &q_direction->band_data[j].elevation[k], - &q_direction->band_data[j].azimuth[k], &q_direction->band_data[j].elevation_index[k], &q_direction->band_data[j].azimuth_index[k], q_direction->cfg.mc_ls_setup ); -#endif + move16(); IF( GE_32( bits_dir0[k], 3 ) ) { @@ -7541,7 +7596,7 @@ static void joint_encoding_fx( /* encode indexes for current subband and count the number of bits */ - + test(); IF( EQ_16( q_direction->cfg.nblocks, 1 ) && LE_32( q_direction->band_data[j].bits_sph_idx[0], MASA_MIN_BITS_TF + 1 ) ) { /* encode with fixed rate only if only one subframe and very low number of bits */ @@ -7566,12 +7621,13 @@ static void joint_encoding_fx( move16(); FOR( k = 1; k < q_direction->cfg.nblocks; k++ ) { - IF( NE_32( q_direction->band_data[j].elevation_index[k], q_direction->band_data[j].elevation_index[0] ) ) + if ( NE_32( q_direction->band_data[j].elevation_index[k], q_direction->band_data[j].elevation_index[0] ) ) { same = 0; move16(); } } + test(); IF( EQ_16( same, 1 ) && LT_32( q_direction->band_data[j].elevation_index[0], 4 ) ) { nbits = 3; @@ -7619,6 +7675,7 @@ static void joint_encoding_fx( } } *diff = add( *diff, sub( nbits, allowed_bits ) ); + move16(); update_bits_next_block( q_direction, diff, next_j, coding_subbands, q_direction->cfg.nblocks ); return; @@ -8744,7 +8801,7 @@ static Word16 encode_spread_coherence_1sf_fx( IF( idx_ER > 0 ) { // idx_sp_coh[j] = (uint16_t) roundf( q_direction->coherence_band_data[j].spread_coherence[0] / ( 255.0f / (float) idx_ER ) ); - idx_sp_coh[j] = extract_l( Mpy_32_32_r( imult1616( q_direction->coherence_band_data[j].spread_coherence[0], idx_ER ), 8421505 ) ); + idx_sp_coh[j] = extract_l( Mpy_32_32_r( imult1616( q_direction->coherence_band_data[j].spread_coherence[0], idx_ER ), 8421505 /* 1/255.f in Q31 */ ) ); move16(); // q_direction->coherence_band_data[j].spread_coherence[0] = (uint8_t) roundf( idx_sp_coh[j] * ( 255.0f / (float) idx_ER ) ); IF( idx_sp_coh[j] ) @@ -8781,12 +8838,12 @@ static Word16 encode_spread_coherence_1sf_fx( nbits_max = 0; move16(); - if ( GT_16( coding_subbands, MASA_LIMIT_NO_BANDS_SUR_COH ) ) + IF( GT_16( coding_subbands, MASA_LIMIT_NO_BANDS_SUR_COH ) ) { j = maximum_s( (Word16 *) idx_sp_coh, coding_subbands, &max_val ); FOR( j = 0; j < coding_subbands; j++ ) { - if ( GT_16( no_cv[j], add( max_val, 1 ) ) ) + IF( GT_16( no_cv[j], add( max_val, 1 ) ) ) { no_cv[j] = add( max_val, 1 ); move16(); @@ -8893,7 +8950,7 @@ static Word16 encode_spread_coherence_1sf_fx( /* write the min */ bits_GR = hMasaMetaData->nb_bits_tot; move16(); - ivas_qmetadata_encode_extended_gr( hMasaMetaData, min_idx, MASA_MAX_NO_CV_SUR_COH + extra_cv, 0 ); + ivas_qmetadata_encode_extended_gr( hMasaMetaData, min_idx, add( MASA_MAX_NO_CV_SUR_COH, extra_cv ), 0 ); nbits = add( nbits, sub( hMasaMetaData->nb_bits_tot, bits_GR ) ); /* write GR data */ @@ -9197,7 +9254,7 @@ static Word16 encode_surround_coherence_fx( j = maximum_s( (Word16 *) idx_sur_coh, coding_subbands, &max_val ); FOR( j = 0; j < coding_subbands; j++ ) { - if ( GT_16( no_cv[j], add( max_val, 1 ) ) ) + IF( GT_16( no_cv[j], add( max_val, 1 ) ) ) { no_cv[j] = add( max_val, 1 ); move16(); @@ -9225,7 +9282,7 @@ static Word16 encode_surround_coherence_fx( /* write max value*/ bits_GR = hMetaData->nb_bits_tot; move16(); - ivas_qmetadata_encode_extended_gr( hMetaData, MASA_MAX_NO_CV_SUR_COH - max_val - 1, MASA_MAX_NO_CV_SUR_COH, 0 ); + ivas_qmetadata_encode_extended_gr( hMetaData, sub( MASA_MAX_NO_CV_SUR_COH - 1, max_val ), MASA_MAX_NO_CV_SUR_COH, 0 ); nbits = add( nbits, sub( hMetaData->nb_bits_tot, bits_GR ) ); } @@ -10509,12 +10566,14 @@ static Word16 ivas_qmetadata_quantize_coherence_fx( IF( LT_16( coding_subbands, coding_subbands_0 ) ) { d = 0; + move16(); FOR( j = 0; j < coding_subbands_0; j++ ) { - if ( EQ_16( hQMetaData->twoDirBands[j], 1 ) ) + IF( EQ_16( hQMetaData->twoDirBands[j], 1 ) ) { - two_dir_band[d++] = j; + two_dir_band[d] = j; move16(); + d = add( d, 1 ); } } } @@ -10569,7 +10628,7 @@ static Word16 ivas_qmetadata_quantize_coherence_fx( { /* make two indxes */ no_cb = 1; - move16(); + move64(); FOR( j = 0; j < coding_subbands / 2; j++ ) { @@ -10587,7 +10646,7 @@ static Word16 ivas_qmetadata_quantize_coherence_fx( nbits = sub( 63, W_norm( W_sub( no_cb, 1 ) ) ); } no_cb = 1; - move16(); + move64(); FOR( j = coding_subbands / 2; j < coding_subbands; j++ ) { @@ -10607,7 +10666,7 @@ static Word16 ivas_qmetadata_quantize_coherence_fx( ELSE { no_cb = 1; - move16(); + move64(); FOR( j = 0; j < coding_subbands; j++ ) { @@ -10631,17 +10690,7 @@ static Word16 ivas_qmetadata_quantize_coherence_fx( FOR( j = 0; j < coding_subbands; j++ ) { /* inverse DCT transform */ - -#ifdef IVAS_FLOAT_FIXED - - /*================================flt-2-fix========================================*/ - // floatToFixed_arrL( dct_coh[j], dct_coh_fx[j], Q21, MAX_PARAM_SPATIAL_SUBFRAMES ); // Q21 is used in decoder hence chosed otherwise function can work with variable Q - /*================================fix-2-flt========================================*/ - invdct4_transform_fx( dct_coh[j], q_direction->coherence_band_data[j].spread_coherence, Q21 ); -#else - invdct4_transform( dct_coh[j], q_direction->coherence_band_data[j].spread_coherence ); -#endif } nbits = encode_coherence_indexesDCT0_fx( idx_dct, coding_subbands, no_cb_vec, hMetaData, *indice_coherence, nbits, nbits1 ); @@ -10665,7 +10714,7 @@ static Word16 ivas_qmetadata_quantize_coherence_fx( move16(); WHILE( k > 0 ) { - push_next_indice( hMetaData, 0, min( 16, k ) ); + push_next_indice( hMetaData, 0, s_min( 16, k ) ); k = sub( k, 16 ); } } @@ -11131,23 +11180,23 @@ static void transform_azimuth_dir2_fx( FOR( b = 0; b < hQMetaData->q_direction[1].cfg.nblocks; b++ ) { Word64 azimuth; - azimuth = W_add( W_deposit32_l( L_sub( hQMetaData->q_direction[1].band_data[i].azimuth_fx[b], hQMetaData->q_direction[0].band_data[dir2_bands[i]].azimuth_fx[b] ) ), 180 << Q22 ); + azimuth = W_add( W_deposit32_l( L_sub( hQMetaData->q_direction[1].band_data[i].azimuth_fx[b], hQMetaData->q_direction[0].band_data[dir2_bands[i]].azimuth_fx[b] ) ), DEGREE_180_Q_22 ); - if ( GE_64( azimuth, 180 << Q22 ) ) + IF( GE_64( azimuth, DEGREE_180_Q_22 ) ) { - azimuth = W_sub( azimuth, 360 << Q22 ); + azimuth = W_sub( azimuth, DEGREE_360_Q_22 ); } - if ( LT_64( azimuth, -( 180 << Q22 ) ) ) + IF( LT_64( azimuth, -DEGREE_180_Q_22 ) ) { - azimuth = W_add( azimuth, 360 << Q22 ); + azimuth = W_add( azimuth, DEGREE_360_Q_22 ); } - if ( GE_64( azimuth, 180 << Q22 ) ) + IF( GE_64( azimuth, DEGREE_180_Q_22 ) ) { - azimuth = W_sub( azimuth, 360 << Q22 ); + azimuth = W_sub( azimuth, DEGREE_360_Q_22 ); } - if ( LT_64( azimuth, -( 180 << Q22 ) ) ) + IF( LT_64( azimuth, -DEGREE_180_Q_22 ) ) { - azimuth = W_add( azimuth, 360 << Q22 ); + azimuth = W_add( azimuth, DEGREE_360_Q_22 ); } hQMetaData->q_direction[1].band_data[i].azimuth_fx[b] = W_extract_l( azimuth ); diff --git a/lib_enc/ivas_qspherical_enc.c b/lib_enc/ivas_qspherical_enc.c index d2804108a..48e4bb93d 100644 --- a/lib_enc/ivas_qspherical_enc.c +++ b/lib_enc/ivas_qspherical_enc.c @@ -206,6 +206,7 @@ void quantize_direction_frame_fx( &q_direction->band_data[i].azimuth_fx[j], &q_direction->band_data[i].elevation_index[j], &q_direction->band_data[i].azimuth_index[j], q_direction->cfg.mc_ls_setup ); + move16(); q_direction->not_in_2D = add( q_direction->not_in_2D, q_direction->band_data[i].elevation_index[j] ); move16(); @@ -216,11 +217,15 @@ void quantize_direction_frame_fx( { q_direction->band_data[i].elevation_m_alphabet[j] = no_theta_masa[bits_direction_masa[0] - 3]; q_direction->band_data[i].azimuth_m_alphabet[j] = no_phi_masa[bits_direction_masa[0] - 1][q_direction->band_data[i].elevation_index[j]]; + move16(); + move16(); } ELSE { - q_direction->band_data[i].elevation_m_alphabet[j] = no_theta_masa[bits_direction_masa[0] - 3] * 2 - 1; + q_direction->band_data[i].elevation_m_alphabet[j] = sub( imult1616( no_theta_masa[bits_direction_masa[0] - 3], 2 ), 1 ); q_direction->band_data[i].azimuth_m_alphabet[j] = no_phi_masa[bits_direction_masa[0] - 1][( q_direction->band_data[i].elevation_index[j] + 1 ) >> 1]; + move16(); + move16(); } } ELSE @@ -234,7 +239,7 @@ void quantize_direction_frame_fx( } ELSE { - q_direction->band_data[i].elevation_m_alphabet[j] = no_theta_masa[bits_direction_masa[idx] - 3] * 2 - 1; + q_direction->band_data[i].elevation_m_alphabet[j] = sub( imult1616( no_theta_masa[bits_direction_masa[idx] - 3], 2 ), 1 ); q_direction->band_data[i].azimuth_m_alphabet[j] = no_phi_masa[bits_direction_masa[idx] - 1][( q_direction->band_data[i].elevation_index[j] + 1 ) >> 1]; move16(); move16(); diff --git a/lib_enc/lib_enc.c b/lib_enc/lib_enc.c index 4ba0f3444..ac29e728e 100644 --- a/lib_enc/lib_enc.c +++ b/lib_enc/lib_enc.c @@ -347,7 +347,62 @@ ivas_error IVAS_ENC_ConfigureForStereo( * * Configure and initialize the combined MASA and ISM encoder. *---------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +ivas_error IVAS_ENC_ConfigureForMASAObjects( + IVAS_ENC_HANDLE hIvasEnc, /* i/o: IVAS encoder handle */ + const Word32 inputFs, /* i : input sampling frequency */ + const Word32 bitrate, /* i : requested bitrate of the ouput bitstream */ + const IVAS_ENC_BANDWIDTH maxBandwidth, /* i : bandwidth limitation */ + const IVAS_ENC_DTX_CONFIG dtxConfig, /* i : configuration of DTX, can by set to default by using IVAS_ENC_GetDefaultDtxConfig() */ + const UWord16 numObjects, /* i : number of objects to be encoded */ + const Word16 masaVariant /* i : index specifying the number of MASA transport channels */ +) +{ + Encoder_Struct *st_ivas; + ivas_error error; + IF( ( error = doCommonConfigureChecks( hIvasEnc ) ) != IVAS_ERR_OK ) + { + return error; + } + + IF( GT_16( numObjects, MAX_NUM_OBJECTS ) ) + { + return IVAS_ERR_TOO_MANY_INPUTS; + } + st_ivas = hIvasEnc->st_ivas; + SWITCH( masaVariant ) + { + case IVAS_ENC_MASA_2CH: + st_ivas->hEncoderConfig->nchan_inp = add( CPE_CHANNELS, numObjects ); + st_ivas->hEncoderConfig->element_mode_init = IVAS_CPE_DFT; /* initialization only, might be changed later based on element_brate */ + move16(); + move16(); + BREAK; + case IVAS_ENC_MASA_1CH: + st_ivas->hEncoderConfig->nchan_inp = add( 1, numObjects ); + st_ivas->hEncoderConfig->element_mode_init = IVAS_CPE_DFT; /* initialization only, might be changed later based on element_brate */ + move16(); + move16(); + BREAK; + default: + return IVAS_ERR_INVALID_MASA_CONFIG; + BREAK; + } + + st_ivas = hIvasEnc->st_ivas; + + /* Currently this is true but it is already shown in descriptive metadata that there can be inequality for this. */ + st_ivas->nchan_transport = sub( st_ivas->hEncoderConfig->nchan_inp, numObjects ); + st_ivas->hEncoderConfig->ivas_format = MASA_ISM_FORMAT; + st_ivas->hEncoderConfig->nchan_ism = numObjects; + move16(); + move16(); + move16(); + + return configureEncoder( hIvasEnc, inputFs, bitrate, maxBandwidth, dtxConfig, IVAS_ENC_GetDefaultChannelAwareConfig() ); +} +#else ivas_error IVAS_ENC_ConfigureForMASAObjects( IVAS_ENC_HANDLE hIvasEnc, /* i/o: IVAS encoder handle */ const int32_t inputFs, /* i : input sampling frequency */ @@ -395,6 +450,7 @@ ivas_error IVAS_ENC_ConfigureForMASAObjects( return configureEncoder( hIvasEnc, inputFs, bitrate, maxBandwidth, dtxConfig, IVAS_ENC_GetDefaultChannelAwareConfig() ); } +#endif /*---------------------------------------------------------------------* @@ -646,7 +702,56 @@ ivas_error IVAS_ENC_ConfigureForSBAObjects( * * Configure and initialize the MASA encoder. *---------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +ivas_error IVAS_ENC_ConfigureForMasa( + IVAS_ENC_HANDLE hIvasEnc, /* i/o: IVAS encoder handle */ + const Word32 inputFs, /* i : input sampling frequency */ + const Word32 bitrate, /* i : requested bitrate of the output bitstream */ + const bool max_bwidth_user, /* i : shows if bandwidth limitation was set by the user (true) or if default bandwidth was used (false) */ + const IVAS_ENC_BANDWIDTH maxBandwidth, /* i : bandwidth limitation */ + const IVAS_ENC_DTX_CONFIG dtxConfig, /* i : configuration of DTX, can by set to default by using IVAS_ENC_GetDefaultDtxConfig() */ + const IVAS_ENC_MASA_VARIANT masaVariant /* i : type of MASA input (either 1 or 2 channels) */ +) +{ + ENCODER_CONFIG_HANDLE hEncoderConfig; + ivas_error error; + IF( ( error = doCommonConfigureChecks( hIvasEnc ) ) != IVAS_ERR_OK ) + { + return error; + } + + hEncoderConfig = hIvasEnc->st_ivas->hEncoderConfig; + + hEncoderConfig->ivas_format = MASA_FORMAT; + move32(); + + SWITCH( masaVariant ) + { + case IVAS_ENC_MASA_1CH: + hEncoderConfig->nchan_inp = 1; + hEncoderConfig->element_mode_init = IVAS_SCE; + move16(); + move16(); + BREAK; + case IVAS_ENC_MASA_2CH: + hEncoderConfig->nchan_inp = 2; + hEncoderConfig->element_mode_init = IVAS_CPE_DFT; /* initialization only, might be changed later based on element_brate */ + move16(); + move16(); + BREAK; + default: + return IVAS_ERR_INVALID_MASA_CONFIG; + BREAK; + } + + hIvasEnc->maxBandwidthUser = max_bwidth_user; + + error = configureEncoder( hIvasEnc, inputFs, bitrate, maxBandwidth, dtxConfig, IVAS_ENC_GetDefaultChannelAwareConfig() ); + + return error; +} +#else ivas_error IVAS_ENC_ConfigureForMasa( IVAS_ENC_HANDLE hIvasEnc, /* i/o: IVAS encoder handle */ const int32_t inputFs, /* i : input sampling frequency */ @@ -690,6 +795,7 @@ ivas_error IVAS_ENC_ConfigureForMasa( return error; } +#endif /*---------------------------------------------------------------------* @@ -703,12 +809,13 @@ ivas_error IVAS_ENC_FeedMasaMetadata( IVAS_MASA_METADATA_HANDLE hMasaMetadata /* i : MASA metadata for current frame */ ) { - if ( !hIvasEnc->isConfigured ) + IF( !hIvasEnc->isConfigured ) { return IVAS_ERR_NOT_CONFIGURED; } - if ( hIvasEnc->st_ivas->hEncoderConfig->ivas_format != MASA_FORMAT && hIvasEnc->st_ivas->hEncoderConfig->ivas_format != MASA_ISM_FORMAT ) + test(); + IF( NE_32( hIvasEnc->st_ivas->hEncoderConfig->ivas_format, MASA_FORMAT ) && NE_32( hIvasEnc->st_ivas->hEncoderConfig->ivas_format, MASA_ISM_FORMAT ) ) { return IVAS_ERR_METADATA_NOT_EXPECTED; } @@ -2379,6 +2486,7 @@ static ivas_error setChannelAwareConfig_fx( static ivas_error doCommonConfigureChecks( IVAS_ENC_HANDLE hIvasEnc ) { + test(); IF( hIvasEnc == NULL || hIvasEnc->st_ivas == NULL ) { return IVAS_ERR_UNEXPECTED_NULL_POINTER; diff --git a/lib_rend/ivas_efap.c b/lib_rend/ivas_efap.c index 2d0b9e08d..2871969ca 100644 --- a/lib_rend/ivas_efap.c +++ b/lib_rend/ivas_efap.c @@ -2670,7 +2670,22 @@ static void efap_panning_fx( get_poly_gains_fx( P[0], P[1], aziPoly, elePoly, numChan, tmpBuff ); // tmpBuff q31 /* Computing the norm of the tmp buffer */ - normTmpBuff = dotp_fixed( tmpBuff, tmpBuff, numChan ); // q31 + Word64 suma; + suma = Mpy_32_32( tmpBuff[0], tmpBuff[0] ); + FOR( i = 1; i < numChan; i++ ) + { + suma = W_add( suma, Mpy_32_32( tmpBuff[i], tmpBuff[i] ) ); + } + IF( GT_64( suma, MAX_32 ) ) + { + normTmpBuff = MAX_32; + move32(); + } + ELSE + { + normTmpBuff = W_extract_l( suma ); // Q31 + } + Word16 exp = 0; move16(); normTmpBuff = ISqrt32( normTmpBuff, &exp ); // Q=31-exp -- GitLab From f3958a078260f161026ae0bd2e946d6656378f8a Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Mon, 28 Oct 2024 21:18:15 +0530 Subject: [PATCH 053/128] Fix for 3gpp issue 962: Decoder crash for OSBA_ISM1_HOA3 at 80kbps FER in ivas_dirac_dec_binaural_formulate_input_and_target_covariance_matrices_fx() --- lib_rend/ivas_dirac_dec_binaural_functions.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lib_rend/ivas_dirac_dec_binaural_functions.c b/lib_rend/ivas_dirac_dec_binaural_functions.c index 166c9135a..e0d8fa302 100644 --- a/lib_rend/ivas_dirac_dec_binaural_functions.c +++ b/lib_rend/ivas_dirac_dec_binaural_functions.c @@ -2808,9 +2808,12 @@ static void ivas_dirac_dec_binaural_formulate_input_and_target_covariance_matric test(); IF( ( EQ_32( ivas_format, SBA_FORMAT ) || EQ_32( ivas_format, SBA_ISM_FORMAT ) ) && LT_16( bin, BINAURAL_COHERENCE_DIFFERENCE_BINS ) ) { - Word32 diffuseFieldCoherence_fx; - diffuseFieldCoherence_fx = L_add( L_add( Mpy_32_32( hDiracDecBin->hDiffuseDist->diffuseRatioX_fx[bin], hDiracDecBin->diffuseFieldCoherenceX_fx[bin] ), Mpy_32_32( hDiracDecBin->hDiffuseDist->diffuseRatioY_fx[bin], hDiracDecBin->diffuseFieldCoherenceY_fx[bin] ) ), Mpy_32_32( hDiracDecBin->hDiffuseDist->diffuseRatioZ_fx[bin], hDiracDecBin->diffuseFieldCoherenceZ_fx[bin] ) ); - hDiracDecBin->ChCrossReOut_fx[bin] = BASOP_Util_Add_Mant32Exp( hDiracDecBin->ChCrossReOut_fx[bin], hDiracDecBin->ChCrossReOut_e[bin], Mpy_32_32( L_add( Mpy_32_16_1( diffuseFieldCoherence_fx, sub( 32767, surCoh_fx ) ), L_shl( surCoh_fx, 16 ) ), diffEne_fx ), sub( 31, q_diffEne ), &hDiracDecBin->ChCrossReOut_e[bin] ); + Word32 diffuseFieldCoherence_fx, temp; + Word16 tmp_exp; + temp = BASOP_Util_Add_Mant32Exp( Mpy_32_32( hDiracDecBin->hDiffuseDist->diffuseRatioX_fx[bin], hDiracDecBin->diffuseFieldCoherenceX_fx[bin] ), 0, Mpy_32_32( hDiracDecBin->hDiffuseDist->diffuseRatioY_fx[bin], hDiracDecBin->diffuseFieldCoherenceY_fx[bin] ), 0, &tmp_exp ); + diffuseFieldCoherence_fx = BASOP_Util_Add_Mant32Exp( temp, tmp_exp, Mpy_32_32( hDiracDecBin->hDiffuseDist->diffuseRatioZ_fx[bin], hDiracDecBin->diffuseFieldCoherenceZ_fx[bin] ), 0, &tmp_exp ); + temp = BASOP_Util_Add_Mant32Exp( Mpy_32_16_1( diffuseFieldCoherence_fx, sub( 32767, surCoh_fx ) ), tmp_exp, L_shl( surCoh_fx, 16 ), 0, &tmp_exp ); + hDiracDecBin->ChCrossReOut_fx[bin] = BASOP_Util_Add_Mant32Exp( hDiracDecBin->ChCrossReOut_fx[bin], hDiracDecBin->ChCrossReOut_e[bin], Mpy_32_32( temp, diffEne_fx ), add( tmp_exp, sub( 31, q_diffEne ) ), &hDiracDecBin->ChCrossReOut_e[bin] ); } ELSE { -- GitLab From d6078d98eb7a9aad302cc18d97daa39fce06fcc1 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Mon, 28 Oct 2024 21:24:45 +0530 Subject: [PATCH 054/128] Fix for 3GPP issue 966: Decoder crash for OMASA ISM3_1TC with bitrate switching and FER in perform_noise_estimation_dec_ivas_fx() --- lib_dec/fd_cng_dec_fx.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib_dec/fd_cng_dec_fx.c b/lib_dec/fd_cng_dec_fx.c index b6ba82895..51c2c4643 100644 --- a/lib_dec/fd_cng_dec_fx.c +++ b/lib_dec/fd_cng_dec_fx.c @@ -2800,9 +2800,10 @@ void perform_noise_estimation_dec_ivas_fx( } ELSE { - Copy32( msPeriodog, msNoiseEst, npart ); - scale_sig32( &msNoiseEst[npart], sub( NPART_SHAPING, npart ), sub( hFdCngDec->msNoiseEst_exp, hFdCngDec->msPeriodog_exp ) ); - hFdCngDec->msNoiseEst_exp = hFdCngDec->msPeriodog_exp; + Word16 tmp = s_max( sub( hFdCngDec->msNoiseEst_exp, getScaleFactor32( msPeriodog, npart ) ), sub( hFdCngDec->msPeriodog_exp, getScaleFactor32( &msNoiseEst[npart], sub( NPART_SHAPING, npart ) ) ) ); + Copy_Scale_sig32( msPeriodog, msNoiseEst, npart, sub( hFdCngDec->msPeriodog_exp, tmp ) ); + scale_sig32( &msNoiseEst[npart], sub( NPART_SHAPING, npart ), sub( hFdCngDec->msNoiseEst_exp, tmp ) ); + hFdCngDec->msNoiseEst_exp = tmp; move16(); } -- GitLab From f7d3da918b4dc6ed4f5edb44b7fc544d55208fb2 Mon Sep 17 00:00:00 2001 From: Adriana Vasilache Date: Mon, 28 Oct 2024 20:04:32 +0200 Subject: [PATCH 055/128] fix 982 --- lib_com/options.h | 2 +- lib_dec/ivas_masa_dec.c | 6 ++++++ lib_dec/ivas_qmetadata_dec.c | 11 +++++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/lib_com/options.h b/lib_com/options.h index f1023d3b6..3ff81cd74 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -194,7 +194,7 @@ #define NONBE_FIX_943_PORT_1208_DFT_STEREO_PLC_BURST /* Ericsson: BASOP Issue 943, Float Issue 1208, fix for overflow of sample offset counter for burst error in DFT Stereo PLC. */ #define FIX_853_DECODE_MASA_ISM_AZIMUTH_PREC /* Nokia: Fixes ivas_decode_masaism_metadata decision logic change due to precision difference; needs corresponding fix in floating point */ #define FIX_953_WRONG_ENERGY_RATIO_MASA_EXT /* Nok: Fix 953 wrong energy ratio value after shift and cast to Word8 */ - +#define FIX_982_WRONG_DECODED_ENERGY_RATIO /* Nokia: Fix 982 wrong energy in EXT mode and in second direction when present */ /* ################## End DEVELOPMENT switches ######################### */ /* clang-format on */ diff --git a/lib_dec/ivas_masa_dec.c b/lib_dec/ivas_masa_dec.c index f3962ced2..da6d2360e 100644 --- a/lib_dec/ivas_masa_dec.c +++ b/lib_dec/ivas_masa_dec.c @@ -4377,6 +4377,12 @@ static void create_masa_ext_out_meta_fx( { FOR( b_new = bandMap[b_old]; b_new < bandMap[b_old + 1]; b_new++ ) { +#ifdef FIX_982_WRONG_DECODED_ENERGY_RATIO + IF( EQ_32( hQMetaData->q_direction[dir].band_data[b_old].energy_ratio_fx[sf], ONE_IN_Q30 ) ) + { + hQMetaData->q_direction[dir].band_data[b_old].energy_ratio_fx[sf]--; + } +#endif UWord8 tmp = (UWord8) L_shr( hQMetaData->q_direction[dir].band_data[b_old].energy_ratio_fx[sf], Q30 - 8 ); // Q8 move16(); extOutMeta->directToTotalRatio[dir][sf][b_new] = tmp; // Q8 diff --git a/lib_dec/ivas_qmetadata_dec.c b/lib_dec/ivas_qmetadata_dec.c index f213a059d..2e17020cd 100644 --- a/lib_dec/ivas_qmetadata_dec.c +++ b/lib_dec/ivas_qmetadata_dec.c @@ -1725,6 +1725,16 @@ Word16 ivas_qmetadata_dec_decode_hr_384_512( IF( EQ_32( hQMetaData->no_directions, 2 ) ) { #ifdef MSAN_FIX +#ifdef FIX_982_WRONG_DECODED_ENERGY_RATIO + FOR( b = 0; b < hQMetaData->q_direction[0].cfg.nbands; b++ ) + { + FOR( m = 0; m < hQMetaData->q_direction[0].cfg.nblocks; m++ ) + { + hQMetaData->q_direction[1].band_data[b].energy_ratio_fx[m] = W_round64_L( W_nrg_ratio[1][b][m] ); /*Q30*/ + move32(); + } + } +#else FOR( b = 0; b < hQMetaData->q_direction[1].cfg.nbands; b++ ) { FOR( m = 0; m < hQMetaData->q_direction[1].cfg.nblocks; m++ ) @@ -1733,6 +1743,7 @@ Word16 ivas_qmetadata_dec_decode_hr_384_512( move32(); } } +#endif #else FOR( b = 0; b < MASA_MAXIMUM_CODING_SUBBANDS; b++ ) { -- GitLab From 077a57433a28f1fa30f7cf9eff304b1d4c800080 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Tue, 29 Oct 2024 08:50:46 +0530 Subject: [PATCH 056/128] Q info updates for dec and rend files --- lib_com/gs_bitallocation_ivas_fx.c | 1 + lib_com/ivas_cov_smooth.c | 1 + lib_com/ivas_filters.c | 30 +- lib_com/ivas_ism_com.c | 109 +- lib_com/ivas_lfe_com.c | 18 +- lib_com/ivas_masa_com.c | 115 +- lib_com/ivas_mc_param_com.c | 29 +- lib_com/ivas_mct_com.c | 10 +- lib_com/ivas_mdft_imdft.c | 123 +- lib_com/ivas_omasa_com.c | 100 +- lib_com/ivas_pca_tools.c | 137 +- lib_com/ivas_prot.h | 2620 ++------------------ lib_com/ivas_prot_fx.h | 2352 +++++++++++++++++- lib_com/ivas_qmetadata_com.c | 46 +- lib_com/ivas_qspherical_com.c | 58 +- lib_com/ivas_rom_com.c | 233 +- lib_com/ivas_rom_com.h | 270 +- lib_com/ivas_rom_com_fx.c | 33 +- lib_com/ivas_rom_com_fx.h | 6 +- lib_com/ivas_spar_com_quant_util.c | 1 + lib_com/ivas_stereo_ica_com_fx.c | 1 + lib_com/prot_fx.h | 12 +- lib_dec/ACcontextMapping_dec_fx.c | 1 + lib_dec/acelp_core_dec_ivas_fx.c | 1 + lib_dec/ivas_binRenderer_internal.c | 1 + lib_dec/ivas_pca_dec_fx.c | 1 + lib_dec/ivas_qspherical_dec.c | 1 + lib_dec/ivas_range_uni_dec.c | 1 + lib_dec/ivas_sns_dec_fx.c | 1 + lib_dec/ivas_spar_md_dec.c | 2 +- lib_dec/ivas_svd_dec.c | 2 +- lib_dec/ivas_td_low_rate_dec.c | 1 + lib_dec/lsf_dec_fx.c | 1 + lib_enc/cod_tcx.c | 1 + lib_enc/find_uv.c | 1 + lib_enc/ivas_enc_cov_handler.c | 1 + lib_enc/ivas_front_vad.c | 1 + lib_enc/ivas_stereo_adapt_GR_enc.c | 2 +- lib_enc/ivas_stereo_switching_enc.c | 1 + lib_enc/swb_tbe_enc_fx.c | 1 + lib_rend/ivas_crend.c | 1 + lib_rend/ivas_dirac_decorr_dec.c | 1 + lib_rend/ivas_dirac_output_synthesis_dec.c | 1 + lib_rend/ivas_hrtf.c | 1 + lib_rend/ivas_sba_rendering.c | 1 + lib_rend/ivas_vbap.c | 1 + lib_util/hrtf_file_reader.c | 1 + 47 files changed, 3192 insertions(+), 3141 deletions(-) diff --git a/lib_com/gs_bitallocation_ivas_fx.c b/lib_com/gs_bitallocation_ivas_fx.c index e13d04495..f8a45b4f8 100644 --- a/lib_com/gs_bitallocation_ivas_fx.c +++ b/lib_com/gs_bitallocation_ivas_fx.c @@ -10,6 +10,7 @@ #include "ivas_prot.h" /* Function prototypes */ #include "assert.h" /* Debug prototypes */ #include "stl.h" +#include "ivas_prot_fx.h" static void reajust_bits_fx( Word32 *bits_per_bands, const Word16 st_band, const Word16 end_band, const Word16 sum_bit_in, const Word16 bit_bdgt_in ); diff --git a/lib_com/ivas_cov_smooth.c b/lib_com/ivas_cov_smooth.c index 143ac2290..d03d548b6 100644 --- a/lib_com/ivas_cov_smooth.c +++ b/lib_com/ivas_cov_smooth.c @@ -37,6 +37,7 @@ #include "wmc_auto.h" #include "prot.h" #include "prot_fx.h" +#include "ivas_prot_fx.h" /*-----------------------------------------------------------------------------------------* * Local constants diff --git a/lib_com/ivas_filters.c b/lib_com/ivas_filters.c index bc0a2fce2..425149fe0 100644 --- a/lib_com/ivas_filters.c +++ b/lib_com/ivas_filters.c @@ -38,6 +38,7 @@ #include "wmc_auto.h" #ifdef IVAS_FLOAT_FIXED #include "ivas_rom_com.h" +#include "ivas_prot_fx.h" #endif /*------------------------------------------------------------------------------------------* @@ -46,7 +47,12 @@ #ifndef IVAS_FLOAT_FIXED static void ivas_iir_2_filter( ivas_filters_process_state_t *filter_state, float *pIn_Out, const int16_t length, const int16_t stage ); #else -static void ivas_iir_2_filter_fx( ivas_filters_process_state_t *filter_state, Word32 *pIn_Out_fx, const Word16 length, const Word16 stage, Word16 *pIn_Out_e ); +static void ivas_iir_2_filter_fx( + ivas_filters_process_state_t *filter_state, + Word32 *pIn_Out_fx, // Q(31-*pIn_Out_e) + const Word16 length, + const Word16 stage, + Word16 *pIn_Out_e ); #endif /*-----------------------------------------------------------------------------------------* * Function ivas_filters_init() @@ -102,7 +108,7 @@ void ivas_filters_init( #else void ivas_filters_init_fx( ivas_filters_process_state_t *filter_state, /* i/o: filter state handle */ - const Word32 *filt_coeff_fx, /* i : filter coefficients */ + const Word32 *filt_coeff_fx, /* i : filter coefficients Q31- *filt_coeff_e */ const Word16 *filt_coeff_e, /* i : exponents of filter coefficients */ const Word16 order ) /* i : filter order */ { @@ -233,7 +239,7 @@ void ivas_filter_process( #else void ivas_filter_process_fx( ivas_filters_process_state_t *filter_state, /* i/o: filter state handle */ - Word32 *pIn_Out_fx, /* i/o: signal subject to filtering */ + Word32 *pIn_Out_fx, /* i/o: signal subject to filtering Q(q_factor) */ const Word16 length, /* i : filter order */ Word16 q_factor ) { @@ -248,7 +254,7 @@ void ivas_filter_process_fx( /* Scale pIn_Out_fx back to input Q */ FOR( i = 0; i < length; i++ ) { - pIn_Out_fx[i] = L_shr_r_sat( pIn_Out_fx[i], sub( sub( 31, q_factor ), pIn_Out_e[i] ) ); + pIn_Out_fx[i] = L_shr_r_sat( pIn_Out_fx[i], sub( sub( 31, q_factor ), pIn_Out_e[i] ) ); // Q(31-pIn_Out_e[i]) -> Q(q_factor) move32(); } BREAK; @@ -261,7 +267,7 @@ void ivas_filter_process_fx( /* Scale pIn_Out_fx back to input Q */ FOR( i = 0; i < length; i++ ) { - pIn_Out_fx[i] = L_shr_r_sat( pIn_Out_fx[i], sub( sub( 31, q_factor ), pIn_Out_e[i] ) ); + pIn_Out_fx[i] = L_shr_r_sat( pIn_Out_fx[i], sub( sub( 31, q_factor ), pIn_Out_e[i] ) ); // Q(31-pIn_Out_e[i]) -> Q(q_factor) move32(); } BREAK; @@ -308,7 +314,7 @@ static void ivas_iir_2_filter( #else static void ivas_iir_2_filter_fx( ivas_filters_process_state_t *filter_state, - Word32 *pIn_Out_fx, + Word32 *pIn_Out_fx, // Q(31-*pIn_Out_e) const Word16 length, const Word16 stage, Word16 *pIn_Out_e ) @@ -330,23 +336,23 @@ static void ivas_iir_2_filter_fx( tmp_pIn_buf_i_e = pIn_Out_e[i]; move16(); - L_tmp_prod = Mpy_32_32( filter_state->num_fx[stage][0], pIn_fx[i] ); + L_tmp_prod = Mpy_32_32( filter_state->num_fx[stage][0], pIn_fx[i] ); // Q31 -(pIn_Out_e[i]+ filter_state->num_e[stage][0]) L_prod_e = add( pIn_Out_e[i], filter_state->num_e[stage][0] ); - pOut_fx[i] = BASOP_Util_Add_Mant32Exp( filter_state->state_fx[stage][0], filter_state->state_e[stage][0], L_tmp_prod, L_prod_e, &pIn_Out_e[i] ); + pOut_fx[i] = BASOP_Util_Add_Mant32Exp( filter_state->state_fx[stage][0], filter_state->state_e[stage][0], L_tmp_prod, L_prod_e, &pIn_Out_e[i] ); // Q31 - pIn_Out_e[i] move32(); FOR( j = 1; j < filter_state->filt_len; j++ ) { - L_tmp_prod = Mpy_32_32( filter_state->num_fx[stage][j], tmp_pIn_buf_i_fx ); + L_tmp_prod = Mpy_32_32( filter_state->num_fx[stage][j], tmp_pIn_buf_i_fx ); // Q31-L_prod_e L_prod_e = add( filter_state->num_e[stage][j], tmp_pIn_buf_i_e ); - L_tmp = BASOP_Util_Add_Mant32Exp( filter_state->state_fx[stage][j], filter_state->state_e[stage][j], L_tmp_prod, L_prod_e, &L_tmp_e ); + L_tmp = BASOP_Util_Add_Mant32Exp( filter_state->state_fx[stage][j], filter_state->state_e[stage][j], L_tmp_prod, L_prod_e, &L_tmp_e ); // Q31 - L_tmp_e - L_tmp_prod = Mpy_32_32( filter_state->den_fx[stage][j], pOut_fx[i] ); + L_tmp_prod = Mpy_32_32( filter_state->den_fx[stage][j], pOut_fx[i] ); // Q31 - ( pIn_Out_e[i]+filter_state->den_e[stage][j] ) L_prod_e = add( pIn_Out_e[i], filter_state->den_e[stage][j] ); - filter_state->state_fx[stage][j - 1] = BASOP_Util_Add_Mant32Exp( L_tmp, L_tmp_e, L_negate( L_tmp_prod ), L_prod_e, &filter_state->state_e[stage][j - 1] ); + filter_state->state_fx[stage][j - 1] = BASOP_Util_Add_Mant32Exp( L_tmp, L_tmp_e, L_negate( L_tmp_prod ), L_prod_e, &filter_state->state_e[stage][j - 1] ); // Q31 - filter_state->state_e[stage][j - 1] move32(); } } diff --git a/lib_com/ivas_ism_com.c b/lib_com/ivas_ism_com.c index 583051b23..d871ebe6d 100644 --- a/lib_com/ivas_ism_com.c +++ b/lib_com/ivas_ism_com.c @@ -52,10 +52,10 @@ #define BITS_ISM_INACTIVE ( BRATE_ISM_INACTIVE / FRAMES_PER_SEC ) #define BETA_ISM_LOW_IMP 0.6f -#define BETA_ISM_LOW_IMP_Q31 ( 1288490189 ) +#define BETA_ISM_LOW_IMP_Q31 ( 1288490189 ) // 0.6 in Q31 #define BETA_ISM_MEDIUM_IMP 0.8f -#define BETA_ISM_MEDIUM_IMP_Q31 ( 1717986918 ) -#define BETA_ISM_MEDIUM_IMP_BY_8_Q31 ( 214748365 ) +#define BETA_ISM_MEDIUM_IMP_Q31 ( 1717986918 ) // 0.8 in Q31 +#define BETA_ISM_MEDIUM_IMP_BY_8_Q31 ( 214748365 ) // 0.8 in Q29 #define MAX_BRATE_TCX_32k 48000 #define BITS_IVAS_512k ( IVAS_512k / FRAMES_PER_SEC ) @@ -74,8 +74,8 @@ #ifdef IVAS_FLOAT_FIXED void bitbudget_to_brate( - const Word16 x[], /* i : bitbudgets */ - Word32 y[], /* o : bitrates */ + const Word16 x[], /* i : bitbudgets Q0 */ + Word32 y[], /* o : bitrates Q0 */ const Word16 N /* i : number of entries to be converted */ ) { @@ -83,7 +83,7 @@ void bitbudget_to_brate( FOR( i = 0; i < N; i++ ) { - y[i] = FRAMES_PER_SEC * x[i]; + y[i] = L_mult0( FRAMES_PER_SEC, x[i] ); move32(); } @@ -466,10 +466,10 @@ ivas_error ivas_ism_config_fx( { /* combined format: decision about bitrates per channel - variable during the session (at one ivas_total_brate) */ // bits_ism = (Word16) ( ism_total_brate / FRAMES_PER_SEC ); - bits_ism = (Word16) Mpy_32_32( 42949673, ism_total_brate ); - tmp1 = BASOP_Util_Divide1616_Scale( bits_ism, n_ISms, &exp ); + bits_ism = (Word16) Mpy_32_32( 42949673, ism_total_brate ); // 42949673 is 1/FRAMES_PER_SEC in Q31 + tmp1 = BASOP_Util_Divide1616_Scale( bits_ism, n_ISms, &exp ); // Q15 - exp set16_fx( bits_element, shr( tmp1, sub( 15, exp ) ), n_ISms ); - bits_element[n_ISms - 1] = add( bits_element[n_ISms - 1], bits_ism % n_ISms ); + bits_element[n_ISms - 1] = add( bits_element[n_ISms - 1], bits_ism % n_ISms ); // Q0 move16(); /* ISM common signaling bits are counted in MASA MD bit-budget */ @@ -480,17 +480,17 @@ ivas_error ivas_ism_config_fx( // bits_ism = (Word16) ( ism_total_brate / FRAMES_PER_SEC ); // 1 / 50 * 2 ^ 31 -- > 42949673, --> Q31, //(Q31 +Q0) - Q31 --> Q0 - bits_ism = (Word16) Mpy_32_32( 42949673, ism_total_brate ); - tmp1 = BASOP_Util_Divide1616_Scale( bits_ism, n_ISms, &exp ); + bits_ism = (Word16) Mpy_32_32( 42949673, ism_total_brate ); // 42949673 is 1/FRAMES_PER_SEC in Q31 + tmp1 = BASOP_Util_Divide1616_Scale( bits_ism, n_ISms, &exp ); // Q15 - exp set16_fx( bits_element, shr( tmp1, sub( 15, exp ) ), n_ISms ); - bits_element[n_ISms - 1] = add( bits_element[n_ISms - 1], bits_ism % n_ISms ); + bits_element[n_ISms - 1] = add( bits_element[n_ISms - 1], bits_ism % n_ISms ); // Q0 move16(); bitbudget_to_brate( bits_element, element_brate, n_ISms ); /* count ISm common signaling bits */ IF( hIsmMeta != NULL ) { - nb_bits_metadata[0] = add( nb_bits_metadata[0], add( n_ISms * ISM_METADATA_FLAG_BITS, nchan_ism ) ); + nb_bits_metadata[0] = add( nb_bits_metadata[0], add( imult1616( n_ISms, ISM_METADATA_FLAG_BITS ), nchan_ism ) ); move16(); IF( GE_32( ism_total_brate, ISM_EXTENDED_METADATA_BRATE ) ) @@ -534,9 +534,9 @@ ivas_error ivas_ism_config_fx( IF( nb_bits_metadata != NULL ) { bits_side = sum_s( nb_bits_metadata, n_ISms ); - tmp1 = BASOP_Util_Divide1616_Scale( bits_side, n_ISms, &exp ); - set16_fx( nb_bits_metadata, shr( tmp1, ( 15 - exp ) ), n_ISms ); - nb_bits_metadata[n_ISms - 1] = add( nb_bits_metadata[n_ISms - 1], bits_side % n_ISms ); + tmp1 = BASOP_Util_Divide1616_Scale( bits_side, n_ISms, &exp ); // Q15 - exp + set16_fx( nb_bits_metadata, shr( tmp1, sub( 15, exp ) ), n_ISms ); + nb_bits_metadata[n_ISms - 1] = add( nb_bits_metadata[n_ISms - 1], bits_side % n_ISms ); // Q0 move16(); v_sub_s( bits_element, nb_bits_metadata, bits_CoreCoder, n_ISms ); bitbudget_to_brate( bits_CoreCoder, total_brate, n_ISms ); @@ -629,7 +629,7 @@ ivas_error ivas_ism_config_fx( ELSE IF( EQ_16( ism_imp[ch], ISM_MEDIUM_IMP ) ) { // tmp = (Word16) ( BETA_ISM_MEDIUM_IMP * bits_CoreCoder[ch] ); - tmp = extract_l( Mpy_32_32( BETA_ISM_MEDIUM_IMP_BY_8_Q31, L_shl( bits_CoreCoder[ch], Q3 ) ) ); + tmp = extract_l( Mpy_32_32( BETA_ISM_MEDIUM_IMP_BY_8_Q31, L_shl( bits_CoreCoder[ch], Q3 ) ) ); // Q0 tmp = s_max( limit, tmp ); } ELSE /* ism_imp[ch] == ISM_HIGH_IMP */ @@ -638,7 +638,7 @@ ivas_error ivas_ism_config_fx( move16(); } - diff = add( diff, sub( bits_CoreCoder[ch], tmp ) ); + diff = add( diff, sub( bits_CoreCoder[ch], tmp ) ); // Q0 bits_CoreCoder[ch] = tmp; move16(); } @@ -646,8 +646,8 @@ ivas_error ivas_ism_config_fx( test(); IF( diff > 0 && n_higher > 0 ) { - tmp = BASOP_Util_Divide1616_Scale( diff, n_higher, &exp ); - tmp = shr( tmp, sub( 15, exp ) ); + tmp = BASOP_Util_Divide1616_Scale( diff, n_higher, &exp ); // Q15-exp + tmp = shr( tmp, sub( 15, exp ) ); // Q0 FOR( ch = 0; ch < n_ISms; ch++ ) { IF( flag_higher[ch] ) @@ -696,7 +696,7 @@ ivas_error ivas_ism_config_fx( diff = 0; move16(); limit_high = BITS_MAX_BRATE_TCX_32k; - + move16(); FOR( ch = 0; ch < n_ISms; ch++ ) { tmp = (Word16) s_min( bits_CoreCoder[ch], limit_high ); @@ -788,7 +788,7 @@ void ivas_ism_reset_metadata( move32(); hIsmMeta->pitch_fx = 0; move32(); - hIsmMeta->radius_fx = 1 << 9; + hIsmMeta->radius_fx = ONE_IN_Q9; // Q9 move16(); hIsmMeta->ism_metadata_flag = 0; @@ -811,7 +811,7 @@ void ivas_ism_reset_metadata_enc( move32(); hIsmMeta->pitch_fx = 0; move32(); - hIsmMeta->radius_fx = 1 << 9; // Q9 + hIsmMeta->radius_fx = ONE_IN_Q9; // Q9 move16(); hIsmMeta->ism_metadata_flag = 0; move16(); @@ -897,8 +897,8 @@ Word16 ism_quant_meta_fx( { qlow_fx = borders_fx[1]; move32(); - tmp = BASOP_Util_Divide3232_Scale( L_sub( borders_fx[1], borders_fx[0] ), q_step_border_fx, &tmp_e ); - idx_start = shr( tmp, sub( 15, tmp_e ) ); + tmp = BASOP_Util_Divide3232_Scale( L_sub( borders_fx[1], borders_fx[0] ), q_step_border_fx, &tmp_e ); // Q15-tmp_e + idx_start = shr( tmp, sub( 15, tmp_e ) ); // Q0 step_fx = q_step_fx; move32(); } @@ -906,21 +906,21 @@ Word16 ism_quant_meta_fx( { qlow_fx = borders_fx[2]; move32(); - tmp = BASOP_Util_Divide3232_Scale( L_add( L_sub( borders_fx[3], borders_fx[2] ), L_sub( q_step_border_fx, ONE_IN_Q22 ) ), q_step_border_fx, &tmp_e ); - idx_start = sub( cbsize, add( 1, shr( tmp, sub( 15, tmp_e ) ) ) ); + tmp = BASOP_Util_Divide3232_Scale( L_add( L_sub( borders_fx[3], borders_fx[2] ), L_sub( q_step_border_fx, ONE_IN_Q22 ) ), q_step_border_fx, &tmp_e ); // Q15-tmp_e + idx_start = sub( cbsize, add( 1, shr( tmp, sub( 15, tmp_e ) ) ) ); // Q0 step_fx = q_step_border_fx; move32(); } - tmp = BASOP_Util_Divide3232_Scale( L_sub( val, qlow_fx ), step_fx, &tmp_e ); - tmp = shl( tmp, sub( Q1, sub( 15, tmp_e ) ) ); + tmp = BASOP_Util_Divide3232_Scale( L_sub( val, qlow_fx ), step_fx, &tmp_e ); // Q15-tmp_e + tmp = shl( tmp, sub( Q1, sub( 15, tmp_e ) ) ); // Q0 tmp = add( tmp, 1 ); tmp = shr( tmp, 1 ); - idx = add( idx_start, s_max( 0, s_min( sub( cbsize, 1 ), tmp ) ) ); + idx = add( idx_start, s_max( 0, s_min( sub( cbsize, 1 ), tmp ) ) ); // Q0 // idx = idx_start + (int16_t) max( 0.f, min( cbsize - 1, ( ( val - qlow_fx ) / step_fx + 0.5f ) ) ); - *valQ = L_add( imult3216( step_fx, sub( idx, idx_start ) ), qlow_fx ); + *valQ = L_add( imult3216( step_fx, sub( idx, idx_start ) ), qlow_fx ); // Q0 move32(); return idx; @@ -973,29 +973,29 @@ int16_t ism_quant_meta( /*! r: dequantized value */ #ifdef IVAS_FLOAT_FIXED -Word32 ism_dequant_meta_fx( - const Word16 idx, /* i : quantizer index */ - const Word32 borders_fx[], /* i : level borders */ - const Word32 q_step_fx, /* i : quantization step */ - const Word32 q_step_border_fx, /* i : quantization step at the border */ - const Word16 cbsize /* i : codebook size */ +Word32 ism_dequant_meta_fx( /* o : Q22*/ + const Word16 idx, /* i : quantizer index */ + const Word32 borders_fx[], /* i : level borders Q22*/ + const Word32 q_step_fx, /* i : quantization step Q22 */ + const Word32 q_step_border_fx, /* i : quantization step at the border Q22*/ + const Word16 cbsize /* i : codebook size */ ) { Word16 idx_start, tmp1, tmp2, exp1, exp2; Word32 qlow_fx, step_fx, valQ_fx; tmp1 = BASOP_Util_Divide3232_Scale( L_shr( L_sub( borders_fx[1], borders_fx[0] ), 21 ), L_shr( q_step_border_fx, 21 ), &exp1 ); - tmp1 = shr( tmp1, sub( 15, exp1 ) ); + tmp1 = shr( tmp1, sub( 15, exp1 ) ); // Q0 tmp2 = BASOP_Util_Divide3232_Scale( L_shr( L_sub( borders_fx[3], borders_fx[2] ), 21 ), L_shr( q_step_border_fx, 21 ), &exp2 ); - tmp2 = shr( tmp2, sub( 15, exp2 ) ); + tmp2 = shr( tmp2, sub( 15, exp2 ) ); // Q0 IF( LE_16( idx, tmp1 ) ) { - qlow_fx = borders_fx[0]; + qlow_fx = borders_fx[0]; // Q22 idx_start = 0; - step_fx = q_step_border_fx; + step_fx = q_step_border_fx; // Q22 move32(); move32(); @@ -1003,9 +1003,9 @@ Word32 ism_dequant_meta_fx( } ELSE IF( LE_16( idx, sub( sub( cbsize, 1 ), tmp2 ) ) ) { - qlow_fx = borders_fx[1]; + qlow_fx = borders_fx[1]; // Q22 idx_start = tmp1; - step_fx = q_step_fx; + step_fx = q_step_fx; // Q22 move32(); move32(); @@ -1015,14 +1015,14 @@ Word32 ism_dequant_meta_fx( { qlow_fx = borders_fx[2]; idx_start = (Word16) sub( sub( cbsize, 1 ), tmp2 ); - step_fx = q_step_border_fx; + step_fx = q_step_border_fx; // Q22 move32(); move32(); move16(); } - valQ_fx = L_add( sub( idx, idx_start ) * step_fx, qlow_fx ); + valQ_fx = L_add( sub( idx, idx_start ) * step_fx, qlow_fx ); // Q22 return valQ_fx; } @@ -1129,7 +1129,8 @@ void ivas_param_ism_config_fx( move16(); } - hParamIsm->last_dmx_gain_fx = (Word16) 16384; + hParamIsm->last_dmx_gain_fx = (Word16) 16384; // Q15-last_dmx_gain_e + move16(); hParamIsm->last_dmx_gain_e = 1; move16(); set16_fx( hParamIsm->last_cardioid_left_fx, (Word16) 16384, MAX_NUM_OBJECTS ); @@ -1293,9 +1294,9 @@ void update_last_metadata_fx( { IF( EQ_16( updt_flag[ch], 1 ) ) { - hIsmMeta[ch]->last_azimuth_fx = hIsmMeta[ch]->azimuth_fx; + hIsmMeta[ch]->last_azimuth_fx = hIsmMeta[ch]->azimuth_fx; // Q22 move32(); - hIsmMeta[ch]->last_elevation_fx = hIsmMeta[ch]->elevation_fx; + hIsmMeta[ch]->last_elevation_fx = hIsmMeta[ch]->elevation_fx; // Q22 move32(); } } @@ -1315,16 +1316,16 @@ void ivas_get_ism_sid_quan_bitbudget_fx( const Word16 nchan_ism, /* i : number of objects */ Word16 *nBits_azimuth, /* o : number of Q bits for azimuth */ Word16 *nBits_elevation, /* o : number of Q bits for elevation */ - Word32 *q_step_fx, /* o : quantization step */ - Word32 *q_step_border_fx, /* o : quantization step at the border */ + Word32 *q_step_fx, /* o : quantization step Q22*/ + Word32 *q_step_border_fx, /* o : quantization step at the border Q22*/ Word16 *nBits_coh, /* o : number of Q bits for coherence */ Word16 *nBits_sce_id /* o : number of Q bits for sce_id_dtx */ ) { *nBits_azimuth = ISM_DTX_AZI_BITS_HIGH; *nBits_elevation = ISM_DTX_ELE_BITS_HIGH; - *q_step_fx = ISM_Q_STEP_HIGH_FX; - *q_step_border_fx = ISM_Q_STEP_BORDER_HIGH_FX; + *q_step_fx = ISM_Q_STEP_HIGH_FX; // Q22 + *q_step_border_fx = ISM_Q_STEP_BORDER_HIGH_FX; // Q22 *nBits_coh = ISM_DTX_COH_SCA_BITS; *nBits_sce_id = 1; @@ -1339,8 +1340,8 @@ void ivas_get_ism_sid_quan_bitbudget_fx( { *nBits_azimuth = ISM_DTX_AZI_BITS_LOW; *nBits_elevation = ISM_DTX_ELE_BITS_LOW; - *q_step_fx = ISM_Q_STEP_LOW_FX; - *q_step_border_fx = ISM_Q_STEP_BORDER_LOW_FX; + *q_step_fx = ISM_Q_STEP_LOW_FX; // Q22 + *q_step_border_fx = ISM_Q_STEP_BORDER_LOW_FX; // Q22 *nBits_sce_id = 2; move16(); diff --git a/lib_com/ivas_lfe_com.c b/lib_com/ivas_lfe_com.c index 95797ef84..7f68dda86 100644 --- a/lib_com/ivas_lfe_com.c +++ b/lib_com/ivas_lfe_com.c @@ -116,13 +116,13 @@ void ivas_lfe_lpf_select_filt_coeff_fx( SWITCH( sampling_rate ) { case 16000: - *ppFilt_coeff_fx = ivas_lpf_2_butter_16k_fx; + *ppFilt_coeff_fx = ivas_lpf_2_butter_16k_fx; // Q30 BREAK; case 32000: - *ppFilt_coeff_fx = ivas_lpf_2_butter_32k_fx; + *ppFilt_coeff_fx = ivas_lpf_2_butter_32k_fx; // Q30 BREAK; case 48000: - *ppFilt_coeff_fx = ivas_lpf_2_butter_48k_fx; + *ppFilt_coeff_fx = ivas_lpf_2_butter_48k_fx; // Q30 BREAK; default: BREAK; @@ -132,15 +132,15 @@ void ivas_lfe_lpf_select_filt_coeff_fx( SWITCH( sampling_rate ) { case 16000: - *ppFilt_coeff_fx = ivas_lpf_4_butter_16k_sos_fx; + *ppFilt_coeff_fx = ivas_lpf_4_butter_16k_sos_fx; // Q31-ivas_lpf_4_butter_16k_sos_e *ppFilt_coeff_e = ivas_lpf_4_butter_16k_sos_e; BREAK; case 32000: - *ppFilt_coeff_fx = ivas_lpf_4_butter_32k_sos_fx; + *ppFilt_coeff_fx = ivas_lpf_4_butter_32k_sos_fx; // Q31-ivas_lpf_4_butter_32k_sos_e *ppFilt_coeff_e = ivas_lpf_4_butter_32k_sos_e; BREAK; case 48000: - *ppFilt_coeff_fx = ivas_lpf_4_butter_48k_sos_fx; + *ppFilt_coeff_fx = ivas_lpf_4_butter_48k_sos_fx; // Q31-ivas_lpf_4_butter_48k_sos_e *ppFilt_coeff_e = ivas_lpf_4_butter_48k_sos_e; BREAK; default: @@ -172,15 +172,15 @@ void ivas_lfe_window_init_fx( /* Set window coefficients */ IF( EQ_32( sampling_rate, 48000 ) ) { - hLFEWindow->pWindow_coeffs_fx = ivas_lfe_window_coeff_48k_fx; + hLFEWindow->pWindow_coeffs_fx = ivas_lfe_window_coeff_48k_fx; // Q31 } ELSE IF( EQ_32( sampling_rate, 32000 ) ) { - hLFEWindow->pWindow_coeffs_fx = ivas_lfe_window_coeff_32k_fx; + hLFEWindow->pWindow_coeffs_fx = ivas_lfe_window_coeff_32k_fx; // Q31 } ELSE IF( EQ_32( sampling_rate, 16000 ) ) { - hLFEWindow->pWindow_coeffs_fx = ivas_lfe_window_coeff_16k_fx; + hLFEWindow->pWindow_coeffs_fx = ivas_lfe_window_coeff_16k_fx; // Q31 } ELSE { diff --git a/lib_com/ivas_masa_com.c b/lib_com/ivas_masa_com.c index 5d91190bb..fc19d2dc1 100644 --- a/lib_com/ivas_masa_com.c +++ b/lib_com/ivas_masa_com.c @@ -63,9 +63,18 @@ static int16_t quantize_theta_masa( float x, const int16_t no_cb, float *xhat ); static int16_t quantize_phi_masa( float phi, const int16_t flag_delta, float *phi_hat, const int16_t n ); #else -static Word16 quantize_theta_masa_fx( const Word32 x_fx, const Word16 no_cb, Word32 *xhat_fx ); +static Word16 quantize_theta_masa_fx( + const Word32 x_fx, /* i : theta value to be quantized Q22*/ + const Word16 no_cb, /* i : number of codewords */ + Word32 *xhat_fx /* o : quantized value Q22*/ +); -static Word16 quantize_phi_masa_fx( const Word32 phi, const Word16 flag_delta, Word32 *phi_hat, const Word16 n ); +static Word16 quantize_phi_masa_fx( + const Word32 phi_fx, /* i : azimuth value Q22 */ + const Word16 flag_delta, /* i : flag indicating if the azimuth codebook is translated or not */ + Word32 *phi_hat_fx, /* o : quantized azimuth Q22 */ + const Word16 n /* i : azimuth codebook size */ +); static Word32 estim_round[MASA_NO_CIRCLES + 1] = { /* Q0 */ @@ -452,7 +461,7 @@ void ivas_masa_set_elements_fx( *nCPE = 1; move16(); - IF( EQ_16( *element_mode, -1 ) ) + if ( EQ_16( *element_mode, -1 ) ) { *element_mode = IVAS_CPE_DFT; /* To have it initialized in case it was not already. */ move16(); @@ -464,7 +473,7 @@ void ivas_masa_set_elements_fx( test(); test(); test(); - IF( ( EQ_16( ism_mode, ISM_MASA_MODE_DISC ) || EQ_16( ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) || EQ_16( ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) ) && LT_32( L_sub( ivas_total_brate, ism_total_brate ), MIN_BRATE_MDCT_STEREO ) ) + if ( ( EQ_16( ism_mode, ISM_MASA_MODE_DISC ) || EQ_16( ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) || EQ_16( ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) ) && LT_32( L_sub( ivas_total_brate, ism_total_brate ), MIN_BRATE_MDCT_STEREO ) ) { *element_mode = IVAS_CPE_DFT; move16(); @@ -478,7 +487,7 @@ void ivas_masa_set_elements_fx( *nSCE = 0; move16(); - IF( GT_32( ivas_total_brate, MIN_BRATE_MDCT_STEREO ) ) + if ( GT_32( ivas_total_brate, MIN_BRATE_MDCT_STEREO ) ) { *element_mode = IVAS_CPE_MDCT; move16(); @@ -489,7 +498,7 @@ void ivas_masa_set_elements_fx( test(); test(); test(); - IF( EQ_16( ivas_format, MASA_ISM_FORMAT ) && ( EQ_16( ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) || EQ_16( ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) || EQ_16( ism_mode, ISM_MASA_MODE_DISC ) ) ) + if ( EQ_16( ivas_format, MASA_ISM_FORMAT ) && ( EQ_16( ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) || EQ_16( ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) || EQ_16( ism_mode, ISM_MASA_MODE_DISC ) ) ) { /* hQMetaData->bits_frame_nominal -= (int16_t) ( ism_total_brate / FRAMES_PER_SEC ); */ tmp = extract_l( Mpy_32_32( ism_total_brate, ONE_BY_FRAMES_PER_SEC_Q31 ) ); @@ -818,7 +827,7 @@ void ivas_masa_set_coding_config_fx( test(); test(); test(); - IF( ( GT_32( ivas_total_brate, IVAS_96k ) && !config->joinedSubframes ) || ( GT_32( ivas_total_brate, IVAS_80k ) && config->joinedSubframes ) ) + if ( ( GT_32( ivas_total_brate, IVAS_96k ) && !config->joinedSubframes ) || ( GT_32( ivas_total_brate, IVAS_80k ) && config->joinedSubframes ) ) { idx_bands = sub( idx_bands, 1 ); } @@ -839,7 +848,7 @@ void ivas_masa_set_coding_config_fx( move16(); test(); - IF( EQ_32( ivas_total_brate, IVAS_64k ) && GT_16( config->numberOfDirections, 1 ) ) + if ( EQ_32( ivas_total_brate, IVAS_64k ) && GT_16( config->numberOfDirections, 1 ) ) { /* At 64k, we increase metadata bit budget when there is two directions present. */ config->max_metadata_bits = (UWord16) add( config->max_metadata_bits, MASA_EXTRA_BAND_META_BITS ); @@ -849,7 +858,7 @@ void ivas_masa_set_coding_config_fx( test(); test(); test(); - IF( ( ( EQ_32( ivas_total_brate, IVAS_32k ) && EQ_16( nchan_transport, 2 ) ) || EQ_32( ivas_total_brate, IVAS_48k ) ) && config->joinedSubframes ) + if ( ( ( EQ_32( ivas_total_brate, IVAS_32k ) && EQ_16( nchan_transport, 2 ) ) || EQ_32( ivas_total_brate, IVAS_48k ) ) && config->joinedSubframes ) { /* At 32k and 48k, we increase metadata bit budget when joinedSubframes. */ config->max_metadata_bits = (UWord16) add( config->max_metadata_bits, MASA_SMALL_INC_META_BITS ); @@ -906,7 +915,7 @@ void ivas_masa_set_coding_config_fx( test(); test(); test(); - IF( ( !isMcMasa && LT_32( ivas_total_brate, IVAS_48k ) ) || ( isMcMasa && LT_32( ivas_total_brate, IVAS_16k4 ) ) ) + if ( ( !isMcMasa && LT_32( ivas_total_brate, IVAS_48k ) ) || ( isMcMasa && LT_32( ivas_total_brate, IVAS_16k4 ) ) ) { config->useCoherence = FALSE; move16(); @@ -1262,8 +1271,8 @@ uint16_t index_theta_phi_16( } #else UWord16 index_theta_phi_16_fx( - Word32 *p_theta, /* i/o: input elevation to be indexed */ - Word32 *p_phi, /* i/o: input azimuth to be indexed */ + Word32 *p_theta, /* i/o: input elevation to be indexed Q22 */ + Word32 *p_phi, /* i/o: input azimuth to be indexed Q22 */ const SPHERICAL_GRID_DATA *gridData /* i : generated grid data */ ) { @@ -1274,25 +1283,25 @@ UWord16 index_theta_phi_16_fx( Word32 theta_hat_fx, phi_hat_fx; Word32 theta_fx, phi_fx; - theta_fx = *p_theta; + theta_fx = *p_theta; // Q22 move32(); - phi_fx = *p_phi; + phi_fx = *p_phi; // Q22 move32(); phi_hat_fx = 0; move32(); theta_hat_fx = 0; move32(); - phi_fx = L_add( phi_fx, L_shl( 180, Q22 ) ); + phi_fx = L_add( phi_fx, L_shl( 180, Q22 ) ); // Q22 IF( theta_fx < 0 ) { - abs_theta_fx = L_negate( theta_fx ); + abs_theta_fx = L_negate( theta_fx ); // Q22 sign_th = -1; move16(); } ELSE { - abs_theta_fx = theta_fx; + abs_theta_fx = theta_fx; // Q22 move32(); sign_th = 1; move16(); @@ -1309,7 +1318,7 @@ UWord16 index_theta_phi_16_fx( { id_phi = 0; move16(); - phi_hat_fx = L_shl( 180, Q22 ); + phi_hat_fx = L_shl( 180, Q22 ); // Q22 } } ELSE @@ -1319,12 +1328,12 @@ UWord16 index_theta_phi_16_fx( *p_theta = theta_hat_fx; move32(); - IF( EQ_16( sign_th, -1 ) ) + if ( EQ_16( sign_th, -1 ) ) { - *p_theta = L_negate( theta_hat_fx ); + *p_theta = L_negate( theta_hat_fx ); // Q22 move32(); } - *p_phi = L_sub( phi_hat_fx, L_shl( 180, Q22 ) ); + *p_phi = L_sub( phi_hat_fx, L_shl( 180, Q22 ) ); // Q22 move32(); /* Starting from Equator, alternating positive and negative */ @@ -1337,34 +1346,34 @@ UWord16 index_theta_phi_16_fx( { IF( EQ_16( id_th, sub( gridData->no_theta, 1 ) ) ) { - idx_sph = 65534; + idx_sph = 65534; // Q0 move16(); if ( sign_th < 0 ) { - idx_sph = 65535; + idx_sph = 65535; // Q0 move16(); } } ELSE { - cum_n = cum_n_for_id_th[id_th]; + cum_n = cum_n_for_id_th[id_th]; // Q0 move16(); - cum_n = (UWord16) L_add( cum_n, gridData->no_phi[0] ); + cum_n = (UWord16) L_add( cum_n, gridData->no_phi[0] ); // Q0 IF( sign_th > 0 ) { - cum_n = (UWord16) L_sub( cum_n, shl( gridData->no_phi[id_th], 1 ) ); + cum_n = (UWord16) L_sub( cum_n, shl( gridData->no_phi[id_th], 1 ) ); // Q0 } ELSE { - cum_n = (UWord16) L_sub( cum_n, gridData->no_phi[id_th] ); + cum_n = (UWord16) L_sub( cum_n, gridData->no_phi[id_th] ); // Q0 } - idx_sph = (UWord16) L_add( cum_n, id_phi ); + idx_sph = (UWord16) L_add( cum_n, id_phi ); // Q0 } } - return idx_sph; + return idx_sph; // Q0 } #endif @@ -1412,9 +1421,9 @@ static int16_t quantize_theta_masa( } #else static Word16 quantize_theta_masa_fx( - const Word32 x_fx, /* i : theta value to be quantized */ + const Word32 x_fx, /* i : theta value to be quantized Q22*/ const Word16 no_cb, /* i : number of codewords */ - Word32 *xhat_fx /* o : quantized value */ + Word32 *xhat_fx /* o : quantized value Q22*/ ) { Word16 imin; @@ -1425,7 +1434,7 @@ static Word16 quantize_theta_masa_fx( IF( GE_16( imin, sub( no_cb, 1 ) ) ) { imin = sub( no_cb, 1 ); - diff1_fx = L_sub( x_fx, L_shl( 90, Q22 ) ); + diff1_fx = L_sub( x_fx, L_shl( 90, Q22 ) ); // Q22 diff2_fx = L_sub( x_fx, Mpy_32_16_1( MASA_ANGLE_AT_EQUATOR_DEG_Q31, shl( sub( imin, 1 ), 6 ) ) ); // q31 + q0+6 - 15 = q22 IF( GT_32( L_abs( diff1_fx ), L_abs( diff2_fx ) ) ) { @@ -1435,7 +1444,7 @@ static Word16 quantize_theta_masa_fx( } ELSE { - *xhat_fx = L_shl( 90, Q22 ); + *xhat_fx = L_shl( 90, Q22 ); // Q22 move32(); } } @@ -1505,9 +1514,9 @@ static int16_t quantize_phi_masa( } #else static Word16 quantize_phi_masa_fx( - const Word32 phi_fx, /* i : azimuth value */ + const Word32 phi_fx, /* i : azimuth value Q22 */ const Word16 flag_delta, /* i : flag indicating if the azimuth codebook is translated or not */ - Word32 *phi_hat_fx, /* o : quantized azimuth */ + Word32 *phi_hat_fx, /* o : quantized azimuth Q22 */ const Word16 n /* i : azimuth codebook size */ ) { @@ -1519,7 +1528,7 @@ static Word16 quantize_phi_masa_fx( Word16 tmp_e, delta_phi_e; delta_phi_fx = L_deposit_h( BASOP_Util_Divide1616_Scale( 360, n, &delta_phi_e ) ); - delta_phi_fx = L_shr( delta_phi_fx, sub( sub( 31, delta_phi_e ), 22 ) ); + delta_phi_fx = L_shr( delta_phi_fx, sub( sub( 31, delta_phi_e ), 22 ) ); // Q22 IF( EQ_16( n, 1 ) ) { @@ -1531,7 +1540,7 @@ static Word16 quantize_phi_masa_fx( IF( EQ_16( flag_delta, 1 ) ) { - dd_fx = L_shr( delta_phi_fx, 1 ); + dd_fx = L_shr( delta_phi_fx, 1 ); // Q22 } ELSE { @@ -1541,15 +1550,15 @@ static Word16 quantize_phi_masa_fx( tmp32 = L_add( L_sub( phi_fx, dd_fx ), L_shr( delta_phi_fx, 1 ) ); id_phi = BASOP_Util_Divide3232_Scale( tmp32, delta_phi_fx, &tmp_e ); - id_phi = shr( id_phi, sub( 15, tmp_e ) ); + id_phi = shr( id_phi, sub( 15, tmp_e ) ); // Q0 - IF( EQ_16( id_phi, n ) ) + if ( EQ_16( id_phi, n ) ) { id_phi = 0; move16(); } - IF( EQ_16( id_phi, -1 ) ) + if ( EQ_16( id_phi, -1 ) ) { id_phi = sub( n, 1 ); } @@ -1557,7 +1566,7 @@ static Word16 quantize_phi_masa_fx( *phi_hat_fx = L_add( L_shl( Mpy_32_16_1( delta_phi_fx, id_phi ), 15 ), dd_fx ); // q22 + q0 - 15 = q7 -> q7 + 15 = q22 move32(); - return id_phi; + return id_phi; // Q0 } #endif @@ -1716,8 +1725,8 @@ void deindex_sph_idx( void deindex_sph_idx_fx( const UWord16 sphIndex, /* i : Spherical index */ const SPHERICAL_GRID_DATA *gridData, /* i : Prepared spherical grid */ - Word32 *theta_fx, /* o : Elevation */ - Word32 *phi_fx /* o : Azimuth */ + Word32 *theta_fx, /* o : Elevation Q22*/ + Word32 *phi_fx /* o : Azimuth Q22 */ ) { Word32 ba_crt_fx, del_crt_fx, div_crt_fx, a4_crt_fx; @@ -1788,14 +1797,15 @@ void deindex_sph_idx_fx( tmp32 = Mpy_32_32( a4_crt_fx, L_shl_sat( sphIndex, Q15 ) ); /* Q10 */ tmp32 = L_add( del_crt_fx, tmp32 ); /* Q10 */ tmp16 = Q31 - Q10; - tmp32 = Sqrt32( tmp32, &tmp16 ); - tmp32 = Mpy_32_32( div_crt_fx, tmp32 ); + move16(); + tmp32 = Sqrt32( tmp32, &tmp16 ); // Q31-tmp16 + tmp32 = Mpy_32_32( div_crt_fx, tmp32 ); // Q31-tmp16 tmp32 = L_shr( tmp32, sub( Q8, tmp16 ) ); /* Q23 */ estim_fx = L_add( ba_crt_fx, tmp32 ); /* Q23 */ if ( GT_32( estim_fx, MASA_NO_CIRCLES_Q23 ) ) { - estim_fx = MASA_NO_CIRCLES_Q23; + estim_fx = MASA_NO_CIRCLES_Q23; // Q23 move32(); } @@ -1990,6 +2000,7 @@ Word16 valid_ratio_index_fx( FOR( i = 1; i < len; i++ ) { base[i] = i_mult( base[i - 1], 10 ); + move16(); } sum = 0; move16(); @@ -2075,7 +2086,7 @@ void reconstruct_ism_ratios_fx( q_energy_ratio_ism[i] = L_shl( L_mult( ratio_ism_idx[i], step ), 14 ); // q0 + q15 + 1 + 14 = q30; move32(); - sum = L_add( sum, q_energy_ratio_ism[i] ); + sum = L_add( sum, q_energy_ratio_ism[i] ); // Q30 } q_energy_ratio_ism[nchan_ism - 1] = L_sub( ONE_IN_Q30, sum ); @@ -2207,9 +2218,9 @@ void distribute_evenly_ism( } #else void distribute_evenly_ism_fx( - Word16 *idx, /* o : index values */ - const Word16 K, /* i : sum of indexes */ - const Word16 nchan_ism /* i : number of objects */ + Word16 *idx, /* o : index values Q0 */ + const Word16 K, /* i : sum of indexes Q0*/ + const Word16 nchan_ism /* i : number of objects Q0 */ ) { Word16 i; @@ -2226,7 +2237,7 @@ void distribute_evenly_ism_fx( } ELSE { - idx[i] = idiv1616( K, nchan_ism ); + idx[i] = idiv1616( K, nchan_ism ); // Q0 move16(); } sum = add( sum, idx[i] ); @@ -2238,7 +2249,7 @@ void distribute_evenly_ism_fx( move16(); WHILE( LT_16( sum, K ) ) { - IF( EQ_16( i, nchan_ism ) ) + if ( EQ_16( i, nchan_ism ) ) { i = 0; move16(); diff --git a/lib_com/ivas_mc_param_com.c b/lib_com/ivas_mc_param_com.c index 064677bbd..dc26644b9 100644 --- a/lib_com/ivas_mc_param_com.c +++ b/lib_com/ivas_mc_param_com.c @@ -832,7 +832,7 @@ static void ivas_param_mc_set_coding_scheme_fx( hMetadataPMC->icc_coding.sym_freq = &ivas_param_mc_sym_freq_icc_cicp6_48_16bits[0]; hMetadataPMC->icc_coding.cum_freq_delta = &ivas_param_mc_cum_freq_icc_delta_cicp6_48_16bits[0]; hMetadataPMC->icc_coding.sym_freq_delta = &ivas_param_mc_sym_freq_icc_delta_cicp6_48_16bits[0]; - hMetadataPMC->icc_coding.quantizer_fx = &ivas_param_mc_quant_icc_fx[0]; + hMetadataPMC->icc_coding.quantizer_fx = &ivas_param_mc_quant_icc_fx[0]; /*Q15*/ hMetadataPMC->icc_coding.quantizer_size = PARAM_MC_SZ_ICC_QUANTIZER; move16(); hMetadataPMC->icc_coding.uni_bits = PARAM_MC_NUM_BITS_ICC_SCALAR_QUANT; @@ -842,7 +842,7 @@ static void ivas_param_mc_set_coding_scheme_fx( hMetadataPMC->ild_coding.sym_freq = &ivas_param_mc_sym_freq_ild_cicp6_48_16bits[0]; hMetadataPMC->ild_coding.cum_freq_delta = &ivas_param_mc_cum_freq_ild_delta_cicp6_48_16bits[0]; hMetadataPMC->ild_coding.sym_freq_delta = &ivas_param_mc_sym_freq_ild_delta_cicp6_48_16bits[0]; - hMetadataPMC->ild_coding.quantizer_fx = &ivas_param_mc_quant_ild_5d1_48_fx[0]; + hMetadataPMC->ild_coding.quantizer_fx = &ivas_param_mc_quant_ild_5d1_48_fx[0]; /*Q8*/ hMetadataPMC->ild_coding.quantizer_size = PARAM_MC_SZ_ILD_QUANTIZER_4BITS; move16(); hMetadataPMC->ild_coding.uni_bits = PARAM_MC_NUM_BITS_ILD_SCALAR_QUANT; @@ -854,7 +854,7 @@ static void ivas_param_mc_set_coding_scheme_fx( hMetadataPMC->icc_coding.sym_freq = &ivas_param_mc_sym_freq_icc_cicp12_48_16bits[0]; hMetadataPMC->icc_coding.cum_freq_delta = &ivas_param_mc_cum_freq_icc_delta_cicp12_48_16bits[0]; hMetadataPMC->icc_coding.sym_freq_delta = &ivas_param_mc_sym_freq_icc_delta_cicp12_48_16bits[0]; - hMetadataPMC->icc_coding.quantizer_fx = &ivas_param_mc_quant_icc_fx[0]; + hMetadataPMC->icc_coding.quantizer_fx = &ivas_param_mc_quant_icc_fx[0]; /*Q15*/ hMetadataPMC->icc_coding.quantizer_size = PARAM_MC_SZ_ICC_QUANTIZER; move16(); hMetadataPMC->icc_coding.uni_bits = PARAM_MC_NUM_BITS_ICC_SCALAR_QUANT; @@ -864,7 +864,7 @@ static void ivas_param_mc_set_coding_scheme_fx( hMetadataPMC->ild_coding.sym_freq = &ivas_param_mc_sym_freq_ild_cicp12_48_16bits[0]; hMetadataPMC->ild_coding.cum_freq_delta = &ivas_param_mc_cum_freq_ild_delta_cicp12_48_16bits[0]; hMetadataPMC->ild_coding.sym_freq_delta = &ivas_param_mc_sym_freq_ild_delta_cicp12_48_16bits[0]; - hMetadataPMC->ild_coding.quantizer_fx = &ivas_param_mc_quant_ild_5d1_48_fx[0]; + hMetadataPMC->ild_coding.quantizer_fx = &ivas_param_mc_quant_ild_5d1_48_fx[0]; /*Q8*/ hMetadataPMC->ild_coding.quantizer_size = PARAM_MC_SZ_ILD_QUANTIZER_4BITS; move16(); hMetadataPMC->ild_coding.uni_bits = PARAM_MC_NUM_BITS_ILD_SCALAR_QUANT; @@ -876,7 +876,7 @@ static void ivas_param_mc_set_coding_scheme_fx( hMetadataPMC->icc_coding.sym_freq = &ivas_param_mc_sym_freq_icc_cicp14_48_16bits[0]; hMetadataPMC->icc_coding.cum_freq_delta = &ivas_param_mc_cum_freq_icc_delta_cicp14_48_16bits[0]; hMetadataPMC->icc_coding.sym_freq_delta = &ivas_param_mc_sym_freq_icc_delta_cicp14_48_16bits[0]; - hMetadataPMC->icc_coding.quantizer_fx = &ivas_param_mc_quant_icc_fx[0]; + hMetadataPMC->icc_coding.quantizer_fx = &ivas_param_mc_quant_icc_fx[0]; /*Q15*/ hMetadataPMC->icc_coding.quantizer_size = PARAM_MC_SZ_ICC_QUANTIZER; move16(); hMetadataPMC->icc_coding.uni_bits = PARAM_MC_NUM_BITS_ICC_SCALAR_QUANT; @@ -886,7 +886,7 @@ static void ivas_param_mc_set_coding_scheme_fx( hMetadataPMC->ild_coding.sym_freq = &ivas_param_mc_sym_freq_ild_cicp14_48_16bits[0]; hMetadataPMC->ild_coding.cum_freq_delta = &ivas_param_mc_cum_freq_ild_delta_cicp14_48_16bits[0]; hMetadataPMC->ild_coding.sym_freq_delta = &ivas_param_mc_sym_freq_ild_delta_cicp14_48_16bits[0]; - hMetadataPMC->ild_coding.quantizer_fx = &ivas_param_mc_quant_ild_5d1_48_fx[0]; + hMetadataPMC->ild_coding.quantizer_fx = &ivas_param_mc_quant_ild_5d1_48_fx[0]; /*Q8*/ hMetadataPMC->ild_coding.quantizer_size = PARAM_MC_SZ_ILD_QUANTIZER_4BITS; move16(); hMetadataPMC->ild_coding.uni_bits = PARAM_MC_NUM_BITS_ILD_SCALAR_QUANT; @@ -899,7 +899,7 @@ static void ivas_param_mc_set_coding_scheme_fx( hMetadataPMC->icc_coding.sym_freq = &ivas_param_mc_sym_freq_icc_combined_48_16bits[0]; hMetadataPMC->icc_coding.cum_freq_delta = &ivas_param_mc_cum_freq_icc_delta_combined_48_16bits[0]; hMetadataPMC->icc_coding.sym_freq_delta = &ivas_param_mc_sym_freq_icc_delta_combined_48_16bits[0]; - hMetadataPMC->icc_coding.quantizer_fx = &ivas_param_mc_quant_icc_fx[0]; + hMetadataPMC->icc_coding.quantizer_fx = &ivas_param_mc_quant_icc_fx[0]; /*Q15*/ hMetadataPMC->icc_coding.quantizer_size = PARAM_MC_SZ_ICC_QUANTIZER; move16(); hMetadataPMC->icc_coding.uni_bits = PARAM_MC_NUM_BITS_ICC_SCALAR_QUANT; @@ -909,7 +909,7 @@ static void ivas_param_mc_set_coding_scheme_fx( hMetadataPMC->ild_coding.sym_freq = &ivas_param_mc_sym_freq_ild_combined_48_16bits[0]; hMetadataPMC->ild_coding.cum_freq_delta = &ivas_param_mc_cum_freq_ild_delta_combined_48_16bits[0]; hMetadataPMC->ild_coding.sym_freq_delta = &ivas_param_mc_sym_freq_ild_delta_combined_48_16bits[0]; - hMetadataPMC->ild_coding.quantizer_fx = &ivas_param_mc_quant_ild_5d1_48_fx[0]; + hMetadataPMC->ild_coding.quantizer_fx = &ivas_param_mc_quant_ild_5d1_48_fx[0]; /*Q8*/ hMetadataPMC->ild_coding.quantizer_size = PARAM_MC_SZ_ILD_QUANTIZER_4BITS; move16(); hMetadataPMC->ild_coding.uni_bits = PARAM_MC_NUM_BITS_ILD_SCALAR_QUANT; @@ -920,6 +920,7 @@ static void ivas_param_mc_set_coding_scheme_fx( } hMetadataPMC->num_parameter_bands = ivas_param_mc_get_num_param_bands( mc_ls_setup, ivas_total_brate ); + move16(); return; } @@ -966,7 +967,7 @@ static void ivas_param_mc_set_coding_scheme( hMetadataPMC->icc_coding.sym_freq_delta = &ivas_param_mc_sym_freq_icc_delta_cicp12_48_16bits[0]; hMetadataPMC->icc_coding.quantizer = &ivas_param_mc_quant_icc[0]; #ifdef IVAS_FLOAT_FIXED - hMetadataPMC->icc_coding.quantizer_fx = &ivas_param_mc_quant_icc_fx[0]; + hMetadataPMC->icc_coding.quantizer_fx = &ivas_param_mc_quant_icc_fx[0]; // Q15 #endif hMetadataPMC->icc_coding.quantizer_size = PARAM_MC_SZ_ICC_QUANTIZER; hMetadataPMC->icc_coding.uni_bits = PARAM_MC_NUM_BITS_ICC_SCALAR_QUANT; @@ -977,7 +978,7 @@ static void ivas_param_mc_set_coding_scheme( hMetadataPMC->ild_coding.sym_freq_delta = &ivas_param_mc_sym_freq_ild_delta_cicp12_48_16bits[0]; hMetadataPMC->ild_coding.quantizer = &ivas_param_mc_quant_ild_5d1_48[0]; #ifdef IVAS_FLOAT_FIXED - hMetadataPMC->ild_coding.quantizer_fx = &ivas_param_mc_quant_ild_5d1_48_fx[0]; + hMetadataPMC->ild_coding.quantizer_fx = &ivas_param_mc_quant_ild_5d1_48_fx[0]; // Q8 #endif hMetadataPMC->ild_coding.quantizer_size = PARAM_MC_SZ_ILD_QUANTIZER_4BITS; hMetadataPMC->ild_coding.uni_bits = PARAM_MC_NUM_BITS_ILD_SCALAR_QUANT; @@ -990,7 +991,7 @@ static void ivas_param_mc_set_coding_scheme( hMetadataPMC->icc_coding.sym_freq_delta = &ivas_param_mc_sym_freq_icc_delta_cicp14_48_16bits[0]; hMetadataPMC->icc_coding.quantizer = &ivas_param_mc_quant_icc[0]; #ifdef IVAS_FLOAT_FIXED - hMetadataPMC->icc_coding.quantizer_fx = &ivas_param_mc_quant_icc_fx[0]; + hMetadataPMC->icc_coding.quantizer_fx = &ivas_param_mc_quant_icc_fx[0]; // Q15 #endif hMetadataPMC->icc_coding.quantizer_size = PARAM_MC_SZ_ICC_QUANTIZER; hMetadataPMC->icc_coding.uni_bits = PARAM_MC_NUM_BITS_ICC_SCALAR_QUANT; @@ -1001,7 +1002,7 @@ static void ivas_param_mc_set_coding_scheme( hMetadataPMC->ild_coding.sym_freq_delta = &ivas_param_mc_sym_freq_ild_delta_cicp14_48_16bits[0]; hMetadataPMC->ild_coding.quantizer = &ivas_param_mc_quant_ild_5d1_48[0]; #ifdef IVAS_FLOAT_FIXED - hMetadataPMC->ild_coding.quantizer_fx = &ivas_param_mc_quant_ild_5d1_48_fx[0]; + hMetadataPMC->ild_coding.quantizer_fx = &ivas_param_mc_quant_ild_5d1_48_fx[0]; // Q8 #endif hMetadataPMC->ild_coding.quantizer_size = PARAM_MC_SZ_ILD_QUANTIZER_4BITS; hMetadataPMC->ild_coding.uni_bits = PARAM_MC_NUM_BITS_ILD_SCALAR_QUANT; @@ -1015,7 +1016,7 @@ static void ivas_param_mc_set_coding_scheme( hMetadataPMC->icc_coding.sym_freq_delta = &ivas_param_mc_sym_freq_icc_delta_combined_48_16bits[0]; hMetadataPMC->icc_coding.quantizer = &ivas_param_mc_quant_icc[0]; #ifdef IVAS_FLOAT_FIXED - hMetadataPMC->icc_coding.quantizer_fx = &ivas_param_mc_quant_icc_fx[0]; + hMetadataPMC->icc_coding.quantizer_fx = &ivas_param_mc_quant_icc_fx[0]; // Q15 #endif hMetadataPMC->icc_coding.quantizer_size = PARAM_MC_SZ_ICC_QUANTIZER; hMetadataPMC->icc_coding.uni_bits = PARAM_MC_NUM_BITS_ICC_SCALAR_QUANT; @@ -1026,7 +1027,7 @@ static void ivas_param_mc_set_coding_scheme( hMetadataPMC->ild_coding.sym_freq_delta = &ivas_param_mc_sym_freq_ild_delta_combined_48_16bits[0]; hMetadataPMC->ild_coding.quantizer = &ivas_param_mc_quant_ild_5d1_48[0]; #ifdef IVAS_FLOAT_FIXED - hMetadataPMC->ild_coding.quantizer_fx = &ivas_param_mc_quant_ild_5d1_48_fx[0]; + hMetadataPMC->ild_coding.quantizer_fx = &ivas_param_mc_quant_ild_5d1_48_fx[0]; // Q8 #endif hMetadataPMC->ild_coding.quantizer_size = PARAM_MC_SZ_ILD_QUANTIZER_4BITS; hMetadataPMC->ild_coding.uni_bits = PARAM_MC_NUM_BITS_ILD_SCALAR_QUANT; diff --git a/lib_com/ivas_mct_com.c b/lib_com/ivas_mct_com.c index dd7910748..ec8f0907b 100644 --- a/lib_com/ivas_mct_com.c +++ b/lib_com/ivas_mct_com.c @@ -198,7 +198,7 @@ void splitAvailableBitsMCT( void splitAvailableBitsMCT( void **sts, /* i/o: encoder/decoder state structure */ const Word16 total_bits, /* i : total number of available bits */ - const Word16 split_ratio[MCT_MAX_CHANNELS], /* i : ratio for splitting the bits */ + const Word16 split_ratio[MCT_MAX_CHANNELS], /* i : ratio for splitting the bits Q0 */ const Word16 enc_dec, /* i : encoder or decoder flag */ const Word16 nchan /* i : number of channels */ ) @@ -274,7 +274,7 @@ void splitAvailableBitsMCT( { bits_frame_channel = &( (Decoder_State *) sts[i] )->bits_frame_channel; } - + move16(); IF( NE_32( mct_chan_mode[i], MCT_CHAN_MODE_IGNORE ) ) { assert( split_ratio[i] >= 1 && split_ratio[i] < BITRATE_MCT_RATIO_RANGE ); @@ -282,7 +282,7 @@ void splitAvailableBitsMCT( bits_split = add( bits_split, *bits_frame_channel ); /*determine channel with most bits (energy)*/ - IF( GT_16( *bits_frame_channel, tmp ) ) + if ( GT_16( *bits_frame_channel, tmp ) ) { tmp = *bits_frame_channel; move16(); @@ -311,7 +311,7 @@ void splitAvailableBitsMCT( { bits_frame_channel = &( (Decoder_State *) sts[i] )->bits_frame_channel; } - + move16(); IF( NE_32( mct_chan_mode[i], MCT_CHAN_MODE_IGNORE ) ) { Word32 temp_res; @@ -346,7 +346,7 @@ void splitAvailableBitsMCT( { bits_frame_channel = &( (Decoder_State *) sts[max_chn] )->bits_frame_channel; } - + move16(); *bits_frame_channel = add( *bits_frame_channel, sub( total_bits, bits_split ) ); /*if all channels are silent assign bits to ch 0*/ diff --git a/lib_com/ivas_mdft_imdft.c b/lib_com/ivas_mdft_imdft.c index 579efe5da..0369afa71 100644 --- a/lib_com/ivas_mdft_imdft.c +++ b/lib_com/ivas_mdft_imdft.c @@ -49,6 +49,7 @@ #endif #ifdef IVAS_FLOAT_FIXED #include "ivas_rom_com_fx.h" +#include "ivas_prot_fx.h" #endif /*-----------------------------------------------------------------------------------------* @@ -77,33 +78,34 @@ static void ivas_get_mdft_twid_factors_fx( const Word16 length, - const Word32 **ppTwid ) + const Word32 **ppTwid // Q31 +) { SWITCH( length ) { case L_FRAME48k: - *ppTwid = &ivas_mdft_coeff_cos_twid_960_fx[0]; + *ppTwid = &ivas_mdft_coeff_cos_twid_960_fx[0]; // Q31 BREAK; case L_FRAME32k: - *ppTwid = &ivas_mdft_coeff_cos_twid_640_fx[0]; + *ppTwid = &ivas_mdft_coeff_cos_twid_640_fx[0]; // Q31 BREAK; case L_FRAME16k: - *ppTwid = &ivas_mdft_coeff_cos_twid_320_fx[0]; + *ppTwid = &ivas_mdft_coeff_cos_twid_320_fx[0]; // Q31 BREAK; case IVAS_240_PT_LEN: - *ppTwid = &ivas_mdft_coeff_cos_twid_240_fx[0]; + *ppTwid = &ivas_mdft_coeff_cos_twid_240_fx[0]; // Q31 BREAK; case IVAS_160_PT_LEN: - *ppTwid = &ivas_mdft_coeff_cos_twid_160_fx[0]; + *ppTwid = &ivas_mdft_coeff_cos_twid_160_fx[0]; // Q31 BREAK; case IVAS_120_PT_LEN: - *ppTwid = &ivas_mdft_coeff_cos_twid_120_fx[0]; + *ppTwid = &ivas_mdft_coeff_cos_twid_120_fx[0]; // Q31 BREAK; case IVAS_80_PT_LEN: - *ppTwid = &ivas_mdft_coeff_cos_twid_80_fx[0]; + *ppTwid = &ivas_mdft_coeff_cos_twid_80_fx[0]; // Q31 BREAK; case IVAS_40_PT_LEN: - *ppTwid = &ivas_mdft_coeff_cos_twid_40_fx[0]; + *ppTwid = &ivas_mdft_coeff_cos_twid_40_fx[0]; // Q31 BREAK; default: assert( !"Not supported FFT length!" ); @@ -120,27 +122,28 @@ static void ivas_get_mdft_twid_factors_fx( static void ivas_get_imdft_twid_factors_fx( const Word16 length, - const Word32 **ppTwid ) + const Word32 **ppTwid // Q31 +) { SWITCH( length ) { case L_FRAME48k: - *ppTwid = ivas_mdft_coeff_cos_twid_960_fx; + *ppTwid = ivas_mdft_coeff_cos_twid_960_fx; // Q31 BREAK; case L_FRAME32k: - *ppTwid = ivas_mdft_coeff_cos_twid_640_fx; + *ppTwid = ivas_mdft_coeff_cos_twid_640_fx; // Q31 BREAK; case L_FRAME16k: - *ppTwid = ivas_mdft_coeff_cos_twid_320_fx; + *ppTwid = ivas_mdft_coeff_cos_twid_320_fx; // Q31 BREAK; case 240: - *ppTwid = ivas_mdft_coeff_cos_twid_240_fx; + *ppTwid = ivas_mdft_coeff_cos_twid_240_fx; // Q31 BREAK; case 160: - *ppTwid = ivas_mdft_coeff_cos_twid_160_fx; + *ppTwid = ivas_mdft_coeff_cos_twid_160_fx; // Q31 BREAK; case 80: - *ppTwid = ivas_mdft_coeff_cos_twid_80_fx; + *ppTwid = ivas_mdft_coeff_cos_twid_80_fx; // Q31 BREAK; default: assert( !"Not supported FFT length!" ); @@ -268,37 +271,37 @@ static void get_one_by_length( #ifdef IVAS_FLOAT_FIXED static void get_one_by_length_fx( - Word32 *one_by_length, + Word32 *one_by_length, // Q37 const Word16 length ) { IF( EQ_16( length, L_FRAME48k ) ) { - *one_by_length = IVAS_ONE_BY_960_Q37; + *one_by_length = IVAS_ONE_BY_960_Q37; // Q37 move32(); } ELSE IF( EQ_16( length, L_FRAME32k ) ) { - *one_by_length = IVAS_ONE_BY_640_Q37; + *one_by_length = IVAS_ONE_BY_640_Q37; // Q37 move32(); } ELSE IF( EQ_16( length, L_FRAME16k ) ) { - *one_by_length = IVAS_ONE_BY_320_Q37; + *one_by_length = IVAS_ONE_BY_320_Q37; // Q37 move32(); } ELSE IF( EQ_16( length, IVAS_240_PT_LEN ) ) { - *one_by_length = IVAS_ONE_BY_240_Q37; + *one_by_length = IVAS_ONE_BY_240_Q37; // Q37 move32(); } ELSE IF( EQ_16( length, IVAS_160_PT_LEN ) ) { - *one_by_length = IVAS_ONE_BY_160_Q37; + *one_by_length = IVAS_ONE_BY_160_Q37; // Q37 move32(); } ELSE IF( EQ_16( length, IVAS_80_PT_LEN ) ) { - *one_by_length = IVAS_ONE_BY_80_Q37; + *one_by_length = IVAS_ONE_BY_80_Q37; // Q37 move32(); } ELSE @@ -316,32 +319,32 @@ static void get_one_by_length_fx( *-----------------------------------------------------------------------------------------*/ static void ivas_ifft_cplx1_fx( - Word32 *re, - Word32 *im, + Word32 *re, // inp: Qin -> out: Qin + 6 + Word32 *im, // inp: Qin -> out: Qin + 6 const Word16 length ) { Word16 i; Word32 one_by_length, tmp; - get_one_by_length_fx( &one_by_length, length ); + get_one_by_length_fx( &one_by_length, length ); // Q37 /* re-arrange inputs to use fft as ifft */ - re[0] = Mpy_32_32( re[0], one_by_length ); + re[0] = Mpy_32_32( re[0], one_by_length ); // ( Qin + Q37 ) - Q31 -> Qin + 6 move32(); - im[0] = Mpy_32_32( im[0], one_by_length ); + im[0] = Mpy_32_32( im[0], one_by_length ); // ( Qin + Q37 ) - Q31 -> Qin + 6 move32(); FOR( i = 1; i <= length >> 1; i++ ) { - tmp = Mpy_32_32( re[sub( length, i )], one_by_length ); /*stl_arr_index*/ - re[sub( length, i )] = Mpy_32_32( re[i], one_by_length ); /*stl_arr_index*/ + tmp = Mpy_32_32( re[length - i], one_by_length ); /*stl_arr_index Q: ( Qin + Q37 ) - Q31 -> Qin + 6 */ + re[length - i] = Mpy_32_32( re[i], one_by_length ); /*stl_arr_index Q: ( Qin + Q37 ) - Q31 -> Qin + 6 */ move32(); re[i] = tmp; move32(); - tmp = Mpy_32_32( im[sub( length, i )], one_by_length ); /*stl_arr_index*/ - im[sub( length, i )] = Mpy_32_32( im[i], one_by_length ); /*stl_arr_index*/ + tmp = Mpy_32_32( im[length - i], one_by_length ); /*stl_arr_index Q: ( Qin + Q37 ) - Q31 -> Qin + 6 */ + im[length - i] = Mpy_32_32( im[i], one_by_length ); /*stl_arr_index Q: ( Qin + Q37 ) - Q31 -> Qin + 6 */ move32(); - im[i] = tmp; + im[i] = tmp; // Q: ( Qin + Q37 ) - Q31 -> Qin + 6 move32(); } @@ -359,17 +362,17 @@ static void ivas_ifft_cplx1_fx( *-----------------------------------------------------------------------------------------*/ void ivas_mdft_fx( - const Word32 *pIn, /* i : input time-domain signal */ - Word32 *pOut_re, /* o : Real part of MDFT signal */ - Word32 *pOut_im, /* o : Imag. part of MDFT signal */ - const Word16 input_length, /* i : signal length */ - const Word16 mdft_length /* i : MDFT length */ + const Word32 *pIn, /* i : input time-domain signal Qin */ + Word32 *pOut_re, /* o : Real part of MDFT signal Qin */ + Word32 *pOut_im, /* o : Imag. part of MDFT signal Qin */ + const Word16 input_length, /* i : signal length */ + const Word16 mdft_length /* i : MDFT length */ ) { Word32 re[L_FRAME48k]; Word32 im[L_FRAME48k]; Word16 j, len_by_2; - const Word32 *pTwid; + const Word32 *pTwid; // Q31 len_by_2 = shr( mdft_length, 1 ); ivas_get_mdft_twid_factors_fx( mdft_length, &pTwid ); @@ -377,9 +380,9 @@ void ivas_mdft_fx( { FOR( j = 0; j < mdft_length; j++ ) { - re[j] = Mpy_32_32( pIn[j], pTwid[j] ); + re[j] = Mpy_32_32( pIn[j], pTwid[j] ); // ( Qin + Q31 ) - Q31 -> Qin move32(); - im[j] = Mpy_32_32( L_negate( pIn[j] ), pTwid[sub( mdft_length, j )] ); + im[j] = Mpy_32_32( L_negate( pIn[j] ), pTwid[mdft_length - j] ); // ( Qin + Q31 ) - Q31 -> Qin move32(); } } @@ -387,9 +390,9 @@ void ivas_mdft_fx( { FOR( j = 0; j < mdft_length; j++ ) { - re[j] = Msub_32_32( Mpy_32_32( pIn[j], pTwid[j] ), pIn[add( mdft_length, j )], pTwid[sub( mdft_length, j )] ); + re[j] = Msub_32_32( Mpy_32_32( pIn[j], pTwid[j] ), pIn[add( mdft_length, j )], pTwid[mdft_length - j] ); // ( Qin + Q31 ) - Q31 -> Qin move32(); - im[j] = Msub_32_32( Mpy_32_32( L_negate( pIn[j] ), pTwid[sub( mdft_length, j )] ), pIn[add( mdft_length, j )], pTwid[j] ); + im[j] = Msub_32_32( Mpy_32_32( L_negate( pIn[j] ), pTwid[mdft_length - j] ), pIn[mdft_length + j], pTwid[j] ); // ( Qin + Q31 ) - Q31 -> Qin move32(); } } @@ -397,14 +400,14 @@ void ivas_mdft_fx( fft_fx( re, im, mdft_length, 1 ); FOR( j = 0; j < len_by_2; j++ ) { - pOut_re[2 * j] = re[j]; + pOut_re[2 * j] = re[j]; // Qin move32(); - pOut_re[add( imult1616( 2, j ), 1 )] = re[sub( sub( mdft_length, j ), 1 )]; + pOut_re[2 * j + 1] = re[mdft_length - j - 1]; // Qin move32(); - pOut_im[2 * j] = im[j]; + pOut_im[2 * j] = im[j]; // Qin move32(); - pOut_im[add( imult1616( 2, j ), 1 )] = L_negate( im[sub( sub( mdft_length, j ), 1 )] ); + pOut_im[2 * j + 1] = L_negate( im[mdft_length - j - 1] ); // Qin move32(); } return; @@ -419,10 +422,10 @@ void ivas_mdft_fx( *-----------------------------------------------------------------------------------------*/ void ivas_imdft_fx( - const Word32 *pRe, /* i : Real part of MDFT signal */ - const Word32 *pIm, /* i : Imag. part of MDFT signal */ - Word32 *pOut, /* o : output time-domain signal */ - const Word16 length /* i : signal length */ + const Word32 *pRe, /* i : Real part of MDFT signal Qin */ + const Word32 *pIm, /* i : Imag. part of MDFT signal Qin */ + Word32 *pOut, /* o : output time-domain signal Qin */ + const Word16 length /* i : signal length */ ) { Word32 *re_tmp = pOut; @@ -430,32 +433,34 @@ void ivas_imdft_fx( Word32 tmp; Word16 j; Word16 len_by_2; - const Word32 *pTwid; + const Word32 *pTwid; // Q31 len_by_2 = shr( length, 1 ); ivas_get_imdft_twid_factors_fx( length, &pTwid ); FOR( j = 0; j < len_by_2; j++ ) { - re_tmp[j] = pRe[2 * j]; + re_tmp[j] = pRe[2 * j]; // Qin move32(); - re_tmp[add( j, len_by_2 )] = pRe[sub( sub( length, imult1616( 2, j ) ), 1 )]; + re_tmp[j + len_by_2] = pRe[length - 2 * j - 1]; // Qin move32(); - im_tmp[j] = pIm[2 * j]; + im_tmp[j] = pIm[2 * j]; // Qin move32(); - im_tmp[add( j, len_by_2 )] = L_negate( pIm[sub( sub( length, imult1616( 2, j ) ), 1 )] ); + im_tmp[j + len_by_2] = L_negate( pIm[length - 2 * j - 1] ); // Qin move32(); } ivas_ifft_cplx1_fx( re_tmp, im_tmp, length ); + // re_tmp: Qin + 6 + // im_tmp: Qin + 6 FOR( j = 0; j < length; j++ ) { - tmp = Msub_32_32( Mpy_32_32( L_shr( re_tmp[j], Q6 ), pTwid[j] ), L_shr( im_tmp[j], Q6 ), pTwid[sub( length, j )] ); - im_tmp[j] = L_negate( Madd_32_32( Mpy_32_32( L_shr( re_tmp[j], Q6 ), pTwid[sub( length, j )] ), L_shr( im_tmp[j], Q6 ), pTwid[j] ) ); + tmp = Msub_32_32( Mpy_32_32( L_shr( re_tmp[j], Q6 ), pTwid[j] ), L_shr( im_tmp[j], Q6 ), pTwid[length - j] ); // ( ( Qin + Q6 - Q6 ) + Q31 ) - Q31 -> Qin + im_tmp[j] = L_negate( Madd_32_32( Mpy_32_32( L_shr( re_tmp[j], Q6 ), pTwid[length - j] ), L_shr( im_tmp[j], Q6 ), pTwid[j] ) ); // ( ( Qin + Q6 - Q6 ) + Q31 ) - Q31 -> Qin move32(); - re_tmp[j] = tmp; + re_tmp[j] = tmp; // ( ( Qin + Q6 - Q6 ) + Q31 ) - Q31 -> Qin move32(); } return; diff --git a/lib_com/ivas_omasa_com.c b/lib_com/ivas_omasa_com.c index 5dbe03866..037364420 100644 --- a/lib_com/ivas_omasa_com.c +++ b/lib_com/ivas_omasa_com.c @@ -882,7 +882,9 @@ void calculate_nbits_meta( return; } #else -static Word16 get_bits_ism( Word32 val ) +static Word16 get_bits_ism( + Word32 val // Q29 +) { Word16 res; test(); @@ -891,33 +893,41 @@ static Word16 get_bits_ism( Word32 val ) test(); test(); test(); - IF( LE_32( val, 536870912 ) && GT_32( val, 447750340 ) ) + /* Considering only 3 points after decimal point, and replacing the other digits with 9 after that*/ + IF( LE_32( val, 536870912 /*1 (in Q29)*/ ) && GT_32( val, 447750340 /*5/6 (in Q29)*/ ) ) { + // 1 (in Q29) <= val <= 5/6 (in Q29) => res = 0 res = 0; move16(); } - ELSE IF( LE_32( val, 447750340 ) && GT_32( val, 358092897 ) ) + ELSE IF( LE_32( val, 447750340 /* 5/6 (in Q29)*/ ) && GT_32( val, 358092897 /*4/6 (in Q29)*/ ) ) { + // 5/6 (in Q29) <= val <= 4/6 (in Q29) => res = 1 res = 1; move16(); } - ELSE IF( LE_32( val, 358092897 ) && GT_32( val, 268972326 ) ) + ELSE IF( LE_32( val, 358092897 /*4/6 (in Q29)*/ ) && GT_32( val, 268972326 /*3/6 (in Q29)*/ ) ) { + // 4/6 (in Q29) <= val <= 3/6 (in Q29) => res = 2 res = 2; move16(); } - ELSE IF( LE_32( val, 268972326 ) && GT_32( val, 179314884 ) ) + ELSE IF( LE_32( val, 268972326 /*3/6 (in Q29)*/ ) && GT_32( val, 179314884 /* 2/6 (in Q29) */ ) ) { + // 3/6 (in Q29) <= val <= 2/6 (in Q29) => res = 3 res = 3; move16(); } - ELSE IF( LE_32( val, 179314884 ) && GT_32( val, 89657442 ) ) + ELSE IF( LE_32( val, 179314884 /* 2/6 (in Q29) */ ) && GT_32( val, 89657442 /* 1/6 => res (in Q29) */ ) ) { + // 2/6 (in Q29) <= val <= 1/6 => res (in Q29) = 4 res = 4; move16(); } - ELSE IF( LE_32( val, 89657442 ) && GT_32( val, 536870 ) ) + ELSE IF( LE_32( val, 89657442 /* 1/6 => res (in Q29) */ ) && GT_32( val, 536870 /* 0.0009999999 ( in Q29 )*/ ) ) { + // 1/6 (in Q29) <= val <= 0 (in Q29) => res = 5 + // 0.0009999999 in Q29-> 536870 res = 5; move16(); } @@ -952,7 +962,7 @@ void calculate_nbits_meta_fx( { FOR( obj = 0; obj < nchan_ism; obj++ ) { - priority[obj] = L_max( priority[obj], ( Mpy_32_32( q_energy_ratio_ism[sf][band][obj], L_sub( 1073741824 /* 1.0f in Q30 */, masa_to_total_energy_ratio[sf][band] ) ) ) ); // Qx - 1 + priority[obj] = L_max( priority[obj], ( Mpy_32_32( q_energy_ratio_ism[sf][band][obj], L_sub( ONE_IN_Q30 /* 1.0f in Q30 */, masa_to_total_energy_ratio[sf][band] ) ) ) ); // Qx - 1 move32(); } } @@ -960,7 +970,7 @@ void calculate_nbits_meta_fx( } ELSE { - priority[0] = 536870912; /* 1.0f in Q29 */ + priority[0] = ONE_IN_Q29; /* 1.0f in Q29 */ move32(); } @@ -972,12 +982,12 @@ void calculate_nbits_meta_fx( { IF( EQ_16( ism_imp, 3 ) ) { - priority[obj] = 536870912; /* 1.0f in Q29 */ + priority[obj] = ONE_IN_Q29; /* 1.0f in Q29 */ move32(); } ELSE IF( EQ_16( ism_imp, 2 ) ) { - priority[obj] = L_shr( L_add( 536870912, max_p ), 1 ); + priority[obj] = L_shr( L_add( ONE_IN_Q29, max_p ), 1 ); // Q29 move32(); } ELSE @@ -1043,12 +1053,13 @@ void ivas_get_stereo_panning_gains( #define SIN_30_DEGREES_Q15 ( (Word16) 0x4000 ) void get_panning_gain( - const Word16 sinAngleMapped, - Word16 *panningGains ) + const Word16 sinAngleMapped, // Q15 + Word16 *panningGains // Q15 +) { Word16 tbl_len, idx, lim_l, lim_r; - const Word16 *ptr_sin = &ivas_sine_panning_tbl_fx[0]; - const Word16 *ptr_tan_0 = ivas_tan_panning_gain_tbl_fx; + const Word16 *ptr_sin = &ivas_sine_panning_tbl_fx[0]; // Q15 + const Word16 *ptr_tan_0 = ivas_tan_panning_gain_tbl_fx; // Q15 tbl_len = 601; move16(); @@ -1064,17 +1075,17 @@ void get_panning_gain( test(); IF( GE_16( idx, tbl_len ) ) { - panningGains[0] = ptr_tan_0[tbl_len - 1]; + panningGains[0] = ptr_tan_0[tbl_len - 1]; // Q15 move16(); - panningGains[1] = ptr_tan_0[0]; + panningGains[1] = ptr_tan_0[0]; // Q15 move16(); BREAK; } ELSE IF( idx < 0 ) { - panningGains[0] = ptr_tan_0[0]; + panningGains[0] = ptr_tan_0[0]; // Q15 move16(); - panningGains[1] = ptr_tan_0[tbl_len - 1]; + panningGains[1] = ptr_tan_0[tbl_len - 1]; // Q15 move16(); BREAK; } @@ -1082,17 +1093,17 @@ void get_panning_gain( { IF( EQ_16( sinAngleMapped, ptr_sin[idx + 1] ) ) { - panningGains[0] = ptr_tan_0[idx + 1]; + panningGains[0] = ptr_tan_0[idx + 1]; // Q15 move16(); - panningGains[1] = ptr_tan_0[sub( sub( tbl_len, idx ), 2 )]; + panningGains[1] = ptr_tan_0[tbl_len - idx - 2]; // Q15 move16(); BREAK; } ELSE IF( EQ_16( sinAngleMapped, ptr_sin[idx] ) ) { - panningGains[0] = ptr_tan_0[idx]; + panningGains[0] = ptr_tan_0[idx]; // Q15 move16(); - panningGains[1] = ptr_tan_0[sub( sub( tbl_len, idx ), 1 )]; + panningGains[1] = ptr_tan_0[tbl_len - idx - 1]; // Q15 move16(); BREAK; } @@ -1102,16 +1113,16 @@ void get_panning_gain( mid = extract_l( L_shr( L_add( L_deposit_l( ptr_sin[idx] ), L_deposit_l( ptr_sin[idx + 1] ) ), 1 ) ); IF( LE_16( sinAngleMapped, mid ) ) { - panningGains[0] = ptr_tan_0[idx]; + panningGains[0] = ptr_tan_0[idx]; // Q15 move16(); - panningGains[1] = ptr_tan_0[sub( sub( tbl_len, idx ), 1 )]; + panningGains[1] = ptr_tan_0[tbl_len - idx - 1]; // Q15 move16(); } ELSE { - panningGains[0] = ptr_tan_0[idx + 1]; + panningGains[0] = ptr_tan_0[idx + 1]; // Q15 move16(); - panningGains[1] = ptr_tan_0[sub( sub( tbl_len, idx ), 2 )]; + panningGains[1] = ptr_tan_0[tbl_len - idx - 2]; // Q15 move16(); } BREAK; @@ -1132,48 +1143,49 @@ void get_panning_gain( void ivas_get_stereo_panning_gains_fx( - const Word16 aziDeg, - const Word16 eleDeg, - Word16 panningGains[2] ) + const Word16 aziDeg, // Q0 + const Word16 eleDeg, // Q0 + Word16 panningGains[2] // Q15 +) { /* Convert azi and ele to an azi value of the cone of confusion */ - Word16 azAddEl = add( aziDeg, eleDeg ); - Word16 azSubEl = sub( aziDeg, eleDeg ); + Word16 azAddEl = add( aziDeg, eleDeg ); // Q0 + Word16 azSubEl = sub( aziDeg, eleDeg ); // Q0 - const Word16 *ptr_sin_az = ivas_sin_az_fx; + const Word16 *ptr_sin_az = ivas_sin_az_fx; // Q15 WHILE( GT_16( azAddEl, 180 ) ) { - azAddEl = sub( azAddEl, 360 ); + azAddEl = sub( azAddEl, 360 ); // Q0 } WHILE( LT_16( azAddEl, -180 ) ) { - azAddEl = add( azAddEl, 360 ); + azAddEl = add( azAddEl, 360 ); // Q0 } WHILE( GT_16( azSubEl, 180 ) ) { - azSubEl = sub( azSubEl, 360 ); + azSubEl = sub( azSubEl, 360 ); // Q0 } WHILE( LT_16( azSubEl, -180 ) ) { - azSubEl = add( azSubEl, 360 ); + azSubEl = add( azSubEl, 360 ); // Q0 } // sin_az_cos_el = (ptr_sin_az[azAddEl] + ptr_sin_az[azSubEl])/2; Word16 sin_az_cos_el; - sin_az_cos_el = extract_l( L_shr( L_add( L_deposit_l( ptr_sin_az[azAddEl + 180] ), L_deposit_l( ptr_sin_az[azSubEl + 180] ) ), 1 ) ); + sin_az_cos_el = extract_l( L_shr( L_add( L_deposit_l( ptr_sin_az[azAddEl + 180] ), L_deposit_l( ptr_sin_az[azSubEl + 180] ) ), 1 ) ); // Q15 IF( GE_16( sin_az_cos_el, SIN_30_DEGREES_Q15 ) ) - { /* Left side */ - panningGains[0] = (Word16) 0x7fff; + { /* Left side */ + panningGains[0] = (Word16) 0x7fff; // Q15 move16(); - panningGains[1] = 0; + panningGains[1] = 0; // Q15 move16(); } ELSE IF( LE_16( sin_az_cos_el, SIN_NEG_30_DEGREES_Q15 ) ) - { /* Right side */ - panningGains[0] = 0; + { /* Right side */ + panningGains[0] = 0; // Q15 move16(); - panningGains[1] = (Word16) 0x7fff; + panningGains[1] = (Word16) 0x7fff; // Q15 move16(); } ELSE /* Tangent panning law */ diff --git a/lib_com/ivas_pca_tools.c b/lib_com/ivas_pca_tools.c index 4df06a23d..e0fed0fa6 100644 --- a/lib_com/ivas_pca_tools.c +++ b/lib_com/ivas_pca_tools.c @@ -41,6 +41,7 @@ #include "prot.h" #ifdef IVAS_FLOAT_FIXED #include "prot_fx.h" +#include "ivas_prot_fx.h" #endif /*---------------------------------------------------------------------* @@ -85,9 +86,10 @@ static Word16 check_bound( Word32 tmp ) #ifdef IVAS_FLOAT_FIXED void eye_matrix_fx( - Word16 *mat, + Word16 *mat, // Q const Word16 n, - const Word16 d ) + const Word16 d // Q +) { Word16 i; @@ -98,7 +100,7 @@ void eye_matrix_fx( } FOR( i = 0; i < n; i++ ) { - mat[add( imult1616( i, n ), i )] = d; + mat[i * n + i] = d; // Q move16(); } @@ -120,7 +122,7 @@ void eye_matrix_fx32( } FOR( i = 0; i < n; i++ ) { - mat[i * n + i] = d; + mat[i * n + i] = d; // Q move32(); } @@ -190,7 +192,7 @@ void cov_subfr_fx( FOR( k = 0; k < n_channels; k++ ) { t_fx = &ptr_sig_fx[k][0]; - s_fx = W_shr( W_mult0_32_32( t_fx[0], t_fx[0] ), 11 ); // Q11 + s_fx = W_shr( W_mult0_32_32( t_fx[0], t_fx[0] ), 11 ); // Q11 + Q11 - Q11 -> Q11 FOR( j = 1; j < len; j++ ) { if ( s_fx != 0 ) @@ -198,7 +200,7 @@ void cov_subfr_fx( t_fx[j] = t_fx[j]; move32(); } - s_fx = W_add( s_fx, W_shr( W_mult0_32_32( t_fx[j], t_fx[j] ), 11 ) ); // Q11 + s_fx = W_add( s_fx, W_shr( W_mult0_32_32( t_fx[j], t_fx[j] ), 11 ) ); // Q11 + Q11 - Q11 -> Q11 } r_fx_64[k * n_channels + k] = s_fx; // Q11 move64(); @@ -211,7 +213,7 @@ void cov_subfr_fx( FOR( l = k + 1; l < n_channels; l++ ) { tt_fx = &ptr_sig_fx[l][0]; - s_fx = W_shr( W_mult0_32_32( t_fx[0], tt_fx[0] ), 11 ); // Q11 + s_fx = W_shr( W_mult0_32_32( t_fx[0], tt_fx[0] ), 11 ); // Q11 + Q11 - Q11 -> Q11 FOR( j = 1; j < len; j++ ) { s_fx = W_add( s_fx, W_shr( W_mult0_32_32( t_fx[j], tt_fx[j] ), 11 ) ); @@ -278,7 +280,7 @@ static void house_refl_fx( const Word16 sizex, Word32 *pu_fx, // Q: pu_q Word16 *pu_fx_q, - Word32 *normu_fx, // Q: q_norm + Word32 *normu_fx, // Q: q_normu Word16 *q_normu ) { Word16 i; @@ -292,7 +294,7 @@ static void house_refl_fx( move64(); FOR( Word16 k = 0; k < sizex; k++ ) { - L64_sum = W_mac_32_32( L64_sum, pu_fx[k], pu_fx[k] ); + L64_sum = W_mac_32_32( L64_sum, pu_fx[k], pu_fx[k] ); // pu_q } Word16 norm = W_norm( L64_sum ); L64_sum = W_shl( L64_sum, norm ); @@ -307,17 +309,17 @@ static void house_refl_fx( IF( ( *normu_fx ) == 0 ) { - pu_fx[0] = SQRT2_FIXED; // same q as other elements + pu_fx[0] = SQRT2_FIXED; // same q as other elements -> Q30 pu_e[0] = 1; move32(); move16(); } ELSE { - tmp = BASOP_Util_Divide3232_Scale( 1073741824, *normu_fx, &exp ); // Q30 + px_q, 1073741824 ->1 in Q30 + tmp = BASOP_Util_Divide3232_Scale( ONE_IN_Q30, *normu_fx, &exp ); // Q30 + px_q, 1073741824 ->1 in Q30 exp = add( exp, sub( 1, sub( 31, normu_q ) ) ); - Word32 rcp_fx = L_deposit_h( tmp ); + Word32 rcp_fx = L_deposit_h( tmp ); // rcp_q Word16 rcp_q = sub( Q31, exp ); rcp_fx = L_shr( rcp_fx, sub( rcp_q, Q31 ) ); // making rcp_fx in Q31 @@ -333,7 +335,7 @@ static void house_refl_fx( IF( pu_fx[0] >= 0 ) { - pu_fx[0] = L_add( pu_fx[0], L_shl( 1, 31 - pu_e[0] ) ); + pu_fx[0] = L_add( pu_fx[0], L_shl( 1, sub( 31, pu_e[0] ) ) ); ( *normu_fx ) = L_negate( *normu_fx ); move32(); @@ -341,7 +343,7 @@ static void house_refl_fx( } ELSE { - pu_fx[0] = L_sub( pu_fx[0], L_shl( 1, 31 - pu_e[0] ) ); + pu_fx[0] = L_sub( pu_fx[0], L_shl( 1, sub( 31, pu_e[0] ) ) ); move32(); } @@ -518,7 +520,7 @@ static void house_qr_fx( { FOR( i = 0; i < n_rows; i++ ) { - pa_fx[i] = A_fx[i * n + c]; + pa_fx[i] = A_fx[i * n + c]; // pA_q move32(); } @@ -527,7 +529,7 @@ static void house_qr_fx( Word16 norm; FOR( Word16 l = 0; l < n_rows - k; l++ ) { - L64_sum = W_mac_32_32( L64_sum, pa_fx[k + l], pu_fx[l] ); + L64_sum = W_mac_32_32( L64_sum, pa_fx[k + l], pu_fx[l] ); // pA_q + pu_fx_q } norm = W_norm( L64_sum ); L64_sum = W_shl( L64_sum, norm ); @@ -550,8 +552,8 @@ static void house_qr_fx( FOR( r = k + 1; r < n_rows; r++ ) { - A_fx[s * n_rows + r] = BASOP_Util_Add_Mant32Exp( A_fx[s * n_rows + r], sub( 31, pA_q ), L_negate( Mpy_32_32( pv_fx[j], pu_fx[i] ) ), add( sub( 31, pu_fx_q ), pv_exp[j] ), &exp2 ); - A_fx[s * n_rows + r] = L_shr_sat( A_fx[s * n_rows + r], sub( sub( 31, exp2 ), pA_q ) ); + A_fx[s * n_rows + r] = BASOP_Util_Add_Mant32Exp( A_fx[s * n_rows + r], sub( 31, pA_q ), L_negate( Mpy_32_32( pv_fx[j], pu_fx[i] ) ), add( sub( 31, pu_fx_q ), pv_exp[j] ), &exp2 ); // exp2 + A_fx[s * n_rows + r] = L_shr_sat( A_fx[s * n_rows + r], sub( sub( 31, exp2 ), pA_q ) ); // pA_q move32(); j = add( j, 1 ); } @@ -571,7 +573,7 @@ static void house_qr_fx( { FOR( i = 0; i < n_rows; i++ ) { - pu_fx[i] = L_shr( U_fx[i * n + k], sub( sub( 31, U_e[i * n + k] ), pu_fx_q ) ); + pu_fx[i] = L_shr( U_fx[i * n + k], sub( sub( 31, U_e[i * n + k] ), pu_fx_q ) ); // pu_fx_q move32(); } @@ -579,7 +581,7 @@ static void house_qr_fx( { FOR( i = 0; i < n_rows; i++ ) { - pa_fx[i] = pQ_fx[i * n + s]; + pa_fx[i] = pQ_fx[i * n + s]; // Q31 move32(); } @@ -711,7 +713,7 @@ void eig_qr_fx( move16(); /* check zero matrix */ - d_fx = dotp_fixed( A_fx, A_fx, n * n ); + d_fx = dotp_fixed( A_fx, A_fx, n * n ); // A_q + A_q - Q31 -> d_q d_q = sub( add( A_q, A_q ), 31 ); if ( d_fx != 0 ) @@ -720,14 +722,14 @@ void eig_qr_fx( move16(); } /* duplicate */ - Copy32( A_fx, Ak_fx, n * n ); + Copy32( A_fx, Ak_fx, n * n ); // A_q /* identity */ set_zero_fx( EV_fx, n * n ); FOR( i = 0; i < n; i++ ) { - EV_fx[i * n + i] = 2147483647; // 1 in Q31 + EV_fx[i * n + i] = ONE_IN_Q31; // 1 in Q31 move32(); } set_zero_fx( Vals_fx, n ); @@ -742,12 +744,12 @@ void eig_qr_fx( FOR( i = 0; i < n; i++ ) { - D_fx[i * n + i] = Vals_fx[i]; + D_fx[i * n + i] = Vals_fx[i]; // A_q move32(); } /* stop condition */ - d_fx = dotp_fixed_guarded( D_fx, D_fx, n * n ); + d_fx = dotp_fixed_guarded( D_fx, D_fx, n * n ); // ( A_q + A_q - 31 ) - find_guarded_bits_fx( n * n ) d_q = sub( sub( add( A_q, A_q ), 31 ), find_guarded_bits_fx( n * n ) ); exp = sub( 31, d_q ); d_fx = Sqrt32( d_fx, &exp ); @@ -761,11 +763,11 @@ void eig_qr_fx( house_qr_fx( Ak_fx, A_q, Qk_fx, Rk_fx, n ); - matrix_product_fx( Qk_fx, n, n, 0, Rk_fx, n, n, 0, Ak_fx ); - matrix_product_mant_exp_fx( Qk_fx, 0, n, n, 0, EV_fx, 0, n, n, 0, D_fx, &exp ); - Scale_sig32( D_fx, imult1616( n, n ), exp ); + matrix_product_fx( Qk_fx, n, n, 0, Rk_fx, n, n, 0, Ak_fx ); // A_q + Q31 - Q31 -> A_q + matrix_product_mant_exp_fx( Qk_fx, 0, n, n, 0, EV_fx, 0, n, n, 0, D_fx, &exp ); // Q31 + Q31 - Q31 -> Q31 + Scale_sig32( D_fx, imult1616( n, n ), exp ); // Q31 - Copy32( D_fx, EV_fx, imult1616( n, n ) ); + Copy32( D_fx, EV_fx, imult1616( n, n ) ); // Q31 } @@ -1056,8 +1058,8 @@ void mat2dquat_fx( /* determine (absolute) left and right terms */ i_ql = 0; i_qr = 0; - ql_max = MIN_16; - qr_max = MIN_16; + ql_max = MIN_16; // Q15 + qr_max = MIN_16; // Q15 move16(); move16(); move16(); @@ -1082,7 +1084,7 @@ void mat2dquat_fx( } - ql[i] = Sqrt16( tmp_l, &tmp_l_e ); + ql[i] = Sqrt16( tmp_l, &tmp_l_e ); // tmp_l_e ql[i] = check_bound( L_shl( ql[i], tmp_l_e ) ); // Q15 move16(); move16(); @@ -1094,13 +1096,13 @@ void mat2dquat_fx( move16(); } - qr[i] = Sqrt16( tmp_r, &tmp_r_e ); + qr[i] = Sqrt16( tmp_r, &tmp_r_e ); // tmp_r_e qr[i] = check_bound( L_shl( qr[i], tmp_r_e ) ); // Q15 move16(); move16(); IF( GT_16( qr[i], qr_max ) ) { - qr_max = qr[i]; + qr_max = qr[i]; // Q15 i_qr = i; move16(); move16(); @@ -1112,7 +1114,7 @@ void mat2dquat_fx( { IF( AM[i_ql * 4 + k] < 0 ) { - qr[k] = negate( qr[k] ); + qr[k] = negate( qr[k] ); // Q15 move16(); } } @@ -1122,7 +1124,7 @@ void mat2dquat_fx( temp = mult( AM[k * 4 + i_qr], mult( ql[k], qr[i_qr] ) ); // Q15 IF( temp < 0 ) { - ql[k] = negate( ql[k] ); + ql[k] = negate( ql[k] ); // Q15 move16(); } } @@ -1241,6 +1243,7 @@ void dquat2mat_fx( dx = mult( d, x ); dy = mult( d, y ); dz = mult( d, z ); + // Q15 m[0] = check_bound( L_sub( L_sub( aw, bx ), L_add( cy, dz ) ) ); move16(); m[1] = check_bound( L_sub( L_sub( cz, dy ), L_add( ax, bw ) ) ); @@ -1504,31 +1507,32 @@ static void norm_quat( #ifdef IVAS_FLOAT_FIXED -static Word32 dotp16_fixed_guarded( const Word16 x[], /* i : vector x[] */ - const Word16 y[], /* i : vector y[] */ - const Word16 n /* i : vector length */ ) +static Word32 dotp16_fixed_guarded( const Word16 x[], /* i : vector x[] Qx */ + const Word16 y[], /* i : vector y[] Qy */ + const Word16 n /* i : vector length */ ) { Word16 i; Word32 suma; Word16 guarded_bits = find_guarded_bits_fx( n ); - suma = L_shr( L_mult( x[0], y[0] ), guarded_bits ); + suma = L_shr( L_mult( x[0], y[0] ), guarded_bits ); // Qx + Qy - guarded_bits FOR( i = 1; i < n; i++ ) { - suma = L_add( suma, L_shr( L_mult( x[i], y[i] ), guarded_bits ) ); + suma = L_add( suma, L_shr( L_mult( x[i], y[i] ), guarded_bits ) ); // Qx + Qy - guarded_bits } return suma; } static void norm_quat_fx( - Word16 *q ) + Word16 *q // Q15 +) { Word32 norm_q; Word16 i, exp1; exp1 = 0; move16(); - norm_q = dotp16_fixed_guarded( q, q, IVAS_PCA_INTERP ); + norm_q = dotp16_fixed_guarded( q, q, IVAS_PCA_INTERP ); // (Q15 + Q15 - Q15) - exp1 exp1 = find_guarded_bits_fx( IVAS_PCA_INTERP ); norm_q = ISqrt32( norm_q, &exp1 ); /*Q(31 - exp)*/ @@ -1562,10 +1566,11 @@ static void quat_nlerp_preproc( #ifdef IVAS_FLOAT_FIXED static void quat_nlerp_preproc_fx( - const Word16 *q0, - const Word16 *q1, - const Word16 alpha, - Word16 *q_slerp ) + const Word16 *q0, // Q15 + const Word16 *q1, // Q15 + const Word16 alpha, // Q15 + Word16 *q_slerp // Q15 +) { Word16 i; Word16 tmp1, tmp2; @@ -1574,12 +1579,13 @@ static void quat_nlerp_preproc_fx( { tmp1 = mult( sub( MAX_16, alpha ), q1[i] ); tmp2 = mult_r( alpha, q0[i] ); - if ( EQ_16( alpha, q0[i] ) && EQ_16( alpha, 32767 ) ) + test(); + if ( EQ_16( alpha, q0[i] ) && EQ_16( alpha, MAX_16 ) ) { - tmp2 = 32767; + tmp2 = MAX_16; move16(); } - q_slerp[i] = add( tmp1, tmp2 ); + q_slerp[i] = add( tmp1, tmp2 ); // Q15 move16(); } @@ -1614,13 +1620,14 @@ void pca_interp_preproc( } #ifdef IVAS_FLOAT_FIXED void pca_interp_preproc_fx( - const Word16 *prev_ql, - const Word16 *prev_qr, - const Word16 *ql, - const Word16 *qr, + const Word16 *prev_ql, // Q15 + const Word16 *prev_qr, // Q15 + const Word16 *ql, // Q15 + const Word16 *qr, // Q15 const Word16 len, - Word16 *ql_interp, - Word16 *qr_interp ) + Word16 *ql_interp, // Q15 + Word16 *qr_interp // Q15 +) { Word16 alpha; Word16 j; @@ -1641,7 +1648,7 @@ void pca_interp_preproc_fx( tmp2 = mult( EVS_PI_FX, alpha ); /* Q13 */ tmp3 = getCosWord16( tmp2 ); /* Q14 */ alpha = sub_sat( ONE_IN_Q14, tmp3 ); /* Q15 */ - alpha = sub( MAX_16, alpha ); + alpha = sub( MAX_16, alpha ); // Q15 quat_nlerp_preproc_fx( prev_ql, ql, alpha, &ql_interp[j * IVAS_PCA_INTERP] ); quat_nlerp_preproc_fx( prev_qr, qr, alpha, &qr_interp[j * IVAS_PCA_INTERP] ); } @@ -1669,11 +1676,11 @@ static Word16 acos_clip_fx( { Word16 ph_fx; - v_fx = check_bounds_s_fx( v_fx, -32767, 32767 ); + v_fx = check_bounds_s_fx( v_fx, -32767, 32767 ); // Q15 Word32 tmp1_fx, tmp2_fx; Word16 tmp1_e, tmp2_e; - tmp1_fx = L_sub( 2147483647, L_deposit_h( mult( v_fx, v_fx ) ) ); // Q31 + tmp1_fx = L_sub( ONE_IN_Q31, L_deposit_h( mult( v_fx, v_fx ) ) ); // Q31 tmp1_e = 0; tmp2_e = 0; move16(); @@ -1718,7 +1725,7 @@ static void sp2cart_fx( Word16 s1, s2, s1s2; Word16 sin_ph3, cos_ph3; - sin_ph3 = cos_ph3 = ph3; + sin_ph3 = cos_ph3 = ph3; // Q12 move16(); move16(); @@ -2063,8 +2070,8 @@ static void q_ang_circ_fx( } assert( ( *index >= 0 ) && ( *index <= ( N - 1 ) ) ); - d_fx = shl( d_fx, sub( 12, sub( 15, d_e ) ) ); - *a_q_fx = extract_l( L_mult0( *index, d_fx ) ); + d_fx = shl( d_fx, sub( 12, sub( 15, d_e ) ) ); // Q12 + *a_q_fx = extract_l( L_mult0( *index, d_fx ) ); // Q12 move16(); return; @@ -2548,9 +2555,9 @@ void pca_dec_s3_fx( assert( index1 > -1 ); - ph1_q_fx = ph1_q_n2_tbl[index1][0]; + ph1_q_fx = ph1_q_n2_tbl[index1][0]; // Q13 move16(); - n2 = ph1_q_n2_tbl[index1][1]; + n2 = ph1_q_n2_tbl[index1][1]; // Q0 move16(); j = L_sub( j, ivas_pca_offset_index1[index1] ); @@ -2576,7 +2583,7 @@ void pca_dec_s3_fx( ELSE { - num_fx = 12868; + num_fx = 12868; // EVS_PI in Q12 move16(); d_fx = BASOP_Util_Divide1616_Scale( num_fx, sub( n2, 1 ), &exp ); /* Q12 */ diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index 75c7d206f..b63a975d3 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -86,10 +86,6 @@ void copy_encoder_config( void ivas_write_format( Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ ); -#else -void ivas_write_format_fx( /* i/o: IVAS encoder structure */ - Encoder_Struct *st_ivas -); #endif #ifndef IVAS_FLOAT_FIXED @@ -98,12 +94,6 @@ void ivas_write_format_sid( const int16_t element_mode, /* i : element bitrate */ BSTR_ENC_HANDLE hBstr /* i/o: encoder bitstream handle */ ); -#else -void ivas_write_format_sid_fx( - const IVAS_FORMAT ivas_format, /* i : IVAS format */ - const Word16 element_mode, /* i : element bitrate */ - BSTR_ENC_HANDLE hBstr /* i/o: encoder bitstream handle */ -); #endif ivas_error create_sce_enc( @@ -112,12 +102,6 @@ ivas_error create_sce_enc( const int32_t element_brate /* i : element bitrate */ ); -ivas_error create_sce_enc_fx( - Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ - const Word16 sce_id, /* i : SCE # identifier */ - const Word32 element_brate /* i : element bitrate */ -); - ivas_error create_evs_sce_enc( Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ const int16_t sce_id, /* i : SCE # identifier */ @@ -130,12 +114,6 @@ ivas_error create_cpe_enc( const int32_t element_brate /* i : element bitrate */ ); -ivas_error create_cpe_enc_fx( - Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ - const Word16 cpe_id, /* i : CPE # identifier */ - const Word32 element_brate /* i : element bitrate */ -); - ivas_error create_mct_enc( Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ ); @@ -180,16 +158,7 @@ ivas_error ivas_sce_enc( const int16_t nb_bits_metadata /* i : number of metadata bits */ ); -#ifdef IVAS_FLOAT_FIXED -ivas_error ivas_cpe_enc( - Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ - const Word16 cpe_id, /* i : CPE # identifier */ - float data_f_ch0[], /* i : input signal for channel 0 */ - float data_f_ch1[], /* i : input signal for channel 1 */ - const Word16 input_frame, /* i : input frame length per channel */ - const Word16 nb_bits_metadata /* i : number of metadata bits */ -); -#else +#ifndef IVAS_FLOAT_FIXED ivas_error ivas_cpe_enc( Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ const int16_t cpe_id, /* i : CPE # identifier */ @@ -200,6 +169,15 @@ ivas_error ivas_cpe_enc( ); #endif +ivas_error ivas_cpe_enc( + Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ + const Word16 cpe_id, /* i : CPE # identifier */ + float data_f_ch0[], /* i : input signal for channel 0 */ + float data_f_ch1[], /* i : input signal for channel 1 */ + const Word16 input_frame, /* i : input frame length per channel */ + const Word16 nb_bits_metadata /* i : number of metadata bits */ +); + ivas_error ivas_mct_enc( Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ float *data[MCT_MAX_CHANNELS], /* i : input signal buffers */ @@ -381,15 +359,6 @@ void ivas_syn_output_f( float *synth_out /* o : integer 16 bits synthesis signal */ ); -#ifdef IVAS_FLOAT_FIXED -void ivas_syn_output_f_fx( - Word32 *synth[], /* i/o: float synthesis signal */ - const Word16 output_frame, /* i : output frame length (one channel) */ - const Word16 n_channels, /* i : number of output channels */ - Word32 *synth_out /* o : integer 16 bits synthesis signal */ -); -#endif - void ivas_initialize_handles_enc( Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ ); @@ -398,10 +367,6 @@ ivas_error ivas_init_encoder( Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ ); -ivas_error ivas_init_encoder_fx( - Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ -); - void destroy_core_enc( ENC_CORE_HANDLE hCoreCoder /* i/o: core encoder structure */ ); @@ -426,13 +391,6 @@ ivas_error ivas_init_decoder_front( ivas_error ivas_init_decoder( Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ ); -#ifdef IVAS_FLOAT_FIXED -ivas_error ivas_output_buff_dec_fx( - Word32 *p_output_f[], /* i/o: output audio buffers */ - const Word16 nchan_out_buff_old, /* i : previous frame number of output channels */ - const Word16 nchan_out_buff /* i : number of output channels */ -); -#else ivas_error ivas_output_buff_dec( float *p_output_f[], /* i/o: output audio buffers */ @@ -461,12 +419,6 @@ ivas_error ivas_dec_setup( uint16_t *nSamplesRendered, /* o : number of samples flushed from the previous frame (JBM) */ int16_t *data /* o : output synthesis signal */ ); -#else -ivas_error ivas_dec_setup( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ - UWord16 *nSamplesRendered, /* o : number of samples flushed from the previous frame (JBM) */ - Word16 *data /* o : output synthesis signal */ -); #endif #ifndef IVAS_FLOAT_FIXED @@ -482,12 +434,7 @@ ivas_error create_cpe_dec( const int32_t element_brate /* i : element bitrate */ ); #endif // !IVAS_FLOAT_FIXED -#ifdef IVAS_FLOAT_FIXED -ivas_error create_mct_dec_fx( - Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ -); -#else // IVAS_FLOAT_FIXED - +#ifndef IVAS_FLOAT_FIXED ivas_error create_mct_dec( Decoder_Struct *st_ivas /* i/o: IVAS decoder handle */ ); @@ -497,13 +444,6 @@ ivas_error mct_dec_reconfigure( const uint16_t b_nchan_change /* i : flag indicating different channel count */ ); -#ifdef IVAS_FLOAT_FIXED -ivas_error mct_dec_reconfigure_fx( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ - const UWord16 b_nchan_change /* i : flag indicating different channel count */ -); -#endif - #ifndef IVAS_FLOAT_FIXED void destroy_sce_dec( SCE_DEC_HANDLE hSCE /* i/o: SCE decoder structure */ @@ -518,17 +458,6 @@ void ivas_mct_dec_close( MCT_DEC_HANDLE *hMCT /* i/o: MCT decoder structure */ ); -#ifdef IVAS_FLOAT_FIXED -ivas_error ivas_corecoder_dec_reconfig_fx( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ - const Word16 nSCE_old, /* i : number of SCEs in previous frame */ - Word16 nCPE_old, /* i : number of CPEs in previous frame */ - const Word16 nchan_transport_old, /* i : number of TCs in previous frame */ - const Word16 sba_dirac_stereo_flag_old, /* i : signal stereo rendering using DFT upmix in previous frame */ - const Word32 brate_SCE, /* i : bitrate to be set for the SCEs */ - const Word32 brate_CPE /* i : bitrate to be set for the CPEs */ -); -#endif ivas_error ivas_corecoder_dec_reconfig( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ const int16_t nSCE_old, /* i : number of SCEs in previous frame */ @@ -538,12 +467,6 @@ ivas_error ivas_corecoder_dec_reconfig( const int32_t brate_SCE, /* i : bitrate to be set for the SCEs */ const int32_t brate_CPE /* i : bitrate to be set for the CPEs */ ); -#ifdef IVAS_FLOAT_FIXED -ivas_error ivas_hp20_dec_reconfig_fx( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ - const Word16 nchan_hp20_old /* i : number of HP20 filters in previous frame*/ -); -#endif // IVAS_FLOAT_FIXED ivas_error ivas_hp20_dec_reconfig( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ @@ -574,11 +497,7 @@ ivas_error ivas_mct_dec( ); /*! r: number of channels to be synthesised */ -#ifdef IVAS_FLOAT_FIXED -Word16 getNumChanSynthesis( - Decoder_Struct *st_ivas /* i : IVAS decoder structure */ -); -#else +#ifndef IVAS_FLOAT_FIXED int16_t getNumChanSynthesis( Decoder_Struct *st_ivas /* i : IVAS decoder structure */ ); @@ -597,10 +516,6 @@ void destroy_core_dec( void ivas_destroy_dec( Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ ); -#else -void ivas_destroy_dec_fx( - Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ -); #endif void ivas_initialize_handles_dec( @@ -634,19 +549,7 @@ ivas_error ivas_core_enc( const int16_t ivas_format, /* i : IVAS format */ const int16_t flag_16k_smc /* i : flag to indicate if the OL SMC is run at 16 kHz */ ); -#ifdef IVAS_FLOAT_FIXED -ivas_error ivas_core_dec_fx( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ - SCE_DEC_HANDLE hSCE, /* i/o: SCE decoder structure */ - CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ - MCT_DEC_HANDLE hMCT, /* i/o: MCT decoder structure */ - const int16_t n_channels, /* i : number of channels to be decoded */ - Word32 *output_fx[], /* o : output synthesis signal */ - Word32 outputHB[][L_FRAME48k], /* o : output HB synthesis signal */ - Word32 DFT_fx[CPE_CHANNELS][STEREO_DFT_BUF_MAX], /* o : DFT buffers */ - const int16_t sba_dirac_stereo_flag /* i : signal stereo output for SBA DirAC */ -); -#else +#ifndef IVAS_FLOAT_FIXED ivas_error ivas_core_dec( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ SCE_DEC_HANDLE hSCE, /* i/o: SCE decoder structure */ @@ -693,22 +596,6 @@ void decod_gen_2sbfr( const float tdm_Pri_pitch_buf[] /* i : pitch values for primary channel */ ); -#ifdef IVAS_FLOAT_FIXED -void decod_gen_2sbfr_ivas_fx( - Decoder_State *st, /* i/o: decoder static memory */ - const Word16 sharpFlag, /* i : formant sharpening flag `Q0*/ - const Word16 *Aq, /* i : LP filter coefficient Q12*/ - Word16 *pitch_buf, /* o : Word16 pitch values for each subframe Q6*/ - Word16 *voice_factors, /* o : voicing factors Q15*/ - Word16 *exc, /* i/o: adapt. excitation exc Q_exc*/ - Word16 *exc2, /* i/o: adapt. excitation/total exc Q_exc*/ - Word16 *bwe_exc, /* o : excitation for SWB TBE Q_exc*/ - Word16 *gain_buf, /* o : Word16 pitch gain for each subframe Q14*/ - const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag Q0*/ - const Word16 tdm_Pri_pitch_buf[] /* i : pitch values for primary channel Q6*/ -); -#endif - void synchro_synthesis( const int32_t ivas_total_brate, /* i : IVAS total bitrate */ CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ @@ -758,6 +645,19 @@ void stereo_tcx_core_dec( ); #endif // !IVAS_FLOAT_FIXED +void stereo_tcx_core_enc( + Encoder_State *st, /* i/o: encoder state structure */ + const float new_samples_12k8[], /* i : buffer of input signal @12.8 kHz */ + const float new_samples_16k[], /* i : buffer of input signal @16 kHz */ + const Word16 Aw_fx[], /* i : weighted A(z) unquant. for subframes, Q12 */ + float lsp_new[], /* i : LSPs at the end of the frame, Q15 */ + float lsp_mid[], /* i : LSPs in the middle of the frame, Q15 */ + Word16 pitch_buf_fx[NB_SUBFR16k], /* o : pitch for each subframe, Q6 */ + const Word16 last_element_mode, /* i : last element mode, Q0 */ + const Word16 vad_hover_flag /* i : VAD hangover flag, Q0 */ +); + + void stereo_tcx_init_dec( Decoder_State *st, /* i/o: decoder state structure */ const int16_t MCT_flag, /* i : hMCT handle allocated (1) or not (0) */ @@ -779,27 +679,7 @@ int16_t ivas_smc_gmm( int16_t *high_lpn_flag, /* i/o: sp/mus LPN flag */ const int16_t flag_spitch /* i : flag to indicate very short stable pitch */ ); -#ifdef IVAS_FLOAT_FIXED -/*! r: S/M decision (0=speech or noise,1=unclear,2=music) */ -Word16 ivas_smc_gmm_fx( - Encoder_State *st, /* i/o: state structure */ - STEREO_CLASSIF_HANDLE hStereoClassif, /* i/o: stereo classifier structure */ - const Word16 localVAD_HE_SAD, /* i : HE-SAD flag without hangover */ - const Word16 Etot_fx, /* i : total frame energy */ - Word16 lsp_new_fx[M], /* i : LSPs in current frame TODO:For now removing 'const' to avoid warning */ - Word16 cor_map_sum_fx, /* i : correlation map sum (from multi-harmonic anal.) */ - Word32 epsP_fx[M + 1], /* i : LP prediciton error TODO:For now removing 'const' to avoid warning */ - Word32 PS_fx[], /* i : energy spectrum TODO:For now removing 'const' to avoid warning */ - const Word16 non_sta_fx, /* i : unbound non-stationarity */ - const Word16 relE_fx, /* i : relative frame energy */ - Word16 *high_lpn_flag, /* i/o: sp/mus LPN flag */ - const Word16 flag_spitch /* i : flag to indicate very short stable pitch */ - , - Word16 Qfact_PS, - Word16 Q_esp, - Word16 Qfact_PS_past -); -#endif + void ivas_smc_mode_selection( Encoder_State *st, /* i/o: encoder state structure */ const int32_t element_brate, /* i : element bitrate */ @@ -835,26 +715,9 @@ void ivas_decision_matrix_enc( const float enerBuffer[], /* i : energy buffer */ const int16_t last_element_mode /* i : last element mode */ ); -#else -void ivas_decision_matrix_enc_fx( - Encoder_State *st, /* i : encoder state structure */ - const Word32 element_brate, /* i : element bitrate */ - const Word16 fft_buff[], /* i : FFT buffer */ - const Word32 enerBuffer[], /* i : energy buffer */ - Word16 enerBuffer_exp, - const Word16 last_element_mode /* i : last element mode */ -); #endif -#ifdef IVAS_FLOAT_FIXED -void ivas_signaling_enc_fx( - Encoder_State *st, /* i/o: encoder state structure */ - const Word16 MCT_flag, /* i : hMCT handle allocated (1) or not (0) */ - const Word32 element_brate, /* i : element bitrate */ - const Word16 tdm_SM_or_LRTD_Pri, /* i : channel combination scheme flag in TD stereo OR LRTD primary channel */ - const Word16 tdm_Pitch_reuse_flag /* i : primary channel pitch reuse flag in TD stereo */ -); -#else +#ifndef IVAS_FLOAT_FIXED void ivas_signaling_enc( Encoder_State *st, /* i/o: encoder state structure */ const int16_t MCT_flag, /* i : hMCT handle allocated (1) or not (0) */ @@ -964,20 +827,12 @@ void smooth_dft2td_transition( const int16_t output_frame /* i : output frame length */ ); -void smooth_dft2td_transition_fx( - CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ - Word32 *output_fx[CPE_CHANNELS], /* i/o: synthesis @external Fs Q11*/ - const Word16 output_frame /* i : output frame lenght Q0*/ -); + /*! r: flag indicating a valid bitrate */ int16_t is_IVAS_bitrate( const int32_t ivas_total_brate /* i : IVAS total bitrate */ ); -Word16 is_IVAS_bitrate_fx( - const Word32 ivas_total_brate /* i : IVAS total bitrate */ -); - int16_t is_DTXrate( const int32_t ivas_total_brate /* i : IVAS total bitrate */ ); @@ -1002,35 +857,7 @@ void ivas_imdft( float *pOut, /* o : output time-domain signal */ const int16_t length /* i : signal length */ ); -#ifdef IVAS_FLOAT_FIXED -void ivas_mdft_fx( - const Word32 *pIn, /* i : input time-domain signal */ - Word32 *pOut_re, /* o : Real part of MDFT signal */ - Word32 *pOut_im, /* o : Imag. part of MDFT signal */ - const Word16 length, /* i : signal length */ - const Word16 mdft_length /* i : MDFT length */ -); -void ivas_imdft_fx( - const Word32 *pRe, /* i : Real part of MDFT signal */ - const Word32 *pIm, /* i : Imag. part of MDFT signal */ - Word32 *pOut, /* o : output time-domain signal */ - const Word16 length /* i : signal length */ -); -#endif -#ifdef IVAS_FLOAT_FIXED -void TonalMdctConceal_create_concealment_noise_ivas_fx( - Word32 concealment_noise[L_FRAME48k], - Word16 *concealment_noise_exp, - CPE_DEC_HANDLE hCPE, - const Word16 L_frameTCX, - const Word16 L_frame, - const Word16 idchan, - const Word16 subframe_idx, - const Word16 core, - const Word16 crossfade_gain, - const TONALMDCTCONC_NOISE_GEN_MODE noise_gen_mode); -#endif void TonalMdctConceal_create_concealment_noise_ivas( float concealment_noise[L_FRAME48k], CPE_DEC_HANDLE hCPE, @@ -1061,16 +888,6 @@ int16_t get_igf_startline_flt( float rand_triangular_signed( int16_t *seed ); -#ifdef IVAS_FLOAT_FIXED -Word16 rand_triangular_signed_fx( - Word16 *seed, - Word16 *exp_fac); -#endif -Word64 var_32_fx( - const Word32 *x, /* i : input vector */ - const Word16 len, /* i : length of inputvector */ - Word16 q /* q : q-factor for the array */ -); void dtx_read_padding_bits( DEC_CORE_HANDLE st, @@ -1090,17 +907,13 @@ void ivas_apply_non_diegetic_panning( * JBM prototypes *----------------------------------------------------------------------------------*/ -#ifdef IVAS_FLOAT_FIXED -ivas_error ivas_jbm_dec_tc_fx( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ - Word32 *data_fx -); -#else +#ifndef IVAS_FLOAT_FIXED ivas_error ivas_jbm_dec_tc( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ float *data /* o : output synthesis signals */ ); #endif + #ifndef IVAS_FLOAT_FIXED ivas_error ivas_jbm_dec_render( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ @@ -1110,19 +923,6 @@ ivas_error ivas_jbm_dec_render( int16_t *data /* o : output synthesis signal */ ); #endif -#ifdef IVAS_FLOAT_FIXED -ivas_error ivas_jbm_dec_flush_renderer_fx( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ - const Word16 tc_granularity_new, /* i : new renderer granularity */ - const RENDERER_TYPE renderer_type_old, /* i : old renderer type */ - const AUDIO_CONFIG intern_config_old, /* i : old internal config */ - const IVAS_OUTPUT_SETUP_HANDLE hIntSetupOld, /* i : old internal output setup */ - const MC_MODE mc_mode_old, /* i : old MC mode */ - const ISM_MODE ism_mode_old, /* i : old ISM mode */ - UWord16 *nSamplesRendered, /* o : number of samples flushed */ - Word16 *data /* o : output synthesis signal */ -); -#endif // IVAS_FLOAT_FIXED ivas_error ivas_jbm_dec_flush_renderer( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ @@ -1142,19 +942,6 @@ void ivas_jbm_dec_feed_tc_to_renderer( int16_t *nSamplesResidual, /* o : number of samples not fitting into the renderer grid and buffer for the next call*/ float *data /* i/o: transport channels/output synthesis signal */ ); -void ivas_jbm_dec_feed_tc_to_renderer_fx( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ - const Word16 nSamplesForRendering, /* i : number of TC samples available for rendering */ - Word16 *nSamplesResidual, /* o : number of samples not fitting into the renderer grid and buffer for the next call*/ - Word32 *data /* i/o: transport channels/output synthesis signal */ -); - -void ivas_jbm_dec_feed_tc_to_renderer_fx( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ - const int16_t nSamplesForRendering, /* i : number of TC samples available for rendering */ - int16_t *nSamplesResidual, /* o : number of samples not fitting into the renderer grid and buffer for the next call*/ - Word32 *data /* i/o: transport channels/output synthesis signal */ -); ivas_error ivas_jbm_dec_set_discard_samples( Decoder_Struct *st_ivas /* i/o: main IVAS decoder structre */ @@ -1166,13 +953,7 @@ void ivas_jbm_dec_get_adapted_linear_interpolator( float *interpolator /* o : the interpolator */ ); -#ifdef IVAS_FLOAT_FIXED -void ivas_jbm_dec_get_adapted_subframes( - const Word16 nCldfbTs, /* i : number of time slots in the current frame */ - Word16 *subframe_nbslots, /* i/o: subframe grid */ - Word16 *nb_subframes /* i/o: number of subframes in the frame */ -); -#else +#ifndef IVAS_FLOAT_FIXED void ivas_jbm_dec_get_adapted_subframes( const int16_t nCldfbTs, /* i : number of time slots in the current frame */ int16_t *subframe_nbslots, /* i/o: subframe grid */ @@ -1180,16 +961,7 @@ void ivas_jbm_dec_get_adapted_subframes( ); #endif -#ifdef IVAS_FLOAT_FIXED -void ivas_jbm_dec_get_md_map( - const Word16 default_len, /* i : default frame length in metadata slots */ - const Word16 len, /* i : length of the modfied frames in metadata slots */ - const Word16 subframe_len, /* i : default length of a subframe */ - const Word16 offset, /* i : current read offset into the md buffer */ - const Word16 buf_len, /* i : length of the metadata buffer */ - Word16 *map /* o : metadata index map */ -); -#else +#ifndef IVAS_FLOAT_FIXED void ivas_jbm_dec_get_md_map( const int16_t default_len, /* i : default frame length in metadata slots */ const int16_t len, /* i : length of the modfied frames in metadata slots */ @@ -1210,15 +982,7 @@ void ivas_jbm_dec_copy_tc_no_tsm( const int16_t output_frame /* i : output frame size */ ); -#ifdef IVAS_FLOAT_FIXED -void ivas_jbm_dec_get_md_map_even_spacing( - const Word16 len, /* i : length of the modfied frames in metadata slots */ - const Word16 subframe_len, /* i : default length of a subframe */ - const Word16 offset, /* i : current read offset into the md buffer */ - const Word16 buf_len, /* i : length of the metadata buffer */ - Word16 *map /* o : metadata index map */ -); -#else +#ifndef IVAS_FLOAT_FIXED void ivas_jbm_dec_get_md_map_even_spacing( const int16_t len, /* i : length of the modfied frames in metadata slots */ const int16_t subframe_len, /* i : default length of a subframe */ @@ -1295,9 +1059,9 @@ ivas_error ivas_ism_config( #ifdef IVAS_FLOAT_FIXED void bitbudget_to_brate( - const Word16 x[], /* i : bitbudgets */ - Word32 y[], /* o : bitrates */ - const Word16 N /* i : number of entries to be converted */ + const Word16 x[], /* i : bitbudgets Q0 */ + Word32 y[], /* o : bitrates Q0 */ + const Word16 N /* i : number of entries to be converted */ ); #else void bitbudget_to_brate( @@ -1321,12 +1085,12 @@ void ivas_ism_reset_metadata_API( /*! r: index of the winning codeword */ #ifdef IVAS_FLOAT_FIXED Word16 ism_quant_meta_fx( - const Word32 val, /* i : scalar value to quantize */ - Word32 *valQ, /* o : quantized value */ - const Word32 borders_fx[], /* i : level borders */ - const Word32 q_step_fx, /* i : quantization step */ - const Word32 q_step_border_fx, /* i : quantization step at the border */ - const Word16 cbsize /* i : codebook size */ + const Word32 val, /* i : scalar value to quantize Q22 */ + Word32 *valQ, /* o : quantized value Q22 */ + const Word32 borders_fx[], /* i : level borders Q22 */ + const Word32 q_step_fx, /* i : quantization step Q22 */ + const Word32 q_step_border_fx, /* i : quantization step at the border Q22 */ + const Word16 cbsize /* i : codebook size */ ); #endif @@ -1348,17 +1112,7 @@ float ism_dequant_meta( const int16_t cbsize /* i : codebook size */ ); -#ifdef IVAS_FLOAT_FIXED -ivas_error ivas_set_ism_metadata_fx( - ISM_METADATA_HANDLE hIsmMeta, /* o : ISM metadata handle */ - const Word32 azimuth, /* i : azimuth value */ - const Word32 elevation, /* i : elevation value */ - const Word16 radius_meta, /* i : radius */ - const Word32 yaw, /* i : yaw */ - const Word32 pitch, /* i : pitch */ - const Word16 non_diegetic_flag /* i : non-diegetic object flag */ -); -#else +#ifndef IVAS_FLOAT_FIXED ivas_error ivas_set_ism_metadata( ISM_METADATA_HANDLE hIsmMeta, /* o : ISM metadata handle */ const float azimuth, /* i : azimuth value */ @@ -1389,25 +1143,7 @@ ivas_error ivas_ism_enc( const int16_t flag_omasa_ener_brate /* i : less bitrate for objects in OMASA flag */ ); -#ifdef IVAS_FLOAT_FIXED -ivas_error ivas_ism_metadata_enc( - Word32 *ism_total_brate, /* i/o: ISM total bitrate */ - const Word16 nchan_ism, /* i : number of ISM channels */ - const Word16 nchan_transport, /* i : number of transport channels */ - ISM_METADATA_HANDLE hIsmMeta[], /* i/o: ISM metadata handles */ - SCE_ENC_HANDLE hSCE[], /* i/o: SCE encoder handles */ - BSTR_ENC_HANDLE hBstr, /* i/o: bitstream handle */ - Word16 nb_bits_metadata[], /* o : number of metadata bits */ - const Word16 localVAD[], /* i : VAD flag */ - const Word16 ism_mode, /* i : ISM mode */ - const PARAM_ISM_CONFIG_HANDLE hParamIsm, /* i : Param ISM Config Handle */ - const Word16 ism_extended_metadata_flag, /* i : Extended metadata flag */ - const Word16 lp_noise_CPE, /* i : LP filtered total noise estimation */ - const Word16 flag_omasa_ener_brate, /* i : less bitrate for objects in OMASA flag */ - Word16 *omasa_stereo_sw_cnt, - const Word16 ini_frame -); -#else +#ifndef IVAS_FLOAT_FIXED ivas_error ivas_ism_metadata_enc( int32_t *ism_total_brate, /* i/o: ISM total bitrate */ const int16_t nchan_ism, /* i : number of ISM channels */ @@ -1492,15 +1228,8 @@ void ivas_param_ism_config( ivas_error ivas_ism_enc_config( Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ ); -#ifdef IVAS_FLOAT_FIXED -ivas_error ivas_ism_dec_config( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ - const ISM_MODE last_ism_mode, /* i/o: last ISM mode */ - UWord16 *nSamplesRendered, /* o : number of samples flushed when the renderer granularity changes */ - Word16 *data /* o : output synthesis signal */ -); -#else +#ifndef IVAS_FLOAT_FIXED ivas_error ivas_ism_dec_config( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ const ISM_MODE last_ism_mode, /* i/o: last ISM mode */ @@ -1509,23 +1238,13 @@ ivas_error ivas_ism_dec_config( ); #endif // IVAS_FLOAT_FIXED -#ifdef IVAS_FLOAT_FIXED -ivas_error ivas_param_ism_dec_open_fx( - Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ -); -#else +#ifndef IVAS_FLOAT_FIXED ivas_error ivas_param_ism_dec_open( Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ ); #endif -#ifdef IVAS_FLOAT_FIXED -void ivas_param_ism_dec_close_fx( - PARAM_ISM_DEC_HANDLE *hParamIsmDec, /* i/o: decoder ParamISM handle */ - SPAT_PARAM_REND_COMMON_DATA_HANDLE *hSpatParamRendCom_out, /* i/o: common spatial renderer data */ - const AUDIO_CONFIG output_config /* i : output audio configuration */ -); -#else +#ifndef IVAS_FLOAT_FIXED void ivas_param_ism_dec_close( PARAM_ISM_DEC_HANDLE *hParamIsmDec, /* i/o: decoder ParamISM handle */ SPAT_PARAM_REND_COMMON_DATA_HANDLE *hSpatParamRendCom_out, /* i/o: common spatial renderer data */ @@ -1538,23 +1257,11 @@ void ivas_param_ism_dec( float *output_f[] /* i/o: synthesized core-coder transport channels/DirAC output */ ); -#ifdef IVAS_FLOAT_FIXED -void ivas_ism_dec_digest_tc_fx( - Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ -); -#endif void ivas_ism_dec_digest_tc( Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ ); -#ifdef IVAS_FLOAT_FIXED -void ivas_param_ism_dec_digest_tc_fx( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ - const UWord16 nCldfbSlots, /* i : number of CLFBS slots in the transport channels */ - Word32 *transport_channels[], /* i : synthesized core-coder transport channels/DirAC output */ - Word16 q_tc_in -); -#else +#ifndef IVAS_FLOAT_FIXED void ivas_param_ism_dec_digest_tc( Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ const uint16_t nCldfbSlots, /* i : number of CLFBS slots in the transport channels */ @@ -1579,19 +1286,6 @@ void ivas_param_ism_dec_render( float *output_f[] /* o : rendered time signal */ ); -#ifdef IVAS_FLOAT_FIXED -void ivas_param_ism_dec_render_fx( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ - const UWord16 nSamplesAsked, /* i : number of CLDFB slots requested */ - UWord16 *nSamplesRendered, /* o : number of CLDFB slots rendered */ - UWord16 *nSamplesAvailable, /* o : number of CLDFB slots still to render */ - Word32 *output_f_fx[] -); -void ivas_param_ism_params_to_masa_param_mapping_fx( - Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ -); -#endif - void ivas_param_ism_params_to_masa_param_mapping( Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ ); @@ -1604,19 +1298,6 @@ void ivas_param_ism_params_to_masa_param_mapping( ivas_error ivas_ism_dtx_open( Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ ); -#ifdef IVAS_FLOAT_FIXED -Word16 ivas_ism_dtx_enc_fx( - ISM_DTX_HANDLE hISMDTX, /* i/o: ISM DTX handle */ - SCE_ENC_HANDLE hSCE[MAX_SCE], /* i/o: SCE encoder structure */ - const Word32 ivas_total_brate, /* i : IVAS total bitrate */ - const Word16 nchan_ism, /* i : number of objects */ - const Word16 nchan_transport, /* i : number of transport channels */ - Word16 vad_flag[MAX_NUM_OBJECTS], /* i : VAD flag */ - ISM_METADATA_HANDLE hIsmMeta[], /* i/o: ISM metadata handles */ - Word16 md_diff_flag[], /* o : metadata differential flag */ - Word16 *sid_flag /* o : indication of SID frame */ -); -#endif // IVAS_FLOAT_FIXED /*! r: indication of DTX frame */ int16_t ivas_ism_dtx_enc( @@ -1630,12 +1311,6 @@ int16_t ivas_ism_dtx_enc( int16_t md_diff_flag[], /* o : metadata differential flag */ int16_t *sid_flag /* o : indication of SID frame */ ); -#ifdef IVAS_FLOAT_FIXED -void ivas_ism_dtx_dec_fx( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ - Word16 *nb_bits_metadata /* o : number of metadata bits */ -); -#endif // IVAS_FLOAT_FIXED void ivas_ism_dtx_dec( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ @@ -1667,14 +1342,6 @@ void ivas_ism_metadata_sid_dec( ISM_METADATA_HANDLE hIsmMeta[], /* i/o: ISM metadata handles */ int16_t nb_bits_metadata[] /* o : number of metadata bits */ ); -#ifdef IVAS_FLOAT_FIXED -void ivas_ism_get_sce_id_dtx_fx( - ISM_DTX_HANDLE hISMDTX, /* i/o: ISM DTX handle */ - SCE_ENC_HANDLE hSCE[MAX_SCE], /* i/o: SCE encoder structure */ - const Word16 nchan_transport, /* i : number of transport channels */ - const Word16 input_frame /* i : input frame length per channel */ -); -#endif // IVAS_FLOAT_FIXED void ivas_ism_get_sce_id_dtx( ISM_DTX_HANDLE hISMDTX, /* i/o: ISM DTX handle */ @@ -1687,14 +1354,6 @@ void ivas_param_ism_compute_noisy_speech_flag( Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ ); -#ifdef IVAS_FLOAT_FIXED -void ivas_ism_coh_estim_dtx_enc_fx( - ISM_DTX_HANDLE hISMDTX, /* i/o: ISM DTX handle */ - SCE_ENC_HANDLE hSCE[MAX_SCE], /* i/o: SCE encoder structure */ - const Word16 nchan_transport, /* i : number of transport channels */ - const Word16 input_frame /* i : input frame length */ -); -#endif // IVAS_FLOAT_FIXED void ivas_ism_coh_estim_dtx_enc( ISM_DTX_HANDLE hISMDTX, /* i/o: ISM DTX handle */ SCE_ENC_HANDLE hSCE[MAX_SCE], /* i/o: SCE encoder structure */ @@ -1717,14 +1376,6 @@ void ivas_get_ism_sid_quan_bitbudget( int16_t *nBits_coh, /* o : number of Q bits for coherence */ int16_t *nBits_sce_id /* o : number of Q bits for sce_id_dtx */ ); -#ifdef IVAS_FLOAT_FIXED -void ivas_ism_dtx_limit_noise_energy_for_near_silence_fx( - SCE_DEC_HANDLE hSCE[], /* i/o: SCE decoder structures */ - const Word16 sce_id_dtx, /* i : SCE DTX ID */ - const Word16 nchan_transport, /* i : number of transport channels */ - Word16 *Q_cngNoiseLevel -); -#endif // IVAS_FLOAT_FIXED void ivas_ism_dtx_limit_noise_energy_for_near_silence( SCE_DEC_HANDLE hSCE[], /* i/o: SCE decoder structures */ @@ -1742,34 +1393,15 @@ ivas_error stereo_dft_enc_create( const int16_t max_bwidth /* i : maximum encoded bandwidth */ ); -ivas_error stereo_dft_enc_create_fx( - STEREO_DFT_ENC_DATA_HANDLE *hStereoDft, /* o : encoder DFT stereo handle */ - const Word32 input_Fs, /* i : input sampling rate */ - const Word16 max_bwidth /* i : maximum encoded bandwidth */ -); - void stereo_dft_enc_reset( STEREO_DFT_ENC_DATA_HANDLE hStereoDft /* i/o: encoder stereo handle */ ); -void stereo_dft_enc_reset_fx( - STEREO_DFT_ENC_DATA_HANDLE hStereoDft /* i/o: encoder stereo handle */ -); - void stereo_enc_itd_init( ITD_DATA_HANDLE hItd /* i/o: encoder ITD handle */ ); -void stereo_enc_itd_init_fx( - ITD_DATA_HANDLE hItd /* i/o: encoder ITD handle */ -); - -#ifdef IVAS_FLOAT_FIXED -void stereo_dft_enc_update_fx( - STEREO_DFT_ENC_DATA_HANDLE hStereoDft, /* i/o: encoder stereo handle */ - const Word16 max_bwidth /* i : maximum encoded bandwidth */ -); -#else +#ifndef IVAS_FLOAT_FIXED void stereo_dft_enc_update( STEREO_DFT_ENC_DATA_HANDLE hStereoDft, /* i/o: encoder DFT stereo handle */ const int16_t max_bwidth /* i : maximum encoded bandwidth */ @@ -1840,16 +1472,6 @@ void stereo_dft_cng_side_gain( const int16_t bwidth /* i : audio band-width */ ); -#ifdef IVAS_FLOAT_FIXED -void stereo_dft_quantize_res_gains_fx( - const Word32 *g, //Q31 - const Word32 *r, //Q31 - Word32 *gq, //Q31 - Word32 *rq, //Q31 - Word16 *ig, - Word16 *ir); -#endif - void stereo_dft_quantize_res_gains( const float *g, const float *r, @@ -1858,13 +1480,6 @@ void stereo_dft_quantize_res_gains( int16_t *ig, int16_t *ir ); -#ifdef IVAS_FLOAT_FIXED -void stereo_dft_dequantize_itd_fx( - Word16 *ind, /* Q0 */ - Word32 *out, /* Q15 */ - const Word32 output_Fs /* Q0 */ -); -#endif // IVAS_FLOAT_FIXED void stereo_dft_dequantize_itd( int16_t *ind, @@ -1891,14 +1506,6 @@ void stereo_dft_enc_sid_coh( float *cohBand /* i/o: Coherence per band */ ); #endif -#ifdef IVAS_FLOAT_FIXED -void stereo_dft_dec_sid_coh_fx( - Decoder_State *st, /* i/o: decoder state structure */ - const Word16 nbands, /* i : number of DFT stereo bands Q0*/ - Word16 *coh, /* i/o: coherence Q15*/ - Word16 *nb_bits /* i/o: number of bits read Q0*/ -); -#endif // IVAS_FLOAT_FIXED void stereo_dft_dec_sid_coh( Decoder_State *st, /* i/o: decoder state structure */ @@ -2009,11 +1616,6 @@ float stereo_dft_dmx_swb_nrg( const int16_t frame_length /* i : frame lanegth */ ); -#ifdef IVAS_FLOAT_FIXED -Word16 stereo_dft_sg_recovery_fx( - STEREO_DFT_DEC_DATA_HANDLE hStereoDft /* i/o: Decoder DFT stereo handle */ -); -#endif int16_t stereo_dft_sg_recovery( STEREO_DFT_DEC_DATA_HANDLE hStereoDft /* i/o: Decoder DFT stereo handle */ ); @@ -2031,33 +1633,12 @@ int16_t res_bpf_adapt( const float *bpf_error_signal_8k, /* i : BPF modification signal */ float res_buf[STEREO_DFT_N_8k] /* i : residual buffer */ ); -#else // IVAS_FLOAT_FIXED -Word16 res_bpf_adapt_ivas_fx( - STEREO_DFT_DEC_DATA_HANDLE hStereoDft, /* i/o: DFT stereo decoder handle */ - const Word32 *bpf_error_signal_8k, /* i : BPF modification signal */ - Word32 res_buf[STEREO_DFT_N_8k], /* i : residual buffer Q_res */ - Word16 q_res -); #endif + void bpf_pitch_coherence( Decoder_State *st, /* i/o: decoder state structure */ const float pitch_buf[] /* i : pitch for each subframe [0,1,2,3] */ ); -#ifdef IVAS_FLOAT_FIXED -void stereo_dft_dec_read_BS_fx( - const Word32 ivas_total_brate, /* i : IVAS total bitrate Q0*/ - const Word32 element_brate, /* i : element bitrate Q0*/ - Word32 *total_brate, /* o : total bitrate Q0*/ - Decoder_State *st, /* i/o: decoder state structure */ - STEREO_DFT_DEC_DATA_HANDLE hStereoDft, /* i/o: decoder stereo handle */ - const Word16 bwidth, /* i : bandwidth Q0*/ - const Word16 output_frame, /* i : output frame length Q0*/ - Word32 res_buf_fx[STEREO_DFT_N_8k], /* o : residual buffer Q0*/ - Word16 *nb_bits, /* o : number of bits read Q0*/ - Word16 *coh_fx, /* i/o: Coherence Q15*/ - const Word16 ivas_format /* i : ivas format Q0*/ -); -#endif // IVAS_FLOAT_FIXED void stereo_dft_dec_read_BS( const int32_t ivas_total_brate, /* i : IVAS total bitrate */ @@ -2117,16 +1698,7 @@ void filter_with_allpass( ); /*! r: used GR order */ -#ifdef IVAS_FLOAT_FIXED -Word16 write_bitstream_adapt_GR( - BSTR_ENC_HANDLE hBstr, /* i/o: Encoder bitstream handle */ - const Word16 ind, /* i : bitstream index */ - const Word16 *in, /* i : values to be written in bitstream */ - const Word16 len, /* i : values vector length */ - const Word16 GR_ord, /* i : GR order to be used */ - const Word16 no_GR_ord /* i : speech/music 0/1 */ -); -#else +#ifndef IVAS_FLOAT_FIXED int16_t write_bitstream_adapt_GR( BSTR_ENC_HANDLE hBstr, /* i/o: Encoder bitstream handle */ const int16_t Indice, /* i : identifier for bitstream index */ @@ -2138,24 +1710,7 @@ int16_t write_bitstream_adapt_GR( #endif /*! r: used GR order */ -#ifdef IVAS_FLOAT_FIXED -Word16 adapt_GR_ief_fx( - const Word16 *in, /* i : vector to encode */ - Word16 *in_diff, /* o : encoded symbols in case of differential encoding */ - const Word16 *prev, /* i : previous frame data */ - const Word16 len, /* i : input vector length */ - const Word16 no_symb, /* i : number of symbols */ - Word16 *nbits, /* o : number of used bits */ - Word16 *in_enc, /* o : symbold actually encoded after adapt_GR */ - const Word16 *map0, /* i : mapping array */ - const Word16 no_GR_ord, /* i : number of GR order to try 2: 0,1; 3:0,1,2 */ - Word16 *nbits_diff, /* o : number bits in diff encoding */ - const Word16 side_gain_counter, /* i : number of frames since last abs coding */ - Word16 *side_gain_bitdiff_lp, /* i/o: LP-filtered bit difference between abs/diff */ - Word16 *q_side_gain_bitdiff_lp, /* i/o: Q of LP-filtered bit difference between abs/diff */ - const Word16 try_diff /* i : diff coding allowed 1/0 */ -); -#else +#ifndef IVAS_FLOAT_FIXED int16_t adapt_GR_ief( const int16_t *in, /* i : vector to encode */ int16_t *in_diff, /* o : encoded symbols in case of differential encoding */ @@ -2173,21 +1728,7 @@ int16_t adapt_GR_ief( ); #endif -#ifdef IVAS_FLOAT_FIXED -Word16 adapt_GR_rpg1_ief( - const Word16 *in, /* i : res pred gains input vector */ - Word16 *in_diff, /* o : encoded symbols in case of differential encoding */ - const Word16 *prev, /* i : previous frame data */ - const Word16 len, /* i : input vector length */ - const Word16 no_symb, /* i : number of symbols */ - Word16 *nbits, /* o : number of used bits */ - Word16 *in_enc, /* o : symbold actually encoded after adapt_GR */ - const Word16 *maps, /* i : mapping array */ - Word16 *nbits_diff, /* o : estimated no of bits for differential encoding */ - const Word16 no_GR_ord, /* i : number of GR order to try 2: 0,1; 3:0,1,2 */ - const Word16 try_diff /* i : diff coding allowed 1/0 */ -); -#else +#ifndef IVAS_FLOAT_FIXED /*! r: used GR order */ int16_t adapt_GR_rpg1_ief( const int16_t *in, /* i : res pred gains input vector */ @@ -2205,14 +1746,7 @@ int16_t adapt_GR_rpg1_ief( #endif /*! r: number of bits written */ -#ifdef IVAS_FLOAT_FIXED -Word16 write_GR1( - BSTR_ENC_HANDLE hBstr, /* i/o: Encoder bitstream handle */ - const Word16 ind, /* i : bitstream index */ - const Word16 *in, /* i : data to be encoded */ - const Word16 len /* i : input data length */ -); -#else +#ifndef IVAS_FLOAT_FIXED int16_t write_GR1( BSTR_ENC_HANDLE hBstr, /* i/o: Encoder bitstream handle */ const int16_t ind, /* i : bitstream index */ @@ -2222,15 +1756,7 @@ int16_t write_GR1( #endif /*! r: number of bits written */ -#ifdef IVAS_FLOAT_FIXED -Word16 write_bitstream_GR( - BSTR_ENC_HANDLE hBstr, /* i/o: Encoder bitstream handle */ - const Word16 ind, /* i : bitstream index */ - const Word16 *in, /* i : input vector */ - const Word16 len, /* i : input vector length */ - const Word16 GR_ord /* i : GR order */ -); -#else +#ifndef IVAS_FLOAT_FIXED int16_t write_bitstream_GR( BSTR_ENC_HANDLE hBstr, /* i/o: Encoder bitstream handle */ const int16_t ind, /* i : bitstream index */ @@ -2289,12 +1815,6 @@ int16_t read_BS_adapt_GR_sg( ); #endif -void stereo_dft_hybrid_ITD_flag( - STEREO_DFT_CONFIG_DATA_HANDLE hConfig, /* o : DFT stereo configuration */ - const Word32 input_Fs, /* i : CPE element sampling rate */ - const Word16 hybrid_itd_max /* i : flag for hybrid ITD for very large ITDs */ -); - void stereo_dft_enc_compute_itd( CPE_ENC_HANDLE hCPE, /* i/o: CPE encoder structure */ float *DFT_L, @@ -2396,11 +1916,6 @@ void rc_uni_dec_init( uint16_t *bit_buffer, /* i : Bit buffer */ const int16_t max_available_bits /* i : Total maximum bits available */ ); -void rc_uni_dec_init_fx( - RangeUniDecState *rc_st_dec, /* i/o: RC state handle */ - UWord16 *bit_buffer, /* i : Bit buffer */ - const Word16 max_available_bits /* i : Total maximum bits available */ -); /*! r: Read symbol */ uint16_t rc_uni_dec_read_symbol_fastS( @@ -2410,14 +1925,6 @@ uint16_t rc_uni_dec_read_symbol_fastS( const uint16_t alphabet_size, /* i : Number of symbols in the alphabet */ const uint16_t tot_shift /* i : Total frequency as a power of 2 */ ); -/*! r: Read symbol */ -UWord16 rc_uni_dec_read_symbol_fastS_fx( - RangeUniDecState *rc_st_dec, /* i/o: Decoder State */ - const UWord16 cum_freq_table[], /* i : Cumulative frequency up to symbol */ - const UWord16 sym_freq_table[], /* i : Symbol frequency */ - const UWord16 alphabet_size, /* i : Number of symbols in the alphabet */ - const UWord16 tot_shift /* i : Total frequency as a power of 2 */ -); /*! r: Read bit */ uint16_t rc_uni_dec_read_bit( @@ -2442,9 +1949,6 @@ int16_t rc_uni_dec_virtual_finish( RangeUniDecState *rc_st_dec /* i/o: RC state handle */ ); -Word16 rc_uni_dec_virtual_finish_fx( - RangeUniDecState *rc_st_dec /* i/o: RC state handle */ -); /*! r: Total number of bits consumed */ int16_t rc_uni_dec_finish( RangeUniDecState *rc_st_dec /* i/o: RC state handle */ @@ -2519,11 +2023,6 @@ void stereo_tca_init_enc( const int32_t input_Fs /* i : input sampling frequency */ ); -void stereo_tca_init_enc_fx( - STEREO_TCA_ENC_HANDLE hStereoTCA, /* i/o: Stereo ICA handle */ - const Word32 input_Fs /* i : input sampling frequency */ -); - void stereo_tca_enc( CPE_ENC_HANDLE hCPE, /* i : CPE encoder structure */ const int16_t input_frame /* i : length of a frame per channel */ @@ -2539,24 +2038,12 @@ void stereo_tca_dec( const int16_t output_frame /* i : length of a frame per channel */ ); -void stereo_tca_dec_fx( - CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ - Word32 *synth[CPE_CHANNELS], /* i/o: output synth qsynth*/ - const Word16 output_frame /* i : length of a frame per channel Q0*/ -); - void stereo_tca_scale_R_channel( CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ float *output, /* i/o: output synthesis, R channel */ const int16_t output_frame /* i : frame length */ ); -void stereo_tca_scale_R_channel_fx( - CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ - Word32 *output_fx, /* i/o: output synthesis, R channel q_out*/ - const Word16 output_frame /* i : frame length Q0*/ -); - void adjustTargetSignal( float *target, const int16_t prevShift, @@ -2565,12 +2052,6 @@ void adjustTargetSignal( const int16_t method ); -void adjustTargetSignal_fx( - Word32 *target_fx, - const Word16 prevShift, - const Word16 currShift, - const Word16 L_shift_adapt, - const Word16 method); /*----------------------------------------------------------------------------------* * IC-BWE Stereo prototypes *----------------------------------------------------------------------------------*/ @@ -2579,10 +2060,6 @@ void stereo_icBWE_init_enc( STEREO_ICBWE_ENC_HANDLE hStereoICBWE /* i/o: Stereo inter-channel BWE handle */ ); -void stereo_icBWE_init_enc_fx( - STEREO_ICBWE_ENC_HANDLE hStereoICBWE /* i/o: Stereo inter-channel BWE handle */ -); - void spectral_balancer( float *signal, float *mem, @@ -2640,10 +2117,6 @@ int16_t select_stereo_mode( void stereo_classifier_init( STEREO_CLASSIF_HANDLE hStereoClassif /* i/o: stereo classifier structure */ ); -#else -void stereo_classifier_init_fx( - STEREO_CLASSIF_HANDLE hStereoClassif /* i/o: stereo classifier structure */ -); #endif void stereo_classifier_features( @@ -2661,11 +2134,7 @@ void stereo_classifier_features( const int16_t clas /* i : signal class */ ); -#ifdef IVAS_FLOAT_FIXED -void unclr_classifier_dft_fx( - CPE_ENC_HANDLE hCPE /* i/o: CPE encoder structure */ -); -#else +#ifndef IVAS_FLOAT_FIXED void unclr_classifier_dft( CPE_ENC_HANDLE hCPE /* i/o: CPE encoder structure */ ); @@ -2675,13 +2144,7 @@ void unclr_classifier_td( CPE_ENC_HANDLE hCPE /* i/o: CPE encoder structure */ ); #endif -#ifdef IVAS_FLOAT_FIXED -void xtalk_classifier_dft_fx( - CPE_ENC_HANDLE hCPE, /* i/o: CPE encoder structure */ - const Word16 itd, /* i : ITD from DFT stereo - used as a feature */ - const Word32 gcc_phat[] /* i : GPHAT cross-channel correlation function Q31*/ -); -#endif + void xtalk_classifier_dft( CPE_ENC_HANDLE hCPE, /* i/o: CPE encoder structure */ const int16_t itd, /* i : ITD from DFT stereo - used as a feature */ @@ -2702,35 +2165,19 @@ void stereo_td_init_enc( const int16_t last_element_mode /* i : last element mode */ ); -void stereo_td_init_enc_fx( - STEREO_TD_ENC_DATA_HANDLE hStereoTD, /* i/o: TD stereo encoder handle */ - const Word16 last_element_mode /* i : last element mode */ -); #ifndef IVAS_FLOAT_FIXED ivas_error stereo_set_tdm( CPE_ENC_HANDLE hCPE, /* i : CPE encoder structure */ const int16_t input_frame /* i : input frame length per channel */ ); -#else -ivas_error stereo_set_tdm_fx( - CPE_ENC_HANDLE hCPE, /* i : CPE encoder structure */ - const Word16 input_frame, /* i : input frame length per channel */ - Word16 input_q -); #endif + #ifndef IVAS_FLOAT_FIXED void stereo_tdm_prep_dwnmx ( CPE_ENC_HANDLE hCPE, /* i : CPE encoder structure */ const float *input1, /* i : right channel input */ const int16_t input_frame /* i : frame lenght */ ); -#else -void stereo_tdm_prep_dwnmx_fx( - CPE_ENC_HANDLE hCPE, /* i : CPE encoder structure */ - const Word32 *input1, /* i : right channel input */ - const Word16 input_frame, /* i : frame lenght */ - const Word16 input_q /* i : frame lenght */ -); #endif #ifndef IVAS_FLOAT_FIXED @@ -2757,11 +2204,6 @@ void stereo_td_init_dec( const int16_t last_element_mode /* i : last element mode */ ); -void stereo_td_init_dec_fx( - STEREO_TD_DEC_DATA_HANDLE hStereoTD, /* i/o: TD stereo decoder handle */ - const Word16 last_element_mode /* i : last element mode Q0*/ -); - void tdm_configure_dec( const int16_t ivas_format, /* i : IVAS format */ const int16_t ism_mode, /* i : ISM mode in combined format */ @@ -2782,18 +2224,6 @@ void tdm_upmix_plain( const int16_t plus_minus_flag /* i : plus/minus flag */ ); -void tdm_upmix_plain_fx( - Word32 Left_fx[], /* o : left channel Qx*/ - Word32 Right_fx[], /* o : right channel Qx*/ - const Word32 PCh_2_L_fx[], /* i : primary channel Qx*/ - const Word32 SCh_2_R_fx[], /* i : secondary channel Qx*/ - const Word32 LR_ratio_fx, /* i : mixing ratio Q31*/ - const Word32 inv_den_LR_ratio_fx, /* i : inverse mixing ration Q31*/ - const Word16 start_index, /* i : start index Q0*/ - const Word16 end_index, /* i : end index Q0*/ - const Word16 plus_minus_flag /* i : plus/minus flag Q0*/ -); - void stereo_tdm_combine( CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ float *PCh_2_L, /* i/o: Primary channel -> output as L channel */ @@ -2803,29 +2233,7 @@ void stereo_tdm_combine( const int16_t tdm_ratio_idx /* i : TDM ratio index */ ); -void stereo_tdm_combine_fx( - CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ - Word32 *PCh_2_L_fx, /* i/o: Primary channel -> output as left channel Qx*/ - Word32 *SCh_2_R_fx, /* i/o: Secondary channel -> output as right channel Qx*/ - const Word16 output_frame, /* i : Number of samples Q0*/ - const Word16 flag_HB, /* i : flag to distinguish between core (0) and HB (1) synthesis Q0*/ - const Word16 tdm_ratio_idx /* i : TDM ratio index Q0*/ -); -#ifdef IVAS_FLOAT_FIXED -Word16 tdm_lp_comparison_fx( - STEREO_TD_ENC_DATA_HANDLE hStereoTD, /* i/o: TD stereo encoder handle */ - STEREO_CLASSIF_HANDLE hStereoClassif, /* i/o: stereo classifier structure */ - Encoder_State *st, /* i/o: Encoder structure */ - Word32 *speech_buff, /* i : Current speech frame Q_speech */ - const Word16 *A_PCh_fx, /* i : primary channel LP coefficients Q12*/ - const Word16 *A_SCh_fx, /* i : secondary channel LP coeff. Q12*/ - const Word16 m, /* i : filter length */ - const Word32 *isp_PCh_fx, /* i : primary channel LSPs Q31 */ - const Word32 *isp_SCh_fx, /* i : secondary channel LSPs Q31 */ - const Word16 L_frame, /* i : frame length */ - const Word32 element_brate_wo_meta, /* i : element bitrate without metadata*/ - Word16 Q_speech ); -#else +#ifndef IVAS_FLOAT_FIXED /*! r: replication decision; 1 = Use old LP */ int16_t tdm_lp_comparison( STEREO_TD_ENC_DATA_HANDLE hStereoTD, /* i/o: TD stereo encoder handle */ @@ -2860,13 +2268,7 @@ void tdm_configure_enc( const int16_t nb_bits_metadata /* i : number of metadata bits */ ); -#ifdef IVAS_FLOAT_FIXED -ivas_error signaling_enc_secondary_fx( - Encoder_State *st, /* i/o: Encoder structure */ - const Word16 tdm_SM_or_LRTD_Pri, /* i : channel combination scheme flag OR LRTD primary channel */ - const Word16 tdm_Pitch_reuse_flag /* i : primary channel pitch reuse flag*/ -); -#else +#ifndef IVAS_FLOAT_FIXED ivas_error signaling_enc_secondary( Encoder_State *st, /* i/o: Encoder structure */ const int16_t tdm_SM_flag, /* i : channel combination scheme flag */ @@ -2932,21 +2334,6 @@ void tdm_low_rate_enc( const float *lsf_new, /* i : current frame ISF vector */ float *tmp_noise /* o : long-term noise energy */ ); -#else -void tdm_low_rate_enc( - Encoder_State *st, /* i/o: State structure */ - const Word16 Aq[], /* i : 12k8 Lp coefficient */ - const Word16 *res, /* i : residual signal */ // Q_new - Word16 *synth, /* i/o: core synthesis */ // Q_new - Word16 *exc_fx, /* i/o: current non-enhanced excitation */ // Q_new - Word16 *pitch_buf, /* i/o: floating pitch values for each subframe */ // Q6 - Word16 *voice_factors, /* o : voicing factors */ // Q15 - Word16 *bwe_exc_fx, /* o : excitation for SWB TBE */ // Q_new - const Word16 attack_flag, /* i : attck flag */ - const Word16 *lsf_new, /* i : current frame ISF vector */ // x2.56 - Word16 *tmp_noise, /* o : long-term noise energy */ // Q8 - Word16 *Q_new -); #endif /*! r: value of the indice */ @@ -2957,19 +2344,6 @@ uint16_t get_indice_st( const int16_t nb_bits /* i : number of bits to quantize the indice */ ); -#ifdef IVAS_FLOAT_FIXED -void tdm_low_rate_dec_fx( - Decoder_State *st, /* i/o: decoder static memory */ - Word16 dct_epit[], /* o : GSC excitation in DCT domain Q_exc*/ - Word16 *pitch_buf, /* o : Word16 pitch values for each subframe Q6*/ - Word16 *voice_factors, /* o : voicing factors Q15*/ - Word16 *exc, /* i/o: adapt. excitation exc Q_exc*/ - Word16 *exc2, /* i/o: adapt. excitation/total exc Q_exc*/ - Word16 *bwe_exc, /* o : excitation for SWB TBE Q_exc*/ - const Word16 *lsf_new /* i : ISFs at the end of the frame Q8/100 (2.56x)*/ -); -#endif - void tdm_low_rate_dec( Decoder_State *st, /* i/o: decoder static memory */ float dct_epit[], /* o : GSC excitation in DCT domain */ @@ -2981,30 +2355,14 @@ void tdm_low_rate_dec( float *bwe_exc, /* o : excitation for SWB TBE */ const float *lsf_new /* i : ISFs at the end of the frame */ ); -#ifdef IVAS_FLOAT_FIXED -void tdm_SCh_LSF_intra_pred_fx( - const Word32 element_brate, /* i : element bitrate */ - const Word16 *tdm_lsfQ_PCh_fx, /* i : primary channel LSFs */ - Word16 *pred_lsf_SCh_fx /* o : predicted secondary channel LSFs */ -); -#endif + void tdm_SCh_LSF_intra_pred( const int32_t element_brate, /* i : element bitrate */ const float *tdm_lsfQ_PCh, /* i : primary channel LSFs */ float *pred_lsf_SCh /* o : predicted secondary channel LSFs */ ); -#ifdef IVAS_FLOAT_FIXED -void tdm_SCh_lsf_reuse_fx( - const Word16 enc_dec, /* i : encoder/decoder flag */ - const Word32 element_brate, /* i : element bitrate */ - Word16 lsf_new_fx[M], /* i/o: LSFs at the end of the frame */ - Word16 lsp_new_fx[M], /* i/o: LSPs at the end of the frame */ - const Word16 tdm_lsfQ_PCh_fx[M], /* i : primary channel LSFs */ - const Word16 lsf_wgts_fx[M], /* i : LSF weights */ - Word16 *beta_index /* i/o: quantization index */ -); -#else +#ifndef IVAS_FLOAT_FIXED void tdm_SCh_lsf_reuse( const int16_t enc_dec, /* i : encoder/decoder flag */ const int32_t element_brate, /* i : element bitrate */ @@ -3076,21 +2434,7 @@ void QuantizeTCXSpectrum( float *gain_tcx, /* o : global gain */ int16_t prm[] /* o : tcx parameters */ ); -#ifdef IVAS_FLOAT_FIXED -void EstimateStereoTCXNoiseLevel_fx( - Encoder_State **sts, /* i : state handle */ - Word32 *q_spectrum[CPE_CHANNELS][NB_DIV], /* i : quantized MDCT spectrum */ - Word16 gain_tcx[][NB_DIV], /* i : global gain */ - Word16 gain_tcx_e, /* i : global gain exponent */ - Word16 L_frame[][NB_DIV], /* i : frame length */ - Word16 noiseFillingBorder[][NB_DIV], /* i : noise filling border */ - Word16 hm_active[][NB_DIV], /* i : flag indicating if the harmonic model is active */ - const Word16 ignore_chan[], /* i : flag indicating whether the channel should be ignored */ - Word16 fac_ns[][NB_DIV], /* o : noise filling level */ - Word16 param_core[][NB_DIV * NPRM_DIV], /* o : quantized noise filling level */ - const Word16 MCT_flag /* i : hMCT handle allocated (1) or not (0) */ -); -#endif + void EstimateStereoTCXNoiseLevel( Encoder_State **sts, /* i : state handle */ float *q_spectrum[CPE_CHANNELS][NB_DIV], /* i : quantized MDCT spectrum */ @@ -3113,17 +2457,7 @@ void TNSAnalysisStereo( int16_t param_core[][NB_DIV * NPRM_DIV], /* o : quantized noise filling level */ const int16_t mct_on /* i : flag mct block (1) or stereo (0) */ ); -#ifdef IVAS_FLOAT_FIXED -void TNSAnalysisStereo_fx( - Encoder_State **sts, /* i : encoder state handle */ - Word32 *mdst_spectrum_fx[CPE_CHANNELS][NB_DIV], /* o : MDST spectrum Qx*/ - const Word16 bWhitenedDomain, /* i : whitened domain flag Q0*/ - Word16 tnsSize[CPE_CHANNELS][NB_DIV], /* i : number of tns parameters put into prm Q0*/ - Word16 tnsBits[CPE_CHANNELS][NB_DIV], /* i : number of tns bits in the frame Q0*/ - Word16 param_core[][NB_DIV * NPRM_DIV], /* o : TNS parameters Q0*/ - const Word16 mct_on /* i : flag mct block (1) or stereo (0) Q0*/ -); -#endif + void InternalTCXDecoder( Encoder_State *st, /* i/o: state handle */ const int16_t frame_cnt, /* i : frame counter in the super_frame */ @@ -3164,17 +2498,6 @@ void initMdctStereoEncData( const int16_t mem_init /* i : initialize memory after malloc */ ); -void initMdctStereoEncData_fx( - STEREO_MDCT_ENC_DATA *hStereoMdct, /* i/o: mdct stereo parameters structure */ - const IVAS_FORMAT ivas_format, /* i : IVAS format */ - const Word16 element_mode, /* i : element mode */ - const Word32 element_brate, /* i : element bitrate */ - const Word16 bwidth, /* i : bandwidth */ - const Word16 igf, /* i : flag indicating IGF activity */ - const H_IGF_GRID hIgfGrid, /* i : IGF grid setup */ - const Word16 mem_init /* i : initialize memory after malloc */ -); - ivas_error initMdctItdHandling( STEREO_MDCT_ENC_DATA *hStereoMdct, /* i/o: mdct stereo parameters structure */ const int32_t input_Fs /* i : input sampling rate */ @@ -3209,15 +2532,6 @@ void stereo_mdct_init_igf_start_band( const int32_t element_brate /* i : element bitrate */ ); -#ifdef IVAS_FLOAT_FIXED -void init_tcx_enc_info_fx( - Encoder_State *st, /* i/o: coder memory state */ - Word16 *L_frame, - Word16 *L_frameTCX, - Word16 *L_spec -); -#endif - void init_tcx_enc_info( Encoder_State *st, /* i : coder memory state */ int16_t *L_frame, @@ -3409,12 +2723,6 @@ void SetCurrentPsychParams( const int16_t last_frame_was_concealed_cng, TCX_CONFIG_HANDLE hTcxCfg ); -#else -void SetCurrentPsychParams( - const Word16 core, - const Word16 last_frame_was_concealed_cng, - TCX_CONFIG_HANDLE hTcxCfg -); #endif void stereo_coder_tcx( @@ -3543,32 +2851,7 @@ void dequantize_sns( float snsQ_out[CPE_CHANNELS][NB_DIV][M], Decoder_State **sts ); -#ifdef IVAS_FLOAT_FIXED -void sns_avq_cod_fx( - const Word32 *sns_fx, /* i : Input sns vectors */ - Word16 exp_sns, - const Word32 *snsmid_fx, /* i : Input mid-sns vectors */ - Word16 exp_snsmid, - Word32 *sns_q_fx, /* o : Quantized LFS vectors Q16 */ - Word32 *snsmid_q_fx, /* o : Quantized mid-LFS vectors Q16 */ - Word16 *index, /* o : Quantization indices */ - const Word16 core, /* i : core */ - const Word16 L_frame, - const Word16 low_brate_mode /* i : flag low bit operating mode */ -); - -void sns_avq_cod_stereo_fx( - const Word32 *snsl_fx, /* i : Input sns vector (left channel) */ - Word16 exp_snl, - const Word32 *snsr_fx, /* i : Input sns vector (right channel) */ - Word16 exp_snr, - const Word16 L_frame, - Word32 *snsl_q_fx, /* o : Quantized sns vector (left channel) Q16 */ - Word32 *snsr_q_fx, /* o : Quantized sns vector (right channel) Q16 */ - Word16 *indexl, /* o : Quantization indices (left channel) */ - Word16 *indexr /* o : Quantization indices (right channel) */ -); -#else +#ifndef IVAS_FLOAT_FIXED void sns_avq_cod( const float *sns, /* i : Input sns vectors */ const float *snsmid, /* i : Input mid-sns vectors */ @@ -3632,11 +2915,6 @@ void FdCngEncodeMDCTStereoSID( void FdCngDecodeMDCTStereoSID( CPE_DEC_HANDLE hCPE /* i/o: CPE decoder state structure */ ); -#ifdef IVAS_FLOAT_FIXED -ivas_error initMdctStereoDtxData_fx( - CPE_DEC_HANDLE hCPE /* i/o: CPE handle */ -); -#endif // IVAS_FLOAT_FIXED ivas_error initMdctStereoDtxData( CPE_DEC_HANDLE hCPE /* i/o: CPE decoder handle */ @@ -3660,13 +2938,6 @@ void applyDmxMdctStereo( const int16_t output_frame /* i : output frame length */ ); -void applyDmxMdctStereo_fx( - const CPE_DEC_HANDLE hCPE, /* i : CPE handle */ - Word32 *output_fx[CPE_CHANNELS], /* o : output from core decoder q_out*/ - const Word16 output_frame /* i : output frame length Q0*/ -); - - /*----------------------------------------------------------------------------------* * Front-VAD prototypes *----------------------------------------------------------------------------------*/ @@ -3676,19 +2947,9 @@ ivas_error front_vad_create( const ENCODER_CONFIG_HANDLE hEncoderConfig /* i : configuration structure */ ); -ivas_error front_vad_create_fx( - FRONT_VAD_ENC_HANDLE *hFrontVad, /* i/o: front-VAD handle */ - const ENCODER_CONFIG_HANDLE hEncoderConfig /* i : configuration structure */ -); - void front_vad_destroy( FRONT_VAD_ENC_HANDLE *hFrontVad /* i/o: front-VAD handle */ ); -#ifdef IVAS_FLOAT_FIXED -void front_vad_destroy_fx( - FRONT_VAD_ENC_HANDLE *hFrontVad /* i/o: front-VAD handle */ -); -#endif ivas_error front_vad( CPE_ENC_HANDLE hCPE, /* i/o: CPE encoder structure, nullable */ @@ -3707,28 +2968,7 @@ ivas_error front_vad( float *PS_out, /* o : energy spectrum */ float *Bin_E_out /* o : log-energy spectrum of the current frame*/ ); -#ifdef IVAS_FLOAT_FIXED -ivas_error front_vad_fx( - CPE_ENC_HANDLE hCPE, /* i/o: CPE encoder structure, nullable */ - Encoder_State * st, /* i/o: encoder state structure */ - const ENCODER_CONFIG_HANDLE hEncoderConfig, /* i : configuration structure */ - FRONT_VAD_ENC_HANDLE *hFrontVads, /* i/o: FrontVad handles */ - const Word16 MCT_flag, /* i : hMCT handle allocated (1) or not (0) */ - const Word16 input_frame, /* i : frame length */ - Word16 vad_flag_dtx[], /* o : HE-SAD flag with additional DTX HO */ - Word32 fr_bands_fx[][2 * NB_BANDS], /* o : energy in frequency bands Q_buffer[n] + QSCALE + 2 */ - Word16 Etot_LR_fx[], /* o : total energy Left & Right channel Q8 */ - Word32 lf_E_fx[][2 * VOIC_BINS], /* i : per bin spectrum energy in lf, LR channels Q_buffer[n] + QSCALE */ - Word16 localVAD_HE_SAD[], /* o : HE-SAD flag without hangover, LR channels */ - Word16 vad_hover_flag[], /* o : VAD hangover flag */ - Word32 band_energies_LR_fx[2 * NB_BANDS], /* o : energy in critical bands without minimum noise floor E_MIN Q_buffer[1] + QSCALE + 2 - band_ener_guardbits*/ - Word32 *PS_out_fx, /* o : energy spectrum Q_buffer + QSCALE */ - Word16 *Bin_E_out_fx, /* o : log-energy spectrum of the current frame Q7 */ - Word16 Q_inp, - Word16 *Q_buffer, - Word16 Q_add, - Word16 *front_create_flag ); -#endif + ivas_error front_vad_spar( SPAR_ENC_HANDLE hSpar, /* i/o: SPAR encoder structure */ const float *omni_in, /* i : omnidirectional input signal */ @@ -3777,12 +3017,7 @@ void stereo_cna_update_params( const int16_t output_frame, /* i : Output frame length */ const int16_t tdm_ratio_idx /* i : TDM ratio index */ ); -void stereo_cna_update_params_fx( - CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ - Word32 *output_fx[CPE_CHANNELS], /* i : Output signal OUTPUT_Q*/ - const Word16 output_frame, /* i : Output frame length Q0*/ - const Word16 tdm_ratio_idx /* i : TDM ratio index Q0*/ -); + void dtx_enc_init( Encoder_State *st, /* i : Encoder state handle */ const int16_t var_SID_rate_flag, /* i : flag for variable SID update rate */ @@ -3802,23 +3037,6 @@ void mvr2r_inc( const int16_t n /* i : vector size */ ); -#ifdef IVAS_FLOAT_FIXED -void mvr2r_inc_fixed_one( - const Word32 x_fx[], /* i : input vector */ - const Word16 x_inc, /* i : increment for vector x[] */ - Word32 y_fx[], /* o : output vector */ - const Word16 y_inc, /* i : increment for vector y[] */ - const Word16 n /* i : vector size */ -); - -void mvr2r_inc_fixed( - const Word32 x_fx[], /* i : input vector */ - const int16_t x_inc, /* i : increment for vector x[] */ - Word32 y_fx[], /* o : output vector */ - const int16_t y_inc, /* i : increment for vector y[] */ - const int16_t n /* i : vector size */ -); -#endif void v_add_inc( const float x1[], /* i : Input vector 1 */ const int16_t x_inc, /* i : Increment for input vector 1 */ @@ -3829,45 +3047,6 @@ void v_add_inc( const int16_t N /* i : Vector length */ ); -#ifdef IVAS_FLOAT_FIXED -void v_mult_inc_fx( - const Word32 x1_fx[], /* i : Input vector 1 */ - Word16 *x1_q_fx, - const Word16 x1_inc, /* i : Increment for input vector 1 */ - const Word32 x2_fx[], /* i : Input vector 2 */ - Word16 *x2_q_fx, - const Word16 x2_inc, /* i : Increment for input vector 1 */ - Word32 y_fx[], /* o : Output vector that contains vector 1 .* vector 2 */ - Word16 *y_q_fx, - const Word16 y_inc, /* i : increment for vector y[i] */ - const Word16 N /* i : Vector length */ -); - -void v_add_inc_fx( - const Word32 x1[], /* i : Input vector 1 */ - const Word16 x_inc, /* i : Increment for input vector 1 */ - const Word32 x2[], /* i : Input vector 2 */ - const Word16 x2_inc, /* i : Increment for input vector 2 */ - Word32 y[], /* o : Output vector that contains vector 1 + vector 2 */ - const Word16 y_inc, /* i : increment for vector y[] */ - const Word16 N /* i : Vector length */ -); -Word32 logsumexp_fx( - const Word32 x[], /* i : input array x */ - const Word16 x_e, - const Word16 N /* i : number of elements in array x */ -); -Word32 lin_interp32_fx( - const Word32 x, /* i : the value to be mapped */ - const Word32 x1, /* i : source range interval: low end */ - const Word32 y1, /* i : source range interval: high end */ - const Word32 x2, /* i : target range interval: low */ - const Word32 y2, /* i : target range interval: high */ - const Word16 flag_sat, /* i : flag to indicate whether to apply saturation */ - Word16 *Q_io /*i/o : i/o Q factor of the output*/ -); -#endif - void v_mult_inc( const float x1[], /* i : Input vector 1 */ const int16_t x1_inc, /* i : Increment for input vector 1 */ @@ -3878,21 +3057,6 @@ void v_mult_inc( const int16_t N /* i : Vector length */ ); -#ifdef IVAS_FLOAT_FIXED -void v_addc_fx( - const Word32 x_fx[], /* i : Input vector */ - const Word32 c_fx, /* i : Constant */ - Word32 y_fx[], /* o : Output vector that contains c*x */ - const Word16 N /* i : Vector length */ -); -#endif - -void v_addc_fixed( - const Word32 x[], /* i : Input vector */ - const Word32 c, /* i : Constant */ - Word32 y[], /* o : Output vector that contains c*x */ - const Word16 N /* i : Vector length */ -); void v_addc( const float x[], /* i : Input vector */ const float c, /* i : Constant */ @@ -3900,28 +3064,6 @@ void v_addc( const int16_t N /* i : Vector length */ ); -#ifdef IVAS_FLOAT_FIXED -void v_min_fx( - const Word32 x1_fx[], /* i : Input vector 1 */ - Word16 *x1_q_fx, - const Word32 x2_fx[], /* i : Input vector 2 */ - Word16 *x2_q_fx, - Word32 y_fx[], /* o : Output vector that contains vector 1 .* vector 2 */ - Word16 *y_q_fx, - const Word16 N /* i : Vector length */ -); - -void v_mult_inc_fixed( - const Word32 x1_fx[], /* i : Input vector 1 */ - const Word16 x1_inc, /* i : Increment for input vector 1 */ - const Word32 x2_fx[], /* i : Input vector 2 */ - const Word16 x2_inc, /* i : Increment for input vector 1 */ - Word32 y_fx[], /* o : Output vector that contains vector 1 .* vector 2 */ - const Word16 y_inc, /* i : increment for vector y[i] */ - const Word16 N /* i : Vector length */ -); -#endif - void v_min( const float x1[], /* i : Input vector 1 */ const float x2[], /* i : Input vector 2 */ @@ -3929,15 +3071,6 @@ void v_min( const int16_t N /* i : Vector length */ ); -#ifdef IVAS_FLOAT_FIXED -void v_sqrt_fx( - const Word32 x[], /* i : Input vector */ - Word16 exp[], - Word32 y[], /* o : Output vector that contains sqrt(x) */ - const Word16 N /* i : Vector length */ -); -#endif - void v_sqrt( const float x[], /* i : Input vector */ float y[], /* o : Output vector that contains sqrt(x) */ @@ -3950,13 +3083,6 @@ float sumAbs( const int16_t lvec /* i : length of input vector */ ); -#ifdef IVAS_FLOAT_FIXED -Word32 sumAbs_fx( - const Word32 *vec, /* i : input vector */ - const Word16 lvec /* i : length of input vector */ -); -#endif - void mvc2c( const uint8_t x[], /* i : input vector */ uint8_t y[], /* o : output vector */ @@ -3970,42 +3096,6 @@ float dot_product_cholesky( const int16_t N /* i : vector & matrix size */ ); -#ifdef IVAS_FLOAT_FIXED -Word32 dot_product_cholesky_fx( - const Word32 *x, /* i : vector x */ - const Word32 *A, /* i : Cholesky matrix A */ - const Word16 N /* i : vector & matrix size */ -); -Word32 dot_product_cholesky_fixed( - const Word32 *x, /* i : vector x */ - const Word32 *A, /* i : Cholesky matrix A */ - const Word16 N, /* i : vector & matrix size */ - const Word16 exp_x, - const Word16 exp_A, - Word16 *exp_sum ); -#endif - -#ifdef IVAS_FLOAT_FIXED -void v_mult_mat_fx( - Word32 *y_fx, /* o : the product x*A */ - Word16 *y_q_fx, - const Word32 *x_fx, /* i : vector x */ - Word16 *x_q_fx, - const Word32 *A_fx, /* i : matrix A */ - Word16 *A_q_fx, - const Word16 N, /* i : number of rows */ - const Word16 C /* i : number of columns */ -); -void v_mult_mat_fixed( - Word32 *y, /* o : the product x*A */ - const Word32 *x, /* i : vector x */ - const Word32 *A, /* i : matrix A */ - const Word16 Nr, /* i : number of rows */ - const Word16 Nc, /* i : number of columns */ - Word16 guardbits -); -#endif - void v_mult_mat( float *y, /* o : the product x*A */ const float *x, /* i : vector x */ @@ -4044,29 +3134,7 @@ int16_t check_bounds_s( const int16_t high /* i : High limit */ ); -#ifdef IVAS_FLOAT_FIXED -Word16 check_bounds_s_fx( - const Word16 value, /* i : Input value */ - const Word16 low, /* i : Low limit */ - const Word16 high /* i : High limit */ -); -#endif - -Word32 check_bounds_l( - const Word32 value, /* i : Input value */ - const Word32 low, /* i : Low limit */ - const Word32 high /* i : High limit */ -); -#ifdef IVAS_FLOAT_FIXED -ivas_error stereo_memory_enc_fx( - CPE_ENC_HANDLE hCPE, /* i : CPE encoder structure */ - const int32_t input_Fs, /* i : input sampling rate */ - const int16_t max_bwidth, /* i : maximum audio bandwidth */ - const IVAS_FORMAT ivas_format, /* i : IVAS format */ - const int16_t nchan_transport /* i : number transport chans */ - -); -#else +#ifndef IVAS_FLOAT_FIXED ivas_error stereo_memory_enc( CPE_ENC_HANDLE hCPE, /* i : CPE encoder structure */ const int32_t input_Fs, /* i : input sampling rate */ @@ -4087,20 +3155,15 @@ ivas_error stereo_memory_dec( const MC_MODE mc_mode, /* i : MC mode */ const int16_t nchan_transport /* i : number of transport channels */ ); -#ifdef IVAS_FLOAT_FIXED +#ifndef IVAS_FLOAT_FIXED void stereo_switching_enc_fx( CPE_ENC_HANDLE hCPE, /* i : CPE encoder structure */ Word16 old_input_signal_pri[], /* i : old input signal of primary channel */ const Word16 input_frame, /* i : input frame length */ const Word16 q_inp ); -#else -void stereo_switching_enc( - CPE_ENC_HANDLE hCPE, /* i : CPE structure */ - float old_input_signal_pri[], /* i : old input signal of primary channel */ - const int16_t input_frame /* i : input frame length */ -); #endif + void stereo_switching_dec( CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ const Word32 ivas_total_brate /* i : IVAS total bitrate Q0*/ @@ -4115,34 +3178,15 @@ void stereo_td2dft_update( const int16_t output_frame /* i : frame length */ ); -void stereo_td2dft_update_fx( - CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ - const Word16 n, /* i : channel number Q0*/ - Word32 output_fx[], /* i/o: synthesis @internal Fs Q11*/ - Word32 synth_fx[], /* i/o: synthesis @output Fs Q11*/ - Word32 hb_synth_fx[], /* i/o: hb synthesis Q11*/ - const Word16 output_frame /* i : frame length Q0*/ -); void stereo_mdct2dft_update( CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ float output0[], /* i/o: synthesis @internal Fs, ch0 */ float synth0[] /* i/o: synthesis @output Fs, ch0 */ ); -void stereo_mdct2dft_update_fx( - CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ - Word32 output0_fx[], /* i/o: synthesis @internal Fs, ch0 Q11*/ - Word32 synth0_fx[] /* i/o: synthesis @output Fs, ch0 Q11*/ -); + /*! r: number of bits written */ -#ifdef IVAS_FLOAT_FIXED -Word16 write_GR0( - BSTR_ENC_HANDLE hBstr, /* i/o: Encoder bitstream handle */ - const Word16 ind, /* i : bitstream index */ - const Word16 *in, /* i : data to be encoded */ - const Word16 len /* i : input data length */ -); -#else +#ifndef IVAS_FLOAT_FIXED int16_t write_GR0( BSTR_ENC_HANDLE hBstr, /* i/o: Encoder bitstream handle */ const int16_t ind, /* i : bitstream index */ @@ -4292,15 +3336,7 @@ void ivas_mdct_core_tns_ns( const int16_t MCT_flag /* i : hMCT handle allocated (1) or not (0) */ ); -#ifdef IVAS_FLOAT_FIXED -void ivas_mct_core_dec( - MCT_DEC_HANDLE hMCT, /* i/o: MCT decoder structure */ - CPE_DEC_HANDLE hCPE[MCT_MAX_BLOCKS], /* i/o: CPE decoder structure */ - const Word16 nCPE, /* i : number of CPEs */ - Word32 *signal_out_fx[], - Word16 q_x[MCT_MAX_CHANNELS] -); -#else +#ifndef IVAS_FLOAT_FIXED void ivas_mct_core_dec( MCT_DEC_HANDLE hMCT, /* i/o: MCT decoder structure */ CPE_DEC_HANDLE hCPE[MCT_MAX_BLOCKS], /* i/o: CPE decoder structure */ @@ -4369,10 +3405,10 @@ void deindex_sph_idx( float *phi /* o : Azimuth */ ); void deindex_sph_idx_fx( - const UWord16 sphIndex, /* i : Spherical index */ - const SPHERICAL_GRID_DATA *gridData, /* i : Prepared spherical grid */ - Word32 *theta_fx, /* o : Elevation */ - Word32 *phi_fx /* o : Azimuth */ + const UWord16 sphIndex, /* i : Spherical index */ + const SPHERICAL_GRID_DATA *gridData, /* i : Prepared spherical grid */ + Word32 *theta_fx, /* o : Elevation Q22*/ + Word32 *phi_fx /* o : Azimuth Q22 */ ); /*! r: output index for direction */ @@ -4429,18 +3465,8 @@ int16_t ivas_qmetadata_dec_sid_decode( int16_t *element_mode, /* o : element mode */ const int16_t ivas_format /* i : IVAS format */ ); -#ifdef IVAS_FLOAT_FIXED -void ivas_qmetadata_to_dirac_fx( - const IVAS_QMETADATA_HANDLE hQMetaData, /* i : frame of MASA q_metadata */ - DIRAC_DEC_HANDLE hDirAC, /* i : DirAC decoder structure */ - MASA_DECODER_HANDLE hMasa, /* i : MASA decoder structure */ - SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom, /* i/o: common spatial renderer data handle */ - const Word32 ivas_total_brate, /* i : IVAS total bitrate */ - const IVAS_FORMAT ivas_format, /* i : IVAS format */ - const Word16 hodirac_flag, /* i : flag to indicate HO-DirAC mode */ - Word16 *dirac_to_spar_md_bands /* o : DirAC->SPAR MD bands */ -); -#else + +#ifndef IVAS_FLOAT_FIXED void ivas_qmetadata_to_dirac( const IVAS_QMETADATA_HANDLE hQMetaData, /* i : frame of MASA q_metadata */ DIRAC_DEC_HANDLE hDirAC, /* i : DirAC decoder structure */ @@ -4452,6 +3478,7 @@ void ivas_qmetadata_to_dirac( int16_t *dirac_to_spar_md_bands /* o : DirAC->SPAR MD bands */ ); #endif + #ifndef IVAS_FLOAT_FIXED ivas_error ivas_qmetadata_open( IVAS_QMETADATA_HANDLE *hQMetaData /* i/o: q_metadata handle */ @@ -4483,13 +3510,6 @@ int16_t masa_sq( const int16_t cb_sz /* i : codebook size */ ); -#ifdef IVAS_FLOAT_FIXED -Word16 masa_sq_fx( - const Word32 in, /* i : input value */ - const Word32 *threshold, /* i : partition */ - const Word16 cb_sz /* i : codebook size */ -); -#endif void ivas_qmetadata_azimuth_elevation_to_direction_vector( const float az, /* i : azimuth */ const float el, /* i : elevation */ @@ -4530,16 +3550,6 @@ uint16_t quantize_direction( const MC_LS_SETUP mc_format /* i : channel format if in MC-mode */ ); -#ifdef IVAS_FLOAT_FIXED -Word16 quantize_direction2D_fx( - Word32 phi, /* i : input azimuth value Q22 */ - const Word16 no_cw, /* i : number of bits */ - Word32 *phi_q, /* o : quantized azimuth value Q22 */ - UWord16 *index_phi, /* o : quantized azimuth index */ - const MC_LS_SETUP mc_format /* i : channel format if in MC-mode */ -); -#endif - int16_t quantize_direction2D( float phi, /* i : input azimuth value */ const int16_t no_cw, /* i : number of bits */ @@ -4556,15 +3566,6 @@ float companding_azimuth( const int16_t direction /* i : direction of companding (direct or inverse)*/ ); -#ifdef IVAS_FLOAT_FIXED -Word32 companding_azimuth_fx( - const Word32 azi_fx, /* i : input azimuth value */ - const MC_LS_SETUP mc_format, /* i : input channel format */ - const Word16 theta_flag, /* i : zero/non zero elevation flag */ - const Word16 direction /* i : direction of companding (direct or inverse)*/ -); -#endif - /*! r: index azimuth */ int16_t quantize_phi_chan_lbr( const float phi, /* i : azimuth value */ @@ -4603,21 +3604,7 @@ int16_t quantize_phi( float *phi_hat, /* o : quantized azimuth */ const int16_t n /* i : azimuth codebook size */ ); -#ifdef IVAS_FLOAT_FIXED -Word16 quantize_phi_fx( - Word32 phi, /* i : azimuth value */ - const Word16 flag_delta, /* i : flag indicating if the azimuth codebook is translated or not */ - Word32 *phi_hat, /* o : quantized azimuth */ - const Word16 n /* i : azimuth codebook size */ -); -Word16 quantize_phi_enc_fx( - Word32 phi, /* i : azimuth value */ - const Word16 flag_delta, /* i : flag indicating if the azimuth codebook is translated or not */ - Word32 *phi_hat, /* o : quantized azimuth */ - const Word16 n /* i : azimuth codebook size */ -); -#endif /*! r: decoded elevation value */ float deindex_elevation( uint16_t *id_th, /* i : input index */ @@ -4625,14 +3612,6 @@ float deindex_elevation( const MC_LS_SETUP mc_format /* i : channel format if in MC-mode */ ); -#ifdef IVAS_FLOAT_FIXED -Word32 deindex_elevation_fx( - UWord16 *id_th, /* i : input index */ - const Word16 no_bits, /* i : number of bits for the spherical grid */ - const MC_LS_SETUP mc_format /* i : channel format if in MC-mode */ -); -#endif - float deindex_azimuth( int16_t id_phi, /* i : index */ const int16_t no_bits, /* i : number of bits for the spherical grid */ @@ -4641,24 +3620,7 @@ float deindex_azimuth( const MC_LS_SETUP mc_format /* i : channel format if in MC-mode */ ); -#ifdef IVAS_FLOAT_FIXED -Word32 deindex_azimuth_fx( - Word16 id_phi, /* i : index */ - const Word16 no_bits, /* i : number of bits for the spherical grid */ - const Word16 id_th, /* i : elevation index */ - const Word16 remap, /* i : remapping flag */ - const MC_LS_SETUP mc_format /* i : channel format if in MC-mode */ -); -void deindex_spherical_component_fx( - const UWord16 sph_idx, /* i : spherical index */ - Word32 *az_fx, /* o : decoded azimuth value */ - Word32 *el_fx, /* o : decoded elevation value */ - UWord16 *az_idx, /* o : azimuth index */ - UWord16 *el_idx, /* o : elevation index */ - const UWord16 no_bits, /* i : number of bits for the spherical grid */ - const MC_LS_SETUP mc_format /* i : channel format if in MC-mode */ -); -#else +#ifndef IVAS_FLOAT_FIXED void deindex_spherical_component( const uint16_t sph_idx, /* i : spherical index */ float *az, /* o : decoded azimuth value */ @@ -4713,23 +3675,7 @@ int16_t ivas_chan_project_elevation_index( ); #endif -#ifdef IVAS_FLOAT_FIXED -void ivas_dirac_param_est_enc( - DIRAC_ENC_HANDLE hDirAC, - IVAS_QDIRECTION *q_direction, - const UWord8 useLowerRes, - Word32 *data_f_fx[], - Word32 **pp_fr_real_fx, - Word32 **pp_fr_imag_fx, - Word16 pp_fr_q, - const Word16 input_frame, - const IVAS_FORMAT ivas_format, - const Word16 hodirac_flag, - const Word16 nchan_fb_in, - Word16 *mono_frame_count, - Word16 *dirac_mono_flag -); -#else +#ifndef IVAS_FLOAT_FIXED void ivas_dirac_param_est_enc( DIRAC_ENC_HANDLE hDirAC, IVAS_QDIRECTION *q_direction, @@ -4783,14 +3729,8 @@ void ivas_init_dec_get_num_cldfb_instances( int16_t *numCldfbSyntheses /* o : number of CLDFB synthesis instances */ ); #endif // !IVAS_FLOAT_FIXED -#ifdef IVAS_FLOAT_FIXED -ivas_error ivas_cldfb_dec_reconfig_fx( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ - const Word16 nchan_transport_old, /* i : number of TCs in previous frame */ - Word16 numCldfbAnalyses_old, /* i : number of CLDFB analysis instances in previous frame */ - const Word16 numCldfbSyntheses_old /* i : number of CLDFB synthesis instances in previous frame */ -); -#else + +#ifndef IVAS_FLOAT_FIXED ivas_error ivas_cldfb_dec_reconfig( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ const int16_t nchan_transport_old, /* i : number of TCs in previous frame */ @@ -4805,20 +3745,6 @@ int16_t ivas_sba_get_order( const int16_t sba_planar /* i : SBA planar flag */ ); -#ifdef IVAS_FLOAT_FIXED -Word16 ivas_sba_get_order_fx( - const Word16 nb_channels, /* i : Number of ambisonic channels */ - const Word16 sba_planar /* i : SBA planar flag */ -); - -#endif - -/*! r: Ambisonic (SBA) order used for analysis and coding */ -Word16 ivas_sba_get_analysis_order( - const Word32 ivas_total_brate, /* i : IVAS total bitrate */ - const Word16 sba_order /* i : Ambisonic (SBA) order */ -); - /*! r: number of Ambisonic channels */ int16_t ivas_sba_get_nchan( const int16_t sba_order, /* i : Ambisonic (SBA) order */ @@ -4826,32 +3752,13 @@ int16_t ivas_sba_get_nchan( ); /*! r: number of ambisonics metadata channels */ -#ifdef IVAS_FLOAT_FIXED -Word16 ivas_sba_get_nchan_metadata( - const Word16 sba_order, /* i : Ambisonic (SBA) order */ - const Word32 ivas_total_brate /* i : IVAS total bitrate */ -); -#else +#ifndef IVAS_FLOAT_FIXED int16_t ivas_sba_get_nchan_metadata( const int16_t sba_order, /* i : Ambisonic (SBA) order */ const int32_t ivas_total_brate /* i : IVAS total bitrate */ ); #endif -void ivas_sba_get_spar_hoa_ch_ind( - const Word16 num_md_chs, /* i : number of MD channels */ - const Word32 ivas_total_brate, /* i : IVAS total bitrate */ - Word16 HOA_md_ind[IVAS_SPAR_MAX_CH] -); - -/*! r: flag indicating to code SPAR HOA MD for all bands */ -void ivas_sba_get_spar_hoa_md_flag( - const Word16 sba_order, /* i : Ambisonic (SBA) order */ - const Word32 ivas_total_brate, /* i : IVAS total bitrate */ - Word16 *spar_hoa_md_flag, - Word16 *spar_hoa_dirac2spar_md_flag -); - void ivas_sba_zero_vert_comp( float *sba_data[], /* i : SBA signals */ const int16_t sba_order, /* i : Ambisonic (SBA) order */ @@ -4865,14 +3772,6 @@ void ivas_sba_getTCs( const int16_t input_frame /* i : frame length */ ); -/*! r: SBA DirAC stereo flag */ -#ifdef IVAS_FLOAT_FIXED -Word16 ivas_sba_remapTCs_fx( - Word32 *sba_data[], /* i/o: SBA signals */ - Decoder_Struct *st_ivas, /* i/o: decoder struct */ - const Word16 output_frame /* i : frame length */ -); -#endif // IVAS_FLOAT_FIXED int16_t ivas_sba_remapTCs( float *sba_data[], /* i/o: SBA signals */ Decoder_Struct *st_ivas, /* i/o: decoder struct */ @@ -4918,27 +3817,13 @@ void ivas_sba2mc_cldfb( const int16_t nb_timeslots, /* i : number of time slots to process */ const float *hoa_dec_mtx /* i : HOA decoding mtx */ ); -#else -void ivas_sba2mc_cldfb_fixed( - IVAS_OUTPUT_SETUP hInSetup, /* i : Format of input layout */ - Word32 RealBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* i/o: cldfb real part (Q_real) */ - Word32 ImagBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* i/o: cldfb imag part (Q_imag) */ - const Word16 nb_channels_out, /* i : nb of output channels */ - const Word16 nb_bands, /* i : nb of CLDFB bands to process */ - const Word16 nb_timeslots, /* i : number of time slots to process */ - const Word32 *hoa_dec_mtx /* i : HOA decoding mtx */ -); #endif /*----------------------------------------------------------------------------------* * DirAC prototypes *----------------------------------------------------------------------------------*/ -#ifdef IVAS_FLOAT_FIXED -ivas_error ivas_dirac_enc_open_fx( - Encoder_Struct *st_ivas /* i/o: IVAS encoder handle */ -); -#else +#ifndef IVAS_FLOAT_FIXED ivas_error ivas_dirac_enc_open( Encoder_Struct *st_ivas /* i/o: IVAS encoder handle */ ); @@ -4948,33 +3833,14 @@ ivas_error ivas_dirac_enc_reconfigure( Encoder_Struct *st_ivas /* i/o: IVAS encoder handle */ ); -#ifdef IVAS_FLOAT_FIXED -void ivas_dirac_enc_close_fx( - DIRAC_ENC_HANDLE *hDirAC, /* i/o: encoder DirAC handle */ - const Word32 input_Fs /* i : input sampling_rate */ -); -#else +#ifndef IVAS_FLOAT_FIXED void ivas_dirac_enc_close( DIRAC_ENC_HANDLE *hDirAC, /* i/o: encoder DirAC handle */ const int32_t input_Fs /* i : input sampling_rate */ ); #endif -#ifdef IVAS_FLOAT_FIXED -ivas_error ivas_dirac_enc_fx( - DIRAC_ENC_HANDLE hDirAC, /* i/o: encoder DirAC handle */ - IVAS_QMETADATA_HANDLE hQMetaData, /* i/o: q_metadata handle */ - BSTR_ENC_HANDLE hMetaData, /* i/o: Metadata bitstream handle */ - Word32 *data_f[], /* i/o: SBA channels */ - Word32 **ppIn_FR_real, /* o : real freq domain values */ - Word32 **ppIn_FR_imag, /* o : imag freq domain values */ - Word16 pp_fr_q, - const int16_t input_frame, /* i : input frame length */ - const int16_t dtx_vad, /* i : DTX vad flag */ - const IVAS_FORMAT ivas_format, /* i : ivas format */ - const int16_t hodirac_flag /* i : hodirac flag */ -); -#else +#ifndef IVAS_FLOAT_FIXED ivas_error ivas_dirac_enc( DIRAC_ENC_HANDLE hDirAC, /* i/o: encoder DirAC handle */ IVAS_QMETADATA_HANDLE hQMetaData, /* i/o: q_metadata handle */ @@ -5004,17 +3870,6 @@ void ivas_dirac_config_bands( IVAS_FB_MIXER_HANDLE hFbMdft ); -#ifdef IVAS_FLOAT_FIXED -void ivas_dirac_config_bands_fx( - Word16 *band_grouping, /* o : band grouping */ - const Word16 nbands, /* i : number of bands */ - const Word16 max_band, /* i : maximal band index +1 */ - Word16 *dirac_to_spar_md_bands, /* o : mapping of DirAC parameter band index to SPAR FB band index */ - const Word8 useLowerBandRes, /* i : flag indicating lower band resolution for DirAC */ - const Word16 enc_param_start_band, /* i : band index of first DirAC parameter band */ - IVAS_FB_MIXER_HANDLE hFbMdft -); -#endif void ivas_get_dirac_sba_max_md_bits( const int32_t sba_total_brate, int16_t *bits_frame_nominal, @@ -5063,23 +3918,8 @@ void generate_masking_noise_lb_dirac( const int16_t cna_flag /* i : CNA flag for LB and HB */ ); #ifdef IVAS_FLOAT_FIXED -void generate_masking_noise_lb_dirac_fx( - HANDLE_FD_CNG_COM hFdCngCom, /* i/o: FD_CNG structure containing all buffers and variables */ - Word32 *tdBuffer, /* i/o: time-domain signal, if NULL no LB-CNA */ - const Word16 nCldfbTs, /* i : number of CLDFB slots that will be rendered */ - const Word16 cna_flag /* i : CNA flag for LB and HB */ -); -#endif -#ifdef IVAS_FLOAT_FIXED -void ivas_dirac_dec_close_fx( - DIRAC_DEC_HANDLE *hDirAC_out -); -void ivas_dirac_dec_set_md_map( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ - const Word16 nCldfbTs /* i : number of CLDFB time slots */ -); -#else +#ifndef IVAS_FLOAT_FIXED void ivas_dirac_dec_set_md_map( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ const int16_t nCldfbTs /* i : number of CLDFB time slots */ @@ -5110,29 +3950,7 @@ void computeDiffuseness_mdft( const uint16_t no_col_avg_diff, float *diffuseness ); -#ifdef IVAS_FLOAT_FIXED -void computeDirectionVectors_fixed( - Word32 *intensity_real_x, - Word32 *intensity_real_y, - Word32 *intensity_real_z, - const Word16 enc_param_start_band, - const Word16 num_frequency_bands, - Word32 *direction_vector_x,/*Q30*/ - Word32 *direction_vector_y,/*Q30*/ - Word32 *direction_vector_z,/*Q30*/ - Word16 i_e /*Exponent of all the intensity buffers*/); -void computeDirectionVectors_fx( - Word32 *intensity_real_x, - Word32 *intensity_real_y, - Word32 *intensity_real_z, - const Word16 enc_param_start_band, - const Word16 num_frequency_bands, - Word32 *direction_vector_x, - Word32 *direction_vector_y, - Word32 *direction_vector_z , - Word16 *q_factor -); -#endif + void computeDirectionVectors( float *intensity_real_x, float *intensity_real_y, @@ -5151,64 +3969,14 @@ void computeDiffuseness( float *diffuseness ); -#ifdef IVAS_FLOAT_FIXED - -void computeDiffuseness_fx( - Word32 *buffer_intensity[DIRAC_NUM_DIMS][DIRAC_NO_COL_AVG_DIFF], - const Word32 *buffer_energy, - const Word16 num_freq_bands, - Word32 *diffuseness , - Word16 q_factor_intensity, - Word16 q_factor_energy, - Word16 *out_exp - -); -#endif -#ifdef IVAS_FLOAT_FIXED -void computeDiffuseness_fixed( - Word32 *buffer_intensity[DIRAC_NUM_DIMS][DIRAC_NO_COL_AVG_DIFF], - const Word32 *buffer_energy, - const Word16 num_freq_bands, - Word32 *diffuseness , - Word16 *q_factor_intensity, - Word16 *q_factor_energy, - Word16 *q_diffuseness -); -#endif void ivas_dirac_dec_get_response( const int16_t azimuth, const int16_t elevation, float *response, const int16_t ambisonics_order ); -#ifdef IVAS_FLOAT_FIXED -void ivas_dirac_dec_get_response_fx( - const Word16 azimuth, - const Word16 elevation, - Word32 * response, - const Word16 ambisonics_order, - Word16 Q_out); -#endif - -#ifdef IVAS_FLOAT_FIXED -void calculate_hodirac_sector_parameters_fx( - DIRAC_ENC_HANDLE hDirAC, /* i : DirAC handle */ - Word32 RealBuffer_fx[DIRAC_MAX_ANA_CHANS][DIRAC_NO_FB_BANDS_MAX], /* i : signal vector (L+1)^2 x N_bins, real part */ - Word32 ImagBuffer_fx[DIRAC_MAX_ANA_CHANS][DIRAC_NO_FB_BANDS_MAX], /* i : signal vector, imaginary part */ - Word16 Qfac, /* i : Q-factor of signal vector */ - const Word32 beta_fx, /* i : forgetting factor for average filtering, Q30 */ - const Word16 *band_grouping, /* i : indices of band groups */ - const Word16 N_bands, /* i : number of bands (groups) */ - const Word16 enc_param_start_band, /* i : first band to process */ - Word32 *azi_fx, /* o : array of sector azimuth angles, flat Q23 */ - Word32 *ele_fx, /* o : array of sector elevation angles, flat Q23 */ - Word32 *diff_fx, /* o : array of sector diffuseness values, flat */ - Word16 *diff_exp, /* o : array of sector diffuseness exponents, flat */ - Word32 *ene_fx, /* o : array of sector energy values, flat */ - Word16 *ene_exp /* o : array of sector energy exponents, flat */ -); -#else +#ifndef IVAS_FLOAT_FIXED void calculate_hodirac_sector_parameters( DIRAC_ENC_HANDLE hDirAC, float RealBuffer[DIRAC_MAX_ANA_CHANS][DIRAC_NO_FB_BANDS_MAX],/* i : signal vector (L+1)^2 x N_bins, real part */ @@ -5224,14 +3992,7 @@ void calculate_hodirac_sector_parameters( ); #endif -#ifdef IVAS_FLOAT_FIXED -void ivas_mc_paramupmix_enc_fx( - Encoder_Struct *st_ivas, /* i/o: IVAS Encoder handle */ - BSTR_ENC_HANDLE hMetaData, /* i/o: IVAS Metadata bitstream handle */ - Word32 *data_fx[], - const int16_t input_frame /* i : input frame length */ -); -#else +#ifndef IVAS_FLOAT_FIXED void ivas_mc_paramupmix_enc( Encoder_Struct *st_ivas, /* i/o: IVAS Encoder handle */ BSTR_ENC_HANDLE hMetaData, /* i/o: IVAS Metadata bitstream handle */ @@ -5269,17 +4030,7 @@ void ivas_mc_paramupmix_dec_digest_tc( const uint8_t nCldfbSlots, /* i : number of CLFBS slots in the transport channels */ const int16_t nSamplesForRendering /* i : number of samples provided */ ); -#ifdef IVAS_FLOAT_FIXED -void ivas_mc_paramupmix_dec_render( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ - const UWord16 nSamplesAsked, /* i : number of CLDFB slots requested */ - UWord16 *nSamplesRendered, /* o : number of CLDFB slots rendered */ - UWord16 *nSamplesAvailable, /* o : number of CLDFB slots still to render */ - Word32 *input_fx[], /* i : core-coder transport channels */ - Word32 *output_fx[] /* i/o: synthesized core-coder transport channels */ -); -#else - +#ifndef IVAS_FLOAT_FIXED void ivas_mc_paramupmix_dec_render( Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ const uint16_t nSamplesAsked, /* i : number of CLDFB slots requested */ @@ -5315,12 +4066,7 @@ void ivas_param_mc_create_full_icc_mapping( ); #endif /*! r: number of IVAS transport channels */ -#ifdef IVAS_FLOAT_FIXED -Word16 ivas_param_mc_getNumTransportChannels( - const Word32 ivas_total_bitrate, /* i : IVAS total bitrate */ - const MC_LS_SETUP mc_ls_setup /* i : MC ls setup */ -); -#else +#ifndef IVAS_FLOAT_FIXED int16_t ivas_param_mc_getNumTransportChannels( const int32_t ivas_total_bitrate, /* i : IVAS total bitrate */ const MC_LS_SETUP mc_ls_setup /* i : MC ls setup */ @@ -5346,30 +4092,16 @@ void ivas_param_mc_enc( float *data_f[], /* i/o: input/transport MC data */ const int16_t input_frame /* i : input frame length */ ); -#ifdef IVAS_FLOAT_FIXED -ivas_error ivas_param_mc_dec_open_fx( - Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ -); -#endif // IVAS_FLOAT_FIXED ivas_error ivas_param_mc_dec_open( Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ ); -#ifdef IVAS_FLOAT_FIXED -ivas_error ivas_param_mc_dec_reconfig_fx( - Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ -); -#endif // IVAS_FLOAT_FIXED - ivas_error ivas_param_mc_dec_reconfig( Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ ); -#ifdef IVAS_FLOAT_FIXED -void ivas_param_mc_dec_close_fx( - PARAM_MC_DEC_HANDLE *hParamMC_out /* i/o: Parametric MC decoder handle */ -); -#else + +#ifndef IVAS_FLOAT_FIXED void ivas_param_mc_dec_close( PARAM_MC_DEC_HANDLE *hParamMC /* i/o: Parametric MC decoder handle */ ); @@ -5390,23 +4122,6 @@ void ivas_param_mc_dec_digest_tc( float *transport_channels_f[] /* i : synthesized core-coder transport channels/DirAC output*/ ); -void ivas_param_mc_dec_digest_tc_fx( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ - const UWord8 nCldfbSlots, /* i : number of CLFBS slots in the transport channels */ - Word32 *transport_channels_f_fx[], - Word16 transport_f_e ); - -#ifdef IVAS_FLOAT_FIXED -void ivas_param_mc_dec_render_fx( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ - const UWord16 nSamplesAsked, /* i : number of CLDFB slots requested */ - UWord16 *nSamplesRendered, /* o : number of CLDFB slots rendered */ - UWord16 *nSamplesAvailable, /* o : number of CLDFB slots still to render */ - Word32 *output_f_fx[], /* o : rendered time signal */ - Word16 channel_active_fx[MAX_OUTPUT_CHANNELS] -); -#endif - void ivas_param_mc_dec_render( Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ const uint16_t nSamplesAsked, /* i : number of CLDFB slots requested */ @@ -5457,79 +4172,7 @@ int16_t matrix_product( float *Z /* o : resulting matrix after the matrix multiplication */ ); -#ifdef IVAS_FLOAT_FIXED -Word16 matrix_product_mant_exp_fx( - const Word32 *X_fx, /* i : left hand matrix */ - const Word16 X_fx_e, /* i : left hand matrix */ - const Word16 rowsX, /* i : number of rows of the left hand matrix */ - const Word16 colsX, /* i : number of columns of the left hand matrix */ - const Word16 transpX, /* i : flag indicating the transposition of the left hand matrix prior to the multiplication */ - const Word32 *Y_fx, /* i : right hand matrix */ - const Word16 Y_fx_e, /* i : right hand matrix */ - const Word16 rowsY, /* i : number of rows of the right hand matrix */ - const Word16 colsY, /* i : number of columns of the right hand matrix */ - const Word16 transpY, /* i : flag indicating the transposition of the right hand matrix prior to the multiplication */ - Word32 *Z_fx, /* o : resulting matrix after the matrix multiplication */ - Word16 *Z_fx_e /* o : resulting matrix after the matrix multiplication */ -); - -Word16 matrix_product_fx( - const Word32 *X_fx, /* i : left hand matrix */ - const Word16 rowsX, /* i : number of rows of the left hand matrix */ - const Word16 colsX, /* i : number of columns of the left hand matrix */ - const Word16 transpX, /* i : flag indicating the transposition of the left hand matrix prior to the multiplication */ - const Word32 *Y_fx, /* i : right hand matrix */ - const Word16 rowsY, /* i : number of rows of the right hand matrix */ - const Word16 colsY, /* i : number of columns of the right hand matrix */ - const Word16 transpY, /* i : flag indicating the transposition of the right hand matrix prior to the multiplication */ - Word32 *Z_fx /* o : resulting matrix after the matrix multiplication */ -); - -Word16 matrix_product_q30_fx( - const Word32 *X_fx, /* i : left hand matrix */ - const Word16 rowsX, /* i : number of rows of the left hand matrix */ - const Word16 colsX, /* i : number of columns of the left hand matrix */ - const Word16 transpX, /* i : flag indicating the transposition of the left hand matrix prior to the multiplication */ - const Word32 *Y_fx, /* i : right hand matrix */ - const Word16 rowsY, /* i : number of rows of the right hand matrix */ - const Word16 colsY, /* i : number of columns of the right hand matrix */ - const Word16 transpY, /* i : flag indicating the transposition of the right hand matrix prior to the multiplication */ - Word32 *Z_fx /* o : resulting matrix after the matrix multiplication */ -); - -Word16 matrix_product_mant_exp( - const Word32 *X_fx, /* i : left hand matrix */ - const Word16 *X_e, /* i : left hand matrix */ - const Word16 rowsX, /* i : number of rows of the left hand matrix */ - const Word16 colsX, /* i : number of columns of the left hand matrix */ - const Word16 transpX, /* i : flag indicating the transposition of the left hand matrix prior to the multiplication */ - const Word32 *Y_fx, /* i : right hand matrix */ - const Word16 *Y_e, /* i : right hand matrix */ - const Word16 rowsY, /* i : number of rows of the right hand matrix */ - const Word16 colsY, /* i : number of columns of the right hand matrix */ - const Word16 transpY, /* i : flag indicating the transposition of the right hand matrix prior to the multiplication */ - Word32 *Z_fx, /* o : resulting matrix after the matrix multiplication */ - Word16 *Z_e /* o : resulting matrix after the matrix multiplication */ -); -#endif - -#ifdef IVAS_FLOAT_FIXED -void mat2svdMat_fx( - const Word32 *mat, /* i : matrix as column ordered vector Qx*/ - Word32 svdMat[MAX_OUTPUT_CHANNELS][MAX_OUTPUT_CHANNELS], /* o : matrix as two-dimensional arry Qx*/ - const Word16 nRows, /* i : number of rows of the matrix Q0*/ - const Word16 mCols, /* i : number of columns of the matrix Q0*/ - const Word16 transpose /* i : flag indication transposition Q0*/ -); - -void svdMat2mat_fx( - Word32 svdMat[MAX_OUTPUT_CHANNELS][MAX_OUTPUT_CHANNELS], /* i : matrix as two-dimensional arry Qx*/ - Word32 *mat, /* o : matrix as column ordered vector Qx*/ - const Word16 nRows, /* i : number of rows of the matrix Q0*/ - const Word16 mCols /* i : number of columns of the matrix Q0*/ -); -#else - +#ifndef IVAS_FLOAT_FIXED void mat2svdMat( const float *mat, /* i : matrix as column ordered vector */ float svdMat[MAX_OUTPUT_CHANNELS][MAX_OUTPUT_CHANNELS], /* o : matrix as two-dimensional arry */ @@ -5600,27 +4243,6 @@ int16_t computeMixingMatrices( float *mixing_matrix, /* o : resulting mixing matrix */ float *Cr /* o : residual covariance matrix */ ); - -#else -Word16 computeMixingMatrices_fx( - const Word16 num_inputs, /* i : number of input channels */ - const Word16 num_outputs, /* i : number of output channels */ - const Word32 *Cx, /* i : input channel covariance matrix */ - Word16 Cx_e, - const Word32 *Cy, /* i : target covariance matrix */ - Word16 Cy_e, - const Word32 *Q, /* i : prototype matrix (usually a upmix matrix) */ - Word16 Q_fx_e, - const Word16 energy_compensation_flag, /* i : flag indicating that the energy compensation should be performed (i.e. no residual mixing matrix will follow) */ - const Word32 reg_Sx_fx, /* i : regularization factor for the input channel singular values */ - Word16 reg_Sx_e, - const Word32 reg_ghat_fx, /* i : regularization factor for the normalization matrix */ - Word16 reg_ghat_e, - Word32 *mixing_matrix_fx, /* o : resulting mixing matrix */ - Word16 *mixing_matrix_out_e, - Word32 *Cr_fx, /* o : residual covariance matrix */ - Word16 *Cr_e -); #endif #ifndef IVAS_FLOAT_FIXED @@ -5632,36 +4254,9 @@ int16_t computeMixingMatricesResidual( const float reg_ghat, /* i : regularization factor for the normalization matrix */ float *mixing_matrix /* o : resulting residual mixing matrix */ ); - -#else -Word16 computeMixingMatricesResidual_fx( - const Word32 num_outputs, /* i : number of output channels */ - const Word32 *Cx_fx, /* i : vector containing the diagonal diffuse prototype covariance */ - const Word16 Cx_e, - const Word32 *Cy_fx, /* i : matrix containing the missing cov (Cr from computeMixingMatrices()) */ - const Word16 Cy_fx_e, - const Word32 reg_Sx_fx, /* i : regularization factor for the input channel singular values */ - const Word16 reg_Sx_e, - const Word32 reg_ghat_fx, /* i : regularization factor for the normalization matrix */ - const Word16 reg_ghat_e, - Word32 *mixing_matrix_fx, /* o : resulting residual mixing matrix */ - Word16 *mixing_matrix_ret_e -); #endif -#ifdef IVAS_FLOAT_FIXED -/*! r: error or success */ -Word16 svd_fx( - Word32 InputMatrix[][MAX_OUTPUT_CHANNELS], /* i : matrix to be decomposed (M) InputMatrix_e*/ - Word16 InputMatrix_e, - Word32 singularVectors_Left_fx[][MAX_OUTPUT_CHANNELS], /* o : left singular vectors (U) Q31*/ - Word32 singularValues_fx[MAX_OUTPUT_CHANNELS], /* o : singular values vector (S) singularValues_fx_e*/ - Word32 singularVectors_Right_fx[][MAX_OUTPUT_CHANNELS], /* o : right singular vectors (V) Q31*/ - Word16 singularValues_fx_e[MAX_OUTPUT_CHANNELS], - const Word16 nChannelsL, /* i : number of rows in the matrix to be decomposed Q0*/ - const Word16 nChannelsC /* i : number of columns in the matrix to be decomposed Q0*/ -); -#else +#ifndef IVAS_FLOAT_FIXED /*! r: error or success */ int16_t svd( float InputMatrix[][MAX_OUTPUT_CHANNELS], /* i : matrix to be decomposed (M) */ @@ -5673,20 +4268,6 @@ int16_t svd( ); #endif -#ifdef IVAS_FLOAT_FIXED -ivas_error ivas_dirac_dec_output_synthesis_cov_open_fx( - DIRAC_OUTPUT_SYNTHESIS_PARAMS *h_dirac_output_synthesis_params, /* i/o: handle for the covariance synthesis parameters */ - DIRAC_OUTPUT_SYNTHESIS_COV_STATE *h_dirac_output_synthesis_state, /* i/o: hanlde for the covariance synthesis state */ - const Word16 max_band_decorr, /* i : uppermost frequency band where decorrelation is applied */ - const Word16 interp_length, /* i : length for interpolating the mixing matrices in time slots */ - const Word16 num_param_bands, /* i : number of parameter bands */ - const Word16 num_param_bands_residual, /* i : number of parameter bands with a residual mixing matrix (i.e. decorrelation */ - const Word16 nchan_in, /* i : number of input (transport) channels */ - const Word16 nchan_out, /* i : number of output channels */ - const Word32 *proto_matrix /* i : the prototype (upmix) matrix (only used if mode == 1) */ -); -#endif // IVAS_FLOAT_FIXED - ivas_error ivas_dirac_dec_output_synthesis_cov_open( DIRAC_OUTPUT_SYNTHESIS_PARAMS *h_dirac_output_synthesis_params, /* i/o: handle for the covariance synthesis parameters */ DIRAC_OUTPUT_SYNTHESIS_COV_STATE *h_dirac_output_synthesis_state, /* i/o: handle for the covariance synthesis state */ @@ -5699,26 +4280,10 @@ ivas_error ivas_dirac_dec_output_synthesis_cov_open( const float *proto_matrix /* i : the prototype (upmix) matrix (only used if mode == 1) */ ); -#ifdef IVAS_FLOAT_FIXED -void ivas_dirac_dec_output_synthesis_get_interpolator_fx( - DIRAC_OUTPUT_SYNTHESIS_PARAMS *h_dirac_output_synthesis_params, /* i/o: handle for the covariance synthesis parameters */ - const UWord16 interp_length /* i : interpolator length */ -); -#endif - void ivas_dirac_dec_output_synthesis_get_interpolator( DIRAC_OUTPUT_SYNTHESIS_PARAMS *h_dirac_output_synthesis_params, /* i/o: handle for the covariance synthesis parameters */ const uint16_t interp_length /* i : interpolator length */ ); -#ifdef IVAS_FLOAT_FIXED -void ivas_dirac_dec_output_synthesis_cov_init_fx( - DIRAC_OUTPUT_SYNTHESIS_COV_STATE *h_dirac_output_synthesis_state, /* i/o: pointer to the state of the covariance synthesis */ - const Word16 nchan_in, /* i : number of input (tranport) channels */ - const Word16 nchan_out, /* i : number of output channels */ - const Word16 n_param_bands, /* i : number of total parameter bands */ - const Word16 n_param_bands_res /* i : number of parameter bands with a residual mixing matrix (i.e. decorrelation */ -); -#endif void ivas_dirac_dec_output_synthesis_cov_init( DIRAC_OUTPUT_SYNTHESIS_COV_STATE *h_dirac_output_synthesis_state, /* i/o: pointer to the state of the covariance synthesis */ @@ -5727,12 +4292,6 @@ void ivas_dirac_dec_output_synthesis_cov_init( const int16_t n_param_bands, /* i : number of total parameter bands */ const int16_t n_param_bands_res /* i : number of parameter bands with a residual mixing matrix (i.e. decorrelation */ ); -#ifdef IVAS_FLOAT_FIXED1 -void ivas_dirac_dec_output_synthesis_cov_close_fx( - DIRAC_OUTPUT_SYNTHESIS_PARAMS *h_dirac_output_synthesis_params, /* i : handle for the covariance synthesis parameters */ - DIRAC_OUTPUT_SYNTHESIS_COV_STATE *h_dirac_output_synthesis_state /* i/o: handle for the covariance synthesis state */ -); -#endif // IVAS_FLOAT_FIXED void ivas_dirac_dec_output_synthesis_cov_close( DIRAC_OUTPUT_SYNTHESIS_PARAMS *h_dirac_output_synthesis_params, /* i : handle for the covariance synthesis parameters */ @@ -5764,44 +4323,7 @@ void ivas_dirac_dec_output_synthesis_cov_param_mc_synthesise_slot( PARAM_MC_DEC_HANDLE hParamMC /* i : handle to the Parametric MC decoder state */ ); -#ifdef IVAS_FLOAT_FIXED -void ivas_dirac_dec_output_synthesis_cov_param_mc_synthesise_slot_fx( - Word32 *Cldfb_RealBuffer_in_fx, - Word32 *Cldfb_ImagBuffer_in_fx, - Word32 Cldfb_RealBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* o : output channel filter bank samples (real part) */ - Word32 Cldfb_ImagBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* o : output channel filter bank samples (imaginary part) */ - Word32 *mixing_matrix_fx[], /* i : parameter band wise mixing matrices (direct part) */ - Word16 *mixing_matrix_e, /* i : parameter band wise mixing matrices (direct part) */ - Word32 *mixing_matrix_res_fx[], /* i : parameter band wise mixing matrices (residual part) */ - Word16 *mixing_matrix_res_e, /* i : parameter band wise mixing matrices (residual part) */ - const UWord16 slot_idx_sfr, /* i : time slot index for the current slot within the current subframe */ - const UWord16 slot_idx_tot, /* i : time slot index for the current slot within the frame */ - const Word16 nX, /* i : number of input channels */ - const Word16 nY, /* i : number of output channels */ - PARAM_MC_DEC_HANDLE hParamMC /* i : handle to the Parametric MC decoder state */ -); -#endif - -#ifdef IVAS_FLOAT_FIXED -Word16 computeMixingMatricesISM_fx( - const Word16 num_inputs, - const Word16 num_responses, - const Word16 num_outputs, - const Word32 *responses_fx, - const Word16 responses_e, - const Word32 *ener_fx, - const Word16 ener_e, - const Word32 *Cx_diag_fx, - const Word16 Cx_diag_e, - const Word32 *Cy_diag_fx, - const Word16 Cy_diag_e, - const Word16 *Q_16fx, //Q15 - const Word16 energy_compensation_flag, - const Word32 reg_Sx_fx, - const Word32 reg_ghat_fx, - Word32 *mixing_matrix_fx, - Word16 *mixing_matrix_e); -#else +#ifndef IVAS_FLOAT_FIXED int16_t computeMixingMatricesISM( const int16_t num_inputs, const int16_t num_responses, @@ -5836,11 +4358,6 @@ ivas_error ivas_spar_enc_open( const int16_t spar_reconfig_flag /* i : SPAR reconfiguration flag */ ); -ivas_error ivas_spar_enc_open_fx( - Encoder_Struct *st_ivas, /* i/o: IVAS encoder handle */ - const Word16 spar_reconfig_flag /* i : SPAR reconfiguration flag */ -); - void ivas_spar_enc_close( SPAR_ENC_HANDLE *hSpar, /* i/o: SPAR encoder handle */ const int32_t input_Fs, /* i : input sampling rate */ @@ -5867,12 +4384,6 @@ void ivas_spar_dec_close( const int32_t output_Fs, /* i : output sampling rate */ const int16_t spar_reconfig_flag /* i : SPAR reconfiguration flag */ ); -#else -void ivas_spar_dec_close_fx( - SPAR_DEC_HANDLE *hSpar, /* i/o: SPAR decoder handle */ - const Word32 output_Fs, /* i : output sampling rate */ - const Word16 spar_reconfig_flag /* i : SPAR reconfiguration flag */ -); #endif ivas_error ivas_spar_dec( @@ -5889,16 +4400,6 @@ void ivas_spar_config( int32_t *core_nominal_brate, /* o : core-coding nominal bitrate */ const int16_t sid_format /* i : IVAS format indicator from SID frame */ ); -#ifdef IVAS_FLOAT_FIXED -ivas_error ivas_sba_linear_renderer_fx( - Word32 *output_f[], /* i/o: synthesized core-coder transport channels/DirAC output */ - const Word16 output_frame, /* i : output frame length per channel */ - const Word16 nchan_in, /* i : number of input ambisonics channels */ - const Word16 nchan_ism, /* i : number of objects */ - const AUDIO_CONFIG output_config, /* i : output audio configuration */ - const IVAS_OUTPUT_SETUP output_setup /* i : output format setup */ -); -#endif // IVAS_FLOAT_FIXED ivas_error ivas_sba_linear_renderer( float *output_f[], /* i/o: synthesized core-coder transport channels/DirAC output */ @@ -5908,17 +4409,6 @@ ivas_error ivas_sba_linear_renderer( const AUDIO_CONFIG output_config, /* i : output audio configuration */ const IVAS_OUTPUT_SETUP output_setup /* i : output format setup */ ); -#ifdef IVAS_FLOAT_FIXED -void ivas_sba_mix_matrix_determiner_fx( - SPAR_DEC_HANDLE hSpar, /* i/o: SPAR decoder handle */ - Word32 *output_fx[], /* i/o: transport/output audio channels */ - const Word16 bfi, /* i : BFI flag */ - const Word16 nchan_remapped, /* i : num channels after remapping of TCs */ - const Word16 output_frame, /* i : output frame length */ - const Word16 num_md_sub_frames, /* i : number of subframes in mixing matrix*/ - const Word16 Q_output /* i : Q of transport/output audio channels */ -); -#endif // IVAS_FLOAT_FIXED void ivas_sba_mix_matrix_determiner( SPAR_DEC_HANDLE hSpar, /* i/o: SPAR decoder handle */ @@ -5935,10 +4425,6 @@ void ivas_sba_mix_matrix_determiner( int16_t ivas_agc_enc_get_flag( const int16_t nchan_transport /* i : number of transport channels */ ); -#else -Word16 ivas_agc_enc_get_flag( - const Word16 nchan_transport /* i : number of transport channels */ -); #endif ivas_error ivas_spar_agc_enc_open( @@ -5947,34 +4433,10 @@ ivas_error ivas_spar_agc_enc_open( const int16_t nchan_inp /* i : number of input channels */ ); -#ifdef IVAS_FLOAT_FIXED -ivas_error ivas_spar_agc_enc_open_fx( - ivas_agc_enc_state_t **hAgcEnc, /* i/o: SPAR AGC encoder handle */ - const Word32 input_Fs, /* i : input sampling rate */ - const Word16 nchan_inp /* i : number of input channels */ -); -#endif - void ivas_spar_agc_enc_close( ivas_agc_enc_state_t **hAgcEnc /* i/o: AGC encoder handle */ ); -#ifdef IVAS_FLOAT_FIXED -void ivas_spar_agc_enc_close_fx( - ivas_agc_enc_state_t **hAgcEnc /* i/o: SPAR AGC encoder handle */ -); - -void ivas_agc_enc_process_fx( - ivas_agc_enc_state_t *hAgcEnc, /* i/o: AGC encoder handle */ - BSTR_ENC_HANDLE hMetaData, /* i/o: MetaData handle */ - Word32 **ppPcm_in, /* i : input audio channels */ - Word32 **ppPcm_out, /* o : output audio channels */ - const Word16 n_channels, /* i : number of channels */ - const ENCODER_CONFIG_HANDLE hEncoderConfig, /* i : configuration structure */ - Word16 *q_ppPcm -); -#endif - void ivas_agc_enc_process( ivas_agc_enc_state_t *hAgcEnc, /* i/o: AGC encoder handle */ BSTR_ENC_HANDLE hMetaData, /* i/o: MetaData handle */ @@ -6000,12 +4462,6 @@ ivas_error ivas_spar_md_enc_init const int16_t sba_order /* i : Ambisonic (SBA) order */ ); -ivas_error ivas_spar_md_enc_init_fx( - ivas_spar_md_enc_state_t *hMdEnc, /* o : MD encoder handle */ - const ENCODER_CONFIG_HANDLE hEncoderConfig, /* i : configuration structure */ - const Word16 sba_order /* i : Ambisonic (SBA) order */ -); - void ivas_agc_dec_process( ivas_agc_dec_state_t *hAgcDec, /* i/o: AGC decoder handle */ float *pcm_in[], /* i : input audio channels */ @@ -6072,15 +4528,6 @@ void ivas_spar_set_bitrate_config( const int16_t agc_flag ); -void ivas_spar_set_bitrate_config_fx( - ivas_spar_md_com_cfg *pSpar_md_cfg, /* i/o: SPAR MD config. handle */ - const Word16 table_idx, /* i : config. table index */ - const Word16 num_bands, /* i : number of bands */ - const Word16 dirac2spar_md_flag, - const Word16 enc_flag, - const Word16 pca_flag, - const Word16 agc_flag); - void ivas_spar_bitrate_dist( int32_t core_brates_act[], /* o : bitrates per core-coder */ const int16_t nAvailBits, /* i : number of available bits */ @@ -6125,12 +4572,6 @@ void ivas_itda( const int16_t length ); -void ivas_spar_get_cldfb_gains_fx( - SPAR_DEC_HANDLE hSpar, - HANDLE_CLDFB_FILTER_BANK cldfbAnaDec0, - HANDLE_CLDFB_FILTER_BANK cldfbSynDec0, - const DECODER_CONFIG_HANDLE hDecoderConfig -); void ivas_spar_get_cldfb_gains( SPAR_DEC_HANDLE hSpar, HANDLE_CLDFB_FILTER_BANK cldfbAnaDec0, @@ -6144,41 +4585,19 @@ int16_t ivas_is_res_channel( const int16_t ch, /* i : ch index in WYZX ordering */ const int16_t nchan_transport /* i : number of transport channels (1-4) */ ); - -#else -Word16 ivas_is_res_channel( - const Word16 ch, /* i : ch index in WYZX ordering */ - const Word16 nchan_transport /* i : number of transport channels (1-4) */ -); #endif + void ivas_spar_dec_agc_pca( Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ float *output[], /* i/o: input/output audio channels */ const Word16 output_frame /* i : output frame length */ ); -#ifdef IVAS_FLOAT_FIXED -void ivas_spar_dec_agc_pca_fx( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ - Word32 *output[], /* i/o: input/output audio channels */ - const Word16 output_frame /* i : output frame length */ -); -#endif -#ifdef IVAS_FLOAT_FIXED -void ivas_spar_dec_set_render_map_fx( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ - const Word16 nCldfbTs /* i : number of CLDFB time slots */ -); -#endif + void ivas_spar_dec_set_render_map( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ const int16_t nCldfbTs /* i : number of CLDFB time slots */ ); -#ifdef IVAS_FLOAT_FIXED -void ivas_spar_dec_set_render_params_fx( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ - const Word16 n_cldfb_slots /* i : number of cldfb slots in this frame */ -); -#endif + void ivas_spar_dec_set_render_params( Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ const int16_t n_cldfb_slots /* i : number of cldfb slots in this frame */ @@ -6190,34 +4609,12 @@ void ivas_spar_dec_digest_tc( const int16_t nCldfbSlots, /* i : number of CLDFB slots */ const int16_t nSamplesForRendering /* i : number of samples provided */ ); -#ifdef IVAS_FLOAT_FIXED -void ivas_spar_dec_digest_tc_fx( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ - const Word16 nchan_transport, /* i : number of transport channels */ - const Word16 nCldfbSlots, /* i : number of CLDFB slots */ - const Word16 nSamplesForRendering /* i : number of samples provided */ -); -#endif + void ivas_sba_dec_digest_tc( Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ const int16_t nCldfbSlots, /* i : number of CLDFB slots */ const int16_t nSamplesForRendering /* i : number of samples provided */ ); -#ifdef IVAS_FLOAT_FIXED -void ivas_sba_dec_digest_tc_fx( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ - const Word16 nCldfbSlots, /* i : number of CLDFB slots */ - const Word16 nSamplesForRendering /* i : number of samples provided */ -); -ivas_error ivas_sba_dec_render_fx( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ - const UWord16 nSamplesAsked, /* i : number of CLDFB slots requested */ - UWord16 *nSamplesRendered, /* o : number of CLDFB slots rendered */ - UWord16 *nSamplesAvailableNext, /* o : number of CLDFB slots still to render */ - Word32 *output_fx[], /* o : rendered time signal Q11*/ - Word16 out_len/*Store the length of values in each channel*/ -); -#endif // IVAS_FLOAT_FIXED ivas_error ivas_sba_dec_render( Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ @@ -6226,14 +4623,6 @@ ivas_error ivas_sba_dec_render( uint16_t *nSamplesAvailable, /* o : number of CLDFB slots still to render */ float *output_f[] /* o : rendered time signal */ ); -#ifdef IVAS_FLOAT_FIXED -void ivas_spar_dec_upmixer_sf_fx( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ - Word32 *output_fx[], /* o : output audio channels */ - const Word16 nchan_internal, /* i : number of internal channels */ - Word16 out_len -); -#endif // IVAS_FLOAT_FIXED void ivas_spar_dec_upmixer_sf( Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ @@ -6255,32 +4644,11 @@ ivas_error ivas_spar_md_enc_open( const int16_t sba_order /* i : Ambisonic (SBA) order */ ); -ivas_error ivas_spar_md_enc_open_fx( - ivas_spar_md_enc_state_t **hMdEnc_in, /* i/o: SPAR MD encoder handle */ - const ENCODER_CONFIG_HANDLE hEncoderConfig, /* i : configuration structure */ - const Word16 sba_order /* i : Ambisonic (SBA) order */ -); - void ivas_spar_md_enc_close( ivas_spar_md_enc_state_t **hMdEnc /* i/o: SPAR MD encoder handle */ ); -#ifdef IVAS_FLOAT_FIXED -ivas_error ivas_spar_md_enc_process_fx( - ivas_spar_md_enc_state_t *hMdEnc, /* i/o: SPAR MD encoder handle */ - const ENCODER_CONFIG_HANDLE hEncoderConfig, /* i : configuration structure */ - Word32 *cov_real_fx[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], - Word16 *cov_real_q[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], - Word32 *cov_dtx_real_fx[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], - Word16 *cov_dtx_real_q[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], - BSTR_ENC_HANDLE hMetaData, /* i/o: MetaData handle */ - const Word16 dtx_vad, - const Word16 nchan_inp, - const Word16 sba_order, /* i : Ambisonic (SBA) order */ - float *prior_mixer[IVAS_MAX_FB_MIXER_OUT_CH][IVAS_MAX_SPAR_FB_MIXER_IN_CH], /* i : prior mixer_matrix */ - const Word16 dyn_active_w_flag, /* i : flag to indicate dynamic active W */ - const Word16 dirac_mono_flag /* i : flag to indicate mono only mode in SBA */ -); -#else + +#ifndef IVAS_FLOAT_FIXED ivas_error ivas_spar_md_enc_process( ivas_spar_md_enc_state_t *hMdEnc, /* i/o: SPAR MD encoder handle */ const ENCODER_CONFIG_HANDLE hEncoderConfig, /* i : configuration structure */ @@ -6296,51 +4664,69 @@ ivas_error ivas_spar_md_enc_process( ); #endif -#ifdef IVAS_FLOAT_FIXED -void ivas_create_fullr_dmx_mat_fx( - Word32 pred_coeffs_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], - Word16 q_pred_coeffs_re, - Word32 dm_fv_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], - Word16 q_dm_fv_re, - Word32 ***mixer_mat, - Word16 *q_mixer_mat, - const Word16 in_chans, - const Word16 start_band, - const Word16 end_band, - const Word16 active_w, - ivas_spar_md_com_cfg *hMdCfg +void ivas_compute_spar_params( + float *pppCov_mat_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + float dm_fv_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], + const int16_t i_ts, + float ***mixer_mat, + const int16_t start_band, + const int16_t end_band, + const int16_t dtx_vad, + const int16_t num_ch, + const int16_t bands_bw, + const int16_t active_w, + const int16_t active_w_vlbr, + ivas_spar_md_com_cfg *hSparCfg, + ivas_spar_md_t *hSparMd, + float *pWscale, + const int16_t from_dirac, + const int16_t dyn_active_w_flag +); + +void ivas_create_fullr_dmx_mat( + float pred_coeffs_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], + float dm_fv_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], + float ***mixer_mat, + const int16_t in_chans, + const int16_t start_band, + const int16_t end_band, + const int16_t active_w, + ivas_spar_md_com_cfg *hMdCfg ); -#endif // IVAS_FLOAT_FIXED -#ifdef IVAS_FLOAT_FIXED -void ivas_get_spar_md_from_dirac_fx( - Word32 azi_dirac_fx[IVAS_MAX_NUM_BANDS][MAX_PARAM_SPATIAL_SUBFRAMES], // Q22 - Word32 ele_dirac_fx[IVAS_MAX_NUM_BANDS][MAX_PARAM_SPATIAL_SUBFRAMES], // Q22 - Word32 diffuseness_fx[IVAS_MAX_NUM_BANDS], // Q30 - const Word16 n_ts, - Word32 ***mixer_mat_fx, - Word16 *q_mixer_mat_fx, +void ivas_calc_c_p_coeffs( + ivas_spar_md_t *pSparMd, + float *pppCov_mat_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + const int16_t i_ts, + float ***mixer_mat, + const int16_t num_ch, + const int16_t num_dmx, + const int16_t band_idx, + const int16_t dtx_vad, + const int16_t compute_p_flag, + const int16_t dyn_active_w_flag +); + +void ivas_get_spar_md_from_dirac( + float azi_dirac[IVAS_MAX_NUM_BANDS][MAX_PARAM_SPATIAL_SUBFRAMES], + float ele_dirac[IVAS_MAX_NUM_BANDS][MAX_PARAM_SPATIAL_SUBFRAMES], + float diffuseness[IVAS_MAX_NUM_BANDS], + const int16_t n_ts, + float ***mixer_mat, ivas_spar_md_t *hSpar_md, ivas_spar_md_com_cfg *hSpar_md_cfg, - const Word16 start_band, - const Word16 end_band, - const Word16 order, - const Word16 dtx_vad, - Word32 Wscale_d[IVAS_MAX_NUM_BANDS], // Q29 - const UWord8 useLowerRes, - const Word16 active_w_vlbr, - const Word16 dyn_active_w_flag + const int16_t start_band, + const int16_t end_band, + const int16_t order, + const int16_t dtx_vad, + float Wscale_d[IVAS_MAX_NUM_BANDS], + const uint8_t useLowerRes, + const int16_t active_w_vlbr, + const int16_t dyn_active_w_flag ); -#endif /*! r: number of MD subframes */ -#ifdef IVAS_FLOAT_FIXED -Word16 ivas_get_spar_dec_md_num_subframes( - const Word16 sba_order, /* i : Ambisonic (SBA) order */ - const Word32 ivas_total_brate, /* i : IVAS total bitrate */ - const Word32 ivas_last_active_brate /* i : IVAS last active bitrate */ -); -#else +#ifndef IVAS_FLOAT_FIXED int16_t ivas_get_spar_dec_md_num_subframes( const int16_t sba_order, /* i : Ambisonic (SBA) order */ const int32_t ivas_total_brate, /* i : IVAS total bitrate */ @@ -6372,15 +4758,6 @@ void ivas_spar_md_dec_close( ivas_spar_md_dec_state_t **hMdDec /* i/o: SPAR MD decoder handle */ ); -void ivas_spar_get_parameters_fx( - SPAR_DEC_HANDLE hSpar, /* i/o: SPAR decoder handle */ - const DECODER_CONFIG_HANDLE hDecoderConfig, /* i : configuration structure */ - const Word16 ts, /* i : time slot index */ - const Word16 num_ch_out, /* i : number of channels out */ - const Word16 num_ch_in, /* i : number of channels in */ - const Word16 num_spar_bands, /* i : number of SPAR bands */ - Word32 par_mat_fx[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH][IVAS_MAX_NUM_BANDS] /* o : mixing matrix */ -); void ivas_spar_get_parameters( SPAR_DEC_HANDLE hSpar, /* i/o: SPAR decoder handle */ const DECODER_CONFIG_HANDLE hDecoderConfig, /* i : configuration structure */ @@ -6413,14 +4790,7 @@ void ivas_spar_to_dirac( const int16_t bw, /* i : band joining factor */ const int16_t dyn_active_w_flag /* i : dynamic active W flag */ ); -void ivas_spar_to_dirac_fx( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ - ivas_spar_md_dec_state_t *hMdDec, /* i/o: SPAR MD decoder handle */ - const Word16 dtx_vad, /* i : DTX frame flag */ - const Word16 num_bands_out, /* i : number of output bands */ - const Word16 bw, /* i : band joining factor */ - const Word16 dyn_active_w_flag /* i : dynamic active W flag */ -); + void ivas_spar_update_md_hist( ivas_spar_md_dec_state_t *hMdDec /* i/o: SPAR MD decoder handle */ ); @@ -6429,10 +4799,6 @@ int16_t ivas_spar_chk_zero_coefs( Decoder_Struct *st_ivas /* i/o: IVAS decoder handle */ ); -Word16 ivas_spar_chk_zero_coefs_fx( - Decoder_Struct *st_ivas /* i/o: IVAS decoder handle */ -); - void ivas_spar_smooth_md_dtx( ivas_spar_md_dec_state_t *hMdDec, /* i/o: SPAR MD decoder handle */ const int16_t num_bands_out, /* i : number of output bands */ @@ -6444,15 +4810,6 @@ void ivas_spar_setup_md_smoothing( const int16_t num_bands_out, /* i : number of output bands */ const int16_t num_md_sub_frames /* i : number of metadata subframes */ ); -#ifdef IVAS_FLOAT_FIXED -void ivas_spar_dec_gen_umx_mat_fx( - ivas_spar_md_dec_state_t *hMdDec, /* i/o: SPAR MD decoder handle */ - const Word16 nchan_transport, /* i : number of transport channels */ - const Word16 num_bands_out, /* i : number of output bands */ - const Word16 bfi, /* i : bad frame indicator */ - const Word16 num_md_sub_frames -); -#endif // IVAS_FLOAT_FIXED void ivas_spar_dec_gen_umx_mat( ivas_spar_md_dec_state_t *hMdDec, /* i/o: SPAR MD decoder handle */ @@ -6462,21 +4819,7 @@ void ivas_spar_dec_gen_umx_mat( const int16_t num_md_sub_frames ); -#ifdef IVAS_FLOAT_FIXED -ivas_error ivas_spar_covar_enc_open_fx( - ivas_enc_cov_handler_state_t **hCovEnc, /* i/o: SPAR Covar. encoder handle */ - ivas_filterbank_t *pFb, /* i/o: FB handle */ - const Word32 input_Fs, /* i : input sampling rate */ - const Word16 nchan_inp, /* i : number of input channels */ - const COV_SMOOTHING_TYPE smooth_mode, /* i : Smooth covariance for SPAR or MC*/ - const Word32 ivas_total_brate /* i : IVAS total bitrate */ -); - -void ivas_spar_covar_enc_close_fx( - ivas_enc_cov_handler_state_t **hCovEnc, /* i/o: SPAR Covar. encoder handle */ - const Word16 nchan_inp /* i : number of input channels */ -); -#else +#ifndef IVAS_FLOAT_FIXED /* Covariance module */ ivas_error ivas_spar_covar_enc_open( ivas_enc_cov_handler_state_t **hCovEnc, /* i/o: SPAR Covar. encoder handle */ @@ -6493,30 +4836,7 @@ void ivas_spar_covar_enc_close( ); #endif -#ifdef IVAS_FLOAT_FIXED -void ivas_enc_cov_handler_process_fx( - ivas_enc_cov_handler_state_t *hCovEnc, /* i/o: SPAR Covar. encoder handle */ - Word32 **ppIn_FR_real, - Word32 **ppIn_FR_imag, - Word16 q_ppIn_FR, - Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], - Word16 *q_cov_real[IVAS_SPAR_MAX_CH], - Word32 *cov_dtx_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], - Word16 *q_cov_dtx_real[IVAS_SPAR_MAX_CH], - ivas_filterbank_t *pFb, /* i/o: FB handle */ - const Word16 start_band, - const Word16 end_band, - const Word16 num_ch, - const Word16 dtx_vad, - const Word16 transient_det[2], - const Word16 HOA_md_ind[IVAS_SPAR_MAX_CH], - Word16 *res_ind, - const Word16 *remix_order, - Word16 *dyn_active_w_flag, - const Word16 nchan_transport, - const Word16 is_sba -); -#else +#ifndef IVAS_FLOAT_FIXED void ivas_enc_cov_handler_process( ivas_enc_cov_handler_state_t *hCovEnc, /* i/o: SPAR Covar. encoder handle */ float **ppIn_FR_real, @@ -6538,21 +4858,7 @@ void ivas_enc_cov_handler_process( ); #endif -#ifdef IVAS_FLOAT_FIXED -ivas_error ivas_spar_covar_smooth_enc_open_fx( - ivas_cov_smooth_state_t **hCovState, /* i/o: SPAR Covar. smoothing handle */ - const ivas_cov_smooth_cfg_t *cov_smooth_cfg, /* i : SPAR config. handle */ - ivas_filterbank_t *pFb, /* i/o: FB handle */ - const Word16 nchan_inp, /* i : number of input channels */ - const COV_SMOOTHING_TYPE smooth_mode, /* i : Smooth covariance for SPAR or MC */ - const Word32 ivas_total_brate /* i : IVAS total bitrate */ -); - -void ivas_spar_covar_smooth_enc_close_fx( - ivas_cov_smooth_state_t **hCovState, /* i/o: SPAR Covar. encoder handle */ - const Word16 nchan_inp /* i : number of input channels */ -); -#else +#ifndef IVAS_FLOAT_FIXED ivas_error ivas_spar_covar_smooth_enc_open( ivas_cov_smooth_state_t **hCovState, /* i/o: SPAR Covar. smoothing handle */ const ivas_cov_smooth_cfg_t *cov_smooth_cfg, /* i : SPAR config. handle */ @@ -6568,18 +4874,7 @@ void ivas_spar_covar_smooth_enc_close( ); #endif -#ifdef IVAS_FLOAT_FIXED -void ivas_cov_smooth_process_fx( - ivas_cov_smooth_state_t *hCovState, /* i/o: Covariance state handle */ - Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], - ivas_filterbank_t *pFb, /* i/o: FB handle */ - const Word16 start_band, - const Word16 end_band, - const Word16 num_ch, - const Word16 transient_det[2], - Word16 *q_cov[IVAS_SPAR_MAX_CH] -); -#else +#ifndef IVAS_FLOAT_FIXED void ivas_cov_smooth_process( ivas_cov_smooth_state_t *hCovState, /* i/o: Covariance state handle */ float *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], @@ -6654,17 +4949,6 @@ void ivas_pca_enc( const int16_t n_channels /* i : number of channels */ ); -#ifdef IVAS_FLOAT_FIXED -void ivas_pca_enc_fx( - const ENCODER_CONFIG_HANDLE hEncoderConfig, /* i : configuration structure */ - PCA_ENC_STATE *hPCA, /* i : PCA encoder structure */ - BSTR_ENC_HANDLE hMetaData, /* i/o: MetaData handle */ - Word32 *data_f[8], /* i : input/transformed audio channels Q11 */ - const Word16 input_frame, /* i : input frame length */ - const Word16 n_channels /* i : number of channels */ -); -#endif - void ivas_pca_read_bits( Decoder_State *st0, /* i/o: decoder state structure - for bitstream handling*/ PCA_DEC_STATE *hPCA /* i/o: PCA encoder structure */ @@ -6683,44 +4967,14 @@ void ivas_pca_dec( const int16_t bfi, /* i : bad frame indicator */ float *pcm_out[] /* o : output audio channels */ ); -#ifdef IVAS_FLOAT_FIXED -void ivas_pca_read_bits_fx( - Decoder_State *st0, /* i/o: decoder state structure - for bitstream handling*/ - PCA_DEC_STATE *hPCA /* i/o: PCA encoder structure */ -); -void ivas_pca_dec_init_fx( - PCA_DEC_STATE *hPCA /* i/o: PCA decoder structure */ -); - -void ivas_pca_dec_fx( - PCA_DEC_STATE *hPCA, /* i/o: PCA decoder structure */ - const Word16 output_frame, /* i : output frame length */ - const Word16 n_channels, /* i : number of channels */ - const Word32 ivas_total_brate, /* i : IVAS total bitrate */ - const Word32 last_ivas_total_brate, /* i : last IVAS total bitrate */ - const Word16 bfi, /* i : bad frame indicator */ - Word32 *pcm_out[] /* o : output audio channels */ -); -#endif /* PCA utilities */ void eye_matrix( float *mat, const int16_t n, const float d ); -#ifdef IVAS_FLOAT_FIXED -void eye_matrix_fx( - Word16 *mat, - const Word16 n, - const Word16 d -); -void eye_matrix_fx32( - Word32 *mat, // Q - const Word16 n, - const Word32 d ); // Q -#endif void cov_subfr( float **ptr_sig, float *r, @@ -6728,14 +4982,6 @@ void cov_subfr( const int16_t len ); -#ifdef IVAS_FLOAT_FIXED -void cov_subfr_fx( - Word32 **ptr_sig_fx, // Q11 - Word64 *r_fx_64, // Q11 - const Word16 n_channels, - const Word16 len ); -#endif - void eig_qr( const float *A, const int16_t num_iter, @@ -6743,39 +4989,16 @@ void eig_qr( const int16_t n ); -#ifdef IVAS_FLOAT_FIXED -void eig_qr_fx( - const Word32 *A_fx, // A_q - Word16 A_q, - const Word16 num_iter, - Word32 *EV_fx, // Q31 - Word32 *Vals_fx, // A_q - const Word16 n ); -#endif - void exhst_4x4( float *cost_mtx, int16_t *path, const int16_t maximize ); -#ifdef IVAS_FLOAT_FIXED -void exhst_4x4_fx( - Word16 *cost_mtx, // Q - Word16 *path, - const Word16 maximize ); -#endif - float mat_det4( const float *m ); -#ifdef IVAS_FLOAT_FIXED -Word16 mat_det4_fx( - const Word16 *m // Q15 -); -#endif - /* quaternion utilities */ void mat2dquat( const float *a, @@ -6783,14 +5006,6 @@ void mat2dquat( float *qr ); -#ifdef IVAS_FLOAT_FIXED -void mat2dquat_fx( - const Word16 *a, // Q15 - Word16 *ql, // Q15 - Word16 *qr // Q15 -); -#endif - void dquat2mat( const float *ql, const float *qr, @@ -6814,50 +5029,16 @@ void pca_interp_preproc( float *qr_interp ); -#ifdef IVAS_FLOAT_FIXED -void dquat2mat_fx( - const Word16 *ql, - const Word16 *qr, - Word16 *m); - -void quat_shortestpath_fx( - const Word16 *q00, - Word16 *q01, - const Word16 *q10, - Word16 *q11); - -void pca_interp_preproc_fx( - const Word16 *prev_ql, - const Word16 *prev_qr, - const Word16 *ql, - const Word16 *qr, - const Word16 len, - Word16 *ql_interp, - Word16 *qr_interp); -#endif void pca_enc_s3( float *q, int32_t *index ); -#ifdef IVAS_FLOAT_FIXED -void pca_enc_s3_fx( - Word16 *q, // Q15 - Word32 *index -); -#endif - void pca_dec_s3( const int32_t index, float *q ); -#ifdef IVAS_FLOAT_FIXED -void pca_dec_s3_fx( - const Word32 index, - Word16 *q); -#endif - #ifndef IVAS_FLOAT_FIXED int16_t ivas_get_bits_to_encode( int32_t val @@ -6871,17 +5052,6 @@ void ivas_huffman_encode( int16_t *hlen ); -void ivas_spar_huff_coeffs_com_init( - ivas_huff_coeffs_t *pHuff_coeffs, - ivas_spar_md_com_cfg *pSpar_cfg, - const Word16 table_idx, - const Word16 enc_dec); - -void ivas_spar_arith_coeffs_com_init( - ivas_arith_coeffs_t *pArith_coeffs, - ivas_spar_md_com_cfg *pSpar_cfg, - const Word16 table_idx, - const Word16 enc_dec); #ifndef IVAS_FLOAT_FIXED int16_t ivas_arith_encode_cmplx_cell_array( @@ -6920,12 +5090,6 @@ void ivas_ari_start_decoding_14bits_ext_1_lfe( Tastat *s, int16_t *extra_bits_read ); -#else -void ivas_ari_start_decoding_14bits_ext_1_lfe( - Decoder_State *st, - Tastat *s, - Word16 *extra_bits_read -); #endif #ifndef IVAS_FLOAT_FIXED @@ -6934,12 +5098,6 @@ uint16_t ivas_ari_decode_14bits_bit_ext_1_lfe( const uint16_t *cum_freq, int16_t *extra_bits_read ); -#else -UWord16 ivas_ari_decode_14bits_bit_ext_1_lfe( - Decoder_State *st, Tastat *s, - const UWord16 *cum_freq, - Word16 *extra_bits_read -); #endif #ifndef IVAS_FLOAT_FIXED @@ -6947,11 +5105,6 @@ void ivas_ari_done_decoding_14bits_ext_1_lfe( Decoder_State *st, const int16_t extra_bits_read ); -#else -void ivas_ari_done_decoding_14bits_ext_1_lfe( - Decoder_State *st, - const Word16 extra_bits_read -); #endif void ivas_ari_done_encoding_14bits( @@ -7003,59 +5156,17 @@ void ivas_quantise_real_values( float *quant, const int16_t dim ); -void ivas_quantise_real_values_fx( - const Word32 *values_fx, - const Word16 q_levels, - const Word32 min_value_fx, - const Word32 max_value_fx, - Word16 *index, - Word32 *quant_fx, - const Word16 dim); - -void ivas_quantise_real_values_enc_fx_varq( - const Word32 *values_fx, - const Word16 q_levels, - const Word32 min_value_fx, - const Word32 max_value_fx, - Word16 *index, - Word32 *quant_fx, - const Word16 dim, - Word16 inp_q ); - -void ivas_quantise_real_values_enc_fx( - const Word32 *values_fx,//Q28 - const Word16 q_levels, - const Word32 min_value_fx,//Q28 - const Word32 max_value_fx,//Q28 - Word16 *index, - Word32 *quant_fx,//Q28 - const Word16 dim); - void ivas_spar_get_uniform_quant_strat( ivas_spar_md_com_cfg *pSpar_md_com_cfg, const int16_t table_idx ); -void ivas_spar_get_uniform_quant_strat_fx( - ivas_spar_md_com_cfg *pSpar_md_com_cfg, - const Word16 table_idx); - void ivas_spar_quant_dtx_init( ivas_spar_md_t *spar_md, float *min_max ); -void ivas_spar_quant_dtx_init_fx( - ivas_spar_md_t *spar_md, - Word32 *min_max -); - -void ivas_spar_quant_dtx_init_fx( - ivas_spar_md_t *spar_md, - Word32 *min_max -); - void ivas_map_prior_coeffs_quant( ivas_spar_md_prev_t *pSpar_md_prior, ivas_spar_md_com_cfg *pSpar_md_cfg, @@ -7063,14 +5174,7 @@ void ivas_map_prior_coeffs_quant( const int16_t nB ); -#ifdef IVAS_FLOAT_FIXED -void ivas_copy_band_coeffs_idx_to_arr( - ivas_band_coeffs_ind_t *pBands_idx, - const Word16 nB, - Word16 *pSymbol_re, - ivas_cell_dim_t *pCell_dims, - const ivas_coeffs_type_t coeff_type); -#else +#ifndef IVAS_FLOAT_FIXED void ivas_copy_band_coeffs_idx_to_arr( ivas_band_coeffs_ind_t *pBands_idx, const int16_t nB, @@ -7080,9 +5184,10 @@ void ivas_copy_band_coeffs_idx_to_arr( ); #endif -void ivas_clear_band_coeffs_fx( - ivas_band_coeffs_t *pband_coeffs, - const UWord16 num_bands); +void ivas_clear_band_coeffs( + ivas_band_coeffs_t *pband_coeffs, + const uint16_t num_bands +); void ivas_clear_band_coeff_idx( ivas_band_coeffs_ind_t *pband_coeff_idx, @@ -7196,14 +5301,7 @@ void distribute_evenly_ism( const int16_t nchan_ism ); -#ifdef IVAS_FLOAT_FIXED -Word16 ivas_qmetadata_DecodeExtendedGR( - UWord16* bitstream, - Word16* index, - const Word16 alph_size, - const Word16 gr_param -); -#else +#ifndef IVAS_FLOAT_FIXED int16_t ivas_qmetadata_DecodeExtendedGR( uint16_t* bitstream, int16_t* index, @@ -7235,11 +5333,7 @@ void ivas_merge_masa_metadata( OMASA_SPATIAL_META_HANDLE hOMasaMeta /* i : ISM-object metadata to be merged with the MASA metadata */ ); -#ifdef IVAS_FLOAT_FIXED -void ivas_masa_combine_directions_fx( - MASA_ENCODER_HANDLE hMasa /* i/o: MASA encoder handle */ -); -#else +#ifndef IVAS_FLOAT_FIXED void ivas_masa_combine_directions( MASA_ENCODER_HANDLE hMasa /* i/o: MASA encoder handle */ ); @@ -7302,7 +5396,7 @@ void ivas_set_qmetadata_maxbit_req( const IVAS_FORMAT ivas_format /* i : IVAS format */ ); -#ifdef IVAS_FLOAT_FIXED +#ifndef IVAS_FLOAT_FIXED /*! r: Bits to be used for quantizing distribution ratio of direct-to-total ratios */ Word16 ivas_get_df_ratio_bits_hodirac( const Word16 index_diff /* i : index of quantized diffuse-to-total ratio */ @@ -7312,16 +5406,6 @@ Word16 ivas_get_df_ratio_bits_hodirac( Word16 ivas_get_df_ratio_bits( const Word16 index_diff /* i : index of quantized diffuse-to-total ratio */ ); -#else -/*! r: Bits to be used for quantizing distribution ratio of direct-to-total ratios */ -int16_t ivas_get_df_ratio_bits_hodirac( - const int16_t index_diff /* i : Index of quantized diffuse-to-total ratio */ -); - -/*! r: Bits to be used for quantizing distribution ratio of direct-to-total ratios */ -int16_t ivas_get_df_ratio_bits( - const int16_t index_diff /* i : Index of quantized diffuse-to-total ratio */ -); #endif @@ -7339,14 +5423,6 @@ void invdct4_transform( uint8_t *invdct_v /* o : transformed vector */ ); -#ifdef IVAS_FLOAT_FIXED -void invdct4_transform_fx( - Word32 *v_fx, /* i : input vector */ - UWord8 *invdct_v, /* o : transformed vector */ - Word16 q -); -#endif - #ifndef IVAS_FLOAT_FIXED void update_bits_next_block( IVAS_QDIRECTION *q_direction, /* i/o: qdirection */ @@ -7371,33 +5447,16 @@ void ivas_spar_param_to_masa_param_mapping( const int16_t subframe /* i : Subframe to map */ ); -void ivas_spar_param_to_masa_param_mapping_fx( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder struct */ - Word32 inRe_fx[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], /* i : Input audio in CLDFB domain, real */ - Word32 inIm_fx[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], /* i : Input audio in CLDFB domain, imag */ - Word16 q_cldfb[6][CLDFB_SLOTS_PER_SUBFRAME], - const Word16 subframe /* i : Subframe to map */ -); - - /*---------------------------------------------------------------------------------* * Binaural FastConv Renderer Prototypes *-----------------------------------------------------------------------------------*/ -#ifdef IVAS_FLOAT_FIXED -ivas_error ivas_binRenderer_open_fx( - Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ -); -#else +#ifndef IVAS_FLOAT_FIXED ivas_error ivas_binRenderer_open( Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ ); #endif -#ifdef IVAS_FLOAT_FIXED -void ivas_binRenderer_close_fx( - BINAURAL_RENDERER_HANDLE *hBinRenderer /* i/o: decoder binaural renderer handle */ -); -#else +#ifndef IVAS_FLOAT_FIXED void ivas_binRenderer_close( BINAURAL_RENDERER_HANDLE *hBinRenderer /* i/o: decoder binaural renderer handle */ ); @@ -7406,24 +5465,12 @@ void ivas_binRenderer_close( void ivas_binaural_hrtf_close( HRTFS_FASTCONV_HANDLE *hHrtfFastConv /* i/o: decoder binaural hrtf handle */ ); -#ifdef IVAS_FLOAT_FIXED -void ivas_init_binaural_hrtf_fx( - HRTFS_FASTCONV *HrtfFastConv /* i/o: FASTCONV HRTF structure */ -); -#else +#ifndef IVAS_FLOAT_FIXED void ivas_init_binaural_hrtf( HRTFS_FASTCONV *HrtfFastConv /* i/o: FASTCONV HRTF structure */ ); #endif -#ifdef IVAS_FLOAT_FIXED -ivas_error ivas_allocate_binaural_hrtf_fx( - HRTFS_FASTCONV *HrtfFastConv, /* i/o: FASTCONV HRTF structure */ - const AUDIO_CONFIG input_config, /* i : input audio configuration */ - const BINAURAL_INPUT_AUDIO_CONFIG bin_input_config, /* i : binaural input audio config */ - const RENDERER_TYPE renderer_type, /* i : renderer type */ - const Word16 allocate_init_flag /* i : Memory allocation flag */ -); -#else +#ifndef IVAS_FLOAT_FIXED ivas_error ivas_allocate_binaural_hrtf( HRTFS_FASTCONV *HrtfFastConv, /* i/o: FASTCONV HRTF structure */ const AUDIO_CONFIG input_config, /* i : input audio configuration */ @@ -7443,29 +5490,12 @@ void ivas_binRenderer( float ImagBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX] /* i : LS signals */ ); -void ivas_binRenderer_fx( - BINAURAL_RENDERER_HANDLE hBinRenderer, /* i/o: binaural renderer handle */ - COMBINED_ORIENTATION_HANDLE hCombinedOrientationData, /* i : combined head and external orientation handle*/ - const Word16 numTimeSlots, /* i : number of time slots to render */ - Word32 Cldfb_RealBuffer_Binaural_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* o : Binaural signals */ - Word32 Cldfb_ImagBuffer_Binaural_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* o : Binaural signals */ - Word32 RealBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* i : LS signals */ - Word32 ImagBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* i : LS signals */ - Word16 *Q_in /* i : LS signals exp */ -); - void ivas_binaural_add_LFE( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ int16_t output_frame, /* i : length of input frame */ float *input_f[], /* i : transport channels */ float *output_f[] /* o : synthesized core-coder transport channels/DirAC output */ ); -void ivas_binaural_add_LFE_fx( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ - Word16 output_frame, /* i : length of input frame */ - Word32 *input_fx[], /* i : transport channels */ - Word32 *output_fx[] /* o : synthesized core-coder transport channels/DirAC output */ -); /*----------------------------------------------------------------------------------* * renderer prototypes @@ -7494,17 +5524,6 @@ void ivas_ism_get_stereo_gains( ); #endif -#ifdef IVAS_FLOAT_FIXED -void ivas_mc2sba_fx( - IVAS_OUTPUT_SETUP hIntSetup, /* i : Format of decoder output */ - Word32 *in_buffer_td[], /* i : MC signals (on input) and the HOA3 (on output) */ - Word32 *buffer_td[], /* i/o: MC signals (on input) and the HOA3 (on output) */ - const Word16 output_frame, /* i : output frame length per channel */ - const Word16 sba_order, /* i : Ambisonic (SBA) order */ - const Word16 gain_lfe /* i : gain for LFE, 0 = ignore LFE */ -); -#endif // IVAS_FLOAT_FIXED - void ivas_mc2sba( IVAS_OUTPUT_SETUP hIntSetup, /* i : Format of decoder output */ float *in_buffer_td[], /* i : MC signals (on input) and the HOA3 (on output) */ @@ -7513,17 +5532,6 @@ void ivas_mc2sba( const int16_t sba_order, /* i : SBA order */ const float gain_lfe /* i : gain for LFE, 0=ignore LFE */ ); -#ifdef IVAS_FLOAT_FIXED -void ivas_param_mc_mc2sba_cldfb_fx( - IVAS_OUTPUT_SETUP hTransSetup, /* i : transported MC Format */ - Word32 *hoa_encoder, /* i : HOA3 encoder for the transported MC format */ - const Word16 slot_idx, /* i : current slot in the subframe */ - Word32 Cldfb_RealBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* i/o: Contains the MC signals (on input) and the HOA3 (on output) */ - Word32 Cldfb_ImagBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* i/o: Contains the MC signals (on input) and the HOA3 (on output) */ - const Word16 nBands, /* i : number of synth CLDFB bands */ - const Word16 gain_lfe /* i : gain applied to LFE */ -); -#endif // IVAS_FLOAT_FIXED void ivas_param_mc_mc2sba_cldfb( IVAS_OUTPUT_SETUP hTransSetup, /* i : transported MC Format */ @@ -7535,17 +5543,7 @@ void ivas_param_mc_mc2sba_cldfb( const float gain_lfe /* i : gain applied to LFE */ ); -#ifdef IVAS_FLOAT_FIXED -void ivas_ism2sba_sf_fx( - Word32 *buffer_in_fx[], /* i : TC buffer */ - Word32 *buffer_out_fx[], /* o : TD signal buffers */ - ISM_RENDERER_HANDLE hIsmRendererData, /* i/o: renderer data */ - const Word16 num_objects, /* i : number of objects */ - const Word16 n_samples_to_render, /* i : output frame length per channel */ - const Word16 offset, /* i : offset for the interpolatr */ - const Word16 sba_order /* i : Ambisonic (SBA) order */ -); -#else // IVAS_FLOAT_FIXED +#ifndef IVAS_FLOAT_FIXED void ivas_ism2sba_sf( float *buffer_in[], /* i : TC buffer */ float *buffer_out[], /* o : TD signal buffers */ @@ -7567,26 +5565,12 @@ void panning_wrap_angles( float *azi_wrapped, /* o : wrapped azimuth component */ float *ele_wrapped /* o : wrapped elevation component */ ); -#ifdef IVAS_FLOAT_FIXED -void panning_wrap_angles_fx( - const Word32 azi_deg, /* i : azimuth in degrees for panning direction (positive left) Q22 */ - const Word32 ele_deg, /* i : elevation in degrees for panning direction (positive up) Q22 */ - Word32 *azi_wrapped, /* o : wrapped azimuth component Q22 */ - Word32 *ele_wrapped /* o : wrapped elevation component Q22 */ -); -#endif + void v_sort_ind( float *x, /* i/o: Vector to be sorted */ int16_t *idx, /* o : Original index positions */ const int16_t len /* i : vector length */ ); -#ifdef IVAS_FLOAT_FIXED -void v_sort_ind_fixed( - Word32 *x, /* i/o: Vector to be sorted */ - Word16 *idx, /* o : Original index positions */ - const Word16 len /* i : vector length */ -); -#endif /*----------------------------------------------------------------------------------* * LS Renderer prototypes @@ -7613,13 +5597,6 @@ void ivas_ls_setup_conversion_process_mdct( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ float *output[] /* i/o: output synthesis signal */ ); -#ifdef IVAS_FLOAT_FIXED -void ivas_ls_setup_conversion_process_mdct_param_mc_fx( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ - Word32 *x_fx[][NB_DIV], /* i/o: Fixed output synthesis signal */ - Word16 x_e[CPE_CHANNELS][NB_DIV]/* i/o: Exponent for output synthesis signal */ -); -#endif // IVAS_FLOAT_FIXED void ivas_ls_setup_conversion_process_mdct_param_mc( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ @@ -7750,14 +5727,6 @@ void lls_interp_n( const int16_t upd /* i : use 1 to update x[] with the interpolated output*/ ); -void lls_interp_n_fx( - Word16 x_fx[], /* i/o: input/output vector */ - const Word16 N, /* i : length of the input vector */ - Word16 *a_fx, /* o : calculated slope */ - Word16 *b_fx, /* o : calculated offset */ - const Word16 upd /* i : use 1 to update x[] with the interpolated output */ -); - void computeReferencePower_enc( const int16_t *band_grouping, /* i : Band grouping for estimation */ float Cldfb_RealBuffer[][DIRAC_NO_FB_BANDS_MAX], /* i : Real part of input signal */ @@ -7794,15 +5763,7 @@ void ivas_mono_stereo_downmix_mcmasa( int16_t output_frame /* i : output frame length per channel */ ); #endif -#ifdef IVAS_FLOAT_FIXED -void ivas_lfe_synth_with_filters_fx( - MCMASA_LFE_SYNTH_DATA_HANDLE hMasaLfeSynth, /* i/o: LFE synthesis structure for McMASA */ - Word32 *data_f[], /* o : output signals */ - const Word16 output_frame, /* i : output frame length per channel */ - const Word16 separateChannelIndex, /* i : separate channel index */ - const Word16 lfeChannelIndex /* i : LFE channel index */ -); -#else +#ifndef IVAS_FLOAT_FIXED void ivas_lfe_synth_with_filters( MCMASA_LFE_SYNTH_DATA_HANDLE hMasaLfeSynth, /* i/o: LFE synthesis structure for McMASA */ float *data_f[], /* o : output signals */ @@ -7852,16 +5813,6 @@ void ivas_lfe_enc( BSTR_ENC_HANDLE hBstr /* i/o: bitstream handle */ ); -#ifdef IVAS_FLOAT_FIXED -void ivas_lfe_enc_fx( - LFE_ENC_HANDLE hLFE, /* i/o: LFE encoder handle */ - Word32 data_lfe_ch[], /* i : input LFE signal */ - Word16 q_data_lfe_ch, /* i : Q of input LFE signal */ - const Word16 input_frame, /* i : input frame length per channel */ - BSTR_ENC_HANDLE hBstr /* i/o: bitstream handle */ -); -#endif // IVAS_FLOAT_FIXED - #ifndef IVAS_FLOAT_FIXED ivas_error ivas_create_lfe_dec( LFE_DEC_HANDLE *hLFE_out, /* o : IVAS LFE decoder structure */ @@ -7903,16 +5854,6 @@ void ivas_lfe_lpf_select_filt_coeff( const float **ppFilt_coeff /* o : filter coefficients */ ); -#ifdef IVAS_FLOAT_FIXED -void ivas_lfe_lpf_select_filt_coeff_fx( - const Word32 sampling_rate, /* i : sampling rate */ - const Word16 order, /* i : filter order */ - const Word32 **ppFilt_coeff_fx, /* o : filter coefficients */ - const Word16 **ppFilt_coeff_e /* o : exponents of filter coefficients */ -); -#endif - - void ivas_filters_init( ivas_filters_process_state_t *filter_state, /* i/o: filter state handle */ const float *filt_coeff, /* i : filter coefficients */ @@ -7921,11 +5862,10 @@ void ivas_filters_init( #ifdef IVAS_FLOAT_FIXED void ivas_filters_init_fx( - ivas_filters_process_state_t *filter_state, /* i/o: filter state handle */ - const Word32 *filt_coeff, /* i : filter coefficients */ - const Word16 *filt_coeff_e, /* i : exponents of filter coefficients */ - const Word16 order /* i : filter order */ -); + ivas_filters_process_state_t *filter_state, /* i/o: filter state handle */ + const Word32 *filt_coeff_fx, /* i : filter coefficients Q31- *filt_coeff_e */ + const Word16 *filt_coeff_e, /* i : exponents of filter coefficients */ + const Word16 order ) ; #endif void ivas_filter_process( @@ -7936,30 +5876,21 @@ void ivas_filter_process( #ifdef IVAS_FLOAT_FIXED void ivas_filter_process_fx( - ivas_filters_process_state_t *filter_state, /* i/o: filter state handle */ - Word32 *pIn_Out_fx, /* i : signal subject to filtering */ - const Word16 length, /* i : filter order */ - Word16 q_factor -); + ivas_filters_process_state_t *filter_state, /* i/o: filter state handle */ + Word32 *pIn_Out_fx, /* i/o: signal subject to filtering Q(q_factor) */ + const Word16 length, /* i : filter order */ + Word16 q_factor ); #endif /*----------------------------------------------------------------------------------* * OSBA prototypes *----------------------------------------------------------------------------------*/ -#ifdef IVAS_FLOAT_FIXED -ivas_error ivas_osba_enc_open_fx( - Encoder_Struct *st_ivas /* i/o: IVAS encoder handle */ -); -#else +#ifndef IVAS_FLOAT_FIXED ivas_error ivas_osba_enc_open( Encoder_Struct *st_ivas /* i/o: IVAS encoder handle */ ); #endif -#ifdef IVAS_FLOAT_FIXED -void ivas_osba_enc_close_fx( - OSBA_ENC_HANDLE *hOSba /* i/o: encoder OSBA handle */ -); -#else +#ifndef IVAS_FLOAT_FIXED void ivas_osba_enc_close( OSBA_ENC_HANDLE *hOSba /* i/o: encoder OSBA handle */ ); @@ -7979,36 +5910,10 @@ void ivas_osba_enc( const int32_t input_Fs, /* i : input sampling rate */ const int16_t sba_planar /* i : planar SBA flag */ ); -#else -void ivas_osba_enc_fx( - OSBA_ENC_HANDLE hOSba, /* i/o: OSBA encoder handle */ - ISM_METADATA_HANDLE hIsmMeta[], /* i/o: ISM metadata handle */ - Word32 *data_in_fx[], /* i/o: Input / transport audio signals */ - const int16_t input_frame, /* i : Input frame size */ - const int16_t nchan_ism, /* i : Number of objects for parameter analysis */ - const ISM_MODE ism_mode, /* i : ISM mode */ - const int16_t sba_analysis_order, /* i : SBA order evaluated in DirAC/SPAR encoder */ - const int32_t input_Fs, /* i : input sampling rate */ - const int16_t sba_planar, /* i : planar SBA flag */ - Word16 *q_data - ); #endif ivas_error ivas_osba_data_open( Decoder_Struct *st_ivas /* i/o: IVAS decoder handle */ ); -#ifdef IVAS_FLOAT_FIXED -ivas_error ivas_osba_data_open_fx( - Decoder_Struct *st_ivas /* i/o: IVAS decoder handle */ -); -ivas_error ivas_osba_dirac_td_binaural_jbm_fx( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ - const UWord16 nSamplesAsked, /* i : number of CLDFB slots requested */ - UWord16 *nSamplesRendered, /* o : number of CLDFB slots rendered */ - UWord16 *nSamplesAvailable, /* o : number of CLDFB slots still to render */ - Word32 *output_fx[], /* o : rendered time signal */ - Word16 out_len/*Store the length of values in each channel*/ -); -#endif // IVAS_FLOAT_FIXED ivas_error ivas_osba_dirac_td_binaural_jbm( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ @@ -8018,14 +5923,7 @@ ivas_error ivas_osba_dirac_td_binaural_jbm( float *output_f[] /* o : rendered time signal */ ); -#ifdef IVAS_FLOAT_FIXED -ivas_error ivas_osba_ism_metadata_dec_fx( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ - const Word32 ism_total_brate, /* i : ISM total bitrate */ - Word16 *nchan_ism, /* o : number of ISM separated channels */ - Word16 nb_bits_metadata[] /* o : number of ISM metadata bits */ -); -#else +#ifndef IVAS_FLOAT_FIXED ivas_error ivas_osba_ism_metadata_dec( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ const int32_t ism_total_brate, /* i : ISM total bitrate */ @@ -8033,15 +5931,7 @@ ivas_error ivas_osba_ism_metadata_dec( int16_t nb_bits_metadata[] /* o : number of ISM metadata bits */ ); #endif -#ifdef IVAS_FLOAT_FIXED -ivas_error ivas_osba_render_sf_fx( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ - const UWord16 nSamplesAsked, /* i : number of CLDFB slots requested */ - UWord16 *nSamplesRendered, /* o : number of CLDFB slots rendered */ - UWord16 *nSamplesAvailableNext, /* o : number of CLDFB slots still to render */ - Word32 *p_output[] /* o : rendered time signal */ -); -#else +#ifndef IVAS_FLOAT_FIXED ivas_error ivas_osba_render_sf( Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ const uint16_t nSamplesAsked, /* i : number of CLDFB slots requested */ @@ -8050,11 +5940,7 @@ ivas_error ivas_osba_render_sf( float *output_f[] /* o : rendered time signal */ ); #endif -#ifdef IVAS_FLOAT_FIXED -void ivas_osba_data_close_fx( - SBA_ISM_DATA_HANDLE *hSbaIsmData /* i/o: OSBA rendering handle */ -); -#endif + void ivas_osba_data_close( SBA_ISM_DATA_HANDLE *hSbaIsmData /* i/o: OSBA rendering handle */ ); @@ -8122,16 +6008,6 @@ void ivas_set_surplus_brate_dec( int32_t *ism_total_brate /* i : ISM total bitrate */ ); -#ifdef IVAS_FLOAT_FIXED -void ivas_set_ism_importance_interformat_fx( - const Word32 ism_total_brate, /* i/o: ISms total bitrate */ - const Word16 nchan_transport, /* i : number of transported channels */ - ISM_METADATA_HANDLE hIsmMeta[], /* i/o: ISM metadata handles */ - SCE_ENC_HANDLE hSCE[], /* i/o: SCE encoder handles */ - const Word16 lp_noise_CPE_fx, /* i : LP filtered total noise estimation */ - Word16 ism_imp[] /* o : ISM importance flags */ -); -#endif void ivas_set_ism_importance_interformat( const int32_t ism_total_brate, /* i/o: ISms total bitrate */ @@ -8235,16 +6111,7 @@ void ivas_omasa_dirac_rend_jbm( float *output_f[] /* o : rendered time signal */ ); #endif -#ifdef IVAS_FLOAT_FIXED -void ivas_omasa_preProcessStereoTransportsForMovedObjects_fx( - Decoder_Struct *st_ivas, - Word32 inRe_fx[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], /*cldfb_buf_q*/ - Word32 inIm_fx[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], /*cldfb_buf_q*/ - Word16 *cldfb_buf_q, - const Word16 nBins, - const Word16 subframe -); -#endif + void ivas_omasa_preProcessStereoTransportsForMovedObjects( Decoder_Struct *st_ivas, float inRe[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], @@ -8286,15 +6153,6 @@ void ivas_omasa_decode_masa_to_total( const int16_t nblocks ); -#ifdef IVAS_FLOAT_FIXED -void ivas_omasa_decode_masa_to_total_fx( - UWord16 *bit_stream, - Word16 *index, - Word32 masa_to_total_energy_ratio_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], - const Word16 nbands, - const Word16 nblocks); -#endif - void ivas_omasa_modify_masa_energy_ratios( IVAS_QMETADATA_HANDLE hQMetaData, /* i/o: q_metadata handle */ float masa_to_total_energy_ratio[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_MAXIMUM_CODING_SUBBANDS] @@ -8304,26 +6162,12 @@ void ivas_omasa_modify_masa_energy_ratios( /*----------------------------------------------------------------------------------* * TD Binaural Object renderer *----------------------------------------------------------------------------------*/ -#ifdef IVAS_FLOAT_FIXED -ivas_error ivas_td_binaural_open_fx( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ - Word16 * SrcInd, /*Temporarily used to store the updated value of SrcInd*/ - Word16 *num_src -); -#else +#ifndef IVAS_FLOAT_FIXED ivas_error ivas_td_binaural_open( Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ ); #endif // IVAS_FLOAT_FIXED -#ifdef IVAS_FLOAT_FIXED -ivas_error ivas_td_binaural_renderer_fx( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ - Word32 *output[], /* i/o: SCE channels / Binaural synthesis */ - const Word16 output_frame /* i : output frame length */ -); -#endif - ivas_error ivas_td_binaural_renderer( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ float *output[], /* i/o: SCE channels / Binaural synthesis */ @@ -8357,15 +6201,6 @@ ivas_error ivas_FB_mixer_open( const int16_t spar_reconfig_flag /* i : SPAR reconfiguration flag */ ); -#ifdef IVAS_FLOAT_FIXED -void ivas_FB_mixer_close_fx( - IVAS_FB_MIXER_HANDLE *hFbMixer, /* i/o: FB mixer handle */ - const Word32 sampling_rate, /* i : sampling rate in Hz */ - const Word16 spar_reconfig_flag /* i : SPAR reconfiguration flag */ -); - -#endif - void ivas_FB_mixer_close( IVAS_FB_MIXER_HANDLE *hFbMixer, /* i/o: FB mixer handle */ const int32_t sampling_rate, /* i : sampling rate in Hz */ @@ -8379,16 +6214,6 @@ void ivas_fb_mixer_pcm_ingest( const int16_t frame_length, /* i : frame length */ const int16_t HOA_md_ind[IVAS_SPAR_MAX_CH] ); -#ifdef IVAS_FLOAT_FIXED -void ivas_fb_mixer_pcm_ingest_fx( - IVAS_FB_MIXER_HANDLE hFbMixer, /* i/o: FB mixer handle */ - Word32 *pcm_in[], /* i : input audio channels Qq_data_fix[] */ - Word32 **ppOut_pcm, /* o : output audio channels Qq_ppOut_pcm[] */ - const Word16 frame_len, /* i : frame length */ - const Word16 HOA_md_ind[IVAS_SPAR_MAX_CH], - Word16 q_data_fix[MAX_INPUT_CHANNELS + MAX_NUM_OBJECTS], - Word16 *q_ppOut_pcm ); -#endif void ivas_fb_mixer_update_prior_input( IVAS_FB_MIXER_HANDLE hFbMixer, /* i/o: FB mixer handle */ @@ -8407,17 +6232,7 @@ void ivas_fb_mixer_get_windowed_fr( const int16_t nchan_fb_in /* i : number of analysis channels */ ); -#ifdef IVAS_FLOAT_FIXED -void ivas_fb_mixer_process( - IVAS_FB_MIXER_HANDLE hFbMixer, /* i/o: FB mixer handle */ - Word32 ***mixer_mat_fx, /* i : mixer matrix in q_mixer_mat_fx */ - Word16 *q_mixer_mat_fx, /* i : mixer matrix */ - Word32 **ppOut_pcm_fx, /* o : output audio channels in ppOut_pcm_fx resultant */ - Word16 *q_ppOut_pcm_fx, /*ppOut_pcm_fx resultant q*/ - const int16_t frame_len, /* i : frame length in samples */ - int16_t in_out_mixer_map[IVAS_MAX_FB_MIXER_OUT_CH][IVAS_MAX_SPAR_FB_MIXER_IN_CH] /* i/o: mixing mapping */ -); -#else +#ifndef IVAS_FLOAT_FIXED void ivas_fb_mixer_process( IVAS_FB_MIXER_HANDLE hFbMixer, /* i/o: FB mixer handle */ float ***mixer_mat, /* i : mixer matrix */ @@ -8442,49 +6257,12 @@ void ivas_fb_mixer_cross_fading( ); /*! r: number of spectral bands */ -#ifdef IVAS_FLOAT_FIXED -Word16 ivas_get_num_bands_from_bw_idx( - const Word16 bwidth /* i : audio bandwidth */ -); -#else +#ifndef IVAS_FLOAT_FIXED int16_t ivas_get_num_bands_from_bw_idx( const int16_t bwidth /* i : audio bandwidth */ ); #endif -#ifdef IVAS_FLOAT_FIXED -/*to be moved to prot_fx1.h*/ -void sns_avq_dec_fx( - Word16 *index, /* i : Quantization indices */ - Word32 SNS_Q[NB_DIV][M], /* o : Quantized SNS vectors */ - Word16 *q_snsq, - const Word16 L_frame, /* i : frame length */ - const Word16 numlpc /* i : Number of sets of lpc */ -); - -void sns_avq_dec_stereo_fx( - Word16 *indexl, /* i : Quantization indices (left channel) */ - Word16 *indexr, /* i : Quantization indices (right channe) */ - const Word16 L_frame, /* i : frame length */ - Word32 *SNS_Ql, /* o : Quantized SNS vectors (left channel) */ - Word16 *q_l, - Word32 *SNS_Qr, /* o : Quantized SNS vectors (right channe) */ - Word16 *q_r ); - -void dequantize_sns_fx( - Word16 indices[CPE_CHANNELS][NPRM_LPC_NEW], - Word32 snsQ_out[CPE_CHANNELS][NB_DIV][M], - Decoder_State **sts ); - -void inverseMS_fx( - const Word16 L_frame, /* i : frame length Q0*/ - Word32 x0[], /* i/o: mid/left channel coefficients Qx*/ - Word32 x1[], /* i/o: side/right channel coefficients Qx*/ - const Word32 norm_fac /* i : normalization factor Q31*/ -); - -#endif - /* clang-format on */ #endif /* IVAS_PROT_H */ diff --git a/lib_com/ivas_prot_fx.h b/lib_com/ivas_prot_fx.h index 4a0e4ddb1..3123d4475 100644 --- a/lib_com/ivas_prot_fx.h +++ b/lib_com/ivas_prot_fx.h @@ -121,8 +121,8 @@ Word16 valid_ratio_index_fx( ); UWord16 index_theta_phi_16_fx( - Word32 *p_theta, /* i/o: input elevation to be indexed */ - Word32 *p_phi, /* i/o: input azimuth to be indexed */ + Word32 *p_theta, /* i/o: input elevation to be indexed Q22 */ + Word32 *p_phi, /* i/o: input azimuth to be indexed Q22 */ const SPHERICAL_GRID_DATA *gridData /* i : generated grid data */ ); @@ -138,7 +138,6 @@ void ivas_omasa_rearrange_channels_fx( const Word16 output_frame /* i : output frame length per channel */ ); -#ifdef IVAS_FLOAT_FIXED ivas_error ivas_omasa_ism_metadata_dec_fx( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ const Word32 ism_total_brate, /* i : ISM total bitrate */ @@ -159,7 +158,6 @@ ivas_error ivas_td_binaural_renderer_sf_fx( Word32 *output_fx[], /* i/o: SCE channels / Binaural synthesis */ const Word16 n_samples_granularity /* i : granularity of the renderer/buffer */ ); -#endif void ivas_omasa_modify_masa_energy_ratios_fx( IVAS_QMETADATA_HANDLE hQMetaData, /* i/o: q_metadata handle */ @@ -186,46 +184,46 @@ ivas_error ivas_jbm_dec_tc_buffer_open_fx( ); void ivas_dct_windowing_fx( - const Word16 fade_len, - const Word16 full_len, - const Word16 dct_len, - const Word16 zero_pad_len, - const Word32 *pWindow_coeffs, - const Word16 frame_len, - Word32 *pOut_buf, - Word32 *pBuffer_prev, + const Word16 fade_len, /*Q0*/ + const Word16 full_len, /*Q0*/ + const Word16 dct_len, /*Q0*/ + const Word16 zero_pad_len, /*Q0*/ + const Word32 *pWindow_coeffs, /*Q31*/ + const Word16 frame_len, /*Q0*/ + Word32 *pOut_buf, // Q10 + Word32 *pBuffer_prev, // Q10 Word32 *pTemp_lfe ); void ivas_get_twid_factors_fx1( - const Word16 length, - const Word16 **pTwid_re, + const Word16 length, // Q0 + const Word16 **pTwid_re, // Q15 const Word16 **pTwid_im ); Word32 ivas_get_mdct_scaling_gain_fx( const Word16 dct_len_by_2 ); void ivas_imdct_fx( - const Word32 *pIn, - Word32 *pOut, - const Word16 length, + const Word32 *pIn, // Q24 + Word32 *pOut, // q_out Q9 + const Word16 length /*Q0*/, Word16 *q_out ); void ivas_mdct_fx( - const Word32 *pIn, - Word32 *pOut, - const Word16 length, + const Word32 *pIn, // q_out + Word32 *pOut, // q_out + const Word16 length, // Q0 Word16 *q_out ); void ivas_itda_fx( - const Word32 *re, /* i : time alised signal after IDCT */ + const Word32 *re, /* i : time alised signal after IDCT Q24 */ Word32 *pOut, /* o : time domain buffer of size 2*length */ - const Word16 length /* i : length of time alised signal buffer */ + const Word16 length /* i : length of time alised signal buffer Q0 */ ); void ivas_tda_fx( - const Word32 *pIn, /* i : time domain buffer of size 2*length */ - Word32 *pOut, /* o : time domain buffer of size length */ - const Word16 length /* i : length of time alised signal buffer */ + const Word32 *pIn, /* i : time domain buffer of size 2*length Q10*/ + Word32 *pOut, /* o : time domain buffer of size length Q10 */ + const Word16 length /* i : length of time alised signal buffer Q0*/ ); // ivas_agc_dec_fx.c @@ -253,7 +251,6 @@ void ivas_agc_read_bits_fx( const Word16 AGC_flag /* i : AGC on/off flag */ ); -#ifdef IVAS_FLOAT_FIXED // ivas_agc_com_fx.c void ivas_agc_initWindowFunc_fx( Word16 *pWinFunc, @@ -285,7 +282,6 @@ void ECSQ_decode( ECSQ_instance *ecsq_inst, const Word16 N, Word16 *output ); -#endif // IVAS_FLOAT_FIXED // bass_psfilter.c Word16 res_bpf_adapt_fx( @@ -447,7 +443,6 @@ Word16 get_igf_startline( const Word16 L_frameTCX /* i : full band frame length */ ); -#ifdef IVAS_FLOAT_FIXED void stereo_dft_dec_reset_fx( STEREO_DFT_DEC_DATA_HANDLE hStereoDft /* i/o: decoder DFT stereo handle */ ); @@ -503,8 +498,6 @@ void stereo_dft_generate_res_pred_fx( const Word16 bfi /* i : BFI flag */ ); -#endif - void stereo_dft_dec_analyze_fx( CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ const Word32 *input_fx, /* i : input signal */ @@ -565,10 +558,8 @@ void ivas_sba_config_fx( Word16 *element_mode /* o : element mode of the core coder */ ); -#ifdef IVAS_FLOAT_FIXED Word16 ivas_get_bits_to_encode( Word32 val ); -#endif Word16 ivas_get_spar_table_idx_fx( const Word32 ivas_total_brate, /* i : IVAS total bitrate */ @@ -613,7 +604,6 @@ void ivas_ism_param_dec_tc_gain_ajust_fx( Word16 *Q_tc /* i/o : Q of input tc buffer */ ); -#ifdef IVAS_FLOAT_FIXED /*! r: number of bits read */ Word16 read_GR0( const UWord16 *bit_stream, /* i : bitstream to be read */ @@ -667,12 +657,12 @@ Word16 read_flag_EC_DFT( const UWord16 *bit_stream, /* i : bitstream */ Word16 *flag /* o : flag value */ ); -#ifdef IVAS_FLOAT_FIXED + /*file : ivas_mc_param_dec_fx.c*/ Word16 param_mc_get_num_cldfb_syntheses_ivas_fx( Decoder_Struct *st_ivas /* i : Parametric MC handle */ ); -#endif + void ivas_init_dec_get_num_cldfb_instances( Decoder_Struct *st_ivas, /* i : IVAS decoder structure */ Word16 *numCldfbAnalyses, /* o : number of CLDFB analysis instances */ @@ -684,7 +674,6 @@ void ivas_init_dec_get_num_cldfb_instances_ivas_fx( Word16 *numCldfbAnalyses, /* o : number of needed CLDFB analysis instances */ Word16 *numCldfbSyntheses /* o : number of needed CLDFB synthesis instances */ ); -#endif Word16 masa_sq_fx( const Word32 in, /* i : input value */ @@ -756,8 +745,8 @@ void ivas_get_ism_sid_quan_bitbudget_fx( const Word16 nchan_ism, /* i : number of objects */ Word16 *nBits_azimuth, /* o : number of Q bits for azimuth */ Word16 *nBits_elevation, /* o : number of Q bits for elevation */ - Word32 *q_step_fx, /* o : quantization step */ - Word32 *q_step_border_fx, /* o : quantization step at the border */ + Word32 *q_step_fx, /* o : quantization step Q22*/ + Word32 *q_step_border_fx, /* o : quantization step at the border Q22*/ Word16 *nBits_coh, /* o : number of Q bits for coherence */ Word16 *nBits_sce_id /* o : number of Q bits for sce_id_dtx */ ); @@ -775,7 +764,6 @@ void ivas_ism_metadata_sid_dec_fx( Word16 nb_bits_metadata[] /* o : number of metadata bits */ ); -#ifdef IVAS_FLOAT_FIXED // ivas_sce_dec_fx.c ivas_error create_sce_dec( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ @@ -827,7 +815,6 @@ void ivas_post_proc_fx( const Word16 output_frame, /* i : output frame length */ const Word16 sba_dirac_stereo_flag, /* i : signal stereo output for SBA DirAC */ Word16 output_q ); -#endif // ivas_lfe_dec_fx.c @@ -1215,11 +1202,9 @@ void stereo_dft_dec_fx( ); // ivas_stereo_dft_enc.c -#ifdef IVAS_FLOAT_FIXED Word32 stereo_dft_enc_synthesize_fx( STEREO_DFT_ENC_DATA_HANDLE hStereoDft, /* i/o: encoder stereo handle */ - // float *output, /* o : output synthesis */ - Word32 *output_fx, /* o : output synthesis Q16 */ + Word32 *output_fx, /* o : output synthesis Q16 */ Word16 *output_start_index, Word16 *output_end_index, const Word16 chan, /* i : channel number */ @@ -1227,7 +1212,6 @@ Word32 stereo_dft_enc_synthesize_fx( const Word32 output_sampling_rate, /* i : output sampling rate */ const Word16 L_frame, /* i : frame length at internal Fs */ Word16 *nrg_out_fx_e ); -#endif void ivas_ls_setup_conversion_fx( Decoder_Struct *st_ivas, /* i : IVAS decoder structure */ @@ -2056,13 +2040,10 @@ Word16 is_DTXrate( const Word32 ivas_total_brate /* i : IVAS total bitrate */ ); -#ifdef IVAS_FLOAT_FIXED Word16 ivas_qmetadata_dereorder_generic( const UWord16 uns_value /* i : unsigned value result of ReorderGeneric */ ); -#endif -#ifdef IVAS_FLOAT_FIXED void update_bits_next_block( IVAS_QDIRECTION *q_direction, /* i/o: qdirection */ Word16 *p_diff, /* i/o: bits to be transferred */ @@ -2070,17 +2051,15 @@ void update_bits_next_block( const Word16 max_i, /* i : number of subbands */ const Word16 max_k /* i : n umber of subframes */ ); -#endif UWord32 ivas_syn_output_fx( - Word32 *synth[], /* i/o: float synthesis signal */ + Word32 *synth[], /* i/o: Word32 synthesis signal */ const Word16 q_synth, const Word16 output_frame, /* i : output frame length (one channel) */ const Word16 n_channels, /* i : number of output channels */ Word16 *synth_out /* o : integer 16 bits synthesis signal */ ); -#ifdef IVAS_FLOAT_FIXED void stereo_tcx_core_dec_fx( Decoder_State *st, /* i/o: decoder state structure */ const FRAME_MODE frameMode, /* i : Decoder frame mode */ @@ -2095,7 +2074,6 @@ void stereo_tcx_core_dec_fx( const Word16 nchan_out, /* i : number of output channels */ const IVAS_FORMAT ivas_format /* i : IVAS format */ ); -#endif // IVAS_FLOAT_FIXED void masa_compensate_two_dir_energy_ratio_index_fx( const Word16 ratio_index_1, /* i : Input ratio for direction 1 */ @@ -2105,17 +2083,14 @@ void masa_compensate_two_dir_energy_ratio_index_fx( const Word16 hodirac_flag /* i : flag to indicate HO-DirAC mode */ ); -#ifdef IVAS_FLOAT_FIXED -int16_t stereo_tdm_ener_analysis_fx( +Word16 stereo_tdm_ener_analysis_fx( const Word16 ivas_format, /* i : IVAS format */ CPE_ENC_HANDLE hCPE, /* i : CPE structure */ const Word16 input_frame, /* i : Number of samples */ Word16 *tdm_SM_or_LRTD_Pri, /* o : channel combination scheme flag in TD stereo OR LRTD primary channel */ Word16 *tdm_ratio_idx_SM /* o : TDM ratio index for SM mode */ ); -#endif -#ifdef IVAS_FLOAT_FIXED /*! r: projected azimuth index */ Word16 ivas_dirac_project_azimuth_index( const Word16 az_idx, /* i : azimuth index */ @@ -2142,7 +2117,7 @@ void small_reduction_direction( UWord16 bits_dir[MASA_MAXIMUM_CODING_SUBBANDS][MAX_PARAM_SPATIAL_SUBFRAMES], const Word16 raw_flag[MASA_MAXIMUM_CODING_SUBBANDS], Word16 *diff ); -#endif + void sort_desc_ind_16_fx( Word16 *s, /* i/o: vector to be sorted Qx*/ @@ -2165,9 +2140,9 @@ ivas_error only_reduce_bits_direction_fx( Word16 *ind_order ); void ivas_qmetadata_azimuth_elevation_to_direction_vector_fx( - const Word32 az, /* i : azimuth */ - const Word32 el, /* i : elevation */ - Word32 *dv /* o : direction vector */ + const Word32 az, /* i : azimuth Q22 */ + const Word32 el, /* i : elevation Q22 */ + Word32 *dv /* o : direction vector Q30 */ ); void ivas_qmetadata_direction_vector_to_azimuth_elevation_fx( @@ -2177,7 +2152,6 @@ void ivas_qmetadata_direction_vector_to_azimuth_elevation_fx( Word32 *el /* o : elevation */ ); -#ifdef IVAS_FLOAT_FIXED ivas_error ivas_qmetadata_open( IVAS_QMETADATA_HANDLE *hQMetaData /* i/o: q_metadata handle */ ); @@ -2281,7 +2255,6 @@ void stereo_dtf_cng_fx( Word16 q_dft /* i : Q factor of the DFT data */ ); -#endif // IVAS_FLOAT_FIXED void ivas_spar_update_md_hist_fx( ivas_spar_md_dec_state_t *hMdDec /* i/o: SPAR MD decoder handle */ @@ -2627,12 +2600,12 @@ Word16 calculate_brate_limit_flag_fx( const Word16 nchan_ism /* i : number of objects */ ); Word16 ism_quant_meta_fx( - const Word32 val, /* i : scalar value to quantize */ - Word32 *valQ, /* o : quantized value */ - const Word32 borders_fx[], /* i : level borders */ - const Word32 q_step_fx, /* i : quantization step */ - const Word32 q_step_border_fx, /* i : quantization step at the border */ - const Word16 cbsize /* i : codebook size */ + const Word32 val, /* i : scalar value to quantize Q22 */ + Word32 *valQ, /* o : quantized value Q22 */ + const Word32 borders_fx[], /* i : level borders Q22 */ + const Word32 q_step_fx, /* i : quantization step Q22 */ + const Word32 q_step_border_fx, /* i : quantization step at the border Q22 */ + const Word16 cbsize /* i : codebook size */ ); /*! r: number of channels to be analysed */ @@ -2690,30 +2663,30 @@ void ivas_ari_encode_14bits_ext_fx( void ms_inv_mask_processing_fx( STEREO_MDCT_ENC_DATA_HANDLE hStereoMdct, /* i/o: MDCT encoder structure */ Encoder_State **sts, /* i/o: Encoder state structure */ - int16_t ms_mask[NB_DIV][MAX_SFB], /* i : bandwise MS mask */ - const int16_t iSubframe, /* i : subframe number */ + Word16 ms_mask[NB_DIV][MAX_SFB], /* i : bandwise MS mask */ + const Word16 iSubframe, /* i : subframe number */ const Word32 x_0_fx[], /* i : spectrum 1 */ const Word32 x_1_fx[], /* i : spectrum 2 */ Word32 x_inv_0_fx[], /* o : inverse spectrum 1 */ Word32 x_inv_1_fx[], /* o : inverse spectrum 2 */ - int16_t maxSfb /* i : number of stereo frequency bands */ + Word16 maxSfb /* i : number of stereo frequency bands */ ); void ms_processing_fx( STEREO_MDCT_ENC_DATA_HANDLE hStereoMdct, /* i/o: Stereo MDCT encoder structure */ Encoder_State **sts, /* i/o: Encoder state structure */ Word16 ms_mask[NB_DIV][MAX_SFB], /* i : bandwise MS mask */ - const int16_t iSubframe, /* i : subframe number */ + const Word16 iSubframe, /* i : subframe number */ Word32 x_0_fx[], /* i/o: spectrum 1 */ Word32 x_1_fx[], /* i/o: spectrum 1 */ Word16 maxSfb /* i : number of stereo frequency bands*/ ); void convertToMS_fx( - const int16_t L_frame, /* i : frame length */ - Word32 x0[], /* i/o: mid/left channel coefficients */ - Word32 x1[], /* i/o: side/right channel coefficients */ - const Word32 norm_fac /* i : normalization factor */ + const Word16 L_frame, /* i : frame length */ + Word32 x0[], /* i/o: mid/left channel coefficients */ + Word32 x1[], /* i/o: side/right channel coefficients */ + const Word32 norm_fac /* i : normalization factor */ ); void FindSplitRatio_fx( @@ -3094,19 +3067,6 @@ void InternalTCXDecoder_fx( Word16 *gain_tcx_q /* o : quantized global gain (at low bitrates) */ ); -void stereo_tcx_core_enc( - Encoder_State *st, /* i/o: encoder state structure */ - const float new_samples_12k8[], /* i : buffer of input signal @12.8 kHz */ - const float new_samples_16k[], /* i : buffer of input signal @16 kHz */ - const Word16 Aw_fx[], /* i : weighted A(z) unquant. for subframes, Q12 */ - float lsp_new[], /* i : LSPs at the end of the frame, Q15 */ - float lsp_mid[], /* i : LSPs in the middle of the frame, Q15 */ - Word16 pitch_buf_fx[NB_SUBFR16k], /* o : pitch for each subframe, Q6 */ - const Word16 last_element_mode, /* i : last element mode, Q0 */ - const Word16 vad_hover_flag /* i : VAD hangover flag, Q0 */ -); - - Word16 transient_analysis_ivas_fx( TRAN_DET_HANDLE hTranDet, /* i : handle transient detection */ const Word16 cor_map_LT[], /* i : LT correlation map Q_cor_map = Qx */ @@ -3194,8 +3154,6 @@ void small_requantize_direction_frame_fx( Word16 bits_dir_bands[MASA_MAXIMUM_CODING_SUBBANDS], Word16 *diff ); -#ifdef IVAS_FLOAT_FIXED - void ivas_param_ism_stereo_dmx_fx( Encoder_Struct *st_ivas, /* i : IVAS encoder structure */ Word32 *data[MAX_NUM_OBJECTS], /* i/o: input signal/stereo dmx Qx */ @@ -3207,7 +3165,6 @@ void ivas_param_ism_enc_fx( Word32 *data[MAX_NUM_OBJECTS], /* i : input signal q_pcm_in */ const Word16 input_frame, /* i : input frame length per channel */ const Word16 q_pcm_in ); -#endif ISM_MODE ivas_ism_mode_select( const Word16 nchan_inp, /* i : number of input objects */ @@ -3226,9 +3183,9 @@ void ivas_fb_mixer_get_windowed_fr_fx( Word32 *pcm_in_fx[], Word32 *frame_f_real_fx[], Word32 *frame_f_imag_fx[], - const int16_t length, /* i : number of new samples in time slot */ - const int16_t mdft_len, /* i : MDFT frame length */ - const int16_t nchan_fb_in, /* i : number of analysis channels */ + const Word16 length, /* i : number of new samples in time slot */ + const Word16 mdft_len, /* i : MDFT frame length */ + const Word16 nchan_fb_in, /* i : number of analysis channels */ Word16 gb ); void ivas_omasa_set_config_fx( OMASA_ENC_HANDLE hOMasa, /* i/o: OMASA encoder handle */ @@ -3547,4 +3504,2211 @@ ivas_error ivas_masa_encode_fx( const Word16 ism_imp, /* i : importance of separated object */ const Word16 flag_omasa_ener_brate /* i : less bitrate for objects in OMASA flag */ ); + +void ivas_write_format_sid_fx( + const IVAS_FORMAT ivas_format, /* i : IVAS format */ + const Word16 element_mode, /* i : element bitrate */ + BSTR_ENC_HANDLE hBstr /* i/o: encoder bitstream handle */ +); + +void ivas_write_format_fx( /* i/o: IVAS encoder structure */ + Encoder_Struct *st_ivas ); + +ivas_error create_sce_enc_fx( + Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ + const Word16 sce_id, /* i : SCE # identifier */ + const Word32 element_brate /* i : element bitrate */ +); + +ivas_error create_cpe_enc_fx( + Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ + const Word16 cpe_id, /* i : CPE # identifier */ + const Word32 element_brate /* i : element bitrate */ +); + +void ivas_quantise_real_values_fx( + const Word32 *values_fx, + const Word16 q_levels, + const Word32 min_value_fx, + const Word32 max_value_fx, + Word16 *index, + Word32 *quant_fx, + const Word16 dim ); + +void ivas_quantise_real_values_enc_fx( + const Word32 *values_fx, // Q28 + const Word16 q_levels, + const Word32 min_value_fx, // Q28 + const Word32 max_value_fx, // Q28 + Word16 *index, + Word32 *quant_fx, // Q28 + const Word16 dim ); + +void ivas_quantise_real_values_enc_fx_varq( + const Word32 *values_fx, + const Word16 q_levels, + const Word32 min_value_fx, + const Word32 max_value_fx, + Word16 *index, + Word32 *quant_fx, + const Word16 dim, + Word16 inp_q ); + +void ivas_spar_quant_dtx_init_fx( + ivas_spar_md_t *spar_md, + Word32 *min_max ); + +void ivas_spar_quant_dtx_init_fx( + ivas_spar_md_t *spar_md, + Word32 *min_max ); + +void ivas_copy_band_coeffs_idx_to_arr( + ivas_band_coeffs_ind_t *pBands_idx, + const Word16 nB, + Word16 *pSymbol_re, + ivas_cell_dim_t *pCell_dims, + const ivas_coeffs_type_t coeff_type ); + +void ivas_clear_band_coeffs_fx( + ivas_band_coeffs_t *pband_coeffs, + const UWord16 num_bands ); + +Word16 ivas_qmetadata_DecodeExtendedGR( + UWord16 *bitstream, + Word16 *index, + const Word16 alph_size, + const Word16 gr_param ); + +void ivas_masa_combine_directions_fx( + MASA_ENCODER_HANDLE hMasa /* i/o: MASA encoder handle */ +); + +/*! r: Bits to be used for quantizing distribution ratio of direct-to-total ratios */ +Word16 ivas_get_df_ratio_bits_hodirac( + const Word16 index_diff /* i : index of quantized diffuse-to-total ratio */ +); + +/*! r: Bits to be used for quantizing distribution ratio of direct-to-total ratios */ +Word16 ivas_get_df_ratio_bits( + const Word16 index_diff /* i : index of quantized diffuse-to-total ratio */ +); + +void invdct4_transform_fx( + Word32 *v_fx, /* i : input vector */ + UWord8 *invdct_v, /* o : transformed vector */ + Word16 q ); + +void ivas_spar_param_to_masa_param_mapping_fx( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder struct */ + Word32 inRe_fx[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], /* i : Input audio in CLDFB domain, real */ + Word32 inIm_fx[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], /* i : Input audio in CLDFB domain, imag */ + Word16 q_cldfb[6][CLDFB_SLOTS_PER_SUBFRAME], + const Word16 subframe /* i : Subframe to map */ +); + +ivas_error ivas_binRenderer_open_fx( + Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ +); + +void ivas_binRenderer_close_fx( + BINAURAL_RENDERER_HANDLE *hBinRenderer /* i/o: decoder binaural renderer handle */ +); + +void ivas_init_binaural_hrtf_fx( + HRTFS_FASTCONV *HrtfFastConv /* i/o: FASTCONV HRTF structure */ +); + +ivas_error ivas_allocate_binaural_hrtf_fx( + HRTFS_FASTCONV *HrtfFastConv, /* i/o: FASTCONV HRTF structure */ + const AUDIO_CONFIG input_config, /* i : input audio configuration */ + const BINAURAL_INPUT_AUDIO_CONFIG bin_input_config, /* i : binaural input audio config */ + const RENDERER_TYPE renderer_type, /* i : renderer type */ + const Word16 allocate_init_flag /* i : Memory allocation flag */ +); + +void ivas_binRenderer_fx( + BINAURAL_RENDERER_HANDLE hBinRenderer, /* i/o: binaural renderer handle */ + COMBINED_ORIENTATION_HANDLE hCombinedOrientationData, /* i : combined head and external orientation handle*/ + const Word16 numTimeSlots, /* i : number of time slots to render */ + Word32 Cldfb_RealBuffer_Binaural_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* o : Binaural signals */ + Word32 Cldfb_ImagBuffer_Binaural_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* o : Binaural signals */ + Word32 RealBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* i : LS signals */ + Word32 ImagBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* i : LS signals */ + Word16 *Q_in /* i : LS signals exp */ +); + +void ivas_binaural_add_LFE_fx( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + Word16 output_frame, /* i : length of input frame */ + Word32 *input_fx[], /* i : transport channels */ + Word32 *output_fx[] /* o : synthesized core-coder transport channels/DirAC output */ +); + +void ivas_mc2sba_fx( + IVAS_OUTPUT_SETUP hIntSetup, /* i : Format of decoder output */ + Word32 *in_buffer_td[], /* i : MC signals (on input) and the HOA3 (on output) */ + Word32 *buffer_td[], /* i/o: MC signals (on input) and the HOA3 (on output) */ + const Word16 output_frame, /* i : output frame length per channel */ + const Word16 sba_order, /* i : Ambisonic (SBA) order */ + const Word16 gain_lfe /* i : gain for LFE, 0 = ignore LFE */ +); + +void ivas_param_mc_mc2sba_cldfb_fx( + IVAS_OUTPUT_SETUP hTransSetup, /* i : transported MC Format */ + Word32 *hoa_encoder, /* i : HOA3 encoder for the transported MC format */ + const Word16 slot_idx, /* i : current slot in the subframe */ + Word32 Cldfb_RealBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* i/o: Contains the MC signals (on input) and the HOA3 (on output) */ + Word32 Cldfb_ImagBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* i/o: Contains the MC signals (on input) and the HOA3 (on output) */ + const Word16 nBands, /* i : number of synth CLDFB bands */ + const Word16 gain_lfe /* i : gain applied to LFE */ +); + +void ivas_ism2sba_sf_fx( + Word32 *buffer_in_fx[], /* i : TC buffer */ + Word32 *buffer_out_fx[], /* o : TD signal buffers */ + ISM_RENDERER_HANDLE hIsmRendererData, /* i/o: renderer data */ + const Word16 num_objects, /* i : number of objects */ + const Word16 n_samples_to_render, /* i : output frame length per channel */ + const Word16 offset, /* i : offset for the interpolatr */ + const Word16 sba_order /* i : Ambisonic (SBA) order */ +); + +void panning_wrap_angles_fx( + const Word32 azi_deg, /* i : azimuth in degrees for panning direction (positive left) Q22 */ + const Word32 ele_deg, /* i : elevation in degrees for panning direction (positive up) Q22 */ + Word32 *azi_wrapped, /* o : wrapped azimuth component Q22 */ + Word32 *ele_wrapped /* o : wrapped elevation component Q22 */ +); + +void v_sort_ind_fixed( + Word32 *x, /* i/o: Vector to be sorted */ + Word16 *idx, /* o : Original index positions */ + const Word16 len /* i : vector length */ +); + +void ivas_ls_setup_conversion_process_mdct_param_mc_fx( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + Word32 *x_fx[][NB_DIV], /* i/o: Fixed output synthesis signal */ + Word16 x_e[CPE_CHANNELS][NB_DIV] /* i/o: Exponent for output synthesis signal */ +); + +void lls_interp_n_fx( + Word16 x_fx[], /* i/o: input/output vector */ + const Word16 N, /* i : length of the input vector */ + Word16 *a_fx, /* o : calculated slope */ + Word16 *b_fx, /* o : calculated offset */ + const Word16 upd /* i : use 1 to update x[] with the interpolated output */ +); + +void ivas_lfe_synth_with_filters_fx( + MCMASA_LFE_SYNTH_DATA_HANDLE hMasaLfeSynth, /* i/o: LFE synthesis structure for McMASA */ + Word32 *data_f[], /* o : output signals */ + const Word16 output_frame, /* i : output frame length per channel */ + const Word16 separateChannelIndex, /* i : separate channel index */ + const Word16 lfeChannelIndex /* i : LFE channel index */ +); + +void ivas_lfe_enc_fx( + LFE_ENC_HANDLE hLFE, /* i/o: LFE encoder handle */ + Word32 data_lfe_ch[], /* i : input LFE signal */ + Word16 q_data_lfe_ch, /* i : Q of input LFE signal */ + const Word16 input_frame, /* i : input frame length per channel */ + BSTR_ENC_HANDLE hBstr /* i/o: bitstream handle */ +); + +void ivas_filter_process_fx( + ivas_filters_process_state_t *filter_state, /* i/o: filter state handle */ + Word32 *pIn_Out_fx, /* i : signal subject to filtering */ + const Word16 length, /* i : filter order */ + Word16 q_factor ); + +ivas_error ivas_osba_enc_open_fx( + Encoder_Struct *st_ivas /* i/o: IVAS encoder handle */ +); + +void ivas_osba_enc_close_fx( + OSBA_ENC_HANDLE *hOSba /* i/o: encoder OSBA handle */ +); + +void ivas_osba_enc_fx( + OSBA_ENC_HANDLE hOSba, /* i/o: OSBA encoder handle */ + ISM_METADATA_HANDLE hIsmMeta[], /* i/o: ISM metadata handle */ + Word32 *data_in_fx[], /* i/o: Input / transport audio signals */ + const Word16 input_frame, /* i : Input frame size */ + const Word16 nchan_ism, /* i : Number of objects for parameter analysis */ + const ISM_MODE ism_mode, /* i : ISM mode */ + const Word16 sba_analysis_order, /* i : SBA order evaluated in DirAC/SPAR encoder */ + const Word32 input_Fs, /* i : input sampling rate */ + const Word16 sba_planar, /* i : planar SBA flag */ + Word16 *q_data ); + +ivas_error ivas_osba_data_open_fx( + Decoder_Struct *st_ivas /* i/o: IVAS decoder handle */ +); +ivas_error ivas_osba_dirac_td_binaural_jbm_fx( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + const UWord16 nSamplesAsked, /* i : number of CLDFB slots requested */ + UWord16 *nSamplesRendered, /* o : number of CLDFB slots rendered */ + UWord16 *nSamplesAvailable, /* o : number of CLDFB slots still to render */ + Word32 *output_fx[], /* o : rendered time signal */ + Word16 out_len /*Store the length of values in each channel*/ +); + +ivas_error ivas_osba_ism_metadata_dec_fx( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + const Word32 ism_total_brate, /* i : ISM total bitrate */ + Word16 *nchan_ism, /* o : number of ISM separated channels */ + Word16 nb_bits_metadata[] /* o : number of ISM metadata bits */ +); + +ivas_error ivas_osba_render_sf_fx( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ + const UWord16 nSamplesAsked, /* i : number of CLDFB slots requested */ + UWord16 *nSamplesRendered, /* o : number of CLDFB slots rendered */ + UWord16 *nSamplesAvailableNext, /* o : number of CLDFB slots still to render */ + Word32 *p_output[] /* o : rendered time signal */ +); + +void ivas_osba_data_close_fx( + SBA_ISM_DATA_HANDLE *hSbaIsmData /* i/o: OSBA rendering handle */ +); + +void ivas_set_ism_importance_interformat_fx( + const Word32 ism_total_brate, /* i/o: ISms total bitrate */ + const Word16 nchan_transport, /* i : number of transported channels */ + ISM_METADATA_HANDLE hIsmMeta[], /* i/o: ISM metadata handles */ + SCE_ENC_HANDLE hSCE[], /* i/o: SCE encoder handles */ + const Word16 lp_noise_CPE_fx, /* i : LP filtered total noise estimation */ + Word16 ism_imp[] /* o : ISM importance flags */ +); + +void ivas_omasa_preProcessStereoTransportsForMovedObjects_fx( + Decoder_Struct *st_ivas, + Word32 inRe_fx[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], /*cldfb_buf_q*/ + Word32 inIm_fx[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], /*cldfb_buf_q*/ + Word16 *cldfb_buf_q, + const Word16 nBins, + const Word16 subframe ); + + +void ivas_omasa_decode_masa_to_total_fx( + UWord16 *bit_stream, + Word16 *index, + Word32 masa_to_total_energy_ratio_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], + const Word16 nbands, + const Word16 nblocks ); + + +ivas_error ivas_td_binaural_open_fx( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + Word16 *SrcInd, /*Temporarily used to store the updated value of SrcInd*/ + Word16 *num_src ); + +ivas_error ivas_td_binaural_renderer_fx( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + Word32 *output[], /* i/o: SCE channels / Binaural synthesis */ + const Word16 output_frame /* i : output frame length */ +); + +void ivas_FB_mixer_close_fx( + IVAS_FB_MIXER_HANDLE *hFbMixer, /* i/o: FB mixer handle */ + const Word32 sampling_rate, /* i : sampling rate in Hz */ + const Word16 spar_reconfig_flag /* i : SPAR reconfiguration flag */ +); + +void ivas_fb_mixer_pcm_ingest_fx( + IVAS_FB_MIXER_HANDLE hFbMixer, /* i/o: FB mixer handle */ + Word32 *pcm_in[], /* i : input audio channels Qq_data_fix[] */ + Word32 **ppOut_pcm, /* o : output audio channels Qq_ppOut_pcm[] */ + const Word16 frame_len, /* i : frame length */ + const Word16 HOA_md_ind[IVAS_SPAR_MAX_CH], + Word16 q_data_fix[MAX_INPUT_CHANNELS + MAX_NUM_OBJECTS], + Word16 *q_ppOut_pcm ); + +void ivas_fb_mixer_process( + IVAS_FB_MIXER_HANDLE hFbMixer, /* i/o: FB mixer handle */ + Word32 ***mixer_mat_fx, /* i : mixer matrix in q_mixer_mat_fx */ + Word16 *q_mixer_mat_fx, /* i : mixer matrix */ + Word32 **ppOut_pcm_fx, /* o : output audio channels in ppOut_pcm_fx resultant */ + Word16 *q_ppOut_pcm_fx, /*ppOut_pcm_fx resultant q*/ + const Word16 frame_len, /* i : frame length in samples */ + Word16 in_out_mixer_map[IVAS_MAX_FB_MIXER_OUT_CH][IVAS_MAX_SPAR_FB_MIXER_IN_CH] /* i/o: mixing mapping */ +); + +Word16 ivas_get_num_bands_from_bw_idx( + const Word16 bwidth /* i : audio bandwidth */ +); + +void sns_avq_dec_fx( + Word16 *index, /* i : Quantization indices */ + Word32 SNS_Q[NB_DIV][M], /* o : Quantized SNS vectors */ + Word16 *q_snsq, + const Word16 L_frame, /* i : frame length */ + const Word16 numlpc /* i : Number of sets of lpc */ +); + +void sns_avq_dec_stereo_fx( + Word16 *indexl, /* i : Quantization indices (left channel) */ + Word16 *indexr, /* i : Quantization indices (right channe) */ + const Word16 L_frame, /* i : frame length */ + Word32 *SNS_Ql, /* o : Quantized SNS vectors (left channel) */ + Word16 *q_l, + Word32 *SNS_Qr, /* o : Quantized SNS vectors (right channe) */ + Word16 *q_r ); + +void dequantize_sns_fx( + Word16 indices[CPE_CHANNELS][NPRM_LPC_NEW], + Word32 snsQ_out[CPE_CHANNELS][NB_DIV][M], + Decoder_State **sts ); + +void inverseMS_fx( + const Word16 L_frame, /* i : frame length Q0*/ + Word32 x0[], /* i/o: mid/left channel coefficients Qx*/ + Word32 x1[], /* i/o: side/right channel coefficients Qx*/ + const Word32 norm_fac /* i : normalization factor Q31*/ +); + +void ivas_syn_output_f_fx( + Word32 *synth[], /* i/o: Word32 synthesis signal */ + const Word16 output_frame, /* i : output frame length (one channel) */ + const Word16 n_channels, /* i : number of output channels */ + Word32 *synth_out /* o : integer 16 bits synthesis signal */ +); + + +ivas_error ivas_init_encoder_fx( + Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ +); + +ivas_error ivas_output_buff_dec_fx( + Word32 *p_output_f[], /* i/o: output audio buffers */ + const Word16 nchan_out_buff_old, /* i : previous frame number of output channels */ + const Word16 nchan_out_buff /* i : number of output channels */ +); + +ivas_error ivas_dec_setup( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + UWord16 *nSamplesRendered, /* o : number of samples flushed from the previous frame (JBM) */ + Word16 *data /* o : output synthesis signal */ +); + +ivas_error create_mct_dec_fx( + Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ +); + +ivas_error mct_dec_reconfigure_fx( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + const UWord16 b_nchan_change /* i : flag indicating different channel count */ +); + +ivas_error ivas_corecoder_dec_reconfig_fx( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + const Word16 nSCE_old, /* i : number of SCEs in previous frame */ + Word16 nCPE_old, /* i : number of CPEs in previous frame */ + const Word16 nchan_transport_old, /* i : number of TCs in previous frame */ + const Word16 sba_dirac_stereo_flag_old, /* i : signal stereo rendering using DFT upmix in previous frame */ + const Word32 brate_SCE, /* i : bitrate to be set for the SCEs */ + const Word32 brate_CPE /* i : bitrate to be set for the CPEs */ +); + +ivas_error ivas_hp20_dec_reconfig_fx( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + const Word16 nchan_hp20_old /* i : number of HP20 filters in previous frame*/ +); + +Word16 getNumChanSynthesis( + Decoder_Struct *st_ivas /* i : IVAS decoder structure */ +); + +void ivas_destroy_dec_fx( + Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ +); + +ivas_error ivas_core_dec_fx( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + SCE_DEC_HANDLE hSCE, /* i/o: SCE decoder structure */ + CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ + MCT_DEC_HANDLE hMCT, /* i/o: MCT decoder structure */ + const Word16 n_channels, /* i : number of channels to be decoded */ + Word32 *output_fx[], /* o : output synthesis signal */ + Word32 outputHB[][L_FRAME48k], /* o : output HB synthesis signal */ + Word32 DFT_fx[CPE_CHANNELS][STEREO_DFT_BUF_MAX], /* o : DFT buffers */ + const Word16 sba_dirac_stereo_flag /* i : signal stereo output for SBA DirAC */ +); + +void decod_gen_2sbfr_ivas_fx( + Decoder_State *st, /* i/o: decoder static memory */ + const Word16 sharpFlag, /* i : formant sharpening flag `Q0*/ + const Word16 *Aq, /* i : LP filter coefficient Q12*/ + Word16 *pitch_buf, /* o : Word16 pitch values for each subframe Q6*/ + Word16 *voice_factors, /* o : voicing factors Q15*/ + Word16 *exc, /* i/o: adapt. excitation exc Q_exc*/ + Word16 *exc2, /* i/o: adapt. excitation/total exc Q_exc*/ + Word16 *bwe_exc, /* o : excitation for SWB TBE Q_exc*/ + Word16 *gain_buf, /* o : Word16 pitch gain for each subframe Q14*/ + const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag Q0*/ + const Word16 tdm_Pri_pitch_buf[] /* i : pitch values for primary channel Q6*/ +); + +Word16 ivas_smc_gmm_fx( + Encoder_State *st, /* i/o: state structure */ + STEREO_CLASSIF_HANDLE hStereoClassif, /* i/o: stereo classifier structure */ + const Word16 localVAD_HE_SAD, /* i : HE-SAD flag without hangover */ + const Word16 Etot_fx, /* i : total frame energy */ + Word16 lsp_new_fx[M], /* i : LSPs in current frame TODO:For now removing 'const' to avoid warning */ + Word16 cor_map_sum_fx, /* i : correlation map sum (from multi-harmonic anal.) */ + Word32 epsP_fx[M + 1], /* i : LP prediciton error TODO:For now removing 'const' to avoid warning */ + Word32 PS_fx[], /* i : energy spectrum TODO:For now removing 'const' to avoid warning */ + const Word16 non_sta_fx, /* i : unbound non-stationarity */ + const Word16 relE_fx, /* i : relative frame energy */ + Word16 *high_lpn_flag, /* i/o: sp/mus LPN flag */ + const Word16 flag_spitch /* i : flag to indicate very short stable pitch */ + , + Word16 Qfact_PS, + Word16 Q_esp, + Word16 Qfact_PS_past ); + +void ivas_signaling_enc_fx( + Encoder_State *st, /* i/o: encoder state structure */ + const Word16 MCT_flag, /* i : hMCT handle allocated (1) or not (0) */ + const Word32 element_brate, /* i : element bitrate */ + const Word16 tdm_SM_or_LRTD_Pri, /* i : channel combination scheme flag in TD stereo OR LRTD primary channel */ + const Word16 tdm_Pitch_reuse_flag /* i : primary channel pitch reuse flag in TD stereo */ +); + +void smooth_dft2td_transition_fx( + CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ + Word32 *output_fx[CPE_CHANNELS], /* i/o: synthesis @external Fs Q11*/ + const Word16 output_frame /* i : output frame lenght Q0*/ +); + + +Word16 is_IVAS_bitrate_fx( + const Word32 ivas_total_brate /* i : IVAS total bitrate */ +); + +void ivas_mdft_fx( + const Word32 *pIn, /* i : input time-domain signal Qin */ + Word32 *pOut_re, /* o : Real part of MDFT signal Qin */ + Word32 *pOut_im, /* o : Imag. part of MDFT signal Qin */ + const Word16 length, /* i : signal length */ + const Word16 mdft_length /* i : MDFT length */ +); + +void ivas_imdft_fx( + const Word32 *pRe, /* i : Real part of MDFT signal Qin */ + const Word32 *pIm, /* i : Imag. part of MDFT signal Qin */ + Word32 *pOut, /* o : output time-domain signal Qin */ + const Word16 length /* i : signal length */ +); + +void TonalMdctConceal_create_concealment_noise_ivas_fx( + Word32 concealment_noise[L_FRAME48k], + Word16 *concealment_noise_exp, + CPE_DEC_HANDLE hCPE, + const Word16 L_frameTCX, + const Word16 L_frame, + const Word16 idchan, + const Word16 subframe_idx, + const Word16 core, + const Word16 crossfade_gain, + const TONALMDCTCONC_NOISE_GEN_MODE noise_gen_mode ); + + +Word16 rand_triangular_signed_fx( + Word16 *seed, + Word16 *exp_fac ); + +Word64 var_32_fx( + const Word32 *x, /* i : input vector */ + const Word16 len, /* i : length of inputvector */ + Word16 q /* q : q-factor for the array */ +); + +ivas_error ivas_jbm_dec_tc_fx( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + Word32 *data_fx ); + +ivas_error ivas_jbm_dec_flush_renderer_fx( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + const Word16 tc_granularity_new, /* i : new renderer granularity */ + const RENDERER_TYPE renderer_type_old, /* i : old renderer type */ + const AUDIO_CONFIG intern_config_old, /* i : old internal config */ + const IVAS_OUTPUT_SETUP_HANDLE hIntSetupOld, /* i : old internal output setup */ + const MC_MODE mc_mode_old, /* i : old MC mode */ + const ISM_MODE ism_mode_old, /* i : old ISM mode */ + UWord16 *nSamplesRendered, /* o : number of samples flushed */ + Word16 *data /* o : output synthesis signal */ +); + +void ivas_jbm_dec_feed_tc_to_renderer_fx( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + const Word16 nSamplesForRendering, /* i : number of TC samples available for rendering */ + Word16 *nSamplesResidual, /* o : number of samples not fitting into the renderer grid and buffer for the next call*/ + Word32 *data /* i/o: transport channels/output synthesis signal */ +); + +void ivas_jbm_dec_feed_tc_to_renderer_fx( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + const Word16 nSamplesForRendering, /* i : number of TC samples available for rendering */ + Word16 *nSamplesResidual, /* o : number of samples not fitting into the renderer grid and buffer for the next call*/ + Word32 *data /* i/o: transport channels/output synthesis signal */ +); + +void ivas_jbm_dec_get_adapted_subframes( + const Word16 nCldfbTs, /* i : number of time slots in the current frame */ + Word16 *subframe_nbslots, /* i/o: subframe grid */ + Word16 *nb_subframes /* i/o: number of subframes in the frame */ +); + +void ivas_jbm_dec_get_md_map( + const Word16 default_len, /* i : default frame length in metadata slots */ + const Word16 len, /* i : length of the modfied frames in metadata slots */ + const Word16 subframe_len, /* i : default length of a subframe */ + const Word16 offset, /* i : current read offset into the md buffer */ + const Word16 buf_len, /* i : length of the metadata buffer */ + Word16 *map /* o : metadata index map */ +); + +void ivas_jbm_dec_get_md_map_even_spacing( + const Word16 len, /* i : length of the modfied frames in metadata slots */ + const Word16 subframe_len, /* i : default length of a subframe */ + const Word16 offset, /* i : current read offset into the md buffer */ + const Word16 buf_len, /* i : length of the metadata buffer */ + Word16 *map /* o : metadata index map */ +); + +void bitbudget_to_brate( + const Word16 x[], /* i : bitbudgets */ + Word32 y[], /* o : bitrates */ + const Word16 N /* i : number of entries to be converted */ +); + +Word16 ism_quant_meta_fx( + const Word32 val, /* i : scalar value to quantize */ + Word32 *valQ, /* o : quantized value */ + const Word32 borders_fx[], /* i : level borders */ + const Word32 q_step_fx, /* i : quantization step */ + const Word32 q_step_border_fx, /* i : quantization step at the border */ + const Word16 cbsize /* i : codebook size */ +); + +ivas_error ivas_set_ism_metadata_fx( + ISM_METADATA_HANDLE hIsmMeta, /* o : ISM metadata handle */ + const Word32 azimuth, /* i : azimuth value */ + const Word32 elevation, /* i : elevation value */ + const Word16 radius_meta, /* i : radius */ + const Word32 yaw, /* i : yaw */ + const Word32 pitch, /* i : pitch */ + const Word16 non_diegetic_flag /* i : non-diegetic object flag */ +); + +ivas_error ivas_ism_metadata_enc( + Word32 *ism_total_brate, /* i/o: ISM total bitrate */ + const Word16 nchan_ism, /* i : number of ISM channels */ + const Word16 nchan_transport, /* i : number of transport channels */ + ISM_METADATA_HANDLE hIsmMeta[], /* i/o: ISM metadata handles */ + SCE_ENC_HANDLE hSCE[], /* i/o: SCE encoder handles */ + BSTR_ENC_HANDLE hBstr, /* i/o: bitstream handle */ + Word16 nb_bits_metadata[], /* o : number of metadata bits */ + const Word16 localVAD[], /* i : VAD flag */ + const Word16 ism_mode, /* i : ISM mode */ + const PARAM_ISM_CONFIG_HANDLE hParamIsm, /* i : Param ISM Config Handle */ + const Word16 ism_extended_metadata_flag, /* i : Extended metadata flag */ + const Word16 lp_noise_CPE, /* i : LP filtered total noise estimation */ + const Word16 flag_omasa_ener_brate, /* i : less bitrate for objects in OMASA flag */ + Word16 *omasa_stereo_sw_cnt, + const Word16 ini_frame ); + +ivas_error ivas_ism_dec_config( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + const ISM_MODE last_ism_mode, /* i/o: last ISM mode */ + UWord16 *nSamplesRendered, /* o : number of samples flushed when the renderer granularity changes */ + Word16 *data /* o : output synthesis signal */ +); + +ivas_error ivas_param_ism_dec_open_fx( + Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ +); + +void ivas_param_ism_dec_close_fx( + PARAM_ISM_DEC_HANDLE *hParamIsmDec, /* i/o: decoder ParamISM handle */ + SPAT_PARAM_REND_COMMON_DATA_HANDLE *hSpatParamRendCom_out, /* i/o: common spatial renderer data */ + const AUDIO_CONFIG output_config /* i : output audio configuration */ +); + +void ivas_ism_dec_digest_tc_fx( + Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ +); + +void ivas_param_ism_dec_digest_tc_fx( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ + const UWord16 nCldfbSlots, /* i : number of CLFBS slots in the transport channels */ + Word32 *transport_channels[], /* i : synthesized core-coder transport channels/DirAC output */ + Word16 q_tc_in ); + +void ivas_param_ism_dec_render_fx( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ + const UWord16 nSamplesAsked, /* i : number of CLDFB slots requested */ + UWord16 *nSamplesRendered, /* o : number of CLDFB slots rendered */ + UWord16 *nSamplesAvailable, /* o : number of CLDFB slots still to render */ + Word32 *output_f_fx[] ); + +void ivas_param_ism_params_to_masa_param_mapping_fx( + Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ +); + +Word16 ivas_ism_dtx_enc_fx( + ISM_DTX_HANDLE hISMDTX, /* i/o: ISM DTX handle */ + SCE_ENC_HANDLE hSCE[MAX_SCE], /* i/o: SCE encoder structure */ + const Word32 ivas_total_brate, /* i : IVAS total bitrate */ + const Word16 nchan_ism, /* i : number of objects */ + const Word16 nchan_transport, /* i : number of transport channels */ + Word16 vad_flag[MAX_NUM_OBJECTS], /* i : VAD flag */ + ISM_METADATA_HANDLE hIsmMeta[], /* i/o: ISM metadata handles */ + Word16 md_diff_flag[], /* o : metadata differential flag */ + Word16 *sid_flag /* o : indication of SID frame */ +); + +void ivas_ism_dtx_dec_fx( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + Word16 *nb_bits_metadata /* o : number of metadata bits */ +); + +void ivas_ism_get_sce_id_dtx_fx( + ISM_DTX_HANDLE hISMDTX, /* i/o: ISM DTX handle */ + SCE_ENC_HANDLE hSCE[MAX_SCE], /* i/o: SCE encoder structure */ + const Word16 nchan_transport, /* i : number of transport channels */ + const Word16 input_frame /* i : input frame length per channel */ +); + +void ivas_ism_coh_estim_dtx_enc_fx( + ISM_DTX_HANDLE hISMDTX, /* i/o: ISM DTX handle */ + SCE_ENC_HANDLE hSCE[MAX_SCE], /* i/o: SCE encoder structure */ + const Word16 nchan_transport, /* i : number of transport channels */ + const Word16 input_frame /* i : input frame length */ +); + +void ivas_ism_dtx_limit_noise_energy_for_near_silence_fx( + SCE_DEC_HANDLE hSCE[], /* i/o: SCE decoder structures */ + const Word16 sce_id_dtx, /* i : SCE DTX ID */ + const Word16 nchan_transport, /* i : number of transport channels */ + Word16 *Q_cngNoiseLevel ); + + +ivas_error stereo_dft_enc_create_fx( + STEREO_DFT_ENC_DATA_HANDLE *hStereoDft, /* o : encoder DFT stereo handle */ + const Word32 input_Fs, /* i : input sampling rate */ + const Word16 max_bwidth /* i : maximum encoded bandwidth */ +); + +void stereo_dft_enc_reset_fx( + STEREO_DFT_ENC_DATA_HANDLE hStereoDft /* i/o: encoder stereo handle */ +); + +void stereo_enc_itd_init_fx( + ITD_DATA_HANDLE hItd /* i/o: encoder ITD handle */ +); + +void stereo_dft_enc_update_fx( + STEREO_DFT_ENC_DATA_HANDLE hStereoDft, /* i/o: encoder stereo handle */ + const Word16 max_bwidth /* i : maximum encoded bandwidth */ +); + +void stereo_dft_quantize_res_gains_fx( + const Word32 *g, // Q31 + const Word32 *r, // Q31 + Word32 *gq, // Q31 + Word32 *rq, // Q31 + Word16 *ig, + Word16 *ir ); + +void stereo_dft_dequantize_itd_fx( + Word16 *ind, /* Q0 */ + Word32 *out, /* Q15 */ + const Word32 output_Fs /* Q0 */ +); + +Word16 stereo_dft_sg_recovery_fx( + STEREO_DFT_DEC_DATA_HANDLE hStereoDft /* i/o: Decoder DFT stereo handle */ +); + +Word16 res_bpf_adapt_ivas_fx( + STEREO_DFT_DEC_DATA_HANDLE hStereoDft, /* i/o: DFT stereo decoder handle */ + const Word32 *bpf_error_signal_8k, /* i : BPF modification signal */ + Word32 res_buf[STEREO_DFT_N_8k], /* i : residual buffer Q_res */ + Word16 q_res ); + +void stereo_dft_dec_read_BS_fx( + const Word32 ivas_total_brate, /* i : IVAS total bitrate Q0*/ + const Word32 element_brate, /* i : element bitrate Q0*/ + Word32 *total_brate, /* o : total bitrate Q0*/ + Decoder_State *st, /* i/o: decoder state structure */ + STEREO_DFT_DEC_DATA_HANDLE hStereoDft, /* i/o: decoder stereo handle */ + const Word16 bwidth, /* i : bandwidth Q0*/ + const Word16 output_frame, /* i : output frame length Q0*/ + Word32 res_buf_fx[STEREO_DFT_N_8k], /* o : residual buffer Q0*/ + Word16 *nb_bits, /* o : number of bits read Q0*/ + Word16 *coh_fx, /* i/o: Coherence Q15*/ + const Word16 ivas_format /* i : ivas format Q0*/ +); + +Word16 write_bitstream_adapt_GR( + BSTR_ENC_HANDLE hBstr, /* i/o: Encoder bitstream handle */ + const Word16 ind, /* i : bitstream index */ + const Word16 *in, /* i : values to be written in bitstream */ + const Word16 len, /* i : values vector length */ + const Word16 GR_ord, /* i : GR order to be used */ + const Word16 no_GR_ord /* i : speech/music 0/1 */ +); + +Word16 adapt_GR_ief_fx( + const Word16 *in, /* i : vector to encode */ + Word16 *in_diff, /* o : encoded symbols in case of differential encoding */ + const Word16 *prev, /* i : previous frame data */ + const Word16 len, /* i : input vector length */ + const Word16 no_symb, /* i : number of symbols */ + Word16 *nbits, /* o : number of used bits */ + Word16 *in_enc, /* o : symbold actually encoded after adapt_GR */ + const Word16 *map0, /* i : mapping array */ + const Word16 no_GR_ord, /* i : number of GR order to try 2: 0,1; 3:0,1,2 */ + Word16 *nbits_diff, /* o : number bits in diff encoding */ + const Word16 side_gain_counter, /* i : number of frames since last abs coding */ + Word16 *side_gain_bitdiff_lp, /* i/o: LP-filtered bit difference between abs/diff */ + Word16 *q_side_gain_bitdiff_lp, /* i/o: Q of LP-filtered bit difference between abs/diff */ + const Word16 try_diff /* i : diff coding allowed 1/0 */ +); + +Word16 adapt_GR_rpg1_ief( + const Word16 *in, /* i : res pred gains input vector */ + Word16 *in_diff, /* o : encoded symbols in case of differential encoding */ + const Word16 *prev, /* i : previous frame data */ + const Word16 len, /* i : input vector length */ + const Word16 no_symb, /* i : number of symbols */ + Word16 *nbits, /* o : number of used bits */ + Word16 *in_enc, /* o : symbold actually encoded after adapt_GR */ + const Word16 *maps, /* i : mapping array */ + Word16 *nbits_diff, /* o : estimated no of bits for differential encoding */ + const Word16 no_GR_ord, /* i : number of GR order to try 2: 0,1; 3:0,1,2 */ + const Word16 try_diff /* i : diff coding allowed 1/0 */ +); + +Word16 write_GR1( + BSTR_ENC_HANDLE hBstr, /* i/o: Encoder bitstream handle */ + const Word16 ind, /* i : bitstream index */ + const Word16 *in, /* i : data to be encoded */ + const Word16 len /* i : input data length */ +); + +Word16 write_bitstream_GR( + BSTR_ENC_HANDLE hBstr, /* i/o: Encoder bitstream handle */ + const Word16 ind, /* i : bitstream index */ + const Word16 *in, /* i : input vector */ + const Word16 len, /* i : input vector length */ + const Word16 GR_ord /* i : GR order */ +); + +void stereo_dft_hybrid_ITD_flag( + STEREO_DFT_CONFIG_DATA_HANDLE hConfig, /* o : DFT stereo configuration */ + const Word32 input_Fs, /* i : CPE element sampling rate */ + const Word16 hybrid_itd_max /* i : flag for hybrid ITD for very large ITDs */ +); + +void rc_uni_dec_init_fx( + RangeUniDecState *rc_st_dec, /* i/o: RC state handle */ + UWord16 *bit_buffer, /* i : Bit buffer */ + const Word16 max_available_bits /* i : Total maximum bits available */ +); + +UWord16 rc_uni_dec_read_symbol_fastS_fx( + RangeUniDecState *rc_st_dec, /* i/o: Decoder State */ + const UWord16 cum_freq_table[], /* i : Cumulative frequency up to symbol */ + const UWord16 sym_freq_table[], /* i : Symbol frequency */ + const UWord16 alphabet_size, /* i : Number of symbols in the alphabet */ + const UWord16 tot_shift /* i : Total frequency as a power of 2 */ +); + +Word16 rc_uni_dec_virtual_finish_fx( + RangeUniDecState *rc_st_dec /* i/o: RC state handle */ +); + +void unclr_classifier_dft_fx( + CPE_ENC_HANDLE hCPE /* i/o: CPE encoder structure */ +); + +void xtalk_classifier_dft_fx( + CPE_ENC_HANDLE hCPE, /* i/o: CPE encoder structure */ + const Word16 itd, /* i : ITD from DFT stereo - used as a feature */ + const Word32 gcc_phat[] /* i : GPHAT cross-channel correlation function Q31*/ +); + +void stereo_td_init_enc_fx( + STEREO_TD_ENC_DATA_HANDLE hStereoTD, /* i/o: TD stereo encoder handle */ + const Word16 last_element_mode /* i : last element mode */ +); + +ivas_error stereo_set_tdm_fx( + CPE_ENC_HANDLE hCPE, /* i : CPE encoder structure */ + const Word16 input_frame, /* i : input frame length per channel */ + Word16 input_q ); + +void stereo_tdm_prep_dwnmx_fx( + CPE_ENC_HANDLE hCPE, /* i : CPE encoder structure */ + const Word32 *input1, /* i : right channel input */ + const Word16 input_frame, /* i : frame lenght */ + const Word16 input_q /* i : frame lenght */ +); + +void tdm_upmix_plain_fx( + Word32 Left_fx[], /* o : left channel Qx*/ + Word32 Right_fx[], /* o : right channel Qx*/ + const Word32 PCh_2_L_fx[], /* i : primary channel Qx*/ + const Word32 SCh_2_R_fx[], /* i : secondary channel Qx*/ + const Word32 LR_ratio_fx, /* i : mixing ratio Q31*/ + const Word32 inv_den_LR_ratio_fx, /* i : inverse mixing ration Q31*/ + const Word16 start_index, /* i : start index Q0*/ + const Word16 end_index, /* i : end index Q0*/ + const Word16 plus_minus_flag /* i : plus/minus flag Q0*/ +); + +void stereo_tdm_combine_fx( + CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ + Word32 *PCh_2_L_fx, /* i/o: Primary channel -> output as left channel Qx*/ + Word32 *SCh_2_R_fx, /* i/o: Secondary channel -> output as right channel Qx*/ + const Word16 output_frame, /* i : Number of samples Q0*/ + const Word16 flag_HB, /* i : flag to distinguish between core (0) and HB (1) synthesis Q0*/ + const Word16 tdm_ratio_idx /* i : TDM ratio index Q0*/ +); + +Word16 tdm_lp_comparison_fx( + STEREO_TD_ENC_DATA_HANDLE hStereoTD, /* i/o: TD stereo encoder handle */ + STEREO_CLASSIF_HANDLE hStereoClassif, /* i/o: stereo classifier structure */ + Encoder_State *st, /* i/o: Encoder structure */ + Word32 *speech_buff, /* i : Current speech frame Q_speech */ + const Word16 *A_PCh_fx, /* i : primary channel LP coefficients Q12*/ + const Word16 *A_SCh_fx, /* i : secondary channel LP coeff. Q12*/ + const Word16 m, /* i : filter length */ + const Word32 *isp_PCh_fx, /* i : primary channel LSPs Q31 */ + const Word32 *isp_SCh_fx, /* i : secondary channel LSPs Q31 */ + const Word16 L_frame, /* i : frame length */ + const Word32 element_brate_wo_meta, /* i : element bitrate without metadata*/ + Word16 Q_speech ); + +ivas_error signaling_enc_secondary_fx( + Encoder_State *st, /* i/o: Encoder structure */ + const Word16 tdm_SM_or_LRTD_Pri, /* i : channel combination scheme flag OR LRTD primary channel */ + const Word16 tdm_Pitch_reuse_flag /* i : primary channel pitch reuse flag*/ +); + +void tdm_low_rate_enc( + Encoder_State *st, /* i/o: State structure */ + const Word16 Aq[], /* i : 12k8 Lp coefficient */ + const Word16 *res, + /* i : residual signal */ // Q_new + Word16 *synth, + /* i/o: core synthesis */ // Q_new + Word16 *exc_fx, + /* i/o: current non-enhanced excitation */ // Q_new + Word16 *pitch_buf, + /* i/o: floating pitch values for each subframe */ // Q6 + Word16 *voice_factors, + /* o : voicing factors */ // Q15 + Word16 *bwe_exc_fx, + /* o : excitation for SWB TBE */ // Q_new + const Word16 attack_flag, /* i : attck flag */ + const Word16 *lsf_new, + /* i : current frame ISF vector */ // x2.56 + Word16 *tmp_noise, + /* o : long-term noise energy */ // Q8 + Word16 *Q_new ); + +void tdm_low_rate_dec_fx( + Decoder_State *st, /* i/o: decoder static memory */ + Word16 dct_epit[], /* o : GSC excitation in DCT domain Q_exc*/ + Word16 *pitch_buf, /* o : Word16 pitch values for each subframe Q6*/ + Word16 *voice_factors, /* o : voicing factors Q15*/ + Word16 *exc, /* i/o: adapt. excitation exc Q_exc*/ + Word16 *exc2, /* i/o: adapt. excitation/total exc Q_exc*/ + Word16 *bwe_exc, /* o : excitation for SWB TBE Q_exc*/ + const Word16 *lsf_new /* i : ISFs at the end of the frame Q8/100 (2.56x)*/ +); + +void tdm_SCh_LSF_intra_pred_fx( + const Word32 element_brate, /* i : element bitrate */ + const Word16 *tdm_lsfQ_PCh_fx, /* i : primary channel LSFs */ + Word16 *pred_lsf_SCh_fx /* o : predicted secondary channel LSFs */ +); + +void tdm_SCh_lsf_reuse_fx( + const Word16 enc_dec, /* i : encoder/decoder flag */ + const Word32 element_brate, /* i : element bitrate */ + Word16 lsf_new_fx[M], /* i/o: LSFs at the end of the frame */ + Word16 lsp_new_fx[M], /* i/o: LSPs at the end of the frame */ + const Word16 tdm_lsfQ_PCh_fx[M], /* i : primary channel LSFs */ + const Word16 lsf_wgts_fx[M], /* i : LSF weights */ + Word16 *beta_index /* i/o: quantization index */ +); + +void EstimateStereoTCXNoiseLevel_fx( + Encoder_State **sts, /* i : state handle */ + Word32 *q_spectrum[CPE_CHANNELS][NB_DIV], /* i : quantized MDCT spectrum */ + Word16 gain_tcx[][NB_DIV], /* i : global gain */ + Word16 gain_tcx_e, /* i : global gain exponent */ + Word16 L_frame[][NB_DIV], /* i : frame length */ + Word16 noiseFillingBorder[][NB_DIV], /* i : noise filling border */ + Word16 hm_active[][NB_DIV], /* i : flag indicating if the harmonic model is active */ + const Word16 ignore_chan[], /* i : flag indicating whether the channel should be ignored */ + Word16 fac_ns[][NB_DIV], /* o : noise filling level */ + Word16 param_core[][NB_DIV * NPRM_DIV], /* o : quantized noise filling level */ + const Word16 MCT_flag /* i : hMCT handle allocated (1) or not (0) */ +); + +void TNSAnalysisStereo_fx( + Encoder_State **sts, /* i : encoder state handle */ + Word32 *mdst_spectrum_fx[CPE_CHANNELS][NB_DIV], /* o : MDST spectrum Qx*/ + const Word16 bWhitenedDomain, /* i : whitened domain flag Q0*/ + Word16 tnsSize[CPE_CHANNELS][NB_DIV], /* i : number of tns parameters put into prm Q0*/ + Word16 tnsBits[CPE_CHANNELS][NB_DIV], /* i : number of tns bits in the frame Q0*/ + Word16 param_core[][NB_DIV * NPRM_DIV], /* o : TNS parameters Q0*/ + const Word16 mct_on /* i : flag mct block (1) or stereo (0) Q0*/ +); + +void init_tcx_enc_info_fx( + Encoder_State *st, /* i/o: coder memory state */ + Word16 *L_frame, + Word16 *L_frameTCX, + Word16 *L_spec ); + +void SetCurrentPsychParams( + const Word16 core, + const Word16 last_frame_was_concealed_cng, + TCX_CONFIG_HANDLE hTcxCfg ); + +void sns_avq_cod_fx( + const Word32 *sns_fx, /* i : Input sns vectors */ + Word16 exp_sns, + const Word32 *snsmid_fx, /* i : Input mid-sns vectors */ + Word16 exp_snsmid, + Word32 *sns_q_fx, /* o : Quantized LFS vectors Q16 */ + Word32 *snsmid_q_fx, /* o : Quantized mid-LFS vectors Q16 */ + Word16 *index, /* o : Quantization indices */ + const Word16 core, /* i : core */ + const Word16 L_frame, + const Word16 low_brate_mode /* i : flag low bit operating mode */ +); + +void sns_avq_cod_stereo_fx( + const Word32 *snsl_fx, /* i : Input sns vector (left channel) */ + Word16 exp_snl, + const Word32 *snsr_fx, /* i : Input sns vector (right channel) */ + Word16 exp_snr, + const Word16 L_frame, + Word32 *snsl_q_fx, /* o : Quantized sns vector (left channel) Q16 */ + Word32 *snsr_q_fx, /* o : Quantized sns vector (right channel) Q16 */ + Word16 *indexl, /* o : Quantization indices (left channel) */ + Word16 *indexr /* o : Quantization indices (right channel) */ +); + +ivas_error initMdctStereoDtxData_fx( + CPE_DEC_HANDLE hCPE /* i/o: CPE handle */ +); + +void applyDmxMdctStereo_fx( + const CPE_DEC_HANDLE hCPE, /* i : CPE handle */ + Word32 *output_fx[CPE_CHANNELS], /* o : output from core decoder q_out*/ + const Word16 output_frame /* i : output frame length Q0*/ +); + +ivas_error front_vad_create_fx( + FRONT_VAD_ENC_HANDLE *hFrontVad, /* i/o: front-VAD handle */ + const ENCODER_CONFIG_HANDLE hEncoderConfig /* i : configuration structure */ +); + +void front_vad_destroy_fx( + FRONT_VAD_ENC_HANDLE *hFrontVad /* i/o: front-VAD handle */ +); + +ivas_error front_vad_fx( + CPE_ENC_HANDLE hCPE, /* i/o: CPE encoder structure, nullable */ + Encoder_State *st, /* i/o: encoder state structure */ + const ENCODER_CONFIG_HANDLE hEncoderConfig, /* i : configuration structure */ + FRONT_VAD_ENC_HANDLE *hFrontVads, /* i/o: FrontVad handles */ + const Word16 MCT_flag, /* i : hMCT handle allocated (1) or not (0) */ + const Word16 input_frame, /* i : frame length */ + Word16 vad_flag_dtx[], /* o : HE-SAD flag with additional DTX HO */ + Word32 fr_bands_fx[][2 * NB_BANDS], /* o : energy in frequency bands Q_buffer[n] + QSCALE + 2 */ + Word16 Etot_LR_fx[], /* o : total energy Left & Right channel Q8 */ + Word32 lf_E_fx[][2 * VOIC_BINS], /* i : per bin spectrum energy in lf, LR channels Q_buffer[n] + QSCALE */ + Word16 localVAD_HE_SAD[], /* o : HE-SAD flag without hangover, LR channels */ + Word16 vad_hover_flag[], /* o : VAD hangover flag */ + Word32 band_energies_LR_fx[2 * NB_BANDS], /* o : energy in critical bands without minimum noise floor E_MIN Q_buffer[1] + QSCALE + 2 - band_ener_guardbits*/ + Word32 *PS_out_fx, /* o : energy spectrum Q_buffer + QSCALE */ + Word16 *Bin_E_out_fx, /* o : log-energy spectrum of the current frame Q7 */ + Word16 Q_inp, + Word16 *Q_buffer, + Word16 Q_add, + Word16 *front_create_flag ); + +void stereo_cna_update_params_fx( + CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ + Word32 *output_fx[CPE_CHANNELS], /* i : Output signal OUTPUT_Q*/ + const Word16 output_frame, /* i : Output frame length Q0*/ + const Word16 tdm_ratio_idx /* i : TDM ratio index Q0*/ +); + +void mvr2r_inc_fixed_one( + const Word32 x_fx[], /* i : input vector */ + const Word16 x_inc, /* i : increment for vector x[] */ + Word32 y_fx[], /* o : output vector */ + const Word16 y_inc, /* i : increment for vector y[] */ + const Word16 n /* i : vector size */ +); + +void mvr2r_inc_fixed( + const Word32 x_fx[], /* i : input vector */ + const Word16 x_inc, /* i : increment for vector x[] */ + Word32 y_fx[], /* o : output vector */ + const Word16 y_inc, /* i : increment for vector y[] */ + const Word16 n /* i : vector size */ +); + +void v_mult_inc_fx( + const Word32 x1_fx[], /* i : Input vector 1 */ + Word16 *x1_q_fx, + const Word16 x1_inc, /* i : Increment for input vector 1 */ + const Word32 x2_fx[], /* i : Input vector 2 */ + Word16 *x2_q_fx, + const Word16 x2_inc, /* i : Increment for input vector 1 */ + Word32 y_fx[], /* o : Output vector that contains vector 1 .* vector 2 */ + Word16 *y_q_fx, + const Word16 y_inc, /* i : increment for vector y[i] */ + const Word16 N /* i : Vector length */ +); + +void v_add_inc_fx( + const Word32 x1[], /* i : Input vector 1 */ + const Word16 x_inc, /* i : Increment for input vector 1 */ + const Word32 x2[], /* i : Input vector 2 */ + const Word16 x2_inc, /* i : Increment for input vector 2 */ + Word32 y[], /* o : Output vector that contains vector 1 + vector 2 */ + const Word16 y_inc, /* i : increment for vector y[] */ + const Word16 N /* i : Vector length */ +); +Word32 logsumexp_fx( + const Word32 x[], /* i : input array x */ + const Word16 x_e, + const Word16 N /* i : number of elements in array x */ +); +Word32 lin_interp32_fx( + const Word32 x, /* i : the value to be mapped */ + const Word32 x1, /* i : source range interval: low end */ + const Word32 y1, /* i : source range interval: high end */ + const Word32 x2, /* i : target range interval: low */ + const Word32 y2, /* i : target range interval: high */ + const Word16 flag_sat, /* i : flag to indicate whether to apply saturation */ + Word16 *Q_io /*i/o : i/o Q factor of the output*/ +); + +void v_addc_fx( + const Word32 x_fx[], /* i : Input vector */ + const Word32 c_fx, /* i : Constant */ + Word32 y_fx[], /* o : Output vector that contains c*x */ + const Word16 N /* i : Vector length */ +); + +void v_addc_fixed( + const Word32 x[], /* i : Input vector */ + const Word32 c, /* i : Constant */ + Word32 y[], /* o : Output vector that contains c*x */ + const Word16 N /* i : Vector length */ +); + +void v_min_fx( + const Word32 x1_fx[], /* i : Input vector 1 */ + Word16 *x1_q_fx, + const Word32 x2_fx[], /* i : Input vector 2 */ + Word16 *x2_q_fx, + Word32 y_fx[], /* o : Output vector that contains vector 1 .* vector 2 */ + Word16 *y_q_fx, + const Word16 N /* i : Vector length */ +); + +void v_mult_inc_fixed( + const Word32 x1_fx[], /* i : Input vector 1 */ + const Word16 x1_inc, /* i : Increment for input vector 1 */ + const Word32 x2_fx[], /* i : Input vector 2 */ + const Word16 x2_inc, /* i : Increment for input vector 1 */ + Word32 y_fx[], /* o : Output vector that contains vector 1 .* vector 2 */ + const Word16 y_inc, /* i : increment for vector y[i] */ + const Word16 N /* i : Vector length */ +); + +void v_sqrt_fx( + const Word32 x[], /* i : Input vector */ + Word16 exp[], + Word32 y[], /* o : Output vector that contains sqrt(x) */ + const Word16 N /* i : Vector length */ +); + +Word32 sumAbs_fx( + const Word32 *vec, /* i : input vector */ + const Word16 lvec /* i : length of input vector */ +); + +Word32 dot_product_cholesky_fx( + const Word32 *x, /* i : vector x */ + const Word32 *A, /* i : Cholesky matrix A */ + const Word16 N /* i : vector & matrix size */ +); +Word32 dot_product_cholesky_fixed( + const Word32 *x, /* i : vector x */ + const Word32 *A, /* i : Cholesky matrix A */ + const Word16 N, /* i : vector & matrix size */ + const Word16 exp_x, + const Word16 exp_A, + Word16 *exp_sum ); + +void v_mult_mat_fx( + Word32 *y_fx, /* o : the product x*A */ + Word16 *y_q_fx, + const Word32 *x_fx, /* i : vector x */ + Word16 *x_q_fx, + const Word32 *A_fx, /* i : matrix A */ + Word16 *A_q_fx, + const Word16 N, /* i : number of rows */ + const Word16 C /* i : number of columns */ +); +void v_mult_mat_fixed( + Word32 *y, /* o : the product x*A */ + const Word32 *x, /* i : vector x */ + const Word32 *A, /* i : matrix A */ + const Word16 Nr, /* i : number of rows */ + const Word16 Nc, /* i : number of columns */ + Word16 guardbits ); + +Word32 check_bounds_l( + const Word32 value, /* i : Input value */ + const Word32 low, /* i : Low limit */ + const Word32 high /* i : High limit */ +); + +Word16 check_bounds_s_fx( + const Word16 value, /* i : Input value */ + const Word16 low, /* i : Low limit */ + const Word16 high /* i : High limit */ +); + +ivas_error stereo_memory_enc_fx( + CPE_ENC_HANDLE hCPE, /* i : CPE encoder structure */ + const Word32 input_Fs, /* i : input sampling rate */ + const Word16 max_bwidth, /* i : maximum audio bandwidth */ + const IVAS_FORMAT ivas_format, /* i : IVAS format */ + const Word16 nchan_transport /* i : number transport chans */ + +); + +void stereo_switching_enc_fx( + CPE_ENC_HANDLE hCPE, /* i : CPE encoder structure */ + Word16 old_input_signal_pri[], /* i : old input signal of primary channel */ + const Word16 input_frame, /* i : input frame length */ + const Word16 q_inp ); + + +void stereo_td2dft_update_fx( + CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ + const Word16 n, /* i : channel number Q0*/ + Word32 output_fx[], /* i/o: synthesis @internal Fs Q11*/ + Word32 synth_fx[], /* i/o: synthesis @output Fs Q11*/ + Word32 hb_synth_fx[], /* i/o: hb synthesis Q11*/ + const Word16 output_frame /* i : frame length Q0*/ +); + +void stereo_mdct2dft_update_fx( + CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ + Word32 output0_fx[], /* i/o: synthesis @internal Fs, ch0 Q11*/ + Word32 synth0_fx[] /* i/o: synthesis @output Fs, ch0 Q11*/ +); + +Word16 write_GR0( + BSTR_ENC_HANDLE hBstr, /* i/o: Encoder bitstream handle */ + const Word16 ind, /* i : bitstream index */ + const Word16 *in, /* i : data to be encoded */ + const Word16 len /* i : input data length */ +); + +void ivas_mct_core_dec( + MCT_DEC_HANDLE hMCT, /* i/o: MCT decoder structure */ + CPE_DEC_HANDLE hCPE[MCT_MAX_BLOCKS], /* i/o: CPE decoder structure */ + const Word16 nCPE, /* i : number of CPEs */ + Word32 *signal_out_fx[], + Word16 q_x[MCT_MAX_CHANNELS] ); + +void ivas_qmetadata_to_dirac_fx( + const IVAS_QMETADATA_HANDLE hQMetaData, /* i : frame of MASA q_metadata */ + DIRAC_DEC_HANDLE hDirAC, /* i : DirAC decoder structure */ + MASA_DECODER_HANDLE hMasa, /* i : MASA decoder structure */ + SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom, /* i/o: common spatial renderer data handle */ + const Word32 ivas_total_brate, /* i : IVAS total bitrate */ + const IVAS_FORMAT ivas_format, /* i : IVAS format */ + const Word16 hodirac_flag, /* i : flag to indicate HO-DirAC mode */ + Word16 *dirac_to_spar_md_bands /* o : DirAC->SPAR MD bands */ +); + +Word16 masa_sq_fx( + const Word32 in, /* i : input value */ + const Word32 *threshold, /* i : partition */ + const Word16 cb_sz /* i : codebook size */ +); + +Word16 quantize_direction2D_fx( + Word32 phi, /* i : input azimuth value Q22 */ + const Word16 no_cw, /* i : number of bits */ + Word32 *phi_q, /* o : quantized azimuth value Q22 */ + UWord16 *index_phi, /* o : quantized azimuth index */ + const MC_LS_SETUP mc_format /* i : channel format if in MC-mode */ +); + +Word32 companding_azimuth_fx( + const Word32 azi_fx, /* i : input azimuth value */ + const MC_LS_SETUP mc_format, /* i : input channel format */ + const Word16 theta_flag, /* i : zero/non zero elevation flag */ + const Word16 direction /* i : direction of companding (direct or inverse)*/ +); + +Word16 quantize_phi_fx( + Word32 phi, /* i : azimuth value */ + const Word16 flag_delta, /* i : flag indicating if the azimuth codebook is translated or not */ + Word32 *phi_hat, /* o : quantized azimuth */ + const Word16 n /* i : azimuth codebook size */ +); + +Word32 deindex_elevation_fx( + UWord16 *id_th, /* i : input index */ + const Word16 no_bits, /* i : number of bits for the spherical grid */ + const MC_LS_SETUP mc_format /* i : channel format if in MC-mode */ +); + +Word32 deindex_azimuth_fx( + Word16 id_phi, /* i : index */ + const Word16 no_bits, /* i : number of bits for the spherical grid */ + const Word16 id_th, /* i : elevation index */ + const Word16 remap, /* i : remapping flag */ + const MC_LS_SETUP mc_format /* i : channel format if in MC-mode */ +); +void deindex_spherical_component_fx( + const UWord16 sph_idx, /* i : spherical index */ + Word32 *az_fx, /* o : decoded azimuth value */ + Word32 *el_fx, /* o : decoded elevation value */ + UWord16 *az_idx, /* o : azimuth index */ + UWord16 *el_idx, /* o : elevation index */ + const UWord16 no_bits, /* i : number of bits for the spherical grid */ + const MC_LS_SETUP mc_format /* i : channel format if in MC-mode */ +); + +void ivas_dirac_param_est_enc( + DIRAC_ENC_HANDLE hDirAC, + IVAS_QDIRECTION *q_direction, + const UWord8 useLowerRes, + Word32 *data_f_fx[], + Word32 **pp_fr_real_fx, + Word32 **pp_fr_imag_fx, + Word16 pp_fr_q, + const Word16 input_frame, + const IVAS_FORMAT ivas_format, + const Word16 hodirac_flag, + const Word16 nchan_fb_in, + Word16 *mono_frame_count, + Word16 *dirac_mono_flag ); + +ivas_error ivas_cldfb_dec_reconfig_fx( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + const Word16 nchan_transport_old, /* i : number of TCs in previous frame */ + Word16 numCldfbAnalyses_old, /* i : number of CLDFB analysis instances in previous frame */ + const Word16 numCldfbSyntheses_old /* i : number of CLDFB synthesis instances in previous frame */ +); + +Word16 ivas_sba_get_order_fx( + const Word16 nb_channels, /* i : Number of ambisonic channels */ + const Word16 sba_planar /* i : SBA planar flag */ +); + +/*! r: Ambisonic (SBA) order used for analysis and coding */ +Word16 ivas_sba_get_analysis_order( + const Word32 ivas_total_brate, /* i : IVAS total bitrate */ + const Word16 sba_order /* i : Ambisonic (SBA) order */ +); + +Word16 ivas_sba_get_nchan_metadata( + const Word16 sba_order, /* i : Ambisonic (SBA) order */ + const Word32 ivas_total_brate /* i : IVAS total bitrate */ +); + +void ivas_sba_get_spar_hoa_ch_ind( + const Word16 num_md_chs, /* i : number of MD channels */ + const Word32 ivas_total_brate, /* i : IVAS total bitrate */ + Word16 HOA_md_ind[IVAS_SPAR_MAX_CH] ); + +/*! r: flag indicating to code SPAR HOA MD for all bands */ +void ivas_sba_get_spar_hoa_md_flag( + const Word16 sba_order, /* i : Ambisonic (SBA) order */ + const Word32 ivas_total_brate, /* i : IVAS total bitrate */ + Word16 *spar_hoa_md_flag, + Word16 *spar_hoa_dirac2spar_md_flag ); + +Word16 ivas_sba_remapTCs_fx( + Word32 *sba_data[], /* i/o: SBA signals */ + Decoder_Struct *st_ivas, /* i/o: decoder struct */ + const Word16 output_frame /* i : frame length */ +); + +void ivas_sba2mc_cldfb_fixed( + IVAS_OUTPUT_SETUP hInSetup, /* i : Format of input layout */ + Word32 RealBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* i/o: cldfb real part (Q_real) */ + Word32 ImagBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* i/o: cldfb imag part (Q_imag) */ + const Word16 nb_channels_out, /* i : nb of output channels */ + const Word16 nb_bands, /* i : nb of CLDFB bands to process */ + const Word16 nb_timeslots, /* i : number of time slots to process */ + const Word32 *hoa_dec_mtx /* i : HOA decoding mtx */ +); + +void ivas_dirac_config_bands_fx( + Word16 *band_grouping, /* o : band grouping */ + const Word16 nbands, /* i : number of bands */ + const Word16 max_band, /* i : maximal band index +1 */ + Word16 *dirac_to_spar_md_bands, /* o : mapping of DirAC parameter band index to SPAR FB band index */ + const Word8 useLowerBandRes, /* i : flag indicating lower band resolution for DirAC */ + const Word16 enc_param_start_band, /* i : band index of first DirAC parameter band */ + IVAS_FB_MIXER_HANDLE hFbMdft ); + +void ivas_dirac_dec_close_fx( + DIRAC_DEC_HANDLE *hDirAC_out ); + +void generate_masking_noise_lb_dirac_fx( + HANDLE_FD_CNG_COM hFdCngCom, /* i/o: FD_CNG structure containing all buffers and variables */ + Word32 *tdBuffer, /* i/o: time-domain signal, if NULL no LB-CNA */ + const Word16 nCldfbTs, /* i : number of CLDFB slots that will be rendered */ + const Word16 cna_flag /* i : CNA flag for LB and HB */ +); + +void generate_masking_noise_lb_dirac_fx( + HANDLE_FD_CNG_COM hFdCngCom, /* i/o: FD_CNG structure containing all buffers and variables */ + Word32 *tdBuffer, /* i/o: time-domain signal, if NULL no LB-CNA */ + const Word16 nCldfbTs, /* i : number of CLDFB slots that will be rendered */ + const Word16 cna_flag /* i : CNA flag for LB and HB */ +); + +void ivas_dirac_dec_close_fx( + DIRAC_DEC_HANDLE *hDirAC_out ); + +void ivas_dirac_dec_set_md_map( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + const Word16 nCldfbTs /* i : number of CLDFB time slots */ +); + +void computeDirectionVectors_fixed( + Word32 *intensity_real_x, + Word32 *intensity_real_y, + Word32 *intensity_real_z, + const Word16 enc_param_start_band, + const Word16 num_frequency_bands, + Word32 *direction_vector_x, /*Q30*/ + Word32 *direction_vector_y, /*Q30*/ + Word32 *direction_vector_z, /*Q30*/ + Word16 i_e /*Exponent of all the intensity buffers*/ ); + +void computeDirectionVectors_fx( + Word32 *intensity_real_x, + Word32 *intensity_real_y, + Word32 *intensity_real_z, + const Word16 enc_param_start_band, + const Word16 num_frequency_bands, + Word32 *direction_vector_x, + Word32 *direction_vector_y, + Word32 *direction_vector_z, + Word16 *q_factor ); + + +void computeDiffuseness_fx( + Word32 *buffer_intensity[DIRAC_NUM_DIMS][DIRAC_NO_COL_AVG_DIFF], + const Word32 *buffer_energy, + const Word16 num_freq_bands, + Word32 *diffuseness, + Word16 q_factor_intensity, + Word16 q_factor_energy, + Word16 *out_exp + +); + +void computeDiffuseness_fixed( + Word32 *buffer_intensity[DIRAC_NUM_DIMS][DIRAC_NO_COL_AVG_DIFF], + const Word32 *buffer_energy, + const Word16 num_freq_bands, + Word32 *diffuseness, + Word16 *q_factor_intensity, + Word16 *q_factor_energy, + Word16 *q_diffuseness ); + +void ivas_dirac_dec_get_response_fx( + const Word16 azimuth, + const Word16 elevation, + Word32 *response, + const Word16 ambisonics_order, + Word16 Q_out ); + +void calculate_hodirac_sector_parameters_fx( + DIRAC_ENC_HANDLE hDirAC, /* i : DirAC handle */ + Word32 RealBuffer_fx[DIRAC_MAX_ANA_CHANS][DIRAC_NO_FB_BANDS_MAX], /* i : signal vector (L+1)^2 x N_bins, real part */ + Word32 ImagBuffer_fx[DIRAC_MAX_ANA_CHANS][DIRAC_NO_FB_BANDS_MAX], /* i : signal vector, imaginary part */ + Word16 Qfac, /* i : Q-factor of signal vector */ + const Word32 beta_fx, /* i : forgetting factor for average filtering, Q30 */ + const Word16 *band_grouping, /* i : indices of band groups */ + const Word16 N_bands, /* i : number of bands (groups) */ + const Word16 enc_param_start_band, /* i : first band to process */ + Word32 *azi_fx, /* o : array of sector azimuth angles, flat Q23 */ + Word32 *ele_fx, /* o : array of sector elevation angles, flat Q23 */ + Word32 *diff_fx, /* o : array of sector diffuseness values, flat */ + Word16 *diff_exp, /* o : array of sector diffuseness exponents, flat */ + Word32 *ene_fx, /* o : array of sector energy values, flat */ + Word16 *ene_exp /* o : array of sector energy exponents, flat */ +); + +void ivas_mc_paramupmix_enc_fx( + Encoder_Struct *st_ivas, /* i/o: IVAS Encoder handle */ + BSTR_ENC_HANDLE hMetaData, /* i/o: IVAS Metadata bitstream handle */ + Word32 *data_fx[], + const Word16 input_frame /* i : input frame length */ +); + +void ivas_mc_paramupmix_dec_render( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ + const UWord16 nSamplesAsked, /* i : number of CLDFB slots requested */ + UWord16 *nSamplesRendered, /* o : number of CLDFB slots rendered */ + UWord16 *nSamplesAvailable, /* o : number of CLDFB slots still to render */ + Word32 *input_fx[], /* i : core-coder transport channels */ + Word32 *output_fx[] /* i/o: synthesized core-coder transport channels */ +); + +Word16 ivas_param_mc_getNumTransportChannels( + const Word32 ivas_total_bitrate, /* i : IVAS total bitrate */ + const MC_LS_SETUP mc_ls_setup /* i : MC ls setup */ +); + +ivas_error ivas_param_mc_dec_open_fx( + Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ +); + +ivas_error ivas_param_mc_dec_reconfig_fx( + Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ +); + +void ivas_param_mc_dec_close_fx( + PARAM_MC_DEC_HANDLE *hParamMC_out /* i/o: Parametric MC decoder handle */ +); + +void ivas_param_mc_dec_digest_tc_fx( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ + const UWord8 nCldfbSlots, /* i : number of CLFBS slots in the transport channels */ + Word32 *transport_channels_f_fx[], + Word16 transport_f_e ); + +void ivas_param_mc_dec_render_fx( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ + const UWord16 nSamplesAsked, /* i : number of CLDFB slots requested */ + UWord16 *nSamplesRendered, /* o : number of CLDFB slots rendered */ + UWord16 *nSamplesAvailable, /* o : number of CLDFB slots still to render */ + Word32 *output_f_fx[], /* o : rendered time signal */ + Word16 channel_active_fx[MAX_OUTPUT_CHANNELS] ); + +Word16 matrix_product_mant_exp_fx( + const Word32 *X_fx, /* i : left hand matrix */ + const Word16 X_fx_e, /* i : left hand matrix */ + const Word16 rowsX, /* i : number of rows of the left hand matrix */ + const Word16 colsX, /* i : number of columns of the left hand matrix */ + const Word16 transpX, /* i : flag indicating the transposition of the left hand matrix prior to the multiplication */ + const Word32 *Y_fx, /* i : right hand matrix */ + const Word16 Y_fx_e, /* i : right hand matrix */ + const Word16 rowsY, /* i : number of rows of the right hand matrix */ + const Word16 colsY, /* i : number of columns of the right hand matrix */ + const Word16 transpY, /* i : flag indicating the transposition of the right hand matrix prior to the multiplication */ + Word32 *Z_fx, /* o : resulting matrix after the matrix multiplication */ + Word16 *Z_fx_e /* o : resulting matrix after the matrix multiplication */ +); + +Word16 matrix_product_fx( + const Word32 *X_fx, /* i : left hand matrix */ + const Word16 rowsX, /* i : number of rows of the left hand matrix */ + const Word16 colsX, /* i : number of columns of the left hand matrix */ + const Word16 transpX, /* i : flag indicating the transposition of the left hand matrix prior to the multiplication */ + const Word32 *Y_fx, /* i : right hand matrix */ + const Word16 rowsY, /* i : number of rows of the right hand matrix */ + const Word16 colsY, /* i : number of columns of the right hand matrix */ + const Word16 transpY, /* i : flag indicating the transposition of the right hand matrix prior to the multiplication */ + Word32 *Z_fx /* o : resulting matrix after the matrix multiplication */ +); + +Word16 matrix_product_q30_fx( + const Word32 *X_fx, /* i : left hand matrix */ + const Word16 rowsX, /* i : number of rows of the left hand matrix */ + const Word16 colsX, /* i : number of columns of the left hand matrix */ + const Word16 transpX, /* i : flag indicating the transposition of the left hand matrix prior to the multiplication */ + const Word32 *Y_fx, /* i : right hand matrix */ + const Word16 rowsY, /* i : number of rows of the right hand matrix */ + const Word16 colsY, /* i : number of columns of the right hand matrix */ + const Word16 transpY, /* i : flag indicating the transposition of the right hand matrix prior to the multiplication */ + Word32 *Z_fx /* o : resulting matrix after the matrix multiplication */ +); + +Word16 matrix_product_mant_exp( + const Word32 *X_fx, /* i : left hand matrix */ + const Word16 *X_e, /* i : left hand matrix */ + const Word16 rowsX, /* i : number of rows of the left hand matrix */ + const Word16 colsX, /* i : number of columns of the left hand matrix */ + const Word16 transpX, /* i : flag indicating the transposition of the left hand matrix prior to the multiplication */ + const Word32 *Y_fx, /* i : right hand matrix */ + const Word16 *Y_e, /* i : right hand matrix */ + const Word16 rowsY, /* i : number of rows of the right hand matrix */ + const Word16 colsY, /* i : number of columns of the right hand matrix */ + const Word16 transpY, /* i : flag indicating the transposition of the right hand matrix prior to the multiplication */ + Word32 *Z_fx, /* o : resulting matrix after the matrix multiplication */ + Word16 *Z_e /* o : resulting matrix after the matrix multiplication */ +); + +void mat2svdMat_fx( + const Word32 *mat, /* i : matrix as column ordered vector Qx*/ + Word32 svdMat[MAX_OUTPUT_CHANNELS][MAX_OUTPUT_CHANNELS], /* o : matrix as two-dimensional arry Qx*/ + const Word16 nRows, /* i : number of rows of the matrix Q0*/ + const Word16 mCols, /* i : number of columns of the matrix Q0*/ + const Word16 transpose /* i : flag indication transposition Q0*/ +); + +void svdMat2mat_fx( + Word32 svdMat[MAX_OUTPUT_CHANNELS][MAX_OUTPUT_CHANNELS], /* i : matrix as two-dimensional arry Qx*/ + Word32 *mat, /* o : matrix as column ordered vector Qx*/ + const Word16 nRows, /* i : number of rows of the matrix Q0*/ + const Word16 mCols /* i : number of columns of the matrix Q0*/ +); + +Word16 computeMixingMatrices_fx( + const Word16 num_inputs, /* i : number of input channels */ + const Word16 num_outputs, /* i : number of output channels */ + const Word32 *Cx, /* i : input channel covariance matrix */ + Word16 Cx_e, + const Word32 *Cy, /* i : target covariance matrix */ + Word16 Cy_e, + const Word32 *Q, /* i : prototype matrix (usually a upmix matrix) */ + Word16 Q_fx_e, + const Word16 energy_compensation_flag, /* i : flag indicating that the energy compensation should be performed (i.e. no residual mixing matrix will follow) */ + const Word32 reg_Sx_fx, /* i : regularization factor for the input channel singular values */ + Word16 reg_Sx_e, + const Word32 reg_ghat_fx, /* i : regularization factor for the normalization matrix */ + Word16 reg_ghat_e, + Word32 *mixing_matrix_fx, /* o : resulting mixing matrix */ + Word16 *mixing_matrix_out_e, + Word32 *Cr_fx, /* o : residual covariance matrix */ + Word16 *Cr_e ); + +Word16 computeMixingMatricesResidual_fx( + const Word32 num_outputs, /* i : number of output channels */ + const Word32 *Cx_fx, /* i : vector containing the diagonal diffuse prototype covariance */ + const Word16 Cx_e, + const Word32 *Cy_fx, /* i : matrix containing the missing cov (Cr from computeMixingMatrices()) */ + const Word16 Cy_fx_e, + const Word32 reg_Sx_fx, /* i : regularization factor for the input channel singular values */ + const Word16 reg_Sx_e, + const Word32 reg_ghat_fx, /* i : regularization factor for the normalization matrix */ + const Word16 reg_ghat_e, + Word32 *mixing_matrix_fx, /* o : resulting residual mixing matrix */ + Word16 *mixing_matrix_ret_e ); + +Word16 svd_fx( + Word32 InputMatrix[][MAX_OUTPUT_CHANNELS], /* i : matrix to be decomposed (M) InputMatrix_e*/ + Word16 InputMatrix_e, + Word32 singularVectors_Left_fx[][MAX_OUTPUT_CHANNELS], /* o : left singular vectors (U) Q31*/ + Word32 singularValues_fx[MAX_OUTPUT_CHANNELS], /* o : singular values vector (S) singularValues_fx_e*/ + Word32 singularVectors_Right_fx[][MAX_OUTPUT_CHANNELS], /* o : right singular vectors (V) Q31*/ + Word16 singularValues_fx_e[MAX_OUTPUT_CHANNELS], + const Word16 nChannelsL, /* i : number of rows in the matrix to be decomposed Q0*/ + const Word16 nChannelsC /* i : number of columns in the matrix to be decomposed Q0*/ +); + +ivas_error ivas_dirac_dec_output_synthesis_cov_open_fx( + DIRAC_OUTPUT_SYNTHESIS_PARAMS *h_dirac_output_synthesis_params, /* i/o: handle for the covariance synthesis parameters */ + DIRAC_OUTPUT_SYNTHESIS_COV_STATE *h_dirac_output_synthesis_state, /* i/o: hanlde for the covariance synthesis state */ + const Word16 max_band_decorr, /* i : uppermost frequency band where decorrelation is applied */ + const Word16 interp_length, /* i : length for interpolating the mixing matrices in time slots */ + const Word16 num_param_bands, /* i : number of parameter bands */ + const Word16 num_param_bands_residual, /* i : number of parameter bands with a residual mixing matrix (i.e. decorrelation */ + const Word16 nchan_in, /* i : number of input (transport) channels */ + const Word16 nchan_out, /* i : number of output channels */ + const Word32 *proto_matrix /* i : the prototype (upmix) matrix (only used if mode == 1) */ +); + +void ivas_dirac_dec_output_synthesis_get_interpolator_fx( + DIRAC_OUTPUT_SYNTHESIS_PARAMS *h_dirac_output_synthesis_params, /* i/o: handle for the covariance synthesis parameters */ + const UWord16 interp_length /* i : interpolator length */ +); + +void ivas_dirac_dec_output_synthesis_cov_init_fx( + DIRAC_OUTPUT_SYNTHESIS_COV_STATE *h_dirac_output_synthesis_state, /* i/o: pointer to the state of the covariance synthesis */ + const Word16 nchan_in, /* i : number of input (tranport) channels */ + const Word16 nchan_out, /* i : number of output channels */ + const Word16 n_param_bands, /* i : number of total parameter bands */ + const Word16 n_param_bands_res /* i : number of parameter bands with a residual mixing matrix (i.e. decorrelation */ +); + +void ivas_dirac_dec_output_synthesis_cov_param_mc_synthesise_slot_fx( + Word32 *Cldfb_RealBuffer_in_fx, + Word32 *Cldfb_ImagBuffer_in_fx, + Word32 Cldfb_RealBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* o : output channel filter bank samples (real part) */ + Word32 Cldfb_ImagBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* o : output channel filter bank samples (imaginary part) */ + Word32 *mixing_matrix_fx[], /* i : parameter band wise mixing matrices (direct part) */ + Word16 *mixing_matrix_e, /* i : parameter band wise mixing matrices (direct part) */ + Word32 *mixing_matrix_res_fx[], /* i : parameter band wise mixing matrices (residual part) */ + Word16 *mixing_matrix_res_e, /* i : parameter band wise mixing matrices (residual part) */ + const UWord16 slot_idx_sfr, /* i : time slot index for the current slot within the current subframe */ + const UWord16 slot_idx_tot, /* i : time slot index for the current slot within the frame */ + const Word16 nX, /* i : number of input channels */ + const Word16 nY, /* i : number of output channels */ + PARAM_MC_DEC_HANDLE hParamMC /* i : handle to the Parametric MC decoder state */ +); + +Word16 computeMixingMatricesISM_fx( + const Word16 num_inputs, + const Word16 num_responses, + const Word16 num_outputs, + const Word32 *responses_fx, + const Word16 responses_e, + const Word32 *ener_fx, + const Word16 ener_e, + const Word32 *Cx_diag_fx, + const Word16 Cx_diag_e, + const Word32 *Cy_diag_fx, + const Word16 Cy_diag_e, + const Word16 *Q_16fx, // Q15 + const Word16 energy_compensation_flag, + const Word32 reg_Sx_fx, + const Word32 reg_ghat_fx, + Word32 *mixing_matrix_fx, + Word16 *mixing_matrix_e ); + +ivas_error ivas_spar_enc_open_fx( + Encoder_Struct *st_ivas, /* i/o: IVAS encoder handle */ + const Word16 spar_reconfig_flag /* i : SPAR reconfiguration flag */ +); + +void ivas_spar_dec_close_fx( + SPAR_DEC_HANDLE *hSpar, /* i/o: SPAR decoder handle */ + const Word32 output_Fs, /* i : output sampling rate */ + const Word16 spar_reconfig_flag /* i : SPAR reconfiguration flag */ +); + +ivas_error ivas_sba_linear_renderer_fx( + Word32 *output_f[], /* i/o: synthesized core-coder transport channels/DirAC output */ + const Word16 output_frame, /* i : output frame length per channel */ + const Word16 nchan_in, /* i : number of input ambisonics channels */ + const Word16 nchan_ism, /* i : number of objects */ + const AUDIO_CONFIG output_config, /* i : output audio configuration */ + const IVAS_OUTPUT_SETUP output_setup /* i : output format setup */ +); + +void ivas_sba_mix_matrix_determiner_fx( + SPAR_DEC_HANDLE hSpar, /* i/o: SPAR decoder handle */ + Word32 *output_fx[], /* i/o: transport/output audio channels */ + const Word16 bfi, /* i : BFI flag */ + const Word16 nchan_remapped, /* i : num channels after remapping of TCs */ + const Word16 output_frame, /* i : output frame length */ + const Word16 num_md_sub_frames, /* i : number of subframes in mixing matrix*/ + const Word16 Q_output /* i : Q of transport/output audio channels */ +); + +Word16 ivas_agc_enc_get_flag( + const Word16 nchan_transport /* i : number of transport channels */ +); + +ivas_error ivas_spar_agc_enc_open_fx( + ivas_agc_enc_state_t **hAgcEnc, /* i/o: SPAR AGC encoder handle */ + const Word32 input_Fs, /* i : input sampling rate */ + const Word16 nchan_inp /* i : number of input channels */ +); + +void ivas_spar_agc_enc_close_fx( + ivas_agc_enc_state_t **hAgcEnc /* i/o: SPAR AGC encoder handle */ +); + +void ivas_agc_enc_process_fx( + ivas_agc_enc_state_t *hAgcEnc, /* i/o: AGC encoder handle */ + BSTR_ENC_HANDLE hMetaData, /* i/o: MetaData handle */ + Word32 **ppPcm_in, /* i : input audio channels */ + Word32 **ppPcm_out, /* o : output audio channels */ + const Word16 n_channels, /* i : number of channels */ + const ENCODER_CONFIG_HANDLE hEncoderConfig, /* i : configuration structure */ + Word16 *q_ppPcm ); + +void ivas_spar_set_bitrate_config_fx( + ivas_spar_md_com_cfg *pSpar_md_cfg, /* i/o: SPAR MD config. handle */ + const Word16 table_idx, /* i : config. table index */ + const Word16 num_bands, /* i : number of bands */ + const Word16 dirac2spar_md_flag, + const Word16 enc_flag, + const Word16 pca_flag, + const Word16 agc_flag ); + +Word16 ivas_is_res_channel( + const Word16 ch, /* i : ch index in WYZX ordering */ + const Word16 nchan_transport /* i : number of transport channels (1-4) */ +); + +void ivas_spar_dec_agc_pca_fx( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ + Word32 *output[], /* i/o: input/output audio channels */ + const Word16 output_frame /* i : output frame length */ +); + +void ivas_spar_dec_set_render_map_fx( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + const Word16 nCldfbTs /* i : number of CLDFB time slots */ +); + +void ivas_spar_dec_set_render_params_fx( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ + const Word16 n_cldfb_slots /* i : number of cldfb slots in this frame */ +); + +void ivas_spar_dec_digest_tc_fx( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ + const Word16 nchan_transport, /* i : number of transport channels */ + const Word16 nCldfbSlots, /* i : number of CLDFB slots */ + const Word16 nSamplesForRendering /* i : number of samples provided */ +); + +void ivas_sba_dec_digest_tc_fx( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ + const Word16 nCldfbSlots, /* i : number of CLDFB slots */ + const Word16 nSamplesForRendering /* i : number of samples provided */ +); +ivas_error ivas_sba_dec_render_fx( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ + const UWord16 nSamplesAsked, /* i : number of CLDFB slots requested */ + UWord16 *nSamplesRendered, /* o : number of CLDFB slots rendered */ + UWord16 *nSamplesAvailableNext, /* o : number of CLDFB slots still to render */ + Word32 *output_fx[], /* o : rendered time signal Q11*/ + Word16 out_len /*Store the length of values in each channel*/ +); + +void ivas_spar_dec_upmixer_sf_fx( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ + Word32 *output_fx[], /* o : output audio channels */ + const Word16 nchan_internal, /* i : number of internal channels */ + Word16 out_len ); + +ivas_error ivas_spar_md_enc_open_fx( + ivas_spar_md_enc_state_t **hMdEnc_in, /* i/o: SPAR MD encoder handle */ + const ENCODER_CONFIG_HANDLE hEncoderConfig, /* i : configuration structure */ + const Word16 sba_order /* i : Ambisonic (SBA) order */ +); + +void ivas_create_fullr_dmx_mat_fx( + Word32 pred_coeffs_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], + Word16 q_pred_coeffs_re, + Word32 dm_fv_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], + Word16 q_dm_fv_re, + Word32 ***mixer_mat, + Word16 *q_mixer_mat, + const Word16 in_chans, + const Word16 start_band, + const Word16 end_band, + const Word16 active_w, + ivas_spar_md_com_cfg *hMdCfg ); + +void ivas_get_spar_md_from_dirac_fx( + Word32 azi_dirac_fx[IVAS_MAX_NUM_BANDS][MAX_PARAM_SPATIAL_SUBFRAMES], // Q22 + Word32 ele_dirac_fx[IVAS_MAX_NUM_BANDS][MAX_PARAM_SPATIAL_SUBFRAMES], // Q22 + Word32 diffuseness_fx[IVAS_MAX_NUM_BANDS], // Q30 + const Word16 n_ts, + Word32 ***mixer_mat_fx, + Word16 *q_mixer_mat_fx, + ivas_spar_md_t *hSpar_md, + ivas_spar_md_com_cfg *hSpar_md_cfg, + const Word16 start_band, + const Word16 end_band, + const Word16 order, + const Word16 dtx_vad, + Word32 Wscale_d[IVAS_MAX_NUM_BANDS], // Q29 + const UWord8 useLowerRes, + const Word16 active_w_vlbr, + const Word16 dyn_active_w_flag ); + +ivas_error ivas_spar_md_enc_process_fx( + ivas_spar_md_enc_state_t *hMdEnc, /* i/o: SPAR MD encoder handle */ + const ENCODER_CONFIG_HANDLE hEncoderConfig, /* i : configuration structure */ + Word32 *cov_real_fx[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + Word16 *cov_real_q[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + Word32 *cov_dtx_real_fx[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + Word16 *cov_dtx_real_q[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + BSTR_ENC_HANDLE hMetaData, /* i/o: MetaData handle */ + const Word16 dtx_vad, + const Word16 nchan_inp, + const Word16 sba_order, /* i : Ambisonic (SBA) order */ + float *prior_mixer[IVAS_MAX_FB_MIXER_OUT_CH][IVAS_MAX_SPAR_FB_MIXER_IN_CH], /* i : prior mixer_matrix */ + const Word16 dyn_active_w_flag, /* i : flag to indicate dynamic active W */ + const Word16 dirac_mono_flag /* i : flag to indicate mono only mode in SBA */ +); + +Word16 ivas_get_spar_dec_md_num_subframes( + const Word16 sba_order, /* i : Ambisonic (SBA) order */ + const Word32 ivas_total_brate, /* i : IVAS total bitrate */ + const Word32 ivas_last_active_brate /* i : IVAS last active bitrate */ +); + +void ivas_spar_get_parameters_fx( + SPAR_DEC_HANDLE hSpar, /* i/o: SPAR decoder handle */ + const DECODER_CONFIG_HANDLE hDecoderConfig, /* i : configuration structure */ + const Word16 ts, /* i : time slot index */ + const Word16 num_ch_out, /* i : number of channels out */ + const Word16 num_ch_in, /* i : number of channels in */ + const Word16 num_spar_bands, /* i : number of SPAR bands */ + Word32 par_mat_fx[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH][IVAS_MAX_NUM_BANDS] /* o : mixing matrix */ +); + +void ivas_spar_to_dirac_fx( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ + ivas_spar_md_dec_state_t *hMdDec, /* i/o: SPAR MD decoder handle */ + const Word16 dtx_vad, /* i : DTX frame flag */ + const Word16 num_bands_out, /* i : number of output bands */ + const Word16 bw, /* i : band joining factor */ + const Word16 dyn_active_w_flag /* i : dynamic active W flag */ +); + +void ivas_spar_dec_gen_umx_mat_fx( + ivas_spar_md_dec_state_t *hMdDec, /* i/o: SPAR MD decoder handle */ + const Word16 nchan_transport, /* i : number of transport channels */ + const Word16 num_bands_out, /* i : number of output bands */ + const Word16 bfi, /* i : bad frame indicator */ + const Word16 num_md_sub_frames ); + +ivas_error ivas_spar_covar_enc_open_fx( + ivas_enc_cov_handler_state_t **hCovEnc, /* i/o: SPAR Covar. encoder handle */ + ivas_filterbank_t *pFb, /* i/o: FB handle */ + const Word32 input_Fs, /* i : input sampling rate */ + const Word16 nchan_inp, /* i : number of input channels */ + const COV_SMOOTHING_TYPE smooth_mode, /* i : Smooth covariance for SPAR or MC*/ + const Word32 ivas_total_brate /* i : IVAS total bitrate */ +); + +void ivas_spar_covar_enc_close_fx( + ivas_enc_cov_handler_state_t **hCovEnc, /* i/o: SPAR Covar. encoder handle */ + const Word16 nchan_inp /* i : number of input channels */ +); + +void ivas_enc_cov_handler_process_fx( + ivas_enc_cov_handler_state_t *hCovEnc, /* i/o: SPAR Covar. encoder handle */ + Word32 **ppIn_FR_real, + Word32 **ppIn_FR_imag, + Word16 q_ppIn_FR, + Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + Word16 *q_cov_real[IVAS_SPAR_MAX_CH], + Word32 *cov_dtx_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + Word16 *q_cov_dtx_real[IVAS_SPAR_MAX_CH], + ivas_filterbank_t *pFb, /* i/o: FB handle */ + const Word16 start_band, + const Word16 end_band, + const Word16 num_ch, + const Word16 dtx_vad, + const Word16 transient_det[2], + const Word16 HOA_md_ind[IVAS_SPAR_MAX_CH], + Word16 *res_ind, + const Word16 *remix_order, + Word16 *dyn_active_w_flag, + const Word16 nchan_transport, + const Word16 is_sba ); + +ivas_error ivas_spar_covar_smooth_enc_open_fx( + ivas_cov_smooth_state_t **hCovState, /* i/o: SPAR Covar. smoothing handle */ + const ivas_cov_smooth_cfg_t *cov_smooth_cfg, /* i : SPAR config. handle */ + ivas_filterbank_t *pFb, /* i/o: FB handle */ + const Word16 nchan_inp, /* i : number of input channels */ + const COV_SMOOTHING_TYPE smooth_mode, /* i : Smooth covariance for SPAR or MC */ + const Word32 ivas_total_brate /* i : IVAS total bitrate */ +); + +void ivas_spar_covar_smooth_enc_close_fx( + ivas_cov_smooth_state_t **hCovState, /* i/o: SPAR Covar. encoder handle */ + const Word16 nchan_inp /* i : number of input channels */ +); + +void ivas_cov_smooth_process_fx( + ivas_cov_smooth_state_t *hCovState, /* i/o: Covariance state handle */ + Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + ivas_filterbank_t *pFb, /* i/o: FB handle */ + const Word16 start_band, + const Word16 end_band, + const Word16 num_ch, + const Word16 transient_det[2], + Word16 *q_cov[IVAS_SPAR_MAX_CH] ); + +void ivas_pca_enc_fx( + const ENCODER_CONFIG_HANDLE hEncoderConfig, /* i : configuration structure */ + PCA_ENC_STATE *hPCA, /* i : PCA encoder structure */ + BSTR_ENC_HANDLE hMetaData, /* i/o: MetaData handle */ + Word32 *data_f[8], /* i : input/transformed audio channels Q11 */ + const Word16 input_frame, /* i : input frame length */ + const Word16 n_channels /* i : number of channels */ +); + +void cov_subfr_fx( + Word32 **ptr_sig_fx, // Q11 + Word64 *r_fx_64, // Q11 + const Word16 n_channels, + const Word16 len ); + +void ivas_pca_read_bits_fx( + Decoder_State *st0, /* i/o: decoder state structure - for bitstream handling*/ + PCA_DEC_STATE *hPCA /* i/o: PCA encoder structure */ +); + +void ivas_pca_dec_init_fx( + PCA_DEC_STATE *hPCA /* i/o: PCA decoder structure */ +); + +void ivas_pca_dec_fx( + PCA_DEC_STATE *hPCA, /* i/o: PCA decoder structure */ + const Word16 output_frame, /* i : output frame length */ + const Word16 n_channels, /* i : number of channels */ + const Word32 ivas_total_brate, /* i : IVAS total bitrate */ + const Word32 last_ivas_total_brate, /* i : last IVAS total bitrate */ + const Word16 bfi, /* i : bad frame indicator */ + Word32 *pcm_out[] /* o : output audio channels */ +); + +void eye_matrix_fx( + Word16 *mat, + const Word16 n, + const Word16 d ); + +void eye_matrix_fx32( + Word32 *mat, // Q + const Word16 n, + const Word32 d ); // Q + +void eig_qr_fx( + const Word32 *A_fx, // A_q + Word16 A_q, + const Word16 num_iter, + Word32 *EV_fx, // Q31 + Word32 *Vals_fx, // A_q + const Word16 n ); + +void exhst_4x4_fx( + Word16 *cost_mtx, // Q + Word16 *path, + const Word16 maximize ); + +Word16 mat_det4_fx( + const Word16 *m // Q15 +); + +void mat2dquat_fx( + const Word16 *a, // Q15 + Word16 *ql, // Q15 + Word16 *qr // Q15 +); + +void dquat2mat_fx( + const Word16 *ql, + const Word16 *qr, + Word16 *m ); + +void quat_shortestpath_fx( + const Word16 *q00, + Word16 *q01, + const Word16 *q10, + Word16 *q11 ); + +void pca_interp_preproc_fx( + const Word16 *prev_ql, + const Word16 *prev_qr, + const Word16 *ql, + const Word16 *qr, + const Word16 len, + Word16 *ql_interp, + Word16 *qr_interp ); + +void pca_dec_s3_fx( + const Word32 index, + Word16 *q ); + +void ivas_spar_huff_coeffs_com_init( + ivas_huff_coeffs_t *pHuff_coeffs, + ivas_spar_md_com_cfg *pSpar_cfg, + const Word16 table_idx, + const Word16 enc_dec ); + +void ivas_spar_arith_coeffs_com_init( + ivas_arith_coeffs_t *pArith_coeffs, + ivas_spar_md_com_cfg *pSpar_cfg, + const Word16 table_idx, + const Word16 enc_dec ); + +void ivas_ari_start_decoding_14bits_ext_1_lfe( + Decoder_State *st, + Tastat *s, + Word16 *extra_bits_read ); + +UWord16 ivas_ari_decode_14bits_bit_ext_1_lfe( + Decoder_State *st, + Tastat *s, + const UWord16 *cum_freq, + Word16 *extra_bits_read ); + +void ivas_ari_done_decoding_14bits_ext_1_lfe( + Decoder_State *st, + const Word16 extra_bits_read ); + +Word16 quantize_phi_fx( + Word32 phi, /* i : azimuth value */ + const Word16 flag_delta, /* i : flag indicating if the azimuth codebook is translated or not */ + Word32 *phi_hat, /* o : quantized azimuth */ + const Word16 n /* i : azimuth codebook size */ +); + +Word16 quantize_phi_enc_fx( + Word32 phi, /* i : azimuth value */ + const Word16 flag_delta, /* i : flag indicating if the azimuth codebook is translated or not */ + Word32 *phi_hat, /* o : quantized azimuth */ + const Word16 n /* i : azimuth codebook size */ +); + +Word16 ivas_spar_chk_zero_coefs_fx( + Decoder_Struct *st_ivas /* i/o: IVAS decoder handle */ +); + +void pca_enc_s3_fx( + Word16 *q, // Q15 + Word32 *index ); + +void ivas_spar_get_uniform_quant_strat_fx( + ivas_spar_md_com_cfg *pSpar_md_com_cfg, + const Word16 table_idx ); + +void ivas_lfe_lpf_select_filt_coeff_fx( + const Word32 sampling_rate, /* i : sampling rate */ + const Word16 order, /* i : filter order */ + const Word32 **ppFilt_coeff_fx, /* o : filter coefficients */ + const Word16 **ppFilt_coeff_e /* o : exponents of filter coefficients */ +); + +void ivas_filters_init_fx( + ivas_filters_process_state_t *filter_state, /* i/o: filter state handle */ + const Word32 *filt_coeff, /* i : filter coefficients */ + const Word16 *filt_coeff_e, /* i : exponents of filter coefficients */ + const Word16 order /* i : filter order */ +); + +void ivas_decision_matrix_enc_fx( + Encoder_State *st, /* i : encoder state structure */ + const Word32 element_brate, /* i : element bitrate */ + const Word16 fft_buff[], /* i : FFT buffer */ + const Word32 enerBuffer[], /* i : energy buffer */ + Word16 enerBuffer_exp, + const Word16 last_element_mode /* i : last element mode */ +); + +void stereo_dft_dec_sid_coh_fx( + Decoder_State *st, /* i/o: decoder state structure */ + const Word16 nbands, /* i : number of DFT stereo bands Q0*/ + Word16 *coh, /* i/o: coherence Q15*/ + Word16 *nb_bits /* i/o: number of bits read Q0*/ +); + +void stereo_tca_init_enc_fx( + STEREO_TCA_ENC_HANDLE hStereoTCA, /* i/o: Stereo ICA handle */ + const Word32 input_Fs /* i : input sampling frequency */ +); + +void stereo_tca_dec_fx( + CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ + Word32 *synth[CPE_CHANNELS], /* i/o: output synth qsynth*/ + const Word16 output_frame /* i : length of a frame per channel Q0*/ +); + +void stereo_tca_scale_R_channel_fx( + CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ + Word32 *output_fx, /* i/o: output synthesis, R channel q_out*/ + const Word16 output_frame /* i : frame length Q0*/ +); + +void adjustTargetSignal_fx( + Word32 *target_fx, + const Word16 prevShift, + const Word16 currShift, + const Word16 L_shift_adapt, + const Word16 method ); + +void stereo_icBWE_init_enc_fx( + STEREO_ICBWE_ENC_HANDLE hStereoICBWE /* i/o: Stereo inter-channel BWE handle */ +); + +void stereo_classifier_init_fx( + STEREO_CLASSIF_HANDLE hStereoClassif /* i/o: stereo classifier structure */ +); + +void stereo_td_init_dec_fx( + STEREO_TD_DEC_DATA_HANDLE hStereoTD, /* i/o: TD stereo decoder handle */ + const Word16 last_element_mode /* i : last element mode Q0*/ +); + +void initMdctStereoEncData_fx( + STEREO_MDCT_ENC_DATA *hStereoMdct, /* i/o: mdct stereo parameters structure */ + const IVAS_FORMAT ivas_format, /* i : IVAS format */ + const Word16 element_mode, /* i : element mode */ + const Word32 element_brate, /* i : element bitrate */ + const Word16 bwidth, /* i : bandwidth */ + const Word16 igf, /* i : flag indicating IGF activity */ + const H_IGF_GRID hIgfGrid, /* i : IGF grid setup */ + const Word16 mem_init /* i : initialize memory after malloc */ +); + +void deindex_sph_idx_fx( + const UWord16 sphIndex, /* i : Spherical index */ + const SPHERICAL_GRID_DATA *gridData, /* i : Prepared spherical grid */ + Word32 *theta_fx, /* o : Elevation */ + Word32 *phi_fx /* o : Azimuth */ +); + +ivas_error ivas_dirac_enc_open_fx( + Encoder_Struct *st_ivas /* i/o: IVAS encoder handle */ +); + +void ivas_dirac_enc_close_fx( + DIRAC_ENC_HANDLE *hDirAC, /* i/o: encoder DirAC handle */ + const Word32 input_Fs /* i : input sampling_rate */ +); + +ivas_error ivas_dirac_enc_fx( + DIRAC_ENC_HANDLE hDirAC, /* i/o: encoder DirAC handle */ + IVAS_QMETADATA_HANDLE hQMetaData, /* i/o: q_metadata handle */ + BSTR_ENC_HANDLE hMetaData, /* i/o: Metadata bitstream handle */ + Word32 *data_f[], /* i/o: SBA channels */ + Word32 **ppIn_FR_real, /* o : real freq domain values */ + Word32 **ppIn_FR_imag, /* o : imag freq domain values */ + Word16 pp_fr_q, + const Word16 input_frame, /* i : input frame length */ + const Word16 dtx_vad, /* i : DTX vad flag */ + const IVAS_FORMAT ivas_format, /* i : ivas format */ + const Word16 hodirac_flag /* i : hodirac flag */ +); + +ivas_error ivas_spar_md_enc_init_fx( + ivas_spar_md_enc_state_t *hMdEnc, /* o : MD encoder handle */ + const ENCODER_CONFIG_HANDLE hEncoderConfig, /* i : configuration structure */ + const Word16 sba_order /* i : Ambisonic (SBA) order */ +); + +void ivas_spar_get_cldfb_gains_fx( + SPAR_DEC_HANDLE hSpar, + HANDLE_CLDFB_FILTER_BANK cldfbAnaDec0, + HANDLE_CLDFB_FILTER_BANK cldfbSynDec0, + const DECODER_CONFIG_HANDLE hDecoderConfig ); + + #endif diff --git a/lib_com/ivas_qmetadata_com.c b/lib_com/ivas_qmetadata_com.c index 552adb118..88821d0b3 100644 --- a/lib_com/ivas_qmetadata_com.c +++ b/lib_com/ivas_qmetadata_com.c @@ -990,25 +990,26 @@ void invdct4_transform( } #else void invdct4_transform_fx( - Word32 *v_fx, /* i : input vector */ - UWord8 *invdct_v, /* o : inverse transformed vector */ + Word32 *v_fx, /* i : input vector q */ + UWord8 *invdct_v, /* o : inverse transformed vector */ Word16 q ) { Word32 a_fx, b_fx, c_fx, d_fx; Word16 i; Word32 f_invdct_v_fx[4]; - a_fx = L_add( v_fx[0], v_fx[2] ); - b_fx = L_sub( v_fx[0], v_fx[2] ); - c_fx = L_shl( L_add( Mpy_32_32( 1402911360, v_fx[1] ), Mpy_32_32( 581104896, v_fx[3] ) ), Q31 - Q30 ); - d_fx = L_shl( L_sub( Mpy_32_32( 581104896, v_fx[1] ), Mpy_32_32( 1402911360, v_fx[3] ) ), Q31 - Q30 ); - f_invdct_v_fx[0] = L_shl( L_add( a_fx, c_fx ), 7 ); + a_fx = L_add( v_fx[0], v_fx[2] ); // q + b_fx = L_sub( v_fx[0], v_fx[2] ); // q + // 1.306562964876376f * 2 ^ 30 -> 1402911360, 0.541196100146198f * 2 ^ 30 -> 581104896 + c_fx = L_shl( L_add( Mpy_32_32( 1402911360, v_fx[1] ), Mpy_32_32( 581104896, v_fx[3] ) ), Q31 - Q30 ); // q + d_fx = L_shl( L_sub( Mpy_32_32( 581104896, v_fx[1] ), Mpy_32_32( 1402911360, v_fx[3] ) ), Q31 - Q30 ); // q + f_invdct_v_fx[0] = L_shl( L_add( a_fx, c_fx ), 7 ); // q move32(); - f_invdct_v_fx[1] = L_shl( L_add( b_fx, d_fx ), 7 ); + f_invdct_v_fx[1] = L_shl( L_add( b_fx, d_fx ), 7 ); // q move32(); - f_invdct_v_fx[2] = L_shl( L_sub( b_fx, d_fx ), 7 ); + f_invdct_v_fx[2] = L_shl( L_sub( b_fx, d_fx ), 7 ); // q move32(); - f_invdct_v_fx[3] = L_shl( L_sub( a_fx, c_fx ), 7 ); + f_invdct_v_fx[3] = L_shl( L_sub( a_fx, c_fx ), 7 ); // q move32(); FOR( i = 0; i < 4; i++ ) @@ -1022,10 +1023,10 @@ void invdct4_transform_fx( { IF( GT_32( f_invdct_v_fx[i], L_shl( 255, q ) ) ) { - f_invdct_v_fx[i] = L_shl( 255, q ); + f_invdct_v_fx[i] = L_shl( 255, q ); // q move32(); } - invdct_v[i] = (UWord8) L_shr( f_invdct_v_fx[i], q ); + invdct_v[i] = (UWord8) L_shr( f_invdct_v_fx[i], q ); // Q0 move16(); } } @@ -1180,16 +1181,17 @@ void ivas_qmetadata_azimuth_elevation_to_direction_vector( } #else void ivas_qmetadata_azimuth_elevation_to_direction_vector_fx( - const Word32 az, /* i : azimuth Q22 */ - const Word32 el, /* i : elevation Q22 */ - Word32 *dv /* o : direction vector */ + const Word32 az, /* i : azimuth Q22 */ + const Word32 el, /* i : elevation Q22 */ + Word32 *dv /* o : direction vector Q30 */ ) { Word16 radius_length; Word16 elevation_fx, azimuth_fx; - elevation_fx = extract_l( L_shr( Mpy_32_32( el, 5965232 ), 7 ) ); - azimuth_fx = extract_l( L_shr( Mpy_32_32( az, 5965232 ), 7 ) ); + // (2 ^ 31 - 1) / 360 -> 5965232 + elevation_fx = extract_l( L_shr( Mpy_32_32( el, ONE_BY_360_Q31 ), 7 ) ); // ( ( Q22 + Q31 - Q31 ) - Q7 ) -> Q15 + azimuth_fx = extract_l( L_shr( Mpy_32_32( az, ONE_BY_360_Q31 ), 7 ) ); // ( ( Q22 + Q31 - Q31 ) - Q7 ) -> Q15 dv[2] = L_shl( getSineWord16R2( elevation_fx ), Q15 ); /* Q30 */ move32(); @@ -1226,10 +1228,10 @@ void ivas_qmetadata_direction_vector_to_azimuth_elevation( #ifdef IVAS_FLOAT_FIXED void ivas_qmetadata_direction_vector_to_azimuth_elevation_fx( - const Word32 *dv, /* i : direction vector */ + const Word32 *dv, /* i : direction vector dv_q */ const Word16 dv_q, - Word32 *az, /* o : azimuth */ - Word32 *el /* o : elevation */ + Word32 *az, /* o : azimuth Q22 */ + Word32 *el /* o : elevation Q22 */ ) { /* note: dv does not need to have unit L_2 norm, because the conversion is scale invariant */ @@ -1237,9 +1239,11 @@ void ivas_qmetadata_direction_vector_to_azimuth_elevation_fx( Word16 e_tmp; L_tmp = L_add( Mpy_32_32( dv[0], dv[0] ), Mpy_32_32( dv[1], dv[1] ) ); /* 2 * dv_q - 31 */ e_tmp = shl( sub( 31, dv_q ), 1 ); - L_tmp = Sqrt32( L_tmp, &e_tmp ); + L_tmp = Sqrt32( L_tmp, &e_tmp ); // e_tmp + // 29335 -> 180 / PI in Q9 *el = L_mult0( BASOP_util_atan2( dv[2], L_tmp, sub( sub( 31, dv_q ), e_tmp ) ), 29335 ); /* Q22 */ move32(); + // 29335 -> 180 / PI in Q9 *az = L_mult0( BASOP_util_atan2( dv[1], dv[0], 0 ), 29335 ); /* Q22 */ move32(); return; diff --git a/lib_com/ivas_qspherical_com.c b/lib_com/ivas_qspherical_com.c index 4c15510fe..52cfb9323 100644 --- a/lib_com/ivas_qspherical_com.c +++ b/lib_com/ivas_qspherical_com.c @@ -441,9 +441,9 @@ Word16 quantize_phi_fx( Word32 inv_delta_phi_fx; Word32 temp_res; - delta_phi_fx = delta_phi_val[n]; + delta_phi_fx = delta_phi_val[n]; // Q22 move32(); - inv_delta_phi_fx = inv_delta_phi_val[n]; + inv_delta_phi_fx = inv_delta_phi_val[n]; // Q31 move32(); IF( EQ_16( n, 1 ) ) { @@ -465,8 +465,8 @@ Word16 quantize_phi_fx( move32(); } - temp_res = Mpy_32_32( L_sub( L_sub( phi, DEGREE_180_Q_22 ), dd_fx ), inv_delta_phi_fx ); - id_phi = round_fx( L_shr( temp_res, Q22 - Q16 ) ); + temp_res = Mpy_32_32( L_sub( L_sub( phi, DEGREE_180_Q_22 ), dd_fx ), inv_delta_phi_fx ); // Q22 + Q31 - Q31 -> Q22 + id_phi = round_fx( L_shr( temp_res, Q22 - Q16 ) ); // Q0 assert( L_sub( L_abs( temp_res ), abs( id_phi ) * ONE_IN_Q22 ) <= ONE_IN_Q21 ); @@ -497,7 +497,7 @@ ELSE } } -*phi_hat = L_add_sat( L_add_sat( ( id_phi * delta_phi_fx ), dd_fx ), DEGREE_180_Q_22 ); +*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 ) ); @@ -676,8 +676,8 @@ Word32 companding_azimuth_fx( const Word16 direction /* i : direction of companding (direct or inverse)*/ ) { - const Word16 pointsA[] = { 0, 60, 110, 150, 180, 0, 50, 90, 150, 180, 0, 30, 80, 150, 180 }; - const Word16 pointsB[] = { 0, 90, 110, 170, 180, 0, 90, 110, 170, 180, 0, 10, 100, 170, 180 }; + const Word16 pointsA[] = { 0, 60, 110, 150, 180, 0, 50, 90, 150, 180, 0, 30, 80, 150, 180 }; // Q0 + const Word16 pointsB[] = { 0, 90, 110, 170, 180, 0, 90, 110, 170, 180, 0, 10, 100, 170, 180 }; // Q0 const Word16 *pA; const Word32 pointsA_fx[] = { 0, 251658240, 461373440, 629145600, 754974720, 0, 209715200, 377487360, 629145600, 754974720, 0, 125829120, 335544320, 629145600, 754974720 }; // q=22 const Word32 pointsB_fx[] = { 0, 377487360, 461373440, 713031680, 754974720, 0, 377487360, 461373440, 713031680, 754974720, 0, 41943040, 419430400, 713031680, 754974720 }; // q=22 @@ -806,38 +806,46 @@ Word32 companding_azimuth_fx( not_done = 0; move16(); /* calculate companding */ - comp_azi_fx = Mpy_32_32( L_sub( pB_fx[i + 1], pB_fx[i] ), L_sub( abs_azi_fx, pA_fx[i] ) ); + comp_azi_fx = Mpy_32_32( L_sub( pB_fx[i + 1], pB_fx[i] ), L_sub( abs_azi_fx, pA_fx[i] ) ); // ( Q22 + Q22 - Q31 ) -> Q13 SWITCH( sub( pA[i + 1], pA[i] ) ) { case 10: - comp_azi_fx = Mpy_32_32( comp_azi_fx, 214748364 ); + // Q13 + Q31 - Q31 -> Q13 + comp_azi_fx = Mpy_32_32( comp_azi_fx, 214748364 ); // 1 / 10 in 2 ^ 31 BREAK; case 20: - comp_azi_fx = Mpy_32_32( comp_azi_fx, 107374182 ); + // Q13 + Q31 - Q31 -> Q13 + comp_azi_fx = Mpy_32_32( comp_azi_fx, 107374182 ); // 1 / 20 in 2 ^ 31 BREAK; case 30: - comp_azi_fx = Mpy_32_32( comp_azi_fx, 71582788 ); + // Q13 + Q31 - Q31 -> Q13 + comp_azi_fx = Mpy_32_32( comp_azi_fx, 71582788 ); // 1 / 30 in 2 ^ 31 BREAK; case 40: - comp_azi_fx = Mpy_32_32( comp_azi_fx, 53687091 ); + // Q13 + Q31 - Q31 -> Q13 + comp_azi_fx = Mpy_32_32( comp_azi_fx, 53687091 ); // 1 / 40 in 2 ^ 31 BREAK; case 50: - comp_azi_fx = Mpy_32_32( comp_azi_fx, 42949672 ); + // Q13 + Q31 - Q31 -> Q13 + comp_azi_fx = Mpy_32_32( comp_azi_fx, 42949672 ); // 1 / 50 in 2 ^ 31 BREAK; case 60: - comp_azi_fx = Mpy_32_32( comp_azi_fx, 35791394 ); + // Q13 + Q31 - Q31 -> Q13 + comp_azi_fx = Mpy_32_32( comp_azi_fx, 35791394 ); // 1 / 60 in 2 ^ 31 BREAK; case 70: - comp_azi_fx = Mpy_32_32( comp_azi_fx, 30678337 ); + // Q13 + Q31 - Q31 -> Q13 + comp_azi_fx = Mpy_32_32( comp_azi_fx, 30678337 ); // 1 / 70 in 2 ^ 31 BREAK; case 90: - comp_azi_fx = Mpy_32_32( comp_azi_fx, 23860929 ); + // Q13 + Q31 - Q31 -> Q13 + comp_azi_fx = Mpy_32_32( comp_azi_fx, 23860929 ); // 1 / 90 in 2 ^ 31 BREAK; default: assert( 0 ); BREAK; } - comp_azi_fx = L_add( pB_fx[i], L_shl( comp_azi_fx, 31 - 22 ) ); + comp_azi_fx = L_add( pB_fx[i], L_shl( comp_azi_fx, Q22 - Q13 ) ); // Q22 // comp_azi = pB[i] + ( pB[i + 1] - pB[i] ) / ( pA[i + 1] - pA[i] ) * ( abs_azi - pA[i] ); } ELSE @@ -848,16 +856,16 @@ Word32 companding_azimuth_fx( IF( azi_fx < 0 ) { - comp_azi_fx = L_negate( comp_azi_fx ); + comp_azi_fx = L_negate( comp_azi_fx ); // Q22 } IF( EQ_16( not_done, 1 ) ) { - comp_azi_fx = azi_fx; + comp_azi_fx = azi_fx; // Q22 move32(); } - return comp_azi_fx; + return comp_azi_fx; // Q22 } #endif @@ -926,7 +934,7 @@ Word16 quantize_phi_chan_lbr_fx( IF( phi < 0 && id_phi > 0 ) { id_phi = sub( shl( id_phi, 1 ), 1 ); - *phi_hat = L_negate( *phi_hat ); + *phi_hat = L_negate( *phi_hat ); // Q22 move32(); } ELSE @@ -1038,8 +1046,8 @@ Word16 quantize_phi_chan_compand_fx( delta_phi = BASOP_Util_Divide3232_Scale_cadence( 360, n, &tmp_e ); delta_phi = L_shr( delta_phi, sub( 9, tmp_e ) ); // Q22 // id_phi = (int16_t) round_f( ( phi / (float) delta_phi ) ); - id_phi = BASOP_Util_Divide3232_Scale( phi, delta_phi, &tmp_e ); - id_phi = shr( id_phi, sub( 15, tmp_e ) ); + id_phi = BASOP_Util_Divide3232_Scale( phi, delta_phi, &tmp_e ); // Q15 + id_phi = shr( id_phi, sub( 15, tmp_e ) ); // Q0 IF( add( id_phi, shr( n, 1 ) ) < 0 ) { @@ -1066,14 +1074,14 @@ ELSE } } //*phi_hat = id_phi * delta_phi; -*phi_hat = imult3216( delta_phi, id_phi ); +*phi_hat = imult3216( delta_phi, id_phi ); // Q22 move32(); // 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 ); +*phi_hat = L_add( companding_azimuth_fx( *phi_hat, mc_format, theta_flag, -1 ), DEGREE_180_Q_22 ); // Q22 move32(); return id_phi; diff --git a/lib_com/ivas_rom_com.c b/lib_com/ivas_rom_com.c index 9f08e3dfe..805900f8f 100644 --- a/lib_com/ivas_rom_com.c +++ b/lib_com/ivas_rom_com.c @@ -58,13 +58,13 @@ const int32_t ivas_brate_tbl[SIZE_IVAS_BRATE_TBL] = *------------------------------------------------------------------------*/ /*4xERB scale: max of 14 bands*/ -const int16_t dft_band_limits_erb4[STEREO_DFT_ERB4_BANDS] = +const Word16 dft_band_limits_erb4[STEREO_DFT_ERB4_BANDS] = { 1, 3, 5, 10, 18, 26, 41, 56, 84, 132, 214, 342, 470, 601 }; /*8xERB scale: max of 8 bands*/ -const int16_t dft_band_limits_erb8[STEREO_DFT_ERB8_BANDS] = +const Word16 dft_band_limits_erb8[STEREO_DFT_ERB8_BANDS] = { 1, 5, 18, 41, 84, 214, 470, 601 }; @@ -76,20 +76,21 @@ const float dft_res_cod_alpha[STEREO_DFT_BAND_MAX] = }; #endif -const int16_t dft_band_ipd[3][4] = +const Word16 dft_band_ipd[3][4] = { {0,8,10,13}, {0,5,6,8}, {0,2,3,4} }; -const int16_t dft_band_res_cod[3][4] = +const Word16 dft_band_res_cod[3][4] = { {0,8,10,11}, {0,5,6,7}, {0,5,6,7} }; +// Q31 const Word32 dft_res_gains_q_Q31[][2] = { /* quantization points for joint quantization of prediction gain and residual energy */ @@ -501,17 +502,17 @@ const float dft_trigo_48k[STEREO_DFT_N_MAX_ENC / 4 + 1] = }; /* tables for adaptive Golomb-Rice coding of DFT stereo parameters */ -const int16_t dft_code_itd[] = +const Word16 dft_code_itd[] = { 0, 3, 4, 13, 8, 9, 12, 5, 10, 44, 23, 60, 45, 31, 235, 59, 28, 61, 234, 116 }; -const int16_t dft_len_itd[] = +const Word16 dft_len_itd[] = { 2, 3, 4, 4, 4, 4, 4, 4, 4, 6, 5, 6, 6, 5, 8, 6, 5, 6, 8, 7 }; -const int16_t dft_maps_rpg[] = +const Word16 dft_maps_rpg[] = { 0, 1, 2, 3, 4, 5, 6, 7, 2, 0, 1, 3, 4, 5, 6, 7, @@ -524,7 +525,7 @@ const int16_t dft_maps_rpg[] = 6, 5, 4, 3, 1, 0, 2, 7, }; -const int16_t dft_maps_sg[NO_SYMB_GR_SIDE_G * NO_SYMB_GR_SIDE_G] = +const Word16 dft_maps_sg[NO_SYMB_GR_SIDE_G * NO_SYMB_GR_SIDE_G] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 1, 0, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, @@ -565,7 +566,7 @@ const int16_t dft_maps_sg[NO_SYMB_GR_SIDE_G * NO_SYMB_GR_SIDE_G] = *------------------------------------------------------------------------*/ /* Create separate tables for cumulative frequency and symbol frequency */ -const uint16_t cum_freq_ari_pk_s17_LC_ext[RANGE_N_CONTEXT][1 + RANGE_N_SYMBOLS] = +const UWord16 cum_freq_ari_pk_s17_LC_ext[RANGE_N_CONTEXT][1 + RANGE_N_SYMBOLS] = { { 0,16,47,153,241,269,325,468,591,674,798,912,1017,1082,1183,1277,1364,16384 }, { 0,7401,7844,7886,7899,12065,12718,12790,12805,14099,14476,14533,14549,15058,15264,15299,15310,16384 }, @@ -633,7 +634,7 @@ const uint16_t cum_freq_ari_pk_s17_LC_ext[RANGE_N_CONTEXT][1 + RANGE_N_SYMBOLS] { 0,6720,8878,9325,9467,11564,13248,13744,13929,14384,14880,15087,15167,15311,15488,15569,15607,16384 }, }; -const uint16_t sym_freq_ari_pk_s17_LC_ext[RANGE_N_CONTEXT][RANGE_N_SYMBOLS] = +const UWord16 sym_freq_ari_pk_s17_LC_ext[RANGE_N_CONTEXT][RANGE_N_SYMBOLS] = { { 16,31,106,88,28,56,143,123,83,124,114,105,65,101,94,87,15020 }, { 7401,443,42,13,4166,653,72,15,1294,377,57,16,509,206,35,11,1074 }, @@ -707,7 +708,7 @@ const uint16_t sym_freq_ari_pk_s17_LC_ext[RANGE_N_CONTEXT][RANGE_N_SYMBOLS] = *------------------------------------------------------------------------*/ /* table with round(ECSQ_PROB_TOTAL / index) for entropy coding, with i in {1, .., ECSQ_SEGMENT_SIZE} */ -const uint16_t ECSQ_tab_inverse[1 + ECSQ_SEGMENT_SIZE] = +const UWord16 ECSQ_tab_inverse[1 + ECSQ_SEGMENT_SIZE] = { 0, 16384, 8192, 5461, 4096, 3277, 2731, 2341, 2048 }; @@ -792,7 +793,7 @@ const float tdm_den_ratio_tabl[TDM_NQ+1] = /* 1.0f/(2*LR_ratio*LR_ratio-2*LR_ra 1.2088f, 1.1429f, 1.0902f, 1.0501f, 1.0221f, 1.0000f, 1.0000f, 1.0000f }; -const int16_t tdm_bit_allc_tbl[5][6] = +const Word16 tdm_bit_allc_tbl[5][6] = { /* IC -- UC -- GC -- TM --AC */ { 1650, 3500, 0, 4400, 0, 5000 }, /* IVAS_13k2 */ @@ -879,9 +880,9 @@ const float tdm_PRED_QNT_fixed_beta_prd_diag_3[15 + 16 + 15] = 0.1193f, 0.6574f, }; -const int16_t fast_FCB_bits_2sfr[] = {8, 14, 18, 20, 24, 128/*stop value*/}; +const Word16 fast_FCB_bits_2sfr[] = {8, 14, 18, 20, 24, 128/*stop value*/}; -const int16_t fast_FCB_rates_2sfr[] = {/*16*50,*/ (8+14)*50, 28*50, 32*50, 34*50, 36*50, 38*50, 40*50, 42*50, 44*50, 48*50}; +const Word16 fast_FCB_rates_2sfr[] = {/*16*50,*/ (8+14)*50, 28*50, 32*50, 34*50, 36*50, 38*50, 40*50, 42*50, 44*50, 48*50}; /*----------------------------------------------------------------------------------* @@ -970,11 +971,11 @@ const float dft_cng_coh_pred[STEREO_DFT_N_COH_PRED][STEREO_DFT_COH_PRED_COEFFS] { 1.393664f, -0.131401f, 0.989429f, 0.738330f, 0.683865f, 0.001677f, -0.225448f, -0.012158f, 1.084608f, -0.115464f, 0.022371f, -0.045560f, -0.336230f, 0.422742f, 0.499163f} }; -const int16_t dft_cng_coh_u2i[9] = { 4, 5, 3, 6, 2, 7, 1, 8, 0 }; /* Coherence unary codeword -> residual codeword conversion table */ +const Word16 dft_cng_coh_u2i[9] = { 4, 5, 3, 6, 2, 7, 1, 8, 0 }; /* Coherence unary codeword -> residual codeword conversion table */ -const int16_t dft_cng_coh_i2u[9] = { 8, 6, 4, 2, 0, 1, 3, 5, 7 }; /* Coherence residual codeword -> unary codeword conversion table */ +const Word16 dft_cng_coh_i2u[9] = { 8, 6, 4, 2, 0, 1, 3, 5, 7 }; /* Coherence residual codeword -> unary codeword conversion table */ -const int16_t dft_cng_coh_alpha_start[STEREO_DFT_N_COH_ALPHA_STEPS - 1] = { 15, 16, 17, 18 }; +const Word16 dft_cng_coh_alpha_start[STEREO_DFT_N_COH_ALPHA_STEPS - 1] = { 15, 16, 17, 18 }; const float dft_cng_alpha_bits[STEREO_DFT_N_COH_ALPHA_STEPS][STEREO_DFT_N_COH_ALPHA_LEVELS] = { @@ -1015,28 +1016,28 @@ const float diffuseness_thresholds[DIRAC_DIFFUSE_LEVELS + 1] = 2.0f /* out-of-range large value to make searching easier */ }; -const int16_t DirAC_band_grouping_12[12 + 1] = +const Word16 DirAC_band_grouping_12[12 + 1] = { 0, 1, 2, 3, 4, 5, 6, 7, 11, 17, 25, 40, 60 }; -const int16_t DirAC_band_grouping_6[6 + 1] = +const Word16 DirAC_band_grouping_6[6 + 1] = { 0, 1, 4, 8, 20, 30, 60 }; -const int16_t DirAC_band_grouping_5[5 + 1] = +const Word16 DirAC_band_grouping_5[5 + 1] = { 0, 1, 3, 7, 15, 60 }; -const int16_t DirAC_block_grouping[MAX_PARAM_SPATIAL_SUBFRAMES + 1] = +const Word16 DirAC_block_grouping[MAX_PARAM_SPATIAL_SUBFRAMES + 1] = { 0, 4, 8, 12, 16 }; -const int16_t DirAC_block_grouping_5ms_MDFT[MAX_PARAM_SPATIAL_SUBFRAMES + 1] = +const Word16 DirAC_block_grouping_5ms_MDFT[MAX_PARAM_SPATIAL_SUBFRAMES + 1] = { 0, 1, 2, 3, 4 }; @@ -1686,18 +1687,18 @@ const ivas_huff_models_t ivas_huff_decd_r_consts[TOTAL_DECD_QUANT_STRATS] = /* DTX quantization and bitstream constants */ const float dtx_pd_real_min_max[2] = { 0, 1.6f }; -const int16_t dtx_pd_real_q_levels[3][3] = { { 7,7,7 },{ 7,7,0 },{ 3,0,0 } }; -const int16_t dtx_pr_real_q_levels[3][3] = { { 9,9,9 },{ 9,7,9 },{ 9,5,7 } }; -const int16_t pr_pr_idx_pairs[3][3][2] = { { { 0, 0 },{ 0, 0 },{ 0, 0 } },{ { 0, 0 },{ 0, 0 },{ 0, 0 } },{ { 0, 0 },{ 1, 3 },{ 0, 0 } } }; -const int16_t pr_pd_idx_pairs[3][3][2] = { { { 1, 1 },{ 2, 2 },{ 3, 3 } },{ { 1, 1 },{ 3, 2 },{ 2, 0 } },{ { 2, 1 },{ 0, 0 },{ 0, 0 } } }; +const Word16 dtx_pd_real_q_levels[3][3] = { { 7,7,7 },{ 7,7,0 },{ 3,0,0 } }; +const Word16 dtx_pr_real_q_levels[3][3] = { { 9,9,9 },{ 9,7,9 },{ 9,5,7 } }; +const Word16 pr_pr_idx_pairs[3][3][2] = { { { 0, 0 },{ 0, 0 },{ 0, 0 } },{ { 0, 0 },{ 0, 0 },{ 0, 0 } },{ { 0, 0 },{ 1, 3 },{ 0, 0 } } }; +const Word16 pr_pd_idx_pairs[3][3][2] = { { { 1, 1 },{ 2, 2 },{ 3, 3 } },{ { 1, 1 },{ 3, 2 },{ 2, 0 } },{ { 2, 1 },{ 0, 0 },{ 0, 0 } } }; -const int16_t remix_order_set[1][DIRAC_MAX_ANA_CHANS] = { /* WYZX --> WYXZ... */ +const Word16 remix_order_set[1][DIRAC_MAX_ANA_CHANS] = { /* WYZX --> WYXZ... */ { 0, 1, 3, 2, 4, 5, 6, 7, 8, 9, 10 } }; -const int16_t HOA_keep_ind[IVAS_SPAR_MAX_FB_IN_CHAN] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 15}; -const int16_t HOA_keep_ind_spar[IVAS_SPAR_MAX_CH] = {0, 1, 2, 3, 4, 8, 9, 10, 10, 10, 10}; -const int16_t HOA_keep_ind_spar512[IVAS_SPAR_MAX_CH] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; +const Word16 HOA_keep_ind[IVAS_SPAR_MAX_FB_IN_CHAN] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 15}; +const Word16 HOA_keep_ind_spar[IVAS_SPAR_MAX_CH] = {0, 1, 2, 3, 4, 8, 9, 10, 10, 10, 10}; +const Word16 HOA_keep_ind_spar512[IVAS_SPAR_MAX_CH] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; /*----------------------------------------------------------------------* @@ -1719,7 +1720,7 @@ const int32_t ivas_pca_offset_index1[IVAS_PCA_N1 + 1] = 463455, 463456 }; -const int16_t ivas_pca_offset_index2[2692] = +const Word16 ivas_pca_offset_index2[2692] = { 0, 1, 0, 1, 7, 8, 0, 1, 7, 19, 33, 45, 51, 52, 0, 1, 9, 23, 41, 61, @@ -1993,7 +1994,7 @@ const int16_t ivas_pca_offset_index2[2692] = 10365, 10366 }; -const int16_t ivas_pca_offset_n2[IVAS_PCA_N1] = +const Word16 ivas_pca_offset_n2[IVAS_PCA_N1] = { 0, 2, 6, 14, 24, 38, 56, 76, 100, 126, 156, 188, 224, 262, 302, 346, 392, 442, 494, 548, 604, 664, 726, 790, @@ -2106,53 +2107,53 @@ const Word16 ph1_q_n2_tbl[IVAS_PCA_N1][2] = { /* ph1_q : Q13, n2 : Q0 */ * Parametric MC ROM tables *----------------------------------------------------------------------------------*/ -const int16_t param_mc_band_grouping_20[20 + 1] = +const Word16 param_mc_band_grouping_20[20 + 1] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 14, 17, 20, 23, 27, 33, 40, 52, 60 }; -const int16_t param_mc_coding_band_mapping_20[20] = +const Word16 param_mc_coding_band_mapping_20[20] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; -const int16_t param_mc_bands_coded_20[4] = +const Word16 param_mc_bands_coded_20[4] = { 10, 14, 18, 20 }; -const int16_t param_mc_band_grouping_14[14 + 1] = +const Word16 param_mc_band_grouping_14[14 + 1] = { 0, 1, 2, 3, 4, 5, 6, 8, 10, 13, 16, 20, 28, 40, 60 }; -const int16_t param_mc_coding_band_mapping_14[14] = +const Word16 param_mc_coding_band_mapping_14[14] = { 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0 }; -const int16_t param_mc_bands_coded_14[4] = +const Word16 param_mc_bands_coded_14[4] = { 8, 11, 13, 14 }; -const int16_t param_mc_band_grouping_10[10 + 1] = +const Word16 param_mc_band_grouping_10[10 + 1] = { 0, 1, 2, 3, 5, 7, 10, 14, 20, 40, 60 }; -const int16_t param_mc_bands_coded_10[4] = +const Word16 param_mc_bands_coded_10[4] = { 6, 8, 9, 10 }; -const int16_t param_mc_coding_band_mapping_10[10] = +const Word16 param_mc_coding_band_mapping_10[10] = { 1, 1, 1, 1, 1, 0, 0, 0, 0, 0 }; -const int16_t Param_MC_index[MAX_CICP_CHANNELS] = +const Word16 Param_MC_index[MAX_CICP_CHANNELS] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 }; @@ -2914,161 +2915,161 @@ const float ivas_param_mc_quant_icc[PARAM_MC_SZ_ICC_QUANTIZER] = }; /* Alphabet for delta coding for the ICCs in Parametric MC processing */ -const uint16_t ivas_param_mc_cum_freq_icc_cicp6_48_16bits[PARAM_MC_SZ_ICC_QUANTIZER + 1] = +const UWord16 ivas_param_mc_cum_freq_icc_cicp6_48_16bits[PARAM_MC_SZ_ICC_QUANTIZER + 1] = { 0, 24, 224, 20873, 42384, 51699, 57122, 60572, 65535 }; -const uint16_t ivas_param_mc_sym_freq_icc_cicp6_48_16bits[PARAM_MC_SZ_ICC_QUANTIZER] = +const UWord16 ivas_param_mc_sym_freq_icc_cicp6_48_16bits[PARAM_MC_SZ_ICC_QUANTIZER] = { 24, 200, 20649, 21511, 9315, 5423, 3450, 4963 }; -const uint16_t ivas_param_mc_cum_freq_icc_delta_cicp6_48_16bits[2 * PARAM_MC_SZ_ICC_QUANTIZER] = +const UWord16 ivas_param_mc_cum_freq_icc_delta_cicp6_48_16bits[2 * PARAM_MC_SZ_ICC_QUANTIZER] = { 0, 4, 9, 124, 447, 1311, 4453, 18116, 48636, 60573, 63692, 64746, 65327, 65531, 65534, 65535 }; -const uint16_t ivas_param_mc_sym_freq_icc_delta_cicp6_48_16bits[2 * PARAM_MC_SZ_ICC_QUANTIZER - 1] = +const UWord16 ivas_param_mc_sym_freq_icc_delta_cicp6_48_16bits[2 * PARAM_MC_SZ_ICC_QUANTIZER - 1] = { 4, 5, 115, 323, 864, 3142, 13663, 30520, 11937, 3119, 1054, 581, 204, 3, 1 }; -const uint16_t ivas_param_mc_cum_freq_icc_cicp12_48_16bits[PARAM_MC_SZ_ICC_QUANTIZER + 1] = +const UWord16 ivas_param_mc_cum_freq_icc_cicp12_48_16bits[PARAM_MC_SZ_ICC_QUANTIZER + 1] = { 0, 30, 848, 26611, 47846, 57358, 61679, 63237, 65535 }; -const uint16_t ivas_param_mc_sym_freq_icc_cicp12_48_16bits[PARAM_MC_SZ_ICC_QUANTIZER] = +const UWord16 ivas_param_mc_sym_freq_icc_cicp12_48_16bits[PARAM_MC_SZ_ICC_QUANTIZER] = { 30, 818, 25763, 21235, 9512, 4321, 1558, 2298 }; -const uint16_t ivas_param_mc_cum_freq_icc_delta_cicp12_48_16bits[2 * PARAM_MC_SZ_ICC_QUANTIZER] = +const UWord16 ivas_param_mc_cum_freq_icc_delta_cicp12_48_16bits[2 * PARAM_MC_SZ_ICC_QUANTIZER] = { 0, 2, 7, 53, 243, 979, 3994, 16732, 49642, 61343, 64331, 65158, 65438, 65532, 65534, 65535 }; -const uint16_t ivas_param_mc_sym_freq_icc_delta_cicp12_48_16bits[2 * PARAM_MC_SZ_ICC_QUANTIZER - 1] = +const UWord16 ivas_param_mc_sym_freq_icc_delta_cicp12_48_16bits[2 * PARAM_MC_SZ_ICC_QUANTIZER - 1] = { 2, 5, 46, 190, 736, 3015, 12738, 32910, 11701, 2988, 827, 280, 94, 2, 1 }; -const uint16_t ivas_param_mc_cum_freq_icc_cicp14_48_16bits[PARAM_MC_SZ_ICC_QUANTIZER + 1] = +const UWord16 ivas_param_mc_cum_freq_icc_cicp14_48_16bits[PARAM_MC_SZ_ICC_QUANTIZER + 1] = { 0, 46, 826, 27798, 49552, 58447, 62046, 63284, 65535 }; -const uint16_t ivas_param_mc_sym_freq_icc_cicp14_48_16bits[PARAM_MC_SZ_ICC_QUANTIZER ]={ +const UWord16 ivas_param_mc_sym_freq_icc_cicp14_48_16bits[PARAM_MC_SZ_ICC_QUANTIZER ]={ 46, 780, 26972, 21754, 8895, 3599, 1238, 2251 }; -const uint16_t ivas_param_mc_cum_freq_icc_delta_cicp14_48_16bits[2 * PARAM_MC_SZ_ICC_QUANTIZER] = +const UWord16 ivas_param_mc_cum_freq_icc_delta_cicp14_48_16bits[2 * PARAM_MC_SZ_ICC_QUANTIZER] = { 0, 3, 8, 36, 172, 763, 3436, 15845, 50168, 62005, 64676, 65298, 65481, 65533, 65534, 65535 }; -const uint16_t ivas_param_mc_sym_freq_icc_delta_cicp14_48_16bits[2* PARAM_MC_SZ_ICC_QUANTIZER - 1] = +const UWord16 ivas_param_mc_sym_freq_icc_delta_cicp14_48_16bits[2* PARAM_MC_SZ_ICC_QUANTIZER - 1] = { 3, 5, 28, 136, 591, 2673, 12409, 34323, 11837, 2671, 622, 183, 52, 1, 1 }; -const uint16_t ivas_param_mc_cum_freq_icc_combined_48_16bits[PARAM_MC_SZ_ICC_QUANTIZER + 1] = +const UWord16 ivas_param_mc_cum_freq_icc_combined_48_16bits[PARAM_MC_SZ_ICC_QUANTIZER + 1] = { 0, 34, 552, 24717, 45819, 54772, 59054, 61166, 65535 }; -const uint16_t ivas_param_mc_sym_freq_icc_combined_48_16bits[PARAM_MC_SZ_ICC_QUANTIZER] = +const UWord16 ivas_param_mc_sym_freq_icc_combined_48_16bits[PARAM_MC_SZ_ICC_QUANTIZER] = { 34, 518, 24165, 21102, 8953, 4282, 2112, 4369 }; -const uint16_t ivas_param_mc_cum_freq_icc_delta_combined_48_16bits[2 * PARAM_MC_SZ_ICC_QUANTIZER] = +const UWord16 ivas_param_mc_cum_freq_icc_delta_combined_48_16bits[2 * PARAM_MC_SZ_ICC_QUANTIZER] = { 0, 3, 7, 74, 304, 1009, 3870, 16502, 49834, 61384, 64217, 65020, 65369, 65531, 65534, 65535 }; -const uint16_t ivas_param_mc_sym_freq_icc_delta_combined_48_16bits[2 * PARAM_MC_SZ_ICC_QUANTIZER - 1] = +const UWord16 ivas_param_mc_sym_freq_icc_delta_combined_48_16bits[2 * PARAM_MC_SZ_ICC_QUANTIZER - 1] = { 3, 4, 67, 230, 705, 2861, 12632, 33332, 11550, 2833, 803, 349, 162, 3, 1 }; -const uint16_t ivas_param_mc_cum_freq_ild_cicp6_48_16bits[PARAM_MC_SZ_ILD_QUANTIZER_4BITS + 1] = +const UWord16 ivas_param_mc_cum_freq_ild_cicp6_48_16bits[PARAM_MC_SZ_ILD_QUANTIZER_4BITS + 1] = { 0, 1092, 5574, 8315, 10652, 13875, 19656, 27664, 36284, 47058, 56251, 62579, 65118, 65462, 65513, 65532, 65535 }; -const uint16_t ivas_param_mc_sym_freq_ild_cicp6_48_16bits[PARAM_MC_SZ_ILD_QUANTIZER_4BITS] = +const UWord16 ivas_param_mc_sym_freq_ild_cicp6_48_16bits[PARAM_MC_SZ_ILD_QUANTIZER_4BITS] = { 1092, 4482, 2741, 2337, 3223, 5781, 8008, 8620, 10774, 9193, 6328, 2539, 344, 51, 19, 3 }; -const uint16_t ivas_param_mc_cum_freq_ild_delta_cicp6_48_16bits[2 * PARAM_MC_SZ_ILD_QUANTIZER_4BITS] = +const UWord16 ivas_param_mc_cum_freq_ild_delta_cicp6_48_16bits[2 * PARAM_MC_SZ_ILD_QUANTIZER_4BITS] = { 0, 1, 2, 3, 5, 38, 146, 352, 638, 997, 1559, 2323, 3570, 5859, 10556, 21075, 44682, 55617, 60408, 62739, 63833, 64443, 64809, 65074, 65279, 65400, 65484, 65531, 65532, 65533, 65534, 65535 }; -const uint16_t ivas_param_mc_sym_freq_ild_delta_cicp6_48_16bits[2 * PARAM_MC_SZ_ILD_QUANTIZER_4BITS - 1] = +const UWord16 ivas_param_mc_sym_freq_ild_delta_cicp6_48_16bits[2 * PARAM_MC_SZ_ILD_QUANTIZER_4BITS - 1] = { 1, 1, 1, 2, 33, 108, 206, 286, 359, 562, 764, 1247, 2289, 4697, 10519, 23607, 10935, 4791, 2331, 1094, 610, 366, 265, 205, 121, 84, 47, 1, 1, 1, 1 }; -const uint16_t ivas_param_mc_cum_freq_ild_cicp12_48_16bits[PARAM_MC_SZ_ILD_QUANTIZER_4BITS + 1] = +const UWord16 ivas_param_mc_cum_freq_ild_cicp12_48_16bits[PARAM_MC_SZ_ILD_QUANTIZER_4BITS + 1] = { 0, 967, 6335, 9941, 12837, 16652, 22416, 29814, 38807, 48497, 57184, 62661, 64916, 65466, 65514, 65530, 65535 }; -const uint16_t ivas_param_mc_sym_freq_ild_cicp12_48_16bits[PARAM_MC_SZ_ILD_QUANTIZER_4BITS] = +const UWord16 ivas_param_mc_sym_freq_ild_cicp12_48_16bits[PARAM_MC_SZ_ILD_QUANTIZER_4BITS] = { 967, 5368, 3606, 2896, 3815, 5764, 7398, 8993, 9690, 8687, 5477, 2255, 550, 48, 16, 5 }; -const uint16_t ivas_param_mc_cum_freq_ild_delta_cicp12_48_16bits[2 * PARAM_MC_SZ_ILD_QUANTIZER_4BITS] = +const UWord16 ivas_param_mc_cum_freq_ild_delta_cicp12_48_16bits[2 * PARAM_MC_SZ_ILD_QUANTIZER_4BITS] = { 0, 1, 2, 3, 5, 18, 61, 149, 320, 592, 1083, 1793, 2974, 5257, 10133, 21274, 44342, 55891, 60895, 63174, 64244, 64793, 65100, 65287, 65406, 65477, 65517, 65531, 65532, 65533, 65534, 65535 }; -const uint16_t ivas_param_mc_sym_freq_ild_delta_cicp12_48_16bits[2 * PARAM_MC_SZ_ILD_QUANTIZER_4BITS - 1] = +const UWord16 ivas_param_mc_sym_freq_ild_delta_cicp12_48_16bits[2 * PARAM_MC_SZ_ILD_QUANTIZER_4BITS - 1] = { 1, 1, 1, 2, 13, 43, 88, 171, 272, 491, 710, 1181, 2283, 4876, 11141, 23068, 11549, 5004, 2279, 1070, 549, 307, 187, 119, 71, 40, 14, 1, 1, 1, 1 }; -const uint16_t ivas_param_mc_cum_freq_ild_cicp14_48_16bits[PARAM_MC_SZ_ILD_QUANTIZER_4BITS + 1] = +const UWord16 ivas_param_mc_cum_freq_ild_cicp14_48_16bits[PARAM_MC_SZ_ILD_QUANTIZER_4BITS + 1] = { 0, 229, 7068, 10910, 13856, 17467, 22629, 29174, 36906, 46558, 55579, 61802, 65222, 65505, 65527, 65534, 65535 }; -const uint16_t ivas_param_mc_sym_freq_ild_cicp14_48_16bits[PARAM_MC_SZ_ILD_QUANTIZER_4BITS] = +const UWord16 ivas_param_mc_sym_freq_ild_cicp14_48_16bits[PARAM_MC_SZ_ILD_QUANTIZER_4BITS] = { 229, 6839, 3842, 2946, 3611, 5162, 6545, 7732, 9652, 9021, 6223, 3420, 283, 22, 7, 1 }; -const uint16_t ivas_param_mc_cum_freq_ild_delta_cicp14_48_16bits[2 * PARAM_MC_SZ_ILD_QUANTIZER_4BITS] = +const UWord16 ivas_param_mc_cum_freq_ild_delta_cicp14_48_16bits[2 * PARAM_MC_SZ_ILD_QUANTIZER_4BITS] = { 0, 1, 2, 3, 4, 12, 56, 153, 278, 475, 856, 1430, 2489, 4723, 9580, 20685, 45423, 56274, 60948, 63097, 64128, 64679, 65002, 65208, 65348, 65445, 65517, 65531, 65532, 65533, 65534, 65535 }; -const uint16_t ivas_param_mc_sym_freq_ild_delta_cicp14_48_16bits[2 * PARAM_MC_SZ_ILD_QUANTIZER_4BITS - 1] = +const UWord16 ivas_param_mc_sym_freq_ild_delta_cicp14_48_16bits[2 * PARAM_MC_SZ_ILD_QUANTIZER_4BITS - 1] = { 1, 1, 1, 1, 8, 44, 97, 125, 197, 381, 574, 1059, 2234, 4857, 11105, 24738, 10851, 4674, 2149, 1031, 551, 323, 206, 140, 97, 72, 14, 1, 1, 1, 1 }; -const uint16_t ivas_param_mc_cum_freq_ild_combined_48_16bits[PARAM_MC_SZ_ILD_QUANTIZER_4BITS+1] = +const UWord16 ivas_param_mc_cum_freq_ild_combined_48_16bits[PARAM_MC_SZ_ILD_QUANTIZER_4BITS+1] = { 0, 1453, 8326, 12221, 15164, 18764, 24177, 31297, 39520, 49154, 57135, 62460, 64821, 65468, 65514, 65530, 65535 }; -const uint16_t ivas_param_mc_sym_freq_ild_combined_48_16bits[PARAM_MC_SZ_ILD_QUANTIZER_4BITS] = +const UWord16 ivas_param_mc_sym_freq_ild_combined_48_16bits[PARAM_MC_SZ_ILD_QUANTIZER_4BITS] = { 1453, 6873, 3895, 2943, 3600, 5413, 7120, 8223, 9634, 7981, 5325, 2361, 647, 46, 16, 5 }; -const uint16_t ivas_param_mc_cum_freq_ild_delta_combined_48_16bits[2 * PARAM_MC_SZ_ILD_QUANTIZER_4BITS] = +const UWord16 ivas_param_mc_cum_freq_ild_delta_combined_48_16bits[2 * PARAM_MC_SZ_ILD_QUANTIZER_4BITS] = { 0, 1, 2, 3, 5, 29, 98, 220, 414, 699, 1186, 1876, 3049, 5304, 10013, 20612, 45247, 56109, 60818, 63022, 64081, 64647, 64977, 65198, 65348, 65443, 65502, 65530, 65532, 65533, 65534, 65535 }; -const uint16_t ivas_param_mc_sym_freq_ild_delta_combined_48_16bits[2 * PARAM_MC_SZ_ILD_QUANTIZER_4BITS - 1] = +const UWord16 ivas_param_mc_sym_freq_ild_delta_combined_48_16bits[2 * PARAM_MC_SZ_ILD_QUANTIZER_4BITS - 1] = { 1, 1, 1, 2, 24, 69, 122, 194, 285, 487, 690, 1173, 2255, 4709, 10599, 24635, 10862, 4709, 2204, 1059, 566, 330, 221, 150, 95, 59, 28, 2, 1, 1, 1 }; @@ -3156,7 +3157,7 @@ const Word32 diffuseness_thresholds_hr_fx[HR_MASA_ER_LEVELS + 1] = { /* Q30 */ MAX_32 /* out-of-range large value to make searching easier */ }; -const int16_t bits_direction_masa[DIRAC_DIFFUSE_LEVELS] = +const Word16 bits_direction_masa[DIRAC_DIFFUSE_LEVELS] = { 11, 11, @@ -3218,7 +3219,7 @@ const float coherence_cb1_masa[MASA_NO_CV_COH1*MASA_MAXIMUM_CODING_SUBBANDS] = 0.0017f, 0.2521f, -0.2479f, 0.7217f, -0.7157f }; -const int16_t len_cb_dct0_masa[DIRAC_DIFFUSE_LEVELS] = { 7, 6, 5, 4, 4, 4, 3, 2 }; +const Word16 len_cb_dct0_masa[DIRAC_DIFFUSE_LEVELS] = { 7, 6, 5, 4, 4, 4, 3, 2 }; const uint8_t sur_coherence_cb_masa[MASA_MAX_NO_CV_SUR_COH*MASA_NO_CB_SUR_COH] = { @@ -3231,18 +3232,18 @@ const uint8_t sur_coherence_cb_masa[MASA_MAX_NO_CV_SUR_COH*MASA_NO_CB_SUR_COH] = 6, 20, 38, 60, 86, 119, 165, 249 }; -const int16_t idx_cb_sur_coh_masa[MASA_MAX_NO_CV_SUR_COH] = { 0, 1, 2, 3, 4, 5, 5, 6 }; +const Word16 idx_cb_sur_coh_masa[MASA_MAX_NO_CV_SUR_COH] = { 0, 1, 2, 3, 4, 5, 5, 6 }; -const int16_t len_huf_masa[MASA_NO_CV_COH1] = { 4, 2, 1, 3, 4 }; +const Word16 len_huf_masa[MASA_NO_CV_COH1] = { 4, 2, 1, 3, 4 }; -const int16_t huff_code_av_masa[MASA_NO_CV_COH1] = { 15, 2, 0, 6, 14 }; +const Word16 huff_code_av_masa[MASA_NO_CV_COH1] = { 15, 2, 0, 6, 14 }; -const int16_t no_theta_masa[NO_SPHERICAL_GRIDS-2] = /* from 1 to 11 bits */ +const Word16 no_theta_masa[NO_SPHERICAL_GRIDS-2] = /* from 1 to 11 bits */ { /*1, 1,*/ 2 ,2 , 4, 5, 6, 7, 10, 14, 19 /*0, 2, 8, 6, 7, 12, 14, 16*/ }; -const int16_t no_phi_masa[NO_SPHERICAL_GRIDS][MAX_NO_THETA] = /* from 1 to 11 bits*/ +const Word16 no_phi_masa[NO_SPHERICAL_GRIDS][MAX_NO_THETA] = /* from 1 to 11 bits*/ { { 2 }, { 4 }, @@ -3278,63 +3279,63 @@ const float azimuth_cb[8] = 0.0f, -180.0f, -90.0f, 90.0f, -45.0f, 45.0f, -135.0f, 135.0f }; -const int16_t MASA_band_grouping_24[24 + 1] = +const Word16 MASA_band_grouping_24[24 + 1] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 25, 30, 40, 60 }; -const int16_t MASA_band_mapping_24_to_18[18 + 1] = +const Word16 MASA_band_mapping_24_to_18[18 + 1] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 14, 17, 20, 21, 22, 23, 24 }; -const int16_t MASA_band_mapping_24_to_12[12 + 1] = +const Word16 MASA_band_mapping_24_to_12[12 + 1] = { 0, 1, 2, 3, 4, 5, 7, 9, 12, 15, 20, 22, 24 }; -const int16_t MASA_band_mapping_24_to_8[8 + 1] = +const Word16 MASA_band_mapping_24_to_8[8 + 1] = { 0, 1, 2, 3, 5, 8, 12, 20, 24 }; -const int16_t MASA_band_mapping_24_to_5[5 + 1] = +const Word16 MASA_band_mapping_24_to_5[5 + 1] = { 0, 1, 3, 7, 15, 24 }; -const int16_t MASA_grouping_8_to_5[8] = +const Word16 MASA_grouping_8_to_5[8] = { 0, 1, 1, 2, 3, 3, 4, 4 }; -const int16_t MASA_grouping_12_to_5[12] = +const Word16 MASA_grouping_12_to_5[12] = { 0, 1, 1, 2, 2, 2, 3, 3, 3, 3, 4, 4 }; -const int16_t MASA_grouping_18_to_5[18] = +const Word16 MASA_grouping_18_to_5[18] = { 0, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4 }; -const int16_t MASA_grouping_24_to_5[24] = +const Word16 MASA_grouping_24_to_5[24] = { 0, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4 }; /* IVAS_13k2, IVAS_16k4, IVAS_24k4, IVAS_32k, IVAS_48k, IVAS_64k, IVAS_80k, IVAS_96k, IVAS_128k, IVAS_160k, IVAS_192k, IVAS_256k, IVAS_384k, IVAS_512k */ -const int16_t masa_bits[IVAS_NUM_ACTIVE_BRATES] = +const Word16 masa_bits[IVAS_NUM_ACTIVE_BRATES] = { 50, 60, 70, 85, 140, 180, 220, 256, 350, 432, 528, 832, 1024, MASA_MAX_BITS }; -const int16_t masa_bits_LR_stereo[4] = +const Word16 masa_bits_LR_stereo[4] = { 50, 50, 60, 70 }; -const int16_t mcmasa_bits[IVAS_NUM_ACTIVE_BRATES] = +const Word16 mcmasa_bits[IVAS_NUM_ACTIVE_BRATES] = { 50, 70, 80, 120, 140, 160, 220, 256, 288, 432, 528, 832, 1024, MASA_MAX_BITS }; @@ -3497,7 +3498,7 @@ const float ism_elevation_borders[4] = * Param ISM ROM tables *----------------------------------------------------------------------------------*/ -const int16_t Param_ISM_band_grouping[MAX_PARAM_ISM_NBANDS + 1] = +const Word16 Param_ISM_band_grouping[MAX_PARAM_ISM_NBANDS + 1] = { 0, 1, 2, 3, 4, 6, 8, 11, 15, 21, 31, 60 }; @@ -3780,7 +3781,7 @@ const ivas_lfe_freq_models ivas_str_lfe_freq_models = { 16384, 4468, 1489, 745, 0 }, 0, }; -const int16_t ivas_lfe_num_ele_in_coder_models[2][4] = +const Word16 ivas_lfe_num_ele_in_coder_models[2][4] = { { 63, 31, 7, 1 },{ 31, 15, 3, 0 } }; @@ -3790,9 +3791,9 @@ const Word16 ivas_lfe_log2_num_ele_in_coder_models_fx[2][4] = { 6, 5, 3, 1 },{ 5, 4, 2, 0 } }; -const int16_t ivas_lfe_num_dct_pass_bins_tbl[IVAS_LFE_NUM_COEFFS_IN_SUBGRP] = { 8, 6 }; +const Word16 ivas_lfe_num_dct_pass_bins_tbl[IVAS_LFE_NUM_COEFFS_IN_SUBGRP] = { 8, 6 }; -const int16_t ivas_lfe_min_shift_tbl[IVAS_LFE_NUM_COEFFS_IN_SUBGRP] = { 1, 0 }; +const Word16 ivas_lfe_min_shift_tbl[IVAS_LFE_NUM_COEFFS_IN_SUBGRP] = { 1, 0 }; const float ivas_lfe_lpf_delay[2] = { 0.00175f, 0.0035f }; const Word16 ivas_lfe_lpf_delay_Q15[2] = { 57, 114 }; @@ -4752,7 +4753,7 @@ const float ivas_cos_twiddle_80[IVAS_80_PT_LEN >> 1] = 0.151584296010041f, 0.112661287574648f, 0.0735645635996675f, 0.0343544083996823f }; -const int16_t dirac_gains_P_idx[16] = +const Word16 dirac_gains_P_idx[16] = { -1, 1, 0, 1, 4, 3, 2, 3, 4, 8, 7, 6, 5, 6, 7, 8 }; @@ -5120,21 +5121,21 @@ const Word32 ivas_fb_fcs_12band_1ms_fx[IVAS_FB_BANDS_12] = 465288128, 715827904, 1091637520, 1735882615 };/*Q31*/ -const int16_t ivas_fb_abs_bins_per_band_12band_1ms[IVAS_NUM_SUPPORTED_FS][IVAS_FB_BANDS_12] = +const Word16 ivas_fb_abs_bins_per_band_12band_1ms[IVAS_NUM_SUPPORTED_FS][IVAS_FB_BANDS_12] = { { 24, 30, 30, 30, 30, 30, 42, 76, 124, 182, 291, 367 }, { 24, 30, 30, 30, 30, 30, 42, 76, 124, 182, 260, 47 }, { 24, 30, 30, 30, 30, 30, 42, 75, 122, 73, 0, 0 } }; -const int16_t ivas_fb_abs_bins_start_offset_12band_1ms[IVAS_NUM_SUPPORTED_FS][IVAS_FB_BANDS_12] = +const Word16 ivas_fb_abs_bins_start_offset_12band_1ms[IVAS_NUM_SUPPORTED_FS][IVAS_FB_BANDS_12] = { {0, 9, 25, 41, 57, 73, 88, 110, 158, 246, 380, 593 }, {0, 9, 25, 41, 57, 73, 88, 110, 158, 246, 380, 593 }, {0, 9, 25, 41, 57, 73, 88, 110, 159, 247, 0, 0 } }; -const int16_t ivas_fb_bins_per_band_12band_1ms[IVAS_NUM_SUPPORTED_FS][IVAS_FB_BANDS_12] = +const Word16 ivas_fb_bins_per_band_12band_1ms[IVAS_NUM_SUPPORTED_FS][IVAS_FB_BANDS_12] = { { IVAS_FB_12_1MS_48K_END_BINS_BAND_0 - IVAS_FB_12_1MS_48K_START_OFFSET_BAND_0, @@ -5180,7 +5181,7 @@ const int16_t ivas_fb_bins_per_band_12band_1ms[IVAS_NUM_SUPPORTED_FS][IVAS_FB_BA }, }; -const int16_t ivas_fb_bins_start_offset_12band_1ms[IVAS_NUM_SUPPORTED_FS][IVAS_FB_BANDS_12] = +const Word16 ivas_fb_bins_start_offset_12band_1ms[IVAS_NUM_SUPPORTED_FS][IVAS_FB_BANDS_12] = { { IVAS_FB_12_1MS_48K_START_OFFSET_BAND_0, IVAS_FB_12_1MS_48K_START_OFFSET_BAND_1, @@ -6275,7 +6276,7 @@ const float ivas_fb_resp_cheby_ramp_16del[IVAS_FB_1MS_16K_SAMP + 1] = 0.500000000000000f }; -const int16_t ivas_num_active_bands[FB - WB + 1] = +const Word16 ivas_num_active_bands[FB - WB + 1] = { IVAS_16K_12BANDS_ACTIVE_BANDS, IVAS_FB_BANDS_12, IVAS_FB_BANDS_12 }; @@ -6284,9 +6285,9 @@ const int16_t ivas_num_active_bands[FB - WB + 1] = * SNS MSVQ codebooks and means *------------------------------------------------------------------------------------------*/ -const int16_t ivas_sns_cdbks_tcx20_levels[SNS_MSVQ_NSTAGES_TCX20] = { 128, 64, 32, 32 }; +const Word16 ivas_sns_cdbks_tcx20_levels[SNS_MSVQ_NSTAGES_TCX20] = { 128, 64, 32, 32 }; -const int16_t ivas_sns_cdbks_tcx20_bits[SNS_MSVQ_NSTAGES_TCX20] = { 7, 6, 5, 5 }; +const Word16 ivas_sns_cdbks_tcx20_bits[SNS_MSVQ_NSTAGES_TCX20] = { 7, 6, 5, 5 }; /* pre-rounded codebook vectors for singed Q4.12 represantation */ const float ivas_sns_cdbk_tcx20_stage1[ 128 * 16 ] = @@ -6563,9 +6564,9 @@ const float ivas_sns_cdbk_tcx20_stage4[ 32 * 16 ] = const float *const ivas_sns_cdbks_tcx20[SNS_MSVQ_NSTAGES_TCX20] = { ivas_sns_cdbk_tcx20_stage1, ivas_sns_cdbk_tcx20_stage2, ivas_sns_cdbk_tcx20_stage3, ivas_sns_cdbk_tcx20_stage4 }; -const int16_t ivas_sns_cdbks_tcx10_levels[SNS_MSVQ_NSTAGES_TCX10] = { 128, 32, 8 }; +const Word16 ivas_sns_cdbks_tcx10_levels[SNS_MSVQ_NSTAGES_TCX10] = { 128, 32, 8 }; -const int16_t ivas_sns_cdbks_tcx10_bits[SNS_MSVQ_NSTAGES_TCX10] = { 7, 5, 3 }; +const Word16 ivas_sns_cdbks_tcx10_bits[SNS_MSVQ_NSTAGES_TCX10] = { 7, 5, 3 }; const float ivas_sns_cdbk_tcx10_stage1[ 128 * 16 ] = { @@ -6749,10 +6750,10 @@ const float ivas_sns_cdbk_tcx10_stage3[ 8 * 16 ] = const float *const ivas_sns_cdbks_tcx10[SNS_MSVQ_NSTAGES_TCX10] = { ivas_sns_cdbk_tcx10_stage1, ivas_sns_cdbk_tcx10_stage2, ivas_sns_cdbk_tcx10_stage3}; -const int16_t ivas_sns_cdbks_side_tcx20_levels[SNS_MSVQ_NSTAGES_SIDE] = { 32, 32 }; -const int16_t ivas_sns_cdbks_side_tcx20_bits[SNS_MSVQ_NSTAGES_SIDE] = { 5, 5 }; -const int16_t ivas_sns_cdbks_side_tcx10_levels[SNS_MSVQ_NSTAGES_SIDE] = { 32, 8 }; -const int16_t ivas_sns_cdbks_side_tcx10_bits[SNS_MSVQ_NSTAGES_SIDE] = { 5, 3 }; +const Word16 ivas_sns_cdbks_side_tcx20_levels[SNS_MSVQ_NSTAGES_SIDE] = { 32, 32 }; +const Word16 ivas_sns_cdbks_side_tcx20_bits[SNS_MSVQ_NSTAGES_SIDE] = { 5, 5 }; +const Word16 ivas_sns_cdbks_side_tcx10_levels[SNS_MSVQ_NSTAGES_SIDE] = { 32, 8 }; +const Word16 ivas_sns_cdbks_side_tcx10_bits[SNS_MSVQ_NSTAGES_SIDE] = { 5, 3 }; const float ivas_sns_cdbks_side_tcx20_stage1[ 32 * 16 ] = { @@ -6879,7 +6880,7 @@ const float ivas_sns_cdbks_side_tcx10_stage2[ 8 * 16 ] = const float *const ivas_sns_cdbks_side_tcx10[SNS_MSVQ_NSTAGES_SIDE] = { ivas_sns_cdbks_side_tcx10_stage1, ivas_sns_cdbks_side_tcx10_stage2 }; -const int16_t sns_1st_cdbk[2][2][8 * 32] = +const Word16 sns_1st_cdbk[2][2][8 * 32] = { { /* split 1 */ { /* TCX 20 */ @@ -7023,7 +7024,7 @@ const int16_t sns_1st_cdbk[2][2][8 * 32] = } }; -const int16_t sns_1st_means_16k[2][16] = +const Word16 sns_1st_means_16k[2][16] = { { /* TCX 20 */ 14210, 19017, 14362, 9309, 5385, 2674, 1055, -211, -1407, -3059, -4393, -8597, -11180, -11756, -12131, -13281, @@ -7033,7 +7034,7 @@ const int16_t sns_1st_means_16k[2][16] = } }; -const int16_t sns_1st_means_25k6[2][16] = +const Word16 sns_1st_means_25k6[2][16] = { { /* TCX 20 */ 14973, 20323, 16461, 9554, 4017, 3103, 1602, 1694, -221, -1401, -6817, -10071, -11503, -11805, -13158, -16749, @@ -7043,7 +7044,7 @@ const int16_t sns_1st_means_25k6[2][16] = } }; -const int16_t sns_1st_means_32k[2][16] = +const Word16 sns_1st_means_32k[2][16] = { { /* TCX 20 */ 15041, 20603, 16969, 10289, 4973, 4283, 3003, 3316, 1684, -259, -6614, -9535, -10363, -11834, -16625, -24930, @@ -7058,7 +7059,7 @@ const int16_t sns_1st_means_32k[2][16] = * MC ParamUpmix ROM tables *-----------------------------------------------------------------------*/ -const int16_t ivas_param_upmx_mx_qmap[33] = +const Word16 ivas_param_upmx_mx_qmap[33] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 7, 6, 5, 4, 3, 2, 1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 7, 6, 5, 4, 3, 2, 1, 0 }; diff --git a/lib_com/ivas_rom_com.h b/lib_com/ivas_rom_com.h index 6d1648c4e..f70ad7937 100644 --- a/lib_com/ivas_rom_com.h +++ b/lib_com/ivas_rom_com.h @@ -45,16 +45,16 @@ * General IVAS ROM tables *----------------------------------------------------------------------------------*/ -extern const int32_t ivas_brate_tbl[]; +extern const Word32 ivas_brate_tbl[]; /*------------------------------------------------------------------------- * DFT Stereo ROM tables *------------------------------------------------------------------------*/ -extern const int16_t dft_band_limits_erb4[]; -extern const int16_t dft_band_limits_erb8[]; -extern const int16_t dft_band_ipd[3][4]; -extern const int16_t dft_band_res_cod[3][4]; +extern const Word16 dft_band_limits_erb4[]; +extern const Word16 dft_band_limits_erb8[]; +extern const Word16 dft_band_ipd[3][4]; +extern const Word16 dft_band_res_cod[3][4]; extern const float dft_res_gains_q[][2]; #ifndef IVAS_FLOAT_FIXED @@ -66,23 +66,23 @@ extern const float dft_trigo_32k[STEREO_DFT_N_32k_ENC / 4 + 1]; extern const float dft_trigo_48k[STEREO_DFT_N_MAX_ENC / 4 + 1]; /* Golomb-Rice encoding tables */ -extern const int16_t dft_maps_rpg[]; -extern const int16_t dft_code_itd[]; -extern const int16_t dft_len_itd[]; -extern const int16_t dft_maps_sg[NO_SYMB_GR_SIDE_G * NO_SYMB_GR_SIDE_G]; +extern const Word16 dft_maps_rpg[]; +extern const Word16 dft_code_itd[]; +extern const Word16 dft_len_itd[]; +extern const Word16 dft_maps_sg[NO_SYMB_GR_SIDE_G * NO_SYMB_GR_SIDE_G]; /*----------------------------------------------------------------------------------* * Range Coder ROM tables *----------------------------------------------------------------------------------*/ -extern const uint16_t cum_freq_ari_pk_s17_LC_ext[RANGE_N_CONTEXT][1 + RANGE_N_SYMBOLS]; -extern const uint16_t sym_freq_ari_pk_s17_LC_ext[RANGE_N_CONTEXT][RANGE_N_SYMBOLS]; +extern const UWord16 cum_freq_ari_pk_s17_LC_ext[RANGE_N_CONTEXT][1 + RANGE_N_SYMBOLS]; +extern const UWord16 sym_freq_ari_pk_s17_LC_ext[RANGE_N_CONTEXT][RANGE_N_SYMBOLS]; /*----------------------------------------------------------------------------------* * ECLVQ Stereo ROM tables *----------------------------------------------------------------------------------*/ -extern const uint16_t ECSQ_tab_inverse[1 + ECSQ_SEGMENT_SIZE]; +extern const UWord16 ECSQ_tab_inverse[1 + ECSQ_SEGMENT_SIZE]; /*----------------------------------------------------------------------------------* * Stereo ICA ROM tables @@ -105,7 +105,7 @@ extern const float icbwe_gsMappingDFT_tbl[]; extern const float tdm_ratio_tabl[]; extern const float tdm_den_ratio_tabl[]; -extern const int16_t tdm_bit_allc_tbl[5][6]; +extern const Word16 tdm_bit_allc_tbl[5][6]; /* LSFs Intra-frame prediction tables */ #ifdef IVAS_FLOAT_FIXED @@ -141,8 +141,8 @@ extern const float tdm_LSF_MEAN_PRED_QNT_IN[M]; extern const float tdm_LSF_MEAN_PRED_QNT[M]; extern const float tdm_PRED_QNT_fixed_beta_prd_diag_3[15 + 16 + 15]; -extern const int16_t fast_FCB_bits_2sfr[]; -extern const int16_t fast_FCB_rates_2sfr[]; +extern const Word16 fast_FCB_bits_2sfr[]; +extern const Word16 fast_FCB_rates_2sfr[]; /*----------------------------------------------------------------------------------* * MDCT Stereo ROM tables @@ -161,11 +161,11 @@ extern const float nf_tw_smoothing_coeffs[N_LTP_GAIN_MEMS]; extern const Word16 dft_cng_coh_pred_fx[][STEREO_DFT_COH_PRED_COEFFS]; extern const float dft_cng_coh_pred[][STEREO_DFT_COH_PRED_COEFFS]; -extern const int16_t dft_cng_coh_u2i[9]; -extern const int16_t dft_cng_coh_i2u[9]; +extern const Word16 dft_cng_coh_u2i[9]; +extern const Word16 dft_cng_coh_i2u[9]; extern const Word16 dft_cng_alpha_bits_fx[STEREO_DFT_N_COH_ALPHA_STEPS][STEREO_DFT_N_COH_ALPHA_LEVELS]; extern const float dft_cng_alpha_bits[STEREO_DFT_N_COH_ALPHA_STEPS][STEREO_DFT_N_COH_ALPHA_LEVELS]; -extern const int16_t dft_cng_coh_alpha_start[STEREO_DFT_N_COH_ALPHA_STEPS - 1]; +extern const Word16 dft_cng_coh_alpha_start[STEREO_DFT_N_COH_ALPHA_STEPS - 1]; /*----------------------------------------------------------------------------------* * DirAC ROM tables @@ -173,11 +173,11 @@ extern const int16_t dft_cng_coh_alpha_start[STEREO_DFT_N_COH_ALPHA_STEPS - 1]; extern const float diffuseness_reconstructions[DIRAC_DIFFUSE_LEVELS]; extern const float diffuseness_thresholds[DIRAC_DIFFUSE_LEVELS + 1]; -extern const int16_t DirAC_band_grouping_12[12 + 1]; -extern const int16_t DirAC_band_grouping_6[6 + 1]; -extern const int16_t DirAC_band_grouping_5[5 + 1]; -extern const int16_t DirAC_block_grouping[MAX_PARAM_SPATIAL_SUBFRAMES + 1]; -extern const int16_t DirAC_block_grouping_5ms_MDFT[MAX_PARAM_SPATIAL_SUBFRAMES + 1]; +extern const Word16 DirAC_band_grouping_12[12 + 1]; +extern const Word16 DirAC_band_grouping_6[6 + 1]; +extern const Word16 DirAC_band_grouping_5[5 + 1]; +extern const Word16 DirAC_block_grouping[MAX_PARAM_SPATIAL_SUBFRAMES + 1]; +extern const Word16 DirAC_block_grouping_5ms_MDFT[MAX_PARAM_SPATIAL_SUBFRAMES + 1]; #ifdef IVAS_FLOAT_FIXED extern const Word32 c_weights_fx[DIRAC_NO_FB_BANDS_MAX]; // Q30 @@ -201,24 +201,24 @@ extern const ivas_huff_models_t ivas_huff_drct_r_consts[TOTAL_DRCT_QUANT_STRATS] extern const ivas_huff_models_t ivas_huff_decd_r_consts[TOTAL_DECD_QUANT_STRATS]; extern const ivas_spar_br_table_t ivas_spar_br_table_consts[IVAS_SPAR_BR_TABLE_LEN]; extern const ivas_spar_br_table_t ivas_spar_br_table_consts_fx[IVAS_SPAR_BR_TABLE_LEN]; -extern const int16_t remix_order_set[1][DIRAC_MAX_ANA_CHANS]; -extern const int16_t HOA_keep_ind[IVAS_SPAR_MAX_FB_IN_CHAN]; -extern const int16_t HOA_keep_ind_spar[IVAS_SPAR_MAX_CH]; -extern const int16_t HOA_keep_ind_spar512[IVAS_SPAR_MAX_CH]; +extern const Word16 remix_order_set[1][DIRAC_MAX_ANA_CHANS]; +extern const Word16 HOA_keep_ind[IVAS_SPAR_MAX_FB_IN_CHAN]; +extern const Word16 HOA_keep_ind_spar[IVAS_SPAR_MAX_CH]; +extern const Word16 HOA_keep_ind_spar512[IVAS_SPAR_MAX_CH]; extern const float dtx_pd_real_min_max[2]; -extern const int16_t dtx_pd_real_q_levels[3][3]; -extern const int16_t dtx_pr_real_q_levels[3][3]; -extern const int16_t pr_pr_idx_pairs[3][3][2]; -extern const int16_t pr_pd_idx_pairs[3][3][2]; +extern const Word16 dtx_pd_real_q_levels[3][3]; +extern const Word16 dtx_pr_real_q_levels[3][3]; +extern const Word16 pr_pr_idx_pairs[3][3][2]; +extern const Word16 pr_pd_idx_pairs[3][3][2]; /*----------------------------------------------------------------------* * PCA ROM tables *-----------------------------------------------------------------------*/ -extern const int32_t ivas_pca_offset_index1[IVAS_PCA_N1 + 1]; -extern const int16_t ivas_pca_offset_index2[2692]; -extern const int16_t ivas_pca_offset_n2[IVAS_PCA_N1]; +extern const Word32 ivas_pca_offset_index1[IVAS_PCA_N1 + 1]; +extern const Word16 ivas_pca_offset_index2[2692]; +extern const Word16 ivas_pca_offset_n2[IVAS_PCA_N1]; extern const Word16 ph1_q_n2_tbl[IVAS_PCA_N1][2]; @@ -226,98 +226,98 @@ extern const Word16 ph1_q_n2_tbl[IVAS_PCA_N1][2]; * Parametric MC ROM tables *----------------------------------------------------------------------------------*/ -extern const int16_t param_mc_band_grouping_20[20 + 1]; -extern const int16_t param_mc_coding_band_mapping_20[20]; -extern const int16_t param_mc_bands_coded_20[4]; -extern const int16_t param_mc_band_grouping_14[14 + 1]; -extern const int16_t param_mc_coding_band_mapping_14[14]; -extern const int16_t param_mc_bands_coded_14[4]; -extern const int16_t param_mc_band_grouping_10[10 + 1]; -extern const int16_t param_mc_coding_band_mapping_10[10]; -extern const int16_t param_mc_bands_coded_10[4]; -extern const int16_t param_mc_start_bin_per_band_20[20]; -extern const int16_t param_mc_active_bins_per_band_20[20]; -extern const int16_t param_mc_start_bin_per_band_14[14]; -extern const int16_t param_mc_active_bins_per_band_14[14]; -extern const int16_t param_mc_start_bin_per_band_10[10]; -extern const int16_t param_mc_active_bins_per_band_10[10]; -extern const int16_t Param_MC_index[MAX_CICP_CHANNELS]; +extern const Word16 param_mc_band_grouping_20[20 + 1]; +extern const Word16 param_mc_coding_band_mapping_20[20]; +extern const Word16 param_mc_bands_coded_20[4]; +extern const Word16 param_mc_band_grouping_14[14 + 1]; +extern const Word16 param_mc_coding_band_mapping_14[14]; +extern const Word16 param_mc_bands_coded_14[4]; +extern const Word16 param_mc_band_grouping_10[10 + 1]; +extern const Word16 param_mc_coding_band_mapping_10[10]; +extern const Word16 param_mc_bands_coded_10[4]; +extern const Word16 param_mc_start_bin_per_band_20[20]; +extern const Word16 param_mc_active_bins_per_band_20[20]; +extern const Word16 param_mc_start_bin_per_band_14[14]; +extern const Word16 param_mc_active_bins_per_band_14[14]; +extern const Word16 param_mc_start_bin_per_band_10[10]; +extern const Word16 param_mc_active_bins_per_band_10[10]; +extern const Word16 Param_MC_index[MAX_CICP_CHANNELS]; extern const PARAM_MC_CONF ivas_param_mc_conf[PARAM_MC_NUM_CONFIGS]; extern const float ivas_param_mc_quant_ild_5d1_48[PARAM_MC_SZ_ILD_QUANTIZER_4BITS]; extern const float ivas_param_mc_quant_icc[PARAM_MC_SZ_ICC_QUANTIZER]; -extern const uint16_t ivas_param_mc_cum_freq_ild_cicp6_48_16bits[PARAM_MC_SZ_ILD_QUANTIZER_4BITS + 1]; -extern const uint16_t ivas_param_mc_sym_freq_ild_cicp6_48_16bits[PARAM_MC_SZ_ILD_QUANTIZER_4BITS]; -extern const uint16_t ivas_param_mc_cum_freq_ild_delta_cicp6_48_16bits[2 * PARAM_MC_SZ_ILD_QUANTIZER_4BITS]; -extern const uint16_t ivas_param_mc_sym_freq_ild_delta_cicp6_48_16bits[2 * PARAM_MC_SZ_ILD_QUANTIZER_4BITS - 1]; -extern const uint16_t ivas_param_mc_cum_freq_icc_cicp6_48_16bits[PARAM_MC_SZ_ICC_QUANTIZER + 1]; -extern const uint16_t ivas_param_mc_sym_freq_icc_cicp6_48_16bits[PARAM_MC_SZ_ICC_QUANTIZER]; -extern const uint16_t ivas_param_mc_cum_freq_icc_delta_cicp6_48_16bits[2 * PARAM_MC_SZ_ICC_QUANTIZER]; -extern const uint16_t ivas_param_mc_sym_freq_icc_delta_cicp6_48_16bits[2 * PARAM_MC_SZ_ICC_QUANTIZER - 1]; - -extern const uint16_t ivas_param_mc_cum_freq_ild_cicp12_48_16bits[PARAM_MC_SZ_ILD_QUANTIZER_4BITS + 1]; -extern const uint16_t ivas_param_mc_sym_freq_ild_cicp12_48_16bits[PARAM_MC_SZ_ILD_QUANTIZER_4BITS]; -extern const uint16_t ivas_param_mc_cum_freq_ild_delta_cicp12_48_16bits[2 * PARAM_MC_SZ_ILD_QUANTIZER_4BITS]; -extern const uint16_t ivas_param_mc_sym_freq_ild_delta_cicp12_48_16bits[2 * PARAM_MC_SZ_ILD_QUANTIZER_4BITS - 1]; -extern const uint16_t ivas_param_mc_cum_freq_icc_cicp12_48_16bits[PARAM_MC_SZ_ICC_QUANTIZER + 1]; -extern const uint16_t ivas_param_mc_sym_freq_icc_cicp12_48_16bits[PARAM_MC_SZ_ICC_QUANTIZER]; -extern const uint16_t ivas_param_mc_cum_freq_icc_delta_cicp12_48_16bits[2 * PARAM_MC_SZ_ICC_QUANTIZER]; -extern const uint16_t ivas_param_mc_sym_freq_icc_delta_cicp12_48_16bits[2 * PARAM_MC_SZ_ICC_QUANTIZER - 1]; - -extern const uint16_t ivas_param_mc_cum_freq_ild_cicp14_48_16bits[PARAM_MC_SZ_ILD_QUANTIZER_4BITS + 1]; -extern const uint16_t ivas_param_mc_sym_freq_ild_cicp14_48_16bits[PARAM_MC_SZ_ILD_QUANTIZER_4BITS]; -extern const uint16_t ivas_param_mc_cum_freq_ild_delta_cicp14_48_16bits[2 * PARAM_MC_SZ_ILD_QUANTIZER_4BITS]; -extern const uint16_t ivas_param_mc_sym_freq_ild_delta_cicp14_48_16bits[2 * PARAM_MC_SZ_ILD_QUANTIZER_4BITS - 1]; -extern const uint16_t ivas_param_mc_cum_freq_icc_cicp14_48_16bits[PARAM_MC_SZ_ICC_QUANTIZER + 1]; -extern const uint16_t ivas_param_mc_sym_freq_icc_cicp14_48_16bits[PARAM_MC_SZ_ICC_QUANTIZER]; -extern const uint16_t ivas_param_mc_cum_freq_icc_delta_cicp14_48_16bits[2 * PARAM_MC_SZ_ICC_QUANTIZER]; -extern const uint16_t ivas_param_mc_sym_freq_icc_delta_cicp14_48_16bits[2 * PARAM_MC_SZ_ICC_QUANTIZER - 1]; - -extern const uint16_t ivas_param_mc_cum_freq_ild_combined_48_16bits[PARAM_MC_SZ_ILD_QUANTIZER_4BITS + 1]; -extern const uint16_t ivas_param_mc_sym_freq_ild_combined_48_16bits[PARAM_MC_SZ_ILD_QUANTIZER_4BITS]; -extern const uint16_t ivas_param_mc_cum_freq_ild_delta_combined_48_16bits[2 * PARAM_MC_SZ_ILD_QUANTIZER_4BITS]; -extern const uint16_t ivas_param_mc_sym_freq_ild_delta_combined_48_16bits[2 * PARAM_MC_SZ_ILD_QUANTIZER_4BITS - 1]; -extern const uint16_t ivas_param_mc_cum_freq_icc_combined_48_16bits[PARAM_MC_SZ_ICC_QUANTIZER + 1]; -extern const uint16_t ivas_param_mc_sym_freq_icc_combined_48_16bits[PARAM_MC_SZ_ICC_QUANTIZER]; -extern const uint16_t ivas_param_mc_cum_freq_icc_delta_combined_48_16bits[2 * PARAM_MC_SZ_ICC_QUANTIZER]; -extern const uint16_t ivas_param_mc_sym_freq_icc_delta_combined_48_16bits[2 * PARAM_MC_SZ_ICC_QUANTIZER - 1]; +extern const UWord16 ivas_param_mc_cum_freq_ild_cicp6_48_16bits[PARAM_MC_SZ_ILD_QUANTIZER_4BITS + 1]; +extern const UWord16 ivas_param_mc_sym_freq_ild_cicp6_48_16bits[PARAM_MC_SZ_ILD_QUANTIZER_4BITS]; +extern const UWord16 ivas_param_mc_cum_freq_ild_delta_cicp6_48_16bits[2 * PARAM_MC_SZ_ILD_QUANTIZER_4BITS]; +extern const UWord16 ivas_param_mc_sym_freq_ild_delta_cicp6_48_16bits[2 * PARAM_MC_SZ_ILD_QUANTIZER_4BITS - 1]; +extern const UWord16 ivas_param_mc_cum_freq_icc_cicp6_48_16bits[PARAM_MC_SZ_ICC_QUANTIZER + 1]; +extern const UWord16 ivas_param_mc_sym_freq_icc_cicp6_48_16bits[PARAM_MC_SZ_ICC_QUANTIZER]; +extern const UWord16 ivas_param_mc_cum_freq_icc_delta_cicp6_48_16bits[2 * PARAM_MC_SZ_ICC_QUANTIZER]; +extern const UWord16 ivas_param_mc_sym_freq_icc_delta_cicp6_48_16bits[2 * PARAM_MC_SZ_ICC_QUANTIZER - 1]; + +extern const UWord16 ivas_param_mc_cum_freq_ild_cicp12_48_16bits[PARAM_MC_SZ_ILD_QUANTIZER_4BITS + 1]; +extern const UWord16 ivas_param_mc_sym_freq_ild_cicp12_48_16bits[PARAM_MC_SZ_ILD_QUANTIZER_4BITS]; +extern const UWord16 ivas_param_mc_cum_freq_ild_delta_cicp12_48_16bits[2 * PARAM_MC_SZ_ILD_QUANTIZER_4BITS]; +extern const UWord16 ivas_param_mc_sym_freq_ild_delta_cicp12_48_16bits[2 * PARAM_MC_SZ_ILD_QUANTIZER_4BITS - 1]; +extern const UWord16 ivas_param_mc_cum_freq_icc_cicp12_48_16bits[PARAM_MC_SZ_ICC_QUANTIZER + 1]; +extern const UWord16 ivas_param_mc_sym_freq_icc_cicp12_48_16bits[PARAM_MC_SZ_ICC_QUANTIZER]; +extern const UWord16 ivas_param_mc_cum_freq_icc_delta_cicp12_48_16bits[2 * PARAM_MC_SZ_ICC_QUANTIZER]; +extern const UWord16 ivas_param_mc_sym_freq_icc_delta_cicp12_48_16bits[2 * PARAM_MC_SZ_ICC_QUANTIZER - 1]; + +extern const UWord16 ivas_param_mc_cum_freq_ild_cicp14_48_16bits[PARAM_MC_SZ_ILD_QUANTIZER_4BITS + 1]; +extern const UWord16 ivas_param_mc_sym_freq_ild_cicp14_48_16bits[PARAM_MC_SZ_ILD_QUANTIZER_4BITS]; +extern const UWord16 ivas_param_mc_cum_freq_ild_delta_cicp14_48_16bits[2 * PARAM_MC_SZ_ILD_QUANTIZER_4BITS]; +extern const UWord16 ivas_param_mc_sym_freq_ild_delta_cicp14_48_16bits[2 * PARAM_MC_SZ_ILD_QUANTIZER_4BITS - 1]; +extern const UWord16 ivas_param_mc_cum_freq_icc_cicp14_48_16bits[PARAM_MC_SZ_ICC_QUANTIZER + 1]; +extern const UWord16 ivas_param_mc_sym_freq_icc_cicp14_48_16bits[PARAM_MC_SZ_ICC_QUANTIZER]; +extern const UWord16 ivas_param_mc_cum_freq_icc_delta_cicp14_48_16bits[2 * PARAM_MC_SZ_ICC_QUANTIZER]; +extern const UWord16 ivas_param_mc_sym_freq_icc_delta_cicp14_48_16bits[2 * PARAM_MC_SZ_ICC_QUANTIZER - 1]; + +extern const UWord16 ivas_param_mc_cum_freq_ild_combined_48_16bits[PARAM_MC_SZ_ILD_QUANTIZER_4BITS + 1]; +extern const UWord16 ivas_param_mc_sym_freq_ild_combined_48_16bits[PARAM_MC_SZ_ILD_QUANTIZER_4BITS]; +extern const UWord16 ivas_param_mc_cum_freq_ild_delta_combined_48_16bits[2 * PARAM_MC_SZ_ILD_QUANTIZER_4BITS]; +extern const UWord16 ivas_param_mc_sym_freq_ild_delta_combined_48_16bits[2 * PARAM_MC_SZ_ILD_QUANTIZER_4BITS - 1]; +extern const UWord16 ivas_param_mc_cum_freq_icc_combined_48_16bits[PARAM_MC_SZ_ICC_QUANTIZER + 1]; +extern const UWord16 ivas_param_mc_sym_freq_icc_combined_48_16bits[PARAM_MC_SZ_ICC_QUANTIZER]; +extern const UWord16 ivas_param_mc_cum_freq_icc_delta_combined_48_16bits[2 * PARAM_MC_SZ_ICC_QUANTIZER]; +extern const UWord16 ivas_param_mc_sym_freq_icc_delta_combined_48_16bits[2 * PARAM_MC_SZ_ICC_QUANTIZER - 1]; /*----------------------------------------------------------------------------------* * MASA ROM tables *----------------------------------------------------------------------------------*/ -extern const int16_t bits_direction_masa[DIRAC_DIFFUSE_LEVELS]; -extern const int16_t no_theta_masa[NO_SPHERICAL_GRIDS - 2]; -extern const int16_t no_phi_masa[NO_SPHERICAL_GRIDS][MAX_NO_THETA]; +extern const Word16 bits_direction_masa[DIRAC_DIFFUSE_LEVELS]; +extern const Word16 no_theta_masa[NO_SPHERICAL_GRIDS - 2]; +extern const Word16 no_phi_masa[NO_SPHERICAL_GRIDS][MAX_NO_THETA]; extern const float delta_theta_masa[NO_SPHERICAL_GRIDS - 2]; extern const float azimuth_cb[8]; extern const float coherence_cb0_masa[DIRAC_DIFFUSE_LEVELS * 2 * MASA_NO_CV_COH]; extern const float coherence_cb1_masa[MASA_NO_CV_COH1 * MASA_MAXIMUM_CODING_SUBBANDS]; /* 25 */ -extern const int16_t len_cb_dct0_masa[DIRAC_DIFFUSE_LEVELS]; -extern const uint8_t sur_coherence_cb_masa[MASA_NO_CB_SUR_COH * MASA_MAX_NO_CV_SUR_COH]; -extern const int16_t idx_cb_sur_coh_masa[MASA_NO_CV_COH]; -extern const int16_t len_huf_masa[MASA_NO_CV_COH1]; -extern const int16_t huff_code_av_masa[MASA_NO_CV_COH1]; - -extern const int16_t MASA_band_grouping_24[24 + 1]; -extern const int16_t MASA_band_mapping_24_to_18[18 + 1]; -extern const int16_t MASA_band_mapping_24_to_12[12 + 1]; -extern const int16_t MASA_band_mapping_24_to_8[8 + 1]; -extern const int16_t MASA_band_mapping_24_to_5[5 + 1]; - -extern const int16_t MASA_grouping_8_to_5[8]; -extern const int16_t MASA_grouping_12_to_5[12]; -extern const int16_t MASA_grouping_18_to_5[18]; -extern const int16_t MASA_grouping_24_to_5[24]; -extern const int16_t masa_bits[14]; -extern const int16_t masa_bits_LR_stereo[4]; -extern const int16_t mcmasa_bits[]; -extern const uint8_t masa_nbands[]; -extern const uint8_t masa_joined_nbands[]; -extern const uint8_t masa_twodir_bands[]; -extern const uint8_t masa_twodir_bands_joined[]; +extern const Word16 len_cb_dct0_masa[DIRAC_DIFFUSE_LEVELS]; +extern const UWord8 sur_coherence_cb_masa[MASA_NO_CB_SUR_COH * MASA_MAX_NO_CV_SUR_COH]; +extern const Word16 idx_cb_sur_coh_masa[MASA_NO_CV_COH]; +extern const Word16 len_huf_masa[MASA_NO_CV_COH1]; +extern const Word16 huff_code_av_masa[MASA_NO_CV_COH1]; + +extern const Word16 MASA_band_grouping_24[24 + 1]; +extern const Word16 MASA_band_mapping_24_to_18[18 + 1]; +extern const Word16 MASA_band_mapping_24_to_12[12 + 1]; +extern const Word16 MASA_band_mapping_24_to_8[8 + 1]; +extern const Word16 MASA_band_mapping_24_to_5[5 + 1]; + +extern const Word16 MASA_grouping_8_to_5[8]; +extern const Word16 MASA_grouping_12_to_5[12]; +extern const Word16 MASA_grouping_18_to_5[18]; +extern const Word16 MASA_grouping_24_to_5[24]; +extern const Word16 masa_bits[14]; +extern const Word16 masa_bits_LR_stereo[4]; +extern const Word16 mcmasa_bits[]; +extern const UWord8 masa_nbands[]; +extern const UWord8 masa_joined_nbands[]; +extern const UWord8 masa_twodir_bands[]; +extern const UWord8 masa_twodir_bands_joined[]; extern const float diffuseness_reconstructions_hr[HR_MASA_ER_LEVELS]; extern const float diffuseness_thresholds_hr[HR_MASA_ER_LEVELS + 1]; @@ -347,7 +347,7 @@ extern const float McMASA_LFEGain_vectors[64]; * MASA and ISM (OMASA) combined format ROM tables *----------------------------------------------------------------------------------*/ -extern const int32_t sep_object_brate[][MAX_NUM_OBJECTS]; +extern const Word32 sep_object_brate[][MAX_NUM_OBJECTS]; extern const float dct4[]; extern const float dct5[]; extern const float dct8[]; @@ -364,7 +364,7 @@ extern const float ism_elevation_borders[4]; * Param ISM ROM tables *----------------------------------------------------------------------------------*/ -extern const int16_t Param_ISM_band_grouping[MAX_PARAM_ISM_NBANDS + 1]; +extern const Word16 Param_ISM_band_grouping[MAX_PARAM_ISM_NBANDS + 1]; /*----------------------------------------------------------------------------------* * LFE coding ROM tables @@ -381,10 +381,10 @@ extern const float ivas_lfe_window_coeff_48k[IVAS_LFE_FADE_LEN_48K]; extern const float ivas_lfe_window_coeff_32k[IVAS_LFE_FADE_LEN_32K]; extern const float ivas_lfe_window_coeff_16k[IVAS_LFE_FADE_LEN_16K]; -extern const int16_t ivas_lfe_num_ele_in_coder_models[2][4]; +extern const Word16 ivas_lfe_num_ele_in_coder_models[2][4]; extern const Word16 ivas_lfe_log2_num_ele_in_coder_models_fx[2][4]; -extern const int16_t ivas_lfe_num_dct_pass_bins_tbl[IVAS_LFE_NUM_COEFFS_IN_SUBGRP]; -extern const int16_t ivas_lfe_min_shift_tbl[IVAS_LFE_NUM_COEFFS_IN_SUBGRP]; +extern const Word16 ivas_lfe_num_dct_pass_bins_tbl[IVAS_LFE_NUM_COEFFS_IN_SUBGRP]; +extern const Word16 ivas_lfe_min_shift_tbl[IVAS_LFE_NUM_COEFFS_IN_SUBGRP]; extern const ivas_lfe_freq_models ivas_str_lfe_freq_models; extern const float ivas_lfe_lpf_delay[2]; extern const Word16 ivas_lfe_lpf_delay_Q15[2]; @@ -414,7 +414,7 @@ extern const float ivas_mdft_coeff_cos_twid_40[IVAS_40_PT_LEN + 1]; extern const float ivas_mdft_coeff_cos_twid_960[IVAS_960_PT_LEN + 1]; extern const float ivas_mdft_coeff_cos_twid_640[IVAS_640_PT_LEN + 1]; extern const float ivas_mdft_coeff_cos_twid_320[IVAS_320_PT_LEN + 1]; -extern const int16_t dirac_gains_P_idx[16]; +extern const Word16 dirac_gains_P_idx[16]; extern const float dirac_gains_norm_term[9]; extern const float dirac_gains_Pnm[91][9]; extern const float dirac_gains_trg_term[181][2]; @@ -429,10 +429,10 @@ extern const Word32 ivas_fb_fcs_12band_1ms_fx[IVAS_FB_BANDS_12]; extern const float ivas_fb_fr_12band_1ms_re[IVAS_FB_12_1MS_LEN]; extern const float ivas_fb_fr_12band_1ms_im[IVAS_FB_12_1MS_LEN]; -extern const int16_t ivas_fb_bins_per_band_12band_1ms[IVAS_NUM_SUPPORTED_FS][IVAS_FB_BANDS_12]; -extern const int16_t ivas_fb_bins_start_offset_12band_1ms[IVAS_NUM_SUPPORTED_FS][IVAS_FB_BANDS_12]; -extern const int16_t ivas_fb_abs_bins_per_band_12band_1ms[IVAS_NUM_SUPPORTED_FS][IVAS_FB_BANDS_12]; -extern const int16_t ivas_fb_abs_bins_start_offset_12band_1ms[IVAS_NUM_SUPPORTED_FS][IVAS_FB_BANDS_12]; +extern const Word16 ivas_fb_bins_per_band_12band_1ms[IVAS_NUM_SUPPORTED_FS][IVAS_FB_BANDS_12]; +extern const Word16 ivas_fb_bins_start_offset_12band_1ms[IVAS_NUM_SUPPORTED_FS][IVAS_FB_BANDS_12]; +extern const Word16 ivas_fb_abs_bins_per_band_12band_1ms[IVAS_NUM_SUPPORTED_FS][IVAS_FB_BANDS_12]; +extern const Word16 ivas_fb_abs_bins_start_offset_12band_1ms[IVAS_NUM_SUPPORTED_FS][IVAS_FB_BANDS_12]; extern const float ivas_fb_cf_4ms_48k[IVAS_FB_4MS_48K_SAMP]; extern const float ivas_fb_cf_1ms_48k[IVAS_FB_1MS_48K_SAMP]; @@ -444,41 +444,41 @@ extern const float ivas_fb_cf_1ms_16k[IVAS_FB_1MS_16K_SAMP]; extern const float ivas_fb_resp_cheby_ramp_32del[IVAS_FB_1MS_32K_SAMP + 1]; extern const float ivas_fb_resp_cheby_ramp_16del[IVAS_FB_1MS_16K_SAMP + 1]; -extern const int16_t ivas_num_active_bands[FB - WB + 1]; +extern const Word16 ivas_num_active_bands[FB - WB + 1]; /*------------------------------------------------------------------------------------------* * SNS MSVQ codebooks and means *------------------------------------------------------------------------------------------*/ -extern const int16_t ivas_sns_cdbks_tcx20_levels[]; -extern const int16_t ivas_sns_cdbks_tcx20_bits[]; +extern const Word16 ivas_sns_cdbks_tcx20_levels[]; +extern const Word16 ivas_sns_cdbks_tcx20_bits[]; -extern const int16_t ivas_sns_cdbks_tcx10_levels[]; -extern const int16_t ivas_sns_cdbks_tcx10_bits[]; +extern const Word16 ivas_sns_cdbks_tcx10_levels[]; +extern const Word16 ivas_sns_cdbks_tcx10_bits[]; extern const float *const ivas_sns_cdbks_tcx20[]; extern const float *const ivas_sns_cdbks_tcx10[]; -extern const int16_t ivas_sns_cdbks_side_tcx20_levels[]; -extern const int16_t ivas_sns_cdbks_side_tcx20_bits[]; -extern const int16_t ivas_sns_cdbks_side_tcx10_levels[]; -extern const int16_t ivas_sns_cdbks_side_tcx10_bits[]; +extern const Word16 ivas_sns_cdbks_side_tcx20_levels[]; +extern const Word16 ivas_sns_cdbks_side_tcx20_bits[]; +extern const Word16 ivas_sns_cdbks_side_tcx10_levels[]; +extern const Word16 ivas_sns_cdbks_side_tcx10_bits[]; extern const float *const ivas_sns_cdbks_side_tcx20[]; extern const float *const ivas_sns_cdbks_side_tcx10[]; /* means and codebooks for the split VQ in the 2-stage SNS VQ */ -extern const int16_t sns_1st_cdbk[2][2][8 * 32]; -extern const int16_t sns_1st_means_16k[2][16]; -extern const int16_t sns_1st_means_25k6[2][16]; -extern const int16_t sns_1st_means_32k[2][16]; +extern const Word16 sns_1st_cdbk[2][2][8 * 32]; +extern const Word16 sns_1st_means_16k[2][16]; +extern const Word16 sns_1st_means_25k6[2][16]; +extern const Word16 sns_1st_means_32k[2][16]; /*----------------------------------------------------------------------* * MC ParamUpmix ROM tables *-----------------------------------------------------------------------*/ -extern const int16_t ivas_param_upmx_mx_qmap[33]; +extern const Word16 ivas_param_upmx_mx_qmap[33]; extern const ACPL_QUANT_TABLE ivas_mc_paramupmix_alpha_quant_table; extern const ACPL_QUANT_TABLE ivas_mc_paramupmix_beta_quant_table[9]; diff --git a/lib_com/ivas_rom_com_fx.c b/lib_com/ivas_rom_com_fx.c index 269c62d28..dc2e0ad4e 100644 --- a/lib_com/ivas_rom_com_fx.c +++ b/lib_com/ivas_rom_com_fx.c @@ -605,6 +605,7 @@ const Word32 pow_10_q23[14] = { #endif /* clang-format on */ +// Q15 const Word16 ivas_tan_panning_gain_dirac_tbl_fx[601] = { SHC( 0x8000 ), SHC( 0x8001 ), @@ -1298,6 +1299,7 @@ const Masa_Diffuseness_Ratios masa_diffuse_ratios[DIRAC_DIFFUSE_LEVELS][DIRAC_DI * Stereo ICA ROM tables *----------------------------------------------------------------------------------*/ +// Q31 const Word32 ica_sincInterp2_fx[2 * SINC_ORDER1 + 1] = { 0, -4988604, 0, 7486127, 0, -12594991, 0, 20905753, 0, -33172179, 0, @@ -1310,10 +1312,12 @@ const Word32 ica_sincInterp2_fx[2 * SINC_ORDER1 + 1] = { -4988604, 0 }; +// Q31 const Word32 ica_sincInterp4_fx[2 * SINC_ORDER1 + 1] = { 0, -7054484, -11890617, -10587094, 0, 17813376, 32618130, 29564408, 0, -46911780, -82209968, -71380208, 0, 105465072, 180201792, 153819952, 0, -226492960, -394310208, -349923872, 0, 621904832, 1345701248, 1925805312, 2147483647, 1925805312, 1345701248, 621904832, 0, -349923872, -394310208, -226492960, 0, 153819952, 180201792, 105465072, 0, -71380208, -82209968, -46911780, 0, 29564408, 32618130, 17813376, 0, -10587094, -11890617, -7054484, 0 }; +// Q31 const Word32 ica_sincInterp6_fx[2 * SINC_ORDER1 + 1] = { 0, -7481833, -15444702, -22462678, -25151328, -18893562, 0, 31359704, 68816112, 99516536, 106796512, 75709536, 0, -111862424, -234090752, -326303712, -341870816, -240232560, 0, 371151744, 833251584, 1319259392, 1748116096, 2042624128, 2147483647, 2042624128, 1748116096, 1319259392, 833251584, 371151744, 0, -240232560, -341870816, -326303712, -234090752, -111862424, 0, 75709536, 106796512, 99516536, 68816112, 31359704, 0, -18893562, -25151328, -22462678, -15444702, -7481833, 0 }; @@ -1476,6 +1480,7 @@ const Word32 diffuseness_reconstructions_fx[DIRAC_DIFFUSE_LEVELS] = { 0, 42467328, 96206848, 170655744, 331087872, 508821504, 678952960, 912785408 }; +// Q30 const Word32 diffuseness_thresholds_fx[DIRAC_DIFFUSE_LEVELS + 1] = { 0, 20447232, @@ -1492,10 +1497,12 @@ const Word32 diffuseness_thresholds_fx[DIRAC_DIFFUSE_LEVELS + 1] = { * SPAR ROM tables *------------------------------------------------------------------------------------------*/ +// Q28 const Word32 dtx_pd_real_min_max_fx[2] = { 0, 429496729 }; +// Q31 const Word32 one_by_q_level[64] = { 0, 2147483647, 1073741824, 715827904, 536870912, 429496736, 357913952, 306783392, 268435456, 238609296, 214748368, @@ -1634,6 +1641,7 @@ const Word32 shoebox_sin_cos_tbl_fx[11][2] = { { 0, 1073741824 }, // 0 { 759250112, -759250112 }, { -759250112, -759250112 } }; // 135, -135 //Q.30 +// Q22 const Word32 delta_phi_val[90] = { 0, 1509949440, 754974720, 503316480, 377487360, 301989888, 251658240, 215707056, 188743680, 167772160, 150994944, @@ -1655,6 +1663,7 @@ const Word32 delta_phi_val[90] = { 17557552, 17355740, 17158516, 16965724 }; +// Q31 const Word32 inv_delta_phi_val[90] = { 0, 5965232, 11930464, 17895697, 23860929, 29826161, 35791394, 41756626, 47721858, 53687091, 59652323, @@ -1676,6 +1685,7 @@ const Word32 inv_delta_phi_val[90] = { 513009982, 518975214, 524940447, 530905679 }; +// Q22 const Word32 dd_val[90] = { 0, 754974720, 377487360, 251658240, 188743680, 150994944, 125829120, 107853528, 94371840, 83886080, 75497472, @@ -1749,10 +1759,12 @@ const Word32 dct12_fx[12 * 12] = { // Q31 * ISM ROM tables *----------------------------------------------------------------------------------*/ +// Q22 const Word32 ism_azimuth_borders_fx[4] = { ISM_AZIMUTH_MIN_FX, ISM_AZIMUTH_LOW_BORDER_FX, ISM_AZIMUTH_HIGH_BORDER_FX, ISM_AZIMUTH_MAX_FX }; +// Q22 const Word32 ism_elevation_borders_fx[4] = { ISM_ELEVATION_MIN_FX, ISM_ELEVATION_LOW_BORDER_FX, ISM_ELEVATION_HIGH_BORDER_FX, ISM_ELEVATION_MAX_FX }; @@ -1804,15 +1816,15 @@ const Word32 ivas_lpf_2_butter_48k_fx[IVAS_BIQUAD_FILT_LEN << 1] = { /* Q30 */ 0x12c07, 0x2580d, 0x12c07, 0x40000000, 0x818a4580, 0x3e7a6a80 }; -const Word32 ivas_lfe_window_coeff_48k_fx[IVAS_LFE_FADE_LEN_48K] = { +const Word32 ivas_lfe_window_coeff_48k_fx[IVAS_LFE_FADE_LEN_48K] = { // Q31 0x0003a373, 0x000608f6, 0x000888a7, 0x000b3e1b, 0x000e34f1, 0x001174a2, 0x00150328, 0x0018e5e1, 0x001d21eb, 0x0021bc4d, 0x0026ba09, 0x002c202f, 0x0031f3dc, 0x00383a43, 0x003ef8ad, 0x0046347b, 0x004df325, 0x00563a3f, 0x005f0f74, 0x00687888, 0x00727b59, 0x007d1ddb, 0x0088661c, 0x00945a41, 0x00a10087, 0x00ae5f3d, 0x00bc7ccd, 0x00cb5fb3, 0x00db0e7d, 0x00eb8fd0, 0x00fcea61, 0x010f24f8, 0x0122466a, 0x013655a0, 0x014b598e, 0x01615936, 0x01785ba8, 0x01906800, 0x01a9855e, 0x01c3baf0, 0x01df0fee, 0x01fb8b90, 0x02193514, 0x023813c4, 0x02582ee4, 0x02798db8, 0x029c378c, 0x02c033a4, 0x02e58944, 0x030c3fa8, 0x03345e0c, 0x035deba0, 0x0388ef8c, 0x03b570f0, 0x03e376dc, 0x04130858, 0x04442c58, 0x0476e9b8, 0x04ab4760, 0x04e14c00, 0x0518fe48, 0x055264c8, 0x058d8600, 0x05ca6850, 0x06091200, 0x06498930, 0x068bd3f0, 0x06cff830, 0x0715fba8, 0x075de408, 0x07a7b6c8, 0x07f37940, 0x084130a0, 0x0890e200, 0x08e29220, 0x093645c0, 0x098c0150, 0x09e3c940, 0x0a3da180, 0x0a998e30, 0x0af792e0, 0x0b57b320, 0x0bb9f240, 0x0c1e5360, 0x0c84d940, 0x0ced8690, 0x0d585dc0, 0x0dc560f0, 0x0e349200, 0x0ea5f2b0, 0x0f198450, 0x0f8f4820, 0x10073f00, 0x10816980, 0x10fdc840, 0x117c5b00, 0x11fd21e0, 0x12801c60, 0x130549a0, 0x138ca8c0, 0x14163880, 0x14a1f740, 0x152fe320, 0x15bffa00, 0x16523980, 0x16e69ee0, 0x177d2700, 0x1815cec0, 0x18b09260, 0x194d6e00, 0x19ec5d60, 0x1a8d5c20, 0x1b306580, 0x1bd57440, 0x1c7c8300, 0x1d258c40, 0x1dd08a00, 0x1e7d7600, 0x1f2c49a0, 0x1fdcfe20, 0x208f8c40, 0x2143ed00, 0x21fa1840, 0x22b20680, 0x236baf40, 0x24270a00, 0x24e40e00, 0x25a2b280, 0x2662ee00, 0x2724b700, 0x27e80400, 0x28acca80, 0x297300c0, 0x2a3a9c00, 0x2b039180, 0x2bcdd680, 0x2c995fc0, 0x2d6621c0, 0x2e341140, 0x2f032240, 0x2fd34900, 0x30a47900, 0x3176a640, 0x3249c440, 0x331dc600, 0x33f29f40, 0x34c842c0, 0x359ea340, 0x3675b3c0, 0x374d66c0, 0x3825af00, 0x38fe7ec0, 0x39d7c880, 0x3ab17e40, 0x3b8b9240, 0x3c65f6c0, 0x3d409d80, 0x3e1b7880, 0x3ef679c0, 0x3fd19340, 0x40acb680, 0x4187d580, 0x4262e280, 0x433dce80, 0x44188c00, 0x44f30c80, 0x45cd4180, 0x46a71e00, 0x47809300, 0x48599300, 0x49320f80, 0x4a09fb80, 0x4ae14880, 0x4bb7e900, 0x4c8dcf80, 0x4d62ee80, 0x4e373880, 0x4f0aa080, 0x4fdd1900, 0x50ae9600, 0x517f0980, 0x524e6780, 0x531ca380, 0x53e9b100, 0x54b58400, 0x55801080, 0x56494b00, 0x57112800, 0x57d79c00, 0x589c9c00, 0x59601d00, 0x5a221480, 0x5ae27880, 0x5ba13e00, 0x5c5e5c00, 0x5d19c880, 0x5dd37a80, 0x5e8b6800, 0x5f418980, 0x5ff5d580, 0x60a84480, 0x6158ce00, 0x62076a80, 0x62b41280, 0x635ebf80, 0x64076a80, 0x64ae0d00, 0x6552a100, 0x65f52080, 0x66958680, 0x6733cd00, 0x67cff000, 0x6869ea80, 0x6901b880, 0x69975600, 0x6a2abf80, 0x6abbf200, 0x6b4aea80, 0x6bd7a680, 0x6c622300, 0x6cea5f80, 0x6d705900, 0x6df40f00, 0x6e758080, 0x6ef4ac80, 0x6f719300, 0x6fec3380, 0x70648f00, 0x70daa580, 0x714e7880, 0x71c00880, 0x722f5780, 0x729c6700, 0x73073980, 0x736fd100, 0x73d62f80, 0x743a5900, 0x749c5080, 0x74fc1880, 0x7559b600, 0x75b52b80, 0x760e7e80, 0x7665b280, 0x76bacc80, 0x770dd180, 0x775ec600, 0x77adb000, 0x77fa9480, 0x78457900, 0x788e6400, 0x78d55b80, 0x791a6500, 0x795d8780, 0x799ec900, 0x79de3100, 0x7a1bc580, 0x7a578d80, 0x7a919100, 0x7ac9d600, 0x7b006500, 0x7b354400, 0x7b687b80, 0x7b9a1300, 0x7bca1180, 0x7bf87f80, 0x7c256400, 0x7c50c780, 0x7c7ab180, 0x7ca32a00, 0x7cca3900, 0x7cefe600, 0x7d143900, 0x7d373a80, 0x7d58f280, 0x7d796800, 0x7d98a380, 0x7db6ad00, 0x7dd38c80, 0x7def4900, 0x7e09eb00, 0x7e237a00, 0x7e3bfd80, 0x7e537d80, 0x7e6a0180, 0x7e7f9080, 0x7e943200, 0x7ea7ed80, 0x7ebaca00, 0x7ecccf00, 0x7ede0300, 0x7eee6d00, 0x7efe1400, 0x7f0cfe80, 0x7f1b3380, 0x7f28b900, 0x7f359500, 0x7f41ce80, 0x7f4d6b80, 0x7f587180, 0x7f62e680, 0x7f6cd000, 0x7f763400, 0x7f7f1780, 0x7f878080, 0x7f8f7380, 0x7f96f580, 0x7f9e0b80, 0x7fa4bb00, 0x7fab0780, 0x7fb0f600, 0x7fb68b00, 0x7fbbca00, 0x7fc0b800, 0x7fc55880, 0x7fc9af80, 0x7fcdc080, 0x7fd18f00, 0x7fd51e80, 0x7fd87280, 0x7fdb8d80, 0x7fde7380, 0x7fe12700, 0x7fe3aa80, 0x7fe60100, 0x7fe82d00, 0x7fea3180, 0x7fec1000, 0x7fedcb00, 0x7fef6500, 0x7ff0e000, 0x7ff23e00, 0x7ff38080, 0x7ff4a980, 0x7ff5ba80, 0x7ff6b580, 0x7ff79c00, 0x7ff86e80, 0x7ff92f80, 0x7ff9e000, 0x7ffa8100, 0x7ffb1380, 0x7ffb9880, 0x7ffc1180, 0x7ffc7f80, 0x7ffce300, 0x7ffd3c80, 0x7ffd8d80, 0x7ffdd680, 0x7ffe1880, 0x7ffe5300, 0x7ffe8800, 0x7ffeb700, 0x7ffee100, 0x7fff0600, 0x7fff2700, 0x7fff4480, 0x7fff5e80, 0x7fff7500, 0x7fff8900, 0x7fff9a80, 0x7fffaa00, 0x7fffb780, 0x7fffc300, 0x7fffcd00, 0x7fffd580, 0x7fffdc80, 0x7fffe300, 0x7fffe880, 0x7fffec80, 0x7ffff080, 0x7ffff380, 0x7ffff680, 0x7ffff880, 0x7ffffa00, 0x7ffffb80, 0x7ffffc80, 0x7ffffd80, 0x7ffffe80, 0x7fffff00, 0x7fffff00, 0x7fffff80, 0x7fffff80, 0x7fffffff, 0x7fffffff }; -const Word32 ivas_lfe_window_coeff_32k_fx[IVAS_LFE_FADE_LEN_32K] = { +const Word32 ivas_lfe_window_coeff_32k_fx[IVAS_LFE_FADE_LEN_32K] = { // Q31 0x000474c9, 0x0007fdfd, 0x000c0272, 0x0010a35b, 0x0015f4ae, 0x001c079e, 0x0022ecc2, 0x002ab4c6, 0x003370ac, 0x003d31e5, 0x00480a5f, 0x00540c87, 0x00614b4e, 0x006fda25, 0x007fccfb, 0x0091383a, 0x00a430c2, 0x00b8cbe7, 0x00cf1f67, 0x00e74167, 0x0101486c, 0x011d4b52, 0x013b614e, 0x015ba1d8, 0x017e24ae, 0x01a301c8, 0x01ca514e, 0x01f42b90, 0x0220a900, 0x024fe224, 0x0281ef88, 0x02b6e9c0, 0x02eee954, 0x032a06b4, 0x03685a34, 0x03a9fc00, 0x03ef0408, 0x043789f8, 0x0483a538, 0x04d36cd0, 0x0526f760, 0x057e5b20, 0x05d9adc0, 0x06390470, 0x069c73c0, 0x07040fa8, 0x076feb68, 0x07e01990, 0x0854abe0, 0x08cdb350, 0x094b4000, 0x09cd6120, 0x0a5424d0, 0x0adf9870, 0x0b6fc830, 0x0c04bf20, 0x0c9e8760, 0x0d3d29c0, 0x0de0ade0, 0x0e891a50, 0x0f367440, 0x0fe8bfa0, 0x109fff00, 0x115c33a0, 0x121d5d80, 0x12e37b00, 0x13ae8960, 0x147e8440, 0x155365c0, 0x162d26c0, 0x170bbe80, 0x17ef22e0, 0x18d74820, 0x19c42100, 0x1ab59f20, 0x1babb200, 0x1ca64840, 0x1da54e80, 0x1ea8b080, 0x1fb057e0, 0x20bc2d80, 0x21cc1800, 0x22dffd40, 0x23f7c1c0, 0x25134800, 0x26327200, 0x27552000, 0x287b30c0, 0x29a48280, 0x2ad0f180, 0x2c005940, 0x2d329440, 0x2e677c00, 0x2f9ee880, 0x30d8b100, 0x3214ac40, 0x3352afc0, 0x34929040, 0x35d421c0, 0x37173780, 0x385ba480, 0x39a13b00, 0x3ae7cc40, 0x3c2f2a00, 0x3d7724c0, 0x3ebf8d80, 0x40083400, 0x4150e980, 0x42997d80, 0x43e1c000, 0x45298180, 0x46709200, 0x47b6c280, 0x48fbe380, 0x4a3fc600, 0x4b823b80, 0x4cc31600, 0x4e022800, 0x4f3f4500, 0x507a4080, 0x51b2ee80, 0x52e92580, 0x541cba80, 0x554d8580, 0x567b5e00, 0x57a61d80, 0x58cd9e00, 0x59f1bb80, 0x5b125200, 0x5c2f3f00, 0x5d486280, 0x5e5d9d00, 0x5f6ecf80, 0x607bde00, 0x6184ad00, 0x62892280, 0x63892680, 0x6484a280, 0x657b8100, 0x666daf00, 0x675b1980, 0x6843b100, 0x69276680, 0x6a062d00, 0x6adff980, 0x6bb4c180, 0x6c847d80, 0x6d4f2680, 0x6e14b800, 0x6ed52e80, 0x6f908900, 0x7046c680, 0x70f7e880, 0x71a3f300, 0x724aea00, 0x72ecd300, 0x7389b680, 0x74219c80, 0x74b48f80, 0x75429b80, 0x75cbcc80, 0x76503100, 0x76cfd800, 0x774ad280, 0x77c13180, 0x78330780, 0x78a06880, 0x79096800, 0x796e1b80, 0x79ce9980, 0x7a2af880, 0x7a835000, 0x7ad7b800, 0x7b284980, 0x7b751c80, 0x7bbe4c00, 0x7c03f080, 0x7c462580, 0x7c850480, 0x7cc0a880, 0x7cf92c00, 0x7d2eaa80, 0x7d613e00, 0x7d910180, 0x7dbe0f80, 0x7de88300, 0x7e107600, 0x7e360300, 0x7e594280, 0x7e7a4f80, 0x7e994200, 0x7eb63280, 0x7ed13a00, 0x7eea6f00, 0x7f01e980, 0x7f17c000, 0x7f2c0800, 0x7f3ed780, 0x7f504280, 0x7f605d80, 0x7f6f3c00, 0x7f7cf100, 0x7f898e00, 0x7f952500, 0x7f9fc600, 0x7fa98200, 0x7fb26800, 0x7fba8680, 0x7fc1eb80, 0x7fc8a400, 0x7fcebd80, 0x7fd44380, 0x7fd94100, 0x7fddc180, 0x7fe1ce80, 0x7fe57180, 0x7fe8b400, 0x7feb9d80, 0x7fee3680, 0x7ff08600, 0x7ff29280, 0x7ff46300, 0x7ff5fc80, 0x7ff76500, 0x7ff8a180, 0x7ff9b600, 0x7ffaa780, 0x7ffb7900, 0x7ffc2e80, 0x7ffccb80, 0x7ffd5200, 0x7ffdc580, 0x7ffe2800, 0x7ffe7b80, 0x7ffec200, 0x7ffefd80, 0x7fff2f00, 0x7fff5880, 0x7fff7a80, 0x7fff9680, 0x7fffad80, 0x7fffc000, 0x7fffcf00, 0x7fffdb00, 0x7fffe480, 0x7fffeb80, 0x7ffff180, 0x7ffff580, 0x7ffff900, 0x7ffffb00, 0x7ffffd00, 0x7ffffe00, 0x7fffff00, 0x7fffff80, 0x7fffffff, 0x7fffffff }; -const Word32 ivas_lfe_window_coeff_16k_fx[IVAS_LFE_FADE_LEN_16K] = { +const Word32 ivas_lfe_window_coeff_16k_fx[IVAS_LFE_FADE_LEN_16K] = { // Q31 0x00064d50, 0x000e283c, 0x0018b753, 0x00267552, 0x0037e397, 0x004d8c2b, 0x006801d2, 0x0087dfb9, 0x00adc8fc, 0x00da680b, 0x010e6df8, 0x014a91a0, 0x018f8ecc, 0x01de252a, 0x02371734, 0x029b2908, 0x030b1f1c, 0x0387bd00, 0x0411c3e8, 0x04a9f148, 0x0550fd60, 0x060799b0, 0x06ce6f88, 0x07a61e78, 0x088f3ad0, 0x098a4c30, 0x0a97cc00, 0x0bb82430, 0x0cebadd0, 0x0e32afe0, 0x0f8d5df0, 0x10fbd760, 0x127e2680, 0x14143f40, 0x15bdff00, 0x177b2bc0, 0x194b7440, 0x1b2e6f00, 0x1d239ae0, 0x1f2a5ee0, 0x21420ac0, 0x2369d700, 0x25a0e640, 0x27e64500, 0x2a38ebc0, 0x2c97bfc0, 0x2f019400, 0x31752b00, 0x33f13800, 0x36746180, 0x38fd42c0, 0x3b8a6cc0, 0x3e1a6a80, 0x40abc080, 0x433cf080, 0x45cc7c80, 0x4858e600, 0x4ae0b400, 0x4d627280, 0x4fdcb500, 0x524e1b00, 0x54b54e80, 0x57110880, 0x59601300, 0x5ba14800, 0x5dd39780, 0x5ff60500, 0x6207aa80, 0x6407ba80, 0x65f57e80, 0x67d05b00, 0x6997cc80, 0x6b4b6b00, 0x6ceae880, 0x6e761080, 0x6fecc980, 0x714f1280, 0x729d0480, 0x73d6ce80, 0x74fcb800, 0x760f1d80, 0x770e6e80, 0x77fb2f00, 0x78d5f280, 0x799f5b80, 0x7a581b80, 0x7b00ec80, 0x7b9a9480, 0x7c25df80, 0x7ca39e80, 0x7d14a680, 0x7d79ce00, 0x7dd3eb00, 0x7e23d180, 0x7e6a5180, 0x7ea83680, 0x7ede4580, 0x7f0d3a80, 0x7f35cb00, 0x7f58a180, 0x7f765e80, 0x7f8f9880, 0x7fa4db80, 0x7fb6a700, 0x7fc57100, 0x7fd1a400, 0x7fdb9f80, 0x7fe3b980, 0x7fea3e00, 0x7fef6f80, 0x7ff38900, 0x7ff6bc80, 0x7ff93500, 0x7ffb1780, 0x7ffc8300, 0x7ffd9080, 0x7ffe5500, 0x7ffee280, 0x7fff4580, 0x7fff8a00, 0x7fffb800, 0x7fffd580, 0x7fffe880, 0x7ffff400, 0x7ffffa00, 0x7ffffd80, 0x7fffff00, 0x7fffffff }; @@ -1826,6 +1838,7 @@ const UWord32 d_hamm_lfe_plc_fx[LFE_PLC_LENANA / 2] = { 171798688, 172140032, 17 * MDFT/iMDFT ROM tables *------------------------------------------------------------------------------------------*/ +// Q31 const Word32 ivas_mdft_coeff_cos_twid_960_fx[IVAS_960_PT_LEN + 1] = { 2147483647, 2147480832, 2147472128, 2147457792, 2147437696, @@ -2070,6 +2083,7 @@ const Word32 ivas_mdft_coeff_cos_twid_960_fx[IVAS_960_PT_LEN + 1] = { 10541393, 7027612, 3513810, 0 }; +// Q31 const Word32 ivas_mdft_coeff_cos_twid_640_fx[IVAS_640_PT_LEN + 1] = { 2147483647, 2147477120, 2147457792, 2147425408, 2147380096, @@ -2234,6 +2248,7 @@ const Word32 ivas_mdft_coeff_cos_twid_640_fx[IVAS_640_PT_LEN + 1] = { 15812011, 10541393, 5270713, 0 }; +// Q31 const Word32 ivas_mdft_coeff_cos_twid_320_fx[IVAS_320_PT_LEN + 1] = { 2147483647, 2147457792, 2147380096, 2147250816, 2147069696, @@ -2318,6 +2333,7 @@ const Word32 ivas_mdft_coeff_cos_twid_320_fx[IVAS_320_PT_LEN + 1] = { 31623164, 21082532, 10541393, 0 }; +// Q31 const Word32 ivas_mdft_coeff_cos_twid_240_fx[IVAS_240_PT_LEN + 1] = { 2147483647, 2147437696, 2147299712, 2147069696, 2146747776, @@ -2382,6 +2398,7 @@ const Word32 ivas_mdft_coeff_cos_twid_240_fx[IVAS_240_PT_LEN + 1] = { 42163032, 28109692, 14055147, 0 }; +// Q31 const Word32 ivas_mdft_coeff_cos_twid_160_fx[IVAS_160_PT_LEN + 1] = { 2147483647, 2147380096, 2147069696, 2146552320, 2145827968, @@ -2426,6 +2443,7 @@ const Word32 ivas_mdft_coeff_cos_twid_160_fx[IVAS_160_PT_LEN + 1] = { 63239472, 42163032, 21082532, 0 }; +// Q31 const Word32 ivas_mdft_coeff_cos_twid_120_fx[IVAS_120_PT_LEN + 1] = { 2147483647, 2147299712, 2146747776, 2145827968, 2144540544, @@ -2460,6 +2478,7 @@ const Word32 ivas_mdft_coeff_cos_twid_120_fx[IVAS_120_PT_LEN + 1] = { 84309816, 56214568, 28109692, 0 }; +// Q31 const Word32 ivas_mdft_coeff_cos_twid_80_fx[IVAS_80_PT_LEN + 1] = { 2147483647, 2147069696, 2145827968, 2143759104, 2140863616, @@ -2484,6 +2503,7 @@ const Word32 ivas_mdft_coeff_cos_twid_80_fx[IVAS_80_PT_LEN + 1] = { 126424088, 84309816, 42163032, 0 }; +// Q31 const Word32 ivas_mdft_coeff_cos_twid_40_fx[IVAS_40_PT_LEN + 1] = { 2147483647, 2145827968, 2140863616, 2132598272, 2121044608, @@ -2978,26 +2998,32 @@ const Word32 dirac_gains_trg_term_fx[181][2] = { * FB ROM tables *------------------------------------------------------------------------------------------*/ +// Q15 const Word16 ivas_fb_cf_4ms_48k_fx[IVAS_FB_4MS_48K_SAMP] = { 0, 4, 13, 26, 44, 66, 92, 123, 158, 197, 241, 289, 341, 398, 458, 524, 593, 667, 744, 826, 913, 1003, 1097, 1196, 1298, 1405, 1516, 1630, 1749, 1871, 1998, 2128, 2262, 2400, 2541, 2687, 2836, 2988, 3144, 3304, 3467, 3634, 3804, 3977, 4154, 4334, 4517, 4704, 4893, 5086, 5282, 5480, 5682, 5886, 6094, 6304, 6516, 6732, 6949, 7170, 7393, 7618, 7846, 8076, 8308, 8542, 8779, 9017, 9258, 9500, 9744, 9990, 10238, 10487, 10738, 10990, 11244, 11499, 11756, 12014, 12273, 12533, 12794, 13056, 13319, 13582, 13847, 14112, 14378, 14644, 14911, 15178, 15446, 15713, 15981, 16249, 16518, 16786, 17054, 17321, 17589, 17856, 18123, 18389, 18655, 18920, 19185, 19448, 19711, 19973, 20234, 20494, 20753, 21011, 21268, 21523, 21777, 22029, 22280, 22529, 22777, 23023, 23267, 23509, 23750, 23988, 24225, 24459, 24691, 24921, 25149, 25374, 25597, 25818, 26035, 26251, 26463, 26673, 26881, 27085, 27287, 27485, 27681, 27874, 28063, 28250, 28433, 28613, 28790, 28963, 29133, 29300, 29463, 29623, 29779, 29931, 30080, 30226, 30367, 30505, 30639, 30769, 30896, 31018, 31137, 31251, 31362, 31469, 31571, 31670, 31764, 31854, 31941, 32023, 32100, 32174, 32243, 32309, 32369, 32426, 32478, 32526, 32570, 32609, 32644, 32675, 32701, 32723, 32741, 32754, 32763, 32767 }; +// Q15 const Word16 ivas_fb_cf_4ms_32k_fx[IVAS_FB_4MS_32K_SAMP] = { 1, 11, 30, 60, 99, 149, 208, 276, 355, 443, 541, 648, 765, 891, 1026, 1171, 1325, 1488, 1660, 1840, 2030, 2228, 2435, 2650, 2873, 3105, 3345, 3592, 3847, 4110, 4380, 4657, 4941, 5233, 5530, 5835, 6146, 6463, 6786, 7115, 7449, 7789, 8134, 8483, 8838, 9197, 9561, 9928, 10300, 10675, 11054, 11435, 11820, 12208, 12598, 12990, 13385, 13781, 14179, 14578, 14978, 15379, 15780, 16182, 16585, 16987, 17388, 17789, 18189, 18588, 18986, 19382, 19777, 20169, 20559, 20947, 21332, 21713, 22092, 22467, 22839, 23206, 23570, 23929, 24284, 24633, 24978, 25318, 25652, 25981, 26304, 26621, 26932, 27237, 27534, 27826, 28110, 28387, 28657, 28920, 29175, 29422, 29662, 29894, 30117, 30332, 30539, 30737, 30927, 31107, 31279, 31442, 31596, 31741, 31876, 32002, 32119, 32226, 32324, 32412, 32491, 32559, 32618, 32668, 32707, 32737, 32756, 32766 }; +// Q15 const Word16 ivas_fb_cf_4ms_16k_fx[IVAS_FB_4MS_16K_SAMP] = { 4, 44, 123, 241, 398, 593, 826, 1097, 1405, 1749, 2128, 2541, 2988, 3467, 3977, 4517, 5086, 5682, 6304, 6949, 7618, 8308, 9017, 9744, 10487, 11244, 12014, 12794, 13582, 14378, 15178, 15981, 16786, 17589, 18389, 19185, 19973, 20753, 21523, 22280, 23023, 23750, 24459, 25149, 25818, 26463, 27085, 27681, 28250, 28790, 29300, 29779, 30226, 30639, 31018, 31362, 31670, 31941, 32174, 32369, 32526, 32644, 32723, 32763 }; +// Q15 const Word16 ivas_fb_cf_1ms_48k_fx[IVAS_FB_1MS_48K_SAMP] = { 8, 78, 218, 427, 705, 1050, 1460, 1934, 2470, 3066, 3718, 4425, 5184, 5990, 6840, 7732, 8660, 9622, 10612, 11627, 12663, 13715, 14778, 15847, 16920, 17989, 19052, 20104, 21140, 22155, 23145, 24107, 25035, 25927, 26777, 27583, 28342, 29049, 29701, 30297, 30833, 31307, 31717, 32062, 32340, 32549, 32689, 32759 }; +// Q15 const Word16 ivas_fb_cf_1ms_32k_fx[IVAS_FB_1MS_32K_SAMP] = { 19, 177, 491, 957, 1573, 2330, 3224, 4244, 5381, 6624, 7960, 9378, 10864, 12403, 13979, 15580, 17187, 18788, 20364, 21903, 23389, 24807, 26143, 27386, 28523, 29543, 30437, 31194, 31810, 32276, 32590, 32748 }; +// Q15 const Word16 ivas_fb_cf_1ms_16k_fx[IVAS_FB_1MS_16K_SAMP] = { 78, 705, 1934, 3718, 5990, 8660, 11627, 14778, 17989, 21140, 24107, 26777, 29049, 30833, 32062, 32689 }; @@ -4020,6 +4046,7 @@ const Word32 ivas_sine_frame_len_640_del_32_fx[577] = { }; +/* Q Factor is 30 */ const Word32 ivas_sine_frame_len_640_del_16_fx[289] = { 1073725952, 1073678400, 1073599104, 1073488064, 1073345344, 1073170880, 1072964736, 1072726912, 1072457408, 1072156160, 1071823296, diff --git a/lib_com/ivas_rom_com_fx.h b/lib_com/ivas_rom_com_fx.h index 4cf61f9ae..2460cd383 100644 --- a/lib_com/ivas_rom_com_fx.h +++ b/lib_com/ivas_rom_com_fx.h @@ -224,9 +224,9 @@ extern const Word32 ivas_lpf_2_butter_16k_fx[IVAS_BIQUAD_FILT_LEN << 1]; extern const Word32 ivas_lpf_2_butter_32k_fx[IVAS_BIQUAD_FILT_LEN << 1]; extern const Word32 ivas_lpf_2_butter_48k_fx[IVAS_BIQUAD_FILT_LEN << 1]; -extern const Word32 ivas_lfe_window_coeff_48k_fx[IVAS_LFE_FADE_LEN_48K]; -extern const Word32 ivas_lfe_window_coeff_32k_fx[IVAS_LFE_FADE_LEN_32K]; -extern const Word32 ivas_lfe_window_coeff_16k_fx[IVAS_LFE_FADE_LEN_16K]; +extern const Word32 ivas_lfe_window_coeff_48k_fx[IVAS_LFE_FADE_LEN_48K]; // Q31 +extern const Word32 ivas_lfe_window_coeff_32k_fx[IVAS_LFE_FADE_LEN_32K]; // Q31 +extern const Word32 ivas_lfe_window_coeff_16k_fx[IVAS_LFE_FADE_LEN_16K]; // Q31 extern const UWord32 d_hamm_lfe_plc_fx[LFE_PLC_LENANA / 2]; diff --git a/lib_com/ivas_spar_com_quant_util.c b/lib_com/ivas_spar_com_quant_util.c index 3c7b4e620..0207e3e19 100644 --- a/lib_com/ivas_spar_com_quant_util.c +++ b/lib_com/ivas_spar_com_quant_util.c @@ -41,6 +41,7 @@ #include "wmc_auto.h" #ifdef IVAS_FLOAT_FIXED #include "ivas_rom_com_fx.h" +#include "ivas_prot_fx.h" #endif diff --git a/lib_com/ivas_stereo_ica_com_fx.c b/lib_com/ivas_stereo_ica_com_fx.c index f5f4c423d..829f4e5e8 100644 --- a/lib_com/ivas_stereo_ica_com_fx.c +++ b/lib_com/ivas_stereo_ica_com_fx.c @@ -42,6 +42,7 @@ #include "wmc_auto.h" #include "rom_com.h" #include "ivas_rom_com.h" +#include "ivas_prot_fx.h" #ifdef IVAS_FLOAT_FIXED #include "ivas_rom_com_fx.h" #endif diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index 942135fbd..d615e511b 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -9593,12 +9593,12 @@ void addBassPostFilter_ivas_fx( Word32 **iAnalysis_fx, HANDLE_CLDFB_FILTER_BANK cldfb ); -Word32 ism_dequant_meta_fx( - const Word16 idx, /* i : quantizer index */ - const Word32 borders_fx[], /* i : level borders */ - const Word32 q_step_fx, /* i : quantization step */ - const Word32 q_step_border_fx, /* i : quantization step at the border */ - const Word16 cbsize /* i : codebook size */ +Word32 ism_dequant_meta_fx( /* o : Q22*/ + const Word16 idx, /* i : quantizer index */ + const Word32 borders_fx[], /* i : level borders Q22*/ + const Word32 q_step_fx, /* i : quantization step Q22 */ + const Word32 q_step_border_fx, /* i : quantization step at the border Q22*/ + const Word16 cbsize /* i : codebook size */ ); void save_synthesis_hq_fec_fx( diff --git a/lib_dec/ACcontextMapping_dec_fx.c b/lib_dec/ACcontextMapping_dec_fx.c index df1ae4cc8..677e37baf 100644 --- a/lib_dec/ACcontextMapping_dec_fx.c +++ b/lib_dec/ACcontextMapping_dec_fx.c @@ -10,6 +10,7 @@ #include "basop_util.h" #include "cnst.h" #include "prot_fx.h" +#include "ivas_prot_fx.h" #include "ivas_prot.h" #include "ivas_rom_com.h" diff --git a/lib_dec/acelp_core_dec_ivas_fx.c b/lib_dec/acelp_core_dec_ivas_fx.c index 834691ce0..3fcf4610b 100644 --- a/lib_dec/acelp_core_dec_ivas_fx.c +++ b/lib_dec/acelp_core_dec_ivas_fx.c @@ -45,6 +45,7 @@ #include "ivas_prot.h" #include "ivas_rom_com.h" #include "wmc_auto.h" +#include "ivas_prot_fx.h" #ifdef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* diff --git a/lib_dec/ivas_binRenderer_internal.c b/lib_dec/ivas_binRenderer_internal.c index f38fe4612..fa0a6c053 100644 --- a/lib_dec/ivas_binRenderer_internal.c +++ b/lib_dec/ivas_binRenderer_internal.c @@ -45,6 +45,7 @@ #include "wmc_auto.h" #ifdef IVAS_FLOAT_FIXED #include "prot_fx.h" +#include "ivas_prot_fx.h" #include "ivas_rom_com_fx.h" #include "debug.h" #define NUM_TAPS_F0_6 ( Word16 )( 58 ) // (Word16) ceil( 0.6f * hBinRenConvModule->numTaps ) diff --git a/lib_dec/ivas_pca_dec_fx.c b/lib_dec/ivas_pca_dec_fx.c index 9765facd6..bec9d70d9 100644 --- a/lib_dec/ivas_pca_dec_fx.c +++ b/lib_dec/ivas_pca_dec_fx.c @@ -40,6 +40,7 @@ #include "wmc_auto.h" #include "prot_fx.h" #include "math.h" +#include "ivas_prot_fx.h" /*-----------------------------------------------------------------------* * Local function definitions diff --git a/lib_dec/ivas_qspherical_dec.c b/lib_dec/ivas_qspherical_dec.c index 3f50f3816..ef42ebe55 100644 --- a/lib_dec/ivas_qspherical_dec.c +++ b/lib_dec/ivas_qspherical_dec.c @@ -40,6 +40,7 @@ #include "prot.h" #ifdef IVAS_FLOAT_FIXED #include "ivas_rom_com_fx.h" +#include "ivas_prot_fx.h" #endif diff --git a/lib_dec/ivas_range_uni_dec.c b/lib_dec/ivas_range_uni_dec.c index 8a82dabd2..b2e00ffc2 100644 --- a/lib_dec/ivas_range_uni_dec.c +++ b/lib_dec/ivas_range_uni_dec.c @@ -41,6 +41,7 @@ #include "prot.h" #include "wmc_auto.h" #ifdef IVAS_FLOAT_FIXED +#include "ivas_prot_fx.h" #include "prot_fx.h" #endif diff --git a/lib_dec/ivas_sns_dec_fx.c b/lib_dec/ivas_sns_dec_fx.c index 1863e11ae..a2ca9f3c2 100644 --- a/lib_dec/ivas_sns_dec_fx.c +++ b/lib_dec/ivas_sns_dec_fx.c @@ -42,6 +42,7 @@ #ifdef IVAS_FLOAT_FIXED #include "prot_fx.h" #include "ivas_rom_com_fx.h" +#include "ivas_prot_fx.h" /*------------------------------------------------------------------- * sns_1st_dec_fx() diff --git a/lib_dec/ivas_spar_md_dec.c b/lib_dec/ivas_spar_md_dec.c index 886db7651..5b3d2000b 100644 --- a/lib_dec/ivas_spar_md_dec.c +++ b/lib_dec/ivas_spar_md_dec.c @@ -4459,7 +4459,7 @@ static void ivas_parse_parameter_bitstream_dtx( move16(); } pd = extract_l( L_sub( value, i_mult( pr, pd_q_lvls ) ) ); - val_fx = dtx_pd_real_min_max_fx[0]; /*Q0*/ + val_fx = dtx_pd_real_min_max_fx[0]; /*Q28*/ move32(); ivas_quantise_real_values_fx( &val_fx, pd_q_lvls, dtx_pd_real_min_max_fx[0], dtx_pd_real_min_max_fx[1], &idx, &val_fx, 1 ); pd = add( pd, idx ); diff --git a/lib_dec/ivas_svd_dec.c b/lib_dec/ivas_svd_dec.c index e0c210a2f..1cb20cc22 100644 --- a/lib_dec/ivas_svd_dec.c +++ b/lib_dec/ivas_svd_dec.c @@ -39,7 +39,7 @@ #include #include "wmc_auto.h" #include "prot_fx.h" - +#include "ivas_prot_fx.h" /*-----------------------------------------------------------------------* * Local constants diff --git a/lib_dec/ivas_td_low_rate_dec.c b/lib_dec/ivas_td_low_rate_dec.c index 03f85a5d6..73214cb3c 100644 --- a/lib_dec/ivas_td_low_rate_dec.c +++ b/lib_dec/ivas_td_low_rate_dec.c @@ -41,6 +41,7 @@ #include "prot_fx.h" #include "ivas_prot.h" #include "wmc_auto.h" +#include "ivas_prot_fx.h" #ifndef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* * tdm_low_rate_dec() diff --git a/lib_dec/lsf_dec_fx.c b/lib_dec/lsf_dec_fx.c index a81e22f25..a50c98d09 100644 --- a/lib_dec/lsf_dec_fx.c +++ b/lib_dec/lsf_dec_fx.c @@ -9,6 +9,7 @@ #include "prot_fx.h" /* Function prototypes */ #if defined LSF_RE_USE_SECONDARY_CHANNEL || defined FIX_798_LSF_SECONDARY_CH_MISSING_CODE #include "ivas_prot.h" +#include "ivas_prot_fx.h" #endif #ifdef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* diff --git a/lib_enc/cod_tcx.c b/lib_enc/cod_tcx.c index 502b22aed..a5152dcb6 100644 --- a/lib_enc/cod_tcx.c +++ b/lib_enc/cod_tcx.c @@ -47,6 +47,7 @@ #include "ivas_rom_com_fx.h" #include "prot_fx_enc.h" #include "prot_fx.h" +#include "ivas_prot_fx.h" #endif /*-------------------------------------------------------------------* * HBAutocorrelation() diff --git a/lib_enc/find_uv.c b/lib_enc/find_uv.c index f51a259bc..7acb99f49 100644 --- a/lib_enc/find_uv.c +++ b/lib_enc/find_uv.c @@ -562,6 +562,7 @@ Word16 find_uv_ivas_fx( /* o : coding typ test(); #ifdef BASOP_NOGLOB if ( ( ( LT_16( add_o( mean_voi3, corr_shift, &Overflow ), add( 22774, mean_voi3_offset ) ) ) && /* normalized correlation low */ + ( LT_16( add_o( st_fx->voicing_fx[2], corr_shift, &Overflow ), 25887 ) ) && /* normalized correlation low on look-ahead - onset detection */ ( LT_32( ee[0], 397 ) ) && ( GT_32( hp_E[0], E_min_th ) ) && /* energy concentrated in high frequencies provided that some energy is present in HF... */ ( LT_32( ee[1], 397 ) ) && ( GT_32( hp_E[1], E_min_th ) ) && /* ... biased towards look-ahead to detect onsets */ ( tmp_offset_flag == 0 ) && /* Take care of voiced offsets */ diff --git a/lib_enc/ivas_enc_cov_handler.c b/lib_enc/ivas_enc_cov_handler.c index 7c5223b42..3804b1a9e 100644 --- a/lib_enc/ivas_enc_cov_handler.c +++ b/lib_enc/ivas_enc_cov_handler.c @@ -38,6 +38,7 @@ #include "wmc_auto.h" #ifdef IVAS_FLOAT_FIXED #include "prot_fx.h" +#include "ivas_prot_fx.h" #endif /*------------------------------------------------------------------------------------------* diff --git a/lib_enc/ivas_front_vad.c b/lib_enc/ivas_front_vad.c index a4f7731e1..ca21f7b64 100644 --- a/lib_enc/ivas_front_vad.c +++ b/lib_enc/ivas_front_vad.c @@ -45,6 +45,7 @@ #ifdef IVAS_FLOAT_FIXED #include "prot_fx_enc.h" #include "prot_fx.h" +#include "ivas_prot_fx.h" #endif /*-----------------------------------------------------------------------------------------* diff --git a/lib_enc/ivas_stereo_adapt_GR_enc.c b/lib_enc/ivas_stereo_adapt_GR_enc.c index f98b453a0..b1c490c78 100644 --- a/lib_enc/ivas_stereo_adapt_GR_enc.c +++ b/lib_enc/ivas_stereo_adapt_GR_enc.c @@ -38,7 +38,7 @@ #include "stat_enc.h" #include "wmc_auto.h" #include "ivas_rom_com.h" - +#include "ivas_prot_fx.h" /*---------------------------------------------------------------------* * Local function prototypes diff --git a/lib_enc/ivas_stereo_switching_enc.c b/lib_enc/ivas_stereo_switching_enc.c index 683907e8a..ef62186fe 100644 --- a/lib_enc/ivas_stereo_switching_enc.c +++ b/lib_enc/ivas_stereo_switching_enc.c @@ -45,6 +45,7 @@ #ifdef IVAS_FLOAT_FIXED #include "prot_fx_enc.h" #include "prot_fx.h" +#include "ivas_prot_fx.h" #endif #ifdef IVAS_FLOAT_FIXED diff --git a/lib_enc/swb_tbe_enc_fx.c b/lib_enc/swb_tbe_enc_fx.c index 18ef67dbf..4618eaaa6 100644 --- a/lib_enc/swb_tbe_enc_fx.c +++ b/lib_enc/swb_tbe_enc_fx.c @@ -14,6 +14,7 @@ #include "prot_fx_enc.h" /* Function prototypes */ #include "ivas_prot.h" /* Function prototypes */ #include "stl.h" +#include "ivas_prot_fx.h" /*-----------------------------------------------------------------* diff --git a/lib_rend/ivas_crend.c b/lib_rend/ivas_crend.c index 78ebf384d..95ab75f93 100644 --- a/lib_rend/ivas_crend.c +++ b/lib_rend/ivas_crend.c @@ -49,6 +49,7 @@ #ifdef IVAS_FLOAT_FIXED #include "control.h" #include "prot_fx.h" +#include "ivas_prot_fx.h" #define float_to_fix( n, factor ) ( round( n * ( 1 << factor ) ) ) #define fix_to_float( n, factor ) ( (float) n / ( 1 << factor ) ) #endif diff --git a/lib_rend/ivas_dirac_decorr_dec.c b/lib_rend/ivas_dirac_decorr_dec.c index 01bd6edab..dd71510d7 100644 --- a/lib_rend/ivas_dirac_decorr_dec.c +++ b/lib_rend/ivas_dirac_decorr_dec.c @@ -42,6 +42,7 @@ #include "ivas_rom_rend.h" #include "wmc_auto.h" #include "prot_fx.h" +#include "ivas_prot_fx.h" /*------------------------------------------------------------------------- * Local constants diff --git a/lib_rend/ivas_dirac_output_synthesis_dec.c b/lib_rend/ivas_dirac_output_synthesis_dec.c index ef7f34e82..f30bb1237 100644 --- a/lib_rend/ivas_dirac_output_synthesis_dec.c +++ b/lib_rend/ivas_dirac_output_synthesis_dec.c @@ -45,6 +45,7 @@ #include "wmc_auto.h" #ifdef IVAS_FLOAT_FIXED #include "prot_fx.h" /* Function prototypes */ +#include "ivas_prot_fx.h" #endif #ifdef IVAS_FLOAT_FIXED #include "ivas_rom_com_fx.h" diff --git a/lib_rend/ivas_hrtf.c b/lib_rend/ivas_hrtf.c index 28ba346ca..f12d122b7 100644 --- a/lib_rend/ivas_hrtf.c +++ b/lib_rend/ivas_hrtf.c @@ -37,6 +37,7 @@ #include "ivas_error.h" #include "wmc_auto.h" #include "ivas_prot.h" +#include "ivas_prot_fx.h" /*-----------------------------------------------------------------------* * ivas_HRTF_binary_open() diff --git a/lib_rend/ivas_sba_rendering.c b/lib_rend/ivas_sba_rendering.c index 4a23da243..ccf81a09d 100644 --- a/lib_rend/ivas_sba_rendering.c +++ b/lib_rend/ivas_sba_rendering.c @@ -40,6 +40,7 @@ #include "ivas_cnst.h" #include #include "wmc_auto.h" +#include "ivas_prot_fx.h" /*-------------------------------------------------------------------* * ivas_sba_prototype_renderer() diff --git a/lib_rend/ivas_vbap.c b/lib_rend/ivas_vbap.c index 4c14067ec..ad0de1534 100644 --- a/lib_rend/ivas_vbap.c +++ b/lib_rend/ivas_vbap.c @@ -40,6 +40,7 @@ #include "ivas_stat_dec.h" #include "wmc_auto.h" #include "prot_fx.h" +#include "ivas_prot_fx.h" /*-----------------------------------------------------------------------* * Local constants diff --git a/lib_util/hrtf_file_reader.c b/lib_util/hrtf_file_reader.c index 0fe9ed71d..625302e11 100644 --- a/lib_util/hrtf_file_reader.c +++ b/lib_util/hrtf_file_reader.c @@ -36,6 +36,7 @@ #include "ivas_prot_rend.h" #include "prot_fx.h" #include "ivas_prot.h" +#include "ivas_prot_fx.h" /*---------------------------------------------------------------------* * Local structures -- GitLab From 2e03263cbd71baece2aff730391b6b2ecff4040c Mon Sep 17 00:00:00 2001 From: Jan Kiene Date: Tue, 29 Oct 2024 10:55:58 +0100 Subject: [PATCH 057/128] remove accidental change --- lib_enc/ivas_dirac_enc.c | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/lib_enc/ivas_dirac_enc.c b/lib_enc/ivas_dirac_enc.c index 6574b24f1..45a008543 100644 --- a/lib_enc/ivas_dirac_enc.c +++ b/lib_enc/ivas_dirac_enc.c @@ -140,21 +140,6 @@ ivas_error ivas_dirac_enc_open_fx( } set32_fx( hDirAC->direction_vector_m_fx[i][j], 0, DIRAC_MAX_NBANDS ); } -#ifdef IVAS_FLOAT_FIXED - IF( ( hDirAC->direction_vector_m_fx[i] = (Word32 **) malloc( MAX_PARAM_SPATIAL_SUBFRAMES * sizeof( Word32 * ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); - } - - FOR( j = 0; j < MAX_PARAM_SPATIAL_SUBFRAMES; j++ ) - { - if ( ( hDirAC->direction_vector_m_fx[i][j] = (Word32 *) malloc( DIRAC_MAX_NBANDS * sizeof( Word32 ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); - } - set32_fx( hDirAC->direction_vector_m_fx[i][j], 0, DIRAC_MAX_NBANDS ); - } -#endif } Word16 tmp_e = 0; -- GitLab From 0da5f29bef3fefb7071cec64d16bf0ce913ec319 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Tue, 29 Oct 2024 20:37:01 +0530 Subject: [PATCH 058/128] Q info updates, encoder cleanup --- lib_com/arith_coder.c | 162 ++-- lib_com/arith_coder_fx.c | 124 ++-- lib_com/basop_com_lpc.c | 79 +- lib_com/basop_lsf_tools.c | 64 +- lib_com/basop_proto_func.h | 61 +- lib_com/basop_tcx_utils.c | 89 ++- lib_com/bitalloc.c | 209 +++--- lib_com/bitalloc_fx.c | 165 +++-- lib_com/core_com_config.c | 296 ++++---- lib_com/deemph.c | 54 +- lib_com/delay_comp.c | 24 +- lib_com/dlpc_bfi_fx.c | 26 +- lib_com/enhancer_fx.c | 78 +- lib_com/est_tilt_fx.c | 20 +- lib_com/fd_cng_com.c | 45 +- lib_com/fd_cng_com_fx.c | 102 +-- lib_com/ivas_prot_fx.h | 52 +- lib_com/ivas_sba_config.c | 13 +- lib_com/ivas_sns_com_fx.c | 71 +- lib_com/ivas_spar_com.c | 1099 ++++++++++++++-------------- lib_com/ivas_spar_com_quant_util.c | 76 +- lib_com/ivas_stat_com.h | 2 +- lib_com/ivas_stereo_dft_com.c | 17 +- lib_com/ivas_stereo_eclvq_com_fx.c | 15 +- lib_com/log2.c | 10 +- lib_com/log2.h | 14 +- lib_com/logqnorm_fx.c | 30 +- lib_com/low_rate_band_att_fx.c | 8 +- lib_com/lpc_tools.c | 16 +- lib_com/lpc_tools_fx.c | 54 +- lib_com/lsf_dec_bfi_fx.c | 10 +- lib_com/lsf_msvq_ma_fx.c | 6 +- lib_com/lsf_tools.c | 96 +-- lib_com/lsf_tools_fx.c | 237 +++--- lib_com/lsp_conv_poly_fx.c | 4 +- lib_com/modif_fs.c | 187 ++--- lib_com/modif_fs_fx.c | 34 +- lib_com/mslvq_com_fx.c | 8 + lib_com/nelp_fx.c | 4 +- lib_com/parameter_bitmaping.c | 3 + lib_com/prot.h | 14 +- lib_com/prot_fx.h | 222 +++--- lib_dec/fd_cng_dec_fx.c | 2 +- lib_dec/hq_core_dec_fx.c | 2 +- lib_enc/core_enc_init.c | 2 +- lib_enc/ivas_cpe_enc.c | 2 +- lib_enc/ivas_spar_encoder.c | 6 +- lib_enc/ivas_spar_md_enc.c | 4 + 48 files changed, 2028 insertions(+), 1890 deletions(-) diff --git a/lib_com/arith_coder.c b/lib_com/arith_coder.c index bba7ab973..ce16e7a7b 100644 --- a/lib_com/arith_coder.c +++ b/lib_com/arith_coder.c @@ -65,11 +65,11 @@ Word16 expfp_evs( assert( x <= 0 ); - L_tmp = L_negate( L_shl( L_deposit_h( x ), sub( x_e, 15 ) ) ); + L_tmp = L_negate( L_shl( L_deposit_h( x ), sub( x_e, 15 ) ) ); /* Q16 */ /* split into integer and fractional parts */ - xi = round_fx( L_tmp ); - xf = extract_l( L_tmp ); + xi = round_fx( L_tmp ); /* Q0 */ + xf = extract_l( L_tmp ); /* Q16 */ BASOP_SATURATE_WARNING_OFF; xf = negate( xf ); @@ -81,13 +81,13 @@ Word16 expfp_evs( + ((xf*xf) / (2*65536)) + ((((((xf*xf) / (2*65536))*xf) / 65536)*65536/3) / 65536) + ((((((((xf*xf) / (2*65536))*xf) / 65536)*65536/3) / 65536)*xf) / (4*65536)); */ - y = L_mac0( 65536, xf, 1 ); - tmp = shr( mult( xf, xf ), 2 ); - y = L_mac0( y, tmp, 1 ); + y = L_mac0( 65536, xf, 1 ); /* Q16 */ + tmp = shr( mult( xf, xf ), 2 ); /* Q15 */ + y = L_mac0( y, tmp, 1 ); /* Q16 */ tmp = shr( mult( shr( mult( tmp, xf ), 1 ), 65536 / 3 ), 1 ); - y = L_mac0( y, tmp, 1 ); + y = L_mac0( y, tmp, 1 ); /* Q16 */ tmp = shr( mult( tmp, xf ), 3 ); - y = L_mac0( y, tmp, 1 ); + y = L_mac0( y, tmp, 1 ); /* Q16 */ /* Integer part */ b0 = s_and( xi, 1 ); @@ -105,7 +105,7 @@ Word16 expfp_evs( y = Mpy_32_16_1( y, 22513 ); /* exp(-8) in -11Q26 */ /* scaling: -1*b0 - 2*b1 -5*b2 -11*b3 */ - y = L_shr( y, add( add( xi, shr( xi, 2 ) ), shr( b3, 3 ) ) ); + y = L_shr( y, add( add( xi, shr( xi, 2 ) ), shr( b3, 3 ) ) ); /* Q16 */ /* zero for xi >= 16 */ if ( shr( xi, 4 ) > 0 ) @@ -157,44 +157,44 @@ void powfp_odd2_evs( maxk = sub( 15, norm_s( exp ) ); assert( maxk < 12 ); - pows[0] = base; + pows[0] = base; /* Q15 */ move16(); FOR( k = 0; k < maxk; k++ ) { - pows[k + 1] = mult_r( pows[k], pows[k] ); + pows[k + 1] = mult_r( pows[k], pows[k] ); /* Q15 */ move16(); } - k = sub( k, 1 ); + k--; h = shl( 1, k ); /* highest bit of exp2 */ - out2 = base; + out2 = base; /* Q15 */ move16(); - out = mult_r( out, pows[add( k, 1 )] ); /* we already know that "exp" has the highest bit set to one since we calculated .. */ + out = mult_r( out, pows[k + 1] ); /* we already know that "exp" has the highest bit set to one since we calculated .. */ /* .. the effective length of "exp" earlier on, thus we omit the branch for out2 */ if ( s_and( exp2, h ) != 0 ) { - out2 = mult_r( out2, pows[add( k, 1 )] ); + out2 = mult_r( out2, pows[k + 1] ); /* Q15 */ } h = shr( h, 1 ); - FOR( k = sub( k, 1 ); k >= 0; k-- ) + FOR( k = k - 1; k >= 0; k-- ) { if ( s_and( exp, h ) != 0 ) { - out = mult_r( out, pows[k + 1] ); + out = mult_r( out, pows[k + 1] ); /* Q15 */ } if ( s_and( exp2, h ) != 0 ) { - out2 = mult_r( out2, pows[k + 1] ); + out2 = mult_r( out2, pows[k + 1] ); /* Q15 */ } h = shr( h, 1 ); } } - *pout1 = out2; + *pout1 = out2; /* Q15 */ move16(); - *pout2 = out; + *pout2 = out; /* Q15 */ move16(); return; @@ -256,8 +256,8 @@ void tcx_arith_scale_envelope_ivas( L_tmp = L_sub( L_tmp, L_shr( L_mult0( target_bits, 30199 ), 11 ) ); /* Q15; 30199 -> 0.00045f (Q26) */ L_tmp = L_add( L_tmp, 39322 ); /* Q15; 39322 -> 1.2f (Q15) */ L_tmp = Mpy_32_16_1( L_tmp, target_bits ); /* Q0 */ - assert( L_tmp < 32768 ); - target_bits = extract_l( L_tmp ); + assert( LE_32( L_tmp, 32768 ) ); + target_bits = extract_l( L_tmp ); /* Q0 */ /* Calculate inverse envelope and find initial scale guess based on mean */ mean = L_deposit_l( 0 ); @@ -271,22 +271,22 @@ void tcx_arith_scale_envelope_ivas( #ifndef BASOP_NOGLOB tmp = Inv16( round_fx( L_shl( env[k], tmp ) ), &tmp2 ); #else /* BASOP_NOGLOB */ - tmp = Inv16( round_fx_o( L_shl( env[k], tmp ), &Overflow ), &tmp2 ); + tmp = Inv16( round_fx_o( L_shl( env[k], tmp ), &Overflow ), &tmp2 ); /* exp(tmp2) */ #endif /* BASOP_NOGLOB */ ienv[k] = L_shl( L_deposit_h( tmp ), sub( tmp2, 15 ) ); /* Q16 */ move32(); - mean = L_add( mean, ienv[k] ); + mean = L_add( mean, ienv[k] ); /* Q16 */ } tmp = norm_s( L_frame ); - tmp2 = div_s( 8192, shl( L_frame, tmp ) ); + tmp2 = div_s( 8192, shl( L_frame, tmp ) ); /* Q15 */ tmp = shl( tmp2, sub( tmp, 7 ) ); mean = L_shr( Mpy_32_16_1( mean, tmp ), 6 ); /* Q16 */ /* Rate dependent compensation to get closer to the target on average */ /* mean = powf(mean, (float)L_frame / target_bits * 0.357f); */ - tmp = BASOP_Util_Divide1616_Scale( L_frame, target_bits, &tmp2 ); - tmp = mult_r( tmp, FL2WORD16( 0.357f ) ); - mean = BASOP_Util_fPow( mean, 15, L_deposit_h( tmp ), tmp2, &mean_e ); + tmp = BASOP_Util_Divide1616_Scale( L_frame, target_bits, &tmp2 ); /* exp(tmp2) */ + tmp = mult_r( tmp, 11698 /*0.357f Q15*/ ); + mean = BASOP_Util_fPow( mean, 15, L_deposit_h( tmp ), tmp2, &mean_e ); /* exp(mean_e) */ /* Find first-guess scaling coefficient "scale" such that if "mean" is the * mean of the envelope, then the mean bit-consumption is approximately @@ -294,22 +294,22 @@ void tcx_arith_scale_envelope_ivas( * log2(2*e*mean*scale + 0.15 + 0.035/(mean*scale)) * L_frame = target_bits */ /* a = 2*2.71828183f*mean*mean; */ - tmp = round_fx( mean ); - a = L_mult( mult_r( tmp, FL2WORD16_SCALE( 2.71828183f, 2 ) ), tmp ); + tmp = round_fx( mean ); /* Q15 - mean_e */ + a = L_mult( mult_r( tmp, 22268 /*2.71828183f Q13*/ ), tmp ); /* 2 * mean_e + 3 */ a_e = add( shl( mean_e, 1 ), 3 ); /* b = (0.15f - powf(2.0f, target_bits/(float)L_frame)) * mean; */ - tmp = BASOP_Util_Divide1616_Scale( target_bits, L_frame, &tmp2 ); + tmp = BASOP_Util_Divide1616_Scale( target_bits, L_frame, &tmp2 ); /* exp(tmp2) */ tmp = round_fx( BASOP_util_Pow2( L_deposit_h( tmp ), tmp2, &tmp2 ) ); - b_e = BASOP_Util_Add_MantExp( FL2WORD16( 0.15f ), 0, negate( tmp ), tmp2, &b ); - b = mult_r( b, round_fx( mean ) ); + b_e = BASOP_Util_Add_MantExp( 4915 /*0.15f in Q15*/, 0, negate( tmp ), tmp2, &b ); + b = mult_r( b, round_fx( mean ) ); /* exp(b_e + mean_e) */ b_e = add( b_e, mean_e ); /* scale = (-b + sqrtf(b*b - 4.0f*a*0.035f)) / (2.0f * a); */ #ifndef BASOP_NOGLOB tmp = round_fx( BASOP_Util_Add_Mant32Exp( L_mult( b, b ), shl( b_e, 1 ), Mpy_32_16_1( a, FL2WORD16( -4.0f * 0.035f ) ), a_e, &tmp2 ) ); #else - tmp = round_fx_o( BASOP_Util_Add_Mant32Exp( L_mult( b, b ), shl( b_e, 1 ), Mpy_32_16_1( a, FL2WORD16( -4.0f * 0.035f ) ), a_e, &tmp2 ), &Overflow ); + tmp = round_fx_o( BASOP_Util_Add_Mant32Exp( L_mult( b, b ), shl( b_e, 1 ), Mpy_32_16_1( a, -4588 /*-4.0f*0.035f Q15*/ ), a_e, &tmp2 ), &Overflow ); /* Q15 - a_e */ #endif IF( tmp <= 0 ) @@ -328,34 +328,34 @@ void tcx_arith_scale_envelope_ivas( } tmp2 = BASOP_Util_Add_MantExp( negate( b ), b_e, tmp, tmp2, &scale ); - scale = BASOP_Util_Divide1616_Scale( scale, round_fx( a ), &tmp ); + scale = BASOP_Util_Divide1616_Scale( scale, round_fx( a ), &tmp ); /* exp(tmp) */ #ifndef BASOP_NOGLOB scale = shl( scale, sub( sub( add( tmp, tmp2 ), a_e ), 1 ) ); /* Q15 */ #else - scale = shl_o( scale, sub( sub( add( tmp, tmp2 ), a_e ), 1 ), &Overflow ); /* Q15 */ + scale = shl_o( scale, sub( sub( add( tmp, tmp2 ), a_e ), 1 ), &Overflow ); /* Q15 */ #endif /* iscale = 1.0f / scale; */ iscale_e = 0; move16(); - iscale = Inv16( s_max( 1, scale ), &iscale_e ); + iscale = Inv16( s_max( 1, scale ), &iscale_e ); /* exp(iscale_e) */ lob = 0; move16(); hib = 0; move16(); - max_iter = 2; + max_iter = 2; /* Q0 */ move16(); if ( low_complexity ) { - max_iter = 1; + max_iter = 1; /* Q0 */ move16(); } FOR( iter = 0; iter < max_iter; iter++ ) { - statesi = 0x7FFF; + statesi = 0x7FFF; /* 1 in Q15 */ move16(); bits = 0; move16(); @@ -364,65 +364,65 @@ void tcx_arith_scale_envelope_ivas( { s = Mpy_32_16_1( ienv[k], scale ); /* Q16 */ - IF( L_sub( s, FL2WORD32_SCALE( 0.08f, 15 ) ) <= 0 ) + IF( L_sub( s, 5243l /*0.08f Q16*/ ) <= 0 ) { /* If s = 0.08, the expected bit-consumption is log2(1.0224). Below 0.08, the bit-consumption estimate function becomes inaccurate, so use log2(1.0224) for all values below 0.08. */ /* round(state * 1.0224 * 32768) */ - statesi = mult_r( statesi, FL2WORD16_SCALE( 1.0224, 1 ) ); + statesi = mult_r( statesi, 16751 /*1.0224 Q14*/ ); /* Q14 */ tmp = norm_s( statesi ); - statesi = shl( statesi, tmp ); - bits = add( bits, sub( 1, tmp ) ); + statesi = shl( statesi, tmp ); /* Q15 */ + bits = add( bits, sub( 1, tmp ) ); /* Q0 */ } - ELSE IF( L_sub( s, FL2WORD32_SCALE( 255.0, 15 ) ) <= 0 ) + ELSE IF( L_sub( s, 16711680l /*255.0 Q16*/ ) <= 0 ) { /* a = 5.436564f * s + 0.15f + 0.035f * env[k] * iscale; */ - L_tmp = L_shl( Mpy_32_16_1( s, FL2WORD16_SCALE( 5.436564f, 3 ) ), 3 ); - L_tmp = L_add( L_tmp, FL2WORD32_SCALE( 0.15f, 15 ) ); - L_tmp = L_add( L_tmp, L_shl( Mpy_32_16_1( env[k], mult_r( FL2WORD16( 0.035f ), iscale ) ), iscale_e ) ); + L_tmp = L_shl( Mpy_32_16_1( s, 22268 /*5.436564f Q12*/ ), 3 ); /* Q16 */ + L_tmp = L_add( L_tmp, 9830l /*0.15f Q16*/ ); /* Q16 */ + L_tmp = L_add( L_tmp, L_shl( Mpy_32_16_1( env[k], mult_r( 1147 /*0.035f Q15*/, iscale ) ), iscale_e ) ); /* Q16 */ tmp = norm_l( L_tmp ); #ifndef BASOP_NOGLOB statesi = mult_r( statesi, round_fx( L_shl( L_tmp, tmp ) ) ); -#else /* BASOP_NOGLOB */ - statesi = mult_r( statesi, round_fx_o( L_shl( L_tmp, tmp ), &Overflow ) ); -#endif /* BASOP_NOGLOB */ - bits = add( bits, sub( 15, tmp ) ); +#else /* BASOP_NOGLOB */ + statesi = mult_r( statesi, round_fx_o( L_shl( L_tmp, tmp ), &Overflow ) ); /* */ +#endif /* BASOP_NOGLOB */ + bits = add( bits, sub( 15, tmp ) ); /* Q0 */ tmp = norm_s( statesi ); statesi = shl( statesi, tmp ); - bits = sub( bits, tmp ); + bits = sub( bits, tmp ); /* Q0 */ } ELSE { /* for large envelope values, s > 255, bit consumption is approx log2(2*e*s) * further, we use round(log2(x)) = floor(log2(x)+0.5) = floor(log2(x*sqrt(2))) */ /* a = 5.436564f * s; */ - L_tmp = Mpy_32_16_1( s, FL2WORD16_SCALE( 5.436564f * 1.4142f, 3 ) ); /* Q13 */ - bits = add( bits, sub( 17, norm_l( L_tmp ) ) ); + L_tmp = Mpy_32_16_1( s, 31492 /*5.436564f * 1.4142f Q12*/ ); /* Q13 */ + bits = add( bits, sub( 17, norm_l( L_tmp ) ) ); /* Q0 */ } } IF( sub( bits, target_bits ) <= 0 ) { /* Bits leftover => scale is too small */ - lob = scale; + lob = scale; /* Q0 */ move16(); - lob_bits = bits; + lob_bits = bits; /* Q0 */ move16(); IF( hib > 0 ) /* Bisection search */ { - adjust = div_s( sub( hib_bits, target_bits ), sub( hib_bits, lob_bits ) ); - scale = add( mult_r( sub( lob, hib ), adjust ), hib ); + adjust = div_s( sub( hib_bits, target_bits ), sub( hib_bits, lob_bits ) ); /* Q15 */ + scale = add( mult_r( sub( lob, hib ), adjust ), hib ); /* Q0 */ } ELSE { /* Initial scale adaptation */ /* adjust = 1.05f * target_bits / (float)bits; scale *= adjust; */ - adjust = mult_r( FL2WORD16_SCALE( 1.05f, 1 ), target_bits ); - adjust = BASOP_Util_Divide1616_Scale( adjust, bits, &tmp ); + adjust = mult_r( 17203 /*1.05f Q14*/, target_bits ); /* Q15 */ + adjust = BASOP_Util_Divide1616_Scale( adjust, bits, &tmp ); /* exp(tmp) */ scale = shl( mult_r( scale, adjust ), add( 1, tmp ) ); } } @@ -431,13 +431,13 @@ void tcx_arith_scale_envelope_ivas( /* Ran out of bits => scale is too large */ hib = scale; move16(); - hib_bits = bits; + hib_bits = bits; /* Q0 */ move16(); IF( lob > 0 ) /* Bisection search */ { - adjust = div_s( sub( hib_bits, target_bits ), sub( hib_bits, lob_bits ) ); - scale = add( mult_r( sub( lob, hib ), adjust ), hib ); + adjust = div_s( sub( hib_bits, target_bits ), sub( hib_bits, lob_bits ) ); /* Q15 */ + scale = add( mult_r( sub( lob, hib ), adjust ), hib ); /* Q0 */ } ELSE { /* Initial scale adaptation */ @@ -449,13 +449,13 @@ void tcx_arith_scale_envelope_ivas( FOR( k = 0; k < L_frame; k++ ) { - s_env[k] = 0; + s_env[k] = 0; /* Q15 - e */ move16(); } } ELSE { - adjust = div_s( mult_r( 31130 /*0.95f Q15*/, target_bits ), bits ); + adjust = div_s( mult_r( 31130 /*0.95f Q15*/, target_bits ), bits ); /* Q15 */ } scale = mult_r( scale, adjust ); } @@ -476,10 +476,10 @@ void tcx_arith_scale_envelope_ivas( } ELSE { - iscale = Inv16( scale, &iscale_e ); + iscale = Inv16( scale, &iscale_e ); /* exp(iscale_e) */ } } - L_frame = L_spec_core; + L_frame = L_spec_core; /* Q0 */ move16(); tmp = getScaleFactor32( env, L_frame ); @@ -495,9 +495,9 @@ void tcx_arith_scale_envelope_ivas( FOR( k = 0; k < L_frame; k++ ) { - L_tmp = Mpy_32_16_1( L_shl( env[k], tmp ), iscale ); - L_tmp = L_min( L_tmp, a ); - s_env[k] = round_fx( L_tmp ); + L_tmp = Mpy_32_16_1( L_shl( env[k], tmp ), iscale ); /* Q31 - e */ + L_tmp = L_min( L_tmp, a ); /* Q31 - e */ + s_env[k] = round_fx( L_tmp ); /* Q15 - e */ move16(); } @@ -519,13 +519,13 @@ void tcx_arith_scale_envelope_ivas( *-------------------------------------------------------------------------*/ void tcx_arith_render_envelope_ivas( - const Word16 A_ind[], /* i : LPC coefficients of signal envelope */ - const Word16 L_frame, /* i : number of spectral lines */ - const Word16 L_spec, /* i : length of the coded spectrum */ - const Word16 preemph_fac, /* i : pre-emphasis factor */ - const Word16 gamma_w, /* i : A_ind -> weighted envelope factor */ - const Word16 gamma_uw, /* i : A_ind -> non-weighted envelope factor */ - Word32 env[] /* o : shaped signal envelope */ + const Word16 A_ind[], /* i : LPC coefficients of signal envelope Q12*/ + const Word16 L_frame, /* i : number of spectral lines Q0*/ + const Word16 L_spec, /* i : length of the coded spectrum Q0*/ + const Word16 preemph_fac, /* i : pre-emphasis factor Q15*/ + const Word16 gamma_w, /* i : A_ind -> weighted envelope factor Q15*/ + const Word16 gamma_uw, /* i : A_ind -> non-weighted envelope factor Q14*/ + Word32 env[] /* o : shaped signal envelope Q16*/ ) { Word16 k; @@ -545,7 +545,7 @@ void tcx_arith_render_envelope_ivas( /* Compute weighted signal envelope in perceptual domain */ FOR( k = 0; k < FDNS_NPTS; k++ ) { - signal_env[k] = mult_r( signal_env[k], gainlpc[k] ); + signal_env[k] = mult_r( signal_env[k], gainlpc[k] ); /* exp(signal_env_e + gainlpc_e) */ move16(); signal_env_e[k] = add( signal_env_e[k], gainlpc_e[k] ); move16(); @@ -554,7 +554,7 @@ void tcx_arith_render_envelope_ivas( /* Adaptive low frequency emphasis */ FOR( k = 0; k < L_frame; k++ ) { - env[k] = 0x10000; + env[k] = 0x10000; /* 1 in Q16 */ move32(); } @@ -565,7 +565,7 @@ void tcx_arith_render_envelope_ivas( FOR( k = L_frame; k < L_spec; ++k ) { - env[k] = env[k - 1]; + env[k] = env[k - 1]; /* Q16 */ move32(); } diff --git a/lib_com/arith_coder_fx.c b/lib_com/arith_coder_fx.c index 64cc81d04..58ab13175 100644 --- a/lib_com/arith_coder_fx.c +++ b/lib_com/arith_coder_fx.c @@ -21,11 +21,11 @@ Word32 expfp( /* o: Q31 */ assert( x > 0 ); - L_tmp = L_shl( L_deposit_h( x ), x_e ); + L_tmp = L_shl( L_deposit_h( x ), x_e ); /* Q31 */ /* split into integer and fractional parts */ - xi = round_fx( L_tmp ); - xf = extract_l( L_tmp ); + xi = round_fx( L_tmp ); /* Q15 */ + xf = extract_l( L_tmp ); /* Q31 */ BASOP_SATURATE_WARNING_OFF_EVS; xf = negate( xf ); @@ -37,13 +37,13 @@ Word32 expfp( /* o: Q31 */ + ((xf*xf) / (2*65536)) + ((((((xf*xf) / (2*65536))*xf) / 65536)*65536/3) / 65536) + ((((((((xf*xf) / (2*65536))*xf) / 65536)*65536/3) / 65536)*xf) / (4*65536)); */ - y = L_mac0( 65536, xf, 1 ); + y = L_mac0( 65536, xf, 1 ); /* Q16 */ tmp = shr( mult( xf, xf ), 2 ); - y = L_mac0( y, tmp, 1 ); + y = L_mac0( y, tmp, 1 ); /* Q16 */ tmp = shr( mult( shr( mult( tmp, xf ), 1 ), 65536 / 3 ), 1 ); - y = L_mac0( y, tmp, 1 ); + y = L_mac0( y, tmp, 1 ); /* Q16 */ tmp = shr( mult( tmp, xf ), 3 ); - y = L_mac0( y, tmp, 1 ); + y = L_mac0( y, tmp, 1 ); /* Q16 */ /* Integer part */ b0 = s_and( xi, 1 ); @@ -51,19 +51,19 @@ Word32 expfp( /* o: Q31 */ b2 = s_and( xi, 4 ); b3 = s_and( xi, 8 ); - if ( b0 != 0 ) + IF( b0 != 0 ) { y = Mpy_32_16_1( y, 24109 ); /* exp(-1) in -1Q16 */ } - if ( b1 != 0 ) + IF( b1 != 0 ) { y = Mpy_32_16_1( y, 17739 ); /* exp(-2) in -2Q17 */ } - if ( b2 != 0 ) + IF( b2 != 0 ) { y = Mpy_32_16_1( y, 19205 ); /* exp(-4) in -5Q20 */ } - if ( b3 != 0 ) + IF( b3 != 0 ) { y = Mpy_32_16_1( y, 22513 ); /* exp(-8) in -11Q26 */ } @@ -104,9 +104,9 @@ void powfp_odd2( assert( exp >= 0 ); - out = base; + out = base; /* Q15 */ move16(); - out2 = 0x7FFF; + out2 = 0x7FFF; /* 1 in Q15 */ move16(); IF( exp != 0 ) { @@ -114,11 +114,11 @@ void powfp_odd2( maxk = sub( 15, norm_s( exp ) ); assert( maxk < 12 ); - pows[0] = base; + pows[0] = base; /* Q15 */ move16(); FOR( k = 0; k < maxk; k++ ) { - pows[k + 1] = mult_r( pows[k], pows[k] ); + pows[k + 1] = mult_r( pows[k], pows[k] ); /* Q15 */ move16(); } k = sub( k, 1 ); @@ -127,31 +127,31 @@ void powfp_odd2( move16(); out = mult_r( out, pows[k + 1] ); /* we already know that "exp" has the highest bit set to one since we calculated .. */ /* .. the effective length of "exp" earlier on, thus we omit the branch for out2 */ - if ( s_and( exp2, h ) != 0 ) + IF( s_and( exp2, h ) != 0 ) { - out2 = mult_r( out2, pows[k + 1] ); + out2 = mult_r( out2, pows[k + 1] ); /* Q15 */ } h = shr( h, 1 ); FOR( k = sub( k, 1 ); k >= 0; k-- ) { - if ( s_and( exp, h ) != 0 ) + IF( s_and( exp, h ) != 0 ) { - out = mult_r( out, pows[k + 1] ); + out = mult_r( out, pows[k + 1] ); /* Q15 */ } - if ( s_and( exp2, h ) != 0 ) + IF( s_and( exp2, h ) != 0 ) { - out2 = mult_r( out2, pows[k + 1] ); + out2 = mult_r( out2, pows[k + 1] ); /* Q15 */ } h = shr( h, 1 ); } } - *pout1 = out2; + *pout1 = out2; /* Q15 */ move16(); - *pout2 = out; + *pout2 = out; /* Q15 */ move16(); } @@ -223,13 +223,13 @@ void tcx_arith_scale_envelope( tmp = norm_l( env[k] ); tmp2 = sub( 15, tmp ); #ifdef BASOP_NOGLOB - tmp = Inv16( round_fx_o( L_shl_o( env[k], tmp, &Overflow ), &Overflow ), &tmp2 ); + tmp = Inv16( round_fx_o( L_shl_o( env[k], tmp, &Overflow ), &Overflow ), &tmp2 ); /* exp(tmp2) */ #else tmp = Inv16( round_fx( L_shl( env[k], tmp ) ), &tmp2 ); #endif ienv[k] = L_shl( L_deposit_h( tmp ), sub( tmp2, 15 ) ); /* Q16 */ move32(); - mean = L_add( mean, ienv[k] ); + mean = L_add( mean, ienv[k] ); /* Q16 */ } tmp = norm_s( L_frame ); tmp = shl( div_s( 8192, shl( L_frame, tmp ) ), sub( tmp, 7 ) ); @@ -237,9 +237,9 @@ void tcx_arith_scale_envelope( /* Rate dependent compensation to get closer to the target on average */ /* mean = (float)pow(mean, (float)L_frame / (float)target_bits * 0.357f); */ - tmp = BASOP_Util_Divide1616_Scale( L_frame, target_bits, &tmp2 ); + tmp = BASOP_Util_Divide1616_Scale( L_frame, target_bits, &tmp2 ); /* exp(tmp2) */ tmp = mult_r( tmp, 11698 /*0.357f Q15*/ ); - mean = BASOP_Util_fPow( mean, 15, L_deposit_h( tmp ), tmp2, &mean_e ); + mean = BASOP_Util_fPow( mean, 15, L_deposit_h( tmp ), tmp2, &mean_e ); /* exp(mean_e) */ /* Find first-guess scaling coefficient "scale" such that if "mean" is the * mean of the envelope, then the mean bit-consumption is approximately @@ -247,15 +247,15 @@ void tcx_arith_scale_envelope( * log2(2*e*mean*scale + 0.15 + 0.035/(mean*scale)) * L_frame = target_bits */ /* a = 2*2.71828183f*mean*mean; */ - tmp = round_fx( mean ); - a = L_mult( mult_r( tmp, 22268 /*2.71828183f Q13*/ ), tmp ); + tmp = round_fx( mean ); /* Q15 - mean_e */ + a = L_mult( mult_r( tmp, 22268 /*2.71828183f Q13*/ ), tmp ); /* 2 * mean_e + 3 */ a_e = add( shl( mean_e, 1 ), 3 ); /* b = (0.15f - (float)pow(2.0f, target_bits/(float)L_frame)) * mean; */ - tmp = BASOP_Util_Divide1616_Scale( target_bits, L_frame, &tmp2 ); + tmp = BASOP_Util_Divide1616_Scale( target_bits, L_frame, &tmp2 ); /* exp(tmp2) */ tmp = round_fx( BASOP_util_Pow2( L_deposit_h( tmp ), tmp2, &tmp2 ) ); b_e = BASOP_Util_Add_MantExp( 4915 /*0.15f Q15*/, 0, negate( tmp ), tmp2, &b ); - b = mult_r( b, round_fx( mean ) ); + b = mult_r( b, round_fx( mean ) ); /* exp(b_e + mean_e) */ b_e = add( b_e, mean_e ); /* scale = (-b + (float)sqrt(b*b - 4.0f*a*0.035f)) / (2.0f * a); */ @@ -272,7 +272,7 @@ void tcx_arith_scale_envelope( tmp = Sqrt16( tmp, &tmp2 ); } - tmp2 = BASOP_Util_Add_MantExp( negate( b ), b_e, tmp, tmp2, &scale ); + tmp2 = BASOP_Util_Add_MantExp( negate( b ), b_e, tmp, tmp2, &scale ); /* exp(scale) */ scale = BASOP_Util_Divide1616_Scale( scale, round_fx( a ), &tmp ); #ifdef BASOP_NOGLOB scale = shl_o( scale, sub( sub( add( tmp, tmp2 ), a_e ), 1 ), &Overflow ); /* Q15 */ @@ -283,7 +283,7 @@ void tcx_arith_scale_envelope( /* iscale = 1.0f / scale; */ iscale_e = 0; move16(); - iscale = Inv16( s_max( 1, scale ), &iscale_e ); + iscale = Inv16( s_max( 1, scale ), &iscale_e ); /* exp(isacle_e) */ lob = 0; move16(); @@ -300,7 +300,7 @@ void tcx_arith_scale_envelope( FOR( iter = 0; iter < max_iter; iter++ ) { - statesi = 0x7FFF; + statesi = 0x7FFF; /* 1 in Q15 */ move16(); bits = 0; move16(); @@ -314,17 +314,17 @@ void tcx_arith_scale_envelope( /* If s = 0.08, the expected bit-consumption is log2(1.0224). Below 0.08, the bit-consumption estimate function becomes inaccurate, so use log2(1.0224) for all values below 0.08. */ /* round(state * 1.0224 * 32768) */ - statesi = mult_r( statesi, 16751 /*1.0224 Q14*/ ); + statesi = mult_r( statesi, 16751 /*1.0224 Q14*/ ); /* Q14 */ tmp = norm_s( statesi ); - statesi = shl( statesi, tmp ); - bits = add( bits, sub( 1, tmp ) ); + statesi = shl( statesi, tmp ); /* Q15 */ + bits = add( bits, sub( 1, tmp ) ); /* Q0 */ } ELSE IF( LE_32( s, 16711680l /*255.0 Q16*/ ) ) { /* a = 5.436564f * s + 0.15f + 0.035f * env[k] * iscale; */ - L_tmp = L_shl( Mpy_32_16_1( s, 22268 /*5.436564f Q12*/ ), 3 ); - L_tmp = L_add( L_tmp, 9830l /*0.15f Q16*/ ); - L_tmp = L_add( L_tmp, L_shl( Mpy_32_16_1( env[k], mult_r( 1147 /*0.035f Q15*/, iscale ) ), iscale_e ) ); + L_tmp = L_shl( Mpy_32_16_1( s, 22268 /*5.436564f Q12*/ ), 3 ); /* Q16 */ + L_tmp = L_add( L_tmp, 9830l /*0.15f Q16*/ ); /* Q16 */ + L_tmp = L_add( L_tmp, L_shl( Mpy_32_16_1( env[k], mult_r( 1147 /*0.035f Q15*/, iscale ) ), iscale_e ) ); /* Q16 */ tmp = norm_l( L_tmp ); #ifdef BASOP_NOGLOB @@ -336,7 +336,7 @@ void tcx_arith_scale_envelope( tmp = norm_s( statesi ); statesi = shl( statesi, tmp ); - bits = sub( bits, tmp ); + bits = sub( bits, tmp ); /* Q0 */ } ELSE { @@ -344,20 +344,20 @@ void tcx_arith_scale_envelope( * further, we use round(log2(x)) = floor(log2(x)+0.5) = floor(log2(x*sqrt(2))) */ /* a = 5.436564f * s; */ L_tmp = Mpy_32_16_1( s, 31492 /*5.436564f * 1.4142f Q12*/ ); /* Q13 */ - bits = add( bits, sub( 17, norm_l( L_tmp ) ) ); + bits = add( bits, sub( 17, norm_l( L_tmp ) ) ); /* Q0 */ } } IF( LE_16( bits, target_bits ) ) /* Bits leftover => scale is too small */ { - lob = scale; + lob = scale; /* Q0 */ move16(); - lob_bits = bits; + lob_bits = bits; /* Q0 */ move16(); IF( hib > 0 ) /* Bisection search */ { - adjust = div_s( sub( hib_bits, target_bits ), sub( hib_bits, lob_bits ) ); + adjust = div_s( sub( hib_bits, target_bits ), sub( hib_bits, lob_bits ) ); /* Q15 */ scale = add( mult_r( sub( lob, hib ), adjust ), hib ); } ELSE /* Initial scale adaptation */ @@ -365,7 +365,7 @@ void tcx_arith_scale_envelope( /* adjust = 1.05f * target_bits / (float)bits; scale *= adjust; */ adjust = mult_r( 17203 /*1.05f Q14*/, target_bits ); - adjust = BASOP_Util_Divide1616_Scale( adjust, bits, &tmp ); + adjust = BASOP_Util_Divide1616_Scale( adjust, bits, &tmp ); /* exp(tmp) */ scale = shl( mult_r( scale, adjust ), add( 1, tmp ) ); } } @@ -378,7 +378,7 @@ void tcx_arith_scale_envelope( IF( lob > 0 ) /* Bisection search */ { - adjust = div_s( sub( hib_bits, target_bits ), sub( hib_bits, lob_bits ) ); + adjust = div_s( sub( hib_bits, target_bits ), sub( hib_bits, lob_bits ) ); /* Q15 */ scale = add( mult_r( sub( lob, hib ), adjust ), hib ); } ELSE @@ -392,7 +392,7 @@ void tcx_arith_scale_envelope( } ELSE { - adjust = div_s( mult_r( 31130 /*0.95f Q15*/, target_bits ), bits ); + adjust = div_s( mult_r( 31130 /*0.95f Q15*/, target_bits ), bits ); /* Q15 */ } scale = mult_r( scale, adjust ); } @@ -411,7 +411,7 @@ void tcx_arith_scale_envelope( iscale = Inv16( scale, &iscale_e ); } } - L_frame = L_spec_core; + L_frame = L_spec_core; /* Q0 */ move16(); tmp = getScaleFactor32( env, L_frame ); @@ -427,9 +427,9 @@ void tcx_arith_scale_envelope( FOR( k = 0; k < L_frame; k++ ) { - L_tmp = Mpy_32_16_1( L_shl( env[k], tmp ), iscale ); - L_tmp = L_min( L_tmp, a ); - s_env[k] = round_fx( L_tmp ); + L_tmp = Mpy_32_16_1( L_shl( env[k], tmp ), iscale ); /* Q31 - e */ + L_tmp = L_min( L_tmp, a ); /* Q31 - e */ + s_env[k] = round_fx( L_tmp ); /* Q15 - e */ move16(); } } @@ -447,13 +447,13 @@ void tcx_arith_scale_envelope( * and decoder remain synchronized. *-------------------------------------------------------------------------*/ void tcx_arith_render_envelope( - const Word16 A_ind[], /* i: LPC coefficients of signal envelope */ - const Word16 L_frame, /* i: number of spectral lines */ - const Word16 L_spec, - const Word16 preemph_fac, /* i: pre-emphasis factor */ - const Word16 gamma_w, /* i: A_ind -> weighted envelope factor */ - const Word16 gamma_uw, /* i: A_ind -> non-weighted envelope factor */ - Word32 env[] /* o: shaped signal envelope */ + const Word16 A_ind[], /* i: LPC coefficients of signal envelope Q12*/ + const Word16 L_frame, /* i: number of spectral lines Q0*/ + const Word16 L_spec, /* Q0 */ + const Word16 preemph_fac, /* i: pre-emphasis factor Q15*/ + const Word16 gamma_w, /* i: A_ind -> weighted envelope factor Q15*/ + const Word16 gamma_uw, /* i: A_ind -> non-weighted envelope factor Q14*/ + Word32 env[] /* o: shaped signal envelope Q16*/ ) { Word16 k; @@ -474,14 +474,14 @@ void tcx_arith_render_envelope( /* Compute weighted signal envelope in perceptual domain */ FOR( k = 0; k < FDNS_NPTS; k++ ) { - signal_env[k] = mult_r( signal_env[k], gainlpc[k] ); + signal_env[k] = mult_r( signal_env[k], gainlpc[k] ); /* exp(signal_env_e + gainlpc_e) */ move16(); signal_env_e[k] = add( signal_env_e[k], gainlpc_e[k] ); move16(); } /* Adaptive low frequency emphasis */ - set32_fx( env, 0x10000, L_frame ); + set32_fx( env, 0x10000 /* 1 in Q16 */, L_frame ); AdaptLowFreqDeemph( env, 15, 1, @@ -493,7 +493,7 @@ void tcx_arith_render_envelope( FOR( k = L_frame; k < L_spec; ++k ) { - env[k] = env[k - 1]; + env[k] = env[k - 1]; /* Q16 */ move32(); } } diff --git a/lib_com/basop_com_lpc.c b/lib_com/basop_com_lpc.c index 669b976e6..5de4fa5d3 100644 --- a/lib_com/basop_com_lpc.c +++ b/lib_com/basop_com_lpc.c @@ -67,32 +67,36 @@ * Returns: * void */ -void basop_weight_a( const Word16 *a, Word16 *ap, const Word16 gamma ) +void basop_weight_a( + const Word16 *a, /* Q12 */ + Word16 *ap, /* Q12 */ + const Word16 gamma /* Q15 */ +) { Word16 i, fac; Word32 Amax; Word16 shift; - fac = gamma; - Amax = L_mult( 16384, a[0] ); + fac = gamma; /* Q15 */ + Amax = L_mult( 16384, a[0] ); /* Q27 */ FOR( i = 1; i < M; i++ ) { Amax = L_max( Amax, L_abs( L_mult0( fac, a[i] ) ) ); - fac = mult_r( fac, gamma ); + fac = mult_r( fac, gamma ); /* Q15 */ } - Amax = L_max( Amax, L_abs( L_mult0( fac, a[M] ) ) ); + Amax = L_max( Amax, L_abs( L_mult0( fac, a[M] ) ) ); /* Q27 */ shift = norm_l( Amax ); fac = gamma; ap[0] = shl( a[0], sub( shift, 1 ) ); move16(); FOR( i = 1; i < M; i++ ) { - ap[i] = round_fx( L_shl( L_mult0( a[i], fac ), shift ) ); + ap[i] = round_fx( L_shl( L_mult0( a[i], fac ), shift ) ); /* Q12 */ move16(); - fac = mult_r( fac, gamma ); + fac = mult_r( fac, gamma ); /* Q15 */ } - ap[M] = round_fx( L_shl( L_mult0( a[M], fac ), shift ) ); + ap[M] = round_fx( L_shl( L_mult0( a[M], fac ), shift ) ); /* Q12 */ move16(); @@ -113,7 +117,11 @@ void basop_weight_a( const Word16 *a, Word16 *ap, const Word16 gamma ) * Returns: * void */ -void basop_weight_a_inv( const Word16 *a, Word16 *ap, const Word16 inv_gamma ) +void basop_weight_a_inv( + const Word16 *a, /* Q12 */ + Word16 *ap, /* Q12 */ + const Word16 inv_gamma /* Q14 */ +) { Word16 i; static const Word16 inv_gamma_tab_12k8[16] = { 17809, 19357, 21041, 22870, 24859, 27020, 29370, 31924, /* Q14 */ @@ -130,7 +138,7 @@ void basop_weight_a_inv( const Word16 *a, Word16 *ap, const Word16 inv_gamma ) { FOR( i = 0; i <= M; i++ ) { - ap[i] = a[i]; + ap[i] = a[i]; /* Q12 */ move16(); } return; @@ -138,37 +146,37 @@ void basop_weight_a_inv( const Word16 *a, Word16 *ap, const Word16 inv_gamma ) assert( inv_gamma == GAMMA1_INV || inv_gamma == GAMMA16k_INV ); - inv_gamma_tab = inv_gamma_tab_12k8; + inv_gamma_tab = inv_gamma_tab_12k8; /* Q14 */ move16(); if ( sub( inv_gamma, GAMMA16k_INV ) == 0 ) { - inv_gamma_tab = inv_gamma_tab_16k; + inv_gamma_tab = inv_gamma_tab_16k; /* Q14 */ move16(); } Amax = L_mult( 16384, a[0] ); FOR( i = 1; i < 9; i++ ) { - Amax = L_max( Amax, L_abs( L_mult( a[i], inv_gamma_tab[i - 1] ) ) ); + Amax = L_max( Amax, L_abs( L_mult( a[i], inv_gamma_tab[i - 1] ) ) ); /* Q27 */ } FOR( i = 9; i < 17; i++ ) { - Amax = L_max( Amax, L_abs( L_shl( L_mult( a[i], inv_gamma_tab[i - 1] ), 1 ) ) ); + Amax = L_max( Amax, L_abs( L_shl( L_mult( a[i], inv_gamma_tab[i - 1] ), 1 ) ) ); /* Q27 */ } shift = norm_l( Amax ); - ap[0] = shl( a[0], sub( shift, 1 ) ); + ap[0] = shl( a[0], sub( shift, 1 ) ); /* Q11 + shift */ move16(); FOR( i = 1; i < 9; i++ ) { - L_tmp = L_mult( a[i], inv_gamma_tab[i - 1] ); - ap[i] = round_fx( L_shl( L_tmp, shift ) ); + L_tmp = L_mult( a[i], inv_gamma_tab[i - 1] ); /* Q27 */ + ap[i] = round_fx( L_shl( L_tmp, shift ) ); /* Q11 + shift */ move16(); } shift = add( shift, 1 ); FOR( i = 9; i < 17; i++ ) { - L_tmp = L_mult( a[i], inv_gamma_tab[i - 1] ); - ap[i] = round_fx( L_shl( L_tmp, shift ) ); + L_tmp = L_mult( a[i], inv_gamma_tab[i - 1] ); /* Q27 */ + ap[i] = round_fx( L_shl( L_tmp, shift ) ); /* Q11 + shift */ move16(); } @@ -190,39 +198,45 @@ void basop_weight_a_inv( const Word16 *a, Word16 *ap, const Word16 inv_gamma ) * Returns: * void */ -void basop_E_LPC_a_add_tilt( const Word16 *a, Word16 *ap, Word16 gamma ) +void basop_E_LPC_a_add_tilt( + const Word16 *a, /* Q12 */ + Word16 *ap, /* Q12 */ + Word16 gamma /* Q15 */ +) { Word16 i; Word32 Amax, Atmp[M + 2]; Word16 shift; - Amax = L_mult( 16384, a[0] ); + Amax = L_mult( 16384, a[0] ); /* Q27 */ FOR( i = 1; i <= M; i++ ) { - Atmp[i] = L_sub( L_mult( 16384, a[i] ), L_mult0( gamma, a[i - 1] ) ); + Atmp[i] = L_sub( L_mult( 16384, a[i] ), L_mult0( gamma, a[i - 1] ) ); /* Q27 */ move32(); - Amax = L_max( Amax, L_abs( Atmp[i] ) ); + Amax = L_max( Amax, L_abs( Atmp[i] ) ); /* Q27 */ } - Atmp[M + 1] = L_negate( L_mult0( gamma, a[M] ) ); + Atmp[M + 1] = L_negate( L_mult0( gamma, a[M] ) ); /* Q27 */ move32(); - Amax = L_max( Amax, L_abs( Atmp[M + 1] ) ); + Amax = L_max( Amax, L_abs( Atmp[M + 1] ) ); /* Q27 */ shift = norm_l( Amax ); - ap[0] = shl( a[0], sub( shift, 1 ) ); + ap[0] = shl( a[0], sub( shift, 1 ) ); /* Q11 + shift */ move16(); FOR( i = 1; i <= M; i++ ) { - ap[i] = round_fx( L_shl( Atmp[i], shift ) ); + ap[i] = round_fx( L_shl( Atmp[i], shift ) ); /* Q11 + shift */ move16(); } - ap[M + 1] = round_fx( L_shl( Atmp[M + 1], shift ) ); + ap[M + 1] = round_fx( L_shl( Atmp[M + 1], shift ) ); /* Q12 */ move16(); return; } -static Word16 xsf_to_xsp( Word16 xsf ) +static Word16 xsf_to_xsp( + Word16 xsf /* Q2.56 */ +) { /* xsp = cos(xsf * 3.1415/6400); */ return getCosWord16R2( xsf ); @@ -244,7 +258,10 @@ static Word16 xsf_to_xsp( Word16 xsf ) * Returns: * void */ -void basop_lsf2lsp( const Word16 lsf[], Word16 lsp[] ) +void basop_lsf2lsp( + const Word16 lsf[], /* Q2.56 */ + Word16 lsp[] /* Q15 */ +) { Word16 i; @@ -252,7 +269,7 @@ void basop_lsf2lsp( const Word16 lsf[], Word16 lsp[] ) /* convert ISFs to the cosine domain */ FOR( i = 0; i < M; i++ ) { - *lsp++ = xsf_to_xsp( *lsf++ ); + *lsp++ = xsf_to_xsp( *lsf++ ); /* Q15 */ move16(); } diff --git a/lib_com/basop_lsf_tools.c b/lib_com/basop_lsf_tools.c index f378bcbaa..aac96ae5f 100644 --- a/lib_com/basop_lsf_tools.c +++ b/lib_com/basop_lsf_tools.c @@ -62,9 +62,10 @@ static Word16 E_LPC_f_lsp_pol_get( const Word16 lsp[], Word32 f[], const Word16 * void */ void basop_E_LPC_f_lsp_a_conversion( - const Word16 *lsp, - Word16 *a, - const Word16 m ) + const Word16 *lsp, /* Q15 */ + Word16 *a, /* Qx */ + const Word16 m /* Q0 */ +) { Word16 i, j, k; Word32 f1[NC_MAX + 1], f2[NC_MAX + 1]; @@ -83,8 +84,8 @@ void basop_E_LPC_f_lsp_a_conversion( Ovf = 0; move16(); - Ovf = E_LPC_f_lsp_pol_get( &lsp[0], f1, nc, Ovf, 1 ); - Ovf2 = E_LPC_f_lsp_pol_get( &lsp[1], f2, nc, Ovf, 1 ); + Ovf = E_LPC_f_lsp_pol_get( &lsp[0], f1, nc, Ovf, 1 ); /* Q0 */ + Ovf2 = E_LPC_f_lsp_pol_get( &lsp[1], f2, nc, Ovf, 1 ); /* Q0 */ IF( sub( Ovf2, Ovf ) != 0 ) { /* to ensure similar scaling for f1 and f2 in case @@ -99,9 +100,9 @@ void basop_E_LPC_f_lsp_a_conversion( k = sub( nc, 1 ); FOR( i = 0; i <= k; i++ ) { - f1[nc - i] = L_add( f1[nc - i], f1[nc - i - 1] ); + f1[nc - i] = L_add( f1[nc - i], f1[nc - i - 1] ); /* Q23 */ move32(); - f2[nc - i] = L_sub( f2[nc - i], f2[nc - i - 1] ); + f2[nc - i] = L_sub( f2[nc - i], f2[nc - i - 1] ); /* Q23 */ move32(); } @@ -113,8 +114,8 @@ void basop_E_LPC_f_lsp_a_conversion( t0 = L_deposit_l( 0 ); FOR( i = 1; i <= nc; i++ ) { - t0 = L_max( t0, L_abs( L_add( f1[i], f2[i] ) ) ); - t0 = L_max( t0, L_abs( L_sub( f1[i], f2[i] ) ) ); + t0 = L_max( t0, L_abs( L_add( f1[i], f2[i] ) ) ); /* Q23 */ + t0 = L_max( t0, L_abs( L_sub( f1[i], f2[i] ) ) ); /* Q23 */ } k = s_min( norm_l( t0 ), 6 ); a[0] = shl( 256, k ); @@ -129,12 +130,12 @@ void basop_E_LPC_f_lsp_a_conversion( FOR( i = 1; i <= nc; i++ ) { /* a[i] = 0.5*(f1[i] + f2[i]) */ - t0 = L_add( f1[i], f2[i] ); + t0 = L_add( f1[i], f2[i] ); /* Q23 */ t0 = L_shl( t0, k ); a[i] = round_fx( t0 ); /* from Q23 to Qx and * 0.5 */ /* a[j] = 0.5*(f1[i] - f2[i]) */ - t0 = L_sub( f1[i], f2[i] ); + t0 = L_sub( f1[i], f2[i] ); /* Q23 */ t0 = L_shl( t0, k ); a[j] = round_fx( t0 ); /* from Q23 to Qx and * 0.5 */ j--; @@ -153,14 +154,14 @@ void basop_E_LPC_f_lsp_a_conversion( void basop_reorder_lsf( Word16 *lsf, /* i/o: LSFs in the frequency domain (0..0.5) Q(x2.56)*/ const Word16 min_dist, /* i : minimum required distance x2.56*/ - const Word16 n, /* i : LPC order */ - const Word32 Fs /* i : sampling frequency */ + const Word16 n, /* i : LPC order Q0*/ + const Word32 Fs /* i : sampling frequency Q0*/ ) { Word16 i, lsf_min, n_m_1; Word16 lsf_max; - lsf_min = min_dist; + lsf_min = min_dist; /* Q2.56 */ move16(); /*-----------------------------------------------------------------------* @@ -171,10 +172,10 @@ void basop_reorder_lsf( { if ( sub( lsf[i], lsf_min ) < 0 ) { - lsf[i] = lsf_min; + lsf[i] = lsf_min; /* Q2.56 */ move16(); } - lsf_min = add( lsf[i], min_dist ); + lsf_min = add( lsf[i], min_dist ); /* Q2.56 */ } /*-----------------------------------------------------------------------* @@ -183,17 +184,17 @@ void basop_reorder_lsf( lsf_max = round_fx( L_sub( L_shr( L_mult0( extract_l( L_shr( Fs, 1 ) ), 1311 ), 9 - 16 ), L_deposit_h( min_dist ) ) ); /* Q0 + Q9 , 1311 is 2.56 in Q9 */ - n_m_1 = sub( n, 1 ); + n_m_1 = sub( n, 1 ); /* Q0 */ IF( sub( lsf[n_m_1], lsf_max ) > 0 ) /* If danger of unstable filter in case of resonance in HF */ { FOR( i = n_m_1; i >= 0; i-- ) /* Reverify the minimum LSF gap in the reverse direction */ { if ( sub( lsf[i], lsf_max ) > 0 ) { - lsf[i] = lsf_max; + lsf[i] = lsf_max; /* Q2.56 */ move16(); } - lsf_max = sub( lsf[i], min_dist ); + lsf_max = sub( lsf[i], min_dist ); /* Q2.56 */ } } @@ -229,11 +230,12 @@ void basop_reorder_lsf( *-----------------------------------------------------------* */ static Word16 E_LPC_f_lsp_pol_get( - const Word16 lsp[], - Word32 f[], - const Word16 n, - const Word16 past_Ovf, - const Word16 isMODE1 ) + const Word16 lsp[], /* Q15 */ + Word32 f[], /* Q23 */ + const Word16 n, /* Q0 */ + const Word16 past_Ovf, /* Q0 */ + const Word16 isMODE1 /* Q0 */ +) { /* All computation in Q23 */ const Word16 *plsp; @@ -245,8 +247,8 @@ static Word16 E_LPC_f_lsp_pol_get( Word16 m2; #ifdef BASOP_NOGLOB Flag Overflow; -#endif /* BASOP_NOGLOB */ - +#endif /* BASOP_NOGLOB */ + move16(); // move for Ovf = 0 Q_out = 31 - 23; move16(); @@ -271,7 +273,7 @@ static Word16 E_LPC_f_lsp_pol_get( b = *plsp; move16(); m2 = shl( -2, sub( 15, Q_out ) ); - f[1] = L_mult( b, m2 ); + f[1] = L_mult( b, m2 ); /* Q23 */ move32(); FOR( i = 2; i <= n; i++ ) @@ -284,16 +286,16 @@ static Word16 E_LPC_f_lsp_pol_get( /*f[i] = -b*f[i-1] + 2.0f*f[i-2];*/ move32(); - f[i] = L_shl( L_sub( f[i - 2], Mpy_32_16_1( f[i - 1], b ) ), 1 ); + f[i] = L_shl( L_sub( f[i - 2], Mpy_32_16_1( f[i - 1], b ) ), 1 ); /* Q23 */ FOR( j = i - 1; j > 1; j-- ) { /*f[j] += b*f[j-1] + f[j-2];*/ move32(); - f[j] = L_add( f[j], L_sub( f[j - 2], L_shl( Mpy_32_16_1( f[j - 1], b ), 1 ) ) ); + f[j] = L_add( f[j], L_sub( f[j - 2], L_shl( Mpy_32_16_1( f[j - 1], b ), 1 ) ) ); /* Q23 */ } move32(); - f[1] = L_add( f[1], b32 ); + f[1] = L_add( f[1], b32 ); /* Q23 */ } @@ -305,7 +307,7 @@ static Word16 E_LPC_f_lsp_pol_get( #endif /* BASOP_NOGLOB */ /* If an overflow is detected, redo the computation with 1 bit less */ Ovf = add( Ovf, 1 ); - Ovf = E_LPC_f_lsp_pol_get( lsp, f, n, Ovf, isMODE1 ); + Ovf = E_LPC_f_lsp_pol_get( lsp, f, n, Ovf, isMODE1 ); /* Q0 */ } return Ovf; } diff --git a/lib_com/basop_proto_func.h b/lib_com/basop_proto_func.h index d8b9768a1..0580db98e 100644 --- a/lib_com/basop_proto_func.h +++ b/lib_com/basop_proto_func.h @@ -53,18 +53,59 @@ #define INT_FS_FX 12800 /* internal sampling frequency */ void basop_lsp2a_stab( const Word16 *lsp, Word16 *a ); -void basop_lsf2lsp( const Word16 lsf[], Word16 lsp[] ); -void basop_weight_a( const Word16 *a, Word16 *ap, const Word16 gamma ); -void basop_weight_a_inv( const Word16 *a, Word16 *ap, const Word16 inv_gamma ); -void basop_E_LPC_a_add_tilt( const Word16 *a, Word16 *ap, Word16 gamma ); -void basop_reorder_lsf( Word16 *lsf, const Word16 min_dist, const Word16 n, const Word32 Fs ); -void basop_E_LPC_f_lsp_a_conversion( const Word16 *lsp, Word16 *a, const Word16 m ); +void basop_lsf2lsp( + const Word16 lsf[], /* Q2.56 */ + Word16 lsp[] /* Q15 */ +); + +void basop_weight_a( + const Word16 *a, /* Q12 */ + Word16 *ap, /* Q12 */ + const Word16 gamma /* Q15 */ +); + +void basop_weight_a_inv( + const Word16 *a, /* Q12 */ + Word16 *ap, /* Q12 */ + const Word16 inv_gamma /* Q14 */ +); +void basop_E_LPC_a_add_tilt( + const Word16 *a, /* Q12 */ + Word16 *ap, /* Q12 */ + Word16 gamma /* Q14 */ +); +void basop_reorder_lsf( + Word16 *lsf, /* i/o: LSFs in the frequency domain (0..0.5) Q(x2.56)*/ + const Word16 min_dist, /* i : minimum required distance x2.56*/ + const Word16 n, /* i : LPC order Q0*/ + const Word32 Fs /* i : sampling frequency Q0*/ +); +void basop_E_LPC_f_lsp_a_conversion( + const Word16 *lsp, /* Q15 */ + Word16 *a, /* Qx */ + const Word16 m /* Q0 */ +); /* tcx_utils.c */ -void basop_lpc2mdct( Word16 *lpcCoeffs, Word16 lpcOrder, Word16 *mdct_gains, Word16 *mdct_gains_exp, Word16 *mdct_inv_gains, Word16 *mdct_inv_gains_exp ); - -void basop_PsychAdaptLowFreqDeemph( Word32 x[], const Word16 lpcGains[], const Word16 lpcGains_e[], Word16 lf_deemph_factors[] ); -void basop_mdct_noiseShaping_interp( Word32 x[], Word16 lg, Word16 gains[], Word16 gains_exp[] ); +void basop_lpc2mdct( + Word16 *lpcCoeffs, /* Q12 */ + Word16 lpcOrder, /* Q0 */ + Word16 *mdct_gains, /* Q12 */ + Word16 *mdct_gains_exp, + Word16 *mdct_inv_gains, /* Q12 */ + Word16 *mdct_inv_gains_exp ); + +void basop_PsychAdaptLowFreqDeemph( + Word32 x[], /* Q16 */ + const Word16 lpcGains[], /* exp(lpcGains_e) */ + const Word16 lpcGains_e[], + Word16 lf_deemph_factors[] /* Qx */ +); +void basop_mdct_noiseShaping_interp( + Word32 x[], /* Q16 */ + Word16 lg, /* Q0 */ + Word16 gains[], /* exp(gain_exp) */ + Word16 gains_exp[] ); #endif diff --git a/lib_com/basop_tcx_utils.c b/lib_com/basop_tcx_utils.c index 5730b2212..579711080 100644 --- a/lib_com/basop_tcx_utils.c +++ b/lib_com/basop_tcx_utils.c @@ -60,7 +60,13 @@ // return tmp; // } -void basop_lpc2mdct( Word16 *lpcCoeffs, Word16 lpcOrder, Word16 *mdct_gains, Word16 *mdct_gains_exp, Word16 *mdct_inv_gains, Word16 *mdct_inv_gains_exp ) +void basop_lpc2mdct( + Word16 *lpcCoeffs, /* Q12 */ + Word16 lpcOrder, /* Q0 */ + Word16 *mdct_gains, /* Q12 */ + Word16 *mdct_gains_exp, + Word16 *mdct_inv_gains, /* Q12 */ + Word16 *mdct_inv_gains_exp ) { Word32 RealData[FDNS_NPTS]; Word32 ImagData[FDNS_NPTS]; @@ -80,9 +86,9 @@ void basop_lpc2mdct( Word16 *lpcCoeffs, Word16 lpcOrder, Word16 *mdct_gains, Wor /* pre-twiddle */ FOR( i = 0; i <= lpcOrder; i++ ) { - RealData[i] = L_mult( lpcCoeffs[i], ptwiddle->v.re ); + RealData[i] = L_mult( lpcCoeffs[i], ptwiddle->v.re ); /* Q28 */ move32(); - ImagData[i] = L_negate( L_mult( lpcCoeffs[i], ptwiddle->v.im ) ); + ImagData[i] = L_negate( L_mult( lpcCoeffs[i], ptwiddle->v.im ) ); /* Q28 */ move32(); ptwiddle += step; } @@ -103,7 +109,7 @@ void basop_lpc2mdct( Word16 *lpcCoeffs, Word16 lpcOrder, Word16 *mdct_gains, Wor /*Get amplitude*/ - j = FDNS_NPTS - 1; + j = FDNS_NPTS - 1; /* Q0 */ k = 0; move16(); move16(); @@ -135,7 +141,7 @@ void basop_lpc2mdct( Word16 *lpcCoeffs, Word16 lpcOrder, Word16 *mdct_gains, Wor if ( mdct_gains != NULL ) { - mdct_gains[k] = g; + mdct_gains[k] = g; /* exp(g_e) */ move16(); } @@ -147,7 +153,7 @@ void basop_lpc2mdct( Word16 *lpcCoeffs, Word16 lpcOrder, Word16 *mdct_gains, Wor if ( mdct_inv_gains != NULL ) { - mdct_inv_gains[k] = ig; + mdct_inv_gains[k] = ig; /* exp(ig_e) */ move16(); } @@ -157,7 +163,7 @@ void basop_lpc2mdct( Word16 *lpcCoeffs, Word16 lpcOrder, Word16 *mdct_gains, Wor move16(); } - k = add( k, 1 ); + k++; s = sub( norm_l( L_max( L_abs( RealData[j] ), L_abs( ImagData[j] ) ) ), 1 ); @@ -185,7 +191,7 @@ void basop_lpc2mdct( Word16 *lpcCoeffs, Word16 lpcOrder, Word16 *mdct_gains, Wor if ( mdct_gains != NULL ) { - mdct_gains[k] = g; + mdct_gains[k] = g; /* exp(g_e) */ move16(); } @@ -197,7 +203,7 @@ void basop_lpc2mdct( Word16 *lpcCoeffs, Word16 lpcOrder, Word16 *mdct_gains, Wor if ( mdct_inv_gains != NULL ) { - mdct_inv_gains[k] = ig; + mdct_inv_gains[k] = ig; /* exp(ig_e) */ move16(); } @@ -207,13 +213,17 @@ void basop_lpc2mdct( Word16 *lpcCoeffs, Word16 lpcOrder, Word16 *mdct_gains, Wor move16(); } - j = sub( j, 1 ); - k = add( k, 1 ); + j--; + k++; } } -void basop_mdct_noiseShaping_interp( Word32 x[], Word16 lg, Word16 gains[], Word16 gains_exp[] ) +void basop_mdct_noiseShaping_interp( + Word32 x[], /* Q16 */ + Word16 lg, /* Q0 */ + Word16 gains[], /* exp(gain_exp) */ + Word16 gains_exp[] ) { Word16 i, j, jp, jn, k, l; Word16 g, pg, ng, e, tmp; @@ -251,16 +261,16 @@ void basop_mdct_noiseShaping_interp( Word32 x[], Word16 lg, Word16 gains[], Word g = shl( g, tmp ); e = s_max( gains_exp[j], gains_exp[jp] ); - tmp = mac_r( L_mult( pg, FL2WORD16( 0.375f ) ), g, FL2WORD16( 0.625f ) ); - x[i] = L_shl( Mpy_32_16_1( x[i], tmp ), e ); + tmp = mac_r( L_mult( pg, 12288 /* 0.375 in Q15 */ ), g, 20480 /* 0.625 in Q15 */ ); /* exp(gains_exp) */ + x[i] = L_shl( Mpy_32_16_1( x[i], tmp ), e ); /* Q16 */ move32(); - tmp = mac_r( L_mult( pg, FL2WORD16( 0.125f ) ), g, FL2WORD16( 0.875f ) ); - x[i + 1] = L_shl( Mpy_32_16_1( x[i + 1], tmp ), e ); + tmp = mac_r( L_mult( pg, 4096 /* 0.125 in Q15*/ ), g, 28672 /* 0.875 in Q15 */ ); /* exp(gains_exp) */ + x[i + 1] = L_shl( Mpy_32_16_1( x[i + 1], tmp ), e ); /* Q16 */ move32(); /* common exponent for g and ng */ - g = gains[j]; + g = gains[j]; /* exp(gains_exp) */ move16(); tmp = sub( gains_exp[j], gains_exp[jn] ); if ( tmp > 0 ) @@ -269,19 +279,19 @@ void basop_mdct_noiseShaping_interp( Word32 x[], Word16 lg, Word16 gains[], Word g = shl( g, tmp ); e = s_max( gains_exp[j], gains_exp[jn] ); - tmp = mac_r( L_mult( g, FL2WORD16( 0.875f ) ), ng, FL2WORD16( 0.125f ) ); - x[i + 2] = L_shl( Mpy_32_16_1( x[i + 2], tmp ), e ); + tmp = mac_r( L_mult( g, 28672 /* 0.875 in Q15 */ ), ng, 4096 /* 0.125 in Q15*/ ); /* exp(gains_exp) */ + x[i + 2] = L_shl( Mpy_32_16_1( x[i + 2], tmp ), e ); /* Q16 */ move32(); - tmp = mac_r( L_mult( g, FL2WORD16( 0.625f ) ), ng, FL2WORD16( 0.375f ) ); - x[i + 3] = L_shl( Mpy_32_16_1( x[i + 3], tmp ), e ); + tmp = mac_r( L_mult( g, 20480 /* 0.625 in Q15 */ ), ng, 12288 /* 0.375 in Q15 */ ); /* exp(gains_exp) */ + x[i + 3] = L_shl( Mpy_32_16_1( x[i + 3], tmp ), e ); /* Q16 */ move32(); jp = j; move16(); j = jn; move16(); - jn = s_min( add( jn, 1 ), FDNS_NPTS - 1 ); + jn = s_min( add( jn, 1 ), FDNS_NPTS - 1 ); /* Q0 */ } } ELSE IF( sub( k, 5 ) == 0 ) @@ -310,16 +320,16 @@ void basop_mdct_noiseShaping_interp( Word32 x[], Word16 lg, Word16 gains[], Word g = shl( g, tmp ); e = s_max( gains_exp[j], gains_exp[jp] ); - tmp = mac_r( L_mult( pg, FL2WORD16( 0.40f ) ), g, FL2WORD16( 0.60f ) ); - x[i] = L_shl( Mpy_32_16_1( x[i], tmp ), e ); + tmp = mac_r( L_mult( pg, 13107 /* 0.4 in Q15 */ ), g, 19661 /* 0.6 in Q15 */ ); /* exp(gains_exp) */ + x[i] = L_shl( Mpy_32_16_1( x[i], tmp ), e ); /* Q16 */ move32(); - tmp = mac_r( L_mult( pg, FL2WORD16( 0.20f ) ), g, FL2WORD16( 0.80f ) ); - x[i + 1] = L_shl( Mpy_32_16_1( x[i + 1], tmp ), e ); + tmp = mac_r( L_mult( pg, 6554 /* 0.2 in Q15 */ ), g, 26214 /* 0.8 in Q15 */ ); /* exp(gains_exp) */ + x[i + 1] = L_shl( Mpy_32_16_1( x[i + 1], tmp ), e ); /* Q16 */ move32(); - x[i + 2] = L_shl( Mpy_32_16_1( x[i + 2], gains[j] ), gains_exp[j] ); + x[i + 2] = L_shl( Mpy_32_16_1( x[i + 2], gains[j] ), gains_exp[j] ); /* Q16 */ move32(); /* common exponent for g and ng */ @@ -332,19 +342,19 @@ void basop_mdct_noiseShaping_interp( Word32 x[], Word16 lg, Word16 gains[], Word g = shl( g, tmp ); e = s_max( gains_exp[j], gains_exp[jn] ); - tmp = mac_r( L_mult( g, FL2WORD16( 0.80f ) ), ng, FL2WORD16( 0.20f ) ); - x[i + 3] = L_shl( Mpy_32_16_1( x[i + 3], tmp ), e ); + tmp = mac_r( L_mult( g, 26214 /* 0.8 in Q15 */ ), ng, 6554 /* 0.2 in Q15 */ ); /* exp(gains_exp) */ + x[i + 3] = L_shl( Mpy_32_16_1( x[i + 3], tmp ), e ); /* Q16 */ move32(); - tmp = mac_r( L_mult( g, FL2WORD16( 0.60f ) ), ng, FL2WORD16( 0.40f ) ); - x[i + 4] = L_shl( Mpy_32_16_1( x[i + 4], tmp ), e ); + tmp = mac_r( L_mult( g, 19661 /* 0.6 in Q15 */ ), ng, 13107 /* 0.4 in Q15 */ ); /* exp(gains_exp) */ + x[i + 4] = L_shl( Mpy_32_16_1( x[i + 4], tmp ), e ); /* Q16 */ move32(); jp = j; move16(); j = jn; move16(); - jn = s_min( add( jn, 1 ), FDNS_NPTS - 1 ); + jn = s_min( add( jn, 1 ), FDNS_NPTS - 1 ); /* Q0 */ } } ELSE /* no interpolation */ @@ -353,7 +363,7 @@ void basop_mdct_noiseShaping_interp( Word32 x[], Word16 lg, Word16 gains[], Word { FOR( l = 0; l < k; l++ ) { - *x = L_shl( Mpy_32_16_1( *x, *gains ), *gains_exp ); + *x = L_shl( Mpy_32_16_1( *x, *gains ), *gains_exp ); /* Q16 */ move32(); x++; } @@ -366,7 +376,12 @@ void basop_mdct_noiseShaping_interp( Word32 x[], Word16 lg, Word16 gains[], Word } -void basop_PsychAdaptLowFreqDeemph( Word32 x[], const Word16 lpcGains[], const Word16 lpcGains_e[], Word16 lf_deemph_factors[] ) +void basop_PsychAdaptLowFreqDeemph( + Word32 x[], /* Q16 */ + const Word16 lpcGains[], /* exp(lpcGains_e) */ + const Word16 lpcGains_e[], + Word16 lf_deemph_factors[] /* Qx */ +) { Word16 i; Word16 max_val, max_e, fac, min_val, min_e, tmp, tmp_e; @@ -424,14 +439,14 @@ void basop_PsychAdaptLowFreqDeemph( Word32 x[], const Word16 lpcGains[], const W /* gradual lowering of lowest 32 bins; DC is lowered by (max/tmp)^1/4 */ FOR( i = 31; i >= 0; i-- ) { - x[i] = Mpy_32_16_1( x[i], fac ); + x[i] = Mpy_32_16_1( x[i], fac ); /* Q16 */ move32(); if ( lf_deemph_factors != NULL ) { - lf_deemph_factors[i] = mult_r( lf_deemph_factors[i], fac ); + lf_deemph_factors[i] = mult_r( lf_deemph_factors[i], fac ); /* Qx */ move16(); } - fac = mult_r( fac, tmp ); + fac = mult_r( fac, tmp ); /* Q15 */ } } } diff --git a/lib_com/bitalloc.c b/lib_com/bitalloc.c index 7e1c92f9c..0daed8fc5 100644 --- a/lib_com/bitalloc.c +++ b/lib_com/bitalloc.c @@ -228,14 +228,14 @@ void bitalloc( /*! r: Integer (truncated) number of allocated bits */ int16_t BitAllocF( - int16_t *y, /* i : norm of sub-vectors */ - int32_t bit_rate, /* i : bitrate */ - int16_t B, /* i : number of available bits */ - int16_t N, /* i : number of sub-vectors */ - int16_t *R, /* o : bit-allocation indicator */ - int16_t *Rsubband, /* o : sub-band bit-allocation vector (Q3) */ - const int16_t hqswb_clas, /* i : hq swb class */ - const int16_t num_env_bands /* i : Number sub bands to be encoded for HQ_SWB_BWE */ + Word16 *y, /* i : norm of sub-vectors Q0*/ + Word32 bit_rate, /* i : bitrate Q0*/ + Word16 B, /* i : number of available bits Q0*/ + Word16 N, /* i : number of sub-vectors Q0*/ + Word16 *R, /* o : bit-allocation indicator Q0*/ + Word16 *Rsubband, /* o : sub-band bit-allocation vector Q3*/ + const Word16 hqswb_clas, /* i : hq swb class Q0*/ + const Word16 num_env_bands /* i : Number sub bands to be encoded for HQ_SWB_BWE Q0*/ ) { Word16 fac; @@ -256,18 +256,18 @@ int16_t BitAllocF( fac = 3; if ( L_sub( bit_rate, 32000 ) < 0 ) { - bs = 2; + bs = 2; /* Q0 */ } else { - bs = 3; + bs = 3; /* Q0 */ } - low_rate = 1; + low_rate = 1; /* Q0 */ - Nmin = N; + Nmin = N; /* Q0 */ if ( sub( Nmin, SFM_N ) > 0 ) { - Nmin = SFM_N; + Nmin = SFM_N; /* Q0 */ } /* Initial bits distribution */ @@ -278,13 +278,13 @@ int16_t BitAllocF( m_fx = 0; for ( i = 0; i < num_env_bands; i++ ) { - L_tmp1 = L_mac0( L_tmp1, Nb[i], y[i] ); + L_tmp1 = L_mac0( L_tmp1, Nb[i], y[i] ); /* Q0 */ } - L_tmp1 = L_msu0( L_tmp1, fac, B ); + L_tmp1 = L_msu0( L_tmp1, fac, B ); /* Q0 */ t_fx = 0; n = 0; - tmp = add( band_end_HQ[num_env_bands - 1], shl( band_end_HQ[num_env_bands - 1], 1 ) ); + tmp = add( band_end_HQ[num_env_bands - 1], shl( band_end_HQ[num_env_bands - 1], 1 ) ); /* Q0 */ exp1 = norm_s( tmp ); tmp = div_s( 16384, shl( tmp, exp1 ) ); /*15 + 14 - exp1*/ exp2 = norm_s( tmp ); @@ -303,7 +303,7 @@ int16_t BitAllocF( move32(); /*exp1 - 15*/ Rsubband_w32_fx[i] = L_shl( Rsubband_w32_fx[i], sub( 30, exp1 ) ); /*Q15*/ - t_fx = L_add( t_fx, Rsubband_w32_fx[i] ); /*Q0*/ + t_fx = L_add( t_fx, Rsubband_w32_fx[i] ); /*Q15*/ } else { @@ -319,14 +319,14 @@ int16_t BitAllocF( m_fx = 0; for ( i = 0; i < N; i++ ) { - L_tmp1 = L_mac0( L_tmp1, Nb[i], y[i] ); + L_tmp1 = L_mac0( L_tmp1, Nb[i], y[i] ); /* Q0 */ } - L_tmp1 = L_msu0( L_tmp1, fac, B ); + L_tmp1 = L_msu0( L_tmp1, fac, B ); /* Q0 */ t_fx = 0; n = 0; - tmp = add( band_end_HQ[N - 1], shl( band_end_HQ[N - 1], 1 ) ); + tmp = add( band_end_HQ[N - 1], shl( band_end_HQ[N - 1], 1 ) ); /* Q0 */ exp1 = norm_s( tmp ); tmp = div_s( 16384, shl( tmp, exp1 ) ); /*15 + 14 - exp1*/ exp2 = norm_s( tmp ); @@ -334,7 +334,7 @@ int16_t BitAllocF( exp1 = add( 29, sub( exp2, exp1 ) ); for ( i = 0; i < N; i++ ) { - L_tmp2 = L_sub( L_mult0( y[i], band_end_HQ[N - 1] ), L_tmp1 ); + L_tmp2 = L_sub( L_mult0( y[i], band_end_HQ[N - 1] ), L_tmp1 ); /* Q0 */ Rsubband_w32_fx[i] = L_mult0( extract_l( L_tmp2 ), Nb[i] ); move32(); /*Q0*/ if ( Rsubband_w32_fx[i] > 0 ) @@ -344,7 +344,7 @@ int16_t BitAllocF( move32(); /*exp1 - 15*/ Rsubband_w32_fx[i] = L_shl( Rsubband_w32_fx[i], sub( 30, exp1 ) ); /*Q15*/ - t_fx = L_add( t_fx, Rsubband_w32_fx[i] ); /*Q0*/ + t_fx = L_add( t_fx, Rsubband_w32_fx[i] ); /*Q15*/ } else { @@ -381,7 +381,7 @@ int16_t BitAllocF( { n = add( n, Nb[i] ); - t_fx = L_add( t_fx, Rsubband_w32_fx[i] ); + t_fx = L_add( t_fx, Rsubband_w32_fx[i] ); /* Q15 */ } else { @@ -409,14 +409,14 @@ int16_t BitAllocF( } else if ( L_sub( Rsubband_w32_fx[i], L_shl( Nb[i], 15 ) ) <= 0 ) { - B = sub( B, Nb[i] ); - Rsubband_w32_fx[i] = L_shl( Nb[i], 15 ); + B = sub( B, Nb[i] ); /* Q0 */ + Rsubband_w32_fx[i] = L_shl( Nb[i], 15 ); /* Q15 */ move32(); } else { - n = add( n, Nb[i] ); - t_fx = L_add( t_fx, Rsubband_w32_fx[i] ); + n = add( n, Nb[i] ); /* Q0 */ + t_fx = L_add( t_fx, Rsubband_w32_fx[i] ); /* Q15 */ } } } @@ -448,18 +448,18 @@ int16_t BitAllocF( { if ( L_sub( Rsubband_w32_fx[i], L_shl( Nb[i], 15 ) ) > 0 ) { - Rsubband_w32_fx[i] = L_msu( Rsubband_w32_fx[i], m_fx, Nb[i] ); + Rsubband_w32_fx[i] = L_msu( Rsubband_w32_fx[i], m_fx, Nb[i] ); /* Q15 */ if ( L_sub( Rsubband_w32_fx[i], L_shl( Nb[i], 15 ) ) > 0 ) { - n = add( n, Nb[i] ); + n = add( n, Nb[i] ); /* Q0 */ - t_fx = L_add( t_fx, Rsubband_w32_fx[i] ); + t_fx = L_add( t_fx, Rsubband_w32_fx[i] ); /* Q15 */ } else { - B = sub( B, Nb[i] ); + B = sub( B, Nb[i] ); /* Q0 */ - Rsubband_w32_fx[i] = L_shl( Nb[i], 15 ); + Rsubband_w32_fx[i] = L_shl( Nb[i], 15 ); /* Q15 */ move32(); } } @@ -472,7 +472,7 @@ int16_t BitAllocF( { if ( Rsubband_w32_fx[i] > 0 ) { - B = add( B, Nb[i] ); + B = add( B, Nb[i] ); /* Q0 */ Rsubband_w32_fx[i] = 0; move32(); if ( B >= 0 ) @@ -489,12 +489,12 @@ int16_t BitAllocF( tmp = 0; for ( i = 0; i < N; i++ ) { - Rsubband[i] = extract_l( L_shr( Rsubband_w32_fx[i], 12 ) ); - tmp = add( tmp, Rsubband[i] ); + Rsubband[i] = extract_l( L_shr( Rsubband_w32_fx[i], 12 ) ); /* Q3 */ + tmp = add( tmp, Rsubband[i] ); /* Q3 */ } - B = Bits; - B_w16_fx = shl( B, 3 ); + B = Bits; /* Q0 */ + B_w16_fx = shl( B, 3 ); /* Q3 */ if ( sub( tmp, B_w16_fx ) > 0 ) { tmp = sub( tmp, B_w16_fx ); @@ -502,19 +502,19 @@ int16_t BitAllocF( { if ( sub( Rsubband[i], add( shl( Nb[i], 3 ), tmp ) ) >= 0 ) { - Rsubband[i] = sub( Rsubband[i], tmp ); + Rsubband[i] = sub( Rsubband[i], tmp ); /* Q3 */ BREAK; } } } else { - tmp = sub( tmp, B_w16_fx ); + tmp = sub( tmp, B_w16_fx ); /* Q3 */ for ( i = 0; i < N; i++ ) { if ( Rsubband[i] > 0 ) { - Rsubband[i] = sub( Rsubband[i], tmp ); + Rsubband[i] = sub( Rsubband[i], tmp ); /* Q3 */ BREAK; } } @@ -524,8 +524,8 @@ int16_t BitAllocF( tmp = 0; for ( i = 0; i < N; i++ ) { - tmp = add( tmp, Rsubband[i] ); - R[i] = shr( Rsubband[i], 3 ); + tmp = add( tmp, Rsubband[i] ); /* Q3 */ + R[i] = shr( Rsubband[i], 3 ); /* Q0 */ } return shr( tmp, 3 ); @@ -552,6 +552,9 @@ static void Bit_group_fx( Word32 R_temp_fx[16], R_sum_fx = 0, R_sum_org_fx = 0, Bits_avg_fx = 0; Word32 L_tmp; UWord32 lo; + move32(); + move32(); + move32(); /* initialization for bit allocation in one group*/ tmp = 6554; @@ -576,9 +579,9 @@ static void Bit_group_fx( FOR( i = 0; i < band_num; i++ ) { - y_index[i] = y[add( i, start_band )]; + y_index[i] = y[i + start_band]; /* Q0 */ move16(); - index[i] = i; + index[i] = i; /* Q0 */ move16(); } @@ -622,15 +625,15 @@ static void Bit_group_fx( y_index[j] = 0; move16(); } - R_temp_fx[j] = 2097152; - move16(); /*Q21 = 1 move16(); */ + R_temp_fx[j] = 2097152; /* 1 in Q21 */ + move16(); } i = sub( band_num, 1 ); norm_sum = 0; /*Q0 */ FOR( k = 0; k <= i; k++ ) { - norm_sum = add( norm_sum, y_index[k] ); + norm_sum = add( norm_sum, y_index[k] ); /* Q0 */ } FOR( j = 0; j < band_num; j++ ) @@ -653,7 +656,7 @@ static void Bit_group_fx( FOR( k = 0; k <= i; k++ ) { L_tmp = L_shl( L_deposit_l( y_index[k] ), 24 ); - Mpy_32_32_ss( Bits_avg_fx, L_tmp, &L_tmp, &lo ); + Mpy_32_32_ss( Bits_avg_fx, L_tmp, &L_tmp, &lo ); /*Q(30-exp) */ R_temp_fx[k] = L_shl( L_tmp, sub( exp, 2 ) ); move32(); /*Q21 */ @@ -665,7 +668,7 @@ static void Bit_group_fx( { R_temp_fx[i] = 0; move32(); - norm_sum = sub( norm_sum, y_index[i] ); + norm_sum = sub( norm_sum, y_index[i] ); /* Q0 */ i--; } ELSE @@ -683,8 +686,8 @@ static void Bit_group_fx( y_index[j] = 0; move16(); } - R_temp_fx[j] = 2097152; - move32(); /*Q21 = 1 */ + R_temp_fx[j] = 2097152; /* 1 in Q21 */ + move32(); } FOR( j = bit_band; j < band_num; j++ ) @@ -696,7 +699,7 @@ static void Bit_group_fx( norm_sum = 0; FOR( k = 0; k < bit_band; k++ ) { - norm_sum = add( norm_sum, y_index[k] ); + norm_sum = add( norm_sum, y_index[k] ); /* Q0 */ } i = bit_band; @@ -719,7 +722,7 @@ static void Bit_group_fx( FOR( k = 0; k < i; k++ ) { L_tmp = L_shl( L_deposit_l( y_index[k] ), 24 ); - Mpy_32_32_ss( Bits_avg_fx, L_tmp, &L_tmp, &lo ); + Mpy_32_32_ss( Bits_avg_fx, L_tmp, &L_tmp, &lo ); /*Q(30-exp) */ R_temp_fx[k] = L_shl( L_tmp, sub( exp, 2 ) ); move32(); /*Q21 */ } @@ -732,7 +735,7 @@ static void Bit_group_fx( { FOR( m = k; m < i; m++ ) { - norm_sum = sub( norm_sum, y_index[m] ); + norm_sum = sub( norm_sum, y_index[m] ); /* Q0 */ R_temp_fx[m] = 0; move32(); /*Q21 */ } @@ -758,7 +761,7 @@ static void Bit_group_fx( { j = index[k]; move16(); - Rsubband_fx[add( j, start_band )] = R_temp_fx[k]; + Rsubband_fx[j + start_band] = R_temp_fx[k]; /* Q21 */ move32(); } @@ -772,12 +775,12 @@ static void Bit_group_fx( *-------------------------------------------------------------------*/ /*! r: Integer (truncated) number of allocated bits */ -int16_t BitAllocWB( - int16_t *y, /* i : norm of sub-vectors */ - int16_t B, /* i : number of available bits */ - int16_t N, /* i : number of sub-vectors */ - int16_t *R, /* o : bit-allocation indicator */ - int16_t *Rsubband /* o : sub-band bit-allocation vector (Q3) */ +Word16 BitAllocWB( + Word16 *y, /* i : norm of sub-vectors Q0*/ + Word16 B, /* i : number of available bits Q0*/ + Word16 N, /* i : number of sub-vectors Q0*/ + Word16 *R, /* o : bit-allocation indicator Q0*/ + Word16 *Rsubband /* o : sub-band bit-allocation vector (Q3) Q3*/ ) { Word16 t_fx; @@ -791,18 +794,18 @@ int16_t BitAllocWB( Word32 Rsubband_buf[NB_SFM]; UWord16 lo; - BANDS = N; + BANDS = N; /* Q0 */ move16(); IF( sub( BANDS, SFM_N ) > 0 ) { - BANDS = SFM_N; + BANDS = SFM_N; /* Q0 */ move16(); } /* Init Rsubband to non-zero values for bands to be allocated bits */ FOR( k = 0; k < BANDS; k++ ) { Rsubband_buf[k] = 2097152; - move32(); /*Q21 */ + move32(); /*1 in Q21 */ } /* Calculate the norm sum and average of sub-band */ Rsum_sub_fx[0] = 0; @@ -857,7 +860,7 @@ int16_t BitAllocWB( R_diff_32_fx[1] = L_sub( Ravg_sub_32_fx[1], Ravg_sub_32_fx[2] ); move32(); /*Q16 */ - IF( L_sub( R_diff_32_fx[0], 393216 ) < 0 && L_sub( R_diff_32_fx[1], 245760 ) < 0 ) + IF( L_sub( R_diff_32_fx[0], 393216 /* 32 in Q16 */ ) < 0 && L_sub( R_diff_32_fx[1], 245760 /* 3.75 in Q16 */ ) < 0 ) { IF( Rsum_fx == 0 ) { @@ -878,47 +881,47 @@ int16_t BitAllocWB( B1 = extract_h( L_shl( L_tmp, add( exp, 1 ) ) ); /*Q0 */ IF( L_sub( L_tmp1, L_mult( B1, Rsum_fx ) ) > 0 && L_sub( L_tmp1, L_mult( add( B1, 1 ), Rsum_fx ) ) >= 0 ) { - B1 = add( B1, 1 ); + B1 = add( B1, 1 ); /* Q0 */ } - L_tmp1 = L_mult( B, Rsum_sub_fx[1] ); /*Q1 */ - Mpy_32_16_ss( L_tmp1, tmp, &L_tmp, &lo ); + L_tmp1 = L_mult( B, Rsum_sub_fx[1] ); /*Q1 */ + Mpy_32_16_ss( L_tmp1, tmp, &L_tmp, &lo ); /*Q(15-exp) */ B2 = extract_h( L_shl( L_tmp, add( exp, 1 ) ) ); /*Q0 */ IF( L_sub( L_tmp1, L_mult( B2, Rsum_fx ) ) > 0 && L_sub( L_tmp1, L_mult( add( B2, 1 ), Rsum_fx ) ) >= 0 ) { - B2 = add( B2, 1 ); + B2 = add( B2, 1 ); /* Q0 */ } - L_tmp1 = L_mult( B, Rsum_sub_fx[2] ); /*Q1 */ - Mpy_32_16_ss( L_tmp1, tmp, &L_tmp, &lo ); + L_tmp1 = L_mult( B, Rsum_sub_fx[2] ); /*Q1 */ + Mpy_32_16_ss( L_tmp1, tmp, &L_tmp, &lo ); /*Q(15-exp) */ B3 = extract_h( L_shl( L_tmp, add( exp, 1 ) ) ); /*Q0 */ IF( L_sub( L_tmp1, L_mult( B3, Rsum_fx ) ) > 0 && L_sub( L_tmp1, L_mult( add( B3, 1 ), Rsum_fx ) ) >= 0 ) { - B3 = add( B3, 1 ); + B3 = add( B3, 1 ); /* Q0 */ } } - IF( L_sub( Ravg_sub_32_fx[2], 786432 ) > 0 ) + IF( L_sub( Ravg_sub_32_fx[2], 786432 /* 12 in Q16 */ ) > 0 ) { B_saved = 0; move16(); IF( sub( B1, 288 ) > 0 ) { - B_saved = sub( B1, 288 ); - B1 = 288; + B_saved = sub( B1, 288 ); /* Q0 */ + B1 = 288; /* Q0 */ move16(); } IF( sub( B2, 256 ) > 0 ) { - tmp = sub( B2, 256 ); - B_saved = add( B_saved, tmp ); - B2 = 256; + tmp = sub( B2, 256 ); /* Q0 */ + B_saved = add( B_saved, tmp ); /* Q0 */ + B2 = 256; /* Q0 */ move16(); } IF( sub( B3, 96 ) > 0 ) { - tmp = sub( B3, 96 ); - B_saved = add( B_saved, tmp ); - B3 = 96; + tmp = sub( B3, 96 ); /* Q0 */ + B_saved = add( B_saved, tmp ); /* Q0 */ + B3 = 96; /* Q0 */ move16(); } @@ -926,24 +929,24 @@ int16_t BitAllocWB( { IF( sub( B1, 288 ) == 0 ) { - tmp = shr( B_saved, 1 ); - B2 = add( B2, tmp ); - tmp = sub( B, B1 ); - B3 = sub( tmp, B2 ); + tmp = shr( B_saved, 1 ); /* Q0 */ + B2 = add( B2, tmp ); /* Q0 */ + tmp = sub( B, B1 ); /* Q0 */ + B3 = sub( tmp, B2 ); /* Q0 */ } ELSE { - tmp = shr( B_saved, 1 ); - B1 = add( B1, tmp ); + tmp = shr( B_saved, 1 ); /* Q0 */ + B1 = add( B1, tmp ); /* Q0 */ IF( sub( B2, 256 ) == 0 ) { - tmp = sub( B, B1 ); - B3 = sub( tmp, B2 ); + tmp = sub( B, B1 ); /* Q0 */ + B3 = sub( tmp, B2 ); /* Q0 */ } ELSE { - tmp = sub( B, B1 ); - B2 = sub( tmp, B3 ); + tmp = sub( B, B1 ); /* Q0 */ + B2 = sub( tmp, B3 ); /* Q0 */ } } } @@ -968,24 +971,24 @@ int16_t BitAllocWB( ELSE { exp = norm_s( Rsum_fx ); - tmp = shl( Rsum_fx, exp ); /*Q(exp) */ - tmp = div_s( 16384, tmp ); /*Q(15+14-exp) */ - L_tmp1 = L_mult( B, Rsum_sub_fx[0] ); /*Q1 */ - Mpy_32_16_ss( L_tmp1, tmp, &L_tmp, &lo ); + tmp = shl( Rsum_fx, exp ); /*Q(exp) */ + tmp = div_s( 16384, tmp ); /*Q(15+14-exp) */ + L_tmp1 = L_mult( B, Rsum_sub_fx[0] ); /*Q1 */ + Mpy_32_16_ss( L_tmp1, tmp, &L_tmp, &lo ); /*Q(15-exp) */ B1 = extract_h( L_shl( L_tmp, add( exp, 1 ) ) ); /*Q0 */ IF( L_sub( L_tmp1, L_mult( B1, Rsum_fx ) ) > 0 && L_sub( L_tmp1, L_mult( add( B1, 1 ), Rsum_fx ) ) >= 0 ) { - B1 = add( B1, 1 ); + B1 = add( B1, 1 ); /* Q0 */ } - Mpy_32_16_ss( 1975684956, shl( B, 5 ), &L_tmp1, &lo ); - Mpy_32_16_ss( L_tmp1, shl( Rsum_sub_fx[1], 7 ), &L_tmp1, &lo ); - Mpy_32_16_ss( L_tmp1, tmp, &L_tmp, &lo ); - B2 = extract_h( L_shl( L_tmp, sub( exp, 11 ) ) ); /*Q0 */ + Mpy_32_16_ss( 1975684956 /* 0.92 in Q31 */, shl( B, 5 ), &L_tmp1, &lo ); /*Q(31+5-15=21) */ + Mpy_32_16_ss( L_tmp1, shl( Rsum_sub_fx[1], 7 ), &L_tmp1, &lo ); /*Q(21+7-15=13) */ + Mpy_32_16_ss( L_tmp1, tmp, &L_tmp, &lo ); /*Q(27-exp) */ + B2 = extract_h( L_shl( L_tmp, sub( exp, 11 ) ) ); /*Q0 */ IF( L_sub( L_tmp1, L_shl( L_mult( B2, Rsum_fx ), 12 ) ) > 0 && L_sub( L_add( L_tmp1, 2 ), L_shl( L_mult( add( B2, 1 ), Rsum_fx ), 12 ) ) >= 0 ) { - B2 = add( B2, 1 ); + B2 = add( B2, 1 ); /* Q0 */ } - tmp = sub( B, B1 ); + tmp = sub( B, B1 ); /* Q0 */ B3 = sub( tmp, B2 ); } } @@ -1004,7 +1007,7 @@ int16_t BitAllocWB( Bit_group_fx( y, SFM_G1G2, BANDS, B3, 7, Rsubband_buf, factor_fx ); FOR( i = 0; i < BANDS; i++ ) { - Rsubband[i] = extract_l( L_shr( Rsubband_buf[i], 18 ) ); + Rsubband[i] = extract_l( L_shr( Rsubband_buf[i], 18 ) ); /* Q3 */ move16(); } diff --git a/lib_com/bitalloc_fx.c b/lib_com/bitalloc_fx.c index c20235e39..e7d7602d6 100644 --- a/lib_com/bitalloc_fx.c +++ b/lib_com/bitalloc_fx.c @@ -30,22 +30,22 @@ void bitalloc_fx( Word16 SFM_thr = SFM_G1G2; move16(); - N = sub( N, 1 ); + N = sub( N, 1 ); /* Q0 */ if ( EQ_16( hqswb_clas, HQ_HARMONIC ) ) { - SFM_thr = 22; + SFM_thr = 22; /* Q0 */ move16(); } fac = 3; move16(); - K = sub( K, 2 ); + K = sub( K, 2 ); /* Q0 */ im = 1; move16(); - diff = sum; + diff = sum; /* Q0 */ move16(); - n = shr( sum, 3 ); + n = shr( sum, 3 ); /* Q0 */ FOR( i = 0; i < n; i++ ) { k = 0; @@ -55,14 +55,14 @@ void bitalloc_fx( FOR( m = 1; m < im; m++ ) { #ifdef BASOP_NOGLOB - v = sub_o( temp, y[m], &Overflow ); -#else /* BASOP_NOGLOB */ + v = sub_o( temp, y[m], &Overflow ); /* Q0 */ +#else /* BASOP_NOGLOB */ v = sub( temp, y[m] ); #endif temp = s_max( temp, y[m] ); if ( v < 0 ) { - k = m; + k = m; /* Q0 */ move16(); } } @@ -73,7 +73,7 @@ void bitalloc_fx( move16(); if ( LT_16( im, N ) ) { - im = add( im, 1 ); + im = add( im, 1 ); /* Q0 */ } } @@ -83,9 +83,9 @@ void bitalloc_fx( test(); IF( GE_16( sum, sfmsize[j] ) && LT_16( r[j], K ) ) { - y[k] = sub( y[k], fac ); + y[k] = sub( y[k], fac ); /* Q0 */ move16(); - r[j] = add( r[j], 1 ); + r[j] = add( r[j], 1 ); /* Q0 */ move16(); if ( GE_16( r[j], K ) ) @@ -93,7 +93,7 @@ void bitalloc_fx( y[k] = -32768; move16(); } - sum = sub( sum, sfmsize[j] ); + sum = sub( sum, sfmsize[j] ); /* Q0 */ } ELSE { @@ -103,7 +103,7 @@ void bitalloc_fx( test(); if ( EQ_16( k, im ) && LT_16( im, N ) ) { - im = add( im, 1 ); + im = add( im, 1 ); /* Q0 */ } } @@ -113,9 +113,9 @@ void bitalloc_fx( BREAK; } - diff = sum; + diff = sum; /* Q0 */ move16(); - v = sub( N, 1 ); + v = sub( N, 1 ); /* Q0 */ IF( GT_16( k, v ) ) { @@ -125,7 +125,7 @@ void bitalloc_fx( { if ( LT_16( ii, N ) ) { - im = add( ii, 1 ); + im = add( ii, 1 ); /* Q0 */ } BREAK; } @@ -138,7 +138,7 @@ void bitalloc_fx( { FOR( i = 0; i <= N; i++ ) { - j = idx[i]; + j = idx[i]; /* Q0 */ move16(); test(); test(); @@ -146,7 +146,7 @@ void bitalloc_fx( { r[j] = 1; move16(); - sum = sub( sum, sfmsize[j] ); + sum = sub( sum, sfmsize[j] ); /* Q0 */ IF( LT_16( sum, sfmsize[SFM_G1] ) ) { BREAK; @@ -167,7 +167,7 @@ void bitalloc_fx( { r[j] = 2; move16(); - sum = sub( sum, sfmsize[j] ); + sum = sub( sum, sfmsize[j] ); /* Q0 */ IF( LT_16( sum, sfmsize[SFM_G1] ) ) { BREAK; @@ -180,14 +180,14 @@ void bitalloc_fx( { FOR( i = 0; i <= N; i++ ) { - j = idx[i]; + j = idx[i]; /* Q0 */ move16(); test(); IF( LT_16( j, SFM_G1 ) && r[j] == 0 ) { r[j] = 1; move16(); - sum = sub( sum, sfmsize[j] ); + sum = sub( sum, sfmsize[j] ); /* Q0 */ IF( LT_16( sum, sfmsize[SFM_G1 - 1] ) ) { BREAK; @@ -200,14 +200,14 @@ void bitalloc_fx( { FOR( i = 0; i <= N; i++ ) { - j = idx[i]; + j = idx[i]; /* Q0 */ move16(); test(); IF( LT_16( j, SFM_G1 ) && EQ_16( r[j], 1 ) ) { - r[j] = 2; + r[j] = 2; /* Q0 */ move16(); - sum = sub( sum, sfmsize[j] ); + sum = sub( sum, sfmsize[j] ); /* Q0 */ IF( LT_16( sum, sfmsize[SFM_G1 - 1] ) ) { BREAK; @@ -239,6 +239,7 @@ Word16 BitAllocF_fx( { Word16 fac; Word16 i, n, Nmin, Bits, bs, low_rate = 0; + move16(); Word16 m_fx; Word32 t_fx, B_fx; @@ -248,6 +249,7 @@ Word16 BitAllocF_fx( Word16 B_w16_fx; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif set32_fx( Rsubband_w32_fx, 0, NB_SFM ); @@ -268,11 +270,11 @@ Word16 BitAllocF_fx( low_rate = 1; move16(); - Nmin = N; + Nmin = N; /* Q0 */ move16(); if ( GT_16( Nmin, SFM_N ) ) { - Nmin = SFM_N; + Nmin = SFM_N; /* Q0 */ move16(); } @@ -287,14 +289,14 @@ Word16 BitAllocF_fx( move16(); FOR( i = 0; i < num_env_bands; i++ ) { - L_tmp1 = L_mac0( L_tmp1, Nb[i], y[i] ); + L_tmp1 = L_mac0( L_tmp1, Nb[i], y[i] ); /* Q0 */ } - L_tmp1 = L_msu0( L_tmp1, fac, B ); + L_tmp1 = L_msu0( L_tmp1, fac, B ); /* Q0 */ t_fx = L_deposit_l( 0 ); n = 0; move16(); - tmp = add( band_end_HQ[sub( num_env_bands, 1 )], shl( band_end_HQ[sub( num_env_bands, 1 )], 1 ) ); + tmp = add( band_end_HQ[num_env_bands - 1], shl( band_end_HQ[num_env_bands - 1], 1 ) ); /* Q0 */ exp1 = norm_s( tmp ); tmp = div_s( 16384, shl( tmp, exp1 ) ); /*15 + 14 - exp1*/ exp2 = norm_s( tmp ); @@ -303,7 +305,7 @@ Word16 BitAllocF_fx( FOR( i = 0; i < N; i++ ) { - L_tmp2 = L_sub( L_mult0( y[i], band_end_HQ[num_env_bands - 1] ), L_tmp1 ); + L_tmp2 = L_sub( L_mult0( y[i], band_end_HQ[num_env_bands - 1] ), L_tmp1 ); /* Q0 */ Rsubband_w32_fx[i] = L_mult0( extract_l( L_tmp2 ), Nb[i] ); move32(); /*Q0*/ IF( Rsubband_w32_fx[i] > 0 ) @@ -331,15 +333,15 @@ Word16 BitAllocF_fx( move16(); FOR( i = 0; i < N; i++ ) { - L_tmp1 = L_mac0( L_tmp1, Nb[i], y[i] ); + L_tmp1 = L_mac0( L_tmp1, Nb[i], y[i] ); /* Q0 */ } - L_tmp1 = L_msu0( L_tmp1, fac, B ); + L_tmp1 = L_msu0( L_tmp1, fac, B ); /* Q0 */ t_fx = L_deposit_l( 0 ); n = 0; move16(); - tmp = add( band_end_HQ[sub( N, 1 )], shl( band_end_HQ[sub( N, 1 )], 1 ) ); + tmp = add( band_end_HQ[N - 1], shl( band_end_HQ[N - 1], 1 ) ); /* Q0 */ exp1 = norm_s( tmp ); tmp = div_s( 16384, shl( tmp, exp1 ) ); /*15 + 14 - exp1*/ exp2 = norm_s( tmp ); @@ -347,7 +349,7 @@ Word16 BitAllocF_fx( exp1 = add( 29, sub( exp2, exp1 ) ); FOR( i = 0; i < N; i++ ) { - L_tmp2 = L_sub( L_mult0( y[i], band_end_HQ[sub( N, 1 )] ), L_tmp1 ); + L_tmp2 = L_sub( L_mult0( y[i], band_end_HQ[N - 1] ), L_tmp1 ); /* Q0 */ Rsubband_w32_fx[i] = L_mult0( extract_l( L_tmp2 ), Nb[i] ); move32(); /*Q0*/ IF( Rsubband_w32_fx[i] > 0 ) @@ -357,7 +359,7 @@ Word16 BitAllocF_fx( Rsubband_w32_fx[i] = L_shl( L_tmp3, sub( 30, exp1 ) ); /*Q15*/ move32(); - t_fx = L_add( t_fx, Rsubband_w32_fx[i] ); /*Q0*/ + t_fx = L_add( t_fx, Rsubband_w32_fx[i] ); /*Q15*/ } ELSE { @@ -387,14 +389,14 @@ Word16 BitAllocF_fx( { IF( Rsubband_w32_fx[i] > 0 ) { - Rsubband_w32_fx[i] = L_msu( Rsubband_w32_fx[i], m_fx, Nb[i] ); + Rsubband_w32_fx[i] = L_msu( Rsubband_w32_fx[i], m_fx, Nb[i] ); /* Q15 */ move32(); IF( Rsubband_w32_fx[i] > 0 ) { n = add( n, Nb[i] ); - t_fx = L_add( t_fx, Rsubband_w32_fx[i] ); + t_fx = L_add( t_fx, Rsubband_w32_fx[i] ); /* Q15 */ } ELSE { @@ -404,7 +406,7 @@ Word16 BitAllocF_fx( } } } - Bits = B; + Bits = B; /* Q0 */ move16(); /* Impose bit-constraints to subbands with less than minimum bits*/ @@ -423,14 +425,14 @@ Word16 BitAllocF_fx( } ELSE IF( LE_32( Rsubband_w32_fx[i], L_shl( Nb[i], 15 ) ) ) { - B = sub( B, Nb[i] ); - Rsubband_w32_fx[i] = L_shl( Nb[i], 15 ); + B = sub( B, Nb[i] ); /* Q0 */ + Rsubband_w32_fx[i] = L_shl( Nb[i], 15 ); /* Q15 */ move32(); } ELSE { - n = add( n, Nb[i] ); - t_fx = L_add( t_fx, Rsubband_w32_fx[i] ); + n = add( n, Nb[i] ); /* Q0 */ + t_fx = L_add( t_fx, Rsubband_w32_fx[i] ); /* Q15 */ } } } @@ -463,19 +465,19 @@ Word16 BitAllocF_fx( { IF( GT_32( Rsubband_w32_fx[i], L_shl( Nb[i], 15 ) ) ) { - Rsubband_w32_fx[i] = L_msu( Rsubband_w32_fx[i], m_fx, Nb[i] ); + Rsubband_w32_fx[i] = L_msu( Rsubband_w32_fx[i], m_fx, Nb[i] ); /* Q15 */ move32(); IF( GT_32( Rsubband_w32_fx[i], L_shl( Nb[i], 15 ) ) ) { - n = add( n, Nb[i] ); + n = add( n, Nb[i] ); /* Q0 */ - t_fx = L_add( t_fx, Rsubband_w32_fx[i] ); + t_fx = L_add( t_fx, Rsubband_w32_fx[i] ); /* Q15 */ } ELSE { - B = sub( B, Nb[i] ); + B = sub( B, Nb[i] ); /* Q0 */ - Rsubband_w32_fx[i] = L_shl( Nb[i], 15 ); + Rsubband_w32_fx[i] = L_shl( Nb[i], 15 ); /* Q15 */ move32(); } } @@ -488,7 +490,7 @@ Word16 BitAllocF_fx( { IF( Rsubband_w32_fx[i] > 0 ) { - B = add( B, Nb[i] ); + B = add( B, Nb[i] ); /* Q0 */ Rsubband_w32_fx[i] = L_deposit_l( 0 ); move32(); IF( B >= 0 ) @@ -506,9 +508,9 @@ Word16 BitAllocF_fx( move16(); FOR( i = 0; i < N; i++ ) { - Rsubband_fx[i] = extract_l( L_shr( Rsubband_w32_fx[i], 12 ) ); + Rsubband_fx[i] = extract_l( L_shr( Rsubband_w32_fx[i], 12 ) ); /* Q3 */ move16(); - tmp = add( tmp, Rsubband_fx[i] ); + tmp = add( tmp, Rsubband_fx[i] ); /* Q3 */ } B = Bits; @@ -520,7 +522,7 @@ Word16 BitAllocF_fx( { IF( GE_16( Rsubband_fx[i], add( shl( Nb[i], 3 ), tmp ) ) ) { - Rsubband_fx[i] = sub( Rsubband_fx[i], tmp ); + Rsubband_fx[i] = sub( Rsubband_fx[i], tmp ); /* Q3 */ move16(); BREAK; } @@ -533,7 +535,7 @@ Word16 BitAllocF_fx( { IF( Rsubband_fx[i] > 0 ) { - Rsubband_fx[i] = sub( Rsubband_fx[i], tmp ); + Rsubband_fx[i] = sub( Rsubband_fx[i], tmp ); /* Q3 */ move16(); BREAK; } @@ -545,8 +547,8 @@ Word16 BitAllocF_fx( move16(); FOR( i = 0; i < N; i++ ) { - tmp = add( tmp, Rsubband_fx[i] ); - R[i] = shr( Rsubband_fx[i], 3 ); + tmp = add( tmp, Rsubband_fx[i] ); /* Q3 */ + R[i] = shr( Rsubband_fx[i], 3 ); /* Q0 */ move16(); } return shr( tmp, 3 ); @@ -571,6 +573,9 @@ static void Bit_group_fx( Word16 factor_fx; Word32 R_temp_fx[16], R_sum_fx = 0, R_sum_org_fx = 0, Bits_avg_fx = 0; Word32 L_tmp; + move32(); + move32(); + move32(); /* initialization for bit allocation in one group*/ tmp = 6554; @@ -595,7 +600,7 @@ static void Bit_group_fx( FOR( i = 0; i < band_num; i++ ) { - y_index[i] = y[add( i, start_band )]; + y_index[i] = y[i + start_band]; /* Q0 */ move16(); index[i] = i; move16(); @@ -687,7 +692,7 @@ static void Bit_group_fx( R_temp_fx[i] = L_deposit_h( 0 ); move32(); norm_sum = sub( norm_sum, y_index[i] ); - i = sub( i, 1 ); + i--; } ELSE { @@ -767,7 +772,7 @@ static void Bit_group_fx( } ELSE { - R_sum_fx = L_add( R_sum_fx, R_temp_fx[k] ); + R_sum_fx = L_add( R_sum_fx, R_temp_fx[k] ); /* Q21 */ } } IF( EQ_32( R_sum_fx, R_sum_org_fx ) ) @@ -785,7 +790,7 @@ static void Bit_group_fx( { j = index[k]; move16(); - Rsubband_fx[add( j, start_band )] = R_temp_fx[k]; + Rsubband_fx[j + start_band] = R_temp_fx[k]; /* Q21 */ move32(); } @@ -898,7 +903,7 @@ Word16 BitAllocWB_fx( /* o : t move32(); /*Q16 */ test(); - IF( LT_32( R_diff_32_fx[0], 393216 ) && LT_32( R_diff_32_fx[1], 245760 ) ) + IF( LT_32( R_diff_32_fx[0], 393216 /* 32 in Q16 */ ) && LT_32( R_diff_32_fx[1], 245760 /* 3.75 in Q16 */ ) ) { IF( Rsum_fx == 0 ) { @@ -939,29 +944,29 @@ Word16 BitAllocWB_fx( /* o : t B3 = add( B3, 1 ); } } - IF( GT_32( Ravg_sub_32_fx[2], 786432 ) ) + IF( GT_32( Ravg_sub_32_fx[2], 786432 /* 12 in Q16 */ ) ) { B_saved = 0; move16(); IF( GT_16( B1, 288 ) ) { - B_saved = sub( B1, 288 ); + B_saved = sub( B1, 288 ); /* Q0 */ B1 = 288; move16(); } IF( GT_16( B2, 256 ) ) { - tmp = sub( B2, 256 ); - B_saved = add( B_saved, tmp ); + tmp = sub( B2, 256 ); /* Q0 */ + B_saved = add( B_saved, tmp ); /* Q0 */ B2 = 256; move16(); } IF( GT_16( B3, 96 ) ) { - tmp = sub( B3, 96 ); - B_saved = add( B_saved, tmp ); + tmp = sub( B3, 96 ); /* Q0 */ + B_saved = add( B_saved, tmp ); /* Q0 */ B3 = 96; move16(); } @@ -970,24 +975,24 @@ Word16 BitAllocWB_fx( /* o : t { IF( EQ_16( B1, 288 ) ) { - tmp = shr( B_saved, 1 ); - B2 = add( B2, tmp ); - tmp = sub( B, B1 ); - B3 = sub( tmp, B2 ); + tmp = shr( B_saved, 1 ); /* Q0 */ + B2 = add( B2, tmp ); /* Q0 */ + tmp = sub( B, B1 ); /* Q0 */ + B3 = sub( tmp, B2 ); /* Q0 */ } ELSE { - tmp = shr( B_saved, 1 ); - B1 = add( B1, tmp ); + tmp = shr( B_saved, 1 ); /* Q0 */ + B1 = add( B1, tmp ); /* Q0 */ IF( EQ_16( B2, 256 ) ) { - tmp = sub( B, B1 ); - B3 = sub( tmp, B2 ); + tmp = sub( B, B1 ); /* Q0 */ + B3 = sub( tmp, B2 ); /* Q0 */ } ELSE { - tmp = sub( B, B1 ); - B2 = sub( tmp, B3 ); + tmp = sub( B, B1 ); /* Q0 */ + B2 = sub( tmp, B3 ); /* Q0 */ } } } @@ -1020,7 +1025,7 @@ Word16 BitAllocWB_fx( /* o : t test(); if ( GT_32( L_tmp1, L_mult( B1, Rsum_fx ) ) && GE_32( L_tmp1, L_mult( add( B1, 1 ), Rsum_fx ) ) ) { - B1 = add( B1, 1 ); + B1 = add( B1, 1 ); /* Q0 */ } L_tmp1 = Mult_32_16( 1975684956, shl( B, 5 ) ); /*Q(31+5-15=21) */ L_tmp1 = Mult_32_16( L_tmp1, shl( Rsum_sub_fx[1], 7 ) ); /*Q(21+7-15=13) */ @@ -1031,15 +1036,15 @@ Word16 BitAllocWB_fx( /* o : t { B2 = add( B2, 1 ); } - tmp = sub( B, B1 ); - B3 = sub( tmp, B2 ); + tmp = sub( B, B1 ); /* Q0 */ + B3 = sub( tmp, B2 ); /* Q0 */ } } } IF( LT_16( Rsum_sub_fx[2], 3 ) ) { - B2 = add( B2, B3 ); + B2 = add( B2, B3 ); /* Q0 */ B3 = 0; move16(); } @@ -1050,7 +1055,7 @@ Word16 BitAllocWB_fx( /* o : t Bit_group_fx( y, SFM_G1G2, BANDS, B3, 7, Rsubband_buf, factor_fx ); FOR( i = 0; i < BANDS; i++ ) { - Rsubband_fx[i] = extract_l( L_shr( Rsubband_buf[i], 18 ) ); + Rsubband_fx[i] = extract_l( L_shr( Rsubband_buf[i], 18 ) ); /* Q3 */ move16(); } diff --git a/lib_com/core_com_config.c b/lib_com/core_com_config.c index 77f904055..6c9c8fa32 100644 --- a/lib_com/core_com_config.c +++ b/lib_com/core_com_config.c @@ -53,8 +53,8 @@ /*! r: flag indicating a valid bitrate */ Word16 is_EVS_bitrate( - const Word32 ivas_total_brate, /* i : IVAS total bitrate */ - Word16 *Opt_AMR_WB /* i : AMR-WB IO flag */ + const Word32 ivas_total_brate, /* i : IVAS total bitrate Q0*/ + Word16 *Opt_AMR_WB /* i : AMR-WB IO flag Q0*/ ) { Word16 j; @@ -109,7 +109,7 @@ Word16 is_EVS_bitrate( /*! r: codec mode */ Word16 get_codec_mode( - const Word32 total_brate /* i : total bitrate */ + const Word32 total_brate /* i : total bitrate Q0*/ ) { Word16 codec_mode; @@ -168,7 +168,7 @@ Word16 get_codec_mode( BREAK; } - return codec_mode; + return codec_mode; /*Q0*/ } @@ -178,11 +178,12 @@ Word16 get_codec_mode( * *-------------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED int16_t getTcxonly_ivas( - const int16_t element_mode, /* i : IVAS element mode */ - const int32_t total_brate, /* i : total bitrate */ - const int16_t MCT_flag, /* i : hMCT handle allocated (1) or not (0)*/ - const int16_t is_ism_format /* i : flag indicating ISM format */ + const int16_t element_mode, /* i : IVAS element mode */ + const int32_t total_brate, /* i : total bitrate */ + const int16_t MCT_flag, /* i : hMCT handle allocated (1) or not (0) */ + const int16_t is_ism_format /* i : flag indicating ISM format */ ) { int16_t tcxonly = 0; @@ -230,13 +231,12 @@ int16_t getTcxonly_ivas( return tcxonly; } - -#ifdef IVAS_FLOAT_FIXED +#else Word16 getTcxonly_ivas_fx( - const Word16 element_mode, /* i : IVAS element mode */ - const Word32 total_brate, /* i : total bitrate */ - const Word16 MCT_flag, /* i : hMCT handle allocated (1) or not (0)*/ - const Word16 is_ism_format /* i : flag indicating ISM format */ + const Word16 element_mode, /* i : IVAS element mode Q0*/ + const Word32 total_brate, /* i : total bitrate Q0*/ + const Word16 MCT_flag, /* i : hMCT handle allocated (1) or not (0) Q0*/ + const Word16 is_ism_format /* i : flag indicating ISM format Q0*/ ) { Word16 tcxonly = 0; @@ -298,7 +298,7 @@ Word16 getTcxonly_ivas_fx( BREAK; } - return tcxonly; + return tcxonly; /*Q0*/ } #endif @@ -364,14 +364,14 @@ Word16 getTcxonly( #ifdef IVAS_CODE_SWITCHING } #endif - return tcxonly; + return tcxonly; /*Q0*/ } Word16 getTcxonly_fx( - const Word16 element_mode, /* i : IVAS element mode */ - const Word32 total_brate, /* i : total bitrate */ - const Word16 MCT_flag, /* i : hMCT handle allocated (1) or not (0)*/ - const Word16 is_ism_format /* i : flag indicating ISM format */ + const Word16 element_mode, /* i : IVAS element mode Q0*/ + const Word32 total_brate, /* i : total bitrate Q0*/ + const Word16 MCT_flag, /* i : hMCT handle allocated (1) or not (0) Q0*/ + const Word16 is_ism_format /* i : flag indicating ISM format Q0*/ ) { Word16 tcxonly; @@ -435,7 +435,7 @@ Word16 getTcxonly_fx( BREAK; } - return tcxonly; + return tcxonly; /*Q0*/ } /*-------------------------------------------------------------------* @@ -445,9 +445,9 @@ Word16 getTcxonly_fx( *-------------------------------------------------------------------*/ Word16 getCtxHm( - const Word16 element_mode, /* i : IVAS element mode */ - const Word32 total_brate, /* i : total bitrate */ - const Word16 rf_flag /* i : flag to signal the RF mode */ + const Word16 element_mode, /* i : IVAS element mode Q0*/ + const Word32 total_brate, /* i : total bitrate Q0*/ + const Word16 rf_flag /* i : flag to signal the RF mode Q0*/ ) { Word16 ctx_hm; @@ -469,7 +469,7 @@ Word16 getCtxHm( move16(); } - return ctx_hm; + return ctx_hm; /*Q0*/ } /*-------------------------------------------------------------------* @@ -479,7 +479,7 @@ Word16 getCtxHm( *-------------------------------------------------------------------*/ Word16 getResq( - const Word32 total_brate /* i : total bitrate */ + const Word32 total_brate /* i : total bitrate Q0*/ ) { Word16 resq; @@ -492,7 +492,7 @@ Word16 getResq( move16(); } - return resq; + return resq; /*Q0*/ } /*-------------------------------------------------------------------* @@ -502,9 +502,9 @@ Word16 getResq( *-------------------------------------------------------------------*/ Word16 getTnsAllowed( - const Word32 total_brate, /* i : total bitrate */ - const Word16 igf, /* i : flag indicating IGF activity*/ - const Word16 element_mode /* i : IVAS element mode */ + const Word32 total_brate, /* i : total bitrate Q0*/ + const Word16 igf, /* i : flag indicating IGF activity Q0*/ + const Word16 element_mode /* i : IVAS element mode Q0*/ ) { Word16 tnsAllowed; @@ -530,7 +530,7 @@ Word16 getTnsAllowed( } } - return tnsAllowed; + return tnsAllowed; /*Q0*/ } /*-------------------------------------------------------------------* @@ -540,9 +540,9 @@ Word16 getTnsAllowed( *-------------------------------------------------------------------*/ Word16 getRestrictedMode( - const Word16 element_mode, /* i : IVAS element mode */ - const Word32 total_brate, /* i : total bitrate */ - const Word16 Opt_AMR_WB /* i : flag indicating AMR-WB IO mode */ + const Word16 element_mode, /* i : IVAS element mode Q0*/ + const Word32 total_brate, /* i : total bitrate Q0*/ + const Word16 Opt_AMR_WB /* i : flag indicating AMR-WB IO mode Q0*/ ) { Word16 restrictedMode; @@ -569,7 +569,7 @@ Word16 getRestrictedMode( move16(); } - return restrictedMode; + return restrictedMode; /*Q0*/ } /*-------------------------------------------------------------------* @@ -577,7 +577,7 @@ Word16 getRestrictedMode( * * *-------------------------------------------------------------------*/ - +#ifndef IVAS_FLOAT_FIXED int16_t getMdctWindowLength( const int16_t fscale ) { @@ -587,14 +587,14 @@ int16_t getMdctWindowLength( return mdctWindowLength; } -#ifdef IVAS_FLOAT_FIXED +#else Word16 getMdctWindowLength_fx( - const Word16 fscale ) + const Word16 fscale /*Q0*/ ) { Word16 mdctWindowLength; mdctWindowLength = extract_l( L_shr( L_mult0( L_LOOK_12k8, fscale ), LD_FSCALE_DENOM ) ); - return mdctWindowLength; + return mdctWindowLength; /*Q0*/ } #endif // IVAS_FLOAT_FIXED @@ -605,10 +605,10 @@ Word16 getMdctWindowLength_fx( *-------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED Word16 sr2fscale_fx( - const Word32 sr_core /* i : internal sampling rate */ + const Word32 sr_core /* i : internal sampling rate Q0*/ ) { - return extract_l( Mpy_32_16_1( sr_core, FSCALE_DENOM_BY_12800_Q15 ) ); + return extract_l( Mpy_32_16_1( sr_core, FSCALE_DENOM_BY_12800_Q15 ) ); /*Q0*/ } #endif @@ -678,12 +678,12 @@ int32_t getCoreSamplerateMode2_flt( } Word32 getCoreSamplerateMode2( - const Word16 element_mode, /* i : IVAS element mode */ - const Word32 total_brate, /* i : total bitrate */ - const Word16 bwidth, /* i : audio bandwidth */ - const Word16 flag_ACELP16k, /* i : ACELP@16kHz flag */ - const Word16 rf_mode, /* i : flag to signal the RF mode */ - const IVAS_FORMAT is_ism_format /* i : flag indicating ISM format */ + const Word16 element_mode, /* i : IVAS element mode Q0*/ + const Word32 total_brate, /* i : total bitrate Q0*/ + const Word16 bwidth, /* i : audio bandwidth Q0*/ + const Word16 flag_ACELP16k, /* i : ACELP@16kHz flag Q0*/ + const Word16 rf_mode, /* i : flag to signal the RF mode Q0*/ + const IVAS_FORMAT is_ism_format /* i : flag indicating ISM format Q0*/ ) { @@ -767,11 +767,11 @@ Word32 getCoreSamplerateMode2( assert( 0 ); } - return sr_core; + return sr_core; /*Q0*/ } Word16 getTcxBandwidth( - const Word16 bwidth /* i : audio bandwidth */ + const Word16 bwidth /* i : audio bandwidth Q0*/ ) { @@ -785,7 +785,7 @@ Word16 getTcxBandwidth( move16(); } - return tcxBandwidth; + return tcxBandwidth; /*Q15*/ } /*-------------------------------------------------------------------* @@ -908,10 +908,10 @@ int16_t getIgfPresent( } #else Word16 getIgfPresent_fx( - const Word16 element_mode, /* i : IVAS element mode */ - const Word32 total_brate, /* i : total bitrate */ - const Word16 bwidth, /* i : audio bandwidth */ - const Word16 rf_mode /* i : flag to signal the RF mode */ + const Word16 element_mode, /* i : IVAS element mode Q0*/ + const Word32 total_brate, /* i : total bitrate Q0*/ + const Word16 bwidth, /* i : audio bandwidth Q0*/ + const Word16 rf_mode /* i : flag to signal the RF mode Q0*/ ) { Word16 igfPresent; @@ -1008,7 +1008,7 @@ Word16 getIgfPresent_fx( move16(); } - return igfPresent; + return igfPresent; /*Q0*/ } #endif @@ -1053,10 +1053,10 @@ int16_t getCnaPresent( } Word16 getCnaPresent_fx( - const Word16 element_mode, /* i : element mode */ - const Word32 element_brate, /* i : element bitrate */ - const Word32 total_brate, /* i : total bitrate */ - const Word16 bwidth /* i : audio bandwidth */ + const Word16 element_mode, /* i : element mode Q0*/ + const Word32 element_brate, /* i : element bitrate Q0*/ + const Word32 total_brate, /* i : total bitrate Q0*/ + const Word16 bwidth /* i : audio bandwidth Q0*/ ) { Word16 flag_cna; @@ -1079,7 +1079,7 @@ Word16 getCnaPresent_fx( } } - return flag_cna; + return flag_cna; /*Q0*/ } /*-------------------------------------------------------------------* * getTcxLtp() @@ -1088,7 +1088,7 @@ Word16 getCnaPresent_fx( *-------------------------------------------------------------------*/ Word16 getTcxLtp( - const Word32 sr_core /* i : internal sampling rate */ + const Word32 sr_core /* i : internal sampling rate Q0*/ ) { Word16 tcxltp; @@ -1102,7 +1102,7 @@ Word16 getTcxLtp( move16(); } - return tcxltp; + return tcxltp; /*Q0*/ } /*-------------------------------------------------------------------* @@ -1112,12 +1112,12 @@ Word16 getTcxLtp( *-------------------------------------------------------------------*/ Word16 initPitchLagParameters( - const Word32 sr_core, - Word16 *pit_min, - Word16 *pit_fr1, - Word16 *pit_fr1b, - Word16 *pit_fr2, - Word16 *pit_max ) + const Word32 sr_core, /*Q0*/ + Word16 *pit_min, /*Q0*/ + Word16 *pit_fr1, /*Q0*/ + Word16 *pit_fr1b, /*Q0*/ + Word16 *pit_fr2, /*Q0*/ + Word16 *pit_max /*Q0*/ ) { Word16 pit_res_max; @@ -1182,7 +1182,7 @@ Word16 initPitchLagParameters( move16(); } - return pit_res_max; + return pit_res_max; /*Q0*/ } /*-------------------------------------------------------------------* @@ -1192,7 +1192,7 @@ Word16 initPitchLagParameters( *-------------------------------------------------------------------*/ Word16 getNumTcxCodedLines( - const Word16 bwidth /* i : audio bandwidth */ + const Word16 bwidth /* i : audio bandwidth Q0*/ ) { Word16 tcx_coded_lines; @@ -1224,7 +1224,7 @@ Word16 getNumTcxCodedLines( BREAK; } - return tcx_coded_lines; + return tcx_coded_lines; /*Q0*/ } /*-------------------------------------------------------------------* @@ -1234,9 +1234,9 @@ Word16 getNumTcxCodedLines( *-------------------------------------------------------------------*/ Word16 getTcxLpcShapedAri( - const Word32 total_brate, /* i : total bitrate */ - const Word16 rf_mode, /* i : flag to signal the RF mode */ - const Word16 element_mode /* i : IVAS element mode */ + const Word32 total_brate, /* i : total bitrate Q0*/ + const Word16 rf_mode, /* i : flag to signal the RF mode Q0*/ + const Word16 element_mode /* i : IVAS element mode Q0*/ ) { Word16 tcx_lpc_shaped_ari; @@ -1253,7 +1253,7 @@ Word16 getTcxLpcShapedAri( move16(); } - return tcx_lpc_shaped_ari; + return tcx_lpc_shaped_ari; /*Q0*/ } @@ -1399,7 +1399,7 @@ void init_tcx_cfg( hTcxCfg->tcx5SizeFB = NS2SA( input_Fs, FRAME_SIZE_NS / 4 ); /* Always 5 ms */ hTcxCfg->tcx_mdct_window_length_old = hTcxCfg->tcx_mdct_window_length; - mdctWindowLength = getMdctWindowLength( fscale ); + mdctWindowLength = getMdctWindowLength_fx( fscale ); mdctWindowLengthFB = (int16_t) ( mdctWindowLength * input_Fs / sr_core ); init_tcx_window_cfg( hTcxCfg, sr_core, input_Fs, L_frame, L_frameTCX, encoderLookahead_enc, encoderLookahead_FB, mdctWindowLength, mdctWindowLengthFB, element_mode ); @@ -1503,21 +1503,21 @@ void init_tcx_cfg( #ifdef IVAS_FLOAT_FIXED void init_tcx_cfg_ivas_fx( TCX_CONFIG_HANDLE hTcxCfg, - const Word32 total_brate, - const Word32 sr_core, - const Word32 input_Fs, - const Word16 L_frame, - const Word16 bwidth, - const Word16 L_frameTCX, - const Word16 fscale, - const Word16 preemph_fac, - const Word16 tcxonly, - const Word16 rf_mode, - const Word16 igf, - const Word16 infoIGFStopFreq, - const Word16 element_mode, - const Word16 ini_frame, - const Word16 MCT_flag ) + const Word32 total_brate, /*Q0*/ + const Word32 sr_core, /*Q0*/ + const Word32 input_Fs, /*Q0*/ + const Word16 L_frame, /*Q0*/ + const Word16 bwidth, /*Q0*/ + const Word16 L_frameTCX, /*Q0*/ + const Word16 fscale, /*Q0*/ + const Word16 preemph_fac, /*Q15*/ + const Word16 tcxonly, /*Q0*/ + const Word16 rf_mode, /*Q0*/ + const Word16 igf, /*Q0*/ + const Word16 infoIGFStopFreq, /*Q0*/ + const Word16 element_mode, /*Q0*/ + const Word16 ini_frame, /*Q0*/ + const Word16 MCT_flag /*Q0*/ ) { Word16 i; Word16 mdctWindowLength; @@ -1527,14 +1527,14 @@ void init_tcx_cfg_ivas_fx( hTcxCfg->preemph_fac = preemph_fac; move16(); - hTcxCfg->tcx5Size = shr( L_frame, 2 ); /* Always 5 ms */ - hTcxCfg->tcx5SizeFB = shr( L_frameTCX, 2 ); /* Always 5 ms */ + hTcxCfg->tcx5Size = shr( L_frame, 2 ); /* Always 5 ms Q0*/ + hTcxCfg->tcx5SizeFB = shr( L_frameTCX, 2 ); /* Always 5 ms Q0*/ move16(); move16(); - hTcxCfg->tcx_mdct_window_length_old = hTcxCfg->tcx_mdct_window_length; + hTcxCfg->tcx_mdct_window_length_old = hTcxCfg->tcx_mdct_window_length; /*Q0*/ move16(); - mdctWindowLength = getMdctWindowLength_fx( fscale ); + mdctWindowLength = getMdctWindowLength_fx( fscale ); /*Q0*/ mdctWindowLengthFB = (Word16) ( mdctWindowLength * input_Fs / sr_core ); init_tcx_window_cfg_fx( hTcxCfg, sr_core, input_Fs, L_frame, L_frameTCX, mdctWindowLength, mdctWindowLengthFB, element_mode ); @@ -1556,16 +1556,16 @@ void init_tcx_cfg_ivas_fx( hTcxCfg->tcxRateLoopOpt = 3; move16(); } - hTcxCfg->bandwidth = getTcxBandwidth( bwidth ); + hTcxCfg->bandwidth = getTcxBandwidth( bwidth ); /*Q15*/ move16(); /* set number of coded lines */ - hTcxCfg->tcx_coded_lines = getNumTcxCodedLines( bwidth ); + hTcxCfg->tcx_coded_lines = getNumTcxCodedLines( bwidth ); /*Q0*/ move16(); /* TNS in TCX */ hTcxCfg->pCurrentTnsConfig = NULL; - hTcxCfg->fIsTNSAllowed = getTnsAllowed( total_brate, igf, element_mode ); + hTcxCfg->fIsTNSAllowed = getTnsAllowed( total_brate, igf, element_mode ); /*Q0*/ move16(); IF( hTcxCfg->fIsTNSAllowed ) @@ -1585,11 +1585,11 @@ void init_tcx_cfg_ivas_fx( } /* Context HM*/ - hTcxCfg->ctx_hm = getCtxHm( element_mode, total_brate, rf_mode ); + hTcxCfg->ctx_hm = getCtxHm( element_mode, total_brate, rf_mode ); /*Q0*/ move16(); /* Residual Coding*/ - hTcxCfg->resq = getResq( total_brate ); + hTcxCfg->resq = getResq( total_brate ); /*Q0*/ move16(); test(); if ( hTcxCfg->resq && !tcxonly ) @@ -1630,7 +1630,7 @@ void init_tcx_cfg_ivas_fx( { i = sub( i, 1 ); } - hTcxCfg->na_scale = scaleTcxTable[i].scale; + hTcxCfg->na_scale = scaleTcxTable[i].scale; /*Q15*/ move16(); BREAK; } @@ -1652,14 +1652,14 @@ void init_tcx_cfg_ivas_fx( #ifdef IVAS_FLOAT_FIXED void init_tcx_window_cfg_fx( - TCX_CONFIG_HANDLE hTcxCfg, /* i/o: TCX Config handle */ - const Word32 sr_core, /* i : SR core */ - const Word32 input_Fs, /* i : input/output SR */ - const Word16 L_frame, /* i : L_frame at sr_core */ - const Word16 L_frameTCX, /* i : L_frame at i/o SR */ - const Word16 mdctWindowLength, /* i : window length at sr_core */ - const Word16 mdctWindowLengthFB, /* i : window length at i/o SR */ - const Word16 element_mode /* i : mode of CPE/SCE */ + TCX_CONFIG_HANDLE hTcxCfg, /* i/o: TCX Config handle Q0*/ + const Word32 sr_core, /* i : SR core Q0*/ + const Word32 input_Fs, /* i : input/output SR Q0*/ + const Word16 L_frame, /* i : L_frame at sr_core Q0*/ + const Word16 L_frameTCX, /* i : L_frame at i/o SR Q0*/ + const Word16 mdctWindowLength, /* i : window length at sr_core Q0*/ + const Word16 mdctWindowLengthFB, /* i : window length at i/o SR Q0*/ + const Word16 element_mode /* i : mode of CPE/SCE Q0*/ ) { /* Symmetric window = sine LD window*/ @@ -1675,7 +1675,7 @@ void init_tcx_window_cfg_fx( IF( EQ_16( hTcxCfg->tcx_mdct_window_length, hTcxCfg->tcx_mdct_window_lengthFB ) ) { - Copy_pword( hTcxCfg->tcx_mdct_window, hTcxCfg->tcx_mdct_windowFB, shr( hTcxCfg->tcx_mdct_window_length, 1 ) ); + Copy_pword( hTcxCfg->tcx_mdct_window, hTcxCfg->tcx_mdct_windowFB, shr( hTcxCfg->tcx_mdct_window_length, 1 ) ); /*Q15*/ } ELSE { @@ -1687,14 +1687,14 @@ void init_tcx_window_cfg_fx( mdct_window_aldo( hTcxCfg->tcx_aldo_window_1_FB, hTcxCfg->tcx_aldo_window_1_FB_trunc, hTcxCfg->tcx_aldo_window_2_FB, NS2SA_FX2( input_Fs, FRAME_SIZE_NS ) ); /*1.25ms transition window for ACELP->TCX*/ - hTcxCfg->tcx_mdct_window_trans_length = NS2SA_FX2( sr_core, ACELP_TCX_TRANS_NS ); + hTcxCfg->tcx_mdct_window_trans_length = NS2SA_FX2( sr_core, ACELP_TCX_TRANS_NS ); /*Q0*/ move16(); mdct_window_sine_IVAS_updated( hTcxCfg->tcx_mdct_window_trans, sr_core, hTcxCfg->tcx_mdct_window_trans_length, TRANSITION_OVERLAP, element_mode ); - hTcxCfg->tcx_mdct_window_trans_lengthFB = NS2SA_FX2( input_Fs, ACELP_TCX_TRANS_NS ); + hTcxCfg->tcx_mdct_window_trans_lengthFB = NS2SA_FX2( input_Fs, ACELP_TCX_TRANS_NS ); /*Q0*/ move16(); IF( EQ_16( hTcxCfg->tcx_mdct_window_trans_length, hTcxCfg->tcx_mdct_window_trans_lengthFB ) ) { - Copy_pword( hTcxCfg->tcx_mdct_window_trans, hTcxCfg->tcx_mdct_window_transFB, shr( hTcxCfg->tcx_mdct_window_trans_length, 1 ) ); + Copy_pword( hTcxCfg->tcx_mdct_window_trans, hTcxCfg->tcx_mdct_window_transFB, shr( hTcxCfg->tcx_mdct_window_trans_length, 1 ) ); /*Q15*/ } ELSE { @@ -1702,8 +1702,8 @@ void init_tcx_window_cfg_fx( } /*Mid-OLA*/ /*compute minimum length for "half" window: lookahead - 5ms. It must be also multiple of 2*/ - hTcxCfg->tcx_mdct_window_half_length = extract_l( L_shr( L_mult0( L_LOOK_12k8 - NS2SA_FX2( 12800, 5000000L ), sr2fscale( sr_core ) ), LD_FSCALE_DENOM ) ); - hTcxCfg->tcx_mdct_window_half_lengthFB = extract_l( L_shr( L_mult0( L_LOOK_12k8 - NS2SA_FX2( 12800, 5000000L ), sr2fscale( input_Fs ) ), LD_FSCALE_DENOM ) ); + hTcxCfg->tcx_mdct_window_half_length = extract_l( L_shr( L_mult0( L_LOOK_12k8 - NS2SA_FX2( 12800, 5000000L ), sr2fscale( sr_core ) ), LD_FSCALE_DENOM ) ); /*Q0*/ + hTcxCfg->tcx_mdct_window_half_lengthFB = extract_l( L_shr( L_mult0( L_LOOK_12k8 - NS2SA_FX2( 12800, 5000000L ), sr2fscale( input_Fs ) ), LD_FSCALE_DENOM ) ); /*Q0*/ move16(); move16(); assert( GT_16( hTcxCfg->tcx_mdct_window_half_length, 16 ) && "Half window can not be large enough!" ); @@ -1711,7 +1711,7 @@ void init_tcx_window_cfg_fx( mdct_window_sine_IVAS_updated( hTcxCfg->tcx_mdct_window_half, sr_core, hTcxCfg->tcx_mdct_window_half_length, HALF_OVERLAP, element_mode ); IF( EQ_16( hTcxCfg->tcx_mdct_window_half_length, hTcxCfg->tcx_mdct_window_half_lengthFB ) ) { - Copy_pword( hTcxCfg->tcx_mdct_window_half, hTcxCfg->tcx_mdct_window_halfFB, shr( hTcxCfg->tcx_mdct_window_half_length, 1 ) ); + Copy_pword( hTcxCfg->tcx_mdct_window_half, hTcxCfg->tcx_mdct_window_halfFB, shr( hTcxCfg->tcx_mdct_window_half_length, 1 ) ); /*Q15*/ } ELSE { @@ -1726,7 +1726,7 @@ void init_tcx_window_cfg_fx( /* save complexity by copying the small windows if they have the same length */ IF( EQ_16( hTcxCfg->tcx_mdct_window_min_length, hTcxCfg->tcx_mdct_window_trans_length ) ) { - Copy_pword( hTcxCfg->tcx_mdct_window_trans, hTcxCfg->tcx_mdct_window_minimum, shr( hTcxCfg->tcx_mdct_window_min_length, 1 ) ); + Copy_pword( hTcxCfg->tcx_mdct_window_trans, hTcxCfg->tcx_mdct_window_minimum, shr( hTcxCfg->tcx_mdct_window_min_length, 1 ) ); /*Q15*/ } ELSE { @@ -1735,19 +1735,19 @@ void init_tcx_window_cfg_fx( IF( EQ_16( hTcxCfg->tcx_mdct_window_min_lengthFB, hTcxCfg->tcx_mdct_window_trans_lengthFB ) ) { - Copy_pword( hTcxCfg->tcx_mdct_window_transFB, hTcxCfg->tcx_mdct_window_minimumFB, shr( hTcxCfg->tcx_mdct_window_min_lengthFB, 1 ) ); + Copy_pword( hTcxCfg->tcx_mdct_window_transFB, hTcxCfg->tcx_mdct_window_minimumFB, shr( hTcxCfg->tcx_mdct_window_min_lengthFB, 1 ) ); /*Q15*/ } ELSE IF( EQ_16( hTcxCfg->tcx_mdct_window_min_length, hTcxCfg->tcx_mdct_window_min_lengthFB ) ) { - Copy_pword( hTcxCfg->tcx_mdct_window_minimum, hTcxCfg->tcx_mdct_window_minimumFB, shr( hTcxCfg->tcx_mdct_window_min_lengthFB, 1 ) ); + Copy_pword( hTcxCfg->tcx_mdct_window_minimum, hTcxCfg->tcx_mdct_window_minimumFB, shr( hTcxCfg->tcx_mdct_window_min_lengthFB, 1 ) ); /*Q15*/ } ELSE { mdct_window_sine_IVAS_updated( hTcxCfg->tcx_mdct_window_minimumFB, input_Fs, hTcxCfg->tcx_mdct_window_min_lengthFB, MIN_OVERLAP, element_mode ); } /* TCX Offset */ - hTcxCfg->tcx_offset = shr( hTcxCfg->tcx_mdct_window_delay, 1 ); - hTcxCfg->tcx_offsetFB = shr( hTcxCfg->tcx_mdct_window_delayFB, 1 ); + hTcxCfg->tcx_offset = shr( hTcxCfg->tcx_mdct_window_delay, 1 ); /*Q0*/ + hTcxCfg->tcx_offsetFB = shr( hTcxCfg->tcx_mdct_window_delayFB, 1 ); /*Q0*/ /*<0 rectangular transition with optimized window size = L_frame+L_frame/4*/ hTcxCfg->lfacNext = sub( hTcxCfg->tcx_offset, shr( L_frame, 2 ) ); hTcxCfg->lfacNextFB = sub( hTcxCfg->tcx_offsetFB, shr( L_frameTCX, 2 ) ); @@ -1761,22 +1761,22 @@ void init_tcx_window_cfg_fx( void init_tcx_cfg_fx( TCX_CONFIG_HANDLE hTcxCfg, - const Word32 total_brate, - const Word32 sr_core, - const Word32 input_Fs, - const Word16 L_frame, - const Word16 bwidth, - const Word16 L_frameTCX, - const Word16 fscale, - const Word16 preemph_fac, /*Q15*/ - const Word16 tcxonly, - const Word16 rf_mode, - const Word16 igf, - const Word16 infoIGFStopFreq, - const Word16 element_mode, - const Word16 ini_frame, - const Word16 MCT_flag, - const Word16 fscaleFB ) + const Word32 total_brate, /*Q0*/ + const Word32 sr_core, /*Q0*/ + const Word32 input_Fs, /*Q0*/ + const Word16 L_frame, /*Q0*/ + const Word16 bwidth, /*Q0*/ + const Word16 L_frameTCX, /*Q0*/ + const Word16 fscale, /*Q0*/ + const Word16 preemph_fac, /*Q15*/ + const Word16 tcxonly, /*Q0*/ + const Word16 rf_mode, /*Q0*/ + const Word16 igf, /*Q0*/ + const Word16 infoIGFStopFreq, /*Q0*/ + const Word16 element_mode, /*Q0*/ + const Word16 ini_frame, /*Q0*/ + const Word16 MCT_flag, /*Q0*/ + const Word16 fscaleFB /*Q0*/ ) { Word16 i; Word16 mdctWindowLength; @@ -1786,15 +1786,15 @@ void init_tcx_cfg_fx( hTcxCfg->preemph_fac = preemph_fac; move16(); - hTcxCfg->tcx5Size = shr( L_frame, 2 ); /* Always 5 ms */ - hTcxCfg->tcx5SizeFB = shr( L_frameTCX, 2 ); /* Always 5 ms */ + hTcxCfg->tcx5Size = shr( L_frame, 2 ); /* Always 5 ms Q0*/ + hTcxCfg->tcx5SizeFB = shr( L_frameTCX, 2 ); /* Always 5 ms Q0*/ move16(); move16(); - hTcxCfg->tcx_mdct_window_length_old = hTcxCfg->tcx_mdct_window_length; + hTcxCfg->tcx_mdct_window_length_old = hTcxCfg->tcx_mdct_window_length; /*Q0*/ move16(); - mdctWindowLength = getMdctWindowLength_fx( fscale ); - mdctWindowLengthFB = getMdctWindowLength_fx( fscaleFB ); + mdctWindowLength = getMdctWindowLength_fx( fscale ); /*Q0*/ + mdctWindowLengthFB = getMdctWindowLength_fx( fscaleFB ); /*Q0*/ init_tcx_window_cfg_fx( hTcxCfg, sr_core, input_Fs, L_frame, L_frameTCX, mdctWindowLength, mdctWindowLengthFB, element_mode ); /* SQ deadzone & memory quantization*/ hTcxCfg->sq_rounding = 12288 /*0.375f Q15*/; /*deadzone of 1.25->rounding=1-1.25/2 (No deadzone=0.5)*/ @@ -1814,16 +1814,16 @@ void init_tcx_cfg_fx( hTcxCfg->tcxRateLoopOpt = 3; move16(); } - hTcxCfg->bandwidth = getTcxBandwidth( bwidth ); + hTcxCfg->bandwidth = getTcxBandwidth( bwidth ); /*Q15*/ move16(); /* set number of coded lines */ - hTcxCfg->tcx_coded_lines = getNumTcxCodedLines( bwidth ); + hTcxCfg->tcx_coded_lines = getNumTcxCodedLines( bwidth ); /*Q0*/ move16(); /* TNS in TCX */ hTcxCfg->pCurrentTnsConfig = NULL; - hTcxCfg->fIsTNSAllowed = getTnsAllowed( total_brate, igf, element_mode ); + hTcxCfg->fIsTNSAllowed = getTnsAllowed( total_brate, igf, element_mode ); /*Q0*/ move16(); IF( hTcxCfg->fIsTNSAllowed ) @@ -1843,11 +1843,11 @@ void init_tcx_cfg_fx( } /* Context HM*/ - hTcxCfg->ctx_hm = getCtxHm( element_mode, total_brate, rf_mode ); + hTcxCfg->ctx_hm = getCtxHm( element_mode, total_brate, rf_mode ); /*Q0*/ move16(); /* Residual Coding*/ - hTcxCfg->resq = getResq( total_brate ); + hTcxCfg->resq = getResq( total_brate ); /*Q0*/ move16(); test(); if ( hTcxCfg->resq && !tcxonly ) @@ -1888,7 +1888,7 @@ void init_tcx_cfg_fx( { i = sub( i, 1 ); } - hTcxCfg->na_scale = scaleTcxTable[i].scale; + hTcxCfg->na_scale = scaleTcxTable[i].scale; /*Q15*/ move16(); BREAK; } diff --git a/lib_com/deemph.c b/lib_com/deemph.c index 9583a79d4..4e1093120 100644 --- a/lib_com/deemph.c +++ b/lib_com/deemph.c @@ -75,22 +75,22 @@ void deemph_fx_32( Word32 *signal, /* i/o: signal Qx*/ const Word16 mu, /* i : deemphasis factor Q15*/ const int16_t L, /* i : vector size */ - Word32 *mem /* i/o: memory (y[-1]) Qx*/ + Word32 *mem /* i/o: memory (y[-1]) Qx+shift*/ ) { Word16 i; - signal[0] = L_add( signal[0], Mpy_32_16_1( ( *mem ), mu ) ); + signal[0] = L_add( signal[0], Mpy_32_16_1( ( *mem ), mu ) ); /*Qx*/ move32(); FOR( i = 1; i < L; i++ ) { - signal[i] = L_add( signal[i], Mpy_32_16_1( signal[i - 1], mu ) ); - signal[i] = L_shl( signal[i], shift ); + signal[i] = L_add( signal[i], Mpy_32_16_1( signal[i - 1], mu ) ); /*Qx*/ + signal[i] = L_shl( signal[i], shift ); /*Qx+shift*/ move32(); move32(); } - *mem = signal[L - 1]; + *mem = signal[L - 1]; /*Qx+shift*/ move32(); return; @@ -132,10 +132,10 @@ void deemph_fx( move32(); #endif - L_tmp = L_deposit_h( signal[0] ); + L_tmp = L_deposit_h( signal[0] ); /*Qx+16*/ #ifdef BASOP_NOGLOB - L_tmp = L_mac_o( L_tmp, *mem, mu, &Overflow ); - signal[0] = round_fx_o( L_tmp, &Overflow ); + L_tmp = L_mac_o( L_tmp, *mem, mu, &Overflow ); /*Qx+16*/ + signal[0] = round_fx_o( L_tmp, &Overflow ); /*Qx*/ #else L_tmp = L_mac( L_tmp, *mem, mu ); signal[0] = round_fx( L_tmp ); @@ -144,18 +144,18 @@ void deemph_fx( FOR( i = 1; i < L; i++ ) { - L_tmp = L_deposit_h( signal[i] ); + L_tmp = L_deposit_h( signal[i] ); /*Qx+16*/ #ifdef BASOP_NOGLOB - L_tmp = L_mac_o( L_tmp, signal[i - 1], mu, &Overflow ); - signal[i] = round_fx_o( L_tmp, &Overflow ); -#else /* BASOP_NOGLOB */ + L_tmp = L_mac_o( L_tmp, signal[i - 1], mu, &Overflow ); /*Qx+16*/ + signal[i] = round_fx_o( L_tmp, &Overflow ); /*Qx*/ +#else /* BASOP_NOGLOB */ L_tmp = L_mac( L_tmp, signal[i - 1], mu ); signal[i] = round_fx( L_tmp ); -#endif /* BASOP_NOGLOB */ +#endif /* BASOP_NOGLOB */ move16(); } - *mem = signal[L - 1]; + *mem = signal[L - 1]; /*Qx*/ move16(); } @@ -181,22 +181,22 @@ void Deemph2( #endif /* saturation can occur in L_mac() */ - L_tmp = L_mult( x[0], 16384 ); - x[0] = mac_r( L_tmp, *mem, mu ); + L_tmp = L_mult( x[0], 16384 /*0.5f in Q15*/ ); /*Qx+16*/ + x[0] = mac_r( L_tmp, *mem, mu ); /*Qx-1*/ move16(); FOR( i = 1; i < L; i++ ) { - L_tmp = L_mult( x[i], 16384 ); + L_tmp = L_mult( x[i], 16384 /*0.5f in Q15*/ ); /*Qx+16*/ #ifdef BASOP_NOGLOB - x[i] = mac_ro( L_tmp, x[i - 1], mu, &Overflow ); + x[i] = mac_ro( L_tmp, x[i - 1], mu, &Overflow ); /*Qx-1*/ #else x[i] = mac_r( L_tmp, x[i - 1], mu ); #endif move16(); } - *mem = x[L - 1]; + *mem = x[L - 1]; /*Qx-1*/ move16(); } @@ -229,15 +229,15 @@ void E_UTIL_deemph2( Word16 shift, Word16 *x, const Word16 mu, const Word16 L, W #endif /* signal[0] = signal[0] + mu * (*mem); */ - L_tmp = L_deposit_h( *mem ); + L_tmp = L_deposit_h( *mem ); /*Qx+16*/ IF( shift >= 0 ) { - shift = shr( -32768, shift ); + shift = shr( -32768, shift ); /*Q15 - shift*/ FOR( i = 0; i < L; i++ ) { #ifdef BASOP_NOGLOB - L_tmp = L_msu_o( Mpy_32_16_1( L_tmp, mu ), x[i], shift, &Overflow ); - x[i] = round_fx_o( L_tmp, &Overflow ); + L_tmp = L_msu_o( Mpy_32_16_1( L_tmp, mu ), x[i], shift, &Overflow ); /*Qx-shift+16*/ + x[i] = round_fx_o( L_tmp, &Overflow ); /*Qx-shift*/ #else L_tmp = L_msu( Mpy_32_16_1( L_tmp, mu ), x[i], shift ); x[i] = round_fx( L_tmp ); @@ -250,9 +250,9 @@ void E_UTIL_deemph2( Word16 shift, Word16 *x, const Word16 mu, const Word16 L, W FOR( i = 0; i < L; i++ ) { #ifdef BASOP_NOGLOB - L_tmp = L_msu_o( Mpy_32_16_1( L_tmp, mu ), shr_o( x[i], shift, &Overflow ), -32768, &Overflow ); - x[i] = round_fx_o( L_tmp, &Overflow ); -#else /* BASOP_NOGLOB */ + L_tmp = L_msu_o( Mpy_32_16_1( L_tmp, mu ), shr_o( x[i], shift, &Overflow ), -32768 /*1.0f in Q15*/, &Overflow ); /*Qx-shift+16*/ + x[i] = round_fx_o( L_tmp, &Overflow ); /*Qx-shift*/ +#else /* BASOP_NOGLOB */ L_tmp = L_msu( Mpy_32_16_1( L_tmp, mu ), shr( x[i], shift ), -32768 ); x[i] = round_fx( L_tmp ); #endif @@ -260,7 +260,7 @@ void E_UTIL_deemph2( Word16 shift, Word16 *x, const Word16 mu, const Word16 L, W } } - *mem = x[L - 1]; + *mem = x[L - 1]; /*Qx-shift*/ move16(); return; diff --git a/lib_com/delay_comp.c b/lib_com/delay_comp.c index c1e1e869c..8e522ccd6 100644 --- a/lib_com/delay_comp.c +++ b/lib_com/delay_comp.c @@ -113,8 +113,8 @@ int32_t get_delay( } #else Word32 get_delay_fx( /* o : delay value in ms */ - const Word16 what_delay, /* i : what delay? (ENC or DEC) */ - const Word32 io_fs, /* i : input/output sampling frequency */ + const Word16 what_delay, /* i : what delay? (ENC or DEC) Q0*/ + const Word32 io_fs, /* i : input/output sampling frequency Q0*/ const IVAS_FORMAT ivas_format, /* i : IVAS format */ HANDLE_CLDFB_FILTER_BANK hCldfb /* i : Handle of Cldfb analysis */ #ifdef SPLIT_REND_WITH_HEAD_ROT @@ -123,7 +123,7 @@ Word32 get_delay_fx( /* o : delay value in ms #endif ) { - Word32 delay; + Word32 delay; /*Q0*/ delay = 0; move32(); @@ -131,12 +131,12 @@ Word32 get_delay_fx( /* o : delay value in ms { IF( EQ_16( ivas_format, MONO_FORMAT ) ) /* EVS mono */ { - delay = ( DELAY_FIR_RESAMPL_NS + ACELP_LOOK_NS ); + delay = DELAY_FIR_RESAMPL_NS + ACELP_LOOK_NS; /*Q0*/ move32(); } ELSE { - delay = IVAS_ENC_DELAY_NS; + delay = IVAS_ENC_DELAY_NS; /*Q0*/ move32(); test(); if ( EQ_16( ivas_format, MASA_FORMAT ) || EQ_16( ivas_format, MASA_ISM_FORMAT ) ) @@ -149,7 +149,7 @@ Word32 get_delay_fx( /* o : delay value in ms if ( EQ_16( ivas_format, SBA_FORMAT ) || EQ_16( ivas_format, SBA_ISM_FORMAT ) ) { /* compensate for DirAC/SPAR filterbank delay */ - delay = L_add( delay, IVAS_FB_ENC_DELAY_NS ); + delay = L_add( delay, IVAS_FB_ENC_DELAY_NS ); /*Q0*/ } } ELSE @@ -158,18 +158,18 @@ Word32 get_delay_fx( /* o : delay value in ms { IF( EQ_32( io_fs, 8000 ) ) { - delay = DELAY_CLDFB_NS; + delay = DELAY_CLDFB_NS; /*Q0*/ move32(); } ELSE { - delay = DELAY_BWE_TOTAL_NS; + delay = DELAY_BWE_TOTAL_NS; /*Q0*/ move32(); } } ELSE /* IVAS */ { - delay = IVAS_DEC_DELAY_NS; + delay = IVAS_DEC_DELAY_NS; /*Q0*/ move32(); #ifdef SPLIT_REND_WITH_HEAD_ROT @@ -180,7 +180,7 @@ Word32 get_delay_fx( /* o : delay value in ms if ( hCldfb != NULL ) { /* compensate for filterbank delay */ - delay = L_add( delay, IVAS_FB_DEC_DELAY_NS ); + delay = L_add( delay, IVAS_FB_DEC_DELAY_NS ); /*Q0*/ } #ifdef SPLIT_REND_WITH_HEAD_ROT } @@ -188,11 +188,11 @@ Word32 get_delay_fx( /* o : delay value in ms test(); if ( EQ_16( ivas_format, MASA_FORMAT ) || EQ_16( ivas_format, MASA_ISM_FORMAT ) ) { - delay = L_add( delay, IVAS_ENC_DELAY_NS ); /* Compensate also the encoder delay in the decoder with MASA */ + delay = L_add( delay, IVAS_ENC_DELAY_NS ); /* Compensate also the encoder delay in the decoder with MASA */ /*Q0*/ } } } - return delay; + return delay; /*Q0*/ } #endif diff --git a/lib_com/dlpc_bfi_fx.c b/lib_com/dlpc_bfi_fx.c index be4b27696..2d6b11268 100644 --- a/lib_com/dlpc_bfi_fx.c +++ b/lib_com/dlpc_bfi_fx.c @@ -10,20 +10,20 @@ void dlpc_bfi( const Word16 L_frame, - Word16 *lsf_q, /* o : quantized LSFs */ - const Word16 *lsfold, /* i : past quantized LSF */ - const Word16 last_good, /* i : last good received frame */ - const Word16 nbLostCmpt, /* i : counter of consecutive bad frames */ - Word16 mem_MA[], /* i/o: quantizer memory for MA model */ - Word16 mem_AR[], /* i/o: quantizer memory for AR model */ - Word16 *stab_fac, /* i : LSF stability factor */ - Word16 *lsf_adaptive_mean, /* i : LSF adaptive mean, updated when BFI==0 */ - Word16 numlpc, /* i : Number of division per superframe */ - Word16 lsf_cng[], + Word16 *lsf_q, /* o : quantized LSFs 14Q1*1.28*/ + const Word16 *lsfold, /* i : past quantized LSF 14Q1*1.28*/ + const Word16 last_good, /* i : last good received frame Q0*/ + const Word16 nbLostCmpt, /* i : counter of consecutive bad frames Q0*/ + Word16 mem_MA[], /* i/o: quantizer memory for MA model 14Q1*1.28*/ + Word16 mem_AR[], /* i/o: quantizer memory for AR model 14Q1*1.28*/ + Word16 *stab_fac, /* i : LSF stability factor Q15*/ + Word16 *lsf_adaptive_mean, /* i : LSF adaptive mean, updated when BFI==0 14Q1*1.28*/ + Word16 numlpc, /* i : Number of division per superframe Q0*/ + Word16 lsf_cng[], /*Q1*1.28*/ Word8 plcBackgroundNoiseUpdated, - Word16 *lsf_q_cng, /* o : quantized LSFs */ - Word16 *old_lsf_q_cng, /* o : old quantized LSFs for background noise */ - const Word16 *lsfBase, /* i : base for differential LSF coding */ + Word16 *lsf_q_cng, /* o : quantized LSFs 14Q1*1.28*/ + Word16 *old_lsf_q_cng, /* o : old quantized LSFs for background noise 14Q1*1.28*/ + const Word16 *lsfBase, /* i : base for differential LSF coding Q1*1.28*/ Word8 tcxonly ) { diff --git a/lib_com/enhancer_fx.c b/lib_com/enhancer_fx.c index 8211bb406..8d8bb2ef3 100644 --- a/lib_com/enhancer_fx.c +++ b/lib_com/enhancer_fx.c @@ -100,7 +100,7 @@ void enhancer_fx( i = 0; move16(); /* high dispersion */ } - ELSE if ( LE_32( core_brate, ACELP_8k85 ) ) + ELSE IF( LE_32( core_brate, ACELP_8k85 ) ) { i = 1; move16(); /* low dispersion */ @@ -118,7 +118,7 @@ void enhancer_fx( i = 0; move16(); /* high dispersion */ } - ELSE if ( ( EQ_16( coder_type, GENERIC ) || EQ_16( coder_type, TRANSITION ) || EQ_16( coder_type, AUDIO ) || coder_type == INACTIVE ) && LE_32( core_brate, ACELP_9k60 ) ) + ELSE IF( ( EQ_16( coder_type, GENERIC ) || EQ_16( coder_type, TRANSITION ) || EQ_16( coder_type, AUDIO ) || coder_type == INACTIVE ) && LE_32( core_brate, ACELP_9k60 ) ) { i = 1; move16(); /* low dispersion */ @@ -138,7 +138,7 @@ void enhancer_fx( /* tmp = 0.5f * (1.0f - voice_fac) */ #ifdef BASOP_NOGLOB - tmp = msu_r_sat( 0x40000000, voice_fac, 16384 ); /*Q15 */ /* 1=unvoiced, 0=voiced */ + tmp = msu_r_sat( 0x40000000 /*0.5.Q31*/, voice_fac, 16384 /*0.5.Q15*/ ); /*Q15 */ /* 1=unvoiced, 0=voiced */ #else tmp = msu_r( 0x40000000, voice_fac, 16384 ); /*Q15 */ /* 1=unvoiced, 0=voiced */ #endif @@ -147,13 +147,13 @@ void enhancer_fx( IF( LT_32( norm_gain_code, *gc_threshold ) ) { - L_tmp = Madd_32_16( norm_gain_code, norm_gain_code, 6226 ); /*Q16 */ - L_tmp = L_min( L_tmp, *gc_threshold ); /*Q16 */ + L_tmp = Madd_32_16( norm_gain_code, norm_gain_code, 6226 /*0.19.Q15*/ ); /*Q16 */ + L_tmp = L_min( L_tmp, *gc_threshold ); /*Q16 */ } ELSE { - L_tmp = Mult_32_16( norm_gain_code, 27536 ); /*Q16 */ - L_tmp = L_max( L_tmp, *gc_threshold ); /*Q16 */ + L_tmp = Mult_32_16( norm_gain_code, 27536 /*0.84.Q15*/ ); /*Q16 */ + L_tmp = L_max( L_tmp, *gc_threshold ); /*Q16 */ } *gc_threshold = L_tmp; move32(); /*Q16 */ @@ -199,9 +199,9 @@ void enhancer_fx( pit_sharp = shl( gain_pit, 1 ); /* saturation can occur here Q14 -> Q15 */ #endif /* saturation takes care of "if (pit_sharp > 1.0) { pit_sharp=1.0; }" */ - IF( GT_16( pit_sharp, 16384 ) ) + IF( GT_16( pit_sharp, 16384 /*0.5.Q15*/ ) ) { - tmp16 = mult( pit_sharp, 8192 ); + tmp16 = mult( pit_sharp, 8192 /*0.25.Q15*/ ); FOR( i = 0; i < L_SUBFR; i++ ) { /* excp[i] = pt_exc2[i] * pit_sharp * 0.25 */ @@ -215,13 +215,13 @@ void enhancer_fx( { /* tmp = 0.150 * (1.0 + voice_fac) */ /* 0.30=voiced, 0=unvoiced */ - tmp = mac_r( 0x10000000L, voice_fac, 4915 ); /*Q15 */ + tmp = mac_r( 0x10000000L, voice_fac, 4915 /*0.15.Q15*/ ); /*Q15 */ } ELSE { /* tmp = 0.125 * (1.0 + voice_fac) */ /* 0.25=voiced, 0=unvoiced */ - tmp = mac_r( 0x10000000L, voice_fac, 4096 ); /*Q15 */ + tmp = mac_r( 0x10000000L /*0.125.Q31*/, voice_fac, 4096 ); /*Q15 */ } /*----------------------------------------------------------------- @@ -241,7 +241,6 @@ void enhancer_fx( pt_exc2[0] = msu_r( L_tmp, -32768, pt_exc2[0] ); move16(); #endif - move16(); /* in Q_exc */ FOR( i = 1; i < L_SUBFR - 1; i++ ) { @@ -257,8 +256,8 @@ void enhancer_fx( tmp16 = msu_r( L_tmp, code[i - 1], tmp ); L_tmp = L_shl( L_mult( gain_code_hi, tmp16 ), sc ); pt_exc2[i] = msu_r( L_tmp, -32768, pt_exc2[i] ); -#endif move16(); /* in Q_exc */ +#endif } /* pt_exc2[L_SUBFR-1] += code[L_SUBFR-1] - tmp * code[L_SUBFR-2] */ @@ -272,12 +271,11 @@ void enhancer_fx( pt_exc2[L_SUBFR - 1] = msu_r( L_tmp, -32768, pt_exc2[L_SUBFR - 1] ); move16(); #endif - move16(); /* in Q_exc */ test(); test(); IF( Opt_AMR_WB && ( EQ_32( core_brate, ACELP_8k85 ) || EQ_32( core_brate, ACELP_6k60 ) ) ) { - IF( GT_16( pit_sharp, 16384 ) ) + IF( GT_16( pit_sharp, 16384 /*0.5.Q115*/ ) ) { FOR( i = 0; i < L_SUBFR; i++ ) { @@ -334,7 +332,7 @@ void enhancer_fx( void enhancer_ivas_fx( const Word16 codec_mode, /* i : flag indicating Codec Mode */ const Word32 core_brate, /* i : decoder bitrate */ - const int16_t cbk_index, /* i : */ + const Word16 cbk_index, /* i : */ const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ const Word16 coder_type, /* i : coder type */ const Word16 i_subfr, /* i : subframe number */ @@ -379,7 +377,7 @@ void enhancer_ivas_fx( i = 0; move16(); /* high dispersion */ } - ELSE if ( LE_32( core_brate, ACELP_8k85 ) ) + ELSE IF( LE_32( core_brate, ACELP_8k85 ) ) { i = 1; move16(); /* low dispersion */ @@ -443,7 +441,7 @@ void enhancer_ivas_fx( /* tmp = 0.5f * (1.0f - voice_fac) */ #ifdef BASOP_NOGLOB - tmp = msu_r_sat( 0x40000000, voice_fac, 16384 ); /*Q15 */ /* 1=unvoiced, 0=voiced */ + tmp = msu_r_sat( 0x40000000 /*0.5.Q31*/, voice_fac, 16384 /*0.5.Q14*/ ); /*Q15 */ /* 1=unvoiced, 0=voiced */ #else tmp = msu_r( 0x40000000, voice_fac, 16384 ); /*Q15 */ /* 1=unvoiced, 0=voiced */ #endif @@ -452,13 +450,13 @@ void enhancer_ivas_fx( IF( LT_32( norm_gain_code, *gc_threshold ) ) { - L_tmp = Madd_32_16( norm_gain_code, norm_gain_code, 6226 ); /*Q16 */ - L_tmp = L_min( L_tmp, *gc_threshold ); /*Q16 */ + L_tmp = Madd_32_16( norm_gain_code, norm_gain_code, 6226 /*0.19.Q15*/ ); /*Q16 */ + L_tmp = L_min( L_tmp, *gc_threshold ); /*Q16 */ } ELSE { - L_tmp = Mult_32_16( norm_gain_code, 27536 ); /*Q16 */ - L_tmp = L_max( L_tmp, *gc_threshold ); /*Q16 */ + L_tmp = Mult_32_16( norm_gain_code, 27536 /*0.84.Q15*/ ); /*Q16 */ + L_tmp = L_max( L_tmp, *gc_threshold ); /*Q16 */ } *gc_threshold = L_tmp; move32(); /*Q16 */ @@ -504,9 +502,9 @@ void enhancer_ivas_fx( pit_sharp = shl( gain_pit, 1 ); /* saturation can occur here Q14 -> Q15 */ #endif /* saturation takes care of "if (pit_sharp > 1.0) { pit_sharp=1.0; }" */ - IF( GT_16( pit_sharp, 16384 ) ) + IF( GT_16( pit_sharp, 16384 /*0.5.Q15*/ ) ) { - tmp16 = mult( pit_sharp, 8192 ); + tmp16 = mult( pit_sharp, 8192 /*0.25.Q15*/ ); FOR( i = 0; i < L_SUBFR; i++ ) { /* excp[i] = pt_exc2[i] * pit_sharp * 0.25 */ @@ -520,13 +518,13 @@ void enhancer_ivas_fx( { /* tmp = 0.150 * (1.0 + voice_fac) */ /* 0.30=voiced, 0=unvoiced */ - tmp = mac_r( 0x13333333L, voice_fac, 4915 ); /*Q15 */ + tmp = mac_r( 0x13333333L /*0.150.Q31*/, voice_fac, 4915 /*0.150.Q15*/ ); /*Q15 */ } ELSE { /* tmp = 0.125 * (1.0 + voice_fac) */ /* 0.25=voiced, 0=unvoiced */ - tmp = mac_r( 0x10000000L, voice_fac, 4096 ); /*Q15 */ + tmp = mac_r( 0x10000000L /*0.125.Q31*/, voice_fac, 4096 ); /*Q15 */ } /*----------------------------------------------------------------- @@ -566,7 +564,7 @@ void enhancer_ivas_fx( test(); IF( Opt_AMR_WB && ( EQ_32( core_brate, ACELP_8k85 ) || EQ_32( core_brate, ACELP_6k60 ) ) ) { - IF( GT_16( pit_sharp, 16384 ) ) + IF( GT_16( pit_sharp, 16384 /*0.5.Q14*/ ) ) { FOR( i = 0; i < L_SUBFR; i++ ) { @@ -624,7 +622,7 @@ void enhancer_ivas_fx2( i = 0; move16(); /* high dispersion */ } - ELSE if ( LE_32( core_brate, ACELP_8k85 ) ) + ELSE IF( LE_32( core_brate, ACELP_8k85 ) ) { i = 1; move16(); /* low dispersion */ @@ -642,7 +640,7 @@ void enhancer_ivas_fx2( i = 0; move16(); /* high dispersion */ } - ELSE if ( ( EQ_16( coder_type, GENERIC ) || EQ_16( coder_type, TRANSITION ) || EQ_16( coder_type, AUDIO ) || coder_type == INACTIVE ) && LE_32( core_brate, ACELP_9k60 ) ) + ELSE IF( ( EQ_16( coder_type, GENERIC ) || EQ_16( coder_type, TRANSITION ) || EQ_16( coder_type, AUDIO ) || coder_type == INACTIVE ) && LE_32( core_brate, ACELP_9k60 ) ) { i = 1; move16(); /* low dispersion */ @@ -662,7 +660,7 @@ void enhancer_ivas_fx2( /* tmp = 0.5f * (1.0f - voice_fac) */ #ifdef BASOP_NOGLOB - tmp = msu_r_sat( 0x40000000, voice_fac, 16384 ); /*Q15 */ /* 1=unvoiced, 0=voiced */ + tmp = msu_r_sat( 0x40000000 /*0.5.Q31*/, voice_fac, 16384 /*0.5.Q15*/ ); /*Q15 */ /* 1=unvoiced, 0=voiced */ #else tmp = msu_r( 0x40000000, voice_fac, 16384 ); /*Q15 */ /* 1=unvoiced, 0=voiced */ #endif @@ -671,13 +669,13 @@ void enhancer_ivas_fx2( IF( LT_32( norm_gain_code, *gc_threshold ) ) { - L_tmp = Madd_32_16( norm_gain_code, norm_gain_code, 6226 ); /*Q16 */ - L_tmp = L_min( L_tmp, *gc_threshold ); /*Q16 */ + L_tmp = Madd_32_16( norm_gain_code, norm_gain_code, 6226 /*0.19.Q15*/ ); /*Q16 */ + L_tmp = L_min( L_tmp, *gc_threshold ); /*Q16 */ } ELSE { - L_tmp = Mult_32_16( norm_gain_code, 27536 ); /*Q16 */ - L_tmp = L_max( L_tmp, *gc_threshold ); /*Q16 */ + L_tmp = Mult_32_16( norm_gain_code, 27536 /*0.84.Q15*/ ); /*Q16 */ + L_tmp = L_max( L_tmp, *gc_threshold ); /*Q16 */ } *gc_threshold = L_tmp; move32(); /*Q16 */ @@ -723,9 +721,9 @@ void enhancer_ivas_fx2( pit_sharp = shl( gain_pit, 1 ); /* saturation can occur here Q14 -> Q15 */ #endif /* saturation takes care of "if (pit_sharp > 1.0) { pit_sharp=1.0; }" */ - IF( GT_16( pit_sharp, 16384 ) ) + IF( GT_16( pit_sharp, 16384 /*0.5.Q15*/ ) ) { - tmp16 = mult( pit_sharp, 8192 ); + tmp16 = mult( pit_sharp, 8192 /*0.25.Q15*/ ); FOR( i = 0; i < L_SUBFR; i++ ) { /* excp[i] = pt_exc2[i] * pit_sharp * 0.25 */ @@ -739,13 +737,13 @@ void enhancer_ivas_fx2( { /* tmp = 0.150 * (1.0 + voice_fac) */ /* 0.30=voiced, 0=unvoiced */ - tmp = mac_r( 0x13333333L, voice_fac, 4915 ); /*Q15 */ + tmp = mac_r( 0x13333333L /*0.150.Q31*/, voice_fac, 4915 /*0.150.Q15*/ ); /*Q15 */ } ELSE { /* tmp = 0.125 * (1.0 + voice_fac) */ /* 0.25=voiced, 0=unvoiced */ - tmp = mac_r( 0x10000000L, voice_fac, 4096 ); /*Q15 */ + tmp = mac_r( 0x10000000L /*0.125.Q31*/, voice_fac, 4096 /*0.125.Q15*/ ); /*Q15 */ } /*----------------------------------------------------------------- @@ -801,7 +799,7 @@ void enhancer_ivas_fx2( test(); IF( Opt_AMR_WB && ( EQ_32( core_brate, ACELP_8k85 ) || EQ_32( core_brate, ACELP_6k60 ) ) ) { - IF( GT_16( pit_sharp, 16384 ) ) + IF( GT_16( pit_sharp, 16384 /*0.5.Q15*/ ) ) { FOR( i = 0; i < L_SUBFR; i++ ) { @@ -979,7 +977,7 @@ Word16 E_UTIL_enhancer( #endif move16(); - FOR( i = 1; i < sub( L_subfr, 1 ); i++ ) + FOR( i = 1; i < L_subfr - 1; i++ ) { /* exc2[i] = exc2[i] + code[i] - tmp*(code[i+1]+code[i-1]); */ L_tmp = L_mult( code[i], 16384 ); diff --git a/lib_com/est_tilt_fx.c b/lib_com/est_tilt_fx.c index 6f541c11f..d47a47191 100644 --- a/lib_com/est_tilt_fx.c +++ b/lib_com/est_tilt_fx.c @@ -93,7 +93,7 @@ Word16 est_tilt_fx( /* o : tilt of the code /* tilt of code for next subframe: 0.5=voiced, 0=unvoiced */ /* tilt_code = (float)(0.25*(1.0 + *voice_fac)) */ - tilt_code = mac_r( 8192L * 65536 - 0x8000, *voice_fac, 8192 ); /*Q15 */ + tilt_code = mac_r( 8192L /*0.25.Q15*/ * 65536 /*1.Q16*/ - 0x8000 /*1.Q15*/, *voice_fac, 8192 /*0.25.Q15*/ ); /*Q15 */ return tilt_code; } @@ -173,7 +173,7 @@ Word16 est_tilt_ivas_fx( /* o : tilt of the code /* find voice factor (1=voiced, -1=unvoiced) */ exp = div_s( abs_s( tmp ), ener1 ); - IF( LT_16( tmp, 0 ) ) + IF( tmp < 0 ) { exp = negate( exp ); } @@ -185,19 +185,19 @@ Word16 est_tilt_ivas_fx( /* o : tilt of the code /* tilt of code for next subframe: 0.5=voiced, 0=unvoiced */ /* tilt_code = (float)(0.25*(1.0 + *voice_fac)) */ - tilt_code = mac_r( 8192L * 65536 - 0x8000, *voice_fac, 8192 ); /*Q15 */ + tilt_code = mac_r( 8192L /*0.25.Q15*/ * 65536 /*1.Q16*/ - 0x8000 /*1.Q15*/, *voice_fac, 8192 /*0.25.Q15*/ ); /*Q15 */ } - ELSE IF( flag_tilt == 1 ) + ELSE IF( EQ_16( flag_tilt, 1 ) ) { /*Between 0.25 (=unvoiced) and 0.5 (=voiced)*/ // tilt_code = (float)(0.25f + (*voice_fac + 1.0f) * 0.125f); - tilt_code = mac_r( 12288L * 65536 - 0x8000, *voice_fac, 4096 ); /*Q15 */ + tilt_code = mac_r( 12288L /*0.375.Q15*/ * 65536 /*1.Q16*/ - 0x8000 /*1.Q15*/, *voice_fac, 4096 /*0.125.Q15*/ ); /*Q15 */ } ELSE { /*Between 0.28 (=unvoiced) and 0.56 (=voiced)*/ // tilt_code = (float)(0.28f + (*voice_fac + 1.0f) * 0.14f); - tilt_code = mac_r( 13763L * 65536 - 0x8000, *voice_fac, 4588 ); /*Q15 */ + tilt_code = mac_r( 13763L /*0.42.Q15*/ * 65536 /*1.Q16*/ - 0x8000 /*1.Q15*/, *voice_fac, 4588 /*0.14.Q15*/ ); /*Q15 */ } return tilt_code; @@ -249,7 +249,7 @@ Word16 Est_tilt2( /* o : tilt of the code /* find voice factor (1=voiced, -1=unvoiced) */ exp = div_s( abs_s( tmp ), ener1 ); - if ( tmp < 0 ) + IF( tmp < 0 ) { exp = negate( exp ); } @@ -259,7 +259,7 @@ Word16 Est_tilt2( /* o : tilt of the code /* tilt of code for next subframe: 0.5=voiced, 0=unvoiced */ /* tilt_code = (float)(0.25*(1.0 + *voice_fac)) */ - tilt_code = mac_r( 8192L * 65536 - 0x8000, *voice_fac, 8192 ); + tilt_code = mac_r( 8192L /*0.25.Q15*/ * 65536 /*1.Q16*/ - 0x8000 /*1.Q15*/, *voice_fac, 8192 /*0.25.Q15*/ ); return tilt_code; } @@ -289,7 +289,7 @@ void E_UTIL_voice_factor( Word16 *exc, /* i : pointer to the excitation f IF( shift != 0 ) { - fac = shl( 0x4000, add( 1, shift ) ); + fac = shl( 0x4000 /*1.Q14*/, add( 1, shift ) ); /* energy of pitch excitation */ stmp = mult_r( exc[0 + i_subfr], fac ); /* remove fac bits */ ener_64 = W_mult0_16_16( stmp, stmp ); @@ -377,7 +377,7 @@ void E_UTIL_voice_factor( Word16 *exc, /* i : pointer to the excitation f move16(); *tilt_code = add( 8192 /*0.25f Q15*/, mult_r( 8192 /*0.25f Q15*/, *voice_fac ) ); } - ELSE IF( flag_tilt == 1 ) + ELSE IF( EQ_16( flag_tilt, 1 ) ) { /*Between 0.25 (=unvoiced) and 0.5 (=voiced)*/ move16(); diff --git a/lib_com/fd_cng_com.c b/lib_com/fd_cng_com.c index a03edf290..350391c26 100644 --- a/lib_com/fd_cng_com.c +++ b/lib_com/fd_cng_com.c @@ -967,9 +967,10 @@ void SynthesisSTFT_flt( *-------------------------------------------------------------------*/ void SynthesisSTFT_fx( - Word32 *fftBuffer, /* i : FFT bins */ + Word32 *fftBuffer, + /* i : FFT bins */ // Q15 Word32 *timeDomainOutput, - Word32 *olapBuffer, + Word32 *olapBuffer, // Qin const Word16 *olapWin, const Word16 tcx_transition, HANDLE_FD_CNG_COM hFdCngCom, /* i/o: FD_CNG structure containing all buffers and variables */ @@ -988,7 +989,7 @@ void SynthesisSTFT_fx( test(); IF( ( EQ_16( element_mode, IVAS_CPE_TD ) || EQ_16( element_mode, IVAS_CPE_DFT ) ) && EQ_16( nchan_out, 2 ) ) { - Copy32( olapBuffer + sub( i_mult( 3, shr( hFdCngCom->frameSize, 2 ) ), ( M + 1 ) ), buf_fx, add( hFdCngCom->frameSize, M + 1 ) ); + Copy32( olapBuffer + sub( i_mult( 3, shr( hFdCngCom->frameSize, 2 ) ), ( M + 1 ) ), buf_fx, add( hFdCngCom->frameSize, M + 1 ) ); // Qin set32_fx( olapBuffer, 0, hFdCngCom->fftlen ); } ELSE @@ -999,28 +1000,28 @@ void SynthesisSTFT_fx( IF( tcx_transition ) { - FOR( i = 0; i < i_mult( 5, shr( hFdCngCom->frameSize, 2 ) ); i++ ) + FOR( i = 0; i < ( 5 * ( hFdCngCom->frameSize >> 2 ) ); i++ ) { - olapBuffer[i] = fftBuffer[i]; + olapBuffer[i] = fftBuffer[i]; // Q15 move32(); } } ELSE { - FOR( i = hFdCngCom->frameSize / 4; i < i_mult( 3, shr( hFdCngCom->frameSize, 2 ) ); i++ ) + FOR( i = hFdCngCom->frameSize / 4; i < ( 3 * ( hFdCngCom->frameSize >> 2 ) ); i++ ) { - olapBuffer[i] = L_add( olapBuffer[i], Mpy_32_16_1( fftBuffer[i], olapWin[sub( i, shr( hFdCngCom->frameSize, 2 ) )] ) ); + olapBuffer[i] = L_add( olapBuffer[i], Mpy_32_16_1( fftBuffer[i], olapWin[( i - ( hFdCngCom->frameSize >> 2 ) )] ) ); move32(); } - FOR( ; i < i_mult( 5, shr( hFdCngCom->frameSize, 2 ) ); i++ ) + FOR( ; i < ( 5 * ( hFdCngCom->frameSize >> 2 ) ); i++ ) { olapBuffer[i] = fftBuffer[i]; move32(); } } - FOR( ; i < i_mult( 7, shr( hFdCngCom->frameSize, 2 ) ); i++ ) + FOR( ; i < ( 7 * ( hFdCngCom->frameSize >> 2 ) ); i++ ) { - olapBuffer[i] = Mpy_32_16_1( fftBuffer[i], olapWin[sub( i, i_mult( 3, shr( hFdCngCom->frameSize, 2 ) ) )] ); + olapBuffer[i] = Mpy_32_16_1( fftBuffer[i], olapWin[( i - ( 3 * ( hFdCngCom->frameSize >> 2 ) ) )] ); move32(); } @@ -1054,7 +1055,7 @@ void SynthesisSTFT_fx( { FOR( i = 0; i < hFdCngCom->frameSize / 2; i++ ) { - buf_fx[i + ( M + 1 )] = L_add( buf_fx[i + ( M + 1 )], olapBuffer[add( i, shr( hFdCngCom->frameSize, 2 ) )] ); + buf_fx[i + ( M + 1 )] = L_add( buf_fx[i + ( M + 1 )], olapBuffer[( i + ( hFdCngCom->frameSize >> 2 ) )] ); move32(); } // v_multc(buf, (float)(hFdCngCom->fftlen / 2), buf, M + 1 + hFdCngCom->frameSize); @@ -1072,13 +1073,8 @@ void SynthesisSTFT_fx( preemph_ivas_fx( buf_fx + 1, PREEMPH_FAC, add( M, hFdCngCom->frameSize ), &tmp_fx ); // residu(hFdCngCom->A_cng_flt, M, buf + 1 + M, hFdCngCom->exc_cng_flt, hFdCngCom->frameSize); - // floatToFixed_arr( hFdCngCom->A_cng_flt, hFdCngCom->A_cng, Q13, M + 1 ); // residu_ivas_fx( hFdCngCom->A_cng, Q13, M, buf_fx + 1 + M, hFdCngCom->exc_cng_32fx, hFdCngCom->frameSize ); residu_ivas_fx( hFdCngCom->A_cng, ( 15 - norm_s( hFdCngCom->A_cng[0] - 1 ) ), M, buf_fx + 1 + M, hFdCngCom->exc_cng_32fx, hFdCngCom->frameSize ); - // for ( i = 0; i < hFdCngCom->frameSize; i++ ) - //{ - // hFdCngCom->exc_cng_flt[i] = fix_to_float( hFdCngCom->exc_cng_32fx[i], Q_in - 9 ); - // } return; } @@ -1152,9 +1148,10 @@ void SynthesisSTFT_dirac_flt( #endif #ifdef IVAS_FLOAT_FIXED void SynthesisSTFT_dirac_fx( - Word32 *fftBuffer, /* i : FFT bins */ + Word32 *fftBuffer, + /* i : FFT bins */ // hFdCngCom->fftBuffer_exp Word32 *timeDomainOutput, - Word32 *olapBuffer, + Word32 *olapBuffer, // Q_in const Word16 *olapWin, const Word16 samples_out, HANDLE_FD_CNG_COM hFdCngCom /* i/o: FD_CNG structure containing all buffers and variables */ @@ -1170,18 +1167,18 @@ void SynthesisSTFT_dirac_fx( Copy32( olapBuffer + hFdCngCom->frameSize, olapBuffer, hFdCngCom->frameSize ); set32_fx( olapBuffer + hFdCngCom->frameSize, 0, hFdCngCom->frameSize ); /*olapBuffer, fftBuffer, olapWin*/ - FOR( i = shr( hFdCngCom->frameSize, 2 ); i < i_mult( 3, shr( hFdCngCom->frameSize, 2 ) ); i++ ) + FOR( i = ( hFdCngCom->frameSize >> 2 ); i < ( 3 * ( hFdCngCom->frameSize >> 2 ) ); i++ ) { - olapBuffer[i] = L_add( olapBuffer[i], Mpy_32_16_1( fftBuffer[i], olapWin[sub( i, shr( hFdCngCom->frameSize, 2 ) )] ) ); + olapBuffer[i] = L_add( olapBuffer[i], Mpy_32_16_1( fftBuffer[i], olapWin[( i - ( hFdCngCom->frameSize >> 2 ) )] ) ); move32(); } - FOR( ; i < i_mult( 5, shr( hFdCngCom->frameSize, 2 ) ); i++ ) + FOR( ; i < ( 5 * ( hFdCngCom->frameSize >> 2 ) ); i++ ) { olapBuffer[i] = fftBuffer[i]; move32(); } - FOR( ; i < i_mult( 7, shr( hFdCngCom->frameSize, 2 ) ); i++ ) + FOR( ; i < ( 7 * ( hFdCngCom->frameSize >> 2 ) ); i++ ) { olapBuffer[i] = fftBuffer[i]; move32(); @@ -1225,9 +1222,9 @@ void SynthesisSTFT_dirac_fx( { Copy32( olapBuffer + samples_out, olapBuffer + hFdCngCom->frameSize, i_mult( 3, shr( hFdCngCom->frameSize, 2 ) ) ); } - FOR( i = i_mult( 5, shr( hFdCngCom->frameSize, 2 ) ); i < i_mult( 7, shr( hFdCngCom->frameSize, 2 ) ); i++ ) + FOR( i = ( 5 * ( hFdCngCom->frameSize >> 2 ) ); i < ( 7 * ( hFdCngCom->frameSize >> 2 ) ); i++ ) { - olapBuffer[i] = Mpy_32_16_1( olapBuffer[i], olapWin[sub( i, i_mult( 3, shr( hFdCngCom->frameSize, 2 ) ) )] ); + olapBuffer[i] = Mpy_32_16_1( olapBuffer[i], olapWin[( i - ( 3 * ( hFdCngCom->frameSize >> 2 ) ) )] ); move32(); } diff --git a/lib_com/fd_cng_com_fx.c b/lib_com/fd_cng_com_fx.c index e11d67d69..69228a482 100644 --- a/lib_com/fd_cng_com_fx.c +++ b/lib_com/fd_cng_com_fx.c @@ -364,7 +364,7 @@ void initPartitions( * Apply some dynamic range compression based on the log *-------------------------------------------------------------------*/ void compress_range( - Word32 *in, + Word32 *in, // Q(31 - in_exp) Word16 in_exp, Word16 *out, const Word16 len ) @@ -379,11 +379,11 @@ void compress_range( /* out = log2( 1 + in ) */ IF( in_exp >= 0 ) { - one_s = L_shr( 1073741824l /*0.5 Q31*/, in_exp ); + one_s = L_shr( 1073741824l /*0.5 Q31*/, in_exp ); // Q(31 - in_exp) in_exp32 = L_shl( L_deposit_l( add( in_exp, 1 ) ), WORD32_BITS - 1 - LD_DATA_SCALE ); FOR( i = 0; i < len; i++ ) { - in_s = L_add( L_shr( in[i], 1 ), one_s ); + in_s = L_add( L_shr( in[i], 1 ), one_s ); // Q(31 - in_exp) L_tmp = L_add( BASOP_Util_Log2( in_s ), in_exp32 ); if ( in_s == 0 ) { @@ -434,8 +434,8 @@ void compress_range( * Apply some dynamic range expansion to undo the compression *-------------------------------------------------------------------*/ void expand_range( - Word16 *in, - Word32 *out, + Word16 *in, // Q15 + Word32 *out, // Q(31 - out_exp) Word16 *out_exp, const Word16 len ) { @@ -451,7 +451,7 @@ void expand_range( move16(); FOR( i = 0; i < len; i++ ) { - maxVal = s_max( maxVal, in[i] ); + maxVal = s_max( maxVal, in[i] ); // Q15 } maxVal2 = maxVal; @@ -460,12 +460,12 @@ void expand_range( move16(); WHILE( maxVal >= 0 ) { - maxVal = sub( maxVal, 512 /*0.015625 Q15*/ ); + maxVal = sub( maxVal, 512 /*0.015625 Q15*/ ); // Q15 s = add( s, 1 ); } tmp = sub( maxVal2, maxVal ); - one_s = L_shr( 1073741824l /*0.5 Q31*/, sub( s, 1 ) ); + one_s = L_shr( 1073741824l /*0.5 Q31*/, sub( s, 1 ) ); // Q(31 - sub( s, 1 )) tmp32 = L_shr( 726941l /*0.0003385080526823181 Q31*/, s ); /* out = (2^(in) - 1) */ FOR( i = 0; i < len; i++ ) @@ -1766,7 +1766,7 @@ void minimum_statistics_fx( move16(); } } - if ( enc_dec == DEC && element_mode == IVAS_CPE_TD ) + IF( EQ_16( enc_dec, DEC ) && EQ_16( element_mode, IVAS_CPE_TD ) ) { // v_multc(msNoiseEst, 1.4125f, msNoiseEst, NPART_SHAPING); v_multc_att( msNoiseEst, 23142, msNoiseEst, NPART_SHAPING ); @@ -1812,7 +1812,7 @@ void apply_scale( Word32 *scale, /* o : scalefactor */ const Word16 bwmode, /* i : audio bandwidth */ const Word32 bitrate, /* i : Bit rate */ - const SCALE_SETUP *scaleTable, /* i : Scale table */ + const SCALE_SETUP *scaleTable, /* i : Scale table Q7 */ const Word16 scaleTableSize /* i : Size of scale table */ ) { @@ -1874,7 +1874,7 @@ void apply_scale_ivas_fx( Word32 *scale, /* o : scalefactor */ const Word16 bwmode, /* i : audio bandwidth */ const Word32 bitrate, /* i : Bit rate */ - const SCALE_SETUP *scaleTable, /* i : Scale table */ + const SCALE_SETUP *scaleTable, /* i : Scale table Q7 */ const Word16 scaleTableSize, /* i : Size of scale table */ Word16 *index ) { @@ -1922,7 +1922,7 @@ void bandcombinepow( IF( EQ_16( nband, npart ) ) { - Copy32( bandpow, partpow, nband ); + Copy32( bandpow, partpow, nband ); // Q(31 - exp_bandpow) smin = 0; move16(); } @@ -1973,13 +1973,13 @@ void bandcombinepow( * Scale partitions (with smoothing) *-------------------------------------------------------------------*/ void scalebands( - const Word32 *partpow, /* i : Power for each partition */ + const Word32 *partpow, /* i : Power for each partition Qx*/ Word16 *part, /* i : Partition upper boundaries (band indices starting from 0) */ const Word16 npart, /* i : Number of partitions */ Word16 *midband, /* i : Central band of each partition */ const Word16 nFFTpart, /* i : Number of FFT partitions */ const Word16 nband, /* i : Number of bands */ - Word32 *bandpow, /* o : Power for each band */ + Word32 *bandpow, /* o : Power for each band Qx*/ const Word16 flag_fft_en ) { Word16 i, j, s, s1, nint, delta, delta_cmp, delta_s; @@ -2008,7 +2008,7 @@ void scalebands( stopPart = nFFTpart; move16(); - WHILE( LT_16( startBand, nband ) ) + WHILE( startBand < nband ) { stopPartM1 = sub( stopPart, 1 ); test(); @@ -2026,15 +2026,15 @@ void scalebands( j = add( j, 1 ); /* inner partitions */ - IF( j < stopPart ) + IF( LT_16( j, stopPart ) ) { partpowLD64M1 = BASOP_Util_Log2( partpow[j - 1] ); } /* Debug values to check this variable is set. */ - delta = 0x4000; + delta = 0x4000; // 1.Q14 move16(); - delta_cmp = 0x4000; + delta_cmp = 0x4000; // 1.Q14 move16(); s1 = 1; move16(); @@ -2057,7 +2057,7 @@ void scalebands( WHILE( tmp > 0 ) { - tmp = L_sub( tmp, 33554432l /*0.015625 Q31*/ ); + tmp = L_sub( tmp, 33554432l /*0.015625 Q31*/ ); // Q31 delta_s = add( delta_s, 1 ); } delta_cmp = shl( 1, s_max( -15, sub( WORD16_BITS - 1, delta_s ) ) ); @@ -2067,7 +2067,7 @@ void scalebands( s1 = sub( delta_s, s ); #ifdef BASOP_NOGLOB - delta = round_fx_sat( L_shl_sat( tmp, s ) ); + delta = round_fx_sat( L_shl_sat( tmp, s ) ); // Q(14+s) #else delta = round_fx( L_shl( tmp, s ) ); #endif @@ -2088,19 +2088,19 @@ void scalebands( IF( GT_16( shr( delta, s ), delta_cmp ) ) { - delta = 0x4000; + delta = 0x4000; // 1.Q14 move16(); s1 = 1; move16(); } /* last half partition */ - val = partpow[stopPartM1]; + val = partpow[stopPartM1]; // Qx move32(); FOR( ; i <= part[stopPartM1]; i++ ) { val = L_shl( Mpy_32_16_1( val, delta ), s1 ); - bandpow[i] = val; + bandpow[i] = val; // Qx move32(); } } @@ -2115,13 +2115,13 @@ void scalebands( #ifdef IVAS_FLOAT_FIXED void scalebands_fx( - const Word32 *partpow, /* i : Power for each partition */ + const Word32 *partpow, /* i : Power for each partition Qx*/ Word16 *part, /* i : Partition upper boundaries (band indices starting from 0) */ const Word16 npart, /* i : Number of partitions */ Word16 *midband, /* i : Central band of each partition */ const Word16 nFFTpart, /* i : Number of FFT partitions */ const Word16 nband, /* i : Number of bands */ - Word32 *bandpow, /* o : Power for each band */ + Word32 *bandpow, /* o : Power for each band Qx*/ const Word16 flag_fft_en ) { Word16 i, j, s, s1, nint, delta, delta_cmp, delta_s; @@ -2162,7 +2162,7 @@ void scalebands_fx( FOR( i = startBand; i <= midband[j]; i++ ) { - bandpow[i] = partpow[j]; + bandpow[i] = partpow[j]; // Qx move32(); } j = add( j, 1 ); @@ -2174,9 +2174,9 @@ void scalebands_fx( } /* Debug values to check this variable is set. */ - delta = 0x4000; + delta = 0x4000; // 1.Q14 move16(); - delta_cmp = 0x4000; + delta_cmp = 0x4000; // 1.Q14 move16(); s1 = 1; move16(); @@ -2206,7 +2206,7 @@ void scalebands_fx( WHILE( tmp > 0 ) { - tmp = L_sub( tmp, 33554432l /*0.015625 Q31*/ ); + tmp = L_sub( tmp, 33554432l /*0.015625 Q31*/ ); // Q31 delta_s = add( delta_s, 1 ); } delta_cmp = shl( 1, s_max( -15, sub( WORD16_BITS - 1, delta_s ) ) ); @@ -2216,7 +2216,7 @@ void scalebands_fx( s1 = sub( delta_s, s ); #ifdef BASOP_NOGLOB - delta = round_fx_sat( L_shl_sat( tmp, s ) ); + delta = round_fx_sat( L_shl_sat( tmp, s ) ); // Q(14+s) #else delta = round_fx( L_shl( tmp, s ) ); #endif @@ -2229,7 +2229,7 @@ void scalebands_fx( bandpow[i] = L_shr( val, delta_s ); move32(); } - bandpow[i++] = partpow[j]; + bandpow[i++] = partpow[j]; // Qx move32(); partpowLD64M1 = partpowLD64; move32(); @@ -2237,14 +2237,14 @@ void scalebands_fx( IF( GT_16( shr( delta, s ), delta_cmp ) ) { - delta = 0x4000; + delta = 0x4000; // 1.Q14 move16(); s1 = 1; move16(); } /* last half partition */ - val = partpow[stopPartM1]; + val = partpow[stopPartM1]; // Qx move32(); FOR( ; i <= part[stopPartM1]; i++ ) { @@ -2263,7 +2263,7 @@ void scalebands_fx( val = 0; move32(); } - bandpow[i] = val; + bandpow[i] = val; // Qx move32(); } } @@ -2331,8 +2331,8 @@ static void getmidbands( FOR( j = 0; j < npart; j++ ) { #ifdef BASOP_NOGLOB - psize_norm[j] = shl_o( psize[j], shift, &Overflow ); -#else /* BASOP_NOGLOB */ + psize_norm[j] = shl_o( psize[j], shift, &Overflow ); // Q(15 - psize_norm_exp) +#else /* BASOP_NOGLOB */ psize_norm[j] = shl( psize[j], shift ); #endif move16(); @@ -2348,7 +2348,7 @@ static void getmidbands( *-------------------------------------------------------------------*/ void AnalysisSTFT( - const Word16 *timeDomainInput, /* i : pointer to time signal */ + const Word16 *timeDomainInput, /* i : pointer to time signal Q(Q)*/ Word16 Q, Word32 *fftBuffer, /* o : FFT bins */ Word16 *fftBuffer_exp, /* i : exponent of FFT bins */ @@ -2418,7 +2418,7 @@ void AnalysisSTFT( * STFT analysis filterbank *-------------------------------------------------------------------*/ void AnalysisSTFT_fx( - const Word16 *timeDomainInput, + const Word16 *timeDomainInput, // Q(Q) Word16 Q, Word32 *fftBuffer, /* o : FFT bins */ Word16 *fftBuffer_exp, /* i : exponent of FFT bins */ @@ -2528,7 +2528,7 @@ void SynthesisSTFT_enc_ivas_fx( { FOR( i = 0; i < len; i++ ) { - olapBuffer[i] = round_fx_sat( L_shl_sat( fftBuffer[i], sub( fftBufferExp, 15 ) ) ); + olapBuffer[i] = round_fx_sat( L_shl_sat( fftBuffer[i], sub( fftBufferExp, 15 ) ) ); // Q(15 - fftBufferExp) move16(); } } @@ -2543,7 +2543,7 @@ void SynthesisSTFT_enc_ivas_fx( } FOR( i = len3; i < len; i++ ) { - olapBuffer[i] = round_fx_sat( L_shl_sat( fftBuffer[i], sub( fftBufferExp, 15 ) ) ); + olapBuffer[i] = round_fx_sat( L_shl_sat( fftBuffer[i], sub( fftBufferExp, 15 ) ) ); // Q(15 - fftBufferExp) move16(); } } @@ -2620,7 +2620,7 @@ void SynthesisSTFT_enc_ivas_fx( void SynthesisSTFT( Word32 *fftBuffer, /* i : pointer to FFT bins */ Word16 fftBufferExp, /* i : exponent of FFT bins */ - Word16 *timeDomainOutput, /* o : pointer to time domain signal */ + Word16 *timeDomainOutput, /* o : pointer to time domain signal Qx*/ Word16 *olapBuffer, /* i/o : pointer to overlap buffer */ const PWord16 *olapWin, /* i : pointer to overlap window */ Word16 tcx_transition, @@ -2666,7 +2666,7 @@ void SynthesisSTFT( { FOR( i = 0; i < len; i++ ) { - olapBuffer[i] = round_fx_sat( L_shl_sat( fftBuffer[i], fftBufferExp - 15 ) ); + olapBuffer[i] = round_fx_sat( L_shl_sat( fftBuffer[i], fftBufferExp - 15 ) ); // Q(15 - fftBufferExp) move16(); } } @@ -2744,7 +2744,7 @@ void SynthesisSTFT( void SynthesisSTFT_ivas_fx( Word32 *fftBuffer, /* i : pointer to FFT bins */ Word16 fftBufferExp, /* i : exponent of FFT bins */ - Word16 *timeDomainOutput, /* o : pointer to time domain signal */ + Word16 *timeDomainOutput, /* o : pointer to time domain signal Qx*/ Word16 *olapBuffer, /* i/o : pointer to overlap buffer */ const PWord16 *olapWin, /* i : pointer to overlap window */ Word16 tcx_transition, @@ -2772,6 +2772,8 @@ void SynthesisSTFT_ivas_fx( /* Perform overlap-add */ /* Handle overlap in P/S domain for stereo */ + test(); + test(); IF( ( EQ_16( element_mode, IVAS_CPE_TD ) || EQ_16( element_mode, IVAS_CPE_DFT ) ) && EQ_16( nchan_out, 2 ) ) { Copy( olapBuffer + 3 * hFdCngCom->frameSize / 4 - ( M + 1 ), buf, hFdCngCom->frameSize + M + 1 ); @@ -2790,7 +2792,7 @@ void SynthesisSTFT_ivas_fx( { FOR( i = 0; i < len; i++ ) { - olapBuffer[i] = round_fx_sat( L_shl_sat( fftBuffer[i], fftBufferExp - 15 ) ); + olapBuffer[i] = round_fx_sat( L_shl_sat( fftBuffer[i], fftBufferExp - 15 ) ); // Q(15 - fftBufferExp) move16(); } } @@ -3290,12 +3292,12 @@ void FdCng_exc( Word16 *lsp_old, Word16 first_CNG, Word16 *lspCNG, - Word16 *Aq, /* o: LPC coeffs */ - Word16 *lsp_new, /* o: lsp */ - Word16 *lsf_new, /* o: lsf */ - Word16 *exc, /* o: LP excitation */ - Word16 *exc2, /* o: LP excitation */ - Word16 *bwe_exc /* o: LP excitation for BWE */ + Word16 *Aq, /* o: LPC coeffs Q12*/ + Word16 *lsp_new, /* o: lsp Q15 */ + Word16 *lsf_new, /* o: lsf Qlog2(2.56) */ + Word16 *exc, /* o: LP excitation Q12 */ + Word16 *exc2, /* o: LP excitation Q12 */ + Word16 *bwe_exc /* o: LP excitation for BWE Q12*/ ) { Word16 i; diff --git a/lib_com/ivas_prot_fx.h b/lib_com/ivas_prot_fx.h index 3123d4475..fea7eca61 100644 --- a/lib_com/ivas_prot_fx.h +++ b/lib_com/ivas_prot_fx.h @@ -299,17 +299,17 @@ void sns_compute_scf_fx( Word16 q ); void sns_interpolate_scalefactors_fx( - Word32 *scf_int, /* o : interpolated scalefactors for spectrum shaping */ - const Word32 *scf, /* i : sns scalefactors as derived from the signal or read from the bitstream */ - Word16 encoder_side /* i : flag, if scalefactors have to be inverted */ + Word32 *scf_int, /* o : interpolated scalefactors for spectrum shaping q16*/ + const Word32 *scf, /* i : sns scalefactors as derived from the signal or read from the bitstream Q16*/ + Word16 encoder_side /* i : flag, if scalefactors have to be inverted */ ); void sns_shape_spectrum_fx( - Word32 spectrum[], /* i/o: spectrum to be shaped */ + Word32 spectrum[], /* i/o: spectrum to be shaped Input Q is q_spectrum and ouput Q is (q_spectrum-1)*/ Word16 *q_spectrum, /* i/o: Q of spectrum */ const PsychoacousticParameters *pPsychParams, /* i : psychoacoustic parameters used to get the frequency bands */ const Word32 *scf_int, /* i : already interpolated SNS scalefactors */ - const Word16 q_scf_int, /* i : Q of interpolated SNS scalefactors */ + const Word16 q_scf_int, /* i : Q of interpolated SNS scalefactors q_scf_int*/ const Word16 L_frame, /* i : frame length */ Word16 *length ); @@ -323,10 +323,10 @@ void stereo_tca_enc_fx( ); void ECSQ_dequantize_vector_fx( - const Word16 *input, - const Word32 global_gain, + const Word16 *input, /*qx*/ + const Word32 global_gain, /*q15*/ const Word16 N, - Word32 *output ); + Word32 *output /*qx*/ ); void ECSQ_init_instance_fx( ECSQ_instance *ecsq_inst, @@ -682,12 +682,12 @@ Word16 masa_sq_fx( ); void ivas_compute_spar_params_enc_fx( - Word32 *cov_real_fx[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + Word32 *cov_real_fx[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], /*q_cov_real*/ Word16 *q_cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], - Word32 dm_fv_re_fx[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], + Word32 dm_fv_re_fx[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], /*q_dm_fv_re*/ Word16 *q_dm_fv_re, const Word16 i_ts, - Word32 ***mixer_mat_fx, + Word32 ***mixer_mat_fx, /*q_mixer_mat*/ Word16 *q_mixer_mat, const Word16 start_band, const Word16 end_band, @@ -698,18 +698,18 @@ void ivas_compute_spar_params_enc_fx( const Word16 active_w_vlbr, ivas_spar_md_com_cfg *hSparCfg, ivas_spar_md_t *hSparMd, - Word32 *pWscale, + Word32 *pWscale, /*q_Wscale*/ Word16 *q_Wscale, const Word16 from_dirac, const Word16 dyn_active_w_flag ); void ivas_compute_spar_params_fx( - Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], /*q_cov_real*/ Word16 q_cov_real, - Word32 dm_fv_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], + Word32 dm_fv_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], /*q_dm_fv_re*/ Word16 *q_dm_fv_re, const Word16 i_ts, - Word32 ***mixer_mat_fx, + Word32 ***mixer_mat_fx, /*q_mixer_mat*/ Word16 *q_mixer_mat, const Word16 start_band, const Word16 end_band, @@ -720,7 +720,7 @@ void ivas_compute_spar_params_fx( const Word16 active_w_vlbr, ivas_spar_md_com_cfg *hSparCfg, ivas_spar_md_t *hSparMd, - Word32 *pWscale_fx, + Word32 *pWscale_fx, /*q_pWscale*/ Word16 *q_pWscale, const Word16 from_dirac, const Word16 dyn_active_w_flag ); @@ -1681,7 +1681,7 @@ void ivas_fine_gain_pred_fx( const Word16 *R, /* i : Bits per sub band Q3 */ const Word16 num_sfm, /* i : Number of sub bands */ Word16 *xq, /* i/o: Quantized vector /quantized vector with finegain adj Q15*/ - Word16 *y, /* i/o: Quantized vector (int) */ + Word16 *y, /* i/o: Quantized vector (int) Q0*/ Word16 *fg_pred, /* o : Predicted fine gains Q12 */ const Word16 core /* i : Core */ ); @@ -2006,10 +2006,10 @@ Word16 set_ACELP_flag_IVAS( void ivas_calc_c_p_coeffs_enc_fx( ivas_spar_md_t *pSparMd, - Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], /*q_cov_real*/ Word16 *q_cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], const Word16 i_ts, - Word32 ***mixer_mat, + Word32 ***mixer_mat, /*q_mixer_mat*/ Word16 q_mixer_mat, const Word16 num_ch, const Word16 num_dmx, @@ -2020,10 +2020,10 @@ void ivas_calc_c_p_coeffs_enc_fx( void ivas_calc_c_p_coeffs_fx( ivas_spar_md_t *pSparMd, - Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], /*q_cov_real*/ Word16 q_cov_real, const Word16 i_ts, - Word32 ***mixer_mat, + Word32 ***mixer_mat, /*q_mixer_mat*/ Word16 q_mixer_mat, const Word16 num_ch, const Word16 num_dmx, @@ -4951,7 +4951,7 @@ void computeDiffuseness_fixed( void ivas_dirac_dec_get_response_fx( const Word16 azimuth, const Word16 elevation, - Word32 *response, + Word32 *response_fx, /*Q_out*/ const Word16 ambisonics_order, Word16 Q_out ); @@ -5308,11 +5308,11 @@ ivas_error ivas_spar_md_enc_open_fx( ); void ivas_create_fullr_dmx_mat_fx( - Word32 pred_coeffs_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], + Word32 pred_coeffs_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], /*q_pred_coeffs_re*/ Word16 q_pred_coeffs_re, - Word32 dm_fv_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], + Word32 dm_fv_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], /*q_dm_fv_re*/ Word16 q_dm_fv_re, - Word32 ***mixer_mat, + Word32 ***mixer_mat, /*q_mixer_mat*/ Word16 *q_mixer_mat, const Word16 in_chans, const Word16 start_band, @@ -5325,7 +5325,7 @@ void ivas_get_spar_md_from_dirac_fx( Word32 ele_dirac_fx[IVAS_MAX_NUM_BANDS][MAX_PARAM_SPATIAL_SUBFRAMES], // Q22 Word32 diffuseness_fx[IVAS_MAX_NUM_BANDS], // Q30 const Word16 n_ts, - Word32 ***mixer_mat_fx, + Word32 ***mixer_mat_fx, /*q_mixer_mat_fx*/ Word16 *q_mixer_mat_fx, ivas_spar_md_t *hSpar_md, ivas_spar_md_com_cfg *hSpar_md_cfg, diff --git a/lib_com/ivas_sba_config.c b/lib_com/ivas_sba_config.c index 3aebb59f5..424a95b5a 100644 --- a/lib_com/ivas_sba_config.c +++ b/lib_com/ivas_sba_config.c @@ -176,9 +176,11 @@ void ivas_sba_config_fx( *nSCE = 0; move16(); *nCPE = shr( *nchan_transport, 1 ); + move16(); IF( NE_16( i_mult( 2, ( *nCPE ) ), *nchan_transport ) ) { *nCPE = add( *nCPE, 1 ); + move16(); } *element_mode = IVAS_CPE_MDCT; move16(); @@ -302,7 +304,7 @@ Word16 ivas_sba_get_analysis_order_fx( sba_analysis_order = sba_order; move16(); - IF( LT_32( ivas_total_brate, SBA_MIN_BRATE_HOA ) ) + if ( LT_32( ivas_total_brate, SBA_MIN_BRATE_HOA ) ) { /* Hard coding the sba_analysis_order as 1 as higher not supported below SBA_MIN_BRATE_HOA bitrate */ sba_analysis_order = SBA_FOA_ORDER; @@ -321,6 +323,7 @@ Word16 ivas_sba_get_analysis_order_fx( *-------------------------------------------------------------------*/ /*! r: number of Ambisonic channels */ +#ifndef IVAS_FLOAT_FIXED int16_t ivas_sba_get_nchan( const int16_t sba_order, /* i : Ambisonic (SBA) order */ const int16_t sba_planar /* i : SBA planar flag */ @@ -339,7 +342,7 @@ int16_t ivas_sba_get_nchan( return ( nb_channels ); } -#ifdef IVAS_FLOAT_FIXED +#else Word16 ivas_sba_get_nchan_fx( const Word16 sba_order, /* i : Ambisonic (SBA) order */ const Word16 sba_planar /* i : SBA planar flag */ @@ -398,7 +401,7 @@ Word16 ivas_sba_get_nchan_metadata_fx( return ( nb_channels ); } -#endif +#else int16_t ivas_sba_get_nchan_metadata( const int16_t sba_order, /* i : Ambisonic (SBA) order */ const int32_t ivas_total_brate /* i : IVAS total bitrate */ @@ -426,7 +429,7 @@ int16_t ivas_sba_get_nchan_metadata( return ( nb_channels ); } - +#endif /*-------------------------------------------------------------------* * ivas_sba_get_spar_hoa_ch_ind() @@ -565,7 +568,7 @@ void ivas_sba_get_spar_hoa_md_flag_fx( *-------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED void ivas_sba_zero_vert_comp_fx( - Word32 *sba_data[], /* i : SBA signals */ + Word32 *sba_data[], /* i : SBA signals q_data */ const Word16 sba_order, /* i : SBA order */ const Word16 sba_planar, /* i : SBA planar flag */ const Word16 input_frame /* i : frame length */ diff --git a/lib_com/ivas_sns_com_fx.c b/lib_com/ivas_sns_com_fx.c index ff8fcd8aa..9a7a092b3 100644 --- a/lib_com/ivas_sns_com_fx.c +++ b/lib_com/ivas_sns_com_fx.c @@ -50,11 +50,11 @@ *-------------------------------------------------------------------*/ void sns_compute_scf_fx( - Word32 spectrum[], /* i : Spectrum (Q_in) */ + Word32 spectrum[], /* i : Spectrum Q_in */ const PsychoacousticParameters *pPsychParams, const Word16 L_frame, Word32 *scf, /* o : Scalefactors (Q16)*/ - Word16 q ) + Word16 Q_in ) { Word16 i, n, k; Word32 x[FDNS_NPTS], xs[FDNS_NPTS], mean, xl4[SNS_NPTS], nf, xl[FDNS_NPTS]; @@ -75,11 +75,11 @@ void sns_compute_scf_fx( move16(); const Word16 w_2 = 8192; // 0.25f ( 3.0f / 12.0f ) in Q15 move16(); - const Word16 w_3 = w_2; + const Word16 w_3 = w_2; // q15 move16(); - const Word16 w_4 = w_1; + const Word16 w_4 = w_1; // q15 move16(); - const Word16 w_5 = w_0; + const Word16 w_5 = w_0; // q15 move16(); assert( nBands == FDNS_NPTS ); @@ -138,7 +138,7 @@ void sns_compute_scf_fx( Word16 inv_bw; bw = (Word8) shr( L_frame, 6 ); move16(); - inv_bw = div_l( ONE_IN_Q16, bw ); // Q15 + inv_bw = div_l( ONE_IN_Q16 /*1 Q16*/, bw ); // Q15 FOR( i = 0; i < nBands; ++i ) { x[i] = Mpy_32_16_1( x[i], inv_bw ); // Q_in + (q_shift - 32) @@ -149,8 +149,8 @@ void sns_compute_scf_fx( { FOR( i = 0; i < nBands; ++i ) { - Word16 inv_bw = div_l( ONE_IN_Q16, bandLengths[i] ); // Q15 - x[i] = Mpy_32_16_1( x[i], inv_bw ); // Q_in + (q_shift - 32) + Word16 inv_bw = div_l( ONE_IN_Q16 /*1 Q16*/, bandLengths[i] ); // Q15 + x[i] = Mpy_32_16_1( x[i], inv_bw ); // Q_in + (q_shift - 32) move32(); } } @@ -196,7 +196,7 @@ void sns_compute_scf_fx( move64(); FOR( Word16 ind = 0; ind < FDNS_NPTS; ind++ ) { - sum = W_add( sum, (Word64) xs[ind] ); // Q_in + (q_shift - 32) + sum = W_add( sum, W_deposit32_l( xs[ind] ) ); // Q_in + (q_shift - 32) } mean = W_extract_l( W_shr( sum, 6 ) ); // Q_in + (q_shift - 32) @@ -216,8 +216,8 @@ void sns_compute_scf_fx( FOR( i = 0; i < FDNS_NPTS; i++ ) { Word16 e_tmp = norm_l( xs[i] ); - Word16 f_tmp = Log2_norm_lc( L_shl( xs[i], e_tmp ) ); - e_tmp = sub( sub( 34, e_tmp ), q ); + Word16 f_tmp = Log2_norm_lc( L_shl( xs[i], e_tmp ) ); /*Q16*/ + e_tmp = sub( sub( 34, e_tmp ), Q_in ); /* Note: Mpy_32_16 is used temporarily for this computation, It needs to be replaced with appropriate BASOP. */ xl[i] = Mpy_32_16( e_tmp, f_tmp, 16384 ); /* Q16 */ move32(); @@ -264,7 +264,7 @@ void sns_compute_scf_fx( move64(); FOR( Word16 ind = 0; ind < SNS_NPTS; ind++ ) { - sum = W_add( sum, (Word64) xl4[ind] ); // Q16 + sum = W_add( sum, W_deposit32_l( xl4[ind] ) ); // Q16 } mean = W_extract_l( W_shr( sum, 4 ) ); // Q16 @@ -284,8 +284,8 @@ void sns_compute_scf_fx( *-------------------------------------------------------------------*/ void sns_interpolate_scalefactors_fx( - Word32 *scf_int, /* o : interpolated scalefactors for spectrum shaping*/ - const Word32 *scf, /* i : sns scalefactors as derived from the signal or read from the bitstream */ + Word32 *scf_int, /* o : interpolated scalefactors for spectrum shaping q16*/ + const Word32 *scf, /* i : sns scalefactors as derived from the signal or read from the bitstream Q16*/ Word16 encoder_side /* i : flag, if scalefactors have to be inverted */ ) { @@ -294,34 +294,34 @@ void sns_interpolate_scalefactors_fx( Word16 exp; /* Interpolation */ - scf_int[0] = scf[0]; - scf_int[1] = scf[0]; + scf_int[0] = scf[0]; // q16 + scf_int[1] = scf[0]; // q16 move32(); move32(); FOR( n = 0; n <= M - 2; n++ ) { - scf_int[add( n * 4, 2 )] = Madd_32_16( scf[n], L_sub( scf[n + 1], scf[n] ), 4096 ); /* 4096 -> 1/8 in Q15 */ - scf_int[add( n * 4, 3 )] = Madd_32_16( scf[n], L_sub( scf[n + 1], scf[n] ), 12288 ); /* 12288 -> 3/8 in Q15 */ - scf_int[add( n * 4, 4 )] = Madd_32_16( scf[n], L_sub( scf[n + 1], scf[n] ), 20480 ); /* 20480 -> 5/8 in Q15 */ - scf_int[add( n * 4, 5 )] = Madd_32_16( scf[n], L_sub( scf[n + 1], scf[n] ), 28672 ); /* 28672 -> 7/8 in Q15 */ + scf_int[n * 4 + 2] = Madd_32_16( scf[n], L_sub( scf[n + 1], scf[n] ), 4096 /* 4096 -> 1/8 in Q15 */ ); // q16 + scf_int[n * 4 + 3] = Madd_32_16( scf[n], L_sub( scf[n + 1], scf[n] ), 12288 /* 12288 -> 3/8 in Q15 */ ); // q16 + scf_int[n * 4 + 4] = Madd_32_16( scf[n], L_sub( scf[n + 1], scf[n] ), 20480 /* 20480 -> 5/8 in Q15 */ ); // q16 + scf_int[n * 4 + 5] = Madd_32_16( scf[n], L_sub( scf[n + 1], scf[n] ), 28672 /* 28672 -> 7/8 in Q15 */ ); // q16 move32(); move32(); move32(); move32(); } - scf_int[FDNS_NPTS - 2] = Madd_32_16( scf[M - 1], L_sub( scf[M - 1], scf[M - 2] ), 4096 ); - scf_int[FDNS_NPTS - 1] = Madd_32_16( scf[M - 1], L_sub( scf[M - 1], scf[M - 2] ), 12288 ); + scf_int[FDNS_NPTS - 2] = Madd_32_16( scf[M - 1], L_sub( scf[M - 1], scf[M - 2] ), 4096 /* 4096 -> 1/8 in Q15 */ ); // q16 + scf_int[FDNS_NPTS - 1] = Madd_32_16( scf[M - 1], L_sub( scf[M - 1], scf[M - 2] ), 12288 /* 12288 -> 3/8 in Q15 */ ); // q16 move32(); move32(); /* Inversion at encoder-side */ - IF( encoder_side == ENC ) + IF( encoder_side == ENC /*0*/ ) { FOR( n = 0; n < FDNS_NPTS; n++ ) { - scf_int[n] = L_negate( scf_int[n] ); + scf_int[n] = L_negate( scf_int[n] ); // q16 move32(); } } @@ -329,9 +329,9 @@ void sns_interpolate_scalefactors_fx( /* Linear domain */ FOR( n = 0; n < FDNS_NPTS; n++ ) { - L_tmp = BASOP_util_Pow2( scf_int[n], Q15, &exp ); + L_tmp = BASOP_util_Pow2( scf_int[n], 15 /*31-Q16*/, &exp ); // Q=31-exp exp = sub( 15, exp ); - scf_int[n] = L_shr( L_tmp, exp ); + scf_int[n] = L_shr( L_tmp, exp ); // q16 move32(); } @@ -346,11 +346,11 @@ void sns_interpolate_scalefactors_fx( *-------------------------------------------------------------------*/ void sns_shape_spectrum_fx( - Word32 spectrum[], /* i/o: spectrum to be shaped */ + Word32 spectrum[], /* i/o: spectrum to be shaped Input Q is q_spectrum and ouput Q is (q_spectrum-1)*/ Word16 *q_spectrum, /* i/o: Q of spectrum */ const PsychoacousticParameters *pPsychParams, /* i : psychoacoustic parameters used to get the frequency bands */ const Word32 *scf_int, /* i : already interpolated SNS scalefactors */ - const Word16 q_scf_int, /* i : Q of interpolated SNS scalefactors */ + const Word16 q_scf_int, /* i : Q of interpolated SNS scalefactors q_scf_int*/ const Word16 L_frame, /* i : frame length */ Word16 *length ) { @@ -364,7 +364,7 @@ void sns_shape_spectrum_fx( IF( bandLengths == NULL ) { - bw = divide3216( shl( L_frame, 1 ), nBands ); + bw = divide3216( shl( L_frame, 1 ), nBands ); // q0 /* Shape spectrum */ k = 0; @@ -376,7 +376,7 @@ void sns_shape_spectrum_fx( L64_tmp[k] = W_mult_32_32( spectrum[k], scf_int[i] ); // Q = q_spectrum + q_scf_int + 1 move64(); shift = W_norm( L64_tmp[k] ); - IF( LT_16( shift, min_shift ) ) + if ( LT_16( shift, min_shift ) ) { min_shift = shift; move16(); @@ -398,9 +398,9 @@ void sns_shape_spectrum_fx( } FOR( k = 0; k < tmp_k; k++ ) { - L64_tmp[k] = W_shr( L64_tmp[k], sub( add( *q_spectrum, q_scf_int ), q_tmp ) ); + L64_tmp[k] = W_shr( L64_tmp[k], sub( add( *q_spectrum, q_scf_int ), q_tmp ) ); // Q = q_tmp+1 move64(); - spectrum[k] = W_sat_l( L64_tmp[k] ); // Q = q_tmp + spectrum[k] = W_sat_l( L64_tmp[k] ); // Q = q_tmp+1 move64(); } *q_spectrum = q_tmp; @@ -418,7 +418,8 @@ void sns_shape_spectrum_fx( L64_tmp[k] = W_mult_32_32( spectrum[k], scf_int[i] ); // Q = q_spectrum + q_scf_int + 1 move64(); shift = W_norm( L64_tmp[k] ); - IF( LT_16( shift, min_shift ) && NE_64( L64_tmp[k], 0 ) ) + test(); + if ( LT_16( shift, min_shift ) && NE_64( L64_tmp[k], 0 ) ) { min_shift = shift; move16(); @@ -440,9 +441,9 @@ void sns_shape_spectrum_fx( } FOR( k = 0; k < tmp_k; k++ ) { - L64_tmp[k] = W_shr( L64_tmp[k], sub( add( *q_spectrum, q_scf_int ), q_tmp ) ); + L64_tmp[k] = W_shr( L64_tmp[k], sub( add( *q_spectrum, q_scf_int ), q_tmp ) ); // q_tmp+1 move64(); - spectrum[k] = W_sat_l( L64_tmp[k] ); // Q = q_tmp + spectrum[k] = W_sat_l( L64_tmp[k] ); // Q = q_tmp+1 move64(); } *q_spectrum = q_tmp; diff --git a/lib_com/ivas_spar_com.c b/lib_com/ivas_spar_com.c index f70a74d6e..74d3c01d3 100644 --- a/lib_com/ivas_spar_com.c +++ b/lib_com/ivas_spar_com.c @@ -64,18 +64,18 @@ #define IVAS_REMIX_MULT_FAC ( 0.5f ) #define IVAS_ACTIVEW_DM_F ( 1.0f ) -#define IVAS_ACTIVEW_DM_F_Q30 ( ONE_IN_Q30 ) +#define IVAS_ACTIVEW_DM_F_Q30 ( ONE_IN_Q30 ) /*1 Q30*/ #define IVAS_ACTIVEW_DM_F_DTX ( 0.25f ) -#define IVAS_ACTIVEW_DM_F_DTX_Q30 ( 268435456 ) +#define IVAS_ACTIVEW_DM_F_DTX_Q30 ( 268435456 ) /*0.25 Q30*/ #define IVAS_ACTIVEW_DM_F_VLBR ( 0.25f ) -#define IVAS_ACTIVEW_DM_F_VLBR_Q30 ( 268435456 ) +#define IVAS_ACTIVEW_DM_F_VLBR_Q30 ( 268435456 ) /*0.25 Q30*/ #define IVAS_LIN_ACTIVEW_QUAD_ACTIVEW_THRESH ( 3.0f ) -#define IVAS_LIN_ACTIVEW_QUAD_ACTIVEW_THRESH_Q29 ( 1610612736 ) +#define IVAS_LIN_ACTIVEW_QUAD_ACTIVEW_THRESH_Q29 ( 1610612736 ) /*3 Q29*/ #define IVAS_P_NORM_SCALING ( 1.0f ) -#define IVAS_P_NORM_SCALING_FX ( ONE_IN_Q31 ) // Q31 +#define IVAS_P_NORM_SCALING_FX ( ONE_IN_Q31 ) // 1 Q31 #define IVAS_P_NORM_SCALING_DTX ( 0.75f ) -#define IVAS_P_NORM_SCALING_DTX_FX ( 1610612736 ) // Q31 +#define IVAS_P_NORM_SCALING_DTX_FX ( 1610612736 ) // 0.75 Q31 #define IVAS_MAT_DIM_3 ( 3 ) #define IVAS_MAT_DIM_2 ( 2 ) @@ -88,11 +88,11 @@ #ifdef IVAS_FLOAT_FIXED static void ivas_get_pred_coeffs_enc_fx( - Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], /*q_cov_real*/ Word16 *q_cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], - Word32 ppPred_coeffs_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], + Word32 ppPred_coeffs_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], /*q_pred_coeffs*/ Word16 *q_pred_coeffs, - Word32 ppDM_Fv_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], + Word32 ppDM_Fv_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], /*q_dm_fv_re*/ Word16 *q_dm_fv_re, const Word16 in_chans, const Word16 start_band, @@ -105,11 +105,11 @@ static void ivas_get_pred_coeffs_enc_fx( const Word16 res_ind ); static void ivas_get_Wscaling_factor_enc_fx( - Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], /*q_cov_real*/ Word16 *q_cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], - Word32 pred_coeffs_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], + Word32 pred_coeffs_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], /*q_pred_coeffs_re*/ Word16 q_pred_coeffs_re, - Word32 ***mixer_mat, + Word32 ***mixer_mat, /*q_mixer_mat*/ Word16 q_mixer_mat, const Word16 start_band, const Word16 end_band, @@ -119,24 +119,24 @@ static void ivas_get_Wscaling_factor_enc_fx( const Word16 bands_bw, const Word16 active_w, const Word16 active_w_vlbr, - Word32 *pWscale, + Word32 *pWscale, /*q_pWscale*/ Word16 *q_pWscale, const Word16 dyn_active_w_flag ); static void ivas_calc_post_pred_per_band_enc_fx( - Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], /*q_cov_real*/ Word16 *q_cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], - Word32 ***mixer_mat, + Word32 ***mixer_mat, /*q_mixer_mat*/ Word16 q_mixer_mat, const Word16 num_ch, const Word16 band_idx, - Word32 postpred_cov_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + Word32 postpred_cov_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], /*q_postpred_cov_re*/ Word16 *q_postpred_cov_re ); static void ivas_get_pred_coeffs_fx( - Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], - Word32 ppPred_coeffs_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], - Word32 ppDM_Fv_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], + Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], /*Q30*/ + Word32 ppPred_coeffs_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], /*q_pred_coeffs*/ + Word32 ppDM_Fv_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], /*q_dm_fv_re*/ const Word16 in_chans, const Word16 start_band, const Word16 end_band, @@ -148,11 +148,11 @@ static void ivas_get_pred_coeffs_fx( const Word16 res_ind, Word16 *q_pred_coeffs, Word16 *q_dm_fv_re ); -static void ivas_reorder_array_fx( Word32 in_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH][IVAS_MAX_NUM_BANDS], const Word16 in_chans, const Word16 order[IVAS_SPAR_MAX_CH], Word32 ***mixer_mat, const Word16 start_band, const Word16 end_band ); -static void ivas_get_Wscaling_factor_fx( Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], Word16 q_cov_real, Word32 pred_coeffs_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], Word16 q_pred_coeffs_re, Word32 ***mixer_mat, Word16 q_mixer_mat, const Word16 start_band, const Word16 end_band, const Word16 dtx_vad, const Word16 num_ch, const Word16 *pNum_dmx, const Word16 bands_bw, const Word16 active_w, const Word16 active_w_vlbr, Word32 *pWscale, Word16 *q_pWscale, const Word16 dyn_active_w_flag ); -static void ivas_calc_post_pred_per_band_fx( Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], Word16 q_cov_real, Word32 ***mixer_mat, Word16 q_mixer_mat, const Word16 num_ch, const Word16 band_idx, Word32 postpred_cov_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], Word16 *q_postpred_cov_re ); -static Word16 ivas_is_mat_inv_fx( Word32 in_re[MAX_MAT_DIM][MAX_MAT_DIM], Word16 q_in_re, const Word16 dim ); -static void ivas_calc_mat_inv_fx( Word32 in_re[MAX_MAT_DIM][MAX_MAT_DIM], Word16 q_in_re, const Word16 dim, Word32 out_re[MAX_MAT_DIM][MAX_MAT_DIM], Word16 *q_out_re ); +static void ivas_reorder_array_fx( Word32 in_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH][IVAS_MAX_NUM_BANDS] /*qx*/, const Word16 in_chans, const Word16 order[IVAS_SPAR_MAX_CH], Word32 ***mixer_mat /*qx*/, const Word16 start_band, const Word16 end_band ); +static void ivas_get_Wscaling_factor_fx( Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH] /*q_cov_real*/, Word16 q_cov_real, Word32 pred_coeffs_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS] /*q_pred_coeffs_re*/, Word16 q_pred_coeffs_re, Word32 ***mixer_mat /*q_mixer_mat*/, Word16 q_mixer_mat, const Word16 start_band, const Word16 end_band, const Word16 dtx_vad, const Word16 num_ch, const Word16 *pNum_dmx, const Word16 bands_bw, const Word16 active_w, const Word16 active_w_vlbr, Word32 *pWscale /*q_pWscale*/, Word16 *q_pWscale, const Word16 dyn_active_w_flag ); +static void ivas_calc_post_pred_per_band_fx( Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH] /*q_cov_real*/, Word16 q_cov_real, Word32 ***mixer_mat /*q_mixer_mat*/, Word16 q_mixer_mat, const Word16 num_ch, const Word16 band_idx, Word32 postpred_cov_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH] /*q_postpred_cov_re*/, Word16 *q_postpred_cov_re ); +static Word16 ivas_is_mat_inv_fx( Word32 in_re[MAX_MAT_DIM][MAX_MAT_DIM] /*q_in_re*/, Word16 q_in_re, const Word16 dim ); +static void ivas_calc_mat_inv_fx( Word32 in_re[MAX_MAT_DIM][MAX_MAT_DIM] /*q_in_re*/, Word16 q_in_re, const Word16 dim, Word32 out_re[MAX_MAT_DIM][MAX_MAT_DIM] /*q_out_re*/, Word16 *q_out_re ); #endif /*-----------------------------------------------------------------------------------------* @@ -323,13 +323,13 @@ void ivas_spar_config_fx( move16(); } - *nSCE = max( 0, sub( *nchan_transport, shl( *nCPE, 1 ) ) ); + *nSCE = s_max( 0, sub( *nchan_transport, shl( *nCPE, 1 ) ) ); move16(); IF( EQ_16( *nchan_transport, 1 ) ) { /* map SPAR SID bitrate to SPAR active bitrate */ - IF( EQ_32( ivas_total_brate, IVAS_SID_5k2 ) ) + if ( EQ_32( ivas_total_brate, IVAS_SID_5k2 ) ) { ivas_total_brate = IVAS_32k; move32(); @@ -439,7 +439,7 @@ Word16 ivas_get_spar_table_idx_fx( ( EQ_16( ivas_spar_br_table_consts[i].sba_order, sba_order ) ) ) { ind1[j] = i; - j = add( j, 1 ); + j++; move16(); } } @@ -459,7 +459,7 @@ Word16 ivas_get_spar_table_idx_fx( table_idx = ind1[ind2]; move16(); - IF( ind != NULL ) + if ( ind != NULL ) { *ind = ind2; move16(); @@ -525,11 +525,11 @@ Word16 ivas_get_sba_num_TCs_fx( *-----------------------------------------------------------------------------------------*/ static void ivas_get_pred_coeffs_enc_fx( - Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], /*q_cov_real*/ Word16 *q_cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], - Word32 ppPred_coeffs_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], + Word32 ppPred_coeffs_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], /*q_pred_coeffs*/ Word16 *q_pred_coeffs, - Word32 ppDM_Fv_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], + Word32 ppDM_Fv_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], /*q_dm_fv_re*/ Word16 *q_dm_fv_re, const Word16 in_chans, const Word16 start_band, @@ -573,7 +573,7 @@ static void ivas_get_pred_coeffs_enc_fx( set16_fx( q_pPred_temp, 31, IVAS_MAX_NUM_BANDS ); FOR( k = start_band; k < end_band; k++ ) { - div_factor[k] = BASOP_Util_Divide3232_Scale( ONE_IN_Q31, L_max( 1, cov_real[0][0][k] ), &s_div ); + div_factor[k] = BASOP_Util_Divide3232_Scale( ONE_IN_Q31 /*1 in q31*/, L_max( 1, cov_real[0][0][k] ), &s_div ); /*Q=15-(s_div-(31-q_cov_real))*/ move16(); div_factor_e[k] = sub( add( s_div, q_cov_real[0][0][k] ), 31 ); @@ -584,7 +584,7 @@ static void ivas_get_pred_coeffs_enc_fx( { FOR( k = start_band; k < end_band; k++ ) { - tmp64 = W_mult_32_16( cov_real[i + 1][0][k], div_factor[k] ); + tmp64 = W_mult_32_16( cov_real[i + 1][0][k], div_factor[k] ); /*q_cov_real+15-div_factor_e[k]+1*/ tmp_shift = W_norm( tmp64 ); IF( tmp64 != 0 ) { @@ -607,11 +607,11 @@ static void ivas_get_pred_coeffs_enc_fx( IF( GE_16( q_tmp, q_pPred_temp[k] ) ) { - abs_value = L_shr( abs_value, sub( q_tmp, q_pPred_temp[k] ) ); + abs_value = L_shr( abs_value, sub( q_tmp, q_pPred_temp[k] ) ); // q_tmp -> q_pPred_temp[k] } ELSE { - pPred_temp[k] = W_shr( pPred_temp[k], sub( q_pPred_temp[k], q_tmp ) ); + pPred_temp[k] = W_shr( pPred_temp[k], sub( q_pPred_temp[k], q_tmp ) ); // q_pPred_temp[k]->q_tmp move64(); q_pPred_temp[k] = q_tmp; move16(); @@ -626,13 +626,13 @@ static void ivas_get_pred_coeffs_enc_fx( { tmp_shift = W_norm( pPred_temp[k] ); e_tmp = sub( 31, sub( add( q_pPred_temp[k], tmp_shift ), 32 ) ); - L_tmp = Sqrt32( W_extract_h( W_shl( pPred_temp[k], tmp_shift ) ), &e_tmp ); + L_tmp = Sqrt32( W_extract_h( W_shl( pPred_temp[k], tmp_shift ) ), &e_tmp ); // Q=31-e_tmp - one_in_q = L_shl_sat( 1, sub( 31, e_tmp ) ); + one_in_q = L_shl_sat( 1, sub( 31, e_tmp ) ); // 1 in Q(31-e_tmp) IF( LT_32( one_in_q, L_tmp ) ) { - div_factor[k] = BASOP_Util_Divide3232_Scale( one_in_q, L_tmp, &s_div ); + div_factor[k] = BASOP_Util_Divide3232_Scale( one_in_q, L_tmp, &s_div ); // Q=15-s_div move16(); div_factor[k] = shl_sat( div_factor[k], s_div ); // Q = Q15 move16(); @@ -641,7 +641,7 @@ static void ivas_get_pred_coeffs_enc_fx( } ELSE { - div_factor[k] = ONE_IN_Q15 - 1; + div_factor[k] = ONE_IN_Q15 - 1; /*1 in Q15*/ move16(); div_factor_e[k] = 0; move16(); @@ -654,7 +654,7 @@ static void ivas_get_pred_coeffs_enc_fx( { FOR( k = start_band; k < end_band; k++ ) { - IF( NE_16( div_factor[k], ONE_IN_Q15 - 1 ) ) + IF( NE_16( div_factor[k], ONE_IN_Q15 - 1 /*1 in Q15*/ ) ) { ppPred_coeffs_re[i][k] = Mpy_32_16_1( ppPred_coeffs_re[i][k], div_factor[k] ); // Q = q_ppPred_coeffs_re[i][k] move32(); @@ -672,7 +672,7 @@ static void ivas_get_pred_coeffs_enc_fx( { FOR( k = start_band; k < end_band; k++ ) { - ppPred_coeffs_re[i][k] = L_shr( ppPred_coeffs_re[i][k], sub( q_ppPred_coeffs_re[i][k], tmp_shift ) ); + ppPred_coeffs_re[i][k] = L_shr( ppPred_coeffs_re[i][k], sub( q_ppPred_coeffs_re[i][k], tmp_shift ) ); // Q=tmp_shift move32(); } } @@ -702,12 +702,12 @@ static void ivas_get_pred_coeffs_enc_fx( IF( EQ_16( dyn_active_w_flag, 1 ) ) { - activew_quad_thresh = ONE_IN_Q29; + activew_quad_thresh = ONE_IN_Q29; /*1 in Q29*/ move32(); } ELSE { - activew_quad_thresh = IVAS_LIN_ACTIVEW_QUAD_ACTIVEW_THRESH_Q29; + activew_quad_thresh = IVAS_LIN_ACTIVEW_QUAD_ACTIVEW_THRESH_Q29; /*3.0f Q29*/ move32(); } g_th_sq = Mpy_32_32( activew_quad_thresh, activew_quad_thresh ); // Q27 @@ -734,7 +734,7 @@ static void ivas_get_pred_coeffs_enc_fx( } IF( LT_16( q_tmp, dm_alpha64_q[k] ) ) { - dm_alpha64[k] = W_add( W_shr( dm_alpha64[k], sub( dm_alpha64_q[k], q_tmp ) ), W_extract_h( W_shl( abs_value64, tmp_shift ) ) ); + dm_alpha64[k] = W_add( W_shr( dm_alpha64[k], sub( dm_alpha64_q[k], q_tmp ) ), W_extract_h( W_shl( abs_value64, tmp_shift ) ) ); // Q=q_tmp move64(); dm_alpha64_q[k] = q_tmp; move16(); @@ -744,7 +744,7 @@ static void ivas_get_pred_coeffs_enc_fx( tmp_shift = sub( add( q_tmp, sub( 32, tmp_shift ) ), dm_alpha64_q[k] ); IF( LT_16( tmp_shift, 63 ) ) { - dm_alpha64[k] = W_add( dm_alpha64[k], W_shr( abs_value64, tmp_shift ) ); + dm_alpha64[k] = W_add( dm_alpha64[k], W_shr( abs_value64, tmp_shift ) ); // Q=dm_alpha64_q[k] move64(); } } @@ -763,12 +763,12 @@ static void ivas_get_pred_coeffs_enc_fx( e_tmp = 0; move16(); } - dm_alpha[k] = Sqrt32( W_extract_h( W_shl( dm_alpha64[k], tmp_shift ) ), &e_tmp ); + dm_alpha[k] = Sqrt32( W_extract_h( W_shl( dm_alpha64[k], tmp_shift ) ), &e_tmp ); // Q=31-e_tmp move32(); dm_alpha64_q[k] = sub( 31, e_tmp ); move16(); - div_factor[k] = BASOP_Util_Divide3232_Scale( ONE_IN_Q31, L_max( dm_alpha[k], 1 ), &s_div ); + div_factor[k] = BASOP_Util_Divide3232_Scale( ONE_IN_Q31 /*1 Q31*/, L_max( dm_alpha[k], 1 ), &s_div ); // Q=15-(dm_alpha64_q[k]+ s_div-31) move16(); div_factor_e[k] = sub( add( dm_alpha64_q[k], s_div ), 31 ); @@ -779,7 +779,7 @@ static void ivas_get_pred_coeffs_enc_fx( { FOR( k = start_band; k < end_band; k++ ) { - tmp64 = W_mult_32_16( cov_real[i + 1][0][k], div_factor[k] ); + tmp64 = W_mult_32_16( cov_real[i + 1][0][k], div_factor[k] ); // Q=(15-div_factor_e[k]+q_cov_real[i+1][0][k])+1 tmp_shift = W_norm( tmp64 ); IF( tmp64 != 0 ) { @@ -800,19 +800,19 @@ static void ivas_get_pred_coeffs_enc_fx( IF( dtx_vad == 0 ) { - dm_f_local = IVAS_ACTIVEW_DM_F_DTX_Q30; + dm_f_local = IVAS_ACTIVEW_DM_F_DTX_Q30; // q30 move32(); } ELSE { IF( active_w_vlbr ) { - dm_f_local = IVAS_ACTIVEW_DM_F_VLBR_Q30; + dm_f_local = IVAS_ACTIVEW_DM_F_VLBR_Q30; // q30 move32(); } ELSE { - dm_f_local = IVAS_ACTIVEW_DM_F_Q30; + dm_f_local = IVAS_ACTIVEW_DM_F_Q30; // q30 move32(); } } @@ -827,7 +827,7 @@ static void ivas_get_pred_coeffs_enc_fx( FOR( k = 1; k < in_chans; k++ ) { // IVAS_RMULT_FLOAT( cov_real[j + 1][k][b], dm_v_re[k - 1][b], re ); - re = W_mult0_32_32( cov_real[j + 1][k][b], dm_v_re[k - 1][b] ); + re = W_mult0_32_32( cov_real[j + 1][k][b], dm_v_re[k - 1][b] ); // Q=q_cov_real[j+1][k][b]+dm_v_re_q[k-1][b] tmp_shift = W_norm( re ); IF( re != 0 ) { @@ -841,7 +841,7 @@ static void ivas_get_pred_coeffs_enc_fx( IF( LT_16( q_tmp, real64_q[j] ) ) { - real64[j] = W_add( W_shr( real64[j], sub( real64_q[j], q_tmp ) ), W_extract_h( W_shl( re, tmp_shift ) ) ); + real64[j] = W_add( W_shr( real64[j], sub( real64_q[j], q_tmp ) ), W_extract_h( W_shl( re, tmp_shift ) ) ); // Q=q_tmp move64(); real64_q[j] = q_tmp; move16(); @@ -851,7 +851,7 @@ static void ivas_get_pred_coeffs_enc_fx( tmp_shift = sub( add( q_tmp, sub( 32, tmp_shift ) ), real64_q[j] ); IF( LT_16( tmp_shift, 63 ) ) { - real64[j] = W_add( real64[j], W_shr( re, tmp_shift ) ); + real64[j] = W_add( real64[j], W_shr( re, tmp_shift ) ); // Q=real64_q[j] move64(); } } @@ -866,7 +866,7 @@ static void ivas_get_pred_coeffs_enc_fx( { // IVAS_RMULT_FLOAT( real[k], dm_v_re[k][b], re ); tmp_shift = W_norm( real64[k] ); - re = W_mult0_32_32( W_extract_h( W_shl( real64[k], tmp_shift ) ), dm_v_re[k][b] ); + re = W_mult0_32_32( W_extract_h( W_shl( real64[k], tmp_shift ) ), dm_v_re[k][b] ); // Q=(real64[k]+tmp_shift-32)+dm_v_re_q q_tmp = sub( add( add( real64_q[k], dm_v_re_q[k][b] ), tmp_shift ), 32 ); tmp_shift = W_norm( re ); IF( re != 0 ) @@ -881,7 +881,7 @@ static void ivas_get_pred_coeffs_enc_fx( IF( LT_16( q_tmp, dm_beta_re_q ) ) { - tmp64 = W_add( W_shr( tmp64, sub( dm_beta_re_q, q_tmp ) ), W_extract_h( W_shl( re, tmp_shift ) ) ); + tmp64 = W_add( W_shr( tmp64, sub( dm_beta_re_q, q_tmp ) ), W_extract_h( W_shl( re, tmp_shift ) ) ); // Q=q_tmp dm_beta_re_q = q_tmp; move16(); } @@ -890,12 +890,12 @@ static void ivas_get_pred_coeffs_enc_fx( tmp_shift = sub( add( q_tmp, sub( 32, tmp_shift ) ), dm_beta_re_q ); IF( LT_16( tmp_shift, 63 ) ) { - tmp64 = W_add( tmp64, W_shr( re, tmp_shift ) ); + tmp64 = W_add( tmp64, W_shr( re, tmp_shift ) ); // Q=dm_beta_re_q } } } tmp_shift = W_norm( tmp64 ); - dm_beta_re = W_extract_h( W_shl( tmp64, tmp_shift ) ); + dm_beta_re = W_extract_h( W_shl( tmp64, tmp_shift ) ); // Q=dm_beta_re_q+tmp_shift-32 IF( tmp64 != 0 ) { dm_beta_re_q = sub( add( dm_beta_re_q, tmp_shift ), 32 ); @@ -908,7 +908,7 @@ static void ivas_get_pred_coeffs_enc_fx( dm_w = cov_real[0][0][b]; // q_cov_real[0][0][b] move32(); - den_f = L_max( dm_w, 1 ); + den_f = L_max( dm_w, 1 ); // q_cov_real[0][0][b] passive_g = L_deposit_l( BASOP_Util_Divide3232_Scale( dm_alpha[b], den_f, &s_div ) ); // dm_alpha64_q[b] - q_cov_real[0][0][b] + 15 - s_div div_shift = sub( Q29, add( sub( dm_alpha64_q[b], q_cov_real[0][0][b] ), sub( 15, s_div ) ) ); @@ -929,16 +929,16 @@ static void ivas_get_pred_coeffs_enc_fx( dm_v_re_q[i][b] = 31; move16(); } - dm_v_re[res_ind - 1][b] = MAX_32; + dm_v_re[res_ind - 1][b] = MAX_32; /*1 Q31*/ move32(); dm_v_re_q[i][b] = 31; move16(); - passive_g = activew_quad_thresh; + passive_g = activew_quad_thresh; // q29 move32(); } - IF( LT_32( passive_g, activew_quad_thresh ) ) + IF( LT_32( passive_g, activew_quad_thresh ) ) // q29 { /*linear activeW*/ dm_y = 0; @@ -950,30 +950,30 @@ static void ivas_get_pred_coeffs_enc_fx( { IF( GT_16( q_tmp, q_cov_real[k][k][b] ) ) { - dm_y = W_add( W_shr( dm_y, sub( q_tmp, q_cov_real[k][k][b] ) ), cov_real[k][k][b] ); + dm_y = W_add( W_shr( dm_y, sub( q_tmp, q_cov_real[k][k][b] ) ), cov_real[k][k][b] ); // q_cov_real[k][k][b] q_tmp = q_cov_real[k][k][b]; move16(); } ELSE { - dm_y = W_add( dm_y, L_shr( cov_real[k][k][b], sub( q_cov_real[k][k][b], q_tmp ) ) ); + dm_y = W_add( dm_y, L_shr( cov_real[k][k][b], sub( q_cov_real[k][k][b], q_tmp ) ) ); // q_tmp } } - tmp64 = W_mult0_32_32( w_norm_fac, dm_w ); + tmp64 = W_mult0_32_32( w_norm_fac, dm_w ); // Q=q_tmp IF( LT_16( q_tmp, q_cov_real[0][0][b] ) ) { - tmp64 = W_shr( tmp64, sub( q_cov_real[0][0][b], q_tmp ) ); + tmp64 = W_shr( tmp64, sub( q_cov_real[0][0][b], q_tmp ) ); // Q=q_tmp } ELSE { q_tmp = q_cov_real[0][0][b]; move16(); - dm_y = W_shr( dm_y, sub( q_tmp, q_cov_real[0][0][b] ) ); + dm_y = W_shr( dm_y, sub( q_tmp, q_cov_real[0][0][b] ) ); // Q=q_cov_real[0][0][b] } if ( GT_64( tmp64, dm_y ) ) { - dm_y = tmp64; + dm_y = tmp64; // Q=q_tmp move16(); } @@ -989,7 +989,7 @@ static void ivas_get_pred_coeffs_enc_fx( den_f = W_extract_h( W_shl( dm_y, tmp_shift ) ); // q_tmp + tmp_shift - 32 } - den_f = L_max( den_f, 1 ); + den_f = L_max( den_f, 1 ); // q_tmp + tmp_shift - 32 DM_F[b] = L_deposit_l( BASOP_Util_Divide3232_Scale( Mpy_32_32( dm_f_local, dm_alpha[b] ), den_f, &s_div ) ); // Q30 + dm_alpha64_q[b] - 31 - q_tmp - tmp_shift + 32 + 15 - s_div move32(); @@ -997,15 +997,15 @@ static void ivas_get_pred_coeffs_enc_fx( DM_F_q[b] = add( sub( sub( dm_alpha64_q[b], add( q_tmp, tmp_shift ) ), s_div ), ( 30 - 31 + 32 + 15 ) ); move16(); - IF( LT_32( ONE_IN_Q30, L_shl_sat( DM_F[b], sub( Q30, DM_F_q[b] ) ) ) ) + IF( LT_32( ONE_IN_Q30, L_shl_sat( DM_F[b], sub( Q30, DM_F_q[b] ) ) ) ) // q30 { - DM_F[b] = ONE_IN_Q31; + DM_F[b] = ONE_IN_Q31; /*1 Q31*/ move32(); DM_F_q[b] = Q31; move16(); } - tmp64 = W_mult0_32_32( DM_F[b], DM_F[b] ); + tmp64 = W_mult0_32_32( DM_F[b], DM_F[b] ); /*Q=(2*DM_F_q[b])*/ tmp_shift = W_norm( tmp64 ); IF( tmp64 == 0 ) { @@ -1014,7 +1014,7 @@ static void ivas_get_pred_coeffs_enc_fx( } ELSE { - tmp64 = W_shl( tmp64, tmp_shift ); + tmp64 = W_shl( tmp64, tmp_shift ); /*Q=(2*DM_F_q[b]+tmp_shift)*/ } tmp64 = W_mult0_32_32( W_extract_h( tmp64 ), dm_beta_re ); // 2 * DM_F_q[b] + tmp_shift - 32 + dm_beta_re_q q_tmp = sub( add( add( shl( DM_F_q[b], 1 ), tmp_shift ), dm_beta_re_q ), 32 ); @@ -1026,12 +1026,12 @@ static void ivas_get_pred_coeffs_enc_fx( } ELSE { - tmp64 = W_shl( tmp64, tmp_shift ); + tmp64 = W_shl( tmp64, tmp_shift ); // Q=q_tmp+tmp_shift } - L_tmp2 = W_extract_h( tmp64 ); + L_tmp2 = W_extract_h( tmp64 ); // Q=q_tmp+tmp_shift-32 L_tmp2_q = sub( add( q_tmp, tmp_shift ), 32 ); - tmp64 = W_shl( W_mult0_32_32( dm_alpha[b], DM_F[b] ), 1 ); + tmp64 = W_shl( W_mult0_32_32( dm_alpha[b], DM_F[b] ), 1 ); // Q=dm_alpha64_q[b]+DM_F_q[b] tmp_shift = sub( W_norm( tmp64 ), 2 ); IF( tmp64 == 0 ) { @@ -1040,40 +1040,40 @@ static void ivas_get_pred_coeffs_enc_fx( } ELSE { - tmp64 = W_shl( tmp64, tmp_shift ); + tmp64 = W_shl( tmp64, tmp_shift ); // Q=dm_alpha64_q[b]+DM_F_q[b]+tmp_shift } L_tmp1 = W_extract_h( tmp64 ); // DM_F_q[b] + dm_alpha64_q[b] + tmp_shift - 32 L_tmp1_q = sub( add( add( DM_F_q[b], dm_alpha64_q[b] ), tmp_shift ), 32 ); IF( LT_16( L_tmp2_q, L_tmp1_q ) ) { - L_tmp1 = L_add( L_shr( L_tmp1, sub( L_tmp1_q, L_tmp2_q ) ), L_tmp2 ); + L_tmp1 = L_add( L_shr( L_tmp1, sub( L_tmp1_q, L_tmp2_q ) ), L_tmp2 ); // Q=L_tmp2_q L_tmp1_q = L_tmp2_q; move16(); } ELSE { - L_tmp1 = L_add( L_tmp1, L_shr( L_tmp2, sub( L_tmp2_q, L_tmp1_q ) ) ); + L_tmp1 = L_add( L_tmp1, L_shr( L_tmp2, sub( L_tmp2_q, L_tmp1_q ) ) ); // Q=L_tmp1_q } tmp_shift = sub( norm_l( dm_w ), 1 ); - L_tmp2 = L_shl( dm_w, tmp_shift ); + L_tmp2 = L_shl( dm_w, tmp_shift ); // Q=q_cov_real[0][0][b]+ tmp_shift L_tmp2_q = add( q_cov_real[0][0][b], tmp_shift ); IF( LT_16( L_tmp2_q, L_tmp1_q ) ) { - den_f = L_add( L_shr( L_tmp1, sub( L_tmp1_q, L_tmp2_q ) ), L_tmp2 ); + den_f = L_add( L_shr( L_tmp1, sub( L_tmp1_q, L_tmp2_q ) ), L_tmp2 ); // Q=L_tmp2_q den_f_e = sub( 31, L_tmp2_q ); } ELSE { - den_f = L_add( L_tmp1, L_shr( L_tmp2, sub( L_tmp2_q, L_tmp1_q ) ) ); + den_f = L_add( L_tmp1, L_shr( L_tmp2, sub( L_tmp2_q, L_tmp1_q ) ) ); // Q=L_tmp2_q den_f_e = sub( 31, L_tmp1_q ); } - den_f = L_max( den_f, 1 ); + den_f = L_max( den_f, 1 ); // Q=31-den_f_e - tmp64 = W_mult0_32_32( DM_F[b], dm_beta_re ); + tmp64 = W_mult0_32_32( DM_F[b], dm_beta_re ); // Q= DM_F_q[b]+dm_beta_re_q tmp_shift = sub( W_norm( tmp64 ), 1 ); IF( tmp64 == 0 ) { @@ -1082,23 +1082,23 @@ static void ivas_get_pred_coeffs_enc_fx( } ELSE { - tmp64 = W_shl( tmp64, tmp_shift ); + tmp64 = W_shl( tmp64, tmp_shift ); // Q= DM_F_q[b]+dm_beta_re_q+tmp_shift } L_tmp2_q = sub( add( add( DM_F_q[b], dm_beta_re_q ), tmp_shift ), 32 ); - L_tmp2 = W_extract_h( tmp64 ); + L_tmp2 = W_extract_h( tmp64 ); // Q= DM_F_q[b]+dm_beta_re_q+tmp_shift-32 tmp_shift = sub( norm_l( dm_alpha[b] ), 1 ); IF( LT_16( L_tmp2_q, add( dm_alpha64_q[b], tmp_shift ) ) ) { - L_tmp1 = L_add( L_shr( dm_alpha[b], sub( dm_alpha64_q[b], L_tmp2_q ) ), L_tmp2 ); + L_tmp1 = L_add( L_shr( dm_alpha[b], sub( dm_alpha64_q[b], L_tmp2_q ) ), L_tmp2 ); // Q=L_tmp2_q L_tmp1_q = L_tmp2_q; move16(); } ELSE { L_tmp1_q = add( dm_alpha64_q[b], tmp_shift ); - L_tmp1 = L_add( L_shl( dm_alpha[b], tmp_shift ), L_shr( L_tmp2, sub( L_tmp2_q, L_tmp1_q ) ) ); + L_tmp1 = L_add( L_shl( dm_alpha[b], tmp_shift ), L_shr( L_tmp2, sub( L_tmp2_q, L_tmp1_q ) ) ); // Q=L_tmp1_q } dm_g[b] = L_deposit_l( BASOP_Util_Divide3232_Scale( L_tmp1, den_f, &s_div ) ); // L_tmp1_q - (31 - den_f_e) + (15 - s_div) @@ -1113,7 +1113,7 @@ static void ivas_get_pred_coeffs_enc_fx( Word16 num_f_e; /* quadratic activeW */ - tmp64 = W_shl( W_mult0_32_32( dm_alpha[b], activew_quad_thresh ), 1 ); + tmp64 = W_shl( W_mult0_32_32( dm_alpha[b], activew_quad_thresh ), 1 ); // Q=dm_alpha64_q[b]+29 tmp_shift = sub( W_norm( tmp64 ), 1 ); IF( tmp64 == 0 ) { @@ -1122,31 +1122,31 @@ static void ivas_get_pred_coeffs_enc_fx( } ELSE { - tmp64 = W_shl( tmp64, tmp_shift ); + tmp64 = W_shl( tmp64, tmp_shift ); // Q=dm_alpha64_q+29+tmp_shift } - L_tmp1 = W_extract_h( tmp64 ); // Q29 + dm_alpha64_q[b] + tmp_shift - 32 - L_tmp1_q = sub( add( add( Q29, dm_alpha64_q[b] ), tmp_shift ), 32 ); + L_tmp1 = W_extract_h( tmp64 ); // Q29 + dm_alpha64_q[b] + tmp_shift - 32 + L_tmp1_q = sub( add( add( Q29, dm_alpha64_q[b] ), tmp_shift ), 32 ); // Q=dm_alpha64_q+29+1+tmp_shift-32 - num_f = BASOP_Util_Add_Mant32Exp( dm_beta_re, sub( 31, dm_beta_re_q ), L_negate( L_tmp1 ), sub( 31, L_tmp1_q ), &num_f_e ); + num_f = BASOP_Util_Add_Mant32Exp( dm_beta_re, sub( 31, dm_beta_re_q ), L_negate( L_tmp1 ), sub( 31, L_tmp1_q ), &num_f_e ); // Q=31-num_f_e - sqrt_val = Mpy_32_32( Mpy_32_32( dm_alpha[b], dm_alpha[b] ), g_th_sq ); + sqrt_val = Mpy_32_32( Mpy_32_32( dm_alpha[b], dm_alpha[b] ), g_th_sq ); //((2*dm_alpha64_q[b]-31)+27-31)-2 ,reducing the Q by 2 instead of multiplication by 4 val_e = sub( 31, sub( sub( add( sub( shl( dm_alpha64_q[b], 1 ), 31 ), 27 ), 31 ), 2 ) ); // reducing the Q by 2 instead of multiplication by 4 move16(); - sqrt_val = BASOP_Util_Add_Mant32Exp( sqrt_val, val_e, Mpy_32_32( dm_beta_re, dm_beta_re ), sub( 31, sub( shl( dm_beta_re_q, 1 ), 31 ) ), &val_e ); - sqrt_val = BASOP_Util_Add_Mant32Exp( sqrt_val, val_e, L_negate( Mpy_32_32( Mpy_32_32( dm_beta_re, g_th_sq ), dm_w ) ), sub( 31, sub( sub( add( sub( add( dm_beta_re_q, 27 ), 31 ), q_cov_real[0][0][b] ), 31 ), 2 ) ), &val_e ); // reducing the Q by 2 instead of multiplication by 4 + sqrt_val = BASOP_Util_Add_Mant32Exp( sqrt_val, val_e, Mpy_32_32( dm_beta_re, dm_beta_re ), sub( 31, sub( shl( dm_beta_re_q, 1 ), 31 ) ), &val_e ); // q=31-val_e + sqrt_val = BASOP_Util_Add_Mant32Exp( sqrt_val, val_e, L_negate( Mpy_32_32( Mpy_32_32( dm_beta_re, g_th_sq ), dm_w ) ), sub( 31, sub( sub( add( sub( add( dm_beta_re_q, 27 ), 31 ), q_cov_real[0][0][b] ), 31 ), 2 ) ) /* reducing the Q by 2 instead of multiplication by 4*/, &val_e ); // q=31-val_e // val_e = norm_l( sqrt_val ); - sqrt_val = Sqrt32( sqrt_val, &val_e ); + sqrt_val = Sqrt32( sqrt_val, &val_e ); // q=31-val_e - num_f = BASOP_Util_Add_Mant32Exp( num_f, num_f_e, sqrt_val, val_e, &num_f_e ); + num_f = BASOP_Util_Add_Mant32Exp( num_f, num_f_e, sqrt_val, val_e, &num_f_e ); // q=31-num_f_e - den_f = Mpy_32_32( dm_beta_re, g_th_sq ); + den_f = Mpy_32_32( dm_beta_re, g_th_sq ); // Q=dm_beta_re_q+27-31-1 den_f_e = add( add( sub( 31, dm_beta_re_q ), 4 ), 1 ); // adding the exp with 1 instead of multiplication by 2 - den_f = L_max( den_f, 1 ); - dm_g[b] = activew_quad_thresh; // Q29 + den_f = L_max( den_f, 1 ); // q=31-den_f_e + dm_g[b] = activew_quad_thresh; // Q29 move32(); dm_g_q[b] = Q29; move16(); - DM_F[b] = BASOP_Util_Divide3232_Scale_cadence( Mpy_32_32( dm_g[b], num_f ), den_f, &s_dm_f ); + DM_F[b] = BASOP_Util_Divide3232_Scale_cadence( Mpy_32_32( dm_g[b], num_f ), den_f, &s_dm_f ); // Q=(31-(s_dm_f+2+num_f_e-den_f_e)) move32(); DM_F_q[b] = sub( 31, add( s_dm_f, sub( add( 2, num_f_e ), den_f_e ) ) ); move16(); @@ -1162,7 +1162,7 @@ static void ivas_get_pred_coeffs_enc_fx( { FOR( b = start_band; b < end_band; b++ ) { - tmp64 = W_mult0_32_32( dm_v_re[i][b], dm_g[b] ); + tmp64 = W_mult0_32_32( dm_v_re[i][b], dm_g[b] ); // dm_v_re_q[i][b]+dm_g_q[b] tmp_shift = W_norm( tmp64 ); IF( tmp64 == 0 ) { @@ -1171,14 +1171,14 @@ static void ivas_get_pred_coeffs_enc_fx( } ELSE { - tmp64 = W_shl( tmp64, tmp_shift ); + tmp64 = W_shl( tmp64, tmp_shift ); // dm_v_re_q[i][b]+dm_g_q[b]+tmp_shift } ppPred_coeffs_re[i][b] = W_extract_h( tmp64 ); // Q = dm_v_re_q[i][b] + dm_g_q[b] + tmp_shift - 32 move32(); q_ppPred_coeffs_re[i][b] = sub( add( add( dm_v_re_q[i][b], dm_g_q[b] ), tmp_shift ), 32 ); move16(); - tmp64 = W_mult0_32_32( dm_v_re[i][b], DM_F[b] ); + tmp64 = W_mult0_32_32( dm_v_re[i][b], DM_F[b] ); // Q = dm_v_re_q[i][b] + DM_F_q[b] tmp_shift = W_norm( tmp64 ); IF( tmp64 == 0 ) { @@ -1187,7 +1187,7 @@ static void ivas_get_pred_coeffs_enc_fx( } ELSE { - tmp64 = W_shl( tmp64, tmp_shift ); + tmp64 = W_shl( tmp64, tmp_shift ); // Q = dm_v_re_q[i][b] + DM_F_q[b] + tmp_shift } ppDM_Fv_re[i][b] = W_extract_h( tmp64 ); // Q = dm_v_re_q[i][b] + DM_F_q[b] + tmp_shift - 32 move32(); @@ -1204,9 +1204,9 @@ static void ivas_get_pred_coeffs_enc_fx( { FOR( b = start_band; b < end_band; b++ ) { - ppPred_coeffs_re[i][b] = L_shr( ppPred_coeffs_re[i][b], sub( q_ppPred_coeffs_re[i][b], *q_pred_coeffs ) ); + ppPred_coeffs_re[i][b] = L_shr( ppPred_coeffs_re[i][b], sub( q_ppPred_coeffs_re[i][b], *q_pred_coeffs ) ); // Q=*q_pred_coeffs move32(); - ppDM_Fv_re[i][b] = L_shr( ppDM_Fv_re[i][b], sub( dm_v_re_q[i][b], *q_dm_fv_re ) ); + ppDM_Fv_re[i][b] = L_shr( ppDM_Fv_re[i][b], sub( dm_v_re_q[i][b], *q_dm_fv_re ) ); // Q=*q_dm_fv_re move32(); } } @@ -1216,9 +1216,9 @@ static void ivas_get_pred_coeffs_enc_fx( } static void ivas_get_pred_coeffs_fx( - Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], - Word32 ppPred_coeffs_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], - Word32 ppDM_Fv_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], + Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], /*Q30*/ + Word32 ppPred_coeffs_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], /*q_pred_coeffs*/ + Word32 ppDM_Fv_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], /*q_dm_fv_re*/ const Word16 in_chans, const Word16 start_band, const Word16 end_band, @@ -1241,12 +1241,12 @@ static void ivas_get_pred_coeffs_fx( IF( EQ_16( from_dirac, 1 ) ) { - w_norm_fac = ONE_IN_Q29; + w_norm_fac = ONE_IN_Q29; /*1 q29*/ move32(); } ELSE { - w_norm_fac = 3 * ONE_IN_Q29; + w_norm_fac = 3 * ONE_IN_Q29; /* 3 q29*/ move32(); } tmp_shift = Q30; @@ -1261,13 +1261,13 @@ static void ivas_get_pred_coeffs_fx( set32_fx( pPred_temp, 0, IVAS_MAX_NUM_BANDS ); FOR( k = start_band; k < end_band; k++ ) { - div_factor[k] = L_max( 1, cov_real[0][0][k] ); + div_factor[k] = L_max( 1, cov_real[0][0][k] ); // q30 move32(); tmp_shift = Q30; move16(); - IF( NE_32( cov_real[0][0][k], ONE_IN_Q30 ) ) + IF( NE_32( cov_real[0][0][k], ONE_IN_Q30 ) ) // q30 { - div_factor[k] = L_deposit_l( BASOP_Util_Divide3232_Scale( ONE_IN_Q31, div_factor[k], &s_div ) ); + div_factor[k] = L_deposit_l( BASOP_Util_Divide3232_Scale( ONE_IN_Q31 /*1 q31*/, div_factor[k], &s_div ) ); // Q=15-(s_div-(31-30)) move32(); IF( s_div < 0 ) { @@ -1288,7 +1288,7 @@ static void ivas_get_pred_coeffs_fx( { FOR( p = start_band; p < k; p++ ) { - div_factor[p] = L_shr( div_factor[p], sub( prev_tmp_shift, tmp_shift ) ); + div_factor[p] = L_shr( div_factor[p], sub( prev_tmp_shift, tmp_shift ) ); // tmp_shift move32(); } prev_tmp_shift = tmp_shift; @@ -1296,7 +1296,7 @@ static void ivas_get_pred_coeffs_fx( } ELSE IF( GT_16( tmp_shift, prev_tmp_shift ) ) { - div_factor[k] = L_shr( div_factor[k], sub( tmp_shift, prev_tmp_shift ) ); + div_factor[k] = L_shr( div_factor[k], sub( tmp_shift, prev_tmp_shift ) ); // prev_tmp_shift move32(); tmp_shift = prev_tmp_shift; move16(); @@ -1324,7 +1324,7 @@ static void ivas_get_pred_coeffs_fx( FOR( k = start_band; k < end_band; k++ ) { q_pred_temp = sub( 31, sub( shl( *q_pred_coeffs, 1 ), 31 ) ); - pPred_temp[k] = Sqrt32( pPred_temp[k], &q_pred_temp ); + pPred_temp[k] = Sqrt32( pPred_temp[k], &q_pred_temp ); // q=31-q_pred_temp move32(); IF( LT_16( q_pred_temp, 1 ) ) @@ -1342,14 +1342,14 @@ static void ivas_get_pred_coeffs_fx( move16(); } - one_in_q = L_shl( 1, sub( 31, q_pred_temp ) ); + one_in_q = L_shl( 1, sub( 31, q_pred_temp ) ); /*Q=q_pred_temp*/ IF( LT_32( one_in_q, pPred_temp[k] ) ) { - div_factor[k] = pPred_temp[k]; + div_factor[k] = pPred_temp[k]; /*Q=q_pred_temp*/ move32(); - div_factor[k] = L_deposit_l( BASOP_Util_Divide3232_Scale( one_in_q, div_factor[k], &s_div ) ); + div_factor[k] = L_deposit_l( BASOP_Util_Divide3232_Scale( one_in_q, div_factor[k], &s_div ) ); // q=15-s_div move32(); IF( s_div < 0 ) { @@ -1368,7 +1368,7 @@ static void ivas_get_pred_coeffs_fx( } ELSE { - div_factor[k] = one_in_q; + div_factor[k] = one_in_q; // q=31-q_pred_temp move32(); tmp_shift = sub( 31, q_pred_temp ); } @@ -1377,7 +1377,7 @@ static void ivas_get_pred_coeffs_fx( { FOR( p = start_band; p < k; p++ ) { - div_factor[p] = L_shr( div_factor[p], sub( prev_tmp_shift, tmp_shift ) ); + div_factor[p] = L_shr( div_factor[p], sub( prev_tmp_shift, tmp_shift ) ); // q=tmp_shift move32(); } prev_tmp_shift = tmp_shift; @@ -1385,7 +1385,7 @@ static void ivas_get_pred_coeffs_fx( } ELSE IF( GT_16( tmp_shift, prev_tmp_shift ) ) { - div_factor[k] = L_shr( div_factor[k], sub( tmp_shift, prev_tmp_shift ) ); + div_factor[k] = L_shr( div_factor[k], sub( tmp_shift, prev_tmp_shift ) ); // q=prev_tmp_shift move32(); tmp_shift = prev_tmp_shift; move16(); @@ -1427,12 +1427,12 @@ static void ivas_get_pred_coeffs_fx( IF( EQ_16( dyn_active_w_flag, 1 ) ) { - activew_quad_thresh = ONE_IN_Q29; + activew_quad_thresh = ONE_IN_Q29; // 1 q29 move32(); } ELSE { - activew_quad_thresh = IVAS_LIN_ACTIVEW_QUAD_ACTIVEW_THRESH_Q29; + activew_quad_thresh = IVAS_LIN_ACTIVEW_QUAD_ACTIVEW_THRESH_Q29; // 3 q29 move32(); } g_th_sq = Mpy_32_32( activew_quad_thresh, activew_quad_thresh ); // Q27 @@ -1453,13 +1453,13 @@ static void ivas_get_pred_coeffs_fx( FOR( k = start_band; k < end_band; k++ ) { dm_alpha_e = 31 - Q29; - dm_alpha[k] = Sqrt32( dm_alpha[k], &dm_alpha_e ); + dm_alpha[k] = Sqrt32( dm_alpha[k], &dm_alpha_e ); // q=31-dm_alpha_e move32(); - div_factor[k] = L_max( dm_alpha[k], 1 ); + div_factor[k] = L_max( dm_alpha[k], 1 ); // q=31-dm_alpha_e move32(); - div_factor[k] = L_deposit_l( BASOP_Util_Divide3232_Scale( ONE_IN_Q31, div_factor[k], &s_div ) ); + div_factor[k] = L_deposit_l( BASOP_Util_Divide3232_Scale( ONE_IN_Q31, div_factor[k], &s_div ) ); // q=15-(s_div+(0-dm_alpha_e)) move32(); IF( s_div < 0 ) { @@ -1480,7 +1480,7 @@ static void ivas_get_pred_coeffs_fx( { FOR( p = start_band; p < k; p++ ) { - div_factor[p] = L_shr( div_factor[p], sub( prev_tmp_shift, tmp_shift ) ); + div_factor[p] = L_shr( div_factor[p], sub( prev_tmp_shift, tmp_shift ) ); // q=tmp_shift move32(); } prev_tmp_shift = tmp_shift; @@ -1488,7 +1488,7 @@ static void ivas_get_pred_coeffs_fx( } ELSE IF( GT_16( tmp_shift, prev_tmp_shift ) ) { - div_factor[k] = L_shr( div_factor[k], sub( tmp_shift, prev_tmp_shift ) ); + div_factor[k] = L_shr( div_factor[k], sub( tmp_shift, prev_tmp_shift ) ); // q=prev_tmp_shift move32(); tmp_shift = prev_tmp_shift; move16(); @@ -1506,19 +1506,19 @@ static void ivas_get_pred_coeffs_fx( IF( dtx_vad == 0 ) { - dm_f_local = IVAS_ACTIVEW_DM_F_DTX_Q30; + dm_f_local = IVAS_ACTIVEW_DM_F_DTX_Q30; // q30 move32(); } ELSE { IF( active_w_vlbr ) { - dm_f_local = IVAS_ACTIVEW_DM_F_VLBR_Q30; + dm_f_local = IVAS_ACTIVEW_DM_F_VLBR_Q30; // q30 move32(); } ELSE { - dm_f_local = IVAS_ACTIVEW_DM_F_Q30; + dm_f_local = IVAS_ACTIVEW_DM_F_Q30; // q30 move32(); } } @@ -1552,8 +1552,8 @@ static void ivas_get_pred_coeffs_fx( dm_beta_re_e = sub( 31, ( sub( sub( shl( tmp_shift, 1 ), 3 ), 31 ) ) ); dm_w = cov_real[0][0][b]; // Q30 move32(); - den_f = L_max( dm_w, 1 ); - passive_g = L_deposit_l( BASOP_Util_Divide3232_Scale( dm_alpha[b], den_f, &s_div ) ); + den_f = L_max( dm_w, 1 ); // Q30 + passive_g = L_deposit_l( BASOP_Util_Divide3232_Scale( dm_alpha[b], den_f, &s_div ) ); // Q=15-(s_div+dm_alpha_e-1) div_shift = add( ( sub( 15, ( sub( ( sub( 31, dm_alpha_e ) ), Q30 ) ) ) ), sub( s_div, 1 ) ); passive_g = L_shl( passive_g, div_shift ); // Q = 29 @@ -1571,15 +1571,15 @@ static void ivas_get_pred_coeffs_fx( } IF( NE_16( sub( tmp_shift, 1 ), 31 ) ) { - dm_v_re[res_ind - 1][b] = L_shl( 1, sub( tmp_shift, 1 ) ); + dm_v_re[res_ind - 1][b] = L_shl( 1, sub( tmp_shift, 1 ) ); // Q=tmp_shift-1 move32(); } ELSE { - dm_v_re[res_ind - 1][b] = MAX_32; + dm_v_re[res_ind - 1][b] = MAX_32; // Q=tmp_shift-1 move32(); } - passive_g = activew_quad_thresh; + passive_g = activew_quad_thresh; // q29 move32(); } @@ -1604,24 +1604,24 @@ static void ivas_get_pred_coeffs_fx( DM_F[b] = L_shl( DM_F[b], div_shift ); // Q30 move32(); - DM_F[b] = L_min( ONE_IN_Q30, DM_F[b] ); + DM_F[b] = L_min( ONE_IN_Q30, DM_F[b] ); // q30 move32(); L_tmp1 = L_add( L_shr( dm_w, 1 ), Mpy_32_32( dm_alpha[b], DM_F[b] ) ); /* Q 29*/ - L_tmp2 = Mpy_32_32( Mpy_32_32( DM_F[b], DM_F[b] ), dm_beta_re ); - L_tmp2_q = add( 29, sub( shl( tmp_shift, 1 ), 65 ) ); // simplified equation for calculating Q of L_tmp2 - L_tmp2 = L_shl( L_tmp2, sub( 29, L_tmp2_q ) ); + L_tmp2 = Mpy_32_32( Mpy_32_32( DM_F[b], DM_F[b] ), dm_beta_re ); // Q=(Q29-dm_beta_re_e) + L_tmp2_q = add( 29, sub( shl( tmp_shift, 1 ), 65 ) ); // simplified equation for calculating Q of L_tmp2 + L_tmp2 = L_shl( L_tmp2, sub( 29, L_tmp2_q ) ); // Q29 den_f = L_add( L_tmp1, L_tmp2 ); // Q29 - den_f = L_max( den_f, 1 ); + den_f = L_max( den_f, 1 ); // Q29 den_f_e = 31 - 29; move16(); - L_tmp2 = Mpy_32_32( DM_F[b], dm_beta_re ); + L_tmp2 = Mpy_32_32( DM_F[b], dm_beta_re ); // Q=30-dm_beta_re_e L_tmp2_q = add( 30, sub( ( sub( shl( tmp_shift, 1 ), 34 ) ), 31 ) ); - L_tmp2 = L_shl( L_tmp2, ( sub( ( sub( 29, dm_alpha_e ) ), L_tmp2_q ) ) ); - L_tmp1 = L_shr( dm_alpha[b], ( sub( ( sub( 31, dm_alpha_e ) ), 29 ) ) ); - L_tmp1 = L_add( L_tmp1, L_tmp2 ); // Q29 + L_tmp2 = L_shl( L_tmp2, ( sub( ( sub( 29, dm_alpha_e ) ), L_tmp2_q ) ) ); // Q=29 + L_tmp1 = L_shr( dm_alpha[b], ( sub( ( sub( 31, dm_alpha_e ) ), 29 ) ) ); // Q=29 + L_tmp1 = L_add( L_tmp1, L_tmp2 ); // Q29 dm_g[b] = L_deposit_l( BASOP_Util_Divide3232_Scale( L_tmp1, den_f, &s_div ) ); // Q29 + den_f_e - 31 + 15 - s_div move32(); @@ -1637,34 +1637,34 @@ static void ivas_get_pred_coeffs_fx( /* quadratic activeW */ - num_f = BASOP_Util_Add_Mant32Exp( dm_beta_re, dm_beta_re_e, L_negate( L_shl( Mpy_32_32( dm_alpha[b], activew_quad_thresh ), 1 ) ), add( dm_alpha_e, ( 31 - Q29 ) ), &num_f_e ); + num_f = BASOP_Util_Add_Mant32Exp( dm_beta_re, dm_beta_re_e, L_negate( L_shl( Mpy_32_32( dm_alpha[b], activew_quad_thresh ), 1 ) ), add( dm_alpha_e, ( 31 - Q29 ) ), &num_f_e ); // Q=31-num_f_e sqrt_val = L_shl( Mpy_32_32( Mpy_32_32( dm_alpha[b], dm_alpha[b] ), g_th_sq ), 2 ); /*Q27*/ val_e = 4; move16(); - sqrt_val = BASOP_Util_Add_Mant32Exp( sqrt_val, 4, Mpy_32_32( dm_beta_re, dm_beta_re ), 2 * dm_beta_re_e, &val_e ); - sqrt_val = BASOP_Util_Add_Mant32Exp( sqrt_val, val_e, L_negate( L_shl( Mpy_32_32( Mpy_32_32( dm_beta_re, g_th_sq ), dm_w ), 2 ) ), add( dm_beta_re_e, 4 + 1 ), &val_e ); + sqrt_val = BASOP_Util_Add_Mant32Exp( sqrt_val, 4, Mpy_32_32( dm_beta_re, dm_beta_re ), 2 * dm_beta_re_e, &val_e ); // Q=31-val_e + sqrt_val = BASOP_Util_Add_Mant32Exp( sqrt_val, val_e, L_negate( L_shl( Mpy_32_32( Mpy_32_32( dm_beta_re, g_th_sq ), dm_w ), 2 ) ), add( dm_beta_re_e, 4 + 1 ), &val_e ); // Q=31-val_e // val_e = norm_l( sqrt_val ); - sqrt_val = Sqrt32( sqrt_val, &val_e ); + sqrt_val = Sqrt32( sqrt_val, &val_e ); // Q=31-val_e IF( val_e < 0 ) { - sqrt_val = L_shr( sqrt_val, abs_s( val_e ) ); + sqrt_val = L_shr( sqrt_val, abs_s( val_e ) ); // Q31 } ELSE IF( val_e > 0 ) { - sqrt_val = L_shl( sqrt_val, abs_s( val_e ) ); + sqrt_val = L_shl( sqrt_val, abs_s( val_e ) ); // Q31 val_e = 0; move16(); } - num_f = BASOP_Util_Add_Mant32Exp( num_f, num_f_e, sqrt_val, 0, &num_f_e ); + num_f = BASOP_Util_Add_Mant32Exp( num_f, num_f_e, sqrt_val, 0, &num_f_e ); // Q=31-num_f_e - den_f = L_shl( Mpy_32_32( dm_beta_re, g_th_sq ), 1 ); + den_f = L_shl( Mpy_32_32( dm_beta_re, g_th_sq ), 1 ); // Q=31-dm_beta_re_e+27-31=>-dm_beta_re_e+27 den_f_e = add( dm_beta_re_e, 4 ); - den_f = L_max( den_f, 1 ); + den_f = L_max( den_f, 1 ); // Q=31-den_f_e dm_g[b] = activew_quad_thresh; // Q29 move32(); - DM_F[b] = BASOP_Util_Divide3232_Scale_cadence( Mpy_32_32( dm_g[b], num_f ), den_f, &s_dm_f ); + DM_F[b] = BASOP_Util_Divide3232_Scale_cadence( Mpy_32_32( dm_g[b], num_f ), den_f, &s_dm_f ); // s_dm_f+2+num_f_e-den_f_e move32(); s_dm_f = add( s_dm_f, sub( add( 2, num_f_e ), den_f_e ) ); /*Resultant exp for DM_F s_dm_f +( 2 + num_f_e ) - den_f_e*/ div_shift = sub( s_dm_f, 1 ); @@ -1679,7 +1679,7 @@ static void ivas_get_pred_coeffs_fx( { ppPred_coeffs_re[i][b] = Mpy_32_32( dm_v_re[i][b], dm_g[b] ); // Q = tmp_shift - 1 + 30 - 31 move32(); - ppDM_Fv_re[i][b] = Mpy_32_32( dm_v_re[i][b], DM_F[b] ); + ppDM_Fv_re[i][b] = Mpy_32_32( dm_v_re[i][b], DM_F[b] ); // Q = tmp_shift - 1 + 30 -31 move32(); } } @@ -1703,11 +1703,11 @@ static void ivas_get_pred_coeffs_fx( #ifdef IVAS_FLOAT_FIXED static void ivas_get_Wscaling_factor_enc_fx( - Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], /*q_cov_real*/ Word16 *q_cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], - Word32 pred_coeffs_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], + Word32 pred_coeffs_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], /*q_pred_coeffs_re*/ Word16 q_pred_coeffs_re, - Word32 ***mixer_mat, + Word32 ***mixer_mat, /*q_mixer_mat*/ Word16 q_mixer_mat, const Word16 start_band, const Word16 end_band, @@ -1717,7 +1717,7 @@ static void ivas_get_Wscaling_factor_enc_fx( const Word16 bands_bw, const Word16 active_w, const Word16 active_w_vlbr, - Word32 *pWscale, + Word32 *pWscale, /*q_pWscale*/ Word16 *q_pWscale, const Word16 dyn_active_w_flag ) { @@ -1770,41 +1770,41 @@ static void ivas_get_Wscaling_factor_enc_fx( ivas_calc_post_pred_per_band_enc_fx( cov_real, q_cov_real, mixer_mat, q_mixer_mat, num_ch, b, postpred_cov_re, &q_postpred_cov_re ); } - Gw_sq = BASOP_Util_Divide3232_Scale( cov_real[0][0][b], L_max( postpred_cov_re[0][0], IVAS_FIX_EPS ), &tmp_exp ); + Gw_sq = BASOP_Util_Divide3232_Scale( cov_real[0][0][b], L_max( postpred_cov_re[0][0], IVAS_FIX_EPS ), &tmp_exp ); // 15-(tmp_exp-(q_cov_real[0][0][b]- q_postpred_cov_re)) q_Gw_sq = add( sub( 15, tmp_exp ), sub( q_cov_real[0][0][b], q_postpred_cov_re ) ); guard_bits = find_guarded_bits_fx( num_ch ); FOR( ch = 0; ch < sub( num_ch, 1 ); ch++ ) { - abs_val = L_shr( Mpy_32_32( pred_coeffs_re[ch][b], pred_coeffs_re[ch][b] ), guard_bits ); - g_sq = L_add( g_sq, abs_val ); + abs_val = L_shr( Mpy_32_32( pred_coeffs_re[ch][b], pred_coeffs_re[ch][b] ), guard_bits ); // q=2*q_pred_coeffs_re-guard_bits-31 + g_sq = L_add( g_sq, abs_val ); // q=2*q_pred_coeffs_re-guard_bits-31 } q_g_sq = sub( add( q_pred_coeffs_re, q_pred_coeffs_re ), add( 31, guard_bits ) ); - tmp = Mpy_32_32( ONE_IN_Q30 /*4 in Q28*/, Mpy_32_32( dm_f_local, g_sq ) ); + tmp = Mpy_32_32( ONE_IN_Q30 /*4 in Q28*/, Mpy_32_32( dm_f_local, g_sq ) ); // q_g_sq+28-31 q_tmp = sub( q_g_sq, 3 ); q_min = s_min( q_Gw_sq, q_tmp ); - tmp = L_shr( tmp, sub( q_tmp, q_min ) ); - tmp = L_add( L_shr( Gw_sq, sub( q_Gw_sq, q_min ) ), tmp ); + tmp = L_shr( tmp, sub( q_tmp, q_min ) ); // Q=q_min + tmp = L_add( L_shr( Gw_sq, sub( q_Gw_sq, q_min ) ), tmp ); // Q=q_min tmp_exp = sub( 31, q_min ); - tmp = Sqrt32( tmp, &tmp_exp ); + tmp = Sqrt32( tmp, &tmp_exp ); // q=31-tmp_exp q_tmp = sub( 31, tmp_exp ); tmp_exp = sub( 31, q_Gw_sq ); - Gw_sq = Sqrt32( Gw_sq, &tmp_exp ); + Gw_sq = Sqrt32( Gw_sq, &tmp_exp ); // q=31-tmp_exp q_Gw_sq = sub( 31, tmp_exp ); q_min = s_min( q_Gw_sq, q_tmp ); - Gw_sq = L_shr( Gw_sq, sub( q_Gw_sq, q_min ) ); + Gw_sq = L_shr( Gw_sq, sub( q_Gw_sq, q_min ) ); // q=q_min q_Gw_sq = q_min; move16(); - tmp = L_shr( tmp, sub( q_tmp, q_min ) ); + tmp = L_shr( tmp, sub( q_tmp, q_min ) ); // q=q_min - pWscale[b] = L_add( Mpy_32_32( Gw_sq, ONE_IN_Q30 /* 0.5 in Q31*/ ), Mpy_32_32( tmp, ONE_IN_Q30 /* 0.5 in Q31*/ ) ); + pWscale[b] = L_add( Mpy_32_32( Gw_sq, ONE_IN_Q30 /* 0.5 in Q31*/ ), Mpy_32_32( tmp, ONE_IN_Q30 /* 0.5 in Q31*/ ) ); // q=q_Gw_sq move32(); q_pWscale[b] = q_Gw_sq; move16(); @@ -1815,11 +1815,11 @@ static void ivas_get_Wscaling_factor_enc_fx( } static void ivas_get_Wscaling_factor_fx( - Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], /*q_cov_real*/ Word16 q_cov_real, - Word32 pred_coeffs_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], + Word32 pred_coeffs_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], /*q_pred_coeffs_re*/ Word16 q_pred_coeffs_re, - Word32 ***mixer_mat, + Word32 ***mixer_mat, /*q_mixer_mat*/ Word16 q_mixer_mat, const Word16 start_band, const Word16 end_band, @@ -1829,7 +1829,7 @@ static void ivas_get_Wscaling_factor_fx( const Word16 bands_bw, const Word16 active_w, const Word16 active_w_vlbr, - Word32 *pWscale, + Word32 *pWscale, /*q_pWscale*/ Word16 *q_pWscale, const Word16 dyn_active_w_flag ) { @@ -1882,41 +1882,41 @@ static void ivas_get_Wscaling_factor_fx( ivas_calc_post_pred_per_band_fx( cov_real, q_cov_real, mixer_mat, q_mixer_mat, num_ch, b, postpred_cov_re, &q_postpred_cov_re ); } - Gw_sq = BASOP_Util_Divide3232_Scale( cov_real[0][0][b], L_max( postpred_cov_re[0][0], IVAS_FIX_EPS ), &tmp_exp ); + Gw_sq = BASOP_Util_Divide3232_Scale( cov_real[0][0][b], L_max( postpred_cov_re[0][0], IVAS_FIX_EPS ), &tmp_exp ); /*15-(tmp_exp-(q_cov_real-q_postpred_cov_re))*/ q_Gw_sq = add( sub( 15, tmp_exp ), sub( q_cov_real, q_postpred_cov_re ) ); guard_bits = find_guarded_bits_fx( num_ch ); FOR( ch = 0; ch < sub( num_ch, 1 ); ch++ ) { - abs_val = L_shr( Mpy_32_32( pred_coeffs_re[ch][b], pred_coeffs_re[ch][b] ), guard_bits ); - g_sq = L_add( g_sq, abs_val ); + abs_val = L_shr( Mpy_32_32( pred_coeffs_re[ch][b], pred_coeffs_re[ch][b] ), guard_bits ); /*q=2*q_pred_coeffs_re-guard_bits-31*/ + g_sq = L_add( g_sq, abs_val ); /*q=2*q_pred_coeffs_re-guard_bits-31*/ } q_g_sq = sub( add( q_pred_coeffs_re, q_pred_coeffs_re ), add( 31, guard_bits ) ); - tmp = Mpy_32_32( ONE_IN_Q30 /*4 in Q28*/, Mpy_32_32( dm_f_local, g_sq ) ); + tmp = Mpy_32_32( ONE_IN_Q30 /*4 in Q28*/, Mpy_32_32( dm_f_local, g_sq ) ); /*q=q_g_sq-3*/ q_tmp = sub( q_g_sq, 3 ); q_min = s_min( q_Gw_sq, q_tmp ); - tmp = L_shr( tmp, sub( q_tmp, q_min ) ); - tmp = L_add( L_shr( Gw_sq, sub( q_Gw_sq, q_min ) ), tmp ); + tmp = L_shr( tmp, sub( q_tmp, q_min ) ); // q=q_min + tmp = L_add( L_shr( Gw_sq, sub( q_Gw_sq, q_min ) ), tmp ); // q=q_min tmp_exp = sub( 31, q_min ); - tmp = Sqrt32( tmp, &tmp_exp ); + tmp = Sqrt32( tmp, &tmp_exp ); // q=31-tmp_exp q_tmp = sub( 31, tmp_exp ); tmp_exp = sub( 31, q_Gw_sq ); - Gw_sq = Sqrt32( Gw_sq, &tmp_exp ); + Gw_sq = Sqrt32( Gw_sq, &tmp_exp ); // q=31-tmp_exp q_Gw_sq = sub( 31, tmp_exp ); q_min = s_min( q_Gw_sq, q_tmp ); - Gw_sq = L_shr( Gw_sq, sub( q_Gw_sq, q_min ) ); + Gw_sq = L_shr( Gw_sq, sub( q_Gw_sq, q_min ) ); // q=q_min q_Gw_sq = q_min; move16(); - tmp = L_shr( tmp, sub( q_tmp, q_min ) ); + tmp = L_shr( tmp, sub( q_tmp, q_min ) ); // q=q_min - pWscale[b] = L_add( L_shr( Gw_sq, 1 /* Gw_sq * 0.5 */ ), L_shr( tmp, 1 /* tmp * 0.5 */ ) ); + pWscale[b] = L_add( L_shr( Gw_sq, 1 /* Gw_sq * 0.5 */ ), L_shr( tmp, 1 /* tmp * 0.5 */ ) ); // q=q_Gw_sq move32(); q_pWscale[b] = q_Gw_sq; move16(); @@ -1938,11 +1938,11 @@ static void ivas_get_Wscaling_factor_fx( #ifdef IVAS_FLOAT_FIXED void ivas_create_fullr_dmx_mat_fx( - Word32 pred_coeffs_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], + Word32 pred_coeffs_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], /*q_pred_coeffs_re*/ Word16 q_pred_coeffs_re, - Word32 dm_fv_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], + Word32 dm_fv_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], /*q_dm_fv_re*/ Word16 q_dm_fv_re, - Word32 ***mixer_mat, + Word32 ***mixer_mat, /*q_mixer_mat*/ Word16 *q_mixer_mat, const Word16 in_chans, const Word16 start_band, @@ -1983,9 +1983,9 @@ void ivas_create_fullr_dmx_mat_fx( { FOR( b = start_band; b < end_band; b++ ) { - tmp_p2_re[j][j][b] = L_shl_sat( 1, q_pred_coeffs_re ); + tmp_p2_re[j][j][b] = L_shl_sat( 1, q_pred_coeffs_re ); // q=q_pred_coeffs_re move32(); - max_val_tmp_p2 = L_max( max_val_tmp_p2, L_abs( tmp_p2_re[j][j][b] ) ); + max_val_tmp_p2 = L_max( max_val_tmp_p2, L_abs( tmp_p2_re[j][j][b] ) ); // q=q_pred_coeffs_re } } @@ -1993,9 +1993,9 @@ void ivas_create_fullr_dmx_mat_fx( { FOR( b = start_band; b < end_band; b++ ) { - tmp_p2_re[j][0][b] = L_negate( pred_coeffs_re[j - 1][b] ); + tmp_p2_re[j][0][b] = L_negate( pred_coeffs_re[j - 1][b] ); // q=q_pred_coeffs_re move32(); - max_val_tmp_p2 = L_max( max_val_tmp_p2, L_abs( tmp_p2_re[j][0][b] ) ); + max_val_tmp_p2 = L_max( max_val_tmp_p2, L_abs( tmp_p2_re[j][0][b] ) ); // q=q_pred_coeffs_re } } @@ -2011,9 +2011,9 @@ void ivas_create_fullr_dmx_mat_fx( { FOR( b = start_band; b < end_band; b++ ) { - tmp_p1_re[j][j][b] = L_shl_sat( 1, q_dm_fv_re ); + tmp_p1_re[j][j][b] = L_shl_sat( 1, q_dm_fv_re ); // q=q_dm_fv_re move32(); - max_val = L_max( max_val, L_abs( tmp_p1_re[j][j][b] ) ); + max_val = L_max( max_val, L_abs( tmp_p1_re[j][j][b] ) ); // q=q_dm_fv_re } } @@ -2021,9 +2021,9 @@ void ivas_create_fullr_dmx_mat_fx( { FOR( b = start_band; b < end_band; b++ ) { - tmp_p1_re[0][j][b] = dm_fv_re[j - 1][b]; + tmp_p1_re[0][j][b] = dm_fv_re[j - 1][b]; // q=q_dm_fv_re move32(); - max_val = L_max( max_val, L_abs( tmp_p1_re[0][j][b] ) ); + max_val = L_max( max_val, L_abs( tmp_p1_re[0][j][b] ) ); // q=q_dm_fv_re } } @@ -2038,8 +2038,8 @@ void ivas_create_fullr_dmx_mat_fx( { FOR( b = start_band; b < end_band; b++ ) { - tmp_re = L_shr( Mpy_32_32( tmp_p2_re[i][k][b], tmp_p1_re[k][j][b] ), guard_bits ); - down_mix_mat1_re[i][j][b] = L_add( down_mix_mat1_re[i][j][b], tmp_re ); + tmp_re = L_shr( Mpy_32_32( tmp_p2_re[i][k][b], tmp_p1_re[k][j][b] ), guard_bits ); // q= q_dm_fv_re+ q_pred_coeffs_re-31-guard_bits + down_mix_mat1_re[i][j][b] = L_add( down_mix_mat1_re[i][j][b], tmp_re ); // q= q_dm_fv_re+ q_pred_coeffs_re-31-guard_bits move32(); } } @@ -2056,7 +2056,7 @@ void ivas_create_fullr_dmx_mat_fx( { FOR( b = start_band; b < end_band; b++ ) { - down_mix_mat1_re[j][k][b] = tmp_p2_re[j][k][b]; + down_mix_mat1_re[j][k][b] = tmp_p2_re[j][k][b]; // q=q_pred_coeffs_re move32(); } } @@ -2084,10 +2084,10 @@ void ivas_create_fullr_dmx_mat_fx( #ifdef IVAS_FLOAT_FIXED static void ivas_reorder_array_fx( - Word32 in_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH][IVAS_MAX_NUM_BANDS], + Word32 in_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH][IVAS_MAX_NUM_BANDS], /*qx*/ const Word16 in_chans, const Word16 order[IVAS_SPAR_MAX_CH], - Word32 ***mixer_mat, + Word32 ***mixer_mat, /*qx*/ const Word16 start_band, const Word16 end_band ) { @@ -2102,7 +2102,7 @@ static void ivas_reorder_array_fx( { FOR( b = start_band; b < end_band; b++ ) { - mixer_mat[i][j][b] = in_re[idx][j][b]; + mixer_mat[i][j][b] = in_re[idx][j][b]; /*qx*/ move32(); } } @@ -2121,13 +2121,13 @@ static void ivas_reorder_array_fx( #ifdef IVAS_FLOAT_FIXED static void ivas_calc_post_pred_per_band_enc_fx( - Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], /*q_cov_real*/ Word16 *q_cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], - Word32 ***mixer_mat, + Word32 ***mixer_mat, /*q_mixer_mat*/ Word16 q_mixer_mat, const Word16 num_ch, const Word16 band_idx, - Word32 postpred_cov_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + Word32 postpred_cov_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], /*q_postpred_cov_re*/ Word16 *q_postpred_cov_re ) { Word16 i, j, k, guard_bits, tmp, q_temp_mat[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], q_tmp_re, q_W_tmp; @@ -2141,7 +2141,7 @@ static void ivas_calc_post_pred_per_band_enc_fx( { FOR( j = 0; j < num_ch; j++ ) { - dmx_mat_conj[i][j] = mixer_mat[j][i][band_idx]; + dmx_mat_conj[i][j] = mixer_mat[j][i][band_idx]; /*q_mixer_mat*/ move32(); } } @@ -2165,16 +2165,16 @@ static void ivas_calc_post_pred_per_band_enc_fx( move16(); FOR( k = 0; k < num_ch; k++ ) { - W_tmp = W_shr( W_mult0_32_32( cov_real[i][k][band_idx], dmx_mat_conj[k][j] ), q_mixer_mat ); + W_tmp = W_shr( W_mult0_32_32( cov_real[i][k][band_idx], dmx_mat_conj[k][j] ), q_mixer_mat ); /*q_cov_real[i][k][band_idx]*/ IF( LT_16( q_cov_real[i][k][band_idx], q_tmp_re ) ) { - tmp_re = W_add( W_shr( tmp_re, sub( q_tmp_re, q_cov_real[i][k][band_idx] ) ), W_tmp ); + tmp_re = W_add( W_shr( tmp_re, sub( q_tmp_re, q_cov_real[i][k][band_idx] ) ), W_tmp ); /*q_cov_real[i][k][band_idx]*/ q_tmp_re = q_cov_real[i][k][band_idx]; move16(); } ELSE { - tmp_re = W_add( tmp_re, W_shr( W_tmp, sub( q_cov_real[i][k][band_idx], q_tmp_re ) ) ); + tmp_re = W_add( tmp_re, W_shr( W_tmp, sub( q_cov_real[i][k][band_idx], q_tmp_re ) ) ); /*q_tmp_re*/ } } IF( tmp_re == 0 ) @@ -2189,7 +2189,7 @@ static void ivas_calc_post_pred_per_band_enc_fx( q_temp_mat[i][j] = q_tmp_re; move16(); q_tmp_re = W_norm( tmp_re ); - temp_mat[i][j] = W_extract_h( W_shl( tmp_re, q_tmp_re ) ); + temp_mat[i][j] = W_extract_h( W_shl( tmp_re, q_tmp_re ) ); /*q_temp_mat[i][j]+ q_tmp_re -32*/ move32(); q_temp_mat[i][j] = sub( add( q_temp_mat[i][j], q_tmp_re ), 32 ); move16(); @@ -2224,17 +2224,17 @@ static void ivas_calc_post_pred_per_band_enc_fx( move16(); FOR( k = 0; k < num_ch; k++ ) { - W_tmp = W_shr( W_mult0_32_32( mixer_mat[i][k][band_idx], temp_mat[k][j] ), guard_bits ); + W_tmp = W_shr( W_mult0_32_32( mixer_mat[i][k][band_idx], temp_mat[k][j] ), guard_bits ); // q_temp_mat[k][j]+ q_mixer_mat-guard_bits q_W_tmp = sub( add( q_temp_mat[k][j], q_mixer_mat ), guard_bits ); IF( LT_16( q_W_tmp, q_tmp_re ) ) { - tmp_re = W_add( W_shr( tmp_re, sub( q_tmp_re, q_W_tmp ) ), W_tmp ); + tmp_re = W_add( W_shr( tmp_re, sub( q_tmp_re, q_W_tmp ) ), W_tmp ); // q_W_tmp q_tmp_re = q_W_tmp; move16(); } ELSE { - tmp_re = W_add( tmp_re, W_shr( W_tmp, sub( q_W_tmp, q_tmp_re ) ) ); + tmp_re = W_add( tmp_re, W_shr( W_tmp, sub( q_W_tmp, q_tmp_re ) ) ); // q_tmp_re } } @@ -2247,7 +2247,7 @@ static void ivas_calc_post_pred_per_band_enc_fx( q_postpred_cov_re_per_value[i][j] = q_tmp_re; move16(); q_tmp_re = W_norm( tmp_re ); - postpred_cov_re[i][j] = W_extract_h( W_shl( tmp_re, q_tmp_re ) ); + postpred_cov_re[i][j] = W_extract_h( W_shl( tmp_re, q_tmp_re ) ); /* q_tmp_re+ q_postpred_cov_re_per_value[i][j] -32*/ move32(); q_postpred_cov_re_per_value[i][j] = sub( add( q_tmp_re, q_postpred_cov_re_per_value[i][j] ), 32 ); move16(); @@ -2262,12 +2262,12 @@ static void ivas_calc_post_pred_per_band_enc_fx( { IF( postpred_cov_re[i][j] >= 0 ) { - postpred_cov_re[i][j] = L_shr( postpred_cov_re[i][j], sub( q_postpred_cov_re_per_value[i][j], *q_postpred_cov_re ) ); + postpred_cov_re[i][j] = L_shr( postpred_cov_re[i][j], sub( q_postpred_cov_re_per_value[i][j], *q_postpred_cov_re ) ); //*q_postpred_cov_re move32(); } ELSE { - postpred_cov_re[i][j] = L_negate( L_shr( L_negate( postpred_cov_re[i][j] ), sub( q_postpred_cov_re_per_value[i][j], *q_postpred_cov_re ) ) ); + postpred_cov_re[i][j] = L_negate( L_shr( L_negate( postpred_cov_re[i][j] ), sub( q_postpred_cov_re_per_value[i][j], *q_postpred_cov_re ) ) ); //*q_postpred_cov_re move32(); } } @@ -2277,7 +2277,7 @@ static void ivas_calc_post_pred_per_band_enc_fx( { FOR( j = 0; j < i; j++ ) { - postpred_cov_re[i][j] = postpred_cov_re[j][i]; + postpred_cov_re[i][j] = postpred_cov_re[j][i]; //*q_postpred_cov_re move32(); } } @@ -2286,13 +2286,13 @@ static void ivas_calc_post_pred_per_band_enc_fx( } static void ivas_calc_post_pred_per_band_fx( - Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], /*q_cov_real*/ Word16 q_cov_real, - Word32 ***mixer_mat, + Word32 ***mixer_mat, /*q_mixer_mat*/ Word16 q_mixer_mat, const Word16 num_ch, const Word16 band_idx, - Word32 postpred_cov_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + Word32 postpred_cov_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], /*q_postpred_cov_re*/ Word16 *q_postpred_cov_re ) { Word16 i, j, k, guard_bits, tmp, q_temp_mat; @@ -2305,7 +2305,7 @@ static void ivas_calc_post_pred_per_band_fx( { FOR( j = 0; j < num_ch; j++ ) { - dmx_mat_conj[i][j] = mixer_mat[j][i][band_idx]; + dmx_mat_conj[i][j] = mixer_mat[j][i][band_idx]; /*q_mixer_mat*/ move32(); } } @@ -2329,7 +2329,7 @@ static void ivas_calc_post_pred_per_band_fx( move64(); FOR( k = 0; k < num_ch; k++ ) { - tmp_re = W_add( tmp_re, W_shr( W_mult0_32_32( cov_real[i][k][band_idx], dmx_mat_conj[k][j] ), guard_bits ) ); + tmp_re = W_add( tmp_re, W_shr( W_mult0_32_32( cov_real[i][k][band_idx], dmx_mat_conj[k][j] ), guard_bits ) ); /*q_cov_real+q_mixer_mat-guard_bits*/ } if ( LT_64( W_abs( tmp_re ), L_shl( IVAS_FIX_EPS, guard_bits ) ) ) { @@ -2338,7 +2338,7 @@ static void ivas_calc_post_pred_per_band_fx( } temp_mat[i][j] = W_extract_l( W_shr( tmp_re, q_mixer_mat ) ); // Q = (q_cov_real - guard_bits) move32(); - max_val = L_max( max_val, L_abs( temp_mat[i][j] ) ); + max_val = L_max( max_val, L_abs( temp_mat[i][j] ) ); // Q = (q_cov_real - guard_bits) } } q_temp_mat = sub( q_cov_real, guard_bits ); @@ -2365,7 +2365,7 @@ static void ivas_calc_post_pred_per_band_fx( move64(); FOR( k = 0; k < num_ch; k++ ) { - tmp_re = W_add( tmp_re, W_shr( W_mult0_32_32( mixer_mat[i][k][band_idx], temp_mat[k][j] ), guard_bits ) ); + tmp_re = W_add( tmp_re, W_shr( W_mult0_32_32( mixer_mat[i][k][band_idx], temp_mat[k][j] ), guard_bits ) ); /*q_mixer_mat+q_temp_mat-guard_bits*/ } if ( LT_64( W_abs( tmp_re ), L_shl( IVAS_FIX_EPS, guard_bits ) ) ) @@ -2374,7 +2374,7 @@ static void ivas_calc_post_pred_per_band_fx( move64(); } - postpred_cov_re[i][j] = W_extract_l( W_shr( tmp_re, q_mixer_mat ) ); + postpred_cov_re[i][j] = W_extract_l( W_shr( tmp_re, q_mixer_mat ) ); /*q_temp_mat-guard_bits*/ move32(); } } @@ -2386,7 +2386,7 @@ static void ivas_calc_post_pred_per_band_fx( { FOR( j = 0; j < i; j++ ) { - postpred_cov_re[i][j] = postpred_cov_re[j][i]; + postpred_cov_re[i][j] = postpred_cov_re[j][i]; /* *q_postpred_cov_re */ move32(); } } @@ -2407,7 +2407,7 @@ static void ivas_calc_post_pred_per_band_fx( static void ivas_calc_p_coeffs_per_band_enc_fx( ivas_spar_md_t *pSparMd, const Word16 i_ts, - Word32 postpred_cov_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + Word32 postpred_cov_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], /*q_postpred_cov_re*/ Word16 q_postpred_cov_re, const Word16 num_ch, const Word16 dtx_vad, @@ -2445,7 +2445,7 @@ static void ivas_calc_p_coeffs_per_band_enc_fx( { FOR( j = num_dmx; j < num_ch; j++ ) { - cov_uu_re[i - num_dmx][j - num_dmx] = postpred_cov_re[i][j]; + cov_uu_re[i - num_dmx][j - num_dmx] = postpred_cov_re[i][j]; // q_postpred_cov_re move32(); } } @@ -2458,7 +2458,7 @@ static void ivas_calc_p_coeffs_per_band_enc_fx( { FOR( j = 1; j < num_dmx; j++ ) { - cov_dd_re[i - 1][j - 1] = postpred_cov_re[i][j]; + cov_dd_re[i - 1][j - 1] = postpred_cov_re[i][j]; // q_postpred_cov_re move32(); } } @@ -2472,18 +2472,18 @@ static void ivas_calc_p_coeffs_per_band_enc_fx( { Word32 re1, re2; - W_tmp = W_mult0_32_32( pSparMd->band_coeffs[b_ts_idx].C_re_fx[0][0], cov_dd_re[0][0] ); + W_tmp = W_mult0_32_32( pSparMd->band_coeffs[b_ts_idx].C_re_fx[0][0], cov_dd_re[0][0] ); /*q_cov_dd_re+ pSparMd->band_coeffs[b_ts_idx].q_C_re_fx*/ q_tmp1 = W_norm( W_tmp ); - re1 = W_extract_h( W_shl( W_tmp, q_tmp1 ) ); + re1 = W_extract_h( W_shl( W_tmp, q_tmp1 ) ); /*q_cov_dd_re+ q_C_re+q_tmp1-32*/ q_tmp1 = sub( add( add( q_C_re, q_tmp1 ), q_cov_dd_re ), 32 ); if ( W_tmp == 0 ) { q_tmp1 = 31; move16(); } - W_tmp = W_mult0_32_32( pSparMd->band_coeffs[b_ts_idx].C_re_fx[1][0], cov_dd_re[0][0] ); + W_tmp = W_mult0_32_32( pSparMd->band_coeffs[b_ts_idx].C_re_fx[1][0], cov_dd_re[0][0] ); /*q_cov_dd_re+ q_C_re*/ q_tmp = W_norm( W_tmp ); - re2 = W_extract_h( W_shl( W_tmp, q_tmp ) ); + re2 = W_extract_h( W_shl( W_tmp, q_tmp ) ); /*q_cov_dd_re+ q_C_re+q_tmp-32*/ q_tmp = sub( add( add( q_C_re, q_tmp ), q_cov_dd_re ), 32 ); if ( W_tmp == 0 ) { @@ -2491,10 +2491,10 @@ static void ivas_calc_p_coeffs_per_band_enc_fx( move16(); } - W_tmp = W_mult0_32_32( pSparMd->band_coeffs[b_ts_idx].C_re_fx[0][0], re1 ); + W_tmp = W_mult0_32_32( pSparMd->band_coeffs[b_ts_idx].C_re_fx[0][0], re1 ); // q_tmp1+q_C_re q_recon_uu_re[0][0] = W_norm( W_tmp ); move16(); - recon_uu_re[0][0] = W_extract_h( W_shl( W_tmp, q_recon_uu_re[0][0] ) ); + recon_uu_re[0][0] = W_extract_h( W_shl( W_tmp, q_recon_uu_re[0][0] ) ); // q_tmp1+q_C_re+q_recon_uu_re[0][0]-32 move32(); q_recon_uu_re[0][0] = sub( add( add( q_C_re, q_recon_uu_re[0][0] ), q_tmp1 ), 32 ); move16(); @@ -2504,10 +2504,10 @@ static void ivas_calc_p_coeffs_per_band_enc_fx( move16(); } - W_tmp = W_mult0_32_32( pSparMd->band_coeffs[b_ts_idx].C_re_fx[1][0], re1 ); + W_tmp = W_mult0_32_32( pSparMd->band_coeffs[b_ts_idx].C_re_fx[1][0], re1 ); // q_C_re+q_tmp1 q_recon_uu_re[0][1] = W_norm( W_tmp ); move16(); - recon_uu_re[0][1] = W_extract_h( W_shl( W_tmp, q_recon_uu_re[0][1] ) ); + recon_uu_re[0][1] = W_extract_h( W_shl( W_tmp, q_recon_uu_re[0][1] ) ); // q_C_re+q_tmp1+q_recon_uu_re[0][1]-32 move32(); q_recon_uu_re[0][1] = sub( add( add( q_C_re, q_recon_uu_re[0][1] ), q_tmp1 ), 32 ); move16(); @@ -2517,10 +2517,10 @@ static void ivas_calc_p_coeffs_per_band_enc_fx( move16(); } - W_tmp = W_mult0_32_32( pSparMd->band_coeffs[b_ts_idx].C_re_fx[0][0], re2 ); + W_tmp = W_mult0_32_32( pSparMd->band_coeffs[b_ts_idx].C_re_fx[0][0], re2 ); // q_C_re+q_tmp q_recon_uu_re[1][0] = W_norm( W_tmp ); move16(); - recon_uu_re[1][0] = W_extract_h( W_shl( W_tmp, q_recon_uu_re[1][0] ) ); + recon_uu_re[1][0] = W_extract_h( W_shl( W_tmp, q_recon_uu_re[1][0] ) ); // q_C_re+q_tmp+q_recon_uu_re[1][0]-32 move32(); q_recon_uu_re[1][0] = sub( add( add( q_C_re, q_recon_uu_re[1][0] ), q_tmp ), 32 ); move16(); @@ -2530,12 +2530,12 @@ static void ivas_calc_p_coeffs_per_band_enc_fx( move16(); } - W_tmp = W_mult0_32_32( pSparMd->band_coeffs[b_ts_idx].C_re_fx[1][0], re2 ); + W_tmp = W_mult0_32_32( pSparMd->band_coeffs[b_ts_idx].C_re_fx[1][0], re2 ); // q_C_re+q_tmp q_recon_uu_re[1][1] = W_norm( W_tmp ); move16(); - recon_uu_re[1][1] = W_extract_h( W_shl( W_tmp, q_recon_uu_re[1][1] ) ); + recon_uu_re[1][1] = W_extract_h( W_shl( W_tmp, q_recon_uu_re[1][1] ) ); // q_C_re+q_tmp+q_recon_uu_re[1][1]-32 move32(); - q_recon_uu_re[1][1] = sub( add( add( q_C_re, q_recon_uu_re[1][1] ), q_tmp1 ), 32 ); + q_recon_uu_re[1][1] = sub( add( add( q_C_re, q_recon_uu_re[1][1] ), q_tmp ), 32 ); move16(); if ( W_tmp == 0 ) { @@ -2558,7 +2558,7 @@ static void ivas_calc_p_coeffs_per_band_enc_fx( { FOR( j = 0; j < 2; j++ ) { - cov_uu_re[i][j] = L_sub( L_shr( cov_uu_re[i][j], sub( q_cov_uu_re, q_tmp ) ), L_shr( recon_uu_re[i][j], sub( q_recon_uu_re[i][j], q_tmp ) ) ); + cov_uu_re[i][j] = L_sub( L_shr( cov_uu_re[i][j], sub( q_cov_uu_re, q_tmp ) ), L_shr( recon_uu_re[i][j], sub( q_recon_uu_re[i][j], q_tmp ) ) ); // q_tmp move32(); } } @@ -2577,9 +2577,9 @@ static void ivas_calc_p_coeffs_per_band_enc_fx( FOR( k = 0; k < 2; k++ ) { Word32 re; - W_tmp = W_mult0_32_32( pSparMd->band_coeffs[b_ts_idx].C_re_fx[0][k], cov_dd_re[k][j] ); + W_tmp = W_mult0_32_32( pSparMd->band_coeffs[b_ts_idx].C_re_fx[0][k], cov_dd_re[k][j] ); // q_C_re+q_cov_dd_re q_tmp = sub( W_norm( W_tmp ), 1 ); - re = W_extract_h( W_shl( W_tmp, q_tmp ) ); + re = W_extract_h( W_shl( W_tmp, q_tmp ) ); // q_C_re+q_cov_dd_re+q_tmp-32 q_tmp = sub( add( add( q_C_re, q_tmp ), q_cov_dd_re ), 32 ); if ( W_tmp == 0 ) { @@ -2589,35 +2589,35 @@ static void ivas_calc_p_coeffs_per_band_enc_fx( IF( LT_16( q_tmp, q_re1[j] ) ) { - re1[j] = L_shr( re1[j], sub( q_re1[j], q_tmp ) ); + re1[j] = L_shr( re1[j], sub( q_re1[j], q_tmp ) ); // q_tmp move32(); q_re1[j] = q_tmp; move16(); } ELSE { - re = L_shr( re, sub( q_tmp, q_re1[j] ) ); + re = L_shr( re, sub( q_tmp, q_re1[j] ) ); // q_re1[j] } - re1[j] = L_add( re1[j], re ); + re1[j] = L_add( re1[j], re ); // q_re1[j] move32(); } } - W_tmp = W_mult0_32_32( pSparMd->band_coeffs[b_ts_idx].C_re_fx[0][0], re1[0] ); + W_tmp = W_mult0_32_32( pSparMd->band_coeffs[b_ts_idx].C_re_fx[0][0], re1[0] ); // q_C_re+q_re1[0] q_tmp = sub( W_norm( W_tmp ), 1 ); - re2 = W_extract_h( W_shl( W_tmp, q_tmp ) ); + re2 = W_extract_h( W_shl( W_tmp, q_tmp ) ); // q_C_re+q_re1[0]+q_tmp-32 q_tmp = sub( add( add( q_C_re, q_tmp ), q_re1[0] ), 32 ); if ( W_tmp == 0 ) { q_tmp = 31; move16(); } - recon_uu_re[0][0] = re2; + recon_uu_re[0][0] = re2; // q_C_re+q_re1[0]+q_tmp-32 move32(); - W_tmp = W_mult0_32_32( pSparMd->band_coeffs[b_ts_idx].C_re_fx[0][1], re1[1] ); + W_tmp = W_mult0_32_32( pSparMd->band_coeffs[b_ts_idx].C_re_fx[0][1], re1[1] ); // q_C_re+q_re1[1] q_tmp1 = sub( W_norm( W_tmp ), 1 ); - re2 = W_extract_h( W_shl( W_tmp, q_tmp1 ) ); + re2 = W_extract_h( W_shl( W_tmp, q_tmp1 ) ); // q_C_re+q_re1[1]+q_tmp1-32 q_tmp1 = sub( add( add( q_C_re, q_tmp1 ), q_re1[1] ), 32 ); if ( W_tmp == 0 ) { @@ -2627,22 +2627,22 @@ static void ivas_calc_p_coeffs_per_band_enc_fx( IF( LT_16( q_tmp, q_tmp1 ) ) { - re2 = L_shr( re2, sub( q_tmp1, q_tmp ) ); + re2 = L_shr( re2, sub( q_tmp1, q_tmp ) ); // q_tmp } ELSE { - recon_uu_re[0][0] = L_shr( recon_uu_re[0][0], sub( q_tmp, q_tmp1 ) ); + recon_uu_re[0][0] = L_shr( recon_uu_re[0][0], sub( q_tmp, q_tmp1 ) ); // q_tmp1 move32(); q_tmp = q_tmp1; move16(); } - recon_uu_re[0][0] = L_add( recon_uu_re[0][0], re2 ); + recon_uu_re[0][0] = L_add( recon_uu_re[0][0], re2 ); // q_tmp move32(); IF( LT_16( q_cov_uu_re, q_tmp ) ) { - recon_uu_re[0][0] = L_shr( recon_uu_re[0][0], sub( q_tmp, q_cov_uu_re ) ); + recon_uu_re[0][0] = L_shr( recon_uu_re[0][0], sub( q_tmp, q_cov_uu_re ) ); // q_cov_uu_re move32(); } ELSE @@ -2651,7 +2651,7 @@ static void ivas_calc_p_coeffs_per_band_enc_fx( { FOR( j = num_dmx; j < num_ch; j++ ) { - cov_uu_re[i - num_dmx][j - num_dmx] = L_shr( cov_uu_re[i - num_dmx][j - num_dmx], sub( q_cov_uu_re, q_tmp ) ); + cov_uu_re[i - num_dmx][j - num_dmx] = L_shr( cov_uu_re[i - num_dmx][j - num_dmx], sub( q_cov_uu_re, q_tmp ) ); // q_tmp move32(); } } @@ -2668,17 +2668,17 @@ static void ivas_calc_p_coeffs_per_band_enc_fx( { FOR( j = num_dmx; j < num_ch; j++ ) { - cov_uu_re[i - num_dmx][j - num_dmx] = L_shr( cov_uu_re[i - num_dmx][j - num_dmx], 1 ); + cov_uu_re[i - num_dmx][j - num_dmx] = L_shr( cov_uu_re[i - num_dmx][j - num_dmx], 1 ); // q_cov_uu_re-1 move32(); } } q_cov_uu_re = sub( q_cov_uu_re, 1 ); - recon_uu_re[0][0] = L_shr( recon_uu_re[0][0], 1 ); + recon_uu_re[0][0] = L_shr( recon_uu_re[0][0], 1 ); // q_cov_uu_re move32(); } } - cov_uu_re[0][0] = L_sub( cov_uu_re[0][0], recon_uu_re[0][0] ); + cov_uu_re[0][0] = L_sub( cov_uu_re[0][0], recon_uu_re[0][0] ); // q_cov_uu_re move32(); } ELSE IF( EQ_16( num_dmx, 4 ) ) @@ -2696,9 +2696,9 @@ static void ivas_calc_p_coeffs_per_band_enc_fx( { FOR( k = 0; k < num_dmx - 1; k++ ) { - W_tmp = W_mult0_32_32( pSparMd->band_coeffs[b_ts_idx].C_re_fx[i][k], cov_dd_re[k][m] ); + W_tmp = W_mult0_32_32( pSparMd->band_coeffs[b_ts_idx].C_re_fx[i][k], cov_dd_re[k][m] ); // q_C_re+q_cov_dd_re q_tmp = sub( W_norm( W_tmp ), 2 ); - re = W_extract_h( W_shl( W_tmp, q_tmp ) ); + re = W_extract_h( W_shl( W_tmp, q_tmp ) ); // q_C_re+q_cov_dd_re+q_tmp-32 q_tmp = sub( add( add( q_C_re, q_tmp ), q_cov_dd_re ), 32 ); if ( W_tmp == 0 ) { @@ -2708,29 +2708,29 @@ static void ivas_calc_p_coeffs_per_band_enc_fx( IF( LT_16( q_tmp, q_re1[m] ) ) { - re1[m] = L_shr( re1[m], sub( q_re1[m], q_tmp ) ); + re1[m] = L_shr( re1[m], sub( q_re1[m], q_tmp ) ); // q_tmp move32(); q_re1[m] = q_tmp; move16(); } ELSE { - re = L_shr( re, sub( q_tmp, q_re1[m] ) ); + re = L_shr( re, sub( q_tmp, q_re1[m] ) ); // q_re1[m] } IF( re != 0 ) { test(); IF( W_norm( re ) == 0 || W_norm( re1[m] ) == 0 ) { - re1[m] = L_shr( re1[m], 1 ); + re1[m] = L_shr( re1[m], 1 ); // q_re1[m]-1 move32(); q_re1[m] = sub( q_re1[m], 1 ); move16(); - re = L_shr( re, 1 ); + re = L_shr( re, 1 ); // q_re1[m] } } - re1[m] = L_add( re1[m], re ); + re1[m] = L_add( re1[m], re ); // q_re1[m] move32(); } } @@ -2738,9 +2738,9 @@ static void ivas_calc_p_coeffs_per_band_enc_fx( { FOR( m = 0; m < num_dmx - 1; m++ ) { - W_tmp = W_mult0_32_32( pSparMd->band_coeffs[b_ts_idx].C_re_fx[j][m], re1[m] ); + W_tmp = W_mult0_32_32( pSparMd->band_coeffs[b_ts_idx].C_re_fx[j][m], re1[m] ); // q_C_re+q_re1[m] q_tmp = sub( W_norm( W_tmp ), 2 ); - re = W_extract_h( W_shl( W_tmp, q_tmp ) ); + re = W_extract_h( W_shl( W_tmp, q_tmp ) ); // q_C_re+q_re1[m]+q_tmp-32 q_tmp = sub( add( add( q_C_re, q_tmp ), q_re1[m] ), 32 ); if ( W_tmp == 0 ) { @@ -2750,28 +2750,28 @@ static void ivas_calc_p_coeffs_per_band_enc_fx( IF( LT_16( q_tmp, q_recon_uu_re[i][j] ) ) { - recon_uu_re[i][j] = L_shr( recon_uu_re[i][j], sub( q_recon_uu_re[i][j], q_tmp ) ); + recon_uu_re[i][j] = L_shr( recon_uu_re[i][j], sub( q_recon_uu_re[i][j], q_tmp ) ); // q_tmp move32(); q_recon_uu_re[i][j] = q_tmp; move16(); } ELSE { - re = L_shr( re, sub( q_tmp, q_recon_uu_re[i][j] ) ); + re = L_shr( re, sub( q_tmp, q_recon_uu_re[i][j] ) ); // q_recon_uu_re[i][j] } IF( re != 0 ) { test(); IF( W_norm( re ) == 0 || W_norm( recon_uu_re[i][j] ) == 0 ) { - re1[m] = L_shr( re1[m], 1 ); + re1[m] = L_shr( re1[m], 1 ); // q_recon_uu_re[i][j]-1 move32(); q_recon_uu_re[i][j] = sub( q_recon_uu_re[i][j], 1 ); move16(); - re = L_shr( re, 1 ); + re = L_shr( re, 1 ); // q_recon_uu_re[i][j] } } - recon_uu_re[i][j] = L_add( recon_uu_re[i][j], re ); + recon_uu_re[i][j] = L_add( recon_uu_re[i][j], re ); // q_recon_uu_re[i][j] move32(); } } @@ -2793,7 +2793,7 @@ static void ivas_calc_p_coeffs_per_band_enc_fx( { FOR( j = 0; j < num_ch - num_dmx; j++ ) { - cov_uu_re[i][j] = L_sub( L_shr( cov_uu_re[i][j], sub( q_cov_uu_re, q_tmp ) ), L_shr( recon_uu_re[i][j], sub( q_recon_uu_re[i][j], q_tmp ) ) ); + cov_uu_re[i][j] = L_sub( L_shr( cov_uu_re[i][j], sub( q_cov_uu_re, q_tmp ) ), L_shr( recon_uu_re[i][j], sub( q_recon_uu_re[i][j], q_tmp ) ) ); // q_tmp move32(); } } @@ -2802,13 +2802,13 @@ static void ivas_calc_p_coeffs_per_band_enc_fx( } } - p_norm_scaling = IVAS_P_NORM_SCALING_FX; + p_norm_scaling = IVAS_P_NORM_SCALING_FX; // q31 move32(); test(); if ( ( dtx_vad == 0 ) && EQ_16( num_dmx, 1 ) ) { - p_norm_scaling = IVAS_P_NORM_SCALING_DTX_FX; + p_norm_scaling = IVAS_P_NORM_SCALING_DTX_FX; // q31 move32(); } @@ -2817,33 +2817,33 @@ static void ivas_calc_p_coeffs_per_band_enc_fx( FOR( i = num_dmx; i < num_ch; i++ ) { - trace = W_add( trace, W_deposit32_l( L_abs( cov_uu_re[i - num_dmx][i - num_dmx] ) ) ); + trace = W_add( trace, W_deposit32_l( L_abs( cov_uu_re[i - num_dmx][i - num_dmx] ) ) ); // q_cov_uu_re } - factor = L_max( IVAS_FIX_EPS, postpred_cov_re[0][0] ); + factor = L_max( IVAS_FIX_EPS, postpred_cov_re[0][0] ); // q_postpred_cov_re q_factor = q_postpred_cov_re; move16(); IF( trace != 0 ) { q_factor = W_norm( trace ); - tmp = Mpy_32_32( p_norm_scaling, W_extract_h( W_shl( trace, q_factor ) ) ); - q_factor = sub( add( q_postpred_cov_re, q_factor ), 32 ); + tmp = Mpy_32_32( p_norm_scaling, W_extract_h( W_shl( trace, q_factor ) ) ); // q_cov_uu_re+q_factor-32 + q_factor = sub( add( q_cov_uu_re, q_factor ), 32 ); IF( GT_16( q_factor, q_postpred_cov_re ) ) { - tmp = L_shr( tmp, sub( q_factor, q_postpred_cov_re ) ); + tmp = L_shr( tmp, sub( q_factor, q_postpred_cov_re ) ); // q_postpred_cov_re q_factor = q_postpred_cov_re; move16(); } ELSE { - factor = L_shr( factor, sub( q_postpred_cov_re, q_factor ) ); + factor = L_shr( factor, sub( q_postpred_cov_re, q_factor ) ); // q_factor } - factor = L_max( factor, tmp ); + factor = L_max( factor, tmp ); // q_factor } Word16 factor_exp = 0; move16(); - factor = BASOP_Util_Divide3232_Scale( 1, factor, &factor_exp ); + factor = BASOP_Util_Divide3232_Scale( 1, factor, &factor_exp ); // q=15-(factor_exp+31-(31-q_factor)) factor_exp = add( factor_exp, q_factor ); /* normalise Hermitian (except for rounding) cov_uu */ @@ -2854,14 +2854,14 @@ static void ivas_calc_p_coeffs_per_band_enc_fx( IF( EQ_16( i, j ) ) { /* force diagonal to be real */ - W_tmp = W_mult0_32_32( cov_uu_re[i - num_dmx][j - num_dmx], factor ); + W_tmp = W_mult0_32_32( cov_uu_re[i - num_dmx][j - num_dmx], factor ); /*q_cov_uu_re+15-factor_exp*/ q_tmp = 32; move16(); if ( W_tmp != 0 ) { q_tmp = W_norm( W_tmp ); } - cov_uu_re[i - num_dmx][j - num_dmx] = W_extract_h( W_shl( W_mult0_32_32( cov_uu_re[i - num_dmx][j - num_dmx], factor ), q_tmp ) ); + cov_uu_re[i - num_dmx][j - num_dmx] = W_extract_h( W_shl( W_mult0_32_32( cov_uu_re[i - num_dmx][j - num_dmx], factor ), q_tmp ) ); /*q_cov_uu_re+15-factor_exp+q_tmp-32*/ move32(); q_cov_uu_re_per_value[i - num_dmx][j - num_dmx] = sub( add( add( q_cov_uu_re, sub( 15, factor_exp ) ), q_tmp ), 32 ); move16(); @@ -2884,7 +2884,7 @@ static void ivas_calc_p_coeffs_per_band_enc_fx( FOR( i = num_dmx; i < num_ch; i++ ) { cov_uu_re_exp = sub( 31, q_cov_uu_re_per_value[i - num_dmx][i - num_dmx] ); - cov_uu_re[i - num_dmx][i - num_dmx] = Sqrt32( L_max( 0, cov_uu_re[i - num_dmx][i - num_dmx] ), &cov_uu_re_exp ); + cov_uu_re[i - num_dmx][i - num_dmx] = Sqrt32( L_max( 0, cov_uu_re[i - num_dmx][i - num_dmx] ), &cov_uu_re_exp ); // q=31-cov_uu_re_exp move32(); q_cov_uu_re_per_value[i - num_dmx][i - num_dmx] = sub( 31, cov_uu_re_exp ); move16(); @@ -2898,7 +2898,7 @@ static void ivas_calc_p_coeffs_per_band_enc_fx( { IF( EQ_16( i, j ) ) { - pSparMd->band_coeffs[b_ts_idx].P_re_fx[j - num_dmx] = L_shr( cov_uu_re[i - num_dmx][j - num_dmx], sub( q_cov_uu_re_per_value[i - num_dmx][j - num_dmx], Q28 ) ); + pSparMd->band_coeffs[b_ts_idx].P_re_fx[j - num_dmx] = L_shr( cov_uu_re[i - num_dmx][j - num_dmx], sub( q_cov_uu_re_per_value[i - num_dmx][j - num_dmx], Q28 ) ); // Q28 move32(); } } @@ -2913,7 +2913,7 @@ static void ivas_calc_p_coeffs_per_band_enc_fx( static void ivas_calc_p_coeffs_per_band_fx( ivas_spar_md_t *pSparMd, const Word16 i_ts, - Word32 postpred_cov_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + Word32 postpred_cov_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], // q_postpred_cov_re Word16 q_postpred_cov_re, const Word16 num_ch, const Word16 dtx_vad, @@ -2948,7 +2948,7 @@ static void ivas_calc_p_coeffs_per_band_fx( { FOR( j = num_dmx; j < num_ch; j++ ) { - cov_uu_re[i - num_dmx][j - num_dmx] = postpred_cov_re[i][j]; + cov_uu_re[i - num_dmx][j - num_dmx] = postpred_cov_re[i][j]; // q=q_postpred_cov_re move32(); } } @@ -2961,7 +2961,7 @@ static void ivas_calc_p_coeffs_per_band_fx( { FOR( j = 1; j < num_dmx; j++ ) { - cov_dd_re[i - 1][j - 1] = postpred_cov_re[i][j]; + cov_dd_re[i - 1][j - 1] = postpred_cov_re[i][j]; // q=q_postpred_cov_re move32(); } } @@ -2973,13 +2973,13 @@ static void ivas_calc_p_coeffs_per_band_fx( { Word32 re1, re2; - re1 = W_extract_l( W_shr( W_mult0_32_32( pSparMd->band_coeffs[b_ts_idx].C_re_fx[0][0], cov_dd_re[0][0] ), q_C_re ) ); - re2 = W_extract_l( W_shr( W_mult0_32_32( pSparMd->band_coeffs[b_ts_idx].C_re_fx[1][0], cov_dd_re[0][0] ), q_C_re ) ); + re1 = W_extract_l( W_shr( W_mult0_32_32( pSparMd->band_coeffs[b_ts_idx].C_re_fx[0][0], cov_dd_re[0][0] ), q_C_re ) ); // q_cov_uu_re + re2 = W_extract_l( W_shr( W_mult0_32_32( pSparMd->band_coeffs[b_ts_idx].C_re_fx[1][0], cov_dd_re[0][0] ), q_C_re ) ); // q_cov_uu_re - recon_uu_re[0][0] = W_extract_l( W_shr( W_mult0_32_32( pSparMd->band_coeffs[b_ts_idx].C_re_fx[0][0], re1 ), q_C_re ) ); - recon_uu_re[0][1] = W_extract_l( W_shr( W_mult0_32_32( pSparMd->band_coeffs[b_ts_idx].C_re_fx[1][0], re1 ), q_C_re ) ); - recon_uu_re[1][0] = W_extract_l( W_shr( W_mult0_32_32( pSparMd->band_coeffs[b_ts_idx].C_re_fx[0][0], re2 ), q_C_re ) ); - recon_uu_re[1][1] = W_extract_l( W_shr( W_mult0_32_32( pSparMd->band_coeffs[b_ts_idx].C_re_fx[1][0], re2 ), q_C_re ) ); + recon_uu_re[0][0] = W_extract_l( W_shr( W_mult0_32_32( pSparMd->band_coeffs[b_ts_idx].C_re_fx[0][0], re1 ), q_C_re ) ); // q_cov_uu_re + recon_uu_re[0][1] = W_extract_l( W_shr( W_mult0_32_32( pSparMd->band_coeffs[b_ts_idx].C_re_fx[1][0], re1 ), q_C_re ) ); // q_cov_uu_re + recon_uu_re[1][0] = W_extract_l( W_shr( W_mult0_32_32( pSparMd->band_coeffs[b_ts_idx].C_re_fx[0][0], re2 ), q_C_re ) ); // q_cov_uu_re + recon_uu_re[1][1] = W_extract_l( W_shr( W_mult0_32_32( pSparMd->band_coeffs[b_ts_idx].C_re_fx[1][0], re2 ), q_C_re ) ); // q_cov_uu_re move32(); move32(); move32(); @@ -2989,7 +2989,7 @@ static void ivas_calc_p_coeffs_per_band_fx( { FOR( j = 0; j < 2; j++ ) { - cov_uu_re[i][j] = L_sub( cov_uu_re[i][j], recon_uu_re[i][j] ); + cov_uu_re[i][j] = L_sub( cov_uu_re[i][j], recon_uu_re[i][j] ); // q_cov_uu_re move32(); } } @@ -3004,20 +3004,20 @@ static void ivas_calc_p_coeffs_per_band_fx( FOR( k = 0; k < 2; k++ ) { Word32 re; - re = W_extract_l( W_shr( W_mult0_32_32( pSparMd->band_coeffs[b_ts_idx].C_re_fx[0][k], cov_dd_re[k][j] ), q_C_re ) ); - re1[j] = L_add( re1[j], re ); + re = W_extract_l( W_shr( W_mult0_32_32( pSparMd->band_coeffs[b_ts_idx].C_re_fx[0][k], cov_dd_re[k][j] ), q_C_re ) ); // q_cov_uu_re + re1[j] = L_add( re1[j], re ); // q_cov_uu_re move32(); } } - re2 = W_extract_l( W_shr( W_mult0_32_32( pSparMd->band_coeffs[b_ts_idx].C_re_fx[0][0], re1[0] ), q_C_re ) ); - recon_uu_re[0][0] = re2; + re2 = W_extract_l( W_shr( W_mult0_32_32( pSparMd->band_coeffs[b_ts_idx].C_re_fx[0][0], re1[0] ), q_C_re ) ); // q_cov_uu_re + recon_uu_re[0][0] = re2; // q_cov_uu_re move32(); - re2 = W_extract_l( W_shr( W_mult0_32_32( pSparMd->band_coeffs[b_ts_idx].C_re_fx[0][1], re1[1] ), q_C_re ) ); - recon_uu_re[0][0] = L_add( recon_uu_re[0][0], re2 ); + re2 = W_extract_l( W_shr( W_mult0_32_32( pSparMd->band_coeffs[b_ts_idx].C_re_fx[0][1], re1[1] ), q_C_re ) ); // q_cov_uu_re + recon_uu_re[0][0] = L_add( recon_uu_re[0][0], re2 ); // q_cov_uu_re move32(); - cov_uu_re[0][0] = L_sub( cov_uu_re[0][0], recon_uu_re[0][0] ); + cov_uu_re[0][0] = L_sub( cov_uu_re[0][0], recon_uu_re[0][0] ); // q_cov_uu_re move32(); } ELSE IF( EQ_16( num_dmx, 4 ) ) @@ -3032,8 +3032,8 @@ static void ivas_calc_p_coeffs_per_band_fx( { FOR( k = 0; k < num_dmx - 1; k++ ) { - re = W_extract_l( W_shr( W_mult0_32_32( pSparMd->band_coeffs[b_ts_idx].C_re_fx[i][k], cov_dd_re[k][m] ), q_C_re ) ); - re1[m] = L_add( re1[m], re ); + re = W_extract_l( W_shr( W_mult0_32_32( pSparMd->band_coeffs[b_ts_idx].C_re_fx[i][k], cov_dd_re[k][m] ), q_C_re ) ); // q_cov_uu_re + re1[m] = L_add( re1[m], re ); // q_cov_uu_re move32(); } } @@ -3041,8 +3041,8 @@ static void ivas_calc_p_coeffs_per_band_fx( { FOR( m = 0; m < num_dmx - 1; m++ ) { - re = W_extract_l( W_shr( W_mult0_32_32( pSparMd->band_coeffs[b_ts_idx].C_re_fx[j][m], re1[m] ), q_C_re ) ); - recon_uu_re[i][j] = L_add( recon_uu_re[i][j], re ); + re = W_extract_l( W_shr( W_mult0_32_32( pSparMd->band_coeffs[b_ts_idx].C_re_fx[j][m], re1[m] ), q_C_re ) ); // q_cov_uu_re + recon_uu_re[i][j] = L_add( recon_uu_re[i][j], re ); // q_cov_uu_re move32(); } } @@ -3053,20 +3053,20 @@ static void ivas_calc_p_coeffs_per_band_fx( { FOR( j = 0; j < num_ch - num_dmx; j++ ) { - cov_uu_re[i][j] = L_sub( cov_uu_re[i][j], recon_uu_re[i][j] ); + cov_uu_re[i][j] = L_sub( cov_uu_re[i][j], recon_uu_re[i][j] ); // q_cov_uu_re move32(); } } } } - p_norm_scaling = IVAS_P_NORM_SCALING_FX; + p_norm_scaling = IVAS_P_NORM_SCALING_FX; /*q31*/ move32(); test(); if ( ( dtx_vad == 0 ) && EQ_16( num_dmx, 1 ) ) { - p_norm_scaling = IVAS_P_NORM_SCALING_DTX_FX; + p_norm_scaling = IVAS_P_NORM_SCALING_DTX_FX; /*q31*/ move32(); } @@ -3075,15 +3075,15 @@ static void ivas_calc_p_coeffs_per_band_fx( FOR( i = num_dmx; i < num_ch; i++ ) { - trace = L_add( trace, L_abs( cov_uu_re[i - num_dmx][i - num_dmx] ) ); + trace = L_add( trace, L_abs( cov_uu_re[i - num_dmx][i - num_dmx] ) ); // q_cov_uu_re } - factor = L_max( IVAS_FIX_EPS, postpred_cov_re[0][0] ); - factor = L_max( factor, Mpy_32_32( p_norm_scaling, trace ) ); + factor = L_max( IVAS_FIX_EPS, postpred_cov_re[0][0] ); // q=q_postpred_cov_re + factor = L_max( factor, Mpy_32_32( p_norm_scaling, trace ) ); // q=q_postpred_cov_re Word16 factor_exp = 0; move16(); - factor = BASOP_Util_Divide3232_Scale( L_shl( 1, q_postpred_cov_re ), factor, &factor_exp ); + factor = BASOP_Util_Divide3232_Scale( L_shl( 1, q_postpred_cov_re ), factor, &factor_exp ); // q=15-factor_exp tmp = sub( 15, factor_exp ); /* normalise Hermitian (except for rounding) cov_uu */ @@ -3094,7 +3094,7 @@ static void ivas_calc_p_coeffs_per_band_fx( IF( EQ_16( i, j ) ) { /* force diagonal to be real */ - cov_uu_re[i - num_dmx][j - num_dmx] = W_extract_l( W_shr( W_mult0_32_32( cov_uu_re[i - num_dmx][j - num_dmx], factor ), tmp ) ); + cov_uu_re[i - num_dmx][j - num_dmx] = W_extract_l( W_shr( W_mult0_32_32( cov_uu_re[i - num_dmx][j - num_dmx], factor ), tmp ) ); // q_cov_uu_re move32(); } ELSE @@ -3111,8 +3111,8 @@ static void ivas_calc_p_coeffs_per_band_fx( FOR( i = num_dmx; i < num_ch; i++ ) { cov_uu_re_exp = sub( 31, q_cov_uu_re ); - cov_uu_re[i - num_dmx][i - num_dmx] = Sqrt32( L_max( 0, cov_uu_re[i - num_dmx][i - num_dmx] ), &cov_uu_re_exp ); - cov_uu_re[i - num_dmx][i - num_dmx] = L_shl( cov_uu_re[i - num_dmx][i - num_dmx], sub( q_cov_uu_re, sub( 31, cov_uu_re_exp ) ) ); + cov_uu_re[i - num_dmx][i - num_dmx] = Sqrt32( L_max( 0, cov_uu_re[i - num_dmx][i - num_dmx] ), &cov_uu_re_exp ); // q=31-cov_uu_re_exp + cov_uu_re[i - num_dmx][i - num_dmx] = L_shl( cov_uu_re[i - num_dmx][i - num_dmx], sub( q_cov_uu_re, sub( 31, cov_uu_re_exp ) ) ); // q_cov_uu_re move32(); move32(); } @@ -3124,7 +3124,7 @@ static void ivas_calc_p_coeffs_per_band_fx( { IF( EQ_16( i, j ) ) { - pSparMd->band_coeffs[b_ts_idx].P_re_fx[j - num_dmx] = cov_uu_re[i - num_dmx][j - num_dmx]; + pSparMd->band_coeffs[b_ts_idx].P_re_fx[j - num_dmx] = cov_uu_re[i - num_dmx][j - num_dmx]; // q_cov_uu_re move32(); } } @@ -3149,7 +3149,7 @@ static void ivas_calc_p_coeffs_per_band_fx( static void ivas_calc_c_coeffs_per_band_enc_fx( ivas_spar_md_t *pSparMd, const Word16 i_ts, - Word32 postpred_cov_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + Word32 postpred_cov_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], // q_post_pred_cov_re Word16 q_post_pred_cov_re, const Word16 num_ch, const Word16 num_dmx, @@ -3182,7 +3182,7 @@ static void ivas_calc_c_coeffs_per_band_enc_fx( { FOR( j = 1; j < num_dmx; j++ ) { - cov_ud_re[i - num_dmx][j - 1] = postpred_cov_re[i][j]; + cov_ud_re[i - num_dmx][j - 1] = postpred_cov_re[i][j]; // q_post_pred_cov_re move32(); } } @@ -3196,9 +3196,9 @@ static void ivas_calc_c_coeffs_per_band_enc_fx( { IF( EQ_16( i, j ) ) { - max_val = L_max( max_val, postpred_cov_re[i][j] ); + max_val = L_max( max_val, postpred_cov_re[i][j] ); // q_post_pred_cov_re } - cov_dd_re[i - 1][j - 1] = postpred_cov_re[i][j]; + cov_dd_re[i - 1][j - 1] = postpred_cov_re[i][j]; // q_post_pred_cov_re move32(); } } @@ -3208,10 +3208,10 @@ static void ivas_calc_c_coeffs_per_band_enc_fx( FOR( i = 0; i < sub( num_dmx, 1 ); i++ ) { - trace_cov_dd_re = L_add( trace_cov_dd_re, Mpy_32_32( cov_dd_re[i][i], 10737418 /* 0.005f in Q31*/ ) ); + trace_cov_dd_re = L_add( trace_cov_dd_re, Mpy_32_32( cov_dd_re[i][i], 10737418 /* 0.005f in Q31*/ ) ); // q_post_pred_cov_re } - abs_trace = L_abs( trace_cov_dd_re ); + abs_trace = L_abs( trace_cov_dd_re ); // q_post_pred_cov_re IF( LE_32( abs_trace, IVAS_FIX_EPS ) ) { @@ -3224,12 +3224,12 @@ static void ivas_calc_c_coeffs_per_band_enc_fx( { q_tmp = 1; move16(); - IF( norm_l( max_val ) > 0 ) + if ( norm_l( max_val ) > 0 ) { q_tmp = 0; move16(); } - trace_cov_dd_re = L_shr( trace_cov_dd_re, q_tmp ); + trace_cov_dd_re = L_shr( trace_cov_dd_re, q_tmp ); // q_post_pred_cov_re - q_tmp FOR( i = 0; i < sub( num_dmx, 1 ); i++ ) { FOR( j = 0; j < sub( num_dmx, 1 ); j++ ) @@ -3241,7 +3241,7 @@ static void ivas_calc_c_coeffs_per_band_enc_fx( FOR( i = 0; i < sub( num_dmx, 1 ); i++ ) { - cov_dd_re[i][i] = L_add( trace_cov_dd_re, cov_dd_re[i][i] ); + cov_dd_re[i][i] = L_add( trace_cov_dd_re, cov_dd_re[i][i] ); // q_post_pred_cov_re - q_tmp move32(); } test(); @@ -3268,12 +3268,12 @@ static void ivas_calc_c_coeffs_per_band_enc_fx( move64(); FOR( k = 0; k < sub( num_dmx, 1 ); k++ ) { - C_re_fx[i][j] = W_add_nosat( C_re_fx[i][j], W_mult0_32_32( cov_ud_re[i][k], cov_dd_re_inv[k][j] ) ); + C_re_fx[i][j] = W_add_nosat( C_re_fx[i][j], W_mult0_32_32( cov_ud_re[i][k], cov_dd_re_inv[k][j] ) ); // q_post_pred_cov_re+q_cov_dd_re_inv move64(); } - IF( LT_64( W_max_val, W_abs( C_re_fx[i][j] ) ) ) + if ( LT_64( W_max_val, W_abs( C_re_fx[i][j] ) ) ) { - W_max_val = W_abs( C_re_fx[i][j] ); + W_max_val = W_abs( C_re_fx[i][j] ); // q_post_pred_cov_re+q_cov_dd_re_inv } } } @@ -3284,7 +3284,7 @@ static void ivas_calc_c_coeffs_per_band_enc_fx( { FOR( j = 0; j < sub( num_dmx, 1 ); j++ ) { - pSparMd->band_coeffs[b_ts_idx].C_re_fx[i][j] = W_extract_l( W_shr( C_re_fx[i][j], tmp ) ); + pSparMd->band_coeffs[b_ts_idx].C_re_fx[i][j] = W_extract_l( W_shr( C_re_fx[i][j], tmp ) ); // q_post_pred_cov_re+q_cov_dd_re_inv-tmp move32(); } } @@ -3299,7 +3299,7 @@ static void ivas_calc_c_coeffs_per_band_enc_fx( static void ivas_calc_c_coeffs_per_band_fx( ivas_spar_md_t *pSparMd, const Word16 i_ts, - Word32 postpred_cov_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + Word32 postpred_cov_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], /*q_post_pred_cov_re*/ Word16 q_post_pred_cov_re, const Word16 num_ch, const Word16 num_dmx, @@ -3331,7 +3331,7 @@ static void ivas_calc_c_coeffs_per_band_fx( { FOR( j = 1; j < num_dmx; j++ ) { - cov_ud_re[i - num_dmx][j - 1] = postpred_cov_re[i][j]; + cov_ud_re[i - num_dmx][j - 1] = postpred_cov_re[i][j]; // q_post_pred_cov_re move32(); } } @@ -3340,7 +3340,7 @@ static void ivas_calc_c_coeffs_per_band_fx( { FOR( j = 1; j < num_dmx; j++ ) { - cov_dd_re[i - 1][j - 1] = postpred_cov_re[i][j]; + cov_dd_re[i - 1][j - 1] = postpred_cov_re[i][j]; // q_post_pred_cov_re move32(); } } @@ -3350,11 +3350,11 @@ static void ivas_calc_c_coeffs_per_band_fx( FOR( i = 0; i < num_dmx - 1; i++ ) { - trace_cov_dd_re = L_add( trace_cov_dd_re, cov_dd_re[i][i] ); + trace_cov_dd_re = L_add( trace_cov_dd_re, cov_dd_re[i][i] ); // q_post_pred_cov_re } - trace_cov_dd_re = Mpy_32_32( trace_cov_dd_re, 10737418 /* 0.005f in Q31*/ ); + trace_cov_dd_re = Mpy_32_32( trace_cov_dd_re, 10737418 /* 0.005f in Q31*/ ); // q_post_pred_cov_re - abs_trace = L_abs( trace_cov_dd_re ); + abs_trace = L_abs( trace_cov_dd_re ); // q_post_pred_cov_re IF( LE_32( abs_trace, IVAS_FIX_EPS ) ) { @@ -3367,7 +3367,7 @@ static void ivas_calc_c_coeffs_per_band_fx( { FOR( i = 0; i < sub( num_dmx, 1 ); i++ ) { - cov_dd_re[i][i] = L_add( trace_cov_dd_re, cov_dd_re[i][i] ); + cov_dd_re[i][i] = L_add( trace_cov_dd_re, cov_dd_re[i][i] ); // q_post_pred_cov_re move32(); } test(); @@ -3394,12 +3394,12 @@ static void ivas_calc_c_coeffs_per_band_fx( move64(); FOR( k = 0; k < sub( num_dmx, 1 ); k++ ) { - C_re_fx[i][j] = W_add_nosat( C_re_fx[i][j], W_mult0_32_32( cov_ud_re[i][k], cov_dd_re_inv[k][j] ) ); + C_re_fx[i][j] = W_add_nosat( C_re_fx[i][j], W_mult0_32_32( cov_ud_re[i][k], cov_dd_re_inv[k][j] ) ); // q_post_pred_cov_re+q_cov_dd_re_inv move64(); } - IF( LT_64( max_val, W_abs( C_re_fx[i][j] ) ) ) + if ( LT_64( max_val, W_abs( C_re_fx[i][j] ) ) ) { - max_val = W_abs( C_re_fx[i][j] ); + max_val = W_abs( C_re_fx[i][j] ); // q_post_pred_cov_re+q_cov_dd_re_inv } } } @@ -3410,7 +3410,7 @@ static void ivas_calc_c_coeffs_per_band_fx( { FOR( j = 0; j < sub( num_dmx, 1 ); j++ ) { - pSparMd->band_coeffs[b_ts_idx].C_re_fx[i][j] = W_extract_l( W_shr( C_re_fx[i][j], tmp ) ); + pSparMd->band_coeffs[b_ts_idx].C_re_fx[i][j] = W_extract_l( W_shr( C_re_fx[i][j], tmp ) ); // q_post_pred_cov_re+q_cov_dd_re_inv-tmp move32(); } } @@ -3435,10 +3435,10 @@ static void ivas_calc_c_coeffs_per_band_fx( void ivas_calc_c_p_coeffs_enc_fx( ivas_spar_md_t *pSparMd, - Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], /*q_cov_real*/ Word16 *q_cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], const Word16 i_ts, - Word32 ***mixer_mat, + Word32 ***mixer_mat, /*q_mixer_mat*/ Word16 q_mixer_mat, const Word16 num_ch, const Word16 num_dmx, @@ -3448,8 +3448,12 @@ void ivas_calc_c_p_coeffs_enc_fx( const Word16 dyn_active_w_flag ) { Word16 i, j, q_postpred_cov_re; - Word32 postpred_cov_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH] = { 0 }; + Word32 postpred_cov_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH]; + FOR( i = 0; i < IVAS_SPAR_MAX_CH; i++ ) + { + set_zero_fx( postpred_cov_re[i], IVAS_SPAR_MAX_CH ); + } IF( NE_16( num_dmx, num_ch ) ) { ivas_calc_post_pred_per_band_enc_fx( cov_real, q_cov_real, mixer_mat, q_mixer_mat, num_ch, band_idx, postpred_cov_re, &q_postpred_cov_re ); @@ -3494,10 +3498,10 @@ void ivas_calc_c_p_coeffs_enc_fx( void ivas_calc_c_p_coeffs_fx( ivas_spar_md_t *pSparMd, - Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], /*q_cov_real*/ Word16 q_cov_real, const Word16 i_ts, - Word32 ***mixer_mat, + Word32 ***mixer_mat, /*q_mixer_mat*/ Word16 q_mixer_mat, const Word16 num_ch, const Word16 num_dmx, @@ -3556,40 +3560,40 @@ void ivas_calc_c_p_coeffs_fx( #ifdef IVAS_FLOAT_FIXED static void ivas_calc_mat_det_fx( - Word32 in_re[MAX_MAT_DIM][MAX_MAT_DIM], + Word32 in_re[MAX_MAT_DIM][MAX_MAT_DIM], /*q_in_re*/ Word16 q_in_re, const Word16 dim, - Word64 *det_re, + Word64 *det_re, /*q_det_re*/ Word16 *q_det_re ) { IF( EQ_16( dim, IVAS_MAT_DIM_3 ) ) { Word64 re1, re2, re; - re1 = W_mult0_32_32( in_re[1][1], in_re[2][2] ); - re2 = W_mult0_32_32( in_re[1][2], in_re[2][1] ); - re = W_sub_nosat( re1, re2 ); + re1 = W_mult0_32_32( in_re[1][1], in_re[2][2] ); /* 2*q_in_re */ + re2 = W_mult0_32_32( in_re[1][2], in_re[2][1] ); /* 2*q_in_re */ + re = W_sub_nosat( re1, re2 ); /* 2*q_in_re */ - re1 = W_mult0_32_32( in_re[0][0], W_extract_h( re ) ); + re1 = W_mult0_32_32( in_re[0][0], W_extract_h( re ) ); /* 3*q_in_re - 32 */ - *det_re = re1; + *det_re = re1; /* 3*q_in_re - 32 */ move64(); - re1 = W_mult0_32_32( in_re[1][0], in_re[2][2] ); - re2 = W_mult0_32_32( in_re[1][2], in_re[2][0] ); - re = W_sub_nosat( re1, re2 ); + re1 = W_mult0_32_32( in_re[1][0], in_re[2][2] ); /* 2*q_in_re */ + re2 = W_mult0_32_32( in_re[1][2], in_re[2][0] ); /* 2*q_in_re */ + re = W_sub_nosat( re1, re2 ); /* 2*q_in_re */ - re1 = W_mult0_32_32( in_re[0][1], W_extract_h( re ) ); + re1 = W_mult0_32_32( in_re[0][1], W_extract_h( re ) ); /* 3*q_in_re - 32 */ - *det_re = W_sub_nosat( *det_re, re1 ); + *det_re = W_sub_nosat( *det_re, re1 ); /* 3*q_in_re - 32 */ move64(); - re1 = W_mult0_32_32( in_re[1][0], in_re[2][1] ); - re2 = W_mult0_32_32( in_re[1][1], in_re[2][0] ); - re = W_sub_nosat( re1, re2 ); + re1 = W_mult0_32_32( in_re[1][0], in_re[2][1] ); /* 2*q_in_re */ + re2 = W_mult0_32_32( in_re[1][1], in_re[2][0] ); /* 2*q_in_re */ + re = W_sub_nosat( re1, re2 ); /* 2*q_in_re */ - re1 = W_mult0_32_32( in_re[0][2], W_extract_h( re ) ); + re1 = W_mult0_32_32( in_re[0][2], W_extract_h( re ) ); /* 3*q_in_re - 32 */ - *det_re = W_add_nosat( *det_re, re1 ); + *det_re = W_add_nosat( *det_re, re1 ); /* 3*q_in_re - 32 */ move64(); *q_det_re = add( q_in_re, sub( add( q_in_re, q_in_re ), 32 ) ); @@ -3598,16 +3602,16 @@ static void ivas_calc_mat_det_fx( ELSE IF( EQ_16( dim, IVAS_MAT_DIM_2 ) ) { Word64 re1, re2; - re1 = W_mult0_32_32( in_re[0][0], in_re[1][1] ); - re2 = W_mult0_32_32( in_re[0][1], in_re[1][0] ); - *det_re = W_sub_nosat( re1, re2 ); + re1 = W_mult0_32_32( in_re[0][0], in_re[1][1] ); /* 2*q_in_re */ + re2 = W_mult0_32_32( in_re[0][1], in_re[1][0] ); /* 2*q_in_re */ + *det_re = W_sub_nosat( re1, re2 ); /* 2*q_in_re */ move64(); *q_det_re = add( q_in_re, q_in_re ); move16(); } ELSE IF( EQ_16( dim, IVAS_MAT_DIM_1 ) ) { - *det_re = in_re[0][0]; + *det_re = in_re[0][0]; /*q_in_re*/ move32(); *q_det_re = q_in_re; move16(); @@ -3632,8 +3636,8 @@ static void ivas_calc_mat_det_fx( #ifdef IVAS_FLOAT_FIXED static void ivas_get_mat_cofactor_fx( - Word32 in_re[MAX_MAT_DIM][MAX_MAT_DIM], - Word32 out_re[MAX_MAT_DIM][MAX_MAT_DIM], + Word32 in_re[MAX_MAT_DIM][MAX_MAT_DIM], /*qx*/ + Word32 out_re[MAX_MAT_DIM][MAX_MAT_DIM], /*qx*/ const Word16 row, const Word16 col ) { @@ -3649,7 +3653,7 @@ static void ivas_get_mat_cofactor_fx( test(); IF( NE_16( i, row ) && NE_16( j, col ) ) { - out_re[r][c] = in_re[i][j]; + out_re[r][c] = in_re[i][j]; /*qx*/ move64(); c = add( c, 1 ); } @@ -3677,10 +3681,10 @@ static void ivas_get_mat_cofactor_fx( #ifdef IVAS_FLOAT_FIXED static void ivas_calc_mat_inv_fx( - Word32 in_re[MAX_MAT_DIM][MAX_MAT_DIM], + Word32 in_re[MAX_MAT_DIM][MAX_MAT_DIM], /*q_in_re*/ Word16 q_in_re, const Word16 dim, - Word32 out_re[MAX_MAT_DIM][MAX_MAT_DIM], + Word32 out_re[MAX_MAT_DIM][MAX_MAT_DIM], /*q_out_re*/ Word16 *q_out_re ) { Word64 det; @@ -3689,7 +3693,7 @@ static void ivas_calc_mat_inv_fx( IF( EQ_16( dim, IVAS_MAT_DIM_1 ) ) { - det = W_mult0_32_32( in_re[0][0], in_re[0][0] ); + det = W_mult0_32_32( in_re[0][0], in_re[0][0] ); /* 2*q_in_re */ /* assert to catch cases when input is singular matrix*/ assert( det > 0 ); @@ -3698,10 +3702,10 @@ static void ivas_calc_mat_inv_fx( // dbl_out_re[0][0] = dbl_in_re[0][0] * det = dbl_in_re[0][0] * (1 / (dbl_in_re[0][0] * dbl_in_re[0][0])); // dbl_out_re[0][0] = 1 / dbl_in_re[0][0]; - one_by_det = BASOP_Util_Divide3232_Scale( 1, in_re[0][0], &q_tmp ); + one_by_det = BASOP_Util_Divide3232_Scale( 1, in_re[0][0], &q_tmp ); /*q=15-(q_tmp-(0-q_in_re))*/ q_one_by_det = sub( 15, add( q_tmp, q_in_re ) ); - out_re[0][0] = one_by_det; + out_re[0][0] = one_by_det; /*q=q_one_by_det*/ move32(); *q_out_re = q_one_by_det; move16(); @@ -3715,22 +3719,22 @@ static void ivas_calc_mat_inv_fx( q_tmp = W_norm( det_re ); q_tmp = s_max( sub( 32, q_tmp ), 0 ); - det_re = W_shr( det_re, q_tmp ); + det_re = W_shr( det_re, q_tmp ); /*q_det_re-q_tmp*/ q_det_re = sub( q_det_re, q_tmp ); - det = W_mult0_32_32( W_extract_l( det_re ), W_extract_l( det_re ) ); + det = W_mult0_32_32( W_extract_l( det_re ), W_extract_l( det_re ) ); /* 2*q_det_re */ /* assert to catch cases when input is singular matrix*/ assert( det > 0 ); one_by_det = BASOP_Util_Divide3232_Scale( 1, W_extract_l( det_re ), &q_tmp ); // Q = (15 - (q_tmp + q_det_re)) - out_re[0][0] = Mpy_32_16_1( in_re[1][1], one_by_det ); + out_re[0][0] = Mpy_32_16_1( in_re[1][1], one_by_det ); /*q_in_re+(15 - (q_tmp + q_det_re)) -15=>q_in_re-(q_tmp + q_det_re)*/ - out_re[0][1] = L_negate( Mpy_32_16_1( in_re[0][1], one_by_det ) ); + out_re[0][1] = L_negate( Mpy_32_16_1( in_re[0][1], one_by_det ) ); /*q_in_re-(q_tmp + q_det_re)*/ - out_re[1][0] = L_negate( Mpy_32_16_1( in_re[1][0], one_by_det ) ); + out_re[1][0] = L_negate( Mpy_32_16_1( in_re[1][0], one_by_det ) ); /*q_in_re-(q_tmp + q_det_re)*/ - out_re[1][1] = Mpy_32_16_1( in_re[0][0], one_by_det ); + out_re[1][1] = Mpy_32_16_1( in_re[0][0], one_by_det ); /*q_in_re-(q_tmp + q_det_re)*/ move32(); move32(); move32(); @@ -3752,7 +3756,7 @@ static void ivas_calc_mat_inv_fx( q_tmp = W_norm( det_re ); q_tmp = s_max( sub( 32, q_tmp ), 0 ); - det_re = W_shr( det_re, q_tmp ); + det_re = W_shr( det_re, q_tmp ); /*q_det_re-q_tmp*/ q_det_re = sub( q_det_re, q_tmp ); if ( det_re == 0 ) @@ -3761,7 +3765,7 @@ static void ivas_calc_mat_inv_fx( move64(); } - one_by_det = BASOP_Util_Divide3232_Scale( 1, W_extract_l( det_re ), &q_tmp ); + one_by_det = BASOP_Util_Divide3232_Scale( 1, W_extract_l( det_re ), &q_tmp ); /*15-(q_tmp-(0-q_det_re))*/ q_one_by_det = sub( 15, add( q_tmp, q_det_re ) ); FOR( i = 0; i < dim; i++ ) @@ -3771,9 +3775,9 @@ static void ivas_calc_mat_inv_fx( ivas_get_mat_cofactor_fx( in_re, fac_re, i, j ); ivas_calc_mat_det_fx( fac_re, q_in_re, IVAS_MAT_DIM_2, &W_tmp, &q_W_tmp ); - out_re[j][i] = Mpy_32_16_1( W_extract_h( W_tmp ), one_by_det ); + out_re[j][i] = Mpy_32_16_1( W_extract_h( W_tmp ), one_by_det ); /*q_W_tmp-32+q_one_by_det-15*/ move32(); - out_re[j][i] = W_extract_l( W_mult0_32_32( out_re[j][i], sign ) ); + out_re[j][i] = W_extract_l( W_mult0_32_32( out_re[j][i], sign ) ); /*q_W_tmp-32+q_one_by_det-15*/ move32(); IF( s_and( add( i, j ), 1 ) == 0 ) @@ -3811,7 +3815,7 @@ static void ivas_calc_mat_inv_fx( #ifdef IVAS_FLOAT_FIXED static Word16 ivas_is_mat_inv_fx( - Word32 in_re[MAX_MAT_DIM][MAX_MAT_DIM], + Word32 in_re[MAX_MAT_DIM][MAX_MAT_DIM], /*q_in_re*/ Word16 q_in_re, const Word16 dim ) { @@ -3825,10 +3829,10 @@ static Word16 ivas_is_mat_inv_fx( tmp = W_norm( det_re ); tmp = s_max( sub( 32, tmp ), 0 ); - det_re = W_shr( det_re, tmp ); + det_re = W_shr( det_re, tmp ); /*q_det_re-tmp*/ q_det_re = sub( q_det_re, tmp ); - det = W_mult0_32_32( W_extract_l( det_re ), W_extract_l( det_re ) ); + det = W_mult0_32_32( W_extract_l( det_re ), W_extract_l( det_re ) ); /*2*q_det_re*/ if ( LE_64( det, IVAS_FIX_EPS ) ) { @@ -3850,12 +3854,12 @@ static Word16 ivas_is_mat_inv_fx( #ifdef IVAS_FLOAT_FIXED void ivas_compute_spar_params_enc_fx( - Word32 *cov_real_fx[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + Word32 *cov_real_fx[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], /*q_cov_real*/ Word16 *q_cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], - Word32 dm_fv_re_fx[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], + Word32 dm_fv_re_fx[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], /*q_dm_fv_re*/ Word16 *q_dm_fv_re, const Word16 i_ts, - Word32 ***mixer_mat_fx, + Word32 ***mixer_mat_fx, /*q_mixer_mat*/ Word16 *q_mixer_mat, const Word16 start_band, const Word16 end_band, @@ -3866,7 +3870,7 @@ void ivas_compute_spar_params_enc_fx( const Word16 active_w_vlbr, ivas_spar_md_com_cfg *hSparCfg, ivas_spar_md_t *hSparMd, - Word32 *pWscale, + Word32 *pWscale, /*q_Wscale*/ Word16 *q_Wscale, const Word16 from_dirac, const Word16 dyn_active_w_flag ) @@ -3892,22 +3896,22 @@ void ivas_compute_spar_params_enc_fx( move16(); } - Word16 onebyscale_fx = BASOP_Util_Divide3232_Scale( 1, pWscale[b], &tmp_exp ); + Word16 onebyscale_fx = BASOP_Util_Divide3232_Scale( 1, pWscale[b], &tmp_exp ); /*q=15-(tmp_exp+(15-(15-q_Wscale)))=>15-(tmp_exp+q_Wscale)*/ q_tmp = sub( sub( 15, tmp_exp ), q_Wscale[b] ); tmp = sub( add( q_pred_coeffs_re, q_tmp ), 15 ); FOR( i = 0; i < sub( num_ch, 1 ); i++ ) { - hSparMd->band_coeffs[b + ( i_ts * IVAS_MAX_NUM_BANDS )].pred_re_fx[i] = L_shl( Mpy_32_16_1( pred_coeffs_re_fx[i][b], onebyscale_fx ), sub( Q28, tmp ) ); + hSparMd->band_coeffs[b + ( i_ts * IVAS_MAX_NUM_BANDS )].pred_re_fx[i] = L_shl( Mpy_32_16_1( pred_coeffs_re_fx[i][b], onebyscale_fx ), sub( Q28, tmp ) ); // Q28 move32(); } // hSparMd->band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].q_pred_re_fx = sub(add(q_pred_coeffs, q_tmp), 15); - hSparMd->band_coeffs[( b + ( i_ts * IVAS_MAX_NUM_BANDS ) )].q_pred_re_fx = Q28; + hSparMd->band_coeffs[b + ( i_ts * IVAS_MAX_NUM_BANDS )].q_pred_re_fx = Q28; move16(); FOR( i = 0; i < num_ch; i++ ) { - mixer_mat_fx[0][i][b] = W_extract_l( W_shr( W_mult0_32_32( mixer_mat_fx[0][i][b], pWscale[b] ), q_Wscale[b] ) ); + mixer_mat_fx[0][i][b] = W_extract_l( W_shr( W_mult0_32_32( mixer_mat_fx[0][i][b], pWscale[b] ), q_Wscale[b] ) ); /*q_mixer_mat*/ move32(); } } @@ -3928,12 +3932,12 @@ void ivas_compute_spar_params_enc_fx( void ivas_compute_spar_params_fx( - Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], /*q_cov_real*/ Word16 q_cov_real, - Word32 dm_fv_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], + Word32 dm_fv_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], /*q_dm_fv_re*/ Word16 *q_dm_fv_re, const Word16 i_ts, - Word32 ***mixer_mat_fx, + Word32 ***mixer_mat_fx, /*q_mixer_mat*/ Word16 *q_mixer_mat, const Word16 start_band, const Word16 end_band, @@ -3944,7 +3948,7 @@ void ivas_compute_spar_params_fx( const Word16 active_w_vlbr, ivas_spar_md_com_cfg *hSparCfg, ivas_spar_md_t *hSparMd, - Word32 *pWscale_fx, + Word32 *pWscale_fx, /*q_pWscale*/ Word16 *q_pWscale, const Word16 from_dirac, const Word16 dyn_active_w_flag ) @@ -3963,23 +3967,23 @@ void ivas_compute_spar_params_fx( FOR( b = start_band; b < end_band; b++ ) { Word16 tmp_exp, q_tmp, tmp; - Word16 onebyscale_fx = BASOP_Util_Divide3232_Scale( 1, pWscale_fx[b], &tmp_exp ); + Word16 onebyscale_fx = BASOP_Util_Divide3232_Scale( 1, pWscale_fx[b], &tmp_exp ); /*15-(tmp_exp+q_pWscale[b])*/ q_tmp = sub( sub( 15, tmp_exp ), q_pWscale[b] ); tmp = sub( add( q_pred_coeffs, q_tmp ), 15 ); FOR( i = 0; i < sub( num_ch, 1 ); i++ ) { - hSparMd->band_coeffs[b + ( i_ts * IVAS_MAX_NUM_BANDS )].pred_re_fx[i] = Mpy_32_16_1( pred_coeffs_re[i][b], onebyscale_fx ); + hSparMd->band_coeffs[b + ( i_ts * IVAS_MAX_NUM_BANDS )].pred_re_fx[i] = Mpy_32_16_1( pred_coeffs_re[i][b], onebyscale_fx ); // q=tmp move32(); IF( tmp < 0 ) { tmp = negate( tmp ); - hSparMd->band_coeffs[b + ( i_ts * IVAS_MAX_NUM_BANDS )].pred_re_fx[i] = L_shl( hSparMd->band_coeffs[b + ( i_ts * IVAS_MAX_NUM_BANDS )].pred_re_fx[i], add( tmp, 22 ) ); + hSparMd->band_coeffs[b + ( i_ts * IVAS_MAX_NUM_BANDS )].pred_re_fx[i] = L_shl( hSparMd->band_coeffs[b + ( i_ts * IVAS_MAX_NUM_BANDS )].pred_re_fx[i], add( tmp, 22 ) ); // q22 move32(); } ELSE { - hSparMd->band_coeffs[b + ( i_ts * IVAS_MAX_NUM_BANDS )].pred_re_fx[i] = L_shr( hSparMd->band_coeffs[b + ( i_ts * IVAS_MAX_NUM_BANDS )].pred_re_fx[i], sub( tmp, 22 ) ); + hSparMd->band_coeffs[b + ( i_ts * IVAS_MAX_NUM_BANDS )].pred_re_fx[i] = L_shr( hSparMd->band_coeffs[b + ( i_ts * IVAS_MAX_NUM_BANDS )].pred_re_fx[i], sub( tmp, 22 ) ); // q22 move32(); } } @@ -3989,7 +3993,7 @@ void ivas_compute_spar_params_fx( FOR( i = 0; i < num_ch; i++ ) { - mixer_mat_fx[0][i][b] = W_extract_l( W_shr( W_mult0_32_32( mixer_mat_fx[0][i][b], pWscale_fx[b] ), q_pWscale[b] ) ); + mixer_mat_fx[0][i][b] = W_extract_l( W_shr( W_mult0_32_32( mixer_mat_fx[0][i][b], pWscale_fx[b] ), q_pWscale[b] ) ); /*q_mixer_mat*/ move32(); } } @@ -4007,11 +4011,11 @@ void ivas_compute_spar_params_fx( IF( NE_16( ndm, 1 ) ) { #ifdef MSAN_FIX - FOR( i = 0; i < sub( num_ch, ndm ); i++ ) + FOR( i = 0; i < ( num_ch - ndm ); i++ ) { FOR( Word16 j = 0; j < sub( ndm, 1 ); j++ ) { - hSparMd->band_coeffs[b + ( i_ts * IVAS_MAX_NUM_BANDS )].C_re_fx[i][j] = L_shr( hSparMd->band_coeffs[b + ( i_ts * IVAS_MAX_NUM_BANDS )].C_re_fx[i][j], sub( q_tmp, 22 ) ); + hSparMd->band_coeffs[b + ( i_ts * IVAS_MAX_NUM_BANDS )].C_re_fx[i][j] = L_shr( hSparMd->band_coeffs[b + ( i_ts * IVAS_MAX_NUM_BANDS )].C_re_fx[i][j], sub( q_tmp, 22 ) ); // q22 move32(); } } @@ -4033,10 +4037,10 @@ void ivas_compute_spar_params_fx( FOR( Word16 j = 0; j < sub( IVAS_SPAR_MAX_CH, 1 ); j++ ) { - hSparMd->band_coeffs[b + ( i_ts * IVAS_MAX_NUM_BANDS )].P_re_fx[j] = L_shr( hSparMd->band_coeffs[b + ( i_ts * IVAS_MAX_NUM_BANDS )].P_re_fx[j], sub( q_tmp, 22 ) ); + hSparMd->band_coeffs[b + ( i_ts * IVAS_MAX_NUM_BANDS )].P_re_fx[j] = L_shr( hSparMd->band_coeffs[b + ( i_ts * IVAS_MAX_NUM_BANDS )].P_re_fx[j], sub( q_tmp, 22 ) ); // q22 move32(); } - hSparMd->band_coeffs[b + imult1616( i_ts, IVAS_MAX_NUM_BANDS )].q_P_re_fx = Q22; + hSparMd->band_coeffs[b + ( i_ts * IVAS_MAX_NUM_BANDS )].q_P_re_fx = Q22; move16(); } } @@ -4052,9 +4056,9 @@ void ivas_compute_spar_params_fx( * *-----------------------------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED -Word32 diff_norm_order1_table[4] = { 0, 805306368, 402653184, 268435456 }; -Word32 diff_norm_order2_table[6] = { 0, 1342177280, 671088640, 447392416, 335544320, 268435456 }; -Word32 diff_norm_order3_table[8] = { 0, 1879048192, 939524096, 626349376, 469762048, 375809632, 313174688, 268435456 }; +Word32 diff_norm_order1_table[4] = { 0, 805306368, 402653184, 268435456 }; // q28 +Word32 diff_norm_order2_table[6] = { 0, 1342177280, 671088640, 447392416, 335544320, 268435456 }; // q28 +Word32 diff_norm_order3_table[8] = { 0, 1879048192, 939524096, 626349376, 469762048, 375809632, 313174688, 268435456 }; // q28 #define EPSILON_FX_THR 70 #define ONE_BY_THREE_Q31 715827882 #define ONE_BY_FIVE_Q31 429496729 @@ -4064,7 +4068,7 @@ void ivas_get_spar_md_from_dirac_fx( Word32 ele_dirac_fx[IVAS_MAX_NUM_BANDS][MAX_PARAM_SPATIAL_SUBFRAMES], // Q22 Word32 diffuseness_fx[IVAS_MAX_NUM_BANDS], // Q30 const Word16 n_ts, - Word32 ***mixer_mat_fx, + Word32 ***mixer_mat_fx, /*q_mixer_mat_fx*/ Word16 *q_mixer_mat_fx, ivas_spar_md_t *hSpar_md, ivas_spar_md_com_cfg *hSpar_md_cfg, @@ -4147,36 +4151,36 @@ void ivas_get_spar_md_from_dirac_fx( move32(); FOR( i = 0; i < max( 0, sub( foa_ch, ndm ) ); i++ ) { - P_norm_fx[0] = L_add( P_norm_fx[0], Mpy_32_32( hSpar_md->band_coeffs[start_band - 1].P_re_fx[i], hSpar_md->band_coeffs[start_band - 1].P_re_fx[i] ) ); + P_norm_fx[0] = L_add( P_norm_fx[0], Mpy_32_32( hSpar_md->band_coeffs[start_band - 1].P_re_fx[i], hSpar_md->band_coeffs[start_band - 1].P_re_fx[i] ) ); // q25 move32(); } - P_norm_fx[0] = Mpy_32_32( L_shl( P_norm_fx[0], 3 ), diff_norm_order1_table[min( diff_norm_order1_fx, max( 0, sub( foa_ch, ndm ) ) )] ); + P_norm_fx[0] = Mpy_32_32( L_shl( P_norm_fx[0], 3 ), diff_norm_order1_table[min( diff_norm_order1_fx, max( 0, sub( foa_ch, ndm ) ) )] ); // q25 move32(); P_norm_fx[1] = 0; move32(); - FOR( ; i < max( 0, sub( min( num_ch, hoa2_ch ), ndm ) ); i++ ) + FOR( ; i < max( 0, ( min( num_ch, hoa2_ch ) - ndm ) ); i++ ) { - P_norm_fx[1] = L_add( P_norm_fx[1], Mpy_32_32( hSpar_md->band_coeffs[start_band - 1].P_re_fx[i], hSpar_md->band_coeffs[start_band - 1].P_re_fx[i] ) ); + P_norm_fx[1] = L_add( P_norm_fx[1], Mpy_32_32( hSpar_md->band_coeffs[start_band - 1].P_re_fx[i], hSpar_md->band_coeffs[start_band - 1].P_re_fx[i] ) ); // q25 move32(); } - P_norm_fx[1] = Mpy_32_32( L_shl( P_norm_fx[1], 3 ), diff_norm_order2_table[min( diff_norm_order2_fx, max( 0, sub( min( num_ch, hoa2_ch ), ndm ) ) )] ); + P_norm_fx[1] = Mpy_32_32( L_shl( P_norm_fx[1], 3 ), diff_norm_order2_table[min( diff_norm_order2_fx, max( 0, ( min( num_ch, hoa2_ch ) - ndm ) ) )] ); // q25 move32(); P_norm_fx[2] = 0; move32(); - FOR( ; i < sub( num_ch, ndm ); i++ ) + FOR( ; i < ( num_ch - ndm ); i++ ) { - P_norm_fx[2] = L_add( P_norm_fx[2], Mpy_32_32( hSpar_md->band_coeffs[start_band - 1].P_re_fx[i], hSpar_md->band_coeffs[start_band - 1].P_re_fx[i] ) ); + P_norm_fx[2] = L_add( P_norm_fx[2], Mpy_32_32( hSpar_md->band_coeffs[start_band - 1].P_re_fx[i], hSpar_md->band_coeffs[start_band - 1].P_re_fx[i] ) ); // q25 move32(); } - P_norm_fx[2] = Mpy_32_32( L_shl( P_norm_fx[2], 3 ), diff_norm_order3_table[min( diff_norm_order3_fx, max( 0, sub( num_ch, ndm ) ) )] ); + P_norm_fx[2] = Mpy_32_32( L_shl( P_norm_fx[2], 3 ), diff_norm_order3_table[min( diff_norm_order3_fx, max( 0, ( num_ch - ndm ) ) )] ); // q25 move32(); - FOR( i = 0; i < max( 0, sub( foa_ch, ndm ) ); i++ ) + FOR( i = 0; i < max( 0, ( foa_ch - ndm ) ); i++ ) { idx = sub( remix_order[i + ndm], ndm ); - P_dir_fact_fx[idx] = Mpy_32_32( hSpar_md->band_coeffs[start_band - 1].P_re_fx[i], hSpar_md->band_coeffs[start_band - 1].P_re_fx[i] ); + P_dir_fact_fx[idx] = Mpy_32_32( hSpar_md->band_coeffs[start_band - 1].P_re_fx[i], hSpar_md->band_coeffs[start_band - 1].P_re_fx[i] ); // q25 move32(); IF( P_dir_fact_fx[idx] == 0 ) { @@ -4185,16 +4189,16 @@ void ivas_get_spar_md_from_dirac_fx( } ELSE { - P_dir_fact_fx[idx] = divide3232( P_dir_fact_fx[idx], max( P_norm_fx[0], IVAS_FIX_EPS ) ); + P_dir_fact_fx[idx] = divide3232( P_dir_fact_fx[idx], L_max( P_norm_fx[0], IVAS_FIX_EPS ) ); // q15 move32(); - P_dir_fact_fx[idx] = L_shl( P_dir_fact_fx[idx], 15 ); + P_dir_fact_fx[idx] = L_shl( P_dir_fact_fx[idx], 15 ); // q30 move32(); } } - FOR( ; i < max( 0, sub( min( num_ch, hoa2_ch ), ndm ) ); i++ ) + FOR( ; i < max( 0, ( min( num_ch, hoa2_ch ) - ndm ) ); i++ ) { idx = sub( remix_order[i + ndm], ndm ); - P_dir_fact_fx[idx] = Mpy_32_32( hSpar_md->band_coeffs[start_band - 1].P_re_fx[i], hSpar_md->band_coeffs[start_band - 1].P_re_fx[i] ); + P_dir_fact_fx[idx] = Mpy_32_32( hSpar_md->band_coeffs[start_band - 1].P_re_fx[i], hSpar_md->band_coeffs[start_band - 1].P_re_fx[i] ); // q25 IF( P_dir_fact_fx[idx] == 0 ) { P_dir_fact_fx[idx] = 0; @@ -4202,16 +4206,16 @@ void ivas_get_spar_md_from_dirac_fx( } ELSE { - P_dir_fact_fx[idx] = divide3232( P_dir_fact_fx[idx], max( P_norm_fx[1], IVAS_FIX_EPS ) ); + P_dir_fact_fx[idx] = divide3232( P_dir_fact_fx[idx], L_max( P_norm_fx[1], IVAS_FIX_EPS ) ); // q15 move32(); - P_dir_fact_fx[idx] = L_shl( P_dir_fact_fx[idx], 15 ); + P_dir_fact_fx[idx] = L_shl( P_dir_fact_fx[idx], 15 ); // q30 move32(); } } - FOR( ; i < sub( num_ch, ndm ); i++ ) + FOR( ; i < ( num_ch - ndm ); i++ ) { idx = sub( remix_order[i + ndm], ndm ); - P_dir_fact_fx[idx] = Mpy_32_32( hSpar_md->band_coeffs[start_band - 1].P_re_fx[i], hSpar_md->band_coeffs[start_band - 1].P_re_fx[i] ); + P_dir_fact_fx[idx] = Mpy_32_32( hSpar_md->band_coeffs[start_band - 1].P_re_fx[i], hSpar_md->band_coeffs[start_band - 1].P_re_fx[i] ); // q25 move32(); IF( P_dir_fact_fx[idx] == 0 ) { @@ -4220,9 +4224,9 @@ void ivas_get_spar_md_from_dirac_fx( } ELSE { - P_dir_fact_fx[idx] = divide3232( P_dir_fact_fx[idx], max( P_norm_fx[2], IVAS_FIX_EPS ) ); + P_dir_fact_fx[idx] = divide3232( P_dir_fact_fx[idx], L_max( P_norm_fx[2], IVAS_FIX_EPS ) ); // q15 move32(); - P_dir_fact_fx[idx] = L_shl( P_dir_fact_fx[idx], 15 ); + P_dir_fact_fx[idx] = L_shl( P_dir_fact_fx[idx], 15 ); // q30 move32(); } } @@ -4242,19 +4246,19 @@ void ivas_get_spar_md_from_dirac_fx( { IF( ele_dirac_fx[band][i_ts] < 0 ) { - elevation = negate( extract_l( L_shr( L_negate( ele_dirac_fx[band][i_ts] ), Q22 ) ) ); + elevation = negate( extract_l( L_shr( L_negate( ele_dirac_fx[band][i_ts] ), Q22 ) ) ); // q0 } ELSE { - elevation = extract_l( L_shr( ele_dirac_fx[band][i_ts], Q22 ) ); + elevation = extract_l( L_shr( ele_dirac_fx[band][i_ts], Q22 ) ); // q0 } IF( azi_dirac_fx[band][i_ts] < 0 ) { - azimuth = negate( extract_l( L_shr( L_negate( azi_dirac_fx[band][i_ts] ), Q22 ) ) ); + azimuth = negate( extract_l( L_shr( L_negate( azi_dirac_fx[band][i_ts] ), Q22 ) ) ); // q0 } ELSE { - azimuth = extract_l( L_shr( azi_dirac_fx[band][i_ts], Q22 ) ); + azimuth = extract_l( L_shr( azi_dirac_fx[band][i_ts], Q22 ) ); // q0 } ivas_dirac_dec_get_response_fx( azimuth, elevation, response_avg_fx, order, Q30 ); } @@ -4262,19 +4266,19 @@ void ivas_get_spar_md_from_dirac_fx( { IF( ele_dirac_fx[band][0] < 0 ) { - elevation = negate( extract_l( L_shr( L_negate( ele_dirac_fx[band][0] ), Q22 ) ) ); + elevation = negate( extract_l( L_shr( L_negate( ele_dirac_fx[band][0] ), Q22 ) ) ); // q0 } ELSE { - elevation = extract_l( L_shr( ele_dirac_fx[band][0], Q22 ) ); + elevation = extract_l( L_shr( ele_dirac_fx[band][0], Q22 ) ); // q0 } IF( azi_dirac_fx[band][0] < 0 ) { - azimuth = negate( extract_l( L_shr( L_negate( azi_dirac_fx[band][0] ), Q22 ) ) ); + azimuth = negate( extract_l( L_shr( L_negate( azi_dirac_fx[band][0] ), Q22 ) ) ); // q0 } ELSE { - azimuth = extract_l( L_shr( azi_dirac_fx[band][0], Q22 ) ); + azimuth = extract_l( L_shr( azi_dirac_fx[band][0], Q22 ) ); // q0 } ivas_dirac_dec_get_response_fx( azimuth, elevation, response_avg_fx, order, Q30 ); } @@ -4284,19 +4288,19 @@ void ivas_get_spar_md_from_dirac_fx( { IF( ele_dirac_fx[band][block] < 0 ) { - elevation = negate( extract_l( L_shr( L_negate( ele_dirac_fx[band][block] ), Q22 ) ) ); + elevation = negate( extract_l( L_shr( L_negate( ele_dirac_fx[band][block] ), Q22 ) ) ); // q0 } ELSE { - elevation = extract_l( L_shr( ele_dirac_fx[band][block], Q22 ) ); + elevation = extract_l( L_shr( ele_dirac_fx[band][block], Q22 ) ); // q0 } IF( azi_dirac_fx[band][block] < 0 ) { - azimuth = negate( extract_l( L_shr( L_negate( azi_dirac_fx[band][block] ), Q22 ) ) ); + azimuth = negate( extract_l( L_shr( L_negate( azi_dirac_fx[band][block] ), Q22 ) ) ); // q0 } ELSE { - azimuth = extract_l( L_shr( azi_dirac_fx[band][block], Q22 ) ); + azimuth = extract_l( L_shr( azi_dirac_fx[band][block], Q22 ) ); // q0 } ivas_dirac_dec_get_response_fx( azimuth, elevation, &( response_fx[block][0] ), order, Q30 ); } @@ -4316,9 +4320,9 @@ void ivas_get_spar_md_from_dirac_fx( move64(); FOR( block = 0; block < MAX_PARAM_SPATIAL_SUBFRAMES; block++ ) { - temp = W_add( temp, W_deposit32_l( response_fx[block][ch] ) ); + temp = W_add( temp, W_deposit32_l( response_fx[block][ch] ) ); // q30 } - response_avg_fx[ch] = W_extract_l( W_shr( temp, 2 ) ); + response_avg_fx[ch] = W_extract_l( W_shr( temp, 2 ) ); // q30 move32(); } @@ -4329,13 +4333,13 @@ void ivas_get_spar_md_from_dirac_fx( move16(); FOR( ch = 1; ch < foa_ch; ch++ ) { - norm_fx = L_add( norm_fx, Mpy_32_32( response_avg_fx[ch], response_avg_fx[ch] ) ); + norm_fx = L_add( norm_fx, Mpy_32_32( response_avg_fx[ch], response_avg_fx[ch] ) ); // q29 } norm_q = sub( 31, ( sub( add( 30, 30 ), 31 ) ) ); IF( norm_fx ) { - norm_fx = Sqrt32( norm_fx, &norm_q ); + norm_fx = Sqrt32( norm_fx, &norm_q ); // q=31-norm_q } ELSE { @@ -4344,33 +4348,33 @@ void ivas_get_spar_md_from_dirac_fx( } IF( norm_q <= 0 ) { - norm_fx = L_shr( norm_fx, ( negate( norm_q ) ) ); + norm_fx = L_shr( norm_fx, ( negate( norm_q ) ) ); // q=31 norm_q = 0; move16(); } - norm_fx = L_shr( norm_fx, sub( 1, norm_q ) ); + norm_fx = L_shr( norm_fx, sub( 1, norm_q ) ); // q30 FOR( ch = 1; ch < foa_ch; ch++ ) { IF( LT_32( norm_fx, EPSILON_FX_THR ) ) { IF( response_avg_fx[ch] != 0 ) { - response_avg_fx[ch] = divide3232( response_avg_fx[ch], EPSILON_FX_THR ); + response_avg_fx[ch] = divide3232( response_avg_fx[ch], EPSILON_FX_THR ); // q15 move32(); } - response_avg_fx[ch] = L_shl( response_avg_fx[ch], 15 ); + response_avg_fx[ch] = L_shl( response_avg_fx[ch], 15 ); // q30 move32(); } ELSE IF( GT_32( response_avg_fx[ch], norm_fx ) ) { - response_avg_fx[ch] = ONE_IN_Q30; + response_avg_fx[ch] = ONE_IN_Q30; // 1 q30 move32(); } ELSE { - response_avg_fx[ch] = divide3232( response_avg_fx[ch], norm_fx ); + response_avg_fx[ch] = divide3232( response_avg_fx[ch], norm_fx ); // q15 move32(); - response_avg_fx[ch] = L_shl( response_avg_fx[ch], 15 ); + response_avg_fx[ch] = L_shl( response_avg_fx[ch], 15 ); // q30 move32(); } } @@ -4380,12 +4384,12 @@ void ivas_get_spar_md_from_dirac_fx( move32(); FOR( ch = foa_ch; ch < min( hoa2_ch_order, num_ch_order ); ch++ ) { - norm_fx = L_add( norm_fx, Mpy_32_32( response_avg_fx[ch], response_avg_fx[ch] ) ); + norm_fx = L_add( norm_fx, Mpy_32_32( response_avg_fx[ch], response_avg_fx[ch] ) ); // q29 } norm_q = sub( 31, ( sub( add( 29, 29 ), 31 ) ) ); IF( norm_fx ) { - norm_fx = Sqrt32( norm_fx, &norm_q ); + norm_fx = Sqrt32( norm_fx, &norm_q ); // q=31-norm_q } ELSE { @@ -4394,45 +4398,46 @@ void ivas_get_spar_md_from_dirac_fx( } IF( norm_q < 0 ) { - norm_fx = L_shr( norm_fx, negate( norm_q ) ); + norm_fx = L_shr( norm_fx, negate( norm_q ) ); // q31 norm_q = 0; move16(); } - norm_fx = L_shr( norm_fx, sub( 1, norm_q ) ); + norm_fx = L_shr( norm_fx, sub( 1, norm_q ) ); // q30 FOR( ch = foa_ch; ch < min( hoa2_ch_order, num_ch_order ); ch++ ) { IF( LT_32( norm_fx, EPSILON_FX_THR ) ) { - response_avg_fx[ch] = response_avg_fx[ch]; - response_avg_fx[ch] = divide3232( response_avg_fx[ch], EPSILON_FX_THR ); - response_avg_fx[ch] = L_shl( response_avg_fx[ch], 15 ); + response_avg_fx[ch] = response_avg_fx[ch]; // q30 + response_avg_fx[ch] = divide3232( response_avg_fx[ch], EPSILON_FX_THR ); // q15 + response_avg_fx[ch] = L_shl( response_avg_fx[ch], 15 ); // q30 move32(); move32(); move32(); } ELSE IF( GT_32( response_avg_fx[ch], norm_fx ) ) { - response_avg_fx[ch] = ONE_IN_Q30; + response_avg_fx[ch] = ONE_IN_Q30; // q30 move32(); } ELSE { - response_avg_fx[ch] = divide3232( response_avg_fx[ch], norm_fx ); - response_avg_fx[ch] = L_shl( response_avg_fx[ch], 15 ); + response_avg_fx[ch] = divide3232( response_avg_fx[ch], norm_fx ); // q15 + response_avg_fx[ch] = L_shl( response_avg_fx[ch], 15 ); // q30 move32(); move32(); } } /*normalize 3rd order*/ + norm_fx = 0; FOR( ch = hoa2_ch_order; ch < num_ch_order; ch++ ) { - norm_fx = L_add( norm_fx, Mpy_32_32( response_avg_fx[ch], response_avg_fx[ch] ) ); + norm_fx = L_add( norm_fx, Mpy_32_32( response_avg_fx[ch], response_avg_fx[ch] ) ); // q29 } norm_q = sub( 31, ( sub( add( 29, 29 ), 31 ) ) ); IF( norm_fx ) { - norm_fx = Sqrt32( norm_fx, &norm_q ); + norm_fx = Sqrt32( norm_fx, &norm_q ); // q=31-norm_q } ELSE { @@ -4441,32 +4446,32 @@ void ivas_get_spar_md_from_dirac_fx( } IF( norm_q < 0 ) { - norm_fx = L_shr( norm_fx, negate( norm_q ) ); + norm_fx = L_shr( norm_fx, negate( norm_q ) ); // q31 norm_q = 0; move16(); } - norm_fx = L_shr( norm_fx, sub( 1, norm_q ) ); + norm_fx = L_shr( norm_fx, sub( 1, norm_q ) ); // q30 FOR( ch = hoa2_ch_order; ch < num_ch_order; ch++ ) { IF( LT_32( norm_fx, EPSILON_FX_THR ) ) { - response_avg_fx[ch] = response_avg_fx[ch]; - response_avg_fx[ch] = divide3232( response_avg_fx[ch], EPSILON_FX_THR ); - response_avg_fx[ch] = L_shl( response_avg_fx[ch], 15 ); + response_avg_fx[ch] = response_avg_fx[ch]; // q30 + response_avg_fx[ch] = divide3232( response_avg_fx[ch], EPSILON_FX_THR ); // q15 + response_avg_fx[ch] = L_shl( response_avg_fx[ch], 15 ); // q30 move32(); move32(); move32(); } ELSE IF( GT_32( response_avg_fx[ch], norm_fx ) ) { - response_avg_fx[ch] = ONE_IN_Q30; + response_avg_fx[ch] = ONE_IN_Q30; // 1 q30 move32(); } ELSE { - response_avg_fx[ch] = divide3232( response_avg_fx[ch], norm_fx ); + response_avg_fx[ch] = divide3232( response_avg_fx[ch], norm_fx ); // q15 move32(); - response_avg_fx[ch] = L_shl( response_avg_fx[ch], 15 ); + response_avg_fx[ch] = L_shl( response_avg_fx[ch], 15 ); // q30 move32(); } } @@ -4475,13 +4480,13 @@ void ivas_get_spar_md_from_dirac_fx( FOR( i = add( FOA_CHANNELS, 1 ); i < num_ch; i++ ) { - response_avg_fx[i] = response_avg_fx[HOA_keep_ind[i]]; + response_avg_fx[i] = response_avg_fx[HOA_keep_ind[i]]; // q30 move32(); } - en_ratio_fac_fx = L_shl( L_sub( ONE_IN_Q30 - EPSILON_FX /* Guard to prevent overflow if diffuseness_fx is 0 */, diffuseness_fx[band] ), 1 ); // assuming q of dissusion 30 - en_ratio_fac_fx = L_max( en_ratio_fac_fx, 0 ); + en_ratio_fac_fx = L_shl( L_sub( ONE_IN_Q30 - EPSILON_FX /* Guard to prevent overflow if diffuseness_fx is 0 */, diffuseness_fx[band] ), 1 ); // assuming q of dissusion 30=>q31 + en_ratio_fac_fx = L_max( en_ratio_fac_fx, 0 ); // q31 FOR( i = 0; i < num_ch; i++ ) { @@ -4491,48 +4496,48 @@ void ivas_get_spar_md_from_dirac_fx( { IF( i == 0 ) { - cov_real_dirac_fx[i][i][band] = ONE_IN_Q30; + cov_real_dirac_fx[i][i][band] = ONE_IN_Q30; // 1 q30 move32(); } ELSE { Word32 en_ratio_fac_sq = 0; move32(); - cov_real_dirac_fx[i][j][band] = Mpy_32_32( L_shl_sat( Mpy_32_32( en_ratio_fac_fx, response_avg_fx[i] ), 1 ), response_avg_fx[j] ); + cov_real_dirac_fx[i][j][band] = Mpy_32_32( L_shl_sat( Mpy_32_32( en_ratio_fac_fx, response_avg_fx[i] ), 1 ), response_avg_fx[j] ); // q30 move32(); IF( LE_16( hSpar_md_cfg->nchan_transport, 2 ) ) { - cov_real_dirac_fx[i][j][band] = Mpy_32_32( cov_real_dirac_fx[i][j][band], en_ratio_fac_fx ); + cov_real_dirac_fx[i][j][band] = Mpy_32_32( cov_real_dirac_fx[i][j][band], en_ratio_fac_fx ); // q30 move32(); test(); IF( ( GE_16( i, ndm ) ) && ( EQ_16( dtx_vad, 1 ) ) ) { - en_ratio_fac_sq = Mpy_32_32( en_ratio_fac_fx, en_ratio_fac_fx ); - cov_real_dirac_fx[i][j][band] = L_add( cov_real_dirac_fx[i][j][band], Mpy_32_32( L_sub( ONE_IN_Q31, en_ratio_fac_sq ), P_dir_fact_fx[i - ndm] ) ); + en_ratio_fac_sq = Mpy_32_32( en_ratio_fac_fx, en_ratio_fac_fx ); // q31 + cov_real_dirac_fx[i][j][band] = L_add( cov_real_dirac_fx[i][j][band], Mpy_32_32( L_sub( ONE_IN_Q31, en_ratio_fac_sq ), P_dir_fact_fx[i - ndm] ) ); // q30 move32(); } ELSE { IF( LT_16( i, foa_ch ) ) { - en_ratio_fac_sq = Mpy_32_32( en_ratio_fac_fx, en_ratio_fac_fx ); - Word32 temp = Mpy_32_32( L_sub( ONE_IN_Q31, en_ratio_fac_sq ), ONE_BY_THREE_Q31 ); - cov_real_dirac_fx[i][j][band] = L_add( cov_real_dirac_fx[i][j][band], L_shr( temp, 1 ) ); + en_ratio_fac_sq = Mpy_32_32( en_ratio_fac_fx, en_ratio_fac_fx ); // q31 + Word32 temp = Mpy_32_32( L_sub( ONE_IN_Q31 /*1 q31*/, en_ratio_fac_sq ), ONE_BY_THREE_Q31 /*1/3 q31*/ ); // q31 + cov_real_dirac_fx[i][j][band] = L_add( cov_real_dirac_fx[i][j][band], L_shr( temp, 1 ) ); // q30 move32(); } ELSE IF( LT_16( i, hoa2_ch ) ) { - en_ratio_fac_sq = Mpy_32_32( en_ratio_fac_fx, en_ratio_fac_fx ); - Word32 temp = Mpy_32_32( L_sub( ONE_IN_Q31, en_ratio_fac_sq ), ONE_BY_FIVE_Q31 ); - cov_real_dirac_fx[i][j][band] = L_add( cov_real_dirac_fx[i][j][band], L_shr( temp, 1 ) ); + en_ratio_fac_sq = Mpy_32_32( en_ratio_fac_fx, en_ratio_fac_fx ); // q31 + Word32 temp = Mpy_32_32( L_sub( ONE_IN_Q31, en_ratio_fac_sq ), ONE_BY_FIVE_Q31 /*1/5 q31*/ ); // q31 + cov_real_dirac_fx[i][j][band] = L_add( cov_real_dirac_fx[i][j][band], L_shr( temp, 1 ) ); // q30 move32(); } ELSE { - en_ratio_fac_sq = Mpy_32_32( en_ratio_fac_fx, en_ratio_fac_fx ); - Word32 temp = Mpy_32_32( L_sub( ONE_IN_Q31, en_ratio_fac_sq ), ONE_BY_SEVEN_Q31 ); - cov_real_dirac_fx[i][j][band] = L_add( cov_real_dirac_fx[i][j][band], L_shr( temp, 1 ) ); + en_ratio_fac_sq = Mpy_32_32( en_ratio_fac_fx, en_ratio_fac_fx ); // q31 + Word32 temp = Mpy_32_32( L_sub( ONE_IN_Q31, en_ratio_fac_sq ), ONE_BY_SEVEN_Q31 /*1/7 q31*/ ); // q31 + cov_real_dirac_fx[i][j][band] = L_add( cov_real_dirac_fx[i][j][band], L_shr( temp, 1 ) ); // q30 move32(); } } @@ -4541,17 +4546,17 @@ void ivas_get_spar_md_from_dirac_fx( { IF( LT_16( i, foa_ch ) ) { - cov_real_dirac_fx[i][j][band] = L_add( cov_real_dirac_fx[i][j][band], L_shr( Mpy_32_32( L_sub( ONE_IN_Q31, en_ratio_fac_fx ), ONE_BY_THREE_Q31 ), 1 ) ); + cov_real_dirac_fx[i][j][band] = L_add( cov_real_dirac_fx[i][j][band], L_shr( Mpy_32_32( L_sub( ONE_IN_Q31, en_ratio_fac_fx ), ONE_BY_THREE_Q31 /*1/3 q31*/ ), 1 ) ); // q30 move32(); } ELSE IF( LT_16( i, hoa2_ch ) ) { - cov_real_dirac_fx[i][j][band] = L_add( cov_real_dirac_fx[i][j][band], L_shr( Mpy_32_32( L_sub( ONE_IN_Q31, en_ratio_fac_fx ), ONE_BY_FIVE_Q31 ), 1 ) ); + cov_real_dirac_fx[i][j][band] = L_add( cov_real_dirac_fx[i][j][band], L_shr( Mpy_32_32( L_sub( ONE_IN_Q31, en_ratio_fac_fx ), ONE_BY_FIVE_Q31 /*1/5 q31*/ ), 1 ) ); // q30 move32(); } ELSE { - cov_real_dirac_fx[i][j][band] = L_add( cov_real_dirac_fx[i][j][band], L_shr( Mpy_32_32( L_sub( ONE_IN_Q31, en_ratio_fac_fx ), ONE_BY_SEVEN_Q31 ), 1 ) ); + cov_real_dirac_fx[i][j][band] = L_add( cov_real_dirac_fx[i][j][band], L_shr( Mpy_32_32( L_sub( ONE_IN_Q31, en_ratio_fac_fx ), ONE_BY_SEVEN_Q31 /*1/7 q31*/ ), 1 ) ); // q30 move32(); } } @@ -4559,7 +4564,7 @@ void ivas_get_spar_md_from_dirac_fx( } ELSE { - cov_real_dirac_fx[i][j][band] = L_shl( Mpy_32_32( Mpy_32_32( en_ratio_fac_fx, response_avg_fx[i] ), response_avg_fx[j] ), 1 ); + cov_real_dirac_fx[i][j][band] = L_shl( Mpy_32_32( Mpy_32_32( en_ratio_fac_fx, response_avg_fx[i] ), response_avg_fx[j] ), 1 ); // q30 move32(); } } @@ -4570,7 +4575,7 @@ void ivas_get_spar_md_from_dirac_fx( { FOR( j = 0; j < num_ch; j++ ) { - pCov_real_fx[i][j] = cov_real_dirac_fx[i][j]; + pCov_real_fx[i][j] = cov_real_dirac_fx[i][j]; // q30 move32(); } } @@ -4595,7 +4600,7 @@ void ivas_get_spar_md_from_dirac_fx( { FOR( j = 0; j < num_ch; j++ ) { - mixer_mat_fx[i][j][band + ( i_ts * IVAS_MAX_NUM_BANDS )] = L_shl( ppMixer_mat_fx[i][j][band], sub( *q_mixer_mat_fx, q_ppMixer_mat ) ); + mixer_mat_fx[i][j][band + ( i_ts * IVAS_MAX_NUM_BANDS )] = L_shl( ppMixer_mat_fx[i][j][band], sub( *q_mixer_mat_fx, q_ppMixer_mat ) ); // q_mixer_mat_fx move32(); } } @@ -4614,7 +4619,7 @@ void ivas_get_spar_md_from_dirac_fx( { FOR( j = 0; j < num_ch; j++ ) { - mixer_mat_fx[0][j][band + ( i_ts * IVAS_MAX_NUM_BANDS )] = Mpy_32_32( L_shl( mixer_mat_fx[0][j][band + ( i_ts * IVAS_MAX_NUM_BANDS )], 2 ), Wscale_d[band] ); + mixer_mat_fx[0][j][band + ( i_ts * IVAS_MAX_NUM_BANDS )] = Mpy_32_32( L_shl( mixer_mat_fx[0][j][band + ( i_ts * IVAS_MAX_NUM_BANDS )], 2 ), Wscale_d[band] ); // q_mixer_mat_fx move32(); } } @@ -4750,7 +4755,7 @@ void ivas_dirac_dec_get_response( * Input azimuth and elevation are expected in Q0 *------------------------------------------------------------------------*/ -Word32 local_result_table[91][9] = { +Word32 local_result_table[91][9] /*q30*/ = { { -1518500224, 0, @@ -5754,7 +5759,7 @@ Word32 local_result_table[91][9] = { } }; -Word32 local_result_table_2[91][9] = { +Word32 local_result_table_2[91][9] /*q30*/ = { { -1073741824, 0, @@ -6760,7 +6765,7 @@ Word32 local_result_table_2[91][9] = { void ivas_dirac_dec_get_response_fx( const Word16 azimuth, const Word16 elevation, - Word32 *response_fx, + Word32 *response_fx, /*Q_out*/ const Word16 ambisonics_order, Word16 Q_out ) { @@ -6819,31 +6824,31 @@ void ivas_dirac_dec_get_response_fx( f_fx = 1; move16(); } - cos_1_fx = dirac_gains_trg_term_fx[az][0]; + cos_1_fx = dirac_gains_trg_term_fx[az][0]; // q31 move32(); - cos_2_fx = Mpy_32_32( cos_1_fx, cos_1_fx ); - sin_1_fx = dirac_gains_trg_term_fx[az][1]; + cos_2_fx = Mpy_32_32( cos_1_fx, cos_1_fx ); // q31 + sin_1_fx = dirac_gains_trg_term_fx[az][1]; // q31 move32(); if ( EQ_32( f_fx, -1 ) ) { - sin_1_fx = L_negate( sin_1_fx ); + sin_1_fx = L_negate( sin_1_fx ); // q31 move32(); } - cos_az_fx[0] = cos_1_fx; + cos_az_fx[0] = cos_1_fx; // q31 move32(); - cos_az_fx[1] = L_shl_sat( L_sub( cos_2_fx, ONE_IN_Q30 ), 1 ); + cos_az_fx[1] = L_shl_sat( L_sub( cos_2_fx, ONE_IN_Q30 /*0.5 q31*/ ), 1 ); /*q31*/ move32(); - cos_az_fx[2] = L_shl_sat( L_sub( Mpy_32_32( cos_1_fx, cos_az_fx[1] ), L_shr( cos_az_fx[0], 1 ) ), 1 ); + cos_az_fx[2] = L_shl_sat( L_sub( Mpy_32_32( cos_1_fx, cos_az_fx[1] ), L_shr( cos_az_fx[0], 1 ) /* cos_az_fx[0]/2 q31*/ ), 1 ); /*q31*/ move32(); - sin_az_fx[0] = sin_1_fx; + sin_az_fx[0] = sin_1_fx; /*q31*/ move32(); - sin_az_fx[1] = L_shl_sat( Mpy_32_32( sin_1_fx, cos_1_fx ), 1 ); + sin_az_fx[1] = L_shl_sat( Mpy_32_32( sin_1_fx, cos_1_fx ), 1 ); /*q31*/ move32(); - sin_az_fx[2] = L_shl_sat( Mpy_32_32( sin_1_fx, L_sub( cos_2_fx, ONE_IN_Q29 ) ), 2 ); + sin_az_fx[2] = L_shl_sat( Mpy_32_32( sin_1_fx, L_sub( cos_2_fx, ONE_IN_Q29 /*1/4 q31*/ ) ), 2 ); /*q31*/ move32(); - response_fx[0] = L_shl_sat( 1, Q_out ); + response_fx[0] = L_shl_sat( 1, Q_out ); // Q_out move32(); FOR( l = 1; l <= ambisonics_order; l++ ) @@ -6855,7 +6860,7 @@ void ivas_dirac_dec_get_response_fx( b = add( b_2, m ); a = dirac_gains_P_idx[b]; move16(); - c_fx_better = local_result_table[el][a]; + c_fx_better = local_result_table[el][a]; // q30 move32(); response_fx[b] = L_shl_sat( Mpy_32_32( c_fx_better, sin_az_fx[l - m - 1] ), sub( Q_out, 30 ) ); // Q_out move32(); @@ -6870,11 +6875,11 @@ void ivas_dirac_dec_get_response_fx( b = add( b_2, m ); a = dirac_gains_P_idx[b]; move16(); - c_fx_better = local_result_table[el][a]; + c_fx_better = local_result_table[el][a]; // q30 move32(); if ( EQ_16( e, -1 ) ) { - c_fx_better = L_negate( c_fx_better ); + c_fx_better = L_negate( c_fx_better ); // q30 } response_fx[b] = L_shl_sat( Mpy_32_32( c_fx_better, sin_az_fx[l - m - 1] ), sub( Q_out, 30 ) ); // Q_out move32(); @@ -6886,13 +6891,13 @@ void ivas_dirac_dec_get_response_fx( b = add( b_2, l ); a = dirac_gains_P_idx[b]; move16(); - c_fx_better = local_result_table_2[el][a]; + c_fx_better = local_result_table_2[el][a]; // q30 move32(); IF( EQ_16( ( l % 2 ), 1 ) ) { if ( EQ_16( e, -1 ) ) { - c_fx_better = L_negate( c_fx_better ); + c_fx_better = L_negate( c_fx_better ); // q30 move32(); } } @@ -7043,7 +7048,11 @@ void ivas_spar_set_bitrate_config( num_PR_bits_dirac_bands = max( 0, num_PR_bits_dirac_bands ); num_PR_bits_dirac_bands *= DIRAC_TO_SPAR_HBR_PRED_CHS; +#ifdef IVAS_FLOAT_FIXED + n_input = ivas_sba_get_nchan_metadata_fx( sba_order, ivas_total_brate ); +#else n_input = ivas_sba_get_nchan_metadata( sba_order, ivas_total_brate ); +#endif n_dmx = ivas_spar_br_table_consts[table_idx].nchan_transport; n_dec = n_input - n_dmx; bits_PR = (int16_t) ceilf( log2f( ivas_spar_br_table_consts[table_idx].q_lvls[quant_strat][0] ) ); @@ -7162,7 +7171,7 @@ void ivas_spar_set_bitrate_config_fx( } /* (int16_t) ( ivas_total_brate / FRAMES_PER_SEC ) */ - div1 = extract_l( Mpy_32_32( ivas_total_brate, ONE_BY_FRAMES_PER_SEC_Q31 ) ); + div1 = extract_l( Mpy_32_32( ivas_total_brate, ONE_BY_FRAMES_PER_SEC_Q31 /*1/FRAMES_PER_SEC Q31*/ ) ); /*31-31=>0*/ pSpar_md_cfg->tgt_bits_per_blk = sub( div1, add( add( add( add( add( IVAS_FORMAT_SIGNALING_NBITS_EXTENDED, SBA_PLANAR_BITS ), 0 ), SBA_ORDER_BITS ), length ), total_bits ) ); pSpar_md_cfg->max_bits_per_blk = sub( div1, add( add( add( add( add( IVAS_FORMAT_SIGNALING_NBITS_EXTENDED, SBA_PLANAR_BITS ), 0 ), SBA_ORDER_BITS ), length ), max_bits ) ); move16(); @@ -7186,8 +7195,8 @@ void ivas_spar_set_bitrate_config_fx( move16(); } - pSpar_md_cfg->tgt_bits_per_blk = extract_l( Mpy_32_32( i_mult( pSpar_md_cfg->tgt_bits_per_blk, num_bands ), 178956971 /* 1 / IVAS_MAX_NUM_BANDS in Q31 */ ) ); - pSpar_md_cfg->max_bits_per_blk = extract_l( Mpy_32_32( i_mult( pSpar_md_cfg->max_bits_per_blk, num_bands ), 178956971 /* 1 / IVAS_MAX_NUM_BANDS in Q31 */ ) ); + pSpar_md_cfg->tgt_bits_per_blk = extract_l( Mpy_32_32( i_mult( pSpar_md_cfg->tgt_bits_per_blk, num_bands ), 178956971 /* 1 / IVAS_MAX_NUM_BANDS in Q31 */ ) ); /*Q0*/ + pSpar_md_cfg->max_bits_per_blk = extract_l( Mpy_32_32( i_mult( pSpar_md_cfg->max_bits_per_blk, num_bands ), 178956971 /* 1 / IVAS_MAX_NUM_BANDS in Q31 */ ) ); /*Q0*/ pSpar_md_cfg->tgt_bits_per_blk = add( pSpar_md_cfg->tgt_bits_per_blk, md_coding_bits_header ); pSpar_md_cfg->max_bits_per_blk = add( pSpar_md_cfg->max_bits_per_blk, md_coding_bits_header ); @@ -7220,8 +7229,8 @@ void ivas_spar_set_bitrate_config_fx( num_PR_bits_dirac_bands = 0; move16(); } - div1 = BASOP_Util_Divide3232_Scale( num_PR_bits_dirac_bands, bands_bw, &temp ); - num_PR_bits_dirac_bands = shr( div1, sub( 15, temp ) ); + div1 = BASOP_Util_Divide3232_Scale( num_PR_bits_dirac_bands, bands_bw, &temp ); /*15-temp*/ + num_PR_bits_dirac_bands = shr( div1, sub( 15, temp ) ); /*q0*/ num_PR_bits_dirac_bands = s_max( 0, num_PR_bits_dirac_bands ); num_PR_bits_dirac_bands = i_mult( num_PR_bits_dirac_bands, DIRAC_TO_SPAR_HBR_PRED_CHS ); @@ -7238,12 +7247,12 @@ void ivas_spar_set_bitrate_config_fx( wc_coarse_strat = add( add( bits_PR, bits_C ), bits_P ); wc_coarse_strat = i_mult( wc_coarse_strat, num_bands ); - div1 = BASOP_Util_Divide3232_Scale( wc_coarse_strat, bands_bw, &temp ); - wc_coarse_strat = shr( div1, sub( 15, temp ) ); + div1 = BASOP_Util_Divide3232_Scale( wc_coarse_strat, bands_bw, &temp ); // q=15-temp + wc_coarse_strat = shr( div1, sub( 15, temp ) ); // q0 wc_coarse_strat = sub( wc_coarse_strat, num_PR_bits_dirac_bands ); wc_coarse_strat = add( wc_coarse_strat, md_coding_bits_header ); - IF( LT_16( pSpar_md_cfg->max_bits_per_blk, wc_coarse_strat ) ) + if ( LT_16( pSpar_md_cfg->max_bits_per_blk, wc_coarse_strat ) ) { assert( 0 ); } @@ -7402,7 +7411,7 @@ void ivas_spar_bitrate_dist_fx( move16(); FOR( i = 0; i < nchan_transport; i++ ) { - core_bits_act[i] = extract_l( Mpy_32_16_1( ivas_spar_br_table_consts[table_idx].core_brs[i][0], INV_FRAME_PER_SEC_Q15 ) ); + core_bits_act[i] = extract_l( Mpy_32_16_1( ivas_spar_br_table_consts[table_idx].core_brs[i][0], INV_FRAME_PER_SEC_Q15 /*1/FRAMES_PER_SEC Q15*/ ) ); /*q0*/ move16(); sum_core_act_bits = add( sum_core_act_bits, core_bits_act[i] ); @@ -7415,13 +7424,13 @@ void ivas_spar_bitrate_dist_fx( { FOR( i = 0; i < nchan_transport; i++ ) { - core_range_bits[i] = extract_l( Mpy_32_16_1( L_sub( ivas_spar_br_table_consts[table_idx].core_brs[i][2], ivas_spar_br_table_consts[table_idx].core_brs[i][0] ), INV_FRAME_PER_SEC_Q15 ) ); + core_range_bits[i] = extract_l( Mpy_32_16_1( L_sub( ivas_spar_br_table_consts[table_idx].core_brs[i][2], ivas_spar_br_table_consts[table_idx].core_brs[i][0] ), INV_FRAME_PER_SEC_Q15 /*1/FRAMES_PER_SEC Q15*/ ) ); /*q0*/ move16(); - core_bits_act[i] = add( core_bits_act[i], min( residual_bits, core_range_bits[i] ) ); + core_bits_act[i] = add( core_bits_act[i], s_min( residual_bits, core_range_bits[i] ) ); move16(); residual_bits = sub( residual_bits, core_range_bits[i] ); - IF( residual_bits <= 0 ) + if ( residual_bits <= 0 ) { BREAK; } @@ -7431,7 +7440,7 @@ void ivas_spar_bitrate_dist_fx( { FOR( i = 0; i < nchan_transport; i++ ) { - core_range_bits[i] = extract_l( Mpy_32_16_1( L_sub( ivas_spar_br_table_consts[table_idx].core_brs[i][0], ivas_spar_br_table_consts[table_idx].core_brs[i][1] ), INV_FRAME_PER_SEC_Q15 ) ); + core_range_bits[i] = extract_l( Mpy_32_16_1( L_sub( ivas_spar_br_table_consts[table_idx].core_brs[i][0], ivas_spar_br_table_consts[table_idx].core_brs[i][1] ), INV_FRAME_PER_SEC_Q15 /*1/FRAMES_PER_SEC Q15*/ ) ); /*q0*/ move16(); } @@ -7439,11 +7448,11 @@ void ivas_spar_bitrate_dist_fx( FOR( i = 0; i < nchan_transport; i++ ) { - core_bits_act[nchan_transport - 1 - i] = sub( core_bits_act[nchan_transport - 1 - i], min( overflow_bits, core_range_bits[nchan_transport - 1 - i] ) ); + core_bits_act[nchan_transport - 1 - i] = sub( core_bits_act[nchan_transport - 1 - i], s_min( overflow_bits, core_range_bits[nchan_transport - 1 - i] ) ); move16(); overflow_bits = sub( overflow_bits, core_range_bits[nchan_transport - 1 - i] ); - IF( overflow_bits <= 0 ) + if ( overflow_bits <= 0 ) { BREAK; } @@ -7461,7 +7470,7 @@ void ivas_spar_bitrate_dist_fx( overflow_bits = sub( overflow_bits, overflow_bits_ch ); } - core_bits_act[nchan_transport - 1] = sub( core_bits_act[nchan_transport - 1], max( 0, overflow_bits ) ); + core_bits_act[nchan_transport - 1] = sub( core_bits_act[nchan_transport - 1], s_max( 0, overflow_bits ) ); move16(); } } diff --git a/lib_com/ivas_spar_com_quant_util.c b/lib_com/ivas_spar_com_quant_util.c index 0207e3e19..8b0bf766f 100644 --- a/lib_com/ivas_spar_com_quant_util.c +++ b/lib_com/ivas_spar_com_quant_util.c @@ -162,12 +162,12 @@ void ivas_quantise_real_values_enc_fx_varq( #ifdef IVAS_FLOAT_FIXED void ivas_quantise_real_values_fx( - const Word32 *values_fx, + const Word32 *values_fx, /*q28*/ const Word16 q_levels, - const Word32 min_value_fx, - const Word32 max_value_fx, + const Word32 min_value_fx, /*q28*/ + const Word32 max_value_fx, /*q28*/ Word16 *index, - Word32 *quant_fx, + Word32 *quant_fx, /*q28*/ const Word16 dim ) { Word16 i; @@ -186,18 +186,18 @@ void ivas_quantise_real_values_fx( ELSE IF( q_levels && NE_32( max_value_fx, min_value_fx ) ) { Word16 nor_q_level = norm_l( sub( q_levels, 1 ) ); - Word32 one_by_q_levels = divide3232( L_shl( 1, ( nor_q_level ) ), L_shl( sub( q_levels, 1 ), ( nor_q_level ) ) ); - one_by_q_levels = L_shl( one_by_q_levels, 16 ); - q_step_fx = Mpy_32_32( L_sub( max_value_fx, min_value_fx ), one_by_q_levels ); - Word16 one_by_max_min = divide3232( ONE_IN_Q28, L_sub( max_value_fx, min_value_fx ) ); - one_by_q_step_fx = L_mult0( sub( q_levels, 1 ), one_by_max_min ); + Word32 one_by_q_levels = divide3232( L_shl( 1, ( nor_q_level ) ), L_shl( sub( q_levels, 1 ), ( nor_q_level ) ) ); // q15 + one_by_q_levels = L_shl( one_by_q_levels, 16 ); // q31 + q_step_fx = Mpy_32_32( L_sub( max_value_fx, min_value_fx ), one_by_q_levels ); // q28 + Word16 one_by_max_min = divide3232( ONE_IN_Q28, L_sub( max_value_fx, min_value_fx ) ); // q15 + one_by_q_step_fx = L_mult0( sub( q_levels, 1 ), one_by_max_min ); // q15 Word32 val_fx; FOR( i = 0; i < dim; i++ ) { - val_fx = L_max( min_value_fx, L_min( values_fx[i], max_value_fx ) ); - index[i] = extract_l( L_shr( Mpy_32_32( one_by_q_step_fx, val_fx ), 12 ) ); + val_fx = L_max( min_value_fx, L_min( values_fx[i], max_value_fx ) ); // q28 + index[i] = extract_l( L_shr( Mpy_32_32( one_by_q_step_fx, val_fx ), 12 ) ); // q15+q28-q31-q12=>q0 move16(); - quant_fx[i] = imult3216( q_step_fx, index[i] ); + quant_fx[i] = imult3216( q_step_fx, index[i] ); // q28 move16(); } } @@ -205,7 +205,7 @@ void ivas_quantise_real_values_fx( { FOR( i = 0; i < dim; i++ ) { - quant_fx[i] = values_fx[i]; + quant_fx[i] = values_fx[i]; // q28 move32(); } } @@ -418,25 +418,25 @@ void ivas_spar_get_uniform_quant_strat_fx( move16(); pSpar_md_com_cfg->quant_strat[i].PR.q_levels[1] = PQ_q_lvl; move16(); - pSpar_md_com_cfg->quant_strat[i].PR.max_fx = ONE_IN_Q28; // Q28 + pSpar_md_com_cfg->quant_strat[i].PR.max_fx = ONE_IN_Q28; // 1 Q28 move32(); - pSpar_md_com_cfg->quant_strat[i].PR.min_fx = -ONE_IN_Q28; // Q28 + pSpar_md_com_cfg->quant_strat[i].PR.min_fx = -ONE_IN_Q28; //-1 Q28 move32(); pSpar_md_com_cfg->quant_strat[i].C.q_levels[0] = C_q_lvl; move16(); pSpar_md_com_cfg->quant_strat[i].C.q_levels[1] = C_q_lvl; move16(); - pSpar_md_com_cfg->quant_strat[i].C.max_fx = ONE_IN_Q29; // Q28 + pSpar_md_com_cfg->quant_strat[i].C.max_fx = ONE_IN_Q29; // 2 Q28 move32(); - pSpar_md_com_cfg->quant_strat[i].C.min_fx = -ONE_IN_Q29; // Q28 + pSpar_md_com_cfg->quant_strat[i].C.min_fx = -ONE_IN_Q29; //-2 Q28 move32(); pSpar_md_com_cfg->quant_strat[i].P_r.q_levels[0] = Pr_q_lvl; move16(); pSpar_md_com_cfg->quant_strat[i].P_r.q_levels[1] = Pr_q_lvl; move16(); - pSpar_md_com_cfg->quant_strat[i].P_r.max_fx = ONE_IN_Q28; // Q28 + pSpar_md_com_cfg->quant_strat[i].P_r.max_fx = ONE_IN_Q28; // 1 Q28 move32(); pSpar_md_com_cfg->quant_strat[i].P_r.min_fx = 0; // Q28 move32(); @@ -445,9 +445,9 @@ void ivas_spar_get_uniform_quant_strat_fx( move16(); pSpar_md_com_cfg->quant_strat[i].P_c.q_levels[1] = Pc_q_lvl; move16(); - pSpar_md_com_cfg->quant_strat[i].P_c.max_fx = ONE_IN_Q27; // Q28 + pSpar_md_com_cfg->quant_strat[i].P_c.max_fx = ONE_IN_Q27; // 0.5 Q28 move32(); - pSpar_md_com_cfg->quant_strat[i].P_c.min_fx = -ONE_IN_Q27; // Q28 + pSpar_md_com_cfg->quant_strat[i].P_c.min_fx = -ONE_IN_Q27; //-0.5 Q28 move32(); } } @@ -475,33 +475,33 @@ void ivas_map_prior_coeffs_quant( { ivas_quant_strat_t qs = pSpar_md_cfg->quant_strat[qsi]; ivas_quant_strat_t prev_qs = pSpar_md_cfg->quant_strat[pSpar_md_cfg->prev_quant_idx]; - Word32 one_by_q_lvl_PR_fx = one_by_q_level[s_max( sub( prev_qs.PR.q_levels[0], 1 ), 1 )]; + Word32 one_by_q_lvl_PR_fx = one_by_q_level[max( ( prev_qs.PR.q_levels[0] - 1 ), 1 )]; /*q31*/ move32(); - Word32 one_by_q_lvl_C_fx = one_by_q_level[s_max( sub( prev_qs.C.q_levels[0], 1 ), 1 )]; + Word32 one_by_q_lvl_C_fx = one_by_q_level[max( ( prev_qs.C.q_levels[0] - 1 ), 1 )]; /*q31*/ move32(); - Word32 one_by_q_lvl_P_r_fx = one_by_q_level[s_max( sub( prev_qs.P_r.q_levels[0], 1 ), 1 )]; + Word32 one_by_q_lvl_P_r_fx = one_by_q_level[max( ( prev_qs.P_r.q_levels[0] - 1 ), 1 )]; /*q31*/ move32(); FOR( i = 0; i < nB; i++ ) { FOR( j = 0; j < IVAS_SPAR_MAX_CH - 1; j++ ) { - Word32 trial1 = L_mult0( sub( qs.PR.q_levels[0], 1 ), pSpar_md_prior->band_coeffs_idx[i].pred_index_re[j] ); - trial1 = L_shl( trial1, 16 ); - trial1 = round_fx( Mpy_32_32( trial1, one_by_q_lvl_PR_fx ) ); - pSpar_md_prior->band_coeffs_idx_mapped[i].pred_index_re[j] = extract_l( trial1 ); + Word32 trial1 = L_mult0( sub( qs.PR.q_levels[0], 1 ), pSpar_md_prior->band_coeffs_idx[i].pred_index_re[j] ); /*q0*/ + trial1 = L_shl( trial1, 16 ); /*q16*/ + trial1 = round_fx( Mpy_32_32( trial1, one_by_q_lvl_PR_fx ) ); /*q16+q31-31-16->0*/ + pSpar_md_prior->band_coeffs_idx_mapped[i].pred_index_re[j] = extract_l( trial1 ); /*q0*/ move16(); - Word32 trial2 = L_mult0( sub( qs.P_r.q_levels[0], 1 ), pSpar_md_prior->band_coeffs_idx[i].decd_index_re[j] ); - trial2 = L_shl( trial2, 16 ); - trial2 = round_fx( Mpy_32_32( trial2, one_by_q_lvl_P_r_fx ) ); - pSpar_md_prior->band_coeffs_idx_mapped[i].decd_index_re[j] = extract_l( trial2 ); + Word32 trial2 = L_mult0( sub( qs.P_r.q_levels[0], 1 ), pSpar_md_prior->band_coeffs_idx[i].decd_index_re[j] ); /*q0*/ + trial2 = L_shl( trial2, 16 ); /*q16*/ + trial2 = round_fx( Mpy_32_32( trial2, one_by_q_lvl_P_r_fx ) ); /*q16+q31-31-16->0*/ + pSpar_md_prior->band_coeffs_idx_mapped[i].decd_index_re[j] = extract_l( trial2 ); /*q0*/ move16(); } FOR( j = 0; j < IVAS_SPAR_MAX_C_COEFF; j++ ) { - Word32 trial1 = L_mult0( sub( qs.C.q_levels[0], 1 ), pSpar_md_prior->band_coeffs_idx[i].drct_index_re[j] ); - trial1 = L_shl( trial1, 16 ); - trial1 = round_fx( Mpy_32_32( trial1, one_by_q_lvl_C_fx ) ); - pSpar_md_prior->band_coeffs_idx_mapped[i].drct_index_re[j] = extract_l( trial1 ); + Word32 trial1 = L_mult0( sub( qs.C.q_levels[0], 1 ), pSpar_md_prior->band_coeffs_idx[i].drct_index_re[j] ); /*q0*/ + trial1 = L_shl( trial1, 16 ); /*q16*/ + trial1 = round_fx( Mpy_32_32( trial1, one_by_q_lvl_C_fx ) ); /*q16+q31-31-16->0*/ + pSpar_md_prior->band_coeffs_idx_mapped[i].drct_index_re[j] = extract_l( trial1 ); /*q0*/ move16(); } } @@ -593,11 +593,11 @@ void ivas_spar_quant_dtx_init( void ivas_spar_quant_dtx_init_fx( ivas_spar_md_t *spar_md, - Word32 *min_max ) + Word32 *min_max /*q28*/ ) { - spar_md->min_max_fx[0] = min_max[0]; + spar_md->min_max_fx[0] = min_max[0]; // q28 move32(); - spar_md->min_max_fx[1] = min_max[1]; + spar_md->min_max_fx[1] = min_max[1]; // q28 move32(); return; diff --git a/lib_com/ivas_stat_com.h b/lib_com/ivas_stat_com.h index bfe312557..fc0f2159d 100644 --- a/lib_com/ivas_stat_com.h +++ b/lib_com/ivas_stat_com.h @@ -216,7 +216,7 @@ typedef struct ivas_spar_md_t ivas_band_coeffs_ind_t band_coeffs_idx[IVAS_MAX_NUM_BANDS]; int16_t num_bands; float min_max[2]; - Word32 min_max_fx[2]; + Word32 min_max_fx[2]; /*q28*/ int16_t dtx_vad; float en_ratio_slow[IVAS_MAX_NUM_BANDS]; Word32 en_ratio_slow_fx[IVAS_MAX_NUM_BANDS]; diff --git a/lib_com/ivas_stereo_dft_com.c b/lib_com/ivas_stereo_dft_com.c index b315083d8..34a4573c9 100644 --- a/lib_com/ivas_stereo_dft_com.c +++ b/lib_com/ivas_stereo_dft_com.c @@ -43,7 +43,6 @@ #include "ivas_prot_fx.h" #endif -#define INV_FPS 655 // Q15 /*------------------------------------------------------------------------- * stereo_dft_config() * @@ -331,23 +330,23 @@ Word16 stereo_dft_band_config_fx( move16(); nbands = 0; move16(); - WHILE( LT_16( band_limits[nbands], shr( NFFT, 1 ) ) ) + WHILE( LT_16( band_limits[nbands], NFFT / 2 ) ) { - nbands = add( nbands, 1 ); + nbands++; IF( band_res == 0 ) { assert( 0 && "stereo DFT: band config failed!\n" ); } ELSE IF( EQ_16( band_res, 1 ) ) { - IF( enc_dec == ENC ) + IF( enc_dec == ENC /*0*/ ) { - band_limits[nbands] = round_fx( L_mult0( shl( dft_band_limits_erb4[nbands], 2 ), 26214 /* 1.60000002 in Q14 */ ) ); + band_limits[nbands] = round_fx( L_mult0( shl( dft_band_limits_erb4[nbands], 2 ), 26214 /* 1.60000002 in Q14 */ ) ); // Q0 move16(); } ELSE { - band_limits[nbands] = round_fx( L_mult0( shl( dft_band_limits_erb4[nbands], 1 ), 26214 /* 0.800000012 in Q14 */ ) ); + band_limits[nbands] = round_fx( L_mult0( shl( dft_band_limits_erb4[nbands], 1 ), 26214 /* 0.800000012 in Q14 */ ) ); // Q0 move16(); } @@ -357,12 +356,12 @@ Word16 stereo_dft_band_config_fx( { IF( enc_dec == ENC ) { - band_limits[nbands] = round_fx( L_mult0( shl( dft_band_limits_erb8[nbands], 2 ), 26214 /* 1.60000002 in Q14 */ ) ); + band_limits[nbands] = round_fx( L_mult0( shl( dft_band_limits_erb8[nbands], 2 ), 26214 /* 1.60000002 in Q14 */ ) ); // Q0 move16(); } ELSE { - band_limits[nbands] = round_fx( L_mult0( shl( dft_band_limits_erb8[nbands], 1 ), 26214 /* 0.800000012 in Q14 */ ) ); + band_limits[nbands] = round_fx( L_mult0( shl( dft_band_limits_erb8[nbands], 1 ), 26214 /* 0.800000012 in Q14 */ ) ); // Q0 move16(); } @@ -370,7 +369,7 @@ Word16 stereo_dft_band_config_fx( } } - band_limits[nbands] = shr( NFFT, 1 ); /*Nyquist Freq*/ + band_limits[nbands] = NFFT / 2; /*Nyquist Freq*/ move16(); return ( nbands ); diff --git a/lib_com/ivas_stereo_eclvq_com_fx.c b/lib_com/ivas_stereo_eclvq_com_fx.c index deebbe7b8..aebde1530 100644 --- a/lib_com/ivas_stereo_eclvq_com_fx.c +++ b/lib_com/ivas_stereo_eclvq_com_fx.c @@ -81,12 +81,12 @@ Word32 ECSQ_dequantize_gain_fx( /* pow(10.0, index * ECLVQ_INV_GLOBAL_GAIN_FACTOR) = pow(2.0,(index * ECLVQ_INV_GLOBAL_GAIN_FACTOR)*3.321928 */ L_prod = Mpy_32_16_1( ECLVQ_INV_GLOBAL_GAIN_FACTOR_Q24, shl( index, 8 ) ); /* Q17 */ - L_tmp = Mpy_32_16_1( L_prod, 27213 ); /* Q17 + Q13 >> 15 => Q15 */ + L_tmp = Mpy_32_16_1( L_prod, 27213 /*3.321928 q13*/ ); /* Q17 + Q13 >> 15 => Q15 */ - global_gain = BASOP_util_Pow2( L_tmp, tmp_e, &gg_e ); + global_gain = BASOP_util_Pow2( L_tmp, tmp_e, &gg_e ); // 31-gg_e gg_e = sub( 16, gg_e ); - global_gain = L_shr( global_gain, gg_e ); + global_gain = L_shr( global_gain, gg_e ); // q15 return global_gain; } @@ -98,16 +98,17 @@ Word32 ECSQ_dequantize_gain_fx( * ---------------------------------------------------------------*/ void ECSQ_dequantize_vector_fx( - const Word16 *input, - const Word32 global_gain, + const Word16 *input, /*qx*/ + const Word32 global_gain, /*q15*/ const Word16 N, - Word32 *output ) + Word32 *output /*qx*/ +) { Word16 i; FOR( i = 0; i < N; ++i ) { - output[i] = Mpy_32_16_1( global_gain, input[i] ); + output[i] = Mpy_32_16_1( global_gain, input[i] ); /*qx+q15-15->qx*/ move32(); } diff --git a/lib_com/log2.c b/lib_com/log2.c index 9e1cb14ae..1fef489e9 100644 --- a/lib_com/log2.c +++ b/lib_com/log2.c @@ -51,8 +51,8 @@ * 5- fraction = table[i]<<16 - (table[i] - table[i+1]) * a * 2 * *************************************************************************/ -Word16 Log2_norm_lc( /* (o) : Fractional part of Log2. (range: 0<=val<1) */ - Word32 L_x /* (i) : input value (normalized) */ +Word16 Log2_norm_lc( /* (o) : Fractional part of Log2. (range: 0<=val<1) Q15*/ + Word32 L_x /* (i) : input value (normalized) Qx*/ ) { Word16 i, a; @@ -72,7 +72,7 @@ Word16 Log2_norm_lc( /* (o) : Fractional part of Log2. (range: 0<=val return y; } -Word32 log10_fx( Word32 Linput ) +Word32 log10_fx( Word32 Linput ) /*o : Q23, i: 2Q13*/ { Word16 n1, frac, p1, p2, q1; Word32 Ltemp1, Ltemp2; @@ -119,7 +119,7 @@ Word32 log10_fx( Word32 Linput ) return ( L_shr( Ltemp1, 1 ) ); } -Word32 pow_10( Word32 x, Word16 *Q ) +Word32 pow_10( Word32 x, Word16 *Q ) /*o : Q15, i: Q26*/ { Word16 xl, xh, t1, t2, n; Word32 Ltemp1; @@ -209,7 +209,7 @@ Word32 pow_10( Word32 x, Word16 *Q ) return ( L_shl( Lacc, sub( n, count ) ) ); } -Word16 Log2_lc( /* (o) : Fractional part of Log2. (range: 0<=val<1) */ +Word16 Log2_lc( /* (o) : Fractional part of Log2. (range: 0<=val<1) Q15 - exponent*/ Word32 L_x, /* (i) : input value */ Word16 *exponent /* (o) : Integer part of Log2. (range: 0<=val<=30) */ ) diff --git a/lib_com/log2.h b/lib_com/log2.h index 9dc2b01ab..d87f677b5 100644 --- a/lib_com/log2.h +++ b/lib_com/log2.h @@ -26,14 +26,14 @@ * DECLARATION OF PROTOTYPES ******************************************************************************** */ -Word16 Log2_norm_lc( /* (o) : Fractional part of Log2. (range: 0<=val<1) */ - Word32 L_x /* (i) : input value (normalized) */ +Word16 Log2_norm_lc( /* (o) : Fractional part of Log2. (range: 0<=val<1) Q15 */ + Word32 L_x /* (i) : input value (normalized) Qx */ ); -Word32 log10_fx( Word32 Linput ); -Word32 pow_10( Word32 x, Word16 *Q ); -Word16 Log2_lc( /* (o) : Fractional part of Log2. (range: 0<=val<1) */ - Word32 L_x, /* (i) : input value */ - Word16 *exponent /* (o) : Integer part of Log2. (range: 0<=val<=30) */ +Word32 log10_fx( Word32 Linput ); /*o : Q23, i: 2Q13*/ +Word32 pow_10( Word32 x, Word16 *Q ); /*o : Q15, i: Q26*/ +Word16 Log2_lc( /* (o) : Fractional part of Log2. (range: 0<=val<1) Q15 - exponent */ + Word32 L_x, /* (i) : input value */ + Word16 *exponent /* (o) : Integer part of Log2. (range: 0<=val<=30) */ ); #endif diff --git a/lib_com/logqnorm_fx.c b/lib_com/logqnorm_fx.c index 4505c749d..cef2a6fa3 100644 --- a/lib_com/logqnorm_fx.c +++ b/lib_com/logqnorm_fx.c @@ -49,12 +49,12 @@ *--------------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED void logqnorm_ivas_fx( - const Word32 *x_fx, /* i : coefficient vector */ + const Word32 *x_fx, /* i : coefficient vector Qq*/ const Word16 q, /* i : q of coefficient vector */ Word16 *k_fx, /* o : index (Q0)*/ const Word16 L, /* i : codebook length */ const Word16 N, /* i : sub-vector size */ - const Word32 *thre_fxn /* i : quantization thresholds */ + const Word32 *thre_fxn /* i : quantization thresholds Q14*/ ) { Word16 i, j, j1, j2; @@ -82,10 +82,10 @@ void logqnorm_ivas_fx( thren0_sqr = W_mult0_32_32( thre_fxn[0], thre_fxn[0] ); // Q28 threnL2_sqr = W_mult0_32_32( thre_fxn[L - 2], thre_fxn[L - 2] ); // Q28 l_shift = W_norm( thren0_sqr ); - thren0_sqr32 = W_extract_h( W_shl( thren0_sqr, l_shift ) ); + thren0_sqr32 = W_extract_h( W_shl( thren0_sqr, l_shift ) ); // Q28 + l_shift - 32 thren0_sqr32_e = sub( 31, sub( add( Q28, l_shift ), 32 ) ); l_shift = W_norm( threnL2_sqr ); - threnL2_sqr32 = W_extract_h( W_shl( threnL2_sqr, l_shift ) ); + threnL2_sqr32 = W_extract_h( W_shl( threnL2_sqr, l_shift ) ); // Q28 + l_shift - 32 threnL2_sqr32_e = sub( 31, sub( add( Q28, l_shift ), 32 ) ); result1 = BASOP_Util_Add_Mant32Exp( thren0_sqr32, thren0_sqr32_e, L_negate( temp32_fx ), temp_e, &result1_e ); result2 = BASOP_Util_Add_Mant32Exp( threnL2_sqr32, threnL2_sqr32_e, L_negate( temp32_fx ), temp_e, &result2_e ); @@ -97,7 +97,7 @@ void logqnorm_ivas_fx( } ELSE IF( result2 > 0 ) { - *k_fx = L - 1; + *k_fx = sub( L, 1 ); move16(); } ELSE @@ -105,11 +105,11 @@ void logqnorm_ivas_fx( Word16 e = 0; move16(); power_fx = Sqrt32( ONE_IN_Q31, &e ); - power_fx = Sqrt32( temp32_fx, &temp_e ); + power_fx = Sqrt32( temp32_fx, &temp_e ); // Q31-temp_e // power_fx = L_shr( power_fx , Q14-(31-temp_e)); j1 = 0; move16(); - j2 = L - 1; + j2 = sub( L, 1 ); move16(); WHILE( GT_16( sub( j2, j1 ), 1 ) ) { @@ -164,21 +164,21 @@ void logqnorm_fx( FOR( i = 0; i < N; i++ ) { - coefs16[i] = extract_h( L_shl( L_x[i], coefs_shift ) ); + coefs16[i] = extract_h( L_shl( L_x[i], coefs_shift ) ); // Qx + coefs_shift - 16 move16(); - L_temp = L_mac0( L_temp, coefs16[i], coefs16[i] ); + L_temp = L_mac0( L_temp, coefs16[i], coefs16[i] ); // 2*(Qx + coefs_shift - 16) } - if ( GT_16( N, 1 ) ) + IF( GT_16( N, 1 ) ) { - Mpy_32_16_ss( L_temp, inv_tbl_fx[N], &L_temp, &lsb ); + Mpy_32_16_ss( L_temp, inv_tbl_fx[N], &L_temp, &lsb ); // 2*(Qx + coefs_shift - 16) } power_shift = shl( sub( coefs_shift, 16 ), 1 ); temp_shift = norm_l( L_temp ); m = add( temp_shift, power_shift ); - L_temp1 = L_add( L_shl( L_temp, temp_shift ), L_shr( lsb, sub( 16, temp_shift ) ) ); + L_temp1 = L_add( L_shl( L_temp, temp_shift ), L_shr( lsb, sub( 16, temp_shift ) ) ); // 2*(Qx + coefs_shift - 16)+ temp_shift m = add( offset, m ); test(); @@ -219,8 +219,8 @@ void logqnorm_2_fx( const Word16 L, /* i : codebook length */ const Word16 n_env_band, /* i : sub-vector size */ const Word16 nb_sfm, /* i : sub-vector size */ - Word16 *ynrm, /* o : norm indices */ - Word16 *normqlg2, /* o : quantized norm values */ + Word16 *ynrm, /* o : norm indices Q0*/ + Word16 *normqlg2, /* o : quantized norm values Q0*/ const Word32 *thren /* i, Q10 : quantization thresholds */ ) { @@ -306,7 +306,7 @@ void calc_norm_ivas_fx( logqnorm_ivas_fx( &x_fx[band_start[band]], 12, &nrm, 40, band_len[band], thren_HQ_fx ); norm[band] = nrm; move16(); - normlg[band] = dicnlg2[nrm]; + normlg[band] = dicnlg2[nrm]; // Q0 move16(); } diff --git a/lib_com/low_rate_band_att_fx.c b/lib_com/low_rate_band_att_fx.c index 5efed0d03..ef47fa18d 100644 --- a/lib_com/low_rate_band_att_fx.c +++ b/lib_com/low_rate_band_att_fx.c @@ -27,7 +27,7 @@ void ivas_fine_gain_pred_fx( const Word16 *R, /* i : Bits per sub band Q3 */ const Word16 num_sfm, /* i : Number of sub bands */ Word16 *xq, /* i/o: Quantized vector /quantized vector with finegain adj Q15*/ - Word16 *y, /* i/o: Quantized vector (int) */ + Word16 *y, /* i/o: Quantized vector (int) Q0*/ Word16 *fg_pred, /* o : Predicted fine gains Q12 */ const Word16 core /* i : Core */ ) @@ -263,8 +263,8 @@ void get_max_pulses_fx( const Word16 *k_sort, /* i : Indices for sorting by energy */ const Word16 *npulses, /* i : Pulses per sub band */ const Word16 BANDS, /* i : Number of bands */ - Word16 *inp_vector, /* i/o: Encoded shape vectors (int)*/ - Word16 *maxpulse /* o : Maximum pulse height per band */ + Word16 *inp_vector, /* i/o: Encoded shape vectors (int)Q0*/ + Word16 *maxpulse /* o : Maximum pulse height per band Q0*/ ) { Word16 i, k; @@ -309,7 +309,7 @@ void fine_gain_dec_fx( const Word16 *ord, /* i : Indices for energy order */ const Word16 num_sfm, /* i : Number of bands */ const Word16 *gain_bits, /* i : Gain adjustment bits per sub band */ - Word16 *fg_pred /* i/o: Predicted gains / Corrected gains */ + Word16 *fg_pred /* i/o: Predicted gains / Corrected gains Q12*/ ) { Word16 band; diff --git a/lib_com/lpc_tools.c b/lib_com/lpc_tools.c index d3635d286..0c13ef7b1 100644 --- a/lib_com/lpc_tools.c +++ b/lib_com/lpc_tools.c @@ -195,10 +195,10 @@ int16_t lev_dur( } #ifdef IVAS_FLOAT_FIXED Word16 lev_dur_fx( - Word32 *a_fx, /* o : LP coefficients (a[0] = 1.0) */ - const Word32 *r_fx, /* i : vector of autocorrelations */ + Word32 *a_fx, /* o : LP coefficients (a[0] = 1.0) Q(q_a)*/ + const Word32 *r_fx, /* i : vector of autocorrelations Q(q_r)*/ const Word16 m, /* i : order of LP filter */ - Word32 epsP[], /* o : prediction error energy */ + Word32 epsP[], /* o : prediction error energy Q(q_r)*/ Word16 q_a, Word16 q_r ) { @@ -232,10 +232,10 @@ Word16 lev_dur_fx( move32(); FOR( j = 0; j < i; j++ ) { - s = L_add( s, Mpy_32_32( r_fx[i - j], a_fx[j] ) ); + s = L_add( s, Mpy_32_32( r_fx[i - j], a_fx[j] ) ); // Q(q_a + q_r - 31) } - rc_fx[i - 1] = divide3232( L_negate( s ), L_shr( err, sub( 31, q_a ) ) ); + rc_fx[i - 1] = divide3232( L_negate( s ), L_shr( err, sub( 31, q_a ) ) ); // Q15 move16(); if ( GT_16( abs_s( rc_fx[i - 1] ), 32749 ) ) // 32749 = 0.99945 in Q15 @@ -248,14 +248,14 @@ Word16 lev_dur_fx( FOR( j = 1; j <= tmp16; j++ ) { l = sub( i, j ); - at = L_add( a_fx[j], Mpy_32_16_1( a_fx[l], rc_fx[i - 1] ) ); // Q(q_a) - a_fx[l] = L_add( a_fx[l], Mpy_32_16_1( a_fx[j], rc_fx[i - 1] ) ); + at = L_add( a_fx[j], Mpy_32_16_1( a_fx[l], rc_fx[i - 1] ) ); // Q(q_a) + a_fx[l] = L_add( a_fx[l], Mpy_32_16_1( a_fx[j], rc_fx[i - 1] ) ); // Q(q_a) move32(); a_fx[j] = at; move32(); } - a_fx[i] = L_shl( rc_fx[i - 1], sub( q_a, 15 ) ); + a_fx[i] = L_shl( rc_fx[i - 1], sub( q_a, 15 ) ); // Q(q_a) move32(); err = L_add( err, L_shl( Mpy_32_16_1( s, rc_fx[i - 1] ), sub( 31, q_a ) ) ); // q_err - q_s diff --git a/lib_com/lpc_tools_fx.c b/lib_com/lpc_tools_fx.c index bfb5d8ed1..bec794e31 100644 --- a/lib_com/lpc_tools_fx.c +++ b/lib_com/lpc_tools_fx.c @@ -61,8 +61,8 @@ void autocorr_fx( const Word16 x[], /* i : Input signal */ const Word16 m, /* i : LPC order Q0 */ - Word16 r_h[], /* o : Autocorrelations (msb) Q15 */ - Word16 r_l[], /* o : Autocorrelations (lsb) */ + Word16 r_h[], /* o : Autocorrelations (msb) Q15(Q_r -16) */ + Word16 r_l[], /* o : Autocorrelations (lsb) Q(r)-1 */ Word16 *Q_r, /* o : normalisation shift of r Q0 */ const Word16 len, /* i : Frame lenght */ const Word16 *wind, /* i : Window used */ @@ -165,12 +165,12 @@ void autocorr_fx( } #ifdef IVAS_FLOAT_FIXED void autocorr_fx_32( - const Word16 x[], /* i : Input signal */ + const Word16 x[], /* i : Input signal Q(q_x) */ const Word16 m, /* i : LPC order Q0 */ - Word32 r[], /* o : Autocorrelations */ + Word32 r[], /* o : Autocorrelations Q_r */ Word16 *Q_r, /* o : normalisation shift of r Q0 */ const Word16 len, /* i : Frame lenght */ - const Word16 *wind, /* i : Window used */ + const Word16 *wind, /* i : Window used Q15 */ Word16 rev_flag, const Word16 sym_flag /* i : symmetric window flag */ ) @@ -185,7 +185,7 @@ void autocorr_fx_32( /* Windowing of signal */ FOR( i = 0; i < len; i++ ) { - y[i] = mult_r( x[i], wind[sub( sub( len, i ), 1 )] ); + y[i] = mult_r( x[i], wind[len - i - 1] ); // Q(x) move16(); } } @@ -195,12 +195,12 @@ void autocorr_fx_32( tmp16 = shr( len, 1 ); FOR( i = 0; i < tmp16; i++ ) { - y[i] = mult_r( x[i], wind[i] ); + y[i] = mult_r( x[i], wind[i] ); // Q(x) move16(); } FOR( ; i < len; i++ ) { - y[i] = mult_r( x[i], wind[sub( sub( len, i ), 1 )] ); + y[i] = mult_r( x[i], wind[len - i - 1] ); // Q(x) move16(); } } @@ -208,7 +208,7 @@ void autocorr_fx_32( { FOR( i = 0; i < len; i++ ) { - y[i] = mult_r( x[i], wind[i] ); + y[i] = mult_r( x[i], wind[i] ); // Q(x) move16(); } } @@ -218,9 +218,9 @@ void autocorr_fx_32( L_sum = L_deposit_h( 16 ); /* sqrt(256), avoid overflow after rounding */ FOR( i = 0; i < len; i += 2 ) { - L_tmp = L_mult0( y[i], y[i] ); + L_tmp = L_mult0( y[i], y[i] ); // 2*Q(x) L_tmp = L_and( L_tmp, ~( 128 - 1 ) ); - L_tmp = L_mac0( L_tmp, y[i + 1], y[i + 1] ); + L_tmp = L_mac0( L_tmp, y[i + 1], y[i + 1] ); // 2*Q(x) L_tmp = L_shr( L_tmp, 7 ); L_sum = L_add( L_sum, L_tmp ); } @@ -234,7 +234,7 @@ void autocorr_fx_32( fact = lshr( -32768, shift ); FOR( i = 0; i < len; i++ ) { - y[i] = mult_r( y[i], fact ); + y[i] = mult_r( y[i], fact ); // Q(x) move16(); } } @@ -245,10 +245,10 @@ void autocorr_fx_32( } /* Compute and normalize r[0] */ - L_sum = L_mac( 1, y[0], y[0] ); + L_sum = L_mac( 1, y[0], y[0] ); // 2*Q(x) FOR( i = 1; i < len; i++ ) { - L_sum = L_mac( L_sum, y[i], y[i] ); + L_sum = L_mac( L_sum, y[i], y[i] ); // 2*Q(x) } norm = norm_l( L_sum ); L_sum = L_shl( L_sum, norm ); @@ -258,14 +258,14 @@ void autocorr_fx_32( /* Compute r[1] to r[m] */ FOR( i = 1; i <= m; i++ ) { - L_sum = L_mult( y[0], y[i] ); + L_sum = L_mult( y[0], y[i] ); // 2*Q(x)+1 tmp16 = sub( len, i ); FOR( j = 1; j < tmp16; j++ ) { - L_sum = L_mac( L_sum, y[j], y[j + i] ); + L_sum = L_mac( L_sum, y[j], y[j + i] ); // 2*Q(x)+1 } - L_sum = L_shl( L_sum, norm ); + L_sum = L_shl( L_sum, norm ); // 2*Q(x)+1+norm r[i] = L_sum; move32(); } @@ -316,7 +316,7 @@ void autocorr_fx_32( * - result = L_num * (1/L_denom) * ***************************************************************************** */ -static Word32 Div_32_opt( Word32 L_num, Word16 denom_hi, Word16 denom_lo ) +static Word32 Div_32_opt( Word32 L_num /*Q31*/, Word16 denom_hi /*Qx -16*/, Word16 denom_lo /*Qx -1*/ ) { Word16 approx /*, hi, lo, n_hi , n_lo*/; Word32 L_32; @@ -364,12 +364,12 @@ static Word32 Div_32_opt( Word32 L_num, Word16 denom_hi, Word16 denom_lo ) * Returns: * void */ -Word16 E_LPC_lev_dur( const Word16 Rh[], const Word16 Rl[], Word16 A[], Word32 epsP[], const Word16 order, Word16 *mem ) +Word16 E_LPC_lev_dur( const Word16 Rh[] /*QR -16*/, const Word16 Rl[] /*QR -1*/, Word16 A[] /*Qx*/, Word32 epsP[] /*QR*/, const Word16 order, Word16 *mem /*Qx*/ ) { return ( E_LPC_lev_dur_stab( Rh, Rl, A, epsP, order, mem, 32750 ) ); /* 0.99945 in Q15 */ } -Word16 E_LPC_lev_dur_stab( const Word16 Rh[], const Word16 Rl[], Word16 A[], Word32 epsP[], const Word16 order, Word16 *mem, Word16 k_max ) +Word16 E_LPC_lev_dur_stab( const Word16 Rh[] /*QR -16*/, const Word16 Rl[] /*QR -1*/, Word16 A[] /*Qx*/, Word32 epsP[] /*QR*/, const Word16 order, Word16 *mem /*Qx*/, Word16 k_max /*Q15*/ ) { Word16 i, j, k; Word16 hi, lo; @@ -794,12 +794,12 @@ Word16 E_LPC_lev_dur_stab_ivas_fx( const Word16 Rh[], const Word16 Rl[], Word16 return ( flag ); } -Word16 E_LPC_lev_dur_fx( const Word16 Rh[], const Word16 Rl[], Word32 A[], Word32 epsP[], const Word16 order, Word32 *mem ) +Word16 E_LPC_lev_dur_fx( const Word16 Rh[] /*QR -16*/, const Word16 Rl[] /*QR -1*/, Word32 A[] /*QA*/, Word32 epsP[] /*QR*/, const Word16 order, Word32 *mem /*QA*/ ) { return ( E_LPC_lev_dur_stab_fx( Rh, Rl, A, epsP, order, mem, 32750 ) ); /* 0.99945 in Q15 */ } -Word16 E_LPC_lev_dur_stab_fx( const Word16 Rh[], const Word16 Rl[], Word32 A[], Word32 epsP[], const Word16 order, Word32 *mem, Word16 k_max ) +Word16 E_LPC_lev_dur_stab_fx( const Word16 Rh[] /*QR -16*/, const Word16 Rl[] /*QR -1*/, Word32 A[] /*QA*/, Word32 epsP[] /*QR*/, const Word16 order, Word32 *mem /*QA*/, Word16 k_max /*Q15*/ ) { Word16 i, j, k; Word16 hi, lo; @@ -1026,7 +1026,7 @@ Word16 E_LPC_lev_dur_stab_fx( const Word16 Rh[], const Word16 Rl[], Word32 A[], * Returns: * void */ -void E_LPC_a_add_tilt( const Word16 *a, Word16 *ap, Word16 gamma, Word16 m ) +void E_LPC_a_add_tilt( const Word16 *a /*Qa*/, Word16 *ap /*Qa*/, Word16 gamma /*Q15*/, Word16 m ) { Word16 i; Word32 Amax, Atmp[M + 2]; @@ -1204,7 +1204,7 @@ Word16 E_LPC_lsp_unweight( * Returns: * void */ -Word32 E_LPC_schur( Word32 r[], Word16 reflCoeff[], Word32 epsP[], const Word16 m ) +Word32 E_LPC_schur( Word32 r[] /*Qr*/, Word16 reflCoeff[] /*Q15*/, Word32 epsP[] /*Qr*/, const Word16 m ) { Word16 i, j, temp16, mM1, mMi, s; Word32 g0[M], *g1, tmp32; @@ -1286,8 +1286,8 @@ extern const PWord16 w19N[127]; extern const PWord16 w18N[127]; extern void BASOP_getTables( const PWord16 **ptwiddle, const PWord16 **sin_twiddle, Word16 *psin_step, Word16 length ); static void spec2isf( - Word16 /*double*/ spec_r[], /* input spectrum real part (only left half + one zero)*/ - Word16 /*double*/ spec_i[], /* input spectrum imag part (only left half+right halt with zeros)*/ + Word16 /*double*/ spec_r[], /* input spectrum real part (only left half + one zero)Q_spec*/ + Word16 /*double*/ spec_i[], /* input spectrum imag part (only left half+right halt with zeros)Q_spec*/ Word16 /*short*/ speclen, /* length of spectrum (only left half)*/ Word16 /*double*/ lsf[], /* locations of LSFs (buffer must be sufficiently long) */ /*15Q16*/ @@ -1354,7 +1354,7 @@ static void spec2isf( return; } -void E_LPC_a_lsf_isf_conversion( Word16 *lpcCoeffs, Word16 *lsf, const Word16 *old_lsf, Word16 lpcOrder, Word8 lpcRep ) +void E_LPC_a_lsf_isf_conversion( Word16 *lpcCoeffs /*Qx*/, Word16 *lsf /*15Q16*/, const Word16 *old_lsf /*15Q16*/, Word16 lpcOrder, Word8 lpcRep /*Q0*/ ) { Word32 RealFFT[128]; Word32 ImagFFT[128]; diff --git a/lib_com/lsf_dec_bfi_fx.c b/lib_com/lsf_dec_bfi_fx.c index b41fa9de9..6292630af 100644 --- a/lib_com/lsf_dec_bfi_fx.c +++ b/lib_com/lsf_dec_bfi_fx.c @@ -24,15 +24,15 @@ void lsf_dec_bfi( const Word16 lsfBase[], /* i : base for differential lsf coding */ Word16 *mem_MA, /*!< i/o: 14Q1*1.28 quantizer memory for MA model */ Word16 *mem_AR, /*!< i/o: 14Q1*1.28 quantizer memory for MA model */ - Word16 stab_fac, /*!< i : ISF stability factor (shifted right by 1) */ + Word16 stab_fac, /*!< i : ISF stability factor (shifted right by 1) Q15*/ const Word16 last_coder_type, /*!< i : coding type in last good received fr. */ Word16 L_frame, const Word16 last_good, /*!< i : last good received frame */ const Word16 nbLostCmpt, /*!< i : counter of consecutive bad frames */ const Word8 plcBackgroundNoiseUpdated, /* i : background noise already updated?*/ Word16 *lsf_q_cng, /* o : quantized ISFs for background noise (14Q1*1.28) */ - Word16 *lsf_cng, - Word16 *old_lsf_q_cng, /* o : old quantized ISFs for background noise */ + Word16 *lsf_cng, /* Q2.56 */ + Word16 *old_lsf_q_cng, /* o : old quantized ISFs for background noise Q2.56*/ const Word16 Last_GSC_pit_band_idx, const Word16 Opt_AMR_WB, /* i : IO flag */ const Word8 tcxonly, @@ -140,11 +140,13 @@ void lsf_dec_bfi( ELSE { alpha = _ALPHA_VT_FX; /* rapid convergence to the CNG spectrum (long erasure, ONSETS) */ + move16(); } } ELSE { Word16 exp = 15; + move16(); alpha = Inv16( nbLostCmpt, &exp ); /*1.f/bfi_cnt;*/ alpha = shl( alpha, exp ); } @@ -254,7 +256,7 @@ return; } Word16 const *PlcGetLsfBase( - Word16 const lpcQuantization, + Word16 const lpcQuantization /*Q0*/, Word16 const narrowBand, Word32 const sr_core ) { diff --git a/lib_com/lsf_msvq_ma_fx.c b/lib_com/lsf_msvq_ma_fx.c index 409566ddc..6f8ea44c2 100644 --- a/lib_com/lsf_msvq_ma_fx.c +++ b/lib_com/lsf_msvq_ma_fx.c @@ -29,7 +29,7 @@ void midlsf_dec( const Word16 idx, /* i: codebook index */ Word16 qlsf[], /* o: decoded lsf coefficients (3Q12) */ const Word16 coder_type, - Word16 *mid_lsf_int, + Word16 *mid_lsf_int, /*Q0*/ const Word16 prev_bfi, const Word16 safety_net ) { @@ -138,8 +138,8 @@ void midlsf_dec( return; } Word16 lsf_ind_is_active( - const Word16 lsf_q_ind[], - const Word16 means[], + const Word16 lsf_q_ind[], /*(14Q1*1.28)*/ + const Word16 means[], /*(14Q1*1.28)*/ const Word16 narrowband, const Word16 cdk ) { diff --git a/lib_com/lsf_tools.c b/lib_com/lsf_tools.c index 4d063b5b0..d051a54c7 100644 --- a/lib_com/lsf_tools.c +++ b/lib_com/lsf_tools.c @@ -2088,12 +2088,12 @@ void dec_FDCNG_MSVQ_stage1( #ifdef IVAS_FLOAT_FIXED void dec_FDCNG_MSVQ_stage1_fx( - Word16 j_full, /* i : index full range */ - Word16 n, /* i : dimension to generate */ - const Word32 *invTrfMatrix, /* i : IDCT matrix for synthesis */ - const DCTTYPE idcttype, /* i : specify which IDCT */ - Word32 *uq, /* o : synthesized stage1 vector */ - Word16 *uq_ind /* o : synthesized stage1 vector in BASOP */ + Word16 j_full, /* i : index full range */ + Word16 n, /* i : dimension to generate */ + const Word32 *invTrfMatrix, /* i : IDCT matrix for synthesis Q31 */ + const DCTTYPE idcttype, /* i : specify which IDCT */ + Word32 *uq, /* o : synthesized stage1 vector Q20 */ + Word16 *uq_ind /* o : synthesized stage1 vector in BASOP */ ) { Word16 col, segm_ind, j, i; @@ -2120,12 +2120,12 @@ void dec_FDCNG_MSVQ_stage1_fx( /* Word8 column variable Qx storage*/ cbpW8 = cdk_37bits_ivas_stage1_W8Qx_dct_sections[segm_ind]; /* Word8 storage fixed ptr_init */ - cbpW8 += j * cdk1_ivas_cols_per_segment[segm_ind]; /* adaptive ptr init */ + cbpW8 += imult1616( j, cdk1_ivas_cols_per_segment[segm_ind] ); /* adaptive ptr init */ dct_col_shift_tab = stage1_dct_col_syn_shift[segm_ind]; FOR( col = 0; col < cdk1_ivas_cols_per_segment[segm_ind]; col++ ) { - dct_vec[col] = shl( cbpW8[col], dct_col_shift_tab[col] ); + dct_vec[col] = shl( cbpW8[col], dct_col_shift_tab[col] ); // Q0 move32(); /* LOGIC( 1 ) , SHIFT( 1 ); in BASOP: s_and(for W8->W16), shl() @@ -2138,7 +2138,7 @@ void dec_FDCNG_MSVQ_stage1_fx( FOR( i = 0; i < cdk1_ivas_cols_per_segment[segm_ind]; i++ ) { - dct_vec_fx[i] = L_shl( dct_vec[i], norm ); + dct_vec_fx[i] = L_shl( dct_vec[i], norm ); // Q20 move32(); } @@ -2151,6 +2151,7 @@ void dec_FDCNG_MSVQ_stage1_fx( FOR( i = 0; i < n; i++ ) { idct_vec_fx[i] = Mpy_32_32( idct_vec_fx[i], 56410112 ); /* norm + 31 - 31 = norm*/ + // fdcng_dct_scaleF[1] -> 0.420288085937500f / 16.0f -> in Q31 -> 56410112 move32(); } /* fdcng_dct_scaleF[1] --> 0.0625-->scale down from search Q4 domain to Q0 , @@ -2251,18 +2252,18 @@ void msvq_dec_float( #ifdef IVAS_FLOAT_FIXED void msvq_dec_fx( - const Word16 *const *cb, /* i : Codebook (indexed cb[*stages][levels][p]) */ - const Word16 dims[], /* i : Dimension of each codebook stage (NULL: full dim.) */ - const Word16 offs[], /* i : Starting dimension of each codebook stage (NULL: 0) */ - const Word16 stages, /* i : Number of stages */ - const Word16 N, /* i : Vector dimension */ - const Word16 maxN, /* i : Codebook dimension */ - const Word16 Idx[], /* i : Indices */ - const Word16 applyIDCT_flag, /* i : applyIDCT flag */ - const Word32 *invTrfMatrix, /* i : matrix for IDCT synthesis */ - Word32 *uq, /* o : quantized vector */ - Word16 *uq_ind, /* o : quantized vector (fixed point) */ - Word16 exp ) + const Word16 *const *cb, /* i : Codebook (indexed cb[*stages][levels][p]) Q: (Q_cb) */ + const Word16 dims[], /* i : Dimension of each codebook stage (NULL: full dim.) */ + const Word16 offs[], /* i : Starting dimension of each codebook stage (NULL: 0) */ + const Word16 stages, /* i : Number of stages */ + const Word16 N, /* i : Vector dimension */ + const Word16 maxN, /* i : Codebook dimension */ + const Word16 Idx[], /* i : Indices */ + const Word16 applyIDCT_flag, /* i : applyIDCT flag */ + const Word32 *invTrfMatrix, /* i : matrix for IDCT synthesis Q31 */ + Word32 *uq, /* o : quantized vector */ + Word16 *uq_ind, /* o : quantized vector (fixed point) Q0 */ + Word16 Q_cb ) { Word16 i, n, maxn, start, k; Word16 j, max_size = 0; @@ -2327,7 +2328,7 @@ void msvq_dec_fx( { FOR( k = 0; k < N; k++ ) { - uq[k] = L_shr( uq[k], guard_bits ); + uq[k] = L_shr( uq[k], guard_bits ); // 20 - guard_bits move32(); } } @@ -2339,7 +2340,7 @@ void msvq_dec_fx( dec_FDCNG_MSVQ_stage1_fx( Idx[0], N, invTrfMatrix, IDCT_T2_XX_24, uq, uq_ind ); /* IDCT_T2 N=24 used for all synthesis */ FOR( k = 0; k < N; k++ ) { - uq[k] = L_shr( uq[k], guard_bits ); + uq[k] = L_shr( uq[k], guard_bits ); // 20 - guard_bits move32(); } } @@ -2349,7 +2350,7 @@ void msvq_dec_fx( FOR( k = 0; k < n; k++ ) { - uq[add( start, k )] = L_add( uq[add( start, k )], L_lshl( cb[i][add( imult1616( Idx[i], maxn ), k )], sub( sub( 20, exp ), guard_bits ) ) ); + uq[start + k] = L_add( uq[start + k], L_lshl( cb[i][Idx[i] * maxn + k], sub( sub( 20, Q_cb ), guard_bits ) ) ); // 20 - guard_bits move32(); } } @@ -2359,7 +2360,8 @@ void msvq_dec_fx( { FOR( j = 0; j < n; ++j ) { - uq_ind[add( start, j )] = add( uq_ind[add( start, j )], (Word16) ( mult( cb[i][add( imult1616( Idx[i], maxn ), j )], 20971 ), sub( add( 13, exp ), 15 ) ) ); + uq_ind[start + j] = add( uq_ind[start + j], shl( mult( cb[i][Idx[i] * maxn + j], 20971 ), sub( add( 13, Q_cb ), 15 ) ) ); // Q0 + // 2 * 1.28 in Q13 -> 20971 move16(); } } @@ -2711,11 +2713,11 @@ void dctT2_N_apply_matrix( #ifdef IVAS_FLOAT_FIXED void dctT2_N_apply_matrix_fx( - const Word32 *input, /* i : input in fdcng or DCT(fdcng) domain */ - Word32 *output, /* o : output in DCT(fdcng) or fdcng ordomain */ + const Word32 *input, /* i : input in fdcng or DCT(fdcng) domain Q20 */ + Word32 *output, /* o : output in DCT(fdcng) or fdcng ordomain Q20 */ const Word16 dct_dim, /* i : dct processing dim possibly truncated */ const Word16 fdcngvq_dim, /* i : fdcng domain length */ - const Word32 *matrix, /* i : IDCT matrix */ + const Word32 *matrix, /* i : IDCT matrix Q31 */ const Word16 matrix_row_dim, /* i : */ const DCTTYPE dcttype /* i : matrix operation type */ ) @@ -2773,7 +2775,7 @@ void dctT2_N_apply_matrix_fx( /* +i(DCT) or +i*maxTrunc(IDCT) */ #define WMC_TOOL_SKIP - pt_A = &( matrix[imult1616( i, add( mat_step_row, mat_step_col_flag ) )] ); /* ptr indexing */ + pt_A = &( matrix[i * ( mat_step_row + mat_step_col_flag ) ] ); /* ptr indexing */ PTR_INIT( 1 ); #undef WMC_TOOL_SKIP FOR( j = 0; j < dim_in; j++ ) @@ -2848,14 +2850,14 @@ void extend_dctN_input( #ifdef IVAS_FLOAT_FIXED void extend_dctN_input_fx( - const Word32 *input, /* i : input in fdcng domain Q */ - const Word32 *dct_input, /* i : input in dctN(fdcng) domain Q */ - const Word16 in_dim, /* i : in_dim == N */ - Word32 *ext_sig, /* o : extended output in fdcng domain Q */ - const Word16 out_dim, /* i : output total dim */ - Word32 *matrix, /* i : idct synthesis matrix N rows, n_cols columns 31 */ - const Word16 n_cols, /* i : number of columns == DCT truncation length */ - const DCTTYPE dcttype /* i : matrix operation type */ + const Word32 *input, /* i : input in fdcng domain Q */ + const Word32 *dct_input, /* i : input in dctN(fdcng) domain Q */ + const Word16 in_dim, /* i : in_dim == N */ + Word32 *ext_sig, /* o : extended output in fdcng domain Q */ + const Word16 out_dim, /* i : output total dim */ + Word32 *matrix, /* i : idct synthesis matrix N rows, n_cols columns 31 */ + const Word16 n_cols, /* i : number of columns == DCT truncation length */ + const DCTTYPE dcttype /* i : matrix operation type */ ) { Word16 i, j, i_rev; @@ -2868,7 +2870,7 @@ void extend_dctN_input_fx( assert( n_cols == FDCNG_VQ_DCT_MAXTRUNC ); /* for *ptr[MAX_TRUNC] adressing*/ assert( ( dcttype & 1 ) != 0 ); /* idct tables always in use for this basis vector extension */ - Copy32( input, ext_sig, in_dim ); /* copy initial part, i.e. only last/tail parts are extended */ + Copy32( input, ext_sig, in_dim ); /* copy initial part, i.e. only last/tail parts are extended q: Q */ set32_fx( &( ext_sig[in_dim] ), 0, sub( out_dim, in_dim ) ); i_rev = in_dim; /*ptr init*/ @@ -2980,10 +2982,10 @@ void create_IDCT_N_Matrix( #ifdef IVAS_FLOAT_FIXED void create_IDCT_N_Matrix_fx( - Word32 *inv_matrixFloatQ, /* i/o: RAM buffer */ - const Word16 N, /* i : DCT length, number of time samples */ - const Word16 n_cols, /* i : number of dct coeffs (as DCT may be truncated) */ - const Word16 alloc_size /* i : RAM buffer size in elements */ + Word32 *inv_matrixFloatQ, /* i/o: RAM buffer Q31 */ + const Word16 N, /* i : DCT length, number of time samples */ + const Word16 n_cols, /* i : number of dct coeffs (as DCT may be truncated) */ + const Word16 alloc_size /* i : RAM buffer size in elements */ ) { Word16 c, c1, r, r_flip, W16_val, tmp16; @@ -2994,14 +2996,14 @@ void create_IDCT_N_Matrix_fx( Word16 idx; Word32( *ptr )[FDCNG_VQ_DCT_MAXTRUNC] = (void *) inv_matrixFloatQ; /* fixed number of columns pointers, to simplifies adressing in ANSIC */ - absval_ptr = unique_idctT2_24coeffsQ16; + absval_ptr = unique_idctT2_24coeffsQ16; // Q16 idx_ptr = idctT2_24_compressed_idx; len = FDCNG_VQ_MAX_LEN; move16(); IF( EQ_16( N, FDCNG_VQ_MAX_LEN_WB ) ) { - absval_ptr = unique_idctT2_21coeffsQ16; + absval_ptr = unique_idctT2_21coeffsQ16; // Q16 idx_ptr = idctT2_21_compressed_idx; len = N; move16(); @@ -3021,7 +3023,7 @@ void create_IDCT_N_Matrix_fx( FOR( c = 0; c < mat_cpy_size; c++ ) { idx = (Word16) ( idx_ptr[c] ); - W16_val = absval_ptr[abs( idx )]; + W16_val = absval_ptr[abs( idx )]; // Q16 move16(); IF( idx < 0 ) @@ -3048,8 +3050,8 @@ void create_IDCT_N_Matrix_fx( FOR( r = 0; r < tmp16; r_flip-- ) { #define WMC_TOOL_SKIP - ptr[r_flip][c] = ptr[r][c]; /* flipped */ - ptr[r_flip][c1] = L_negate( ptr[r][c1] ); /* flipped and sign swapped */ + ptr[r_flip][c] = ptr[r][c]; /* flipped: Q31*/ + ptr[r_flip][c1] = L_negate( ptr[r][c1] ); /* flipped and sign swapped: Q31 */ MOVE( 2 ); MULT( 1 ); /* for negate */ #undef WMC_TOOL_SKIP diff --git a/lib_com/lsf_tools_fx.c b/lib_com/lsf_tools_fx.c index a28f58851..d0dcc289e 100644 --- a/lib_com/lsf_tools_fx.c +++ b/lib_com/lsf_tools_fx.c @@ -1964,6 +1964,7 @@ ivas_error lsf_allocate_fx( bits1[n_stages] = bits_lvq; move16(); *stages1 = add( n_stages, 1 ); + move16(); } } ELSE @@ -2195,7 +2196,7 @@ Word16 lsf_stab_fx( /* o : LP filter stability Q15*/ e = norm_l( L_tmp ); L_tmp = L_shl( L_tmp, e ); /*Q(1+e)*/ - IF( L_frame == L_FRAME16k ) + IF( EQ_16( L_frame, L_FRAME16k ) ) { /*stab_fac = (float)(1.25f - (tmp/625000.0f));*/ L_tmp = Mpy_32_16_1( L_tmp, 16777 ); /* 30-eQ(1+e)*-21Q36 = 30-21-eQ31-9+e */ @@ -2296,7 +2297,7 @@ Word16 lsf_stab_ivas_fx( /* o : LP filter stability e = norm_l( L_tmp ); L_tmp = L_shl( L_tmp, e ); /*Q(0+e)*/ - IF( L_frame == L_FRAME16k ) + IF( EQ_16( L_frame, L_FRAME16k ) ) { /*stab_fac = (float)(1.25f - (tmp/625000.0f));*/ L_tmp = Mpy_32_16_1( L_tmp, 16777 ); /* 30-eQ(-1+e)*-21Q36 = 30-21-eQ31-9+e */ @@ -2815,28 +2816,29 @@ Word16 qlsf_ARSN_tcvq_Dec_16k_fx( /*=======================================================================*/ void lsf_syn_mem_backup_fx( - Encoder_State *st_fx, /* i: state structure */ - Word16 *btilt_code_fx, /* i: tilt code */ - Word32 *gc_threshold_fx, /* i: */ - Word16 *clip_var_bck_fx, /* o: */ - Word16 *next_force_sf_bck_fx, /* o: */ - - Word16 *lsp_new, /* i: LSP vector to quantize */ - Word16 *lsf_new, /* i: quantized LSF vector */ - Word16 *lsp_mid, /* i: mid-frame LSP vector */ - Word16 *clip_var, /* o: pitch clipping state var */ - Word16 *mem_AR, /* o: quantizer memory for AR model */ - Word16 *mem_MA, /* o: quantizer memory for AR model */ - Word16 *lsp_new_bck, /* o: LSP vector to quantize- backup */ - Word16 *lsf_new_bck, /* o: quantized LSF vector - backup */ - Word16 *lsp_mid_bck, /* o: mid-frame LSP vector - backup */ - Word16 *mCb1, /* o: counter for stationary frame after a transition frame */ - Word32 *Bin_E, /* o: FFT Bin energy 128 *2 sets */ - Word32 *Bin_E_old, /* o: FFT Bin energy 128 sets */ - Word16 *mem_syn_bck, /* o: synthesis filter memory */ - Word16 *mem_w0_bck, /* o: memory of the weighting filter */ - Word16 *streaklimit, - Word16 *pstreaklen ) + Encoder_State *st_fx, /* o: state structure */ + Word16 *btilt_code_fx, /* i: Q15 */ + Word32 *gc_threshold_fx, /* i: Q16 */ + Word16 *clip_var_bck_fx, /* i: Q(2.56), Q14, Q7, Q0, Q14, Q14 */ + Word16 *next_force_sf_bck_fx,/* i: */ + + Word16 *lsp_new, /* o: LSP vector to quantize Q15 */ + Word16 *lsf_new, /* i: quantized LSF vector Q15 */ + Word16 *lsp_mid, /* o: mid-frame LSP vector Q15 */ + Word16 *clip_var, /* i: pitch clipping state var Q(2.56) */ + Word16 *mem_AR, /* i: quantizer memory for AR model 2.56 */ + Word16 *mem_MA, /* i: quantizer memory for MA model 2.56 */ + Word16 *lsp_new_bck, /* i: LSP vector to quantize- backup Q15 */ + Word16 *lsf_new_bck, /* o: quantized LSF vector - backup Q15 */ + Word16 *lsp_mid_bck, /* i: mid-frame LSP vector - backup Q15 */ + Word16 *mCb1, /* o: counter for stationary frame after a transition frame */ + Word32 *Bin_E, /* i: FFT Bin energy 128 *2 sets q_bin */ + Word32 *Bin_E_old, /* i: FFT Bin energy 128 sets q_bin */ + Word16 *mem_syn_bck, /* i: synthesis filter memory q */ + Word16 *mem_w0_bck, /* i: memory of the weighting filter q */ + Word16 *streaklimit, /* i:LSF quantizer Q15 */ + Word16 *pstreaklen /* i:LSF quantizer */ +) { Word16 i; LPD_state_HANDLE hLPDmem = st_fx->hLPDmem; @@ -2902,24 +2904,24 @@ void lsf_syn_mem_backup_fx( #ifdef IVAS_FLOAT_FIXED void lsf_syn_mem_backup_ivas_fx( - Encoder_State *st_fx, /* i: state structure */ - Word16 *btilt_code_fx, /* i: tilt code */ - Word32 *gc_threshold_fx, /* i: */ - Word16 *clip_var_bck_fx, /* o: */ - Word16 *next_force_sf_bck_fx, /* o: */ - - Word16 *lsp_new, /* i: LSP vector to quantize */ - Word16 *lsp_mid, /* i: mid-frame LSP vector */ - Word16 *clip_var, /* o: pitch clipping state var */ - Word16 *mem_AR, /* o: quantizer memory for AR model */ - Word16 *mem_MA, /* o: quantizer memory for AR model */ - Word16 *lsp_new_bck, /* o: LSP vector to quantize- backup */ - Word16 *lsp_mid_bck, /* o: mid-frame LSP vector - backup */ - Word32 *Bin_E, /* o: FFT Bin energy 128 *2 sets */ - Word32 *Bin_E_old, /* o: FFT Bin energy 128 sets */ - Word16 *mem_syn_bck, /* o: synthesis filter memory */ - Word16 *mem_w0_bck, /* o: memory of the weighting filter */ - Word16 *streaklimit, + Encoder_State *st_fx, /* i: state structure */ + Word16 *btilt_code_fx, /* i: tilt code Q15 */ + Word32 *gc_threshold_fx, /* i: Q16 */ + Word16 *clip_var_bck_fx, /* o: Q(2.56), Q14, Q7, Q0, Q14, Q14 */ + Word16 *next_force_sf_bck_fx, /* o: */ + + Word16 *lsp_new, /* i: LSP vector to quantize Q15 */ + Word16 *lsp_mid, /* i: mid-frame LSP vector Q15 */ + Word16 *clip_var, /* o: pitch clipping state var Q(2.56) */ + Word16 *mem_AR, /* o: quantizer memory for AR model Q(2.56) */ + Word16 *mem_MA, /* o: quantizer memory for AR model Q(2.56) */ + Word16 *lsp_new_bck, /* o: LSP vector to quantize- backup Q15 */ + Word16 *lsp_mid_bck, /* o: mid-frame LSP vector - backup Q15 */ + Word32 *Bin_E, /* o: FFT Bin energy 128 *2 sets Q_new + Q_SCALE - 2 */ + Word32 *Bin_E_old, /* o: FFT Bin energy 128 sets Q_new + Q_SCALE - 2 */ + Word16 *mem_syn_bck, /* o: synthesis filter memory ( 15 - st_fx->hLPDmem->e_mem_syn ) */ + Word16 *mem_w0_bck, /* o: memory of the weighting filter ( 15 - st_fx->hLPDmem->e_mem_syn ) */ + Word16 *streaklimit, /* Q15 */ Word16 *pstreaklen ) { Word16 i; @@ -2930,47 +2932,47 @@ void lsf_syn_mem_backup_ivas_fx( FOR( i = 0; i < M; i++ ) { - mem_AR[i] = st_fx->mem_AR_fx[i]; + mem_AR[i] = st_fx->mem_AR_fx[i]; // Q2.56 move16(); - mem_MA[i] = st_fx->mem_MA_fx[i]; + mem_MA[i] = st_fx->mem_MA_fx[i]; // Q2.56 move16(); - lsp_new_bck[i] = lsp_new[i]; + lsp_new_bck[i] = lsp_new[i]; // Q15 move16(); - lsp_mid_bck[i] = lsp_mid[i]; + lsp_mid_bck[i] = lsp_mid[i]; // Q15 move16(); } - *streaklimit = st_fx->streaklimit_fx; + *streaklimit = st_fx->streaklimit_fx; // Q15 move16(); *pstreaklen = st_fx->pstreaklen; move16(); FOR( i = 0; i < L_FFT; i++ ) { - Bin_E[i] = st_fx->Bin_E_fx[i]; + Bin_E[i] = st_fx->Bin_E_fx[i]; // Q_new + Q_SCALE - 2 move32(); } FOR( i = 0; i < ( L_FFT / 2 ); i++ ) { - Bin_E_old[i] = st_fx->Bin_E_old_fx[i]; + Bin_E_old[i] = st_fx->Bin_E_old_fx[i]; // Q_new + Q_SCALE - 2 move32(); } /* back-up memories */ FOR( i = 0; i < M; i++ ) { - mem_syn_bck[i] = hLPDmem->mem_syn[i]; + mem_syn_bck[i] = hLPDmem->mem_syn[i]; // Q: ( 15 - st_fx->hLPDmem->e_mem_syn ) move16(); } - *mem_w0_bck = hLPDmem->mem_w0; + *mem_w0_bck = hLPDmem->mem_w0; // ( 15 - st_fx->hLPDmem->e_mem_syn ) move16(); - *btilt_code_fx = hLPDmem->tilt_code; + *btilt_code_fx = hLPDmem->tilt_code; // Q15 move16(); - *gc_threshold_fx = hLPDmem->gc_threshold; + *gc_threshold_fx = hLPDmem->gc_threshold; // Q16 move16(); Copy( st_fx->clip_var_fx, clip_var_bck_fx, 6 ); *next_force_sf_bck_fx = st_fx->next_force_safety_net; @@ -3034,28 +3036,28 @@ void lsf_update_memory( /* _ None */ /*=======================================================================*/ void lsf_syn_mem_restore_fx( - Encoder_State *st_fx, /* o: state structure */ - Word16 btilt_code_fx, /* i: */ - Word32 gc_threshold_fx, /* i: */ - Word16 *clip_var_bck_fx, /* i: */ - Word16 next_force_sf_bck_fx, /* i: */ - - Word16 *lsp_new, /* o: LSP vector to quantize */ - Word16 *lsf_new, /* o: quantized LSF vector */ - Word16 *lsp_mid, /* o: mid-frame LSP vector */ - Word16 clip_var, /* i: pitch clipping state var */ - Word16 *mem_AR, /* i: quantizer memory for AR model */ - Word16 *mem_MA, /* i: quantizer memory for MA model */ - Word16 *lsp_new_bck, /* i: LSP vector to quantize- backup */ - Word16 *lsf_new_bck, /* i: quantized LSF vector - backup */ - Word16 *lsp_mid_bck, /* i: mid-frame LSP vector - backup */ - Word16 mCb1, /* i: counter for stationary frame after a transition frame */ - Word32 *Bin_E, /* i: FFT Bin energy 128 *2 sets */ - Word32 *Bin_E_old, /* i: FFT Bin energy 128 sets */ - Word16 *mem_syn_bck, /* i: synthesis filter memory */ - Word16 mem_w0_bck, /* i: memory of the weighting filter */ - Word16 streaklimit, /* i:LSF quantizer */ - Word16 pstreaklen /* i:LSF quantizer */ + Encoder_State *st_fx, /* o: state structure */ + Word16 btilt_code_fx, /* i: Q15 */ + Word32 gc_threshold_fx, /* i: Q16 */ + Word16 *clip_var_bck_fx, /* i: Q(2.56), Q14, Q7, Q0, Q14, Q14 */ + Word16 next_force_sf_bck_fx, /* i: */ + + Word16 *lsp_new, /* o: LSP vector to quantize Q15 */ + Word16 *lsf_new, /* o: quantized LSF vector Q15 */ + Word16 *lsp_mid, /* o: mid-frame LSP vector Q15 */ + Word16 clip_var, /* i: pitch clipping state var Q(2.56) */ + Word16 *mem_AR, /* i: quantizer memory for AR model Q15 */ + Word16 *mem_MA, /* i: quantizer memory for MA model Q15 */ + Word16 *lsp_new_bck, /* i: LSP vector to quantize- backup Q15 */ + Word16 *lsf_new_bck, /* i: quantized LSF vector - backup Q15 */ + Word16 *lsp_mid_bck, /* i: mid-frame LSP vector - backup Q15 */ + Word16 mCb1, /* i: counter for stationary frame after a transition frame */ + Word32 *Bin_E, /* i: FFT Bin energy 128 *2 sets Q_new + Q_SCALE - 2 */ + Word32 *Bin_E_old, /* i: FFT Bin energy 128 sets Q_new + Q_SCALE - 2 */ + Word16 *mem_syn_bck, /* i: synthesis filter memory ( 15 - st_fx->hLPDmem->e_mem_syn ) */ + Word16 mem_w0_bck, /* i: memory of the weighting filter ( 15 - st_fx->hLPDmem->e_mem_syn ) */ + Word16 streaklimit, /* i:LSF quantizer Q15 */ + Word16 pstreaklen /* i:LSF quantizer */ ) { Word16 i; @@ -3067,78 +3069,81 @@ void lsf_syn_mem_restore_fx( FOR( i = 0; i < M; i++ ) { - st_fx->mem_AR_fx[i] = mem_AR[i]; + st_fx->mem_AR_fx[i] = mem_AR[i]; // 2.56 move16(); - st_fx->mem_MA_fx[i] = mem_MA[i]; + st_fx->mem_MA_fx[i] = mem_MA[i]; // 2.56 move16(); - lsp_new[i] = lsp_new_bck[i]; + lsp_new[i] = lsp_new_bck[i]; // Q15 move16(); - lsf_new[i] = lsf_new_bck[i]; + lsf_new[i] = lsf_new_bck[i]; // Q15 move16(); - lsp_mid[i] = lsp_mid_bck[i]; + lsp_mid[i] = lsp_mid_bck[i]; // Q15 move16(); } st_fx->mCb1_fx = mCb1; move16(); - st_fx->streaklimit_fx = streaklimit; + st_fx->streaklimit_fx = streaklimit; // Q15 move16(); st_fx->pstreaklen = pstreaklen; move16(); FOR( i = 0; i < L_FFT; i++ ) { - st_fx->Bin_E_fx[i] = Bin_E[i]; + st_fx->Bin_E_fx[i] = Bin_E[i]; // Q_new + Q_SCALE - 2 move16(); } FOR( i = 0; i < ( L_FFT / 2 ); i++ ) { - st_fx->Bin_E_old_fx[i] = Bin_E_old[i]; + st_fx->Bin_E_old_fx[i] = Bin_E_old[i]; // Q_new + Q_SCALE - 2 move32(); } /* restoring memories */ - hLPDmem->mem_w0 = mem_w0_bck; + hLPDmem->mem_w0 = mem_w0_bck; // ( 15 - st_fx->hLPDmem->e_mem_syn ) move16(); FOR( i = 0; i < M; i++ ) { - hLPDmem->mem_syn[i] = mem_syn_bck[i]; + hLPDmem->mem_syn[i] = mem_syn_bck[i]; // ( 15 - st_fx->hLPDmem->e_mem_syn ) move16(); } move16(); move32(); move16(); - hLPDmem->tilt_code = btilt_code_fx; - hLPDmem->gc_threshold = gc_threshold_fx; + hLPDmem->tilt_code = btilt_code_fx; // Q15 + hLPDmem->gc_threshold = gc_threshold_fx; // Q16 + move16(); + move32(); Copy( clip_var_bck_fx, st_fx->clip_var_fx, 6 ); st_fx->next_force_safety_net = next_force_sf_bck_fx; + move16(); return; } #ifdef IVAS_FLOAT_FIXED void lsf_syn_mem_restore_ivas_fx( - Encoder_State *st_fx, /* o: state structure */ - Word16 btilt_code_fx, /* i: */ - Word32 gc_threshold_fx, /* i: */ - Word16 *clip_var_bck_fx, /* i: */ - Word16 next_force_sf_bck_fx, /* i: */ - Word16 *lsp_new, /* o: LSP vector to quantize */ - Word16 *lsp_mid, /* o: mid-frame LSP vector */ - Word16 clip_var, /* i: pitch clipping state var */ - Word16 *mem_AR, /* i: quantizer memory for AR model */ - Word16 *mem_MA, /* i: quantizer memory for MA model */ - Word16 *lsp_new_bck, /* i: LSP vector to quantize- backup */ - Word16 *lsp_mid_bck, /* i: mid-frame LSP vector - backup */ - Word32 *Bin_E, /* i: FFT Bin energy 128 *2 sets */ - Word32 *Bin_E_old, /* i: FFT Bin energy 128 sets */ - Word16 *mem_syn_bck, /* i: synthesis filter memory */ - Word16 mem_w0_bck, /* i: memory of the weighting filter */ - Word16 streaklimit, /* i:LSF quantizer */ - Word16 pstreaklen /* i:LSF quantizer */ + Encoder_State *st_fx, /* o: state structure */ + Word16 btilt_code_fx, /* i: Q15 */ + Word32 gc_threshold_fx, /* i: Q16 */ + Word16 *clip_var_bck_fx, /* i: Q(2.56), Q14, Q7, Q0, Q14, Q14 */ + Word16 next_force_sf_bck_fx, /* i: */ + Word16 *lsp_new, /* o: LSP vector to quantize Q15 */ + Word16 *lsp_mid, /* o: mid-frame LSP vector Q15 */ + Word16 clip_var, /* i: pitch clipping state var Q(2.56), Q14, Q7, Q0, Q14, Q14 */ + Word16 *mem_AR, /* i: quantizer memory for AR model 2.56 */ + Word16 *mem_MA, /* i: quantizer memory for MA model 2.56 */ + Word16 *lsp_new_bck, /* i: LSP vector to quantize- backup Q15 */ + Word16 *lsp_mid_bck, /* i: mid-frame LSP vector - backup Q15 */ + Word32 *Bin_E, /* i: FFT Bin energy 128 *2 sets Q_new + Q_SCALE - 2 */ + Word32 *Bin_E_old, /* i: FFT Bin energy 128 sets Q_new + Q_SCALE - 2 */ + Word16 *mem_syn_bck, /* i: synthesis filter memory Q(15 - st_fx->hLPDmem->e_mem_syn ) */ + Word16 mem_w0_bck, /* i: memory of the weighting filter Q(15 - st_fx->hLPDmem->e_mem_syn ) */ + Word16 streaklimit, /* i:LSF quantizer Q15 */ + Word16 pstreaklen /* i:LSF quantizer */ ) { Word16 i; @@ -3150,47 +3155,47 @@ void lsf_syn_mem_restore_ivas_fx( FOR( i = 0; i < M; i++ ) { - st_fx->mem_AR_fx[i] = mem_AR[i]; + st_fx->mem_AR_fx[i] = mem_AR[i]; // 2.56 move16(); - st_fx->mem_MA_fx[i] = mem_MA[i]; + st_fx->mem_MA_fx[i] = mem_MA[i]; // 2.56 move16(); - lsp_new[i] = lsp_new_bck[i]; + lsp_new[i] = lsp_new_bck[i]; // Q15 move16(); - lsp_mid[i] = lsp_mid_bck[i]; + lsp_mid[i] = lsp_mid_bck[i]; // Q15 move16(); } - st_fx->streaklimit_fx = streaklimit; + st_fx->streaklimit_fx = streaklimit; // Q15 move16(); st_fx->pstreaklen = pstreaklen; move16(); FOR( i = 0; i < L_FFT; i++ ) { - st_fx->Bin_E_fx[i] = Bin_E[i]; + st_fx->Bin_E_fx[i] = Bin_E[i]; // Q_new + Q_SCALE - 2 move16(); } FOR( i = 0; i < ( L_FFT / 2 ); i++ ) { - st_fx->Bin_E_old_fx[i] = Bin_E_old[i]; + st_fx->Bin_E_old_fx[i] = Bin_E_old[i]; // Q_new + Q_SCALE - 2 move32(); } /* restoring memories */ - hLPDmem->mem_w0 = mem_w0_bck; + hLPDmem->mem_w0 = mem_w0_bck; // Q(15 - st_fx->hLPDmem->e_mem_syn ) move16(); FOR( i = 0; i < M; i++ ) { - hLPDmem->mem_syn[i] = mem_syn_bck[i]; + hLPDmem->mem_syn[i] = mem_syn_bck[i]; // Q(15 - st_fx->hLPDmem->e_mem_syn ) move16(); } move16(); - hLPDmem->tilt_code = btilt_code_fx; + hLPDmem->tilt_code = btilt_code_fx; // Q15 move32(); - hLPDmem->gc_threshold = gc_threshold_fx; + hLPDmem->gc_threshold = gc_threshold_fx; // Q16 Copy( clip_var_bck_fx, st_fx->clip_var_fx, 6 ); st_fx->next_force_safety_net = next_force_sf_bck_fx; move16(); diff --git a/lib_com/lsp_conv_poly_fx.c b/lib_com/lsp_conv_poly_fx.c index 70b919002..762dea2bd 100644 --- a/lib_com/lsp_conv_poly_fx.c +++ b/lib_com/lsp_conv_poly_fx.c @@ -535,7 +535,7 @@ static void spectautocorr_fx( * Here m = 51. *---------------------------------------------------------------------*/ - imid = ( N - 1 ) / 2; + imid = shr( sub( N, 1 ), 1 ); move16(); /*---------------------------------------------------------------------* @@ -569,7 +569,7 @@ static void spectautocorr_fx( FOR( i = 3; i < M; i += 2 ) { r[i] = L_deposit_l( 0 ); - r[i + 1] = -r[i - 1]; + r[i + 1] = L_negate( r[i - 1] ); move32(); move32(); } diff --git a/lib_com/modif_fs.c b/lib_com/modif_fs.c index 4b8d785b4..42241bce1 100644 --- a/lib_com/modif_fs.c +++ b/lib_com/modif_fs.c @@ -534,7 +534,7 @@ void Interpolate_allpass_steep( void Interpolate_allpass_steep_32( const Word32 *in_fx, /* i : input array of size N Qx */ Word32 *mem_fx, /* i/o: memory Qx */ - const int16_t N, /* i : number of input samples */ + const int16_t N, /* i : number of input samples */ Word32 *out_fx /* o : output array of size 2*N Qx */ ) { @@ -545,46 +545,46 @@ void Interpolate_allpass_steep_32( /* upper allpass filter chain */ FOR( k = 0; k < N; k++ ) { - temp_fx[0] = Madd_32_16( mem_fx[0], in_fx[k], AP2_STEEP_FX[0] ); + temp_fx[0] = Madd_32_16( mem_fx[0], in_fx[k], AP2_STEEP_FX[0] ); // Qx move32(); - mem_fx[0] = Msub_32_16( in_fx[k], temp_fx[0], AP2_STEEP_FX[0] ); + mem_fx[0] = Msub_32_16( in_fx[k], temp_fx[0], AP2_STEEP_FX[0] ); // Qx move32(); /* for better performance, unroll this loop */ FOR( n = 1; n < ALLPASSSECTIONS_STEEP - 1; n++ ) { - temp_fx[n] = Madd_32_16( mem_fx[n], temp_fx[n - 1], AP2_STEEP_FX[n] ); + temp_fx[n] = Madd_32_16( mem_fx[n], temp_fx[n - 1], AP2_STEEP_FX[n] ); // Qx move32(); - mem_fx[n] = Msub_32_16( temp_fx[n - 1], temp_fx[n], AP2_STEEP_FX[n] ); + mem_fx[n] = Msub_32_16( temp_fx[n - 1], temp_fx[n], AP2_STEEP_FX[n] ); // Qx move32(); } - out_fx[2 * k + 1] = Madd_32_16( mem_fx[ALLPASSSECTIONS_STEEP - 1], temp_fx[ALLPASSSECTIONS_STEEP - 2], AP2_STEEP_FX[ALLPASSSECTIONS_STEEP - 1] ); + out_fx[2 * k + 1] = Madd_32_16( mem_fx[ALLPASSSECTIONS_STEEP - 1], temp_fx[ALLPASSSECTIONS_STEEP - 2], AP2_STEEP_FX[ALLPASSSECTIONS_STEEP - 1] ); // Qx move32(); - mem_fx[ALLPASSSECTIONS_STEEP - 1] = Msub_32_16( temp_fx[ALLPASSSECTIONS_STEEP - 2], out_fx[2 * k + 1], AP2_STEEP_FX[ALLPASSSECTIONS_STEEP - 1] ); + mem_fx[ALLPASSSECTIONS_STEEP - 1] = Msub_32_16( temp_fx[ALLPASSSECTIONS_STEEP - 2], out_fx[2 * k + 1], AP2_STEEP_FX[ALLPASSSECTIONS_STEEP - 1] ); // Qx move32(); } /* lower allpass filter chain */ FOR( k = 0; k < N; k++ ) { - temp_fx[0] = Madd_32_16( mem_fx[ALLPASSSECTIONS_STEEP], in_fx[k], AP1_STEEP_FX[0] ); + temp_fx[0] = Madd_32_16( mem_fx[ALLPASSSECTIONS_STEEP], in_fx[k], AP1_STEEP_FX[0] ); // Qx move32(); - mem_fx[ALLPASSSECTIONS_STEEP] = Msub_32_16( in_fx[k], temp_fx[0], AP1_STEEP_FX[0] ); + mem_fx[ALLPASSSECTIONS_STEEP] = Msub_32_16( in_fx[k], temp_fx[0], AP1_STEEP_FX[0] ); // Qx move32(); /* for better performance, unroll this loop */ FOR( n = 1; n < ALLPASSSECTIONS_STEEP - 1; n++ ) { - temp_fx[n] = Madd_32_16( mem_fx[ALLPASSSECTIONS_STEEP + n], temp_fx[n - 1], AP1_STEEP_FX[n] ); + temp_fx[n] = Madd_32_16( mem_fx[ALLPASSSECTIONS_STEEP + n], temp_fx[n - 1], AP1_STEEP_FX[n] ); // Qx move32(); - mem_fx[ALLPASSSECTIONS_STEEP + n] = Msub_32_16( temp_fx[n - 1], temp_fx[n], AP1_STEEP_FX[n] ); + mem_fx[ALLPASSSECTIONS_STEEP + n] = Msub_32_16( temp_fx[n - 1], temp_fx[n], AP1_STEEP_FX[n] ); // Qx move32(); } - out_fx[2 * k] = Madd_32_16( mem_fx[2 * ALLPASSSECTIONS_STEEP - 1], temp_fx[ALLPASSSECTIONS_STEEP - 2], AP1_STEEP_FX[ALLPASSSECTIONS_STEEP - 1] ); + out_fx[2 * k] = Madd_32_16( mem_fx[2 * ALLPASSSECTIONS_STEEP - 1], temp_fx[ALLPASSSECTIONS_STEEP - 2], AP1_STEEP_FX[ALLPASSSECTIONS_STEEP - 1] ); // Qx move32(); - mem_fx[2 * ALLPASSSECTIONS_STEEP - 1] = Msub_32_16( temp_fx[ALLPASSSECTIONS_STEEP - 2], out_fx[2 * k], AP1_STEEP_FX[ALLPASSSECTIONS_STEEP - 1] ); + mem_fx[2 * ALLPASSSECTIONS_STEEP - 1] = Msub_32_16( temp_fx[ALLPASSSECTIONS_STEEP - 2], out_fx[2 * k], AP1_STEEP_FX[ALLPASSSECTIONS_STEEP - 1] ); // Qx move32(); } #else @@ -728,9 +728,9 @@ void Decimate_allpass_steep( #ifdef IVAS_FLOAT_FIXED void Decimate_allpass_steep_fx32( const Word32 *in, /* i : input array of size N Qx */ - Word32 *mem, /* i/o: memory Qx*/ - const Word16 N, /* i : number of input samples */ - Word32 *out /* o : output array of size N/2 Qx*/ + Word32 *mem, /* i/o: memory Qx */ + const Word16 N, /* i : number of input samples */ + Word32 *out /* o : output array of size N/2 Qx */ ) { Word16 n, k; @@ -739,74 +739,74 @@ void Decimate_allpass_steep_fx32( /* upper allpass filter chain */ FOR( k = 0; k < N / 2; k++ ) { - temp[0] = L_add( mem[0], Mpy_32_16_1( in[2 * k], AP1_STEEP_FX[0] ) ); + temp[0] = L_add( mem[0], Mpy_32_16_1( in[2 * k], AP1_STEEP_FX[0] ) ); // Qx move32(); - mem[0] = L_sub( in[2 * k], Mpy_32_16_1( temp[0], AP1_STEEP_FX[0] ) ); + mem[0] = L_sub( in[2 * k], Mpy_32_16_1( temp[0], AP1_STEEP_FX[0] ) ); // Qx move32(); - temp[1] = L_add( mem[1], Mpy_32_16_1( temp[0], AP1_STEEP_FX[1] ) ); + temp[1] = L_add( mem[1], Mpy_32_16_1( temp[0], AP1_STEEP_FX[1] ) ); // Qx move32(); - mem[1] = L_sub( temp[0], Mpy_32_16_1( temp[1], AP1_STEEP_FX[1] ) ); + mem[1] = L_sub( temp[0], Mpy_32_16_1( temp[1], AP1_STEEP_FX[1] ) ); // Qx move32(); - out[k] = L_add( mem[ALLPASSSECTIONS_STEEP - 1], Mpy_32_16_1( temp[ALLPASSSECTIONS_STEEP - 2], AP1_STEEP_FX[ALLPASSSECTIONS_STEEP - 1] ) ); + out[k] = L_add( mem[ALLPASSSECTIONS_STEEP - 1], Mpy_32_16_1( temp[ALLPASSSECTIONS_STEEP - 2], AP1_STEEP_FX[ALLPASSSECTIONS_STEEP - 1] ) ); // Qx move32(); - mem[ALLPASSSECTIONS_STEEP - 1] = L_sub( temp[ALLPASSSECTIONS_STEEP - 2], Mpy_32_16_1( out[k], AP1_STEEP_FX[ALLPASSSECTIONS_STEEP - 1] ) ); + mem[ALLPASSSECTIONS_STEEP - 1] = L_sub( temp[ALLPASSSECTIONS_STEEP - 2], Mpy_32_16_1( out[k], AP1_STEEP_FX[ALLPASSSECTIONS_STEEP - 1] ) ); // Qx move32(); } /* lower allpass filter chain */ - temp[0] = L_add( mem[ALLPASSSECTIONS_STEEP], Mpy_32_16_1( mem[2 * ALLPASSSECTIONS_STEEP], AP2_STEEP_FX[0] ) ); + temp[0] = L_add( mem[ALLPASSSECTIONS_STEEP], Mpy_32_16_1( mem[2 * ALLPASSSECTIONS_STEEP], AP2_STEEP_FX[0] ) ); // Qx move32(); - mem[ALLPASSSECTIONS_STEEP] = L_sub( mem[2 * ALLPASSSECTIONS_STEEP], Mpy_32_16_1( temp[0], AP2_STEEP_FX[0] ) ); + mem[ALLPASSSECTIONS_STEEP] = L_sub( mem[2 * ALLPASSSECTIONS_STEEP], Mpy_32_16_1( temp[0], AP2_STEEP_FX[0] ) ); // Qx move32(); /* for better performance, unroll this loop */ FOR( n = 1; n < ALLPASSSECTIONS_STEEP - 1; n++ ) { - temp[n] = L_add( mem[ALLPASSSECTIONS_STEEP + n], Mpy_32_16_1( temp[n - 1], AP2_STEEP_FX[n] ) ); + temp[n] = L_add( mem[ALLPASSSECTIONS_STEEP + n], Mpy_32_16_1( temp[n - 1], AP2_STEEP_FX[n] ) ); // Qx move32(); /*if ( fabs( temp[n] ) < 1e-12 ) { temp[n] = sign( temp[n] ) * 1e-12f; }*/ - mem[ALLPASSSECTIONS_STEEP + 1] = L_sub( temp[n - 1], Mpy_32_16_1( temp[n], AP2_STEEP_FX[n] ) ); + mem[ALLPASSSECTIONS_STEEP + 1] = L_sub( temp[n - 1], Mpy_32_16_1( temp[n], AP2_STEEP_FX[n] ) ); // Qx move32(); } - temp[ALLPASSSECTIONS_STEEP - 1] = L_add( mem[2 * ALLPASSSECTIONS_STEEP - 1], Mpy_32_16_1( temp[ALLPASSSECTIONS_STEEP - 2], AP2_STEEP_FX[ALLPASSSECTIONS_STEEP - 1] ) ); + temp[ALLPASSSECTIONS_STEEP - 1] = L_add( mem[2 * ALLPASSSECTIONS_STEEP - 1], Mpy_32_16_1( temp[ALLPASSSECTIONS_STEEP - 2], AP2_STEEP_FX[ALLPASSSECTIONS_STEEP - 1] ) ); //Qx move32(); - mem[2 * ALLPASSSECTIONS_STEEP - 1] = L_sub( temp[ALLPASSSECTIONS_STEEP - 2], Mpy_32_16_1( temp[ALLPASSSECTIONS_STEEP - 1], AP2_STEEP_FX[ALLPASSSECTIONS_STEEP - 1] ) ); + mem[2 * ALLPASSSECTIONS_STEEP - 1] = L_sub( temp[ALLPASSSECTIONS_STEEP - 2], Mpy_32_16_1( temp[ALLPASSSECTIONS_STEEP - 1], AP2_STEEP_FX[ALLPASSSECTIONS_STEEP - 1] ) ); // Qx move32(); - out[0] = W_round48_L( W_mac_32_16( W_mult_32_16( out[0], 16384 ), temp[ALLPASSSECTIONS_STEEP - 1], 16384 ) ); + out[0] = W_round48_L( W_mac_32_16( W_mult_32_16( out[0], 16384 /*0.5 in Q15*/ ), temp[ALLPASSSECTIONS_STEEP - 1], 16384 /*0.5 in Q15*/ ) ); // Qx move32(); FOR( k = 1; k < N / 2; k++ ) { - temp[0] = L_add( mem[ALLPASSSECTIONS_STEEP], Mpy_32_16_1( in[sub( shl( k, 1 ), 1 )], AP2_STEEP_FX[0] ) ); + temp[0] = L_add( mem[ALLPASSSECTIONS_STEEP], Mpy_32_16_1( in[sub( shl( k, 1 ), 1 )], AP2_STEEP_FX[0] ) ); // Qx move32(); - mem[ALLPASSSECTIONS_STEEP] = L_sub( in[sub( shl( k, 1 ), 1 )], Mpy_32_16_1( temp[0], AP2_STEEP_FX[0] ) ); + mem[ALLPASSSECTIONS_STEEP] = L_sub( in[sub( shl( k, 1 ), 1 )], Mpy_32_16_1( temp[0], AP2_STEEP_FX[0] ) ); // Qx move32(); /* for better performance, unroll this loop */ FOR( n = 1; n < ALLPASSSECTIONS_STEEP - 1; n++ ) { - temp[n] = L_add( mem[ALLPASSSECTIONS_STEEP + n], Mpy_32_16_1( temp[n - 1], AP2_STEEP_FX[n] ) ); + temp[n] = L_add( mem[ALLPASSSECTIONS_STEEP + n], Mpy_32_16_1( temp[n - 1], AP2_STEEP_FX[n] ) ); // Qx move32(); /*if ( fabs( temp[n] ) < 1e-12 ) { temp[n] = sign( temp[n] ) * 1e-12f; }*/ - mem[ALLPASSSECTIONS_STEEP + n] = L_sub( temp[n - 1], Mpy_32_16_1( temp[n], AP2_STEEP_FX[n] ) ); + mem[ALLPASSSECTIONS_STEEP + n] = L_sub( temp[n - 1], Mpy_32_16_1( temp[n], AP2_STEEP_FX[n] ) ); // Qx move32(); } - temp[ALLPASSSECTIONS_STEEP - 1] = L_add( mem[2 * ALLPASSSECTIONS_STEEP - 1], Mpy_32_16_1( temp[ALLPASSSECTIONS_STEEP - 2], AP2_STEEP_FX[ALLPASSSECTIONS_STEEP - 1] ) ); + temp[ALLPASSSECTIONS_STEEP - 1] = L_add( mem[2 * ALLPASSSECTIONS_STEEP - 1], Mpy_32_16_1( temp[ALLPASSSECTIONS_STEEP - 2], AP2_STEEP_FX[ALLPASSSECTIONS_STEEP - 1] ) ); // Qx move32(); - mem[2 * ALLPASSSECTIONS_STEEP - 1] = L_sub( temp[ALLPASSSECTIONS_STEEP - 2], Mpy_32_16_1( temp[ALLPASSSECTIONS_STEEP - 1], AP2_STEEP_FX[ALLPASSSECTIONS_STEEP - 1] ) ); + mem[2 * ALLPASSSECTIONS_STEEP - 1] = L_sub( temp[ALLPASSSECTIONS_STEEP - 2], Mpy_32_16_1( temp[ALLPASSSECTIONS_STEEP - 1], AP2_STEEP_FX[ALLPASSSECTIONS_STEEP - 1] ) ); // Qx move32(); - out[k] = W_round48_L( W_mac_32_16( W_mult_32_16( out[k], 16384 ), temp[ALLPASSSECTIONS_STEEP - 1], 16384 ) ); + out[k] = W_round48_L( W_mac_32_16( W_mult_32_16( out[k], 16384 /*0.5 in Q15*/ ), temp[ALLPASSSECTIONS_STEEP - 1], 16384 /*0.5 in Q15*/ ) ); // Qx move32(); } @@ -900,57 +900,57 @@ void interpolate_3_over_2_allpass_32( Word32 out1_buff[L_FRAME32k * 3]; Word32 *out1; Word32 mem_temp; - const Word16 *filt_coeff = allpass_poles_3_ov_2; + const Word16 *filt_coeff = allpass_poles_3_ov_2; // Q15 out1 = out1_buff; FOR( i = 0; i < len; i++ ) { /* Upper branch */ - Vu[0] = L_add( mem[0], Mpy_32_16_1( ( input[i] - mem[1] ), filt_coeff[0] ) ); + Vu[0] = L_add( mem[0], Mpy_32_16_1( L_sub( input[i], mem[1] ), filt_coeff[0] ) ); // Qx + Q15 - Q15 -> Qx move32(); - Vu[1] = L_add( mem[1], Mpy_32_16_1( ( Vu[0] - mem[2] ), filt_coeff[1] ) ); + Vu[1] = L_add( mem[1], Mpy_32_16_1( L_sub( Vu[0], mem[2] ), filt_coeff[1] ) ); // Qx + Q15 - Q15 -> Qx move32(); - mem[3] = L_add( mem[2], Mpy_32_16_1( ( Vu[1] - mem[3] ), filt_coeff[2] ) ); + mem[3] = L_add( mem[2], Mpy_32_16_1( L_sub( Vu[1], mem[3] ), filt_coeff[2] ) ); // Qx + Q15 - Q15 -> Qx move32(); - mem[1] = Vu[0]; + mem[1] = Vu[0]; // Qx move32(); - mem[2] = Vu[1]; + mem[2] = Vu[1]; // Qx move32(); - *out1++ = mem[3]; + *out1++ = mem[3]; // Qx move32(); /* Middle branch */ - Vm[0] = L_add( mem[0], Mpy_32_16_1( ( input[i] - mem[4] ), filt_coeff[3] ) ); + Vm[0] = L_add( mem[0], Mpy_32_16_1( L_sub( input[i], mem[4] ), filt_coeff[3] ) ); // Qx + Q15 - Q15 -> Qx move32(); - Vm[1] = L_add( mem[4], Mpy_32_16_1( ( Vm[0] - mem[5] ), filt_coeff[4] ) ); + Vm[1] = L_add( mem[4], Mpy_32_16_1( L_sub( Vm[0], mem[5] ), filt_coeff[4] ) ); // Qx + Q15 - Q15 -> Qx move32(); - mem[6] = L_add( mem[5], Mpy_32_16_1( ( Vm[1] - mem[6] ), filt_coeff[5] ) ); + mem[6] = L_add( mem[5], Mpy_32_16_1( L_sub( Vm[1], mem[6] ), filt_coeff[5] ) ); // Qx + Q15 - Q15 -> Qx move32(); - mem[4] = Vm[0]; + mem[4] = Vm[0]; // Qx move32(); - mem[5] = Vm[1]; + mem[5] = Vm[1]; // Qx move32(); - *out1++ = mem[6]; + *out1++ = mem[6]; // Qx move32(); /* Lower branch */ - Vl[0] = L_add( mem[0], Mpy_32_16_1( ( input[i] - mem[7] ), filt_coeff[6] ) ); + Vl[0] = L_add( mem[0], Mpy_32_16_1( L_sub( input[i], mem[7] ), filt_coeff[6] ) ); // Qx + Q15 - Q15 -> Qx move32(); - Vl[1] = L_add( mem[7], Mpy_32_16_1( ( Vl[0] - mem[8] ), filt_coeff[7] ) ); + Vl[1] = L_add( mem[7], Mpy_32_16_1( L_sub( Vl[0], mem[8] ), filt_coeff[7] ) ); // Qx + Q15 - Q15 -> Qx move32(); - mem[9] = L_add( mem[8], Mpy_32_16_1( ( Vl[1] - mem[9] ), filt_coeff[8] ) ); + mem[9] = L_add( mem[8], Mpy_32_16_1( L_sub( Vl[1], mem[9] ), filt_coeff[8] ) ); // Qx + Q15 - Q15 -> Qx move32(); - mem[0] = input[i]; + mem[0] = input[i]; // Qx move32(); - mem[7] = Vl[0]; + mem[7] = Vl[0]; // Qx move32(); - mem[8] = Vl[1]; + mem[8] = Vl[1]; // Qx move32(); - *out1++ = mem[9]; + *out1++ = mem[9]; // Qx move32(); } @@ -961,17 +961,19 @@ void interpolate_3_over_2_allpass_32( { mem_temp = out1_buff[2 * i]; move32(); - out[i] = L_add( Mpy_32_16_1( ( mem_temp + mem[10] ), 1550 ), Mpy_32_16_1( ( mem[11] + mem[14] ), -4965 ) ); - out[i] = L_add( out[i], Mpy_32_16_1( ( mem[12] + mem[13] ), 20125 ) ); - mem[10] = mem[11]; + out[i] = L_add( Mpy_32_16_1( L_add( mem_temp, mem[10] ), 1550 ), Mpy_32_16_1( L_add( mem[11], mem[14] ), -4965 ) ); // Qx + Q15 - Q15 -> Qx + // 0.0473147f in Q15 -> 1550, -0.151521f in Q15 -> -4965 + out[i] = L_add( out[i], Mpy_32_16_1( L_add( mem[12], mem[13] ), 20125 ) ); + // 0.614152f in Q15 -> 20125 + mem[10] = mem[11]; // Qx move32(); - mem[11] = mem[12]; + mem[11] = mem[12]; // Qx move32(); - mem[12] = mem[13]; + mem[12] = mem[13]; // Qx move32(); - mem[13] = mem[14]; + mem[13] = mem[14]; // Qx move32(); - mem[14] = mem_temp; + mem[14] = mem_temp; // Qx move32(); } @@ -1127,67 +1129,67 @@ void interpolate_3_over_1_allpass( #ifdef IVAS_FLOAT_FIXED void interpolate_3_over_1_allpass_32( - const Word32 *input, /* i : input signal */ - const Word16 len, /* i : number of input samples */ - Word32 *out, /* o : output signal */ - Word32 *mem /* i/o: memory */ + const Word32 *input, /* i : input signal Qx */ + const Word16 len, /* i : number of input samples */ + Word32 *out, /* o : output signal */ + Word32 *mem /* i/o: memory */ ) { Word16 i, tmp16; Word32 Vu[2], Vm[2], Vl[2]; /* Outputs of three cascaded allpass stages (upper, middle, and lower) */ Word32 *out1; Word32 mem_temp; - const Word16 *filt_coeff = allpass_poles_3_ov_2; + const Word16 *filt_coeff = allpass_poles_3_ov_2; // Qx out1 = &out[0]; FOR( i = 0; i < len; i++ ) { /* Upper branch */ - Vu[0] = L_add_sat( mem[0], Mpy_32_16_1( L_sub( input[i], mem[1] ), filt_coeff[0] ) ); + Vu[0] = L_add_sat( mem[0], Mpy_32_16_1( L_sub( input[i], mem[1] ), filt_coeff[0] ) ); // Qx move32(); - Vu[1] = L_add_sat( mem[1], Mpy_32_16_1( L_sub( Vu[0], mem[2] ), filt_coeff[1] ) ); + Vu[1] = L_add_sat( mem[1], Mpy_32_16_1( L_sub( Vu[0], mem[2] ), filt_coeff[1] ) ); // Qx move32(); - mem[3] = L_add_sat( mem[2], Mpy_32_16_1( L_sub( Vu[1], mem[3] ), filt_coeff[2] ) ); + mem[3] = L_add_sat( mem[2], Mpy_32_16_1( L_sub( Vu[1], mem[3] ), filt_coeff[2] ) ); // Qx move32(); - mem[1] = Vu[0]; + mem[1] = Vu[0]; // Qx move32(); - mem[2] = Vu[1]; + mem[2] = Vu[1]; // Qx move32(); - *out1++ = mem[3]; + *out1++ = mem[3]; // Qx move32(); /* Middle branch */ - Vm[0] = L_add_sat( mem[0], Mpy_32_16_1( L_sub( input[i], mem[4] ), filt_coeff[3] ) ); + Vm[0] = L_add_sat( mem[0], Mpy_32_16_1( L_sub( input[i], mem[4] ), filt_coeff[3] ) ); // Qx move32(); - Vm[1] = L_add_sat( mem[4], Mpy_32_16_1( L_sub( Vm[0], mem[5] ), filt_coeff[4] ) ); + Vm[1] = L_add_sat( mem[4], Mpy_32_16_1( L_sub( Vm[0], mem[5] ), filt_coeff[4] ) ); // Qx move32(); - mem[6] = L_add_sat( mem[5], Mpy_32_16_1( L_sub( Vm[1], mem[6] ), filt_coeff[5] ) ); + mem[6] = L_add_sat( mem[5], Mpy_32_16_1( L_sub( Vm[1], mem[6] ), filt_coeff[5] ) ); // Qx move32(); - mem[4] = Vm[0]; + mem[4] = Vm[0]; // Qx move32(); - mem[5] = Vm[1]; + mem[5] = Vm[1]; // Qx move32(); - *out1++ = mem[6]; + *out1++ = mem[6]; // Qx move32(); /* Lower branch */ - Vl[0] = L_add_sat( mem[0], Mpy_32_16_1( L_sub( input[i], mem[7] ), filt_coeff[6] ) ); + Vl[0] = L_add_sat( mem[0], Mpy_32_16_1( L_sub( input[i], mem[7] ), filt_coeff[6] ) ); // Qx move32(); - Vl[1] = L_add_sat( mem[7], Mpy_32_16_1( L_sub( Vl[0], mem[8] ), filt_coeff[7] ) ); + Vl[1] = L_add_sat( mem[7], Mpy_32_16_1( L_sub( Vl[0], mem[8] ), filt_coeff[7] ) ); // Qx move32(); - mem[9] = L_add_sat( mem[8], Mpy_32_16_1( L_sub( Vl[1], mem[9] ), filt_coeff[8] ) ); + mem[9] = L_add_sat( mem[8], Mpy_32_16_1( L_sub( Vl[1], mem[9] ), filt_coeff[8] ) ); // Qx move32(); - mem[0] = input[i]; + mem[0] = input[i]; // Qx move32(); - mem[7] = Vl[0]; + mem[7] = Vl[0]; // Qx move32(); - mem[8] = Vl[1]; + mem[8] = Vl[1]; // Qx move32(); - *out1++ = mem[9]; + *out1++ = mem[9]; // Qx move32(); } @@ -1195,15 +1197,16 @@ void interpolate_3_over_1_allpass_32( tmp16 = imult1616( len, 3 ); FOR( i = 0; i < tmp16; i++ ) { - mem_temp = out[i]; + mem_temp = out[i]; // Qx move32(); - out[i] = L_sub_sat( Mpy_32_16_1( L_add_sat( mem[12], mem[11] ), 18768 ), Mpy_32_16_1( L_add_sat( mem_temp, mem[10] ), 2424 ) ); + out[i] = L_sub_sat( Mpy_32_16_1( L_add_sat( mem[12], mem[11] ), 18768 ), Mpy_32_16_1( L_add_sat( mem_temp, mem[10] ), 2424 ) ); // Qx + // 0.572769 in Q15 -> 18768, 0.074005 in Q15 -> 2424 move32(); - mem[10] = mem[11]; + mem[10] = mem[11]; // Qx move32(); - mem[11] = mem[12]; + mem[11] = mem[12]; // Qx move32(); - mem[12] = mem_temp; + mem[12] = mem_temp; // Qx move32(); } diff --git a/lib_com/modif_fs_fx.c b/lib_com/modif_fs_fx.c index 3cf2b645d..320682c6b 100644 --- a/lib_com/modif_fs_fx.c +++ b/lib_com/modif_fs_fx.c @@ -280,7 +280,7 @@ Word16 modify_Fs_ivas_fx( /* o : length of output Q test(); test(); test(); - if ( GT_32( fin, 16000 ) && ( EQ_16( lg_out, L_FRAME ) || EQ_16( lg_out, L_FRAME16k ) || EQ_16( lg_out, 512 ) ) ) + IF( GT_32( fin, 16000 ) && ( EQ_16( lg_out, L_FRAME ) || EQ_16( lg_out, L_FRAME16k ) || EQ_16( lg_out, 512 ) ) ) { #ifdef BASOP_NOGLOB num_den = shl_o( num_den, 1, &Overflow ); @@ -378,6 +378,7 @@ Word16 modify_Fs_fx( /* o : length of output Q0 */ * Find the resampling configuration *-------------------------------------------------------------------*/ *Q_new_inp = 0; + move16(); /* check if fin and fout are the same */ IF( EQ_32( fin, fout ) ) { @@ -385,6 +386,8 @@ Word16 modify_Fs_fx( /* o : length of output Q0 */ Copy( sigIn_fx, sigOut_fx, lg ); *mem_decim_size = 0; *Q_new_inp = 0; + move16(); + move16(); return lg; } ELSE @@ -450,6 +453,7 @@ Word16 modify_Fs_fx( /* o : length of output Q0 */ mem_len = shl( filt_len, 1 ); *mem_decim_size = mem_len; + move16(); signal_fx = signal_tab_fx + 2 * L_FILT_MAX + sub( L_FRAME48k, add( mem_len, lg ) ); signal_ana_fx = signal_fx; mem_len_ana = mem_len; @@ -468,7 +472,7 @@ Word16 modify_Fs_fx( /* o : length of output Q0 */ IF( plus_sample_in > 0 ) { - autocorr_fx( signal_ana_fx + mem_len_ana + lg - LEN_WIN_SSS, 1, r_fx_h, r_fx_l, &Q_r, LEN_WIN_SSS, wind_sss_fx, 0, 0 ); + autocorr_fx( signal_ana_fx + sub( add( mem_len_ana, lg ), LEN_WIN_SSS ), 1, r_fx_h, r_fx_l, &Q_r, LEN_WIN_SSS, wind_sss_fx, 0, 0 ); t1 = L_Comp( r_fx_h[1], r_fx_l[1] ); /* R[1] in Q31 */ @@ -487,11 +491,11 @@ Word16 modify_Fs_fx( /* o : length of output Q0 */ mu_preemph_fx = extract_h( t0 ); /*r_fx[1] / r_fx[0]; */ mem_preemph_fx = signal_ana_fx[mem_len_ana + lg - LEN_WIN_SSS - 1]; move16(); - PREEMPH_FX( signal_ana_fx + mem_len_ana + lg - LEN_WIN_SSS, mu_preemph_fx, LEN_WIN_SSS, &mem_preemph_fx ); + PREEMPH_FX( signal_ana_fx + sub( add( mem_len_ana, lg ), LEN_WIN_SSS ), mu_preemph_fx, LEN_WIN_SSS, &mem_preemph_fx ); /* Autocorrelations */ - autocorr_fx( signal_ana_fx + mem_len_ana + lg - LEN_WIN_SSS, M, r_fx_h, r_fx_l, &Q_r, + autocorr_fx( signal_ana_fx + sub( add( mem_len_ana, lg ), LEN_WIN_SSS ), M, r_fx_h, r_fx_l, &Q_r, LEN_WIN_SSS, wind_sss_fx, 0, 0 ); /* Lag windowing */ @@ -505,7 +509,7 @@ Word16 modify_Fs_fx( /* o : length of output Q0 */ FOR( i = 0; i < plus_sample_in; i++ ) { - sigPtr = signal_fx + lg + mem_len + i; + sigPtr = signal_fx + add( add( lg, mem_len ), i ); move16(); /*+i*/ L_tmp = syn_kern_16( 0, A_fx, sigPtr ); #ifdef BASOP_NOGLOB @@ -518,7 +522,7 @@ Word16 modify_Fs_fx( /* o : length of output Q0 */ } mem_preemph_fx = signal_fx[mem_len + lg - LEN_WIN_SSS - 1]; move16(); - deemph_fx( signal_fx + mem_len + lg - LEN_WIN_SSS, mu_preemph_fx, LEN_WIN_SSS + plus_sample_in, &mem_preemph_fx ); + deemph_fx( signal_fx + sub( add( mem_len, lg ), LEN_WIN_SSS ), mu_preemph_fx, add( LEN_WIN_SSS, plus_sample_in ), &mem_preemph_fx ); } /* interpolation */ @@ -543,6 +547,7 @@ Word16 modify_Fs_fx( /* o : length of output Q0 */ #else sigOut_fx[i] = round_fx( Interpol_lc_fx( sigIn_ptr, cfg_ptr_fx->filter_fx, frac, fac_num, filt_len_tmp ) ); #endif + move16(); frac = add( frac, fracstep ); j = sub( fac_num, frac ); @@ -555,7 +560,7 @@ Word16 modify_Fs_fx( /* o : length of output Q0 */ /* rescaling */ test(); - IF( ( GT_16( fac_num, fac_den ) ) == ( ( cfg_ptr_fx->flags_fx & RS_INV_FAC ) != 0 ) ) + IF( EQ_32( ( GT_16( fac_num, fac_den ) ), ( ( cfg_ptr_fx->flags_fx & RS_INV_FAC ) != 0 ) ) ) { IF( LT_16( fac_num, fac_den ) ) { @@ -568,6 +573,8 @@ Word16 modify_Fs_fx( /* o : length of output Q0 */ { sigOut_fx[i] = round_fx( L_shl( L_mult( sigOut_fx[i], num_den ), 1 ) ); /*Q0*/ *Q_new_inp = -1; + move16(); + move16(); } } ELSE @@ -590,6 +597,7 @@ Word16 modify_Fs_fx( /* o : length of output Q0 */ move16(); } *Q_new_inp = -1; + move16(); } } ELSE @@ -603,6 +611,7 @@ Word16 modify_Fs_fx( /* o : length of output Q0 */ sigOut_fx[i] = mult_r( sigOut_fx[i], num_den ); /*Q-1*/ move16(); *Q_new_inp = -2; + move16(); } } ELSE @@ -612,6 +621,8 @@ Word16 modify_Fs_fx( /* o : length of output Q0 */ { sigOut_fx[i] = round_fx( L_mac( L_deposit_h( sigOut_fx[i] ), sigOut_fx[i], num_den ) ); /*Q0*/ *Q_new_inp = -1; + move16(); + move16(); } } } @@ -623,6 +634,7 @@ Word16 modify_Fs_fx( /* o : length of output Q0 */ sigOut_fx[i] = mult_r( sigOut_fx[i], 16384 ); move16(); /*Q-1*/ *Q_new_inp = -2; + move16(); } } /* update the filter memory */ @@ -893,11 +905,11 @@ Word16 modify_Fs_intcub3m_sup_fx( /* o : length of output if ( LT_16( ctptr[10], 3 ) ) { - *sigOutptr++ = sigIn[add( i, 1 )]; + *sigOutptr++ = sigIn[i + 1]; move16(); } - FOR( k1 = ctptr[add( k, 1 )]; k1 < fk1; k1 += inc ) + FOR( k1 = ctptr[k + 1]; k1 < fk1; k1 += inc ) { cptr = &( cc[kk][0] ); uptr = &( cu[k1][0] ); @@ -912,7 +924,7 @@ Word16 modify_Fs_intcub3m_sup_fx( /* o : length of output if ( EQ_16( ctptr[10], 1 ) ) { - *sigOutptr = sigIn[add( i, 2 )]; + *sigOutptr = sigIn[i + 2]; move16(); } } @@ -1558,7 +1570,7 @@ void interpolate_3_over_1_allpass_fx( Word16 Vu[2], Vm[2], Vl[2]; /* Outputs of three cascaded allpass stages (upper, middle, and lower) */ Word16 *out1; Word16 mem_temp; - const Word16 *filt_coeff_fx = allpass_poles_3_ov_2; + const Word16 *filt_coeff_fx = allpass_poles_3_ov_2; // Q15 out1 = &out_fx[0]; diff --git a/lib_com/mslvq_com_fx.c b/lib_com/mslvq_com_fx.c index 748f2f564..3ff688d7b 100644 --- a/lib_com/mslvq_com_fx.c +++ b/lib_com/mslvq_com_fx.c @@ -151,6 +151,7 @@ void init_lvq_fx( move16(); WHILE( ( LT_16( j, MAX_NO_SCALES ) ) && ( no_lead_p_fx[i][j] > 0 ) ) { + test(); j++; } no_scales_p[i][0] = j; @@ -159,6 +160,7 @@ void init_lvq_fx( move16(); WHILE( ( LT_16( j, shl( MAX_NO_SCALES, 1 ) ) ) && ( no_lead_p_fx[i][j] > 0 ) ) { + test(); j++; } no_scales_p[i][1] = sub( j, MAX_NO_SCALES ); @@ -587,6 +589,7 @@ Word16 deindex_lvq_fx( /* Increase calculation accuracy by shifting more to the left and using rounding instead of truncation*/ L_tmp = L_shl( Mult_32_16( L_tmp, shl( sigma_MSLVQ_fx[mode][i], 3 ) ), 15 ); /* Q13 + Q2 +x2.56 -Q15 */ x_lvq[i] = round_fx( L_tmp ); + move16(); } } IF( scales_mslvq[1] ) @@ -596,6 +599,7 @@ Word16 deindex_lvq_fx( L_tmp = L_mult( x_lvq[i], scales_mslvq[1] ); /* Q1+Q11+Q1 = Q13 */ L_tmp = L_shl( Mult_32_16( L_tmp, shl( sigma_MSLVQ_fx[mode][i], 3 ) ), 15 ); /* Q13 + Q2 +x2.56 -Q15 */ x_lvq[i] = round_fx( L_tmp ); + move16(); } } } @@ -609,6 +613,7 @@ Word16 deindex_lvq_fx( L_tmp = L_mult( x_lvq[i], scales_mslvq[0] ); /* Q1+Q11+Q1 = Q13 */ L_tmp = L_shl( Mult_32_16( L_tmp, shl( sigma_p_fx[mode][i], 3 ) ), 15 ); /* Q13 + Q2 +x2.56 -Q15 */ x_lvq[i] = round_fx( L_tmp ); + move16(); } } IF( scales_mslvq[1] ) @@ -618,6 +623,7 @@ Word16 deindex_lvq_fx( L_tmp = L_mult( x_lvq[i], scales_mslvq[1] ); /* Q1+Q11+Q1 = Q13 */ L_tmp = L_shl( Mult_32_16( L_tmp, shl( sigma_p_fx[mode][i], 3 ) ), 15 ); /* Q13 + Q2 +x2.56 -Q15 */ x_lvq[i] = round_fx( L_tmp ); + move16(); } } } @@ -656,6 +662,7 @@ Word16 deindex_lvq_ivas_fx( } ELSE { + test(); IF( ( LT_16( mode, 6 ) ) || ( EQ_16( mode, 12 ) ) ) /* for NB */ { mode_glb = add( offset_lvq_modes_pred[mode], offset_in_lvq_mode_pred[mode][sub( no_bits, min_lat_bits_pred[mode] )] ); @@ -1002,6 +1009,7 @@ static void decode_leaders_fx( case 4: dim_loc = add( dim_loc, no_vals_ind[idx_lead][2] ); n_crt = no_vals_ind[idx_lead][2]; + move16(); index1 = divide_16_16_fx( index, C_VQ[dim_loc][n_crt], &index ); /* index1 = index/C_VQ_fx[dim_loc][n_crt]; */ /*index = sub(index, i_mult2(index1, C_VQ_fx[dim_loc][n_crt]) ); */ /* index-= index1*C_VQ_fx[dim_loc][n_crt]; */ move16(); idx2c_fx( dim_loc, p, n_crt, index ); diff --git a/lib_com/nelp_fx.c b/lib_com/nelp_fx.c index a357b7455..b37d57093 100644 --- a/lib_com/nelp_fx.c +++ b/lib_com/nelp_fx.c @@ -127,7 +127,7 @@ Word16 dequantize_uvg_fx( L_tmp = L_shr_r( L_tmp, 11 ); /* Q16 */ frac = L_Extract_lc( L_tmp, &exp ); frac = extract_l( Pow2( 14, frac ) ); - G[i * 5 + k] = round_fx( L_shl( L_mult( frac, UVG2CB1[iG2[i]][k] ), exp - sc ) ); /* Q0 */ + G[i * 5 + k] = round_fx( L_shl( L_mult( frac, UVG2CB1[iG2[i]][k] ), sub( exp, sc ) ) ); /* Q0 */ move16(); } ELSE IF( EQ_16( i, 1 ) ) @@ -136,7 +136,7 @@ Word16 dequantize_uvg_fx( L_tmp = L_shr_r( L_tmp, 11 ); /* Q16 */ frac = L_Extract_lc( L_tmp, &exp ); frac = extract_l( Pow2( 14, frac ) ); - G[i * 5 + k] = round_fx( L_shl( L_mult( frac, UVG2CB2[iG2[i]][k] ), exp - sc ) ); /* Q0 */ + G[i * 5 + k] = round_fx( L_shl( L_mult( frac, UVG2CB2[iG2[i]][k] ), sub( exp, sc ) ) ); /* Q0 */ move16(); } } diff --git a/lib_com/parameter_bitmaping.c b/lib_com/parameter_bitmaping.c index ff7a9c5bd..50cf4886f 100644 --- a/lib_com/parameter_bitmaping.c +++ b/lib_com/parameter_bitmaping.c @@ -214,6 +214,7 @@ void GetParameters_fx( pSubStruct = param->GetParamValue( pParameter, index, &value ); #undef WMC_TOOL_SKIP /* If a function for encoding/decoding value is defined than it should take care of 0 */ + test(); IF( param->fZeroAllowed || ( param->EncodeValue != NULL ) ) { *( *pStream )++ = value; @@ -236,6 +237,8 @@ void GetParameters_fx( } move16(); #undef WMC_TOOL_SKIP + + test(); IF( ( param->pSubParamBitMap != NULL ) && ( value > 0 ) ) { GetParameters_fx( param->pSubParamBitMap, value, ( pSubStruct != NULL ) ? pSubStruct : pParameter, pStream, pnSize, pnBits ); diff --git a/lib_com/prot.h b/lib_com/prot.h index f895ef5f2..1f54c2b1b 100644 --- a/lib_com/prot.h +++ b/lib_com/prot.h @@ -7818,13 +7818,13 @@ void tcx_arith_scale_envelope_ivas( ); void tcx_arith_render_envelope_ivas( - const Word16 A_ind[], /* i : LPC coefficients of signal envelope */ - const Word16 L_frame, /* i : number of spectral lines */ - const Word16 L_spec, /* i : length of the coded spectrum */ - const Word16 preemph_fac, /* i : pre-emphasis factor */ - const Word16 gamma_w, /* i : A_ind -> weighted envelope factor */ - const Word16 gamma_uw, /* i : A_ind -> non-weighted envelope factor */ - Word32 env[] /* o : shaped signal envelope */ + const Word16 A_ind[], /* i : LPC coefficients of signal envelope Q12*/ + const Word16 L_frame, /* i : number of spectral lines Q0*/ + const Word16 L_spec, /* i : length of the coded spectrum Q0*/ + const Word16 preemph_fac, /* i : pre-emphasis factor Q15*/ + const Word16 gamma_w, /* i : A_ind -> weighted envelope factor Q15*/ + const Word16 gamma_uw, /* i : A_ind -> non-weighted envelope factor Q14*/ + Word32 env[] /* o : shaped signal envelope Q16*/ ); int16_t ari_encode_14bits_range( diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index d615e511b..de27c37c2 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -449,13 +449,13 @@ void logqnorm_fx( ); void logqnorm_2_fx( - const Word32 *env_fl, /* o : index */ + const Word32 *env_fl, /* o, Q10 : index */ const Word16 L, /* i : codebook length */ const Word16 n_env_band, /* i : sub-vector size */ const Word16 nb_sfm, /* i : sub-vector size */ - Word16 *ynrm, - Word16 *normqlg2, - const Word32 *thren /* i : quantization thresholds */ + Word16 *ynrm, /* o : norm indices Q0*/ + Word16 *normqlg2, /* o : quantized norm values Q0*/ + const Word32 *thren /* i, Q10 : quantization thresholds */ ); void calc_norm_fx( @@ -470,21 +470,21 @@ void calc_norm_fx( ); #ifdef IVAS_FLOAT_FIXED void calc_norm_ivas_fx( - const Word32 *x_fx, /* i : Input vector. */ - Word16 *norm, /* o : Quantization indices for norms */ - Word16 *normlg, /* o : Quantized norms in log2 */ + const Word32 *x_fx, /* i : Input vector.(Qin) */ + Word16 *norm, /* o : Quantization indices for norms Q0 */ + Word16 *normlg, /* o : Quantized norms in log2 Q0 */ const Word16 start_band, /* i : Indice of band to start coding */ const Word16 num_bands, /* i : Number of bands */ const Word16 *band_len, /* i : Length of bands */ const Word16 *band_start /* i : Start of bands */ ); void logqnorm_ivas_fx( - const Word32 *x_fx, /* i : coefficient vector */ + const Word32 *x_fx, /* i : coefficient vector Qq*/ const Word16 q, /* i : q of coefficient vector */ - Word16 *k_fx, /* o : index */ + Word16 *k_fx, /* o : index (Q0)*/ const Word16 L, /* i : codebook length */ const Word16 N, /* i : sub-vector size */ - const Word32 *thre_fxn /* i : quantization thresholds */ + const Word32 *thre_fxn /* i : quantization thresholds Q14*/ ); #endif /*========================================================================================================/ @@ -764,7 +764,8 @@ Word16 xsp_to_xsf( Word16 lsp ); Word16 xsf_to_xsp( - Word16 lsf ); + Word16 lsf /* Q2.56 */ +); void lsp_convolve_fx( Word32 x, Word32 *p1, Word32 *p2, Word16 len ); Word32 poscos_fx( Word16 w ); @@ -849,49 +850,50 @@ Word16 tcxlpc_get_cdk( ); void lsf_syn_mem_restore_fx( - Encoder_State *st_fx, /* o: state structure */ - Word16 btilt_code_fx, /* i: */ - Word32 gc_threshold_fx, /* i: */ - Word16 *clip_var_bck_fx, /* i: */ - Word16 next_force_sf_bck_fx, /* i: */ - Word16 *lsp_new, /* o: LSP vector to quantize */ - Word16 *lsf_new, /* o: quantized LSF vector */ - Word16 *lsp_mid, /* o: mid-frame LSP vector */ - Word16 clip_var, /* i: pitch clipping state var */ - Word16 *mem_AR, /* i: quantizer memory for AR model */ - Word16 *mem_MA, /* i: quantizer memory for MA model */ - Word16 *lsp_new_bck, /* i: LSP vector to quantize- backup */ - Word16 *lsf_new_bck, /* i: quantized LSF vector - backup */ - Word16 *lsp_mid_bck, /* i: mid-frame LSP vector - backup */ - Word16 mCb1, /* i: counter for stationary frame after a transition frame */ - Word32 *Bin_E, /* i: FFT Bin energy 128 *2 sets */ - Word32 *Bin_E_old, /* i: FFT Bin energy 128 sets */ - Word16 *mem_syn_bck, /* i: synthesis filter memory */ - Word16 mem_w0_bck, /* i: memory of the weighting filter */ - Word16 streaklimit, /* i:LSF quantizer */ - Word16 pstreaklen /* i:LSF quantizer */ + Encoder_State *st_fx, /* o: state structure */ + Word16 btilt_code_fx, /* i: Q15 */ + Word32 gc_threshold_fx, /* i: Q16 */ + Word16 *clip_var_bck_fx, /* i: Q(2.56), Q14, Q7, Q0, Q14, Q14 */ + Word16 next_force_sf_bck_fx, /* i: */ + + Word16 *lsp_new, /* o: LSP vector to quantize Q15 */ + Word16 *lsf_new, /* o: quantized LSF vector Q15 */ + Word16 *lsp_mid, /* o: mid-frame LSP vector Q15 */ + Word16 clip_var, /* i: pitch clipping state var Q(2.56) */ + Word16 *mem_AR, /* i: quantizer memory for AR model Q15 */ + Word16 *mem_MA, /* i: quantizer memory for MA model Q15 */ + Word16 *lsp_new_bck, /* i: LSP vector to quantize- backup Q15 */ + Word16 *lsf_new_bck, /* i: quantized LSF vector - backup Q15 */ + Word16 *lsp_mid_bck, /* i: mid-frame LSP vector - backup Q15 */ + Word16 mCb1, /* i: counter for stationary frame after a transition frame */ + Word32 *Bin_E, /* i: FFT Bin energy 128 *2 sets Q_new + Q_SCALE - 2 */ + Word32 *Bin_E_old, /* i: FFT Bin energy 128 sets Q_new + Q_SCALE - 2 */ + Word16 *mem_syn_bck, /* i: synthesis filter memory ( 15 - st_fx->hLPDmem->e_mem_syn ) */ + Word16 mem_w0_bck, /* i: memory of the weighting filter ( 15 - st_fx->hLPDmem->e_mem_syn ) */ + Word16 streaklimit, /* i:LSF quantizer Q15 */ + Word16 pstreaklen /* i:LSF quantizer */ ); #ifdef IVAS_FLOAT_FIXED void lsf_syn_mem_restore_ivas_fx( - Encoder_State *st_fx, /* o: state structure */ - Word16 btilt_code_fx, /* i: */ - Word32 gc_threshold_fx, /* i: */ - Word16 *clip_var_bck_fx, /* i: */ - Word16 next_force_sf_bck_fx, /* i: */ - Word16 *lsp_new, /* o: LSP vector to quantize */ - Word16 *lsp_mid, /* o: mid-frame LSP vector */ - Word16 clip_var, /* i: pitch clipping state var */ - Word16 *mem_AR, /* i: quantizer memory for AR model */ - Word16 *mem_MA, /* i: quantizer memory for MA model */ - Word16 *lsp_new_bck, /* i: LSP vector to quantize- backup */ - Word16 *lsp_mid_bck, /* i: mid-frame LSP vector - backup */ - Word32 *Bin_E, /* i: FFT Bin energy 128 *2 sets */ - Word32 *Bin_E_old, /* i: FFT Bin energy 128 sets */ - Word16 *mem_syn_bck, /* i: synthesis filter memory */ - Word16 mem_w0_bck, /* i: memory of the weighting filter */ - Word16 streaklimit, /* i:LSF quantizer */ - Word16 pstreaklen /* i:LSF quantizer */ + Encoder_State *st_fx, /* o: state structure */ + Word16 btilt_code_fx, /* i: Q15 */ + Word32 gc_threshold_fx, /* i: Q16 */ + Word16 *clip_var_bck_fx, /* i: Q(2.56), Q14, Q7, Q0, Q14, Q14 */ + Word16 next_force_sf_bck_fx, /* i: */ + Word16 *lsp_new, /* o: LSP vector to quantize Q15 */ + Word16 *lsp_mid, /* o: mid-frame LSP vector Q15 */ + Word16 clip_var, /* i: pitch clipping state var Q(2.56), Q14, Q7, Q0, Q14, Q14 */ + Word16 *mem_AR, /* i: quantizer memory for AR model 2.56 */ + Word16 *mem_MA, /* i: quantizer memory for MA model 2.56 */ + Word16 *lsp_new_bck, /* i: LSP vector to quantize- backup Q15 */ + Word16 *lsp_mid_bck, /* i: mid-frame LSP vector - backup Q15 */ + Word32 *Bin_E, /* i: FFT Bin energy 128 *2 sets Q_new + Q_SCALE - 2 */ + Word32 *Bin_E_old, /* i: FFT Bin energy 128 sets Q_new + Q_SCALE - 2 */ + Word16 *mem_syn_bck, /* i: synthesis filter memory Q(15 - st_fx->hLPDmem->e_mem_syn ) */ + Word16 mem_w0_bck, /* i: memory of the weighting filter Q(15 - st_fx->hLPDmem->e_mem_syn ) */ + Word16 streaklimit, /* i:LSF quantizer Q15 */ + Word16 pstreaklen /* i:LSF quantizer */ ); #endif @@ -1091,9 +1093,9 @@ lpc_tools_fx.c void autocorr_fx( const Word16 x[], /* i : Input signal */ const Word16 m, /* i : LPC order Q0 */ - Word16 r_h[], /* o : Autocorrelations (msb) Q15 */ - Word16 r_l[], /* o : Autocorrelations (lsb) */ - Word16 *Q_r, /* o : normailsation shift of r Q0 */ + Word16 r_h[], /* o : Autocorrelations (msb) Q15(Q_r -16) */ + Word16 r_l[], /* o : Autocorrelations (lsb) Q(r)-1 */ + Word16 *Q_r, /* o : normalisation shift of r Q0 */ const Word16 len, /* i : Frame lenght */ const Word16 *wind, /* i : Window used */ Word16 rev_flag, @@ -1101,12 +1103,12 @@ void autocorr_fx( ); void autocorr_fx_32( - const Word16 x[], /* i : Input signal */ + const Word16 x[], /* i : Input signal Q(q_x) */ const Word16 m, /* i : LPC order Q0 */ - Word32 r[], /* o : Autocorrelations (msb) */ + Word32 r[], /* o : Autocorrelations Q_r */ Word16 *Q_r, /* o : normalisation shift of r Q0 */ const Word16 len, /* i : Frame lenght */ - const Word16 *wind, /* i : Window used */ + const Word16 *wind, /* i : Window used Q15 */ Word16 rev_flag, const Word16 sym_flag /* i : symmetric window flag */ ); @@ -1121,29 +1123,29 @@ Word16 E_LPC_lev_dur_fx( const Word16 Rh[], const Word16 Rl[], Word32 A[], Word3 Word16 E_LPC_lev_dur_stab_fx( const Word16 Rh[], const Word16 Rl[], Word32 A[], Word32 epsP[], const Word16 order, Word32 *mem, Word16 k_max ); Word16 lev_dur_fx( - Word32 *a_fx, /* o : LP coefficients (a[0] = 1.0) */ - const Word32 *r_fx, /* i : vector of autocorrelations */ + Word32 *a_fx, /* o : LP coefficients (a[0] = 1.0) Q(q_a)*/ + const Word32 *r_fx, /* i : vector of autocorrelations Q(q_r)*/ const Word16 m, /* i : order of LP filter */ - Word32 epsP[], /* o : prediction error energy */ + Word32 epsP[], /* o : prediction error energy Q(q_r)*/ Word16 q_a, Word16 q_r ); -void E_LPC_a_add_tilt( const Word16 *a, Word16 *ap, Word16 gamma, Word16 m ); +void E_LPC_a_add_tilt( const Word16 *a /*Qa*/, Word16 *ap /*Qa*/, Word16 gamma /*Q15*/, Word16 m ); void E_LPC_int_lpc_tcx( const Word16 lsp_old[], /* i : LSPs from past frame (1Q14) */ const Word16 lsp_new[], /* i : LSPs from present frame (1Q14) */ Word16 a[] /* o : interpolated LP coefficients (4Q11) */ ); Word16 E_LPC_lsp_unweight( - /* const */ Word16 xsp_w[], /* (I): weighted xSP */ - Word16 xsp_uw[], /* (O): unweighted xSP */ - Word16 xsf_uw[], /* (O): unweighted xSF */ - Word16 inv_gamma, /* (I): inverse weighting factor */ - Word16 lpcorder /* (I): prediction order */ + /* const */ Word16 lsp_w[], /* (I): weighted xSP Q15 */ + Word16 lsp_uw[], /* (O): unweighted xSP Q15 */ + Word16 lsf_uw[], /* (O): unweighted LSF Q1*1.28 */ + Word16 inv_gamma, /* (I): inverse weighting factor Q14 */ + Word16 lpcorder /* (I): prediction order Q0 */ ); -Word32 E_LPC_schur( Word32 r[], Word16 reflCoeff[], Word32 epsP[], const Word16 m ); -void E_LPC_a_lsf_isf_conversion( Word16 *lpcCoeffs, Word16 *lsf, const Word16 *old_lsf, Word16 lpcOrder, Word8 lpcRep ); +Word32 E_LPC_schur( Word32 r[] /*Qr*/, Word16 reflCoeff[] /*Q15*/, Word32 epsP[] /*Qr*/, const Word16 m ); +void E_LPC_a_lsf_isf_conversion( Word16 *lpcCoeffs /*Qx*/, Word16 *lsf /*15Q16*/, const Word16 *old_lsf /*15Q16*/, Word16 lpcOrder, Word8 lpcRep /*Q0*/ ); /*========================================================================================================/ @@ -4852,15 +4854,15 @@ void get_max_pulses_fx( const Word16 *k_sort, /* i : Indices for sorting by energy */ const Word16 *npulses, /* i : Pulses per sub band */ const Word16 BANDS, /* i : Number of bands */ - Word16 *inp_vector, /* i/o: Encoded shape vectors (int)*/ - Word16 *maxpulse /* o : Maximum pulse height per band */ + Word16 *inp_vector, /* i/o: Encoded shape vectors (int)Q0*/ + Word16 *maxpulse /* o : Maximum pulse height per band Q0*/ ); void fine_gain_dec_fx( Decoder_State *st, const Word16 *ord, /* i : Indices for energy order */ const Word16 num_sfm, /* i : Number of bands */ const Word16 *gain_bits, /* i : Gain adjustment bits per sub band */ - Word16 *fg_pred /* i/o: Predicted gains / Corrected gains */ + Word16 *fg_pred /* i/o: Predicted gains / Corrected gains Q12*/ ); // fine_gain_bits_fx.c @@ -4959,15 +4961,15 @@ void lsf_dec_bfi( const Word16 lsfBase[], /* i : base for differential lsf coding */ Word16 *mem_MA, /*!< i/o: 14Q1*1.28 quantizer memory for MA model */ Word16 *mem_AR, /*!< i/o: 14Q1*1.28 quantizer memory for MA model */ - Word16 stab_fac, /*!< i : ISF stability factor (shifted right by 1) */ + Word16 stab_fac, /*!< i : ISF stability factor (shifted right by 1) Q15*/ const Word16 last_coder_type, /*!< i : coding type in last good received fr. */ Word16 L_frame, const Word16 last_good, /*!< i : last good received frame */ const Word16 nbLostCmpt, /*!< i : counter of consecutive bad frames */ const Word8 plcBackgroundNoiseUpdated, /* i : background noise already updated?*/ Word16 *lsf_q_cng, /* o : quantized ISFs for background noise (14Q1*1.28) */ - Word16 *lsf_cng, - Word16 *old_lsf_q_cng, /* o : old quantized ISFs for background noise */ + Word16 *lsf_cng, /* Q2.56 */ + Word16 *old_lsf_q_cng, /* o : old quantized ISFs for background noise Q2.56*/ const Word16 Last_GSC_pit_band_idx, const Word16 Opt_AMR_WB, /* i : IO flag */ const Word8 tcxonly, @@ -5736,13 +5738,13 @@ void tcx_arith_scale_envelope( ); void tcx_arith_render_envelope( - const Word16 A_ind[], /* i: LPC coefficients of signal envelope */ - const Word16 L_frame, /* i: number of spectral lines */ - const Word16 L_spec, - const Word16 preemph_fac, /* i: pre-emphasis factor */ - const Word16 gamma_w, /* i: A_ind -> weighted envelope factor */ - const Word16 gamma_uw, /* i: A_ind -> non-weighted envelope factor */ - Word32 env[] /* o: shaped signal envelope */ + const Word16 A_ind[], /* i: LPC coefficients of signal envelope Q12*/ + const Word16 L_frame, /* i: number of spectral lines Q0*/ + const Word16 L_spec, /* Q0 */ + const Word16 preemph_fac, /* i: pre-emphasis factor Q15*/ + const Word16 gamma_w, /* i: A_ind -> weighted envelope factor Q15*/ + const Word16 gamma_uw, /* i: A_ind -> non-weighted envelope factor Q14*/ + Word32 env[] /* o: shaped signal envelope Q16*/ ); @@ -8667,8 +8669,8 @@ void midlsf_dec( const Word16 safety_net ); Word16 lsf_ind_is_active( - const Word16 lsf_q_ind[], - const Word16 means[], + const Word16 lsf_q_ind[], /*(14Q1*1.28)*/ + const Word16 means[], /*(14Q1*1.28)*/ const Word16 narrowband, const Word16 cdk ); @@ -9652,10 +9654,10 @@ void generate_masking_noise_dirac_ivas_fx( // modif_fs/c void interpolate_3_over_2_allpass_32( - const Word32 *input, /* i : input signal */ - const int16_t len, /* i : number of input samples */ - Word32 *out, /* o : output signal */ - Word32 *mem /* i/o: memory */ + const Word32 *input, /* i : input signal Qx */ + const int16_t len, /* i : number of input samples */ + Word32 *out, /* o : output signal */ + Word32 *mem /* i/o: memory */ ); void interpolate_3_over_1_allpass_32( @@ -10431,12 +10433,12 @@ void msvq_dec_fx( Word16 exp ); void dec_FDCNG_MSVQ_stage1_fx( - Word16 j_full, /* i : index full range */ - Word16 n, /* i : dimension to generate */ - const Word32 *invTrfMatrix, /* i : IDCT matrix for synthesis */ - const DCTTYPE idcttype, /* i : specify which IDCT */ - Word32 *uq, /* o : synthesized stage1 vector */ - Word16 *uq_ind /* o : synthesized stage1 vector in BASOP */ + Word16 j_full, /* i : index full range */ + Word16 n, /* i : dimension to generate */ + const Word32 *invTrfMatrix, /* i : IDCT matrix for synthesis Q31 */ + const DCTTYPE idcttype, /* i : specify which IDCT */ + Word32 *uq, /* o : synthesized stage1 vector Q20 */ + Word16 *uq_ind /* o : synthesized stage1 vector in BASOP */ ); void dctT2_N_apply_matrix_fx( @@ -10797,24 +10799,24 @@ Word16 ari_decode_14bits_sign_ivas( Tastat *s ); void lsf_syn_mem_backup_ivas_fx( - Encoder_State *st_fx, /* i: state structure */ - Word16 *btilt_code_fx, /* i: tilt code */ - Word32 *gc_threshold_fx, /* i: */ - Word16 *clip_var_bck_fx, /* o: */ - Word16 *next_force_sf_bck_fx, /* o: */ - - Word16 *lsp_new, /* i: LSP vector to quantize */ - Word16 *lsp_mid, /* i: mid-frame LSP vector */ - Word16 *clip_var, /* o: pitch clipping state var */ - Word16 *mem_AR, /* o: quantizer memory for AR model */ - Word16 *mem_MA, /* o: quantizer memory for AR model */ - Word16 *lsp_new_bck, /* o: LSP vector to quantize- backup */ - Word16 *lsp_mid_bck, /* o: mid-frame LSP vector - backup */ - Word32 *Bin_E, /* o: FFT Bin energy 128 *2 sets */ - Word32 *Bin_E_old, /* o: FFT Bin energy 128 sets */ - Word16 *mem_syn_bck, /* o: synthesis filter memory */ - Word16 *mem_w0_bck, /* o: memory of the weighting filter */ - Word16 *streaklimit, + Encoder_State *st_fx, /* i: state structure */ + Word16 *btilt_code_fx, /* i: tilt code Q15 */ + Word32 *gc_threshold_fx, /* i: Q16 */ + Word16 *clip_var_bck_fx, /* o: Q(2.56), Q14, Q7, Q0, Q14, Q14 */ + Word16 *next_force_sf_bck_fx, /* o: */ + + Word16 *lsp_new, /* i: LSP vector to quantize Q15 */ + Word16 *lsp_mid, /* i: mid-frame LSP vector Q15 */ + Word16 *clip_var, /* o: pitch clipping state var Q(2.56) */ + Word16 *mem_AR, /* o: quantizer memory for AR model Q(2.56) */ + Word16 *mem_MA, /* o: quantizer memory for AR model Q(2.56) */ + Word16 *lsp_new_bck, /* o: LSP vector to quantize- backup Q15 */ + Word16 *lsp_mid_bck, /* o: mid-frame LSP vector - backup Q15 */ + Word32 *Bin_E, /* o: FFT Bin energy 128 *2 sets Q_new + Q_SCALE - 2 */ + Word32 *Bin_E_old, /* o: FFT Bin energy 128 sets Q_new + Q_SCALE - 2 */ + Word16 *mem_syn_bck, /* o: synthesis filter memory ( 15 - st_fx->hLPDmem->e_mem_syn ) */ + Word16 *mem_w0_bck, /* o: memory of the weighting filter ( 15 - st_fx->hLPDmem->e_mem_syn ) */ + Word16 *streaklimit, /* Q15 */ Word16 *pstreaklen ); ivas_error config_acelp1_IVAS( diff --git a/lib_dec/fd_cng_dec_fx.c b/lib_dec/fd_cng_dec_fx.c index 51c2c4643..ae5f0c2b1 100644 --- a/lib_dec/fd_cng_dec_fx.c +++ b/lib_dec/fd_cng_dec_fx.c @@ -2800,7 +2800,7 @@ void perform_noise_estimation_dec_ivas_fx( } ELSE { - Word16 tmp = s_max( sub( hFdCngDec->msNoiseEst_exp, getScaleFactor32( msPeriodog, npart ) ), sub( hFdCngDec->msPeriodog_exp, getScaleFactor32( &msNoiseEst[npart], sub( NPART_SHAPING, npart ) ) ) ); + Word16 tmp = s_max( sub( hFdCngDec->msPeriodog_exp, getScaleFactor32( msPeriodog, npart ) ), sub( hFdCngDec->msNoiseEst_exp, getScaleFactor32( &msNoiseEst[npart], sub( NPART_SHAPING, npart ) ) ) ); Copy_Scale_sig32( msPeriodog, msNoiseEst, npart, sub( hFdCngDec->msPeriodog_exp, tmp ) ); scale_sig32( &msNoiseEst[npart], sub( NPART_SHAPING, npart ), sub( hFdCngDec->msNoiseEst_exp, tmp ) ); hFdCngDec->msNoiseEst_exp = tmp; diff --git a/lib_dec/hq_core_dec_fx.c b/lib_dec/hq_core_dec_fx.c index de8d19e32..c31727f29 100644 --- a/lib_dec/hq_core_dec_fx.c +++ b/lib_dec/hq_core_dec_fx.c @@ -938,7 +938,7 @@ void ivas_hq_core_dec_fx( // fscaleFB = sr2fscale( st_fx->output_Fs ); // encoderLookahead = ( L_LOOK_12k8 * st_fx->fscale ) / FSCALE_DENOM; // encoderLookaheadFB = ( L_LOOK_12k8 * fscaleFB ) / FSCALE_DENOM; - mdctWindowLength = getMdctWindowLength( st_fx->fscale ); /* Q0 */ + mdctWindowLength = getMdctWindowLength_fx( st_fx->fscale ); /* Q0 */ Word16 temp, temp_e; temp = BASOP_Util_Divide3232_Scale( st_fx->output_Fs, st_fx->sr_core, &temp_e ); mdctWindowLengthFB = extract_l( L_shr( L_mult0( temp, mdctWindowLength ), sub( 15, temp_e ) ) ); /* Q0 */ diff --git a/lib_enc/core_enc_init.c b/lib_enc/core_enc_init.c index fc2bef83c..633675002 100644 --- a/lib_enc/core_enc_init.c +++ b/lib_enc/core_enc_init.c @@ -332,7 +332,7 @@ void init_coder_ace_plus( int16_t L_subfr; /* Bitrate */ - st->tcxonly = getTcxonly_ivas( st->element_mode, st->total_brate, MCT_flag, st->is_ism_format ); + st->tcxonly = getTcxonly_ivas_fx( st->element_mode, st->total_brate, MCT_flag, st->is_ism_format ); /* Core Sampling Rate */ st->sr_core = getCoreSamplerateMode2_flt( st->element_mode, st->total_brate, st->bwidth, st->flag_ACELP16k, st->rf_mode, st->is_ism_format ); diff --git a/lib_enc/ivas_cpe_enc.c b/lib_enc/ivas_cpe_enc.c index 89ae59101..46fc42291 100644 --- a/lib_enc/ivas_cpe_enc.c +++ b/lib_enc/ivas_cpe_enc.c @@ -839,7 +839,7 @@ ivas_error ivas_cpe_enc( { int32_t internal_Fs; - internal_Fs = getTcxonly_ivas( IVAS_CPE_MDCT, sts[0]->bits_frame_nominal * FRAMES_PER_SEC, 0, sts[0]->is_ism_format ) == 0 ? INT_FS_16k : max( INT_FS_16k, sts[0]->sr_core ); + internal_Fs = getTcxonly_ivas_fx( IVAS_CPE_MDCT, sts[0]->bits_frame_nominal * FRAMES_PER_SEC, 0, sts[0]->is_ism_format ) == 0 ? INT_FS_16k : max( INT_FS_16k, sts[0]->sr_core ); /* iDFT at input sampling rate */ #ifdef IVAS_FLOAT_FIXED diff --git a/lib_enc/ivas_spar_encoder.c b/lib_enc/ivas_spar_encoder.c index 454b2305f..2ad739323 100644 --- a/lib_enc/ivas_spar_encoder.c +++ b/lib_enc/ivas_spar_encoder.c @@ -104,7 +104,11 @@ ivas_error ivas_spar_enc_open( hSpar->spar_reconfig_flag = 0; input_Fs = hEncoderConfig->input_Fs; sba_order_internal = min( st_ivas->sba_analysis_order, IVAS_MAX_SBA_ORDER ); +#ifdef IVAS_FLOAT_FIXED + nchan_inp = ivas_sba_get_nchan_metadata_fx( sba_order_internal, hEncoderConfig->ivas_total_brate ); +#else nchan_inp = ivas_sba_get_nchan_metadata( sba_order_internal, hEncoderConfig->ivas_total_brate ); +#endif // IVAS_FLOAT_FIXED assert( nchan_inp <= hEncoderConfig->nchan_inp ); ivas_total_brate = hEncoderConfig->ivas_total_brate; @@ -1381,7 +1385,7 @@ static ivas_error ivas_spar_enc_process( #ifdef IVAS_FLOAT_FIXED_CONVERSIONS Word16 mixer_q = 31; Word16 prior_mixer_q = 31; - Word32 num_channels = ivas_sba_get_nchan_metadata( sba_order, hEncoderConfig->ivas_total_brate ); + Word32 num_channels = ivas_sba_get_nchan_metadata_fx( sba_order, hEncoderConfig->ivas_total_brate ); for ( i = 0; i < num_channels; i++ ) { for ( j = 0; j < num_channels; j++ ) diff --git a/lib_enc/ivas_spar_md_enc.c b/lib_enc/ivas_spar_md_enc.c index 1bfa16eaf..b2413c928 100644 --- a/lib_enc/ivas_spar_md_enc.c +++ b/lib_enc/ivas_spar_md_enc.c @@ -164,7 +164,11 @@ ivas_error ivas_spar_md_enc_open( return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD encoder" ); } +#ifdef IVAS_FLOAT_FIXED + num_channels = ivas_sba_get_nchan_metadata_fx( sba_order, hEncoderConfig->ivas_total_brate ); +#else num_channels = ivas_sba_get_nchan_metadata( sba_order, hEncoderConfig->ivas_total_brate ); +#endif // IVAS_FLOAT_FIXED if ( ( hMdEnc->spar_md.band_coeffs = (ivas_band_coeffs_t *) malloc( IVAS_MAX_NUM_BANDS * sizeof( ivas_band_coeffs_t ) ) ) == NULL ) { -- GitLab From 0370eaa3a62bf29444a14aeb896f44203cdd3157 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Tue, 29 Oct 2024 20:42:47 +0530 Subject: [PATCH 059/128] Clang formatting changes --- lib_com/lsf_tools.c | 10 ++++----- lib_com/lsf_tools_fx.c | 46 +++++++++++++++++++++--------------------- lib_com/modif_fs.c | 2 +- lib_com/modif_fs_fx.c | 2 +- 4 files changed, 30 insertions(+), 30 deletions(-) diff --git a/lib_com/lsf_tools.c b/lib_com/lsf_tools.c index d051a54c7..b2be1b043 100644 --- a/lib_com/lsf_tools.c +++ b/lib_com/lsf_tools.c @@ -2119,8 +2119,8 @@ void dec_FDCNG_MSVQ_stage1_fx( /* Word8 column variable Qx storage*/ - cbpW8 = cdk_37bits_ivas_stage1_W8Qx_dct_sections[segm_ind]; /* Word8 storage fixed ptr_init */ - cbpW8 += imult1616( j, cdk1_ivas_cols_per_segment[segm_ind] ); /* adaptive ptr init */ + cbpW8 = cdk_37bits_ivas_stage1_W8Qx_dct_sections[segm_ind]; /* Word8 storage fixed ptr_init */ + cbpW8 += imult1616( j, cdk1_ivas_cols_per_segment[segm_ind] ); /* adaptive ptr init */ dct_col_shift_tab = stage1_dct_col_syn_shift[segm_ind]; FOR( col = 0; col < cdk1_ivas_cols_per_segment[segm_ind]; col++ ) @@ -2151,7 +2151,7 @@ void dec_FDCNG_MSVQ_stage1_fx( FOR( i = 0; i < n; i++ ) { idct_vec_fx[i] = Mpy_32_32( idct_vec_fx[i], 56410112 ); /* norm + 31 - 31 = norm*/ - // fdcng_dct_scaleF[1] -> 0.420288085937500f / 16.0f -> in Q31 -> 56410112 + // fdcng_dct_scaleF[1] -> 0.420288085937500f / 16.0f -> in Q31 -> 56410112 move32(); } /* fdcng_dct_scaleF[1] --> 0.0625-->scale down from search Q4 domain to Q0 , @@ -2360,7 +2360,7 @@ void msvq_dec_fx( { FOR( j = 0; j < n; ++j ) { - uq_ind[start + j] = add( uq_ind[start + j], shl( mult( cb[i][Idx[i] * maxn + j], 20971 ), sub( add( 13, Q_cb ), 15 ) ) ); // Q0 + uq_ind[start + j] = add( uq_ind[start + j], shl( mult( cb[i][Idx[i] * maxn + j], 20971 ), sub( add( 13, Q_cb ), 15 ) ) ); // Q0 // 2 * 1.28 in Q13 -> 20971 move16(); } @@ -2775,7 +2775,7 @@ void dctT2_N_apply_matrix_fx( /* +i(DCT) or +i*maxTrunc(IDCT) */ #define WMC_TOOL_SKIP - pt_A = &( matrix[i * ( mat_step_row + mat_step_col_flag ) ] ); /* ptr indexing */ + pt_A = &( matrix[i * ( mat_step_row + mat_step_col_flag )] ); /* ptr indexing */ PTR_INIT( 1 ); #undef WMC_TOOL_SKIP FOR( j = 0; j < dim_in; j++ ) diff --git a/lib_com/lsf_tools_fx.c b/lib_com/lsf_tools_fx.c index d0dcc289e..d3694637e 100644 --- a/lib_com/lsf_tools_fx.c +++ b/lib_com/lsf_tools_fx.c @@ -2816,28 +2816,28 @@ Word16 qlsf_ARSN_tcvq_Dec_16k_fx( /*=======================================================================*/ void lsf_syn_mem_backup_fx( - Encoder_State *st_fx, /* o: state structure */ - Word16 *btilt_code_fx, /* i: Q15 */ - Word32 *gc_threshold_fx, /* i: Q16 */ - Word16 *clip_var_bck_fx, /* i: Q(2.56), Q14, Q7, Q0, Q14, Q14 */ - Word16 *next_force_sf_bck_fx,/* i: */ - - Word16 *lsp_new, /* o: LSP vector to quantize Q15 */ - Word16 *lsf_new, /* i: quantized LSF vector Q15 */ - Word16 *lsp_mid, /* o: mid-frame LSP vector Q15 */ - Word16 *clip_var, /* i: pitch clipping state var Q(2.56) */ - Word16 *mem_AR, /* i: quantizer memory for AR model 2.56 */ - Word16 *mem_MA, /* i: quantizer memory for MA model 2.56 */ - Word16 *lsp_new_bck, /* i: LSP vector to quantize- backup Q15 */ - Word16 *lsf_new_bck, /* o: quantized LSF vector - backup Q15 */ - Word16 *lsp_mid_bck, /* i: mid-frame LSP vector - backup Q15 */ - Word16 *mCb1, /* o: counter for stationary frame after a transition frame */ - Word32 *Bin_E, /* i: FFT Bin energy 128 *2 sets q_bin */ - Word32 *Bin_E_old, /* i: FFT Bin energy 128 sets q_bin */ - Word16 *mem_syn_bck, /* i: synthesis filter memory q */ - Word16 *mem_w0_bck, /* i: memory of the weighting filter q */ - Word16 *streaklimit, /* i:LSF quantizer Q15 */ - Word16 *pstreaklen /* i:LSF quantizer */ + Encoder_State *st_fx, /* o: state structure */ + Word16 *btilt_code_fx, /* i: Q15 */ + Word32 *gc_threshold_fx, /* i: Q16 */ + Word16 *clip_var_bck_fx, /* i: Q(2.56), Q14, Q7, Q0, Q14, Q14 */ + Word16 *next_force_sf_bck_fx, /* i: */ + + Word16 *lsp_new, /* o: LSP vector to quantize Q15 */ + Word16 *lsf_new, /* i: quantized LSF vector Q15 */ + Word16 *lsp_mid, /* o: mid-frame LSP vector Q15 */ + Word16 *clip_var, /* i: pitch clipping state var Q(2.56) */ + Word16 *mem_AR, /* i: quantizer memory for AR model 2.56 */ + Word16 *mem_MA, /* i: quantizer memory for MA model 2.56 */ + Word16 *lsp_new_bck, /* i: LSP vector to quantize- backup Q15 */ + Word16 *lsf_new_bck, /* o: quantized LSF vector - backup Q15 */ + Word16 *lsp_mid_bck, /* i: mid-frame LSP vector - backup Q15 */ + Word16 *mCb1, /* o: counter for stationary frame after a transition frame */ + Word32 *Bin_E, /* i: FFT Bin energy 128 *2 sets q_bin */ + Word32 *Bin_E_old, /* i: FFT Bin energy 128 sets q_bin */ + Word16 *mem_syn_bck, /* i: synthesis filter memory q */ + Word16 *mem_w0_bck, /* i: memory of the weighting filter q */ + Word16 *streaklimit, /* i:LSF quantizer Q15 */ + Word16 *pstreaklen /* i:LSF quantizer */ ) { Word16 i; @@ -3113,7 +3113,7 @@ void lsf_syn_mem_restore_fx( move16(); move32(); move16(); - hLPDmem->tilt_code = btilt_code_fx; // Q15 + hLPDmem->tilt_code = btilt_code_fx; // Q15 hLPDmem->gc_threshold = gc_threshold_fx; // Q16 move16(); move32(); diff --git a/lib_com/modif_fs.c b/lib_com/modif_fs.c index 42241bce1..5bc57cc4b 100644 --- a/lib_com/modif_fs.c +++ b/lib_com/modif_fs.c @@ -774,7 +774,7 @@ void Decimate_allpass_steep_fx32( move32(); } - temp[ALLPASSSECTIONS_STEEP - 1] = L_add( mem[2 * ALLPASSSECTIONS_STEEP - 1], Mpy_32_16_1( temp[ALLPASSSECTIONS_STEEP - 2], AP2_STEEP_FX[ALLPASSSECTIONS_STEEP - 1] ) ); //Qx + temp[ALLPASSSECTIONS_STEEP - 1] = L_add( mem[2 * ALLPASSSECTIONS_STEEP - 1], Mpy_32_16_1( temp[ALLPASSSECTIONS_STEEP - 2], AP2_STEEP_FX[ALLPASSSECTIONS_STEEP - 1] ) ); // Qx move32(); mem[2 * ALLPASSSECTIONS_STEEP - 1] = L_sub( temp[ALLPASSSECTIONS_STEEP - 2], Mpy_32_16_1( temp[ALLPASSSECTIONS_STEEP - 1], AP2_STEEP_FX[ALLPASSSECTIONS_STEEP - 1] ) ); // Qx diff --git a/lib_com/modif_fs_fx.c b/lib_com/modif_fs_fx.c index 320682c6b..b53bb9d1c 100644 --- a/lib_com/modif_fs_fx.c +++ b/lib_com/modif_fs_fx.c @@ -597,7 +597,7 @@ Word16 modify_Fs_fx( /* o : length of output Q0 */ move16(); } *Q_new_inp = -1; - move16(); + move16(); } } ELSE -- GitLab From a275f8291da0d3dc1602939a803a23b190367b48 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Tue, 29 Oct 2024 20:54:30 +0530 Subject: [PATCH 060/128] Fix for 3GPP issue 967: Decoder crash for OMASA ISM3_2TC at 64kbps FER in ivas_mdct_core_invQ_fx() --- lib_com/ivas_omasa_com.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib_com/ivas_omasa_com.c b/lib_com/ivas_omasa_com.c index 037364420..5821c474c 100644 --- a/lib_com/ivas_omasa_com.c +++ b/lib_com/ivas_omasa_com.c @@ -900,13 +900,13 @@ static Word16 get_bits_ism( res = 0; move16(); } - ELSE IF( LE_32( val, 447750340 /* 5/6 (in Q29)*/ ) && GT_32( val, 358092897 /*4/6 (in Q29)*/ ) ) + ELSE IF( LE_32( val, 447750340 /* 5/6 (in Q29)*/ ) && GT_32( val, 358092870 /*4/6 (in Q29)*/ ) ) { // 5/6 (in Q29) <= val <= 4/6 (in Q29) => res = 1 res = 1; move16(); } - ELSE IF( LE_32( val, 358092897 /*4/6 (in Q29)*/ ) && GT_32( val, 268972326 /*3/6 (in Q29)*/ ) ) + ELSE IF( LE_32( val, 358092870 /*4/6 (in Q29)*/ ) && GT_32( val, 268972326 /*3/6 (in Q29)*/ ) ) { // 4/6 (in Q29) <= val <= 3/6 (in Q29) => res = 2 res = 2; -- GitLab From 6c7b1e3af3c6b79659e4a8d0b6987843f1978397 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Wed, 30 Oct 2024 11:36:47 +0530 Subject: [PATCH 061/128] SBA, MCMASA and OMASA float code cleanup, Q-info updates for lib_com and lib_rend --- lib_com/bitstream.c | 802 ++++++++++---------------- lib_com/bitstream_fx.c | 4 +- lib_com/gs_preech.c | 44 +- lib_com/guided_plc_util_fx.c | 98 ++-- lib_com/hq2_bit_alloc_fx.c | 158 ++--- lib_com/ivas_dirac_com.c | 12 +- lib_com/ivas_fb_mixer.c | 90 +-- lib_com/ivas_prot.h | 49 +- lib_com/ivas_prot_fx.h | 25 +- lib_com/ivas_qmetadata_com.c | 20 - lib_com/ivas_spar_com.c | 12 +- lib_com/ivas_stat_com.h | 4 +- lib_com/ivas_tools.c | 22 - lib_com/ivas_transient_det.c | 39 +- lib_com/prot.h | 15 - lib_com/prot_fx.h | 100 ++-- lib_enc/ivas_corecoder_enc_reconfig.c | 147 ++++- lib_enc/ivas_enc.c | 151 ++--- lib_enc/ivas_init_enc.c | 318 +++++----- lib_enc/ivas_ism_dtx_enc.c | 14 +- lib_enc/ivas_ism_metadata_enc.c | 38 +- lib_enc/ivas_masa_enc.c | 26 +- lib_enc/ivas_mc_paramupmix_enc.c | 4 +- lib_enc/ivas_mcmasa_enc.c | 237 +++++--- lib_enc/ivas_omasa_enc.c | 24 +- lib_enc/ivas_osba_enc.c | 59 -- lib_enc/ivas_sba_enc.c | 99 +--- lib_enc/ivas_sce_enc.c | 50 +- lib_enc/ivas_spar_encoder.c | 166 +----- lib_enc/ivas_spar_md_enc.c | 118 ++-- lib_enc/ivas_stat_enc.h | 4 +- lib_enc/ivas_tcx_core_enc.c | 37 +- lib_enc/lib_enc.c | 588 ++++++++++--------- lib_enc/lib_enc.h | 11 + lib_enc/prot_fx_enc.h | 5 + lib_rend/ivas_td_decorr.c | 4 +- 36 files changed, 1667 insertions(+), 1927 deletions(-) diff --git a/lib_com/bitstream.c b/lib_com/bitstream.c index 584013e2b..3d8a69a3e 100644 --- a/lib_com/bitstream.c +++ b/lib_com/bitstream.c @@ -39,6 +39,7 @@ #include "options.h" #include "cnst.h" #include "prot.h" +#include "prot_fx.h" #include "stat_enc.h" #include "stat_dec.h" #include "rom_com.h" @@ -49,6 +50,7 @@ #include "wmc_auto.h" #ifdef IVAS_FLOAT_FIXED #include "ivas_prot_fx.h" +#include "prot_fx_enc.h" #endif @@ -422,277 +424,6 @@ ivas_error ind_list_realloc( *-----------------------------------------------------------------------*/ /*! r: maximum number of indices */ -int16_t get_ivas_max_num_indices( - const IVAS_FORMAT ivas_format, /* i : IVAS format */ - const int32_t ivas_total_brate /* i : IVAS total bitrate */ -) -{ - if ( ivas_format == STEREO_FORMAT ) - { - if ( ivas_total_brate <= IVAS_16k4 ) - { - return 300; - } - else if ( ivas_total_brate <= IVAS_24k4 ) - { - return 400; - } - else if ( ivas_total_brate <= IVAS_32k ) - { - return 450; - } - else if ( ivas_total_brate <= IVAS_48k ) - { - return 650; - } - else if ( ivas_total_brate <= IVAS_80k ) - { - return 750; - } - else if ( ivas_total_brate <= IVAS_128k ) - { - return 850; - } - else if ( ivas_total_brate <= IVAS_192k ) - { - return 950; - } - else if ( ivas_total_brate <= IVAS_256k ) - { - return 1350; - } - else - { - return 1650; - } - } - else if ( ivas_format == ISM_FORMAT || ivas_format == MONO_FORMAT ) - { - if ( ivas_total_brate <= IVAS_16k4 ) - { - return 250; - } - else if ( ivas_total_brate <= IVAS_24k4 ) - { - return 350; - } - else if ( ivas_total_brate <= IVAS_32k ) - { - return 450; - } - else if ( ivas_total_brate <= IVAS_48k ) - { - return 550; - } - else if ( ivas_total_brate <= IVAS_64k ) - { - return 620; - } - else if ( ivas_total_brate <= IVAS_80k ) - { - return 670; - } - else if ( ivas_total_brate <= IVAS_96k ) - { - return 780; - } - else if ( ivas_total_brate <= IVAS_128k ) - { - return 880; - } - else if ( ivas_total_brate <= IVAS_192k ) - { - return 950; - } - else if ( ivas_total_brate <= IVAS_256k ) - { - return 1100; - } - else if ( ivas_total_brate <= IVAS_384k ) - { - return 1300; - } - else - { - return 1650; - } - } - else if ( ivas_format == SBA_FORMAT || ivas_format == SBA_ISM_FORMAT ) - { - if ( ivas_total_brate <= IVAS_16k4 ) - { - return 250; - } - else if ( ivas_total_brate <= IVAS_24k4 ) - { - return 350; - } - else if ( ivas_total_brate <= IVAS_32k ) - { - return 400; - } - else if ( ivas_total_brate <= IVAS_48k ) - { - return 650; - } - else if ( ivas_total_brate <= IVAS_80k ) - { - return 750; - } - else if ( ivas_total_brate <= IVAS_128k ) - { - return 1020; - } - else if ( ivas_total_brate <= IVAS_160k ) - { - return 1160; - } - else if ( ivas_total_brate <= IVAS_192k ) - { - return 1220; - } - else if ( ivas_total_brate <= IVAS_256k ) - { - return 1300; - } - else if ( ivas_total_brate <= IVAS_384k ) - { - return 1720; - } - else - { - return 2000; - } - } - else if ( ivas_format == MASA_FORMAT ) - { - if ( ivas_total_brate <= IVAS_16k4 ) - { - return 300; - } - else if ( ivas_total_brate <= IVAS_32k ) - { - return 400; - } - else if ( ivas_total_brate <= IVAS_48k ) - { - return 650; - } - else if ( ivas_total_brate <= IVAS_80k ) - { - return 750; - } - else if ( ivas_total_brate <= IVAS_160k ) - { - return 850; - } - else if ( ivas_total_brate <= IVAS_192k ) - { - return 950; - } - else if ( ivas_total_brate <= IVAS_256k ) - { - return 1150; - } - else if ( ivas_total_brate <= IVAS_384k ) - { - return 1450; - } - else - { - return 1650; - } - } - else if ( ivas_format == MASA_ISM_FORMAT ) - { - if ( ivas_total_brate <= IVAS_16k4 ) - { - return 300; - } - else if ( ivas_total_brate <= IVAS_32k ) - { - return 400; - } - else if ( ivas_total_brate <= IVAS_48k ) - { - return 650; - } - else if ( ivas_total_brate <= IVAS_80k ) - { - return 750; - } - else if ( ivas_total_brate <= IVAS_160k ) - { - return 1150; - } - else if ( ivas_total_brate <= IVAS_192k ) - { - return 1250; - } - else if ( ivas_total_brate <= IVAS_256k ) - { - return 1400; - } - else if ( ivas_total_brate <= IVAS_384k ) - { - return 1650; - } - else - { - return 1850; - } - } - else if ( ivas_format == MC_FORMAT ) - { - if ( ivas_total_brate <= IVAS_16k4 ) - { - return 250; - } - else if ( ivas_total_brate <= IVAS_24k4 ) - { - return 350; - } - else if ( ivas_total_brate <= IVAS_32k ) - { - return 400; - } - else if ( ivas_total_brate <= IVAS_48k ) - { - return 650; - } - else if ( ivas_total_brate <= IVAS_64k ) - { - return 750; - } - else if ( ivas_total_brate <= IVAS_80k ) - { - return 850; - } - else if ( ivas_total_brate <= IVAS_128k ) - { - return 1150; - } - else if ( ivas_total_brate <= IVAS_160k ) - { - return 1420; - } - else if ( ivas_total_brate <= IVAS_256k ) - { - return 2120; - } - else if ( ivas_total_brate <= IVAS_384k ) - { - return 2250; - } - else - { - return 2450; - } - } - - return 2450; -} - Word16 get_ivas_max_num_indices_fx( const IVAS_FORMAT ivas_format, /* i : IVAS format */ const Word32 ivas_total_brate /* i : IVAS total bitrate */ @@ -908,273 +639,93 @@ Word16 get_ivas_max_num_indices_fx( } ELSE IF( LE_32( ivas_total_brate, IVAS_384k ) ) { - return 1650; - } - ELSE - { - return 1850; - } - } - ELSE IF( EQ_16( ivas_format, MC_FORMAT ) ) - { - IF( LE_32( ivas_total_brate, IVAS_16k4 ) ) - { - return 250; - } - ELSE IF( LE_32( ivas_total_brate, IVAS_24k4 ) ) - { - return 350; - } - ELSE IF( LE_32( ivas_total_brate, IVAS_32k ) ) - { - return 400; - } - ELSE IF( LE_32( ivas_total_brate, IVAS_48k ) ) - { - return 650; - } - ELSE IF( LE_32( ivas_total_brate, IVAS_64k ) ) - { - return 750; - } - ELSE IF( LE_32( ivas_total_brate, IVAS_80k ) ) - { - return 850; - } - ELSE IF( LE_32( ivas_total_brate, IVAS_128k ) ) - { - return 1150; - } - ELSE IF( LE_32( ivas_total_brate, IVAS_160k ) ) - { - return 1420; - } - ELSE IF( LE_32( ivas_total_brate, IVAS_256k ) ) - { - return 2120; - } - ELSE IF( LE_32( ivas_total_brate, IVAS_384k ) ) - { - return 2250; - } - ELSE - { - return 2450; - } - } - - return 2450; -} -/*-----------------------------------------------------------------------* - * get_BWE_max_num_indices() - * - * Get the maximum number of indices in the BWE - *-----------------------------------------------------------------------*/ - -/*! r: maximum number of indices */ -int16_t get_BWE_max_num_indices( - const int32_t extl_brate /* i : extensiona layer bitrate */ -) -{ - /* set the maximum number of indices in the BWE */ - if ( extl_brate < SWB_BWE_16k ) - { - return 30; - } - else - { - return 150; - } -} - - -/*-----------------------------------------------------------------------* - * get_ivas_max_num_indices_metadata() - * - * Set the maximum allowed number of metadata indices in the list - *-----------------------------------------------------------------------*/ - -/*! r: maximum number of indices */ -int16_t get_ivas_max_num_indices_metadata( - const IVAS_FORMAT ivas_format, /* i : IVAS format */ - const int32_t ivas_total_brate /* i : IVAS total bitrate */ -) -{ - /* set the maximum required number of metadata indices */ - if ( ivas_format == MONO_FORMAT ) - { - return 0; - } - else if ( ivas_format == STEREO_FORMAT ) - { - if ( ivas_total_brate <= IVAS_16k4 ) - { - return 60; - } - else - { - return 80; - } - } - else if ( ivas_format == ISM_FORMAT ) - { - if ( ivas_total_brate <= IVAS_16k4 ) - { - return 20; - } - else if ( ivas_total_brate <= IVAS_32k ) - { - return 65; - } - else - { - return 80; - } - } - else if ( ivas_format == SBA_FORMAT || ivas_format == SBA_ISM_FORMAT ) - { - if ( ivas_total_brate <= IVAS_16k4 ) - { - return 100; - } - else if ( ivas_total_brate <= IVAS_24k4 ) - { - return 200; - } - else if ( ivas_total_brate <= IVAS_32k ) - { - return 300; - } - else if ( ivas_total_brate <= IVAS_192k ) - { - return 500; - } - else if ( ivas_total_brate <= IVAS_256k ) - { - return 1050; - } - else if ( ivas_total_brate <= IVAS_384k ) - { - return 2000; - } - else - { - return 2500; - } - } - else if ( ivas_format == MASA_FORMAT ) - { - if ( ivas_total_brate <= IVAS_16k4 ) - { - return 80; - } - else if ( ivas_total_brate <= IVAS_32k ) - { - return 125; - } - else if ( ivas_total_brate <= IVAS_48k ) - { - return 205; - } - else if ( ivas_total_brate <= IVAS_96k ) - { - return 240; - } - else if ( ivas_total_brate <= IVAS_128k ) - { - return 305; - } - else if ( ivas_total_brate <= IVAS_160k ) - { - return 425; - } - else if ( ivas_total_brate <= IVAS_192k ) - { - return 630; - } - else if ( ivas_total_brate <= IVAS_256k ) - { - return 850; - } - else if ( ivas_total_brate <= IVAS_384k ) - { - return 1000; - } - else - { - return 1750; - } - } - else if ( ivas_format == MASA_ISM_FORMAT ) - { - if ( ivas_total_brate <= IVAS_16k4 ) - { - return 80; - } - else if ( ivas_total_brate <= IVAS_32k ) - { - return 125 + 100; - } - else if ( ivas_total_brate <= IVAS_48k ) - { - return 205 + 100; + return 1650; } - else if ( ivas_total_brate <= IVAS_96k ) + ELSE { - return 240 + 150; + return 1850; } - else if ( ivas_total_brate <= IVAS_128k ) + } + ELSE IF( EQ_16( ivas_format, MC_FORMAT ) ) + { + IF( LE_32( ivas_total_brate, IVAS_16k4 ) ) { - return 305 + 30; + return 250; } - else if ( ivas_total_brate <= IVAS_160k ) + ELSE IF( LE_32( ivas_total_brate, IVAS_24k4 ) ) { - return 425 + 30; + return 350; } - else if ( ivas_total_brate <= IVAS_192k ) + ELSE IF( LE_32( ivas_total_brate, IVAS_32k ) ) { - return 630 + 30; + return 400; } - else if ( ivas_total_brate <= IVAS_256k ) + ELSE IF( LE_32( ivas_total_brate, IVAS_48k ) ) { - return 850 + 30; + return 650; } - else if ( ivas_total_brate <= IVAS_384k ) + ELSE IF( LE_32( ivas_total_brate, IVAS_64k ) ) { - return 1000 + 30; + return 750; } - else + ELSE IF( LE_32( ivas_total_brate, IVAS_80k ) ) { - return 1750 + 30; + return 850; } - } - else if ( ivas_format == MC_FORMAT ) - { - if ( ivas_total_brate <= IVAS_13k2 ) + ELSE IF( LE_32( ivas_total_brate, IVAS_128k ) ) { - return 80; + return 1150; } - else if ( ivas_total_brate <= IVAS_24k4 ) + ELSE IF( LE_32( ivas_total_brate, IVAS_160k ) ) { - return 100; + return 1420; } - else if ( ivas_total_brate <= IVAS_64k ) + ELSE IF( LE_32( ivas_total_brate, IVAS_256k ) ) { - return 210; + return 2120; } - else if ( ivas_total_brate <= IVAS_96k ) + ELSE IF( LE_32( ivas_total_brate, IVAS_384k ) ) { - return 220; + return 2250; } - else + ELSE { - return 300; + return 2450; } } - return 50; + return 2450; +} +/*-----------------------------------------------------------------------* + * get_BWE_max_num_indices() + * + * Get the maximum number of indices in the BWE + *-----------------------------------------------------------------------*/ + +/*! r: maximum number of indices */ +int16_t get_BWE_max_num_indices( + const int32_t extl_brate /* i : extensiona layer bitrate */ +) +{ + /* set the maximum number of indices in the BWE */ + if ( extl_brate < SWB_BWE_16k ) + { + return 30; + } + else + { + return 150; + } } + +/*-----------------------------------------------------------------------* + * get_ivas_max_num_indices_metadata() + * + * Set the maximum allowed number of metadata indices in the list + *-----------------------------------------------------------------------*/ + +/*! r: maximum number of indices */ Word16 get_ivas_max_num_indices_metadata_fx( const IVAS_FORMAT ivas_format, /* i : IVAS format */ const Word32 ivas_total_brate /* i : IVAS total bitrate */ @@ -2244,7 +1795,52 @@ void reset_indices_dec( * * writing forward or backward to a serial stream *-------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +static Word16 write_indices_to_stream_fx( + Indice *ind_list, + UWord16 **pt_stream, + const Word16 inc, + const Word16 num_indices ) +{ + Word16 i, k; + Word16 value, nb_bits; + UWord16 mask; + + FOR( i = 0; i < num_indices; i++ ) + { + value = ind_list[i].value; + nb_bits = ind_list[i].nb_bits; + move16(); + move16(); + + IF( nb_bits > 0 ) + { + /* mask from MSB to LSB */ + mask = (UWord16) L_shl( 1, sub( nb_bits, 1 ) ); + + /* write bit by bit */ + FOR( k = 0; k < nb_bits; k++ ) + { + IF( L_and( value, mask ) ) + { + **pt_stream = 1; + move16(); + *pt_stream += inc; + } + ELSE + { + **pt_stream = 0; + move16(); + *pt_stream += inc; + } + mask = (UWord16) L_shr( mask, 1 ); + } + } + } + return 0; +} +#else static int16_t write_indices_to_stream( Indice *ind_list, uint16_t **pt_stream, @@ -2285,13 +1881,158 @@ static int16_t write_indices_to_stream( } return 0; } +#endif /*-------------------------------------------------------------------* * write_indices_element() * * Bitstream writing function of one element (one SCE or one CPE) *-------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +static ivas_error write_indices_element_fx( + Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ + UWord16 **pt_stream, /* i : pointer to bitstream buffer */ + const Word16 is_SCE, /* i : flag to distingusih SCE and CPE */ + const Word16 element_id /* i : id of the SCE or CPE */ +) +{ + Word16 ch; + Encoder_State **sts = NULL; + UWord16 *pt_stream_loc; + UWord16 *pt_stream_backup; + UWord16 *pt_stream_end; + Word16 nb_bits_tot_metadata; + Word16 nb_ind_tot_metadata; + + Indice *ind_list_metadata; + Word16 n, n_channels; + ivas_error error; + + error = IVAS_ERR_OK; + move32(); + + ind_list_metadata = NULL; + nb_ind_tot_metadata = 0; + move16(); + + IF( EQ_32( st_ivas->hEncoderConfig->ivas_format, MONO_FORMAT ) ) + { + sts = st_ivas->hSCE[0]->hCoreCoder; + nb_bits_tot_metadata = 0; + move16(); + } + ELSE + { + nb_bits_tot_metadata = 0; + move16(); + test(); + test(); + IF( is_SCE && st_ivas->hSCE[element_id] != NULL ) + { + sts = st_ivas->hSCE[element_id]->hCoreCoder; + + IF( st_ivas->hSCE[element_id]->hMetaData != NULL ) + { + nb_bits_tot_metadata = st_ivas->hSCE[element_id]->hMetaData->nb_bits_tot; + ind_list_metadata = st_ivas->hSCE[element_id]->hMetaData->ind_list; + nb_ind_tot_metadata = st_ivas->hSCE[element_id]->hMetaData->nb_ind_tot; + move16(); + move16(); + } + } + ELSE IF( !is_SCE && st_ivas->hCPE[element_id] != NULL ) + { + sts = st_ivas->hCPE[element_id]->hCoreCoder; + + IF( st_ivas->hCPE[element_id]->hMetaData != NULL ) + { + nb_bits_tot_metadata = st_ivas->hCPE[element_id]->hMetaData->nb_bits_tot; + ind_list_metadata = st_ivas->hCPE[element_id]->hMetaData->ind_list; + nb_ind_tot_metadata = st_ivas->hCPE[element_id]->hMetaData->nb_ind_tot; + move16(); + move16(); + } + } + } + + n_channels = 1; + move16(); + if ( GT_16( sts[0]->element_mode, IVAS_CPE_DFT ) ) + { + n_channels = CPE_CHANNELS; + move16(); + } + + /*----------------------------------------------------------------* + * Bitstream packing (conversion of individual indices into a serial stream) + *----------------------------------------------------------------*/ + + pt_stream_loc = *pt_stream; + pt_stream_end = pt_stream_loc; + + FOR( n = 0; n < n_channels; n++ ) + { + /* write the metadata buffer */ + test(); + IF( n == 0 && nb_bits_tot_metadata != 0 ) + { + pt_stream_backup = pt_stream_loc; + + FOR( ch = 0; ch < n_channels; ch++ ) + { + pt_stream_loc += sts[ch]->hBstr->nb_bits_tot; + } + pt_stream_loc += nb_bits_tot_metadata - 1; + pt_stream_end = pt_stream_loc + 1; + + write_indices_to_stream_fx( ind_list_metadata, &pt_stream_loc, -1, + nb_ind_tot_metadata ); + + /* restore previous pointer position */ + pt_stream_loc = pt_stream_backup; + } + write_indices_to_stream_fx( sts[n]->hBstr->ind_list, &pt_stream_loc, 1, + sts[n]->hBstr->nb_ind_tot ); + + if ( pt_stream_loc > pt_stream_end ) + { + pt_stream_end = pt_stream_loc; + } + } + + /*----------------------------------------------------------------* + * Clearing of indices + * Reset index pointers + *----------------------------------------------------------------*/ + + IF( is_SCE ) /* EVS and SCE */ + { + IF( st_ivas->hSCE[element_id]->hMetaData != NULL ) + { + reset_indices_enc( st_ivas->hSCE[element_id]->hMetaData, st_ivas->hSCE[element_id]->hMetaData->nb_ind_tot ); + } + + reset_indices_enc( sts[0]->hBstr, sts[0]->hBstr->nb_ind_tot ); + } + ELSE + { + IF( st_ivas->hCPE[element_id]->hMetaData != NULL ) + { + reset_indices_enc( st_ivas->hCPE[element_id]->hMetaData, st_ivas->hCPE[element_id]->hMetaData->nb_ind_tot ); + } + + FOR( n = 0; n < n_channels; n++ ) + { + reset_indices_enc( sts[n]->hBstr, sts[n]->hBstr->nb_ind_tot ); + } + } + /* update pointer */ + *pt_stream = pt_stream_end; + + return error; +} +#else static ivas_error write_indices_element( Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ uint16_t **pt_stream, /* i : pointer to bitstream buffer */ @@ -2422,6 +2163,7 @@ static ivas_error write_indices_element( return error; } +#endif /*-------------------------------------------------------------------* * write_indices_ivas() @@ -2429,7 +2171,48 @@ static ivas_error write_indices_element( * Write the buffer of indices to a serial bitstream buffer, * each bit represented as a uint16_t of value 0 or 1 *-------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +ivas_error write_indices_ivas_fx( + Encoder_Struct *st_ivas, /* i/o: encoder state structure */ + UWord16 *bit_stream, /* i/o: output bitstream */ + UWord16 *num_bits /* i : number of indices written to output */ +) +{ + Word16 i, n; + UWord16 *pt_stream; + ivas_error error; + + error = IVAS_ERR_OK; + move32(); + + pt_stream = bit_stream; + FOR( i = 0; i < MAX_BITS_PER_FRAME; ++i ) + { + bit_stream[i] = 0; + move16(); + } + + + /*-----------------------------------------------------------------* + * Encode Payload + *-----------------------------------------------------------------*/ + + FOR( n = 0; n < st_ivas->nSCE; n++ ) + { + write_indices_element_fx( st_ivas, &pt_stream, 1, n ); + } + + FOR( n = 0; n < st_ivas->nCPE; n++ ) + { + write_indices_element_fx( st_ivas, &pt_stream, 0, n ); + } + + *num_bits = (UWord16) ( pt_stream - bit_stream ); + move16(); + return error; +} +#else ivas_error write_indices_ivas( Encoder_Struct *st_ivas, /* i/o: encoder state structure */ uint16_t *bit_stream, /* i/o: output bitstream */ @@ -2467,6 +2250,7 @@ ivas_error write_indices_ivas( return error; } +#endif #ifndef IVAS_FLOAT_FIXED /*---------------------------------------------------------------------* diff --git a/lib_com/bitstream_fx.c b/lib_com/bitstream_fx.c index 7d7fa3fdd..753bc19cf 100644 --- a/lib_com/bitstream_fx.c +++ b/lib_com/bitstream_fx.c @@ -1088,7 +1088,7 @@ static void decoder_selectCodec( } -void dec_prm_core( Decoder_State *st ) +static void dec_prm_core( Decoder_State *st ) { Word16 n, frame_size_index, num_bits; UWord16 lsb; @@ -1178,7 +1178,7 @@ void dec_prm_core( Decoder_State *st ) * Set st->core, and st->bwidth if signalled together with the core. *-----------------------------------------------------------------*/ -void decision_matrix_core_dec( +static void decision_matrix_core_dec( Decoder_State *st /* i/o: decoder state structure */ ) { diff --git a/lib_com/gs_preech.c b/lib_com/gs_preech.c index 3d1b6f550..1fc23300e 100644 --- a/lib_com/gs_preech.c +++ b/lib_com/gs_preech.c @@ -144,10 +144,10 @@ void pre_echo_att( void pre_echo_att_fx( Word32 *Last_frame_ener_fx, /* i/o: Energy of the last frame 2*Q_new+1*/ Word16 *exc_fx, /* i/o: Excitation of the current frame Q_new*/ - const Word16 gsc_attack_flag_fx, /* i : flag signalling attack encoded by AC mode (GSC) */ + const Word16 gsc_attack_flag_fx, /* i : flag signalling attack encoded by AC mode (GSC) Q0*/ const Word16 Q_new, - const Word16 last_coder_type, /* i : Last coding mode */ - const Word16 L_frame /* i : Frame length*/ + const Word16 last_coder_type, /* i : Last coding mode Q0*/ + const Word16 L_frame /* i : Frame length Q0*/ ) { Word32 etmp_fx; @@ -168,18 +168,18 @@ void pre_echo_att_fx( * The inverse weighting aims to favor the first maxima in case of * gradual onset *-------------------------------------------------------------------------*/ - att_len = ATT_LENGHT; + att_len = ATT_LENGHT; /* Q0 */ move16(); if ( EQ_16( L_frame, L_FRAME16k ) ) { - att_len = ATT_LENGHT16k; + att_len = ATT_LENGHT16k; /* Q0 */ move16(); } FOR( i = 0; i < att_len; i++ ) { - L_tmp = sum2_fx( &exc_fx[shl( i, 2 )], ATT_SEG_LEN ); /*2*Q_new+1, //ATT_SEG_LEN=(L_FRAME/ATT_LENGHT)=4(=shl(x,2))*/ - tmp = div_s( sub( att_len, i ), att_len ); /*Q15 */ - L_tmp = Mult_32_16( L_tmp, tmp ); /*2*Q_new+1 */ + L_tmp = sum2_fx( &exc_fx[i * 4], ATT_SEG_LEN ); /*2*Q_new+1, //ATT_SEG_LEN=(L_FRAME/ATT_LENGHT)=4(=shl(x,2))*/ + tmp = div_s( sub( att_len, i ), att_len ); /*Q15 */ + L_tmp = Mult_32_16( L_tmp, tmp ); /*2*Q_new+1 */ finc_fx[i] = L_tmp; move32(); /*2*Q_new+1 */ } @@ -231,10 +231,10 @@ void pre_echo_att_fx( L_tmp = L_shr( L_tmp, exp ); /* add exponent */ L_tmp = Isqrt( L_tmp ); - ratio_fx = round_fx( L_shl( L_tmp, 9 ) ); + ratio_fx = round_fx( L_shl( L_tmp, 9 ) ); /* Q13 */ /* Pre-echo atttenuation should never increase the energy */ - ratio_fx = s_min( ratio_fx, 8192 ); + ratio_fx = s_min( ratio_fx, 8192 /* 1 in Q13 */ ); /* Q13 */ FOR( i = 0; i < attack_pos_fx * ATT_SEG_LEN; i++ ) { /*exc_fx[i] *= ratio_fx;*/ @@ -242,7 +242,7 @@ void pre_echo_att_fx( move16(); } } - *Last_frame_ener_fx = etmp1_fx; + *Last_frame_ener_fx = etmp1_fx; /*2*Q_new+1*/ move32(); } ELSE @@ -270,10 +270,10 @@ void pre_echo_att_fx( void pre_echo_att_ivas_fx( Word32 *Last_frame_ener_fx, /* i/o: Energy of the last frame 2*Q_new+1*/ Word16 *exc_fx, /* i/o: Excitation of the current frame Q_new*/ - const Word16 gsc_attack_flag_fx, /* i : flag signalling attack encoded by AC mode (GSC) */ + const Word16 gsc_attack_flag_fx, /* i : flag signalling attack encoded by AC mode (GSC) Q0*/ const Word16 Q_new, - const Word16 last_coder_type, /* i : Last coding mode */ - const Word16 L_frame /* i : Frame length*/ + const Word16 last_coder_type, /* i : Last coding mode Q0*/ + const Word16 L_frame /* i : Frame length Q0*/ ) { Word32 etmp_fx; @@ -294,18 +294,18 @@ void pre_echo_att_ivas_fx( * The inverse weighting aims to favor the first maxima in case of * gradual onset *-------------------------------------------------------------------------*/ - att_len = ATT_LENGHT; + att_len = ATT_LENGHT; /* Q0 */ move16(); if ( EQ_16( L_frame, L_FRAME16k ) ) { - att_len = ATT_LENGHT16k; + att_len = ATT_LENGHT16k; /* Q0 */ move16(); } FOR( i = 0; i < att_len; i++ ) { - L_tmp = sum2_fx( &exc_fx[shl( i, 2 )], ATT_SEG_LEN ); /*2*Q_new+1, //ATT_SEG_LEN=(L_FRAME/ATT_LENGHT)=4(=shl(x,2))*/ - tmp = div_s( sub( att_len, i ), att_len ); /*Q15 */ - L_tmp = Mult_32_16( L_tmp, tmp ); /*2*Q_new+1 */ + L_tmp = sum2_fx( &exc_fx[i * 4], ATT_SEG_LEN ); /*2*Q_new+1, //ATT_SEG_LEN=(L_FRAME/ATT_LENGHT)=4(=shl(x,2))*/ + tmp = div_s( sub( att_len, i ), att_len ); /*Q15 */ + L_tmp = Mult_32_16( L_tmp, tmp ); /*2*Q_new+1 */ finc_fx[i] = L_tmp; move32(); /*2*Q_new+1 */ } @@ -360,7 +360,7 @@ void pre_echo_att_ivas_fx( ratio_fx = round_fx( L_shl( L_tmp, 9 ) ); /* Pre-echo atttenuation should never increase the energy */ - ratio_fx = s_min( ratio_fx, 8192 ); + ratio_fx = s_min( ratio_fx, 8192 /* 1 in Q13 */ ); /* Q13 */ FOR( i = 0; i < attack_pos_fx * ATT_SEG_LEN; i++ ) { /*exc_fx[i] *= ratio_fx;*/ @@ -368,7 +368,7 @@ void pre_echo_att_ivas_fx( move16(); } } - *Last_frame_ener_fx = etmp1_fx; + *Last_frame_ener_fx = etmp1_fx; /* 2 * Q_new + 1 */ move32(); } ELSE @@ -383,7 +383,7 @@ void pre_echo_att_ivas_fx( if ( EQ_16( L_frame, L_FRAME16k ) ) { - etmp_fx = Mpy_32_16_1( etmp_fx, 26214 ); + etmp_fx = Mpy_32_16_1( etmp_fx, 26214 /* 0.8 in Q15 */ ); /*2*Q_new+1*/ } *Last_frame_ener_fx = etmp_fx; move32(); /*2*Q_new+1*/ diff --git a/lib_com/guided_plc_util_fx.c b/lib_com/guided_plc_util_fx.c index b7eba5d7e..f556fff05 100644 --- a/lib_com/guided_plc_util_fx.c +++ b/lib_com/guided_plc_util_fx.c @@ -22,11 +22,12 @@ static void reorder_lsfs( Word16 *lsf, const Word16 min_dist, const Word16 n, co * *-------------------------------------------------------------------*/ void getLookAheadResSig( - Word16 *speechLookAhead, - Word16 *A_3Q12, - Word16 *res, - const Word16 L_frame, - const Word16 numSubFrame ) + Word16 *speechLookAhead, /* Qx */ + Word16 *A_3Q12, /* 3Q12 */ + Word16 *res, /* Qx */ + const Word16 L_frame, /* Q0 */ + const Word16 numSubFrame /* Q0 */ +) { Word16 *p_A; Word16 i_subfr; @@ -40,12 +41,12 @@ void getLookAheadResSig( move16(); /* 0.75 * L_SUBFR(64) */ } - p_A = A_3Q12; + p_A = A_3Q12; /* Q12 */ FOR( i_subfr = 0; i_subfr < numSubFrame * L_SUBFR; i_subfr += L_SUBFR ) { /* calculate residual signal */ Residu3_fx( p_A, &speechLookAhead[i_subfr], &res[i_subfr], - subfr_len[shr( i_subfr, 6 )], 0 ); + subfr_len[i_subfr / 64], 0 ); /* pointer initialization */ p_A += ( M + 1 ); @@ -62,21 +63,22 @@ void getLookAheadResSig( void updateLSFForConcealment( PLC_ENC_EVS_HANDLE decState, - Word16 *lsf_14Q1 ) + Word16 *lsf_14Q1 /* 14Q1 */ +) { Word16 i; Word32 L_tmp = 0; - const Word16 divide_by_3_Q15 = 10923; + const Word16 divide_by_3_Q15 = 10923; /* 1/3 in Q15 */ FOR( i = 0; i < M; i++ ) { - L_tmp = L_mult( divide_by_3_Q15, decState->lsfoldbfi1_14Q1[i] ); - L_tmp = L_mac( L_tmp, divide_by_3_Q15, decState->lsfoldbfi0_14Q1[i] ); - decState->lsf_adaptive_mean_14Q1[i] = mac_r( L_tmp, divide_by_3_Q15, lsf_14Q1[i] ); + L_tmp = L_mult( divide_by_3_Q15, decState->lsfoldbfi1_14Q1[i] ); /* Q17 */ + L_tmp = L_mac( L_tmp, divide_by_3_Q15, decState->lsfoldbfi0_14Q1[i] ); /* Q17 */ + decState->lsf_adaptive_mean_14Q1[i] = mac_r( L_tmp, divide_by_3_Q15, lsf_14Q1[i] ); /* 14Q1 */ move16(); - decState->lsfoldbfi1_14Q1[i] = decState->lsfoldbfi0_14Q1[i]; + decState->lsfoldbfi1_14Q1[i] = decState->lsfoldbfi0_14Q1[i]; /* 14Q1 */ move16(); - decState->lsfoldbfi0_14Q1[i] = lsf_14Q1[i]; + decState->lsfoldbfi0_14Q1[i] = lsf_14Q1[i]; /* 14Q1 */ move16(); } @@ -90,10 +92,11 @@ void updateLSFForConcealment( void getConcealedLP( PLC_ENC_EVS_HANDLE memDecState, - Word16 *AqCon, - const Word16 lsfBase[], - const Word16 last_good, - const Word16 L_frame ) + Word16 *AqCon, /* 14Q1 */ + const Word16 lsfBase[], /* Q1 * 1.28 */ + const Word16 last_good, /* Q0 */ + const Word16 L_frame /* Q0 */ +) { Word16 *lsf; Word16 lsp[( NB_DIV + 1 ) * M]; @@ -106,7 +109,7 @@ void getConcealedLP( 1, memDecState->mem_MA_14Q1, memDecState->mem_AR, &( memDecState->stab_fac_Q15 ), memDecState->lsf_adaptive_mean_14Q1, 1, NULL, 0, NULL, NULL, lsfBase, 0 ); - Copy( memDecState->lspold_Q15, lsp, M ); + Copy( memDecState->lspold_Q15, lsp, M ); /* Q15 */ int_fs = INT_FS_FX; move32(); @@ -128,9 +131,10 @@ void getConcealedLP( *-------------------------------------------------------------------*/ void getConcealedLSF( PLC_ENC_EVS_HANDLE memDecState, - const Word16 lsfBase[], - const Word16 last_good, - const Word16 L_frame ) + const Word16 lsfBase[], /* Q1 * 1.28 */ + const Word16 last_good, /* Q0 */ + const Word16 L_frame /* Q0 */ +) { Word16 *lsf = memDecState->lsf_con; @@ -149,11 +153,12 @@ void getConcealedLSF( *-------------------------------------------------------------------*/ void RecLpcSpecPowDiffuseLc( - Word16 *lspq, - Word16 *lsp_old, - Word16 *lsfq, + Word16 *lspq, /* Q15 */ + Word16 *lsp_old, /* Q15 */ + Word16 *lsfq, /* Q2.56 */ Decoder_State *st, - const Word16 reset_q ) + const Word16 reset_q /* Q0 */ +) { const Word16 *means; Word16 lsf_old[M]; @@ -163,7 +168,7 @@ void RecLpcSpecPowDiffuseLc( st->narrowBand, st->sr_core ); - Copy( st->lsf_old_fx, lsf_old, M ); + Copy( st->lsf_old_fx, lsf_old, M ); /* Q2.56 */ modify_lsf( lsf_old, M, st->sr_core, reset_q ); @@ -173,7 +178,7 @@ void RecLpcSpecPowDiffuseLc( { FOR( i = 0; i < M; i++ ) { - lsfq[i] = add( st->mem_MA_fx[i], means[i] ); + lsfq[i] = add( st->mem_MA_fx[i], means[i] ); /* Q2.56 */ move16(); } sort_fx( lsfq, 0, sub( M, 1 ) ); @@ -195,10 +200,11 @@ void RecLpcSpecPowDiffuseLc( * *-------------------------------------------------------------------*/ void modify_lsf( - Word16 *lsf, - const Word16 n, - const Word32 sr_core, - const Word16 reset_q ) + Word16 *lsf, /* Q14 */ + const Word16 n, /* Q0 */ + const Word32 sr_core, /* Q0 */ + const Word16 reset_q /* Q0 */ +) { Word16 i, k, th_x1p28_Q14; Word16 gap, gap_sum; @@ -231,25 +237,25 @@ void modify_lsf( } } - gap = mult_r( lsf[i - 1], InvIntTable[i] ); + gap = mult_r( lsf[i - 1], InvIntTable[i] ); /* Q14 */ move16(); gap_sum = gap; - i = sub( i, 1 ); + i--; FOR( k = 0; k < i; k++ ) { move16(); - lsf[k] = gap_sum; + lsf[k] = gap_sum; /* Q14 */ gap_sum = add( gap_sum, gap ); } } static void reorder_lsfs( - Word16 *lsf, /* i/o: vector of lsfs in the frequency domain (0..0.5)*/ - const Word16 min_dist0, /* i : minimum required distance */ - const Word16 n, /* i : LPC order */ - const Word32 sr_core /* i : input sampling frequency */ + Word16 *lsf, /* i/o: vector of lsfs in the frequency domain (0..0.5) 1.28 Q1*/ + const Word16 min_dist0, /* i : minimum required distance 1.28 Q1*/ + const Word16 n, /* i : LPC order Q0*/ + const Word32 sr_core /* i : input sampling frequency Q0*/ ) { Word16 i; @@ -277,17 +283,17 @@ static void reorder_lsfs( *-----------------------------------------------------------------*/ IF( EQ_32( sr_core, INT_FS_16k ) ) { - th1 = 3200; + th1 = 3200; /*1000.0 * 1.25 * 1.28 Q1*/ move16(); - th2 = 6080; + th2 = 6080; /*1900.0 * 1.25 * 1.28 Q1*/ move16(); min_dist = add( min_dist0, shr( min_dist0, 2 ) ); } ELSE { - th1 = 2560; + th1 = 2560; /* 1000.0 * 1.28 Q1 */ move16(); - th2 = 4864; + th2 = 4864; /* 1900.0 * 1.28 Q1 */ move16(); min_dist = min_dist0; move16(); @@ -322,7 +328,7 @@ static void reorder_lsfs( move16(); } - lsf_min = add( lsf[i], curr_min_dist ); + lsf_min = add( lsf[i], curr_min_dist ); /* 1.28 Q1 */ } /*------------------------------------------------------------------------------------------* @@ -333,7 +339,7 @@ static void reorder_lsfs( IF( GT_16( lsf[n - 1], lsf_max ) ) /* If danger of unstable filter in case of resonance in HF */ { - FOR( i = sub( n, 1 ); i >= 0; i-- ) /* Reverify the minimum ISF gap in the reverse direction */ + FOR( i = n - 1; i >= 0; i-- ) /* Reverify the minimum ISF gap in the reverse direction */ { IF( LE_16( lsf[i], th2 ) ) { @@ -354,7 +360,7 @@ static void reorder_lsfs( lsf[i] = lsf_max; move16(); } - lsf_max = sub( lsf[i], curr_min_dist ); + lsf_max = sub( lsf[i], curr_min_dist ); /* 1.28 Q1 */ } } diff --git a/lib_com/hq2_bit_alloc_fx.c b/lib_com/hq2_bit_alloc_fx.c index 486de81de..395854d5f 100644 --- a/lib_com/hq2_bit_alloc_fx.c +++ b/lib_com/hq2_bit_alloc_fx.c @@ -92,14 +92,14 @@ void Bits2indvsb_fx( Word32 L_temp1; Word32 L_temp2; - band_num_fx = sub( end_band, start_band ); - L_y_ptr = L_be + start_band; - L_R_ptr = L_Rsubband + start_band; - p2aflags_fx_ptr = p2aflags_fx + start_band; + band_num_fx = sub( end_band, start_band ); /* Q0 */ + L_y_ptr = L_be + start_band; /* Qbe */ + L_R_ptr = L_Rsubband + start_band; /* QRk */ + p2aflags_fx_ptr = p2aflags_fx + start_band; /* Q0 */ FOR( i = 0; i < band_num_fx; i++ ) { - y_index_fx[i] = extract_h( L_shr( L_y_ptr[i], sub( SWB_BWE_LR_Qbe, 16 ) ) ); + y_index_fx[i] = extract_h( L_shr( L_y_ptr[i], sub( SWB_BWE_LR_Qbe, 16 ) ) ); /* Q16 */ move16(); index_fx[i] = i; move16(); @@ -125,9 +125,9 @@ void Bits2indvsb_fx( } ELSE { - L_R_temp[j] = C1_QRk; - move32(); /* filled not zero value */ - be_cnt_fx = add( be_cnt_fx, 1 ); + L_R_temp[j] = C1_QRk; /* QRk */ + move32(); /* filled not zero value */ + be_cnt_fx = add( be_cnt_fx, 1 ); /* Q0 */ } } @@ -187,7 +187,7 @@ void Bits2indvsb_fx( exp_normn = sub( exp_normn, 1 ); exp_normd = norm_s( Rcnt_fx ); Ravg_fx = div_s( shl( be_sum_fx, exp_normn ), shl( Rcnt_fx, exp_normd ) ); - Ravg_fx = shr( Ravg_fx, 2 ); /* safe shift */ + Ravg_fx = shr( Ravg_fx, 2 ); /* safe shift exp_normn - exp_normd + 13*/ QRavg = add( sub( exp_normn, exp_normd ), 15 - 2 ); if ( be_sum_fx <= 0 ) @@ -207,7 +207,7 @@ void Bits2indvsb_fx( exp_normn = sub( exp_normn, 1 ); exp_normd = norm_s( be_sum_fx ); Bits_avg_fx = div_s( shl( Bits, exp_normn ), shl( be_sum_fx, exp_normd ) ); - Bits_avg_fx = shr( Bits_avg_fx, 2 ); /* safe_shift */ + Bits_avg_fx = shr( Bits_avg_fx, 2 ); /* safe_shift exp_normn - exp_normd + 13*/ QBavg = add( sub( exp_normn, exp_normd ), 15 - 2 ); } FOR( k = 0; k <= i; k++ ) @@ -244,7 +244,7 @@ void Bits2indvsb_fx( { j = index_fx[k]; move16(); - L_R_ptr[j] = L_R_temp[k]; + L_R_ptr[j] = L_R_temp[k]; /* SWB_BWE_LR_QRk */ move32(); } @@ -262,7 +262,7 @@ void hq2_bit_alloc_har_fx( Word16 B_fx, /* i : Q0 number of available bits */ const Word16 N_fx, /* i : Q0 number of sub-vectors */ Word32 *L_Rsubband, /* o : QRk sub-band bit-allocation vector */ - Word16 p2a_bands_fx, /* i : highfreq bands */ + Word16 p2a_bands_fx, /* i : Q0 highfreq bands */ const Word32 L_core_brate, /* i : Q0 core bit rate */ Word16 p2a_flags_fx[], /* i/o: Q0 p2a_flags */ const Word16 band_width_fx[] /* i : Q0 table of band_width */ @@ -280,7 +280,7 @@ void hq2_bit_alloc_har_fx( Word16 G1_BE_DIFF_POS_fx; /* Q0 */ Word32 L_G1_BE_DIFF_VAL; /* Qbe Word32 */ Word16 final_gr_fact_pos_fx, gmax_range_fx[2], temp_fx; - Word16 bits_fact_fx, bits_fact1_fx; /* Q? */ + Word16 bits_fact_fx, bits_fact1_fx; Word16 grp_rngmax_fx[2] = { 0 }; Word16 index_fx[NB_SWB_SUBBANDS_HAR], y_index_fx[NB_SWB_SUBBANDS_HAR], esthf_bits_fx, grp_bit_avg_fx, harmonic_band_fx; Word32 L_norm_sum_avg; @@ -336,9 +336,9 @@ void hq2_bit_alloc_har_fx( } final_gr_fact_pos_fx = 2; move16(); - bits_fact_fx = C1_Qbf; + bits_fact_fx = C1_Qbf; /* Qbf */ move16(); - bits_fact1_fx = C1_Qbf; + bits_fact1_fx = C1_Qbf; /* Qbf */ move16(); gmax_range_fx[0] = G1_RANGE; @@ -378,27 +378,27 @@ void hq2_bit_alloc_har_fx( { FOR( temp_fx = 2; temp_fx <= k_fx; ) { - IF( LT_32( L_temp_band_energy[sub( add( gmax_range_fx[i], temp_fx ), 1 )], L_temp_band_energy[add( gmax_range_fx[i], temp_fx )] ) ) + IF( LT_32( L_temp_band_energy[( gmax_range_fx[i] + temp_fx ) - 1], L_temp_band_energy[gmax_range_fx[i] + temp_fx] ) ) { BREAK; } - ELSE IF( GE_32( L_temp_band_energy[sub( add( gmax_range_fx[i], temp_fx ), 1 )], L_temp_band_energy[add( gmax_range_fx[i], temp_fx )] ) ) + ELSE IF( GE_32( L_temp_band_energy[( gmax_range_fx[i] + temp_fx ) - 1], L_temp_band_energy[( gmax_range_fx[i] + temp_fx )] ) ) { - temp_fx = add( temp_fx, 1 ); + temp_fx++; IF( GT_16( temp_fx, k_fx ) ) { - temp_fx = sub( temp_fx, 1 ); + temp_fx--; /* Q0 */ BREAK; } } } - gmax_range_fx[i] = add( gmax_range_fx[i], temp_fx ); + gmax_range_fx[i] = add( gmax_range_fx[i], temp_fx ); /* Q0 */ move16(); } ELSE { - gmax_range_fx[i] = add( gmax_range_fx[i], temp_fx ); + gmax_range_fx[i] = add( gmax_range_fx[i], temp_fx ); /* Q0 */ move16(); } } @@ -407,12 +407,12 @@ void hq2_bit_alloc_har_fx( move16(); FOR( i = 1; i < GRP_SB - 1; i++ ) { - grp_bound_fx[i] = gmax_range_fx[i - 1]; + grp_bound_fx[i] = gmax_range_fx[i - 1]; /* Q0 */ move16(); } - grp_bound_fx[i] = harmonic_band_fx; + grp_bound_fx[i] = harmonic_band_fx; /* Q0 */ move16(); - grp_bound_fx[add( i, 1 )] = N_fx; + grp_bound_fx[i + 1] = N_fx; /* Q0 */ move16(); @@ -423,7 +423,7 @@ void hq2_bit_alloc_har_fx( { IF( L_temp_band_energy[j] > 0x0L ) { - L_Ravg_sub[i] = L_add( L_Ravg_sub[i], L_temp_band_energy[j] ); + L_Ravg_sub[i] = L_add( L_Ravg_sub[i], L_temp_band_energy[j] ); /* Qbe */ move32(); } } @@ -433,7 +433,7 @@ void hq2_bit_alloc_har_fx( move32(); FOR( j = 1; j < harmonic_band_fx; j++ ) { - L_temp_band_energydiff[j] = L_abs( L_sub( L_temp_band_energy[j], L_temp_band_energy[j - 1] ) ); + L_temp_band_energydiff[j] = L_abs( L_sub( L_temp_band_energy[j], L_temp_band_energy[j - 1] ) ); /* Qbe */ move32(); } @@ -447,7 +447,7 @@ void hq2_bit_alloc_har_fx( { G1_BE_DIFF_POS_fx = j; move16(); - L_G1_BE_DIFF_VAL = L_temp_band_energydiff[j]; + L_G1_BE_DIFF_VAL = L_temp_band_energydiff[j]; /* Qbe */ move32(); } } @@ -506,47 +506,47 @@ void hq2_bit_alloc_har_fx( } } - j = sub( N_fx, harmonic_band_fx ); + j = sub( N_fx, harmonic_band_fx ); /* Q0 */ FOR( i = 0; i < j; i++ ) { - y_index_fx[i] = extract_h( L_shl( L_temp_band_energy[harmonic_band_fx + i], sub( 16, SWB_BWE_LR_Qbe ) ) ); + y_index_fx[i] = extract_h( L_shl( L_temp_band_energy[harmonic_band_fx + i], sub( 16, SWB_BWE_LR_Qbe ) ) ); /* Q0 */ move16(); - index_fx[i] = add( harmonic_band_fx, i ); + index_fx[i] = add( harmonic_band_fx, i ); /* Q0 */ move16(); } reordvct_fx( y_index_fx, sub( N_fx, harmonic_band_fx ), index_fx ); /* Log2 */ - L_temp = L_deposit_l( band_width_fx[index_fx[0]] ); + L_temp = L_deposit_l( band_width_fx[index_fx[0]] ); /* Q0 */ exp = norm_l( L_temp ); frac = Log2_norm_lc( L_shl( L_temp, exp ) ); exp = sub( 30, exp ); - L_temp = L_Comp( exp, frac ); + L_temp = L_Comp( exp, frac ); /* Q16 */ /* ceil */ if ( L_and( 0x0000ffff, L_temp ) > 0 ) { - L_temp = L_add( L_temp, 0x00010000 ); + L_temp = L_add( L_temp, 0x00010000 ); /* Q16 */ } esthf_bits_fx = extract_h( L_temp ); - L_grp_thr[0] = L_THR1; + L_grp_thr[0] = L_THR1; /* SWB_BWE_LR_QRk */ move32(); - L_grp_thr[1] = L_THR2; + L_grp_thr[1] = L_THR2; /* SWB_BWE_LR_QRk */ move32(); - L_grp_thr[2] = L_THR3; + L_grp_thr[2] = L_THR3; /* SWB_BWE_LR_QRk */ move32(); - L_grp_thr[3] = L_shl( L_deposit_l( esthf_bits_fx ), SWB_BWE_LR_QRk ); + L_grp_thr[3] = L_shl( L_deposit_l( esthf_bits_fx ), SWB_BWE_LR_QRk ); /* SWB_BWE_LR_QRk */ move16(); L_norm_sum = L_deposit_l( 1 ); FOR( i = 0; i < 3; i++ ) { - L_norm_sum = L_add( L_norm_sum, L_Ravg_sub[i] ); + L_norm_sum = L_add( L_norm_sum, L_Ravg_sub[i] ); /* Qbe */ } /*reserve bits for HF coding */ - L_temp = L_add( L_norm_sum, L_Ravg_sub[GRP_SB - 1] ); + L_temp = L_add( L_norm_sum, L_Ravg_sub[GRP_SB - 1] ); /* Qbe */ exp_normn = norm_l( L_temp ); exp_normn = sub( exp_normn, 1 ); exp_normd = norm_s( N_fx ); @@ -558,7 +558,7 @@ void hq2_bit_alloc_har_fx( norm_sum_fx = extract_h( L_shl( L_norm_sum, exp_norm ) ); /* SWB_BWE_LR_Qbe+exp_norm-16 */ Qns = sub( add( SWB_BWE_LR_Qbe, exp_norm ), 16 ); - Inv_norm_sum_fx = div_s( 0x4000 /* Q15 */, norm_sum_fx ); + Inv_norm_sum_fx = div_s( 0x4000 /* 0.5 in Q15 */, norm_sum_fx ); QIns = sub( 31, exp_norm ); /* 14 - (14+exp_norm-16) + 15 */ grp_bit_avg_fx = div_s_ss( B_fx, GRP_SB ); /* Q0 */ @@ -567,8 +567,8 @@ void hq2_bit_alloc_har_fx( Inv_p2a_bands_fx = div_s( 0x3fff, shl( p2a_bands_fx, exp_normd ) ); /* 14-exp_normd+15 */ QIpb = sub( 29, exp_normd ); - L_temp = L_shl( Mult_32_16( L_Ravg_sub[GRP_SB - 1], Inv_p2a_bands_fx ), sub( SWB_BWE_LR_Qbe, sub( QIpb, 1 ) ) ); - L_norm_diff = L_sub( L_temp, L_norm_sum_avg ); /* Qbe */ + L_temp = L_shl( Mult_32_16( L_Ravg_sub[GRP_SB - 1], Inv_p2a_bands_fx ), sub( SWB_BWE_LR_Qbe, sub( QIpb, 1 ) ) ); /* Qbe */ + L_norm_diff = L_sub( L_temp, L_norm_sum_avg ); /* Qbe */ L_temp = Mult_32_16( L_Ravg_sub[GRP_SB - 1], sub( GRP_SB, 1 ) ); /* Qbe+0+1 */ L_temp = Mult_32_16( L_temp, Inv_norm_sum_fx ); /* Qbe+1+QIpb+1 */ @@ -604,11 +604,11 @@ void hq2_bit_alloc_har_fx( L_temp2 = Mult_32_16( L_norm_diff, bits_allocweigh_fx ); /* Qbe+Q15-15 */ L_temp = L_shr( L_temp, add( QIpb, 1 ) ); - L_temp = L_add( L_shl( L_temp, SWB_BWE_LR_Qbe ), L_temp2 ); + L_temp = L_add( L_shl( L_temp, SWB_BWE_LR_Qbe ), L_temp2 ); /* Qbe+Q15-15 */ - Bits_grp_fx[GRP_SB - 1] = extract_h( L_shl( L_temp, sub( 16, SWB_BWE_LR_Qbe ) ) ); + Bits_grp_fx[GRP_SB - 1] = extract_h( L_shl( L_temp, sub( 16, SWB_BWE_LR_Qbe ) ) ); /* Q0 */ move16(); - Bits_grp_fx[GRP_SB - 1] = s_min( Bits_grp_fx[GRP_SB - 1], 10 ); + Bits_grp_fx[GRP_SB - 1] = s_min( Bits_grp_fx[GRP_SB - 1], 10 ); /* Q0 */ move16(); if ( LT_16( Bits_grp_fx[GRP_SB - 1], esthf_bits_fx ) ) @@ -616,7 +616,7 @@ void hq2_bit_alloc_har_fx( Bits_grp_fx[GRP_SB - 1] = 0; move16(); } - B_fx = sub( B_fx, Bits_grp_fx[GRP_SB - 1] ); + B_fx = sub( B_fx, Bits_grp_fx[GRP_SB - 1] ); /* Q0 */ } exp_shift = sub( add( SWB_BWE_LR_Qbe, QIns ), 47 ); /* (SWB_BWE_LR_Qbe+14+1+QIns-15-16) */ @@ -627,37 +627,37 @@ void hq2_bit_alloc_har_fx( IF( EQ_16( final_gr_fact_pos_fx, 1 ) ) { L_temp = Mult_32_16( L_Ravg_sub[1], extract_h( L_mult( bits_fact_fx, B_norm_fx ) ) ); - L_temp = Mult_32_16( L_temp, Inv_norm_sum_fx ); - Bits_grp_fx[1] = extract_h( L_shr( L_temp, exp_shift ) ); + L_temp = Mult_32_16( L_temp, Inv_norm_sum_fx ); /* Q16 + exp_shift */ + Bits_grp_fx[1] = extract_h( L_shr( L_temp, exp_shift ) ); /* Q0 */ move16(); L_temp = Mult_32_16( L_Ravg_sub[2], extract_h( L_mult( bits_fact1_fx, B_norm_fx ) ) ); - L_temp = Mult_32_16( L_temp, Inv_norm_sum_fx ); - Bits_grp_fx[2] = extract_h( L_shr( L_temp, exp_shift ) ); + L_temp = Mult_32_16( L_temp, Inv_norm_sum_fx ); /* Q16 + exp_shift */ + Bits_grp_fx[2] = extract_h( L_shr( L_temp, exp_shift ) ); /* Q0 */ move16(); - Bits_grp_fx[0] = sub( sub( B_fx, Bits_grp_fx[1] ), Bits_grp_fx[2] ); + Bits_grp_fx[0] = sub( sub( B_fx, Bits_grp_fx[1] ), Bits_grp_fx[2] ); /* Q0 */ move16(); } ELSE { L_temp = Mult_32_16( L_Ravg_sub[0], extract_h( L_mult( bits_fact_fx, B_norm_fx ) ) ); - L_temp = Mult_32_16( L_temp, Inv_norm_sum_fx ); - Bits_grp_fx[0] = extract_h( L_shr( L_temp, exp_shift ) ); + L_temp = Mult_32_16( L_temp, Inv_norm_sum_fx ); /* Q16 + exp_shift */ + Bits_grp_fx[0] = extract_h( L_shr( L_temp, exp_shift ) ); /* Q0 */ move16(); L_temp = Mult_32_16( L_Ravg_sub[2], extract_h( L_mult( bits_fact1_fx, B_norm_fx ) ) ); - L_temp = Mult_32_16( L_temp, Inv_norm_sum_fx ); - Bits_grp_fx[2] = extract_h( L_shr( L_temp, exp_shift ) ); + L_temp = Mult_32_16( L_temp, Inv_norm_sum_fx ); /* Q16 + exp_shift */ + Bits_grp_fx[2] = extract_h( L_shr( L_temp, exp_shift ) ); /* Q0 */ move16(); - Bits_grp_fx[1] = sub( sub( B_fx, Bits_grp_fx[0] ), Bits_grp_fx[2] ); + Bits_grp_fx[1] = sub( sub( B_fx, Bits_grp_fx[0] ), Bits_grp_fx[2] ); /* Q0 */ move16(); } IF( LT_16( Bits_grp_fx[2], THR2 ) ) { - Bits_grp_fx[1] = add( Bits_grp_fx[1], Bits_grp_fx[2] ); + Bits_grp_fx[1] = add( Bits_grp_fx[1], Bits_grp_fx[2] ); /* Q0 */ move16(); Bits_grp_fx[2] = 0; move16(); @@ -690,16 +690,16 @@ void hq2_bit_alloc_har_fx( Word32 hq2_bit_alloc_fx( const Word32 L_band_energy[], /* i : band energy of each subband */ - const Word16 bands, /* i : total number of subbands in a frame */ - Word32 L_Rk[], /* i/o: Bit allocation/Adjusted bit alloc. */ - Word16 *bit_budget_fx, /* i/o: bit bugdet */ - Word16 *p2a_flags, /* i : HF tonal indicator */ - const Word16 weight_fx, /* i : weight */ - const Word16 band_width[], /* i : Sub band bandwidth */ - const Word16 num_bits, /* i : available bits */ - const Word16 hqswb_clas, /* i : HQ2 class information */ - const Word16 bwidth, /* i : input bandwidth */ - const Word16 is_transient /* i : indicator HQ_TRANSIENT or not */ + const Word16 bands, /* i : total number of subbands in a frame Q0*/ + Word32 L_Rk[], /* i/o: Bit allocation/Adjusted bit alloc. QRk*/ + Word16 *bit_budget_fx, /* i/o: bit bugdet Q0*/ + Word16 *p2a_flags, /* i : HF tonal indicator Q0*/ + const Word16 weight_fx, /* i : weight Q13*/ + const Word16 band_width[], /* i : Sub band bandwidth Q0*/ + const Word16 num_bits, /* i : available bits Q0*/ + const Word16 hqswb_clas, /* i : HQ2 class information Q0*/ + const Word16 bwidth, /* i : input bandwidth Q0*/ + const Word16 is_transient /* i : indicator HQ_TRANSIENT or not Q0*/ ) { Word16 j, k; @@ -728,9 +728,9 @@ Word32 hq2_bit_alloc_fx( Word32 L_THR1, L_THR2, L_THR3; - L_THR1 = L_shl( L_deposit_l( THR1 ), SWB_BWE_LR_QRk ); - L_THR2 = L_shl( L_deposit_l( THR2 ), SWB_BWE_LR_QRk ); - L_THR3 = L_shl( L_deposit_l( THR3 ), SWB_BWE_LR_QRk ); + L_THR1 = L_shl( L_deposit_l( THR1 ), SWB_BWE_LR_QRk ); /* SWB_BWE_LR_QRk */ + L_THR2 = L_shl( L_deposit_l( THR2 ), SWB_BWE_LR_QRk ); /* SWB_BWE_LR_QRk */ + L_THR3 = L_shl( L_deposit_l( THR3 ), SWB_BWE_LR_QRk ); /* SWB_BWE_LR_QRk */ /* Init Rk to non-zero values for bands to be allocated bits */ IF( LE_16( num_bits, HQ_16k40_BIT ) ) @@ -763,7 +763,7 @@ Word32 hq2_bit_alloc_fx( /*mvs2r( p2a_flags, Rk, bands ); */ FOR( k = 0; k < bands; k++ ) { - L_Rk[k] = L_shl( L_deposit_l( p2a_flags[k] ), SWB_BWE_LR_QRk ); + L_Rk[k] = L_shl( L_deposit_l( p2a_flags[k] ), SWB_BWE_LR_QRk ); /* QRk */ move32(); } } @@ -807,11 +807,11 @@ Word32 hq2_bit_alloc_fx( Qdiv = sub( sub( add( SWB_BWE_LR_QRk, exp_normd ), exp_normn ), 1 ); - L_Ravg = L_shr( L_deposit_l( div_fx ), sub( Qdiv, SWB_BWE_LR_QRk ) ); + L_Ravg = L_shr( L_deposit_l( div_fx ), sub( Qdiv, SWB_BWE_LR_QRk ) ); /* QRk */ exp_normd = norm_s( *bit_budget_fx ); exp_normd = sub( exp_normd, 1 ); - bit_budget_norm_fx = shl( *bit_budget_fx, exp_normd ); + bit_budget_norm_fx = shl( *bit_budget_fx, exp_normd ); /* exp_normd */ div_fx = 0; move16(); @@ -830,7 +830,7 @@ Word32 hq2_bit_alloc_fx( L_tmp = Mult_32_16( L_sub( L_shl( L_band_energy[k], sub( SWB_BWE_LR_QRk, SWB_BWE_LR_Qbe ) ), L_Ravg ), weight_fx ); /* SWB_BWE_LR_QRk + Q13 - 15 */ L_tmp = L_shl( L_tmp, 2 ); /* -> SWB_BWE_LR_QRk */ - L_Rk[k] = L_add( L_shr( L_deposit_l( div_fx ), sub( Qdiv, SWB_BWE_LR_QRk ) ), L_tmp ); + L_Rk[k] = L_add( L_shr( L_deposit_l( div_fx ), sub( Qdiv, SWB_BWE_LR_QRk ) ), L_tmp ); /* SWB_BWE_LR_QRk */ move32(); } } @@ -860,9 +860,9 @@ Word32 hq2_bit_alloc_fx( L_Rcalc = L_deposit_l( 0 ); /* find worst under-allocation */ - FOR( k = sub( bands, 1 ); k >= 0; k-- ) + FOR( k = bands - 1; k >= 0; k-- ) { - tmp_fx = s_min( band_width[k], s_max( 12, shr( band_width[k], 2 ) ) ); + tmp_fx = s_min( band_width[k], s_max( 12, shr( band_width[k], 2 ) ) ); /* Q0 */ L_dummy = L_sub( L_shl( L_deposit_l( tmp_fx ), SWB_BWE_LR_QRk ), L_Rk[k] ); /*SWB_BWE_LR_QRk */ test(); test(); @@ -927,14 +927,14 @@ Word32 hq2_bit_alloc_fx( test(); IF( EQ_16( hqswb_clas, HQ_NORMAL ) && LT_16( num_bits, HQ_16k40_BIT ) ) { - bit_budget_temp_fx = *bit_budget_fx; + bit_budget_temp_fx = *bit_budget_fx; /* Q0 */ move16(); FOR( k = 0; k < NB_SWB_SUBBANDS; k++ ) { test(); - IF( EQ_16( p2a_flags[add( sub( bands, NB_SWB_SUBBANDS ), k )], 1 ) && L_Rk[add( sub( bands, NB_SWB_SUBBANDS ), k )] == 0 ) + IF( EQ_16( p2a_flags[( bands - NB_SWB_SUBBANDS ) + k], 1 ) && L_Rk[( bands - NB_SWB_SUBBANDS ) + k] == 0 ) { - p2a_flags[add( sub( bands, NB_SWB_SUBBANDS ), k )] = 0; + p2a_flags[( bands - NB_SWB_SUBBANDS ) + k] = 0; move16(); bit_budget_temp_fx = sub( bit_budget_temp_fx, bits_lagIndices_modeNormal[k] ); } diff --git a/lib_com/ivas_dirac_com.c b/lib_com/ivas_dirac_com.c index 2b696a4b1..f07dcd4be 100644 --- a/lib_com/ivas_dirac_com.c +++ b/lib_com/ivas_dirac_com.c @@ -1029,8 +1029,8 @@ void computeDirectionVectors_fixed( e_x = sub( i_e, norm_x ); e_y = sub( i_e, norm_y ); e_z = sub( i_e, norm_z ); - temp1 = BASOP_Util_Add_Mant32Exp( Mult_32_32( scaled_x, scaled_x ), 2 * e_x, Mult_32_32( scaled_y, scaled_y ), 2 * e_y, &exp1 ); - intensityNorm = BASOP_Util_Add_Mant32Exp( temp1, exp1, Mult_32_32( scaled_z, scaled_z ), 2 * e_z, &intensityNorm_e ); + temp1 = BASOP_Util_Add_Mant32Exp( Mult_32_32( scaled_x, scaled_x ), shl( e_x, 1 ), Mult_32_32( scaled_y, scaled_y ), shl( e_y, 1 ), &exp1 ); + intensityNorm = BASOP_Util_Add_Mant32Exp( temp1, exp1, Mult_32_32( scaled_z, scaled_z ), shl( e_z, 1 ), &intensityNorm_e ); IF( LE_32( intensityNorm, EPSILON_FX ) ) { @@ -1048,12 +1048,12 @@ void computeDirectionVectors_fixed( } ELSE { - intensityNorm = ISqrt32( intensityNorm, &intensityNorm_e ); /*Q31-intensityNorm_e*/ - *( direction_vector_x++ ) = L_shl( Mult_32_32( scaled_x, intensityNorm ), e_x + intensityNorm_e - 1 ); /*Q30*/ + intensityNorm = ISqrt32( intensityNorm, &intensityNorm_e ); /*Q31-intensityNorm_e*/ + *( direction_vector_x++ ) = L_shl( Mult_32_32( scaled_x, intensityNorm ), sub( add( e_x, intensityNorm_e ), 1 ) ); /*Q30*/ intensity_real_x++; - *( direction_vector_y++ ) = L_shl( Mult_32_32( scaled_y, intensityNorm ), e_y + intensityNorm_e - 1 ); /*Q30*/ + *( direction_vector_y++ ) = L_shl( Mult_32_32( scaled_y, intensityNorm ), sub( add( e_y, intensityNorm_e ), 1 ) ); /*Q30*/ intensity_real_y++; - *( direction_vector_z++ ) = L_shl( Mult_32_32( scaled_z, intensityNorm ), e_z + intensityNorm_e - 1 ); /*Q30*/ + *( direction_vector_z++ ) = L_shl( Mult_32_32( scaled_z, intensityNorm ), sub( add( e_z, intensityNorm_e ), 1 ) ); /*Q30*/ intensity_real_z++; move32(); diff --git a/lib_com/ivas_fb_mixer.c b/lib_com/ivas_fb_mixer.c index 5da92e987..86e9e9e47 100644 --- a/lib_com/ivas_fb_mixer.c +++ b/lib_com/ivas_fb_mixer.c @@ -343,13 +343,18 @@ ivas_error ivas_FB_mixer_open( { if ( fb_cfg->num_out_chans == 0 ) { +#ifndef IVAS_FLOAT_FIXED hFbMixer->ppFilterbank_inFR_re[i] = NULL; hFbMixer->ppFilterbank_inFR_im[i] = NULL; +#else + hFbMixer->ppFilterbank_inFR_re_fx[i] = NULL; + hFbMixer->ppFilterbank_inFR_im_fx[i] = NULL; +#endif } else { j = fb_cfg->remix_order[i]; - +#ifndef IVAS_FLOAT_FIXED if ( ( hFbMixer->ppFilterbank_inFR_re[j] = (float *) malloc( sizeof( float ) * frame_len ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FB mixer encoder" ); @@ -359,8 +364,7 @@ ivas_error ivas_FB_mixer_open( { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FB mixer encoder" ); } - -#ifdef IVAS_FLOAT_FIXED +#else if ( ( hFbMixer->ppFilterbank_inFR_re_fx[j] = (Word32 *) malloc( sizeof( Word32 ) * frame_len ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FB mixer encoder" ); @@ -412,21 +416,6 @@ ivas_error ivas_FB_mixer_open( if ( ( fb_cfg->active_w_mixing != -1 ) && ( fb_cfg->num_out_chans > 0 ) ) { - float *pTemp_mem; - if ( ( pTemp_mem = (float *) malloc( sizeof( float ) * fb_cfg->num_out_chans * max( fb_cfg->num_in_chans, fb_cfg->nchan_fb_in ) * IVAS_MAX_NUM_BANDS ) ) == NULL ) - { - return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FB mixer" ); - } - for ( i = 0; i < fb_cfg->num_out_chans; i++ ) - { - for ( j = 0; j < fb_cfg->num_in_chans; j++ ) - { - hFbMixer->prior_mixer[i][j] = pTemp_mem; - pTemp_mem += IVAS_MAX_NUM_BANDS; - set_f( hFbMixer->prior_mixer[i][j], 0, IVAS_MAX_NUM_BANDS ); - } - } - Word32 *pTemp_mem_fx; if ( ( pTemp_mem_fx = (Word32 *) malloc( sizeof( Word32 ) * fb_cfg->num_out_chans * max( fb_cfg->num_in_chans, fb_cfg->nchan_fb_in ) * IVAS_MAX_NUM_BANDS ) ) == NULL ) { @@ -441,6 +430,8 @@ ivas_error ivas_FB_mixer_open( set32_fx( hFbMixer->prior_mixer_fx[i][j], 0, IVAS_MAX_NUM_BANDS ); } } + hFbMixer->q_prior_mixer_fx = Q31; + move16(); } if ( !spar_reconfig_flag ) @@ -600,6 +591,7 @@ ivas_error ivas_FB_mixer_open_fx( ELSE { j = fb_cfg->remix_order[i]; + move16(); IF( ( hFbMixer->ppFilterbank_inFR_re_fx[j] = (Word32 *) malloc( sizeof( Word32 ) * frame_len ) ) == NULL ) { @@ -611,27 +603,6 @@ ivas_error ivas_FB_mixer_open_fx( return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FB mixer encoder" ); } } -#if 1 // TODO: To be removed later - if ( fb_cfg->num_out_chans == 0 ) - { - hFbMixer->ppFilterbank_inFR_re[i] = NULL; - hFbMixer->ppFilterbank_inFR_im[i] = NULL; - } - else - { - j = fb_cfg->remix_order[i]; - - if ( ( hFbMixer->ppFilterbank_inFR_re[j] = (float *) malloc( sizeof( float ) * frame_len ) ) == NULL ) - { - return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FB mixer encoder" ); - } - - if ( ( hFbMixer->ppFilterbank_inFR_im[j] = (float *) malloc( sizeof( float ) * frame_len ) ) == NULL ) - { - return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FB mixer encoder" ); - } - } -#endif } IF( EQ_16( fb_cfg->active_w_mixing, -1 ) ) @@ -677,22 +648,8 @@ ivas_error ivas_FB_mixer_open_fx( set32_fx( hFbMixer->prior_mixer_fx[i][j], 0, IVAS_MAX_NUM_BANDS ); } } -#if 1 // TODO: To be removed later - float *pTemp_mem; - if ( ( pTemp_mem = (float *) malloc( sizeof( float ) * fb_cfg->num_out_chans * max( fb_cfg->num_in_chans, fb_cfg->nchan_fb_in ) * IVAS_MAX_NUM_BANDS ) ) == NULL ) - { - return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FB mixer" ); - } - for ( i = 0; i < fb_cfg->num_out_chans; i++ ) - { - for ( j = 0; j < fb_cfg->num_in_chans; j++ ) - { - hFbMixer->prior_mixer[i][j] = pTemp_mem; - pTemp_mem += IVAS_MAX_NUM_BANDS; - set_f( hFbMixer->prior_mixer[i][j], 0, IVAS_MAX_NUM_BANDS ); - } - } -#endif + hFbMixer->q_prior_mixer_fx = Q31; + move16(); } IF( !spar_reconfig_flag ) @@ -816,13 +773,13 @@ void ivas_FB_mixer_close( if ( fb_cfg->num_out_chans > 0 ) { j = fb_cfg->remix_order[i]; - +#ifndef IVAS_FLOAT_FIXED free( hFbMixer->ppFilterbank_inFR_re[j] ); hFbMixer->ppFilterbank_inFR_re[j] = NULL; free( hFbMixer->ppFilterbank_inFR_im[j] ); hFbMixer->ppFilterbank_inFR_im[j] = NULL; -#ifdef IVAS_FLOAT_FIXED +#else free( hFbMixer->ppFilterbank_inFR_re_fx[j] ); hFbMixer->ppFilterbank_inFR_re_fx[j] = NULL; @@ -853,12 +810,6 @@ void ivas_FB_mixer_close( hFbMixer->ppFilterbank_prior_input_fx[i] = NULL; } #endif - if ( ( fb_cfg->active_w_mixing != -1 ) && ( fb_cfg->num_out_chans > 0 ) ) - { - free( hFbMixer->prior_mixer[0][0] ); - hFbMixer->prior_mixer[0][0] = NULL; - } - if ( !spar_reconfig_flag ) { if ( fb_cfg->num_out_chans > 0 ) @@ -1056,7 +1007,7 @@ void ivas_FB_mixer_close_fx( * * PCM ingest block *-----------------------------------------------------------------------------------------*/ - +#ifndef IVAS_FLOAT_FIXED void ivas_fb_mixer_pcm_ingest( IVAS_FB_MIXER_HANDLE hFbMixer, /* i/o: FB mixer handle */ float *pcm_in[], /* i : input audio channels */ @@ -1090,7 +1041,7 @@ void ivas_fb_mixer_pcm_ingest( return; } -#ifdef IVAS_FLOAT_FIXED +#else void ivas_fb_mixer_pcm_ingest_fx( IVAS_FB_MIXER_HANDLE hFbMixer, /* i/o: FB mixer handle */ Word32 *pcm_in[], /* i : input audio channels Qq_data_fix[] */ @@ -1167,7 +1118,7 @@ void ivas_fb_mixer_pcm_ingest_fx( * * *-----------------------------------------------------------------------------------------*/ - +#ifndef IVAS_FLOAT_FIXED void ivas_fb_mixer_update_prior_input( IVAS_FB_MIXER_HANDLE hFbMixer, /* i/o: FB mixer handle */ float *pcm_in[], /* i : input audio channels */ @@ -1185,8 +1136,7 @@ void ivas_fb_mixer_update_prior_input( return; } - -#ifdef IVAS_FLOAT_FIXED +#else void ivas_fb_mixer_update_prior_input_fx( IVAS_FB_MIXER_HANDLE hFbMixer, /* i/o: FB mixer handle */ Word32 *pcm_in_fx[], /* i : input audio channels */ @@ -1266,7 +1216,7 @@ void ivas_fb_mixer_get_windowed_fr_fx( return; } -#endif +#else void ivas_fb_mixer_get_windowed_fr( IVAS_FB_MIXER_HANDLE hFbMixer, /* i/o: FB mixer handle */ @@ -1311,7 +1261,7 @@ void ivas_fb_mixer_get_windowed_fr( return; } - +#endif /*-----------------------------------------------------------------------------------------* * Function ivas_fb_mixer_cross_fading() diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index b63a975d3..6dc3b8f55 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -829,8 +829,8 @@ void smooth_dft2td_transition( /*! r: flag indicating a valid bitrate */ -int16_t is_IVAS_bitrate( - const int32_t ivas_total_brate /* i : IVAS total bitrate */ +Word16 is_IVAS_bitrate_fx( + const Word32 ivas_total_brate /* i : IVAS total bitrate */ ); int16_t is_DTXrate( @@ -4648,22 +4648,6 @@ void ivas_spar_md_enc_close( ivas_spar_md_enc_state_t **hMdEnc /* i/o: SPAR MD encoder handle */ ); -#ifndef IVAS_FLOAT_FIXED -ivas_error ivas_spar_md_enc_process( - ivas_spar_md_enc_state_t *hMdEnc, /* i/o: SPAR MD encoder handle */ - const ENCODER_CONFIG_HANDLE hEncoderConfig, /* i : configuration structure */ - float *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], - float *cov_dtx_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], - BSTR_ENC_HANDLE hMetaData, /* i/o: MetaData handle */ - const int16_t dtx_vad, - const int16_t nchan_inp, - const int16_t sba_order, /* i : Ambisonic (SBA) order */ - float *prior_mixer[IVAS_MAX_FB_MIXER_OUT_CH][IVAS_MAX_SPAR_FB_MIXER_IN_CH], /* i : prior mixer_matrix */ - const int16_t dyn_active_w_flag, /* i : flag to indicate dynamic active W */ - const int16_t dirac_mono_flag /* i : flag to indicate mono only mode in SBA */ -); -#endif - void ivas_compute_spar_params( float *pppCov_mat_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], float dm_fv_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], @@ -4887,6 +4871,16 @@ void ivas_cov_smooth_process( #endif /* Transient detector module */ +#ifdef IVAS_FLOAT_FIXED +ivas_error ivas_transient_det_open_fx( + ivas_trans_det_state_t **hTranDet, /* i/o: Transient detector handle */ + const Word32 sampling_rate /* i : sampling rate */ +); + +void ivas_transient_det_close_fx( + ivas_trans_det_state_t **hTranDet /* i/o: Transient detector handle */ +); +#else ivas_error ivas_transient_det_open( ivas_trans_det_state_t **hTranDet, /* i/o: Transient detector handle */ const int32_t sampling_rate /* i : sampling rate */ @@ -4895,6 +4889,7 @@ ivas_error ivas_transient_det_open( void ivas_transient_det_close( ivas_trans_det_state_t **hTranDet /* i/o: Transient detector handle */ ); +#endif void ivas_transient_det_process( ivas_trans_det_state_t *hTranDet, /* i/o: SPAR TD handle */ @@ -5704,6 +5699,15 @@ void ivas_mcmasa_param_est_enc( const int16_t nchan_inp /* i : Number of input channels */ ); +#endif + +#ifdef IVAS_FLOAT_FIXED +void ivas_mcmasa_dmx_modify_fx( + const Word16 n_samples, /* i : input frame length in samples */ + Word32 dmx_fx[][L_FRAME48k + NS2SA(48000, IVAS_FB_ENC_DELAY_NS)], /* i/o: downmix signal to be transformed into another format Qx*/ + const Word16 n_chnls_dmx_old, /* i : number of downmix channels in the old format Q0*/ + const Word16 n_chnls_dmx_new /* i : number of downmix channels in the target format Q0*/ +); #endif void ivas_mcmasa_dmx_modify( const int16_t n_samples, /* i : input frame length in samples */ @@ -6232,15 +6236,6 @@ void ivas_fb_mixer_get_windowed_fr( const int16_t nchan_fb_in /* i : number of analysis channels */ ); -#ifndef IVAS_FLOAT_FIXED -void ivas_fb_mixer_process( - IVAS_FB_MIXER_HANDLE hFbMixer, /* i/o: FB mixer handle */ - float ***mixer_mat, /* i : mixer matrix */ - float **ppOut_pcm, /* o : output audio channels */ - const int16_t frame_len, /* i : frame length in samples */ - int16_t in_out_mixer_map[IVAS_MAX_FB_MIXER_OUT_CH][IVAS_MAX_SPAR_FB_MIXER_IN_CH] /* i/o: mixing mapping */ -); -#endif void ivas_fb_mixer_get_in_out_mapping( const IVAS_FB_CFG *fb_cfg, /* i : FB config. handle */ int16_t in_out_mixer_map[IVAS_MAX_FB_MIXER_OUT_CH][IVAS_MAX_SPAR_FB_MIXER_IN_CH] /* i/o: mixing mapping */ diff --git a/lib_com/ivas_prot_fx.h b/lib_com/ivas_prot_fx.h index fea7eca61..7c0458fa2 100644 --- a/lib_com/ivas_prot_fx.h +++ b/lib_com/ivas_prot_fx.h @@ -3224,10 +3224,10 @@ void computeDirectionVectors_fixed( UWord8 ivas_masa_surrcoh_signicant_fx( - Word32 surroundingCoherence[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /* i : Surround coherence */ - Word32 diffuse_to_total_ratio[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /* i : Diffuse to total ratio */ - const Word16 nSubFrames, /* i : Number of sub frames */ - const Word16 nBands /* i : Number of frequency bands */ + Word32 surroundingCoherence[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /* i : Surround coherence Q31 */ + Word32 diffuse_to_total_ratio[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /* i : Diffuse to total ratio Q31 */ + const Word16 nSubFrames, /* i : Number of sub frames */ + const Word16 nBands /* i : Number of frequency bands */ ); /*----------------------------------------------------------------------------------* @@ -3406,9 +3406,9 @@ void ivas_param_mc_enc_fx( const Word16 input_frame /* i : input frame length */ ); void ivas_merge_masa_transports_fx( - Word32 data_in_f1_fx[][L_FRAME48k], - Word32 *data_in_f2_fx[], - Word32 *data_out_f_fx[], + Word32 data_in_f1_fx[][L_FRAME48k], // Qx + Word32 *data_in_f2_fx[], // Qx + Word32 *data_out_f_fx[], // Qx const Word16 input_frame, const Word16 num_transport_channels ); @@ -5348,11 +5348,12 @@ ivas_error ivas_spar_md_enc_process_fx( BSTR_ENC_HANDLE hMetaData, /* i/o: MetaData handle */ const Word16 dtx_vad, const Word16 nchan_inp, - const Word16 sba_order, /* i : Ambisonic (SBA) order */ - float *prior_mixer[IVAS_MAX_FB_MIXER_OUT_CH][IVAS_MAX_SPAR_FB_MIXER_IN_CH], /* i : prior mixer_matrix */ - const Word16 dyn_active_w_flag, /* i : flag to indicate dynamic active W */ - const Word16 dirac_mono_flag /* i : flag to indicate mono only mode in SBA */ -); + const Word16 sba_order, /* i : Ambisonic (SBA) order */ + Word32 *prior_mixer[IVAS_MAX_FB_MIXER_OUT_CH][IVAS_MAX_SPAR_FB_MIXER_IN_CH], /* i : prior mixer_matrix */ + Word16 *q_prior_mixer, /* i/o : q for prior mixer_matrix */ + const Word16 dyn_active_w_flag, /* i : flag to indicate dynamic active W */ + const Word16 dirac_mono_flag, /* i : flag to indicate mono only mode in SBA */ + const Word16 nchan_out ); Word16 ivas_get_spar_dec_md_num_subframes( const Word16 sba_order, /* i : Ambisonic (SBA) order */ diff --git a/lib_com/ivas_qmetadata_com.c b/lib_com/ivas_qmetadata_com.c index 88821d0b3..25815afe3 100644 --- a/lib_com/ivas_qmetadata_com.c +++ b/lib_com/ivas_qmetadata_com.c @@ -69,24 +69,6 @@ static void ivas_qmetadata_free_memory( IVAS_QMETADATA_HANDLE hQMetaData ); * Allocate Q Metadata handle *-----------------------------------------------------------------------*/ -#ifdef IVAS_FLOAT_FIXED -ivas_error ivas_qmetadata_open( - IVAS_QMETADATA_HANDLE *hQMetaData /* i/o: q_metadata handle */ -) -{ - /* allocate MetaData handle */ - IF( ( *hQMetaData = (IVAS_QMETADATA_HANDLE) malloc( sizeof( IVAS_QMETADATA ) ) ) == NULL ) - { - return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for Q MetaData" ); - } - - ( *hQMetaData )->q_direction = NULL; - ( *hQMetaData )->surcoh_band_data = NULL; - ( *hQMetaData )->bandMap = NULL; - - return IVAS_ERR_OK; -} -#else ivas_error ivas_qmetadata_open( IVAS_QMETADATA_HANDLE *hQMetaData /* i/o: q_metadata handle */ ) @@ -103,8 +85,6 @@ ivas_error ivas_qmetadata_open( return IVAS_ERR_OK; } -#endif - /*-----------------------------------------------------------------------* * ivas_qmetadata_allocate_memory() diff --git a/lib_com/ivas_spar_com.c b/lib_com/ivas_spar_com.c index 74d3c01d3..bae0da15f 100644 --- a/lib_com/ivas_spar_com.c +++ b/lib_com/ivas_spar_com.c @@ -1129,9 +1129,8 @@ static void ivas_get_pred_coeffs_enc_fx( num_f = BASOP_Util_Add_Mant32Exp( dm_beta_re, sub( 31, dm_beta_re_q ), L_negate( L_tmp1 ), sub( 31, L_tmp1_q ), &num_f_e ); // Q=31-num_f_e - sqrt_val = Mpy_32_32( Mpy_32_32( dm_alpha[b], dm_alpha[b] ), g_th_sq ); //((2*dm_alpha64_q[b]-31)+27-31)-2 ,reducing the Q by 2 instead of multiplication by 4 - val_e = sub( 31, sub( sub( add( sub( shl( dm_alpha64_q[b], 1 ), 31 ), 27 ), 31 ), 2 ) ); // reducing the Q by 2 instead of multiplication by 4 - move16(); + sqrt_val = Mpy_32_32( Mpy_32_32( dm_alpha[b], dm_alpha[b] ), g_th_sq ); //((2*dm_alpha64_q[b]-31)+27-31)-2 ,reducing the Q by 2 instead of multiplication by 4 + val_e = sub( 31, sub( sub( add( sub( shl( dm_alpha64_q[b], 1 ), 31 ), 27 ), 31 ), 2 ) ); // reducing the Q by 2 instead of multiplication by 4 sqrt_val = BASOP_Util_Add_Mant32Exp( sqrt_val, val_e, Mpy_32_32( dm_beta_re, dm_beta_re ), sub( 31, sub( shl( dm_beta_re_q, 1 ), 31 ) ), &val_e ); // q=31-val_e sqrt_val = BASOP_Util_Add_Mant32Exp( sqrt_val, val_e, L_negate( Mpy_32_32( Mpy_32_32( dm_beta_re, g_th_sq ), dm_w ) ), sub( 31, sub( sub( add( sub( add( dm_beta_re_q, 27 ), 31 ), q_cov_real[0][0][b] ), 31 ), 2 ) ) /* reducing the Q by 2 instead of multiplication by 4*/, &val_e ); // q=31-val_e // val_e = norm_l( sqrt_val ); @@ -1193,6 +1192,11 @@ static void ivas_get_pred_coeffs_enc_fx( move32(); dm_v_re_q[i][b] = sub( add( add( dm_v_re_q[i][b], DM_F_q[b] ), tmp_shift ), 32 ); move16(); + if ( ppDM_Fv_re[i][b] == 0 ) + { + dm_v_re_q[i][b] = Q31; + move16(); + } *q_pred_coeffs = s_min( *q_pred_coeffs, q_ppPred_coeffs_re[i][b] ); move16(); @@ -3892,7 +3896,7 @@ void ivas_compute_spar_params_enc_fx( { pWscale[b] = 1; move32(); - q_Wscale[b] = 15; + q_Wscale[b] = Q31; move16(); } diff --git a/lib_com/ivas_stat_com.h b/lib_com/ivas_stat_com.h index fc0f2159d..d6dd690fb 100644 --- a/lib_com/ivas_stat_com.h +++ b/lib_com/ivas_stat_com.h @@ -853,11 +853,11 @@ typedef struct ivas_fb_mixer_state_structure int16_t num_diff_bands; ivas_filterbank_t *pFb; - +#ifndef IVAS_FLOAT_FIXED float *ppFilterbank_inFR_re[IVAS_MAX_FB_MIXER_IN_CH]; float *ppFilterbank_inFR_im[IVAS_MAX_FB_MIXER_IN_CH]; +#endif float *ppFilterbank_prior_input[IVAS_MAX_FB_MIXER_IN_CH]; - float *prior_mixer[IVAS_MAX_FB_MIXER_OUT_CH][IVAS_MAX_SPAR_FB_MIXER_IN_CH]; #ifdef IVAS_FLOAT_FIXED Word32 *ppFilterbank_inFR_re_fx[IVAS_MAX_FB_MIXER_IN_CH]; diff --git a/lib_com/ivas_tools.c b/lib_com/ivas_tools.c index 20cce673c..88a0200eb 100644 --- a/lib_com/ivas_tools.c +++ b/lib_com/ivas_tools.c @@ -3197,27 +3197,6 @@ void v_sort_ind_fixed( *-------------------------------------------------------------------*/ /*! r: flag indicating a valid bitrate */ -int16_t is_IVAS_bitrate( - const int32_t ivas_total_brate /* i : IVAS total bitrate */ -) -{ - int16_t j; - - j = SIZE_IVAS_BRATE_TBL - IVAS_NUM_ACTIVE_BRATES; /* skip NO_DATA and SID bitrates */ - while ( j < SIZE_IVAS_BRATE_TBL && ivas_total_brate != ivas_brate_tbl[j] ) - { - j++; - } - - if ( j >= SIZE_IVAS_BRATE_TBL ) - { - return 0; - } - - return 1; -} - -#ifdef IVAS_FLOAT_FIXED Word16 is_IVAS_bitrate_fx( const Word32 ivas_total_brate /* i : IVAS total bitrate */ ) @@ -3241,7 +3220,6 @@ Word16 is_IVAS_bitrate_fx( return 1; } -#endif /*-------------------------------------------------------------------* * is_DTXrate() diff --git a/lib_com/ivas_transient_det.c b/lib_com/ivas_transient_det.c index 65bb7f72b..019874fc9 100644 --- a/lib_com/ivas_transient_det.c +++ b/lib_com/ivas_transient_det.c @@ -350,7 +350,26 @@ static void ivas_transient_det_init( * * Allocate and initialize SPAR TD handle *------------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +ivas_error ivas_transient_det_open_fx( + ivas_trans_det_state_t **hTranDet_in, /* i/o: Transient detector handle */ + const Word32 sampling_rate /* i : sampling rate */ +) +{ + ivas_trans_det_state_t *hTranDet; + + IF( ( hTranDet = (ivas_trans_det_state_t *) malloc( sizeof( ivas_trans_det_state_t ) ) ) == NULL ) + { + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR TD\n" ); + } + ivas_transient_det_init( hTranDet, sampling_rate ); + + *hTranDet_in = hTranDet; + + return IVAS_ERR_OK; +} +#else ivas_error ivas_transient_det_open( ivas_trans_det_state_t **hTranDet_in, /* i/o: Transient detector handle */ const Word32 sampling_rate /* i : sampling rate */ @@ -358,7 +377,7 @@ ivas_error ivas_transient_det_open( { ivas_trans_det_state_t *hTranDet; - IF( ( hTranDet = (ivas_trans_det_state_t *) malloc( sizeof( ivas_trans_det_state_t ) ) ) == NULL ) + if ( ( hTranDet = (ivas_trans_det_state_t *) malloc( sizeof( ivas_trans_det_state_t ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR TD\n" ); } @@ -369,6 +388,7 @@ ivas_error ivas_transient_det_open( return IVAS_ERR_OK; } +#endif /*------------------------------------------------------------------------- @@ -376,7 +396,23 @@ ivas_error ivas_transient_det_open( * * Deallocate and initialize Transient detector handle *------------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +void ivas_transient_det_close_fx( + ivas_trans_det_state_t **hTranDet /* i/o: Transient detector handle */ +) +{ + test(); + IF( hTranDet == NULL || *hTranDet == NULL ) + { + return; + } + + free( *hTranDet ); + *hTranDet = NULL; + return; +} +#else void ivas_transient_det_close( ivas_trans_det_state_t **hTranDet /* i/o: Transient detector handle */ ) @@ -392,6 +428,7 @@ void ivas_transient_det_close( return; } +#endif #ifdef IVAS_FLOAT_FIXED /*-----------------------------------------------------------------------------------------* diff --git a/lib_com/prot.h b/lib_com/prot.h index 1f54c2b1b..d15bb767d 100644 --- a/lib_com/prot.h +++ b/lib_com/prot.h @@ -522,11 +522,6 @@ ivas_error push_next_bits( #endif // IVAS_FLOAT_FIXED /*! r: maximum number of indices */ -int16_t get_ivas_max_num_indices( - const IVAS_FORMAT ivas_format, /* i : IVAS format */ - const int32_t ivas_total_brate /* i : IVAS total bitrate */ -); - Word16 get_ivas_max_num_indices_fx( const IVAS_FORMAT ivas_format, /* i : IVAS format */ const Word32 ivas_total_brate /* i : IVAS total bitrate */ @@ -538,11 +533,6 @@ int16_t get_BWE_max_num_indices( ); /*! r: maximum number of indices */ -int16_t get_ivas_max_num_indices_metadata( - const IVAS_FORMAT ivas_format, /* i : IVAS format */ - const int32_t ivas_total_brate /* i : IVAS total bitrate */ -); - Word16 get_ivas_max_num_indices_metadata_fx( const IVAS_FORMAT ivas_format, /* i : IVAS format */ const Word32 ivas_total_brate /* i : IVAS total bitrate */ @@ -9940,11 +9930,6 @@ int16_t is_EVS_bitrate( int16_t *Opt_AMR_WB /* i : AMR-WB IO flag */ ); -/*! r: codec mode */ -int16_t get_codec_mode( - const int32_t total_brate /* i : total bitrate */ -); - int16_t getTcxonly_ivas( const int16_t element_mode, /* i : IVAS element mode */ const int32_t total_brate, /* i : total bitrate */ diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index de27c37c2..3239613af 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -1262,13 +1262,6 @@ void indices_to_serial_generic( Word16 *pFrame_size /* i/o: number of bits in the binary encoded access unit [bits] */ ); -void dec_prm_core( - Decoder_State *st ); - -void decision_matrix_core_dec( - Decoder_State *st /* i/o: decoder state structure */ -); - Word16 BRATE2IDX_fx( Word32 brate ); Word16 BRATE2IDX16k_fx( Word32 brate ); @@ -1743,20 +1736,20 @@ void Comp_and_apply_gain_ivas_fx( void pre_echo_att_fx( Word32 *Last_frame_ener_fx, /* i/o: Energy of the last frame 2*Q_new+1*/ Word16 *exc_fx, /* i/o: Excitation of the current frame Q_new*/ - const Word16 gsc_attack_flag_fx, /* i : flag signalling attack encoded by AC mode (GSC) */ + const Word16 gsc_attack_flag_fx, /* i : flag signalling attack encoded by AC mode (GSC) Q0*/ const Word16 Q_new, - const Word16 last_coder_type, /* i : Last coding mode */ - const Word16 L_frame /* i : Frame length*/ + const Word16 last_coder_type, /* i : Last coding mode Q0*/ + const Word16 L_frame /* i : Frame length Q0*/ ); void pre_echo_att_ivas_fx( Word32 *Last_frame_ener_fx, /* i/o: Energy of the last frame 2*Q_new+1*/ Word16 *exc_fx, /* i/o: Excitation of the current frame Q_new*/ - const Word16 gsc_attack_flag_fx, /* i : flag signalling attack encoded by AC mode (GSC) */ + const Word16 gsc_attack_flag_fx, /* i : flag signalling attack encoded by AC mode (GSC) Q0*/ const Word16 Q_new, - const Word16 last_coder_type, /* i : Last coding mode */ - const Word16 L_frame /* i : Frame length*/ + const Word16 last_coder_type, /* i : Last coding mode Q0*/ + const Word16 L_frame /* i : Frame length Q0*/ ); // wtda_fx.c void tcx_get_windows_mode1( @@ -2163,21 +2156,21 @@ hq2_bit_alloc_fx.c /========================================================================================================*/ void Bits2indvsb_fx( - const Word32 *L_be, /* i : Q14 Band Energy of sub-band */ + const Word32 *L_be, /* i : Qbe Band Energy of sub-band */ const Word16 start_band, /* i : Q0 start band indices */ const Word16 end_band, /* i : Q0 end band indices */ const Word16 Bits, /* i : Q0 Total number of bits allocated to a group */ - const Word32 L_Bits_needed, /* i : Q0 smallest bit number for allocation in group */ - Word32 *L_Rsubband, /* o : Q18 bit allocation of sub-band */ + const Word32 L_Bits_needed, /* i : QRk smallest bit number for allocation in group */ + Word32 *L_Rsubband, /* o : QRk bit allocation of sub-band */ Word16 *p2aflags_fx /* i/o: Q0 peaky/noise subband flag */ ); void hq2_bit_alloc_har_fx( - const Word32 *L_y, /* i : Q14 band energy of sub-vectors */ + const Word32 *L_y, /* i : Qbe band energy of sub-vectors */ Word16 B_fx, /* i : Q0 number of available bits */ const Word16 N_fx, /* i : Q0 number of sub-vectors */ - Word32 *L_Rsubband, /* o : Q18 sub-band bit-allocation vector */ - Word16 p2a_bands_fx, /* i : Q0 highfreq bands */ + Word32 *L_Rsubband, /* o : QRk sub-band bit-allocation vector */ + Word16 p2a_bands_fx, /* i : Q0 highfreq bands */ const Word32 L_core_brate, /* i : Q0 core bit rate */ Word16 p2a_flags_fx[], /* i/o: Q0 p2a_flags */ const Word16 band_width_fx[] /* i : Q0 table of band_width */ @@ -2185,16 +2178,16 @@ void hq2_bit_alloc_har_fx( Word32 hq2_bit_alloc_fx( const Word32 L_band_energy[], /* i : band energy of each subband */ - const Word16 bands, /* i : total number of subbands in a frame */ - Word32 L_Rk[], /* i/o: Bit allocation/Adjusted bit alloc. */ - Word16 *bit_budget_fx, /* i/o: bit bugdet */ - Word16 *p2a_flags, /* i : HF tonal indicator */ - const Word16 weight_fx, /* i : weight */ - const Word16 band_width[], /* i : Sub band bandwidth */ - const Word16 num_bits, /* i : available bits */ - const Word16 hqswb_clas, /* i : HQ2 class information */ - const Word16 bwidth, /* i : i bandwidth */ - const Word16 is_transient /* i : indicator HQ_TRANSIENT or not */ + const Word16 bands, /* i : total number of subbands in a frame Q0*/ + Word32 L_Rk[], /* i/o: Bit allocation/Adjusted bit alloc. QRk*/ + Word16 *bit_budget_fx, /* i/o: bit bugdet Q0*/ + Word16 *p2a_flags, /* i : HF tonal indicator Q0*/ + const Word16 weight_fx, /* i : weight Q13*/ + const Word16 band_width[], /* i : Sub band bandwidth Q0*/ + const Word16 num_bits, /* i : available bits Q0*/ + const Word16 hqswb_clas, /* i : HQ2 class information Q0*/ + const Word16 bwidth, /* i : input bandwidth Q0*/ + const Word16 is_transient /* i : indicator HQ_TRANSIENT or not Q0*/ ); void reordvct_fx( @@ -3919,6 +3912,7 @@ int16_t get_cng_mode( ); // core_com_config.c +/*! r: codec mode */ Word16 get_codec_mode( const Word32 total_brate /* i : total bitrate */ ); @@ -9192,38 +9186,44 @@ void dlpc_bfi( // guided_plc_util_fx.c void getLookAheadResSig( - Word16 *speechLookAhead, - Word16 *A_3Q12, - Word16 *res, - const Word16 L_frame, - const Word16 numSubFrame ); + Word16 *speechLookAhead, /* Qx */ + Word16 *A_3Q12, /* 3Q12 */ + Word16 *res, /* Qx */ + const Word16 L_frame, /* Q0 */ + const Word16 numSubFrame /* Q0 */ +); void updateLSFForConcealment( PLC_ENC_EVS_HANDLE decState, - Word16 *lsf_14Q1 ); + Word16 *lsf_14Q1 /* 14Q1 */ +); void getConcealedLP( PLC_ENC_EVS_HANDLE memDecState, - Word16 *AqCon, - const Word16 lsfBase[], - const Word16 last_good, - const Word16 L_frame ); + Word16 *AqCon, /* 14Q1 */ + const Word16 lsfBase[], /* Q1 * 1.28 */ + const Word16 last_good, /* Q0 */ + const Word16 L_frame /* Q0 */ +); void getConcealedLSF( PLC_ENC_EVS_HANDLE memDecState, - const Word16 lsfBase[], - const Word16 last_good, - const Word16 L_frame ); + const Word16 lsfBase[], /* Q1 * 1.28 */ + const Word16 last_good, /* Q0 */ + const Word16 L_frame /* Q0 */ +); void RecLpcSpecPowDiffuseLc( - Word16 *lspq, - Word16 *lsp_old, - Word16 *lsfq, + Word16 *lspq, /* Q15 */ + Word16 *lsp_old, /* Q15 */ + Word16 *lsfq, /* Q2.56 */ Decoder_State *st, - const Word16 reset_q ); + const Word16 reset_q /* Q0 */ +); void modify_lsf( - Word16 *lsf, - const Word16 n, - const Word32 sr_core, - const Word16 reset_q ); + Word16 *lsf, /* Q14 */ + const Word16 n, /* Q0 */ + const Word32 sr_core, /* Q0 */ + const Word16 reset_q /* Q0 */ +); // er_dec_tcx_fx.c void con_tcx_fx( diff --git a/lib_enc/ivas_corecoder_enc_reconfig.c b/lib_enc/ivas_corecoder_enc_reconfig.c index 9fb4736f1..c36c6eabd 100644 --- a/lib_enc/ivas_corecoder_enc_reconfig.c +++ b/lib_enc/ivas_corecoder_enc_reconfig.c @@ -39,6 +39,7 @@ #include "ivas_prot.h" #include "wmc_auto.h" #include "ivas_prot_fx.h" +#include "math.h" /*-------------------------------------------------------------------* * ivas_corecoder_enc_reconfig() * @@ -504,7 +505,12 @@ ivas_error ivas_corecoder_enc_reconfig_fx( { Word16 n, sce_id, cpe_id; Word16 len_inp_memory, n_CoreCoder_existing, nSCE_existing, nCPE_existing; - float input_buff[MCT_MAX_BLOCKS][L_FRAME48k + NS2SA( 48000, IVAS_FB_ENC_DELAY_NS )]; + + Word32 input_buff_fx[MCT_MAX_BLOCKS][L_FRAME48k + NS2SA( 48000, IVAS_FB_ENC_DELAY_NS )]; + FOR( int i = 0; i < MCT_MAX_BLOCKS; i++ ) + { + set32_fx( input_buff_fx[i], 0, L_FRAME48k + NS2SA( 48000, IVAS_FB_ENC_DELAY_NS ) ); + } BSTR_ENC_HANDLE hBstr; Word16 i, nb_bits; Indice temp_ind_list[MAX_NUM_IND_TEMP_LIST]; @@ -531,7 +537,7 @@ ivas_error ivas_corecoder_enc_reconfig_fx( nchan_transport_real = st_ivas->nchan_transport; move16(); - if ( EQ_16( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) ) + IF( EQ_16( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) ) { nchan_transport_real = add( nchan_transport_real, st_ivas->hEncoderConfig->nchan_ism ); } @@ -571,7 +577,6 @@ ivas_error ivas_corecoder_enc_reconfig_fx( move16(); } st_ivas->hCPE[cpe_id]->hCoreCoder[n]->total_brate = L_shr( st_ivas->hCPE[cpe_id]->element_brate, tmp ); /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() */ - // st_ivas->hCPE[cpe_id]->hCoreCoder[n]->total_brate = st_ivas->hCPE[cpe_id]->element_brate / ( st_ivas->nCPE > 1 ? 1 : CPE_CHANNELS ); /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() */ move32(); } } @@ -621,9 +626,9 @@ ivas_error ivas_corecoder_enc_reconfig_fx( nb_bits = 0; move16(); - test(); WHILE( LT_16( nb_bits, nb_bits_tot ) && LT_16( i, MAX_NUM_IND_TEMP_LIST ) ) { + test(); IF( hBstr->ind_list[i].nb_bits > 0 ) { temp_ind_list[i].id = hBstr->ind_list[i].id; @@ -653,28 +658,95 @@ ivas_error ivas_corecoder_enc_reconfig_fx( move16(); } +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + Word16 q_com_sce = 0; + Word16 q_com_cpe = 0; + + Word16 gb = find_guarded_bits_fx( len_inp_memory ); + IF( nSCE_old > 0 ) + { + float max_val = 0.0f; + for ( int k = 0; k < nSCE_old; k++ ) + { + for ( i = 0; i < len_inp_memory; i++ ) + { + max_val = max( max_val, (float) fabs( st_ivas->hSCE[k]->hCoreCoder[0]->input_buff[i] ) ); + } + } + q_com_sce = L_get_q1( max_val ) - gb; + } + + IF( nCPE_old > 0 ) + { + float max_val = 0.0f; + FOR( cpe_id = 0; cpe_id < nCPE_old; cpe_id++ ) + { + FOR( n = 0; n < CPE_CHANNELS; n++ ) + { + for ( i = 0; i < len_inp_memory; i++ ) + { + max_val = max( max_val, (float) fabs( st_ivas->hCPE[cpe_id]->hCoreCoder[n]->input_buff[i] ) ); + } + } + } + q_com_cpe = L_get_q1( max_val ) - gb; + } + + Word16 q_com = min( q_com_sce, q_com_cpe ); + IF( nSCE_old > 0 ) + { + for ( int k = 0; k < nSCE_old; k++ ) + { + st_ivas->hSCE[k]->hCoreCoder[0]->q_inp32 = q_com; + } + for ( int k = 0; k < nSCE_old; k++ ) + { + floatToFixed_arrL( st_ivas->hSCE[k]->hCoreCoder[0]->input_buff, st_ivas->hSCE[k]->hCoreCoder[0]->input_buff32_fx, st_ivas->hSCE[k]->hCoreCoder[0]->q_inp32, len_inp_memory ); + } + } + + IF( nCPE_old > 0 ) + { + + FOR( cpe_id = 0; cpe_id < nCPE_old; cpe_id++ ) + { + FOR( n = 0; n < CPE_CHANNELS; n++ ) + { + st_ivas->hCPE[cpe_id]->hCoreCoder[n]->q_inp32 = q_com; + } + } + FOR( cpe_id = 0; cpe_id < nCPE_old; cpe_id++ ) + { + FOR( n = 0; n < CPE_CHANNELS; n++ ) + { + floatToFixed_arrL( st_ivas->hCPE[cpe_id]->hCoreCoder[n]->input_buff, st_ivas->hCPE[cpe_id]->hCoreCoder[n]->input_buff32_fx, st_ivas->hCPE[cpe_id]->hCoreCoder[n]->q_inp32, len_inp_memory ); + } + } + } +#endif test(); test(); IF( EQ_16( hEncoderConfig->ivas_format, MC_FORMAT ) && EQ_16( last_mc_mode, MC_MODE_MCMASA ) && EQ_16( st_ivas->mc_mode, MC_MODE_MCMASA ) ) { /* within McMASA we can modify the transport signals when switching */ /* copy earlier dmx buffers */ + IF( nSCE_old > 0 ) { - set_zero( input_buff[0], len_inp_memory ); - mvr2r( st_ivas->hSCE[0]->hCoreCoder[0]->input_buff, input_buff[0], len_inp_memory ); + set32_fx( input_buff_fx[0], 0, len_inp_memory ); + Copy32( st_ivas->hSCE[0]->hCoreCoder[0]->input_buff32_fx, input_buff_fx[0], len_inp_memory ); } FOR( n = 0; n < CPE_CHANNELS; n++ ) { - set_zero( input_buff[n + 1], len_inp_memory ); + set32_fx( input_buff_fx[n + 1], 0, len_inp_memory ); IF( nCPE_old > 0 ) { - mvr2r( st_ivas->hCPE[0]->hCoreCoder[n]->input_buff, input_buff[n + 1], len_inp_memory ); + Copy32( st_ivas->hCPE[0]->hCoreCoder[n]->input_buff32_fx, input_buff_fx[n + 1], len_inp_memory ); } } - ivas_mcmasa_dmx_modify( len_inp_memory, input_buff, nSCE_old + CPE_CHANNELS * nCPE_old, st_ivas->nSCE + CPE_CHANNELS * st_ivas->nCPE ); + ivas_mcmasa_dmx_modify_fx( len_inp_memory, input_buff_fx, nSCE_old + CPE_CHANNELS * nCPE_old, st_ivas->nSCE + CPE_CHANNELS * st_ivas->nCPE ); n_CoreCoder_existing = 0; move16(); @@ -690,9 +762,8 @@ ivas_error ivas_corecoder_enc_reconfig_fx( /* save input audio buffers */ IF( GT_16( n_CoreCoder_existing, sce_id ) ) { - mvr2r( st_ivas->hSCE[sce_id]->hCoreCoder[0]->input_buff, input_buff[sce_id], len_inp_memory ); + Copy32( st_ivas->hSCE[sce_id]->hCoreCoder[0]->input_buff32_fx, input_buff_fx[sce_id], len_inp_memory ); } - destroy_sce_enc( st_ivas->hSCE[sce_id], ( EQ_16( st_ivas->hEncoderConfig->element_mode_init, EVS_MONO ) && !st_ivas->hEncoderConfig->stereo_dmx_evs ) ); st_ivas->hSCE[sce_id] = NULL; } @@ -704,14 +775,12 @@ ivas_error ivas_corecoder_enc_reconfig_fx( { IF( n_CoreCoder_existing > cpe_id * CPE_CHANNELS + n ) { - mvr2r( st_ivas->hCPE[cpe_id]->hCoreCoder[n]->input_buff, input_buff[( cpe_id - st_ivas->nCPE ) * CPE_CHANNELS + n], len_inp_memory ); + Copy32( st_ivas->hCPE[cpe_id]->hCoreCoder[n]->input_buff32_fx, input_buff_fx[( cpe_id - st_ivas->nCPE ) * CPE_CHANNELS + n], len_inp_memory ); } } - destroy_cpe_enc( st_ivas->hCPE[cpe_id] ); st_ivas->hCPE[cpe_id] = NULL; } - test(); IF( LE_16( st_ivas->nCPE, 1 ) && st_ivas->hMCT != NULL ) { @@ -752,9 +821,8 @@ ivas_error ivas_corecoder_enc_reconfig_fx( test(); IF( GT_16( n_CoreCoder_existing, sce_id ) && NE_16( hEncoderConfig->ivas_format, MASA_ISM_FORMAT ) ) { - mvr2r( input_buff[sce_id], st_ivas->hSCE[sce_id]->hCoreCoder[0]->input_buff, len_inp_memory ); + Copy32( input_buff_fx[sce_id], st_ivas->hSCE[sce_id]->hCoreCoder[0]->input_buff32_fx, len_inp_memory ); } - test(); /* only reset indices if it is not the first index list, this already contains the IVAS format bits */ IF( sce_id > 0 || EQ_16( hEncoderConfig->ivas_format, MASA_ISM_FORMAT ) ) @@ -785,7 +853,14 @@ ivas_error ivas_corecoder_enc_reconfig_fx( FOR( n = 0; n < CPE_CHANNELS; n++ ) { copy_encoder_config_fx( st_ivas, st_ivas->hCPE[cpe_id]->hCoreCoder[n], 0 ); - st_ivas->hCPE[cpe_id]->hCoreCoder[n]->total_brate = st_ivas->hCPE[cpe_id]->element_brate / ( st_ivas->nCPE > 1 ? 1 : CPE_CHANNELS ); /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() */ + IF( GT_16( st_ivas->nCPE, 1 ) ) + { + st_ivas->hCPE[cpe_id]->hCoreCoder[n]->total_brate = st_ivas->hCPE[cpe_id]->element_brate; + } + ELSE + { + st_ivas->hCPE[cpe_id]->hCoreCoder[n]->total_brate = L_shr( st_ivas->hCPE[cpe_id]->element_brate, 1 ); // CPE_CHANNELS + } move32(); test(); @@ -818,9 +893,10 @@ ivas_error ivas_corecoder_enc_reconfig_fx( /* propagate input audio buffers */ FOR( n = 0; n < CPE_CHANNELS; n++ ) { + IF( GT_16( n_CoreCoder_existing, add( i_mult( cpe_id, CPE_CHANNELS ), n ) ) ) { - mvr2r( input_buff[n], st_ivas->hCPE[cpe_id]->hCoreCoder[n]->input_buff, len_inp_memory ); + Copy32( input_buff_fx[n], st_ivas->hCPE[cpe_id]->hCoreCoder[n]->input_buff32_fx, len_inp_memory ); } } @@ -829,7 +905,7 @@ ivas_error ivas_corecoder_enc_reconfig_fx( /* only reset indices if it is not the first index list, this already contains the IVAS format bits */ test(); test(); - IF( add( i_mult( cpe_id, CPE_CHANNELS ), n ) > 0 || ( st_ivas->mc_mode == MC_MODE_MCMASA && st_ivas->nSCE > 0 ) ) + IF( add( i_mult( cpe_id, CPE_CHANNELS ), n ) > 0 || ( EQ_16( st_ivas->mc_mode, MC_MODE_MCMASA ) && st_ivas->nSCE > 0 ) ) { reset_indices_enc( st_ivas->hCPE[cpe_id]->hCoreCoder[n]->hBstr, st_ivas->hCPE[cpe_id]->hCoreCoder[n]->hBstr->nb_ind_tot ); } @@ -850,9 +926,9 @@ ivas_error ivas_corecoder_enc_reconfig_fx( move16(); IF( st_ivas->nSCE > 0 ) { - test(); WHILE( LT_16( nb_bits, nb_bits_tot ) && LT_16( i, MAX_NUM_IND_TEMP_LIST ) ) { + test(); IF( temp_ind_list[i].nb_bits > 0 ) { st_ivas->hSCE[0]->hCoreCoder[0]->hBstr->ind_list[i].id = temp_ind_list[i].id; @@ -876,6 +952,7 @@ ivas_error ivas_corecoder_enc_reconfig_fx( { WHILE( LT_16( nb_bits, nb_bits_tot ) && LT_16( i, MAX_NUM_IND_TEMP_LIST ) ) { + test(); IF( temp_ind_list[i].nb_bits > 0 ) { st_ivas->hCPE[0]->hCoreCoder[0]->hBstr->ind_list[i].id = temp_ind_list[i].id; @@ -895,26 +972,42 @@ ivas_error ivas_corecoder_enc_reconfig_fx( move16(); } - + test(); IF( EQ_16( last_mc_mode, MC_MODE_MCMASA ) && EQ_16( st_ivas->mc_mode, MC_MODE_MCMASA ) ) { /* restore modified transport signal */ IF( st_ivas->nSCE ) { - mvr2r( input_buff[0], st_ivas->hSCE[0]->hCoreCoder[0]->input_buff, len_inp_memory ); + Copy32( input_buff_fx[0], st_ivas->hSCE[0]->hCoreCoder[0]->input_buff32_fx, len_inp_memory ); } IF( st_ivas->nCPE ) { FOR( n = 0; n < CPE_CHANNELS; n++ ) { - mvr2r( input_buff[n + 1], st_ivas->hCPE[0]->hCoreCoder[n]->input_buff, len_inp_memory ); + Copy32( input_buff_fx[n + 1], st_ivas->hCPE[0]->hCoreCoder[n]->input_buff32_fx, len_inp_memory ); } } } test(); test(); + +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + IF( st_ivas->nSCE ) + { + fixedToFloat_arrL( st_ivas->hSCE[0]->hCoreCoder[0]->input_buff32_fx, st_ivas->hSCE[0]->hCoreCoder[0]->input_buff, q_com, len_inp_memory ); + } + + IF( st_ivas->nCPE ) + { + FOR( n = 0; n < CPE_CHANNELS; n++ ) + { + fixedToFloat_arrL( st_ivas->hCPE[0]->hCoreCoder[n]->input_buff32_fx, st_ivas->hCPE[0]->hCoreCoder[n]->input_buff, q_com, len_inp_memory ); + } + } +#endif + IF( GT_16( st_ivas->nCPE, 1 ) && LE_16( nCPE_old, 1 ) ) { IF( EQ_16( nCPE_old, 1 ) ) @@ -986,17 +1079,11 @@ ivas_error ivas_corecoder_enc_reconfig_fx( st_ivas->hCPE[0]->hCoreCoder[n]->total_brate = st_ivas->hCPE[0]->element_brate; move32(); st_ivas->hCPE[0]->hCoreCoder[n]->bits_frame_nominal = extract_l( Mpy_32_32( st_ivas->hCPE[0]->element_brate, 42949673 ) ) /* 1/50 in Q31*/; // ( st_ivas->hCPE[0]->element_brate / FRAMES_PER_SEC ); -#ifndef IVAS_FLOAT_FIXED - st_ivas->hCPE[0]->hCoreCoder[n]->igf = getIgfPresent( st_ivas->hCPE[0]->hCoreCoder[n]->element_mode, - L_mult0( st_ivas->hCPE[0]->hCoreCoder[n]->bits_frame_nominal, FRAMES_PER_SEC ), - st_ivas->hCPE[0]->hCoreCoder[n]->bwidth, - st_ivas->hCPE[0]->hCoreCoder[n]->rf_mode ); -#else + st_ivas->hCPE[0]->hCoreCoder[n]->igf = getIgfPresent_fx( st_ivas->hCPE[0]->hCoreCoder[n]->element_mode, L_mult0( st_ivas->hCPE[0]->hCoreCoder[n]->bits_frame_nominal, FRAMES_PER_SEC ), st_ivas->hCPE[0]->hCoreCoder[n]->bwidth, st_ivas->hCPE[0]->hCoreCoder[n]->rf_mode ); -#endif move16(); diff --git a/lib_enc/ivas_enc.c b/lib_enc/ivas_enc.c index 1a5a95af5..bb6a9dc84 100644 --- a/lib_enc/ivas_enc.c +++ b/lib_enc/ivas_enc.c @@ -773,8 +773,8 @@ ivas_error ivas_enc( /*----------------------------------------------------------------* * Encoding *----------------------------------------------------------------*/ - - if ( ivas_format == STEREO_FORMAT ) + test(); + IF( EQ_32( ivas_format, STEREO_FORMAT ) ) { st_ivas->hCPE[0]->element_brate = ivas_total_brate; if ( ( error = ivas_cpe_enc( st_ivas, 0, data_f[0], data_f[1], input_frame, 0 /* no metadata */ ) ) != IVAS_ERR_OK ) @@ -782,7 +782,7 @@ ivas_error ivas_enc( return error; } } - else if ( ivas_format == ISM_FORMAT ) + ELSE IF( EQ_32( ivas_format, ISM_FORMAT ) ) { /* select ISM format mode; reconfigure the ISM format encoder */ if ( ( error = ivas_ism_enc_config( st_ivas ) ) != IVAS_ERR_OK ) @@ -968,9 +968,7 @@ ivas_error ivas_enc( v_multc( data_f[hEncoderConfig->nchan_ism], 1.0f / SQRT2, data_f[hEncoderConfig->nchan_ism], input_frame ); mvr2r( data_f[hEncoderConfig->nchan_ism], data_f[hEncoderConfig->nchan_ism + 1], input_frame ); } -#endif -#ifdef IVAS_FLOAT_FIXED -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + for ( i = 0; i < st_ivas->nchan_transport; i++ ) { floatToFixed_arrL( st_ivas->hMasa->data.cldfbAnaEnc[i]->cldfb_state, st_ivas->hMasa->data.cldfbAnaEnc[i]->cldfb_state_fx, Q11, st_ivas->hMasa->data.cldfbAnaEnc[i]->cldfb_state_length ); @@ -985,65 +983,53 @@ ivas_error ivas_enc( fixedToFloat_arrL( st_ivas->hMasa->data.cldfbAnaEnc[i]->cldfb_state_fx, st_ivas->hMasa->data.cldfbAnaEnc[i]->cldfb_state, Q11, st_ivas->hMasa->data.cldfbAnaEnc[i]->cldfb_state_length ); } #endif -#else - /* Estimate TF-tile energy for the input MASA stream */ - ivas_masa_estimate_energy( st_ivas->hMasa, &( data_f[hEncoderConfig->nchan_ism] ), input_frame, st_ivas->nchan_transport ); -#endif -#ifdef IVAS_FLOAT_FIXED - if ( ( error = ivas_omasa_enc_config_fx( st_ivas ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_omasa_enc_config_fx( st_ivas ) ) != IVAS_ERR_OK ) { return error; } -#else - if ( ( error = ivas_omasa_enc_config( st_ivas ) ) != IVAS_ERR_OK ) - { - return error; - } -#endif // IVAS_FLOAT_FIXED set_s( nb_bits_metadata, 0, MAX_SCE + 1 ); idx_separated_object = 0; + move16(); data_separated_object = data_f[hEncoderConfig->nchan_ism + CPE_CHANNELS]; data_separated_object_fx = data_fx[hEncoderConfig->nchan_ism + CPE_CHANNELS]; /* put audio object data in SCE's */ - if ( st_ivas->ism_mode != ISM_MASA_MODE_DISC ) + IF( NE_32( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) ) { - /* Estimate MASA parameters for the objects */ -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - OMASA_ENC_HANDLE hOMasa = st_ivas->hOMasa; - int16_t j; - int16_t nchan_transport = st_ivas->nchan_transport; - int16_t nchan_ism = hEncoderConfig->nchan_ism; - int16_t norm_data_in = MAX16B; - for ( j = 0; j < nchan_ism + nchan_transport; j++ ) + /* Scaling data_fx */ { - for ( int k = 0; k < input_frame; k++ ) + Word16 norm_data_in = MAX16B; + FOR( i = 0; i < hEncoderConfig->nchan_ism + st_ivas->nchan_transport; i++ ) { - data_fx[j][k] = float_to_fix( data_f[j][k], st_ivas->q_data_fx ); + norm_data_in = s_min( norm_data_in, L_norm_arr( data_fx[i], input_frame ) ); } - norm_data_in = s_min( norm_data_in, L_norm_arr( data_fx[j], input_frame ) ); - } - norm_data_in -= 6; /*guard bit is 3->to handle overflow in cldfbAnalysis*/ - for ( j = 0; j < nchan_ism + nchan_transport; j++ ) - { - Scale_sig32( data_fx[j], input_frame, norm_data_in ); + norm_data_in = sub( norm_data_in, 6 ); /*guard bit is 3->to handle overflow in cldfbAnalysis*/ + FOR( i = 0; i < hEncoderConfig->nchan_ism + st_ivas->nchan_transport; i++ ) + { + scale_sig32( data_fx[i], input_frame, norm_data_in ); + } + st_ivas->q_data_fx = add( st_ivas->q_data_fx, norm_data_in ); + move16(); } - st_ivas->q_data_fx = st_ivas->q_data_fx + norm_data_in; - for ( i = 0; i < nchan_ism; i++ ) +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + OMASA_ENC_HANDLE hOMasa = st_ivas->hOMasa; + for ( i = 0; i < hEncoderConfig->nchan_ism; i++ ) { floatToFixed_arrL( hOMasa->cldfbAnaEnc[i]->cldfb_state, hOMasa->cldfbAnaEnc[i]->cldfb_state_fx, st_ivas->q_data_fx, hOMasa->cldfbAnaEnc[i]->cldfb_state_length ); } #endif + + /* Estimate MASA parameters for the objects */ ivas_omasa_enc_fx( st_ivas->hOMasa, st_ivas->hMasa, st_ivas->hIsmMetaData, data_fx, st_ivas->q_data_fx, input_frame, st_ivas->nchan_transport, hEncoderConfig->nchan_ism, st_ivas->ism_mode, data_separated_object_fx, &idx_separated_object ); #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - for ( i = 0; i < nchan_ism; i++ ) + for ( i = 0; i < hEncoderConfig->nchan_ism; i++ ) { fixedToFloat_arrL( hOMasa->cldfbAnaEnc[i]->cldfb_state_fx, hOMasa->cldfbAnaEnc[i]->cldfb_state, st_ivas->q_data_fx, hOMasa->cldfbAnaEnc[i]->cldfb_state_length ); } - for ( i = 0; i < nchan_ism + nchan_transport; i++ ) + for ( i = 0; i < hEncoderConfig->nchan_ism + st_ivas->nchan_transport; i++ ) { fixedToFloat_arrL( data_fx[i], data_f[i], st_ivas->q_data_fx, input_frame ); } @@ -1053,39 +1039,37 @@ ivas_error ivas_enc( /* Encode ISMs transport channels */ n = 0; - if ( st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ ) + move16(); + IF( EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) ) { - if ( ( error = ivas_sce_enc( st_ivas, 0, data_separated_object, input_frame, nb_bits_metadata[1] ) ) != IVAS_ERR_OK ) /* there are no metadata bits in SCE in this mode */ + IF( ( error = ivas_sce_enc( st_ivas, 0, data_separated_object, input_frame, nb_bits_metadata[1] ) ) != IVAS_ERR_OK ) /* there are no metadata bits in SCE in this mode */ { return error; } } - else if ( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ ) + ELSE IF( EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) ) { - if ( ( error = ivas_ism_enc( st_ivas, &data_separated_object, input_frame, &nb_bits_metadata[1], 0 ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_ism_enc( st_ivas, &data_separated_object, input_frame, &nb_bits_metadata[1], 0 ) ) != IVAS_ERR_OK ) { return error; } } - else if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC ) + ELSE IF( EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) ) { -#ifdef IVAS_FLOAT_FIXED flag_omasa_ener_brate = ivas_omasa_ener_brate_fx( st_ivas->hEncoderConfig->nchan_ism, ivas_total_brate, data_fx, input_frame, sub( 31, st_ivas->q_data_fx ) ); -#else - flag_omasa_ener_brate = ivas_omasa_ener_brate( st_ivas->hEncoderConfig->nchan_ism, ivas_total_brate, data_fx, input_frame, sub( 31, st_ivas->q_data_fx ) ); -#endif // IVAS_FLOAT_FIXED /* Analysis, decision about bitrates per channel & core coding */ - if ( ( error = ivas_ism_enc( st_ivas, data_f, input_frame, &nb_bits_metadata[1], flag_omasa_ener_brate ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_ism_enc( st_ivas, data_f, input_frame, &nb_bits_metadata[1], flag_omasa_ener_brate ) ) != IVAS_ERR_OK ) { return error; } n = st_ivas->hEncoderConfig->nchan_ism; + move16(); } hMetaData = st_ivas->hCPE[st_ivas->nCPE - 1]->hMetaData; - if ( st_ivas->nSCE > 0 ) + IF( st_ivas->nSCE > 0 ) { /* update pointer to the buffer of indices (ISM indices were alredy written) */ hMetaData->ind_list = st_ivas->hSCE[st_ivas->nSCE - 1]->hMetaData->ind_list + st_ivas->hSCE[st_ivas->nSCE - 1]->hMetaData->nb_ind_tot; @@ -1108,14 +1092,14 @@ ivas_error ivas_enc( ); /* Encode MASA transport channels */ - if ( ( ivas_cpe_enc( st_ivas, 0, data_f[n], data_f[n + 1], input_frame, nb_bits_metadata[0] ) ) != IVAS_ERR_OK ) + IF( ( ivas_cpe_enc( st_ivas, 0, data_f[n], data_f[n + 1], input_frame, nb_bits_metadata[0] ) ) != IVAS_ERR_OK ) { return error; } } - else if ( ivas_format == SBA_ISM_FORMAT ) + ELSE IF( EQ_32( ivas_format, SBA_ISM_FORMAT ) ) { - int16_t planar_sba_orig; + Word16 planar_sba_orig; planar_sba_orig = hEncoderConfig->sba_planar; #ifdef IVAS_FLOAT_FIXED /* Analyze objects and determine needed audio signals */ @@ -1200,10 +1184,10 @@ ivas_error ivas_enc( } } } - else if ( EQ_32( ivas_format, MC_FORMAT ) ) + ELSE IF( EQ_32( ivas_format, MC_FORMAT ) ) { /* select MC format mode; write MC LS setup; reconfigure the MC format encoder */ - if ( ( error = ivas_mc_enc_config( st_ivas ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_mc_enc_config( st_ivas ) ) != IVAS_ERR_OK ) { return error; } @@ -1239,14 +1223,14 @@ ivas_error ivas_enc( fixedToFloat_arrL( data_fx[LFE_CHANNEL], data_f[LFE_CHANNEL], st_ivas->q_data_fx, input_frame ); #endif - if ( st_ivas->mc_mode == MC_MODE_MCT ) + IF( EQ_32( st_ivas->mc_mode, MC_MODE_MCT ) ) { if ( ( error = ivas_mct_enc( st_ivas, data_f, input_frame, 0 ) ) != IVAS_ERR_OK ) { return error; } } - else if ( st_ivas->mc_mode == MC_MODE_PARAMUPMIX ) + ELSE IF( EQ_32( st_ivas->mc_mode, MC_MODE_PARAMUPMIX ) ) { /* encode MC ParamUpmix parameters and write bitstream */ #ifdef IVAS_FLOAT_FIXED @@ -1292,7 +1276,7 @@ ivas_error ivas_enc( return error; } } - else if ( st_ivas->mc_mode == MC_MODE_PARAMMC ) + ELSE IF( EQ_32( st_ivas->mc_mode, MC_MODE_PARAMMC ) ) { /* encode Parametric MC parameters and write bitstream */ #ifdef IVAS_FLOAT_FIXED @@ -1334,72 +1318,65 @@ ivas_error ivas_enc( } } } - else if ( st_ivas->mc_mode == MC_MODE_MCMASA ) + ELSE IF( EQ_32( st_ivas->mc_mode, MC_MODE_MCMASA ) ) { if ( st_ivas->hMcMasa->separateChannelEnabled ) { hMetaData = st_ivas->hCPE[0]->hMetaData; /* Metadata is always with CPE in the case of separated channel */ } -#ifdef IVAS_FLOAT_FIXED -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - Word16 q_data = Q8; - for ( i = 0; i < nchan_inp; i++ ) + + FOR( i = 0; i < nchan_inp; i++ ) { - floatToFixed_arrL32( data_f[i], data_fx[i], q_data, input_frame ); + scale_sig32( data_fx[i], input_frame, Q8 - Q11 ); // Q11 -> Q8 } -#endif - ivas_mcmasa_enc_fx( st_ivas->hMcMasa, st_ivas->hQMetaData, st_ivas->hMasa, data_fx, input_frame, st_ivas->nchan_transport, nchan_inp, q_data ); + st_ivas->q_data_fx = Q8; + move16(); + + ivas_mcmasa_enc_fx( st_ivas->hMcMasa, st_ivas->hQMetaData, st_ivas->hMasa, data_fx, input_frame, st_ivas->nchan_transport, nchan_inp, st_ivas->q_data_fx ); #ifdef IVAS_FLOAT_FIXED_CONVERSIONS for ( i = 0; i < nchan_inp; i++ ) { - fixedToFloat_arrL( data_fx[i], data_f[i], q_data, input_frame ); + fixedToFloat_arrL( data_fx[i], data_f[i], st_ivas->q_data_fx, input_frame ); } - Word32 ii, jj; - Word16 nBands = st_ivas->hMcMasa->nbands; - Word16 nBlocks = MAX_PARAM_SPATIAL_SUBFRAMES; - FOR( ii = 0; ii < nBands; ii++ ) +#endif + /* Scaling down the Q-factor of energy_ratio_fx from Q31 to Q30 */ + FOR( i = 0; i < st_ivas->hMcMasa->nbands; i++ ) { - FOR( jj = 0; jj < nBlocks; jj++ ) - { - st_ivas->hQMetaData->q_direction[0].band_data[ii].energy_ratio_fx[jj] = L_shr( st_ivas->hQMetaData->q_direction[0].band_data[ii].energy_ratio_fx[jj], 1 ); // Q31 -> Q30 - } + scale_sig32( st_ivas->hQMetaData->q_direction[0].band_data[i].energy_ratio_fx, MAX_PARAM_SPATIAL_SUBFRAMES, -1 ); // Q31 -> Q30 } -#endif -#else - ivas_mcmasa_enc( st_ivas->hMcMasa, st_ivas->hQMetaData, st_ivas->hMasa, data_f, input_frame, st_ivas->nchan_transport, nchan_inp ); -#endif + IF( ( error = ivas_masa_encode_fx( st_ivas->hMasa, st_ivas->hQMetaData, hMetaData, &nb_bits_metadata[0], st_ivas->nchan_transport, ivas_format, ivas_total_brate, 0, -1, ISM_MODE_NONE, -1, NULL, -1, NULL, 0, 0 ) ) != IVAS_ERR_OK ) { return error; } - if ( st_ivas->hMcMasa->separateChannelEnabled ) + IF( st_ivas->hMcMasa->separateChannelEnabled ) { - if ( ( error = ivas_sce_enc( st_ivas, 0, data_f[2], input_frame, 0 ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_sce_enc( st_ivas, 0, data_f[2], input_frame, 0 ) ) != IVAS_ERR_OK ) { return error; } st_ivas->hCPE[0]->hCoreCoder[0]->hBstr->ind_list = st_ivas->hSCE[0]->hCoreCoder[0]->hBstr->ind_list + st_ivas->hSCE[0]->hCoreCoder[0]->hBstr->nb_ind_tot; - if ( ( error = ivas_cpe_enc( st_ivas, 0, data_f[0], data_f[1], input_frame, hMetaData->nb_bits_tot ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_cpe_enc( st_ivas, 0, data_f[0], data_f[1], input_frame, hMetaData->nb_bits_tot ) ) != IVAS_ERR_OK ) { return error; } } - else + ELSE { - if ( st_ivas->nSCE == 1 ) + IF( EQ_16( st_ivas->nSCE, 1 ) ) { - if ( ( error = ivas_sce_enc( st_ivas, 0, data_f[0], input_frame, hMetaData->nb_bits_tot ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_sce_enc( st_ivas, 0, data_f[0], input_frame, hMetaData->nb_bits_tot ) ) != IVAS_ERR_OK ) { return error; } } - else if ( st_ivas->nCPE == 1 ) /* Stereo DMX */ + ELSE IF( EQ_16( st_ivas->nCPE, 1 ) ) /* Stereo DMX */ { - if ( ( error = ivas_cpe_enc( st_ivas, 0, data_f[0], data_f[1], input_frame, hMetaData->nb_bits_tot ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_cpe_enc( st_ivas, 0, data_f[0], data_f[1], input_frame, hMetaData->nb_bits_tot ) ) != IVAS_ERR_OK ) { return error; } diff --git a/lib_enc/ivas_init_enc.c b/lib_enc/ivas_init_enc.c index 3114ae478..e0fd58802 100644 --- a/lib_enc/ivas_init_enc.c +++ b/lib_enc/ivas_init_enc.c @@ -567,7 +567,11 @@ void ivas_initialize_handles_enc( st_ivas->hCPE[i] = NULL; } +#ifdef IVAS_FLOAT_FIXED + st_ivas->mem_hp20_in_fx = NULL; +#else st_ivas->mem_hp20_in = NULL; +#endif /* ISM metadata handles */ FOR( i = 0; i < MAX_NUM_OBJECTS; i++ ) @@ -711,7 +715,7 @@ ivas_error ivas_init_encoder( *-----------------------------------------------------------------*/ /* set the maximum allowed number of indices in the list */ - st_ivas->ivas_max_num_indices = get_ivas_max_num_indices( ivas_format, ivas_total_brate ); + st_ivas->ivas_max_num_indices = get_ivas_max_num_indices_fx( ivas_format, ivas_total_brate ); /* allocate buffer of indices */ if ( ( st_ivas->ind_list = (INDICE_HANDLE) malloc( st_ivas->ivas_max_num_indices * sizeof( Indice ) ) ) == NULL ) @@ -726,7 +730,7 @@ ivas_error ivas_init_encoder( } /* set the maximum allowed number of metadata indices in the list */ - st_ivas->ivas_max_num_indices_metadata = get_ivas_max_num_indices_metadata( st_ivas->hEncoderConfig->ivas_format, st_ivas->hEncoderConfig->ivas_total_brate ); + st_ivas->ivas_max_num_indices_metadata = get_ivas_max_num_indices_metadata_fx( st_ivas->hEncoderConfig->ivas_format, st_ivas->hEncoderConfig->ivas_total_brate ); /* allocate buffer of metadata indices */ if ( st_ivas->ivas_max_num_indices_metadata > 0 ) @@ -765,7 +769,7 @@ ivas_error ivas_init_encoder( test(); IF( NE_16( st_ivas->hEncoderConfig->element_mode_init, EVS_MONO ) ) { - IF( NE_32( ( error = create_sce_enc( st_ivas, sce_id, ivas_total_brate ) ), IVAS_ERR_OK ) ) + IF( NE_32( ( error = create_sce_enc_fx( st_ivas, sce_id, ivas_total_brate ) ), IVAS_ERR_OK ) ) { return error; } @@ -817,7 +821,7 @@ ivas_error ivas_init_encoder( for ( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ ) { - if ( ( error = create_sce_enc( st_ivas, sce_id, element_brate_tmp[sce_id] ) ) != IVAS_ERR_OK ) + if ( ( error = create_sce_enc_fx( st_ivas, sce_id, element_brate_tmp[sce_id] ) ) != IVAS_ERR_OK ) { return error; } @@ -1260,6 +1264,7 @@ ivas_error ivas_init_encoder( n = getNumChanAnalysis_fx( st_ivas ); #endif +#ifndef IVAS_FLOAT_FIXED if ( n > 0 ) { if ( ( st_ivas->mem_hp20_in = (float **) malloc( n * sizeof( float * ) ) ) == NULL ) @@ -1281,7 +1286,7 @@ ivas_error ivas_init_encoder( set_f( st_ivas->mem_hp20_in[i], 0.0f, L_HP20_MEM ); } -#ifdef IVAS_FLOAT_FIXED +#else IF( n > 0 ) { IF( ( st_ivas->mem_hp20_in_fx = (Word32 **) malloc( n * sizeof( Word32 * ) ) ) == NULL ) @@ -1321,41 +1326,52 @@ ivas_error ivas_init_encoder_fx( ivas_error error; error = IVAS_ERR_OK; + move32(); hEncoderConfig = st_ivas->hEncoderConfig; ivas_format = hEncoderConfig->ivas_format; + move32(); input_Fs = hEncoderConfig->input_Fs; + move32(); ivas_total_brate = hEncoderConfig->ivas_total_brate; + move32(); hEncoderConfig->last_ivas_total_brate = ivas_total_brate; + move32(); IF( NE_16( ivas_format, MONO_FORMAT ) ) { /* In IVAS, ensure that minimum coded bandwidth is WB */ hEncoderConfig->max_bwidth = extract_l( L_max( hEncoderConfig->max_bwidth, WB ) ); + move16(); } st_ivas->ism_mode = ISM_MODE_NONE; + move32(); st_ivas->mc_mode = MC_MODE_NONE; + move32(); st_ivas->nchan_transport = -1; + move16(); /*-----------------------------------------------------------------* * Allocate floating-point input audio buffers *-----------------------------------------------------------------*/ nchan_inp_buff = hEncoderConfig->nchan_inp; + move16(); IF( EQ_16( ivas_format, MONO_FORMAT ) ) { nchan_inp_buff = 0; + move16(); } ELSE IF( EQ_16( ivas_format, MASA_ISM_FORMAT ) ) { IF( EQ_16( sub( hEncoderConfig->nchan_inp, hEncoderConfig->nchan_ism ), 1 ) ) /* mono is duplicated in monoMASA */ { - nchan_inp_buff++; + nchan_inp_buff = add( nchan_inp_buff, 1 ); } - nchan_inp_buff++; /* for *data_separated_object */ + nchan_inp_buff = add( nchan_inp_buff, 1 ); /* for *data_separated_object */ } #if 1 /* To be removed */ FOR( n = 0; n < nchan_inp_buff; n++ ) @@ -1391,6 +1407,7 @@ ivas_error ivas_init_encoder_fx( /* set the maximum allowed number of indices in the list */ st_ivas->ivas_max_num_indices = get_ivas_max_num_indices_fx( ivas_format, ivas_total_brate ); + move16(); /* allocate buffer of indices */ IF( ( st_ivas->ind_list = (INDICE_HANDLE) malloc( st_ivas->ivas_max_num_indices * sizeof( Indice ) ) ) == NULL ) @@ -1402,11 +1419,12 @@ ivas_error ivas_init_encoder_fx( FOR( i = 0; i < st_ivas->ivas_max_num_indices; i++ ) { st_ivas->ind_list[i].nb_bits = -1; + move16(); } /* set the maximum allowed number of metadata indices in the list */ st_ivas->ivas_max_num_indices_metadata = get_ivas_max_num_indices_metadata_fx( st_ivas->hEncoderConfig->ivas_format, st_ivas->hEncoderConfig->ivas_total_brate ); - + move16(); /* allocate buffer of metadata indices */ IF( st_ivas->ivas_max_num_indices_metadata > 0 ) { @@ -1419,6 +1437,7 @@ ivas_error ivas_init_encoder_fx( FOR( i = 0; i < st_ivas->ivas_max_num_indices_metadata; i++ ) { st_ivas->ind_list_metadata[i].nb_bits = -1; + move16(); } } ELSE @@ -1429,7 +1448,7 @@ ivas_error ivas_init_encoder_fx( /*-----------------------------------------------------------------* * Allocate and initialize SCE/CPE and other handles *-----------------------------------------------------------------*/ - + test(); IF( EQ_16( ivas_format, MONO_FORMAT ) ) { st_ivas->nSCE = 1; /* in mono, there is always only one SCE */ @@ -1469,35 +1488,40 @@ ivas_error ivas_init_encoder_fx( ELSE IF( ivas_format == STEREO_FORMAT ) { st_ivas->nSCE = 0; + move16(); st_ivas->nCPE = 1; /* in stereo, there is always only one CPE */ + move16(); st_ivas->nchan_transport = CPE_CHANNELS; + move16(); cpe_id = 0; + move16(); - IF( ( error = create_cpe_enc( st_ivas, cpe_id, ivas_total_brate ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = create_cpe_enc( st_ivas, cpe_id, ivas_total_brate ) ), IVAS_ERR_OK ) ) { return error; } } - ELSE IF( ivas_format == ISM_FORMAT ) + ELSE IF( EQ_32( ivas_format, ISM_FORMAT ) ) { st_ivas->ism_mode = ivas_ism_mode_select( hEncoderConfig->nchan_inp, ivas_total_brate ); + move32(); - IF( ( error = ivas_ism_metadata_enc_create( st_ivas, hEncoderConfig->nchan_inp, element_brate_tmp ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_ism_metadata_enc_create( st_ivas, hEncoderConfig->nchan_inp, element_brate_tmp ) ), IVAS_ERR_OK ) ) { return error; } FOR( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ ) { - IF( ( error = create_sce_enc_fx( st_ivas, sce_id, element_brate_tmp[sce_id] ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = create_sce_enc_fx( st_ivas, sce_id, element_brate_tmp[sce_id] ) ), IVAS_ERR_OK ) ) { return error; } } - IF( st_ivas->ism_mode == ISM_MODE_PARAM ) + IF( EQ_32( st_ivas->ism_mode, ISM_MODE_PARAM ) ) { - IF( ( error = ivas_param_ism_enc_open( st_ivas ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_param_ism_enc_open( st_ivas ) ), IVAS_ERR_OK ) ) { return error; } @@ -1505,48 +1529,39 @@ ivas_error ivas_init_encoder_fx( IF( st_ivas->hEncoderConfig->Opt_DTX_ON ) { - IF( ( error = ivas_ism_dtx_open( st_ivas ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_ism_dtx_open( st_ivas ) ), IVAS_ERR_OK ) ) { return error; } } } - ELSE IF( ivas_format == SBA_FORMAT || ivas_format == MASA_FORMAT ) + ELSE IF( EQ_32( ivas_format, SBA_FORMAT ) || EQ_32( ivas_format, MASA_FORMAT ) ) { - IF( ( error = ivas_qmetadata_open( &( st_ivas->hQMetaData ) ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_qmetadata_open( &( st_ivas->hQMetaData ) ) ), IVAS_ERR_OK ) ) { return error; } - IF( ivas_format == SBA_FORMAT ) + IF( EQ_32( ivas_format, SBA_FORMAT ) ) { -#ifndef IVAS_FLOAT_FIXED - st_ivas->sba_analysis_order = ivas_sba_get_analysis_order( ivas_total_brate, st_ivas->hEncoderConfig->sba_order ); -#else st_ivas->sba_analysis_order = ivas_sba_get_analysis_order_fx( ivas_total_brate, st_ivas->hEncoderConfig->sba_order ); -#endif + move16(); - IF( ( error = ivas_spar_enc_open_fx( st_ivas, 0 ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_spar_enc_open_fx( st_ivas, 0 ) ), IVAS_ERR_OK ) ) { return error; } -#ifdef IVAS_FLOAT_FIXED IF( ( error = ivas_dirac_enc_open_fx( st_ivas ) ) != IVAS_ERR_OK ) { return error; } -#else - IF( ( error = ivas_dirac_enc_open( st_ivas ) ) != IVAS_ERR_OK ) - { - return error; - } -#endif } ELSE { st_ivas->nchan_transport = hEncoderConfig->nchan_inp; + move16(); - IF( ( error = ivas_masa_enc_open( st_ivas ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_masa_enc_open( st_ivas ) ), IVAS_ERR_OK ) ) { return error; } @@ -1554,20 +1569,25 @@ ivas_error ivas_init_encoder_fx( FOR( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ ) { - IF( ( error = create_sce_enc_fx( st_ivas, sce_id, ivas_total_brate / st_ivas->nchan_transport ) ) != IVAS_ERR_OK ) + Word32 res_dec, res_frac; + iDiv_and_mod_32( ivas_total_brate, st_ivas->nchan_transport, &res_dec, &res_frac, 0 ); + IF( NE_32( ( error = create_sce_enc_fx( st_ivas, sce_id, res_dec ) ), IVAS_ERR_OK ) ) { return error; } - + test(); IF( EQ_16( ivas_format, SBA_FORMAT ) && st_ivas->hEncoderConfig->Opt_DTX_ON ) { st_ivas->hSCE[sce_id]->hCoreCoder[0]->dtx_sce_sba = 1; + move16(); } } FOR( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) { - IF( ( error = create_cpe_enc_fx( st_ivas, cpe_id, ( ivas_total_brate / st_ivas->nchan_transport ) * CPE_CHANNELS ) ) != IVAS_ERR_OK ) + Word32 res_dec, res_frac; + iDiv_and_mod_32( ivas_total_brate, st_ivas->nchan_transport, &res_dec, &res_frac, 0 ); + IF( NE_32( ( error = create_cpe_enc_fx( st_ivas, cpe_id, imult3216( res_dec, CPE_CHANNELS ) ) ), IVAS_ERR_OK ) ) { return error; } @@ -1577,297 +1597,283 @@ ivas_error ivas_init_encoder_fx( IF( hEncoderConfig->Opt_DTX_ON ) { st_ivas->hCPE[cpe_id]->hCoreCoder[n]->cng_sba_flag = 1; + move16(); } } } - if ( st_ivas->nCPE > 1 ) + IF( st_ivas->nCPE > 1 ) { - if ( ( error = create_mct_enc( st_ivas ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = create_mct_enc( st_ivas ) ), IVAS_ERR_OK ) ) { return error; } } } - else if ( ivas_format == MASA_ISM_FORMAT ) + ELSE IF( EQ_32( ivas_format, MASA_ISM_FORMAT ) ) { - int32_t ism_total_brate; - int16_t k; + Word32 ism_total_brate; + Word16 k; -#ifndef IVAS_FLOAT_FIXED - st_ivas->ism_mode = ivas_omasa_ism_mode_select( ivas_total_brate, hEncoderConfig->nchan_ism ); -#else st_ivas->ism_mode = ivas_omasa_ism_mode_select_fx( ivas_total_brate, hEncoderConfig->nchan_ism ); move32(); -#endif st_ivas->nchan_transport = 2; + move16(); - if ( ( error = ivas_ism_metadata_enc_create( st_ivas, hEncoderConfig->nchan_ism, element_brate_tmp ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_ism_metadata_enc_create( st_ivas, hEncoderConfig->nchan_ism, element_brate_tmp ) ), IVAS_ERR_OK ) ) { return error; } k = 0; - while ( k < SIZE_IVAS_BRATE_TBL && ivas_total_brate != ivas_brate_tbl[k] ) + move16(); + test(); + WHILE( LT_16( k, SIZE_IVAS_BRATE_TBL ) && NE_32( ivas_total_brate, ivas_brate_tbl[k] ) ) { - k++; + k = add( k, 1 ); } ism_total_brate = 0; - for ( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ ) + move32(); + FOR( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ ) { - ism_total_brate += sep_object_brate[k - 2][st_ivas->nSCE - 1]; - if ( ( error = create_sce_enc_fx( st_ivas, sce_id, sep_object_brate[k - 2][st_ivas->nSCE - 1] ) ) != IVAS_ERR_OK ) + ism_total_brate = L_add( ism_total_brate, sep_object_brate[k - 2][st_ivas->nSCE - 1] ); + IF( NE_32( ( error = create_sce_enc_fx( st_ivas, sce_id, sep_object_brate[k - 2][st_ivas->nSCE - 1] ) ), IVAS_ERR_OK ) ) { return error; } } - if ( ( error = ivas_qmetadata_open( &( st_ivas->hQMetaData ) ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_qmetadata_open( &( st_ivas->hQMetaData ) ) ), IVAS_ERR_OK ) ) { return error; } - if ( ( error = ivas_masa_enc_open( st_ivas ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_masa_enc_open( st_ivas ) ), IVAS_ERR_OK ) ) { return error; } - if ( st_ivas->ism_mode != ISM_MASA_MODE_DISC ) + IF( NE_32( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) ) { - if ( ( error = ivas_omasa_enc_open_fx( st_ivas ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_omasa_enc_open_fx( st_ivas ) ), IVAS_ERR_OK ) ) { return error; } } - if ( ivas_total_brate - ism_total_brate >= MIN_BRATE_MDCT_STEREO ) + IF( GE_32( L_sub( ivas_total_brate, ism_total_brate ), MIN_BRATE_MDCT_STEREO ) ) { st_ivas->hEncoderConfig->element_mode_init = IVAS_CPE_MDCT; + move16(); } - else + ELSE { st_ivas->hEncoderConfig->element_mode_init = IVAS_CPE_DFT; + move16(); } - if ( ( error = create_cpe_enc( st_ivas, 0, ivas_total_brate - ism_total_brate ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = create_cpe_enc( st_ivas, 0, L_sub( ivas_total_brate, ism_total_brate ) ) ), IVAS_ERR_OK ) ) { return error; } } - else if ( ivas_format == SBA_ISM_FORMAT ) + ELSE IF( EQ_32( ivas_format, SBA_ISM_FORMAT ) ) { st_ivas->ism_mode = ISM_MODE_NONE; + move32(); - if ( ivas_total_brate >= IVAS_256k ) + IF( GE_32( ivas_total_brate, IVAS_256k ) ) { st_ivas->ism_mode = ISM_SBA_MODE_DISC; + move32(); } - if ( ( error = ivas_ism_metadata_enc_create( st_ivas, hEncoderConfig->nchan_ism, element_brate_tmp ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_ism_metadata_enc_create( st_ivas, hEncoderConfig->nchan_ism, element_brate_tmp ) ), IVAS_ERR_OK ) ) { return error; } /* allocate and initialize SBA handles */ - if ( ( error = ivas_qmetadata_open( &( st_ivas->hQMetaData ) ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_qmetadata_open( &( st_ivas->hQMetaData ) ) ), IVAS_ERR_OK ) ) { return error; } -#ifndef IVAS_FLOAT_FIXED - st_ivas->sba_analysis_order = ivas_sba_get_analysis_order( ivas_total_brate, st_ivas->hEncoderConfig->sba_order ); -#else st_ivas->sba_analysis_order = ivas_sba_get_analysis_order_fx( ivas_total_brate, st_ivas->hEncoderConfig->sba_order ); -#endif - if ( ( error = ivas_spar_enc_open_fx( st_ivas, 0 ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_spar_enc_open_fx( st_ivas, 0 ) ), IVAS_ERR_OK ) ) { return error; } -#ifdef IVAS_FLOAT_FIXED IF( ( error = ivas_dirac_enc_open_fx( st_ivas ) ) != IVAS_ERR_OK ) { return error; } -#else - if ( ( error = ivas_dirac_enc_open( st_ivas ) ) != IVAS_ERR_OK ) - { - return error; - } -#endif - if ( st_ivas->ism_mode == ISM_MODE_NONE ) + IF( EQ_32( st_ivas->ism_mode, ISM_MODE_NONE ) ) { /* allocate and initialize SBA core-coders */ - if ( st_ivas->nchan_transport == 1 ) + IF( EQ_16( st_ivas->nchan_transport, 1 ) ) { - if ( ( error = create_sce_enc_fx( st_ivas, 0, ivas_total_brate ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = create_sce_enc_fx( st_ivas, 0, ivas_total_brate ) ), IVAS_ERR_OK ) ) { return error; } } - for ( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) + FOR( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) { - if ( ( error = create_cpe_enc( st_ivas, cpe_id, ( ivas_total_brate / st_ivas->nchan_transport ) * CPE_CHANNELS ) ) != IVAS_ERR_OK ) + Word32 res_dec, res_frac; + iDiv_and_mod_32( ivas_total_brate, st_ivas->nchan_transport, &res_dec, &res_frac, 0 ); + IF( NE_32( ( error = create_cpe_enc( st_ivas, cpe_id, imult3216( res_dec, CPE_CHANNELS ) ) ), IVAS_ERR_OK ) ) { return error; } } - if ( st_ivas->nCPE > 1 ) + IF( GT_16( st_ivas->nCPE, 1 ) ) { - if ( ( error = create_mct_enc( st_ivas ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = create_mct_enc( st_ivas ) ), IVAS_ERR_OK ) ) { return error; } } } - else + ELSE { /* allocate and initialize MCT core coder */ - st_ivas->nCPE += ( st_ivas->hEncoderConfig->nchan_ism + 1 ) >> 1; + st_ivas->nCPE = add( st_ivas->nCPE, shr( add( st_ivas->hEncoderConfig->nchan_ism, 1 ), 1 ) ); - for ( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) + FOR( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) { - if ( ( error = create_cpe_enc( st_ivas, cpe_id, ( ivas_total_brate / st_ivas->nchan_transport ) * CPE_CHANNELS ) ) != IVAS_ERR_OK ) + Word32 res_dec, res_frac; + iDiv_and_mod_32( ivas_total_brate, st_ivas->nchan_transport, &res_dec, &res_frac, 0 ); + IF( NE_32( ( error = create_cpe_enc( st_ivas, cpe_id, imult3216( res_dec, CPE_CHANNELS ) ) ), IVAS_ERR_OK ) ) { return error; } } - if ( ( error = create_mct_enc( st_ivas ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = create_mct_enc( st_ivas ) ), IVAS_ERR_OK ) ) { return error; } } -#ifdef IVAS_FLOAT_FIXED - if ( ( error = ivas_osba_enc_open_fx( st_ivas ) ) != IVAS_ERR_OK ) - { - return error; - } -#else - if ( ( error = ivas_osba_enc_open( st_ivas ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_osba_enc_open_fx( st_ivas ) ), IVAS_ERR_OK ) ) { return error; } -#endif } - else if ( ivas_format == MC_FORMAT ) + ELSE IF( EQ_32( ivas_format, MC_FORMAT ) ) { -#ifndef IVAS_FLOAT_FIXED - st_ivas->mc_mode = ivas_mc_mode_select( hEncoderConfig->mc_input_setup, ivas_total_brate ); -#else st_ivas->mc_mode = ivas_mc_mode_select_fx( hEncoderConfig->mc_input_setup, ivas_total_brate ); -#endif + move32(); - if ( ( error = ivas_create_lfe_lpf_enc_fx( &st_ivas->hLfeLpf, hEncoderConfig->input_Fs ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_create_lfe_lpf_enc_fx( &st_ivas->hLfeLpf, hEncoderConfig->input_Fs ) ), IVAS_ERR_OK ) ) { return error; } - if ( st_ivas->mc_mode == MC_MODE_MCT ) + IF( NE_32( st_ivas->mc_mode, MC_MODE_MCT ) ) { st_ivas->nSCE = 0; - st_ivas->nCPE = hEncoderConfig->nchan_inp / CPE_CHANNELS; + move16(); + st_ivas->nCPE = idiv1616( hEncoderConfig->nchan_inp, CPE_CHANNELS ); + move16(); - for ( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) + FOR( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) { - if ( ( error = create_cpe_enc( st_ivas, cpe_id, ( ivas_total_brate / ( hEncoderConfig->nchan_inp - 1 ) * CPE_CHANNELS ) ) ) != IVAS_ERR_OK ) + Word32 res_dec, res_frac; + iDiv_and_mod_32( ivas_total_brate, sub( hEncoderConfig->nchan_inp, 1 ), &res_dec, &res_frac, 0 ); + IF( NE_32( ( error = create_cpe_enc( st_ivas, cpe_id, imult3216( res_dec, CPE_CHANNELS ) ) ), IVAS_ERR_OK ) ) { return error; } } - if ( ( error = create_mct_enc( st_ivas ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = create_mct_enc( st_ivas ) ), IVAS_ERR_OK ) ) { return error; } - if ( ( error = ivas_create_lfe_enc( &st_ivas->hLFE, input_Fs ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_create_lfe_enc( &st_ivas->hLFE, input_Fs ) ), IVAS_ERR_OK ) ) { return error; } -#ifndef IVAS_FLOAT_FIXED - st_ivas->nchan_transport = ivas_mc_ls_setup_get_num_channels( st_ivas->hEncoderConfig->mc_input_setup ); -#else st_ivas->nchan_transport = ivas_mc_ls_setup_get_num_channels_fx( st_ivas->hEncoderConfig->mc_input_setup ); -#endif + move16(); } - else if ( st_ivas->mc_mode == MC_MODE_PARAMUPMIX ) + ELSE IF( EQ_32( st_ivas->mc_mode, MC_MODE_PARAMUPMIX ) ) { st_ivas->nSCE = 0; - st_ivas->nCPE = MC_PARAMUPMIX_MAX_TRANSPORT_CHANS / 2; + move16(); + st_ivas->nCPE = MC_PARAMUPMIX_MAX_TRANSPORT_CHANS >> 1; + move16(); st_ivas->nchan_transport = MC_PARAMUPMIX_MAX_TRANSPORT_CHANS; + move16(); - if ( ( error = ivas_mc_paramupmix_enc_open( st_ivas ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_mc_paramupmix_enc_open( st_ivas ) ), IVAS_ERR_OK ) ) { return error; } - for ( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) + FOR( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) { - if ( ( error = create_cpe_enc( st_ivas, cpe_id, ( ivas_total_brate / st_ivas->nCPE ) ) ) != IVAS_ERR_OK ) + Word32 res_dec, res_frac; + iDiv_and_mod_32( ivas_total_brate, st_ivas->nCPE, &res_dec, &res_frac, 0 ); + IF( NE_32( ( error = create_cpe_enc( st_ivas, cpe_id, res_dec ) ), IVAS_ERR_OK ) ) { return error; } } - if ( ( error = create_mct_enc( st_ivas ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = create_mct_enc( st_ivas ) ), IVAS_ERR_OK ) ) { return error; } - if ( ( error = ivas_create_lfe_enc( &st_ivas->hLFE, input_Fs ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_create_lfe_enc( &st_ivas->hLFE, input_Fs ) ), IVAS_ERR_OK ) ) { return error; } } - else if ( st_ivas->mc_mode == MC_MODE_PARAMMC ) + ELSE IF( st_ivas->mc_mode == MC_MODE_PARAMMC ) { -#ifdef IVAS_FLOAT_FIXED - if ( ( error = ivas_param_mc_enc_open_fx( st_ivas ) ) != IVAS_ERR_OK ) -#else - if ( ( error = ivas_param_mc_enc_open( st_ivas ) ) != IVAS_ERR_OK ) -#endif + IF( NE_32( ( error = ivas_param_mc_enc_open_fx( st_ivas ) ), IVAS_ERR_OK ) ) { return error; } - for ( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) + FOR( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) { - if ( ( error = create_cpe_enc( st_ivas, cpe_id, ivas_total_brate / ( st_ivas->nCPE + st_ivas->nSCE ) ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = create_cpe_enc( st_ivas, cpe_id, ivas_total_brate / ( st_ivas->nCPE + st_ivas->nSCE ) ) ), IVAS_ERR_OK ) ) { return error; } } - if ( st_ivas->nCPE > 1 ) + IF( GT_16( st_ivas->nCPE, 1 ) ) { - if ( ( error = create_mct_enc( st_ivas ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = create_mct_enc( st_ivas ) ), IVAS_ERR_OK ) ) { return error; } } } - else if ( st_ivas->mc_mode == MC_MODE_MCMASA ) + ELSE IF( EQ_32( st_ivas->mc_mode, MC_MODE_MCMASA ) ) { - int32_t brate_sce, brate_cpe; + Word32 brate_sce, brate_cpe; -#ifndef IVAS_FLOAT_FIXED - ivas_mcmasa_setNumTransportChannels( &( st_ivas->nchan_transport ), &( hEncoderConfig->element_mode_init ), ivas_total_brate ); -#else ivas_mcmasa_setNumTransportChannels_fx( &( st_ivas->nchan_transport ), &( hEncoderConfig->element_mode_init ), ivas_total_brate ); -#endif - if ( ( error = ivas_qmetadata_open( &( st_ivas->hQMetaData ) ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_qmetadata_open( &( st_ivas->hQMetaData ) ) ), IVAS_ERR_OK ) ) { return error; } - if ( ( error = ivas_masa_enc_open( st_ivas ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_masa_enc_open( st_ivas ) ), IVAS_ERR_OK ) ) { return error; } @@ -1878,31 +1884,27 @@ ivas_error ivas_init_encoder_fx( return error; } #else - if ( ( error = ivas_mcmasa_enc_open_fx( st_ivas ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_mcmasa_enc_open_fx( st_ivas ) ), IVAS_ERR_OK ) ) { return error; } #endif - -#ifndef IVAS_FLOAT_FIXED - ivas_mcmasa_split_brate( st_ivas->hMcMasa->separateChannelEnabled, ivas_total_brate, st_ivas->nSCE, st_ivas->nCPE, &brate_sce, &brate_cpe ); -#else ivas_mcmasa_split_brate_fx( st_ivas->hMcMasa->separateChannelEnabled, ivas_total_brate, st_ivas->nSCE, st_ivas->nCPE, &brate_sce, &brate_cpe ); -#endif - for ( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ ) + FOR( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ ) { - if ( ( error = create_sce_enc_fx( st_ivas, sce_id, brate_sce ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = create_sce_enc_fx( st_ivas, sce_id, brate_sce ) ), IVAS_ERR_OK ) ) { return error; } } - for ( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) + FOR( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) { hEncoderConfig->element_mode_init = IVAS_CPE_MDCT; + move16(); - if ( ( error = create_cpe_enc( st_ivas, cpe_id, brate_cpe ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = create_cpe_enc( st_ivas, cpe_id, brate_cpe ) ), IVAS_ERR_OK ) ) { return error; } @@ -1916,30 +1918,6 @@ ivas_error ivas_init_encoder_fx( /* set number of input channels used for analysis/coding */ n = getNumChanAnalysis_fx( st_ivas ); -#if 1 // To be removed - if ( n > 0 ) - { - if ( ( st_ivas->mem_hp20_in = (float **) malloc( n * sizeof( float * ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HP20 filter memory\n" ) ); - } - } - else - { - st_ivas->mem_hp20_in = NULL; - } - - for ( i = 0; i < n; i++ ) - { - if ( ( st_ivas->mem_hp20_in[i] = (float *) malloc( L_HP20_MEM * sizeof( float ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HP20 filter memory\n" ) ); - } - - set_f( st_ivas->mem_hp20_in[i], 0.0f, L_HP20_MEM ); - } -#endif - /*Fixed point init*/ IF( n > 0 ) { IF( ( st_ivas->mem_hp20_in_fx = (Word32 **) malloc( n * sizeof( Word32 * ) ) ) == NULL ) @@ -2156,7 +2134,7 @@ void ivas_destroy_enc( } /* HP20 filter handles */ - if ( st_ivas->mem_hp20_in != NULL ) + if ( st_ivas->mem_hp20_in_fx != NULL ) { n = getNumChanAnalysis_fx( st_ivas ); @@ -2168,6 +2146,7 @@ void ivas_destroy_enc( free( st_ivas->mem_hp20_in_fx ); st_ivas->mem_hp20_in_fx = NULL; } +#ifndef IVAS_FLOAT_FIXED if ( st_ivas->mem_hp20_in != NULL ) { n = getNumChanAnalysis_fx( st_ivas ); @@ -2180,6 +2159,7 @@ void ivas_destroy_enc( free( st_ivas->mem_hp20_in ); st_ivas->mem_hp20_in = NULL; } +#endif /* ISM metadata handles */ ivas_ism_metadata_close( st_ivas->hIsmMetaData, 0 ); diff --git a/lib_enc/ivas_ism_dtx_enc.c b/lib_enc/ivas_ism_dtx_enc.c index c1947034d..5b90cb9f8 100644 --- a/lib_enc/ivas_ism_dtx_enc.c +++ b/lib_enc/ivas_ism_dtx_enc.c @@ -69,26 +69,30 @@ ivas_error ivas_ism_dtx_open( { ivas_error error; ISM_DTX_HANDLE hISMDTX; - int16_t i; + Word16 i; error = IVAS_ERR_OK; + move32(); /* Assign memory to DirAC handle */ - if ( ( hISMDTX = (ISM_DTX_HANDLE) malloc( sizeof( ISM_DTX_DATA ) ) ) == NULL ) + IF( ( hISMDTX = (ISM_DTX_HANDLE) malloc( sizeof( ISM_DTX_DATA ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for ISM DTX Handle \n" ) ); } hISMDTX->dtx_flag = 0; + move16(); hISMDTX->sce_id_dtx = 0; + move16(); hISMDTX->cnt_SID_ISM = -1; + move16(); - for ( i = 0; i < MAX_NUM_OBJECTS; i++ ) + FOR( i = 0; i < MAX_NUM_OBJECTS; i++ ) { - set_f( hISMDTX->long_term_energy_stereo_dmx_enc[i], 0.0f, PARAM_ISM_HYS_BUF_SIZE ); + set32_fx( hISMDTX->long_term_energy_stereo_dmx_enc_fx[i], 0, PARAM_ISM_HYS_BUF_SIZE ); } - set_f( hISMDTX->coh, 0.0f, MAX_NUM_OBJECTS ); + set16_fx( hISMDTX->coh_fx, 0, MAX_NUM_OBJECTS ); st_ivas->hISMDTX = hISMDTX; diff --git a/lib_enc/ivas_ism_metadata_enc.c b/lib_enc/ivas_ism_metadata_enc.c index 982b35550..64f64b721 100644 --- a/lib_enc/ivas_ism_metadata_enc.c +++ b/lib_enc/ivas_ism_metadata_enc.c @@ -1518,7 +1518,7 @@ ivas_error ivas_ism_metadata_enc( #ifdef IVAS_FLOAT_FIXED ivas_error ivas_ism_metadata_enc_create( Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ - const int16_t n_ISms, /* i : number of objects */ + const Word16 n_ISms, /* i : number of objects */ Word32 element_brate_tmp[] /* o : element bitrate per object */ ) { @@ -1527,27 +1527,25 @@ ivas_error ivas_ism_metadata_enc_create( nchan_transport = st_ivas->nchan_transport; move16(); - IF( st_ivas->hEncoderConfig->ivas_format == MASA_ISM_FORMAT ) + IF( EQ_32( st_ivas->hEncoderConfig->ivas_format, MASA_ISM_FORMAT ) ) { nchan_transport = MAX_PARAM_ISM_WAVE; -#ifndef IVAS_FLOAT_FIXED - ivas_set_omasa_TC( st_ivas->ism_mode, n_ISms, &st_ivas->nSCE, &st_ivas->nCPE ); -#else + move16(); ivas_set_omasa_TC_fx( st_ivas->ism_mode, n_ISms, &st_ivas->nSCE, &st_ivas->nCPE ); -#endif } - ELSE IF( st_ivas->hEncoderConfig->ivas_format == SBA_ISM_FORMAT ) + ELSE IF( EQ_32( st_ivas->hEncoderConfig->ivas_format, SBA_ISM_FORMAT ) ) { nchan_transport = n_ISms; + move16(); } ELSE { - IF( st_ivas->ism_mode == ISM_MODE_NONE ) + IF( EQ_32( st_ivas->ism_mode, ISM_MODE_NONE ) ) { nchan_transport = st_ivas->nchan_transport; move16(); - IF( nchan_transport == 1 ) + IF( EQ_16( nchan_transport, 1 ) ) { st_ivas->nSCE = 1; move16(); @@ -1562,7 +1560,7 @@ ivas_error ivas_ism_metadata_enc_create( move16(); } } - ELSE IF( st_ivas->ism_mode == ISM_MODE_PARAM ) + ELSE IF( EQ_32( st_ivas->ism_mode, ISM_MODE_PARAM ) ) { nchan_transport = 2; move16(); @@ -1623,37 +1621,39 @@ ivas_error ivas_ism_metadata_enc_create( st_ivas->hIsmMetaData[ch]->q_elevation_old_fx = 0; move16(); -#ifdef IVAS_FLOAT_FIXED ivas_ism_reset_metadata_enc( st_ivas->hIsmMetaData[ch] ); -#else - ivas_ism_reset_metadata( st_ivas->hIsmMetaData[ch] ); -#endif - st_ivas->hIsmMetaData[ch]->last_azimuth_fx = 0; + move32(); st_ivas->hIsmMetaData[ch]->last_elevation_fx = 0; + move32(); st_ivas->hIsmMetaData[ch]->last_true_azimuth_fx = 0; + move32(); st_ivas->hIsmMetaData[ch]->last_true_elevation_fx = 0; + move32(); st_ivas->hIsmMetaData[ch]->ism_md_fec_cnt_enc = 0; + move16(); st_ivas->hIsmMetaData[ch]->ism_md_inc_diff_cnt = ISM_MD_INC_DIFF_CNT_MAX; + move16(); st_ivas->hIsmMetaData[ch]->last_true_radius_fx = ONE_IN_Q9; + move16(); } IF( EQ_16( st_ivas->hEncoderConfig->ivas_format, MASA_ISM_FORMAT ) ) { test(); - IF( st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ ) + IF( EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) || EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) ) { - IF( ( error = ivas_ism_config_fx( st_ivas->hEncoderConfig->ivas_total_brate, nchan_transport, 1, NULL, 0, NULL, NULL, element_brate_tmp, NULL, NULL, 1 ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_ism_config_fx( st_ivas->hEncoderConfig->ivas_total_brate, nchan_transport, 1, NULL, 0, NULL, NULL, element_brate_tmp, NULL, NULL, 1 ) ), IVAS_ERR_OK ) ) { return error; } } ELSE IF( EQ_16( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) ) { - IF( ( error = ivas_ism_config_fx( st_ivas->hEncoderConfig->ivas_total_brate, nchan_transport, n_ISms, NULL, 0, NULL, NULL, element_brate_tmp, NULL, NULL, 1 ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_ism_config_fx( st_ivas->hEncoderConfig->ivas_total_brate, nchan_transport, n_ISms, NULL, 0, NULL, NULL, element_brate_tmp, NULL, NULL, 1 ) ), IVAS_ERR_OK ) ) { return error; } @@ -1661,7 +1661,7 @@ ivas_error ivas_ism_metadata_enc_create( } ELSE { - IF( ( error = ivas_ism_config_fx( st_ivas->hEncoderConfig->ivas_total_brate, nchan_transport, n_ISms, NULL, 0, NULL, NULL, element_brate_tmp, NULL, NULL, 0 ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_ism_config_fx( st_ivas->hEncoderConfig->ivas_total_brate, nchan_transport, n_ISms, NULL, 0, NULL, NULL, element_brate_tmp, NULL, NULL, 0 ) ), IVAS_ERR_OK ) ) { return error; } diff --git a/lib_enc/ivas_masa_enc.c b/lib_enc/ivas_masa_enc.c index 9b975d935..63354efd4 100644 --- a/lib_enc/ivas_masa_enc.c +++ b/lib_enc/ivas_masa_enc.c @@ -2254,10 +2254,10 @@ ivas_error ivas_masa_enc_config( * Determine if surrounding coherence is significant in this frame and should be encoded *-----------------------------------------------------------------------*/ UWord8 ivas_masa_surrcoh_signicant_fx( - Word32 surroundingCoherence[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /* i : Surround coherence */ - Word32 diffuse_to_total_ratio[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /* i : Diffuse to total ratio */ - const Word16 nSubFrames, /* i : Number of sub frames */ - const Word16 nBands /* i : Number of frequency bands */ /* i : dynamic (min q for surroundingCoherence and diffuse_to_total_ratio) */ + Word32 surroundingCoherence[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /* i : Surround coherence Q31 */ + Word32 diffuse_to_total_ratio[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /* i : Diffuse to total ratio Q31 */ + const Word16 nSubFrames, /* i : Number of sub frames */ + const Word16 nBands /* i : Number of frequency bands */ ) { Word32 significanceMeasure1, significanceMeasure2, significanceMeasure; @@ -2287,17 +2287,17 @@ UWord8 ivas_masa_surrcoh_signicant_fx( FOR( band = 0; band < nBands; band++ ) { - surrCohToTotal = Mpy_32_32( diffuse_to_total_ratio[sf][band], surroundingCoherence[sf][band] ); // 2Q -> Q + surrCohToTotal = Mpy_32_32( diffuse_to_total_ratio[sf][band], surroundingCoherence[sf][band] ); // Q31 surrCohToTotalSum = BASOP_Util_Add_Mant32Exp( surrCohToTotalSum, surrCohToTotalSum_e, surrCohToTotal, 0, &surrCohToTotalSum_e ); - surrCohToTotalTimesDiffSum = BASOP_Util_Add_Mant32Exp( surrCohToTotalTimesDiffSum, surrCohToTotalTimesDiffSum_e, Mpy_32_32( (Word32) diffuse_to_total_ratio[sf][band], surrCohToTotal ), 0, &surrCohToTotalTimesDiffSum_e ); // Q2 -> Q - diffSum = BASOP_Util_Add_Mant32Exp( diffSum, diffSum_e, diffuse_to_total_ratio[sf][band], 0, &diffSum_e ); // Q + surrCohToTotalTimesDiffSum = BASOP_Util_Add_Mant32Exp( surrCohToTotalTimesDiffSum, surrCohToTotalTimesDiffSum_e, Mpy_32_32( (Word32) diffuse_to_total_ratio[sf][band], surrCohToTotal ), 0, &surrCohToTotalTimesDiffSum_e ); + diffSum = BASOP_Util_Add_Mant32Exp( diffSum, diffSum_e, diffuse_to_total_ratio[sf][band], 0, &diffSum_e ); } Word16 significanceMeasure1_e, significanceMeasure2_e; Word16 significanceMeasure_e; - significanceMeasure1 = L_deposit_h( BASOP_Util_Divide3216_Scale( surrCohToTotalSum, nBands, &significanceMeasure1_e ) ); // e1 exponent + significanceMeasure1 = L_deposit_h( BASOP_Util_Divide3216_Scale( surrCohToTotalSum, nBands, &significanceMeasure1_e ) ); significanceMeasure1_e = add( significanceMeasure1_e, sub( surrCohToTotalSum_e, 15 ) ); - significanceMeasure2 = L_deposit_h( BASOP_Util_Divide3232_Scale( Mpy_32_32( surrCohSignificanceCoef, surrCohToTotalTimesDiffSum ), L_add( diffSum, EPSILON_FX ), &significanceMeasure2_e ) ); // e2 exponent + significanceMeasure2 = L_deposit_h( BASOP_Util_Divide3232_Scale( Mpy_32_32( surrCohSignificanceCoef, surrCohToTotalTimesDiffSum ), L_add( diffSum, EPSILON_FX ), &significanceMeasure2_e ) ); significanceMeasure2_e = add( significanceMeasure2_e, sub( surrCohToTotalTimesDiffSum_e, diffSum_e ) ); IF( BASOP_Util_Cmp_Mant32Exp( significanceMeasure1, significanceMeasure1_e, significanceMeasure2, significanceMeasure2_e ) > 0 ) @@ -2314,7 +2314,7 @@ UWord8 ivas_masa_surrcoh_signicant_fx( significanceMeasure_e = significanceMeasure2_e; move16(); } - IF( BASOP_Util_Cmp_Mant32Exp( significanceMeasure, significanceMeasure_e, threshold, 0 ) > 0 ) // Q31 Comparision + IF( BASOP_Util_Cmp_Mant32Exp( significanceMeasure, significanceMeasure_e, threshold, 0 ) > 0 ) { return 1; } @@ -8903,9 +8903,9 @@ static void ivas_encode_masaism_metadata_fx( *-------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED void ivas_merge_masa_transports_fx( - Word32 data_in_f1_fx[][L_FRAME48k], - Word32 *data_in_f2_fx[], - Word32 *data_out_f_fx[], + Word32 data_in_f1_fx[][L_FRAME48k], // Qx + Word32 *data_in_f2_fx[], // Qx + Word32 *data_out_f_fx[], // Qx const Word16 input_frame, const Word16 num_transport_channels ) { diff --git a/lib_enc/ivas_mc_paramupmix_enc.c b/lib_enc/ivas_mc_paramupmix_enc.c index 7e4902855..d26e6bee4 100644 --- a/lib_enc/ivas_mc_paramupmix_enc.c +++ b/lib_enc/ivas_mc_paramupmix_enc.c @@ -258,7 +258,7 @@ ivas_error ivas_mc_paramupmix_enc_open( /* Transient Detector handle */ FOR( i = 0; i < MC_PARAMUPMIX_COMBINATIONS * MC_PARAMUPMIX_NCH; i++ ) { - IF( ( error = ivas_transient_det_open( &( hMCParamUpmix->hTranDet[i] ), input_Fs ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_transient_det_open_fx( &( hMCParamUpmix->hTranDet[i] ), input_Fs ) ) != IVAS_ERR_OK ) { return error; } @@ -600,7 +600,7 @@ void ivas_mc_paramupmix_enc_close( FOR( i = 0; i < MC_PARAMUPMIX_COMBINATIONS * MC_PARAMUPMIX_NCH; i++ ) { - ivas_transient_det_close( &( *hMCParamUpmix )->hTranDet[i] ); + ivas_transient_det_close_fx( &( *hMCParamUpmix )->hTranDet[i] ); } IF( ( *hMCParamUpmix )->hFbMixer != NULL ) diff --git a/lib_enc/ivas_mcmasa_enc.c b/lib_enc/ivas_mcmasa_enc.c index 57de41384..c38bd5ec6 100644 --- a/lib_enc/ivas_mcmasa_enc.c +++ b/lib_enc/ivas_mcmasa_enc.c @@ -190,7 +190,6 @@ ivas_error ivas_mcmasa_enc_open_fx( Word16 maxBin, input_frame; Word16 nchan_inp; Word32 input_Fs; - Word32 dirac_slot_ns; IVAS_FB_CFG *fb_cfg, *fb_cfgLfe; ivas_error error; @@ -370,8 +369,7 @@ ivas_error ivas_mcmasa_enc_open_fx( } - dirac_slot_ns = DIRAC_SLOT_ENC_NS; - move32(); + /*dirac_slot_ns = DIRAC_SLOT_ENC_NS;*/ /* intensity 3-dim */ FOR( i = 0; i < DIRAC_NUM_DIMS; i++ ) @@ -406,7 +404,7 @@ ivas_error ivas_mcmasa_enc_open_fx( } } - hMcMasa->no_col_avg_diff = (Word8) ( DIRAC_NO_COL_AVG_DIFF_NS / dirac_slot_ns ); + hMcMasa->no_col_avg_diff = (Word8) ( DIRAC_NO_COL_AVG_DIFF_NS / DIRAC_SLOT_ENC_NS ); /* dirac_slot_ns = DIRAC_SLOT_ENC_NS */ move16(); FOR( i = 0; i < DIRAC_NUM_DIMS; i++ ) @@ -445,41 +443,41 @@ ivas_error ivas_mcmasa_enc_open_fx( { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for McMasa\n" ) ); } - set_zero_fx( hMcMasa->buffer_energy_fx, hMcMasa->nbands * hMcMasa->no_col_avg_diff ); + set_zero_fx( hMcMasa->buffer_energy_fx, imult1616( hMcMasa->nbands, hMcMasa->no_col_avg_diff ) ); set16_fx( hMcMasa->buffer_intensity_real_vert_q, 31, DIRAC_NO_COL_AVG_DIFF ); set16_fx( hMcMasa->buffer_energy_q, 31, DIRAC_NO_COL_AVG_DIFF ); - IF( st_ivas->hEncoderConfig->mc_input_setup == MC_LS_SETUP_5_1 ) + IF( EQ_32( st_ivas->hEncoderConfig->mc_input_setup, MC_LS_SETUP_5_1 ) ) { - Copy32( ls_azimuth_CICP6_fx, ls_azimuth, nchan_inp - 1 ); - Copy32( ls_elevation_CICP6_fx, ls_elevation, nchan_inp - 1 ); + Copy32( ls_azimuth_CICP6_fx, ls_azimuth, sub( nchan_inp, 1 ) ); + Copy32( ls_elevation_CICP6_fx, ls_elevation, sub( nchan_inp, 1 ) ); hMcMasa->numHorizontalChannels = 5; move16(); hMcMasa->isHorizontalSetup = 1; move16(); } - ELSE IF( st_ivas->hEncoderConfig->mc_input_setup == MC_LS_SETUP_7_1 ) + ELSE IF( EQ_32( st_ivas->hEncoderConfig->mc_input_setup, MC_LS_SETUP_7_1 ) ) { - Copy32( ls_azimuth_CICP12_fx, ls_azimuth, nchan_inp - 1 ); - Copy32( ls_elevation_CICP12_fx, ls_elevation, nchan_inp - 1 ); + Copy32( ls_azimuth_CICP12_fx, ls_azimuth, sub( nchan_inp, 1 ) ); + Copy32( ls_elevation_CICP12_fx, ls_elevation, sub( nchan_inp, 1 ) ); hMcMasa->numHorizontalChannels = 7; move16(); hMcMasa->isHorizontalSetup = 1; move16(); } - ELSE IF( st_ivas->hEncoderConfig->mc_input_setup == MC_LS_SETUP_5_1_2 ) + ELSE IF( EQ_32( st_ivas->hEncoderConfig->mc_input_setup, MC_LS_SETUP_5_1_2 ) ) { - Copy32( ls_azimuth_CICP14_fx, ls_azimuth, nchan_inp - 1 ); - Copy32( ls_elevation_CICP14_fx, ls_elevation, nchan_inp - 1 ); + Copy32( ls_azimuth_CICP14_fx, ls_azimuth, sub( nchan_inp, 1 ) ); + Copy32( ls_elevation_CICP14_fx, ls_elevation, sub( nchan_inp, 1 ) ); hMcMasa->numHorizontalChannels = 5; move16(); hMcMasa->isHorizontalSetup = 0; move16(); } - ELSE IF( st_ivas->hEncoderConfig->mc_input_setup == MC_LS_SETUP_5_1_4 ) + ELSE IF( EQ_32( st_ivas->hEncoderConfig->mc_input_setup, MC_LS_SETUP_5_1_4 ) ) { - Copy32( ls_azimuth_CICP16_fx, ls_azimuth, nchan_inp - 1 ); - Copy32( ls_elevation_CICP16_fx, ls_elevation, nchan_inp - 1 ); + Copy32( ls_azimuth_CICP16_fx, ls_azimuth, sub( nchan_inp, 1 ) ); + Copy32( ls_elevation_CICP16_fx, ls_elevation, sub( nchan_inp, 1 ) ); hMcMasa->numHorizontalChannels = 5; move16(); hMcMasa->isHorizontalSetup = 0; @@ -487,8 +485,8 @@ ivas_error ivas_mcmasa_enc_open_fx( } ELSE { - Copy32( ls_azimuth_CICP19_fx, ls_azimuth, nchan_inp - 1 ); - Copy32( ls_elevation_CICP19_fx, ls_elevation, nchan_inp - 1 ); + Copy32( ls_azimuth_CICP19_fx, ls_azimuth, sub( nchan_inp, 1 ) ); + Copy32( ls_elevation_CICP19_fx, ls_elevation, sub( nchan_inp, 1 ) ); hMcMasa->numHorizontalChannels = 7; move16(); hMcMasa->isHorizontalSetup = 0; @@ -506,23 +504,23 @@ ivas_error ivas_mcmasa_enc_open_fx( computeEvenLayout_fx( ls_azimuth, ls_azimuth_even, hMcMasa->numHorizontalChannels ); IF( !hMcMasa->isHorizontalSetup ) { - computeEvenLayout_fx( &ls_azimuth[hMcMasa->numHorizontalChannels], &ls_azimuth_even[hMcMasa->numHorizontalChannels], numAnalysisChannels - hMcMasa->numHorizontalChannels ); + computeEvenLayout_fx( &ls_azimuth[hMcMasa->numHorizontalChannels], &ls_azimuth_even[hMcMasa->numHorizontalChannels], sub( numAnalysisChannels, hMcMasa->numHorizontalChannels ) ); } FOR( i = 0; i < numAnalysisChannels; i++ ) { hMcMasa->chnlToFoaMtx_fx[0][i] = ONE_IN_Q31; move32(); - hMcMasa->chnlToFoaMtx_fx[1][i] = L_mult( getSineWord16R2( extract_l( L_shr( Mult_32_16( ls_azimuth[i], 91 /*32767/360*/ ), 7 ) ) ), getCosWord16R2( extract_l( L_shr( Mult_32_16( ls_elevation[i], 91 ), 7 ) ) ) ); + hMcMasa->chnlToFoaMtx_fx[1][i] = L_mult( getSineWord16R2( extract_l( L_shr( Mult_32_16( ls_azimuth[i], 91 /*32767/360*/ ), 7 ) ) ), getCosWord16R2( extract_l( L_shr( Mult_32_16( ls_elevation[i], 91 ), 7 ) ) ) ); // Q31 move32(); - hMcMasa->chnlToFoaMtx_fx[2][i] = L_shl( getSineWord16R2( extract_l( L_shr( Mult_32_16( ls_elevation[i], 91 ), 7 ) ) ), 16 ); + hMcMasa->chnlToFoaMtx_fx[2][i] = L_shl( getSineWord16R2( extract_l( L_shr( Mult_32_16( ls_elevation[i], 91 ), 7 ) ) ), 16 ); // Q31 move32(); - hMcMasa->chnlToFoaMtx_fx[3][i] = L_mult( getCosWord16R2( extract_l( L_shr( Mult_32_16( ls_azimuth[i], 91 ), 7 ) ) ), getCosWord16R2( extract_l( L_shr( Mult_32_16( ls_elevation[i], 91 ), 7 ) ) ) ); + hMcMasa->chnlToFoaMtx_fx[3][i] = L_mult( getCosWord16R2( extract_l( L_shr( Mult_32_16( ls_azimuth[i], 91 ), 7 ) ) ), getCosWord16R2( extract_l( L_shr( Mult_32_16( ls_elevation[i], 91 ), 7 ) ) ) ); // Q31 move32(); hMcMasa->chnlToFoaEvenMtx_fx[0][i] = ONE_IN_Q31; move32(); - hMcMasa->chnlToFoaEvenMtx_fx[1][i] = L_shl( getSineWord16R2( extract_l( L_shr( Mult_32_16( ls_azimuth_even[i], 91 ), 7 ) ) ), 16 ); + hMcMasa->chnlToFoaEvenMtx_fx[1][i] = L_shl( getSineWord16R2( extract_l( L_shr( Mult_32_16( ls_azimuth_even[i], 91 ), 7 ) ) ), 16 ); // Q31 move32(); hMcMasa->chnlToFoaEvenMtx_fx[2][i] = 0; move32(); @@ -1215,11 +1213,11 @@ void ivas_mcmasa_enc_fx( MCMASA_ENC_HANDLE hMcMasa, /* i/o: Encoder McMASA handle */ IVAS_QMETADATA_HANDLE hQMeta, /* o : Qmetadata handle */ MASA_ENCODER_HANDLE hMasa, /* i/o: Encoder MASA handle */ - Word32 *data_fx[], /* i : Input frame of audio */ + Word32 *data_fx[], /* i : Input frame of audio Q(q_inp) */ const Word16 input_frame, /* i : Input frame size */ const Word16 nchan_transport, /* i : Number of transport channels */ const Word16 nchan_inp, /* i : Number of input channels */ - const Word16 q_inp /* i : Input data q-format */ + const Word16 q_inp /* i : Input data q-format */ ) { Word16 i, j, k; @@ -1270,6 +1268,8 @@ void ivas_mcmasa_enc_fx( { hMasa->data.lfeToTotalEnergyRatio_fx[i] = BASOP_Util_Divide3232_Scale( hMcMasa->lfeLfEne[i], L_add( EPSILON_FX, hMcMasa->totalLfEne[i] ), &hMasa->data.lfeToTotalEnergyRatio_e[i] ); hMasa->data.lfeToTotalEnergyRatio_e[i] = add( sub( hMcMasa->lfeLfEne_e[i], hMcMasa->totalLfEne_e[i] ), hMasa->data.lfeToTotalEnergyRatio_e[i] ); + move32(); + move16(); } /* Set analyzed values to the MASA struct */ @@ -1299,8 +1299,10 @@ void ivas_mcmasa_enc_fx( IF( hQMeta->surcoh_band_data != NULL ) { - hQMeta->q_direction[0].coherence_band_data[i].spread_coherence[j] = (uint8_t) round_fx( Mpy_32_32( spreadCoherence_fx[j][i], L_shl( UINT8_MAX, Q16 ) ) ); - hQMeta->surcoh_band_data[i].surround_coherence[j] = (uint8_t) round_fx( Mpy_32_32( surroundingCoherence_fx[k][i], L_shl( UINT8_MAX, Q16 ) ) ); + hQMeta->q_direction[0].coherence_band_data[i].spread_coherence[j] = (UWord8) round_fx( Mpy_32_32( spreadCoherence_fx[j][i], L_shl( UINT8_MAX, Q16 ) ) ); // Q0 + hQMeta->surcoh_band_data[i].surround_coherence[j] = (UWord8) round_fx( Mpy_32_32( surroundingCoherence_fx[k][i], L_shl( UINT8_MAX, Q16 ) ) ); // Q0 + move16(); + move16(); } } } @@ -1333,7 +1335,7 @@ void ivas_mcmasa_enc_fx( } /* Downmix */ - ivas_mcmasa_dmx_fx( hMcMasa, data_fx, 31 - q_inp, input_frame, nchan_transport, nchan_inp ); + ivas_mcmasa_dmx_fx( hMcMasa, data_fx, sub( 31, q_inp ), input_frame, nchan_transport, nchan_inp ); IF( hMcMasa->separateChannelEnabled ) { @@ -1344,11 +1346,13 @@ void ivas_mcmasa_enc_fx( /* Update mcMASA-relevant coding parameters */ /* These are reset to default values as they may be modified during later processing. */ hMasa->config.joinedSubframes = FALSE; + move16(); hQMeta->q_direction[0].cfg.nbands = hMcMasa->nbands; move16(); hQMeta->q_direction[0].cfg.nblocks = MAX_PARAM_SPATIAL_SUBFRAMES; move16(); hQMeta->all_coherence_zero = 1; + move16(); /* Check spread coherence */ i = 0; @@ -1356,11 +1360,13 @@ void ivas_mcmasa_enc_fx( test(); WHILE( LT_16( i, nBlocks ) && hQMeta->all_coherence_zero ) { + test(); j = 0; move16(); test(); WHILE( LT_16( j, nBands ) && hQMeta->all_coherence_zero ) { + test(); IF( GT_32( spreadCoherence_fx[i][j], MASA_COHERENCE_THRESHOLD_FX ) ) { hQMeta->all_coherence_zero = 0; @@ -1393,7 +1399,7 @@ void ivas_mcmasa_enc_fx( { FOR( j = 0; j < nBands; j++ ) { - diffuse_to_total_ratio_fx[i][j] = L_max( 0, L_sub( ONE_IN_Q31, energyRatio_fx[i][j] ) ); + diffuse_to_total_ratio_fx[i][j] = L_max( 0, L_sub( ONE_IN_Q31, energyRatio_fx[i][j] ) ); // Q31 move32(); } } @@ -1588,17 +1594,17 @@ void ivas_mcmasa_enc( #ifdef IVAS_FLOAT_FIXED void ivas_mcmasa_param_est_enc_fx( - MCMASA_ENC_HANDLE hMcMasa, /* i : McMASA encoder structure */ - MASA_ENCODER_HANDLE hMasa, /* i : MASA encoder structure */ - Word32 *data_f[], /* i : Audio frame in MC-format */ - Word32 elevation_m_values_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /* o : Estimated elevation */ - Word32 azimuth_m_values_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /* o : Estimated azimuth */ - Word32 energyRatio_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /* o : Estimated direct-to-total ratio */ - Word32 spreadCoherence_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /* o : Estimated spread coherence */ - Word32 surroundingCoherence_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /* o : Estimated surround coherence */ - const Word16 input_frame, /* i : Input frame size */ - const Word16 nchan_inp, /* i : Number of input channels */ - const Word16 q_inp /* i : Number of input channels */ + MCMASA_ENC_HANDLE hMcMasa, /* i : McMASA encoder structure */ + MASA_ENCODER_HANDLE hMasa, /* i : MASA encoder structure */ + Word32 *data_f[], /* i : Audio frame in MC-format */ + Word32 elevation_m_values_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /* o : Estimated elevation Q22 */ + Word32 azimuth_m_values_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /* o : Estimated azimuth Q22 */ + Word32 energyRatio_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /* o : Estimated direct-to-total ratio Q31 */ + Word32 spreadCoherence_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /* o : Estimated spread coherence Q31 */ + Word32 surroundingCoherence_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /* o : Estimated surround coherence Q31 */ + const Word16 input_frame, /* i : Input frame size */ + const Word16 nchan_inp, /* i : Number of input channels */ + const Word16 q_inp /* i : Q factor of the data_f */ ) { Word32 reference_power_fx[MDFT_NO_COL_MAX][DIRAC_NO_FB_BANDS_MAX]; @@ -1902,6 +1908,7 @@ void ivas_mcmasa_param_est_enc_fx( num_freq_bands, intensity_even_real_fx ); Word16 ref_e = 0; + move16(); computeReferencePower_enc_fx( hMcMasa->band_grouping, FoaEven_RealBuffer_fx, FoaEven_ImagBuffer_fx, @@ -1913,7 +1920,7 @@ void ivas_mcmasa_param_est_enc_fx( FOA_CHANNELS, inp_q, &ref_e ); /* Fill buffers of length "averaging_length" time slots for intensity and energy */ - hMcMasa->index_buffer_intensity = ( hMcMasa->index_buffer_intensity % hMcMasa->no_col_avg_diff ) + 1; /* averaging_length = 32 */ + hMcMasa->index_buffer_intensity = add( ( hMcMasa->index_buffer_intensity % hMcMasa->no_col_avg_diff ), 1 ); /* averaging_length = 32 */ move16(); index = hMcMasa->index_buffer_intensity; move16(); @@ -1959,8 +1966,9 @@ void ivas_mcmasa_param_est_enc_fx( ELSE { diffuseness_m_fx[block_m_idx][band_m_idx] = diffuseness_vector_fx[band_m_idx]; - diffuseness_e[block_m_idx][band_m_idx] = Q31; + diffuseness_e[block_m_idx][band_m_idx] = 0; // Q31 move32(); + move16(); } } } @@ -2075,7 +2083,7 @@ void ivas_mcmasa_param_est_enc_fx( /* Compute spread coherence */ IF( LT_32( elevation_m_values_fx[block_m_idx][band_m_idx], NEAR_HORIZONTAL_PLANE_ELEVATION_FX ) ) /* Computed only near horizontal plane */ { - minAngleDist_fx = 754974720; /*Q22*/ + minAngleDist_fx = 754974720; /*180.0f Q.22*/ move32(); i1 = 0; move16(); @@ -2086,7 +2094,7 @@ void ivas_mcmasa_param_est_enc_fx( angleDist_fx = L_abs( L_sub( currentAzi_fx, hMcMasa->ls_azimuth_fx[i] ) ); IF( GT_32( angleDist_fx, 754974720 /*180.0f Q.22*/ ) ) { - angleDist_fx = L_abs( L_sub( angleDist_fx, 1509949440 ) ); + angleDist_fx = L_abs( L_sub( angleDist_fx, 1509949440 /*360.0f Q.22*/ ) ); } IF( LT_32( angleDist_fx, minAngleDist_fx ) ) { @@ -2278,14 +2286,14 @@ void ivas_mcmasa_param_est_enc_fx( lsEnergySum_fx = L_add_sat( lsEnergySum_fx, EPSILON_FX ); lsEnergyRelation_fx = BASOP_Util_Divide3232_Scale( temp1, lsEnergySum_fx, &lsEnergyRelation_e ); lsEnergyRelation_e = add( lsEnergyRelation_e, sub( temp1_e, lsEnergySum_e ) ); - lsEnergyRelation_fx = L_shl_sat( lsEnergyRelation_fx, add( 16, lsEnergyRelation_e ) ); - stereoRatio_fx = L_sub( Mult_32_32( L_shl_sat( stereoCoh_fx, stereoCoh_e ), lsEnergyRelation_fx ), surrCoh_fx ); + lsEnergyRelation_fx = L_shl_sat( lsEnergyRelation_fx, add( 16, lsEnergyRelation_e ) ); // Q31 + stereoRatio_fx = L_sub( Mult_32_32( L_shl_sat( stereoCoh_fx, stereoCoh_e ), lsEnergyRelation_fx ), surrCoh_fx ); // Q31 temp2 = L_sub( temp2, EPSILLON_FX ); lsEnergyRelation_fx = BASOP_Util_Divide3232_Scale( temp2, lsEnergySum_fx, &lsEnergyRelation_e ); lsEnergyRelation_e = add( lsEnergyRelation_e, sub( temp2_e, lsEnergySum_e ) ); - lsEnergyRelation_fx = L_shl_sat( lsEnergyRelation_fx, add( 16, lsEnergyRelation_e ) ); - cohPanRatio_fx = L_sub( Mult_32_32( cohPanCoh_fx, lsEnergyRelation_fx ), surrCoh_fx ); + lsEnergyRelation_fx = L_shl_sat( lsEnergyRelation_fx, add( 16, lsEnergyRelation_e ) ); // Q31 + cohPanRatio_fx = L_sub( Mult_32_32( cohPanCoh_fx, lsEnergyRelation_fx ), surrCoh_fx ); // Q31 IF( GT_32( stereoRatio_fx, cohPanRatio_fx ) ) { cohRatio_fx = stereoRatio_fx; @@ -2338,9 +2346,9 @@ void ivas_mcmasa_param_est_enc_fx( } ELSE { - surroundingCoherence_fx[block_m_idx][band_m_idx] = surrCoh_fx; + surroundingCoherence_fx[block_m_idx][band_m_idx] = surrCoh_fx; // Q31 move32(); - coherentEnergyRatio_fx[block_m_idx][band_m_idx] = cohRatio_fx; + coherentEnergyRatio_fx[block_m_idx][band_m_idx] = cohRatio_fx; // Q31 move32(); } } @@ -2356,7 +2364,7 @@ void ivas_mcmasa_param_est_enc_fx( diffuseness_m_fx[0][band_m_idx] = BASOP_Util_Divide3232_Scale( diffuseness_m_fx[0][band_m_idx], renormalization_factor_diff_fx[band_m_idx], &diffuseness_m_e ); move32(); diffuseness_m_e = add( diffuseness_m_e, sub( diffuseness_e[0][band_m_idx], renormalization_factor_diff_e[band_m_idx] ) ); - diffuseness_m_fx[0][band_m_idx] = L_shl_sat( diffuseness_m_fx[0][band_m_idx], add( 16, diffuseness_m_e ) ); + diffuseness_m_fx[0][band_m_idx] = L_shl_sat( diffuseness_m_fx[0][band_m_idx], add( 16, diffuseness_m_e ) ); // Q(31 - diffuseness_m_e) -> Q31 move32(); } ELSE @@ -2372,12 +2380,12 @@ void ivas_mcmasa_param_est_enc_fx( surroundingCoherence_fx[0][band_m_idx] = BASOP_Util_Divide3232_Scale( surroundingCoherence_fx[0][band_m_idx], renormalization_factor_coh_fx[band_m_idx], &sc_e ); move32(); sc_e = add( sc_e, sub( surroundingCoherence_e[0][band_m_idx], renormalization_factor_coh_e[band_m_idx] ) ); - surroundingCoherence_fx[0][band_m_idx] = L_shl_sat( surroundingCoherence_fx[0][band_m_idx], add( 16, sc_e ) ); + surroundingCoherence_fx[0][band_m_idx] = L_shl_sat( surroundingCoherence_fx[0][band_m_idx], add( 16, sc_e ) ); // Q(31 - sc_e) -> Q31 move32(); coherentEnergyRatio_fx[0][band_m_idx] = BASOP_Util_Divide3232_Scale( coherentEnergyRatio_fx[0][band_m_idx], renormalization_factor_coh_fx[band_m_idx], &cer_e ); move32(); cer_e = add( cer_e, sub( coherentEnergyRatio_e[0][band_m_idx], renormalization_factor_coh_e[band_m_idx] ) ); - coherentEnergyRatio_fx[0][band_m_idx] = L_shl_sat( coherentEnergyRatio_fx[0][band_m_idx], add( 16, cer_e ) ); + coherentEnergyRatio_fx[0][band_m_idx] = L_shl_sat( coherentEnergyRatio_fx[0][band_m_idx], add( 16, cer_e ) ); // Q(31 - cer_e) -> Q31 move32(); } ELSE @@ -2406,7 +2414,7 @@ void ivas_mcmasa_param_est_enc_fx( { FOR( j = 0; j < hMcMasa->nbands; j++ ) { - energyRatio_fx[i][j] = L_sub( ONE_IN_Q31, diffuseness_m_fx[i][j] ); + energyRatio_fx[i][j] = L_sub( ONE_IN_Q31, diffuseness_m_fx[i][j] ); // Q31 move32(); IF( GT_32( energyRatio_fx[i][j], coherentEnergyRatio_fx[i][j] ) ) { @@ -2415,7 +2423,7 @@ void ivas_mcmasa_param_est_enc_fx( } ELSE { - energyRatio_fx[i][j] = coherentEnergyRatio_fx[i][j]; + energyRatio_fx[i][j] = coherentEnergyRatio_fx[i][j]; // Q31 move32(); } } @@ -2945,6 +2953,92 @@ void ivas_mcmasa_param_est_enc( * *--------------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +void ivas_mcmasa_dmx_modify_fx( + const Word16 n_samples, /* i : input frame length in samples */ + Word32 dmx_fx[][L_FRAME48k + NS2SA( 48000, IVAS_FB_ENC_DELAY_NS )], /* i/o: downmix signal to be transformed into another format Qx*/ + const Word16 n_chnls_dmx_old, /* i : number of downmix channels in the old format Q0 */ + const Word16 n_chnls_dmx_new ) /* i : number of downmix channels in the target format Q0*/ +{ + /* assumed data ordering in **dmx: [sce][cpe_chnl0][cpe_chnl1], i.e., [c][l][r] */ + Word16 i; + + assert( ( n_chnls_dmx_old == 1 || n_chnls_dmx_old == 2 || n_chnls_dmx_old == 3 ) && "Input downmix may contain only 1-3 channels." ); + assert( ( n_chnls_dmx_new == 1 || n_chnls_dmx_new == 2 || n_chnls_dmx_new == 3 ) && "Output downmix may contain only 1-3 channels." ); + + IF( EQ_16( n_chnls_dmx_old, n_chnls_dmx_new ) ) + { + /* same dmx layout -> nothing to do */ + return; + } + + IF( EQ_16( n_chnls_dmx_old, 1 ) ) + { + /* split mono energy into identical channels */ + FOR( i = 0; i < n_samples; i++ ) + { + IF( EQ_16( n_chnls_dmx_new, 2 ) ) + { + dmx_fx[1][i] = Mpy_32_16_1( dmx_fx[0][i], INV_SQRT2_FX_Q15 ); // dmx_q + Q15 - 15 + dmx_fx[2][i] = dmx_fx[1][i]; + move32(); + move32(); + } + ELSE IF( EQ_16( n_chnls_dmx_new, 3 ) ) + { + dmx_fx[0][i] = Mpy_32_16_1( dmx_fx[0][i], INV_SQRT3_FX ); // dmx_q + Q15 - 15 + move32(); + } + } + } + ELSE IF( EQ_16( n_chnls_dmx_old, 2 ) ) + { + FOR( i = 0; i < n_samples; i++ ) + { + IF( EQ_16( n_chnls_dmx_new, 1 ) ) + { + /* sum l and r */ + dmx_fx[0][i] = L_add( dmx_fx[1][i], dmx_fx[2][i] ); + move32(); + } + ELSE IF( EQ_16( n_chnls_dmx_new, 3 ) ) + { + dmx_fx[0][i] = L_shr( L_add( dmx_fx[1][i], dmx_fx[2][i] ), 1 ); + dmx_fx[1][i] = L_sub( dmx_fx[1][i], dmx_fx[0][i] ); + dmx_fx[2][i] = L_sub( dmx_fx[2][i], dmx_fx[0][i] ); + move32(); + move32(); + move32(); + } + } + } + ELSE IF( EQ_16( n_chnls_dmx_old, 3 ) ) + { + FOR( i = 0; i < n_samples; i++ ) + { + IF( EQ_16( n_chnls_dmx_new, 1 ) ) + { + /* sum all channels */ + dmx_fx[0][i] = L_add( L_add( dmx_fx[0][i], dmx_fx[1][i] ), dmx_fx[2][i] ); + move32(); + } + ELSE IF( EQ_16( n_chnls_dmx_new, 2 ) ) + { + /* mix center into sides */ + dmx_fx[0][i] = Mpy_32_16_1( dmx_fx[0][i], INV_SQRT2_FX_Q15 ); + dmx_fx[1][i] = L_add( dmx_fx[1][i], dmx_fx[0][i] ); + dmx_fx[2][i] = L_add( dmx_fx[2][i], dmx_fx[0][i] ); + move32(); + move32(); + move32(); + } + } + } + + return; +} +#endif + void ivas_mcmasa_dmx_modify( const int16_t n_samples, /* i : input frame length in samples */ float dmx[][L_FRAME48k + NS2SA( 48000, IVAS_FB_ENC_DELAY_NS )], /* i/o: downmix signal to be transformed into another format */ @@ -3127,16 +3221,16 @@ static void ivas_mcmasa_dmx_fx( } } - alpha_fx = 214748364; // Q31 + alpha_fx = 214748364; // 0.1 in Q31 move32(); L_tmp = Mpy_32_32( alpha_fx, multiChEne_fx ); - L_tmp1 = Mpy_32_32( 1932735284, hMcMasa->prevMultiChEne_fx ); + L_tmp1 = Mpy_32_32( 1932735284 /* 0.9f in Q31 */, hMcMasa->prevMultiChEne_fx ); hMcMasa->prevMultiChEne_fx = BASOP_Util_Add_Mant32Exp( L_tmp, multiChEne_e, L_tmp1, hMcMasa->prevMultiChEne_e, &hMcMasa->prevMultiChEne_e ); move32(); L_tmp = Mpy_32_32( alpha_fx, downmixEne_fx ); - L_tmp1 = Mpy_32_32( 1932735284, hMcMasa->prevDownmixEne_fx ); + L_tmp1 = Mpy_32_32( 1932735284 /* 0.9f in Q31 */, hMcMasa->prevDownmixEne_fx ); hMcMasa->prevDownmixEne_fx = BASOP_Util_Add_Mant32Exp( L_tmp, downmixEne_e, L_tmp1, hMcMasa->prevDownmixEne_e, &hMcMasa->prevDownmixEne_e ); move32(); @@ -3157,7 +3251,7 @@ static void ivas_mcmasa_dmx_fx( FOR( i = 0; i < input_frame; i++ ) { L_tmp = Mpy_32_32( L_deposit_h( hMcMasa->interpolator_fx[i] ), currEQ_fx ); - L_tmp1 = L_sub( 1073741824, L_lshr( L_deposit_h( hMcMasa->interpolator_fx[i] ), 1 ) ); + L_tmp1 = L_sub( 1073741824 /* 1 in Q30 */, L_lshr( L_deposit_h( hMcMasa->interpolator_fx[i] ), 1 ) ); L_tmp1 = Mpy_32_32( L_tmp1, prevEQ_fx ); instEQ_fx = BASOP_Util_Add_Mant32Exp( L_tmp, currEQ_e, L_tmp1, add( prevEQ_e, 1 ), &instEQ_e ); @@ -3282,8 +3376,8 @@ static void ivas_mcmasa_dmx( #ifdef IVAS_FLOAT_FIXED /* Compute covariance matrix, i.e., xT * conj(x), and accumulate to the output */ static void compute_cov_mtx_fx( - Word32 sr[MCMASA_MAX_ANA_CHANS][DIRAC_NO_FB_BANDS_MAX], /* i : Input matrix, real, s[ch][freq] */ - Word32 si[MCMASA_MAX_ANA_CHANS][DIRAC_NO_FB_BANDS_MAX], /* i : Input matrix, imag, s[ch][freq] */ + Word32 sr[MCMASA_MAX_ANA_CHANS][DIRAC_NO_FB_BANDS_MAX], /* i : Input matrix, real, s[ch][freq] (inp_exp) */ + Word32 si[MCMASA_MAX_ANA_CHANS][DIRAC_NO_FB_BANDS_MAX], /* i : Input matrix, imag, s[ch][freq] (inp_exp) */ const Word16 freq, /* i : Freq to process */ const Word16 N, /* i : Number of channels */ CovarianceMatrix *COVls, /* o : Output matrix, contains upper part of cov mtx */ @@ -3445,11 +3539,11 @@ static void computeIntensityVector_enc_fx( #endif #ifdef IVAS_FLOAT_FIXED static void computeVerticalDiffuseness_fx( - Word32 **buffer_intensity, /* i : Intensity vectors */ - const Word32 *buffer_energy, /* i : Energy */ - const int16_t averaging_length, /* i : Averaging length */ - const Word16 num_freq_bands, /* i : Number of frequency bands */ - Word32 *diffuseness, /* o : Estimated diffuseness */ + Word32 **buffer_intensity, /* i : Intensity vectors */ + const Word32 *buffer_energy, /* i : Energy */ + const Word16 averaging_length, /* i : Averaging length */ + const Word16 num_freq_bands, /* i : Number of frequency bands */ + Word32 *diffuseness, /* o : Estimated diffuseness Q31 */ Word16 *buffer_intensity_q, Word16 *buffer_energy_q ) { @@ -3518,7 +3612,7 @@ static void computeVerticalDiffuseness_fx( { tmp = L_shl( tmp, add( 16, tmp_e2 ) ); } - diffuseness[i] = tmp; + diffuseness[i] = tmp; // Q31 move32(); } @@ -3906,7 +4000,8 @@ static void computeLfeEnergy_fx( move32(); } - hMcMasa->ringBufferPointer--; + hMcMasa->ringBufferPointer = sub( hMcMasa->ringBufferPointer, 1 ); + move16(); IF( hMcMasa->ringBufferPointer < 0 ) { hMcMasa->ringBufferPointer = sub( hMcMasa->ringBufferSize, 1 ); @@ -3973,8 +4068,8 @@ static void computeLfeEnergy_fx( IF( hMcMasa->separateChannelEnabled ) { - Copy32( data_fx[lfeChannelIndex] + ( input_frame - hMcMasa->num_samples_delay_comp + hMcMasa->offset_comp ), &( hMcMasa->delay_buffer_lfe[0][0] ), ( hMcMasa->num_samples_delay_comp - hMcMasa->offset_comp ) ); - Copy32( data_fx[separateChannelIndex] + ( input_frame - hMcMasa->num_samples_delay_comp + hMcMasa->offset_comp ), &( hMcMasa->delay_buffer_lfe[1][0] ), ( hMcMasa->num_samples_delay_comp - hMcMasa->offset_comp ) ); + Copy32( data_fx[lfeChannelIndex] + ( input_frame - hMcMasa->num_samples_delay_comp + hMcMasa->offset_comp ), &( hMcMasa->delay_buffer_lfe[0][0] ), sub( hMcMasa->num_samples_delay_comp, hMcMasa->offset_comp ) ); + Copy32( data_fx[separateChannelIndex] + ( input_frame - hMcMasa->num_samples_delay_comp + hMcMasa->offset_comp ), &( hMcMasa->delay_buffer_lfe[1][0] ), sub( hMcMasa->num_samples_delay_comp, hMcMasa->offset_comp ) ); } return; diff --git a/lib_enc/ivas_omasa_enc.c b/lib_enc/ivas_omasa_enc.c index 0265b1339..48592f1b3 100644 --- a/lib_enc/ivas_omasa_enc.c +++ b/lib_enc/ivas_omasa_enc.c @@ -75,9 +75,6 @@ static void ivas_omasa_energy_and_ratio_est_fx( OMASA_ENC_HANDLE hOMasa, OMASA_ENCODER_DATA_HANDLE hOmasaData, Word32 *data_fx[], -#if 0 - float *data_f[], -#endif const Word16 input_frame, const Word16 nchan_ism, const Word16 q_data ); @@ -873,7 +870,7 @@ void ivas_omasa_enc_fx( MASA_ENCODER_HANDLE hMasa, /* i/o: MASA encoder handle */ ISM_METADATA_HANDLE hIsmMeta[], /* i/o: ISM metadata handle */ Word32 *data_in[], /* i/o: Input / transport audio signals */ - Word16 q_data, /* i:Q0 Stores the q for data_in_f */ + Word16 q_data, /* i : Q0 Stores the q for data_in */ const Word16 input_frame, /* i : Input frame size */ const Word16 nchan_transport, /* i : Number of transport channels */ const Word16 nchan_ism, /* i : Number of objects for parameter analysis */ @@ -939,7 +936,7 @@ void ivas_omasa_enc_fx( // alpha = 26214;/*0.8 Q15*/ FOR( i = 0; i < nchan_all_inp; i++ ) { - hOMasa->broadband_energy_sm_fx[i] = L_add( Mpy_32_16_1( broadband_energy_fx[i], 6554 ), Mpy_32_16_1( hOMasa->broadband_energy_sm_fx[i], 26214 ) ); + hOMasa->broadband_energy_sm_fx[i] = L_add( Mpy_32_16_1( broadband_energy_fx[i], 6554 /*0.2 Q15*/ ), Mpy_32_16_1( hOMasa->broadband_energy_sm_fx[i], 26214 /*0.8 Q15*/ ) ); move32(); } @@ -1405,6 +1402,7 @@ void ivas_set_ism_importance_interformat_fx( IF( active_flag == 0 ) { + test(); if ( GT_16( st->lp_noise_fx, 3840 /* 15 in Q8 */ ) || LT_16( sub( lp_noise_CPE_fx, st->lp_noise_fx ), 7680 /* 30 in Q8 */ ) ) { active_flag = 1; @@ -1425,6 +1423,8 @@ void ivas_set_ism_importance_interformat_fx( ctype = hSCE[ch]->hCoreCoder[0]->coder_type_raw; st->low_rate_mode = 0; + move16(); + test(); IF( active_flag == 0 ) { ism_imp[ch] = ISM_INACTIVE_IMP; @@ -1533,12 +1533,8 @@ void ivas_set_surplus_brate_enc( test(); IF( EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) ) { -#ifndef IVAS_FLOAT_FIXED - st_ivas->hCPE[0]->brate_surplus = st_ivas->hSCE[0]->element_brate - ivas_interformat_brate( ISM_MASA_MODE_PARAM_ONE_OBJ, 1, st_ivas->hSCE[0]->element_brate, st_ivas->hIsmMetaData[0]->ism_imp, 0 ); -#else st_ivas->hCPE[0]->brate_surplus = L_sub( st_ivas->hSCE[0]->element_brate, ivas_interformat_brate_fx( ISM_MASA_MODE_PARAM_ONE_OBJ, 1, st_ivas->hSCE[0]->element_brate, st_ivas->hIsmMetaData[0]->ism_imp, 0 ) ); move32(); -#endif /* note: ISM st->total_brate is iset in ivas_sce_enc() */ } ELSE IF( EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) || EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) ) @@ -1777,7 +1773,7 @@ static void ivas_omasa_param_est_enc_fx( dir_v_e = MIN_16; num_freq_bins = hOMasa->cldfbAnaEnc[0]->no_channels; num_freq_bands = hOMasa->nbands; - l_ts = input_frame / CLDFB_NO_COL_MAX; /*division by power of 2 so basop not used*/ + l_ts = idiv1616( input_frame, CLDFB_NO_COL_MAX ); move16(); move16(); move16(); @@ -2011,8 +2007,8 @@ static void ivas_omasa_param_est_enc_fx( move16(); } move32(); - diffuseness_m_fx[band_m_idx] = L_shl( diffuseness_m_fx[band_m_idx], 15 + temp_e ); - energyRatio_fx[band_m_idx] = L_sub( ONE_IN_Q30, diffuseness_m_fx[band_m_idx] ); + diffuseness_m_fx[band_m_idx] = L_shl( diffuseness_m_fx[band_m_idx], add( 15, temp_e ) ); // Scaling to Q30 + energyRatio_fx[band_m_idx] = L_sub( ONE_IN_Q30, diffuseness_m_fx[band_m_idx] ); // Q30 move32(); move32(); } @@ -2672,9 +2668,7 @@ static void computeReferencePower_omasa_ivas_fx( /* abs()^2 */ FOR( j = brange[0]; j < brange[1]; j++ ) { - // reference_power[i] += ( Cldfb_RealBuffer[ch_idx][j] * Cldfb_RealBuffer[ch_idx][j] ) + ( Cldfb_ImagBuffer[ch_idx][j] * Cldfb_ImagBuffer[ch_idx][j] ); - // Q13 (Q6+Q6+1) - reference_power_tmp[i] = W_add( reference_power_tmp[i], W_mac_32_32( W_mult_32_32( Cldfb_RealBuffer[ch_idx][j], Cldfb_RealBuffer[ch_idx][j] ), Cldfb_ImagBuffer[ch_idx][j], Cldfb_ImagBuffer[ch_idx][j] ) ); + reference_power_tmp[i] = W_add( reference_power_tmp[i], W_mac_32_32( W_mult_32_32( Cldfb_RealBuffer[ch_idx][j], Cldfb_RealBuffer[ch_idx][j] ), Cldfb_ImagBuffer[ch_idx][j], Cldfb_ImagBuffer[ch_idx][j] ) ); // Q13 (Q6+Q6+1) move64(); } } diff --git a/lib_enc/ivas_osba_enc.c b/lib_enc/ivas_osba_enc.c index 4da8169fb..ec1e0f9fa 100644 --- a/lib_enc/ivas_osba_enc.c +++ b/lib_enc/ivas_osba_enc.c @@ -345,66 +345,7 @@ ivas_error ivas_osba_enc_reconfig( n_old = add( st_ivas->hEncoderConfig->nchan_ism, imult1616( add( analysis_order_old, 1 ), add( analysis_order_old, 1 ) ) ); n = add( st_ivas->hEncoderConfig->nchan_ism, imult1616( add( st_ivas->sba_analysis_order, 1 ), add( st_ivas->sba_analysis_order, 1 ) ) ); -#if 1 // To be removed - float **old_mem_hp20_in; - - if ( n > n_old ) - { - /* save old mem_hp_20 pointer */ - old_mem_hp20_in = st_ivas->mem_hp20_in; - st_ivas->mem_hp20_in = NULL; - - if ( ( st_ivas->mem_hp20_in = (float **) malloc( n * sizeof( float * ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HP20 filter memory\n" ) ); - } - - for ( i = 0; i < n_old; i++ ) - { - st_ivas->mem_hp20_in[i] = old_mem_hp20_in[i]; - old_mem_hp20_in[i] = NULL; - } - /* create additional hp20 memories */ - for ( ; i < n; i++ ) - { - if ( ( st_ivas->mem_hp20_in[i] = (float *) malloc( L_HP20_MEM * sizeof( float ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HP20 filter memory\n" ) ); - } - - set_f( st_ivas->mem_hp20_in[i], 0.0f, L_HP20_MEM ); - } - - free( old_mem_hp20_in ); - old_mem_hp20_in = NULL; - } - else if ( n < n_old ) - { - /* save old mem_hp_20 pointer */ - old_mem_hp20_in = st_ivas->mem_hp20_in; - st_ivas->mem_hp20_in = NULL; - if ( ( st_ivas->mem_hp20_in = (float **) malloc( n * sizeof( float * ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HP20 filter memory\n" ) ); - } - - for ( i = 0; i < n; i++ ) - { - st_ivas->mem_hp20_in[i] = old_mem_hp20_in[i]; - old_mem_hp20_in[i] = NULL; - } - /* remove superfluous hp20 memories */ - for ( ; i < n_old; i++ ) - { - free( old_mem_hp20_in[i] ); - old_mem_hp20_in[i] = NULL; - } - - free( old_mem_hp20_in ); - old_mem_hp20_in = NULL; - } -#endif IF( GT_16( n, n_old ) ) { /* save old mem_hp_20 pointer */ diff --git a/lib_enc/ivas_sba_enc.c b/lib_enc/ivas_sba_enc.c index 549b7ccdc..501c6796a 100644 --- a/lib_enc/ivas_sba_enc.c +++ b/lib_enc/ivas_sba_enc.c @@ -140,66 +140,6 @@ ivas_error ivas_sba_enc_reconfigure( n_old = imult1616( add( analysis_order_old, 1 ), add( analysis_order_old, 1 ) ); n = imult1616( add( st_ivas->sba_analysis_order, 1 ), add( st_ivas->sba_analysis_order, 1 ) ); -#if 1 // To be removed - float **old_mem_hp20_in; - - if ( n > n_old ) - { - /* save old mem_hp_20 pointer */ - old_mem_hp20_in = st_ivas->mem_hp20_in; - st_ivas->mem_hp20_in = NULL; - - if ( ( st_ivas->mem_hp20_in = (float **) malloc( n * sizeof( float * ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HP20 filter memory\n" ) ); - } - - for ( i = 0; i < n_old; i++ ) - { - st_ivas->mem_hp20_in[i] = old_mem_hp20_in[i]; - old_mem_hp20_in[i] = NULL; - } - /* create additional hp20 memories */ - for ( ; i < n; i++ ) - { - if ( ( st_ivas->mem_hp20_in[i] = (float *) malloc( L_HP20_MEM * sizeof( float ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HP20 filter memory\n" ) ); - } - - set_f( st_ivas->mem_hp20_in[i], 0.0f, L_HP20_MEM ); - } - - free( old_mem_hp20_in ); - old_mem_hp20_in = NULL; - } - else if ( n < n_old ) - { - /* save old mem_hp_20 pointer */ - old_mem_hp20_in = st_ivas->mem_hp20_in; - st_ivas->mem_hp20_in = NULL; - - if ( ( st_ivas->mem_hp20_in = (float **) malloc( n * sizeof( float * ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HP20 filter memory\n" ) ); - } - - for ( i = 0; i < n; i++ ) - { - st_ivas->mem_hp20_in[i] = old_mem_hp20_in[i]; - old_mem_hp20_in[i] = NULL; - } - /* remove superfluous hp20 memories */ - for ( ; i < n_old; i++ ) - { - free( old_mem_hp20_in[i] ); - old_mem_hp20_in[i] = NULL; - } - - free( old_mem_hp20_in ); - old_mem_hp20_in = NULL; - } -#endif IF( GT_16( n, n_old ) ) { /* save old mem_hp_20 pointer */ @@ -258,70 +198,77 @@ ivas_error ivas_sba_enc_reconfigure( } } -#ifdef IVAS_FLOAT_FIXED ivas_spar_config_fx( ivas_total_brate, min( st_ivas->sba_analysis_order, IVAS_MAX_SBA_ORDER ), &st_ivas->nchan_transport, &st_ivas->nSCE, &st_ivas->nCPE, &st_ivas->hSpar->core_nominal_brate, -1 ); -#else - ivas_spar_config( ivas_total_brate, min( st_ivas->sba_analysis_order, IVAS_MAX_SBA_ORDER ), &st_ivas->nchan_transport, &st_ivas->nSCE, &st_ivas->nCPE, &st_ivas->hSpar->core_nominal_brate, -1 ); -#endif hSpar = st_ivas->hSpar; - if ( st_ivas->nchan_transport == 1 ) + IF( EQ_16( st_ivas->nchan_transport, 1 ) ) { hEncoderConfig->element_mode_init = IVAS_SCE; } - else + ELSE { hEncoderConfig->element_mode_init = IVAS_CPE_MDCT; } + move16(); - if ( nchan_transport_old != st_ivas->nchan_transport || ( ivas_total_brate < IVAS_512k && hEncoderConfig->last_ivas_total_brate >= IVAS_512k ) || ( ivas_total_brate >= IVAS_512k && hEncoderConfig->last_ivas_total_brate < IVAS_512k ) ) + test(); + test(); + test(); + test(); + IF( NE_16( nchan_transport_old, st_ivas->nchan_transport ) || ( LT_32( ivas_total_brate, IVAS_512k ) && GE_32( hEncoderConfig->last_ivas_total_brate, IVAS_512k ) ) || ( GE_32( ivas_total_brate, IVAS_512k ) && LT_32( hEncoderConfig->last_ivas_total_brate, IVAS_512k ) ) ) { /* FB mixer handle */ - if ( hDirAC->hFbMixer != NULL ) + IF( hDirAC->hFbMixer != NULL ) { ivas_FB_mixer_close( &( hDirAC->hFbMixer ), hEncoderConfig->input_Fs, 0 ); hDirAC->hFbMixer = NULL; } spar_reconfig_flag = 1; + move16(); ivas_spar_enc_close( &( st_ivas->hSpar ), hEncoderConfig->input_Fs, hEncoderConfig->nchan_inp, spar_reconfig_flag ); - if ( ( error = ivas_spar_enc_open( st_ivas, spar_reconfig_flag ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_spar_enc_open( st_ivas, spar_reconfig_flag ) ) != IVAS_ERR_OK ) { return error; } } st_ivas->hSpar->spar_reconfig_flag = spar_reconfig_flag; + move16(); - if ( ( error = ivas_dirac_enc_reconfigure( st_ivas ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_dirac_enc_reconfigure( st_ivas ) ) != IVAS_ERR_OK ) { return error; } - if ( st_ivas->hQMetaData->q_direction->cfg.nbands != nbands_old || st_ivas->hQMetaData->no_directions != ndir_old ) + test(); + IF( NE_16( st_ivas->hQMetaData->q_direction->cfg.nbands, nbands_old ) || NE_16( st_ivas->hQMetaData->no_directions, ndir_old ) ) { - int16_t dir, j, i; + Word16 dir, j, i; IVAS_QDIRECTION *q_direction = st_ivas->hQMetaData->q_direction; - for ( dir = 0; dir < st_ivas->hQMetaData->no_directions; dir++ ) + FOR( dir = 0; dir < st_ivas->hQMetaData->no_directions; dir++ ) { - for ( j = 0; j < q_direction[dir].cfg.nbands; j++ ) + FOR( j = 0; j < q_direction[dir].cfg.nbands; j++ ) { - for ( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) + FOR( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) { q_direction[dir].band_data[j].energy_ratio_index[i] = 0; q_direction[dir].band_data[j].energy_ratio_index_mod[i] = 0; + move16(); + move16(); } } } } hSpar->enc_param_start_band = hDirAC->hConfig->enc_param_start_band; + move16(); /*-----------------------------------------------------------------* * Allocate, initialize, and configure SCE/CPE/MCT handles *-----------------------------------------------------------------*/ - if ( ( error = ivas_corecoder_enc_reconfig_fx( st_ivas, nSCE_old, nCPE_old, nchan_transport_old, ivas_total_brate / st_ivas->nchan_transport, ( ivas_total_brate / st_ivas->nchan_transport ) * CPE_CHANNELS, MC_MODE_NONE ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_corecoder_enc_reconfig_fx( st_ivas, nSCE_old, nCPE_old, nchan_transport_old, ivas_total_brate / st_ivas->nchan_transport, ( ivas_total_brate / st_ivas->nchan_transport ) * CPE_CHANNELS, MC_MODE_NONE ) ) != IVAS_ERR_OK ) { return error; } diff --git a/lib_enc/ivas_sce_enc.c b/lib_enc/ivas_sce_enc.c index b6e5fbaf6..6637128dd 100644 --- a/lib_enc/ivas_sce_enc.c +++ b/lib_enc/ivas_sce_enc.c @@ -428,7 +428,7 @@ ivas_error create_sce_enc( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for CoreCoder structure\n" ) ); } - copy_encoder_config( st_ivas, st, 1 ); + copy_encoder_config_fx( st_ivas, st, 1 ); if ( st_ivas->hEncoderConfig->ivas_format == MASA_ISM_FORMAT && ( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_DISC ) ) { @@ -544,12 +544,13 @@ ivas_error create_evs_sce_enc( ivas_error error; error = IVAS_ERR_OK; + move32(); /*-----------------------------------------------------------------* * Allocate SCE handle *-----------------------------------------------------------------*/ - if ( ( hSCE = (SCE_ENC_HANDLE) malloc( sizeof( SCE_ENC_DATA ) ) ) == NULL ) + IF( ( hSCE = (SCE_ENC_HANDLE) malloc( sizeof( SCE_ENC_DATA ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SCE\n" ) ); } @@ -559,21 +560,23 @@ ivas_error create_evs_sce_enc( *-----------------------------------------------------------------*/ hSCE->sce_id = sce_id; + move16(); hSCE->element_brate = element_brate; + move32(); hSCE->last_element_brate = hSCE->element_brate; - + move32(); /*-----------------------------------------------------------------* * Metadata: allocate and initialize *-----------------------------------------------------------------*/ - - if ( st_ivas->hEncoderConfig->ivas_format != MONO_FORMAT && sce_id == ( st_ivas->nSCE - 1 ) ) + test(); + IF( NE_32( st_ivas->hEncoderConfig->ivas_format, MONO_FORMAT ) && EQ_16( sce_id, sub( st_ivas->nSCE, 1 ) ) ) { - if ( ( error = ivas_initialize_MD_bstr_enc( &( hSCE->hMetaData ), st_ivas ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_initialize_MD_bstr_enc( &( hSCE->hMetaData ), st_ivas ) ), IVAS_ERR_OK ) ) { return error; } } - else + ELSE { hSCE->hMetaData = NULL; } @@ -581,45 +584,72 @@ ivas_error create_evs_sce_enc( /*-----------------------------------------------------------------* * Core Coder, 1 instance: allocate and initialize *-----------------------------------------------------------------*/ - if ( ( st_fx = (ENC_CORE_HANDLE) malloc( sizeof( Encoder_State ) ) ) == NULL ) + IF( ( st_fx = (ENC_CORE_HANDLE) malloc( sizeof( Encoder_State ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for CoreCoder structure\n" ) ); } memset( st_fx, 0, sizeof( Encoder_State ) ); st_fx->input_Fs = 16000; + move32(); st_fx->total_brate = ACELP_12k65; - + move32(); st_fx->Opt_AMR_WB = 0; + move16(); st_fx->Opt_RF_ON = 0; + move16(); st_fx->rf_fec_offset = 0; + move16(); st_fx->rf_fec_indicator = 1; + move16(); st_fx->max_bwidth = SWB; + move16(); st_fx->interval_SID_fx = FIXED_SID_RATE; + move16(); st_fx->var_SID_rate_flag_fx = 1; + move16(); st_fx->Opt_HE_SAD_ON_fx = 0; + move16(); st_fx->Opt_SC_VBR = 0; + move16(); st_fx->last_Opt_SC_VBR = 0; + move16(); st_fx->bitstreamformat = G192; + move16(); // copy_encoder_config_fx( st_ivas, st_fx, 1 ); st_fx->max_bwidth = st_ivas->hEncoderConfig->max_bwidth; + move16(); st_fx->Opt_DTX_ON = st_ivas->hEncoderConfig->Opt_DTX_ON; + move16(); st_fx->var_SID_rate_flag_fx = st_ivas->hEncoderConfig->var_SID_rate_flag; + move16(); st_fx->interval_SID_fx = st_ivas->hEncoderConfig->interval_SID; + move16(); st_fx->Opt_RF_ON = st_ivas->hEncoderConfig->Opt_RF_ON; + move16(); st_fx->rf_fec_indicator = st_ivas->hEncoderConfig->rf_fec_indicator; + move16(); st_fx->rf_fec_offset = st_ivas->hEncoderConfig->rf_fec_offset; + move16(); // st_fx->bitstreamformat = st->bitstreamformat; st_fx->total_brate = st_ivas->hEncoderConfig->ivas_total_brate; + move32(); st_fx->Opt_SC_VBR = st_ivas->hEncoderConfig->Opt_SC_VBR; + move16(); st_fx->last_Opt_SC_VBR = st_ivas->hEncoderConfig->last_Opt_SC_VBR; + move16(); st_fx->Opt_AMR_WB = st_ivas->hEncoderConfig->Opt_AMR_WB; + move16(); st_fx->input_Fs = st_ivas->hEncoderConfig->input_Fs; + move32(); st_fx->codec_mode = st_ivas->codec_mode; + move16(); st_fx->last_codec_mode = st_ivas->last_codec_mode; + move16(); st_fx->input_frame_fx = extract_l( Mult_32_16( st_fx->input_Fs, 0x0290 ) ); - if ( ( error = init_encoder_fx( st_fx ) ) != IVAS_ERR_OK ) + move16(); + IF( NE_32( ( error = init_encoder_fx( st_fx ) ), IVAS_ERR_OK ) ) { return error; } diff --git a/lib_enc/ivas_spar_encoder.c b/lib_enc/ivas_spar_encoder.c index 2ad739323..9ffd91825 100644 --- a/lib_enc/ivas_spar_encoder.c +++ b/lib_enc/ivas_spar_encoder.c @@ -104,11 +104,7 @@ ivas_error ivas_spar_enc_open( hSpar->spar_reconfig_flag = 0; input_Fs = hEncoderConfig->input_Fs; sba_order_internal = min( st_ivas->sba_analysis_order, IVAS_MAX_SBA_ORDER ); -#ifdef IVAS_FLOAT_FIXED nchan_inp = ivas_sba_get_nchan_metadata_fx( sba_order_internal, hEncoderConfig->ivas_total_brate ); -#else - nchan_inp = ivas_sba_get_nchan_metadata( sba_order_internal, hEncoderConfig->ivas_total_brate ); -#endif // IVAS_FLOAT_FIXED assert( nchan_inp <= hEncoderConfig->nchan_inp ); ivas_total_brate = hEncoderConfig->ivas_total_brate; @@ -130,9 +126,9 @@ ivas_error ivas_spar_enc_open( assert( 0 && "sba_order must be 1,2, or 3!" ); } - nchan_transport = ivas_get_sba_num_TCs( hEncoderConfig->ivas_total_brate, sba_order_internal ); + nchan_transport = ivas_get_sba_num_TCs_fx( hEncoderConfig->ivas_total_brate, sba_order_internal ); - table_idx = ivas_get_spar_table_idx( ivas_total_brate, sba_order_internal, SPAR_CONFIG_BW, NULL, NULL ); + table_idx = ivas_get_spar_table_idx_fx( ivas_total_brate, sba_order_internal, SPAR_CONFIG_BW, NULL, NULL ); /* MD handle */ if ( ( error = ivas_spar_md_enc_open( &( hSpar->hMdEnc ), hEncoderConfig, sba_order_internal ) ) != IVAS_ERR_OK ) @@ -170,10 +166,17 @@ ivas_error ivas_spar_enc_open( if ( !spar_reconfig_flag ) { /* Transient Detector handle */ +#ifdef IVAS_FLOAT_FIXED + IF( ( error = ivas_transient_det_open_fx( &( hSpar->hTranDet ), input_Fs ) ) != IVAS_ERR_OK ) + { + return error; + } +#else if ( ( error = ivas_transient_det_open( &( hSpar->hTranDet ), input_Fs ) ) != IVAS_ERR_OK ) { return error; } +#endif } /* initialization */ @@ -262,7 +265,7 @@ ivas_error ivas_spar_enc_open( hSpar->hCoreCoderVAD->total_brate = hEncoderConfig->ivas_total_brate; /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() */ hSpar->hCoreCoderVAD->mct_chan_mode = MCT_CHAN_MODE_IGNORE; - if ( ( error = init_encoder( hSpar->hCoreCoderVAD, st_ivas, 0, hEncoderConfig->var_SID_rate_flag, hEncoderConfig->interval_SID, 1, st_ivas->ism_mode, hSpar->hCoreCoderVAD->total_brate ) ) != IVAS_ERR_OK ) + if ( ( error = init_encoder_ivas_fx( hSpar->hCoreCoderVAD, st_ivas, 0, hEncoderConfig->var_SID_rate_flag, hEncoderConfig->interval_SID, 1, st_ivas->ism_mode, hSpar->hCoreCoderVAD->total_brate ) ) != IVAS_ERR_OK ) { return error; } @@ -375,7 +378,7 @@ ivas_error ivas_spar_enc_open_fx( IF( !spar_reconfig_flag ) { /* Transient Detector handle */ - IF( ( error = ivas_transient_det_open( &( hSpar->hTranDet ), input_Fs ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_transient_det_open_fx( &( hSpar->hTranDet ), input_Fs ) ) != IVAS_ERR_OK ) { return error; } @@ -546,7 +549,11 @@ void ivas_spar_enc_close( if ( !spar_reconfig_flag ) { /* Trans Det handle */ +#ifdef IVAS_FLOAT_FIXED + ivas_transient_det_close_fx( &( *hSpar )->hTranDet ); +#else ivas_transient_det_close( &( *hSpar )->hTranDet ); +#endif free( ( *hSpar ) ); ( *hSpar ) = NULL; } @@ -661,10 +668,6 @@ static ivas_error ivas_spar_cov_md_process( Word16 i, j, i_ts, b, table_idx; Word16 active_w_vlbr; /* note: the actual dimensions of matrixes correspond to num_channels = ivas_sba_get_nchan_metadata( sba_order, ivas_total_brate ); */ - float *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH]; - float *cov_dtx_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH]; - float cov_real_buf[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH][IVAS_MAX_NUM_BANDS]; - float cov_dtx_real_buf[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH][IVAS_MAX_NUM_BANDS]; #ifdef IVAS_FLOAT_FIXED Word32 *cov_real_fx[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH]; Word32 *cov_dtx_real_fx[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH]; @@ -716,29 +719,13 @@ static ivas_error ivas_spar_cov_md_process( num_bands = IVAS_MAX_NUM_BANDS; move16(); } - ivas_spar_set_bitrate_config( &hSpar->hMdEnc->spar_md_cfg, table_idx, num_bands, hSpar->hMdEnc->spar_hoa_dirac2spar_md_flag, 1, hEncoderConfig->Opt_PCA_ON, hSpar->AGC_Enable ); + ivas_spar_set_bitrate_config_fx( &hSpar->hMdEnc->spar_md_cfg, table_idx, num_bands, hSpar->hMdEnc->spar_hoa_dirac2spar_md_flag, 1, hEncoderConfig->Opt_PCA_ON, hSpar->AGC_Enable ); } } /*-----------------------------------------------------------------------------------------* * Covariance process *-----------------------------------------------------------------------------------------*/ - - for ( i = 0; i < nchan_inp; i++ ) - { - for ( j = 0; j < nchan_inp; j++ ) - { - cov_real[i][j] = cov_real_buf[i][j]; - cov_dtx_real[i][j] = cov_dtx_real_buf[i][j]; - for ( b = hSpar->hFbMixer->pFb->filterbank_num_bands; b < IVAS_MAX_NUM_BANDS; b++ ) - { - cov_real[i][j][b] = 0.0f; - cov_dtx_real[i][j][b] = 0.0f; - } - } - } - -#ifdef IVAS_FLOAT_FIXED FOR( i = 0; i < nchan_inp; i++ ) { FOR( j = 0; j < nchan_inp; j++ ) @@ -757,14 +744,13 @@ static ivas_error ivas_spar_cov_md_process( { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR COV encoder Fixed" ); } - set_s( q_cov_real[i], Q31, nchan_inp ); + set16_fx( q_cov_real[i], Q31, nchan_inp ); IF( ( q_cov_dtx_real[i] = (Word16 *) malloc( sizeof( Word16 ) * nchan_inp ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR COV encoder Fixed" ); } - set_s( q_cov_dtx_real[i], Q31, nchan_inp ); + set16_fx( q_cov_dtx_real[i], Q31, nchan_inp ); } -#endif ivas_enc_cov_handler_process_fx( hSpar->hCovEnc, ppIn_FR_real_fx, ppIn_FR_imag_fx, q_ppIn_FR, cov_real_fx, q_cov_real, cov_dtx_real_fx, q_cov_dtx_real, hSpar->hFbMixer->pFb, 0, hSpar->hFbMixer->pFb->filterbank_num_bands, nchan_inp, dtx_vad, transient_det, hSpar->hMdEnc->HOA_md_ind, &hSpar->hMdEnc->spar_md.res_ind, remix_order_set[hSpar->hMdEnc->spar_md_cfg.remix_unmix_order], dyn_active_w_flag, nchan_transport, 1 ); @@ -772,15 +758,6 @@ static ivas_error ivas_spar_cov_md_process( #ifdef IVAS_FLOAT_FIXED_CONVERSIONS FOR( i = 0; i < nchan_inp; i++ ) { - FOR( j = 0; j < nchan_inp; j++ ) - { - Word16 k; - FOR( k = 0; k < hSpar->hFbMixer->pFb->filterbank_num_bands; k++ ) - { - cov_real[i][j][k] = me2f( cov_real_fx[i][j][k], sub( Q31, hSpar->hCovEnc->pCov_state->q_cov_real_per_band[i][j][k] ) ); - cov_dtx_real[i][j][k] = me2f( cov_dtx_real_fx[i][j][k], sub( Q31, hSpar->hCovEnc->pCov_dtx_state->q_cov_real_per_band[i][j][k] ) ); - } - } free( q_cov_real[i] ); q_cov_real[i] = NULL; free( q_cov_dtx_real[i] ); @@ -821,7 +798,7 @@ static ivas_error ivas_spar_cov_md_process( IF( hSpar->hMdEnc->spar_hoa_md_flag == 0 ) { - IF( NE_32( ( error = ivas_spar_md_enc_process_fx( hSpar->hMdEnc, hEncoderConfig, cov_real_fx, hSpar->hCovEnc->pCov_state->q_cov_real_per_band, cov_dtx_real_fx, hSpar->hCovEnc->pCov_dtx_state->q_cov_real_per_band, hMetaData, dtx_vad, nchan_inp, sba_order, hSpar->hFbMixer->prior_mixer, *dyn_active_w_flag, hQMetaData->dirac_mono_flag ) ), IVAS_ERR_OK ) ) + IF( NE_32( ( error = ivas_spar_md_enc_process_fx( hSpar->hMdEnc, hEncoderConfig, cov_real_fx, hSpar->hCovEnc->pCov_state->q_cov_real_per_band, cov_dtx_real_fx, hSpar->hCovEnc->pCov_dtx_state->q_cov_real_per_band, hMetaData, dtx_vad, nchan_inp, sba_order, hSpar->hFbMixer->prior_mixer_fx, &hSpar->hFbMixer->q_prior_mixer_fx, *dyn_active_w_flag, hQMetaData->dirac_mono_flag, hSpar->hFbMixer->fb_cfg->num_out_chans ) ), IVAS_ERR_OK ) ) { return error; } @@ -892,35 +869,21 @@ static ivas_error ivas_spar_cov_md_process( move32(); } -#ifdef IVAS_FLOAT_FIXED #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - for ( b = 0; b < IVAS_MAX_NUM_BANDS; b++ ) + FOR( b = 0; b < IVAS_MAX_NUM_BANDS; b++ ) { - for ( i = 0; i < IVAS_SPAR_MAX_CH - 1; i++ ) + FOR( i = 0; i < IVAS_SPAR_MAX_CH - 1; i++ ) { hSpar->hMdEnc->spar_md.band_coeffs[b].P_re_fx[i] = L_shr( hSpar->hMdEnc->spar_md.band_coeffs[b].P_re_fx[i], Q6 ); + move32(); hSpar->hMdEnc->spar_md.band_coeffs[b].pred_re_fx[i] = L_shr( hSpar->hMdEnc->spar_md.band_coeffs[b].pred_re_fx[i], Q6 ); + move32(); } hSpar->hMdEnc->spar_md.band_coeffs[b].q_P_re_fx = Q22; + move16(); hSpar->hMdEnc->spar_md.band_coeffs[b].q_pred_re_fx = Q22; + move16(); } - Word16 num_ch = ivas_sba_get_nchan_metadata_fx( sba_order, hEncoderConfig->ivas_total_brate ); - Word16 q_mixer_mat = 26; - for ( i = 0; i < num_ch; i++ ) - { - for ( j = 0; j < num_ch; j++ ) - { - q_mixer_mat = min( q_mixer_mat, Q_factor_arrL( hSpar->hMdEnc->mixer_mat[i][j], IVAS_MAX_NUM_BANDS ) ); - } - } - for ( i = 0; i < num_ch; i++ ) - { - for ( j = 0; j < num_ch; j++ ) - { - floatToFixed_arr32( hSpar->hMdEnc->mixer_mat[i][j], hSpar->hMdEnc->mixer_mat_fx[i][j], q_mixer_mat, IVAS_MAX_NUM_BANDS ); - } - } - hSpar->hMdEnc->q_mixer_mat_fx = q_mixer_mat; #endif IF( hSpar->hMdEnc->spar_hoa_md_flag == 0 ) { @@ -934,35 +897,26 @@ static ivas_error ivas_spar_cov_md_process( } ivas_get_spar_md_from_dirac_fx( azi_dirac_fx, ele_dirac_fx, diffuseness_fx, 1, hSpar->hMdEnc->mixer_mat_fx, &hSpar->hMdEnc->q_mixer_mat_fx, &hSpar->hMdEnc->spar_md, &hSpar->hMdEnc->spar_md_cfg, d_start_band, d_end_band, order, dtx_vad, Wscale_d_fx, hQMetaData->useLowerRes, active_w_vlbr, *dyn_active_w_flag ); #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - for ( b = 0; b < IVAS_MAX_NUM_BANDS; b++ ) + FOR( b = 0; b < IVAS_MAX_NUM_BANDS; b++ ) { - for ( i = 0; i < IVAS_SPAR_MAX_CH - 1; i++ ) + FOR( i = 0; i < IVAS_SPAR_MAX_CH - 1; i++ ) { hSpar->hMdEnc->spar_md.band_coeffs[b].P_re_fx[i] = L_shl( hSpar->hMdEnc->spar_md.band_coeffs[b].P_re_fx[i], Q6 ); + move32(); hSpar->hMdEnc->spar_md.band_coeffs[b].pred_re_fx[i] = L_shl( hSpar->hMdEnc->spar_md.band_coeffs[b].pred_re_fx[i], Q6 ); + move32(); } hSpar->hMdEnc->spar_md.band_coeffs[b].q_P_re_fx = Q28; + move16(); hSpar->hMdEnc->spar_md.band_coeffs[b].q_pred_re_fx = Q28; + move16(); } - for ( b = 0; b < IVAS_MAX_NUM_BANDS; b++ ) - { - for ( i = 0; i < num_ch; i++ ) - { - for ( j = 0; j < num_ch; j++ ) - { - hSpar->hMdEnc->mixer_mat[i][j][b] = fixedToFloat_32( hSpar->hMdEnc->mixer_mat_fx[i][j][b], hSpar->hMdEnc->q_mixer_mat_fx ); - } - } - } -#endif -#else - ivas_get_spar_md_from_dirac( azi_dirac, ele_dirac, diffuseness, 1, hSpar->hMdEnc->mixer_mat, &hSpar->hMdEnc->spar_md, &hSpar->hMdEnc->spar_md_cfg, d_start_band, d_end_band, ( hSpar->hMdEnc->spar_hoa_md_flag ) ? 1 : sba_order, dtx_vad, Wscale_d, hQMetaData->useLowerRes, active_w_vlbr, *dyn_active_w_flag ); #endif } IF( hSpar->hMdEnc->spar_hoa_md_flag ) { - error = ivas_spar_md_enc_process_fx( hSpar->hMdEnc, hEncoderConfig, cov_real_fx, hSpar->hCovEnc->pCov_state->q_cov_real_per_band, cov_dtx_real_fx, hSpar->hCovEnc->pCov_dtx_state->q_cov_real_per_band, hMetaData, dtx_vad, nchan_inp, sba_order, hSpar->hFbMixer->prior_mixer, *dyn_active_w_flag, hQMetaData->dirac_mono_flag ); + error = ivas_spar_md_enc_process_fx( hSpar->hMdEnc, hEncoderConfig, cov_real_fx, hSpar->hCovEnc->pCov_state->q_cov_real_per_band, cov_dtx_real_fx, hSpar->hCovEnc->pCov_dtx_state->q_cov_real_per_band, hMetaData, dtx_vad, nchan_inp, sba_order, hSpar->hFbMixer->prior_mixer_fx, &hSpar->hFbMixer->q_prior_mixer_fx, *dyn_active_w_flag, hQMetaData->dirac_mono_flag, hSpar->hFbMixer->fb_cfg->num_out_chans ); } return error; @@ -1161,12 +1115,6 @@ static ivas_error ivas_spar_enc_process( hSpar->hFbMixer->q_ppFilterbank_inFR_re_fx[hSpar->hFbMixer->fb_cfg->remix_order[x]] = q_p_pcm_tmp_fx[hSpar->hFbMixer->fb_cfg->remix_order[x]]; hSpar->hFbMixer->q_ppFilterbank_inFR_im_fx[hSpar->hFbMixer->fb_cfg->remix_order[x]] = q_p_pcm_tmp_fx[hSpar->hFbMixer->fb_cfg->remix_order[x]]; - - me2f_buf( hSpar->hFbMixer->ppFilterbank_inFR_re_fx[hSpar->hFbMixer->fb_cfg->remix_order[x]], 31 - q_p_pcm_tmp_fx[hSpar->hFbMixer->fb_cfg->remix_order[x]], - hSpar->hFbMixer->ppFilterbank_inFR_re[hSpar->hFbMixer->fb_cfg->remix_order[x]], input_frame ); - - me2f_buf( hSpar->hFbMixer->ppFilterbank_inFR_im_fx[hSpar->hFbMixer->fb_cfg->remix_order[x]], 31 - q_p_pcm_tmp_fx[hSpar->hFbMixer->fb_cfg->remix_order[x]], - hSpar->hFbMixer->ppFilterbank_inFR_im[hSpar->hFbMixer->fb_cfg->remix_order[x]], input_frame ); } /* Need to remove fix to flt conversions */ #endif @@ -1383,45 +1331,6 @@ static ivas_error ivas_spar_enc_process( } #endif #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - Word16 mixer_q = 31; - Word16 prior_mixer_q = 31; - Word32 num_channels = ivas_sba_get_nchan_metadata_fx( sba_order, hEncoderConfig->ivas_total_brate ); - for ( i = 0; i < num_channels; i++ ) - { - for ( j = 0; j < num_channels; j++ ) - { - mixer_q = s_min( mixer_q, Q_factor_arrL( hSpar->hMdEnc->mixer_mat[i][j], IVAS_MAX_NUM_BANDS ) ); - } - } - for ( i = 0; i < hSpar->hFbMixer->fb_cfg->num_out_chans; i++ ) - { - for ( j = 0; j < hSpar->hFbMixer->fb_cfg->num_in_chans; j++ ) - { - prior_mixer_q = s_min( prior_mixer_q, Q_factor_arrL( hSpar->hFbMixer->prior_mixer[i][j], IVAS_MAX_NUM_BANDS ) ); - } - } - - mixer_q = s_min( mixer_q, prior_mixer_q ); - // both should have a common q as there are values being copied inside function - // or need to do loop for updating values for unused values - - for ( i = 0; i < num_channels; i++ ) - { - for ( j = 0; j < num_channels; j++ ) - { - floatToFixed_arrL32( hSpar->hMdEnc->mixer_mat[i][j], hSpar->hMdEnc->mixer_mat_fx[i][j], mixer_q, IVAS_MAX_NUM_BANDS ); - } - } - for ( i = 0; i < hSpar->hFbMixer->fb_cfg->num_out_chans; i++ ) - { - for ( j = 0; j < hSpar->hFbMixer->fb_cfg->num_in_chans; j++ ) - { - floatToFixed_arrL32( hSpar->hFbMixer->prior_mixer[i][j], hSpar->hFbMixer->prior_mixer_fx[i][j], mixer_q, IVAS_MAX_NUM_BANDS ); - } - } - - hSpar->hMdEnc->q_mixer_mat_fx = mixer_q; - hSpar->hFbMixer->q_prior_mixer_fx = mixer_q; Word16 q_p_pcm_tmp_loc_fx[DIRAC_MAX_ANA_CHANS]; #endif @@ -1437,17 +1346,6 @@ static ivas_error ivas_spar_enc_process( p_pcm_tmp[ch][k] = (float) fixedToFloat( p_pcm_tmp_fx[ch][k], q_p_pcm_tmp_loc_fx[ch] ); } } - - // hSpar->hMdEnc->q_mixer_mat_fx = mixer_q; - // hSpar->hFbMixer->q_prior_mixer_fx = mixer_q; - // should be same - for ( i = 0; i < hSpar->hFbMixer->fb_cfg->num_out_chans; i++ ) - { - for ( j = 0; j < hSpar->hFbMixer->fb_cfg->num_in_chans; j++ ) - { - fixedToFloat_arrL32( hSpar->hFbMixer->prior_mixer_fx[i][j], hSpar->hFbMixer->prior_mixer[i][j], hSpar->hFbMixer->q_prior_mixer_fx, IVAS_MAX_NUM_BANDS ); - } - } #endif if ( hSpar->hFbMixer->fb_cfg->active_w_mixing == 0 ) { diff --git a/lib_enc/ivas_spar_md_enc.c b/lib_enc/ivas_spar_md_enc.c index b2413c928..1b07f61a6 100644 --- a/lib_enc/ivas_spar_md_enc.c +++ b/lib_enc/ivas_spar_md_enc.c @@ -174,24 +174,6 @@ ivas_error ivas_spar_md_enc_open( { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for band_coeffs in SPAR MD" ); } - if ( ( hMdEnc->mixer_mat = (float ***) malloc( num_channels * sizeof( float ** ) ) ) == NULL ) - { - return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix" ); - } - for ( i = 0; i < num_channels; i++ ) - { - if ( ( hMdEnc->mixer_mat[i] = (float **) malloc( num_channels * sizeof( float * ) ) ) == NULL ) - { - return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix" ); - } - for ( j = 0; j < num_channels; j++ ) - { - if ( ( hMdEnc->mixer_mat[i][j] = (float *) malloc( IVAS_MAX_NUM_BANDS * sizeof( float ) ) ) == NULL ) - { - return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix" ); - } - } - } IF( ( hMdEnc->mixer_mat_fx = (Word32 ***) malloc( num_channels * sizeof( Word32 ** ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix" ); @@ -323,18 +305,6 @@ void ivas_spar_md_enc_close( free( hMdEnc->spar_md.band_coeffs ); hMdEnc->spar_md.band_coeffs = NULL; } - if ( hMdEnc->mixer_mat != NULL ) - { - for ( i = 0; i < num_channels; i++ ) - { - for ( j = 0; j < num_channels; j++ ) - { - free( hMdEnc->mixer_mat[i][j] ); - } - free( hMdEnc->mixer_mat[i] ); - } - free( hMdEnc->mixer_mat ); - } #ifdef IVAS_FLOAT_FIXED IF( hMdEnc->mixer_mat_fx != NULL ) { @@ -475,18 +445,6 @@ ivas_error ivas_spar_md_enc_init( hMdEnc->spar_md_cfg.prior_strat = START; hMdEnc->spar_md_cfg.prev_quant_idx = -1; - - for ( i = 0; i < num_channels; i++ ) - { - for ( j = 0; j < num_channels; j++ ) - { - for ( k = 0; k < IVAS_MAX_NUM_BANDS; k++ ) - { - hMdEnc->mixer_mat[i][j][k] = 0; - } - } - } - #ifdef MSAN_FIX FOR( i = 0; i < num_channels; i++ ) { @@ -499,6 +457,8 @@ ivas_error ivas_spar_md_enc_init( } } } + hMdEnc->q_mixer_mat_fx = Q31; + move16(); #endif ivas_clear_band_coeffs_fx( hMdEnc->spar_md.band_coeffs, IVAS_MAX_NUM_BANDS ); @@ -581,19 +541,6 @@ ivas_error ivas_spar_md_enc_init_fx( } } } -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - FOR( i = 0; i < num_channels; i++ ) - { - FOR( j = 0; j < num_channels; j++ ) - { - FOR( k = 0; k < IVAS_MAX_NUM_BANDS; k++ ) - { - hMdEnc->mixer_mat[i][j][k] = 0.0f; - move32(); - } - } - } -#endif hMdEnc->q_mixer_mat_fx = 0; move16(); ivas_clear_band_coeffs_fx( hMdEnc->spar_md.band_coeffs, IVAS_MAX_NUM_BANDS ); @@ -826,11 +773,12 @@ ivas_error ivas_spar_md_enc_process_fx( BSTR_ENC_HANDLE hMetaData, /* i/o: MetaData handle */ const Word16 dtx_vad, const Word16 nchan_inp, - const Word16 sba_order, /* i : Ambisonic (SBA) order */ - float *prior_mixer[IVAS_MAX_FB_MIXER_OUT_CH][IVAS_MAX_SPAR_FB_MIXER_IN_CH], /* i : prior mixer_matrix */ - const Word16 dyn_active_w_flag, /* i : flag to indicate dynamic active W */ - const Word16 dirac_mono_flag /* i : flag to indicate mono only mode in SBA */ -) + const Word16 sba_order, /* i : Ambisonic (SBA) order */ + Word32 *prior_mixer[IVAS_MAX_FB_MIXER_OUT_CH][IVAS_MAX_SPAR_FB_MIXER_IN_CH], /* i : prior mixer_matrix */ + Word16 *q_prior_mixer, /* i/o : q for prior mixer_matrix */ + const Word16 dyn_active_w_flag, /* i : flag to indicate dynamic active W */ + const Word16 dirac_mono_flag, /* i : flag to indicate mono only mode in SBA */ + const Word16 nchan_out ) { Word32 pred_coeffs_re_fx[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS]; Word32 dm_fv_re_fx[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS]; @@ -1197,15 +1145,6 @@ ivas_error ivas_spar_md_enc_process_fx( { ivas_band_mixing_fx( hMdEnc, num_ch, num_bands, nchan_transport, num_bands_full ); } -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - for ( i = 0; i < num_ch; i++ ) - { - for ( j = 0; j < num_ch; j++ ) - { - fixedToFloat_arrL32( hMdEnc->mixer_mat_fx[i][j], hMdEnc->mixer_mat[i][j], hMdEnc->q_mixer_mat_fx, IVAS_MAX_NUM_BANDS ); - } - } -#endif IF( dtx_vad == 0 ) { @@ -1285,8 +1224,38 @@ ivas_error ivas_spar_md_enc_process_fx( } } } - - + IF( GT_16( hMdEnc->q_mixer_mat_fx, *q_prior_mixer ) ) + { + FOR( i = 0; i < num_ch; i++ ) + { + FOR( j = 0; j < num_ch; j++ ) + { + FOR( b = 0; b < IVAS_MAX_NUM_BANDS; b++ ) + { + hMdEnc->mixer_mat_fx[i][j][b] = L_shr( hMdEnc->mixer_mat_fx[i][j][b], sub( hMdEnc->q_mixer_mat_fx, *q_prior_mixer ) ); + move32(); + } + } + } + hMdEnc->q_mixer_mat_fx = *q_prior_mixer; + move16(); + } + ELSE + { + FOR( i = 0; i < nchan_out; i++ ) + { + FOR( j = 0; j < num_ch; j++ ) + { + FOR( b = 0; b < IVAS_MAX_NUM_BANDS; b++ ) + { + prior_mixer[i][j][b] = L_shr( prior_mixer[i][j][b], sub( *q_prior_mixer, hMdEnc->q_mixer_mat_fx ) ); + move32(); + } + } + } + *q_prior_mixer = hMdEnc->q_mixer_mat_fx; + move16(); + } /* Reuse mixer matrix values for unsent bands */ test(); IF( ( LT_32( hEncoderConfig->ivas_total_brate, IVAS_24k4 ) ) && GT_16( code_strat, 3 ) ) @@ -1302,9 +1271,10 @@ ivas_error ivas_spar_md_enc_process_fx( { FOR( j = 0; j < 4; j++ ) { - // TODO once fb-mixer changes are final - hMdEnc->mixer_mat[i][j][b] = prior_mixer[i][j][b]; - hMdEnc->mixer_mat[i][j][b + 1] = prior_mixer[i][j][b + 1]; + hMdEnc->mixer_mat_fx[i][j][b] = prior_mixer[i][j][b]; + move32(); + hMdEnc->mixer_mat_fx[i][j][b + 1] = prior_mixer[i][j][b + 1]; + move32(); } } } diff --git a/lib_enc/ivas_stat_enc.h b/lib_enc/ivas_stat_enc.h index 0286115d7..eae425507 100644 --- a/lib_enc/ivas_stat_enc.h +++ b/lib_enc/ivas_stat_enc.h @@ -1059,7 +1059,6 @@ typedef struct ivas_spar_md_enc_state_t Word16 num_umx_ch; Word16 num_decorr; - float ***mixer_mat; ivas_spar_md_com_cfg spar_md_cfg; ivas_arith_coeffs_t arith_coeffs; ivas_huff_coeffs_t huff_coeffs; @@ -1822,9 +1821,10 @@ typedef struct Word16 sba_analysis_order; /* Ambisonic (SBA) order used for analysis and coding */ Word16 codec_mode; /* Mode1 or Mode2 of core codec */ Word16 last_codec_mode; /* previous frame Mode 1 or 2 */ - float **mem_hp20_in; /* input signals HP filter memories */ #ifdef IVAS_FLOAT_FIXED Word32 **mem_hp20_in_fx; /* input signals HP filter memories */ +#else + float **mem_hp20_in; /* input signals HP filter memories */ #endif /* core-encoder modules */ diff --git a/lib_enc/ivas_tcx_core_enc.c b/lib_enc/ivas_tcx_core_enc.c index b2dd2863f..2ba28fcf6 100644 --- a/lib_enc/ivas_tcx_core_enc.c +++ b/lib_enc/ivas_tcx_core_enc.c @@ -1738,7 +1738,14 @@ Word16 ivas_acelp_tcx20_switching_fx( basop_weight_a( A_q_tcx_fx, Ap_fx, 30147 /*0.92 in Q15*/ ); basop_lpc2mdct( Ap_fx, M, gainlpc_fx, gainlpc_e, gainlpc_noinv, gainlpc_noinv_e ); - + Word16 com_gainlpc_e = 0; + move16(); + FOR( i = 0; i < FDNS_NPTS; i++ ) + { + com_gainlpc_e = s_max( com_gainlpc_e, gainlpc_e[i] ); + } + Copy_Scale_sig32( x_fx, x_fx, L_frame, -com_gainlpc_e ); + e_x = add( e_x, com_gainlpc_e ); mdct_shaping( x_fx, L_frame, gainlpc_fx, gainlpc_e ); FOR( i = 0; i < L_frame_4; i++ ) @@ -1748,20 +1755,20 @@ Word16 ivas_acelp_tcx20_switching_fx( move16(); tmp16 = norm_l( x_fx[0] ); - if ( x_fx[0] != 0 ) - s = s_min( s, tmp16 ); + IF( x_fx[0] != 0 ) + s = s_min( s, tmp16 ); tmp16 = norm_l( x_fx[1] ); - if ( x_fx[1] != 0 ) - s = s_min( s, tmp16 ); + IF( x_fx[1] != 0 ) + s = s_min( s, tmp16 ); tmp16 = norm_l( x_fx[2] ); - if ( x_fx[2] != 0 ) - s = s_min( s, tmp16 ); + IF( x_fx[2] != 0 ) + s = s_min( s, tmp16 ); tmp16 = norm_l( x_fx[3] ); - if ( x_fx[3] != 0 ) - s = s_min( s, tmp16 ); + IF( x_fx[3] != 0 ) + s = s_min( s, tmp16 ); s = sub( s, 2 ); /* 2 bits headroom */ @@ -1803,28 +1810,28 @@ Word16 ivas_acelp_tcx20_switching_fx( { tmp32 = L_sub( en[i], offset ); - if ( GT_32( tmp32, 0xFF20 ) ) /* 0xFF20 -> 3.f * log2(10)/10 */ + IF( GT_32( tmp32, 0xFF20 ) ) /* 0xFF20 -> 3.f * log2(10)/10 */ { ener = L_add( ener, tmp32 ); } tmp32 = L_sub( en[i + 1], offset ); - if ( GT_32( tmp32, 0xFF20 ) ) /* 0xFF20 -> 3.f * log2(10)/10 */ + IF( GT_32( tmp32, 0xFF20 ) ) /* 0xFF20 -> 3.f * log2(10)/10 */ { ener = L_add( ener, tmp32 ); } tmp32 = L_sub( en[i + 2], offset ); - if ( GT_32( tmp32, 0xFF20 ) ) /* 0xFF20 -> 3.f * log2(10)/10 */ + IF( GT_32( tmp32, 0xFF20 ) ) /* 0xFF20 -> 3.f * log2(10)/10 */ { ener = L_add( ener, tmp32 ); } tmp32 = L_sub( en[i + 3], offset ); - if ( GT_32( tmp32, 0xFF20 ) ) /* 0xFF20 -> 3.f * log2(10)/10 */ + IF( GT_32( tmp32, 0xFF20 ) ) /* 0xFF20 -> 3.f * log2(10)/10 */ { ener = L_add( ener, tmp32 ); } @@ -1837,7 +1844,7 @@ Word16 ivas_acelp_tcx20_switching_fx( } } - if ( LE_32( offset, 0xAA153 ) ) /* 0xAA153 -> 32.f * log2(10)/10 */ + IF( LE_32( offset, 0xAA153 ) ) /* 0xAA153 -> 32.f * log2(10)/10 */ { offset = L_add( 0xFFD57AB5, 0 ); /* 0xFFD57AB5 -> -128.f * log2(10)/10; */ } @@ -1875,6 +1882,7 @@ Word16 ivas_acelp_tcx20_switching_fx( Word32 nrg_s, nrg_n; Word16 temp_e, e_num, e_den, temp_ene_e; temp_ene_e = ener_e; + move16(); tmp32 = Sqrt32( ener, &temp_ene_e ); /*Approximate SNR of TCX*/ set32_fx( x_fx, tmp32, L_frame ); /* ener_e */ @@ -2037,6 +2045,7 @@ Word16 ivas_acelp_tcx20_switching_fx( tmp32 = Mpy_32_16_1( temp_energy, tmp16 ); /*ener_e*/ tmp32 = L_shr( Mpy_32_16_1( tmp32, 0x6054 /* 0x6054 -> 10/log2(10) (2Q13) */ ), sub( 13, ener_e ) ); /* Q16*/ snr_acelp = tmp32; + move32(); /*--------------------------------------------------------------* * Switching Decision diff --git a/lib_enc/lib_enc.c b/lib_enc/lib_enc.c index ac29e728e..ce072891d 100644 --- a/lib_enc/lib_enc.c +++ b/lib_enc/lib_enc.c @@ -71,16 +71,14 @@ static ivas_error setBandwidth_fx( IVAS_ENC_HANDLE hIvasEnc, const IVAS_ENC_BAND static ivas_error setChannelAwareConfig_fx( IVAS_ENC_HANDLE hIvasEnc, const IVAS_ENC_CHANNEL_AWARE_CONFIG caConfig ); static ivas_error sanitizeBandwidth_fx( const IVAS_ENC_HANDLE hIvasEnc ); static ivas_error sanitizeBitrateISM_fx( const ENCODER_CONFIG_HANDLE hEncoderConfig, const bool extMetadataApi ); +static Word16 getInputBufferSize_fx( const Encoder_Struct *st_ivas ); +#else +static int16_t getInputBufferSize( const Encoder_Struct *st_ivas ); #endif // IVAS_FLOAT_FIXED static ivas_error configureEncoder( IVAS_ENC_HANDLE hIvasEnc, const int32_t inputFs, const int32_t initBitrate, const IVAS_ENC_BANDWIDTH initBandwidth, const IVAS_ENC_DTX_CONFIG dtxConfig, const IVAS_ENC_CHANNEL_AWARE_CONFIG caConfig ); -static ivas_error setBandwidth( IVAS_ENC_HANDLE hIvasEnc, const IVAS_ENC_BANDWIDTH maxBandwidth ); static ivas_error setBitrate( IVAS_ENC_HANDLE hIvasEnc, const int32_t totalBitrate ); -static ivas_error setChannelAwareConfig( IVAS_ENC_HANDLE hIvasEnc, const IVAS_ENC_CHANNEL_AWARE_CONFIG caConfig ); -static int16_t getInputBufferSize( const Encoder_Struct *st_ivas ); static ivas_error doCommonConfigureChecks( IVAS_ENC_HANDLE hIvasEnc ); static ivas_error doCommonSetterChecks( IVAS_ENC_HANDLE hIvasEnc ); -static ivas_error sanitizeBandwidth( const IVAS_ENC_HANDLE hIvasEnc ); -static ivas_error sanitizeBitrateISM( const ENCODER_CONFIG_HANDLE hEncoderConfig, const bool extMetadataApi ); static void init_encoder_config( ENCODER_CONFIG_HANDLE hEncoderConfig ); static void resetIsmMetadataProvidedFlags( IVAS_ENC_HANDLE hIvasEnc ); static ivas_error bandwidthApiToInternal( const IVAS_ENC_BANDWIDTH maxBandwidth, int16_t *internalMaxBandwidth ); @@ -650,11 +648,11 @@ ivas_error IVAS_ENC_ConfigureForAmbisonics_fx( ivas_error IVAS_ENC_ConfigureForSBAObjects( IVAS_ENC_HANDLE hIvasEnc, /* i/o: IVAS encoder handle */ - const int32_t inputFs, /* i : input sampling frequency */ - const int32_t bitrate, /* i : requested bitrate of the ouput bitstream */ + const Word32 inputFs, /* i : input sampling frequency */ + const Word32 bitrate, /* i : requested bitrate of the ouput bitstream */ const IVAS_ENC_BANDWIDTH maxBandwidth, /* i : bandwidth limitation */ const IVAS_ENC_DTX_CONFIG dtxConfig, /* i : configuration of DTX, can by set to default by using IVAS_ENC_GetDefaultDtxConfig() */ - const uint16_t numObjects, /* i : number of objects to be encoded */ + const UWord16 numObjects, /* i : number of objects to be encoded */ const IVAS_ENC_SBA_ORDER order, /* i : order of the Ambisonics input */ const bool isPlanar, /* i : if true, input is treated as planar Ambisonics */ const bool Opt_PCA_ON /* i : PCA option flag */ @@ -663,35 +661,38 @@ ivas_error IVAS_ENC_ConfigureForSBAObjects( Encoder_Struct *st_ivas; ivas_error error; - if ( ( error = doCommonConfigureChecks( hIvasEnc ) ) != IVAS_ERR_OK ) + IF( NE_16( ( error = doCommonConfigureChecks( hIvasEnc ) ), IVAS_ERR_OK ) ) { return error; } - if ( numObjects > MAX_NUM_OBJECTS ) + IF( GT_32( numObjects, MAX_NUM_OBJECTS ) ) { return IVAS_ERR_TOO_MANY_INPUTS; } st_ivas = hIvasEnc->st_ivas; st_ivas->hEncoderConfig->element_mode_init = IVAS_SCE; /* Just needs to be something not mono, will be set later */ + move16(); st_ivas->hEncoderConfig->sba_planar = isPlanar; + move16(); st_ivas->hEncoderConfig->sba_order = order; + move16(); /* Input in ACN/SN3D in all cases (3D and planar): get number of channels */ /*Input file will always contain all channels for a given order irrespective of planar flag*/ -#ifndef IVAS_FLOAT_FIXED - st_ivas->hEncoderConfig->nchan_inp = ivas_sba_get_nchan( st_ivas->hEncoderConfig->sba_order, 0 ) + numObjects; -#else - st_ivas->hEncoderConfig->nchan_inp = add( ivas_sba_get_nchan_fx( st_ivas->hEncoderConfig->sba_order, 0 ), (Word16) numObjects ); -#endif - - st_ivas->hEncoderConfig->Opt_PCA_ON = (int16_t) Opt_PCA_ON; + st_ivas->hEncoderConfig->nchan_inp = add( ivas_sba_get_nchan_fx( st_ivas->hEncoderConfig->sba_order, 0 ), numObjects ); + move16(); + st_ivas->hEncoderConfig->Opt_PCA_ON = extract_l( Opt_PCA_ON ); + move16(); /* Currently this is true but it is already shown in descriptive metadata that there can be inequality for this. */ - st_ivas->nchan_transport = st_ivas->hEncoderConfig->nchan_inp - numObjects; + st_ivas->nchan_transport = sub( st_ivas->hEncoderConfig->nchan_inp, numObjects ); + move16(); st_ivas->hEncoderConfig->ivas_format = SBA_ISM_FORMAT; + move16(); st_ivas->hEncoderConfig->nchan_ism = numObjects; + move16(); return configureEncoder( hIvasEnc, inputFs, bitrate, maxBandwidth, dtxConfig, IVAS_ENC_GetDefaultChannelAwareConfig() ); } @@ -919,7 +920,7 @@ static ivas_error configureEncoder( * Bandwidth limitation *-----------------------------------------------------------------*/ - if ( ( error = setBandwidth( hIvasEnc, initBandwidth ) ) != IVAS_ERR_OK ) + if ( ( error = setBandwidth_fx( hIvasEnc, initBandwidth ) ) != IVAS_ERR_OK ) { return error; } @@ -978,7 +979,7 @@ static ivas_error configureEncoder( /* check if the entered bitrate is supported */ if ( hEncoderConfig->ivas_format != UNDEFINED_FORMAT && hEncoderConfig->ivas_format != MONO_FORMAT ) /* IVAS */ { - if ( !is_IVAS_bitrate( hEncoderConfig->ivas_total_brate ) ) + if ( !is_IVAS_bitrate_fx( hEncoderConfig->ivas_total_brate ) ) { if ( hEncoderConfig->Opt_SC_VBR ) { @@ -1017,7 +1018,7 @@ static ivas_error configureEncoder( } else if ( hEncoderConfig->ivas_format == ISM_FORMAT ) { - if ( ( error = sanitizeBitrateISM( hEncoderConfig, hIvasEnc->extMetadataApi ) ) != IVAS_ERR_OK ) + if ( ( error = sanitizeBitrateISM_fx( hEncoderConfig, hIvasEnc->extMetadataApi ) ) != IVAS_ERR_OK ) { return error; } @@ -1099,7 +1100,7 @@ static ivas_error configureEncoder( * Channel-aware mode *-----------------------------------------------------------------*/ - if ( ( error = setChannelAwareConfig( hIvasEnc, caConfig ) ) != IVAS_ERR_OK ) + if ( ( error = setChannelAwareConfig_fx( hIvasEnc, caConfig ) ) != IVAS_ERR_OK ) { return error; } @@ -1153,7 +1154,7 @@ static ivas_error configureEncoder( return IVAS_ERROR( IVAS_ERR_NOT_SUPPORTED_OPTION, "PCA supported at SBA FOA 256 kbps only." ); } - if ( ( error = sanitizeBandwidth( hIvasEnc ) ) != IVAS_ERR_OK ) + if ( ( error = sanitizeBandwidth_fx( hIvasEnc ) ) != IVAS_ERR_OK ) { return error; } @@ -1545,13 +1546,21 @@ ivas_error IVAS_ENC_GetDelay( * * *---------------------------------------------------------------------*/ - +#ifdef IVAS_FLOAT_FIXED +static Word16 getInputBufferSize_fx( + const Encoder_Struct *st_ivas /* i : IVAS encoder handle */ +) +{ + return extract_l( Mpy_32_32( imult3216( st_ivas->hEncoderConfig->input_Fs, st_ivas->hEncoderConfig->nchan_inp ), ONE_BY_FRAMES_PER_SEC_Q31 ) ); +} +#else static int16_t getInputBufferSize( const Encoder_Struct *st_ivas /* i : IVAS encoder handle */ ) { return (int16_t) ( st_ivas->hEncoderConfig->input_Fs * st_ivas->hEncoderConfig->nchan_inp / FRAMES_PER_SEC ); } +#endif /*---------------------------------------------------------------------* * IVAS_ENC_GetNumInChannels() @@ -1584,7 +1593,28 @@ ivas_error IVAS_ENC_GetNumInChannels( * * *---------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +ivas_error IVAS_ENC_GetInputBufferSize( + const IVAS_ENC_HANDLE hIvasEnc, /* i : IVAS encoder handle */ + Word16 *inputBufferSize /* o : total number of samples expected in the input buffer for current encoder configuration */ +) +{ + IF( !hIvasEnc->isConfigured ) + { + return IVAS_ERR_NOT_CONFIGURED; + } + IF( inputBufferSize == NULL ) + { + return IVAS_ERR_UNEXPECTED_NULL_POINTER; + } + + *inputBufferSize = getInputBufferSize_fx( hIvasEnc->st_ivas ); + move16(); + + return IVAS_ERR_OK; +} +#else ivas_error IVAS_ENC_GetInputBufferSize( const IVAS_ENC_HANDLE hIvasEnc, /* i : IVAS encoder handle */ int16_t *inputBufferSize /* o : total number of samples expected in the input buffer for current encoder configuration */ @@ -1604,6 +1634,7 @@ ivas_error IVAS_ENC_GetInputBufferSize( return IVAS_ERR_OK; } +#endif /*---------------------------------------------------------------------* @@ -1611,7 +1642,269 @@ ivas_error IVAS_ENC_GetInputBufferSize( * * Main function to encode one frame to a serial bitstream *---------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +ivas_error IVAS_ENC_EncodeFrameToSerial( + IVAS_ENC_HANDLE hIvasEnc, /* i/o: IVAS encoder handle */ + Word16 *inputBuffer, /* i : PCM input, Q0 */ + Word16 inputBufferSize, /* i : total number of samples in the input buffer. Related function: IVAS_ENC_GetInputBufferSize() */ + UWord16 *outputBitStream, /* o : pointer to serial output bitstream. The array must already be allocated and be of size at least IVAS_MAX_BITS_PER_FRAME */ + UWord16 *numOutBits /* o : number of bits written to output bitstream. Each bit is stored as a single uint16_t value */ +) +{ + Encoder_Struct *st_ivas; + ENCODER_CONFIG_HANDLE hEncoderConfig; + Word16 i; + Word16 n, ch; + ivas_error error; + + error = IVAS_ERR_OK; + move32(); + + IF( !hIvasEnc->isConfigured ) + { + return IVAS_ERR_NOT_CONFIGURED; + } + + st_ivas = hIvasEnc->st_ivas; + hEncoderConfig = st_ivas->hEncoderConfig; + ENC_CORE_HANDLE hCoreCoder = hIvasEnc->hCoreCoder; + + IF( NE_16( inputBufferSize, getInputBufferSize_fx( st_ivas ) ) ) + { + return IVAS_ERR_INVALID_INPUT_BUFFER_SIZE; + } + + IF( NE_32( ( error = sanitizeBandwidth_fx( hIvasEnc ) ), IVAS_ERR_OK ) ) + { + return error; + } + + IF( EQ_32( hEncoderConfig->ivas_format, ISM_FORMAT ) ) + { + FOR( i = 0; i < hEncoderConfig->nchan_inp; ++i ) + { + IF( !hIvasEnc->ismMetadataProvided[i] ) + { + ivas_ism_reset_metadata_API( hIvasEnc->st_ivas->hIsmMetaData[i] ); + } + } + resetIsmMetadataProvidedFlags( hIvasEnc ); + } + + test(); + test(); + test(); + test(); + IF( ( hEncoderConfig->Opt_RF_ON && ( NE_32( hEncoderConfig->ivas_total_brate, ACELP_13k20 ) || EQ_32( hEncoderConfig->input_Fs, 8000 ) || hEncoderConfig->max_bwidth == NB ) ) || hEncoderConfig->rf_fec_offset == 0 ) + { + test(); + IF( EQ_32( hEncoderConfig->ivas_total_brate, ACELP_13k20 ) && EQ_32( hEncoderConfig->ivas_format, MONO_FORMAT ) ) + { + st_ivas->codec_mode = MODE1; + move16(); + + reset_rf_indices_fx( hCoreCoder ); + } + hEncoderConfig->Opt_RF_ON = 0; + move16(); + hEncoderConfig->rf_fec_offset = 0; + move16(); + hIvasEnc->switchingActive = true; + move16(); + } + + test(); + test(); + test(); + test(); + IF( hIvasEnc->Opt_RF_ON_loc && hIvasEnc->rf_fec_offset_loc != 0 && L_sub( hEncoderConfig->ivas_total_brate, ACELP_13k20 ) == 0 && L_sub( hEncoderConfig->input_Fs, 8000 ) != 0 && hEncoderConfig->max_bwidth != NB ) + { + st_ivas->codec_mode = MODE2; + move16(); + test(); + IF( hEncoderConfig->Opt_RF_ON == 0 && EQ_16( hEncoderConfig->ivas_format, MONO_FORMAT ) ) + { + reset_rf_indices_fx( hCoreCoder ); + } + hEncoderConfig->Opt_RF_ON = 1; + hEncoderConfig->rf_fec_offset = hIvasEnc->rf_fec_offset_loc; + hIvasEnc->switchingActive = true; + move16(); + move16(); + move16(); + } + + /* in case of 8kHz sampling rate or when in "max_band NB" mode, limit the total bitrate to 24.40 kbps */ + test(); + test(); + IF( ( EQ_32( hEncoderConfig->input_Fs, 8000 ) || ( hEncoderConfig->max_bwidth == NB ) ) && GT_32( hEncoderConfig->ivas_total_brate, ACELP_24k40 ) ) + { + hEncoderConfig->ivas_total_brate = ACELP_24k40; + st_ivas->codec_mode = MODE2; + hIvasEnc->switchingActive = true; + move32(); + move16(); + move16(); + } + + /*-----------------------------------------------------------------* + * Re-allocate and re-initialize buffer of indices if IVAS total bitrate has changed + *-----------------------------------------------------------------*/ + + IF( NE_32( hEncoderConfig->ivas_total_brate, hEncoderConfig->last_ivas_total_brate ) ) + { + /* de-allocate old buffer of indices */ + free( st_ivas->ind_list ); + + /* set the maximum allowed number of indices in the list */ + st_ivas->ivas_max_num_indices = get_ivas_max_num_indices_fx( hEncoderConfig->ivas_format, hEncoderConfig->ivas_total_brate ); + move16(); + + /* allocate new buffer of indices */ + IF( ( st_ivas->ind_list = (INDICE_HANDLE) malloc( st_ivas->ivas_max_num_indices * sizeof( Indice ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for buffer of indices!\n" ) ); + } + + /* reset the list of indices */ + FOR( i = 0; i < st_ivas->ivas_max_num_indices; i++ ) + { + st_ivas->ind_list[i].nb_bits = -1; + move16(); + } + + /* de-allocate old buffer of metadata indices */ + IF( st_ivas->ind_list_metadata != NULL ) + { + free( st_ivas->ind_list_metadata ); + } + + /* set the maximum allowed number of metadata indices in the list */ + st_ivas->ivas_max_num_indices_metadata = get_ivas_max_num_indices_metadata_fx( hEncoderConfig->ivas_format, hEncoderConfig->ivas_total_brate ); + move16(); + + IF( st_ivas->ivas_max_num_indices_metadata > 0 ) + { + /* allocate new buffer of metadata indices */ + IF( ( st_ivas->ind_list_metadata = (INDICE_HANDLE) malloc( st_ivas->ivas_max_num_indices_metadata * sizeof( Indice ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for buffer of metadata indices!\n" ) ); + } + + /* reset the list of metadata indices */ + FOR( i = 0; i < st_ivas->ivas_max_num_indices_metadata; i++ ) + { + st_ivas->ind_list_metadata[i].nb_bits = -1; + move16(); + } + } + ELSE + { + st_ivas->ind_list_metadata = NULL; + } + + /* set pointers to the new buffers of indices in each element */ + FOR( n = 0; n < st_ivas->nSCE; n++ ) + { + test(); + IF( !( hIvasEnc->hCoreCoder == NULL && EQ_32( hEncoderConfig->ivas_format, MONO_FORMAT ) ) ) + { + if ( ( hEncoderConfig->element_mode_init != EVS_MONO ) ) + { + st_ivas->hSCE[n]->hCoreCoder[0]->hBstr->ind_list = st_ivas->ind_list; + } + st_ivas->hSCE[n]->hCoreCoder[0]->hBstr->ivas_ind_list_zero = &st_ivas->ind_list; + } + + IF( st_ivas->hSCE[n]->hMetaData != NULL ) + { + st_ivas->hSCE[n]->hMetaData->ind_list = st_ivas->ind_list_metadata; + st_ivas->hSCE[n]->hMetaData->ivas_ind_list_zero = &st_ivas->ind_list_metadata; + } + } + + FOR( n = 0; n < st_ivas->nCPE; n++ ) + { + FOR( ch = 0; ch < CPE_CHANNELS; ch++ ) + { + st_ivas->hCPE[n]->hCoreCoder[ch]->hBstr->ind_list = st_ivas->ind_list; + st_ivas->hCPE[n]->hCoreCoder[ch]->hBstr->ivas_ind_list_zero = &st_ivas->ind_list; + } + IF( st_ivas->hCPE[n]->hMetaData != NULL ) + { + st_ivas->hCPE[n]->hMetaData->ind_list = st_ivas->ind_list_metadata; + st_ivas->hCPE[n]->hMetaData->ivas_ind_list_zero = &st_ivas->ind_list_metadata; + } + } + } + + test(); + IF( hIvasEnc->switchingActive && EQ_16( hEncoderConfig->ivas_format, MONO_FORMAT ) ) + { + copy_encoder_config_fx( st_ivas, hCoreCoder, 0 ); + hEncoderConfig->last_ivas_total_brate = hEncoderConfig->ivas_total_brate; + move32(); + } + + /* run the main encoding routine */ + IF( EQ_32( hEncoderConfig->ivas_format, MONO_FORMAT ) ) /* EVS mono */ + { + hCoreCoder->total_brate = hEncoderConfig->ivas_total_brate; /* needed in case of bitrate switching */ + move32(); + + IF( EQ_16( hEncoderConfig->stereo_dmx_evs, 1 ) ) + { + inputBufferSize = shr( inputBufferSize, 1 ); + stereo_dmx_evs_enc_fx( st_ivas->hStereoDmxEVS, hEncoderConfig->input_Fs, inputBuffer, inputBufferSize, hEncoderConfig->is_binaural ); + } + + IF( hEncoderConfig->Opt_AMR_WB ) + { + amr_wb_enc_fx( hCoreCoder, inputBuffer, inputBufferSize ); + } + ELSE + { + hCoreCoder->input_frame_fx = inputBufferSize; + move32(); + IF( NE_32( ( error = evs_enc_fx( hCoreCoder, inputBuffer, hCoreCoder->mem_hp20_in_fx, inputBufferSize ) ), IVAS_ERR_OK ) ) + { + return error; + } + } + } + ELSE /* IVAS */ + { + IF( NE_32( ( error = ivas_enc( st_ivas, inputBuffer, inputBufferSize ) ), IVAS_ERR_OK ) ) + { + return error; + } + } + + /* write indices into bitstream buffer */ + IF( EQ_16( hEncoderConfig->element_mode_init, EVS_MONO ) ) + { + test(); + IF( EQ_16( hEncoderConfig->ivas_format, MONO_FORMAT ) && ( hCoreCoder->element_mode == EVS_MONO ) ) + { + /* write indices into bitstream file */ + UWord8 pFrame[( MAX_BITS_PER_FRAME + 7 ) >> 3]; + Word16 pFrame_size = 0; + move16(); + write_indices_buf_fx( hCoreCoder, hCoreCoder->hBstr, outputBitStream, pFrame, pFrame_size, numOutBits ); + } + } + ELSE + { + 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; +} +#else ivas_error IVAS_ENC_EncodeFrameToSerial( IVAS_ENC_HANDLE hIvasEnc, /* i/o: IVAS encoder handle */ int16_t *inputBuffer, /* i : PCM input */ @@ -1642,7 +1935,7 @@ ivas_error IVAS_ENC_EncodeFrameToSerial( return IVAS_ERR_INVALID_INPUT_BUFFER_SIZE; } - if ( ( error = sanitizeBandwidth( hIvasEnc ) ) != IVAS_ERR_OK ) + if ( ( error = sanitizeBandwidth_fx( hIvasEnc ) ) != IVAS_ERR_OK ) { return error; } @@ -1716,7 +2009,7 @@ ivas_error IVAS_ENC_EncodeFrameToSerial( free( st_ivas->ind_list ); /* set the maximum allowed number of indices in the list */ - st_ivas->ivas_max_num_indices = get_ivas_max_num_indices( hEncoderConfig->ivas_format, hEncoderConfig->ivas_total_brate ); + st_ivas->ivas_max_num_indices = get_ivas_max_num_indices_fx( hEncoderConfig->ivas_format, hEncoderConfig->ivas_total_brate ); /* allocate new buffer of indices */ if ( ( st_ivas->ind_list = (INDICE_HANDLE) malloc( st_ivas->ivas_max_num_indices * sizeof( Indice ) ) ) == NULL ) @@ -1737,7 +2030,7 @@ ivas_error IVAS_ENC_EncodeFrameToSerial( } /* set the maximum allowed number of metadata indices in the list */ - st_ivas->ivas_max_num_indices_metadata = get_ivas_max_num_indices_metadata( hEncoderConfig->ivas_format, hEncoderConfig->ivas_total_brate ); + st_ivas->ivas_max_num_indices_metadata = get_ivas_max_num_indices_metadata_fx( hEncoderConfig->ivas_format, hEncoderConfig->ivas_total_brate ); if ( st_ivas->ivas_max_num_indices_metadata > 0 ) { @@ -1885,6 +2178,7 @@ ivas_error IVAS_ENC_EncodeFrameToSerial( return error; } +#endif #ifndef IVAS_FLOAT_FIXED /*---------------------------------------------------------------------* @@ -1935,7 +2229,7 @@ ivas_error IVAS_ENC_SetBandwidth( } /* Use internal function to set bandiwdth */ - return setBandwidth( hIvasEnc, maxBandwidth ); + return setBandwidth_fx( hIvasEnc, maxBandwidth ); } @@ -1984,7 +2278,7 @@ ivas_error IVAS_ENC_SetChannelAwareConfig( } /* Use internal function to set CA config */ - return setChannelAwareConfig( hIvasEnc, rfConfig ); + return setChannelAwareConfig_fx( hIvasEnc, rfConfig ); } @@ -2034,8 +2328,11 @@ IVAS_ENC_CHANNEL_AWARE_CONFIG IVAS_ENC_GetDefaultChannelAwareConfig( void ) { IVAS_ENC_CHANNEL_AWARE_CONFIG defaultCaConfig; defaultCaConfig.channelAwareModeEnabled = 0; + move16(); defaultCaConfig.fec_indicator = IVAS_ENC_FEC_HI; + move16(); defaultCaConfig.fec_offset = 0; + move16(); return defaultCaConfig; } @@ -2308,7 +2605,7 @@ static ivas_error setBitrate( /* check if the entered bitrate is supported */ if ( hEncoderConfig->element_mode_init > EVS_MONO ) { - if ( !is_IVAS_bitrate( hEncoderConfig->ivas_total_brate ) ) + if ( !is_IVAS_bitrate_fx( hEncoderConfig->ivas_total_brate ) ) { return IVAS_ERROR( IVAS_ERR_INVALID_BITRATE, "Incorrect bitrate specification in IVAS: %d", hEncoderConfig->ivas_total_brate ); } @@ -2329,7 +2626,7 @@ static ivas_error setBitrate( if ( hEncoderConfig->ivas_format == ISM_FORMAT ) { - if ( ( error = sanitizeBitrateISM( hEncoderConfig, hIvasEnc->extMetadataApi ) ) != IVAS_ERR_OK ) + if ( ( error = sanitizeBitrateISM_fx( hEncoderConfig, hIvasEnc->extMetadataApi ) ) != IVAS_ERR_OK ) { return error; } @@ -2359,64 +2656,6 @@ static ivas_error setBitrate( * *---------------------------------------------------------------------*/ -static ivas_error setChannelAwareConfig( - IVAS_ENC_HANDLE hIvasEnc, - const IVAS_ENC_CHANNEL_AWARE_CONFIG caConfig ) -{ - int16_t newFecIndicator; - ivas_error error; - Encoder_Struct *st_ivas; - ENCODER_CONFIG_HANDLE hEncoderConfig; - - st_ivas = hIvasEnc->st_ivas; - hEncoderConfig = st_ivas->hEncoderConfig; - - /* channel-aware mode is supported only at 13.20 kbps and with WB or SWB bandwidth */ - if ( ( caConfig.channelAwareModeEnabled && st_ivas->hEncoderConfig->ivas_total_brate != ACELP_13k20 ) || ( hEncoderConfig->Opt_RF_ON && hEncoderConfig->input_Fs == 8000 ) ) - { - hEncoderConfig->Opt_RF_ON = 0; - hEncoderConfig->rf_fec_offset = 0; - return IVAS_ERR_OK; - } - - if ( caConfig.channelAwareModeEnabled ) - { - hEncoderConfig->Opt_RF_ON = 1; - - /* Convert FEC indicator from API type */ - if ( ( error = fecIndicatorApiToInternal( caConfig.fec_indicator, &newFecIndicator ) ) != IVAS_ERR_OK ) - { - return error; - } - - /* Set new values only if they differ from current values */ - if ( ( newFecIndicator != hEncoderConfig->rf_fec_indicator || caConfig.fec_offset != hEncoderConfig->rf_fec_offset ) ) - { - hEncoderConfig->rf_fec_indicator = newFecIndicator; - - /* Check if new FEC offset has a valid value */ - if ( caConfig.fec_offset == 0 || caConfig.fec_offset == 2 || caConfig.fec_offset == 3 || caConfig.fec_offset == 5 || caConfig.fec_offset == 7 ) - { - hEncoderConfig->rf_fec_offset = caConfig.fec_offset; - } - else - { - return IVAS_ERR_INVALID_FEC_OFFSET; - } - - hIvasEnc->switchingActive = true; - } - - /* Save a copy of FEC offset value - needed during encoding */ - hIvasEnc->rf_fec_offset_loc = hEncoderConfig->rf_fec_offset; - } - else - { - hEncoderConfig->Opt_RF_ON = 0; - } - - return IVAS_ERR_OK; -} #ifdef IVAS_FLOAT_FIXED static ivas_error setChannelAwareConfig_fx( IVAS_ENC_HANDLE hIvasEnc, @@ -2531,94 +2770,6 @@ static ivas_error doCommonSetterChecks( * *---------------------------------------------------------------------*/ -static ivas_error sanitizeBandwidth( - const IVAS_ENC_HANDLE hIvasEnc ) -{ - ENCODER_CONFIG_HANDLE hEncoderConfig; - int16_t max_bwidth_tmp; - - hEncoderConfig = hIvasEnc->st_ivas->hEncoderConfig; - - max_bwidth_tmp = hIvasEnc->newBandwidthApi; - - /* Prevent st_ivas->max_bwidth from being higher than Fs/2 */ - if ( hEncoderConfig->input_Fs == 8000 && max_bwidth_tmp > NB ) - { - max_bwidth_tmp = NB; - } - else if ( hEncoderConfig->input_Fs == 16000 && max_bwidth_tmp > WB ) - { - max_bwidth_tmp = WB; - } - else if ( hEncoderConfig->input_Fs == 32000 && max_bwidth_tmp > SWB ) - { - max_bwidth_tmp = SWB; - } - - /* NB coding not supported in IVAS. Switching to WB. */ - if ( max_bwidth_tmp == NB && hEncoderConfig->ivas_format != UNDEFINED_FORMAT && hEncoderConfig->ivas_format != MONO_FORMAT ) - { - if ( hEncoderConfig->input_Fs >= 16000 ) - { - max_bwidth_tmp = WB; - } - else - { - return IVAS_ERR_INVALID_BITRATE; - } - } - - if ( hEncoderConfig->ivas_format == MONO_FORMAT ) - { -#if 0 // IVAS_fmToDo: temporary disabled to keep EVS bit-exactness -> to be verified - if ( max_bwidth_tmp == FB && hEncoderConfig->ivas_total_brate < ACELP_16k40 ) - { - if ( hEncoderConfig->ivas_total_brate < ACELP_9k60 ) - { - max_bwidth_tmp = WB; - } - else - { - max_bwidth_tmp = SWB; - } - } - - if ( max_bwidth_tmp == SWB && hEncoderConfig->ivas_total_brate < ACELP_9k60 ) - { - max_bwidth_tmp = WB; - } - - /* in case of 8kHz input sampling or "-max_band NB", require the total bitrate to be below 24.40 kbps */ - if ( ( max_bwidth_tmp == NB || hEncoderConfig->input_Fs == 8000 ) && hEncoderConfig->ivas_total_brate > ACELP_24k40 ) - { - if ( hEncoderConfig->input_Fs >= 16000 ) - { - max_bwidth_tmp = WB; - } - else - { - return IVAS_ERR_INVALID_BITRATE; - } - } -#endif - } - else - { - if ( max_bwidth_tmp == FB && ( ( hEncoderConfig->ivas_format != ISM_FORMAT && hEncoderConfig->ivas_total_brate < MIN_BRATE_FB_STEREO ) || - ( hEncoderConfig->ivas_format == ISM_FORMAT && hEncoderConfig->ivas_total_brate / hEncoderConfig->nchan_ism < MIN_BRATE_FB_ISM ) ) ) - { - max_bwidth_tmp = SWB; - } - } - - if ( hEncoderConfig->max_bwidth != max_bwidth_tmp ) - { - hEncoderConfig->max_bwidth = max_bwidth_tmp; - hIvasEnc->switchingActive = true; - } - - return IVAS_ERR_OK; -} #ifdef IVAS_FLOAT_FIXED static ivas_error sanitizeBandwidth_fx( const IVAS_ENC_HANDLE hIvasEnc ) @@ -2710,56 +2861,11 @@ static ivas_error sanitizeBandwidth_fx( } #endif /*---------------------------------------------------------------------* - * sanitizeBitrateISM() + * sanitizeBitrateISM_fx() * * *---------------------------------------------------------------------*/ -static ivas_error sanitizeBitrateISM( - const ENCODER_CONFIG_HANDLE hEncoderConfig, - const bool extMetadataApi ) -{ - if ( hEncoderConfig->ivas_total_brate > IVAS_128k && hEncoderConfig->nchan_inp == 1 ) - { - return IVAS_ERROR( IVAS_ERR_INVALID_BITRATE, "Too high bitrate for 1 ISM specified in IVAS: %d", hEncoderConfig->ivas_total_brate ); - } - - if ( hEncoderConfig->ivas_total_brate > IVAS_256k && hEncoderConfig->nchan_inp == 2 ) - { - return IVAS_ERROR( IVAS_ERR_INVALID_BITRATE, "Too high bitrate for 2 ISM specified in IVAS: %d", hEncoderConfig->ivas_total_brate ); - } - - if ( hEncoderConfig->ivas_total_brate > IVAS_384k && hEncoderConfig->nchan_inp == 3 ) - { - return IVAS_ERROR( IVAS_ERR_INVALID_BITRATE, "Too high bitrate for 3 ISM specified in IVAS: %d", hEncoderConfig->ivas_total_brate ); - } - - if ( hEncoderConfig->ivas_total_brate < IVAS_16k4 && hEncoderConfig->nchan_inp == 2 ) - { - return IVAS_ERROR( IVAS_ERR_INVALID_BITRATE, "Too low bitrate for 2 ISM specified in IVAS: %d", hEncoderConfig->ivas_total_brate ); - } - - if ( hEncoderConfig->ivas_total_brate < IVAS_24k4 && hEncoderConfig->nchan_inp == 3 ) - { - return IVAS_ERROR( IVAS_ERR_INVALID_BITRATE, "Too low bitrate for 3 ISM specified in IVAS: %d", hEncoderConfig->ivas_total_brate ); - } - - if ( hEncoderConfig->ivas_total_brate < IVAS_24k4 && hEncoderConfig->nchan_inp == 4 ) - { - return IVAS_ERROR( IVAS_ERR_INVALID_BITRATE, "Too low bitrate for 4 ISM specified in IVAS: %d", hEncoderConfig->ivas_total_brate ); - } - - if ( extMetadataApi ) - { - hEncoderConfig->ism_extended_metadata_flag = ( hEncoderConfig->ivas_total_brate >= ISM_EXTENDED_METADATA_BRATE ); - } - else - { - hEncoderConfig->ism_extended_metadata_flag = 0; - } - - return IVAS_ERR_OK; -} #ifdef IVAS_FLOAT_FIXED static ivas_error sanitizeBitrateISM_fx( const ENCODER_CONFIG_HANDLE hEncoderConfig, @@ -2808,44 +2914,11 @@ static ivas_error sanitizeBitrateISM_fx( } #endif /*---------------------------------------------------------------------* - * setBandwidth() + * setBandwidth_fx() * * *---------------------------------------------------------------------*/ -static ivas_error setBandwidth( - IVAS_ENC_HANDLE hIvasEnc, - const IVAS_ENC_BANDWIDTH maxBandwidth ) -{ - ivas_error error; - int16_t newBandwidth; - ENCODER_CONFIG_HANDLE hEncoderConfig; - - hEncoderConfig = hIvasEnc->st_ivas->hEncoderConfig; - - /* Convert bandwidth from API type */ - if ( ( error = bandwidthApiToInternal( maxBandwidth, &newBandwidth ) ) != IVAS_ERR_OK ) - { - return error; - } - - hIvasEnc->newBandwidthApi = newBandwidth; - - /* NB coding not supported in IVAS. Switching to WB. */ - if ( newBandwidth == NB && hEncoderConfig->ivas_format != UNDEFINED_FORMAT && hEncoderConfig->ivas_format != MONO_FORMAT ) - { - newBandwidth = WB; - } - - if ( hEncoderConfig->max_bwidth != newBandwidth ) - { - hEncoderConfig->max_bwidth = newBandwidth; - hIvasEnc->switchingActive = true; - } - - return IVAS_ERR_OK; -} -#ifdef IVAS_FLOAT_FIXED static ivas_error setBandwidth_fx( IVAS_ENC_HANDLE hIvasEnc, const IVAS_ENC_BANDWIDTH maxBandwidth ) @@ -2878,7 +2951,6 @@ static ivas_error setBandwidth_fx( return IVAS_ERR_OK; } -#endif /*---------------------------------------------------------------------* * resetIsmMetadataProvidedFlags() diff --git a/lib_enc/lib_enc.h b/lib_enc/lib_enc.h index c50055f33..67e747393 100644 --- a/lib_enc/lib_enc.h +++ b/lib_enc/lib_enc.h @@ -257,6 +257,16 @@ ivas_error IVAS_ENC_FeedMasaMetadata( IVAS_MASA_METADATA_HANDLE hMasaMetadata /* i : MASA metadata for current frame */ ); +#ifdef IVAS_FLOAT_FIXED +/*! r: error code */ +ivas_error IVAS_ENC_EncodeFrameToSerial( + IVAS_ENC_HANDLE hIvasEnc, /* i/o: IVAS encoder handle */ + Word16 *inputBuffer, /* i : PCM input, Q0 */ + Word16 inputBufferSize, /* i : total number of samples in the input buffer. Related function: IVAS_ENC_GetInputBufferSize() */ + UWord16 *outputBitStream, /* o : pointer to serial output bitstream. The array must already be allocated and be of size at least IVAS_MAX_BITS_PER_FRAME */ + UWord16 *numOutBits /* o : number of bits written to output bitstream. Each bit is stored as a single uint16_t value */ +); +#else /*! r: error code */ ivas_error IVAS_ENC_EncodeFrameToSerial( IVAS_ENC_HANDLE hIvasEnc, /* i/o: IVAS encoder handle */ @@ -265,6 +275,7 @@ ivas_error IVAS_ENC_EncodeFrameToSerial( uint16_t *outputBitStream, /* o : pointer to serial output bitstream. The array must already be allocated and be of size at least IVAS_MAX_BITS_PER_FRAME */ uint16_t *numOutBits /* o : number of bits written to output bitstream. Each bit is stored as a single uint16_t value */ ); +#endif /*! r: error code */ ivas_error IVAS_ENC_EncodeFrameToCompact( diff --git a/lib_enc/prot_fx_enc.h b/lib_enc/prot_fx_enc.h index d113f7c4c..d41b70076 100644 --- a/lib_enc/prot_fx_enc.h +++ b/lib_enc/prot_fx_enc.h @@ -4393,4 +4393,9 @@ void SynthesisSTFT_enc_ivas_fx( const Word16 nchan_out /* i : number of output channels */ ); +ivas_error write_indices_ivas_fx( + Encoder_Struct *st_ivas, /* i/o: encoder state structure */ + UWord16 *bit_stream, /* i/o: output bitstream */ + UWord16 *num_bits /* i : number of indices written to output */ +); #endif diff --git a/lib_rend/ivas_td_decorr.c b/lib_rend/ivas_td_decorr.c index ab172f972..8e1f4d043 100644 --- a/lib_rend/ivas_td_decorr.c +++ b/lib_rend/ivas_td_decorr.c @@ -391,7 +391,7 @@ ivas_error ivas_td_decorr_dec_open_fx( IF( ducking_flag ) { - IF( NE_32( ( error = ivas_transient_det_open( &hTdDecorr_loc->pTrans_det, output_Fs ) ), IVAS_ERR_OK ) ) + IF( NE_32( ( error = ivas_transient_det_open_fx( &hTdDecorr_loc->pTrans_det, output_Fs ) ), IVAS_ERR_OK ) ) { return error; } @@ -508,7 +508,7 @@ void ivas_td_decorr_dec_close( IF( ( *hTdDecorr )->pTrans_det != NULL ) { - ivas_transient_det_close( &( *hTdDecorr )->pTrans_det ); + ivas_transient_det_close_fx( &( *hTdDecorr )->pTrans_det ); } free( ( *hTdDecorr ) ); -- GitLab From b611af1b7c227f66b43a10b3185ac4c6930eccd3 Mon Sep 17 00:00:00 2001 From: Markus <59919483+mave2802@users.noreply.github.com> Date: Wed, 23 Oct 2024 11:37:42 +0200 Subject: [PATCH 062/128] fixed application of IGF in case of tonal MDCT concealment --- lib_com/prot_fx.h | 3 ++- lib_dec/dec_tcx_fx.c | 5 +++-- lib_dec/igf_dec_fx.c | 8 +++++--- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index 3239613af..292546d98 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -8921,7 +8921,8 @@ void IGFDecApplyStereo( const Word16 *coreMsMask, const Word16 restrict_hopsize, const Word16 bfi, /* i : frame loss == 1, frame good == 0 */ - const Word16 bfi_apply_damping ); + const Word16 bfi_apply_damping, + const Word16 tonalMDCTConcealment_flag); void IGFDecSetMode( const IGF_DEC_INSTANCE_HANDLE hIGFDec, /* o : instance handle of IGF Decoder */ diff --git a/lib_dec/dec_tcx_fx.c b/lib_dec/dec_tcx_fx.c index 35a417a6c..53d866a70 100644 --- a/lib_dec/dec_tcx_fx.c +++ b/lib_dec/dec_tcx_fx.c @@ -3643,6 +3643,7 @@ void decoder_tcx_IGF_stereo_fx( Word16 coreMsMask[N_MAX]; STEREO_MDCT_BAND_PARAMETERS *sfbConf; Word16 core, sfb, igfGridIdx, restrict_hopsize; + Word16 tonalMDCTConcealment_flag = (sts[0]->hTonalMDCTConc != NULL); core = sts[0]->core; move16(); @@ -3750,7 +3751,7 @@ void decoder_tcx_IGF_stereo_fx( move16(); } - IGFDecApplyStereo( sts[0]->hIGFDec, sts[1]->hIGFDec, x_fx[0][k], &x_e[0][k], x_fx[1][k], &x_e[1][k], igfGridIdx, coreMsMask, restrict_hopsize, bfi, MCT_flag ); + IGFDecApplyStereo(sts[0]->hIGFDec, sts[1]->hIGFDec, x_fx[0][k], &x_e[0][k], x_fx[1][k], &x_e[1][k], igfGridIdx, coreMsMask, restrict_hopsize, bfi, MCT_flag, tonalMDCTConcealment_flag); x_len[0][k] = sts[0]->hIGFDec->igfData.igfInfo.grid[igfGridIdx].stopLine; move16(); @@ -4846,7 +4847,7 @@ void decoder_tcx_noisefilling_fx( test(); IF( EQ_16( st->element_mode, IVAS_CPE_MDCT ) && MCT_flag == 0 ) { - TonalMDCTConceal_InsertNoise_ivas_fx( st->hTonalMDCTConc, x, x_e, st->tonal_mdct_plc_active, &st->seed_tcx_plc, noiseTiltFactor, f, concealment_noise, concealment_noise_exp, CngLevelBackgroundTrace_bfi_fx, CngLevelBackgroundTrace_bfi_exp, infoIGFStartLine ); + TonalMDCTConceal_InsertNoise_ivas_fx( st->hTonalMDCTConc, x, x_e, st->tonal_mdct_plc_active, &st->seed_tcx_plc, noiseTiltFactor, f, concealment_noise, concealment_noise_exp, CngLevelBackgroundTrace_bfi_fx, CngLevelBackgroundTrace_bfi_exp, infoIGFStartLine ); } ELSE { diff --git a/lib_dec/igf_dec_fx.c b/lib_dec/igf_dec_fx.c index 463875a1c..8ed3f3520 100644 --- a/lib_dec/igf_dec_fx.c +++ b/lib_dec/igf_dec_fx.c @@ -3694,7 +3694,8 @@ void IGFDecApplyStereo( const Word16 *coreMsMask, const Word16 restrict_hopsize, const Word16 bfi, /* i : frame loss == 1, frame good == 0 */ - const Word16 bfi_apply_damping ) + const Word16 bfi_apply_damping, + const Word16 tonalMDCTConcealment_flag) { IGF_DEC_PRIVATE_DATA_HANDLE hPrivateDataL, hPrivateDataR; H_IGF_GRID hGrid; @@ -3793,9 +3794,10 @@ void IGFDecApplyStereo( move16(); } - /* skip IGF processing if all IGF levels are zero */ + /* skip IGF processing if all IGF levels are zero or tonal MDCT concealment is active*/ test(); - IF( !hIGFDecL->infoIGFAllZero || !hIGFDecR->infoIGFAllZero ) + + IF(!(tonalMDCTConcealment_flag & bfi) && (!hIGFDecL->infoIGFAllZero || !hIGFDecR->infoIGFAllZero)) { FOR( i = 0; i < hGrid->nTiles; i++ ) { -- GitLab From bceb0b769e8ff33aa524774dcd74f0bd8eacdc9f Mon Sep 17 00:00:00 2001 From: Markus <59919483+mave2802@users.noreply.github.com> Date: Wed, 30 Oct 2024 10:55:45 +0100 Subject: [PATCH 063/128] As in fade out, set spectrum from last block to zero above the crossover frequency in first concealed frame --- lib_com/prot_fx.h | 4 ++-- lib_dec/dec_tcx_fx.c | 3 +-- lib_dec/igf_dec_fx.c | 7 +++---- lib_dec/tonalMDCTconcealment_fx.c | 2 +- 4 files changed, 7 insertions(+), 9 deletions(-) diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index 292546d98..9fa7ff0ed 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -8921,8 +8921,8 @@ void IGFDecApplyStereo( const Word16 *coreMsMask, const Word16 restrict_hopsize, const Word16 bfi, /* i : frame loss == 1, frame good == 0 */ - const Word16 bfi_apply_damping, - const Word16 tonalMDCTConcealment_flag); + const Word16 bfi_apply_damping); + void IGFDecSetMode( const IGF_DEC_INSTANCE_HANDLE hIGFDec, /* o : instance handle of IGF Decoder */ diff --git a/lib_dec/dec_tcx_fx.c b/lib_dec/dec_tcx_fx.c index 53d866a70..a4656e639 100644 --- a/lib_dec/dec_tcx_fx.c +++ b/lib_dec/dec_tcx_fx.c @@ -3643,7 +3643,6 @@ void decoder_tcx_IGF_stereo_fx( Word16 coreMsMask[N_MAX]; STEREO_MDCT_BAND_PARAMETERS *sfbConf; Word16 core, sfb, igfGridIdx, restrict_hopsize; - Word16 tonalMDCTConcealment_flag = (sts[0]->hTonalMDCTConc != NULL); core = sts[0]->core; move16(); @@ -3751,7 +3750,7 @@ void decoder_tcx_IGF_stereo_fx( move16(); } - IGFDecApplyStereo(sts[0]->hIGFDec, sts[1]->hIGFDec, x_fx[0][k], &x_e[0][k], x_fx[1][k], &x_e[1][k], igfGridIdx, coreMsMask, restrict_hopsize, bfi, MCT_flag, tonalMDCTConcealment_flag); + IGFDecApplyStereo(sts[0]->hIGFDec, sts[1]->hIGFDec, x_fx[0][k], &x_e[0][k], x_fx[1][k], &x_e[1][k], igfGridIdx, coreMsMask, restrict_hopsize, bfi, MCT_flag); x_len[0][k] = sts[0]->hIGFDec->igfData.igfInfo.grid[igfGridIdx].stopLine; move16(); diff --git a/lib_dec/igf_dec_fx.c b/lib_dec/igf_dec_fx.c index 8ed3f3520..e417edf44 100644 --- a/lib_dec/igf_dec_fx.c +++ b/lib_dec/igf_dec_fx.c @@ -3694,8 +3694,7 @@ void IGFDecApplyStereo( const Word16 *coreMsMask, const Word16 restrict_hopsize, const Word16 bfi, /* i : frame loss == 1, frame good == 0 */ - const Word16 bfi_apply_damping, - const Word16 tonalMDCTConcealment_flag) + const Word16 bfi_apply_damping) { IGF_DEC_PRIVATE_DATA_HANDLE hPrivateDataL, hPrivateDataR; H_IGF_GRID hGrid; @@ -3794,10 +3793,10 @@ void IGFDecApplyStereo( move16(); } - /* skip IGF processing if all IGF levels are zero or tonal MDCT concealment is active*/ + /* skip IGF processing if all IGF levels are zero */ test(); - IF(!(tonalMDCTConcealment_flag & bfi) && (!hIGFDecL->infoIGFAllZero || !hIGFDecR->infoIGFAllZero)) + IF(!hIGFDecL->infoIGFAllZero || !hIGFDecR->infoIGFAllZero) { FOR( i = 0; i < hGrid->nTiles; i++ ) { diff --git a/lib_dec/tonalMDCTconcealment_fx.c b/lib_dec/tonalMDCTconcealment_fx.c index adb73de03..babc04ac6 100644 --- a/lib_dec/tonalMDCTconcealment_fx.c +++ b/lib_dec/tonalMDCTconcealment_fx.c @@ -1486,7 +1486,7 @@ void TonalMDCTConceal_InsertNoise_ivas_fx( FOR( l = crossOverFreq; l < hTonalMDCTConc->lastBlockData.nSamples; l++ ) { - mdctSpectrum[l] = L_shl( L_deposit_l( hTonalMDCTConc->lastBlockData.spectralData[l] ), 16 ); // Q31-spectralData_exp + mdctSpectrum[i] = 0; move32(); } -- GitLab From e00a8c5898b203d0fff5d7ac00a4e55c9294c44f Mon Sep 17 00:00:00 2001 From: Markus Multrus Date: Thu, 31 Oct 2024 14:56:24 +0100 Subject: [PATCH 064/128] fix formatting --- lib_com/prot_fx.h | 2 +- lib_dec/dec_tcx_fx.c | 4 ++-- lib_dec/igf_dec_fx.c | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index 9fa7ff0ed..b80334f21 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -8921,7 +8921,7 @@ void IGFDecApplyStereo( const Word16 *coreMsMask, const Word16 restrict_hopsize, const Word16 bfi, /* i : frame loss == 1, frame good == 0 */ - const Word16 bfi_apply_damping); + const Word16 bfi_apply_damping ); void IGFDecSetMode( diff --git a/lib_dec/dec_tcx_fx.c b/lib_dec/dec_tcx_fx.c index a4656e639..35a417a6c 100644 --- a/lib_dec/dec_tcx_fx.c +++ b/lib_dec/dec_tcx_fx.c @@ -3750,7 +3750,7 @@ void decoder_tcx_IGF_stereo_fx( move16(); } - IGFDecApplyStereo(sts[0]->hIGFDec, sts[1]->hIGFDec, x_fx[0][k], &x_e[0][k], x_fx[1][k], &x_e[1][k], igfGridIdx, coreMsMask, restrict_hopsize, bfi, MCT_flag); + IGFDecApplyStereo( sts[0]->hIGFDec, sts[1]->hIGFDec, x_fx[0][k], &x_e[0][k], x_fx[1][k], &x_e[1][k], igfGridIdx, coreMsMask, restrict_hopsize, bfi, MCT_flag ); x_len[0][k] = sts[0]->hIGFDec->igfData.igfInfo.grid[igfGridIdx].stopLine; move16(); @@ -4846,7 +4846,7 @@ void decoder_tcx_noisefilling_fx( test(); IF( EQ_16( st->element_mode, IVAS_CPE_MDCT ) && MCT_flag == 0 ) { - TonalMDCTConceal_InsertNoise_ivas_fx( st->hTonalMDCTConc, x, x_e, st->tonal_mdct_plc_active, &st->seed_tcx_plc, noiseTiltFactor, f, concealment_noise, concealment_noise_exp, CngLevelBackgroundTrace_bfi_fx, CngLevelBackgroundTrace_bfi_exp, infoIGFStartLine ); + TonalMDCTConceal_InsertNoise_ivas_fx( st->hTonalMDCTConc, x, x_e, st->tonal_mdct_plc_active, &st->seed_tcx_plc, noiseTiltFactor, f, concealment_noise, concealment_noise_exp, CngLevelBackgroundTrace_bfi_fx, CngLevelBackgroundTrace_bfi_exp, infoIGFStartLine ); } ELSE { diff --git a/lib_dec/igf_dec_fx.c b/lib_dec/igf_dec_fx.c index e417edf44..c5ee99d17 100644 --- a/lib_dec/igf_dec_fx.c +++ b/lib_dec/igf_dec_fx.c @@ -3694,7 +3694,7 @@ void IGFDecApplyStereo( const Word16 *coreMsMask, const Word16 restrict_hopsize, const Word16 bfi, /* i : frame loss == 1, frame good == 0 */ - const Word16 bfi_apply_damping) + const Word16 bfi_apply_damping ) { IGF_DEC_PRIVATE_DATA_HANDLE hPrivateDataL, hPrivateDataR; H_IGF_GRID hGrid; @@ -3796,7 +3796,7 @@ void IGFDecApplyStereo( /* skip IGF processing if all IGF levels are zero */ test(); - IF(!hIGFDecL->infoIGFAllZero || !hIGFDecR->infoIGFAllZero) + IF( !hIGFDecL->infoIGFAllZero || !hIGFDecR->infoIGFAllZero ) { FOR( i = 0; i < hGrid->nTiles; i++ ) { -- GitLab From 2fe0a149864f28e3ac122da5cdb7f6474b8c8fb4 Mon Sep 17 00:00:00 2001 From: Markus Multrus Date: Thu, 31 Oct 2024 15:07:49 +0100 Subject: [PATCH 065/128] undo whitespace changes --- lib_com/prot_fx.h | 1 - lib_dec/igf_dec_fx.c | 1 - 2 files changed, 2 deletions(-) diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index b80334f21..3239613af 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -8923,7 +8923,6 @@ void IGFDecApplyStereo( const Word16 bfi, /* i : frame loss == 1, frame good == 0 */ const Word16 bfi_apply_damping ); - void IGFDecSetMode( const IGF_DEC_INSTANCE_HANDLE hIGFDec, /* o : instance handle of IGF Decoder */ const Word32 total_brate, /* i : bitrate */ diff --git a/lib_dec/igf_dec_fx.c b/lib_dec/igf_dec_fx.c index c5ee99d17..463875a1c 100644 --- a/lib_dec/igf_dec_fx.c +++ b/lib_dec/igf_dec_fx.c @@ -3795,7 +3795,6 @@ void IGFDecApplyStereo( /* skip IGF processing if all IGF levels are zero */ test(); - IF( !hIGFDecL->infoIGFAllZero || !hIGFDecR->infoIGFAllZero ) { FOR( i = 0; i < hGrid->nTiles; i++ ) -- GitLab From 094c1d0d168df328ae0ab8b2367a3a9dcee37bf9 Mon Sep 17 00:00:00 2001 From: Markus Multrus Date: Thu, 31 Oct 2024 15:15:09 +0100 Subject: [PATCH 066/128] fix index --- lib_dec/tonalMDCTconcealment_fx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_dec/tonalMDCTconcealment_fx.c b/lib_dec/tonalMDCTconcealment_fx.c index babc04ac6..0a079d45d 100644 --- a/lib_dec/tonalMDCTconcealment_fx.c +++ b/lib_dec/tonalMDCTconcealment_fx.c @@ -1486,7 +1486,7 @@ void TonalMDCTConceal_InsertNoise_ivas_fx( FOR( l = crossOverFreq; l < hTonalMDCTConc->lastBlockData.nSamples; l++ ) { - mdctSpectrum[i] = 0; + mdctSpectrum[l] = 0; move32(); } -- GitLab From f8712cf567d035c33476c7da393a41d93eb27ce2 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Mon, 4 Nov 2024 10:26:14 +0530 Subject: [PATCH 067/128] Encoder float structure elements cleanup and lib_com Q-info updates --- lib_com/cb_shape_fx.c | 19 +- lib_com/cldfb.c | 444 ++++++++++++++--------------- lib_com/cldfb_evs.c | 233 +++++++-------- lib_com/fft_cldfb_fx.c | 12 +- lib_com/fft_rel.c | 84 +++--- lib_com/fft_rel_fx.c | 18 +- lib_com/fill_spectrum.c | 10 +- lib_com/findpulse.c | 24 +- lib_com/frame_ener.c | 24 +- lib_com/get_gain.c | 8 +- lib_com/gs_bitallocation_ivas_fx.c | 122 ++++---- lib_com/gs_gains.c | 49 ++-- lib_com/gs_gains_fx.c | 102 +++---- lib_com/gs_inact_switching_fx.c | 19 +- lib_com/gs_noisefill_fx.c | 59 ++-- lib_com/hq2_core_com.c | 40 +-- lib_com/hq2_core_com_fx.c | 300 +++++++++---------- lib_com/hq2_noise_inject_fx.c | 257 ++++++++--------- lib_com/hq_bit_allocation_fx.c | 14 +- lib_com/hq_conf.c | 114 +++----- lib_com/hq_conf_fx.c | 236 ++++++--------- lib_com/hvq_pvq_bitalloc_fx.c | 30 +- lib_com/interleave_spectrum.c | 103 ++++--- lib_com/ivas_prot_fx.h | 2 +- lib_com/prot.h | 2 + lib_com/prot_fx.h | 193 +++++++------ lib_com/rom_com.c | 10 +- lib_com/rom_com.h | 10 +- lib_com/stat_noise_uv_mod.c | 2 + lib_com/swb_bwe_com_lr.c | 2 + lib_enc/acelp_core_enc.c | 38 +-- lib_enc/acelp_core_switch_enc.c | 2 + lib_enc/core_enc_init.c | 9 + lib_enc/core_enc_switch.c | 6 - lib_enc/core_switching_enc.c | 17 ++ lib_enc/hq_core_enc.c | 3 +- lib_enc/igf_enc.c | 22 +- lib_enc/init_enc.c | 63 ++-- lib_enc/ivas_core_enc.c | 10 - lib_enc/ivas_core_pre_proc_front.c | 5 - lib_enc/ivas_cpe_enc.c | 3 - lib_enc/ivas_dirac_enc.c | 21 +- lib_enc/ivas_masa_enc.c | 105 +++---- lib_enc/ivas_mct_enc.c | 6 - lib_enc/ivas_qmetadata_enc.c | 58 ++-- lib_enc/ivas_tcx_core_enc.c | 3 - lib_enc/rst_enc.c | 12 + lib_enc/stat_enc.h | 143 ++++++---- lib_enc/swb_tbe_enc.c | 12 +- 49 files changed, 1541 insertions(+), 1539 deletions(-) diff --git a/lib_com/cb_shape_fx.c b/lib_com/cb_shape_fx.c index fcd9e06e4..56d645ce0 100644 --- a/lib_com/cb_shape_fx.c +++ b/lib_com/cb_shape_fx.c @@ -28,7 +28,7 @@ static void E_GAIN_f_pitch_sharpening( Word16 *x, Word16 pit_lag, Word16 L_subfr FOR( i = pit_lag; i < L_subfr; i++ ) { /*x[i] += x[i - pit_lag] * F_PIT_SHARP;*/ - tmp = mult_r( x[sub( i, pit_lag )], 27853 /*F_PIT_SHARP Q15*/ ); + tmp = mult_r( x[i - pit_lag], 27853 /*F_PIT_SHARP Q15*/ ); x[i] = add( x[i], tmp ); move16(); } @@ -47,12 +47,12 @@ void cb_shape_fx( const Word16 scramblingFlag, /* i : flag for phase scrambling */ const Word16 sharpFlag, /* i : flag for formant sharpening */ const Word16 formantTiltFlag, /* i : flag for formant tilt */ - const Word16 g1, /* i : formant sharpening numerator weighting */ - const Word16 g2, /* i : formant sharpening denominator weighting */ - const Word16 *p_Aq, /* i : LP filter coefficients */ - Word16 *code, /* i/o: signal to shape */ - const Word16 tilt_code, /* i : tilt of code */ - const Word16 pt_pitch, /* i : pointer to current subframe fractional pitch */ + const Word16 g1, /* i : formant sharpening numerator weighting Q15 */ + const Word16 g2, /* i : formant sharpening denominator weighting Q15 */ + const Word16 *p_Aq, /* i : LP filter coefficients Q12 */ + Word16 *code, /* i/o: signal to shape Q9 */ + const Word16 tilt_code, /* i : tilt of code Q15 */ + const Word16 pt_pitch, /* i : pointer to current subframe fractional pitch Q6 */ const Word16 shift, const Word16 L_subfr /* i : subframe lenght */ ) @@ -88,8 +88,8 @@ void cb_shape_fx( buff[i] = code[i]; move16(); /*code[i] = 0.7f*buff[i] + buff[i-1] - 0.7f*code[i-1]; */ - L_tmp = L_mult( 22938, buff[i] ); - tmp = mac_r( L_tmp, -22938, code[i - 1] ); + L_tmp = L_mult( 22938 /*.7f in Q15*/, buff[i] ); // Q15+Q9+1 + tmp = mac_r( L_tmp, -22938 /*-.7f in Q15*/, code[i - 1] ); // Q9 code[i] = add( tmp, buff[i - 1] ); move16(); } @@ -121,7 +121,6 @@ void cb_shape_fx( { Copy( code, buff, L_subfr ); - move16(); Residu3_lc_fx( A_num, M, buff, code, L_subfr, shift ); { syn_filt_s_lc_fx( shift, A_den, code, code, L_subfr ); diff --git a/lib_com/cldfb.c b/lib_com/cldfb.c index 4eae5458f..5b6e77394 100644 --- a/lib_com/cldfb.c +++ b/lib_com/cldfb.c @@ -307,7 +307,7 @@ void cldfbAnalysis_ivas_fx( /* only process needed cols */ IF( GT_16( samplesToProcess, -1 ) ) { - no_col = min( no_col, div_l( sub( add( samplesToProcess, h_cldfb->no_channels ), 1 ), shr( h_cldfb->no_channels, 1 ) ) ); + no_col = s_min( no_col, div_l( sub( add( samplesToProcess, h_cldfb->no_channels ), 1 ), shr( h_cldfb->no_channels, 1 ) ) ); } M1 = h_cldfb->no_channels; @@ -333,29 +333,29 @@ void cldfbAnalysis_ivas_fx( FOR( k = 0; k < M4; k++ ) { /* prototype filter */ - r1_fx = Msub_32_16( 0, timeBuffer_fx[add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 0, L2 ) )], ptr_pf_fx[( add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 0, L2 ) ) )] ); // Qx - r1_fx = Msub_32_16( r1_fx, timeBuffer_fx[add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 1, L2 ) )], ptr_pf_fx[( add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 1, L2 ) ) )] ); // Qx - r1_fx = Msub_32_16( r1_fx, timeBuffer_fx[add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 2, L2 ) )], ptr_pf_fx[( add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 2, L2 ) ) )] ); // Qx - r1_fx = Msub_32_16( r1_fx, timeBuffer_fx[add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 3, L2 ) )], ptr_pf_fx[( add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 3, L2 ) ) )] ); // Qx - r1_fx = Msub_32_16( r1_fx, timeBuffer_fx[add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 4, L2 ) )], ptr_pf_fx[( add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 4, L2 ) ) )] ); // Qx - - r2_fx = Msub_32_16( 0, timeBuffer_fx[add( add( sub( L2, M2 ), shl( k, 1 ) ), i_mult( 0, L2 ) )], ptr_pf_fx[( add( add( sub( L2, M2 ), shl( k, 1 ) ), i_mult( 0, L2 ) ) )] ); // Qx - r2_fx = Msub_32_16( r2_fx, timeBuffer_fx[add( add( sub( L2, M2 ), shl( k, 1 ) ), i_mult( 1, L2 ) )], ptr_pf_fx[( add( add( sub( L2, M2 ), shl( k, 1 ) ), i_mult( 1, L2 ) ) )] ); // Qx - r2_fx = Msub_32_16( r2_fx, timeBuffer_fx[add( add( sub( L2, M2 ), shl( k, 1 ) ), i_mult( 2, L2 ) )], ptr_pf_fx[( add( add( sub( L2, M2 ), shl( k, 1 ) ), i_mult( 2, L2 ) ) )] ); // Qx - r2_fx = Msub_32_16( r2_fx, timeBuffer_fx[add( add( sub( L2, M2 ), shl( k, 1 ) ), i_mult( 3, L2 ) )], ptr_pf_fx[( add( add( sub( L2, M2 ), shl( k, 1 ) ), i_mult( 3, L2 ) ) )] ); // Qx - r2_fx = Msub_32_16( r2_fx, timeBuffer_fx[add( add( sub( L2, M2 ), shl( k, 1 ) ), i_mult( 4, L2 ) )], ptr_pf_fx[( add( add( sub( L2, M2 ), shl( k, 1 ) ), i_mult( 4, L2 ) ) )] ); // Qx - - i1_fx = Msub_32_16( 0, timeBuffer_fx[add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 0, L2 ) )], ptr_pf_fx[( add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 0, L2 ) ) )] ); // Qx - i1_fx = Msub_32_16( i1_fx, timeBuffer_fx[add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 1, L2 ) )], ptr_pf_fx[( add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 1, L2 ) ) )] ); // Qx - i1_fx = Msub_32_16( i1_fx, timeBuffer_fx[add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 2, L2 ) )], ptr_pf_fx[( add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 2, L2 ) ) )] ); // Qx - i1_fx = Msub_32_16( i1_fx, timeBuffer_fx[add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 3, L2 ) )], ptr_pf_fx[( add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 3, L2 ) ) )] ); // Qx - i1_fx = Msub_32_16( i1_fx, timeBuffer_fx[add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 4, L2 ) )], ptr_pf_fx[( add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 4, L2 ) ) )] ); // Qx - - i2_fx = Msub_32_16( 0, timeBuffer_fx[add( sub( sub( sub( L2, i_mult( 3, M2 ) ), 1 ), shl( k, 1 ) ), i_mult( 0, L2 ) )], ptr_pf_fx[( add( sub( sub( sub( L2, i_mult( 3, M2 ) ), 1 ), shl( k, 1 ) ), i_mult( 0, L2 ) ) )] ); // Qx - i2_fx = Msub_32_16( i2_fx, timeBuffer_fx[add( sub( sub( sub( L2, i_mult( 3, M2 ) ), 1 ), shl( k, 1 ) ), i_mult( 1, L2 ) )], ptr_pf_fx[( add( sub( sub( sub( L2, i_mult( 3, M2 ) ), 1 ), shl( k, 1 ) ), i_mult( 1, L2 ) ) )] ); // Qx - i2_fx = Msub_32_16( i2_fx, timeBuffer_fx[add( sub( sub( sub( L2, i_mult( 3, M2 ) ), 1 ), shl( k, 1 ) ), i_mult( 2, L2 ) )], ptr_pf_fx[( add( sub( sub( sub( L2, i_mult( 3, M2 ) ), 1 ), shl( k, 1 ) ), i_mult( 2, L2 ) ) )] ); // Qx - i2_fx = Msub_32_16( i2_fx, timeBuffer_fx[add( sub( sub( sub( L2, i_mult( 3, M2 ) ), 1 ), shl( k, 1 ) ), i_mult( 3, L2 ) )], ptr_pf_fx[( add( sub( sub( sub( L2, i_mult( 3, M2 ) ), 1 ), shl( k, 1 ) ), i_mult( 3, L2 ) ) )] ); // Qx - i2_fx = Msub_32_16( i2_fx, timeBuffer_fx[add( sub( sub( sub( L2, i_mult( 3, M2 ) ), 1 ), shl( k, 1 ) ), i_mult( 4, L2 ) )], ptr_pf_fx[( add( sub( sub( sub( L2, i_mult( 3, M2 ) ), 1 ), shl( k, 1 ) ), i_mult( 4, L2 ) ) )] ); // Qx + r1_fx = Msub_32_16( 0, timeBuffer_fx[( L2 - M2 - 1 - ( 2 * k ) + 0 * L2 )], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 0 * L2 )] ); // Qx + r1_fx = Msub_32_16( r1_fx, timeBuffer_fx[( L2 - M2 - 1 - ( 2 * k ) + 1 * L2 )], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 1 * L2 )] ); // Qx + r1_fx = Msub_32_16( r1_fx, timeBuffer_fx[( L2 - M2 - 1 - ( 2 * k ) + 2 * L2 )], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 2 * L2 )] ); // Qx + r1_fx = Msub_32_16( r1_fx, timeBuffer_fx[( L2 - M2 - 1 - ( 2 * k ) + 3 * L2 )], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 3 * L2 )] ); // Qx + r1_fx = Msub_32_16( r1_fx, timeBuffer_fx[( L2 - M2 - 1 - ( 2 * k ) + 4 * L2 )], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 4 * L2 )] ); // Qx + + r2_fx = Msub_32_16( 0, timeBuffer_fx[( L2 - M2 + ( 2 * k ) + 0 * L2 )], ptr_pf_fx[( L2 - M2 + ( 2 * k ) + 0 * L2 )] ); // Qx + r2_fx = Msub_32_16( r2_fx, timeBuffer_fx[( L2 - M2 + ( 2 * k ) + 1 * L2 )], ptr_pf_fx[( L2 - M2 + ( 2 * k ) + 1 * L2 )] ); // Qx + r2_fx = Msub_32_16( r2_fx, timeBuffer_fx[( L2 - M2 + ( 2 * k ) + 2 * L2 )], ptr_pf_fx[( L2 - M2 + ( 2 * k ) + 2 * L2 )] ); // Qx + r2_fx = Msub_32_16( r2_fx, timeBuffer_fx[( L2 - M2 + ( 2 * k ) + 3 * L2 )], ptr_pf_fx[( L2 - M2 + ( 2 * k ) + 3 * L2 )] ); // Qx + r2_fx = Msub_32_16( r2_fx, timeBuffer_fx[( L2 - M2 + ( 2 * k ) + 4 * L2 )], ptr_pf_fx[( L2 - M2 + ( 2 * k ) + 4 * L2 )] ); // Qx + + i1_fx = Msub_32_16( 0, timeBuffer_fx[( L2 - 3 * M2 + ( 2 * k ) + 0 * L2 )], ptr_pf_fx[( L2 - 3 * M2 + ( 2 * k ) + 0 * L2 )] ); // Qx + i1_fx = Msub_32_16( i1_fx, timeBuffer_fx[( L2 - 3 * M2 + ( 2 * k ) + 1 * L2 )], ptr_pf_fx[( L2 - 3 * M2 + ( 2 * k ) + 1 * L2 )] ); // Qx + i1_fx = Msub_32_16( i1_fx, timeBuffer_fx[( L2 - 3 * M2 + ( 2 * k ) + 2 * L2 )], ptr_pf_fx[( L2 - 3 * M2 + ( 2 * k ) + 2 * L2 )] ); // Qx + i1_fx = Msub_32_16( i1_fx, timeBuffer_fx[( L2 - 3 * M2 + ( 2 * k ) + 3 * L2 )], ptr_pf_fx[( L2 - 3 * M2 + ( 2 * k ) + 3 * L2 )] ); // Qx + i1_fx = Msub_32_16( i1_fx, timeBuffer_fx[( L2 - 3 * M2 + ( 2 * k ) + 4 * L2 )], ptr_pf_fx[( L2 - 3 * M2 + ( 2 * k ) + 4 * L2 )] ); // Qx + + i2_fx = Msub_32_16( 0, timeBuffer_fx[( L2 - 3 * M2 - 1 - ( 2 * k ) + 0 * L2 )], ptr_pf_fx[( L2 - 3 * M2 - 1 - ( 2 * k ) + 0 * L2 )] ); // Qx + i2_fx = Msub_32_16( i2_fx, timeBuffer_fx[( L2 - 3 * M2 - 1 - ( 2 * k ) + 1 * L2 )], ptr_pf_fx[( L2 - 3 * M2 - 1 - ( 2 * k ) + 1 * L2 )] ); // Qx + i2_fx = Msub_32_16( i2_fx, timeBuffer_fx[( L2 - 3 * M2 - 1 - ( 2 * k ) + 2 * L2 )], ptr_pf_fx[( L2 - 3 * M2 - 1 - ( 2 * k ) + 2 * L2 )] ); // Qx + i2_fx = Msub_32_16( i2_fx, timeBuffer_fx[( L2 - 3 * M2 - 1 - ( 2 * k ) + 3 * L2 )], ptr_pf_fx[( L2 - 3 * M2 - 1 - ( 2 * k ) + 3 * L2 )] ); // Qx + i2_fx = Msub_32_16( i2_fx, timeBuffer_fx[( L2 - 3 * M2 - 1 - ( 2 * k ) + 4 * L2 )], ptr_pf_fx[( L2 - 3 * M2 - 1 - ( 2 * k ) + 4 * L2 )] ); // Qx r1_fx = Mpy_32_16_1( r1_fx, ptr_pf_sf ); // Qx - 1 r2_fx = Mpy_32_16_1( r2_fx, ptr_pf_sf ); // Qx - 1 @@ -368,7 +368,7 @@ void cldfbAnalysis_ivas_fx( // cplxMult( &rBuffer_fx[2 * k], &rBuffer_fx[2 * k + 1], rr12_fx, ri12_fx, rot_vctr_re_fx[k], rot_vctr_im_fx[k] ); rBuffer_fx[2 * k] = Msub_32_32( Mpy_32_32( rr12_fx, rot_vctr_re_fx[k] ), ri12_fx, rot_vctr_im_fx[k] ); // Qx - 3 move32(); - rBuffer_fx[add( 2 * k, 1 )] = Madd_32_32( Mpy_32_32( rr12_fx, rot_vctr_im_fx[k] ), ri12_fx, rot_vctr_re_fx[k] ); // Qx - 3 + rBuffer_fx[2 * k + 1] = Madd_32_32( Mpy_32_32( rr12_fx, rot_vctr_im_fx[k] ), ri12_fx, rot_vctr_re_fx[k] ); // Qx - 3 move32(); /* folding + pre modulation of DCT IV */ @@ -377,36 +377,36 @@ void cldfbAnalysis_ivas_fx( // cplxMult( &iBuffer_fx[2 * k], &iBuffer_fx[2 * k + 1], ir12_fx, ii12_fx, rot_vctr_re_fx[k], rot_vctr_im_fx[k] ); iBuffer_fx[2 * k] = Msub_32_32( Mpy_32_32( ir12_fx, rot_vctr_re_fx[k] ), ii12_fx, rot_vctr_im_fx[k] ); // Qx - 3 move32(); - iBuffer_fx[add( 2 * k, 1 )] = Madd_32_32( Mpy_32_32( ir12_fx, rot_vctr_im_fx[k] ), ii12_fx, rot_vctr_re_fx[k] ); // Qx - 3 + iBuffer_fx[2 * k + 1] = Madd_32_32( Mpy_32_32( ir12_fx, rot_vctr_im_fx[k] ), ii12_fx, rot_vctr_re_fx[k] ); // Qx - 3 move32(); } FOR( k = M4; k < M2; k++ ) { /* prototype filter */ - r1_fx = Msub_32_16( 0, timeBuffer_fx[add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 0, L2 ) )], ptr_pf_fx[( add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 0, L2 ) ) )] ); // Qx - r1_fx = Msub_32_16( r1_fx, timeBuffer_fx[add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 1, L2 ) )], ptr_pf_fx[( add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 1, L2 ) ) )] ); // Qx - r1_fx = Msub_32_16( r1_fx, timeBuffer_fx[add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 2, L2 ) )], ptr_pf_fx[( add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 2, L2 ) ) )] ); // Qx - r1_fx = Msub_32_16( r1_fx, timeBuffer_fx[add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 3, L2 ) )], ptr_pf_fx[( add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 3, L2 ) ) )] ); // Qx - r1_fx = Msub_32_16( r1_fx, timeBuffer_fx[add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 4, L2 ) )], ptr_pf_fx[( add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 4, L2 ) ) )] ); // Qx - - r2_fx = Msub_32_16( 0, timeBuffer_fx[add( add( sub( L2, i_mult( 5, M2 ) ), shl( k, 1 ) ), i_mult( 0, L2 ) )], ptr_pf_fx[( add( add( sub( L2, i_mult( 5, M2 ) ), shl( k, 1 ) ), i_mult( 0, L2 ) ) )] ); // Qx - r2_fx = Msub_32_16( r2_fx, timeBuffer_fx[add( add( sub( L2, i_mult( 5, M2 ) ), shl( k, 1 ) ), i_mult( 1, L2 ) )], ptr_pf_fx[( add( add( sub( L2, i_mult( 5, M2 ) ), shl( k, 1 ) ), i_mult( 1, L2 ) ) )] ); // Qx - r2_fx = Msub_32_16( r2_fx, timeBuffer_fx[add( add( sub( L2, i_mult( 5, M2 ) ), shl( k, 1 ) ), i_mult( 2, L2 ) )], ptr_pf_fx[( add( add( sub( L2, i_mult( 5, M2 ) ), shl( k, 1 ) ), i_mult( 2, L2 ) ) )] ); // Qx - r2_fx = Msub_32_16( r2_fx, timeBuffer_fx[add( add( sub( L2, i_mult( 5, M2 ) ), shl( k, 1 ) ), i_mult( 3, L2 ) )], ptr_pf_fx[( add( add( sub( L2, i_mult( 5, M2 ) ), shl( k, 1 ) ), i_mult( 3, L2 ) ) )] ); // Qx - r2_fx = Msub_32_16( r2_fx, timeBuffer_fx[add( add( sub( L2, i_mult( 5, M2 ) ), shl( k, 1 ) ), i_mult( 4, L2 ) )], ptr_pf_fx[( add( add( sub( L2, i_mult( 5, M2 ) ), shl( k, 1 ) ), i_mult( 4, L2 ) ) )] ); // Qx - - i1_fx = Msub_32_16( 0, timeBuffer_fx[add( sub( sub( add( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 0, L2 ) )], ptr_pf_fx[( add( sub( sub( add( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 0, L2 ) ) )] ); // Qx - i1_fx = Msub_32_16( i1_fx, timeBuffer_fx[add( sub( sub( add( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 1, L2 ) )], ptr_pf_fx[( add( sub( sub( add( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 1, L2 ) ) )] ); // Qx - i1_fx = Msub_32_16( i1_fx, timeBuffer_fx[add( sub( sub( add( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 2, L2 ) )], ptr_pf_fx[( add( sub( sub( add( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 2, L2 ) ) )] ); // Qx - i1_fx = Msub_32_16( i1_fx, timeBuffer_fx[add( sub( sub( add( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 3, L2 ) )], ptr_pf_fx[( add( sub( sub( add( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 3, L2 ) ) )] ); // Qx - i1_fx = Msub_32_16( i1_fx, timeBuffer_fx[add( sub( sub( add( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 4, L2 ) )], ptr_pf_fx[( add( sub( sub( add( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 4, L2 ) ) )] ); // Qx - - i2_fx = Msub_32_16( 0, timeBuffer_fx[add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 0, L2 ) )], ptr_pf_fx[( add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 0, L2 ) ) )] ); // Qx - i2_fx = Msub_32_16( i2_fx, timeBuffer_fx[add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 1, L2 ) )], ptr_pf_fx[( add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 1, L2 ) ) )] ); // Qx - i2_fx = Msub_32_16( i2_fx, timeBuffer_fx[add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 2, L2 ) )], ptr_pf_fx[( add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 2, L2 ) ) )] ); // Qx - i2_fx = Msub_32_16( i2_fx, timeBuffer_fx[add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 3, L2 ) )], ptr_pf_fx[( add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 3, L2 ) ) )] ); // Qx - i2_fx = Msub_32_16( i2_fx, timeBuffer_fx[add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 4, L2 ) )], ptr_pf_fx[( add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 4, L2 ) ) )] ); // Qx + r1_fx = Msub_32_16( 0, timeBuffer_fx[( L2 - M2 - 1 - ( 2 * k ) + 0 * L2 )], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 0 * L2 )] ); // Qx + r1_fx = Msub_32_16( r1_fx, timeBuffer_fx[( L2 - M2 - 1 - ( 2 * k ) + 1 * L2 )], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 1 * L2 )] ); // Qx + r1_fx = Msub_32_16( r1_fx, timeBuffer_fx[( L2 - M2 - 1 - ( 2 * k ) + 2 * L2 )], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 2 * L2 )] ); // Qx + r1_fx = Msub_32_16( r1_fx, timeBuffer_fx[( L2 - M2 - 1 - ( 2 * k ) + 3 * L2 )], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 3 * L2 )] ); // Qx + r1_fx = Msub_32_16( r1_fx, timeBuffer_fx[( L2 - M2 - 1 - ( 2 * k ) + 4 * L2 )], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 4 * L2 )] ); // Qx + + r2_fx = Msub_32_16( 0, timeBuffer_fx[( L2 - 5 * M2 + ( 2 * k ) + 0 * L2 )], ptr_pf_fx[( L2 - 5 * M2 + ( 2 * k ) + 0 * L2 )] ); // Qx + r2_fx = Msub_32_16( r2_fx, timeBuffer_fx[( L2 - 5 * M2 + ( 2 * k ) + 1 * L2 )], ptr_pf_fx[( L2 - 5 * M2 + ( 2 * k ) + 1 * L2 )] ); // Qx + r2_fx = Msub_32_16( r2_fx, timeBuffer_fx[( L2 - 5 * M2 + ( 2 * k ) + 2 * L2 )], ptr_pf_fx[( L2 - 5 * M2 + ( 2 * k ) + 2 * L2 )] ); // Qx + r2_fx = Msub_32_16( r2_fx, timeBuffer_fx[( L2 - 5 * M2 + ( 2 * k ) + 3 * L2 )], ptr_pf_fx[( L2 - 5 * M2 + ( 2 * k ) + 3 * L2 )] ); // Qx + r2_fx = Msub_32_16( r2_fx, timeBuffer_fx[( L2 - 5 * M2 + ( 2 * k ) + 4 * L2 )], ptr_pf_fx[( L2 - 5 * M2 + ( 2 * k ) + 4 * L2 )] ); // Qx + + i1_fx = Msub_32_16( 0, timeBuffer_fx[( L2 + M2 - 1 - ( 2 * k ) + 0 * L2 )], ptr_pf_fx[( L2 + M2 - 1 - ( 2 * k ) + 0 * L2 )] ); // Qx + i1_fx = Msub_32_16( i1_fx, timeBuffer_fx[( L2 + M2 - 1 - ( 2 * k ) + 1 * L2 )], ptr_pf_fx[( L2 + M2 - 1 - ( 2 * k ) + 1 * L2 )] ); // Qx + i1_fx = Msub_32_16( i1_fx, timeBuffer_fx[( L2 + M2 - 1 - ( 2 * k ) + 2 * L2 )], ptr_pf_fx[( L2 + M2 - 1 - ( 2 * k ) + 2 * L2 )] ); // Qx + i1_fx = Msub_32_16( i1_fx, timeBuffer_fx[( L2 + M2 - 1 - ( 2 * k ) + 3 * L2 )], ptr_pf_fx[( L2 + M2 - 1 - ( 2 * k ) + 3 * L2 )] ); // Qx + i1_fx = Msub_32_16( i1_fx, timeBuffer_fx[( L2 + M2 - 1 - ( 2 * k ) + 4 * L2 )], ptr_pf_fx[( L2 + M2 - 1 - ( 2 * k ) + 4 * L2 )] ); // Qx + + i2_fx = Msub_32_16( 0, timeBuffer_fx[( L2 - 3 * M2 + ( 2 * k ) + 0 * L2 )], ptr_pf_fx[( L2 - 3 * M2 + ( 2 * k ) + 0 * L2 )] ); // Qx + i2_fx = Msub_32_16( i2_fx, timeBuffer_fx[( L2 - 3 * M2 + ( 2 * k ) + 1 * L2 )], ptr_pf_fx[( L2 - 3 * M2 + ( 2 * k ) + 1 * L2 )] ); // Qx + i2_fx = Msub_32_16( i2_fx, timeBuffer_fx[( L2 - 3 * M2 + ( 2 * k ) + 2 * L2 )], ptr_pf_fx[( L2 - 3 * M2 + ( 2 * k ) + 2 * L2 )] ); // Qx + i2_fx = Msub_32_16( i2_fx, timeBuffer_fx[( L2 - 3 * M2 + ( 2 * k ) + 3 * L2 )], ptr_pf_fx[( L2 - 3 * M2 + ( 2 * k ) + 3 * L2 )] ); // Qx + i2_fx = Msub_32_16( i2_fx, timeBuffer_fx[( L2 - 3 * M2 + ( 2 * k ) + 4 * L2 )], ptr_pf_fx[( L2 - 3 * M2 + ( 2 * k ) + 4 * L2 )] ); // Qx r1_fx = Mpy_32_16_1( r1_fx, ptr_pf_sf ); // Qx - 1 r2_fx = Mpy_32_16_1( r2_fx, ptr_pf_sf ); // Qx - 1 @@ -419,7 +419,7 @@ void cldfbAnalysis_ivas_fx( // cplxMult( &rBuffer_fx[2 * k], &rBuffer[2 * k + 1], rr12, ri12, rot_vctr_re[k], rot_vctr_im[k] ); rBuffer_fx[2 * k] = Msub_32_32( Mpy_32_32( rr12_fx, rot_vctr_re_fx[k] ), ri12_fx, rot_vctr_im_fx[k] ); // Qx - 3 move32(); - rBuffer_fx[add( 2 * k, 1 )] = Madd_32_32( Mpy_32_32( rr12_fx, rot_vctr_im_fx[k] ), ri12_fx, rot_vctr_re_fx[k] ); // Qx - 3 + rBuffer_fx[( 2 * k ) + 1] = Madd_32_32( Mpy_32_32( rr12_fx, rot_vctr_im_fx[k] ), ri12_fx, rot_vctr_re_fx[k] ); // Qx - 3 move32(); /* folding + pre modulation of DCT IV */ @@ -428,7 +428,7 @@ void cldfbAnalysis_ivas_fx( // cplxMult( &iBuffer[2 * k], &iBuffer[2 * k + 1], ir12, ii12, rot_vctr_re[k], rot_vctr_im[k] ); iBuffer_fx[2 * k] = Msub_32_32( Mpy_32_32( ir12_fx, rot_vctr_re_fx[k] ), ii12_fx, rot_vctr_im_fx[k] ); // Qx - 3 move32(); - iBuffer_fx[add( 2 * k, 1 )] = Madd_32_32( Mpy_32_32( ir12_fx, rot_vctr_im_fx[k] ), ii12_fx, rot_vctr_re_fx[k] ); // Qx - 3 + iBuffer_fx[( 2 * k ) + 1] = Madd_32_32( Mpy_32_32( ir12_fx, rot_vctr_im_fx[k] ), ii12_fx, rot_vctr_re_fx[k] ); // Qx - 3 move32(); } @@ -440,9 +440,9 @@ void cldfbAnalysis_ivas_fx( FOR( k = 0; k < M2; k++ ) { // cplxMult( &realBuffer[i][M1 - 1 - ( 2 * k )], &realBuffer[i][2 * k], rBuffer[2 * k], rBuffer[2 * k + 1], rot_vctr_re[k], rot_vctr_im[k] ); - realBuffer_fx[i][sub( sub( M1, 1 ), shl( k, 1 ) )] = Msub_32_32( Mpy_32_32( rBuffer_fx[2 * k], rot_vctr_re_fx[k] ), rBuffer_fx[add( 2 * k, 1 )], rot_vctr_im_fx[k] ); // Qx - 5 + realBuffer_fx[i][( M1 - 1 ) - ( k * 2 )] = Msub_32_32( Mpy_32_32( rBuffer_fx[2 * k], rot_vctr_re_fx[k] ), rBuffer_fx[2 * k + 1], rot_vctr_im_fx[k] ); // Qx - 5 move32(); - realBuffer_fx[i][2 * k] = Madd_32_32( Mpy_32_32( rBuffer_fx[2 * k], rot_vctr_im_fx[k] ), rBuffer_fx[add( 2 * k, 1 )], rot_vctr_re_fx[k] ); // Qx - 5 + realBuffer_fx[i][2 * k] = Madd_32_32( Mpy_32_32( rBuffer_fx[2 * k], rot_vctr_im_fx[k] ), rBuffer_fx[2 * k + 1], rot_vctr_re_fx[k] ); // Qx - 5 move32(); } @@ -455,9 +455,9 @@ void cldfbAnalysis_ivas_fx( { /* do it inplace */ // cplxMult( &imagBuffer[i][2 * k], &imagBuffer[i][M1 - 1 - ( 2 * k )], iBuffer[2 * k], iBuffer[2 * k + 1], rot_vctr_re[k], rot_vctr_im[k] ); - imagBuffer_fx[i][2 * k] = Msub_32_32( Mpy_32_32( iBuffer_fx[2 * k], rot_vctr_re_fx[k] ), iBuffer_fx[add( 2 * k, 1 )], rot_vctr_im_fx[k] ); // QX - 5 + imagBuffer_fx[i][2 * k] = Msub_32_32( Mpy_32_32( iBuffer_fx[2 * k], rot_vctr_re_fx[k] ), iBuffer_fx[( 2 * k + 1 )], rot_vctr_im_fx[k] ); // QX - 5 move32(); - imagBuffer_fx[i][sub( sub( M1, 1 ), shl( k, 1 ) )] = Madd_32_32( Mpy_32_32( iBuffer_fx[2 * k], rot_vctr_im_fx[k] ), iBuffer_fx[add( 2 * k, 1 )], rot_vctr_re_fx[k] ); // Qx - 5 + imagBuffer_fx[i][( ( M1 - 1 ) - ( k * 2 ) )] = Madd_32_32( Mpy_32_32( iBuffer_fx[2 * k], rot_vctr_im_fx[k] ), iBuffer_fx[2 * k + 1], rot_vctr_re_fx[k] ); // Qx - 5 move32(); } @@ -743,20 +743,17 @@ void cldfbAnalysis_ts_fx( move16(); /* only process needed cols */ - IF( samplesToProcess > -1 ) + IF( GT_16( samplesToProcess, -1 ) ) { - no_col = min( no_col, idiv1616( sub( add( samplesToProcess, h_cldfb->no_channels ), 1 ), h_cldfb->no_channels ) ); + no_col = s_min( no_col, idiv1616( sub( add( samplesToProcess, h_cldfb->no_channels ), 1 ), h_cldfb->no_channels ) ); assert( no_col == 1 ); } M1 = h_cldfb->no_channels; move16(); M2 = shr( M1, 1 ); - move16(); M4 = shr( M1, 2 ); - move16(); L2 = shl( M1, 1 ); - move16(); if ( s_and( M2, 1 ) ) { @@ -777,29 +774,29 @@ void cldfbAnalysis_ts_fx( FOR( k = 0; k < M4; k++ ) { /* prototype filter */ - r1_fx = Msub_32_16( 0, timeBuffer_fx[add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 0, L2 ) )], ptr_pf_fx[( add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 0, L2 ) ) )] ); // q - r1_fx = Msub_32_16( r1_fx, timeBuffer_fx[add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 1, L2 ) )], ptr_pf_fx[( add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 1, L2 ) ) )] ); // q - r1_fx = Msub_32_16( r1_fx, timeBuffer_fx[add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 2, L2 ) )], ptr_pf_fx[( add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 2, L2 ) ) )] ); // q - r1_fx = Msub_32_16( r1_fx, timeBuffer_fx[add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 3, L2 ) )], ptr_pf_fx[( add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 3, L2 ) ) )] ); // q - r1_fx = Msub_32_16( r1_fx, timeBuffer_fx[add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 4, L2 ) )], ptr_pf_fx[( add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 4, L2 ) ) )] ); // q - - r2_fx = Msub_32_16( 0, timeBuffer_fx[add( add( sub( L2, M2 ), shl( k, 1 ) ), i_mult( 0, L2 ) )], ptr_pf_fx[( add( add( sub( L2, M2 ), shl( k, 1 ) ), i_mult( 0, L2 ) ) )] ); // q - r2_fx = Msub_32_16( r2_fx, timeBuffer_fx[add( add( sub( L2, M2 ), shl( k, 1 ) ), i_mult( 1, L2 ) )], ptr_pf_fx[( add( add( sub( L2, M2 ), shl( k, 1 ) ), i_mult( 1, L2 ) ) )] ); // q - r2_fx = Msub_32_16( r2_fx, timeBuffer_fx[add( add( sub( L2, M2 ), shl( k, 1 ) ), i_mult( 2, L2 ) )], ptr_pf_fx[( add( add( sub( L2, M2 ), shl( k, 1 ) ), i_mult( 2, L2 ) ) )] ); // q - r2_fx = Msub_32_16( r2_fx, timeBuffer_fx[add( add( sub( L2, M2 ), shl( k, 1 ) ), i_mult( 3, L2 ) )], ptr_pf_fx[( add( add( sub( L2, M2 ), shl( k, 1 ) ), i_mult( 3, L2 ) ) )] ); // q - r2_fx = Msub_32_16( r2_fx, timeBuffer_fx[add( add( sub( L2, M2 ), shl( k, 1 ) ), i_mult( 4, L2 ) )], ptr_pf_fx[( add( add( sub( L2, M2 ), shl( k, 1 ) ), i_mult( 4, L2 ) ) )] ); // q - - i1_fx = Msub_32_16( 0, timeBuffer_fx[add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 0, L2 ) )], ptr_pf_fx[( add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 0, L2 ) ) )] ); // q - i1_fx = Msub_32_16( i1_fx, timeBuffer_fx[add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 1, L2 ) )], ptr_pf_fx[( add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 1, L2 ) ) )] ); // q - i1_fx = Msub_32_16( i1_fx, timeBuffer_fx[add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 2, L2 ) )], ptr_pf_fx[( add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 2, L2 ) ) )] ); // q - i1_fx = Msub_32_16( i1_fx, timeBuffer_fx[add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 3, L2 ) )], ptr_pf_fx[( add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 3, L2 ) ) )] ); // q - i1_fx = Msub_32_16( i1_fx, timeBuffer_fx[add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 4, L2 ) )], ptr_pf_fx[( add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 4, L2 ) ) )] ); // q - - i2_fx = Msub_32_16( 0, timeBuffer_fx[add( sub( sub( sub( L2, i_mult( 3, M2 ) ), 1 ), shl( k, 1 ) ), i_mult( 0, L2 ) )], ptr_pf_fx[( add( sub( sub( sub( L2, i_mult( 3, M2 ) ), 1 ), shl( k, 1 ) ), i_mult( 0, L2 ) ) )] ); // q - i2_fx = Msub_32_16( i2_fx, timeBuffer_fx[add( sub( sub( sub( L2, i_mult( 3, M2 ) ), 1 ), shl( k, 1 ) ), i_mult( 1, L2 ) )], ptr_pf_fx[( add( sub( sub( sub( L2, i_mult( 3, M2 ) ), 1 ), shl( k, 1 ) ), i_mult( 1, L2 ) ) )] ); // q - i2_fx = Msub_32_16( i2_fx, timeBuffer_fx[add( sub( sub( sub( L2, i_mult( 3, M2 ) ), 1 ), shl( k, 1 ) ), i_mult( 2, L2 ) )], ptr_pf_fx[( add( sub( sub( sub( L2, i_mult( 3, M2 ) ), 1 ), shl( k, 1 ) ), i_mult( 2, L2 ) ) )] ); // q - i2_fx = Msub_32_16( i2_fx, timeBuffer_fx[add( sub( sub( sub( L2, i_mult( 3, M2 ) ), 1 ), shl( k, 1 ) ), i_mult( 3, L2 ) )], ptr_pf_fx[( add( sub( sub( sub( L2, i_mult( 3, M2 ) ), 1 ), shl( k, 1 ) ), i_mult( 3, L2 ) ) )] ); // q - i2_fx = Msub_32_16( i2_fx, timeBuffer_fx[add( sub( sub( sub( L2, i_mult( 3, M2 ) ), 1 ), shl( k, 1 ) ), i_mult( 4, L2 ) )], ptr_pf_fx[( add( sub( sub( sub( L2, i_mult( 3, M2 ) ), 1 ), shl( k, 1 ) ), i_mult( 4, L2 ) ) )] ); // q + r1_fx = Msub_32_16( 0, timeBuffer_fx[( L2 - M2 - 1 - ( 2 * k ) + 0 * L2 )], ptr_pf_fx[L2 - M2 - 1 - ( 2 * k ) + 0 * L2] ); // q + r1_fx = Msub_32_16( r1_fx, timeBuffer_fx[( L2 - M2 - 1 - ( 2 * k ) + 1 * L2 )], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 1 * L2 )] ); // q + r1_fx = Msub_32_16( r1_fx, timeBuffer_fx[( L2 - M2 - 1 - ( 2 * k ) + 2 * L2 )], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 2 * L2 )] ); // q + r1_fx = Msub_32_16( r1_fx, timeBuffer_fx[( L2 - M2 - 1 - ( 2 * k ) + 3 * L2 )], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 3 * L2 )] ); // q + r1_fx = Msub_32_16( r1_fx, timeBuffer_fx[( L2 - M2 - 1 - ( 2 * k ) + 4 * L2 )], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 4 * L2 )] ); // q + + r2_fx = Msub_32_16( 0, timeBuffer_fx[( L2 - M2 + ( 2 * k ) + 0 * L2 )], ptr_pf_fx[( L2 - M2 + ( 2 * k ) + 0 * L2 )] ); // q + r2_fx = Msub_32_16( r2_fx, timeBuffer_fx[( L2 - M2 + ( 2 * k ) + 1 * L2 )], ptr_pf_fx[( L2 - M2 + ( 2 * k ) + 1 * L2 )] ); // q + r2_fx = Msub_32_16( r2_fx, timeBuffer_fx[( L2 - M2 + ( 2 * k ) + 2 * L2 )], ptr_pf_fx[( L2 - M2 + ( 2 * k ) + 2 * L2 )] ); // q + r2_fx = Msub_32_16( r2_fx, timeBuffer_fx[( L2 - M2 + ( 2 * k ) + 3 * L2 )], ptr_pf_fx[( L2 - M2 + ( 2 * k ) + 3 * L2 )] ); // q + r2_fx = Msub_32_16( r2_fx, timeBuffer_fx[( L2 - M2 + ( 2 * k ) + 4 * L2 )], ptr_pf_fx[( L2 - M2 + ( 2 * k ) + 4 * L2 )] ); // q + + i1_fx = Msub_32_16( 0, timeBuffer_fx[( L2 - 3 * M2 + ( 2 * k ) + 0 * L2 )], ptr_pf_fx[( L2 - 3 * M2 + ( 2 * k ) + 0 * L2 )] ); // q + i1_fx = Msub_32_16( i1_fx, timeBuffer_fx[( L2 - 3 * M2 + ( 2 * k ) + 1 * L2 )], ptr_pf_fx[( L2 - 3 * M2 + ( 2 * k ) + 1 * L2 )] ); // q + i1_fx = Msub_32_16( i1_fx, timeBuffer_fx[( L2 - 3 * M2 + ( 2 * k ) + 2 * L2 )], ptr_pf_fx[( L2 - 3 * M2 + ( 2 * k ) + 2 * L2 )] ); // q + i1_fx = Msub_32_16( i1_fx, timeBuffer_fx[( L2 - 3 * M2 + ( 2 * k ) + 3 * L2 )], ptr_pf_fx[( L2 - 3 * M2 + ( 2 * k ) + 3 * L2 )] ); // q + i1_fx = Msub_32_16( i1_fx, timeBuffer_fx[( L2 - 3 * M2 + ( 2 * k ) + 4 * L2 )], ptr_pf_fx[( L2 - 3 * M2 + ( 2 * k ) + 4 * L2 )] ); // q + + i2_fx = Msub_32_16( 0, timeBuffer_fx[( L2 - 3 * M2 - 1 - ( 2 * k ) + 0 * L2 )], ptr_pf_fx[( L2 - 3 * M2 - 1 - ( 2 * k ) + 0 * L2 )] ); // q + i2_fx = Msub_32_16( i2_fx, timeBuffer_fx[( L2 - 3 * M2 - 1 - ( 2 * k ) + 1 * L2 )], ptr_pf_fx[( L2 - 3 * M2 - 1 - ( 2 * k ) + 1 * L2 )] ); // q + i2_fx = Msub_32_16( i2_fx, timeBuffer_fx[( L2 - 3 * M2 - 1 - ( 2 * k ) + 2 * L2 )], ptr_pf_fx[( L2 - 3 * M2 - 1 - ( 2 * k ) + 2 * L2 )] ); // q + i2_fx = Msub_32_16( i2_fx, timeBuffer_fx[( L2 - 3 * M2 - 1 - ( 2 * k ) + 3 * L2 )], ptr_pf_fx[( L2 - 3 * M2 - 1 - ( 2 * k ) + 3 * L2 )] ); // q + i2_fx = Msub_32_16( i2_fx, timeBuffer_fx[( L2 - 3 * M2 - 1 - ( 2 * k ) + 4 * L2 )], ptr_pf_fx[( L2 - 3 * M2 - 1 - ( 2 * k ) + 4 * L2 )] ); // q r1_fx = Mpy_32_16_1( r1_fx, ptr_pf_sf ); // q - 1 r2_fx = Mpy_32_16_1( r2_fx, ptr_pf_sf ); // q - 1 @@ -810,8 +807,8 @@ void cldfbAnalysis_ts_fx( rr12_fx = L_sub( r1_fx, r2_fx ); // q -1 ri12_fx = L_negate( L_add( i1_fx, i2_fx ) ); // q - 1 /*cplxMult(&rBuffer[2*k],&rBuffer[2*k+1],rr12,ri12,rot_vctr_re[k],rot_vctr_im[k]);*/ - rBuffer_fx[2 * k] = L_sub( Mpy_32_32( rr12_fx, rot_vctr_re_fx[k] ), Mpy_32_32( ri12_fx, rot_vctr_im_fx[k] ) ); // q - 3 - rBuffer_fx[add( 2 * k, 1 )] = L_add( Mpy_32_32( rr12_fx, rot_vctr_im_fx[k] ), Mpy_32_32( ri12_fx, rot_vctr_re_fx[k] ) ); // q - 3 + rBuffer_fx[2 * k] = L_sub( Mpy_32_32( rr12_fx, rot_vctr_re_fx[k] ), Mpy_32_32( ri12_fx, rot_vctr_im_fx[k] ) ); // q - 3 + rBuffer_fx[2 * k + 1] = L_add( Mpy_32_32( rr12_fx, rot_vctr_im_fx[k] ), Mpy_32_32( ri12_fx, rot_vctr_re_fx[k] ) ); // q - 3 move32(); move32(); @@ -819,8 +816,8 @@ void cldfbAnalysis_ts_fx( ir12_fx = L_add( r1_fx, r2_fx ); // q - 1 ii12_fx = L_sub( i1_fx, i2_fx ); // q - 1 /*cplxMult(&iBuffer[2*k],&iBuffer[2*k+1],ir12,ii12,rot_vctr_re[k],rot_vctr_im[k]);*/ - iBuffer_fx[2 * k] = L_sub( Mpy_32_32( ir12_fx, rot_vctr_re_fx[k] ), Mpy_32_32( ii12_fx, rot_vctr_im_fx[k] ) ); // q - 3 - iBuffer_fx[add( 2 * k, 1 )] = L_add( Mpy_32_32( ir12_fx, rot_vctr_im_fx[k] ), Mpy_32_32( ii12_fx, rot_vctr_re_fx[k] ) ); // q - 3 + iBuffer_fx[2 * k] = L_sub( Mpy_32_32( ir12_fx, rot_vctr_re_fx[k] ), Mpy_32_32( ii12_fx, rot_vctr_im_fx[k] ) ); // q - 3 + iBuffer_fx[2 * k + 1] = L_add( Mpy_32_32( ir12_fx, rot_vctr_im_fx[k] ), Mpy_32_32( ii12_fx, rot_vctr_re_fx[k] ) ); // q - 3 move32(); move32(); } @@ -828,29 +825,29 @@ void cldfbAnalysis_ts_fx( FOR( k = M4; k < M2; k++ ) { /* prototype filter */ - r1_fx = Msub_32_16( 0, timeBuffer_fx[add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 0, L2 ) )], ptr_pf_fx[( add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 0, L2 ) ) )] ); // q - r1_fx = Msub_32_16( r1_fx, timeBuffer_fx[add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 1, L2 ) )], ptr_pf_fx[( add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 1, L2 ) ) )] ); // q - r1_fx = Msub_32_16( r1_fx, timeBuffer_fx[add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 2, L2 ) )], ptr_pf_fx[( add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 2, L2 ) ) )] ); // q - r1_fx = Msub_32_16( r1_fx, timeBuffer_fx[add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 3, L2 ) )], ptr_pf_fx[( add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 3, L2 ) ) )] ); // q - r1_fx = Msub_32_16( r1_fx, timeBuffer_fx[add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 4, L2 ) )], ptr_pf_fx[( add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 4, L2 ) ) )] ); // q - - r2_fx = Msub_32_16( 0, timeBuffer_fx[add( add( sub( L2, i_mult( 5, M2 ) ), shl( k, 1 ) ), i_mult( 0, L2 ) )], ptr_pf_fx[( add( add( sub( L2, i_mult( 5, M2 ) ), shl( k, 1 ) ), i_mult( 0, L2 ) ) )] ); // q - r2_fx = Msub_32_16( r2_fx, timeBuffer_fx[add( add( sub( L2, i_mult( 5, M2 ) ), shl( k, 1 ) ), i_mult( 1, L2 ) )], ptr_pf_fx[( add( add( sub( L2, i_mult( 5, M2 ) ), shl( k, 1 ) ), i_mult( 1, L2 ) ) )] ); // q - r2_fx = Msub_32_16( r2_fx, timeBuffer_fx[add( add( sub( L2, i_mult( 5, M2 ) ), shl( k, 1 ) ), i_mult( 2, L2 ) )], ptr_pf_fx[( add( add( sub( L2, i_mult( 5, M2 ) ), shl( k, 1 ) ), i_mult( 2, L2 ) ) )] ); // q - r2_fx = Msub_32_16( r2_fx, timeBuffer_fx[add( add( sub( L2, i_mult( 5, M2 ) ), shl( k, 1 ) ), i_mult( 3, L2 ) )], ptr_pf_fx[( add( add( sub( L2, i_mult( 5, M2 ) ), shl( k, 1 ) ), i_mult( 3, L2 ) ) )] ); // q - r2_fx = Msub_32_16( r2_fx, timeBuffer_fx[add( add( sub( L2, i_mult( 5, M2 ) ), shl( k, 1 ) ), i_mult( 4, L2 ) )], ptr_pf_fx[( add( add( sub( L2, i_mult( 5, M2 ) ), shl( k, 1 ) ), i_mult( 4, L2 ) ) )] ); // q - - i1_fx = Msub_32_16( 0, timeBuffer_fx[add( sub( sub( add( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 0, L2 ) )], ptr_pf_fx[( add( sub( sub( add( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 0, L2 ) ) )] ); // q - i1_fx = Msub_32_16( i1_fx, timeBuffer_fx[add( sub( sub( add( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 1, L2 ) )], ptr_pf_fx[( add( sub( sub( add( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 1, L2 ) ) )] ); // q - i1_fx = Msub_32_16( i1_fx, timeBuffer_fx[add( sub( sub( add( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 2, L2 ) )], ptr_pf_fx[( add( sub( sub( add( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 2, L2 ) ) )] ); // q - i1_fx = Msub_32_16( i1_fx, timeBuffer_fx[add( sub( sub( add( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 3, L2 ) )], ptr_pf_fx[( add( sub( sub( add( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 3, L2 ) ) )] ); // q - i1_fx = Msub_32_16( i1_fx, timeBuffer_fx[add( sub( sub( add( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 4, L2 ) )], ptr_pf_fx[( add( sub( sub( add( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 4, L2 ) ) )] ); // q - - i2_fx = Msub_32_16( 0, timeBuffer_fx[add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 0, L2 ) )], ptr_pf_fx[( add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 0, L2 ) ) )] ); // q - i2_fx = Msub_32_16( i2_fx, timeBuffer_fx[add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 1, L2 ) )], ptr_pf_fx[( add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 1, L2 ) ) )] ); // q - i2_fx = Msub_32_16( i2_fx, timeBuffer_fx[add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 2, L2 ) )], ptr_pf_fx[( add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 2, L2 ) ) )] ); // q - i2_fx = Msub_32_16( i2_fx, timeBuffer_fx[add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 3, L2 ) )], ptr_pf_fx[( add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 3, L2 ) ) )] ); // q - i2_fx = Msub_32_16( i2_fx, timeBuffer_fx[add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 4, L2 ) )], ptr_pf_fx[( add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 4, L2 ) ) )] ); // q + r1_fx = Msub_32_16( 0, timeBuffer_fx[( L2 - M2 - 1 - ( 2 * k ) + 0 * L2 )], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 0 * L2 )] ); // q + r1_fx = Msub_32_16( r1_fx, timeBuffer_fx[( L2 - M2 - 1 - ( 2 * k ) + 1 * L2 )], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 1 * L2 )] ); // q + r1_fx = Msub_32_16( r1_fx, timeBuffer_fx[( L2 - M2 - 1 - ( 2 * k ) + 2 * L2 )], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 2 * L2 )] ); // q + r1_fx = Msub_32_16( r1_fx, timeBuffer_fx[( L2 - M2 - 1 - ( 2 * k ) + 3 * L2 )], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 3 * L2 )] ); // q + r1_fx = Msub_32_16( r1_fx, timeBuffer_fx[( L2 - M2 - 1 - ( 2 * k ) + 4 * L2 )], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 4 * L2 )] ); // q + + r2_fx = Msub_32_16( 0, timeBuffer_fx[( L2 - 5 * M2 + ( 2 * k ) + 0 * L2 )], ptr_pf_fx[( L2 - 5 * M2 + ( 2 * k ) + 0 * L2 )] ); // q + r2_fx = Msub_32_16( r2_fx, timeBuffer_fx[( L2 - 5 * M2 + ( 2 * k ) + 1 * L2 )], ptr_pf_fx[( L2 - 5 * M2 + ( 2 * k ) + 1 * L2 )] ); // q + r2_fx = Msub_32_16( r2_fx, timeBuffer_fx[( L2 - 5 * M2 + ( 2 * k ) + 2 * L2 )], ptr_pf_fx[( L2 - 5 * M2 + ( 2 * k ) + 2 * L2 )] ); // q + r2_fx = Msub_32_16( r2_fx, timeBuffer_fx[( L2 - 5 * M2 + ( 2 * k ) + 3 * L2 )], ptr_pf_fx[( L2 - 5 * M2 + ( 2 * k ) + 3 * L2 )] ); // q + r2_fx = Msub_32_16( r2_fx, timeBuffer_fx[( L2 - 5 * M2 + ( 2 * k ) + 4 * L2 )], ptr_pf_fx[( L2 - 5 * M2 + ( 2 * k ) + 4 * L2 )] ); // q + + i1_fx = Msub_32_16( 0, timeBuffer_fx[( L2 + M2 - 1 - ( 2 * k ) + 0 * L2 )], ptr_pf_fx[( L2 + M2 - 1 - ( 2 * k ) + 0 * L2 )] ); // q + i1_fx = Msub_32_16( i1_fx, timeBuffer_fx[( L2 + M2 - 1 - ( 2 * k ) + 1 * L2 )], ptr_pf_fx[( L2 + M2 - 1 - ( 2 * k ) + 1 * L2 )] ); // q + i1_fx = Msub_32_16( i1_fx, timeBuffer_fx[( L2 + M2 - 1 - ( 2 * k ) + 2 * L2 )], ptr_pf_fx[( L2 + M2 - 1 - ( 2 * k ) + 2 * L2 )] ); // q + i1_fx = Msub_32_16( i1_fx, timeBuffer_fx[( L2 + M2 - 1 - ( 2 * k ) + 3 * L2 )], ptr_pf_fx[( L2 + M2 - 1 - ( 2 * k ) + 3 * L2 )] ); // q + i1_fx = Msub_32_16( i1_fx, timeBuffer_fx[( L2 + M2 - 1 - ( 2 * k ) + 4 * L2 )], ptr_pf_fx[( L2 + M2 - 1 - ( 2 * k ) + 4 * L2 )] ); // q + + i2_fx = Msub_32_16( 0, timeBuffer_fx[( L2 + M2 - 1 - ( 2 * k ) + 0 * L2 )], ptr_pf_fx[( L2 + M2 - 1 - ( 2 * k ) + 0 * L2 )] ); // q + i2_fx = Msub_32_16( i2_fx, timeBuffer_fx[( L2 + M2 - 1 - ( 2 * k ) + 1 * L2 )], ptr_pf_fx[( L2 + M2 - 1 - ( 2 * k ) + 1 * L2 )] ); // q + i2_fx = Msub_32_16( i2_fx, timeBuffer_fx[( L2 + M2 - 1 - ( 2 * k ) + 2 * L2 )], ptr_pf_fx[( L2 + M2 - 1 - ( 2 * k ) + 2 * L2 )] ); // q + i2_fx = Msub_32_16( i2_fx, timeBuffer_fx[( L2 + M2 - 1 - ( 2 * k ) + 3 * L2 )], ptr_pf_fx[( L2 + M2 - 1 - ( 2 * k ) + 3 * L2 )] ); // q + i2_fx = Msub_32_16( i2_fx, timeBuffer_fx[( L2 + M2 - 1 - ( 2 * k ) + 4 * L2 )], ptr_pf_fx[( L2 + M2 - 1 - ( 2 * k ) + 4 * L2 )] ); // q r1_fx = Mpy_32_16_1( r1_fx, ptr_pf_sf ); // q - 1 r2_fx = Mpy_32_16_1( r2_fx, ptr_pf_sf ); // q - 1 @@ -861,8 +858,8 @@ void cldfbAnalysis_ts_fx( rr12_fx = L_add( r1_fx, r2_fx ); // q - 1 ri12_fx = L_sub( i1_fx, i2_fx ); // q - 1 /*cplxMult(&rBuffer[2*k],&rBuffer[2*k+1],rr12,ri12,rot_vctr_re[k],rot_vctr_im[k]);*/ - rBuffer_fx[2 * k] = L_sub( Mpy_32_32( rr12_fx, rot_vctr_re_fx[k] ), Mpy_32_32( ri12_fx, rot_vctr_im_fx[k] ) ); // q - 3 - rBuffer_fx[add( 2 * k, 1 )] = L_add( Mpy_32_32( rr12_fx, rot_vctr_im_fx[k] ), Mpy_32_32( ri12_fx, rot_vctr_re_fx[k] ) ); // q - 3 + rBuffer_fx[2 * k] = L_sub( Mpy_32_32( rr12_fx, rot_vctr_re_fx[k] ), Mpy_32_32( ri12_fx, rot_vctr_im_fx[k] ) ); // q - 3 + rBuffer_fx[2 * k + 1] = L_add( Mpy_32_32( rr12_fx, rot_vctr_im_fx[k] ), Mpy_32_32( ri12_fx, rot_vctr_re_fx[k] ) ); // q - 3 move32(); move32(); @@ -870,8 +867,8 @@ void cldfbAnalysis_ts_fx( ir12_fx = L_sub( r1_fx, r2_fx ); // q - 1 ii12_fx = L_add( i1_fx, i2_fx ); // q - 1 /*cplxMult(&iBuffer[2*k],&iBuffer[2*k+1],ir12,ii12,rot_vctr_re[k],rot_vctr_im[k]);*/ - iBuffer_fx[2 * k] = L_sub( Mpy_32_32( ir12_fx, rot_vctr_re_fx[k] ), Mpy_32_32( ii12_fx, rot_vctr_im_fx[k] ) ); // q - 3 - iBuffer_fx[add( 2 * k, 1 )] = L_add( Mpy_32_32( ir12_fx, rot_vctr_im_fx[k] ), Mpy_32_32( ii12_fx, rot_vctr_re_fx[k] ) ); // q - 3 + iBuffer_fx[2 * k] = L_sub( Mpy_32_32( ir12_fx, rot_vctr_re_fx[k] ), Mpy_32_32( ii12_fx, rot_vctr_im_fx[k] ) ); // q - 3 + iBuffer_fx[2 * k + 1] = L_add( Mpy_32_32( ir12_fx, rot_vctr_im_fx[k] ), Mpy_32_32( ii12_fx, rot_vctr_re_fx[k] ) ); // q - 3 move32(); move32(); } @@ -884,12 +881,12 @@ void cldfbAnalysis_ts_fx( q_shift = sub( s_min( getScaleFactor32( rBuffer_fx, shl( M2, 1 ) ), getScaleFactor32( iBuffer_fx, shl( M2, 1 ) ) ), find_guarded_bits_fx( M2 ) ); *q_cldfb = add( *q_cldfb, q_shift ); move16(); - FOR( Word16 ind = 0; ind < shl( M2, 1 ); ind++ ) + FOR( Word16 ind = 0; ind < M2 * 2; ind++ ) { rBuffer_fx[ind] = L_shl( rBuffer_fx[ind], q_shift ); move32(); } - FOR( Word16 ind = 0; ind < shl( M2, 1 ); ind++ ) + FOR( Word16 ind = 0; ind < M2 * 2; ind++ ) { iBuffer_fx[ind] = L_shl( iBuffer_fx[ind], q_shift ); move32(); @@ -900,8 +897,8 @@ void cldfbAnalysis_ts_fx( FOR( k = 0; k < M2; k++ ) { /*cplxMult(&realBuffer[M1-1-(2*k)],&realBuffer[2*k],rBuffer[2*k],rBuffer[2*k+1],rot_vctr_re[k],rot_vctr_im[k]);*/ - realBuffer_fx[sub( sub( M1, 1 ), shl( k, 1 ) )] = L_sub( Mpy_32_32( rBuffer_fx[2 * k], rot_vctr_re_fx[k] ), Mpy_32_32( rBuffer_fx[add( 2 * k, 1 )], rot_vctr_im_fx[k] ) ); // q - 5 - realBuffer_fx[2 * k] = L_add( Mpy_32_32( rBuffer_fx[2 * k], rot_vctr_im_fx[k] ), Mpy_32_32( rBuffer_fx[add( 2 * k, 1 )], rot_vctr_re_fx[k] ) ); // q - 5 + realBuffer_fx[( ( M1 - 1 ) - ( k * 2 ) )] = L_sub( Mpy_32_32( rBuffer_fx[2 * k], rot_vctr_re_fx[k] ), Mpy_32_32( rBuffer_fx[2 * k + 1], rot_vctr_im_fx[k] ) ); // q - 5 + realBuffer_fx[2 * k] = L_add( Mpy_32_32( rBuffer_fx[2 * k], rot_vctr_im_fx[k] ), Mpy_32_32( rBuffer_fx[2 * k + 1], rot_vctr_re_fx[k] ) ); // q - 5 move32(); move32(); } @@ -914,12 +911,12 @@ void cldfbAnalysis_ts_fx( q_shift = s_min( getScaleFactor32( rBuffer_fx, shl( M2, 1 ) ), getScaleFactor32( iBuffer_fx, shl( M2, 1 ) ) ); *q_cldfb = add( *q_cldfb, q_shift ); move16(); - FOR( Word16 ind = 0; ind < shl( M2, 1 ); ind++ ) + FOR( Word16 ind = 0; ind < M2 * 2; ind++ ) { rBuffer_fx[ind] = L_shl( rBuffer_fx[ind], q_shift ); move32(); } - FOR( Word16 ind = 0; ind < shl( M2, 1 ); ind++ ) + FOR( Word16 ind = 0; ind < M2 * 2; ind++ ) { iBuffer_fx[ind] = L_shl( iBuffer_fx[ind], q_shift ); move32(); @@ -930,8 +927,8 @@ void cldfbAnalysis_ts_fx( { /* do it inplace */ /*cplxMult(&imagBuffer[2*k],&imagBuffer[M1-1-(2*k)],iBuffer[2*k],iBuffer[2*k+1],rot_vctr_re[k],rot_vctr_im[k]);*/ - imagBuffer_fx[2 * k] = L_sub( Mpy_32_32( iBuffer_fx[2 * k], rot_vctr_re_fx[k] ), Mpy_32_32( iBuffer_fx[add( 2 * k, 1 )], rot_vctr_im_fx[k] ) ); // q - 5 - imagBuffer_fx[sub( sub( M1, 1 ), shl( k, 1 ) )] = L_add( Mpy_32_32( iBuffer_fx[2 * k], rot_vctr_im_fx[k] ), Mpy_32_32( iBuffer_fx[add( 2 * k, 1 )], rot_vctr_re_fx[k] ) ); // q - 5 + imagBuffer_fx[2 * k] = L_sub( Mpy_32_32( iBuffer_fx[2 * k], rot_vctr_re_fx[k] ), Mpy_32_32( iBuffer_fx[2 * k + 1], rot_vctr_im_fx[k] ) ); // q - 5 + imagBuffer_fx[( M1 - 1 ) - ( k * 2 )] = L_add( Mpy_32_32( iBuffer_fx[2 * k], rot_vctr_im_fx[k] ), Mpy_32_32( iBuffer_fx[2 * k + 1], rot_vctr_re_fx[k] ) ); // q - 5 move32(); move32(); } @@ -1028,7 +1025,7 @@ void cldfbAnalysis_ts_fx_fixed_q( /* only process needed cols */ IF( GT_16( samplesToProcess, -1 ) ) { - no_col = min( no_col, idiv1616( sub( add( samplesToProcess, h_cldfb->no_channels ), 1 ), h_cldfb->no_channels ) ); + no_col = s_min( no_col, idiv1616( sub( add( samplesToProcess, h_cldfb->no_channels ), 1 ), h_cldfb->no_channels ) ); assert( no_col == 1 ); } @@ -1037,9 +1034,6 @@ void cldfbAnalysis_ts_fx_fixed_q( M4 = shr( M1, 2 ); L2 = shl( M1, 1 ); move16(); - move16(); - move16(); - move16(); if ( s_and( M2, 1 ) ) { @@ -1060,29 +1054,29 @@ void cldfbAnalysis_ts_fx_fixed_q( FOR( k = 0; k < M4; k++ ) { /* prototype filter */ - r1_fx = Msub_32_16( 0, timeBuffer_fx[add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 0, L2 ) )], ptr_pf_fx[( add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 0, L2 ) ) )] ); // q - r1_fx = Msub_32_16( r1_fx, timeBuffer_fx[add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 1, L2 ) )], ptr_pf_fx[( add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 1, L2 ) ) )] ); // q - r1_fx = Msub_32_16( r1_fx, timeBuffer_fx[add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 2, L2 ) )], ptr_pf_fx[( add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 2, L2 ) ) )] ); // q - r1_fx = Msub_32_16( r1_fx, timeBuffer_fx[add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 3, L2 ) )], ptr_pf_fx[( add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 3, L2 ) ) )] ); // q - r1_fx = Msub_32_16( r1_fx, timeBuffer_fx[add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 4, L2 ) )], ptr_pf_fx[( add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 4, L2 ) ) )] ); // q - - r2_fx = Msub_32_16( 0, timeBuffer_fx[add( add( sub( L2, M2 ), shl( k, 1 ) ), i_mult( 0, L2 ) )], ptr_pf_fx[( add( add( sub( L2, M2 ), shl( k, 1 ) ), i_mult( 0, L2 ) ) )] ); // q - r2_fx = Msub_32_16( r2_fx, timeBuffer_fx[add( add( sub( L2, M2 ), shl( k, 1 ) ), i_mult( 1, L2 ) )], ptr_pf_fx[( add( add( sub( L2, M2 ), shl( k, 1 ) ), i_mult( 1, L2 ) ) )] ); // q - r2_fx = Msub_32_16( r2_fx, timeBuffer_fx[add( add( sub( L2, M2 ), shl( k, 1 ) ), i_mult( 2, L2 ) )], ptr_pf_fx[( add( add( sub( L2, M2 ), shl( k, 1 ) ), i_mult( 2, L2 ) ) )] ); // q - r2_fx = Msub_32_16( r2_fx, timeBuffer_fx[add( add( sub( L2, M2 ), shl( k, 1 ) ), i_mult( 3, L2 ) )], ptr_pf_fx[( add( add( sub( L2, M2 ), shl( k, 1 ) ), i_mult( 3, L2 ) ) )] ); // q - r2_fx = Msub_32_16( r2_fx, timeBuffer_fx[add( add( sub( L2, M2 ), shl( k, 1 ) ), i_mult( 4, L2 ) )], ptr_pf_fx[( add( add( sub( L2, M2 ), shl( k, 1 ) ), i_mult( 4, L2 ) ) )] ); // q - - i1_fx = Msub_32_16( 0, timeBuffer_fx[add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 0, L2 ) )], ptr_pf_fx[( add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 0, L2 ) ) )] ); // q - i1_fx = Msub_32_16( i1_fx, timeBuffer_fx[add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 1, L2 ) )], ptr_pf_fx[( add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 1, L2 ) ) )] ); // q - i1_fx = Msub_32_16( i1_fx, timeBuffer_fx[add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 2, L2 ) )], ptr_pf_fx[( add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 2, L2 ) ) )] ); // q - i1_fx = Msub_32_16( i1_fx, timeBuffer_fx[add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 3, L2 ) )], ptr_pf_fx[( add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 3, L2 ) ) )] ); // q - i1_fx = Msub_32_16( i1_fx, timeBuffer_fx[add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 4, L2 ) )], ptr_pf_fx[( add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 4, L2 ) ) )] ); // q - - i2_fx = Msub_32_16( 0, timeBuffer_fx[add( sub( sub( sub( L2, i_mult( 3, M2 ) ), 1 ), shl( k, 1 ) ), i_mult( 0, L2 ) )], ptr_pf_fx[( add( sub( sub( sub( L2, i_mult( 3, M2 ) ), 1 ), shl( k, 1 ) ), i_mult( 0, L2 ) ) )] ); // q - i2_fx = Msub_32_16( i2_fx, timeBuffer_fx[add( sub( sub( sub( L2, i_mult( 3, M2 ) ), 1 ), shl( k, 1 ) ), i_mult( 1, L2 ) )], ptr_pf_fx[( add( sub( sub( sub( L2, i_mult( 3, M2 ) ), 1 ), shl( k, 1 ) ), i_mult( 1, L2 ) ) )] ); // q - i2_fx = Msub_32_16( i2_fx, timeBuffer_fx[add( sub( sub( sub( L2, i_mult( 3, M2 ) ), 1 ), shl( k, 1 ) ), i_mult( 2, L2 ) )], ptr_pf_fx[( add( sub( sub( sub( L2, i_mult( 3, M2 ) ), 1 ), shl( k, 1 ) ), i_mult( 2, L2 ) ) )] ); // q - i2_fx = Msub_32_16( i2_fx, timeBuffer_fx[add( sub( sub( sub( L2, i_mult( 3, M2 ) ), 1 ), shl( k, 1 ) ), i_mult( 3, L2 ) )], ptr_pf_fx[( add( sub( sub( sub( L2, i_mult( 3, M2 ) ), 1 ), shl( k, 1 ) ), i_mult( 3, L2 ) ) )] ); // q - i2_fx = Msub_32_16( i2_fx, timeBuffer_fx[add( sub( sub( sub( L2, i_mult( 3, M2 ) ), 1 ), shl( k, 1 ) ), i_mult( 4, L2 ) )], ptr_pf_fx[( add( sub( sub( sub( L2, i_mult( 3, M2 ) ), 1 ), shl( k, 1 ) ), i_mult( 4, L2 ) ) )] ); // q + r1_fx = Msub_32_16( 0, timeBuffer_fx[( L2 - M2 - 1 - ( 2 * k ) + 0 * L2 )], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 0 * L2 )] ); // q + r1_fx = Msub_32_16( r1_fx, timeBuffer_fx[( L2 - M2 - 1 - ( 2 * k ) + 1 * L2 )], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 1 * L2 )] ); // q + r1_fx = Msub_32_16( r1_fx, timeBuffer_fx[( L2 - M2 - 1 - ( 2 * k ) + 2 * L2 )], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 2 * L2 )] ); // q + r1_fx = Msub_32_16( r1_fx, timeBuffer_fx[( L2 - M2 - 1 - ( 2 * k ) + 3 * L2 )], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 3 * L2 )] ); // q + r1_fx = Msub_32_16( r1_fx, timeBuffer_fx[( L2 - M2 - 1 - ( 2 * k ) + 4 * L2 )], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 4 * L2 )] ); // q + + r2_fx = Msub_32_16( 0, timeBuffer_fx[( L2 - M2 + ( 2 * k ) + 0 * L2 )], ptr_pf_fx[( L2 - M2 + ( 2 * k ) + 0 * L2 )] ); // q + r2_fx = Msub_32_16( r2_fx, timeBuffer_fx[( L2 - M2 + ( 2 * k ) + 1 * L2 )], ptr_pf_fx[( L2 - M2 + ( 2 * k ) + 1 * L2 )] ); // q + r2_fx = Msub_32_16( r2_fx, timeBuffer_fx[( L2 - M2 + ( 2 * k ) + 2 * L2 )], ptr_pf_fx[( L2 - M2 + ( 2 * k ) + 2 * L2 )] ); // q + r2_fx = Msub_32_16( r2_fx, timeBuffer_fx[( L2 - M2 + ( 2 * k ) + 3 * L2 )], ptr_pf_fx[( L2 - M2 + ( 2 * k ) + 3 * L2 )] ); // q + r2_fx = Msub_32_16( r2_fx, timeBuffer_fx[( L2 - M2 + ( 2 * k ) + 4 * L2 )], ptr_pf_fx[( L2 - M2 + ( 2 * k ) + 4 * L2 )] ); // q + + i1_fx = Msub_32_16( 0, timeBuffer_fx[( L2 - 3 * M2 + ( 2 * k ) + 0 * L2 )], ptr_pf_fx[( L2 - 3 * M2 + ( 2 * k ) + 0 * L2 )] ); // q + i1_fx = Msub_32_16( i1_fx, timeBuffer_fx[( L2 - 3 * M2 + ( 2 * k ) + 1 * L2 )], ptr_pf_fx[( L2 - 3 * M2 + ( 2 * k ) + 1 * L2 )] ); // q + i1_fx = Msub_32_16( i1_fx, timeBuffer_fx[( L2 - 3 * M2 + ( 2 * k ) + 2 * L2 )], ptr_pf_fx[( L2 - 3 * M2 + ( 2 * k ) + 2 * L2 )] ); // q + i1_fx = Msub_32_16( i1_fx, timeBuffer_fx[( L2 - 3 * M2 + ( 2 * k ) + 3 * L2 )], ptr_pf_fx[( L2 - 3 * M2 + ( 2 * k ) + 3 * L2 )] ); // q + i1_fx = Msub_32_16( i1_fx, timeBuffer_fx[( L2 - 3 * M2 + ( 2 * k ) + 4 * L2 )], ptr_pf_fx[( L2 - 3 * M2 + ( 2 * k ) + 4 * L2 )] ); // q + + i2_fx = Msub_32_16( 0, timeBuffer_fx[( L2 - 3 * M2 - 1 - ( 2 * k ) + 0 * L2 )], ptr_pf_fx[( L2 - 3 * M2 - 1 - ( 2 * k ) + 0 * L2 )] ); // q + i2_fx = Msub_32_16( i2_fx, timeBuffer_fx[( L2 - 3 * M2 - 1 - ( 2 * k ) + 1 * L2 )], ptr_pf_fx[( L2 - 3 * M2 - 1 - ( 2 * k ) + 1 * L2 )] ); // q + i2_fx = Msub_32_16( i2_fx, timeBuffer_fx[( L2 - 3 * M2 - 1 - ( 2 * k ) + 2 * L2 )], ptr_pf_fx[( L2 - 3 * M2 - 1 - ( 2 * k ) + 2 * L2 )] ); // q + i2_fx = Msub_32_16( i2_fx, timeBuffer_fx[( L2 - 3 * M2 - 1 - ( 2 * k ) + 3 * L2 )], ptr_pf_fx[( L2 - 3 * M2 - 1 - ( 2 * k ) + 3 * L2 )] ); // q + i2_fx = Msub_32_16( i2_fx, timeBuffer_fx[( L2 - 3 * M2 - 1 - ( 2 * k ) + 4 * L2 )], ptr_pf_fx[( L2 - 3 * M2 - 1 - ( 2 * k ) + 4 * L2 )] ); // q r1_fx = Mpy_32_16_1( r1_fx, ptr_pf_sf ); // q - 1 r2_fx = Mpy_32_16_1( r2_fx, ptr_pf_sf ); // q - 1 @@ -1093,8 +1087,8 @@ void cldfbAnalysis_ts_fx_fixed_q( rr12_fx = L_sub( r1_fx, r2_fx ); // q -1 ri12_fx = L_negate( L_add( i1_fx, i2_fx ) ); // q - 1 /*cplxMult(&rBuffer[2*k],&rBuffer[2*k+1],rr12,ri12,rot_vctr_re[k],rot_vctr_im[k]);*/ - rBuffer_fx[2 * k] = Msub_32_32( Mpy_32_32( rr12_fx, rot_vctr_re_fx[k] ), ri12_fx, rot_vctr_im_fx[k] ); // q - 3 - rBuffer_fx[add( 2 * k, 1 )] = Madd_32_32( Mpy_32_32( rr12_fx, rot_vctr_im_fx[k] ), ri12_fx, rot_vctr_re_fx[k] ); // q - 3 + rBuffer_fx[2 * k] = Msub_32_32( Mpy_32_32( rr12_fx, rot_vctr_re_fx[k] ), ri12_fx, rot_vctr_im_fx[k] ); // q - 3 + rBuffer_fx[2 * k + 1] = Madd_32_32( Mpy_32_32( rr12_fx, rot_vctr_im_fx[k] ), ri12_fx, rot_vctr_re_fx[k] ); // q - 3 move32(); move32(); @@ -1102,8 +1096,8 @@ void cldfbAnalysis_ts_fx_fixed_q( ir12_fx = L_add( r1_fx, r2_fx ); // q - 1 ii12_fx = L_sub( i1_fx, i2_fx ); // q - 1 /*cplxMult(&iBuffer[2*k],&iBuffer[2*k+1],ir12,ii12,rot_vctr_re[k],rot_vctr_im[k]);*/ - iBuffer_fx[2 * k] = Msub_32_32( Mpy_32_32( ir12_fx, rot_vctr_re_fx[k] ), ii12_fx, rot_vctr_im_fx[k] ); // q - 3 - iBuffer_fx[add( 2 * k, 1 )] = Madd_32_32( Mpy_32_32( ir12_fx, rot_vctr_im_fx[k] ), ii12_fx, rot_vctr_re_fx[k] ); // q - 3 + iBuffer_fx[2 * k] = Msub_32_32( Mpy_32_32( ir12_fx, rot_vctr_re_fx[k] ), ii12_fx, rot_vctr_im_fx[k] ); // q - 3 + iBuffer_fx[2 * k + 1] = Madd_32_32( Mpy_32_32( ir12_fx, rot_vctr_im_fx[k] ), ii12_fx, rot_vctr_re_fx[k] ); // q - 3 move32(); move32(); } @@ -1111,29 +1105,29 @@ void cldfbAnalysis_ts_fx_fixed_q( FOR( k = M4; k < M2; k++ ) { /* prototype filter */ - r1_fx = Msub_32_16( 0, timeBuffer_fx[add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 0, L2 ) )], ptr_pf_fx[( add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 0, L2 ) ) )] ); // q - r1_fx = Msub_32_16( r1_fx, timeBuffer_fx[add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 1, L2 ) )], ptr_pf_fx[( add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 1, L2 ) ) )] ); // q - r1_fx = Msub_32_16( r1_fx, timeBuffer_fx[add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 2, L2 ) )], ptr_pf_fx[( add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 2, L2 ) ) )] ); // q - r1_fx = Msub_32_16( r1_fx, timeBuffer_fx[add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 3, L2 ) )], ptr_pf_fx[( add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 3, L2 ) ) )] ); // q - r1_fx = Msub_32_16( r1_fx, timeBuffer_fx[add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 4, L2 ) )], ptr_pf_fx[( add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 4, L2 ) ) )] ); // q - - r2_fx = Msub_32_16( 0, timeBuffer_fx[add( add( sub( L2, i_mult( 5, M2 ) ), shl( k, 1 ) ), i_mult( 0, L2 ) )], ptr_pf_fx[( add( add( sub( L2, i_mult( 5, M2 ) ), shl( k, 1 ) ), i_mult( 0, L2 ) ) )] ); // q - r2_fx = Msub_32_16( r2_fx, timeBuffer_fx[add( add( sub( L2, i_mult( 5, M2 ) ), shl( k, 1 ) ), i_mult( 1, L2 ) )], ptr_pf_fx[( add( add( sub( L2, i_mult( 5, M2 ) ), shl( k, 1 ) ), i_mult( 1, L2 ) ) )] ); // q - r2_fx = Msub_32_16( r2_fx, timeBuffer_fx[add( add( sub( L2, i_mult( 5, M2 ) ), shl( k, 1 ) ), i_mult( 2, L2 ) )], ptr_pf_fx[( add( add( sub( L2, i_mult( 5, M2 ) ), shl( k, 1 ) ), i_mult( 2, L2 ) ) )] ); // q - r2_fx = Msub_32_16( r2_fx, timeBuffer_fx[add( add( sub( L2, i_mult( 5, M2 ) ), shl( k, 1 ) ), i_mult( 3, L2 ) )], ptr_pf_fx[( add( add( sub( L2, i_mult( 5, M2 ) ), shl( k, 1 ) ), i_mult( 3, L2 ) ) )] ); // q - r2_fx = Msub_32_16( r2_fx, timeBuffer_fx[add( add( sub( L2, i_mult( 5, M2 ) ), shl( k, 1 ) ), i_mult( 4, L2 ) )], ptr_pf_fx[( add( add( sub( L2, i_mult( 5, M2 ) ), shl( k, 1 ) ), i_mult( 4, L2 ) ) )] ); // q - - i1_fx = Msub_32_16( 0, timeBuffer_fx[add( sub( sub( add( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 0, L2 ) )], ptr_pf_fx[( add( sub( sub( add( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 0, L2 ) ) )] ); // q - i1_fx = Msub_32_16( i1_fx, timeBuffer_fx[add( sub( sub( add( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 1, L2 ) )], ptr_pf_fx[( add( sub( sub( add( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 1, L2 ) ) )] ); // q - i1_fx = Msub_32_16( i1_fx, timeBuffer_fx[add( sub( sub( add( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 2, L2 ) )], ptr_pf_fx[( add( sub( sub( add( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 2, L2 ) ) )] ); // q - i1_fx = Msub_32_16( i1_fx, timeBuffer_fx[add( sub( sub( add( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 3, L2 ) )], ptr_pf_fx[( add( sub( sub( add( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 3, L2 ) ) )] ); // q - i1_fx = Msub_32_16( i1_fx, timeBuffer_fx[add( sub( sub( add( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 4, L2 ) )], ptr_pf_fx[( add( sub( sub( add( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 4, L2 ) ) )] ); // q - - i2_fx = Msub_32_16( 0, timeBuffer_fx[add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 0, L2 ) )], ptr_pf_fx[( add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 0, L2 ) ) )] ); // q - i2_fx = Msub_32_16( i2_fx, timeBuffer_fx[add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 1, L2 ) )], ptr_pf_fx[( add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 1, L2 ) ) )] ); // q - i2_fx = Msub_32_16( i2_fx, timeBuffer_fx[add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 2, L2 ) )], ptr_pf_fx[( add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 2, L2 ) ) )] ); // q - i2_fx = Msub_32_16( i2_fx, timeBuffer_fx[add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 3, L2 ) )], ptr_pf_fx[( add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 3, L2 ) ) )] ); // q - i2_fx = Msub_32_16( i2_fx, timeBuffer_fx[add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 4, L2 ) )], ptr_pf_fx[( add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 4, L2 ) ) )] ); // q + r1_fx = Msub_32_16( 0, timeBuffer_fx[( L2 - M2 - 1 - ( 2 * k ) + 0 * L2 )], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 0 * L2 )] ); // q + r1_fx = Msub_32_16( r1_fx, timeBuffer_fx[( L2 - M2 - 1 - ( 2 * k ) + 1 * L2 )], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 1 * L2 )] ); // q + r1_fx = Msub_32_16( r1_fx, timeBuffer_fx[( L2 - M2 - 1 - ( 2 * k ) + 2 * L2 )], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 2 * L2 )] ); // q + r1_fx = Msub_32_16( r1_fx, timeBuffer_fx[( L2 - M2 - 1 - ( 2 * k ) + 3 * L2 )], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 3 * L2 )] ); // q + r1_fx = Msub_32_16( r1_fx, timeBuffer_fx[( L2 - M2 - 1 - ( 2 * k ) + 4 * L2 )], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 4 * L2 )] ); // q + + r2_fx = Msub_32_16( 0, timeBuffer_fx[( L2 - 5 * M2 + ( 2 * k ) + 0 * L2 )], ptr_pf_fx[( L2 - 5 * M2 + ( 2 * k ) + 0 * L2 )] ); // q + r2_fx = Msub_32_16( r2_fx, timeBuffer_fx[( L2 - 5 * M2 + ( 2 * k ) + 1 * L2 )], ptr_pf_fx[( L2 - 5 * M2 + ( 2 * k ) + 1 * L2 )] ); // q + r2_fx = Msub_32_16( r2_fx, timeBuffer_fx[( L2 - 5 * M2 + ( 2 * k ) + 2 * L2 )], ptr_pf_fx[( L2 - 5 * M2 + ( 2 * k ) + 2 * L2 )] ); // q + r2_fx = Msub_32_16( r2_fx, timeBuffer_fx[( L2 - 5 * M2 + ( 2 * k ) + 3 * L2 )], ptr_pf_fx[( L2 - 5 * M2 + ( 2 * k ) + 3 * L2 )] ); // q + r2_fx = Msub_32_16( r2_fx, timeBuffer_fx[( L2 - 5 * M2 + ( 2 * k ) + 4 * L2 )], ptr_pf_fx[( L2 - 5 * M2 + ( 2 * k ) + 4 * L2 )] ); // q + + i1_fx = Msub_32_16( 0, timeBuffer_fx[( L2 + M2 - 1 - ( 2 * k ) + 0 * L2 )], ptr_pf_fx[( L2 + M2 - 1 - ( 2 * k ) + 0 * L2 )] ); // q + i1_fx = Msub_32_16( i1_fx, timeBuffer_fx[( L2 + M2 - 1 - ( 2 * k ) + 1 * L2 )], ptr_pf_fx[( L2 + M2 - 1 - ( 2 * k ) + 1 * L2 )] ); // q + i1_fx = Msub_32_16( i1_fx, timeBuffer_fx[( L2 + M2 - 1 - ( 2 * k ) + 2 * L2 )], ptr_pf_fx[( L2 + M2 - 1 - ( 2 * k ) + 2 * L2 )] ); // q + i1_fx = Msub_32_16( i1_fx, timeBuffer_fx[( L2 + M2 - 1 - ( 2 * k ) + 3 * L2 )], ptr_pf_fx[( L2 + M2 - 1 - ( 2 * k ) + 3 * L2 )] ); // q + i1_fx = Msub_32_16( i1_fx, timeBuffer_fx[( L2 + M2 - 1 - ( 2 * k ) + 4 * L2 )], ptr_pf_fx[( L2 + M2 - 1 - ( 2 * k ) + 4 * L2 )] ); // q + + i2_fx = Msub_32_16( 0, timeBuffer_fx[( L2 - 3 * M2 + ( 2 * k ) + 0 * L2 )], ptr_pf_fx[( L2 - 3 * M2 + ( 2 * k ) + 0 * L2 )] ); // q + i2_fx = Msub_32_16( i2_fx, timeBuffer_fx[( L2 - 3 * M2 + ( 2 * k ) + 1 * L2 )], ptr_pf_fx[( L2 - 3 * M2 + ( 2 * k ) + 1 * L2 )] ); // q + i2_fx = Msub_32_16( i2_fx, timeBuffer_fx[( L2 - 3 * M2 + ( 2 * k ) + 2 * L2 )], ptr_pf_fx[( L2 - 3 * M2 + ( 2 * k ) + 2 * L2 )] ); // q + i2_fx = Msub_32_16( i2_fx, timeBuffer_fx[( L2 - 3 * M2 + ( 2 * k ) + 3 * L2 )], ptr_pf_fx[( L2 - 3 * M2 + ( 2 * k ) + 3 * L2 )] ); // q + i2_fx = Msub_32_16( i2_fx, timeBuffer_fx[( L2 - 3 * M2 + ( 2 * k ) + 4 * L2 )], ptr_pf_fx[( L2 - 3 * M2 + ( 2 * k ) + 4 * L2 )] ); // q r1_fx = Mpy_32_16_1( r1_fx, ptr_pf_sf ); // q - 1 r2_fx = Mpy_32_16_1( r2_fx, ptr_pf_sf ); // q - 1 @@ -1144,8 +1138,8 @@ void cldfbAnalysis_ts_fx_fixed_q( rr12_fx = L_add( r1_fx, r2_fx ); // q - 1 ri12_fx = L_sub( i1_fx, i2_fx ); // q - 1 /*cplxMult(&rBuffer[2*k],&rBuffer[2*k+1],rr12,ri12,rot_vctr_re[k],rot_vctr_im[k]);*/ - rBuffer_fx[2 * k] = Msub_32_32( Mpy_32_32( rr12_fx, rot_vctr_re_fx[k] ), ri12_fx, rot_vctr_im_fx[k] ); // q - 3 - rBuffer_fx[add( 2 * k, 1 )] = Madd_32_32( Mpy_32_32( rr12_fx, rot_vctr_im_fx[k] ), ri12_fx, rot_vctr_re_fx[k] ); // q - 3 + rBuffer_fx[2 * k] = Msub_32_32( Mpy_32_32( rr12_fx, rot_vctr_re_fx[k] ), ri12_fx, rot_vctr_im_fx[k] ); // q - 3 + rBuffer_fx[2 * k + 1] = Madd_32_32( Mpy_32_32( rr12_fx, rot_vctr_im_fx[k] ), ri12_fx, rot_vctr_re_fx[k] ); // q - 3 move32(); move32(); @@ -1153,8 +1147,8 @@ void cldfbAnalysis_ts_fx_fixed_q( ir12_fx = L_sub( r1_fx, r2_fx ); // q - 1 ii12_fx = L_add( i1_fx, i2_fx ); // q - 1 /*cplxMult(&iBuffer[2*k],&iBuffer[2*k+1],ir12,ii12,rot_vctr_re[k],rot_vctr_im[k]);*/ - iBuffer_fx[2 * k] = Msub_32_32( Mpy_32_32( ir12_fx, rot_vctr_re_fx[k] ), ii12_fx, rot_vctr_im_fx[k] ); // q - 3 - iBuffer_fx[add( 2 * k, 1 )] = Madd_32_32( Mpy_32_32( ir12_fx, rot_vctr_im_fx[k] ), ii12_fx, rot_vctr_re_fx[k] ); // q - 3 + iBuffer_fx[2 * k] = Msub_32_32( Mpy_32_32( ir12_fx, rot_vctr_re_fx[k] ), ii12_fx, rot_vctr_im_fx[k] ); // q - 3 + iBuffer_fx[2 * k + 1] = Madd_32_32( Mpy_32_32( ir12_fx, rot_vctr_im_fx[k] ), ii12_fx, rot_vctr_re_fx[k] ); // q - 3 move32(); move32(); } @@ -1169,8 +1163,8 @@ void cldfbAnalysis_ts_fx_fixed_q( FOR( k = 0; k < M2; k++ ) { /*cplxMult(&realBuffer[M1-1-(2*k)],&realBuffer[2*k],rBuffer[2*k],rBuffer[2*k+1],rot_vctr_re[k],rot_vctr_im[k]);*/ - realBuffer_fx[sub( sub( M1, 1 ), shl( k, 1 ) )] = Msub_32_32( Mpy_32_32( rBuffer_fx[2 * k], rot_vctr_re_fx[k] ), rBuffer_fx[add( 2 * k, 1 )], rot_vctr_im_fx[k] ); // q - 5 - realBuffer_fx[2 * k] = Madd_32_32( Mpy_32_32( rBuffer_fx[2 * k], rot_vctr_im_fx[k] ), rBuffer_fx[add( 2 * k, 1 )], rot_vctr_re_fx[k] ); // q - 5 + realBuffer_fx[( M1 - 1 ) - ( k * 2 )] = Msub_32_32( Mpy_32_32( rBuffer_fx[2 * k], rot_vctr_re_fx[k] ), rBuffer_fx[2 * k + 1], rot_vctr_im_fx[k] ); // q - 5 + realBuffer_fx[2 * k] = Madd_32_32( Mpy_32_32( rBuffer_fx[2 * k], rot_vctr_im_fx[k] ), rBuffer_fx[2 * k + 1], rot_vctr_re_fx[k] ); // q - 5 move32(); move32(); } @@ -1185,8 +1179,8 @@ void cldfbAnalysis_ts_fx_fixed_q( { /* do it inplace */ /*cplxMult(&imagBuffer[2*k],&imagBuffer[M1-1-(2*k)],iBuffer[2*k],iBuffer[2*k+1],rot_vctr_re[k],rot_vctr_im[k]);*/ - imagBuffer_fx[2 * k] = Msub_32_32( Mpy_32_32( iBuffer_fx[2 * k], rot_vctr_re_fx[k] ), iBuffer_fx[add( 2 * k, 1 )], rot_vctr_im_fx[k] ); // q - 5 - imagBuffer_fx[sub( sub( M1, 1 ), shl( k, 1 ) )] = Madd_32_32( Mpy_32_32( iBuffer_fx[2 * k], rot_vctr_im_fx[k] ), iBuffer_fx[add( 2 * k, 1 )], rot_vctr_re_fx[k] ); // q - 5 + imagBuffer_fx[2 * k] = Msub_32_32( Mpy_32_32( iBuffer_fx[2 * k], rot_vctr_re_fx[k] ), iBuffer_fx[2 * k + 1], rot_vctr_im_fx[k] ); // q - 5 + imagBuffer_fx[( M1 - 1 ) - ( k * 2 )] = Madd_32_32( Mpy_32_32( iBuffer_fx[2 * k], rot_vctr_im_fx[k] ), iBuffer_fx[2 * k + 1], rot_vctr_re_fx[k] ); // q - 5 move32(); move32(); } @@ -1459,6 +1453,7 @@ void cldfbSynthesis_ivas_fx( move16(); M1 = h_cldfb->no_channels; + move16(); L2 = shl( M1, 1 ); M2 = shr( M1, 1 ); M41 = shr( M2, 1 ); @@ -1468,7 +1463,7 @@ void cldfbSynthesis_ivas_fx( /* only process needed cols */ IF( GT_16( samplesToProcess, -1 ) ) { - no_col = min( no_col, idiv1616( sub( add( samplesToProcess, h_cldfb->no_channels ), 1 ), h_cldfb->no_channels ) ); + no_col = s_min( no_col, idiv1616( sub( add( samplesToProcess, h_cldfb->no_channels ), 1 ), h_cldfb->no_channels ) ); move16(); } @@ -1491,7 +1486,7 @@ void cldfbSynthesis_ivas_fx( FOR( k = 0; k < no_col; k++ ) { - IF( EQ_16( (Word16) h_cldfb->prototype, (Word16) CLDFB_PROTOTYPE_5_00MS ) ) + IF( EQ_16( h_cldfb->prototype, CLDFB_PROTOTYPE_5_00MS ) ) { /* rotation due to delay*/ /*if(h_cldfb->ds != M1)*/ @@ -1527,16 +1522,16 @@ void cldfbSynthesis_ivas_fx( { /* pre modulation of DST IV */ /*cplxMult(&rBuffer[2*i], &rBuffer[2*i+1], realBuffer[k][2*i], realBuffer[k][M1-1-2*i], rot_vctr_re[i], rot_vctr_im[i]);*/ - rBuffer_fx[2 * i] = Msub_32_32( Mpy_32_32( realBuffer_fx[k][2 * i], rot_vctr_re_fx[i] ), realBuffer_fx[k][sub( sub( M1, 1 ), shl( i, 1 ) )], rot_vctr_im_fx[i] ); // Qx + rBuffer_fx[2 * i] = Msub_32_32( Mpy_32_32( realBuffer_fx[k][2 * i], rot_vctr_re_fx[i] ), realBuffer_fx[k][( M1 - 1 ) - ( i * 2 )], rot_vctr_im_fx[i] ); // Qx move32(); - rBuffer_fx[add( 2 * i, 1 )] = Madd_32_32( Mpy_32_32( realBuffer_fx[k][2 * i], rot_vctr_im_fx[i] ), realBuffer_fx[k][sub( sub( M1, 1 ), shl( i, 1 ) )], rot_vctr_re_fx[i] ); // Qx + rBuffer_fx[2 * i + 1] = Madd_32_32( Mpy_32_32( realBuffer_fx[k][2 * i], rot_vctr_im_fx[i] ), realBuffer_fx[k][( M1 - 1 ) - ( i * 2 )], rot_vctr_re_fx[i] ); // Qx move32(); /* pre modulation of DCT IV */ /*cplxMult(&iBuffer[2*i], &iBuffer[2*i+1],-imagBuffer[k][2*i], imagBuffer[k][M1-1-2*i], rot_vctr_re[i], rot_vctr_im[i]);*/ - iBuffer_fx[2 * i] = Msub_32_32( Mpy_32_32( ( L_negate( imagBuffer_fx[k][2 * i] ) ), rot_vctr_re_fx[i] ), imagBuffer_fx[k][sub( sub( M1, 1 ), shl( i, 1 ) )], rot_vctr_im_fx[i] ); // Qx + iBuffer_fx[2 * i] = Msub_32_32( Mpy_32_32( ( L_negate( imagBuffer_fx[k][2 * i] ) ), rot_vctr_re_fx[i] ), imagBuffer_fx[k][( M1 - 1 ) - ( i * 2 )], rot_vctr_im_fx[i] ); // Qx move32(); - iBuffer_fx[add( 2 * i, 1 )] = Madd_32_32( Mpy_32_32( ( L_negate( imagBuffer_fx[k][2 * i] ) ), rot_vctr_im_fx[i] ), imagBuffer_fx[k][sub( sub( M1, 1 ), shl( i, 1 ) )], rot_vctr_re_fx[i] ); // Qx + iBuffer_fx[2 * i + 1] = Madd_32_32( Mpy_32_32( ( L_negate( imagBuffer_fx[k][2 * i] ) ), rot_vctr_im_fx[i] ), imagBuffer_fx[k][( M1 - 1 ) - ( i * 2 )], rot_vctr_re_fx[i] ); // Qx move32(); } @@ -1550,69 +1545,69 @@ void cldfbSynthesis_ivas_fx( FOR( i = 0; i < M41; i++ ) { /* post modulation of DST IV */ - rr12_fx = Msub_32_32( Mpy_32_32( rBuffer_fx[sub( sub( M1, 2 ), shl( i, 1 ) )], rot_vctr_re_fx[sub( sub( M2, 1 ), i )] ), rBuffer_fx[sub( sub( M1, 1 ), shl( i, 1 ) )], rot_vctr_im_fx[sub( sub( M2, 1 ), i )] ); // Qx - ri12_fx = Madd_32_32( Mpy_32_32( rBuffer_fx[sub( sub( M1, 2 ), shl( i, 1 ) )], rot_vctr_im_fx[sub( sub( M2, 1 ), i )] ), rBuffer_fx[sub( sub( M1, 1 ), shl( i, 1 ) )], rot_vctr_re_fx[sub( sub( M2, 1 ), i )] ); // Qx + rr12_fx = Msub_32_32( Mpy_32_32( rBuffer_fx[( M1 - 2 ) - ( i * 2 )], rot_vctr_re_fx[( M2 - 1 ) - i] ), rBuffer_fx[( M1 - 1 ) - ( i * 2 )], rot_vctr_im_fx[( M2 - 1 ) - i] ); // Qx + ri12_fx = Madd_32_32( Mpy_32_32( rBuffer_fx[( M1 - 2 ) - ( i * 2 )], rot_vctr_im_fx[( M2 - 1 ) - i] ), rBuffer_fx[( M1 - 1 ) - ( i * 2 )], rot_vctr_re_fx[( M2 - 1 ) - i] ); // Qx /* post modulation of DCT IV */ - ir12_fx = Msub_32_32( Mpy_32_32( iBuffer_fx[sub( sub( M1, 2 ), shl( i, 1 ) )], rot_vctr_re_fx[sub( sub( M2, 1 ), i )] ), iBuffer_fx[sub( sub( M1, 1 ), shl( i, 1 ) )], rot_vctr_im_fx[sub( sub( M2, 1 ), i )] ); // Qx - ii12_fx = Madd_32_32( Mpy_32_32( iBuffer_fx[sub( sub( M1, 2 ), shl( i, 1 ) )], rot_vctr_im_fx[sub( sub( M2, 1 ), i )] ), iBuffer_fx[sub( sub( M1, 1 ), shl( i, 1 ) )], rot_vctr_re_fx[sub( sub( M2, 1 ), i )] ); // Qx + ir12_fx = Msub_32_32( Mpy_32_32( iBuffer_fx[( M1 - 2 ) - ( i * 2 )], rot_vctr_re_fx[( M2 - 1 ) - i] ), iBuffer_fx[( M1 - 1 ) - ( i * 2 )], rot_vctr_im_fx[( M2 - 1 ) - i] ); // Qx + ii12_fx = Madd_32_32( Mpy_32_32( iBuffer_fx[( M1 - 2 ) - ( i * 2 )], rot_vctr_im_fx[( M2 - 1 ) - i] ), iBuffer_fx[( M1 - 1 ) - ( i * 2 )], rot_vctr_re_fx[( M2 - 1 ) - i] ); // Qx - new_samples_fx[add( add( add( M1, M2 ), 1 ), shl( i, 1 ) )] = L_negate( L_add( rr12_fx, ii12_fx ) ); // Qx + new_samples_fx[M1 + M2 + 1 + 2 * i] = L_negate( L_add( rr12_fx, ii12_fx ) ); // Qx move32(); - new_samples_fx[sub( sub( M2, 2 ), shl( i, 1 ) )] = L_negate( L_add( ri12_fx, ir12_fx ) ); // Qx + new_samples_fx[M2 - 2 - 2 * i] = L_negate( L_add( ri12_fx, ir12_fx ) ); // Qx move32(); - new_samples_fx[sub( sub( add( M1, M2 ), 2 ), shl( i, 1 ) )] = L_sub( rr12_fx, ii12_fx ); // Qx + new_samples_fx[M1 + M2 - 2 - 2 * i] = L_sub( rr12_fx, ii12_fx ); // Qx move32(); - new_samples_fx[add( add( M2, 1 ), shl( i, 1 ) )] = L_sub( ir12_fx, ri12_fx ); // Qx + new_samples_fx[M2 + 1 + 2 * i] = L_sub( ir12_fx, ri12_fx ); // Qx move32(); } FOR( i = 0; i < M42; i++ ) { /* post modulation of DST IV */ - rr12_fx = Msub_32_32( Mpy_32_32( rBuffer_fx[2 * i], rot_vctr_re_fx[i] ), rBuffer_fx[add( 2 * i, 1 )], rot_vctr_im_fx[i] ); // Qx - ri12_fx = Madd_32_32( Mpy_32_32( rBuffer_fx[2 * i], rot_vctr_im_fx[i] ), rBuffer_fx[add( 2 * i, 1 )], rot_vctr_re_fx[i] ); // Qx + rr12_fx = Msub_32_32( Mpy_32_32( rBuffer_fx[2 * i], rot_vctr_re_fx[i] ), rBuffer_fx[2 * i + 1], rot_vctr_im_fx[i] ); // Qx + ri12_fx = Madd_32_32( Mpy_32_32( rBuffer_fx[2 * i], rot_vctr_im_fx[i] ), rBuffer_fx[2 * i + 1], rot_vctr_re_fx[i] ); // Qx /* post modulation of DCT IV */ - ir12_fx = Msub_32_32( Mpy_32_32( iBuffer_fx[2 * i], rot_vctr_re_fx[i] ), iBuffer_fx[add( 2 * i, 1 )], rot_vctr_im_fx[i] ); // Qx - ii12_fx = Madd_32_32( Mpy_32_32( iBuffer_fx[2 * i], rot_vctr_im_fx[i] ), iBuffer_fx[add( 2 * i, 1 )], rot_vctr_re_fx[i] ); // Qx + ir12_fx = Msub_32_32( Mpy_32_32( iBuffer_fx[2 * i], rot_vctr_re_fx[i] ), iBuffer_fx[2 * i + 1], rot_vctr_im_fx[i] ); // Qx + ii12_fx = Madd_32_32( Mpy_32_32( iBuffer_fx[2 * i], rot_vctr_im_fx[i] ), iBuffer_fx[2 * i + 1], rot_vctr_re_fx[i] ); // Qx - new_samples_fx[add( add( M1, M2 ), shl( i, 1 ) )] = L_add( ri12_fx, ir12_fx ); // Qx + new_samples_fx[M1 + M2 + 2 * i] = L_add( ri12_fx, ir12_fx ); // Qx move32(); - new_samples_fx[sub( sub( M2, 1 ), shl( i, 1 ) )] = L_add( rr12_fx, ii12_fx ); // Qx + new_samples_fx[M2 - 1 - 2 * i] = L_add( rr12_fx, ii12_fx ); // Qx move32(); - new_samples_fx[sub( sub( add( M1, M2 ), 1 ), shl( i, 1 ) )] = L_sub( ir12_fx, ri12_fx ); // Qx + new_samples_fx[M1 + M2 - 1 - 2 * i] = L_sub( ir12_fx, ri12_fx ); // Qx move32(); - new_samples_fx[add( M2, shl( i, 1 ) )] = L_sub( rr12_fx, ii12_fx ); // Qx + new_samples_fx[M2 + 2 * i] = L_sub( rr12_fx, ii12_fx ); // Qx move32(); } /* synthesis prototype filter */ FOR( i = 0; i < L2; i++ ) { - accu0 = Madd_32_16( synthesisBuffer_fx[i], Mpy_32_16_1( new_samples_fx[sub( sub( L2, 1 ), i )], p_filter[i] ), p_filter_sf ); // Qx - 1 - accu1 = Madd_32_16( synthesisBuffer_fx[add( L2, i )], Mpy_32_16_1( new_samples_fx[sub( sub( L2, 1 ), i )], p_filter[add( L2, i )] ), p_filter_sf ); // Qx - 1 - accu2 = Madd_32_16( synthesisBuffer_fx[add( i_mult( 2, L2 ), i )], Mpy_32_16_1( new_samples_fx[sub( sub( L2, 1 ), i )], p_filter[add( i_mult( 2, L2 ), i )] ), p_filter_sf ); // Qx - 1 - accu3 = Madd_32_16( synthesisBuffer_fx[add( i_mult( 3, L2 ), i )], Mpy_32_16_1( new_samples_fx[sub( sub( L2, 1 ), i )], p_filter[add( i_mult( 3, L2 ), i )] ), p_filter_sf ); // Qx - 1 - accu4 = Madd_32_16( synthesisBuffer_fx[add( i_mult( 4, L2 ), i )], Mpy_32_16_1( new_samples_fx[sub( sub( L2, 1 ), i )], p_filter[add( i_mult( 4, L2 ), i )] ), p_filter_sf ); // Qx - 1 + accu0 = Madd_32_16( synthesisBuffer_fx[i], Mpy_32_16_1( new_samples_fx[L2 - 1 - i], p_filter[i] ), p_filter_sf ); // Qx - 1 + accu1 = Madd_32_16( synthesisBuffer_fx[1 * L2 + i], Mpy_32_16_1( new_samples_fx[L2 - 1 - i], p_filter[( 1 * L2 + i )] ), p_filter_sf ); // Qx - 1 + accu2 = Madd_32_16( synthesisBuffer_fx[2 * L2 + i], Mpy_32_16_1( new_samples_fx[L2 - 1 - i], p_filter[( 2 * L2 + i )] ), p_filter_sf ); // Qx - 1 + accu3 = Madd_32_16( synthesisBuffer_fx[3 * L2 + i], Mpy_32_16_1( new_samples_fx[L2 - 1 - i], p_filter[( 3 * L2 + i )] ), p_filter_sf ); // Qx - 1 + accu4 = Madd_32_16( synthesisBuffer_fx[4 * L2 + i], Mpy_32_16_1( new_samples_fx[L2 - 1 - i], p_filter[( 4 * L2 + i )] ), p_filter_sf ); // Qx - 1 synthesisBuffer_fx[i] = accu0; move32(); - synthesisBuffer_fx[add( L2, i )] = accu1; + synthesisBuffer_fx[1 * L2 + i] = accu1; move32(); - synthesisBuffer_fx[add( i_mult( 2, L2 ), i )] = accu2; + synthesisBuffer_fx[2 * L2 + i] = accu2; move32(); - synthesisBuffer_fx[add( i_mult( 3, L2 ), i )] = accu3; + synthesisBuffer_fx[3 * L2 + i] = accu3; move32(); - synthesisBuffer_fx[add( i_mult( 4, L2 ), i )] = accu4; + synthesisBuffer_fx[4 * L2 + i] = accu4; move32(); } FOR( i = 0; i < M1; i++ ) { - ptr_time_out_fx[sub( sub( M1, 1 ), i )] = synthesisBuffer_fx[add( i_mult( 4, L2 ), add( M1, i ) )]; + ptr_time_out_fx[( M1 - 1 ) - i] = synthesisBuffer_fx[4 * L2 + M1 + i]; move32(); } @@ -1728,9 +1723,9 @@ ivas_error openCldfb_ivas_fx( } hs->type = type; - move16(); + move32(); hs->prototype = prototype; - move16(); + move32(); configureCldfb_ivas_fx( hs, sampling_rate ); hs->memory32 = NULL; hs->FilterStates = NULL; @@ -1958,11 +1953,11 @@ void analysisCldfbEncoder_ivas_fx( Word32 *timeIn, /*q11*/ Word16 timeInq, Word16 samplesToProcess, - Word32 realBuffer[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], - Word32 imagBuffer[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], - Word16 realBuffer16[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], - Word16 imagBuffer16[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], - Word32 *ppBuf_Ener, + Word32 realBuffer[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], // Q(scale.lb_scale) + Word32 imagBuffer[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], // Q(scale.lb_scale) + Word16 realBuffer16[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], // Q15 + Word16 imagBuffer16[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], // Q15 + Word32 *ppBuf_Ener, // Q(31-enerBuffSum_exp) Word16 *enerBuffSum_exp, CLDFB_SCALE_FACTOR *scale ) { @@ -2135,6 +2130,7 @@ void deleteCldfb_ivas_fx( { HANDLE_CLDFB_FILTER_BANK hs = *h_cldfb; + test(); IF( h_cldfb == NULL || *h_cldfb == NULL ) { return; @@ -3239,7 +3235,7 @@ ivas_error cldfb_save_memory_ivas_fx( ) { UWord16 offset = sub( hs->p_filter_length, hs->no_channels ); - + test(); IF( hs->memory32 != NULL || ( hs->memory_length != 0 ) ) { /* memory already stored; Free memory first */ diff --git a/lib_com/cldfb_evs.c b/lib_com/cldfb_evs.c index 1186c82fa..c22e583be 100644 --- a/lib_com/cldfb_evs.c +++ b/lib_com/cldfb_evs.c @@ -241,9 +241,9 @@ static void calcModulation( Word32 *rYR, C_c = C_form( *cr, *ci ); CL_z = CL_mult_32x16( CL_x, C_c ); *rYR = CL_Extract_real( CL_z ); - move64(); + move32(); *rYI = CL_Extract_imag( CL_z ); - move64(); + move32(); rYR += srYR; rYI += srYI; rXR += srXR; @@ -252,9 +252,9 @@ static void calcModulation( Word32 *rYR, CL_x = CL_form( *iXR, *iXI ); CL_z = CL_mult_32x16( CL_x, C_c ); *iYR = CL_Extract_real( CL_z ); - move64(); + move32(); *iYI = CL_Extract_imag( CL_z ); - move64(); + move32(); iYR += siYR; iYI += siYI; iXR += siXR; @@ -301,14 +301,14 @@ static void calcModulationAndFolding( Word16 *rY, const Word16 *r11, *r12, *r21, *r22; - y11 = &rY[add( add( m, m2 ), 1 )]; - y12 = &rY[sub( m2, 2 )]; - y13 = &rY[sub( add( m, m2 ), 2 )]; + y11 = &rY[( m + m2 ) + 1]; + y12 = &rY[m2 - 2]; + y13 = &rY[( m + m2 ) - 2]; y14 = &rY[m2 + 1]; - y21 = &rY[add( m, m2 )]; + y21 = &rY[m + m2]; y22 = &rY[m2 - 1]; - y23 = &rY[sub( add( m, m2 ), 1 )]; + y23 = &rY[( m + m2 ) - 1]; y24 = &rY[m2]; x11 = &rX[m - 2]; @@ -376,10 +376,11 @@ void cldfbAnalysisFiltering( HANDLE_CLDFB_FILTER_BANK cldfbBank, Word32 **rAnalysis, Word32 **iAnalysis, CLDFB_SCALE_FACTOR *scaleFactor, - const Word16 *timeIn, + const Word16 *timeIn, // Q(15-timeIn_e) const Word16 timeIn_e, const Word16 nTimeSlots, - Word32 *pWorkBuffer ) + Word32 *pWorkBuffer // Qx +) { Word16 i, k; @@ -450,13 +451,14 @@ void cldfbAnalysisFiltering( HANDLE_CLDFB_FILTER_BANK cldfbBank, pStates6 = &pStates[M0M2]; p_stride = CLDFB_NO_POLY; + move16(); pFilter = &cldfbBank->p_filter[p_stride - CLDFB_NO_POLY]; - pFilter1 = &pFilter[i_mult( p_stride, L3M1 )]; - pFilter2 = &pFilter[i_mult( p_stride, L3 )]; - pFilter3 = &pFilter[i_mult( p_stride, m2 )]; - pFilter4 = &pFilter[i_mult( p_stride, M2M1 )]; - pFilter5 = &pFilter[i_mult( p_stride, L4M1 )]; - pFilter6 = &pFilter[i_mult( p_stride, M0M2 )]; + pFilter1 = &pFilter[p_stride * L3M1]; + pFilter2 = &pFilter[p_stride * L3]; + pFilter3 = &pFilter[p_stride * m2]; + pFilter4 = &pFilter[p_stride * M2M1]; + pFilter5 = &pFilter[p_stride * L4M1]; + pFilter6 = &pFilter[p_stride * M0M2]; nSamples = i_mult( nTimeSlots, cldfbBank->no_channels ); nSamplesUpd = i_mult( cldfbBank->no_col, cldfbBank->no_channels ); @@ -469,7 +471,7 @@ void cldfbAnalysisFiltering( HANDLE_CLDFB_FILTER_BANK cldfbBank, move16(); FOR( i = 0; i < offset; i += cldfbBank->no_channels ) { - cldfbBank->FilterStates_e[k] = cldfbBank->FilterStates_e[add( k, cldfbBank->no_col )]; + cldfbBank->FilterStates_e[k] = cldfbBank->FilterStates_e[( k + cldfbBank->no_col )]; move16(); assert( (size_t) k < sizeof( cldfbBank->FilterStates_e ) / sizeof( cldfbBank->FilterStates_e[0] ) ); scale = s_max( scale, cldfbBank->FilterStates_e[k] ); @@ -496,7 +498,7 @@ void cldfbAnalysisFiltering( HANDLE_CLDFB_FILTER_BANK cldfbBank, FOR( i = 0; i < offset; i++ ) { #ifdef BASOP_NOGLOB - pStates[i] = shl_sat( pStates[i + nSamplesUpd], scale ); + pStates[i] = shl_sat( pStates[i + nSamplesUpd], scale ); // Q(15-(timeIn_e-FilterStates_eg)) #else pStates[i] = shl( pStates[i + nSamplesUpd], scale ); #endif @@ -508,7 +510,7 @@ void cldfbAnalysisFiltering( HANDLE_CLDFB_FILTER_BANK cldfbBank, FOR( i = 0; i < nSamples; i++ ) { #ifdef BASOP_NOGLOB - pStates[offset + i] = shl_sat( *timeIn, scale ); + pStates[offset + i] = shl_sat( *timeIn, scale ); // Q(15-scale) #else pStates[offset + i] = shl( *timeIn, scale ); #endif @@ -521,80 +523,80 @@ void cldfbAnalysisFiltering( HANDLE_CLDFB_FILTER_BANK cldfbBank, FOR( i = 0; i < M4; i++ ) { /* prototype filter */ - r1 = L_msu0( 0, pFilter1[sub( 0, i_mult( p_stride, shl( i, 1 ) ) )], pStates1[sub( i_mult( 0, L2 ), shl( i, 1 ) )] ); - r1 = L_msu0( r1, pFilter1[sub( 1, i_mult( p_stride, shl( i, 1 ) ) )], pStates1[sub( i_mult( 1, L2 ), shl( i, 1 ) )] ); - r1 = L_msu0( r1, pFilter1[sub( 2, i_mult( p_stride, shl( i, 1 ) ) )], pStates1[sub( i_mult( 2, L2 ), shl( i, 1 ) )] ); - r1 = L_msu0( r1, pFilter1[sub( 3, i_mult( p_stride, shl( i, 1 ) ) )], pStates1[sub( i_mult( 3, L2 ), shl( i, 1 ) )] ); - r1 = L_msu0( r1, pFilter1[sub( 4, i_mult( p_stride, shl( i, 1 ) ) )], pStates1[sub( i_mult( 4, L2 ), shl( i, 1 ) )] ); - - r2 = L_msu0( 0, pFilter2[add( 0, i_mult( p_stride, shl( i, 1 ) ) )], pStates2[add( i_mult( 0, L2 ), shl( i, 1 ) )] ); - r2 = L_msu0( r2, pFilter2[add( 1, i_mult( p_stride, shl( i, 1 ) ) )], pStates2[add( i_mult( 1, L2 ), shl( i, 1 ) )] ); - r2 = L_msu0( r2, pFilter2[add( 2, i_mult( p_stride, shl( i, 1 ) ) )], pStates2[add( i_mult( 2, L2 ), shl( i, 1 ) )] ); - r2 = L_msu0( r2, pFilter2[add( 3, i_mult( p_stride, shl( i, 1 ) ) )], pStates2[add( i_mult( 3, L2 ), shl( i, 1 ) )] ); - r2 = L_msu0( r2, pFilter2[add( 4, i_mult( p_stride, shl( i, 1 ) ) )], pStates2[add( i_mult( 4, L2 ), shl( i, 1 ) )] ); - - i1 = L_msu0( 0, pFilter3[add( 0, i_mult( p_stride, shl( i, 1 ) ) )], pStates3[add( i_mult( 0, L2 ), shl( i, 1 ) )] ); - i1 = L_msu0( i1, pFilter3[add( 1, i_mult( p_stride, shl( i, 1 ) ) )], pStates3[add( i_mult( 1, L2 ), shl( i, 1 ) )] ); - i1 = L_msu0( i1, pFilter3[add( 2, i_mult( p_stride, shl( i, 1 ) ) )], pStates3[add( i_mult( 2, L2 ), shl( i, 1 ) )] ); - i1 = L_msu0( i1, pFilter3[add( 3, i_mult( p_stride, shl( i, 1 ) ) )], pStates3[add( i_mult( 3, L2 ), shl( i, 1 ) )] ); - i1 = L_msu0( i1, pFilter3[add( 4, i_mult( p_stride, shl( i, 1 ) ) )], pStates3[add( i_mult( 4, L2 ), shl( i, 1 ) )] ); - - i2 = L_msu0( 0, pFilter4[sub( 0, i_mult( p_stride, shl( i, 1 ) ) )], pStates4[sub( i_mult( 0, L2 ), shl( i, 1 ) )] ); - i2 = L_msu0( i2, pFilter4[sub( 1, i_mult( p_stride, shl( i, 1 ) ) )], pStates4[sub( i_mult( 1, L2 ), shl( i, 1 ) )] ); - i2 = L_msu0( i2, pFilter4[sub( 2, i_mult( p_stride, shl( i, 1 ) ) )], pStates4[sub( i_mult( 2, L2 ), shl( i, 1 ) )] ); - i2 = L_msu0( i2, pFilter4[sub( 3, i_mult( p_stride, shl( i, 1 ) ) )], pStates4[sub( i_mult( 3, L2 ), shl( i, 1 ) )] ); - i2 = L_msu0( i2, pFilter4[sub( 4, i_mult( p_stride, shl( i, 1 ) ) )], pStates4[sub( i_mult( 4, L2 ), shl( i, 1 ) )] ); + r1 = L_msu0( 0, pFilter1[0 - ( p_stride * ( i * 2 ) )], pStates1[( 0 * L2 ) - ( i * 2 )] ); + r1 = L_msu0( r1, pFilter1[1 - ( p_stride * ( i * 2 ) )], pStates1[( 1 * L2 ) - ( i * 2 )] ); + r1 = L_msu0( r1, pFilter1[2 - ( p_stride * ( i * 2 ) )], pStates1[( 2 * L2 ) - ( i * 2 )] ); + r1 = L_msu0( r1, pFilter1[3 - ( p_stride * ( i * 2 ) )], pStates1[( 3 * L2 ) - ( i * 2 )] ); + r1 = L_msu0( r1, pFilter1[4 - ( p_stride * ( i * 2 ) )], pStates1[( 4 * L2 ) - ( i * 2 )] ); + + r2 = L_msu0( 0, pFilter2[0 + ( p_stride * ( i * 2 ) )], pStates2[( 0 * L2 ) + ( i * 2 )] ); + r2 = L_msu0( r2, pFilter2[1 + ( p_stride * ( i * 2 ) )], pStates2[( 1 * L2 ) + ( i * 2 )] ); + r2 = L_msu0( r2, pFilter2[2 + ( p_stride * ( i * 2 ) )], pStates2[( 2 * L2 ) + ( i * 2 )] ); + r2 = L_msu0( r2, pFilter2[3 + ( p_stride * ( i * 2 ) )], pStates2[( 3 * L2 ) + ( i * 2 )] ); + r2 = L_msu0( r2, pFilter2[4 + ( p_stride * ( i * 2 ) )], pStates2[( 4 * L2 ) + ( i * 2 )] ); + + i1 = L_msu0( 0, pFilter3[0 + ( p_stride * ( i * 2 ) )], pStates3[( 0 * L2 ) + ( i * 2 )] ); + i1 = L_msu0( i1, pFilter3[1 + ( p_stride * ( i * 2 ) )], pStates3[( 1 * L2 ) + ( i * 2 )] ); + i1 = L_msu0( i1, pFilter3[2 + ( p_stride * ( i * 2 ) )], pStates3[( 2 * L2 ) + ( i * 2 )] ); + i1 = L_msu0( i1, pFilter3[3 + ( p_stride * ( i * 2 ) )], pStates3[( 3 * L2 ) + ( i * 2 )] ); + i1 = L_msu0( i1, pFilter3[4 + ( p_stride * ( i * 2 ) )], pStates3[( 4 * L2 ) + ( i * 2 )] ); + + i2 = L_msu0( 0, pFilter4[0 - ( p_stride * ( i * 2 ) )], pStates4[( 0 * L2 ) - ( i * 2 )] ); + i2 = L_msu0( i2, pFilter4[1 - ( p_stride * ( i * 2 ) )], pStates4[( 1 * L2 ) - ( i * 2 )] ); + i2 = L_msu0( i2, pFilter4[2 - ( p_stride * ( i * 2 ) )], pStates4[( 2 * L2 ) - ( i * 2 )] ); + i2 = L_msu0( i2, pFilter4[3 - ( p_stride * ( i * 2 ) )], pStates4[( 3 * L2 ) - ( i * 2 )] ); + i2 = L_msu0( i2, pFilter4[4 - ( p_stride * ( i * 2 ) )], pStates4[( 4 * L2 ) - ( i * 2 )] ); /* folding */ rBuffer[2 * i] = L_sub( r1, r2 ); move32(); - rBuffer[add( shl( i, 1 ), 1 )] = L_negate( L_add( i1, i2 ) ); + rBuffer[( ( i * 2 ) + 1 )] = L_negate( L_add( i1, i2 ) ); move32(); /* folding */ iBuffer[2 * i] = L_add( r1, r2 ); move32(); - iBuffer[add( shl( i, 1 ), 1 )] = L_sub( i1, i2 ); + iBuffer[( ( i * 2 ) + 1 )] = L_sub( i1, i2 ); move32(); } FOR( i = M4; i < m2; i++ ) { /* prototype filter */ - r1 = L_msu0( 0, pFilter1[sub( 0, i_mult( p_stride, shl( i, 1 ) ) )], pStates1[sub( i_mult( 0, L2 ), shl( i, 1 ) )] ); - r1 = L_msu0( r1, pFilter1[sub( 1, i_mult( p_stride, shl( i, 1 ) ) )], pStates1[sub( i_mult( 1, L2 ), shl( i, 1 ) )] ); - r1 = L_msu0( r1, pFilter1[sub( 2, i_mult( p_stride, shl( i, 1 ) ) )], pStates1[sub( i_mult( 2, L2 ), shl( i, 1 ) )] ); - r1 = L_msu0( r1, pFilter1[sub( 3, i_mult( p_stride, shl( i, 1 ) ) )], pStates1[sub( i_mult( 3, L2 ), shl( i, 1 ) )] ); - r1 = L_msu0( r1, pFilter1[sub( 4, i_mult( p_stride, shl( i, 1 ) ) )], pStates1[sub( i_mult( 4, L2 ), shl( i, 1 ) )] ); - - r2 = L_msu0( 0, pFilter6[add( 0, i_mult( p_stride, shl( i, 1 ) ) )], pStates6[add( i_mult( 0, L2 ), shl( i, 1 ) )] ); - r2 = L_msu0( r2, pFilter6[add( 1, i_mult( p_stride, shl( i, 1 ) ) )], pStates6[add( i_mult( 1, L2 ), shl( i, 1 ) )] ); - r2 = L_msu0( r2, pFilter6[add( 2, i_mult( p_stride, shl( i, 1 ) ) )], pStates6[add( i_mult( 2, L2 ), shl( i, 1 ) )] ); - r2 = L_msu0( r2, pFilter6[add( 3, i_mult( p_stride, shl( i, 1 ) ) )], pStates6[add( i_mult( 3, L2 ), shl( i, 1 ) )] ); - r2 = L_msu0( r2, pFilter6[add( 4, i_mult( p_stride, shl( i, 1 ) ) )], pStates6[add( i_mult( 4, L2 ), shl( i, 1 ) )] ); - - i1 = L_msu0( 0, pFilter5[sub( 0, i_mult( p_stride, shl( i, 1 ) ) )], pStates5[sub( i_mult( 0, L2 ), shl( i, 1 ) )] ); - i1 = L_msu0( i1, pFilter5[sub( 1, i_mult( p_stride, shl( i, 1 ) ) )], pStates5[sub( i_mult( 1, L2 ), shl( i, 1 ) )] ); - i1 = L_msu0( i1, pFilter5[sub( 2, i_mult( p_stride, shl( i, 1 ) ) )], pStates5[sub( i_mult( 2, L2 ), shl( i, 1 ) )] ); - i1 = L_msu0( i1, pFilter5[sub( 3, i_mult( p_stride, shl( i, 1 ) ) )], pStates5[sub( i_mult( 3, L2 ), shl( i, 1 ) )] ); - i1 = L_msu0( i1, pFilter5[sub( 4, i_mult( p_stride, shl( i, 1 ) ) )], pStates5[sub( i_mult( 4, L2 ), shl( i, 1 ) )] ); - - i2 = L_msu0( 0, pFilter3[add( 0, i_mult( p_stride, shl( i, 1 ) ) )], pStates3[add( i_mult( 0, L2 ), shl( i, 1 ) )] ); - i2 = L_msu0( i2, pFilter3[add( 1, i_mult( p_stride, shl( i, 1 ) ) )], pStates3[add( i_mult( 1, L2 ), shl( i, 1 ) )] ); - i2 = L_msu0( i2, pFilter3[add( 2, i_mult( p_stride, shl( i, 1 ) ) )], pStates3[add( i_mult( 2, L2 ), shl( i, 1 ) )] ); - i2 = L_msu0( i2, pFilter3[add( 3, i_mult( p_stride, shl( i, 1 ) ) )], pStates3[add( i_mult( 3, L2 ), shl( i, 1 ) )] ); - i2 = L_msu0( i2, pFilter3[add( 4, i_mult( p_stride, shl( i, 1 ) ) )], pStates3[add( i_mult( 4, L2 ), shl( i, 1 ) )] ); + r1 = L_msu0( 0, pFilter1[0 - ( p_stride * ( i * 2 ) )], pStates1[( 0 * L2 ) - ( i * 2 )] ); + r1 = L_msu0( r1, pFilter1[1 - ( p_stride * ( i * 2 ) )], pStates1[( 1 * L2 ) - ( i * 2 )] ); + r1 = L_msu0( r1, pFilter1[2 - ( p_stride * ( i * 2 ) )], pStates1[( 2 * L2 ) - ( i * 2 )] ); + r1 = L_msu0( r1, pFilter1[3 - ( p_stride * ( i * 2 ) )], pStates1[( 3 * L2 ) - ( i * 2 )] ); + r1 = L_msu0( r1, pFilter1[4 - ( p_stride * ( i * 2 ) )], pStates1[( 4 * L2 ) - ( i * 2 )] ); + + r2 = L_msu0( 0, pFilter6[0 + ( p_stride * ( i * 2 ) )], pStates6[( 0 * L2 ) + ( i * 2 )] ); + r2 = L_msu0( r2, pFilter6[1 + ( p_stride * ( i * 2 ) )], pStates6[( 1 * L2 ) + ( i * 2 )] ); + r2 = L_msu0( r2, pFilter6[2 + ( p_stride * ( i * 2 ) )], pStates6[( 2 * L2 ) + ( i * 2 )] ); + r2 = L_msu0( r2, pFilter6[3 + ( p_stride * ( i * 2 ) )], pStates6[( 3 * L2 ) + ( i * 2 )] ); + r2 = L_msu0( r2, pFilter6[4 + ( p_stride * ( i * 2 ) )], pStates6[( 4 * L2 ) + ( i * 2 )] ); + + i1 = L_msu0( 0, pFilter5[0 - ( p_stride * ( i * 2 ) )], pStates5[( 0 * L2 ) - ( i * 2 )] ); + i1 = L_msu0( i1, pFilter5[1 - ( p_stride * ( i * 2 ) )], pStates5[( 1 * L2 ) - ( i * 2 )] ); + i1 = L_msu0( i1, pFilter5[2 - ( p_stride * ( i * 2 ) )], pStates5[( 2 * L2 ) - ( i * 2 )] ); + i1 = L_msu0( i1, pFilter5[3 - ( p_stride * ( i * 2 ) )], pStates5[( 3 * L2 ) - ( i * 2 )] ); + i1 = L_msu0( i1, pFilter5[4 - ( p_stride * ( i * 2 ) )], pStates5[( 4 * L2 ) - ( i * 2 )] ); + + i2 = L_msu0( 0, pFilter3[0 + ( p_stride * ( i * 2 ) )], pStates3[( 0 * L2 ) + ( i * 2 )] ); + i2 = L_msu0( i2, pFilter3[1 + ( p_stride * ( i * 2 ) )], pStates3[( 1 * L2 ) + ( i * 2 )] ); + i2 = L_msu0( i2, pFilter3[2 + ( p_stride * ( i * 2 ) )], pStates3[( 2 * L2 ) + ( i * 2 )] ); + i2 = L_msu0( i2, pFilter3[3 + ( p_stride * ( i * 2 ) )], pStates3[( 3 * L2 ) + ( i * 2 )] ); + i2 = L_msu0( i2, pFilter3[4 + ( p_stride * ( i * 2 ) )], pStates3[( 4 * L2 ) + ( i * 2 )] ); /* folding */ rBuffer[2 * i] = L_add( r1, r2 ); move32(); - rBuffer[add( shl( i, 1 ), 1 )] = L_sub( i1, i2 ); + rBuffer[( ( i * 2 ) + 1 )] = L_sub( i1, i2 ); move32(); /* folding */ iBuffer[2 * i] = L_sub( r1, r2 ); move32(); - iBuffer[add( shl( i, 1 ), 1 )] = L_add( i1, i2 ); + iBuffer[( ( i * 2 ) + 1 )] = L_add( i1, i2 ); move32(); } @@ -655,10 +657,11 @@ void cldfbSynthesisFiltering( HANDLE_CLDFB_FILTER_BANK cldfbBank, Word32 **rAnalysis, Word32 **iAnalysis, const CLDFB_SCALE_FACTOR *scaleFactor, - Word16 *timeOut, + Word16 *timeOut, // Q(15-timeOut_e) const Word16 timeOut_e, const Word16 nTimeSlots, - Word32 *pWorkBuffer ) + Word32 *pWorkBuffer // Qx +) { Word16 i; Word16 k; @@ -709,7 +712,7 @@ void cldfbSynthesisFiltering( HANDLE_CLDFB_FILTER_BANK cldfbBank, Lz = s_min( cldfbBank->lsb, sub( m, cldfbBank->bandsToZero ) ); Mz = s_min( cldfbBank->usb, sub( m, cldfbBank->bandsToZero ) ); stride = 1; /* constant */ - + move16(); channels0 = sub( m, cldfbBank->zeros ); channels1 = sub( m, 1 ); channels2 = shl( m, 1 ); @@ -726,7 +729,7 @@ void cldfbSynthesisFiltering( HANDLE_CLDFB_FILTER_BANK cldfbBank, iBuffer = &pWorkBuffer[m]; nBuffer = (Word16 *) ( &pWorkBuffer[L2] ); - rAnalysisS = &pWorkBuffer[i_mult( 3, m )]; + rAnalysisS = &pWorkBuffer[3 * m]; iAnalysisS = &pWorkBuffer[4 * m]; rRotVctr = cldfbBank->rRotVctr; @@ -756,7 +759,7 @@ void cldfbSynthesisFiltering( HANDLE_CLDFB_FILTER_BANK cldfbBank, scale = add( outScale, timeOut_e ); IF( NE_16( scale, cldfbBank->FilterStates_eg ) ) { - Scale_sig( cldfbBank->FilterStates, statesSizeM2, sub( cldfbBank->FilterStates_eg, scale ) ); + Scale_sig( cldfbBank->FilterStates, statesSizeM2, sub( cldfbBank->FilterStates_eg, scale ) ); // Q(15-scale) cldfbBank->FilterStates_eg = scale; move16(); } @@ -787,9 +790,9 @@ void cldfbSynthesisFiltering( HANDLE_CLDFB_FILTER_BANK cldfbBank, { FOR( ; i < m; i += 2 ) { - rAnalysisS[i] = L_deposit_l( 0 ); + rAnalysisS[i] = 0; move32(); - iAnalysisS[i] = L_deposit_l( 0 ); + iAnalysisS[i] = 0; move32(); } } @@ -817,9 +820,9 @@ void cldfbSynthesisFiltering( HANDLE_CLDFB_FILTER_BANK cldfbBank, { FOR( ; i < m; i += 2 ) { - rAnalysisS[i] = L_deposit_l( 0 ); + rAnalysisS[i] = 0; move32(); - iAnalysisS[i] = L_deposit_l( 0 ); + iAnalysisS[i] = 0; move32(); } } @@ -845,7 +848,7 @@ void cldfbSynthesisFiltering( HANDLE_CLDFB_FILTER_BANK cldfbBank, calcModulationAndFolding( nBuffer, rBuffer, iBuffer, rRotVctr, iRotVctr, cldfbBank->synGain, scale, m, m2 ); /* prototype filter */ - pStates = &cldfbBank->FilterStates[i_mult( k, L2 )]; + pStates = &cldfbBank->FilterStates[( k * L2 )]; pFilterS = &cldfbBank->p_filter[0]; pFilterM = &cldfbBank->p_filter[shr( cldfbBank->p_filter_length, 1 )]; @@ -878,7 +881,7 @@ void cldfbSynthesisFiltering( HANDLE_CLDFB_FILTER_BANK cldfbBank, BASOP_SATURATE_WARNING_OFF_EVS #ifdef BASOP_NOGLOB - timeOut[i_mult( sub( offset1, i ), stride )] = round_fx_sat( L_shl_sat( acc, outScale ) ); + timeOut[( offset1 - i ) * stride] = round_fx_sat( L_shl_sat( acc, outScale ) ); #else timeOut[( offset1 - i ) * stride] = round_fx( L_shl( acc, outScale ) ); #endif @@ -888,8 +891,8 @@ void cldfbSynthesisFiltering( HANDLE_CLDFB_FILTER_BANK cldfbBank, FOR( ; i < cldfbBank->no_channels; i++ ) { - pStatesI = &pStates[add( i, channels2 )]; - pStatesR = &pStates[add( add( i, channels2 ), channels3 )]; + pStatesI = &pStates[i + channels2]; + pStatesR = &pStates[( i + channels2 ) + channels3]; acc = L_mult( *pStatesI, *pFilterS++ ); acc = L_mac( acc, *pStatesR, *pFilterM++ ); @@ -914,7 +917,7 @@ void cldfbSynthesisFiltering( HANDLE_CLDFB_FILTER_BANK cldfbBank, BASOP_SATURATE_WARNING_OFF_EVS #ifdef BASOP_NOGLOB - timeOut[i_mult( sub( offset2, i ), stride )] = round_fx_sat( L_shl_sat( acc, outScale ) ); + timeOut[( offset2 - i ) * stride] = round_fx_sat( L_shl_sat( acc, outScale ) ); #else timeOut[( offset2 - i ) * stride] = round_fx( L_shl( acc, outScale ) ); #endif @@ -924,17 +927,17 @@ void cldfbSynthesisFiltering( HANDLE_CLDFB_FILTER_BANK cldfbBank, FOR( i = 0; i < cldfbBank->no_channels; i++ ) { - pStates[add( statesSizeM1, i )] = nBuffer[sub( channels1, i )]; + pStates[statesSizeM1 + i] = nBuffer[channels1 - i]; move16(); - pStates[add( statesSizeM2, i )] = nBuffer[sub( add( channels1, m ), i )]; + pStates[statesSizeM2 + i] = nBuffer[( channels1 + m ) - i]; move16(); } - timeOut = &timeOut[i_mult( m, stride )]; + timeOut = &timeOut[m * stride]; } /* move filter states */ - Copy( &cldfbBank->FilterStates[i_mult( nTimeSlots, L2 )], cldfbBank->FilterStates, statesSizeM2 ); + Copy( &cldfbBank->FilterStates[nTimeSlots * L2], cldfbBank->FilterStates, statesSizeM2 ); set16_fx( &cldfbBank->FilterStates[statesSizeM2], 0, L2 ); } @@ -1040,8 +1043,8 @@ ivas_error openCldfb( { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for CLDFB" ); } - hs->flags &= ~CLDFB_FLAG_KEEP_STATES; - + hs->flags = s_and( hs->flags, ~CLDFB_FLAG_KEEP_STATES ); + move16(); configureCldfb( hs, maxCldfbBands, frameSize ); hs->memory = NULL; @@ -1140,10 +1143,10 @@ void resampleCldfb( HANDLE_CLDFB_FILTER_BANK hs, */ Word16 AnalysisPostSpectrumScaling_Fx( HANDLE_CLDFB_FILTER_BANK cldfbBank, /*!< Handle of cldfbBank */ - Word32 **rSubband32, /*!< Real bands */ - Word32 **iSubband32, /*!< Imaginary bands */ - Word16 **rSubband16, /*!< Real bands */ - Word16 **iSubband16, /*!< Imaginary bands */ + Word32 **rSubband32, /*!< Real bands Q(cldfbSacle)*/ + Word32 **iSubband32, /*!< Imaginary bands Q(cldfbSacle)*/ + Word16 **rSubband16, /*!< Real bands Q(cldfbSacle)*/ + Word16 **iSubband16, /*!< Imaginary bands Q(cldfbScale)*/ Word16 *cldfbScale /*!< CLDFB lowband scalefactor */ ) { @@ -1165,14 +1168,14 @@ AnalysisPostSpectrumScaling_Fx( HANDLE_CLDFB_FILTER_BANK cldfbBank, /*!< Handle FOR( j = 0; j < cldfbBank->no_channels; j++ ) { #ifdef BASOP_NOGLOB - rSubband16[i][j] = round_fx_sat( L_shl_sat( rSubband32[i][j], headRoom ) ); - iSubband16[i][j] = round_fx_sat( L_shl_sat( iSubband32[i][j], headRoom ) ); + rSubband16[i][j] = round_fx_sat( L_shl_sat( rSubband32[i][j], headRoom ) ); // Q(cldfbSacle_headRoom) + iSubband16[i][j] = round_fx_sat( L_shl_sat( iSubband32[i][j], headRoom ) ); // Q(cldfbSacle+headRoom) #else rSubband16[i][j] = round_fx( L_shl( rSubband32[i][j], headRoom ) ); iSubband16[i][j] = round_fx( L_shl( iSubband32[i][j], headRoom ) ); #endif - move32(); - move32(); + move16(); + move16(); } } @@ -1192,12 +1195,12 @@ AnalysisPostSpectrumScaling_Fx( HANDLE_CLDFB_FILTER_BANK cldfbBank, /*!< Handle void analysisCldfbEncoder_fx( Encoder_State *st_fx, /* i/o: encoder state structure */ - const Word16 *timeIn, + const Word16 *timeIn, // Q15 Word32 realBuffer[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], Word32 imagBuffer[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], - Word16 realBuffer16[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], - Word16 imagBuffer16[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], - Word32 enerBuffSum[CLDFB_NO_CHANNELS_MAX], + Word16 realBuffer16[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], // Q(enerScale.lb_scale16) + Word16 imagBuffer16[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], // Q(enerScale.lb_scale16) + Word32 enerBuffSum[CLDFB_NO_CHANNELS_MAX], // Q(31-enerBuffSum_exp) Word16 *enerBuffSum_exp, CLDFB_SCALE_FACTOR *scale ) { @@ -1232,7 +1235,8 @@ void analysisCldfbEncoder_fx( enerScale.lb_scale = negate( scale->lb_scale ); enerScale.lb_scale16 = negate( scale->lb_scale ); - + move16(); + move16(); /* get 16bit respresentation */ AnalysisPostSpectrumScaling_Fx( st_fx->cldfbAnaEnc, @@ -1294,8 +1298,8 @@ void GetEnergyCldfb( Word32 *energyLookahead, /*!< o: Q(*sf_energyLookahead) { FOR( j = 0; j < numberBands; j++ ) { - nrg = L_mult0( realValues[k][j], realValues[k][j] ); - nrg = L_mac0( nrg, imagValues[k][j], imagValues[k][j] ); + nrg = L_mult0( realValues[k][j], realValues[k][j] ); // Q(2*sf_Values) + nrg = L_mac0( nrg, imagValues[k][j], imagValues[k][j] ); // Q(2*sf_Values) energyValues[k][j] = nrg; move32(); @@ -1325,13 +1329,13 @@ void GetEnergyCldfb( Word32 *energyLookahead, /*!< o: Q(*sf_energyLookahead) FOR( j = 0; j < numberBands; j++ ) { - energyValuesSum[j] = L_deposit_l( 0 ); + energyValuesSum[j] = 0; move32(); energyValuesSumE[j] = 31; move16(); FOR( k = 0; k < CLDFB_NO_COL_MAX; k++ ) { - nrg = L_shr_r( energyValues[k][j], sub( energyValuesSumE[j], 31 ) ); + nrg = L_shr_r( energyValues[k][j], sub( energyValuesSumE[j], 31 ) ); // Q(2*sf_Values - (energyValuesSumE[j]-31)) IF( LT_32( L_sub( maxWord32, nrg ), energyValuesSum[j] ) ) { energyValuesSumE[j] = add( energyValuesSumE[j], 1 ); @@ -1352,7 +1356,7 @@ void GetEnergyCldfb( Word32 *energyLookahead, /*!< o: Q(*sf_energyLookahead) } FOR( j = 0; j < numberBands; j++ ) { - energyValuesSum[j] = L_shr_r( energyValuesSum[j], sub( *energyValuesSum_Exp, energyValuesSumE[j] ) ); + energyValuesSum[j] = L_shr_r( energyValuesSum[j], sub( *energyValuesSum_Exp, energyValuesSumE[j] ) ); // Q(energyValuesSum_Exp - (2*sf_Values)) move32(); } *energyValuesSum_Exp = sub( *energyValuesSum_Exp, shl( sf_Values, 1 ) ); @@ -1368,8 +1372,8 @@ void GetEnergyCldfb( Word32 *energyLookahead, /*!< o: Q(*sf_energyLookahead) /* sum up CLDFB energy above 8 kHz */ s = BASOP_util_norm_s_bands2shift( i_mult( numberColsL, numberBandsM20 ) ); s = sub( s, 4 ); - nrg = L_deposit_l( 0 ); - + nrg = 0; + move32(); FOR( k = 0; k < numberColsL; k++ ) { FOR( j = 20; j < numberBandsM; j++ ) @@ -1386,7 +1390,7 @@ void GetEnergyCldfb( Word32 *energyLookahead, /*!< o: Q(*sf_energyLookahead) sm = sub( s_min( s, *sf_energyLookahead ), 1 ); *energyHF = L_add( L_shr( nrg, limitScale32( sub( s, sm ) ) ), - L_shr( *energyLookahead, sub( *sf_energyLookahead, sm ) ) ); + L_shr( *energyLookahead, sub( *sf_energyLookahead, sm ) ) ); // Q(31-(-nm)) move32(); *energyHF_Exp = negate( sm ); @@ -1395,8 +1399,8 @@ void GetEnergyCldfb( Word32 *energyLookahead, /*!< o: Q(*sf_energyLookahead) /* process look-ahead region */ s = BASOP_util_norm_s_bands2shift( i_mult( numLookahead, numberBandsM20 ) ); s = sub( s, 2 ); - nrg = L_deposit_l( 0 ); - + nrg = 0; + move32(); FOR( k = numberColsL; k < numberCols; k++ ) { FOR( j = 20; j < numberBandsM; j++ ) @@ -1642,13 +1646,14 @@ cldfb_init_proto_and_twiddles( HANDLE_CLDFB_FILTER_BANK hs ) /* i: cldfb handle ivas_error cldfb_save_memory( HANDLE_CLDFB_FILTER_BANK hs ) /* i: cldfb handle */ { - + test(); IF( hs->memory != NULL || hs->memory_length != 0 ) { /* memory already stored; Free memory first */ return IVAS_ERR_OK; } hs->memory_length = cldfb_get_memory_length( hs ); + move16(); hs->memory = (Word16 *) calloc( hs->memory_length + CLDFB_MEM_EXPONENTS + 1, sizeof( Word16 ) ); /* save the memory */ diff --git a/lib_com/fft_cldfb_fx.c b/lib_com/fft_cldfb_fx.c index ba5ca4e1e..b4dbcc095 100644 --- a/lib_com/fft_cldfb_fx.c +++ b/lib_com/fft_cldfb_fx.c @@ -124,7 +124,7 @@ cmplx CL_dscale_t( cmplx x, Word16 y1, Word16 y2 ); * * \return void */ -static void fft8_with_cmplx_data( cmplx *inp ) +static void fft8_with_cmplx_data( cmplx *inp /*Qx*/ ) { cmplx x0, x1, x2, x3, x4, x5, x6, x7; cmplx s0, s1, s2, s3, s4, s5, s6, s7; @@ -204,7 +204,7 @@ static void fft8_with_cmplx_data( cmplx *inp ) * * \return void */ -static void fft5_with_cmplx_data( cmplx *inp ) +static void fft5_with_cmplx_data( cmplx *inp /*Qx*/ ) { cmplx x0, x1, x2, x3, x4; cmplx y1, y2, y3, y4; @@ -262,7 +262,7 @@ static void fft5_with_cmplx_data( cmplx *inp ) * * \return void */ -static void fft10_with_cmplx_data( cmplx *inp_data ) +static void fft10_with_cmplx_data( cmplx *inp_data /*Qx*/ ) { cmplx r1, r2, r3, r4; cmplx x0, x1, x2, x3, x4, t; @@ -369,7 +369,7 @@ static void fft10_with_cmplx_data( cmplx *inp_data ) * * \return void */ -static void fft20_with_cmplx_data( cmplx *inp_data ) +static void fft20_with_cmplx_data( cmplx *inp_data /*Qx*/ ) { cmplx r1, r2, r3, r4; cmplx x0, x1, x2, x3, x4; @@ -617,7 +617,7 @@ static void fft20_with_cmplx_data( cmplx *inp_data ) * * \return void */ -static void fft30_with_cmplx_data( cmplx *inp ) +static void fft30_with_cmplx_data( cmplx *inp /*Qx*/ ) { cmplx *l = &inp[0]; cmplx *h = &inp[15]; @@ -1023,7 +1023,7 @@ static void fft30_with_cmplx_data( cmplx *inp ) * Interface functions FFT subroutines *--------------------------------------------------------------------*/ void fft_cldfb_fx( - Word32 *data, /* i/o: input/output vector */ + Word32 *data, /* i/o: input/output vector Qx*/ const Word16 size /* size of fft operation */ ) { diff --git a/lib_com/fft_rel.c b/lib_com/fft_rel.c index bad84753f..88f80e798 100644 --- a/lib_com/fft_rel.c +++ b/lib_com/fft_rel.c @@ -303,7 +303,7 @@ void fft_rel( void fft_rel_fx( - Word16 x[], /* i/o: input/output vector */ + Word16 x[], /* i/o: input/output vector Qx */ const Word16 n, /* i : vector length */ const Word16 m /* i : log2 of vector length */ ) @@ -326,22 +326,22 @@ void fft_rel_fx( j = 0; move16(); - x0 = &x[0]; + x0 = &x[0]; // Qx move16(); FOR( i = 0; i < n - 1; i++ ) { IF( LT_16( i, j ) ) { - xt = x[j]; + xt = x[j]; // Qx move16(); - x[j] = *x0; + x[j] = *x0; // Qx move16(); - *x0 = xt; + *x0 = xt; // Qx move16(); } x0++; k = shr( n, 1 ); - WHILE( LE_16( k, j ) ) + WHILE( ( k <= j ) ) { j = sub( j, k ); k = shr( k, 1 ); @@ -357,7 +357,7 @@ void fft_rel_fx( move16(); x1 = &x[1]; move16(); - FOR( i = 0; i < shr( n, 1 ); i++ ) + FOR( i = 0; i < ( n >> 1 ); i++ ) { xt = *x0; move16(); @@ -425,8 +425,8 @@ void fft_rel_fx( move16(); /* x[i+n2+n4] = -x[i+n2+n4]; */ - s = sincos_t_fx + step; - c = s + 64; + s = sincos_t_fx + step; // Q15 + c = s + 64; // Q15 xi1 = x + add( i, 1 ); xi3 = xi1 + n2; xi2 = xi3 - 2; @@ -435,8 +435,8 @@ void fft_rel_fx( FOR( j = 1; j < n4; j++ ) { #ifdef BASOP_NOGLOB - t1 = add_o( mult_r( *xi3, *c ), mult_r( *xi4, *s ), &Overflow ); /* t1 = *xi3**(pt_c+ind) + *xi4**(pt_s+ind); */ - t2 = sub_o( mult_r( *xi3, *s ), mult_r( *xi4, *c ), &Overflow ); /* t2 = *xi3**(pt_s+ind) - *xi4**(pt_c+ind); */ + t1 = add_o( mult_r( *xi3, *c ), mult_r( *xi4, *s ), &Overflow ); /* t1 = *xi3**(pt_c+ind) + *xi4**(pt_s+ind); Qx */ + t2 = sub_o( mult_r( *xi3, *s ), mult_r( *xi4, *c ), &Overflow ); /* t2 = *xi3**(pt_s+ind) - *xi4**(pt_c+ind); Qx */ *xi4 = sub_o( *xi2, t2, &Overflow ); #else /* BASOP_NOGLOB */ t1 = add( mult_r( *xi3, *c ), mult_r( *xi4, *s ) ); /* t1 = *xi3**(pt_c+ind) + *xi4**(pt_s+ind); */ @@ -482,7 +482,7 @@ void fft_rel_fx( } void fft_rel_fx32( - Word32 x[], /* i/o: input/output vector */ + Word32 x[], /* i/o: input/output vector Qx */ const Word16 n, /* i : vector length */ const Word16 m /* i : log2 of vector length */ ) @@ -517,9 +517,9 @@ void fft_rel_fx32( k = *idx++; move16(); - *x2++ = L_add( x[shr( j, 1 )], x[shr( k, 1 )] ); + *x2++ = L_add( x[( j >> 1 )], x[( k >> 1 )] ); // Qx move16(); - *x2++ = L_sub( x[shr( j, 1 )], x[shr( k, 1 )] ); + *x2++ = L_sub( x[( j >> 1 )], x[( k >> 1 )] ); // Qx move16(); } } @@ -533,9 +533,9 @@ void fft_rel_fx32( k = *idx++; move16(); - *x2++ = L_add( x[j], x[k] ); + *x2++ = L_add( x[j], x[k] ); // Qx move16(); - *x2++ = L_sub( x[j], x[k] ); + *x2++ = L_sub( x[j], x[k] ); // Qx move16(); } } @@ -551,15 +551,15 @@ void fft_rel_fx32( k = shl( *idx, 1 ); idx++; - *x2even++ = L_add( x[j], x[k] ); + *x2even++ = L_add( x[j], x[k] ); // Qx move16(); - *x2even++ = L_sub( x[j], x[k] ); + *x2even++ = L_sub( x[j], x[k] ); // Qx move16(); j = add( j, 1 ); k = add( k, 1 ); - *x2odd++ = L_add( x[j], x[k] ); + *x2odd++ = L_add( x[j], x[k] ); // Qx move16(); - *x2odd++ = L_sub( x[j], x[k] ); + *x2odd++ = L_sub( x[j], x[k] ); // Qx move16(); } } @@ -576,7 +576,7 @@ void fft_rel_fx32( { x0 = temp; x1 = x0 + 2; - x2 = x; + x2 = x; // Qx FOR( i = 0; i < n; i += 4 ) { @@ -604,12 +604,12 @@ void fft_rel_fx32( j = 0; move16(); - x0 = &x[0]; - FOR( i = 0; i < sub( n, 1 ); i++ ) + x0 = &x[0]; // Qx + FOR( i = 0; i < ( n - 1 ); i++ ) { IF( LT_16( i, j ) ) { - xt = x[j]; + xt = x[j]; // Qx move32(); x[j] = *x0; move32(); @@ -618,7 +618,7 @@ void fft_rel_fx32( } x0++; k = shr( n, 1 ); - WHILE( LE_16( k, j ) ) + WHILE( ( k <= j ) ) { j = sub( j, k ); k = shr( k, 1 ); @@ -630,13 +630,13 @@ void fft_rel_fx32( * Length two butterflies *-----------------------------------------------------------------*/ - x0 = &x[0]; - x1 = &x[1]; - FOR( i = 0; i < shr( n, 1 ); i++ ) + x0 = &x[0]; // Qx + x1 = &x[1]; // Qx + FOR( i = 0; i < ( n >> 1 ); i++ ) { - *x1 = L_sub( *x0, *x1 ); + *x1 = L_sub( *x0, *x1 ); // Qx move32(); - *x0 = L_sub( L_shl( *x0, 1 ), *x1 ); + *x0 = L_sub( L_shl( *x0, 1 ), *x1 ); //*x0 * 2 - *x1 (Qx) move32(); x0++; @@ -653,16 +653,16 @@ void fft_rel_fx32( /* for_ (k = 2; k < 3; k++) */ { - x0 = x; + x0 = x; // Qx x1 = x0 + 2; FOR( i = 0; i < n; i += 4 ) { - *x1 = L_sub( *x0, *x1 ); /* x[i+n2] = xt - x[i+n2]; */ + *x1 = L_sub( *x0, *x1 ); /* x[i+n2] = xt - x[i+n2]; Qx*/ move32(); - *x0 = L_sub( L_shl( *x0, 1 ), *x1++ ); /* x[i] = xt + x[i+n2]; */ + *x0 = L_sub( L_shl( *x0, 1 ), *x1++ ); /* x[i] = xt + x[i+n2]; */ /**x0 * 2 - *x1 (Qx)*/ move32(); - *x1 = L_negate( *x1 ); /* x[i+n2+n4] = -x[i+n2+n4]; */ + *x1 = L_negate( *x1 ); /* x[i+n2+n4] = -x[i+n2+n4]; Qx*/ move32(); x0 += 4; @@ -707,13 +707,13 @@ void fft_rel_fx32( { *x1 = L_sub( *x0, *x1 ); /* x[i+n2] = xt - x[i+n2]; */ move32(); - *x0 = L_sub( L_shl( *x0, 1 ), *x1 ); /* x[i] = xt + x[i+n2]; */ + *x0 = L_sub( L_shl( *x0, 1 ), *x1 ); /* x[i] = xt + x[i+n2]; */ /**x0 * 2 - *x1 (Qx)*/ move32(); - *x2 = L_negate( *x2 ); /* x[i+n2+n4] = -x[i+n2+n4]; */ + *x2 = L_negate( *x2 ); /* x[i+n2+n4] = -x[i+n2+n4]; Qx */ move32(); - s = sincos_t_ext_fx; - c = s + N_MAX_FFT / 4; /* 1024/4 = 256, 256/4=64 */ + s = sincos_t_ext_fx; // Q15 + c = s + N_MAX_FFT / 4; /* 1024/4 = 256, 256/4=64 Q15*/ xi1 = x0; xi3 = xi1 + n2; xi2 = xi3; @@ -729,16 +729,16 @@ void fft_rel_fx32( c += step; s += step; /* autoincrement by ar0 */ - t1 = L_add( Mpy_32_16_1( *xi3, *c ), Mpy_32_16_1( *xi4, *s ) ); /* t1 = *xi3**(pt_c+ind) + *xi4**(pt_s+ind); */ - t2 = L_sub( Mpy_32_16_1( *xi3, *s ), Mpy_32_16_1( *xi4, *c ) ); /* t2 = *xi3**(pt_s+ind) - *xi4**(pt_c+ind); */ + t1 = L_add( Mpy_32_16_1( *xi3, *c ), Mpy_32_16_1( *xi4, *s ) ); /* t1 = *xi3**(pt_c+ind) + *xi4**(pt_s+ind); Qx*/ + t2 = L_sub( Mpy_32_16_1( *xi3, *s ), Mpy_32_16_1( *xi4, *c ) ); /* t2 = *xi3**(pt_s+ind) - *xi4**(pt_c+ind); Qx*/ *xi4 = L_sub( *xi2, t2 ); move32(); *xi2 = L_sub( *xi1, t1 ); move32(); - *xi1 = L_sub( L_shl( *xi1, 1 ), *xi2 ); + *xi1 = L_sub( L_shl( *xi1, 1 ), *xi2 ); // Qx move32(); - *xi3 = L_negate( L_add( L_shl( t2, 1 ), *xi4 ) ); + *xi3 = L_negate( L_add( L_shl( t2, 1 ), *xi4 ) ); // Qx move32(); } diff --git a/lib_com/fft_rel_fx.c b/lib_com/fft_rel_fx.c index 85a5a3224..1285049bc 100644 --- a/lib_com/fft_rel_fx.c +++ b/lib_com/fft_rel_fx.c @@ -72,8 +72,8 @@ static void c_fft_fx( const Word16 *phs_tbl, /* i : Table of phases */ Word16 SIZE, /* i : Size of the FFT */ Word16 NUM_STAGE, /* i : Number of stages */ - const Word16 *in_ptr, /* i : coefficients in the order re[0], re[n/2], re[1], im[1], ..., re[n/2-1], im[n/2-1] */ - Word16 *out_ptr, /* o : coefficients in the order re[0], re[n/2], re[1], im[1], ..., re[n/2-1], im[n/2-1] */ + const Word16 *in_ptr, /* i : coefficients in the order re[0], re[n/2], re[1], im[1], ..., re[n/2-1], im[n/2-1] Qx*/ + Word16 *out_ptr, /* o : coefficients in the order re[0], re[n/2], re[1], im[1], ..., re[n/2-1], im[n/2-1] Q(x - 1)*/ /* in_ptr & out_ptr must not overlap! */ const Word16 isign ) /* i : 1=fft, otherwise it is ifft*/ { @@ -129,7 +129,7 @@ static void c_fft_fx( * is counted as a move16() */ - input_ptr1 = in_ptr + ( const Word16 )( (uintptr_t) ( *table_ptr++ ) >> (uintptr_t) shift ); + input_ptr1 = in_ptr + ( const Word16 )( (uintptr_t) ( *table_ptr++ ) >> (uintptr_t) shift ); // Qx L_tmp1 = L_mult( *input_ptr1++, 16384 ); L_tmp2 = L_mult( *input_ptr1, 16384 ); @@ -379,8 +379,8 @@ void r_fft_fx_lc( const Word16 SIZE, /* i : Size of the FFT */ const Word16 SIZE2, /* i : Size / 2 */ const Word16 NUM_STAGE, /* i : Number of stage */ - const Word16 *in_ptr, /* i : coefficients in the order re[0], re[1], ... re[n/2], im[n/2-1], im[n/2-2], ..., im[1] */ - Word16 *out_ptr, /* o : coefficients in the order re[0], re[1], ... re[n/2], im[n/2-1], im[n/2-2], ..., im[1] */ + const Word16 *in_ptr, /* i : coefficients in the order re[0], re[1], ... re[n/2], im[n/2-1], im[n/2-2], ..., im[1] Qx*/ + Word16 *out_ptr, /* o : coefficients in the order re[0], re[1], ... re[n/2], im[n/2-1], im[n/2-2], ..., im[1] Q(x - 1)*/ const Word16 isign /* i : 1=fft, otherwize it's ifft */ ) { @@ -478,10 +478,10 @@ void r_fft_fx_lc( /* This is ok because we use these pointers for */ /* reading only. This is just to avoid declaring a */ /* bunch of 4 other pointer with const Word16 *. */ - ptImaDn = &in_ptr[SIZE - 1]; - ptRealUp = &in_ptr[1]; - ptImaUp = &in_ptr[SIZE2 + 1]; - ptRealDn = &in_ptr[SIZE2 - 1]; + ptImaDn = &in_ptr[SIZE - 1]; // Qx + ptRealUp = &in_ptr[1]; // Qx + ptImaUp = &in_ptr[SIZE2 + 1]; // Qx + ptRealDn = &in_ptr[SIZE2 - 1]; // Qx /* Now, handle the remaining positive frequencies */ FOR( i = 2; i <= SIZE2; i += 2 ) diff --git a/lib_com/fill_spectrum.c b/lib_com/fill_spectrum.c index 5fe270c3c..d9f24d8d5 100644 --- a/lib_com/fill_spectrum.c +++ b/lib_com/fill_spectrum.c @@ -394,7 +394,7 @@ void ivas_fill_spectrum_fx( test(); test(); test(); - if ( EQ_16( length, L_FRAME32k ) && ( ( LT_16( env_stab, 16384 ) && *no_att_hangover == 0 ) || EQ_16( HQ_mode, HQ_HVQ ) ) ) + if ( EQ_16( length, L_FRAME32k ) && ( ( LT_16( env_stab, 16384 /*0.5.Q15*/ ) && *no_att_hangover == 0 ) || EQ_16( HQ_mode, HQ_HVQ ) ) ) { flag_32K_env_hangover = 1; move16(); @@ -437,7 +437,7 @@ void ivas_fill_spectrum_fx( * Normal mode BWE *----------------------------------------------------------------*/ - IF( EQ_16( HQ_mode, HQ_NORMAL ) ) + IF( HQ_mode == HQ_NORMAL ) { hq_fold_bwe_fx( last_sfm, sfm_end, num_sfm, coeff ); } @@ -625,7 +625,7 @@ void fill_spectrum_fx( move16(); } } - ELSE if ( EQ_16( HQ_mode, HQ_HVQ ) ) + ELSE IF( EQ_16( HQ_mode, HQ_HVQ ) ) { bin_th = sfm_end[last_sfm]; move16(); @@ -654,7 +654,7 @@ void fill_spectrum_fx( test(); test(); test(); - if ( EQ_16( length, L_FRAME32k ) && ( ( LT_16( env_stab, 16384 ) && *no_att_hangover == 0 ) || EQ_16( HQ_mode, HQ_HVQ ) ) ) + if ( EQ_16( length, L_FRAME32k ) && ( ( LT_16( env_stab, 16384 /*0.5.Q15*/ ) && *no_att_hangover == 0 ) || EQ_16( HQ_mode, HQ_HVQ ) ) ) { flag_32K_env_hangover = 1; move16(); @@ -697,7 +697,7 @@ void fill_spectrum_fx( * Normal mode BWE *----------------------------------------------------------------*/ - IF( EQ_16( HQ_mode, HQ_NORMAL ) ) + IF( HQ_mode == HQ_NORMAL ) { hq_fold_bwe_fx( last_sfm, sfm_end, num_sfm, coeff ); } diff --git a/lib_com/findpulse.c b/lib_com/findpulse.c index 72f1b3990..3596b20b8 100644 --- a/lib_com/findpulse.c +++ b/lib_com/findpulse.c @@ -48,6 +48,7 @@ * Find first pitch pulse in a frame *----------------------------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED /*! r: pulse position */ int16_t findpulse( const int16_t L_frame, /* i : length of the frame */ @@ -139,11 +140,12 @@ int16_t findpulse( return ( maxi ); } +#endif #ifdef IVAS_FLOAT_FIXED -Word16 findpulse_fx( /* o : pulse position */ +Word16 findpulse_fx( /* o : pulse position Q0 */ const Word16 L_frame, /* i : length of the frame */ - const Word16 res[], /* i : Residual signal <12 bits */ + const Word16 res[], /* i : Residual signal <12 bits Qx */ const Word16 T0, /* i : Pitch estimation Q0 */ const Word16 enc, /* i : enc = 1 -> encoder side; enc = 0 -> decoder side */ Word16 *sign /* i/o: sign of the maximum */ @@ -162,21 +164,21 @@ Word16 findpulse_fx( /* o : pulse position *------------------------------------------------------------------------*/ /* resf[0] = 0.50f * res[0] + 0.25f * res[1] */ - Ltmp = L_mult( res[0], 16384 ); - resf[0] = mac_r( Ltmp, res[1], 8192 ); + Ltmp = L_mult( res[0], 16384 /*0.5 (Q15)*/ ); /*Q(x + 15 + 1) => Q(x + 16)*/ + resf[0] = mac_r( Ltmp, res[1], 8192 /*0.25( Q15 )*/ ); /*Q(x + 16)*/ move16(); FOR( i = 1; i < L_frame - 1; i++ ) { /* resf[i] = 0.25f * res[i-1] + 0.5f * res[i] + 0.25f * res[i+1] */ - Ltmp = L_mult( 8192, res[i - 1] ); - Ltmp = L_mac( Ltmp, 16384, res[i] ); - resf[i] = mac_r( Ltmp, 8192, res[i + 1] ); + Ltmp = L_mult( 8192 /*0.25 (Q15)*/, res[i - 1] ); /*Q(x + 16)*/ + Ltmp = L_mac( Ltmp, 16384 /*0.5 (Q15)*/, res[i] ); /*Q(x + 16)*/ + resf[i] = mac_r( Ltmp, 8192 /*0.25 (Q15)*/, res[i + 1] ); /*Q(x*/ move16(); } /* resf[L_frame-1] = 0.25f * res[L_frame-2] + 0.50f * res[L_frame-1] */ - Ltmp = L_mult( res[L_frame - 2], 8192 ); - resf[L_frame - 1] = mac_r( Ltmp, 16384, res[L_frame - 1] ); + Ltmp = L_mult( res[L_frame - 2], 8192 /*0.25 (Q15)*/ ); /*Q(x + 16)*/ + resf[L_frame - 1] = mac_r( Ltmp, 16384 /*0.5 (Q15)*/, res[L_frame - 1] ); /*Q(x)*/ move16(); /*------------------------------------------------------------------------* @@ -189,14 +191,14 @@ Word16 findpulse_fx( /* o : pulse position FOR( i = 1; i < T0; i++ ) { - Ltmp = L_mult0( ptr[-maxi], ptr[-maxi] ); + Ltmp = L_mult0( ptr[-maxi], ptr[-maxi] ); /*Q( 2 * x )*/ if ( L_msu0( Ltmp, ptr[-i], ptr[-i] ) < 0 ) { maxi = i; move16(); } } - *sign = negate( shr( ptr[-maxi], 15 ) ); + *sign = negate( shr( ptr[-maxi], 15 ) ); /*extracting sign : Q0*/ move16(); } ELSE diff --git a/lib_com/frame_ener.c b/lib_com/frame_ener.c index ece0418c6..cd2eb4418 100644 --- a/lib_com/frame_ener.c +++ b/lib_com/frame_ener.c @@ -87,13 +87,13 @@ void fer_energy( #ifdef IVAS_FLOAT_FIXED void fer_energy_fx( - const Word16 L_frame, /* i : frame length */ - const Word16 clas, /* i : frame classification */ - const Word32 *synth, /* i : synthesized speech at Fs = 12k8 Hz */ - const Word16 q_synth, /* i : synthesized speech at Fs = 12k8 Hz */ - const Word16 pitch, /* i : pitch period */ - Word32 *enr, /* o : pitch-synchronous or half_frame energy */ - const Word16 offset /* i : speech pointer offset (0 or L_frame) */ + const Word16 L_frame, /* i : frame length */ + const Word16 clas, /* i : frame classification */ + const Word32 *synth, /* i : synthesized speech at Fs = 12k8 Hz Q(q_synth) */ + const Word16 q_synth, /* i : synthesized speech at Fs = 12k8 Hz */ + const Word16 pitch, /* i : pitch period Q0 */ + Word32 *enr, /* o : pitch-synchronous or half_frame energy Q0 */ + const Word16 offset /* i : speech pointer offset (0 or L_frame) */ ) { Word16 len, shift, exp; @@ -136,7 +136,7 @@ void fer_energy_fx( move32(); enr_tmp = BASOP_Util_Divide3216_Scale( *enr, shr( L_frame, 1 ) /*Q0*/, &exp ); - *enr = L_shr( L_deposit_l( enr_tmp ), sub( sub( sub( shift, 32 ), exp ), 1 ) ); + *enr = L_shr( L_deposit_l( enr_tmp ), sub( sub( sub( shift, 32 ), exp ), 1 ) ); /*Q0*/ move32(); } return; @@ -222,13 +222,11 @@ Word16 frame_ener_fx( len = pitch; move16(); /* pitch value at the end of frame */ pt_synth = synth; - move16(); if ( offset != 0 ) { pt_synth = synth + sub( L_frame, len ); } emaximum_fx( Q_new, pt_synth, len, enr_q ); - move16(); /* pitch synchronous E */ IF( enc != 0 ) { exp_enrq = norm_l( *enr_q ); @@ -251,15 +249,15 @@ Word16 frame_ener_fx( pos = sub( L_frame, L_frame2 ); } #ifdef BASOP_NOGLOB - Ltmp = L_mult_sat( synth[pos], synth[pos] ); + Ltmp = L_mult_sat( synth[pos], synth[pos] ); /*2 * Qnew + 1*/ #else Ltmp = L_mult( synth[pos], synth[pos] ); #endif FOR( i = 1; i < L_frame2; i++ ) { #ifdef BASOP_NOGLOB - Ltmp = L_mac_sat( Ltmp, synth[pos + i], synth[pos + i] ); -#else /* BASOP_NOGLOB */ + Ltmp = L_mac_sat( Ltmp, synth[pos + i], synth[pos + i] ); /*2 * Qnew + 1*/ +#else /* BASOP_NOGLOB */ Ltmp = L_mac( Ltmp, synth[pos + i], synth[pos + i] ); #endif } diff --git a/lib_com/get_gain.c b/lib_com/get_gain.c index 33739f0cd..8cfa02160 100644 --- a/lib_com/get_gain.c +++ b/lib_com/get_gain.c @@ -73,9 +73,9 @@ float get_gain_flt( #ifdef IVAS_FLOAT_FIXED Word32 get_gain( /* output: codebook gain (adaptive or fixed) Q16 */ - const Word16 x[], /* input : target signal */ - const Word16 y[], /* input : filtered codebook excitation */ - const Word16 n /* input : segment length */ + const Word16 x[], /* input : target signal Qx */ + const Word16 y[], /* input : filtered codebook excitation Qx */ + const Word16 n /* input : segment length */ ) { Word32 tcorr, tener, Lgain; @@ -155,7 +155,7 @@ Word32 get_gain2( /* output: codebook gain (adaptive or fixed) move16(); m_corr = 0x7FFF; } - if ( m_ener != 0 ) + IF( m_ener != 0 ) { m_corr = div_s( m_corr, m_ener ); } diff --git a/lib_com/gs_bitallocation_ivas_fx.c b/lib_com/gs_bitallocation_ivas_fx.c index f8a45b4f8..077463885 100644 --- a/lib_com/gs_bitallocation_ivas_fx.c +++ b/lib_com/gs_bitallocation_ivas_fx.c @@ -69,7 +69,7 @@ static Word32 Find_bit_frac( const Word16 nb_band, const Word16 remaining_bits ) /*----------------------------------------------------------------------------------*/ /* INPUT/OUTPUT ARGUMENTS : */ /* _ (Word16*) bit :Number of bit allowed for frequency quantization */ -/* _ (Word16*) Ener_per_bd_iQ : Quantized energy vector Q13 */ +/* _ (Word16*) Ener_per_bd_iQ : Quantized energy vector Q12 */ /* _ (Word32*) bits_per_bands : Number of bit allowed per allowed subband Q18 */ /*----------------------------------------------------------------------------------*/ /* RETURN ARGUMENTS : */ @@ -82,7 +82,7 @@ void bands_and_bit_alloc_ivas_fx( const Word16 Diff_len, /* i : Lenght of the difference signal (before pure spectral)*/ const Word16 bits_used, /* i : Number of bit used before frequency Q */ Word16 *bit, /* i/o: Number of bit allowed for frequency quantization */ - const Word16 *Ener_per_bd_iQ, /* i/o: Quantized energy vector */ + const Word16 *Ener_per_bd_iQ, /* i/o: Quantized energy vector Q12 */ Word16 *max_ener_band, /* o : Sorted order */ Word16 *out_bits_per_bands, /* i/o: Number of bit allowed per allowed subband Q3 */ Word16 *nb_subbands, /* o : Number of subband allowed */ @@ -103,7 +103,7 @@ void bands_and_bit_alloc_ivas_fx( Word16 nb_tot_bands = 16; Word16 bit_index, bit_index_mem, imax; Word32 L_tmp; - Word32 sum_bit /*Q18*/, bit_fracf /*Q18*/; + Word32 sum_bit /*Q0*/, bit_fracf /*Q18*/; Word16 etmp; Word16 tmp; Word16 Ener_per_bd_iQ_tmp[MBANDS_GN_BITALLOC16k]; // Q13 @@ -143,10 +143,10 @@ void bands_and_bit_alloc_ivas_fx( move16(); IF( EQ_16( L_frame, L_FRAME16k ) ) { - ener_vec[16] = Ener_per_bd_iQ[16]; - ener_vec[17] = mac_r( L_mult( Ener_per_bd_iQ[16], 16384 ), Ener_per_bd_iQ[17], 16384 ); - ener_vec[18] = Ener_per_bd_iQ[17]; - ener_vec[19] = mult_r( Ener_per_bd_iQ[17], 26214 ); + ener_vec[16] = Ener_per_bd_iQ[16]; /*Q12*/ + ener_vec[17] = mac_r( L_mult( Ener_per_bd_iQ[16], 16384 /*0.5 in Q15*/ ), Ener_per_bd_iQ[17], 16384 /*0.5 in Q15*/ ); /*Q12*/ + ener_vec[18] = Ener_per_bd_iQ[17]; /*Q12*/ + ener_vec[19] = mult_r( Ener_per_bd_iQ[17], 26214 /*0.8 in Q15*/ ); /*Q12*/ move16(); move16(); move16(); @@ -210,16 +210,16 @@ void bands_and_bit_alloc_ivas_fx( IF( GE_32( core_brate, ACELP_9k60 ) ) { /* *bit = (short)(core_brate*(1.0f/50) + 0.5f) - bits_used - 25; */ - L_tmp = Mult_32_16( core_brate, 20971 ); + L_tmp = Mult_32_16( core_brate, 20971 /*1/50 in Q20*/ ); tmp = extract_l( L_shr_r( L_tmp, 5 ) ); - *bit = sub( sub( tmp, bits_used ), 25 ); + *bit = sub( sub( tmp, bits_used ), 25 ); /*Q0*/ move16(); } ELSE { - L_tmp = Mult_32_16( core_brate, 20971 ); + L_tmp = Mult_32_16( core_brate, 20971 /*1/50 in Q20*/ ); tmp = extract_l( L_shr_r( L_tmp, 5 ) ); - *bit = sub( sub( tmp, bits_used ), 21 ); + *bit = sub( sub( tmp, bits_used ), 21 ); /*Q0*/ move16(); } nb_tot_bands = 10; @@ -229,7 +229,7 @@ void bands_and_bit_alloc_ivas_fx( { /* *bit = (short)(core_brate*(1.0f/50) + 0.5f) - bits_used - GSC_freq_bits[bit_index]; */ - L_tmp = Mult_32_16( core_brate, 20971 ); + L_tmp = Mult_32_16( core_brate, 20971 /*1/50 in Q20*/ ); tmp = extract_l( L_shr_r( L_tmp, 5 ) ); *bit = sub( sub( tmp, bits_used ), GSC_freq_bits[bit_index] ); move16(); @@ -493,7 +493,7 @@ void bands_and_bit_alloc_ivas_fx( #endif IF( EQ_16( GSC_noisy_speech, 1 ) ) { - SWB_bit_budget = *bit; + SWB_bit_budget = *bit; /*Q0*/ move32(); nb_bands = 5; move16(); @@ -536,7 +536,7 @@ void bands_and_bit_alloc_ivas_fx( set32_fx( bits_per_bands, 0, MBANDS_GN ); /*bit_fracf = (1.0f/nb_bands)*(SWB_bit_budget); */ #ifdef FIX_802__NON_BE_DECODING - bit_fracf = Find_bit_frac( nb_bands, extract_l( SWB_bit_budget ) ); + bit_fracf = Find_bit_frac( nb_bands, extract_l( SWB_bit_budget ) ); /*Q18*/ #else bit_fracf = L_mult( div_s( 1, nb_bands ), shl( (Word16) SWB_bit_budget, 2 ) ); /* Q18 */ #endif @@ -734,7 +734,7 @@ void bands_and_bit_alloc_ivas_fx( #endif { #ifdef FIX_802__NON_BE_DECODING - bit_fracf = Find_bit_frac( st_band, bit_tmp ); + bit_fracf = Find_bit_frac( st_band, bit_tmp ); /*Q18*/ #else bit_fracf = L_mult( div_s( 1, st_band ), shl( bit_tmp, 2 ) ); /* Q18 */ #endif @@ -752,8 +752,8 @@ void bands_and_bit_alloc_ivas_fx( } FOR( i = 0; i < imax; i++ ) { - bits_per_bands[i] = L_add( GSC_freq_bits_fx_Q18[bit_index], bit_fracf ); - move32(); /* Q18 */ + bits_per_bands[i] = L_add( GSC_freq_bits_fx_Q18[bit_index], bit_fracf ); /*Q18*/ + move32(); /* Q18 */ bit_index = add( bit_index, 1 ); } #if 1 // def ADD_LRTD @@ -763,14 +763,15 @@ void bands_and_bit_alloc_ivas_fx( move16(); i = sub( imax, 1 ); // bits_per_bands[i] += Compl_GSC_freq_bits[bit_index]; - bits_per_bands[i] = L_add( bits_per_bands[i], L_shl( Compl_GSC_freq_bits[bit_index], Q18 ) ); + bits_per_bands[i] = L_add( bits_per_bands[i], L_shl( Compl_GSC_freq_bits[bit_index], Q18 ) ); /*Q18*/ + move32(); i = add( i, 1 ); bit_index = add( bit_index, 1 ); FOR( ; i < 10; i++ ) { // bits_per_bands[i] += Compl_GSC_freq_bits[bit_index] + bit_fracf; - bits_per_bands[i] = L_add( bits_per_bands[i], L_add( L_shl( Compl_GSC_freq_bits[bit_index], Q18 ), bit_fracf ) ); + bits_per_bands[i] = L_add( bits_per_bands[i], L_add( L_shl( Compl_GSC_freq_bits[bit_index], Q18 ), bit_fracf ) ); /*Q18*/ move32(); bit_index = add( bit_index, 1 ); } @@ -781,8 +782,8 @@ void bands_and_bit_alloc_ivas_fx( bit_index = add( bit_index_mem, 10 ); FOR( i = 0; i < 7; i++ ) { - bits_per_bands[i] = L_add( bits_per_bands[i], GSC_freq_bits_fx_Q18[bit_index] ); - move32(); /*chk Q18 */ + bits_per_bands[i] = L_add( bits_per_bands[i], GSC_freq_bits_fx_Q18[bit_index] ); /*Q18*/ + move32(); /*chk Q18 */ bit_index = add( bit_index, 1 ); } } @@ -801,6 +802,7 @@ void bands_and_bit_alloc_ivas_fx( * Complete the bit allocation per frequency band for 16kHz high brate mode *--------------------------------------------------------------------------*/ #if 1 // def ADD_LRTD + test(); IF( EQ_16( L_frame, L_FRAME16k ) && GT_32( core_brate, ACELP_32k ) ) { FOR( j = st_band; j < nb_bands; j++ ) @@ -811,19 +813,19 @@ void bands_and_bit_alloc_ivas_fx( } // bit_fracf = (1.0f / nb_bands) * (bit_tmp); - bit_fracf = L_shl( L_mult0( idiv1616( 16384, nb_bands ), bit_tmp ), 4 ); + bit_fracf = L_shl( L_mult0( idiv1616( 16384, nb_bands ), bit_tmp ), 4 ); /*Q18*/ // etmp = 2.0f * bit_fracf / (nb_bands + 1); etmp = divide3216( L_shr( bit_fracf, Q2 ), add( nb_bands, 1 ) ); // Q15 // bit_fracf = etmp; bit_fracf = L_shl( etmp, Q3 ); // Q18 - FOR( j = sub( nb_bands, 1 ); j >= 0; j-- ) + FOR( j = nb_bands - 1; j >= 0; j-- ) { // bits_per_bands[j] = etmp; // etmp += bit_fracf; bits_per_bands[j] = L_add( bits_per_bands[j], L_shl( etmp, Q3 ) ); // Q18 move32(); - etmp = (Word16) L_add( etmp, L_shr( bit_fracf, Q3 ) ); + etmp = extract_l( L_add( etmp, L_shr( bit_fracf, Q3 ) ) ); } } ELSE @@ -852,7 +854,7 @@ void bands_and_bit_alloc_ivas_fx( { bandoffset = sub( bandoffset, 1 ); } - ELSE IF( ( LE_32( core_brate, ACELP_13k20 ) && ( EQ_16( coder_type, INACTIVE ) || GE_16( noise_lev, NOISE_LEVEL_SP3 ) ) ) || + ELSE IF( ( LE_32( core_brate, ACELP_13k20 ) && ( ( coder_type == INACTIVE ) || GE_16( noise_lev, NOISE_LEVEL_SP3 ) ) ) || ( LE_32( core_brate, ACELP_13k20 ) && GE_32( core_brate, ACELP_9k60 ) && cor_strong_limit == 0 ) ) { bandoffset = add( bandoffset, 1 ); @@ -899,12 +901,12 @@ void bands_and_bit_alloc_ivas_fx( FOR( j = 0; j < band; j++ ) { i = maximum_fx( ener_vec, sub( nb_tot_bands, bandoffset ), &etmp ); - max_ener_band[add( nb_bands, j )] = i; + max_ener_band[nb_bands + j] = i; move16(); ener_vec[i] = -10; move16(); - bits_per_bands[add( nb_bands, j )] = 1310720; - move32(); /*Q18 */ + bits_per_bands[nb_bands + j] = 1310720; /*5 in Q18*/ + move32(); /*Q18 */ } nb_bands = add( nb_bands, band ); @@ -912,7 +914,7 @@ void bands_and_bit_alloc_ivas_fx( IF( LE_16( band, 2 ) ) { - FOR( j = sub( st_band, 1 ); j < nb_bands; j++ ) + FOR( j = st_band - 1; j < nb_bands; j++ ) { bits_per_bands[j] = L_add( bits_per_bands[j], 262144 ); /*Q18 */ move32(); @@ -926,7 +928,7 @@ void bands_and_bit_alloc_ivas_fx( move16(); FOR( ; bit_tmp > 0; bit_tmp-- ) { - bits_per_bands[j] = L_sub( bits_per_bands[j], 262144 ); /*Q18 */ + bits_per_bands[j] = L_sub( bits_per_bands[j], ONE_IN_Q18 ); /*Q18 */ j = add( j, 1 ); IF( EQ_16( j, sub( st_band, i ) ) ) { @@ -934,7 +936,7 @@ void bands_and_bit_alloc_ivas_fx( move16(); } test(); - IF( j == 0 && LT_16( i, sub( st_band, 1 ) ) ) + if ( j == 0 && LT_16( i, sub( st_band, 1 ) ) ) { i = add( i, 1 ); } @@ -952,12 +954,12 @@ void bands_and_bit_alloc_ivas_fx( move16(); FOR( i = 0; i < nb_bands; i++ ) { - L_tmp = Mult_32_16( sum_bit, 10923 ); + L_tmp = Mult_32_16( sum_bit, 10923 /*1/3 in Q15*/ ); IF( GT_32( bits_per_bands[i], 29360128 ) ) /* 112 in Q18 */ { - sum_bit = L_add( sum_bit, L_sub( bits_per_bands[i], 29360128 ) ); /* Q18 */ - bits_per_bands[i] = 29360128; + sum_bit = L_add( sum_bit, L_sub( bits_per_bands[i], 29360128 /* 112 in Q18 */ ) ); /* Q18 */ + bits_per_bands[i] = 29360128 /* 112 in Q18 */; move32(); j = add( i, 1 ); } @@ -982,12 +984,13 @@ void bands_and_bit_alloc_ivas_fx( *--------------------------------------------------------------------------*/ #if 1 // def ADD_LRTD sum_bit = 0; + move32(); FOR( i = 0; i < nb_bands; i++ ) { // bits_per_bands[i] = (float)floor(bits_per_bands[i]); bits_per_bands[i] = L_shl( L_shr( bits_per_bands[i], Q18 ), Q18 ); move32(); - sum_bit = L_add( sum_bit, L_shr( bits_per_bands[i], Q18 ) ); + sum_bit = L_add( sum_bit, L_shr( bits_per_bands[i], Q18 ) ); /*Q0*/ } test(); IF( GSC_IVAS_mode != 0 && LT_32( sum_bit, *bit ) ) /* If we need to add bits, we are doing it on the LF */ @@ -1030,6 +1033,7 @@ void bands_and_bit_alloc_ivas_fx( *nb_subbands = nb_bands; move16(); *pvq_len = shl( *nb_subbands, 4 ); + move16(); /*-------------------------------------------------------------------------- * Concatenate bands (encoder only) @@ -1062,11 +1066,11 @@ void bands_and_bit_alloc_ivas_fx( *-------------------------------------------------------------------*/ static void reajust_bits_fx( - Word32 *bits_per_bands, + Word32 *bits_per_bands, /*i : Q18*/ const Word16 st_band, const Word16 end_band, - const Word16 sum_bit_in, - const Word16 bit_bdgt_in ) + const Word16 sum_bit_in, /*i : Q0*/ + const Word16 bit_bdgt_in /*i : Q0*/ ) { Word16 i, amount_to_add, incr; Word16 bit_bdgt, sum_bit; @@ -1105,10 +1109,10 @@ static void reajust_bits_fx( /* if (amount_to_add > 0 || (amount_to_add < 0 && bits_per_bands[i] > 1))*/ test(); test(); - IF( amount_to_add > 0 || ( amount_to_add < 0 && GT_32( bits_per_bands[i], 262144 ) ) ) + IF( amount_to_add > 0 || ( amount_to_add < 0 && GT_32( bits_per_bands[i], ONE_IN_Q18 ) ) ) { /* bits_per_bands[i] += amount_to_add;*/ - bits_per_bands[i] = L_add( bits_per_bands[i], L_shl( amount_to_add, Q18 ) ); + bits_per_bands[i] = L_add( bits_per_bands[i], L_shl( amount_to_add, Q18 ) ); /*Q18*/ move32(); sum_bit = add( sum_bit, abs_s( amount_to_add ) ); } @@ -1135,34 +1139,34 @@ static Word32 Find_bit_frac( const Word16 nb_band, const Word16 remaining_bits ) { - int16_t inv_bandQ15; - int32_t L_out; + Word16 inv_bandQ15; + Word32 L_out; - inv_bandQ15 = 6553; + inv_bandQ15 = 6553; /*Q15*/ move16(); - IF( nb_band == 7 ) + IF( EQ_16( nb_band, 7 ) ) { - inv_bandQ15 = 4681; + inv_bandQ15 = 4681; /*Q15*/ move16(); } - ELSE IF( nb_band == 3 ) + ELSE IF( EQ_16( nb_band, 3 ) ) { - inv_bandQ15 = 10922; + inv_bandQ15 = 10922; /*Q15*/ move16(); } - ELSE IF( nb_band == 4 ) + ELSE IF( EQ_16( nb_band, 4 ) ) { - inv_bandQ15 = 8192; + inv_bandQ15 = 8192; /*Q15*/ move16(); } - ELSE IF( nb_band == 5 ) + ELSE IF( EQ_16( nb_band, 5 ) ) { - inv_bandQ15 = 6536; + inv_bandQ15 = 6536; /*Q15*/ move16(); } - ELSE IF( nb_band == 10 ) + ELSE IF( EQ_16( nb_band, 10 ) ) { - inv_bandQ15 = 3277; + inv_bandQ15 = 3277; /*Q15*/ move16(); } ELSE @@ -1171,7 +1175,7 @@ static Word32 Find_bit_frac( printf( "1/%d NOT DEFINED in Find_bit_frac\n", nb_band ); #endif } - L_out = L_mult( inv_bandQ15, shl( remaining_bits, 2 ) ); + L_out = L_mult( inv_bandQ15, shl( remaining_bits, 2 ) ); /*Q18*/ return ( L_out ); } @@ -1185,7 +1189,7 @@ static Word16 Find_bit_alloc_IVAS( /*o: Number of Word16 *bit, /* i/o: Number of bit allowed for frequency quantization */ Word16 *max_ener_band, /* i/o: Energy based sorted order */ Word16 *ener_vec, /* i/o: Energy per band order */ - Word32 *bits_per_bands /* o : Number of bit allowed per allowed subband Q3 */ + Word32 *bits_per_bands /* o : Number of bit allowed per allowed subband Q18 */ ) { Word32 mp, mb, nb_bands_adj, bit_adj; @@ -1241,6 +1245,8 @@ static Word16 Find_bit_alloc_IVAS( /*o: Number of /* nb_bands_adj = 1.0f; */ nb_bands_adj = Q18_1_0; move32(); + test(); + test(); IF( EQ_16( GSC_IVAS_mode, 1 ) && LT_32( core_brate, GSC_L_RATE_STG ) ) { /* nb_bands_adj = 0.0125f * SWB_bit_budget - 0.75f;*/ @@ -1393,11 +1399,11 @@ static Word16 Find_bit_alloc_IVAS( /*o: Number of WHILE( SWB_bit_budget > 0 ) { /* bits_per_bands[i]++; */ - bits_per_bands[i] = L_add( bits_per_bands[i], Q18_1_0 ); + bits_per_bands[i] = L_add( bits_per_bands[i], Q18_1_0 ); /*Q18*/ move32(); /* SWB_bit_budget--; */ - SWB_bit_budget = L_sub( SWB_bit_budget, Q18_1_0 ); - i--; + SWB_bit_budget = L_sub( SWB_bit_budget, Q18_1_0 ); /*Q18*/ + i = sub( i, 1 ); if ( EQ_16( i, -1 ) ) { i = sub( st_band, 1 ); diff --git a/lib_com/gs_gains.c b/lib_com/gs_gains.c index b9a6f5875..31aca67b6 100644 --- a/lib_com/gs_gains.c +++ b/lib_com/gs_gains.c @@ -588,19 +588,19 @@ float gsc_gainQ( } Word16 gsc_gainQ_ivas_fx( - BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - const int16_t element_mode, /* i : element mode */ - const int16_t idchan, /* i : channel ID */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + const Word16 element_mode, /* i : element mode */ + const Word16 idchan, /* i : channel ID */ const Word16 y_gain4[], /* i : Energy per band */ // Q12 Word16 y_gainQ[], /* o : quantized energy per band */ // Q12 - const int32_t core_brate, /* i : Core rate */ - const int16_t coder_type, /* i : coding type */ - const int16_t bwidth, /* i : input signal bandwidth */ - const int16_t L_frame, /* i : frame length */ - const int16_t tdm_LRTD_flag, /* i : LRTD stereo mode flag */ - const int32_t core_brate_inp /* i : true core bitrate */ + const Word32 core_brate, /* i : Core rate */ + const Word16 coder_type, /* i : coding type */ + const Word16 bwidth, /* i : input signal bandwidth */ + const Word16 L_frame, /* i : frame length */ + const Word16 tdm_LRTD_flag, /* i : LRTD stereo mode flag */ + const Word32 core_brate_inp /* i : true core bitrate */ ) { Word16 y_gain_tmp[MBANDS_GN16k]; @@ -609,10 +609,11 @@ Word16 gsc_gainQ_ivas_fx( move16(); Word16 mean_4g_fx[1], ftmp1_fx; Word16 Mbands_gn = MBANDS_GN; + move16(); Word16 y_gain_tmp3[MBANDS_GN]; Word32 L_tmp; - IF( EQ_16( L_frame, L_FRAME16k ) ) + if ( EQ_16( L_frame, L_FRAME16k ) ) { Mbands_gn = MBANDS_GN16k; move16(); @@ -637,11 +638,11 @@ Word16 gsc_gainQ_ivas_fx( { IF( LT_16( y_gain4[i], ftmp1_fx ) ) { - y_gain_tmp2[i] = ftmp1_fx; + y_gain_tmp2[i] = ftmp1_fx; /*Q12*/ } ELSE { - y_gain_tmp2[i] = y_gain4[i]; + y_gain_tmp2[i] = y_gain4[i]; /*Q12*/ } move16(); } @@ -665,7 +666,7 @@ Word16 gsc_gainQ_ivas_fx( move16(); } - IF( LT_16( y_gain_tmp[9], -1229 /* -0.3f in Q12 */ ) ) + if ( LT_16( y_gain_tmp[9], -1229 /* -0.3f in Q12 */ ) ) { y_gain_tmp[9] = -1229; /* -0.3f in Q12 */ move16(); @@ -696,17 +697,17 @@ Word16 gsc_gainQ_ivas_fx( IF( LE_32( core_brate, ACELP_9k60 ) && coder_type == INACTIVE ) { /* Some energy is needed in high band for stat_noise_uv_enc() to be functional in inactive speech */ - y_gain_tmp[10] = mean_fx( y_gain_tmp + 6, 3 ); + y_gain_tmp[10] = mean_fx( y_gain_tmp + 6, 3 ); /*Q12*/ move16(); - y_gain_tmp[11] = mean_fx( y_gain_tmp + 7, 3 ); + y_gain_tmp[11] = mean_fx( y_gain_tmp + 7, 3 ); /*Q12*/ move16(); - y_gain_tmp[12] = mean_fx( y_gain_tmp + 8, 3 ); + y_gain_tmp[12] = mean_fx( y_gain_tmp + 8, 3 ); /*Q12*/ move16(); - y_gain_tmp[13] = mean_fx( y_gain_tmp + 9, 3 ); + y_gain_tmp[13] = mean_fx( y_gain_tmp + 9, 3 ); /*Q12*/ move16(); - y_gain_tmp[14] = mean_fx( y_gain_tmp + 10, 3 ); + y_gain_tmp[14] = mean_fx( y_gain_tmp + 10, 3 ); /*Q12*/ move16(); - y_gain_tmp[15] = mean_fx( y_gain_tmp + 11, 3 ); + y_gain_tmp[15] = mean_fx( y_gain_tmp + 11, 3 ); /*Q12*/ move16(); } ELSE @@ -726,13 +727,13 @@ Word16 gsc_gainQ_ivas_fx( ftmp1_fx = extract_l( L_tmp ); FOR( i = 0; i < Mbands_gn; i++ ) { - IF( LT_16( y_gain4[i], sub( ftmp1_fx, 2457 ) ) ) + IF( LT_16( y_gain4[i], sub( ftmp1_fx, 2457 /* 0.6 in Q12*/ ) ) ) { - y_gain_tmp2[i] = sub( ftmp1_fx, 2457 ); + y_gain_tmp2[i] = sub( ftmp1_fx, 2457 /* 0.6 in Q12*/ ); } - ELSE IF( GT_16( y_gain4[i], add( ftmp1_fx, 2457 ) ) ) + ELSE IF( GT_16( y_gain4[i], add( ftmp1_fx, 2457 /* 0.6 in Q12*/ ) ) ) { - y_gain_tmp2[i] = add( ftmp1_fx, 2457 ); + y_gain_tmp2[i] = add( ftmp1_fx, 2457 /* 0.6 in Q12*/ ); } ELSE { @@ -817,7 +818,7 @@ Word16 gsc_gainQ_ivas_fx( FOR( i = 8; i < 16; i++ ) { - y_gain_tmp[i] = shl( mult( y_gain_tmp[i], 23101 ), 1 ); + y_gain_tmp[i] = shl( mult( y_gain_tmp[i], 23101 /* 1.41 in Q14 */ ), 1 ); /*Q12*/ move16(); } diff --git a/lib_com/gs_gains_fx.c b/lib_com/gs_gains_fx.c index 703f0e4ef..8b3719e98 100644 --- a/lib_com/gs_gains_fx.c +++ b/lib_com/gs_gains_fx.c @@ -82,6 +82,7 @@ void Comp_and_apply_gain_fx( Word32 L32; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif /* Recreate excitation for local synthesis and decoder */ @@ -139,7 +140,8 @@ void Comp_and_apply_gain_fx( L32 = L_mult( exc_diffQ[i], y_gain ); /*Qexc_diff+15 */ #ifdef BASOP_NOGLOB exc_diffQ[i] = round_fx_o( L_shl_o( L32, tmp_exp, &Overflow ), &Overflow ); /*Q_exc */ -#else /* BASOP_NOGLOB */ + move16(); +#else /* BASOP_NOGLOB */ exc_diffQ[i] = round_fx( L_shl( L32, tmp_exp ) ); /*Q_exc */ #endif } @@ -183,7 +185,7 @@ void Comp_and_apply_gain_ivas_fx( move16(); IF( EQ_16( ReUseGain, 1 ) ) { - y_gain = Ener_per_bd_yQ[i_band]; + y_gain = Ener_per_bd_yQ[i_band]; /*Q13*/ move16(); FOR( i = StartBin; i < NB_Qbins + StartBin; i++ ) @@ -221,11 +223,11 @@ void Comp_and_apply_gain_ivas_fx( /* output of Pow2() will be: */ /* 16384 < Pow2() <= 32767 */ #ifdef BASOP_NOGLOB - Ener_per_bd_yQ[i_band] = shl_o( y_gain, sub( exp1, 13 ), &Overflow ); -#else /* BASOP_NOGLOB */ + Ener_per_bd_yQ[i_band] = shl_o( y_gain, sub( exp1, 13 ), &Overflow ); /*Q13*/ +#else /* BASOP_NOGLOB */ Ener_per_bd_yQ[i_band] = shl( y_gain, sub( exp1, 13 ) ); -#endif /* BASOP_NOGLOB */ - move16(); /*Q1 */ +#endif /* BASOP_NOGLOB */ + move16(); /*Q1 */ tmp_exp = add( add( exp1, 1 ), sub( *Q_exc, Qexc_diff ) ); FOR( i = StartBin; i < NB_Qbins + StartBin; i++ ) @@ -257,7 +259,7 @@ void Comp_and_apply_gain_ivas_fx( } FOR( i = 0; i < StartBin + NB_Qbins; i++ ) { - exc_diffQ[i] = shl( exc_diffQ[i], sub( *Q_exc, Q_exc_diffQ[i] ) ); + exc_diffQ[i] = shl( exc_diffQ[i], sub( *Q_exc, Q_exc_diffQ[i] ) ); /*Q_exc*/ move16(); } @@ -320,21 +322,21 @@ void Ener_per_band_comp_fx( pt_fx = exc_diff_fx; FOR( j = 0; j < 2; j++ ) { - y_gain4_fx[j] = Comp_band_log_ener( pt_fx, 8, Q_exc, 1 ); + y_gain4_fx[j] = Comp_band_log_ener( pt_fx, 8, Q_exc, 1 ); /*Q12*/ move16(); pt_fx += 8; } FOR( j = 1; j < Mband - 2; j++ ) { - y_gain4_fx[j + 1] = Comp_band_log_ener( pt_fx, 16, Q_exc, 0 ); + y_gain4_fx[j + 1] = Comp_band_log_ener( pt_fx, 16, Q_exc, 0 ); /*Q12*/ move16(); pt_fx += 16; } IF( EQ_16( Eflag, 1 ) ) { - y_gain4_fx[add( j, 1 )] = Comp_band_log_ener( pt_fx, 32, Q_exc, -1 ); + y_gain4_fx[j + 1] = Comp_band_log_ener( pt_fx, 32, Q_exc, -1 ); /*Q12*/ move16(); pt_fx += 32; } @@ -357,30 +359,30 @@ void Ener_per_band_comp_ivas_fx( pt_fx = exc_diff_fx; FOR( j = 0; j < 2; j++ ) { - y_gain4_fx[j] = Comp_band_log_ener( pt_fx, 8, Q_exc, 1 ); + y_gain4_fx[j] = Comp_band_log_ener( pt_fx, 8, Q_exc, 1 ); /*Q12*/ move16(); pt_fx += 8; } FOR( j = 1; j < Mband - 2; j++ ) { - y_gain4_fx[j + 1] = Comp_band_log_ener( pt_fx, 16, Q_exc, 0 ); + y_gain4_fx[j + 1] = Comp_band_log_ener( pt_fx, 16, Q_exc, 0 ); /*Q12*/ move16(); pt_fx += 16; } IF( EQ_16( Eflag, 1 ) ) { - y_gain4_fx[add( j, 1 )] = Comp_band_log_ener( pt_fx, 32, Q_exc, -1 ); + y_gain4_fx[j + 1] = Comp_band_log_ener( pt_fx, 32, Q_exc, -1 ); /*Q12*/ move16(); pt_fx += 32; } IF( EQ_16( L_frame, L_FRAME16k ) ) { - y_gain4_fx[j + 2] = Comp_band_log_ener( pt_fx, 32, Q_exc, -1 ); + y_gain4_fx[j + 2] = Comp_band_log_ener( pt_fx, 32, Q_exc, -1 ); /*Q12*/ move16(); - y_gain4_fx[j + 3] = Comp_band_log_ener( pt_fx, 64, Q_exc, -1 ); + y_gain4_fx[j + 3] = Comp_band_log_ener( pt_fx, 64, Q_exc, -1 ); /*Q12*/ move16(); pt_fx += 64; } @@ -566,7 +568,7 @@ static void GSC_gain_adj( old_y_gain[i] = y_gain_tmp[i]; move16(); /*y_gainQ[i] = y_gain_tmp[i]+mean_4g[0]-(i*(Gain_off/20.f)/((float) Mbands_gn));*/ - y_gainQ[i] = add( y_gain_tmp[i], sub( mean_g, i_mult2( i, mult_r( Gain_off, 102 ) ) ) ); + y_gainQ[i] = add( y_gain_tmp[i], sub( mean_g, i_mult2( i, mult_r( Gain_off, 102 /* 20/MBANDS_GN in Q15 */ ) ) ) ); move16(); } } @@ -594,7 +596,7 @@ static void GSC_gain_adj_ivas_fx( Word16 Gain_off, i; test(); - IF( NE_16( coder_type, INACTIVE ) && NE_16( coder_type, UNVOICED ) ) + IF( ( coder_type != INACTIVE ) && NE_16( coder_type, UNVOICED ) ) { FOR( i = 0; i < Mbands_gn; i++ ) { @@ -646,7 +648,7 @@ static void GSC_gain_adj_ivas_fx( { old_y_gain[i] = y_gain_tmp[i]; move16(); - y_gainQ[i] = add( y_gain_tmp[i], sub( mean_g, i_mult2( i, mult_r( Gain_off, 205 ) ) ) ); + y_gainQ[i] = add( y_gain_tmp[i], sub( mean_g, i_mult2( i, mult_r( Gain_off, 205 /* 20/MBANDS_GN in Q16 */ ) ) ) ); move16(); } } @@ -690,33 +692,32 @@ Word16 gsc_gaindec_fx( /* o : average frequency gai test(); test(); - IF( ( EQ_16( coder_type, AUDIO ) || EQ_16( coder_type, INACTIVE ) ) && EQ_16( bwidth_fx, NB ) ) + IF( ( EQ_16( coder_type, AUDIO ) || ( coder_type == INACTIVE ) ) && EQ_16( bwidth_fx, NB ) ) { - idx_g_fx = (Word16) get_next_indice_fx( st_fx, 6 ); + idx_g_fx = (Word16) ( get_next_indice_fx( st_fx, 6 ) ); VDQ_vec_fx( &mean_4g_fx, Gain_meanNB_fx, Gain_mean_dicNB_fx, idx_g_fx, 1 ); - idx_g_fx = (Word16) get_next_indice_fx( st_fx, 6 ); - move16(); + idx_g_fx = (Word16) ( get_next_indice_fx( st_fx, 6 ) ); VDQ_vec_fx( y_gainQ_fx, Mean_dic_NB_fx, Gain_dic1_NB_fx, idx_g_fx, 3 ); IF( LT_32( core_brate_fx, ACELP_9k60 ) ) { - idx_g_fx = (Word16) get_next_indice_fx( st_fx, 5 ); + idx_g_fx = (Word16) ( get_next_indice_fx( st_fx, 5 ) ); VDQ_vec_fx( y_gainQ_fx + 3, Mean_dic_NB_fx + 3, Gain_dic2_NB_fx, idx_g_fx, 3 ); - idx_g_fx = (Word16) get_next_indice_fx( st_fx, 4 ); + idx_g_fx = (Word16) ( get_next_indice_fx( st_fx, 4 ) ); VDQ_vec_fx( y_gainQ_fx + 6, Mean_dic_NB_fx + 6, Gain_dic3_NB_fx, idx_g_fx, 4 ); } ELSE { - idx_g_fx = (Word16) get_next_indice_fx( st_fx, 6 ); + idx_g_fx = (Word16) ( get_next_indice_fx( st_fx, 6 ) ); VDQ_vec_fx( y_gainQ_fx + 3, Mean_dic_NB_fx + 3, Gain_dic2_NBHR_fx, idx_g_fx, 3 ); - idx_g_fx = (Word16) get_next_indice_fx( st_fx, 7 ); + idx_g_fx = (Word16) ( get_next_indice_fx( st_fx, 7 ) ); VDQ_vec_fx( y_gainQ_fx + 6, Mean_dic_NB_fx + 6, Gain_dic3_NBHR_fx, idx_g_fx, 4 ); } test(); - IF( LE_32( core_brate_fx, ACELP_9k60 ) && EQ_16( coder_type, INACTIVE ) ) + IF( LE_32( core_brate_fx, ACELP_9k60 ) && ( coder_type == INACTIVE ) ) { /* Some energy is needed in high band for stat_noise_uv_enc to be functional in inactive speech */ @@ -777,6 +778,7 @@ Word16 gsc_gaindec_fx( /* o : average frequency gai FOR( i = 8; i < 16; i++ ) { y_gainQ_fx[i] = round_fx( L_shl( L_mult( y_gainQ_fx[i], 23101 ), 1 ) ); /*Q12 */ + move16(); } /*----------------------------------------------------------------------* * Copy the true Q values in the specific bands @@ -835,7 +837,7 @@ Word16 gsc_gaindec_fx( /* o : average frequency gai /*==========================================================================*/ Word16 gsc_gaindec_ivas_fx( /* o : average frequency gain */ Decoder_State *st_fx, /* i/o: decoder state structure */ - Word16 y_gainQ_fx[], /* o : quantized gain per band */ + Word16 y_gainQ_fx[], /* o : quantized gain per band Q12 */ const Word32 core_brate_fx, /* i : core used */ Word16 old_y_gain_fx[], /* i/o: AR gain quantizer for low rate */ const Word16 coder_type, /* i : coding type */ @@ -847,7 +849,7 @@ Word16 gsc_gaindec_ivas_fx( /* o : average frequenc Word16 Mbands_gn = MBANDS_GN; move16(); Word16 y_gain_tmp3_fx[MBANDS_GN]; - IF( EQ_16( st_fx->L_frame, L_FRAME16k ) ) + if ( EQ_16( st_fx->L_frame, L_FRAME16k ) ) { Mbands_gn = MBANDS_GN16k; move16(); @@ -855,7 +857,7 @@ Word16 gsc_gaindec_ivas_fx( /* o : average frequenc test(); test(); - IF( ( EQ_16( coder_type, AUDIO ) || EQ_16( coder_type, INACTIVE ) ) && EQ_16( bwidth_fx, NB ) ) + IF( ( EQ_16( coder_type, AUDIO ) || ( coder_type == INACTIVE ) ) && EQ_16( bwidth_fx, NB ) ) { idx_g_fx = (Word16) get_next_indice_fx( st_fx, 6 ); VDQ_vec_fx( &mean_4g_fx, Gain_meanNB_fx, Gain_mean_dicNB_fx, idx_g_fx, 1 ); @@ -880,21 +882,21 @@ Word16 gsc_gaindec_ivas_fx( /* o : average frequenc VDQ_vec_fx( y_gainQ_fx + 6, Mean_dic_NB_fx + 6, Gain_dic3_NBHR_fx, idx_g_fx, 4 ); } test(); - IF( LE_32( core_brate_fx, ACELP_9k60 ) && EQ_16( coder_type, INACTIVE ) ) + IF( LE_32( core_brate_fx, ACELP_9k60 ) && ( coder_type == INACTIVE ) ) { /* Some energy is needed in high band for stat_noise_uv_enc to be functional in inactive speech */ - y_gainQ_fx[10] = mean_fx( y_gainQ_fx + 6, 3 ); + y_gainQ_fx[10] = mean_fx( y_gainQ_fx + 6, 3 ); /*Q12*/ move16(); - y_gainQ_fx[11] = mean_fx( y_gainQ_fx + 7, 3 ); + y_gainQ_fx[11] = mean_fx( y_gainQ_fx + 7, 3 ); /*Q12*/ move16(); - y_gainQ_fx[12] = mean_fx( y_gainQ_fx + 8, 3 ); + y_gainQ_fx[12] = mean_fx( y_gainQ_fx + 8, 3 ); /*Q12*/ move16(); - y_gainQ_fx[13] = mean_fx( y_gainQ_fx + 9, 3 ); + y_gainQ_fx[13] = mean_fx( y_gainQ_fx + 9, 3 ); /*Q12*/ move16(); - y_gainQ_fx[14] = mean_fx( y_gainQ_fx + 10, 3 ); + y_gainQ_fx[14] = mean_fx( y_gainQ_fx + 10, 3 ); /*Q12*/ move16(); - y_gainQ_fx[15] = mean_fx( y_gainQ_fx + 11, 3 ); + y_gainQ_fx[15] = mean_fx( y_gainQ_fx + 11, 3 ); /*Q12*/ move16(); } ELSE @@ -946,13 +948,13 @@ Word16 gsc_gaindec_ivas_fx( /* o : average frequenc /*----------------------------------------------------------------------* * Copy the true Q values in the specific bands *----------------------------------------------------------------------*/ - y_gainQ_fx[8] = y_gain_tmp3_fx[0]; + y_gainQ_fx[8] = y_gain_tmp3_fx[0]; /*Q12*/ move16(); - y_gainQ_fx[10] = y_gain_tmp3_fx[1]; + y_gainQ_fx[10] = y_gain_tmp3_fx[1]; /*Q12*/ move16(); - y_gainQ_fx[12] = y_gain_tmp3_fx[2]; + y_gainQ_fx[12] = y_gain_tmp3_fx[2]; /*Q12*/ move16(); - y_gainQ_fx[14] = y_gain_tmp3_fx[3]; + y_gainQ_fx[14] = y_gain_tmp3_fx[3]; /*Q12*/ move16(); } ELSE @@ -973,19 +975,19 @@ Word16 gsc_gaindec_ivas_fx( /* o : average frequenc } ELSE { - idx_g_fx = get_next_indice_fx( st_fx, 7 ); + idx_g_fx = (Word16) get_next_indice_fx( st_fx, 7 ); VDQ_vec_fx( y_gainQ_fx, YG_mean16HR_fx, YG_dicHR_1_fx, idx_g_fx, 4 ); - idx_g_fx = get_next_indice_fx( st_fx, 6 ); + idx_g_fx = (Word16) get_next_indice_fx( st_fx, 6 ); VDQ_vec_fx( y_gainQ_fx + 4, YG_mean16HR_fx + 4, YG_dicHR_2_fx, idx_g_fx, 4 ); - idx_g_fx = get_next_indice_fx( st_fx, 6 ); + idx_g_fx = (Word16) get_next_indice_fx( st_fx, 6 ); VDQ_vec_fx( y_gainQ_fx + 8, YG_mean16HR_fx + 8, YG_dicHR_3_fx, idx_g_fx, 4 ); - idx_g_fx = get_next_indice_fx( st_fx, 6 ); + idx_g_fx = (Word16) get_next_indice_fx( st_fx, 6 ); VDQ_vec_fx( y_gainQ_fx + 12, YG_mean16HR_16kHz_fx, YG_dicHR_4_16kHz_fx, idx_g_fx, 4 ); - idx_g_fx = get_next_indice_fx( st_fx, 3 ); + idx_g_fx = (Word16) get_next_indice_fx( st_fx, 3 ); VDQ_vec_fx( y_gainQ_fx + 16, YG_meanL2G_16kHz_fx, YG_dicL2G_16kHz_fx, idx_g_fx, 2 ); } } @@ -1033,7 +1035,7 @@ Word16 gsc_gainQ_fx( /*Q12*/ L_tmp = L_deposit_l( 0 ); FOR( cnt = 0; cnt < 10; cnt++ ) { - L_tmp = L_mac( L_tmp, y_gain4[cnt], 3277 ); + L_tmp = L_mac( L_tmp, y_gain4[cnt], 3277 /*0.1 in Q15*/ ); } tmp16 = sub( round_fx( L_tmp ), 4915 ); @@ -1049,7 +1051,7 @@ Word16 gsc_gainQ_fx( /*Q12*/ L_tmp = L_deposit_l( 0 ); FOR( i = 0; i < 10; i++ ) { - L_tmp = L_mac( L_tmp, y_gain_tmp2[i], 3277 ); + L_tmp = L_mac( L_tmp, y_gain_tmp2[i], 3277 /*0.1 in Q15*/ ); } /* Quantized mean gain without clipping */ @@ -1064,7 +1066,7 @@ Word16 gsc_gainQ_fx( /*Q12*/ move16(); } /*if(y_gain_tmp[9] < -0.3f){y_gain_tmp[9] = -0.3f;}*/ - y_gain_tmp[9] = s_max( y_gain_tmp[9], -1229 ); + y_gain_tmp[9] = s_max( y_gain_tmp[9], -1229 /*0.3 in Q12*/ ); move16(); set16_fx( y_gain_tmp + 10, 0, MBANDS_GN - 10 ); idx_g = vquant_fx( y_gain_tmp, Mean_dic_NB_fx, y_gain_tmp, Gain_dic1_NB_fx, 3, 64 ); @@ -1086,7 +1088,7 @@ Word16 gsc_gainQ_fx( /*Q12*/ } /*add end */ test(); - IF( LE_32( core_brate, ACELP_9k60 ) && EQ_16( coder_type, INACTIVE ) ) + IF( LE_32( core_brate, ACELP_9k60 ) && ( coder_type == INACTIVE ) ) { /* Some energy is needed in high band for stat_noise_uv_enc to be functional in inactive speech */ diff --git a/lib_com/gs_inact_switching_fx.c b/lib_com/gs_inact_switching_fx.c index aa7b647bd..7fc4ca16d 100644 --- a/lib_com/gs_inact_switching_fx.c +++ b/lib_com/gs_inact_switching_fx.c @@ -13,8 +13,8 @@ *-------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED -#define ALPHA0_FX 13107 -#define BETA0_FX ( 32768 - ALPHA0_FX ) +#define ALPHA0_FX 13107 /*Q15*/ +#define BETA0_FX ( 32768 - ALPHA0_FX ) /*Q15*/ /*========================================================================*/ /* FUNCTION : Inac_swtch_ematch_fx() */ @@ -83,7 +83,7 @@ void Inac_swtch_ematch_fx( move16(); } } - ELSE IF( EQ_16( coder_type, VOICED ) || EQ_16( coder_type, GENERIC ) || EQ_16( coder_type, TRANSITION ) || NE_16( last_core, ACELP_CORE ) || NE_16( last_codec_mode, MODE1 ) ) + ELSE IF( EQ_16( coder_type, VOICED ) || EQ_16( coder_type, GENERIC ) || EQ_16( coder_type, TRANSITION ) || ( last_core != ACELP_CORE ) || NE_16( last_codec_mode, MODE1 ) ) { /* Find spectrum and energy per band for GC and VC frames */ edct_16fx( exc2, dct_exc_tmp, L_frame, 5, EVS_MONO ); @@ -97,7 +97,7 @@ void Inac_swtch_ematch_fx( move16(); } } - ELSE IF( EQ_16( coder_type, INACTIVE ) && LE_32( core_brate, ACELP_24k40 ) ) + ELSE IF( ( coder_type == INACTIVE ) && LE_32( core_brate, ACELP_24k40 ) ) { /* Find spectrum and energy per band for inactive frames */ edct_16fx( exc2, dct_exc_tmp, L_frame, 5, EVS_MONO ); @@ -112,6 +112,7 @@ void Inac_swtch_ematch_fx( L_tmp = L_mult( ALPHA0_FX, lt_ener_per_band[i] ); /*Q(15+12+1)=Q(28) */ L_tmp = L_mac( L_tmp, BETA0_FX, Ener_per_bd[i] ); /*Q28 */ lt_ener_per_band[i] = round_fx( L_tmp ); /*Q12 */ + move16(); ftmp = sub( lt_ener_per_band[i], Ener_per_bd[i] ); /*Q12 */ @@ -205,6 +206,8 @@ void Inac_switch_ematch_ivas_fx( test(); test(); test(); + test(); + test(); IF( ( EQ_16( coder_type, AUDIO ) || ( EQ_16( coder_type, UNVOICED ) && EQ_16( tdm_low_rate_mode, 1 ) ) ) && bfi == 0 ) { Ener_per_band_comp_ivas_fx( dct_exc_tmp, Ener_per_bd, Q_exc, MBANDS_GN, 1, L_frame ); @@ -212,11 +215,11 @@ void Inac_switch_ematch_ivas_fx( /* reset long-term energy per band */ FOR( i = 0; i < MBANDS_GN; i++ ) { - lt_ener_per_band[i] = Ener_per_bd[i]; + lt_ener_per_band[i] = Ener_per_bd[i]; /*Q12*/ move16(); } } - ELSE IF( EQ_16( coder_type, VOICED ) || EQ_16( coder_type, GENERIC ) || EQ_16( coder_type, TRANSITION ) || NE_16( last_core, ACELP_CORE ) || NE_16( last_codec_mode, MODE1 ) || ( GT_16( element_mode, EVS_MONO ) && EQ_16( coder_type, UNVOICED ) ) ) + ELSE IF( EQ_16( coder_type, VOICED ) || EQ_16( coder_type, GENERIC ) || EQ_16( coder_type, TRANSITION ) || ( last_core != ACELP_CORE ) || NE_16( last_codec_mode, MODE1 ) || ( ( element_mode > EVS_MONO ) && EQ_16( coder_type, UNVOICED ) ) ) { /* Find spectrum and energy per band for GC and VC frames */ edct_16fx( exc2, dct_exc_tmp, L_frame, 5, element_mode ); @@ -226,11 +229,11 @@ void Inac_switch_ematch_ivas_fx( /* reset long-term energy per band */ FOR( i = 0; i < MBANDS_GN; i++ ) { - lt_ener_per_band[i] = Ener_per_bd[i]; + lt_ener_per_band[i] = Ener_per_bd[i]; /*Q12*/ move16(); } } - ELSE IF( EQ_16( coder_type, INACTIVE ) && LE_32( total_brate, MAX_GSC_INACTIVE_BRATE ) ) + ELSE IF( ( coder_type == INACTIVE ) && LE_32( total_brate, MAX_GSC_INACTIVE_BRATE ) ) { /* Find spectrum and energy per band for inactive frames */ edct_16fx( exc2, dct_exc_tmp, L_frame, 5, element_mode ); diff --git a/lib_com/gs_noisefill_fx.c b/lib_com/gs_noisefill_fx.c index 93b7bb3f8..d0f72936d 100644 --- a/lib_com/gs_noisefill_fx.c +++ b/lib_com/gs_noisefill_fx.c @@ -17,8 +17,8 @@ static void gs_noisf_fx( const Word16 Start_BIN, /* i : First bin for noise fill */ const Word16 NB_Qbins, /* i : Number of bin per band */ const Word16 Noise_fac, /* i : Noise level Q15 */ - const Word16 *y_norm, /* i : Quantized pulses Qn */ - Word16 *exc_diffQ, /* o : Quantized pulses with noise added Qn */ + const Word16 *y_norm, /* i : Quantized pulses Q(qNoise_fac) */ + Word16 *exc_diffQ, /* o : Quantized pulses with noise added Q(qNoise_fac) */ Word16 *seed_tcx, /* i : Random generator seed */ const Word16 coder_type, /* i : coder type */ Word16 qNoise_fac ) @@ -32,8 +32,8 @@ static void gs_noisf_fx( NB_zer = shr( NB_Qbins, 1 ); - const_1 = L_shl( const_1, add( qNoise_fac, qNoise_fac ) ); - if ( EQ_16( coder_type, INACTIVE ) ) + const_1 = L_shl( const_1, add( qNoise_fac, qNoise_fac ) ); /*2*Q(qNoise_fac)*/ + if ( ( coder_type == INACTIVE ) ) { NB_zer = 2; move16(); @@ -51,7 +51,7 @@ static void gs_noisf_fx( { exc_diffQ[i] = y_norm[i]; move16(); - ftmp = L_mac0( ftmp, exc_diffQ[i], exc_diffQ[i] ); + ftmp = L_mac0( ftmp, exc_diffQ[i], exc_diffQ[i] ); /*2*Q(qNoise_fac)*/ } IF( LT_32( L_shl( ftmp, 1 ), const_1 ) ) @@ -118,11 +118,11 @@ static void EstimateNoiseLevel_inner_fx( move16(); /*.4f * 32768 */ } - set16_fx( noisepb + i_band, noise_offset, sub( Mbands_gn, i_band ) ); + set16_fx( noisepb + i_band, noise_offset, sub( Mbands_gn, i_band ) ); /*Q15*/ FOR( i = i_band; i < 5; i++ ) { - noisepb[i] = s_min( noisepb[i], 6554 ); + noisepb[i] = s_min( noisepb[i], 6554 /*0.2(Q15)*/ ); move16(); } @@ -196,7 +196,7 @@ static void EstimateNoiseLevel_fx( } test(); test(); - IF( ( EQ_16( coder_type, INACTIVE ) || GE_16( noise_lev, NOISE_LEVEL_SP3 ) ) && EQ_16( L_frame, L_FRAME ) ) + IF( ( ( coder_type == INACTIVE ) || GE_16( noise_lev, NOISE_LEVEL_SP3 ) ) && EQ_16( L_frame, L_FRAME ) ) { FOR( i_band = 9; i_band < Mbands_gn; i_band++ ) { @@ -211,7 +211,7 @@ static void EstimateNoiseLevel_fx( set16_fx( noisepb, 14746 /*0.45*/, Mbands_gn ); } - IF( EQ_16( coder_type, INACTIVE ) ) + IF( ( coder_type == INACTIVE ) ) { FOR( ; i_band < Mbands_gn; i_band++ ) { @@ -320,7 +320,7 @@ void freq_dnw_scaling_fx( const Word16 coder_type, /* i : coder type */ const Word16 noise_lev, /* i : Noise level */ const Word32 core_brate, /* i : Core bitrate */ - Word16 fy_norm[], /* i/o: Frequency quantized parameter */ + Word16 fy_norm[], /* i/o: Frequency quantized parameter Qx */ Word16 Qx, /* Q format of fy_norm*/ const Word16 L_frame /* i : frame length */ @@ -340,7 +340,7 @@ void freq_dnw_scaling_fx( start_sc = 64; move16(); } - ELSE IF( EQ_16( coder_type, INACTIVE ) ) + ELSE IF( ( coder_type == INACTIVE ) ) { sc_dyn = mult_r( sc_dyn, 8192 ); /*Q15 (0.25 in Q15) */ start_sc = 80; @@ -377,9 +377,9 @@ void freq_dnw_scaling_fx( { FOR( i = 160; i < L_frame; i++ ) { - fy_norm[i] = s_min( fy_norm[i], shl( 1, Qx ) ); + fy_norm[i] = s_min( fy_norm[i], shl( 1, Qx ) ); /*Qx*/ move16(); - fy_norm[i] = s_max( fy_norm[i], shl( -1, Qx ) ); + fy_norm[i] = s_max( fy_norm[i], shl( -1, Qx ) ); /*Qx*/ move16(); } } @@ -387,9 +387,9 @@ void freq_dnw_scaling_fx( { FOR( i = 160; i < L_frame; i++ ) { - fy_norm[i] = s_min( fy_norm[i], shr_r( 1536, sub( 10, Qx ) ) ); + fy_norm[i] = s_min( fy_norm[i], shr_r( 1536 /*1.5 in Q10*/, sub( 10, Qx ) ) ); /*Qx*/ move16(); - fy_norm[i] = s_max( fy_norm[i], shr_r( -1536, sub( 10, Qx ) ) ); + fy_norm[i] = s_max( fy_norm[i], shr_r( -1536 /*1.5 in Q10*/, sub( 10, Qx ) ) ); /*Qx*/ move16(); } } @@ -398,7 +398,7 @@ void freq_dnw_scaling_fx( } static void Decreas_freqPeak_fx( - const Word16 *lsf_new, /* i : ISFs at the end of the frame */ + const Word16 *lsf_new, /* i : ISFs at the end of the frame Qx2.56 */ Word16 *exc_diffQ, /* i/o: frequency coefficients of per band */ Word16 rat /* i : threshold of ratio between consecutive lsf_new_diff */ ) @@ -406,6 +406,7 @@ static void Decreas_freqPeak_fx( Word16 i, j, k; Word16 last_bin = 0; Word16 pos = 0; + move16(); Word16 *src, max_val, avrg; Word32 L_avrg, L_tmp; Word16 lsf_new_diff[M]; @@ -446,7 +447,7 @@ static void Decreas_freqPeak_fx( move16(); /* When the search is false, should equate the end of the vector, not the beginning */ FOR( i = 0; i < ( M - 1 ); i++ ) { - if ( GT_16( lsf_new[i], 10240 ) ) + IF( GT_16( lsf_new[i], 10240 /*4000 in Qx2.56*/ ) ) { last_bin = i; move16(); @@ -459,7 +460,7 @@ static void Decreas_freqPeak_fx( tmp = mult_r( rat, lsf_new_diff[i - 1] ); /*Qx2.56 */ IF( GT_16( tmp, lsf_new_diff[i] ) ) { - src = &exc_diffQ[shl( sub( i, 1 ), 4 )]; + src = &exc_diffQ[( i - 1 ) << 4]; move16(); FOR( j = 0; j < 2; j++ ) { @@ -505,7 +506,7 @@ static void Decreas_freqPeak_fx( { FOR( i = pos - 1; i < pos + 2; i++ ) { - exc_diffQ[pos] = mult_r( 16384, exc_diffQ[pos] ); + exc_diffQ[pos] = mult_r( 16384 /*0.5 in Q15*/, exc_diffQ[pos] ); move16(); } } @@ -553,8 +554,7 @@ static void envelop_modify_fx( exp1 = norm_l( Ener_fx ); Ener_fx = L_shl( Ener_fx, exp1 ); - exp1 = 31 - exp1 - sub( shl( Q_exc, 1 ), 7 ); - move16(); + exp1 = sub( sub( 31, exp1 ), sub( shl( Q_exc, 1 ), 7 ) ); Ener_fx = Isqrt_lc( Ener_fx, &exp1 ); /*Q(31-exp1) */ weight_fx = 16384; /*Q15 */ @@ -586,7 +586,7 @@ static void envelop_modify_fx( L_tmp = L_mult0( sub( 32767, weight_fx ), Random( seed_tcx ) ); /*Q30 */ tmp1 = round_fx( L_shr( L_tmp, 2 ) ); - L_exc_diffQ_fx[add( i_mult( 16, i ), j )] = L_mult0( Ener1_fx, add( tmp, tmp1 ) ); /*Q12 */ + L_exc_diffQ_fx[( ( 16 * i ) + j )] = L_mult0( Ener1_fx, add( tmp, tmp1 ) ); /*Q12 */ move32(); src_fx++; } @@ -617,7 +617,7 @@ static void envelop_modify_fx( L_tmp = L_mult0( sub( 32767, weight_fx ), Random( seed_tcx ) ); /*Q30 */ tmp1 = round_fx( L_shr( L_tmp, 2 ) ); /*Q12 */ - L_exc_diffQ_fx[add( i_mult( 16, i ), j )] = L_mult0( Ener1_fx, add( tmp, tmp1 ) ); /*Q12 */ + L_exc_diffQ_fx[( ( 16 * i ) + j )] = L_mult0( Ener1_fx, add( tmp, tmp1 ) ); /*Q12 */ move32(); src_fx++; } @@ -647,6 +647,7 @@ static void envelop_modify_fx( { Q_tmp = sub( 16, exp ); *Q_hb_exc = sub( 12, Q_tmp ); + move16(); FOR( i = start_band; i < L_FRAME; i++ ) { exc_diffQ_fx[i] = extract_l( L_shr( L_exc_diffQ_fx[i], Q_tmp ) ); @@ -988,11 +989,11 @@ void highband_exc_dct_in_fx( last_bin = sub( last_bin, 1 ); tmp = i_mult( MAX_Bin, 16 ); tmp1 = i_mult( last_bin, 16 ); - src = &exc_diffQ[sub( L_FRAME, 1 )]; + src = &exc_diffQ[L_FRAME - 1]; move16(); - dst = &exc_dct_in[sub( tmp, 1 )]; + dst = &exc_dct_in[( tmp - 1 )]; move16(); - end = &exc_diffQ[sub( tmp1, 1 )]; + end = &exc_diffQ[( tmp1 - 1 )]; move16(); WHILE( src > end ) @@ -1492,11 +1493,11 @@ void highband_exc_dct_in_ivas_fx( last_bin = sub( last_bin, 1 ); tmp = i_mult( MAX_Bin, 16 ); tmp1 = i_mult( last_bin, 16 ); - src = &exc_diffQ[sub( L_FRAME, 1 )]; + src = &exc_diffQ[( L_FRAME - 1 )]; move16(); - dst = &exc_dct_in[sub( tmp, 1 )]; + dst = &exc_dct_in[( tmp - 1 )]; move16(); - end = &exc_diffQ[sub( tmp1, 1 )]; + end = &exc_diffQ[( tmp1 - 1 )]; move16(); WHILE( src > end ) diff --git a/lib_com/hq2_core_com.c b/lib_com/hq2_core_com.c index 59ad832f7..e238ac724 100644 --- a/lib_com/hq2_core_com.c +++ b/lib_com/hq2_core_com.c @@ -305,16 +305,17 @@ void reverse_transient_frame_energies( #define WMC_TOOL_SKIP void bit_allocation_second_fx2( - Word32 *Rk, - Word32 *Rk_sort, - Word16 BANDS, - const Word16 *band_width, - Word16 *k_sort, - Word16 *k_num, - const Word16 *p2a_flags, - const Word16 p2a_bands, - const Word16 *last_bitalloc, - const Word16 input_frame ) + Word32 *Rk, /* Q16 */ + Word32 *Rk_sort, /* Q16 */ + Word16 BANDS, /* Q0 */ + const Word16 *band_width, /* Q0 */ + Word16 *k_sort, /* Q0 */ + Word16 *k_num, /* Q0 */ + const Word16 *p2a_flags, /* Q0 */ + const Word16 p2a_bands, /* Q0 */ + const Word16 *last_bitalloc, /* Q0 */ + const Word16 input_frame /* Q0 */ +) { Word16 k, k2 = 0; Word16 ever_bits[BANDS_MAX], ever_sort[BANDS_MAX]; /*Q12 */ @@ -323,13 +324,18 @@ void bit_allocation_second_fx2( Word16 exp; Word16 tmp; Word32 L_tmp; + move16(); + move16(); + move16(); + move16(); + FOR( k = 0; k < BANDS; k++ ) { test(); test(); IF( ( ( sub( k_sort[k], sub( BANDS, p2a_bands ) ) >= 0 ) && ( sub( p2a_flags[k_sort[k]], 1 ) == 0 ) ) || - ( ( sub( k_sort[k], sub( BANDS, 2 ) ) >= 0 ) && ( sub( last_bitalloc[sub( k_sort[k], sub( BANDS, 2 ) )], 1 ) == 0 ) ) ) + ( ( sub( k_sort[k], ( BANDS - 2 ) ) >= 0 ) && ( sub( last_bitalloc[k_sort[k] - ( BANDS - 2 )], 1 ) == 0 ) ) ) { exp = norm_s( band_width[k_sort[k]] ); tmp = shl( band_width[k_sort[k]], exp ); /*Q(exp) */ @@ -339,7 +345,7 @@ void bit_allocation_second_fx2( ever_bits[k] = extract_l( L_shr( L_tmp, tmp ) ); /*Q12 */ if ( sub( ever_bits[k], rk_temp ) < 0 ) { - rk_temp = ever_bits[k]; + rk_temp = ever_bits[k]; /* Q12 */ k2 = k; move16(); move16(); @@ -364,7 +370,7 @@ void bit_allocation_second_fx2( move16(); IF( sub( ever_sort[k], ever_temp ) < 0 ) { - ever_temp = ever_sort[k]; + ever_temp = ever_sort[k]; /* Q12 */ move16(); k2 = k; move16(); @@ -381,7 +387,7 @@ void bit_allocation_second_fx2( { IF( sub( k_sort[k], sub( k_sort[k2], 1 ) ) == 0 ) { - k_num[1] = k; + k_num[1] = k; /* Q0 */ move16(); } } @@ -392,7 +398,7 @@ void bit_allocation_second_fx2( { IF( sub( k_sort[k], add( k_sort[k2], 1 ) ) == 0 ) { - k_num[1] = k; + k_num[1] = k; /* Q0 */ move16(); } } @@ -405,7 +411,7 @@ void bit_allocation_second_fx2( { IF( sub( k_sort[k], sub( k_sort[k2], 1 ) ) == 0 ) { - k_num[1] = k; + k_num[1] = k; /* Q0 */ move16(); } } @@ -416,7 +422,7 @@ void bit_allocation_second_fx2( { IF( sub( k_sort[k], add( k_sort[k2], 1 ) ) == 0 ) { - k_num[1] = k; + k_num[1] = k; /* Q0 */ move16(); } } diff --git a/lib_com/hq2_core_com_fx.c b/lib_com/hq2_core_com_fx.c index d24bb0d96..a05519387 100644 --- a/lib_com/hq2_core_com_fx.c +++ b/lib_com/hq2_core_com_fx.c @@ -122,7 +122,7 @@ void mdct_spectrum_denorm_fx( /*gamma = (float) sqrt (pow (2.0f, band_energy[k]) / Eyy); */ /* Pow part (pow(2.0f, band_energy) ) */ - L_temp = L_shr( L_band_energy[k], sub( SWB_BWE_LR_Qbe, 16 ) ); + L_temp = L_shr( L_band_energy[k], sub( SWB_BWE_LR_Qbe, 16 ) ); /* Q16 */ temp_lo_fx = L_Extract_lc( L_temp, &temp_hi_fx ); Qpow = sub( 14, temp_hi_fx ); pow_fx = extract_l( Pow2( 14, temp_lo_fx ) ); /* Qpow */ @@ -145,14 +145,14 @@ void mdct_spectrum_denorm_fx( L_temp = Sqrt_l( L_shr( L_deposit_h( temp_fx ), 1 ), &exp_norm ); L_temp = L_shr( L_temp, exp_norm ); Qgamma = sub( shr( Qgamma, 1 ), 1 ); - gamma_fx = round_fx( L_temp ); + gamma_fx = round_fx( L_temp ); /* Qgamma */ } ELSE { L_temp = Sqrt_l( L_deposit_h( temp_fx ), &exp_norm ); L_temp = L_shr( L_temp, exp_norm ); Qgamma = shr( Qgamma, 1 ); - gamma_fx = round_fx( L_temp ); + gamma_fx = round_fx( L_temp ); /* Qgamma */ } /* Adjust gamma based on pulse density (0 bit MSE gain estimator) */ @@ -160,12 +160,12 @@ void mdct_spectrum_denorm_fx( exp_normn = norm_s( npulses[k] ); exp_normn = sub( exp_normn, 1 ); exp_normd = norm_s( band_width[k] ); - pd_fx = div_s( shl( npulses[k], exp_normn ), shl( band_width[k], exp_normd ) ); + pd_fx = div_s( shl( npulses[k], exp_normn ), shl( band_width[k], exp_normd ) ); /* 15 + (exp_norm - exp_normd) */ Qpd = add( sub( exp_normn, exp_normd ), 15 ); #ifdef BASOP_NOGLOB - cond_fx = sub( shl_o( pd_fx, sub( 15, Qpd ), &Overflow ), pd_thresh_fx /*Q15*/ ); -#else /* BASOP_NOGLOB */ + cond_fx = sub( shl_o( pd_fx, sub( 15, Qpd ), &Overflow ), pd_thresh_fx /*Q15*/ ); /* Q15 */ +#else /* BASOP_NOGLOB */ cond_fx = sub( shl( pd_fx, sub( 15, Qpd ) ), pd_thresh_fx /*Q15*/ ); #endif Overflow = 0; @@ -190,7 +190,7 @@ void mdct_spectrum_denorm_fx( L_tmp = L_Comp( exp, frac ); /* Q16 */ /* Mult part */ - L_tmp = Mpy_32_16_1( L_tmp, ld_slope_fx ); + L_tmp = Mpy_32_16_1( L_tmp, ld_slope_fx ); /* Q16 */ /* Pow part */ temp_lo_fx = L_Extract_lc( L_tmp, &temp_hi_fx ); @@ -213,7 +213,7 @@ void mdct_spectrum_denorm_fx( { /*y2[i] = gamma * inp_vector[i]; */ L_tmp = L_mult( gamma_fx, (Word16) inp_vector[i] ); /* Qgamma+0+1=Qgamma+1 */ - L_y2[i] = L_shl( L_tmp, exp_shift ); + L_y2[i] = L_shl( L_tmp, exp_shift ); /* SWB_BWE_LR_Qs */ move32(); } } @@ -312,11 +312,11 @@ void mdct_spectrum_denorm_ivas_fx( exp_normn = norm_s( pow_fx ); exp_normn = sub( exp_normn, 1 ); exp_normd = norm_l( L_Eyy ); - temp_fx = div_s( shl( pow_fx, exp_normn ), extract_h( L_shl( L_Eyy, exp_normd ) ) ); + temp_fx = div_s( shl( pow_fx, exp_normn ), extract_h( L_shl( L_Eyy, exp_normd ) ) ); /* ((Qpow + exp_norm) - (QEyy + exp_normd)) + 31 */ Qdiv = add( sub( add( Qpow, exp_normn ), add( QEyy, exp_normd ) ), 31 ); exp_norm = norm_s( temp_fx ); - temp_fx = shl( temp_fx, exp_norm ); + temp_fx = shl( temp_fx, exp_norm ); /* Qdiv + exp_norm */ Qdiv = add( Qdiv, exp_norm ); /* Sqrt part sqrt(pow (2.0f, band_energy[i])/Eyy) */ @@ -341,12 +341,12 @@ void mdct_spectrum_denorm_ivas_fx( exp_normn = norm_s( npulses[k] ); exp_normn = sub( exp_normn, 1 ); exp_normd = norm_s( band_width[k] ); - pd_fx = div_s( shl( npulses[k], exp_normn ), shl( band_width[k], exp_normd ) ); + pd_fx = div_s( shl( npulses[k], exp_normn ), shl( band_width[k], exp_normd ) ); /* 15 + (exp_normn + exp_normd) */ Qpd = add( sub( exp_normn, exp_normd ), 15 ); #ifdef BASOP_NOGLOB - cond_fx = sub( shl_o( pd_fx, sub( 15, Qpd ), &Overflow ), pd_thresh_fx /*Q15*/ ); -#else /* BASOP_NOGLOB */ + cond_fx = sub( shl_o( pd_fx, sub( 15, Qpd ), &Overflow ), pd_thresh_fx /*Q15*/ ); /* Q15 */ +#else /* BASOP_NOGLOB */ cond_fx = sub( shl( pd_fx, sub( 15, Qpd ) ), pd_thresh_fx /*Q15*/ ); #endif Overflow = 0; @@ -363,7 +363,7 @@ void mdct_spectrum_denorm_ivas_fx( /* Log2 part */ exp_norm = norm_s( div_pd_fx ); - L_div_pd = L_deposit_h( shl( div_pd_fx, exp_norm ) ); + L_div_pd = L_deposit_h( shl( div_pd_fx, exp_norm ) ); /* Qdivpd + exp_norm + 16 */ Qdivpd = add( add( Qdivpd, exp_norm ), 16 ); frac = Log2_norm_lc( L_div_pd ); @@ -394,7 +394,7 @@ void mdct_spectrum_denorm_ivas_fx( { /*y2[i] = gamma * inp_vector[i]; */ L_tmp = L_mult( gamma_fx, extract_l( inp_vector[i] ) ); /* Qgamma+0+1=Qgamma+1 */ - L_y2[i] = L_shl( L_tmp, exp_shift ); + L_y2[i] = L_shl( L_tmp, exp_shift ); /* SWB_BWE_LR_Qs */ move32(); } } @@ -429,25 +429,26 @@ void mdct_spectrum_denorm_ivas_fx( /*==========================================================================*/ void hq2_core_configure_fx( - const Word16 frame_length, - const Word16 num_bits, - const Word16 is_transient, - Word16 *bands, - Word16 *length, - Word16 band_width[], - Word16 band_start[], - Word16 band_end[], - Word32 *L_qint, - Word16 *eref, - Word16 *bit_alloc_weight, - Word16 *gqlevs, - Word16 *Ngq, - Word16 *p2a_bands, - Word16 *p2a_th, - Word16 *pd_thresh, - Word16 *ld_slope, - Word16 *ni_coef, - Word32 L_bwe_br ) + const Word16 frame_length, /* Q0 */ + const Word16 num_bits, /* Q0 */ + const Word16 is_transient, /* Q0 */ + Word16 *bands, /* Q0 */ + Word16 *length, /* Q0 */ + Word16 band_width[], /* Q0 */ + Word16 band_start[], /* Q0 */ + Word16 band_end[], /* Q0 */ + Word32 *L_qint, /* Q13 */ + Word16 *eref, /* Q10 */ + Word16 *bit_alloc_weight, /* Q13 */ + Word16 *gqlevs, /* Q0 */ + Word16 *Ngq, /* Q0 */ + Word16 *p2a_bands, /* Q0 */ + Word16 *p2a_th, /* Q11 */ + Word16 *pd_thresh, /* Q15 */ + Word16 *ld_slope, /* Q15 */ + Word16 *ni_coef, /* Q14 */ + Word32 L_bwe_br /* Q0 */ +) { const Xcore_Config *xcore_config_fx; @@ -554,67 +555,67 @@ ELSE } } -*bands = xcore_config_fx->bands; +*bands = xcore_config_fx->bands; /* Q0 */ move16(); -*length = xcore_config_fx->bw; +*length = xcore_config_fx->bw; /* Q0 */ move16(); -*L_qint = xcore_config_fx->L_qint; +*L_qint = xcore_config_fx->L_qint; /* Q13 */ move32(); -*eref = xcore_config_fx->eref; +*eref = xcore_config_fx->eref; /* Q10 */ move16(); -*bit_alloc_weight = xcore_config_fx->bit_alloc_weight; +*bit_alloc_weight = xcore_config_fx->bit_alloc_weight; /* Q13 */ move16(); -*gqlevs = xcore_config_fx->gqlevs; +*gqlevs = xcore_config_fx->gqlevs; /* Q0 */ move16(); -*Ngq = xcore_config_fx->Ngq; +*Ngq = xcore_config_fx->Ngq; /* Q0 */ move16(); -*p2a_bands = xcore_config_fx->p2a_bands; +*p2a_bands = xcore_config_fx->p2a_bands; /* Q0 */ move16(); -*p2a_th = xcore_config_fx->p2a_th; +*p2a_th = xcore_config_fx->p2a_th; /* Q11 */ move16(); -*pd_thresh = xcore_config_fx->pd_thresh; +*pd_thresh = xcore_config_fx->pd_thresh; /* Q15 */ move16(); -*ld_slope = xcore_config_fx->ld_slope; +*ld_slope = xcore_config_fx->ld_slope; /* Q14 */ move16(); -*ni_coef = xcore_config_fx->ni_coef; +*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 ); +Copy( xcore_config_fx->band_width, band_width, *bands ); /* Q0 */ /* Expand band_width[] table for short windows */ IF( is_transient ) { - bands_sh = *bands; + bands_sh = *bands; /* Q0 */ move16(); - *bands = shl( bands_sh, 2 ); + *bands = shl( bands_sh, 2 ); /* Q0 */ move16(); - *length = shl( *length, 2 ); + *length = shl( *length, 2 ); /* Q0 */ move16(); FOR( i = 1; i <= 3; i++ ) { FOR( k = 0; k < bands_sh; k++ ) { - band_width[i * bands_sh + k] = band_width[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; +band_start[0] = 0; /* Q0 */ move16(); -band_end[0] = sub( band_width[0], 1 ); +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] ); + 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 ); + band_end[k] = sub( add( band_start[k], band_width[k] ), 1 ); /* Q0 */ move16(); } @@ -638,37 +639,37 @@ void reverse_transient_frame_energies_fx( Word16 bands_2, bands_4, bands_8; Word32 *p_be1, *p_be2; - bands_2 = shr( bands, 1 ); - bands_4 = shr( bands, 2 ); - bands_8 = shr( bands, 3 ); + bands_2 = shr( bands, 1 ); /* Q0 */ + bands_4 = shr( bands, 2 ); /* Q0 */ + bands_8 = shr( bands, 3 ); /* Q0 */ - k1 = bands_4; - k2 = sub( bands_2, 1 ); - p_be1 = &L_band_energy[k1]; - p_be2 = &L_band_energy[k2]; + k1 = bands_4; /* Q0 */ + k2 = sub( bands_2, 1 ); /* Q0 */ + p_be1 = &L_band_energy[k1]; /* Q14 */ + p_be2 = &L_band_energy[k2]; /* Q14 */ FOR( k = 0; k < bands_8; k++ ) { - L_be = *p_be1; + L_be = *p_be1; /* Q14 */ move32(); - *p_be1 = *p_be2; + *p_be1 = *p_be2; /* Q14 */ move32(); - *p_be2 = L_be; + *p_be2 = L_be; /* Q14 */ move32(); p_be1++; p_be2--; } - k1 = sub( bands, bands_4 ); /* 3*bands/4 */ - k2 = sub( bands, 1 ); - p_be1 = &L_band_energy[k1]; - p_be2 = &L_band_energy[k2]; + k1 = sub( bands, bands_4 ); /* 3*bands/4 Q0 */ + k2 = sub( bands, 1 ); /* Q0 */ + p_be1 = &L_band_energy[k1]; /* Q14 */ + p_be2 = &L_band_energy[k2]; /* Q14 */ FOR( k = 0; k < bands_8; k++ ) { - L_be = *p_be1; + L_be = *p_be1; /* Q14 */ move32(); - *p_be1 = *p_be2; + *p_be1 = *p_be2; /* Q14 */ move32(); - *p_be2 = L_be; + *p_be2 = L_be; /* Q14 */ move32(); p_be1++; p_be2--; @@ -685,14 +686,14 @@ void reverse_transient_frame_energies_fx( *--------------------------------------------------------------------------*/ void spt_shorten_domain_pre_fx( - const Word16 band_start[], /* i: Starting position of sub band */ - const Word16 band_end[], /* i: End position of sub band */ - const Word16 prev_SWB_peak_pos[], /* i: Spectral peak */ - const Word16 BANDS, /* i: total number of bands */ - const Word32 L_bwe_br, /* i: bitrate information */ - Word16 new_band_start[], /* o: Starting position of new shorten sub band */ - Word16 new_band_end[], /* o: End position of new shorten sub band */ - Word16 new_band_width[] /* o: new sub band bandwidth */ + const Word16 band_start[], /* i: Starting position of sub band Q0*/ + const Word16 band_end[], /* i: End position of sub band Q0*/ + const Word16 prev_SWB_peak_pos[], /* i: Spectral peak Q0*/ + const Word16 BANDS, /* i: total number of bands Q0*/ + const Word32 L_bwe_br, /* i: bitrate information Q0*/ + Word16 new_band_start[], /* o: Starting position of new shorten sub band Q0*/ + Word16 new_band_end[], /* o: End position of new shorten sub band Q0*/ + Word16 new_band_width[] /* o: new sub band bandwidth Q0*/ ) { Word16 j; @@ -702,60 +703,60 @@ void spt_shorten_domain_pre_fx( Word16 new_band_width_half; const Word16 *p_bw_SPT_tbl; /* pointer of bw_SPT_tbl */ - p_bw_SPT_tbl = bw_SPT_tbl[0]; + p_bw_SPT_tbl = bw_SPT_tbl[0]; /* Q0 */ if ( EQ_32( L_bwe_br, HQ_16k40 ) ) { - p_bw_SPT_tbl = bw_SPT_tbl[1]; + p_bw_SPT_tbl = bw_SPT_tbl[1]; /* Q0 */ } kpos = 0; move16(); j = 0; move16(); - FOR( k = sub( BANDS, SPT_SHORTEN_SBNUM ); k < BANDS; k++ ) + FOR( k = BANDS - SPT_SHORTEN_SBNUM; k < BANDS; k++ ) { IF( prev_SWB_peak_pos[kpos] != 0 ) { - new_band_width[j] = p_bw_SPT_tbl[j]; + new_band_width[j] = p_bw_SPT_tbl[j]; /* Q0 */ /*shorten the bandwidth for pulse resolution*/ - new_band_width_half = shr( new_band_width[j], 1 ); + new_band_width_half = shr( new_band_width[j], 1 ); /* Q0 */ move16(); - new_band_start[j] = sub( prev_SWB_peak_pos[kpos], new_band_width_half ); + new_band_start[j] = sub( prev_SWB_peak_pos[kpos], new_band_width_half ); /* Q0 */ move16(); - new_band_end[j] = add( prev_SWB_peak_pos[kpos], new_band_width_half ); + new_band_end[j] = add( prev_SWB_peak_pos[kpos], new_band_width_half ); /* Q0 */ move16(); IF( LT_16( new_band_start[j], band_start[k] ) ) { - new_band_start[j] = band_start[k]; + new_band_start[j] = band_start[k]; /* Q0 */ move16(); - new_band_end[j] = add( new_band_start[j], sub( new_band_width[j], 1 ) ); + new_band_end[j] = add( new_band_start[j], sub( new_band_width[j], 1 ) ); /* Q0 */ move16(); } ELSE IF( GT_16( new_band_end[j], band_end[k] ) ) { - new_band_end[j] = band_end[k]; + new_band_end[j] = band_end[k]; /* Q0 */ move16(); - new_band_start[j] = sub( new_band_end[j], sub( new_band_width[j], 1 ) ); + new_band_start[j] = sub( new_band_end[j], sub( new_band_width[j], 1 ) ); /* Q0 */ move16(); } } ELSE { - new_band_width[j] = p_bw_SPT_tbl[j]; + new_band_width[j] = p_bw_SPT_tbl[j]; /* Q0 */ /*shorten the bandwidth for pulse resolution*/ - new_band_width_half = shr( new_band_width[j], 1 ); + new_band_width_half = shr( new_band_width[j], 1 ); /* Q0 */ move16(); - new_band_start[j] = sub( shr( add( band_start[k], band_end[k] ), 1 ), new_band_width_half ); + new_band_start[j] = sub( shr( add( band_start[k], band_end[k] ), 1 ), new_band_width_half ); /* Q0 */ move16(); - new_band_end[j] = add( shr( add( band_start[k], band_end[k] ), 1 ), new_band_width_half ); + new_band_end[j] = add( shr( add( band_start[k], band_end[k] ), 1 ), new_band_width_half ); /* Q0 */ move16(); } - kpos = add( kpos, 1 ); - j = add( j, 1 ); + kpos++; + j++; } return; @@ -768,13 +769,13 @@ void spt_shorten_domain_pre_fx( *--------------------------------------------------------------------------*/ void spt_shorten_domain_band_save_fx( - const Word16 bands, /* i: total subband */ - const Word16 band_start[], /* i: starting position of subband */ - const Word16 band_end[], /* i: end position of subband */ - const Word16 band_width[], /* i: band width of subband */ - Word16 org_band_start[], /* o: starting position of subband */ - Word16 org_band_end[], /* o: end position of subband */ - Word16 org_band_width[] /* o: band width of subband */ + const Word16 bands, /* i: total subband Q0*/ + const Word16 band_start[], /* i: starting position of subband Q0*/ + const Word16 band_end[], /* i: end position of subband Q0*/ + const Word16 band_width[], /* i: band width of subband Q0*/ + Word16 org_band_start[], /* o: starting position of subband Q0*/ + Word16 org_band_end[], /* o: end position of subband Q0*/ + Word16 org_band_width[] /* o: band width of subband Q0*/ ) { Word16 k; @@ -782,15 +783,15 @@ void spt_shorten_domain_band_save_fx( kpos = 0; move16(); - FOR( k = sub( bands, SPT_SHORTEN_SBNUM ); k < bands; k++ ) + FOR( k = bands - SPT_SHORTEN_SBNUM; k < bands; k++ ) { - org_band_start[kpos] = band_start[k]; + org_band_start[kpos] = band_start[k]; /* Q0 */ move16(); - org_band_end[kpos] = band_end[k]; + org_band_end[kpos] = band_end[k]; /* Q0 */ move16(); - org_band_width[kpos] = band_width[k]; + org_band_width[kpos] = band_width[k]; /* Q0 */ move16(); - kpos = add( kpos, 1 ); + kpos++; } return; @@ -803,13 +804,13 @@ void spt_shorten_domain_band_save_fx( *--------------------------------------------------------------------------*/ void spt_shorten_domain_band_restore_fx( - const Word16 bands, /* i: total subband */ - Word16 band_start[], /* i/o: starting position of subband */ - Word16 band_end[], /* i/o: end position of subband */ - Word16 band_width[], /* i/o: band width of subband */ - const Word16 org_band_start[], /* o: starting position of subband */ - const Word16 org_band_end[], /* o: end position of subband */ - const Word16 org_band_width[] /* o: band width of subband */ + const Word16 bands, /* i: total subband Q0*/ + Word16 band_start[], /* i/o: starting position of subband Q0*/ + Word16 band_end[], /* i/o: end position of subband Q0*/ + Word16 band_width[], /* i/o: band width of subband Q0*/ + const Word16 org_band_start[], /* o: starting position of subband Q0*/ + const Word16 org_band_end[], /* o: end position of subband Q0*/ + const Word16 org_band_width[] /* o: band width of subband Q0*/ ) { Word16 k; @@ -817,15 +818,15 @@ void spt_shorten_domain_band_restore_fx( kpos = 0; move16(); - FOR( k = sub( bands, SPT_SHORTEN_SBNUM ); k < bands; k++ ) + FOR( k = bands - SPT_SHORTEN_SBNUM; k < bands; k++ ) { - band_start[k] = org_band_start[kpos]; + band_start[k] = org_band_start[kpos]; /* Q0 */ move16(); - band_end[k] = org_band_end[kpos]; + band_end[k] = org_band_end[kpos]; /* Q0 */ move16(); - band_width[k] = org_band_width[kpos]; + band_width[k] = org_band_width[kpos]; /* Q0 */ move16(); - kpos = add( kpos, 1 ); + kpos++; } return; @@ -838,11 +839,11 @@ void spt_shorten_domain_band_restore_fx( *--------------------------------------------------------------------------*/ void spt_swb_peakpos_tmp_save_fx( - const Word32 L_y2[], /* i: coded spectral information */ - const Word16 bands, /* i: total number of bands */ - const Word16 band_start[], /* i: starting position of subband */ - const Word16 band_end[], /* i: end position of subband */ - Word16 prev_SWB_peak_pos_tmp[] /* o: spectral peaks */ + const Word32 L_y2[], /* i: coded spectral information Qx*/ + const Word16 bands, /* i: total number of bands Q0*/ + const Word16 band_start[], /* i: starting position of subband Q0*/ + const Word16 band_end[], /* i: end position of subband Q0*/ + Word16 prev_SWB_peak_pos_tmp[] /* o: spectral peaks Q0*/ ) { @@ -852,7 +853,7 @@ void spt_swb_peakpos_tmp_save_fx( j = 0; move16(); - FOR( k = sub( bands, SPT_SHORTEN_SBNUM ); k < bands; k++ ) + FOR( k = bands - SPT_SHORTEN_SBNUM; k < bands; k++ ) { L_peak_max = L_deposit_l( 0 ); prev_SWB_peak_pos_tmp[j] = 0; @@ -863,13 +864,13 @@ void spt_swb_peakpos_tmp_save_fx( move32(); IF( LT_32( L_peak_max, L_abs_y2 ) ) { - L_peak_max = L_abs_y2; + L_peak_max = L_abs_y2; /* Qx */ move32(); - prev_SWB_peak_pos_tmp[j] = i; + prev_SWB_peak_pos_tmp[j] = i; /* Q0 */ move16(); } } - j = add( j, 1 ); + j++; } return; } @@ -877,16 +878,17 @@ void spt_swb_peakpos_tmp_save_fx( // already present need this one because appropriate and uses basops other than previous one. void bit_allocation_second_fx( - Word32 *Rk, - Word32 *Rk_sort, - Word16 BANDS, - const Word16 *band_width, - Word16 *k_sort, - Word16 *k_num, - const Word16 *p2a_flags, - const Word16 p2a_bands, - const Word16 *last_bitalloc, - const Word16 input_frame ) + Word32 *Rk, /* Q16 */ + Word32 *Rk_sort, /* Q16 */ + Word16 BANDS, /* Q0 */ + const Word16 *band_width, /* Q0 */ + Word16 *k_sort, /* Q0 */ + Word16 *k_num, /* Q0 */ + const Word16 *p2a_flags, /* Q0 */ + const Word16 p2a_bands, /* Q0 */ + const Word16 *last_bitalloc, /* Q0 */ + const Word16 input_frame /* Q0 */ +) { Word16 k, k2 = 0; move16(); @@ -906,7 +908,7 @@ void bit_allocation_second_fx( test(); test(); IF( ( ( GE_16( k_sort[k], sub( BANDS, p2a_bands ) ) ) && ( EQ_16( p2a_flags[k_sort[k]], 1 ) ) ) || - ( ( GE_16( k_sort[k], sub( BANDS, 2 ) ) ) && ( EQ_16( last_bitalloc[sub( k_sort[k], sub( BANDS, 2 ) )], 1 ) ) ) ) + ( ( GE_16( k_sort[k], ( BANDS - 2 ) ) ) && ( EQ_16( last_bitalloc[k_sort[k] - ( BANDS - 2 )], 1 ) ) ) ) { exp = norm_s( band_width[k_sort[k]] ); tmp = shl( band_width[k_sort[k]], exp ); /*Q(exp) */ @@ -916,7 +918,7 @@ void bit_allocation_second_fx( ever_bits[k] = extract_l( L_shr( L_tmp, tmp ) ); /*Q12 */ IF( LT_16( ever_bits[k], rk_temp ) ) { - rk_temp = ever_bits[k]; + rk_temp = ever_bits[k]; /* Q12 */ move16(); k2 = k; move16(); @@ -941,7 +943,7 @@ void bit_allocation_second_fx( ever_sort[k] = extract_l( L_shr( L_tmp, tmp ) ); /*Q12 */ IF( LT_16( ever_sort[k], ever_temp ) ) { - ever_temp = ever_sort[k]; + ever_temp = ever_sort[k]; /* Q12 */ move16(); k2 = k; move16(); @@ -950,7 +952,7 @@ void bit_allocation_second_fx( } } - k_num[0] = k2; + k_num[0] = k2; /* Q0 */ move16(); IF( EQ_16( k_sort[k2], sub( BANDS, 1 ) ) ) { @@ -958,7 +960,7 @@ void bit_allocation_second_fx( { if ( EQ_16( k_sort[k], sub( k_sort[k2], 1 ) ) ) { - k_num[1] = k; + k_num[1] = k; /* Q0 */ move16(); } } @@ -969,20 +971,20 @@ void bit_allocation_second_fx( { if ( EQ_16( k_sort[k], add( k_sort[k2], 1 ) ) ) { - k_num[1] = k; + k_num[1] = k; /* Q0 */ move16(); } } } ELSE { - IF( LT_32( Rk[sub( k_sort[k2], 1 )], Rk[add( k_sort[k2], 1 )] ) ) + IF( LT_32( Rk[k_sort[k2] - 1], Rk[k_sort[k2] + 1] ) ) { FOR( k = 0; k < BANDS; k++ ) { if ( EQ_16( k_sort[k], sub( k_sort[k2], 1 ) ) ) { - k_num[1] = k; + k_num[1] = k; /* Q0 */ move16(); } } @@ -993,7 +995,7 @@ void bit_allocation_second_fx( { if ( EQ_16( k_sort[k], add( k_sort[k2], 1 ) ) ) { - k_num[1] = k; + k_num[1] = k; /* Q0 */ move16(); } } diff --git a/lib_com/hq2_noise_inject_fx.c b/lib_com/hq2_noise_inject_fx.c index 223462df4..12bedd1fb 100644 --- a/lib_com/hq2_noise_inject_fx.c +++ b/lib_com/hq2_noise_inject_fx.c @@ -43,28 +43,29 @@ * HQ2 noise injection for WB signals *--------------------------------------------------------------------------*/ void hq2_noise_inject_fx( - Word32 L_y2[], - const Word16 band_start[], - const Word16 band_end[], - const Word16 band_width[], - Word32 Ep_fx[], - Word32 Rk_fx[], - const Word16 npulses[], - Word16 ni_seed, - const Word16 bands, - const Word16 ni_start_band, - const Word16 bw_low, - const Word16 bw_high, - const Word32 enerL_fx, - const Word32 enerH_fx, - Word32 last_ni_gain_fx[], - Word16 last_env_fx[], - Word16 *last_max_pos_pulse, - Word16 *p2a_flags, - Word16 p2a_bands, - const Word16 hqswb_clas, - const Word16 bwidth, - const Word32 bwe_br ) + Word32 L_y2[], /* Q12 */ + const Word16 band_start[], /* Q0 */ + const Word16 band_end[], /* Q0 */ + const Word16 band_width[], /* Q0 */ + Word32 Ep_fx[], /* Q-6 */ + Word32 Rk_fx[], /* QRk (Q16) */ + const Word16 npulses[], /* Q0 */ + Word16 ni_seed, /* Q0 */ + const Word16 bands, /* Q0 */ + const Word16 ni_start_band, /* Q0 */ + const Word16 bw_low, /* Q0 */ + const Word16 bw_high, /* Q0 */ + const Word32 enerL_fx, /* Q0 */ + const Word32 enerH_fx, /* Q0 */ + Word32 last_ni_gain_fx[], /* Q17 */ + Word16 last_env_fx[], /* Q1 */ + Word16 *last_max_pos_pulse, /* Q0 */ + Word16 *p2a_flags, /* Q0 */ + Word16 p2a_bands, /* Q0 */ + const Word16 hqswb_clas, /* Q0 */ + const Word16 bwidth, /* Q0 */ + const Word32 bwe_br /* Q0 */ +) { Word32 L_tmp, L_tmp2, L_tmp2x, L_tmp3, L_tmp1; Word16 exp, exp2, Q_speech; @@ -136,7 +137,7 @@ void hq2_noise_inject_fx( exp = norm_l( L_tmp ); tmp = extract_h( L_shl( L_tmp, exp ) ); - L_tmp3 = (Word32) band_width[k]; + L_tmp3 = (Word32) band_width[k]; /* Q0 */ move32(); exp2 = norm_l( L_tmp3 ); tmp2 = extract_h( L_shl( L_tmp3, exp2 ) ); @@ -152,8 +153,8 @@ void hq2_noise_inject_fx( { exp2 = add( exp2, 1 ); } - tmp = div_s( tmp2, tmp ); - L_tmp = L_deposit_h( tmp ); + tmp = div_s( tmp2, tmp ); /* Q15 */ + L_tmp = L_deposit_h( tmp ); /* Q31 */ L_tmp = Isqrt_lc( L_tmp, &exp2 ); env_fx[k] = L_tmp; move32(); /*Q(31-exp2) move32(); */ @@ -174,35 +175,35 @@ void hq2_noise_inject_fx( { FOR( i = band_start[k]; i <= band_end[k]; i++ ) { - L_tmp = L_mult0( y2hat_fx[i], y2hat_fx[i] ); /*0 */ + L_tmp = L_mult0( y2hat_fx[i], y2hat_fx[i] ); /* Q0 */ #ifdef BASOP_NOGLOB Ep_fx[k] = L_sub_o( Ep_fx[k], L_tmp, &Overflow ); #else /* BASOP_NOGLOB */ Ep_fx[k] = L_sub( Ep_fx[k], L_tmp ); #endif /* BASOP_NOGLOB */ - move32(); /*0 */ + move32(); /* Q0 */ IF( GT_16( abs_s( y2hat_fx[i] ), peak_fx[k] ) ) { peak_fx[k] = abs_s( y2hat_fx[i] ); - move16(); /*0 */ + move16(); /* Q0 */ } IF( y2hat_fx[i] != 0 ) { - count[k] = add( count[k], 1 ); + count[k] = add( count[k], 1 ); /* Q0 */ move16(); } } - max_pos_pulse = k; + max_pos_pulse = k; /* Q0 */ move16(); - L_tmp2 = Ep_fx[k]; + L_tmp2 = Ep_fx[k]; /* Q0 */ move32(); L_tmp = L_max( 1, L_tmp2 ); exp = norm_l( L_tmp ); tmp = extract_h( L_shl( L_tmp, exp ) ); - L_tmp3 = (Word32) band_width[k]; + L_tmp3 = (Word32) band_width[k]; /* Q0 */ exp2 = norm_l( L_tmp3 ); tmp2 = extract_h( L_shl( L_tmp3, exp2 ) ); @@ -217,8 +218,8 @@ void hq2_noise_inject_fx( { exp2 = add( exp2, 1 ); } - tmp = div_s( tmp2, tmp ); - L_tmp = L_deposit_h( tmp ); + tmp = div_s( tmp2, tmp ); /* Q15 */ + L_tmp = L_deposit_h( tmp ); /* Q31 */ L_tmp = Isqrt_lc( L_tmp, &exp2 ); Ep_fx[k] = L_tmp; move32(); /*Q(31-exp2) */ @@ -239,9 +240,9 @@ void hq2_noise_inject_fx( /* calculate the noise gain */ satur = 0; move16(); - if ( GE_16( pd_fx[k], 819 ) ) + if ( GE_16( pd_fx[k], 819 /* 0.8 in Q10 */ ) ) { - satur = 1; + satur = 1; /* Q0 */ move16(); } @@ -262,7 +263,7 @@ void hq2_noise_inject_fx( } ELSE { - tmp = 0x7fff; + tmp = 0x7fff; /* 1 in Q15 */ move16(); Q_speech = 0; move16(); @@ -274,10 +275,10 @@ void hq2_noise_inject_fx( IF( EQ_16( hqswb_clas, HQ_HARMONIC ) ) { - tmp = sub( 1536, pd_fx[k] ); /*Q10 */ - tmp3 = shl( tmp, 4 ); /*Q14 */ - L_tmp = Mult_32_16( env_fx[k], tmp3 ); /*Q(Q_env_fx[k]+14-15 = Q_env_fx[k]-1) */ - L_tmp = Mult_32_16( L_tmp, 6144 ); /*Q(Q_env_fx[k]-1+10-15 = Q_env_fx[k]-6) */ + tmp = sub( 1536 /* 1.5 in Q10 */, pd_fx[k] ); /*Q10 */ + tmp3 = shl( tmp, 4 ); /*Q14 */ + L_tmp = Mult_32_16( env_fx[k], tmp3 ); /*Q(Q_env_fx[k]+14-15 = Q_env_fx[k]-1) */ + L_tmp = Mult_32_16( L_tmp, 6144 /* 6.0f in Q10 */ ); /*Q(Q_env_fx[k]-1+10-15 = Q_env_fx[k]-6) */ IF( peak_fx[k] != 0 ) { @@ -287,7 +288,7 @@ void hq2_noise_inject_fx( } ELSE { - tmp = 0x7fff; + tmp = 0x7fff; /* 1 in Q15 */ move16(); Q_speech = 0; move16(); @@ -307,48 +308,48 @@ void hq2_noise_inject_fx( move16(); /*Q12 */ if ( GT_16( k, sb ) ) { - fac_fx = mult( 24576, tmp2 ); /*//Q(14+13-15=12) */ + fac_fx = mult( 24576 /* 1.5 in Q14 */, tmp2 ); /*//Q(14+13-15=12) */ } } ELSE { IF( LE_16( k, sb ) ) { - tmp = sub( 1536, pd_fx[k] ); /*Q10 */ + tmp = sub( 1536 /* 1.5 in Q10 */, pd_fx[k] ); /*Q10 */ tmp3 = shl( tmp, 4 ); /*Q14 */ L_tmp = Mult_32_16( L_tmp2x, tmp3 ); /*Q(Q_Ep_fx[k]-Q_speech+14+14-15 = Q_Ep_fx[k]-Q_speech+13) */ - L_tmp = Mult_32_16( L_tmp, 20480 ); /*Q(Q_Ep_fx[k]-Q_speech+13+12-15 = Q_Ep_fx[k]-Q_speech+10) */ + L_tmp = Mult_32_16( L_tmp, 20480 /* 5 in Q12 */ ); /*Q(Q_Ep_fx[k]-Q_speech+13+12-15 = Q_Ep_fx[k]-Q_speech+10) */ fac_fx = extract_h( L_shl( L_tmp, sub( add( 18, Q_speech ), Q_Ep_fx[k] ) ) ); /*Q_Ep_fx[k]-Q_speech+10 +18+Q_speech-Q_Ep_fx[k] -16 =12 */ } ELSE { - fac_fx = shl( mult( 32767, tmp2 ), 1 ); /*//Q(13+13-15+1=12) */ + fac_fx = shl( mult( 32767 /* 4.0f in Q13 */, tmp2 ), 1 ); /*//Q(13+13-15+1=12) */ } } } ELSE { fac_fx = 4505; - move16(); /*Q12 */ + move16(); /* 1.1 in Q12 */ } } ELSE { - tmp = sub( 1536, pd_fx[k] ); /*Q10 */ - tmp2 = s_min( 1024, tmp ); /*q10 */ - tmp2 = shl( tmp2, 4 ); /*Q14 */ - L_tmp = Mult_32_16( env_fx[k], tmp2 ); /*Q(Q_env_fx[k]+14-15 = Q_env_fx[k]-1) */ - L_tmp = Mult_32_16( L_tmp, 20480 ); /*Q(Q_env_fx[k]-1+10-15 = Q_env_fx[k]-6) */ + tmp = sub( 1536 /* 1.5 in Q10 */, pd_fx[k] ); /*Q10 */ + tmp2 = s_min( 1024 /* 1 in Q10 */, tmp ); /*q10 */ + tmp2 = shl( tmp2, 4 ); /*Q14 */ + L_tmp = Mult_32_16( env_fx[k], tmp2 ); /*Q(Q_env_fx[k]+14-15 = Q_env_fx[k]-1) */ + L_tmp = Mult_32_16( L_tmp, 20480 /* 20 in Q10 */ ); /*Q(Q_env_fx[k]-1+10-15 = Q_env_fx[k]-6) */ IF( peak_fx[k] != 0 ) { Q_speech = norm_s( peak_fx[k] ); - tmp = shl( peak_fx[k], Q_speech ); /*Q(Q_speech) */ - tmp = div_s( 16384, tmp ); /*Q(15+14-Q_speech) */ + tmp = shl( peak_fx[k], Q_speech ); /*Q(Q_speech) */ + tmp = div_s( 16384 /* 0.5f in Q15 */, tmp ); /*Q(15+14-Q_speech) */ } ELSE { - tmp = 0x7fff; + tmp = 0x7fff; /* 1 in Q15 */ move16(); Q_speech = 0; move16(); @@ -371,35 +372,35 @@ void hq2_noise_inject_fx( IF( env_fx2[k] != 0 ) { Q_speech = norm_s( env_fx2[k] ); - tmp = shl( env_fx2[k], Q_speech ); /*Q(Q_speech+1) */ - tmp = div_s( 16384, tmp ); /*Q(15+14-Q_speech-1=28-Q_speech) */ + tmp = shl( env_fx2[k], Q_speech ); /*Q(Q_speech+1) */ + tmp = div_s( 16384 /* 0.5 in Q15 */, tmp ); /*Q(15+14-Q_speech-1=28-Q_speech) */ Q_speech = sub( 28, Q_speech ); } ELSE { - tmp = 0x7fff; + tmp = 0x7fff; /* 1/0 in Q15 */ move16(); Q_speech = 0; move16(); } - tmp1 = mult( env_fx2[add( k, 1 )], 16384 ); /*Q(1+15-15=1) Q1 */ + tmp1 = mult( env_fx2[k + 1], 16384 /* 0.5 in Q15 */ ); /*Q(1+15-15=1) Q1 */ tmp2 = sub( env_fx2[k], tmp1 ); - tmp1 = mult( env_fx2[k], 16384 ); /*Q(1+15-15=1) Q1 */ - tmp3 = sub( tmp1, env_fx2[sub( k, 1 )] ); - tmp1 = mult( peak_fx[k], 16384 ); /*Q(0+15-15=0) Q0 */ + tmp1 = mult( env_fx2[k], 16384 /* 0.5 in Q15 */ ); /*Q(1+15-15=1) Q1 */ + tmp3 = sub( tmp1, env_fx2[k - 1] ); + tmp1 = mult( peak_fx[k], 16384 /* 0.5 in Q15 */ ); /*Q(0+15-15=0) Q0 */ tmp4 = sub( tmp1, shr( env_fx2[k], 1 ) ); test(); test(); test(); - IF( count[add( k, 1 )] == 0 && tmp2 > 0 && tmp3 < 0 ) + IF( count[k + 1] == 0 && tmp2 > 0 && tmp3 < 0 ) { - L_tmp = L_mult( env_fx2[add( k, 1 )], tmp ); /* Q(1+Q_speech+1 = Q_speech+2) */ - L_tmp = Mult_32_16( L_tmp, 24576 ); /*Q(Q_speech+2+14-15=Q_speech+1) */ + L_tmp = L_mult( env_fx2[k + 1], tmp ); /* Q(1+Q_speech+1 = Q_speech+2) */ + L_tmp = Mult_32_16( L_tmp, 24576 /* 1.5 in Q14 */ ); /*Q(Q_speech+2+14-15=Q_speech+1) */ fac_fx = extract_h( L_shl( L_tmp, sub( 27, Q_speech ) ) ); /*Q12 */ } - ELSE IF( count[sub( k, 1 )] == 0 && tmp4 > 0 ) + ELSE IF( count[k - 1] == 0 && tmp4 > 0 ) { - L_tmp = L_mult( env_fx2[sub( k, 1 )], tmp ); /* Q(1+Q_speech+1 = Q_speech+2) */ + L_tmp = L_mult( env_fx2[k - 1], tmp ); /* Q(1+Q_speech+1 = Q_speech+2) */ #ifdef BASOP_NOGLOB fac_fx = extract_h( L_shl_o( L_tmp, sub( 26, Q_speech ), &Overflow ) ); /*Q12 */ #else @@ -414,7 +415,7 @@ void hq2_noise_inject_fx( L_tmp = Mult_32_16( enerH_fx, bw_low ); L_tmp2 = Mult_32_16( enerL_fx, bw_high ); L_tmp = L_sub( L_tmp, L_tmp2 ); - tmp1 = mult( peak_fx[k], 16384 ); /*Q(0+15-15=0) Q0 */ + tmp1 = mult( peak_fx[k], 16384 /* 0.5 in Q15 */ ); /*Q(0+15-15=0) Q0 */ tmp4 = sub( tmp1, shr( env_fx2[k], 1 ) ); test(); IF( L_tmp > 0 && tmp4 < 0 ) @@ -422,12 +423,12 @@ void hq2_noise_inject_fx( IF( peak_fx[k] != 0 ) { Q_speech = norm_s( peak_fx[k] ); - tmp = shl( peak_fx[k], Q_speech ); /*Q(Q_speech) */ - tmp = div_s( 16384, tmp ); /*Q(15+14-Q_speech) */ + tmp = shl( peak_fx[k], Q_speech ); /*Q(Q_speech) */ + tmp = div_s( 16384 /* 0.5 in Q15 */, tmp ); /*Q(15+14-Q_speech) */ } ELSE { - tmp = 0x7fff; + tmp = 0x7fff; /* 1.0f in Q15 */ move16(); Q_speech = 0; move16(); @@ -436,7 +437,7 @@ void hq2_noise_inject_fx( tmp = sub( Q_Ep_fx[k], Q_speech ); tmp = add( tmp, 1 ); tmp = extract_l( L_shr( L_tmp2, tmp ) ); /*Q13 */ - tmp = sub( 16384, tmp ); /*Q13 */ + tmp = sub( 16384 /* 2 in Q13 */, tmp ); /*Q13 */ fac_fx = extract_h( L_shl( L_mult( fac_fx, tmp ), 2 ) ); /*Q12*/ } @@ -447,9 +448,9 @@ void hq2_noise_inject_fx( tmp = extract_h( L_shl( L_tmp2, Q_speech ) ); /*Q(Q_Ep_fx[k]-3+Q_speech-16 = Q_Ep_fx[k]+Q_speech-19) */ IF( tmp != 0 ) { - tmp = div_s( 16384, tmp ); /*Q(15+14-Q_Ep_fx[k]-Q_speech+19 = 48-Q_Ep_fx[k]-Q_speech) */ - L_tmp2 = Mult_32_16( env_fx[k], tmp ); /*Q(Q_env_fx[k]+48-Q_Ep_fx[k]-Q_speech-15 = Q_env_fx[k]-Q_Ep_fx[k]-Q_speech+33) */ - L_tmp2 = Mult_32_16( L_tmp2, 20480 ); /*Q(Q_env_fx[k]-Q_Ep_fx[k]-Q_speech+33+14-15 = Q_env_fx[k]-Q_Ep_fx[k]-Q_speech+32) */ + tmp = div_s( 16384 /* 0.5 in Q15 */, tmp ); /*Q(15+14-Q_Ep_fx[k]-Q_speech+19 = 48-Q_Ep_fx[k]-Q_speech) */ + L_tmp2 = Mult_32_16( env_fx[k], tmp ); /*Q(Q_env_fx[k]+48-Q_Ep_fx[k]-Q_speech-15 = Q_env_fx[k]-Q_Ep_fx[k]-Q_speech+33) */ + L_tmp2 = Mult_32_16( L_tmp2, 20480 /* 1.25 in Q14 */ ); /*Q(Q_env_fx[k]-Q_Ep_fx[k]-Q_speech+33+14-15 = Q_env_fx[k]-Q_Ep_fx[k]-Q_speech+32) */ tmp = sub( Q_env_fx[k], Q_Ep_fx[k] ); tmp = sub( tmp, Q_speech ); tmp = add( tmp, 25 ); @@ -458,22 +459,22 @@ void hq2_noise_inject_fx( #else L_tmp = L_shr( L_tmp2, tmp ); /*Q7 */ #endif - tmp = extract_l( L_min( L_tmp, 192 ) ); /* */ + tmp = extract_l( L_min( L_tmp, 192 /* 1.5 in Q7 */ ) ); /* */ fac_fx = extract_h( L_shl( L_mult( fac_fx, tmp ), 8 ) ); /*Q12 */ } ELSE { - tmp = 0x7fff; /*Q0 */ - L_tmp2 = Mult_32_16( env_fx[k], tmp ); /*Q(Q_env_fx[k]+0-15 = Q_env_fx[k]-15) */ - L_tmp2 = Mult_32_16( L_tmp2, 20480 ); /*Q(Q_env_fx[k]-15+14-15 = Q_env_fx[k]-16) */ + tmp = 0x7fff; /*Q0 */ + L_tmp2 = Mult_32_16( env_fx[k], tmp ); /*Q(Q_env_fx[k]+0-15 = Q_env_fx[k]-15) */ + L_tmp2 = Mult_32_16( L_tmp2, 20480 /* 1.25 in Q14 */ ); /*Q(Q_env_fx[k]-15+14-15 = Q_env_fx[k]-16) */ tmp = sub( Q_env_fx[k], 23 ); #ifdef BASOP_NOGLOB L_tmp = L_shr_sat( L_tmp2, tmp ); /*Q7 */ #else L_tmp = L_shr( L_tmp2, tmp ); /*Q7 */ #endif - tmp = extract_l( ( L_min( L_tmp, 192 ) ) ); /* */ - fac_fx = extract_h( L_shl( L_mult( fac_fx, tmp ), 8 ) ); /*Q12 */ + tmp = extract_l( ( L_min( L_tmp, 192 /* 1.5 in Q7 */ ) ) ); /* Q7 */ + fac_fx = extract_h( L_shl( L_mult( fac_fx, tmp ), 8 ) ); /*Q12 */ } } } @@ -481,12 +482,12 @@ void hq2_noise_inject_fx( } ELSE { - fac_fx = 4505; + fac_fx = 4505; /* 1.1 in Q12 */ move16(); test(); if ( EQ_16( hqswb_clas, HQ_HARMONIC ) && EQ_16( bwidth, SWB ) ) { - fac_fx = 3277; + fac_fx = 3277; /* 0.8 in Q12 */ move16(); } } @@ -505,11 +506,11 @@ void hq2_noise_inject_fx( } /* smooth the noise gain between the current frame and the previous frame */ - pos = s_max( max_pos_pulse, *last_max_pos_pulse ); + pos = s_max( max_pos_pulse, *last_max_pos_pulse ); /* Q0 */ move16(); if ( EQ_16( bwidth, SWB ) ) { - pos = sub( ni_end_band, 1 ); + pos = sub( ni_end_band, 1 ); /* Q0 */ move16(); } @@ -518,18 +519,18 @@ void hq2_noise_inject_fx( test(); IF( k > 0 && LT_16( sub( k, ni_end_band ), -1 ) ) { - tmp1 = mult( last_env_fx[k], 16384 ); /*Q(1+15-15=1) Q1 */ - tmp2 = sub( env_fx2[k], tmp1 ); /*>0 */ - tmp1 = mult( env_fx2[k], 16384 ); /*Q(1+15-15=1) Q1 */ - tmp3 = sub( tmp1, last_env_fx[k] ); /*<0 */ - L_tmp = L_add( (Word32) env_fx2[k], (Word32) env_fx2[sub( k, 1 )] ); - L_tmp = L_add( L_tmp, (Word32) env_fx2[add( k, 1 )] ); /*Q1 */ - L_tmp1 = L_add( (Word32) last_env_fx[k], (Word32) last_env_fx[sub( k, 1 )] ); - L_tmp1 = L_add( L_tmp1, (Word32) last_env_fx[add( k, 1 )] ); /*Q1 */ - L_tmp2 = Mult_32_16( L_tmp1, 16384 ); /*Q(1+15-15) Q1 */ - L_tmp2 = L_sub( L_tmp, L_tmp2 ); /*>0 */ - L_tmp3 = Mult_32_16( L_tmp, 16384 ); /*Q(1+15-15) Q1 */ - L_tmp3 = L_sub( L_tmp3, L_tmp1 ); /*<0 */ + tmp1 = mult( last_env_fx[k], 16384 /* 0.5 in Q15 */ ); /*Q(1+15-15=1) Q1 */ + tmp2 = sub( env_fx2[k], tmp1 ); /* Q1 */ + tmp1 = mult( env_fx2[k], 16384 /* 0.5 in Q15 */ ); /*Q(1+15-15=1) Q1 */ + tmp3 = sub( tmp1, last_env_fx[k] ); /* Q1 */ + L_tmp = L_add( (Word32) env_fx2[k], (Word32) env_fx2[k - 1] ); /* Q1 */ + L_tmp = L_add( L_tmp, (Word32) env_fx2[k + 1] ); /*Q1 */ + L_tmp1 = L_add( (Word32) last_env_fx[k], (Word32) last_env_fx[k - 1] ); /* Q1 */ + L_tmp1 = L_add( L_tmp1, (Word32) last_env_fx[k + 1] ); /*Q1 */ + L_tmp2 = Mult_32_16( L_tmp1, 16384 /* 0.5 in Q15 */ ); /*Q(1+15-15) Q1 */ + L_tmp2 = L_sub( L_tmp, L_tmp2 ); /*Q1 */ + L_tmp3 = Mult_32_16( L_tmp, 16384 /* 0.5 in Q15 */ ); /*Q(1+15-15) Q1 */ + L_tmp3 = L_sub( L_tmp3, L_tmp1 ); /*Q1 */ test(); test(); test(); @@ -537,32 +538,32 @@ void hq2_noise_inject_fx( { IF( GT_32( ni_gain_fx[k], last_ni_gain_fx[k] ) ) { - L_tmp = Mult_32_16( ni_gain_fx[k], 6554 ); /*Q(17+15-15 = 17) */ - L_tmp1 = Mult_32_16( last_ni_gain_fx[k], 26214 ); /*Q17 */ - ni_gain_fx[k] = L_add( L_tmp, L_tmp1 ); + L_tmp = Mult_32_16( ni_gain_fx[k], 6554 /* 0.2 in Q15 */ ); /*Q(17+15-15 = 17) */ + L_tmp1 = Mult_32_16( last_ni_gain_fx[k], 26214 /* 0.8 in Q15 */ ); /*Q17 */ + ni_gain_fx[k] = L_add( L_tmp, L_tmp1 ); /* Q17 */ move32(); } ELSE { - L_tmp = Mult_32_16( ni_gain_fx[k], 19661 ); /*Q(17+15-15 = 17) */ - L_tmp1 = Mult_32_16( last_ni_gain_fx[k], 13107 ); /*Q17 */ - ni_gain_fx[k] = L_add( L_tmp, L_tmp1 ); + L_tmp = Mult_32_16( ni_gain_fx[k], 19661 /* 0.6 in Q15 */ ); /*Q(17+15-15 = 17) */ + L_tmp1 = Mult_32_16( last_ni_gain_fx[k], 13107 /* 0.4 in Q15 */ ); /*Q17 */ + ni_gain_fx[k] = L_add( L_tmp, L_tmp1 ); /* Q17 */ move32(); } } } ELSE IF( add( sub( k, ni_end_band ), 1 ) == 0 ) { - tmp1 = mult( last_env_fx[k], 16384 ); /*Q(1+15-15=1) Q1 */ - tmp2 = sub( env_fx2[k], tmp1 ); /*>0 */ - tmp1 = mult( env_fx2[k], 16384 ); /*Q(1+15-15=1) Q1 */ - tmp3 = sub( tmp1, last_env_fx[k] ); /*<0 */ - L_tmp = L_add( (Word32) env_fx2[k], (Word32) env_fx2[sub( k, 1 )] ); /*Q1 */ - L_tmp1 = L_add( (Word32) last_env_fx[k], (Word32) last_env_fx[sub( k, 1 )] ); /*Q1 */ - L_tmp2 = Mult_32_16( L_tmp1, 16384 ); /*Q(1+15-15) Q1 */ - L_tmp2 = L_sub( L_tmp, L_tmp2 ); /*>0 */ - L_tmp3 = Mult_32_16( L_tmp, 16384 ); /*Q(1+15-15) Q1 */ - L_tmp3 = L_sub( L_tmp3, L_tmp1 ); /*<0 */ + tmp1 = mult( last_env_fx[k], 16384 /* 0.5 in Q15 */ ); /*Q(1+15-15=1) Q1 */ + tmp2 = sub( env_fx2[k], tmp1 ); /*Q1 */ + tmp1 = mult( env_fx2[k], 16384 /* 0.5 in Q15 */ ); /*Q(1+15-15=1) Q1 */ + tmp3 = sub( tmp1, last_env_fx[k] ); /*Q1 */ + L_tmp = L_add( (Word32) env_fx2[k], (Word32) env_fx2[k - 1] ); /*Q1 */ + L_tmp1 = L_add( (Word32) last_env_fx[k], (Word32) last_env_fx[k - 1] ); /*Q1 */ + L_tmp2 = Mult_32_16( L_tmp1, 16384 /* 0.5 in Q15 */ ); /*Q(1+15-15) Q1 */ + L_tmp2 = L_sub( L_tmp, L_tmp2 ); /*Q1 */ + L_tmp3 = Mult_32_16( L_tmp, 16384 /* 0.5 in Q15 */ ); /*Q(1+15-15) Q1 */ + L_tmp3 = L_sub( L_tmp3, L_tmp1 ); /*Q1 */ test(); test(); @@ -571,16 +572,16 @@ void hq2_noise_inject_fx( { IF( GT_32( ni_gain_fx[k], last_ni_gain_fx[k] ) ) { - L_tmp = Mult_32_16( ni_gain_fx[k], 6554 ); /*Q(17+15-15 = 17) */ - L_tmp1 = Mult_32_16( last_ni_gain_fx[k], 26214 ); /*Q17 */ - ni_gain_fx[k] = L_add( L_tmp, L_tmp1 ); + L_tmp = Mult_32_16( ni_gain_fx[k], 6554 /* 0.2 in Q15 */ ); /*Q(17+15-15 = 17) */ + L_tmp1 = Mult_32_16( last_ni_gain_fx[k], 26214 /* 0.8 in Q15 */ ); /*Q17 */ + ni_gain_fx[k] = L_add( L_tmp, L_tmp1 ); /* Q17 */ move32(); } ELSE { - L_tmp = Mult_32_16( ni_gain_fx[k], 19661 ); /*Q(17+15-15 = 17) */ - L_tmp1 = Mult_32_16( last_ni_gain_fx[k], 13107 ); /*Q17 */ - ni_gain_fx[k] = L_add( L_tmp, L_tmp1 ); + L_tmp = Mult_32_16( ni_gain_fx[k], 19661 /* 0.6 in Q15 */ ); /*Q(17+15-15 = 17) */ + L_tmp1 = Mult_32_16( last_ni_gain_fx[k], 13107 /* 0.4 in Q15 */ ); /*Q17 */ + ni_gain_fx[k] = L_add( L_tmp, L_tmp1 ); /* Q17 */ move32(); } } @@ -596,7 +597,7 @@ void hq2_noise_inject_fx( { IF( L_y2[i] != 0 ) { - L_y2[i] = Mult_32_16( L_y2[i], 26215 ); + L_y2[i] = Mult_32_16( L_y2[i], 26215 /* 0.8 in Q15 */ ); move32(); /*Q(12+15-15=12) */ } } @@ -614,8 +615,8 @@ void hq2_noise_inject_fx( tmp = extract_h( L_shl( ni_gain_fx[k], Q_speech ) ); /*Q(Q_speech+1) */ IF( tmp != 0 ) { - tmp = div_s( 16384, tmp ); /*Q(15+14-Q_speech-1 = 28-Q_speech) */ - L_tmp = Mult_32_16( Ep_fx[k], tmp ); /*Q(Q_Ep_fx[k]+28-Q_speech-15 = Q_Ep_fx[k]+13-Q_speech) */ + tmp = div_s( 16384 /* 0.5 in Q15 */, tmp ); /*Q(15+14-Q_speech-1 = 28-Q_speech) */ + L_tmp = Mult_32_16( Ep_fx[k], tmp ); /*Q(Q_Ep_fx[k]+28-Q_speech-15 = Q_Ep_fx[k]+13-Q_speech) */ tmp = sub( Q_Ep_fx[k], Q_speech ); tmp = sub( 15, tmp ); #ifdef BASOP_NOGLOB @@ -635,7 +636,7 @@ void hq2_noise_inject_fx( tmp = extract_h( L_shl( L_tmp, tmp ) ); /*Q12 */ #endif } - fac_fx = s_max( tmp, 4096 ); /*Q12 */ + fac_fx = s_max( tmp, 4096 /* 1 in Q12 */ ); /*Q12 */ FOR( i = band_start[k]; i <= band_end[k]; i++ ) { @@ -650,7 +651,7 @@ void hq2_noise_inject_fx( #else tmp = shl( band_width[k], Q_speech ); /*Q(Q_speech) */ #endif - tmp = div_s( 16384, tmp ); /*Q(15+14-Q_speech) */ + tmp = div_s( 16384 /* 0.5 in Q15 */, tmp ); /*Q(15+14-Q_speech) */ } ELSE { @@ -659,9 +660,9 @@ void hq2_noise_inject_fx( move16(); move16(); } - tmp1 = sub( fac_fx, 4096 ); /*Q12 */ - L_tmp = L_mult( tmp1, j ); /*Q13 */ - L_tmp = Mult_32_16( L_tmp, tmp ); /*Q(13+29-Q_speech-15 = 27-Q_speech) */ + tmp1 = sub( fac_fx, 4096 /* 1 in Q12 */ ); /*Q12 */ + L_tmp = L_mult( tmp1, j ); /*Q13 */ + L_tmp = Mult_32_16( L_tmp, tmp ); /*Q(13+29-Q_speech-15 = 27-Q_speech) */ #ifdef BASOP_NOGLOB tmp = extract_h( L_shl_o( L_tmp, add( 1, Q_speech ), &Overflow ) ); /*Q12 */ #else @@ -691,7 +692,7 @@ void hq2_noise_inject_fx( } Copy( env_fx2, last_env_fx, ni_end_band ); - Copy32( ni_gain_fx, last_ni_gain_fx, ni_end_band ); + Copy32( ni_gain_fx, last_ni_gain_fx, ni_end_band ); /* Q17 */ *last_max_pos_pulse = max_pos_pulse; move16(); return; diff --git a/lib_com/hq_bit_allocation_fx.c b/lib_com/hq_bit_allocation_fx.c index e03fec40b..c3fc6a3a5 100644 --- a/lib_com/hq_bit_allocation_fx.c +++ b/lib_com/hq_bit_allocation_fx.c @@ -22,7 +22,7 @@ void ivas_hq_bit_allocation_fx( const Word16 *normqlg2, /* i : Quantized norms Q0 */ const Word16 nb_sfm, /* i : Number sub bands to be encoded Q0 */ const Word16 *sfmsize, /* i : Sub band bandwidths Q0 */ - Word16 *noise_level, /* o : HVQ noise level */ + Word16 *noise_level, /* o : HVQ noise level Q15 */ Word16 *R, /* o : Bit allocation per sub band Q0 */ Word16 *Rsubband, /* o : Fractional bit allocation Q3 */ Word16 *sum, /* o : Sum of allocated shape bits Q0 */ @@ -56,7 +56,7 @@ void ivas_hq_bit_allocation_fx( IF( NE_16( hqswb_clas, HQ_TRANSIENT ) && NE_16( hqswb_clas, HQ_HVQ ) && !( EQ_16( length, L_FRAME16k ) && LE_32( core_brate, HQ_32k ) ) ) { /* 'nf_idx' 2-bits index written later */ - *num_bits = sub( *num_bits, 2 ); + *num_bits = sub( *num_bits, 2 ); /*Q0*/ move16(); } @@ -65,17 +65,17 @@ void ivas_hq_bit_allocation_fx( { IF( GE_32( core_brate, HQ_32k ) ) { - *num_bits = sub( *num_bits, HQ_GENERIC_SWB_NBITS2 ); + *num_bits = sub( *num_bits, HQ_GENERIC_SWB_NBITS2 ); /*Q0*/ } ELSE { - *num_bits = sub( *num_bits, HQ_GENERIC_SWB_NBITS ); + *num_bits = sub( *num_bits, HQ_GENERIC_SWB_NBITS ); /*Q0*/ } move16(); IF( EQ_16( length, L_SPEC48k ) ) { - *num_bits = sub( *num_bits, HQ_GENERIC_FB_NBITS ); + *num_bits = sub( *num_bits, HQ_GENERIC_FB_NBITS ); /*Q0*/ move16(); } } @@ -235,7 +235,7 @@ void hq_bit_allocation_fx( const Word16 *normqlg2, /* i : Quantized norms Q0 */ const Word16 nb_sfm, /* i : Number sub bands to be encoded Q0 */ const Word16 *sfmsize, /* i : Sub band bandwidths Q0 */ - Word16 *noise_level, /* o : HVQ noise level */ + Word16 *noise_level, /* o : HVQ noise level Q15 */ Word16 *R, /* o : Bit allocation per sub band Q0 */ Word16 *Rsubband, /* o : Fractional bit allocation Q3 */ Word16 *sum, /* o : Sum of allocated shape bits Q0 */ @@ -293,6 +293,8 @@ void hq_bit_allocation_fx( } } + test(); + test(); IF( ( EQ_16( length, L_FRAME48k ) ) && ( NE_16( hqswb_clas, HQ_HARMONIC ) ) && ( NE_16( hqswb_clas, HQ_HVQ ) ) ) { tmp = 0; diff --git a/lib_com/hq_conf.c b/lib_com/hq_conf.c index 6c2b60c99..e99e89ba7 100644 --- a/lib_com/hq_conf.c +++ b/lib_com/hq_conf.c @@ -287,14 +287,10 @@ void hq_configure_fx( { *num_sfm = NB_SFM; move16(); - p_sfmsize = band_len_HQ; - move16(); - p_sfm_start = band_start_HQ; - move16(); - p_sfm_end = band_end_HQ; - move16(); + p_sfmsize = band_len_HQ; /* Q0 */ + p_sfm_start = band_start_HQ; /* Q0 */ + p_sfm_end = band_end_HQ; /* Q0 */ - test(); IF( GE_32( core_brate, HQ_32k ) ) { *hq_generic_offset = HQ_GENERIC_FOFFSET_32K; @@ -323,12 +319,9 @@ void hq_configure_fx( *num_env_bands = SFM_N_HARM_FB; move16(); - p_sfmsize = band_len_harm; - move16(); - p_sfm_start = band_start_harm; - move16(); - p_sfm_end = band_end_harm; - move16(); + p_sfmsize = band_len_harm; /* Q0 */ + p_sfm_start = band_start_harm; /* Q0 */ + p_sfm_end = band_end_harm; /* Q0 */ } ELSE IF( EQ_16( hqswb_clas, HQ_HVQ ) ) { @@ -354,28 +347,22 @@ void hq_configure_fx( *start_norm = HVQ_THRES_SFM_32k; move16(); } - p_sfmsize = band_len_harm; - p_sfm_start = band_start_harm; - p_sfm_end = band_end_harm; - move16(); - move16(); - move16(); + p_sfmsize = band_len_harm; /* Q0 */ + p_sfm_start = band_start_harm; /* Q0 */ + p_sfm_end = band_end_harm; /* Q0 */ } ELSE { *num_sfm = NB_SFM; move16(); - *nb_sfm = *num_sfm; + *nb_sfm = *num_sfm; /* Q0 */ move16(); *num_env_bands = NB_SFM; move16(); - p_sfmsize = band_len_HQ; - move16(); - p_sfm_start = band_start_HQ; - move16(); - p_sfm_end = band_end_HQ; - move16(); + p_sfmsize = band_len_HQ; /* Q0 */ + p_sfm_start = band_start_HQ; /* Q0 */ + p_sfm_end = band_end_HQ; /* Q0 */ } } } @@ -390,12 +377,9 @@ void hq_configure_fx( *num_env_bands = SFM_N_HARM; move16(); - p_sfmsize = band_len_harm; - move16(); - p_sfm_start = band_start_harm; - move16(); - p_sfm_end = band_end_harm; - move16(); + p_sfmsize = band_len_harm; /* Q0 */ + p_sfm_start = band_start_harm; /* Q0 */ + p_sfm_end = band_end_harm; /* Q0 */ } ELSE IF( EQ_16( hqswb_clas, HQ_HVQ ) ) { @@ -405,7 +389,7 @@ void hq_configure_fx( move16(); *nb_sfm = HVQ_THRES_SFM_24k; move16(); - *num_env_bands = sub( *num_sfm, *nb_sfm ); + *num_env_bands = sub( *num_sfm, *nb_sfm ); /* Q0 */ move16(); *start_norm = HVQ_THRES_SFM_24k; @@ -417,29 +401,23 @@ void hq_configure_fx( move16(); *nb_sfm = HVQ_THRES_SFM_32k; move16(); - *num_env_bands = sub( *num_sfm, *nb_sfm ); + *num_env_bands = sub( *num_sfm, *nb_sfm ); /* Q0 */ move16(); *start_norm = HVQ_THRES_SFM_32k; move16(); } p_sfmsize = band_len_harm; - move16(); p_sfm_start = band_start_harm; - move16(); p_sfm_end = band_end_harm; - move16(); } ELSE IF( EQ_16( hqswb_clas, HQ_GEN_SWB ) ) { *num_sfm = SFM_N_SWB; move16(); - p_sfmsize = band_len_HQ; - move16(); - p_sfm_start = band_start_HQ; - move16(); - p_sfm_end = band_end_HQ; - move16(); + p_sfmsize = band_len_HQ; /* Q0 */ + p_sfm_start = band_start_HQ; /* Q0 */ + p_sfm_end = band_end_HQ; /* Q0 */ IF( GE_32( core_brate, HQ_32k ) ) { @@ -469,70 +447,58 @@ void hq_configure_fx( *num_env_bands = SFM_N_SWB; move16(); - p_sfmsize = band_len_HQ; - move16(); - p_sfm_start = band_start_HQ; - move16(); - p_sfm_end = band_end_HQ; - move16(); + p_sfmsize = band_len_HQ; /* Q0 */ + p_sfm_start = band_start_HQ; /* Q0 */ + p_sfm_end = band_end_HQ; /* Q0 */ } } ELSE IF( EQ_16( length, L_SPEC48k_EXT ) ) { bw_ext = 1; - p_sfmsize = band_len_HQ; - p_sfm_start = band_start_HQ; - p_sfm_end = band_end_HQ; + p_sfmsize = band_len_HQ; /* Q0 */ + p_sfm_start = band_start_HQ; /* Q0 */ + p_sfm_end = band_end_HQ; /* Q0 */ *num_sfm = NB_SFM; - move16(); - move16(); - move16(); - move16(); } ELSE IF( EQ_16( length, L_SPEC16k_EXT ) ) { bw_ext = 1; - p_sfmsize = band_len_wb; - p_sfm_start = band_start_wb; - p_sfm_end = band_end_wb; - *num_sfm = SFM_N_WB; - move16(); - move16(); move16(); + p_sfmsize = band_len_wb; /* Q0 */ + p_sfm_start = band_start_wb; /* Q0 */ + p_sfm_end = band_end_wb; /* Q0 */ + *num_sfm = SFM_N_WB; move16(); } ELSE { *num_sfm = SFM_N_WB; move16(); - *nb_sfm = *num_sfm; + *nb_sfm = *num_sfm; /* Q0 */ move16(); *num_env_bands = SFM_N_WB; move16(); - p_sfmsize = band_len_wb; - move16(); - p_sfm_start = band_start_wb; - move16(); - p_sfm_end = band_end_wb; - move16(); + p_sfmsize = band_len_wb; /* Q0 */ + p_sfm_start = band_start_wb; /* Q0 */ + p_sfm_end = band_end_wb; /* Q0 */ } IF( bw_ext ) { FOR( i = 0; i < *num_sfm; i++ ) { /*sfmsize[i] = (int16_t)(1.25f * p_sfmsize[i]);*/ - sfmsize[i] = mult_r( shl( p_sfmsize[i], 1 ), 20480 ); + sfmsize[i] = mult_r( shl( p_sfmsize[i], 1 ), 20480 /* 1.25 in Q14 */ ); /* Q0 */ move16(); /*sfm_start[i] = (int16_t)(1.25f * p_sfm_start[i]);*/ - sfm_start[i] = mult_r( shl( p_sfm_start[i], 1 ), 20480 ); + sfm_start[i] = mult_r( shl( p_sfm_start[i], 1 ), 20480 /* 1.25 in Q14 */ ); /* Q0 */ move16(); /*sfm_end[i] = (int16_t)(1.25f * p_sfm_end[i]);*/ - sfm_end[i] = mult_r( shl( p_sfm_end[i], 1 ), 20480 ); + sfm_end[i] = mult_r( shl( p_sfm_end[i], 1 ), 20480 /* 1.25 in Q14 */ ); /* Q0 */ move16(); } - *nb_sfm = *num_sfm; - *num_env_bands = *num_sfm; + *nb_sfm = *num_sfm; /* Q0 */ + *num_env_bands = *num_sfm; /* Q0 */ move16(); move16(); } diff --git a/lib_com/hq_conf_fx.c b/lib_com/hq_conf_fx.c index 7dd8a2371..ae3fc58b0 100644 --- a/lib_com/hq_conf_fx.c +++ b/lib_com/hq_conf_fx.c @@ -50,14 +50,10 @@ void ivas_hq_configure_fx( { *num_sfm = NB_SFM; move16(); - p_sfmsize = band_len_HQ; - move16(); - p_sfm_start = band_start_HQ; - move16(); - p_sfm_end = band_end_HQ; - move16(); + p_sfmsize = band_len_HQ; /* Q0 */ + p_sfm_start = band_start_HQ; /* Q0 */ + p_sfm_end = band_end_HQ; /* Q0 */ - test(); IF( GE_32( core_brate, HQ_32k ) ) { *hq_generic_offset = HQ_GENERIC_FOFFSET_32K; @@ -86,12 +82,9 @@ void ivas_hq_configure_fx( *num_env_bands = SFM_N_HARM_FB; move16(); - p_sfmsize = band_len_harm; - move16(); - p_sfm_start = band_start_harm; - move16(); - p_sfm_end = band_end_harm; - move16(); + p_sfmsize = band_len_harm; /* Q0 */ + p_sfm_start = band_start_harm; /* Q0 */ + p_sfm_end = band_end_harm; /* Q0 */ } ELSE IF( EQ_16( hqswb_clas, HQ_HVQ ) ) { @@ -101,7 +94,7 @@ void ivas_hq_configure_fx( move16(); *nb_sfm = HVQ_THRES_SFM_24k; move16(); - *num_env_bands = sub( *num_sfm, *nb_sfm ); + *num_env_bands = sub( *num_sfm, *nb_sfm ); /* Q0 */ move16(); *start_norm = HVQ_THRES_SFM_24k; move16(); @@ -112,33 +105,27 @@ void ivas_hq_configure_fx( move16(); *nb_sfm = HVQ_THRES_SFM_32k; move16(); - *num_env_bands = sub( *num_sfm, *nb_sfm ); + *num_env_bands = sub( *num_sfm, *nb_sfm ); /* Q0 */ move16(); *start_norm = HVQ_THRES_SFM_32k; move16(); } - p_sfmsize = band_len_harm; - p_sfm_start = band_start_harm; - p_sfm_end = band_end_harm; - move16(); - move16(); - move16(); + p_sfmsize = band_len_harm; /* Q0 */ + p_sfm_start = band_start_harm; /* Q0 */ + p_sfm_end = band_end_harm; /* Q0 */ } ELSE { *num_sfm = NB_SFM; move16(); - *nb_sfm = *num_sfm; + *nb_sfm = *num_sfm; /* Q0 */ move16(); *num_env_bands = NB_SFM; move16(); - p_sfmsize = band_len_HQ; - move16(); - p_sfm_start = band_start_HQ; - move16(); - p_sfm_end = band_end_HQ; - move16(); + p_sfmsize = band_len_HQ; /* Q0 */ + p_sfm_start = band_start_HQ; /* Q0 */ + p_sfm_end = band_end_HQ; /* Q0 */ } } } @@ -153,12 +140,9 @@ void ivas_hq_configure_fx( *num_env_bands = SFM_N_HARM; move16(); - p_sfmsize = band_len_harm; - move16(); - p_sfm_start = band_start_harm; - move16(); - p_sfm_end = band_end_harm; - move16(); + p_sfmsize = band_len_harm; /* Q0 */ + p_sfm_start = band_start_harm; /* Q0 */ + p_sfm_end = band_end_harm; /* Q0 */ } ELSE IF( EQ_16( hqswb_clas, HQ_HVQ ) ) { @@ -168,7 +152,7 @@ void ivas_hq_configure_fx( move16(); *nb_sfm = HVQ_THRES_SFM_24k; move16(); - *num_env_bands = sub( *num_sfm, *nb_sfm ); + *num_env_bands = sub( *num_sfm, *nb_sfm ); /* Q0 */ move16(); *start_norm = HVQ_THRES_SFM_24k; @@ -180,29 +164,23 @@ void ivas_hq_configure_fx( move16(); *nb_sfm = HVQ_THRES_SFM_32k; move16(); - *num_env_bands = sub( *num_sfm, *nb_sfm ); + *num_env_bands = sub( *num_sfm, *nb_sfm ); /* Q0 */ move16(); *start_norm = HVQ_THRES_SFM_32k; move16(); } p_sfmsize = band_len_harm; - move16(); p_sfm_start = band_start_harm; - move16(); p_sfm_end = band_end_harm; - move16(); } ELSE IF( EQ_16( hqswb_clas, HQ_GEN_SWB ) ) { *num_sfm = SFM_N_SWB; move16(); - p_sfmsize = band_len_HQ; - move16(); - p_sfm_start = band_start_HQ; - move16(); - p_sfm_end = band_end_HQ; - move16(); + p_sfmsize = band_len_HQ; /* Q0 */ + p_sfm_start = band_start_HQ; /* Q0 */ + p_sfm_end = band_end_HQ; /* Q0 */ IF( GE_32( core_brate, HQ_32k ) ) { @@ -227,75 +205,65 @@ void ivas_hq_configure_fx( /* HQ_NORMAL and HQ_TRANSIENT */ *num_sfm = SFM_N_SWB; move16(); - *nb_sfm = *num_sfm; + *nb_sfm = *num_sfm; /* Q0 */ move16(); *num_env_bands = SFM_N_SWB; move16(); - p_sfmsize = band_len_HQ; - move16(); - p_sfm_start = band_start_HQ; - move16(); - p_sfm_end = band_end_HQ; - move16(); + p_sfmsize = band_len_HQ; /* Q0 */ + p_sfm_start = band_start_HQ; /* Q0 */ + p_sfm_end = band_end_HQ; /* Q0 */ } } ELSE IF( EQ_16( length, L_SPEC48k_EXT ) ) { bw_ext = 1; - p_sfmsize = band_len_HQ; - p_sfm_start = band_start_HQ; - p_sfm_end = band_end_HQ; - *num_sfm = NB_SFM; - move16(); - move16(); move16(); + p_sfmsize = band_len_HQ; /* Q0 */ + p_sfm_start = band_start_HQ; /* Q0 */ + p_sfm_end = band_end_HQ; /* Q0 */ + *num_sfm = NB_SFM; move16(); } ELSE IF( EQ_16( length, L_SPEC16k_EXT ) ) { bw_ext = 1; - p_sfmsize = band_len_wb; - p_sfm_start = band_start_wb; - p_sfm_end = band_end_wb; - *num_sfm = SFM_N_WB; - move16(); - move16(); move16(); + p_sfmsize = band_len_wb; /* Q0 */ + p_sfm_start = band_start_wb; /* Q0 */ + p_sfm_end = band_end_wb; /* Q0 */ + *num_sfm = SFM_N_WB; move16(); } ELSE { *num_sfm = SFM_N_WB; move16(); - *nb_sfm = *num_sfm; + *nb_sfm = *num_sfm; /* Q0 */ move16(); *num_env_bands = SFM_N_WB; move16(); - p_sfmsize = band_len_wb; - move16(); - p_sfm_start = band_start_wb; - move16(); - p_sfm_end = band_end_wb; - move16(); + p_sfmsize = band_len_wb; /* Q0 */ + p_sfm_start = band_start_wb; /* Q0 */ + p_sfm_end = band_end_wb; /* Q0 */ } IF( bw_ext ) { FOR( i = 0; i < *num_sfm; i++ ) { /*sfmsize[i] = (int16_t)(1.25f * p_sfmsize[i]);*/ - sfmsize[i] = mult_r( shl( p_sfmsize[i], 1 ), 20480 ); + sfmsize[i] = mult_r( shl( p_sfmsize[i], 1 ), 20480 /* 1.25 in Q14 */ ); /* Q0 */ move16(); /*sfm_start[i] = (int16_t)(1.25f * p_sfm_start[i]);*/ - sfm_start[i] = mult_r( shl( p_sfm_start[i], 1 ), 20480 ); + sfm_start[i] = mult_r( shl( p_sfm_start[i], 1 ), 20480 /* 1.25 in Q14 */ ); /* Q0 */ move16(); /*sfm_end[i] = (int16_t)(1.25f * p_sfm_end[i]);*/ - sfm_end[i] = mult_r( shl( p_sfm_end[i], 1 ), 20480 ); + sfm_end[i] = mult_r( shl( p_sfm_end[i], 1 ), 20480 /* 1.25 in Q14 */ ); /* Q0 */ move16(); } - *nb_sfm = *num_sfm; - *num_env_bands = *num_sfm; + *nb_sfm = *num_sfm; /* Q0 */ + *num_env_bands = *num_sfm; /* Q0 */ move16(); move16(); } @@ -349,14 +317,10 @@ void hq_configure_evs_fx( { *num_sfm = NB_SFM; move16(); - p_sfmsize = band_len_HQ; - move16(); - p_sfm_start = band_start_HQ; - move16(); - p_sfm_end = band_end_HQ; - move16(); + p_sfmsize = band_len_HQ; /* Q0 */ + p_sfm_start = band_start_HQ; /* Q0 */ + p_sfm_end = band_end_HQ; /* Q0 */ - test(); IF( GE_32( core_brate, HQ_32k ) ) { *hq_generic_offset = HQ_GENERIC_FOFFSET_32K; @@ -371,7 +335,7 @@ void hq_configure_evs_fx( move16(); move16(); } - *nb_sfm = *num_sfm; + *nb_sfm = *num_sfm; /* Q0 */ move16(); } ELSE @@ -385,12 +349,9 @@ void hq_configure_evs_fx( *num_env_bands = SFM_N_HARM_FB; move16(); - p_sfmsize = band_len_harm; - move16(); - p_sfm_start = band_start_harm; - move16(); - p_sfm_end = band_end_harm; - move16(); + p_sfmsize = band_len_harm; /* Q0 */ + p_sfm_start = band_start_harm; /* Q0 */ + p_sfm_end = band_end_harm; /* Q0 */ } ELSE IF( EQ_16( hqswb_clas, HQ_HVQ ) ) { @@ -400,7 +361,7 @@ void hq_configure_evs_fx( move16(); *nb_sfm = HVQ_THRES_SFM_24k; move16(); - *num_env_bands = sub( *num_sfm, *nb_sfm ); + *num_env_bands = sub( *num_sfm, *nb_sfm ); /* Q0 */ move16(); *start_norm = HVQ_THRES_SFM_24k; move16(); @@ -411,33 +372,27 @@ void hq_configure_evs_fx( move16(); *nb_sfm = HVQ_THRES_SFM_32k; move16(); - *num_env_bands = sub( *num_sfm, *nb_sfm ); + *num_env_bands = sub( *num_sfm, *nb_sfm ); /* Q0 */ move16(); *start_norm = HVQ_THRES_SFM_32k; move16(); } - p_sfmsize = band_len_harm; - p_sfm_start = band_start_harm; - p_sfm_end = band_end_harm; - move16(); - move16(); - move16(); + p_sfmsize = band_len_harm; /* Q0 */ + p_sfm_start = band_start_harm; /* Q0 */ + p_sfm_end = band_end_harm; /* Q0 */ } ELSE { *num_sfm = NB_SFM; move16(); - *nb_sfm = *num_sfm; + *nb_sfm = *num_sfm; /* Q0 */ move16(); *num_env_bands = NB_SFM; move16(); - p_sfmsize = band_len_HQ; - move16(); - p_sfm_start = band_start_HQ; - move16(); - p_sfm_end = band_end_HQ; - move16(); + p_sfmsize = band_len_HQ; /* Q0 */ + p_sfm_start = band_start_HQ; /* Q0 */ + p_sfm_end = band_end_HQ; /* Q0 */ } } } @@ -452,12 +407,9 @@ void hq_configure_evs_fx( *num_env_bands = SFM_N_HARM; move16(); - p_sfmsize = band_len_harm; - move16(); - p_sfm_start = band_start_harm; - move16(); - p_sfm_end = band_end_harm; - move16(); + p_sfmsize = band_len_harm; /* Q0 */ + p_sfm_start = band_start_harm; /* Q0 */ + p_sfm_end = band_end_harm; /* Q0 */ } ELSE IF( EQ_16( hqswb_clas, HQ_HVQ ) ) { @@ -485,23 +437,17 @@ void hq_configure_evs_fx( *start_norm = HVQ_THRES_SFM_32k; move16(); } - p_sfmsize = band_len_harm; - move16(); - p_sfm_start = band_start_harm; - move16(); - p_sfm_end = band_end_harm; - move16(); + p_sfmsize = band_len_harm; /* Q0 */ + p_sfm_start = band_start_harm; /* Q0 */ + p_sfm_end = band_end_harm; /* Q0 */ } ELSE IF( EQ_16( hqswb_clas, HQ_GEN_SWB ) ) { *num_sfm = SFM_N_SWB; move16(); - p_sfmsize = band_len_HQ; - move16(); - p_sfm_start = band_start_HQ; - move16(); - p_sfm_end = band_end_HQ; - move16(); + p_sfmsize = band_len_HQ; /* Q0 */ + p_sfm_start = band_start_HQ; /* Q0 */ + p_sfm_end = band_end_HQ; /* Q0 */ IF( GE_32( core_brate, HQ_32k ) ) { @@ -531,36 +477,29 @@ void hq_configure_evs_fx( *num_env_bands = SFM_N_SWB; move16(); - p_sfmsize = band_len_HQ; - move16(); - p_sfm_start = band_start_HQ; - move16(); - p_sfm_end = band_end_HQ; - move16(); + p_sfmsize = band_len_HQ; /* Q0 */ + p_sfm_start = band_start_HQ; /* Q0 */ + p_sfm_end = band_end_HQ; /* Q0 */ } } ELSE IF( EQ_16( length, L_SPEC48k_EXT ) ) { bw_ext = 1; - p_sfmsize = band_len_HQ; - p_sfm_start = band_start_HQ; - p_sfm_end = band_end_HQ; - *num_sfm = NB_SFM; - move16(); - move16(); move16(); + p_sfmsize = band_len_HQ; /* Q0 */ + p_sfm_start = band_start_HQ; /* Q0 */ + p_sfm_end = band_end_HQ; /* Q0 */ + *num_sfm = NB_SFM; move16(); } ELSE IF( EQ_16( length, L_SPEC16k_EXT ) ) { bw_ext = 1; - p_sfmsize = band_len_wb; - p_sfm_start = band_start_wb; - p_sfm_end = band_end_wb; - *num_sfm = SFM_N_WB; - move16(); - move16(); move16(); + p_sfmsize = band_len_wb; /* Q0 */ + p_sfm_start = band_start_wb; /* Q0 */ + p_sfm_end = band_end_wb; /* Q0 */ + *num_sfm = SFM_N_WB; move16(); } ELSE @@ -572,25 +511,22 @@ void hq_configure_evs_fx( *num_env_bands = SFM_N_WB; move16(); - p_sfmsize = band_len_wb; - move16(); - p_sfm_start = band_start_wb; - move16(); - p_sfm_end = band_end_wb; - move16(); + p_sfmsize = band_len_wb; /* Q0 */ + p_sfm_start = band_start_wb; /* Q0 */ + p_sfm_end = band_end_wb; /* Q0 */ } IF( bw_ext ) { FOR( i = 0; i < *num_sfm; i++ ) { /*sfmsize[i] = (int16_t)(1.25f * p_sfmsize[i]);*/ - sfmsize[i] = mult_r( shl( p_sfmsize[i], 1 ), 20480 ); + sfmsize[i] = mult_r( shl( p_sfmsize[i], 1 ), 20480 /* 1.25 in Q14 */ ); move16(); /*sfm_start[i] = (int16_t)(1.25f * p_sfm_start[i]);*/ - sfm_start[i] = mult_r( shl( p_sfm_start[i], 1 ), 20480 ); + sfm_start[i] = mult_r( shl( p_sfm_start[i], 1 ), 20480 /* 1.25 in Q14 */ ); move16(); /*sfm_end[i] = (int16_t)(1.25f * p_sfm_end[i]);*/ - sfm_end[i] = mult_r( shl( p_sfm_end[i], 1 ), 20480 ); + sfm_end[i] = mult_r( shl( p_sfm_end[i], 1 ), 20480 /* 1.25 in Q14 */ ); move16(); } *nb_sfm = *num_sfm; diff --git a/lib_com/hvq_pvq_bitalloc_fx.c b/lib_com/hvq_pvq_bitalloc_fx.c index 298547b53..bc15fe266 100644 --- a/lib_com/hvq_pvq_bitalloc_fx.c +++ b/lib_com/hvq_pvq_bitalloc_fx.c @@ -22,10 +22,10 @@ Word16 hvq_pvq_bitalloc_fx( const Word16 *ynrm, /* i : Envelope coefficients */ const Word32 manE_peak, /* i : Peak energy mantissa */ const Word16 expE_peak, /* i : Peak energy exponent */ - Word16 *Rk, /* o : bit allocation for concatenated vector */ - Word16 *R, /* i/o: Global bit allocation */ - Word16 *sel_bands, /* o : Selected bands for encoding */ - Word16 *n_sel_bands /* o : No. of selected bands for encoding */ + Word16 *Rk, /* Q3 o : bit allocation for concatenated vector */ + Word16 *R, /* Q0 i/o: Global bit allocation */ + Word16 *sel_bands, /* Q0 o : Selected bands for encoding */ + Word16 *n_sel_bands /* Q0 o : No. of selected bands for encoding */ ) { Word16 num_bands, band_max_bits; @@ -52,11 +52,11 @@ Word16 hvq_pvq_bitalloc_fx( IF( LT_32( core_brate, HQ_BWE_CROSSOVER_BRATE ) ) { - band_max_bits = HVQ_BAND_MAX_BITS_24k; + band_max_bits = HVQ_BAND_MAX_BITS_24k; /*Q0*/ move16(); - one_over_band_max_bits = ONE_OVER_HVQ_BAND_MAX_BITS_24k_FX; + one_over_band_max_bits = ONE_OVER_HVQ_BAND_MAX_BITS_24k_FX; /*Q15*/ move16(); - k_start = HVQ_THRES_SFM_24k; + k_start = HVQ_THRES_SFM_24k; /*Q0*/ move16(); IF( EQ_16( bwidth_fx, FB ) ) { @@ -71,11 +71,11 @@ Word16 hvq_pvq_bitalloc_fx( } ELSE { - band_max_bits = HVQ_BAND_MAX_BITS_32k; + band_max_bits = HVQ_BAND_MAX_BITS_32k; /*Q0*/ move16(); - one_over_band_max_bits = ONE_OVER_HVQ_BAND_MAX_BITS_32k_FX; + one_over_band_max_bits = ONE_OVER_HVQ_BAND_MAX_BITS_32k_FX; /*Q15*/ move16(); - k_start = HVQ_THRES_SFM_32k; + k_start = HVQ_THRES_SFM_32k; /*Q0*/ move16(); IF( EQ_16( bwidth_fx, FB ) ) { @@ -164,14 +164,14 @@ Word16 hvq_pvq_bitalloc_fx( { QuantaPerDsDirac_fx( band_len_harm[k_max], 1, hBitsN, &n ); } - m = shl( sub( num_bits, HVQ_PVQ_GAIN_BITS ), 3 ); + m = shl( sub( num_bits, HVQ_PVQ_GAIN_BITS ), 3 ); /*Q3*/ IF( GE_16( m, n ) ) { IF( GT_16( num_bands, 1 ) ) /* condition: num_bands > 1 */ { - sel_bands[*n_sel_bands] = k_max; + sel_bands[*n_sel_bands] = k_max; /*Q0*/ move16(); - *n_sel_bands = add( *n_sel_bands, 1 ); + *n_sel_bands = add( *n_sel_bands, 1 ); /*Q0*/ move16(); R[k_max] = 1; /* Mark that the band has been encoded for fill_spectrum */ move16(); @@ -184,11 +184,11 @@ Word16 hvq_pvq_bitalloc_fx( tmp = sub( num_bands, 1 ); FOR( k = 0; k < tmp; k++ ) { - Rk[k] = shl( sub( band_max_bits, HVQ_PVQ_GAIN_BITS ), 3 ); + Rk[k] = shl( sub( band_max_bits, HVQ_PVQ_GAIN_BITS ), 3 ); /*Q3*/ move16(); } /* NB: When it exits the above loop, k = num_bands - 1. */ - Rk[k] = shl( sub( num_bits, HVQ_PVQ_GAIN_BITS ), 3 ); + Rk[k] = shl( sub( num_bits, HVQ_PVQ_GAIN_BITS ), 3 ); /*Q3*/ move16(); return num_bands; diff --git a/lib_com/interleave_spectrum.c b/lib_com/interleave_spectrum.c index 65b42e575..1cf7d5ce6 100644 --- a/lib_com/interleave_spectrum.c +++ b/lib_com/interleave_spectrum.c @@ -142,8 +142,11 @@ void interleave_spectrum_fx( const Word16 *bw; const Word16 *cnt; + move16(); + move16(); + move16(); /* Common inits */ - p1 = coefs; + p1 = coefs; /*Q12*/ p_out = coefs_out; #ifdef SOLVED_COMP_ENC_DEC IF( EQ_16( length, L_SPEC48k ) ) @@ -151,8 +154,8 @@ void interleave_spectrum_fx( IF( EQ_16( length, L_FRAME48k ) ) #endif { - bw = intl_bw_48; - cnt = intl_cnt_48; + bw = intl_bw_48; /*Q0*/ + cnt = intl_cnt_48; /*Q0*/ grps = N_INTL_GRP_48; move16(); p2 = p1 + sublen[0]; @@ -161,8 +164,8 @@ void interleave_spectrum_fx( } ELSE IF( EQ_16( length, L_SPEC32k ) ) { - bw = intl_bw_32; - cnt = intl_cnt_32; + bw = intl_bw_32; /*Q0*/ + cnt = intl_cnt_32; /*Q0*/ grps = N_INTL_GRP_32; move16(); p2 = p1 + sublen[1]; @@ -171,8 +174,8 @@ void interleave_spectrum_fx( } ELSE /* length == L_SPEC16k */ { - bw = intl_bw_16; - cnt = intl_cnt_16; + bw = intl_bw_16; /*Q0*/ + cnt = intl_cnt_16; /*Q0*/ grps = N_INTL_GRP_16; move16(); p2 = p1 + sublen[2]; @@ -186,22 +189,22 @@ void interleave_spectrum_fx( { FOR( k = 0; k < bw[i]; k++ ) { - *p_out++ = *p1++; + *p_out++ = *p1++; /*Q12*/ move32(); } FOR( k = 0; k < bw[i]; k++ ) { - *p_out++ = *p2++; + *p_out++ = *p2++; /*Q12*/ move32(); } FOR( k = 0; k < bw[i]; k++ ) { - *p_out++ = *p3++; + *p_out++ = *p3++; /*Q12*/ move32(); } FOR( k = 0; k < bw[i]; k++ ) { - *p_out++ = *p4++; + *p_out++ = *p4++; /*Q12*/ move32(); } } @@ -231,13 +234,13 @@ void interleave_spectrum_ivas_fx( const Word16 *cnt; /* Common inits */ - p1 = coefs; + p1 = coefs; /*Q12*/ p_out = coefs_out; IF( EQ_16( length, L_SPEC48k ) ) { - bw = intl_bw_48; - cnt = intl_cnt_48; + bw = intl_bw_48; /*Q0*/ + cnt = intl_cnt_48; /*Q0*/ grps = N_INTL_GRP_48; move16(); p2 = p1 + sublen[0]; @@ -246,8 +249,8 @@ void interleave_spectrum_ivas_fx( } ELSE IF( EQ_16( length, L_SPEC32k ) ) { - bw = intl_bw_32; - cnt = intl_cnt_32; + bw = intl_bw_32; /*Q0*/ + cnt = intl_cnt_32; /*Q0*/ grps = N_INTL_GRP_32; move16(); p2 = p1 + sublen[1]; @@ -256,8 +259,8 @@ void interleave_spectrum_ivas_fx( } ELSE /* length == L_SPEC16k */ { - bw = intl_bw_16; - cnt = intl_cnt_16; + bw = intl_bw_16; /*Q0*/ + cnt = intl_cnt_16; /*Q0*/ grps = N_INTL_GRP_16; move16(); p2 = p1 + sublen[2]; @@ -271,22 +274,22 @@ void interleave_spectrum_ivas_fx( { FOR( k = 0; k < bw[i]; k++ ) { - *p_out++ = *p1++; + *p_out++ = *p1++; /*Q12*/ move32(); } FOR( k = 0; k < bw[i]; k++ ) { - *p_out++ = *p2++; + *p_out++ = *p2++; /*Q12*/ move32(); } FOR( k = 0; k < bw[i]; k++ ) { - *p_out++ = *p3++; + *p_out++ = *p3++; /*Q12*/ move32(); } FOR( k = 0; k < bw[i]; k++ ) { - *p_out++ = *p4++; + *p_out++ = *p4++; /*Q12*/ move32(); } } @@ -389,6 +392,12 @@ void ivas_de_interleave_spectrum_fx( Word32 *p_in; Word32 coefs_out[L_FRAME48k]; Word16 sublen[] = { 80, 160, 240, 320, 480, 720 }; + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); Word16 grps; Word16 l_frame; const Word16 *bw; @@ -400,8 +409,8 @@ void ivas_de_interleave_spectrum_fx( move16(); IF( EQ_16( length, L_SPEC48k ) ) { - bw = intl_bw_48; - cnt = intl_cnt_48; + bw = intl_bw_48; /*Q0*/ + cnt = intl_cnt_48; /*Q0*/ grps = N_INTL_GRP_48; move16(); l_frame = L_FRAME48k; @@ -412,8 +421,8 @@ void ivas_de_interleave_spectrum_fx( } ELSE IF( EQ_16( length, L_FRAME32k ) ) { - bw = intl_bw_32; - cnt = intl_cnt_32; + bw = intl_bw_32; /*Q0*/ + cnt = intl_cnt_32; /*Q0*/ grps = N_INTL_GRP_32; move16(); @@ -423,8 +432,8 @@ void ivas_de_interleave_spectrum_fx( } ELSE /* length == L_SPEC16k */ { - bw = intl_bw_16; - cnt = intl_cnt_16; + bw = intl_bw_16; /*Q0*/ + cnt = intl_cnt_16; /*Q0*/ grps = N_INTL_GRP_16; move16(); @@ -434,7 +443,7 @@ void ivas_de_interleave_spectrum_fx( } set32_fx( coefs_out, 0, L_FRAME48k ); - p_in = coefs; + p_in = coefs; /*Q12*/ FOR( i = 0; i < grps; i++ ) { @@ -442,22 +451,22 @@ void ivas_de_interleave_spectrum_fx( { FOR( k = 0; k < bw[i]; k++ ) { - *p1++ = *p_in++; + *p1++ = *p_in++; /*Q12*/ move32(); } FOR( k = 0; k < bw[i]; k++ ) { - *p2++ = *p_in++; + *p2++ = *p_in++; /*Q12*/ move32(); } FOR( k = 0; k < bw[i]; k++ ) { - *p3++ = *p_in++; + *p3++ = *p_in++; /*Q12*/ move32(); } FOR( k = 0; k < bw[i]; k++ ) { - *p4++ = *p_in++; + *p4++ = *p_in++; /*Q12*/ move32(); } } @@ -478,6 +487,12 @@ void de_interleave_spectrum_fx( Word32 *p_in; Word32 coefs_out[L_FRAME48k]; Word16 sublen[] = { 80, 160, 240, 320, 480, 720 }; + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); Word16 grps; Word16 l_frame; const Word16 *bw; @@ -493,8 +508,8 @@ void de_interleave_spectrum_fx( IF( EQ_16( length, L_FRAME48k ) ) #endif { - bw = intl_bw_48; - cnt = intl_cnt_48; + bw = intl_bw_48; /*Q0*/ + cnt = intl_cnt_48; /*Q0*/ grps = N_INTL_GRP_48; move16(); #ifdef SOLVED_COMP_ENC_DEC @@ -507,8 +522,8 @@ void de_interleave_spectrum_fx( } ELSE IF( EQ_16( length, L_SPEC32k ) ) { - bw = intl_bw_32; - cnt = intl_cnt_32; + bw = intl_bw_32; /*Q0*/ + cnt = intl_cnt_32; /*Q0*/ grps = N_INTL_GRP_32; move16(); @@ -518,8 +533,8 @@ void de_interleave_spectrum_fx( } ELSE /* length == L_SPEC16k */ { - bw = intl_bw_16; - cnt = intl_cnt_16; + bw = intl_bw_16; /*Q0*/ + cnt = intl_cnt_16; /*Q0*/ grps = N_INTL_GRP_16; move16(); @@ -529,7 +544,7 @@ void de_interleave_spectrum_fx( } set32_fx( coefs_out, 0, L_FRAME48k ); - p_in = coefs; + p_in = coefs; /*Q12*/ FOR( i = 0; i < grps; i++ ) { @@ -537,22 +552,22 @@ void de_interleave_spectrum_fx( { FOR( k = 0; k < bw[i]; k++ ) { - *p1++ = *p_in++; + *p1++ = *p_in++; /*Q12*/ move32(); } FOR( k = 0; k < bw[i]; k++ ) { - *p2++ = *p_in++; + *p2++ = *p_in++; /*Q12*/ move32(); } FOR( k = 0; k < bw[i]; k++ ) { - *p3++ = *p_in++; + *p3++ = *p_in++; /*Q12*/ move32(); } FOR( k = 0; k < bw[i]; k++ ) { - *p4++ = *p_in++; + *p4++ = *p_in++; /*Q12*/ move32(); } } diff --git a/lib_com/ivas_prot_fx.h b/lib_com/ivas_prot_fx.h index 7c0458fa2..348fc2ebe 100644 --- a/lib_com/ivas_prot_fx.h +++ b/lib_com/ivas_prot_fx.h @@ -1654,7 +1654,7 @@ void ivas_hq_bit_allocation_fx( const Word16 *normqlg2, /* i : Quantized norms Q0 */ const Word16 nb_sfm, /* i : Number sub bands to be encoded Q0 */ const Word16 *sfmsize, /* i : Sub band bandwidths Q0 */ - Word16 *noise_level, /* o : HVQ noise level */ + Word16 *noise_level, /* o : HVQ noise level Q15 */ Word16 *R, /* o : Bit allocation per sub band Q0 */ Word16 *Rsubband, /* o : Fractional bit allocation Q3 */ Word16 *sum, /* o : Sum of allocated shape bits Q0 */ diff --git a/lib_com/prot.h b/lib_com/prot.h index d15bb767d..803a0a757 100644 --- a/lib_com/prot.h +++ b/lib_com/prot.h @@ -827,6 +827,7 @@ int16_t lsp_convert_poly( const int16_t Opt_AMRWB /* i : flag for the AMR-WB IO mode */ ); /*! r: pulse position */ +#ifndef IVAS_FLOAT_FIXED int16_t findpulse( const int16_t L_frame, /* i : length of the frame */ const float res[], /* i : residual signal */ @@ -834,6 +835,7 @@ int16_t findpulse( const int16_t enc_dec, /* i : flag enc/dec, 0 - enc, 1 - dec */ int16_t *sign /* i/o: sign of the maximum */ ); +#endif void fft_rel( float x[], /* i/o: input/output vector */ diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index 3239613af..07e2aa779 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -2128,28 +2128,29 @@ hq2_noise_inject.c fix part /========================================================================================================*/ void hq2_noise_inject_fx( - Word32 L_y2[], - const Word16 band_start[], - const Word16 band_end[], - const Word16 band_width[], - Word32 Ep_fx[], - Word32 Rk_fx[], - const Word16 npulses[], - Word16 ni_seed, - const Word16 bands, - const Word16 ni_start_band, - const Word16 bw_low, - const Word16 bw_high, - const Word32 enerL_fx, - const Word32 enerH_fx, - Word32 last_ni_gain_fx[], - Word16 last_env_fx[], - Word16 *last_max_pos_pulse, - Word16 *p2a_flags, - Word16 p2a_bands, - const Word16 hqswb_clas, - const Word16 bwidth, - const Word32 bwe_br ); + Word32 L_y2[], /* Q12 */ + const Word16 band_start[], /* Q0 */ + const Word16 band_end[], /* Q0 */ + const Word16 band_width[], /* Q0 */ + Word32 Ep_fx[], /* Q-6 */ + Word32 Rk_fx[], /* QRk (Q16) */ + const Word16 npulses[], /* Q0 */ + Word16 ni_seed, /* Q0 */ + const Word16 bands, /* Q0 */ + const Word16 ni_start_band, /* Q0 */ + const Word16 bw_low, /* Q0 */ + const Word16 bw_high, /* Q0 */ + const Word32 enerL_fx, /* Q0 */ + const Word32 enerH_fx, /* Q0 */ + Word32 last_ni_gain_fx[], /* Q17 */ + Word16 last_env_fx[], /* Q1 */ + Word16 *last_max_pos_pulse, /* Q0 */ + Word16 *p2a_flags, /* Q0 */ + Word16 p2a_bands, /* Q0 */ + const Word16 hqswb_clas, /* Q0 */ + const Word16 bwidth, /* Q0 */ + const Word32 bwe_br /* Q0 */ +); /*========================================================================================================/ hq2_bit_alloc_fx.c @@ -2262,25 +2263,26 @@ void mdct_spectrum_denorm_ivas_fx( ); void hq2_core_configure_fx( - const Word16 frame_length, - const Word16 num_bits, - const Word16 is_transient, - Word16 *bands, - Word16 *length, - Word16 band_width[], - Word16 band_start[], - Word16 band_end[], - Word32 *L_qint, - Word16 *eref, - Word16 *bit_alloc_weight, - Word16 *gqlevs, - Word16 *Ngq, - Word16 *p2a_bands, - Word16 *p2a_th, - Word16 *pd_thresh, - Word16 *ld_slope, - Word16 *ni_coef, - Word32 L_bwe_br ); + const Word16 frame_length, /* Q0 */ + const Word16 num_bits, /* Q0 */ + const Word16 is_transient, /* Q0 */ + Word16 *bands, /* Q0 */ + Word16 *length, /* Q0 */ + Word16 band_width[], /* Q0 */ + Word16 band_start[], /* Q0 */ + Word16 band_end[], /* Q0 */ + Word32 *L_qint, /* Q13 */ + Word16 *eref, /* Q10 */ + Word16 *bit_alloc_weight, /* Q13 */ + Word16 *gqlevs, /* Q0 */ + Word16 *Ngq, /* Q0 */ + Word16 *p2a_bands, /* Q0 */ + Word16 *p2a_th, /* Q11 */ + Word16 *pd_thresh, /* Q15 */ + Word16 *ld_slope, /* Q15 */ + Word16 *ni_coef, /* Q14 */ + Word32 L_bwe_br /* Q0 */ +); void reverse_transient_frame_energies_fx( Word32 L_band_energy[], /* o : Q14 : band energies */ @@ -2288,55 +2290,56 @@ void reverse_transient_frame_energies_fx( ); void spt_shorten_domain_pre_fx( - const Word16 band_start[], /* i: Starting position of sub band */ - const Word16 band_end[], /* i: End position of sub band */ - const Word16 prev_SWB_peak_pos[], /* i: Spectral peak */ - const Word16 BANDS, /* i: total number of bands */ - const Word32 L_bwe_br, /* i: bitrate information */ - Word16 new_band_start[], /* o: Starting position of new shorten sub band */ - Word16 new_band_end[], /* o: End position of new shorten sub band */ - Word16 new_band_width[] /* o: new sub band bandwidth */ + const Word16 band_start[], /* i: Starting position of sub band Q0*/ + const Word16 band_end[], /* i: End position of sub band Q0*/ + const Word16 prev_SWB_peak_pos[], /* i: Spectral peak Q0*/ + const Word16 BANDS, /* i: total number of bands Q0*/ + const Word32 L_bwe_br, /* i: bitrate information Q0*/ + Word16 new_band_start[], /* o: Starting position of new shorten sub band Q0*/ + Word16 new_band_end[], /* o: End position of new shorten sub band Q0*/ + Word16 new_band_width[] /* o: new sub band bandwidth Q0*/ ); void spt_shorten_domain_band_save_fx( - const Word16 bands, /* i: total subband */ - const Word16 band_start[], /* i: starting position of subband */ - const Word16 band_end[], /* i: end position of subband */ - const Word16 band_width[], /* i: band width of subband */ - Word16 org_band_start[], /* o: starting position of subband */ - Word16 org_band_end[], /* o: end position of subband */ - Word16 org_band_width[] /* o: band width of subband */ + const Word16 bands, /* i: total subband Q0*/ + const Word16 band_start[], /* i: starting position of subband Q0*/ + const Word16 band_end[], /* i: end position of subband Q0*/ + const Word16 band_width[], /* i: band width of subband Q0*/ + Word16 org_band_start[], /* o: starting position of subband Q0*/ + Word16 org_band_end[], /* o: end position of subband Q0*/ + Word16 org_band_width[] /* o: band width of subband Q0*/ ); void spt_shorten_domain_band_restore_fx( - const Word16 bands, /* i: total subband */ - Word16 band_start[], /* i/o: starting position of subband */ - Word16 band_end[], /* i/o: end position of subband */ - Word16 band_width[], /* i/o: band width of subband */ - const Word16 org_band_start[], /* o: starting position of subband */ - const Word16 org_band_end[], /* o: end position of subband */ - const Word16 org_band_width[] /* o: band width of subband */ + const Word16 bands, /* i: total subband Q0*/ + Word16 band_start[], /* i/o: starting position of subband Q0*/ + Word16 band_end[], /* i/o: end position of subband Q0*/ + Word16 band_width[], /* i/o: band width of subband Q0*/ + const Word16 org_band_start[], /* o: starting position of subband Q0*/ + const Word16 org_band_end[], /* o: end position of subband Q0*/ + const Word16 org_band_width[] /* o: band width of subband Q0*/ ); void spt_swb_peakpos_tmp_save_fx( - const Word32 L_y2[], /* i: coded spectral information */ - const Word16 bands, /* i: total number of bands */ - const Word16 band_start[], /* i: starting position of subband */ - const Word16 band_end[], /* i: end position of subband */ - Word16 prev_SWB_peak_pos_tmp[] /* o: spectral peaks */ + const Word32 L_y2[], /* i: coded spectral information Qx*/ + const Word16 bands, /* i: total number of bands Q0*/ + const Word16 band_start[], /* i: starting position of subband Q0*/ + const Word16 band_end[], /* i: end position of subband Q0*/ + Word16 prev_SWB_peak_pos_tmp[] /* o: spectral peaks Q0*/ ); void bit_allocation_second_fx( - Word32 *Rk, - Word32 *Rk_sort, - Word16 BANDS, - const Word16 *band_width, - Word16 *k_sort, - Word16 *k_num, - const Word16 *p2a_flags, - const Word16 p2a_bands, - const Word16 *last_bitalloc, - const Word16 input_frame ); + Word32 *Rk, /* Q16 */ + Word32 *Rk_sort, /* Q16 */ + Word16 BANDS, /* Q0 */ + const Word16 *band_width, /* Q0 */ + Word16 *k_sort, /* Q0 */ + Word16 *k_num, /* Q0 */ + const Word16 *p2a_flags, /* Q0 */ + const Word16 p2a_bands, /* Q0 */ + const Word16 *last_bitalloc, /* Q0 */ + const Word16 input_frame /* Q0 */ +); // synth_filt_fix.c Word32 syn_kern_16( @@ -5372,19 +5375,19 @@ void fill_spectrum_fx( // hq_bit_allocation_fx.c" void hq_bit_allocation_fx( - const Word32 core_brate, /* i : Core bit-rate */ - const Word16 length, /* i : Frame length */ - const Word16 hqswb_clas, /* i : HQ class */ - Word16 *num_bits, /* i/o: Remaining bit budget */ - const Word16 *normqlg2, /* i : Quantized norms */ - const Word16 nb_sfm, /* i : Number sub bands to be encoded */ - const Word16 *sfmsize, /* i : Sub band bandwidths */ - Word16 *noise_level, /* o : HVQ noise level */ - Word16 *R, /* o : Bit allocation per sub band */ - Word16 *Rsubband, /* o : Fractional bit allocation */ - Word16 *sum, /* o : Sum of allocated shape bits */ - Word16 *core_sfm, /* o : Last coded band in core */ - const Word16 num_env_bands /* i : Number sub bands to be encoded for HQ_SWB_BWE */ + const Word32 core_brate, /* i : Core bit-rate Q0 */ + const Word16 length, /* i : Frame length Q0 */ + const Word16 hqswb_clas, /* i : HQ class Q0 */ + Word16 *num_bits, /* i/o: Remaining bit budget Q0 */ + const Word16 *normqlg2, /* i : Quantized norms Q0 */ + const Word16 nb_sfm, /* i : Number sub bands to be encoded Q0 */ + const Word16 *sfmsize, /* i : Sub band bandwidths Q0 */ + Word16 *noise_level, /* o : HVQ noise level Q15 */ + Word16 *R, /* o : Bit allocation per sub band Q0 */ + Word16 *Rsubband, /* o : Fractional bit allocation Q3 */ + Word16 *sum, /* o : Sum of allocated shape bits Q0 */ + Word16 *core_sfm, /* o : Last coded band in core Q0 */ + const Word16 num_env_bands /* i : Number sub bands to be encoded for HQ_SWB_BWE Q0 */ ); // weight_fx.c @@ -7800,10 +7803,10 @@ Word16 hvq_pvq_bitalloc_fx( const Word16 *ynrm, /* i : Envelope coefficients */ const Word32 manE_peak, /* i : Peak energy mantissa */ const Word16 expE_peak, /* i : Peak energy exponent */ - Word16 *Rk, /* o : bit allocation for concatenated vector */ - Word16 *R, /* i/o: Global bit allocation */ - Word16 *sel_bands, /* o : Selected bands for encoding */ - Word16 *n_sel_bands /* o : No. of selected bands for encoding */ + Word16 *Rk, /* Q3 o : bit allocation for concatenated vector */ + Word16 *R, /* Q0 i/o: Global bit allocation */ + Word16 *sel_bands, /* Q0 o : Selected bands for encoding */ + Word16 *n_sel_bands /* Q0 o : No. of selected bands for encoding */ ); // hq_conf_fec_fx.c diff --git a/lib_com/rom_com.c b/lib_com/rom_com.c index 9047d8338..648280d1e 100644 --- a/lib_com/rom_com.c +++ b/lib_com/rom_com.c @@ -8328,7 +8328,7 @@ const Word16 mean_isf_noise_amr_wb_fx[M] = { 478, 1100, 2213, 3267, 4219, 5222, 6198, 7240, 8229, 9153,10098, 11108, 12144, 13184,14165, 3803 -}; +};/*14Q1*1.28*/ /* ISF codebook - common 1st stage, 1st split (only in AMR-WB IO mode) */ /*------------------------------------------------------* @@ -17816,7 +17816,7 @@ const Word16 dico5_ns_28b_fx[] = 1109, 918, 1101, 503, 1039, 1286, 1220, 317, 1351, 1207, 1010, 326 -}; +}; /*1.28f Q1*/ const Word16 means_nb_31bits_ma_lsf[16] = { 861 /*336.3281f*1.28f Q1*/, 1360 /*531.2500f*1.28f Q1*/, 2270 /*886.7188f*1.28f Q1*/, 3243 /*1266.7969f*1.28f Q1*/, 4171 /*1629.2969f*1.28f Q1*/, 5052 /*1973.4375f*1.28f Q1*/, 6012 /*2348.4375f*1.28f Q1*/, 6776 /*2646.8750f*1.28f Q1*/, 7676 /*2998.4375f*1.28f Q1*/, 8428 /*3292.1875f*1.28f Q1*/, 9194 /*3591.4062f*1.28f Q1*/, 9744 /*3806.2500f*1.28f Q1*/, 10580 /*4132.8125f*1.28f Q1*/, 11911 /*4652.7344f*1.28f Q1*/, 13440 /*5250.0000f*1.28f Q1*/, 15061 /*5883.2031f*1.28f Q1*/ }; const Word16 means_wb_31bits_ma_lsf[16] = { 818 /*319.5312f*1.28f Q1*/, 1403 /*548.0469f*1.28f Q1*/, 2392 /*934.3750f*1.28f Q1*/, 3465 /*1353.5156f*1.28f Q1*/, 4429 /*1730.0781f*1.28f Q1*/, 5428 /*2120.3125f*1.28f Q1*/, 6414 /*2505.4688f*1.28f Q1*/, 7323 /*2860.5469f*1.28f Q1*/, 8304 /*3243.7500f*1.28f Q1*/, 9221 /*3601.9531f*1.28f Q1*/, 10162 /*3969.5312f*1.28f Q1*/, 11091 /*4332.4219f*1.28f Q1*/, 12125 /*4736.3281f*1.28f Q1*/, 13153 /*5137.8906f*1.28f Q1*/, 14241 /*5562.8906f*1.28f Q1*/, 15266 /*5963.2812f*1.28f Q1*/ }; @@ -28071,7 +28071,7 @@ const int16_t intl_cnt_16[N_INTL_GRP_16] = {4, 1}; const int16_t intl_cnt_32[N_INTL_GRP_32] = {4, 4}; const int16_t intl_cnt_48[N_INTL_GRP_48] = {4, 3, 2}; -const int16_t band_start_HQ[44] = +const Word16 band_start_HQ[44] = { 0, 8, 16, 24, 32, 40, 48, 56, 64, 72, 80, 88, 96, 104, 112, 120, 128, 144, 160, 176, 192, 208, 224, 240, @@ -28079,7 +28079,7 @@ const int16_t band_start_HQ[44] = 544, 576, 608, 640, 672, 704, 736, 768 }; -const int16_t band_end_HQ[44] = +const Word16 band_end_HQ[44] = { 8, 16, 24, 32, 40, 48, 56, 64, 72, 80, 88, 96, 104, 112, 120, 128, 144, 160, 176, 192, 208, 224, 240, 256, @@ -28087,7 +28087,7 @@ const int16_t band_end_HQ[44] = 576, 608, 640, 672, 704, 736, 768, 800 }; -const int16_t band_len_HQ[44] = +const Word16 band_len_HQ[44] = { 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 16, 16, 16, 16, 16, 16, 16, 16, diff --git a/lib_com/rom_com.h b/lib_com/rom_com.h index 993e213b3..ce044a4e6 100644 --- a/lib_com/rom_com.h +++ b/lib_com/rom_com.h @@ -1066,15 +1066,15 @@ extern const Word16 wscw16q15_16_fx[]; extern const Word16 wscw16q15_32_fx[]; /* Band structure */ -extern const int16_t band_len_HQ[]; -extern const int16_t band_start_HQ[]; -extern const int16_t band_end_HQ[]; +extern const Word16 band_len_HQ[]; +extern const Word16 band_start_HQ[]; +extern const Word16 band_end_HQ[]; extern const int16_t band_len_wb[]; extern const int16_t band_start_wb[]; extern const int16_t band_end_wb[]; extern const int16_t band_len_harm_float[]; -extern const int16_t band_start_harm[]; -extern const int16_t band_end_harm[]; +extern const Word16 band_start_harm[]; +extern const Word16 band_end_harm[]; extern const float rat_flt[SFM_N_WB]; extern const Word16 rat_fx[SFM_N_WB]; extern const int16_t intl_bw_16[N_INTL_GRP_16]; diff --git a/lib_com/stat_noise_uv_mod.c b/lib_com/stat_noise_uv_mod.c index f9b10f501..2899052f3 100644 --- a/lib_com/stat_noise_uv_mod.c +++ b/lib_com/stat_noise_uv_mod.c @@ -40,6 +40,7 @@ #include "prot.h" #include "wmc_auto.h" +#ifndef IVAS_FLOAT_FIXED /*---------------------------------------------------------------------* * Local constants *---------------------------------------------------------------------*/ @@ -236,3 +237,4 @@ static float calc_tilt( return r1 / r0; } +#endif diff --git a/lib_com/swb_bwe_com_lr.c b/lib_com/swb_bwe_com_lr.c index 638e78db5..22d79f157 100644 --- a/lib_com/swb_bwe_com_lr.c +++ b/lib_com/swb_bwe_com_lr.c @@ -42,6 +42,7 @@ #include "rom_com.h" #include "wmc_auto.h" +#ifndef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* * hf_parinitiz() * @@ -2108,3 +2109,4 @@ void updat_prev_frm( return; } +#endif diff --git a/lib_enc/acelp_core_enc.c b/lib_enc/acelp_core_enc.c index a814ff029..d2a43ac55 100644 --- a/lib_enc/acelp_core_enc.c +++ b/lib_enc/acelp_core_enc.c @@ -217,8 +217,6 @@ ivas_error acelp_core_enc( } for ( int ii = 0; ii < M; ii++ ) { - st->mem_MA_fx[ii] = (Word16) ( ( st->mem_MA[ii] ) * 2.56f ); - st->mem_AR_fx[ii] = (Word16) ( ( st->mem_AR[ii] ) * 2.56f ); st->lsf_old_fx[ii] = (Word16) ( ( st->lsf_old[ii] ) * 2.56f ); } Word16 inp_buff[L_FRAME16k + M + 1]; @@ -448,8 +446,6 @@ ivas_error acelp_core_enc( for ( i = 0; i < M; i++ ) { st->lsf_old[i] = st->lsf_old_fx[i] / 2.56f; - st->mem_AR[i] = st->mem_AR_fx[i] / 2.56f; - st->mem_MA[i] = st->mem_MA_fx[i] / 2.56f; } fixedToFloat_arr( st->lsp_old_fx, st->lsp_old, 15, M ); IF( st->hLPDmem ) @@ -508,7 +504,6 @@ ivas_error acelp_core_enc( floatToFixed_arr( lsp_new, lsp_new_fx, Q15, M ); floatToFixed_arr( st->lsp_old, st->lsp_old_fx, Q15, M ); floatToFixed_arr( st->hTdCngEnc->ho_lsp_circ, st->hTdCngEnc->ho_lsp_circ_fx, Q15, HO_HIST_SIZE * M ); - floatToFixed_arr( st->hTdCngEnc->ho_lsp_circ2, st->hTdCngEnc->ho_lsp_circ2_fx, Q15, HO_HIST_SIZE * M ); floatToFixed_arrL( st->hTdCngEnc->ho_ener_circ, st->hTdCngEnc->ho_ener_circ_fx, Q6, HO_HIST_SIZE ); floatToFixed_arr( st->hTdCngEnc->exc_mem2, st->hTdCngEnc->exc_mem2_fx, q_inp, 30 ); for ( i = 0; i < M; i++ ) @@ -525,7 +520,6 @@ ivas_error acelp_core_enc( fixedToFloat_arrL32( q_env_fx, q_env, Q6, NUM_ENV_CNG ); fixedToFloat_arr( st->lsp_old_fx, st->lsp_old, Q15, M ); fixedToFloat_arr( st->hTdCngEnc->ho_lsp_circ_fx, st->hTdCngEnc->ho_lsp_circ, Q15, HO_HIST_SIZE * M ); - fixedToFloat_arr( st->hTdCngEnc->ho_lsp_circ2_fx, st->hTdCngEnc->ho_lsp_circ2, Q15, HO_HIST_SIZE * M ); fixedToFloat_arrL( st->hTdCngEnc->ho_env_circ_fx, st->hTdCngEnc->ho_env_circ, Q6, 160 ); fixedToFloat_arrL( st->hTdCngEnc->ho_ener_circ_fx, st->hTdCngEnc->ho_ener_circ, Q6, HO_HIST_SIZE ); fixedToFloat_arr( st->hTdCngEnc->exc_mem2_fx, st->hTdCngEnc->exc_mem2, q_inp, 30 ); @@ -767,7 +761,6 @@ ivas_error acelp_core_enc( IF( st->hLPDmem ) { st->hLPDmem->tilt_code = float_to_fix16( st->hLPDmem->tilt_code_flt, Q15 ); - st->hLPDmem->gc_threshold = float_to_fix16( st->hLPDmem->gc_threshold_flt, Q16 ); f2me_buf_16( &st->hLPDmem->mem_syn_flt[-1], &st->hLPDmem->mem_syn[-1], &st->hLPDmem->e_mem_syn, M + 1 ); // -1 to sync the exponent of mem_syn with mem_w0 } floatToFixed_arr( lsp_new, lsp_new_fx, Q15, M ); @@ -780,11 +773,8 @@ ivas_error acelp_core_enc( st->clip_var_fx[5] = float_to_fix16( st->clip_var[5], Q14 ); FOR( Word16 idx = 0; idx < M; idx++ ) { - st->lsf_adaptive_mean_fx[idx] = (Word16) ( st->lsf_adaptive_mean[idx] * 2.56f ); IF( tdm_lsfQ_PCh ) tdm_lsfQ_PCh_fx[idx] = (Word16) ( tdm_lsfQ_PCh[idx] * 2.56f ); - st->lsfoldbfi1_fx[idx] = (Word16) ( st->lsfoldbfi1[idx] * 2.56f ); - st->lsfoldbfi0_fx[idx] = (Word16) ( st->lsfoldbfi0[idx] * 2.56f ); } Q_old_bwe_exc = Q_factor_arr( old_bwe_exc, 1380 ); floatToFixed_arr( old_bwe_exc, old_bwe_exc_fx, Q_old_bwe_exc, 1380 ); @@ -1016,11 +1006,6 @@ ivas_error acelp_core_enc( lsf_new[i] = lsf_new_fx[i] / 2.56f; st->lsf_old[i] = st->lsf_old_fx[i] / 2.56f; - st->lsf_adaptive_mean[i] = st->lsf_adaptive_mean_fx[i] / 2.56f; - st->mem_MA[i] = st->mem_MA_fx[i] / 2.56f; - st->mem_AR[i] = st->mem_AR_fx[i] / 2.56f; - st->lsfoldbfi1[i] = st->lsfoldbfi1_fx[i] / 2.56f; - st->lsfoldbfi0[i] = st->lsfoldbfi0_fx[i] / 2.56f; } fixedToFloat_arrL( st->Bin_E_old_fx, st->Bin_E_old, q_comm_Bin, 128 ); fixedToFloat_arrL( st->Bin_E_fx, st->Bin_E, q_comm_Bin, 256 ); @@ -1128,7 +1113,6 @@ ivas_error acelp_core_enc( lsf_syn_mem_restore_ivas_fx( st, tilt_code_bck_fx, gc_threshold_bck_fx, clip_var_bck_fx, next_force_sf_bck, lsp_new_fx, lsp_mid_fx, clip_var_fx, mem_AR_fx, mem_MA_fx, lsp_new_bck_fx, lsp_mid_bck_fx, Bin_E_fx, Bin_E_old_fx, mem_syn_bck_fx, mem_w0_bck_fx, streaklimit_fx, pstreaklen ); #ifdef IVAS_FLOAT_FIXED_CONVERSIONS st->hLPDmem->tilt_code_flt = fix16_to_float( st->hLPDmem->tilt_code, Q15 ); - st->hLPDmem->gc_threshold_flt = fix_to_float( st->hLPDmem->gc_threshold, Q16 ); st->clip_var[0] = st->clip_var_fx[0] / 2.56f; st->clip_var[1] = fix16_to_float( st->clip_var_fx[1], Q14 ); st->clip_var[2] = fix16_to_float( st->clip_var_fx[2], Q7 ); @@ -1141,11 +1125,6 @@ ivas_error acelp_core_enc( fixedToFloat_arrL( st->Bin_E_old_fx, st->Bin_E_old, q_comm_Bin, L_FFT / 2 ); fixedToFloat_arr( st->hLPDmem->mem_syn, st->hLPDmem->mem_syn_flt, mem_syn, M ); st->hLPDmem->mem_w0_flt = me2f( st->hLPDmem->mem_w0, st->hLPDmem->e_mem_syn ); - for ( i = 0; i < M; i++ ) - { - st->mem_AR[i] = (float) st->mem_AR_fx[i] / 2.56f; - st->mem_MA[i] = (float) st->mem_MA_fx[i] / 2.56f; - } #endif #else lsf_syn_mem_restore( st, tilt_code_bck, gc_threshold_bck, clip_var_bck, next_force_sf_bck, lsp_new, lsp_mid, clip_var, mem_AR, mem_MA, lsp_new_bck, lsp_mid_bck, Bin_E, Bin_E_old, mem_syn_bck, mem_w0_bck, streaklimit, pstreaklen ); @@ -1268,13 +1247,10 @@ ivas_error acelp_core_enc( floatToFixed_arr( exc2, exc2_fx, Q_exc2, L_FRAME ); #endif floatToFixed_arr( Aq, Aq_fx, 12, NB_SUBFR16k * ( M + 1 ) ); - floatToFixed_arr( st->lspold_s, st->lspold_s_fx, 15, 16 ); - st->min_alpha_fx = float_to_fix16( st->min_alpha, 15 ); Word32 LepsP[2]; Word32 epsP_fx[M + 1]; Word16 e_epsP; f2me_buf( epsP, epsP_fx, &e_epsP, M + 1 ); - st->ge_sm_fx = float_to_fix( st->ge_sm, 6 ); st->exc_pe_fx = float_to_fix16( st->exc_pe, st->Q_stat_noise ); floatToFixed_arr( lsp_new, lsp_new_fx, 15, 16 ); floatToFixed_arr( lsp_mid, lsp_mid_fx, 15, 16 ); @@ -1289,9 +1265,6 @@ ivas_error acelp_core_enc( // conv params from fix to float fixedToFloat_arr( exc2_fx, exc2, Q_exc2, L_FRAME16k ); fixedToFloat_arr( Aq_fx, Aq, 12, NB_SUBFR16k * ( M + 1 ) ); - fixedToFloat_arr( st->lspold_s_fx, st->lspold_s, 15, 16 ); - st->min_alpha = fix16_to_float( st->min_alpha_fx, 15 ); - st->ge_sm = fix_to_float( st->ge_sm_fx, 6 ); st->exc_pe = fix16_to_float( st->exc_pe_fx, st->Q_stat_noise ); #endif #endif @@ -1498,11 +1471,22 @@ ivas_error acelp_core_enc( cng_params_upd( lsp_new, exc, st->L_frame, &st->hTdCngEnc->ho_circ_ptr, st->hTdCngEnc->ho_ener_circ, &st->hTdCngEnc->ho_circ_size, st->hTdCngEnc->ho_lsp_circ, ENC, st->hTdCngEnc->ho_env_circ, &st->hTdCngEnc->cng_buf_cnt, st->hTdCngEnc->cng_exc2_buf_flt, st->hTdCngEnc->cng_brate_buf, st->hDtxEnc->last_active_brate, st->element_mode, st->hFdCngEnc->hFdCngCom->CngBandwidth ); +#ifndef IVAS_FLOAT_FIXED if ( st->L_frame == L_FRAME ) { /* store LSPs@16k, potentially to be used in CNG@16k */ mvr2r( st->lsp_old16k, &( st->hTdCngEnc->ho_lsp_circ2[( st->hTdCngEnc->ho_circ_ptr ) * M] ), M ); } +#else +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + floatToFixed_arr( st->lsp_old16k, st->lsp_old16k_fx, Q15, M ); +#endif + IF( EQ_16( st->L_frame, L_FRAME ) ) + { + /* store LSPs@16k, potentially to be used in CNG@16k */ + Copy( st->lsp_old16k_fx, &( st->hTdCngEnc->ho_lsp_circ2_fx[( st->hTdCngEnc->ho_circ_ptr ) * M] ), M ); + } +#endif /* set LSP@16k flag for the first buffer */ st->hTdCngEnc->ho_16k_lsp[st->hTdCngEnc->ho_circ_ptr] = ( st->L_frame == L_FRAME ? 0 : 1 ); diff --git a/lib_enc/acelp_core_switch_enc.c b/lib_enc/acelp_core_switch_enc.c index 768ccf004..465df84a2 100644 --- a/lib_enc/acelp_core_switch_enc.c +++ b/lib_enc/acelp_core_switch_enc.c @@ -43,6 +43,7 @@ #include "prot.h" #include "wmc_auto.h" +#ifndef IVAS_FLOAT_FIXED /*---------------------------------------------------------------------* * Local function prototypes *---------------------------------------------------------------------*/ @@ -460,3 +461,4 @@ static void bwe_switch_enc( return; } +#endif diff --git a/lib_enc/core_enc_init.c b/lib_enc/core_enc_init.c index 633675002..add6c9675 100644 --- a/lib_enc/core_enc_init.c +++ b/lib_enc/core_enc_init.c @@ -424,8 +424,13 @@ void init_coder_ace_plus( st->next_force_safety_net = 0; if ( ( st->last_L_frame != st->L_frame ) || ( st->last_core == AMR_WB_CORE ) || ( st->last_core == HQ_CORE ) ) { +#ifndef IVAS_FLOAT_FIXED set_f( st->mem_MA, 0.0f, M ); mvr2r( GEWB_Ave, st->mem_AR, M ); +#else + set16_fx( st->mem_MA_fx, 0, M ); + Copy( GEWB_Ave_fx, st->mem_AR_fx, M ); +#endif } /* Initialize IGF */ @@ -1372,7 +1377,11 @@ static void init_acelp( if ( hLPDmem != NULL ) { set_zero( hLPDmem->dispMem_flt, 8 ); +#ifndef IVAS_FLOAT_FIXED hLPDmem->gc_threshold_flt = 0.0f; +#else + hLPDmem->gc_threshold = 0; +#endif } /* Pulse Search configuration */ diff --git a/lib_enc/core_enc_switch.c b/lib_enc/core_enc_switch.c index f6c196b42..6397c2d4c 100644 --- a/lib_enc/core_enc_switch.c +++ b/lib_enc/core_enc_switch.c @@ -220,12 +220,6 @@ void core_coder_mode_switch_ivas_fx( st->currEnergyHF = 0; - IF( ( NE_16( st->last_L_frame, st->L_frame ) ) || ( EQ_16( st->last_core, AMR_WB_CORE ) ) || ( EQ_16( st->last_core, HQ_CORE ) ) ) - { - set_f( st->mem_MA, 0.0f, M ); - mvr2r( GEWB_Ave, st->mem_AR, M ); - } - /* Initialize TCX */ IF( hTcxEnc != NULL ) { diff --git a/lib_enc/core_switching_enc.c b/lib_enc/core_switching_enc.c index fe6837e7a..029bdb8bb 100644 --- a/lib_enc/core_switching_enc.c +++ b/lib_enc/core_switching_enc.c @@ -213,13 +213,22 @@ void core_switching_pre_enc( set_f( hLPDmem->mem_syn1_flt, 0.0f, M ); hLPDmem->mem_w0_flt = 0.0f; hLPDmem->tilt_code_flt = 0.0f; +#ifndef IVAS_FLOAT_FIXED hLPDmem->gc_threshold_flt = 0.0f; +#else + hLPDmem->gc_threshold = 0; +#endif set_f( hLPDmem->dispMem_flt, 0, 8 ); } st->Nb_ACELP_frames = 0; +#ifndef IVAS_FLOAT_FIXED set_zero( st->mem_MA, M ); mvr2r( GEWB_Ave, st->mem_AR, M ); +#else + set16_fx( st->mem_MA_fx, 0, M ); + Copy( GEWB_Ave_fx, st->mem_AR_fx, M ); +#endif init_gp_clip( st->clip_var ); st->last_coder_type = GENERIC; @@ -261,7 +270,11 @@ void core_switching_pre_enc( hLPDmem->mem_w0_flt = 0.0f; hLPDmem->tilt_code_flt = 0.0f; init_gp_clip( st->clip_var ); +#ifndef IVAS_FLOAT_FIXED hLPDmem->gc_threshold_flt = 0.0f; +#else + hLPDmem->gc_threshold = 0; +#endif set_f( hLPDmem->dispMem_flt, 0, 8 ); } @@ -898,7 +911,11 @@ void core_switching_post_enc( if ( ( st->extl == SWB_TBE || st->extl == FB_TBE ) && ( st->last_core == HQ_CORE || st->L_frame != st->last_L_frame || ( st->last_extl != SWB_TBE && st->last_extl != FB_TBE && st->last_core != TCX_20_CORE && st->last_core != TCX_10_CORE ) ) ) { +#ifdef IVAS_FLOAT_FIXED + set16_fx( st->hBWE_TD->state_ana_filt_shb_fx, 0, ( 2 * ALLPASSSECTIONS_STEEP + 1 ) ); +#else set_f( st->hBWE_TD->state_ana_filt_shb, 0.0f, ( 2 * ALLPASSSECTIONS_STEEP + 1 ) ); +#endif #ifdef IVAS_FLOAT_FIXED InitSWBencBufferStates_fx( st->hBWE_TD, NULL ); swb_tbe_reset_fx( st->hBWE_TD->mem_csfilt_fx, st->hBWE_TD->mem_genSHBexc_filt_down_shb_fx, st->hBWE_TD->state_lpc_syn_fx, st->hBWE_TD->syn_overlap_fx, st->hBWE_TD->state_syn_shbexc_fx, &( st->hBWE_TD->tbe_demph_fx ), &( st->hBWE_TD->tbe_premph_fx ), st->hBWE_TD->mem_stp_swb_fx, &( st->hBWE_TD->gain_prec_swb_fx ) ); diff --git a/lib_enc/hq_core_enc.c b/lib_enc/hq_core_enc.c index 317f59eae..6345a1c63 100644 --- a/lib_enc/hq_core_enc.c +++ b/lib_enc/hq_core_enc.c @@ -678,10 +678,11 @@ void HQ_core_enc_init( hHQ_core->prev_stab_hfe2 = 0; #ifndef IVAS_FLOAT_FIXED hHQ_core->prev_ni_ratio = 0.5f; + set_f( hHQ_core->prev_En_sb, 0.0f, NB_SWB_SUBBANDS ); #else hHQ_core->prev_ni_ratio_fx = 16384; + set16_fx( hHQ_core->prev_En_sb_fx, 0, NB_SWB_SUBBANDS ); #endif - set_f( hHQ_core->prev_En_sb, 0.0f, NB_SWB_SUBBANDS ); set_s( hHQ_core->last_bitalloc_max_band, 0, 2 ); #ifndef IVAS_FLOAT_FIXED set_f( hHQ_core->last_ni_gain, 0, BANDS_MAX ); diff --git a/lib_enc/igf_enc.c b/lib_enc/igf_enc.c index a2ec04bba..bc926b32d 100644 --- a/lib_enc/igf_enc.c +++ b/lib_enc/igf_enc.c @@ -209,7 +209,7 @@ static Word16 IGF_getCrest_new_fx( move16(); return crest; } -#endif +#else static float IGF_getCrest_new( const int16_t *logSpec, /* i : power spectrum */ const int16_t start, /* i : start subband index */ @@ -242,6 +242,7 @@ static float IGF_getCrest_new( return crest; } +#endif /*-------------------------------------------------------------------* @@ -305,7 +306,7 @@ static Word16 IGF_getSFM_new_fx( return sfm; } -#endif +#else static float IGF_getSFM_new( const float *powerSpectrum, /* i : power spectrum */ const int16_t *logSpec, /* i : log of power spectrum */ @@ -343,6 +344,7 @@ static float IGF_getSFM_new( return sfm; } +#endif /*-------------------------------------------------------------------* @@ -546,7 +548,7 @@ static Word32 IGF_getTNR_fx( return tonalToNoise; } -#endif // IVAS_FLOAT_FIXED +#else static float IGF_getTNR( const float *powerSpectrum, /* i : energies */ const int16_t start, /* i : start subband index */ @@ -589,8 +591,10 @@ static float IGF_getTNR( return tonalToNoise; } +#endif +#ifndef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* * IGF_getCrest() * @@ -675,6 +679,7 @@ static float IGF_getSFM_ivas( return sfm; } +#endif /*-------------------------------------------------------------------* @@ -1991,6 +1996,7 @@ static void IGF_CalculateStereoEnvelope_fx( return; } #endif +#ifndef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* * IGF_CalculateStereoEnvelope() * @@ -2232,6 +2238,7 @@ static void IGF_CalculateStereoEnvelope( return; } +#endif /*-------------------------------------------------------------------* @@ -2384,6 +2391,7 @@ static int16_t IGF_WriteEnvelope( #endif +#ifndef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* * IGF_ErodeSpectrum() * @@ -2513,6 +2521,7 @@ static float IGF_ErodeSpectrum_ivas( return highPassEner; } +#endif /*-------------------------------------------------------------------* @@ -2968,6 +2977,7 @@ static void IGF_Whitening_ivas_fx( } #endif // IVAS_FLOAT_FIXED +#ifndef IVAS_FLOAT_FIXED static void IGF_Whitening( const IGF_ENC_INSTANCE_HANDLE hIGFEnc, /* i : | instance handle of IGF Encoder */ float *powerSpectrum, /* i : Q31 | MDCT/MDST power spectrum */ @@ -3310,6 +3320,7 @@ static void IGF_Whitening( return; } +#endif /*-------------------------------------------------------------------* @@ -4282,6 +4293,7 @@ void IGFEncApplyMono( * * apply the IGF encoder, main encoder interface *-------------------------------------------------------------------*/ + #ifdef IVAS_FLOAT_FIXED void IGFEncApplyStereo_fx( STEREO_MDCT_ENC_DATA_HANDLE hStereoMdct, /* i/o: MDCT stereo encoder structure */ @@ -4372,8 +4384,7 @@ void IGFEncApplyStereo_fx( } return; } -#endif // IVAS_FLOAT_FIXED - +#else void IGFEncApplyStereo( STEREO_MDCT_ENC_DATA_HANDLE hStereoMdct, /* i/o: MDCT stereo encoder structure */ int16_t ms_mask[2][MAX_SFB], /* i : bandwise MS mask */ @@ -4450,6 +4461,7 @@ void IGFEncApplyStereo( return; } +#endif /*-------------------------------------------------------------------* diff --git a/lib_enc/init_enc.c b/lib_enc/init_enc.c index 6e051302f..98f4a3df5 100644 --- a/lib_enc/init_enc.c +++ b/lib_enc/init_enc.c @@ -143,20 +143,28 @@ ivas_error init_encoder( * Pre-processing and ACELP core parameters *-----------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED mvr2r( GEWB_Ave, st->mem_AR, M ); mvr2r( GEWB_Ave, st->lsfoldbfi0, M ); mvr2r( GEWB_Ave, st->lsfoldbfi1, M ); mvr2r( GEWB_Ave, st->lsf_adaptive_mean, M ); +#else + Copy( GEWB_Ave_fx, st->mem_AR_fx, M ); + Copy( GEWB_Ave_fx, st->lsfoldbfi0_fx, M ); + Copy( GEWB_Ave_fx, st->lsfoldbfi1_fx, M ); + Copy( GEWB_Ave_fx, st->lsf_adaptive_mean_fx, M ); +#endif st->next_force_safety_net = 0; st->pstreaklen = 0; #ifndef IVAS_FLOAT_FIXED st->streaklimit = 1.0f; + set_f( st->mem_MA, 0, M ); #else st->streaklimit_fx = 32767; + set16_fx( st->mem_MA_fx, 0, M ); #endif - set_f( st->mem_MA, 0, M ); init_gp_clip( st->clip_var ); pitch_ol_init( @@ -195,9 +203,10 @@ ivas_error init_encoder( set_f( st->mem_decim2, 0, 3 ); set_f( st->Bin_E, 0, L_FFT ); +#ifndef IVAS_FLOAT_FIXED st->ee_old = 10.0f; -#ifdef IVAS_FLOAT_FIXED - st->ee_old_fx = 10 << 6; // 10 in Q6 +#else + st->ee_old_fx = 640; #endif st->Nb_ACELP_frames = 0; st->audio_frame_cnt = AUDIO_COUNTER_INI; /* Initialization of the audio frame counter mildly into the audio mode */ @@ -250,12 +259,17 @@ ivas_error init_encoder( st->tc_cnt = 0; /* find_uv() parameters */ +#ifndef IVAS_FLOAT_FIXED st->old_dE1 = 0.0f; -#ifdef IVAS_FLOAT_FIXED +#else st->old_dE1_fx = 0; #endif st->old_ind_deltaMax = 0; +#ifndef IVAS_FLOAT_FIXED set_f( st->old_enr_ssf, 0.0f, 2 * NB_SSF ); +#else + set32_fx( st->old_enr_ssf_fx, 0, 2 * NB_SSF ); +#endif st->spike_hyst = -1; /* stereo switching memories */ @@ -271,12 +285,27 @@ ivas_error init_encoder( st->sharpFlag = 0; #endif /* Stationary noise UV modification */ +#ifndef IVAS_FLOAT_FIXED st->ge_sm = 10; +#else + st->ge_sm_fx = L_deposit_l( 640 ); +#endif st->uv_count = 0; st->act_count = 3; +#ifndef IVAS_FLOAT_FIXED mvr2r( st->lsp_old, st->lspold_s, M ); +#else +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + floatToFixed_arr( st->lsp_old, st->lsp_old_fx, Q15, M ); +#endif + Copy( st->lsp_old_fx, st->lspold_s_fx, M ); +#endif st->noimix_seed = RANDOM_INITSEED; +#ifndef IVAS_FLOAT_FIXED st->min_alpha = 1; +#else + st->min_alpha_fx = 32767; +#endif st->exc_pe = 0; #ifdef IVAS_FLOAT_FIXED st->exc_pe_fx = 0; @@ -1230,12 +1259,7 @@ ivas_error init_encoder_ivas_fx( Copy( GEWB_Ave_fx, st->lsfoldbfi1_fx, M ); Copy( GEWB_Ave_fx, st->lsf_adaptive_mean_fx, M ); #if 1 // TODO: Float Initializations. To be removed later - mvr2r( GEWB_Ave, st->mem_AR, M ); - mvr2r( GEWB_Ave, st->lsfoldbfi0, M ); - mvr2r( GEWB_Ave, st->lsfoldbfi1, M ); - mvr2r( GEWB_Ave, st->lsf_adaptive_mean, M ); init_gp_clip( st->clip_var ); - set_zero( st->mem_MA, M ); pitch_ol_init( #ifndef IVAS_FLOAT_FIXED &st->old_thres, @@ -1278,8 +1302,6 @@ ivas_error init_encoder_ivas_fx( st->mem_wsp = 0.0f; set_f( st->mem_decim2, 0, 3 ); set_f( st->Bin_E, 0, L_FFT ); - st->ee_old = 10.0f; - st->old_dE1 = 0.0f; if ( st->Opt_AMR_WB ) { mvr2r( mean_isf_amr_wb, st->lsf_old, M ); @@ -1294,12 +1316,10 @@ ivas_error init_encoder_ivas_fx( mvr2r( st->lsp_old1, st->lsp_old, M ); mvr2r( st->lsp_old, st->lsp_old16k, M ); mvr2r( st->lsp_old, st->lspold_enc, M ); - set_f( st->old_enr_ssf, 0.0f, 2 * NB_SSF ); st->mem_preemph_DFT = 0.0f; set_f( st->inp_12k8_mem_stereo_sw, 0, STEREO_DFT_OVL_12k8 - L_MEM_RECALC_12K8 - L_FILT ); st->mem_preemph16k_DFT = 0.0f; set_f( st->inp_16k_mem_stereo_sw, 0, STEREO_DFT_OVL_16k - L_MEM_RECALC_16K - L_FILT16k ); - mvr2r( st->lsp_old, st->lspold_s, M ); set_f( st->old_Aq_12_8 + 1, 0, M ); st->old_Aq_12_8[0] = 4096; st->voicing0_sm = 0; @@ -1317,7 +1337,6 @@ ivas_error init_encoder_ivas_fx( st->EnergyLT = 0.0f; st->Energy_Old = 0; #endif - st->min_alpha = 1; #ifndef IVAS_FLOAT_FIXED st->prev_fmerit_flt = 0; st->fmerit_dt_flt = 0; @@ -1350,7 +1369,7 @@ ivas_error init_encoder_ivas_fx( set16_fx( st->mem_decim2_fx, 0, 3 ); set32_fx( st->Bin_E_fx, 0, L_FFT ); - st->ee_old_fx = 640; /*chk //10 in Q6 */ + st->ee_old_fx = 640; /* 10.0f in Q6 */ move16(); st->Nb_ACELP_frames = 0; move16(); @@ -1430,9 +1449,7 @@ ivas_error init_encoder_ivas_fx( st->sharpFlag = 0; /* Stationary noise UV modification */ - st->ge_sm_fx = 10; /*chk //10 in Q6 */ - move16(); - st->ge_sm = 10; /*chk //10 in Q6 */ + st->ge_sm_fx = L_deposit_l( 640 ); /*Q(GE_SHIFT)*/ move16(); st->uv_count = 0; move16(); @@ -2248,12 +2265,6 @@ ivas_error init_encoder_ivas_fx( st->currEnergyHF = 0; - IF( ( NE_16( st->last_L_frame, st->L_frame ) ) || ( EQ_16( st->last_core, AMR_WB_CORE ) ) || ( EQ_16( st->last_core, HQ_CORE ) ) ) - { - set_f( st->mem_MA, 0.0f, M ); - mvr2r( GEWB_Ave, st->mem_AR, M ); - } - /* Initialize TCX */ IF( hTcxEnc != NULL ) { @@ -2416,7 +2427,11 @@ void LPDmem_enc_init( set_f( hLPDmem->mem_syn3_flt, 0, M ); hLPDmem->tilt_code_flt = 0.0f; +#ifndef IVAS_FLOAT_FIXED hLPDmem->gc_threshold_flt = 0.0f; +#else + hLPDmem->gc_threshold = 0; +#endif set_f( hLPDmem->dispMem_flt, 0, 8 ); return; diff --git a/lib_enc/ivas_core_enc.c b/lib_enc/ivas_core_enc.c index 20ac14fb6..32ea92422 100644 --- a/lib_enc/ivas_core_enc.c +++ b/lib_enc/ivas_core_enc.c @@ -489,7 +489,6 @@ ivas_error ivas_core_enc( fixedToFloat_arr( st->hTdCngEnc->ho_lsp_circ_fx, st->hTdCngEnc->ho_lsp_circ, Q15, HO_HIST_SIZE * M ); fixedToFloat_arrL( st->hTdCngEnc->ho_env_circ_fx, st->hTdCngEnc->ho_env_circ, Q6, HO_HIST_SIZE * NUM_ENV_CNG ); // fixedToFloat_arr( st->hTdCngEnc->cng_exc2_buf, st->hTdCngEnc->cng_exc2_buf_flt, Q_exc, HO_HIST_SIZE * L_FFT ); - fixedToFloat_arr( st->hTdCngEnc->ho_lsp_circ2_fx, st->hTdCngEnc->ho_lsp_circ2, M, Q15 ); } st->hTcxEnc->measuredBwRatio_flt = fix16_to_float( st->hTcxEnc->measuredBwRatio, Q14 ); @@ -507,9 +506,6 @@ ivas_error ivas_core_enc( for ( int j = 0; j < M; j++ ) { st->lsf_old[j] = (float) st->lsf_old_fx[j] / 2.56f; - st->lsf_adaptive_mean[j] = (float) st->lsf_adaptive_mean_fx[j] / 2.56f; - st->mem_AR[j] = (float) st->mem_AR_fx[j] / 2.56f; - st->mem_MA[j] = (float) st->mem_MA_fx[j] / 2.56f; } for ( int k = 0; k < 2; k++ ) { @@ -1423,12 +1419,6 @@ ivas_error ivas_core_enc( me2f_buf_16( st->hTcxEnc->buf_speech_ltp, st->hTcxEnc->exp_buf_speech_ltp, st->hTcxEnc->buf_speech_ltp_flt, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k ); } - IF( ( st->Opt_DTX_ON && LE_32( st->core_brate, SID_2k40 ) && EQ_16( st->cng_type, FD_CNG ) ) || ( st->tcxonly && ( EQ_16( st->codec_mode, MODE2 ) || GT_16( st->element_mode, EVS_MONO ) ) ) ) - { - set_zero( st->mem_MA, M ); - mvr2r( GEWB_Ave, st->mem_AR, M ); - } - IF( st->element_mode > EVS_MONO && st->hTcxEnc != NULL ) { st->hTcxEnc->tcxltp_norm_corr_mem_flt = fixedToFloat( st->hTcxEnc->tcxltp_norm_corr_mem, 15 ); diff --git a/lib_enc/ivas_core_pre_proc_front.c b/lib_enc/ivas_core_pre_proc_front.c index b84e82262..1a6970133 100644 --- a/lib_enc/ivas_core_pre_proc_front.c +++ b/lib_enc/ivas_core_pre_proc_front.c @@ -2383,9 +2383,6 @@ ivas_error pre_proc_front_ivas_fx( } st->hNoiseEst->Etot_last_fx = float_to_fix16( st->hNoiseEst->Etot_last, Q8 ); - - floatToFixed_arr32( st->old_enr_ssf, st->old_enr_ssf_fx, 0, 2 * NB_SSF ); - #endif // IVAS_FLOAT_FIXED_CONVERSIONS /* Detection of very short stable pitch period */ @@ -2473,8 +2470,6 @@ ivas_error pre_proc_front_ivas_fx( fixedToFloat_arrL32( ee_fx, ee, Q6, 2 ); fixedToFloat_arrL32( hp_E_fx, hp_E, q_fr_bands, 2 ); - fixedToFloat_arrL32( st->old_enr_ssf_fx, st->old_enr_ssf, 0, 2 * NB_SSF ); - non_staX = fixedToFloat_16( non_staX16_fx, Q8 ); sp_div = fixedToFloat_16( sp_div16_fx, q_sp_div ); *cor_map_sum = fixedToFloat_16( cor_map_sum16_fx, Q8 ); diff --git a/lib_enc/ivas_cpe_enc.c b/lib_enc/ivas_cpe_enc.c index 46fc42291..2b8930a55 100644 --- a/lib_enc/ivas_cpe_enc.c +++ b/lib_enc/ivas_cpe_enc.c @@ -733,9 +733,6 @@ ivas_error ivas_cpe_enc( sts[0]->old_corr_fx = float_to_fix16( sts[0]->old_corr, Q15 ); sts[1]->old_corr_fx = float_to_fix16( sts[1]->old_corr, Q15 ); - sts[0]->ee_old_fx = floatToFixed( sts[0]->ee_old, Q6 ); - sts[1]->ee_old_fx = floatToFixed( sts[1]->ee_old, Q6 ); - IF( hCPE->hStereoTD->tdm_last_SM_flag ) { floatToFixed_arr16( sts[0]->input, sts[0]->input_fx, 0, input_frame ); diff --git a/lib_enc/ivas_dirac_enc.c b/lib_enc/ivas_dirac_enc.c index 45a008543..5dc8c4f61 100644 --- a/lib_enc/ivas_dirac_enc.c +++ b/lib_enc/ivas_dirac_enc.c @@ -1842,6 +1842,8 @@ void ivas_dirac_param_est_enc( /* Sectors */ IF( hodirac_flag ) { + Word32 L_tmp, L_tmp1; + Word16 e_tmp, e_tmp1, exp_diff; FOR( band_m_idx = 0; band_m_idx < hDirAC->hConfig->nbands; band_m_idx++ ) { q_direction->band_data[band_m_idx].azimuth_fx[block_m_idx] = L_shr( azi_secs_fx[band_m_idx], 1 ); // Q23 -> Q22 @@ -1854,20 +1856,21 @@ void ivas_dirac_param_est_enc( q_direction[1].band_data[band_m_idx].elevation_fx[block_m_idx] = L_shr( ele_secs_fx[num_freq_bands + band_m_idx], 1 ); // Q23 -> Q22 move32(); - Word32 x = L_sub( ONE_IN_Q30, L_shr( diff_secs_fx[band_m_idx], sub( 1, diff_secs_exp[band_m_idx] ) ) ); - Word32 y = L_sub( ONE_IN_Q30, L_shr( diff_secs_fx[num_freq_bands + band_m_idx], sub( 1, diff_secs_exp[num_freq_bands + band_m_idx] ) ) ); - - Word16 tmp16 = extract_h( L_add( x, y ) ); - Word32 tmp32; - IF( tmp16 == 0 ) + L_tmp = BASOP_Util_Add_Mant32Exp( ONE_IN_Q30, Q1, L_negate( diff_secs_fx[band_m_idx] ), diff_secs_exp[band_m_idx], &e_tmp ); + L_tmp1 = BASOP_Util_Add_Mant32Exp( ONE_IN_Q30, Q1, L_negate( diff_secs_fx[num_freq_bands + band_m_idx] ), diff_secs_exp[num_freq_bands + band_m_idx], &e_tmp1 ); + L_tmp1 = BASOP_Util_Add_Mant32Exp( L_tmp, e_tmp, L_tmp1, e_tmp1, &e_tmp1 ); + IF( L_tmp1 == 0 ) { - tmp32 = L_deposit_h( div_l( x, EPSILON_FX ) ); + q_direction[1].band_data[band_m_idx].energy_ratio_fx[block_m_idx] = L_shl( div_l( L_tmp, EPSILON_FX ), Q30 - Q15 ); // Q30 + move32(); } ELSE { - tmp32 = L_deposit_h( div_l( x, tmp16 ) ); + L_tmp = L_deposit_h( BASOP_Util_Divide3232_Scale( L_tmp, L_add( L_tmp1, EPSILON_FX ), &exp_diff ) ); + exp_diff = add( exp_diff, sub( e_tmp, e_tmp1 ) ); + q_direction[1].band_data[band_m_idx].energy_ratio_fx[block_m_idx] = L_shl( L_tmp, sub( exp_diff, Q1 ) ); // Q30 + move32(); } - tmp32 = L_shr( tmp32, 1 ); // Q31 -> Q30 } } } diff --git a/lib_enc/ivas_masa_enc.c b/lib_enc/ivas_masa_enc.c index 63354efd4..4c27158a0 100644 --- a/lib_enc/ivas_masa_enc.c +++ b/lib_enc/ivas_masa_enc.c @@ -551,7 +551,7 @@ ivas_error ivas_masa_encode_fx( ivas_error error; Word16 guard_bits, tmp; - guard_bits = find_guarded_bits_fx( 24 ); + guard_bits = find_guarded_bits_fx( 9 ); masa_sid_descriptor = -1; h_orig_metadata = NULL; @@ -2381,6 +2381,9 @@ static void combine_freqbands_and_subframes_fx( Word32 x[MASA_MAXIMUM_DIRECTIONS][MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; Word32 y[MASA_MAXIMUM_DIRECTIONS][MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; Word32 z[MASA_MAXIMUM_DIRECTIONS][MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; + Word16 x_e[MASA_MAXIMUM_DIRECTIONS][MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; + Word16 y_e[MASA_MAXIMUM_DIRECTIONS][MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; + Word16 z_e[MASA_MAXIMUM_DIRECTIONS][MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; Word32 vecLen; Word16 vecLen_e; Word32 xSum, ySum, zSum; @@ -2468,12 +2471,27 @@ static void combine_freqbands_and_subframes_fx( eleRad = extract_l( L_shl( Mpy_32_32( hMeta->directional_meta[i].elevation_fx[j][k], PI_OVER_180_FX ), Q13 - Q22 ) ); // ((Q22, Q31) -> Q22) >> Q9 -> Q13 vecLen = Mpy_32_32( hMeta->directional_meta[i].energy_ratio_fx[j][k], hMasa->data.energy_fx[j][k] ); // (Q30, 31-hMasa->data.energy_e[j][k]) -> (31-hMasa->data.energy_e[j][k]) - Q1 - x[i][j][k] = Mpy_32_32( L_mult( getCosWord16( aziRad ), getCosWord16( eleRad ) ), vecLen ); // (Q29, (31-hMasa->data.energy_e[j][k]) - Q1) -> (31-hMasa->data.energy_e[j][k]) - Q3 + /* Need more precision for some DTX cases with low energy frames */ + W_tmp = W_mult0_32_32( L_mult( getCosWord16( aziRad ), getCosWord16( eleRad ) ), vecLen ); // (Q29, (31-hMasa->data.energy_e[j][k]) - Q1) -> (Q59 - hMasa->data.energy_e[j][k]) + q_shift = W_norm( W_tmp ); + x[i][j][k] = W_extract_h( W_shl( W_tmp, q_shift ) ); move32(); - y[i][j][k] = Mpy_32_32( L_mult0( getSinWord16( aziRad ), getCosWord16( eleRad ) ), vecLen ); // (Q29, (31-hMasa->data.energy_e[j][k]) - Q1) -> (31-hMasa->data.energy_e[j][k]) - Q3 + x_e[i][j][k] = sub( Q31, add( sub( 59, hMasa->data.energy_e[j][k] ), sub( q_shift, 32 ) ) ); + move16(); + + W_tmp = W_mult0_32_32( L_mult0( getSinWord16( aziRad ), getCosWord16( eleRad ) ), vecLen ); // (Q29, (31-hMasa->data.energy_e[j][k]) - Q1) -> (Q59 - hMasa->data.energy_e[j][k]) + q_shift = W_norm( W_tmp ); + y[i][j][k] = W_extract_h( W_shl( W_tmp, q_shift ) ); move32(); - z[i][j][k] = Mpy_32_32( L_mult0( getSinWord16( eleRad ), ONE_IN_Q14 ), vecLen ); // (Q29, (31-hMasa->data.energy_e[j][k]) - Q1) -> (31-hMasa->data.energy_e[j][k]) - Q3 + y_e[i][j][k] = sub( Q31, add( sub( 59, hMasa->data.energy_e[j][k] ), sub( q_shift, 32 ) ) ); + move16(); + + W_tmp = W_mult0_32_32( L_mult0( getSinWord16( eleRad ), ONE_IN_Q14 ), vecLen ); // (Q29, (31-hMasa->data.energy_e[j][k]) - Q1) -> (Q59 - hMasa->data.energy_e[j][k]) + q_shift = W_norm( W_tmp ); + z[i][j][k] = W_extract_h( W_shl( W_tmp, q_shift ) ); move32(); + z_e[i][j][k] = sub( Q31, add( sub( 59, hMasa->data.energy_e[j][k] ), sub( q_shift, 32 ) ) ); + move16(); } } } @@ -2512,9 +2530,9 @@ static void combine_freqbands_and_subframes_fx( FOR( m = brange[0]; m < brange[1]; m++ ) { - xSum = BASOP_Util_Add_Mant32Exp( xSum, xSum_e, x[i][j][m], add( hMasa->data.energy_e[j][m], 3 ), &xSum_e ); // xSum_e - ySum = BASOP_Util_Add_Mant32Exp( ySum, ySum_e, y[i][j][m], add( hMasa->data.energy_e[j][m], 3 ), &ySum_e ); // ySum_e - zSum = BASOP_Util_Add_Mant32Exp( zSum, zSum_e, z[i][j][m], add( hMasa->data.energy_e[j][m], 3 ), &zSum_e ); // zSum_e + xSum = BASOP_Util_Add_Mant32Exp( xSum, xSum_e, x[i][j][m], x_e[i][j][m], &xSum_e ); // xSum_e + ySum = BASOP_Util_Add_Mant32Exp( ySum, ySum_e, y[i][j][m], y_e[i][j][m], &ySum_e ); // ySum_e + zSum = BASOP_Util_Add_Mant32Exp( zSum, zSum_e, z[i][j][m], z_e[i][j][m], &zSum_e ); // zSum_e energySum = BASOP_Util_Add_Mant32Exp( energySum, energySum_e, hMasa->data.energy_fx[j][m], hMasa->data.energy_e[j][m], &energySum_e ); // energySum_e } common_e = add( s_max( xSum_e, s_max( ySum_e, zSum_e ) ), 2 ); /*2 is guard bit for addition operations*/ @@ -2563,7 +2581,8 @@ static void combine_freqbands_and_subframes_fx( hMeta->directional_meta[i].spread_coherence_fx[j][k] = BASOP_Util_Divide3232_Scale( spreadCohSum, L_add( energySum, EPSILON_FX ), &exp_diff ); /*exp_diff+spreadCohSum_e-energySum_e*/ exp_diff = add( exp_diff, sub( spreadCohSum_e, energySum_e ) ); move16(); - hMeta->directional_meta[i].spread_coherence_fx[j][k] = shl( hMeta->directional_meta[i].spread_coherence_fx[j][k], exp_diff ); // Q15 + /* Saturation - LTV fix for values close to 1.0f+ */ + hMeta->directional_meta[i].spread_coherence_fx[j][k] = shl_sat( hMeta->directional_meta[i].spread_coherence_fx[j][k], exp_diff ); // Q15 move16(); IF( i == 0 ) @@ -2579,7 +2598,8 @@ static void combine_freqbands_and_subframes_fx( hMeta->common_meta.surround_coherence_fx[j][k] = BASOP_Util_Divide3232_Scale( surrCohSum, L_add( energySum, EPSILON_FX ), &exp_diff ); /*exp_diff+surrCohSum_e-energySum_e*/ move16(); exp_diff = add( exp_diff, sub( surrCohSum_e, energySum_e ) ); - hMeta->common_meta.surround_coherence_fx[j][k] = shl( hMeta->common_meta.surround_coherence_fx[j][k], exp_diff ); // Q15 + /* Saturation - LTV fix for values close to 1.0f+ */ + hMeta->common_meta.surround_coherence_fx[j][k] = shl_sat( hMeta->common_meta.surround_coherence_fx[j][k], exp_diff ); // Q15 move16(); } } @@ -2882,11 +2902,8 @@ void ivas_masa_combine_directions_fx( Word16 exp_sumVecLen_buff[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], exp_sumVecLen = MIN16B_FLT_FX; move16(); Word32 tempImportance_fx; - Word16 exp_tmp_importance = 0; - move16(); Word32 importance_fx[MASA_FREQUENCY_BANDS]; - Word16 exp_importance_buff[MASA_FREQUENCY_BANDS], exp_importance = MIN16B_FLT_FX; - move16(); + Word16 exp_importance; Word16 indicesOfLargest[MASA_FREQUENCY_BANDS]; Word32 ratioSum_fx; @@ -3004,41 +3021,29 @@ void ivas_masa_combine_directions_fx( } /* Estimate the importance of having two directions instead of one */ + /* Reduced precision of importance_fx intentionally to Q13 to maintatin 0.0001f resolution */ FOR( i = 0; i < numCodingBands; i++ ) { importance_fx[i] = 0; move32(); FOR( j = 0; j < numSf; j++ ) { - tempImportance_fx = L_add( hMeta->directional_meta[0].energy_ratio_fx[j][i], hMeta->directional_meta[1].energy_ratio_fx[j][i] ); - exp_tmp_importance = 0; - move16(); - tempImportance_fx = BASOP_Util_Add_Mant32Exp( tempImportance_fx, 31 - Q30, L_negate( sumVecLen_fx[j][i] ), exp_sumVecLen, &exp_tmp_importance ); - importance_fx[i] = BASOP_Util_Add_Mant32Exp( importance_fx[i], exp_importance_buff[i], tempImportance_fx, exp_tmp_importance, &exp_importance_buff[i] ); + tempImportance_fx = L_shr( L_add( hMeta->directional_meta[0].energy_ratio_fx[j][i], hMeta->directional_meta[1].energy_ratio_fx[j][i] ), Q30 - Q13 ); // Q13 + tempImportance_fx = L_sub( tempImportance_fx, L_shr( sumVecLen_fx[j][i], sub( sub( Q31, exp_sumVecLen ), Q13 ) ) ); // Q13 + importance_fx[i] = L_add( importance_fx[i], tempImportance_fx ); // Q13 move32(); } IF( NE_16( numSf, 1 ) ) { - importance_fx[i] = L_shr( importance_fx[i], 2 ); + importance_fx[i] = L_shr( importance_fx[i], 2 ); // Q13 move32(); } - importance_fx[i] = Mpy_32_32( importance_fx[i], hMasa->data.importanceWeight_fx[i] ); - move32(); - exp_importance_buff[i] = add( exp_importance_buff[i], 1 ); - move16(); - } - - /*make commen exp for importance_fx buffer*/ - FOR( i = 0; i < numCodingBands; i++ ) - { - exp_importance = s_max( exp_importance_buff[i], exp_importance ); - } - FOR( i = 0; i < numCodingBands; i++ ) - { - importance_fx[i] = L_shr( importance_fx[i], sub( exp_importance, exp_importance_buff[i] ) ); + importance_fx[i] = Mpy_32_32( importance_fx[i], hMasa->data.importanceWeight_fx[i] ); //(Q13, Q30) -> Q12 move32(); } + exp_importance = Q31 - Q12; + move16(); /* Determine bands where to use two directions */ find_n_largest_fx( importance_fx, exp_importance, indicesOfLargest, numCodingBands, hMasa->config.numTwoDirBands ); @@ -5996,8 +6001,8 @@ static void masa_metadata_direction_alignment_fx( FOR( band = 0; band < MASA_FREQUENCY_BANDS; band++ ) { UWord8 sf; - Word16 diff_swap_fx; - Word16 diff_no_swap_fx; + Word32 diff_swap_fx; + Word32 diff_no_swap_fx; /* trade 2*(cos+sin) against storing the values between frames */ Word16 prev_ele_dir1_sin_fx, prev_ele_dir2_sin_fx; @@ -6041,7 +6046,9 @@ static void masa_metadata_direction_alignment_fx( LT_32( L_abs( L_sub( ele_rad2_fx, hAlignState->previous_ele_dir2_fx[band] ) ), EPSILON_FX ) ) { diff_swap_fx = ONE_IN_Q13; /*1 q13*/ + move32(); diff_no_swap_fx = 0; + move32(); /* cached values that will be used for the short-cuts and over-written by the real computations, if done */ sin_ele1_fx = prev_ele_dir1_sin_fx; /*q15*/ sin_ele2_fx = prev_ele_dir2_sin_fx; /*q15*/ @@ -6051,8 +6058,6 @@ static void masa_metadata_direction_alignment_fx( move16(); move16(); move16(); - move16(); - move16(); } ELSE IF( LT_32( L_abs( L_sub( azi_rad1_fx, hAlignState->previous_azi_dir2_fx[band] ) ), EPSILON_FX ) && LT_32( L_abs( L_sub( azi_rad2_fx, hAlignState->previous_azi_dir1_fx[band] ) ), EPSILON_FX ) && @@ -6060,7 +6065,9 @@ static void masa_metadata_direction_alignment_fx( LT_32( L_abs( L_sub( ele_rad2_fx, hAlignState->previous_ele_dir1_fx[band] ) ), EPSILON_FX ) ) { diff_swap_fx = 0; + move32(); diff_no_swap_fx = ONE_IN_Q13; /*1.0 q13*/ + move32(); /* cached values that will be used for the short-cuts and over-written by the real computations, if done */ sin_ele1_fx = prev_ele_dir2_sin_fx; /*q15*/ sin_ele2_fx = prev_ele_dir1_sin_fx; /*q15*/ @@ -6070,8 +6077,6 @@ static void masa_metadata_direction_alignment_fx( move16(); move16(); move16(); - move16(); - move16(); } ELSE { @@ -6089,8 +6094,8 @@ static void masa_metadata_direction_alignment_fx( temp1_e = 1; /*stores expoenent for square root operation*/ move16(); temp2 = Sqrt32( L_sub( ONE_IN_Q30, L_mult0( temp1, temp1 ) ), &temp1_e ); /*31-temp1_e*/ - temp1 = BASOP_util_atan2( temp2, abs_s( temp1 ), sub( temp1_e, 16 ) ); /*q13*/ - diff_no_swap_fx = temp1; /*q13*/ + temp1 = BASOP_util_atan2( temp2, temp1, sub( temp1_e, 16 ) ); /*q13*/ + diff_no_swap_fx = L_deposit_l( temp1 ); /*q13*/ temp1 = getCosWord16R2( extract_l( Mpy_32_32( L_sub( azi_rad2_fx, hAlignState->previous_azi_dir2_fx[band] ), 2670177 /*2^24/(2*pi)*/ ) ) ); /*q15*/ temp1 = mult( mult( temp1, cos_ele2_fx ) /*q31*/, prev_ele_dir2_cos_fx /*q15*/ ); /*q15*/ @@ -6098,8 +6103,8 @@ static void masa_metadata_direction_alignment_fx( temp1_e = 1; /*stores expoenent for square root operation*/ move16(); temp2 = Sqrt32( L_sub( ONE_IN_Q30, L_mult0( temp1, temp1 ) ), &temp1_e ); /*31-temp1_e*/ - temp1 = BASOP_util_atan2( temp2, abs_s( temp1 ), sub( temp1_e, 16 ) ); /*q13*/ - diff_no_swap_fx = add( diff_no_swap_fx, temp1 ); /*q13*/ + temp1 = BASOP_util_atan2( temp2, temp1, sub( temp1_e, 16 ) ); /*q13*/ + diff_no_swap_fx = L_add( diff_no_swap_fx, temp1 ); /*q13*/ temp1 = getCosWord16R2( extract_l( Mpy_32_32( L_sub( azi_rad1_fx, hAlignState->previous_azi_dir2_fx[band] ), 2670177 /*2^24/(2*pi)*/ ) ) ); /*q15*/ temp1 = mult( mult( temp1, cos_ele1_fx ) /*q31*/, prev_ele_dir2_cos_fx /*q15*/ ); /*q15*/ @@ -6107,8 +6112,8 @@ static void masa_metadata_direction_alignment_fx( temp1_e = 1; /*stores expoenent for square root operation*/ move16(); temp2 = Sqrt32( L_sub( ONE_IN_Q30, L_mult0( temp1, temp1 ) ), &temp1_e ); /*31-temp1_e*/ - temp1 = BASOP_util_atan2( temp2, abs_s( temp1 ), sub( temp1_e, 16 ) ); /*q13*/ - diff_swap_fx = temp1; /*q13*/ + temp1 = BASOP_util_atan2( temp2, temp1, sub( temp1_e, 16 ) ); /*q13*/ + diff_swap_fx = L_deposit_l( temp1 ); /*q13*/ temp1 = getCosWord16R2( extract_l( Mpy_32_32( L_sub( azi_rad2_fx, hAlignState->previous_azi_dir1_fx[band] ), 2670177 /*2^24/(2*pi)*/ ) ) ); /*q15*/ temp1 = mult( mult( temp1, cos_ele2_fx ) /*q31*/, prev_ele_dir1_cos_fx /*q15*/ ); /*q15*/ @@ -6116,8 +6121,8 @@ static void masa_metadata_direction_alignment_fx( temp1_e = 1; /*stores expoenent for square root operation*/ move16(); temp2 = Sqrt32( L_sub( ONE_IN_Q30, L_mult0( temp1, temp1 ) ), &temp1_e ); /*31-temp1_e*/ - temp1 = BASOP_util_atan2( temp2, abs_s( temp1 ), sub( temp1_e, 16 ) ); /*q13*/ - diff_swap_fx = add( diff_swap_fx, temp1 ); /*q13*/ + temp1 = BASOP_util_atan2( temp2, temp1, sub( temp1_e, 16 ) ); /*q13*/ + diff_swap_fx = L_add( diff_swap_fx, temp1 ); /*q13*/ } } ELSE @@ -6138,12 +6143,12 @@ static void masa_metadata_direction_alignment_fx( diff_swap_fx = ONE_IN_Q13; /*1.0 in Q13*/ diff_no_swap_fx = 0; - move16(); - move16(); + move32(); + move32(); } test(); - IF( GT_16( n_dirs, 1 ) && GT_16( diff_no_swap_fx, diff_swap_fx ) ) + IF( GT_16( n_dirs, 1 ) && GT_32( diff_no_swap_fx, diff_swap_fx ) ) { /* swap the metadata of the two directions in this TF-tile */ Word32 tmp_val; diff --git a/lib_enc/ivas_mct_enc.c b/lib_enc/ivas_mct_enc.c index 472043f02..07379e99c 100644 --- a/lib_enc/ivas_mct_enc.c +++ b/lib_enc/ivas_mct_enc.c @@ -779,12 +779,6 @@ ivas_error ivas_mct_enc( me2f_buf_16( st->hTcxEnc->buf_speech_ltp, st->hTcxEnc->exp_buf_speech_ltp, st->hTcxEnc->buf_speech_ltp_flt, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k ); } - IF( ( st->Opt_DTX_ON && LE_32( st->core_brate, SID_2k40 ) && EQ_16( st->cng_type, FD_CNG ) ) || ( st->tcxonly && ( EQ_16( st->codec_mode, MODE2 ) || GT_16( st->element_mode, EVS_MONO ) ) ) ) - { - set_zero( st->mem_MA, M ); - mvr2r( GEWB_Ave, st->mem_AR, M ); - } - IF( st->element_mode > EVS_MONO && st->hTcxEnc != NULL ) { st->hTcxEnc->tcxltp_norm_corr_mem_flt = fixedToFloat( st->hTcxEnc->tcxltp_norm_corr_mem, 15 ); diff --git a/lib_enc/ivas_qmetadata_enc.c b/lib_enc/ivas_qmetadata_enc.c index f34ae9ef0..f77bce2a8 100644 --- a/lib_enc/ivas_qmetadata_enc.c +++ b/lib_enc/ivas_qmetadata_enc.c @@ -1621,7 +1621,7 @@ void ivas_qmetadata_enc_sid_encode_fx( const Word16 ivas_format /* i : IVAS format */ ) { - Word16 b, m, i; + Word16 b, m; Word16 bit_pos_start; IVAS_QDIRECTION *q_direction; Word16 nbands, nblocks, start_band; @@ -1823,14 +1823,11 @@ void ivas_qmetadata_enc_sid_encode_fx( { /*compute the average direction */ ivas_qmetadata_azimuth_elevation_to_direction_vector_fx( q_direction->band_data[b].azimuth_fx[m], q_direction->band_data[b].elevation_fx[m], direction_vector_fx ); - FOR( i = 0; i < 3; i++ ) - { - avg_direction_vector_fx[i] = L_add( avg_direction_vector_fx[i], L_shr( direction_vector_fx[i], 1 ) ); - move32(); - } + scale_sig32( direction_vector_fx, 3, Q22 - Q30 ); // Q30 -> Q22 + v_add_fixed( avg_direction_vector_fx, direction_vector_fx, avg_direction_vector_fx, 3, 0 ); // Q22 } - ivas_qmetadata_direction_vector_to_azimuth_elevation_fx( avg_direction_vector_fx, Q30, &avg_azimuth_fx[b], &avg_elevation_fx[b] ); + ivas_qmetadata_direction_vector_to_azimuth_elevation_fx( avg_direction_vector_fx, Q22, &avg_azimuth_fx[b], &avg_elevation_fx[b] ); /* Quantize the average direction */ IF( q_direction->not_in_2D == 0 ) @@ -2549,7 +2546,7 @@ static void ivas_qmetadata_quantize_diffuseness_nrg_ratios_fx( FOR( j = hQMetaData->q_direction[0].cfg.start_band; j < hQMetaData->q_direction[0].cfg.nbands; ++j ) { test(); - IF( EQ_16( hQMetaData->no_directions, 2 ) && EQ_16( hQMetaData->twoDirBands[j], 1 ) ) + IF( EQ_32( hQMetaData->no_directions, 2 ) && EQ_16( hQMetaData->twoDirBands[j], 1 ) ) { Word32 diffRatio, dfRatio, dfRatioQ, diffRatioQ, dirRatio1Q, dirRatio2Q; /* Q30 */ Word32 dirRatio1, dirRatio2, sumRatio; /* Q30 */ @@ -2562,27 +2559,28 @@ static void ivas_qmetadata_quantize_diffuseness_nrg_ratios_fx( IF( hodirac_flag ) { /* already encoded as total and ratios in HO-DirAC */ - diffRatio = L_sub( ONE_IN_Q30, hQMetaData->q_direction[0].band_data[j].energy_ratio_fx[0] ); - dfRatio = hQMetaData->q_direction[1].band_data[dir2band].energy_ratio_fx[0]; - move32(); + diffRatio = L_sub( ONE_IN_Q30, hQMetaData->q_direction[0].band_data[j].energy_ratio_fx[0] ); // Q30 + dfRatio = hQMetaData->q_direction[1].band_data[dir2band].energy_ratio_fx[0]; // Q30 move32(); } ELSE { - dirRatio1 = hQMetaData->q_direction[0].band_data[j].energy_ratio_fx[0]; - dirRatio2 = hQMetaData->q_direction[1].band_data[dir2band].energy_ratio_fx[0]; + dirRatio1 = hQMetaData->q_direction[0].band_data[j].energy_ratio_fx[0]; // Q30 move32(); + dirRatio2 = hQMetaData->q_direction[1].band_data[dir2band].energy_ratio_fx[0]; // Q30 move32(); - sumRatio = L_add( dirRatio1, dirRatio2 ); - diffRatio = L_sub( ONE_IN_Q30, sumRatio ); + sumRatio = L_add( dirRatio1, dirRatio2 ); // Q30 + diffRatio = L_sub( ONE_IN_Q30, sumRatio ); // Q30 IF( LT_32( sumRatio, EPSILON_FIX ) ) { - dfRatio = ONE_IN_Q30 / 2; // 0.5 in Q30 + dfRatio = ONE_IN_Q29 /* 0.5f in Q30*/; // Q30 move32(); } ELSE { - dfRatio = L_shl( L_deposit_l( div_l( dirRatio1, extract_h( sumRatio ) ) ), 15 ); // Q30 + Word16 exp_diff; + dfRatio = L_deposit_h( BASOP_Util_Divide3232_Scale( dirRatio1, sumRatio, &exp_diff ) ); + dfRatio = L_shl( dfRatio, sub( exp_diff, Q1 ) ); // Q30 } } @@ -2607,16 +2605,16 @@ static void ivas_qmetadata_quantize_diffuseness_nrg_ratios_fx( IF( hodirac_flag ) { Word16 dfRatioQ16; /* Q14 */ - dfRatio_index = usquant_fx( extract_h( dfRatio ), &dfRatioQ16, 0, shr( div_s( 1, sub( dfRatio_qsteps, 1 ) ), 2 ) /* Q13 */, dfRatio_qsteps ); + dfRatio_index = usquant_fx( extract_h( dfRatio ), &dfRatioQ16 /* Q14 */, 0, shr( div_s( 1, sub( dfRatio_qsteps, 1 ) ), 2 ), dfRatio_qsteps ); dfRatioQ = L_deposit_h( dfRatioQ16 ); // Q30 dirRatio1Q = L_sub( ONE_IN_Q30, diffRatioQ ); // Q30 - dirRatio2Q = dfRatioQ; + dirRatio2Q = dfRatioQ; // Q30 move32(); } ELSE { Word16 dfRatioQ16; /* Q14 */ - dfRatio_index = usquant_fx( extract_h( dfRatio ), &dfRatioQ16, ONE_IN_Q13, shr( div_s( 1, sub( dfRatio_qsteps, 1 ) ), 3 ) /* Q12 */, dfRatio_qsteps ); + dfRatio_index = usquant_fx( extract_h( dfRatio ), &dfRatioQ16 /* Q14 */, ONE_IN_Q13 /* 0.5f in Q14 */, shr( div_s( 1, sub( dfRatio_qsteps, 1 ) ), 3 ), dfRatio_qsteps ); /* Direction quantization requires also separately quantized direct-to-total ratios. Thus, we calculate them. */ dirRatio1Q = L_shl( Mpy_32_16_1( L_sub( ONE_IN_Q30, diffRatioQ ), dfRatioQ16 ), 1 ); // Q30 @@ -2630,9 +2628,9 @@ static void ivas_qmetadata_quantize_diffuseness_nrg_ratios_fx( * then later retrieved for further use in encoding. */ FOR( k = 0; k < hQMetaData->q_direction[0].cfg.nblocks; k++ ) { - hQMetaData->q_direction[0].band_data[j].energy_ratio_index[k] = index_diff; - hQMetaData->q_direction[0].band_data[j].energy_ratio_fx[k] = dirRatio1Q; + hQMetaData->q_direction[0].band_data[j].energy_ratio_index[k] = index_diff; // Q0 move16(); + hQMetaData->q_direction[0].band_data[j].energy_ratio_fx[k] = dirRatio1Q; // Q30 move32(); } nbits_diff[0] = add( nbits_diff[0], MASA_BITS_ER ); @@ -2641,7 +2639,7 @@ static void ivas_qmetadata_quantize_diffuseness_nrg_ratios_fx( IF( hodirac_flag ) { Word16 tmp; /* Q14 */ - index_dirRatio2Inv = usquant_fx( extract_h( dirRatio2Q ), &tmp, 0, shr( div_s( 1, ( DIRAC_DIFFUSE_LEVELS - 1 ) ), 2 ) /* Q13 */, DIRAC_DIFFUSE_LEVELS ); + index_dirRatio2Inv = usquant_fx( extract_h( dirRatio2Q ), &tmp /* Q14 */, 0, shr( div_s( 1, sub( DIRAC_DIFFUSE_LEVELS, 1 ) ), 2 ), DIRAC_DIFFUSE_LEVELS ); } ELSE { @@ -2650,9 +2648,9 @@ static void ivas_qmetadata_quantize_diffuseness_nrg_ratios_fx( FOR( k = 0; k < hQMetaData->q_direction[1].cfg.nblocks; k++ ) { - hQMetaData->q_direction[1].band_data[dir2band].energy_ratio_index[k] = dfRatio_index; - hQMetaData->q_direction[1].band_data[dir2band].energy_ratio_fx[k] = dirRatio2Q; + hQMetaData->q_direction[1].band_data[dir2band].energy_ratio_index[k] = dfRatio_index; // Q0 move16(); + hQMetaData->q_direction[1].band_data[dir2band].energy_ratio_fx[k] = dirRatio2Q; // Q30 move32(); } nbits_diff[1] = add( nbits_diff[1], dfRatio_bits ); @@ -2667,8 +2665,8 @@ static void ivas_qmetadata_quantize_diffuseness_nrg_ratios_fx( FOR( k = 0; k < hQMetaData->q_direction[0].cfg.nblocks; k++ ) { hQMetaData->q_direction[0].band_data[j].energy_ratio_index_mod[k] = index_dirRatio1Inv_mod; - hQMetaData->q_direction[0].band_data[j].bits_sph_idx[k] = bits_direction_masa[index_dirRatio1Inv_mod]; move16(); + hQMetaData->q_direction[0].band_data[j].bits_sph_idx[k] = bits_direction_masa[index_dirRatio1Inv_mod]; move16(); } needed_bits[0] = add( needed_bits[0], imult1616( hQMetaData->q_direction[0].cfg.nblocks, bits_direction_masa[index_dirRatio1Inv_mod] ) ); @@ -2677,8 +2675,8 @@ static void ivas_qmetadata_quantize_diffuseness_nrg_ratios_fx( FOR( k = 0; k < hQMetaData->q_direction[1].cfg.nblocks; k++ ) { hQMetaData->q_direction[1].band_data[dir2band].energy_ratio_index_mod[k] = index_dirRatio2Inv_mod; - hQMetaData->q_direction[1].band_data[dir2band].bits_sph_idx[k] = bits_direction_masa[index_dirRatio2Inv_mod]; move16(); + hQMetaData->q_direction[1].band_data[dir2band].bits_sph_idx[k] = bits_direction_masa[index_dirRatio2Inv_mod]; move16(); } needed_bits[1] = add( needed_bits[1], imult1616( hQMetaData->q_direction[1].cfg.nblocks, bits_direction_masa[index_dirRatio2Inv_mod] ) ); @@ -2693,12 +2691,12 @@ static void ivas_qmetadata_quantize_diffuseness_nrg_ratios_fx( FOR( k = 0; k < hQMetaData->q_direction[0].cfg.nblocks; k++ ) { hQMetaData->q_direction[0].band_data[j].energy_ratio_index[k] = index_dirRatio1Inv; - hQMetaData->q_direction[0].band_data[j].energy_ratio_index_mod[k] = index_dirRatio1Inv; - hQMetaData->q_direction[0].band_data[j].energy_ratio_fx[k] = L_sub( ONE_IN_Q30, diffuseness_reconstructions_fx[index_dirRatio1Inv] ); - hQMetaData->q_direction[0].band_data[j].bits_sph_idx[k] = bits_direction_masa[index_dirRatio1Inv]; move16(); + hQMetaData->q_direction[0].band_data[j].energy_ratio_index_mod[k] = index_dirRatio1Inv; move16(); + hQMetaData->q_direction[0].band_data[j].energy_ratio_fx[k] = L_sub( ONE_IN_Q30, diffuseness_reconstructions_fx[index_dirRatio1Inv] ); // Q30 move32(); + hQMetaData->q_direction[0].band_data[j].bits_sph_idx[k] = bits_direction_masa[index_dirRatio1Inv]; move16(); } diff --git a/lib_enc/ivas_tcx_core_enc.c b/lib_enc/ivas_tcx_core_enc.c index 2ba28fcf6..40223d1bd 100644 --- a/lib_enc/ivas_tcx_core_enc.c +++ b/lib_enc/ivas_tcx_core_enc.c @@ -474,9 +474,6 @@ void stereo_tcx_core_enc( for ( int j = 0; j < M; j++ ) { st->lsf_old_fx[j] = (Word16) ( st->lsf_old[j] * 2.56f ); - st->lsf_adaptive_mean_fx[j] = (Word16) ( st->lsf_adaptive_mean[j] * 2.56f ); - st->mem_MA_fx[j] = (Word16) ( st->mem_MA[j] * 2.56f ); - st->mem_AR_fx[j] = (Word16) ( st->mem_AR[j] * 2.56f ); } floatToFixed_arr( st->lspold_enc, st->lspold_enc_fx, Q15, M ); diff --git a/lib_enc/rst_enc.c b/lib_enc/rst_enc.c index 0e8ec0a3e..66ea72cc9 100644 --- a/lib_enc/rst_enc.c +++ b/lib_enc/rst_enc.c @@ -40,6 +40,9 @@ #include "rom_com.h" #include "prot.h" #include "wmc_auto.h" +#ifdef IVAS_FLOAT_FIXED +#include "prot_fx.h" +#endif /*-------------------------------------------------------------------* * CNG_reset_enc() @@ -54,11 +57,20 @@ void CNG_reset_enc( int16_t VBR_cng_reset_flag ) { init_gp_clip( st->clip_var ); +#ifndef IVAS_FLOAT_FIXED mvr2r( UVWB_Ave, st->mem_AR, M ); set_f( st->mem_MA, 0, M ); +#else + Copy( UVWB_Ave_fx, st->mem_AR_fx, M ); + set16_fx( st->mem_MA_fx, 0, M ); +#endif st->hLPDmem->mem_w0_flt = 0.0f; st->hLPDmem->tilt_code_flt = 0.0f; +#ifndef IVAS_FLOAT_FIXED st->hLPDmem->gc_threshold_flt = 0.0f; +#else + st->hLPDmem->gc_threshold = 0; +#endif if ( VBR_cng_reset_flag ) { diff --git a/lib_enc/stat_enc.h b/lib_enc/stat_enc.h index 500dd1307..87076409e 100644 --- a/lib_enc/stat_enc.h +++ b/lib_enc/stat_enc.h @@ -457,11 +457,14 @@ typedef struct td_cng_enc_structure #else Word16 CNG_att_fx; /* CNG and DTX - attenuation factor for CNG, in dB Q7 */ #endif - int16_t ho_16k_lsp[HO_HIST_SIZE]; /* CNG and DTX - 16k LSPs flags */ - int16_t act_cnt2; /* CNG and DTX - counter of active frames for CNG_mode switching */ - float ho_lsp_circ2[HO_HIST_SIZE * M]; /* CNG and DTX - second buffer of LSPs */ - Word16 ho_lsp_circ2_fx[HO_HIST_SIZE * M]; /* CNG and DTX - second buffer of LSPs */ - int16_t num_ho; /* CNG and DTX - number of selected hangover frames */ + int16_t ho_16k_lsp[HO_HIST_SIZE]; /* CNG and DTX - 16k LSPs flags */ + int16_t act_cnt2; /* CNG and DTX - counter of active frames for CNG_mode switching */ +#ifndef IVAS_FLOAT_FIXED + float ho_lsp_circ2[HO_HIST_SIZE * M]; /* CNG and DTX - second buffer of LSPs */ +#else + Word16 ho_lsp_circ2_fx[HO_HIST_SIZE * M]; /* CNG and DTX - second buffer of LSPs Q15 */ +#endif + int16_t num_ho; /* CNG and DTX - number of selected hangover frames */ #ifndef IVAS_FLOAT_FIXED float old_env[NUM_ENV_CNG]; float lp_env[NUM_ENV_CNG]; @@ -1151,11 +1154,14 @@ typedef struct lpd_state_structure Word16 e_mem_syn; float tilt_code_flt; - float gc_threshold_flt; /* Noise enhancer - threshold for gain_code */ + Word16 tilt_code; /* Q15 */ +#ifndef IVAS_FLOAT_FIXED + float gc_threshold_flt; /* Noise enhancer - threshold for gain_code */ +#else + Word32 gc_threshold; /* Noise enhancer - threshold for gain_code. exponent = 15, 15Q16 */ +#endif float dispMem_flt[8]; /* Noise enhancer - phase dispersion algorithm memory */ Word32 dispMem[8]; /* Noise enhancer - phase dispersion algorithm memory */ - Word16 tilt_code; /* Q15 */ - Word32 gc_threshold; /* exponent = 15, 15Q16 */ struct dispMem_fx dm_fx; /* Noise enhancer - phase dispersion algorithm memory */ } LPD_state, *LPD_state_HANDLE; @@ -1246,11 +1252,11 @@ typedef struct hq_enc_structure int16_t prev_stab_hfe2; #ifndef IVAS_FLOAT_FIXED float prev_ni_ratio; + float prev_En_sb[NB_SWB_SUBBANDS]; #else Word16 prev_ni_ratio_fx; /* Q15 */ + Word16 prev_En_sb_fx[NB_SWB_SUBBANDS]; /* QsEn(4) */ #endif - float prev_En_sb[NB_SWB_SUBBANDS]; - Word16 prev_En_sb_fx[NB_SWB_SUBBANDS]; /* QsEn(4) */ int16_t last_bitalloc_max_band[2]; #ifndef IVAS_FLOAT_FIXED @@ -1463,15 +1469,12 @@ typedef struct td_bwe_enc_structure #ifndef IVAS_FLOAT_FIXED float prev_lsp_shb[LPC_SHB_ORDER]; -#else - Word16 prev_lsp_shb_fx[LPC_SHB_ORDER]; /* Q15 */ -#endif float state_ana_filt_shb[2 * ALLPASSSECTIONS_STEEP + 1]; /* states for the analysis filters */ - Word16 state_ana_filt_shb_fx[( 2 * ALLPASSSECTIONS_STEEP + 1 )]; -#ifndef IVAS_FLOAT_FIXED float cldfbHBLT_flt; #else - Word16 cldfbHBLT; /* Q13 */ + Word16 prev_lsp_shb_fx[LPC_SHB_ORDER]; /* Q15 */ + Word16 state_ana_filt_shb_fx[( 2 * ALLPASSSECTIONS_STEEP + 1 )]; /* states for the analysis filters */ + Word16 cldfbHBLT; /* Q13 */ #endif /* states for the filters used in generating SHB excitation from WB excitation*/ float mem_csfilt[2]; @@ -1486,8 +1489,8 @@ typedef struct td_bwe_enc_structure float prev_enr_EnvSHBres; /* energy of the residual SHB envelope from the previous frame */ float prev_shb_env_tilt; /* tilt of the residual SHB envelope from the previous frame */ #else - Word16 old_mean_EnvSHBres_fx; /* energy of the last subframe of the SHB residual signal from previous frame Q15 */ - Word32 prev_enr_EnvSHBres_fx; /* energy of the residual SHB envelope from the previous frame Q(31 - prev_enr_EnvSHBres_e) */ + Word16 old_mean_EnvSHBres_fx; /* energy of the last subframe of the SHB residual signal from previous frame Q15 */ + Word32 prev_enr_EnvSHBres_fx; /* energy of the residual SHB envelope from the previous frame Q(31 - prev_enr_EnvSHBres_e) */ Word16 prev_enr_EnvSHBres_e; Word16 prev_shb_env_tilt_fx; /* tilt of the residual SHB envelope from the previous frame Q(prev_shb_env_tilt_q) */ Word16 prev_shb_env_tilt_q; @@ -2105,8 +2108,13 @@ typedef struct enc_core_structure float mem_wsp; /* weighted signal vector memory */ float mem_decim2[3]; /* weighted signal decimation filter memory */ float clip_var[6]; /* pitch gain clipping memory */ - float mem_AR[M]; /* AR memory of LSF quantizer (past quantized LSFs without mean) */ - float mem_MA[M]; /* MA memory of LSF quantizer (past quantized residual) (used also in AMR-WB IO mode) */ +#ifndef IVAS_FLOAT_FIXED + float mem_AR[M]; /* AR memory of LSF quantizer (past quantized LSFs without mean) */ + float mem_MA[M]; /* MA memory of LSF quantizer (past quantized residual) (used also in AMR-WB IO mode) */ +#else + Word16 mem_AR_fx[M]; /* AR memory of LSF quantizer (past quantized LSFs without mean) Qlog2(2.56) */ + Word16 mem_MA_fx[M]; /* MA memory of LSF quantizer (past quantized residual) (used also in AMR-WB IO mode) Qlog2(2.56) */ +#endif // Word16 pstreaklen_fx; /* LSF quantizer */ Word32 offset_scale1_fx[MAX_NO_MODES + 1][MAX_NO_SCALES + 1]; /* offsets for LSF LVQ structure 1st 8-dim subvector*/ Word32 offset_scale2_fx[MAX_NO_MODES + 1][MAX_NO_SCALES + 1]; /* offsets for LSF LVQ structure 2nd 8-dim subvector*/ @@ -2128,34 +2136,41 @@ typedef struct enc_core_structure Word16 clip_var_fx[6]; Word16 mem_deemph_fx; /* deemphasis filter memory */ Word32 mem_hp20_in_fx[5]; /* HP filter memory for AMR-WB IO */ - Word16 mem_AR_fx[M]; /* AR memory of LSF quantizer (past quantized LSFs without mean) */ - Word16 mem_MA_fx[M]; /* MA memory of LSF quantizer (past quantized residual) (used also in AMR-WB IO mode) */ Word16 mCb1_fx; /* LSF quantizer - counter of stationary frames after a transition frame */ int16_t GSC_noisy_speech; /* AC mode (GSC) - flag to indicate GSC on SWB noisy speech */ int16_t GSC_IVAS_mode; GSC_ENC_HANDLE hGSCEnc; - int16_t Last_pulse_pos; /* FEC - last position of the first glottal pulse in the frame */ - float lsfoldbfi0[M]; /* FEC - LSF vector of the previous frame */ - float lsfoldbfi1[M]; /* FEC - LSF vector of the past previous frame */ - float lsf_adaptive_mean[M]; /* FEC - adaptive mean LSF vector for FEC */ - Word16 lsfoldbfi0_fx[M]; /* FEC - LSF vector of the previous frame */ - Word16 lsfoldbfi1_fx[M]; /* FEC - LSF vector of the past previous frame */ - Word16 lsf_adaptive_mean_fx[M]; /* FEC - adaptive mean LSF vector for FEC */ - int16_t next_force_safety_net; /* FEC - flag to force safety net in next frame */ + int16_t Last_pulse_pos; /* FEC - last position of the first glottal pulse in the frame */ +#ifndef IVAS_FLOAT_FIXED + float lsfoldbfi0[M]; /* FEC - LSF vector of the previous frame */ + float lsfoldbfi1[M]; /* FEC - LSF vector of the past previous frame */ + float lsf_adaptive_mean[M]; /* FEC - adaptive mean LSF vector for FEC */ +#else + Word16 lsfoldbfi0_fx[M]; /* FEC - LSF vector of the previous frame Qlog2(2.56) */ + Word16 lsfoldbfi1_fx[M]; /* FEC - LSF vector of the past previous frame Qlog2(2.56) */ + Word16 lsf_adaptive_mean_fx[M]; /* FEC - adaptive mean LSF vector for FEC Qlog2(2.56) */ +#endif + int16_t next_force_safety_net; /* FEC - flag to force safety net in next frame */ // Word16 next_force_safety_net_fx; /* FEC - flag to force safety net in next frame */ - int16_t uv_count; /* Stationary noise UV modification - unvoiced counter */ - int16_t act_count; /* Stationary noise UV modification - activation counter */ - float ge_sm; /* Stationary noise UV modification - smoothed excitation gain */ - float lspold_s[M]; /* Stationary noise UV modification - old LSP vector */ - Word32 ge_sm_fx; /* Stationary noise UV modification - smoothed excitation gain */ - Word16 lspold_s_fx[M]; /*Q15*/ /* Stationary noise UV modification - old LSP vector */ - int16_t noimix_seed; /* Stationary noise UV modification - mixture seed */ - float min_alpha; /* Stationary noise UV modification - minimum alpha */ - float exc_pe; /* Stationary noise UV modification - memory of the preemphasis filter */ - Word16 min_alpha_fx; /*Q15*/ /* Stationary noise UV modification - minimum alpha */ - Word16 exc_pe_fx; /* Stationary noise UV modification - memory of the preemphasis filter */ + int16_t uv_count; /* Stationary noise UV modification - unvoiced counter */ + int16_t act_count; /* Stationary noise UV modification - activation counter */ +#ifndef IVAS_FLOAT_FIXED + float ge_sm; /* Stationary noise UV modification - smoothed excitation gain */ + float lspold_s[M]; /* Stationary noise UV modification - old LSP vector */ +#else + Word32 ge_sm_fx; /* Stationary noise UV modification - smoothed excitation gain Q(GE_SHIFT) */ + Word16 lspold_s_fx[M]; /* Stationary noise UV modification - old LSP vector Q15 */ +#endif + int16_t noimix_seed; /* Stationary noise UV modification - mixture seed */ +#ifndef IVAS_FLOAT_FIXED + float min_alpha; /* Stationary noise UV modification - minimum alpha */ +#else + Word16 min_alpha_fx; /* Stationary noise UV modification - minimum alpha Q15 */ +#endif + float exc_pe; /* Stationary noise UV modification - memory of the preemphasis filter */ + Word16 exc_pe_fx; /* Stationary noise UV modification - memory of the preemphasis filter */ int16_t coder_type_raw; /* raw coder_type (before UNVOICED is lost) */ int16_t last_coder_type_raw; /* raw last_coder_type (coming from the sigal classification) */ @@ -2169,25 +2184,33 @@ typedef struct enc_core_structure Word16 old_corr_fx; /* normalized correlation in previous frame (mean value) Q15 */ int16_t old_pitch; /* previous pitch for open-loop pitch search */ int16_t delta_pit; /* open-loop pitch extrapolation correction */ - float ee_old; /* previous frame low/high frequency energy ratio */ - - Word32 ee_old_fx; - int16_t min_band; /* minimum critical band of useful bandwidth */ - int16_t max_band; /* maximum critical band of useful bandwidth */ - int16_t tc_cnt; /* TC frame counter */ - int16_t audio_frame_cnt; /* Counter of relative presence of audio frames */ - float old_dE1; /* Maximum energy increase in previous frame */ - Word32 old_dE1_fx; /* Maximum energy increase in previous frame */ - int16_t old_ind_deltaMax; /* Index of the sub-subframe of maximum energy in previous frame */ - float old_enr_ssf[2 * NB_SSF]; /* Maxima of energies per sub-subframes of previous frame */ - Word32 old_enr_ssf_fx[2 * NB_SSF]; /* Maxima of energies per sub-subframes of previous frame */ - int16_t spike_hyst; /* Hysteresis to prevent UC after sharp energy spike */ - int16_t last_harm_flag_acelp; /* harmonicity flag for ACELP @32kbps rate */ - float old_Aq_12_8[M + 1]; /* old Aq[] for core switching */ - float old_Es_pred; /* old Es_pred for core switching */ - Word16 old_Aq_12_8_fx[M + 1]; /* Q12 old Aq[] for core switching */ - Word16 old_Es_pred_fx; /* Q8 old Es_pred for core switching */ - Word16 music_hysteresis_fx; /* Counter of frames after AUDIO coding mode to prevent UC */ +#ifndef IVAS_FLOAT_FIXED + float ee_old; /* previous frame low/high frequency energy ratio */ +#else + Word32 ee_old_fx; /* previous frame low/high frequency energy ratio Q6 */ +#endif + int16_t min_band; /* minimum critical band of useful bandwidth */ + int16_t max_band; /* maximum critical band of useful bandwidth */ + int16_t tc_cnt; /* TC frame counter */ + int16_t audio_frame_cnt; /* Counter of relative presence of audio frames */ +#ifndef IVAS_FLOAT_FIXED + float old_dE1; /* Maximum energy increase in previous frame */ +#else + Word32 old_dE1_fx; /* Maximum energy increase in previous frame Q13 */ +#endif + int16_t old_ind_deltaMax; /* Index of the sub-subframe of maximum energy in previous frame */ +#ifndef IVAS_FLOAT_FIXED + float old_enr_ssf[2 * NB_SSF]; /* Maxima of energies per sub-subframes of previous frame */ +#else + Word32 old_enr_ssf_fx[2 * NB_SSF]; /* Maxima of energies per sub-subframes of previous frame */ +#endif + int16_t spike_hyst; /* Hysteresis to prevent UC after sharp energy spike */ + int16_t last_harm_flag_acelp; /* harmonicity flag for ACELP @32kbps rate */ + float old_Aq_12_8[M + 1]; /* old Aq[] for core switching */ + float old_Es_pred; /* old Es_pred for core switching */ + Word16 old_Aq_12_8_fx[M + 1]; /* Q12 old Aq[] for core switching */ + Word16 old_Es_pred_fx; /* Q8 old Es_pred for core switching */ + Word16 music_hysteresis_fx; /* Counter of frames after AUDIO coding mode to prevent UC */ Word16 last_vad_spa_fx; Word16 last_L_frame; /* ACELP@16kHz - last L_frame value */ diff --git a/lib_enc/swb_tbe_enc.c b/lib_enc/swb_tbe_enc.c index 37c799639..dad834fcf 100644 --- a/lib_enc/swb_tbe_enc.c +++ b/lib_enc/swb_tbe_enc.c @@ -99,19 +99,19 @@ void InitSWBencBuffer( set_f( hBWE_TD->old_bwe_exc_extended, 0.0f, NL_BUFF_OFFSET ); #ifndef IVAS_FLOAT_FIXED hBWE_TD->bwe_non_lin_prev_scale = 0; -#else - hBWE_TD->bwe_non_lin_prev_scale_fx = 0; -#endif set_f( hBWE_TD->state_ana_filt_shb, 0.0f, ( 2 * ALLPASSSECTIONS_STEEP + 1 ) ); -#ifndef IVAS_FLOAT_FIXED set_f( hBWE_TD->elliptic_bpf_2_48k_mem[0], 0.0f, 4 ); set_f( hBWE_TD->elliptic_bpf_2_48k_mem[1], 0.0f, 4 ); set_f( hBWE_TD->elliptic_bpf_2_48k_mem[2], 0.0f, 4 ); set_f( hBWE_TD->elliptic_bpf_2_48k_mem[3], 0.0f, 4 ); hBWE_TD->prev_fb_energy = 0.0f; #else + hBWE_TD->bwe_non_lin_prev_scale_fx = 0; + + set16_fx( hBWE_TD->state_ana_filt_shb_fx, 0, ( 2 * ALLPASSSECTIONS_STEEP + 1 ) ); + set32_fx( hBWE_TD->elliptic_bpf_2_48k_mem_fx[0], 0, 4 ); set32_fx( hBWE_TD->elliptic_bpf_2_48k_mem_fx[1], 0, 4 ); set32_fx( hBWE_TD->elliptic_bpf_2_48k_mem_fx[2], 0, 4 ); @@ -2976,7 +2976,11 @@ void TBEreset_enc( } else if ( bwidth == SWB || bwidth == FB ) { +#ifdef IVAS_FLOAT_FIXED + set16_fx( hBWE_TD->state_ana_filt_shb_fx, 0, ( 2 * ALLPASSSECTIONS_STEEP + 1 ) ); +#else set_f( hBWE_TD->state_ana_filt_shb, 0.0f, ( 2 * ALLPASSSECTIONS_STEEP + 1 ) ); +#endif swb_tbe_reset( hBWE_TD->mem_csfilt, hBWE_TD->mem_genSHBexc_filt_down_shb, hBWE_TD->state_lpc_syn, hBWE_TD->syn_overlap, hBWE_TD->state_syn_shbexc, &( hBWE_TD->tbe_demph ), &( hBWE_TD->tbe_premph ), hBWE_TD->mem_stp_swb, &( hBWE_TD->gain_prec_swb ) ); -- GitLab From 9b06a6d0b33339f02fff37c5b4f5db1a0b07ad5e Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Mon, 4 Nov 2024 10:31:15 +0530 Subject: [PATCH 068/128] Fix for 3gpp issue 974: OSBA 160 kbps (pre-rendering): Discrepancy for SPAR part for several components --- lib_rend/ivas_dirac_output_synthesis_dec.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/lib_rend/ivas_dirac_output_synthesis_dec.c b/lib_rend/ivas_dirac_output_synthesis_dec.c index f30bb1237..0fa4511fd 100644 --- a/lib_rend/ivas_dirac_output_synthesis_dec.c +++ b/lib_rend/ivas_dirac_output_synthesis_dec.c @@ -1537,7 +1537,15 @@ void ivas_dirac_dec_output_synthesis_process_slot_fx( } ELSE { - b = BASOP_Util_Divide3232_Scale( reference_power[k + num_freq_bands], L_add( reference_power[k + ( ch_idx + 1 ) * num_freq_bands], EPSILON_FX ), &b_exp ); /*Q(15-b_exp)*/ + IF( reference_power[k + ( ch_idx + 1 ) * num_freq_bands] == 0 ) + { + b = BASOP_Util_Divide3232_Scale( reference_power[k + num_freq_bands], 232831 /* EPSILON in exp 63 */, &b_exp ); + b_exp = add( b_exp, sub( sub( 31, q_reference_power ), 63 ) ); + } + ELSE + { + b = BASOP_Util_Divide3232_Scale( reference_power[k + num_freq_bands], reference_power[k + ( ch_idx + 1 ) * num_freq_bands], &b_exp ); /*Q(15-b_exp)*/ + } } c = L_add( ONE_IN_Q29 /*1 Q29*/, Mpy_32_16_1( L_sub( h_dirac_output_synthesis_params->diffuse_compensation_factor_decorr_fx, ONE_IN_Q29 /*1 Q29*/ ), 5461 /*1.0 / 6.0 Q15*/ ) ); /*Diffuseness modellling nrg compensation*/ /*Q29*/ @@ -1611,10 +1619,8 @@ void ivas_dirac_dec_output_synthesis_process_slot_fx( { IF( reference_power[k + ( ch_idx + 1 ) * num_freq_bands] == 0 ) { - b = MAXVAL_WORD16; /*Q(-9)*/ - move16(); - b_exp = 40; - move16(); + b = BASOP_Util_Divide3232_Scale( reference_power[k + num_freq_bands], 232831 /* EPSILON in exp 63 */, &b_exp ); + b_exp = add( b_exp, sub( sub( 31, q_reference_power ), 63 ) ); } ELSE { -- GitLab From 2f9f657253c2634d5ab290ea89608cb345dc278f Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Mon, 4 Nov 2024 10:34:22 +0530 Subject: [PATCH 069/128] Fix for 3gpp issue 971: Waveform discrepency when transitioning from concealing a lost frame to decoding a received frame with SBA bitstream [x] Changed guard bits logic to avoid saturation --- lib_dec/FEC_scale_syn_fx.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/lib_dec/FEC_scale_syn_fx.c b/lib_dec/FEC_scale_syn_fx.c index 1de166612..21a589c56 100644 --- a/lib_dec/FEC_scale_syn_fx.c +++ b/lib_dec/FEC_scale_syn_fx.c @@ -790,15 +790,16 @@ void FEC_scale_syn_ivas_fx( /*-----------------------------------------------------------------* * Find the energy/gain at the end of the frame *-----------------------------------------------------------------*/ - IF( LT_16( getScaleFactor16( synth, L_frame ), 2 ) ) + tmp = sub( 3, getScaleFactor16( synth, L_frame ) ); + IF( tmp > 0 ) { - Scale_sig( synth, L_frame, -1 ); - frame_ener_fx( L_frame, clas, synth, pitch[sub( shr( L_frame, 6 ), 1 )], &L_enr2 /*Q0*/, 1, sub( Q_syn, 1 ), 3, 0 ); - Scale_sig( synth, L_frame, 1 ); + Word16 synth_tmp[L_FRAME16k]; + Copy_Scale_sig( synth, synth_tmp, L_frame, -tmp ); // Q_synth - tmp + frame_ener_fx( L_frame, clas, synth_tmp, pitch[L_frame / L_SUBFR - 1], &L_enr2 /*Q0*/, 1, sub( Q_syn, tmp ), 3, 0 ); } ELSE { - frame_ener_fx( L_frame, clas, synth, pitch[sub( shr( L_frame, 6 ), 1 )], &L_enr2 /*Q0*/, 1, Q_syn, 3, 0 ); + frame_ener_fx( L_frame, clas, synth, pitch[L_frame / L_SUBFR - 1], &L_enr2 /*Q0*/, 1, Q_syn, 3, 0 ); } test(); -- GitLab From e4f931a6c03d0cac5db470649d693f09c4d89665 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Mon, 4 Nov 2024 15:19:16 +0530 Subject: [PATCH 070/128] Encoder LTV crash fixes and Q-info updates for lib_com --- lib_com/fft_evs.c | 74 +- lib_com/fft_fx.c | 1753 +++++++++++++++++---------------- lib_com/fft_fx_evs.c | 700 ++++++------- lib_com/ppp_fx.c | 18 +- lib_com/pred_lt4_fx.c | 75 +- lib_com/preemph.c | 16 +- lib_com/preemph_fx.c | 121 ++- lib_com/prot.h | 8 +- lib_com/prot_fx.h | 70 +- lib_enc/ivas_stereo_dmx_evs.c | 9 +- 10 files changed, 1459 insertions(+), 1385 deletions(-) diff --git a/lib_com/fft_evs.c b/lib_com/fft_evs.c index cffdac16b..e53404f0b 100644 --- a/lib_com/fft_evs.c +++ b/lib_com/fft_evs.c @@ -104,17 +104,17 @@ void fft16_with_cmplx_data( cmplx *pInp, Word16 bsacle ); * * \return void */ -static void fft5_with_cmplx_data( cmplx *inp ) +static void fft5_with_cmplx_data( cmplx *inp /*Qx*/ ) { cmplx x0, x1, x2, x3, x4; cmplx y1, y2, y3, y4; cmplx t; - x0 = CL_shr( inp[0], SCALEFACTOR5 ); - x1 = CL_shr( inp[1], SCALEFACTOR5 ); - x2 = CL_shr( inp[2], SCALEFACTOR5 ); - x3 = CL_shr( inp[3], SCALEFACTOR5 ); - x4 = CL_shr( inp[4], SCALEFACTOR5 ); + x0 = CL_shr( inp[0], SCALEFACTOR5 ); // Qx - 4 + x1 = CL_shr( inp[1], SCALEFACTOR5 ); // Qx - 4 + x2 = CL_shr( inp[2], SCALEFACTOR5 ); // Qx - 4 + x3 = CL_shr( inp[3], SCALEFACTOR5 ); // Qx - 4 + x4 = CL_shr( inp[4], SCALEFACTOR5 ); // Qx - 4 y1 = CL_add( x1, x4 ); y4 = CL_sub( x1, x4 ); @@ -162,14 +162,14 @@ static void fft5_with_cmplx_data( cmplx *inp ) * * \return void */ -static void fft8_with_cmplx_data( cmplx *inp ) +static void fft8_with_cmplx_data( cmplx *inp /*Qx*/ ) { cmplx x0, x1, x2, x3, x4, x5, x6, x7; cmplx s0, s1, s2, s3, s4, s5, s6, s7; cmplx t0, t1, t2, t3, t4, t5, t6, t7; /* Pre-additions */ - x0 = CL_shr( inp[0], SCALEFACTOR8 ); + x0 = CL_shr( inp[0], SCALEFACTOR8 ); // Qx - 4 x1 = CL_shr( inp[1], SCALEFACTOR8 ); x2 = CL_shr( inp[2], SCALEFACTOR8 ); x3 = CL_shr( inp[3], SCALEFACTOR8 ); @@ -244,7 +244,7 @@ static void fft8_with_cmplx_data( cmplx *inp ) * \return void */ -static void fft10_with_cmplx_data( cmplx *inp_data ) +static void fft10_with_cmplx_data( cmplx *inp_data /*Qx*/ ) { cmplx r1, r2, r3, r4; cmplx x0, x1, x2, x3, x4, t; @@ -252,7 +252,7 @@ static void fft10_with_cmplx_data( cmplx *inp_data ) /* FOR i=0 */ { - x0 = CL_shr( inp_data[0], SCALEFACTOR10 ); + x0 = CL_shr( inp_data[0], SCALEFACTOR10 ); // Qx - 5 x1 = CL_shr( inp_data[2], SCALEFACTOR10 ); x2 = CL_shr( inp_data[4], SCALEFACTOR10 ); x3 = CL_shr( inp_data[6], SCALEFACTOR10 ); @@ -280,7 +280,7 @@ static void fft10_with_cmplx_data( cmplx *inp_data ) } /* FOR i=1 */ { - x0 = CL_shr( inp_data[5], SCALEFACTOR10 ); + x0 = CL_shr( inp_data[5], SCALEFACTOR10 ); // Qx - 5 x1 = CL_shr( inp_data[1], SCALEFACTOR10 ); x2 = CL_shr( inp_data[3], SCALEFACTOR10 ); x3 = CL_shr( inp_data[7], SCALEFACTOR10 ); @@ -353,14 +353,14 @@ static void fft10_with_cmplx_data( cmplx *inp_data ) * \return void */ -static void fft15_with_cmplx_data( cmplx *inp_data ) +static void fft15_with_cmplx_data( cmplx *inp_data /*Qx*/ ) { cmplx c0, c1, c2, c3, c4, c5, c6, c7, c8, c9, c10, c11, c12, c13, c14; cmplx c_z0, c_z1, c_z2, c_z3, c_z4, c_z5, c_z6, c_z7, c_z8, c_z9, c_z10, c_z11, c_z12, c_z13, c_z14; cmplx c_y1, c_y2, c_y3, c_y4; cmplx c_t; - c0 = CL_shr( inp_data[0], SCALEFACTOR15 ); + c0 = CL_shr( inp_data[0], SCALEFACTOR15 ); // Qx - 5 c1 = CL_shr( inp_data[3], SCALEFACTOR15 ); c2 = CL_shr( inp_data[6], SCALEFACTOR15 ); c3 = CL_shr( inp_data[9], SCALEFACTOR15 ); @@ -497,8 +497,8 @@ static void fft15_with_cmplx_data( cmplx *inp_data ) * WOPS with 32x16 bit multiplications (scale on ): 288 cycles * WOPS with 32x16 bit multiplications (scale off): 256 cycles * - * \param [i/o] re real input / output - * \param [i/o] im imag input / output + * \param [i/o] re real input / output Qx + * \param [i/o] im imag input / output Qx * \param [i ] s stride real and imag input / output * * \return void @@ -529,7 +529,7 @@ void fft16( Word32 *re, Word32 *im, Word16 s, Word16 bScale ) } } -void fft16_with_cmplx_data( cmplx *input, Word16 bScale ) +void fft16_with_cmplx_data( cmplx *input /*Qx*/, Word16 bScale ) { cmplx x0, x1, x2, x3, temp; cmplx t0, t2, t4, t6, t7; @@ -538,7 +538,7 @@ void fft16_with_cmplx_data( cmplx *input, Word16 bScale ) IF( bScale ) { { - x0 = CL_shr( input[0], SCALEFACTOR16 ); + x0 = CL_shr( input[0], SCALEFACTOR16 ); // Qx - 5 x1 = CL_shr( input[4], SCALEFACTOR16 ); x2 = CL_shr( input[8], SCALEFACTOR16 ); x3 = CL_shr( input[12], SCALEFACTOR16 ); @@ -553,7 +553,7 @@ void fft16_with_cmplx_data( cmplx *input, Word16 bScale ) y[3] = CL_add( t2, t6 ); - x0 = CL_shr( input[1], SCALEFACTOR16 ); + x0 = CL_shr( input[1], SCALEFACTOR16 ); // Qx - 5 x1 = CL_shr( input[5], SCALEFACTOR16 ); x2 = CL_shr( input[9], SCALEFACTOR16 ); x3 = CL_shr( input[13], SCALEFACTOR16 ); @@ -568,7 +568,7 @@ void fft16_with_cmplx_data( cmplx *input, Word16 bScale ) y[7] = CL_add( t2, t6 ); - x0 = CL_shr( input[2], SCALEFACTOR16 ); + x0 = CL_shr( input[2], SCALEFACTOR16 ); // Qx - 5 x1 = CL_shr( input[6], SCALEFACTOR16 ); x2 = CL_shr( input[10], SCALEFACTOR16 ); x3 = CL_shr( input[14], SCALEFACTOR16 ); @@ -584,7 +584,7 @@ void fft16_with_cmplx_data( cmplx *input, Word16 bScale ) y[11] = CL_add( t2, t6 ); - x0 = CL_shr( input[3], SCALEFACTOR16 ); + x0 = CL_shr( input[3], SCALEFACTOR16 ); // Qx - 5 x1 = CL_shr( input[7], SCALEFACTOR16 ); x2 = CL_shr( input[11], SCALEFACTOR16 ); x3 = CL_shr( input[15], SCALEFACTOR16 ); @@ -736,7 +736,7 @@ void fft16_with_cmplx_data( cmplx *input, Word16 bScale ) * * \return void */ -static void fft20_with_cmplx_data( cmplx *inp_data ) +static void fft20_with_cmplx_data( cmplx *inp_data /*Qx*/ ) { cmplx r1, r2, r3, r4; cmplx x0, x1, x2, x3, x4; @@ -751,7 +751,7 @@ static void fft20_with_cmplx_data( cmplx *inp_data ) y4 = &y[12]; { - x0 = CL_shr( inp_data[0], SCALEFACTOR20 ); + x0 = CL_shr( inp_data[0], SCALEFACTOR20 ); // Qx - 5 x1 = CL_shr( inp_data[16], SCALEFACTOR20 ); x2 = CL_shr( inp_data[12], SCALEFACTOR20 ); x3 = CL_shr( inp_data[8], SCALEFACTOR20 ); @@ -778,7 +778,7 @@ static void fft20_with_cmplx_data( cmplx *inp_data ) y4[0] = CL_msu_j( r3, r4 ); } { - x0 = CL_shr( inp_data[5], SCALEFACTOR20 ); + x0 = CL_shr( inp_data[5], SCALEFACTOR20 ); // Qx - 5 x1 = CL_shr( inp_data[1], SCALEFACTOR20 ); x2 = CL_shr( inp_data[17], SCALEFACTOR20 ); x3 = CL_shr( inp_data[13], SCALEFACTOR20 ); @@ -805,7 +805,7 @@ static void fft20_with_cmplx_data( cmplx *inp_data ) y4[1] = CL_msu_j( r3, r4 ); } { - x0 = CL_shr( inp_data[10], SCALEFACTOR20 ); + x0 = CL_shr( inp_data[10], SCALEFACTOR20 ); // Qx - 5 x1 = CL_shr( inp_data[6], SCALEFACTOR20 ); x2 = CL_shr( inp_data[2], SCALEFACTOR20 ); x3 = CL_shr( inp_data[18], SCALEFACTOR20 ); @@ -832,7 +832,7 @@ static void fft20_with_cmplx_data( cmplx *inp_data ) y4[2] = CL_msu_j( r3, r4 ); } { - x0 = CL_shr( inp_data[15], SCALEFACTOR20 ); + x0 = CL_shr( inp_data[15], SCALEFACTOR20 ); // Qx - 5 x1 = CL_shr( inp_data[11], SCALEFACTOR20 ); x2 = CL_shr( inp_data[7], SCALEFACTOR20 ); x3 = CL_shr( inp_data[3], SCALEFACTOR20 ); @@ -985,7 +985,7 @@ static void fft20_with_cmplx_data( cmplx *inp_data ) * \return void */ -static void fft30_with_cmplx_data( cmplx *inp ) +static void fft30_with_cmplx_data( cmplx *inp /*Qx*/ ) { cmplx *l = &inp[0]; cmplx *h = &inp[15]; @@ -994,19 +994,19 @@ static void fft30_with_cmplx_data( cmplx *inp ) /* 1. FFT15 stage */ - x[0] = CL_shr( inp[0], SCALEFACTOR30_1 ); + x[0] = CL_shr( inp[0], SCALEFACTOR30_1 ); // Qx - 5 x[1] = CL_shr( inp[18], SCALEFACTOR30_1 ); x[2] = CL_shr( inp[6], SCALEFACTOR30_1 ); x[3] = CL_shr( inp[24], SCALEFACTOR30_1 ); x[4] = CL_shr( inp[12], SCALEFACTOR30_1 ); - x[5] = CL_shr( inp[20], SCALEFACTOR30_1 ); + x[5] = CL_shr( inp[20], SCALEFACTOR30_1 ); // Qx - 5 x[6] = CL_shr( inp[8], SCALEFACTOR30_1 ); x[7] = CL_shr( inp[26], SCALEFACTOR30_1 ); x[8] = CL_shr( inp[14], SCALEFACTOR30_1 ); x[9] = CL_shr( inp[2], SCALEFACTOR30_1 ); - x[10] = CL_shr( inp[10], SCALEFACTOR30_1 ); + x[10] = CL_shr( inp[10], SCALEFACTOR30_1 ); // Qx - 5 x[11] = CL_shr( inp[28], SCALEFACTOR30_1 ); x[12] = CL_shr( inp[16], SCALEFACTOR30_1 ); x[13] = CL_shr( inp[4], SCALEFACTOR30_1 ); @@ -1140,19 +1140,19 @@ static void fft30_with_cmplx_data( cmplx *inp ) /* 2. FFT15 stage */ - x[0] = CL_shr( inp[15], SCALEFACTOR30_1 ); + x[0] = CL_shr( inp[15], SCALEFACTOR30_1 ); // Qx - 5 x[1] = CL_shr( inp[3], SCALEFACTOR30_1 ); x[2] = CL_shr( inp[21], SCALEFACTOR30_1 ); x[3] = CL_shr( inp[9], SCALEFACTOR30_1 ); x[4] = CL_shr( inp[27], SCALEFACTOR30_1 ); - x[5] = CL_shr( inp[5], SCALEFACTOR30_1 ); + x[5] = CL_shr( inp[5], SCALEFACTOR30_1 ); // Qx - 5 x[6] = CL_shr( inp[23], SCALEFACTOR30_1 ); x[7] = CL_shr( inp[11], SCALEFACTOR30_1 ); x[8] = CL_shr( inp[29], SCALEFACTOR30_1 ); x[9] = CL_shr( inp[17], SCALEFACTOR30_1 ); - x[10] = CL_shr( inp[25], SCALEFACTOR30_1 ); + x[10] = CL_shr( inp[25], SCALEFACTOR30_1 ); // Qx - 5 x[11] = CL_shr( inp[13], SCALEFACTOR30_1 ); x[12] = CL_shr( inp[1], SCALEFACTOR30_1 ); x[13] = CL_shr( inp[19], SCALEFACTOR30_1 ); @@ -1425,14 +1425,14 @@ static void fft30_with_cmplx_data( cmplx *inp ) */ -static void fft32_with_cmplx_data( cmplx *inp ) +static void fft32_with_cmplx_data( cmplx *inp /*Qx*/ ) { cmplx x[32], y[32], t[32], s[32], temp, temp1; const cmplx_s *pRotVector_32 = (const cmplx_s *) RotVector_32; /* 1. FFT8 stage */ - x[0] = CL_shr( inp[0], SCALEFACTOR32_1 ); + x[0] = CL_shr( inp[0], SCALEFACTOR32_1 ); // Qx - 5 x[1] = CL_shr( inp[4], SCALEFACTOR32_1 ); x[2] = CL_shr( inp[8], SCALEFACTOR32_1 ); x[3] = CL_shr( inp[12], SCALEFACTOR32_1 ); @@ -1478,7 +1478,7 @@ static void fft32_with_cmplx_data( cmplx *inp ) /* 2. FFT8 stage */ - x[0] = CL_shr( inp[1], SCALEFACTOR32_1 ); + x[0] = CL_shr( inp[1], SCALEFACTOR32_1 ); // Qx - 5 x[1] = CL_shr( inp[5], SCALEFACTOR32_1 ); x[2] = CL_shr( inp[9], SCALEFACTOR32_1 ); x[3] = CL_shr( inp[13], SCALEFACTOR32_1 ); @@ -1525,7 +1525,7 @@ static void fft32_with_cmplx_data( cmplx *inp ) /* 3. FFT8 stage */ - x[0] = CL_shr( inp[2], SCALEFACTOR32_1 ); + x[0] = CL_shr( inp[2], SCALEFACTOR32_1 ); // Qx - 5 x[1] = CL_shr( inp[6], SCALEFACTOR32_1 ); x[2] = CL_shr( inp[10], SCALEFACTOR32_1 ); x[3] = CL_shr( inp[14], SCALEFACTOR32_1 ); @@ -1572,7 +1572,7 @@ static void fft32_with_cmplx_data( cmplx *inp ) /* 4. FFT8 stage */ - x[0] = CL_shr( inp[3], SCALEFACTOR32_1 ); + x[0] = CL_shr( inp[3], SCALEFACTOR32_1 ); // Qx - 5 x[1] = CL_shr( inp[7], SCALEFACTOR32_1 ); x[2] = CL_shr( inp[11], SCALEFACTOR32_1 ); x[3] = CL_shr( inp[15], SCALEFACTOR32_1 ); diff --git a/lib_com/fft_fx.c b/lib_com/fft_fx.c index 27adc56fe..6b8b49bd2 100644 --- a/lib_com/fft_fx.c +++ b/lib_com/fft_fx.c @@ -65,32 +65,32 @@ #define FFTC( x ) WORD322WORD16( (Word32) x ) /* DCT related */ -#define KP559016994_16FX ( FFTC( 1200479845 ) ) /* EDCT & EMDCT constants */ -#define KP951056516_16FX ( FFTC( 2042378325 ) ) /* EDCT & EMDCT constants */ -#define KP587785252_16FX ( FFTC( 1262259213 ) ) /* EDCT & EMDCT constants */ +#define KP559016994_16FX ( FFTC( 1200479845 ) ) /* EDCT & EMDCT constants Q15*/ +#define KP951056516_16FX ( FFTC( 2042378325 ) ) /* EDCT & EMDCT constants Q15*/ +#define KP587785252_16FX ( FFTC( 1262259213 ) ) /* EDCT & EMDCT constants Q15*/ -#define FFT_15PONIT_WNK1 ( FFTC( 0x478dde64 ) ) /* EDCT & EMDCT constants */ -#define FFT_15PONIT_WNK2 ( FFTC( 0x79bc3854 ) ) /* EDCT & EMDCT constants */ -#define FFT_15PONIT_WNK3 ( FFTC( 0x4B3C8C0D ) ) /* EDCT & EMDCT constants */ -#define FFT_15PONIT_WNK4 ( FFTC( 0x6ED9EBA0 ) ) /* EDCT & EMDCT constants */ -#define FFT_15PONIT_WNK5 ( FFTC( 0x20000000 ) ) /* EDCT & EMDCT constants */ +#define FFT_15PONIT_WNK1 ( FFTC( 0x478dde64 ) ) /* EDCT & EMDCT constants Q15*/ +#define FFT_15PONIT_WNK2 ( FFTC( 0x79bc3854 ) ) /* EDCT & EMDCT constants Q15*/ +#define FFT_15PONIT_WNK3 ( FFTC( 0x4B3C8C0D ) ) /* EDCT & EMDCT constants Q15*/ +#define FFT_15PONIT_WNK4 ( FFTC( 0x6ED9EBA0 ) ) /* EDCT & EMDCT constants Q15*/ +#define FFT_15PONIT_WNK5 ( FFTC( 0x20000000 ) ) /* EDCT & EMDCT constants Q15*/ /* FFT constants */ -#define FFT_C31 ( FFTC( 0x91261468 ) ) /* FL2WORD32( -0.86602540) -sqrt(3)/2 */ -#define FFT_C51 ( FFTC( 0x79bc3854 ) ) /* FL2WORD32( 0.95105652) */ -#define FFT_C52 ( FFTC( 0x9d839db0 ) ) /* FL2WORD32(-1.53884180/2) */ -#define FFT_C53 ( FFTC( 0xd18053ce ) ) /* FL2WORD32(-0.36327126) */ -#define FFT_C54 ( FFTC( 0x478dde64 ) ) /* FL2WORD32( 0.55901699) */ -#define FFT_C55 ( FFTC( 0xb0000001 ) ) /* FL2WORD32(-1.25/2) */ -#define FFT_C61 ( FFTC( 0x6ED9EBA0 ) ) -#define FFT_C81 ( FFTC( 0x5a82799a ) ) -#define FFT_C82 ( FFTC( 0xa57d8666 ) ) -#define FFT_C161 ( FFTC( 0x5a82799a ) ) /* FL2WORD32( 7.071067811865475e-1) INV_SQRT2 */ -#define FFT_C162 ( FFTC( 0xa57d8666 ) ) /* FL2WORD32(-7.071067811865475e-1) -INV_SQRT2 */ -#define FFT_C163 ( FFTC( 0x7641af3d ) ) /* FL2WORD32( 9.238795325112867e-1) COS_PI_DIV8 */ -#define FFT_C164 ( FFTC( 0x89be50c3 ) ) /* FL2WORD32(-9.238795325112867e-1) -COS_PI_DIV8 */ -#define FFT_C165 ( FFTC( 0x30fbc54d ) ) /* FL2WORD32( 3.826834323650898e-1) COS_3PI_DIV8 */ -#define FFT_C166 ( FFTC( 0xcf043ab3 ) ) /* FL2WORD32(-3.826834323650898e-1) -COS_3PI_DIV8 */ +#define FFT_C31 ( FFTC( 0x91261468 ) ) /* FL2WORD32( -0.86602540) -sqrt(3)/2 Q15*/ +#define FFT_C51 ( FFTC( 0x79bc3854 ) ) /* FL2WORD32( 0.95105652) Q15*/ +#define FFT_C52 ( FFTC( 0x9d839db0 ) ) /* FL2WORD32(-1.53884180/2) Q15*/ +#define FFT_C53 ( FFTC( 0xd18053ce ) ) /* FL2WORD32(-0.36327126) Q15*/ +#define FFT_C54 ( FFTC( 0x478dde64 ) ) /* FL2WORD32( 0.55901699) Q15*/ +#define FFT_C55 ( FFTC( 0xb0000001 ) ) /* FL2WORD32(-1.25/2) Q15*/ +#define FFT_C61 ( FFTC( 0x6ED9EBA0 ) ) // Q15 +#define FFT_C81 ( FFTC( 0x5a82799a ) ) // Q15 +#define FFT_C82 ( FFTC( 0xa57d8666 ) ) // Q15 +#define FFT_C161 ( FFTC( 0x5a82799a ) ) /* FL2WORD32( 7.071067811865475e-1) INV_SQRT2 Q15*/ +#define FFT_C162 ( FFTC( 0xa57d8666 ) ) /* FL2WORD32(-7.071067811865475e-1) -INV_SQRT2 Q15*/ +#define FFT_C163 ( FFTC( 0x7641af3d ) ) /* FL2WORD32( 9.238795325112867e-1) COS_PI_DIV8 Q15*/ +#define FFT_C164 ( FFTC( 0x89be50c3 ) ) /* FL2WORD32(-9.238795325112867e-1) -COS_PI_DIV8 Q15*/ +#define FFT_C165 ( FFTC( 0x30fbc54d ) ) /* FL2WORD32( 3.826834323650898e-1) COS_3PI_DIV8 Q15*/ +#define FFT_C166 ( FFTC( 0xcf043ab3 ) ) /* FL2WORD32(-3.826834323650898e-1) -COS_3PI_DIV8 Q15*/ #define SCALEFACTOR16 ( 0 ) #define SCALEFACTOR20 ( 0 ) @@ -167,9 +167,9 @@ void DoRTFTn_fx_ivas( static void fft15_shift2( Word16 n1, /* i : length of data */ - Word32 *zRe, /* i/o: real part of input and output data */ - Word32 *zIm, /* i/o: imaginary part of input and output data */ - const Word16 *Idx /* i : pointer of the address table */ + Word32 *zRe, /* i/o: real part of input and output data Qx */ + Word32 *zIm, /* i/o: imaginary part of input and output data Qx */ + const Word16 *Idx /* i : pointer of the address table Q0 */ ) { Word16 in0, in8, in16, in24, in32, in1, in9, in17, in25, in33, in2, in10, in18, in26, in34; @@ -192,47 +192,47 @@ static void fft15_shift2( move16(); in16 = Idx[n1 * 2]; move16(); - in24 = Idx[i_mult( n1, 3 )]; + in24 = Idx[( n1 * 3 )]; move16(); in32 = Idx[n1 * 4]; move16(); - in1 = Idx[i_mult( n1, 5 )]; + in1 = Idx[( n1 * 5 )]; move16(); in9 = Idx[n1 * 6]; move16(); - in17 = Idx[i_mult( n1, 7 )]; + in17 = Idx[( n1 * 7 )]; move16(); in25 = Idx[n1 * 8]; move16(); - in33 = Idx[i_mult( n1, 9 )]; + in33 = Idx[( n1 * 9 )]; move16(); in2 = Idx[n1 * 10]; move16(); - in10 = Idx[i_mult( n1, 11 )]; + in10 = Idx[( n1 * 11 )]; move16(); in18 = Idx[n1 * 12]; move16(); - in26 = Idx[i_mult( n1, 13 )]; + in26 = Idx[( n1 * 13 )]; move16(); in34 = Idx[n1 * 14]; move16(); - f2i13 = zRe[in0]; + f2i13 = zRe[in0]; // Qx move32(); - f2i14 = zIm[in0]; + f2i14 = zIm[in0]; // Qx move32(); - f2i21 = zRe[in1]; + f2i21 = zRe[in1]; // Qx move32(); - f2i22 = zRe[in2]; + f2i22 = zRe[in2]; // Qx move32(); - f2i23 = zIm[in1]; + f2i23 = zIm[in1]; // Qx move32(); - f2i24 = zIm[in2]; + f2i24 = zIm[in2]; // Qx move32(); f2i15 = L_add( f2i21, f2i22 ); - f2i16 = Mpy_32_16_1( L_sub( f2i22, f2i21 ), FFT_15PONIT_WNK4 ); - f2i17 = Mpy_32_16_1( L_sub( f2i23, f2i24 ), FFT_15PONIT_WNK4 ); + f2i16 = Mpy_32_16_1( L_sub( f2i22, f2i21 ), FFT_15PONIT_WNK4 ); // Qx + f2i17 = Mpy_32_16_1( L_sub( f2i23, f2i24 ), FFT_15PONIT_WNK4 ); // Qx f2i18 = L_add( f2i23, f2i24 ); fi1 = L_add( f2i13, f2i15 ); fi2 = L_add( f2i14, f2i18 ); @@ -244,44 +244,44 @@ static void fft15_shift2( fi5 = L_add( f2i16, f2i20 ); fi6 = L_sub( f2i20, f2i16 ); - f3i1 = zRe[in9]; + f3i1 = zRe[in9]; // Qx move32(); - f4i2 = zRe[in10]; + f4i2 = zRe[in10]; // Qx move32(); - f4i3 = zRe[in8]; + f4i3 = zRe[in8]; // Qx move32(); f3i2 = L_add( f4i2, f4i3 ); f3i3 = L_sub( f3i1, L_shr( f3i2, 1 ) ); - f3i4 = Mpy_32_16_1( L_sub( f4i3, f4i2 ), FFT_15PONIT_WNK4 ); + f3i4 = Mpy_32_16_1( L_sub( f4i3, f4i2 ), FFT_15PONIT_WNK4 ); // Qx - f3i5 = zIm[in9]; + f3i5 = zIm[in9]; // Qx move32(); - f4i4 = zIm[in10]; + f4i4 = zIm[in10]; // Qx move32(); - f4i5 = zIm[in8]; + f4i5 = zIm[in8]; // Qx move32(); f3i6 = L_add( f4i4, f4i5 ); - f3i7 = Mpy_32_16_1( L_sub( f4i4, f4i5 ), FFT_15PONIT_WNK4 ); + f3i7 = Mpy_32_16_1( L_sub( f4i4, f4i5 ), FFT_15PONIT_WNK4 ); // Qx f3i8 = L_sub( f3i5, L_shr( f3i6, 1 ) ); - f3i9 = zRe[in33]; + f3i9 = zRe[in33]; // Qx move32(); - f4i6 = zRe[in34]; + f4i6 = zRe[in34]; // Qx move32(); - f4i7 = zRe[in32]; + f4i7 = zRe[in32]; // Qx move32(); f3i10 = L_add( f4i6, f4i7 ); f3i11 = L_sub( f3i9, L_shr( f3i10, 1 ) ); - f3i12 = Mpy_32_16_1( L_sub( f4i7, f4i6 ), FFT_15PONIT_WNK4 ); + f3i12 = Mpy_32_16_1( L_sub( f4i7, f4i6 ), FFT_15PONIT_WNK4 ); // Qx - f3i13 = zIm[in33]; + f3i13 = zIm[in33]; // Qx move32(); - f4i8 = zIm[in34]; + f4i8 = zIm[in34]; // Qx move32(); - f4i9 = zIm[in32]; + f4i9 = zIm[in32]; // Qx move32(); f3i14 = L_add( f4i8, f4i9 ); - f3i15 = Mpy_32_16_1( L_sub( f4i8, f4i9 ), FFT_15PONIT_WNK4 ); + f3i15 = Mpy_32_16_1( L_sub( f4i8, f4i9 ), FFT_15PONIT_WNK4 ); // Qx f4i1 = L_sub( f3i13, L_shr( f3i14, 1 ) ); fi7 = L_add( f3i1, f3i2 ); @@ -303,44 +303,44 @@ static void fft15_shift2( fi23 = L_add( f3i11, f3i15 ); fi24 = L_add( fi22, fi23 ); - f4i10 = zRe[in24]; + f4i10 = zRe[in24]; // Qx move32(); - fo6 = zRe[in25]; + fo6 = zRe[in25]; // Qx move32(); - fo7 = zRe[in26]; + fo7 = zRe[in26]; // Qx move32(); f4i11 = L_add( fo6, fo7 ); f4i12 = L_sub( f4i10, L_shr( f4i11, 1 ) ); - f4i13 = Mpy_32_16_1( L_sub( fo7, fo6 ), FFT_15PONIT_WNK4 ); + f4i13 = Mpy_32_16_1( L_sub( fo7, fo6 ), FFT_15PONIT_WNK4 ); // Qx - f4i14 = zIm[in24]; + f4i14 = zIm[in24]; // Qx move32(); - fo8 = zIm[in25]; + fo8 = zIm[in25]; // Qx move32(); - fo9 = zIm[in26]; + fo9 = zIm[in26]; // Qx move32(); f4i15 = L_add( fo8, fo9 ); - f4i16 = Mpy_32_16_1( L_sub( fo8, fo9 ), FFT_15PONIT_WNK4 ); + f4i16 = Mpy_32_16_1( L_sub( fo8, fo9 ), FFT_15PONIT_WNK4 ); // Qx f4i17 = L_sub( f4i14, L_shr( f4i15, 1 ) ); - f4i18 = zRe[in18]; + f4i18 = zRe[in18]; // Qx move32(); - f2o10 = zRe[in16]; + f2o10 = zRe[in16]; // Qx move32(); - f2o11 = zRe[in17]; + f2o11 = zRe[in17]; // Qx move32(); f4i19 = L_add( f2o10, f2o11 ); f4i20 = L_sub( f4i18, L_shr( f4i19, 1 ) ); - fo1 = Mpy_32_16_1( L_sub( f2o11, f2o10 ), FFT_15PONIT_WNK4 ); + fo1 = Mpy_32_16_1( L_sub( f2o11, f2o10 ), FFT_15PONIT_WNK4 ); // Qx - fo2 = zIm[in18]; + fo2 = zIm[in18]; // Qx move32(); - f2o12 = zIm[in16]; + f2o12 = zIm[in16]; // Qx move32(); - f2o13 = zIm[in17]; + f2o13 = zIm[in17]; // Qx move32(); fo3 = L_add( f2o12, f2o13 ); - fo4 = Mpy_32_16_1( L_sub( f2o12, f2o13 ), FFT_15PONIT_WNK4 ); + fo4 = Mpy_32_16_1( L_sub( f2o12, f2o13 ), FFT_15PONIT_WNK4 ); // Qx fo5 = L_sub( fo2, L_shr( fo3, 1 ) ); fi25 = L_add( f4i10, f4i11 ); @@ -362,13 +362,13 @@ static void fft15_shift2( f2i11 = L_add( f4i20, fo4 ); f2i12 = L_add( f2i10, f2i11 ); - fo10 = Mpy_32_16_1( L_sub( fi27, fi9 ), FFT_15PONIT_WNK1 ); + fo10 = Mpy_32_16_1( L_sub( fi27, fi9 ), FFT_15PONIT_WNK1 ); // Qx fo11 = L_add( fi27, fi9 ); - fo12 = L_sub( fi1, Mpy_32_16_1( fo11, FFT_15PONIT_WNK5 ) ); + fo12 = L_sub( fi1, Mpy_32_16_1( fo11, FFT_15PONIT_WNK5 ) ); // Qx fo15 = L_sub( fi13, fi14 ); fo16 = L_sub( f2i1, f2i2 ); - fo13 = L_sub( Mpy_32_16_1( fo15, FFT_15PONIT_WNK2 ), Mpy_32_16_1( fo16, FFT_15PONIT_WNK3 ) ); - fo14 = L_add( Mpy_32_16_1( fo15, FFT_15PONIT_WNK3 ), Mpy_32_16_1( fo16, FFT_15PONIT_WNK2 ) ); + fo13 = L_sub( Mpy_32_16_1( fo15, FFT_15PONIT_WNK2 ), Mpy_32_16_1( fo16, FFT_15PONIT_WNK3 ) ); // Qx + fo14 = L_add( Mpy_32_16_1( fo15, FFT_15PONIT_WNK3 ), Mpy_32_16_1( fo16, FFT_15PONIT_WNK2 ) ); // Qx zRe[in0] = L_add( fi1, fo11 ); move32(); @@ -383,13 +383,13 @@ static void fft15_shift2( zRe[in33] = L_add( fo18, fo13 ); move32(); - f2o1 = Mpy_32_16_1( L_sub( f2i3, fi15 ), FFT_15PONIT_WNK1 ); + f2o1 = Mpy_32_16_1( L_sub( f2i3, fi15 ), FFT_15PONIT_WNK1 ); // Qx f2o2 = L_add( f2i3, fi15 ); - f2o3 = L_sub( fi2, Mpy_32_16_1( f2o2, FFT_15PONIT_WNK5 ) ); + f2o3 = L_sub( fi2, Mpy_32_16_1( f2o2, FFT_15PONIT_WNK5 ) ); // Qx f2o6 = L_sub( fi7, fi8 ); f2o7 = L_sub( fi25, fi26 ); - f2o4 = L_sub( Mpy_32_16_1( f2o6, FFT_15PONIT_WNK2 ), Mpy_32_16_1( f2o7, FFT_15PONIT_WNK3 ) ); - f2o5 = L_add( Mpy_32_16_1( f2o6, FFT_15PONIT_WNK3 ), Mpy_32_16_1( f2o7, FFT_15PONIT_WNK2 ) ); + f2o4 = L_sub( Mpy_32_16_1( f2o6, FFT_15PONIT_WNK2 ), Mpy_32_16_1( f2o7, FFT_15PONIT_WNK3 ) ); // Qx + f2o5 = L_add( Mpy_32_16_1( f2o6, FFT_15PONIT_WNK3 ), Mpy_32_16_1( f2o7, FFT_15PONIT_WNK2 ) ); // Qx zIm[in0] = L_add( fi2, f2o2 ); move32(); f2o8 = L_add( f2o1, f2o3 ); @@ -403,13 +403,13 @@ static void fft15_shift2( zIm[in9] = L_add( f2o4, f2o9 ); move32(); - f2o14 = Mpy_32_16_1( L_sub( fi30, fi12 ), FFT_15PONIT_WNK1 ); + f2o14 = Mpy_32_16_1( L_sub( fi30, fi12 ), FFT_15PONIT_WNK1 ); // Qx f2o15 = L_add( fi30, fi12 ); - f3o1 = L_sub( fi3, Mpy_32_16_1( f2o15, FFT_15PONIT_WNK5 ) ); + f3o1 = L_sub( fi3, Mpy_32_16_1( f2o15, FFT_15PONIT_WNK5 ) ); // Qx f3o4 = L_sub( fi16, fi17 ); f3o5 = L_sub( f2i4, f2i5 ); - f3o2 = L_sub( Mpy_32_16_1( f3o4, FFT_15PONIT_WNK2 ), Mpy_32_16_1( f3o5, FFT_15PONIT_WNK3 ) ); - f3o3 = L_add( Mpy_32_16_1( f3o5, FFT_15PONIT_WNK2 ), Mpy_32_16_1( f3o4, FFT_15PONIT_WNK3 ) ); + f3o2 = L_sub( Mpy_32_16_1( f3o4, FFT_15PONIT_WNK2 ), Mpy_32_16_1( f3o5, FFT_15PONIT_WNK3 ) ); // Qx + f3o3 = L_add( Mpy_32_16_1( f3o5, FFT_15PONIT_WNK2 ), Mpy_32_16_1( f3o4, FFT_15PONIT_WNK3 ) ); // Qx zRe[in2] = L_add( fi3, f2o15 ); move32(); f3o6 = L_add( f2o14, f3o1 ); @@ -423,13 +423,13 @@ static void fft15_shift2( zRe[in32] = L_add( f3o7, f3o2 ); move32(); - f3o8 = Mpy_32_16_1( L_sub( f2i6, fi18 ), FFT_15PONIT_WNK1 ); + f3o8 = Mpy_32_16_1( L_sub( f2i6, fi18 ), FFT_15PONIT_WNK1 ); // Qx f3o9 = L_add( f2i6, fi18 ); - f3o10 = L_sub( fi6, Mpy_32_16_1( f3o9, FFT_15PONIT_WNK5 ) ); + f3o10 = L_sub( fi6, Mpy_32_16_1( f3o9, FFT_15PONIT_WNK5 ) ); // Qx f3o13 = L_sub( fi10, fi11 ); f3o14 = L_sub( fi28, fi29 ); - f3o11 = L_sub( Mpy_32_16_1( f3o13, FFT_15PONIT_WNK2 ), Mpy_32_16_1( f3o14, FFT_15PONIT_WNK3 ) ); - f3o12 = L_add( Mpy_32_16_1( f3o14, FFT_15PONIT_WNK2 ), Mpy_32_16_1( f3o13, FFT_15PONIT_WNK3 ) ); + f3o11 = L_sub( Mpy_32_16_1( f3o13, FFT_15PONIT_WNK2 ), Mpy_32_16_1( f3o14, FFT_15PONIT_WNK3 ) ); // Qx + f3o12 = L_add( Mpy_32_16_1( f3o14, FFT_15PONIT_WNK2 ), Mpy_32_16_1( f3o13, FFT_15PONIT_WNK3 ) ); // Qx zIm[in2] = L_add( fi6, f3o9 ); move32(); f3o15 = L_add( f3o8, f3o10 ); @@ -443,13 +443,13 @@ static void fft15_shift2( zIm[in32] = L_sub( f4o1, f3o11 ); move32(); - f4o2 = Mpy_32_16_1( L_sub( f2i9, fi21 ), FFT_15PONIT_WNK1 ); + f4o2 = Mpy_32_16_1( L_sub( f2i9, fi21 ), FFT_15PONIT_WNK1 ); // Qx f4o3 = L_add( f2i9, fi21 ); - f4o4 = L_sub( fi5, Mpy_32_16_1( f4o3, FFT_15PONIT_WNK5 ) ); + f4o4 = L_sub( fi5, Mpy_32_16_1( f4o3, FFT_15PONIT_WNK5 ) ); // Qx f4o7 = L_sub( f2i10, f2i11 ); f4o8 = L_sub( fi22, fi23 ); - f4o5 = L_add( Mpy_32_16_1( f4o8, FFT_15PONIT_WNK3 ), Mpy_32_16_1( f4o7, FFT_15PONIT_WNK2 ) ); - f4o6 = L_sub( Mpy_32_16_1( f4o8, FFT_15PONIT_WNK2 ), Mpy_32_16_1( f4o7, FFT_15PONIT_WNK3 ) ); + f4o5 = L_add( Mpy_32_16_1( f4o8, FFT_15PONIT_WNK3 ), Mpy_32_16_1( f4o7, FFT_15PONIT_WNK2 ) ); // Qx + f4o6 = L_sub( Mpy_32_16_1( f4o8, FFT_15PONIT_WNK2 ), Mpy_32_16_1( f4o7, FFT_15PONIT_WNK3 ) ); // Qx zIm[in1] = L_add( fi5, f4o3 ); move32(); f4o9 = L_sub( f4o4, f4o2 ); @@ -464,13 +464,13 @@ static void fft15_shift2( zIm[in16] = L_add( f4o5, f4o10 ); move32(); - f4o11 = Mpy_32_16_1( L_sub( f2i12, fi24 ), FFT_15PONIT_WNK1 ); + f4o11 = Mpy_32_16_1( L_sub( f2i12, fi24 ), FFT_15PONIT_WNK1 ); // Qx f4o12 = L_add( f2i12, fi24 ); - f4o13 = L_sub( fi4, Mpy_32_16_1( f4o12, FFT_15PONIT_WNK5 ) ); + f4o13 = L_sub( fi4, Mpy_32_16_1( f4o12, FFT_15PONIT_WNK5 ) ); // Qx f4o16 = L_sub( f2i7, f2i8 ); f4o17 = L_sub( fi19, fi20 ); - f4o14 = L_add( Mpy_32_16_1( f4o16, FFT_15PONIT_WNK2 ), Mpy_32_16_1( f4o17, FFT_15PONIT_WNK3 ) ); - f4o15 = L_sub( Mpy_32_16_1( f4o17, FFT_15PONIT_WNK2 ), Mpy_32_16_1( f4o16, FFT_15PONIT_WNK3 ) ); + f4o14 = L_add( Mpy_32_16_1( f4o16, FFT_15PONIT_WNK2 ), Mpy_32_16_1( f4o17, FFT_15PONIT_WNK3 ) ); // Qx + f4o15 = L_sub( Mpy_32_16_1( f4o17, FFT_15PONIT_WNK2 ), Mpy_32_16_1( f4o16, FFT_15PONIT_WNK3 ) ); // Qx zRe[in1] = L_add( fi4, f4o12 ); move32(); f4o18 = L_sub( f4o13, f4o11 ); @@ -495,9 +495,9 @@ static void fft15_shift2( static void fft15_shift8( Word16 n1, /* i : length of data */ - Word32 *zRe, /* i/o: real part of input and output data */ - Word32 *zIm, /* i/o: imaginary part of input and output data */ - const Word16 *Idx /* i : pointer of the address table */ + Word32 *zRe, /* i/o: real part of input and output data Qx */ + Word32 *zIm, /* i/o: imaginary part of input and output data Qx */ + const Word16 *Idx /* i : pointer of the address table Q0 */ ) { Word16 in0, in8, in16, in24, in32, in1, in9, in17, in25, in33, in2, in10, in18, in26, in34; @@ -520,41 +520,41 @@ static void fft15_shift8( move16(); in16 = Idx[n1 * 2]; move16(); - in24 = Idx[i_mult( n1, 3 )]; + in24 = Idx[( n1 * 3 )]; move16(); in32 = Idx[n1 * 4]; move16(); - in1 = Idx[i_mult( n1, 5 )]; + in1 = Idx[( n1 * 5 )]; move16(); in9 = Idx[n1 * 6]; move16(); - in17 = Idx[i_mult( n1, 7 )]; + in17 = Idx[( n1 * 7 )]; move16(); in25 = Idx[n1 * 8]; move16(); - in33 = Idx[i_mult( n1, 9 )]; + in33 = Idx[( n1 * 9 )]; move16(); in2 = Idx[n1 * 10]; move16(); - in10 = Idx[i_mult( n1, 11 )]; + in10 = Idx[( n1 * 11 )]; move16(); in18 = Idx[n1 * 12]; move16(); - in26 = Idx[i_mult( n1, 13 )]; + in26 = Idx[( n1 * 13 )]; move16(); in34 = Idx[n1 * 14]; move16(); - f2i13 = zRe[in0]; - f2i14 = zIm[in0]; - f3i6 = zRe[in1]; - f3i7 = zRe[in2]; - f3i8 = zIm[in1]; - f3i9 = zIm[in2]; + f2i13 = zRe[in0]; // Qx + f2i14 = zIm[in0]; // Qx + f3i6 = zRe[in1]; // Qx + f3i7 = zRe[in2]; // Qx + f3i8 = zIm[in1]; // Qx + f3i9 = zIm[in2]; // Qx f2i15 = L_add( f3i6, f3i7 ); - f3i1 = Mpy_32_16_1( L_sub( f3i7, f3i6 ), FFT_15PONIT_WNK4 ); - f3i2 = Mpy_32_16_1( L_sub( f3i8, f3i9 ), FFT_15PONIT_WNK4 ); + f3i1 = Mpy_32_16_1( L_sub( f3i7, f3i6 ), FFT_15PONIT_WNK4 ); // Qx + f3i2 = Mpy_32_16_1( L_sub( f3i8, f3i9 ), FFT_15PONIT_WNK4 ); // Qx f3i3 = L_add( f3i8, f3i9 ); fi1 = L_add( f2i13, f2i15 ); @@ -594,15 +594,15 @@ static void fft15_shift8( f3i11 = L_add( f4i11, f4i12 ); f3i12 = L_sub( f3i10, L_shr( f3i11, 1 ) ); - f3i13 = Mpy_32_16_1( L_sub( f4i12, f4i11 ), FFT_15PONIT_WNK4 ); + f3i13 = Mpy_32_16_1( L_sub( f4i12, f4i11 ), FFT_15PONIT_WNK4 ); // Qx f3i15 = L_add( f4i13, f4i14 ); - f4i1 = Mpy_32_16_1( L_sub( f4i13, f4i14 ), FFT_15PONIT_WNK4 ); + f4i1 = Mpy_32_16_1( L_sub( f4i13, f4i14 ), FFT_15PONIT_WNK4 ); // Qx f4i2 = L_sub( f3i14, L_shr( f3i15, 1 ) ); f4i4 = L_add( f4i15, fo1 ); f4i5 = L_sub( f4i3, L_shr( f4i4, 1 ) ); - f4i6 = Mpy_32_16_1( L_sub( fo1, f4i15 ), FFT_15PONIT_WNK4 ); + f4i6 = Mpy_32_16_1( L_sub( fo1, f4i15 ), FFT_15PONIT_WNK4 ); // Qx f4i8 = L_add( fo2, fo3 ); - f4i9 = Mpy_32_16_1( L_sub( fo2, fo3 ), FFT_15PONIT_WNK4 ); + f4i9 = Mpy_32_16_1( L_sub( fo2, fo3 ), FFT_15PONIT_WNK4 ); // Qx f4i10 = L_sub( f4i7, L_shr( f4i8, 1 ) ); fi7 = L_add( f3i10, f3i11 ); @@ -652,15 +652,15 @@ static void fft15_shift8( fo5 = L_add( f2o5, f2o6 ); fo6 = L_sub( fo4, L_shr( fo5, 1 ) ); - fo7 = Mpy_32_16_1( L_sub( f2o6, f2o5 ), FFT_15PONIT_WNK4 ); + fo7 = Mpy_32_16_1( L_sub( f2o6, f2o5 ), FFT_15PONIT_WNK4 ); // Qx fo9 = L_add( f2o7, f2o8 ); - fo10 = Mpy_32_16_1( L_sub( f2o7, f2o8 ), FFT_15PONIT_WNK4 ); + fo10 = Mpy_32_16_1( L_sub( f2o7, f2o8 ), FFT_15PONIT_WNK4 ); // Qx fo11 = L_sub( fo8, L_shr( fo9, 1 ) ); fo13 = L_add( f2o9, f2o10 ); fo14 = L_sub( fo12, L_shr( fo13, 1 ) ); - fo15 = Mpy_32_16_1( L_sub( f2o10, f2o9 ), FFT_15PONIT_WNK4 ); + fo15 = Mpy_32_16_1( L_sub( f2o10, f2o9 ), FFT_15PONIT_WNK4 ); // Qx f2o2 = L_add( f2o11, f2o12 ); - f2o3 = Mpy_32_16_1( L_sub( f2o11, f2o12 ), FFT_15PONIT_WNK4 ); + f2o3 = Mpy_32_16_1( L_sub( f2o11, f2o12 ), FFT_15PONIT_WNK4 ); // Qx f2o4 = L_sub( f2o1, L_shr( f2o2, 1 ) ); fi25 = L_add( fo4, fo5 ); @@ -682,13 +682,13 @@ static void fft15_shift8( f2i11 = L_add( fo14, f2o3 ); f2i12 = L_add( f2i10, f2i11 ); - f2o13 = Mpy_32_16_1( L_sub( fi27, fi9 ), FFT_15PONIT_WNK1 ); + f2o13 = Mpy_32_16_1( L_sub( fi27, fi9 ), FFT_15PONIT_WNK1 ); // Qx f2o14 = L_add( fi27, fi9 ); - f2o15 = L_sub( fi1, Mpy_32_16_1( f2o14, FFT_15PONIT_WNK5 ) ); + f2o15 = L_sub( fi1, Mpy_32_16_1( f2o14, FFT_15PONIT_WNK5 ) ); // Qx f3o3 = L_sub( fi13, fi14 ); f3o4 = L_sub( f2i1, f2i2 ); - f3o1 = L_sub( Mpy_32_16_1( f3o3, FFT_15PONIT_WNK2 ), Mpy_32_16_1( f3o4, FFT_15PONIT_WNK3 ) ); - f3o2 = L_add( Mpy_32_16_1( f3o4, FFT_15PONIT_WNK2 ), Mpy_32_16_1( f3o3, FFT_15PONIT_WNK3 ) ); + f3o1 = L_sub( Mpy_32_16_1( f3o3, FFT_15PONIT_WNK2 ), Mpy_32_16_1( f3o4, FFT_15PONIT_WNK3 ) ); // Qx + f3o2 = L_add( Mpy_32_16_1( f3o4, FFT_15PONIT_WNK2 ), Mpy_32_16_1( f3o3, FFT_15PONIT_WNK3 ) ); // Qx zRe[in0] = L_add( fi1, f2o14 ); move32(); f3o5 = L_add( f2o13, f2o15 ); @@ -702,13 +702,13 @@ static void fft15_shift8( zRe[in9] = L_add( f3o6, f3o1 ); move32(); - f3o7 = Mpy_32_16_1( L_sub( f2i3, fi15 ), FFT_15PONIT_WNK1 ); + f3o7 = Mpy_32_16_1( L_sub( f2i3, fi15 ), FFT_15PONIT_WNK1 ); // Qx f3o8 = L_add( f2i3, fi15 ); - f3o9 = L_sub( fi2, Mpy_32_16_1( f3o8, FFT_15PONIT_WNK5 ) ); + f3o9 = L_sub( fi2, Mpy_32_16_1( f3o8, FFT_15PONIT_WNK5 ) ); // Qx f3o12 = L_sub( fi7, fi8 ); f3o13 = L_sub( fi25, fi26 ); - f3o10 = L_sub( Mpy_32_16_1( f3o12, FFT_15PONIT_WNK2 ), Mpy_32_16_1( f3o13, FFT_15PONIT_WNK3 ) ); - f3o11 = L_add( Mpy_32_16_1( f3o13, FFT_15PONIT_WNK2 ), Mpy_32_16_1( f3o12, FFT_15PONIT_WNK3 ) ); + f3o10 = L_sub( Mpy_32_16_1( f3o12, FFT_15PONIT_WNK2 ), Mpy_32_16_1( f3o13, FFT_15PONIT_WNK3 ) ); // Qx + f3o11 = L_add( Mpy_32_16_1( f3o13, FFT_15PONIT_WNK2 ), Mpy_32_16_1( f3o12, FFT_15PONIT_WNK3 ) ); // Qx zIm[in0] = L_add( fi2, f3o8 ); move32(); f3o14 = L_add( f3o7, f3o9 ); @@ -722,13 +722,13 @@ static void fft15_shift8( zIm[in33] = L_add( f3o10, f3o15 ); move32(); - f4o1 = Mpy_32_16_1( L_sub( fi30, fi12 ), FFT_15PONIT_WNK1 ); + f4o1 = Mpy_32_16_1( L_sub( fi30, fi12 ), FFT_15PONIT_WNK1 ); // Qx f4o2 = L_add( fi30, fi12 ); - f4o3 = L_sub( fi3, Mpy_32_16_1( f4o2, FFT_15PONIT_WNK5 ) ); + f4o3 = L_sub( fi3, Mpy_32_16_1( f4o2, FFT_15PONIT_WNK5 ) ); // Qx f4o6 = L_sub( fi16, fi17 ); f4o7 = L_sub( f2i4, f2i5 ); - f4o4 = L_sub( Mpy_32_16_1( f4o6, FFT_15PONIT_WNK2 ), Mpy_32_16_1( f4o7, FFT_15PONIT_WNK3 ) ); - f4o5 = L_add( Mpy_32_16_1( f4o7, FFT_15PONIT_WNK2 ), Mpy_32_16_1( f4o6, FFT_15PONIT_WNK3 ) ); + f4o4 = L_sub( Mpy_32_16_1( f4o6, FFT_15PONIT_WNK2 ), Mpy_32_16_1( f4o7, FFT_15PONIT_WNK3 ) ); // Qx + f4o5 = L_add( Mpy_32_16_1( f4o7, FFT_15PONIT_WNK2 ), Mpy_32_16_1( f4o6, FFT_15PONIT_WNK3 ) ); // Qx zRe[in2] = L_add( fi3, f4o2 ); move32(); f4o8 = L_add( f4o1, f4o3 ); @@ -742,13 +742,13 @@ static void fft15_shift8( zRe[in8] = L_add( f4o9, f4o4 ); move32(); - f4o10 = Mpy_32_16_1( L_sub( f2i6, fi18 ), FFT_15PONIT_WNK1 ); + f4o10 = Mpy_32_16_1( L_sub( f2i6, fi18 ), FFT_15PONIT_WNK1 ); // Qx f4o11 = L_add( f2i6, fi18 ); - f4o12 = L_sub( fi6, Mpy_32_16_1( f4o11, FFT_15PONIT_WNK5 ) ); + f4o12 = L_sub( fi6, Mpy_32_16_1( f4o11, FFT_15PONIT_WNK5 ) ); // Qx f4o15 = L_sub( fi10, fi11 ); f5o1 = L_sub( fi28, fi29 ); - f4o13 = L_sub( Mpy_32_16_1( f4o15, FFT_15PONIT_WNK2 ), Mpy_32_16_1( f5o1, FFT_15PONIT_WNK3 ) ); - f4o14 = L_add( Mpy_32_16_1( f5o1, FFT_15PONIT_WNK2 ), Mpy_32_16_1( f4o15, FFT_15PONIT_WNK3 ) ); + f4o13 = L_sub( Mpy_32_16_1( f4o15, FFT_15PONIT_WNK2 ), Mpy_32_16_1( f5o1, FFT_15PONIT_WNK3 ) ); // Qx + f4o14 = L_add( Mpy_32_16_1( f5o1, FFT_15PONIT_WNK2 ), Mpy_32_16_1( f4o15, FFT_15PONIT_WNK3 ) ); // Qx zIm[in2] = L_add( fi6, f4o11 ); move32(); f5o2 = L_add( f4o10, f4o12 ); @@ -762,13 +762,13 @@ static void fft15_shift8( zIm[in8] = L_sub( f5o3, f4o13 ); move32(); - f5o4 = Mpy_32_16_1( L_sub( f2i9, fi21 ), FFT_15PONIT_WNK1 ); + f5o4 = Mpy_32_16_1( L_sub( f2i9, fi21 ), FFT_15PONIT_WNK1 ); // Qx f5o5 = L_add( f2i9, fi21 ); - f5o6 = L_sub( fi5, Mpy_32_16_1( f5o5, FFT_15PONIT_WNK5 ) ); + f5o6 = L_sub( fi5, Mpy_32_16_1( f5o5, FFT_15PONIT_WNK5 ) ); // Qx f5o9 = L_sub( f2i10, f2i11 ); f5o10 = L_sub( fi22, fi23 ); - f5o7 = L_add( Mpy_32_16_1( f5o9, FFT_15PONIT_WNK2 ), Mpy_32_16_1( f5o10, FFT_15PONIT_WNK3 ) ); - f5o8 = L_sub( Mpy_32_16_1( f5o10, FFT_15PONIT_WNK2 ), Mpy_32_16_1( f5o9, FFT_15PONIT_WNK3 ) ); + f5o7 = L_add( Mpy_32_16_1( f5o9, FFT_15PONIT_WNK2 ), Mpy_32_16_1( f5o10, FFT_15PONIT_WNK3 ) ); // Qx + f5o8 = L_sub( Mpy_32_16_1( f5o10, FFT_15PONIT_WNK2 ), Mpy_32_16_1( f5o9, FFT_15PONIT_WNK3 ) ); // Qx zIm[in1] = L_add( fi5, f5o5 ); move32(); f5o11 = L_sub( f5o6, f5o4 ); @@ -783,13 +783,13 @@ static void fft15_shift8( zIm[in25] = L_add( f5o7, f5o12 ); move32(); - f5o13 = Mpy_32_16_1( L_sub( f2i12, fi24 ), FFT_15PONIT_WNK1 ); + f5o13 = Mpy_32_16_1( L_sub( f2i12, fi24 ), FFT_15PONIT_WNK1 ); // Qx f5o14 = L_add( f2i12, fi24 ); - f5o15 = L_sub( fi4, Mpy_32_16_1( f5o14, FFT_15PONIT_WNK5 ) ); + f5o15 = L_sub( fi4, Mpy_32_16_1( f5o14, FFT_15PONIT_WNK5 ) ); // Qx f5o18 = L_sub( f2i7, f2i8 ); f5o19 = L_sub( fi19, fi20 ); - f5o16 = L_add( Mpy_32_16_1( f5o18, FFT_15PONIT_WNK2 ), Mpy_32_16_1( f5o19, FFT_15PONIT_WNK3 ) ); - f5o17 = L_sub( Mpy_32_16_1( f5o19, FFT_15PONIT_WNK2 ), Mpy_32_16_1( f5o18, FFT_15PONIT_WNK3 ) ); + f5o16 = L_add( Mpy_32_16_1( f5o18, FFT_15PONIT_WNK2 ), Mpy_32_16_1( f5o19, FFT_15PONIT_WNK3 ) ); // Qx + f5o17 = L_sub( Mpy_32_16_1( f5o19, FFT_15PONIT_WNK2 ), Mpy_32_16_1( f5o18, FFT_15PONIT_WNK3 ) ); // Qx zRe[in1] = L_add( fi4, f5o14 ); move32(); f5o21 = L_sub( f5o15, f5o13 ); @@ -813,10 +813,10 @@ static void fft15_shift8( *-----------------------------------------------------------------*/ static void fft5_shift1( - Word16 n1, /* i : length of data */ - Word32 *zRe, /* i/o: real part of input and output data */ - Word32 *zIm, /* i/o: imaginary part of input and output data */ - const Word16 *Idx /* i : pointer of the address table */ + Word16 n1, /* i : length of data Q0 */ + Word32 *zRe, /* i/o: real part of input and output data Qx */ + Word32 *zIm, /* i/o: imaginary part of input and output data Qx */ + const Word16 *Idx /* i : pointer of the address table Q0 */ ) { Word32 fi1, fi2, fi3, fi4, fi5, fi6, fi7, fi8; @@ -829,29 +829,29 @@ static void fft5_shift1( move16(); in3 = Idx[n1 * 2]; move16(); - in4 = Idx[i_mult( n1, 3 )]; + in4 = Idx[( n1 * 3 )]; move16(); in5 = Idx[n1 * 4]; move16(); - fi1 = zRe[in1]; + fi1 = zRe[in1]; // Qx move32(); - fi2 = zIm[in1]; + fi2 = zIm[in1]; // Qx move32(); - fo3 = zRe[in2]; + fo3 = zRe[in2]; // Qx move32(); - fo4 = zRe[in5]; + fo4 = zRe[in5]; // Qx move32(); - fo6 = zRe[in3]; + fo6 = zRe[in3]; // Qx move32(); - fo7 = zRe[in4]; + fo7 = zRe[in4]; // Qx move32(); fo5 = L_add( fo3, fo4 ); fo8 = L_add( fo6, fo7 ); fi3 = L_add( fo5, fo8 ); fi4 = L_sub( fo6, fo7 ); - fi5 = Mpy_32_16_1( L_sub( fo5, fo8 ), FFT_15PONIT_WNK1 ); + fi5 = Mpy_32_16_1( L_sub( fo5, fo8 ), FFT_15PONIT_WNK1 ); // Qx fi6 = L_sub( fo3, fo4 ); fo3 = zIm[in2]; @@ -868,15 +868,15 @@ static void fft5_shift1( fi7 = L_sub( fo3, fo4 ); fi8 = L_add( fo5, fo8 ); fo1 = L_sub( fo6, fo7 ); - fo2 = Mpy_32_16_1( L_sub( fo5, fo8 ), FFT_15PONIT_WNK1 ); + fo2 = Mpy_32_16_1( L_sub( fo5, fo8 ), FFT_15PONIT_WNK1 ); // Qx zRe[in1] = L_add( fi1, fi3 ); move32(); zIm[in1] = L_add( fi2, fi8 ); move32(); - fo3 = L_add( Mpy_32_16_1( fi7, FFT_15PONIT_WNK2 ), Mpy_32_16_1( fo1, FFT_15PONIT_WNK3 ) ); - fo4 = L_sub( Mpy_32_16_1( fo1, FFT_15PONIT_WNK2 ), Mpy_32_16_1( fi7, FFT_15PONIT_WNK3 ) ); + fo3 = L_add( Mpy_32_16_1( fi7, FFT_15PONIT_WNK2 ), Mpy_32_16_1( fo1, FFT_15PONIT_WNK3 ) ); // Qx + fo4 = L_sub( Mpy_32_16_1( fo1, FFT_15PONIT_WNK2 ), Mpy_32_16_1( fi7, FFT_15PONIT_WNK3 ) ); // Qx fo7 = L_sub( fi1, L_shr( fi3, 2 ) ); fo5 = L_add( fi5, fo7 ); fo6 = L_sub( fo7, fi5 ); @@ -890,8 +890,8 @@ static void fft5_shift1( zRe[in5] = L_sub( fo5, fo3 ); move32(); - fo3 = L_add( Mpy_32_16_1( fi6, FFT_15PONIT_WNK2 ), Mpy_32_16_1( fi4, FFT_15PONIT_WNK3 ) ); - fo4 = L_sub( Mpy_32_16_1( fi4, FFT_15PONIT_WNK2 ), Mpy_32_16_1( fi6, FFT_15PONIT_WNK3 ) ); + fo3 = L_add( Mpy_32_16_1( fi6, FFT_15PONIT_WNK2 ), Mpy_32_16_1( fi4, FFT_15PONIT_WNK3 ) ); // Qx + fo4 = L_sub( Mpy_32_16_1( fi4, FFT_15PONIT_WNK2 ), Mpy_32_16_1( fi6, FFT_15PONIT_WNK3 ) ); // Qx fo7 = L_sub( fi2, L_shr( fi8, 2 ) ); fo5 = L_add( fo2, fo7 ); fo6 = L_sub( fo7, fo2 ); @@ -914,10 +914,10 @@ static void fft5_shift1( *-----------------------------------------------------------------*/ static void fft5_shift4( - Word16 n1, /* i : length of data */ - Word32 *zRe, /* i/o: real part of input and output data */ - Word32 *zIm, /* i/o: imaginary part of input and output data */ - const Word16 *Idx /* i : pointer of the address table */ + Word16 n1, /* i : length of data Q0 */ + Word32 *zRe, /* i/o: real part of input and output data Qx */ + Word32 *zIm, /* i/o: imaginary part of input and output data Qx */ + const Word16 *Idx /* i : pointer of the address table Q0 */ ) { Word32 fi1, fi2, fi3, fi4, fi5, fi6, fi7, fi8; @@ -930,29 +930,29 @@ static void fft5_shift4( move16(); in3 = Idx[n1 * 2]; move16(); - in4 = Idx[i_mult( n1, 3 )]; + in4 = Idx[( n1 * 3 )]; move16(); in5 = Idx[n1 * 4]; move16(); - fi1 = zRe[in1]; + fi1 = zRe[in1]; // Qx move32(); - fi2 = zIm[in1]; + fi2 = zIm[in1]; // Qx move32(); - fo3 = zRe[in2]; + fo3 = zRe[in2]; // Qx move32(); - fo4 = zRe[in5]; + fo4 = zRe[in5]; // Qx move32(); - fo6 = zRe[in3]; + fo6 = zRe[in3]; // Qx move32(); - fo7 = zRe[in4]; + fo7 = zRe[in4]; // Qx move32(); fo5 = L_add( fo3, fo4 ); fo8 = L_add( fo6, fo7 ); fi3 = L_add( fo5, fo8 ); fi4 = L_sub( fo6, fo7 ); - fi5 = Mpy_32_16_1( L_sub( fo5, fo8 ), FFT_15PONIT_WNK1 ); + fi5 = Mpy_32_16_1( L_sub( fo5, fo8 ), FFT_15PONIT_WNK1 ); // Qx fi6 = L_sub( fo3, fo4 ); fo3 = zIm[in2]; @@ -969,15 +969,15 @@ static void fft5_shift4( fi7 = L_sub( fo3, fo4 ); fi8 = L_add( fo5, fo8 ); fo1 = L_sub( fo6, fo7 ); - fo2 = Mpy_32_16_1( L_sub( fo5, fo8 ), FFT_15PONIT_WNK1 ); + fo2 = Mpy_32_16_1( L_sub( fo5, fo8 ), FFT_15PONIT_WNK1 ); // Qx zRe[in1] = L_add( fi1, fi3 ); move32(); zIm[in1] = L_add( fi2, fi8 ); move32(); - fo3 = L_add( Mpy_32_16_1( fi7, FFT_15PONIT_WNK2 ), Mpy_32_16_1( fo1, FFT_15PONIT_WNK3 ) ); - fo4 = L_sub( Mpy_32_16_1( fo1, FFT_15PONIT_WNK2 ), Mpy_32_16_1( fi7, FFT_15PONIT_WNK3 ) ); + fo3 = L_add( Mpy_32_16_1( fi7, FFT_15PONIT_WNK2 ), Mpy_32_16_1( fo1, FFT_15PONIT_WNK3 ) ); // Qx + fo4 = L_sub( Mpy_32_16_1( fo1, FFT_15PONIT_WNK2 ), Mpy_32_16_1( fi7, FFT_15PONIT_WNK3 ) ); // Qx fo7 = L_sub( fi1, L_shr( fi3, 2 ) ); fo5 = L_add( fi5, fo7 ); fo6 = L_sub( fo7, fi5 ); @@ -991,8 +991,8 @@ static void fft5_shift4( zRe[in5] = L_add( fo5, fo3 ); move32(); - fo3 = L_add( Mpy_32_16_1( fi6, FFT_15PONIT_WNK2 ), Mpy_32_16_1( fi4, FFT_15PONIT_WNK3 ) ); - fo4 = L_sub( Mpy_32_16_1( fi4, FFT_15PONIT_WNK2 ), Mpy_32_16_1( fi6, FFT_15PONIT_WNK3 ) ); + fo3 = L_add( Mpy_32_16_1( fi6, FFT_15PONIT_WNK2 ), Mpy_32_16_1( fi4, FFT_15PONIT_WNK3 ) ); // Qx + fo4 = L_sub( Mpy_32_16_1( fi4, FFT_15PONIT_WNK2 ), Mpy_32_16_1( fi6, FFT_15PONIT_WNK3 ) ); // Qx fo7 = L_sub( fi2, L_shr( fi8, 2 ) ); fo5 = L_add( fo2, fo7 ); fo6 = L_sub( fo7, fo2 ); @@ -1015,9 +1015,9 @@ static void fft5_shift4( *-----------------------------------------------------------------*/ static void fft5_32( - Word32 *zRe, /* i/o: real part of input and output data */ - Word32 *zIm, /* i/o: imaginary part of input and output data */ - const Word16 *Idx /* i : pointer of the address table */ + Word32 *zRe, /* i/o: real part of input and output data Qx */ + Word32 *zIm, /* i/o: imaginary part of input and output data Qx */ + const Word16 *Idx /* i : pointer of the address table Q0 */ ) { Word32 fi1, fi2, fi3, fi4, fi5, fi6, fi7, fi8; @@ -1035,24 +1035,24 @@ static void fft5_32( in5 = Idx[128]; move16(); - fi1 = zRe[in1]; + fi1 = zRe[in1]; // Qx move32(); - fi2 = zIm[in1]; + fi2 = zIm[in1]; // Qx move32(); - fo3 = zRe[in2]; + fo3 = zRe[in2]; // Qx move32(); - fo4 = zRe[in5]; + fo4 = zRe[in5]; // Qx move32(); - fo6 = zRe[in3]; + fo6 = zRe[in3]; // Qx move32(); - fo7 = zRe[in4]; + fo7 = zRe[in4]; // Qx move32(); fo5 = L_add( fo3, fo4 ); fo8 = L_add( fo6, fo7 ); fi3 = L_add( fo5, fo8 ); fi4 = L_sub( fo6, fo7 ); - fi5 = Mpy_32_16_1( L_sub( fo5, fo8 ), FFT_15PONIT_WNK1 ); + fi5 = Mpy_32_16_1( L_sub( fo5, fo8 ), FFT_15PONIT_WNK1 ); // Qx fi6 = L_sub( fo3, fo4 ); fo3 = zIm[in2]; @@ -1069,15 +1069,15 @@ static void fft5_32( fi7 = L_sub( fo3, fo4 ); fi8 = L_add( fo5, fo8 ); fo1 = L_sub( fo6, fo7 ); - fo2 = Mpy_32_16_1( L_sub( fo5, fo8 ), FFT_15PONIT_WNK1 ); + fo2 = Mpy_32_16_1( L_sub( fo5, fo8 ), FFT_15PONIT_WNK1 ); // Qx zRe[in1] = L_add( fi1, fi3 ); move32(); zIm[in1] = L_add( fi2, fi8 ); move32(); - fo3 = L_add( Mpy_32_16_1( fi7, FFT_15PONIT_WNK2 ), Mpy_32_16_1( fo1, FFT_15PONIT_WNK3 ) ); - fo4 = L_sub( Mpy_32_16_1( fo1, FFT_15PONIT_WNK2 ), Mpy_32_16_1( fi7, FFT_15PONIT_WNK3 ) ); + fo3 = L_add( Mpy_32_16_1( fi7, FFT_15PONIT_WNK2 ), Mpy_32_16_1( fo1, FFT_15PONIT_WNK3 ) ); // Qx + fo4 = L_sub( Mpy_32_16_1( fo1, FFT_15PONIT_WNK2 ), Mpy_32_16_1( fi7, FFT_15PONIT_WNK3 ) ); // Qx fo7 = L_sub( fi1, L_shr( fi3, 2 ) ); fo5 = L_add( fi5, fo7 ); fo6 = L_sub( fo7, fi5 ); @@ -1091,8 +1091,8 @@ static void fft5_32( zRe[in5] = L_sub( fo6, fo4 ); move32(); - fo3 = L_add( Mpy_32_16_1( fi6, FFT_15PONIT_WNK2 ), Mpy_32_16_1( fi4, FFT_15PONIT_WNK3 ) ); - fo4 = L_sub( Mpy_32_16_1( fi4, FFT_15PONIT_WNK2 ), Mpy_32_16_1( fi6, FFT_15PONIT_WNK3 ) ); + fo3 = L_add( Mpy_32_16_1( fi6, FFT_15PONIT_WNK2 ), Mpy_32_16_1( fi4, FFT_15PONIT_WNK3 ) ); // Qx + fo4 = L_sub( Mpy_32_16_1( fi4, FFT_15PONIT_WNK2 ), Mpy_32_16_1( fi6, FFT_15PONIT_WNK3 ) ); // Qx fo7 = L_sub( fi2, L_shr( fi8, 2 ) ); fo5 = L_add( fo2, fo7 ); fo6 = L_sub( fo7, fo2 ); @@ -1115,9 +1115,9 @@ static void fft5_32( *-----------------------------------------------------------------*/ static void fft64( - Word32 *x, /* i/o: real part of input and output data */ - Word32 *y, /* i/o: imaginary part of input and output data */ - const Word16 *Idx /* i : pointer of the address table */ + Word32 *x, /* i/o: real part of input and output data Qx */ + Word32 *y, /* i/o: imaginary part of input and output data Qx */ + const Word16 *Idx /* i : pointer of the address table Q0 */ ) { Word16 i, id, jd; @@ -1126,9 +1126,9 @@ static void fft64( { id = Idx[i]; move16(); - z[2 * i] = x[id]; + z[2 * i] = x[id]; // Qx move32(); - z[add( shl( i, 1 ), 1 )] = y[id]; + z[( ( i << 1 ) + 1 )] = y[id]; // Qx move32(); } @@ -1140,9 +1140,9 @@ static void fft64( move16(); id = Idx[jd]; move16(); - x[id] = z[2 * i]; + x[id] = z[2 * i]; // Qx move32(); - y[id] = z[add( shl( i, 1 ), 1 )]; + y[id] = z[( ( i << 1 ) + 1 )]; // Qx move32(); } @@ -1156,9 +1156,9 @@ static void fft64( *-----------------------------------------------------------------*/ static void fft32_15( - Word32 *x, /* i/o: real part of input and output data */ - Word32 *y, /* i/o: imaginary part of input and output data */ - const Word16 *Idx /* i : pointer of the address table */ + Word32 *x, /* i/o: real part of input and output data Qx */ + Word32 *y, /* i/o: imaginary part of input and output data Qx */ + const Word16 *Idx /* i : pointer of the address table Q0 */ ) { Word16 i, id, jd; @@ -1168,9 +1168,9 @@ static void fft32_15( { id = Idx[i]; move16(); - z[2 * i] = x[id]; + z[2 * i] = x[id]; // Qx move32(); - z[add( shl( i, 1 ), 1 )] = y[id]; + z[( ( i << 1 ) + 1 )] = y[id]; // Qx move32(); } @@ -1182,9 +1182,9 @@ static void fft32_15( move16(); id = Idx[jd]; move16(); - x[id] = z[2 * i]; + x[id] = z[2 * i]; // Qx move32(); - y[id] = z[add( shl( i, 1 ), 1 )]; + y[id] = z[( ( i << 1 ) + 1 )]; // Qx move32(); } @@ -1197,9 +1197,9 @@ static void fft32_15( *-----------------------------------------------------------------*/ static void fft32_5( - Word32 *x, /* i/o: real part of input and output data */ - Word32 *y, /* i/o: imaginary part of input and output data */ - const Word16 *Idx /* i : pointer of the address table */ + Word32 *x, /* i/o: real part of input and output data Qx */ + Word32 *y, /* i/o: imaginary part of input and output data Qx */ + const Word16 *Idx /* i : pointer of the address table Q0 */ ) { Word16 i, id, jd; @@ -1209,9 +1209,9 @@ static void fft32_5( { id = Idx[i]; move16(); - z[2 * i] = x[id]; + z[2 * i] = x[id]; // Qx move32(); - z[add( shl( i, 1 ), 1 )] = y[id]; + z[( ( i << 1 ) + 1 )] = y[id]; // Qx move32(); } @@ -1223,9 +1223,9 @@ static void fft32_5( move16(); id = Idx[jd]; move16(); - x[id] = z[2 * i]; + x[id] = z[2 * i]; // Qx move32(); - y[id] = z[add( shl( i, 1 ), 1 )]; + y[id] = z[( ( i << 1 ) + 1 )]; // Qx move32(); } @@ -1238,9 +1238,9 @@ static void fft32_5( *-----------------------------------------------------------------*/ static void fft16_ivas( - Word32 *x, /* i/o: real part of input and output data */ - Word32 *y, /* i/o: imaginary part of input and output data */ - const Word16 *Idx /* i : pointer of the address table */ + Word32 *x, /* i/o: real part of input and output data Qx */ + Word32 *y, /* i/o: imaginary part of input and output data Qx */ + const Word16 *Idx /* i : pointer of the address table Q0 */ ) { Word16 i, id, jd; @@ -1250,9 +1250,9 @@ static void fft16_ivas( { id = Idx[i]; move16(); - z[2 * i] = x[id]; + z[2 * i] = x[id]; // Qx move32(); - z[add( shl( i, 1 ), 1 )] = y[id]; + z[( ( i << 1 ) + 1 )] = y[id]; // Qx move32(); } @@ -1264,9 +1264,9 @@ static void fft16_ivas( move16(); id = Idx[jd]; move16(); - x[id] = z[2 * i]; + x[id] = z[2 * i]; // Qx move32(); - y[id] = z[add( shl( i, 1 ), 1 )]; + y[id] = z[( ( i << 1 ) + 1 )]; // Qx move32(); } @@ -1279,9 +1279,9 @@ static void fft16_ivas( *-----------------------------------------------------------------*/ static void fft8( - Word32 *x, /* i/o: real part of input and output data */ - Word32 *y, /* i/o: imaginary part of input and output data */ - const Word16 *Idx /* i : pointer of the address table */ + Word32 *x, /* i/o: real part of input and output data Qx */ + Word32 *y, /* i/o: imaginary part of input and output data Qx */ + const Word16 *Idx /* i : pointer of the address table Q0 */ ) { Word16 i, id; @@ -1291,9 +1291,9 @@ static void fft8( { id = Idx[i]; move16(); - z[2 * i] = x[id]; + z[2 * i] = x[id]; // Qx move32(); - z[add( shl( i, 1 ), 1 )] = y[id]; + z[( ( i << 1 ) + 1 )] = y[id]; // Qx move32(); } @@ -1303,9 +1303,9 @@ static void fft8( { id = Idx[i]; move16(); - x[id] = z[2 * i]; + x[id] = z[2 * i]; // Qx move32(); - y[id] = z[add( shl( i, 1 ), 1 )]; + y[id] = z[( ( i << 1 ) + 1 )]; // Qx move32(); } @@ -1318,9 +1318,9 @@ static void fft8( *-----------------------------------------------------------------*/ static void fft8_5( - Word32 *x, /* i/o: real part of input and output data */ - Word32 *y, /* i/o: imaginary part of input and output data */ - const Word16 *Idx /* i : pointer of the address table */ + Word32 *x, /* i/o: real part of input and output data Qx */ + Word32 *y, /* i/o: imaginary part of input and output data Qx */ + const Word16 *Idx /* i : pointer of the address table Q0 */ ) { Word16 i, id, jd; @@ -1332,7 +1332,7 @@ static void fft8_5( move16(); z[2 * i] = x[id]; move32(); - z[add( shl( i, 1 ), 1 )] = y[id]; + z[( ( i << 1 ) + 1 )] = y[id]; // Qx move32(); } @@ -1344,9 +1344,9 @@ static void fft8_5( move16(); id = Idx[jd]; move16(); - x[id] = z[2 * i]; + x[id] = z[2 * i]; // Qx move32(); - y[id] = z[add( shl( i, 1 ), 1 )]; + y[id] = z[( ( i << 1 ) + 1 )]; // Qx move32(); } return; @@ -1358,10 +1358,10 @@ static void fft8_5( *-----------------------------------------------------------------*/ static void fft5_8( - Word16 n1, /* i : length of data */ - Word32 *zRe, /* i/o: real part of input and output data */ - Word32 *zIm, /* i/o: imaginary part of input and output data */ - const Word16 *Idx /* i : pointer of the address table */ + Word16 n1, /* i : length of data Q0 */ + Word32 *zRe, /* i/o: real part of input and output data Qx */ + Word32 *zIm, /* i/o: imaginary part of input and output data Qx */ + const Word16 *Idx /* i : pointer of the address table Q0 */ ) { Word32 fi1, fi2, fi3, fi4, fi5, fi6, fi7, fi8; @@ -1374,29 +1374,29 @@ static void fft5_8( move16(); in3 = Idx[n1 * 2]; move16(); - in4 = Idx[i_mult( n1, 3 )]; + in4 = Idx[( n1 * 3 )]; move16(); in5 = Idx[n1 * 4]; move16(); - fi1 = zRe[in1]; + fi1 = zRe[in1]; // Qx move32(); - fi2 = zIm[in1]; + fi2 = zIm[in1]; // Qx move32(); - fo3 = zRe[in2]; + fo3 = zRe[in2]; // Qx move32(); - fo4 = zRe[in5]; + fo4 = zRe[in5]; // Qx move32(); - fo6 = zRe[in3]; + fo6 = zRe[in3]; // Qx move32(); - fo7 = zRe[in4]; + fo7 = zRe[in4]; // Qx move32(); fo5 = L_add( fo3, fo4 ); fo8 = L_add( fo6, fo7 ); fi3 = L_add( fo5, fo8 ); fi4 = L_sub( fo6, fo7 ); - fi5 = Mpy_32_16_1( L_sub( fo5, fo8 ), FFT_15PONIT_WNK1 ); + fi5 = Mpy_32_16_1( L_sub( fo5, fo8 ), FFT_15PONIT_WNK1 ); // Qx fi6 = L_sub( fo3, fo4 ); fo3 = zIm[in2]; @@ -1413,15 +1413,15 @@ static void fft5_8( fi7 = L_sub( fo3, fo4 ); fi8 = L_add( fo5, fo8 ); fo1 = L_sub( fo6, fo7 ); - fo2 = Mpy_32_16_1( L_sub( fo5, fo8 ), FFT_15PONIT_WNK1 ); + fo2 = Mpy_32_16_1( L_sub( fo5, fo8 ), FFT_15PONIT_WNK1 ); // Qx zRe[in1] = L_add( fi1, fi3 ); move32(); zIm[in1] = L_add( fi2, fi8 ); move32(); - fo3 = L_add( Mpy_32_16_1( fi7, FFT_15PONIT_WNK2 ), Mpy_32_16_1( fo1, FFT_15PONIT_WNK3 ) ); - fo4 = L_sub( Mpy_32_16_1( fo1, FFT_15PONIT_WNK2 ), Mpy_32_16_1( fi7, FFT_15PONIT_WNK3 ) ); + fo3 = L_add( Mpy_32_16_1( fi7, FFT_15PONIT_WNK2 ), Mpy_32_16_1( fo1, FFT_15PONIT_WNK3 ) ); // Qx + fo4 = L_sub( Mpy_32_16_1( fo1, FFT_15PONIT_WNK2 ), Mpy_32_16_1( fi7, FFT_15PONIT_WNK3 ) ); // Qx fo7 = L_sub( fi1, L_shr( fi3, 2 ) ); fo5 = L_add( fi5, fo7 ); fo6 = L_sub( fo7, fi5 ); @@ -1435,8 +1435,8 @@ static void fft5_8( zRe[in4] = L_add( fo5, fo3 ); move32(); - fo3 = L_add( Mpy_32_16_1( fi6, FFT_15PONIT_WNK2 ), Mpy_32_16_1( fi4, FFT_15PONIT_WNK3 ) ); - fo4 = L_sub( Mpy_32_16_1( fi4, FFT_15PONIT_WNK2 ), Mpy_32_16_1( fi6, FFT_15PONIT_WNK3 ) ); + fo3 = L_add( Mpy_32_16_1( fi6, FFT_15PONIT_WNK2 ), Mpy_32_16_1( fi4, FFT_15PONIT_WNK3 ) ); // Qx + fo4 = L_sub( Mpy_32_16_1( fi4, FFT_15PONIT_WNK2 ), Mpy_32_16_1( fi6, FFT_15PONIT_WNK3 ) ); // Qx fo7 = L_sub( fi2, L_shr( fi8, 2 ) ); fo5 = L_add( fo2, fo7 ); fo6 = L_sub( fo7, fo2 ); @@ -1459,9 +1459,9 @@ static void fft5_8( *-----------------------------------------------------------------*/ static void fft4_5( - Word32 *x, /* i/o: real part of input and output data */ - Word32 *y, /* i/o: imaginary part of input and output data */ - const Word16 *Idx /* i : pointer of the address table */ + Word32 *x, /* i/o: real part of input and output data Qx */ + Word32 *y, /* i/o: imaginary part of input and output data Qx */ + const Word16 *Idx /* i : pointer of the address table Q0 */ ) { Word16 i, id, jd; @@ -1471,9 +1471,9 @@ static void fft4_5( { id = Idx[i]; move16(); - z[2 * i] = x[id]; + z[2 * i] = x[id]; // Qx move32(); - z[add( shl( i, 1 ), 1 )] = y[id]; + z[( ( i << 1 ) + 1 )] = y[id]; // Qx move32(); } @@ -1485,9 +1485,9 @@ static void fft4_5( move16(); id = Idx[jd]; move16(); - x[id] = z[2 * i]; + x[id] = z[2 * i]; // Qx move32(); - y[id] = z[add( shl( i, 1 ), 1 )]; + y[id] = z[( ( i << 1 ) + 1 )]; // Qx move32(); } return; @@ -1499,10 +1499,11 @@ static void fft4_5( *-----------------------------------------------------------------*/ static void fft5_4( - Word16 n1, - Word32 *zRe, - Word32 *zIm, - const Word16 *Idx ) + Word16 n1, // Q0 + Word32 *zRe, // Qx + Word32 *zIm, // Qx + const Word16 *Idx // Q0 +) { Word32 fi1, fi2, fi3, fi4, fi5, fi6, fi7, fi8; Word32 fo1, fo2, fo3, fo4, fo5, fo6, fo7, fo8; @@ -1514,29 +1515,29 @@ static void fft5_4( move16(); in3 = Idx[n1 * 2]; move16(); - in4 = Idx[i_mult( n1, 3 )]; + in4 = Idx[( n1 * 3 )]; move16(); in5 = Idx[n1 * 4]; move16(); - fi1 = zRe[in1]; + fi1 = zRe[in1]; // Qx move32(); - fi2 = zIm[in1]; + fi2 = zIm[in1]; // Qx move32(); - fo3 = zRe[in2]; + fo3 = zRe[in2]; // Qx move32(); - fo4 = zRe[in5]; + fo4 = zRe[in5]; // Qx move32(); - fo6 = zRe[in3]; + fo6 = zRe[in3]; // Qx move32(); - fo7 = zRe[in4]; + fo7 = zRe[in4]; // Qx move32(); fo5 = L_add( fo3, fo4 ); fo8 = L_add( fo6, fo7 ); fi3 = L_add( fo5, fo8 ); fi4 = L_sub( fo6, fo7 ); - fi5 = Mpy_32_16_1( L_sub( fo5, fo8 ), FFT_15PONIT_WNK1 ); + fi5 = Mpy_32_16_1( L_sub( fo5, fo8 ), FFT_15PONIT_WNK1 ); // Qx fi6 = L_sub( fo3, fo4 ); fo3 = zIm[in2]; @@ -1553,15 +1554,15 @@ static void fft5_4( fi7 = L_sub( fo3, fo4 ); fi8 = L_add( fo5, fo8 ); fo1 = L_sub( fo6, fo7 ); - fo2 = Mpy_32_16_1( L_sub( fo5, fo8 ), FFT_15PONIT_WNK1 ); + fo2 = Mpy_32_16_1( L_sub( fo5, fo8 ), FFT_15PONIT_WNK1 ); // Qx zRe[in1] = L_add( fi1, fi3 ); move32(); zIm[in1] = L_add( fi2, fi8 ); move32(); - fo3 = L_add( Mpy_32_16_1( fi7, FFT_15PONIT_WNK2 ), Mpy_32_16_1( fo1, FFT_15PONIT_WNK3 ) ); - fo4 = L_sub( Mpy_32_16_1( fo1, FFT_15PONIT_WNK2 ), Mpy_32_16_1( fi7, FFT_15PONIT_WNK3 ) ); + fo3 = L_add( Mpy_32_16_1( fi7, FFT_15PONIT_WNK2 ), Mpy_32_16_1( fo1, FFT_15PONIT_WNK3 ) ); // Qx + fo4 = L_sub( Mpy_32_16_1( fo1, FFT_15PONIT_WNK2 ), Mpy_32_16_1( fi7, FFT_15PONIT_WNK3 ) ); // Qx fo7 = L_sub( fi1, L_shr( fi3, 2 ) ); fo5 = L_add( fi5, fo7 ); fo6 = L_sub( fo7, fi5 ); @@ -1575,8 +1576,8 @@ static void fft5_4( zRe[in5] = L_add( fo5, fo3 ); move32(); - fo3 = L_add( Mpy_32_16_1( fi6, FFT_15PONIT_WNK2 ), Mpy_32_16_1( fi4, FFT_15PONIT_WNK3 ) ); - fo4 = L_sub( Mpy_32_16_1( fi4, FFT_15PONIT_WNK2 ), Mpy_32_16_1( fi6, FFT_15PONIT_WNK3 ) ); + fo3 = L_add( Mpy_32_16_1( fi6, FFT_15PONIT_WNK2 ), Mpy_32_16_1( fi4, FFT_15PONIT_WNK3 ) ); // Qx + fo4 = L_sub( Mpy_32_16_1( fi4, FFT_15PONIT_WNK2 ), Mpy_32_16_1( fi6, FFT_15PONIT_WNK3 ) ); // Qx fo7 = L_sub( fi2, L_shr( fi8, 2 ) ); fo5 = L_add( fo2, fo7 ); fo6 = L_sub( fo7, fo2 ); @@ -1599,8 +1600,8 @@ static void fft5_4( *-----------------------------------------------------------------*/ void DoRTFT80_fx( - Word32 *x, /* i/o: real part of input and output data */ - Word32 *y /* i/o: imaginary part of input and output data */ + Word32 *x, /* i/o: real part of input and output data Qx */ + Word32 *y /* i/o: imaginary part of input and output data Qx */ ) { Word16 j; @@ -1626,8 +1627,8 @@ void DoRTFT80_fx( *-----------------------------------------------------------------*/ void DoRTFT120_fx( - Word32 *x, /* i/o: real part of input and output data */ - Word32 *y /* i/o: imaginary part of input and output data */ + Word32 *x, /* i/o: real part of input and output data Qx */ + Word32 *y /* i/o: imaginary part of input and output data Qx */ ) { Word16 j; @@ -1653,8 +1654,8 @@ void DoRTFT120_fx( *-----------------------------------------------------------------*/ void DoRTFT160_fx( - Word32 x[], /* i/o: real part of input and output data */ - Word32 y[] /* i/o: imaginary part of input and output data */ + Word32 x[], /* i/o: real part of input and output data Qx */ + Word32 y[] /* i/o: imaginary part of input and output data Qx */ ) { Word16 j; @@ -1680,8 +1681,8 @@ void DoRTFT160_fx( *-----------------------------------------------------------------*/ void DoRTFT320_fx( - Word32 *x, /* i/o: real part of input and output data */ - Word32 *y /* i/o: imaginary part of input and output data */ + Word32 *x, /* i/o: real part of input and output data Qx */ + Word32 *y /* i/o: imaginary part of input and output data Qx */ ) { Word16 j; @@ -1707,8 +1708,8 @@ void DoRTFT320_fx( *-----------------------------------------------------------------*/ void DoRTFT480_fx( - Word32 *x, /* i/o: real part of input and output data */ - Word32 *y /* i/o: imaginary part of input and output data */ + Word32 *x, /* i/o: real part of input and output data Qx */ + Word32 *y /* i/o: imaginary part of input and output data Qx */ ) { Word16 j; @@ -1734,8 +1735,8 @@ void DoRTFT480_fx( *-----------------------------------------------------------------*/ void DoRTFT40_fx( - Word32 *x, /* i/o: real part of input and output data */ - Word32 *y /* i/o: imaginary part of input and output data */ + Word32 *x, /* i/o: real part of input and output data Qx */ + Word32 *y /* i/o: imaginary part of input and output data Qx */ ) { Word16 j; @@ -1760,8 +1761,8 @@ void DoRTFT40_fx( *-----------------------------------------------------------------*/ void DoRTFT20_fx( - Word32 *x, /* i/o: real part of input and output data */ - Word32 *y /* i/o: imaginary part of input and output data */ + Word32 *x, /* i/o: real part of input and output data Qx */ + Word32 *y /* i/o: imaginary part of input and output data Qx */ ) { Word16 j; @@ -1787,8 +1788,8 @@ void DoRTFT20_fx( *-----------------------------------------------------------------*/ void DoRTFT128_fx( - Word32 *x, /* i/o: real part of input and output data */ - Word32 *y /* i/o: imaginary part of input and output data */ + Word32 *x, /* i/o: real part of input and output data Qx */ + Word32 *y /* i/o: imaginary part of input and output data Qx */ ) { @@ -1799,7 +1800,7 @@ void DoRTFT128_fx( { z[2 * i] = x[i]; move32(); - z[add( shl( i, 1 ), 1 )] = y[i]; + z[( ( i << 1 ) + 1 )] = y[i]; move32(); } @@ -1813,7 +1814,7 @@ void DoRTFT128_fx( { x[128 - i] = z[2 * i]; move32(); - y[128 - i] = z[add( shl( i, 1 ), 1 )]; + y[128 - i] = z[( ( i << 1 ) + 1 )]; move32(); } @@ -1826,10 +1827,10 @@ void DoRTFT128_fx( *-----------------------------------------------------------------*/ static void cdftForw( - Word16 n, /* i : data length of real and imag */ - Word32 *a, /* i/o: input/output data */ - const Word16 *ip, /* i : work area for bit reversal */ - const Word16 *w /* i : cos/sin table */ + Word16 n, /* i : data length of real and imag Q0 */ + Word32 *a, /* i/o: input/output data Qx */ + const Word16 *ip, /* i : work area for bit reversal Qx */ + const Word16 *w /* i : cos/sin table Q15 */ ) { /* bit reversal */ @@ -1845,9 +1846,9 @@ static void cdftForw( *-----------------------------------------------------------------*/ static void bitrv2_SR( - Word16 n, /* i : data length of real and imag */ - const Word16 *ip, /* i/o: work area for bit reversal */ - Word32 *a /* i/o: input/output data */ + Word16 n, /* i : data length of real and imag Q0 */ + const Word16 *ip, /* i/o: work area for bit reversal Q0 */ + Word32 *a /* i/o: input/output data Qx */ ) { Word16 j, j1, k, k1, m, m2; @@ -1882,7 +1883,7 @@ static void bitrv2_SR( m = 1; move16(); - WHILE( shl( m, 3 ) < l ) + WHILE( ( m << 3 ) < l ) { l = shr( l, 1 ); m = shl( m, 1 ); @@ -1900,21 +1901,21 @@ static void bitrv2_SR( { j1 = add( shl( j, 1 ), ip[k] ); k1 = add( shl( k, 1 ), ip[j] ); - xr = a[j1]; + xr = a[j1]; // Qx move32(); - xi = a[j1 + 1]; + xi = a[j1 + 1]; // Qx move32(); - yr = a[k1]; + yr = a[k1]; // Qx move32(); - yi = a[k1 + 1]; + yi = a[k1 + 1]; // Qx move32(); - a[j1] = yr; + a[j1] = yr; // Qx move32(); - a[j1 + 1] = yi; + a[j1 + 1] = yi; // Qx move32(); - a[k1] = xr; + a[k1] = xr; // Qx move32(); - a[k1 + 1] = xi; + a[k1 + 1] = xi; // Qx move32(); j1 = add( j1, m2 ); k1 = add( k1, 2 * m2 ); @@ -2047,9 +2048,9 @@ static void bitrv2_SR( *-----------------------------------------------------------------*/ static void cftfsub( - Word16 n, /* i : data length of real and imag */ - Word32 *a, /* i/o: input/output data */ - const Word16 *w /* i : cos/sin table */ + Word16 n, /* i : data length of real and imag Q0 */ + Word32 *a, /* i/o: input/output data Qx */ + const Word16 *w /* i : cos/sin table Q15 */ ) { Word16 j, j1, j2, j3, l; @@ -2065,7 +2066,7 @@ static void cftfsub( l = 8; move16(); - WHILE( LT_16( shl( l, 2 ), n ) ) + WHILE( ( ( l << 2 ) < n ) ) { cftmdl( n, l, a, w ); l = shl( l, 2 ); @@ -2079,14 +2080,14 @@ static void cftfsub( j1 = add( j, l ); j2 = add( j1, l ); j3 = add( j2, l ); - x0r = L_add( a[j], a[j1] ); - x0i = L_add( a[j + 1], a[j1 + 1] ); - x1r = L_sub( a[j], a[j1] ); - x1i = L_sub( a[j + 1], a[j1 + 1] ); - x2r = L_add( a[j2], a[j3] ); - x2i = L_add( a[j2 + 1], a[j3 + 1] ); - x3r = L_sub( a[j2], a[j3] ); - x3i = L_sub( a[j2 + 1], a[j3 + 1] ); + x0r = L_add( a[j], a[j1] ); // Qx + x0i = L_add( a[j + 1], a[j1 + 1] ); // Qx + x1r = L_sub( a[j], a[j1] ); // Qx + x1i = L_sub( a[j + 1], a[j1 + 1] ); // Qx + x2r = L_add( a[j2], a[j3] ); // Qx + x2i = L_add( a[j2 + 1], a[j3 + 1] ); // Qx + x3r = L_sub( a[j2], a[j3] ); // Qx + x3i = L_sub( a[j2 + 1], a[j3 + 1] ); // Qx a[j] = L_add( x0r, x2r ); move32(); a[j + 1] = L_add( x0i, x2i ); @@ -2132,23 +2133,23 @@ static void cftfsub( *-----------------------------------------------------------------*/ static void cft1st( - Word16 n, /* i : data length of real and imag */ - Word32 *a, /* i/o: input/output data */ - const Word16 *w /* i : cos/sin table */ + Word16 n, /* i : data length of real and imag Q0 */ + Word32 *a, /* i/o: input/output data Qx */ + const Word16 *w /* i : cos/sin table Q15 */ ) { Word16 j, k1, k2; Word16 wk1r, wk1i, wk2r, wk2i, wk3r, wk3i, wtmp; Word32 x0r, x0i, x1r, x1i, x2r, x2i, x3r, x3i; - x0r = L_add( a[0], a[2] ); - x0i = L_add( a[1], a[3] ); - x1r = L_sub( a[0], a[2] ); - x1i = L_sub( a[1], a[3] ); - x2r = L_add( a[4], a[6] ); - x2i = L_add( a[5], a[7] ); - x3r = L_sub( a[4], a[6] ); - x3i = L_sub( a[5], a[7] ); + x0r = L_add( a[0], a[2] ); // Qx + x0i = L_add( a[1], a[3] ); // Qx + x1r = L_sub( a[0], a[2] ); // Qx + x1i = L_sub( a[1], a[3] ); // Qx + x2r = L_add( a[4], a[6] ); // Qx + x2i = L_add( a[5], a[7] ); // Qx + x3r = L_sub( a[4], a[6] ); // Qx + x3i = L_sub( a[5], a[7] ); // Qx a[0] = L_add( x0r, x2r ); move32(); a[1] = L_add( x0i, x2i ); @@ -2295,10 +2296,10 @@ static void cft1st( *-----------------------------------------------------------------*/ static void cftmdl( - Word16 n, /* i : data length of real and imag */ - Word16 l, /* i : initial shift for processing */ - Word32 *a, /* i/o: input/output data */ - const Word16 *w /* i : cos/sin table */ + Word16 n, /* i : data length of real and imag Q0 */ + Word16 l, /* i : initial shift for processing Q0 */ + Word32 *a, /* i/o: input/output data Qx */ + const Word16 *w /* i : cos/sin table Q15 */ ) { Word16 j, j1, j2, j3, k, k1, k2, m, m2; @@ -2311,14 +2312,14 @@ static void cftmdl( j1 = add( j, l ); j2 = add( j1, l ); j3 = add( j2, l ); - x0r = L_add( a[j], a[j1] ); - x0i = L_add( a[j + 1], a[j1 + 1] ); - x1r = L_sub( a[j], a[j1] ); - x1i = L_sub( a[j + 1], a[j1 + 1] ); - x2r = L_add( a[j2], a[j3] ); - x2i = L_add( a[j2 + 1], a[j3 + 1] ); - x3r = L_sub( a[j2], a[j3] ); - x3i = L_sub( a[j2 + 1], a[j3 + 1] ); + x0r = L_add( a[j], a[j1] ); // Qx + x0i = L_add( a[j + 1], a[j1 + 1] ); // Qx + x1r = L_sub( a[j], a[j1] ); // Qx + x1i = L_sub( a[j + 1], a[j1 + 1] ); // Qx + x2r = L_add( a[j2], a[j3] ); // Qx + x2i = L_add( a[j2 + 1], a[j3 + 1] ); // Qx + x3r = L_sub( a[j2], a[j3] ); // Qx + x3i = L_sub( a[j2 + 1], a[j3 + 1] ); // Qx a[j] = L_add( x0r, x2r ); move32(); a[j + 1] = L_add( x0i, x2i ); @@ -2414,21 +2415,21 @@ static void cftmdl( move32(); x0r = L_sub( x0r, x2r ); x0i = L_sub( x0i, x2i ); - a[j2] = L_sub( Mpy_32_16_1( x0r, wk2r ), Mpy_32_16_1( x0i, wk2i ) ); + a[j2] = L_sub( Mpy_32_16_1( x0r, wk2r ), Mpy_32_16_1( x0i, wk2i ) ); // Qx move32(); - a[j2 + 1] = L_add( Mpy_32_16_1( x0i, wk2r ), Mpy_32_16_1( x0r, wk2i ) ); + a[j2 + 1] = L_add( Mpy_32_16_1( x0i, wk2r ), Mpy_32_16_1( x0r, wk2i ) ); // Qx move32(); x0r = L_sub( x1r, x3i ); x0i = L_add( x1i, x3r ); - a[j1] = L_sub( Mpy_32_16_1( x0r, wk1r ), Mpy_32_16_1( x0i, wk1i ) ); + a[j1] = L_sub( Mpy_32_16_1( x0r, wk1r ), Mpy_32_16_1( x0i, wk1i ) ); // Qx move32(); - a[j1 + 1] = L_add( Mpy_32_16_1( x0i, wk1r ), Mpy_32_16_1( x0r, wk1i ) ); + a[j1 + 1] = L_add( Mpy_32_16_1( x0i, wk1r ), Mpy_32_16_1( x0r, wk1i ) ); // Qx move32(); x0r = L_add( x1r, x3i ); x0i = L_sub( x1i, x3r ); - a[j3] = L_sub( Mpy_32_16_1( x0r, wk3r ), Mpy_32_16_1( x0i, wk3i ) ); + a[j3] = L_sub( Mpy_32_16_1( x0r, wk3r ), Mpy_32_16_1( x0i, wk3i ) ); // Qx move32(); - a[j3 + 1] = L_add( Mpy_32_16_1( x0i, wk3r ), Mpy_32_16_1( x0r, wk3i ) ); + a[j3 + 1] = L_add( Mpy_32_16_1( x0i, wk3r ), Mpy_32_16_1( x0r, wk3i ) ); // Qx move32(); } @@ -2461,21 +2462,21 @@ static void cftmdl( move32(); x0r = L_sub( x0r, x2r ); x0i = L_sub( x0i, x2i ); - a[j2] = L_negate( L_add( Mpy_32_16_1( x0r, wk2i ), Mpy_32_16_1( x0i, wk2r ) ) ); + a[j2] = L_negate( L_add( Mpy_32_16_1( x0r, wk2i ), Mpy_32_16_1( x0i, wk2r ) ) ); // Qx move32(); - a[j2 + 1] = L_sub( Mpy_32_16_1( x0r, wk2r ), Mpy_32_16_1( x0i, wk2i ) ); + a[j2 + 1] = L_sub( Mpy_32_16_1( x0r, wk2r ), Mpy_32_16_1( x0i, wk2i ) ); // Qx move32(); x0r = L_sub( x1r, x3i ); x0i = L_add( x1i, x3r ); - a[j1] = L_sub( Mpy_32_16_1( x0r, wk1r ), Mpy_32_16_1( x0i, wk1i ) ); + a[j1] = L_sub( Mpy_32_16_1( x0r, wk1r ), Mpy_32_16_1( x0i, wk1i ) ); // Qx move32(); - a[j1 + 1] = L_add( Mpy_32_16_1( x0i, wk1r ), Mpy_32_16_1( x0r, wk1i ) ); + a[j1 + 1] = L_add( Mpy_32_16_1( x0i, wk1r ), Mpy_32_16_1( x0r, wk1i ) ); // Qx move32(); x0r = L_add( x1r, x3i ); x0i = L_sub( x1i, x3r ); - a[j3] = L_sub( Mpy_32_16_1( x0r, wk3r ), Mpy_32_16_1( x0i, wk3i ) ); + a[j3] = L_sub( Mpy_32_16_1( x0r, wk3r ), Mpy_32_16_1( x0i, wk3i ) ); // Qx move32(); - a[j3 + 1] = L_add( Mpy_32_16_1( x0i, wk3r ), Mpy_32_16_1( x0r, wk3i ) ); + a[j3 + 1] = L_add( Mpy_32_16_1( x0i, wk3r ), Mpy_32_16_1( x0r, wk3i ) ); // Qx move32(); } } @@ -2484,9 +2485,9 @@ static void cftmdl( } static void cftbsub( - Word16 n, - Word32 *a, - const Word16 *w /* i : cos/sin table */ + Word16 n, // Q0 + Word32 *a, // Qx + const Word16 *w /* i : cos/sin table Q15 */ ) { Word16 j, j1, j2, j3, l; @@ -2500,7 +2501,7 @@ static void cftbsub( l = 8; move16(); - WHILE( LT_16( shl( l, 2 ), n ) ) + WHILE( ( ( l << 2 ) < n ) ) { cftmdl( n, l, a, w ); l = shl( l, 2 ); @@ -2514,14 +2515,14 @@ static void cftbsub( j1 = add( j, l ); j2 = add( j1, l ); j3 = add( j2, l ); - x0r = L_add( a[j], a[j1] ); - x0i = L_negate( L_add( a[j + 1], a[j1 + 1] ) ); - x1r = L_sub( a[j], a[j1] ); - x1i = L_sub( a[j1 + 1], a[j + 1] ); - x2r = L_add( a[j2], a[j3] ); - x2i = L_add( a[j2 + 1], a[j3 + 1] ); - x3r = L_sub( a[j2], a[j3] ); - x3i = L_sub( a[j2 + 1], a[j3 + 1] ); + x0r = L_add( a[j], a[j1] ); // Qx + x0i = L_negate( L_add( a[j + 1], a[j1 + 1] ) ); // Qx + x1r = L_sub( a[j], a[j1] ); // Qx + x1i = L_sub( a[j1 + 1], a[j + 1] ); // Qx + x2r = L_add( a[j2], a[j3] ); // Qx + x2i = L_add( a[j2 + 1], a[j3 + 1] ); // Qx + x3r = L_sub( a[j2], a[j3] ); // Qx + x3i = L_sub( a[j2 + 1], a[j3 + 1] ); // Qx a[j] = L_add( x0r, x2r ); move32(); a[j + 1] = L_sub( x0i, x2i ); @@ -2562,10 +2563,11 @@ static void cftbsub( } static void rftfsub( - Word16 n, - Word32 *a, - Word16 nc, - const Word16 *c ) + Word16 n, // Q0 + Word32 *a, // Qx + Word16 nc, // Q0 + const Word16 *c // Q15 +) { Word16 j, k, kk, ks, m; Word16 wkr, wki; @@ -2579,8 +2581,8 @@ static void rftfsub( { k = sub( n, j ); kk = add( kk, ks ); - wkr = sub( (Word16) 0x4000, c[sub( nc, kk )] ); - wki = c[kk]; + wkr = sub( extract_l( 0x4000 ) /*0.5.Q15*/, c[( nc - kk )] ); + wki = c[kk]; // Q15 move16(); xr = L_sub( a[j], a[k] ); xi = L_add( a[j + 1], a[k + 1] ); @@ -2601,10 +2603,11 @@ static void rftfsub( static void rftbsub( - Word16 n, - Word32 *a, - Word16 nc, - const Word16 *c ) + Word16 n, // Q0 + Word32 *a, // Qx + Word16 nc, // Q0 + const Word16 *c // Q15 +) { Word16 j, k, kk, ks, m; Word16 wkr, wki; @@ -2619,12 +2622,12 @@ static void rftbsub( { k = sub( n, j ); kk = add( kk, ks ); - wkr = sub( (Word16) 0x4000, c[sub( nc, kk )] ); - wki = c[kk]; + wkr = sub( extract_l( 0x4000 ) /*0.5.Q15*/, c[( nc - kk )] ); + wki = c[kk]; // Q15 xr = L_sub( a[j], a[k] ); xi = L_add( a[j + 1], a[k + 1] ); - yr = L_add( Mpy_32_16_1( xr, wkr ), Mpy_32_16_1( xi, wki ) ); - yi = L_sub( Mpy_32_16_1( xi, wkr ), Mpy_32_16_1( xr, wki ) ); + yr = L_add( Mpy_32_16_1( xr, wkr ), Mpy_32_16_1( xi, wki ) ); // Qx + yi = L_sub( Mpy_32_16_1( xi, wkr ), Mpy_32_16_1( xr, wki ) ); // Qx a[j] = L_sub( a[j], yr ); move32(); a[j + 1] = L_sub( yi, a[j + 1] ); @@ -2641,10 +2644,11 @@ static void rftbsub( static void dctsub( - Word16 n, - Word32 *a, - Word16 nc, - const Word16 *c ) + Word16 n, // Q0 + Word32 *a, // Qx + Word16 nc, // Q0 + const Word16 *c // Q15 +) { Word16 j, k, kk, ks, m; Word16 wkr, wki; @@ -2658,15 +2662,15 @@ static void dctsub( { k = sub( n, j ); kk = add( kk, ks ); - wkr = sub( c[kk], c[sub( nc, kk )] ); - wki = add( c[kk], c[sub( nc, kk )] ); - xr = L_sub( Mpy_32_16_1( a[j], wki ), Mpy_32_16_1( a[k], wkr ) ); - a[j] = L_add( Mpy_32_16_1( a[j], wkr ), Mpy_32_16_1( a[k], wki ) ); + wkr = sub( c[kk], c[( nc - kk )] ); // Q15 + wki = add( c[kk], c[( nc - kk )] ); // Q15 + xr = L_sub( Mpy_32_16_1( a[j], wki ), Mpy_32_16_1( a[k], wkr ) ); // Qx + a[j] = L_add( Mpy_32_16_1( a[j], wkr ), Mpy_32_16_1( a[k], wki ) ); // Qx move32(); a[k] = xr; move32(); } - a[m] = Mpy_32_16_1( a[m], c[0] ); + a[m] = Mpy_32_16_1( a[m], c[0] ); // Qx move32(); return; @@ -2680,12 +2684,13 @@ static void dctsub( *-----------------------------------------------------------------*/ void edct2_fx_ivas( - const Word16 n, + const Word16 n, // Q0 const Word16 isgn, - Word32 *in, - Word32 *a, + Word32 *in, // Qx + Word32 *a, // Qx const Word16 *ip, - const Word16 *w ) + const Word16 *w // Q15 +) { Word16 j, nw, nc; Word32 xr; @@ -2694,7 +2699,7 @@ void edct2_fx_ivas( nw = ip[0]; move16(); - if ( GT_16( n, shl( nw, 2 ) ) ) + IF( GT_16( n, shl( nw, 2 ) ) ) { nw = shr( n, 2 ); } @@ -2776,9 +2781,9 @@ void edct2_fx_ivas( } void DoRTFTn_fx_ivas( - Word32 *x, /* i/o: real part of input and output data */ - Word32 *y, /* i/o: imaginary part of input and output data */ - const Word16 n /* i : size of the FFT up to 1024 */ + Word32 *x, /* i/o: real part of input and output data Qx */ + Word32 *y, /* i/o: imaginary part of input and output data Qx */ + const Word16 n /* i : size of the FFT up to 1024 Q0*/ ) { @@ -2787,9 +2792,9 @@ void DoRTFTn_fx_ivas( FOR( i = 0; i < n; i++ ) { - z[2 * i] = x[i]; + z[2 * i] = x[i]; // Qx move32(); - z[add( shl( i, 1 ), 1 )] = y[i]; + z[( ( i << 1 ) + 1 )] = y[i]; // Qx move32(); } @@ -2817,15 +2822,15 @@ void DoRTFTn_fx_ivas( assert( 0 ); } - x[0] = z[0]; + x[0] = z[0]; // Qx move32(); - y[0] = z[1]; + y[0] = z[1]; // Qx move32(); FOR( i = 1; i < n; i++ ) { - x[sub( n, i )] = z[2 * i]; + x[( n - i )] = z[2 * i]; move32(); - y[sub( n, i )] = z[add( shl( i, 1 ), 1 )]; + y[( n - i )] = z[( ( i << 1 ) + 1 )]; move32(); } @@ -2833,15 +2838,16 @@ void DoRTFTn_fx_ivas( } void fft3_fx_ivas( - const Word32 X[], - Word32 Y[], - const Word16 n ) + const Word32 X[], // Qx + Word32 Y[], // Qx + const Word16 n // Q0 +) { Word32 Z[PH_ECU_SPEC_SIZE]; Word32 *Z0, *Z1, *Z2; Word32 *z0, *z1, *z2; const Word32 *x; - const Word16 *t_sin = sincos_t_rad3_fx; + const Word16 *t_sin = sincos_t_rad3_fx; // Q15 Word16 m, step, order; Word16 i, j; Word16 c1_ind, s1_ind, c2_ind, s2_ind; @@ -2902,8 +2908,8 @@ void fft3_fx_ivas( /* Butterflies of order 3. */ /* pointer initialization */ - RY = &Y[0]; - IY = &Y[n]; + RY = &Y[0]; // Qx + IY = &Y[n]; // Qx RZ0 = &Z0[0]; IZ0 = &Z0[m]; RZ1 = &Z1[0]; @@ -2928,42 +2934,42 @@ void fft3_fx_ivas( move32(); /* first 3/12 */ - FOR( i = 1; i < i_mult( 3, shr( m, 3 ) ); ( i++, c1_ind = add( c1_ind, c1_step ), s1_ind = add( s1_ind, s1_step ), c2_ind = add( c2_ind, c2_step ), s2_ind = add( s2_ind, s2_step ) ) ) + FOR( i = 1; i < ( 3 * ( m >> 3 ) ); ( i++, c1_ind = ( c1_ind + c1_step ), s1_ind = ( s1_ind + s1_step ), c2_ind = ( c2_ind + c2_step ), s2_ind = ( s2_ind + s2_step ) ) ) { RY[i] = L_add( RZ0[i], L_add( Mpy_32_16_1( RZ1[i], t_sin[c1_ind] ), L_add( Mpy_32_16_1( IZ1[-i], t_sin[s1_ind] ), L_add( Mpy_32_16_1( RZ2[i], t_sin[c2_ind] ), - Mpy_32_16_1( IZ2[-i], t_sin[s2_ind] ) ) ) ) ); + Mpy_32_16_1( IZ2[-i], t_sin[s2_ind] ) ) ) ) ); // Qx move32(); IY[-i] = L_sub( IZ0[-i], L_add( L_sub( Mpy_32_16_1( RZ1[i], t_sin[s1_ind] ), Mpy_32_16_1( IZ1[-i], t_sin[c1_ind] ) ), L_sub( Mpy_32_16_1( RZ2[i], t_sin[s2_ind] ), - Mpy_32_16_1( IZ2[-i], t_sin[c2_ind] ) ) ) ); + Mpy_32_16_1( IZ2[-i], t_sin[c2_ind] ) ) ) ); // Qx move32(); } /* next 1/12 */ - FOR( ; i < 4 * m / 8; ( i++, c1_ind = add( c1_ind, c1_step ), s1_ind = add( s1_ind, s1_step ), c2_ind = sub( c2_ind, c2_step ), s2_ind = sub( s2_ind, s2_step ) ) ) + FOR( ; i < 4 * m / 8; ( i++, c1_ind = ( c1_ind + c1_step ), s1_ind = ( s1_ind + s1_step ), c2_ind = ( c2_ind - c2_step ), s2_ind = ( s2_ind - s2_step ) ) ) { RY[i] = L_add( RZ0[i], L_sub( L_add( Mpy_32_16_1( RZ1[i], t_sin[c1_ind] ), Mpy_32_16_1( IZ1[-i], t_sin[s1_ind] ) ), L_sub( Mpy_32_16_1( RZ2[i], t_sin[c2_ind] ), - Mpy_32_16_1( IZ2[-i], t_sin[s2_ind] ) ) ) ); + Mpy_32_16_1( IZ2[-i], t_sin[s2_ind] ) ) ) ); // Qx move32(); IY[-i] = L_sub( IZ0[-i], L_sub( Mpy_32_16_1( RZ1[i], t_sin[s1_ind] ), L_sub( Mpy_32_16_1( IZ1[-i], t_sin[c1_ind] ), L_add( Mpy_32_16_1( RZ2[i], t_sin[s2_ind] ), - Mpy_32_16_1( IZ2[-i], t_sin[c2_ind] ) ) ) ) ); + Mpy_32_16_1( IZ2[-i], t_sin[c2_ind] ) ) ) ) ); // Qx move32(); } /* special case: i = m/2 i.e. 1/3 */ RY[i] = L_add( RZ0[i], L_sub( Mpy_32_16_1( RZ1[i], t_sin[c1_ind] ), - Mpy_32_16_1( RZ2[i], t_sin[c2_ind] ) ) ); + Mpy_32_16_1( RZ2[i], t_sin[c2_ind] ) ) ); // Qx move32(); IY[-i] = L_negate( L_add( Mpy_32_16_1( RZ1[i], t_sin[s1_ind] ), - Mpy_32_16_1( RZ2[i], t_sin[s2_ind] ) ) ); + Mpy_32_16_1( RZ2[i], t_sin[s2_ind] ) ) ); // Qx move32(); i = add( i, 1 ); @@ -2973,92 +2979,92 @@ void fft3_fx_ivas( s2_ind = sub( s2_ind, s2_step ); /* next 2/12 */ - FOR( j = i - 2; i < 6 * m / 8; ( i++, j--, c1_ind = add( c1_ind, c1_step ), s1_ind = add( s1_ind, s1_step ), c2_ind = sub( c2_ind, c2_step ), s2_ind = sub( s2_ind, s2_step ) ) ) + FOR( j = i - 2; i < 6 * m / 8; ( i++, j--, c1_ind = ( c1_ind + c1_step ), s1_ind = ( s1_ind + s1_step ), c2_ind = ( c2_ind - c2_step ), s2_ind = ( s2_ind - s2_step ) ) ) { RY[i] = L_add( RZ0[j], L_sub( Mpy_32_16_1( RZ1[j], t_sin[c1_ind] ), L_add( Mpy_32_16_1( IZ1[-j], t_sin[s1_ind] ), L_add( Mpy_32_16_1( RZ2[j], t_sin[c2_ind] ), - Mpy_32_16_1( IZ2[-j], t_sin[s2_ind] ) ) ) ) ); + Mpy_32_16_1( IZ2[-j], t_sin[s2_ind] ) ) ) ) ); // Qx move32(); IY[-i] = L_negate( L_add( IZ0[-j], L_add( Mpy_32_16_1( RZ1[j], t_sin[s1_ind] ), L_add( Mpy_32_16_1( IZ1[-j], t_sin[c1_ind] ), L_sub( Mpy_32_16_1( RZ2[j], t_sin[s2_ind] ), - Mpy_32_16_1( IZ2[-j], t_sin[c2_ind] ) ) ) ) ) ); + Mpy_32_16_1( IZ2[-j], t_sin[c2_ind] ) ) ) ) ) ); // Qx move32(); } /*--------------------------half--------------------------*/ /* next 2/12 */ - FOR( ; i < 8 * m / 8; ( i++, j--, c1_ind = sub( c1_ind, c1_step ), s1_ind = sub( s1_ind, s1_step ), c2_ind = add( c2_ind, c2_step ), s2_ind = add( s2_ind, s2_step ) ) ) + FOR( ; i < 8 * m / 8; ( i++, j--, c1_ind = ( c1_ind - c1_step ), s1_ind = ( s1_ind - s1_step ), c2_ind = ( c2_ind + c2_step ), s2_ind = ( s2_ind + s2_step ) ) ) { RY[i] = L_sub( RZ0[j], L_add( Mpy_32_16_1( RZ1[j], t_sin[c1_ind] ), L_add( Mpy_32_16_1( IZ1[-j], t_sin[s1_ind] ), L_sub( Mpy_32_16_1( RZ2[j], t_sin[c2_ind] ), - Mpy_32_16_1( IZ2[-j], t_sin[s2_ind] ) ) ) ) ); + Mpy_32_16_1( IZ2[-j], t_sin[s2_ind] ) ) ) ) ); // Qx move32(); IY[-i] = L_negate( L_add( IZ0[-j], L_sub( Mpy_32_16_1( RZ1[j], t_sin[s1_ind] ), L_add( Mpy_32_16_1( IZ1[-j], t_sin[c1_ind] ), L_add( Mpy_32_16_1( RZ2[j], t_sin[s2_ind] ), - Mpy_32_16_1( IZ2[-j], t_sin[c2_ind] ) ) ) ) ) ); + Mpy_32_16_1( IZ2[-j], t_sin[c2_ind] ) ) ) ) ) ); // Qx move32(); } /* special case: i = m, i.e 2/3 */ RY[i] = L_sub( RZ0[j], L_add( Mpy_32_16_1( RZ1[j], t_sin[c1_ind] ), - Mpy_32_16_1( RZ2[j], t_sin[c2_ind] ) ) ); + Mpy_32_16_1( RZ2[j], t_sin[c2_ind] ) ) ); // Qx move32(); IY[-i] = L_sub( Mpy_32_16_1( RZ2[j], t_sin[s2_ind] ), - Mpy_32_16_1( RZ1[j], t_sin[s1_ind] ) ); + Mpy_32_16_1( RZ1[j], t_sin[s1_ind] ) ); // Qx move32(); i = add( i, 1 ); c1_ind = sub( c1_ind, c1_step ), s1_ind = sub( s1_ind, s1_step ), c2_ind = add( c2_ind, c2_step ), s2_ind = add( s2_ind, s2_step ); /* next 1/12 */ - FOR( j = 1; i < i_mult( 9, shr( m, 3 ) ); ( i++, j++, c1_ind = sub( c1_ind, c1_step ), s1_ind = sub( s1_ind, s1_step ), c2_ind = add( c2_ind, c2_step ), s2_ind = add( s2_ind, s2_step ) ) ) + FOR( j = 1; i < ( 9 * ( m >> 3 ) ); ( i++, j++, c1_ind = ( c1_ind - c1_step ), s1_ind = ( s1_ind - s1_step ), c2_ind = ( c2_ind + c2_step ), s2_ind = ( s2_ind + s2_step ) ) ) { RY[i] = L_sub( RZ0[j], L_sub( Mpy_32_16_1( RZ1[j], t_sin[c1_ind] ), L_sub( Mpy_32_16_1( IZ1[-j], t_sin[s1_ind] ), L_add( Mpy_32_16_1( RZ2[j], t_sin[c2_ind] ), - Mpy_32_16_1( IZ2[-j], t_sin[s2_ind] ) ) ) ) ); + Mpy_32_16_1( IZ2[-j], t_sin[s2_ind] ) ) ) ) ); // Qx move32(); IY[-i] = L_sub( IZ0[-j], L_add( Mpy_32_16_1( RZ1[j], t_sin[s1_ind] ), L_sub( Mpy_32_16_1( IZ1[-j], t_sin[c1_ind] ), L_sub( Mpy_32_16_1( RZ2[j], t_sin[s2_ind] ), - Mpy_32_16_1( IZ2[-j], t_sin[c2_ind] ) ) ) ) ); + Mpy_32_16_1( IZ2[-j], t_sin[c2_ind] ) ) ) ) ); // Qx move32(); } /* last 3/12 */ - FOR( ; i < 12 * m / 8; ( i++, j++, c1_ind = sub( c1_ind, c1_step ), s1_ind = sub( s1_ind, s1_step ), c2_ind = sub( c2_ind, c2_step ), s2_ind = sub( s2_ind, s2_step ) ) ) + FOR( ; i < 12 * m / 8; ( i++, j++, c1_ind = ( c1_ind - c1_step ), s1_ind = ( s1_ind - s1_step ), c2_ind = ( c2_ind - c2_step ), s2_ind = ( s2_ind - s2_step ) ) ) { RY[i] = L_sub( RZ0[j], L_sub( L_sub( Mpy_32_16_1( RZ1[j], t_sin[c1_ind] ), Mpy_32_16_1( IZ1[-j], t_sin[s1_ind] ) ), L_sub( Mpy_32_16_1( RZ2[j], t_sin[c2_ind] ), - Mpy_32_16_1( IZ2[-j], t_sin[s2_ind] ) ) ) ); + Mpy_32_16_1( IZ2[-j], t_sin[s2_ind] ) ) ) ); // Qx move32(); IY[-i] = L_sub( IZ0[-j], L_sub( L_add( Mpy_32_16_1( RZ1[j], t_sin[s1_ind] ), Mpy_32_16_1( IZ1[-j], t_sin[c1_ind] ) ), L_add( Mpy_32_16_1( RZ2[j], t_sin[s2_ind] ), - Mpy_32_16_1( IZ2[-j], t_sin[c2_ind] ) ) ) ); + Mpy_32_16_1( IZ2[-j], t_sin[c2_ind] ) ) ) ); // Qx move32(); } /* special case: i = 3*m/2 */ RY[i] = L_sub( RZ0[j], L_sub( Mpy_32_16_1( RZ1[j], t_sin[c1_ind] ), - Mpy_32_16_1( RZ2[j], t_sin[c2_ind] ) ) ); + Mpy_32_16_1( RZ2[j], t_sin[c2_ind] ) ) ); // Qx move32(); return; } void ifft3_fx_ivas( - const Word32 Z[], + const Word32 Z[], // Qx Word32 X[], const Word16 n ) { Word32 Y[PH_ECU_SPEC_SIZE]; - const Word16 *t_sin = sincos_t_rad3_fx; + const Word16 *t_sin = sincos_t_rad3_fx; // Q15 Word16 m, step, step2, order; Word16 i; Word16 c0_ind, s0_ind, c1_ind, s1_ind, c2_ind, s2_ind; @@ -3103,7 +3109,7 @@ void ifft3_fx_ivas( RY2 = &RY1[m]; IY2 = &RY2[m]; - RZ0 = &Z[0]; + RZ0 = &Z[0]; // Qx RZ1 = RZ0 + m; RZ2 = RZ0 + sub( shr( n, 1 ), shr( m, 1 ) ); IZ0 = &Z[n]; @@ -3139,7 +3145,7 @@ void ifft3_fx_ivas( L_add( Mpy_32_16_1( RZ1[0], t_sin[c1_ind] ), L_add( Mpy_32_16_1( RZ2[0], t_sin[c2_ind] ), L_add( Mpy_32_16_1( IZ1[0], t_sin[s1_ind] ), - Mpy_32_16_1( IZ2[0], t_sin[s2_ind] ) ) ) ) ); + Mpy_32_16_1( IZ2[0], t_sin[s2_ind] ) ) ) ) ); // Qx move32(); c0_ind = sub( c0_ind, step ); @@ -3148,39 +3154,39 @@ void ifft3_fx_ivas( s1_ind = sub( s1_ind, step ); c2_ind = sub( c2_ind, step ); s2_ind = add( s2_ind, step ); - FOR( i = 1; i < m / 4; ( i++, c0_ind = sub( c0_ind, step ), s0_ind = add( s0_ind, step ), c1_ind = add( c1_ind, step ), s1_ind = sub( s1_ind, step ), c2_ind = sub( c2_ind, step ), s2_ind = add( s2_ind, step ) ) ) + FOR( i = 1; i < m / 4; ( i++, c0_ind = ( c0_ind - step ), s0_ind = ( s0_ind + step ), c1_ind = ( c1_ind + step ), s1_ind = ( s1_ind - step ), c2_ind = ( c2_ind - step ), s2_ind = ( s2_ind + step ) ) ) { RY1[i] = L_sub( Mpy_32_16_1( RZ0[i], t_sin[c0_ind] ), L_add( Mpy_32_16_1( RZ1[i], t_sin[c1_ind] ), L_add( Mpy_32_16_1( RZ2[-i], t_sin[c2_ind] ), L_add( Mpy_32_16_1( IZ0[-i], t_sin[s0_ind] ), L_add( Mpy_32_16_1( IZ1[-i], t_sin[s1_ind] ), - Mpy_32_16_1( IZ2[i], t_sin[s2_ind] ) ) ) ) ) ); + Mpy_32_16_1( IZ2[i], t_sin[s2_ind] ) ) ) ) ) ); // Qx move32(); IY1[-i] = L_add( L_sub( Mpy_32_16_1( IZ0[-i], t_sin[c0_ind] ), Mpy_32_16_1( IZ1[-i], t_sin[c1_ind] ) ), L_add( Mpy_32_16_1( IZ2[i], t_sin[c2_ind] ), L_add( Mpy_32_16_1( RZ0[i], t_sin[s0_ind] ), L_sub( Mpy_32_16_1( RZ1[i], t_sin[s1_ind] ), - Mpy_32_16_1( RZ2[-i], t_sin[s2_ind] ) ) ) ) ); + Mpy_32_16_1( RZ2[-i], t_sin[s2_ind] ) ) ) ) ); // Qx move32(); } - FOR( ; i < m / 2; ( i++, c0_ind = sub( c0_ind, step ), s0_ind = add( s0_ind, step ), c1_ind = add( c1_ind, step ), s1_ind = sub( s1_ind, step ), c2_ind = add( c2_ind, step ), s2_ind = sub( s2_ind, step ) ) ) + FOR( ; i < m / 2; ( i++, c0_ind = ( c0_ind - step ), s0_ind = ( s0_ind + step ), c1_ind = ( c1_ind + step ), s1_ind = ( s1_ind - step ), c2_ind = ( c2_ind + step ), s2_ind = ( s2_ind - step ) ) ) { RY1[i] = L_sub( Mpy_32_16_1( RZ0[i], t_sin[c0_ind] ), L_add( L_sub( Mpy_32_16_1( RZ1[i], t_sin[c1_ind] ), Mpy_32_16_1( RZ2[-i], t_sin[c2_ind] ) ), L_add( Mpy_32_16_1( IZ0[-i], t_sin[s0_ind] ), L_add( Mpy_32_16_1( IZ1[-i], t_sin[s1_ind] ), - Mpy_32_16_1( IZ2[i], t_sin[s2_ind] ) ) ) ) ); + Mpy_32_16_1( IZ2[i], t_sin[s2_ind] ) ) ) ) ); // Qx move32(); IY1[-i] = L_sub( Mpy_32_16_1( IZ0[-i], t_sin[c0_ind] ), L_sub( L_add( Mpy_32_16_1( IZ1[-i], t_sin[c1_ind] ), Mpy_32_16_1( IZ2[i], t_sin[c2_ind] ) ), L_add( Mpy_32_16_1( RZ0[i], t_sin[s0_ind] ), L_sub( Mpy_32_16_1( RZ1[i], t_sin[s1_ind] ), - Mpy_32_16_1( RZ2[-i], t_sin[s2_ind] ) ) ) ) ); + Mpy_32_16_1( RZ2[-i], t_sin[s2_ind] ) ) ) ) ); // Qx move32(); } @@ -3190,7 +3196,7 @@ void ifft3_fx_ivas( Mpy_32_16_1( RZ2[-i], t_sin[c2_ind] ) ), L_add( Mpy_32_16_1( IZ0[-i], t_sin[s0_ind] ), L_add( Mpy_32_16_1( IZ1[-i], t_sin[s1_ind] ), - Mpy_32_16_1( IZ2[i], t_sin[s2_ind] ) ) ) ) ); + Mpy_32_16_1( IZ2[i], t_sin[s2_ind] ) ) ) ) ); // Qx move32(); /* Construction of Y2 */ @@ -3211,7 +3217,7 @@ void ifft3_fx_ivas( L_sub( L_add( Mpy_32_16_1( RZ1[0], t_sin[c1_ind] ), Mpy_32_16_1( RZ2[0], t_sin[c2_ind] ) ), L_add( Mpy_32_16_1( IZ1[0], t_sin[s1_ind] ), - Mpy_32_16_1( IZ2[0], t_sin[s2_ind] ) ) ) ); + Mpy_32_16_1( IZ2[0], t_sin[s2_ind] ) ) ) ); // Qx move32(); c0_ind = sub( c0_ind, step2 ); @@ -3220,75 +3226,75 @@ void ifft3_fx_ivas( s1_ind = add( s1_ind, step2 ); c2_ind = add( c2_ind, step2 ); s2_ind = sub( s2_ind, step2 ); - FOR( i = 1; i < m / 8; ( i++, c0_ind = sub( c0_ind, step2 ), s0_ind = add( s0_ind, step2 ), c1_ind = sub( c1_ind, step2 ), s1_ind = add( s1_ind, step2 ), c2_ind = add( c2_ind, step2 ), s2_ind = sub( s2_ind, step2 ) ) ) + FOR( i = 1; i < m / 8; ( i++, c0_ind = ( c0_ind - step2 ), s0_ind = ( s0_ind + step2 ), c1_ind = ( c1_ind - step2 ), s1_ind = ( s1_ind + step2 ), c2_ind = ( c2_ind + step2 ), s2_ind = ( s2_ind - step2 ) ) ) { RY2[i] = L_sub( Mpy_32_16_1( RZ0[i], t_sin[c0_ind] ), L_add( L_add( Mpy_32_16_1( RZ1[i], t_sin[c1_ind] ), Mpy_32_16_1( RZ2[-i], t_sin[c2_ind] ) ), L_sub( Mpy_32_16_1( IZ0[-i], t_sin[s0_ind] ), L_add( Mpy_32_16_1( IZ1[-i], t_sin[s1_ind] ), - Mpy_32_16_1( IZ2[i], t_sin[s2_ind] ) ) ) ) ); + Mpy_32_16_1( IZ2[i], t_sin[s2_ind] ) ) ) ) ); // Qx move32(); IY2[-i] = L_add( L_sub( Mpy_32_16_1( IZ0[-i], t_sin[c0_ind] ), Mpy_32_16_1( IZ1[-i], t_sin[c1_ind] ) ), L_add( Mpy_32_16_1( IZ2[i], t_sin[c2_ind] ), L_sub( Mpy_32_16_1( RZ0[i], t_sin[s0_ind] ), L_sub( Mpy_32_16_1( RZ1[i], t_sin[s1_ind] ), - Mpy_32_16_1( RZ2[-i], t_sin[s2_ind] ) ) ) ) ); + Mpy_32_16_1( RZ2[-i], t_sin[s2_ind] ) ) ) ) ); // Qx move32(); } - FOR( ; i < m / 4; ( i++, c0_ind = sub( c0_ind, step2 ), s0_ind = add( s0_ind, step2 ), c1_ind = add( c1_ind, step2 ), s1_ind = sub( s1_ind, step2 ), c2_ind = add( c2_ind, step2 ), s2_ind = sub( s2_ind, step2 ) ) ) + FOR( ; i < m / 4; ( i++, c0_ind = ( c0_ind - step2 ), s0_ind = ( s0_ind + step2 ), c1_ind = ( c1_ind + step2 ), s1_ind = ( s1_ind - step2 ), c2_ind = ( c2_ind + step2 ), s2_ind = ( s2_ind - step2 ) ) ) { RY2[i] = L_add( Mpy_32_16_1( RZ0[i], t_sin[c0_ind] ), L_sub( Mpy_32_16_1( RZ1[i], t_sin[c1_ind] ), L_sub( L_add( Mpy_32_16_1( RZ2[-i], t_sin[c2_ind] ), Mpy_32_16_1( IZ0[-i], t_sin[s0_ind] ) ), L_add( Mpy_32_16_1( IZ1[-i], t_sin[s1_ind] ), - Mpy_32_16_1( IZ2[i], t_sin[s2_ind] ) ) ) ) ); + Mpy_32_16_1( IZ2[i], t_sin[s2_ind] ) ) ) ) ); // Qx move32(); IY2[-i] = L_add( Mpy_32_16_1( IZ0[-i], t_sin[c0_ind] ), L_add( Mpy_32_16_1( IZ1[-i], t_sin[c1_ind] ), L_add( Mpy_32_16_1( IZ2[i], t_sin[c2_ind] ), L_sub( Mpy_32_16_1( RZ0[i], t_sin[s0_ind] ), L_sub( Mpy_32_16_1( RZ1[i], t_sin[s1_ind] ), - Mpy_32_16_1( RZ2[-i], t_sin[s2_ind] ) ) ) ) ) ); + Mpy_32_16_1( RZ2[-i], t_sin[s2_ind] ) ) ) ) ) ); // Qx move32(); } - FOR( ; i < i_mult( 3, shr( m, 3 ) ); ( i++, c0_ind = sub( c0_ind, step2 ), s0_ind = add( s0_ind, step2 ), c1_ind = add( c1_ind, step2 ), s1_ind = sub( s1_ind, step2 ), c2_ind = sub( c2_ind, step2 ), s2_ind = add( s2_ind, step2 ) ) ) + FOR( ; i < ( 3 * ( m >> 3 ) ); ( i++, c0_ind = ( c0_ind - step2 ), s0_ind = ( s0_ind + step2 ), c1_ind = ( c1_ind + step2 ), s1_ind = ( s1_ind - step2 ), c2_ind = ( c2_ind - step2 ), s2_ind = ( s2_ind + step2 ) ) ) { RY2[i] = L_sub( L_add( Mpy_32_16_1( RZ0[i], t_sin[c0_ind] ), Mpy_32_16_1( RZ1[i], t_sin[c1_ind] ) ), L_sub( L_add( Mpy_32_16_1( RZ2[-i], t_sin[c2_ind] ), Mpy_32_16_1( IZ0[-i], t_sin[s0_ind] ) ), L_sub( Mpy_32_16_1( IZ1[-i], t_sin[s1_ind] ), - Mpy_32_16_1( IZ2[i], t_sin[s2_ind] ) ) ) ); + Mpy_32_16_1( IZ2[i], t_sin[s2_ind] ) ) ) ); // Qx move32(); IY2[-i] = L_sub( L_add( Mpy_32_16_1( IZ0[-i], t_sin[c0_ind] ), L_add( Mpy_32_16_1( IZ1[-i], t_sin[c1_ind] ), L_add( Mpy_32_16_1( IZ2[i], t_sin[c2_ind] ), Mpy_32_16_1( RZ0[i], t_sin[s0_ind] ) ) ) ), L_add( Mpy_32_16_1( RZ1[i], t_sin[s1_ind] ), - Mpy_32_16_1( RZ2[-i], t_sin[s2_ind] ) ) ); + Mpy_32_16_1( RZ2[-i], t_sin[s2_ind] ) ) ); // Qx move32(); } - FOR( ; i < m / 2; ( i++, c0_ind = add( c0_ind, step2 ), s0_ind = sub( s0_ind, step2 ), c1_ind = add( c1_ind, step2 ), s1_ind = sub( s1_ind, step2 ), c2_ind = sub( c2_ind, step2 ), s2_ind = add( s2_ind, step2 ) ) ) + FOR( ; i < m / 2; ( i++, c0_ind = ( c0_ind + step2 ), s0_ind = ( s0_ind - step2 ), c1_ind = ( c1_ind + step2 ), s1_ind = ( s1_ind - step2 ), c2_ind = ( c2_ind - step2 ), s2_ind = ( s2_ind + step2 ) ) ) { RY2[i] = L_sub( L_sub( Mpy_32_16_1( RZ1[i], t_sin[c1_ind] ), Mpy_32_16_1( RZ0[i], t_sin[c0_ind] ) ), L_sub( L_add( Mpy_32_16_1( RZ2[-i], t_sin[c2_ind] ), Mpy_32_16_1( IZ0[-i], t_sin[s0_ind] ) ), L_sub( Mpy_32_16_1( IZ1[-i], t_sin[s1_ind] ), - Mpy_32_16_1( IZ2[i], t_sin[s2_ind] ) ) ) ); + Mpy_32_16_1( IZ2[i], t_sin[s2_ind] ) ) ) ); // Qx move32(); IY2[-i] = L_add( L_sub( Mpy_32_16_1( IZ1[-i], t_sin[c1_ind] ), Mpy_32_16_1( IZ0[-i], t_sin[c0_ind] ) ), L_sub( L_add( Mpy_32_16_1( IZ2[i], t_sin[c2_ind] ), Mpy_32_16_1( RZ0[i], t_sin[s0_ind] ) ), L_add( Mpy_32_16_1( RZ1[i], t_sin[s1_ind] ), - Mpy_32_16_1( RZ2[-i], t_sin[s2_ind] ) ) ) ); + Mpy_32_16_1( RZ2[-i], t_sin[s2_ind] ) ) ) ); // Qx move32(); } @@ -3298,7 +3304,7 @@ void ifft3_fx_ivas( L_sub( L_add( Mpy_32_16_1( RZ2[-i], t_sin[c2_ind] ), Mpy_32_16_1( IZ0[-i], t_sin[s0_ind] ) ), L_sub( Mpy_32_16_1( IZ1[-i], t_sin[s1_ind] ), - Mpy_32_16_1( IZ2[i], t_sin[s2_ind] ) ) ) ); + Mpy_32_16_1( IZ2[i], t_sin[s2_ind] ) ) ) ); // Qx move32(); /* Compute the inverse FFT for all 3 blocks. */ @@ -3311,16 +3317,16 @@ void ifft3_fx_ivas( y2 = RY2; /* Interlacing and scaling, scale = 1/3 */ - scale = (Word16) ( 0x2AAB ); + scale = extract_l( 0x2AAB /*(1/3).Q15*/ ); FOR( i = 0; i < n; ) { - X[i] = Mpy_32_16_1( ( *y0++ ), scale ); + X[i] = Mpy_32_16_1( ( *y0++ ), scale ); // Qx move32(); i = add( i, 1 ); - X[i] = Mpy_32_16_1( ( *y1++ ), scale ); + X[i] = Mpy_32_16_1( ( *y1++ ), scale ); // Qx move32(); i = add( i, 1 ); - X[i] = Mpy_32_16_1( ( *y2++ ), scale ); + X[i] = Mpy_32_16_1( ( *y2++ ), scale ); // Qx move32(); i = add( i, 1 ); } @@ -3330,8 +3336,8 @@ void ifft3_fx_ivas( static void rfft_post( - const Word16 *sine_table, - Word32 *buf, + const Word16 *sine_table, // Q15 + Word32 *buf, // hFdCngCom->fftBuffer_exp(Qx) const Word16 len ) { Word32 tmp1, tmp2, tmp3, tmp4; @@ -3345,68 +3351,69 @@ static void rfft_post( buf[0] = tmp1; move32(); - FOR( i = 1; i <= shr( add( len, 2 ), 2 ); i++ ) + FOR( i = 1; i <= ( ( len + 2 ) >> 2 ); i++ ) { - s = sine_table[i]; /* sin(pi*i/(len/2)) */ + s = sine_table[i]; /* sin(pi*i/(len/2)) Q15*/ move16(); - c = sine_table[add( i, shr( len, 2 ) )]; /* cos(pi*i/(len/2)) */ + c = sine_table[( i + ( len >> 2 ) )]; /* cos(pi*i/(len/2)) Q15*/ move16(); - tmp1 = L_sub( buf[2 * i], buf[sub( len, shl( i, 1 ) )] ); - tmp2 = L_add( buf[add( shl( i, 1 ), 1 )], buf[add( sub( len, shl( i, 1 ) ), 1 )] ); - tmp3 = L_sub( Mpy_32_16_1( tmp1, s ), Mpy_32_16_1( tmp2, c ) ); /* real part of j*W(k,N)*[T(k) - T'(N-k)] */ - tmp4 = L_add( Mpy_32_16_1( tmp1, c ), Mpy_32_16_1( tmp2, s ) ); /* imag part of j*W(k,N)*[T(k) - T'(N-k)] */ - tmp1 = L_add( buf[2 * i], buf[sub( len, shl( i, 1 ) )] ); - tmp2 = L_sub( buf[add( shl( i, 1 ), 1 )], buf[add( sub( len, shl( i, 1 ) ), 1 )] ); + tmp1 = L_sub( buf[2 * i], buf[( len - ( i << 1 ) )] ); + tmp2 = L_add( buf[( ( i << 1 ) + 1 )], buf[( ( len - ( i << 1 ) ) + 1 )] ); + tmp3 = L_sub( Mpy_32_16_1( tmp1, s ), Mpy_32_16_1( tmp2, c ) ); /* real part of j*W(k,N)*[T(k) - T'(N-k)] Qx*/ + tmp4 = L_add( Mpy_32_16_1( tmp1, c ), Mpy_32_16_1( tmp2, s ) ); /* imag part of j*W(k,N)*[T(k) - T'(N-k)] Qx*/ + tmp1 = L_add( buf[2 * i], buf[( len - ( i << 1 ) )] ); + tmp2 = L_sub( buf[( ( i << 1 ) + 1 )], buf[( ( len - ( i << 1 ) ) + 1 )] ); buf[2 * i] = L_shr( L_sub( tmp1, tmp3 ), 1 ); move32(); - buf[add( shl( i, 1 ), 1 )] = L_shr( L_sub( tmp2, tmp4 ), 1 ); + buf[( ( i << 1 ) + 1 )] = L_shr( L_sub( tmp2, tmp4 ), 1 ); move32(); - buf[sub( len, shl( i, 1 ) )] = L_shr( L_add( tmp1, tmp3 ), 1 ); + buf[( len - ( i << 1 ) )] = L_shr( L_add( tmp1, tmp3 ), 1 ); move32(); - buf[add( sub( len, shl( i, 1 ) ), 1 )] = L_negate( L_shr( L_add( tmp2, tmp4 ), 1 ) ); + buf[( ( len - ( i << 1 ) ) + 1 )] = L_negate( L_shr( L_add( tmp2, tmp4 ), 1 ) ); move32(); } } static void rfft_pre( - const Word16 *sine_table, - Word32 *buf, - const Word16 len ) + const Word16 *sine_table, // Q15 + Word32 *buf, // hFdCngCom->fftBuffer_exp (Qx) + const Word16 len // Q0 +) { - const Word16 scale = (Word16) ( 1.0f / len * 32768.0 ); + const Word16 scale = ( div_s( 1, len ) ); // Q15 Word32 tmp1, tmp2, tmp3, tmp4; Word16 s, c; Word16 i = 0; - tmp1 = L_add( buf[0], buf[1] ); - buf[1] = Mpy_32_16_1( L_sub( buf[0], buf[1] ), scale ); + tmp1 = L_add( buf[0], buf[1] ); // Qx + buf[1] = Mpy_32_16_1( L_sub( buf[0], buf[1] ), scale ); // Qx move32(); - buf[0] = Mpy_32_16_1( tmp1, scale ); + buf[0] = Mpy_32_16_1( tmp1, scale ); // Qx move32(); - FOR( i = 1; i <= shr( add( len, 2 ), 2 ); i++ ) + FOR( i = 1; i <= ( ( len + 2 ) >> 2 ); i++ ) { - s = sine_table[i]; /* sin(pi*i/(len/2)) */ + s = sine_table[i]; /* sin(pi*i/(len/2)) Q15*/ move16(); - c = sine_table[add( i, shr( len, 2 ) )]; /* cos(pi*i/(len/2)) */ + c = sine_table[( i + ( len >> 2 ) )]; /* cos(pi*i/(len/2)) Q15*/ move16(); - tmp1 = L_sub( buf[2 * i], buf[sub( len, shl( i, 1 ) )] ); - tmp2 = L_add( buf[add( shl( i, 1 ), 1 )], buf[add( sub( len, shl( i, 1 ) ), 1 )] ); - tmp3 = L_add( Mpy_32_16_1( tmp1, s ), Mpy_32_16_1( tmp2, c ) ); /* real part of j*W(k,N)*[T(k) - T'(N-k)] */ - tmp4 = L_sub( Mpy_32_16_1( tmp2, s ), Mpy_32_16_1( tmp1, c ) ); /* imag part of j*W(k,N)*[T(k) - T'(N-k)] */ - tmp1 = L_add( buf[2 * i], buf[sub( len, shl( i, 1 ) )] ); - tmp2 = L_sub( buf[add( shl( i, 1 ), 1 )], buf[add( sub( len, shl( i, 1 ) ), 1 )] ); + tmp1 = L_sub( buf[2 * i], buf[( len - ( i << 1 ) )] ); // Qx + tmp2 = L_add( buf[( ( i << 1 ) + 1 )], buf[( ( len - ( i << 1 ) ) + 1 )] ); // Qx + tmp3 = L_add( Mpy_32_16_1( tmp1, s ), Mpy_32_16_1( tmp2, c ) ); /* real part of j*W(k,N)*[T(k) - T'(N-k)] Qx*/ + tmp4 = L_sub( Mpy_32_16_1( tmp2, s ), Mpy_32_16_1( tmp1, c ) ); /* imag part of j*W(k,N)*[T(k) - T'(N-k)] Qx*/ + tmp1 = L_add( buf[2 * i], buf[( len - ( i << 1 ) )] ); // Qx + tmp2 = L_sub( buf[( ( i << 1 ) + 1 )], buf[( ( len - ( i << 1 ) ) + 1 )] ); // Qx - buf[2 * i] = Mpy_32_16_1( L_add( tmp1, tmp3 ), scale ); + buf[2 * i] = Mpy_32_16_1( L_add( tmp1, tmp3 ), scale ); // Qx move32(); - buf[add( shl( i, 1 ), 1 )] = L_negate( Mpy_32_16_1( L_add( tmp2, tmp4 ), scale ) ); + buf[( ( i << 1 ) + 1 )] = L_negate( Mpy_32_16_1( L_add( tmp2, tmp4 ), scale ) ); // Qx move32(); - buf[sub( len, shl( i, 1 ) )] = Mpy_32_16_1( L_sub( tmp1, tmp3 ), scale ); + buf[( len - ( i << 1 ) )] = Mpy_32_16_1( L_sub( tmp1, tmp3 ), scale ); // Qx move32(); - buf[add( sub( len, shl( i, 1 ) ), 1 )] = Mpy_32_16_1( L_sub( tmp2, tmp4 ), scale ); + buf[( ( len - ( i << 1 ) ) + 1 )] = Mpy_32_16_1( L_sub( tmp2, tmp4 ), scale ); // Qx move32(); } @@ -3414,9 +3421,9 @@ static void rfft_pre( } Word16 RFFTN_fx( - Word32 *data, - const Word16 *sine_table, - const Word16 len, + Word32 *data, // hFdCngCom->fftBuffer_exp (Qx) + const Word16 *sine_table, // Q15 + const Word16 len, // Q0 const Word16 sign ) { assert( len <= 640 && len > 0 ); @@ -3435,7 +3442,7 @@ Word16 RFFTN_fx( { x[i] = data[2 * i]; move32(); - y[i] = data[add( shl( i, 1 ), 1 )]; + y[i] = data[( ( i << 1 ) + 1 )]; move32(); } DoRTFT320_fx( x, y ); @@ -3443,7 +3450,7 @@ Word16 RFFTN_fx( { data[2 * i] = x[i]; move32(); - data[add( shl( i, 1 ), 1 )] = y[i]; + data[( ( i << 1 ) + 1 )] = y[i]; move32(); } @@ -3472,7 +3479,7 @@ Word16 RFFTN_fx( { reordered_data[2 * i] = data[i]; move32(); - reordered_data[add( shl( i, 1 ), 1 )] = data[sub( len, i )]; + reordered_data[( ( i << 1 ) + 1 )] = data[( len - i )]; move32(); } } @@ -3486,7 +3493,7 @@ Word16 RFFTN_fx( { reordered_data[i] = data[2 * i]; move32(); - reordered_data[sub( len, i )] = data[add( shl( i, 1 ), 1 )]; + reordered_data[( len - i )] = data[( ( i << 1 ) + 1 )]; move32(); } ifft_rel_fx32( reordered_data, len, log2 ); @@ -3503,10 +3510,11 @@ Word16 RFFTN_fx( } static void butterfly( - const Word32 a, - const Word32 b, - Word32 *aPlusb, - Word32 *aMinusb ) + const Word32 a, // Qx + const Word32 b, // Qx + Word32 *aPlusb, // Qx + Word32 *aMinusb // Qx +) { *aPlusb = L_add( a, b ); move32(); @@ -3517,7 +3525,8 @@ static void butterfly( } static void fft2( - Word32 *pInOut ) + Word32 *pInOut // Qx +) { /* FFT MATRIX: 1.0000 1.0000 @@ -3550,7 +3559,7 @@ static void fft2( static const Word16 C31 = 0x4000; /*0.5f in Q15 cos(PI/3); sin(2*PI/3) */ static const Word16 C32 = 0x6ED9; /*0.866025403784439f in Q15 cos(PI/3); sin(2*PI/3) */ -static void fft3_2( Word32 *pInOut ) +static void fft3_2( Word32 *pInOut /*Qx*/ ) { Word32 re1, im1; Word32 re2, im2; @@ -3559,17 +3568,17 @@ static void fft3_2( Word32 *pInOut ) Word32 tmp1, tmp2; Word32 tmp3, tmp4; - re1 = pInOut[0]; + re1 = pInOut[0]; // Qx move32(); - im1 = pInOut[1]; + im1 = pInOut[1]; // Qx move32(); - re2 = pInOut[2]; + re2 = pInOut[2]; // Qx move32(); - im2 = pInOut[3]; + im2 = pInOut[3]; // Qx move32(); - re3 = pInOut[4]; + re3 = pInOut[4]; // Qx move32(); - im3 = pInOut[5]; + im3 = pInOut[5]; // Qx move32(); /* FFT MATRIX: @@ -3586,20 +3595,20 @@ static void fft3_2( Word32 *pInOut ) move32(); pInOut[1] = L_add( im1, tmp3 ); move32(); - pInOut[2] = L_sub( re1, L_sub( Mpy_32_16_1( tmp1, C31 ), Mpy_32_16_1( tmp4, C32 ) ) ); + pInOut[2] = L_sub( re1, L_sub( Mpy_32_16_1( tmp1, C31 ), Mpy_32_16_1( tmp4, C32 ) ) ); // Qx move32(); - pInOut[4] = L_sub( re1, L_add( Mpy_32_16_1( tmp1, C31 ), Mpy_32_16_1( tmp4, C32 ) ) ); + pInOut[4] = L_sub( re1, L_add( Mpy_32_16_1( tmp1, C31 ), Mpy_32_16_1( tmp4, C32 ) ) ); // Qx move32(); - pInOut[3] = L_sub( im1, L_add( Mpy_32_16_1( tmp2, C32 ), Mpy_32_16_1( tmp3, C31 ) ) ); + pInOut[3] = L_sub( im1, L_add( Mpy_32_16_1( tmp2, C32 ), Mpy_32_16_1( tmp3, C31 ) ) ); // Qx move32(); - pInOut[5] = L_add( im1, L_sub( Mpy_32_16_1( tmp2, C32 ), Mpy_32_16_1( tmp3, C31 ) ) ); + pInOut[5] = L_add( im1, L_sub( Mpy_32_16_1( tmp2, C32 ), Mpy_32_16_1( tmp3, C31 ) ) ); // Qx move32(); } static void fft4( - Word32 *pInOut ) + Word32 *pInOut /*Qx*/ ) { Word32 re1, im1; Word32 re2, im2; @@ -3664,13 +3673,13 @@ static void fft4( return; } -static const Word16 C51 = 0x278D; /* 0.309016994374947f cos(2*PI/5); */ -static const Word16 C52 = 0x79bc; /* 0.951056516295154f sin(2*PI/5); */ -static const Word16 C53 = 0x678D; /* 0.809016994374947f cos( PI/5); */ -static const Word16 C54 = 0x4B3D; /* 0.587785252292473f sin( PI/5); */ +static const Word16 C51 = 0x278D; /* 0.309016994374947f cos(2*PI/5); Q15*/ +static const Word16 C52 = 0x79bc; /* 0.951056516295154f sin(2*PI/5); Q15*/ +static const Word16 C53 = 0x678D; /* 0.809016994374947f cos( PI/5); Q15*/ +static const Word16 C54 = 0x4B3D; /* 0.587785252292473f sin( PI/5); Q15*/ static void fft5( - cmplx *pInOut ) + cmplx *pInOut /*Qx*/ ) { cmplx x[5]; cmplx t[4]; @@ -3707,22 +3716,22 @@ static void fft5( pInOut[0] = CL_add( x[0], CL_add( t[0], t[2] ) ); move32(); - pInOut[1] = CL_add( CL_add( x[0], CL_sub( CL_scale( t[0], C51 ), CL_scale( t[2], C53 ) ) ), CL_add( CL_conjugate( CL_scale( CL_swap_real_imag( t[1] ), C52 ) ), CL_conjugate( CL_scale( CL_swap_real_imag( t[3] ), C54 ) ) ) ); + pInOut[1] = CL_add( CL_add( x[0], CL_sub( CL_scale( t[0], C51 ), CL_scale( t[2], C53 ) ) ), CL_add( CL_conjugate( CL_scale( CL_swap_real_imag( t[1] ), C52 ) ), CL_conjugate( CL_scale( CL_swap_real_imag( t[3] ), C54 ) ) ) ); // Qx move32(); - pInOut[4] = CL_add( x[0], CL_sub( CL_scale( t[0], C51 ), CL_add( CL_scale( t[2], C53 ), CL_add( CL_conjugate( CL_scale( CL_swap_real_imag( t[1] ), C52 ) ), CL_conjugate( CL_scale( CL_swap_real_imag( t[3] ), C54 ) ) ) ) ) ); + pInOut[4] = CL_add( x[0], CL_sub( CL_scale( t[0], C51 ), CL_add( CL_scale( t[2], C53 ), CL_add( CL_conjugate( CL_scale( CL_swap_real_imag( t[1] ), C52 ) ), CL_conjugate( CL_scale( CL_swap_real_imag( t[3] ), C54 ) ) ) ) ) ); // Qx move32(); - pInOut[2] = CL_add( CL_sub( x[0], CL_scale( t[0], C53 ) ), CL_add( CL_scale( t[2], C51 ), CL_sub( CL_conjugate( CL_scale( CL_swap_real_imag( t[1] ), C54 ) ), CL_conjugate( CL_scale( CL_swap_real_imag( t[3] ), C52 ) ) ) ) ); + pInOut[2] = CL_add( CL_sub( x[0], CL_scale( t[0], C53 ) ), CL_add( CL_scale( t[2], C51 ), CL_sub( CL_conjugate( CL_scale( CL_swap_real_imag( t[1] ), C54 ) ), CL_conjugate( CL_scale( CL_swap_real_imag( t[3] ), C52 ) ) ) ) ); // Qx move32(); - pInOut[3] = CL_add( CL_sub( x[0], CL_scale( t[0], C53 ) ), CL_add( CL_sub( CL_scale( t[2], C51 ), CL_conjugate( CL_scale( CL_swap_real_imag( t[1] ), C54 ) ) ), CL_conjugate( CL_scale( CL_swap_real_imag( t[3] ), C52 ) ) ) ); + pInOut[3] = CL_add( CL_sub( x[0], CL_scale( t[0], C53 ) ), CL_add( CL_sub( CL_scale( t[2], C51 ), CL_conjugate( CL_scale( CL_swap_real_imag( t[1] ), C54 ) ) ), CL_conjugate( CL_scale( CL_swap_real_imag( t[3] ), C52 ) ) ) ); // Qx move32(); return; } -static const Word16 C81 = 0x5a82; /* 0.707106781186548f cos(PI/4); */ +static const Word16 C81 = 0x5a82; /* 0.707106781186548f cos(PI/4); Q15*/ static void fft8_2( - Word32 *pInOut ) + Word32 *pInOut /*Qx*/ ) { Word32 re0, im0, re4, im4; @@ -3802,8 +3811,8 @@ static void fft8_2( } static void nextFFT( - Word32 *x, - const Word16 length ) + Word32 *x, /*Qx*/ + const Word16 length /*Qx*/ ) { cmplx val[5]; SWITCH( length ) @@ -3822,7 +3831,7 @@ static void nextFFT( { val[i].re = x[2 * i]; move32(); - val[i].im = x[add( shl( i, 1 ), 1 )]; + val[i].im = x[( ( i << 1 ) + 1 )]; move32(); } fft5( val ); @@ -3830,7 +3839,7 @@ static void nextFFT( { x[2 * i] = val[i].re; move32(); - x[add( shl( i, 1 ), 1 )] = val[i].im; + x[( ( i << 1 ) + 1 )] = val[i].im; move32(); } BREAK; @@ -3863,20 +3872,20 @@ static __inline Word16 findFactor( move16(); BREAK; } - i = add( i, 1 ); + i += 1; } return factor; } static __inline void twiddle( - Word32 *x, + Word32 *x, // Qx const Word16 length, const Word16 n1, const Word16 n2 ) { Word16 i, ii; - const Word16 *ptr_sin = &sin_twiddle_table_25_5_5[0]; - const Word16 *ptr_cos = &cos_twiddle_table_25_5_5[0]; + const Word16 *ptr_sin = &sin_twiddle_table_25_5_5[0]; // Q15 + const Word16 *ptr_cos = &cos_twiddle_table_25_5_5[0]; // Q15 test(); test(); @@ -3884,8 +3893,8 @@ static __inline void twiddle( test(); IF( EQ_16( length, 16 ) && EQ_16( n1, 8 ) && EQ_16( n2, 2 ) ) { - ptr_sin = &sin_twiddle_table_16_8_2[0]; - ptr_cos = &cos_twiddle_table_16_8_2[0]; + ptr_sin = &sin_twiddle_table_16_8_2[0]; // Q15 + ptr_cos = &cos_twiddle_table_16_8_2[0]; // Q15 } ELSE IF( NE_16( length, 25 ) || NE_16( n1, 5 ) || NE_16( n2, 5 ) ) { @@ -3897,11 +3906,11 @@ static __inline void twiddle( FOR( ii = 1; ii < n2; ii++ ) { Word32 xRe, xIm; - xRe = x[shl( ( add( i_mult( i, n2 ), ii ) ), 1 )]; - xIm = x[add( shl( ( add( i_mult( i, n2 ), ii ) ), 1 ), 1 )]; - x[shl( ( add( i_mult( i, n2 ), ii ) ), 1 )] = L_sub( Mpy_32_16_1( xRe, ptr_cos[add( i_mult( i, n2 ), ii )] ), Mpy_32_16_1( xIm, ptr_sin[add( i_mult( i, n2 ), ii )] ) ); + xRe = x[( ( ( ( i * n2 ) + ii ) ) << 1 )]; // Qx + xIm = x[( ( ( ( ( i * n2 ) + ii ) ) << 1 ) + 1 )]; // Qx + x[( ( ( ( i * n2 ) + ii ) ) << 1 )] = L_sub( Mpy_32_16_1( xRe, ptr_cos[( ( i * n2 ) + ii )] ), Mpy_32_16_1( xIm, ptr_sin[( ( i * n2 ) + ii )] ) ); // Qx move32(); - x[add( shl( ( add( i_mult( i, n2 ), ii ) ), 1 ), 1 )] = L_add( Mpy_32_16_1( xRe, ptr_sin[add( i_mult( i, n2 ), ii )] ), Mpy_32_16_1( xIm, ptr_cos[add( i_mult( i, n2 ), ii )] ) ); + x[( ( ( ( ( i * n2 ) + ii ) ) << 1 ) + 1 )] = L_add( Mpy_32_16_1( xRe, ptr_sin[( ( i * n2 ) + ii )] ), Mpy_32_16_1( xIm, ptr_cos[( ( i * n2 ) + ii )] ) ); // Qx move32(); } } @@ -3909,9 +3918,10 @@ static __inline void twiddle( } static void cooleyTukeyFFT( - Word32 *x, + Word32 *x, // Qx const Word16 length, - Word32 *scratch ) + Word32 *scratch // Qx +) { Word16 factor; Word16 i, ii; @@ -3937,9 +3947,9 @@ static void cooleyTukeyFFT( case 5: FOR( i = 0; i < 5; i++ ) { - val[i].re = x[2 * i]; + val[i].re = x[2 * i]; // Qx move32(); - val[i].im = x[add( shl( i, 1 ), 1 )]; + val[i].im = x[( ( i << 1 ) + 1 )]; // Qx move32(); } fft5( val ); @@ -3947,7 +3957,7 @@ static void cooleyTukeyFFT( { x[2 * i] = val[i].re; move32(); - x[add( shl( i, 1 ), 1 )] = val[i].im; + x[( ( i << 1 ) + 1 )] = val[i].im; move32(); } BREAK; @@ -3958,14 +3968,14 @@ static void cooleyTukeyFFT( { factor = findFactor( length ); - IF( GT_16( factor, 0 ) && GT_16( idiv1616( length, factor ), 1 ) ) + IF( ( factor > 0 ) && GT_16( idiv1616( length, factor ), 1 ) ) { n1 = factor; move16(); n2 = idiv1616( length, factor ); /* DATA Resorting for stage1 */ - dest = scratch; + dest = scratch; // Qx FOR( i = 0; i < 2 * n1; i += 2 ) { src = x + i; @@ -3980,7 +3990,7 @@ static void cooleyTukeyFFT( src += 2 * n1; } } - src = scratch; + src = scratch; // Qx dest = x; FOR( i = 0; i < length; i++ ) { @@ -4003,9 +4013,9 @@ static void cooleyTukeyFFT( { FOR( ii = 0; ii < n1; ii++ ) { - scratch[2 * cnt] = x[shl( add( i, i_mult( ii, n2 ) ), 1 )]; + scratch[2 * cnt] = x[( ( i + ( ii * n2 ) ) << 1 )]; move32(); - scratch[add( shl( cnt, 1 ), 1 )] = x[add( shl( add( i, i_mult( ii, n2 ) ), 1 ), 1 )]; + scratch[( ( cnt << 1 ) + 1 )] = x[( ( ( i + ( ii * n2 ) ) << 1 ) + 1 )]; move32(); cnt = add( cnt, 1 ); } @@ -4021,9 +4031,9 @@ static void cooleyTukeyFFT( { FOR( ii = 0; ii < n2; ii++ ) { - x[2 * cnt] = scratch[shl( add( i, i_mult( ii, n1 ) ), 1 )]; + x[2 * cnt] = scratch[( ( i + ( ii * n1 ) ) << 1 )]; move32(); - x[add( shl( cnt, 1 ), 1 )] = scratch[add( shl( add( i, i_mult( ii, n1 ) ), 1 ), 1 )]; + x[( ( cnt << 1 ) + 1 )] = scratch[( ( ( i + ( ii * n1 ) ) << 1 ) + 1 )]; move32(); cnt = add( cnt, 1 ); } @@ -4040,9 +4050,9 @@ static void cooleyTukeyFFT( } static void pfaDFT( - Word32 *x, - const Word16 length, - Word32 *scratch1, + Word32 *x, // Qx + const Word16 length, // Q0 + Word32 *scratch1, // Qx const Word16 numFactors, const Word16 *factor ) { @@ -4060,17 +4070,17 @@ static void pfaDFT( Word16 n1 = idiv1616( length, n2 ); Word16 idx, incr; - WHILE( ( i_mult( n1_inv, n1 ) % n2 ) != 1 ) + WHILE( ( ( n1_inv * n1 ) % n2 ) != 1 ) { n1_inv = add( n1_inv, 1 ); } - WHILE( ( i_mult( n2_inv, n2 ) % n1 ) != 1 ) + WHILE( ( ( n2_inv * n2 ) % n1 ) != 1 ) { n2_inv = add( n2_inv, 1 ); } idx = 0; move16(); - incr = i_mult( n1, n1_inv ); + incr = ( n1 * n1_inv ); move16(); cnt = 0; move16(); @@ -4081,7 +4091,7 @@ static void pfaDFT( tmp[cnt] = x[2 * idx]; move32(); cnt = add( cnt, 1 ); - tmp[cnt] = x[add( shl( idx, 1 ), 1 )]; + tmp[cnt] = x[( ( idx << 1 ) + 1 )]; // Qx move32(); cnt = add( cnt, 1 ); @@ -4092,10 +4102,10 @@ static void pfaDFT( idx = sub( idx, length ); } } - tmp[cnt] = x[2 * idx]; + tmp[cnt] = x[2 * idx]; // Qx move32(); cnt = add( cnt, 1 ); - tmp[cnt] = x[add( shl( idx, 1 ), 1 )]; + tmp[cnt] = x[( ( idx << 1 ) + 1 )]; // Qx move32(); cnt = add( cnt, 1 ); idx = add( idx, 1 ); @@ -4108,9 +4118,9 @@ static void pfaDFT( { FOR( i = 0; i < n2; i++ ) { - x[shl( add( cnt, i_mult( i, n1 ) ), 1 )] = tmp[shl( add( i_mult( cnt, n2 ), i ), 1 )]; + x[( ( cnt + ( i * n1 ) ) << 1 )] = tmp[( ( ( cnt * n2 ) + i ) << 1 )]; move32(); - x[add( shl( add( cnt, i_mult( i, n1 ) ), 1 ), 1 )] = tmp[add( shl( add( i_mult( cnt, n2 ), i ), 1 ), 1 )]; + x[( ( ( cnt + ( i * n1 ) ) << 1 ) + 1 )] = tmp[( ( ( ( cnt * n2 ) + i ) << 1 ) + 1 )]; move32(); } } @@ -4130,7 +4140,7 @@ static void pfaDFT( tmp[2 * idx] = x[cnt]; move32(); cnt = add( cnt, 1 ); - tmp[add( shl( idx, 1 ), 1 )] = x[cnt]; + tmp[( ( idx << 1 ) + 1 )] = x[cnt]; move32(); cnt = add( cnt, 1 ); idx = add( idx, n2 ); @@ -4145,7 +4155,7 @@ static void pfaDFT( { x[2 * cnt] = tmp[2 * cnt]; move32(); - x[add( shl( cnt, 1 ), 1 )] = tmp[add( shl( cnt, 1 ), 1 )]; + x[( ( cnt << 1 ) + 1 )] = tmp[( ( cnt << 1 ) + 1 )]; move32(); } } @@ -4158,10 +4168,11 @@ static void pfaDFT( } static void fftf_interleave( - Word32 *re, - Word32 *im, - Word32 *out, - const Word16 len ) + Word32 *re, // Qx + Word32 *im, // Qx + Word32 *out, // Qx + const Word16 len // Q0 +) { Word16 i = 0; move16(); @@ -4178,10 +4189,11 @@ static void fftf_interleave( } static void fftf_deinterleave( - Word32 *in, - Word32 *re, - Word32 *im, - const Word16 len ) + Word32 *in, // Qx + Word32 *re, // Qx + Word32 *im, // Qx + const Word16 len // Q0 +) { Word16 i = 0; move16(); @@ -4198,8 +4210,8 @@ static void fftf_deinterleave( } static void DoRTFT600( - Word32 *x, /* i/o: real part of input and output data */ - Word32 *y /* i/o: imaginary part of input and output data */ + Word32 *x, /* i/o: real part of input and output data Qx*/ + Word32 *y /* i/o: imaginary part of input and output data Qx*/ ) { Word32 scratch[1200], cmplx[1200]; @@ -4216,8 +4228,8 @@ static void DoRTFT600( } static void DoRTFT400( - Word32 *x, /* i/o: real part of input and output data */ - Word32 *y /* i/o: imaginary part of input and output data */ + Word32 *x, /* i/o: real part of input and output data Qx */ + Word32 *y /* i/o: imaginary part of input and output data Qx */ ) { Word32 scratch[800], cmplx[800]; @@ -4234,8 +4246,8 @@ static void DoRTFT400( } static void DoRTFT240( - Word32 *x, /* i/o: real part of input and output data */ - Word32 *y /* i/o: imaginary part of input and output data */ + Word32 *x, /* i/o: real part of input and output data Qx */ + Word32 *y /* i/o: imaginary part of input and output data Qx */ ) { Word32 scratch[480], cmplx[480]; @@ -4252,8 +4264,8 @@ static void DoRTFT240( } static void DoRTFT200( - Word32 *x, /* i/o: real part of input and output data */ - Word32 *y /* i/o: imaginary part of input and output data */ + Word32 *x, /* i/o: real part of input and output data Qx */ + Word32 *y /* i/o: imaginary part of input and output data Qx */ ) { Word32 scratch[400], cmplx[400]; @@ -4269,8 +4281,8 @@ static void DoRTFT200( } static void DoRTFT100( - Word32 *x, /* i/o: real part of input and output data */ - Word32 *y /* i/o: imaginary part of input and output data */ + Word32 *x, /* i/o: real part of input and output data Qx */ + Word32 *y /* i/o: imaginary part of input and output data Qx */ ) { Word32 scratch[200], cmplx[200]; @@ -4287,9 +4299,10 @@ static void DoRTFT100( void DoFFT_fx( - Word32 *re2, - Word32 *im2, - const Word16 length ) + Word32 *re2, // Qx + Word32 *im2, // Qx + const Word16 length // Q0 +) { SWITCH( length ) { @@ -4350,7 +4363,8 @@ void DoFFT_fx( *-----------------------------------------------------------------*/ static void fft_len5( - cmplx *x ) + cmplx *x // Qx +) { cmplx y1, y2, y3, y4; cmplx t; @@ -4359,18 +4373,18 @@ static void fft_len5( y4 = CL_sub( x[1], x[4] ); y3 = CL_add( x[2], x[3] ); y2 = CL_sub( x[2], x[3] ); - t = CL_scale( CL_sub( y1, y3 ), FFT_C54 ); + t = CL_scale( CL_sub( y1, y3 ), FFT_C54 ); // Qx y1 = CL_add( y1, y3 ); x[0] = CL_add( x[0], y1 ); move64(); - y1 = CL_add( x[0], CL_shl( CL_scale( y1, FFT_C55 ), 1 ) ); + y1 = CL_add( x[0], CL_shl( CL_scale( y1, FFT_C55 ), 1 ) ); // Qx y3 = CL_sub( y1, t ); y1 = CL_add( y1, t ); t = CL_scale( CL_add( y4, y2 ), FFT_C51 ); - y4 = CL_add( t, CL_shl( CL_scale( y4, FFT_C52 ), 1 ) ); - y2 = CL_add( t, CL_scale( y2, FFT_C53 ) ); + y4 = CL_add( t, CL_shl( CL_scale( y4, FFT_C52 ), 1 ) ); // Qx + y2 = CL_add( t, CL_scale( y2, FFT_C53 ) ); // Qx x[1] = CL_msu_j( y1, y2 ); move64(); @@ -4385,7 +4399,8 @@ static void fft_len5( } static void fft_len8( - cmplx *x ) + cmplx *x // Qx +) { cmplx t[8], s[8]; @@ -4452,7 +4467,8 @@ static void fft_len8( } static void fft_len10( - cmplx *x ) + cmplx *x // Qx +) { cmplx t; cmplx s[4]; @@ -4466,22 +4482,22 @@ static void fft_len10( move64(); s[1] = CL_sub( x[2], x[8] ); move64(); - t = CL_scale( CL_sub( s[0], s[2] ), FFT_C54 ); + t = CL_scale( CL_sub( s[0], s[2] ), FFT_C54 ); // Qx s[0] = CL_add( s[0], s[2] ); move64(); y[0] = CL_add( x[0], s[0] ); move64(); - s[0] = CL_add( y[0], CL_shl( CL_scale( s[0], FFT_C55 ), 1 ) ); + s[0] = CL_add( y[0], CL_shl( CL_scale( s[0], FFT_C55 ), 1 ) ); // Qx move64(); s[2] = CL_sub( s[0], t ); move64(); s[0] = CL_add( s[0], t ); move64(); - t = CL_scale( CL_add( s[3], s[1] ), FFT_C51 ); + t = CL_scale( CL_add( s[3], s[1] ), FFT_C51 ); // Qx move64(); - s[3] = CL_add( t, CL_shl( CL_scale( s[3], FFT_C52 ), 1 ) ); + s[3] = CL_add( t, CL_shl( CL_scale( s[3], FFT_C52 ), 1 ) ); // Qx move64(); - s[1] = CL_add( t, CL_scale( s[1], FFT_C53 ) ); + s[1] = CL_add( t, CL_scale( s[1], FFT_C53 ) ); // Qx move64(); y[2] = CL_msu_j( s[0], s[1] ); @@ -4501,21 +4517,21 @@ static void fft_len10( move64(); s[1] = CL_sub( x[7], x[3] ); move64(); - t = CL_scale( CL_sub( s[0], s[2] ), FFT_C54 ); + t = CL_scale( CL_sub( s[0], s[2] ), FFT_C54 ); // Qx s[0] = CL_add( s[0], s[2] ); move64(); y[1] = CL_add( x[5], s[0] ); move64(); - s[0] = CL_add( y[1], CL_shl( CL_scale( s[0], FFT_C55 ), 1 ) ); + s[0] = CL_add( y[1], CL_shl( CL_scale( s[0], FFT_C55 ), 1 ) ); // Qx move64(); s[2] = CL_sub( s[0], t ); move64(); s[0] = CL_add( s[0], t ); move64(); - t = CL_scale( CL_add( s[3], s[1] ), FFT_C51 ); - s[3] = CL_add( t, CL_shl( CL_scale( s[3], FFT_C52 ), 1 ) ); + t = CL_scale( CL_add( s[3], s[1] ), FFT_C51 ); // Qx + s[3] = CL_add( t, CL_shl( CL_scale( s[3], FFT_C52 ), 1 ) ); // Qx move64(); - s[1] = CL_add( t, CL_scale( s[1], FFT_C53 ) ); + s[1] = CL_add( t, CL_scale( s[1], FFT_C53 ) ); // Qx move64(); y[3] = CL_msu_j( s[0], s[1] ); @@ -4558,7 +4574,8 @@ static void fft_len10( } static void fft_len15( - cmplx *x ) + cmplx *x // Qx +) { cmplx t; cmplx s[5]; @@ -4572,21 +4589,21 @@ static void fft_len15( move64(); s[1] = CL_sub( x[6], x[9] ); move64(); - t = CL_scale( CL_sub( s[0], s[2] ), FFT_C54 ); + t = CL_scale( CL_sub( s[0], s[2] ), FFT_C54 ); // Qx s[0] = CL_add( s[0], s[2] ); move64(); y[0] = CL_add( x[0], s[0] ); move64(); - s[0] = CL_add( y[0], CL_shl( CL_scale( s[0], FFT_C55 ), 1 ) ); + s[0] = CL_add( y[0], CL_shl( CL_scale( s[0], FFT_C55 ), 1 ) ); // Qx move64(); s[2] = CL_sub( s[0], t ); move64(); s[0] = CL_add( s[0], t ); move64(); - t = CL_scale( CL_add( s[3], s[1] ), FFT_C51 ); - s[3] = CL_add( t, CL_shl( CL_scale( s[3], FFT_C52 ), 1 ) ); + t = CL_scale( CL_add( s[3], s[1] ), FFT_C51 ); // Qx + s[3] = CL_add( t, CL_shl( CL_scale( s[3], FFT_C52 ), 1 ) ); // Qx move64(); - s[1] = CL_add( t, CL_scale( s[1], FFT_C53 ) ); + s[1] = CL_add( t, CL_scale( s[1], FFT_C53 ) ); // Qx move64(); y[1] = CL_msu_j( s[0], s[1] ); @@ -4606,21 +4623,21 @@ static void fft_len15( move64(); s[1] = CL_sub( x[11], x[14] ); move64(); - t = CL_scale( CL_sub( s[0], s[2] ), FFT_C54 ); + t = CL_scale( CL_sub( s[0], s[2] ), FFT_C54 ); // Qx s[0] = CL_add( s[0], s[2] ); move64(); y[5] = CL_add( x[5], s[0] ); move64(); - s[0] = CL_add( y[5], CL_shl( CL_scale( s[0], FFT_C55 ), 1 ) ); + s[0] = CL_add( y[5], CL_shl( CL_scale( s[0], FFT_C55 ), 1 ) ); // Qx move64(); s[2] = CL_sub( s[0], t ); move64(); s[0] = CL_add( s[0], t ); move64(); - t = CL_scale( CL_add( s[3], s[1] ), FFT_C51 ); - s[3] = CL_add( t, CL_shl( CL_scale( s[3], FFT_C52 ), 1 ) ); + t = CL_scale( CL_add( s[3], s[1] ), FFT_C51 ); // Qx + s[3] = CL_add( t, CL_shl( CL_scale( s[3], FFT_C52 ), 1 ) ); // Qx move64(); - s[1] = CL_add( t, CL_scale( s[1], FFT_C53 ) ); + s[1] = CL_add( t, CL_scale( s[1], FFT_C53 ) ); // Qx move64(); y[6] = CL_msu_j( s[0], s[1] ); @@ -4640,21 +4657,21 @@ static void fft_len15( move64(); s[1] = CL_sub( x[1], x[4] ); move64(); - t = CL_scale( CL_sub( s[0], s[2] ), FFT_C54 ); + t = CL_scale( CL_sub( s[0], s[2] ), FFT_C54 ); // Qx s[0] = CL_add( s[0], s[2] ); move64(); y[10] = CL_add( x[10], s[0] ); move64(); - s[0] = CL_add( y[10], CL_shl( CL_scale( s[0], FFT_C55 ), 1 ) ); + s[0] = CL_add( y[10], CL_shl( CL_scale( s[0], FFT_C55 ), 1 ) ); // Qx move64(); s[2] = CL_sub( s[0], t ); move64(); s[0] = CL_add( s[0], t ); move64(); - t = CL_scale( CL_add( s[3], s[1] ), FFT_C51 ); - s[3] = CL_add( t, CL_shl( CL_scale( s[3], FFT_C52 ), 1 ) ); + t = CL_scale( CL_add( s[3], s[1] ), FFT_C51 ); // Qx + s[3] = CL_add( t, CL_shl( CL_scale( s[3], FFT_C52 ), 1 ) ); // Qx move64(); - s[1] = CL_add( t, CL_scale( s[1], FFT_C53 ) ); + s[1] = CL_add( t, CL_scale( s[1], FFT_C53 ) ); // Qx move64(); y[11] = CL_msu_j( s[0], s[1] ); @@ -4668,7 +4685,7 @@ static void fft_len15( s[0] = CL_add( y[5], y[10] ); move64(); - s[1] = CL_scale( CL_sub( y[5], y[10] ), FFT_C31 ); + s[1] = CL_scale( CL_sub( y[5], y[10] ), FFT_C31 ); // Qx move64(); x[0] = CL_add( y[0], s[0] ); move64(); @@ -4682,7 +4699,7 @@ static void fft_len15( s[0] = CL_add( y[6], y[11] ); move64(); - s[1] = CL_scale( CL_sub( y[6], y[11] ), FFT_C31 ); + s[1] = CL_scale( CL_sub( y[6], y[11] ), FFT_C31 ); // Qx move64(); x[6] = CL_add( y[1], s[0] ); move64(); @@ -4696,7 +4713,7 @@ static void fft_len15( s[0] = CL_add( y[7], y[12] ); move64(); - s[1] = CL_scale( CL_sub( y[7], y[12] ), FFT_C31 ); + s[1] = CL_scale( CL_sub( y[7], y[12] ), FFT_C31 ); // Qx move64(); x[12] = CL_add( y[2], s[0] ); move64(); @@ -4710,7 +4727,7 @@ static void fft_len15( s[0] = CL_add( y[8], y[13] ); move64(); - s[1] = CL_scale( CL_sub( y[8], y[13] ), FFT_C31 ); + s[1] = CL_scale( CL_sub( y[8], y[13] ), FFT_C31 ); // Qx move64(); x[3] = CL_add( y[3], s[0] ); move64(); @@ -4724,7 +4741,7 @@ static void fft_len15( s[0] = CL_add( y[9], y[14] ); move64(); - s[1] = CL_scale( CL_sub( y[9], y[14] ), FFT_C31 ); + s[1] = CL_scale( CL_sub( y[9], y[14] ), FFT_C31 ); // Qx move64(); x[9] = CL_add( y[4], s[0] ); move64(); @@ -4740,19 +4757,20 @@ static void fft_len15( } static void fft_len16( - cmplx *x ) + cmplx *x // Qx +) { cmplx s[4]; cmplx t[4]; cmplx y[16]; - s[0] = CL_shr( x[0], SCALEFACTOR16 ); + s[0] = CL_shr( x[0], SCALEFACTOR16 ); // Qx move64(); - s[1] = CL_shr( x[4], SCALEFACTOR16 ); + s[1] = CL_shr( x[4], SCALEFACTOR16 ); // Qx move64(); - s[2] = CL_shr( x[8], SCALEFACTOR16 ); + s[2] = CL_shr( x[8], SCALEFACTOR16 ); // Qx move64(); - s[3] = CL_shr( x[12], SCALEFACTOR16 ); + s[3] = CL_shr( x[12], SCALEFACTOR16 ); // Qx move64(); t[0] = CL_add( s[0], s[2] ); @@ -4773,13 +4791,13 @@ static void fft_len16( y[3] = CL_add( t[1], t[3] ); move64(); - s[0] = CL_shr( x[1], SCALEFACTOR16 ); + s[0] = CL_shr( x[1], SCALEFACTOR16 ); // Qx move64(); - s[1] = CL_shr( x[5], SCALEFACTOR16 ); + s[1] = CL_shr( x[5], SCALEFACTOR16 ); // Qx move64(); - s[2] = CL_shr( x[9], SCALEFACTOR16 ); + s[2] = CL_shr( x[9], SCALEFACTOR16 ); // Qx move64(); - s[3] = CL_shr( x[13], SCALEFACTOR16 ); + s[3] = CL_shr( x[13], SCALEFACTOR16 ); // Qx move64(); t[0] = CL_add( s[0], s[2] ); @@ -4800,13 +4818,13 @@ static void fft_len16( y[7] = CL_add( t[1], t[3] ); move64(); - s[0] = CL_shr( x[2], SCALEFACTOR16 ); + s[0] = CL_shr( x[2], SCALEFACTOR16 ); // Qx move64(); - s[1] = CL_shr( x[6], SCALEFACTOR16 ); + s[1] = CL_shr( x[6], SCALEFACTOR16 ); // Qx move64(); - s[2] = CL_shr( x[10], SCALEFACTOR16 ); + s[2] = CL_shr( x[10], SCALEFACTOR16 ); // Qx move64(); - s[3] = CL_shr( x[14], SCALEFACTOR16 ); + s[3] = CL_shr( x[14], SCALEFACTOR16 ); // Qx move64(); t[0] = CL_add( s[0], s[2] ); @@ -4829,13 +4847,13 @@ static void fft_len16( y[11] = CL_add( t[1], t[3] ); move64(); - s[0] = CL_shr( x[3], SCALEFACTOR16 ); + s[0] = CL_shr( x[3], SCALEFACTOR16 ); // Qx move64(); - s[1] = CL_shr( x[7], SCALEFACTOR16 ); + s[1] = CL_shr( x[7], SCALEFACTOR16 ); // Qx move64(); - s[2] = CL_shr( x[11], SCALEFACTOR16 ); + s[2] = CL_shr( x[11], SCALEFACTOR16 ); // Qx move64(); - s[3] = CL_shr( x[15], SCALEFACTOR16 ); + s[3] = CL_shr( x[15], SCALEFACTOR16 ); // Qx move64(); t[0] = CL_add( s[0], s[2] ); @@ -4856,17 +4874,17 @@ static void fft_len16( y[15] = CL_add( t[1], t[3] ); move64(); - s[0] = CL_scale( y[11], FFT_C162 ); + s[0] = CL_scale( y[11], FFT_C162 ); // Qx move64(); y[11] = CL_mac_j( s[0], s[0] ); move64(); - s[0] = CL_scale( y[14], FFT_C162 ); + s[0] = CL_scale( y[14], FFT_C162 ); // Qx move64(); y[14] = CL_mac_j( s[0], s[0] ); move64(); - s[0] = CL_scale( y[6], FFT_C161 ); + s[0] = CL_scale( y[6], FFT_C161 ); // Qx move64(); y[6] = CL_mac_j( s[0], s[0] ); move64(); @@ -4875,7 +4893,7 @@ static void fft_len16( y[6] = CL_conjugate( y[6] ); move64(); - s[0] = CL_scale( y[9], FFT_C161 ); + s[0] = CL_scale( y[9], FFT_C161 ); // Qx move64(); y[9] = CL_mac_j( s[0], s[0] ); move64(); @@ -4884,30 +4902,30 @@ static void fft_len16( y[9] = CL_conjugate( y[9] ); move64(); - s[0] = CL_scale( y[5], FFT_C163 ); + s[0] = CL_scale( y[5], FFT_C163 ); // Qx move64(); - s[1] = CL_scale( y[5], FFT_C166 ); + s[1] = CL_scale( y[5], FFT_C166 ); // Qx move64(); y[5] = CL_mac_j( s[0], s[1] ); move64(); - s[0] = CL_scale( y[7], FFT_C165 ); + s[0] = CL_scale( y[7], FFT_C165 ); // Qx move64(); - s[1] = CL_scale( y[7], FFT_C164 ); + s[1] = CL_scale( y[7], FFT_C164 ); // Qx move64(); y[7] = CL_mac_j( s[0], s[1] ); move64(); - s[0] = CL_scale( y[13], FFT_C165 ); + s[0] = CL_scale( y[13], FFT_C165 ); // Qx move64(); - s[1] = CL_scale( y[13], FFT_C164 ); + s[1] = CL_scale( y[13], FFT_C164 ); // Qx move64(); y[13] = CL_mac_j( s[0], s[1] ); move64(); - s[0] = CL_scale( y[15], FFT_C164 ); + s[0] = CL_scale( y[15], FFT_C164 ); // Qx move64(); - s[1] = CL_scale( y[15], FFT_C165 ); + s[1] = CL_scale( y[15], FFT_C165 ); // Qx move64(); y[15] = CL_mac_j( s[0], s[1] ); move64(); @@ -4988,7 +5006,8 @@ static void fft_len16( } static void fft_len20_fx( - cmplx *x ) + cmplx *x // Qx +) { cmplx s[4]; cmplx xx[5]; @@ -4996,15 +5015,15 @@ static void fft_len20_fx( cmplx tt[4]; cmplx y[20]; - xx[0] = CL_shr( x[0], SCALEFACTOR20 ); + xx[0] = CL_shr( x[0], SCALEFACTOR20 ); // Qx move64(); - xx[1] = CL_shr( x[16], SCALEFACTOR20 ); + xx[1] = CL_shr( x[16], SCALEFACTOR20 ); // Qx move64(); - xx[2] = CL_shr( x[12], SCALEFACTOR20 ); + xx[2] = CL_shr( x[12], SCALEFACTOR20 ); // Qx move64(); - xx[3] = CL_shr( x[8], SCALEFACTOR20 ); + xx[3] = CL_shr( x[8], SCALEFACTOR20 ); // Qx move64(); - xx[4] = CL_shr( x[4], SCALEFACTOR20 ); + xx[4] = CL_shr( x[4], SCALEFACTOR20 ); // Qx move64(); s[0] = CL_add( xx[1], xx[4] ); @@ -5020,14 +5039,14 @@ static void fft_len20_fx( move64(); y[0] = CL_add( xx[0], s[0] ); move64(); - s[0] = CL_add( y[0], CL_shl( CL_scale( s[0], FFT_C55 ), 1 ) ); + s[0] = CL_add( y[0], CL_shl( CL_scale( s[0], FFT_C55 ), 1 ) ); // Qx move64(); s[2] = CL_sub( s[0], t ); move64(); s[0] = CL_add( s[0], t ); move64(); t = CL_scale( CL_add( s[3], s[1] ), FFT_C51 ); - s[3] = CL_add( t, CL_shl( CL_scale( s[3], FFT_C52 ), 1 ) ); + s[3] = CL_add( t, CL_shl( CL_scale( s[3], FFT_C52 ), 1 ) ); // Qx move64(); s[1] = CL_add( t, CL_scale( s[1], FFT_C53 ) ); move64(); @@ -5065,14 +5084,14 @@ static void fft_len20_fx( move64(); y[1] = CL_add( xx[0], s[0] ); move64(); - s[0] = CL_add( y[1], CL_shl( CL_scale( s[0], FFT_C55 ), 1 ) ); + s[0] = CL_add( y[1], CL_shl( CL_scale( s[0], FFT_C55 ), 1 ) ); // Qx move64(); s[2] = CL_sub( s[0], t ); move64(); s[0] = CL_add( s[0], t ); move64(); t = CL_scale( CL_add( s[3], s[1] ), FFT_C51 ); - s[3] = CL_add( t, CL_shl( CL_scale( s[3], FFT_C52 ), 1 ) ); + s[3] = CL_add( t, CL_shl( CL_scale( s[3], FFT_C52 ), 1 ) ); // Qx move64(); s[1] = CL_add( t, CL_scale( s[1], FFT_C53 ) ); move64(); @@ -5110,14 +5129,14 @@ static void fft_len20_fx( move64(); y[2] = CL_add( xx[0], s[0] ); move64(); - s[0] = CL_add( y[2], CL_shl( CL_scale( s[0], FFT_C55 ), 1 ) ); + s[0] = CL_add( y[2], CL_shl( CL_scale( s[0], FFT_C55 ), 1 ) ); // Qx move64(); s[2] = CL_sub( s[0], t ); move64(); s[0] = CL_add( s[0], t ); move64(); t = CL_scale( CL_add( s[3], s[1] ), FFT_C51 ); - s[3] = CL_add( t, CL_shl( CL_scale( s[3], FFT_C52 ), 1 ) ); + s[3] = CL_add( t, CL_shl( CL_scale( s[3], FFT_C52 ), 1 ) ); // Qx move64(); s[1] = CL_add( t, CL_scale( s[1], FFT_C53 ) ); move64(); @@ -5155,14 +5174,14 @@ static void fft_len20_fx( move64(); y[3] = CL_add( xx[0], s[0] ); move64(); - s[0] = CL_add( y[3], CL_shl( CL_scale( s[0], FFT_C55 ), 1 ) ); + s[0] = CL_add( y[3], CL_shl( CL_scale( s[0], FFT_C55 ), 1 ) ); // Qx move64(); s[2] = CL_sub( s[0], t ); move64(); s[0] = CL_add( s[0], t ); move64(); t = CL_scale( CL_add( s[3], s[1] ), FFT_C51 ); - s[3] = CL_add( t, CL_shl( CL_scale( s[3], FFT_C52 ), 1 ) ); + s[3] = CL_add( t, CL_shl( CL_scale( s[3], FFT_C52 ), 1 ) ); // Qx move64(); s[1] = CL_add( t, CL_scale( s[1], FFT_C53 ) ); move64(); @@ -5270,7 +5289,8 @@ static void fft_len20_fx( } static void fft_len30( - cmplx *x ) + cmplx *x // Qx +) { cmplx t; cmplx s[4]; @@ -5323,20 +5343,20 @@ static void fft_len30( move64(); s[1] = CL_sub( xx[2], xx[3] ); move64(); - t = CL_scale( CL_sub( s[0], s[2] ), FFT_C54 ); + t = CL_scale( CL_sub( s[0], s[2] ), FFT_C54 ); // Qx s[0] = CL_add( s[0], s[2] ); move64(); y[0] = CL_add( xx[0], s[0] ); - s[0] = CL_add( y[0], CL_shl( CL_scale( s[0], FFT_C55 ), 1 ) ); + s[0] = CL_add( y[0], CL_shl( CL_scale( s[0], FFT_C55 ), 1 ) ); // Qx move64(); s[2] = CL_sub( s[0], t ); move64(); s[0] = CL_add( s[0], t ); move64(); t = CL_scale( CL_add( s[3], s[1] ), FFT_C51 ); - s[3] = CL_add( t, CL_shl( CL_scale( s[3], FFT_C52 ), 1 ) ); + s[3] = CL_add( t, CL_shl( CL_scale( s[3], FFT_C52 ), 1 ) ); // Qx move64(); - s[1] = CL_add( t, CL_scale( s[1], FFT_C53 ) ); + s[1] = CL_add( t, CL_scale( s[1], FFT_C53 ) ); // Qx move64(); y[1] = CL_msu_j( s[0], s[1] ); @@ -5361,16 +5381,16 @@ static void fft_len30( move64(); y[5] = CL_add( xx[5], s[0] ); move64(); - s[0] = CL_add( y[5], CL_shl( CL_scale( s[0], FFT_C55 ), 1 ) ); + s[0] = CL_add( y[5], CL_shl( CL_scale( s[0], FFT_C55 ), 1 ) ); // Qx move64(); s[2] = CL_sub( s[0], t ); move64(); s[0] = CL_add( s[0], t ); move64(); t = CL_scale( CL_add( s[3], s[1] ), FFT_C51 ); - s[3] = CL_add( t, CL_shl( CL_scale( s[3], FFT_C52 ), 1 ) ); + s[3] = CL_add( t, CL_shl( CL_scale( s[3], FFT_C52 ), 1 ) ); // Qx move64(); - s[1] = CL_add( t, CL_scale( s[1], FFT_C53 ) ); + s[1] = CL_add( t, CL_scale( s[1], FFT_C53 ) ); // Qx move64(); y[6] = CL_msu_j( s[0], s[1] ); @@ -5395,13 +5415,13 @@ static void fft_len30( move64(); y[10] = CL_add( xx[10], s[0] ); move64(); - s[0] = CL_add( y[10], CL_shl( CL_scale( s[0], FFT_C55 ), 1 ) ); + s[0] = CL_add( y[10], CL_shl( CL_scale( s[0], FFT_C55 ), 1 ) ); // Qx s[2] = CL_sub( s[0], t ); move64(); s[0] = CL_add( s[0], t ); move64(); t = CL_scale( CL_add( s[3], s[1] ), FFT_C51 ); - s[3] = CL_add( t, CL_shl( CL_scale( s[3], FFT_C52 ), 1 ) ); + s[3] = CL_add( t, CL_shl( CL_scale( s[3], FFT_C52 ), 1 ) ); // Qx move64(); s[1] = CL_add( t, CL_scale( s[1], FFT_C53 ) ); move64(); @@ -5417,7 +5437,7 @@ static void fft_len30( s[0] = CL_add( y[5], y[10] ); move64(); - s[1] = CL_scale( CL_sub( y[5], y[10] ), FFT_C31 ); + s[1] = CL_scale( CL_sub( y[5], y[10] ), FFT_C31 ); // Qx move64(); z[0] = CL_add( y[0], s[0] ); move64(); @@ -5431,7 +5451,7 @@ static void fft_len30( s[0] = CL_add( y[6], y[11] ); move64(); - s[1] = CL_scale( CL_sub( y[6], y[11] ), FFT_C31 ); + s[1] = CL_scale( CL_sub( y[6], y[11] ), FFT_C31 ); // Qx move64(); z[6] = CL_add( y[1], s[0] ); move64(); @@ -5445,7 +5465,7 @@ static void fft_len30( s[0] = CL_add( y[7], y[12] ); move64(); - s[1] = CL_scale( CL_sub( y[7], y[12] ), FFT_C31 ); + s[1] = CL_scale( CL_sub( y[7], y[12] ), FFT_C31 ); // Qx move64(); z[12] = CL_add( y[2], s[0] ); move64(); @@ -5459,7 +5479,7 @@ static void fft_len30( s[0] = CL_add( y[8], y[13] ); move64(); - s[1] = CL_scale( CL_sub( y[8], y[13] ), FFT_C31 ); + s[1] = CL_scale( CL_sub( y[8], y[13] ), FFT_C31 ); // Qx move64(); z[3] = CL_add( y[3], s[0] ); move64(); @@ -5473,7 +5493,7 @@ static void fft_len30( s[0] = CL_add( y[9], y[14] ); move64(); - s[1] = CL_scale( CL_sub( y[9], y[14] ), FFT_C31 ); + s[1] = CL_scale( CL_sub( y[9], y[14] ), FFT_C31 ); // Qx move64(); z[9] = CL_add( y[4], s[0] ); move64(); @@ -5526,21 +5546,21 @@ static void fft_len30( move64(); s[1] = CL_sub( xx[2], xx[3] ); move64(); - t = CL_scale( CL_sub( s[0], s[2] ), FFT_C54 ); + t = CL_scale( CL_sub( s[0], s[2] ), FFT_C54 ); // Qx s[0] = CL_add( s[0], s[2] ); move64(); y[0] = CL_add( xx[0], s[0] ); move64(); - s[0] = CL_add( y[0], CL_shl( CL_scale( s[0], FFT_C55 ), 1 ) ); + s[0] = CL_add( y[0], CL_shl( CL_scale( s[0], FFT_C55 ), 1 ) ); // Qx move64(); s[2] = CL_sub( s[0], t ); move64(); s[0] = CL_add( s[0], t ); move64(); - t = CL_scale( CL_add( s[3], s[1] ), FFT_C51 ); - s[3] = CL_add( t, CL_shl( CL_scale( s[3], FFT_C52 ), 1 ) ); + t = CL_scale( CL_add( s[3], s[1] ), FFT_C51 ); // Qx + s[3] = CL_add( t, CL_shl( CL_scale( s[3], FFT_C52 ), 1 ) ); // Qx move64(); - s[1] = CL_add( t, CL_scale( s[1], FFT_C53 ) ); + s[1] = CL_add( t, CL_scale( s[1], FFT_C53 ) ); // Qx move64(); y[1] = CL_msu_j( s[0], s[1] ); @@ -5560,21 +5580,21 @@ static void fft_len30( move64(); s[1] = CL_sub( xx[7], xx[8] ); move64(); - t = CL_scale( CL_sub( s[0], s[2] ), FFT_C54 ); + t = CL_scale( CL_sub( s[0], s[2] ), FFT_C54 ); // Qx s[0] = CL_add( s[0], s[2] ); move64(); y[5] = CL_add( xx[5], s[0] ); move64(); - s[0] = CL_add( y[5], CL_shl( CL_scale( s[0], FFT_C55 ), 1 ) ); + s[0] = CL_add( y[5], CL_shl( CL_scale( s[0], FFT_C55 ), 1 ) ); // Qx move64(); s[2] = CL_sub( s[0], t ); move64(); s[0] = CL_add( s[0], t ); move64(); - t = CL_scale( CL_add( s[3], s[1] ), FFT_C51 ); - s[3] = CL_add( t, CL_shl( CL_scale( s[3], FFT_C52 ), 1 ) ); + t = CL_scale( CL_add( s[3], s[1] ), FFT_C51 ); // Qx + s[3] = CL_add( t, CL_shl( CL_scale( s[3], FFT_C52 ), 1 ) ); // Qx move64(); - s[1] = CL_add( t, CL_scale( s[1], FFT_C53 ) ); + s[1] = CL_add( t, CL_scale( s[1], FFT_C53 ) ); // Qx move64(); y[6] = CL_msu_j( s[0], s[1] ); @@ -5594,21 +5614,21 @@ static void fft_len30( move64(); s[1] = CL_sub( xx[12], xx[13] ); move64(); - t = CL_scale( CL_sub( s[0], s[2] ), FFT_C54 ); + t = CL_scale( CL_sub( s[0], s[2] ), FFT_C54 ); // Qx s[0] = CL_add( s[0], s[2] ); move64(); y[10] = CL_add( xx[10], s[0] ); move64(); - s[0] = CL_add( y[10], CL_shl( CL_scale( s[0], FFT_C55 ), 1 ) ); + s[0] = CL_add( y[10], CL_shl( CL_scale( s[0], FFT_C55 ), 1 ) ); // Qx move64(); s[2] = CL_sub( s[0], t ); move64(); s[0] = CL_add( s[0], t ); move64(); - t = CL_scale( CL_add( s[3], s[1] ), FFT_C51 ); - s[3] = CL_add( t, CL_shl( CL_scale( s[3], FFT_C52 ), 1 ) ); + t = CL_scale( CL_add( s[3], s[1] ), FFT_C51 ); // Qx + s[3] = CL_add( t, CL_shl( CL_scale( s[3], FFT_C52 ), 1 ) ); // Qx move64(); - s[1] = CL_add( t, CL_scale( s[1], FFT_C53 ) ); + s[1] = CL_add( t, CL_scale( s[1], FFT_C53 ) ); // Qx move64(); y[11] = CL_msu_j( s[0], s[1] ); @@ -5622,7 +5642,7 @@ static void fft_len30( s[0] = CL_add( y[5], y[10] ); move64(); - s[1] = CL_scale( CL_sub( y[5], y[10] ), FFT_C31 ); + s[1] = CL_scale( CL_sub( y[5], y[10] ), FFT_C31 ); // Qx move64(); z[15] = CL_add( y[0], s[0] ); move64(); @@ -5636,7 +5656,7 @@ static void fft_len30( s[0] = CL_add( y[6], y[11] ); move64(); - s[1] = CL_scale( CL_sub( y[6], y[11] ), FFT_C31 ); + s[1] = CL_scale( CL_sub( y[6], y[11] ), FFT_C31 ); // Qx move64(); z[21] = CL_add( y[1], s[0] ); move64(); @@ -5650,7 +5670,7 @@ static void fft_len30( s[0] = CL_add( y[7], y[12] ); move64(); - s[1] = CL_scale( CL_sub( y[7], y[12] ), FFT_C31 ); + s[1] = CL_scale( CL_sub( y[7], y[12] ), FFT_C31 ); // Qx move64(); z[27] = CL_add( y[2], s[0] ); move64(); @@ -5664,7 +5684,7 @@ static void fft_len30( s[0] = CL_add( y[8], y[13] ); move64(); - s[1] = CL_scale( CL_sub( y[8], y[13] ), FFT_C31 ); + s[1] = CL_scale( CL_sub( y[8], y[13] ), FFT_C31 ); // Qx move64(); z[18] = CL_add( y[3], s[0] ); move64(); @@ -5678,7 +5698,7 @@ static void fft_len30( s[0] = CL_add( y[9], y[14] ); move64(); - s[1] = CL_scale( CL_sub( y[9], y[14] ), FFT_C31 ); + s[1] = CL_scale( CL_sub( y[9], y[14] ), FFT_C31 ); // Qx move64(); z[24] = CL_add( y[4], s[0] ); move64(); @@ -5844,7 +5864,8 @@ static void fft_len30( } static void fft_len32( - cmplx *x ) + cmplx *x // Qx +) { cmplx t[8], s[8], xx[8]; cmplx y[32]; @@ -5902,9 +5923,9 @@ static void fft_len32( move64(); { - s[6] = CL_scale( CL_add( CL_conjugate( t[0] ), t[1] ), FFT_C81 ); + s[6] = CL_scale( CL_add( CL_conjugate( t[0] ), t[1] ), FFT_C81 ); // Qx move64(); - s[7] = CL_scale( CL_sub( t[0], CL_conjugate( t[1] ) ), FFT_C81 ); + s[7] = CL_scale( CL_sub( t[0], CL_conjugate( t[1] ) ), FFT_C81 ); // Qx move64(); s[7] = CL_conjugate( s[7] ); move64(); @@ -6056,9 +6077,9 @@ static void fft_len32( move64(); { - s[6] = CL_scale( CL_add( CL_conjugate( t[0] ), t[1] ), FFT_C81 ); + s[6] = CL_scale( CL_add( CL_conjugate( t[0] ), t[1] ), FFT_C81 ); // Qx move64(); - s[7] = CL_scale( CL_sub( t[0], CL_conjugate( t[1] ) ), FFT_C81 ); + s[7] = CL_scale( CL_sub( t[0], CL_conjugate( t[1] ) ), FFT_C81 ); // Qx move64(); s[7] = CL_conjugate( s[7] ); move64(); @@ -6133,9 +6154,9 @@ static void fft_len32( move64(); { - s[6] = CL_scale( CL_add( CL_conjugate( t[0] ), t[1] ), FFT_C81 ); + s[6] = CL_scale( CL_add( CL_conjugate( t[0] ), t[1] ), FFT_C81 ); // Qx move64(); - s[7] = CL_scale( CL_sub( t[0], CL_conjugate( t[1] ) ), FFT_C81 ); + s[7] = CL_scale( CL_sub( t[0], CL_conjugate( t[1] ) ), FFT_C81 ); // Qx move64(); s[7] = CL_conjugate( s[7] ); move64(); @@ -6161,43 +6182,43 @@ static void fft_len32( { ab = y[9]; move64(); - y[9] = CL_mac_j( CL_scale( ab, FFT_RotVector_32_fx[0] ), CL_scale( ab, FFT_RotVector_32_fx[1] ) ); + y[9] = CL_mac_j( CL_scale( ab, FFT_RotVector_32_fx[0] ), CL_scale( ab, FFT_RotVector_32_fx[1] ) ); // Qx move64(); }; { ab = y[10]; move64(); - y[10] = CL_mac_j( CL_scale( ab, FFT_RotVector_32_fx[2] ), CL_scale( ab, FFT_RotVector_32_fx[3] ) ); + y[10] = CL_mac_j( CL_scale( ab, FFT_RotVector_32_fx[2] ), CL_scale( ab, FFT_RotVector_32_fx[3] ) ); // Qx move64(); }; { ab = y[11]; move64(); - y[11] = CL_mac_j( CL_scale( ab, FFT_RotVector_32_fx[4] ), CL_scale( ab, FFT_RotVector_32_fx[5] ) ); + y[11] = CL_mac_j( CL_scale( ab, FFT_RotVector_32_fx[4] ), CL_scale( ab, FFT_RotVector_32_fx[5] ) ); // Qx move64(); }; { ab = y[12]; move64(); - y[12] = CL_mac_j( CL_scale( ab, FFT_RotVector_32_fx[6] ), CL_scale( ab, FFT_RotVector_32_fx[7] ) ); + y[12] = CL_mac_j( CL_scale( ab, FFT_RotVector_32_fx[6] ), CL_scale( ab, FFT_RotVector_32_fx[7] ) ); // Qx move64(); }; { ab = y[13]; move64(); - y[13] = CL_mac_j( CL_scale( ab, FFT_RotVector_32_fx[8] ), CL_scale( ab, FFT_RotVector_32_fx[9] ) ); + y[13] = CL_mac_j( CL_scale( ab, FFT_RotVector_32_fx[8] ), CL_scale( ab, FFT_RotVector_32_fx[9] ) ); // Qx move64(); }; { ab = y[14]; move64(); - y[14] = CL_mac_j( CL_scale( ab, FFT_RotVector_32_fx[10] ), CL_scale( ab, FFT_RotVector_32_fx[11] ) ); + y[14] = CL_mac_j( CL_scale( ab, FFT_RotVector_32_fx[10] ), CL_scale( ab, FFT_RotVector_32_fx[11] ) ); // Qx move64(); }; { ab = y[15]; move64(); - y[15] = CL_mac_j( CL_scale( ab, FFT_RotVector_32_fx[12] ), CL_scale( ab, FFT_RotVector_32_fx[13] ) ); + y[15] = CL_mac_j( CL_scale( ab, FFT_RotVector_32_fx[12] ), CL_scale( ab, FFT_RotVector_32_fx[13] ) ); // Qx move64(); }; { @@ -6427,8 +6448,8 @@ static void fft_len32( } static void fft_lenN( - cmplx *x, - const Word16 *W, + cmplx *x, // Qx + const Word16 *W, // Q15 const Word16 len, const Word16 dim1, const Word16 dim2, @@ -6442,9 +6463,9 @@ static void fft_lenN( { FOR( j = 0; j < dim1; j++ ) { - xx[add( i_mult( i, dim1 ), j )].re = x[add( i, i_mult( j, dim2 ) )].re; + xx[( ( i * dim1 ) + j )].re = x[( i + ( j * dim2 ) )].re; // Qx move64(); - xx[add( i_mult( i, dim1 ), j )].im = x[add( i, i_mult( j, dim2 ) )].im; + xx[( ( i * dim1 ) + j )].im = x[( i + ( j * dim2 ) )].im; // Qx move64(); } } @@ -6454,56 +6475,56 @@ static void fft_lenN( case 5: FOR( i = 0; i < dim2; i++ ) { - fft_len5( &xx[i_mult( i, dim1 )] ); + fft_len5( &xx[( i * dim1 )] ); } BREAK; case 8: FOR( i = 0; i < dim2; i++ ) { - fft_len8( &xx[i_mult( i, dim1 )] ); + fft_len8( &xx[( i * dim1 )] ); } BREAK; case 10: FOR( i = 0; i < dim2; i++ ) { - fft_len10( &xx[i_mult( i, dim1 )] ); + fft_len10( &xx[( i * dim1 )] ); } BREAK; case 15: FOR( i = 0; i < dim2; i++ ) { - fft_len15( &xx[i_mult( i, dim1 )] ); + fft_len15( &xx[( i * dim1 )] ); } BREAK; case 16: FOR( i = 0; i < dim2; i++ ) { - fft_len16( &xx[i_mult( i, dim1 )] ); + fft_len16( &xx[( i * dim1 )] ); } BREAK; case 20: FOR( i = 0; i < dim2; i++ ) { - fft_len20_fx( &xx[i_mult( i, dim1 )] ); + fft_len20_fx( &xx[( i * dim1 )] ); } BREAK; case 30: FOR( i = 0; i < dim2; i++ ) { - fft_len30( &xx[i_mult( i, dim1 )] ); + fft_len30( &xx[( i * dim1 )] ); } BREAK; case 32: FOR( i = 0; i < dim2; i++ ) { - fft_len32( &xx[i_mult( i, dim1 )] ); + fft_len32( &xx[( i * dim1 )] ); } BREAK; } @@ -6532,69 +6553,69 @@ static void fft_lenN( IF( i == 0 ) { { - y[1] = xx[add( i, i_mult( 1, dim1 ) )]; + y[1] = xx[( i + ( 1 * dim1 ) )]; move64(); }; { - y[2] = xx[add( i, i_mult( 2, dim1 ) )]; + y[2] = xx[( i + ( 2 * dim1 ) )]; move64(); }; { - y[3] = xx[add( i, i_mult( 3, dim1 ) )]; + y[3] = xx[( i + ( 3 * dim1 ) )]; move64(); }; { - y[4] = xx[add( i, i_mult( 4, dim1 ) )]; + y[4] = xx[( i + ( 4 * dim1 ) )]; move64(); }; { - y[5] = xx[add( i, i_mult( 5, dim1 ) )]; + y[5] = xx[( i + ( 5 * dim1 ) )]; move64(); }; { - y[6] = xx[add( i, i_mult( 6, dim1 ) )]; + y[6] = xx[( i + ( 6 * dim1 ) )]; move64(); }; { - y[7] = xx[add( i, i_mult( 7, dim1 ) )]; + y[7] = xx[( i + ( 7 * dim1 ) )]; move64(); }; } ELSE { { - y[1] = CL_mac_j( CL_scale( xx[add( i, i_mult( 1, dim1 ) )], W[sub( add( i_mult( sc, i ), shl( i_mult( i_mult( sc, 1 ), dim1 ), 1 ) ), Woff )] ), - CL_scale( xx[add( i, i_mult( 1, dim1 ) )], W[sub( add( add( i_mult( sc, i ), shl( i_mult( i_mult( sc, 1 ), dim1 ), 1 ) ), 1 ), Woff )] ) ); + y[1] = CL_mac_j( CL_scale( xx[( i + ( 1 * dim1 ) )], W[( ( ( sc * i ) + ( ( ( sc * 1 ) * dim1 ) << 1 ) ) - Woff )] ), + CL_scale( xx[( i + ( 1 * dim1 ) )], W[( ( ( ( sc * i ) + ( ( ( sc * 1 ) * dim1 ) << 1 ) ) + 1 ) - Woff )] ) ); // Qx move64(); }; { - y[2] = CL_mac_j( CL_scale( xx[add( i, i_mult( 2, dim1 ) )], W[sub( add( i_mult( sc, i ), shl( i_mult( i_mult( sc, 2 ), dim1 ), 1 ) ), Woff )] ), - CL_scale( xx[add( i, i_mult( 2, dim1 ) )], W[sub( add( add( i_mult( sc, i ), shl( i_mult( i_mult( sc, 2 ), dim1 ), 1 ) ), 1 ), Woff )] ) ); + y[2] = CL_mac_j( CL_scale( xx[( i + ( 2 * dim1 ) )], W[( ( ( sc * i ) + ( ( ( sc * 2 ) * dim1 ) << 1 ) ) - Woff )] ), + CL_scale( xx[( i + ( 2 * dim1 ) )], W[( ( ( ( sc * i ) + ( ( ( sc * 2 ) * dim1 ) << 1 ) ) + 1 ) - Woff )] ) ); // Qx move64(); }; { - y[3] = CL_mac_j( CL_scale( xx[add( i, i_mult( 3, dim1 ) )], W[sub( add( i_mult( sc, i ), shl( i_mult( i_mult( sc, 3 ), dim1 ), 1 ) ), Woff )] ), - CL_scale( xx[add( i, i_mult( 3, dim1 ) )], W[sub( add( add( i_mult( sc, i ), shl( i_mult( i_mult( sc, 3 ), dim1 ), 1 ) ), 1 ), Woff )] ) ); + y[3] = CL_mac_j( CL_scale( xx[( i + ( 3 * dim1 ) )], W[( ( ( sc * i ) + ( ( ( sc * 3 ) * dim1 ) << 1 ) ) - Woff )] ), + CL_scale( xx[( i + ( 3 * dim1 ) )], W[( ( ( ( sc * i ) + ( ( ( sc * 3 ) * dim1 ) << 1 ) ) + 1 ) - Woff )] ) ); // Qx move64(); }; { - y[4] = CL_mac_j( CL_scale( xx[add( i, i_mult( 4, dim1 ) )], W[sub( add( i_mult( sc, i ), shl( i_mult( i_mult( sc, 4 ), dim1 ), 1 ) ), Woff )] ), - CL_scale( xx[add( i, i_mult( 4, dim1 ) )], W[sub( add( add( i_mult( sc, i ), shl( i_mult( i_mult( sc, 4 ), dim1 ), 1 ) ), 1 ), Woff )] ) ); + y[4] = CL_mac_j( CL_scale( xx[( i + ( 4 * dim1 ) )], W[( ( ( sc * i ) + ( ( ( sc * 4 ) * dim1 ) << 1 ) ) - Woff )] ), + CL_scale( xx[( i + ( 4 * dim1 ) )], W[( ( ( ( sc * i ) + ( ( ( sc * 4 ) * dim1 ) << 1 ) ) + 1 ) - Woff )] ) ); // Qx move64(); }; { - y[5] = CL_mac_j( CL_scale( xx[add( i, i_mult( 5, dim1 ) )], W[sub( add( i_mult( sc, i ), shl( i_mult( i_mult( sc, 5 ), dim1 ), 1 ) ), Woff )] ), - CL_scale( xx[add( i, i_mult( 5, dim1 ) )], W[sub( add( add( i_mult( sc, i ), shl( i_mult( i_mult( sc, 5 ), dim1 ), 1 ) ), 1 ), Woff )] ) ); + y[5] = CL_mac_j( CL_scale( xx[( i + ( 5 * dim1 ) )], W[( ( ( sc * i ) + ( ( ( sc * 5 ) * dim1 ) << 1 ) ) - Woff )] ), + CL_scale( xx[( i + ( 5 * dim1 ) )], W[( ( ( ( sc * i ) + ( ( ( sc * 5 ) * dim1 ) << 1 ) ) + 1 ) - Woff )] ) ); // Qx move64(); }; { - y[6] = CL_mac_j( CL_scale( xx[add( i, i_mult( 6, dim1 ) )], W[sub( add( i_mult( sc, i ), shl( i_mult( i_mult( sc, 6 ), dim1 ), 1 ) ), Woff )] ), - CL_scale( xx[add( i, i_mult( 6, dim1 ) )], W[sub( add( add( i_mult( sc, i ), shl( i_mult( i_mult( sc, 6 ), dim1 ), 1 ) ), 1 ), Woff )] ) ); + y[6] = CL_mac_j( CL_scale( xx[( i + ( 6 * dim1 ) )], W[( ( ( sc * i ) + ( ( ( sc * 6 ) * dim1 ) << 1 ) ) - Woff )] ), + CL_scale( xx[( i + ( 6 * dim1 ) )], W[( ( ( ( sc * i ) + ( ( ( sc * 6 ) * dim1 ) << 1 ) ) + 1 ) - Woff )] ) ); // Qx move64(); }; { - y[7] = CL_mac_j( CL_scale( xx[add( i, i_mult( 7, dim1 ) )], W[sub( add( i_mult( sc, i ), shl( i_mult( i_mult( sc, 7 ), dim1 ), 1 ) ), Woff )] ), - CL_scale( xx[add( i, i_mult( 7, dim1 ) )], W[sub( add( add( i_mult( sc, i ), shl( i_mult( i_mult( sc, 7 ), dim1 ), 1 ) ), 1 ), Woff )] ) ); + y[7] = CL_mac_j( CL_scale( xx[( i + ( 7 * dim1 ) )], W[( ( ( sc * i ) + ( ( ( sc * 7 ) * dim1 ) << 1 ) ) - Woff )] ), + CL_scale( xx[( i + ( 7 * dim1 ) )], W[( ( ( ( sc * i ) + ( ( ( sc * 7 ) * dim1 ) << 1 ) ) + 1 ) - Woff )] ) ); // Qx move64(); }; } @@ -6634,28 +6655,28 @@ static void fft_lenN( t[1] = CL_sub( t[3], t[7] ); move64(); - s[6] = CL_scale( CL_add( CL_conjugate( t[0] ), t[1] ), FFT_C81 ); + s[6] = CL_scale( CL_add( CL_conjugate( t[0] ), t[1] ), FFT_C81 ); // Qx move64(); - s[7] = CL_scale( CL_sub( t[0], CL_conjugate( t[1] ) ), FFT_C81 ); + s[7] = CL_scale( CL_sub( t[0], CL_conjugate( t[1] ) ), FFT_C81 ); // Qx move64(); s[7] = CL_conjugate( s[7] ); move64(); x[i] = CL_add( s[0], s[1] ); /*x[add(i + i_mult(0 , dim1)] = CL_add( s[0], s[1] )*/ move64(); - x[add( i, i_mult( 1, dim1 ) )] = CL_add( s[5], s[6] ); + x[( i + ( 1 * dim1 ) )] = CL_add( s[5], s[6] ); move64(); - x[add( i, i_mult( 2, dim1 ) )] = CL_sub( s[2], s[3] ); + x[( i + ( 2 * dim1 ) )] = CL_sub( s[2], s[3] ); move64(); - x[add( i, i_mult( 3, dim1 ) )] = CL_add( s[4], s[7] ); + x[( i + ( 3 * dim1 ) )] = CL_add( s[4], s[7] ); move64(); - x[add( i, i_mult( 4, dim1 ) )] = CL_sub( s[0], s[1] ); + x[( i + ( 4 * dim1 ) )] = CL_sub( s[0], s[1] ); move64(); - x[add( i, i_mult( 5, dim1 ) )] = CL_sub( s[5], s[6] ); + x[( i + ( 5 * dim1 ) )] = CL_sub( s[5], s[6] ); move64(); - x[add( i, i_mult( 6, dim1 ) )] = CL_add( s[2], s[3] ); + x[( i + ( 6 * dim1 ) )] = CL_add( s[2], s[3] ); move64(); - x[add( i, i_mult( 7, dim1 ) )] = CL_sub( s[4], s[7] ); + x[( i + ( 7 * dim1 ) )] = CL_sub( s[4], s[7] ); move64(); } } @@ -6670,69 +6691,69 @@ static void fft_lenN( IF( i == 0 ) { { - y[1] = xx[add( i, i_mult( 1, dim1 ) )]; + y[1] = xx[( i + ( 1 * dim1 ) )]; move64(); }; { - y[2] = xx[add( i, i_mult( 2, dim1 ) )]; + y[2] = xx[( i + ( 2 * dim1 ) )]; move64(); }; { - y[3] = xx[add( i, i_mult( 3, dim1 ) )]; + y[3] = xx[( i + ( 3 * dim1 ) )]; move64(); }; { - y[4] = xx[add( i, i_mult( 4, dim1 ) )]; + y[4] = xx[( i + ( 4 * dim1 ) )]; move64(); }; { - y[5] = xx[add( i, i_mult( 5, dim1 ) )]; + y[5] = xx[( i + ( 5 * dim1 ) )]; move64(); }; { - y[6] = xx[add( i, i_mult( 6, dim1 ) )]; + y[6] = xx[( i + ( 6 * dim1 ) )]; move64(); }; { - y[7] = xx[add( i, i_mult( 7, dim1 ) )]; + y[7] = xx[( i + ( 7 * dim1 ) )]; move64(); }; } ELSE { { - y[1] = CL_mac_j( CL_scale( xx[add( i, i_mult( 1, dim1 ) )], W[sub( add( i_mult( sc, i ), i_mult( i_mult( sc, 1 ), dim1 ) ), Woff )] ), - CL_scale( xx[add( i, i_mult( 1, dim1 ) )], W[sub( add( add( i_mult( sc, i ), i_mult( i_mult( sc, 1 ), dim1 ) ), 1 ), Woff )] ) ); + y[1] = CL_mac_j( CL_scale( xx[( i + ( 1 * dim1 ) )], W[( ( ( sc * i ) + ( ( sc * 1 ) * dim1 ) ) - Woff )] ), + CL_scale( xx[( i + ( 1 * dim1 ) )], W[( ( ( ( sc * i ) + ( ( sc * 1 ) * dim1 ) ) + 1 ) - Woff )] ) ); // Qx move64(); }; { - y[2] = CL_mac_j( CL_scale( xx[add( i, i_mult( 2, dim1 ) )], W[sub( add( i_mult( sc, i ), i_mult( i_mult( sc, 2 ), dim1 ) ), Woff )] ), - CL_scale( xx[add( i, i_mult( 2, dim1 ) )], W[sub( add( add( i_mult( sc, i ), i_mult( i_mult( sc, 2 ), dim1 ) ), 1 ), Woff )] ) ); + y[2] = CL_mac_j( CL_scale( xx[( i + ( 2 * dim1 ) )], W[( ( ( sc * i ) + ( ( sc * 2 ) * dim1 ) ) - Woff )] ), + CL_scale( xx[( i + ( 2 * dim1 ) )], W[( ( ( ( sc * i ) + ( ( sc * 2 ) * dim1 ) ) + 1 ) - Woff )] ) ); // Qx move64(); }; { - y[3] = CL_mac_j( CL_scale( xx[add( i, i_mult( 3, dim1 ) )], W[sub( add( i_mult( sc, i ), i_mult( i_mult( sc, 3 ), dim1 ) ), Woff )] ), - CL_scale( xx[add( i, i_mult( 3, dim1 ) )], W[sub( add( add( i_mult( sc, i ), i_mult( i_mult( sc, 3 ), dim1 ) ), 1 ), Woff )] ) ); + y[3] = CL_mac_j( CL_scale( xx[( i + ( 3 * dim1 ) )], W[( ( ( sc * i ) + ( ( sc * 3 ) * dim1 ) ) - Woff )] ), + CL_scale( xx[( i + ( 3 * dim1 ) )], W[( ( ( ( sc * i ) + ( ( sc * 3 ) * dim1 ) ) + 1 ) - Woff )] ) ); // Qx move64(); }; { - y[4] = CL_mac_j( CL_scale( xx[add( i, i_mult( 4, dim1 ) )], W[sub( add( i_mult( sc, i ), i_mult( i_mult( sc, 4 ), dim1 ) ), Woff )] ), - CL_scale( xx[add( i, i_mult( 4, dim1 ) )], W[sub( add( add( i_mult( sc, i ), i_mult( i_mult( sc, 4 ), dim1 ) ), 1 ), Woff )] ) ); + y[4] = CL_mac_j( CL_scale( xx[( i + ( 4 * dim1 ) )], W[( ( ( sc * i ) + ( ( sc * 4 ) * dim1 ) ) - Woff )] ), + CL_scale( xx[( i + ( 4 * dim1 ) )], W[( ( ( ( sc * i ) + ( ( sc * 4 ) * dim1 ) ) + 1 ) - Woff )] ) ); // Qx move64(); }; { - y[5] = CL_mac_j( CL_scale( xx[add( i, i_mult( 5, dim1 ) )], W[sub( add( i_mult( sc, i ), i_mult( i_mult( sc, 5 ), dim1 ) ), Woff )] ), - CL_scale( xx[add( i, i_mult( 5, dim1 ) )], W[sub( add( add( i_mult( sc, i ), i_mult( i_mult( sc, 5 ), dim1 ) ), 1 ), Woff )] ) ); + y[5] = CL_mac_j( CL_scale( xx[( i + ( 5 * dim1 ) )], W[( ( ( sc * i ) + ( ( sc * 5 ) * dim1 ) ) - Woff )] ), + CL_scale( xx[( i + ( 5 * dim1 ) )], W[( ( ( ( sc * i ) + ( ( sc * 5 ) * dim1 ) ) + 1 ) - Woff )] ) ); // Qx move64(); }; { - y[6] = CL_mac_j( CL_scale( xx[add( i, i_mult( 6, dim1 ) )], W[sub( add( i_mult( sc, i ), i_mult( i_mult( sc, 6 ), dim1 ) ), Woff )] ), - CL_scale( xx[add( i, i_mult( 6, dim1 ) )], W[sub( add( add( i_mult( sc, i ), i_mult( i_mult( sc, 6 ), dim1 ) ), 1 ), Woff )] ) ); + y[6] = CL_mac_j( CL_scale( xx[( i + ( 6 * dim1 ) )], W[( ( ( sc * i ) + ( ( sc * 6 ) * dim1 ) ) - Woff )] ), + CL_scale( xx[( i + ( 6 * dim1 ) )], W[( ( ( ( sc * i ) + ( ( sc * 6 ) * dim1 ) ) + 1 ) - Woff )] ) ); // Qx move64(); }; { - y[7] = CL_mac_j( CL_scale( xx[add( i, i_mult( 7, dim1 ) )], W[sub( add( i_mult( sc, i ), i_mult( i_mult( sc, 7 ), dim1 ) ), Woff )] ), - CL_scale( xx[add( i, i_mult( 7, dim1 ) )], W[sub( add( add( i_mult( sc, i ), i_mult( i_mult( sc, 7 ), dim1 ) ), 1 ), Woff )] ) ); + y[7] = CL_mac_j( CL_scale( xx[( i + ( 7 * dim1 ) )], W[( ( ( sc * i ) + ( ( sc * 7 ) * dim1 ) ) - Woff )] ), + CL_scale( xx[( i + ( 7 * dim1 ) )], W[( ( ( ( sc * i ) + ( ( sc * 7 ) * dim1 ) ) + 1 ) - Woff )] ) ); // Qx move64(); }; } @@ -6772,28 +6793,28 @@ static void fft_lenN( t[1] = CL_sub( t[3], t[7] ); move64(); - s[6] = CL_scale( CL_add( CL_conjugate( t[0] ), t[1] ), FFT_C81 ); + s[6] = CL_scale( CL_add( CL_conjugate( t[0] ), t[1] ), FFT_C81 ); // Qx move64(); - s[7] = CL_scale( CL_sub( t[0], CL_conjugate( t[1] ) ), FFT_C81 ); + s[7] = CL_scale( CL_sub( t[0], CL_conjugate( t[1] ) ), FFT_C81 ); // Qx move64(); s[7] = CL_conjugate( s[7] ); move64(); x[i] = CL_add( s[0], s[1] ); /*x[i + 0 * dim1] = CL_add( s[0], s[1] )*/ move64(); - x[add( i, i_mult( 1, dim1 ) )] = CL_add( s[5], s[6] ); + x[( i + ( 1 * dim1 ) )] = CL_add( s[5], s[6] ); move64(); - x[add( i, i_mult( 2, dim1 ) )] = CL_sub( s[2], s[3] ); + x[( i + ( 2 * dim1 ) )] = CL_sub( s[2], s[3] ); move64(); - x[add( i, i_mult( 3, dim1 ) )] = CL_add( s[4], s[7] ); + x[( i + ( 3 * dim1 ) )] = CL_add( s[4], s[7] ); move64(); - x[add( i, i_mult( 4, dim1 ) )] = CL_sub( s[0], s[1] ); + x[( i + ( 4 * dim1 ) )] = CL_sub( s[0], s[1] ); move64(); - x[add( i, i_mult( 5, dim1 ) )] = CL_sub( s[5], s[6] ); + x[( i + ( 5 * dim1 ) )] = CL_sub( s[5], s[6] ); move64(); - x[add( i, i_mult( 6, dim1 ) )] = CL_add( s[2], s[3] ); + x[( i + ( 6 * dim1 ) )] = CL_add( s[2], s[3] ); move64(); - x[add( i, i_mult( 7, dim1 ) )] = CL_sub( s[4], s[7] ); + x[( i + ( 7 * dim1 ) )] = CL_sub( s[4], s[7] ); move64(); } } @@ -6806,14 +6827,14 @@ static void fft_lenN( FOR( j = 0; j < dim2; j++ ) { { - y[j] = xx[0 + i_mult( j, dim1 )]; /*y[j] = xx[0 + j * dim1];*/ + y[j] = xx[0 + ( j * dim1 )]; /*y[j] = xx[0 + j * dim1];*/ move64(); }; } fft_len10( &y[0] ); FOR( j = 0; j < dim2; j++ ) { - x[0 + i_mult( j, dim1 )] = y[j]; + x[0 + ( j * dim1 )] = y[j]; move64(); } @@ -6827,15 +6848,15 @@ static void fft_lenN( FOR( j = 1; j < dim2; j++ ) { { - y[( j + 0 )] = CL_mac_j( CL_scale( xx[add( i, i_mult( ( j + 0 ), dim1 ) )], W[sub( add( i_mult( sc, i ), i_mult( i_mult( sc, j ), dim1 ) ), Woff )] ), - CL_scale( xx[add( i, i_mult( ( j + 0 ), dim1 ) )], W[sub( add( add( i_mult( sc, i ), i_mult( i_mult( sc, j ), dim1 ) ), 1 ), Woff )] ) ); + y[( j + 0 )] = CL_mac_j( CL_scale( xx[( i + ( ( j + 0 ) * dim1 ) )], W[( ( ( sc * i ) + ( ( sc * j ) * dim1 ) ) - Woff )] ), + CL_scale( xx[( i + ( ( j + 0 ) * dim1 ) )], W[( ( ( ( sc * i ) + ( ( sc * j ) * dim1 ) ) + 1 ) - Woff )] ) ); // Qx move64(); } } fft_len10( &y[0] ); FOR( j = 0; j < dim2; j++ ) { - x[add( i, i_mult( j, dim1 ) )] = y[j]; + x[( i + ( j * dim1 ) )] = y[j]; move64(); } } @@ -6848,7 +6869,7 @@ static void fft_lenN( FOR( j = 0; j < dim2; j++ ) { { - y[j] = xx[0 + i_mult( j, dim1 )]; + y[j] = xx[0 + ( j * dim1 )]; move64(); }; } @@ -6856,7 +6877,7 @@ static void fft_lenN( fft_len16( &y[0] ); FOR( j = 0; j < dim2; j++ ) { - x[0 + i_mult( j, dim1 )] = y[j]; + x[0 + ( j * dim1 )] = y[j]; move64(); } @@ -6870,15 +6891,15 @@ static void fft_lenN( FOR( j = 1; j < dim2; j++ ) { { - y[( j + 0 )] = CL_mac_j( CL_scale( xx[add( i, i_mult( ( j + 0 ), dim1 ) )], W[sub( add( i_mult( sc, i ), i_mult( i_mult( sc, j ), dim1 ) ), Woff )] ), - CL_scale( xx[add( i, i_mult( ( j + 0 ), dim1 ) )], W[sub( add( add( i_mult( sc, i ), i_mult( i_mult( sc, j ), dim1 ) ), 1 ), Woff )] ) ); + y[( j + 0 )] = CL_mac_j( CL_scale( xx[( i + ( ( j + 0 ) * dim1 ) )], W[( ( ( sc * i ) + ( ( sc * j ) * dim1 ) ) - Woff )] ), + CL_scale( xx[( i + ( ( j + 0 ) * dim1 ) )], W[( ( ( ( sc * i ) + ( ( sc * j ) * dim1 ) ) + 1 ) - Woff )] ) ); // Qx move64(); } } fft_len16( &y[0] ); FOR( j = 0; j < dim2; j++ ) { - x[add( i, i_mult( j, dim1 ) )] = y[j]; + x[( i + ( j * dim1 ) )] = y[j]; move64(); } } @@ -6891,39 +6912,39 @@ static void fft_lenN( FOR( j = 0; j < dim2; j++ ) { { - y[j] = xx[0 + i_mult( j, dim1 )]; + y[j] = xx[0 + ( j * dim1 )]; move64(); }; } fft_len20_fx( &y[0] ); FOR( j = 0; j < dim2; j++ ) { - x[0 + i_mult( j, dim1 )] = y[j]; + x[0 + ( j * dim1 )] = y[j]; move64(); } FOR( i = 1; i < dim1; i++ ) { { - y[( 0 + 0 )] = xx[add( i, ( 0 + 0 ) * dim1 )]; + y[( 0 + 0 )] = xx[( i + ( 0 + 0 ) * dim1 )]; move64(); } { - y[( 0 + 1 )] = CL_mac_j( CL_scale( xx[add( i, i_mult( ( 0 + 1 ), dim1 ) )], W[sub( add( len, i_mult( sc, i ) ) + 0 * dim1, Woff )] ), - CL_scale( xx[add( i, i_mult( ( 0 + 1 ), dim1 ) )], W[sub( add( add( len, i_mult( sc, i ) ) + 0 * dim1, 1 ), Woff )] ) ); + y[( 0 + 1 )] = CL_mac_j( CL_scale( xx[( i + ( ( 0 + 1 ) * dim1 ) )], W[( ( len + ( sc * i ) ) + 0 * dim1 - Woff )] ), + CL_scale( xx[( i + ( ( 0 + 1 ) * dim1 ) )], W[( ( ( len + ( sc * i ) ) + 0 * dim1 + 1 ) - Woff )] ) ); // Qx move64(); } FOR( j = 2; j < dim2; j = j + 2 ) { { - y[( j + 0 )] = CL_mac_j( CL_scale( xx[add( i, i_mult( ( j + 0 ), dim1 ) )], W[sub( add( i_mult( sc, i ), i_mult( j, dim1 ) ), Woff )] ), - CL_scale( xx[add( i, i_mult( ( j + 0 ), dim1 ) )], W[sub( add( add( i_mult( sc, i ), i_mult( j, dim1 ) ), 1 ), Woff )] ) ); + y[( j + 0 )] = CL_mac_j( CL_scale( xx[( i + ( ( j + 0 ) * dim1 ) )], W[( ( ( sc * i ) + ( j * dim1 ) ) - Woff )] ), + CL_scale( xx[( i + ( ( j + 0 ) * dim1 ) )], W[( ( ( ( sc * i ) + ( j * dim1 ) ) + 1 ) - Woff )] ) ); // Qx move64(); } { - y[( j + 1 )] = CL_mac_j( CL_scale( xx[add( i, i_mult( ( j + 1 ), dim1 ) )], W[sub( add( add( len, i_mult( sc, i ) ), i_mult( j, dim1 ) ), Woff )] ), - CL_scale( xx[add( i, i_mult( ( j + 1 ), dim1 ) )], W[sub( add( add( add( len, i_mult( sc, i ) ), i_mult( j, dim1 ) ), 1 ), Woff )] ) ); + y[( j + 1 )] = CL_mac_j( CL_scale( xx[( i + ( ( j + 1 ) * dim1 ) )], W[( ( ( len + ( sc * i ) ) + ( j * dim1 ) ) - Woff )] ), + CL_scale( xx[( i + ( ( j + 1 ) * dim1 ) )], W[( ( ( ( len + ( sc * i ) ) + ( j * dim1 ) ) + 1 ) - Woff )] ) ); // Qx move64(); } } @@ -6961,28 +6982,28 @@ static void fft_lenN( move64(); } { - y[( 0 + 1 )] = CL_mac_j( CL_scale( xx[add( i, i_mult( ( 0 + 1 ), dim1 ) )], W[sub( add( len, i_mult( sc, i ) ) + 0 * dim1, Woff )] ), - CL_scale( xx[add( i, i_mult( ( 0 + 1 ), dim1 ) )], W[sub( add( add( len, i_mult( sc, i ) ) + 0 * dim1, 1 ), Woff )] ) ); + y[( 0 + 1 )] = CL_mac_j( CL_scale( xx[( i + ( ( 0 + 1 ) * dim1 ) )], W[( ( len + ( sc * i ) ) + 0 * dim1 - Woff )] ), + CL_scale( xx[( i + ( ( 0 + 1 ) * dim1 ) )], W[( ( ( len + ( sc * i ) ) + 0 * dim1 + 1 ) - Woff )] ) ); // Qx move64(); } FOR( j = 2; j < dim2; j = j + 2 ) { { - y[( j + 0 )] = CL_mac_j( CL_scale( xx[add( i, i_mult( ( j + 0 ), dim1 ) )], W[sub( add( i_mult( sc, i ), i_mult( j, dim1 ) ), Woff )] ), - CL_scale( xx[add( i, i_mult( ( j + 0 ), dim1 ) )], W[sub( add( add( i_mult( sc, i ), i_mult( j, dim1 ) ), 1 ), Woff )] ) ); + y[( j + 0 )] = CL_mac_j( CL_scale( xx[( i + ( ( j + 0 ) * dim1 ) )], W[( ( ( sc * i ) + ( j * dim1 ) ) - Woff )] ), + CL_scale( xx[( i + ( ( j + 0 ) * dim1 ) )], W[( ( ( ( sc * i ) + ( j * dim1 ) ) + 1 ) - Woff )] ) ); // Qx move64(); } { - y[( j + 1 )] = CL_mac_j( CL_scale( xx[add( i, i_mult( ( j + 1 ), dim1 ) )], W[sub( add( add( len, i_mult( sc, i ) ), i_mult( j, dim1 ) ), Woff )] ), - CL_scale( xx[add( i, i_mult( ( j + 1 ), dim1 ) )], W[sub( add( add( add( len, i_mult( sc, i ) ), i_mult( j, dim1 ) ), 1 ), Woff )] ) ); + y[( j + 1 )] = CL_mac_j( CL_scale( xx[( i + ( ( j + 1 ) * dim1 ) )], W[( ( ( len + ( sc * i ) ) + ( j * dim1 ) ) - Woff )] ), + CL_scale( xx[( i + ( ( j + 1 ) * dim1 ) )], W[( ( ( ( len + ( sc * i ) ) + ( j * dim1 ) ) + 1 ) - Woff )] ) ); // Qx move64(); } } fft_len32( &y[0] ); FOR( j = 0; j < dim2; j++ ) { - x[add( i, i_mult( j, dim1 ) )] = y[j]; + x[( i + ( j * dim1 ) )] = y[j]; move64(); } } @@ -6999,8 +7020,8 @@ static void fft_lenN( *-----------------------------------------------------------------*/ void fft_fx( - Word32 *re, /* i/o: real part */ - Word32 *im, /* i/o: imag part */ + Word32 *re, /* i/o: real part Qx */ + Word32 *im, /* i/o: imag part Qx */ const Word16 length, /* i : length of fft */ const Word16 s /* i : sign */ ) @@ -7009,9 +7030,9 @@ void fft_fx( FOR( Word16 j = 0; j < length; j++ ) { - x[j].re = re[i_mult( s, j )]; + x[j].re = re[( s * j )]; move32(); - x[j].im = im[i_mult( s, j )]; + x[j].im = im[( s * j )]; move32(); } @@ -7074,9 +7095,9 @@ void fft_fx( FOR( Word16 j = 0; j < length; j++ ) { - re[i_mult( s, j )] = x[j].re; + re[( s * j )] = x[j].re; move32(); - im[i_mult( s, j )] = x[j].im; + im[( s * j )] = x[j].im; move32(); } @@ -7084,8 +7105,8 @@ void fft_fx( } void rfft_fx( - Word32 *x, /* i/o: values */ - const Word16 *w, /* i : window */ + Word32 *x, /* i/o: values Qx */ + const Word16 *w, /* i : window Q15 */ const Word16 length, /* i : length of fft */ const Word16 isign /* i : sign */ ) @@ -7099,55 +7120,55 @@ void rfft_fx( SWITCH( sizeOfFft2 ) { case 80: - s1 = 409; + s1 = 409; //(1/sizeOfFft2).Q15 move16(); s2 = -409; move16(); BREAK; case 128: - s1 = 256; + s1 = 256; //(1/sizeOfFft2).Q15 move16(); s2 = -256; move16(); BREAK; case 160: - s1 = 204; + s1 = 204; //(1/sizeOfFft2).Q15 move16(); s2 = -204; move16(); BREAK; case 240: - s1 = 136; + s1 = 136; //(1/sizeOfFft2).Q15 move16(); s2 = -136; move16(); BREAK; case 256: - s1 = 128; + s1 = 128; //(1/sizeOfFft2).Q15 move16(); s2 = -128; move16(); BREAK; case 320: - s1 = 102; + s1 = 102; //(1/sizeOfFft2).Q15 move16(); s2 = -102; move16(); BREAK; case 480: - s1 = 68; + s1 = 68; //(1/sizeOfFft2).Q15 move16(); s2 = -68; move16(); BREAK; case 640: - s1 = 51; + s1 = 51; //(1/sizeOfFft2).Q15 move16(); s2 = -51; move16(); BREAK; case 960: - s1 = 34; + s1 = 34; //(1/sizeOfFft2).Q15 move16(); s2 = -34; move16(); @@ -7167,29 +7188,29 @@ void rfft_fx( case -1: fft_fx( x, x + 1, sizeOfFft2, 2 ); - + // Qx tmp = L_add( x[0], x[1] ); - x[1] = L_sub( x[0], x[1] ); + x[1] = L_sub( x[0], x[1] ); // Qx move32(); x[0] = tmp; move32(); FOR( i = 1; i <= sizeOfFft4; i++ ) { - t1 = L_sub( x[2 * i], x[sub( length, shl( i, 1 ) )] ); - t2 = L_add( x[add( shl( i, 1 ), 1 )], x[add( sub( length, shl( i, 1 ) ), 1 )] ); - t3 = L_sub( Mpy_32_16_1( t1, w[i] ), Mpy_32_16_1( t2, w[i + sizeOfFft4] ) ); - t4 = L_add( Mpy_32_16_1( t1, w[i + sizeOfFft4] ), Mpy_32_16_1( t2, w[i] ) ); - t1 = L_add( x[2 * i], x[sub( length, shl( i, 1 ) )] ); - t2 = L_sub( x[add( shl( i, 1 ), 1 )], x[add( sub( length, shl( i, 1 ) ), 1 )] ); - - x[2 * i] = Mpy_32_16_1( L_sub( t1, t3 ), 16384 ); + t1 = L_sub( x[2 * i], x[( length - ( i << 1 ) )] ); // Qx + t2 = L_add( x[( ( i << 1 ) + 1 )], x[( ( length - ( i << 1 ) ) + 1 )] ); // Qx + t3 = L_sub( Mpy_32_16_1( t1, w[i] ), Mpy_32_16_1( t2, w[i + sizeOfFft4] ) ); // Qx + t4 = L_add( Mpy_32_16_1( t1, w[i + sizeOfFft4] ), Mpy_32_16_1( t2, w[i] ) ); // Qx + t1 = L_add( x[2 * i], x[( length - ( i << 1 ) )] ); + t2 = L_sub( x[( ( i << 1 ) + 1 )], x[( ( length - ( i << 1 ) ) + 1 )] ); + + x[2 * i] = Mpy_32_16_1( L_sub( t1, t3 ), 16384 /*0.5.Q15*/ ); move32(); - x[add( shl( i, 1 ), 1 )] = Mpy_32_16_1( L_sub( t2, t4 ), 16384 ); + x[( ( i << 1 ) + 1 )] = Mpy_32_16_1( L_sub( t2, t4 ), 16384 /*0.5.Q15*/ ); move32(); - x[sub( length, shl( i, 1 ) )] = Mpy_32_16_1( L_add( t1, t3 ), 16384 ); + x[( length - ( i << 1 ) )] = Mpy_32_16_1( L_add( t1, t3 ), 16384 /*0.5.Q15*/ ); move32(); - x[add( sub( length, shl( i, 1 ) ), 1 )] = Mpy_32_16_1( L_negate( L_add( t2, t4 ) ), 16384 ); + x[( ( length - ( i << 1 ) ) + 1 )] = Mpy_32_16_1( L_negate( L_add( t2, t4 ) ), 16384 /*0.5.Q15*/ ); move32(); } @@ -7197,28 +7218,28 @@ void rfft_fx( case +1: - tmp = Mpy_32_16_1( L_add( x[0], x[1] ), 16384 ); - x[1] = Mpy_32_16_1( L_sub( x[1], x[0] ), 16384 ); + tmp = Mpy_32_16_1( L_add( x[0], x[1] ), 16384 /*0.5.Q15*/ ); + x[1] = Mpy_32_16_1( L_sub( x[1], x[0] ), 16384 /*0.5.Q15*/ ); move32(); x[0] = tmp; move32(); FOR( i = 1; i <= sizeOfFft4; i++ ) { - t1 = L_sub( x[2 * i], x[sub( length, shl( i, 1 ) )] ); - t2 = L_add( x[add( shl( i, 1 ), 1 )], x[add( sub( length, shl( i, 1 ) ), 1 )] ); - t3 = L_add( Mpy_32_16_1( t1, w[i] ), Mpy_32_16_1( t2, w[add( i, sizeOfFft4 )] ) ); - t4 = L_sub( Mpy_32_16_1( t2, w[i] ), Mpy_32_16_1( t1, w[add( i, sizeOfFft4 )] ) ); - t1 = L_add( x[2 * i], x[sub( length, shl( i, 1 ) )] ); - t2 = L_sub( x[add( shl( i, 1 ), 1 )], x[add( sub( length, shl( i, 1 ) ), 1 )] ); - - x[2 * i] = Mpy_32_16_1( L_sub( t1, t3 ), 16384 ); + t1 = L_sub( x[2 * i], x[( length - ( i << 1 ) )] ); + t2 = L_add( x[( ( i << 1 ) + 1 )], x[( ( length - ( i << 1 ) ) + 1 )] ); + t3 = L_add( Mpy_32_16_1( t1, w[i] ), Mpy_32_16_1( t2, w[( i + sizeOfFft4 )] ) ); + t4 = L_sub( Mpy_32_16_1( t2, w[i] ), Mpy_32_16_1( t1, w[( i + sizeOfFft4 )] ) ); + t1 = L_add( x[2 * i], x[( length - ( i << 1 ) )] ); + t2 = L_sub( x[( ( i << 1 ) + 1 )], x[( ( length - ( i << 1 ) ) + 1 )] ); + + x[2 * i] = Mpy_32_16_1( L_sub( t1, t3 ), 16384 /*0.5.Q15*/ ); // Qx move32(); - x[add( shl( i, 1 ), 1 )] = Mpy_32_16_1( L_sub( t4, t2 ), 16384 ); + x[( ( i << 1 ) + 1 )] = Mpy_32_16_1( L_sub( t4, t2 ), 16384 /*0.5.Q15*/ ); // Qx move32(); - x[sub( length, shl( i, 1 ) )] = Mpy_32_16_1( L_add( t1, t3 ), 16384 ); + x[( length - ( i << 1 ) )] = Mpy_32_16_1( L_add( t1, t3 ), 16384 /*0.5.Q15*/ ); // Qx move32(); - x[add( sub( length, shl( i, 1 ) ), 1 )] = Mpy_32_16_1( L_add( t2, t4 ), 16384 ); + x[( ( length - ( i << 1 ) ) + 1 )] = Mpy_32_16_1( L_add( t2, t4 ), 16384 /*0.5.Q15*/ ); // Qx move32(); } @@ -7226,9 +7247,9 @@ void rfft_fx( FOR( i = 0; i < length; i += 2 ) { - x[i] = Mpy_32_16_1( x[i], s1 ); + x[i] = Mpy_32_16_1( x[i], s1 ); // Qx move32(); - x[i + 1] = Mpy_32_16_1( x[i + 1], s2 ); + x[i + 1] = Mpy_32_16_1( x[i + 1], s2 ); // Qx move32(); } diff --git a/lib_com/fft_fx_evs.c b/lib_com/fft_fx_evs.c index b09b41379..e2fce166c 100644 --- a/lib_com/fft_fx_evs.c +++ b/lib_com/fft_fx_evs.c @@ -15,9 +15,9 @@ #define FFT3_ONE_THIRD 21845 /* 1/3 in Q16 */ /* DCT related */ -#define KP559016994_16FX 1200479845 /* EDCT & EMDCT constants */ -#define KP951056516_16FX 2042378325 /* EDCT & EMDCT constants */ -#define KP587785252_16FX 1262259213 /* EDCT & EMDCT constants */ +#define KP559016994_16FX 1200479845 /* EDCT & EMDCT constants Q31*/ +#define KP951056516_16FX 2042378325 /* EDCT & EMDCT constants Q31*/ +#define KP587785252_16FX 1262259213 /* EDCT & EMDCT constants Q31*/ static void fft5_shift4_16fx( Word16 n1, Word16 *zRe, Word16 *zIm, const Word16 *Idx ); static void fft64_16fx( Word16 *x, Word16 *y, const Word16 *Idx ); @@ -45,8 +45,8 @@ static void cftmdl_fx( Word16 n, Word16 l, Word32 *a, const Word16 *w ); void DoRTFTn_fx( - Word32 *x, /* i/o : real part of input and output data */ - Word32 *y, /* i/o : imaginary part of input and output data */ + Word32 *x, /* i/o : real part of input and output data Q(x) */ + Word32 *y, /* i/o : imaginary part of input and output data Q(x) */ const Word16 n /* i : size of the FFT up to 1024 */ ) { @@ -145,7 +145,7 @@ static void bitrv2_SR_fx( m = 1; move16(); - WHILE( LT_16( shl( m, 3 ), l ) ) + WHILE( ( ( m << 3 ) < l ) ) { l = shr( l, 1 ); m = shl( m, 1 ); @@ -324,7 +324,7 @@ static void cftfsub_fx( cft1st_fx( n, a, w ); l = 8; move16(); - WHILE( ( shl( l, 2 ) < n ) ) + WHILE( ( ( l << 2 ) < n ) ) { cftmdl_fx( n, l, a, w ); l = shl( l, 2 ); @@ -695,7 +695,7 @@ static void cftmdl_fx( wk3i = extract_l( L_msu0( L_shr( L_mult( wk2r, wk1r ), 14 ), wk1i, 1 ) ); tmp = add( l, add( k, m ) ); - FOR( j = add( k, m ); j < tmp; j += 2 ) + FOR( j = k + m; j < tmp; j += 2 ) { j1 = add( j, l ); j2 = add( j1, l ); @@ -739,8 +739,8 @@ static void cftmdl_fx( static void cftbsub_fx( Word16 n, - Word32 *a, - const Word16 *w /* i : cos/sin table */ + Word32 *a, // Q(Qx+Q_edct) + const Word16 *w /* i : cos/sin table Q14 */ ) { Word16 j, j1, j2, j3, l; @@ -748,13 +748,13 @@ static void cftbsub_fx( l = 2; move16(); - IF( n > 8 ) + IF( GT_16( n, 8 ) ) { cft1st_fx( n, a, w ); l = 8; move16(); - WHILE( LT_16( shl( l, 2 ), n ) ) + WHILE( ( ( l << 2 ) < n ) ) { cftmdl_fx( n, l, a, w ); l = shl( l, 2 ); @@ -815,9 +815,9 @@ static void cftbsub_fx( static void rftfsub_fx( Word16 n, - Word32 *a, + Word32 *a, // Qx Word16 nc, - const Word16 *c ) + const Word16 *c /*Q14*/ ) { Word16 j, k, kk, ks, m, tmp; Word32 xr, xi, yr, yi; @@ -828,7 +828,7 @@ static void rftfsub_fx( tmp = shl( nc, 1 ); ks = 0; move16(); - WHILE( GE_16( tmp, m ) ) + WHILE( ( tmp >= m ) ) { ks = add( ks, 1 ); tmp = sub( tmp, m ); @@ -839,13 +839,13 @@ static void rftfsub_fx( { k = sub( n, j ); kk = add( kk, ks ); - wkr = sub( 8192, c[sub( nc, kk )] ); - wki = c[kk]; + wkr = sub( 8192 /*0.5.Q14*/, c[( nc - kk )] ); // Q14 + wki = c[kk]; // Q14 move16(); - xr = L_sub( a[j], a[k] ); - xi = L_add( a[j + 1], a[k + 1] ); - yr = L_sub( Mult_32_16( L_shl( xr, 1 ), wkr ), Mult_32_16( L_shl( xi, 1 ), wki ) ); - yi = L_add( Mult_32_16( L_shl( xi, 1 ), wkr ), Mult_32_16( L_shl( xr, 1 ), wki ) ); + xr = L_sub( a[j], a[k] ); // Qx + xi = L_add( a[j + 1], a[k + 1] ); // Qx + yr = L_sub( Mult_32_16( L_shl( xr, 1 ), wkr ), Mult_32_16( L_shl( xi, 1 ), wki ) ); // Qx + yi = L_add( Mult_32_16( L_shl( xi, 1 ), wkr ), Mult_32_16( L_shl( xr, 1 ), wki ) ); // Qx a[j] = L_sub( a[j], yr ); move32(); a[j + 1] = L_sub( a[j + 1], yi ); @@ -860,9 +860,9 @@ static void rftfsub_fx( static void rftbsub_fx( Word16 n, - Word32 *a, + Word32 *a, // Qx Word16 nc, - const Word16 *c ) + const Word16 *c /*Q14*/ ) { Word16 j, k, kk, ks, m, tmp; Word32 xr, xi, yr, yi; @@ -874,7 +874,7 @@ static void rftbsub_fx( tmp = shl( nc, 1 ); ks = 0; move16(); - WHILE( GE_16( tmp, m ) ) + WHILE( ( tmp >= m ) ) { ks = add( ks, 1 ); tmp = sub( tmp, m ); @@ -885,13 +885,13 @@ static void rftbsub_fx( { k = sub( n, j ); kk = add( kk, ks ); - wkr = sub( 8192, c[sub( nc, kk )] ); - wki = c[kk]; + wkr = sub( 8192 /*0.5.Q14*/, c[( nc - kk )] ); // Q14 + wki = c[kk]; // Q14 move16(); - xr = L_sub( a[j], a[k] ); - xi = L_add( a[j + 1], a[k + 1] ); - yr = L_add( Mult_32_16( L_shl( xr, 1 ), wkr ), Mult_32_16( L_shl( xi, 1 ), wki ) ); - yi = L_sub( Mult_32_16( L_shl( xi, 1 ), wkr ), Mult_32_16( L_shl( xr, 1 ), wki ) ); + xr = L_sub( a[j], a[k] ); // Qx + xi = L_add( a[j + 1], a[k + 1] ); // Qx + yr = L_add( Mult_32_16( L_shl( xr, 1 ), wkr ), Mult_32_16( L_shl( xi, 1 ), wki ) ); // Qx + yi = L_sub( Mult_32_16( L_shl( xi, 1 ), wkr ), Mult_32_16( L_shl( xr, 1 ), wki ) ); // Qx a[j] = L_sub( a[j], yr ); move32(); a[j + 1] = L_sub( yi, a[j + 1] ); @@ -908,9 +908,9 @@ static void rftbsub_fx( static void dctsub_fx( Word16 n, - Word32 *a, + Word32 *a, // Qx Word16 nc, - const Word16 *c ) + const Word16 *c /*Q14*/ ) { Word16 j, k, kk, ks, m, tmp; Word16 wkr, wki; @@ -922,7 +922,7 @@ static void dctsub_fx( move16(); ks = 0; move16(); - WHILE( GE_16( tmp, n ) ) + WHILE( ( tmp >= n ) ) { ks = add( ks, 1 ); tmp = sub( tmp, n ); @@ -933,15 +933,15 @@ static void dctsub_fx( { k = sub( n, j ); kk = add( kk, ks ); - wkr = sub( c[kk], c[sub( nc, kk )] ); - wki = add( c[kk], c[sub( nc, kk )] ); - xr = L_sub( Mult_32_16( L_shl( a[j], 1 ), wki ), Mult_32_16( L_shl( a[k], 1 ), wkr ) ); - a[j] = L_add( Mult_32_16( L_shl( a[j], 1 ), wkr ), Mult_32_16( L_shl( a[k], 1 ), wki ) ); + wkr = sub( c[kk], c[( nc - kk )] ); // Q14 + wki = add( c[kk], c[( nc - kk )] ); // Q14 + xr = L_sub( Mult_32_16( L_shl( a[j], 1 ), wki ), Mult_32_16( L_shl( a[k], 1 ), wkr ) ); // Qx + a[j] = L_add( Mult_32_16( L_shl( a[j], 1 ), wkr ), Mult_32_16( L_shl( a[k], 1 ), wki ) ); // Qx move32(); a[k] = xr; move32(); } - a[m] = Mult_32_16( L_shl( a[m], 1 ), c[0] ); + a[m] = Mult_32_16( L_shl( a[m], 1 ), c[0] ); // Qx move16(); } @@ -955,11 +955,11 @@ static void dctsub_fx( void edct2_fx( Word16 n, Word16 isgn, - Word16 *in, - Word32 *a, + Word16 *in, // Q(q) + Word32 *a, // Qx Word16 *q, const Word16 *ip, - const Word16 *w ) + const Word16 *w /*Q14*/ ) { Word16 j, nw, nc; Word32 xr; @@ -983,7 +983,7 @@ void edct2_fx( nc = ip[1]; move16(); - if ( n > nc ) + if ( GT_16( n, nc ) ) { nc = n; move16(); @@ -1005,13 +1005,13 @@ void edct2_fx( a[0] = L_add( a[0], xr ); move32(); - IF( n > 4 ) + IF( GT_16( n, 4 ) ) { rftbsub_fx( n, a, nc, w + nw ); bitrv2_SR_fx( n, ip + 2, a ); cftbsub_fx( n, a, w ); } - ELSE IF( n == 4 ) + ELSE IF( EQ_16( n, 4 ) ) { cftfsub_fx( n, a, w ); } @@ -1027,13 +1027,13 @@ void edct2_fx( IF( isgn >= 0 ) { - IF( n > 4 ) + IF( GT_16( n, 4 ) ) { bitrv2_SR_fx( n, ip + 2, a ); cftfsub_fx( n, a, w ); rftfsub_fx( n, a, nc, w + nw ); } - ELSE IF( n == 4 ) + ELSE IF( EQ_16( n, 4 ) ) { cftfsub_fx( n, a, w ); } @@ -1052,7 +1052,7 @@ void edct2_fx( FOR( j = 0; j < n; j++ ) { - a[j] = L_shr( a[j], 5 ); + a[j] = L_shr( a[j], 5 ); // a[j] / 32.0f move32(); } } @@ -1066,9 +1066,9 @@ void edct2_fx( static void fft5_shift4_16fx( Word16 n1, /* i : length of data */ - Word16 *zRe, /* i/o : real part of input and output data */ - Word16 *zIm, /* i/o : imaginary part of input and output data */ - const Word16 *Idx /* i : pointer of the address table */ + Word16 *zRe, /* i/o : real part of input and output data Q(Qx+Q_edct) */ + Word16 *zIm, /* i/o : imaginary part of input and output data Q(Qx+Q_edct) */ + const Word16 *Idx /* i : pointer of the address table Q0 */ ) { Word16 T1, To, T8, Tt, T9, Ts, Te, Tp, Th, Tn, T2, T3, T4, T5, T6, T7; @@ -1087,9 +1087,9 @@ static void fft5_shift4_16fx( i4 = Idx[n1 * 4]; move16(); - T1 = zRe[i0]; + T1 = zRe[i0]; // Qx move16(); - To = zIm[i0]; + To = zIm[i0]; // Qx move16(); T2 = zRe[i1]; @@ -1116,8 +1116,8 @@ static void fft5_shift4_16fx( #endif /* T9 = KP559016994 * (T4 - T7); */ #ifdef BASOP_NOGLOB - L_tmp = Mult_32_16( KP559016994_16FX, sub_sat( T4, T7 ) ); - T9 = round_fx_sat( L_tmp ); + L_tmp = Mult_32_16( KP559016994_16FX, sub_sat( T4, T7 ) ); // Q(16 +x) + T9 = round_fx_sat( L_tmp ); // Qx Ts = sub_sat( T2, T3 ); #else L_tmp = Mult_32_16( KP559016994_16FX, sub( T4, T7 ) ); @@ -1148,8 +1148,8 @@ static void fft5_shift4_16fx( #ifdef BASOP_NOGLOB /* Tn = KP559016994 * (T4 - T7); */ - L_tmp = Mult_32_16( KP559016994_16FX, sub_sat( T4, T7 ) ); - Tn = round_fx_sat( L_tmp ); + L_tmp = Mult_32_16( KP559016994_16FX, sub_sat( T4, T7 ) ); // Q(16 +x) + Tn = round_fx_sat( L_tmp ); // Qx zRe[i0] = add_sat( T1, T8 ); move16(); zIm[i0] = add_sat( To, Tp ); @@ -1164,18 +1164,18 @@ static void fft5_shift4_16fx( move16(); /* T2 = KP951056516*Te + KP587785252*Th; */ - L_tmp = Mult_32_16( KP951056516_16FX, Te ); - L_tmp = Madd_32_16( L_tmp, KP587785252_16FX, Th ); + L_tmp = Mult_32_16( KP951056516_16FX, Te ); // Q(16 +x) + L_tmp = Madd_32_16( L_tmp, KP587785252_16FX, Th ); // Q(16 +x) #ifdef BASOP_NOGLOB - T2 = round_fx_sat( L_tmp ); + T2 = round_fx_sat( L_tmp ); // Qx #else T2 = round_fx( L_tmp ); #endif /*T3 = KP951056516*Th - KP587785252*Te; */ - L_tmp = Mult_32_16( KP951056516_16FX, Th ); - L_tmp = Msub_32_16( L_tmp, KP587785252_16FX, Te ); + L_tmp = Mult_32_16( KP951056516_16FX, Th ); // Q(16 +x) + L_tmp = Msub_32_16( L_tmp, KP587785252_16FX, Te ); // Q(16 +x) #ifdef BASOP_NOGLOB - T3 = round_fx_sat( L_tmp ); + T3 = round_fx_sat( L_tmp ); // Qx #else T3 = round_fx( L_tmp ); #endif @@ -1206,23 +1206,23 @@ static void fft5_shift4_16fx( #endif /* T2 = KP951056516 * Ts + KP587785252 * Tt; */ - L_tmp = Mult_32_16( KP951056516_16FX, Ts ); - L_tmp = Madd_32_16( L_tmp, KP587785252_16FX, Tt ); + L_tmp = Mult_32_16( KP951056516_16FX, Ts ); // Q(16 +x) + L_tmp = Madd_32_16( L_tmp, KP587785252_16FX, Tt ); // Q(16 +x) #ifdef BASOP_NOGLOB - T2 = round_fx_sat( L_tmp ); + T2 = round_fx_sat( L_tmp ); // Qx #else T2 = round_fx( L_tmp ); #endif /* T3 = KP951056516 * Tt - KP587785252 * Ts; */ - L_tmp = Mult_32_16( KP951056516_16FX, Tt ); - L_tmp = Msub_32_16( L_tmp, KP587785252_16FX, Ts ); + L_tmp = Mult_32_16( KP951056516_16FX, Tt ); // Q(16 +x) + L_tmp = Msub_32_16( L_tmp, KP587785252_16FX, Ts ); // Q(16 +x) #ifdef BASOP_NOGLOB - T3 = round_fx_sat( L_tmp ); + T3 = round_fx_sat( L_tmp ); // Qx #else T3 = round_fx( L_tmp ); #endif #ifdef BASOP_NOGLOB - T6 = sub_sat( To, shr( Tp, 2 ) ); + T6 = sub_sat( To, shr( Tp, 2 ) ); // To - (Tp / 4) T4 = add_sat( Tn, T6 ); T5 = sub_sat( T6, Tn ); zIm[i4] = sub_sat( T4, T2 ); @@ -1254,9 +1254,9 @@ static void fft5_shift4_16fx( * 5-point FFT called for 32 times *-----------------------------------------------------------------*/ static void fft5_32_16fx( - Word16 *zRe, /* i/o : real part of input and output data */ - Word16 *zIm, /* i/o : imaginary part of input and output data */ - const Word16 *Idx /* i : pointer of the address table */ + Word16 *zRe, /* i/o : real part of input and output data Qx */ + Word16 *zIm, /* i/o : imaginary part of input and output data Qx */ + const Word16 *Idx /* i : pointer of the address table Q0 */ ) { Word16 T1, To, T8, Tt, T9, Ts, Te, Tp, Th, Tn, T2, T3, T4, T5, T6, T7; @@ -1277,14 +1277,14 @@ static void fft5_32_16fx( i4 = Idx[128]; move16(); - T1 = zRe[i0]; + T1 = zRe[i0]; // Qx move16(); - To = zIm[i0]; + To = zIm[i0]; // Qx move16(); - T2 = zRe[i1]; + T2 = zRe[i1]; // Qx move16(); - T3 = zRe[i4]; + T3 = zRe[i4]; // Qx move16(); #ifdef BASOP_NOGLOB @@ -1308,8 +1308,8 @@ static void fft5_32_16fx( #endif #ifdef BASOP_NOGLOB /* T9 = KP559016994 * (T4 - T7); */ - L_tmp = Mult_32_16( KP559016994_16FX, sub_sat( T4, T7 ) ); - T9 = round_fx_sat( L_tmp ); + L_tmp = Mult_32_16( KP559016994_16FX, sub_sat( T4, T7 ) ); // Q(16 +x) + T9 = round_fx_sat( L_tmp ); // Qx Ts = sub_sat( T2, T3 ); T2 = zIm[i1]; @@ -1325,8 +1325,8 @@ static void fft5_32_16fx( Te = sub_sat( T2, T3 ); Tp = add_sat( T4, T7 ); Th = sub_sat( T5, T6 ); - L_tmp = Mult_32_16( KP559016994_16FX, sub_sat( T4, T7 ) ); - Tn = round_fx_sat( L_tmp ); + L_tmp = Mult_32_16( KP559016994_16FX, sub_sat( T4, T7 ) ); // Q(16 +x) + Tn = round_fx_sat( L_tmp ); // Qx #else /* T9 = KP559016994 * (T4 - T7); */ L_tmp = Mult_32_16( KP559016994_16FX, sub( T4, T7 ) ); @@ -1365,14 +1365,14 @@ static void fft5_32_16fx( #ifdef BASOP_NOGLOB /*T2 = KP951056516*Te + KP587785252*Th; */ - L_tmp = Mult_32_16( KP951056516_16FX, Te ); - L_tmp = Madd_32_16( L_tmp, KP587785252_16FX, Th ); - T2 = round_fx_sat( L_tmp ); + L_tmp = Mult_32_16( KP951056516_16FX, Te ); // Q(16 +x) + L_tmp = Madd_32_16( L_tmp, KP587785252_16FX, Th ); // Q(16 +x) + T2 = round_fx_sat( L_tmp ); // Qx /*T3 = KP951056516*Th - KP587785252*Te; */ - L_tmp = Mult_32_16( KP951056516_16FX, Th ); - L_tmp = Msub_32_16( L_tmp, KP587785252_16FX, Te ); - T3 = round_fx_sat( L_tmp ); + L_tmp = Mult_32_16( KP951056516_16FX, Th ); // Q(16 +x) + L_tmp = Msub_32_16( L_tmp, KP587785252_16FX, Te ); // Q(16 +x) + T3 = round_fx_sat( L_tmp ); // Qx T6 = sub_sat( T1, shr( T8, 2 ) ); @@ -1414,16 +1414,16 @@ static void fft5_32_16fx( #endif /* T2 = KP951056516 * Ts + KP587785252 * Tt; */ - L_tmp = Mult_32_16( KP951056516_16FX, Ts ); - L_tmp = Madd_32_16( L_tmp, KP587785252_16FX, Tt ); - T2 = round_fx_sat( L_tmp ); + L_tmp = Mult_32_16( KP951056516_16FX, Ts ); // Q(16 +x) + L_tmp = Madd_32_16( L_tmp, KP587785252_16FX, Tt ); // Q(16 +x) + T2 = round_fx_sat( L_tmp ); // Qx /* T3 = KP951056516 * Tt - KP587785252 * Ts; */ - L_tmp = Mult_32_16( KP951056516_16FX, Tt ); - L_tmp = Msub_32_16( L_tmp, KP587785252_16FX, Ts ); + L_tmp = Mult_32_16( KP951056516_16FX, Tt ); // Q(16 +x) + L_tmp = Msub_32_16( L_tmp, KP587785252_16FX, Ts ); // Q(16 +x) #ifdef BASOP_NOGLOB - T3 = round_fx_sat( L_tmp ); + T3 = round_fx_sat( L_tmp ); // Qx T6 = sub_sat( To, shr( Tp, 2 ) ); T4 = add_sat( Tn, T6 ); @@ -1460,9 +1460,9 @@ static void fft5_32_16fx( * 64-point FFT *-----------------------------------------------------------------*/ static void fft64_16fx( - Word16 *x, /* i/o : real part of input and output data */ - Word16 *y, /* i/o : imaginary part of input and output data */ - const Word16 *Idx /* i : pointer of the address table */ + Word16 *x, /* i/o : real part of input and output data Q(Qx+Q_edct) */ + Word16 *y, /* i/o : imaginary part of input and output data Q(Qx+Q_edct) */ + const Word16 *Idx /* i : pointer of the address table Q0 */ ) { Word16 i, id, jd; @@ -1502,8 +1502,8 @@ static void fft64_16fx( * 32-point FFT called for 5 times *-----------------------------------------------------------------*/ static void fft32_5_16fx( - Word16 *x, /* i/o : real part of input and output data */ - Word16 *y, /* i/o : imaginary part of input and output data */ + Word16 *x, /* i/o : real part of input and output data Q(Qx+Q_edct) */ + Word16 *y, /* i/o : imaginary part of input and output data Q(Qx+Q_edct) */ const Word16 *Idx /* i : pointer of the address table */ ) { @@ -1543,8 +1543,8 @@ static void fft32_5_16fx( * a low complexity 2-dimensional DFT of 160 points *-----------------------------------------------------------------*/ void DoRTFT160_16fx( - Word16 x[], /* i/o : real part of input and output data */ - Word16 y[] /* i/o : imaginary part of input and output data */ + Word16 x[], /* i/o : real part of input and output data Q(Qx+Q_edct) */ + Word16 y[] /* i/o : imaginary part of input and output data Q(Qx+Q_edct) */ ) { Word16 j; @@ -1569,8 +1569,8 @@ void DoRTFT160_16fx( * a low complexity 2-dimensional DFT of 320 points *-----------------------------------------------------------------*/ void DoRTFT320_16fx( - Word16 *x, /* i/o : real part of input and output data */ - Word16 *y /* i/o : imaginary part of input and output data */ + Word16 *x, /* i/o : real part of input and output data Q(Qx+Q_edct) */ + Word16 *y /* i/o : imaginary part of input and output data Q(Qx+Q_edct) */ ) { Word16 j; @@ -1664,7 +1664,7 @@ static void bitrv2_SR_16fx( m = 1; move16(); - WHILE( LT_16( shl( m, 3 ), l ) ) + WHILE( ( ( m << 3 ) < l ) ) { l = shr( l, 1 ); m = shl( m, 1 ); @@ -1846,7 +1846,7 @@ static void cftfsub_16fx( cft1st_16fx( n, a, w ); l = 8; move16(); - WHILE( LT_16( shl( l, 2 ), n ) ) + WHILE( ( ( l << 2 ) < n ) ) { cftmdl_16fx( n, l, a, w ); l = shl( l, 2 ); @@ -2756,13 +2756,13 @@ static void cftmdl_16fx( return; } -void fft3_fx( const Word16 X[], Word16 Y[], const Word16 n ) +void fft3_fx( const Word16 X[] /*Qx*/, Word16 Y[] /*Qx*/, const Word16 n ) { Word16 Z[PH_ECU_SPEC_SIZE]; Word16 *Z0, *Z1, *Z2; Word16 *z0, *z1, *z2; const Word16 *x; - const Word16 *t_sin = sincos_t_rad3_fx; + const Word16 *t_sin = sincos_t_rad3_fx; // Q15 Word16 m, mMinus1, step; Word16 i, l; Word16 c1_ind, s1_ind, c2_ind, s2_ind; @@ -2813,14 +2813,14 @@ void fft3_fx( const Word16 X[], Word16 Y[], const Word16 n ) z1 = &Z1[0]; /* Z1 = &Z[ m]; */ Z2 = &Z1[m]; z2 = &Z2[0]; /* Z2 = &Z[2m]; */ - x = &X[0]; + x = &X[0]; // Qx FOR( i = 0; i < m; i++ ) { - *z0++ = *x++; /* Z0[i] = X[3i]; */ + *z0++ = *x++; /* Z0[i] = X[3i]; Qx */ move16(); - *z1++ = *x++; /* Z1[i] = X[3i+1]; */ + *z1++ = *x++; /* Z1[i] = X[3i+1]; Qx */ move16(); - *z2++ = *x++; /* Z2[i] = X[3i+2]; */ + *z2++ = *x++; /* Z2[i] = X[3i+2]; Qx */ move16(); } mBy2 = shr( m, 1 ); @@ -2831,15 +2831,15 @@ void fft3_fx( const Word16 X[], Word16 Y[], const Word16 n ) /* Butterflies of order 3. */ /* pointer initialization */ mMinus1 = sub( m, 1 ); - RY = &Y[0]; - IY = &Y[n]; - IY--; /* Decrement the address counter.*/ - RZ0 = &Z0[0]; + RY = &Y[0]; // Qx + IY = &Y[n]; // Qx + IY--; /* Decrement the address counter.*/ + RZ0 = &Z0[0]; // Qx IZ0 = &Z0[mMinus1]; - RZ1 = &Z1[0]; - IZ1 = &Z1[mMinus1]; - RZ2 = &Z2[0]; - IZ2 = &Z2[mMinus1]; + RZ1 = &Z1[0]; // Qx + IZ1 = &Z1[mMinus1]; // Qx + RZ2 = &Z2[0]; // Qx + IZ2 = &Z2[mMinus1]; // Qx c1_step = negate( step ); s1_step = step; @@ -2854,10 +2854,10 @@ void fft3_fx( const Word16 X[], Word16 Y[], const Word16 n ) move16(); /* special case: i = 0 */ - acc = L_mult( *RZ0++, 0x4000 ); - acc = L_mac( acc, *RZ1++, 0x4000 ); + acc = L_mult( *RZ0++, 0x4000 /*1.Q14*/ ); // Q15 + Qx + acc = L_mac( acc, *RZ1++, 0x4000 /*1.Q14*/ ); // Q15 + Qx #ifdef BASOP_NOGLOB - *RY++ = mac_r_sat( acc, *RZ2++, 0x4000 ); + *RY++ = mac_r_sat( acc, *RZ2++, 0x4000 /*1.Q14*/ ); // Qx #else *RY++ = mac_r( acc, *RZ2++, 0x4000 ); #endif @@ -2867,20 +2867,20 @@ void fft3_fx( const Word16 X[], Word16 Y[], const Word16 n ) l = sub( shr( n, 3 ), 1 ); /* (3*m/8) - 1 = (n/8) - 1 */ FOR( i = 0; i < l; i++ ) { - acc = L_shl( *RZ0++, 15 ); /* Align with the following non-fractional mode so as to gain 1 more bit headroom. */ - acc = L_mac0( acc, *RZ1, t_sin[c1_ind] ); /* Non-fractional mode gains 1 more bit headroom. */ - acc = L_mac0( acc, *IZ1, t_sin[s1_ind] ); - acc = L_mac0( acc, *RZ2, t_sin[c2_ind] ); - acc = L_mac0( acc, *IZ2, t_sin[s2_ind] ); - *RY++ = round_fx( acc ); /* bit growth = 1 (compensated by non-fractional mode MAC). */ + acc = L_shl( *RZ0++, 15 ); /* Align with the following non-fractional mode so as to gain 1 more bit headroom. Q15 + Qx*/ + acc = L_mac0( acc, *RZ1, t_sin[c1_ind] ); /* Non-fractional mode gains 1 more bit headroom. Q15 + Qx*/ + acc = L_mac0( acc, *IZ1, t_sin[s1_ind] ); // Q15 + Qx + acc = L_mac0( acc, *RZ2, t_sin[c2_ind] ); // Q15 + Qx + acc = L_mac0( acc, *IZ2, t_sin[s2_ind] ); // Q15 + Qx + *RY++ = round_fx( acc ); /* bit growth = 1 (compensated by non-fractional mode MAC). Qx - 1*/ move16(); - acc = L_shl( *IZ0--, 15 ); - acc = L_msu0( acc, *RZ1++, t_sin[s1_ind] ); - acc = L_mac0( acc, *IZ1--, t_sin[c1_ind] ); - acc = L_msu0( acc, *RZ2++, t_sin[s2_ind] ); - acc = L_mac0( acc, *IZ2--, t_sin[c2_ind] ); - *IY-- = round_fx( acc ); + acc = L_shl( *IZ0--, 15 ); // Q15 + Qx + acc = L_msu0( acc, *RZ1++, t_sin[s1_ind] ); // Q15 + Qx + acc = L_mac0( acc, *IZ1--, t_sin[c1_ind] ); // Q15 + Qx + acc = L_msu0( acc, *RZ2++, t_sin[s2_ind] ); // Q15 + Qx + acc = L_mac0( acc, *IZ2--, t_sin[c2_ind] ); // Q15 + Qx + *IY-- = round_fx( acc ); // Qx - 1 move16(); c1_ind = add( c1_ind, c1_step ); @@ -2893,20 +2893,20 @@ void fft3_fx( const Word16 X[], Word16 Y[], const Word16 n ) l = shr( m, 3 ); /* (4*m/8) - (3*m/8) = m/8 */ FOR( i = 0; i < l; i++ ) { - acc = L_shl( *RZ0++, 15 ); - acc = L_mac0( acc, *RZ1, t_sin[c1_ind] ); /* Non-fractional mode gains 1 more bit headroom. */ - acc = L_mac0( acc, *IZ1, t_sin[s1_ind] ); - acc = L_msu0( acc, *RZ2, t_sin[c2_ind] ); - acc = L_mac0( acc, *IZ2, t_sin[s2_ind] ); - *RY++ = round_fx( acc ); + acc = L_shl( *RZ0++, 15 ); // Q15 + Qx + acc = L_mac0( acc, *RZ1, t_sin[c1_ind] ); /* Non-fractional mode gains 1 more bit headroom. Q15 + Qx*/ + acc = L_mac0( acc, *IZ1, t_sin[s1_ind] ); // Q15 + Qx + acc = L_msu0( acc, *RZ2, t_sin[c2_ind] ); // Q15 + Qx + acc = L_mac0( acc, *IZ2, t_sin[s2_ind] ); // Q15 + Qx + *RY++ = round_fx( acc ); // Qx - 1 move16(); - acc = L_shl( *IZ0--, 15 ); - acc = L_msu0( acc, *RZ1++, t_sin[s1_ind] ); - acc = L_mac0( acc, *IZ1--, t_sin[c1_ind] ); - acc = L_msu0( acc, *RZ2++, t_sin[s2_ind] ); - acc = L_msu0( acc, *IZ2--, t_sin[c2_ind] ); - *IY-- = round_fx( acc ); + acc = L_shl( *IZ0--, 15 ); // Q15 + Qx + acc = L_msu0( acc, *RZ1++, t_sin[s1_ind] ); // Q15 + Qx + acc = L_mac0( acc, *IZ1--, t_sin[c1_ind] ); // Q15 + Qx + acc = L_msu0( acc, *RZ2++, t_sin[s2_ind] ); // Q15 + Qx + acc = L_msu0( acc, *IZ2--, t_sin[c2_ind] ); // Q15 + Qx + *IY-- = round_fx( acc ); // Qx - 1 move16(); c1_ind = add( c1_ind, c1_step ); @@ -2916,17 +2916,17 @@ void fft3_fx( const Word16 X[], Word16 Y[], const Word16 n ) } /* special case: i = m/2 i.e. 1/3 */ - acc = L_shl( *RZ0--, 15 ); - acc = L_mac0( acc, *RZ1, t_sin[c1_ind] ); - acc = L_msu0( acc, *RZ2, t_sin[c2_ind] ); - *RY++ = round_fx( acc ); + acc = L_shl( *RZ0--, 15 ); // Q15 + Qx + acc = L_mac0( acc, *RZ1, t_sin[c1_ind] ); // Q15 + Qx + acc = L_msu0( acc, *RZ2, t_sin[c2_ind] ); // Q15 + Qx + *RY++ = round_fx( acc ); // Qx - 1 move16(); acc = 0; move32(); - acc = L_msu0( acc, *RZ1--, t_sin[s1_ind] ); - acc = L_msu0( acc, *RZ2--, t_sin[s2_ind] ); - *IY-- = round_fx( acc ); + acc = L_msu0( acc, *RZ1--, t_sin[s1_ind] ); // Q15 + Qx + acc = L_msu0( acc, *RZ2--, t_sin[s2_ind] ); // Q15 + Qx + *IY-- = round_fx( acc ); // Qx - 1 move16(); IZ0++; IZ1++; @@ -2941,20 +2941,20 @@ void fft3_fx( const Word16 X[], Word16 Y[], const Word16 n ) l = sub( shr( m, 2 ), 1 ); /* (6*m/8) - ((m/2)+1) = m/4 - 1 */ FOR( i = 0; i < l; i++ ) { - acc = L_shl( *RZ0--, 15 ); - acc = L_mac0( acc, *RZ1, t_sin[c1_ind] ); /* Non-fractional mode gains 1 more bit headroom. */ - acc = L_msu0( acc, *IZ1, t_sin[s1_ind] ); - acc = L_msu0( acc, *RZ2, t_sin[c2_ind] ); - acc = L_msu0( acc, *IZ2, t_sin[s2_ind] ); - *RY++ = round_fx( acc ); + acc = L_shl( *RZ0--, 15 ); // Q15 + Qx + acc = L_mac0( acc, *RZ1, t_sin[c1_ind] ); /* Non-fractional mode gains 1 more bit headroom. Q15 + Qx*/ + acc = L_msu0( acc, *IZ1, t_sin[s1_ind] ); // Q15 + Qx + acc = L_msu0( acc, *RZ2, t_sin[c2_ind] ); // Q15 + Qx + acc = L_msu0( acc, *IZ2, t_sin[s2_ind] ); // Q15 + Qx + *RY++ = round_fx( acc ); // Qx - 1 move16(); - acc = L_mult0( *IZ0++, -32768 ); - acc = L_msu0( acc, *RZ1--, t_sin[s1_ind] ); - acc = L_msu0( acc, *IZ1++, t_sin[c1_ind] ); - acc = L_msu0( acc, *RZ2--, t_sin[s2_ind] ); - acc = L_mac0( acc, *IZ2++, t_sin[c2_ind] ); - *IY-- = round_fx( acc ); + acc = L_mult0( *IZ0++, -32768 ); // Q15 + Qx + acc = L_msu0( acc, *RZ1--, t_sin[s1_ind] ); // Q15 + Qx + acc = L_msu0( acc, *IZ1++, t_sin[c1_ind] ); // Q15 + Qx + acc = L_msu0( acc, *RZ2--, t_sin[s2_ind] ); // Q15 + Qx + acc = L_mac0( acc, *IZ2++, t_sin[c2_ind] ); // Q15 + Qx + *IY-- = round_fx( acc ); // Qx - 1 move16(); c1_ind = add( c1_ind, c1_step ); @@ -2968,20 +2968,20 @@ void fft3_fx( const Word16 X[], Word16 Y[], const Word16 n ) l = shr( m, 2 ); FOR( i = 0; i < l; i++ ) { - acc = L_shl( *RZ0--, 15 ); - acc = L_msu0( acc, *RZ1, t_sin[c1_ind] ); /* Non-fractional mode gains 1 more bit headroom. */ - acc = L_msu0( acc, *IZ1, t_sin[s1_ind] ); - acc = L_msu0( acc, *RZ2, t_sin[c2_ind] ); - acc = L_mac0( acc, *IZ2, t_sin[s2_ind] ); - *RY++ = round_fx( acc ); + acc = L_shl( *RZ0--, 15 ); // Q15 + Qx + acc = L_msu0( acc, *RZ1, t_sin[c1_ind] ); /* Non-fractional mode gains 1 more bit headroom. Q15 + Qx*/ + acc = L_msu0( acc, *IZ1, t_sin[s1_ind] ); // Q15 + Qx + acc = L_msu0( acc, *RZ2, t_sin[c2_ind] ); // Q15 + Qx + acc = L_mac0( acc, *IZ2, t_sin[s2_ind] ); // Q15 + Qx + *RY++ = round_fx( acc ); // Qx - 1 move16(); - acc = L_mult0( *IZ0++, -32768 ); - acc = L_msu0( acc, *RZ1--, t_sin[s1_ind] ); - acc = L_mac0( acc, *IZ1++, t_sin[c1_ind] ); - acc = L_mac0( acc, *RZ2--, t_sin[s2_ind] ); - acc = L_mac0( acc, *IZ2++, t_sin[c2_ind] ); - *IY-- = round_fx( acc ); + acc = L_mult0( *IZ0++, -32768 ); // Q15 + Qx + acc = L_msu0( acc, *RZ1--, t_sin[s1_ind] ); // Q15 + Qx + acc = L_mac0( acc, *IZ1++, t_sin[c1_ind] ); // Q15 + Qx + acc = L_mac0( acc, *RZ2--, t_sin[s2_ind] ); // Q15 + Qx + acc = L_mac0( acc, *IZ2++, t_sin[c2_ind] ); // Q15 + Qx + *IY-- = round_fx( acc ); // Qx - 1 move16(); c1_ind = sub( c1_ind, c1_step ); @@ -2991,16 +2991,16 @@ void fft3_fx( const Word16 X[], Word16 Y[], const Word16 n ) } /* special case: i = m, i.e 2/3 */ - acc = L_shl( *RZ0++, 15 ); - acc = L_msu0( acc, *RZ1, t_sin[c1_ind] ); - acc = L_msu0( acc, *RZ2, t_sin[c2_ind] ); - *RY++ = round_fx( acc ); + acc = L_shl( *RZ0++, 15 ); // Q15 + Qx + acc = L_msu0( acc, *RZ1, t_sin[c1_ind] ); // Q15 + Qx + acc = L_msu0( acc, *RZ2, t_sin[c2_ind] ); // Q15 + Qx + *RY++ = round_fx( acc ); // Qx - 1 move16(); acc = L_deposit_l( 0 ); - acc = L_msu0( acc, *RZ1++, t_sin[s1_ind] ); - acc = L_mac0( acc, *RZ2++, t_sin[s2_ind] ); - *IY-- = round_fx( acc ); + acc = L_msu0( acc, *RZ1++, t_sin[s1_ind] ); // Q15 + Qx + acc = L_mac0( acc, *RZ2++, t_sin[s2_ind] ); // Q15 + Qx + *IY-- = round_fx( acc ); // Qx - 1 move16(); IZ0--; /* Just decrement the address counter */ IZ1--; @@ -3015,20 +3015,20 @@ void fft3_fx( const Word16 X[], Word16 Y[], const Word16 n ) l = sub( shr( m, 3 ), 1 ); /* (9*m/8) - (m +1) = m/8 - 1 */ FOR( i = 0; i < l; i++ ) { - acc = L_shl( *RZ0++, 15 ); - acc = L_msu0( acc, *RZ1, t_sin[c1_ind] ); /* Non-fractional mode gains 1 more bit headroom. */ - acc = L_mac0( acc, *IZ1, t_sin[s1_ind] ); - acc = L_msu0( acc, *RZ2, t_sin[c2_ind] ); - acc = L_msu0( acc, *IZ2, t_sin[s2_ind] ); - *RY++ = round_fx( acc ); + acc = L_shl( *RZ0++, 15 ); // Q15 + Qx + acc = L_msu0( acc, *RZ1, t_sin[c1_ind] ); /* Non-fractional mode gains 1 more bit headroom. Q15 + Qx*/ + acc = L_mac0( acc, *IZ1, t_sin[s1_ind] ); // Q15 + Qx + acc = L_msu0( acc, *RZ2, t_sin[c2_ind] ); // Q15 + Qx + acc = L_msu0( acc, *IZ2, t_sin[s2_ind] ); // Q15 + Qx + *RY++ = round_fx( acc ); // Qx - 1 move16(); - acc = L_shl( *IZ0--, 15 ); - acc = L_msu0( acc, *RZ1++, t_sin[s1_ind] ); - acc = L_msu0( acc, *IZ1--, t_sin[c1_ind] ); - acc = L_mac0( acc, *RZ2++, t_sin[s2_ind] ); - acc = L_msu0( acc, *IZ2--, t_sin[c2_ind] ); - *IY-- = round_fx( acc ); + acc = L_shl( *IZ0--, 15 ); // Q15 + Qx + acc = L_msu0( acc, *RZ1++, t_sin[s1_ind] ); // Q15 + Qx + acc = L_msu0( acc, *IZ1--, t_sin[c1_ind] ); // Q15 + Qx + acc = L_mac0( acc, *RZ2++, t_sin[s2_ind] ); // Q15 + Qx + acc = L_msu0( acc, *IZ2--, t_sin[c2_ind] ); // Q15 + Qx + *IY-- = round_fx( acc ); // Qx - 1 move16(); c1_ind = sub( c1_ind, c1_step ); @@ -3041,20 +3041,20 @@ void fft3_fx( const Word16 X[], Word16 Y[], const Word16 n ) l = shr( n, 3 ); /* (12*m/8) - (9*m/8) = 3*m/8 = n/8 */ FOR( i = 0; i < l; i++ ) { - acc = L_shl( *RZ0++, 15 ); - acc = L_msu0( acc, *RZ1, t_sin[c1_ind] ); /* Non-fractional mode gains 1 more bit headroom. */ - acc = L_mac0( acc, *IZ1, t_sin[s1_ind] ); - acc = L_mac0( acc, *RZ2, t_sin[c2_ind] ); - acc = L_msu0( acc, *IZ2, t_sin[s2_ind] ); - *RY++ = round_fx( acc ); + acc = L_shl( *RZ0++, 15 ); // Q15 + Qx + acc = L_msu0( acc, *RZ1, t_sin[c1_ind] ); /* Non-fractional mode gains 1 more bit headroom. Q15 + Qx*/ + acc = L_mac0( acc, *IZ1, t_sin[s1_ind] ); // Q15 + Qx + acc = L_mac0( acc, *RZ2, t_sin[c2_ind] ); // Q15 + Qx + acc = L_msu0( acc, *IZ2, t_sin[s2_ind] ); // Q15 + Qx + *RY++ = round_fx( acc ); // Qx - 1 move16(); - acc = L_shl( *IZ0--, 15 ); - acc = L_msu0( acc, *RZ1++, t_sin[s1_ind] ); - acc = L_msu0( acc, *IZ1--, t_sin[c1_ind] ); - acc = L_mac0( acc, *RZ2++, t_sin[s2_ind] ); - acc = L_mac0( acc, *IZ2--, t_sin[c2_ind] ); - *IY-- = round_fx( acc ); + acc = L_shl( *IZ0--, 15 ); // Q15 + Qx + acc = L_msu0( acc, *RZ1++, t_sin[s1_ind] ); // Q15 + Qx + acc = L_msu0( acc, *IZ1--, t_sin[c1_ind] ); // Q15 + Qx + acc = L_mac0( acc, *RZ2++, t_sin[s2_ind] ); // Q15 + Qx + acc = L_mac0( acc, *IZ2--, t_sin[c2_ind] ); // Q15 + Qx + *IY-- = round_fx( acc ); // Qx - 1 move16(); c1_ind = sub( c1_ind, c1_step ); @@ -3064,20 +3064,20 @@ void fft3_fx( const Word16 X[], Word16 Y[], const Word16 n ) } /* special case: i = 3*m/2 */ - acc = L_shl( *RZ0, 15 ); - acc = L_msu0( acc, *RZ1, t_sin[c1_ind] ); - acc = L_mac0( acc, *RZ2, t_sin[c2_ind] ); - *RY = round_fx( acc ); + acc = L_shl( *RZ0, 15 ); // Q15 + Qx + acc = L_msu0( acc, *RZ1, t_sin[c1_ind] ); // Q15 + Qx + acc = L_mac0( acc, *RZ2, t_sin[c2_ind] ); // Q15 + Qx + *RY = round_fx( acc ); // Qx - 1 move16(); return; } -void ifft3_fx( const Word16 Z[], Word16 X[], const Word16 n ) +void ifft3_fx( const Word16 Z[] /*Qx*/, Word16 X[] /*Qx*/, const Word16 n ) { Word16 Y[PH_ECU_SPEC_SIZE]; - const Word16 *t_sin = sincos_t_rad3_fx; + const Word16 *t_sin = sincos_t_rad3_fx; // Q15 Word16 m, mMinus1, step, step2; Word16 i, l; Word16 c0_ind, s0_ind, c1_ind, s1_ind, c2_ind, s2_ind; @@ -3124,19 +3124,19 @@ void ifft3_fx( const Word16 Z[], Word16 X[], const Word16 n ) nMinusMBy2 = shr( sub( n, m ), 1 ); mMinus1 = sub( m, 1 ); /* pointer initialization */ - RY0 = &Y[0]; - IY0 = &Y[m]; - RY1 = &RY0[m]; - IY1 = &RY1[mMinus1]; - RY2 = &RY1[m]; - IY2 = &RY2[mMinus1]; - - RZ00 = &Z[0]; /* The zero positions of the pointers */ - RZ10 = &RZ00[m]; - RZ20 = &RZ00[nMinusMBy2]; - IZ00 = &Z[n]; - IZ10 = &IZ00[-m]; - IZ20 = &IZ00[-nMinusMBy2]; + RY0 = &Y[0]; // Qx + IY0 = &Y[m]; // Qx + RY1 = &RY0[m]; // Qx + IY1 = &RY1[mMinus1]; // Qx + RY2 = &RY1[m]; // Qx + IY2 = &RY2[mMinus1]; // Qx + + RZ00 = &Z[0]; /* The zero positions of the pointers Qx*/ + RZ10 = &RZ00[m]; // Qx + RZ20 = &RZ00[nMinusMBy2]; // Qx + IZ00 = &Z[n]; // Qx + IZ10 = &IZ00[-m]; // Qx + IZ20 = &IZ00[-nMinusMBy2]; // Qx RZ0 = RZ00; /* Reset the pointers to zero positions. */ RZ1 = RZ10; @@ -3148,9 +3148,9 @@ void ifft3_fx( const Word16 Z[], Word16 X[], const Word16 n ) /* Inverse butterflies of order 3. */ /* Construction of Y0 */ - acc = L_mult( *RZ0++, 0x4000 ); - acc = L_mac( acc, *RZ1++, 0x4000 ); - *RY0++ = mac_r( acc, *RZ2--, 0x4000 ); + acc = L_mult( *RZ0++, 0x4000 /*1.Q14*/ ); // Qx + Q15 + acc = L_mac( acc, *RZ1++, 0x4000 /*1.Q14*/ ); // Qx + Q15 + *RY0++ = mac_r( acc, *RZ2--, 0x4000 /*1.Q14*/ ); // Qx move16(); IZ0--; IZ1--; @@ -3160,21 +3160,21 @@ void ifft3_fx( const Word16 Z[], Word16 X[], const Word16 n ) l = sub( shr( m, 1 ), 1 ); FOR( i = 0; i < l; i++ ) { - acc = L_mult( *RZ0++, 0x4000 ); - acc = L_mac( acc, *RZ1++, 0x4000 ); - *RY0++ = mac_r( acc, *RZ2--, 0x4000 ); + acc = L_mult( *RZ0++, 0x4000 /*1.Q14*/ ); // Qx + Q15 + acc = L_mac( acc, *RZ1++, 0x4000 /*1.Q14*/ ); // Qx + Q15 + *RY0++ = mac_r( acc, *RZ2--, 0x4000 /*1.Q14*/ ); // Qx move16(); - acc = L_mult( *IZ0--, 0x4000 ); - acc = L_mac( acc, *IZ1--, 0x4000 ); - *IY0-- = msu_r( acc, *IZ2++, 0x4000 ); + acc = L_mult( *IZ0--, 0x4000 /*1.Q14*/ ); // Qx + Q15 + acc = L_mac( acc, *IZ1--, 0x4000 /*1.Q14*/ ); // Qx + Q15 + *IY0-- = msu_r( acc, *IZ2++, 0x4000 /*1.Q14*/ ); // Qx move16(); } /* m/2 */ - acc = L_mult( *RZ0, 0x4000 ); - acc = L_mac( acc, *RZ1, 0x4000 ); - *RY0++ = mac_r( acc, *RZ2, 0x4000 ); + acc = L_mult( *RZ0, 0x4000 /*1.Q14*/ ); // Qx + Q15 + acc = L_mac( acc, *RZ1, 0x4000 /*1.Q14*/ ); // Qx + Q15 + *RY0++ = mac_r( acc, *RZ2, 0x4000 /*1.Q14*/ ); // Qx move16(); @@ -3192,13 +3192,13 @@ void ifft3_fx( const Word16 Z[], Word16 X[], const Word16 n ) IZ0 = IZ00; IZ1 = IZ10; IZ2 = IZ20; - acc = L_mult0( *RZ0++, t_sin[c0_ind] ); - acc = L_msu0( acc, *RZ1++, t_sin[c1_ind] ); - acc = L_msu0( acc, *RZ2--, t_sin[c2_ind] ); + acc = L_mult0( *RZ0++, t_sin[c0_ind] ); // Qx + Q15 + acc = L_msu0( acc, *RZ1++, t_sin[c1_ind] ); // Qx + Q15 + acc = L_msu0( acc, *RZ2--, t_sin[c2_ind] ); // Qx + Q15 IZ0--; - acc = L_msu0( acc, *IZ1--, t_sin[s1_ind] ); - acc = L_msu0( acc, *IZ2++, t_sin[s2_ind] ); - *RY1++ = round_fx( acc ); + acc = L_msu0( acc, *IZ1--, t_sin[s1_ind] ); // Qx + Q15 + acc = L_msu0( acc, *IZ2++, t_sin[s2_ind] ); // Qx + Q15 + *RY1++ = round_fx( acc ); // Qx - 1 move16(); c0_ind = sub( c0_ind, step ); @@ -3212,22 +3212,22 @@ void ifft3_fx( const Word16 Z[], Word16 X[], const Word16 n ) l = sub( shr( m, 2 ), 1 ); FOR( i = 0; i < l; i++ ) { - acc = L_mult0( *RZ0, t_sin[c0_ind] ); - acc = L_msu0( acc, *RZ1, t_sin[c1_ind] ); - acc = L_msu0( acc, *RZ2, t_sin[c2_ind] ); - acc = L_msu0( acc, *IZ0, t_sin[s0_ind] ); - acc = L_msu0( acc, *IZ1, t_sin[s1_ind] ); - acc = L_msu0( acc, *IZ2, t_sin[s2_ind] ); - *RY1++ = round_fx( acc ); + acc = L_mult0( *RZ0, t_sin[c0_ind] ); // Qx + Q15 + acc = L_msu0( acc, *RZ1, t_sin[c1_ind] ); // Qx + Q15 + acc = L_msu0( acc, *RZ2, t_sin[c2_ind] ); // Qx + Q15 + acc = L_msu0( acc, *IZ0, t_sin[s0_ind] ); // Qx + Q15 + acc = L_msu0( acc, *IZ1, t_sin[s1_ind] ); // Qx + Q15 + acc = L_msu0( acc, *IZ2, t_sin[s2_ind] ); // Qx + Q15 + *RY1++ = round_fx( acc ); // Qx - 1 move16(); - acc = L_mult0( *IZ0--, t_sin[c0_ind] ); - acc = L_msu0( acc, *IZ1--, t_sin[c1_ind] ); - acc = L_mac0( acc, *IZ2++, t_sin[c2_ind] ); - acc = L_mac0( acc, *RZ0++, t_sin[s0_ind] ); - acc = L_mac0( acc, *RZ1++, t_sin[s1_ind] ); - acc = L_msu0( acc, *RZ2--, t_sin[s2_ind] ); - *IY1-- = round_fx( acc ); + acc = L_mult0( *IZ0--, t_sin[c0_ind] ); // Qx + Q15 + acc = L_msu0( acc, *IZ1--, t_sin[c1_ind] ); // Qx + Q15 + acc = L_mac0( acc, *IZ2++, t_sin[c2_ind] ); // Qx + Q15 + acc = L_mac0( acc, *RZ0++, t_sin[s0_ind] ); // Qx + Q15 + acc = L_mac0( acc, *RZ1++, t_sin[s1_ind] ); // Qx + Q15 + acc = L_msu0( acc, *RZ2--, t_sin[s2_ind] ); // Qx + Q15 + *IY1-- = round_fx( acc ); // Qx - 1 move16(); c0_ind = sub( c0_ind, step ); @@ -3242,22 +3242,22 @@ void ifft3_fx( const Word16 Z[], Word16 X[], const Word16 n ) l = shr( m, 2 ); /* m/2 - m/4 = m/4 */ FOR( i = 0; i < l; i++ ) { - acc = L_mult0( *RZ0, t_sin[c0_ind] ); - acc = L_msu0( acc, *RZ1, t_sin[c1_ind] ); - acc = L_mac0( acc, *RZ2, t_sin[c2_ind] ); - acc = L_msu0( acc, *IZ0, t_sin[s0_ind] ); - acc = L_msu0( acc, *IZ1, t_sin[s1_ind] ); - acc = L_msu0( acc, *IZ2, t_sin[s2_ind] ); - *RY1++ = round_fx( acc ); + acc = L_mult0( *RZ0, t_sin[c0_ind] ); // Qx + Q15 + acc = L_msu0( acc, *RZ1, t_sin[c1_ind] ); // Qx + Q15 + acc = L_mac0( acc, *RZ2, t_sin[c2_ind] ); // Qx + Q15 + acc = L_msu0( acc, *IZ0, t_sin[s0_ind] ); // Qx + Q15 + acc = L_msu0( acc, *IZ1, t_sin[s1_ind] ); // Qx + Q15 + acc = L_msu0( acc, *IZ2, t_sin[s2_ind] ); // Qx + Q15 + *RY1++ = round_fx( acc ); // Qx - 1 move16(); - acc = L_mult0( *IZ0--, t_sin[c0_ind] ); - acc = L_msu0( acc, *IZ1--, t_sin[c1_ind] ); - acc = L_msu0( acc, *IZ2++, t_sin[c2_ind] ); - acc = L_mac0( acc, *RZ0++, t_sin[s0_ind] ); - acc = L_mac0( acc, *RZ1++, t_sin[s1_ind] ); - acc = L_msu0( acc, *RZ2--, t_sin[s2_ind] ); - *IY1-- = round_fx( acc ); + acc = L_mult0( *IZ0--, t_sin[c0_ind] ); // Qx + Q15 + acc = L_msu0( acc, *IZ1--, t_sin[c1_ind] ); // Qx + Q15 + acc = L_msu0( acc, *IZ2++, t_sin[c2_ind] ); // Qx + Q15 + acc = L_mac0( acc, *RZ0++, t_sin[s0_ind] ); // Qx + Q15 + acc = L_mac0( acc, *RZ1++, t_sin[s1_ind] ); // Qx + Q15 + acc = L_msu0( acc, *RZ2--, t_sin[s2_ind] ); // Qx + Q15 + *IY1-- = round_fx( acc ); // Qx - 1 move16(); c0_ind = sub( c0_ind, step ); @@ -3269,13 +3269,13 @@ void ifft3_fx( const Word16 Z[], Word16 X[], const Word16 n ) } /* m/2 */ - acc = L_mult0( *RZ0, t_sin[c0_ind] ); - acc = L_msu0( acc, *RZ1, t_sin[c1_ind] ); - acc = L_mac0( acc, *RZ2, t_sin[c2_ind] ); - acc = L_msu0( acc, *IZ0, t_sin[s0_ind] ); - acc = L_msu0( acc, *IZ1, t_sin[s1_ind] ); - acc = L_msu0( acc, *IZ2, t_sin[s2_ind] ); - *RY1++ = round_fx( acc ); + acc = L_mult0( *RZ0, t_sin[c0_ind] ); // Qx + Q15 + acc = L_msu0( acc, *RZ1, t_sin[c1_ind] ); // Qx + Q15 + acc = L_mac0( acc, *RZ2, t_sin[c2_ind] ); // Qx + Q15 + acc = L_msu0( acc, *IZ0, t_sin[s0_ind] ); // Qx + Q15 + acc = L_msu0( acc, *IZ1, t_sin[s1_ind] ); // Qx + Q15 + acc = L_msu0( acc, *IZ2, t_sin[s2_ind] ); // Qx + Q15 + *RY1++ = round_fx( acc ); // Qx - 1 move16(); /* Construction of Y2 */ @@ -3293,13 +3293,13 @@ void ifft3_fx( const Word16 Z[], Word16 X[], const Word16 n ) IZ0 = IZ00; IZ1 = IZ10; IZ2 = IZ20; - acc = L_mult0( *RZ0++, t_sin[c0_ind] ); - acc = L_msu0( acc, *RZ1++, t_sin[c1_ind] ); - acc = L_msu0( acc, *RZ2--, t_sin[c2_ind] ); + acc = L_mult0( *RZ0++, t_sin[c0_ind] ); // Qx + Q15 + acc = L_msu0( acc, *RZ1++, t_sin[c1_ind] ); // Qx + Q15 + acc = L_msu0( acc, *RZ2--, t_sin[c2_ind] ); // Qx + Q15 IZ0--; - acc = L_mac0( acc, *IZ1--, t_sin[s1_ind] ); - acc = L_mac0( acc, *IZ2++, t_sin[s2_ind] ); - *RY2++ = round_fx( acc ); + acc = L_mac0( acc, *IZ1--, t_sin[s1_ind] ); // Qx + Q15 + acc = L_mac0( acc, *IZ2++, t_sin[s2_ind] ); // Qx + Q15 + *RY2++ = round_fx( acc ); // Qx - 1 move16(); c0_ind = sub( c0_ind, step2 ); @@ -3313,22 +3313,22 @@ void ifft3_fx( const Word16 Z[], Word16 X[], const Word16 n ) l = sub( shr( m, 3 ), 1 ); /* m/8 - 1. */ FOR( i = 0; i < l; i++ ) { - acc = L_mult0( *RZ0, t_sin[c0_ind] ); - acc = L_msu0( acc, *RZ1, t_sin[c1_ind] ); - acc = L_msu0( acc, *RZ2, t_sin[c2_ind] ); - acc = L_msu0( acc, *IZ0, t_sin[s0_ind] ); - acc = L_mac0( acc, *IZ1, t_sin[s1_ind] ); - acc = L_mac0( acc, *IZ2, t_sin[s2_ind] ); - *RY2++ = round_fx( acc ); + acc = L_mult0( *RZ0, t_sin[c0_ind] ); // Qx + Q15 + acc = L_msu0( acc, *RZ1, t_sin[c1_ind] ); // Qx + Q15 + acc = L_msu0( acc, *RZ2, t_sin[c2_ind] ); // Qx + Q15 + acc = L_msu0( acc, *IZ0, t_sin[s0_ind] ); // Qx + Q15 + acc = L_mac0( acc, *IZ1, t_sin[s1_ind] ); // Qx + Q15 + acc = L_mac0( acc, *IZ2, t_sin[s2_ind] ); // Qx + Q15 + *RY2++ = round_fx( acc ); // Qx - 1 move16(); - acc = L_mult0( *IZ0--, t_sin[c0_ind] ); - acc = L_msu0( acc, *IZ1--, t_sin[c1_ind] ); - acc = L_mac0( acc, *IZ2++, t_sin[c2_ind] ); - acc = L_mac0( acc, *RZ0++, t_sin[s0_ind] ); - acc = L_msu0( acc, *RZ1++, t_sin[s1_ind] ); - acc = L_mac0( acc, *RZ2--, t_sin[s2_ind] ); - *IY2-- = round_fx( acc ); + acc = L_mult0( *IZ0--, t_sin[c0_ind] ); // Qx + Q15 + acc = L_msu0( acc, *IZ1--, t_sin[c1_ind] ); // Qx + Q15 + acc = L_mac0( acc, *IZ2++, t_sin[c2_ind] ); // Qx + Q15 + acc = L_mac0( acc, *RZ0++, t_sin[s0_ind] ); // Qx + Q15 + acc = L_msu0( acc, *RZ1++, t_sin[s1_ind] ); // Qx + Q15 + acc = L_mac0( acc, *RZ2--, t_sin[s2_ind] ); // Qx + Q15 + *IY2-- = round_fx( acc ); // Qx - 1 move16(); c0_ind = sub( c0_ind, step2 ); @@ -3343,22 +3343,22 @@ void ifft3_fx( const Word16 Z[], Word16 X[], const Word16 n ) l = shr( m, 3 ); /* m/4 - m/8 = m/8 */ FOR( i = 0; i < l; i++ ) { - acc = L_mult0( *RZ0, t_sin[c0_ind] ); - acc = L_mac0( acc, *RZ1, t_sin[c1_ind] ); - acc = L_msu0( acc, *RZ2, t_sin[c2_ind] ); - acc = L_msu0( acc, *IZ0, t_sin[s0_ind] ); - acc = L_mac0( acc, *IZ1, t_sin[s1_ind] ); - acc = L_mac0( acc, *IZ2, t_sin[s2_ind] ); - *RY2++ = round_fx( acc ); + acc = L_mult0( *RZ0, t_sin[c0_ind] ); // Qx + Q15 + acc = L_mac0( acc, *RZ1, t_sin[c1_ind] ); // Qx + Q15 + acc = L_msu0( acc, *RZ2, t_sin[c2_ind] ); // Qx + Q15 + acc = L_msu0( acc, *IZ0, t_sin[s0_ind] ); // Qx + Q15 + acc = L_mac0( acc, *IZ1, t_sin[s1_ind] ); // Qx + Q15 + acc = L_mac0( acc, *IZ2, t_sin[s2_ind] ); // Qx + Q15 + *RY2++ = round_fx( acc ); // Qx - 1 move16(); - acc = L_mult0( *IZ0--, t_sin[c0_ind] ); - acc = L_mac0( acc, *IZ1--, t_sin[c1_ind] ); - acc = L_mac0( acc, *IZ2++, t_sin[c2_ind] ); - acc = L_mac0( acc, *RZ0++, t_sin[s0_ind] ); - acc = L_msu0( acc, *RZ1++, t_sin[s1_ind] ); - acc = L_mac0( acc, *RZ2--, t_sin[s2_ind] ); - *IY2-- = round_fx( acc ); + acc = L_mult0( *IZ0--, t_sin[c0_ind] ); // Qx + Q15 + acc = L_mac0( acc, *IZ1--, t_sin[c1_ind] ); // Qx + Q15 + acc = L_mac0( acc, *IZ2++, t_sin[c2_ind] ); // Qx + Q15 + acc = L_mac0( acc, *RZ0++, t_sin[s0_ind] ); // Qx + Q15 + acc = L_msu0( acc, *RZ1++, t_sin[s1_ind] ); // Qx + Q15 + acc = L_mac0( acc, *RZ2--, t_sin[s2_ind] ); // Qx + Q15 + *IY2-- = round_fx( acc ); // Qx - 1 move16(); c0_ind = sub( c0_ind, step2 ); @@ -3373,22 +3373,22 @@ void ifft3_fx( const Word16 Z[], Word16 X[], const Word16 n ) l = shr( m, 3 ); /* 3*m/8 - m/4 = m/8 */ FOR( i = 0; i < l; i++ ) { - acc = L_mult0( *RZ0, t_sin[c0_ind] ); - acc = L_mac0( acc, *RZ1, t_sin[c1_ind] ); - acc = L_msu0( acc, *RZ2, t_sin[c2_ind] ); - acc = L_msu0( acc, *IZ0, t_sin[s0_ind] ); - acc = L_mac0( acc, *IZ1, t_sin[s1_ind] ); - acc = L_msu0( acc, *IZ2, t_sin[s2_ind] ); - *RY2++ = round_fx( acc ); + acc = L_mult0( *RZ0, t_sin[c0_ind] ); // Qx + Q15 + acc = L_mac0( acc, *RZ1, t_sin[c1_ind] ); // Qx + Q15 + acc = L_msu0( acc, *RZ2, t_sin[c2_ind] ); // Qx + Q15 + acc = L_msu0( acc, *IZ0, t_sin[s0_ind] ); // Qx + Q15 + acc = L_mac0( acc, *IZ1, t_sin[s1_ind] ); // Qx + Q15 + acc = L_msu0( acc, *IZ2, t_sin[s2_ind] ); // Qx + Q15 + *RY2++ = round_fx( acc ); // Qx - 1 move16(); - acc = L_mult0( *IZ0--, t_sin[c0_ind] ); - acc = L_mac0( acc, *IZ1--, t_sin[c1_ind] ); - acc = L_mac0( acc, *IZ2++, t_sin[c2_ind] ); - acc = L_mac0( acc, *RZ0++, t_sin[s0_ind] ); - acc = L_msu0( acc, *RZ1++, t_sin[s1_ind] ); - acc = L_msu0( acc, *RZ2--, t_sin[s2_ind] ); - *IY2-- = round_fx( acc ); + acc = L_mult0( *IZ0--, t_sin[c0_ind] ); // Qx + Q15 + acc = L_mac0( acc, *IZ1--, t_sin[c1_ind] ); // Qx + Q15 + acc = L_mac0( acc, *IZ2++, t_sin[c2_ind] ); // Qx + Q15 + acc = L_mac0( acc, *RZ0++, t_sin[s0_ind] ); // Qx + Q15 + acc = L_msu0( acc, *RZ1++, t_sin[s1_ind] ); // Qx + Q15 + acc = L_msu0( acc, *RZ2--, t_sin[s2_ind] ); // Qx + Q15 + *IY2-- = round_fx( acc ); // Qx - 1 move16(); c0_ind = sub( c0_ind, step2 ); @@ -3403,22 +3403,22 @@ void ifft3_fx( const Word16 Z[], Word16 X[], const Word16 n ) l = shr( m, 3 ); /* m/2 - 3*m/8 = m/8 */ FOR( i = 0; i < l; i++ ) { - acc = L_mult0( *RZ1, t_sin[c1_ind] ); - acc = L_msu0( acc, *RZ0, t_sin[c0_ind] ); - acc = L_msu0( acc, *RZ2, t_sin[c2_ind] ); - acc = L_msu0( acc, *IZ0, t_sin[s0_ind] ); - acc = L_mac0( acc, *IZ1, t_sin[s1_ind] ); - acc = L_msu0( acc, *IZ2, t_sin[s2_ind] ); - *RY2++ = round_fx( acc ); + acc = L_mult0( *RZ1, t_sin[c1_ind] ); // Qx + Q15 + acc = L_msu0( acc, *RZ0, t_sin[c0_ind] ); // Qx + Q15 + acc = L_msu0( acc, *RZ2, t_sin[c2_ind] ); // Qx + Q15 + acc = L_msu0( acc, *IZ0, t_sin[s0_ind] ); // Qx + Q15 + acc = L_mac0( acc, *IZ1, t_sin[s1_ind] ); // Qx + Q15 + acc = L_msu0( acc, *IZ2, t_sin[s2_ind] ); // Qx + Q15 + *RY2++ = round_fx( acc ); // Qx - 1 move16(); - acc = L_mult0( *IZ1--, t_sin[c1_ind] ); - acc = L_msu0( acc, *IZ0--, t_sin[c0_ind] ); - acc = L_mac0( acc, *IZ2++, t_sin[c2_ind] ); - acc = L_mac0( acc, *RZ0++, t_sin[s0_ind] ); - acc = L_msu0( acc, *RZ1++, t_sin[s1_ind] ); - acc = L_msu0( acc, *RZ2--, t_sin[s2_ind] ); - *IY2-- = round_fx( acc ); + acc = L_mult0( *IZ1--, t_sin[c1_ind] ); // Qx + Q15 + acc = L_msu0( acc, *IZ0--, t_sin[c0_ind] ); // Qx + Q15 + acc = L_mac0( acc, *IZ2++, t_sin[c2_ind] ); // Qx + Q15 + acc = L_mac0( acc, *RZ0++, t_sin[s0_ind] ); // Qx + Q15 + acc = L_msu0( acc, *RZ1++, t_sin[s1_ind] ); // Qx + Q15 + acc = L_msu0( acc, *RZ2--, t_sin[s2_ind] ); // Qx + Q15 + *IY2-- = round_fx( acc ); // Qx - 1 move16(); c0_ind = add( c0_ind, step2 ); @@ -3430,13 +3430,13 @@ void ifft3_fx( const Word16 Z[], Word16 X[], const Word16 n ) } /* m/2 */ - acc = L_mult0( *RZ1, t_sin[c1_ind] ); - acc = L_msu0( acc, *RZ0, t_sin[c0_ind] ); - acc = L_msu0( acc, *RZ2, t_sin[c2_ind] ); - acc = L_msu0( acc, *IZ0, t_sin[s0_ind] ); - acc = L_mac0( acc, *IZ1, t_sin[s1_ind] ); - acc = L_msu0( acc, *IZ2, t_sin[s2_ind] ); - *RY2++ = round_fx( acc ); + acc = L_mult0( *RZ1, t_sin[c1_ind] ); // Qx + Q15 + acc = L_msu0( acc, *RZ0, t_sin[c0_ind] ); // Qx + Q15 + acc = L_msu0( acc, *RZ2, t_sin[c2_ind] ); // Qx + Q15 + acc = L_msu0( acc, *IZ0, t_sin[s0_ind] ); // Qx + Q15 + acc = L_mac0( acc, *IZ1, t_sin[s1_ind] ); // Qx + Q15 + acc = L_msu0( acc, *IZ2, t_sin[s2_ind] ); // Qx + Q15 + *RY2++ = round_fx( acc ); // Qx - 1 move16(); /* Compute the inverse FFT for all 3 blocks. */ @@ -3457,11 +3457,11 @@ void ifft3_fx( const Word16 Z[], Word16 X[], const Word16 n ) FOR( i = 0; i < m; i++ ) { #ifdef BASOP_NOGLOB - *pX++ = shl_sat( mult_r( *y0++, FFT3_ONE_THIRD ), 1 ); + *pX++ = shl_sat( mult_r( *y0++, FFT3_ONE_THIRD ), 1 ); // Qx move16(); - *pX++ = shl_sat( mult_r( *y1++, FFT3_ONE_THIRD ), 1 ); + *pX++ = shl_sat( mult_r( *y1++, FFT3_ONE_THIRD ), 1 ); // Qx move16(); - *pX++ = shl_sat( mult_r( *y2++, FFT3_ONE_THIRD ), 1 ); + *pX++ = shl_sat( mult_r( *y2++, FFT3_ONE_THIRD ), 1 ); // Qx move16(); #else *pX++ = shl( mult_r( *y0++, FFT3_ONE_THIRD ), 1 ); diff --git a/lib_com/ppp_fx.c b/lib_com/ppp_fx.c index 390c0a47c..92831ce2b 100644 --- a/lib_com/ppp_fx.c +++ b/lib_com/ppp_fx.c @@ -57,7 +57,13 @@ /* NOTE: this function uses a 5 entry table frac_fx (Q4 unsigned) */ /*===================================================================*/ -void Interpol_delay_fx( Word16 *out_fx, Word16 last_fx, Word16 current_fx, Word16 SubNum, const Word16 *frac_fx ) +void Interpol_delay_fx( + Word16 *out_fx, /* Q4 */ + Word16 last_fx, /* Q0 */ + Word16 current_fx, /* Q0 */ + Word16 SubNum, /* Q0 */ + const Word16 *frac_fx /* Q4 */ +) { Word16 i, temp; Word32 L_add1, L_add2; @@ -81,17 +87,19 @@ void Interpol_delay_fx( Word16 *out_fx, Word16 last_fx, Word16 current_fx, Word1 *--------------------------------------------------------------------*/ void deemph_lpc_fx( - const Word16 *p_Aq_curr_fx, /* i : LP coefficients current frame */ - const Word16 *p_Aq_old_fx, /* i : LP coefficients previous frame */ + const Word16 *p_Aq_curr_fx, /* i : LP coefficients current frame Q12 */ + const Word16 *p_Aq_old_fx, /* i : LP coefficients previous frame Q12 */ Word16 *LPC_de_curr_fx, /* o : De-emphasized LP coefficients current frame in Q12 */ Word16 *LPC_de_old_fx, /* o : De-emphasized LP coefficients previous frame in Q12 */ - const Word16 deemph_old ) + const Word16 deemph_old /* Q0 */ +) { Word16 k, temp; Word16 b_fx[M + 2]; /* Q12 */ Word16 a_fx[2] = { -22282, 32767 }; /* Q15 {-PREEMPH_FAC,1.0} */ #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif b_fx[0] = 4096; move16(); /* 1 in Q12 */ @@ -123,7 +131,7 @@ void deemph_lpc_fx( move16(); /* 1 in Q12 */ FOR( k = 0; k < M; k++ ) { - b_fx[k + 1] = p_Aq_old_fx[k + 1]; + b_fx[k + 1] = p_Aq_old_fx[k + 1]; /* Q12 */ move16(); } b_fx[M + 1] = 0; diff --git a/lib_com/pred_lt4_fx.c b/lib_com/pred_lt4_fx.c index 21bd9f541..935e6b33f 100644 --- a/lib_com/pred_lt4_fx.c +++ b/lib_com/pred_lt4_fx.c @@ -21,14 +21,14 @@ *-------------------------------------------------------------------*/ void pred_lt4( - const Word16 excI[], /* in : excitation buffer */ - Word16 excO[], /* out: excitation buffer */ - const Word16 T0, /* input : integer pitch lag */ - Word16 frac, /* input : fraction of lag */ - const Word16 L_subfr, /* input : subframe size */ - const Word16 *win, /* i : interpolation window */ - const Word16 nb_coef, /* i : nb of filter coef */ - const Word16 up_sample /* i : up_sample */ + const Word16 excI[], /* in : excitation buffer Q_exc*/ + Word16 excO[], /* out: excitation buffer Q_exc*/ + const Word16 T0, /* input : integer pitch lag Q0*/ + Word16 frac, /* input : fraction of lag Q0*/ + const Word16 L_subfr, /* input : subframe size Q0*/ + const Word16 *win, /* i : interpolation window Q14*/ + const Word16 nb_coef, /* i : nb of filter coef Q0*/ + const Word16 up_sample /* i : up_sample Q0*/ ) { Word16 i, j; @@ -36,6 +36,7 @@ void pred_lt4( const Word16 *x0, *x1, *x2, *c1, *c2; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif x0 = &excI[-T0]; @@ -44,16 +45,16 @@ void pred_lt4( IF( frac < 0 ) { - frac = add( frac, up_sample ); + frac = add( frac, up_sample ); /* Q0 */ x0--; } FOR( j = 0; j < L_subfr; j++ ) { - x1 = x0++; - x2 = x1 + 1; - c1 = ( &win[frac] ); - c2 = ( &win[up_sample - frac] ); + x1 = x0++; /* Q_exc */ + x2 = x1 + 1; /* Q_exc */ + c1 = ( &win[frac] ); /* Q14 */ + c2 = ( &win[up_sample - frac] ); /* Q14 */ { Word64 s64 = 0; @@ -61,24 +62,25 @@ void pred_lt4( FOR( i = 0; i < nb_coef; i++ ) { /*s += (*x1--) * (*c1) + (*x2++) * (*c2);*/ - s64 = W_mac0_16_16( s64, ( *x1-- ), ( *c1 ) ); - s64 = W_mac0_16_16( s64, ( *x2++ ), ( *c2 ) ); + s64 = W_mac0_16_16( s64, ( *x1-- ), ( *c1 ) ); /* Q_exc + Q14 */ + s64 = W_mac0_16_16( s64, ( *x2++ ), ( *c2 ) ); /* Q_exc + Q14 */ c1 += up_sample; c2 += up_sample; } - s = W_sat_l( s64 ); + s = W_sat_l( s64 ); /* Q_exc + Q14 */ } #if ( INTERP_EXP != -1 ) #ifdef BASOP_NOGLOB - s = L_shl_o( s, INTERP_EXP + 1, &Overflow ); -#else /* BASOP_NOGLOB */ + s = L_shl_o( s, INTERP_EXP + 1, &Overflow ); /* Q_exc + Q15 */ +#else /* BASOP_NOGLOB */ s = L_shl( s, INTERP_EXP + 1 ); -#endif /* BASOP_NOGLOB */ +#endif /* BASOP_NOGLOB */ #endif #ifdef BASOP_NOGLOB - excO[j] = round_fx_o( s, &Overflow ); + excO[j] = round_fx_o( s, &Overflow ); /* Q_exc */ + move16(); #else /* BASOP_NOGLOB */ excO[j] = round_fx( s ); #endif @@ -113,12 +115,12 @@ void pred_lt4( /* NONE */ /*=======================================================================*/ void pred_lt4_tc_fx( - Word16 exc[], /* i/o: excitation buffer */ - const Word16 T0, /* i : integer pitch lag */ - Word16 frac, /* i: fraction of lag */ - const Word16 *win, /* i : interpolation window */ - const Word16 imp_pos, /* i : glottal impulse position */ - const Word16 i_subfr /* i : subframe index */ + Word16 exc[], /* i/o: excitation buffer Q0*/ + const Word16 T0, /* i : integer pitch lag Q0*/ + Word16 frac, /* i: fraction of lag Q0*/ + const Word16 *win, /* i : interpolation window Q14*/ + const Word16 imp_pos, /* i : glottal impulse position Q0*/ + const Word16 i_subfr /* i : subframe index Q0*/ ) { Word16 i, j, k, l; @@ -128,28 +130,29 @@ void pred_lt4_tc_fx( Word16 excI[2 * L_SUBFR]; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif - Copy( exc + sub( i_subfr, L_SUBFR ), excI, shl( L_SUBFR, 1 ) ); + Copy( exc + sub( i_subfr, L_SUBFR ), excI, L_SUBFR * 2 ); /* Q0 */ test(); IF( LT_16( add( T0, sub( imp_pos, L_IMPULSE2 ) ), L_SUBFR ) && LT_16( T0, L_SUBFR ) ) { - set16_fx( &excI[sub( L_SUBFR, T0 )], 0, T0 ); + set16_fx( &excI[L_SUBFR - T0], 0, T0 ); set16_fx( excO, 0, L_SUBFR + 1 ); - x0 = excI + sub( L_SUBFR, L_INTERPOL2 - 1 ); + x0 = excI + ( L_SUBFR - ( L_INTERPOL2 - 1 ) ); IF( frac > 0 ) { - frac = sub( frac, UP_SAMP ); + frac = sub( frac, UP_SAMP ); /* Q0 */ x0--; } - l = add( UP_SAMP - 1, frac ); + l = add( UP_SAMP - 1, frac ); /* Q0 */ FOR( j = T0; j < L_SUBFR + 1; j++ ) { k = l; move16(); - L_sum = L_mult( x0[0], win[k] ); + L_sum = L_mult( x0[0], win[k] ); /* Q15 */ FOR( i = 1; i < 2 * L_INTERPOL2; i++ ) { /* @@ -158,11 +161,11 @@ void pred_lt4_tc_fx( * so that the values needed are contiguous. */ k += UP_SAMP; - L_sum = L_mac( L_sum, x0[i], win[k] ); /*Q1 */ + L_sum = L_mac( L_sum, x0[i], win[k] ); /* Q15 */ } #ifdef BASOP_NOGLOB - L_sum = L_shl_o( L_sum, 1, &Overflow ); /*Q0h */ - excO[j] = round_fx_o( L_sum, &Overflow ); + L_sum = L_shl_o( L_sum, 1, &Overflow ); /* Q16 */ + excO[j] = round_fx_o( L_sum, &Overflow ); /* Q0 */ move16(); #else L_sum = L_shl( L_sum, 1 ); /*Q0h */ @@ -175,7 +178,7 @@ void pred_lt4_tc_fx( FOR( i = T0; i < L_SUBFR; i++ ) { #ifdef BASOP_NOGLOB - exc[i + i_subfr] = add_o( exc[i + i_subfr], mult_r( PIT_SHARP_fx, excO[i] ), &Overflow ); + exc[i + i_subfr] = add_o( exc[i + i_subfr], mult_r( PIT_SHARP_fx, excO[i] ), &Overflow ); /* Q0 */ #else exc[i + i_subfr] = add( exc[i + i_subfr], mult_r( PIT_SHARP_fx, excO[i] ) ); #endif diff --git a/lib_com/preemph.c b/lib_com/preemph.c index decc73f99..914ebe477 100644 --- a/lib_com/preemph.c +++ b/lib_com/preemph.c @@ -75,26 +75,26 @@ void preemph( *-------------------------------------------------------------*/ void preemph_ivas_fx( - Word32 *signal, /* i/o: signal */ - const Word16 mu, /* i : preemphasis factor */ - const Word16 L, /* i : vector size */ - Word32 *mem /* i/o: memory (x[-1]) */ + Word32 *signal, /* i/o: signal Qx*/ + const Word16 mu, /* i : preemphasis factor Q15*/ + const Word16 L, /* i : vector size Q0*/ + Word32 *mem /* i/o: memory (x[-1]) Qx*/ ) { Word16 i; Word32 temp; - temp = signal[L - 1]; + temp = signal[L - 1]; /* Qx */ move32(); FOR( i = L - 1; i > 0; i-- ) { - signal[i] = L_sub( signal[i], Mpy_32_16_1( signal[i - 1], mu ) ); + signal[i] = L_sub( signal[i], Mpy_32_16_1( signal[i - 1], mu ) ); /* Qx */ move32(); } - signal[0] = L_sub( signal[0], Mpy_32_16_1( *mem, mu ) ); + signal[0] = L_sub( signal[0], Mpy_32_16_1( *mem, mu ) ); /* Qx */ move32(); - *mem = temp; + *mem = temp; /* Qx */ move32(); return; diff --git a/lib_com/preemph_fx.c b/lib_com/preemph_fx.c index 13a0b5e42..ee0379fdb 100644 --- a/lib_com/preemph_fx.c +++ b/lib_com/preemph_fx.c @@ -20,26 +20,27 @@ void preemph_copy_fx( Word16 i, temp; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif - temp = x[lg - 1]; + temp = x[lg - 1]; /* Qx */ move16(); - FOR( i = sub( lg, 1 ); i > 0; i-- ) + FOR( i = lg - 1; i > 0; i-- ) { #ifdef BASOP_NOGLOB - y[i] = msu_ro( L_deposit_h( x[i] ), x[i - 1], mu, &Overflow ); + y[i] = msu_ro( L_deposit_h( x[i] ), x[i - 1], mu, &Overflow ); /* Qx */ #else y[i] = msu_r( L_deposit_h( x[i] ), x[i - 1], mu ); #endif move16(); } #ifdef BASOP_NOGLOB - y[0] = msu_ro( L_deposit_h( x[0] ), *mem, mu, &Overflow ); + y[0] = msu_ro( L_deposit_h( x[0] ), *mem, mu, &Overflow ); /* Qx */ #else y[0] = msu_r( L_deposit_h( x[0] ), *mem, mu ); #endif move16(); - *mem = temp; + *mem = temp; /* Qx */ move16(); } @@ -59,7 +60,13 @@ void preemph_copy_fx( * Returns: * void */ -void E_UTIL_f_preemph2( Word16 shift, Word16 *signal, const Word16 mu, const Word16 lg, Word16 *mem ) +void E_UTIL_f_preemph2( + Word16 shift, /* Q0 */ + Word16 *signal, /* Qx */ + const Word16 mu, /* Q15 */ + const Word16 lg, /* Q0 */ + Word16 *mem /* Qx */ +) { Word16 i, temp; Word32 L_tmp; @@ -67,16 +74,16 @@ void E_UTIL_f_preemph2( Word16 shift, Word16 *signal, const Word16 mu, const Wor Flag Overflow = 0; move32(); #endif - temp = signal[lg - 1]; + temp = signal[lg - 1]; /* Qx */ move16(); - FOR( i = sub( lg, 1 ); i > 0; i-- ) + FOR( i = lg - 1; i > 0; i-- ) { - L_tmp = L_mult( signal[i], 16384 ); + L_tmp = L_mult( signal[i], 16384 ); /* Qx + 15 */ #ifdef BASOP_NOGLOB - L_tmp = L_msu0_o( L_tmp, signal[i - 1], mu, &Overflow ); - L_tmp = L_shl_o( L_tmp, add( shift, 1 ), &Overflow ); - signal[i] = round_fx_o( L_tmp, &Overflow ); + L_tmp = L_msu0_o( L_tmp, signal[i - 1], mu, &Overflow ); /* Qx + 15 */ + L_tmp = L_shl_o( L_tmp, add( shift, 1 ), &Overflow ); /* Qx + shift + 16 */ + signal[i] = round_fx_o( L_tmp, &Overflow ); /* Qx + shift */ move16(); #else L_tmp = L_msu0( L_tmp, signal[i - 1], mu ); @@ -85,11 +92,11 @@ void E_UTIL_f_preemph2( Word16 shift, Word16 *signal, const Word16 mu, const Wor #endif } - L_tmp = L_mult( signal[0], 16384 ); + L_tmp = L_mult( signal[0], 16384 ); /* Qx + 15 */ #ifdef BASOP_NOGLOB - L_tmp = L_msu0_o( L_tmp, *mem, mu, &Overflow ); - L_tmp = L_shl_o( L_tmp, add( shift, 1 ), &Overflow ); - signal[0] = round_fx_o( L_tmp, &Overflow ); + L_tmp = L_msu0_o( L_tmp, *mem, mu, &Overflow ); /* Qx + 15 */ + L_tmp = L_shl_o( L_tmp, add( shift, 1 ), &Overflow ); /* Qx + shift + 16 */ + signal[0] = round_fx_o( L_tmp, &Overflow ); /* Qx + shift */ move16(); #else L_tmp = L_msu0( L_tmp, *mem, mu ); @@ -97,35 +104,41 @@ void E_UTIL_f_preemph2( Word16 shift, Word16 *signal, const Word16 mu, const Wor signal[0] = round_fx( L_tmp ); #endif - *mem = temp; + *mem = temp; /* Qx */ move16(); return; } -Word16 E_UTIL_f_preemph3( Word16 *signal, const Word16 mu, const Word16 lg, Word16 *mem, Word16 bits ) +Word16 E_UTIL_f_preemph3( + Word16 *signal, /* Qx */ + const Word16 mu, /* Q15 */ + const Word16 lg, /* Q0 */ + Word16 *mem, /* Qx */ + Word16 bits /* Q0 */ +) { Word16 i, QVal, mus, tmp_fixed, Q_new; Word32 L_tmp, L_maxloc; - QVal = shl( 1, sub( 15, bits ) ); - mus = shr( mu, bits ); + QVal = shl( 1, sub( 15, bits ) ); /* Q15 - bits */ + mus = shr( mu, bits ); /* Q15 - bits */ - L_tmp = L_mult( signal[0], QVal ); - L_tmp = L_msu( L_tmp, *mem, mus ); + L_tmp = L_mult( signal[0], QVal ); /* Qx + Q16 - bits */ + L_tmp = L_msu( L_tmp, *mem, mus ); /* Qx + Q16 - bits */ L_maxloc = L_abs( L_tmp ); FOR( i = 1; i < lg; i++ ) { - L_tmp = L_mult( signal[i], QVal ); - L_tmp = L_msu( L_tmp, signal[i - 1], mus ); + L_tmp = L_mult( signal[i], QVal ); /* Qx + Q16 - bits */ + L_tmp = L_msu( L_tmp, signal[i - 1], mus ); /* Qx + Q16 - bits */ L_tmp = L_abs( L_tmp ); L_maxloc = L_max( L_tmp, L_maxloc ); } - tmp_fixed = extract_h( L_maxloc ); + tmp_fixed = extract_h( L_maxloc ); /* Qx - bits */ Q_new = Q_MAX; move16(); @@ -136,22 +149,22 @@ Word16 E_UTIL_f_preemph3( Word16 *signal, const Word16 mu, const Word16 lg, Word Q_new = s_min( Q_new, Q_MAX ); } - tmp_fixed = signal[lg - 1]; + tmp_fixed = signal[lg - 1]; /* Qx */ move16(); - FOR( i = sub( lg, 1 ); i > 0; i-- ) + FOR( i = lg - 1; i > 0; i-- ) { - L_tmp = L_mult( signal[i], QVal ); - L_tmp = L_msu( L_tmp, signal[i - 1], mus ); - L_tmp = L_shl( L_tmp, Q_new ); - signal[i] = round_fx( L_tmp ); + L_tmp = L_mult( signal[i], QVal ); /* Qx + Q16 - bits */ + L_tmp = L_msu( L_tmp, signal[i - 1], mus ); /* Qx + Q16 - bits */ + L_tmp = L_shl( L_tmp, Q_new ); /* Qx + Q16 + Q_new - bits */ + signal[i] = round_fx( L_tmp ); /* Qx + Q_new - bits */ move16(); } - L_tmp = L_mult( signal[0], QVal ); - L_tmp = L_msu( L_tmp, *mem, mus ); - L_tmp = L_shl( L_tmp, Q_new ); - signal[0] = round_fx( L_tmp ); + L_tmp = L_mult( signal[0], QVal ); /* Qx + Q16 - bits */ + L_tmp = L_msu( L_tmp, *mem, mus ); /* Qx + Q16 - bits */ + L_tmp = L_shl( L_tmp, Q_new ); /* Qx + Q16 + Q_new - bits */ + signal[0] = round_fx( L_tmp ); /* Qx + Q_new - bits */ move16(); *mem = tmp_fixed; move16(); @@ -159,28 +172,34 @@ Word16 E_UTIL_f_preemph3( Word16 *signal, const Word16 mu, const Word16 lg, Word return Q_new; } -Word16 E_UTIL_f_preemph3_ivas_fx( Word16 *signal, const Word16 mu, const Word16 lg, Word16 *mem, Word16 bits ) +Word16 E_UTIL_f_preemph3_ivas_fx( + Word16 *signal, /* Qx */ + const Word16 mu, /* Q15 */ + const Word16 lg, /* Q0 */ + Word16 *mem, /* Qx */ + Word16 bits /* Q0 */ +) { Word16 i, QVal, mus, tmp_fixed, Q_new; Word32 L_tmp, L_maxloc; - QVal = shl( 1, sub( 15, bits ) ); - mus = shr( mu, bits ); + QVal = shl( 1, sub( 15, bits ) ); /* Q15 - bits */ + mus = shr( mu, bits ); /* Q15 - bits */ - L_tmp = L_mult( signal[0], QVal ); - L_tmp = L_msu( L_tmp, *mem, mus ); + L_tmp = L_mult( signal[0], QVal ); /* Qx + Q16 - bits */ + L_tmp = L_msu( L_tmp, *mem, mus ); /* Qx + Q16 - bits */ L_maxloc = L_abs( L_tmp ); FOR( i = 1; i < lg; i++ ) { - L_tmp = L_mult( signal[i], QVal ); - L_tmp = L_msu( L_tmp, signal[i - 1], mus ); + L_tmp = L_mult( signal[i], QVal ); /* Qx + Q16 - bits */ + L_tmp = L_msu( L_tmp, signal[i - 1], mus ); /* Qx + Q16 - bits */ L_tmp = L_abs( L_tmp ); L_maxloc = L_max( L_tmp, L_maxloc ); } - tmp_fixed = extract_h( L_maxloc ); + tmp_fixed = extract_h( L_maxloc ); /* Qx - bits */ Q_new = Q_MAX; move16(); @@ -196,17 +215,17 @@ Word16 E_UTIL_f_preemph3_ivas_fx( Word16 *signal, const Word16 mu, const Word16 FOR( i = sub( lg, 1 ); i > 0; i-- ) { - L_tmp = L_mult( signal[i], QVal ); - L_tmp = L_msu( L_tmp, signal[i - 1], mus ); - L_tmp = L_shl( L_tmp, Q_new ); - signal[i] = round_fx( L_tmp ); + L_tmp = L_mult( signal[i], QVal ); /* Qx + Q16 - bits */ + L_tmp = L_msu( L_tmp, signal[i - 1], mus ); /* Qx + Q16 - bits */ + L_tmp = L_shl( L_tmp, Q_new ); /* Qx + Q16 + Q_new - bits */ + signal[i] = round_fx( L_tmp ); /* Qx + Q_new - bits */ move16(); } - L_tmp = L_mult( signal[0], QVal ); - L_tmp = L_msu( L_tmp, *mem, mus ); - L_tmp = L_shl( L_tmp, Q_new ); - signal[0] = round_fx( L_tmp ); + L_tmp = L_mult( signal[0], QVal ); /* Qx + Q16 - bits */ + L_tmp = L_msu( L_tmp, *mem, mus ); /* Qx + Q16 - bits */ + L_tmp = L_shl( L_tmp, Q_new ); /* Qx + Q_new + Q16 - bits */ + signal[0] = round_fx( L_tmp ); /* Qx + Q_new - bits */ move16(); *mem = tmp_fixed; move16(); diff --git a/lib_com/prot.h b/lib_com/prot.h index 803a0a757..93b3f3a90 100644 --- a/lib_com/prot.h +++ b/lib_com/prot.h @@ -856,10 +856,10 @@ void preemph( float *mem /* i/o: memory (x[-1]) */ ); void preemph_ivas_fx( - Word32 *signal, /* i/o: signal */ - const Word16 mu, /* i : preemphasis factor */ - const Word16 L, /* i : vector size */ - Word32 *mem /* i/o: memory (x[-1]) */ + Word32 *signal, /* i/o: signal Qx*/ + const Word16 mu, /* i : preemphasis factor Q15*/ + const Word16 L, /* i : vector size Q0*/ + Word32 *mem /* i/o: memory (x[-1]) Qx*/ ); void cb_shape( const int16_t preemphFlag, /* i : flag for pre-emphasis */ diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index 07e2aa779..bfe439692 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -2220,18 +2220,20 @@ ppp_fx.c /========================================================================================================*/ void Interpol_delay_fx( - Word16 *out_fx, - Word16 last_fx, - Word16 current_fx, - Word16 SubNum, - const Word16 *frac_fx ); + Word16 *out_fx, /* Q4 */ + Word16 last_fx, /* Q0 */ + Word16 current_fx, /* Q0 */ + Word16 SubNum, /* Q0 */ + const Word16 *frac_fx /* Q4 */ +); void deemph_lpc_fx( - const Word16 *p_Aq_curr_fx, /* i : LP coefficients current frame */ - const Word16 *p_Aq_old_fx, /* i : LP coefficients previous frame */ + const Word16 *p_Aq_curr_fx, /* i : LP coefficients current frame Q12 */ + const Word16 *p_Aq_old_fx, /* i : LP coefficients previous frame Q12 */ Word16 *LPC_de_curr_fx, /* o : De-emphasized LP coefficients current frame in Q12 */ Word16 *LPC_de_old_fx, /* o : De-emphasized LP coefficients previous frame in Q12 */ - const Word16 deemph_old ); + const Word16 deemph_old /* Q0 */ +); /*========================================================================================================/ hq2_core_com_fx.c @@ -2607,10 +2609,28 @@ void preemph_copy_fx( Word16 *mem /* i/o: memory (x[-1]) Qx */ ); -void E_UTIL_f_preemph2( Word16 shift, Word16 *signal, const Word16 mu, const Word16 lg, Word16 *mem ); +void E_UTIL_f_preemph2( + Word16 shift, /* Q0 */ + Word16 *signal, /* Qx */ + const Word16 mu, /* Q15 */ + const Word16 lg, /* Q0 */ + Word16 *mem /* Qx */ +); -Word16 E_UTIL_f_preemph3( Word16 *signal, const Word16 mu, const Word16 lg, Word16 *mem, Word16 bits ); -Word16 E_UTIL_f_preemph3_ivas_fx( Word16 *signal, const Word16 mu, const Word16 lg, Word16 *mem, Word16 bits ); +Word16 E_UTIL_f_preemph3( + Word16 *signal, /* Qx */ + const Word16 mu, /* Q15 */ + const Word16 lg, /* Q0 */ + Word16 *mem, /* Qx */ + Word16 bits /* Q0 */ +); +Word16 E_UTIL_f_preemph3_ivas_fx( + Word16 *signal, /* Qx */ + const Word16 mu, /* Q15 */ + const Word16 lg, /* Q0 */ + Word16 *mem, /* Qx */ + Word16 bits /* Q0 */ +); // swb_bwe_com_fx.c Word16 WB_BWE_gain_pred_fx( Word16 *WB_fenv, /* o : WB frequency envelopes */ @@ -7171,24 +7191,24 @@ ivas_error acelp_core_switch_dec_bfi_ivas_fx( // pred_lt4_fx.c void pred_lt4( - const Word16 excI[], /* in : excitation buffer */ - Word16 excO[], /* out: excitation buffer */ - const Word16 T0, /* i : integer pitch lag */ - Word16 frac, /* i : fraction of lag */ - const Word16 L_subfr, /* i : subframe size */ - const Word16 *win, /* i : interpolation window */ - const Word16 nb_coef, /* i : nb of filter coef */ - const Word16 up_sample /* i : up_sample */ + const Word16 excI[], /* in : excitation buffer Q_exc*/ + Word16 excO[], /* out: excitation buffer Q_exc*/ + const Word16 T0, /* input : integer pitch lag Q0*/ + Word16 frac, /* input : fraction of lag Q0*/ + const Word16 L_subfr, /* input : subframe size Q0*/ + const Word16 *win, /* i : interpolation window Q14*/ + const Word16 nb_coef, /* i : nb of filter coef Q0*/ + const Word16 up_sample /* i : up_sample Q0*/ ); void pred_lt4_tc_fx( - Word16 exc[], /* i/o: excitation buffer */ - const Word16 T0, /* i : integer pitch lag */ - Word16 frac, /* i: fraction of lag */ - const Word16 *win, /* i : interpolation window */ - const Word16 imp_pos, /* i : glottal impulse position */ - const Word16 i_subfr /* i : subframe index */ + Word16 exc[], /* i/o: excitation buffer Q0*/ + const Word16 T0, /* i : integer pitch lag Q0*/ + Word16 frac, /* i: fraction of lag Q0*/ + const Word16 *win, /* i : interpolation window Q14*/ + const Word16 imp_pos, /* i : glottal impulse position Q0*/ + const Word16 i_subfr /* i : subframe index Q0*/ ); // pvq_cored_dec diff --git a/lib_enc/ivas_stereo_dmx_evs.c b/lib_enc/ivas_stereo_dmx_evs.c index 11a6fd49c..d3be66ae9 100644 --- a/lib_enc/ivas_stereo_dmx_evs.c +++ b/lib_enc/ivas_stereo_dmx_evs.c @@ -702,7 +702,8 @@ static void calc_poc_fx( } isd_rate = BASOP_Util_Divide1616_Scale( isd_cnt_h, freq_8k, &isd_rate_e ); - isd_rate = shl_r( isd_rate, isd_rate_e ); // Q15 + // Saturation to handle values close to 1.0f + isd_rate = shl_sat( isd_rate, isd_rate_e ); // Q15 hPHA->isd_rate_s_fx = add( mult_r( STEREO_DMX_EVS_ISD_FORGETTING_Q15, hPHA->isd_rate_s_fx ), mult_r( MAX_16 - STEREO_DMX_EVS_ISD_FORGETTING_Q15, isd_rate ) ); move16(); @@ -883,7 +884,8 @@ static void calc_poc_fx( ICCr = BASOP_Util_Divide3232_Scale_cadence( L_tmp1, L_tmp2, &L_tmp_e ); L_tmp_e = add( L_tmp_e, sub( L_tmp1_e, L_tmp2_e ) ); ICCr = Sqrt32( ICCr, &L_tmp_e ); - ICCr = L_shl_r( ICCr, L_tmp_e ); // Q31 + // Saturation to handle values close to 1.0f + ICCr = L_shl_sat( ICCr, L_tmp_e ); // Q31 // hPHA->iccr_s = STEREO_DMX_EVS_ICCR_FORGETTING * hPHA->iccr_s + ( 1.0f - STEREO_DMX_EVS_ICCR_FORGETTING ) * ICCr; hPHA->iccr_s_fx = L_add( Mpy_32_32_r( STEREO_DMX_EVS_ICCR_FORGETTING_Q31, hPHA->iccr_s_fx ), Mpy_32_32_r( MAX_32 - STEREO_DMX_EVS_ICCR_FORGETTING_Q31, ICCr ) ); @@ -967,7 +969,8 @@ static void calc_poc_fx( ild_cnt = 0; move16(); isd_rate = BASOP_Util_Divide1616_Scale( isd_cnt_l, freq_8k, &isd_rate_e ); - isd_rate = shl_r( isd_rate, isd_rate_e ); // Q15 + // Saturation to handle values close to 1.0f + isd_rate = shl_sat( isd_rate, isd_rate_e ); // Q15 FOR( i = 1; i < nsbd; i++ ) { // rfft_pha_buf[i * 2] = (float) sqrt( ( 1.0f + Pr[i] ) / 2.0f ); -- GitLab From d355b48bd45599c227d4d48945e1ec9e65986214 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Mon, 4 Nov 2024 15:21:58 +0530 Subject: [PATCH 071/128] Fix for 3GPP issue 984: Decoder crash for Stereo at 24.4 / 32 kbps JBM operation in Comp_and_apply_gain_ivas_fx() --- lib_com/gs_gains_fx.c | 14 +++++++------- lib_com/gs_noisefill_fx.c | 4 ++-- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib_com/gs_gains_fx.c b/lib_com/gs_gains_fx.c index 8b3719e98..08c4d9f36 100644 --- a/lib_com/gs_gains_fx.c +++ b/lib_com/gs_gains_fx.c @@ -215,13 +215,13 @@ void Comp_and_apply_gain_ivas_fx( * y_gain = pow(10.0, (Ener_per_bd_iQ[i_band]-Ener_per_bd_yQ[i_band])) * = pow(2, 3.321928*(Ener_per_bd_iQ[i_band]-Ener_per_bd_yQ[i_band])) *-----------------------------------------------------------------*/ - L16 = sub( Ener_per_bd_iQ[i_band], Ener_per_bd_yQ[i_band] ); /*Q12 */ - L32 = L_mult( L16, 27213 ); /* 3.321928 in Q13 -> Q26 */ - L32 = L_shr( L32, 10 ); /* From Q26 to Q16 */ - frac = L_Extract_lc( L32, &exp1 ); /* Extract exponent of gcode0 */ - y_gain = extract_l( Pow2( 14, frac ) ); /* Put 14 as exponent so that */ - /* output of Pow2() will be: */ - /* 16384 < Pow2() <= 32767 */ + L16 = sub_sat( Ener_per_bd_iQ[i_band], Ener_per_bd_yQ[i_band] ); /*Q12 */ + L32 = L_mult( L16, 27213 ); /* 3.321928 in Q13 -> Q26 */ + L32 = L_shr( L32, 10 ); /* From Q26 to Q16 */ + frac = L_Extract_lc( L32, &exp1 ); /* Extract exponent of gcode0 */ + y_gain = extract_l( Pow2( 14, frac ) ); /* Put 14 as exponent so that */ + /* output of Pow2() will be: */ + /* 16384 < Pow2() <= 32767 */ #ifdef BASOP_NOGLOB Ener_per_bd_yQ[i_band] = shl_o( y_gain, sub( exp1, 13 ), &Overflow ); /*Q13*/ #else /* BASOP_NOGLOB */ diff --git a/lib_com/gs_noisefill_fx.c b/lib_com/gs_noisefill_fx.c index d0f72936d..9f4ef9810 100644 --- a/lib_com/gs_noisefill_fx.c +++ b/lib_com/gs_noisefill_fx.c @@ -1338,9 +1338,9 @@ void highband_exc_dct_in_ivas_fx( { FOR( i = 0; i < last_bin; i++ ) { - Ener_per_bd_iQ[i] = s_min( Ener_per_bd_iQ[i], sub( add( lt_ener_per_band_fx[i], 1229 ), Ener_per_bd_yQ[i] ) ); + Ener_per_bd_iQ[i] = s_min( Ener_per_bd_iQ[i], sub_sat( add( lt_ener_per_band_fx[i], 1229 ), Ener_per_bd_yQ[i] ) ); move16(); - lt_ener_per_band_fx[i] = sub( lt_ener_per_band_fx[i], 77 ); + lt_ener_per_band_fx[i] = sub_sat( lt_ener_per_band_fx[i], 77 ); move16(); } FOR( ; i < MBANDS_GN; i++ ) -- GitLab From 90dfd9a30148b489d7665d322c52e6b14e08e812 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Mon, 4 Nov 2024 17:58:05 +0530 Subject: [PATCH 072/128] Fix for 3GPP issue 970: Major waveform discrepency in decoding SBA packets with 15% FER [x] Changed implementation of decoder_tcx_post_ivas_fx to accomodate variable Q instead of -2 --- lib_com/prot_fx.h | 1 + lib_dec/dec_tcx_fx.c | 22 +++++++++------------- lib_dec/ivas_mdct_core_dec.c | 2 +- lib_dec/ivas_tcx_core_dec.c | 2 +- 4 files changed, 12 insertions(+), 15 deletions(-) diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index bfe439692..1fac038c8 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -9818,6 +9818,7 @@ UWord32 mvl2s_r( void decoder_tcx_post_ivas_fx( Decoder_State *st_fx, Word16 *synth, Word16 *synthFB, + Word16 Q_syn, Word16 *A, Word16 bfi, Word16 MCT_flag ); diff --git a/lib_dec/dec_tcx_fx.c b/lib_dec/dec_tcx_fx.c index 35a417a6c..100b49de8 100644 --- a/lib_dec/dec_tcx_fx.c +++ b/lib_dec/dec_tcx_fx.c @@ -1613,9 +1613,10 @@ void decoder_tcx_post_fx( Decoder_State *st_fx, #ifdef IVAS_FLOAT_FIXED void decoder_tcx_post_ivas_fx( Decoder_State *st_fx, - Word16 *synth, // Qx - Word16 *synthFB, // Qx - Word16 *A, // Q: 14 - norm_s(A[0]) + Word16 *synth, // Q_syn + Word16 *synthFB, // Q_syn + Word16 Q_syn, + Word16 *A, // Q: 14 - norm_s(A[0]) Word16 bfi, Word16 MCT_flag ) { @@ -1684,7 +1685,7 @@ void decoder_tcx_post_ivas_fx( Decoder_State *st_fx, { tmp32 = L_shl( tmp32_1 /*Q28*/, -( 28 - 15 ) ); /*16Q15*/ #ifdef BASOP_NOGLOB - synthFB[i] = round_fx_sat( L_shl_sat( Mpy_32_16_1( tmp32, synthFB[i] ), 16 ) ); // Qx + synthFB[i] = round_fx_sat( L_shl_sat( Mpy_32_16_1( tmp32, synthFB[i] ), 16 ) ); // Q_syn #else synthFB[i] = round_fx( L_shl( Mpy_32_16_1( tmp32, synthFB[i] ), 16 ) ); #endif @@ -1696,8 +1697,8 @@ void decoder_tcx_post_ivas_fx( Decoder_State *st_fx, tmp32_2 /*stepCompensate*/ = L_shl_r( L_deposit_h( hTcxDec->stepCompensate ), sub( hTcxDec->stepCompensate_e, 31 - 28 ) ); /*Q28*/ FOR( i = 0; i < st_fx->L_frame; i++ ) { - tmp32 = L_shl( tmp32_1 /*Q28*/, -( 28 - 15 ) ); /*16Q15*/ - xn_buf[i] = extract_l( Mpy_32_16_1( tmp32, xn_buf[i] ) ); // Qx + tmp32 = L_shl( tmp32_1 /*Q28*/, -( 28 - 15 ) ); /*16Q15*/ + xn_buf[i] = extract_h( L_shl_sat( Mpy_32_16_1( tmp32, xn_buf[i] ), 16 ) ); // Q_syn move16(); tmp32_1 = L_sub( tmp32_1, tmp32_2 ); } @@ -1726,7 +1727,7 @@ void decoder_tcx_post_ivas_fx( Decoder_State *st_fx, tmp1 = round_fx( L_shl( tmp32, tmp2 ) ); #endif // s = sub(sub(sub(1, shl(s, 1)), 6/*table lookup for inverse framelength*/), tmp2); - s = sub( 25, add( shl( add( -2, s ), 1 ), tmp2 ) ); + s = sub( 25, add( shl( add( Q_syn, s ), 1 ), tmp2 ) ); tmp1 = Sqrt16( tmp1, &s ); move16(); level_syn = tmp1; /*Q0*/ @@ -1878,7 +1879,7 @@ void decoder_tcx_post_ivas_fx( Decoder_State *st_fx, FOR( i = 0; i < hTcxDec->L_frameTCX; i++ ) { tmp_shift = conceal_eof_gainFB_e; - synthFB[i] = round_fx_sat( L_shl_sat( Mpy_32_16_1( conceal_eof_gainFB, synthFB[i] ), tmp_shift ) ); // Qx + synthFB[i] = round_fx_sat( L_shl_sat( Mpy_32_16_1( conceal_eof_gainFB, synthFB[i] ), tmp_shift ) ); // Q_syn move16(); conceal_eof_gainFB = BASOP_Util_Add_Mant32Exp( conceal_eof_gainFB, conceal_eof_gainFB_e, L_negate( stepFB ), stepFB_e, &conceal_eof_gainFB_e ); // Q: 31 - conceal_eof_gainFB_e } @@ -1890,11 +1891,6 @@ void decoder_tcx_post_ivas_fx( Decoder_State *st_fx, hTcxDec->conceal_eof_gain32 = BASOP_Util_Add_Mant32Exp( hTcxDec->conceal_eof_gain32, hTcxDec->conceal_eof_gain_e, L_negate( step ), step_e, &hTcxDec->conceal_eof_gain_e ); move32(); } - Word32 temp = 0; - FOR( i = 0; i < hTcxDec->L_frameTCX; i++ ) - { - temp = L_add_sat( temp, abs( synthFB[i] ) ); - } /* run lpc gain compensation not for waveform adjustment */ test(); diff --git a/lib_dec/ivas_mdct_core_dec.c b/lib_dec/ivas_mdct_core_dec.c index 7201bad8c..caa01e7de 100644 --- a/lib_dec/ivas_mdct_core_dec.c +++ b/lib_dec/ivas_mdct_core_dec.c @@ -2121,7 +2121,7 @@ void ivas_mdct_core_reconstruct_fx( Copy_Scale_sig( synthFB_fx, synth_tmp, st->hTonalMDCTConc->nSamples, 2 ); TonalMDCTConceal_SaveTimeSignal( st->hTonalMDCTConc, synth_tmp, L_frameTCX[ch] ); } - decoder_tcx_post_ivas_fx( st, synth_fx, synthFB_fx, NULL, bfi, MCT_flag ); + decoder_tcx_post_ivas_fx( st, synth_fx, synthFB_fx, q_win, NULL, bfi, MCT_flag ); sf = s_min( getScaleFactor16( synth_buf_fx, add( add( st->hTcxDec->old_synth_len, L_FRAME_PLUS ), M ) ), getScaleFactor16( synth_bufFB_fx, add( add( st->hTcxDec->old_synth_lenFB, L_FRAME_PLUS ), M ) ) ); IF( LT_16( sf, 2 ) ) diff --git a/lib_dec/ivas_tcx_core_dec.c b/lib_dec/ivas_tcx_core_dec.c index 7930720f3..407f6d68d 100644 --- a/lib_dec/ivas_tcx_core_dec.c +++ b/lib_dec/ivas_tcx_core_dec.c @@ -733,7 +733,7 @@ void stereo_tcx_core_dec_fx( TonalMDCTConceal_SaveTimeSignal( st->hTonalMDCTConc, synthFB_fx, hTcxDec->L_frameTCX ); } - decoder_tcx_post_ivas_fx( st, synth_fx, synthFB_fx, Aq_fx, bfi, 0 ); + decoder_tcx_post_ivas_fx( st, synth_fx, synthFB_fx, 0, Aq_fx, bfi, 0 ); IF( EQ_16( st->core, TCX_20_CORE ) ) { -- GitLab From e1e8bfe73f0291d03e212045035bfd4a678f2e98 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Mon, 4 Nov 2024 20:45:41 +0530 Subject: [PATCH 073/128] Cleanup of stat_com float structure elements --- lib_com/cldfb.c | 188 ++++++++++++++++------------ lib_com/rom_com.c | 24 ++-- lib_com/stat_com.h | 49 ++++---- lib_dec/ivas_mc_paramupmix_dec.c | 4 +- lib_enc/ivas_core_enc.c | 13 +- lib_enc/ivas_core_pre_proc_front.c | 14 +-- lib_enc/ivas_enc.c | 37 ------ lib_enc/ivas_stereo_switching_enc.c | 6 +- lib_enc/ivas_tcx_core_enc.c | 7 +- lib_enc/swb_tbe_enc_fx.c | 1 + 10 files changed, 174 insertions(+), 169 deletions(-) diff --git a/lib_com/cldfb.c b/lib_com/cldfb.c index 5b6e77394..f5efb77d2 100644 --- a/lib_com/cldfb.c +++ b/lib_com/cldfb.c @@ -325,7 +325,7 @@ void cldfbAnalysis_ivas_fx( rot_vctr_im_fx = h_cldfb->rot_vec_ana_im_fx; ptr_pf_fx = h_cldfb->p_filter; - ptr_pf_sf = h_cldfb->p_filter_sf; + ptr_pf_sf = h_cldfb->p_filter_sf; // Q14 move16(); FOR( i = 0; i < no_col; i++ ) @@ -766,7 +766,7 @@ void cldfbAnalysis_ts_fx( rot_vctr_delay_im_fx = h_cldfb->rot_vec_ana_delay_im_fx; // q = 31 ptr_pf_fx = h_cldfb->p_filter; - ptr_pf_sf = h_cldfb->p_filter_sf; + ptr_pf_sf = h_cldfb->p_filter_sf; // Q14 move16(); FOR( i = 0; i < no_col; i++ ) @@ -1046,7 +1046,7 @@ void cldfbAnalysis_ts_fx_fixed_q( rot_vctr_delay_im_fx = h_cldfb->rot_vec_ana_delay_im_fx; // q = 31 ptr_pf_fx = h_cldfb->p_filter; - ptr_pf_sf = h_cldfb->p_filter_sf; + ptr_pf_sf = h_cldfb->p_filter_sf; // Q14 move16(); FOR( i = 0; i < no_col; i++ ) @@ -1477,7 +1477,7 @@ void cldfbSynthesis_ivas_fx( Copy32( h_cldfb->cldfb_state_fx, synthesisBuffer_fx + i_mult( M1, no_col ), h_cldfb->p_filter_length ); p_filter = h_cldfb->p_filter; - p_filter_sf = h_cldfb->p_filter_sf; + p_filter_sf = h_cldfb->p_filter_sf; // Q14 move16(); ptr_time_out_fx = timeOut_fx; @@ -1823,7 +1823,9 @@ ivas_error openCldfb_ivas_enc( hs->prototype = prototype; configureCldfb_ivas_enc( hs, sampling_rate ); +#ifndef IVAS_FLOAT_FIXED hs->memory_flt = NULL; +#endif hs->memory_length = 0; if ( type == CLDFB_ANALYSIS ) @@ -1843,11 +1845,13 @@ ivas_error openCldfb_ivas_enc( #endif } +#ifndef IVAS_FLOAT_FIXED if ( ( hs->cldfb_state = (float *) malloc( buf_len * sizeof( float ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for CLDFB" ); } set_f( hs->cldfb_state, 0.0f, buf_len ); +#endif #ifdef IVAS_FLOAT_FIXED if ( ( hs->cldfb_state_fx = (Word32 *) malloc( buf_len * sizeof( Word32 ) ) ) == NULL ) { @@ -1858,6 +1862,8 @@ ivas_error openCldfb_ivas_enc( hs->cldfb_size = buf_len; /*for having original size at intermediatery conversion, will be removed on removing conversion*/ move16(); set32_fx( hs->cldfb_state_fx, 0, buf_len ); + hs->Q_cldfb_state = 0; + move16(); set16_fx( hs->FilterStates, 0, i_mult( 9 + 16, hs->no_channels ) ); set16_fx( hs->FilterStates_e, 0, sizeof( hs->FilterStates_e ) / sizeof( hs->FilterStates_e[0] ) ); #endif // IVAS_FLOAT_FIXED @@ -2101,11 +2107,12 @@ void deleteCldfb_ivas( return; } +#ifndef IVAS_FLOAT_FIXED IF( hs->cldfb_state ) { free( hs->cldfb_state ); } -#ifdef IVAS_FLOAT_FIXED +#else IF( hs->cldfb_state_fx ) { free( hs->cldfb_state_fx ); @@ -2176,7 +2183,7 @@ static void cldfb_init_proto_and_twiddles( hs->rot_vec_ana_delay_im_fx = NULL; hs->rot_vec_syn_delay_im_fx = NULL; hs->rot_vec_syn_delay_re_fx = NULL; - hs->p_filter_sf = (Word16) 17036; + hs->p_filter_sf = (Word16) 17036; // Q14 hs->p_filter = CLDFB80_10_fx; hs->scale = CLDFB80_10_SCALE_FX_Q8; } @@ -2188,7 +2195,7 @@ static void cldfb_init_proto_and_twiddles( hs->rot_vec_ana_delay_im_fx = rot_vec_delay_im_LDQMF_fx; hs->rot_vec_syn_delay_re_fx = rot_vec_delay_re_LDQMF_fx; hs->rot_vec_syn_delay_im_fx = rot_vec_delay_im_LDQMF_fx; - hs->p_filter_sf = (Word16) 15388; + hs->p_filter_sf = (Word16) 15388; // Q14 hs->p_filter = LDQMF_10_fx; hs->scale = LDQMF_10_SCALE_FX_Q8; } @@ -2207,7 +2214,7 @@ static void cldfb_init_proto_and_twiddles( hs->rot_vec_ana_delay_im_fx = NULL; hs->rot_vec_syn_delay_im_fx = NULL; hs->rot_vec_syn_delay_re_fx = NULL; - hs->p_filter_sf = (Word16) 17051; + hs->p_filter_sf = (Word16) 17051; // Q14 hs->p_filter = CLDFB80_16_fx; hs->scale = CLDFB80_16_SCALE_FX_Q8; } @@ -2219,7 +2226,7 @@ static void cldfb_init_proto_and_twiddles( hs->rot_vec_ana_delay_im_fx = rot_vec_delay_im_LDQMF_fx; hs->rot_vec_syn_delay_re_fx = rot_vec_delay_re_LDQMF_fx; hs->rot_vec_syn_delay_im_fx = rot_vec_delay_im_LDQMF_fx; - hs->p_filter_sf = (Word16) 15388; + hs->p_filter_sf = (Word16) 15388; // Q14 hs->p_filter = LDQMF_16_fx; hs->scale = LDQMF_16_SCALE_FX_Q8; } @@ -2238,7 +2245,7 @@ static void cldfb_init_proto_and_twiddles( hs->rot_vec_ana_delay_im_fx = NULL; hs->rot_vec_syn_delay_im_fx = NULL; hs->rot_vec_syn_delay_re_fx = NULL; - hs->p_filter_sf = (Word16) 17050; + hs->p_filter_sf = (Word16) 17050; // Q14 hs->p_filter = CLDFB80_20_fx; hs->scale = CLDFB80_20_SCALE_FX_Q8; } @@ -2250,7 +2257,7 @@ static void cldfb_init_proto_and_twiddles( hs->rot_vec_ana_delay_im_fx = rot_vec_delay_im_LDQMF_fx; hs->rot_vec_syn_delay_re_fx = rot_vec_delay_re_LDQMF_fx; hs->rot_vec_syn_delay_im_fx = rot_vec_delay_im_LDQMF_fx; - hs->p_filter_sf = (Word16) 15390; + hs->p_filter_sf = (Word16) 15390; // Q14 hs->p_filter = LDQMF_20_fx; hs->scale = LDQMF_20_SCALE_FX_Q8; } @@ -2269,7 +2276,7 @@ static void cldfb_init_proto_and_twiddles( hs->rot_vec_ana_delay_im_fx = NULL; hs->rot_vec_syn_delay_im_fx = NULL; hs->rot_vec_syn_delay_re_fx = NULL; - hs->p_filter_sf = (Word16) 17051; + hs->p_filter_sf = (Word16) 17051; // Q14 hs->p_filter = CLDFB80_30_fx; hs->scale = CLDFB80_30_SCALE_FX_Q8; } @@ -2281,7 +2288,7 @@ static void cldfb_init_proto_and_twiddles( hs->rot_vec_ana_delay_im_fx = rot_vec_delay_im_LDQMF_fx; hs->rot_vec_syn_delay_re_fx = rot_vec_delay_re_LDQMF_fx; hs->rot_vec_syn_delay_im_fx = rot_vec_delay_im_LDQMF_fx; - hs->p_filter_sf = (Word16) 15388; + hs->p_filter_sf = (Word16) 15388; // Q14 hs->p_filter = LDQMF_30_fx; hs->scale = LDQMF_30_SCALE_FX_Q8; } @@ -2300,7 +2307,7 @@ static void cldfb_init_proto_and_twiddles( hs->rot_vec_ana_delay_im_fx = NULL; hs->rot_vec_syn_delay_im_fx = NULL; hs->rot_vec_syn_delay_re_fx = NULL; - hs->p_filter_sf = (Word16) 17050; + hs->p_filter_sf = (Word16) 17050; // Q14 hs->p_filter = CLDFB80_32_fx; hs->scale = CLDFB80_32_SCALE_FX_Q8; } @@ -2312,7 +2319,7 @@ static void cldfb_init_proto_and_twiddles( hs->rot_vec_ana_delay_im_fx = rot_vec_delay_im_LDQMF_fx; hs->rot_vec_syn_delay_re_fx = rot_vec_delay_re_LDQMF_fx; hs->rot_vec_syn_delay_im_fx = rot_vec_delay_im_LDQMF_fx; - hs->p_filter_sf = (Word16) 15392; + hs->p_filter_sf = (Word16) 15392; // Q14 hs->p_filter = LDQMF_32_fx; hs->scale = LDQMF_32_SCALE_FX_Q8; } @@ -2331,7 +2338,7 @@ static void cldfb_init_proto_and_twiddles( hs->rot_vec_ana_delay_im_fx = NULL; hs->rot_vec_syn_delay_im_fx = NULL; hs->rot_vec_syn_delay_re_fx = NULL; - hs->p_filter_sf = (Word16) 17051; + hs->p_filter_sf = (Word16) 17051; // Q14 hs->p_filter = CLDFB80_40_fx; hs->scale = CLDFB80_40_SCALE_FX_Q8; } @@ -2343,7 +2350,7 @@ static void cldfb_init_proto_and_twiddles( hs->rot_vec_ana_delay_im_fx = rot_vec_delay_im_LDQMF_fx; hs->rot_vec_syn_delay_re_fx = rot_vec_delay_re_LDQMF_fx; hs->rot_vec_syn_delay_im_fx = rot_vec_delay_im_LDQMF_fx; - hs->p_filter_sf = (Word16) 15391; + hs->p_filter_sf = (Word16) 15391; // Q14 hs->p_filter = LDQMF_40_fx; hs->scale = LDQMF_40_SCALE_FX_Q8; } @@ -2362,7 +2369,7 @@ static void cldfb_init_proto_and_twiddles( hs->rot_vec_ana_delay_im_fx = NULL; hs->rot_vec_syn_delay_re_fx = NULL; hs->rot_vec_syn_delay_im_fx = NULL; - hs->p_filter_sf = (Word16) 17051; + hs->p_filter_sf = (Word16) 17051; // Q14 hs->p_filter = CLDFB80_60_fx; hs->scale = CLDFB80_60_SCALE_FX_Q8; } @@ -2374,7 +2381,7 @@ static void cldfb_init_proto_and_twiddles( hs->rot_vec_ana_delay_im_fx = rot_vec_delay_im_LDQMF_fx; hs->rot_vec_syn_delay_re_fx = rot_vec_delay_re_LDQMF_fx; hs->rot_vec_syn_delay_im_fx = rot_vec_delay_im_LDQMF_fx; - hs->p_filter_sf = (Word16) 15391; + hs->p_filter_sf = (Word16) 15391; // Q14 hs->p_filter = LDQMF_60_fx; hs->scale = LDQMF_60_SCALE_FX_Q8; } @@ -2779,11 +2786,12 @@ static void cldfb_init_proto_and_twiddles_enc( switch ( hs->no_channels ) { case 10: +#ifndef IVAS_FLOAT_FIXED hs->rot_vec_ana_re = rot_vec_ana_re_L10; hs->rot_vec_ana_im = rot_vec_ana_im_L10; hs->rot_vec_syn_re = rot_vec_syn_re_L10; hs->rot_vec_syn_im = rot_vec_syn_im_L10; -#ifdef IVAS_FLOAT_FIXED +#else hs->rot_vec_ana_re_fx = rot_vec_ana_re_L10_fx; hs->rot_vec_ana_im_fx = rot_vec_ana_im_L10_fx; hs->rot_vec_syn_re_fx = rot_vec_syn_re_L10_fx; @@ -2803,40 +2811,44 @@ static void cldfb_init_proto_and_twiddles_enc( #endif if ( hs->prototype == CLDFB_PROTOTYPE_1_25MS ) { - hs->p_filter_flt = CLDFB80_10_flt; - hs->scale_flt = CLDFB80_10_SCALE; hs->ds = 10; hs->da = 10; + hs->scale_flt = CLDFB80_10_SCALE; +#ifndef IVAS_FLOAT_FIXED + hs->p_filter_flt = CLDFB80_10_flt; hs->rot_vec_ana_delay_re = NULL; hs->rot_vec_ana_delay_im = NULL; hs->rot_vec_syn_delay_re = NULL; hs->rot_vec_syn_delay_im = NULL; -#ifdef IVAS_FLOAT_FIXED +#else hs->rot_vec_ana_delay_re_fx = NULL; hs->rot_vec_ana_delay_im_fx = NULL; hs->rot_vec_syn_delay_re_fx = NULL; hs->rot_vec_syn_delay_im_fx = NULL; - hs->p_filter_sf = (Word16) 17036; + hs->p_filter_sf = (Word16) 17036; // Q14 hs->scale = cldfb_scale_2_5ms[0]; hs->p_filter = CLDFB80_10_fx; #endif } else if ( hs->prototype == CLDFB_PROTOTYPE_5_00MS ) { +#ifndef IVAS_FLOAT_FIXED hs->p_filter_flt = LDQMF_10; +#endif hs->scale_flt = LDQMF_10_SCALE; hs->ds = 40; hs->da = -20; +#ifndef IVAS_FLOAT_FIXED hs->rot_vec_ana_delay_re = rot_vec_delay_re_LDQMF; hs->rot_vec_ana_delay_im = rot_vec_delay_im_LDQMF; hs->rot_vec_syn_delay_re = rot_vec_delay_re_LDQMF; hs->rot_vec_syn_delay_im = rot_vec_delay_im_LDQMF; -#ifdef IVAS_FLOAT_FIXED +#else hs->rot_vec_ana_delay_re_fx = rot_vec_delay_re_LDQMF_fx; hs->rot_vec_ana_delay_im_fx = rot_vec_delay_im_LDQMF_fx; hs->rot_vec_syn_delay_re_fx = rot_vec_delay_re_LDQMF_fx; hs->rot_vec_syn_delay_im_fx = rot_vec_delay_im_LDQMF_fx; - hs->p_filter_sf = (Word16) 15388; + hs->p_filter_sf = (Word16) 15388; // Q14 hs->p_filter = LDQMF_10_fx; hs->scale = cldfb_scale_5_0ms[0]; #endif @@ -2844,11 +2856,12 @@ static void cldfb_init_proto_and_twiddles_enc( break; case 16: +#ifndef IVAS_FLOAT_FIXED hs->rot_vec_ana_re = rot_vec_ana_re_L16; hs->rot_vec_ana_im = rot_vec_ana_im_L16; hs->rot_vec_syn_re = rot_vec_syn_re_L16; hs->rot_vec_syn_im = rot_vec_syn_im_L16; -#ifdef IVAS_FLOAT_FIXED +#else hs->rot_vec_ana_re_fx = rot_vec_ana_re_L16_fx; hs->rot_vec_ana_im_fx = rot_vec_ana_im_L16_fx; hs->rot_vec_syn_re_fx = rot_vec_syn_re_L16_fx; @@ -2862,40 +2875,44 @@ static void cldfb_init_proto_and_twiddles_enc( #endif if ( hs->prototype == CLDFB_PROTOTYPE_1_25MS ) { +#ifndef IVAS_FLOAT_FIXED hs->p_filter_flt = CLDFB80_16_flt; +#endif hs->scale_flt = CLDFB80_16_SCALE; hs->ds = 20; hs->da = 20; +#ifndef IVAS_FLOAT_FIXED hs->rot_vec_ana_delay_re = NULL; hs->rot_vec_ana_delay_im = NULL; hs->rot_vec_syn_delay_re = NULL; hs->rot_vec_syn_delay_im = NULL; -#ifdef IVAS_FLOAT_FIXED +#else hs->rot_vec_ana_delay_re_fx = NULL; hs->rot_vec_ana_delay_im_fx = NULL; hs->rot_vec_syn_delay_re_fx = NULL; hs->rot_vec_syn_delay_im_fx = NULL; - hs->p_filter_sf = (Word16) 17051; + hs->p_filter_sf = (Word16) 17051; // Q14 hs->p_filter = CLDFB80_16_fx; hs->scale = cldfb_scale_2_5ms[1]; #endif } else if ( hs->prototype == CLDFB_PROTOTYPE_5_00MS ) { - hs->p_filter_flt = LDQMF_16; - hs->scale_flt = LDQMF_16_SCALE; hs->ds = 80; hs->da = -40; + hs->scale_flt = LDQMF_16_SCALE; +#ifndef IVAS_FLOAT_FIXED + hs->p_filter_flt = LDQMF_16; hs->rot_vec_ana_delay_re = rot_vec_delay_re_LDQMF; hs->rot_vec_ana_delay_im = rot_vec_delay_im_LDQMF; hs->rot_vec_syn_delay_re = rot_vec_delay_re_LDQMF; hs->rot_vec_syn_delay_im = rot_vec_delay_im_LDQMF; -#ifdef IVAS_FLOAT_FIXED +#else hs->rot_vec_ana_delay_re_fx = rot_vec_delay_re_LDQMF_fx; hs->rot_vec_ana_delay_im_fx = rot_vec_delay_im_LDQMF_fx; hs->rot_vec_syn_delay_re_fx = rot_vec_delay_re_LDQMF_fx; hs->rot_vec_syn_delay_im_fx = rot_vec_delay_im_LDQMF_fx; - hs->p_filter_sf = (Word16) 15388; + hs->p_filter_sf = (Word16) 15388; // Q14 hs->p_filter = LDQMF_16_fx; hs->scale = cldfb_scale_5_0ms[1]; #endif @@ -2903,11 +2920,12 @@ static void cldfb_init_proto_and_twiddles_enc( break; case 20: +#ifndef IVAS_FLOAT_FIXED hs->rot_vec_ana_re = rot_vec_ana_re_L20; hs->rot_vec_ana_im = rot_vec_ana_im_L20; hs->rot_vec_syn_re = rot_vec_syn_re_L20; hs->rot_vec_syn_im = rot_vec_syn_im_L20; -#ifdef IVAS_FLOAT_FIXED +#else hs->rRotVctr = rRotVectr_20; hs->iRotVctr = iRotVectr_20; hs->rot_vec_ana_re_fx = rot_vec_ana_re_L20_fx; @@ -2927,40 +2945,42 @@ static void cldfb_init_proto_and_twiddles_enc( #endif if ( hs->prototype == CLDFB_PROTOTYPE_1_25MS ) { - hs->p_filter_flt = CLDFB80_20_flt; - hs->scale_flt = CLDFB80_20_SCALE; hs->ds = 20; hs->da = 20; + hs->scale_flt = CLDFB80_20_SCALE; +#ifndef IVAS_FLOAT_FIXED + hs->p_filter_flt = CLDFB80_20_flt; hs->rot_vec_ana_delay_re = NULL; hs->rot_vec_ana_delay_im = NULL; hs->rot_vec_syn_delay_re = NULL; hs->rot_vec_syn_delay_im = NULL; -#ifdef IVAS_FLOAT_FIXED +#else hs->rot_vec_ana_delay_re_fx = NULL; hs->rot_vec_ana_delay_im_fx = NULL; hs->rot_vec_syn_delay_re_fx = NULL; hs->rot_vec_syn_delay_im_fx = NULL; - hs->p_filter_sf = (Word16) 17050; + hs->p_filter_sf = (Word16) 17050; // Q14 hs->p_filter = CLDFB80_20_fx; hs->scale = cldfb_scale_2_5ms[2]; #endif } else if ( hs->prototype == CLDFB_PROTOTYPE_5_00MS ) { - hs->p_filter_flt = LDQMF_20; - hs->scale_flt = LDQMF_20_SCALE; hs->ds = 80; hs->da = -40; + hs->scale_flt = LDQMF_20_SCALE; +#ifndef IVAS_FLOAT_FIXED + hs->p_filter_flt = LDQMF_20; hs->rot_vec_ana_delay_re = rot_vec_delay_re_LDQMF; hs->rot_vec_ana_delay_im = rot_vec_delay_im_LDQMF; hs->rot_vec_syn_delay_re = rot_vec_delay_re_LDQMF; hs->rot_vec_syn_delay_im = rot_vec_delay_im_LDQMF; -#ifdef IVAS_FLOAT_FIXED +#else hs->rot_vec_ana_delay_re_fx = rot_vec_delay_re_LDQMF_fx; hs->rot_vec_ana_delay_im_fx = rot_vec_delay_im_LDQMF_fx; hs->rot_vec_syn_delay_re_fx = rot_vec_delay_re_LDQMF_fx; hs->rot_vec_syn_delay_im_fx = rot_vec_delay_im_LDQMF_fx; - hs->p_filter_sf = (Word16) 15390; + hs->p_filter_sf = (Word16) 15390; // Q14 hs->p_filter = LDQMF_20_fx; hs->scale = cldfb_scale_5_0ms[2]; #endif @@ -2968,11 +2988,12 @@ static void cldfb_init_proto_and_twiddles_enc( break; case 30: +#ifndef IVAS_FLOAT_FIXED hs->rot_vec_ana_re = rot_vec_ana_re_L30; hs->rot_vec_ana_im = rot_vec_ana_im_L30; hs->rot_vec_syn_re = rot_vec_syn_re_L30; hs->rot_vec_syn_im = rot_vec_syn_im_L30; -#ifdef IVAS_FLOAT_FIXED +#else hs->rot_vec_ana_re_fx = rot_vec_ana_re_L30_fx; hs->rot_vec_ana_im_fx = rot_vec_ana_im_L30_fx; hs->rot_vec_syn_re_fx = rot_vec_syn_re_L30_fx; @@ -2992,40 +3013,42 @@ static void cldfb_init_proto_and_twiddles_enc( #endif if ( hs->prototype == CLDFB_PROTOTYPE_1_25MS ) { - hs->p_filter_flt = CLDFB80_30_flt; - hs->scale_flt = CLDFB80_30_SCALE; hs->ds = 30; hs->da = 30; + hs->scale_flt = CLDFB80_30_SCALE; +#ifndef IVAS_FLOAT_FIXED + hs->p_filter_flt = CLDFB80_30_flt; hs->rot_vec_ana_delay_re = NULL; hs->rot_vec_ana_delay_im = NULL; hs->rot_vec_syn_delay_re = NULL; hs->rot_vec_syn_delay_im = NULL; -#ifdef IVAS_FLOAT_FIXED +#else hs->rot_vec_ana_delay_re_fx = NULL; hs->rot_vec_ana_delay_im_fx = NULL; hs->rot_vec_syn_delay_re_fx = NULL; hs->rot_vec_syn_delay_im_fx = NULL; - hs->p_filter_sf = (Word16) 17051; + hs->p_filter_sf = (Word16) 17051; // Q14 hs->scale = cldfb_scale_2_5ms[6]; hs->p_filter = CLDFB80_30_fx; #endif } else if ( hs->prototype == CLDFB_PROTOTYPE_5_00MS ) { - hs->p_filter_flt = LDQMF_30; - hs->scale_flt = LDQMF_30_SCALE; hs->ds = 120; hs->da = -60; + hs->scale_flt = LDQMF_30_SCALE; +#ifndef IVAS_FLOAT_FIXED + hs->p_filter_flt = LDQMF_30; hs->rot_vec_ana_delay_re = rot_vec_delay_re_LDQMF; hs->rot_vec_ana_delay_im = rot_vec_delay_im_LDQMF; hs->rot_vec_syn_delay_re = rot_vec_delay_re_LDQMF; hs->rot_vec_syn_delay_im = rot_vec_delay_im_LDQMF; -#ifdef IVAS_FLOAT_FIXED +#else hs->rot_vec_ana_delay_re_fx = rot_vec_delay_re_LDQMF_fx; hs->rot_vec_ana_delay_im_fx = rot_vec_delay_im_LDQMF_fx; hs->rot_vec_syn_delay_re_fx = rot_vec_delay_re_LDQMF_fx; hs->rot_vec_syn_delay_im_fx = rot_vec_delay_im_LDQMF_fx; - hs->p_filter_sf = (Word16) 15388; + hs->p_filter_sf = (Word16) 15388; // Q14 hs->scale = cldfb_scale_5_0ms[6]; hs->p_filter = LDQMF_30_fx; #endif @@ -3033,11 +3056,12 @@ static void cldfb_init_proto_and_twiddles_enc( break; case 32: +#ifndef IVAS_FLOAT_FIXED hs->rot_vec_ana_re = rot_vec_ana_re_L32; hs->rot_vec_ana_im = rot_vec_ana_im_L32; hs->rot_vec_syn_re = rot_vec_syn_re_L32; hs->rot_vec_syn_im = rot_vec_syn_im_L32; -#ifdef IVAS_FLOAT_FIXED +#else hs->rot_vec_ana_re_fx = rot_vec_ana_re_L32_fx; hs->rot_vec_ana_im_fx = rot_vec_ana_im_L32_fx; hs->rot_vec_syn_re_fx = rot_vec_syn_re_L32_fx; @@ -3051,40 +3075,42 @@ static void cldfb_init_proto_and_twiddles_enc( #endif if ( hs->prototype == CLDFB_PROTOTYPE_1_25MS ) { - hs->p_filter_flt = CLDFB80_32_flt; - hs->scale_flt = CLDFB80_32_SCALE; hs->ds = 32; hs->da = 32; + hs->scale_flt = CLDFB80_32_SCALE; +#ifndef IVAS_FLOAT_FIXED + hs->p_filter_flt = CLDFB80_32_flt; hs->rot_vec_ana_delay_re = NULL; hs->rot_vec_ana_delay_im = NULL; hs->rot_vec_syn_delay_re = NULL; hs->rot_vec_syn_delay_im = NULL; -#ifdef IVAS_FLOAT_FIXED +#else hs->rot_vec_ana_delay_re_fx = NULL; hs->rot_vec_ana_delay_im_fx = NULL; hs->rot_vec_syn_delay_re_fx = NULL; hs->rot_vec_syn_delay_im_fx = NULL; - hs->p_filter_sf = (Word16) 17050; + hs->p_filter_sf = (Word16) 17050; // Q14 hs->p_filter = CLDFB80_32_fx; hs->scale = cldfb_scale_2_5ms[3]; #endif } else if ( hs->prototype == CLDFB_PROTOTYPE_5_00MS ) { - hs->p_filter_flt = LDQMF_32; - hs->scale_flt = LDQMF_32_SCALE; hs->ds = 160; hs->da = -80; + hs->scale_flt = LDQMF_32_SCALE; +#ifndef IVAS_FLOAT_FIXED + hs->p_filter_flt = LDQMF_32; hs->rot_vec_ana_delay_re = rot_vec_delay_re_LDQMF; hs->rot_vec_ana_delay_im = rot_vec_delay_im_LDQMF; hs->rot_vec_syn_delay_re = rot_vec_delay_re_LDQMF; hs->rot_vec_syn_delay_im = rot_vec_delay_im_LDQMF; -#ifdef IVAS_FLOAT_FIXED +#else hs->rot_vec_ana_delay_re_fx = rot_vec_delay_re_LDQMF_fx; hs->rot_vec_ana_delay_im_fx = rot_vec_delay_im_LDQMF_fx; hs->rot_vec_syn_delay_re_fx = rot_vec_delay_re_LDQMF_fx; hs->rot_vec_syn_delay_im_fx = rot_vec_delay_im_LDQMF_fx; - hs->p_filter_sf = (Word16) 15392; + hs->p_filter_sf = (Word16) 15392; // Q14 hs->scale = cldfb_scale_5_0ms[3]; hs->p_filter = LDQMF_32_fx; #endif @@ -3092,11 +3118,12 @@ static void cldfb_init_proto_and_twiddles_enc( break; case 40: +#ifndef IVAS_FLOAT_FIXED hs->rot_vec_ana_re = rot_vec_ana_re_L40; hs->rot_vec_ana_im = rot_vec_ana_im_L40; hs->rot_vec_syn_re = rot_vec_syn_re_L40; hs->rot_vec_syn_im = rot_vec_syn_im_L40; -#ifdef IVAS_FLOAT_FIXED +#else hs->rot_vec_ana_re_fx = rot_vec_ana_re_L40_fx; hs->rot_vec_ana_im_fx = rot_vec_ana_im_L40_fx; hs->rot_vec_syn_re_fx = rot_vec_syn_re_L40_fx; @@ -3116,40 +3143,42 @@ static void cldfb_init_proto_and_twiddles_enc( #endif if ( hs->prototype == CLDFB_PROTOTYPE_1_25MS ) { - hs->p_filter_flt = CLDFB80_40_flt; - hs->scale_flt = CLDFB80_40_SCALE; hs->ds = 40; hs->da = 40; + hs->scale_flt = CLDFB80_40_SCALE; +#ifndef IVAS_FLOAT_FIXED + hs->p_filter_flt = CLDFB80_40_flt; hs->rot_vec_ana_delay_re = NULL; hs->rot_vec_ana_delay_im = NULL; hs->rot_vec_syn_delay_re = NULL; hs->rot_vec_syn_delay_im = NULL; -#ifdef IVAS_FLOAT_FIXED +#else hs->rot_vec_ana_delay_re_fx = NULL; hs->rot_vec_ana_delay_im_fx = NULL; hs->rot_vec_syn_delay_re_fx = NULL; hs->rot_vec_syn_delay_im_fx = NULL; - hs->p_filter_sf = (Word16) 17051; + hs->p_filter_sf = (Word16) 17051; // Q14 hs->scale = cldfb_scale_2_5ms[4]; hs->p_filter = CLDFB80_40_fx; #endif } else if ( hs->prototype == CLDFB_PROTOTYPE_5_00MS ) { - hs->p_filter_flt = LDQMF_40; - hs->scale_flt = LDQMF_40_SCALE; hs->ds = 160; hs->da = -80; + hs->scale_flt = LDQMF_40_SCALE; +#ifndef IVAS_FLOAT_FIXED + hs->p_filter_flt = LDQMF_40; hs->rot_vec_ana_delay_re = rot_vec_delay_re_LDQMF; hs->rot_vec_ana_delay_im = rot_vec_delay_im_LDQMF; hs->rot_vec_syn_delay_re = rot_vec_delay_re_LDQMF; hs->rot_vec_syn_delay_im = rot_vec_delay_im_LDQMF; -#ifdef IVAS_FLOAT_FIXED +#else hs->rot_vec_ana_delay_re_fx = rot_vec_delay_re_LDQMF_fx; hs->rot_vec_ana_delay_im_fx = rot_vec_delay_im_LDQMF_fx; hs->rot_vec_syn_delay_re_fx = rot_vec_delay_re_LDQMF_fx; hs->rot_vec_syn_delay_im_fx = rot_vec_delay_im_LDQMF_fx; - hs->p_filter_sf = (Word16) 15391; + hs->p_filter_sf = (Word16) 15391; // Q14 hs->p_filter = LDQMF_40_fx; hs->scale = cldfb_scale_5_0ms[4]; #endif @@ -3157,11 +3186,12 @@ static void cldfb_init_proto_and_twiddles_enc( break; case 60: +#ifndef IVAS_FLOAT_FIXED hs->rot_vec_ana_re = rot_vec_ana_re_L60; hs->rot_vec_ana_im = rot_vec_ana_im_L60; hs->rot_vec_syn_re = rot_vec_syn_re_L60; hs->rot_vec_syn_im = rot_vec_syn_im_L60; -#ifdef IVAS_FLOAT_FIXED +#else hs->rot_vec_ana_re_fx = rot_vec_ana_re_L60_fx; hs->rot_vec_ana_im_fx = rot_vec_ana_im_L60_fx; hs->rot_vec_syn_re_fx = rot_vec_syn_re_L60_fx; @@ -3181,40 +3211,42 @@ static void cldfb_init_proto_and_twiddles_enc( #endif if ( hs->prototype == CLDFB_PROTOTYPE_1_25MS ) { - hs->p_filter_flt = CLDFB80_60_flt; - hs->scale_flt = CLDFB80_60_SCALE; hs->ds = 60; hs->da = 60; + hs->scale_flt = CLDFB80_60_SCALE; +#ifndef IVAS_FLOAT_FIXED + hs->p_filter_flt = CLDFB80_60_flt; hs->rot_vec_ana_delay_re = NULL; hs->rot_vec_ana_delay_im = NULL; hs->rot_vec_syn_delay_re = NULL; hs->rot_vec_syn_delay_im = NULL; -#ifdef IVAS_FLOAT_FIXED +#else hs->rot_vec_ana_delay_re_fx = NULL; hs->rot_vec_ana_delay_im_fx = NULL; hs->rot_vec_syn_delay_re_fx = NULL; hs->rot_vec_syn_delay_im_fx = NULL; - hs->p_filter_sf = (Word16) 17051; + hs->p_filter_sf = (Word16) 17051; // Q14 hs->p_filter = CLDFB80_60_fx; hs->scale = cldfb_scale_2_5ms[5]; #endif } else if ( hs->prototype == CLDFB_PROTOTYPE_5_00MS ) { - hs->p_filter_flt = LDQMF_60; - hs->scale_flt = LDQMF_60_SCALE; hs->ds = 240; hs->da = -120; + hs->scale_flt = LDQMF_60_SCALE; +#ifndef IVAS_FLOAT_FIXED + hs->p_filter_flt = LDQMF_60; hs->rot_vec_ana_delay_re = rot_vec_delay_re_LDQMF; hs->rot_vec_ana_delay_im = rot_vec_delay_im_LDQMF; hs->rot_vec_syn_delay_re = rot_vec_delay_re_LDQMF; hs->rot_vec_syn_delay_im = rot_vec_delay_im_LDQMF; -#ifdef IVAS_FLOAT_FIXED +#else hs->rot_vec_ana_delay_re_fx = rot_vec_delay_re_LDQMF_fx; hs->rot_vec_ana_delay_im_fx = rot_vec_delay_im_LDQMF_fx; hs->rot_vec_syn_delay_re_fx = rot_vec_delay_re_LDQMF_fx; hs->rot_vec_syn_delay_im_fx = rot_vec_delay_im_LDQMF_fx; - hs->p_filter_sf = (Word16) 15391; + hs->p_filter_sf = (Word16) 15391; // Q14 hs->p_filter = LDQMF_60_fx; hs->scale = cldfb_scale_5_0ms[5]; #endif diff --git a/lib_com/rom_com.c b/lib_com/rom_com.c index 648280d1e..e8143222d 100644 --- a/lib_com/rom_com.c +++ b/lib_com/rom_com.c @@ -36764,42 +36764,42 @@ const Word16 qGains[2][1 << kTcxHmNumGainBits] = const struct TnsParameters tnsParametersIGF32kHz_LowBR[1] = { - { 600, 3, 1.85f, 0.075f, 4.4f, 237/*1.85f Q7*/, 2458/*0.075f Q15*/,563 /*4.4f Q7*/ } + { 600, 3, /*1.85f, 0.075f, 4.4f,*/ 237/*1.85f Q7*/, 2458/*0.075f Q15*/,563 /*4.4f Q7*/ } }; const struct TnsParameters tnsParameters32kHz[2] = { - { 4500, 3, 1.35f, 0.0300f, 1.0f ,173/*1.35f Q7*/, 983/*0.0300f Q15*/, 128/*1.0f Q7*/}, - { 600, 1, 1.75f, 0.0625f, 4.4f ,224/*1.75f Q7*/, 2048/*0.0625f Q15*/, 563 /*4.4f Q7*/ } + { 4500, 3, /*1.35f, 0.0300f, 1.0f ,*/ 173/*1.35f Q7*/, 983/*0.0300f Q15*/, 128/*1.0f Q7*/}, + { 600, 1, /*1.75f, 0.0625f, 4.4f ,*/ 224/*1.75f Q7*/, 2048/*0.0625f Q15*/, 563 /*4.4f Q7*/ } }; const struct TnsParameters tnsParameters32kHz_grouped[2] = { - { 8400, 3, 1.375f, 0.03125f, 1.0f , 176/*1.375f Q7*/, 1024/*0.03125f Q15*/ , 128/*1.0f Q7*/ }, - { 800, 3, 1.375f, 0.03125f, 1.0f , 176/*1.375f Q7*/, 1024/*0.03125f Q15*/ , 128/*1.0f Q7*/} + { 8400, 3, /*1.375f, 0.03125f, 1.0f ,*/ 176/*1.375f Q7*/, 1024/*0.03125f Q15*/ , 128/*1.0f Q7*/ }, + { 800, 3, /*1.375f, 0.03125f, 1.0f ,*/ 176/*1.375f Q7*/, 1024/*0.03125f Q15*/ , 128/*1.0f Q7*/} }; const struct TnsParameters tnsParameters16kHz[1] = { - { 600, 3, 1.5f, 0.05f, 4.4f, 192/*1.5f Q7*/, 1638/*0.05f Q15*/ ,563 /*4.4f Q7*/ } + { 600, 3, /*1.5f, 0.05f, 4.4f,*/ 192/*1.5f Q7*/, 1638/*0.05f Q15*/ ,563 /*4.4f Q7*/ } }; const struct TnsParameters tnsParameters16kHz_grouped[2] = { - { 4400, 3, 1.5f, 0.05f, 1.0f, 192/*1.5f Q7*/, 1638/*0.05f Q15*/ , 128/*1.0f Q7*/}, - { 800, 3, 1.5f, 0.05f, 1.0f, 192/*1.5f Q7*/, 1638/*0.05f Q15*/ , 128/*1.0f Q7*/} + { 4400, 3, /*1.5f, 0.05f, 1.0f,*/ 192/*1.5f Q7*/, 1638/*0.05f Q15*/ , 128/*1.0f Q7*/}, + { 800, 3, /*1.5f, 0.05f, 1.0f,*/ 192/*1.5f Q7*/, 1638/*0.05f Q15*/ , 128/*1.0f Q7*/} }; const struct TnsParameters tnsParameters48kHz_grouped[2] = { - { 10400, 3, 1.375f, 0.03125f, 1.0f, 176/*1.375f Q7*/, 1024/*0.03125f Q15*/ , 128/*1.0f Q7*/}, - { 800, 3, 1.375f, 0.03125f, 1.0f, 176/*1.375f Q7*/, 1024/*0.03125f Q15*/ , 128/*1.0f Q7*/ } + { 10400, 3, /*1.375f, 0.03125f, 1.0f,*/ 176/*1.375f Q7*/, 1024/*0.03125f Q15*/ , 128/*1.0f Q7*/}, + { 800, 3, /*1.375f, 0.03125f, 1.0f,*/ 176/*1.375f Q7*/, 1024/*0.03125f Q15*/ , 128/*1.0f Q7*/ } }; const struct TnsParameters tnsParameters32kHz_Stereo[2]= { - { 4500, 3, 1.35f, 0.0300f, 1.0f ,173/*1.35f Q7*/, 983/*0.0300f Q15*/ , 128/*1.0f Q7*/}, - { 600, 3, 1.75f, 0.0625f, 4.4f ,224/*1.75f Q7*/, 2048/*0.0625f Q15*/ ,563 /*4.4f Q7*/ } + { 4500, 3, /*1.35f, 0.0300f, 1.0f ,*/ 173/*1.35f Q7*/, 983/*0.0300f Q15*/ , 128/*1.0f Q7*/}, + { 600, 3, /*1.75f, 0.0625f, 4.4f ,*/ 224/*1.75f Q7*/, 2048/*0.0625f Q15*/ ,563 /*4.4f Q7*/ } }; const float tnsAcfWindow[TNS_MAX_FILTER_ORDER] = diff --git a/lib_com/stat_com.h b/lib_com/stat_com.h index 97fec1041..4cfcb8caf 100644 --- a/lib_com/stat_com.h +++ b/lib_com/stat_com.h @@ -662,14 +662,16 @@ typedef struct ParamsBitMap struct TnsParameters { /* Parameters for each TNS filter */ - int16_t startLineFrequency; /* Starting lower frequency of the TNS filter [20..16000] */ - int16_t nSubdivisions; /* Number of spectrum subdivisions in which the filter operates [1..8) */ + Word16 startLineFrequency; /* Starting lower frequency of the TNS filter [20..16000] */ + Word16 nSubdivisions; /* Number of spectrum subdivisions in which the filter operates [1..8) */ +#ifndef IVAS_FLOAT_FIXED float minPredictionGain_flt; /* Minimum prediction gain required to turn on the TNS filter */ float minAvgSqrCoef_flt; /* Minimum average square of coefficients required to turn on the TNS filter */ float minEnergyChange_flt; /* Minimum energy change required to turn on the TNS filter */ - Word16 minPredictionGain; /* Minimum prediction gain required to turn on the TNS filter. Exponent = PRED_GAIN_E */ - Word16 minAvgSqrCoef; /* Minimum average square of coefficients required to turn on the TNS filter. Exponent = 0 */ - Word16 minEnergyChange; /* Minimum energy change required to turn on the TNS filter. Exponent = 8 */ +#endif + Word16 minPredictionGain; /* Minimum prediction gain required to turn on the TNS filter. Exponent = PRED_GAIN_E */ + Word16 minAvgSqrCoef; /* Minimum average square of coefficients required to turn on the TNS filter. Exponent = 0 */ + Word16 minEnergyChange; /* Minimum energy change required to turn on the TNS filter. Exponent = 8 */ }; /**********************************************/ @@ -713,31 +715,32 @@ typedef struct typedef struct cldfb_filter_bank_struct { - int16_t no_channels; - int16_t no_col; - int16_t p_filter_length; + Word16 no_channels; + Word16 no_col; + Word16 p_filter_length; Word16 lsb; /*!< Top of low subbands */ Word16 usb; /*!< Top of high subbands */ Word16 zeros; /*!< number of zeros in filter coefficients */ UWord16 flags; /*!< flags */ CLDFB_TYPE type; - int16_t ds; /* delay synthesis */ - int16_t da; /* delay analysis */ + Word16 ds; /* delay synthesis */ + Word16 da; /* delay analysis */ CLDFB_PROTOTYPE prototype; - +#ifndef IVAS_FLOAT_FIXED const float *p_filter_flt; +#endif const Word16 *p_filter; /*!< Pointer to filter coefficients */ Word16 p_filter_sf; /* rotation vectors */ +#ifndef IVAS_FLOAT_FIXED const float *rot_vec_ana_re; const float *rot_vec_ana_im; const float *rot_vec_syn_re; const float *rot_vec_syn_im; - -#ifdef IVAS_FLOAT_FIXED +#else const Word32 *rot_vec_syn_re_fx; const Word32 *rot_vec_syn_im_fx; @@ -745,12 +748,12 @@ typedef struct cldfb_filter_bank_struct const Word32 *rot_vec_syn_delay_im_fx; #endif /* rotation vectors for delay */ +#ifndef IVAS_FLOAT_FIXED const float *rot_vec_ana_delay_re; const float *rot_vec_ana_delay_im; const float *rot_vec_syn_delay_re; const float *rot_vec_syn_delay_im; - -#ifdef IVAS_FLOAT_FIXED +#else const Word32 *rot_vec_ana_re_fx; const Word32 *rot_vec_ana_im_fx; @@ -774,20 +777,20 @@ typedef struct cldfb_filter_bank_struct /* memory helper states */ +#ifndef IVAS_FLOAT_FIXED float *memory_flt; +#endif Word16 *memory; #ifdef IVAS_FLOAT_FIXED Word32 *memory32; /*because cldfb_state_fx is word32 which is used to assign values*/ #endif // IVAS_FLOAT_FIXED -#if 0 - //Can be deleted -#endif - uint16_t memory_length; + + UWord16 memory_length; /* main filter state */ +#ifndef IVAS_FLOAT_FIXED float *cldfb_state; - -#ifdef IVAS_FLOAT_FIXED +#else Word32 *cldfb_state_fx; Word16 cldfb_state_length; Word16 cldfb_size; @@ -795,8 +798,8 @@ typedef struct cldfb_filter_bank_struct #endif /* other parameters */ - int16_t bandsToZero; /* bands not synthesized */ - int16_t nab; /* number of active bands */ + Word16 bandsToZero; /* bands not synthesized */ + Word16 nab; /* number of active bands */ Word16 filtermode; float scale_flt; /* scaling of frequency domain */ diff --git a/lib_dec/ivas_mc_paramupmix_dec.c b/lib_dec/ivas_mc_paramupmix_dec.c index b0f8d25fe..1e867d4db 100644 --- a/lib_dec/ivas_mc_paramupmix_dec.c +++ b/lib_dec/ivas_mc_paramupmix_dec.c @@ -878,8 +878,8 @@ static void ivas_mc_paramupmix_dec_sf( scale_sig32( st_ivas->cldfbSynDec[ch]->cldfb_state_fx, st_ivas->cldfbSynDec[ch]->cldfb_size, Q5 - Q11 ); // Q11 -> Q5 st_ivas->cldfbSynDec[ch]->Q_cldfb_state = Q5; move16(); - cldfbSynthesis_ivas_fx( RealBuffer_fx, ImagBuffer_fx, &( output_fx[ch][0] ), L_mult0( maxBand, st_ivas->hTcBuffer->subframe_nbslots[subframeIdx] ), st_ivas->cldfbSynDec[ch] ); // output_fx returned in Q5 - scale_sig32( st_ivas->cldfbSynDec[ch]->cldfb_state_fx, st_ivas->cldfbSynDec[ch]->cldfb_size, Q11 - Q5 ); // Q5 -> Q11 + cldfbSynthesis_ivas_fx( RealBuffer_fx, ImagBuffer_fx, &( output_fx[ch][0] ), imult1616( maxBand, st_ivas->hTcBuffer->subframe_nbslots[subframeIdx] ), st_ivas->cldfbSynDec[ch] ); // output_fx returned in Q5 + scale_sig32( st_ivas->cldfbSynDec[ch]->cldfb_state_fx, st_ivas->cldfbSynDec[ch]->cldfb_size, Q11 - Q5 ); // Q5 -> Q11 st_ivas->cldfbSynDec[ch]->Q_cldfb_state = Q11; move16(); } diff --git a/lib_enc/ivas_core_enc.c b/lib_enc/ivas_core_enc.c index 32ea92422..d1a548d1d 100644 --- a/lib_enc/ivas_core_enc.c +++ b/lib_enc/ivas_core_enc.c @@ -915,13 +915,12 @@ ivas_error ivas_core_enc( #ifdef IVAS_FLOAT_FIXED_CONVERSIONS Word32 realBuffer_fx[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; Word32 imagBuffer_fx[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; - // Word16 new_swb_speech_16_fx[L_FRAME48k] = { 0 }; Word16 use_shb32 = 0; Word16 q_realImagBuffer = Q_factor_arrL( (float *) &realBuffer[n][0][0], CLDFB_NO_COL_MAX * CLDFB_NO_CHANNELS_MAX ); q_realImagBuffer = s_min( q_realImagBuffer, Q_factor_arrL( (float *) &imagBuffer[n][0][0], CLDFB_NO_COL_MAX * CLDFB_NO_CHANNELS_MAX ) ); + q_realImagBuffer = s_min( q_realImagBuffer, st->cldfbSynTd->Q_cldfb_state ); floatToFixed_arrL32( (float *) &realBuffer[n][0][0], (Word32 *) &realBuffer_fx[0][0], q_realImagBuffer, CLDFB_NO_COL_MAX * CLDFB_NO_CHANNELS_MAX ); floatToFixed_arrL32( (float *) &imagBuffer[n][0][0], (Word32 *) &imagBuffer_fx[0][0], q_realImagBuffer, CLDFB_NO_COL_MAX * CLDFB_NO_CHANNELS_MAX ); - floatToFixed_arrL32( (float *) &st->cldfbSynTd->cldfb_state[0], (Word32 *) &st->cldfbSynTd->cldfb_state_fx[0], q_realImagBuffer, st->cldfbSynTd->p_filter_length ); #if 0 floatToFixed_arr( &st->hSignalBuf->input_buff_flt[0], &st->hSignalBuf->input_buff[0], 0, L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ) ); @@ -962,7 +961,15 @@ ivas_error ivas_core_enc( } #endif #endif + + /* Scaling cldfb_state_fx */ + scale_sig32( st->cldfbSynTd->cldfb_state_fx, st->cldfbSynTd->p_filter_length, sub( q_realImagBuffer, st->cldfbSynTd->Q_cldfb_state ) ); + swb_pre_proc_ivas_fx( st, new_swb_speech_fx_16, new_swb_speech_fx, shb_speech_fx, shb_speech_fx_32, &use_shb32, realBuffer_fx, imagBuffer_fx, q_realImagBuffer, hCPE ); + + /* Re-scaling cldfb_state_fx */ + scale_sig32( st->cldfbSynTd->cldfb_state_fx, st->cldfbSynTd->p_filter_length, negate( sub( q_realImagBuffer, st->cldfbSynTd->Q_cldfb_state ) ) ); + #ifdef IVAS_FLOAT_FIXED_CONVERSIONS fixedToFloat_arr( (Word16 *) &st->hBWE_TD->old_speech_shb_fx[0], (float *) &st->hBWE_TD->old_speech_shb[0], 0, L_LOOK_16k + L_SUBFR16k ); fixedToFloat_arr( (Word16 *) &st->hBWE_FD->old_fdbwe_speech_fx[0], (float *) &st->hBWE_FD->old_fdbwe_speech[0], 0, L_FRAME48k ); @@ -971,7 +978,6 @@ ivas_error ivas_core_enc( { st->hBWE_FD->old_input[ii] = (Word16) st->hBWE_FD->old_input_fx[ii]; } - fixedToFloat_arrL32( (Word32 *) &st->cldfbSynTd->cldfb_state_fx[0], (float *) &st->cldfbSynTd->cldfb_state[0], q_realImagBuffer, st->cldfbSynTd->p_filter_length ); fixedToFloat_arr( new_swb_speech_fx_16, new_swb_speech, 0, L_FRAME48k ); if ( use_shb32 == 0 ) { @@ -1302,7 +1308,6 @@ ivas_error ivas_core_enc( Copy_Scale_sig_16_32( voice_factors_fx[0], voice_factors_fx32[0], NB_SUBFR16k, 16 ); // Q31 f2me_buf_16( hCPE->hStereoICBWE->mem_shb_speech_nonref, hCPE->hStereoICBWE->mem_shb_speech_nonref_fx, &hCPE->hStereoICBWE->mem_shb_speech_nonref_e, L_LOOK_16k ); // shb_speech_ref_e f2me_buf_16( hCPE->hStereoICBWE->mem_shb_speech_ref, hCPE->hStereoICBWE->mem_shb_speech_ref_fx, &hCPE->hStereoICBWE->mem_shb_speech_ref_e, L_LOOK_16k ); // shb_speech_ref_e - f2me_buf_16( hCPE->hStereoICBWE->shbSynthRef, hCPE->hStereoICBWE->shbSynthRef_fx, &hCPE->hStereoICBWE->shbSynthRef_e, L_LOOK_16k ); // shb_speech_ref_e f2me( hCPE->hStereoICBWE->icbweRefEner, &hCPE->hStereoICBWE->icbweRefEner_fx, &hCPE->hStereoICBWE->icbweRefEner_e ); scale_factor = s_min( scale_factor, Q_factor_arrL( hCPE->hStereoICBWE->mem_lpc_shbsynth_nonref, LPC_SHB_ORDER ) ); diff --git a/lib_enc/ivas_core_pre_proc_front.c b/lib_enc/ivas_core_pre_proc_front.c index 1a6970133..335e85063 100644 --- a/lib_enc/ivas_core_pre_proc_front.c +++ b/lib_enc/ivas_core_pre_proc_front.c @@ -912,10 +912,6 @@ ivas_error pre_proc_front_ivas_fx( } Word16 mem_decim_e; f2me_buf_16( st->mem_decim, st->mem_decim_fx, &mem_decim_e, 2 * L_FILT_MAX ); - IF( st->cldfbAnaEnc != NULL ) - { - floatToFixed_arrL( st->cldfbAnaEnc->cldfb_state, st->cldfbAnaEnc->cldfb_state_fx, Q11, sub( sub( st->cldfbAnaEnc->p_filter_length, st->cldfbAnaEnc->no_channels ), st->cldfbAnaEnc->zeros ) ); - } f2me_buf_16( st->old_inp_12k8, st->old_inp_12k8_fx, &st->exp_old_inp_12k8, 240 ); f2me_buf_16( old_inp_12k8, old_inp_12k8_fx, &old_inp_12k8_e, 496 ); if ( old_inp_12k8_e > st->exp_old_inp_12k8 ) @@ -1135,6 +1131,12 @@ ivas_error pre_proc_front_ivas_fx( LR_localVAD = 0; move16(); + IF( st->cldfbAnaEnc != NULL ) + { + scale_sig32( st->cldfbAnaEnc->cldfb_state_fx, sub( sub( st->cldfbAnaEnc->p_filter_length, st->cldfbAnaEnc->no_channels ), st->cldfbAnaEnc->zeros ), sub( Q11, st->cldfbAnaEnc->Q_cldfb_state ) ); + st->cldfbAnaEnc->Q_cldfb_state = Q11; + move16(); + } IF( hSCE != NULL ) { @@ -1556,10 +1558,6 @@ ivas_error pre_proc_front_ivas_fx( } cldfbScale.hb_scale = cldfbScale.lb_scale; fixedToFloat_arrL( enerBuffer_fx, enerBuffer, 31 - enerBuffer_exp, 60 ); - IF( st->cldfbAnaEnc != NULL ) - { - fixedToFloat_arrL( st->cldfbAnaEnc->cldfb_state_fx, st->cldfbAnaEnc->cldfb_state, Q11, sub( sub( st->cldfbAnaEnc->p_filter_length, st->cldfbAnaEnc->no_channels ), st->cldfbAnaEnc->zeros ) ); - } #endif #if 0 diff --git a/lib_enc/ivas_enc.c b/lib_enc/ivas_enc.c index bb6a9dc84..d2e4487b3 100644 --- a/lib_enc/ivas_enc.c +++ b/lib_enc/ivas_enc.c @@ -869,22 +869,8 @@ ivas_error ivas_enc( test(); IF( st_ivas->hQMetaData != NULL && EQ_32( ivas_format, MASA_FORMAT ) ) { -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - for ( i = 0; i < st_ivas->nchan_transport; i++ ) - { - floatToFixed_arrL( st_ivas->hMasa->data.cldfbAnaEnc[i]->cldfb_state, st_ivas->hMasa->data.cldfbAnaEnc[i]->cldfb_state_fx, Q11, st_ivas->hMasa->data.cldfbAnaEnc[i]->cldfb_state_length ); - } -#endif - ivas_masa_estimate_energy_fx( st_ivas->hMasa, data_fx, input_frame, st_ivas->nchan_transport, st_ivas->q_data_fx ); /* energy-estimation uses TF-resolution: 4x24 */ -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - for ( i = 0; i < st_ivas->nchan_transport; i++ ) - { - fixedToFloat_arrL( st_ivas->hMasa->data.cldfbAnaEnc[i]->cldfb_state_fx, st_ivas->hMasa->data.cldfbAnaEnc[i]->cldfb_state, Q11, st_ivas->hMasa->data.cldfbAnaEnc[i]->cldfb_state_length ); - } -#endif - IF( ( error = ivas_masa_enc_config_fx( st_ivas ) ) != IVAS_ERR_OK ) { return error; @@ -968,22 +954,10 @@ ivas_error ivas_enc( v_multc( data_f[hEncoderConfig->nchan_ism], 1.0f / SQRT2, data_f[hEncoderConfig->nchan_ism], input_frame ); mvr2r( data_f[hEncoderConfig->nchan_ism], data_f[hEncoderConfig->nchan_ism + 1], input_frame ); } - - for ( i = 0; i < st_ivas->nchan_transport; i++ ) - { - floatToFixed_arrL( st_ivas->hMasa->data.cldfbAnaEnc[i]->cldfb_state, st_ivas->hMasa->data.cldfbAnaEnc[i]->cldfb_state_fx, Q11, st_ivas->hMasa->data.cldfbAnaEnc[i]->cldfb_state_length ); - } #endif /* Estimate TF-tile energy for the input MASA stream */ ivas_masa_estimate_energy_fx( st_ivas->hMasa, &( data_fx[hEncoderConfig->nchan_ism] ), input_frame, st_ivas->nchan_transport, st_ivas->q_data_fx ); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - for ( i = 0; i < st_ivas->nchan_transport; i++ ) - { - fixedToFloat_arrL( st_ivas->hMasa->data.cldfbAnaEnc[i]->cldfb_state_fx, st_ivas->hMasa->data.cldfbAnaEnc[i]->cldfb_state, Q11, st_ivas->hMasa->data.cldfbAnaEnc[i]->cldfb_state_length ); - } -#endif - IF( ( error = ivas_omasa_enc_config_fx( st_ivas ) ) != IVAS_ERR_OK ) { return error; @@ -1014,21 +988,10 @@ ivas_error ivas_enc( st_ivas->q_data_fx = add( st_ivas->q_data_fx, norm_data_in ); move16(); } -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - OMASA_ENC_HANDLE hOMasa = st_ivas->hOMasa; - for ( i = 0; i < hEncoderConfig->nchan_ism; i++ ) - { - floatToFixed_arrL( hOMasa->cldfbAnaEnc[i]->cldfb_state, hOMasa->cldfbAnaEnc[i]->cldfb_state_fx, st_ivas->q_data_fx, hOMasa->cldfbAnaEnc[i]->cldfb_state_length ); - } -#endif /* Estimate MASA parameters for the objects */ ivas_omasa_enc_fx( st_ivas->hOMasa, st_ivas->hMasa, st_ivas->hIsmMetaData, data_fx, st_ivas->q_data_fx, input_frame, st_ivas->nchan_transport, hEncoderConfig->nchan_ism, st_ivas->ism_mode, data_separated_object_fx, &idx_separated_object ); #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - for ( i = 0; i < hEncoderConfig->nchan_ism; i++ ) - { - fixedToFloat_arrL( hOMasa->cldfbAnaEnc[i]->cldfb_state_fx, hOMasa->cldfbAnaEnc[i]->cldfb_state, st_ivas->q_data_fx, hOMasa->cldfbAnaEnc[i]->cldfb_state_length ); - } for ( i = 0; i < hEncoderConfig->nchan_ism + st_ivas->nchan_transport; i++ ) { fixedToFloat_arrL( data_fx[i], data_f[i], st_ivas->q_data_fx, input_frame ); diff --git a/lib_enc/ivas_stereo_switching_enc.c b/lib_enc/ivas_stereo_switching_enc.c index ef62186fe..96dab941c 100644 --- a/lib_enc/ivas_stereo_switching_enc.c +++ b/lib_enc/ivas_stereo_switching_enc.c @@ -1319,7 +1319,7 @@ void stereo_switching_enc_fx( sts[0]->cldfbAnaEnc->cldfb_state_fx[i] = L_deposit_h( old_input_signal_pri[input_frame - offset - NS2SA( input_frame * FRAMES_PER_SEC, L_MEM_RECALC_TBE_NS ) + i] ); move32(); } - sts[0]->cldfbAnaEnc->Q_cldfb_state = Q16; + sts[0]->cldfbAnaEnc->Q_cldfb_state = add( Q16, q_inp ); move16(); } @@ -1337,6 +1337,8 @@ void stereo_switching_enc_fx( IF( hCPE->hStereoTD != NULL && EQ_16( hCPE->hStereoTD->tdm_last_ratio_idx, LRTD_STEREO_LEFT_IS_PRIM ) ) { v_multc_fixed_32_16( hCPE->hCoreCoder[1]->old_input_signal_fx + sub( input_frame, add( offset, NS2SA( input_frame * FRAMES_PER_SEC, L_MEM_RECALC_TBE_NS ) ) ), -MAX_32, sts[1]->cldfbAnaEnc->cldfb_state_fx, offset ); + sts[1]->cldfbAnaEnc->Q_cldfb_state = add( Q16, q_inp ); + move16(); } ELSE { @@ -1345,6 +1347,8 @@ void stereo_switching_enc_fx( sts[1]->cldfbAnaEnc->cldfb_state_fx[i] = L_shr( L_deposit_h( hCPE->hCoreCoder[1]->old_input_signal_fx[input_frame - offset - NS2SA( input_frame * FRAMES_PER_SEC, L_MEM_RECALC_TBE_NS ) + i] ), 5 ); move32(); } + sts[1]->cldfbAnaEnc->Q_cldfb_state = add( Q16 - 5, q_inp ); + move16(); } IF( sts[1]->cldfbSynTd != NULL ) diff --git a/lib_enc/ivas_tcx_core_enc.c b/lib_enc/ivas_tcx_core_enc.c index 40223d1bd..926a1930d 100644 --- a/lib_enc/ivas_tcx_core_enc.c +++ b/lib_enc/ivas_tcx_core_enc.c @@ -1716,7 +1716,7 @@ Word16 ivas_acelp_tcx20_switching_fx( xn_buf_fx[L_frame + i] = mult( xn_buf_fx[L_frame + i], window_fx[overlap - 1 - i] ); move16(); } - e_x = 16; + e_x = sub( 16, q_inp ); /*exponent for xn_buf_fx*/ move16(); TCX_MDCT( xn_buf_fx, x_fx, &e_x, overlap, sub( L_frame, overlap ), overlap, st->element_mode ); scale_A = getScaleFactor32( x_fx, L_frame ); @@ -1786,9 +1786,8 @@ Word16 ivas_acelp_tcx20_switching_fx( s = shl( sub( e_x, s ), 1 ); - tmp32 = L_add( BASOP_Util_Log2( ener ), L_shl( L_deposit_l( s ), 25 ) ); /* log2, 6Q25 */ - tmp32 = L_shr( tmp32, 9 ); /* 15Q16 */ - en[i] = L_add( tmp32, 0x2FD5F ); /* 0x2FD5F -> 9.f * log2(10)/10 (15Q16) */ + tmp32 = L_add( L_shr( BASOP_Util_Log2( ener ), 9 ), L_shl( L_deposit_l( s ), 16 ) ); /* 15Q16 */ + en[i] = L_add( tmp32, 0x2FD5F ); /* 0x2FD5F -> 9.f * log2(10)/10 (15Q16) */ move32(); x_fx += 4; diff --git a/lib_enc/swb_tbe_enc_fx.c b/lib_enc/swb_tbe_enc_fx.c index 4618eaaa6..e81ec96ba 100644 --- a/lib_enc/swb_tbe_enc_fx.c +++ b/lib_enc/swb_tbe_enc_fx.c @@ -3564,6 +3564,7 @@ void swb_tbe_enc_ivas_fx( IF( GE_16( st_fx->element_mode, IVAS_CPE_DFT ) && hStereoICBWE != NULL ) { Copy( shaped_shb_excitation_fx + L_SHB_LAHEAD, hStereoICBWE->shbSynthRef_fx, L_FRAME16k ); + hStereoICBWE->shbSynthRef_e = sub( 15, Q_bwe_exc ); } test(); -- GitLab From 4b93ac654828a57440543d327544132797d04a40 Mon Sep 17 00:00:00 2001 From: vaclav Date: Mon, 4 Nov 2024 16:34:29 +0100 Subject: [PATCH 074/128] fix 999: fix ISM extended metadata decoding; under FIX_999_WRONG_ISM_EXTENDED_METADATA --- lib_com/options.h | 1 + lib_dec/ivas_ism_metadata_dec.c | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/lib_com/options.h b/lib_com/options.h index 3ff81cd74..095c183e8 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -195,6 +195,7 @@ #define FIX_853_DECODE_MASA_ISM_AZIMUTH_PREC /* Nokia: Fixes ivas_decode_masaism_metadata decision logic change due to precision difference; needs corresponding fix in floating point */ #define FIX_953_WRONG_ENERGY_RATIO_MASA_EXT /* Nok: Fix 953 wrong energy ratio value after shift and cast to Word8 */ #define FIX_982_WRONG_DECODED_ENERGY_RATIO /* Nokia: Fix 982 wrong energy in EXT mode and in second direction when present */ +#define FIX_999_WRONG_ISM_EXTENDED_METADATA /* VA: fix 999: fix ISM extended metadata decoding */ /* ################## End DEVELOPMENT switches ######################### */ /* clang-format on */ diff --git a/lib_dec/ivas_ism_metadata_dec.c b/lib_dec/ivas_ism_metadata_dec.c index 633459a2a..1aac7e900 100644 --- a/lib_dec/ivas_ism_metadata_dec.c +++ b/lib_dec/ivas_ism_metadata_dec.c @@ -1081,7 +1081,11 @@ ivas_error ivas_ism_metadata_dec_fx( idx_angle2 = hIsmMetaData->orientation_angle.last_angle2_idx; move16(); yaw_fx = ism_dequant_meta_fx( idx_angle1, ism_azimuth_borders_fx, ISM_Q_STEP_FX, ISM_Q_STEP_BORDER_FX, ( 1 << ISM_AZIMUTH_NBITS ) ); +#ifdef FIX_999_WRONG_ISM_EXTENDED_METADATA + pitch_fx = ism_dequant_meta_fx( idx_angle2, ism_elevation_borders_fx, ISM_Q_STEP_FX, ISM_Q_STEP_BORDER_FX, ( 1 << ISM_ELEVATION_NBITS ) ); +#else pitch_fx = ism_dequant_meta_fx( idx_angle2, ism_elevation_borders_fx, ISM_Q_STEP_FX, ISM_Q_STEP_BORDER_FX, ( 1 << ISM_AZIMUTH_NBITS ) ); +#endif idx_radius = decode_radius_fx( st0, &hIsmMetaData->last_radius_idx, &flag_abs_radius ); radius_fx = usdequant_fx( idx_radius, ISM_RADIUS_MIN_Q9, ISM_RADIUS_DELTA_Q8 ); -- GitLab From 2e47ef37fa2238967b21fbc8082c095c23ebcdc1 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Mon, 4 Nov 2024 20:30:54 +0530 Subject: [PATCH 075/128] Fix for 3GPP issue 979: OSBA 128kbps JBM - Saturations across whole signal [x] For this issue, MLD reduced from 88.xx to 12.xx. On debugging 12.xx artifacts, it was observed that it is due to different PLC mode in Float and Basop decoder. When tried giving same PLC mode in both all visible artifacts get resolved. --- lib_dec/ivas_mdct_core_dec.c | 7 ------- lib_dec/lib_dec_fx.c | 17 +++++++++++++++-- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/lib_dec/ivas_mdct_core_dec.c b/lib_dec/ivas_mdct_core_dec.c index caa01e7de..0550189ac 100644 --- a/lib_dec/ivas_mdct_core_dec.c +++ b/lib_dec/ivas_mdct_core_dec.c @@ -2163,11 +2163,6 @@ void ivas_mdct_core_reconstruct_fx( ELSE /*ACELP core for ACELP-PLC */ { assert( EQ_16( st->bfi, 1 ) ); - Scale_sig( synth_buf_fx, add( add( st->hTcxDec->old_synth_len, L_FRAME_PLUS ), M ), negate( q_syn ) ); // Q0 - Scale_sig( synth_bufFB_fx, add( add( st->hTcxDec->old_synth_lenFB, L_FRAME_PLUS ), M ), negate( q_syn ) ); // Q0 - q_syn = 0; - move16(); - move16(); /* PLC: [TCX: TD PLC] */ IF( MCT_flag != 0 ) { @@ -2184,8 +2179,6 @@ void ivas_mdct_core_reconstruct_fx( con_tcx_ivas_fx( st, &synthFB_fx[0], hCPE->hStereoMdct->lastCoh_fx, &sts[0]->seed_acelp, 0, &st->hFdCngDec->hFdCngCom->A_cng[0] ); } } - - Scale_sig( synthFB_fx, st->hTcxDec->L_frameTCX, q_syn ); // q_syn IF( ( EQ_16( st->nbLostCmpt, 1 ) ) || ( st->hTcxDec->tcxConceal_recalc_exc != 0 ) ) { Scale_sig( synthFB_fx - add( add( shr( st->hTcxDec->L_frameTCX, 1 ), st->hTcxDec->pit_max_TCX ), 2 * M ), add( add( shr( st->hTcxDec->L_frameTCX, 1 ), st->hTcxDec->pit_max_TCX ), 2 * M ), sub( q_syn, sub( st->Q_exc, 1 ) ) ); // 2 * q_syn - (st->Q_exc - 1) diff --git a/lib_dec/lib_dec_fx.c b/lib_dec/lib_dec_fx.c index 9d1fb571c..1ec213673 100644 --- a/lib_dec/lib_dec_fx.c +++ b/lib_dec/lib_dec_fx.c @@ -1105,9 +1105,22 @@ ivas_error IVAS_DEC_GetSamples( } ELSE { + Word32 max_val; + Word16 max_shift; + + maximum_32_fx( hIvasDec->apaExecBuffer_fx, APA_BUF_PER_CHANNEL * nTransportChannels, &max_val ); + IF( max_val ) + { + max_shift = sub( 31 - 3, norm_l( L_shr( max_val, 11 ) ) ); + } + ELSE + { + max_shift = Q11; + move16(); + } FOR( Word32 i = 0; i < APA_BUF_PER_CHANNEL * nTransportChannels; ++i ) { - tmp_apaExecBuffer[i] = extract_l( L_shr( hIvasDec->apaExecBuffer_fx[i], Q12 ) ); // Q(-1) + tmp_apaExecBuffer[i] = extract_l( L_shr( hIvasDec->apaExecBuffer_fx[i], max_shift ) ); // Q(-1) } IF( apa_exec_ivas_fx( hIvasDec->hTimeScaler, tmp_apaExecBuffer, (UWord16) imult3216( hIvasDec->nSamplesFrame, nTransportChannels ), (UWord16) hIvasDec->tsm_max_scaling, tmp_apaExecBuffer, &nTimeScalerOutSamples ) != 0 ) { @@ -1116,7 +1129,7 @@ ivas_error IVAS_DEC_GetSamples( FOR( Word32 i = 0; i < APA_BUF_PER_CHANNEL * nTransportChannels; ++i ) { - hIvasDec->apaExecBuffer_fx[i] = L_shl( tmp_apaExecBuffer[i], Q12 ); // Q11 + hIvasDec->apaExecBuffer_fx[i] = L_shl( tmp_apaExecBuffer[i], max_shift ); // Q11 } } assert( LE_32( (Word32) nTimeScalerOutSamples, APA_BUF ) ); -- GitLab From a930638c710eba58d3485fcf2be4eb96785f87ce Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Tue, 5 Nov 2024 08:38:48 +0530 Subject: [PATCH 076/128] Fix for JBM MLD cases --- lib_dec/lib_dec_fx.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib_dec/lib_dec_fx.c b/lib_dec/lib_dec_fx.c index 1ec213673..90b3eb4d8 100644 --- a/lib_dec/lib_dec_fx.c +++ b/lib_dec/lib_dec_fx.c @@ -1111,11 +1111,11 @@ ivas_error IVAS_DEC_GetSamples( maximum_32_fx( hIvasDec->apaExecBuffer_fx, APA_BUF_PER_CHANNEL * nTransportChannels, &max_val ); IF( max_val ) { - max_shift = sub( 31 - 3, norm_l( L_shr( max_val, 11 ) ) ); + max_shift = s_max( Q12, sub( 31 - 3, norm_l( L_shr( max_val, 11 ) ) ) ); } ELSE { - max_shift = Q11; + max_shift = Q12; move16(); } FOR( Word32 i = 0; i < APA_BUF_PER_CHANNEL * nTransportChannels; ++i ) -- GitLab From d92a8c6ab51eeeeedca45b7f7a395949624e66c1 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Tue, 5 Nov 2024 12:25:05 +0530 Subject: [PATCH 077/128] Fix for 3GPP issue 997: Decoder crashed when decoding an OSBA bitstream --- lib_com/ivas_filters.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib_com/ivas_filters.c b/lib_com/ivas_filters.c index 425149fe0..0ef0960d7 100644 --- a/lib_com/ivas_filters.c +++ b/lib_com/ivas_filters.c @@ -354,6 +354,14 @@ static void ivas_iir_2_filter_fx( filter_state->state_fx[stage][j - 1] = BASOP_Util_Add_Mant32Exp( L_tmp, L_tmp_e, L_negate( L_tmp_prod ), L_prod_e, &filter_state->state_e[stage][j - 1] ); // Q31 - filter_state->state_e[stage][j - 1] move32(); + /*In case when exponent is less than -31 the value is very small and negligible hence resetting it to zero to avoid exponent overflow*/ + IF( LT_16( filter_state->state_e[stage][j - 1], -31 ) ) + { + filter_state->state_fx[stage][j - 1] = 0; + move32(); + filter_state->state_e[stage][j - 1] = 0; + move16(); + } } } } -- GitLab From dd2c551db9ea194a12968e35a5122483206fae04 Mon Sep 17 00:00:00 2001 From: Erik Norvell Date: Tue, 5 Nov 2024 11:49:33 +0100 Subject: [PATCH 078/128] Adding coverage test --- .gitlab-ci.yml | 90 ++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 77 insertions(+), 13 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 3167243ff..0f26f2ac4 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -8,6 +8,7 @@ variables: EXIT_CODE_NON_BE: 123 EXIT_CODE_FAIL: 1 LONG_TEST_SUITE: "tests/codec_be_on_mr_nonselection tests/renderer --param_file scripts/config/self_test_ltv.prm --use_ltv" + LONG_TEST_SUITE_NO_RENDERER: "tests/codec_be_on_mr_nonselection --param_file scripts/config/self_test_ltv.prm --use_ltv" SHORT_TEST_SUITE: "tests/codec_be_on_mr_nonselection" TEST_SUITE: "" DUT_ENCODER_PATH: "./IVAS_cod" @@ -111,20 +112,25 @@ stages: echo "Commit time was $CI_COMMIT_TIMESTAMP" date | xargs echo "System time is" -.build-reference-and-dut-binaries: &build-reference-and-dut-binaries - - current_commit_sha=$(git rev-parse HEAD) - ### build reference binaries - - git checkout $REFERENCE_BRANCH - - git pull - - make clean - - make -j - - mv ./IVAS_cod ./$REF_ENCODER_PATH - - mv ./IVAS_dec ./$REF_DECODER_PATH - - mv ./IVAS_rend ./IVAS_rend_ref +.build-reference-binaries: &build-reference-binaries +- current_commit_sha=$(git rev-parse HEAD) +### build reference binaries +- git checkout $REFERENCE_BRANCH +- git pull +- make clean +- make -j +- mv ./IVAS_cod ./$REF_ENCODER_PATH +- mv ./IVAS_dec ./$REF_DECODER_PATH +- mv ./IVAS_rend ./IVAS_rend_ref +### Return to current branch +- git restore . +- git checkout $current_commit_sha - ### build test binaries - - git restore . - - git checkout $current_commit_sha + +.build-reference-and-dut-binaries: &build-reference-and-dut-binaries +### build reference binaries + - *build-reference-binaries +### build dut binaries - make clean - make -j @@ -212,6 +218,15 @@ stages: - if: $CI_PIPELINE_SOURCE == 'merge_request_event' when: never +.rules-coverage: + rules: + - if: $COVERAGE_TEST # Set by scheduled pipeline + - if: $CI_PIPELINE_SOURCE == 'web' && $MANUAL_PIPELINE_TYPE == "coverage" + - if: $CI_PIPELINE_SOURCE == 'push' + when: never + - if: $CI_PIPELINE_SOURCE == 'merge_request_event' + when: never + .rules-pytest-saturation-smoke-test: rules: - if: $PYTEST_SMOKE_TEST # Set by scheduled pipeline @@ -996,6 +1011,55 @@ ivas-smoke-test-saturation: - smoke_test_output_hrtf.txt expose_as: "saturation smoke test results" + +# GCOV/LCOV coverage analysis of self_test suite +coverage-test-on-main-scheduled: + extends: + - .rules-coverage + tags: + - ivas-linux-basop + stage: test + timeout: 3 hours + script: + - *print-common-info + - *update-ltv-repo + - *copy-ltv-files-to-testv-dir + - *build-reference-binaries + # Build DuT binaries with GCOV + - make clean + - make GCOV=1 -j + + - exit_code_dec=0 + - python3 -m pytest --tb=no $LONG_TEST_SUITE --update_ref 1 -v --create_ref --html=report-dec.html --self-contained-html --junit-xml=report-junit-dec.xml -n auto --testcase_timeout $testcase_timeout --ref_encoder_path $REF_ENCODER_PATH --ref_decoder_path $DUT_DECODER_PATH || exit_code_dec=$? + - lcov -c -d obj -o coverage_dec_rend.info # extract coverage of decoder/renderer + + - python3 -m pytest --tb=no $LONG_TEST_SUITE_NO_RENDERER --encoder_only -v --html=report-enc.html --self-contained-html --junit-xml=report-junit-enc.xml -n auto --testcase_timeout $testcase_timeout --dut_encoder_path $DUT_ENCODER_PATH || exit_code_enc=$? + - lcov -c -d obj -o coverage_enc_dec_rend.info # extract coverage of encoder/decoder/renderer + + # remove apps and lib_util files from coverage + - lcov -r coverage_dec_rend.info "*apps*" -o coverage_dec_rend.info + - lcov -r coverage_dec_rend.info "*lib_util*" -o coverage_dec_rend.info + - lcov -r coverage_enc_dec_rend.info "*apps*" -o coverage_enc_dec_rend.info + - lcov -r coverage_enc_dec_rend.info "*lib_util*" -o coverage_enc_dec_rend.info + + - commit_sha=$(git rev-parse HEAD) + - genhtml coverage_enc_dec_rend.info -o coverage_enc_dec_rend -t "Coverage on main enc/dec/rend @ $commit_sha" + - genhtml coverage_dec_rend.info -o coverage_dec_rend -t "Coverage on main -- dec/rend @ $commit_sha" + artifacts: + name: "main-coverage-sha-$CI_COMMIT_SHORT_SHA" + when: always + expire_in: 1 week + paths: + - coverage_enc_dec_rend.info + - coverage_dec_rend.info + - coverage_enc_dec_rend + - coverage_dec_rend + expose_as: "Coverage result" + reports: + junit: + - report-junit-dec.xml + - report-junit-enc.xml + # --------------------------------------------------------------- # EVS 26.444 test job # --------------------------------------------------------------- -- GitLab From c9b81367e4b0f24ea93a5573a0b59f55d90baebf Mon Sep 17 00:00:00 2001 From: Erik Norvell Date: Tue, 5 Nov 2024 11:51:47 +0100 Subject: [PATCH 079/128] Add manual job in drop-down for coverage --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 0f26f2ac4..4eefa5b62 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -41,7 +41,7 @@ variables: - 'sanitizer-stv' - 'pytest-renderer' - 'complexity' - + - 'coverage' default: interruptible: true # Make all jobs by default interruptible -- GitLab From c2b230abea3055ee33f5e2a3cb8c04e516942171 Mon Sep 17 00:00:00 2001 From: Erik Norvell Date: Tue, 5 Nov 2024 11:54:30 +0100 Subject: [PATCH 080/128] Fix rules on coverage job --- .gitlab-ci.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 4eefa5b62..6fe04ea76 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1015,9 +1015,8 @@ ivas-smoke-test-saturation: # GCOV/LCOV coverage analysis of self_test suite coverage-test-on-main-scheduled: extends: + - .test-job-linux - .rules-coverage - tags: - - ivas-linux-basop stage: test timeout: 3 hours script: -- GitLab From cd92a07b48764d9894942c70519c1e073c76a149 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Tue, 5 Nov 2024 14:04:33 +0530 Subject: [PATCH 081/128] Fix for 3GPP issue 784: BASOP decoder without JBM not BE to BASOP decoder with zero-delay profile [x] Changed implementation of apa_exec to take 32 bit input and changed intermediate processing to take variable Q. [x] Validated changes for 3GPP issues #979 and #980. --- lib_dec/jbm_pcmdsp_apa.c | 44 +++++++++++++++++++++++++++++++--------- lib_dec/jbm_pcmdsp_apa.h | 2 +- lib_dec/lib_dec_fx.c | 26 ++---------------------- 3 files changed, 37 insertions(+), 35 deletions(-) diff --git a/lib_dec/jbm_pcmdsp_apa.c b/lib_dec/jbm_pcmdsp_apa.c index 1ddb7fee6..942a5a906 100644 --- a/lib_dec/jbm_pcmdsp_apa.c +++ b/lib_dec/jbm_pcmdsp_apa.c @@ -76,6 +76,7 @@ struct apa_state_t bool evs_compat_mode; Word16 *buf_out_fx; + Word16 Q_buf_out; UWord16 buf_out_capacity; UWord16 l_buf_out; @@ -183,6 +184,8 @@ ivas_error apa_init( { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for JBM\n" ) ); } + ps->Q_buf_out = Q15; + move16(); ps->evs_compat_mode = false; move16(); @@ -262,6 +265,8 @@ UWord8 apa_reconfigure( free( ps->buf_out_fx ); ps->buf_out_fx = (Word16 *) malloc( sizeof( Word16 ) * ps->buf_out_capacity ); + ps->Q_buf_out = Q15; + move16(); IF( !ps->buf_out_fx ) { return 2; @@ -871,10 +876,10 @@ UWord8 apa_exec_fx( UWord8 apa_exec_ivas_fx( apa_state_t *ps, /* i/o: state struct */ - const Word16 a_in[], /* i : input samples Q(-1) */ + const Word32 a_in[], /* i : input samples Q(-1) */ UWord16 l_in, /* i : number of input samples */ UWord16 maxScaling, /* i : allowed number of inserted/removed samples */ - Word16 a_out[], /* o : output samples Q(-1) */ + Word32 a_out[], /* o : output samples Q(-1) */ UWord16 *l_out /* o : number of output samples */ ) { @@ -885,7 +890,9 @@ UWord8 apa_exec_ivas_fx( Word32 dl_scaled, dl_copied, l_frm_out_target; Word32 expScaling, actScaling; UWord32 statsResetThreshold, statsResetShift; + Word16 Q_a_out; + Q_a_out = add( getScaleFactor32( a_in, i_mult( ps->num_channels, APA_BUF_PER_CHANNEL ) ), Q11 - Q16 ); statsResetThreshold = 1637; move32(); statsResetShift = 2; @@ -942,16 +949,25 @@ UWord8 apa_exec_ivas_fx( FOR( i = 0; i < ps->l_frm; i++ ) { a_out[i] = a_in[i]; - move16(); + move32(); } l_frm_out = ps->l_frm; move16(); } ELSE { + Word16 a_tmp[APA_BUF]; Word16 *buf_out_ptr = &( ps->buf_out_fx[ps->l_buf_out - ps->l_frm] ); Word16 *frm_in_ptr = &( frm_in[ps->l_frm] ); + Q_a_out = s_min( Q_a_out, ps->Q_buf_out ); + FOR( i = 0; i < ps->num_channels * APA_BUF_PER_CHANNEL; i++ ) + { + a_tmp[i] = extract_h( L_shl( a_in[i], add( Q_a_out, Q5 ) ) ); // Q_a_out + move16(); + } + Scale_sig( ps->buf_out_fx, ps->buf_out_capacity, sub( Q_a_out, ps->Q_buf_out ) ); // Q_buf_out -> Q_a_out + /* fill input frame */ /* 1st input frame: previous output samples */ FOR( i = 0; i < ps->l_frm; i++ ) @@ -962,23 +978,23 @@ UWord8 apa_exec_ivas_fx( /* 2nd input frame: new input samples */ FOR( i = 0; i < ps->l_frm; i++ ) { - frm_in_ptr[i] = a_in[i]; + frm_in_ptr[i] = a_tmp[i]; move16(); } /* no scaling */ IF( EQ_32( ps->scale, 100 ) ) { - copy_frm_fx( ps, frm_in, a_out, &l_frm_out ); + copy_frm_fx( ps, frm_in, a_tmp, &l_frm_out ); } /* shrink */ ELSE IF( LT_32( ps->scale, 100 ) ) { - shrink_frm_fx( ps, frm_in, maxScaling, a_out, &l_frm_out ); + shrink_frm_fx( ps, frm_in, maxScaling, a_tmp, &l_frm_out ); } /* extend */ ELSE { - extend_frm_fx( ps, frm_in, a_out, &l_frm_out ); + extend_frm_fx( ps, frm_in, a_tmp, &l_frm_out ); } /* control the amount/frequency of scaling */ IF( NE_32( l_frm_out, ps->l_frm ) ) @@ -988,7 +1004,7 @@ UWord8 apa_exec_ivas_fx( GT_32( abs_s( extract_l( L_sub( ps->l_frm, l_frm_out ) ) ), maxScaling ) ) { /* maxScaling exceeded -> discard scaled frame */ - copy_frm_fx( ps, frm_in, a_out, &l_frm_out ); + copy_frm_fx( ps, frm_in, a_tmp, &l_frm_out ); } ELSE IF( GT_32( L_abs( l_frm_out_target ), ps->l_frm ) ) /* ignore small difference */ { @@ -997,10 +1013,16 @@ UWord8 apa_exec_ivas_fx( /* discard scaled frame if copied frame is closer to target length */ IF( LT_32( L_abs( dl_copied ), L_abs( dl_scaled ) ) ) { - copy_frm_fx( ps, frm_in, a_out, &l_frm_out ); + copy_frm_fx( ps, frm_in, a_tmp, &l_frm_out ); } } } + + FOR( i = 0; i < ps->num_channels * APA_BUF_PER_CHANNEL; i++ ) + { + a_out[i] = L_shl( a_tmp[i], sub( Q11, Q_a_out ) ); // Q0 -> Q11 + move32(); + } } /* copy output to internal buffer */ @@ -1035,9 +1057,11 @@ UWord8 apa_exec_ivas_fx( Word16 *buf_out_ptr = &( ps->buf_out_fx[ps->l_buf_out] ); FOR( i = 0; i < l_frm_out; i++ ) { - buf_out_ptr[i] = a_out[i]; + buf_out_ptr[i] = extract_h( L_shl( a_out[i], add( Q_a_out, Q16 - Q11 ) ) ); // Q_a_out move16(); } + ps->Q_buf_out = Q_a_out; + move16(); } ps->l_buf_out = (UWord16) L_add( ps->l_buf_out, l_frm_out ); move16(); diff --git a/lib_dec/jbm_pcmdsp_apa.h b/lib_dec/jbm_pcmdsp_apa.h index 42215ba16..33edf411a 100644 --- a/lib_dec/jbm_pcmdsp_apa.h +++ b/lib_dec/jbm_pcmdsp_apa.h @@ -147,7 +147,7 @@ bool apa_exit( apa_state_t **s ); #ifndef IVAS_FLOAT_FIXED uint8_t apa_exec( apa_state_t *s, const float a_in[], uint16_t l_in, uint16_t maxScaling, float a_out[], uint16_t *l_out ); #else -uint8_t apa_exec_ivas_fx( apa_state_t *s, const Word16 a_in[], UWord16 l_in, UWord16 maxScaling, Word16 a_out[], UWord16 *l_out ); +UWord8 apa_exec_ivas_fx( apa_state_t *s, const Word32 a_in[], UWord16 l_in, UWord16 maxScaling, Word32 a_out[], UWord16 *l_out ); uint8_t apa_exec_fx( apa_state_t *s, const Word16 a_in[], UWord16 l_in, UWord16 maxScaling, Word16 a_out[], UWord16 *l_out ); #endif #endif /* JBM_PCMDSP_APA_H */ diff --git a/lib_dec/lib_dec_fx.c b/lib_dec/lib_dec_fx.c index 90b3eb4d8..77cc8710f 100644 --- a/lib_dec/lib_dec_fx.c +++ b/lib_dec/lib_dec_fx.c @@ -1087,9 +1087,9 @@ ivas_error IVAS_DEC_GetSamples( } // tmp apaExecBuffer - Word16 tmp_apaExecBuffer[APA_BUF]; IF( EQ_16( (Word16) hIvasDec->mode, IVAS_DEC_MODE_EVS ) ) { + Word16 tmp_apaExecBuffer[APA_BUF]; FOR( Word32 i = 0; i < APA_BUF_PER_CHANNEL * nTransportChannels; ++i ) { tmp_apaExecBuffer[i] = extract_l( L_shr( hIvasDec->apaExecBuffer_fx[i], Q11 ) ); // Q0 @@ -1105,32 +1105,10 @@ ivas_error IVAS_DEC_GetSamples( } ELSE { - Word32 max_val; - Word16 max_shift; - - maximum_32_fx( hIvasDec->apaExecBuffer_fx, APA_BUF_PER_CHANNEL * nTransportChannels, &max_val ); - IF( max_val ) - { - max_shift = s_max( Q12, sub( 31 - 3, norm_l( L_shr( max_val, 11 ) ) ) ); - } - ELSE - { - max_shift = Q12; - move16(); - } - FOR( Word32 i = 0; i < APA_BUF_PER_CHANNEL * nTransportChannels; ++i ) - { - tmp_apaExecBuffer[i] = extract_l( L_shr( hIvasDec->apaExecBuffer_fx[i], max_shift ) ); // Q(-1) - } - IF( apa_exec_ivas_fx( hIvasDec->hTimeScaler, tmp_apaExecBuffer, (UWord16) imult3216( hIvasDec->nSamplesFrame, nTransportChannels ), (UWord16) hIvasDec->tsm_max_scaling, tmp_apaExecBuffer, &nTimeScalerOutSamples ) != 0 ) + IF( apa_exec_ivas_fx( hIvasDec->hTimeScaler, hIvasDec->apaExecBuffer_fx, (UWord16) imult3216( hIvasDec->nSamplesFrame, nTransportChannels ), (UWord16) hIvasDec->tsm_max_scaling, hIvasDec->apaExecBuffer_fx, &nTimeScalerOutSamples ) != 0 ) { return IVAS_ERR_UNKNOWN; } - - FOR( Word32 i = 0; i < APA_BUF_PER_CHANNEL * nTransportChannels; ++i ) - { - hIvasDec->apaExecBuffer_fx[i] = L_shl( tmp_apaExecBuffer[i], max_shift ); // Q11 - } } assert( LE_32( (Word32) nTimeScalerOutSamples, APA_BUF ) ); nSamplesTcsScaled = idiv1616U( extract_l( nTimeScalerOutSamples ), nTransportChannels ); -- GitLab From 167d9b1f3473a247bc92421020874e5b08e614c1 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Tue, 5 Nov 2024 17:59:17 +0530 Subject: [PATCH 082/128] Fix for crash issue Multi-channel 7_1_4 at 256 kbps, 48kHz in, 48kHz out, 7_1_4 out, JBM Prof 5 --- lib_com/basop_util.c | 38 ++++++++++++++++++++++++++++++++++++++ lib_com/basop_util.h | 3 +++ lib_dec/jbm_pcmdsp_apa.c | 2 +- 3 files changed, 42 insertions(+), 1 deletion(-) diff --git a/lib_com/basop_util.c b/lib_com/basop_util.c index 71f324f98..1a2ef14f8 100644 --- a/lib_com/basop_util.c +++ b/lib_com/basop_util.c @@ -804,6 +804,44 @@ Word16 getScaleFactor32( /* o: measured headroom in range [ return i; } +Word16 getScaleFactor32_copy( /* o: measured headroom in range [0..31], 0 if all x[i] == 0 */ + const Word32 *x, /* i: array containing 32-bit data */ + const Word32 len_x ) /* i: length of the array to scan */ +{ + Word32 i; + Word16 i_min, i_max; + Word32 x_min, x_max; + + + x_max = 0; + move32(); + x_min = 0; + move32(); + FOR( i = 0; i < len_x; i++ ) + { + if ( x[i] >= 0 ) + x_max = L_max( x_max, x[i] ); + if ( x[i] < 0 ) + x_min = L_min( x_min, x[i] ); + } + + i_max = 0x20; + move16(); + i_min = 0x20; + move16(); + + if ( x_max != 0 ) + i_max = norm_l( x_max ); + + if ( x_min != 0 ) + i_min = norm_l( x_min ); + + i_max = s_and( s_min( i_max, i_min ), 0x1F ); + + + return i_max; +} + Word16 normalize16( Word16 mantissa, Word16 *pexponent ) { Word16 tmp; diff --git a/lib_com/basop_util.h b/lib_com/basop_util.h index 3549f7d5c..92994542e 100644 --- a/lib_com/basop_util.h +++ b/lib_com/basop_util.h @@ -235,6 +235,9 @@ Word16 getScaleFactor32( const Word32 *x, /* i : array containing 32-bit data */ const Word16 len_x ); /* i : length of the array to scan */ +Word16 getScaleFactor32_copy( /* o: measured headroom in range [0..31], 0 if all x[i] == 0 */ + const Word32 *x, /* i: array containing 32-bit data */ + const Word32 len_x ); /* i: length of the array to scan */ /** * \brief normalize mantissa and update the exponent accordingly. diff --git a/lib_dec/jbm_pcmdsp_apa.c b/lib_dec/jbm_pcmdsp_apa.c index 942a5a906..9b94503da 100644 --- a/lib_dec/jbm_pcmdsp_apa.c +++ b/lib_dec/jbm_pcmdsp_apa.c @@ -892,7 +892,7 @@ UWord8 apa_exec_ivas_fx( UWord32 statsResetThreshold, statsResetShift; Word16 Q_a_out; - Q_a_out = add( getScaleFactor32( a_in, i_mult( ps->num_channels, APA_BUF_PER_CHANNEL ) ), Q11 - Q16 ); + Q_a_out = add( getScaleFactor32_copy( a_in, L_mult0( ps->num_channels, APA_BUF_PER_CHANNEL ) ), Q11 - Q16 ); statsResetThreshold = 1637; move32(); statsResetShift = 2; -- GitLab From ed78c6b67a364a0b48504283734a3744088542a6 Mon Sep 17 00:00:00 2001 From: Erik Norvell Date: Tue, 5 Nov 2024 14:54:47 +0100 Subject: [PATCH 083/128] Add *update-scripts-repo to coverage job --- .gitlab-ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 6fe04ea76..7f2eec09e 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1023,6 +1023,7 @@ coverage-test-on-main-scheduled: - *print-common-info - *update-ltv-repo - *copy-ltv-files-to-testv-dir + - *update-scripts-repo - *build-reference-binaries # Build DuT binaries with GCOV - make clean -- GitLab From b88a643ae5a025a4f39d0b48aba3d321c92d6c71 Mon Sep 17 00:00:00 2001 From: Erik Norvell Date: Tue, 5 Nov 2024 15:14:40 +0100 Subject: [PATCH 084/128] Fix order of update-scripts-repo in coverage job --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 7f2eec09e..418e5a8c5 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1021,9 +1021,9 @@ coverage-test-on-main-scheduled: timeout: 3 hours script: - *print-common-info + - *update-scripts-repo - *update-ltv-repo - *copy-ltv-files-to-testv-dir - - *update-scripts-repo - *build-reference-binaries # Build DuT binaries with GCOV - make clean -- GitLab From 42dffbbf291fe054663a69c8c52adf51b80962ab Mon Sep 17 00:00:00 2001 From: Erik Norvell Date: Tue, 5 Nov 2024 15:41:13 +0100 Subject: [PATCH 085/128] Fix timeout --- .gitlab-ci.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 418e5a8c5..07a888bf2 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1029,7 +1029,9 @@ coverage-test-on-main-scheduled: - make clean - make GCOV=1 -j + - testcase_timeout=$TESTCASE_TIMEOUT_LTV - exit_code_dec=0 + - exit_code_enc=0 - python3 -m pytest --tb=no $LONG_TEST_SUITE --update_ref 1 -v --create_ref --html=report-dec.html --self-contained-html --junit-xml=report-junit-dec.xml -n auto --testcase_timeout $testcase_timeout --ref_encoder_path $REF_ENCODER_PATH --ref_decoder_path $DUT_DECODER_PATH || exit_code_dec=$? - lcov -c -d obj -o coverage_dec_rend.info # extract coverage of decoder/renderer -- GitLab From cd14d0c5dabe53d0e64dac840b60faf79eb6d185 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Tue, 5 Nov 2024 20:32:06 +0530 Subject: [PATCH 086/128] Float structure elements cleanup in encoder, Q-info updates for lib_com --- lib_com/bits_alloc.c | 13 +- lib_com/cng_exc.c | 3 +- lib_com/edct_fx.c | 302 +++++++++++----------- lib_com/fd_cng_com.c | 4 + lib_com/igf_base.c | 4 + lib_com/ivas_ism_com.c | 12 +- lib_com/ivas_prot.h | 6 +- lib_com/ivas_prot_fx.h | 8 + lib_com/ivas_stat_com.h | 71 +++--- lib_com/ivas_stereo_mdct_bands_com.c | 78 +++--- lib_com/ivas_stereo_mdct_stereo_com.c | 16 +- lib_com/ivas_stereo_psychlpc_com.c | 28 +- lib_com/ivas_stereo_td_bit_alloc.c | 282 ++++++++++---------- lib_com/prot.h | 4 + lib_com/prot_fx.h | 216 ++++++++-------- lib_com/pvq_com_fx.c | 353 +++++++++++++------------- lib_com/range_com_fx.c | 30 +-- lib_com/re8_ppv_fx.c | 52 ++-- lib_com/re8_util_fx.c | 128 +++++----- lib_com/recovernorm_fx.c | 24 +- lib_com/rom_com.c | 26 +- lib_com/stat_com.h | 36 ++- lib_com/window_fx.c | 4 +- lib_com/window_ola_fx.c | 117 +++++---- lib_com/wtda.c | 26 +- lib_com/wtda_fx.c | 42 +-- lib_enc/acelp_core_enc.c | 63 +++-- lib_enc/core_enc_reconf.c | 9 + lib_enc/igf_enc.c | 4 + lib_enc/ivas_agc_enc.c | 8 +- lib_enc/ivas_cpe_enc.c | 13 +- lib_enc/ivas_enc.c | 6 - lib_enc/ivas_ism_dtx_enc.c | 9 +- lib_enc/ivas_ism_enc.c | 16 -- lib_enc/ivas_masa_enc.c | 2 +- lib_enc/ivas_pca_enc.c | 53 ++-- lib_enc/ivas_spar_encoder.c | 13 +- lib_enc/ivas_spar_md_enc.c | 2 +- lib_enc/ivas_stat_enc.h | 104 ++++---- lib_enc/ivas_stereo_cng_enc.c | 42 ++- lib_enc/ivas_stereo_dft_enc.c | 4 +- lib_enc/ivas_stereo_mdct_core_enc.c | 1 - lib_enc/ivas_stereo_switching_enc.c | 2 +- lib_enc/ivas_tcx_core_enc.c | 2 +- lib_enc/lib_enc.c | 8 +- lib_enc/updt_enc.c | 2 +- 46 files changed, 1175 insertions(+), 1073 deletions(-) diff --git a/lib_com/bits_alloc.c b/lib_com/bits_alloc.c index 67840f93e..c99851d58 100644 --- a/lib_com/bits_alloc.c +++ b/lib_com/bits_alloc.c @@ -42,15 +42,14 @@ #include "ivas_rom_com.h" #include "wmc_auto.h" +#ifndef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* * Local function prototypes *--------------------------------------------------------------------*/ static int16_t BITS_ALLOC_adjust_acelp_fixed_cdk( const int16_t bits_frame, int16_t *fixed_cdk_index, const int16_t nb_subfr ); -#ifndef IVAS_FLOAT_FIXED static int16_t allocate_unused( const int32_t core_brate, const int16_t coder_type, const int16_t unused_bits, const int16_t nb_prm, const int16_t subfr, const int16_t prm_type, int16_t *prm_bit_mode ); -#endif typedef enum { @@ -358,7 +357,6 @@ static int16_t BITS_ALLOC_adjust_acelp_fixed_cdk( * Selection of fixed innovation codebook bitbudget table *--------------------------------------------------------------------*/ -#ifndef IVAS_FLOAT_FIXED static int16_t fcb_table( const int16_t n, const int16_t L_subfr ) @@ -373,7 +371,6 @@ static int16_t fcb_table( return ( out ); } -#endif /*-------------------------------------------------------------------* * acelp_FCB_allocator() @@ -381,7 +378,6 @@ static int16_t fcb_table( * Routine to allocate fixed innovation codebook bit-budget *--------------------------------------------------------------------*/ -#ifndef IVAS_FLOAT_FIXED static ivas_error acelp_FCB_allocator( int16_t *nBits, /* i/o: available bit-budget */ int16_t fixed_cdk_index[], /* o : codebook index */ @@ -512,7 +508,6 @@ static ivas_error acelp_FCB_allocator( return error; } -#endif /*-------------------------------------------------------------------* @@ -523,7 +518,6 @@ static ivas_error acelp_FCB_allocator( * - per channel bitrate minimum is 13250 kbps for ACELP@16kHz *--------------------------------------------------------------------*/ -#ifndef IVAS_FLOAT_FIXED ivas_error config_acelp1_IVAS( const int16_t enc_dec, /* i : encoder/decoder flag */ const int32_t total_brate, /* i : total bitrate */ @@ -1341,7 +1335,6 @@ ivas_error config_acelp1_IVAS( return error; } -#endif /*-------------------------------------------------------------------* * allocate_unused() @@ -1349,7 +1342,6 @@ ivas_error config_acelp1_IVAS( * Allocate unused bits *--------------------------------------------------------------------*/ -#ifndef IVAS_FLOAT_FIXED static int16_t allocate_unused( const int32_t core_brate, const int16_t coder_type, @@ -1426,7 +1418,6 @@ static int16_t allocate_unused( return bit_added + max_bit_per_pos; } -#endif /*-------------------------------------------------------------------* @@ -1436,8 +1427,6 @@ static int16_t allocate_unused( *--------------------------------------------------------------------*/ /*! r: ACELP16k flag */ - -#ifndef IVAS_FLOAT_FIXED int16_t set_ACELP_flag_IVAS( const int16_t element_mode, /* i : element mode */ const int32_t element_brate, /* i : element bitrate */ diff --git a/lib_com/cng_exc.c b/lib_com/cng_exc.c index d1e24e065..716750db8 100644 --- a/lib_com/cng_exc.c +++ b/lib_com/cng_exc.c @@ -478,7 +478,7 @@ void cng_params_postupd( * * update CNG parameters *-------------------------------------------------------*/ - +#ifndef IVAS_FLOAT_FIXED void cng_params_upd( const float lsp_new[], /* i : LSP parameters */ const float exc2[], /* i : current enhanced excitation */ @@ -581,6 +581,7 @@ void cng_params_upd( return; } +#endif /*---------------------------------------------------------------------* diff --git a/lib_com/edct_fx.c b/lib_com/edct_fx.c index c3506838f..468275962 100644 --- a/lib_com/edct_fx.c +++ b/lib_com/edct_fx.c @@ -22,141 +22,141 @@ static Word16 get_edxt_factor( Word16 length ) /* Returns value of sqrtf(2.f/len move16(); IF( EQ_16( length, 512 ) ) { - factor = 2048; + factor = 2048; /*0.0625 in Q15*/ move16(); } ELSE IF( EQ_16( length, 256 ) ) { - factor = 2896; + factor = 2896; /*0.0883 in Q15*/ move16(); } ELSE IF( EQ_16( length, 128 ) ) { - factor = 4096; + factor = 4096; /*0.125 in Q15*/ move16(); } ELSE IF( EQ_16( length, 640 ) ) { - factor = 1832; + factor = 1832; /*0.0559 in Q15*/ move16(); } ELSE IF( EQ_16( length, 320 ) ) { - factor = 2590; + factor = 2590; /*0.079 in Q15*/ move16(); } ELSE IF( EQ_16( length, 160 ) ) { - factor = 3663; + factor = 3663; /*0.1117 in Q15*/ move16(); } ELSE IF( EQ_16( length, 80 ) ) { - factor = 5181; + factor = 5181; /*0.1581 in Q15*/ move16(); } ELSE IF( EQ_16( length, 40 ) ) { - factor = 7327; + factor = 7327; /*0.223 in Q15*/ move16(); } ELSE IF( EQ_16( length, 960 ) ) { - factor = 1496; + factor = 1496; /*0.0456 in Q15*/ move16(); } ELSE IF( EQ_16( length, 480 ) ) { - factor = 2115; + factor = 2115; /*0.0645 in Q15*/ move16(); } ELSE IF( EQ_16( length, 240 ) ) { - factor = 2991; + factor = 2991; /*0.0912 in Q15*/ move16(); } ELSE IF( EQ_16( length, 120 ) ) { - factor = 4230; + factor = 4230; /*0.1290 in Q15*/ move16(); } ELSE IF( EQ_16( length, 1200 ) ) { - factor = 1338; + factor = 1338; /*0.040 in Q15*/ move16(); } ELSE IF( EQ_16( length, 800 ) ) { - factor = 1638; + factor = 1638; /*0.05 in Q15*/ move16(); } ELSE IF( EQ_16( length, 400 ) ) { - factor = 2317; + factor = 2317; /*0.070 in Q15*/ move16(); } ELSE IF( EQ_16( length, 200 ) ) { - factor = 3277; + factor = 3277; /*0.1 in Q15*/ move16(); } - return factor; + return factor; /*Q15*/ } -static Word16 const *get_edct_table( Word16 length, Word16 *q ) +static Word16 const *get_edct_table( Word16 length /*Q0*/, Word16 *q ) { Word16 const *edct_table; edct_table = NULL; SWITCH( length ) { case 1200: - edct_table = edct_table_600_fx; + edct_table = edct_table_600_fx; /*Q17*/ *q = add( *q, 2 ); move16(); BREAK; case 960: - edct_table = edct_table_480_fx; + edct_table = edct_table_480_fx; /*Q16*/ BREAK; case 640: - edct_table = edct_table_320_fx; + edct_table = edct_table_320_fx; /*Q16*/ BREAK; case 320: - edct_table = edct_table_160_fx; + edct_table = edct_table_160_fx; /*Q16*/ BREAK; case 256: - edct_table = edct_table_128_fx; + edct_table = edct_table_128_fx; /*Q16*/ BREAK; case 240: - edct_table = edct_table_120_fx; + edct_table = edct_table_120_fx; /*Q16*/ BREAK; case 200: - edct_table = edct_table_100_fx; + edct_table = edct_table_100_fx; /*Q16*/ BREAK; case 160: - edct_table = edct_table_80_fx; + edct_table = edct_table_80_fx; /*Q16*/ BREAK; case 40: - edct_table = edct_table_20_fx; + edct_table = edct_table_20_fx; /*Q16*/ BREAK; case 800: - edct_table = edct_table_400_fx; + edct_table = edct_table_400_fx; /*Q17*/ *q = add( *q, 2 ); move16(); BREAK; case 512: - edct_table = edct_table_256_fx; + edct_table = edct_table_256_fx; /*Q16*/ BREAK; case 480: - edct_table = edct_table_240_fx; + edct_table = edct_table_240_fx; /*Q16*/ BREAK; case 400: - edct_table = edct_table_200_fx; + edct_table = edct_table_200_fx; /*Q16*/ BREAK; case 128: - edct_table = edct_table_64_fx; + edct_table = edct_table_64_fx; /*Q16*/ BREAK; case 80: - edct_table = edct_table_40_fx; + edct_table = edct_table_40_fx; /*Q16*/ BREAK; default: BREAK; @@ -180,7 +180,7 @@ static Word16 const *get_edct_table( Word16 length, Word16 *q ) void edct_fx( const Word32 *x, /* i : input signal Qq */ Word32 *y, /* o : output transform Qq */ - Word16 length, /* i : length */ + Word16 length, /* i : length Q0*/ Word16 *q /* i : Q value of input signal */ ) { @@ -193,18 +193,18 @@ void edct_fx( Word16 tmp; Word16 len1; - edct_table = get_edct_table( length, q ); - len1 = shr( length, 1 ); + edct_table = get_edct_table( length, q ); /*q*/ + len1 = shr( length, 1 ); /*Q0*/ /* Twiddling and Pre-rotate */ FOR( i = 0; i < len1; i++ ) { - L_tmp = Mult_32_16( x[2 * i], edct_table[i] ); /*Q(q+1) */ - complex_buf[2 * i] = Madd_32_16( L_tmp, x[sub( length, add( 1, shl( i, 1 ) ) )], edct_table[sub( len1, add( 1, i ) )] ); /*Q(q+1) */ + L_tmp = Mult_32_16( x[2 * i], edct_table[i] ); /*Q(q+1) */ + complex_buf[2 * i] = Madd_32_16( L_tmp, x[( length - ( 1 + ( i * 2 ) ) )], edct_table[( len1 - ( 1 + i ) )] ); /*Q(q+1) */ move32(); - L_tmp = Mult_32_16( x[sub( length, add( 1, shl( i, 1 ) ) )], edct_table[i] ); /*Q(q+1) */ + L_tmp = Mult_32_16( x[( length - ( 1 + ( i * 2 ) ) )], edct_table[i] ); /*Q(q+1) */ - complex_buf[add( shl( i, 1 ), 1 )] = Msub_32_16( L_tmp, x[shl( i, 1 )], edct_table[sub( len1, add( 1, i ) )] ); /*Q(q+1) */ + complex_buf[( ( i * 2 ) + 1 )] = Msub_32_16( L_tmp, x[( i * 2 )], edct_table[( len1 - ( 1 + i ) )] ); /*Q(q+1) */ move32(); } @@ -212,15 +212,15 @@ void edct_fx( move16(); BASOP_cfft( (cmplx *) complex_buf, len1, q, y ); - tmp = div_s( 1, length ); /*Q15 */ - tmp = round_fx( L_shl( L_mult( tmp, 19302 ), 2 ) ); /*Q15 */ + tmp = div_s( 1, length ); /*Q15 */ + tmp = round_fx( L_shl( L_mult( tmp, 19302 /*0.75f * EVS_PI in Q13*/ ), 2 ) ); /*Q15 */ FOR( i = 0; i < len1; i++ ) { - re = Msub_32_16( complex_buf[2 * i], complex_buf[add( shl( i, 1 ), 1 )], tmp ); - im = Madd_32_16( complex_buf[add( shl( i, 1 ), 1 )], complex_buf[2 * i], tmp ); - y[2 * i] = L_add( Mult_32_16( re, edct_table[i] ), Mult_32_16( im, edct_table[sub( len1, add( 1, i ) )] ) ); + re = Msub_32_16( complex_buf[2 * i], complex_buf[( ( i * 2 ) + 1 )], tmp ); /*Q(q+1) */ + im = Madd_32_16( complex_buf[( ( i * 2 ) + 1 )], complex_buf[2 * i], tmp ); /*Q(q+1) */ + y[2 * i] = L_add( Mult_32_16( re, edct_table[i] ), Mult_32_16( im, edct_table[( len1 - ( 1 + i ) )] ) ); /*Q(q+2)*/ move32(); - y[sub( length, add( 1, shl( i, 1 ) ) )] = L_sub( Mult_32_16( re, edct_table[sub( len1, add( 1, i ) )] ), Mult_32_16( im, edct_table[i] ) ); + y[( length - ( 1 + ( i * 2 ) ) )] = L_sub( Mult_32_16( re, edct_table[( len1 - ( 1 + i ) )] ), Mult_32_16( im, edct_table[i] ) ); /*Q(q+2)*/ move32(); } /*Q(q-2) */ @@ -258,17 +258,17 @@ void edst_fx( Word16 tmp; Word16 len1; - edct_table = get_edct_table( length, q ); - len1 = shr( length, 1 ); + edct_table = get_edct_table( length, q ); /*q*/ + len1 = shr( length, 1 ); /*Q0*/ /* Twiddling and Pre-rotate */ FOR( i = 0; i < len1; i++ ) { - L_tmp = Mult_32_16( x[sub( length, add( 1, shl( i, 1 ) ) )], edct_table[i] ); - complex_buf[2 * i] = Madd_32_16( L_tmp, x[2 * i], edct_table[sub( len1, add( 1, i ) )] ); + L_tmp = Mult_32_16( x[( length - ( 1 + ( i * 2 ) ) )], edct_table[i] ); /*Qq+1*/ + complex_buf[2 * i] = Madd_32_16( L_tmp, x[2 * i], edct_table[( len1 - ( 1 + i ) )] ); /*Qq+1*/ move32(); - L_tmp = Mult_32_16( x[2 * i], edct_table[i] ); - complex_buf[add( shl( i, 1 ), 1 )] = Msub_32_16( L_tmp, x[sub( length, add( 1, shl( i, 1 ) ) )], edct_table[sub( len1, add( 1, i ) )] ); + L_tmp = Mult_32_16( x[2 * i], edct_table[i] ); /*Qq+1*/ + complex_buf[( ( i * 2 ) + 1 )] = Msub_32_16( L_tmp, x[( length - ( 1 + ( i * 2 ) ) )], edct_table[( len1 - ( 1 + i ) )] ); /*Qq+1*/ move32(); } @@ -276,15 +276,15 @@ void edst_fx( move16(); BASOP_cfft( (cmplx *) complex_buf, len1, q, y ); - tmp = div_s( 1, length ); /*Q15 */ - tmp = round_fx( L_shl( L_mult( tmp, 19302 ), 2 ) ); /*Q15 */ + tmp = div_s( 1, length ); /*Q15 */ + tmp = round_fx( L_shl( L_mult( tmp, 19302 /*0.75f * EVS_PI in Q13*/ ), 2 ) ); /*Q15 */ FOR( i = 0; i < len1; i++ ) { - re = Msub_32_16( complex_buf[2 * i], complex_buf[add( shl( i, 1 ), 1 )], tmp ); - im = Madd_32_16( complex_buf[add( shl( i, 1 ), 1 )], complex_buf[2 * i], tmp ); - y[2 * i] = L_add( Mult_32_16( re, edct_table[i] ), Mult_32_16( im, edct_table[sub( len1, add( 1, i ) )] ) ); + re = Msub_32_16( complex_buf[2 * i], complex_buf[( ( i * 2 ) + 1 )], tmp ); /*Qq+1*/ + im = Madd_32_16( complex_buf[( ( i * 2 ) + 1 )], complex_buf[2 * i], tmp ); /*Qq+1*/ + y[2 * i] = L_add( Mult_32_16( re, edct_table[i] ), Mult_32_16( im, edct_table[( len1 - ( 1 + i ) )] ) ); /*Qq+2*/ move32(); - y[sub( length, add( 1, shl( i, 1 ) ) )] = L_sub( Mult_32_16( im, edct_table[i] ), Mult_32_16( re, edct_table[sub( len1, add( 1, i ) )] ) ); + y[( length - ( 1 + ( i * 2 ) ) )] = L_sub( Mult_32_16( im, edct_table[i] ), Mult_32_16( re, edct_table[( len1 - ( 1 + i ) )] ) ); /*Qq+2*/ move32(); } /*Q(q) */ @@ -347,15 +347,15 @@ void edct_16fx( IF( EQ_16( length, L_FRAME32k ) ) { - edct_table = &edct_table_320_16fx[0]; + edct_table = &edct_table_320_16fx[0]; /*Q15*/ } ELSE IF( EQ_16( length, L_FRAME ) ) { - edct_table = &edct_table_128_16fx[0]; + edct_table = &edct_table_128_16fx[0]; /*Q15*/ } ELSE IF( EQ_16( length, L_FRAME16k ) ) { - edct_table = &edct_table_160_16fx[0]; + edct_table = &edct_table_160_16fx[0]; /*Q15*/ } ELSE { @@ -364,8 +364,8 @@ void edct_16fx( /* Twiddling and Pre-rotate */ Lmax = L_deposit_l( 0 ); Len2 = shr( length, 1 ); - px = x + sub( length, 1 ); - pt = edct_table + sub( Len2, 1 ); + px = x + sub( length, 1 ); /*Qx*/ + pt = edct_table + sub( Len2, 1 ); /*Q16*/ FOR( i = 0; i < Len2; i++ ) { i2 = shl( i, 1 ); @@ -391,8 +391,8 @@ void edct_16fx( } Q_edct = sub( tmp, bh ); /*creating a bit-headroom */ - px = x + sub( length, 1 ); - pt = edct_table + sub( Len2, 1 ); + px = x + sub( length, 1 ); /*Qx*/ + pt = edct_table + sub( Len2, 1 ); /*Q15*/ FOR( i = 0; i < Len2; i++ ) { i2 = shl( i, 1 ); @@ -458,8 +458,8 @@ void edct_16fx( } /* Post-rotate and obtain the output data */ - py = y + sub( length, 1 ); - pt = edct_table + sub( Len2, 1 ); + py = y + sub( length, 1 ); /*Qx*/ + pt = edct_table + sub( Len2, 1 ); /*Q15*/ FOR( i = 0; i < Len2; i++ ) { i2 = shl( i, 1 ); @@ -497,10 +497,10 @@ void edct_16fx( *-----------------------------------------------------------------*/ void iedct_short_fx( - const Word32 *in, /* i : input vector */ + const Word32 *in, /* i : input vector Q*/ Word16 *Q, /* i/o: Q value of input */ - Word32 *out, /* o : output vector */ - const Word16 segment_length /* i : length */ + Word32 *out, /* o : output vector Q*/ + const Word16 segment_length /* i : length Q0*/ ) { Word32 alias[MAX_SEGMENT_LENGTH]; @@ -512,8 +512,8 @@ void iedct_short_fx( move16(); tmp = 0; move16(); - seg_len_div2 = shr( segment_length, 1 ); - seg_len_div4 = shr( segment_length, 2 ); + seg_len_div2 = shr( segment_length, 1 ); /*Q0*/ + seg_len_div4 = shr( segment_length, 2 ); /*Q0*/ seg_len_3mul_div4 = add( seg_len_div2, seg_len_div4 ); edct_fx( in, alias, seg_len_div2, Q ); @@ -533,13 +533,13 @@ void iedct_short_fx( } FOR( i = 0; i < seg_len_div4; i++ ) { - out[i] = alias[add( seg_len_div4, i )]; + out[i] = alias[( seg_len_div4 + i )]; /*Q*/ move32(); - out[add( seg_len_div4, i )] = L_negate( alias[sub( sub( seg_len_div2, 1 ), i )] ); + out[( seg_len_div4 + i )] = L_negate( alias[( ( seg_len_div2 - 1 ) - i )] ); /*Q*/ move32(); - out[add( seg_len_div2, i )] = L_negate( alias[sub( sub( seg_len_div4, 1 ), i )] ); + out[( seg_len_div2 + i )] = L_negate( alias[( ( seg_len_div4 - 1 ) - i )] ); /*Q*/ move32(); - out[add( seg_len_3mul_div4, i )] = L_negate( alias[i] ); + out[( seg_len_3mul_div4 + i )] = L_negate( alias[i] ); /*Q*/ move32(); } @@ -554,11 +554,11 @@ void iedct_short_fx( *-------------------------------------------------------------------------*/ void edxt_fx( - const Word32 *x, /* i : input signal */ - Word32 *y, /* o : output transform */ - const Word16 length, /* i : length */ - const UWord16 kernelType, /* i : kernel type (0 - 3) */ - const UWord16 synthesis /* i : nonzero for inverse */ + const Word32 *x, /* i : input signal Qx*/ + Word32 *y, /* o : output transform Qx*/ + const Word16 length, /* i : length Q0*/ + const UWord16 kernelType, /* i : kernel type (0 - 3) Q0*/ + const UWord16 synthesis /* i : nonzero for inverse Q0*/ ) { Word16 k, m, fac; @@ -570,113 +570,113 @@ void edxt_fx( sinPtr = NULL; IF( EQ_16( length, 512 ) ) { - cosPtr = cos_scale_tbl_512; - sinPtr = sin_scale_tbl_512; + cosPtr = cos_scale_tbl_512; /*Q15*/ + sinPtr = sin_scale_tbl_512; /*Q15*/ n = 1; move16(); } ELSE IF( EQ_16( length, 256 ) ) { - cosPtr = cos_scale_tbl_512; - sinPtr = sin_scale_tbl_512; + cosPtr = cos_scale_tbl_512; /*Q15*/ + sinPtr = sin_scale_tbl_512; /*Q15*/ n = 2; move16(); } ELSE IF( EQ_16( length, 128 ) ) { - cosPtr = cos_scale_tbl_512; - sinPtr = sin_scale_tbl_512; + cosPtr = cos_scale_tbl_512; /*Q15*/ + sinPtr = sin_scale_tbl_512; /*Q15*/ n = 4; move16(); } ELSE IF( EQ_16( length, 640 ) ) { - cosPtr = cos_scale_tbl_640; - sinPtr = sin_scale_tbl_640; + cosPtr = cos_scale_tbl_640; /*Q15*/ + sinPtr = sin_scale_tbl_640; /*Q15*/ n = 1; move16(); } ELSE IF( EQ_16( length, 320 ) ) { - cosPtr = cos_scale_tbl_640; - sinPtr = sin_scale_tbl_640; + cosPtr = cos_scale_tbl_640; /*Q15*/ + sinPtr = sin_scale_tbl_640; /*Q15*/ n = 2; move16(); } ELSE IF( EQ_16( length, 160 ) ) { - cosPtr = cos_scale_tbl_640; - sinPtr = sin_scale_tbl_640; + cosPtr = cos_scale_tbl_640; /*Q15*/ + sinPtr = sin_scale_tbl_640; /*Q15*/ n = 4; move16(); } ELSE IF( EQ_16( length, 80 ) ) { - cosPtr = cos_scale_tbl_640; - sinPtr = sin_scale_tbl_640; + cosPtr = cos_scale_tbl_640; /*Q15*/ + sinPtr = sin_scale_tbl_640; /*Q15*/ n = 8; move16(); } ELSE IF( EQ_16( length, 40 ) ) { - cosPtr = cos_scale_tbl_640; - sinPtr = sin_scale_tbl_640; + cosPtr = cos_scale_tbl_640; /*Q15*/ + sinPtr = sin_scale_tbl_640; /*Q15*/ n = 16; move16(); } ELSE IF( EQ_16( length, 960 ) ) { - cosPtr = cos_scale_tbl_960; - sinPtr = sin_scale_tbl_960; + cosPtr = cos_scale_tbl_960; /*Q15*/ + sinPtr = sin_scale_tbl_960; /*Q15*/ n = 1; move16(); } ELSE IF( EQ_16( length, 480 ) ) { - cosPtr = cos_scale_tbl_960; - sinPtr = sin_scale_tbl_960; + cosPtr = cos_scale_tbl_960; /*Q15*/ + sinPtr = sin_scale_tbl_960; /*Q15*/ n = 2; move16(); } ELSE IF( EQ_16( length, 240 ) ) { - cosPtr = cos_scale_tbl_960; - sinPtr = sin_scale_tbl_960; + cosPtr = cos_scale_tbl_960; /*Q15*/ + sinPtr = sin_scale_tbl_960; /*Q15*/ n = 4; move16(); } ELSE IF( EQ_16( length, 120 ) ) { - cosPtr = cos_scale_tbl_960; - sinPtr = sin_scale_tbl_960; + cosPtr = cos_scale_tbl_960; /*Q15*/ + sinPtr = sin_scale_tbl_960; /*Q15*/ n = 8; move16(); } ELSE IF( EQ_16( length, 1200 ) ) { - cosPtr = cos_scale_tbl_1200; - sinPtr = sin_scale_tbl_1200; + cosPtr = cos_scale_tbl_1200; /*Q15*/ + sinPtr = sin_scale_tbl_1200; /*Q15*/ n = 1; move16(); } ELSE IF( EQ_16( length, 800 ) ) { - cosPtr = cos_scale_tbl_800; - sinPtr = sin_scale_tbl_800; + cosPtr = cos_scale_tbl_800; /*Q15*/ + sinPtr = sin_scale_tbl_800; /*Q15*/ n = 1; move16(); } ELSE IF( EQ_16( length, 400 ) ) { - cosPtr = cos_scale_tbl_800; - sinPtr = sin_scale_tbl_800; + cosPtr = cos_scale_tbl_800; /*Q15*/ + sinPtr = sin_scale_tbl_800; /*Q15*/ n = 2; move16(); } ELSE IF( EQ_16( length, 200 ) ) { - cosPtr = cos_scale_tbl_800; - sinPtr = sin_scale_tbl_800; + cosPtr = cos_scale_tbl_800; /*Q15*/ + sinPtr = sin_scale_tbl_800; /*Q15*/ n = 4; move16(); } @@ -686,17 +686,17 @@ void edxt_fx( IF( EQ_16( kernelType, MDST_II ) || EQ_16( kernelType, MDCT_II ) ) { const Word16 Nm1 = sub( length, 1 ); - const Word16 xSign = sub( imult1616( 2, shr( kernelType, 1 ) ), 1 ); + const Word16 xSign = sub( imult1616( 2, shr( kernelType, 1 ) ), 1 ); /*Q0*/ Word32 re[L_FRAME_PLUS]; Word32 im[L_FRAME_PLUS]; IF( !synthesis ) { - FOR( k = shr( Nm1, 1 ); k >= 0; k-- ) /* pre-modulation of audio input */ + FOR( k = ( Nm1 / 2 ); k >= 0; k-- ) /* pre-modulation of audio input */ { - re[k] = x[2 * k]; - re[sub( Nm1, k )] = Mpy_32_16_1( x[add( shl( k, 1 ), 1 )], shl_sat( xSign, 15 ) ); - im[k] = im[sub( Nm1, k )] = 0; + re[k] = x[2 * k]; /*Qx*/ + re[( Nm1 - k )] = Mpy_32_16_1( x[( ( k * 2 ) + 1 )], shl_sat( xSign, 15 ) ); /*Qx*/ + im[k] = im[( Nm1 - k )] = 0; move32(); move32(); move32(); @@ -713,87 +713,87 @@ void edxt_fx( IF( shr( kernelType, 1 ) ) { - FOR( k = shr( Nm1, 1 ); k > 0; k-- ) + FOR( k = ( Nm1 / 2 ); k > 0; k-- ) { // const float wRe = cosf( scale * k ); // const float wIm = sinf( scale * k ); - const Word16 wRe = cosPtr[imult1616( k, n )]; - const Word16 wIm = sinPtr[imult1616( k, n )]; + const Word16 wRe = cosPtr[( k * n )]; /*Q15*/ + const Word16 wIm = sinPtr[( k * n )]; /*Q15*/ - y[k] /*pt 1*/ = L_add( Mpy_32_16_1( re[k], wRe ), Mpy_32_16_1( im[k], wIm ) ); - y[sub( length, k )] = L_sub( Mpy_32_16_1( re[k], wIm ), Mpy_32_16_1( im[k], wRe ) ); + y[k] /*pt 1*/ = L_add( Mpy_32_16_1( re[k], wRe ), Mpy_32_16_1( im[k], wIm ) ); /*Qx*/ + y[( length - k )] = L_sub( Mpy_32_16_1( re[k], wIm ), Mpy_32_16_1( im[k], wRe ) ); /*Qx*/ move32(); move32(); } - y[shr( length, 1 )] = Mpy_32_16_1( re[shr( length, 1 )], INV_SQRT_2_Q15 ); + y[( length / 2 )] = Mpy_32_16_1( re[( length / 2 )], INV_SQRT_2_Q15 ); /*Qx*/ move32(); } ELSE /* forw. DST-II */ { - FOR( k = shr( Nm1, 1 ); k > 0; k-- ) + FOR( k = ( Nm1 / 2 ); k > 0; k-- ) { // const float wRe = cosf( scale * k ); // const float wIm = sinf( scale * k ); - const Word16 wRe = cosPtr[imult1616( k, n )]; - const Word16 wIm = sinPtr[imult1616( k, n )]; + const Word16 wRe = cosPtr[( k * n )]; /*Q15*/ + const Word16 wIm = sinPtr[( k * n )]; /*Q15*/ - y[sub( Nm1, k )] = L_add( Mpy_32_16_1( re[k], wRe ), Mpy_32_16_1( im[k], wIm ) ); - y[k - 1] = L_sub( Mpy_32_16_1( re[k], wIm ), Mpy_32_16_1( im[k], wRe ) ); + y[( Nm1 - k )] = L_add( Mpy_32_16_1( re[k], wRe ), Mpy_32_16_1( im[k], wIm ) ); /*Qx*/ + y[k - 1] = L_sub( Mpy_32_16_1( re[k], wIm ), Mpy_32_16_1( im[k], wRe ) ); /*Qx*/ move32(); move32(); } - y[shr( Nm1, 1 )] = Mpy_32_16_1( re[shr( length, 1 )], INV_SQRT_2_Q15 ); + y[( Nm1 / 2 )] = Mpy_32_16_1( re[( length / 2 )], INV_SQRT_2_Q15 ); /*Qx*/ move32(); } - y[sub( Nm1, imult1616( Nm1, shr( kernelType, 1 ) ) )] = L_shr( re[0], 1 ); + y[( Nm1 - ( Nm1 * ( kernelType / 2 ) ) )] = L_shr( re[0], 1 ); /*Qx*/ move32(); } ELSE /* inverse II = III */ { IF( shr( kernelType, 1 ) ) { - FOR( k = shr( Nm1, 1 ); k > 0; k-- ) + FOR( k = ( Nm1 / 2 ); k > 0; k-- ) { // const float wRe = cosf( scale * k ) * 0.5f; // const float wIm = sinf( scale * k ) * 0.5f; const Word16 wRe = shr( cosPtr[imult1616( k, n )], 1 ); const Word16 wIm = shr( sinPtr[imult1616( k, n )], 1 ); - re[k] = L_add( Mpy_32_16_1( x[k], wRe ), Mpy_32_16_1( x[sub( length, k )], wIm ) ); - im[k] = L_sub( Mpy_32_16_1( x[sub( length, k )], wRe ), Mpy_32_16_1( x[k], wIm ) ); + re[k] = L_add( Mpy_32_16_1( x[k], wRe ), Mpy_32_16_1( x[( length - k )], wIm ) ); /*Qx*/ + im[k] = L_sub( Mpy_32_16_1( x[( length - k )], wRe ), Mpy_32_16_1( x[k], wIm ) ); /*Qx*/ move32(); move32(); } - re[shr( length, 1 )] = Mpy_32_16_1( x[shr( length, 1 )], INV_SQRT_2_Q15 ); + re[( length / 2 )] = Mpy_32_16_1( x[( length / 2 )], INV_SQRT_2_Q15 ); /*Qx*/ move32(); } ELSE /* DST type III */ { - FOR( k = shr( Nm1, 1 ); k > 0; k-- ) + FOR( k = ( Nm1 / 2 ); k > 0; k-- ) { // const float wRe = cosf( scale * k ) * 0.5f; // const float wIm = sinf( scale * k ) * 0.5f; - const Word16 wRe = shr( cosPtr[imult1616( k, n )], 1 ); - const Word16 wIm = shr( sinPtr[imult1616( k, n )], 1 ); + const Word16 wRe = shr( cosPtr[( k * n )], 1 ); /*Q15*/ + const Word16 wIm = shr( sinPtr[( k * n )], 1 ); /*Q15*/ - re[k] = L_add( Mpy_32_16_1( x[sub( Nm1, k )], wRe ), Mpy_32_16_1( x[sub( k, 1 )], wIm ) ); - im[k] = L_sub( Mpy_32_16_1( x[sub( k, 1 )], wRe ), Mpy_32_16_1( x[sub( Nm1, k )], wIm ) ); + re[k] = L_add( Mpy_32_16_1( x[( Nm1 - k )], wRe ), Mpy_32_16_1( x[( k - 1 )], wIm ) ); /*Qx*/ + im[k] = L_sub( Mpy_32_16_1( x[( k - 1 )], wRe ), Mpy_32_16_1( x[( Nm1 - k )], wIm ) ); /*Qx*/ move32(); move32(); } - re[shr( length, 1 )] = Mpy_32_16_1( x[shr( Nm1, 1 )], INV_SQRT_2_Q15 ); + re[( length / 2 )] = Mpy_32_16_1( x[( Nm1 / 2 )], INV_SQRT_2_Q15 ); /*Qx*/ move32(); } - re[0] = x[sub( Nm1, imult1616( Nm1, shr( kernelType, 1 ) ) )]; - im[0] = im[shr( length, 1 )] = 0; + re[0] = x[( Nm1 - ( Nm1 * ( kernelType / 2 ) ) )]; /*Qx*/ + im[0] = im[( length / 2 )] = 0; move32(); move32(); - FOR( k = shr( Nm1, 1 ); k > 0; k-- ) + FOR( k = ( Nm1 / 2 ); k > 0; k-- ) { - re[sub( length, k )] = re[k]; - im[sub( length, k )] = L_negate( im[k] ); + re[( length - k )] = re[k]; /*Qx*/ + im[( length - k )] = L_negate( im[k] ); /*Qx*/ move32(); move32(); } @@ -807,17 +807,17 @@ void edxt_fx( fft_fx( re, im, length, 1 ); } - FOR( k = shr( Nm1, 1 ); k >= 0; k-- ) /* post-modulation of FFT output */ + FOR( k = ( Nm1 / 2 ); k >= 0; k-- ) /* post-modulation of FFT output */ { - y[2 * k] = re[k]; + y[2 * k] = re[k]; /*Qx*/ move32(); IF( xSign != 0 ) { - y[add( shl( k, 1 ), 1 )] = Mpy_32_16_1( re[sub( Nm1, k )], shl_sat( xSign, 15 ) ); + y[( ( k * 2 ) + 1 )] = Mpy_32_16_1( re[( Nm1 - k )], shl_sat( xSign, 15 ) ); /*Qx*/ } ELSE { - y[add( shl( k, 1 ), 1 )] = 0; + y[( ( k * 2 ) + 1 )] = 0; /*Qx*/ } move32(); } @@ -873,7 +873,7 @@ void edxt_fx( FOR( m = 0; m < length; m++ ) { - y[m] = Mpy_32_16_1( y[m], fac ); + y[m] = Mpy_32_16_1( y[m], fac ); /*Qx*/ move32(); } return; diff --git a/lib_com/fd_cng_com.c b/lib_com/fd_cng_com.c index 350391c26..91750b486 100644 --- a/lib_com/fd_cng_com.c +++ b/lib_com/fd_cng_com.c @@ -117,7 +117,11 @@ void initFdCngCom_flt( hFdCngCom->active_frame_counter = 0; hFdCngCom->frame_type_previous = ACTIVE_FRAME; hFdCngCom->flag_noisy_speech = 0; +#ifndef IVAS_FLOAT_FIXED hFdCngCom->likelihood_noisy_speech_flt = 0.f; +#else + hFdCngCom->likelihood_noisy_speech = 0; +#endif hFdCngCom->numCoreBands = 0; hFdCngCom->stopBand = 0; hFdCngCom->startBand = 0; diff --git a/lib_com/igf_base.c b/lib_com/igf_base.c index adad4c47c..5aa8e8c3f 100644 --- a/lib_com/igf_base.c +++ b/lib_com/igf_base.c @@ -41,6 +41,7 @@ #include "rom_com.h" #include "wmc_auto.h" +#ifndef IVAS_FLOAT_FIXED /*---------------------------------------------------------------------* * IGF_ApplyTransFac_flt() * @@ -63,6 +64,7 @@ int16_t IGF_ApplyTransFac_flt( return ret; } +#endif /*---------------------------------------------------------------------* @@ -357,6 +359,7 @@ int16_t IGF_MapBitRateToIndex_flt( return bitRateIndex; } +#ifndef IVAS_FLOAT_FIXED /*---------------------------------------------------------------------* * IGF_gridSetUp_flt() * @@ -567,6 +570,7 @@ int16_t IGFCommonFuncsIGFConfiguration_flt( return retValue; } +#endif /*---------------------------------------------------------------------* diff --git a/lib_com/ivas_ism_com.c b/lib_com/ivas_ism_com.c index d871ebe6d..f170bada1 100644 --- a/lib_com/ivas_ism_com.c +++ b/lib_com/ivas_ism_com.c @@ -1070,6 +1070,7 @@ float ism_dequant_meta( * * ---------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED void ivas_param_ism_config( PARAM_ISM_CONFIG_HANDLE hParamIsm, /* i/o: IVAS Param ISM Config Structure */ const int16_t nchan_obj /* i : number of ISM channels */ @@ -1098,8 +1099,7 @@ void ivas_param_ism_config( return; } - -#ifdef IVAS_FLOAT_FIXED +#else void ivas_param_ism_config_fx( PARAM_ISM_CONFIG_HANDLE hParamIsm, /* i/o: IVAS Param ISM Config Structure */ const Word16 nchan_obj /* i : number of ISM channels */ @@ -1129,15 +1129,11 @@ void ivas_param_ism_config_fx( move16(); } - hParamIsm->last_dmx_gain_fx = (Word16) 16384; // Q15-last_dmx_gain_e + hParamIsm->last_dmx_gain_fx = (Word16) 16384; // 15-1 = Q14 move16(); hParamIsm->last_dmx_gain_e = 1; move16(); - set16_fx( hParamIsm->last_cardioid_left_fx, (Word16) 16384, MAX_NUM_OBJECTS ); -#if 1 // TODO: To be removed later - hParamIsm->last_dmx_gain = 1.0f; - set_f( hParamIsm->last_cardioid_left, 1.0f, MAX_NUM_OBJECTS ); -#endif + set16_fx( hParamIsm->last_cardioid_left_fx, (Word16) 16384, MAX_NUM_OBJECTS ); // Q14 return; } diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index 6dc3b8f55..d845d8778 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -1218,12 +1218,12 @@ void ivas_param_ism_stereo_dmx( float *data[MAX_NUM_OBJECTS], /* i/o: input signal/stereo dmx */ const int16_t input_frame /* i : Length of input frame */ ); -#endif void ivas_param_ism_config( PARAM_ISM_CONFIG_HANDLE hParamIsm, /* i/o: IVAS Param ISM Config Structure */ const int16_t nchan_ism /* i : number of ISM channels */ ); +#endif ivas_error ivas_ism_enc_config( Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ @@ -1343,23 +1343,27 @@ void ivas_ism_metadata_sid_dec( int16_t nb_bits_metadata[] /* o : number of metadata bits */ ); +#ifndef IVAS_FLOAT_FIXED void ivas_ism_get_sce_id_dtx( ISM_DTX_HANDLE hISMDTX, /* i/o: ISM DTX handle */ SCE_ENC_HANDLE hSCE[MAX_SCE], /* i/o: SCE encoder structure */ const int16_t nchan_transport, /* i : number of transport channels */ const int16_t input_frame /* i : input frame length per channel */ ); +#endif void ivas_param_ism_compute_noisy_speech_flag( Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ ); +#ifndef IVAS_FLOAT_FIXED void ivas_ism_coh_estim_dtx_enc( ISM_DTX_HANDLE hISMDTX, /* i/o: ISM DTX handle */ SCE_ENC_HANDLE hSCE[MAX_SCE], /* i/o: SCE encoder structure */ const int16_t nchan_transport, /* i : number of transport channels */ const int16_t input_frame /* i : input frame length */ ); +#endif void update_last_metadata( const int16_t nchan_ism, /* i : number of objects */ diff --git a/lib_com/ivas_prot_fx.h b/lib_com/ivas_prot_fx.h index 348fc2ebe..5d1a5137a 100644 --- a/lib_com/ivas_prot_fx.h +++ b/lib_com/ivas_prot_fx.h @@ -2872,6 +2872,10 @@ Word16 quantize_sns_fx( Word16 *zero_side_flag, /* Q0 */ Word16 *sns_stereo_mode ); /* Q0 */ +void stereo_enc_cng_init_fx( + STEREO_CNG_ENC_HANDLE hStereoCng /* i/o: stereo CNG encoder structure */ +); + void stereo_cng_upd_counters_fx( STEREO_CNG_ENC_HANDLE hStereoCng, /* i/o: Stereo CNG data structure */ const Word32 element_mode, /* i : element mode */ @@ -5447,6 +5451,10 @@ void ivas_cov_smooth_process_fx( const Word16 transient_det[2], Word16 *q_cov[IVAS_SPAR_MAX_CH] ); +void ivas_pca_enc_init_fx( + PCA_ENC_STATE *hPCA /* i/o: PCA encoder structure */ +); + void ivas_pca_enc_fx( const ENCODER_CONFIG_HANDLE hEncoderConfig, /* i : configuration structure */ PCA_ENC_STATE *hPCA, /* i : PCA encoder structure */ diff --git a/lib_com/ivas_stat_com.h b/lib_com/ivas_stat_com.h index d6dd690fb..d306ed04c 100644 --- a/lib_com/ivas_stat_com.h +++ b/lib_com/ivas_stat_com.h @@ -349,22 +349,23 @@ typedef struct ivas_huff_coeffs_t /* AGC structures */ typedef struct ivas_agc_chan_data_t { - int16_t absGainExp; - int16_t absGainExpCurr; + Word16 absGainExp; + Word16 absGainExpCurr; } ivas_agc_chan_data_t; typedef struct ivas_agc_com_state_t { +#ifndef IVAS_FLOAT_FIXED float *winFunc; -#ifdef IVAS_FLOAT_FIXED - Word16 *winFunc_fx; -#endif // IVAS_FLOAT_FIXED - int16_t in_delay; /* TODO: JBM check if this needs to be adjusted in the dec */ - uint16_t absEmin; - uint16_t betaE; - uint16_t maxAttExp; - uint16_t num_coeff; +#else + Word16 *winFunc_fx; /* Q15 */ +#endif + Word16 in_delay; /* TODO: JBM check if this needs to be adjusted in the dec */ + UWord16 absEmin; + UWord16 betaE; + UWord16 maxAttExp; + UWord16 num_coeff; } ivas_agc_com_state_t; @@ -841,7 +842,7 @@ typedef struct ivas_fb_bin_to_band_data_t typedef struct ivas_filterbank_t { - int16_t filterbank_num_bands; + Word16 filterbank_num_bands; ivas_fb_consts_t fb_consts; ivas_fb_bin_to_band_data_t fb_bin_to_band; @@ -851,7 +852,7 @@ typedef struct ivas_fb_mixer_state_structure { IVAS_FB_CFG *fb_cfg; - int16_t num_diff_bands; + Word16 num_diff_bands; ivas_filterbank_t *pFb; #ifndef IVAS_FLOAT_FIXED float *ppFilterbank_inFR_re[IVAS_MAX_FB_MIXER_IN_CH]; @@ -871,14 +872,14 @@ typedef struct ivas_fb_mixer_state_structure #endif /* store sin part in const table (no need to store 1s and 0s, no need to do windowing for 1's and 0's as well) */ - int16_t cross_fade_start_offset; - int16_t cross_fade_end_offset; + Word16 cross_fade_start_offset; + Word16 cross_fade_end_offset; const float *pFilterbank_cross_fade; - int16_t ana_window_offset; + Word16 ana_window_offset; const float *pAna_window; - int16_t prior_input_length; - int16_t windowed_fr_offset; + Word16 prior_input_length; + Word16 windowed_fr_offset; #ifdef IVAS_FLOAT_FIXED const Word16 *pFilterbank_cross_fade_fx; Word16 cldfb_cross_fade_fx[CLDFB_NO_COL_MAX]; @@ -887,10 +888,10 @@ typedef struct ivas_fb_mixer_state_structure #else float cldfb_cross_fade[CLDFB_NO_COL_MAX]; #endif // IVAS_FLOAT_FIXED - int16_t cldfb_cross_fade_start; - int16_t cldfb_cross_fade_end; + Word16 cldfb_cross_fade_start; + Word16 cldfb_cross_fade_end; - int16_t first_frame[IVAS_SPAR_MAX_CH]; + Word16 first_frame[IVAS_SPAR_MAX_CH]; } IVAS_FB_MIXER_DATA, *IVAS_FB_MIXER_HANDLE; @@ -903,27 +904,29 @@ typedef struct ivas_param_ism_data_structure { IVAS_FB_MIXER_HANDLE hFbMixer; - int16_t nbands; - int16_t nblocks[MAX_PARAM_ISM_NBANDS]; - int16_t band_grouping[MAX_PARAM_ISM_NBANDS + 1]; + Word16 nbands; + Word16 nblocks[MAX_PARAM_ISM_NBANDS]; + Word16 band_grouping[MAX_PARAM_ISM_NBANDS + 1]; - int16_t azi_index[MAX_NUM_OBJECTS]; - int16_t ele_index[MAX_NUM_OBJECTS]; + Word16 azi_index[MAX_NUM_OBJECTS]; + Word16 ele_index[MAX_NUM_OBJECTS]; - int16_t obj_indices[MAX_PARAM_ISM_NBANDS][MAX_PARAM_ISM_NBLOCKS][MAX_PARAM_ISM_WAVE]; - int16_t power_ratios_idx[MAX_PARAM_ISM_NBANDS][MAX_PARAM_ISM_NBLOCKS]; + Word16 obj_indices[MAX_PARAM_ISM_NBANDS][MAX_PARAM_ISM_NBLOCKS][MAX_PARAM_ISM_WAVE]; + Word16 power_ratios_idx[MAX_PARAM_ISM_NBANDS][MAX_PARAM_ISM_NBLOCKS]; - int16_t last_az_sgn[MAX_NUM_OBJECTS]; - int16_t last_az_diff[MAX_NUM_OBJECTS]; - int16_t last_el_sgn[MAX_NUM_OBJECTS]; - int16_t last_el_diff[MAX_NUM_OBJECTS]; + Word16 last_az_sgn[MAX_NUM_OBJECTS]; + Word16 last_az_diff[MAX_NUM_OBJECTS]; + Word16 last_el_sgn[MAX_NUM_OBJECTS]; + Word16 last_el_diff[MAX_NUM_OBJECTS]; - int16_t flag_noisy_speech; - int16_t noisy_speech_buffer[PARAM_ISM_HYS_BUF_SIZE]; - int16_t flag_equal_energy; + Word16 flag_noisy_speech; + Word16 noisy_speech_buffer[PARAM_ISM_HYS_BUF_SIZE]; + Word16 flag_equal_energy; +#ifndef IVAS_FLOAT_FIXED float last_dmx_gain; float last_cardioid_left[MAX_NUM_OBJECTS]; +#endif Word16 last_dmx_gain_fx; Word16 last_dmx_gain_e; diff --git a/lib_com/ivas_stereo_mdct_bands_com.c b/lib_com/ivas_stereo_mdct_bands_com.c index ab2357d24..903f7adee 100644 --- a/lib_com/ivas_stereo_mdct_bands_com.c +++ b/lib_com/ivas_stereo_mdct_bands_com.c @@ -67,13 +67,13 @@ typedef union #ifdef IVAS_FLOAT_FIXED void stereo_mdct_init_bands_fx( - const Word16 L_frame, /* i : frame length */ - const Word16 tmp_tcx_mode, /* i : tcx mode (TCX10, TCX 20), -1 if transition frame */ - const Word32 element_brate, /* i : element bitrate */ - const Word16 igf, /* i : flag indicating if IGF is used */ + const Word16 L_frame, /* i : frame length Q0*/ + const Word16 tmp_tcx_mode, /* i : tcx mode (TCX10, TCX 20), -1 if transition frame Q0*/ + const Word32 element_brate, /* i : element bitrate Q0*/ + const Word16 igf, /* i : flag indicating if IGF is used Q0*/ const H_IGF_GRID hIgfGrid, /* i : IGF grid setup */ - Word16 *sfbOffset, /* o : sfb offset table */ - Word16 *sfbCnt /* o : number of sfbs */ + Word16 *sfbOffset, /* o : sfb offset table Q0*/ + Word16 *sfbCnt /* o : number of sfbs Q0*/ ) { SBPARAMS sfbParam; @@ -82,24 +82,24 @@ void stereo_mdct_init_bands_fx( IF( tmp_tcx_mode > 0 ) { - tcx_mode = tmp_tcx_mode; + tcx_mode = tmp_tcx_mode; /*Q0*/ move16(); IF( EQ_16( tcx_mode, TCX_20_CORE ) ) { - L_frameTCX = L_frame; + L_frameTCX = L_frame; /*Q0*/ move16(); } ELSE { - L_frameTCX = shr( L_frame, 1 ); + L_frameTCX = shr( L_frame, 1 ); /*Q0*/ move16(); } } ELSE { /*transition frame*/ - L_frameTCX = add( L_frame, shr( L_frame, 2 ) ); + L_frameTCX = add( L_frame, shr( L_frame, 2 ) ); /*Q0*/ tcx_mode = TCX_20_CORE; move16(); } @@ -111,23 +111,23 @@ void stereo_mdct_init_bands_fx( IF( EQ_16( tcx_mode, TCX_20_CORE ) ) { - cnt = sfbParam.steBands->bdnCnt_TCX20[0]; + cnt = sfbParam.steBands->bdnCnt_TCX20[0]; /*Q0*/ move16(); } ELSE { - cnt = sfbParam.steBands->bndCnt_TCX10[0]; + cnt = sfbParam.steBands->bndCnt_TCX10[0]; /*Q0*/ move16(); } IF( EQ_16( tcx_mode, TCX_20_CORE ) ) { - sfbWidths = sfbParam.steBands->bandLengthsTCX20; + sfbWidths = sfbParam.steBands->bandLengthsTCX20; /*Q0*/ move16(); } ELSE { - sfbWidths = sfbParam.steBands->bandLengthsTCX10; + sfbWidths = sfbParam.steBands->bandLengthsTCX10; /*Q0*/ move16(); } } @@ -142,36 +142,36 @@ void stereo_mdct_init_bands_fx( case L_FRAME32k: IF( EQ_16( tcx_mode, TCX_20_CORE ) ) { - cnt = sfbParam.steBands->bdnCnt_TCX20[1]; + cnt = sfbParam.steBands->bdnCnt_TCX20[1]; /*Q0*/ move16(); } ELSE { - cnt = sfbParam.steBands->bndCnt_TCX10[1]; + cnt = sfbParam.steBands->bndCnt_TCX10[1]; /*Q0*/ move16(); } BREAK; case L_FRAME25_6k: IF( EQ_16( tcx_mode, TCX_20_CORE ) ) { - cnt = sfbParam.steBands->bdnCnt_TCX20[2]; + cnt = sfbParam.steBands->bdnCnt_TCX20[2]; /*Q0*/ move16(); } ELSE { - cnt = sfbParam.steBands->bndCnt_TCX10[2]; + cnt = sfbParam.steBands->bndCnt_TCX10[2]; /*Q0*/ move16(); } BREAK; case L_FRAME16k: IF( EQ_16( tcx_mode, TCX_20_CORE ) ) { - cnt = sfbParam.steBands->bdnCnt_TCX20[3]; + cnt = sfbParam.steBands->bdnCnt_TCX20[3]; /*Q0*/ move16(); } ELSE { - cnt = sfbParam.steBands->bndCnt_TCX10[3]; + cnt = sfbParam.steBands->bndCnt_TCX10[3]; /*Q0*/ move16(); } move16(); @@ -183,12 +183,12 @@ void stereo_mdct_init_bands_fx( IF( EQ_16( tcx_mode, TCX_20_CORE ) ) { - sfbWidths = sfbParam.steBands->bandLengthsTCX20; + sfbWidths = sfbParam.steBands->bandLengthsTCX20; /*Q0*/ move16(); } ELSE { - sfbWidths = sfbParam.steBands->bandLengthsTCX10; + sfbWidths = sfbParam.steBands->bandLengthsTCX10; /*Q0*/ move16(); } } @@ -213,12 +213,12 @@ void stereo_mdct_init_bands_fx( IF( EQ_16( tcx_mode, TCX_20_CORE ) ) { - sfbWidths = sfbParam.lpcBndsParam->bandLengthsTCX20; + sfbWidths = sfbParam.lpcBndsParam->bandLengthsTCX20; /*Q0*/ move16(); } ELSE { - sfbWidths = sfbParam.lpcBndsParam->bandLengthsTCX10; + sfbWidths = sfbParam.lpcBndsParam->bandLengthsTCX10; /*Q0*/ move16(); } cnt = 64; @@ -232,9 +232,9 @@ void stereo_mdct_init_bands_fx( FOR( i = 0; i < cnt; i++ ) { - sfbOffset[i] = s_min( specStartOffset, L_frameTCX ); + sfbOffset[i] = s_min( specStartOffset, L_frameTCX ); /*Q0*/ move16(); - specStartOffset = add( specStartOffset, sfbWidths[i] ); + specStartOffset = add( specStartOffset, sfbWidths[i] ); /*Q0*/ IF( GE_16( sfbOffset[i], L_frameTCX ) ) { @@ -244,7 +244,7 @@ void stereo_mdct_init_bands_fx( *sfbCnt = i; move16(); - sfbOffset[*sfbCnt] = s_min( specStartOffset, L_frameTCX ); + sfbOffset[*sfbCnt] = s_min( specStartOffset, L_frameTCX ); /*Q0*/ move16(); IF( igf ) @@ -274,7 +274,7 @@ void stereo_mdct_init_bands_fx( IF( GE_16( sfbOffset[i], hIgfGrid->startLine ) ) { /* set band border to igf start line */ - sfbOffset[i] = hIgfGrid->startLine; + sfbOffset[i] = hIgfGrid->startLine; /*Q0*/ move16(); *sfbCnt = i; move16(); @@ -284,15 +284,15 @@ void stereo_mdct_init_bands_fx( /* change bands above the igf start line to match igf bands */ FOR( ( i = 1, k = igfSfbStep ); i < hIgfGrid->swb_offset_len; ( i++, k += igfSfbStep ) ) { - sfbOffset[add( *sfbCnt, i )] = hIgfGrid->swb_offset[k]; + sfbOffset[( *sfbCnt + i )] = hIgfGrid->swb_offset[k]; /*Q0*/ move16(); } - *sfbCnt = add( *sfbCnt, sub( hIgfGrid->swb_offset_len, 1 ) ); + *sfbCnt = add( *sfbCnt, sub( hIgfGrid->swb_offset_len, 1 ) ); /*Q0*/ move16(); /* better save than sorry, overwrite anything that is left above */ - FOR( i = add( *sfbCnt, 1 ); i < add( sfbOldCnt, 1 ); i++ ) + FOR( i = ( *sfbCnt + 1 ); i < ( sfbOldCnt + 1 ); i++ ) { sfbOffset[i] = 0; move16(); @@ -302,13 +302,13 @@ void stereo_mdct_init_bands_fx( { IF( LT_16( sfbOffset[*sfbCnt], L_frameTCX ) ) { - Word16 nMissingBins = sub( L_frameTCX, sfbOffset[*sfbCnt] ); + Word16 nMissingBins = sub( L_frameTCX, sfbOffset[*sfbCnt] ); /*Q0*/ IF( LT_16( shr( sfbWidths[i], 1 ), nMissingBins ) ) { *sfbCnt = add( *sfbCnt, 1 ); move16(); } - sfbOffset[*sfbCnt] = L_frameTCX; + sfbOffset[*sfbCnt] = L_frameTCX; /*Q0*/ move16(); } } @@ -474,17 +474,17 @@ void stereo_mdct_init_bands( #ifdef IVAS_FLOAT_FIXED void stereo_mdct_init_igf_start_band_fx( STEREO_MDCT_BAND_PARAMETERS *stbParams, /* i/o: stereo frequency band parameters */ - const Word16 transFac, /* i : transform factor */ - const Word16 bwidth, /* i : audio bandwidth */ - const Word32 element_brate /* i : element bitrate */ + const Word16 transFac, /* i : transform factor Q14*/ + const Word16 bwidth, /* i : audio bandwidth Q0*/ + const Word32 element_brate /* i : element bitrate Q0*/ ) { Word16 i, bitRateIndex, igfStartLine; const Word16 *swb_offset; - bitRateIndex = IGF_MapBitRateToIndex( element_brate, bwidth, IVAS_CPE_MDCT, 0 ); + bitRateIndex = IGF_MapBitRateToIndex( element_brate, bwidth, IVAS_CPE_MDCT, 0 ); /*Q0*/ swb_offset = &swb_offset_LB_new[bitRateIndex][1]; - igfStartLine = IGF_ApplyTransFac( swb_offset[0], transFac ); + igfStartLine = IGF_ApplyTransFac( swb_offset[0], transFac ); /*Q0*/ FOR( i = 0; i < stbParams->sfbCnt; i++ ) { @@ -496,7 +496,7 @@ void stereo_mdct_init_igf_start_band_fx( } } - stbParams->nBandsStereoCore = stbParams->sfbIgfStart; + stbParams->nBandsStereoCore = stbParams->sfbIgfStart; /*Q0*/ move16(); diff --git a/lib_com/ivas_stereo_mdct_stereo_com.c b/lib_com/ivas_stereo_mdct_stereo_com.c index f28c69b22..7f8f1b55b 100644 --- a/lib_com/ivas_stereo_mdct_stereo_com.c +++ b/lib_com/ivas_stereo_mdct_stereo_com.c @@ -49,26 +49,26 @@ #ifdef IVAS_FLOAT_FIXED void splitAvailableBits_fx( - const Word16 total_bits, /* i : total available bits for TCX coding */ - const Word16 split_ratio, /* i : split ratio */ - const Word16 isSBAStereoMode, /* i : signal core coding for SBA */ - Word16 *bits_ch0, /* o : bits for channel 0 */ - Word16 *bits_ch1 /* o : bits for channel 1 */ + const Word16 total_bits, /* i : total available bits for TCX coding Q0*/ + const Word16 split_ratio, /* i : split ratio Q0*/ + const Word16 isSBAStereoMode, /* i : signal core coding for SBA Q0*/ + Word16 *bits_ch0, /* o : bits for channel 0 Q0*/ + Word16 *bits_ch1 /* o : bits for channel 1 Q0*/ ) { assert( split_ratio >= 1 && LT_16( split_ratio, SMDCT_BITRATE_RATIO_RANGE ) ); /* *bits_ch0 = split_ratio * total_bits / SMDCT_BITRATE_RATIO_RANGE; */ - *bits_ch0 = extract_l( L_shr( L_mult0( split_ratio, total_bits ), 3 ) ); + *bits_ch0 = extract_l( L_shr( L_mult0( split_ratio, total_bits ), 3 ) ); /*Q0*/ move16(); /* for SBA mode bias the distribution towards the W channel */ test(); IF( LT_16( split_ratio, 7 ) && isSBAStereoMode ) { - *bits_ch0 = add( *bits_ch0, extract_l( Mpy_32_16_1( 6554 /* 0.2 in Q15 */, *bits_ch0 ) ) ); + *bits_ch0 = add( *bits_ch0, extract_l( Mpy_32_16_1( 6554 /* 0.2 in Q15 */, *bits_ch0 ) ) ); /*Q0*/ move16(); } - *bits_ch1 = sub( total_bits, *bits_ch0 ); + *bits_ch1 = sub( total_bits, *bits_ch0 ); /*Q0*/ move16(); return; diff --git a/lib_com/ivas_stereo_psychlpc_com.c b/lib_com/ivas_stereo_psychlpc_com.c index 8ca07965d..1acadee31 100644 --- a/lib_com/ivas_stereo_psychlpc_com.c +++ b/lib_com/ivas_stereo_psychlpc_com.c @@ -52,16 +52,16 @@ #ifdef IVAS_FLOAT_FIXED static void SpectrumWeighting_Init_fx( SpectrumWarping const *pSpectrumWarping, - const Word16 isTCX20, + const Word16 isTCX20, /*Q0*/ PsychoacousticParameters *pPsychParams ) { IF( isTCX20 ) { - pPsychParams->bandLengths = pSpectrumWarping->bandLengthsTCX20; + pPsychParams->bandLengths = pSpectrumWarping->bandLengthsTCX20; /*Q0*/ } ELSE { - pPsychParams->bandLengths = pSpectrumWarping->bandLengthsTCX10; + pPsychParams->bandLengths = pSpectrumWarping->bandLengthsTCX10; /*Q0*/ } return; @@ -94,10 +94,10 @@ static void SpectrumWeighting_Init( #ifdef IVAS_FLOAT_FIXED ivas_error PsychoacousticParameters_Init_fx( - const Word32 sr_core, /* i : sampling rate of core-coder */ - const Word16 nBins, /* i : Number of bins (spectral lines) */ - const Word8 nBands, /* i : Number of spectrum subbands */ - const Word16 isTCX20, /* i : Flag indicating if the subband division is for TCX20 or TCX10 */ + const Word32 sr_core, /* i : sampling rate of core-coder Q0*/ + const Word16 nBins, /* i : Number of bins (spectral lines) Q0*/ + const Word8 nBands, /* i : Number of spectrum subbands Q0*/ + const Word16 isTCX20, /* i : Flag indicating if the subband division is for TCX20 or TCX10 Q0*/ const Word16 isWarped, /* i : Flag indicating if the scale is linear or warped */ PsychoacousticParameters *pPsychParams ) { @@ -107,8 +107,8 @@ ivas_error PsychoacousticParameters_Init_fx( return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "PsychParams handle is NULL" ); } - pPsychParams->nBins = nBins; - pPsychParams->nBands = nBands; + pPsychParams->nBins = nBins; /*Q0*/ + pPsychParams->nBands = nBands; /*Q0*/ move16(); move16(); @@ -191,12 +191,12 @@ ivas_error PsychoacousticParameters_Init( #ifdef IVAS_FLOAT_FIXED void InitPsychLPC_fx( - const Word32 sr_core, /* i : sampling rate of core-coder */ - const Word16 L_frame, /* i : frame length */ + const Word32 sr_core, /* i : sampling rate of core-coder Q0*/ + const Word16 L_frame, /* i : frame length Q0*/ const TCX_CONFIG_HANDLE hTcxCfg /* i : TCX configuration handle */ ) { - Word16 L_frame_ext = add( L_frame, shr( L_frame, 2 ) ); + Word16 L_frame_ext = add( L_frame, shr( L_frame, 2 ) ); /*Q0*/ hTcxCfg->psychParamsCurrent = NULL; @@ -252,8 +252,8 @@ void SetCurrentPsychParams( } #else void SetCurrentPsychParams( - const Word16 core, - const Word16 last_frame_was_concealed_cng, + const Word16 core, /*Q0*/ + const Word16 last_frame_was_concealed_cng, /*Q0*/ TCX_CONFIG_HANDLE hTcxCfg ) { test(); diff --git a/lib_com/ivas_stereo_td_bit_alloc.c b/lib_com/ivas_stereo_td_bit_alloc.c index 4d8f90e9d..2168a6755 100644 --- a/lib_com/ivas_stereo_td_bit_alloc.c +++ b/lib_com/ivas_stereo_td_bit_alloc.c @@ -438,29 +438,29 @@ void tdm_bit_alloc( #else void tdm_bit_alloc( - const Word16 ivas_format, /* i : IVAS format */ - const Word16 ism_mode, /* i : ISM mode in combined format */ - const Word32 element_brate_wo_meta, /* i : element bitrate without metadata */ - const Word16 tdm_lp_reuse_flag, /* i : LPC reusage flag */ - Word32 *total_brate_pri, /* o : Allocated primary channel bitrate */ - Word32 *total_brate_sec, /* o : Allocated secondary channel bitrate */ - Word16 *tdm_low_rate_mode, /* o : secondary channel low rate mode flag*/ - const Word16 coder_type, /* i : secondary channel coder type */ - const Word16 ener_ratio_idx, /* i : correlation ratio indexe */ - const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag */ - const Word16 bwidth_pri, /* i : bandwidth of the primary channel */ - const Word16 bwidth_sec, /* i : bandwidth of the secondary channel */ - const Word16 flag_ACELP16k_pri, /* i : ACELP@16kHz core flag, primary chan.*/ - const Word16 tdm_LRTD_flag, /* i : LRTD stereo mode flag */ - const Word16 coder_type0, /* i : coder type (temporary in the encoder, from bitstream in decoder) */ - const Word16 tdm_inst_ratio_idx_ref /* i : instantaneous correlation ratio idx */ + const Word16 ivas_format, /* i : IVAS format Q0*/ + const Word16 ism_mode, /* i : ISM mode in combined format Q0*/ + const Word32 element_brate_wo_meta, /* i : element bitrate without metadata Q0*/ + const Word16 tdm_lp_reuse_flag, /* i : LPC reusage flag Q0*/ + Word32 *total_brate_pri, /* o : Allocated primary channel bitrate Q0*/ + Word32 *total_brate_sec, /* o : Allocated secondary channel bitrate Q0*/ + Word16 *tdm_low_rate_mode, /* o : secondary channel low rate mode flag Q0*/ + const Word16 coder_type, /* i : secondary channel coder type Q0*/ + const Word16 ener_ratio_idx, /* i : correlation ratio indexe Q0*/ + const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag Q0*/ + const Word16 bwidth_pri, /* i : bandwidth of the primary channel Q0*/ + const Word16 bwidth_sec, /* i : bandwidth of the secondary channel Q0*/ + const Word16 flag_ACELP16k_pri, /* i : ACELP@16kHz core flag, primary chan. Q0*/ + const Word16 tdm_LRTD_flag, /* i : LRTD stereo mode flag Q0*/ + const Word16 coder_type0, /* i : coder type (temporary in the encoder, from bitstream in decoder) Q0*/ + const Word16 tdm_inst_ratio_idx_ref /* i : instantaneous correlation ratio idx Q0*/ ) { Word16 idx, four_subfr_fcb, two_subfr_fcb; Word32 bit_rate_diff_fx; Word32 BWE_brate; Word16 tmp_bits; - Word16 tdm_inst_ratio_idx = tdm_inst_ratio_idx_ref; + Word16 tdm_inst_ratio_idx = tdm_inst_ratio_idx_ref; /*Q0*/ move16(); if ( EQ_16( tdm_inst_ratio_idx, TDM_NQ ) ) { @@ -511,7 +511,7 @@ void tdm_bit_alloc( } /* Secondary channel based bitrate allocation */ - *total_brate_sec = tdm_bit_allc_tbl[idx][coder_type]; + *total_brate_sec = tdm_bit_allc_tbl[idx][coder_type]; /*Q0*/ move16(); test(); @@ -523,7 +523,7 @@ void tdm_bit_alloc( /* secondary channel bitrate allocation based on the energy scaling ratio */ IF( ( ( NE_16( ivas_format, MASA_ISM_FORMAT ) || ism_mode == ISM_MODE_NONE ) && ( ( NE_16( coder_type, UNVOICED ) ) || EQ_16( tdm_LRTD_flag, 1 ) ) ) || ( EQ_16( ivas_format, MASA_ISM_FORMAT ) && ism_mode != ISM_MODE_NONE && GT_16( coder_type, UNVOICED ) ) ) { - bit_rate_diff_fx = L_sub( element_brate_wo_meta, L_shl( *total_brate_sec, 1 ) ); + bit_rate_diff_fx = L_sub( element_brate_wo_meta, L_shl( *total_brate_sec, 1 ) ); /*Q0*/ IF( EQ_16( tdm_LRTD_flag, 1 ) ) /* > element_brate > STEREO_22k or CT0 not used */ { @@ -532,31 +532,31 @@ void tdm_bit_alloc( { Word32 res_fix = 0; move32(); - res_fix = Mpy_32_32( 644245095, L_sub( element_brate_wo_meta, 500 ) ); - res_fix = imult3216( Mpy_32_32( L_abs( res_fix ), 21474837 ), 100 ); + res_fix = Mpy_32_32( 644245095 /*0.3f in Q31*/, L_sub( element_brate_wo_meta, 500 ) ); /*Q0*/ + res_fix = imult3216( Mpy_32_32( L_abs( res_fix ), 21474837 /*0.01 in Q31*/ ), 100 ); /*Q0*/ if ( res_fix < 0 ) { res_fix = L_negate( res_fix ); } - *total_brate_sec = L_max( *total_brate_sec, res_fix ); + *total_brate_sec = L_max( *total_brate_sec, res_fix ); /*Q0*/ move32(); - tmp_bits = imult1616( negate( abs_s( sub( tdm_inst_ratio_idx, 16 ) ) ), imult1616( idx, 200 ) ); + tmp_bits = imult1616( negate( abs_s( sub( tdm_inst_ratio_idx, 16 ) ) ), imult1616( idx, 200 ) ); /*Q0*/ } ELSE { Word32 res_fix = 0; move32(); - res_fix = Mpy_32_32( 1073741824, L_sub( element_brate_wo_meta, 500 ) ); - res_fix = imult3216( Mpy_32_32( L_abs( res_fix ), 21474837 ), 100 ); + res_fix = Mpy_32_32( 1073741824 /*0.5f in Q31*/, L_sub( element_brate_wo_meta, 500 ) ); /*Q0*/ + res_fix = imult3216( Mpy_32_32( L_abs( res_fix ), 21474837 /*0.01 in Q31*/ ), 100 ); /*Q0*/ if ( res_fix < 0 ) { res_fix = L_negate( res_fix ); } - *total_brate_sec = L_max( *total_brate_sec, res_fix ); + *total_brate_sec = L_max( *total_brate_sec, res_fix ); /*Q0*/ move32(); - tmp_bits = imult1616( negate( abs_s( sub( tdm_inst_ratio_idx, 16 ) ) ), imult1616( 100, idx ) ); + tmp_bits = imult1616( negate( abs_s( sub( tdm_inst_ratio_idx, 16 ) ) ), imult1616( 100, idx ) ); /*Q0*/ } /* tmp_bits should be subtract from the secondary channel bitrate */ @@ -576,9 +576,9 @@ void tdm_bit_alloc( IF( LT_16( ener_ratio_idx, LRTD_STEREO_MID_IS_PRIM ) ) { - bit_rate_diff_fx = imult3216( bit_rate_diff_fx, sub( LRTD_STEREO_MID_IS_PRIM, ener_ratio_idx ) ); - bit_rate_diff_fx = L_shr( bit_rate_diff_fx, 1 ); - bit_rate_diff_fx = Mpy_32_16_1( L_abs( bit_rate_diff_fx ), 3277 ); + bit_rate_diff_fx = imult3216( bit_rate_diff_fx, sub( LRTD_STEREO_MID_IS_PRIM, ener_ratio_idx ) ); /*Q0*/ + bit_rate_diff_fx = L_shr( bit_rate_diff_fx, 1 ); /*Q0*/ + bit_rate_diff_fx = Mpy_32_16_1( L_abs( bit_rate_diff_fx ), 3277 /*0.1f in Q15*/ ); /*Q0*/ if ( bit_rate_diff_fx < 0 ) { bit_rate_diff_fx = L_negate( bit_rate_diff_fx ); @@ -586,9 +586,9 @@ void tdm_bit_alloc( } ELSE { - bit_rate_diff_fx = imult3216( bit_rate_diff_fx, sub( ener_ratio_idx, LRTD_STEREO_MID_IS_PRIM ) ); - bit_rate_diff_fx = L_shr( bit_rate_diff_fx, 1 ); - bit_rate_diff_fx = Mpy_32_16_1( L_abs( bit_rate_diff_fx ), 3277 ); + bit_rate_diff_fx = imult3216( bit_rate_diff_fx, sub( ener_ratio_idx, LRTD_STEREO_MID_IS_PRIM ) ); /*Q0*/ + bit_rate_diff_fx = L_shr( bit_rate_diff_fx, 1 ); /*Q0*/ + bit_rate_diff_fx = Mpy_32_16_1( L_abs( bit_rate_diff_fx ), 3277 /*0.1f in Q15*/ ); /*Q0*/ if ( bit_rate_diff_fx < 0 ) { bit_rate_diff_fx = L_negate( bit_rate_diff_fx ); @@ -596,21 +596,21 @@ void tdm_bit_alloc( } } /*bit_rate_diff2 = ((Word16)(10.f*(-0.5f*ener_ratio_LR+0.5f)*bit_rate_diff)/100)*100;*/ - Word32 temp = imult3216( Mpy_32_16_1( L_abs( bit_rate_diff_fx ), 328 ), 100 ); + Word32 temp = imult3216( Mpy_32_16_1( L_abs( bit_rate_diff_fx ), 328 /*0.01f in Q15*/ ), 100 ); /*Q0*/ if ( bit_rate_diff_fx < 0 ) { temp = L_negate( temp ); } - *total_brate_sec = L_add( *total_brate_sec, temp ); + *total_brate_sec = L_add( *total_brate_sec, temp ); /*Q0*/ move32(); - *total_brate_sec = L_max( *total_brate_sec, tdm_bit_allc_tbl[idx][coder_type] ); + *total_brate_sec = L_max( *total_brate_sec, tdm_bit_allc_tbl[idx][coder_type] ); /*Q0*/ move32(); test(); IF( ( coder_type == INACTIVE ) && tdm_LRTD_flag == 0 ) { - *total_brate_sec = L_min( *total_brate_sec, MIN_BRATE_SWB_BWE ); + *total_brate_sec = L_min( *total_brate_sec, MIN_BRATE_SWB_BWE ); /*Q0*/ move32(); } @@ -623,11 +623,11 @@ void tdm_bit_alloc( IF( GT_16( bwidth_pri, WB ) ) { - delta_brate = 600; /* To slightly compensate for SWB BWE instead of WB BWE */ + delta_brate = 600; /* To slightly compensate for SWB BWE instead of WB BWE Q0*/ move16(); if ( LE_32( element_brate_wo_meta, IVAS_16k4 ) ) { - delta_brate = 1250; /* To compensate for SWB BWE instead of WB BWE */ + delta_brate = 1250; /* To compensate for SWB BWE instead of WB BWE Q0*/ move16(); } } @@ -639,41 +639,41 @@ void tdm_bit_alloc( } ELSE IF( LE_32( element_brate_wo_meta, IVAS_16k4 ) ) { - *total_brate_sec = L_max( *total_brate_sec, add( 6500, delta_brate ) ); /* ~40-43 % of the total bitrate */ + *total_brate_sec = L_max( *total_brate_sec, add( 6500, delta_brate ) ); /* ~40-43 % of the total bitrate Q0*/ move32(); } ELSE IF( LE_32( element_brate_wo_meta, IVAS_24k4 ) ) { - *total_brate_sec = L_max( *total_brate_sec, add( 9000, delta_brate ) ); /* ~37-39 % of the total bitrate */ + *total_brate_sec = L_max( *total_brate_sec, add( 9000, delta_brate ) ); /* ~37-39 % of the total bitrate Q0*/ move32(); } ELSE { - *total_brate_sec = L_max( *total_brate_sec, add( 9600, delta_brate ) ); /* ~30-32% of the total bitrate */ + *total_brate_sec = L_max( *total_brate_sec, add( 9600, delta_brate ) ); /* ~30-32% of the total bitrate Q0*/ move32(); } } ELSE { - *total_brate_sec = L_min( *total_brate_sec, Mpy_32_32( 9663677, element_brate_wo_meta ) * 100 ); + *total_brate_sec = L_min( *total_brate_sec, Mpy_32_32( 9663677 /*0.0045f in Q31*/, element_brate_wo_meta ) * 100 ); /*Q0*/ move32(); } - *total_brate_sec = L_min( *total_brate_sec, 18000 ); + *total_brate_sec = L_min( *total_brate_sec, 18000 ); /*Q0*/ move32(); } ELSE IF( EQ_16( coder_type, UNVOICED ) ) { IF( tdm_lp_reuse_flag == 0 ) { - *total_brate_sec = L_add( *total_brate_sec, imult3216( FRAMES_PER_SEC, 36 ) ); + *total_brate_sec = L_add( *total_brate_sec, imult3216( FRAMES_PER_SEC, 36 ) ); /*Q0*/ move32(); } } IF( LE_16( coder_type, UNVOICED ) ) { - *total_brate_sec = L_min( *total_brate_sec, MAX_TDM_UC_BRATE ); + *total_brate_sec = L_min( *total_brate_sec, MAX_TDM_UC_BRATE ); /*Q0*/ move32(); test(); @@ -693,7 +693,7 @@ void tdm_bit_alloc( } ELSE IF( ( tdm_lp_reuse_flag == 0 && LT_32( *total_brate_sec, TDM_UC_NORMAL_MODE_MINBR_LP_R ) && EQ_16( coder_type, UNVOICED ) ) || ( tdm_lp_reuse_flag == 0 && LE_32( *total_brate_sec, L_deposit_l( add( tdm_bit_allc_tbl[idx][0], MID_LP_BRATE ) ) ) ) ) { - *total_brate_sec = L_add( *total_brate_sec, MID_LP_BRATE ); + *total_brate_sec = L_add( *total_brate_sec, MID_LP_BRATE ); /*Q0*/ move32(); } } @@ -730,7 +730,7 @@ void tdm_bit_alloc( IF( LT_32( ( L_sub( ( L_sub( element_brate_wo_meta, *total_brate_sec ) ), BWE_brate ) ), 14000 ) ) { - *total_brate_sec = L_sub( element_brate_wo_meta, L_add( 14000, BWE_brate ) ); + *total_brate_sec = L_sub( element_brate_wo_meta, L_add( 14000, BWE_brate ) ); /*Q0*/ move32(); } } @@ -744,12 +744,12 @@ void tdm_bit_alloc( move32(); if ( tdm_LRTD_flag == 0 ) { - BWE_brate = L_add( BWE_brate, 250 ); /* ICA Brate */ + BWE_brate = L_add( BWE_brate, 250 ); /* ICA Brate Q0*/ } } ELSE IF( tdm_LRTD_flag == 0 ) { - BWE_brate = L_add( BWE_brate, 350 ); /* ICA Brate */ + BWE_brate = L_add( BWE_brate, 350 ); /* ICA Brate Q0*/ } } @@ -757,29 +757,29 @@ void tdm_bit_alloc( { IF( GT_32( element_brate_wo_meta, IVAS_13k2 ) ) { - *total_brate_sec = L_min( *total_brate_sec, L_sub( element_brate_wo_meta, L_add( ACELP_8k00, BWE_brate ) ) ); + *total_brate_sec = L_min( *total_brate_sec, L_sub( element_brate_wo_meta, L_add( ACELP_8k00, BWE_brate ) ) ); /*Q0*/ move32(); } ELSE { - *total_brate_sec = L_min( *total_brate_sec, L_sub( element_brate_wo_meta, L_add( ACELP_7k20, BWE_brate ) ) ); + *total_brate_sec = L_min( *total_brate_sec, L_sub( element_brate_wo_meta, L_add( ACELP_7k20, BWE_brate ) ) ); /*Q0*/ move32(); } } ELSE { - *total_brate_sec = L_min( *total_brate_sec, L_sub( element_brate_wo_meta, L_add( 5900, BWE_brate ) ) ); + *total_brate_sec = L_min( *total_brate_sec, L_sub( element_brate_wo_meta, L_add( 5900, BWE_brate ) ) ); /*Q0*/ move32(); } IF( coder_type == INACTIVE ) { - *total_brate_sec = L_max( *total_brate_sec, tdm_bit_allc_tbl[0][0] ); /* sanity check to ensure the secondary channel always gets the minimal bitrate it needs */ + *total_brate_sec = L_max( *total_brate_sec, tdm_bit_allc_tbl[0][0] ); /* sanity check to ensure the secondary channel always gets the minimal bitrate it needs Q0*/ move32(); } ELSE { - *total_brate_sec = L_max( *total_brate_sec, 3500 ); /* sanity check to ensure the secondary channel always gets the minimal bitrate it needs */ + *total_brate_sec = L_max( *total_brate_sec, 3500 ); /* sanity check to ensure the secondary channel always gets the minimal bitrate it needs Q0*/ move32(); } @@ -796,51 +796,51 @@ void tdm_bit_alloc( /* Pitch is transmitted as well, further increase the bitrate */ IF( tdm_Pitch_reuse_flag == 0 ) { - *total_brate_sec = L_max( *total_brate_sec, MIN_FCB_SECRATE2 + MIN_SEC_ACB_RATE + MIN_SEC_LPC_RATE + MIN_SIGN_RATE ); + *total_brate_sec = L_max( *total_brate_sec, MIN_FCB_SECRATE2 + MIN_SEC_ACB_RATE + MIN_SEC_LPC_RATE + MIN_SIGN_RATE ); /*Q0*/ move32(); test(); IF( EQ_16( tdm_LRTD_flag, 1 ) && EQ_16( bwidth_sec, SWB ) ) { /* ensure that there are enough bits to code SWB TBE_1k10 as well */ - *total_brate_sec = L_max( *total_brate_sec, MIN_FCB_SECRATE2 + MIN_SEC_ACB_RATE + MIN_SEC_LPC_RATE + MIN_SIGN_RATE + SWB_TBE_1k10 ); + *total_brate_sec = L_max( *total_brate_sec, MIN_FCB_SECRATE2 + MIN_SEC_ACB_RATE + MIN_SEC_LPC_RATE + MIN_SIGN_RATE + SWB_TBE_1k10 ); /*Q0*/ move32(); } } ELSE /* only LPC is tranmitted -> IF ( *total_brate_sec < MIN_SEC_BRATE+MIN_SEC_LPC_RATE ) */ { - *total_brate_sec = L_max( *total_brate_sec, MIN_FCB_SECRATE2 + MIN_SEC_LPC_RATE + MIN_SIGN_RATE ); + *total_brate_sec = L_max( *total_brate_sec, MIN_FCB_SECRATE2 + MIN_SEC_LPC_RATE + MIN_SIGN_RATE ); /*Q0*/ move32(); } } ELSE IF( /*tdm_lp_reuse_flag == 1*/ tdm_Pitch_reuse_flag == 0 ) { - *total_brate_sec = L_max( *total_brate_sec, MIN_FCB_SECRATE2 + MIN_SEC_ACB_RATE + MIN_SIGN_RATE ); + *total_brate_sec = L_max( *total_brate_sec, MIN_FCB_SECRATE2 + MIN_SEC_ACB_RATE + MIN_SIGN_RATE ); /*Q0*/ move32(); } /* Choose between 2 and 4 subfr, depending of the bitrate available and prevent the gap between the 2 atlernative */ IF( EQ_16( tdm_LRTD_flag, 1 ) ) { - four_subfr_fcb = extract_l( L_sub( *total_brate_sec, ( TDM_SIGNAL_BITS_READ_FROM_THE_END_OF_BS - STEREO_BITS_TCA + 1 + 4 * MIN_GAIN_BITS ) * FRAMES_PER_SEC ) ); - two_subfr_fcb = extract_l( L_sub( *total_brate_sec, ( TDM_SIGNAL_BITS_READ_FROM_THE_END_OF_BS - STEREO_BITS_TCA + 1 + 2 * MIN_GAIN_BITS ) * FRAMES_PER_SEC ) ); + four_subfr_fcb = extract_l( L_sub( *total_brate_sec, ( TDM_SIGNAL_BITS_READ_FROM_THE_END_OF_BS - STEREO_BITS_TCA + 1 + 4 * MIN_GAIN_BITS ) * FRAMES_PER_SEC ) ); /*Q0*/ + two_subfr_fcb = extract_l( L_sub( *total_brate_sec, ( TDM_SIGNAL_BITS_READ_FROM_THE_END_OF_BS - STEREO_BITS_TCA + 1 + 2 * MIN_GAIN_BITS ) * FRAMES_PER_SEC ) ); /*Q0*/ } ELSE { - four_subfr_fcb = extract_l( L_sub( *total_brate_sec, ( TDM_SIGNAL_BITS_READ_FROM_THE_END_OF_BS + 1 + 4 * MIN_GAIN_BITS ) * FRAMES_PER_SEC ) ); - two_subfr_fcb = extract_l( L_sub( *total_brate_sec, ( TDM_SIGNAL_BITS_READ_FROM_THE_END_OF_BS + 1 + 2 * MIN_GAIN_BITS ) * FRAMES_PER_SEC ) ); + four_subfr_fcb = extract_l( L_sub( *total_brate_sec, ( TDM_SIGNAL_BITS_READ_FROM_THE_END_OF_BS + 1 + 4 * MIN_GAIN_BITS ) * FRAMES_PER_SEC ) ); /*Q0*/ + two_subfr_fcb = extract_l( L_sub( *total_brate_sec, ( TDM_SIGNAL_BITS_READ_FROM_THE_END_OF_BS + 1 + 2 * MIN_GAIN_BITS ) * FRAMES_PER_SEC ) ); /*Q0*/ } IF( tdm_lp_reuse_flag == 0 ) { - four_subfr_fcb = sub( four_subfr_fcb, MIN_SEC_LPC_RATE ); - two_subfr_fcb = sub( two_subfr_fcb, MIN_SEC_LPC_RATE ); + four_subfr_fcb = sub( four_subfr_fcb, MIN_SEC_LPC_RATE ); /*Q0*/ + two_subfr_fcb = sub( two_subfr_fcb, MIN_SEC_LPC_RATE ); /*Q0*/ } IF( tdm_Pitch_reuse_flag == 0 ) { - four_subfr_fcb = sub( four_subfr_fcb, ( MIN_SEC_ACB_RATE + 10 * FRAMES_PER_SEC ) ); - two_subfr_fcb = sub( two_subfr_fcb, MIN_SEC_ACB_RATE ); + four_subfr_fcb = sub( four_subfr_fcb, ( MIN_SEC_ACB_RATE + 10 * FRAMES_PER_SEC ) ); /*Q0*/ + two_subfr_fcb = sub( two_subfr_fcb, MIN_SEC_ACB_RATE ); /*Q0*/ } /* Too much bits for the 2 subfr model but not enough for the the 4 subfr model -> slightly reduce the 2nd channel bitrate */ @@ -849,24 +849,24 @@ void tdm_bit_alloc( { IF( EQ_16( tdm_LRTD_flag, 1 ) ) { - *total_brate_sec = 2 * MAX_SC_FCB_RATE * FRAMES_PER_SEC + ( TDM_SIGNAL_BITS_READ_FROM_THE_END_OF_BS - STEREO_BITS_TCA + 1 + 2 * MIN_GAIN_BITS ) * FRAMES_PER_SEC; + *total_brate_sec = 2 * MAX_SC_FCB_RATE * FRAMES_PER_SEC + ( TDM_SIGNAL_BITS_READ_FROM_THE_END_OF_BS - STEREO_BITS_TCA + 1 + 2 * MIN_GAIN_BITS ) * FRAMES_PER_SEC; /*Q0*/ move32(); } ELSE { - *total_brate_sec = 2 * MAX_SC_FCB_RATE * FRAMES_PER_SEC + ( TDM_SIGNAL_BITS_READ_FROM_THE_END_OF_BS + 1 + 2 * MIN_GAIN_BITS ) * FRAMES_PER_SEC; + *total_brate_sec = 2 * MAX_SC_FCB_RATE * FRAMES_PER_SEC + ( TDM_SIGNAL_BITS_READ_FROM_THE_END_OF_BS + 1 + 2 * MIN_GAIN_BITS ) * FRAMES_PER_SEC; /*Q0*/ move32(); } IF( tdm_lp_reuse_flag == 0 ) { - *total_brate_sec = L_add( *total_brate_sec, MIN_SEC_LPC_RATE ); + *total_brate_sec = L_add( *total_brate_sec, MIN_SEC_LPC_RATE ); /*Q0*/ move32(); } IF( tdm_Pitch_reuse_flag == 0 ) { - *total_brate_sec = L_add( *total_brate_sec, MIN_SEC_ACB_RATE ); + *total_brate_sec = L_add( *total_brate_sec, MIN_SEC_ACB_RATE ); /*Q0*/ move32(); } } @@ -878,7 +878,7 @@ void tdm_bit_alloc( ELSE /* Possible slight increase of secondary channel bit budget to compensate for FCB limited flexibility */ { Word16 tmp_rate, i; - tmp_rate = two_subfr_fcb; + tmp_rate = two_subfr_fcb; /*Q0*/ move16(); idx = sub( NB_RATE_POSS, 2 ); @@ -889,13 +889,13 @@ void tdm_bit_alloc( BREAK; } } - *total_brate_sec = L_add( *total_brate_sec, sub( fast_FCB_rates_2sfr[idx], tmp_rate ) ); + *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 ); + *total_brate_sec = L_add( *total_brate_sec, 100 ); /*Q0*/ move32(); } } @@ -903,11 +903,11 @@ IF( EQ_32( L_sub( element_brate_wo_meta, *total_brate_sec ), ACELP_13k20 ) ) 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 ); + *total_brate_sec = L_sub( *total_brate_sec, 100 ); /*Q0*/ move32(); } -*total_brate_pri = L_sub( element_brate_wo_meta, *total_brate_sec ); +*total_brate_pri = L_sub( element_brate_wo_meta, *total_brate_sec ); /*Q0*/ move32(); return; @@ -974,8 +974,8 @@ void td_stereo_param_updt_fx( Word16 tdm_lspQ_PCh_fx[], /* o : Q LSPs for primary channel Q15 */ Word16 tdm_lsfQ_PCh_fx[], /* o : Q LSFs for primary channel Qlog2(2.56) */ Word16 tdm_Pri_pitch_buf_fx[], /* o : pitch values for primary channel Q6 */ - const Word16 flag_ACELP16k, /* i : ACELP@16kHz flag */ - const Word16 tdm_use_IAWB_Ave_lpc /* i : flag to indicate the usage of mean inactive LP coefficients */ + const Word16 flag_ACELP16k, /* i : ACELP@16kHz flag Q0*/ + const Word16 tdm_use_IAWB_Ave_lpc /* i : flag to indicate the usage of mean inactive LP coefficients Q0*/ #ifndef FIX_798_WRONG_CPY_OF_PITCH , Word16 Q_var @@ -987,19 +987,19 @@ void td_stereo_param_updt_fx( IF( EQ_16( tdm_use_IAWB_Ave_lpc, 1 ) ) { /*not being assert*/ - Copy( IAWB_Ave_fx, tdm_lsfQ_PCh_fx, M ); + Copy( IAWB_Ave_fx, tdm_lsfQ_PCh_fx, M ); /*Qlog2(2.56)*/ lsf2lsp_fx( tdm_lsfQ_PCh_fx, tdm_lspQ_PCh_fx, M, INT_FS_12k8 ); } ELSE IF( EQ_16( flag_ACELP16k, 1 ) ) { - Copy( lsp_old_PCh_fx, tdm_lspQ_PCh_fx, M ); + Copy( lsp_old_PCh_fx, tdm_lspQ_PCh_fx, M ); /*Q15*/ lsp_convert_poly_fx( tdm_lspQ_PCh_fx, L_FRAME, 0 ); lsp2lsf_fx( tdm_lspQ_PCh_fx, tdm_lsfQ_PCh_fx, M, INT_FS_12k8 ); } ELSE { - Copy( lsp_old_PCh_fx, tdm_lspQ_PCh_fx, M ); - Copy( lsf_old_PCh_fx, tdm_lsfQ_PCh_fx, M ); + Copy( lsp_old_PCh_fx, tdm_lspQ_PCh_fx, M ); /*Q15*/ + Copy( lsf_old_PCh_fx, tdm_lsfQ_PCh_fx, M ); /*Qlog2(2.56)*/ } #ifdef FIX_798_WRONG_CPY_OF_PITCH IF( EQ_16( flag_ACELP16k, 1 ) ) @@ -1009,14 +1009,14 @@ void td_stereo_param_updt_fx( move16(); FOR( i = 0; i < NB_SUBFR; i++ ) { - tmp16 = mult_r( pitch_buf_PCh_fx[i], mult_factor ); /* Convert 16kHz to 12.8 kHz pitch values */ - tdm_Pri_pitch_buf_fx[i] = s_max( tmp16, PIT_MIN << 6 ); /* pitch is represented in Q6*/ + tmp16 = mult_r( pitch_buf_PCh_fx[i], mult_factor ); /* Convert 16kHz to 12.8 kHz pitch values Q6*/ + tdm_Pri_pitch_buf_fx[i] = s_max( tmp16, shl( PIT_MIN, 6 ) ); /* pitch is represented in Q6*/ move16(); } } ELSE { - Copy( pitch_buf_PCh_fx, tdm_Pri_pitch_buf_fx, NB_SUBFR ); + Copy( pitch_buf_PCh_fx, tdm_Pri_pitch_buf_fx, NB_SUBFR ); /*Q6*/ } #else @@ -1058,17 +1058,17 @@ void td_stereo_param_updt_fx( *-------------------------------------------------------------------*/ static void tdm_SCh_LSF_intra_pred_zero_bits_fx( - const Word16 *tdm_lsfQ_PCh_fx, /* i : primary channel LSFs */ - Word16 *pred_lsf_SCh_fx, /* o : predicted secondary channel LSFs */ - const Word16 *lsf_mean_fx, /* i : secondary channel mean LSFs */ - const Word16 beta_fx /* i : pull to average beta factor */ + const Word16 *tdm_lsfQ_PCh_fx, /* i : primary channel LSFs x2.56*/ + Word16 *pred_lsf_SCh_fx, /* o : predicted secondary channel LSFs x2.56*/ + const Word16 *lsf_mean_fx, /* i : secondary channel mean LSFs x2.56*/ + const Word16 beta_fx /* i : pull to average beta factor Q15*/ ) { Word16 i; /* pulling the LSFs closer to the average */ FOR( i = 0; i < M; i++ ) { - pred_lsf_SCh_fx[i] = add( mult_r( beta_fx, tdm_lsfQ_PCh_fx[i] ), mult_r( sub( 32767, beta_fx ), lsf_mean_fx[i] ) ); + pred_lsf_SCh_fx[i] = add( mult_r( beta_fx, tdm_lsfQ_PCh_fx[i] ), mult_r( sub( 32767 /*1.0f in Q15*/, beta_fx ), lsf_mean_fx[i] ) ); move16(); } @@ -1107,10 +1107,10 @@ static void tdm_SCh_LSF_intra_pred_zero_bits( *-------------------------------------------------------------------*/ static void tdm_SCh_LSF_intra_pred_tri_diag_mat_fx( - Word16 *lsf_SCh_fx, /* i/o: secondary channel LSFs */ - const Word16 *lsf_mean_in_fx, /* i : secondary channel mean LSFs (in) */ - const Word16 *lsf_mean_out_fx, /* i : secondary channel mean LSFs (out) */ - const Word16 *prd_diag_3_fx /* i : secondary channel mean LSFs */ + Word16 *lsf_SCh_fx, /* i/o: secondary channel LSFs x2.56*/ + const Word16 *lsf_mean_in_fx, /* i : secondary channel mean LSFs (in) x2.56*/ + const Word16 *lsf_mean_out_fx, /* i : secondary channel mean LSFs (out) x2.56*/ + const Word16 *prd_diag_3_fx /* i : secondary channel mean LSFs Q15*/ ) { Word16 i; @@ -1120,16 +1120,16 @@ static void tdm_SCh_LSF_intra_pred_tri_diag_mat_fx( Word16 *lsf_tmp_ptr2_fx; Word16 *lsf_SCh_ptr_fx; - prd_ptr_fx = prd_diag_3_fx; + prd_ptr_fx = prd_diag_3_fx; /*Q15*/ v_sub_16( lsf_SCh_fx, lsf_mean_in_fx, lsf_tmp_fx, M ); - lsf_tmp_ptr1_fx = lsf_tmp_fx; + lsf_tmp_ptr1_fx = lsf_tmp_fx; /*x2.56*/ - lsf_SCh_ptr_fx = lsf_SCh_fx; + lsf_SCh_ptr_fx = lsf_SCh_fx; /*x2.56*/ - lsf_tmp_ptr2_fx = lsf_tmp_ptr1_fx; + lsf_tmp_ptr2_fx = lsf_tmp_ptr1_fx; /*x2.56*/ *lsf_SCh_ptr_fx = mult_r( *lsf_tmp_ptr1_fx++, *prd_ptr_fx++ ); // Q2.56 + 15 -15 move16(); @@ -1142,23 +1142,23 @@ static void tdm_SCh_LSF_intra_pred_tri_diag_mat_fx( lsf_tmp_ptr1_fx = lsf_tmp_ptr2_fx; // Q2.56 *lsf_SCh_ptr_fx = mult_r( *lsf_tmp_ptr1_fx++, *prd_ptr_fx++ ); // Q2.56 + 15 -15 move16(); - lsf_tmp_ptr2_fx = lsf_tmp_ptr1_fx; - *lsf_SCh_ptr_fx = add( *lsf_SCh_ptr_fx, mult_r( ( *lsf_tmp_ptr1_fx++ ), ( *prd_ptr_fx++ ) ) ); + lsf_tmp_ptr2_fx = lsf_tmp_ptr1_fx; /*x2.56*/ + *lsf_SCh_ptr_fx = add( *lsf_SCh_ptr_fx, mult_r( ( *lsf_tmp_ptr1_fx++ ), ( *prd_ptr_fx++ ) ) ); /*x2.56*/ move16(); - ( *lsf_SCh_ptr_fx ) = add( *lsf_SCh_ptr_fx, mult_r( ( *lsf_tmp_ptr1_fx ), ( *prd_ptr_fx++ ) ) ); + ( *lsf_SCh_ptr_fx ) = add( *lsf_SCh_ptr_fx, mult_r( ( *lsf_tmp_ptr1_fx ), ( *prd_ptr_fx++ ) ) ); /*x2.56*/ move16(); lsf_SCh_ptr_fx++; } - lsf_tmp_ptr1_fx = lsf_tmp_ptr2_fx; - *lsf_SCh_ptr_fx = mult_r( ( *lsf_tmp_ptr1_fx ), ( *prd_ptr_fx ) ); + lsf_tmp_ptr1_fx = lsf_tmp_ptr2_fx; /*x2.56*/ + *lsf_SCh_ptr_fx = mult_r( ( *lsf_tmp_ptr1_fx ), ( *prd_ptr_fx ) ); /*x2.56*/ move16(); lsf_tmp_ptr1_fx++; prd_ptr_fx++; - *lsf_SCh_ptr_fx = add( mult_r( ( *lsf_tmp_ptr1_fx ), ( *prd_ptr_fx ) ), *lsf_SCh_ptr_fx ); + *lsf_SCh_ptr_fx = add( mult_r( ( *lsf_tmp_ptr1_fx ), ( *prd_ptr_fx ) ), *lsf_SCh_ptr_fx ); /*x2.56*/ move16(); - v_add_16( lsf_SCh_fx, lsf_mean_out_fx, lsf_SCh_fx, M ); + v_add_16( lsf_SCh_fx, lsf_mean_out_fx, lsf_SCh_fx, M ); /*x2.56*/ return; } @@ -1220,9 +1220,9 @@ static void tdm_SCh_LSF_intra_pred_tri_diag_mat( *-------------------------------------------------------------------*/ void tdm_SCh_LSF_intra_pred_fx( - const Word32 element_brate, /* i : element bitrate */ - const Word16 *tdm_lsfQ_PCh_fx, /* i : primary channel LSFs */ - Word16 *pred_lsf_SCh_fx /* o : predicted secondary channel LSFs */ + const Word32 element_brate, /* i : element bitrate Q0*/ + const Word16 *tdm_lsfQ_PCh_fx, /* i : primary channel LSFs x2.56*/ + Word16 *pred_lsf_SCh_fx /* o : predicted secondary channel LSFs x2.56*/ ) { Word16 fixed_beta; @@ -1311,11 +1311,11 @@ void tdm_SCh_LSF_intra_pred( *-------------------------------------------------------------------*/ static void tdm_SCh_LSF_intra_pred_one_bit_dec_fx( - const Word16 *tdm_lsfQ_PCh_fx, /* i : primary channel LSFs */ - Word16 *pred_lsf_SCh_fx, /* o : predicted secondary channel LSFs */ - const Word16 *lsf_mean_fx, /* i : secondary channel mean LSFs */ - const Word16 *Beta_Q_x_fx, /* i : beta quantization values */ - const Word16 beta_index_fx /* i : the quantization bits for beta (-1 if beta fixed)*/ + const Word16 *tdm_lsfQ_PCh_fx, /* i : primary channel LSFs x2.56*/ + Word16 *pred_lsf_SCh_fx, /* o : predicted secondary channel LSFs x2.56*/ + const Word16 *lsf_mean_fx, /* i : secondary channel mean LSFs x2.56*/ + const Word16 *Beta_Q_x_fx, /* i : beta quantization values Q15*/ + const Word16 beta_index_fx /* i : the quantization bits for beta (-1 if beta fixed) Q0*/ ) { Word16 i; @@ -1327,7 +1327,7 @@ static void tdm_SCh_LSF_intra_pred_one_bit_dec_fx( /* pulling the LSFs closer to the avergae */ FOR( i = 0; i < M; i++ ) { - pred_lsf_SCh_fx[i] = add( mult_r( beta_fx, tdm_lsfQ_PCh_fx[i] ), mult_r( sub( 32767, beta_fx ), lsf_mean_fx[i] ) ); + pred_lsf_SCh_fx[i] = add( mult_r( beta_fx, tdm_lsfQ_PCh_fx[i] ), mult_r( sub( 32767 /*1.0f in Q15*/, beta_fx ), lsf_mean_fx[i] ) ); /*x2.56*/ move16(); } @@ -1371,13 +1371,13 @@ static void tdm_SCh_LSF_intra_pred_one_bit_dec( *-------------------------------------------------------------------*/ static void tdm_SCh_LSF_intra_pred_one_bit_enc_fx( - const Word16 *lsf_SCh_fx, /* i : secondary channel LSFs */ - const Word16 *tdm_lsfQ_PCh_fx, /* i : primary channel LSFs */ - Word16 *pred_lsf_SCh_fx, /* o : predicted secondary channel LSFs */ - const Word16 *lsf_mean_fx, /* i : secondary channel mean LSFs */ - const Word16 *lsf_wgts_new_fx, /* i : Improved wgts for LSFs */ - const Word16 *Beta_Q_x_fx, /* i : beta quantization values */ - Word16 *beta_index /* o : the quantization bits for beta (-1 if beta fixed) */ + const Word16 *lsf_SCh_fx, /* i : secondary channel LSFs x2.56*/ + const Word16 *tdm_lsfQ_PCh_fx, /* i : primary channel LSFs x2.56*/ + Word16 *pred_lsf_SCh_fx, /* o : predicted secondary channel LSFs x2.56*/ + const Word16 *lsf_mean_fx, /* i : secondary channel mean LSFs x2.56*/ + const Word16 *lsf_wgts_new_fx, /* i : Improved wgts for LSFs Q8*/ + const Word16 *Beta_Q_x_fx, /* i : beta quantization values Q15*/ + Word16 *beta_index /* o : the quantization bits for beta (-1 if beta fixed) Q0*/ ) { Word16 i; @@ -1390,23 +1390,23 @@ static void tdm_SCh_LSF_intra_pred_one_bit_enc_fx( FOR( i = 0; i < M; i++ ) { - A_temp_fx[i] = sub( lsf_SCh_fx[i], lsf_mean_fx[i] ); + A_temp_fx[i] = sub( lsf_SCh_fx[i], lsf_mean_fx[i] ); /*x2.56*/ move16(); - B_temp_fx[i] = sub( lsf_mean_fx[i], tdm_lsfQ_PCh_fx[i] ); + B_temp_fx[i] = sub( lsf_mean_fx[i], tdm_lsfQ_PCh_fx[i] ); /*x2.56*/ move16(); } FOR( i = 0; i < M; i++ ) { - Word32 wgt_A_temp = Mpy_32_16_1( L_mult( A_temp_fx[i], A_temp_fx[i] ), lsf_wgts_new_fx[i] ); // - Word32 wgt_B_temp = Mpy_32_16_1( L_mult( B_temp_fx[i], B_temp_fx[i] ), lsf_wgts_new_fx[i] ); - Word32 wgt_AB_temp = Mpy_32_16_1( L_mult( A_temp_fx[i], B_temp_fx[i] ), lsf_wgts_new_fx[i] ); - Word32 Beta_Q_x0 = L_mult( Beta_Q_x_fx[0], Beta_Q_x_fx[0] ); // Q31 - Word32 Beta_Q_x1 = L_mult( Beta_Q_x_fx[1], Beta_Q_x_fx[1] ); // Q31 + Word32 wgt_A_temp = Mpy_32_16_1( L_mult( A_temp_fx[i], A_temp_fx[i] ), lsf_wgts_new_fx[i] ); /*2*(x2.56)-7*/ + Word32 wgt_B_temp = Mpy_32_16_1( L_mult( B_temp_fx[i], B_temp_fx[i] ), lsf_wgts_new_fx[i] ); /*2*(x2.56)-7*/ + Word32 wgt_AB_temp = Mpy_32_16_1( L_mult( A_temp_fx[i], B_temp_fx[i] ), lsf_wgts_new_fx[i] ); /*2*(x2.56)-7*/ + Word32 Beta_Q_x0 = L_mult( Beta_Q_x_fx[0], Beta_Q_x_fx[0] ); // Q31 + Word32 Beta_Q_x1 = L_mult( Beta_Q_x_fx[1], Beta_Q_x_fx[1] ); // Q31 - WD_fx[0] = L_add( WD_fx[0], L_add( L_add( wgt_A_temp, Mpy_32_16_1( L_shl( wgt_AB_temp, 1 ), Beta_Q_x_fx[0] ) ), Mpy_32_32( wgt_B_temp, Beta_Q_x0 ) ) ); + WD_fx[0] = L_add( WD_fx[0], L_add( L_add( wgt_A_temp, Mpy_32_16_1( L_shl( wgt_AB_temp, 1 ), Beta_Q_x_fx[0] ) ), Mpy_32_32( wgt_B_temp, Beta_Q_x0 ) ) ); /*2*(x2.56)-7*/ move32(); - WD_fx[1] = L_add( WD_fx[1], L_add( L_add( wgt_A_temp, Mpy_32_16_1( L_shl( wgt_AB_temp, 1 ), Beta_Q_x_fx[1] ) ), Mpy_32_32( wgt_B_temp, Beta_Q_x1 ) ) ); + WD_fx[1] = L_add( WD_fx[1], L_add( L_add( wgt_A_temp, Mpy_32_16_1( L_shl( wgt_AB_temp, 1 ), Beta_Q_x_fx[1] ) ), Mpy_32_32( wgt_B_temp, Beta_Q_x1 ) ) ); /*2*(x2.56)-7*/ move32(); } @@ -1484,32 +1484,32 @@ static void tdm_SCh_LSF_intra_pred_one_bit_enc( *-------------------------------------------------------------------*/ void tdm_SCh_lsf_reuse_fx( - const Word16 enc_dec, /* i : encoder/decoder flag */ - const Word32 element_brate, /* i : element bitrate */ - Word16 lsf_new_fx[M], /* i/o: LSFs at the end of the frame */ - Word16 lsp_new_fx[M], /* i/o: LSPs at the end of the frame */ - const Word16 tdm_lsfQ_PCh_fx[M], /* i : primary channel LSFs */ - const Word16 lsf_wgts_fx[M], /* i : LSF weights */ - Word16 *beta_index /* i/o: quantization index */ + const Word16 enc_dec, /* i : encoder/decoder flag Q0*/ + const Word32 element_brate, /* i : element bitrate Q0*/ + Word16 lsf_new_fx[M], /* i/o: LSFs at the end of the frame x2.56*/ + Word16 lsp_new_fx[M], /* i/o: LSPs at the end of the frame Q15*/ + const Word16 tdm_lsfQ_PCh_fx[M], /* i : primary channel LSFs x2.56*/ + const Word16 lsf_wgts_fx[M], /* i : LSF weights Q8*/ + Word16 *beta_index /* i/o: quantization index Q0*/ ) { const Word16 *Beta_Q1bit_re_use_fx; IF( LE_32( element_brate, IVAS_13k2 ) ) { - Beta_Q1bit_re_use_fx = tdm_Beta_Q1bit_re_use_13k2_fx; + Beta_Q1bit_re_use_fx = tdm_Beta_Q1bit_re_use_13k2_fx; /*Q15*/ } ELSE IF( LE_32( element_brate, IVAS_16k4 ) ) { - Beta_Q1bit_re_use_fx = tdm_Beta_Q1bit_re_use_16k4_fx; + Beta_Q1bit_re_use_fx = tdm_Beta_Q1bit_re_use_16k4_fx; /*Q15*/ } ELSE IF( LE_32( element_brate, IVAS_32k ) ) { - Beta_Q1bit_re_use_fx = tdm_Beta_Q1bit_re_use_24k4_32k_fx; + Beta_Q1bit_re_use_fx = tdm_Beta_Q1bit_re_use_24k4_32k_fx; /*Q15*/ } ELSE { - Beta_Q1bit_re_use_fx = tdm_Beta_Q1bit_re_use_48k_fx; + Beta_Q1bit_re_use_fx = tdm_Beta_Q1bit_re_use_48k_fx; /*Q15*/ } IF( enc_dec == ENC ) diff --git a/lib_com/prot.h b/lib_com/prot.h index 93b3f3a90..7564cdc48 100644 --- a/lib_com/prot.h +++ b/lib_com/prot.h @@ -965,6 +965,7 @@ void CNG_exc( const int16_t element_mode /* i : IVAS Element mode */ ); +#ifndef IVAS_FLOAT_FIXED void cng_params_upd( const float lsp_new[], /* i : LSP aprameters */ const float exc2[], /* i : current enhanced excitation */ @@ -982,6 +983,7 @@ void cng_params_upd( const int16_t element_mode, /* i : Element mode */ const int16_t bwidth /* i : audio bandwidth */ ); +#endif void cng_params_postupd( const int16_t ho_circ_ptr, /* i : pointer for CNG averaging buffers */ @@ -4011,6 +4013,7 @@ void dtx_hangover_control( const float lsp_new[M] /* i : current frame LSPs */ ); +#ifndef IVAS_FLOAT_FIXED void updt_enc( Encoder_State *st, /* i/o: state structure */ const float *old_exc, /* i : buffer of excitation */ @@ -4021,6 +4024,7 @@ void updt_enc( const float *lsp_new, /* i : current frame LSP vector */ const float *old_bwe_exc /* o : buffer of excitation for SWB TBE */ ); +#endif void updt_enc_common( Encoder_State *st /* i/o: encoder state structure */ diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index 1fac038c8..1fa1b3549 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -3157,102 +3157,108 @@ Word16 get_tbe_bits_fx( // pvq_com_fx UWord32 intLimCDivPos_fx( - UWord32 NUM, - Word16 DEN ); + UWord32 NUM, /* Qx */ + Word16 DEN /* Q0 */ +); Word16 shrtCDivSignedApprox( - const Word16 num, - const Word16 den ); + const Word16 num, /* Q0 */ + const Word16 den /* Q0 */ +); void obtainEnergyQuantizerDensity_fx( - const Word16 L, - const Word16 R, - Word16 *Density ); + const Word16 L, /* i : left vector energy Q0*/ + const Word16 R, /* i : right vector energy Q0*/ + Word16 *Density /* o : quantizer density Q0*/ +); void dsDirac2Dirac_fx( - const Word16 dsDiracIndex, - Word16 *diracs ); + const Word16 dsDiracIndex, /* Q0 */ + Word16 *diracs /* Q0 */ +); void dsDiracPerQuanta_fx( - const Word16 td, - const Word16 t_quanta, - const Word16 dsm, - const unsigned char *const *frQuanta, - Word16 *DsIdx ); + const Word16 td, /* i : Length of vector segment Q0*/ + const Word16 t_quanta, /* i : Assigned number of quanta Q0*/ + const Word16 dsm, /* i : Conservative rounding flag Q0*/ + const unsigned char *const *frQuanta, /* i : Quanta lookup table */ + Word16 *DsIdx /* o : Lookup table index Q0*/ +); void QuantaPerDsDirac_fx( - const Word16 td, /* i : Length of vector segment */ - const Word16 dsDiracIndex, /* i : Quanta table index */ - const unsigned char *const *dimFrQuanta, /* i : Quanta lookup table */ - Word16 *Quanta /* i : Quanta */ + const Word16 td, /* i : Length of vector segment Q0*/ + const Word16 dsDiracIndex, /* i : Quanta table index Q0*/ + const unsigned char *const *dimFrQuanta, /* i : Quanta lookup table */ + Word16 *Quanta /* i : Quanta Q0*/ ); void conservativeL1Norm_fx( - const Word16 L, /* i : Length of vector segment */ - const Word16 Qvec, /* i : Assigned number of quanta */ - const Word16 Fcons, /* i : Conservative rounding flag */ - const Word16 Qavail, /* i : Input quanta remaining */ - const Word16 Qreserv, /* i : Input quanta in reservoir */ - const Word16 Dspec, /* i : assigned diracs from bitalloc */ - Word16 *Dvec, /* o : actual number of diracs */ - Word16 *Qspare, /* o : Output quanta remaining */ - Word16 *Qreservplus, /* o : Output quanta in reservoir */ - Word16 *Dspecplus /* o : Output number of diracs */ + const Word16 L, /* i : Length of vector segment Q0*/ + const Word16 Qvec, /* i : Assigned number of quanta Q0*/ + const Word16 Fcons, /* i : Conservative rounding flag Q0*/ + const Word16 Qavail, /* i : Input quanta remaining Q0*/ + const Word16 Qreserv, /* i : Input quanta in reservoir Q0*/ + const Word16 Dspec, /* i : assigned diracs from bitalloc Q0*/ + Word16 *Dvec, /* o : actual number of diracs Q0*/ + Word16 *Qspare, /* o : Output quanta remaining Q0*/ + Word16 *Qreservplus, /* o : Output quanta in reservoir Q0*/ + Word16 *Dspecplus /* o : Output number of diracs Q0*/ ); void bandBitsAdjustment_fx( - const Word16 Brc, /* i : Current number of read quanta in range coder */ - const UWord32 INTrc, /* i : Range coder state */ - const Word16 Bavail, /* i : Available number of quanta */ - const Word16 Nbands, /* i : Number of bands */ - const Word16 D, /* i : Remaining number of bands to encode */ - const Word16 L, /* i : Size of current band */ - const Word16 Bband, /* i : Quanta allocation for current band */ - const Word16 Breserv, /* i : Quanta reservoir */ - Word16 *Bband_adj, /* o : Actual used number of quanta */ - Word16 *Brem, /* o : Quanta remaining */ - Word16 *Breservplus /* o : Quanta pool size */ + const Word16 Brc, /* i : Current number of read quanta in range coder Q0*/ + const UWord32 INTrc, /* i : Range coder state Q0*/ + const Word16 Bavail, /* i : Available number of quanta Q3*/ + const Word16 Nbands, /* i : Number of bands Q0*/ + const Word16 D, /* i : Remaining number of bands to encode Q0*/ + const Word16 L, /* i : Size of current band Q0*/ + const Word16 Bband, /* i : Quanta allocation for current band Q0*/ + const Word16 Breserv, /* i : Quanta reservoir Q0*/ + Word16 *Bband_adj, /* o : Actual used number of quanta Q0*/ + Word16 *Brem, /* o : Quanta remaining Q0*/ + Word16 *Breservplus /* o : Quanta pool size Q0*/ ); void densityAngle2RmsProjDec_fx( - const Word16 D, /* i : density */ - const Word16 indexphi, /* i : decoded index from AR dec */ - Word16 *oppQ15, /* o : opposite */ - Word16 *nearQ15, /* o : near */ - Word16 *oppRatioQ3 /* o : ratio */ + const Word16 D, /* i : density Q0*/ + const Word16 indexphi, /* i : decoded index from AR dec Q0*/ + Word16 *oppQ15, /* o : opposite Q15*/ + Word16 *nearQ15, /* o : near Q15*/ + Word16 *oppRatioQ3 /* o : ratio Q3*/ ); void densityAngle2RmsProjEnc_fx( - const Word16 D, /* i : density */ - const Word16 phiQ14uq, /* i : angle */ - Word16 *indexphi, /* o : index */ - Word16 *oppQ15, /* o : opposite */ - Word16 *nearQ15, /* o : near */ - Word16 *oppRatioQ3 /* o : ratio */ + const Word16 D, /* i : density Q0*/ + const Word16 phiQ14uq, /* i : angle Q14*/ + Word16 *indexphi, /* o : index Q0*/ + Word16 *oppQ15, /* o : opposite Q15*/ + Word16 *nearQ15, /* o : near Q15*/ + Word16 *oppRatioQ3 /* o : ratio Q3*/ ); void NearOppSplitAdjustment_fx( - const Word16 qband, - const Word16 qzero, - const Word16 Qac, - const UWord32 INTac, - const Word16 qglobal, - const Word16 FlagCons, - const Word16 Np, - const Word16 Nhead, - const Word16 Ntail, - const Word16 Nnear, - const Word16 Nopp, - Word16 oppRQ3, - Word16 *qnear, - Word16 *qopp, - Word16 *qglobalupd ); + const Word16 qband, /* i : quanta for current band Q0*/ + const Word16 qzero, /* i : range coder finalization quanta Q0*/ + const Word16 Qac, /* i : range coder current quanta Q0*/ + const UWord32 INTac, /* i : range coder state Q0*/ + const Word16 qglobal, /* i : quanta input Q0*/ + const Word16 FlagCons, /* i : conservative rounding flag Q0*/ + const Word16 Np, /* i : number of parts Q0*/ + const Word16 Nhead, /* i : first part Q0*/ + const Word16 Ntail, /* i : remaining parts Q0*/ + const Word16 Nnear, /* i : length of near component Q0*/ + const Word16 Nopp, /* i : length of opposite component Q0*/ + Word16 oppRQ3, /* i : ratio Q0*/ + Word16 *qnear, /* o : quantized near Q0*/ + Word16 *qopp, /* o : quantized opposite Q0*/ + Word16 *qglobalupd /* o : quanta remaining Q0*/ +); void apply_gain_fx( - const Word16 *ord, /* i : Indices for energy order */ - const Word16 *band_start, /* i : Sub band start indices */ - const Word16 *band_end, /* i : Sub band end indices */ - const Word16 num_sfm, /* i : Number of bands */ + const Word16 *ord, /* i : Indices for energy order Q0 */ + const Word16 *band_start, /* i : Sub band start indices Q0 */ + const Word16 *band_end, /* i : Sub band end indices Q0 */ + const Word16 num_sfm, /* i : Number of bands Q0 */ const Word16 *gains, /* i : Band gain vector Q12 */ Word16 *xq /* i/o: Float synthesis / Gain adjusted synth Q15/Q12 */ ); @@ -3267,25 +3273,27 @@ void fine_gain_quant_fx( ); void srt_vec_ind16_fx( - const Word16 *linear, /* linear i */ - Word16 *srt, /* sorted output*/ - Word16 *I, /* index for sorted output */ - Word16 length ); + const Word16 *linear, /* linear input Q3*/ + Word16 *srt, /* sorted output Q3*/ + Word16 *I, /* index for sorted output Q0*/ + Word16 length /* Q0 */ +); -Word16 atan2_fx( - const Word32, - const Word32 ); +Word16 atan2_fx( /* o: Angle between 0 and PI/2 radian (Q14) */ + const Word32 y, /* i : near side (Argument must be positive) (Q15) */ + const Word32 x /* i : opposite side (Q15) */ +); // rang_com_fx.c -Word16 rc_get_bits2_fx( /* o: Number of bits needed */ - const Word16 N, /* i: Number of bits currently used */ - const UWord32 range /* i: Range of range coder */ +Word16 rc_get_bits2_fx( /* o: Number of bits needed Q0*/ + const Word16 N, /* i: Number of bits currently used Q0*/ + const UWord32 range /* i: Range of range coder Q0*/ ); void rangeCoderFinalizationFBits_fx( - Word16 Brc, /* i : Current number of decoded bits */ - UWord32 INTrc, /* i : Range coder state */ - Word16 *FBits /* i : Fractional finalization bits */ + Word16 Brc, /* i : Current number of decoded bits Q0*/ + UWord32 INTrc, /* i : Range coder state Q0*/ + Word16 *FBits /* i : Fractional finalization bits Q0*/ ); // wi_fx.c @@ -4848,19 +4856,19 @@ void fine_gain_pred_fx( ); void fine_gain_quant_fx( - BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - const Word16 *ord, /* i : Indices for energy order */ - const Word16 num_sfm, /* i : Number of bands */ - const Word16 *gain_bits, /* i : Gain adjustment bits per sub band */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + const Word16 *ord, /* i : Indices for energy order Q0 */ + const Word16 num_sfm, /* i : Number of bands Q0 */ + const Word16 *gain_bits, /* i : Gain adjustment bits per sub band Q0 */ Word16 *fg_pred, /* i/o: Predicted gains / Corrected gains Q12 */ const Word16 *gopt /* i : Optimal gains Q12 */ ); #ifdef IVAS_FLOAT_FIXED void fine_gain_quant_ivas_fx( - BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - const Word16 *ord, /* i : Indices for energy order */ - const Word16 num_sfm, /* i : Number of bands */ - const Word16 *gain_bits, /* i : Gain adjustment bits per sub band */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + const Word16 *ord, /* i : Indices for energy order Q0 */ + const Word16 num_sfm, /* i : Number of bands Q0 */ + const Word16 *gain_bits, /* i : Gain adjustment bits per sub band Q0 */ Word16 *fg_pred, /* i/o: Predicted gains / Corrected gains Q12 */ const Word16 *gopt /* i : Optimal gains Q12 */ ); @@ -5286,10 +5294,10 @@ void Inverse_Transform( // recovernorm void recovernorm_fx( - const Word16 *idxbuf, /* i : reordered quantization indices */ - Word16 *ynrm, /* o : recovered quantization indices */ - Word16 *normqlg2, /* o : recovered quantized norms */ - const Word16 nb_sfm /* i : number of SFMs */ + const Word16 *idxbuf, /* i : reordered quantization indices Q0*/ + Word16 *ynrm, /* o : recovered quantization indices Q0*/ + Word16 *normqlg2, /* o : recovered quantized norms Q0*/ + const Word16 nb_sfm /* i : number of SFMs Q0*/ ); // tcq_poition_qeith.c @@ -6897,23 +6905,23 @@ void re8_decode_base_index_fx( const Word16 n, UWord16 I, Word16 *x ); // re8_utils_fx.c void re8_k2y_fx( - const Word16 *k, /* i : Voronoi index k[0..7] */ - const Word16 m, /* i : Voronoi modulo (m = 2^r = 1<=2) */ - Word16 *y /* o : 8-dimensional point y[0..7] in RE8 */ + const Word16 *k, /* i : Voronoi index k[0..7] Q0*/ + const Word16 m, /* i : Voronoi modulo (m = 2^r = 1<=2) Q0*/ + Word16 *y /* o : 8-dimensional point y[0..7] in RE8 Q0*/ ); void re8_vor_fx( - const Word16 y[], /* i : point in RE8 (8-dimensional integer vector) */ - Word16 *n, /* o : codebook number n=0,2,3,4,... (scalar integer) */ - Word16 k[], /* o : Voronoi index (integer vector of dimension 8) used only if n>4*/ - Word16 c[], /* o : codevector in Q0, Q2, Q3, or Q4 if n<=4, y=c */ - Word16 *ka /* o : identifier of absolute leader (to index c) */ + const Word16 y[], /* i : point in RE8 (8-dimensional integer vector) Q0*/ + Word16 *n, /* o : codebook number n=0,2,3,4,... (scalar integer) Q0*/ + Word16 k[], /* o : Voronoi index (integer vector of dimension 8) used only if n>4 Q0*/ + Word16 c[], /* o : codevector in Q0, Q2, Q3, or Q4 if n<=4, y=c Q0*/ + Word16 *ka /* o : identifier of absolute leader (to index c) Q0*/ ); // re8_PPV_fx.c void re8_PPV_fx( - const Word32 x[], /* i : point in R^8Q15 */ - Word16 y[] /* o : point in RE8 (8-dimensional integer vector) */ + const Word32 x[], /* i : point in R^8 Q15 */ + Word16 y[] /* o : point in RE8 (8-dimensional integer vector) Q0 */ ); // dec_pit_exc_fx.c diff --git a/lib_com/pvq_com_fx.c b/lib_com/pvq_com_fx.c index dc353b95c..4f3f61e99 100644 --- a/lib_com/pvq_com_fx.c +++ b/lib_com/pvq_com_fx.c @@ -10,22 +10,24 @@ /*! r: Approximate integer division for positive input using lookup table */ UWord32 intLimCDivPos_fx( - UWord32 NUM, - Word16 DEN ) + UWord32 NUM, /* Qx */ + Word16 DEN /* Q0 */ +) { UWord32 UL_ru, UL_rl; - Mpy_32_32_uu( UL_lshl( NUM, 1 ), intLimCDivInvDQ31[DEN], &UL_ru, &UL_rl ); + Mpy_32_32_uu( UL_lshl( NUM, 1 ), intLimCDivInvDQ31[DEN], &UL_ru, &UL_rl ); /* Qx */ return UL_ru; } /*! r: Approximate integer division for signed input using lookup table */ static Word32 intLimCDivSigned_fx( - Word32 NUM, - Word16 DEN ) + Word32 NUM, /* Qx */ + Word16 DEN /* Q0 */ +) { Word32 L_tmp; - L_tmp = intLimCDivPos_fx( L_abs( NUM ), DEN ); + L_tmp = intLimCDivPos_fx( L_abs( NUM ), DEN ); /* Qx */ if ( NUM < 0 ) { L_tmp = L_negate( L_tmp ); /* one op */ @@ -35,12 +37,13 @@ static Word32 intLimCDivSigned_fx( /*! r: Approximate integer division for negative input */ Word16 shrtCDivSignedApprox( - const Word16 num, - const Word16 den ) + const Word16 num, /* Q0 */ + const Word16 den /* Q0 */ +) { Word16 pool_part; - pool_part = extract_h( L_mult( negate( abs_s( num ) ), lim_neg_inv_tbl_fx[den] ) ); + pool_part = extract_h( L_mult( negate( abs_s( num ) ), lim_neg_inv_tbl_fx[den] ) ); /* Q0 */ /* neg_in always, positive out always, so that positive truncation(rounding) is used */ if ( num < 0 ) { @@ -50,11 +53,11 @@ Word16 shrtCDivSignedApprox( } static void nearProjQ15_fx( - const Word16 x, /* i : input coefficient */ - Word16 *result /* o : projection */ + const Word16 x, /* i : input coefficient Q15*/ + Word16 *result /* o : projection Q15*/ ) { - const Word16 a[4] = { 14967, -25518, 3415, 32351 }; + const Word16 a[4] = { 14967, -25518, 3415, 32351 }; /* Q15 */ move16(); move16(); move16(); @@ -63,12 +66,12 @@ static void nearProjQ15_fx( UWord16 lsb; b = L_deposit_l( a[0] ); - b = L_shl( L_deposit_l( add( a[1], extract_h( L_mult0( extract_l( b ), x ) ) ) ), 1 ); - Mpy_32_16_ss( b, x, &b, &lsb ); - b = L_add( L_deposit_l( a[2] ), b ); - Mpy_32_16_ss( b, x, &b, &lsb ); - b = L_add( L_deposit_l( a[3] ), b ); - *result = extract_l( b ); + b = L_shl( L_deposit_l( add( a[1], extract_h( L_mult0( extract_l( b ), x ) ) ) ), 1 ); /* Q15 */ + Mpy_32_16_ss( b, x, &b, &lsb ); /* Q15 */ + b = L_add( L_deposit_l( a[2] ), b ); /* Q15 */ + Mpy_32_16_ss( b, x, &b, &lsb ); /* Q15 */ + b = L_add( L_deposit_l( a[3] ), b ); /* Q15 */ + *result = extract_l( b ); /* Q15 */ move16(); return; } @@ -79,9 +82,9 @@ static void nearProjQ15_fx( * *-------------------------------------------------------------------*/ void obtainEnergyQuantizerDensity_fx( - const Word16 L, /* i : left vector energy */ - const Word16 R, /* i : right vector energy */ - Word16 *Density /* o : quantizer density */ + const Word16 L, /* i : left vector energy Q0*/ + const Word16 R, /* i : right vector energy Q0*/ + Word16 *Density /* o : quantizer density Q0*/ ) { Word16 Rnrg, den, n; @@ -89,21 +92,21 @@ void obtainEnergyQuantizerDensity_fx( den = sub( shl( L, 1 ), 1 ); IF( LE_16( den, 67 ) ) { - Rnrg = extract_l( intLimCDivPos_fx( L_deposit_l( R ), den ) ); + Rnrg = extract_l( intLimCDivPos_fx( L_deposit_l( R ), den ) ); /* Q0 */ } ELSE { n = norm_s( den ); move16(); - Rnrg = shr( div_s( R, shl( den, n ) ), sub( 15, n ) ); + Rnrg = shr( div_s( R, shl( den, n ) ), sub( 15, n ) ); /* n */ } - Rnrg = add( Rnrg, 28 ); + Rnrg = add( Rnrg, 28 ); /* Q0 */ - Rnrg = s_min( Rnrg, 56 ); - Rnrg = s_min( Rnrg, sub( R, 96 ) ); + Rnrg = s_min( Rnrg, 56 ); /* Q0 */ + Rnrg = s_min( Rnrg, sub( R, 96 ) ); /* Q0 */ Rnrg = s_max( Rnrg, 3 ); - *Density = obtainEnergyQuantizerDensity_f[Rnrg]; + *Density = obtainEnergyQuantizerDensity_f[Rnrg]; /* Q0 */ move16(); return; } @@ -115,21 +118,21 @@ void obtainEnergyQuantizerDensity_fx( * *-------------------------------------------------------------------*/ void dsDirac2Dirac_fx( - const Word16 dsDiracIndex, /* i : input index */ - Word16 *diracs /* o : number of diracs */ + const Word16 dsDiracIndex, /* i : input index Q0*/ + Word16 *diracs /* o : number of diracs Q0*/ ) { - *diracs = dsDiracsTab[dsDiracIndex]; + *diracs = dsDiracsTab[dsDiracIndex]; /* Q0 */ move16(); return; } void dsDiracPerQuanta_fx( - const Word16 td, /* i : Length of vector segment */ - const Word16 t_quanta, /* i : Assigned number of quanta */ - const Word16 dsm, /* i : Conservative rounding flag */ - const unsigned char *const *frQuanta, /* i : Quanta lookup table */ - Word16 *DsIdx /* o : Lookup table index */ + const Word16 td, /* i : Length of vector segment Q0*/ + const Word16 t_quanta, /* i : Assigned number of quanta Q0*/ + const Word16 dsm, /* i : Conservative rounding flag Q0*/ + const unsigned char *const *frQuanta, /* i : Quanta lookup table */ + Word16 *DsIdx /* o : Lookup table index Q0*/ ) { const unsigned char *sv; @@ -138,55 +141,55 @@ void dsDiracPerQuanta_fx( Word16 dsIndex; Word16 i; - sv = frQuanta[td]; + sv = frQuanta[td]; /* Q0 */ nsv = sv[0]; move16(); - t_quanta_o = sub( t_quanta, QUANTAQ3OFFSET ); + t_quanta_o = sub( t_quanta, QUANTAQ3OFFSET ); /* Q0 */ IF( GE_16( t_quanta_o, sv[nsv] ) ) { - *DsIdx = nsv; + *DsIdx = nsv; /* Q0 */ move16(); return; } IF( LE_16( t_quanta_o, sv[1] ) ) { - *DsIdx = 1; + *DsIdx = 1; /* Q0 */ move16(); return; } - dsIndex = shl( 1, frQuanta[0][td] ); - IF( GT_16( t_quanta_o, sv[shr( nsv, 1 )] ) ) + dsIndex = shl( 1, frQuanta[0][td] ); /* Q0 */ + IF( GT_16( t_quanta_o, sv[nsv >> 1] ) ) { - dsIndex = sub( nsv, dsIndex ); + dsIndex = sub( nsv, dsIndex ); /* Q0 */ } FOR( i = frQuanta[0][td] - 1; i >= 0; i-- ) { - dsIndex = add( dsIndex, shl( sub( shl( lshr( sub( sv[dsIndex], t_quanta_o ), 15 ), 1 ), 1 ), i ) ); + dsIndex = add( dsIndex, shl( sub( shl( lshr( sub( sv[dsIndex], t_quanta_o ), 15 ), 1 ), 1 ), i ) ); /* Q0 */ } - dsIndex = add( dsIndex, lshr( sub( sv[dsIndex], t_quanta_o ), 15 ) ); - dsIndex = sub( dsIndex, lshr( sub( 1, dsIndex ), 15 ) ); + dsIndex = add( dsIndex, lshr( sub( sv[dsIndex], t_quanta_o ), 15 ) ); /* Q0 */ + dsIndex = sub( dsIndex, lshr( sub( 1, dsIndex ), 15 ) ); /* Q0 */ if ( EQ_16( dsm, PVQ_CONS ) ) { - *DsIdx = dsIndex; + *DsIdx = dsIndex; /* Q0 */ move16(); return; } - *DsIdx = add( dsIndex, lshr( sub( add( sv[add( dsIndex, 1 )], sv[dsIndex] ), shl( t_quanta_o, 1 ) ), 15 ) ); + *DsIdx = add( dsIndex, lshr( sub( add( sv[dsIndex + 1], sv[dsIndex] ), shl( t_quanta_o, 1 ) ), 15 ) ); /* Q0 */ move16(); return; } void QuantaPerDsDirac_fx( - const Word16 td, /* i : Length of vector segment */ - const Word16 dsDiracIndex, /* i : Quanta table index */ - const unsigned char *const *dimFrQuanta, /* i : Quanta lookup table */ - Word16 *Quanta /* i : Quanta */ + const Word16 td, /* i : Length of vector segment Q0*/ + const Word16 dsDiracIndex, /* i : Quanta table index Q0*/ + const unsigned char *const *dimFrQuanta, /* i : Quanta lookup table */ + Word16 *Quanta /* i : Quanta Q0*/ ) { *Quanta = dimFrQuanta[td][dsDiracIndex]; @@ -196,22 +199,22 @@ void QuantaPerDsDirac_fx( *Quanta = -1; /* single op */ move16(); } - *Quanta = add( *Quanta, QUANTAQ3OFFSET ); + *Quanta = add( *Quanta, QUANTAQ3OFFSET ); /* Q0 */ move16(); return; } void conservativeL1Norm_fx( - const Word16 L, /* i : Length of vector segment */ - const Word16 Qvec, /* i : Assigned number of quanta */ - const Word16 Fcons, /* i : Conservative rounding flag */ - const Word16 Qavail, /* i : Input quanta remaining */ - const Word16 Qreserv, /* i : Input quanta in reservoir */ - const Word16 Dspec, /* i : assigned diracs from bitalloc */ - Word16 *Dvec, /* o : actual number of diracs */ - Word16 *Qspare, /* o : Output quanta remaining */ - Word16 *Qreservplus, /* o : Output quanta in reservoir */ - Word16 *Dspecplus /* o : Output number of diracs */ + const Word16 L, /* i : Length of vector segment Q0*/ + const Word16 Qvec, /* i : Assigned number of quanta Q0*/ + const Word16 Fcons, /* i : Conservative rounding flag Q0*/ + const Word16 Qavail, /* i : Input quanta remaining Q0*/ + const Word16 Qreserv, /* i : Input quanta in reservoir Q0*/ + const Word16 Dspec, /* i : assigned diracs from bitalloc Q0*/ + Word16 *Dvec, /* o : actual number of diracs Q0*/ + Word16 *Qspare, /* o : Output quanta remaining Q0*/ + Word16 *Qreservplus, /* o : Output quanta in reservoir Q0*/ + Word16 *Dspecplus /* o : Output number of diracs Q0*/ ) { @@ -221,7 +224,7 @@ void conservativeL1Norm_fx( frQuantaL = hBitsN[L]; - *Qreservplus = add( Qreserv, sub( Qvec, QUANTAQ3OFFSET ) ); + *Qreservplus = add( Qreserv, sub( Qvec, QUANTAQ3OFFSET ) ); /* Q0 */ move16(); dsDiracPerQuanta_fx( L, Qvec, Fcons, hBitsN, &Minit ); @@ -229,26 +232,26 @@ void conservativeL1Norm_fx( move16(); DO { - Qtestminus = (short) frQuantaL[Mprime]; + Qtestminus = (Word16) frQuantaL[Mprime]; move16(); - *Qspare = sub( Qavail, Qtestminus ); + *Qspare = sub( Qavail, Qtestminus ); /* Q0 */ move16(); - Mprime = sub( Mprime, 1 ); + Mprime = sub( Mprime, 1 ); /* Q0 */ } WHILE( ( Mprime >= 0 ) && LT_16( *Qspare, QUANTAQ3OFFSET ) ); if ( Mprime < 0 ) { - *Qspare = add( Qavail, QUANTAQ3OFFSET ); /* single op */ + *Qspare = add( Qavail, QUANTAQ3OFFSET ); /* single op Q0*/ move16(); } dsDirac2Dirac_fx( add( Mprime, 1 ), Dvec ); - *Dspecplus = add( Dspec, *Dvec ); + *Dspecplus = add( Dspec, *Dvec ); /* Q0 */ move16(); - *Qreservplus = sub( *Qreservplus, (short) frQuantaL[Minit] ); + *Qreservplus = sub( *Qreservplus, (Word16) frQuantaL[Minit] ); /* Q0 */ move16(); - *Qspare = sub( *Qspare, QUANTAQ3OFFSET ); + *Qspare = sub( *Qspare, QUANTAQ3OFFSET ); /* Q0 */ move16(); return; @@ -256,17 +259,17 @@ void conservativeL1Norm_fx( void bandBitsAdjustment_fx( - const Word16 Brc, /* i : Current number of read quanta in range coder */ - const UWord32 INTrc, /* i : Range coder state */ - const Word16 Bavail, /* i : Available number of quanta */ - const Word16 Nbands, /* i : Number of bands */ - const Word16 D, /* i : Remaining number of bands to encode */ - const Word16 L, /* i : Size of current band */ - const Word16 Bband, /* i : Quanta allocation for current band */ - const Word16 Breserv, /* i : Quanta reservoir */ - Word16 *Bband_adj, /* o : Actual used number of quanta */ - Word16 *Brem, /* o : Quanta remaining */ - Word16 *Breservplus /* o : Quanta pool size */ + const Word16 Brc, /* i : Current number of read quanta in range coder Q0*/ + const UWord32 INTrc, /* i : Range coder state Q0*/ + const Word16 Bavail, /* i : Available number of quanta Q3*/ + const Word16 Nbands, /* i : Number of bands Q0*/ + const Word16 D, /* i : Remaining number of bands to encode Q0*/ + const Word16 L, /* i : Size of current band Q0*/ + const Word16 Bband, /* i : Quanta allocation for current band Q0*/ + const Word16 Breserv, /* i : Quanta reservoir Q0*/ + Word16 *Bband_adj, /* o : Actual used number of quanta Q0*/ + Word16 *Brem, /* o : Quanta remaining Q0*/ + Word16 *Breservplus /* o : Quanta pool size Q0*/ ) { Word16 Btemp; @@ -277,25 +280,25 @@ void bandBitsAdjustment_fx( IF( LT_16( D, Nbands ) ) { - L_tmp = L_deposit_l( sub( Breserv, Bff ) ); - Btemp = extract_l( intLimCDivSigned_fx( L_tmp, s_min( D, 3 ) ) ); /* result always fits in Word16 */ - *Breservplus = add( Bband, Breserv ); + L_tmp = L_deposit_l( sub( Breserv, Bff ) ); /* Q0 */ + Btemp = extract_l( intLimCDivSigned_fx( L_tmp, s_min( D, 3 ) ) ); /* result always fits in Word16 Q0*/ + *Breservplus = add( Bband, Breserv ); /* Q0 */ move16(); } ELSE { Btemp = 0; move16(); - *Breservplus = add( Bband, Bff ); + *Breservplus = add( Bband, Bff ); /* Q0 */ move16(); } - *Bband_adj = s_min( extract_l( L_mult( L, 40 ) ), Bband ); + *Bband_adj = s_min( extract_l( L_mult( L, 40 ) ), Bband ); /* Q3 */ move16(); - *Brem = sub( Bavail, Bff ); + *Brem = sub( Bavail, Bff ); /* Q0 */ move16(); - *Bband_adj = s_min( *Brem, add( *Bband_adj, Btemp ) ); + *Bband_adj = s_min( *Brem, add( *Bband_adj, Btemp ) ); /* Q0 */ move16(); - *Bband_adj = s_max( 0, *Bband_adj ); + *Bband_adj = s_max( 0, *Bband_adj ); /* Q0 */ move16(); return; } @@ -321,38 +324,38 @@ static Word16 Ratio_base2Q11_fx( /* o : Q11 */ d = sub( ms, mc ); /* d in Q15 */ z = mult_r( z, d ); /* z in Q11 */ - result = add( z, shl( sub( nc, ns ), 11 ) ); + result = add( z, shl( sub( nc, ns ), 11 ) ); /* Q11 */ return result; } static void Ratio_rQ3_fx( - Word16 opp, /* i : opposite */ - Word16 near, /* i : near */ - Word16 *result /* o : ratio */ + Word16 opp, /* i : opposite Q15*/ + Word16 near, /* i : near Q15*/ + Word16 *result /* o : ratio Q3*/ ) { Word16 tmp; - tmp = add( 1 << 7, Ratio_base2Q11_fx( opp, near ) ); - *result = shr( tmp, 8 ); + tmp = add( 1 << 7, Ratio_base2Q11_fx( opp, near ) ); /* Q11 */ + *result = shr( tmp, 8 ); /* Q3 */ move16(); return; } void densityAngle2RmsProjDec_fx( - const Word16 D, /* i : density */ - const Word16 indexphi, /* i : decoded index from AR dec */ - Word16 *oppQ15, /* o : opposite */ - Word16 *nearQ15, /* o : near */ - Word16 *oppRatioQ3 /* o : ratio */ + const Word16 D, /* i : density Q0*/ + const Word16 indexphi, /* i : decoded index from AR dec Q0*/ + Word16 *oppQ15, /* o : opposite Q15*/ + Word16 *nearQ15, /* o : near Q15*/ + Word16 *oppRatioQ3 /* o : ratio Q3*/ ) { Word16 phiQ14q; Word16 oppTail, nearTail; - phiQ14q = (Word16) intLimCDivPos_fx( (UWord32) L_shl( L_deposit_l( indexphi ), 13 ), shr( D, 1 ) ); + phiQ14q = (Word16) intLimCDivPos_fx( (UWord32) L_shl( L_deposit_l( indexphi ), 13 ), shr( D, 1 ) ); /* Q14 */ move16(); if ( indexphi < 0 ) { @@ -365,11 +368,11 @@ void densityAngle2RmsProjDec_fx( IF( s_or( oppTail, nearTail ) < 0 ) { - *oppQ15 = s_and( oppTail, ( 1 << 15 ) - 1 ); + *oppQ15 = s_and( oppTail, ( 1 << 15 ) - 1 ); /* Q15 */ move16(); - *nearQ15 = s_and( nearTail, ( 1 << 15 ) - 1 ); + *nearQ15 = s_and( nearTail, ( 1 << 15 ) - 1 ); /* Q15 */ move16(); - *oppRatioQ3 = shl( add( 1, shl( nearTail, 1 ) ), 14 ); + *oppRatioQ3 = shl( add( 1, shl( nearTail, 1 ) ), 14 ); /* Q3 */ move16(); } ELSE @@ -383,15 +386,15 @@ void densityAngle2RmsProjDec_fx( } void densityAngle2RmsProjEnc_fx( - const Word16 D, /* i : density */ - const Word16 phiQ14uq, /* i : angle */ - Word16 *indexphi, /* o : index */ - Word16 *oppQ15, /* o : opposite */ - Word16 *nearQ15, /* o : near */ - Word16 *oppRatioQ3 /* o : ratio */ + const Word16 D, /* i : density Q0*/ + const Word16 phiQ14uq, /* i : angle Q14*/ + Word16 *indexphi, /* o : index Q0*/ + Word16 *oppQ15, /* o : opposite Q15*/ + Word16 *nearQ15, /* o : near Q15*/ + Word16 *oppRatioQ3 /* o : ratio Q3*/ ) { - *indexphi = mult_r( shl( D, 1 ), phiQ14uq ); + *indexphi = mult_r( shl( D, 1 ), phiQ14uq ); /* Q0 */ move16(); if ( s_and( D, 1 ) > 0 ) { @@ -404,21 +407,21 @@ void densityAngle2RmsProjEnc_fx( } void NearOppSplitAdjustment_fx( - const Word16 qband, /* i : quanta for current band */ - const Word16 qzero, /* i : range coder finalization quanta */ - const Word16 Qac, /* i : range coder current quanta */ - const UWord32 INTac, /* i : range coder state */ - const Word16 qglobal, /* i : quanta input */ - const Word16 FlagCons, /* i : conservative rounding flag */ - const Word16 Np, /* i : number of parts */ - const Word16 Nhead, /* i : first part */ - const Word16 Ntail, /* i : remaining parts */ - const Word16 Nnear, /* i : length of near component */ - const Word16 Nopp, /* i : length of opposite component */ - Word16 oppRQ3, /* i : ratio */ - Word16 *qnear, /* o : quantized near */ - Word16 *qopp, /* o : quantized opposite */ - Word16 *qglobalupd /* o : quanta remaining */ + const Word16 qband, /* i : quanta for current band Q0*/ + const Word16 qzero, /* i : range coder finalization quanta Q0*/ + const Word16 Qac, /* i : range coder current quanta Q0*/ + const UWord32 INTac, /* i : range coder state Q0*/ + const Word16 qglobal, /* i : quanta input Q0*/ + const Word16 FlagCons, /* i : conservative rounding flag Q0*/ + const Word16 Np, /* i : number of parts Q0*/ + const Word16 Nhead, /* i : first part Q0*/ + const Word16 Ntail, /* i : remaining parts Q0*/ + const Word16 Nnear, /* i : length of near component Q0*/ + const Word16 Nopp, /* i : length of opposite component Q0*/ + Word16 oppRQ3, /* i : ratio Q0*/ + Word16 *qnear, /* o : quantized near Q0*/ + Word16 *qopp, /* o : quantized opposite Q0*/ + Word16 *qglobalupd /* o : quanta remaining Q0*/ ) { @@ -427,45 +430,46 @@ void NearOppSplitAdjustment_fx( Word16 QIb, QIa; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif rangeCoderFinalizationFBits_fx( Qac, INTac, &qac ); - qboth = sub( qband, sub( qac, qzero ) ); + qboth = sub( qband, sub( qac, qzero ) ); /* Q0 */ /* skew calc code */ qskew = 0; move16(); IF( GT_16( Nhead, 1 ) ) { - qavg = extract_h( L_shl( intLimCDivSigned_fx( L_deposit_l( qboth ), Np ), 16 ) ); /* qboth may be negative */ + qavg = extract_h( L_shl( intLimCDivSigned_fx( L_deposit_l( qboth ), Np ), 16 ) ); /* qboth may be negative Q0*/ dsDiracPerQuanta_fx( Ntail, qavg, FlagCons, hBitsN, &Midx ); QuantaPerDsDirac_fx( Nhead, Midx, hBitsN, &qmin ); - qskew = sub( qavg, qmin ); - qskew = s_max( 0, qskew ); - } /* end of skew calc code*/ + qskew = sub( qavg, qmin ); /* Q0 */ + qskew = s_max( 0, qskew ); /* Q0 */ + } /* end of skew calc code*/ - QIa = add( extract_l( intLimCDivPos_fx( (UWord32) L_deposit_l( Nopp ), Nnear ) ), 1 ); /* always positive Word16 out */ - L_qnum = L_sub( L_deposit_l( sub( sub( add( qband, qzero ), qac ), qskew ) ), L_mult0( Nopp, oppRQ3 ) ); + QIa = add( extract_l( intLimCDivPos_fx( (UWord32) L_deposit_l( Nopp ), Nnear ) ), 1 ); /* always positive Word16 out Q0*/ + L_qnum = L_sub( L_deposit_l( sub( sub( add( qband, qzero ), qac ), qskew ) ), L_mult0( Nopp, oppRQ3 ) ); /* Q0 */ L_QIb = L_deposit_l( 0 ); IF( L_qnum > 0 ) { - L_QIb = (Word32) intLimCDivPos_fx( L_qnum, QIa ); + L_QIb = (Word32) intLimCDivPos_fx( L_qnum, QIa ); /* Q0 */ } - *qnear = qboth; + *qnear = qboth; /* Q3 */ move16(); #ifdef BASOP_NOGLOB - QIb = extract_h( L_shl_o( L_QIb, 16, &Overflow ) ); /* may saturate */ + QIb = extract_h( L_shl_o( L_QIb, 16, &Overflow ) ); /* may saturate Q0*/ #else QIb = extract_h( L_shl( L_QIb, 16 ) ); /* may saturate */ #endif if ( LE_16( QIb, qboth ) ) { - *qnear = QIb; + *qnear = QIb; /* Q0 */ move16(); } - *qopp = sub( qboth, *qnear ); + *qopp = sub( qboth, *qnear ); /* Q0 */ move16(); - *qglobalupd = sub( qglobal, sub( qac, qzero ) ); + *qglobalupd = sub( qglobal, sub( qac, qzero ) ); /* Q0 */ move16(); return; @@ -479,10 +483,10 @@ void NearOppSplitAdjustment_fx( *--------------------------------------------------------------------------*/ void apply_gain_fx( - const Word16 *ord, /* i : Indices for energy order */ - const Word16 *band_start, /* i : Sub band start indices */ - const Word16 *band_end, /* i : Sub band end indices */ - const Word16 num_sfm, /* i : Number of bands */ + const Word16 *ord, /* i : Indices for energy order Q0 */ + const Word16 *band_start, /* i : Sub band start indices Q0 */ + const Word16 *band_end, /* i : Sub band end indices Q0 */ + const Word16 num_sfm, /* i : Number of bands Q0 */ const Word16 *gains, /* i : Band gain vector Q12 */ Word16 *xq /* i/o: Float synthesis / Gain adjusted synth Q15/Q12 */ ) @@ -512,10 +516,10 @@ void apply_gain_fx( *--------------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED void fine_gain_quant_ivas_fx( - BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - const Word16 *ord, /* i : Indices for energy order */ - const Word16 num_sfm, /* i : Number of bands */ - const Word16 *gain_bits, /* i : Gain adjustment bits per sub band */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + const Word16 *ord, /* i : Indices for energy order Q0 */ + const Word16 num_sfm, /* i : Number of bands Q0 */ + const Word16 *gain_bits, /* i : Gain adjustment bits per sub band Q0 */ Word16 *fg_pred, /* i/o: Predicted gains / Corrected gains Q12 */ const Word16 *gopt /* i : Optimal gains Q12 */ ) @@ -536,7 +540,7 @@ void fine_gain_quant_ivas_fx( FOR( band = 0; band < num_sfm; band++ ) { - gbits = gain_bits[ord[band]]; + gbits = gain_bits[ord[band]]; /* Q0 */ move16(); test(); IF( fg_pred[band] != 0 && gbits > 0 ) @@ -545,9 +549,9 @@ void fine_gain_quant_ivas_fx( exp1 = sub( exp1, 1 ); tmp1 = shl( gopt[band], exp1 ); exp2 = norm_s( fg_pred[band] ); - tmp2 = shl( fg_pred[band], exp2 ); + tmp2 = shl( fg_pred[band], exp2 ); /* Q12 + exp2 */ exp1 = add( 15, sub( exp1, exp2 ) ); - err = div_s( tmp1, tmp2 ); + err = div_s( tmp1, tmp2 ); /* Q15 */ tmp1 = norm_s( err ); exp2 = Log2_norm_lc( L_deposit_h( shl( err, tmp1 ) ) ); tmp1 = sub( 14, tmp1 ); @@ -555,16 +559,16 @@ void fine_gain_quant_ivas_fx( L_tmp = L_Comp( tmp1, exp2 ); Mpy_32_16_ss( L_tmp, 24660, &L_tmp, &lsb ); /* 24660 = 20*log10(2) in Q12 */ /*16+12-15=13 */ #ifdef BASOP_NOGLOB - gain_db = round_fx_sat( L_shl_o( L_tmp, 17, &Overflow ) ); -#else /* BASOP_NOGLOB */ + gain_db = round_fx_sat( L_shl_o( L_tmp, 17, &Overflow ) ); /* Q14 */ +#else /* BASOP_NOGLOB */ gain_db = round_fx( L_shl( L_tmp, 17 ) ); #endif - idx = squant_fx( gain_db, &gain_dbq, finegain_fx[gbits - 1], gain_cb_size[gbits - 1] ); + idx = squant_fx( gain_db, &gain_dbq, finegain_fx[gbits - 1], gain_cb_size[gbits - 1] ); /* Q0 */ push_indice( hBstr, IND_PVQ_FINE_GAIN, idx, gbits ); L_tmp = L_mult0( gain_dbq, 21771 ); /* 21771=0.05*log2(10) */ /* 14+17=31 */ - L_tmp = L_shr( L_tmp, 15 ); + L_tmp = L_shr( L_tmp, 15 ); /* Q16 */ tmp1 = L_Extract_lc( L_tmp, &exp1 ); tmp1 = abs_s( tmp1 ); tmp1 = extract_l( Pow2( 14, tmp1 ) ); @@ -580,10 +584,10 @@ void fine_gain_quant_ivas_fx( } #endif void fine_gain_quant_fx( - BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - const Word16 *ord, /* i : Indices for energy order */ - const Word16 num_sfm, /* i : Number of bands */ - const Word16 *gain_bits, /* i : Gain adjustment bits per sub band */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + const Word16 *ord, /* i : Indices for energy order Q0 */ + const Word16 num_sfm, /* i : Number of bands Q0 */ + const Word16 *gain_bits, /* i : Gain adjustment bits per sub band Q0 */ Word16 *fg_pred, /* i/o: Predicted gains / Corrected gains Q12 */ const Word16 *gopt /* i : Optimal gains Q12 */ ) @@ -604,7 +608,7 @@ void fine_gain_quant_fx( FOR( band = 0; band < num_sfm; band++ ) { - gbits = gain_bits[ord[band]]; + gbits = gain_bits[ord[band]]; /* Q0 */ move16(); test(); IF( fg_pred[band] != 0 && gbits > 0 ) @@ -613,9 +617,9 @@ void fine_gain_quant_fx( exp1 = sub( exp1, 1 ); tmp1 = shl( gopt[band], exp1 ); exp2 = norm_s( fg_pred[band] ); - tmp2 = shl( fg_pred[band], exp2 ); + tmp2 = shl( fg_pred[band], exp2 ); /* Q12 + exp2 */ exp1 = add( 15, sub( exp1, exp2 ) ); - err = div_s( tmp1, tmp2 ); + err = div_s( tmp1, tmp2 ); /* Q15 */ tmp1 = norm_s( err ); exp2 = Log2_norm_lc( L_deposit_h( shl( err, tmp1 ) ) ); tmp1 = sub( 14, tmp1 ); @@ -632,7 +636,7 @@ void fine_gain_quant_fx( push_indice_fx( hBstr, IND_PVQ_FINE_GAIN, idx, gbits ); L_tmp = L_mult0( gain_dbq, 21771 ); /* 21771=0.05*log2(10) */ /* 14+17=31 */ - L_tmp = L_shr( L_tmp, 15 ); + L_tmp = L_shr( L_tmp, 15 ); /* Q16 */ tmp1 = L_Extract_lc( L_tmp, &exp1 ); tmp1 = abs_s( tmp1 ); tmp1 = extract_l( Pow2( 14, tmp1 ) ); @@ -654,10 +658,11 @@ void fine_gain_quant_fx( *-------------------------------------------------------------------*/ void srt_vec_ind16_fx( - const Word16 *linear, /* linear input */ - Word16 *srt, /* sorted output*/ - Word16 *I, /* index for sorted output */ - Word16 length ) + const Word16 *linear, /* linear input Q3*/ + Word16 *srt, /* sorted output Q3*/ + Word16 *I, /* index for sorted output Q0*/ + Word16 length /* Q0 */ +) { Word16 pos, npos; Word16 idxMem; @@ -666,11 +671,11 @@ void srt_vec_ind16_fx( /*initilize */ FOR( pos = 0; pos < length; pos++ ) { - I[pos] = pos; + I[pos] = pos; /* Q0 */ move16(); } - Copy( linear, srt, length ); + Copy( linear, srt, length ); /* Q3 */ /* now iterate */ FOR( pos = 0; pos < ( length - 1 ); pos++ ) @@ -679,18 +684,18 @@ void srt_vec_ind16_fx( { IF( LT_16( srt[npos], srt[pos] ) ) { - idxMem = I[pos]; + idxMem = I[pos]; /* Q0 */ move16(); - I[pos] = I[npos]; + I[pos] = I[npos]; /* Q0 */ move16(); - I[npos] = idxMem; + I[npos] = idxMem; /* Q0 */ move16(); - valMem = srt[pos]; + valMem = srt[pos]; /* Q0 */ move16(); - srt[pos] = srt[npos]; + srt[pos] = srt[npos]; /* Q0 */ move16(); - srt[npos] = valMem; + srt[npos] = valMem; /* Q0 */ move16(); } } diff --git a/lib_com/range_com_fx.c b/lib_com/range_com_fx.c index 3eebfa3c9..b84ec6c26 100644 --- a/lib_com/range_com_fx.c +++ b/lib_com/range_com_fx.c @@ -13,9 +13,9 @@ * Get number of bits needed to finalize range coder *-------------------------------------------------------------------*/ -Word16 rc_get_bits2_fx( /* o: Number of bits needed */ - const Word16 N, /* i: Number of bits currently used */ - const UWord32 range /* i: Range of range coder */ +Word16 rc_get_bits2_fx( /* o: Number of bits needed Q0*/ + const Word16 N, /* i: Number of bits currently used Q0*/ + const UWord32 range /* i: Range of range coder Q0*/ ) { return add( add( N, 2 ), norm_ul( range ) ); @@ -28,24 +28,24 @@ Word16 rc_get_bits2_fx( /* o: Number of bits needed *-------------------------------------------------------------------*/ void rangeCoderFinalizationFBits_fx( - Word16 Brc, /* i : Current number of decoded bits */ - UWord32 INTrc, /* i : Range coder state */ - Word16 *FBits /* i : Fractional finalization bits */ + Word16 Brc, /* i : Current number of decoded bits Q0*/ + UWord32 INTrc, /* i : Range coder state Q0*/ + Word16 *FBits /* i : Fractional finalization bits Q0*/ ) { Word32 L_Bq15; UWord32 h, UL_tmp; UWord16 Bq15ui16, l; Word16 B, E, x, k; - *FBits = shl( add( Brc, 32 ), 3 ); + *FBits = shl( add( Brc, 32 ), 3 ); /* Q0 */ - B = sub( 30, norm_ul( INTrc ) ); - x = sub( B, RCF_INIT_SHIFT ); + B = sub( 30, norm_ul( INTrc ) ); /* Q0 */ + x = sub( B, RCF_INIT_SHIFT ); /* Q0 */ L_Bq15 = 0; move16(); if ( x >= 0 ) { - L_Bq15 = (Word32) UL_lshr( INTrc, x ); + L_Bq15 = (Word32) UL_lshr( INTrc, x ); /* Q0 */ move32(); } @@ -53,16 +53,16 @@ void rangeCoderFinalizationFBits_fx( move16(); FOR( k = 1; k < 4; k++ ) { - Bq15ui16 = u_extract_l( L_shr( L_Bq15, s_and( E, 1 ) ) ); - UL_tmp = UL_lshl( UL_deposit_l( Bq15ui16 ), 1 ); - Mpy_32_16_uu( UL_tmp, Bq15ui16, &h, &l ); + Bq15ui16 = u_extract_l( L_shr( L_Bq15, s_and( E, 1 ) ) ); /* Q0 */ + UL_tmp = UL_lshl( UL_deposit_l( Bq15ui16 ), 1 ); /* Q0 */ + Mpy_32_16_uu( UL_tmp, Bq15ui16, &h, &l ); /* Q0 */ L_Bq15 = (Word32) h; move32(); - E = add( shl( B, 1 ), extract_l( L_lshr( L_sub( ( ( 1L << 16 ) - 1L ), L_Bq15 ), 31 ) ) ); + E = add( shl( B, 1 ), extract_l( L_lshr( L_sub( ( ( 1L << 16 ) - 1L ), L_Bq15 ), 31 ) ) ); /* Q0 */ B = E; move16(); } - *FBits = sub( *FBits, B ); + *FBits = sub( *FBits, B ); /* Q0 */ move16(); return; } diff --git a/lib_com/re8_ppv_fx.c b/lib_com/re8_ppv_fx.c index f330f22c2..c643bf1ea 100644 --- a/lib_com/re8_ppv_fx.c +++ b/lib_com/re8_ppv_fx.c @@ -24,8 +24,8 @@ static Word32 compute_error_2D8_fx( const Word32 x[], const Word16 y[] ); * --------------------------------------------------------------*/ void re8_PPV_fx( - const Word32 x[], /* i : point in R^8Q15 */ - Word16 y[] /* o : point in RE8 (8-dimensional integer vector) */ + const Word32 x[], /* i : point in R^8 Q15 */ + Word16 y[] /* o : point in RE8 (8-dimensional integer vector) Q0*/ ) { Word16 i, y0[8]; @@ -42,14 +42,14 @@ void re8_PPV_fx( FOR( i = 0; i < 8; i++ ) { - x1[i] = L_sub( x[i], QR ); + x1[i] = L_sub( x[i], QR ); /* Q15 */ move32(); } nearest_neighbor_2D8_fx( x1, y ); FOR( i = 0; i < 8; i++ ) { - y[i] = add( y[i], 1 ); + y[i] = add( y[i], 1 ); /* Q0 */ move16(); } @@ -66,7 +66,7 @@ void re8_PPV_fx( *--------------------------------------------------------------*/ IF( LT_32( e0, e1 ) ) { - Copy( y0, y, 8 ); + Copy( y0, y, 8 ); /* Q0 */ } return; @@ -83,8 +83,8 @@ void re8_PPV_fx( --------------------------------------------------------------*/ static void nearest_neighbor_2D8_fx( - const Word32 x[], /* i : point in R^8 */ - Word16 y[] /* o : point in 2D8 (8-dimensional integer vector) */ + const Word32 x[], /* i : point in R^8 Q15*/ + Word16 y[] /* o : point in 2D8 (8-dimensional integer vector) Q0*/ ) { Word16 i, j; @@ -103,10 +103,10 @@ static void nearest_neighbor_2D8_fx( { /* round to ..., -2, 0, 2, ... ([-1..1[ --> 0) */ tmp16 = round_fx( L_add( x[i], L_shr( x[i], 31 ) ) ); - y[i] = shl( tmp16, 1 ); + y[i] = shl( tmp16, 1 ); /* Q0 */ move16(); /* sum += y[i] */ - sum = add( sum, y[i] ); + sum = add( sum, y[i] ); /* Q0 */ } /*--------------------------------------------------------------* @@ -126,7 +126,7 @@ static void nearest_neighbor_2D8_fx( { /* compute ei = xi-yi */ /* e[i]=x[i]-y[i] */ - e = L_msu( x[i], y[i], QR / 2 ); + e = L_msu( x[i], y[i], QR / 2 ); /* Q15 */ /* compute |ei| = | xi-yi | */ s = L_abs( e ); @@ -137,19 +137,19 @@ static void nearest_neighbor_2D8_fx( j = i; move16(); } - em = L_max( s, em ); + em = L_max( s, em ); /* Q15 */ } /* round xj in the "wrong way" */ - e = L_msu( x[j], y[j], QR / 2 ); + e = L_msu( x[j], y[j], QR / 2 ); /* Q15 */ tmp16 = extract_h( e ); - tmp16b = add( y[j], 2 ); + tmp16b = add( y[j], 2 ); /* Q0 */ if ( tmp16 < 0 ) { - tmp16b = sub( tmp16b, 2 + 2 ); + tmp16b = sub( tmp16b, 2 + 2 ); /* Q0 */ } - y[j] = tmp16b; + y[j] = tmp16b; /* Q0 */ move16(); } @@ -164,9 +164,9 @@ static void nearest_neighbor_2D8_fx( * (quantized) point in 2D8. --------------------------------------------------------------*/ -static Word32 compute_error_2D8_fx( /* o : mean squared error */ - const Word32 x[], /* i : input vector */ - const Word16 y[] /* i : point in 2D8 (8-dimensional integer vector) */ +static Word32 compute_error_2D8_fx( /* o : mean squared error Q15*/ + const Word32 x[], /* i : input vector Q15*/ + const Word16 y[] /* i : point in 2D8 (8-dimensional integer vector) Q0*/ ) { Word16 i, hi, lo; @@ -176,17 +176,17 @@ static Word32 compute_error_2D8_fx( /* o : mean squared error FOR( i = 0; i < 8; i++ ) { /*tmp = x[i]-y[i];*/ - Ltmp = L_msu( x[i], y[i], 16384 ); - hi = extract_h( L_shl( Ltmp, 1 ) ); - lo = extract_l( L_msu( Ltmp, hi, 16384 ) ); + Ltmp = L_msu( x[i], y[i], 16384 ); /* Q15 */ + hi = extract_h( L_shl( Ltmp, 1 ) ); /* Q0 */ + lo = extract_l( L_msu( Ltmp, hi, 16384 ) ); /* Q15 */ - Ltmp = L_mult( hi, hi ); - Ltmp = L_shl( Ltmp, 14 ); - Ltmp = L_mac( Ltmp, hi, lo ); - Ltmp = L_mac0( Ltmp, mult( lo, lo ), 1 ); + Ltmp = L_mult( hi, hi ); /* Q1 */ + Ltmp = L_shl( Ltmp, 14 ); /* Q15 */ + Ltmp = L_mac( Ltmp, hi, lo ); /* Q15 */ + Ltmp = L_mac0( Ltmp, mult( lo, lo ), 1 ); /* Q15 */ /* err+=tmp*tmp */ - err = L_add( Ltmp, err ); + err = L_add( Ltmp, err ); /* Q15 */ } return ( err ); diff --git a/lib_com/re8_util_fx.c b/lib_com/re8_util_fx.c index 00909e2f5..746b7152b 100644 --- a/lib_com/re8_util_fx.c +++ b/lib_com/re8_util_fx.c @@ -23,11 +23,11 @@ static void re8_coord_fx( const Word16 *y, Word16 *k ); * MULTI-RATE RE8 INDEXING BY VORONOI EXTENSION *----------------------------------------------------------------*/ void re8_vor_fx( - const Word16 y[], /* i : point in RE8 (8-dimensional integer vector) */ - Word16 *n, /* o : codebook number n=0,2,3,4,... (scalar integer) */ - Word16 k[], /* o : Voronoi index (integer vector of dimension 8) used only if n>4*/ - Word16 c[], /* o : codevector in Q0, Q2, Q3, or Q4 if n<=4, y=c */ - Word16 *ka /* o : identifier of absolute leader (to index c) */ + const Word16 y[], /* i : point in RE8 (8-dimensional integer vector) Q0*/ + Word16 *n, /* o : codebook number n=0,2,3,4,... (scalar integer) Q0*/ + Word16 k[], /* o : Voronoi index (integer vector of dimension 8) used only if n>4 Q0*/ + Word16 c[], /* o : codevector in Q0, Q2, Q3, or Q4 if n<=4, y=c Q0*/ + Word16 *ka /* o : identifier of absolute leader (to index c) Q0*/ ) { Word16 i, r, iter, ka_tmp, n_tmp, mask; @@ -45,14 +45,14 @@ void re8_vor_fx( * the absolute leader is identified by ka * - a translation table maps ka to the codebook number n) *----------------------------------------------------------------*/ - *ka = re8_identify_absolute_leader_fx( y ); + *ka = re8_identify_absolute_leader_fx( y ); /* Q0 */ move16(); /*----------------------------------------------------------------* * compute codebook number n of Qn (by table look-up) * at this stage, n=0,2,3,4 or out=100 *----------------------------------------------------------------*/ - *n = Da_nq[*ka]; + *n = Da_nq[*ka]; /* Q0 */ move16(); /*----------------------------------------------------------------* @@ -70,17 +70,17 @@ void re8_vor_fx( IF( LE_16( *n, 4 ) ) { - Copy( y, c, 8 ); + Copy( y, c, 8 ); /* Q0 */ } ELSE { /*------------------------------------------------------------* * initialize r and m=2^r based on || y ||^2/8 *------------------------------------------------------------*/ - Ltmp = L_mult( y[0], y[0] ); + Ltmp = L_mult( y[0], y[0] ); /* Q1 */ FOR( i = 1; i < 8; i++ ) { - Ltmp = L_mac( Ltmp, y[i], y[i] ); + Ltmp = L_mac( Ltmp, y[i], y[i] ); /* Q1 */ } Lsphere = L_shr( Ltmp, 5 + 1 ); /* *0.125*0.25 / 2 to remove L_mac effect */ @@ -99,7 +99,7 @@ void re8_vor_fx( /*------------------------------------------------------------* * compute m and the mask needed for modulo m (for Voronoi coding) *------------------------------------------------------------*/ - mask = sub( shl( 1, r ), 1 ); /* 0x0..011...1 */ + mask = sub( shl( 1, r ), 1 ); /* 0x0..011...1 Q0*/ /*------------------------------------------------------------* * find the minimal value of r (or equivalently of m) in 2 iterations @@ -112,7 +112,7 @@ void re8_vor_fx( *--------------------------------------------------------*/ FOR( i = 0; i < 8; i++ ) { - k_tmp[i] = s_and( k_mod[i], mask ); + k_tmp[i] = s_and( k_mod[i], mask ); /* Q0 */ move16(); } @@ -125,19 +125,19 @@ void re8_vor_fx( FOR( i = 0; i < 8; i++ ) { - c_tmp[i] = shr( sub( y[i], v[i] ), r ); + c_tmp[i] = shr( sub( y[i], v[i] ), r ); /* Q0 */ move16(); } /*--------------------------------------------------------* * verify if c_tmp is in Q2, Q3 or Q4 *--------------------------------------------------------*/ - ka_tmp = re8_identify_absolute_leader_fx( c_tmp ); + ka_tmp = re8_identify_absolute_leader_fx( c_tmp ); /* Q0 */ /*--------------------------------------------------------* * at this stage, n_tmp=2,3,4 or out = 100 -- n=0 is not possible *--------------------------------------------------------*/ - n_tmp = Da_nq[ka_tmp]; + n_tmp = Da_nq[ka_tmp]; /* Q0 */ move16(); IF( GT_16( n_tmp, 4 ) ) @@ -145,7 +145,7 @@ void re8_vor_fx( /*--------------------------------------------------------* * if c is not in Q2, Q3, or Q4 (i.e. n_tmp>4), use m = 2^(r+1) instead of 2^r *--------------------------------------------------------*/ - r = add( r, 1 ); + r = add( r, 1 ); /* Q0 */ mask = add( shl( mask, 1 ), 1 ); /* mask = m-1 <- this is less complex */ } ELSE @@ -156,23 +156,23 @@ void re8_vor_fx( * since Q2 is a subset of Q3, indicate n=3 instead of n=2 (this is because * for n>4, n=n'+2r with n'=3 or 4, so n'=2 is not valid) *--------------------------------------------------------*/ - n_tmp = s_max( n_tmp, 3 ); + n_tmp = s_max( n_tmp, 3 ); /* Q0 */ /*--------------------------------------------------------* * save current values into ka, n, k and c *--------------------------------------------------------*/ - *ka = ka_tmp; + *ka = ka_tmp; /* Q0 */ move16(); - *n = add( n_tmp, shl( r, 1 ) ); + *n = add( n_tmp, shl( r, 1 ) ); /* Q0 */ move16(); - Copy( k_tmp, k, 8 ); - Copy( c_tmp, c, 8 ); + Copy( k_tmp, k, 8 ); /* Q0 */ + Copy( c_tmp, c, 8 ); /* Q0 */ /*--------------------------------------------------------* * try m = 2^(r-1) instead of 2^r to be sure that m is minimal *--------------------------------------------------------*/ - r = sub( r, 1 ); - mask = shr( mask, 1 ); + r = sub( r, 1 ); /* Q0 */ + mask = shr( mask, 1 ); /* Q0 */ } } } @@ -187,9 +187,9 @@ void re8_vor_fx( * VORONOI INDEXING (INDEX DECODING) k -> y -------------------------------------------------------------------------*/ void re8_k2y_fx( - const Word16 *k, /* i : Voronoi index k[0..7] */ - const Word16 m, /* i : Voronoi modulo (m = 2^r = 1<=2) */ - Word16 *y /* o : 8-dimensional point y[0..7] in RE8 */ + const Word16 *k, /* i : Voronoi index k[0..7] Q0*/ + const Word16 m, /* i : Voronoi modulo (m = 2^r = 1<=2) Q0*/ + Word16 *y /* o : 8-dimensional point y[0..7] in RE8 Q0*/ ) { Word16 i, v[8], *ptr1, *ptr2, m_tmp, mm; @@ -204,29 +204,29 @@ void re8_k2y_fx( * [1 1 _ 1 1] * a=(2,0,...,0) *---------------------------------------------------------------*/ - m_tmp = sub( 15, m ); + m_tmp = sub( 15, m ); /* Q0 */ - Lsum = L_deposit_l( k[7] ); + Lsum = L_deposit_l( k[7] ); /* Q0 */ ytp[7] = Lsum; move32(); - z[7] = L_shl( Lsum, m_tmp ); - move32(); /* (int)(floor(y[7]*QR+0.5))>>m */ + z[7] = L_shl( Lsum, m_tmp ); /* m_tmp */ + move32(); /* (int)(floor(y[7]*QR+0.5))>>m */ FOR( i = 6; i >= 1; i-- ) { - Ltmp = L_deposit_l( shl( k[i], 1 ) ); - Lsum = L_add( Lsum, Ltmp ); - ytp[i] = L_add( ytp[7], Ltmp ); + Ltmp = L_deposit_l( shl( k[i], 1 ) ); /* Q0 */ + Lsum = L_add( Lsum, Ltmp ); /* Q0 */ + ytp[i] = L_add( ytp[7], Ltmp ); /* Q0 */ move32(); - z[i] = L_shl( ytp[i], m_tmp ); - move32(); /* (int)(floor(y[7]*QR+0.5))>>m */ + z[i] = L_shl( ytp[i], m_tmp ); /* m_tmp */ + move32(); /* (int)(floor(y[7]*QR+0.5))>>m */ } - Lsum = L_add( Lsum, L_deposit_l( shl( k[0], 2 ) ) ); + Lsum = L_add( Lsum, L_deposit_l( shl( k[0], 2 ) ) ); /* Q0 */ ytp[0] = Lsum; move32(); - z[0] = L_shl( L_sub( Lsum, 2 ), m_tmp ); - move32(); /* (int)(floor(y[7]*QR+0.5))>>m */ + z[0] = L_shl( L_sub( Lsum, 2 ), m_tmp ); /* m_tmp */ + move32(); /* (int)(floor(y[7]*QR+0.5))>>m */ /*---------------------------------------------------------------* * find nearest neighbor v of z in infinite RE8 @@ -236,15 +236,15 @@ void re8_k2y_fx( /*---------------------------------------------------------------* * compute y -= m v *---------------------------------------------------------------*/ - ptr1 = y; - ptr2 = v; + ptr1 = y; /* Q0 */ + ptr2 = v; /* Q0 */ mm = shr( shl( 1, m ), 1 ); /* shr to remove effect of L_mult in L_msu */ FOR( i = 0; i < 8; i++ ) { - Ltmp = L_msu( ytp[i], *ptr2++, mm ); - *ptr1++ = extract_l( Ltmp ); + Ltmp = L_msu( ytp[i], *ptr2++, mm ); /* Q0 */ + *ptr1++ = extract_l( Ltmp ); /* Q0 */ } return; @@ -258,8 +258,8 @@ void re8_k2y_fx( * SPECIFIES THE CODEBOOKS Q0, Q2, Q3 and Q4 -----------------------------------------------------------------------*/ -static Word16 re8_identify_absolute_leader_fx( /* o : integer indicating if y if in Q0, Q2, Q3 or Q4 (or if y is an outlier) */ - const Word16 y[] /* i : point in RE8 (8-dimensional integer vector) */ +static Word16 re8_identify_absolute_leader_fx( /* o : integer indicating if y if in Q0, Q2, Q3 or Q4 (or if y is an outlier) Q0*/ + const Word16 y[] /* i : point in RE8 (8-dimensional integer vector) Q0*/ ) { Word16 i, s, id, nb, pos, ka, tmp16; @@ -270,10 +270,10 @@ static Word16 re8_identify_absolute_leader_fx( /* o : integer i /*-----------------------------------------------------------------------* * compute the RE8 shell number s = (y1^2+...+y8^2)/8 and C=(y1^2, ..., y8^2) *-----------------------------------------------------------------------*/ - Ls = L_mult( y[0], y[0] ); + Ls = L_mult( y[0], y[0] ); /* Q1 */ FOR( i = 1; i < 8; i++ ) { - Ls = L_mac( Ls, y[i], y[i] ); + Ls = L_mac( Ls, y[i], y[i] ); /* Q1 */ } #ifdef BASOP_NOGLOB s = extract_h( L_shl_sat( Ls, 16 - ( 3 + 1 ) ) ); /* s can saturate here */ @@ -304,14 +304,14 @@ static Word16 re8_identify_absolute_leader_fx( /* o : integer i * compute the unique identifier id of the absolute leader related to y: * s = (y1^4 + ... + y8^4)/8 *---------------------------------------------------------------*/ - C = L_mult( y[0], y[0] ); - tmp16 = extract_h( L_shl( C, 16 - 1 ) ); - Ltmp = L_mult( tmp16, tmp16 ); + C = L_mult( y[0], y[0] ); /* Q1 */ + tmp16 = extract_h( L_shl( C, 16 - 1 ) ); /* Q0 */ + Ltmp = L_mult( tmp16, tmp16 ); /* Q1 */ FOR( i = 1; i < 8; i++ ) { - C = L_mult( y[i], y[i] ); - tmp16 = extract_h( L_shl( C, 16 - 1 ) ); - Ltmp = L_mac( Ltmp, tmp16, tmp16 ); + C = L_mult( y[i], y[i] ); /* Q1 */ + tmp16 = extract_h( L_shl( C, 16 - 1 ) ); /* Q0 */ + Ltmp = L_mac( Ltmp, tmp16, tmp16 ); /* Q1 */ } id = extract_h( L_shl( Ltmp, 16 - ( 3 + 1 ) ) ); /* id can saturate to 8192 */ @@ -322,12 +322,12 @@ static Word16 re8_identify_absolute_leader_fx( /* o : integer i * only the id's related to the shell of number s are checked *---------------------------------------------------------------*/ - nb = Da_nb[s - 1]; /* get the number of absolute leaders used on the shell of number s */ - pos = Da_pos[s - 1]; /* get the position of the first absolute leader of shell s in Da_id */ + nb = Da_nb[s - 1]; /* get the number of absolute leaders used on the shell of number s Q0*/ + pos = Da_pos[s - 1]; /* get the position of the first absolute leader of shell s in Da_id Q0*/ move16(); move16(); - ptr = &Da_id[pos]; + ptr = &Da_id[pos]; /* Q0 */ move16(); FOR( i = 0; i < nb; i++ ) { @@ -338,7 +338,7 @@ static Word16 re8_identify_absolute_leader_fx( /* o : integer i BREAK; } ptr++; - pos = add( pos, 1 ); + pos = add( pos, 1 ); /* Q0 */ } } } @@ -354,8 +354,8 @@ static Word16 re8_identify_absolute_leader_fx( /* o : integer i -----------------------------------------------------------------------*/ static void re8_coord_fx( - const Word16 *y, /* i : 8-dimensional point y[0..7] in RE8 */ - Word16 *k /* o : coordinates k[0..7] */ + const Word16 *y, /* i : 8-dimensional point y[0..7] in RE8 Q0*/ + Word16 *k /* o : coordinates k[0..7] Q0*/ ) { Word16 i, tmp, sum; @@ -369,21 +369,21 @@ static void re8_coord_fx( * [ 5 -2 _ -2 4] * *---------------------------------------------------------------*/ - k[7] = y[7]; + k[7] = y[7]; /* Q0 */ move16(); - tmp = y[7]; + tmp = y[7]; /* Q0 */ move16(); - sum = add( y[7], shl( y[7], 2 ) ); + sum = add( y[7], shl( y[7], 2 ) ); /* Q0 */ FOR( i = 6; i >= 1; i-- ) { /* apply factor 2/4 from M^-1 */ - k[i] = shr( sub( y[i], tmp ), 1 ); + k[i] = shr( sub( y[i], tmp ), 1 ); /* Q0 */ move16(); - sum = sub( sum, y[i] ); + sum = sub( sum, y[i] ); /* Q0 */ } /* apply factor 1/4 from M^-1 */ - k[0] = shr( add( y[0], sum ), 2 ); + k[0] = shr( add( y[0], sum ), 2 ); /* Q0 */ move16(); return; diff --git a/lib_com/recovernorm_fx.c b/lib_com/recovernorm_fx.c index a61e1f183..2f9859758 100644 --- a/lib_com/recovernorm_fx.c +++ b/lib_com/recovernorm_fx.c @@ -14,10 +14,10 @@ *--------------------------------------------------------------------------*/ void recovernorm_fx( - const Word16 *idxbuf, /* i : reordered quantization indices */ - Word16 *ynrm, /* o : recovered quantization indices */ - Word16 *normqlg2, /* o : recovered quantized norms */ - const Word16 nb_sfm /* i : number of SFMs */ + const Word16 *idxbuf, /* i : reordered quantization indices Q0*/ + Word16 *ynrm, /* o : recovered quantization indices Q0*/ + Word16 *normqlg2, /* o : recovered quantized norms Q0*/ + const Word16 nb_sfm /* i : number of SFMs Q0*/ ) { Word16 i, j, k; @@ -27,32 +27,32 @@ void recovernorm_fx( SWITCH( nb_sfm ) { case NB_SFM: - order = norm_order_48; + order = norm_order_48; /* Q0 */ move16(); BREAK; case SFM_N_SWB: - order = norm_order_32; + order = norm_order_32; /* Q0 */ move16(); BREAK; case SFM_N_WB: - order = norm_order_16; + order = norm_order_16; /* Q0 */ move16(); BREAK; default: - order = norm_order_48; + order = norm_order_48; /* Q0 */ move16(); BREAK; } FOR( i = 0; i < nb_sfm; i++ ) { - j = order[i]; + j = order[i]; /* Q0 */ move16(); - k = idxbuf[i]; + k = idxbuf[i]; /* Q0 */ move16(); - ynrm[j] = k; + ynrm[j] = k; /* Q0 */ move16(); - normqlg2[j] = dicnlg2[k]; + normqlg2[j] = dicnlg2[k]; /* Q0 */ move16(); } diff --git a/lib_com/rom_com.c b/lib_com/rom_com.c index e8143222d..7430b18e6 100644 --- a/lib_com/rom_com.c +++ b/lib_com/rom_com.c @@ -35673,19 +35673,19 @@ const TCX_LTP_FILTER tcxLtpFilters[12] = const SCALE_TCX_SETUP scaleTcxTable[SIZE_SCALE_TABLE_TCX] = { - { 0, 0, 8000, 0.67f , 21955/*0.67f Q15*/ }, - { 0, 8000, 9600, 0.70f , 22938/*0.70f Q15*/ }, - { 0, 9600, 13200, 0.76f , 24904/*0.76f Q15*/ }, - { 0, 13200, 16400, 0.86f , 28180/*0.86f Q15*/ }, - { 0, 16400, 24400, 0.90f , 29491/*0.90f Q15*/ }, - { 0, 24400, 64000, 0.96f , 31457/*0.96f Q15*/ }, - { 1, 0, 8000, 1.f , 32767/*1.f Q15*/ }, - { 1, 8000, 9600, 1.f , 32767/*1.f Q15*/ }, - { 1, 9600, 13200, 1.f , 32767/*1.f Q15*/ }, - { 1, 13200, 16400, 0.85f /*0.85f*/, 27853/*0.85f Q15*/ }, - { 1, 16400, 24400, 0.88f /*0.90*/ , 28836/*0.88f Q15*/ }, - { 1, 24400, 32000, 0.90f /*0.90*/ , 29491/*0.90f Q15*/ }, - { 1, 32000, 32400, 0.95f /*0.91f*/, 31130/*0.95f Q15*/ }, + { 0, 0, 8000, /* 0.67f ,*/ 21955/*0.67f Q15*/ }, + { 0, 8000, 9600, /* 0.70f ,*/ 22938/*0.70f Q15*/ }, + { 0, 9600, 13200, /* 0.76f ,*/ 24904/*0.76f Q15*/ }, + { 0, 13200, 16400, /* 0.86f ,*/ 28180/*0.86f Q15*/ }, + { 0, 16400, 24400, /* 0.90f ,*/ 29491/*0.90f Q15*/ }, + { 0, 24400, 64000, /* 0.96f ,*/ 31457/*0.96f Q15*/ }, + { 1, 0, 8000, /* 1.f ,*/ 32767/*1.f Q15*/ }, + { 1, 8000, 9600, /* 1.f ,*/ 32767/*1.f Q15*/ }, + { 1, 9600, 13200, /* 1.f ,*/ 32767/*1.f Q15*/ }, + { 1, 13200, 16400, /* 0.85f ,*/ 27853/*0.85f Q15*/ }, + { 1, 16400, 24400, /* 0.88f ,*/ 28836/*0.88f Q15*/ }, + { 1, 24400, 32000, /* 0.90f ,*/ 29491/*0.90f Q15*/ }, + { 1, 32000, 32400, /* 0.95f ,*/ 31130/*0.95f Q15*/ }, }; diff --git a/lib_com/stat_com.h b/lib_com/stat_com.h index 4cfcb8caf..53a29ca93 100644 --- a/lib_com/stat_com.h +++ b/lib_com/stat_com.h @@ -134,10 +134,13 @@ typedef struct int16_t voice_tilt; /*Flag for triggering new voice factor tilt*/ +#ifndef IVAS_FLOAT_FIXED float formant_enh_num_flt; float formant_enh_den_flt; - Word16 formant_enh_num; /* Q15 */ - Word16 formant_enh_den; /* Q15 */ +#else + Word16 formant_enh_num; /* Q15 */ + Word16 formant_enh_den; /* Q15 */ +#endif int16_t bpf_mode; @@ -527,17 +530,20 @@ typedef struct Word32 exc_cng_32fx[L_FRAME16k]; #endif - int32_t CngBitrate; - int16_t CngBandwidth; + Word32 CngBitrate; + Word16 CngBandwidth; - int16_t flag_noisy_speech; + Word16 flag_noisy_speech; +#ifndef IVAS_FLOAT_FIXED float likelihood_noisy_speech_flt; - Word16 likelihood_noisy_speech; // Q15 +#else + Word16 likelihood_noisy_speech; /* Q15 */ +#endif #ifndef IVAS_FLOAT_FIXED float coherence_flt; /* inter-channel coherence of noise */ #else - Word16 coherence_fx; /* inter-channel coherence of noise Q15 */ + Word16 coherence_fx; /* inter-channel coherence of noise Q15 */ #endif int16_t no_side_flag; /* indicates whether the side noise shape should be zeroed-out or not */ @@ -694,8 +700,11 @@ typedef struct int32_t bitrateFrom; int32_t bitrateTo; +#ifndef IVAS_FLOAT_FIXED float scale_flt; - Word16 scale; /* Q15 */ +#else + Word16 scale; /* Q15 */ +#endif } SCALE_TCX_SETUP; @@ -884,14 +893,17 @@ typedef struct igf_grid_struct int16_t infoIsRefined; int16_t infoGranuleLen; Word16 infoTransFac; +#ifndef IVAS_FLOAT_FIXED float whiteningThreshold_flt[2][IGF_MAX_TILES]; - Word16 whiteningThreshold[2][IGF_MAX_TILES]; /* 2Q13 */ float gFactor_flt; float fFactor_flt; float lFactor_flt; - Word16 gFactor; /* 1Q14 */ - Word16 fFactor; /* 1Q14 */ - Word16 lFactor; /* 1Q14 */ +#else + Word16 whiteningThreshold[2][IGF_MAX_TILES]; /* 2Q13 */ + Word16 gFactor; /* 1Q14 */ + Word16 fFactor; /* 1Q14 */ + Word16 lFactor; /* 1Q14 */ +#endif } IGF_GRID, *H_IGF_GRID; diff --git a/lib_com/window_fx.c b/lib_com/window_fx.c index 2efbe5622..2b3c50ac6 100644 --- a/lib_com/window_fx.c +++ b/lib_com/window_fx.c @@ -89,7 +89,7 @@ void ham_cos_window_ivas( const Word16 n2 /* i: */ ) { - Word16 cc_fx; + Word16 cc_fx; // Q15 Word16 i; // cte = PI2 / (float) ( 2 * n1 - 1 ); @@ -98,7 +98,7 @@ void ham_cos_window_ivas( move16(); FOR( i = 0; i < n1; i++ ) { - *fh++ = sub( 17694, mult( getCosWord16R2( cc_fx ), 15073 ) ); + *fh++ = sub( 17694 /*0.54.Q15*/, mult( getCosWord16R2( cc_fx ), 15073 /*0.46.Q15*/ ) ); move16(); cc_fx = div_s( add( i, 1 ), sub( shl( n1, 1 ), 1 ) ); // add(cc_fx, cte_fx); } diff --git a/lib_com/window_ola_fx.c b/lib_com/window_ola_fx.c index 7dd0f2a79..40763be99 100644 --- a/lib_com/window_ola_fx.c +++ b/lib_com/window_ola_fx.c @@ -44,8 +44,8 @@ void sinq_fx( IF( GT_16( abs_s( tmp ), 3 ) ) { /*A=(x[2]+x[0])/x[1]=2*cos(tmp); here approximated by 2*(1-tmp^2/2!) */ - A32 = L_mult0( tmp, tmp ); /*Q30 */ - A32 = L_add( L_sub( 1073741824, A32 ), 1073741824 ); /*Q30 */ + A32 = L_mult0( tmp, tmp ); /*Q30 */ + A32 = L_add( L_sub( 1073741824 /*1.Q30*/, A32 ), 1073741824 /*1.Q30*/ ); /*Q30 */ } ELSE { @@ -216,8 +216,8 @@ void window_ola_fx( temp = sub( L, n ); - tmp2 = div_s( 1, temp ); /*Q15 */ - tmp2 = round_fx( L_shl( L_mult( tmp2, 25736 ), 2 ) ); /*Q15 */ + tmp2 = div_s( 1, temp ); /*Q15 */ + tmp2 = round_fx( L_shl( L_mult( tmp2, 25736 /*(pi/2).Q14*/ ), 2 ) ); /*Q15 */ sinq_fx( shr( tmp2, 1 ), shr( tmp2, 2 ), temp, SS2 ); @@ -532,17 +532,42 @@ void window_ola_fx( *-------------------------------------------------------------------*/ void window_ola_ext_fx( - const Word32 *ImdstOut, /* i : input */ - Word32 *auOut, /* o : output audio */ - Word32 *OldauOut, /* i/o: audio from previous frame */ + const Word32 *ImdstOut, /* i : input Qx */ + Word32 *auOut, /* o : output audio Qx */ + Word32 *OldauOut, /* i/o: audio from previous frame Qx */ const Word16 L, /* i : length */ const Word16 right_mode, const Word16 left_mode, /* i : window overlap of current frame (0: full, 2: none, or 3: half) */ const UWord16 kernel_type /* i : transform kernel type */ ) { - const Word16 sign_left = ( kernel_type & 1 ? MAX_16 : negate( MAX_16 ) ); - const Word16 sign_right = ( kernel_type >= MDCT_II ? negate( MAX_16 ) : MAX_16 ); + Word16 temp; + IF( s_and( kernel_type, 1 ) ) + { + temp = MAX_16; + } + ELSE + { + temp = MIN_16; + } + move16(); + + const Word16 sign_left = temp; + move16(); + + IF( GE_16( kernel_type, MDCT_II ) ) + { + temp = MIN_16; + } + ELSE + { + temp = MAX_16; + } + move16(); + + const Word16 sign_right = temp; + move16(); + Word16 i, decimate, decay; Word16 n, n16, windecay48, windecay16; Word16 win_right[R2_48]; @@ -551,7 +576,7 @@ void window_ola_ext_fx( Word16 win_int_right[R2_16]; Word32 *paout; - n = shr( mult( shl( L, Q5 ), N_ZERO_BY_FS ), Q5 ); + n = shr( mult( shl( L, Q5 ), N_ZERO_BY_FS ), Q5 ); // Q0 n16 = N16_CORE_SW; move16(); windecay48 = WINDECAY48; @@ -600,93 +625,93 @@ void window_ola_ext_fx( move16(); } - paout = auOut - n; + paout = auOut - n; // Qx IF( EQ_16( L, L_FRAME32k ) ) { - FOR( i = n; i < shr( L, 1 ); i += 2 ) + FOR( i = n; i < ( L >> 1 ); i += 2 ) { - paout[i] = L_add_sat( Mpy_32_16_1( Mpy_32_16_1( ImdstOut[add( shr( L, 1 ), i )], sign_right ), win_right[sub( sub( sub( i_mult( ( sub( 2 * L_FRAME16k, add( n16, shr( sub( i, n ), 1 ) ) ) ), decimate ), 1 ), decay ), windecay48 )] ), OldauOut[i] ); + paout[i] = L_add_sat( Mpy_32_16_1( Mpy_32_16_1( ImdstOut[( ( L >> 1 ) + i )], sign_right ), win_right[( ( ( ( ( ( 2 * L_FRAME16k - ( n16 + ( ( i - n ) >> 1 ) ) ) ) * decimate ) - 1 ) - decay ) - windecay48 )] ), OldauOut[i] ); move32(); - paout[i + 1] = L_add_sat( Mpy_32_16_1( Mpy_32_16_1( ImdstOut[add( add( shr( L, 1 ), i ), 1 )], sign_right ), win_int_right[sub( sub( sub( 2 * L_FRAME16k, add( n16, shr( sub( i, n ), 1 ) ) ), 1 ), windecay16 )] ), OldauOut[i + 1] ); + paout[i + 1] = L_add_sat( Mpy_32_16_1( Mpy_32_16_1( ImdstOut[( ( ( L >> 1 ) + i ) + 1 )], sign_right ), win_int_right[( ( ( 2 * L_FRAME16k - ( n16 + ( ( i - n ) >> 1 ) ) ) - 1 ) - windecay16 )] ), OldauOut[i + 1] ); move32(); } - FOR( i = 0; i < shr( L, 1 ) - n; i += 2 ) + FOR( i = 0; i < ( L >> 1 ) - n; i += 2 ) { - paout[add( add( shr( L, 1 ), i ), 1 )] = L_add_sat( Mpy_32_16_1( L_negate( ImdstOut[sub( sub( L, 1 ), add( i, 1 ) )] ), win_right[sub( add( i_mult( ( sub( 3 * L_FRAME16k / 2 - 1, shr( i, 1 ) ) ), decimate ), decay ), windecay48 )] ), OldauOut[add( add( i, shr( L, 1 ) ), 1 )] ); + paout[( ( ( L >> 1 ) + i ) + 1 )] = L_add_sat( Mpy_32_16_1( L_negate( ImdstOut[( ( L - 1 ) - ( i + 1 ) )] ), win_right[( ( ( ( ( 3 * L_FRAME16k / 2 - 1 - ( i >> 1 ) ) ) * decimate ) + decay ) - windecay48 )] ), OldauOut[( ( i + ( L >> 1 ) ) + 1 )] ); move32(); - paout[add( shr( L, 1 ), i )] = L_add_sat( Mpy_32_16_1( L_negate( ImdstOut[sub( sub( L, 1 ), i )] ), win_int_right[sub( sub( 3 * L_FRAME16k / 2 - 1, shr( i, 1 ) ), windecay16 )] ), OldauOut[add( i, shr( L, 1 ) )] ); + paout[( ( L >> 1 ) + i )] = L_add_sat( Mpy_32_16_1( L_negate( ImdstOut[( ( L - 1 ) - i )] ), win_int_right[( ( 3 * L_FRAME16k / 2 - 1 - ( i >> 1 ) ) - windecay16 )] ), OldauOut[( i + ( L >> 1 ) )] ); move32(); } - FOR( i = sub( shr( L, 1 ), n ); i < shr( L, 1 ); i += 2 ) + FOR( i = ( ( L >> 1 ) - n ); i < ( L >> 1 ); i += 2 ) { - paout[add( add( shr( L, 1 ), i ), 1 )] = L_add_sat( L_negate( ImdstOut[sub( sub( L, 1 ), add( i, 1 ) )] ), OldauOut[add( add( i, shr( L, 1 ) ), 1 )] ); + paout[( ( ( L >> 1 ) + i ) + 1 )] = L_add_sat( L_negate( ImdstOut[( ( L - 1 ) - ( i + 1 ) )] ), OldauOut[( ( i + ( L >> 1 ) ) + 1 )] ); move32(); - paout[add( shr( L, 1 ), i )] = L_add_sat( L_negate( ImdstOut[sub( L, add( 1, i ) )] ), OldauOut[add( i, shr( L, 1 ) )] ); + paout[( ( L >> 1 ) + i )] = L_add_sat( L_negate( ImdstOut[( L - ( 1 + i ) )] ), OldauOut[( i + ( L >> 1 ) )] ); move32(); } - FOR( i = 0; i < shr( L, 1 ); i += 2 ) + FOR( i = 0; i < ( L >> 1 ); i += 2 ) { - OldauOut[add( add( shr( L, 1 ), i ), 1 )] = Mpy_32_16_1( Mpy_32_16_1( ImdstOut[i + 1], sign_left ), win_left[add( i_mult( sub( L_FRAME16k / 2 - 1, shr( i, 1 ) ), decimate ), decay )] ); + OldauOut[( ( ( L >> 1 ) + i ) + 1 )] = Mpy_32_16_1( Mpy_32_16_1( ImdstOut[i + 1], sign_left ), win_left[( ( ( L_FRAME16k / 2 - 1 - ( i >> 1 ) ) * decimate ) + decay )] ); move32(); - OldauOut[add( shr( L, 1 ), i )] = Mpy_32_16_1( Mpy_32_16_1( ImdstOut[i], sign_left ), win_int_left[sub( L_FRAME16k / 2 - 1, shr( i, 1 ) )] ); + OldauOut[( ( L >> 1 ) + i )] = Mpy_32_16_1( Mpy_32_16_1( ImdstOut[i], sign_left ), win_int_left[( L_FRAME16k / 2 - 1 - ( i >> 1 ) )] ); move32(); } - FOR( i = n; i < shr( L, 1 ); i += 2 ) + FOR( i = n; i < ( L >> 1 ); i += 2 ) { - OldauOut[i] = Mpy_32_16_1( L_negate( ImdstOut[sub( sub( shr( L, 1 ), 1 ), i )] ), win_left[sub( sub( i_mult( sub( L_FRAME16k, shr( i, 1 ) ), decimate ), decay ), 1 )] ); + OldauOut[i] = Mpy_32_16_1( L_negate( ImdstOut[( ( ( L >> 1 ) - 1 ) - i )] ), win_left[( ( ( ( L_FRAME16k - ( i >> 1 ) ) * decimate ) - decay ) - 1 )] ); move32(); - OldauOut[i + 1] = Mpy_32_16_1( L_negate( ImdstOut[sub( sub( shr( L, 1 ), 1 ), add( i, 1 ) )] ), win_int_left[sub( L_FRAME16k - 1, shr( i, 1 ) )] ); + OldauOut[i + 1] = Mpy_32_16_1( L_negate( ImdstOut[( ( ( L >> 1 ) - 1 ) - ( i + 1 ) )] ), win_int_left[( L_FRAME16k - 1 - ( i >> 1 ) )] ); move32(); } } ELSE { - FOR( i = n; i < shr( L, 1 ); i++ ) + FOR( i = n; i < ( L >> 1 ); i++ ) { - paout[i] = L_add_sat( Mpy_32_16_1( Mpy_32_16_1( ImdstOut[add( shr( L, 1 ), i )], sign_right ), win_right[sub( sub( sub( i_mult( ( sub( shl( L, 1 ), i ) ), decimate ), 1 ), decay ), windecay48 )] ), OldauOut[i] ); + paout[i] = L_add_sat( Mpy_32_16_1( Mpy_32_16_1( ImdstOut[( ( L >> 1 ) + i )], sign_right ), win_right[( ( ( ( ( ( ( L << 1 ) - i ) ) * decimate ) - 1 ) - decay ) - windecay48 )] ), OldauOut[i] ); move32(); } - FOR( i = 0; i < shr( L, 1 ) - n; i++ ) + FOR( i = 0; i < ( L >> 1 ) - n; i++ ) { - paout[add( shr( L, 1 ), i )] = L_add_sat( Mpy_32_16_1( L_negate( ImdstOut[sub( L, add( 1, i ) )] ), win_right[sub( add( i_mult( ( sub( sub( i_mult( 3, shr( L, 1 ) ), 1 ), i ) ), decimate ), decay ), windecay48 )] ), OldauOut[add( i, shr( L, 1 ) )] ); + paout[( ( L >> 1 ) + i )] = L_add_sat( Mpy_32_16_1( L_negate( ImdstOut[( L - ( 1 + i ) )] ), win_right[( ( ( ( ( ( ( 3 * ( L >> 1 ) ) - 1 ) - i ) ) * decimate ) + decay ) - windecay48 )] ), OldauOut[( i + ( L >> 1 ) )] ); move32(); } - FOR( i = sub( shr( L, 1 ), n ); i < shr( L, 1 ); i++ ) + FOR( i = ( ( L >> 1 ) - n ); i < ( L >> 1 ); i++ ) { - paout[add( shr( L, 1 ), i )] = L_add_sat( L_negate( ImdstOut[sub( L, add( 1, i ) )] ), OldauOut[add( i, shr( L, 1 ) )] ); + paout[( ( L >> 1 ) + i )] = L_add_sat( L_negate( ImdstOut[( L - ( 1 + i ) )] ), OldauOut[( i + ( L >> 1 ) )] ); move32(); } - FOR( i = 0; i < shr( L, 1 ); i++ ) + FOR( i = 0; i < ( L >> 1 ); i++ ) { - OldauOut[add( shr( L, 1 ), i )] = Mpy_32_16_1( Mpy_32_16_1( ImdstOut[i], sign_left ), win_left[add( i_mult( ( sub( shr( L, 1 ), add( i, 1 ) ) ), decimate ), decay )] ); + OldauOut[( ( L >> 1 ) + i )] = Mpy_32_16_1( Mpy_32_16_1( ImdstOut[i], sign_left ), win_left[( ( ( ( ( L >> 1 ) - ( i + 1 ) ) ) * decimate ) + decay )] ); move32(); } - FOR( i = n; i < shr( L, 1 ); i++ ) + FOR( i = n; i < ( L >> 1 ); i++ ) { - OldauOut[i] = Mpy_32_16_1( L_negate( ImdstOut[sub( shr( L, 1 ), add( 1, i ) )] ), win_left[sub( sub( i_mult( sub( L, i ), decimate ), decay ), 1 )] ); + OldauOut[i] = Mpy_32_16_1( L_negate( ImdstOut[( ( L >> 1 ) - ( 1 + i ) )] ), win_left[( ( ( ( L - i ) * decimate ) - decay ) - 1 )] ); move32(); } } FOR( i = 0; i < n; i++ ) { - OldauOut[i] = L_negate( ImdstOut[sub( shr( L, 1 ), add( 1, i ) )] ); + OldauOut[i] = L_negate( ImdstOut[( ( L >> 1 ) - ( 1 + i ) )] ); move32(); } FOR( i = 0; i < n; i++ ) { - paout[add( L, i )] = OldauOut[i]; + paout[( L + i )] = OldauOut[i]; move32(); } @@ -731,14 +756,14 @@ void core_switching_OLA_fx( *Qsynth = tmp; move16(); Scale_sig( synth_subfr_out, SWITCH_MAX_GAP, sub( tmp, *Qsubfr ) ); - Scale_sig( mem_over_hp, NS2SA( 16000, DELAY_CLDFB_NS ) + 2, sub( tmp, *Qsubfr ) ); /* reScale mem over HP at Qsynth */ + Scale_sig( mem_over_hp, NS2SA_FX2( 16000, DELAY_CLDFB_NS ) + 2, sub( tmp, *Qsubfr ) ); /* reScale mem over HP at Qsynth */ *Qsubfr = tmp; move16(); /* win = window_48kHz_fx;*/ /* win_int = window_8_16_32kHz_fx;*/ - on_win = one_on_win_48k_fx; - on_win_int = one_on_win_8k_16k_48k_fx; + on_win = one_on_win_48k_fx; // Q14 + on_win_int = one_on_win_8k_16k_48k_fx; // Q14 SWITCH( output_frame ) @@ -792,7 +817,7 @@ void core_switching_OLA_fx( /* resample filter memory */ IF( EQ_16( output_frame, L_FRAME8k ) ) { - Copy( synth_subfr_out + SWITCH_GAP_LENGTH_8k, tmp_buf_switch + SWITCH_GAP_LENGTH_8k, NS2SA( output_Fs, DELAY_CLDFB_NS ) ); /* copy subframe to tmp buffer */ + Copy( synth_subfr_out + SWITCH_GAP_LENGTH_8k, tmp_buf_switch + SWITCH_GAP_LENGTH_8k, NS2SA_FX2( output_Fs, DELAY_CLDFB_NS ) ); /* copy subframe to tmp buffer */ } ELSE { @@ -800,7 +825,7 @@ void core_switching_OLA_fx( move16(); out_filt_length = 0; move16(); - out_filt_length = modify_Fs_intcub3m_sup_fx( mem_over_hp + 2, NS2SA( 12800, DELAY_CLDFB_NS ), 12800, tmp_buf_switch2, output_Fs, &filt_delay ); + out_filt_length = modify_Fs_intcub3m_sup_fx( mem_over_hp + 2, NS2SA_FX2( 12800, DELAY_CLDFB_NS ), 12800, tmp_buf_switch2, output_Fs, &filt_delay ); pt = tmp_buf_switch2 + sub( out_filt_length, filt_delay ); pt2 = pt - 1; FOR( i = 0; i < filt_delay; i++ ) @@ -902,7 +927,7 @@ void core_switching_OLA_fx( pt2 = pt + 1; pt5 = on_win + 210 - 1; pt4 = on_win_int + 70 - 1; - temp_len = i_mult2( shr( R2_16, 2 ), delta ); + temp_len = i_mult2( ( R2_16 >> 2 ), delta ); FOR( i = 0; i < temp_len; i += 2 ) { #ifdef BASOP_NOGLOB @@ -926,7 +951,7 @@ void core_switching_OLA_fx( pt = synth + tmp; pt5 = on_win + 210 - 1; - temp_len = i_mult2( shr( R2_16, 2 ), delta ); + temp_len = i_mult2( ( R2_16 >> 2 ), delta ); FOR( i = 0; i < temp_len; i++ ) { #ifdef BASOP_NOGLOB @@ -944,7 +969,7 @@ void core_switching_OLA_fx( pt = synth + tmp; move16(); /*Q15 */ - pt2 = synth_subfr_bwe + tmp - NS2SA( output_Fs, DELAY_CLDFB_NS ); + pt2 = synth_subfr_bwe + tmp - NS2SA_FX2( output_Fs, DELAY_CLDFB_NS ); move16(); /*Q15 */ pt3 = tmp_buf_switch + tmp; move16(); /*Q15 */ diff --git a/lib_com/wtda.c b/lib_com/wtda.c index eed61a240..3a9494e42 100644 --- a/lib_com/wtda.c +++ b/lib_com/wtda.c @@ -377,9 +377,9 @@ void wtda_fx32( move16(); decay = 0; move16(); - windecay48 = (Word16) WINDECAY48; // (int16_t)(2 * ((float)L_FRAME48k * N_ZERO_MDCT_NS / FRAME_SIZE_NS)) + R1_48 - move16(); + windecay48 = extract_l( WINDECAY48 ); // (int16_t)(2 * ((float)L_FRAME48k * N_ZERO_MDCT_NS / FRAME_SIZE_NS)) + R1_48 + test(); IF( EQ_16( L, L_FRAME32k ) || EQ_16( L, L_FRAME16k ) ) { decimate = 3; @@ -415,7 +415,7 @@ void wtda_fx32( BREAK; } - windecay16 = (Word16) WINDECAY16; // (int16_t)(2 * ((float)L_FRAME16k * N_ZERO_MDCT_NS / FRAME_SIZE_NS)) + R1_16; + windecay16 = extract_l( WINDECAY16 ); // (int16_t)(2 * ((float)L_FRAME16k * N_ZERO_MDCT_NS / FRAME_SIZE_NS)) + R1_16; /* algorithmic delay reduction */ i = 0; @@ -434,7 +434,7 @@ void wtda_fx32( IF( EQ_16( L, L_FRAME32k ) ) { - FOR( i = 0; i < sub( L / 2, n ); i += 2 ) + FOR( i = 0; i < ( L / 2 - n ); i += 2 ) { idx1 = sub( sub( shr( L, 1 ), i ), 1 ); idx2 = sub( sub( 3 * L_FRAME16k / 2 - 1, shr( i, 1 ) ), windecay16 ); @@ -453,16 +453,16 @@ void wtda_fx32( FOR( i = L / 2 - n; i < L / 2; i += 2 ) { - wtda_audio[i] = L_negate( allsig_r[sub( sub( shr( L, 1 ), i ), 1 )] ); + wtda_audio[i] = L_negate( allsig_r[( ( ( L >> 1 ) - i ) - 1 )] ); move32(); - wtda_audio[i + 1] = L_negate( allsig_r[sub( sub( shr( L, 1 ), add( i, 1 ) ), 1 )] ); + wtda_audio[i + 1] = L_negate( allsig_r[( ( ( L >> 1 ) - ( i + 1 ) ) - 1 )] ); move32(); } FOR( i = 0; i < n; i += 2 ) { - wtda_audio[add( i, shr( L, 1 ) )] = L_sub_sat( Mpy_32_16_1( allsig_l[i], win_left[add( i_mult( shr( i, 1 ), decimate ), decay )] ), new_audio[sub( sub( n, i ), 1 )] ); + wtda_audio[( i + ( L >> 1 ) )] = L_sub_sat( Mpy_32_16_1( allsig_l[i], win_left[( ( ( i >> 1 ) * decimate ) + decay )] ), new_audio[( ( n - i ) - 1 )] ); move32(); - wtda_audio[add( add( i, shr( L, 1 ) ), 1 )] = L_sub_sat( Mpy_32_16_1( allsig_l[i + 1], win_int_left[i / 2] ), new_audio[sub( sub( n, add( i, 1 ) ), 1 )] ); + wtda_audio[( ( i + ( L >> 1 ) ) + 1 )] = L_sub_sat( Mpy_32_16_1( allsig_l[i + 1], win_int_left[i / 2] ), new_audio[( ( n - ( i + 1 ) ) - 1 )] ); move32(); } @@ -473,14 +473,14 @@ void wtda_fx32( idx2 = add( i_mult( shr( i, 1 ), decimate ), decay ); idx3 = sub( sub( L, i ), 1 ); idx4 = sub( sub( i_mult( sub( shr( L, 1 ), shr( i, 1 ) ), decimate ), 1 ), decay ); - wtda_audio[add( i, shr( L, 1 ) )] = L_sub_sat( Mpy_32_16_1( allsig_l[idx1], win_left[idx2] ), Mpy_32_16_1( allsig_l[idx3], win_left[idx4] ) ); + wtda_audio[( i + ( L >> 1 ) )] = L_sub_sat( Mpy_32_16_1( allsig_l[idx1], win_left[idx2] ), Mpy_32_16_1( allsig_l[idx3], win_left[idx4] ) ); move32(); idx1 = add( i, 1 ); idx2 = shr( i, 1 ); idx3 = sub( sub( L, add( i, 1 ) ), 1 ); idx4 = sub( sub( shr( L, 1 ), shr( i, 1 ) ), 1 ); - wtda_audio[add( add( i, shr( L, 1 ) ), 1 )] = L_sub_sat( Mpy_32_16_1( allsig_l[idx1], win_int_left[idx2] ), Mpy_32_16_1( allsig_l[idx3], win_int_left[idx4] ) ); + wtda_audio[( ( i + ( L >> 1 ) ) + 1 )] = L_sub_sat( Mpy_32_16_1( allsig_l[idx1], win_int_left[idx2] ), Mpy_32_16_1( allsig_l[idx3], win_int_left[idx4] ) ); move32(); } } @@ -498,13 +498,13 @@ void wtda_fx32( FOR( i = L / 2 - n; i < L / 2; i++ ) { - wtda_audio[i] = L_negate( allsig_r[sub( sub( shr( L, 1 ), i ), 1 )] ); + wtda_audio[i] = L_negate( allsig_r[( ( ( L >> 1 ) - i ) - 1 )] ); move32(); } FOR( i = 0; i < n; i++ ) { - wtda_audio[add( i, shr( L, 1 ) )] = L_sub_sat( Mpy_32_16_1( allsig_l[i], win_left[add( i_mult( i, decimate ), decay )] ), new_audio[sub( sub( n, i ), 1 )] ); + wtda_audio[( i + ( L >> 1 ) )] = L_sub_sat( Mpy_32_16_1( allsig_l[i], win_left[( ( i * decimate ) + decay )] ), new_audio[( ( n - i ) - 1 )] ); move32(); } @@ -515,7 +515,7 @@ void wtda_fx32( idx2 = add( i_mult( i, decimate ), decay ); idx3 = sub( sub( L, i ), 1 ); idx4 = sub( sub( sub( i_mult( L, decimate ), i_mult( i, decimate ) ), 1 ), decay ); - wtda_audio[add( i, shr( L, 1 ) )] = L_sub_sat( Mpy_32_16_1( allsig_l[idx1], win_left[idx2] ), Mpy_32_16_1( allsig_l[idx3], win_left[idx4] ) ); + wtda_audio[( i + ( L >> 1 ) )] = L_sub_sat( Mpy_32_16_1( allsig_l[idx1], win_left[idx2] ), Mpy_32_16_1( allsig_l[idx3], win_left[idx4] ) ); move32(); } } diff --git a/lib_com/wtda_fx.c b/lib_com/wtda_fx.c index e94789a6a..1806638bb 100644 --- a/lib_com/wtda_fx.c +++ b/lib_com/wtda_fx.c @@ -59,7 +59,7 @@ static void mvs2s_dec( *--------------------------------------------------------------------------*/ static void copy_win( - Word16 *out_win, /* o : output window buffer */ + Word16 *out_win, /* o : output window buffer Q15*/ const Word16 nb_zero, /* i : length of zero padding */ const Word16 *in_win, /* i : input window */ const Word16 win_lenght, /* i : length */ @@ -69,7 +69,7 @@ static void copy_win( { IF( decimate < 0 ) { - set16_fx( out_win, 32767, nb_one ); + set16_fx( out_win, 32767, nb_one ); // Q15 mvs2s_inv( in_win, out_win + nb_one, win_lenght, negate( decimate ) ); set16_fx( out_win + add( win_lenght, nb_one ), 0, nb_zero ); } @@ -77,7 +77,7 @@ static void copy_win( { set16_fx( out_win, 0, nb_zero ); mvs2s_dec( in_win, out_win + nb_zero, win_lenght, decimate ); - set16_fx( out_win + add( nb_zero, win_lenght ), 32767, nb_one ); + set16_fx( out_win + add( nb_zero, win_lenght ), 32767, nb_one ); // Q15 } } /*--------------------------------------------------------------------------* @@ -102,12 +102,12 @@ void tcx_get_windows_mode1( test(); IF( EQ_16( L, 256 ) || EQ_16( L, 512 ) ) { - copy_win( left_win, R1_25 - 4 * R2_25 / 7, small_overlap_25, R2_25 / 7, 3 * R2_25 / 7, 1 ); + copy_win( left_win, R1_25 - 4 * R2_25 / 7, small_overlap_25, R2_25 / 7, 3 * R2_25 / 7, 1 ); // Q15 } ELSE { - copy_win( left_win, R1_48 - 4 * R2_48 / 7, small_overlap_48, R2_48 / 7, 3 * R2_48 / 7, 1 ); - copy_win( left_win_int, R1_16 - 4 * R2_16 / 7, small_overlap_int, R2_16 / 7, 3 * R2_16 / 7, 1 ); + copy_win( left_win, R1_48 - 4 * R2_48 / 7, small_overlap_48, R2_48 / 7, 3 * R2_48 / 7, 1 ); // Q15 + copy_win( left_win_int, R1_16 - 4 * R2_16 / 7, small_overlap_int, R2_16 / 7, 3 * R2_16 / 7, 1 ); // Q15 } } ELSE IF( EQ_16( left_mode, HALF_OVERLAP ) ) @@ -115,12 +115,12 @@ void tcx_get_windows_mode1( test(); IF( EQ_16( L, 256 ) || EQ_16( L, 512 ) ) { - copy_win( left_win, R1_25 - 5 * R2_25 / 7, half_overlap_25, 3 * R2_25 / 7, 2 * R2_25 / 7, 1 ); + copy_win( left_win, R1_25 - 5 * R2_25 / 7, half_overlap_25, 3 * R2_25 / 7, 2 * R2_25 / 7, 1 ); // Q15 } ELSE { - copy_win( left_win, R1_48 - 5 * R2_48 / 7, half_overlap_48, 3 * R2_48 / 7, 2 * R2_48 / 7, 1 ); - copy_win( left_win_int, R1_16 - 5 * R2_16 / 7, half_overlap_int, 3 * R2_16 / 7, 2 * R2_16 / 7, 1 ); + copy_win( left_win, R1_48 - 5 * R2_48 / 7, half_overlap_48, 3 * R2_48 / 7, 2 * R2_48 / 7, 1 ); // Q15 + copy_win( left_win_int, R1_16 - 5 * R2_16 / 7, half_overlap_int, 3 * R2_16 / 7, 2 * R2_16 / 7, 1 ); // Q15 } } ELSE IF( EQ_16( left_mode, ALDO_WINDOW ) ) /* ALDO */ @@ -128,12 +128,12 @@ void tcx_get_windows_mode1( test(); IF( EQ_16( L, 256 ) || EQ_16( L, 512 ) ) { - Copy( window_256kHz, left_win, R1_25 ); + Copy( window_256kHz, left_win, R1_25 ); // Q15 } ELSE { - Copy( window_48kHz_fx, left_win, R1_48 ); - Copy( window_8_16_32kHz_fx, left_win_int, R1_16 ); + Copy( window_48kHz_fx, left_win, R1_48 ); // Q15 + Copy( window_8_16_32kHz_fx, left_win_int, R1_16 ); // Q15 } } ELSE @@ -148,13 +148,13 @@ void tcx_get_windows_mode1( test(); IF( EQ_16( L, 256 ) || EQ_16( L, 512 ) ) { - copy_win( right_win, 3 * R2_25 / 7, small_overlap_25, R2_25 / 7, 3 * R2_25 / 7, -1 ); + copy_win( right_win, 3 * R2_25 / 7, small_overlap_25, R2_25 / 7, 3 * R2_25 / 7, -1 ); // Q15 } ELSE { - copy_win( right_win, 3 * R2_48 / 7, small_overlap_48, R2_48 / 7, 3 * R2_48 / 7, -1 ); - copy_win( right_win_int, 3 * R2_16 / 7, small_overlap_int, R2_16 / 7, 3 * R2_16 / 7, -1 ); + copy_win( right_win, 3 * R2_48 / 7, small_overlap_48, R2_48 / 7, 3 * R2_48 / 7, -1 ); // Q15 + copy_win( right_win_int, 3 * R2_16 / 7, small_overlap_int, R2_16 / 7, 3 * R2_16 / 7, -1 ); // Q15 } } ELSE IF( EQ_16( right_mode, HALF_OVERLAP ) ) @@ -162,12 +162,12 @@ void tcx_get_windows_mode1( test(); IF( EQ_16( L, 256 ) || EQ_16( L, 512 ) ) { - copy_win( right_win, 2 * R2_25 / 7, half_overlap_25, 3 * R2_25 / 7, 2 * R2_25 / 7, -1 ); + copy_win( right_win, 2 * R2_25 / 7, half_overlap_25, 3 * R2_25 / 7, 2 * R2_25 / 7, -1 ); // Q15 } ELSE { - copy_win( right_win, 2 * R2_48 / 7, half_overlap_48, 3 * R2_48 / 7, 2 * R2_48 / 7, -1 ); - copy_win( right_win_int, 2 * R2_16 / 7, half_overlap_int, 3 * R2_16 / 7, 2 * R2_16 / 7, -1 ); + copy_win( right_win, 2 * R2_48 / 7, half_overlap_48, 3 * R2_48 / 7, 2 * R2_48 / 7, -1 ); // Q15 + copy_win( right_win_int, 2 * R2_16 / 7, half_overlap_int, 3 * R2_16 / 7, 2 * R2_16 / 7, -1 ); // Q15 } } ELSE IF( EQ_16( right_mode, ALDO_WINDOW ) ) @@ -175,12 +175,12 @@ void tcx_get_windows_mode1( test(); IF( EQ_16( L, 256 ) || EQ_16( L, 512 ) ) { - Copy( window_256kHz + R1_25, right_win, R2_25 ); + Copy( window_256kHz + R1_25, right_win, R2_25 ); // Q15 } ELSE { - Copy( window_48kHz_fx + R1_48, right_win, R2_48 ); - Copy( window_8_16_32kHz_fx + R1_16, right_win_int, R2_16 ); + Copy( window_48kHz_fx + R1_48, right_win, R2_48 ); // Q15 + Copy( window_8_16_32kHz_fx + R1_16, right_win_int, R2_16 ); // Q15 } } ELSE diff --git a/lib_enc/acelp_core_enc.c b/lib_enc/acelp_core_enc.c index d2a43ac55..eef3bcbd2 100644 --- a/lib_enc/acelp_core_enc.c +++ b/lib_enc/acelp_core_enc.c @@ -1390,8 +1390,6 @@ ivas_error acelp_core_enc( *-----------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - - // Word16 pitch_buf_fx[NB_SUBFR16k]; floatToFixed_arr( pitch_buf, pitch_buf_fx, Q6, NB_SUBFR16k ); // Saturation Conversion used as last values have garbage values even in float floatToFixed_arr16( st->old_pitch_buf, st->old_pitch_buf_fx, Q6, 2 * NB_SUBFR16k ); @@ -1408,11 +1406,11 @@ ivas_error acelp_core_enc( floatToFixed_arr16( old_exc_flt, old_exc_fx, q_old_exc, L_EXC ); st->hLPDmem->e_old_exc = sub( 15, q_old_exc ); - Word16 q_old_bwe_exc; + Word16 q_old_bwe_exc = 0; IF( st->hBWE_TD != NULL ) { - q_old_bwe_exc = Q_factor_arr( old_bwe_exc, ( PIT16k_MAX + ( L_FRAME16k + 1 ) + L_SUBFR16k ) * 2 ); - floatToFixed_arr16( old_bwe_exc, old_bwe_exc_fx, q_old_bwe_exc, ( PIT16k_MAX + ( L_FRAME16k + 1 ) + L_SUBFR16k ) * 2 ); + q_old_bwe_exc = Q_factor_arr( &old_bwe_exc[L_FRAME32k], PIT16k_MAX * 2 ); + floatToFixed_arr16( &old_bwe_exc[L_FRAME32k], &old_bwe_exc_fx[L_FRAME32k], q_old_bwe_exc, PIT16k_MAX * 2 ); st->Q_exc = q_old_bwe_exc; } @@ -1421,20 +1419,43 @@ ivas_error acelp_core_enc( st->hGSCEnc->mid_dyn_fx = float_to_fix16( st->hGSCEnc->mid_dyn, Q7 ); } + if ( st->L_frame == L_FRAME ) + { + floatToFixed_arr( st->lsp_old, st->lsp_old_fx, Q15, M ); + } #endif // IVAS_FLOAT_FIXED_CONVERSIONS updt_enc_fx( st, old_exc_fx, pitch_buf_fx, Es_pred_fx, Aq_fx, lsf_new_fx, lsp_new_fx, old_bwe_exc_fx ); -#endif // IVAS_FLOAT_FIXED - +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + fixedToFloat_arr( st->hLPDmem->old_exc, st->hLPDmem->old_exc_flt, q_old_exc, L_EXC_MEM ); + IF( !st->Opt_AMR_WB && st->hBWE_TD != NULL ) + { + fixedToFloat_arr( st->hBWE_TD->old_bwe_exc_fx, st->hBWE_TD->old_bwe_exc, q_old_bwe_exc, PIT16k_MAX * 2 ); + } + fixedToFloat_arr( st->lsp_old_fx, st->lsp_old, Q15, M ); + for ( i = 0; i < M; i++ ) + { + st->lsf_old[i] = (float) ( st->lsf_old_fx[i] / 2.56f ); + } + st->hGSCEnc->mid_dyn = fixedToFloat( st->hGSCEnc->mid_dyn_fx, Q7 ); + IF( EQ_16( st->L_frame, L_FRAME ) ) + { + fixedToFloat_arr( st->lsp_old16k_fx, st->lsp_old16k, Q15, M ); + } + fixedToFloat_arr( st->old_pitch_buf_fx, st->old_pitch_buf, Q6, shl( shr( st->L_frame, 6 ), 1 ) ); // Q6 + fixedToFloat_arr( st->old_Aq_12_8_fx, st->old_Aq_12_8, Q12, M + 1 ); // Q12 + st->old_Es_pred = fixedToFloat( st->old_Es_pred_fx, Q8 ); +#endif +#else updt_enc( st, old_exc_flt, pitch_buf, Es_pred, Aq, lsf_new, lsp_new, old_bwe_exc ); +#endif // IVAS_FLOAT_FIXED if ( st->hTdCngEnc != NULL && st->Opt_DTX_ON && st->core_brate > SID_2k40 ) { /* update CNG parameters in active frames */ #ifdef IVAS_FLOAT_FIXED #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - Word16 q_exc = Q_factor_arr( exc, L_EXC - L_EXC_MEM ); q_exc = min( q_exc, Q_factor_arr( st->hTdCngEnc->cng_exc2_buf_flt, HO_HIST_SIZE * L_FFT ) ); floatToFixed_arr16( exc, exc_fx, q_exc, L_EXC - L_EXC_MEM ); @@ -1442,21 +1463,17 @@ ivas_error acelp_core_enc( floatToFixed_arr32( st->hTdCngEnc->ho_env_circ, st->hTdCngEnc->ho_env_circ_fx, Q6, HO_HIST_SIZE * NUM_ENV_CNG ); floatToFixed_arr16( st->hTdCngEnc->ho_lsp_circ, st->hTdCngEnc->ho_lsp_circ_fx, Q15, HO_HIST_SIZE * M ); - - // Backup - Word16 ho_circ_ptr = st->hTdCngEnc->ho_circ_ptr; - Word16 ho_circ_size = st->hTdCngEnc->ho_circ_size; - Word16 cng_buf_cnt = st->hTdCngEnc->cng_buf_cnt; - Word32 cng_brate_buf[HO_HIST_SIZE]; - for ( int j = 0; j < HO_HIST_SIZE; j++ ) - { - cng_brate_buf[j] = st->hTdCngEnc->cng_brate_buf[j]; - } - #endif // IVAS_FLOAT_FIXED_CONVERSIONS - - cng_params_upd_ivas_fx( lsp_new_fx, exc_fx, st->L_frame, &st->hTdCngEnc->ho_circ_ptr, st->hTdCngEnc->ho_ener_circ_fx, &st->hTdCngEnc->ho_circ_size, st->hTdCngEnc->ho_lsp_circ_fx, q_exc, ENC, st->hTdCngEnc->ho_env_circ_fx, &st->hTdCngEnc->cng_buf_cnt, st->hTdCngEnc->cng_exc2_buf, st->hTdCngEnc->cng_Qexc_buf, st->hTdCngEnc->cng_brate_buf, st->hDtxEnc->last_active_brate, st->element_mode, st->hFdCngEnc->hFdCngCom->CngBandwidth ); - + cng_params_upd_ivas_fx( lsp_new_fx, exc_fx, st->L_frame, &st->hTdCngEnc->ho_circ_ptr, st->hTdCngEnc->ho_ener_circ_fx, + &st->hTdCngEnc->ho_circ_size, st->hTdCngEnc->ho_lsp_circ_fx, q_exc, ENC, st->hTdCngEnc->ho_env_circ_fx, &st->hTdCngEnc->cng_buf_cnt, + st->hTdCngEnc->cng_exc2_buf, st->hTdCngEnc->cng_Qexc_buf, st->hTdCngEnc->cng_brate_buf, st->hDtxEnc->last_active_brate, st->element_mode, + st->hFdCngEnc->hFdCngCom->CngBandwidth ); +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + fixedToFloat_arr( st->hTdCngEnc->ho_lsp_circ_fx, st->hTdCngEnc->ho_lsp_circ, Q15, HO_HIST_SIZE * M ); + fixedToFloat_arrL( st->hTdCngEnc->ho_env_circ_fx, st->hTdCngEnc->ho_env_circ, Q6, HO_HIST_SIZE * NUM_ENV_CNG ); + fixedToFloat_arr( st->hTdCngEnc->cng_exc2_buf, st->hTdCngEnc->cng_exc2_buf_flt, Q6, HO_HIST_SIZE * L_FFT ); +#endif +#else #ifdef IVAS_FLOAT_FIXED_CONVERSIONS // Restore st->hTdCngEnc->ho_circ_ptr = ho_circ_ptr; @@ -1467,9 +1484,9 @@ ivas_error acelp_core_enc( st->hTdCngEnc->cng_brate_buf[j] = cng_brate_buf[j]; } #endif // IVAS_FLOAT_FIXED_CONVERSIONS -#endif // IVAS_FLOAT_FIXED cng_params_upd( lsp_new, exc, st->L_frame, &st->hTdCngEnc->ho_circ_ptr, st->hTdCngEnc->ho_ener_circ, &st->hTdCngEnc->ho_circ_size, st->hTdCngEnc->ho_lsp_circ, ENC, st->hTdCngEnc->ho_env_circ, &st->hTdCngEnc->cng_buf_cnt, st->hTdCngEnc->cng_exc2_buf_flt, st->hTdCngEnc->cng_brate_buf, st->hDtxEnc->last_active_brate, st->element_mode, st->hFdCngEnc->hFdCngCom->CngBandwidth ); +#endif // IVAS_FLOAT_FIXED #ifndef IVAS_FLOAT_FIXED if ( st->L_frame == L_FRAME ) diff --git a/lib_enc/core_enc_reconf.c b/lib_enc/core_enc_reconf.c index b02d0c438..08278149f 100644 --- a/lib_enc/core_enc_reconf.c +++ b/lib_enc/core_enc_reconf.c @@ -56,7 +56,11 @@ void core_coder_reconfig( int16_t bwidth, i, index; /*Configuration of ACELP*/ +#ifndef IVAS_FLOAT_FIXED BITS_ALLOC_init_config_acelp_IVAS( st->total_brate, st->narrowBand, st->nb_subfr, &( st->acelp_cfg ) ); +#else + BITS_ALLOC_init_config_acelp( st->total_brate, st->narrowBand, st->nb_subfr, &( st->acelp_cfg ) ); +#endif /*Configuration of partial copy*/ if ( st->Opt_RF_ON ) @@ -68,8 +72,13 @@ void core_coder_reconfig( st->hRF->acelp_cfg_rf.formant_enh = 1; st->hRF->acelp_cfg_rf.formant_tilt = 1; st->hRF->acelp_cfg_rf.voice_tilt = 1; +#ifndef IVAS_FLOAT_FIXED st->hRF->acelp_cfg_rf.formant_enh_num_flt = FORMANT_SHARPENING_G1_FLT; st->hRF->acelp_cfg_rf.formant_enh_den_flt = FORMANT_SHARPENING_G2_FLT; +#else + st->hRF->acelp_cfg_rf.formant_enh_num = FORMANT_SHARPENING_G1; + st->hRF->acelp_cfg_rf.formant_enh_den = FORMANT_SHARPENING_G2; +#endif } if ( st->element_mode == IVAS_CPE_MDCT ) diff --git a/lib_enc/igf_enc.c b/lib_enc/igf_enc.c index bc926b32d..a78e88139 100644 --- a/lib_enc/igf_enc.c +++ b/lib_enc/igf_enc.c @@ -3827,7 +3827,11 @@ void IGFEncSetMode( set_f( hPrivateData->SFM_sb, 0.f, IGF_MAX_SFB ); set_f( hPrivateData->SFM_tb, 0.f, IGF_MAX_SFB ); +#ifndef IVAS_FLOAT_FIXED if ( IGFCommonFuncsIGFConfiguration_flt( total_brate, bwidth, element_mode, &hPrivateData->igfInfo, rf_mode ) ) +#else + IF( IGFCommonFuncsIGFConfiguration_ivas_fx( total_brate, bwidth, element_mode, &hPrivateData->igfInfo, rf_mode ) ) +#endif { IGFSCFEncoderOpen( &hPrivateData->hIGFSCFArithEnc, &hPrivateData->igfInfo, total_brate, bwidth, element_mode, rf_mode ); diff --git a/lib_enc/ivas_agc_enc.c b/lib_enc/ivas_agc_enc.c index cd20bc222..51ddc9080 100644 --- a/lib_enc/ivas_agc_enc.c +++ b/lib_enc/ivas_agc_enc.c @@ -430,6 +430,7 @@ ivas_error ivas_spar_agc_enc_open_fx( * Deallocate SPAR AGC encoder handle *------------------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED void ivas_spar_agc_enc_close( ivas_agc_enc_state_t **hAgcEnc /* i/o: SPAR AGC encoder handle */ ) @@ -457,8 +458,7 @@ void ivas_spar_agc_enc_close( return; } - -#ifdef IVAS_FLOAT_FIXED +#else void ivas_spar_agc_enc_close_fx( ivas_agc_enc_state_t **hAgcEnc /* i/o: SPAR AGC encoder handle */ ) @@ -495,6 +495,7 @@ void ivas_spar_agc_enc_close_fx( * AGC encoder *-----------------------------------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED void ivas_agc_enc_process( ivas_agc_enc_state_t *hAgcEnc, /* i/o: AGC encoder handle */ BSTR_ENC_HANDLE hMetaData, /* i/o: MetaData handle */ @@ -725,8 +726,7 @@ void ivas_agc_enc_process( return; } - -#ifdef IVAS_FLOAT_FIXED +#else void ivas_agc_enc_process_fx( ivas_agc_enc_state_t *hAgcEnc, /* i/o: AGC encoder handle */ BSTR_ENC_HANDLE hMetaData, /* i/o: MetaData handle */ diff --git a/lib_enc/ivas_cpe_enc.c b/lib_enc/ivas_cpe_enc.c index 2b8930a55..ec599c5fc 100644 --- a/lib_enc/ivas_cpe_enc.c +++ b/lib_enc/ivas_cpe_enc.c @@ -1144,14 +1144,19 @@ ivas_error ivas_cpe_enc( Etot_last_fx[1] = float_to_fix16( Etot_last[1], Q8 ); #endif tdm_configure_enc_fx( ivas_format, st_ivas->ism_mode, hCPE, Etot_last_fx, tdm_SM_or_LRTD_Pri, tdm_ratio_idx, tdm_ratio_idx_SM, attack_flag[0], nb_bits_metadata ); + + IF( hEncoderConfig->Opt_DTX_ON ) + { + stereo_cng_upd_counters_fx( hCPE->hStereoCng, hCPE->element_mode, -1, NULL, sts[0]->hTdCngEnc->burst_ho_cnt, NULL ); + } #else tdm_configure_enc( ivas_format, st_ivas->ism_mode, hCPE, Etot_last, tdm_SM_or_LRTD_Pri, tdm_ratio_idx, tdm_ratio_idx_SM, attack_flag[0], nb_bits_metadata ); -#endif if ( hEncoderConfig->Opt_DTX_ON ) { stereo_cng_upd_counters( hCPE->hStereoCng, hCPE->element_mode, -1, NULL, sts[0]->hTdCngEnc->burst_ho_cnt, NULL ); } +#endif } /* modify the coder_type depending on the total_brate per channel */ @@ -2344,7 +2349,11 @@ ivas_error create_cpe_enc( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Stereo Cng for Unified/TD \n" ) ); } +#ifndef IVAS_FLOAT_FIXED stereo_enc_cng_init( hCPE->hStereoCng ); +#else + stereo_enc_cng_init_fx( hCPE->hStereoCng ); +#endif } } else @@ -2634,7 +2643,7 @@ ivas_error create_cpe_enc_fx( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Stereo Cng for Unified/TD \n" ) ); } - stereo_enc_cng_init( hCPE->hStereoCng ); + stereo_enc_cng_init_fx( hCPE->hStereoCng ); } } ELSE diff --git a/lib_enc/ivas_enc.c b/lib_enc/ivas_enc.c index d2e4487b3..9c114e061 100644 --- a/lib_enc/ivas_enc.c +++ b/lib_enc/ivas_enc.c @@ -801,10 +801,7 @@ ivas_error ivas_enc( for ( i = 0; i < st_ivas->hEncoderConfig->nchan_ism; i++ ) { floatToFixed_arr32( st_ivas->hParamIsm->hFbMixer->ppFilterbank_prior_input[i], st_ivas->hParamIsm->hFbMixer->ppFilterbank_prior_input_fx[i], Q14, st_ivas->hParamIsm->hFbMixer->fb_cfg->prior_input_length ); - st_ivas->hParamIsm->last_cardioid_left_fx[i] = float_to_fix16( st_ivas->hParamIsm->last_cardioid_left[i], Q14 ); } - st_ivas->hParamIsm->last_dmx_gain_e = 15 - norm_s( (Word16) st_ivas->hParamIsm->last_dmx_gain ); - st_ivas->hParamIsm->last_dmx_gain_fx = float_to_fix16( st_ivas->hParamIsm->last_dmx_gain, 15 - st_ivas->hParamIsm->last_dmx_gain_e ); #endif ivas_param_ism_enc_fx( st_ivas, data_fx, input_frame, Q14 ); @@ -820,10 +817,7 @@ ivas_error ivas_enc( for ( i = 0; i < st_ivas->hEncoderConfig->nchan_ism; i++ ) { fixedToFloat_arrL32( st_ivas->hParamIsm->hFbMixer->ppFilterbank_prior_input_fx[i], st_ivas->hParamIsm->hFbMixer->ppFilterbank_prior_input[i], Q14, st_ivas->hParamIsm->hFbMixer->fb_cfg->prior_input_length ); - st_ivas->hParamIsm->last_cardioid_left[i] = fixedToFloat_16( st_ivas->hParamIsm->last_cardioid_left_fx[i], Q14 ); } - - st_ivas->hParamIsm->last_dmx_gain = fixedToFloat_16( st_ivas->hParamIsm->last_dmx_gain_fx, 15 - st_ivas->hParamIsm->last_dmx_gain_e ); #endif #else ivas_param_ism_enc( st_ivas, data_f, input_frame ); diff --git a/lib_enc/ivas_ism_dtx_enc.c b/lib_enc/ivas_ism_dtx_enc.c index 5b90cb9f8..a0f76b78f 100644 --- a/lib_enc/ivas_ism_dtx_enc.c +++ b/lib_enc/ivas_ism_dtx_enc.c @@ -635,8 +635,7 @@ void ivas_ism_get_sce_id_dtx_fx( return; } -#endif // IVAS_FLOAT_FIXED - +#else void ivas_ism_get_sce_id_dtx( ISM_DTX_HANDLE hISMDTX, /* i/o: ISM DTX handle */ SCE_ENC_HANDLE hSCE[MAX_SCE], /* i/o: SCE encoder structure */ @@ -682,7 +681,7 @@ void ivas_ism_get_sce_id_dtx( return; } - +#endif // IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* * ivas_ism_coh_estim_dtx_enc() @@ -775,8 +774,7 @@ void ivas_ism_coh_estim_dtx_enc_fx( return; } -#endif // IVAS_FLOAT_FIXED - +#else void ivas_ism_coh_estim_dtx_enc( ISM_DTX_HANDLE hISMDTX, /* i/o: ISM DTX handle */ SCE_ENC_HANDLE hSCE[MAX_SCE], /* i/o: SCE encoder structure */ @@ -831,3 +829,4 @@ void ivas_ism_coh_estim_dtx_enc( return; } +#endif // IVAS_FLOAT_FIXED diff --git a/lib_enc/ivas_ism_enc.c b/lib_enc/ivas_ism_enc.c index 78eb1974d..47423d868 100644 --- a/lib_enc/ivas_ism_enc.c +++ b/lib_enc/ivas_ism_enc.c @@ -617,20 +617,12 @@ ivas_error ivas_ism_enc( *-----------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - if ( st_ivas->hISMDTX ) - { - floatToFixed_arr16( st_ivas->hISMDTX->coh, st_ivas->hISMDTX->coh_fx, Q15, st_ivas->nchan_transport ); - } - /* compute the dominant sce_id using long term energy */ for ( int j = 0; j < st_ivas->nchan_transport; j++ ) { IF( st_ivas->hSCE[j] && st_ivas->hSCE[j]->hCoreCoder[0] ) floatToFixed_arrL( st_ivas->hSCE[j]->hCoreCoder[0]->input, st_ivas->hSCE[j]->hCoreCoder[0]->input32_fx, Q11, input_frame ); /*Q0*/ } - IF( st_ivas->hISMDTX ) - f2me_buf( &st_ivas->hISMDTX->long_term_energy_stereo_dmx_enc[0][0], &st_ivas->hISMDTX->long_term_energy_stereo_dmx_enc_fx[0][0], &st_ivas->hISMDTX->long_term_energy_stereo_dmx_enc_e, st_ivas->nchan_transport * PARAM_ISM_HYS_BUF_SIZE ); - FOR( sce_id = 0; sce_id < nchan_transport_ism; sce_id++ ) { relE_fx[sce_id][0] = float_to_fix16( relE[sce_id][0], Q8 ); @@ -833,14 +825,6 @@ ivas_error ivas_ism_enc( pop_wmops(); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - IF( st_ivas->hISMDTX ) - { - me2f_buf( &st_ivas->hISMDTX->long_term_energy_stereo_dmx_enc_fx[0][0], st_ivas->hISMDTX->long_term_energy_stereo_dmx_enc_e, &st_ivas->hISMDTX->long_term_energy_stereo_dmx_enc[0][0], st_ivas->nchan_transport * PARAM_ISM_HYS_BUF_SIZE ); - fixedToFloat_arr( st_ivas->hISMDTX->coh_fx, st_ivas->hISMDTX->coh, Q15, st_ivas->nchan_transport ); - } -#endif - return error; } #endif diff --git a/lib_enc/ivas_masa_enc.c b/lib_enc/ivas_masa_enc.c index 4c27158a0..baebbcee5 100644 --- a/lib_enc/ivas_masa_enc.c +++ b/lib_enc/ivas_masa_enc.c @@ -8703,7 +8703,7 @@ static void ivas_encode_masaism_metadata_fx( } ELSE { - hOmasaData->masa_to_total_energy_ratio_fx[sf][band] = MAX_32; + hOmasaData->masa_to_total_energy_ratio_fx[sf][band] = ONE_IN_Q30; move32(); } } diff --git a/lib_enc/ivas_pca_enc.c b/lib_enc/ivas_pca_enc.c index 17cd24ba3..aff3a54e9 100644 --- a/lib_enc/ivas_pca_enc.c +++ b/lib_enc/ivas_pca_enc.c @@ -113,26 +113,11 @@ static void pca_enc_reset( return; } #else -static void pca_enc_reset( +static void pca_enc_reset_fx( PCA_ENC_STATE *hPCA ) { Word16 i; -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - /* reset states for interpolation and multiplexing */ - eye_matrix( hPCA->prev_eigVec, FOA_CHANNELS, 1.0f ); - set_zero( hPCA->prev_ql, IVAS_PCA_INTERP ); - hPCA->prev_ql[0] = 1.0f; - set_zero( hPCA->prev_qr, IVAS_PCA_INTERP ); - hPCA->prev_qr[0] = 1.0f; - FOR( i = 0; i < FOA_CHANNELS; i++ ) - { - hPCA->prev_D[i] = 0.25f; - } - eye_matrix( hPCA->mem_eigVec_interp, FOA_CHANNELS, 1.0f ); - set_zero( hPCA->old_r_sm, FOA_CHANNELS * FOA_CHANNELS ); -#endif - eye_matrix_fx( hPCA->prev_eigVec_fx, FOA_CHANNELS, MAX_WORD16 ); set16_fx( hPCA->prev_ql_fx, 0, IVAS_PCA_INTERP ); hPCA->prev_ql_fx[0] = MAX_WORD16; @@ -142,7 +127,7 @@ static void pca_enc_reset( move16(); FOR( i = 0; i < FOA_CHANNELS; i++ ) { - hPCA->prev_D_fx[i] = shr( MAX_WORD16, 2 ); // 0.25 in Q15 + hPCA->prev_D_fx[i] = ONE_IN_Q13; // 0.25 in Q15 move16(); } eye_matrix_fx( hPCA->mem_eigVec_interp_fx, FOA_CHANNELS, MAX_WORD16 ); @@ -154,6 +139,7 @@ static void pca_enc_reset( } #endif +#ifndef IVAS_FLOAT_FIXED static void pca_transform_sub( float *eigVec, float *transformed_data[8], /* i : input/transformed audio channels */ @@ -183,8 +169,7 @@ static void pca_transform_sub( return; } - -#ifdef IVAS_FLOAT_FIXED +#else static void pca_transform_sub_fx( Word16 *eigVec, Word32 *transformed_data[8], /* i : input/transformed audio channels Q11 */ @@ -219,9 +204,9 @@ static void pca_transform_sub_fx( return; } - #endif +#ifndef IVAS_FLOAT_FIXED static void pca_enc_transform( PCA_ENC_STATE *hPCA, float *ql, @@ -250,9 +235,7 @@ static void pca_enc_transform( return; } - - -#ifdef IVAS_FLOAT_FIXED +#else static void pca_enc_transform_fx( PCA_ENC_STATE *hPCA, Word16 *ql_fx, // Q15 @@ -282,6 +265,7 @@ static void pca_enc_transform_fx( } #endif +#ifndef IVAS_FLOAT_FIXED static void pca_update_state( PCA_ENC_STATE *hPCA, float *ql, @@ -295,9 +279,7 @@ static void pca_update_state( return; } - - -#ifdef IVAS_FLOAT_FIXED +#else static void pca_update_state_fx( PCA_ENC_STATE *hPCA, Word16 *ql, // Q15 @@ -313,6 +295,7 @@ static void pca_update_state_fx( } #endif +#ifndef IVAS_FLOAT_FIXED static void swap_eigvec( float *eigVec, const int16_t i, @@ -336,8 +319,7 @@ static void swap_eigvec( return; } - -#ifdef IVAS_FLOAT_FIXED +#else static void swap_eigvec_fx( Word32 *eigVec, // Q31 const Word32 i, @@ -366,6 +348,7 @@ static void swap_eigvec_fx( } #endif +#ifndef IVAS_FLOAT_FIXED static void sort4_D_eigVec( float *D, float *eigVec ) @@ -408,8 +391,7 @@ static void sort4_D_eigVec( return; } - -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS +#else static void sort4_D_eigVec_fx( Word32 *D, // Q Word32 *eigVec // Q31 @@ -460,14 +442,15 @@ static void sort4_D_eigVec_fx( * * Initialize PCA encoder *------------------------------------------------------------------------*/ + #ifdef IVAS_FLOAT_FIXED -void ivas_pca_enc_init( +void ivas_pca_enc_init_fx( PCA_ENC_STATE *hPCA /* i/o: PCA encoder structure */ ) { hPCA->prev_bypass_decision = PCA_MODE_INACTIVE; move32(); - pca_enc_reset( hPCA ); + pca_enc_reset_fx( hPCA ); return; } @@ -489,6 +472,7 @@ void ivas_pca_enc_init( * PCA encoder *------------------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED void ivas_pca_enc( const ENCODER_CONFIG_HANDLE hEncoderConfig, /* i : configuration structure */ PCA_ENC_STATE *hPCA, /* i : PCA encoder structure */ @@ -824,7 +808,7 @@ void ivas_pca_enc( return; } - +#else void ivas_pca_enc_fx( const ENCODER_CONFIG_HANDLE hEncoderConfig, /* i : configuration structure */ PCA_ENC_STATE *hPCA, /* i : PCA encoder structure */ @@ -878,7 +862,7 @@ void ivas_pca_enc_fx( /* handle bitrate switching */ IF( NE_32( ivas_total_brate, PCA_BRATE ) ) { - pca_enc_reset( hPCA ); + pca_enc_reset_fx( hPCA ); IF( NE_32( hEncoderConfig->last_ivas_total_brate, PCA_BRATE ) ) { @@ -1270,3 +1254,4 @@ void ivas_pca_enc_fx( pca_update_state_fx( hPCA, ql_fx, qr_fx, eigVec_fx16, n_channels ); return; } +#endif diff --git a/lib_enc/ivas_spar_encoder.c b/lib_enc/ivas_spar_encoder.c index 9ffd91825..af5829365 100644 --- a/lib_enc/ivas_spar_encoder.c +++ b/lib_enc/ivas_spar_encoder.c @@ -213,7 +213,11 @@ ivas_error ivas_spar_enc_open( { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR PCA encoder" ); } +#ifndef IVAS_FLOAT_FIXED ivas_pca_enc_init( hSpar->hPCA ); +#else + ivas_pca_enc_init_fx( hSpar->hPCA ); +#endif } /* initialization */ @@ -407,7 +411,7 @@ ivas_error ivas_spar_enc_open_fx( { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR PCA encoder" ); } - ivas_pca_enc_init( hSpar->hPCA ); + ivas_pca_enc_init_fx( hSpar->hPCA ); } /* initialization */ @@ -1459,13 +1463,6 @@ static ivas_error ivas_spar_enc_process( p_pcm_tmp[i][j] = fix_to_float( p_pcm_tmp_fx[i][j], q_pcm_fx[i] ); } } - fixedToFloat_arr( hSpar->hPCA->prev_qr_fx, hSpar->hPCA->prev_qr, Q15, IVAS_PCA_INTERP ); - fixedToFloat_arr( hSpar->hPCA->prev_ql_fx, hSpar->hPCA->prev_ql, Q15, IVAS_PCA_INTERP ); - fixedToFloat_arr( hSpar->hPCA->prev_eigVec_fx, hSpar->hPCA->prev_eigVec, Q15, FOA_CHANNELS * FOA_CHANNELS ); - FOR( Word16 k = 0; k < 16; k++ ) - { - hSpar->hPCA->old_r_sm[k] = fixedToFloat( hSpar->hPCA->old_r_sm_fx[k], hSpar->hPCA->old_r_sm_q ); - } #else ivas_pca_enc( hEncoderConfig, hSpar->hPCA, hMetaData, p_pcm_tmp, input_frame, FOA_CHANNELS ); #endif diff --git a/lib_enc/ivas_spar_md_enc.c b/lib_enc/ivas_spar_md_enc.c index 1b07f61a6..11c2007a1 100644 --- a/lib_enc/ivas_spar_md_enc.c +++ b/lib_enc/ivas_spar_md_enc.c @@ -457,7 +457,7 @@ ivas_error ivas_spar_md_enc_init( } } } - hMdEnc->q_mixer_mat_fx = Q31; + hMdEnc->q_mixer_mat_fx = Q30; move16(); #endif diff --git a/lib_enc/ivas_stat_enc.h b/lib_enc/ivas_stat_enc.h index eae425507..84b5fa9cb 100644 --- a/lib_enc/ivas_stat_enc.h +++ b/lib_enc/ivas_stat_enc.h @@ -313,7 +313,9 @@ typedef struct stereo_dft_enc_data_struct int16_t res_pred_flag_1; int16_t res_pred_flag_2; int16_t res_pred_counter; +#ifndef IVAS_FLOAT_FIXED float res_pred_gain_f[STEREO_DFT_BAND_MAX]; +#endif int16_t res_pred_index_EC[STEREO_DFT_BAND_MAX]; int16_t res_pred_index_ECDiff[STEREO_DFT_BAND_MAX]; int16_t res_pred_index_ECprevious[STEREO_DFT_BAND_MAX]; @@ -331,7 +333,9 @@ typedef struct stereo_dft_enc_data_struct float res_cod_NRG_M[STEREO_DFT_BAND_MAX]; float res_cod_NRG_S[STEREO_DFT_BAND_MAX]; float res_cod_SNR_M[STEREO_DFT_BAND_MAX]; +#ifndef IVAS_FLOAT_FIXED float old_snr; +#endif int16_t first_frm_flag; /* ADAP first frame flag */ /* flags and data for adaptive wideband residual coding */ @@ -884,13 +888,15 @@ typedef struct Word16 long_term_energy_stereo_dmx_enc_e; Word16 coh_fx[MAX_NUM_OBJECTS]; #endif // IVAS_FLOAT_FIXED - int16_t dtx_flag; - int16_t sce_id_dtx; + Word16 dtx_flag; + Word16 sce_id_dtx; - int16_t cnt_SID_ISM; + Word16 cnt_SID_ISM; +#ifndef IVAS_FLOAT_FIXED float long_term_energy_stereo_dmx_enc[MAX_NUM_OBJECTS][PARAM_ISM_HYS_BUF_SIZE]; float coh[MAX_NUM_OBJECTS]; +#endif } ISM_DTX_DATA, *ISM_DTX_HANDLE; /*----------------------------------------------------------------------------------* @@ -1002,33 +1008,38 @@ typedef struct ivas_dirac_enc_data_structure /* AGC structures */ typedef struct ivas_agc_enc_chan_state_t { - int16_t lastExp; - int16_t prevExp; + Word16 lastExp; + Word16 prevExp; +#ifndef IVAS_FLOAT_FIXED float lastGain; float lastMaxAbs; - int16_t gainExpVal; - float MaxAbsVal_del; - int16_t MaxAbsValIdx_del; -#ifdef IVAS_FLOAT_FIXED - Word32 lastGain_fx; - Word32 lastMaxAbs_fx; - Word32 MaxAbsVal_del_fx; +#else + Word32 lastGain_fx; /* Q(q_lastGain_fx) */ Word16 q_lastGain_fx; + Word32 lastMaxAbs_fx; /* Q(q_lastMaxAbs_fx) */ Word16 q_lastMaxAbs_fx; +#endif + Word16 gainExpVal; +#ifndef IVAS_FLOAT_FIXED + float MaxAbsVal_del; +#else + Word32 MaxAbsVal_del_fx; /* Q(q_MaxAbsVal_del_fx) */ Word16 q_MaxAbsVal_del_fx; #endif + Word16 MaxAbsValIdx_del; } ivas_agc_enc_chan_state_t; typedef struct ivas_agc_enc_state_t { ivas_agc_com_state_t agc_com; -#ifdef IVAS_FLOAT_FIXED - Word32 minDelta_fx; - Word32 smFact_fx; -#endif +#ifndef IVAS_FLOAT_FIXED float minDelta; float smFact; +#else + Word32 minDelta_fx; /* Q31 */ + Word32 smFact_fx; /* Q31 */ +#endif ivas_agc_enc_chan_state_t *gain_state; ivas_agc_chan_data_t *gain_data; @@ -1073,15 +1084,15 @@ typedef struct ivas_spar_md_enc_state_t /* PCA structure */ typedef struct { - int16_t prev_bypass_decision; + Word16 prev_bypass_decision; +#ifndef IVAS_FLOAT_FIXED float prev_eigVec[FOA_CHANNELS * FOA_CHANNELS]; float prev_ql[IVAS_PCA_INTERP]; float prev_qr[IVAS_PCA_INTERP]; float prev_D[IVAS_PCA_INTERP]; float mem_eigVec_interp[FOA_CHANNELS * FOA_CHANNELS]; float old_r_sm[FOA_CHANNELS * FOA_CHANNELS]; - -#ifdef IVAS_FLOAT_FIXED +#else Word16 prev_eigVec_fx[FOA_CHANNELS * FOA_CHANNELS]; // Q15 Word16 prev_ql_fx[IVAS_PCA_INTERP]; // Q15 Word16 prev_qr_fx[IVAS_PCA_INTERP]; // Q15 @@ -1129,24 +1140,28 @@ typedef struct ivas_spar_enc_lib_t typedef struct ivas_param_mc_enc_data_structure { IVAS_FB_MIXER_HANDLE hFbMixer; - int16_t transient_detector_delay; + Word16 transient_detector_delay; +#ifndef IVAS_FLOAT_FIXED const float *dmx_factors; - - const Word32 *dmx_factors_fx; +#else + const Word32 *dmx_factors_fx; /* Q31 */ +#endif /* Multichannel Specific Parameters */ IVAS_PARAM_MC_METADATA hMetadataPMC; - int16_t band_grouping[PARAM_MC_MAX_PARAMETER_BANDS + 1]; - int16_t lfe_index; - int16_t icc_map_index[PARAM_MC_PARAMETER_FRAMES][PARAM_MC_SZ_ICC_MAP]; - int16_t max_param_band_abs_cov; + Word16 band_grouping[PARAM_MC_MAX_PARAMETER_BANDS + 1]; + Word16 lfe_index; + Word16 icc_map_index[PARAM_MC_PARAMETER_FRAMES][PARAM_MC_SZ_ICC_MAP]; + Word16 max_param_band_abs_cov; +#ifndef IVAS_FLOAT_FIXED float prev_ilds[PARAM_MC_MAX_PARAMETER_BANDS][PARAM_MC_SZ_ILD_MAP]; - Word32 prev_ilds_fx[PARAM_MC_MAX_PARAMETER_BANDS][PARAM_MC_SZ_ILD_MAP]; /*Q21*/ - float ener_fac[PARAM_MC_MAX_PARAMETER_BANDS]; +#else + Word32 prev_ilds_fx[PARAM_MC_MAX_PARAMETER_BANDS][PARAM_MC_SZ_ILD_MAP]; /*Q21*/ Word32 ener_fac_fx[PARAM_MC_MAX_PARAMETER_BANDS]; /*Q21*/ +#endif } PARAM_MC_ENC_DATA, *PARAM_MC_ENC_HANDLE; @@ -1487,23 +1502,24 @@ typedef struct ivas_osba_enc_data_structure typedef struct stereo_cng_enc { - Word16 prev_sg_average_counter; /* Counter for sidegain averaging */ - Word16 sg_active_cnt; /* Counter for sidegain averaging */ - Word16 sg_average_counter; /* Counter for sidegain averaging */ - float sg_average[STEREO_DFT_ERB4_BANDS]; /* Sidegain average */ -#ifndef IVAS_FLOAT_FIXED - float prev_sg_average[STEREO_DFT_ERB4_BANDS]; /* Previous sidegain average */ -#endif - float mem_cohBand[STEREO_DFT_BAND_MAX / 2]; /* Coherence memory */ - float prev_cohBand[2 * ( STEREO_DFT_BAND_MAX / 2 )]; /* Previous coherence */ - Word16 cng_counter; /* Counter for cng period length */ - Word16 td_active; /* TD-stereo indication */ - Word16 first_SID_after_TD; /* Set if first SID frame after TD stereo */ - Word16 first_SID; /* Set if first SID frame since codec start */ + Word16 prev_sg_average_counter; /* Counter for sidegain averaging */ + Word16 sg_active_cnt; /* Counter for sidegain averaging */ + Word16 sg_average_counter; /* Counter for sidegain averaging */ +#ifndef IVAS_FLOAT_FIXED + float sg_average[STEREO_DFT_ERB4_BANDS]; /* Sidegain average */ + float prev_sg_average[STEREO_DFT_ERB4_BANDS]; /* Previous sidegain average */ + float mem_cohBand[STEREO_DFT_BAND_MAX / 2]; /* Coherence memory */ + float prev_cohBand[2 * ( STEREO_DFT_BAND_MAX / 2 )]; /* Previous coherence */ +#else Word32 sg_average_fx[STEREO_DFT_ERB4_BANDS]; /* Sidegain average Q26 */ - Word32 prev_sg_average_fx[STEREO_DFT_ERB4_BANDS]; /* Previous sidegain average Q26 */ - Word32 mem_cohBand_fx[STEREO_DFT_BAND_MAX / 2]; /* Coherence memory */ - Word32 prev_cohBand_fx[2 * ( STEREO_DFT_BAND_MAX / 2 )]; /* Previous coherence */ + Word32 prev_sg_average_fx[STEREO_DFT_ERB4_BANDS]; /* Previous sidegain average Q26 */ + Word32 mem_cohBand_fx[STEREO_DFT_BAND_MAX / 2]; /* Coherence memory Q31 */ + Word32 prev_cohBand_fx[2 * ( STEREO_DFT_BAND_MAX / 2 )]; /* Previous coherence Q31 */ +#endif + Word16 cng_counter; /* Counter for cng period length */ + Word16 td_active; /* TD-stereo indication */ + Word16 first_SID_after_TD; /* Set if first SID frame after TD stereo */ + Word16 first_SID; /* Set if first SID frame since codec start */ } STEREO_CNG_ENC, *STEREO_CNG_ENC_HANDLE; diff --git a/lib_enc/ivas_stereo_cng_enc.c b/lib_enc/ivas_stereo_cng_enc.c index a9dc30e44..7fd2e4766 100644 --- a/lib_enc/ivas_stereo_cng_enc.c +++ b/lib_enc/ivas_stereo_cng_enc.c @@ -1011,35 +1011,52 @@ void stereo_dft_cng_side_gain( * Initializes counters and averages * ---------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +void stereo_enc_cng_init_fx( + STEREO_CNG_ENC_HANDLE hStereoCng /* i/o: stereo CNG encoder structure */ +) +{ + hStereoCng->sg_average_counter = 0; + move16(); + set32_fx( hStereoCng->sg_average_fx, 0, STEREO_DFT_BAND_MAX ); + hStereoCng->prev_sg_average_counter = 0; + move16(); + set32_fx( hStereoCng->prev_sg_average_fx, 0, STEREO_DFT_BAND_MAX ); + hStereoCng->sg_active_cnt = 0; + move16(); + hStereoCng->first_SID = 1; + move16(); + set32_fx( hStereoCng->mem_cohBand_fx, ONE_IN_Q30, STEREO_DFT_BAND_MAX / 2 ); + set32_fx( hStereoCng->prev_cohBand_fx, 0, 2 * ( STEREO_DFT_BAND_MAX / 2 ) ); + hStereoCng->td_active = 0; + move16(); + hStereoCng->first_SID_after_TD = 1; + move16(); + hStereoCng->cng_counter = 0; + move16(); + + return; +} +#else void stereo_enc_cng_init( STEREO_CNG_ENC_HANDLE hStereoCng /* i/o: stereo CNG encoder structure */ ) { hStereoCng->sg_average_counter = 0; set_zero( hStereoCng->sg_average, STEREO_DFT_BAND_MAX ); -#ifdef IVAS_FLOAT_FIXED - set32_fx( hStereoCng->sg_average_fx, 0, STEREO_DFT_BAND_MAX ); -#endif hStereoCng->prev_sg_average_counter = 0; -#ifndef IVAS_FLOAT_FIXED set_zero( hStereoCng->prev_sg_average, STEREO_DFT_BAND_MAX ); -#else - set32_fx( hStereoCng->prev_sg_average_fx, 0, STEREO_DFT_BAND_MAX ); -#endif hStereoCng->sg_active_cnt = 0; hStereoCng->first_SID = 1; set_f( hStereoCng->mem_cohBand, 0.5f, STEREO_DFT_BAND_MAX / 2 ); /*Q31*/ set_zero( hStereoCng->prev_cohBand, 2 * ( STEREO_DFT_BAND_MAX / 2 ) ); -#ifdef IVAS_FLOAT_FIXED - set32_fx( hStereoCng->mem_cohBand_fx, ONE_IN_Q30, STEREO_DFT_BAND_MAX / 2 ); - set32_fx( hStereoCng->prev_cohBand_fx, 0, 2 * ( STEREO_DFT_BAND_MAX / 2 ) ); -#endif hStereoCng->td_active = 0; hStereoCng->first_SID_after_TD = 1; hStereoCng->cng_counter = 0; return; } +#endif /*------------------------------------------------------------------------- @@ -1098,7 +1115,7 @@ void stereo_cng_upd_counters_fx( } return; } -#endif +#else void stereo_cng_upd_counters( STEREO_CNG_ENC_HANDLE hStereoCng, /* i/o: Stereo CNG data structure */ const int32_t element_mode, /* i : element mode */ @@ -1140,3 +1157,4 @@ void stereo_cng_upd_counters( } return; } +#endif diff --git a/lib_enc/ivas_stereo_dft_enc.c b/lib_enc/ivas_stereo_dft_enc.c index f4afc47ab..bf03b2825 100644 --- a/lib_enc/ivas_stereo_dft_enc.c +++ b/lib_enc/ivas_stereo_dft_enc.c @@ -1027,7 +1027,9 @@ void stereo_dft_enc_reset( hStereoDft->res_cod_NRG_M[i] = 0; hStereoDft->res_cod_NRG_S[i] = 0; } +#ifndef IVAS_FLOAT_FIXED hStereoDft->old_snr = 0.f; +#endif hStereoDft->reverb_flag = 0; @@ -1036,8 +1038,8 @@ void stereo_dft_enc_reset( hStereoDft->diff_l_h_sm = 0.0f; hStereoDft->diff_r_h_sm = 0.0f; hStereoDft->prev_fac2 = 1.0f; -#endif set_zero( hStereoDft->res_pred_gain_f, STEREO_DFT_BAND_MAX ); +#endif /*misc*/ hStereoDft->no_ipd_flag = 1; /* Initialization of the no IPD variables */ diff --git a/lib_enc/ivas_stereo_mdct_core_enc.c b/lib_enc/ivas_stereo_mdct_core_enc.c index e57aadf5d..6854716ae 100644 --- a/lib_enc/ivas_stereo_mdct_core_enc.c +++ b/lib_enc/ivas_stereo_mdct_core_enc.c @@ -1414,7 +1414,6 @@ void stereo_mdct_core_enc( { st->hIGFEnc->tns_predictionGain = float_to_fix16( st->hIGFEnc->tns_predictionGain_flt, Q23 ); } - // floatToFixed_arr16( &hPrivateData->igfInfo.grid[igfGridIdx].whiteningThreshold_flt[0][0], &hPrivateData->igfInfo.grid[igfGridIdx].whiteningThreshold[0][0], Q13, 2 * IGF_MAX_TILES ); #endif ProcessIGF_ivas_fx( st, st->hTcxEnc->spectrum_fx[n], orig_spectrum_fx[ch][n], &q_spectrum, &powerSpec_fx[ch][n * L_subframeTCX], &q_powerSpec, st->core == TCX_20_CORE, n, hCPE->hCoreCoder[0]->sp_aud_decision0, 0 ); #ifdef IVAS_FLOAT_FIXED_CONVERSIONS diff --git a/lib_enc/ivas_stereo_switching_enc.c b/lib_enc/ivas_stereo_switching_enc.c index 96dab941c..5cb71c096 100644 --- a/lib_enc/ivas_stereo_switching_enc.c +++ b/lib_enc/ivas_stereo_switching_enc.c @@ -543,7 +543,7 @@ ivas_error stereo_memory_enc_fx( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Stereo Cng for Unified/TD\n" ) ); } - stereo_enc_cng_init( hCPE->hStereoCng ); + stereo_enc_cng_init_fx( hCPE->hStereoCng ); } } diff --git a/lib_enc/ivas_tcx_core_enc.c b/lib_enc/ivas_tcx_core_enc.c index 926a1930d..8a73b6616 100644 --- a/lib_enc/ivas_tcx_core_enc.c +++ b/lib_enc/ivas_tcx_core_enc.c @@ -1625,7 +1625,7 @@ Word16 ivas_acelp_tcx20_switching_fx( move16(); } - basop_E_LPC_f_lsp_a_conversion( lsp_mid, A_q_tcx_fx, M ); + E_LPC_f_lsp_a_conversion( lsp_mid, A_q_tcx_fx, M ); Q_A_q_tcx = sub( 14, norm_s( A_q_tcx_fx[0] ) ); scale_A = sub( Q12, Q_A_q_tcx ); Copy_Scale_sig( A_q_tcx_fx, A_q_tcx_fx, M + 1, scale_A ); diff --git a/lib_enc/lib_enc.c b/lib_enc/lib_enc.c index ce072891d..a8130236d 100644 --- a/lib_enc/lib_enc.c +++ b/lib_enc/lib_enc.c @@ -2844,8 +2844,14 @@ static ivas_error sanitizeBandwidth_fx( } ELSE { + Word32 quo = 0, rem; + move32(); + IF( EQ_16( hEncoderConfig->ivas_format, ISM_FORMAT ) ) + { + iDiv_and_mod_32( hEncoderConfig->ivas_total_brate, hEncoderConfig->nchan_ism, &quo, &rem, 0 ); + } IF( EQ_16( max_bwidth_tmp, FB ) && ( ( NE_16( hEncoderConfig->ivas_format, ISM_FORMAT ) && LT_32( hEncoderConfig->ivas_total_brate, MIN_BRATE_FB_STEREO ) ) || - ( EQ_16( hEncoderConfig->ivas_format, ISM_FORMAT ) && LT_32( div_l( hEncoderConfig->ivas_total_brate, hEncoderConfig->nchan_ism ), MIN_BRATE_FB_ISM ) ) ) ) + ( EQ_16( hEncoderConfig->ivas_format, ISM_FORMAT ) && LT_32( quo, MIN_BRATE_FB_ISM ) ) ) ) { max_bwidth_tmp = SWB; } diff --git a/lib_enc/updt_enc.c b/lib_enc/updt_enc.c index b6178439a..9c48b93a5 100644 --- a/lib_enc/updt_enc.c +++ b/lib_enc/updt_enc.c @@ -52,6 +52,7 @@ * Common updates (all frame types) *-------------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED void updt_enc( Encoder_State *st, /* i/o: state structure */ const float *old_exc, /* i : buffer of excitation */ @@ -151,7 +152,6 @@ void updt_enc( return; } -#ifndef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* * updt_IO_switch() * -- GitLab From a911abb127935591e97d92d676eeb5735aab33f8 Mon Sep 17 00:00:00 2001 From: Erik Norvell Date: Tue, 5 Nov 2024 19:34:11 +0100 Subject: [PATCH 087/128] Switch to STV, LTV takes a long time --- .gitlab-ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 07a888bf2..de5e63dc2 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1032,10 +1032,10 @@ coverage-test-on-main-scheduled: - testcase_timeout=$TESTCASE_TIMEOUT_LTV - exit_code_dec=0 - exit_code_enc=0 - - python3 -m pytest --tb=no $LONG_TEST_SUITE --update_ref 1 -v --create_ref --html=report-dec.html --self-contained-html --junit-xml=report-junit-dec.xml -n auto --testcase_timeout $testcase_timeout --ref_encoder_path $REF_ENCODER_PATH --ref_decoder_path $DUT_DECODER_PATH || exit_code_dec=$? + - python3 -m pytest --tb=no $SHORT_TEST_SUITE --update_ref 1 -v --create_ref --html=report-dec.html --self-contained-html --junit-xml=report-junit-dec.xml -n auto --testcase_timeout $testcase_timeout --ref_encoder_path $REF_ENCODER_PATH --ref_decoder_path $DUT_DECODER_PATH || exit_code_dec=$? - lcov -c -d obj -o coverage_dec_rend.info # extract coverage of decoder/renderer - - python3 -m pytest --tb=no $LONG_TEST_SUITE_NO_RENDERER --encoder_only -v --html=report-enc.html --self-contained-html --junit-xml=report-junit-enc.xml -n auto --testcase_timeout $testcase_timeout --dut_encoder_path $DUT_ENCODER_PATH || exit_code_enc=$? + - python3 -m pytest --tb=no $SHORT_TEST_SUITE --encoder_only -v --html=report-enc.html --self-contained-html --junit-xml=report-junit-enc.xml -n auto --testcase_timeout $testcase_timeout --dut_encoder_path $DUT_ENCODER_PATH || exit_code_enc=$? - lcov -c -d obj -o coverage_enc_dec_rend.info # extract coverage of encoder/decoder/renderer # remove apps and lib_util files from coverage -- GitLab From 60b5f808bcf11ffc8eb9320a1b7b898767c794a6 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Wed, 6 Nov 2024 18:28:06 +0530 Subject: [PATCH 088/128] Fix for 3GPP issue 992: Crash in ivas_dirac_dec_render_fx() in OMASA JBM decoding --- lib_dec/ivas_dirac_dec.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib_dec/ivas_dirac_dec.c b/lib_dec/ivas_dirac_dec.c index 155e03a17..21d6d6175 100644 --- a/lib_dec/ivas_dirac_dec.c +++ b/lib_dec/ivas_dirac_dec.c @@ -4101,9 +4101,9 @@ void ivas_dirac_dec_render_sf_fx( hDirACRend->h_output_synthesis_psd_state.direct_power_factor_fx[i] = L_add( hDirACRend->h_output_synthesis_psd_state.direct_power_factor_fx[i], surCohEner_fx ); // Q29 move32(); - surCohRatio_fx[i] = BASOP_Util_Divide3232_Scale( surCohEner_fx, ( L_add( EPSILLON_FX, L_add( dirEne_fx, surCohEner_fx ) ) ), &temp_q ); + surCohRatio_fx[i] = BASOP_Util_Divide3232_Scale_cadence( surCohEner_fx, ( L_add( EPSILLON_FX, L_add( dirEne_fx, surCohEner_fx ) ) ), &temp_q ); move32(); - surCohRatio_fx[i] = L_shl( surCohRatio_fx[i], temp_q ); // Q31 + surCohRatio_fx[i] = L_shl( surCohRatio_fx[i], sub( temp_q, 16 ) ); // Q15 move32(); } } -- GitLab From 534b184c9d6a9e52f39e7c751870c2f3a5244a33 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Wed, 6 Nov 2024 18:31:02 +0530 Subject: [PATCH 089/128] Fix for 3GPP issue 964: ParamISM: High MLD for ParamISM, 32 kbps, high frequency content missing --- lib_rend/ivas_dirac_dec_binaural_functions.c | 177 +++++++------------ 1 file changed, 65 insertions(+), 112 deletions(-) diff --git a/lib_rend/ivas_dirac_dec_binaural_functions.c b/lib_rend/ivas_dirac_dec_binaural_functions.c index e0d8fa302..6ff9685bf 100644 --- a/lib_rend/ivas_dirac_dec_binaural_functions.c +++ b/lib_rend/ivas_dirac_dec_binaural_functions.c @@ -1231,8 +1231,7 @@ static void ivas_dirac_dec_binaural_internal_fx( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp = sub( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, shift ); move16(); } - Word16 q_cldfb[6][CLDFB_SLOTS_PER_SUBFRAME] = { 0 }; - move16(); + Word16 q_cldfb[6][CLDFB_SLOTS_PER_SUBFRAME]; FOR( Word16 ind = 0; ind < 6; ind++ ) { FOR( Word16 ind2 = 0; ind2 < 4; ind2++ ) @@ -1533,36 +1532,9 @@ static void ivas_dirac_dec_binaural_internal_fx( } } - Word16 shift = 31; - move16(); - Word32 Cldfb_RealBuffer_inTmp_fx[2][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], Cldfb_ImagBuffer_inTmp_fx[2][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX]; - FOR( i = 0; i < 2; i++ ) - { - FOR( j = 0; j < 4; j++ ) - { - shift = s_min( shift, getScaleFactor32( Cldfb_RealBuffer_in_fx[i][j], CLDFB_NO_CHANNELS_MAX ) ); - shift = s_min( shift, getScaleFactor32( Cldfb_ImagBuffer_in_fx[i][j], CLDFB_NO_CHANNELS_MAX ) ); - } - } - - Word16 q = add( q_inp, shift ); - - FOR( i = 0; i < 2; i++ ) - { - FOR( j = 0; j < 4; j++ ) - { - FOR( Word16 k = 0; k < 60; k++ ) - { - Cldfb_RealBuffer_inTmp_fx[i][j][k] = L_shl( Cldfb_RealBuffer_in_fx[i][j][k], shift ); // q - Cldfb_ImagBuffer_inTmp_fx[i][j][k] = L_shl( Cldfb_ImagBuffer_in_fx[i][j][k], shift ); // q - move32(); - move32(); - } - } - } - - ivas_dirac_dec_binaural_formulate_input_and_target_covariance_matrices_fx( hDiracDecBin, hSpatParamRendCom, &config_data, Cldfb_RealBuffer_inTmp_fx, Cldfb_ImagBuffer_inTmp_fx, Rmat_fx, subframe, - hCombinedOrientationData && hCombinedOrientationData->enableCombinedOrientation[hCombinedOrientationData->subframe_idx] > 0, st_ivas->hMasaIsmData, q ); + test(); + ivas_dirac_dec_binaural_formulate_input_and_target_covariance_matrices_fx( hDiracDecBin, hSpatParamRendCom, &config_data, Cldfb_RealBuffer_in_fx, Cldfb_ImagBuffer_in_fx, Rmat_fx, subframe, + hCombinedOrientationData && hCombinedOrientationData->enableCombinedOrientation[hCombinedOrientationData->subframe_idx] > 0, st_ivas->hMasaIsmData, q_inp ); IF( EQ_32( config_data.ivas_format, ISM_FORMAT ) ) { @@ -2282,7 +2254,7 @@ static void ivas_dirac_dec_binaural_formulate_input_and_target_covariance_matric UWord8 applyLowBitRateEQ; Word16 dirac_read_idx; Word32 subFrameTotalEne_fx[CLDFB_NO_CHANNELS_MAX]; - Word16 q_subFrameTotalEne; + Word16 subFrameTotalEne_e[CLDFB_NO_CHANNELS_MAX]; PARAMBIN_HRTF_GAIN_CACHE gainCache[MAX_GAIN_CACHE_SIZE]; IVAS_FORMAT ivas_format; MC_MODE mc_mode; @@ -2290,6 +2262,9 @@ static void ivas_dirac_dec_binaural_formulate_input_and_target_covariance_matric Word16 nchan_transport; Word16 gainCacheBaseIndex; Word16 q_earlyPartEneCorrection; + Word16 exp, exp1; + Word64 temp64; + Word32 temp; separateCenterChannelRendering = hConfig->separateCenterChannelRendering; move16(); @@ -2334,6 +2309,8 @@ static void ivas_dirac_dec_binaural_formulate_input_and_target_covariance_matric set32_fx( frameMeanDiffusenessEneWeight_fx, 0, CLDFB_NO_CHANNELS_MAX ); + set16_fx( subFrameTotalEne_e, 0, CLDFB_NO_CHANNELS_MAX ); + FOR( idx = 0; idx < MAX_GAIN_CACHE_SIZE; idx++ ) { gainCache[idx].azi = -1000; /* Use -1000 as value for uninitialized cache. */ @@ -2372,44 +2349,43 @@ static void ivas_dirac_dec_binaural_formulate_input_and_target_covariance_matric dirac_read_idx = hSpatParamRendCom->render_to_md_map[subframe]; move16(); + exp = sub( 63, shl( q, 1 ) ); // exp for the energy (inRe_fx * inRe_fx + inIm_fx * inIm_fx) computed below + /* Calculate input covariance matrix */ FOR( slot = 0; slot < hSpatParamRendCom->subframe_nbslots[subframe]; slot++ ) { FOR( bin = 0; bin < nBins; bin++ ) { - hDiracDecBin->ChCrossRe_fx[bin] = BASOP_Util_Add_Mant32Exp( hDiracDecBin->ChCrossRe_fx[bin], hDiracDecBin->ChCrossRe_e[bin], - L_add( L_shr( Mpy_32_32( inRe_fx[0][slot][bin], inRe_fx[1][slot][bin] ), 1 ), L_shr( Mpy_32_32( inIm_fx[0][slot][bin], inIm_fx[1][slot][bin] ), 1 ) ), sub( 63, shl( q, 1 ) ), &hDiracDecBin->ChCrossRe_e[bin] ); - hDiracDecBin->ChCrossIm_fx[bin] = BASOP_Util_Add_Mant32Exp( hDiracDecBin->ChCrossIm_fx[bin], hDiracDecBin->ChCrossIm_e[bin], - L_sub( L_shr( Mpy_32_32( inRe_fx[0][slot][bin], inIm_fx[1][slot][bin] ), 1 ), L_shr( Mpy_32_32( inIm_fx[0][slot][bin], inRe_fx[1][slot][bin] ), 1 ) ), sub( 63, shl( q, 1 ) ), &hDiracDecBin->ChCrossIm_e[bin] ); - - inRe_fx[0][slot][bin] = L_shr( inRe_fx[0][slot][bin], 2 ); - inRe_fx[1][slot][bin] = L_shr( inRe_fx[1][slot][bin], 2 ); - inIm_fx[0][slot][bin] = L_shr( inIm_fx[0][slot][bin], 2 ); - inIm_fx[1][slot][bin] = L_shr( inIm_fx[1][slot][bin], 2 ); - - move32(); - move32(); - move32(); - move32(); - move32(); - move32(); FOR( ch = 0; ch < BINAURAL_CHANNELS; ch++ ) { Word32 instEne_fx; - - instEne_fx = Mpy_32_32( inRe_fx[ch][slot][bin], inRe_fx[ch][slot][bin] ); // 2q - 31 - instEne_fx = L_add( instEne_fx, Mpy_32_32( inIm_fx[ch][slot][bin], inIm_fx[ch][slot][bin] ) ); // 2q - 31 - hDiracDecBin->ChEne_fx[ch][bin] = BASOP_Util_Add_Mant32Exp( hDiracDecBin->ChEne_fx[ch][bin], hDiracDecBin->ChEne_e[ch][bin], instEne_fx, sub( 66, shl( q, 1 ) ), &hDiracDecBin->ChEne_e[ch][bin] ); - subFrameTotalEne_fx[bin] = L_add( subFrameTotalEne_fx[bin], L_shr( instEne_fx, 1 ) ); // 2q - 32 + temp64 = W_mult0_32_32( inRe_fx[ch][slot][bin], inRe_fx[ch][slot][bin] ); // 2q + temp64 = W_add( temp64, W_mult0_32_32( inIm_fx[ch][slot][bin], inIm_fx[ch][slot][bin] ) ); // 2q + exp1 = W_norm( temp64 ); + instEne_fx = W_extract_h( W_shl( temp64, exp1 ) ); // 2q - 32 + exp1 + /* exp of instEne_fx = 31 - (2q -32 + exp1) = 63 - 2q - exp1 = exp - exp1*/ + + hDiracDecBin->ChEne_fx[ch][bin] = BASOP_Util_Add_Mant32Exp( hDiracDecBin->ChEne_fx[ch][bin], hDiracDecBin->ChEne_e[ch][bin], instEne_fx, sub( exp, exp1 ), &hDiracDecBin->ChEne_e[ch][bin] ); + subFrameTotalEne_fx[bin] = BASOP_Util_Add_Mant32Exp( subFrameTotalEne_fx[bin], subFrameTotalEne_e[bin], instEne_fx, sub( exp, exp1 ), &subFrameTotalEne_e[bin] ); move32(); move32(); } + temp64 = W_mult0_32_32( inRe_fx[0][slot][bin], inRe_fx[1][slot][bin] ); // 2q + temp64 = W_add( temp64, W_mult0_32_32( inIm_fx[0][slot][bin], inIm_fx[1][slot][bin] ) ); // 2q + exp1 = W_norm( temp64 ); + temp = W_extract_h( W_shl( temp64, exp1 ) ); // // 2q - 32 + exp1 + hDiracDecBin->ChCrossRe_fx[bin] = BASOP_Util_Add_Mant32Exp( hDiracDecBin->ChCrossRe_fx[bin], hDiracDecBin->ChCrossRe_e[bin], temp, sub( exp, exp1 ), &hDiracDecBin->ChCrossRe_e[bin] ); + move32(); + + temp64 = W_mult0_32_32( inRe_fx[0][slot][bin], inIm_fx[1][slot][bin] ); // 2q + temp64 = W_sub( temp64, W_mult0_32_32( inIm_fx[0][slot][bin], inRe_fx[1][slot][bin] ) ); // 2q + exp1 = W_norm( temp64 ); + temp = W_extract_h( W_shl( temp64, exp1 ) ); // // 2q - 32 + exp1 + hDiracDecBin->ChCrossIm_fx[bin] = BASOP_Util_Add_Mant32Exp( hDiracDecBin->ChCrossIm_fx[bin], hDiracDecBin->ChCrossIm_e[bin], temp, sub( exp, exp1 ), &hDiracDecBin->ChCrossIm_e[bin] ); + move32(); } } - q = sub( q, 2 ); - q_subFrameTotalEne = sub( shl( q, 1 ), 32 ); - /* Apply EQ at low bit rates */ IF( applyLowBitRateEQ != 0 ) { @@ -2417,12 +2393,12 @@ static void ivas_dirac_dec_binaural_formulate_input_and_target_covariance_matric FOR( bin = LOW_BIT_RATE_BINAURAL_EQ_OFFSET; bin < lastEqBin; bin++ ) { - subFrameTotalEne_fx[bin] = Mpy_32_32( subFrameTotalEne_fx[bin], lowBitRateEQ_fx[bin] ); // 2q -32 + subFrameTotalEne_fx[bin] = Mpy_32_32( subFrameTotalEne_fx[bin], lowBitRateEQ_fx[bin] ); // exp = subFrameTotalEne_e[bin] move32(); } FOR( ; bin < nBins; bin++ ) { - subFrameTotalEne_fx[bin] = Mpy_32_32( subFrameTotalEne_fx[bin], lowBitRateEQ_fx[lastEqBin] ); // 2q -32 + subFrameTotalEne_fx[bin] = Mpy_32_32( subFrameTotalEne_fx[bin], lowBitRateEQ_fx[lastEqBin] ); // exp = subFrameTotalEne_e[bin] move32(); } } @@ -2433,22 +2409,33 @@ static void ivas_dirac_dec_binaural_formulate_input_and_target_covariance_matric { Word32 tempRe, tempIm; Word32 subFrameSumEne_fx[CLDFB_NO_CHANNELS_MAX]; + Word16 subFrameSumEne_e[CLDFB_NO_CHANNELS_MAX]; set32_fx( subFrameSumEne_fx, 0, CLDFB_NO_CHANNELS_MAX ); + set16_fx( subFrameSumEne_e, 0, CLDFB_NO_CHANNELS_MAX ); FOR( slot = 0; slot < hSpatParamRendCom->subframe_nbslots[subframe]; slot++ ) { FOR( bin = 0; bin < nBins; bin++ ) { - tempRe = L_add( inRe_fx[0][slot][bin], inRe_fx[1][slot][bin] ); // q - tempIm = L_add( inIm_fx[0][slot][bin], inIm_fx[1][slot][bin] ); // q - subFrameSumEne_fx[bin] = L_add( subFrameSumEne_fx[bin], L_add( L_shr( Mpy_32_32( tempRe, tempRe ), 1 ), L_shr( Mpy_32_32( tempIm, tempIm ), 1 ) ) ); // 2q -32 + tempRe = L_add( inRe_fx[0][slot][bin], inRe_fx[1][slot][bin] ); // q + tempIm = L_add( inIm_fx[0][slot][bin], inIm_fx[1][slot][bin] ); // q + temp64 = W_add( W_mult0_32_32( tempRe, tempRe ), W_mult0_32_32( tempIm, tempIm ) ); // 2q + exp1 = W_norm( temp64 ); + temp64 = W_shl( temp64, exp1 ); // 2q + exp1 + subFrameSumEne_fx[bin] = BASOP_Util_Add_Mant32Exp( subFrameSumEne_fx[bin], subFrameTotalEne_e[bin], W_extract_h( temp64 ), sub( exp /* 63 - 2q */, exp1 ) /*31 - (2q + exp1 - 32)*/, &subFrameTotalEne_e[bin] ); move32(); } } FOR( bin = 0; bin < nBins; bin++ ) { - subFrameTotalEne_fx[bin] = L_max( subFrameTotalEne_fx[bin], subFrameSumEne_fx[bin] ); // 2q -32 - move32(); + temp = L_shl_sat( subFrameTotalEne_fx[bin], sub( subFrameTotalEne_e[bin], subFrameSumEne_e[bin] ) ); // subFrameSumEne_e[bin] + IF( GT_32( subFrameSumEne_fx[bin], temp ) ) + { + subFrameTotalEne_fx[bin] = subFrameSumEne_fx[bin]; + move32(); + subFrameTotalEne_e[bin] = subFrameSumEne_e[bin]; + move16(); + } } } @@ -2475,7 +2462,7 @@ static void ivas_dirac_dec_binaural_formulate_input_and_target_covariance_matric * the early spectrum of the BRIR data, using the spectral correction data in * hBinaural->earlyPartEneCorrection[bin], based on the BRIR set. */ meanEnePerCh_fx = Mpy_32_32( hDiracDecBin->earlyPartEneCorrection_fx[bin], subFrameTotalEne_fx[bin] ); // Q( q_meanEnePerCh ) - q_meanEnePerCh = sub( add( q_earlyPartEneCorrection, q_subFrameTotalEne ), 30 ); + q_meanEnePerCh = add( sub( q_earlyPartEneCorrection, subFrameTotalEne_e[bin] ), 1 ); // q_earlyPartEneCorrection + 31 - subFrameTotalEne_e[bin] - 31 + Q1(0.5f) /* Determine direct part target covariance matrix (for 1 or 2 directions) */ FOR( dirIndex = 0; dirIndex < hSpatParamRendCom->numSimultaneousDirections; dirIndex++ ) { @@ -2808,7 +2795,7 @@ static void ivas_dirac_dec_binaural_formulate_input_and_target_covariance_matric test(); IF( ( EQ_32( ivas_format, SBA_FORMAT ) || EQ_32( ivas_format, SBA_ISM_FORMAT ) ) && LT_16( bin, BINAURAL_COHERENCE_DIFFERENCE_BINS ) ) { - Word32 diffuseFieldCoherence_fx, temp; + Word32 diffuseFieldCoherence_fx; Word16 tmp_exp; temp = BASOP_Util_Add_Mant32Exp( Mpy_32_32( hDiracDecBin->hDiffuseDist->diffuseRatioX_fx[bin], hDiracDecBin->diffuseFieldCoherenceX_fx[bin] ), 0, Mpy_32_32( hDiracDecBin->hDiffuseDist->diffuseRatioY_fx[bin], hDiracDecBin->diffuseFieldCoherenceY_fx[bin] ), 0, &tmp_exp ); diffuseFieldCoherence_fx = BASOP_Util_Add_Mant32Exp( temp, tmp_exp, Mpy_32_32( hDiracDecBin->hDiffuseDist->diffuseRatioZ_fx[bin], hDiracDecBin->diffuseFieldCoherenceZ_fx[bin] ), 0, &tmp_exp ); @@ -2823,21 +2810,14 @@ static void ivas_dirac_dec_binaural_formulate_input_and_target_covariance_matric } /* Store parameters for formulating average diffuseness over frame */ - hDiracDecBin->frameMeanDiffuseness_fx[bin] = L_add( hDiracDecBin->frameMeanDiffuseness_fx[bin], L_shl( diffEneValForDecorrelationReduction_fx, sub( q_meanEnePerCh, q_diffEneValForDecorrelationReduction ) ) ); // Q(q_meanEnePerCh) + Word32 frameMeanDiffuseness = BASOP_Util_Add_Mant32Exp( hDiracDecBin->frameMeanDiffuseness_fx[bin], 2 /*Q29*/, diffEneValForDecorrelationReduction_fx, sub( 31, q_diffEneValForDecorrelationReduction ), &exp1 ); // exp = exp1 frameMeanDiffusenessEneWeight_fx[bin] = L_add( frameMeanDiffusenessEneWeight_fx[bin], meanEnePerCh_fx ); move32(); - move32(); - } - /* Formulate average diffuseness over frame */ - Word16 e; - FOR( bin = 0; bin < nBins; bin++ ) - { - e = 0; - move16(); - hDiracDecBin->frameMeanDiffuseness_fx[bin] = BASOP_Util_Divide3232_Scale( hDiracDecBin->frameMeanDiffuseness_fx[bin], L_max( EPSILLON_FX, frameMeanDiffusenessEneWeight_fx[bin] ), &e ); - hDiracDecBin->frameMeanDiffuseness_fx[bin] = L_shl( hDiracDecBin->frameMeanDiffuseness_fx[bin], add( 14, e ) ); // Q29 - move32(); + /* Formulate average diffuseness over frame */ + frameMeanDiffuseness = BASOP_Util_Divide3232_Scale_cadence( frameMeanDiffuseness, L_max( EPSILLON_FX, frameMeanDiffusenessEneWeight_fx[bin] ), &exp ); // exp = exp + 31 - q_meanEnePerCh - exp1 + exp = sub( exp, sub( sub( 31, q_meanEnePerCh ), exp1 ) ); + hDiracDecBin->frameMeanDiffuseness_fx[bin] = L_shl( frameMeanDiffuseness, sub( exp, 2 ) ); // Q29 move32(); } @@ -2867,16 +2847,16 @@ static void ivas_dirac_dec_binaural_formulate_input_and_target_covariance_matric move16(); den = BASOP_Util_Add_Mant32Exp( hDiracDecBin->ChEnePrev_fx[0][bin], hDiracDecBin->ChEnePrev_e[0][bin], hDiracDecBin->ChEnePrev_fx[1][bin], hDiracDecBin->ChEnePrev_e[1][bin], &den_e ); den = L_max( 1, den ); - IIReneLimiter_fx = BASOP_Util_Divide3232_Scale_cadence( num, den, &e ); - e = add( sub( num_e, den_e ), add( 5, e ) ); - IF( L_shr_sat( IIReneLimiter_fx, sub( 31, e ) ) > 0 ) + IIReneLimiter_fx = BASOP_Util_Divide3232_Scale_cadence( num, den, &exp ); + exp = add( sub( num_e, den_e ), add( 5, exp ) ); + IF( L_shr_sat( IIReneLimiter_fx, sub( 31, exp ) ) > 0 ) { IIReneLimiter_fx = ONE_IN_Q31; /*Q31*/ move32(); } ELSE { - IIReneLimiter_fx = L_shl( IIReneLimiter_fx, e ); /*Q31*/ + IIReneLimiter_fx = L_shl( IIReneLimiter_fx, exp ); /*Q31*/ } hDiracDecBin->ChCrossRe_fx[bin] = Mpy_32_32( hDiracDecBin->ChCrossRe_fx[bin], qualityBasedSmFactor_fx ); @@ -7969,36 +7949,9 @@ static void ivas_masa_ext_rend_parambin_internal_fx( } } - Word16 shift = 31; - move16(); - Word32 Cldfb_RealBuffer_inTmp_fx[2][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], Cldfb_ImagBuffer_inTmp_fx[2][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX]; - FOR( i = 0; i < 2; i++ ) - { - FOR( j = 0; j < 4; j++ ) - { - shift = s_min( shift, getScaleFactor32( Cldfb_RealBuffer_in_fx[i][j], CLDFB_NO_CHANNELS_MAX ) ); - shift = s_min( shift, getScaleFactor32( Cldfb_ImagBuffer_in_fx[i][j], CLDFB_NO_CHANNELS_MAX ) ); - } - } - - Word16 q = add( q_inp, shift ); - - FOR( i = 0; i < 2; i++ ) - { - FOR( j = 0; j < 4; j++ ) - { - FOR( Word16 k = 0; k < 60; k++ ) - { - Cldfb_RealBuffer_inTmp_fx[i][j][k] = L_shl( Cldfb_RealBuffer_in_fx[i][j][k], shift ); // q - Cldfb_ImagBuffer_inTmp_fx[i][j][k] = L_shl( Cldfb_ImagBuffer_in_fx[i][j][k], shift ); // q - move32(); - move32(); - } - } - } - - ivas_dirac_dec_binaural_formulate_input_and_target_covariance_matrices_fx( hDiracDecBin, hSpatParamRendCom, &config_data, Cldfb_RealBuffer_inTmp_fx, Cldfb_ImagBuffer_inTmp_fx, Rmat_fx, subframe, - hCombinedOrientationData && hCombinedOrientationData->enableCombinedOrientation[hCombinedOrientationData->subframe_idx] > 0, NULL, q ); + test(); + ivas_dirac_dec_binaural_formulate_input_and_target_covariance_matrices_fx( hDiracDecBin, hSpatParamRendCom, &config_data, Cldfb_RealBuffer_in_fx, Cldfb_ImagBuffer_in_fx, Rmat_fx, subframe, + hCombinedOrientationData && hCombinedOrientationData->enableCombinedOrientation[hCombinedOrientationData->subframe_idx] > 0, NULL, q_inp ); /* Always using CLDFB decorrelation in MASA EXT renderer */ max_band_decorr = hDiracDecBin->h_freq_domain_decorr_ap_params->max_band_decorr; -- GitLab From 11548ec8611e2e5b76895ca716584f4b6f9d7050 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Wed, 6 Nov 2024 18:34:36 +0530 Subject: [PATCH 090/128] Fix for 3GPP issue 994: High energy in high frequency part of transient for ISM3 --- lib_com/swb_tbe_com_fx.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lib_com/swb_tbe_com_fx.c b/lib_com/swb_tbe_com_fx.c index edc0a1e7d..70ab9f418 100644 --- a/lib_com/swb_tbe_com_fx.c +++ b/lib_com/swb_tbe_com_fx.c @@ -3089,6 +3089,16 @@ void GenShapedSHBExcitation_ivas_fx( { excNoisyEnv[i] = mac_r( L_tmp, csfilt_num2[0], shl( excTmp2[i], sub( Q_excTmp2, *Q_bwe_exc ) ) ); move16(); + /* Work-around to avoid 0s for very small value*/ + test(); + test(); + test(); + test(); + if ( excNoisyEnv[i] == 0 && ( L_tmp != 0 || ( csfilt_num2[0] != 0 && excTmp2[i] != 0 ) ) ) + { + excNoisyEnv[i] = 1; + move16(); + } /* excNoisyEnv : Q_excTmp2, *mem_csfilt: Q_excTmp2+16, excTmp2: Q_excTmp2, csfilt_num2[0] Q_excTmp2 */ L_tmp = L_mult( excNoisyEnv[i], neg_csfilt_den2[1] ); /* Q_excTmp2 + 16 */ -- GitLab From 81f1262fd3a0c9a5f97d972bad0dde1f450532de Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Wed, 6 Nov 2024 18:37:40 +0530 Subject: [PATCH 091/128] Fix for 3GPP issue 1002: Decoder crash for MC51 at 128 kbps with FER in RefineThresholdsUsingPitch() --- lib_dec/TonalComponentDetection_fx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_dec/TonalComponentDetection_fx.c b/lib_dec/TonalComponentDetection_fx.c index 38e7b5cbc..dab3cd359 100644 --- a/lib_dec/TonalComponentDetection_fx.c +++ b/lib_dec/TonalComponentDetection_fx.c @@ -808,7 +808,7 @@ static void CorrectF0( IF( LE_16( iMult, 3 ) ) { /* Use iMostCommonDiff, because the lowest pHarmonicIndexes[i] (which is equal to iMult) may not correspond to the new F0, but to it's multiple */ - F0 = round_fx( L_shl( L_mult( iMostCommonDiff /*Q0*/, F0 /*Q10*/ ), 15 ) ); /*Q10*/ + F0 = round_fx_sat( L_shl_sat( L_mult( iMostCommonDiff /*Q0*/, F0 /*Q10*/ ), 15 ) ); /*Q10*/ } ELSE { -- GitLab From 137e11f019f606946cc90b7bed90ddbb65749d8b Mon Sep 17 00:00:00 2001 From: Erik Norvell Date: Wed, 6 Nov 2024 15:16:23 +0100 Subject: [PATCH 092/128] Add renderer to coverage --- .gitlab-ci.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index de5e63dc2..d71eef6c0 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1032,10 +1032,10 @@ coverage-test-on-main-scheduled: - testcase_timeout=$TESTCASE_TIMEOUT_LTV - exit_code_dec=0 - exit_code_enc=0 - - python3 -m pytest --tb=no $SHORT_TEST_SUITE --update_ref 1 -v --create_ref --html=report-dec.html --self-contained-html --junit-xml=report-junit-dec.xml -n auto --testcase_timeout $testcase_timeout --ref_encoder_path $REF_ENCODER_PATH --ref_decoder_path $DUT_DECODER_PATH || exit_code_dec=$? + - python3 -m pytest --tb=no tests/codec_be_on_mr_nonselection tests/renderer --update_ref 1 -v --create_ref --html=report-dec.html --self-contained-html --junit-xml=report-junit-dec.xml -n auto --testcase_timeout $testcase_timeout --ref_encoder_path $REF_ENCODER_PATH --ref_decoder_path $DUT_DECODER_PATH || exit_code_dec=$? - lcov -c -d obj -o coverage_dec_rend.info # extract coverage of decoder/renderer - - python3 -m pytest --tb=no $SHORT_TEST_SUITE --encoder_only -v --html=report-enc.html --self-contained-html --junit-xml=report-junit-enc.xml -n auto --testcase_timeout $testcase_timeout --dut_encoder_path $DUT_ENCODER_PATH || exit_code_enc=$? + - python3 -m pytest --tb=no tests/codec_be_on_mr_nonselection --encoder_only -v --html=report-enc.html --self-contained-html --junit-xml=report-junit-enc.xml -n auto --testcase_timeout $testcase_timeout --dut_encoder_path $DUT_ENCODER_PATH || exit_code_enc=$? - lcov -c -d obj -o coverage_enc_dec_rend.info # extract coverage of encoder/decoder/renderer # remove apps and lib_util files from coverage @@ -1056,6 +1056,8 @@ coverage-test-on-main-scheduled: - coverage_dec_rend.info - coverage_enc_dec_rend - coverage_dec_rend + - report-dec.html + - report-enc.html expose_as: "Coverage result" reports: junit: -- GitLab From 714c56a8330260d000b9886359491464c1c1bc45 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Wed, 6 Nov 2024 20:33:22 +0530 Subject: [PATCH 093/128] Float struct elements cleanup in lib_com and lib_enc, Q-info lib_com updates [x] Float structure elements cleanup for various FORMATS [x] Q-info updates for lib_com [x] LTV crash fixes --- lib_com/fd_cng_com.c | 2 - lib_com/ifft_rel.c | 378 ++++----- lib_com/igf_base_fx.c | 298 +++---- lib_com/index_pvq_opt_fx.c | 255 +++--- lib_com/int_lsp.c | 56 +- lib_com/interpol.c | 30 +- lib_com/isf_dec_amr_wb_fx.c | 88 +- lib_com/ivas_fb_mixer.c | 1208 +-------------------------- lib_com/ivas_mc_param_com.c | 42 +- lib_com/ivas_mdct_imdct.c | 4 +- lib_com/ivas_prot.h | 45 +- lib_com/ivas_prot_fx.h | 13 +- lib_com/ivas_rom_com.c | 80 +- lib_com/ivas_spar_com.c | 4 +- lib_com/ivas_spar_com_quant_util.c | 9 +- lib_com/ivas_stat_com.h | 243 +++--- lib_com/ivas_tools.c | 762 ++++++++--------- lib_com/ivas_transient_det.c | 154 ++-- lib_com/lag_wind.c | 74 +- lib_com/prot_fx.h | 138 +-- lib_com/rom_com.c | 170 ++-- lib_com/rom_com.h | 8 +- lib_com/stat_com.h | 18 +- lib_com/tcx_mdct_fx.c | 147 ++-- lib_com/vlpc_2st_com_fx.c | 8 +- lib_com/weight_a_fx.c | 75 +- lib_com/weight_fx.c | 148 ++-- lib_com/wi_fx.c | 109 +-- lib_dec/ivas_qmetadata_dec.c | 8 +- lib_dec/jbm_pcmdsp_apa.c | 2 + lib_enc/acelp_core_enc.c | 67 +- lib_enc/cod_tcx_fx.c | 17 +- lib_enc/core_enc_init.c | 114 ++- lib_enc/core_enc_switch.c | 9 +- lib_enc/core_switching_enc.c | 30 +- lib_enc/dtx.c | 6 + lib_enc/fd_cng_enc.c | 20 + lib_enc/fd_cng_enc_fx.c | 10 - lib_enc/init_enc.c | 108 ++- lib_enc/ivas_core_enc.c | 34 - lib_enc/ivas_core_pre_proc_front.c | 30 - lib_enc/ivas_dirac_enc.c | 2 +- lib_enc/ivas_enc.c | 14 +- lib_enc/ivas_front_vad.c | 5 - lib_enc/ivas_masa_enc.c | 2 +- lib_enc/ivas_mc_param_enc.c | 7 - lib_enc/ivas_mc_paramupmix_enc.c | 4 +- lib_enc/ivas_mcmasa_enc.c | 53 +- lib_enc/ivas_osba_enc.c | 2 +- lib_enc/ivas_pca_enc.c | 514 +----------- lib_enc/ivas_sba_enc.c | 2 +- lib_enc/ivas_spar_encoder.c | 549 ++++-------- lib_enc/ivas_spar_md_enc.c | 36 +- lib_enc/ivas_stat_enc.h | 23 +- lib_enc/ivas_stereo_switching_enc.c | 3 - lib_enc/ivas_tcx_core_enc.c | 6 - lib_enc/prot_fx_enc.h | 4 +- lib_enc/speech_music_classif_fx.c | 14 +- lib_enc/stat_enc.h | 104 ++- 59 files changed, 2231 insertions(+), 4134 deletions(-) diff --git a/lib_com/fd_cng_com.c b/lib_com/fd_cng_com.c index 91750b486..37a10990b 100644 --- a/lib_com/fd_cng_com.c +++ b/lib_com/fd_cng_com.c @@ -652,7 +652,6 @@ void minimum_statistics_flt( return; } -#endif /*------------------------------------------------------------------- @@ -689,7 +688,6 @@ void apply_scale_flt( } -#ifndef IVAS_FLOAT_FIXED /*------------------------------------------------------------------- * bandcombinepow_flt() * diff --git a/lib_com/ifft_rel.c b/lib_com/ifft_rel.c index 41599cdd8..a54cbb350 100644 --- a/lib_com/ifft_rel.c +++ b/lib_com/ifft_rel.c @@ -45,7 +45,7 @@ *-----------------------------------------------------------------*/ #define N_MAX_FFT 1024 -#define INV_SQR2_FX 23170 +#define INV_SQR2_FX 23170 /*Q15*/ #define N_MAX_SAS 256 /*---------------------------------------------------------------------* * ifft_rel() @@ -288,9 +288,9 @@ void ifft_rel( } void ifft_rel_fx( - Word16 io[], /* i/o: input/output vector */ - const Word16 n, /* i : vector length */ - const Word16 m /* i : log2 of vector length */ + Word16 io[], /* Qx i/o: input/output vector */ + const Word16 n, /* Q0 i : vector length */ + const Word16 m /* Q0 i : log2 of vector length */ ) { Word16 i, j, k; @@ -316,7 +316,6 @@ void ifft_rel_fx( *-----------------------------------------------------------------*/ x = &io[-1]; - move16(); n2 = shl( n, 1 ); FOR( k = 1; k < m; k++ ) { @@ -325,120 +324,105 @@ void ifft_rel_fx( id = n2; move16(); n2 = shr( n2, 1 ); - move16(); n4 = shr( n2, 2 ); - move16(); n8 = shr( n4, 1 ); - move16(); tmp = sub( n, 1 ); WHILE( LT_16( is, tmp ) ) { - xi1 = x + is + 1; - move16(); - xi2 = xi1 + n4; - move16(); - xi3 = xi2 + n4; - move16(); - xi4 = xi3 + n4; - move16(); + xi1 = x + is + 1; /*Qx*/ + xi2 = xi1 + n4; /*Qx*/ + xi3 = xi2 + n4; /*Qx*/ + xi4 = xi3 + n4; /*Qx*/ FOR( i = is; i < n; i += id ) { #ifdef BASOP_NOGLOB - t1 = sub_o( *xi1, *xi3, &Overflow ); - *xi1 = add_o( *xi1, *xi3, &Overflow ); -#else /* BASOP_NOGLOB */ + t1 = sub_o( *xi1, *xi3, &Overflow ); /*Qx*/ + *xi1 = add_o( *xi1, *xi3, &Overflow ); /*Qx*/ +#else /* BASOP_NOGLOB */ t1 = sub( *xi1, *xi3 ); *xi1 = add( *xi1, *xi3 ); -#endif /* BASOP_NOGLOB */ +#endif /* BASOP_NOGLOB */ move16(); #ifdef BASOP_NOGLOB - *xi2 = shl_o( *xi2, 1, &Overflow ); -#else /* BASOP_NOGLOB */ + *xi2 = shl_o( *xi2, 1, &Overflow ); /*Qx*/ +#else /* BASOP_NOGLOB */ *xi2 = shl( *xi2, 1 ); -#endif /* BASOP_NOGLOB */ +#endif /* BASOP_NOGLOB */ move16(); #ifdef BASOP_NOGLOB - *xi3 = sub_o( t1, shl_o( *xi4, 1, &Overflow ), &Overflow ); -#else /* BASOP_NOGLOB */ + *xi3 = sub_o( t1, shl_o( *xi4, 1, &Overflow ), &Overflow ); /*Qx*/ +#else /* BASOP_NOGLOB */ *xi3 = sub( t1, shl( *xi4, 1 ) ); -#endif /* BASOP_NOGLOB */ +#endif /* BASOP_NOGLOB */ move16(); #ifdef BASOP_NOGLOB - *xi4 = add_o( t1, shl_o( *xi4, 1, &Overflow ), &Overflow ); -#else /* BASOP_NOGLOB */ + *xi4 = add_o( t1, shl_o( *xi4, 1, &Overflow ), &Overflow ); /*Qx*/ +#else /* BASOP_NOGLOB */ *xi4 = add( t1, shl( *xi4, 1 ) ); -#endif /* BASOP_NOGLOB */ +#endif /* BASOP_NOGLOB */ move16(); IF( NE_16( n4, 1 ) ) { #ifdef BASOP_NOGLOB - t1 = mult_r( sub_o( *( xi2 + n8 ), *( xi1 + n8 ), &Overflow ), INV_SQR2_FX ); - t2 = mult_r( add_o( *( xi4 + n8 ), *( xi3 + n8 ), &Overflow ), INV_SQR2_FX ); -#else /* BASOP_NOGLOB */ + t1 = mult_r( sub_o( *( xi2 + n8 ), *( xi1 + n8 ), &Overflow ), INV_SQR2_FX /*Q15*/ ); /*Qx*/ + t2 = mult_r( add_o( *( xi4 + n8 ), *( xi3 + n8 ), &Overflow ), INV_SQR2_FX /*Q15*/ ); /*Qx*/ +#else /* BASOP_NOGLOB */ t1 = mult_r( sub( *( xi2 + n8 ), *( xi1 + n8 ) ), INV_SQR2_FX ); t2 = mult_r( add( *( xi4 + n8 ), *( xi3 + n8 ) ), INV_SQR2_FX ); -#endif /* BASOP_NOGLOB */ +#endif /* BASOP_NOGLOB */ #ifdef BASOP_NOGLOB - *( xi1 + n8 ) = add_o( *( xi1 + n8 ), *( xi2 + n8 ), &Overflow ); -#else /* BASOP_NOGLOB */ + *( xi1 + n8 ) = add_o( *( xi1 + n8 ), *( xi2 + n8 ), &Overflow ); /*Qx*/ +#else /* BASOP_NOGLOB */ *( xi1 + n8 ) = add( *( xi1 + n8 ), *( xi2 + n8 ) ); -#endif /* BASOP_NOGLOB */ +#endif /* BASOP_NOGLOB */ move16(); #ifdef BASOP_NOGLOB - *( xi2 + n8 ) = sub_o( *( xi4 + n8 ), *( xi3 + n8 ), &Overflow ); -#else /* BASOP_NOGLOB */ + *( xi2 + n8 ) = sub_o( *( xi4 + n8 ), *( xi3 + n8 ), &Overflow ); /*Qx*/ +#else /* BASOP_NOGLOB */ *( xi2 + n8 ) = sub( *( xi4 + n8 ), *( xi3 + n8 ) ); -#endif /* BASOP_NOGLOB */ +#endif /* BASOP_NOGLOB */ move16(); #ifdef BASOP_NOGLOB - *( xi3 + n8 ) = negate( shl_o( add_o( t2, t1, &Overflow ), 1, &Overflow ) ); -#else /* BASOP_NOGLOB */ + *( xi3 + n8 ) = negate( shl_o( add_o( t2, t1, &Overflow ), 1, &Overflow ) ); /*Qx*/ +#else /* BASOP_NOGLOB */ *( xi3 + n8 ) = negate( shl( add( t2, t1 ), 1 ) ); -#endif /* BASOP_NOGLOB */ +#endif /* BASOP_NOGLOB */ move16(); #ifdef BASOP_NOGLOB - *( xi4 + n8 ) = shl_o( sub_o( t1, t2, &Overflow ), 1, &Overflow ); -#else /* BASOP_NOGLOB */ + *( xi4 + n8 ) = shl_o( sub_o( t1, t2, &Overflow ), 1, &Overflow ); /*Qx*/ +#else /* BASOP_NOGLOB */ *( xi4 + n8 ) = shl( sub( t1, t2 ), 1 ); -#endif /* BASOP_NOGLOB */ +#endif /* BASOP_NOGLOB */ move16(); } xi1 += id; - move16(); xi2 += id; - move16(); xi3 += id; - move16(); xi4 += id; - move16(); } is = sub( shl( id, 1 ), n2 ); id = shl( id, 2 ); } /*Can be acheived with a shr */ - step = N_MAX_SAS / n2; + step = idiv1616( N_MAX_SAS, n2 ); move16(); - s = sincos_t_fx + step; - move16(); - c = s + 64; - move16(); - s3 = sincos_t_fx + i_mult2( step, 3 ); - move16(); - c3 = s3 + 64; - move16(); + s = sincos_t_fx + step; /*Q15 */ + c = s + 64; /*Q15 */ + s3 = sincos_t_fx + i_mult2( step, 3 ); /*Q15 */ + c3 = s3 + 64; /*Q15 */ FOR( j = 2; j <= n8; j++ ) { - cc1 = *c; + cc1 = *c; /*Q15 */ move16(); - ss1 = *s; + ss1 = *s; /*Q15 */ move16(); - cc3 = *c3; + cc3 = *c3; /*Q15 */ move16(); - ss3 = *s3; + ss3 = *s3; /*Q15 */ move16(); is = 0; @@ -446,123 +430,103 @@ void ifft_rel_fx( id = shl( n2, 1 ); c += step; - move16(); s += step; - move16(); - c3 += 3 * step; - move16(); - s3 += 3 * step; - move16(); + c3 += imult1616( 3, step ); + s3 += imult1616( 3, step ); WHILE( LT_16( is, sub( n, 1 ) ) ) { - xup1 = x + j + is; - move16(); - xup3 = xup1 + shl( n4, 1 ); - move16(); - xdn6 = xup3 - shl( j, 1 ) + 2; - move16(); + xup1 = x + j + is; /*Qx*/ + xup3 = xup1 + shl( n4, 1 ); /*Qx*/ + xdn6 = xup3 - shl( j, 1 ) + 2; /*Qx*/ - xdn8 = xdn6 + shl( n4, 1 ); - move16(); + xdn8 = xdn6 + shl( n4, 1 ); /*Qx*/ FOR( i = is; i < n; i += id ) { #ifdef BASOP_NOGLOB - t1 = sub_o( *xup1, *xdn6, &Overflow ); - *xup1 = add_o( *xup1, *xdn6, &Overflow ); -#else /* BASOP_NOGLOB */ + t1 = sub_o( *xup1, *xdn6, &Overflow ); /*Qx*/ + *xup1 = add_o( *xup1, *xdn6, &Overflow ); /*Qx*/ +#else /* BASOP_NOGLOB */ t1 = sub( *xup1, *xdn6 ); *xup1 = add( *xup1, *xdn6 ); -#endif /* BASOP_NOGLOB */ +#endif /* BASOP_NOGLOB */ move16(); xup1 += n4; - move16(); xdn6 -= n4; - move16(); #ifdef BASOP_NOGLOB - t2 = sub_o( *xdn6, *xup1, &Overflow ); - *xdn6 = add_o( *xup1, *xdn6, &Overflow ); -#else /* BASOP_NOGLOB */ + t2 = sub_o( *xdn6, *xup1, &Overflow ); /*Qx*/ + *xdn6 = add_o( *xup1, *xdn6, &Overflow ); /*Qx*/ +#else /* BASOP_NOGLOB */ t2 = sub( *xdn6, *xup1 ); *xdn6 = add( *xup1, *xdn6 ); -#endif /* BASOP_NOGLOB */ +#endif /* BASOP_NOGLOB */ move16(); xdn6 += n4; - move16(); #ifdef BASOP_NOGLOB - t3 = add_o( *xdn8, *xup3, &Overflow ); - *xdn6 = sub_o( *xdn8, *xup3, &Overflow ); -#else /* BASOP_NOGLOB */ + t3 = add_o( *xdn8, *xup3, &Overflow ); /*Qx*/ + *xdn6 = sub_o( *xdn8, *xup3, &Overflow ); /*Qx*/ +#else /* BASOP_NOGLOB */ t3 = add( *xdn8, *xup3 ); *xdn6 = sub( *xdn8, *xup3 ); -#endif /* BASOP_NOGLOB */ +#endif /* BASOP_NOGLOB */ move16(); xup3 += n4; - move16(); xdn8 -= n4; - move16(); #ifdef BASOP_NOGLOB - t4 = add_o( *xup3, *xdn8, &Overflow ); - *xup1 = sub_o( *xup3, *xdn8, &Overflow ); -#else /* BASOP_NOGLOB */ + t4 = add_o( *xup3, *xdn8, &Overflow ); /*Qx*/ + *xup1 = sub_o( *xup3, *xdn8, &Overflow ); /*Qx*/ +#else /* BASOP_NOGLOB */ t4 = add( *xup3, *xdn8 ); *xup1 = sub( *xup3, *xdn8 ); -#endif /* BASOP_NOGLOB */ +#endif /* BASOP_NOGLOB */ move16(); #ifdef BASOP_NOGLOB - t5 = sub_o( t1, t4, &Overflow ); - t1 = add_o( t1, t4, &Overflow ); - t4 = sub_o( t2, t3, &Overflow ); - t2 = add_o( t2, t3, &Overflow ); - *xup3 = sub_o( mult_r( t1, cc3 ), mult_r( t2, ss3 ), &Overflow ); -#else /* BASOP_NOGLOB */ + t5 = sub_o( t1, t4, &Overflow ); /*Qx*/ + t1 = add_o( t1, t4, &Overflow ); /*Qx*/ + t4 = sub_o( t2, t3, &Overflow ); /*Qx*/ + t2 = add_o( t2, t3, &Overflow ); /*Qx*/ + *xup3 = sub_o( mult_r( t1, cc3 ), mult_r( t2, ss3 ), &Overflow ); /*Qx*/ +#else /* BASOP_NOGLOB */ t5 = sub( t1, t4 ); t1 = add( t1, t4 ); t4 = sub( t2, t3 ); t2 = add( t2, t3 ); *xup3 = sub( mult_r( t1, cc3 ), mult_r( t2, ss3 ) ); -#endif /* BASOP_NOGLOB */ +#endif /* BASOP_NOGLOB */ move16(); xup3 -= n4; - move16(); #ifdef BASOP_NOGLOB - *xup3 = add_o( mult_r( t5, cc1 ), mult_r( t4, ss1 ), &Overflow ); -#else /* BASOP_NOGLOB */ + *xup3 = add_o( mult_r( t5, cc1 ), mult_r( t4, ss1 ), &Overflow ); /*Qx*/ +#else /* BASOP_NOGLOB */ *xup3 = add( mult_r( t5, cc1 ), mult_r( t4, ss1 ) ); -#endif /* BASOP_NOGLOB */ +#endif /* BASOP_NOGLOB */ move16(); #ifdef BASOP_NOGLOB - *xdn8 = sub_o( mult_r( t5, ss1 ), mult_r( t4, cc1 ), &Overflow ); -#else /* BASOP_NOGLOB */ + *xdn8 = sub_o( mult_r( t5, ss1 ), mult_r( t4, cc1 ), &Overflow ); /*Qx*/ +#else /* BASOP_NOGLOB */ *xdn8 = sub( mult_r( t5, ss1 ), mult_r( t4, cc1 ) ); -#endif /* BASOP_NOGLOB */ +#endif /* BASOP_NOGLOB */ move16(); xdn8 += n4; - move16(); #ifdef BASOP_NOGLOB - *xdn8 = add_o( mult_r( t2, cc3 ), mult_r( t1, ss3 ), &Overflow ); -#else /* BASOP_NOGLOB */ + *xdn8 = add_o( mult_r( t2, cc3 ), mult_r( t1, ss3 ), &Overflow ); /*Qx*/ +#else /* BASOP_NOGLOB */ *xdn8 = add( mult_r( t2, cc3 ), mult_r( t1, ss3 ) ); -#endif /* BASOP_NOGLOB */ +#endif /* BASOP_NOGLOB */ move16(); xup1 -= n4; - move16(); xup1 += id; - move16(); xup3 += id; - move16(); xdn6 += id; - move16(); xdn8 += id; - move16(); } is = sub( shl( id, 1 ), n2 ); id = shl( id, 2 ); @@ -581,30 +545,26 @@ void ifft_rel_fx( WHILE( is < n ) { xi0 = x + is; - move16(); xi1 = xi0 + 1; - move16(); FOR( i0 = is; i0 <= n; i0 += id ) { r1 = *xi0; move16(); #ifdef BASOP_NOGLOB - *xi0 = add_o( r1, *xi1, &Overflow ); -#else /* BASOP_NOGLOB */ + *xi0 = add_o( r1, *xi1, &Overflow ); /*Qx*/ +#else /* BASOP_NOGLOB */ *xi0 = add( r1, *xi1 ); -#endif /* BASOP_NOGLOB */ +#endif /* BASOP_NOGLOB */ move16(); #ifdef BASOP_NOGLOB - *xi1 = sub_o( r1, *xi1, &Overflow ); -#else /* BASOP_NOGLOB */ + *xi1 = sub_o( r1, *xi1, &Overflow ); /*Qx*/ +#else /* BASOP_NOGLOB */ *xi1 = sub( r1, *xi1 ); #endif move16(); xi0 += id; - move16(); xi1 += id; - move16(); } is = sub( shl( id, 1 ), 1 ); id = shl( id, 2 ); @@ -620,11 +580,11 @@ void ifft_rel_fx( { IF( LT_16( i, j ) ) { - xt = x[j]; + xt = x[j]; /*Qx*/ move16(); - x[j] = x[i]; + x[j] = x[i]; /*Qx*/ move16(); - x[i] = xt; + x[i] = xt; /*Qx*/ move16(); } k = shr( n, 1 ); @@ -643,18 +603,18 @@ void ifft_rel_fx( tmp = div_s( 1, n ); /*Q15 */ FOR( i = 1; i <= n; i++ ) { - x[i] = mult_r( x[i], tmp ); + x[i] = mult_r( x[i], tmp ); /*Qx*/ move16(); } return; } -#define INV_SQRT_2_16 ( Word16 )( 0x5A82 ) +#define INV_SQRT_2_16 ( Word16 )( 0x5A82 ) /*Q15*/ void ifft_rel_fx32( - Word32 io[], /* i/o: input/output vector */ - const Word16 n, /* i : vector length */ - const Word16 m /* i : log2 of vector length */ + Word32 io[], /* Qx i/o: input/output vector */ + const Word16 n, /* Q0 i : vector length */ + const Word16 m /* Q0 i : log2 of vector length */ ) { Word16 i, j, k; @@ -669,19 +629,19 @@ void ifft_rel_fx32( const Word16 *s, *s3, *c, *c3; const Word16 *idx; Word32 temp[512]; - Word16 n_inv = 128; + Word16 n_inv = 128; /*1/256 in Q15*/ move16(); SWITCH( n ) { case 128: - n_inv = 256; + n_inv = 256; /*1/128 in Q15*/ BREAK; case 256: - n_inv = 128; + n_inv = 128; /*1/256 in Q15*/ BREAK; case 512: - n_inv = 64; + n_inv = 64; /*1/512 in Q15*/ BREAK; default: assert( 0 ); @@ -694,46 +654,46 @@ void ifft_rel_fx32( *-----------------------------------------------------------------*/ x = &io[-1]; - n2 = shl( n, 1 ); + n2 = shl( n, 1 ); /*Q0*/ FOR( k = 1; k < m; k++ ) { is = 0; move16(); id = n2; move16(); - n2 = shr( n2, 1 ); - n4 = shr( n2, 2 ); - n8 = shr( n4, 1 ); + n2 = shr( n2, 1 ); /*Q0*/ + n4 = shr( n2, 2 ); /*Q0*/ + n8 = shr( n4, 1 ); /*Q0*/ WHILE( LT_16( is, sub( n, 1 ) ) ) { - xi1 = x + is + 1; - xi2 = xi1 + n4; - xi3 = xi2 + n4; - xi4 = xi3 + n4; + xi1 = x + is + 1; /*Qx*/ + xi2 = xi1 + n4; /*Qx*/ + xi3 = xi2 + n4; /*Qx*/ + xi4 = xi3 + n4; /*Qx*/ FOR( i = is; i < n; i += id ) { - t1 = L_sub( *xi1, *xi3 ); - *xi1 = L_add( *xi1, *xi3 ); + t1 = L_sub( *xi1, *xi3 ); /*Qx*/ + *xi1 = L_add( *xi1, *xi3 ); /*Qx*/ move32(); - *xi2 = L_shl( *xi2, 1 ); + *xi2 = L_shl( *xi2, 1 ); /*Qx*/ move32(); - *xi3 = L_sub( t1, L_shl( *xi4, 1 ) ); + *xi3 = L_sub( t1, L_shl( *xi4, 1 ) ); /*Qx*/ move32(); - *xi4 = L_add( t1, L_shl( *xi4, 1 ) ); + *xi4 = L_add( t1, L_shl( *xi4, 1 ) ); /*Qx*/ move32(); IF( NE_16( n4, 1 ) ) { - t1 = Mpy_32_16_1( L_sub( *( xi2 + n8 ), *( xi1 + n8 ) ), INV_SQRT_2_16 ); - t2 = Mpy_32_16_1( L_add( *( xi4 + n8 ), *( xi3 + n8 ) ), INV_SQRT_2_16 ); + t1 = Mpy_32_16_1( L_sub( *( xi2 + n8 ), *( xi1 + n8 ) ), INV_SQRT_2_16 ); /*Qx*/ + t2 = Mpy_32_16_1( L_add( *( xi4 + n8 ), *( xi3 + n8 ) ), INV_SQRT_2_16 ); /*Qx*/ - *( xi1 + n8 ) = L_add( *( xi1 + n8 ), *( xi2 + n8 ) ); + *( xi1 + n8 ) = L_add( *( xi1 + n8 ), *( xi2 + n8 ) ); /*Qx*/ move32(); - *( xi2 + n8 ) = L_sub( *( xi4 + n8 ), *( xi3 + n8 ) ); + *( xi2 + n8 ) = L_sub( *( xi4 + n8 ), *( xi3 + n8 ) ); /*Qx*/ move32(); - *( xi3 + n8 ) = L_shl( L_negate( L_add( t2, t1 ) ), 1 ); + *( xi3 + n8 ) = L_shl( L_negate( L_add( t2, t1 ) ), 1 ); /*Qx*/ move32(); - *( xi4 + n8 ) = L_shl( L_sub( t1, t2 ), 1 ); + *( xi4 + n8 ) = L_shl( L_sub( t1, t2 ), 1 ); /*Qx*/ move32(); } xi1 += id; @@ -741,23 +701,27 @@ void ifft_rel_fx32( xi3 += id; xi4 += id; } - is = sub( shl( id, 1 ), n2 ); - id = shl( id, 2 ); + is = sub( shl( id, 1 ), n2 ); /*Q0*/ + id = shl( id, 2 ); /*Q0*/ } /*Can be acheived with a shr */ - step = N_MAX_FFT / n2; + step = idiv1616( N_MAX_FFT, n2 ); move16(); - s = sincos_t_ext_fx + step; - c = s + N_MAX_FFT / 4; - s3 = sincos_t_ext_fx + imult1616( 3, step ); - c3 = s3 + N_MAX_FFT / 4; + s = sincos_t_ext_fx + step; /*Q15*/ + c = s + shr( N_MAX_FFT, 2 ); /*Q15*/ + s3 = sincos_t_ext_fx + imult1616( 3, step ); /*Q15*/ + c3 = s3 + shr( N_MAX_FFT, 2 ); /*Q15*/ FOR( j = 2; j <= n8; j++ ) { - cc1 = *c; - ss1 = *s; - cc3 = *c3; - ss3 = *s3; + cc1 = *c; /*Q15*/ + ss1 = *s; /*Q15*/ + cc3 = *c3; /*Q15*/ + ss3 = *s3; /*Q15*/ + move16(); + move16(); + move16(); + move16(); is = 0; move16(); @@ -767,53 +731,53 @@ void ifft_rel_fx32( c += step; s += step; - c3 += imult1616( 3, step ); - s3 += imult1616( 3, step ); + c3 += imult1616( 3, step ); /*Q15*/ + s3 += imult1616( 3, step ); /*Q15*/ WHILE( LT_16( is, sub( n, 1 ) ) ) { - xup1 = x + add( j, is ); - xup3 = xup1 + shl( n4, 1 ); - xdn6 = xup3 - sub( shl( j, 1 ), 2 ); - xdn8 = xdn6 + shl( n4, 1 ); + xup1 = x + add( j, is ); /*Qx*/ + xup3 = xup1 + shl( n4, 1 ); /*Qx*/ + xdn6 = xup3 - sub( shl( j, 1 ), 2 ); /*Qx*/ + xdn8 = xdn6 + shl( n4, 1 ); /*Qx*/ FOR( i = is; i < n; i += id ) { - t1 = L_sub( *xup1, *xdn6 ); - *xup1 = L_add( *xup1, *xdn6 ); + t1 = L_sub( *xup1, *xdn6 ); /*Qx*/ + *xup1 = L_add( *xup1, *xdn6 ); /*Qx*/ move32(); xup1 += n4; xdn6 -= n4; - t2 = L_sub( *xdn6, *xup1 ); - *xdn6 = L_add( *xup1, *xdn6 ); + t2 = L_sub( *xdn6, *xup1 ); /*Qx*/ + *xdn6 = L_add( *xup1, *xdn6 ); /*Qx*/ move32(); xdn6 += n4; - t3 = L_add( *xdn8, *xup3 ); - *xdn6 = L_sub( *xdn8, *xup3 ); + t3 = L_add( *xdn8, *xup3 ); /*Qx*/ + *xdn6 = L_sub( *xdn8, *xup3 ); /*Qx*/ move32(); xup3 += n4; xdn8 -= n4; - t4 = L_add( *xup3, *xdn8 ); - *xup1 = L_sub( *xup3, *xdn8 ); + t4 = L_add( *xup3, *xdn8 ); /*Qx*/ + *xup1 = L_sub( *xup3, *xdn8 ); /*Qx*/ move32(); - t5 = L_sub( t1, t4 ); - t1 = L_add( t1, t4 ); - t4 = L_sub( t2, t3 ); - t2 = L_add( t2, t3 ); - *xup3 = L_sub( Mpy_32_16_1( t1, cc3 ), Mpy_32_16_1( t2, ss3 ) ); + t5 = L_sub( t1, t4 ); /*Qx*/ + t1 = L_add( t1, t4 ); /*Qx*/ + t4 = L_sub( t2, t3 ); /*Qx*/ + t2 = L_add( t2, t3 ); /*Qx*/ + *xup3 = L_sub( Mpy_32_16_1( t1, cc3 ), Mpy_32_16_1( t2, ss3 ) ); /*Qx*/ move32(); xup3 -= n4; - *xup3 = L_add( Mpy_32_16_1( t5, cc1 ), Mpy_32_16_1( t4, ss1 ) ); + *xup3 = L_add( Mpy_32_16_1( t5, cc1 ), Mpy_32_16_1( t4, ss1 ) ); /*Qx*/ move32(); - *xdn8 = L_sub( Mpy_32_16_1( t5, ss1 ), Mpy_32_16_1( t4, cc1 ) ); + *xdn8 = L_sub( Mpy_32_16_1( t5, ss1 ), Mpy_32_16_1( t4, cc1 ) ); /*Qx*/ move32(); xdn8 += n4; - *xdn8 = L_add( Mpy_32_16_1( t2, cc3 ), Mpy_32_16_1( t1, ss3 ) ); + *xdn8 = L_add( Mpy_32_16_1( t2, cc3 ), Mpy_32_16_1( t1, ss3 ) ); /*Qx*/ move32(); xup1 -= n4; @@ -822,8 +786,8 @@ void ifft_rel_fx32( xdn6 += id; xdn8 += id; } - is = sub( shl( id, 1 ), n2 ); - id = shl( id, 2 ); + is = sub( shl( id, 1 ), n2 ); /*Q0*/ + id = shl( id, 2 ); /*Q0*/ } } } @@ -843,11 +807,11 @@ void ifft_rel_fx32( FOR( i0 = is; i0 <= n; i0 += id ) { - r1 = *xi0; + r1 = *xi0; /*Qx*/ move32(); - *xi0 = L_add( r1, *xi1 ); + *xi0 = L_add( r1, *xi1 ); /*Qx*/ move32(); - *xi1 = L_sub( r1, *xi1 ); + *xi1 = L_sub( r1, *xi1 ); /*Qx*/ move32(); xi0 += id; xi1 += id; @@ -867,7 +831,8 @@ void ifft_rel_fx32( FOR( i = 0; i < n; i++ ) { j = *idx++; - temp[i] = x[1 + shr( j, 1 )]; + move16(); + temp[i] = x[1 + shr( j, 1 )]; /*Qx*/ move32(); } } @@ -876,7 +841,7 @@ void ifft_rel_fx32( FOR( i = 0; i < n; i++ ) { j = *idx++; - temp[i] = x[1 + j]; + temp[i] = x[1 + j]; /*Qx*/ move32(); } } @@ -885,9 +850,9 @@ void ifft_rel_fx32( FOR( i = 0; i < 256; i++ ) { j = *idx++; - temp[i] = x[1 + 2 * j]; + temp[i] = x[1 + 2 * j]; /*Qx*/ move32(); - temp[i + 256] = x[2 + 2 * j]; + temp[i + 256] = x[2 + 2 * j]; /*Qx*/ move32(); } } @@ -895,13 +860,14 @@ void ifft_rel_fx32( { xi0 = x; j = 1; + move16(); FOR( i = 1; i < n; i++ ) { IF( LT_16( i, j ) ) { - xt = x[j]; - x[j] = x[i]; - x[i] = xt; + xt = x[j]; /*Qx*/ + x[j] = x[i]; /*Qx*/ + x[i] = xt; /*Qx*/ move32(); move32(); move32(); @@ -922,7 +888,7 @@ void ifft_rel_fx32( FOR( i = 1; i <= n; i++ ) { - x[i] = Mpy_32_16_1( xi0[i], n_inv ); + x[i] = Mpy_32_16_1( xi0[i], n_inv ); /*Qx*/ move32(); } diff --git a/lib_com/igf_base_fx.c b/lib_com/igf_base_fx.c index b087695b5..5b2f81f93 100644 --- a/lib_com/igf_base_fx.c +++ b/lib_com/igf_base_fx.c @@ -22,17 +22,17 @@ Word16 IGF_ApplyTransFac( /**< ou { Word16 ret; - IF( EQ_16( transFac, 0x4000 ) ) + IF( EQ_16( transFac, 0x4000 /*ONE in Q14*/ ) ) { return val; } ret = shl( val, 1 ); ret = mac_r( 0x00000000, ret, transFac ); - ret = add( ret, s_and( ret, 1 ) ); + ret = add( ret, s_and( ret, 1 ) ); /*Q0*/ - return ret; + return ret; /*Q0*/ } /**********************************************************************/ /* @@ -53,6 +53,7 @@ Word16 IGF_MapBitRateToIndex( SWITCH( bwidth ) { case IGF_MODE_WB: + test(); IF( LE_32( brate, IVAS_13k2 ) && EQ_16( rf_mode, 1 ) ) { bitRateIndex = IGF_BITRATE_RF_WB_13200; @@ -178,6 +179,7 @@ Word16 IGF_MapBitRateToIndex( SWITCH( bwidth ) { case IGF_MODE_WB: + test(); IF( LE_32( brate, IVAS_13k2 ) && EQ_16( rf_mode, 1 ) ) { bitRateIndex = IGF_BITRATE_RF_WB_13200; @@ -279,6 +281,7 @@ Word16 IGF_MapBitRateToIndex( SWITCH( bwidth ) { case IGF_MODE_WB: + test(); IF( LE_32( brate, ACELP_13k20 ) && EQ_16( rf_mode, 1 ) ) { bitRateIndex = IGF_BITRATE_RF_WB_13200; @@ -375,7 +378,7 @@ Word16 IGF_MapBitRateToIndex( } } - return bitRateIndex; + return bitRateIndex; /*Q0*/ } /**********************************************************************/ /* @@ -385,7 +388,7 @@ static void IGF_gridSetUp( H_IGF_GRID hGrid, /**< ou Word16 bitRateIndex, /**< in: Q0 | IGF bitrate index */ Word32 sampleRate, /**< in: | sample rate */ Word16 frameLength, /**< in: | frame length */ - Word16 transFac, /**< in: | transFac */ + Word16 transFac, /**< in: Q14 |transFac */ Word16 igfMinFq /**< in: | IGF minimum frequency indicating lower start frequency for copy up */ ) { @@ -401,7 +404,6 @@ static void IGF_gridSetUp( H_IGF_GRID hGrid, /**< ou Word32 L_tmp2; swb_offset = NULL; - move16(); swb_offset_len = 0; move16(); @@ -417,7 +419,7 @@ static void IGF_gridSetUp( H_IGF_GRID hGrid, /**< ou case IGF_BITRATE_SWB_32000: case IGF_BITRATE_SWB_48000: swb_offset = &swb_offset_LB_new[bitRateIndex][1]; - swb_offset_len = swb_offset_LB_new[bitRateIndex][0]; + swb_offset_len = swb_offset_LB_new[bitRateIndex][0]; /*Q0*/ move16(); Copy( &igf_whitening_TH[bitRateIndex][0][0], &hGrid->whiteningThreshold[0][0], IGF_MAX_TILES * 2 ); BREAK; @@ -425,7 +427,7 @@ static void IGF_gridSetUp( H_IGF_GRID hGrid, /**< ou case IGF_BITRATE_FB_24400: case IGF_BITRATE_FB_32000: swb_offset = &swb_offset_LB_new[bitRateIndex][1]; - swb_offset_len = swb_offset_LB_new[bitRateIndex][0]; + swb_offset_len = swb_offset_LB_new[bitRateIndex][0]; /*Q0*/ move16(); Copy( &igf_whitening_TH[bitRateIndex][0][0], &hGrid->whiteningThreshold[0][0], IGF_MAX_TILES * 2 ); BREAK; @@ -433,7 +435,7 @@ static void IGF_gridSetUp( H_IGF_GRID hGrid, /**< ou case IGF_BITRATE_FB_96000: case IGF_BITRATE_FB_128000: swb_offset = &swb_offset_LB_new[bitRateIndex][1]; - swb_offset_len = swb_offset_LB_new[bitRateIndex][0]; + swb_offset_len = swb_offset_LB_new[bitRateIndex][0]; /*Q0*/ move16(); Copy( &igf_whitening_TH[bitRateIndex][0][0], &hGrid->whiteningThreshold[0][0], IGF_MAX_TILES * 2 ); BREAK; @@ -444,50 +446,50 @@ static void IGF_gridSetUp( H_IGF_GRID hGrid, /**< ou FOR( sfb = 0; sfb < swb_offset_len; sfb++ ) { - hGrid->swb_offset[sfb] = IGF_ApplyTransFac( swb_offset[sfb], transFac ); + hGrid->swb_offset[sfb] = IGF_ApplyTransFac( swb_offset[sfb], transFac ); /*Q0*/ move16(); } hGrid->infoIsRefined = 0; move16(); - frameLength = IGF_ApplyTransFac( frameLength, transFac ); + frameLength = IGF_ApplyTransFac( frameLength, transFac ); /*Q0*/ tmp2 = norm_s( frameLength ); - bandwidth = shl( frameLength, tmp2 ); - hGrid->swb_offset_len = extract_l( L_shr( sampleRate, 2 ) ); + bandwidth = shl( frameLength, tmp2 ); /*tmp2*/ + hGrid->swb_offset_len = extract_l( L_shr( sampleRate, 2 ) ); /*-1*/ move16(); tmp1 = sub( norm_s( hGrid->swb_offset_len ), 1 ); - hGrid->swb_offset_len = shl( hGrid->swb_offset_len, tmp1 ); + hGrid->swb_offset_len = shl( hGrid->swb_offset_len, tmp1 ); /*tmp1-1*/ move16(); - bandwidth = div_s( hGrid->swb_offset_len, bandwidth ); + bandwidth = div_s( hGrid->swb_offset_len, bandwidth ); /*15 + tmp1-1-tmp2*/ tmp2 = sub( add( tmp2, 1 ), tmp1 ); - bandwidth = shr( bandwidth, sub( 15, tmp2 ) ); + bandwidth = shr( bandwidth, sub( 15, tmp2 ) ); /*Q0*/ - hGrid->swb_offset_len = swb_offset_len; + hGrid->swb_offset_len = swb_offset_len; /*Q0*/ move16(); hGrid->startSfb = 0; move16(); - hGrid->stopSfb = sub( hGrid->swb_offset_len, 1 ); + hGrid->stopSfb = sub( hGrid->swb_offset_len, 1 ); /*Q0*/ move16(); - hGrid->startLine = hGrid->swb_offset[hGrid->startSfb]; + hGrid->startLine = hGrid->swb_offset[hGrid->startSfb]; /*Q0*/ move16(); - hGrid->stopLine = hGrid->swb_offset[hGrid->stopSfb]; + hGrid->stopLine = hGrid->swb_offset[hGrid->stopSfb]; /*Q0*/ move16(); - hGrid->startFrequency = imult1616( bandwidth, hGrid->startLine ); + hGrid->startFrequency = imult1616( bandwidth, hGrid->startLine ); /*Q0*/ move16(); - hGrid->stopFrequency = imult1616( bandwidth, hGrid->stopLine ); + hGrid->stopFrequency = imult1616( bandwidth, hGrid->stopLine ); /*Q0*/ move16(); - L_tmp1 = L_mult0( igfMinFq, frameLength ); + L_tmp1 = L_mult0( igfMinFq, frameLength ); /*Q0*/ tmp1 = sub( norm_l( L_tmp1 ), 1 ); - L_tmp1 = L_shl( L_tmp1, tmp1 ); + L_tmp1 = L_shl( L_tmp1, tmp1 ); /*tmp1*/ tmp2 = norm_l( sampleRate ); - L_tmp2 = L_shl( sampleRate, tmp2 ); + L_tmp2 = L_shl( sampleRate, tmp2 ); /*tmp2*/ tmp1 = add( WORD16_BITS - 1, sub( tmp1, add( tmp2, 1 ) ) ); /* takes into account sampleRate >> 1 */ - hGrid->minSrcSubband = div_s( extract_h( L_tmp1 ), extract_h( L_tmp2 ) ); - hGrid->minSrcSubband = shr( hGrid->minSrcSubband, tmp1 ); + hGrid->minSrcSubband = div_s( extract_h( L_tmp1 ), extract_h( L_tmp2 ) ); /*tmp1*/ + hGrid->minSrcSubband = shr( hGrid->minSrcSubband, tmp1 ); /*Q0*/ move16(); move16(); @@ -496,14 +498,14 @@ static void IGF_gridSetUp( H_IGF_GRID hGrid, /**< ou move16(); hGrid->minSrcFrequency = imult1616( bandwidth, hGrid->minSrcSubband ); move16(); - hGrid->infoGranuleLen = frameLength; + hGrid->infoGranuleLen = frameLength; /*Q0*/ move16(); - hGrid->infoTransFac = transFac; + hGrid->infoTransFac = transFac; /*Q14*/ move16(); hGrid->sfbWrap[0] = 0; move16(); - hGrid->tile[0] = hGrid->startLine; + hGrid->tile[0] = hGrid->startLine; /*Q0*/ move16(); @@ -518,19 +520,19 @@ static void IGF_gridSetUp( H_IGF_GRID hGrid, /**< ou move16(); /*1st*/ - hGrid->sfbWrap[0 + 1] = wrp_sfb; + hGrid->sfbWrap[0 + 1] = wrp_sfb; /*Q0*/ move16(); - hGrid->sbWrap[0] = hGrid->minSrcSubband; + hGrid->sbWrap[0] = hGrid->minSrcSubband; /*Q0*/ move16(); - hGrid->tile[0 + 1] = hGrid->swb_offset[wrp_sfb]; + hGrid->tile[0 + 1] = hGrid->swb_offset[wrp_sfb]; /*Q0*/ move16(); /*2nd*/ - hGrid->sfbWrap[1 + 1] = hGrid->stopSfb; + hGrid->sfbWrap[1 + 1] = hGrid->stopSfb; /*Q0*/ move16(); - hGrid->sbWrap[1] = hGrid->minSrcSubband; + hGrid->sbWrap[1] = hGrid->minSrcSubband; /*Q0*/ move16(); - hGrid->tile[1 + 1] = hGrid->swb_offset[hGrid->stopSfb]; + hGrid->tile[1 + 1] = hGrid->swb_offset[hGrid->stopSfb]; /*Q0*/ move16(); BREAK; @@ -541,19 +543,19 @@ static void IGF_gridSetUp( H_IGF_GRID hGrid, /**< ou move16(); /*1st*/ - hGrid->sfbWrap[0 + 1] = wrp_sfb; + hGrid->sfbWrap[0 + 1] = wrp_sfb; /*Q0*/ move16(); - hGrid->sbWrap[0] = hGrid->minSrcSubband; + hGrid->sbWrap[0] = hGrid->minSrcSubband; /*Q0*/ move16(); - hGrid->tile[0 + 1] = hGrid->swb_offset[wrp_sfb]; + hGrid->tile[0 + 1] = hGrid->swb_offset[wrp_sfb]; /*Q0*/ move16(); /*2nd*/ - hGrid->sfbWrap[1 + 1] = hGrid->stopSfb; + hGrid->sfbWrap[1 + 1] = hGrid->stopSfb; /*Q0*/ move16(); - hGrid->sbWrap[1] = hGrid->minSrcSubband; + hGrid->sbWrap[1] = hGrid->minSrcSubband; /*Q0*/ move16(); - hGrid->tile[1 + 1] = hGrid->swb_offset[hGrid->stopSfb]; + hGrid->tile[1 + 1] = hGrid->swb_offset[hGrid->stopSfb]; /*Q0*/ move16(); BREAK; @@ -564,29 +566,29 @@ static void IGF_gridSetUp( H_IGF_GRID hGrid, /**< ou move16(); /*1st*/ - hGrid->sfbWrap[0 + 1] = wrp_sfb; + hGrid->sfbWrap[0 + 1] = wrp_sfb; /*Q0*/ move16(); - hGrid->sbWrap[0] = hGrid->minSrcSubband; + hGrid->sbWrap[0] = hGrid->minSrcSubband; /*Q0*/ move16(); - hGrid->tile[0 + 1] = hGrid->swb_offset[wrp_sfb]; + hGrid->tile[0 + 1] = hGrid->swb_offset[wrp_sfb]; /*Q0*/ move16(); /*2nd*/ wrp_sfb = 2; move16(); - hGrid->sfbWrap[1 + 1] = wrp_sfb; + hGrid->sfbWrap[1 + 1] = wrp_sfb; /*Q0*/ move16(); - hGrid->sbWrap[1] = hGrid->minSrcSubband + IGF_ApplyTransFac( 32, transFac ); + hGrid->sbWrap[1] = hGrid->minSrcSubband + IGF_ApplyTransFac( 32, transFac ); /*Q0*/ move16(); - hGrid->tile[1 + 1] = hGrid->swb_offset[wrp_sfb]; + hGrid->tile[1 + 1] = hGrid->swb_offset[wrp_sfb]; /*Q0*/ move16(); /*3rd*/ - hGrid->sfbWrap[2 + 1] = hGrid->stopSfb; + hGrid->sfbWrap[2 + 1] = hGrid->stopSfb; /*Q0*/ move16(); - hGrid->sbWrap[2] = hGrid->minSrcSubband + IGF_ApplyTransFac( 46, transFac ); + hGrid->sbWrap[2] = hGrid->minSrcSubband + IGF_ApplyTransFac( 46, transFac ); /*Q0*/ move16(); - hGrid->tile[2 + 1] = hGrid->swb_offset[hGrid->stopSfb]; + hGrid->tile[2 + 1] = hGrid->swb_offset[hGrid->stopSfb]; /*Q0*/ move16(); BREAK; @@ -597,29 +599,29 @@ static void IGF_gridSetUp( H_IGF_GRID hGrid, /**< ou move16(); /*1st*/ - hGrid->sfbWrap[0 + 1] = wrp_sfb; + hGrid->sfbWrap[0 + 1] = wrp_sfb; /*Q0*/ move16(); - hGrid->sbWrap[0] = hGrid->minSrcSubband; + hGrid->sbWrap[0] = hGrid->minSrcSubband; /*Q0*/ move16(); - hGrid->tile[0 + 1] = hGrid->swb_offset[wrp_sfb]; + hGrid->tile[0 + 1] = hGrid->swb_offset[wrp_sfb]; /*Q0*/ move16(); /*2nd*/ wrp_sfb = 2; move16(); - hGrid->sfbWrap[1 + 1] = wrp_sfb; + hGrid->sfbWrap[1 + 1] = wrp_sfb; /*Q0*/ move16(); - hGrid->sbWrap[1] = hGrid->minSrcSubband + IGF_ApplyTransFac( 32, transFac ); + hGrid->sbWrap[1] = hGrid->minSrcSubband + IGF_ApplyTransFac( 32, transFac ); /*Q0*/ move16(); - hGrid->tile[1 + 1] = hGrid->swb_offset[wrp_sfb]; + hGrid->tile[1 + 1] = hGrid->swb_offset[wrp_sfb]; /*Q0*/ move16(); /*3rd*/ - hGrid->sfbWrap[2 + 1] = hGrid->stopSfb; + hGrid->sfbWrap[2 + 1] = hGrid->stopSfb; /*Q0*/ move16(); - hGrid->sbWrap[2] = hGrid->minSrcSubband + IGF_ApplyTransFac( 46, transFac ); + hGrid->sbWrap[2] = hGrid->minSrcSubband + IGF_ApplyTransFac( 46, transFac ); /*Q0*/ move16(); - hGrid->tile[2 + 1] = hGrid->swb_offset[hGrid->stopSfb]; + hGrid->tile[2 + 1] = hGrid->swb_offset[hGrid->stopSfb]; /*Q0*/ move16(); BREAK; @@ -631,19 +633,19 @@ static void IGF_gridSetUp( H_IGF_GRID hGrid, /**< ou move16(); /*1st*/ - hGrid->sfbWrap[0 + 1] = wrp_sfb; + hGrid->sfbWrap[0 + 1] = wrp_sfb; /*Q0*/ move16(); - hGrid->sbWrap[0] = hGrid->minSrcSubband; + hGrid->sbWrap[0] = hGrid->minSrcSubband; /*Q0*/ move16(); - hGrid->tile[0 + 1] = hGrid->swb_offset[wrp_sfb]; + hGrid->tile[0 + 1] = hGrid->swb_offset[wrp_sfb]; /*Q0*/ move16(); /*2nd*/ - hGrid->sfbWrap[1 + 1] = hGrid->stopSfb; + hGrid->sfbWrap[1 + 1] = hGrid->stopSfb; /*Q0*/ move16(); - hGrid->sbWrap[1] = add( hGrid->minSrcSubband, IGF_ApplyTransFac( 32, transFac ) ); + hGrid->sbWrap[1] = add( hGrid->minSrcSubband, IGF_ApplyTransFac( 32, transFac ) ); /*Q0*/ move16(); - hGrid->tile[1 + 1] = hGrid->swb_offset[hGrid->stopSfb]; + hGrid->tile[1 + 1] = hGrid->swb_offset[hGrid->stopSfb]; /*Q0*/ move16(); BREAK; @@ -654,27 +656,27 @@ static void IGF_gridSetUp( H_IGF_GRID hGrid, /**< ou move16(); /*1st*/ - hGrid->sfbWrap[0 + 1] = wrp_sfb; + hGrid->sfbWrap[0 + 1] = wrp_sfb; /*Q0*/ move16(); - hGrid->sbWrap[0] = hGrid->minSrcSubband; + hGrid->sbWrap[0] = hGrid->minSrcSubband; /*Q0*/ move16(); - hGrid->tile[0 + 1] = hGrid->swb_offset[wrp_sfb]; + hGrid->tile[0 + 1] = hGrid->swb_offset[wrp_sfb]; /*Q0*/ move16(); /*2nd*/ hGrid->sfbWrap[1 + 1] = 6; move16(); - hGrid->sbWrap[1] = add( hGrid->minSrcSubband, IGF_ApplyTransFac( 48, transFac ) ); + hGrid->sbWrap[1] = add( hGrid->minSrcSubband, IGF_ApplyTransFac( 48, transFac ) ); /*Q0*/ move16(); - hGrid->tile[1 + 1] = hGrid->swb_offset[6]; + hGrid->tile[1 + 1] = hGrid->swb_offset[6]; /*Q0*/ move16(); /*3nd*/ - hGrid->sfbWrap[2 + 1] = hGrid->stopSfb; + hGrid->sfbWrap[2 + 1] = hGrid->stopSfb; /*Q0*/ move16(); - hGrid->sbWrap[2] = add( hGrid->minSrcSubband, IGF_ApplyTransFac( 64, transFac ) ); + hGrid->sbWrap[2] = add( hGrid->minSrcSubband, IGF_ApplyTransFac( 64, transFac ) ); /*Q0*/ move16(); - hGrid->tile[2 + 1] = hGrid->swb_offset[hGrid->stopSfb]; + hGrid->tile[2 + 1] = hGrid->swb_offset[hGrid->stopSfb]; /*Q0*/ move16(); BREAK; @@ -686,27 +688,27 @@ static void IGF_gridSetUp( H_IGF_GRID hGrid, /**< ou move16(); /*1st*/ - hGrid->sfbWrap[0 + 1] = wrp_sfb; + hGrid->sfbWrap[0 + 1] = wrp_sfb; /*Q0*/ move16(); - hGrid->sbWrap[0] = hGrid->minSrcSubband; + hGrid->sbWrap[0] = hGrid->minSrcSubband; /*Q0*/ move16(); - hGrid->tile[0 + 1] = hGrid->swb_offset[wrp_sfb]; + hGrid->tile[0 + 1] = hGrid->swb_offset[wrp_sfb]; /*Q0*/ move16(); /*2nd*/ hGrid->sfbWrap[1 + 1] = 7; move16(); - hGrid->sbWrap[1] = add( hGrid->minSrcSubband, IGF_ApplyTransFac( 32, transFac ) ); + hGrid->sbWrap[1] = add( hGrid->minSrcSubband, IGF_ApplyTransFac( 32, transFac ) ); /*Q0*/ move16(); - hGrid->tile[1 + 1] = hGrid->swb_offset[7]; + hGrid->tile[1 + 1] = hGrid->swb_offset[7]; /*Q0*/ move16(); /*3nd*/ - hGrid->sfbWrap[2 + 1] = hGrid->stopSfb; + hGrid->sfbWrap[2 + 1] = hGrid->stopSfb; /*Q0*/ move16(); - hGrid->sbWrap[2] = add( hGrid->minSrcSubband, IGF_ApplyTransFac( 64, transFac ) ); + hGrid->sbWrap[2] = add( hGrid->minSrcSubband, IGF_ApplyTransFac( 64, transFac ) ); /*Q0*/ move16(); - hGrid->tile[2 + 1] = hGrid->swb_offset[hGrid->stopSfb]; + hGrid->tile[2 + 1] = hGrid->swb_offset[hGrid->stopSfb]; /*Q0*/ move16(); BREAK; case IGF_BITRATE_SWB_48000: @@ -716,11 +718,11 @@ static void IGF_gridSetUp( H_IGF_GRID hGrid, /**< ou move16(); /*1st*/ - hGrid->sfbWrap[0 + 1] = hGrid->stopSfb; + hGrid->sfbWrap[0 + 1] = hGrid->stopSfb; /*Q0*/ move16(); - hGrid->sbWrap[0] = sub( shl( hGrid->startLine, 1 ), hGrid->stopLine ); + hGrid->sbWrap[0] = sub( shl( hGrid->startLine, 1 ), hGrid->stopLine ); /*Q0*/ move16(); - hGrid->tile[0 + 1] = hGrid->swb_offset[hGrid->stopSfb]; + hGrid->tile[0 + 1] = hGrid->swb_offset[hGrid->stopSfb]; /*Q0*/ move16(); BREAK; @@ -731,29 +733,29 @@ static void IGF_gridSetUp( H_IGF_GRID hGrid, /**< ou move16(); /*1st*/ - hGrid->sfbWrap[0 + 1] = wrp_sfb; + hGrid->sfbWrap[0 + 1] = wrp_sfb; /*Q0*/ move16(); - hGrid->sbWrap[0] = hGrid->minSrcSubband; + hGrid->sbWrap[0] = hGrid->minSrcSubband; /*Q0*/ move16(); - hGrid->tile[0 + 1] = hGrid->swb_offset[wrp_sfb]; + hGrid->tile[0 + 1] = hGrid->swb_offset[wrp_sfb]; /*Q0*/ move16(); wrp_sfb = 7; move16(); /*2nd*/ - hGrid->sfbWrap[1 + 1] = wrp_sfb; + hGrid->sfbWrap[1 + 1] = wrp_sfb; /*Q0*/ move16(); - hGrid->sbWrap[1] = hGrid->minSrcSubband; + hGrid->sbWrap[1] = hGrid->minSrcSubband; /*Q0*/ move16(); - hGrid->tile[1 + 1] = hGrid->swb_offset[wrp_sfb]; + hGrid->tile[1 + 1] = hGrid->swb_offset[wrp_sfb]; /*Q0*/ move16(); /*3nd*/ - hGrid->sfbWrap[2 + 1] = hGrid->stopSfb; + hGrid->sfbWrap[2 + 1] = hGrid->stopSfb; /*Q0*/ move16(); - hGrid->sbWrap[2] = hGrid->minSrcSubband; + hGrid->sbWrap[2] = hGrid->minSrcSubband; /*Q0*/ move16(); - hGrid->tile[2 + 1] = hGrid->swb_offset[hGrid->stopSfb]; + hGrid->tile[2 + 1] = hGrid->swb_offset[hGrid->stopSfb]; /*Q0*/ move16(); BREAK; @@ -766,39 +768,39 @@ static void IGF_gridSetUp( H_IGF_GRID hGrid, /**< ou move16(); /*1st*/ - hGrid->sfbWrap[0 + 1] = wrp_sfb; + hGrid->sfbWrap[0 + 1] = wrp_sfb; /*Q0*/ move16(); - hGrid->sbWrap[0] = hGrid->minSrcSubband; + hGrid->sbWrap[0] = hGrid->minSrcSubband; /*Q0*/ move16(); - hGrid->tile[0 + 1] = hGrid->swb_offset[wrp_sfb]; + hGrid->tile[0 + 1] = hGrid->swb_offset[wrp_sfb]; /*Q0*/ move16(); wrp_sfb = 6; move16(); /*2nd*/ - hGrid->sfbWrap[1 + 1] = wrp_sfb; + hGrid->sfbWrap[1 + 1] = wrp_sfb; /*Q0*/ move16(); - hGrid->sbWrap[1] = add( hGrid->minSrcSubband, IGF_ApplyTransFac( 32, transFac ) ); + hGrid->sbWrap[1] = add( hGrid->minSrcSubband, IGF_ApplyTransFac( 32, transFac ) ); /*Q0*/ move16(); - hGrid->tile[1 + 1] = hGrid->swb_offset[wrp_sfb]; + hGrid->tile[1 + 1] = hGrid->swb_offset[wrp_sfb]; /*Q0*/ move16(); wrp_sfb = 9; move16(); /*3nd*/ - hGrid->sfbWrap[2 + 1] = wrp_sfb; + hGrid->sfbWrap[2 + 1] = wrp_sfb; /*Q0*/ move16(); - hGrid->sbWrap[2] = hGrid->minSrcSubband; + hGrid->sbWrap[2] = hGrid->minSrcSubband; /*Q0*/ move16(); - hGrid->tile[2 + 1] = hGrid->swb_offset[wrp_sfb]; + hGrid->tile[2 + 1] = hGrid->swb_offset[wrp_sfb]; /*Q0*/ move16(); /*4nd*/ - hGrid->sfbWrap[3 + 1] = hGrid->stopSfb; + hGrid->sfbWrap[3 + 1] = hGrid->stopSfb; /*Q0*/ move16(); - hGrid->sbWrap[3] = add( hGrid->minSrcSubband, sub( hGrid->swb_offset[9], hGrid->swb_offset[8] ) ); + hGrid->sbWrap[3] = add( hGrid->minSrcSubband, sub( hGrid->swb_offset[9], hGrid->swb_offset[8] ) ); /*Q0*/ move16(); - hGrid->tile[3 + 1] = hGrid->swb_offset[hGrid->stopSfb]; + hGrid->tile[3 + 1] = hGrid->swb_offset[hGrid->stopSfb]; /*Q0*/ move16(); BREAK; case IGF_BITRATE_FB_48000: @@ -808,11 +810,11 @@ static void IGF_gridSetUp( H_IGF_GRID hGrid, /**< ou move16(); /*1st*/ - hGrid->sfbWrap[0 + 1] = hGrid->stopSfb; + hGrid->sfbWrap[0 + 1] = hGrid->stopSfb; /*Q0*/ move16(); - hGrid->sbWrap[0] = sub( shl( hGrid->startLine, 1 ), hGrid->stopLine ); + hGrid->sbWrap[0] = sub( shl( hGrid->startLine, 1 ), hGrid->stopLine ); /*Q0*/ move16(); - hGrid->tile[0 + 1] = hGrid->swb_offset[hGrid->stopSfb]; + hGrid->tile[0 + 1] = hGrid->swb_offset[hGrid->stopSfb]; /*Q0*/ move16(); BREAK; @@ -913,12 +915,12 @@ static void IGF_gridSetUp_ivas_fx( test(); test(); - IF( EQ_16( transFac, 8192 ) && EQ_16( bitRateIndex, IGF_BITRATE_SWB_48000_CPE ) ) + IF( EQ_16( transFac, 8192 /*0.5 in Q14*/ ) && EQ_16( bitRateIndex, IGF_BITRATE_SWB_48000_CPE ) ) { bitRateIndex = IGF_BITRATE_SWB_48000_CPE_TCX10; move16(); } - ELSE IF( EQ_16( transFac, 8192 ) && EQ_16( bitRateIndex, IGF_BITRATE_FB_48000_CPE ) ) + ELSE IF( EQ_16( transFac, 8192 /*0.5 in Q14*/ ) && EQ_16( bitRateIndex, IGF_BITRATE_FB_48000_CPE ) ) { bitRateIndex = IGF_BITRATE_FB_48000_CPE_TCX10; move16(); @@ -949,18 +951,18 @@ static void IGF_gridSetUp_ivas_fx( hGrid->infoIsRefined = 0; move16(); - frameLength = IGF_ApplyTransFac( frameLength, transFac ); + frameLength = IGF_ApplyTransFac( frameLength, transFac ); /*Q0*/ tmp2 = norm_s( frameLength ); - bandwidth_fx = shl( frameLength, tmp2 ); - hGrid->swb_offset_len = extract_l( L_shr( sampleRate, 2 ) ); + bandwidth_fx = shl( frameLength, tmp2 ); /*tmp2*/ + hGrid->swb_offset_len = extract_l( L_shr( sampleRate, 2 ) ); /*-1*/ move16(); tmp1 = sub( norm_s( hGrid->swb_offset_len ), 1 ); - hGrid->swb_offset_len = shl( hGrid->swb_offset_len, tmp1 ); + hGrid->swb_offset_len = shl( hGrid->swb_offset_len, tmp1 ); /*tmp1-1*/ move16(); - bandwidth_fx = div_s( hGrid->swb_offset_len, bandwidth_fx ); + bandwidth_fx = div_s( hGrid->swb_offset_len, bandwidth_fx ); /*15 + tmp1-1-tmp2*/ tmp2 = sub( add( tmp2, 1 ), tmp1 ); bandwidth_fx = shr( bandwidth_fx, sub( 15, tmp2 ) ); - hGrid->swb_offset_len = swb_offset_len; + hGrid->swb_offset_len = swb_offset_len; /*Q0*/ move16(); hGrid->startSfb = 0; move16(); @@ -982,17 +984,17 @@ static void IGF_gridSetUp_ivas_fx( tmp1 = add( WORD16_BITS - 1, sub( tmp1, add( tmp2, 1 ) ) ); /* takes into account sampleRate >> 1 */ hGrid->minSrcSubband = div_s( extract_h( L_tmp1 ), extract_h( L_tmp2 ) ); move16(); - hGrid->minSrcSubband = shr( hGrid->minSrcSubband, tmp1 ); + hGrid->minSrcSubband = shr( hGrid->minSrcSubband, tmp1 ); /*Q0*/ move16(); hGrid->minSrcSubband = add( hGrid->minSrcSubband, s_and( hGrid->minSrcSubband, 1 ) ); move16(); - hGrid->minSrcFrequency = imult1616( bandwidth_fx, hGrid->minSrcSubband ); + hGrid->minSrcFrequency = imult1616( bandwidth_fx, hGrid->minSrcSubband ); /*Q0*/ move16(); - hGrid->infoGranuleLen = frameLength; + hGrid->infoGranuleLen = frameLength; /*Q0*/ move16(); hGrid->sfbWrap[0] = 0; move16(); - hGrid->tile[0] = hGrid->startLine; + hGrid->tile[0] = hGrid->startLine; /*Q0*/ move16(); igf_tile_offset = &igf_tile_offset_table[bitRateIndex][1]; @@ -1008,7 +1010,7 @@ static void IGF_gridSetUp_ivas_fx( move16(); hGrid->sbWrap[k] = add( hGrid->minSrcSubband, IGF_ApplyTransFac( igf_tile_offset[2 * k + 1], transFac ) ); move16(); - hGrid->tile[k + 1] = hGrid->swb_offset[igf_tile_offset[2 * k]]; + hGrid->tile[k + 1] = hGrid->swb_offset[igf_tile_offset[2 * k]]; /*Q0*/ move16(); } FOR( t = hGrid->nTiles + 1; t < IGF_MAX_TILES; t++ ) @@ -1128,7 +1130,7 @@ void IGFCommonFuncsCalcSfbEnergyPowerSpec( const Word16 startSfb, /**< in FOR( sfb = startSfb; sfb < stopSfb; sfb++ ) { sfbEnergy[sfb] = L_deposit_l( 0 ); - move16(); + move32(); } IF( NULL == pPowerSpectrum ) { @@ -1168,9 +1170,9 @@ calculate the MDCT square spectrum in the IGF range **************************************************************************/ void IGFCommonFuncsMDCTSquareSpec( const Word16 sqrtBgn, /**< in: Q0 | start MDCT subband index */ const Word16 sqrtEnd, /**< in: Q0 | stop MDCT subband index */ - const Word32 *mdctSpec, /**< in: Q31 | MDCT spectrum to square */ + const Word32 *mdctSpec, /**< in: | MDCT spectrum to square */ const Word16 mdctSpec_e, /**< in: | exponent of mdctSpectrum */ - Word32 *mdctSquareSpec, /**< out:Q31 | MDCT square spectrum */ + Word32 *mdctSquareSpec, /**< out: | MDCT square spectrum */ Word16 *mdctSquareSpec_e, /**< out: | exponent of mdctSquareSpec */ Word16 indexOffset /**< in: Q0 | index offset */ ) @@ -1195,11 +1197,11 @@ void IGFCommonFuncsMDCTSquareSpec( const Word16 sqrtBgn, /**< in FOR( i = sqrtBgn; i < sqrtEnd; i++ ) { #ifdef BASOP_NOGLOB - tmp = round_fx_sat( L_shl_sat( mdctSpec[i], s1 ) ); + tmp = round_fx_sat( L_shl_sat( mdctSpec[i], s1 ) ); /*(15 - mdctSpec_e)+ S1*/ #else tmp = round_fx( L_shl( mdctSpec[i], s1 ) ); #endif - mdctSquareSpec[j++] = L_mult0( tmp, tmp ); + mdctSquareSpec[j++] = L_mult0( tmp, tmp ); /*31 - mdctSquareSpec_e*/ move32(); } } @@ -1209,9 +1211,9 @@ calculate the MDCT square spectrum in the IGF range (for IVAS) **************************************************************************/ void IGFCommonFuncsMDCTSquareSpec_ivas( const Word16 sqrtBgn, /**< in: Q0 | start MDCT subband index */ const Word16 sqrtEnd, /**< in: Q0 | stop MDCT subband index */ - const Word32 *mdctSpec, /**< in: Q31 | MDCT spectrum to square */ + const Word32 *mdctSpec, /**< in: | MDCT spectrum to square */ const Word16 mdctSpec_e, /**< in: | exponent of mdctSpectrum */ - Word32 *mdctSquareSpec, /**< out:Q31 | MDCT square spectrum */ + Word32 *mdctSquareSpec, /**< out: | MDCT square spectrum */ Word16 *mdctSquareSpec_e, /**< out: | exponent of mdctSquareSpec */ Word16 indexOffset /**< in: Q0 | index offset */ ) @@ -1235,8 +1237,8 @@ void IGFCommonFuncsMDCTSquareSpec_ivas( const Word16 sqrtBgn, /**< in FOR( i = sqrtBgn; i < sqrtEnd; i++ ) { - tmp = extract_h( L_shl( mdctSpec[i], s1 ) ); - mdctSquareSpec[j++] = L_mult0( tmp, tmp ); + tmp = extract_h( L_shl( mdctSpec[i], s1 ) ); /*(15 - mdctSpec_e)+ S1*/ + mdctSquareSpec[j++] = L_mult0( tmp, tmp ); /*31 - mdctSquareSpec_e*/ move32(); } } @@ -1284,7 +1286,7 @@ Word16 IGFCommonFuncsIGFConfiguration( move16(); /* interface call for reading in settings */ - hIGFInfo->bitRateIndex = IGF_MapBitRateToIndex( total_brate, bwidth, element_mode, rf_mode ); + hIGFInfo->bitRateIndex = IGF_MapBitRateToIndex( total_brate, bwidth, element_mode, rf_mode ); /*Q0*/ move16(); IF( NE_16( hIGFInfo->bitRateIndex, IGF_BITRATE_UNKNOWN ) ) @@ -1293,21 +1295,21 @@ Word16 IGFCommonFuncsIGFConfiguration( move16(); /* mapping to local values */ - sampleRate = igfMode[hIGFInfo->bitRateIndex].sampleRate; + sampleRate = igfMode[hIGFInfo->bitRateIndex].sampleRate; /*Q0*/ move32(); - frameLength = igfMode[hIGFInfo->bitRateIndex].frameLength; + frameLength = igfMode[hIGFInfo->bitRateIndex].frameLength; /*Q0*/ move16(); - igfMinFq = igfMode[hIGFInfo->bitRateIndex].igfMinFq; + igfMinFq = igfMode[hIGFInfo->bitRateIndex].igfMinFq; /*Q0*/ move16(); - maxHopsize = igfMode[hIGFInfo->bitRateIndex].maxHopsize; + maxHopsize = igfMode[hIGFInfo->bitRateIndex].maxHopsize; /*Q0*/ move16(); /* basic information */ - hIGFInfo->sampleRate = sampleRate; + hIGFInfo->sampleRate = sampleRate; /*Q0*/ move32(); - hIGFInfo->frameLength = frameLength; + hIGFInfo->frameLength = frameLength; /*Q0*/ move16(); - hIGFInfo->maxHopsize = maxHopsize; + hIGFInfo->maxHopsize = maxHopsize; /*Q0*/ move16(); hIGFInfo->nfSeedBuf[0] = 0; @@ -1366,7 +1368,7 @@ Word16 IGFCommonFuncsIGFConfiguration_ivas_fx( move16(); /* interface call for reading in settings */ - hIGFInfo->bitRateIndex = IGF_MapBitRateToIndex( total_brate, bwidth, element_mode, rf_mode ); + hIGFInfo->bitRateIndex = IGF_MapBitRateToIndex( total_brate, bwidth, element_mode, rf_mode ); /*Q0*/ IF( NE_16( hIGFInfo->bitRateIndex, IGF_BITRATE_UNKNOWN ) ) { @@ -1374,21 +1376,21 @@ Word16 IGFCommonFuncsIGFConfiguration_ivas_fx( move16(); /* mapping to local values */ - sampleRate = igfMode[hIGFInfo->bitRateIndex].sampleRate; + sampleRate = igfMode[hIGFInfo->bitRateIndex].sampleRate; /*Q0*/ move32(); - frameLength = igfMode[hIGFInfo->bitRateIndex].frameLength; + frameLength = igfMode[hIGFInfo->bitRateIndex].frameLength; /*Q0*/ move16(); - igfMinFq = igfMode[hIGFInfo->bitRateIndex].igfMinFq; + igfMinFq = igfMode[hIGFInfo->bitRateIndex].igfMinFq; /*Q0*/ move16(); - maxHopsize = igfMode[hIGFInfo->bitRateIndex].maxHopsize; + maxHopsize = igfMode[hIGFInfo->bitRateIndex].maxHopsize; /*Q0*/ move16(); /* basic information */ - hIGFInfo->sampleRate = sampleRate; + hIGFInfo->sampleRate = sampleRate; /*Q0*/ move32(); - hIGFInfo->frameLength = frameLength; + hIGFInfo->frameLength = frameLength; /*Q0*/ move16(); - hIGFInfo->maxHopsize = maxHopsize; + hIGFInfo->maxHopsize = maxHopsize; /*Q0*/ move16(); hIGFInfo->nfSeedBuf[0] = 0; move16(); @@ -1423,7 +1425,7 @@ Word16 IGFCommonFuncsIGFConfiguration_ivas_fx( igfMinFq ); } - return retValue; + return retValue; /*Q0*/ } #endif // IVAS_FLOAT_FIXED diff --git a/lib_com/index_pvq_opt_fx.c b/lib_com/index_pvq_opt_fx.c index 650b3b764..e2d2690ce 100644 --- a/lib_com/index_pvq_opt_fx.c +++ b/lib_com/index_pvq_opt_fx.c @@ -32,16 +32,16 @@ typedef void ( *NDIM_FUNCM )( Word16, Word16, UWord32, Word16 * ); * find 1/(den1*2+1) * ( num1p*num2p - num3) , * if the result is known a priori to be exactly a 32bit UWord32 *-------------------------------------------------------------------*/ -static UWord32 f_odd_exact_div_opt_fx( /* o : see Eq. */ +static UWord32 f_odd_exact_div_opt_fx( /* o Q0 : see Eq. */ UWord32 num1p, - /* i : see Eq. */ /* (2n-1) or n , i.e can be short also */ - UWord32 num2p, /* i : see Eq. */ - UWord32 num3, /* i : see Eq. */ - Word16 den1 /* i : see Eq. */ /*range [0..127] can be made to short */ + /* i : see Eq. */ /* (2n-1) or n , i.e can be short also */ + UWord32 num2p, /* i : see Eq. */ + UWord32 num3, /* i : see Eq. */ + Word16 den1 /* Q0 i : see Eq. */ /*range [0..127] can be made to short */ ) { UWord32 UL_tmp; - UL_tmp = UL_Mpy_32_32( exactdivodd[den1], UL_subNsD( UL_Mpy_32_32( num1p, num2p ), num3 ) ); + UL_tmp = UL_Mpy_32_32( exactdivodd[den1], UL_subNsD( UL_Mpy_32_32( num1p, num2p ), num3 ) ); /*Q0*/ return ( UL_tmp ); } @@ -52,7 +52,7 @@ static UWord32 f_odd_exact_div_opt_fx( /* o : see Eq. */ * returns (num1p*num2p - num3 )/ den1 * if the result is known a priori to be exactly a 32bit unsigned integer *--------------------------------------------------------------------------*/ -static UWord32 f_even_exact_div_opt_fx( /* o : see Eq. */ +static UWord32 f_even_exact_div_opt_fx( /* o Q0 : see Eq. */ UWord32 UL_num1p, /* i : see Eq. 2n-1 or n can be short input */ UWord32 UL_num2p, /* i : see Eq. range should be larger than num1p */ UWord32 UL_num3, /* i : see Eq. */ @@ -82,7 +82,7 @@ static UWord32 f_even_exact_div_opt_fx( /* o : see Eq. /* total cost 9-11 , old solution had 15-16*/ /* now use tabled modular multiplicative inverse for the odd part division */ - return UL_Mpy_32_32( UL_tmp, UL_oddfactor ); + return UL_Mpy_32_32( UL_tmp, UL_oddfactor ); /*Q0*/ } /* direct calculation functions for smaller dimensions to speed up indexing @@ -122,14 +122,14 @@ U(n,k) = 1 + A(n-1,k-1)>>1 + A(n-1,k)>>1 + A(n,k-1)>>1; A(n,k) is always odd /*-------------------------------------------------------------------* * a_three_fx() *-------------------------------------------------------------------*/ -static UWord32 a_three_fx( /* o: offset for dim 3 */ - UWord32 k_val /* i: nb unit pulses */ +static UWord32 a_three_fx( /* Q0 o: offset for dim 3 */ + UWord32 k_val /* Q0 i: nb unit pulses */ ) /* k_val may be higher than 16 bit signed */ { IF( k_val ) { /* return (ONE_U + k_val*((k_val - ONE_U) << ONE)); */ - return UL_addNsD( 1U, UL_Mpy_32_32( k_val, UL_lshl( UL_subNsD( k_val, 1U ), 1 ) ) ); + return UL_addNsD( 1U, UL_Mpy_32_32( k_val, UL_lshl( UL_subNsD( k_val, 1U ), 1 ) ) ); /*Q0*/ } ELSE { @@ -140,8 +140,8 @@ static UWord32 a_three_fx( /* o: offset for dim 3 */ /*-------------------------------------------------------------------* * a_four_fx() *-------------------------------------------------------------------*/ -static UWord32 a_four_fx( /* o: offset for dim 4 */ - UWord32 k_val /* i: nb unit pulses */ +static UWord32 a_four_fx( /* Q0 o: offset for dim 4 */ + UWord32 k_val /* Q0 i: nb unit pulses */ ) { UWord32 UL_2k; @@ -150,7 +150,7 @@ static UWord32 a_four_fx( /* o: offset for dim 4 */ /* return UDIVBY3*((k_val<0 */ @@ -361,7 +362,7 @@ static void a_u_fwd_fx( UWord32 *a_u_in, /* Note, A(n,k) always odd for k>0 , subtracted one always shifted out */ u_kp1 = UL_lshr( a_u_in[k_val_in], 1 ); - a_u_in[mem_size_m1] = UL_addNsD( 1U, UL_addNsD( u_kp1_prev, UL_addNsD( u_k_prev, u_kp1 ) ) ); + a_u_in[mem_size_m1] = UL_addNsD( 1U, UL_addNsD( u_kp1_prev, UL_addNsD( u_k_prev, u_kp1 ) ) ); /*Q0*/ move32(); return; } @@ -371,10 +372,10 @@ static void a_u_fwd_fx( UWord32 *a_u_in, * * find and return N_MPVQ(n,k) and also offsets A(n, 0 to k ) and U(n,k+1). *-------------------------------------------------------------------*/ -static UWord32 nm_h_prep_opt_fx( /* o: msize for dim */ +static UWord32 nm_h_prep_opt_fx( /* o: Q0 msize for dim */ Word16 dim_in, /* i: dimension */ Word16 k_val_in, /* i: nb unit pulses */ - UWord32 *h /* o: A/U offsets array */ + UWord32 *h /* o: Q0 A/U offsets array */ ) { Word16 mem_size_m1, k_val, tmp; @@ -408,13 +409,13 @@ static UWord32 nm_h_prep_opt_fx( /* o: msize for dim */ } a_k = h[k_val_in]; move32(); - u_kp1 = h[mem_size_m1]; + u_kp1 = h[mem_size_m1]; /*Q0*/ move32(); } ELSE { - numDsub1 = UL_deposit_l( sub( shl( dim_in, 1 ), 1 ) ); - h[2] = numDsub1; + numDsub1 = UL_deposit_l( sub( shl( dim_in, 1 ), 1 ) ); /*Q0*/ + h[2] = numDsub1; /*Q0*/ move32(); /* interleaved " odd, even [odd]" divisor calls */ @@ -436,7 +437,7 @@ static UWord32 nm_h_prep_opt_fx( /* o: msize for dim */ IF( tmp > 0 ) { /* k_val_in = 3,4, 5,6, 7 ... */ - end_loop = mem_size_m1; + end_loop = mem_size_m1; /*Q0*/ move16(); add_last_odd = s_and( k_val_in, 0x1 ); move16(); /* odd -> 0x00100*/ @@ -450,15 +451,15 @@ static UWord32 nm_h_prep_opt_fx( /* o: msize for dim */ /* the optimized non broken loop k=(3,4)(5,6)...(odd,even)*/ /* A(n,k) = A(n,k-2) + ((2*n-1)*A(n,k-1)-A(n,k-2)) /(k-1) */ /* first odd k, even divisor */ - h_saveB = UL_addNsD( h_saveB, f_even_exact_div_opt_fx( numDsub1, h_saveA, h_saveB, sub( k_val, 1 ) ) ); - h[k_val] = h_saveB; + h_saveB = UL_addNsD( h_saveB, f_even_exact_div_opt_fx( numDsub1, h_saveA, h_saveB, sub( k_val, 1 ) ) ); /*Q0*/ + h[k_val] = h_saveB; /*Q0*/ move32(); /* next even k, odd divisor */ /*k_val++; */ - h_saveA = UL_addNsD( h_saveA, f_odd_exact_div_opt_fx( numDsub1, h_saveB, h_saveA, shr( k_val, 1 ) ) ); - k_val++; /* ptr incr */ - h[k_val] = h_saveA; + h_saveA = UL_addNsD( h_saveA, f_odd_exact_div_opt_fx( numDsub1, h_saveB, h_saveA, shr( k_val, 1 ) ) ); /*Q0*/ + k_val++; /* ptr incr */ + h[k_val] = h_saveA; /*Q0*/ move32(); } } @@ -474,13 +475,13 @@ static UWord32 nm_h_prep_opt_fx( /* o: msize for dim */ /* always do the last (k+1) recursion based on U(n,k+1) = func( A(n-2,k+1), A(n-1,k+1) ) */ a_k = h[k_val_in]; move32(); - u_kp1 = direct_row_A2U_rec_calc_fx( dim_in, mem_size_m1, h[sub( mem_size_m1, 2 )], a_k ); - h[mem_size_m1] = u_kp1; + u_kp1 = direct_row_A2U_rec_calc_fx( dim_in, mem_size_m1, h[mem_size_m1 - 2], a_k ); /*Q0*/ + h[mem_size_m1] = u_kp1; /*Q0*/ move32(); } /* N_MPVQ(n,k) = 1 + U(n,k+1) + U(n,k) = 1 + U(n,k+1) + floor(A(n,k))/2) ; */ /* as A(n,k) always odd */ - return ( UL_addNsD( 1U, UL_addNsD( u_kp1, UL_lshr( a_k, 1 ) ) ) ); + return ( UL_addNsD( 1U, UL_addNsD( u_kp1, UL_lshr( a_k, 1 ) ) ) ); /*Q0*/ } /* @@ -488,11 +489,11 @@ static UWord32 nm_h_prep_opt_fx( /* o: msize for dim */ find first offset in range 0..k_val_in that is less than ind_in using a tree search with direct function calls [ or memory iteration] */ -static Word16 find_amp_split_offset_func_mem_fx( /* o: found k_value */ +static Word16 find_amp_split_offset_func_mem_fx( /* o: Q0 found k_value */ UWord32 ind_in, Word16 high, /* i: k_val_in (high bound) */ H_FUNCM h_func_ptr, /* i: offset function pointer */ - UWord32 *UL_tmp_offset ) /* o: offset found */ + UWord32 *UL_tmp_offset ) /* o: Q0 offset found */ { Word16 not_ready, low, k_test = 0; move16(); @@ -512,7 +513,7 @@ static Word16 find_amp_split_offset_func_mem_fx( /* o: found k_value */ *UL_tmp_offset = ( *h_func_ptr )( UL_deposit_l( k_test ) ); /* call direct A offset-function */ move32(); - UL_tmp = UL_subNs( *UL_tmp_offset, ind_in, &sgn ); + UL_tmp = UL_subNs( *UL_tmp_offset, ind_in, &sgn ); /*Q0*/ IF( sgn ) { /* (*tmp_offset < ind_in) */ @@ -535,7 +536,7 @@ static Word16 find_amp_split_offset_func_mem_fx( /* o: found k_value */ } } } - return k_test; + return k_test; /*Q0*/ } /* @@ -554,10 +555,10 @@ static Word16 get_lead_sign_fx( UWord32 *ind ) leading_sign = -1; move16(); } - ( *ind ) = UL_lshr( *ind, 1 ); + ( *ind ) = UL_lshr( *ind, 1 ); /*Q0*/ move32(); - return leading_sign; + return leading_sign; /*Q0*/ } /*-------------------------------------------------------------------* @@ -589,7 +590,7 @@ static void mind2vec_two_fx( Word16 k_val_in, /* i: nb unit pulses */ Word16 leading_sign, /* i: leading sign -1,0, 1 */ UWord32 ind_in, /* i: index */ - Word16 *vec_out /* o: pulse train */ + Word16 *vec_out /* o: Q0 pulse train */ ) { UWord32 UL_ind_tmp; @@ -609,7 +610,7 @@ static void mind2vec_two_fx( ELSE { UL_ind_tmp = UL_subNsD( ind_in, 1U ); - val1 = (Word16) u_extract_l( UL_addNsD( 1U, UL_lshr( UL_ind_tmp, 1 ) ) ); /*(Word16) to avoid warning */ + val1 = (Word16) u_extract_l( UL_addNsD( 1U, UL_lshr( UL_ind_tmp, 1 ) ) ); /*(Word16) to avoid warning */ /*Q0*/ mind2vec_one_fx( sub( k_val_in, val1 ), leading_sign, ind_in, vec_out ); @@ -617,7 +618,7 @@ static void mind2vec_two_fx( { val1 = negate( val1 ); /*single basicop */ } - vec_out[1] = val1; + vec_out[1] = val1; /*Q0*/ move16(); } } @@ -631,11 +632,11 @@ static Word16 setval_update_sign_fx( Word16 k_delta, IF( k_delta != 0 ) { mind2vec_one_fx( k_delta, *leading_sign, *ind_in, vec_out ); - *leading_sign = get_lead_sign_fx( ind_in ); + *leading_sign = get_lead_sign_fx( ind_in ); /*Q0*/ move16(); - k_max_local = sub( k_max_local, k_delta ); + k_max_local = sub( k_max_local, k_delta ); /*Q0*/ } - return k_max_local; + return k_max_local; /*Q0*/ } /*-------------------------------------------------------------------* @@ -645,7 +646,7 @@ static void mind2vec_three_fx( Word16 k_max_local, /* i: nb unit pulses */ Word16 leading_sign, /* i: leading sign */ UWord32 ind_in, /* i: index */ - Word16 *vec_out /* o: pulse train */ + Word16 *vec_out /* Q0 o: pulse train */ ) { /* @@ -658,9 +659,9 @@ static void mind2vec_three_fx( IF( ind_in != 0 ) { /* acc_val=idivide(uint32(floor(real(sqrt(double(ind)*2-1))))+1, 2); % (exact_integer_sqrt((ind*2-1) +1)*2 */ - acc_val = lshr( add( 1, getSqrtWord32( UL_subNsD( UL_lshl( ind_in, 1 ), 1U ) ) ), 1 ); - k_delta = sub( k_max_local, acc_val ); - ind_in = UL_subNsD( ind_in, a_three_fx( UL_deposit_l( acc_val ) ) ); /* remove amplitude offset A(3,k_acc) */ + acc_val = lshr( add( 1, getSqrtWord32( UL_subNsD( UL_lshl( ind_in, 1 ), 1U ) ) ), 1 ); /*Q0*/ + k_delta = sub( k_max_local, acc_val ); /*Q0*/ + ind_in = UL_subNsD( ind_in, a_three_fx( UL_deposit_l( acc_val ) ) ); /* remove amplitude offset A(3,k_acc) */ k_max_local = setval_update_sign_fx( k_delta, k_max_local, &leading_sign, &ind_in, vec_out ); @@ -685,7 +686,7 @@ static void mind2vec_direct_fx( UWord32 ind, /* i: index */ H_FUNCM h_func_ptr, /* i : offset function */ NDIM_FUNCM nd_func_ptr, /* i : next dimension function */ - Word16 *vec_out /* o: pulse train */ + Word16 *vec_out /* Q0 o: pulse train */ ) { @@ -717,7 +718,7 @@ static void mind2vec_four_fx( Word16 k_val_in, /* i: nb unit pulses */ Word16 leading_sign, /* i: leading sign */ UWord32 ind_in, /* i: index */ - Word16 *vec_out /* o: pulse train */ + Word16 *vec_out /* Q0 o: pulse train */ ) { mind2vec_direct_fx( k_val_in, leading_sign, ind_in, a_four_fx, mind2vec_three_fx, vec_out ); @@ -746,7 +747,7 @@ static void mind2vec_fx( Word16 k_max_local, /* i: nb unit pulses */ Word16 leading_sign, /* i: leading sign */ UWord32 ind, /* i: index */ - Word16 *vec_out, /* o: pulse train */ + Word16 *vec_out, /* Q0 o: pulse train */ UWord32 *h_in /* i: offset vector A=1+2U */ ) { @@ -785,7 +786,7 @@ static void mind2vec_fx( BREAK; /* "fast" recursion exit*/ } - k_max_local = setval_update_sign_fx( k_delta, k_max_local, &leading_sign, &ind, &vec_out[pos] ); + k_max_local = setval_update_sign_fx( k_delta, k_max_local, &leading_sign, &ind, &vec_out[pos] ); /*Q0*/ /* move from A(n,kmax) to A(n-1, k_max_local), */ a_bwd_fx( h_in, add( k_max_local, 1 ) ); /* [0 ... k_max_local], no need to update U(n,k_max_local+1) in index decoding */ @@ -803,7 +804,7 @@ static void mind2vec_fx( PvqEntry get_size_mpvq_calc_offset_fx( /* o : size, dim, k_val */ Word16 dim_in, /* i : dimension */ Word16 k_val_in, /* i : nb unit pulses */ - UWord32 *h_mem /* o : offsets */ + UWord32 *h_mem /* Q0 o : offsets */ ) { PvqEntry entry; @@ -819,16 +820,16 @@ PvqEntry get_size_mpvq_calc_offset_fx( /* o : size, dim, k_val IF( GT_16( dim_in, N_OPT_FX ) ) /* non-direct solutions, use A+U relation */ { - entry.size = nm_h_prep_opt_fx( entry.dim, entry.k_val, h_mem ); + entry.size = nm_h_prep_opt_fx( entry.dim, entry.k_val, h_mem ); /*Q0*/ move32(); } ELSE { - entry.size = direct_msize_fx( dim_in, entry.k_val ); + entry.size = direct_msize_fx( dim_in, entry.k_val ); /*Q0*/ move32(); } - return entry; + return entry; /*Q0*/ } /*-------------------------------------------------------------------* @@ -837,7 +838,7 @@ PvqEntry get_size_mpvq_calc_offset_fx( /* o : size, dim, k_val void mpvq_decode_vec_fx( /* o : void */ const PvqEntry *entry, /* i : sign_ind, index, dim, k_val */ UWord32 *h_mem, /* i : A/U offsets */ - Word16 *vec_out /* o : pulse train */ + Word16 *vec_out /* Q0 o : pulse train */ ) { Word16 i, leading_sign; @@ -880,9 +881,9 @@ void mpvq_decode_vec_fx( /* o : void static void vec2mind_one_fx( const Word16 *vec_in, /* i : PVQ pulse train */ Word16 *k_val_out_ptr, - /* o : number of unit pulses */ /* parameter needed as it is used in a function array */ - UWord32 *next_sign_ind, /* i/o: next sign ind */ - UWord32 *ind /* o: MPVQ index */ + /* Q0 o : number of unit pulses */ /* parameter needed as it is used in a function array */ + UWord32 *next_sign_ind, /* i/o: next sign ind */ + UWord32 *ind /* Q0 o: MPVQ index */ ) { *ind = (Word32) ( *k_val_out_ptr ); /* dummy assignment to avoid gcc "unused parameter" warning for *k_val_out_ptr, i.e no move32 needed() */ @@ -894,7 +895,7 @@ static void vec2mind_one_fx( move32(); if ( *vec_in < 0 ) { - *next_sign_ind = UL_deposit_l( 1 ); /*single basicop */ + *next_sign_ind = UL_deposit_l( 1 ); /*single basicop */ /*Q0*/ move32(); } return; @@ -905,9 +906,9 @@ static void vec2mind_one_fx( *-------------------------------------------------------------------*/ static void vec2mind_two_fx( const Word16 *vec_in, /* i : PVQ pulse train */ - Word16 *k_val_out_ptr, /* o : number of unit pulses */ - UWord32 *next_sign_ind, /* i/o: next sign ind */ - UWord32 *ind /* o: MPVQ index */ + Word16 *k_val_out_ptr, /* Q0 o : number of unit pulses */ + UWord32 *next_sign_ind, /* Q0 i/o: next sign ind */ + UWord32 *ind /* Q0 o: MPVQ index */ ) { UWord32 lead_sign_ind_add; @@ -928,8 +929,8 @@ static void vec2mind_two_fx( IF( abs01 != 0 ) { sptr = 0; - move16(); /*used as ptr to vec0 or vec1 value */ - *next_sign_ind = UL_deposit_l( sptr ); + move16(); /*used as ptr to vec0 or vec1 value */ + *next_sign_ind = UL_deposit_l( sptr ); /*Q0*/ move32(); test(); @@ -943,7 +944,7 @@ static void vec2mind_two_fx( { lead_sign_ind_add = UL_deposit_l( 2 ); /* single op */ } - *ind = UL_addNsD( UL_deposit_l( (UWord16) lshl( sub( abs1, 1 ), 1 ) ), lead_sign_ind_add ); + *ind = UL_addNsD( UL_deposit_l( (UWord16) lshl( sub( abs1, 1 ), 1 ) ), lead_sign_ind_add ); /*Q0*/ move32(); } ELSE @@ -952,7 +953,7 @@ static void vec2mind_two_fx( IF( abs0 == 0 ) { /* [ 0 KMAX]*/ - *ind = UL_deposit_l( (UWord16) sub( lshl( abs1, 1 ), 1 ) ); + *ind = UL_deposit_l( (UWord16) sub( lshl( abs1, 1 ), 1 ) ); /*Q0*/ move32(); sptr = 1; move16(); @@ -962,7 +963,7 @@ static void vec2mind_two_fx( /* *next_sign_ind= (unsigned int)(vec_in[*next_sign_ind]<0); */ if ( vec_in[sptr] < 0 ) { - *next_sign_ind = UL_deposit_l( 1 ); /*single instruction */ + *next_sign_ind = UL_deposit_l( 1 ); /*single instruction */ /*Q0*/ move32(); } } @@ -1004,9 +1005,9 @@ static void enc_push_sign( Word16 val, UWord32 *next_sign_ind, UWord32 *index ) static void vec2mind_gen345_fx( const Word16 *vec_in, /* i : PVQ abs pulse train */ - Word16 *k_val_out_ptr, /* o : number of unit pulses */ + Word16 *k_val_out_ptr, /* Q0 o : number of unit pulses */ UWord32 *next_sign_ind, /* i/o: next sign ind */ - UWord32 *index, /* o: MPVQ index */ + UWord32 *index, /* Q0 o: MPVQ index */ VEC2INDFUNCM vec2indfunc_ptr, /* i: */ H_FUNCM a_func_ptr /*i: offset function */ ) @@ -1020,11 +1021,11 @@ static void vec2mind_gen345_fx( enc_push_sign( tmp_val, next_sign_ind, index ); - move32(); /* adaptive function call setup */ - *index = UL_addNsD( *index, ( *a_func_ptr )( UL_deposit_l( *k_val_out_ptr ) ) ); + move32(); /* adaptive function call setup */ + *index = UL_addNsD( *index, ( *a_func_ptr )( UL_deposit_l( *k_val_out_ptr ) ) ); /*Q0*/ move32(); - *k_val_out_ptr = add( *k_val_out_ptr, abs_s( tmp_val ) ); + *k_val_out_ptr = add( *k_val_out_ptr, abs_s( tmp_val ) ); /*Q0*/ move16(); return; @@ -1035,9 +1036,9 @@ static void vec2mind_gen345_fx( *-------------------------------------------------------------------*/ static void vec2mind_three_fx( const Word16 *vec_in, /* i : PVQ pulse train */ - Word16 *k_val_out_ptr, /* o : number of unit pulses */ - UWord32 *next_sign_ind, /* i/o: next sign ind */ - UWord32 *index /* o: MPVQ index */ + Word16 *k_val_out_ptr, /* Q0 o : number of unit pulses */ + UWord32 *next_sign_ind, /* Q0 i/o: next sign ind */ + UWord32 *index /* Q0 o: MPVQ index */ ) { vec2mind_gen345_fx( vec_in, k_val_out_ptr, next_sign_ind, index, vec2mind_two_fx, a_three_fx ); @@ -1050,9 +1051,9 @@ static void vec2mind_three_fx( *-------------------------------------------------------------------*/ static void vec2mind_four_fx( const Word16 *vec_in, /* i : PVQ pulse train */ - Word16 *k_val_out_ptr, /* o : number of unit pulses */ - UWord32 *next_sign_ind, /* i/o: next sign ind */ - UWord32 *index /* o: MPVQ index */ + Word16 *k_val_out_ptr, /* Q0 o : number of unit pulses */ + UWord32 *next_sign_ind, /* Q0 i/o: next sign ind */ + UWord32 *index /* Q0 o: MPVQ index */ ) { vec2mind_gen345_fx( vec_in, k_val_out_ptr, next_sign_ind, index, vec2mind_three_fx, a_four_fx ); @@ -1064,9 +1065,9 @@ static void vec2mind_four_fx( *-------------------------------------------------------------------*/ static void vec2mind_five_fx( const Word16 *vec_in, /* i : PVQ abs pulse train */ - Word16 *k_val_out_ptr, /* o : number of unit pulses */ - UWord32 *next_sign_ind, /* i/o: next sign ind */ - UWord32 *index /* o: MPVQ index */ + Word16 *k_val_out_ptr, /* Q0 o : number of unit pulses */ + UWord32 *next_sign_ind, /* Q0 i/o: next sign ind */ + UWord32 *index /* Q0 o: MPVQ index */ ) { vec2mind_gen345_fx( vec_in, k_val_out_ptr, next_sign_ind, index, vec2mind_four_fx, a_five_fx ); @@ -1079,10 +1080,10 @@ static void vec2mind_five_fx( static void vec2mind_fx( Word16 dim_in, /* i : dim */ Word16 k_val_in, /* i : number of unit pulses */ const Word16 *vec_in, /* i : PVQ pulse train */ - UWord32 *next_sign_ind, /* o : pushed leading sign */ - UWord32 *index, /* o : MPVQ index */ - UWord32 *N_MPVQ_ptr, /* o : size(N_MPVQ(dim,K_val_in))*/ - UWord32 *h_mem ) /* o : offsets */ + UWord32 *next_sign_ind, /* Q0 o : pushed leading sign */ + UWord32 *index, /* Q0 o : MPVQ index */ + UWord32 *N_MPVQ_ptr, /* Q0 o : size(N_MPVQ(dim,K_val_in))*/ + UWord32 *h_mem ) /* Q0 o : offsets */ { Word16 pos, mem_size_m1, k_val_acc, tmp_val; UWord32 tmp_h; @@ -1101,10 +1102,10 @@ static void vec2mind_fx( Word16 dim_in, /* i : dim */ mem_size_m1 = add( k_val_in, 1 ); - *next_sign_ind = UL_deposit_h( SIGNBIT_SHRT_FX ); /* highest bit set signals no sign found yet, should always be 0 or 1 out, */ + *next_sign_ind = UL_deposit_h( SIGNBIT_SHRT_FX ); /* highest bit set signals no sign found yet, should always be 0 or 1 out, */ /*Q0*/ move32(); - pos = sub( dim_in, 2 ); /* adress 2nd last sample */ + pos = sub( dim_in, 2 ); /* adress 2nd last sample */ /*Q0*/ vec2mind_two_fx( &vec_in[pos], &k_val_acc, next_sign_ind, index ); initOffsets_fx( 3, h_mem, k_val_in ); /* start recursions at 3rd sample */ @@ -1117,11 +1118,11 @@ static void vec2mind_fx( Word16 dim_in, /* i : dim enc_push_sign( tmp_val, next_sign_ind, index ); /* now add indexing offset up to this reverse (r_l) accumulated amplitude point */ - *index = UL_addNsD( *index, tmp_h ); /* k_val_acc==0 ==>0 */ + *index = UL_addNsD( *index, tmp_h ); /* k_val_acc==0 ==>0 */ /*Q0*/ move32(); - /* k_val_acc = k_val_acc + vec_abs[pos];*/ /* now increase acc k value for next N */ - k_val_acc = add( k_val_acc, abs_s( tmp_val ) ); + /* k_val_acc = k_val_acc + vec_abs[pos];*/ /* now increase acc k value for next N */ + k_val_acc = add( k_val_acc, abs_s( tmp_val ) ); /*Q0*/ IF( pos != 0 ) { @@ -1129,14 +1130,14 @@ static void vec2mind_fx( Word16 dim_in, /* i : dim /* update A(n,k=1:k_val_in) and U(n,k_val_in+1) */ /* NB here (k_val_in + 2 elements always has to be updated */ } - tmp_h = UL_addNsD( h_mem[k_val_acc], 0U ); + tmp_h = UL_addNsD( h_mem[k_val_acc], 0U ); /*Q0*/ } /* size is needed for the subseqent arithmetic encoding/transmission of the index. use relation N_MPVQ(n,K) = 1 + (A(n, K)-1)/2 + U(n, 1 + K) = N_MPVQ(n,K) = 1 + (A(n, K)>>1) + U(n, 1 + K) , as A(n,K) is odd) */ - *N_MPVQ_ptr = UL_addNsD( 1U, UL_addNsD( UL_lshr( tmp_h, 1 ), h_mem[mem_size_m1] ) ); - move32(); /* calc total size */ + *N_MPVQ_ptr = UL_addNsD( 1U, UL_addNsD( UL_lshr( tmp_h, 1 ), h_mem[mem_size_m1] ) ); /*Q0*/ + move32(); /* calc total size */ return; } @@ -1147,7 +1148,7 @@ static void vec2mind_fx( Word16 dim_in, /* i : dim * returns struct with lead sign index, MPVQ-index, dim and N_MPVQ size *-------------------------------------------------------------------------*/ -PvqEntry mpvq_encode_vec_fx( /* o : leading_sign_index, index, size, k_val */ +PvqEntry mpvq_encode_vec_fx( /* Q0 o : leading_sign_index, index, size, k_val */ const Word16 *vec_in, /* i : signed pulse train */ Word16 dim_in, /* i : dimension */ Word16 k_val_local /* i : nb unit pulses */ @@ -1160,9 +1161,9 @@ PvqEntry mpvq_encode_vec_fx( /* o : leading_sign_index, in VEC2INDFUNCM vec2mind_f[1 + N_OPT_FX] = { (VEC2INDFUNCM) NULL, vec2mind_one_fx, vec2mind_two_fx, vec2mind_three_fx, vec2mind_four_fx, vec2mind_five_fx }; - result.k_val = k_val_local; + result.k_val = k_val_local; /*Q0*/ move16(); - result.dim = dim_in; + result.dim = dim_in; /*Q0*/ move16(); /* NB , k_val_local may be changed in some sub encoding routines */ IF( GT_16( dim_in, N_OPT_FX ) ) @@ -1174,9 +1175,9 @@ PvqEntry mpvq_encode_vec_fx( /* o : leading_sign_index, in { move32(); /* adaptive function ptr setup */ ( vec2mind_f[dim_in] )( vec_in, &k_val_local, &lead_sign_ind, &result.index ); - result.size = direct_msize_fx( dim_in, k_val_local ); + result.size = direct_msize_fx( dim_in, k_val_local ); /*Q0*/ } - result.lead_sign_ind = u_extract_l( lead_sign_ind ); + result.lead_sign_ind = u_extract_l( lead_sign_ind ); /*Q0*/ move16(); return result; diff --git a/lib_com/int_lsp.c b/lib_com/int_lsp.c index 522f62fe0..0adb332fa 100644 --- a/lib_com/int_lsp.c +++ b/lib_com/int_lsp.c @@ -98,12 +98,12 @@ void int_lsp( void int_lsp_fx( const Word16 L_frame, /* i : length of the frame */ - const Word16 lsp_old[], /* i : LSPs from past frame */ - const Word16 lsp_new[], /* i : LSPs from present frame */ - Word16 *Aq, /* o : LP coefficients in both subframes */ + const Word16 lsp_old[], /* i : Q15 LSPs from past frame */ + const Word16 lsp_new[], /* i : Q15 LSPs from present frame */ + Word16 *Aq, /* o : Q12 LP coefficients in both subframes */ const Word16 m, /* i : order of LP filter */ - const Word16 *int_coeffs, /* i : interpolation coefficients */ - const Word16 Opt_AMR_WB /* i : flag indicating AMR-WB IO mode */ + const Word16 *int_coeffs, /* i : Q15 interpolation coefficients */ + const Word16 Opt_AMR_WB /* i : Q0 flag indicating AMR-WB IO mode */ ) { Word16 lsp[M], fnew, fold; @@ -116,12 +116,12 @@ void int_lsp_fx( IF( EQ_16( L_frame, L_FRAME ) ) { - pt_int_coeffs = int_coeffs; + pt_int_coeffs = int_coeffs; /*Q15*/ move16(); } ELSE /* L_frame == L_FRAME16k */ { - pt_int_coeffs = interpol_frac_16k_fx; + pt_int_coeffs = interpol_frac_16k_fx; /*Q15*/ } FOR( k = 0; k < tmp; k++ ) { @@ -134,13 +134,13 @@ void int_lsp_fx( } FOR( i = 0; i < m; i++ ) { - L_tmp = L_mult( lsp_old[i], fold ); - L_tmp = L_mac( L_tmp, lsp_new[i], fnew ); + L_tmp = L_mult( lsp_old[i], fold ); /*Q31*/ + L_tmp = L_mac( L_tmp, lsp_new[i], fnew ); /*Q31*/ IF( fold == 0 ) { L_tmp = L_mac( L_tmp, lsp_new[i], 1 ); /* 'fnew' should have been 32768 */ } - lsp[i] = round_fx( L_tmp ); + lsp[i] = round_fx( L_tmp ); /*Q15*/ } IF( Opt_AMR_WB ) { @@ -257,38 +257,38 @@ void int_lsp4_fx( { IF( EQ_16( relax_prev_lsf_interp, 1 ) ) { - pt_int_coeffs = interpol_frac_mid_relaxprev_12k8_fx; + pt_int_coeffs = interpol_frac_mid_relaxprev_12k8_fx; /*Q15*/ } ELSE IF( EQ_16( relax_prev_lsf_interp, 2 ) ) { - pt_int_coeffs = interpol_frac_mid_FEC_fx; + pt_int_coeffs = interpol_frac_mid_FEC_fx; /*Q15*/ } ELSE IF( EQ_16( relax_prev_lsf_interp, -1 ) ) { - pt_int_coeffs = interpol_frac_mid_relaxprev_pred_12k8_fx; + pt_int_coeffs = interpol_frac_mid_relaxprev_pred_12k8_fx; /*Q15*/ } ELSE { - pt_int_coeffs = interpol_frac_mid_fx; + pt_int_coeffs = interpol_frac_mid_fx; /*Q15*/ } } ELSE /* L_frame == L_FRAME16k */ { IF( EQ_16( relax_prev_lsf_interp, 1 ) ) { - pt_int_coeffs = interpol_frac_mid_relaxprev_16k_fx; + pt_int_coeffs = interpol_frac_mid_relaxprev_16k_fx; /*Q15*/ } ELSE IF( EQ_16( relax_prev_lsf_interp, 2 ) ) { - pt_int_coeffs = interpol_frac_mid_16k_FEC_fx; + pt_int_coeffs = interpol_frac_mid_16k_FEC_fx; /*Q15*/ } ELSE IF( EQ_16( relax_prev_lsf_interp, -1 ) ) { - pt_int_coeffs = interpol_frac_mid_relaxprev_pred_16k_fx; + pt_int_coeffs = interpol_frac_mid_relaxprev_pred_16k_fx; /*Q15*/ } ELSE { - pt_int_coeffs = interpol_frac_mid_16k_fx; + pt_int_coeffs = interpol_frac_mid_16k_fx; /*Q15*/ } } k = sub( shr( L_frame, 6 ), 1 ); @@ -302,11 +302,9 @@ void int_lsp4_fx( move16(); } pt_int_coeffs += 3; - move16(); E_LPC_f_lsp_a_conversion( lsp, Aq, m ); Aq += add( m, 1 ); - move16(); } /* Last subframe */ @@ -334,42 +332,42 @@ void int_lsp4_ivas_fx( { IF( EQ_16( relax_prev_lsf_interp, 1 ) ) { - pt_int_coeffs = interpol_frac_mid_relaxprev_12k8_fx; + pt_int_coeffs = interpol_frac_mid_relaxprev_12k8_fx; /*Q15*/ } ELSE IF( EQ_16( relax_prev_lsf_interp, 2 ) ) { - pt_int_coeffs = interpol_frac_mid_FEC_fx; + pt_int_coeffs = interpol_frac_mid_FEC_fx; /*Q15*/ } ELSE IF( EQ_16( relax_prev_lsf_interp, -1 ) ) { - pt_int_coeffs = interpol_frac_mid_relaxprev_pred_12k8_fx; + pt_int_coeffs = interpol_frac_mid_relaxprev_pred_12k8_fx; /*Q15*/ } ELSE IF( EQ_16( relax_prev_lsf_interp, -2 ) ) { - pt_int_coeffs = interpol_frac2_mid_fx; + pt_int_coeffs = interpol_frac2_mid_fx; /*Q15*/ } ELSE { - pt_int_coeffs = interpol_frac_mid_fx; + pt_int_coeffs = interpol_frac_mid_fx; /*Q15*/ } } ELSE /* L_frame == L_FRAME16k */ { IF( EQ_16( relax_prev_lsf_interp, 1 ) ) { - pt_int_coeffs = interpol_frac_mid_relaxprev_16k_fx; + pt_int_coeffs = interpol_frac_mid_relaxprev_16k_fx; /*Q15*/ } ELSE IF( EQ_16( relax_prev_lsf_interp, 2 ) ) { - pt_int_coeffs = interpol_frac_mid_16k_FEC_fx; + pt_int_coeffs = interpol_frac_mid_16k_FEC_fx; /*Q15*/ } ELSE IF( EQ_16( relax_prev_lsf_interp, -1 ) ) { - pt_int_coeffs = interpol_frac_mid_relaxprev_pred_16k_fx; + pt_int_coeffs = interpol_frac_mid_relaxprev_pred_16k_fx; /*Q15*/ } ELSE { - pt_int_coeffs = interpol_frac_mid_16k_fx; + pt_int_coeffs = interpol_frac_mid_16k_fx; /*Q15*/ } } k = sub( shr( L_frame, 6 ), 1 ); diff --git a/lib_com/interpol.c b/lib_com/interpol.c index d063baadc..67292ad17 100644 --- a/lib_com/interpol.c +++ b/lib_com/interpol.c @@ -79,7 +79,7 @@ float interpolation( return s; } -Word32 Interpol_lc_fx( /* o : interpolated value Qx+16 */ +Word32 Interpol_lc_fx( /* o : interpolated value Q15 */ const Word16 *x, /* i : input vector Q0 */ const Word16 *win, /* i : interpolation window Q14 */ const Word16 frac, /* i : fraction (0..up_samp) Q0 */ @@ -100,17 +100,17 @@ Word32 Interpol_lc_fx( /* o : interpolated value FOR( i = 0; i < nb_coef; i++ ) { /* Using L_mac0 limits the risk of saturation during the loop, saturation may occures after the loop */ - L_sum64 = W_mac0_16_16( L_sum64, *x, *c1 ); + L_sum64 = W_mac0_16_16( L_sum64, *x, *c1 ); /*Q14*/ --x; - L_sum64 = W_mac0_16_16( L_sum64, *x2, *c2 ); + L_sum64 = W_mac0_16_16( L_sum64, *x2, *c2 ); /*Q14*/ ++x2; c2 += up_samp; /* move16() not needed, since the coefficient can be rearrange in bit exact way */ c1 += up_samp; } - L_sum = W_sat_l( L_sum64 ); + L_sum = W_sat_l( L_sum64 ); /*Q14*/ } #ifdef BASOP_NOGLOB - L_sum = L_shl_sat( L_sum, 1 ); + L_sum = L_shl_sat( L_sum, 1 ); /*Q15*/ #else L_sum = L_shl( L_sum, 1 ); #endif @@ -118,9 +118,9 @@ Word32 Interpol_lc_fx( /* o : interpolated value } -Word16 Interpol_4( /* o : interpolated value */ - Word16 *x, /* i : input vector */ - Word16 frac /* i : fraction (-4..+3) */ +Word16 Interpol_4( /* Qx o : interpolated value */ + Word16 *x, /* Qx i : input vector */ + Word16 frac /* Q0 i : fraction (-4..+3) */ ) { Word16 i; @@ -131,7 +131,7 @@ Word16 Interpol_4( /* o : interpolated value */ x = x - L_INTERPOL1 + 1; - L_sum = L_mult( x[0], ( inter4_1_fx + UP_SAMP - 1 )[-frac] ); + L_sum = L_mult( x[0], ( inter4_1_fx + UP_SAMP - 1 )[-frac] ); /*Qx+14+1*/ FOR( i = 1; i < 2 * L_INTERPOL1; i++ ) { /* @@ -140,19 +140,19 @@ Word16 Interpol_4( /* o : interpolated value */ * so that the values needed are contiguous. */ frac -= UP_SAMP; - L_sum = L_mac( L_sum, x[i], ( inter4_1_fx + UP_SAMP - 1 )[-frac] ); + L_sum = L_mac( L_sum, x[i], ( inter4_1_fx + UP_SAMP - 1 )[-frac] ); /*Qx+14+1*/ } BASOP_SATURATE_WARNING_OFF_EVS /* Here, saturation might occur by intention */ #ifdef BASOP_NOGLOB - L_sum = L_shl_o( L_sum, 1, &Overflow ); -#else /* BASOP_NOGLOB */ + L_sum = L_shl_o( L_sum, 1, &Overflow ); /*Qx+14+2*/ +#else /* BASOP_NOGLOB */ L_sum = L_shl( L_sum, 1 ); -#endif /* BASOP_NOGLOB */ +#endif /* BASOP_NOGLOB */ BASOP_SATURATE_WARNING_ON_EVS #ifdef BASOP_NOGLOB - return round_fx_o( L_sum, &Overflow ); -#else /* BASOP_NOGLOB */ + return round_fx_o( L_sum, &Overflow ); /*Qx*/ +#else /* BASOP_NOGLOB */ return round_fx( L_sum ); #endif } diff --git a/lib_com/isf_dec_amr_wb_fx.c b/lib_com/isf_dec_amr_wb_fx.c index 54ab5c16f..3b98b1346 100644 --- a/lib_com/isf_dec_amr_wb_fx.c +++ b/lib_com/isf_dec_amr_wb_fx.c @@ -48,9 +48,9 @@ void E_LPC_isf_isp_conversion( const Word16 isf[], Word16 isp[], const Word16 m void isf_dec_amr_wb_fx( Decoder_State *st, /* i/o: State structure */ - Word16 *Aq, /* o : quantized A(z) for 4 subframes */ - Word16 *isf_new, /* o : de-quantized ISF vector */ - Word16 *isp_new /* o : de-quantized ISP vector */ + Word16 *Aq, /* Q12 o : quantized A(z) for 4 subframes */ + Word16 *isf_new, /* Qlog2(2.56) o : de-quantized ISF vector */ + Word16 *isp_new /* Q15 o : de-quantized ISP vector */ ) { Word16 i; @@ -135,9 +135,9 @@ void isf_dec_amr_wb_fx( FOR( i = 0; i < M; i++ ) { /*st->lsf_adaptive_mean[i] = (st->lsfoldbfi1[i] + st->lsfoldbfi0[i] + isf_new[i]) / 3;*/ - L_tmp = L_mult( st->lsfoldbfi1_fx[i], 10923 ); - L_tmp = L_mac( L_tmp, st->lsfoldbfi0_fx[i], 10923 ); - st->lsf_adaptive_mean_fx[i] = round_fx( L_mac( L_tmp, isf_new[i], 10923 ) ); + L_tmp = L_mult( st->lsfoldbfi1_fx[i], 10923 /*0.3333 in Q15*/ ); /*Q2.56+15+1*/ + L_tmp = L_mac( L_tmp, st->lsfoldbfi0_fx[i], 10923 /*0.3333 in Q15*/ ); /*Q2.56+15+1*/ + st->lsf_adaptive_mean_fx[i] = round_fx( L_mac( L_tmp, isf_new[i], 10923 /*0.3333 in Q15*/ ) ); /*Q2.56*/ } /*-------------------------------------------------------------------------------------* @@ -161,12 +161,12 @@ void isf_dec_amr_wb_fx( IF( st->element_mode == EVS_MONO ) { - st->stab_fac_fx = lsf_stab_fx( isf_new, st->lsf_old_fx, 1, st->L_frame ); + st->stab_fac_fx = lsf_stab_fx( isf_new, st->lsf_old_fx, 1, st->L_frame ); /*Q15*/ move16(); } ELSE { - st->stab_fac_fx = lsf_stab_ivas_fx( isf_new, st->lsf_old_fx, 1, st->L_frame ); + st->stab_fac_fx = lsf_stab_ivas_fx( isf_new, st->lsf_old_fx, 1, st->L_frame ); /*Q15*/ move16(); } @@ -180,37 +180,37 @@ void isf_dec_amr_wb_fx( *-------------------------------------------------------------------*/ void disf_ns_28b_fx( - Word16 *indice, /* i : quantized indices (use indice[0] = -1 in the decoder) */ - Word16 *isf_q /* o : ISF in the frequency domain (0..6400) */ + Word16 *indice, /* Q0 / i : quantized indices (use indice[0] = -1 in the decoder) */ + Word16 *isf_q /* Q1 / o : ISF in the frequency domain (0..6400) */ ) { Word16 i; FOR( i = 0; i < 2; i++ ) { - isf_q[i] = dico1_ns_28b_fx[indice[0] * 2 + i]; + isf_q[i] = dico1_ns_28b_fx[indice[0] * 2 + i]; /* Q1 */ move16(); } FOR( i = 0; i < 3; i++ ) { - isf_q[i + 2] = dico2_ns_28b_fx[indice[1] * 3 + i]; + isf_q[i + 2] = dico2_ns_28b_fx[indice[1] * 3 + i]; /* Q1 */ move16(); - isf_q[i + 5] = dico3_ns_28b_fx[indice[2] * 3 + i]; + isf_q[i + 5] = dico3_ns_28b_fx[indice[2] * 3 + i]; /* Q1 */ move16(); } FOR( i = 0; i < 4; i++ ) { - isf_q[i + 8] = dico4_ns_28b_fx[indice[3] * 4 + i]; + isf_q[i + 8] = dico4_ns_28b_fx[indice[3] * 4 + i]; /* Q1 */ move16(); - isf_q[i + 12] = dico5_ns_28b_fx[indice[4] * 4 + i]; + isf_q[i + 12] = dico5_ns_28b_fx[indice[4] * 4 + i]; /* Q1 */ move16(); } FOR( i = 0; i < M; i++ ) { - isf_q[i] = add( isf_q[i], mean_isf_noise_amr_wb_fx[i] ); + isf_q[i] = add( isf_q[i], mean_isf_noise_amr_wb_fx[i] ); /* Q1 */ move16(); } @@ -225,9 +225,9 @@ void disf_ns_28b_fx( void disf_2s_46b_fx( Word16 *indice, /* i : quantized indices (use indice[0] = -1 in the decoder) */ - Word16 *isf_q, /* o : quantized ISFs in the cosine domain */ - Word16 *mem_AR, /* o : quantizer memory for AR model */ - Word16 *mem_MA, /* i/o: quantizer memory for MA model */ + Word16 *isf_q, /* (Qx2.56) o : quantized ISFs in the cosine domain */ + Word16 *mem_AR, /* (Qx2.56) o : quantizer memory for AR model */ + Word16 *mem_MA, /* (Qx2.56) i/o: quantizer memory for MA model */ const Word16 enc_dec /* i : encoder (0), decoder (1) G722.2 FER */ ) { @@ -247,42 +247,42 @@ void disf_2s_46b_fx( FOR( i = 0; i < 9; i++ ) { - isf_q[i] = dico1_isf_fx[indice[0] * 9 + i]; + isf_q[i] = dico1_isf_fx[indice[0] * 9 + i]; /*(Qx2.56)*/ move16(); } FOR( i = 0; i < 7; i++ ) { - isf_q[i + 9] = dico2_isf_fx[indice[1] * 7 + i]; + isf_q[i + 9] = dico2_isf_fx[indice[1] * 7 + i]; /*(Qx2.56)*/ move16(); } FOR( i = 0; i < 3; i++ ) { - isf_q[i] = add( isf_q[i], dico21_isf_46b_fx[indice[2] * 3 + i] ); + isf_q[i] = add( isf_q[i], dico21_isf_46b_fx[indice[2] * 3 + i] ); /*(Qx2.56)*/ move16(); - isf_q[i + 3] = add( isf_q[i + 3], dico22_isf_46b_fx[indice[3] * 3 + i] ); + isf_q[i + 3] = add( isf_q[i + 3], dico22_isf_46b_fx[indice[3] * 3 + i] ); /*(Qx2.56)*/ move16(); - isf_q[i + 6] = add( isf_q[i + 6], dico23_isf_46b_fx[indice[4] * 3 + i] ); + isf_q[i + 6] = add( isf_q[i + 6], dico23_isf_46b_fx[indice[4] * 3 + i] ); /*(Qx2.56)*/ move16(); - isf_q[i + 9] = add( isf_q[i + 9], dico24_isf_46b_fx[indice[5] * 3 + i] ); + isf_q[i + 9] = add( isf_q[i + 9], dico24_isf_46b_fx[indice[5] * 3 + i] ); /*(Qx2.56)*/ move16(); } FOR( i = 0; i < 4; i++ ) { - isf_q[i + 12] = add( isf_q[i + 12], dico25_isf_46b_fx[indice[6] * 4 + i] ); + isf_q[i + 12] = add( isf_q[i + 12], dico25_isf_46b_fx[indice[6] * 4 + i] ); /*(Qx2.56)*/ move16(); } FOR( i = 0; i < M; i++ ) { - mem_AR[i] = add( isf_q[i], mult_r( MU_MA_FX, mem_MA[i] ) ); - move16(); /* Update with quantized ISF vector for AR model */ + mem_AR[i] = add( isf_q[i], mult_r( MU_MA_FX, mem_MA[i] ) ); /*(Qx2.56)*/ + move16(); /* Update with quantized ISF vector for AR model */ mem_MA[i] = isf_q[i]; - move16(); /* Update with quantized prediction error for MA model */ - isf_q[i] = add( mem_AR[i], mean_isf_amr_wb_fx[i] ); - move16(); /* Quantized ISFs */ + move16(); /* Update with quantized prediction error for MA model */ + isf_q[i] = add( mem_AR[i], mean_isf_amr_wb_fx[i] ); /*(Qx2.56)*/ + move16(); /* Quantized ISFs */ } return; @@ -297,9 +297,9 @@ void disf_2s_46b_fx( void disf_2s_36b_fx( Word16 *indice, /* i : quantized indices (use indice[0] = -1 in the decoder) */ - Word16 *isf_q, /* o : quantized ISFs in the cosine domain */ - Word16 *mem_AR, /* i/o: quantizer memory for AR model */ - Word16 *mem_MA, /* i/o: quantizer memory for MA model */ + Word16 *isf_q, /* (Qx2.56) o : quantized ISFs in the cosine domain */ + Word16 *mem_AR, /* (Qx2.56) i/o: quantizer memory for AR model */ + Word16 *mem_MA, /* (Qx2.56) i/o: quantizer memory for MA model */ const Word16 enc_dec /* i : encoder (0), decoder (1) G722.2 FER */ ) { @@ -323,42 +323,42 @@ void disf_2s_36b_fx( FOR( i = 0; i < 9; i++ ) { - isf_q[i] = pt_dico1[indice[0] * 9 + i]; + isf_q[i] = pt_dico1[indice[0] * 9 + i]; /*(Qx2.56)*/ move16(); } FOR( i = 0; i < 7; i++ ) { - isf_q[i + 9] = dico2_isf_fx[indice[1] * 7 + i]; + isf_q[i + 9] = dico2_isf_fx[indice[1] * 7 + i]; /*(Qx2.56)*/ move16(); } FOR( i = 0; i < 5; i++ ) { - isf_q[i] = add( isf_q[i], dico21_isf_36b_fx[indice[2] * 5 + i] ); + isf_q[i] = add( isf_q[i], dico21_isf_36b_fx[indice[2] * 5 + i] ); /*(Qx2.56)*/ move16(); } FOR( i = 0; i < 4; i++ ) { - isf_q[i + 5] = add( isf_q[i + 5], dico22_isf_36b_fx[indice[3] * 4 + i] ); + isf_q[i + 5] = add( isf_q[i + 5], dico22_isf_36b_fx[indice[3] * 4 + i] ); /*(Qx2.56)*/ move16(); } FOR( i = 0; i < 7; i++ ) { - isf_q[i + 9] = add( isf_q[i + 9], dico23_isf_36b_fx[indice[4] * 7 + i] ); + isf_q[i + 9] = add( isf_q[i + 9], dico23_isf_36b_fx[indice[4] * 7 + i] ); /*(Qx2.56)*/ move16(); } FOR( i = 0; i < M; i++ ) { - mem_AR[i] = add( isf_q[i], mult_r( MU_MA_FX, mem_MA[i] ) ); - move16(); /* Update with quantized ISF vector for AR model */ + mem_AR[i] = add( isf_q[i], mult_r( MU_MA_FX, mem_MA[i] ) ); /*(Qx2.56)*/ + move16(); /* Update with quantized ISF vector for AR model */ mem_MA[i] = isf_q[i]; - move16(); /* Update with quantized prediction error for MA model */ - isf_q[i] = mem_AR[i] + mean_isf_amr_wb_fx[i]; - move16(); /* Quantized ISFs */ + move16(); /* Update with quantized prediction error for MA model */ + isf_q[i] = add( mem_AR[i], mean_isf_amr_wb_fx[i] ); /*(Qx2.56)*/ + move16(); /* Quantized ISFs */ } return; diff --git a/lib_com/ivas_fb_mixer.c b/lib_com/ivas_fb_mixer.c index 86e9e9e47..0a45a3600 100644 --- a/lib_com/ivas_fb_mixer.c +++ b/lib_com/ivas_fb_mixer.c @@ -49,20 +49,10 @@ * Static functions declarations *------------------------------------------------------------------------------------------*/ static void ivas_cmult_fix( Word32 in1_re, Word32 in1_im, Word32 in2_re, Word32 in2_im, Word32 *out1_re, Word32 *out1_im ); -static void ivas_get_active_bins( const int16_t **pActive_bins, const int16_t **pActive_bins_abs, const int16_t **pStart_offset, const int16_t **pStart_offset_ab, const int32_t sampling_rate ); -static void ivas_get_ld_fb_resp( float **ppIdeal_FRs_re, float **ppIdeal_FRs_im, float **ppNew_FRs_re, float **ppNew_FRs_im, const int16_t *pActive_bins, const int16_t *pStart_offset, const int16_t num_bands, const int16_t delay, const int32_t sampling_rate ); -#ifdef IVAS_FLOAT_FIXED static void ivas_get_active_bins_fx( const Word16 **pActive_bins, const Word16 **pActive_bins_abs, const Word16 **pStart_offset, const Word16 **pStart_offset_ab, const Word32 sampling_rate ); static void ivas_get_ld_fb_resp_fx( Word32 **ppIdeal_FRs_re_fx, Word32 **ppIdeal_FRs_im_fx, Word32 **ppNew_FRs_re_fx, Word32 **ppNew_FRs_im_fx, const Word16 *pActive_bins, const Word16 *pStart_offset, const Word16 num_bands, const Word16 delay, const Word32 sampling_rate ); -#endif -static ivas_error ivas_filterbank_setup( IVAS_FB_MIXER_HANDLE hFbMixer, const int32_t sampling_rate ); -#ifdef IVAS_FLOAT_FIXED static ivas_error ivas_filterbank_setup_fx( IVAS_FB_MIXER_HANDLE hFbMixer, const Word32 sampling_rate, Word16 *index ); -#endif -static ivas_error ivas_fb_mixer_get_window( const int16_t fade_len, const int32_t sampling_rate, const float **pWindow ); -#ifdef IVAS_FLOAT_FIXED static ivas_error ivas_fb_mixer_get_window_fx( const Word16 fade_len, const Word32 sampling_rate, const Word16 **pWindow ); -#endif #ifdef IVAS_FLOAT_FIXED @@ -192,7 +182,8 @@ ivas_error ivas_fb_set_cfg( Word16 tmp = shl( div_l( sampling_rate, FRAMES_PER_SEC ), 1 ); // Q0 tmp = mult0( tmp, 3 ); // Q0 tmp = shr( tmp, 2 ); // Q0 - pFb_cfg->windowed_fr_offset = (Word16) ( tmp - NS2SA_FX2( sampling_rate, DELAY_DIRAC_SPAR_ENC_CMP_NS ) ); + pFb_cfg->windowed_fr_offset = sub( tmp, NS2SA_FX2( sampling_rate, DELAY_DIRAC_SPAR_ENC_CMP_NS ) ); + move16(); move16(); move16(); move16(); @@ -287,244 +278,6 @@ ivas_error ivas_fb_set_cfg( * * Allocate and initialize FB mixer handle *------------------------------------------------------------------------*/ - -ivas_error ivas_FB_mixer_open( - IVAS_FB_MIXER_HANDLE *hFbMixer_out, /* i/o: FB mixer handle */ - const int32_t sampling_rate, /* i : sampling rate */ - IVAS_FB_CFG *fb_cfg, /* i : FB config. handle */ - const int16_t spar_reconfig_flag /* i : SPAR reconfiguration flag */ -) -{ - IVAS_FB_MIXER_HANDLE hFbMixer; - int16_t i, j, frame_len, num_bands; - int16_t num_chs_alloc; - ivas_error error; - - error = IVAS_ERR_OK; - - frame_len = (int16_t) ( sampling_rate / FRAMES_PER_SEC ); - - hFbMixer = *hFbMixer_out; - - if ( !spar_reconfig_flag ) - { - if ( ( hFbMixer = (IVAS_FB_MIXER_HANDLE) malloc( sizeof( IVAS_FB_MIXER_DATA ) ) ) == NULL ) - { - return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FB mixer encoder" ); - } - - if ( fb_cfg->num_out_chans > 0 ) - { - if ( ( hFbMixer->pFb = (ivas_filterbank_t *) malloc( sizeof( ivas_filterbank_t ) ) ) == NULL ) - { - return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FB mixer encoder" ); - } - } - else - { - hFbMixer->pFb = NULL; - } - } - - if ( fb_cfg->active_w_mixing == -1 ) - { - num_chs_alloc = 0; - } - else if ( fb_cfg->active_w_mixing ) - { - num_chs_alloc = max( fb_cfg->num_in_chans, fb_cfg->nchan_fb_in ); - } - else - { - num_chs_alloc = 1; /* only W channel processed for predicting YZX */ - } - - for ( i = 0; i < num_chs_alloc; i++ ) - { - if ( fb_cfg->num_out_chans == 0 ) - { -#ifndef IVAS_FLOAT_FIXED - hFbMixer->ppFilterbank_inFR_re[i] = NULL; - hFbMixer->ppFilterbank_inFR_im[i] = NULL; -#else - hFbMixer->ppFilterbank_inFR_re_fx[i] = NULL; - hFbMixer->ppFilterbank_inFR_im_fx[i] = NULL; -#endif - } - else - { - j = fb_cfg->remix_order[i]; -#ifndef IVAS_FLOAT_FIXED - if ( ( hFbMixer->ppFilterbank_inFR_re[j] = (float *) malloc( sizeof( float ) * frame_len ) ) == NULL ) - { - return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FB mixer encoder" ); - } - - if ( ( hFbMixer->ppFilterbank_inFR_im[j] = (float *) malloc( sizeof( float ) * frame_len ) ) == NULL ) - { - return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FB mixer encoder" ); - } -#else - if ( ( hFbMixer->ppFilterbank_inFR_re_fx[j] = (Word32 *) malloc( sizeof( Word32 ) * frame_len ) ) == NULL ) - { - return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FB mixer encoder" ); - } - - if ( ( hFbMixer->ppFilterbank_inFR_im_fx[j] = (Word32 *) malloc( sizeof( Word32 ) * frame_len ) ) == NULL ) - { - return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FB mixer encoder" ); - } -#endif - } - } - - if ( fb_cfg->active_w_mixing == -1 ) - { - num_chs_alloc = 0; - } - else - { - num_chs_alloc = max( fb_cfg->num_in_chans, fb_cfg->nchan_fb_in ); - } - - for ( i = 0; i < num_chs_alloc; i++ ) - { - if ( ( hFbMixer->ppFilterbank_prior_input[i] = (float *) malloc( sizeof( float ) * fb_cfg->prior_input_length ) ) == NULL ) - { - return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FB mixer encoder" ); - } - set_f( hFbMixer->ppFilterbank_prior_input[i], 0, fb_cfg->prior_input_length ); -#ifdef IVAS_FLOAT_FIXED - IF( ( hFbMixer->ppFilterbank_prior_input_fx[i] = (Word32 *) malloc( sizeof( Word32 ) * fb_cfg->prior_input_length ) ) == NULL ) - { - return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FB mixer encoder" ); - } - set32_fx( hFbMixer->ppFilterbank_prior_input_fx[i], 0, fb_cfg->prior_input_length ); -#endif - } - -#ifdef IVAS_FLOAT_FIXED - FOR( i = 0; i < num_chs_alloc; i++ ) - { - IF( ( hFbMixer->ppFilterbank_prior_input_fx[i] = (Word32 *) malloc( sizeof( Word32 ) * fb_cfg->prior_input_length ) ) == NULL ) - { - return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FB mixer encoder" ); - } - set32_fx( hFbMixer->ppFilterbank_prior_input_fx[i], 0, fb_cfg->prior_input_length ); - } -#endif - - if ( ( fb_cfg->active_w_mixing != -1 ) && ( fb_cfg->num_out_chans > 0 ) ) - { - Word32 *pTemp_mem_fx; - if ( ( pTemp_mem_fx = (Word32 *) malloc( sizeof( Word32 ) * fb_cfg->num_out_chans * max( fb_cfg->num_in_chans, fb_cfg->nchan_fb_in ) * IVAS_MAX_NUM_BANDS ) ) == NULL ) - { - return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FB mixer" ); - } - for ( i = 0; i < fb_cfg->num_out_chans; i++ ) - { - for ( j = 0; j < fb_cfg->num_in_chans; j++ ) - { - hFbMixer->prior_mixer_fx[i][j] = pTemp_mem_fx; - pTemp_mem_fx += IVAS_MAX_NUM_BANDS; - set32_fx( hFbMixer->prior_mixer_fx[i][j], 0, IVAS_MAX_NUM_BANDS ); - } - } - hFbMixer->q_prior_mixer_fx = Q31; - move16(); - } - - if ( !spar_reconfig_flag ) - { - if ( fb_cfg->num_out_chans > 0 ) - { - const int16_t *pActive_bins_per_band, *pActive_bins_per_band_abs, *pStart_offset, *pStart_offset_abs; - - num_bands = ivas_get_num_bands( sampling_rate ); - - ivas_get_active_bins( &pActive_bins_per_band, &pActive_bins_per_band_abs, &pStart_offset, &pStart_offset_abs, sampling_rate ); - - if ( fb_cfg->active_w_mixing != -1 ) - { - for ( i = 0; i < num_bands; i++ ) - { - if ( ( hFbMixer->pFb->fb_bin_to_band.pFb_bin_to_band[i] = (float *) malloc( sizeof( float ) * pActive_bins_per_band_abs[i] ) ) == NULL ) - { - return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FB mixer encoder" ); - } -#ifdef IVAS_FLOAT_FIXED - IF( ( hFbMixer->pFb->fb_bin_to_band.pFb_bin_to_band_fx[i] = (Word32 *) malloc( sizeof( Word32 ) * pActive_bins_per_band_abs[i] ) ) == NULL ) - { - return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FB mixer encoder fixed" ); - } -#endif - } - } - - if ( sampling_rate != 48000 ) - { - int16_t num_diff_bands, start_diff_band_non48k; - - num_diff_bands = MAX_NUM_BANDS_DIFF_NON48K; - start_diff_band_non48k = num_bands - num_diff_bands; - - hFbMixer->num_diff_bands = num_diff_bands; - - for ( j = start_diff_band_non48k; j < num_bands; j++ ) - { - if ( ( hFbMixer->pFb->fb_consts.ppFilterbank_FRs_non48k[0][j] = (float *) malloc( sizeof( float ) * pActive_bins_per_band[j] ) ) == NULL ) - { - return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FB mixer encoder" ); - } - - if ( ( hFbMixer->pFb->fb_consts.ppFilterbank_FRs_non48k[1][j] = (float *) malloc( sizeof( float ) * pActive_bins_per_band[j] ) ) == NULL ) - { - return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FB mixer encoder" ); - } -#ifdef IVAS_FLOAT_FIXED - IF( ( hFbMixer->pFb->fb_consts.ppFilterbank_FRs_non48k_fx[0][j] = (Word32 *) malloc( sizeof( Word32 ) * pActive_bins_per_band[j] ) ) == NULL ) - { - return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FB mixer encoder" ); - } - - IF( ( hFbMixer->pFb->fb_consts.ppFilterbank_FRs_non48k_fx[1][j] = (Word32 *) malloc( sizeof( Word32 ) * pActive_bins_per_band[j] ) ) == NULL ) - { - return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FB mixer encoder" ); - } -#endif - } - } - } - else - { - /* ignore all the deeper filter bank stuff for now */ - hFbMixer->num_diff_bands = 0; - } - } - - hFbMixer->fb_cfg = fb_cfg; - set_s( hFbMixer->first_frame, 1, hFbMixer->fb_cfg->num_out_chans ); - set_s( hFbMixer->first_frame + hFbMixer->fb_cfg->num_out_chans, 0, IVAS_SPAR_MAX_CH - hFbMixer->fb_cfg->num_out_chans ); - - if ( !spar_reconfig_flag ) - { - if ( ( error = ivas_filterbank_setup( hFbMixer, sampling_rate ) ) != IVAS_ERR_OK ) - { - return error; - } - Word16 index[IVAS_MAX_NUM_FB_BANDS]; - set16_fx( index, 0, IVAS_MAX_NUM_FB_BANDS ); - if ( ( error = ivas_filterbank_setup_fx( hFbMixer, sampling_rate, index ) ) != IVAS_ERR_OK ) - { - return error; - } - } - - *hFbMixer_out = hFbMixer; - - return error; -} - #ifdef IVAS_FLOAT_FIXED ivas_error ivas_FB_mixer_open_fx( IVAS_FB_MIXER_HANDLE *hFbMixer_out, /* i/o: FB mixer handle */ @@ -622,13 +375,6 @@ ivas_error ivas_FB_mixer_open_fx( return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FB mixer encoder" ); } set32_fx( hFbMixer->ppFilterbank_prior_input_fx[i], 0, fb_cfg->prior_input_length ); -#if 1 // TODO: To be removed later - if ( ( hFbMixer->ppFilterbank_prior_input[i] = (float *) malloc( sizeof( float ) * fb_cfg->prior_input_length ) ) == NULL ) - { - return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FB mixer encoder" ); - } - set_f( hFbMixer->ppFilterbank_prior_input[i], 0, fb_cfg->prior_input_length ); -#endif } test(); @@ -670,12 +416,6 @@ ivas_error ivas_FB_mixer_open_fx( { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FB mixer encoder fixed" ); } -#if 1 // TODO: To be removed later - if ( ( hFbMixer->pFb->fb_bin_to_band.pFb_bin_to_band[i] = (float *) malloc( sizeof( float ) * pActive_bins_per_band_abs[i] ) ) == NULL ) - { - return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FB mixer encoder" ); - } -#endif } } @@ -738,147 +478,6 @@ ivas_error ivas_FB_mixer_open_fx( * Deallocate FB mixer handle *------------------------------------------------------------------------*/ - -void ivas_FB_mixer_close( - IVAS_FB_MIXER_HANDLE *hFbMixer_in, /* i/o: FB mixer handle */ - const int32_t sampling_rate, /* i : sampling rate in Hz */ - const int16_t spar_reconfig_flag /* i : SPAR reconfiguration flag */ -) -{ - IVAS_FB_MIXER_HANDLE hFbMixer; - IVAS_FB_CFG *fb_cfg; - int16_t i, j, num_bands; - int16_t num_chs_alloc; - - hFbMixer = *hFbMixer_in; - fb_cfg = hFbMixer->fb_cfg; - - if ( fb_cfg->active_w_mixing == -1 ) - { - num_chs_alloc = 0; - } - else if ( fb_cfg->active_w_mixing ) - { - num_chs_alloc = max( fb_cfg->num_in_chans, fb_cfg->nchan_fb_in ); - } - else - { - num_chs_alloc = 1; /* only W channel processed for predicting YZX */ - } - - if ( hFbMixer != NULL ) - { - for ( i = 0; i < num_chs_alloc; i++ ) - { - if ( fb_cfg->num_out_chans > 0 ) - { - j = fb_cfg->remix_order[i]; -#ifndef IVAS_FLOAT_FIXED - free( hFbMixer->ppFilterbank_inFR_re[j] ); - hFbMixer->ppFilterbank_inFR_re[j] = NULL; - - free( hFbMixer->ppFilterbank_inFR_im[j] ); - hFbMixer->ppFilterbank_inFR_im[j] = NULL; -#else - free( hFbMixer->ppFilterbank_inFR_re_fx[j] ); - hFbMixer->ppFilterbank_inFR_re_fx[j] = NULL; - - free( hFbMixer->ppFilterbank_inFR_im_fx[j] ); - hFbMixer->ppFilterbank_inFR_im_fx[j] = NULL; -#endif - } - } - - if ( fb_cfg->active_w_mixing == -1 ) - { - num_chs_alloc = 0; - } - else - { - num_chs_alloc = max( fb_cfg->num_in_chans, fb_cfg->nchan_fb_in ); - } - - for ( i = 0; i < num_chs_alloc; i++ ) - { - free( hFbMixer->ppFilterbank_prior_input[i] ); - hFbMixer->ppFilterbank_prior_input[i] = NULL; - } -#ifdef IVAS_FLOAT_FIXED - for ( i = 0; i < num_chs_alloc; i++ ) - { - free( hFbMixer->ppFilterbank_prior_input_fx[i] ); - hFbMixer->ppFilterbank_prior_input_fx[i] = NULL; - } -#endif - if ( !spar_reconfig_flag ) - { - if ( fb_cfg->num_out_chans > 0 ) - { - num_bands = hFbMixer->pFb->filterbank_num_bands; - - if ( fb_cfg->active_w_mixing != -1 ) - { - for ( i = 0; i < num_bands; i++ ) - { - free( hFbMixer->pFb->fb_bin_to_band.pFb_bin_to_band[i] ); - hFbMixer->pFb->fb_bin_to_band.pFb_bin_to_band[i] = NULL; -#ifdef IVAS_FLOAT_FIXED - free( hFbMixer->pFb->fb_bin_to_band.pFb_bin_to_band_fx[i] ); - hFbMixer->pFb->fb_bin_to_band.pFb_bin_to_band_fx[i] = NULL; -#endif - } - } - - if ( sampling_rate != 48000 ) - { - int16_t start_diff_band_non48k; - start_diff_band_non48k = num_bands - hFbMixer->num_diff_bands; - - for ( j = start_diff_band_non48k; j < num_bands; j++ ) - { - free( hFbMixer->pFb->fb_consts.ppFilterbank_FRs_non48k[0][j] ); - hFbMixer->pFb->fb_consts.ppFilterbank_FRs_non48k[0][j] = NULL; - - free( hFbMixer->pFb->fb_consts.ppFilterbank_FRs_non48k[1][j] ); - hFbMixer->pFb->fb_consts.ppFilterbank_FRs_non48k[1][j] = NULL; - } - -#ifdef IVAS_FLOAT_FIXED - FOR( j = start_diff_band_non48k; j < num_bands; j++ ) - { - free( hFbMixer->pFb->fb_consts.ppFilterbank_FRs_non48k_fx[0][j] ); - hFbMixer->pFb->fb_consts.ppFilterbank_FRs_non48k_fx[0][j] = NULL; - - free( hFbMixer->pFb->fb_consts.ppFilterbank_FRs_non48k_fx[1][j] ); - hFbMixer->pFb->fb_consts.ppFilterbank_FRs_non48k_fx[1][j] = NULL; - } -#endif - } - } - if ( hFbMixer->pFb != NULL ) - { - free( hFbMixer->pFb ); - hFbMixer->pFb = NULL; - } - } - - if ( hFbMixer->fb_cfg != NULL ) - { - free( hFbMixer->fb_cfg ); - hFbMixer->fb_cfg = NULL; - } - - if ( !spar_reconfig_flag ) - { - free( hFbMixer ); - hFbMixer = NULL; - } - } - - return; -} - - #ifdef IVAS_FLOAT_FIXED void ivas_FB_mixer_close_fx( IVAS_FB_MIXER_HANDLE *hFbMixer_in, /* i/o: FB mixer handle */ @@ -954,6 +553,7 @@ void ivas_FB_mixer_close_fx( IF( fb_cfg->num_out_chans > 0 ) { num_bands = hFbMixer->pFb->filterbank_num_bands; + move16(); IF( NE_16( fb_cfg->active_w_mixing, -1 ) ) { @@ -1048,7 +648,7 @@ void ivas_fb_mixer_pcm_ingest_fx( Word32 **ppOut_pcm, /* o : output audio channels Qq_ppOut_pcm[] */ const Word16 frame_len, /* i : frame length */ const Word16 HOA_md_ind[IVAS_SPAR_MAX_CH], - Word16 q_data_fix[MAX_INPUT_CHANNELS + MAX_NUM_OBJECTS], + Word16 q_data_fix, Word16 *q_ppOut_pcm ) { Word16 i; @@ -1069,7 +669,7 @@ void ivas_fb_mixer_pcm_ingest_fx( FOR( i = 0; i < fb_cfg->num_in_chans; i++ ) { - Word16 q_temp = s_min( hFbMixer->q_ppFilterbank_prior_input_fx[i], q_data_fix[HOA_md_ind[i]] ); + Word16 q_temp = s_min( hFbMixer->q_ppFilterbank_prior_input_fx[i], q_data_fix ); // mvr2r(&hFbMixer->ppFilterbank_prior_input[i][fb_cfg->prior_input_length - frame_len], ppOut_pcm[i], frame_len); @@ -1086,11 +686,11 @@ void ivas_fb_mixer_pcm_ingest_fx( // mvr2r(pcm_in[HOA_md_ind[i]], &ppOut_pcm[i][frame_len], frame_len); Copy32( pcm_in[HOA_md_ind[i]], &ppOut_pcm[i][frame_len], frame_len ); - IF( LT_16( q_temp, q_data_fix[HOA_md_ind[i]] ) ) + IF( LT_16( q_temp, q_data_fix ) ) { FOR( Word16 x = frame_len; x < shl( frame_len, 1 ); x++ ) { - ppOut_pcm[i][x] = L_shr( ppOut_pcm[i][x], sub( q_data_fix[HOA_md_ind[i]], q_temp ) ); + ppOut_pcm[i][x] = L_shr( ppOut_pcm[i][x], sub( q_data_fix, q_temp ) ); move32(); } } @@ -1102,11 +702,14 @@ void ivas_fb_mixer_pcm_ingest_fx( FOR( i = 0; i < num_chs_ingest; i++ ) { - Word16 q_shift = sub( getScaleFactor32( ppOut_pcm[fb_cfg->remix_order[i]], shl( frame_len, 1 ) ), guard_bits ); + Word16 q_shift = sub( L_norm_arr( ppOut_pcm[fb_cfg->remix_order[i]], shl( frame_len, 1 ) ), guard_bits ); Scale_sig32( ppOut_pcm[fb_cfg->remix_order[i]], shl( frame_len, 1 ), q_shift ); q_ppOut_pcm[fb_cfg->remix_order[i]] = add( q_ppOut_pcm[fb_cfg->remix_order[i]], q_shift ); + move16(); ivas_mdft_fx( ppOut_pcm[fb_cfg->remix_order[i]], hFbMixer->ppFilterbank_inFR_re_fx[fb_cfg->remix_order[i]], hFbMixer->ppFilterbank_inFR_im_fx[fb_cfg->remix_order[i]], shl( frame_len, 1 ), frame_len ); + hFbMixer->q_ppFilterbank_inFR[fb_cfg->remix_order[i]] = q_ppOut_pcm[fb_cfg->remix_order[i]]; + move16(); } return; @@ -1182,8 +785,8 @@ void ivas_fb_mixer_get_windowed_fr_fx( n_old_samples = s_min( ( sub( hFbMixer->fb_cfg->prior_input_length, hFbMixer->fb_cfg->windowed_fr_offset ) ), ( shl( mdft_len, 1 ) ) ); n_new_samples = s_max( 0, sub( shl( length, 1 ), n_old_samples ) ); - offset = (Word16) ( sub( sub( shl( mdft_len, 1 ), length ), hFbMixer->ana_window_offset ) ); - rev_offset = (Word16) ( sub( shl( mdft_len, 1 ), hFbMixer->ana_window_offset ) ); + offset = sub( sub( shl( mdft_len, 1 ), length ), hFbMixer->ana_window_offset ); + rev_offset = sub( shl( mdft_len, 1 ), hFbMixer->ana_window_offset ); set32_fx( fr_in_block_fx, 0, offset ); FOR( ch_idx = 0; ch_idx < nchan_fb_in; ch_idx++ ) @@ -1211,7 +814,7 @@ void ivas_fb_mixer_get_windowed_fr_fx( move16(); } - ivas_mdft_fx( fr_in_block_fx, frame_f_real_fx[ch_idx], frame_f_imag_fx[ch_idx], mdft_len << 1, mdft_len ); + ivas_mdft_fx( fr_in_block_fx, frame_f_real_fx[ch_idx], frame_f_imag_fx[ch_idx], shl( mdft_len, 1 ), mdft_len ); } return; @@ -1269,50 +872,6 @@ void ivas_fb_mixer_get_windowed_fr( * FB Mixer cross fading *-----------------------------------------------------------------------------------------*/ -void ivas_fb_mixer_cross_fading( - IVAS_FB_MIXER_HANDLE hFbMixer, - float **ppOut_pcm, - float *pMdft_out_old, - float *pMdft_out_new, - const int16_t ch, - const int16_t frame_len, - const int16_t cf_offset ) -{ - int16_t k, fade_start_offset, fade_end_offset; - - if ( hFbMixer->first_frame[ch] == 0 ) - { - fade_start_offset = hFbMixer->cross_fade_start_offset; - fade_end_offset = hFbMixer->cross_fade_end_offset; - - for ( k = 0; k < fade_start_offset; k++ ) - { - ppOut_pcm[ch][k] = pMdft_out_old[k + cf_offset]; - } - - for ( k = fade_start_offset; k < fade_end_offset; k++ ) - { - ppOut_pcm[ch][k] = pMdft_out_new[k + cf_offset] * hFbMixer->pFilterbank_cross_fade[k - fade_start_offset] + pMdft_out_old[k + cf_offset] * ( 1.0f - hFbMixer->pFilterbank_cross_fade[k - fade_start_offset] ); - } - - for ( k = fade_end_offset; k < frame_len; k++ ) - { - ppOut_pcm[ch][k] = pMdft_out_new[k + cf_offset]; - } - } - else - { - hFbMixer->first_frame[ch] = 0; - - for ( k = 0; k < frame_len; k++ ) - { - ppOut_pcm[ch][k] = pMdft_out_new[k + cf_offset]; - } - } - - return; -} - #ifdef IVAS_FLOAT_FIXED void ivas_fb_mixer_cross_fading_fx( IVAS_FB_MIXER_HANDLE hFbMixer, @@ -1375,10 +934,12 @@ void ivas_fb_mixer_cross_fading_fx( void ivas_cmult_fix( Word32 in1_re, Word32 in1_im, Word32 in2_re, Word32 in2_im, Word32 *out1_re, Word32 *out1_im ) { *out1_re = L_sub_sat( Mpy_32_32( in1_re, in2_re ), Mpy_32_32( in1_im, in2_im ) ); + move32(); *out1_im = L_add_sat( Mpy_32_32( in1_re, in2_im ), Mpy_32_32( in2_re, in1_im ) ); + move32(); } -void ivas_fb_mixer_process( +void ivas_fb_mixer_process_fx( IVAS_FB_MIXER_HANDLE hFbMixer, /* i/o: FB mixer handle */ Word32 ***mixer_mat_fx, /* i : mixer matrix */ Word16 *q_mixer_mat_fx, /* i : mixer matrix */ @@ -1462,36 +1023,10 @@ void ivas_fb_mixer_process( { Word32 temp_out_re_fx, temp_out_im_fx; - Word16 Fb_inFR_com_q = s_min( hFbMixer->q_ppFilterbank_inFR_re_fx[j], hFbMixer->q_ppFilterbank_inFR_im_fx[j] ); - Word32 inp_Fb_inFR_re, inp_Fb_inFR_im; - IF( NE_16( hFbMixer->q_ppFilterbank_inFR_re_fx[j], Fb_inFR_com_q ) ) - { - inp_Fb_inFR_re = L_shr( pFb_inFR_re_fx[k], sub( hFbMixer->q_ppFilterbank_inFR_re_fx[j], Fb_inFR_com_q ) ); - /*common q for real and imag hFbMixer->q_ppFilterbank_inFR_re_fx[j]*/ - } - ELSE - { - inp_Fb_inFR_re = pFb_inFR_re_fx[k]; - /*q hFbMixer->q_ppFilterbank_inFR_re_fx[j]*/ - move32(); - } - IF( NE_16( hFbMixer->q_ppFilterbank_inFR_im_fx[j], Fb_inFR_com_q ) ) - { - inp_Fb_inFR_im = L_shr( pFb_inFR_im_fx[k], sub( hFbMixer->q_ppFilterbank_inFR_im_fx[j], Fb_inFR_com_q ) ); - /*common q for real and imag hFbMixer->q_ppFilterbank_inFR_re_fx[j]*/ - } - ELSE - { - inp_Fb_inFR_im = pFb_inFR_im_fx[k]; - /*q hFbMixer->q_ppFilterbank_inFR_im_fx[j]*/ - move32(); - } - ivas_cmult_fix( filterbank_mixer_bins_re_fx[k], filterbank_mixer_bins_im_fx[k], inp_Fb_inFR_re, - inp_Fb_inFR_im, &temp_out_re_fx, &temp_out_im_fx ); - res_q = sub( add( sub( sub( add( 30, *q_mixer_mat_fx ), 31 ), total_guard ), Fb_inFR_com_q ), 31 ); - move16(); + ivas_cmult_fix( filterbank_mixer_bins_re_fx[k], filterbank_mixer_bins_im_fx[k], pFb_inFR_re_fx[k], + pFb_inFR_im_fx[k], &temp_out_re_fx, &temp_out_im_fx ); + res_q = sub( add( sub( sub( add( 30, *q_mixer_mat_fx ), 31 ), total_guard ), hFbMixer->q_ppFilterbank_inFR[j] ), 31 ); Word16 q_check = s_min( q_pOut_fr_fx, res_q ); - move16(); IF( NE_16( q_check, q_pOut_fr_fx ) ) { pOut_fr_re_fx[k] = L_shr( pOut_fr_re_fx[k], sub( q_pOut_fr_fx, q_check ) ); @@ -1499,7 +1034,7 @@ void ivas_fb_mixer_process( pOut_fr_im_fx[k] = L_shr( pOut_fr_im_fx[k], sub( q_pOut_fr_fx, q_check ) ); move32(); } - IF( q_check != res_q ) + IF( NE_16( q_check, res_q ) ) { temp_out_re_fx = L_shr( temp_out_re_fx, sub( res_q, q_check ) ); temp_out_im_fx = L_shr( temp_out_im_fx, sub( res_q, q_check ) ); @@ -1648,31 +1183,34 @@ void ivas_fb_mixer_process( * *-----------------------------------------------------------------------------------------*/ -void ivas_fb_mixer_get_in_out_mapping( - const IVAS_FB_CFG *fb_cfg, /* i : FB config. handle */ - int16_t in_out_mixer_map[IVAS_MAX_FB_MIXER_OUT_CH][IVAS_MAX_SPAR_FB_MIXER_IN_CH] /* i/o: mixing mapping */ +void ivas_fb_mixer_get_in_out_mapping_fx( + const IVAS_FB_CFG *fb_cfg, /* i : FB config. handle */ + Word16 in_out_mixer_map[IVAS_MAX_FB_MIXER_OUT_CH][IVAS_MAX_SPAR_FB_MIXER_IN_CH] /* i/o: mixing mapping */ ) { - int16_t i, j; + Word16 i, j; - set_s( (int16_t *) in_out_mixer_map, 0, IVAS_MAX_FB_MIXER_OUT_CH * IVAS_MAX_SPAR_FB_MIXER_IN_CH ); + set_s( (Word16 *) in_out_mixer_map, 0, IVAS_MAX_FB_MIXER_OUT_CH * IVAS_MAX_SPAR_FB_MIXER_IN_CH ); - if ( fb_cfg->active_w_mixing ) + IF( fb_cfg->active_w_mixing ) { - for ( i = 0; i < fb_cfg->num_out_chans; i++ ) + FOR( i = 0; i < fb_cfg->num_out_chans; i++ ) { - for ( j = 0; j < fb_cfg->num_in_chans; j++ ) + FOR( j = 0; j < fb_cfg->num_in_chans; j++ ) { in_out_mixer_map[i][j] = 1; + move16(); } } } - else + ELSE { in_out_mixer_map[0][0] = 1; /* W depends on only W input*/ - for ( i = 1; i < fb_cfg->num_out_chans; i++ ) + move16(); + FOR( i = 1; i < fb_cfg->num_out_chans; i++ ) { in_out_mixer_map[i][0] = 1; + move16(); } } @@ -1686,255 +1224,6 @@ void ivas_fb_mixer_get_in_out_mapping( * Function to calculate number of active bands *-----------------------------------------------------------------------------------------*/ -static int16_t ivas_calculate_abs_fr( - ivas_filterbank_t *pFb, - const int32_t sampling_rate, - const int16_t alloc_fb_resp ) -{ - int16_t frame_len; - float ppFilterbank_FRs_s[L_FRAME48k]; -#ifdef IVAS_FLOAT_FIXED - Word32 ppFilterbank_FRs_s_fx[L_FRAME48k]; -#endif - int16_t bands = pFb->filterbank_num_bands; - int16_t i, j, num_active_bands = 0; - int16_t idx_short_stride_bin_to_band = 0; - - for ( i = 0; i < bands; i++ ) - { - const float *long_mdft_ptr_re = pFb->fb_consts.ppFilterbank_FRs[0][i]; - const float *long_mdft_ptr_im = pFb->fb_consts.ppFilterbank_FRs[1][i]; - int16_t start_offset = pFb->fb_consts.pFilterbank_bins_start_offset[i]; - int16_t num_bins = pFb->fb_consts.pFilterbank_bins_per_band[i]; - int16_t short_mdft_start_bin = -1; - float short_stride_pow_spec[MDFT_FB_BANDS_240]; - float short_stride_nrg = 0.0f; -#ifdef IVAS_FLOAT_FIXED - Word32 short_stride_pow_spec_fx[MDFT_FB_BANDS_240]; - Word32 short_stride_nrg_fx = 0; - Word16 exp_diff = 0, tmp; -#endif - float cldfb_nrg = 0.0f; - int16_t short_stride = pFb->fb_bin_to_band.short_stride; - const int16_t num_bins_per_short_stride_bin = ( const int16_t )( ( sampling_rate / FRAMES_PER_SEC ) / short_stride ); - const int16_t num_bins_per_cldfb_band = ( const int16_t )( ( sampling_rate / FRAMES_PER_SEC ) / pFb->fb_bin_to_band.num_cldfb_bands ); - float short_stride_max_per_spar_band = 1e-9f; -#ifdef IVAS_FLOAT_FIXED - Word32 short_stride_max_per_spar_band_fx = 1; -#endif - - /*loop over all stored Filter Bank Response MDFT coefficients*/ - set_f( short_stride_pow_spec, 0, MDFT_FB_BANDS_240 ); -#ifdef IVAS_FLOAT_FIXED - set32_fx( short_stride_pow_spec_fx, 0, MDFT_FB_BANDS_240 ); -#endif - for ( j = start_offset; j < num_bins + start_offset; j++ ) - { - float sq_abs; -#ifdef IVAS_FLOAT_FIXED - Word32 sq_abs_fx; -#endif - - /*calculate bin energy */ - IVAS_CALCULATE_SQ_ABS( *long_mdft_ptr_re, *long_mdft_ptr_im, sq_abs ); -#ifdef IVAS_FLOAT_FIXED - sq_abs_fx = (Word32) ( sq_abs * ONE_IN_Q22 ); -#endif - long_mdft_ptr_re++; - long_mdft_ptr_im++; - - /* accumulate bin energies within a short stride bin */ - short_stride_nrg += sq_abs; -#ifdef IVAS_FLOAT_FIXED - short_stride_nrg_fx = L_add( short_stride_nrg_fx, sq_abs_fx ); -#endif - if ( !( ( j + 1 ) % num_bins_per_short_stride_bin ) ) - { /* new short stride bin */ - short_stride_pow_spec[j / num_bins_per_short_stride_bin] = short_stride_nrg; /* energy rather than magnitude works better for covariance weighting*/ - short_stride_max_per_spar_band = max( short_stride_nrg, short_stride_max_per_spar_band ); /*compute highest magnitude per band*/ - short_stride_nrg = 0.0f; -#ifdef IVAS_FLOAT_FIXED - short_stride_pow_spec_fx[j / num_bins_per_short_stride_bin] = short_stride_nrg_fx; /* energy rather than magnitude works better for covariance weighting*/ - short_stride_max_per_spar_band_fx = max( short_stride_nrg_fx, short_stride_max_per_spar_band_fx ); /*compute highest magnitude per band*/ - short_stride_nrg_fx = 0; -#endif - } - - /* accumulate bin energies within a CLDFB band */ - cldfb_nrg += sq_abs; - if ( !( ( j + 1 ) % num_bins_per_cldfb_band ) ) - { - pFb->fb_bin_to_band.pp_cldfb_weights_per_spar_band[j / num_bins_per_cldfb_band][i] = sqrtf( cldfb_nrg ); - cldfb_nrg = 0.0f; - } - } - - /*loop over the short MDFT bins*/ - for ( j = 0; j < short_stride; j++ ) - { - /* normalize and sparsify the energies */ - short_stride_pow_spec[j] /= short_stride_max_per_spar_band; - short_stride_pow_spec[j] = max( short_stride_pow_spec[j] - 0.3f, 0.0f ) / 0.7f; -#ifdef IVAS_FLOAT_FIXED - tmp = BASOP_Util_Divide3232_Scale( short_stride_pow_spec_fx[j], short_stride_max_per_spar_band_fx, &exp_diff ); - short_stride_pow_spec_fx[j] = L_shl( L_deposit_l( tmp ), add( Q7, exp_diff ) ); // Q22 - short_stride_pow_spec_fx[j] = L_max( L_sub( short_stride_pow_spec_fx[j], (Word32) ( 0.3f * ONE_IN_Q22 ) ), 0 ); - tmp = BASOP_Util_Divide3232_Scale( short_stride_pow_spec_fx[j], (Word32) ( 0.7f * ONE_IN_Q22 ), &exp_diff ); - short_stride_pow_spec_fx[j] = L_shl( L_deposit_l( tmp ), add( Q7, exp_diff ) ); // Q22 - - IF( GT_32( short_stride_pow_spec_fx[j], 0 ) ) -#else - if ( short_stride_pow_spec[j] > 0.0f ) -#endif - { - assert( idx_short_stride_bin_to_band < 2 * MDFT_FB_BANDS_240 ); /* array size of p_short_stride_bin_to_band */ - if ( short_mdft_start_bin == -1 ) - { - short_mdft_start_bin = j; - pFb->fb_bin_to_band.p_short_stride_start_bin_per_band[i] = j; - pFb->fb_bin_to_band.pp_short_stride_bin_to_band[i] = &pFb->fb_bin_to_band.p_short_stride_bin_to_band[idx_short_stride_bin_to_band]; -#ifdef IVAS_FLOAT_FIXED - pFb->fb_bin_to_band.pp_short_stride_bin_to_band_fx[i] = &pFb->fb_bin_to_band.p_short_stride_bin_to_band_fx[idx_short_stride_bin_to_band]; -#endif - } -#ifdef IVAS_FLOAT_FIXED - pFb->fb_bin_to_band.p_short_stride_bin_to_band[idx_short_stride_bin_to_band] = short_stride_pow_spec[j]; - pFb->fb_bin_to_band.p_short_stride_bin_to_band_fx[idx_short_stride_bin_to_band] = short_stride_pow_spec_fx[j]; - idx_short_stride_bin_to_band++; -#else - pFb->fb_bin_to_band.p_short_stride_bin_to_band[idx_short_stride_bin_to_band++] = short_stride_pow_spec[j]; -#endif - pFb->fb_bin_to_band.p_short_stride_num_bins_per_band[i]++; - } - } - } - - /*loop over CLDFB bands*/ - for ( j = 0; j < pFb->fb_bin_to_band.num_cldfb_bands; j++ ) - { - float sum_over_spar_bands = 0.0f; - float max_spar_band_contribution = 0.0f; - int16_t spar_start = 0; - int16_t any_non_zero = 0; - - for ( i = 0; i < bands; i++ ) - { - sum_over_spar_bands += pFb->fb_bin_to_band.pp_cldfb_weights_per_spar_band[j][i]; - if ( pFb->fb_bin_to_band.pp_cldfb_weights_per_spar_band[j][i] > max_spar_band_contribution ) - { - max_spar_band_contribution = pFb->fb_bin_to_band.pp_cldfb_weights_per_spar_band[j][i]; - pFb->fb_bin_to_band.p_cldfb_map_to_spar_band[j] = i; - } - } - sum_over_spar_bands = max( sum_over_spar_bands, EPSILON ); - for ( i = 0; i < bands; i++ ) - { - if ( pFb->fb_bin_to_band.pp_cldfb_weights_per_spar_band[j][i] == 0.0f && !any_non_zero ) - { - spar_start++; - } - else - { - any_non_zero = 1; - } - pFb->fb_bin_to_band.pp_cldfb_weights_per_spar_band[j][i] /= sum_over_spar_bands; - } - pFb->fb_bin_to_band.p_spar_start_bands[j] = spar_start; - } - - frame_len = (int16_t) ( sampling_rate / FRAMES_PER_SEC ); - - set_f( ppFilterbank_FRs_s, 0, frame_len ); -#ifdef IVAS_FLOAT_FIXED - set32_fx( ppFilterbank_FRs_s_fx, 0, frame_len ); -#endif - - /*Commented logic is for calculating number of active bands, can be removed if not needed */ - for ( i = 0; i < bands; i++ ) - { - const float *pFilterbank_bin_to_band_re = pFb->fb_consts.ppFilterbank_FRs[0][i]; - const float *pFilterbank_bin_to_band_im = pFb->fb_consts.ppFilterbank_FRs[1][i]; - - int16_t start_offset = pFb->fb_consts.pFilterbank_bins_start_offset[i]; - int16_t num_bins = pFb->fb_consts.pFilterbank_bins_per_band[i]; - int16_t idx = 0; - int16_t abs_active_bins = pFb->fb_bin_to_band.pFb_active_bins_per_band[i]; - int16_t abs_start_offset = pFb->fb_bin_to_band.pFb_start_bin_per_band[i]; - - for ( j = start_offset; j < num_bins + start_offset; j++ ) - { - float temp = 0; - - IVAS_CALCULATE_ABS( *pFilterbank_bin_to_band_re, *pFilterbank_bin_to_band_im, temp ); - - pFilterbank_bin_to_band_re++; - pFilterbank_bin_to_band_im++; - - temp -= 0.3f; - - if ( temp < 0.0f ) - { - temp = 0; - } - - if ( j < ( abs_active_bins + abs_start_offset ) && j >= abs_start_offset && alloc_fb_resp != -1 ) - { -#ifdef IVAS_FLOAT_FIXED - pFb->fb_bin_to_band.pFb_bin_to_band[i][idx] = temp; - pFb->fb_bin_to_band.pFb_bin_to_band_fx[i][idx] = (Word32) ( temp * ONE_IN_Q22 ); - idx = add( idx, 1 ); -#else - pFb->fb_bin_to_band.pFb_bin_to_band[i][idx++] = temp; -#endif - } - - ppFilterbank_FRs_s[j] += temp; -#ifdef IVAS_FLOAT_FIXED - ppFilterbank_FRs_s_fx[j] = L_add( ppFilterbank_FRs_s_fx[j], (Word32) ( temp * ONE_IN_Q22 ) ); -#endif - } - } - - for ( i = 0; i < frame_len; i++ ) - { - if ( ppFilterbank_FRs_s[i] < 0.1f ) - { - ppFilterbank_FRs_s[i] = 0.1f; -#ifdef IVAS_FLOAT_FIXED - ppFilterbank_FRs_s_fx[i] = (Word32) ( 0.1f * ONE_IN_Q22 ); -#endif - } - } - - if ( alloc_fb_resp != -1 ) - { - for ( j = 0; j < bands; j++ ) - { - int16_t abs_active_bins = pFb->fb_bin_to_band.pFb_active_bins_per_band[j]; - int16_t abs_start_offset = pFb->fb_bin_to_band.pFb_start_bin_per_band[j]; -#ifdef IVAS_FLOAT_FIXED - Word16 exp_diff = 0, tmp; -#endif - - for ( i = 0; i < abs_active_bins; i++ ) - { - pFb->fb_bin_to_band.pFb_bin_to_band[j][i] /= ppFilterbank_FRs_s[i + abs_start_offset]; -#ifdef IVAS_FLOAT_FIXED - tmp = BASOP_Util_Divide3232_Scale( pFb->fb_bin_to_band.pFb_bin_to_band_fx[j][i], ppFilterbank_FRs_s_fx[i + abs_start_offset], &exp_diff ); - pFb->fb_bin_to_band.pFb_bin_to_band_fx[j][i] = L_shl( L_deposit_l( tmp ), add( Q7, exp_diff ) ); // Q22 -#endif - /*if(pFb->fb_bin_to_band.pFb_bin_to_band[j][i] > 0.5f) - { - num_active_bands = j + 1; - break; - }*/ - } - } - } - - return num_active_bands; -} - #ifdef IVAS_FLOAT_FIXED static Word16 ivas_calculate_abs_fr_fx( ivas_filterbank_t *pFb, @@ -1945,6 +1234,7 @@ static Word16 ivas_calculate_abs_fr_fx( Word16 frame_len; Word32 ppFilterbank_FRs_s_fx[L_FRAME48k]; Word16 bands = pFb->filterbank_num_bands; + move16(); Word16 i, j, num_active_bands = 0; move16(); Word16 idx_short_stride_bin_to_band = 0; @@ -1975,8 +1265,12 @@ static Word16 ivas_calculate_abs_fr_fx( move16(); Word16 short_stride = pFb->fb_bin_to_band.short_stride; move16(); - const Word16 num_bins_per_short_stride_bin = ( const Word16 )( ( sampling_rate / FRAMES_PER_SEC ) / short_stride ); - const Word16 num_bins_per_cldfb_band = ( const Word16 )( ( sampling_rate / FRAMES_PER_SEC ) / pFb->fb_bin_to_band.num_cldfb_bands ); + Word32 res_dec1, res_frac, res_dec2; + iDiv_and_mod_32( sampling_rate, FRAMES_PER_SEC, &res_dec1, &res_frac, 0 ); + iDiv_and_mod_32( res_dec1, short_stride, &res_dec2, &res_frac, 0 ); + const Word16 num_bins_per_short_stride_bin = extract_l( res_dec2 ); + iDiv_and_mod_32( res_dec1, pFb->fb_bin_to_band.num_cldfb_bands, &res_dec2, &res_frac, 0 ); + const Word16 num_bins_per_cldfb_band = extract_l( res_dec2 ); Word32 short_stride_max_per_spar_band_fx = 1; move32(); @@ -2010,7 +1304,6 @@ static Word16 ivas_calculate_abs_fr_fx( move32(); sq_abs_fx = BASOP_Util_Add_Mant32Exp( real_sq, real_exp, imag_sq, imag_exp, &sq_abs_e ); // Q22 - move32(); long_mdft_ptr_re_fx++; long_mdft_ptr_im_fx++; @@ -2018,7 +1311,6 @@ static Word16 ivas_calculate_abs_fr_fx( /* accumulate bin energies within a short stride bin */ short_stride_nrg_fx = L_add( short_stride_nrg_fx, L_shl( sq_abs_fx, sub( Q22, sub( Q31, sq_abs_e ) ) ) ); - move32(); IF( !( ( j + 1 ) % num_bins_per_short_stride_bin ) ) { @@ -2026,7 +1318,6 @@ static Word16 ivas_calculate_abs_fr_fx( short_stride_pow_spec_fx[j / num_bins_per_short_stride_bin] = short_stride_nrg_fx; /* energy rather than magnitude works better for covariance weighting*/ move32(); short_stride_max_per_spar_band_fx = L_max( short_stride_nrg_fx, short_stride_max_per_spar_band_fx ); /*compute highest magnitude per band*/ - move32(); short_stride_nrg_fx = 0; move32(); } @@ -2037,10 +1328,9 @@ static Word16 ivas_calculate_abs_fr_fx( IF( !( ( j + 1 ) % num_bins_per_cldfb_band ) ) { Word32 temp = Sqrt32( cldfb_nrg_fx, &cldfb_nrg_e ); - move32(); temp = L_shl( temp, sub( cldfb_nrg_e, Q9 ) ); // Q22 - move32(); pFb->fb_bin_to_band.pp_cldfb_weights_per_spar_band_fx[j / num_bins_per_cldfb_band][i] = temp; + move32(); cldfb_nrg_fx = 0; move32(); cldfb_nrg_e = 0; @@ -2052,14 +1342,12 @@ static Word16 ivas_calculate_abs_fr_fx( FOR( j = 0; j < short_stride; j++ ) { tmp = BASOP_Util_Divide3232_Scale( short_stride_pow_spec_fx[j], short_stride_max_per_spar_band_fx, &exp_diff ); - move16(); short_stride_pow_spec_fx[j] = L_shl( L_deposit_l( tmp ), add( Q7, exp_diff ) ); // Q22 move32(); short_stride_pow_spec_fx[j] = L_max( L_sub( short_stride_pow_spec_fx[j], 1258291 ), 0 ); // 0.3f * ONE_IN_Q22c move32(); tmp = BASOP_Util_Divide3232_Scale( short_stride_pow_spec_fx[j], 2936012, &exp_diff ); // 0.7f * ONE_IN_Q22 - move16(); - short_stride_pow_spec_fx[j] = L_shl( L_deposit_l( tmp ), add( Q7, exp_diff ) ); // Q22 + short_stride_pow_spec_fx[j] = L_shl( L_deposit_l( tmp ), add( Q7, exp_diff ) ); // Q22 move32(); IF( short_stride_pow_spec_fx[j] > 0 ) @@ -2103,7 +1391,6 @@ static Word16 ivas_calculate_abs_fr_fx( FOR( i = 0; i < bands; i++ ) { sum_over_spar_bands_fx = L_add( sum_over_spar_bands_fx, pFb->fb_bin_to_band.pp_cldfb_weights_per_spar_band_fx[j][i] ); - move32(); IF( pFb->fb_bin_to_band.pp_cldfb_weights_per_spar_band_fx[j][i] > max_spar_band_contribution_fx ) { @@ -2115,7 +1402,6 @@ static Word16 ivas_calculate_abs_fr_fx( } sum_over_spar_bands_fx = L_max( sum_over_spar_bands_fx, EPSILON_FX ); - move32(); FOR( i = 0; i < bands; i++ ) { @@ -2133,7 +1419,6 @@ static Word16 ivas_calculate_abs_fr_fx( Word16 exp_diff = 0; move16(); Word16 tmp = BASOP_Util_Divide3232_Scale( pFb->fb_bin_to_band.pp_cldfb_weights_per_spar_band_fx[j][i], sum_over_spar_bands_fx, &exp_diff ); - move16(); pFb->fb_bin_to_band.pp_cldfb_weights_per_spar_band_fx[j][i] = L_shl( L_deposit_l( tmp ), add( Q7, exp_diff ) ); // Q22 move32(); } @@ -2174,32 +1459,24 @@ static Word16 ivas_calculate_abs_fr_fx( Word16 exp_diff = 0; move16(); Word32 real = L_shr( *pFilterbank_bin_to_band_re_fx, 3 ); // Q27 - move32(); Word32 imag = L_shr( *pFilterbank_bin_to_band_im_fx, 3 ); - move32(); Word32 real_sq, imag_sq; real_sq = Mpy_32_32( real, real ); - move32(); imag_sq = Mpy_32_32( imag, imag ); - move32(); temp_fx = L_add( L_shr( real_sq, 1 ), L_shr( imag_sq, 1 ) ); // Q22 - move32(); exp_diff = 9; move16(); temp_fx = Sqrt32( temp_fx, &exp_diff ); - move32(); temp_fx = L_shl( temp_fx, sub( exp_diff, Q9 ) ); // Q22 - move32(); pFilterbank_bin_to_band_re_fx++; pFilterbank_bin_to_band_im_fx++; temp_fx = L_sub( temp_fx, 1258291 ); - move32(); if ( temp_fx < 0 ) { @@ -2267,36 +1544,6 @@ static Word16 ivas_calculate_abs_fr_fx( * *-----------------------------------------------------------------------------------------*/ -static void ivas_get_active_bins( - const int16_t **pActive_bins, - const int16_t **pActive_bins_abs, - const int16_t **pStart_offset, - const int16_t **pStart_offset_abs, - const int32_t sampling_rate ) -{ - int16_t sr_idx; - - if ( sampling_rate == 32000 ) - { - sr_idx = 1; - } - else if ( sampling_rate == 16000 ) - { - sr_idx = 2; - } - else - { - sr_idx = 0; - } - - *pActive_bins_abs = ivas_fb_abs_bins_per_band_12band_1ms[sr_idx]; - *pActive_bins = ivas_fb_bins_per_band_12band_1ms[sr_idx]; - *pStart_offset_abs = ivas_fb_abs_bins_start_offset_12band_1ms[sr_idx]; - *pStart_offset = ivas_fb_bins_start_offset_12band_1ms[sr_idx]; - - return; -} - #ifdef IVAS_FLOAT_FIXED static void ivas_get_active_bins_fx( const Word16 **pActive_bins, @@ -2343,168 +1590,6 @@ static void ivas_get_active_bins_fx( * Filterbank setup, initialization *-----------------------------------------------------------------------------------------*/ -static ivas_error ivas_filterbank_setup( - IVAS_FB_MIXER_HANDLE hFbMixer, - const int32_t sampling_rate ) -{ - int16_t i, j; - const float *pAll_fb_fr[2]; - const int16_t *pAll_bins_start_offset = NULL; - const int16_t *pAll_bins_per_band = NULL; - const int16_t *pAll_bins_start_offset_abs = NULL; - const int16_t *pAll_bins_per_band_abs = NULL; - const int16_t *pAll_bins_per_band_48k = NULL; - ivas_error error; - IVAS_FB_CFG *pCfg = hFbMixer->fb_cfg; - - error = IVAS_ERR_OK; - - if ( pCfg->num_out_chans > 0 ) - { - hFbMixer->pFb->filterbank_num_bands = ivas_get_num_bands( sampling_rate ); - - ivas_get_active_bins( &pAll_bins_per_band, &pAll_bins_per_band_abs, &pAll_bins_start_offset, &pAll_bins_start_offset_abs, sampling_rate ); - - if ( pCfg->fb_latency == NS2SA( sampling_rate, DELAY_FB_1_NS ) ) - { - pAll_fb_fr[0] = ivas_fb_fr_12band_1ms_re; - pAll_fb_fr[1] = ivas_fb_fr_12band_1ms_im; - pAll_bins_per_band_48k = ivas_fb_bins_per_band_12band_1ms[0]; - } - else - { - return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Wrong FB in ivas_filterbank_setup()!" ); - } - } - - hFbMixer->cross_fade_end_offset = pCfg->fade_len + pCfg->pcm_offset; - hFbMixer->cross_fade_start_offset = hFbMixer->cross_fade_end_offset - pCfg->fade_len; - hFbMixer->ana_window_offset = pCfg->fb_latency + pCfg->pcm_offset; - - if ( ( error = ivas_fb_mixer_get_window( pCfg->fb_latency, sampling_rate, &( hFbMixer->pAna_window ) ) ) != IVAS_ERR_OK ) - { - return error; - } -#ifdef IVAS_FLOAT_FIXED - IF( ( error = ivas_fb_mixer_get_window_fx( pCfg->fb_latency, sampling_rate, &( hFbMixer->pAna_window_fx ) ) ) != IVAS_ERR_OK ) - { - return error; - } -#endif - - if ( ( error = ivas_fb_mixer_get_window( pCfg->fade_len, sampling_rate, &( hFbMixer->pFilterbank_cross_fade ) ) ) != IVAS_ERR_OK ) - { - return error; - } - -#ifdef IVAS_FLOAT_FIXED - if ( ( error = ivas_fb_mixer_get_window_fx( pCfg->fade_len, sampling_rate, &( hFbMixer->pFilterbank_cross_fade_fx ) ) ) != IVAS_ERR_OK ) - { - return error; - } -#endif - - if ( pCfg->num_out_chans > 0 ) - { - ivas_filterbank_t *pFb = hFbMixer->pFb; - int16_t offset = 0; - - pFb->fb_consts.pFilterbank_bins_per_band = pAll_bins_per_band; - pFb->fb_consts.pFilterbank_bins_start_offset = pAll_bins_start_offset; - pFb->fb_bin_to_band.pFb_active_bins_per_band = pAll_bins_per_band_abs; - pFb->fb_bin_to_band.pFb_start_bin_per_band = pAll_bins_start_offset_abs; - - /* Initialization for short stride Parameter calculation and SPAR CLDFB reconstruction */ - pFb->fb_bin_to_band.num_cldfb_bands = (int16_t) ( sampling_rate * INV_CLDFB_BANDWIDTH + 0.5f ); - /*pFb->fb_bin_to_band.cldfb_stride = ( int16_t )( ( sampling_rate / FRAMES_PER_SEC ) / CLDFB_NO_COL_MAX );*/ /* equals num_cldfb_bands*/ - pFb->fb_bin_to_band.short_stride = (int16_t) ( ( sampling_rate / FRAMES_PER_SEC ) / 4 ); - set_f( pFb->fb_bin_to_band.p_short_stride_bin_to_band, 0.0f, 2 * MDFT_FB_BANDS_240 ); -#ifdef IVAS_FLOAT_FIXED - set32_fx( pFb->fb_bin_to_band.p_short_stride_bin_to_band_fx, 0, 2 * MDFT_FB_BANDS_240 ); -#endif - set_s( pFb->fb_bin_to_band.p_cldfb_map_to_spar_band, 0, CLDFB_NO_CHANNELS_MAX ); - set_s( pFb->fb_bin_to_band.p_spar_start_bands, 0, CLDFB_NO_CHANNELS_MAX ); - - for ( j = 0; j < IVAS_MAX_NUM_FB_BANDS; j++ ) - { - pFb->fb_bin_to_band.p_short_stride_num_bins_per_band[j] = 0; /* aka num_active_bins per SPAR band */ - pFb->fb_bin_to_band.p_short_stride_start_bin_per_band[j] = 0; /* first considered bin index per SPAR band */ - pFb->fb_bin_to_band.pp_short_stride_bin_to_band[j] = NULL; -#ifdef IVAS_FLOAT_FIXED - pFb->fb_bin_to_band.pp_short_stride_bin_to_band_fx[j] = NULL; -#endif - for ( i = 0; i < CLDFB_NO_CHANNELS_MAX; i++ ) - { - pFb->fb_bin_to_band.pp_cldfb_weights_per_spar_band[i][j] = 0.0f; - } - } - if ( sampling_rate == 48000 ) - { - for ( j = 0; j < pFb->filterbank_num_bands; j++ ) - { - pFb->fb_consts.ppFilterbank_FRs[0][j] = &pAll_fb_fr[0][offset]; - pFb->fb_consts.ppFilterbank_FRs[1][j] = &pAll_fb_fr[1][offset]; - offset += pFb->fb_consts.pFilterbank_bins_per_band[j]; - } - - ivas_calculate_abs_fr( pFb, sampling_rate, pCfg->active_w_mixing ); - } - else - { - float *ppFilterbank_FRs_re_temp[MAX_NUM_BANDS_DIFF_NON48K]; - float *ppFilterbank_FRs_im_temp[MAX_NUM_BANDS_DIFF_NON48K]; - int16_t active_bins_temp[MAX_NUM_BANDS_DIFF_NON48K]; - int16_t start_offset_temp[MAX_NUM_BANDS_DIFF_NON48K]; - int16_t num_diff_bands, start_diff_band_non48k; - - num_diff_bands = MAX_NUM_BANDS_DIFF_NON48K; - start_diff_band_non48k = pFb->filterbank_num_bands - num_diff_bands; - - pFb->fb_consts.pFilterbank_bins_per_band = pAll_bins_per_band; - pFb->fb_consts.pFilterbank_bins_start_offset = pAll_bins_start_offset; - - for ( j = 0; j < pFb->filterbank_num_bands; j++ ) - { - int16_t num_active_bins = pFb->fb_consts.pFilterbank_bins_per_band[j]; - - if ( j < start_diff_band_non48k ) - { - pFb->fb_consts.ppFilterbank_FRs[0][j] = &pAll_fb_fr[0][offset]; - pFb->fb_consts.ppFilterbank_FRs[1][j] = &pAll_fb_fr[1][offset]; - } - else - { - mvr2r( &pAll_fb_fr[0][offset], pFb->fb_consts.ppFilterbank_FRs_non48k[0][j], num_active_bins ); - mvr2r( &pAll_fb_fr[1][offset], pFb->fb_consts.ppFilterbank_FRs_non48k[1][j], num_active_bins ); - } - - offset += pAll_bins_per_band_48k[j]; - } - - for ( j = start_diff_band_non48k; j < pFb->filterbank_num_bands; j++ ) - { - ppFilterbank_FRs_re_temp[j - start_diff_band_non48k] = pFb->fb_consts.ppFilterbank_FRs_non48k[0][j]; - ppFilterbank_FRs_im_temp[j - start_diff_band_non48k] = pFb->fb_consts.ppFilterbank_FRs_non48k[1][j]; - active_bins_temp[j - start_diff_band_non48k] = pFb->fb_consts.pFilterbank_bins_per_band[j]; - start_offset_temp[j - start_diff_band_non48k] = pFb->fb_consts.pFilterbank_bins_start_offset[j]; - } - - ivas_get_ld_fb_resp( ppFilterbank_FRs_re_temp, ppFilterbank_FRs_im_temp, ppFilterbank_FRs_re_temp, ppFilterbank_FRs_im_temp, - active_bins_temp, start_offset_temp, num_diff_bands, pCfg->fb_latency, sampling_rate ); - - for ( j = start_diff_band_non48k; j < pFb->filterbank_num_bands; j++ ) - { - pFb->fb_consts.ppFilterbank_FRs[0][j] = (const float *) pFb->fb_consts.ppFilterbank_FRs_non48k[0][j]; - pFb->fb_consts.ppFilterbank_FRs[1][j] = (const float *) pFb->fb_consts.ppFilterbank_FRs_non48k[1][j]; - } - - ivas_calculate_abs_fr( pFb, sampling_rate, pCfg->active_w_mixing ); - } - } - - return error; -} - #ifdef IVAS_FLOAT_FIXED static ivas_error ivas_filterbank_setup_fx( IVAS_FB_MIXER_HANDLE hFbMixer, @@ -2595,7 +1680,7 @@ static ivas_error ivas_filterbank_setup_fx( /*pFb->fb_bin_to_band.cldfb_stride = ( int16_t )( ( sampling_rate / FRAMES_PER_SEC ) / CLDFB_NO_COL_MAX );*/ /* equals num_cldfb_bands*/ // pFb->fb_bin_to_band.short_stride = extract_l( ( sampling_rate / FRAMES_PER_SEC ) / 4 ); tmp = BASOP_Util_Divide3232_Scale( sampling_rate, FRAMES_PER_SEC, &exp ); - pFb->fb_bin_to_band.short_stride = shr( tmp, sub( 15, exp ) + 2 ); + pFb->fb_bin_to_band.short_stride = shr( tmp, add( sub( 15, exp ), 2 ) ); move16(); @@ -2710,58 +1795,6 @@ static ivas_error ivas_filterbank_setup_fx( * *-----------------------------------------------------------------------------------------*/ -static ivas_error ivas_fb_mixer_get_window( - const int16_t fade_len, /* i : window fading length in samples */ - const int32_t sampling_rate, /* i : sampling rate */ - const float **pWindow /* o : pointer to the window coefficents */ -) -{ - ivas_error error; - - error = IVAS_ERR_OK; - - if ( fade_len == NS2SA( sampling_rate, DELAY_FB_4_NS ) ) - { - switch ( sampling_rate ) - { - case 48000: - *pWindow = ivas_fb_cf_4ms_48k; - break; - case 32000: - *pWindow = ivas_fb_cf_4ms_32k; - break; - case 16000: - *pWindow = ivas_fb_cf_4ms_16k; - break; - default: - return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Unsupported Sampling frequency!" ); - } - } - else if ( fade_len == NS2SA( sampling_rate, DELAY_FB_1_NS ) ) - { - switch ( sampling_rate ) - { - case 48000: - *pWindow = ivas_fb_cf_1ms_48k; - break; - case 32000: - *pWindow = ivas_fb_cf_1ms_32k; - break; - case 16000: - *pWindow = ivas_fb_cf_1ms_16k; - break; - default: - return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Unsupported Sampling frequency!" ); - } - } - else - { - IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Error: Incorrect FB window fade len (%f ms)\n", ( fade_len / 1000000.f ) ); - } - - return error; -} - #ifdef IVAS_FLOAT_FIXED static ivas_error ivas_fb_mixer_get_window_fx( const Word16 fade_len, /* i : window fading length in samples */ @@ -2818,26 +1851,6 @@ static ivas_error ivas_fb_mixer_get_window_fx( #endif -static const float *ivas_get_cheby_ramp( - const int16_t delay ) -{ - const float *pCheby = NULL; - - switch ( delay ) - { - case IVAS_FB_1MS_32K_SAMP: - pCheby = ivas_fb_resp_cheby_ramp_32del; - break; - case IVAS_FB_1MS_16K_SAMP: - pCheby = ivas_fb_resp_cheby_ramp_16del; - break; - default: - assert( !"Unsupported cheby ramp length!" ); - } - - return pCheby; -} - #ifdef IVAS_FLOAT_FIXED static const Word32 *ivas_get_cheby_ramp_fx( const Word16 delay ) @@ -2860,139 +1873,6 @@ static const Word32 *ivas_get_cheby_ramp_fx( } #endif - -/*get first half of the hanning window*/ -static void ivas_get_hanning_win( - const int16_t len, - float *pH_win ) -{ - int16_t i; - - for ( i = 0; i < len; i++ ) - { - pH_win[i] = 0.5f * ( 1.0f - cosf( ( PI2 * ( i + 1 ) ) / ( ( 2 * len ) + 1 ) ) ); - } - - return; -} - - -static void ivas_get_ld_fb_resp( - float **ppIdeal_FRs_re, - float **ppIdeal_FRs_im, - float **ppNew_FRs_re, - float **ppNew_FRs_im, - const int16_t *pActive_bins, - const int16_t *pStart_offset, - const int16_t num_bands, - const int16_t delay, - const int32_t sampling_rate ) -{ - int16_t b, s, frame_len; - const float *pCheby; - - /*common scratch buffers for computing impulse/frequency responses, - pre-ring, post-ring and circular shifted outputs to optimize stack*/ - float scratch1[L_FRAME32k * 2]; - float scratch2[L_FRAME32k * 2]; - float han_win[L_FRAME32k]; - - frame_len = (int16_t) ( sampling_rate / FRAMES_PER_SEC ); - pCheby = ivas_get_cheby_ramp( delay ); - b = 0; - s = 0; - - assert( sampling_rate == 32000 || sampling_rate == 16000 ); - - ivas_get_hanning_win( frame_len, han_win ); - for ( b = 0; b < num_bands; b++ ) - { - set_f( scratch2, 0, frame_len << 1 ); - mvr2r( ppIdeal_FRs_re[b], &scratch2[pStart_offset[b]], pActive_bins[b] ); - mvr2r( ppIdeal_FRs_im[b], &scratch2[frame_len + pStart_offset[b]], pActive_bins[b] ); - ivas_imdft( scratch2, &scratch2[frame_len], scratch1, frame_len ); - - /*apply circular shift and hanning window*/ - - for ( s = delay; s < frame_len + delay; s++ ) - { - scratch2[s - delay] = scratch1[s] * ( 1 - han_win[s - delay] ); - } - - for ( ; s < 2 * frame_len; s++ ) - { - scratch2[s - delay] = scratch1[s] * han_win[s - ( frame_len + delay )]; - } - - for ( s = 0; s < delay; s++ ) - { - scratch2[2 * frame_len - delay + s] = -1 * scratch1[s] * han_win[frame_len - delay + s]; - } - - /*apply heavy/cheby ramp window and compute pre ring*/ - - for ( s = 0; s < delay + 1; s++ ) - { - scratch1[s] = scratch2[s] * pCheby[delay - s]; - } - - for ( ; s < frame_len; s++ ) - { - scratch1[s] = 0; - } - - for ( ; s < 2 * frame_len - delay; s++ ) - { - scratch1[s] = scratch2[s]; - } - - for ( ; s < 2 * frame_len; s++ ) - { - scratch1[s] = scratch2[s] * ( 1 - pCheby[s - ( 2 * frame_len - delay )] ); - } - - /*IR - pre ring + post ring*/ - for ( s = 1; s < 2 * frame_len; s++ ) - { - scratch2[s] = scratch2[s] /*pre ring*/ - scratch1[s] /*post ring*/ - scratch1[( 2 * frame_len ) - s]; - } - - for ( s = 0; s < 2 * frame_len - delay; s++ ) - { - scratch1[s + delay] = scratch2[s]; - } - - for ( ; s < 2 * frame_len; s++ ) - { - scratch1[s - ( 2 * frame_len - delay )] = -1 * ( scratch2[s] ); - } - - /* apply final window*/ - for ( s = 0; s < delay; s++ ) - { - scratch1[s] = scratch1[s] * sinf( ( EVS_PI * ( s + 1 ) ) / ( 2 * delay ) ); - } - - for ( s = 2 * delay; s < frame_len + 1; s++ ) - { - scratch1[s] = scratch1[s] * sinf( ( EVS_PI * ( frame_len - s ) ) / ( 2 * ( frame_len + 1 - ( 2 * delay ) ) ) ); - } - - for ( ; s < 2 * frame_len; s++ ) - { - scratch1[s] = 0; - } - - /*compute frequency response*/ - ivas_mdft( scratch1, scratch2, &scratch2[frame_len], frame_len << 1, frame_len ); - - mvr2r( &scratch2[pStart_offset[b]], ppNew_FRs_re[b], pActive_bins[b] ); - mvr2r( &scratch2[frame_len + pStart_offset[b]], ppNew_FRs_im[b], pActive_bins[b] ); - } - - return; -} - #ifdef IVAS_FLOAT_FIXED static void ivas_get_ld_fb_resp_fx( Word32 **ppIdeal_FRs_re_fx, diff --git a/lib_com/ivas_mc_param_com.c b/lib_com/ivas_mc_param_com.c index dc26644b9..a20b9b3af 100644 --- a/lib_com/ivas_mc_param_com.c +++ b/lib_com/ivas_mc_param_com.c @@ -51,10 +51,11 @@ * Local function prototypes *------------------------------------------------------------------------*/ -static void ivas_param_mc_set_coding_scheme( const MC_LS_SETUP mc_ls_setup, const int32_t ivas_total_brate, HANDLE_IVAS_PARAM_MC_METADATA hMetadataPMC ); #ifdef IVAS_FLOAT_FIXED static void ivas_param_mc_set_coding_scheme_fx( const MC_LS_SETUP mc_ls_setup, const Word32 ivas_total_brate, HANDLE_IVAS_PARAM_MC_METADATA hMetadataPMC ); +#else +static void ivas_param_mc_set_coding_scheme( const MC_LS_SETUP mc_ls_setup, const int32_t ivas_total_brate, HANDLE_IVAS_PARAM_MC_METADATA hMetadataPMC ); #endif /*------------------------------------------------------------------------- @@ -195,12 +196,11 @@ void ivas_param_mc_metadata_open_fx( return; } -#endif - +#else void ivas_param_mc_metadata_open( - const MC_LS_SETUP mc_ls_setup, /* i : MC ls setup */ + const MC_LS_SETUP mc_ls_setup, /* i : MC ls setup */ #ifndef FIX_901_PARAMMC_DEAD_CODE - const int16_t lfe_index, /* i : channel index of LFE */ + const int16_t lfe_index, /* i : channel index of LFE */ #endif const int32_t ivas_total_brate, /* i : IVAS total bitrate */ HANDLE_IVAS_PARAM_MC_METADATA hMetadataPMC /* o : handle for the Parametric MC parameter coding state */ @@ -253,9 +253,10 @@ void ivas_param_mc_metadata_open( #endif hMetadataPMC->icc_mapping_conf = ivas_param_mc_conf[config_index].icc_mapping_conf; hMetadataPMC->ild_mapping_conf = ivas_param_mc_conf[config_index].ild_mapping_conf; - hMetadataPMC->ild_factors = ivas_param_mc_conf[config_index].ild_factors; #ifdef IVAS_FLOAT_FIXED hMetadataPMC->ild_factors_fx = ivas_param_mc_conf[config_index].ild_factors_fx; /*Q15*/ +#else + hMetadataPMC->ild_factors = ivas_param_mc_conf[config_index].ild_factors; #endif #ifndef FIX_901_PARAMMC_DEAD_CODE @@ -282,6 +283,7 @@ void ivas_param_mc_metadata_open( return; } +#endif /*------------------------------------------------------------------------- * ivas_param_mc_set_coded_bands() @@ -924,8 +926,7 @@ static void ivas_param_mc_set_coding_scheme_fx( return; } -#endif - +#else static void ivas_param_mc_set_coding_scheme( const MC_LS_SETUP mc_ls_setup, /* i : MC ls setup */ const int32_t ivas_total_brate, /* i : IVAS total bitrate */ @@ -941,10 +942,11 @@ static void ivas_param_mc_set_coding_scheme( hMetadataPMC->icc_coding.sym_freq = &ivas_param_mc_sym_freq_icc_cicp6_48_16bits[0]; hMetadataPMC->icc_coding.cum_freq_delta = &ivas_param_mc_cum_freq_icc_delta_cicp6_48_16bits[0]; hMetadataPMC->icc_coding.sym_freq_delta = &ivas_param_mc_sym_freq_icc_delta_cicp6_48_16bits[0]; - hMetadataPMC->icc_coding.quantizer = &ivas_param_mc_quant_icc[0]; hMetadataPMC->icc_coding.quantizer_size = PARAM_MC_SZ_ICC_QUANTIZER; #ifdef IVAS_FLOAT_FIXED hMetadataPMC->icc_coding.quantizer_fx = &ivas_param_mc_quant_icc_fx[0]; +#else + hMetadataPMC->icc_coding.quantizer = &ivas_param_mc_quant_icc[0]; #endif hMetadataPMC->icc_coding.uni_bits = PARAM_MC_NUM_BITS_ICC_SCALAR_QUANT; /* ILD */ @@ -952,9 +954,10 @@ static void ivas_param_mc_set_coding_scheme( hMetadataPMC->ild_coding.sym_freq = &ivas_param_mc_sym_freq_ild_cicp6_48_16bits[0]; hMetadataPMC->ild_coding.cum_freq_delta = &ivas_param_mc_cum_freq_ild_delta_cicp6_48_16bits[0]; hMetadataPMC->ild_coding.sym_freq_delta = &ivas_param_mc_sym_freq_ild_delta_cicp6_48_16bits[0]; - hMetadataPMC->ild_coding.quantizer = &ivas_param_mc_quant_ild_5d1_48[0]; #ifdef IVAS_FLOAT_FIXED hMetadataPMC->ild_coding.quantizer_fx = &ivas_param_mc_quant_ild_5d1_48_fx[0]; +#else + hMetadataPMC->ild_coding.quantizer = &ivas_param_mc_quant_ild_5d1_48[0]; #endif hMetadataPMC->ild_coding.quantizer_size = PARAM_MC_SZ_ILD_QUANTIZER_4BITS; hMetadataPMC->ild_coding.uni_bits = PARAM_MC_NUM_BITS_ILD_SCALAR_QUANT; @@ -965,9 +968,10 @@ static void ivas_param_mc_set_coding_scheme( hMetadataPMC->icc_coding.sym_freq = &ivas_param_mc_sym_freq_icc_cicp12_48_16bits[0]; hMetadataPMC->icc_coding.cum_freq_delta = &ivas_param_mc_cum_freq_icc_delta_cicp12_48_16bits[0]; hMetadataPMC->icc_coding.sym_freq_delta = &ivas_param_mc_sym_freq_icc_delta_cicp12_48_16bits[0]; - hMetadataPMC->icc_coding.quantizer = &ivas_param_mc_quant_icc[0]; #ifdef IVAS_FLOAT_FIXED hMetadataPMC->icc_coding.quantizer_fx = &ivas_param_mc_quant_icc_fx[0]; // Q15 +#else + hMetadataPMC->icc_coding.quantizer = &ivas_param_mc_quant_icc[0]; #endif hMetadataPMC->icc_coding.quantizer_size = PARAM_MC_SZ_ICC_QUANTIZER; hMetadataPMC->icc_coding.uni_bits = PARAM_MC_NUM_BITS_ICC_SCALAR_QUANT; @@ -976,9 +980,10 @@ static void ivas_param_mc_set_coding_scheme( hMetadataPMC->ild_coding.sym_freq = &ivas_param_mc_sym_freq_ild_cicp12_48_16bits[0]; hMetadataPMC->ild_coding.cum_freq_delta = &ivas_param_mc_cum_freq_ild_delta_cicp12_48_16bits[0]; hMetadataPMC->ild_coding.sym_freq_delta = &ivas_param_mc_sym_freq_ild_delta_cicp12_48_16bits[0]; - hMetadataPMC->ild_coding.quantizer = &ivas_param_mc_quant_ild_5d1_48[0]; #ifdef IVAS_FLOAT_FIXED hMetadataPMC->ild_coding.quantizer_fx = &ivas_param_mc_quant_ild_5d1_48_fx[0]; // Q8 +#else + hMetadataPMC->ild_coding.quantizer = &ivas_param_mc_quant_ild_5d1_48[0]; #endif hMetadataPMC->ild_coding.quantizer_size = PARAM_MC_SZ_ILD_QUANTIZER_4BITS; hMetadataPMC->ild_coding.uni_bits = PARAM_MC_NUM_BITS_ILD_SCALAR_QUANT; @@ -989,9 +994,10 @@ static void ivas_param_mc_set_coding_scheme( hMetadataPMC->icc_coding.sym_freq = &ivas_param_mc_sym_freq_icc_cicp14_48_16bits[0]; hMetadataPMC->icc_coding.cum_freq_delta = &ivas_param_mc_cum_freq_icc_delta_cicp14_48_16bits[0]; hMetadataPMC->icc_coding.sym_freq_delta = &ivas_param_mc_sym_freq_icc_delta_cicp14_48_16bits[0]; - hMetadataPMC->icc_coding.quantizer = &ivas_param_mc_quant_icc[0]; #ifdef IVAS_FLOAT_FIXED hMetadataPMC->icc_coding.quantizer_fx = &ivas_param_mc_quant_icc_fx[0]; // Q15 +#else + hMetadataPMC->icc_coding.quantizer = &ivas_param_mc_quant_icc[0]; #endif hMetadataPMC->icc_coding.quantizer_size = PARAM_MC_SZ_ICC_QUANTIZER; hMetadataPMC->icc_coding.uni_bits = PARAM_MC_NUM_BITS_ICC_SCALAR_QUANT; @@ -1000,9 +1006,10 @@ static void ivas_param_mc_set_coding_scheme( hMetadataPMC->ild_coding.sym_freq = &ivas_param_mc_sym_freq_ild_cicp14_48_16bits[0]; hMetadataPMC->ild_coding.cum_freq_delta = &ivas_param_mc_cum_freq_ild_delta_cicp14_48_16bits[0]; hMetadataPMC->ild_coding.sym_freq_delta = &ivas_param_mc_sym_freq_ild_delta_cicp14_48_16bits[0]; - hMetadataPMC->ild_coding.quantizer = &ivas_param_mc_quant_ild_5d1_48[0]; #ifdef IVAS_FLOAT_FIXED hMetadataPMC->ild_coding.quantizer_fx = &ivas_param_mc_quant_ild_5d1_48_fx[0]; // Q8 +#else + hMetadataPMC->ild_coding.quantizer = &ivas_param_mc_quant_ild_5d1_48[0]; #endif hMetadataPMC->ild_coding.quantizer_size = PARAM_MC_SZ_ILD_QUANTIZER_4BITS; hMetadataPMC->ild_coding.uni_bits = PARAM_MC_NUM_BITS_ILD_SCALAR_QUANT; @@ -1014,9 +1021,10 @@ static void ivas_param_mc_set_coding_scheme( hMetadataPMC->icc_coding.sym_freq = &ivas_param_mc_sym_freq_icc_combined_48_16bits[0]; hMetadataPMC->icc_coding.cum_freq_delta = &ivas_param_mc_cum_freq_icc_delta_combined_48_16bits[0]; hMetadataPMC->icc_coding.sym_freq_delta = &ivas_param_mc_sym_freq_icc_delta_combined_48_16bits[0]; - hMetadataPMC->icc_coding.quantizer = &ivas_param_mc_quant_icc[0]; #ifdef IVAS_FLOAT_FIXED hMetadataPMC->icc_coding.quantizer_fx = &ivas_param_mc_quant_icc_fx[0]; // Q15 +#else + hMetadataPMC->icc_coding.quantizer = &ivas_param_mc_quant_icc[0]; #endif hMetadataPMC->icc_coding.quantizer_size = PARAM_MC_SZ_ICC_QUANTIZER; hMetadataPMC->icc_coding.uni_bits = PARAM_MC_NUM_BITS_ICC_SCALAR_QUANT; @@ -1025,9 +1033,10 @@ static void ivas_param_mc_set_coding_scheme( hMetadataPMC->ild_coding.sym_freq = &ivas_param_mc_sym_freq_ild_combined_48_16bits[0]; hMetadataPMC->ild_coding.cum_freq_delta = &ivas_param_mc_cum_freq_ild_delta_combined_48_16bits[0]; hMetadataPMC->ild_coding.sym_freq_delta = &ivas_param_mc_sym_freq_ild_delta_combined_48_16bits[0]; - hMetadataPMC->ild_coding.quantizer = &ivas_param_mc_quant_ild_5d1_48[0]; #ifdef IVAS_FLOAT_FIXED hMetadataPMC->ild_coding.quantizer_fx = &ivas_param_mc_quant_ild_5d1_48_fx[0]; // Q8 +#else + hMetadataPMC->ild_coding.quantizer = &ivas_param_mc_quant_ild_5d1_48[0]; #endif hMetadataPMC->ild_coding.quantizer_size = PARAM_MC_SZ_ILD_QUANTIZER_4BITS; hMetadataPMC->ild_coding.uni_bits = PARAM_MC_NUM_BITS_ILD_SCALAR_QUANT; @@ -1040,3 +1049,4 @@ static void ivas_param_mc_set_coding_scheme( return; } +#endif diff --git a/lib_com/ivas_mdct_imdct.c b/lib_com/ivas_mdct_imdct.c index d4e756775..2d0c824e3 100644 --- a/lib_com/ivas_mdct_imdct.c +++ b/lib_com/ivas_mdct_imdct.c @@ -39,6 +39,7 @@ #include "wmc_auto.h" +#ifndef IVAS_FLOAT_FIXED /*------------------------------------------------------------------------------------------* * Local constants *------------------------------------------------------------------------------------------*/ @@ -56,7 +57,6 @@ * Time domain aliasing *-----------------------------------------------------------------------------------------*/ -#ifndef IVAS_FLOAT_FIXED void ivas_tda( const float *pIn, /* i : time domain buffer of size 2*length */ float *pOut, /* o : time domain buffer of size length */ @@ -74,7 +74,6 @@ void ivas_tda( return; } -#endif /*-----------------------------------------------------------------------------------------* * Function ivas_dct_windowing() @@ -378,3 +377,4 @@ float ivas_get_mdct_scaling_gain( return gain; } +#endif diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index d845d8778..6b5cf7868 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -4043,7 +4043,6 @@ void ivas_mc_paramupmix_dec_render( float *input_f[], /* i : core-coder transport channels */ float *output_f[] /* i/o: synthesized core-coder transport channels */ ); -#endif void ivas_param_mc_metadata_open( const MC_LS_SETUP mc_ls_setup, /* i : MC ls setup */ #ifndef FIX_901_PARAMMC_DEAD_CODE @@ -4052,6 +4051,7 @@ void ivas_param_mc_metadata_open( const int32_t ivas_total_brate, /* i : IVAS total bitrate */ HANDLE_IVAS_PARAM_MC_METADATA hMetadataPMC /* o : handle for the Parametric MC parameter coding state */ ); +#endif void ivas_param_mc_set_coded_bands( HANDLE_IVAS_PARAM_MC_METADATA hMetadataPMC /* i/o: handle for the Parametric MC parameter coding state */ @@ -4459,12 +4459,14 @@ void ivas_spar_agc_dec_close( ivas_agc_dec_state_t **hAgcDec /* i/o: AGC decoder handle */ ); +#ifndef IVAS_FLOAT_FIXED ivas_error ivas_spar_md_enc_init ( ivas_spar_md_enc_state_t *hMdEnc, /* o : MD encoder handle */ const ENCODER_CONFIG_HANDLE hEncoderConfig, /* i : configuration structure */ const int16_t sba_order /* i : Ambisonic (SBA) order */ ); +#endif void ivas_agc_dec_process( ivas_agc_dec_state_t *hAgcDec, /* i/o: AGC decoder handle */ @@ -4522,6 +4524,7 @@ int16_t ivas_get_sba_num_TCs( const int16_t sba_order /* i : IVAS SBA order */ ); +#ifndef IVAS_FLOAT_FIXED void ivas_spar_set_bitrate_config( ivas_spar_md_com_cfg *pSpar_md_cfg, /* i/o: SPAR MD config. handle */ const int16_t table_idx, /* i : config. table index */ @@ -4531,6 +4534,7 @@ void ivas_spar_set_bitrate_config( const int16_t pca_flag, const int16_t agc_flag ); +#endif void ivas_spar_bitrate_dist( int32_t core_brates_act[], /* o : bitrates per core-coder */ @@ -4939,15 +4943,6 @@ void ivas_pca_enc_init( PCA_ENC_STATE *hPCA /* i/o: PCA encoder structure */ ); -void ivas_pca_enc( - const ENCODER_CONFIG_HANDLE hEncoderConfig, /* i : configuration structure */ - PCA_ENC_STATE *hPCA, /* i : PCA encoder structure */ - BSTR_ENC_HANDLE hMetaData, /* i/o: MetaData handle */ - float *data_f[8], /* i : input/transformed audio channels */ - const int16_t input_frame, /* i : input frame length */ - const int16_t n_channels /* i : number of channels */ -); - void ivas_pca_read_bits( Decoder_State *st0, /* i/o: decoder state structure - for bitstream handling*/ PCA_DEC_STATE *hPCA /* i/o: PCA encoder structure */ @@ -5156,10 +5151,12 @@ void ivas_quantise_real_values( const int16_t dim ); +#ifndef IVAS_FLOAT_FIXED void ivas_spar_get_uniform_quant_strat( ivas_spar_md_com_cfg *pSpar_md_com_cfg, const int16_t table_idx ); +#endif void ivas_spar_quant_dtx_init( ivas_spar_md_t *spar_md, @@ -6202,19 +6199,6 @@ ivas_error ivas_fb_set_cfg( const int16_t nachan_dirac_ana /* i : number of DirAR analysis channels */ ); -ivas_error ivas_FB_mixer_open( - IVAS_FB_MIXER_HANDLE *hFbMixer, /* i/o: FB mixer handle */ - const int32_t sampling_rate, /* i : sampling rate */ - IVAS_FB_CFG *fb_cfg, /* i : FB config. handle */ - const int16_t spar_reconfig_flag /* i : SPAR reconfiguration flag */ -); - -void ivas_FB_mixer_close( - IVAS_FB_MIXER_HANDLE *hFbMixer, /* i/o: FB mixer handle */ - const int32_t sampling_rate, /* i : sampling rate in Hz */ - const int16_t spar_reconfig_flag /* i : SPAR reconfiguration flag */ -); - void ivas_fb_mixer_pcm_ingest( IVAS_FB_MIXER_HANDLE hFbMixer, /* i/o: FB mixer handle */ float *pcm_in[], /* i : input audio channels */ @@ -6240,21 +6224,6 @@ void ivas_fb_mixer_get_windowed_fr( const int16_t nchan_fb_in /* i : number of analysis channels */ ); -void ivas_fb_mixer_get_in_out_mapping( - const IVAS_FB_CFG *fb_cfg, /* i : FB config. handle */ - int16_t in_out_mixer_map[IVAS_MAX_FB_MIXER_OUT_CH][IVAS_MAX_SPAR_FB_MIXER_IN_CH] /* i/o: mixing mapping */ -); - -void ivas_fb_mixer_cross_fading( - IVAS_FB_MIXER_HANDLE hFbMixer, - float **ppOut_pcm, - float *pMdft_out_old, - float *pMdft_out_new, - const int16_t ch, - const int16_t frame_len, - const int16_t cf_offset -); - /*! r: number of spectral bands */ #ifndef IVAS_FLOAT_FIXED int16_t ivas_get_num_bands_from_bw_idx( diff --git a/lib_com/ivas_prot_fx.h b/lib_com/ivas_prot_fx.h index 5d1a5137a..b93158e31 100644 --- a/lib_com/ivas_prot_fx.h +++ b/lib_com/ivas_prot_fx.h @@ -2438,6 +2438,11 @@ void ivas_FB_mixer_close_fx( const Word16 spar_reconfig_flag /* i : SPAR reconfiguration flag */ ); +void ivas_fb_mixer_get_in_out_mapping_fx( + const IVAS_FB_CFG *fb_cfg, /* i : FB config. handle */ + Word16 in_out_mixer_map[IVAS_MAX_FB_MIXER_OUT_CH][IVAS_MAX_SPAR_FB_MIXER_IN_CH] /* i/o: mixing mapping */ +); + void ivas_fb_mixer_cross_fading_fx( IVAS_FB_MIXER_HANDLE hFbMixer, Word32 **ppOut_pcm_fx, @@ -3826,10 +3831,10 @@ void ivas_fb_mixer_pcm_ingest_fx( Word32 **ppOut_pcm, /* o : output audio channels Qq_ppOut_pcm[] */ const Word16 frame_len, /* i : frame length */ const Word16 HOA_md_ind[IVAS_SPAR_MAX_CH], - Word16 q_data_fix[MAX_INPUT_CHANNELS + MAX_NUM_OBJECTS], + Word16 q_data_fix, Word16 *q_ppOut_pcm ); -void ivas_fb_mixer_process( +void ivas_fb_mixer_process_fx( IVAS_FB_MIXER_HANDLE hFbMixer, /* i/o: FB mixer handle */ Word32 ***mixer_mat_fx, /* i : mixer matrix in q_mixer_mat_fx */ Word16 *q_mixer_mat_fx, /* i : mixer matrix */ @@ -5311,6 +5316,10 @@ ivas_error ivas_spar_md_enc_open_fx( const Word16 sba_order /* i : Ambisonic (SBA) order */ ); +void ivas_spar_md_enc_close_fx( + ivas_spar_md_enc_state_t **hMdEnc /* i/o: SPAR MD encoder handle */ +); + void ivas_create_fullr_dmx_mat_fx( Word32 pred_coeffs_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], /*q_pred_coeffs_re*/ Word16 q_pred_coeffs_re, diff --git a/lib_com/ivas_rom_com.c b/lib_com/ivas_rom_com.c index 805900f8f..20529b3d4 100644 --- a/lib_com/ivas_rom_com.c +++ b/lib_com/ivas_rom_com.c @@ -2680,11 +2680,12 @@ const PARAM_MC_CONF ivas_param_mc_conf[PARAM_MC_NUM_CONFIGS] = IVAS_48k, &ivas_param_mc_ild_mapping_CICP6_2tc, &ivas_param_mc_icc_mapping_CICP6_2tc, - &ivas_param_mc_dmx_fac_CICP6_2tc[0], - &ivas_param_mc_ild_fac_CICP6_2tc[0], #ifdef IVAS_FLOAT_FIXED &ivas_param_mc_ild_fac_CICP6_2tc_fx[0], &ivas_param_mc_dmx_fac_CICP6_2tc_fx[0] +#else + &ivas_param_mc_ild_fac_CICP6_2tc[0], + &ivas_param_mc_dmx_fac_CICP6_2tc[0], #endif }, /* CICP6 64000 */ @@ -2695,11 +2696,12 @@ const PARAM_MC_CONF ivas_param_mc_conf[PARAM_MC_NUM_CONFIGS] = IVAS_64k, &ivas_param_mc_ild_mapping_CICP6_2tc, &ivas_param_mc_icc_mapping_CICP6_2tc, - &ivas_param_mc_dmx_fac_CICP6_2tc[0], - &ivas_param_mc_ild_fac_CICP6_2tc[0], #ifdef IVAS_FLOAT_FIXED &ivas_param_mc_ild_fac_CICP6_2tc_fx[0], & ivas_param_mc_dmx_fac_CICP6_2tc_fx[0] +#else + &ivas_param_mc_ild_fac_CICP6_2tc[0], + &ivas_param_mc_dmx_fac_CICP6_2tc[0], #endif }, /* CICP6 80000 */ @@ -2710,11 +2712,12 @@ const PARAM_MC_CONF ivas_param_mc_conf[PARAM_MC_NUM_CONFIGS] = IVAS_80k, &ivas_param_mc_ild_mapping_CICP6_2tc, &ivas_param_mc_icc_mapping_CICP6_2tc, - &ivas_param_mc_dmx_fac_CICP6_2tc[0], - &ivas_param_mc_ild_fac_CICP6_2tc[0], #ifdef IVAS_FLOAT_FIXED &ivas_param_mc_ild_fac_CICP6_2tc_fx[0], & ivas_param_mc_dmx_fac_CICP6_2tc_fx[0] +#else + &ivas_param_mc_ild_fac_CICP6_2tc[0], + &ivas_param_mc_dmx_fac_CICP6_2tc[0], #endif }, /* CICP12 48000 */ @@ -2725,11 +2728,12 @@ const PARAM_MC_CONF ivas_param_mc_conf[PARAM_MC_NUM_CONFIGS] = IVAS_48k, &ivas_param_mc_ild_mapping_CICP12_2tc, &ivas_param_mc_icc_mapping_CICP12_2tc, - &ivas_param_mc_dmx_fac_CICP12_2tc[0], - &ivas_param_mc_ild_fac_CICP12_2tc[0], #ifdef IVAS_FLOAT_FIXED &ivas_param_mc_ild_fac_CICP12_2tc_fx[0], &ivas_param_mc_dmx_fac_CICP12_2tc_fx[0] +#else + &ivas_param_mc_ild_fac_CICP12_2tc[0], + &ivas_param_mc_dmx_fac_CICP12_2tc[0], #endif }, /* CICP12 64000 */ @@ -2740,11 +2744,12 @@ const PARAM_MC_CONF ivas_param_mc_conf[PARAM_MC_NUM_CONFIGS] = IVAS_64k, &ivas_param_mc_ild_mapping_CICP12_2tc, &ivas_param_mc_icc_mapping_CICP12_2tc, - &ivas_param_mc_dmx_fac_CICP12_2tc[0], - &ivas_param_mc_ild_fac_CICP12_2tc[0], #ifdef IVAS_FLOAT_FIXED &ivas_param_mc_ild_fac_CICP12_2tc_fx[0], &ivas_param_mc_dmx_fac_CICP12_2tc_fx[0] +#else + &ivas_param_mc_ild_fac_CICP12_2tc[0], + &ivas_param_mc_dmx_fac_CICP12_2tc[0], #endif }, /* CICP12 80000 */ @@ -2755,11 +2760,12 @@ const PARAM_MC_CONF ivas_param_mc_conf[PARAM_MC_NUM_CONFIGS] = IVAS_80k, &ivas_param_mc_ild_mapping_CICP12_2tc, &ivas_param_mc_icc_mapping_CICP12_2tc, - &ivas_param_mc_dmx_fac_CICP12_2tc[0], - &ivas_param_mc_ild_fac_CICP12_2tc[0], #ifdef IVAS_FLOAT_FIXED &ivas_param_mc_ild_fac_CICP12_2tc_fx[0], &ivas_param_mc_dmx_fac_CICP12_2tc_fx[0], +#else + &ivas_param_mc_ild_fac_CICP12_2tc[0], + &ivas_param_mc_dmx_fac_CICP12_2tc[0], #endif }, /* CICP12 96000 */ @@ -2770,11 +2776,12 @@ const PARAM_MC_CONF ivas_param_mc_conf[PARAM_MC_NUM_CONFIGS] = IVAS_96k, &ivas_param_mc_ild_mapping_CICP12_3tc, &ivas_param_mc_icc_mapping_CICP12_3tc, - &ivas_param_mc_dmx_fac_CICP12_3tc[0], - &ivas_param_mc_ild_fac_CICP12_3tc[0], #ifdef IVAS_FLOAT_FIXED &ivas_param_mc_ild_fac_CICP12_3tc_fx[0], &ivas_param_mc_dmx_fac_CICP12_3tc_fx[0] +#else + &ivas_param_mc_ild_fac_CICP12_3tc[0], + &ivas_param_mc_dmx_fac_CICP12_3tc[0], #endif }, /* CICP14 48000 */ @@ -2785,11 +2792,12 @@ const PARAM_MC_CONF ivas_param_mc_conf[PARAM_MC_NUM_CONFIGS] = IVAS_48k, &ivas_param_mc_ild_mapping_CICP14_2tc, &ivas_param_mc_icc_mapping_CICP14_2tc, - &ivas_param_mc_dmx_fac_CICP14_2tc[0], - &ivas_param_mc_ild_fac_CICP14_2tc[0], #ifdef IVAS_FLOAT_FIXED &ivas_param_mc_ild_fac_CICP14_2tc_fx[0], &ivas_param_mc_dmx_fac_CICP14_2tc_fx[0] +#else + &ivas_param_mc_ild_fac_CICP14_2tc[0], + &ivas_param_mc_dmx_fac_CICP14_2tc[0], #endif }, /* CICP14 64000 */ @@ -2800,11 +2808,12 @@ const PARAM_MC_CONF ivas_param_mc_conf[PARAM_MC_NUM_CONFIGS] = IVAS_64k, &ivas_param_mc_ild_mapping_CICP14_2tc, &ivas_param_mc_icc_mapping_CICP14_2tc, - &ivas_param_mc_dmx_fac_CICP14_2tc[0], - &ivas_param_mc_ild_fac_CICP14_2tc[0], #ifdef IVAS_FLOAT_FIXED &ivas_param_mc_ild_fac_CICP14_2tc_fx[0], &ivas_param_mc_dmx_fac_CICP14_2tc_fx[0] +#else + &ivas_param_mc_ild_fac_CICP14_2tc[0], + &ivas_param_mc_dmx_fac_CICP14_2tc[0], #endif }, /* CICP14 80000 */ @@ -2815,11 +2824,12 @@ const PARAM_MC_CONF ivas_param_mc_conf[PARAM_MC_NUM_CONFIGS] = IVAS_80k, &ivas_param_mc_ild_mapping_CICP14_2tc, &ivas_param_mc_icc_mapping_CICP14_2tc, - &ivas_param_mc_dmx_fac_CICP14_2tc[0], - &ivas_param_mc_ild_fac_CICP14_2tc[0], #ifdef IVAS_FLOAT_FIXED &ivas_param_mc_ild_fac_CICP14_2tc_fx[0], - & ivas_param_mc_dmx_fac_CICP14_2tc_fx[0] + &ivas_param_mc_dmx_fac_CICP14_2tc_fx[0] +#else + &ivas_param_mc_ild_fac_CICP14_2tc[0], + &ivas_param_mc_dmx_fac_CICP14_2tc[0], #endif }, /* CICP14 96000 */ @@ -2830,11 +2840,12 @@ const PARAM_MC_CONF ivas_param_mc_conf[PARAM_MC_NUM_CONFIGS] = IVAS_96k, &ivas_param_mc_ild_mapping_CICP14_3tc, &ivas_param_mc_icc_mapping_CICP14_3tc, - &ivas_param_mc_dmx_fac_CICP14_3tc[0], - &ivas_param_mc_ild_fac_CICP14_3tc[0], #ifdef IVAS_FLOAT_FIXED &ivas_param_mc_ild_fac_CICP14_3tc_fx[0], - & ivas_param_mc_dmx_fac_CICP14_3tc_fx[0] + &ivas_param_mc_dmx_fac_CICP14_3tc_fx[0] +#else + &ivas_param_mc_ild_fac_CICP14_3tc[0], + &ivas_param_mc_dmx_fac_CICP14_3tc[0], #endif }, /* CICP16 96000 */ @@ -2845,11 +2856,12 @@ const PARAM_MC_CONF ivas_param_mc_conf[PARAM_MC_NUM_CONFIGS] = IVAS_96k, &ivas_param_mc_ild_mapping_CICP16_3tc, &ivas_param_mc_icc_mapping_CICP16_3tc, - &ivas_param_mc_dmx_fac_CICP16_3tc[0], - &ivas_param_mc_ild_fac_CICP16_3tc[0], #ifdef IVAS_FLOAT_FIXED &ivas_param_mc_ild_fac_CICP16_3tc_fx[0], - & ivas_param_mc_dmx_fac_CICP16_3tc_fx[0] + &ivas_param_mc_dmx_fac_CICP16_3tc_fx[0] +#else + &ivas_param_mc_ild_fac_CICP16_3tc[0], + &ivas_param_mc_dmx_fac_CICP16_3tc[0], #endif }, /* CICP16 128000 */ @@ -2860,11 +2872,12 @@ const PARAM_MC_CONF ivas_param_mc_conf[PARAM_MC_NUM_CONFIGS] = IVAS_128k, &ivas_param_mc_ild_mapping_CICP16_3tc, &ivas_param_mc_icc_mapping_CICP16_3tc, - &ivas_param_mc_dmx_fac_CICP16_3tc[0], - &ivas_param_mc_ild_fac_CICP16_3tc[0], #ifdef IVAS_FLOAT_FIXED &ivas_param_mc_ild_fac_CICP16_3tc_fx[0], - & ivas_param_mc_dmx_fac_CICP16_3tc_fx[0] + &ivas_param_mc_dmx_fac_CICP16_3tc_fx[0] +#else + &ivas_param_mc_ild_fac_CICP16_3tc[0], + &ivas_param_mc_dmx_fac_CICP16_3tc[0], #endif }, /* CICP19 128000 */ @@ -2875,11 +2888,12 @@ const PARAM_MC_CONF ivas_param_mc_conf[PARAM_MC_NUM_CONFIGS] = IVAS_128k, &ivas_param_mc_ild_mapping_CICP19_3tc, &ivas_param_mc_icc_mapping_CICP19_3tc, - &ivas_param_mc_dmx_fac_CICP19_3tc[0], - &ivas_param_mc_ild_fac_CICP19_3tc[0], #ifdef IVAS_FLOAT_FIXED &ivas_param_mc_ild_fac_CICP19_3tc_fx[0], - & ivas_param_mc_dmx_fac_CICP19_3tc_fx[0] + &ivas_param_mc_dmx_fac_CICP19_3tc_fx[0] +#else + &ivas_param_mc_ild_fac_CICP19_3tc[0], + &ivas_param_mc_dmx_fac_CICP19_3tc[0], #endif } #ifndef FIX_901_PARAMMC_DEAD_CODE diff --git a/lib_com/ivas_spar_com.c b/lib_com/ivas_spar_com.c index bae0da15f..4b206e1ca 100644 --- a/lib_com/ivas_spar_com.c +++ b/lib_com/ivas_spar_com.c @@ -6961,6 +6961,7 @@ int16_t ivas_get_bits_to_encode( * Set SPAR bitrate config *-----------------------------------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED void ivas_spar_set_bitrate_config( ivas_spar_md_com_cfg *pSpar_md_cfg, /* i/o: SPAR MD config. handle */ const int16_t table_idx, /* i : config. table index */ @@ -7109,8 +7110,7 @@ void ivas_spar_set_bitrate_config( return; } - -#ifdef IVAS_FLOAT_FIXED +#else void ivas_spar_set_bitrate_config_fx( ivas_spar_md_com_cfg *pSpar_md_cfg, /* i/o: SPAR MD config. handle */ const Word16 table_idx, /* i : config. table index */ diff --git a/lib_com/ivas_spar_com_quant_util.c b/lib_com/ivas_spar_com_quant_util.c index 8b0bf766f..f0f509375 100644 --- a/lib_com/ivas_spar_com_quant_util.c +++ b/lib_com/ivas_spar_com_quant_util.c @@ -272,6 +272,7 @@ void ivas_quantise_real_values_enc_fx( * * Sets the quant strat values *-----------------------------------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED void ivas_spar_get_uniform_quant_strat( ivas_spar_md_com_cfg *pSpar_md_com_cfg, const int16_t table_idx ) @@ -343,9 +344,7 @@ void ivas_spar_get_uniform_quant_strat( return; } - - -#ifdef IVAS_FLOAT_FIXED +#else /*-----------------------------------------------------------------------------------------* * Function ivas_spar_get_uniform_quant_strat_fx() * @@ -581,6 +580,7 @@ void ivas_map_prior_coeffs_quant( * * Init SPAR MD with minmax vals *-----------------------------------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED void ivas_spar_quant_dtx_init( ivas_spar_md_t *spar_md, float *min_max ) @@ -590,7 +590,7 @@ void ivas_spar_quant_dtx_init( return; } - +#else void ivas_spar_quant_dtx_init_fx( ivas_spar_md_t *spar_md, Word32 *min_max /*q28*/ ) @@ -602,6 +602,7 @@ void ivas_spar_quant_dtx_init_fx( return; } +#endif /*-----------------------------------------------------------------------------------------* * Function ivas_copy_band_coeffs_idx_to_arr() diff --git a/lib_com/ivas_stat_com.h b/lib_com/ivas_stat_com.h index d306ed04c..b893c1d84 100644 --- a/lib_com/ivas_stat_com.h +++ b/lib_com/ivas_stat_com.h @@ -214,16 +214,22 @@ typedef struct ivas_spar_md_t { ivas_band_coeffs_t *band_coeffs; ivas_band_coeffs_ind_t band_coeffs_idx[IVAS_MAX_NUM_BANDS]; - int16_t num_bands; + Word16 num_bands; +#ifndef IVAS_FLOAT_FIXED float min_max[2]; +#endif Word32 min_max_fx[2]; /*q28*/ int16_t dtx_vad; +#ifndef IVAS_FLOAT_FIXED float en_ratio_slow[IVAS_MAX_NUM_BANDS]; +#endif Word32 en_ratio_slow_fx[IVAS_MAX_NUM_BANDS]; +#ifndef IVAS_FLOAT_FIXED float ref_pow_slow[IVAS_MAX_NUM_BANDS]; +#endif Word32 ref_pow_slow_fx[IVAS_MAX_NUM_BANDS]; - int16_t res_ind; - int16_t prior_dyn_active_w_flag; + Word16 res_ind; + Word16 prior_dyn_active_w_flag; } ivas_spar_md_t; typedef struct ivas_spar_md_prev_t @@ -235,9 +241,13 @@ typedef struct ivas_spar_md_prev_t typedef struct ivas_quant_coeffs_t { +#ifndef IVAS_FLOAT_FIXED float min; +#endif Word32 min_fx; /* Q28 */ +#ifndef IVAS_FLOAT_FIXED float max; +#endif Word32 max_fx; /* Q28 */ int16_t q_levels[2]; } ivas_quant_coeffs_t; @@ -430,22 +440,24 @@ typedef struct ivas_spar_br_table_t typedef struct ivas_MASA_spherical_grid_deindexing { +#ifndef IVAS_FLOAT_FIXED float theta_cb[NO_THETA16_MAX]; - int16_t no_theta; - int16_t no_phi[NO_THETA16_MAX]; +#endif + Word16 no_theta; + Word16 no_phi[NO_THETA16_MAX]; } SPHERICAL_GRID_DATA; typedef struct ivas_masa_descriptive_meta_struct { - uint8_t formatDescriptor[8]; /* 8x 8 bits */ - uint8_t numberOfDirections; /* 1 bit */ - uint8_t numberOfChannels; /* 1 bit */ - uint8_t sourceFormat; /* 2 bits */ - uint8_t transportDefinition; /* 3 bits */ - uint8_t channelAngle; /* 3 bits */ - uint8_t channelDistance; /* 6 bits */ - uint8_t channelLayout; /* 3 bits, used only when sourceFormat == bit value 10 */ + UWord8 formatDescriptor[8]; /* 8x 8 bits */ + UWord8 numberOfDirections; /* 1 bit */ + UWord8 numberOfChannels; /* 1 bit */ + UWord8 sourceFormat; /* 2 bits */ + UWord8 transportDefinition; /* 3 bits */ + UWord8 channelAngle; /* 3 bits */ + UWord8 channelDistance; /* 6 bits */ + UWord8 channelLayout; /* 3 bits, used only when sourceFormat == bit value 10 */ } MASA_DECRIPTIVE_META; @@ -462,7 +474,7 @@ typedef struct ivas_masa_directional_spatial_meta_struct Word32 energy_ratio_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; /* Q30 */ Word16 spread_coherence_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; /* Q15 */ #endif - uint16_t spherical_index[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; + UWord16 spherical_index[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; } MASA_DIRECTIONAL_SPATIAL_META; @@ -530,7 +542,7 @@ typedef struct typedef struct ivas_qdirection_band_data_struct { - uint16_t spherical_index[MAX_PARAM_SPATIAL_SUBFRAMES]; + UWord16 spherical_index[MAX_PARAM_SPATIAL_SUBFRAMES]; #ifndef IVAS_FLOAT_FIXED float azimuth[MAX_PARAM_SPATIAL_SUBFRAMES]; float elevation[MAX_PARAM_SPATIAL_SUBFRAMES]; @@ -538,21 +550,21 @@ typedef struct ivas_qdirection_band_data_struct Word32 azimuth_fx[MAX_PARAM_SPATIAL_SUBFRAMES]; /* Q22 */ Word32 elevation_fx[MAX_PARAM_SPATIAL_SUBFRAMES]; /* Q22 */ #endif - int16_t elevation_m_alphabet[MAX_PARAM_SPATIAL_SUBFRAMES]; - int16_t azimuth_m_alphabet[MAX_PARAM_SPATIAL_SUBFRAMES]; + Word16 elevation_m_alphabet[MAX_PARAM_SPATIAL_SUBFRAMES]; + Word16 azimuth_m_alphabet[MAX_PARAM_SPATIAL_SUBFRAMES]; #ifdef IVAS_FLOAT_FIXED Word32 energy_ratio_fx[MAX_PARAM_SPATIAL_SUBFRAMES]; /* Q30 */ #else float energy_ratio[MAX_PARAM_SPATIAL_SUBFRAMES]; #endif - uint8_t distance[MAX_PARAM_SPATIAL_SUBFRAMES]; + UWord8 distance[MAX_PARAM_SPATIAL_SUBFRAMES]; - uint16_t bits_sph_idx[MAX_PARAM_SPATIAL_SUBFRAMES]; - uint16_t energy_ratio_index[MAX_PARAM_SPATIAL_SUBFRAMES]; - uint16_t energy_ratio_index_mod[MAX_PARAM_SPATIAL_SUBFRAMES]; - uint16_t azimuth_index[MAX_PARAM_SPATIAL_SUBFRAMES]; - uint16_t elevation_index[MAX_PARAM_SPATIAL_SUBFRAMES]; + UWord16 bits_sph_idx[MAX_PARAM_SPATIAL_SUBFRAMES]; + UWord16 energy_ratio_index[MAX_PARAM_SPATIAL_SUBFRAMES]; + UWord16 energy_ratio_index_mod[MAX_PARAM_SPATIAL_SUBFRAMES]; + UWord16 azimuth_index[MAX_PARAM_SPATIAL_SUBFRAMES]; + UWord16 elevation_index[MAX_PARAM_SPATIAL_SUBFRAMES]; #ifndef IVAS_FLOAT_FIXED float q_azimuth[MAX_PARAM_SPATIAL_SUBFRAMES]; float q_elevation[MAX_PARAM_SPATIAL_SUBFRAMES]; @@ -565,15 +577,15 @@ typedef struct ivas_qdirection_band_data_struct typedef struct ivas_qdirection_band_coherence_data_struct { - uint8_t spread_coherence[MAX_PARAM_SPATIAL_SUBFRAMES]; - uint16_t spread_coherence_dct0_index; - uint16_t spread_coherence_dct1_index; + UWord8 spread_coherence[MAX_PARAM_SPATIAL_SUBFRAMES]; + UWord16 spread_coherence_dct0_index; + UWord16 spread_coherence_dct1_index; } IVAS_QDIRECTION_BAND_COHERENCE_DATA; typedef struct ivas_surround_coherence_band_data_struct { - uint8_t surround_coherence[MAX_PARAM_SPATIAL_SUBFRAMES]; - uint16_t sur_coherence_index; + UWord8 surround_coherence[MAX_PARAM_SPATIAL_SUBFRAMES]; + UWord16 sur_coherence_index; } IVAS_SURROUND_COHERENCE_BAND_DATA; @@ -584,39 +596,39 @@ typedef struct IVAS_QDIRECTION_BAND_DATA *band_data; IVAS_QDIRECTION_BAND_COHERENCE_DATA *coherence_band_data; - int16_t not_in_2D; + Word16 not_in_2D; } IVAS_QDIRECTION; /* IVAS_QMETADATA; */ typedef struct ivas_masa_qmetadata_frame_struct { IVAS_QDIRECTION *q_direction; - uint16_t no_directions; - int16_t bits_frame_nominal; - uint16_t coherence_flag; - uint8_t all_coherence_zero; - uint8_t twoDirBands[MASA_MAXIMUM_CODING_SUBBANDS]; - uint8_t numTwoDirBands; - int16_t qmetadata_max_bit_req; - int16_t metadata_max_bits; /* maximum allowed number of bits for metadata per frame */ - uint8_t useLowerRes; - uint8_t useLowerBandRes; - int16_t dirac_mono_flag; + UWord16 no_directions; + Word16 bits_frame_nominal; + UWord16 coherence_flag; + UWord8 all_coherence_zero; + UWord8 twoDirBands[MASA_MAXIMUM_CODING_SUBBANDS]; + UWord8 numTwoDirBands; + Word16 qmetadata_max_bit_req; + Word16 metadata_max_bits; /* maximum allowed number of bits for metadata per frame */ + UWord8 useLowerRes; + UWord8 useLowerBandRes; + Word16 dirac_mono_flag; IVAS_SURROUND_COHERENCE_BAND_DATA *surcoh_band_data; /* Additional helper values to include all data required for writing to output file */ - uint8_t numCodingBands; - int16_t *bandMap; - int16_t nchan_transport; - int16_t sba_inactive_mode; + UWord8 numCodingBands; + Word16 *bandMap; + Word16 nchan_transport; + Word16 sba_inactive_mode; /* Status values on metadata quality */ - int16_t ec_flag; + Word16 ec_flag; #ifndef IVAS_FLOAT_FIXED float dir_comp_ratio; #else Word16 dir_comp_ratio_fx; /* Q15 */ #endif - uint8_t is_masa_ivas_format; + UWord8 is_masa_ivas_format; } IVAS_QMETADATA, *IVAS_QMETADATA_HANDLE; @@ -627,52 +639,53 @@ typedef struct ivas_masa_qmetadata_frame_struct typedef struct ivas_param_mc_ild_mapping_struct { - int16_t ild_map_size_wo_lfe; - int16_t ild_map_size_lfe; - int16_t ild_index[MAX_CICP_CHANNELS]; - int16_t num_ref_channels[MAX_CICP_CHANNELS]; - int16_t ref_channel_idx[MAX_CICP_CHANNELS][PARAM_MC_MAX_ILD_REF_CHANNELS]; + Word16 ild_map_size_wo_lfe; + Word16 ild_map_size_lfe; + Word16 ild_index[MAX_CICP_CHANNELS]; + Word16 num_ref_channels[MAX_CICP_CHANNELS]; + Word16 ref_channel_idx[MAX_CICP_CHANNELS][PARAM_MC_MAX_ILD_REF_CHANNELS]; } PARAM_MC_ILD_MAPPING, *HANDLE_PARAM_MC_ILD_MAPPING; typedef struct ivas_param_mc_icc_mapping_struct { - int16_t icc_map_size_wo_lfe; - int16_t icc_map_size_lfe; - int16_t icc_mapping[PARAM_MC_SZ_ICC_MAP][2]; + Word16 icc_map_size_wo_lfe; + Word16 icc_map_size_lfe; + Word16 icc_mapping[PARAM_MC_SZ_ICC_MAP][2]; } PARAM_MC_ICC_MAPPING, *HANDLE_PARAM_MC_ICC_MAPPING; typedef struct ivas_param_mc_conf_struct /* structure for ROM Table */ { MC_LS_SETUP mc_ls_setup; - int16_t num_input_chan; - int16_t num_transport_chan; - int32_t ivas_total_brate; + Word16 num_input_chan; + Word16 num_transport_chan; + Word32 ivas_total_brate; const PARAM_MC_ILD_MAPPING *ild_mapping_conf; const PARAM_MC_ICC_MAPPING *icc_mapping_conf; - const float *dmx_fac; - const float *ild_factors; #ifdef IVAS_FLOAT_FIXED const Word16 *ild_factors_fx; const Word32 *dmx_fac_fx; /* Q31 */ +#else + const float *ild_factors; + const float *dmx_fac; #endif } PARAM_MC_CONF; typedef struct ivas_parametric_mc_metadata_value_coding_info_struct { - const uint16_t *cum_freq; - const uint16_t *sym_freq; - const uint16_t *cum_freq_delta; - const uint16_t *sym_freq_delta; - const float *quantizer; + const UWord16 *cum_freq; + const UWord16 *sym_freq; + const UWord16 *cum_freq_delta; + const UWord16 *sym_freq_delta; #ifdef IVAS_FLOAT_FIXED const Word16 *quantizer_fx; - Word16 Q_quant; +#else + const float *quantizer; #endif - int16_t quantizer_size; - int16_t uni_bits; + Word16 quantizer_size; + Word16 uni_bits; } PARAM_MC_PARAMETER_CODING_INFO, *HANDLE_PARAM_MC_PARAMETER_CODING_INFO; @@ -684,24 +697,25 @@ typedef struct ivas_parametric_mc_metadata_struct int16_t icc_mapping[PARAM_MC_PARAMETER_FRAMES][PARAM_MC_SZ_ICC_MAP][2]; int16_t *icc_map_full[2]; #endif - int16_t icc_map_size_full; - int16_t param_frame_idx; + Word16 icc_map_size_full; + Word16 param_frame_idx; #ifndef FIX_901_PARAMMC_DEAD_CODE int16_t flag_use_adaptive_icc_map; #endif - const float *ild_factors; #ifdef IVAS_FLOAT_FIXED const Word16 *ild_factors_fx; +#else + const float *ild_factors; #endif - int16_t coding_band_mapping[PARAM_MC_MAX_PARAMETER_BANDS]; - int16_t nbands_in_param_frame[PARAM_MC_PARAMETER_FRAMES]; - int16_t bAttackPresent; - int16_t attackIndex; - int16_t nbands_coded; - int16_t num_parameter_bands; - int16_t coded_bwidth; - int16_t last_coded_bwidth; - int16_t lfe_on; + Word16 coding_band_mapping[PARAM_MC_MAX_PARAMETER_BANDS]; + Word16 nbands_in_param_frame[PARAM_MC_PARAMETER_FRAMES]; + Word16 bAttackPresent; + Word16 attackIndex; + Word16 nbands_coded; + Word16 num_parameter_bands; + Word16 coded_bwidth; + Word16 last_coded_bwidth; + Word16 lfe_on; PARAM_MC_PARAMETER_CODING_INFO icc_coding; PARAM_MC_PARAMETER_CODING_INFO ild_coding; @@ -718,8 +732,9 @@ typedef struct ivas_lfe_window int16_t fade_len; int16_t zero_pad_len; int16_t full_len; +#ifndef IVAS_FLOAT_FIXED const float *pWindow_coeffs; -#ifdef IVAS_FLOAT_FIXED +#else const Word32 *pWindow_coeffs_fx; #endif @@ -741,8 +756,8 @@ typedef struct ivas_lfe_freq_models typedef struct ivas_filters_process_state_t { - int16_t order; - int16_t filt_len; + Word16 order; + Word16 filt_len; #ifdef IVAS_FLOAT_FIXED Word32 num_fx[IVAS_FILTER_MAX_STAGES][IVAS_BIQUAD_FILT_LEN]; Word32 den_fx[IVAS_FILTER_MAX_STAGES][IVAS_BIQUAD_FILT_LEN]; @@ -790,53 +805,42 @@ typedef struct ivas_trans_det_state_t typedef struct ivas_fb_mixer_cfg_t { - int16_t fb_latency; - int16_t num_in_chans; - int16_t num_out_chans; - int16_t nchan_fb_in; - int16_t pcm_offset; - int16_t fade_len; /* this sets the stride length; no delay is introduced */ - int16_t prior_input_length; - int16_t windowed_fr_offset; - int16_t active_w_mixing; - const int16_t *remix_order; + Word16 fb_latency; + Word16 num_in_chans; + Word16 num_out_chans; + Word16 nchan_fb_in; + Word16 pcm_offset; + Word16 fade_len; /* this sets the stride length; no delay is introduced */ + Word16 prior_input_length; + Word16 windowed_fr_offset; + Word16 active_w_mixing; + const Word16 *remix_order; } IVAS_FB_CFG; typedef struct ivas_fb_consts_t { - const float *ppFilterbank_FRs[2][IVAS_MAX_NUM_BANDS]; - float *ppFilterbank_FRs_non48k[2][IVAS_MAX_NUM_BANDS]; - const int16_t *pFilterbank_bins_per_band; - const int16_t *pFilterbank_bins_start_offset; - -#ifdef IVAS_FLOAT_FIXED + const Word16 *pFilterbank_bins_per_band; + const Word16 *pFilterbank_bins_start_offset; const Word32 *ppFilterbank_FRs_fx[2][IVAS_MAX_NUM_BANDS]; // Q30 Word32 *ppFilterbank_FRs_non48k_fx[2][IVAS_MAX_NUM_BANDS]; // Q30 -#endif } ivas_fb_consts_t; typedef struct ivas_fb_bin_to_band_data_t { - float *pFb_bin_to_band[IVAS_MAX_NUM_FB_BANDS]; - const int16_t *pFb_start_bin_per_band; - const int16_t *pFb_active_bins_per_band; - float pp_cldfb_weights_per_spar_band[CLDFB_NO_CHANNELS_MAX][IVAS_MAX_NUM_FB_BANDS]; /* weights for linear combination of parameters from different SPAR bands*/ - int16_t p_spar_start_bands[CLDFB_NO_CHANNELS_MAX]; /* the first SPAR band per CLFB band when the weight is > 0 */ - int16_t p_cldfb_map_to_spar_band[CLDFB_NO_CHANNELS_MAX]; /* a direct mapping from CLDFB band to SPAR band */ - int16_t p_short_stride_start_bin_per_band[IVAS_MAX_NUM_FB_BANDS]; - int16_t p_short_stride_num_bins_per_band[IVAS_MAX_NUM_FB_BANDS]; - float p_short_stride_bin_to_band[2 * MDFT_FB_BANDS_240]; - float *pp_short_stride_bin_to_band[IVAS_MAX_NUM_FB_BANDS]; - int16_t short_stride; - int16_t num_cldfb_bands; -#ifdef IVAS_FLOAT_FIXED + const Word16 *pFb_start_bin_per_band; + const Word16 *pFb_active_bins_per_band; + Word16 p_spar_start_bands[CLDFB_NO_CHANNELS_MAX]; /* the first SPAR band per CLFB band when the weight is > 0 */ + Word16 p_cldfb_map_to_spar_band[CLDFB_NO_CHANNELS_MAX]; /* a direct mapping from CLDFB band to SPAR band */ + Word16 p_short_stride_start_bin_per_band[IVAS_MAX_NUM_FB_BANDS]; + Word16 p_short_stride_num_bins_per_band[IVAS_MAX_NUM_FB_BANDS]; + Word16 short_stride; + Word16 num_cldfb_bands; Word32 *pFb_bin_to_band_fx[IVAS_MAX_NUM_FB_BANDS]; Word32 p_short_stride_bin_to_band_fx[2 * MDFT_FB_BANDS_240]; Word32 *pp_short_stride_bin_to_band_fx[IVAS_MAX_NUM_FB_BANDS]; Word32 pp_cldfb_weights_per_spar_band_fx[CLDFB_NO_CHANNELS_MAX][IVAS_MAX_NUM_FB_BANDS]; -#endif } ivas_fb_bin_to_band_data_t; @@ -854,23 +858,13 @@ typedef struct ivas_fb_mixer_state_structure Word16 num_diff_bands; ivas_filterbank_t *pFb; -#ifndef IVAS_FLOAT_FIXED - float *ppFilterbank_inFR_re[IVAS_MAX_FB_MIXER_IN_CH]; - float *ppFilterbank_inFR_im[IVAS_MAX_FB_MIXER_IN_CH]; -#endif - float *ppFilterbank_prior_input[IVAS_MAX_FB_MIXER_IN_CH]; - -#ifdef IVAS_FLOAT_FIXED Word32 *ppFilterbank_inFR_re_fx[IVAS_MAX_FB_MIXER_IN_CH]; Word32 *ppFilterbank_inFR_im_fx[IVAS_MAX_FB_MIXER_IN_CH]; Word32 *ppFilterbank_prior_input_fx[IVAS_MAX_FB_MIXER_IN_CH]; - Word16 q_ppFilterbank_inFR_re_fx[IVAS_MAX_FB_MIXER_IN_CH]; - Word16 q_ppFilterbank_inFR_im_fx[IVAS_MAX_FB_MIXER_IN_CH]; + Word16 q_ppFilterbank_inFR[IVAS_MAX_FB_MIXER_IN_CH]; Word16 q_ppFilterbank_prior_input_fx[IVAS_MAX_FB_MIXER_IN_CH]; Word32 *prior_mixer_fx[IVAS_MAX_FB_MIXER_OUT_CH][IVAS_MAX_SPAR_FB_MIXER_IN_CH]; Word16 q_prior_mixer_fx; -#endif - /* store sin part in const table (no need to store 1s and 0s, no need to do windowing for 1's and 0's as well) */ Word16 cross_fade_start_offset; Word16 cross_fade_end_offset; @@ -931,6 +925,7 @@ typedef struct ivas_param_ism_data_structure Word16 last_dmx_gain_fx; Word16 last_dmx_gain_e; Word16 last_cardioid_left_fx[MAX_NUM_OBJECTS]; // Q14 + } PARAM_ISM_CONFIG_DATA, *PARAM_ISM_CONFIG_HANDLE; #ifdef IVAS_FLOAT_FIXED diff --git a/lib_com/ivas_tools.c b/lib_com/ivas_tools.c index 88a0200eb..87984f205 100644 --- a/lib_com/ivas_tools.c +++ b/lib_com/ivas_tools.c @@ -76,18 +76,18 @@ float sumAbs( #ifdef IVAS_FLOAT_FIXED Word32 sumAbs_fx( - const Word32 *vec, /* i : input vector */ - const Word16 lvec /* i : length of input vector */ + const Word32 *vec, /* i : input vector Qx*/ + const Word16 lvec /* i : length of input vector Q0*/ ) { Word16 i; - Word32 tmp; + Word32 tmp; /*Qx*/ tmp = 0; move32(); FOR( i = 0; i < lvec; i++ ) { - tmp = L_add( tmp, L_abs( vec[i] ) ); + tmp = L_add( tmp, L_abs( vec[i] ) ); /*Qx*/ } return tmp; @@ -171,11 +171,11 @@ uint32_t ivas_syn_output( #ifdef IVAS_FLOAT_FIXED UWord32 ivas_syn_output_fx( - Word32 *synth[], /* i/o: float synthesis signal */ + Word32 *synth[], /* i/o: float synthesis signal q_synth*/ const Word16 q_synth, - const Word16 output_frame, /* i : output frame length (one channel) */ - const Word16 n_channels, /* i : number of output channels */ - Word16 *synth_out /* o : integer 16 bits synthesis signal */ + const Word16 output_frame, /* i : output frame length (one channel) Q0*/ + const Word16 n_channels, /* i : number of output channels Q0*/ + Word16 *synth_out /* o : integer 16 bits synthesis signal Q0*/ ) { Word16 i, n; @@ -190,17 +190,17 @@ UWord32 ivas_syn_output_fx( FOR( n = 0; n < n_channels; n++ ) { - tmp = mvl2s_r( synth[n], q_synth, synth_loc, output_frame ); + tmp = mvl2s_r( synth[n], q_synth, synth_loc, output_frame ); /*Q0*/ noClipping = UL_addNsD( noClipping, tmp ); FOR( i = 0; i < output_frame; i++ ) { - synth_out[L_add( imult1616( i, n_channels ), n )] = synth_loc[i]; + synth_out[( ( i * n_channels ) + n )] = synth_loc[i]; /*q_synth*/ move16(); } } - return noClipping; + return noClipping; /*Q0*/ } #endif @@ -239,10 +239,10 @@ void ivas_syn_output_f( #ifdef IVAS_FLOAT_FIXED void ivas_syn_output_f_fx( - Word32 *synth[], /* i/o: float synthesis signal */ - const Word16 output_frame, /* i : output frame length (one channel) */ - const Word16 n_channels, /* i : number of output channels */ - Word32 *synth_out /* o : integer 16 bits synthesis signal */ + Word32 *synth[], /* i/o: float synthesis signal Q11*/ + const Word16 output_frame, /* i : output frame length (one channel) Q0*/ + const Word16 n_channels, /* i : number of output channels Q0*/ + Word32 *synth_out /* o : integer 16 bits synthesis signal Q11*/ ) { Word16 i, n; @@ -255,7 +255,7 @@ void ivas_syn_output_f_fx( { FOR( i = 0; i < output_frame; i++ ) { - synth_out[L_add( imult1616( i, n_channels ), n )] = synth[n][i]; + synth_out[( ( i * n_channels ) + n )] = synth[n][i]; /*Q11*/ move16(); } } @@ -272,11 +272,11 @@ void ivas_syn_output_f_fx( *-------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED void mvr2r_inc_fixed_one( - const Word32 x_fx[], /* i : input vector */ - const Word16 x_inc, /* i : increment for vector x[] */ - Word32 y_fx[], /* o : output vector */ - const Word16 y_inc, /* i : increment for vector y[] */ - const Word16 n /* i : vector size */ + const Word32 x_fx[], /* i : input vector Q29*/ + const Word16 x_inc, /* i : increment for vector x[] Q0*/ + Word32 y_fx[], /* o : output vector Q29*/ + const Word16 y_inc, /* i : increment for vector y[] Q0*/ + const Word16 n /* i : vector size Q0*/ ) { Word16 i; @@ -297,7 +297,7 @@ void mvr2r_inc_fixed_one( move16(); FOR( i = 0; i < n; i++ ) { - y_fx[iy] = x_fx[ix]; + y_fx[iy] = x_fx[ix]; /*Q29*/ move32(); ix = add( ix, x_inc ); @@ -306,11 +306,11 @@ void mvr2r_inc_fixed_one( } ELSE { - ix = imult1616( sub( n, 1 ), x_inc ); - iy = imult1616( sub( n, 1 ), y_inc ); - FOR( i = sub( n, 1 ); i >= 0; i-- ) + ix = imult1616( sub( n, 1 ), x_inc ); /*Q0*/ + iy = imult1616( sub( n, 1 ), y_inc ); /*Q0*/ + FOR( i = ( n - 1 ); i >= 0; i-- ) { - y_fx[iy] = x_fx[ix]; + y_fx[iy] = x_fx[ix]; /*Q29*/ move32(); ix = sub( ix, x_inc ); @@ -322,11 +322,11 @@ void mvr2r_inc_fixed_one( } void mvr2r_inc_fixed( - const Word32 x_fx[], /* i : input vector */ - const Word16 x_inc, /* i : increment for vector x[] */ - Word32 y_fx[], /* o : output vector */ - const Word16 y_inc, /* i : increment for vector y[] */ - const Word16 n /* i : vector size */ + const Word32 x_fx[], /* i : input vector Q29*/ + const Word16 x_inc, /* i : increment for vector x[] Q0*/ + Word32 y_fx[], /* o : output vector Q29*/ + const Word16 y_inc, /* i : increment for vector y[] Q0*/ + const Word16 n /* i : vector size Q0*/ ) { Word16 i; @@ -347,7 +347,7 @@ void mvr2r_inc_fixed( move16(); FOR( i = 0; i < n; i++ ) { - y_fx[iy] = x_fx[ix]; + y_fx[iy] = x_fx[ix]; /*Q29*/ move32(); ix = add( ix, x_inc ); @@ -356,11 +356,11 @@ void mvr2r_inc_fixed( } ELSE { - ix = i_mult( sub( n, 1 ), x_inc ); + ix = i_mult( sub( n, 1 ), x_inc ); /*Q0*/ iy = i_mult( sub( n, 1 ), y_inc ); FOR( i = sub( n, 1 ); i >= 0; i-- ) { - y_fx[iy] = x_fx[ix]; + y_fx[iy] = x_fx[ix]; /*Q29*/ move32(); ix = sub( ix, x_inc ); @@ -451,13 +451,13 @@ void v_add_inc( #ifdef IVAS_FLOAT_FIXED // for same q// void v_add_inc_fx( - const Word32 x1[], /* i : Input vector 1 */ - const Word16 x_inc, /* i : Increment for input vector 1 */ - const Word32 x2[], /* i : Input vector 2 */ - const Word16 x2_inc, /* i : Increment for input vector 2 */ - Word32 y[], /* o : Output vector that contains vector 1 + vector 2 */ - const Word16 y_inc, /* i : increment for vector y[] */ - const Word16 N /* i : Vector length */ + const Word32 x1[], /* i : Input vector 1 Qx*/ + const Word16 x_inc, /* i : Increment for input vector 1 Q0*/ + const Word32 x2[], /* i : Input vector 2 Qx*/ + const Word16 x2_inc, /* i : Increment for input vector 2 Q0*/ + Word32 y[], /* o : Output vector that contains vector 1 + vector 2 Qx*/ + const Word16 y_inc, /* i : increment for vector y[] Q0*/ + const Word16 N /* i : Vector length Q0*/ ) { Word16 i; @@ -469,11 +469,11 @@ void v_add_inc_fx( move16(); FOR( i = 0; i < N; i++ ) { - y[iy] = L_add( x1[ix1], x2[ix2] ); + y[iy] = L_add( x1[ix1], x2[ix2] ); /*Qx*/ move32(); - ix1 = add( ix1, x_inc ); - ix2 = add( ix2, x2_inc ); - iy = add( iy, y_inc ); + ix1 = add( ix1, x_inc ); /*Q0*/ + ix2 = add( ix2, x2_inc ); /*Q0*/ + iy = add( iy, y_inc ); /*Q0*/ } return; } @@ -487,16 +487,16 @@ void v_add_inc_fx( *-------------------------------------------------------------------*/ void v_mult_inc_fx( - const Word32 x1_fx[], /* i : Input vector 1 */ + const Word32 x1_fx[], /* i : Input vector 1 x1_q_fx*/ Word16 *x1_q_fx, - const Word16 x1_inc, /* i : Increment for input vector 1 */ - const Word32 x2_fx[], /* i : Input vector 2 */ + const Word16 x1_inc, /* i : Increment for input vector 1 Q0*/ + const Word32 x2_fx[], /* i : Input vector 2 x2_q_fx*/ Word16 *x2_q_fx, - const Word16 x2_inc, /* i : Increment for input vector 1 */ - Word32 y_fx[], /* o : Output vector that contains vector 1 .* vector 2 */ + const Word16 x2_inc, /* i : Increment for input vector 1 Q0*/ + Word32 y_fx[], /* o : Output vector that contains vector 1 .* vector 2 y_q_fx*/ Word16 *y_q_fx, - const Word16 y_inc, /* i : increment for vector y[i] */ - const Word16 N /* i : Vector length */ + const Word16 y_inc, /* i : increment for vector y[i] Q0*/ + const Word16 N /* i : Vector length Q0*/ ) { Word16 i; @@ -510,14 +510,14 @@ void v_mult_inc_fx( FOR( i = 0; i < N; i++ ) { - y_fx[iy] = Mpy_32_32( x1_fx[ix1], x2_fx[ix2] ); + y_fx[iy] = Mpy_32_32( x1_fx[ix1], x2_fx[ix2] ); /* x1_q_fx + x2_q_fx - 31 */ move32(); y_q_fx[iy] = sub( add( x1_q_fx[ix1], x2_q_fx[ix2] ), 31 ); move16(); - ix1 = add( ix1, x1_inc ); - ix2 = add( ix2, x2_inc ); - iy = add( iy, y_inc ); + ix1 = add( ix1, x1_inc ); /*Q0*/ + ix2 = add( ix2, x2_inc ); /*Q0*/ + iy = add( iy, y_inc ); /*Q0*/ } return; @@ -525,13 +525,13 @@ void v_mult_inc_fx( // when buffers have constant q/ void v_mult_inc_fixed( - const Word32 x1_fx[], /* i : Input vector 1 */ - const Word16 x1_inc, /* i : Increment for input vector 1 */ - const Word32 x2_fx[], /* i : Input vector 2 */ - const Word16 x2_inc, /* i : Increment for input vector 1 */ - Word32 y_fx[], /* o : Output vector that contains vector 1 .* vector 2 */ - const Word16 y_inc, /* i : increment for vector y[i] */ - const Word16 N /* i : Vector length */ + const Word32 x1_fx[], /* i : Input vector 1 Qx1*/ + const Word16 x1_inc, /* i : Increment for input vector 1 Q0*/ + const Word32 x2_fx[], /* i : Input vector 2 Qx2*/ + const Word16 x2_inc, /* i : Increment for input vector 1 Q0*/ + Word32 y_fx[], /* o : Output vector that contains vector 1 .* vector 2 Qx1 + Qx2 - 31*/ + const Word16 y_inc, /* i : increment for vector y[i] Q0*/ + const Word16 N /* i : Vector length Q0*/ ) { Word16 i; @@ -545,7 +545,7 @@ void v_mult_inc_fixed( FOR( i = 0; i < N; i++ ) { - y_fx[iy] = Mpy_32_32( x1_fx[ix1], x2_fx[ix2] ); + y_fx[iy] = Mpy_32_32( x1_fx[ix1], x2_fx[ix2] ); /*Qx1 + Qx2 - 31*/ move32(); ix1 = add( ix1, x1_inc ); @@ -597,17 +597,17 @@ void v_mult_inc( *-------------------------------------------------------------------*/ void v_addc_fx( - const Word32 x_fx[], /* i : Input vector */ - const Word32 c_fx, /* i : Constant */ - Word32 y_fx[], /* o : Output vector that contains c*x */ - const Word16 N /* i : Vector length */ + const Word32 x_fx[], /* i : Input vector Qx*/ + const Word32 c_fx, /* i : Constant Qx*/ + Word32 y_fx[], /* o : Output vector that contains c*x Qx*/ + const Word16 N /* i : Vector length Q0*/ ) { Word16 i; FOR( i = 0; i < N; i++ ) { - y_fx[i] = L_add( c_fx, x_fx[i] ); + y_fx[i] = L_add( c_fx, x_fx[i] ); /*Qx*/ move32(); } @@ -621,17 +621,17 @@ void v_addc_fx( *-------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED void v_addc_fixed( - const Word32 x[], /* i : Input vector */ - const Word32 c, /* i : Constant */ - Word32 y[], /* o : Output vector that contains c*x */ - const Word16 N /* i : Vector length */ + const Word32 x[], /* i : Input vector Qx*/ + const Word32 c, /* i : Constant Qx*/ + Word32 y[], /* o : Output vector that contains c*x Qx*/ + const Word16 N /* i : Vector length Q0*/ ) { Word16 i; FOR( i = 0; i < N; i++ ) { - y[i] = L_add( c, x[i] ); + y[i] = L_add( c, x[i] ); /*Qx*/ move32(); } @@ -664,13 +664,13 @@ void v_addc( *-------------------------------------------------------------------*/ void v_min_fx( - const Word32 x1_fx[], /* i : Input vector 1 */ + const Word32 x1_fx[], /* i : Input vector 1 x1_q_fx*/ Word16 *x1_q_fx, - const Word32 x2_fx[], /* i : Input vector 2 */ + const Word32 x2_fx[], /* i : Input vector 2 x2_q_fx*/ Word16 *x2_q_fx, - Word32 y_fx[], /* o : Output vector that contains vector 1 .* vector 2 */ + Word32 y_fx[], /* o : Output vector that contains vector 1 .* vector 2 y_q_fx*/ Word16 *y_q_fx, - const Word16 N /* i : Vector length */ + const Word16 N /* i : Vector length Q0*/ ) { Word16 i; @@ -681,14 +681,14 @@ void v_min_fx( { IF( LT_32( L_shr( x1_fx[i], sub( x1_q_fx[i], x2_q_fx[i] ) ), x2_fx[i] ) ) { - y_fx[i] = x1_fx[i]; + y_fx[i] = x1_fx[i]; /*x1_q_fx*/ move32(); y_q_fx[i] = x1_q_fx[i]; move16(); } ELSE { - y_fx[i] = x2_fx[i]; + y_fx[i] = x2_fx[i]; /*x2_q_fx*/ move32(); y_q_fx[i] = x2_q_fx[i]; move16(); @@ -698,14 +698,14 @@ void v_min_fx( { IF( LT_32( x1_fx[i], L_shr( x2_fx[i], sub( x2_q_fx[i], x1_q_fx[i] ) ) ) ) { - y_fx[i] = x1_fx[i]; + y_fx[i] = x1_fx[i]; /*x1_q_fx*/ move32(); y_q_fx[i] = x1_q_fx[i]; move16(); } ELSE { - y_fx[i] = x2_fx[i]; + y_fx[i] = x2_fx[i]; /*x2_q_fx*/ move32(); y_q_fx[i] = x2_q_fx[i]; move16(); @@ -747,17 +747,17 @@ void v_min( *-------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED void v_sqrt_fx( - const Word32 x[], /* i : Input vector */ + const Word32 x[], /* i : Input vector Qx*/ Word16 exp[], - Word32 y[], /* o : Output vector that contains sqrt(x) */ - const Word16 N /* i : Vector length */ + Word32 y[], /* o : Output vector that contains sqrt(x) Q31 - exp[]*/ + const Word16 N /* i : Vector length Q0*/ ) { Word16 i; FOR( i = 0; i < N; i++ ) { - y[i] = Sqrt32( x[i], &exp[i] ); + y[i] = Sqrt32( x[i], &exp[i] ); /*Q31 - exp[i]*/ move32(); } @@ -790,10 +790,10 @@ void v_sqrt( #ifdef IVAS_FLOAT_FIXED void v_sub_s16_fx( - const Word16 x1[], /* i : Input vector 1 */ - const Word16 x2[], /* i : Input vector 2 */ - Word16 y[], /* o : Output vector that contains vector 1 - vector 2 */ - const Word16 N /* i : Vector length */ + const Word16 x1[], /* i : Input vector 1 Qx*/ + const Word16 x2[], /* i : Input vector 2 Qx*/ + Word16 y[], /* o : Output vector that contains vector 1 - vector 2 Qx*/ + const Word16 N /* i : Vector length Q0*/ ) { Word16 i; @@ -804,7 +804,7 @@ void v_sub_s16_fx( FOR( i = 0; LT_16( i, N ); i++ ) #endif { - y[i] = sub( x1[i], x2[i] ); + y[i] = sub( x1[i], x2[i] ); /*Qx*/ move16(); } @@ -815,10 +815,10 @@ void v_sub_s16_fx( #ifdef IVAS_FLOAT_FIXED void v_sub32_fx( - const Word32 x1[], /* i : Input vector 1 */ - const Word32 x2[], /* i : Input vector 2 */ - Word32 y[], /* o : Output vector that contains vector 1 - vector 2 */ - const Word16 N /* i : Vector length */ + const Word32 x1[], /* i : Input vector 1 Qx*/ + const Word32 x2[], /* i : Input vector 2 Qx*/ + Word32 y[], /* o : Output vector that contains vector 1 - vector 2 Qx*/ + const Word16 N /* i : Vector length Q0*/ ) { Word16 i; @@ -829,7 +829,7 @@ void v_sub32_fx( FOR( i = 0; LT_16( i, N ); i++ ) #endif { - y[i] = L_sub( x1[i], x2[i] ); + y[i] = L_sub( x1[i], x2[i] ); /*Qx*/ move32(); } @@ -894,9 +894,9 @@ float dot_product_cholesky( } #ifdef IVAS_FLOAT_FIXED Word32 dot_product_cholesky_fixed( - const Word32 *x, /* i : vector x */ - const Word32 *A, /* i : Cholesky matrix A */ - const Word16 N, /* i : vector & matrix size */ + const Word32 *x, /* i : vector x Q31 - exp_x*/ + const Word32 *A, /* i : Cholesky matrix A Q31 - exp_A*/ + const Word16 N, /* i : vector & matrix size Q0*/ const Word16 exp_x, const Word16 exp_A, Word16 *exp_sum ) @@ -919,11 +919,11 @@ Word32 dot_product_cholesky_fixed( FOR( j = 0; j <= i; j++ ) { - mul = Mpy_32_32( *pt_x++, *pt_A++ ); + mul = Mpy_32_32( *pt_x++, *pt_A++ ); /*Q31 - (exp_x + exp_A)*/ tmp_sum = BASOP_Util_Add_Mant32Exp( tmp_sum, tmp_sum_exp, mul, mul_exp, &tmp_sum_exp ); // exp_x+exp_A } - suma = BASOP_Util_Add_Mant32Exp( suma, *exp_sum, Mpy_32_32( tmp_sum, tmp_sum ), shl( tmp_sum_exp, 1 ), exp_sum ); + suma = BASOP_Util_Add_Mant32Exp( suma, *exp_sum, Mpy_32_32( tmp_sum, tmp_sum ), shl( tmp_sum_exp, 1 ), exp_sum ); /*Q31 - exp_sum*/ } return suma; @@ -931,11 +931,11 @@ Word32 dot_product_cholesky_fixed( #endif #ifdef IVAS_FLOAT_FIXED void v_mult_mat_fixed( - Word32 *y, /* o : the product x*A */ - const Word32 *x, /* i : vector x */ - const Word32 *A, /* i : matrix A */ - const Word16 Nr, /* i : number of rows */ - const Word16 Nc, /* i : number of columns */ + Word32 *y, /* o : the product x*A Qx - guardbits*/ + const Word32 *x, /* i : vector x Qx*/ + const Word32 *A, /* i : matrix A Q31*/ + const Word16 Nr, /* i : number of rows Q0*/ + const Word16 Nc, /* i : number of columns Q0*/ Word16 guardbits ) { Word16 i, j; @@ -944,28 +944,28 @@ void v_mult_mat_fixed( Word32 *pt_y; pt_y = tmp_y; - pt_A = A; + pt_A = A; /*Q31*/ FOR( i = 0; i < Nc; i++ ) { - pt_x = x; + pt_x = x; /*Qx*/ *pt_y = 0; move32(); FOR( j = 0; j < Nr; j++ ) { - *pt_y = L_add( *pt_y, L_shr( Mpy_32_32( ( *pt_x++ ), ( *pt_A++ ) ), guardbits ) ); + *pt_y = L_add( *pt_y, L_shr( Mpy_32_32( ( *pt_x++ ), ( *pt_A++ ) ), guardbits ) ); /*Qx - guardbits*/ move32(); } pt_y++; } - MVR2R_WORD32( tmp_y, y, Nc ); + MVR2R_WORD32( tmp_y, y, Nc ); /*Qx - guardbits*/ } Word32 dot_product_cholesky_fx( - const Word32 *x, /* i : vector x */ - const Word32 *A, /* i : Cholesky matrix A */ - const Word16 N /* i : vector & matrix size */ + const Word32 *x, /* i : vector x Qx1*/ + const Word32 *A, /* i : Cholesky matrix A Qx2*/ + const Word16 N /* i : vector & matrix size Q0*/ ) { Word16 i, j; @@ -983,7 +983,7 @@ Word32 dot_product_cholesky_fx( pt_x = x; FOR( j = 0; j <= i; j++ ) { - tmp_sum = L_add( tmp_sum, Mpy_32_32( *pt_x++, *pt_A++ ) ); + tmp_sum = L_add( tmp_sum, Mpy_32_32( *pt_x++, *pt_A++ ) ); /*Qx1 + Qx2 - 31*/ } suma = L_add( suma, Mpy_32_32( tmp_sum, tmp_sum ) ); @@ -1004,14 +1004,14 @@ Word32 dot_product_cholesky_fx( *---------------------------------------------------------------------*/ void v_mult_mat_fx( - Word32 *y_fx, /* o : the product x*A */ + Word32 *y_fx, /* o : the product x*A y_q_fx*/ Word16 *y_q_fx, - const Word32 *x_fx, /* i : vector x */ + const Word32 *x_fx, /* i : vector x x_q_fx*/ Word16 *x_q_fx, - const Word32 *A_fx, /* i : matrix A */ + const Word32 *A_fx, /* i : matrix A A_q_fx*/ Word16 *A_q_fx, - const Word16 Nr, /* i : number of rows */ - const Word16 Nc /* i : number of columns */ + const Word16 Nr, /* i : number of rows Q0*/ + const Word16 Nc /* i : number of columns Q0*/ ) { Word16 i, j; @@ -1022,19 +1022,19 @@ void v_mult_mat_fx( Word16 temp_q; pt_y_fx = tmp_y_fx; - pt_A_fx = A_fx; - pt_x_fx = x_fx; + pt_A_fx = A_fx; /*A_q_fx*/ + pt_x_fx = x_fx; /*x_q_fx*/ FOR( i = 0; i < Nc; i++ ) { - pt_x_fx = x_fx; + pt_x_fx = x_fx; /*x_q_fx*/ *pt_y_fx = 0; move32(); y_q_fx[i] = 0; move32(); FOR( j = 0; j < Nr; j++ ) { - temp = Mpy_32_32( *pt_x_fx++, *pt_A_fx++ ); + temp = Mpy_32_32( *pt_x_fx++, *pt_A_fx++ ); /*x_q_fx + A_q_fx - 31*/ temp_q = sub( add( x_q_fx[j], A_q_fx[Nr * i + j] ), 31 ); IF( j == 0 ) { @@ -1062,7 +1062,7 @@ void v_mult_mat_fx( pt_y_fx++; } - MVR2R_WORD32( tmp_y_fx, y_fx, Nc ); + MVR2R_WORD32( tmp_y_fx, y_fx, Nc ); /*y_q_fx*/ return; } @@ -1144,9 +1144,9 @@ float logsumexp( } #ifdef IVAS_FLOAT_FIXED Word32 logsumexp_fx( - const Word32 x[], /* i : input array x */ + const Word32 x[], /* i : input array x Q31 - x_e*/ const Word16 x_e, - const Word16 N /* i : number of elements in array x */ + const Word16 N /* i : number of elements in array x Q0*/ ) { Word32 max_exp, temp32_sub; @@ -1158,7 +1158,7 @@ Word32 logsumexp_fx( Word16 i; Word16 pow_e, sum_e = 0; move16(); - max_exp = x[0]; + max_exp = x[0]; /*Q31 - x_e*/ move32(); sum = 0; move32(); @@ -1166,24 +1166,24 @@ Word32 logsumexp_fx( { IF( GT_32( x[i], max_exp ) ) { - max_exp = x[i]; + max_exp = x[i]; /*Q31 - x_e*/ move32(); } } FOR( i = 0; i < N; i++ ) { - temp32_sub = L_sub( x[i], max_exp ); + temp32_sub = L_sub( x[i], max_exp ); /*Q31 - x_e*/ pow_e = 0; move16(); - temp32 = Mpy_32_32( log2_e_fx, temp32_sub ); - pow_temp = BASOP_util_Pow2( temp32, add( x_e, log2_e_fx_e ), &pow_e ); - sum = BASOP_Util_Add_Mant32Exp( sum, sum_e, pow_temp, pow_e, &sum_e ); + temp32 = Mpy_32_32( log2_e_fx, temp32_sub ); /*Q30 - x_e*/ + pow_temp = BASOP_util_Pow2( temp32, add( x_e, log2_e_fx_e ), &pow_e ); /*Q31 - pow_e*/ + sum = BASOP_Util_Add_Mant32Exp( sum, sum_e, pow_temp, pow_e, &sum_e ); /*Q31 - sum_e*/ } - temp32 = L_add( BASOP_Util_Log2( sum ), L_shl( sum_e, Q25 ) ); - temp32 = Mpy_32_32( temp32, 1488522239 ); /*logf(x) = log2(x)*logf(2)*/ - temp32 = L_add( L_shr( temp32, sub( x_e, 6 ) ), max_exp ); // q = 31-x_e - return temp32; + temp32 = L_add( BASOP_Util_Log2( sum ), L_shl( sum_e, Q25 ) ); /*Q25*/ + temp32 = Mpy_32_32( temp32, 1488522239 ); /*logf(x) = log2(x)*logf(2) Q25*/ + temp32 = L_add( L_shr( temp32, sub( x_e, 6 ) ), max_exp ); // q = 31-x_e + return temp32; /*31-x_e*/ } #endif @@ -1195,12 +1195,12 @@ Word32 logsumexp_fx( #ifdef IVAS_FLOAT_FIXED /*! r: mapped output value */ Word32 lin_interp32_fx( - const Word32 x, /* i : the value to be mapped */ - const Word32 x1, /* i : source range interval: low end */ - const Word32 y1, /* i : source range interval: high end */ - const Word32 x2, /* i : target range interval: low */ - const Word32 y2, /* i : target range interval: high */ - const Word16 flag_sat, /* i : flag to indicate whether to apply saturation */ + const Word32 x, /* i : the value to be mapped Qin*/ + const Word32 x1, /* i : source range interval: low end Qin*/ + const Word32 y1, /* i : source range interval: high end Qin*/ + const Word32 x2, /* i : target range interval: low Qin*/ + const Word32 y2, /* i : target range interval: high Qin*/ + const Word16 flag_sat, /* i : flag to indicate whether to apply saturation Q0*/ Word16 *Q_io /*i/o : i/o Q factor of the output*/ ) { @@ -1231,7 +1231,7 @@ Word32 lin_interp32_fx( temp32 = BASOP_Util_Add_Mant32Exp( y1, sub( 31, *Q_io ), temp_div, sub( 31, sub( *Q_io, temp_e ) ), &exp_out ); // Qin-temp_e *Q_io = sub( 31, exp_out ); move16(); - return temp32; + return temp32; /*Q_io*/ } #endif @@ -1307,16 +1307,16 @@ int16_t check_bounds_s( } #ifdef IVAS_FLOAT_FIXED Word16 check_bounds_s_fx( - const Word16 value, /* i : Input value */ - const Word16 low, /* i : Low limit */ - const Word16 high /* i : High limit */ + const Word16 value, /* i : Input value Q0*/ + const Word16 low, /* i : Low limit Q0*/ + const Word16 high /* i : High limit Q0*/ ) { Word16 value_adj; - value_adj = s_min( s_max( value, low ), high ); + value_adj = s_min( s_max( value, low ), high ); /*Q0*/ - return value_adj; + return value_adj; /*Q0*/ } #endif @@ -1328,16 +1328,16 @@ Word16 check_bounds_s_fx( /*! r: Adjusted value */ Word32 check_bounds_l( - const Word32 value, /* i : Input value */ - const Word32 low, /* i : Low limit */ - const Word32 high /* i : High limit */ + const Word32 value, /* i : Input value Q0*/ + const Word32 low, /* i : Low limit Q0*/ + const Word32 high /* i : High limit Q0*/ ) { Word32 value_adj; - value_adj = L_min( L_max( value, low ), high ); + value_adj = L_min( L_max( value, low ), high ); /*Q0*/ - return value_adj; + return value_adj; /*Q0*/ } /****************************************************************************/ @@ -1452,17 +1452,17 @@ int16_t matrix_product( #ifdef IVAS_FLOAT_FIXED Word16 matrix_product_mant_exp_fx( - const Word32 *X_fx, /* i : left hand matrix */ + const Word32 *X_fx, /* i : left hand matrix Q31 - X_fx_e*/ const Word16 X_fx_e, /* i : left hand matrix */ - const Word16 rowsX, /* i : number of rows of the left hand matrix */ - const Word16 colsX, /* i : number of columns of the left hand matrix */ - const Word16 transpX, /* i : flag indicating the transposition of the left hand matrix prior to the multiplication */ - const Word32 *Y_fx, /* i : right hand matrix */ + const Word16 rowsX, /* i : number of rows of the left hand matrix Q0*/ + const Word16 colsX, /* i : number of columns of the left hand matrix Q0*/ + const Word16 transpX, /* i : flag indicating the transposition of the left hand matrix prior to the multiplication Q0*/ + const Word32 *Y_fx, /* i : right hand matrix Q31 - Y_fx_e*/ const Word16 Y_fx_e, /* i : right hand matrix */ - const Word16 rowsY, /* i : number of rows of the right hand matrix */ - const Word16 colsY, /* i : number of columns of the right hand matrix */ - const Word16 transpY, /* i : flag indicating the transposition of the right hand matrix prior to the multiplication */ - Word32 *Z_fx, /* o : resulting matrix after the matrix multiplication */ + const Word16 rowsY, /* i : number of rows of the right hand matrix Q0*/ + const Word16 colsY, /* i : number of columns of the right hand matrix Q0*/ + const Word16 transpY, /* i : flag indicating the transposition of the right hand matrix prior to the multiplication Q0*/ + Word32 *Z_fx, /* o : resulting matrix after the matrix multiplication Q31 - Z_fx_e*/ Word16 *Z_fx_e /* o : resulting matrix after the matrix multiplication */ ) { @@ -1495,16 +1495,16 @@ Word16 matrix_product_mant_exp_fx( { x_idx = add( k, imult1616( i, rowsX ) ); y_idx = add( k, imult1616( j, rowsY ) ); - ( *Zp_fx ) = BASOP_Util_Add_Mant32Exp( *Zp_fx, *Zp_fx_e, Mpy_32_32( X_fx[x_idx], Y_fx[y_idx] ), add( X_fx_e, Y_fx_e ), Zp_fx_e ); + ( *Zp_fx ) = BASOP_Util_Add_Mant32Exp( *Zp_fx, *Zp_fx_e, Mpy_32_32( X_fx[x_idx], Y_fx[y_idx] ), add( X_fx_e, Y_fx_e ), Zp_fx_e ); /*Q31 - Zp_fx_e*/ move32(); } Zp_fx++; Zp_fx_e++; } } - row = colsY; + row = colsY; /*Q0*/ move16(); - col = colsX; + col = colsX; /*Q0*/ move16(); } ELSE IF( transpX == 0 && EQ_16( transpY, 1 ) ) /* We use Y transpose */ @@ -1525,16 +1525,16 @@ Word16 matrix_product_mant_exp_fx( { x_idx = add( i, imult1616( k, rowsX ) ); y_idx = add( j, imult1616( k, rowsY ) ); - ( *Zp_fx ) = BASOP_Util_Add_Mant32Exp( *Zp_fx, *Zp_fx_e, Mpy_32_32( X_fx[x_idx], Y_fx[y_idx] ), add( X_fx_e, Y_fx_e ), Zp_fx_e ); + ( *Zp_fx ) = BASOP_Util_Add_Mant32Exp( *Zp_fx, *Zp_fx_e, Mpy_32_32( X_fx[x_idx], Y_fx[y_idx] ), add( X_fx_e, Y_fx_e ), Zp_fx_e ); /*Q31 - Zp_fx_e*/ move32(); } Zp_fx++; Zp_fx_e++; } } - row = rowsY; + row = rowsY; /*Q0*/ move16(); - col = rowsX; + col = rowsX; /*Q0*/ move16(); } ELSE IF( EQ_16( transpX, 1 ) && EQ_16( transpY, 1 ) ) /* We use both transpose */ @@ -1555,7 +1555,7 @@ Word16 matrix_product_mant_exp_fx( { x_idx = add( k, imult1616( i, rowsX ) ); y_idx = add( j, imult1616( k, rowsY ) ); - ( *Zp_fx ) = BASOP_Util_Add_Mant32Exp( *Zp_fx, *Zp_fx_e, Mpy_32_32( X_fx[x_idx], Y_fx[y_idx] ), add( X_fx_e, Y_fx_e ), Zp_fx_e ); + ( *Zp_fx ) = BASOP_Util_Add_Mant32Exp( *Zp_fx, *Zp_fx_e, Mpy_32_32( X_fx[x_idx], Y_fx[y_idx] ), add( X_fx_e, Y_fx_e ), Zp_fx_e ); /*Q31 - Zp_fx_e*/ move32(); } @@ -1563,9 +1563,9 @@ Word16 matrix_product_mant_exp_fx( Zp_fx_e++; } } - row = rowsY; + row = rowsY; /*Q0*/ move16(); - col = colsX; + col = colsX; /*Q0*/ move16(); } ELSE /* Regular case */ @@ -1587,19 +1587,19 @@ Word16 matrix_product_mant_exp_fx( { x_idx = add( i, imult1616( k, rowsX ) ); y_idx = add( k, imult1616( j, rowsY ) ); - ( *Zp_fx ) = BASOP_Util_Add_Mant32Exp( *Zp_fx, *Zp_fx_e, Mpy_32_32( X_fx[x_idx], Y_fx[y_idx] ), add( X_fx_e, Y_fx_e ), Zp_fx_e ); + ( *Zp_fx ) = BASOP_Util_Add_Mant32Exp( *Zp_fx, *Zp_fx_e, Mpy_32_32( X_fx[x_idx], Y_fx[y_idx] ), add( X_fx_e, Y_fx_e ), Zp_fx_e ); /*Q31 - Zp_fx_e*/ move32(); } Zp_fx++; Zp_fx_e++; } } - row = colsY; + row = colsY; /*Q0*/ move16(); - col = rowsX; + col = rowsX; /*Q0*/ move16(); } - Zp_fx = Z_fx; + Zp_fx = Z_fx; /*Q31 - Zp_fx_e*/ Zp_fx_e = out_e; Word16 max_exp = -31; move16(); @@ -1618,7 +1618,7 @@ Word16 matrix_product_mant_exp_fx( { FOR( i = 0; i < col; ++i ) { - *Zp_fx = L_shr_r( *Zp_fx, sub( *Z_fx_e, *Zp_fx_e ) ); + *Zp_fx = L_shr_r( *Zp_fx, sub( *Z_fx_e, *Zp_fx_e ) ); /*Q31 - Zp_fx_e*/ move32(); Zp_fx++; Zp_fx_e++; @@ -1629,15 +1629,15 @@ Word16 matrix_product_mant_exp_fx( } Word16 matrix_product_fx( - const Word32 *X_fx, /* i : left hand matrix */ - const Word16 rowsX, /* i : number of rows of the left hand matrix */ - const Word16 colsX, /* i : number of columns of the left hand matrix */ - const Word16 transpX, /* i : flag indicating the transposition of the left hand matrix prior to the multiplication */ - const Word32 *Y_fx, /* i : right hand matrix */ - const Word16 rowsY, /* i : number of rows of the right hand matrix */ - const Word16 colsY, /* i : number of columns of the right hand matrix */ - const Word16 transpY, /* i : flag indicating the transposition of the right hand matrix prior to the multiplication */ - Word32 *Z_fx /* o : resulting matrix after the matrix multiplication */ + const Word32 *X_fx, /* i : left hand matrix Qx*/ + const Word16 rowsX, /* i : number of rows of the left hand matrix Q0*/ + const Word16 colsX, /* i : number of columns of the left hand matrix Q0*/ + const Word16 transpX, /* i : flag indicating the transposition of the left hand matrix prior to the multiplication Q0*/ + const Word32 *Y_fx, /* i : right hand matrix Qy*/ + const Word16 rowsY, /* i : number of rows of the right hand matrix Q0*/ + const Word16 colsY, /* i : number of columns of the right hand matrix Q0*/ + const Word16 transpY, /* i : flag indicating the transposition of the right hand matrix prior to the multiplication Q0*/ + Word32 *Z_fx /* o : resulting matrix after the matrix multiplication Qx + Qy - 31*/ ) { Word16 i, j, k; @@ -1662,9 +1662,9 @@ Word16 matrix_product_fx( move32(); FOR( k = 0; k < rowsX; ++k ) { - x_idx = add( k, imult1616( i, rowsX ) ); - y_idx = add( k, imult1616( j, rowsY ) ); - ( *Zp_fx ) = L_add( *Zp_fx, Mpy_32_32( X_fx[x_idx], Y_fx[y_idx] ) ); + x_idx = add( k, imult1616( i, rowsX ) ); /*Q0*/ + y_idx = add( k, imult1616( j, rowsY ) ); /*Q0*/ + ( *Zp_fx ) = L_add( *Zp_fx, Mpy_32_32( X_fx[x_idx], Y_fx[y_idx] ) ); /*Qx + Qy - 31*/ move32(); } Zp_fx++; @@ -1685,9 +1685,9 @@ Word16 matrix_product_fx( move32(); FOR( k = 0; k < colsX; ++k ) { - x_idx = add( i, imult1616( k, rowsX ) ); - y_idx = add( j, imult1616( k, rowsY ) ); - ( *Zp_fx ) = L_add( *Zp_fx, Mpy_32_32( X_fx[x_idx], Y_fx[y_idx] ) ); + x_idx = add( i, imult1616( k, rowsX ) ); /*Q0*/ + y_idx = add( j, imult1616( k, rowsY ) ); /*Q0*/ + ( *Zp_fx ) = L_add( *Zp_fx, Mpy_32_32( X_fx[x_idx], Y_fx[y_idx] ) ); /*Qx + Qy - 31*/ move32(); } Zp_fx++; @@ -1708,9 +1708,9 @@ Word16 matrix_product_fx( move32(); FOR( k = 0; k < colsX; ++k ) { - x_idx = add( k, imult1616( i, rowsX ) ); - y_idx = add( j, imult1616( k, rowsY ) ); - ( *Zp_fx ) = L_add( *Zp_fx, Mpy_32_32( X_fx[x_idx], Y_fx[y_idx] ) ); + x_idx = add( k, imult1616( i, rowsX ) ); /*Q0*/ + y_idx = add( j, imult1616( k, rowsY ) ); /*Q0*/ + ( *Zp_fx ) = L_add( *Zp_fx, Mpy_32_32( X_fx[x_idx], Y_fx[y_idx] ) ); /*Qx + Qy - 31*/ move32(); } @@ -1733,9 +1733,9 @@ Word16 matrix_product_fx( move32(); FOR( k = 0; k < colsX; ++k ) { - x_idx = add( i, imult1616( k, rowsX ) ); - y_idx = add( k, imult1616( j, rowsY ) ); - ( *Zp_fx ) = L_add( *Zp_fx, Mpy_32_32( X_fx[x_idx], Y_fx[y_idx] ) ); + x_idx = add( i, imult1616( k, rowsX ) ); /*Q0*/ + y_idx = add( k, imult1616( j, rowsY ) ); /*Q0*/ + ( *Zp_fx ) = L_add( *Zp_fx, Mpy_32_32( X_fx[x_idx], Y_fx[y_idx] ) ); /*Qx + Qy - 31*/ move32(); } Zp_fx++; @@ -1747,15 +1747,15 @@ Word16 matrix_product_fx( } Word16 matrix_product_q30_fx( - const Word32 *X_fx, /* i : left hand matrix */ - const Word16 rowsX, /* i : number of rows of the left hand matrix */ - const Word16 colsX, /* i : number of columns of the left hand matrix */ - const Word16 transpX, /* i : flag indicating the transposition of the left hand matrix prior to the multiplication */ - const Word32 *Y_fx, /* i : right hand matrix */ - const Word16 rowsY, /* i : number of rows of the right hand matrix */ - const Word16 colsY, /* i : number of columns of the right hand matrix */ - const Word16 transpY, /* i : flag indicating the transposition of the right hand matrix prior to the multiplication */ - Word32 *Z_fx /* o : resulting matrix after the matrix multiplication */ + const Word32 *X_fx, /* i : left hand matrix Q31*/ + const Word16 rowsX, /* i : number of rows of the left hand matrix Q0*/ + const Word16 colsX, /* i : number of columns of the left hand matrix Q0*/ + const Word16 transpX, /* i : flag indicating the transposition of the left hand matrix prior to the multiplication Q0*/ + const Word32 *Y_fx, /* i : right hand matrix Q25*/ + const Word16 rowsY, /* i : number of rows of the right hand matrix Q0*/ + const Word16 colsY, /* i : number of columns of the right hand matrix Q0*/ + const Word16 transpY, /* i : flag indicating the transposition of the right hand matrix prior to the multiplication Q0*/ + Word32 *Z_fx /* o : resulting matrix after the matrix multiplication Q30*/ ) { Word16 i, j, k; @@ -1783,12 +1783,12 @@ Word16 matrix_product_q30_fx( FOR( k = 0; k < rowsX; ++k ) { //( *Zp_fx ) = L_add( *Zp_fx, Mpy_32_32( X_fx[k + i * rowsX], Y_fx[k + j * rowsY] ) ); - x_idx = add( k, imult1616( i, rowsX ) ); - y_idx = add( k, imult1616( j, rowsY ) ); + x_idx = add( k, imult1616( i, rowsX ) ); /*Q0*/ + y_idx = add( k, imult1616( j, rowsY ) ); /*Q0*/ W_tmp = W_add( W_tmp, W_mult0_32_32( X_fx[x_idx], Y_fx[y_idx] ) ); // Q56 } - W_tmp = W_shl( W_tmp, 6 ); - ( *Zp_fx ) = W_round64_L( W_tmp ); + W_tmp = W_shl( W_tmp, 6 ); /*Q62*/ + ( *Zp_fx ) = W_round64_L( W_tmp ); /*Q30*/ move32(); Zp_fx++; } @@ -1810,12 +1810,12 @@ Word16 matrix_product_q30_fx( FOR( k = 0; k < colsX; ++k ) { //( *Zp_fx ) = L_add( *Zp_fx, Mpy_32_32( X_fx[i + k * rowsX], Y_fx[j + k * rowsY] ) ); - x_idx = add( i, imult1616( k, rowsX ) ); - y_idx = add( j, imult1616( k, rowsY ) ); + x_idx = add( i, imult1616( k, rowsX ) ); /*Q0*/ + y_idx = add( j, imult1616( k, rowsY ) ); /*Q0*/ W_tmp = W_add( W_tmp, W_mult0_32_32( X_fx[x_idx], Y_fx[y_idx] ) ); // Q56 } - W_tmp = W_shl( W_tmp, 6 ); - ( *Zp_fx ) = W_round64_L( W_tmp ); + W_tmp = W_shl( W_tmp, 6 ); /*Q62*/ + ( *Zp_fx ) = W_round64_L( W_tmp ); /*Q30*/ move32(); Zp_fx++; } @@ -1837,13 +1837,13 @@ Word16 matrix_product_q30_fx( FOR( k = 0; k < colsX; ++k ) { //( *Zp_fx ) = L_add( *Zp_fx, Mpy_32_32( X_fx[k + i * rowsX], Y_fx[j + k * rowsY] ) ); - x_idx = add( k, imult1616( i, rowsX ) ); - y_idx = add( j, imult1616( k, rowsY ) ); + x_idx = add( k, imult1616( i, rowsX ) ); /*Q0*/ + y_idx = add( j, imult1616( k, rowsY ) ); /*Q0*/ W_tmp = W_add( W_tmp, W_mult0_32_32( X_fx[k + i * rowsX], Y_fx[j + k * rowsY] ) ); // Q56 } - W_tmp = W_shl( W_tmp, 6 ); - ( *Zp_fx ) = W_round64_L( W_tmp ); + W_tmp = W_shl( W_tmp, 6 ); /*Q62*/ + ( *Zp_fx ) = W_round64_L( W_tmp ); /*Q30*/ move32(); Zp_fx++; } @@ -1866,12 +1866,12 @@ Word16 matrix_product_q30_fx( FOR( k = 0; k < colsX; ++k ) { //( *Zp_fx ) = L_add( *Zp_fx, Mpy_32_32( X_fx[i + k * rowsX], Y_fx[k + j * rowsY] ) ); - x_idx = add( i, imult1616( k, rowsX ) ); - y_idx = add( k, imult1616( j, rowsY ) ); + x_idx = add( i, imult1616( k, rowsX ) ); /*Q0*/ + y_idx = add( k, imult1616( j, rowsY ) ); /*Q0*/ W_tmp = W_add( W_tmp, W_mult0_32_32( X_fx[x_idx], Y_fx[y_idx] ) ); // Q56 } - W_tmp = W_shl( W_tmp, 6 ); - ( *Zp_fx ) = W_round64_L( W_tmp ); + W_tmp = W_shl( W_tmp, 6 ); /*Q62*/ + ( *Zp_fx ) = W_round64_L( W_tmp ); /*Q30*/ move32(); Zp_fx++; } @@ -1882,17 +1882,17 @@ Word16 matrix_product_q30_fx( } /*takes input matrices in mantissa and exponent forms*/ Word16 matrix_product_mant_exp( - const Word32 *X_fx, /* i : left hand matrix */ + const Word32 *X_fx, /* i : left hand matrix Q31 - X_e*/ const Word16 *X_e, /* i : left hand matrix */ - const Word16 rowsX, /* i : number of rows of the left hand matrix */ - const Word16 colsX, /* i : number of columns of the left hand matrix */ - const Word16 transpX, /* i : flag indicating the transposition of the left hand matrix prior to the multiplication */ - const Word32 *Y_fx, /* i : right hand matrix */ + const Word16 rowsX, /* i : number of rows of the left hand matrix Q0*/ + const Word16 colsX, /* i : number of columns of the left hand matrix Q0*/ + const Word16 transpX, /* i : flag indicating the transposition of the left hand matrix prior to the multiplication Q0*/ + const Word32 *Y_fx, /* i : right hand matrix Q31 - Y_e*/ const Word16 *Y_e, /* i : right hand matrix */ - const Word16 rowsY, /* i : number of rows of the right hand matrix */ - const Word16 colsY, /* i : number of columns of the right hand matrix */ - const Word16 transpY, /* i : flag indicating the transposition of the right hand matrix prior to the multiplication */ - Word32 *Z_fx, /* o : resulting matrix after the matrix multiplication */ + const Word16 rowsY, /* i : number of rows of the right hand matrix Q0*/ + const Word16 colsY, /* i : number of columns of the right hand matrix Q0*/ + const Word16 transpY, /* i : flag indicating the transposition of the right hand matrix prior to the multiplication Q0*/ + Word32 *Z_fx, /* o : resulting matrix after the matrix multiplication Q31 - Z_e*/ Word16 *Z_e /* o : resulting matrix after the matrix multiplication */ ) { @@ -1923,10 +1923,10 @@ Word16 matrix_product_mant_exp( move16(); FOR( k = 0; k < rowsX; ++k ) { - x_idx = add( k, imult1616( i, rowsX ) ); - y_idx = add( k, imult1616( j, rowsY ) ); + x_idx = add( k, imult1616( i, rowsX ) ); /*Q0*/ + y_idx = add( k, imult1616( j, rowsY ) ); /*Q0*/ //( *Zp ) += X[k + i * rowsX] * Y[k + j * rowsY]; - L_tmp = Mpy_32_32( X_fx[x_idx], Y_fx[y_idx] ); + L_tmp = Mpy_32_32( X_fx[x_idx], Y_fx[y_idx] ); /*Q31 - (X_e + Y_e)*/ tmp_e = add( X_e[x_idx], Y_e[y_idx] ); ( *Zp ) = BASOP_Util_Add_Mant32Exp( *Zp, *Zp_e, L_tmp, tmp_e, &tmp_e ); @@ -1955,10 +1955,10 @@ Word16 matrix_product_mant_exp( move16(); FOR( k = 0; k < colsX; ++k ) { - x_idx = add( i, imult1616( k, rowsX ) ); - y_idx = add( j, imult1616( k, rowsY ) ); + x_idx = add( i, imult1616( k, rowsX ) ); /*Q0*/ + y_idx = add( j, imult1616( k, rowsY ) ); /*Q0*/ //( *Zp ) += X_fx[i + k * rowsX] * Y_fx[j + k * rowsY]; - L_tmp = Mpy_32_32( X_fx[x_idx], Y_fx[y_idx] ); + L_tmp = Mpy_32_32( X_fx[x_idx], Y_fx[y_idx] ); /*Q31 - (X_e + Y_e)*/ tmp_e = add( X_e[x_idx], Y_e[y_idx] ); ( *Zp ) = BASOP_Util_Add_Mant32Exp( *Zp, *Zp_e, L_tmp, tmp_e, &tmp_e ); @@ -1986,10 +1986,10 @@ Word16 matrix_product_mant_exp( move16(); FOR( k = 0; k < colsX; ++k ) { - x_idx = add( k, imult1616( i, rowsX ) ); - y_idx = add( j, imult1616( k, rowsY ) ); + x_idx = add( k, imult1616( i, rowsX ) ); /*Q0*/ + y_idx = add( j, imult1616( k, rowsY ) ); /*Q0*/ //( *Zp ) += X_fx[k + i * rowsX] * Y_fx[j + k * rowsY]; - L_tmp = Mpy_32_32( X_fx[x_idx], Y_fx[y_idx] ); + L_tmp = Mpy_32_32( X_fx[x_idx], Y_fx[y_idx] ); /*Q31 - (X_e + Y_e)*/ tmp_e = add( X_e[x_idx], Y_e[y_idx] ); ( *Zp ) = BASOP_Util_Add_Mant32Exp( *Zp, *Zp_e, L_tmp, tmp_e, &tmp_e ); @@ -2020,10 +2020,10 @@ Word16 matrix_product_mant_exp( move16(); FOR( k = 0; k < colsX; ++k ) { - x_idx = add( i, imult1616( k, rowsX ) ); - y_idx = add( k, imult1616( j, rowsY ) ); + x_idx = add( i, imult1616( k, rowsX ) ); /*Q0*/ + y_idx = add( k, imult1616( j, rowsY ) ); /*Q0*/ //( *Zp ) += X_fx[i + k * rowsX] * Y_fx[k + j * rowsY]; - L_tmp = Mpy_32_32( X_fx[x_idx], Y_fx[y_idx] ); + L_tmp = Mpy_32_32( X_fx[x_idx], Y_fx[y_idx] ); /*Q31 - (X_e + Y_e)*/ tmp_e = add( X_e[x_idx], Y_e[y_idx] ); ( *Zp ) = BASOP_Util_Add_Mant32Exp( *Zp, *Zp_e, L_tmp, tmp_e, &tmp_e ); @@ -2099,15 +2099,15 @@ int16_t matrix_diag_product( #ifdef IVAS_FLOAT_FIXED Word16 matrix_diag_product_fx( - const Word32 *X, /* i : left hand matrix */ + const Word32 *X, /* i : left hand matrix Q31 - X_e*/ Word16 X_e, - const Word16 rowsX, /* i : number of rows of the left hand matrix */ - const Word16 colsX, /* i : number of columns of the left hand matrix */ - const Word16 transpX, /* i : flag indicating the transposition of the left hand matrix prior to the multiplication */ - const Word32 *Y, /* i : right hand diagonal matrix as vector containing the diagonal elements */ + const Word16 rowsX, /* i : number of rows of the left hand matrix Q0*/ + const Word16 colsX, /* i : number of columns of the left hand matrix Q0*/ + const Word16 transpX, /* i : flag indicating the transposition of the left hand matrix prior to the multiplication Q0*/ + const Word32 *Y, /* i : right hand diagonal matrix as vector containing the diagonal elements Q31 - Y_e*/ Word16 Y_e, - const Word16 entriesY, /* i : number of entries in the diagonal */ - Word32 *Z, /* o : resulting matrix after the matrix multiplication */ + const Word16 entriesY, /* i : number of entries in the diagonal Q0*/ + Word32 *Z, /* o : resulting matrix after the matrix multiplication Q31 - Z_e*/ Word16 *Z_e ) { Word16 i, j; @@ -2126,7 +2126,7 @@ Word16 matrix_diag_product_fx( FOR( i = 0; i < colsX; ++i ) { tmp = add( j, imult1616( i, rowsX ) ); - *( Zp ) = Mpy_32_32( X[tmp], Y[j] ); + *( Zp ) = Mpy_32_32( X[tmp], Y[j] ); /*Q31 - (X_e + Y_e)*/ move32(); Zp++; } @@ -2143,7 +2143,7 @@ Word16 matrix_diag_product_fx( { FOR( i = 0; i < rowsX; ++i ) { - *( Zp ) = Mpy_32_32( *( X ), Y[j] ); + *( Zp ) = Mpy_32_32( *( X ), Y[j] ); /*Q31 - (X_e + Y_e)*/ move32(); Zp++; X++; @@ -2158,15 +2158,15 @@ Word16 matrix_diag_product_fx( } Word16 matrix_diag_product_fx_1( - const Word32 *X, /* i : left hand matrix */ + const Word32 *X, /* i : left hand matrix Q31 - X_e*/ const Word16 *X_e, - const Word16 rowsX, /* i : number of rows of the left hand matrix */ - const Word16 colsX, /* i : number of columns of the left hand matrix */ - const Word16 transpX, /* i : flag indicating the transposition of the left hand matrix prior to the multiplication */ - const Word32 *Y, /* i : right hand diagonal matrix as vector containing the diagonal elements */ + const Word16 rowsX, /* i : number of rows of the left hand matrix Q0*/ + const Word16 colsX, /* i : number of columns of the left hand matrix Q0*/ + const Word16 transpX, /* i : flag indicating the transposition of the left hand matrix prior to the multiplication Q0*/ + const Word32 *Y, /* i : right hand diagonal matrix as vector containing the diagonal elements Q31 - Y_e*/ const Word16 *Y_e, - const Word16 entriesY, /* i : number of entries in the diagonal */ - Word32 *Z, /* o : resulting matrix after the matrix multiplication */ + const Word16 entriesY, /* i : number of entries in the diagonal Q0*/ + Word32 *Z, /* o : resulting matrix after the matrix multiplication Q31 - Z_e*/ Word16 *Z_e ) { Word16 i, j; @@ -2185,8 +2185,8 @@ Word16 matrix_diag_product_fx_1( { FOR( i = 0; i < colsX; ++i ) { - tmp = add( j, imult1616( i, rowsX ) ); - *( Zp ) = Mpy_32_32( X[tmp], Y[j] ); + tmp = add( j, imult1616( i, rowsX ) ); /*Q0*/ + *( Zp ) = Mpy_32_32( X[tmp], Y[j] ); /*Q31 - (X_e + Y_e)*/ move32(); Zp++; *( Z_ep ) = add( X_e[tmp], Y_e[j] ); @@ -2206,7 +2206,7 @@ Word16 matrix_diag_product_fx_1( { FOR( i = 0; i < rowsX; ++i ) { - *( Zp ) = Mpy_32_32( *( X ), Y[j] ); + *( Zp ) = Mpy_32_32( *( X ), Y[j] ); /*Q31 - (X_e + Y_e)*/ move32(); Zp++; *( Z_ep ) = add( *( X_e ), Y_e[j] ); @@ -2224,15 +2224,15 @@ Word16 matrix_diag_product_fx_1( #ifdef IVAS_FLOAT_FIXED Word16 diag_matrix_product_fx( - const Word32 *Y, /* i : left hand diagonal matrix as vector containing the diagonal elements */ + const Word32 *Y, /* i : left hand diagonal matrix as vector containing the diagonal elements Q31 - Y_e*/ Word16 Y_e, - const Word16 entriesY, /* i : length of the diagonal of the left hand matrix */ - const Word32 *X, /* i : right hand matrix */ + const Word16 entriesY, /* i : length of the diagonal of the left hand matrix Q0*/ + const Word32 *X, /* i : right hand matrix Q31 - X_e*/ Word16 X_e, - const Word16 rowsX, /* i : number of rows of the right hand matrix */ - const Word16 colsX, /* i : number of columns of the right hand matrix */ - const Word16 transpX, /* i : flag indicating the transposition of the right hand matrix prior to the multiplication */ - Word32 *Z, /* o : resulting matrix after the matrix multiplication */ + const Word16 rowsX, /* i : number of rows of the right hand matrix Q0*/ + const Word16 colsX, /* i : number of columns of the right hand matrix Q0*/ + const Word16 transpX, /* i : flag indicating the transposition of the right hand matrix prior to the multiplication Q0*/ + Word32 *Z, /* o : resulting matrix after the matrix multiplication Q31 - Z_e*/ Word16 *Z_e ) { Word16 i, j; @@ -2250,8 +2250,8 @@ Word16 diag_matrix_product_fx( { FOR( j = 0; j < entriesY; ++j ) { - tmp = add( i, imult1616( j, rowsX ) ); - *( Zp ) = Mpy_32_32( X[tmp], Y[j] ); + tmp = add( i, imult1616( j, rowsX ) ); /*Q0*/ + *( Zp ) = Mpy_32_32( X[tmp], Y[j] ); /*Q31 - (X_e + Y_e)*/ move32(); Zp++; } @@ -2267,7 +2267,7 @@ Word16 diag_matrix_product_fx( { FOR( j = 0; j < entriesY; ++j ) { - *( Zp ) = Mpy_32_32( *( X ), Y[j] ); + *( Zp ) = Mpy_32_32( *( X ), Y[j] ); /*Q31 - (X_e + Y_e)*/ move32(); Zp++; X++; @@ -2338,17 +2338,17 @@ int16_t diag_matrix_product( #ifdef IVAS_FLOAT_FIXED Word16 matrix_product_diag_fx( - const Word32 *X, /* i : left hand matrix */ + const Word32 *X, /* i : left hand matrix Q31 - X_e*/ Word16 X_e, - const Word16 rowsX, /* i : number of rows of the left hand matrix */ - const Word16 colsX, /* i : number of columns of the left hand matrix */ - const Word16 transpX, /* i : flag indicating the transposition of the left hand matrix prior to the multiplication */ - const Word32 *Y, /* i : right hand matrix */ + const Word16 rowsX, /* i : number of rows of the left hand matrix Q0*/ + const Word16 colsX, /* i : number of columns of the left hand matrix Q0*/ + const Word16 transpX, /* i : flag indicating the transposition of the left hand matrix prior to the multiplication Q0*/ + const Word32 *Y, /* i : right hand matrix Q31 - Y_e*/ Word16 Y_e, - const Word16 rowsY, /* i : number of rows of the right hand matrix */ - const Word16 colsY, /* i : number of columns of the right hand matrix */ - const Word16 transpY, /* i : flag indicating the transposition of the right hand matrix prior to the multiplication */ - Word32 *Z, /* o : resulting matrix after the matrix multiplication */ + const Word16 rowsY, /* i : number of rows of the right hand matrix Q0*/ + const Word16 colsY, /* i : number of columns of the right hand matrix Q0*/ + const Word16 transpY, /* i : flag indicating the transposition of the right hand matrix prior to the multiplication Q0*/ + Word32 *Z, /* o : resulting matrix after the matrix multiplication Q31 - Z_e*/ Word16 *Z_e ) { Word16 j, k; @@ -2372,9 +2372,9 @@ Word16 matrix_product_diag_fx( move32(); FOR( k = 0; k < rowsX; ++k ) { - x_idx = add( k, imult1616( j, rowsX ) ); - y_idx = add( k, imult1616( j, rowsY ) ); - ( *Zp ) = L_add( ( *Zp ), Mpy_32_32( X[x_idx], Y[y_idx] ) ); + x_idx = add( k, imult1616( j, rowsX ) ); /*Q0*/ + y_idx = add( k, imult1616( j, rowsY ) ); /*Q0*/ + ( *Zp ) = L_add( ( *Zp ), Mpy_32_32( X[x_idx], Y[y_idx] ) ); /*Q31 - (X_e + Y_e)*/ move32(); } Zp++; @@ -2392,9 +2392,9 @@ Word16 matrix_product_diag_fx( move32(); FOR( k = 0; k < colsX; ++k ) { - x_idx = add( j, imult1616( k, rowsX ) ); - y_idx = add( j, imult1616( k, rowsY ) ); - ( *Zp ) = L_add( ( *Zp ), Mpy_32_32( X[x_idx], Y[y_idx] ) ); + x_idx = add( j, imult1616( k, rowsX ) ); /*Q0*/ + y_idx = add( j, imult1616( k, rowsY ) ); /*Q0*/ + ( *Zp ) = L_add( ( *Zp ), Mpy_32_32( X[x_idx], Y[y_idx] ) ); /*Q31 - (X_e + Y_e)*/ move32(); } Zp++; @@ -2414,9 +2414,9 @@ Word16 matrix_product_diag_fx( move32(); FOR( k = 0; k < colsX; ++k ) { - x_idx = add( k, imult1616( j, rowsX ) ); - y_idx = add( j, imult1616( k, rowsY ) ); - ( *Zp ) = L_add( ( *Zp ), Mpy_32_32( X[x_idx], Y[y_idx] ) ); + x_idx = add( k, imult1616( j, rowsX ) ); /*Q0*/ + y_idx = add( j, imult1616( k, rowsY ) ); /*Q0*/ + ( *Zp ) = L_add( ( *Zp ), Mpy_32_32( X[x_idx], Y[y_idx] ) ); /*Q31 - (X_e + Y_e)*/ move32(); } @@ -2436,9 +2436,9 @@ Word16 matrix_product_diag_fx( move32(); FOR( k = 0; k < colsX; ++k ) { - x_idx = add( j, imult1616( k, rowsX ) ); - y_idx = add( k, imult1616( j, rowsY ) ); - ( *Zp ) = L_add( ( *Zp ), Mpy_32_32( X[x_idx], Y[y_idx] ) ); + x_idx = add( j, imult1616( k, rowsX ) ); /*Q0*/ + y_idx = add( k, imult1616( j, rowsY ) ); /*Q0*/ + ( *Zp ) = L_add( ( *Zp ), Mpy_32_32( X[x_idx], Y[y_idx] ) ); /*Q31 - (X_e + Y_e)*/ move32(); } Zp++; @@ -2550,12 +2550,12 @@ int16_t matrix_product_diag( #ifdef IVAS_FLOAT_FIXED void cmplx_matrix_square_fx( - const Word32 *realX, /* i : real part of the matrix */ - const Word32 *imagX, /* i : imaginary part of the matrix */ - const Word16 mRows, /* i : number of rows of the matrix */ - const Word16 nCols, /* i : number of columns of the matrix */ - Word32 *realZ, /* o : real part of the resulting matrix */ - Word32 *imagZ, /* o : imaginary part of the resulting matrix */ + const Word32 *realX, /* i : real part of the matrix Q31 - input_exp*/ + const Word32 *imagX, /* i : imaginary part of the matrix Q31 - input_exp*/ + const Word16 mRows, /* i : number of rows of the matrix Q0*/ + const Word16 nCols, /* i : number of columns of the matrix Q0*/ + Word32 *realZ, /* o : real part of the resulting matrix Q31 - output_exp*/ + Word32 *imagZ, /* o : imaginary part of the resulting matrix Q31 - output_exp*/ Word16 input_exp, Word16 *output_exp ) { @@ -2572,12 +2572,12 @@ void cmplx_matrix_square_fx( { FOR( j = i; j < nCols; j++ ) { - p_real1 = realX + imult1616( i, mRows ); - p_imag1 = imagX + imult1616( i, mRows ); - p_real2 = realX + imult1616( j, mRows ); - p_imag2 = imagX + imult1616( j, mRows ); - realZp = realZ + add( i, imult1616( nCols, j ) ); - imagZp = imagZ + add( i, imult1616( nCols, j ) ); + p_real1 = realX + imult1616( i, mRows ); /*Q31 - input_exp*/ + p_imag1 = imagX + imult1616( i, mRows ); /*Q31 - input_exp*/ + p_real2 = realX + imult1616( j, mRows ); /*Q31 - input_exp*/ + p_imag2 = imagX + imult1616( j, mRows ); /*Q31 - input_exp*/ + realZp = realZ + add( i, imult1616( nCols, j ) ); /*Q31 - output_exp*/ + imagZp = imagZ + add( i, imult1616( nCols, j ) ); /*Q31 - output_exp*/ *( realZp ) = 0; move32(); *( imagZp ) = 0; @@ -2585,9 +2585,9 @@ void cmplx_matrix_square_fx( FOR( k = 0; k < mRows; k++ ) { - *( imagZp ) = L_add( *( imagZp ), L_sub( Mpy_32_32( *( p_real1 ), *( p_imag2 ) ), Mpy_32_32( *( p_real2 ), *( p_imag1 ) ) ) ); + *( imagZp ) = L_add( *( imagZp ), L_sub( Mpy_32_32( *( p_real1 ), *( p_imag2 ) ), Mpy_32_32( *( p_real2 ), *( p_imag1 ) ) ) ); /* Q31 - 2*input_exp */ move32(); - *( realZp ) = L_add( *( realZp ), L_add( Mpy_32_32( *( p_real1 ), *( p_real2 ) ), Mpy_32_32( *( p_imag1 ), *( p_imag2 ) ) ) ); + *( realZp ) = L_add( *( realZp ), L_add( Mpy_32_32( *( p_real1 ), *( p_real2 ) ), Mpy_32_32( *( p_imag1 ), *( p_imag2 ) ) ) ); /* Q31 - 2*input_exp */ move32(); p_real1++; p_real2++; @@ -2602,11 +2602,11 @@ void cmplx_matrix_square_fx( { FOR( j = 0; j < i; j++ ) { - tmp1 = add( i, imult1616( nCols, j ) ); - tmp2 = add( j, imult1616( nCols, i ) ); - realZ[tmp1] = realZ[tmp2]; + tmp1 = add( i, imult1616( nCols, j ) ); /*Q0*/ + tmp2 = add( j, imult1616( nCols, i ) ); /*Q0*/ + realZ[tmp1] = realZ[tmp2]; /*Q31 - output_exp*/ move32(); - imagZ[tmp1] = imagZ[tmp2]; + imagZ[tmp1] = imagZ[tmp2]; /*Q31 - output_exp*/ move32(); } } @@ -2702,10 +2702,10 @@ void v_multc_acc( #ifdef IVAS_FLOAT_FIXED void v_multc_acc_32_16( - const Word32 x[], /* i : Input vector */ - const Word16 c, /* i : Constant */ - Word32 y[], /* o : Output vector that contains y + c*x */ - const Word16 N /* i : Vector length */ + const Word32 x[], /* i : Input vector Qx*/ + const Word16 c, /* i : Constant Q31*/ + Word32 y[], /* o : Output vector that contains y + c*x Qx*/ + const Word16 N /* i : Vector length Q0*/ ) { Word16 i; @@ -2719,17 +2719,17 @@ void v_multc_acc_32_16( return; } void v_multc_acc_32_32( - const Word32 x[], /* i : Input vector */ - const Word32 c, /* i : Constant */ - Word32 y[], /* o : Output vector that contains y + c*x */ - const Word16 N /* i : Vector length */ + const Word32 x[], /* i : Input vector Qx*/ + const Word32 c, /* i : Constant Q31*/ + Word32 y[], /* o : Output vector that contains y + c*x Qx*/ + const Word16 N /* i : Vector length Q0*/ ) { Word16 i; FOR( i = 0; i < N; i++ ) { - y[i] = L_add( y[i], Mpy_32_32( x[i], c ) ); + y[i] = L_add( y[i], Mpy_32_32( x[i], c ) ); /*Qx*/ move32(); } @@ -2793,11 +2793,11 @@ void lls_interp_n( #ifdef IVAS_FLOAT_FIXED void lls_interp_n_fx( - Word16 x_fx[], /* i/o: input/output vector */ - const Word16 N, /* i : length of the input vector */ - Word16 *a_fx, /* o : calculated slope */ - Word16 *b_fx, /* o : calculated offset */ - const Word16 upd /* i : use 1 to update x[] with the interpolated output */ + Word16 x_fx[], /* i/o: input/output vector Q15*/ + const Word16 N, /* i : length of the input vector Q0*/ + Word16 *a_fx, /* o : calculated slope Q15*/ + Word16 *b_fx, /* o : calculated offset Q15*/ + const Word16 upd /* i : use 1 to update x[] with the interpolated output Q0*/ ) { Word16 i; @@ -2814,7 +2814,7 @@ void lls_interp_n_fx( move16(); move16(); - const Word16 one_by_n_fx[11] = { 0, 32767, 16384, 10911, 8192, 6553, 5459, 4681, 4096, 3640, 3276 }; + const Word16 one_by_n_fx[11] = { 0, 32767, 16384, 10911, 8192, 6553, 5459, 4681, 4096, 3640, 3276 }; /*Q15*/ move16(); move16(); move16(); @@ -2827,7 +2827,7 @@ void lls_interp_n_fx( move16(); move16(); - const Word16 sum_i_fx[12] = { 0, 0, 1, 3, 6, 10, 15, 21, 28, 36, 45, 55 }; + const Word16 sum_i_fx[12] = { 0, 0, 1, 3, 6, 10, 15, 21, 28, 36, 45, 55 }; /*Q0*/ move16(); move16(); move16(); @@ -2842,7 +2842,7 @@ void lls_interp_n_fx( move16(); // 1.0f/ ( N * sum_ii[N] - sum_i[N] * sum_i[N] ) - const Word32 res_table[12] = { 0, 0, 0, 357913952, 107374184, 42949672, 20452226, 10956549, 6391320, 3976821, 2603010, 385 }; + const Word32 res_table[12] = { 0, 0, 0, 357913952, 107374184, 42949672, 20452226, 10956549, 6391320, 3976821, 2603010, 385 }; /*Q31*/ move16(); move16(); move16(); @@ -2873,15 +2873,15 @@ void lls_interp_n_fx( FOR( int idx = 0; idx < N; idx++ ) #endif { - sum_x_fx = L_add( sum_x_fx, x_fx[idx] ); + sum_x_fx = L_add( sum_x_fx, x_fx[idx] ); /*Q15*/ } - sum_ix_fx = dotp_fx( x_fx, n_i_fx, N, &dot_exp ); + sum_ix_fx = dotp_fx( x_fx, n_i_fx, N, &dot_exp ); /*sum_ix_q*/ sum_ix_q = sub( 30, sub( dot_exp, ( 11 + 15 ) ) ); - sum_ix_fx = L_shr( sum_ix_fx, sub( sum_ix_q, 15 ) ); - num = L_sub( imult3216( sum_ix_fx, N ), imult3216( sum_x_fx, sum_i_fx[N] ) ); - slope_fx = Mpy_32_32( num, res_table[N] ); - offset_fx = Mpy_32_16_1( L_sub( sum_x_fx, imult3216( slope_fx, sum_i_fx[N] ) ), one_by_n_fx[N] ); + sum_ix_fx = L_shr( sum_ix_fx, sub( sum_ix_q, 15 ) ); /*Q15*/ + num = L_sub( imult3216( sum_ix_fx, N ), imult3216( sum_x_fx, sum_i_fx[N] ) ); /*Q15*/ + slope_fx = Mpy_32_32( num, res_table[N] ); /*Q15*/ + offset_fx = Mpy_32_16_1( L_sub( sum_x_fx, imult3216( slope_fx, sum_i_fx[N] ) ), one_by_n_fx[N] ); /*Q15*/ IF( upd ) { @@ -2889,12 +2889,12 @@ void lls_interp_n_fx( { IF( GT_32( imult3216( slope_fx, i ), MAX_WORD16 ) ) { - x_fx[i] = MAX_WORD16; + x_fx[i] = MAX_WORD16; /*Q15*/ move16(); } ELSE { - x_fx[i] = extract_l( L_add_sat( imult3216( slope_fx, i ), offset_fx ) ); + x_fx[i] = extract_l( L_add_sat( imult3216( slope_fx, i ), offset_fx ) ); /*Q15*/ move16(); } } @@ -2902,13 +2902,13 @@ void lls_interp_n_fx( IF( a_fx != NULL ) { - *a_fx = extract_l( slope_fx ); + *a_fx = extract_l( slope_fx ); /*Q15*/ move16(); } IF( b_fx != NULL ) { - *b_fx = extract_l( offset_fx ); + *b_fx = extract_l( offset_fx ); /*Q15*/ move16(); } @@ -2941,21 +2941,21 @@ static float wrap_azi( static Word32 wrap_azi_fx( const Word32 azi_deg /* Q22 */ ) { - Word32 azi = azi_deg; + Word32 azi = azi_deg; /*Q22*/ move32(); /* Wrap azimuth value */ WHILE( GT_32( azi, ANGLE_180_DEG_Q22 ) ) { - azi = L_sub( azi, ANGLE_360_DEG_Q22 ); + azi = L_sub( azi, ANGLE_360_DEG_Q22 ); /*Q22*/ } WHILE( LE_32( azi, -ANGLE_180_DEG_Q22 ) ) { - azi = L_add( azi, ANGLE_360_DEG_Q22 ); + azi = L_add( azi, ANGLE_360_DEG_Q22 ); /*Q22*/ } - return azi; + return azi; /*Q22*/ } #endif /*-------------------------------------------------------------------* @@ -3043,16 +3043,16 @@ void panning_wrap_angles_fx( { Word32 azi, ele; - azi = azi_deg; + azi = azi_deg; /*Q22*/ move32(); - ele = ele_deg; + ele = ele_deg; /*Q22*/ move32(); IF( LT_32( L_abs( ele ), ANGLE_90_DEG_Q22 ) ) { - *ele_wrapped = ele; + *ele_wrapped = ele; /*Q22*/ move32(); - *azi_wrapped = wrap_azi_fx( azi ); + *azi_wrapped = wrap_azi_fx( azi ); /*Q22*/ move32(); return; } @@ -3092,9 +3092,9 @@ void panning_wrap_angles_fx( ele = L_sub( -ANGLE_180_DEG_Q22, ele ); } } - *azi_wrapped = wrap_azi_fx( azi ); + *azi_wrapped = wrap_azi_fx( azi ); /*Q22*/ move32(); - *ele_wrapped = ele; + *ele_wrapped = ele; /*Q22*/ move32(); } @@ -3150,9 +3150,9 @@ void v_sort_ind( *-------------------------------------------------------------------------*/ void v_sort_ind_fixed( - Word32 *x, /* i/o: Vector to be sorted */ - Word16 *idx, /* o : Original index positions */ - const Word16 len /* i : vector length */ + Word32 *x, /* i/o: Vector to be sorted Qx*/ + Word16 *idx, /* o : Original index positions Q0*/ + const Word16 len /* i : vector length Q0*/ ) { Word16 i, j; @@ -3167,22 +3167,22 @@ void v_sort_ind_fixed( FOR( i = len - 2; i >= 0; i-- ) { - tempr = x[i]; + tempr = x[i]; /*Qx*/ move32(); - tempi = idx[i]; + tempi = idx[i]; /*Qx*/ move16(); test(); - FOR( j = add( i, 1 ); LT_16( j, len ) && GT_32( tempr, x[j] ); j++ ) + FOR( j = ( i + 1 ); LT_16( j, len ) && GT_32( tempr, x[j] ); j++ ) { test(); - x[j - 1] = x[j]; + x[j - 1] = x[j]; /*Qx*/ move32(); - idx[j - 1] = idx[j]; + idx[j - 1] = idx[j]; /*Qx*/ move16(); } - x[j - 1] = tempr; + x[j - 1] = tempr; /*Qx*/ move32(); - idx[j - 1] = tempi; + idx[j - 1] = tempi; /*Qx*/ move16(); } @@ -3198,7 +3198,7 @@ void v_sort_ind_fixed( /*! r: flag indicating a valid bitrate */ Word16 is_IVAS_bitrate_fx( - const Word32 ivas_total_brate /* i : IVAS total bitrate */ + const Word32 ivas_total_brate /* i : IVAS total bitrate Q0*/ ) { Word16 j; @@ -3229,7 +3229,7 @@ Word16 is_IVAS_bitrate_fx( #ifdef IVAS_FLOAT_FIXED Word16 is_DTXrate( - const Word32 ivas_total_brate /* i : IVAS total bitrate */ + const Word32 ivas_total_brate /* i : IVAS total bitrate Q0*/ ) { Word16 dtx_rate_flag = 0; @@ -3242,7 +3242,7 @@ Word16 is_DTXrate( move16(); } - return dtx_rate_flag; + return dtx_rate_flag; /*Q0*/ } #else int16_t is_DTXrate( @@ -3268,7 +3268,7 @@ int16_t is_DTXrate( #ifdef IVAS_FLOAT_FIXED Word16 is_SIDrate( - const Word32 ivas_total_brate /* i : IVAS total bitrate */ + const Word32 ivas_total_brate /* i : IVAS total bitrate Q0*/ ) { Word16 sid_rate_flag = 0; @@ -3284,7 +3284,7 @@ Word16 is_SIDrate( move16(); } - return sid_rate_flag; + return sid_rate_flag; /*Q0*/ } #else int16_t is_SIDrate( @@ -3330,7 +3330,7 @@ float rand_triangular_signed( #ifdef IVAS_FLOAT_FIXED Word16 rand_triangular_signed_fx( - Word16 *seed, + Word16 *seed, /*Q0*/ Word16 *exp_fac ) { Word16 rand_val; @@ -3342,9 +3342,9 @@ Word16 rand_triangular_signed_fx( { /* rand_val in [-1, 0] */ /*0.5f * (sqrtf(rand_val + 1.0f) - 1)*/ - tmp1 = Sqrt16( add( shr( rand_val, 1 ), ONE_IN_Q14 ), &exp ); - exp1 = BASOP_Util_Add_MantExp( tmp1, exp, negate( ONE_IN_Q14 ), 1, &tmp2 ); - tmp2 = shr( tmp2, 1 ); + tmp1 = Sqrt16( add( shr( rand_val, 1 ), ONE_IN_Q14 ), &exp ); /*Q15 - exp*/ + exp1 = BASOP_Util_Add_MantExp( tmp1, exp, negate( ONE_IN_Q14 ), 1, &tmp2 ); /*Q15 - exp1*/ + tmp2 = shr( tmp2, 1 ); /*Q15 - exp1*/ *exp_fac = exp1; move16(); return tmp2; @@ -3353,16 +3353,16 @@ Word16 rand_triangular_signed_fx( { /* rand_val in (0, 1) */ /*0.5f * ( 1 - sqrtf(1.0f - rand_val))*/ - Word16 one_minus_rand = sub( MAX16B, rand_val ); + Word16 one_minus_rand = sub( MAX16B, rand_val ); /*Q15*/ exp = 0; move16(); - tmp1 = Sqrt16( one_minus_rand, &exp ); // q15 - exp - exp1 = BASOP_Util_Add_MantExp( ONE_IN_Q14, 1, negate( tmp1 ), exp, &tmp2 ); - tmp2 = shr( tmp2, 1 ); + tmp1 = Sqrt16( one_minus_rand, &exp ); // q15 - exp + exp1 = BASOP_Util_Add_MantExp( ONE_IN_Q14, 1, negate( tmp1 ), exp, &tmp2 ); /*Q15 - exp1*/ + tmp2 = shr( tmp2, 1 ); /*Q15 - exp1*/ *exp_fac = exp1; move16(); - return tmp2; + return tmp2; /*Q15 - exp_fac*/ } } @@ -3372,7 +3372,7 @@ Word16 rand_triangular_signed_fx( * calculates ceil(log2(val)) *-------------------------------------------------------------------*/ Word16 ceil_log_2( - UWord64 val ) + UWord64 val /*Q0*/ ) { IF( val <= 0 ) @@ -3648,8 +3648,8 @@ Word16 ceil_log_2( *-------------------------------------------------------------------*/ Word64 var_32_fx( - const Word32 *x, /* i : input vector */ - const Word16 len, /* i : length of inputvector */ + const Word32 *x, /* i : input vector q*/ + const Word16 len, /* i : length of inputvector Q0*/ Word16 q /* q : q-factor for the array */ ) { @@ -3663,20 +3663,20 @@ Word64 var_32_fx( FOR( int i = 0; i < len; i++ ) { - mean = W_add( mean, x[i] ); + mean = W_add( mean, x[i] ); /*q*/ } - mean = mean / len; /* NOTE: No BASOP for 64 bit division */ + mean = mean / len; /* NOTE: No BASOP for 64 bit division q*/ FOR( int i = 0; i < len; i++ ) { - var = W_add( var, Mpy_32_32( L_sub( x[i], W_extract_l( mean ) ), L_sub( x[i], W_extract_l( mean ) ) ) ); + var = W_add( var, Mpy_32_32( L_sub( x[i], W_extract_l( mean ) ), L_sub( x[i], W_extract_l( mean ) ) ) ); /*q + q - 31*/ } - var = W_shl( var, sub( 31, q ) ); + var = W_shl( var, sub( 31, q ) ); /*q*/ - var = var / len; /* NOTE: No BASOP for 64 bit division */ + var = var / len; /* NOTE: No BASOP for 64 bit division q*/ - return var; + return var; /*q*/ } #endif diff --git a/lib_com/ivas_transient_det.c b/lib_com/ivas_transient_det.c index 019874fc9..a41e5ea92 100644 --- a/lib_com/ivas_transient_det.c +++ b/lib_com/ivas_transient_det.c @@ -127,7 +127,7 @@ #ifdef IVAS_FLOAT_FIXED static void ivas_transient_det_init( ivas_trans_det_state_t *hTranDet, /* i/o: Transient detector handle */ - const Word32 sampling_rate /* i : sampling rate */ + const Word32 sampling_rate /* i : sampling rate Q0*/ ) { Word16 i; @@ -148,104 +148,104 @@ static void ivas_transient_det_init( { case 48000: /*env_hpf*/ - filt_coeff_arr_fx[0][0] = IVAS_C_HPF_48k_fx; + filt_coeff_arr_fx[0][0] = IVAS_C_HPF_48k_fx; /*Q30*/ move32(); - filt_coeff_arr_fx[0][1] = L_negate( IVAS_C_HPF_48k_fx ); + filt_coeff_arr_fx[0][1] = L_negate( IVAS_C_HPF_48k_fx ); /*Q30*/ move32(); - filt_coeff_arr_fx[0][3] = ONE_IN_Q30; + filt_coeff_arr_fx[0][3] = ONE_IN_Q30; /*Q30*/ move32(); - filt_coeff_arr_fx[0][4] = L_negate( IVAS_C_HPF_48k_fx ); + filt_coeff_arr_fx[0][4] = L_negate( IVAS_C_HPF_48k_fx ); /*Q30*/ move32(); /*env_fast*/ - filt_coeff_arr_fx[1][0] = L_sub( ONE_IN_Q30, IVAS_C_FAST_48k_fx ); + filt_coeff_arr_fx[1][0] = L_sub( ONE_IN_Q30, IVAS_C_FAST_48k_fx ); /*Q30*/ move32(); - filt_coeff_arr_fx[1][3] = ONE_IN_Q30; + filt_coeff_arr_fx[1][3] = ONE_IN_Q30; /*Q30*/ move32(); - filt_coeff_arr_fx[1][4] = L_negate( IVAS_C_FAST_48k_fx ); + filt_coeff_arr_fx[1][4] = L_negate( IVAS_C_FAST_48k_fx ); /*Q30*/ move32(); /*env_slow*/ - filt_coeff_arr_fx[2][0] = L_sub( ONE_IN_Q30, IVAS_C_SLOW_48k_fx ); + filt_coeff_arr_fx[2][0] = L_sub( ONE_IN_Q30, IVAS_C_SLOW_48k_fx ); /*Q30*/ move32(); - filt_coeff_arr_fx[2][3] = ONE_IN_Q30; + filt_coeff_arr_fx[2][3] = ONE_IN_Q30; /*Q30*/ move32(); - filt_coeff_arr_fx[2][4] = L_negate( IVAS_C_SLOW_48k_fx ); + filt_coeff_arr_fx[2][4] = L_negate( IVAS_C_SLOW_48k_fx ); /*Q30*/ move32(); - hTranDet->in_duck_coeff = IVAS_C_IN_DUCK_48k_fx; + hTranDet->in_duck_coeff = IVAS_C_IN_DUCK_48k_fx; /*Q30*/ move32(); - hTranDet->out_duck_coeff = IVAS_C_OUT_DUCK_48k_fx; + hTranDet->out_duck_coeff = IVAS_C_OUT_DUCK_48k_fx; /*Q30*/ move32(); BREAK; case 32000: /*env_hpf*/ - filt_coeff_arr_fx[0][0] = IVAS_C_HPF_32k_fx; + filt_coeff_arr_fx[0][0] = IVAS_C_HPF_32k_fx; /*Q30*/ move32(); - filt_coeff_arr_fx[0][1] = L_negate( IVAS_C_HPF_32k_fx ); + filt_coeff_arr_fx[0][1] = L_negate( IVAS_C_HPF_32k_fx ); /*Q30*/ move32(); - filt_coeff_arr_fx[0][3] = ONE_IN_Q30; + filt_coeff_arr_fx[0][3] = ONE_IN_Q30; /*Q30*/ move32(); - filt_coeff_arr_fx[0][4] = L_negate( IVAS_C_HPF_32k_fx ); + filt_coeff_arr_fx[0][4] = L_negate( IVAS_C_HPF_32k_fx ); /*Q30*/ move32(); /*env_fast*/ - filt_coeff_arr_fx[1][0] = L_sub( ONE_IN_Q30, IVAS_C_FAST_32k_fx ); + filt_coeff_arr_fx[1][0] = L_sub( ONE_IN_Q30, IVAS_C_FAST_32k_fx ); /*Q30*/ move32(); - filt_coeff_arr_fx[1][3] = ONE_IN_Q30; + filt_coeff_arr_fx[1][3] = ONE_IN_Q30; /*Q30*/ move32(); - filt_coeff_arr_fx[1][4] = L_negate( IVAS_C_FAST_32k_fx ); + filt_coeff_arr_fx[1][4] = L_negate( IVAS_C_FAST_32k_fx ); /*Q30*/ move32(); /*env_slow*/ - filt_coeff_arr_fx[2][0] = L_sub( ONE_IN_Q30, IVAS_C_SLOW_32k_fx ); + filt_coeff_arr_fx[2][0] = L_sub( ONE_IN_Q30, IVAS_C_SLOW_32k_fx ); /*Q30*/ move32(); - filt_coeff_arr_fx[2][3] = ONE_IN_Q30; + filt_coeff_arr_fx[2][3] = ONE_IN_Q30; /*Q30*/ move32(); - filt_coeff_arr_fx[2][4] = L_negate( IVAS_C_SLOW_32k_fx ); + filt_coeff_arr_fx[2][4] = L_negate( IVAS_C_SLOW_32k_fx ); /*Q30*/ move32(); - hTranDet->in_duck_coeff = IVAS_C_IN_DUCK_32k_fx; + hTranDet->in_duck_coeff = IVAS_C_IN_DUCK_32k_fx; /*Q30*/ move32(); - hTranDet->out_duck_coeff = IVAS_C_OUT_DUCK_32k_fx; + hTranDet->out_duck_coeff = IVAS_C_OUT_DUCK_32k_fx; /*Q30*/ move32(); BREAK; case 16000: /*env_hpf*/ - filt_coeff_arr_fx[0][0] = IVAS_C_HPF_16k_fx; + filt_coeff_arr_fx[0][0] = IVAS_C_HPF_16k_fx; /*Q30*/ move32(); - filt_coeff_arr_fx[0][1] = L_negate( IVAS_C_HPF_16k_fx ); + filt_coeff_arr_fx[0][1] = L_negate( IVAS_C_HPF_16k_fx ); /*Q30*/ move32(); - filt_coeff_arr_fx[0][3] = ONE_IN_Q30; + filt_coeff_arr_fx[0][3] = ONE_IN_Q30; /*Q30*/ move32(); - filt_coeff_arr_fx[0][4] = L_negate( IVAS_C_HPF_16k_fx ); + filt_coeff_arr_fx[0][4] = L_negate( IVAS_C_HPF_16k_fx ); /*Q30*/ move32(); /*env_fast*/ - filt_coeff_arr_fx[1][0] = L_sub( ONE_IN_Q30, IVAS_C_FAST_16k_fx ); + filt_coeff_arr_fx[1][0] = L_sub( ONE_IN_Q30, IVAS_C_FAST_16k_fx ); /*Q30*/ move32(); - filt_coeff_arr_fx[1][3] = ONE_IN_Q30; + filt_coeff_arr_fx[1][3] = ONE_IN_Q30; /*Q30*/ move32(); - filt_coeff_arr_fx[1][4] = L_negate( IVAS_C_FAST_16k_fx ); + filt_coeff_arr_fx[1][4] = L_negate( IVAS_C_FAST_16k_fx ); /*Q30*/ move32(); /*env_slow*/ - filt_coeff_arr_fx[2][0] = L_sub( ONE_IN_Q30, IVAS_C_SLOW_16k_fx ); + filt_coeff_arr_fx[2][0] = L_sub( ONE_IN_Q30, IVAS_C_SLOW_16k_fx ); /*Q30*/ move32(); - filt_coeff_arr_fx[2][3] = ONE_IN_Q30; + filt_coeff_arr_fx[2][3] = ONE_IN_Q30; /*Q30*/ move32(); - filt_coeff_arr_fx[2][4] = L_negate( IVAS_C_SLOW_16k_fx ); + filt_coeff_arr_fx[2][4] = L_negate( IVAS_C_SLOW_16k_fx ); /*Q30*/ move32(); - hTranDet->in_duck_coeff = IVAS_C_IN_DUCK_16k_fx; + hTranDet->in_duck_coeff = IVAS_C_IN_DUCK_16k_fx; /*Q30*/ move32(); - hTranDet->out_duck_coeff = IVAS_C_OUT_DUCK_16k_fx; + hTranDet->out_duck_coeff = IVAS_C_OUT_DUCK_16k_fx; /*Q30*/ move32(); @@ -256,7 +256,7 @@ static void ivas_transient_det_init( ivas_filters_init_fx( &hTranDet->env_fast, (const Word32 *) filt_coeff_arr_fx[1], filt_coeff_arr_e, IVAS_FILTER_ORDER_1 ); ivas_filters_init_fx( &hTranDet->env_slow, (const Word32 *) filt_coeff_arr_fx[2], filt_coeff_arr_e, IVAS_FILTER_ORDER_1 ); - hTranDet->duck_mult_fac = IVAS_TDET_DUCK_MULT_FAC; + hTranDet->duck_mult_fac = IVAS_TDET_DUCK_MULT_FAC; /*Q29*/ move32(); return; @@ -353,7 +353,7 @@ static void ivas_transient_det_init( #ifdef IVAS_FLOAT_FIXED ivas_error ivas_transient_det_open_fx( ivas_trans_det_state_t **hTranDet_in, /* i/o: Transient detector handle */ - const Word32 sampling_rate /* i : sampling rate */ + const Word32 sampling_rate /* i : sampling rate Q0*/ ) { ivas_trans_det_state_t *hTranDet; @@ -439,14 +439,14 @@ void ivas_transient_det_close( void ivas_transient_det_process_fx( ivas_trans_det_state_t *hTranDet, /* i/o: SPAR TD handle */ - Word32 *pIn_pcm, /* i : input audio channels */ - const Word16 frame_len, /* i : frame length in samples */ - Word16 transient_det[2] /* o : transient det outputs */ + Word32 *pIn_pcm, /* i : input audio channels Q11*/ + const Word16 frame_len, /* i : frame length in samples Q0*/ + Word16 transient_det[2] /* o : transient det outputs Q0*/ ) { Word32 in_duck_gain[L_FRAME48k]; Word16 num_sf, sf, sf_samp, idx; - Word32 mem = hTranDet->in_duck_gain; + Word32 mem = hTranDet->in_duck_gain; /*Q30*/ move32(); ivas_td_decorr_get_ducking_gains_fx( hTranDet, pIn_pcm, in_duck_gain, NULL, frame_len, IVAS_TDET_ONLY ); @@ -460,9 +460,9 @@ void ivas_transient_det_process_fx( move16(); } - num_sf = 16; + num_sf = 16; /*Q0*/ move16(); - sf_samp = idiv1616( frame_len, num_sf ); + sf_samp = idiv1616( frame_len, num_sf ); /*Q0*/ FOR( sf = 1; sf <= num_sf; sf++ ) { idx = sub( imult1616( sf_samp, sf ), 1 ); @@ -471,7 +471,7 @@ void ivas_transient_det_process_fx( transient_det[1] = 1; move16(); } - mem = in_duck_gain[idx]; + mem = in_duck_gain[idx]; /*Q30*/ move32(); } @@ -552,15 +552,15 @@ static float ivas_calc_duck_gain( *-----------------------------------------------------------------------------------------*/ static Word32 ivas_calc_duck_gain_fx( - const Word32 duck_gain, - const Word32 duck_coeff, - const Word32 env_1, - const Word32 env_2, - const Word32 duck_mult_fac ) + const Word32 duck_gain, /*Q30*/ + const Word32 duck_coeff, /*Q30*/ + const Word32 env_1, /*Q14*/ + const Word32 env_2, /*Q14*/ + const Word32 duck_mult_fac /*Q29*/ ) { Word32 duck_gain_out; - duck_gain_out = L_add( L_shl( Mpy_32_32( L_sub( duck_gain, ONE_IN_Q30 ), duck_coeff ), Q1 ), ONE_IN_Q30 ); + duck_gain_out = L_add( L_shl( Mpy_32_32( L_sub( duck_gain, ONE_IN_Q30 ), duck_coeff ), Q1 ), ONE_IN_Q30 ); /*Q30*/ IF( LT_32( Mpy_32_32( duck_mult_fac, env_1 ), Mpy_32_32( L_shr( duck_gain_out, 1 ), env_2 ) ) ) { @@ -572,12 +572,12 @@ static Word32 ivas_calc_duck_gain_fx( } ELSE { - duck_gain_out = Mpy_32_32( duck_mult_fac, L_shl( (Word32) ( divide3232( env_1, env_2 ) ), Q16 ) ); - duck_gain_out = L_shl( duck_gain_out, Q1 ); + duck_gain_out = Mpy_32_32( duck_mult_fac, L_shl( (Word32) ( divide3232( env_1, env_2 ) ), Q16 ) ); /*Q29*/ + duck_gain_out = L_shl( duck_gain_out, Q1 ); /*Q30*/ } } - return duck_gain_out; + return duck_gain_out; /*Q30*/ } #endif #ifndef IVAS_FLOAT_FIXED @@ -654,27 +654,27 @@ void ivas_td_decorr_get_ducking_gains( void ivas_td_decorr_get_ducking_gains_fx( ivas_trans_det_state_t *hTranDet, /* i/o: Transient detector handle */ - Word32 *pIn_pcm, - Word32 *pIn_duck_gains, - Word32 *pOut_duck_gains, - const Word16 frame_len, - const Word16 tdet_flag ) + Word32 *pIn_pcm, /*Q11*/ + Word32 *pIn_duck_gains, /*Q30*/ + Word32 *pOut_duck_gains, /*Q30*/ + const Word16 frame_len, /*Q0*/ + const Word16 tdet_flag /*Q0*/ ) { Word16 i, q = Q14; move16(); Word32 e_fast_fx[L_FRAME48k], e_slow_fx[L_FRAME48k]; - Word32 in_duck_gain = hTranDet->in_duck_gain; + Word32 in_duck_gain = hTranDet->in_duck_gain; /*Q30*/ move32(); - Word32 out_duck_gain = hTranDet->out_duck_gain; + Word32 out_duck_gain = hTranDet->out_duck_gain; /*Q30*/ move32(); - Word32 in_duck_coeff = hTranDet->in_duck_coeff; + Word32 in_duck_coeff = hTranDet->in_duck_coeff; /*Q30*/ move32(); - Word32 out_duck_coeff = hTranDet->out_duck_coeff; + Word32 out_duck_coeff = hTranDet->out_duck_coeff; /*Q30*/ move32(); - Word32 duck_mult_fac = hTranDet->duck_mult_fac; + Word32 duck_mult_fac = hTranDet->duck_mult_fac; /*Q29*/ move32(); - Copy32( pIn_pcm, e_fast_fx, frame_len ); + Copy32( pIn_pcm, e_fast_fx, frame_len ); /*Q11*/ /* env hpf */ ivas_filter_process_fx( &hTranDet->env_hpf, e_fast_fx, frame_len, q ); @@ -683,9 +683,9 @@ void ivas_td_decorr_get_ducking_gains_fx( FOR( i = 0; i < frame_len; i++ ) { - e_fast_fx[i] = L_add( L_abs( e_fast_fx[i] ), L_shr( IVAS_TDET_PARM_ENV_EPS_fx, q_factor_diff ) ); + e_fast_fx[i] = L_add( L_abs( e_fast_fx[i] ), L_shr( IVAS_TDET_PARM_ENV_EPS_fx, q_factor_diff ) ); /*Q14*/ move32(); - e_slow_fx[i] = e_fast_fx[i]; + e_slow_fx[i] = e_fast_fx[i]; /*Q14*/ move32(); } @@ -699,27 +699,27 @@ void ivas_td_decorr_get_ducking_gains_fx( { FOR( i = 0; i < frame_len; i++ ) { - in_duck_gain = ivas_calc_duck_gain_fx( in_duck_gain, in_duck_coeff, e_slow_fx[i], e_fast_fx[i], duck_mult_fac ); - pIn_duck_gains[i] = in_duck_gain; + in_duck_gain = ivas_calc_duck_gain_fx( in_duck_gain, in_duck_coeff, e_slow_fx[i], e_fast_fx[i], duck_mult_fac ); /*Q30*/ + pIn_duck_gains[i] = in_duck_gain; /*Q30*/ move32(); } - hTranDet->in_duck_gain = in_duck_gain; + hTranDet->in_duck_gain = in_duck_gain; /*Q30*/ move32(); } ELSE { FOR( i = 0; i < frame_len; i++ ) { - in_duck_gain = ivas_calc_duck_gain_fx( in_duck_gain, in_duck_coeff, e_slow_fx[i], e_fast_fx[i], duck_mult_fac ); - pIn_duck_gains[i] = in_duck_gain; + in_duck_gain = ivas_calc_duck_gain_fx( in_duck_gain, in_duck_coeff, e_slow_fx[i], e_fast_fx[i], duck_mult_fac ); /*Q30*/ + pIn_duck_gains[i] = in_duck_gain; /*Q30*/ move32(); - out_duck_gain = ivas_calc_duck_gain_fx( out_duck_gain, out_duck_coeff, e_fast_fx[i], e_slow_fx[i], duck_mult_fac ); - pOut_duck_gains[i] = out_duck_gain; + out_duck_gain = ivas_calc_duck_gain_fx( out_duck_gain, out_duck_coeff, e_fast_fx[i], e_slow_fx[i], duck_mult_fac ); /*Q30*/ + pOut_duck_gains[i] = out_duck_gain; /*Q30*/ move32(); } - hTranDet->in_duck_gain = in_duck_gain; + hTranDet->in_duck_gain = in_duck_gain; /*Q30*/ move32(); - hTranDet->out_duck_gain = out_duck_gain; + hTranDet->out_duck_gain = out_duck_gain; /*Q30*/ move32(); } diff --git a/lib_com/lag_wind.c b/lib_com/lag_wind.c index 2d1ec48da..82279af86 100644 --- a/lib_com/lag_wind.c +++ b/lib_com/lag_wind.c @@ -175,11 +175,11 @@ void adapt_lag_wind_fx( *-------------------------------------------------------------*/ void lag_wind( - Word16 r_h[], /* in/out: autocorrelations */ - Word16 r_l[], /* in/out: autocorrelations */ - Word16 m, /* input : order of LP filter */ - Word32 sr_core, /* input : sampling rate */ - Word16 strength /* input : LAGW_WEAK, LAGW_MEDIUM, or LAGW_STRONG */ + Word16 r_h[], /* in/out: autocorrelations Q15(Q_r -16)*/ + Word16 r_l[], /* in/out: autocorrelations Q(r)-1*/ + Word16 m, /* input : order of LP filter Q0*/ + Word32 sr_core, /* input : sampling rate Q0*/ + Word16 strength /* input : LAGW_WEAK, LAGW_MEDIUM, or LAGW_STRONG Q0*/ ) { Word16 i; @@ -193,35 +193,35 @@ void lag_wind( case 8000: assert( m <= 16 ); assert( strength == LAGW_STRONG ); - wnd_h = lag_window_8k[0]; - wnd_l = lag_window_8k[1]; + wnd_h = lag_window_8k[0]; /*Q15(Q_r -16)*/ + wnd_l = lag_window_8k[1]; /*Q(r)-1*/ BREAK; case 12800: assert( m <= 16 ); - wnd_h = lag_window_12k8[strength][0]; - wnd_l = lag_window_12k8[strength][1]; + wnd_h = lag_window_12k8[strength][0]; /*Q15(Q_r -16)*/ + wnd_l = lag_window_12k8[strength][1]; /*Q(r)-1*/ BREAK; case 16000: assert( m <= 16 ); - wnd_h = lag_window_16k[strength][0]; - wnd_l = lag_window_16k[strength][1]; + wnd_h = lag_window_16k[strength][0]; /*Q15(Q_r -16)*/ + wnd_l = lag_window_16k[strength][1]; /*Q(r)-1*/ BREAK; case 24000: case 25600: assert( m <= 16 ); - wnd_h = lag_window_25k6[strength][0]; - wnd_l = lag_window_25k6[strength][1]; + wnd_h = lag_window_25k6[strength][0]; /*Q15(Q_r -16)*/ + wnd_l = lag_window_25k6[strength][1]; /*Q(r)-1*/ BREAK; case 32000: assert( m <= 16 ); - wnd_h = lag_window_32k[strength][0]; - wnd_l = lag_window_32k[strength][1]; + wnd_h = lag_window_32k[strength][0]; /*Q15(Q_r -16)*/ + wnd_l = lag_window_32k[strength][1]; /*Q(r)-1*/ BREAK; case 48000: assert( m <= 16 ); assert( strength == LAGW_STRONG ); - wnd_h = lag_window_48k[0]; - wnd_l = lag_window_48k[1]; + wnd_h = lag_window_48k[0]; /*Q15(Q_r -16)*/ + wnd_l = lag_window_48k[1]; /*Q(r)-1*/ BREAK; default: assert( !"Lag window not implemented for this sampling rate" ); @@ -230,20 +230,20 @@ void lag_wind( FOR( i = 1; i <= m; i++ ) { - tmp = Mpy_32( r_h[i], r_l[i], wnd_h[sub( i, 1 )], wnd_l[sub( i, 1 )] ); + tmp = Mpy_32( r_h[i], r_l[i], wnd_h[( i - 1 )], wnd_l[( i - 1 )] ); /*Q31*/ L_Extract( tmp, &r_h[i], &r_l[i] ); } } void lag_wind_32( - Word32 r[], /* in/out: autocorrelations */ - Word16 m, /* input : order of LP filter */ - Word32 sr_core, /* input : sampling rate */ - Word16 strength /* input : LAGW_WEAK, LAGW_MEDIUM, or LAGW_STRONG */ + Word32 r[], /* in/out: autocorrelations Qx*/ + Word16 m, /* input : order of LP filter Q0*/ + Word32 sr_core, /* input : sampling rate Q0*/ + Word16 strength /* input : LAGW_WEAK, LAGW_MEDIUM, or LAGW_STRONG Q0*/ ) { Word16 i; - const Word32 *wnd; + const Word32 *wnd; /*Q31*/ assert( 0 <= strength && strength <= NUM_LAGW_STRENGTHS ); @@ -252,29 +252,29 @@ void lag_wind_32( case 8000: assert( m <= 16 ); assert( strength == LAGW_STRONG ); - wnd = lag_window_8k_32; + wnd = lag_window_8k_32; /*Q31*/ BREAK; case 12800: assert( m <= 16 ); - wnd = lag_window_12k8_32[strength]; + wnd = lag_window_12k8_32[strength]; /*Q31*/ BREAK; case 16000: assert( m <= 16 ); - wnd = lag_window_16k_32[strength]; + wnd = lag_window_16k_32[strength]; /*Q31*/ BREAK; case 24000: case 25600: assert( m <= 16 ); - wnd = lag_window_25k6_32[strength]; + wnd = lag_window_25k6_32[strength]; /*Q31*/ BREAK; case 32000: assert( m <= 16 ); - wnd = lag_window_32k_32[strength]; + wnd = lag_window_32k_32[strength]; /*Q31*/ BREAK; case 48000: assert( m <= 16 ); assert( strength == LAGW_STRONG ); - wnd = lag_window_48k_32; + wnd = lag_window_48k_32; /*Q31*/ BREAK; default: assert( !"Lag window not implemented for this sampling rate" ); @@ -283,27 +283,27 @@ void lag_wind_32( FOR( i = 1; i <= m; i++ ) { - r[i] = Mpy_32_32( r[i], wnd[sub( i, 1 )] ); + r[i] = Mpy_32_32( r[i], wnd[( i - 1 )] ); /*Qx*/ move32(); } } void adapt_lag_wind( - Word16 r_h[], /* in/out: autocorrelations */ + Word16 r_h[], /* in/out: autocorrelations Q15*/ Word16 r_l[], /* in/out: autocorrelations */ - Word16 m, /* input : order of LP filter */ - const Word16 Top, /* input : open loop pitch lag */ - const Word16 Tnc, /* input : open loop pitch gain */ - Word32 sr_core /* input : sampling rate */ + Word16 m, /* input : order of LP filter Q0*/ + const Word16 Top, /* input : open loop pitch lag Q0*/ + const Word16 Tnc, /* input : open loop pitch gain Q15*/ + Word32 sr_core /* input : sampling rate Q0*/ ) { Word16 strength, pitch_lag; Word16 pitch_gain; - pitch_lag = Top; + pitch_lag = Top; /*Q0*/ move16(); - pitch_gain = Tnc; + pitch_gain = Tnc; /*Q15*/ move16(); IF( LT_16( pitch_lag, 80 ) ) diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index 1fa1b3549..4bead686b 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -1457,14 +1457,14 @@ void fft_rel_fx32( ); // ifft_rel.c void ifft_rel_fx( - Word16 io[], /* i/o: i /output vector */ - const Word16 n, /* i : vector length */ - const Word16 m /* i : log2 of vector length */ + Word16 io[], /* Qx i/o: i /output vector */ + const Word16 n, /* Q0 i : vector length */ + const Word16 m /* Q0 i : log2 of vector length */ ); void ifft_rel_fx32( - Word32 io[], /* i/o: i /output vector */ - const Word16 n, /* i : vector length */ - const Word16 m /* i : log2 of vector length */ + Word32 io[], /* Qx i/o: i /output vector */ + const Word16 n, /* Q0 i : vector length */ + const Word16 m /* Q0 i : log2 of vector length */ ); // gs_gains_fx.c Word16 gsc_gaindec_fx( /* o : average frequency gain */ @@ -1585,12 +1585,12 @@ void deemph_fx_32( // int_lsp.c void int_lsp_fx( const Word16 L_frame, /* i : length of the frame */ - const Word16 lsp_old[], /* i : LSPs from past frame */ - const Word16 lsp_new[], /* i : LSPs from present frame */ - Word16 *Aq, /* o : LP coefficients in both subframes */ + const Word16 lsp_old[], /* i : Q15 LSPs from past frame */ + const Word16 lsp_new[], /* i : Q15 LSPs from present frame */ + Word16 *Aq, /* o : Q12 LP coefficients in both subframes */ const Word16 m, /* i : order of LP filter */ - const Word16 *int_coeffs, /* i : interpolation coefficients */ - const Word16 Opt_AMR_WB /* i : flag indicating AMR-WB IO mode */ + const Word16 *int_coeffs, /* i : Q15 interpolation coefficients */ + const Word16 Opt_AMR_WB /* i : Q0 flag indicating AMR-WB IO mode */ ); void int_lsp4_fx( @@ -2098,17 +2098,17 @@ isf_dec_amr_wb_fx.c void disf_2s_36b_fx( Word16 *indice, /* i : quantized indices (use indice[0] = -1 in the decoder) */ - Word16 *isf_q, /* o : quantized ISFs in the cosine domain */ - Word16 *mem_AR, /* i/o: quantizer memory for AR model */ - Word16 *mem_MA, /* i/o: quantizer memory for MA model */ + Word16 *isf_q, /* (Qx2.56) o : quantized ISFs in the cosine domain */ + Word16 *mem_AR, /* (Qx2.56) i/o: quantizer memory for AR model */ + Word16 *mem_MA, /* (Qx2.56) i/o: quantizer memory for MA model */ const Word16 enc_dec /* i : encoder (0), decoder (1) G722.2 FER */ ); void disf_2s_46b_fx( Word16 *indice, /* i : quantized indices (use indice[0] = -1 in the decoder) */ - Word16 *isf_q, /* o : quantized ISFs in the cosine domain */ - Word16 *mem_AR, /* o : quantizer memory for AR model */ - Word16 *mem_MA, /* i/o: quantizer memory for MA model */ + Word16 *isf_q, /* (Qx2.56) o : quantized ISFs in the cosine domain */ + Word16 *mem_AR, /* (Qx2.56) o : quantizer memory for AR model */ + Word16 *mem_MA, /* (Qx2.56) i/o: quantizer memory for MA model */ const Word16 enc_dec /* i : encoder (0), decoder (1) G722.2 FER */ ); @@ -2118,9 +2118,9 @@ void disf_ns_28b_fx( void isf_dec_amr_wb_fx( Decoder_State *st, /* i/o: State structure */ - Word16 *Aq, /* o : quantized A(z) for 4 subframes */ - Word16 *isf_new, /* o : de-quantized ISF vector */ - Word16 *isp_new /* o : de-quantized ISP vector */ + Word16 *Aq, /* Q12 o : quantized A(z) for 4 subframes */ + Word16 *isf_new, /* Qlog2(2.56) o : de-quantized ISF vector */ + Word16 *isp_new /* Q15 o : de-quantized ISP vector */ ); /*========================================================================================================/ @@ -2423,11 +2423,11 @@ void mpvq_decode_vec_fx( /* o : void ); // weight_a_fx.c void weight_a_subfr_fx( - const Word16 nb_subfr, /* i : number of subframes */ + const Word16 nb_subfr, /* i : number of subframes Q0 */ const Word16 *A, /* i : LP filter coefficients Q12 */ Word16 *Aw, /* o : weighted LP filter coefficients Q12 */ - const Word16 gamma, /* i : weighting factor */ - const Word16 m /* i : order of LP filter */ + const Word16 gamma, /* i : weighting factor Q15 */ + const Word16 order /* i : order of LP filter Q0 */ ); void weight_a_lc_fx( @@ -2443,7 +2443,12 @@ void weight_a_fx( const Word16 gamma, /* i: weighting factor Q15 */ const Word16 m /* i: order of LP filter Q0 */ ); -void E_LPC_a_weight_inv( const Word16 *a, Word16 *ap, const Word16 gamma, const Word16 m ); +void E_LPC_a_weight_inv( + const Word16 *a, /* Q12 */ + Word16 *ap, /* Q12 */ + const Word16 inv_gamma, /* Q14 */ + const Word16 m /* Q0 */ +); // residu_fx.c void Residu3_lc_fx( @@ -2477,7 +2482,7 @@ void calc_residu_fx( const Word16 *p_Aq /* i : quantized LP filter coefficients */ ); // inerpol_lc.c -Word32 Interpol_lc_fx( /* o : interpolated value Qx+16 */ +Word32 Interpol_lc_fx( /* o : interpolated value Q15 */ const Word16 *x, /* i : input vector Q0 */ const Word16 *win, /* i : interpolation window Q14 */ const Word16 frac, /* i : fraction (0..up_samp) Q0 */ @@ -4310,48 +4315,53 @@ void set_TEC_TFA_code_fx( const Word16 corrFlag, Word16 *tec_flag, Word16 *tfa_f // tcx_mdct_fx.c void TCX_MDCT( - const Word16 *x, - Word32 *y, + const Word16 *x, /* Qx */ + Word32 *y, /* exp(y_e) */ Word16 *y_e, - const Word16 l, - const Word16 m, - const Word16 r, - const Word16 element_mode ); + const Word16 l, /* Q0 */ + const Word16 m, /* Q0 */ + const Word16 r, /* Q0 */ + const Word16 element_mode /* Q0 */ +); void TCX_MDST( - const Word16 *x, - Word32 *y, + const Word16 *x, /* Qx */ + Word32 *y, /* exp(y_e) */ Word16 *y_e, - const Word16 l, - const Word16 m, - const Word16 r, - const Word16 element_mode ); + const Word16 l, /* Q0 */ + const Word16 m, /* Q0 */ + const Word16 r, /* Q0 */ + const Word16 element_mode /* Q0 */ +); void TCX_MDCT_Inverse( - Word32 *x, + Word32 *x, /* exp(x_e) */ Word16 x_e, - Word16 *y, - const Word16 l, - const Word16 m, - const Word16 r, - const Word16 element_mode ); + Word16 *y, /* Qy */ + const Word16 l, /* Q0 */ + const Word16 m, /* Q0 */ + const Word16 r, /* Q0 */ + const Word16 element_mode /* Q0 */ +); void TCX_MDST_Inverse_fx( - Word32 *x, + Word32 *x, /* exp(x_e) */ Word16 x_e, - Word16 *y, - const Word16 l, - const Word16 m, - const Word16 r ); + Word16 *y, /* Qx */ + const Word16 l, /* Q0 */ + const Word16 m, /* Q0 */ + const Word16 r /* Q0 */ +); void TCX_MDXT_Inverse_fx( - const Word32 *x, + const Word32 *x, /* exp(x_e) */ Word16 x_e, - Word16 *y, - const Word16 l, - const Word16 m, - const Word16 r, - const UWord16 kernel_type ); + Word16 *y, /* Qx */ + const Word16 l, /* Q0 */ + const Word16 m, /* Q0 */ + const Word16 r, /* Q0 */ + const UWord16 kernel_type /* Q0 */ +); // edct_fx.c #define EDCT_FACTOR_SCALE 2 @@ -5420,9 +5430,9 @@ void hq_bit_allocation_fx( // weight_fx.c void map_quant_weight_fx( - const Word16 normqlg2[], /* i : quantized norms */ - Word16 wnorm[], /* o : weighted norm */ - const Word16 is_transient /* i : transient flag */ + const Word16 normqlg2[], /* i : quantized norms Q0*/ + Word16 wnorm[], /* o : weighted norm Q0*/ + const Word16 is_transient /* i : transient flag Q0*/ ); // bitalloc_fx.c @@ -5675,9 +5685,9 @@ void IGFCommonFuncsCalcSfbEnergyPowerSpec( const Word16 startSfb, /**< in: void IGFCommonFuncsMDCTSquareSpec( const Word16 sqrtBgn, /**< in: Q0 | start MDCT subband index */ const Word16 sqrtEnd, /**< in: Q0 | stop MDCT subband index */ - const Word32 *mdctSpec, /**< in: Q31 | MDCT spectrum to square */ + const Word32 *mdctSpec, /**< in: | MDCT spectrum to square */ const Word16 mdctSpec_e, /**< in: | exponent of mdctSpectrum */ - Word32 *mdctSquareSpec, /**< out:Q31 | MDCT square spectrum */ + Word32 *mdctSquareSpec, /**< out: | MDCT square spectrum */ Word16 *mdctSquareSpec_e, /**< out: | exponent of mdctSquareSpec */ Word16 indexOffset /**< in: Q0 | index offset */ ); @@ -5685,9 +5695,9 @@ void IGFCommonFuncsMDCTSquareSpec( const Word16 sqrtBgn, /**< in: Q0 | star void IGFCommonFuncsMDCTSquareSpec_ivas( const Word16 sqrtBgn, /**< in: Q0 | start MDCT subband index */ const Word16 sqrtEnd, /**< in: Q0 | stop MDCT subband index */ - const Word32 *mdctSpec, /**< in: Q31 | MDCT spectrum to square */ + const Word32 *mdctSpec, /**< in: | MDCT spectrum to square */ const Word16 mdctSpec_e, /**< in: | exponent of mdctSpectrum */ - Word32 *mdctSquareSpec, /**< out:Q31 | MDCT square spectrum */ + Word32 *mdctSquareSpec, /**< out: | MDCT square spectrum */ Word16 *mdctSquareSpec_e, /**< out: | exponent of mdctSquareSpec */ Word16 indexOffset /**< in: Q0 | index offset */ ); @@ -9058,9 +9068,9 @@ void vlpc_2st_dec( Word32 sr_core ); // vlpc_2st_com_fx.c -void lsf_weight_2st( const Word16 *lsfq, /* i : quantized lsf coefficients (3Q12) */ - Word16 *w, /* o : weighting function (0Q15) */ - const Word16 mode /* i : operational mode */ +void lsf_weight_2st( const Word16 *lsfq, /* input: quantized lsf coefficients (14Q1*1.28) */ + Word16 *w, /* output: weighting function (0Q15*1.28) */ + const Word16 mode /* input: operational mode Q0 */ ); // ACcontextMapping_fx.c diff --git a/lib_com/rom_com.c b/lib_com/rom_com.c index 7430b18e6..a1fc49304 100644 --- a/lib_com/rom_com.c +++ b/lib_com/rom_com.c @@ -1670,7 +1670,7 @@ const Word16 sincos_t_ext_fx[641] = -20788, -20943, -21097, -21251, -21403, -21555, -21706, -21856, -22006, -22154, -22302, -22449, -22595, -22740, -22884, -23028, -23028 -}; +};/*Q15*/ const float Asr_LP32[41] = @@ -1733,7 +1733,7 @@ const Word16 Asr_LP48_fx[61] = 0, -407, -592, -571, -408, -192, 0, 123, 167, 146, 93, 38, 0 }; -const int16_t fft256_read_indexes[]= +const Word16 fft256_read_indexes[]= { 0, 128, 64, 192, 32, 160, 96, 224, 16, 144, 80, 208, 48, 176, 112, 240, 8, 136, 72, 200, 40, 168, 104, 232, 24, 152, 88, 216, 56, 184, 120, 248, @@ -2639,7 +2639,7 @@ const Word16 interpol_frac2_mid_fx[NB_SUBFR * 3] = { 8191, 24575, 0, 0, 8191, 24575, 0, 8191, 24575 -}; +};/*Q15*/ const float interpol_frac_12k8[NB_SUBFR] = { 0.25f, 0.5f, 0.75f, 1.0f @@ -2649,19 +2649,19 @@ const Word16 interpol_frac_12k8_fx[NB_SUBFR] = { 8191, 16383, 24575, 32767 }; -const Word16 interpol_frac_fx[NB_SUBFR] = { 8192, 16384, 24576,32767 }; +const Word16 interpol_frac_fx[NB_SUBFR] = { 8192, 16384, 24576,32767 };/*Q15*/ const float interpol_isp_amr_wb[NB_SUBFR] = { 0.45f, 0.8f, 0.96f, 1.0f }; -const Word16 interpol_isp_amr_wb_fx[] = { 14746, 26214, 31457, 32767 }; +const Word16 interpol_isp_amr_wb_fx[] = { 14746, 26214, 31457, 32767 };/*Q15*/ const float interpol_frac_16k[NB_SUBFR16k] = { 0.2f, 0.4f, 0.6f, 0.8f, 1.0f }; -const Word16 interpol_frac_16k_fx[NB_SUBFR16k] = { 6554, 13107, 19661, 26214, 32767 }; +const Word16 interpol_frac_16k_fx[NB_SUBFR16k] = { 6554, 13107, 19661, 26214, 32767 };/*Q15*/ const float interpol_frac_mid[NB_SUBFR*3] = { 0.5f, 0.5f, 0.0f, @@ -2673,7 +2673,7 @@ const Word16 interpol_frac_mid_fx[NB_SUBFR * 3] = { 16384, 16384, 0, 0, 32767, 0, 0, 16384, 16384, 0, 0, 32767 -}; +};/*Q15*/ const float interpol_frac_mid_16k[NB_SUBFR16k*3] = { 0.55f, 0.45f, 0.0f, @@ -2699,7 +2699,7 @@ const Word16 interpol_frac_mid_relaxprev_12k8_fx[NB_SUBFR * 3] = { 0, 22938, 983 0, 0, 32767, 0, 0, 32767, 0, 0, 32767 -}; +};/*Q15*/ const float interpol_frac_mid_FEC[NB_SUBFR*3] = { 0.25f, 0.55f, 0.20f, 0.00f, 0.70f, 0.30f, @@ -2710,7 +2710,7 @@ const Word16 interpol_frac_mid_FEC_fx[NB_SUBFR * 3] = { 8192, 18022, 6554, 0, 22938, 9830, 0, 14746, 18022, 0, 0, 32767 -}; +};/*Q15*/ const float interpol_frac_mid_relaxprev_pred_12k8[NB_SUBFR*3] = { @@ -2737,7 +2737,7 @@ const Word16 interpol_frac_mid_relaxprev_16k_fx[NB_SUBFR16k * 3] = { 0, 22938, 9 0, 0, 32767, 0, 0, 32767, 0, 0, 32767 -}; +};/*Q15*/ const float interpol_frac_mid_16k_FEC[NB_SUBFR16k*3] = { @@ -2752,7 +2752,7 @@ const Word16 interpol_frac_mid_16k_FEC_fx[NB_SUBFR16k * 3] = { 13107, 13107, 655 0, 21299, 11469, 0, 4915, 27853, 0, 0, 32767 -}; +};/*Q15*/ const float interpol_frac_mid_relaxprev_pred_16k[NB_SUBFR16k*3] = { 0.15f, 0.70f, 0.15f, @@ -2766,7 +2766,7 @@ const Word16 interpol_frac_mid_relaxprev_pred_16k_fx[NB_SUBFR16k * 3] = { 4915, 0, 16384, 16384, 0, 4915, 27853, 0, 0, 32767 -}; +};/*Q15*/ /*----------------------------------------------------------------------------------* * Innovative codebook @@ -8298,7 +8298,7 @@ const Word16 mean_isf_amr_wb_fx[M] = { 738, 1326, 2336, 3578, 4596, 5662, 6711, 7730, 8750, 9753,10705, 11728, 12833, 13971,15043, 4037 -}; +};/*1.28f Q1*/ /*----------------------------------------------------------------------------------* * Mean ISF vector for SID frames (only in AMR-WB IO mode) @@ -11633,97 +11633,97 @@ const Word16 msNoiseSlopeMax[4] = { 32767/*2.f Q14*/, 26214/*1.6f Q14*/, 21299 const SCALE_SETUP scaleTableStereo[SIZE_SCALE_TABLE_STEREO] = { - { 1, 0, 8000, -5.5f, -704/*-5.5f Q7*/, -704 }, - { 1, 8000, 9600, -5.0f, -640/*-5.0f Q7*/, -640 }, - { 1, 9600, 13200, -4.0f, -512/*-4.0f Q7*/, -512 }, - { 1, 13200, 16400, -3.0f, -384/*-3.0f Q7*/, -384 }, - { 1, 16400, 24400, -1.6f, -204/*-1.6f Q7*/, -204 }, - { 1, 24400, 32000, -0.2f, -26/*-1.6f Q7*/, -26 }, - { 1, 32000,512001, 0.0f, 0 /*0.0f Q7*/, 0 }, - - { 2, 0, 8000, -0.9f , -115/*-0.9f Q7*/, -115 }, - { 2, 8000, 9600, -0.65f, -83/*-0.65f Q7*/, -83 }, - { 2, 9600, 13200, -2.0f , -256/*-2.0f Q7*/, -256 }, - { 2, 13200, 16400, -3.0f , -384/*-3.0f Q7*/, -384 }, - { 2, 16400, 24400, -0.8f , -102/*-0.8f Q7*/, -102 }, - { 2, 24400, 32000, -0.25f, -32/*-0.25f Q7*/, -32 }, - { 2, 32000,512001, 0.0f , 0/* 0.0f Q7*/, 0 } + { 1, 0, 8000, /* -5.5f,*/ -704/*-5.5f Q7*/, -704 }, + { 1, 8000, 9600, /* -5.0f,*/ -640/*-5.0f Q7*/, -640 }, + { 1, 9600, 13200, /* -4.0f,*/ -512/*-4.0f Q7*/, -512 }, + { 1, 13200, 16400, /* -3.0f,*/ -384/*-3.0f Q7*/, -384 }, + { 1, 16400, 24400, /* -1.6f,*/ -204/*-1.6f Q7*/, -204 }, + { 1, 24400, 32000, /* -0.2f,*/ -26/*-1.6f Q7*/, -26 }, + { 1, 32000,512001, /* 0.0f,*/ 0 /*0.0f Q7*/, 0 }, + + { 2, 0, 8000, /*-0.9f ,*/ -115/*-0.9f Q7*/, -115 }, + { 2, 8000, 9600, /*-0.65f,*/ -83/*-0.65f Q7*/, -83 }, + { 2, 9600, 13200, /*-2.0f ,*/ -256/*-2.0f Q7*/, -256 }, + { 2, 13200, 16400, /*-3.0f ,*/ -384/*-3.0f Q7*/, -384 }, + { 2, 16400, 24400, /*-0.8f ,*/ -102/*-0.8f Q7*/, -102 }, + { 2, 24400, 32000, /*-0.25f,*/ -32/*-0.25f Q7*/, -32 }, + { 2, 32000,512001, /* 0.0f ,*/ 0/* 0.0f Q7*/, 0 } }; #if 0 //scaleTableStereo recheck extended from scaleTableMono #endif const SCALE_SETUP scaleTableMono[SIZE_SCALE_TABLE_MONO] = { - { 0, 0, 8000, -5.5f, -704/*-5.5f Q7*/, -704 }, - { 0, 8000, 9600, -5.0f, -640/*-5.0f Q7*/, -640 }, - { 0, 9600, 13200, -4.0f, -512/*-4.0f Q7*/, -512 }, - { 0, 13200, 16400, -3.0f, -384/*-3.0f Q7*/, -384 }, - { 0, 16400, 24400, -1.5f, -192/*-1.5f Q7*/, -192 }, - { 0, 24400,128001, -0.5f, -64/*-0.5f Q7*/, -64 }, - - { 1, 0, 8000, -5.5f , -704/*-5.5f Q7*/, -704 }, - { 1, 8000, 9600, -5.0f , -640/*-5.0f Q7*/, -640 }, - { 1, 9600, 13200, -1.55f, -198/*-1.55f Q7*/, -198 }, - { 1, 13200, 16400, -3.0f , -384/*-3.0f Q7*/,-384 }, - { 1, 16400, 24400, -0.6f , -77/*-0.6f Q7*/, -77 }, - { 1, 24400, 32000, -0.2f , -26/*-0.2f Q7*/, -26 }, - { 1, 32000,128001, 0.0f , 0/* 0.0f Q7*/, 0 }, - - { 2, 0, 8000, -0.9f , -115/*-0.9f Q7*/, -115 }, - { 2, 8000, 9600, -0.65f, -83/*-0.65f Q7*/, -83 }, - { 2, 9600, 13200, -2.0f , -256/*-2.0f Q7*/, -256 }, - { 2, 13200, 16400, -3.0f , -384/*-3.0f Q7*/, -384 }, - { 2, 16400, 24400, -0.8f , -102/*-0.8f Q7*/, -102 }, - { 2, 24400, 32000, -0.25f, -32/*-0.25f Q7*/, -32 }, - { 2, 32000,128001, 0.0f , 0/* 0.0f Q7*/,0 } + { 0, 0, 8000, /* -5.5f,*/ -704/*-5.5f Q7*/, -704 }, + { 0, 8000, 9600, /* -5.0f,*/ -640/*-5.0f Q7*/, -640 }, + { 0, 9600, 13200, /* -4.0f,*/ -512/*-4.0f Q7*/, -512 }, + { 0, 13200, 16400, /* -3.0f,*/ -384/*-3.0f Q7*/, -384 }, + { 0, 16400, 24400, /* -1.5f,*/ -192/*-1.5f Q7*/, -192 }, + { 0, 24400,128001, /* -0.5f,*/ -64/*-0.5f Q7*/, -64 }, + + { 1, 0, 8000, /*-5.5f ,*/ -704/*-5.5f Q7*/, -704 }, + { 1, 8000, 9600, /*-5.0f ,*/ -640/*-5.0f Q7*/, -640 }, + { 1, 9600, 13200, /*-1.55f,*/ -198/*-1.55f Q7*/, -198 }, + { 1, 13200, 16400, /*-3.0f ,*/ -384/*-3.0f Q7*/,-384 }, + { 1, 16400, 24400, /*-0.6f ,*/ -77/*-0.6f Q7*/, -77 }, + { 1, 24400, 32000, /*-0.2f ,*/ -26/*-0.2f Q7*/, -26 }, + { 1, 32000,128001, /* 0.0f ,*/ 0/* 0.0f Q7*/, 0 }, + + { 2, 0, 8000, /*-0.9f ,*/ -115/*-0.9f Q7*/, -115 }, + { 2, 8000, 9600, /*-0.65f,*/ -83/*-0.65f Q7*/, -83 }, + { 2, 9600, 13200, /*-2.0f ,*/ -256/*-2.0f Q7*/, -256 }, + { 2, 13200, 16400, /*-3.0f ,*/ -384/*-3.0f Q7*/, -384 }, + { 2, 16400, 24400, /*-0.8f ,*/ -102/*-0.8f Q7*/, -102 }, + { 2, 24400, 32000, /*-0.25f,*/ -32/*-0.25f Q7*/, -32 }, + { 2, 32000,128001, /* 0.0f ,*/ 0/* 0.0f Q7*/,0 } }; const SCALE_SETUP scaleTable_cn_only[SIZE_SCALE_TABLE_CN] = { - { 0, 0, 8000, -3.5f, 20295/*1.2387211385 Q14*/ /*-3.5f*/, 20295 }, - { 0, 8000, 9600, -3.0f, 16306/*0.9952622652 Q14*/ /*-3.0f*/, 16306 }, - { 0, 9600, 13200, -2.5f, 12751/*0.7782794237 Q14*/ /*-2.5f*/, 12751 }, - { 0, 13200, 16400, -2.0f, 9583/*0.5848932266 Q14*/ /*-2.0f*/, 9583 }, - { 0, 16400,128001, 0.0f, 0/*0.0000000000 Q14*/ /* 0.0f*/, 0 }, + { 0, 0, 8000, /*-3.5f,*/ 20295/*1.2387211385 Q14*/ /*-3.5f*/, 20295 }, + { 0, 8000, 9600, /*-3.0f,*/ 16306/*0.9952622652 Q14*/ /*-3.0f*/, 16306 }, + { 0, 9600, 13200, /*-2.5f,*/ 12751/*0.7782794237 Q14*/ /*-2.5f*/, 12751 }, + { 0, 13200, 16400, /*-2.0f,*/ 9583/*0.5848932266 Q14*/ /*-2.0f*/, 9583 }, + { 0, 16400,128001, /* 0.0f,*/ 0/*0.0000000000 Q14*/ /* 0.0f*/, 0 }, - { 1, 0, 8000, -3.0f, 16306/*0.9952622652 Q14*/ /*-3.0f*/, 16306 }, - { 1, 8000, 9600, -2.5f, 12751/*0.7782794237 Q14*/ /*-2.5f*/, 12751 }, - { 1, 9600, 13200, -1.5f, 6759/*0.4125375748 Q14*/ /*-1.5f*/, 6759 }, - { 1, 13200, 16400, -2.5f, 12751/*0.7782794237 Q14*/ /*-2.5f*/, 12751 }, - { 1, 16400, 24400, -0.5f, 1999/*0.1220184565 Q14*/ /*-0.5f*/, 1999 }, - { 1, 24400,128001, 0.0f, 0/*0.0000000000 Q14*/ /* 0.0f*/, 0 }, + { 1, 0, 8000, /*-3.0f,*/ 16306/*0.9952622652 Q14*/ /*-3.0f*/, 16306 }, + { 1, 8000, 9600, /*-2.5f,*/ 12751/*0.7782794237 Q14*/ /*-2.5f*/, 12751 }, + { 1, 9600, 13200, /*-1.5f,*/ 6759/*0.4125375748 Q14*/ /*-1.5f*/, 6759 }, + { 1, 13200, 16400, /*-2.5f,*/ 12751/*0.7782794237 Q14*/ /*-2.5f*/, 12751 }, + { 1, 16400, 24400, /*-0.5f,*/ 1999/*0.1220184565 Q14*/ /*-0.5f*/, 1999 }, + { 1, 24400,128001, /* 0.0f,*/ 0/*0.0000000000 Q14*/ /* 0.0f*/, 0 }, - { 2, 0, 8000, -2.5f, 12751/*0.7782794237 Q14*/ /*-2.5f*/, 12751 }, - { 2, 8000, 9600, -2.5f, 12751/*0.7782794237 Q14*/ /*-2.5f*/, 12751 }, - { 2, 9600, 13200, -2.0f, 9583/*0.5848932266 Q14*/ /*-2.0f*/, 9583 }, - { 2, 13200, 16400, -1.0f, 4242/*0.2589254379 Q14*/ /*-1.0f*/, 4242 }, + { 2, 0, 8000, /*-2.5f,*/ 12751/*0.7782794237 Q14*/ /*-2.5f*/, 12751 }, + { 2, 8000, 9600, /*-2.5f,*/ 12751/*0.7782794237 Q14*/ /*-2.5f*/, 12751 }, + { 2, 9600, 13200, /*-2.0f,*/ 9583/*0.5848932266 Q14*/ /*-2.0f*/, 9583 }, + { 2, 13200, 16400, /*-1.0f,*/ 4242/*0.2589254379 Q14*/ /*-1.0f*/, 4242 }, - { 2, 16400, 24400, -0.5f, 1999/*0.1220184565 Q14*/ /*-0.5f*/, 1999 }, - { 2, 24400, 32000, 0.0f, 0/*0.0000000000 Q14*/ /* 0.0f*/, 0 }, - { 2, 32000,128001, 0.0f, 0/*0.0000000000 Q14*/ /* 0.0f*/, 0 } + { 2, 16400, 24400, /*-0.5f,*/ 1999/*0.1220184565 Q14*/ /*-0.5f*/, 1999 }, + { 2, 24400, 32000, /* 0.0f,*/ 0/*0.0000000000 Q14*/ /* 0.0f*/, 0 }, + { 2, 32000,128001, /* 0.0f,*/ 0/*0.0000000000 Q14*/ /* 0.0f*/, 0 } }; #if 0 //scaleTable_cn_dirac recheck extended from scaleTable_cn_only #endif const SCALE_SETUP scaleTable_cn_dirac[15] = { - { 0, 0, 13200, -3.0f, 16306/*0.9952622652 Q14*/ /*-3.0f*/, 16306 }, - { 0, 13200, 16400, -2.5f, 12751/*0.7782794237 Q14*/ /*-2.5f*/, 12751 }, - { 0, 16400, 24400, -2.0f, 9583/*0.5848932266 Q14*/ /*-2.0f*/, 9583 }, - { 0, 24400, 32000, -1.5f, 6759/*0.4125375748 Q14*/ /*-1.5f*/, 6759 }, - { 0, 32000,512001, 0.0f, 0/*0.0000000000 Q14*/ /* 0.0f*/, 0 }, + { 0, 0, 13200, /*-3.0f,*/ 16306/*0.9952622652 Q14*/ /*-3.0f*/, 16306 }, + { 0, 13200, 16400, /*-2.5f,*/ 12751/*0.7782794237 Q14*/ /*-2.5f*/, 12751 }, + { 0, 16400, 24400, /*-2.0f,*/ 9583/*0.5848932266 Q14*/ /*-2.0f*/, 9583 }, + { 0, 24400, 32000, /*-1.5f,*/ 6759/*0.4125375748 Q14*/ /*-1.5f*/, 6759 }, + { 0, 32000,512001, /* 0.0f,*/ 0/*0.0000000000 Q14*/ /* 0.0f*/, 0 }, - { 1, 0, 13200, -3.0f, 16306/*0.9952622652 Q14*/ /*-3.0f*/, 16306 }, - { 1, 13200, 16400, -2.5f, 12751/*0.7782794237 Q14*/ /*-2.5f*/, 12751 }, - { 1, 16400, 24400, -2.0f, 9583/*0.5848932266 Q14*/ /*-2.0f*/, 9583 }, - { 1, 24400, 32000, -1.5f, 6759/*0.4125375748 Q14*/ /*-1.5f*/, 6759 }, - { 1, 32000,512001, 0.0f, 0/*0.0000000000 Q14*/ /* 0.0f*/, 0 }, + { 1, 0, 13200, /*-3.0f,*/ 16306/*0.9952622652 Q14*/ /*-3.0f*/, 16306 }, + { 1, 13200, 16400, /*-2.5f,*/ 12751/*0.7782794237 Q14*/ /*-2.5f*/, 12751 }, + { 1, 16400, 24400, /*-2.0f,*/ 9583/*0.5848932266 Q14*/ /*-2.0f*/, 9583 }, + { 1, 24400, 32000, /*-1.5f,*/ 6759/*0.4125375748 Q14*/ /*-1.5f*/, 6759 }, + { 1, 32000,512001, /* 0.0f,*/ 0/*0.0000000000 Q14*/ /* 0.0f*/, 0 }, - { 2, 0, 13200, -3.0f, 16306/*0.9952622652 Q14*/ /*-3.0f*/, 16306 }, - { 2, 13200, 16400, -2.5f, 12751/*0.7782794237 Q14*/ /*-2.5f*/, 12751 }, - { 2, 16400, 24400, -2.0f, 9583/*0.5848932266 Q14*/ /*-2.0f*/, 9583 }, - { 2, 24400, 32000, -1.5f, 6759/*0.4125375748 Q14*/ /*-1.5f*/, 6759 }, - { 2, 32000,512001, 0.0f, 0/*0.0000000000 Q14*/ /* 0.0f*/, 0 } + { 2, 0, 13200, /*-3.0f,*/ 16306/*0.9952622652 Q14*/ /*-3.0f*/, 16306 }, + { 2, 13200, 16400, /*-2.5f,*/ 12751/*0.7782794237 Q14*/ /*-2.5f*/, 12751 }, + { 2, 16400, 24400, /*-2.0f,*/ 9583/*0.5848932266 Q14*/ /*-2.0f*/, 9583 }, + { 2, 24400, 32000, /*-1.5f,*/ 6759/*0.4125375748 Q14*/ /*-1.5f*/, 6759 }, + { 2, 32000,512001, /* 0.0f,*/ 0/*0.0000000000 Q14*/ /* 0.0f*/, 0 } }; const float scaleTable_cn_only_amrwbio_flt[SIZE_SCALE_TABLE_CN_AMRWB][2] = { @@ -37400,7 +37400,7 @@ const Word16 tnsCoeff4[16] = * IGF settings for each bitrate *----------------------------------------------------------------------------------*/ -const int16_t swb_offset_LB_new[IGF_BITRATE_UNKNOWN][IGF_MAX_SFB] = +const Word16 swb_offset_LB_new[IGF_BITRATE_UNKNOWN][IGF_MAX_SFB] = { /* 0: for 9600 kbs WB */ { @@ -37546,7 +37546,7 @@ const int16_t swb_offset_LB_new[IGF_BITRATE_UNKNOWN][IGF_MAX_SFB] = { 3, 640, 720, 800 } -}; +};/*Q0*/ const int16_t igf_tile_offset_table[IGF_BITRATE_UNKNOWN][2*IGF_MAX_TILES+1] = { { 2, 2, 0, 3, 0}, /* 9600 WB*/ diff --git a/lib_com/rom_com.h b/lib_com/rom_com.h index ce044a4e6..9035c3144 100644 --- a/lib_com/rom_com.h +++ b/lib_com/rom_com.h @@ -194,9 +194,9 @@ extern const float sincos_t_ext[]; extern const Word16 sincos_t_ext_fx[]; extern const float sincos_t_rad3[]; extern const Word16 sincos_t_rad3_fx[]; -extern const int16_t fft256_read_indexes[]; /* FFT */ -extern const float inter4_2[]; /* 1/4 resolution interpolation filter */ -extern const Word16 inter4_2_fx_Q15[]; /* 1/4 resolution interpolation filter */ +extern const Word16 fft256_read_indexes[]; /* FFT */ +extern const float inter4_2[]; /* 1/4 resolution interpolation filter */ +extern const Word16 inter4_2_fx_Q15[]; /* 1/4 resolution interpolation filter */ extern const Word16 inter4_2_fx[]; extern const Word16 pitch_inter4_1[UP_SAMP * L_INTERPOL1 + 1]; /*1Q14*/ extern const Word16 pitch_inter4_2[PIT_FIR_SIZE2]; /*1Q14*/ @@ -1976,7 +1976,7 @@ typedef struct igf_mode_type } IGF_MODE; extern const IGF_MODE igfMode[IGF_BITRATE_UNKNOWN]; -extern const int16_t swb_offset_LB_new[IGF_BITRATE_UNKNOWN][IGF_MAX_SFB]; +extern const Word16 swb_offset_LB_new[IGF_BITRATE_UNKNOWN][IGF_MAX_SFB]; extern const int16_t igf_tile_offset_table[IGF_BITRATE_UNKNOWN][2 * IGF_MAX_TILES + 1]; extern const float igf_whitening_TH_flt[IGF_BITRATE_UNKNOWN][2][IGF_MAX_TILES]; extern const Word16 igf_whitening_TH[][2][IGF_MAX_TILES]; diff --git a/lib_com/stat_com.h b/lib_com/stat_com.h index 53a29ca93..487d94dbf 100644 --- a/lib_com/stat_com.h +++ b/lib_com/stat_com.h @@ -389,9 +389,12 @@ typedef struct int32_t bitrateFrom; int32_t bitrateTo; +#ifndef IVAS_FLOAT_FIXED float scale_flt; - Word16 scale; /* EVS implementation Q14 */ - Word16 scale_ivas; /* IVAS implementation Q14 */ +#else + Word16 scale; /* EVS implementation Q14 */ + Word16 scale_ivas; /* IVAS implementation Q14 */ +#endif } SCALE_SETUP; @@ -424,15 +427,14 @@ typedef struct #ifdef IVAS_FLOAT_FIXED Word32 olapBufferSynth2_fx[FFTLEN]; #endif +#ifndef IVAS_FLOAT_FIXED const float *olapWinAna_flt; const float *olapWinSyn_flt; -#ifdef IVAS_FLOAT_FIXED - const Word32 *olapWinAna_fx; - const Word16 *olapWinSyn_fx; -#endif const float *fftSineTab_flt; -#ifdef IVAS_FLOAT_FIXED - const Word16 *fftSineTab_fx; +#else + const Word32 *olapWinAna_fx; /* Q30 */ + const Word16 *olapWinSyn_fx; /* Q15 */ + const Word16 *fftSineTab_fx; /* Q15 */ #endif Word32 fftBuffer[FFTLEN]; Word16 fftBuffer_exp; diff --git a/lib_com/tcx_mdct_fx.c b/lib_com/tcx_mdct_fx.c index 474f8779b..c45513511 100644 --- a/lib_com/tcx_mdct_fx.c +++ b/lib_com/tcx_mdct_fx.c @@ -9,8 +9,9 @@ #include "basop_util.h" static Word16 TCX_MDCT_GetScaleFactor( - const Word16 L, - Word16 *factor_e ) + const Word16 L, /* Q0 */ + Word16 *factor_e /* Q0 */ +) { Word16 factor; @@ -50,8 +51,9 @@ static Word16 TCX_MDCT_GetScaleFactor( } static Word16 TCX_MDCT_Inverse_GetScaleFactor( - const Word16 L, - Word16 *factor_e ) + const Word16 L, /* Q0 */ + Word16 *factor_e /* Q0 */ +) { Word16 factor; @@ -91,13 +93,14 @@ static Word16 TCX_MDCT_Inverse_GetScaleFactor( void TCX_MDCT( - const Word16 *x, - Word32 *y, + const Word16 *x, /* Qx */ + Word32 *y, /* exp(y_e) */ Word16 *y_e, - const Word16 l, - const Word16 m, - const Word16 r, - const Word16 element_mode ) + const Word16 l, /* Q0 */ + const Word16 m, /* Q0 */ + const Word16 r, /* Q0 */ + const Word16 element_mode /* Q0 */ +) { Word16 i; @@ -112,6 +115,7 @@ void TCX_MDCT( #endif factor = TCX_MDCT_GetScaleFactor( add( add( shr( l, 1 ), m ), shr( r, 1 ) ), &factor_e ); *y_e = add( *y_e, factor_e ); + move16(); neg_factor = negate( factor ); @@ -119,30 +123,30 @@ void TCX_MDCT( /* Init */ FOR( i = 0; i < m / 2; i++ ) { - y[add( add( shr( m, 1 ), shr( r, 1 ) ), i )] = L_mult( x[sub( sub( add( l, shr( m, 1 ) ), 1 ), i )], neg_factor ); + y[m / 2 + r / 2 + i] = L_mult( x[l + m / 2 - 1 - i], neg_factor ); /* exp(y_e) */ move32(); } FOR( i = 0; i < l / 2; i++ ) { #ifdef BASOP_NOGLOB - y[add( add( add( shr( m, 1 ), shr( r, 1 ) ), shr( m, 1 ) ), i )] = L_msu_o( L_mult( x[i], factor ), x[sub( sub( l, 1 ), i )], factor, &Overflow ); -#else /* BASOP_NOGLOB */ + y[m / 2 + r / 2 + m / 2 + i] = L_msu_o( L_mult( x[i], factor ), x[l - 1 - i], factor, &Overflow ); /* exp(y_e) */ +#else /* BASOP_NOGLOB */ y[m / 2 + r / 2 + m / 2 + i] = L_msu( L_mult( x[i], factor ), x[l - 1 - i], factor ); -#endif /* BASOP_NOGLOB */ +#endif /* BASOP_NOGLOB */ move32(); } FOR( i = 0; i < m / 2; i++ ) { - y[sub( sub( add( shr( m, 1 ), shr( r, 1 ) ), 1 ), i )] = L_mult( x[add( add( l, shr( m, 1 ) ), i )], neg_factor ); + y[m / 2 + r / 2 - 1 - i] = L_mult( x[l + m / 2 + i], neg_factor ); /* exp(y_e) */ move32(); } FOR( i = 0; i < r / 2; i++ ) { #ifdef BASOP_NOGLOB - y[sub( sub( sub( add( shr( m, 1 ), shr( r, 1 ) ), 1 ), shr( m, 1 ) ), i )] = L_mac_o( L_mult( x[add( add( l, m ), i )], neg_factor ), x[sub( sub( add( add( l, m ), r ), 1 ), i )], neg_factor, &Overflow ); -#else /* BASOP_NOGLOB */ + y[m / 2 + r / 2 - 1 - m / 2 - i] = L_mac_o( L_mult( x[l + m + i], neg_factor ), x[l + m + r - 1 - i], neg_factor, &Overflow ); /* exp(y_e) */ +#else /* BASOP_NOGLOB */ y[m / 2 + r / 2 - 1 - m / 2 - i] = L_mac( L_mult( x[l + m + i], neg_factor ), x[l + m + r - 1 - i], neg_factor ); -#endif /* BASOP_NOGLOB */ +#endif /* BASOP_NOGLOB */ move32(); } @@ -155,13 +159,14 @@ void TCX_MDCT( } void TCX_MDST( - const Word16 *x, - Word32 *y, + const Word16 *x, /* Qx */ + Word32 *y, /* exp(y_e) */ Word16 *y_e, - const Word16 l, - const Word16 m, - const Word16 r, - const Word16 element_mode ) + const Word16 l, /* Q0 */ + const Word16 m, /* Q0 */ + const Word16 r, /* Q0 */ + const Word16 element_mode /* Q0 */ +) { Word16 i; @@ -174,35 +179,37 @@ void TCX_MDST( Flag Overflow = 0; move32(); #endif - factor = TCX_MDCT_GetScaleFactor( add( add( shr( l, 1 ), m ), shr( r, 1 ) ), &factor_e ); + factor = TCX_MDCT_GetScaleFactor( add( add( shr( l, 1 ), m ), shr( r, 1 ) ), &factor_e ); /* exp(factor_e) */ *y_e = add( *y_e, factor_e ); + move16(); + neg_factor = negate( factor ); /* Init */ FOR( i = 0; i < m / 2; i++ ) { - y[add( add( shr( m, 1 ), shr( r, 1 ) ), i )] = L_mult( x[sub( sub( add( l, shr( m, 1 ) ), 1 ), i )], neg_factor ); + y[m / 2 + r / 2 + i] = L_mult( x[l + m / 2 - 1 - i], neg_factor ); /* exp(y_e) */ move32(); } FOR( i = 0; i < l / 2; i++ ) { #ifdef BASOP_NOGLOB - y[add( add( add( shr( m, 1 ), shr( r, 1 ) ), shr( m, 1 ) ), i )] = L_msu_o( L_mult( x[i], neg_factor ), x[sub( sub( l, 1 ), i )], factor, &Overflow ); -#else /* BASOP_NOGLOB */ + y[m / 2 + r / 2 + m / 2 + i] = L_msu_o( L_mult( x[i], neg_factor ), x[l - 1 - i], factor, &Overflow ); /* exp(y_e) */ +#else /* BASOP_NOGLOB */ y[m / 2 + r / 2 + m / 2 + i] = L_msu( L_mult( x[i], neg_factor ), x[l - 1 - i], factor ); #endif move32(); } FOR( i = 0; i < m / 2; i++ ) { - y[sub( sub( add( shr( m, 1 ), shr( r, 1 ) ), 1 ), i )] = L_mult( x[add( add( l, shr( m, 1 ) ), i )], neg_factor ); + y[m / 2 + r / 2 - 1 - i] = L_mult( x[l + m / 2 + i], neg_factor ); /* exp(y_e) */ move32(); } FOR( i = 0; i < r / 2; i++ ) { #ifdef BASOP_NOGLOB - y[sub( sub( sub( add( shr( m, 1 ), shr( r, 1 ) ), 1 ), m / 2 ), i )] = L_mac_sat( L_mult( x[add( add( l, m ), i )], neg_factor ), x[sub( sub( add( add( l, m ), r ), 1 ), i )], factor ); + y[m / 2 + r / 2 - 1 - m / 2 - i] = L_mac_sat( L_mult( x[l + m + i], neg_factor ), x[l + m + r - 1 - i], factor ); /* exp(y_e) */ #else y[m / 2 + r / 2 - 1 - m / 2 - i] = L_mac( L_mult( x[l + m + i], neg_factor ), x[l + m + r - 1 - i], factor ); #endif @@ -210,19 +217,25 @@ void TCX_MDST( } *y_e = sub( 15, *y_e ); + move16(); + edst_fx( y, y, add( add( shr( l, 1 ), m ), shr( r, 1 ) ), y_e ); + *y_e = sub( 15 - 1, *y_e ); + move16(); + return; } void TCX_MDCT_Inverse( - Word32 *x, + Word32 *x, /* exp(x_e) */ Word16 x_e, - Word16 *y, - const Word16 l, - const Word16 m, - const Word16 r, - const Word16 element_mode ) + Word16 *y, /* Qy */ + const Word16 l, /* Q0 */ + const Word16 m, /* Q0 */ + const Word16 r, /* Q0 */ + const Word16 element_mode /* Q0 */ +) { Word16 i, fac, negfac, s; @@ -239,7 +252,7 @@ void TCX_MDCT_Inverse( edct_fx( x, tmp_buf + L2, add( add( shr( l, 1 ), m ), shr( r, 1 ) ), &x_e ); x_e = sub( 15, x_e ); - fac = TCX_MDCT_Inverse_GetScaleFactor( add( add( shr( l, 1 ), m ), shr( r, 1 ) ), &fac_e ); + fac = TCX_MDCT_Inverse_GetScaleFactor( add( add( shr( l, 1 ), m ), shr( r, 1 ) ), &fac_e ); /* exp(fac_e) */ x_e = add( x_e, fac_e ); negfac = negate( fac ); @@ -250,7 +263,7 @@ void TCX_MDCT_Inverse( FOR( i = 0; i < R2; i++ ) { #ifdef BASOP_NOGLOB - y[add( add( add( l, m ), R2 ), i )] = round_fx_sat( L_shl_sat( Mpy_32_16_1( tmp_buf[add( L2, i )], negfac ), s ) ); /* fold out right end of DCT */ + y[l + m + R2 + i] = round_fx_sat( L_shl_sat( Mpy_32_16_1( tmp_buf[L2 + i], negfac ), s ) ); /* fold out right end of DCT exp(fac_e)*/ #else y[l + m + R2 + i] = round_fx( L_shl( Mpy_32_16_1( tmp_buf[L2 + i], negfac ), s ) ); /* fold out right end of DCT */ #endif @@ -261,38 +274,39 @@ void TCX_MDCT_Inverse( FOR( i = 0; i < L2; i++ ) { #ifdef BASOP_NOGLOB - y[i] = round_fx_sat( L_shl_sat( Mpy_32_16_1( tmp_buf[add( add( add( L2, m ), R2 ), i )], fac ), s ) ); /* negate, fold out left end of DCT */ + y[i] = round_fx_sat( L_shl_sat( Mpy_32_16_1( tmp_buf[L2 + m + R2 + i], fac ), s ) ); /* negate, fold out left end of DCT exp(fac_e)*/ #else y[i] = round_fx( L_shl( Mpy_32_16_1( tmp_buf[L2 + m + R2 + i], fac ), s ) ); /* negate, fold out left end of DCT */ #endif move16(); } - FOR( i = 0; i < shr( add( L2, add( m, R2 ) ), 1 ); i++ ) + FOR( i = 0; i < ( ( L2 + m + R2 ) >> 1 ); i++ ) { Word16 f; #ifdef BASOP_NOGLOB - f = round_fx_sat( L_shl_sat( Mpy_32_16_1( tmp_buf[add( L2, i )], negfac ), s ) ); - y[add( L2, i )] = round_fx_sat( L_shl_sat( Mpy_32_16_1( tmp_buf[sub( sub( add( add( l, m ), R2 ), 1 ), i )], negfac ), s ) ); /* time-reverse mid of DCT */ + f = round_fx_sat( L_shl_sat( Mpy_32_16_1( tmp_buf[L2 + i], negfac ), s ) ); + y[L2 + i] = round_fx_sat( L_shl_sat( Mpy_32_16_1( tmp_buf[l + m + R2 - 1 - i], negfac ), s ) ); /* time-reverse mid of DCT exp(fac_e)*/ #else f = round_fx( L_shl( Mpy_32_16_1( tmp_buf[L2 + i], negfac ), s ) ); y[L2 + i] = round_fx( L_shl( Mpy_32_16_1( tmp_buf[l + m + R2 - 1 - i], negfac ), s ) ); /* time-reverse mid of DCT */ #endif move16(); - y[sub( sub( add( add( l, m ), R2 ), 1 ), i )] = f; + y[l + m + R2 - 1 - i] = f; move16(); } } #ifdef IVAS_FLOAT_FIXED void TCX_MDST_Inverse_fx( - Word32 *x, + Word32 *x, /* exp(x_e) */ Word16 x_e, - Word16 *y, - const Word16 l, - const Word16 m, - const Word16 r ) + Word16 *y, /* Qx */ + const Word16 l, /* Q0 */ + const Word16 m, /* Q0 */ + const Word16 r /* Q0 */ +) { Word16 i, fac, negfac, s; @@ -319,25 +333,25 @@ void TCX_MDST_Inverse_fx( FOR( i = 0; i < R2; i++ ) { - y[add( add( add( l, m ), R2 ), i )] = round_fx( L_shl( Mpy_32_16_1( tmp_buf[add( L2, i )], fac ), s ) ); /* fold out right end of DCT */ + y[l + m + R2 + i] = round_fx( L_shl( Mpy_32_16_1( tmp_buf[L2 + i], fac ), s ) ); /* fold out right end of DCT exp(fac_e)*/ move16(); } FOR( i = 0; i < L2; i++ ) { - y[i] = round_fx( L_shl( Mpy_32_16_1( tmp_buf[add( add( add( L2, m ), R2 ), i )], negfac ), s ) ); /* negate, fold out left end of DCT */ + y[i] = round_fx( L_shl( Mpy_32_16_1( tmp_buf[L2 + m + R2 + i], negfac ), s ) ); /* negate, fold out left end of DCT exp(fac_e)*/ move16(); } - FOR( i = 0; i < shr( add( L2, add( m, R2 ) ), 1 ); i++ ) + FOR( i = 0; i < ( ( L2 + m + R2 ) >> 1 ); i++ ) { Word16 f; - f = round_fx( L_shl( Mpy_32_16_1( tmp_buf[add( L2, i )], fac ), s ) ); + f = round_fx( L_shl( Mpy_32_16_1( tmp_buf[L2 + i], fac ), s ) ); - y[add( L2, i )] = round_fx( L_shl( Mpy_32_16_1( tmp_buf[sub( sub( add( add( l, m ), R2 ), 1 ), i )], negfac ), s ) ); /* time-reverse mid of DCT */ + y[L2 + i] = round_fx( L_shl( Mpy_32_16_1( tmp_buf[l + m + R2 - 1 - i], negfac ), s ) ); /* time-reverse mid of DCT exp(fac_e)*/ move16(); - y[sub( sub( add( add( l, m ), R2 ), 1 ), i )] = negate( f ); + y[l + m + R2 - 1 - i] = negate( f ); move16(); } } @@ -349,13 +363,14 @@ void TCX_MDST_Inverse_fx( *-------------------------------------------------------------------*/ void TCX_MDXT_Inverse_fx( - const Word32 *x, + const Word32 *x, /* exp(x_e) */ Word16 x_e, - Word16 *y, - const Word16 l, - const Word16 m, - const Word16 r, - const UWord16 kernel_type ) + Word16 *y, /* Qx */ + const Word16 l, /* Q0 */ + const Word16 m, /* Q0 */ + const Word16 r, /* Q0 */ + const UWord16 kernel_type /* Q0 */ +) { Word16 signLeft; Word16 signRight; @@ -395,24 +410,24 @@ void TCX_MDXT_Inverse_fx( FOR( i = 0; i < L2; i++ ) { - y[i] = round_fx( L_shl( Mpy_32_16_1( tmp_buf[add( add( add( L2, m ), R2 ), i )], signLeft ), s ) ); /* fold out the left end */ + y[i] = round_fx( L_shl( Mpy_32_16_1( tmp_buf[L2 + m + R2 + i], signLeft ), s ) ); /* fold out the left end exp(fac_e)*/ } FOR( i = 0; i < R2; i++ ) { - y[add( add( add( l, m ), R2 ), i )] = round_fx( L_shl( Mpy_32_16_1( tmp_buf[add( L2, i )], signRight ), s ) ); /* ...and right end */ + y[l + m + R2 + i] = round_fx( L_shl( Mpy_32_16_1( tmp_buf[L2 + i], signRight ), s ) ); /* ...and right end exp(fac_e)*/ move16(); } - FOR( i = 0; i < ( ( add( add( L2, m ), R2 ) ) >> 1 ); i++ ) + FOR( i = 0; i < ( ( L2 + m + R2 ) >> 1 ); i++ ) { - f = round_fx( L_shl( Mpy_32_16_1( tmp_buf[add( L2, i )], negfac ), s ) ); + f = round_fx( L_shl( Mpy_32_16_1( tmp_buf[L2 + i], negfac ), s ) ); - y[add( L2, i )] = round_fx( L_shl( Mpy_32_16_1( tmp_buf[sub( sub( add( add( l, m ), R2 ), 1 ), i )], negfac ), s ) ); /* time-reverse mid of DCT */ + y[L2 + i] = round_fx( L_shl( Mpy_32_16_1( tmp_buf[l + m + R2 - 1 - i], negfac ), s ) ); /* time-reverse mid of DCT exp(fac_e)*/ move16(); - y[sub( sub( add( add( l, m ), R2 ), 1 ), i )] = f; + y[l + m + R2 - 1 - i] = f; move16(); } diff --git a/lib_com/vlpc_2st_com_fx.c b/lib_com/vlpc_2st_com_fx.c index c54e5632f..3f06d3508 100644 --- a/lib_com/vlpc_2st_com_fx.c +++ b/lib_com/vlpc_2st_com_fx.c @@ -11,9 +11,9 @@ void lsf_weight_2st( - const Word16 *lsfq, /* input: quantized lsf coefficients (14Q1*1.28) */ - Word16 *w, /* output: weighting function (0Q15*1.28) */ - const Word16 mode /* input: operational mode */ + const Word16 *lsfq, /* input: quantized lsf coefficients (14Q1*1.28) */ + Word16 *w, /* output: weighting function (0Q15*1.28) */ + const Word16 mode /* input: operational mode Q0 */ ) { Word16 i; @@ -50,7 +50,7 @@ void lsf_weight_2st( /*w[i] = (weight * sqrt(d[i]*d[i+1])));*/ - w[i] = mult_r( weight, getSqrtWord32( L_shl( L_mult0( d[i], d[i + 1] ), 6 ) ) ); + w[i] = mult_r( weight, getSqrtWord32( L_shl( L_mult0( d[i], d[i + 1] ), 6 ) ) ); /* Q15 * 1.28 */ move16(); } diff --git a/lib_com/weight_a_fx.c b/lib_com/weight_a_fx.c index 99b621fa5..782979236 100644 --- a/lib_com/weight_a_fx.c +++ b/lib_com/weight_a_fx.c @@ -15,11 +15,11 @@ *------------------------------------------------------------------*/ void weight_a_subfr_fx( - const Word16 nb_subfr, /* i : number of subframes */ + const Word16 nb_subfr, /* i : number of subframes Q0 */ const Word16 *A, /* i : LP filter coefficients Q12 */ Word16 *Aw, /* o : weighted LP filter coefficients Q12 */ - const Word16 gamma, /* i : weighting factor */ - const Word16 order /* i : order of LP filter */ + const Word16 gamma, /* i : weighting factor Q15 */ + const Word16 order /* i : order of LP filter Q0 */ ) { Word16 k, orderp1; @@ -28,7 +28,7 @@ void weight_a_subfr_fx( orderp1 = add( order, 1 ); FOR( k = 0; k < nb_subfr; k++ ) { - weight_a_fx( &A[imult1616( k, ( orderp1 ) )], &Aw[imult1616( k, ( orderp1 ) )], gamma, order ); + weight_a_fx( &A[k * ( orderp1 )], &Aw[k * ( orderp1 )], gamma, order ); } return; @@ -63,23 +63,23 @@ void weight_a_lc_fx( Word16 shift; const Word16 *ptr_gamma; - ptr_gamma = gammatbl; - Amax = L_mult( 16384, a[0] ); + ptr_gamma = gammatbl; /* Q15 */ + Amax = L_mult( 16384, a[0] ); /* Q27 */ FOR( i = 1; i < m; i++ ) { - Amax = L_max( Amax, L_abs( L_mult0( *ptr_gamma++, a[i] ) ) ); + Amax = L_max( Amax, L_abs( L_mult0( *ptr_gamma++, a[i] ) ) ); /* Q27 */ } - Amax = L_max( Amax, L_abs( L_mult0( *ptr_gamma++, a[m] ) ) ); + Amax = L_max( Amax, L_abs( L_mult0( *ptr_gamma++, a[m] ) ) ); /* Q27 */ shift = norm_l( Amax ); - ptr_gamma = gammatbl; - ap[0] = shl( a[0], sub( shift, 1 ) ); + ptr_gamma = gammatbl; /* Q15 */ + ap[0] = shl( a[0], sub( shift, 1 ) ); /* Q11 + shift */ move16(); FOR( i = 1; i < m; i++ ) { - ap[i] = round_fx( L_shl( L_mult0( a[i], *ptr_gamma++ ), shift ) ); + ap[i] = round_fx( L_shl( L_mult0( a[i], *ptr_gamma++ ), shift ) ); /* Q11 + shift */ move16(); } - ap[m] = round_fx( L_shl( L_mult0( a[m], *ptr_gamma++ ), shift ) ); + ap[m] = round_fx( L_shl( L_mult0( a[m], *ptr_gamma++ ), shift ) ); /* Q11 + shift */ move16(); return; @@ -106,31 +106,31 @@ void weight_a_fx( move32(); #endif - fac = gamma; + fac = gamma; /* Q15 */ move16(); - Amax = L_mult( 16384, a[0] ); + Amax = L_mult( 16384, a[0] ); /* Q27 */ FOR( i = 1; i < m; i++ ) { - Amax = L_max( Amax, L_abs( L_mult0( fac, a[i] ) ) ); - fac = mult_r( fac, gamma ); + Amax = L_max( Amax, L_abs( L_mult0( fac, a[i] ) ) ); /* Q27 */ + fac = mult_r( fac, gamma ); /* Q15 */ } Amax = L_max( Amax, L_abs( L_mult0( fac, a[m] ) ) ); shift = norm_l( Amax ); - fac = gamma; + fac = gamma; /* Q15 */ move16(); - ap[0] = shl( a[0], sub( shift, 1 ) ); + ap[0] = shl( a[0], sub( shift, 1 ) ); /* Q11 + shift */ move16(); FOR( i = 1; i < m; i++ ) { #ifdef BASOP_NOGLOB - ap[i] = round_fx_o( L_shl( L_mult0( a[i], fac ), shift ), &Overflow ); -#else /* BASOP_NOGLOB */ + ap[i] = round_fx_o( L_shl( L_mult0( a[i], fac ), shift ), &Overflow ); /* Q11 + shift */ +#else /* BASOP_NOGLOB */ ap[i] = round_fx( L_shl( L_mult0( a[i], fac ), shift ) ); #endif move16(); - fac = mult_r( fac, gamma ); + fac = mult_r( fac, gamma ); /* Q15 */ } - ap[m] = round_fx( L_shl( L_mult0( a[m], fac ), shift ) ); + ap[m] = round_fx( L_shl( L_mult0( a[m], fac ), shift ) ); /* Q11 + shift */ move16(); return; @@ -152,10 +152,11 @@ void weight_a_fx( * void */ void E_LPC_a_weight_inv( - const Word16 *a, - Word16 *ap, - const Word16 inv_gamma, - const Word16 m ) + const Word16 *a, /* Q12 */ + Word16 *ap, /* Q12 */ + const Word16 inv_gamma, /* Q14 */ + const Word16 m /* Q0 */ +) { Word16 i; static const Word16 inv_gamma_tab_12k8[16] = { 17809, 19357, 21041, 22870, 24859, 27020, 29370, 31924, /* Q14 */ @@ -201,11 +202,11 @@ void E_LPC_a_weight_inv( Word16 shift; - IF( EQ_16( inv_gamma, 16384 ) ) + IF( EQ_16( inv_gamma, 16384 /* 1 in Q14 */ ) ) { FOR( i = 0; i <= m; i++ ) { - ap[i] = a[i]; + ap[i] = a[i]; /* Q12 */ move16(); } return; @@ -214,36 +215,36 @@ void E_LPC_a_weight_inv( assert( inv_gamma == GAMMA1_INV || inv_gamma == GAMMA16k_INV ); assert( m == 16 ); - inv_gamma_tab = inv_gamma_tab_12k8; + inv_gamma_tab = inv_gamma_tab_12k8; /* Q14 */ if ( EQ_16( inv_gamma, GAMMA16k_INV ) ) { - inv_gamma_tab = inv_gamma_tab_16k; + inv_gamma_tab = inv_gamma_tab_16k; /* Q14 */ } Amax = L_mult( 16384, a[0] ); FOR( i = 1; i < 9; i++ ) { - Amax = L_max( Amax, L_abs( L_mult( a[i], inv_gamma_tab[i - 1] ) ) ); + Amax = L_max( Amax, L_abs( L_mult( a[i], inv_gamma_tab[i - 1] ) ) ); /* Q27 */ } FOR( i = 9; i < 17; i++ ) { - Amax = L_max( Amax, L_abs( L_shl( L_mult( a[i], inv_gamma_tab[i - 1] ), 1 ) ) ); + Amax = L_max( Amax, L_abs( L_shl( L_mult( a[i], inv_gamma_tab[i - 1] ), 1 ) ) ); /* Q27 */ } shift = norm_l( Amax ); - ap[0] = shl( a[0], sub( shift, 1 ) ); + ap[0] = shl( a[0], sub( shift, 1 ) ); /* Q11 + shift */ move16(); FOR( i = 1; i < 9; i++ ) { - L_tmp = L_mult( a[i], inv_gamma_tab[i - 1] ); - ap[i] = round_fx( L_shl( L_tmp, shift ) ); + L_tmp = L_mult( a[i], inv_gamma_tab[i - 1] ); /* Q27 */ + ap[i] = round_fx( L_shl( L_tmp, shift ) ); /* Q11 + shift */ move16(); } shift = add( shift, 1 ); FOR( i = 9; i < 17; i++ ) { - L_tmp = L_mult( a[i], inv_gamma_tab[i - 1] ); - ap[i] = round_fx( L_shl( L_tmp, shift ) ); + L_tmp = L_mult( a[i], inv_gamma_tab[i - 1] ); /* Q26 */ + ap[i] = round_fx( L_shl( L_tmp, shift ) ); /* Q11 + shift */ move16(); } diff --git a/lib_com/weight_fx.c b/lib_com/weight_fx.c index 6c123cbf2..eb3f19bf7 100644 --- a/lib_com/weight_fx.c +++ b/lib_com/weight_fx.c @@ -15,45 +15,45 @@ *--------------------------------------------------------------------------*/ static void sfm2mqb_fx( - Word16 spe[], /* i : sub-vectors */ - Word16 spe2q[], /* o : pbands */ - const Word16 nb_sfm /* i : number of norms */ + Word16 spe[], /* i : sub-vectors Q0*/ + Word16 spe2q[], /* o : pbands Q0*/ + const Word16 nb_sfm /* i : number of norms Q0*/ ) { Word16 tmp, i; /* short groups */ - spe2q[0] = add( spe[0], 3 ); + spe2q[0] = add( spe[0], 3 ); /* Q0 */ move16(); - spe2q[1] = add( spe[1], 3 ); + spe2q[1] = add( spe[1], 3 ); /* Q0 */ move16(); - spe2q[2] = add( spe[2], 3 ); + spe2q[2] = add( spe[2], 3 ); /* Q0 */ move16(); - spe2q[3] = add( spe[3], 3 ); + spe2q[3] = add( spe[3], 3 ); /* Q0 */ move16(); - spe2q[4] = add( spe[4], 3 ); + spe2q[4] = add( spe[4], 3 ); /* Q0 */ move16(); - spe2q[5] = add( spe[5], 3 ); + spe2q[5] = add( spe[5], 3 ); /* Q0 */ move16(); - spe2q[6] = add( spe[6], 3 ); + spe2q[6] = add( spe[6], 3 ); /* Q0 */ move16(); - spe2q[7] = add( spe[7], 3 ); + spe2q[7] = add( spe[7], 3 ); /* Q0 */ move16(); - spe2q[8] = add( spe[8], 3 ); + spe2q[8] = add( spe[8], 3 ); /* Q0 */ move16(); - spe2q[9] = add( spe[9], 3 ); + spe2q[9] = add( spe[9], 3 ); /* Q0 */ move16(); - spe2q[10] = add( shr( add( spe[10], spe[11] ), 1 ), 4 ); + spe2q[10] = add( shr( add( spe[10], spe[11] ), 1 ), 4 ); /* Q0 */ move16(); - spe2q[11] = add( shr( add( spe[12], spe[13] ), 1 ), 4 ); + spe2q[11] = add( shr( add( spe[12], spe[13] ), 1 ), 4 ); /* Q0 */ move16(); - spe2q[12] = add( shr( add( spe[14], spe[15] ), 1 ), 4 ); + spe2q[12] = add( shr( add( spe[14], spe[15] ), 1 ), 4 ); /* Q0 */ move16(); - spe2q[13] = add( shr( add( spe[16], spe[17] ), 1 ), 5 ); + spe2q[13] = add( shr( add( spe[16], spe[17] ), 1 ), 5 ); /* Q0 */ move16(); - spe2q[14] = add( shr( add( spe[18], spe[19] ), 1 ), 5 ); + spe2q[14] = add( shr( add( spe[18], spe[19] ), 1 ), 5 ); /* Q0 */ move16(); tmp = 0; @@ -62,16 +62,16 @@ static void sfm2mqb_fx( { tmp = add( tmp, spe[i] ); } - spe2q[15] = add( mult( tmp, 8192 ), 6 ); + spe2q[15] = add( mult( tmp, 8192 ), 6 ); /* Q0 */ move16(); tmp = 0; move16(); FOR( i = 24; i < 27; i++ ) { - tmp = add( tmp, spe[i] ); + tmp = add( tmp, spe[i] ); /* Q0 */ } - spe2q[16] = add( mult( tmp, 10923 ), 6 ); + spe2q[16] = add( mult( tmp, 10923 ), 6 ); /* Q0 */ move16(); IF( GT_16( nb_sfm, SFM_N_STA_8k ) ) @@ -80,9 +80,9 @@ static void sfm2mqb_fx( move16(); FOR( i = 27; i < 30; i++ ) { - tmp = add( tmp, spe[i] ); + tmp = add( tmp, spe[i] ); /* Q0 */ } - spe2q[17] = add( mult( tmp, 10923 ), 6 ); + spe2q[17] = add( mult( tmp, 10923 ), 6 ); /* Q0 */ move16(); IF( GT_16( nb_sfm, SFM_N_STA_10k ) ) @@ -91,18 +91,18 @@ static void sfm2mqb_fx( move16(); FOR( i = 30; i < 35; i++ ) { - tmp = add( tmp, spe[i] ); + tmp = add( tmp, spe[i] ); /* Q0 */ } - spe2q[18] = add( mult( tmp, 6553 ), 7 ); + spe2q[18] = add( mult( tmp, 6553 ), 7 ); /* Q0 */ move16(); tmp = 0; move16(); FOR( i = 35; i < 44; i++ ) { - tmp = add( tmp, spe[i] ); + tmp = add( tmp, spe[i] ); /* Q0 */ } - spe2q[19] = add( mult( tmp, 3641 ), 8 ); + spe2q[19] = add( mult( tmp, 3641 ), 8 ); /* Q0 */ move16(); } } @@ -117,68 +117,68 @@ static void sfm2mqb_fx( *--------------------------------------------------------------------------*/ static void mqb2sfm_fx( - Word16 spe2q[], /* i : pbands */ - Word16 spe[], /* o : sub-vectors */ - const Word16 lnb_sfm /* i : number of norms */ + Word16 spe2q[], /* i : pbands Q0*/ + Word16 spe[], /* o : sub-vectors Q0*/ + const Word16 lnb_sfm /* i : number of norms Q0*/ ) { Word16 i; - spe[0] = spe2q[0]; + spe[0] = spe2q[0]; /* Q0 */ move16(); - spe[1] = spe2q[1]; + spe[1] = spe2q[1]; /* Q0 */ move16(); - spe[2] = spe2q[2]; + spe[2] = spe2q[2]; /* Q0 */ move16(); - spe[3] = spe2q[3]; + spe[3] = spe2q[3]; /* Q0 */ move16(); - spe[4] = spe2q[4]; + spe[4] = spe2q[4]; /* Q0 */ move16(); - spe[5] = spe2q[5]; + spe[5] = spe2q[5]; /* Q0 */ move16(); - spe[6] = spe2q[6]; + spe[6] = spe2q[6]; /* Q0 */ move16(); - spe[7] = spe2q[7]; + spe[7] = spe2q[7]; /* Q0 */ move16(); - spe[8] = spe2q[8]; + spe[8] = spe2q[8]; /* Q0 */ move16(); - spe[9] = spe2q[9]; + spe[9] = spe2q[9]; /* Q0 */ move16(); - spe[10] = spe2q[10]; + spe[10] = spe2q[10]; /* Q0 */ move16(); - spe[11] = spe2q[10]; + spe[11] = spe2q[10]; /* Q0 */ move16(); - spe[12] = spe2q[11]; + spe[12] = spe2q[11]; /* Q0 */ move16(); - spe[13] = spe2q[11]; + spe[13] = spe2q[11]; /* Q0 */ move16(); - spe[14] = spe2q[12]; + spe[14] = spe2q[12]; /* Q0 */ move16(); - spe[15] = spe2q[12]; + spe[15] = spe2q[12]; /* Q0 */ move16(); - spe[16] = spe2q[13]; + spe[16] = spe2q[13]; /* Q0 */ move16(); - spe[17] = spe2q[13]; + spe[17] = spe2q[13]; /* Q0 */ move16(); - spe[18] = spe2q[14]; + spe[18] = spe2q[14]; /* Q0 */ move16(); - spe[19] = spe2q[14]; + spe[19] = spe2q[14]; /* Q0 */ move16(); FOR( i = 20; i < 24; i++ ) { - spe[i] = spe2q[15]; + spe[i] = spe2q[15]; /* Q0 */ move16(); } FOR( i = 24; i < 27; i++ ) { - spe[i] = spe2q[16]; + spe[i] = spe2q[16]; /* Q0 */ move16(); } @@ -186,7 +186,7 @@ static void mqb2sfm_fx( { FOR( i = 27; i < 30; i++ ) { - spe[i] = spe2q[17]; + spe[i] = spe2q[17]; /* Q0 */ move16(); } @@ -194,13 +194,13 @@ static void mqb2sfm_fx( { FOR( i = 30; i < 35; i++ ) { - spe[i] = spe2q[18]; + spe[i] = spe2q[18]; /* Q0 */ move16(); } FOR( i = 35; i < 44; i++ ) { - spe[i] = spe2q[19]; + spe[i] = spe2q[19]; /* Q0 */ move16(); } } @@ -216,9 +216,9 @@ static void mqb2sfm_fx( *--------------------------------------------------------------------------*/ void map_quant_weight_fx( - const Word16 normqlg2[], /* i : quantized norms */ - Word16 wnorm[], /* o : weighted norm */ - const Word16 is_transient /* i : transient flag */ + const Word16 normqlg2[], /* i : quantized norms Q0*/ + Word16 wnorm[], /* o : weighted norm Q0*/ + const Word16 is_transient /* i : transient flag Q0*/ ) { Word16 sfm; @@ -247,13 +247,13 @@ void map_quant_weight_fx( move16(); FOR( k = 0; k < 4; k++ ) { - sum = add( sum, normqlg2[sfm + k] ); + sum = add( sum, normqlg2[sfm + k] ); /* Q0 */ } sum = shr( sum, 2 ); FOR( k = 0; k < 4; k++ ) { - spe[sfm + k] = sum; + spe[sfm + k] = sum; /* Q0 */ move16(); } } @@ -262,7 +262,7 @@ void map_quant_weight_fx( { FOR( sfm = 0; sfm < lnb_sfm; sfm++ ) { - spe[sfm] = normqlg2[sfm]; + spe[sfm] = normqlg2[sfm]; /* Q0 */ move16(); } } @@ -271,28 +271,28 @@ void map_quant_weight_fx( FOR( sfm = 0; sfm < num_map_bands; sfm++ ) { - spe2q[sfm] = sub( spe2q[sfm], 10 ); + spe2q[sfm] = sub( spe2q[sfm], 10 ); /* Q0 */ move16(); } /* spectral smoothing */ FOR( sfm = 1; sfm < num_map_bands; sfm++ ) { - tmp16 = sub( spe2q[sfm - 1], 4 ); - spe2q[sfm] = s_max( spe2q[sfm], tmp16 ); + tmp16 = sub( spe2q[sfm - 1], 4 ); /* Q0 */ + spe2q[sfm] = s_max( spe2q[sfm], tmp16 ); /* Q0 */ move16(); } FOR( sfm = num_map_bands - 2; sfm >= 0; sfm-- ) { - tmp16 = sub( spe2q[sfm + 1], 8 ); - spe2q[sfm] = s_max( spe2q[sfm], tmp16 ); + tmp16 = sub( spe2q[sfm + 1], 8 ); /* Q0 */ + spe2q[sfm] = s_max( spe2q[sfm], tmp16 ); /* Q0 */ move16(); } FOR( sfm = 0; sfm < num_map_bands; sfm++ ) { - spe2q[sfm] = s_max( spe2q[sfm], a_map[sfm] ); + spe2q[sfm] = s_max( spe2q[sfm], a_map[sfm] ); /* Q0 */ move16(); } @@ -304,15 +304,15 @@ void map_quant_weight_fx( FOR( sfm = 0; sfm < num_map_bands; sfm++ ) { - spe2q[sfm] = sub( sfm_width[sfm], spe2q[sfm] ); + spe2q[sfm] = sub( sfm_width[sfm], spe2q[sfm] ); /* Q0 */ move16(); - spe2q_max = s_max( spe2q[sfm], spe2q_max ); - spe2q_min = s_min( spe2q[sfm], spe2q_min ); + spe2q_max = s_max( spe2q[sfm], spe2q_max ); /* Q0 */ + spe2q_min = s_min( spe2q[sfm], spe2q_min ); /* Q0 */ } FOR( sfm = 0; sfm < num_map_bands; sfm++ ) { - spe2q[sfm] = sub( spe2q[sfm], spe2q_min ); + spe2q[sfm] = sub( spe2q[sfm], spe2q_min ); /* Q0 */ move16(); } @@ -338,12 +338,12 @@ void map_quant_weight_fx( move16(); FOR( k = 0; k < 4; k++ ) { - sum = add( sum, spe[sfm + k] ); + sum = add( sum, spe[sfm + k] ); /* Q0 */ } sum = shr( sum, 2 ); FOR( k = 0; k < 4; k++ ) { - spe[sfm + k] = sum; + spe[sfm + k] = sum; /* Q0 */ move16(); } } @@ -352,7 +352,7 @@ void map_quant_weight_fx( /* modify the norms for bit-allocation */ FOR( sfm = 0; sfm < lnb_sfm; sfm++ ) { - wnorm[sfm] = add( spe[sfm], normqlg2[sfm] ); + wnorm[sfm] = add( spe[sfm], normqlg2[sfm] ); /* Q0 */ move16(); } diff --git a/lib_com/wi_fx.c b/lib_com/wi_fx.c index 675ba31aa..19788dc0a 100644 --- a/lib_com/wi_fx.c +++ b/lib_com/wi_fx.c @@ -57,18 +57,18 @@ ivas_error DTFS_new_fx( move16(); dtfs_fx->nH_4kHz_fx = 0; move16(); - dtfs_fx->upper_cut_off_freq_of_interest_fx = 3300; + dtfs_fx->upper_cut_off_freq_of_interest_fx = 3300; // Q0 move16(); - dtfs_fx->upper_cut_off_freq_fx = 4000; + dtfs_fx->upper_cut_off_freq_fx = 4000; // Q0 move16(); dtfs_fx->Q = 0; move16(); FOR( i = 0; i < MAXLAG_WI; i++ ) { - dtfs_fx->a_fx[i] = 0; + dtfs_fx->a_fx[i] = 0; // dtfs_fx->Q move16(); - dtfs_fx->b_fx[i] = 0; + dtfs_fx->b_fx[i] = 0; // dtfs_fx->Q move16(); } *dtfs_out = dtfs_fx; @@ -90,13 +90,13 @@ void DTFS_copy_fx( Word16 k; FOR( k = 0; k < MAXLAG_WI; k++ ) { - Xout_fx->a_fx[k] = Xinp_fx.a_fx[k]; + Xout_fx->a_fx[k] = Xinp_fx.a_fx[k]; /* Q(DTFS_STRUCTURE.Q) */ move16(); } FOR( k = 0; k < MAXLAG_WI; k++ ) { - Xout_fx->b_fx[k] = Xinp_fx.b_fx[k]; + Xout_fx->b_fx[k] = Xinp_fx.b_fx[k]; /* Q(DTFS_STRUCTURE.Q) */ move16(); } @@ -106,9 +106,9 @@ void DTFS_copy_fx( move16(); Xout_fx->nH_4kHz_fx = Xinp_fx.nH_4kHz_fx; move16(); - Xout_fx->upper_cut_off_freq_of_interest_fx = Xinp_fx.upper_cut_off_freq_of_interest_fx; + Xout_fx->upper_cut_off_freq_of_interest_fx = Xinp_fx.upper_cut_off_freq_of_interest_fx; // Q0 move16(); - Xout_fx->upper_cut_off_freq_fx = Xinp_fx.upper_cut_off_freq_fx; + Xout_fx->upper_cut_off_freq_fx = Xinp_fx.upper_cut_off_freq_fx; // Q0 move16(); Xout_fx->Q = Xinp_fx.Q; move16(); @@ -176,7 +176,7 @@ void DTFS_sub_fx( * DTFS inverse. *-------------------------------------------------------------------*/ -static void DTFS_fast_fs_inv_fx( DTFS_STRUCTURE *X_fx, Word16 *out_fx, Word16 N_fx, Word16 LOG2N ) +static void DTFS_fast_fs_inv_fx( DTFS_STRUCTURE *X_fx, Word16 *out_fx /* Q0 */, Word16 N_fx, Word16 LOG2N ) { Word16 i, M_2, N_2, s; Word16 dbuf_fx[256 + 1]; @@ -194,7 +194,7 @@ static void DTFS_fast_fs_inv_fx( DTFS_STRUCTURE *X_fx, Word16 *out_fx, Word16 N_ { dbuf_fx[2 * i] = shl_r( X_fx->a_fx[i], s ); move16(); - dbuf_fx[add( 2 * i, 1 )] = shl_r( X_fx->b_fx[i], s ); + dbuf_fx[( 2 * i + 1 )] = shl_r( X_fx->b_fx[i], s ); move16(); } @@ -202,7 +202,7 @@ static void DTFS_fast_fs_inv_fx( DTFS_STRUCTURE *X_fx, Word16 *out_fx, Word16 N_ { dbuf_fx[2 * i] = 0; move16(); - dbuf_fx[add( 2 * i, 1 )] = 0; + dbuf_fx[( 2 * i + 1 )] = 0; move16(); } @@ -269,7 +269,7 @@ static Word16 DTFS_alignment_weight_fx( move32(); #endif diff_fx = 0; /* to avoid compilation warnings */ - + move16(); DTFS_copy_fx( &X1, *X_fx ); /* X1 = *X_fx ; */ DTFS_adjustLag_fx( &X1, X2.lag_fx ); @@ -474,7 +474,7 @@ Word16 DTFS_alignment_full_fx( } - IF( X1_DTFS_fx.lag_fx < X2_DTFS_fx.lag_fx ) + IF( LT_16( X1_DTFS_fx.lag_fx, X2_DTFS_fx.lag_fx ) ) { DTFS_zeroPadd_fx( X2_DTFS_fx.lag_fx, &X1_DTFS_fx ); } @@ -531,7 +531,7 @@ Word16 DTFS_alignment_full_fx( #endif } - if ( GT_32( corr_fx, maxcorr_fx ) ) + IF( GT_32( corr_fx, maxcorr_fx ) ) { fshift_fx = n; /* Q1 */ move16(); @@ -708,7 +708,7 @@ void DTFS_zeroPadd_fx( { Word16 i, start, end, diff_fx, rem_fx; - if ( EQ_16( N_fx, X_fx->lag_fx ) ) + IF( EQ_16( N_fx, X_fx->lag_fx ) ) { return; } @@ -732,7 +732,7 @@ void DTFS_zeroPadd_fx( X_fx->nH_fx = find_rem( X_fx->upper_cut_off_freq_fx, diff_fx, &rem_fx ); move16(); - if ( GE_16( sub( X_fx->upper_cut_off_freq_fx, shr( (Word16) L_mult( diff_fx, X_fx->nH_fx ), 1 ) ), diff_fx ) ) + if ( GE_16( sub( X_fx->upper_cut_off_freq_fx, shr( extract_l( L_mult( diff_fx, X_fx->nH_fx ) ), 1 ) ), diff_fx ) ) { X_fx->nH_fx = add( X_fx->nH_fx, 1 ); move16(); @@ -1006,7 +1006,7 @@ void DTFS_to_fs_fx( move16(); tmp = s_min( shr( X_fx->lag_fx, 1 ), sub( MAXLAG_WI, 1 ) ); - FOR( k = add( nH_band, 1 ); k <= tmp; k++ ) + FOR( k = ( nH_band + 1 ); k <= tmp; k++ ) { X_fx->a_fx[k] = 0; move16(); @@ -1215,7 +1215,7 @@ static void DTFS_transform_fx( } ELSE { - w_fx = 16384; + w_fx = 16384; // 1.Q14 move16(); } } @@ -1321,7 +1321,7 @@ void DTFS_zeroFilter_fx( FOR( n = 0; n < N; n++ ) { #ifdef BASOP_NOGLOB - sum1_fx = L_mac_o( sum1_fx, LPC[n], C_fx[i_mult( 4, temp2 ) % i_mult( 4, X_fx->lag_fx )], &Overflow ); /* Q(12+15+1) */ + sum1_fx = L_mac_o( sum1_fx, LPC[n], C_fx[( 4 * temp2 ) % ( 4 * X_fx->lag_fx )], &Overflow ); /* Q(12+15+1) */ sum2_fx = L_mac_o( sum2_fx, LPC[n], S_fx[( 4 * temp2 ) % ( 4 * X_fx->lag_fx )], &Overflow ); #else sum1_fx = L_mac( sum1_fx, LPC[n], C_fx[i_mult( 4, temp2 ) % i_mult( 4, X_fx->lag_fx )] ); /* Q(12+15+1) */ @@ -1554,7 +1554,7 @@ void DTFS_adjustLag_fx( Word16 exp, tmp; Word32 L_tmp; - if ( EQ_16( N_fx, X_DTFS_FX->lag_fx ) ) + IF( EQ_16( N_fx, X_DTFS_FX->lag_fx ) ) { return; } @@ -1568,7 +1568,7 @@ void DTFS_adjustLag_fx( en_fx = DTFS_getEngy_fx( X_DTFS_FX ); /* Q = 2*(X_DTFS_FX->Q) */ tmp = s_min( shr( X_DTFS_FX->lag_fx, 1 ), X_DTFS_FX->nH_fx ); - FOR( k = add( shr( N_fx, 1 ), 1 ); k <= tmp; k++ ) + FOR( k = ( ( N_fx >> 1 ) + 1 ); k <= tmp; k++ ) { X_DTFS_FX->a_fx[k] = 0; move16(); @@ -1599,7 +1599,7 @@ void DTFS_adjustLag_fx( X_DTFS_FX->nH_4kHz_fx = extract_l( L_shl( L_tmp, sub( exp, 29 ) ) ); move16(); - if ( GE_16( sub( X_DTFS_FX->upper_cut_off_freq_fx, shr( extract_l( L_mult( diff_fx, X_DTFS_FX->nH_fx ) ), 1 ) ), diff_fx ) ) + IF( GE_16( sub( X_DTFS_FX->upper_cut_off_freq_fx, shr( extract_l( L_mult( diff_fx, X_DTFS_FX->nH_fx ) ), 1 ) ), diff_fx ) ) { X_DTFS_FX->nH_fx = add( X_DTFS_FX->nH_fx, 1 ); move16(); @@ -1610,7 +1610,7 @@ void DTFS_adjustLag_fx( tempnH_fx = Mult_32_32( mul1_fx, mul2_fx ); /* Q6 */ tempnH_fx = L_sub( (Word32) 256000, tempnH_fx ); /* Q6 */ - if ( GE_32( tempnH_fx, temp32_fx ) ) + IF( GE_32( tempnH_fx, temp32_fx ) ) { X_DTFS_FX->nH_4kHz_fx = add( X_DTFS_FX->nH_4kHz_fx, 1 ); move16(); @@ -2029,7 +2029,7 @@ Word32 DTFS_setEngyHarm_fx( count = add( count, 1 ); } - IF( GE_32( Lacc_max, 2147483647 ) ) + IF( GE_32( Lacc_max, 2147483647 /*1.Q31*/ ) ) { tmp = sub( HalfLag_fx, f_low_fx ); exp = norm_s( tmp ); @@ -2077,7 +2077,7 @@ Word32 DTFS_setEngyHarm_fx( #else fracb = round_fx( L_shl( en1_fx, expb ) ); #endif - IF( GE_32( Lacc_max, 2147483647 ) ) + IF( GE_32( Lacc_max, 2147483647 /*1.Q31*/ ) ) { expb = sub( 30, add( expb, sub( shl( X_fx->Q, 1 ), expp ) ) ); } @@ -2122,12 +2122,12 @@ Word32 DTFS_setEngyHarm_fx( move16(); } - if ( GE_32( Lacc_max, 2147483647 ) ) + IF( GE_32( Lacc_max, 2147483647 /*1.Q31*/ ) ) { *Qa_fx = sub( sub( X_fx->Q, add( 1, s_min( 2, expp ) ) ), exp ); move16(); } - else + ELSE { *Qa_fx = sub( sub( X_fx->Q, 1 ), exp ); move16(); @@ -2401,6 +2401,7 @@ static void cubicPhase_fx( /* Computation of the phase value at each sample point */ /* ph[n]= c0*n^3+c1*n^2+c2*n+c3, Q15 */ phOut_fx[0] = L_shl( ph1_fx, 11 ); /* Q27 */ + move32(); IF( LT_16( N, 181 ) ) { @@ -2526,6 +2527,7 @@ void DTFS_to_erb_fx( num_erb_fx = NUM_ERB_NB; move16(); + test(); test(); IF( EQ_16( X_fx.upper_cut_off_freq_fx, 0x02800 ) || EQ_16( X_fx.upper_cut_off_freq_fx, 4000 ) ) /* 0x2800=0.3125 in Q15 (4000Hz) */ { @@ -2536,7 +2538,6 @@ void DTFS_to_erb_fx( } ELSE IF( EQ_16( X_fx.upper_cut_off_freq_fx, 0x04000 ) || EQ_16( X_fx.upper_cut_off_freq_fx, 6400 ) ) /* 0x4000=0.5 in Q15 (6400Hz) */ { - test(); num_erb_fx = NUM_ERB_WB; move16(); erb_fx = &( erb_WB_fx[0] ); @@ -2551,6 +2552,7 @@ void DTFS_to_erb_fx( count[i] = 0; move16(); sum_a_fx[i] = L_deposit_l( 0 ); + move32(); } exp = norm_s( X_fx.lag_fx ); @@ -2587,6 +2589,7 @@ void DTFS_to_erb_fx( { #ifdef BASOP_NOGLOB out_fx[i] = round_fx_o( L_shl_o( sum_a_fx[i], n, &Overflow ), &Overflow ); /* Q13 */ + move16(); #else out_fx[i] = round_fx( L_shl( sum_a_fx[i], n ) ); /* Q13 */ #endif @@ -2710,7 +2713,7 @@ void erb_slot_fx( L_tmp = L_mult0( diff_fx, nH_band_fx ); /* Q0 */ - if ( L_sub( upper_cut_off_freq_fx, L_tmp ) >= diff_fx ) /* Q0 compare */ + IF( GE_32( L_sub( upper_cut_off_freq_fx, L_tmp ), L_deposit_l( diff_fx ) ) ) /* Q0 compare */ { nH_band_fx = add( nH_band_fx, 1 ); /* Q0 */ } @@ -2786,6 +2789,7 @@ void erb_slot_fx( L_tmp = L_shl_o( tmp, add( exp, 16 ), &Overflow ); mfreq_fx[j] = round_fx_o( L_tmp, &Overflow ); + move16(); #else L_tmp = L_shl( tmp, add( exp, 16 ) ); @@ -2838,6 +2842,9 @@ void DTFS_erb_inv_fx( Word32 Ltemp_fx, Ltemp2_fx; Word32 Lacc_fx; Word16 exp, tmp; + move16(); + move16(); + move16(); #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); @@ -3031,8 +3038,8 @@ void erb_add_fx( } ELSE IF( GT_16( l_fx, pl_fx ) ) { - tmp_fx = t_prev_erb_fx[sub( num_erb_fx, 1 )]; /* Q13 */ - FOR( i = sub( num_erb_fx, 1 ); i >= 0; i-- ) + tmp_fx = t_prev_erb_fx[( num_erb_fx - 1 )]; /* Q13 */ + FOR( i = ( num_erb_fx - 1 ); i >= 0; i-- ) { IF( pslot_fx[i] != 0 ) @@ -3054,7 +3061,7 @@ void erb_add_fx( IF( cslot_fx[i] != 0 ) { - curr_erb_fx[i] = add( AmpCB1_fx[sub( add( tmp_fx, i ), 1 )], t_prev_erb_fx[i] ); + curr_erb_fx[i] = add( AmpCB1_fx[( ( tmp_fx + i ) - 1 )], t_prev_erb_fx[i] ); move16(); /* Q13+Q13=Q13 */ curr_erb_fx[i] = s_max( 0, curr_erb_fx[i] ); move16(); @@ -3076,14 +3083,14 @@ void erb_add_fx( { IF( EQ_16( num_erb_fx, NUM_ERB_NB ) ) { - curr_erb_fx[i] = add( AmpCB2_NB_fx[sub( add( tmp_fx, i ), 11 )], t_prev_erb_fx[i] ); /* Q13+Q13=Q13 */ + curr_erb_fx[i] = add( AmpCB2_NB_fx[( ( tmp_fx + i ) - 11 )], t_prev_erb_fx[i] ); /* Q13+Q13=Q13 */ move16(); curr_erb_fx[i] = s_max( 0, curr_erb_fx[i] ); move16(); } ELSE IF( EQ_16( num_erb_fx, NUM_ERB_WB ) ) { - curr_erb_fx[i] = add( AmpCB2_WB_fx[sub( add( tmp2_fx, i ), 11 )], t_prev_erb_fx[i] ); /* Q13 */ + curr_erb_fx[i] = add( AmpCB2_WB_fx[( ( tmp2_fx + i ) - 11 )], t_prev_erb_fx[i] ); /* Q13 */ move16(); curr_erb_fx[i] = s_max( 0, curr_erb_fx[i] ); move16(); @@ -3322,8 +3329,7 @@ ivas_error WIsyn_fx( IF( FR_flag == 0 ) { alignment_fx = DTFS_alignment_weight_fx( &PREVCW_FX, *CURRCW_DTFS_FX, tmp_fx, curr_lpc_fx, curr_lpc_fx, S_fx, - C_fx, pf_temp1, pf_temp2, pf_temp, pf_n2 ); - move16(); /* Q7 */ + C_fx, pf_temp1, pf_temp2, pf_temp, pf_n2 ); /* Q7 */ } ELSE { @@ -3530,7 +3536,7 @@ Word16 ppp_extract_pitch_period_fx( } - tmp = (Word16) ( L_max( L_mult( CUTFREE_REL_RANGE_Q2, l ), CUTFREE_ABS_RANGE_Q3 ) ); /* Q3 */ + tmp = extract_l( ( L_max( L_mult( CUTFREE_REL_RANGE_Q2, l ), CUTFREE_ABS_RANGE_Q3 ) ) ); /* Q3 */ IF( tmp > 0 ) { @@ -4008,7 +4014,7 @@ static void c_fft_wi_fx( Word16 *farray_ptr_fx, Word16 size, Word16 stage, Word1 k = n_2; move16(); - WHILE( GE_16( j, k ) ) + WHILE( ( j >= k ) ) { j = sub( j, k ); k = shr( k, 1 ); @@ -4041,12 +4047,12 @@ static void c_fft_wi_fx( Word16 *farray_ptr_fx, Word16 size, Word16 stage, Word1 /* Butterfly computations */ /* ftmp_real_fx = L_sub(L_mult(*(farray_ptr_fx + kj), cos_table[ji*K]), */ /* L_mult(*(farray_ptr_fx + kj + 1), cos_table[(ji*K+384)%512])); */ - ftmp_real_fx = L_msu( L_mult( *( farray_ptr_fx + kj ), cos_table[i_mult( ji, K )] ), + ftmp_real_fx = L_msu( L_mult( *( farray_ptr_fx + kj ), cos_table[( ji * K )] ), *( farray_ptr_fx + add( kj, 1 ) ), cos_table[temp_sand] ); /* ftmp_imag_fx = L_add(L_mult(*(farray_ptr_fx + kj + 1), cos_table[ji*K]), */ /* L_mult(*(farray_ptr_fx + kj), cos_table[(ji*K+384)%512])); */ - ftmp_imag_fx = L_mac( L_mult( *( farray_ptr_fx + add( kj, 1 ) ), cos_table[i_mult( ji, K )] ), + ftmp_imag_fx = L_mac( L_mult( *( farray_ptr_fx + add( kj, 1 ) ), cos_table[( ji * K )] ), *( farray_ptr_fx + kj ), cos_table[temp_sand] ); tmp1 = round_fx( ftmp_real_fx ); @@ -4092,12 +4098,12 @@ static void c_fft_wi_fx( Word16 *farray_ptr_fx, Word16 size, Word16 stage, Word1 /* Butterfly computations */ /* ftmp_real_fx = L_add(L_mult(*(farray_ptr_fx + kj), cos_table[ji*K]), */ /* L_mult(*(farray_ptr_fx + kj + 1), cos_table[(ji*K+384)%512])); */ - ftmp_real_fx = L_mac( L_mult( *( farray_ptr_fx + kj ), cos_table[i_mult( ji, K )] ), + ftmp_real_fx = L_mac( L_mult( *( farray_ptr_fx + kj ), cos_table[( ji * K )] ), *( farray_ptr_fx + kj + 1 ), cos_table[temp_sand] ); /* ftmp_imag_fx = L_sub(L_mult(*(farray_ptr_fx + kj + 1), cos_table[ji*K]), */ /* L_mult(*(farray_ptr_fx + kj), cos_table[(ji*K+384)%512])); */ - ftmp_imag_fx = L_msu( L_mult( *( farray_ptr_fx + add( kj, 1 ) ), cos_table[i_mult( ji, K )] ), + ftmp_imag_fx = L_msu( L_mult( *( farray_ptr_fx + add( kj, 1 ) ), cos_table[( ji * K )] ), *( farray_ptr_fx + kj ), cos_table[temp_sand] ); tmp1 = round_fx( ftmp_real_fx ); @@ -4130,7 +4136,7 @@ static void c_fft_wi_fx( Word16 *farray_ptr_fx, Word16 size, Word16 stage, Word1 } /* end of c_fft () */ -void r_fft_4_fx( Word16 *farray_ptr_fx, Word16 size, Word16 stage, Word16 isign ) +void r_fft_4_fx( Word16 *farray_ptr_fx /*Q0*/, Word16 size, Word16 stage, Word16 isign ) { Word16 ftmp1_real_fx, ftmp1_imag_fx, ftmp2_real_fx, ftmp2_imag_fx; @@ -4175,22 +4181,22 @@ void r_fft_4_fx( Word16 *farray_ptr_fx, Word16 size, Word16 stage, Word16 isign Lftmp1_imag_fx = L_deposit_h( ftmp1_imag_fx ); temp_sand = s_and( add( i_mult( i, K ), 384 ), 511 ); /* Ltmp1_fx = L_sub(L_mult(ftmp2_real_fx, cos_table[i*K]), L_mult(ftmp2_imag_fx, cos_table[(i*K+384)%512])); */ - Ltmp1_fx = L_msu( L_mult( ftmp2_real_fx, cos_table[i_mult( i, K )] ), ftmp2_imag_fx, cos_table[temp_sand] ); + Ltmp1_fx = L_msu( L_mult( ftmp2_real_fx, cos_table[( i * K )] ), ftmp2_imag_fx, cos_table[temp_sand] ); *( farray_ptr_fx + i ) = round_fx( L_shr( L_add( Lftmp1_real_fx, Ltmp1_fx ), 1 ) ); move16(); /* Ltmp1_fx = L_add(L_mult(ftmp2_imag_fx, cos_table[i*K]), L_mult(ftmp2_real_fx, cos_table[(i*K+384)%512])); */ - Ltmp1_fx = L_mac( L_mult( ftmp2_imag_fx, cos_table[i_mult( i, K )] ), ftmp2_real_fx, cos_table[temp_sand] ); + Ltmp1_fx = L_mac( L_mult( ftmp2_imag_fx, cos_table[( i * K )] ), ftmp2_real_fx, cos_table[temp_sand] ); *( farray_ptr_fx + i + 1 ) = round_fx( L_shr( L_add( Lftmp1_imag_fx, Ltmp1_fx ), 1 ) ); move16(); /* Ltmp1_fx = L_add(L_mult(ftmp2_real_fx, cos_table[j*K]), L_mult(ftmp2_imag_fx, cos_table[(j*K+384)%512])); */ - Ltmp1_fx = L_mac( L_mult( ftmp2_real_fx, cos_table[i_mult( j, K )] ), ftmp2_imag_fx, cos_table[temp_sand] ); + Ltmp1_fx = L_mac( L_mult( ftmp2_real_fx, cos_table[( j * K )] ), ftmp2_imag_fx, cos_table[temp_sand] ); *( farray_ptr_fx + j ) = round_fx( L_shr( L_add( Lftmp1_real_fx, Ltmp1_fx ), 1 ) ); move16(); /* Ltmp1_fx = L_add(L_negate(L_mult(ftmp2_imag_fx, cos_table[j*K])), L_mult(ftmp2_real_fx, cos_table[(j*K+384)%512])); */ - Ltmp1_fx = L_msu( L_mult( ftmp2_real_fx, cos_table[temp_sand] ), ftmp2_imag_fx, cos_table[i_mult( j, K )] ); + Ltmp1_fx = L_msu( L_mult( ftmp2_real_fx, cos_table[temp_sand] ), ftmp2_imag_fx, cos_table[( j * K )] ); Ltmp2_fx = L_sub( Ltmp1_fx, Lftmp1_imag_fx ); *( farray_ptr_fx + j + 1 ) = round_fx( L_shr( Ltmp2_fx, 1 ) ); move16(); @@ -4226,22 +4232,22 @@ void r_fft_4_fx( Word16 *farray_ptr_fx, Word16 size, Word16 stage, Word16 isign Lftmp1_imag_fx = L_deposit_h( ftmp1_imag_fx ); temp_sand = s_and( ( add( i_mult( i, K ), 384 ) ), 511 ); /* Ltmp1_fx = L_add(L_mult(ftmp2_real_fx, cos_table[i*K]), L_mult(ftmp2_imag_fx, cos_table[(i*K+384)%512])); */ - Ltmp1_fx = L_mac( L_mult( ftmp2_real_fx, cos_table[i_mult( i, K )] ), ftmp2_imag_fx, cos_table[temp_sand] ); + Ltmp1_fx = L_mac( L_mult( ftmp2_real_fx, cos_table[( i * K )] ), ftmp2_imag_fx, cos_table[temp_sand] ); *( farray_ptr_fx + i ) = round_fx( L_shr( L_add( Lftmp1_real_fx, Ltmp1_fx ), 1 ) ); move16(); /* Ltmp1_fx = L_sub(L_mult(ftmp2_imag_fx, cos_table[i*K]), L_mult(ftmp2_real_fx, cos_table[(i*K+384)%512])); */ - Ltmp1_fx = L_msu( L_mult( ftmp2_imag_fx, cos_table[i_mult( i, K )] ), ftmp2_real_fx, cos_table[temp_sand] ); + Ltmp1_fx = L_msu( L_mult( ftmp2_imag_fx, cos_table[( i * K )] ), ftmp2_real_fx, cos_table[temp_sand] ); *( farray_ptr_fx + i + 1 ) = round_fx( L_shr( L_add( Lftmp1_imag_fx, Ltmp1_fx ), 1 ) ); move16(); /* Ltmp1_fx = L_sub(L_mult(ftmp2_real_fx, cos_table[j*K]), L_mult(ftmp2_imag_fx, cos_table[(j*K+384)%512])); */ - Ltmp1_fx = L_msu( L_mult( ftmp2_real_fx, cos_table[i_mult( j, K )] ), ftmp2_imag_fx, cos_table[temp_sand] ); + Ltmp1_fx = L_msu( L_mult( ftmp2_real_fx, cos_table[( j * K )] ), ftmp2_imag_fx, cos_table[temp_sand] ); *( farray_ptr_fx + j ) = round_fx( L_shr( L_add( Lftmp1_real_fx, Ltmp1_fx ), 1 ) ); move16(); /* Ltmp1_fx = L_negate(L_add(L_mult(ftmp2_imag_fx, cos_table[j*K]), L_mult(ftmp2_real_fx, cos_table[(j*K+384)%512]))); */ - Ltmp1_fx = L_negate( L_mac( L_mult( ftmp2_imag_fx, cos_table[i_mult( j, K )] ), ftmp2_real_fx, cos_table[temp_sand] ) ); + Ltmp1_fx = L_negate( L_mac( L_mult( ftmp2_imag_fx, cos_table[( j * K )] ), ftmp2_real_fx, cos_table[temp_sand] ) ); Ltmp2_fx = L_sub( Ltmp1_fx, Lftmp1_imag_fx ); *( farray_ptr_fx + j + 1 ) = round_fx( L_shr( Ltmp2_fx, 1 ) ); move16(); @@ -4327,6 +4333,7 @@ void copy_phase_fx( DTFS_STRUCTURE *X1_fx, DTFS_STRUCTURE X2_fx, DTFS_STRUCTURE ELSE { tmp = 0; + move16(); } tmp = shr( tmp, 1 ); q = sub( add( add( 15, exp1 ), 16 ), 1 ); diff --git a/lib_dec/ivas_qmetadata_dec.c b/lib_dec/ivas_qmetadata_dec.c index 2e17020cd..37315192f 100644 --- a/lib_dec/ivas_qmetadata_dec.c +++ b/lib_dec/ivas_qmetadata_dec.c @@ -8705,19 +8705,19 @@ void ivas_omasa_decode_masa_to_total_fx( { case 4: matrix_product_q30_fx( dct4_fx, nblocks, nblocks, 1, q_dct_data_fx, nblocks, 1, 0, dct_data_tmp_fx ); - Copy32( dct_data_tmp_fx, q_dct_data_fx, nblocks ); /*Q25*/ + Copy32( dct_data_tmp_fx, q_dct_data_fx, nblocks ); /*Q30*/ BREAK; case 5: matrix_product_q30_fx( dct5_fx, nbands, nbands, 1, q_dct_data_fx, nbands, 1, 0, dct_data_tmp_fx ); - Copy32( dct_data_tmp_fx, q_dct_data_fx, nbands ); /*Q25*/ + Copy32( dct_data_tmp_fx, q_dct_data_fx, nbands ); /*Q30*/ BREAK; case 8: matrix_product_q30_fx( dct8_fx, nbands, nbands, 1, q_dct_data_fx, nbands, 1, 0, dct_data_tmp_fx ); - Copy32( dct_data_tmp_fx, q_dct_data_fx, nbands ); /*Q25*/ + Copy32( dct_data_tmp_fx, q_dct_data_fx, nbands ); /*Q30*/ BREAK; case 12: matrix_product_q30_fx( dct12_fx, nbands, nbands, 1, q_dct_data_fx, nbands, 1, 0, dct_data_tmp_fx ); - Copy32( dct_data_tmp_fx, q_dct_data_fx, nbands ); /*Q25*/ + Copy32( dct_data_tmp_fx, q_dct_data_fx, nbands ); /*Q30*/ BREAK; case 20: matrix_product_fx( dct5_fx, nbands, nbands, 1, q_dct_data_fx, nbands, nblocks, 0, dct_data_tmp_fx ); diff --git a/lib_dec/jbm_pcmdsp_apa.c b/lib_dec/jbm_pcmdsp_apa.c index 9b94503da..f8cce92ca 100644 --- a/lib_dec/jbm_pcmdsp_apa.c +++ b/lib_dec/jbm_pcmdsp_apa.c @@ -42,6 +42,7 @@ #include #include #include +#include #include "options.h" #include "prot.h" #include "wmc_auto.h" @@ -184,6 +185,7 @@ ivas_error apa_init( { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for JBM\n" ) ); } + memset( ps->buf_out_fx, 0, ( sizeof( Word16 ) * ps->buf_out_capacity ) ); ps->Q_buf_out = Q15; move16(); diff --git a/lib_enc/acelp_core_enc.c b/lib_enc/acelp_core_enc.c index eef3bcbd2..36861985c 100644 --- a/lib_enc/acelp_core_enc.c +++ b/lib_enc/acelp_core_enc.c @@ -198,8 +198,6 @@ ivas_error acelp_core_enc( f2me_buf_16( &st->hLPDmem->old_exc_flt[-M - 1], &st->hLPDmem->old_exc[-M - 1], &st->hLPDmem->e_old_exc, L_EXC_MEM + M + 1 ); IF( st->hBWE_TD ) floatToFixed_arr16( st->hBWE_TD->old_bwe_exc, st->hBWE_TD->old_bwe_exc_fx, Q_exc, PIT16k_MAX * 2 ); - floatToFixed_arr16( st->lsp_old, st->lsp_old_fx, 15, M ); - floatToFixed_arr16( st->lsp_old16k, st->lsp_old16k_fx, 15, M ); floatToFixed_arr16( lsp_mid, lsp_mid_fx, 15, M ); floatToFixed_arr16( lsp_new, lsp_new_fx, 15, M ); IF( st->hLPDmem ) @@ -215,10 +213,6 @@ ivas_error acelp_core_enc( floatToFixed_arr( st->hLPDmem->mem_syn3_flt, st->hLPDmem->mem_syn3, Q_temp, 16 ); floatToFixed_arr( st->hLPDmem->mem_syn_r_flt, st->hLPDmem->mem_syn_r, Q_temp, 60 ); } - for ( int ii = 0; ii < M; ii++ ) - { - st->lsf_old_fx[ii] = (Word16) ( ( st->lsf_old[ii] ) * 2.56f ); - } Word16 inp_buff[L_FRAME16k + M + 1]; Word16 *inp_fx; inp_fx = &inp_buff[M + 1]; @@ -230,10 +224,6 @@ ivas_error acelp_core_enc( floatToFixed_arr( &inp[-M - 1], &inp_fx[-M - 1], Q_new, L_FRAME16k + M + 1 ); floatToFixed_arrL( st->Bin_E_old, st->Bin_E_old_fx, Q_new + Q_SCALE - 2, 128 ); floatToFixed_arrL( st->Bin_E, st->Bin_E_fx, Q_new + Q_SCALE - 2, 256 ); - IF( hStereoTD ) - { - floatToFixed_arr( hStereoTD->tdm_Pri_pitch_buf, hStereoTD->tdm_Pri_pitch_buf_fx, Q6, 4 ); - } #endif ivas_error error; @@ -358,13 +348,17 @@ ivas_error acelp_core_enc( test(); /* TD stereo */ + + float tdm_Pri_pitch_buf_flt[NB_SUBFR]; + set_zero( tdm_Pri_pitch_buf_flt, NB_SUBFR ); IF( EQ_16( st->element_mode, IVAS_CPE_TD ) && EQ_16( st->idchan, 1 ) ) { tdm_lp_reuse_flag = hStereoTD->tdm_lp_reuse_flag; tdm_low_rate_mode = hStereoTD->tdm_low_rate_mode; tdm_Pitch_reuse_flag = hStereoTD->tdm_Pitch_reuse_flag; - tdm_Pri_pitch_buf = hStereoTD->tdm_Pri_pitch_buf; tdm_Pri_pitch_buf_fx = hStereoTD->tdm_Pri_pitch_buf_fx; + fixedToFloat_arr( tdm_Pri_pitch_buf_fx, tdm_Pri_pitch_buf_flt, Q6, NB_SUBFR ); + tdm_Pri_pitch_buf = tdm_Pri_pitch_buf_flt; } ELSE { @@ -442,12 +436,6 @@ ivas_error acelp_core_enc( weight_a_subfr_fx( shr( st->L_frame, 6 ), A_fx, Aw_fx, st->gamma, M ); } #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - - for ( i = 0; i < M; i++ ) - { - st->lsf_old[i] = st->lsf_old_fx[i] / 2.56f; - } - fixedToFloat_arr( st->lsp_old_fx, st->lsp_old, 15, M ); IF( st->hLPDmem ) { Word16 Q_temp = Q31 - st->hLPDmem->e_mem_syn; @@ -492,7 +480,6 @@ ivas_error acelp_core_enc( f2me_buf_16( &st->hTdCngEnc->cng_exc2_buf_flt[ii * L_FFT], &st->hTdCngEnc->cng_exc2_buf[ii * L_FFT], &st->hTdCngEnc->cng_Qexc_buf[ii], L_FFT ); st->hTdCngEnc->cng_Qexc_buf[ii] = Q15 - st->hTdCngEnc->cng_Qexc_buf[ii]; } - floatToFixed_arr32( st->hTdCngEnc->ho_env_circ, st->hTdCngEnc->ho_env_circ_fx, Q6, 160 ); #endif cng_params_postupd_ivas_fx( st->hTdCngEnc->ho_circ_ptr, &st->hTdCngEnc->cng_buf_cnt, st->hTdCngEnc->cng_exc2_buf, st->hTdCngEnc->cng_Qexc_buf, st->hTdCngEnc->cng_brate_buf, st->hTdCngEnc->ho_env_circ_fx, st->element_mode, st->hFdCngEnc->hFdCngCom->CngBandwidth ); #ifdef IVAS_FLOAT_FIXED_CONVERSIONS @@ -502,14 +489,10 @@ ivas_error acelp_core_enc( floatToFixed_arr( inp, inp_fx, q_inp, st->L_frame ); floatToFixed_arr( lsp_mid, lsp_mid_fx, Q15, M ); floatToFixed_arr( lsp_new, lsp_new_fx, Q15, M ); - floatToFixed_arr( st->lsp_old, st->lsp_old_fx, Q15, M ); - floatToFixed_arr( st->hTdCngEnc->ho_lsp_circ, st->hTdCngEnc->ho_lsp_circ_fx, Q15, HO_HIST_SIZE * M ); - floatToFixed_arrL( st->hTdCngEnc->ho_ener_circ, st->hTdCngEnc->ho_ener_circ_fx, Q6, HO_HIST_SIZE ); floatToFixed_arr( st->hTdCngEnc->exc_mem2, st->hTdCngEnc->exc_mem2_fx, q_inp, 30 ); for ( i = 0; i < M; i++ ) { lsf_new_fx[i] = (Word16) ( lsf_new[i] * 2.56f ); - st->lsf_old_fx[i] = (Word16) ( st->lsf_old[i] * 2.56f ); } #endif /* encode CNG parameters */ @@ -518,15 +501,10 @@ ivas_error acelp_core_enc( fixedToFloat_arr( Aq_fx, Aq, Q12, NB_SUBFR16k * ( M + 1 ) ); fixedToFloat_arr( lsp_new_fx, lsp_new, Q15, M ); fixedToFloat_arrL32( q_env_fx, q_env, Q6, NUM_ENV_CNG ); - fixedToFloat_arr( st->lsp_old_fx, st->lsp_old, Q15, M ); - fixedToFloat_arr( st->hTdCngEnc->ho_lsp_circ_fx, st->hTdCngEnc->ho_lsp_circ, Q15, HO_HIST_SIZE * M ); - fixedToFloat_arrL( st->hTdCngEnc->ho_env_circ_fx, st->hTdCngEnc->ho_env_circ, Q6, 160 ); - fixedToFloat_arrL( st->hTdCngEnc->ho_ener_circ_fx, st->hTdCngEnc->ho_ener_circ, Q6, HO_HIST_SIZE ); fixedToFloat_arr( st->hTdCngEnc->exc_mem2_fx, st->hTdCngEnc->exc_mem2, q_inp, 30 ); for ( i = 0; i < M; i++ ) { lsf_new[i] = ( (float) lsf_new_fx[i] / 2.56f ); - st->lsf_old[i] = ( (float) st->lsf_old_fx[i] / 2.56f ); } #endif #else @@ -599,7 +577,6 @@ ivas_error acelp_core_enc( floatToFixed_arr( st->hFdCngEnc->hFdCngCom->A_cng_flt, st->hFdCngEnc->hFdCngCom->A_cng, Q12, ( M + 1 ) ); // Word16 Q_exc_cng_l = Q_factor_arr( st->hFdCngEnc->hFdCngCom->exc_cng_flt, st->L_frame ); floatToFixed_arr( st->hFdCngEnc->hFdCngCom->exc_cng_flt, st->hFdCngEnc->hFdCngCom->exc_cng, Q_new, st->L_frame ); - floatToFixed_arr( st->lsp_old, st->lsp_old_fx, Q15, M ); #endif // FdCng_exc_flt( st->hFdCngEnc->hFdCngCom, &st->hDtxEnc->CNG_mode, st->L_frame, st->lsp_old, st->hDtxEnc->first_CNG, st->hDtxEnc->lspCNG, Aq, lsp_new, lsf_new, exc, exc2, bwe_exc ); FdCng_exc( st->hFdCngEnc->hFdCngCom, &st->hDtxEnc->CNG_mode, st->L_frame, st->lsp_old_fx, st->hDtxEnc->first_CNG, st->hDtxEnc->lspCNG_fx, Aq_fx, lsp_new_fx, lsf_new_fx, exc_fx, exc2_fx, bwe_exc_fx ); @@ -753,10 +730,6 @@ ivas_error acelp_core_enc( } } - for ( i = 0; i < M; i++ ) - { - st->lsf_old_fx[i] = (Word16) ( st->lsf_old[i] * 2.56f ); - } st->mem_deemp_preQ_fx = (Word16) floatToFixed( st->mem_deemp_preQ, -1 ); IF( st->hLPDmem ) { @@ -1005,13 +978,11 @@ ivas_error acelp_core_enc( { lsf_new[i] = lsf_new_fx[i] / 2.56f; - st->lsf_old[i] = st->lsf_old_fx[i] / 2.56f; } fixedToFloat_arrL( st->Bin_E_old_fx, st->Bin_E_old, q_comm_Bin, 128 ); fixedToFloat_arrL( st->Bin_E_fx, st->Bin_E, q_comm_Bin, 256 ); st->clip_var[0] = st->clip_var_fx[0] / 2.56f; fixedToFloat_arr( &st->clip_var_fx[1], &st->clip_var[1], Q14, 5 ); - fixedToFloat_arr( st->lsp_old_fx, st->lsp_old, 15, M ); for ( i = 0; i < NB_SUBFR16k; i++ ) { // Array is getting modified in chunks of 17 inside. @@ -1254,7 +1225,6 @@ ivas_error acelp_core_enc( st->exc_pe_fx = float_to_fix16( st->exc_pe, st->Q_stat_noise ); floatToFixed_arr( lsp_new, lsp_new_fx, 15, 16 ); floatToFixed_arr( lsp_mid, lsp_mid_fx, 15, 16 ); - floatToFixed_arr( st->lsp_old, st->lsp_old_fx, 15, 16 ); #endif LepsP[0] = epsP_fx[2]; move32(); @@ -1391,7 +1361,6 @@ ivas_error acelp_core_enc( #ifdef IVAS_FLOAT_FIXED #ifdef IVAS_FLOAT_FIXED_CONVERSIONS floatToFixed_arr( pitch_buf, pitch_buf_fx, Q6, NB_SUBFR16k ); // Saturation Conversion used as last values have garbage values even in float - floatToFixed_arr16( st->old_pitch_buf, st->old_pitch_buf_fx, Q6, 2 * NB_SUBFR16k ); Es_pred_fx = float_to_fix16( Es_pred, Q8 ); floatToFixed_arr16( Aq, Aq_fx, 12, NB_SUBFR16k * ( M + 1 ) ); @@ -1418,11 +1387,6 @@ ivas_error acelp_core_enc( { st->hGSCEnc->mid_dyn_fx = float_to_fix16( st->hGSCEnc->mid_dyn, Q7 ); } - - if ( st->L_frame == L_FRAME ) - { - floatToFixed_arr( st->lsp_old, st->lsp_old_fx, Q15, M ); - } #endif // IVAS_FLOAT_FIXED_CONVERSIONS updt_enc_fx( st, old_exc_fx, pitch_buf_fx, Es_pred_fx, Aq_fx, lsf_new_fx, lsp_new_fx, old_bwe_exc_fx ); @@ -1433,19 +1397,8 @@ ivas_error acelp_core_enc( { fixedToFloat_arr( st->hBWE_TD->old_bwe_exc_fx, st->hBWE_TD->old_bwe_exc, q_old_bwe_exc, PIT16k_MAX * 2 ); } - fixedToFloat_arr( st->lsp_old_fx, st->lsp_old, Q15, M ); - for ( i = 0; i < M; i++ ) - { - st->lsf_old[i] = (float) ( st->lsf_old_fx[i] / 2.56f ); - } st->hGSCEnc->mid_dyn = fixedToFloat( st->hGSCEnc->mid_dyn_fx, Q7 ); - IF( EQ_16( st->L_frame, L_FRAME ) ) - { - fixedToFloat_arr( st->lsp_old16k_fx, st->lsp_old16k, Q15, M ); - } - fixedToFloat_arr( st->old_pitch_buf_fx, st->old_pitch_buf, Q6, shl( shr( st->L_frame, 6 ), 1 ) ); // Q6 - fixedToFloat_arr( st->old_Aq_12_8_fx, st->old_Aq_12_8, Q12, M + 1 ); // Q12 - st->old_Es_pred = fixedToFloat( st->old_Es_pred_fx, Q8 ); + fixedToFloat_arr( st->old_Aq_12_8_fx, st->old_Aq_12_8, Q12, M + 1 ); // Q12 #endif #else updt_enc( st, old_exc_flt, pitch_buf, Es_pred, Aq, lsf_new, lsp_new, old_bwe_exc ); @@ -1460,17 +1413,12 @@ ivas_error acelp_core_enc( q_exc = min( q_exc, Q_factor_arr( st->hTdCngEnc->cng_exc2_buf_flt, HO_HIST_SIZE * L_FFT ) ); floatToFixed_arr16( exc, exc_fx, q_exc, L_EXC - L_EXC_MEM ); floatToFixed_arr16( st->hTdCngEnc->cng_exc2_buf_flt, st->hTdCngEnc->cng_exc2_buf, q_exc, HO_HIST_SIZE * L_FFT ); - - floatToFixed_arr32( st->hTdCngEnc->ho_env_circ, st->hTdCngEnc->ho_env_circ_fx, Q6, HO_HIST_SIZE * NUM_ENV_CNG ); - floatToFixed_arr16( st->hTdCngEnc->ho_lsp_circ, st->hTdCngEnc->ho_lsp_circ_fx, Q15, HO_HIST_SIZE * M ); #endif // IVAS_FLOAT_FIXED_CONVERSIONS cng_params_upd_ivas_fx( lsp_new_fx, exc_fx, st->L_frame, &st->hTdCngEnc->ho_circ_ptr, st->hTdCngEnc->ho_ener_circ_fx, &st->hTdCngEnc->ho_circ_size, st->hTdCngEnc->ho_lsp_circ_fx, q_exc, ENC, st->hTdCngEnc->ho_env_circ_fx, &st->hTdCngEnc->cng_buf_cnt, st->hTdCngEnc->cng_exc2_buf, st->hTdCngEnc->cng_Qexc_buf, st->hTdCngEnc->cng_brate_buf, st->hDtxEnc->last_active_brate, st->element_mode, st->hFdCngEnc->hFdCngCom->CngBandwidth ); #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - fixedToFloat_arr( st->hTdCngEnc->ho_lsp_circ_fx, st->hTdCngEnc->ho_lsp_circ, Q15, HO_HIST_SIZE * M ); - fixedToFloat_arrL( st->hTdCngEnc->ho_env_circ_fx, st->hTdCngEnc->ho_env_circ, Q6, HO_HIST_SIZE * NUM_ENV_CNG ); fixedToFloat_arr( st->hTdCngEnc->cng_exc2_buf, st->hTdCngEnc->cng_exc2_buf_flt, Q6, HO_HIST_SIZE * L_FFT ); #endif #else @@ -1495,9 +1443,6 @@ ivas_error acelp_core_enc( mvr2r( st->lsp_old16k, &( st->hTdCngEnc->ho_lsp_circ2[( st->hTdCngEnc->ho_circ_ptr ) * M] ), M ); } #else -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - floatToFixed_arr( st->lsp_old16k, st->lsp_old16k_fx, Q15, M ); -#endif IF( EQ_16( st->L_frame, L_FRAME ) ) { /* store LSPs@16k, potentially to be used in CNG@16k */ diff --git a/lib_enc/cod_tcx_fx.c b/lib_enc/cod_tcx_fx.c index 86be7be4e..e2b193791 100644 --- a/lib_enc/cod_tcx_fx.c +++ b/lib_enc/cod_tcx_fx.c @@ -8,11 +8,11 @@ #include #include "rom_com.h" #include "stat_com.h" -//#include "prot_fx.h" +// #include "prot_fx.h" #include "prot_fx.h" #include "basop_util.h" #include "stl.h" -//#include "basop_mpy.h" +// #include "basop_mpy.h" #include "prot_fx_enc.h" #ifdef IVAS_FLOAT_FIXED_CONVERSIONS #include @@ -1798,6 +1798,19 @@ void EstimateStereoTCXNoiseLevel_fx( noiseTransWidth = GetTransWidth_ivas_fx( st->tcxonly, (Word16) EQ_16( L_frame[ch][n], shr( st->L_frame, 1 ) ), smooth_gain, ( st->hTcxCfg->ctx_hm && NE_16( st->last_core, ACELP_CORE ) && hm_active[ch][n] ) ); Copy32( q_spectrum[ch][n], combined_q_spectrum, L_frame[ch][n] ); + + /* Scaling down 1-bit to resolve crashes during accumulation in tcx_noise_factor_ivas_fx() */ + Word32 L_tmp, L_tmp1; + maximum_abs_32_fx( hTcxEnc->spectrum_fx[n], L_frame[ch][n], &L_tmp ); + maximum_abs_32_fx( combined_q_spectrum, L_frame[ch][n], &L_tmp1 ); + test(); + IF( L_tmp != 0 || L_tmp1 != 0 ) + { + scale_sig32( hTcxEnc->spectrum_fx[n], L_frame[ch][n], -Q1 ); + scale_sig32( combined_q_spectrum, L_frame[ch][n], -Q1 ); + hTcxEnc->spectrum_e[n] = add( hTcxEnc->spectrum_e[n], Q1 ); + move16(); + } tcx_noise_factor_ivas_fx( hTcxEnc->spectrum_fx[n], hTcxEnc->spectrum_e[n], combined_q_spectrum, iStart, maxNfCalcBw, noiseTransWidth, L_frame[ch][n], gain_tcx[ch][n], gain_tcx_e, hTcxEnc->noiseTiltFactor, &fac_ns[ch][n], fac_ns_q, st->element_mode ); /* hysteresis for very tonal passages (more stationary noise filling level) */ diff --git a/lib_enc/core_enc_init.c b/lib_enc/core_enc_init.c index add6c9675..b1fd1d7f2 100644 --- a/lib_enc/core_enc_init.c +++ b/lib_enc/core_enc_init.c @@ -480,14 +480,6 @@ void init_coder_ace_plus( { floatToFixed_arr16( st->lspold_enc, &st->lspold_enc_fx[0], Q15, M ); } - if ( st->lsp_old1 != NULL ) - { - floatToFixed_arr16( st->lsp_old1, &st->lsp_old1_fx[0], Q15, M ); - } - if ( st->lsp_old != NULL ) - { - floatToFixed_arr16( st->lsp_old, &st->lsp_old_fx[0], Q15, M ); - } init_acelp_ivas_fx( st, L_frame_old, 0 ); #endif @@ -1277,14 +1269,36 @@ static void init_acelp( /* unquantized LPC*/ if ( !( ( total_brate >= ACELP_16k40 && total_brate <= ACELP_24k40 ) && total_brate == last_total_brate && st->last_bwidth == st->bwidth ) ) { +#ifndef IVAS_FLOAT_FIXED mvr2r( st->lsp_old1, st->lspold_enc, M ); /*lsp old @12.8kHz*/ +#else + Copy( st->lsp_old1_fx, st->lspold_enc_fx, M ); /*lsp old @12.8kHz*/ +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + fixedToFloat_arr( st->lspold_enc_fx, st->lspold_enc, Q15, M ); +#endif +#endif if ( st->L_frame == L_FRAME16k ) { lsp_convert_poly( st->lspold_enc, st->L_frame, 0 ); } } +#ifndef IVAS_FLOAT_FIXED mvr2r( st->lspold_enc, st->lsp_old, M ); /*used unquantized values for mid-LSF Q*/ lsp2lsf( st->lsp_old, st->lsf_old, M, st->sr_core ); +#else +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + floatToFixed_arr( st->lspold_enc, st->lspold_enc_fx, Q15, M ); +#endif + Copy( st->lspold_enc_fx, st->lsp_old_fx, M ); /*used unquantized values for mid-LSF Q*/ + IF( st->tcxonly == 0 ) + { + lsp2lsf_fx( st->lsp_old_fx, st->lsf_old_fx, M, st->sr_core ); + } + ELSE + { + E_LPC_lsp_lsf_conversion( st->lsp_old_fx, st->lsf_old_fx, M ); + } +#endif st->last_core = TCX_20_CORE; @@ -1299,11 +1313,28 @@ static void init_acelp( if ( st->L_frame != L_frame_old && st->L_frame <= L_FRAME16k && L_frame_old <= L_FRAME16k ) /* Rate switching between 12.8 and 16 kHz*/ { float tmp, A[M + 1], Ap[M + 1], tmp_buf[M + 1]; +#ifdef IVAS_FLOAT_FIXED + Word16 A_fx[M + 1]; +#endif /* convert quantized LSP vector */ +#ifndef IVAS_FLOAT_FIXED st->rate_switching_reset = lsp_convert_poly( st->lsp_old, st->L_frame, 0 ); lsp2lsf( st->lsp_old, st->lsf_old, M, st->sr_core ); +#else + st->rate_switching_reset = lsp_convert_poly_fx( st->lsp_old_fx, st->L_frame, 0 ); + move16(); + IF( st->tcxonly == 0 ) + { + lsp2lsf_fx( st->lsp_old_fx, st->lsf_old_fx, M, st->sr_core ); + } + ELSE + { + E_LPC_lsp_lsf_conversion( st->lsp_old_fx, st->lsf_old_fx, M ); + } +#endif +#ifndef IVAS_FLOAT_FIXED if ( st->L_frame == L_FRAME16k ) { mvr2r( st->lsp_old, st->lspold_enc, M ); @@ -1312,12 +1343,32 @@ static void init_acelp( { mvr2r( st->lsp_old1, st->lspold_enc, M ); } +#else + IF( st->L_frame == L_FRAME16k ) + { + Copy( st->lsp_old_fx, st->lspold_enc_fx, M ); + } + ELSE + { + Copy( st->lsp_old1_fx, st->lspold_enc_fx, M ); + } +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + fixedToFloat_arr( st->lspold_enc_fx, st->lspold_enc, Q15, M ); +#endif +#endif /* Update wsyn */ if ( hLPDmem != NULL ) { synth_mem_updt2_flt( st->L_frame, st->last_L_frame, hLPDmem->old_exc_flt, hLPDmem->mem_syn_r_flt, hLPDmem->mem_syn2_flt, hLPDmem->mem_syn_flt, ENC ); +#ifndef IVAS_FLOAT_FIXED lsp2a_stab( st->lsp_old, A, M ); +#else + E_LPC_f_lsp_a_conversion( st->lsp_old_fx, A_fx, M ); +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + fixedToFloat_arr( A_fx, A, Q14 - norm_s( A_fx[0] ), M + 1 ); +#endif +#endif weight_a( A, Ap, GAMMA1_FLT, M ); tmp = 0.f; tmp_buf[0] = 0.f; @@ -1352,13 +1403,35 @@ static void init_acelp( } /* unquantized LPC*/ +#ifndef IVAS_FLOAT_FIXED mvr2r( st->lsp_old1, st->lspold_enc, M ); /*lsp old @12.8kHz*/ +#else + Copy( st->lsp_old1_fx, st->lspold_enc_fx, M ); /*lsp old @12.8kHz*/ +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + fixedToFloat_arr( st->lspold_enc_fx, st->lspold_enc, Q15, M ); +#endif +#endif if ( st->L_frame == L_FRAME16k ) { lsp_convert_poly( st->lspold_enc, st->L_frame, 0 ); } +#ifndef IVAS_FLOAT_FIXED mvr2r( st->lspold_enc, st->lsp_old, M ); /*used unquantized values for mid-LSF Q*/ lsp2lsf( st->lsp_old, st->lsf_old, M, st->sr_core ); +#else +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + floatToFixed_arr( st->lspold_enc, st->lspold_enc_fx, Q15, M ); +#endif + Copy( st->lspold_enc_fx, st->lsp_old_fx, M ); /*used unquantized values for mid-LSF Q*/ + IF( st->tcxonly == 0 ) + { + lsp2lsf_fx( st->lsp_old_fx, st->lsf_old_fx, M, st->sr_core ); + } + ELSE + { + E_LPC_lsp_lsf_conversion( st->lsp_old_fx, st->lsf_old_fx, M ); + } +#endif } /* necessary in BASOP only, due to different representations of st->lsf_old */ /* else if ( !st->tcxonly && (st->L_frame == L_FRAME16k) && (st->last_total_brate > ACELP_32k) ) */ @@ -1394,6 +1467,7 @@ static void init_acelp( } /*BPF parameters for adjusting gain in function of background noise*/ +#ifndef IVAS_FLOAT_FIXED if ( st->codec_mode == MODE2 ) { st->pst_lp_ener = 0.0f; @@ -1402,6 +1476,20 @@ static void init_acelp( st->pst_mem_deemp_err = 0.0f; } } +#else + IF( EQ_16( st->codec_mode, MODE2 ) ) + { + st->mem_bpf_fx.lp_error_ener = L_deposit_l( 0 ); + st->pst_lp_ener_fx = 0; + move16(); + if ( EQ_16( st->last_codec_mode, MODE1 ) ) + { + st->mem_bpf_fx.lp_error = L_deposit_l( 0 ); + st->pst_mem_deemp_err_fx = 0; + move16(); + } + } +#endif return; @@ -1675,16 +1763,14 @@ static void init_acelp_ivas_fx( Encoder_State *st, Word16 L_frame_old, Word16 sh /*BPF parameters for adjusting gain in function of background noise*/ IF( EQ_16( st->codec_mode, MODE2 ) ) { - /*EVS specific*/ - // st->mem_bpf_fx.lp_error_ener = L_deposit_l( 0 ); - /*------------*/ + st->mem_bpf_fx.lp_error_ener = L_deposit_l( 0 ); + move32(); st->pst_lp_ener_fx = 0; move16(); if ( EQ_16( st->last_codec_mode, MODE1 ) ) { - /*EVS specific*/ - // st->mem_bpf_fx.lp_error = L_deposit_l( 0 ); - /*------------*/ + st->mem_bpf_fx.lp_error = L_deposit_l( 0 ); + move32(); st->pst_mem_deemp_err_fx = 0; move16(); } diff --git a/lib_enc/core_enc_switch.c b/lib_enc/core_enc_switch.c index 6397c2d4c..d39efad14 100644 --- a/lib_enc/core_enc_switch.c +++ b/lib_enc/core_enc_switch.c @@ -238,14 +238,6 @@ void core_coder_mode_switch_ivas_fx( { floatToFixed_arr16( st->lspold_enc, &st->lspold_enc_fx[0], Q15, M ); } - if ( st->lsp_old1 != NULL ) - { - floatToFixed_arr16( st->lsp_old1, &st->lsp_old1_fx[0], Q15, M ); - } - if ( st->lsp_old != NULL ) - { - floatToFixed_arr16( st->lsp_old, &st->lsp_old_fx[0], Q15, M ); - } /* Adaptive BPF */ set_zero( st->mem_bpf, 2 * L_FILT16k ); @@ -254,6 +246,7 @@ void core_coder_mode_switch_ivas_fx( init_coder_ace_plus_ivas_fx( st, last_total_brate, MCT_flag ); #ifdef IVAS_FLOAT_FIXED_CONVERSIONS st->preemph_fac_flt = fix16_to_float( st->preemph_fac, Q15 ); + fixedToFloat_arr( st->lspold_enc_fx, st->lspold_enc, Q15, M ); IF( st->hLPDmem != NULL ) { me2f_buf_16( st->hLPDmem->old_exc, st->hLPDmem->e_old_exc, st->hLPDmem->old_exc_flt, L_EXC_MEM ); diff --git a/lib_enc/core_switching_enc.c b/lib_enc/core_switching_enc.c index 029bdb8bb..147a0d015 100644 --- a/lib_enc/core_switching_enc.c +++ b/lib_enc/core_switching_enc.c @@ -131,8 +131,13 @@ void core_switching_pre_enc( } if ( st->L_frame == L_FRAME16k && st->last_L_frame == L_FRAME ) { +#ifndef IVAS_FLOAT_FIXED mvr2r( st->lsp_old, st->lsp_old16k, M ); st->rate_switching_reset_16kHz = lsp_convert_poly( st->lsp_old16k, L_FRAME16k, 0 ); +#else + Copy( st->lsp_old_fx, st->lsp_old16k_fx, M ); + st->rate_switching_reset_16kHz = lsp_convert_poly_fx( st->lsp_old16k_fx, L_FRAME16k, 0 ); +#endif } st->use_acelp_preq = 0; @@ -192,7 +197,7 @@ void core_switching_pre_enc( if ( ( ( st->core == ACELP_CORE || st->core == AMR_WB_CORE ) && st->last_core == HQ_CORE ) || ( ( st->element_mode == IVAS_CPE_DFT || st->element_mode == IVAS_CPE_TD || ( st->element_mode == IVAS_CPE_MDCT && last_element_mode == IVAS_CPE_DFT ) ) && active_cnt == 1 ) ) { /* Reset the ACELP core in case of HQ->ACELP core switching */ - +#ifndef IVAS_FLOAT_FIXED if ( st->L_frame == L_FRAME16k ) { mvr2r( TRWB2_Ave, st->lsf_old, M ); /* init of LSP */ @@ -203,6 +208,18 @@ void core_switching_pre_enc( mvr2r( TRWB_Ave, st->lsf_old, M ); /* init of LSP */ lsf2lsp( st->lsf_old, st->lsp_old, M, INT_FS_12k8 ); } +#else + IF( st->L_frame == L_FRAME16k ) + { + Copy( TRWB2_Ave_fx, st->lsf_old_fx, M ); /* init of LSP */ + lsf2lsp_fx( st->lsf_old_fx, st->lsp_old_fx, M, INT_FS_16k ); + } + ELSE + { + Copy( TRWB_Ave_fx, st->lsf_old_fx, M ); /* init of LSP */ + lsf2lsp_fx( st->lsf_old_fx, st->lsp_old_fx, M, INT_FS_12k8 ); + } +#endif /* Reset ACELP parameters */ if ( hLPDmem != NULL ) @@ -233,8 +250,13 @@ void core_switching_pre_enc( st->last_coder_type = GENERIC; +#ifndef IVAS_FLOAT_FIXED mvr2r( st->old_pitch_buf + st->L_frame / L_SUBFR, st->old_pitch_buf, st->L_frame / L_SUBFR ); set_f( st->old_pitch_buf + st->L_frame / L_SUBFR, L_SUBFR, st->L_frame / L_SUBFR ); +#else + Copy( st->old_pitch_buf_fx + st->L_frame / L_SUBFR, st->old_pitch_buf_fx, st->L_frame / L_SUBFR ); + set16_fx( st->old_pitch_buf_fx + st->L_frame / L_SUBFR, L_SUBFR_Q6, st->L_frame / L_SUBFR ); +#endif /* Reset old ACELP buffers */ if ( st->element_mode == EVS_MONO && hLPDmem != NULL ) @@ -280,8 +302,13 @@ void core_switching_pre_enc( st->last_coder_type = GENERIC; +#ifndef IVAS_FLOAT_FIXED mvr2r( st->old_pitch_buf + st->L_frame / L_SUBFR, st->old_pitch_buf, st->L_frame / L_SUBFR ); set_f( st->old_pitch_buf + st->L_frame / L_SUBFR, L_SUBFR, st->L_frame / L_SUBFR ); +#else + Copy( st->old_pitch_buf_fx + st->L_frame / L_SUBFR, st->old_pitch_buf_fx, st->L_frame / L_SUBFR ); + set16_fx( st->old_pitch_buf_fx + st->L_frame / L_SUBFR, L_SUBFR_Q6, st->L_frame / L_SUBFR ); +#endif /* Reset old TD BWE buffers */ if ( st->hBWE_TD != NULL ) @@ -840,7 +867,6 @@ void core_switching_post_enc( floatToFixed_arr( st->voicing, st->voicing_fx, 15, 3 ); st->hLPDmem->tilt_code = float_to_fix16( st->hLPDmem->tilt_code_flt, 15 ); floatToFixed_arr( st->old_Aq_12_8, st->old_Aq_12_8_fx, 12, M + 1 ); - st->old_Es_pred_fx = float_to_fix16( st->old_Es_pred, 8 ); st->hLPDmem->mem_w0 = float_to_fix16( st->hLPDmem->mem_w0_flt, Q_new - 1 ); floatToFixed_arr( st->hLPDmem->mem_syn_flt, st->hLPDmem->mem_syn, Q_new - 1, M ); diff --git a/lib_enc/dtx.c b/lib_enc/dtx.c index 896d58b4b..ac6b98299 100644 --- a/lib_enc/dtx.c +++ b/lib_enc/dtx.c @@ -823,9 +823,15 @@ void td_cng_enc_init( hTdCngEnc->num_ho = 0; hTdCngEnc->ho_circ_ptr = -1; +#ifndef IVAS_FLOAT_FIXED set_f( hTdCngEnc->ho_lsp_circ, 0, HO_HIST_SIZE * M ); set_f( hTdCngEnc->ho_ener_circ, 0, HO_HIST_SIZE ); set_f( hTdCngEnc->ho_env_circ, 0, HO_HIST_SIZE * NUM_ENV_CNG ); +#else + set16_fx( hTdCngEnc->ho_lsp_circ_fx, 0, HO_HIST_SIZE * M ); + set32_fx( hTdCngEnc->ho_ener_circ_fx, 0, HO_HIST_SIZE ); + set32_fx( hTdCngEnc->ho_env_circ_fx, 0, HO_HIST_SIZE * NUM_ENV_CNG ); +#endif hTdCngEnc->ho_circ_size = 0; hTdCngEnc->burst_ho_cnt = 0; hTdCngEnc->cng_buf_cnt = 0; diff --git a/lib_enc/fd_cng_enc.c b/lib_enc/fd_cng_enc.c index 00b2aef90..d78459371 100644 --- a/lib_enc/fd_cng_enc.c +++ b/lib_enc/fd_cng_enc.c @@ -261,14 +261,34 @@ void configureFdCngEnc( switch ( hsCom->fftlen ) { case 512: +#ifndef IVAS_FLOAT_FIXED hsCom->fftSineTab_flt = NULL; hsCom->olapWinAna_flt = olapWinAna512; hsCom->olapWinSyn_flt = olapWinSyn256; +#else + hsCom->fftSineTab_fx = NULL; + hsCom->olapWinAna_fx = olapWinAna512_fx; + hsCom->olapWinSyn_fx = olapWinSyn256_fx; + hsCom->fftlenShift = 8; + move16(); + hsCom->fftlenFac = 32767 /*1.0 Q15*/; + move16(); +#endif break; case 640: +#ifndef IVAS_FLOAT_FIXED hsCom->fftSineTab_flt = fftSineTab640; hsCom->olapWinAna_flt = olapWinAna640; hsCom->olapWinSyn_flt = olapWinSyn320; +#else + hsCom->fftSineTab_fx = fftSineTab640_fx; + hsCom->olapWinAna_fx = olapWinAna640_fx; + hsCom->olapWinSyn_fx = olapWinSyn320_fx; + hsCom->fftlenShift = 9; + move16(); + hsCom->fftlenFac = 20480 /*0.625 Q15*/; + move16(); +#endif break; default: assert( !"Unsupported FFT length for FD-based CNG" ); diff --git a/lib_enc/fd_cng_enc_fx.c b/lib_enc/fd_cng_enc_fx.c index 8ef56f72f..e439e5f22 100644 --- a/lib_enc/fd_cng_enc_fx.c +++ b/lib_enc/fd_cng_enc_fx.c @@ -372,11 +372,6 @@ void configureFdCngEnc_ivas_fx( SWITCH( hsCom->fftlen ) { case 512: -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - hsCom->fftSineTab_flt = NULL; - hsCom->olapWinAna_flt = olapWinAna512; - hsCom->olapWinSyn_flt = olapWinSyn256; -#endif hsCom->fftSineTab_fx = NULL; hsCom->olapWinAna_fx = olapWinAna512_fx; hsCom->olapWinSyn_fx = olapWinSyn256_fx; @@ -386,11 +381,6 @@ void configureFdCngEnc_ivas_fx( move16(); BREAK; case 640: -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - hsCom->fftSineTab_flt = fftSineTab640; - hsCom->olapWinAna_flt = olapWinAna640; - hsCom->olapWinSyn_flt = olapWinSyn320; -#endif hsCom->fftSineTab_fx = fftSineTab640_fx; hsCom->olapWinAna_fx = olapWinAna640_fx; hsCom->olapWinSyn_fx = olapWinSyn320_fx; diff --git a/lib_enc/init_enc.c b/lib_enc/init_enc.c index 98f4a3df5..d8bccaa05 100644 --- a/lib_enc/init_enc.c +++ b/lib_enc/init_enc.c @@ -228,6 +228,7 @@ ivas_error init_encoder( st->max_band = 19; } +#ifndef IVAS_FLOAT_FIXED if ( st->Opt_AMR_WB ) { mvr2r( mean_isf_amr_wb, st->lsf_old, M ); @@ -238,11 +239,33 @@ ivas_error init_encoder( mvr2r( GEWB_Ave, st->lsf_old, M ); lsf2lsp( st->lsf_old, st->lsp_old1, M, INT_FS_12k8 ); } +#else + IF( st->Opt_AMR_WB ) + { + Copy( mean_isf_amr_wb_fx, st->lsf_old_fx, M ); + E_LPC_isf_isp_conversion( st->lsf_old_fx, st->lsp_old1_fx, M ); + } + ELSE + { + Copy( GEWB_Ave_fx, st->lsf_old_fx, M ); + lsf2lsp_fx( st->lsf_old_fx, st->lsp_old1_fx, M, INT_FS_12k8 ); + } +#endif +#ifndef IVAS_FLOAT_FIXED mvr2r( st->lsf_old, st->lsf_old1, M ); mvr2r( st->lsp_old1, st->lsp_old, M ); mvr2r( st->lsp_old, st->lsp_old16k, M ); mvr2r( st->lsp_old, st->lspold_enc, M ); +#else + Copy( st->lsf_old_fx, st->lsf_old1_fx, M ); + Copy( st->lsp_old1_fx, st->lsp_old_fx, M ); + Copy( st->lsp_old_fx, st->lsp_old16k_fx, M ); + Copy( st->lsp_old_fx, st->lspold_enc_fx, M ); +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + fixedToFloat_arr( st->lspold_enc_fx, st->lspold_enc, Q15, M ); +#endif +#endif #ifndef IVAS_FLOAT_FIXED st->stab_fac = 0.0f; @@ -252,8 +275,13 @@ ivas_error init_encoder( #endif /* Bass post-filter memories - encoder side of MODE2 */ st->bpf_off = 0; +#ifndef IVAS_FLOAT_FIXED st->pst_mem_deemp_err = 0.0f; st->pst_lp_ener = 0.0f; +#else + st->pst_mem_deemp_err_fx = 0; + st->pst_lp_ener_fx = 0; +#endif /* TC coder type */ st->tc_cnt = 0; @@ -295,9 +323,6 @@ ivas_error init_encoder( #ifndef IVAS_FLOAT_FIXED mvr2r( st->lsp_old, st->lspold_s, M ); #else -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - floatToFixed_arr( st->lsp_old, st->lsp_old_fx, Q15, M ); -#endif Copy( st->lsp_old_fx, st->lspold_s_fx, M ); #endif st->noimix_seed = RANDOM_INITSEED; @@ -324,27 +349,42 @@ ivas_error init_encoder( #endif st->Last_pulse_pos = 0; +#ifndef IVAS_FLOAT_FIXED for ( i = 0; i < 2 * NB_SUBFR16k; i++ ) { st->old_pitch_buf[i] = L_SUBFR; } +#else + for ( i = 0; i < 2 * NB_SUBFR16k; i++ ) + { + st->old_pitch_buf_fx[i] = L_SUBFR_Q6; + } +#endif /* mode1 core switching */ +#ifndef IVAS_FLOAT_FIXED st->old_Es_pred = 0; +#else + st->old_Es_pred_fx = 0; +#endif set_f( st->old_Aq_12_8 + 1, 0, M ); st->old_Aq_12_8[0] = 1; /* stable short pitch detection */ +#ifndef IVAS_FLOAT_FIXED st->voicing0_sm = 0; st->voicing_sm = 0; st->LF_EnergyRatio_sm = 1; - st->predecision_flag = 0; - st->diff_sm = 0; - st->energy_sm = 0; -#ifdef IVAS_FLOAT_FIXED +#else st->voicing0_sm_fx = 0; st->voicing_sm_fx = 0; st->LF_EnergyRatio_sm_fx = ONE_IN_Q7; +#endif + st->predecision_flag = 0; +#ifndef IVAS_FLOAT_FIXED + st->diff_sm = 0; + st->energy_sm = 0; +#else st->diff_sm_fx = 0; st->energy_sm_fx = 0; #endif @@ -600,9 +640,6 @@ ivas_error init_encoder( #ifndef IVAS_FLOAT_FIXED dtx_enc_init( st, var_SID_rate_flag, interval_SID ); #else -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - floatToFixed_arr( st->lsp_old1, st->lsp_old1_fx, Q15, M ); -#endif dtx_enc_init_fx( st, var_SID_rate_flag, interval_SID ); #endif } @@ -1302,31 +1339,12 @@ ivas_error init_encoder_ivas_fx( st->mem_wsp = 0.0f; set_f( st->mem_decim2, 0, 3 ); set_f( st->Bin_E, 0, L_FFT ); - if ( st->Opt_AMR_WB ) - { - mvr2r( mean_isf_amr_wb, st->lsf_old, M ); - isf2isp( st->lsf_old, st->lsp_old1, M, INT_FS_12k8 ); - } - else - { - mvr2r( GEWB_Ave, st->lsf_old, M ); - lsf2lsp( st->lsf_old, st->lsp_old1, M, INT_FS_12k8 ); - } - mvr2r( st->lsf_old, st->lsf_old1, M ); - mvr2r( st->lsp_old1, st->lsp_old, M ); - mvr2r( st->lsp_old, st->lsp_old16k, M ); - mvr2r( st->lsp_old, st->lspold_enc, M ); st->mem_preemph_DFT = 0.0f; set_f( st->inp_12k8_mem_stereo_sw, 0, STEREO_DFT_OVL_12k8 - L_MEM_RECALC_12K8 - L_FILT ); st->mem_preemph16k_DFT = 0.0f; set_f( st->inp_16k_mem_stereo_sw, 0, STEREO_DFT_OVL_16k - L_MEM_RECALC_16K - L_FILT16k ); set_f( st->old_Aq_12_8 + 1, 0, M ); st->old_Aq_12_8[0] = 4096; - st->voicing0_sm = 0; - st->voicing_sm = 0; - st->LF_EnergyRatio_sm = 1; - st->diff_sm = 0; - st->energy_sm = 0; set_f( st->voicing, 0.0f, 3 ); st->lp_speech = 45.0f; /* Initialize the long-term active speech level in dB */ st->active_cnt = 0; @@ -1337,14 +1355,12 @@ ivas_error init_encoder_ivas_fx( st->EnergyLT = 0.0f; st->Energy_Old = 0; #endif -#ifndef IVAS_FLOAT_FIXED - st->prev_fmerit_flt = 0; - st->fmerit_dt_flt = 0; #endif - st->pst_mem_deemp_err = 0.0f; - st->pst_lp_ener = 0.0f; -#endif + st->pst_mem_deemp_err_fx = 0; + move16(); + st->pst_lp_ener_fx = 0; + move16(); /* AVQ pre-quantizer memory */ st->mem_preemp_preQ_fx = 0; @@ -1480,15 +1496,12 @@ ivas_error init_encoder_ivas_fx( FOR( i = 0; i < shl( NB_SUBFR16k, 1 ); i++ ) { -#if 1 // TODO: To be removed later - st->old_pitch_buf[i] = L_SUBFR; -#endif st->old_pitch_buf_fx[i] = L_SUBFR_Q6; move16(); } /* mode1 core switching */ - st->old_Es_pred = 0; + st->old_Es_pred_fx = 0; move16(); set16_fx( st->old_Aq_12_8_fx + 1, 0, M ); st->old_Aq_12_8_fx[0] = ONE_IN_Q12; @@ -1766,9 +1779,6 @@ ivas_error init_encoder_ivas_fx( { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DTX variables\n" ) ); } -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - floatToFixed_arr( st->lsp_old1, st->lsp_old1_fx, Q15, M ); -#endif dtx_enc_init_fx( st, var_SID_rate_flag, interval_SID ); } ELSE @@ -2279,19 +2289,6 @@ ivas_error init_encoder_ivas_fx( f2me_buf_16( st->buf_wspeech_enc_flt + st->L_frame + L_SUBFR - L_WSP_MEM, st->buf_wspeech_enc + st->L_frame + L_SUBFR - L_WSP_MEM, &st->exp_old_inp_16k, L_WSP_MEM ); /* Initialize ACELP */ - if ( st->lspold_enc != NULL ) - { - floatToFixed_arr16( st->lspold_enc, &st->lspold_enc_fx[0], Q15, M ); - } - if ( st->lsp_old1 != NULL ) - { - floatToFixed_arr16( st->lsp_old1, &st->lsp_old1_fx[0], Q15, M ); - } - if ( st->lsp_old != NULL ) - { - floatToFixed_arr16( st->lsp_old, &st->lsp_old_fx[0], Q15, M ); - } - /* Adaptive BPF */ set_zero( st->mem_bpf, 2 * L_FILT16k ); set_zero( st->mem_error_bpf, 2 * L_FILT16k ); @@ -2299,6 +2296,7 @@ ivas_error init_encoder_ivas_fx( init_coder_ace_plus_ivas_fx( st, st->last_total_brate, 0 ); #ifdef IVAS_FLOAT_FIXED_CONVERSIONS st->preemph_fac_flt = fix16_to_float( st->preemph_fac, Q15 ); + fixedToFloat_arr( st->lspold_enc_fx, st->lspold_enc, Q15, M ); IF( st->hLPDmem != NULL ) { me2f_buf_16( st->hLPDmem->old_exc, st->hLPDmem->e_old_exc, st->hLPDmem->old_exc_flt, L_EXC_MEM ); diff --git a/lib_enc/ivas_core_enc.c b/lib_enc/ivas_core_enc.c index d1a548d1d..a550f76de 100644 --- a/lib_enc/ivas_core_enc.c +++ b/lib_enc/ivas_core_enc.c @@ -229,8 +229,6 @@ ivas_error ivas_core_enc( st->preemph_fac = (Word16) floatToFixed( st->preemph_fac_flt, Q15 ); - floatToFixed_arr16( st->lsp_old, st->lsp_old_fx, Q15, M ); - floatToFixed_arr16( st->lsp_old1, st->lsp_old1_fx, Q15, M ); floatToFixed_arr16( st->lspold_enc, st->lspold_enc_fx, Q15, M ); floatToFixed_arr16( st->voicing, st->voicing_fx, Q15, 3 ); @@ -310,8 +308,6 @@ ivas_error ivas_core_enc( #ifdef IVAS_FLOAT_FIXED_CONVERSIONS st->preemph_fac_flt = fixedToFloat_16( st->preemph_fac, Q15 ); - fixedToFloat_arr( st->lsp_old_fx, st->lsp_old, Q15, M ); - fixedToFloat_arr( st->lsp_old1_fx, st->lsp_old1, Q15, M ); fixedToFloat_arr( st->lspold_enc_fx, st->lspold_enc, Q15, M ); fixedToFloat_arr( st->voicing_fx, st->voicing, Q15, 3 ); @@ -388,7 +384,6 @@ ivas_error ivas_core_enc( #ifdef IVAS_FLOAT_FIXED_CONVERSIONS Word16 last_core = st->last_core; Word16 bwidth_sw_cnt = st->bwidth_sw_cnt; - floatToFixed_arr16( st->lsp_old, st->lsp_old_fx, 15, M ); Word16 q_old_inp_16k_fx; Word16 q_old_inp_12k8_fx; @@ -463,15 +458,6 @@ ivas_error ivas_core_enc( st->hTcxEnc->Q_old_out = Q_factor_arr( st->hTcxEnc->old_out, L_FRAME32k ) - 1; floatToFixed_arr( st->hTcxEnc->old_out, st->hTcxEnc->old_out_fx, st->hTcxEnc->Q_old_out, L_FRAME32k ); - - IF( st->hTdCngEnc != NULL ) - { - floatToFixed_arrL( st->hTdCngEnc->ho_ener_circ, st->hTdCngEnc->ho_ener_circ_fx, Q6, HO_HIST_SIZE ); - floatToFixed_arr( st->hTdCngEnc->ho_lsp_circ, st->hTdCngEnc->ho_lsp_circ_fx, Q15, HO_HIST_SIZE * M ); - floatToFixed_arrL( st->hTdCngEnc->ho_env_circ, st->hTdCngEnc->ho_env_circ_fx, Q6, HO_HIST_SIZE * NUM_ENV_CNG ); - // floatToFixed_arr( st->hTdCngEnc->cng_exc2_buf_flt, st->hTdCngEnc->cng_exc2_buf, Q_exc, HO_HIST_SIZE * L_FFT ); - } - #endif // IVAS_FLOAT_FIXED_CONVERSIONS @@ -483,17 +469,8 @@ ivas_error ivas_core_enc( fixedToFloat_arr( st->hTcxEnc->old_out_fx, st->hTcxEnc->old_out, st->hTcxEnc->Q_old_out, L_FRAME32k ); - IF( st->hTdCngEnc != NULL ) - { - fixedToFloat_arrL( st->hTdCngEnc->ho_ener_circ_fx, st->hTdCngEnc->ho_ener_circ, Q6, HO_HIST_SIZE ); - fixedToFloat_arr( st->hTdCngEnc->ho_lsp_circ_fx, st->hTdCngEnc->ho_lsp_circ, Q15, HO_HIST_SIZE * M ); - fixedToFloat_arrL( st->hTdCngEnc->ho_env_circ_fx, st->hTdCngEnc->ho_env_circ, Q6, HO_HIST_SIZE * NUM_ENV_CNG ); - // fixedToFloat_arr( st->hTdCngEnc->cng_exc2_buf, st->hTdCngEnc->cng_exc2_buf_flt, Q_exc, HO_HIST_SIZE * L_FFT ); - } - st->hTcxEnc->measuredBwRatio_flt = fix16_to_float( st->hTcxEnc->measuredBwRatio, Q14 ); - fixedToFloat_arr( st->lsp_old_fx, st->lsp_old, Q15, M ); { st->clip_var[0] = (float) st->clip_var_fx[0] / 2.56f; st->clip_var[1] = fix16_to_float( st->clip_var_fx[1], Q14 ); @@ -502,11 +479,6 @@ ivas_error ivas_core_enc( st->clip_var[4] = fix16_to_float( st->clip_var_fx[4], Q14 ); st->clip_var[5] = fix16_to_float( st->clip_var_fx[5], Q14 ); } - - for ( int j = 0; j < M; j++ ) - { - st->lsf_old[j] = (float) st->lsf_old_fx[j] / 2.56f; - } for ( int k = 0; k < 2; k++ ) { fixedToFloat_arrL( st->hTcxEnc->spectrum_fx[k], st->hTcxEnc->spectrum[k], 31 - st->hTcxEnc->spectrum_e[k], 720 ); @@ -699,11 +671,6 @@ ivas_error ivas_core_enc( #else #ifdef IVAS_FLOAT_FIXED_CONVERSIONS // lsp_old - Q15, lsf_old - Qlog2(2.56), pitch_buf - Q6 - floatToFixed_arr16( st->lsp_old, st->lsp_old_fx, Q15, M ); - for ( i = 0; i < M; i++ ) - { - st->lsf_old_fx[i] = (Word16) ( st->lsf_old[i] * 2.56f ); - } floatToFixed_arr16( pitch_buf[0], pitch_buf_fx[0], Q6, NB_SUBFR ); #endif td_stereo_param_updt_fx( st->lsp_old_fx, st->lsf_old_fx, pitch_buf_fx[0], tdm_lspQ_PCh_fx, tdm_lsfQ_PCh_fx, hStereoTD->tdm_Pri_pitch_buf_fx, st->flag_ACELP16k, hStereoTD->tdm_use_IAWB_Ave_lpc ); @@ -714,7 +681,6 @@ ivas_error ivas_core_enc( { tdm_lsfQ_PCh[i] = tdm_lsfQ_PCh_fx[i] / 2.56f; } - fixedToFloat_arr( hStereoTD->tdm_Pri_pitch_buf_fx, hStereoTD->tdm_Pri_pitch_buf, Q6, NB_SUBFR ); #endif #endif } diff --git a/lib_enc/ivas_core_pre_proc_front.c b/lib_enc/ivas_core_pre_proc_front.c index 335e85063..bac876c57 100644 --- a/lib_enc/ivas_core_pre_proc_front.c +++ b/lib_enc/ivas_core_pre_proc_front.c @@ -2061,8 +2061,6 @@ ivas_error pre_proc_front_ivas_fx( for ( int idx = 0; idx < M; idx++ ) { lsp_new_loc_fx[idx] = (Word16) ( lsp_new[idx] * 32767 ); - st->lsp_old1_fx[idx] = (Word16) ( st->lsp_old1[idx] * 32767 ); - st->lsf_old1_fx[idx] = (Word16) ( st->lsf_old1[idx] * 2.56 ); } for ( int idx = 0; idx < 3; idx++ ) { @@ -2116,8 +2114,6 @@ ivas_error pre_proc_front_ivas_fx( lsp_new[idx] = (float) lsp_new_loc_fx[idx] / 32767.0f; lsp_mid[idx] = (float) lsp_mid_loc_fx[idx] / 32767.0f; - st->lsp_old1[idx] = (float) ( (float) st->lsp_old1_fx[idx] / 32767.0f ); - st->lsf_old1[idx] = (float) ( (float) st->lsf_old1_fx[idx] / 2.56f ); lsf_new[idx] = (float) ( (float) lsf_new_16_loc_fx[idx] / 2.56f ); } for ( int idx = 0; idx < NB_SUBFR16k * ( M + 1 ); idx++ ) @@ -2277,11 +2273,6 @@ ivas_error pre_proc_front_ivas_fx( Word16 q_wsp = Q_factor_arr( old_wsp, L_WSP ) - 3; floatToFixed_arr16( old_wsp, old_wsp_fx, q_wsp, L_WSP ); floatToFixed_arr16( st->voicing, st->voicing_fx, Q15, 3 ); - st->voicing_sm_fx = float_to_fix16( st->voicing_sm, Q15 ); - st->voicing0_sm_fx = float_to_fix16( st->voicing0_sm, Q15 ); - st->LF_EnergyRatio_sm_fx = float_to_fix16( st->LF_EnergyRatio_sm, Q7 ); - st->diff_sm_fx = float_to_fix( st->diff_sm, Q7 ); - st->energy_sm_fx = float_to_fix( st->energy_sm, Q7 ); floatToFixed_arr16( st->Bin_E, st->lgBin_E_fx, Q7, L_FFT / 2 ); // Function StableHighPitchDetect_fx excepts st->lgBin_E_fx to be in Q7 @@ -2454,14 +2445,6 @@ ivas_error pre_proc_front_ivas_fx( st->coder_type = find_uv_ivas_fx( st, pitch_fr_fx, voicing_fr_fx, inp_12k8_fx, ee_fx, &dE1X_fx, corr_shift_fx, relE_fx, Etot16_fx, hp_E_fx, &flag_spitch, last_core_orig, hStereoClassif, q_inp_12k8, q_fr_bands ); #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - - st->diff_sm = fixedToFloat_32( st->diff_sm_fx, Q7 ); - st->energy_sm = fixedToFloat_32( st->energy_sm_fx, Q7 ); - - st->voicing_sm = fixedToFloat_16( st->voicing_sm_fx, Q15 ); - st->voicing0_sm = fixedToFloat_16( st->voicing0_sm_fx, Q15 ); - st->LF_EnergyRatio_sm = fixedToFloat_16( st->LF_EnergyRatio_sm_fx, Q7 ); - fixedToFloat_arr( pitch_fr_fx, pitch_fr, Q6, NB_SUBFR ); fixedToFloat_arr( voicing_fr_fx, voicing_fr, Q15, NB_SUBFR ); @@ -2775,11 +2758,6 @@ ivas_error pre_proc_front_ivas_fx( { st->hTcxCfg->bandwidth_flt = getTcxBandwidth_flt( st->bwidth ); } - IF( st->envWeighted && !st->enableTcxLpc ) - { - /* Unweight the envelope */ - floatToFixed_arr( st->lsp_old, st->lsp_old_fx, Q15, M ); - } } #endif @@ -2787,14 +2765,6 @@ ivas_error pre_proc_front_ivas_fx( st->sba_br_sw_while_no_data = 0; move16(); - -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - IF( st->envWeighted && !st->enableTcxLpc ) - { - fixedToFloat_arr( st->lsp_old_fx, st->lsp_old, Q15, M ); - fixedToFloat_arr( st->lsf_old_fx, st->lsf_old, Q15, M ); - } -#endif #else SetModeIndex( st, st->bits_frame_nominal * FRAMES_PER_SEC, element_mode, MCT_flag ); diff --git a/lib_enc/ivas_dirac_enc.c b/lib_enc/ivas_dirac_enc.c index 5dc8c4f61..36abcd18f 100644 --- a/lib_enc/ivas_dirac_enc.c +++ b/lib_enc/ivas_dirac_enc.c @@ -410,7 +410,7 @@ void ivas_dirac_enc_close_fx( IF( hDirAC->hFbMixer != NULL ) { - ivas_FB_mixer_close( &hDirAC->hFbMixer, input_Fs, 0 ); + ivas_FB_mixer_close_fx( &hDirAC->hFbMixer, input_Fs, 0 ); } /* intensity 3-dim */ FOR( i = 0; i < DIRAC_NUM_DIMS; i++ ) diff --git a/lib_enc/ivas_enc.c b/lib_enc/ivas_enc.c index 9c114e061..580ac60a8 100644 --- a/lib_enc/ivas_enc.c +++ b/lib_enc/ivas_enc.c @@ -800,7 +800,8 @@ ivas_error ivas_enc( } for ( i = 0; i < st_ivas->hEncoderConfig->nchan_ism; i++ ) { - floatToFixed_arr32( st_ivas->hParamIsm->hFbMixer->ppFilterbank_prior_input[i], st_ivas->hParamIsm->hFbMixer->ppFilterbank_prior_input_fx[i], Q14, st_ivas->hParamIsm->hFbMixer->fb_cfg->prior_input_length ); + scale_sig32( st_ivas->hParamIsm->hFbMixer->ppFilterbank_prior_input_fx[i], st_ivas->hParamIsm->hFbMixer->fb_cfg->prior_input_length, sub( Q14, st_ivas->hParamIsm->hFbMixer->q_ppFilterbank_prior_input_fx[i] ) ); + st_ivas->hParamIsm->hFbMixer->q_ppFilterbank_prior_input_fx[i] = Q14; } #endif @@ -814,10 +815,6 @@ ivas_error ivas_enc( { fixedToFloat_arrL32( data_fx[i], data_f[i], Q14, input_frame ); } - for ( i = 0; i < st_ivas->hEncoderConfig->nchan_ism; i++ ) - { - fixedToFloat_arrL32( st_ivas->hParamIsm->hFbMixer->ppFilterbank_prior_input_fx[i], st_ivas->hParamIsm->hFbMixer->ppFilterbank_prior_input[i], Q14, st_ivas->hParamIsm->hFbMixer->fb_cfg->prior_input_length ); - } #endif #else ivas_param_ism_enc( st_ivas, data_f, input_frame ); @@ -1203,13 +1200,6 @@ ivas_error ivas_enc( ivas_mc_paramupmix_enc_fx( st_ivas, hMetaData, data_fx, input_frame ); #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - for ( int ts = 0; ts < MAX_PARAM_SPATIAL_SUBFRAMES; ts++ ) - { - for ( int ch_idx = 0; ch_idx < st_ivas->hMCParamUpmix->hFbMixer->fb_cfg->num_in_chans; ch_idx++ ) - { - fixedToFloat_arrL( st_ivas->hMCParamUpmix->hFbMixer->ppFilterbank_prior_input_fx[ch_idx], st_ivas->hMCParamUpmix->hFbMixer->ppFilterbank_prior_input[ch_idx], Q14, input_frame / MAX_PARAM_SPATIAL_SUBFRAMES ); - } - } for ( i = 4; i < 12; i++ ) { for ( int l = 0; l < input_frame; l++ ) diff --git a/lib_enc/ivas_front_vad.c b/lib_enc/ivas_front_vad.c index ca21f7b64..cdca90692 100644 --- a/lib_enc/ivas_front_vad.c +++ b/lib_enc/ivas_front_vad.c @@ -981,7 +981,6 @@ ivas_error front_vad_spar( // analy_lp( inp_12k8, L_FRAME, L_LOOK_12k8, &res_energy, A, epsP, lsp_new, lsp_mid, st->lsp_old1, alw_pitch_lag_12k8, alw_voicing, INT_FS_12k8, 0 /* <-- sec_chan_low_rate */ ); Word16 Q_r[2] = { 0 }; - floatToFixed_arr( st->lsp_old1, st->lsp_old1_fx, Q15, M ); floatToFixed_arr( alw_voicing, alw_voicing_fx, Q15, 2 ); Q_inp_12k8 = Q9; // Q_factor_arr( inp_12k8 - 90, 3 * L_FRAME / 2 + 90 ); floatToFixed_arr( inp_12k8 - 90, inp_12k8_fx - 90, Q_inp_12k8, 3 * L_FRAME / 2 + 90 ); @@ -994,7 +993,6 @@ ivas_error front_vad_spar( fixedToFloat_arr( A_fx, A, Q14, NB_SUBFR16k * ( M + 1 ) ); fixedToFloat_arr( lsp_new_fx, lsp_new, Q15, M ); fixedToFloat_arr( lsp_mid_fx, lsp_mid, Q15, M ); - fixedToFloat_arr( st->lsp_old1_fx, st->lsp_old1, Q15, M ); fixedToFloat_arr( st->mem_decim2_fx, st->mem_decim2, Q9, 3 ); #endif @@ -1072,9 +1070,6 @@ ivas_error front_vad_spar( floatToFixed_arr( st->Bin_E, st->lgBin_E_fx, Q7, 128 ); StableHighPitchDetect_ivas_fx( &flag_spitch, st->pitch, st->voicing_fx, wsp_fx, st->localVAD, &st->voicing_sm_fx, &st->voicing0_sm_fx, &st->LF_EnergyRatio_sm_fx, &st->predecision_flag, &st->diff_sm_fx, &st->energy_sm_fx, Q12, st->lgBin_E_fx ); fixedToFloat_arr( st->lgBin_E_fx, st->Bin_E, Q7, 128 ); - st->LF_EnergyRatio_sm = fixedToFloat( st->LF_EnergyRatio_sm_fx, Q7 ); - st->voicing_sm = fixedToFloat( st->voicing_sm_fx, Q15 ); - st->voicing0_sm = fixedToFloat( st->voicing0_sm_fx, Q15 ); #endif if ( st->hSpMusClas != NULL ) { diff --git a/lib_enc/ivas_masa_enc.c b/lib_enc/ivas_masa_enc.c index baebbcee5..a2fd102b1 100644 --- a/lib_enc/ivas_masa_enc.c +++ b/lib_enc/ivas_masa_enc.c @@ -5204,7 +5204,7 @@ static void average_masa_metadata_fx( hMeta->common_meta.surround_coherence_fx[j][k] = BASOP_Util_Divide3232_Scale( surr_coh_sum_fx, L_add( energy_sum_fx, EPSILON_FX ), &temp2_e ); move16(); temp2_e = add( temp2_e, sub( surr_coh_sum_e, energy_sum_e ) ); - hMeta->common_meta.surround_coherence_fx[j][k] = shl( hMeta->common_meta.surround_coherence_fx[j][k], temp2_e ); /*changing q from 15-temp2_e to q15*/ + hMeta->common_meta.surround_coherence_fx[j][k] = shl_sat( hMeta->common_meta.surround_coherence_fx[j][k], temp2_e ); /*changing q from 15-temp2_e to q15*/ move16(); } diff --git a/lib_enc/ivas_mc_param_enc.c b/lib_enc/ivas_mc_param_enc.c index 024532450..4c5c7905e 100644 --- a/lib_enc/ivas_mc_param_enc.c +++ b/lib_enc/ivas_mc_param_enc.c @@ -1013,13 +1013,6 @@ void ivas_param_mc_enc_fx( } } -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - for ( i = 0; i < hParamMC->hFbMixer->fb_cfg->num_in_chans; i++ ) - { - fixedToFloat_arrL( hParamMC->hFbMixer->ppFilterbank_prior_input_fx[i], hParamMC->hFbMixer->ppFilterbank_prior_input[i], Q11, input_frame / PARAM_MC_MDFT_NO_SLOTS ); - } -#endif - pop_wmops(); return; diff --git a/lib_enc/ivas_mc_paramupmix_enc.c b/lib_enc/ivas_mc_paramupmix_enc.c index d26e6bee4..0671e2f3f 100644 --- a/lib_enc/ivas_mc_paramupmix_enc.c +++ b/lib_enc/ivas_mc_paramupmix_enc.c @@ -281,7 +281,7 @@ ivas_error ivas_mc_paramupmix_enc_open( fb_cfg->prior_input_length = (int16_t) max( fb_cfg->prior_input_length, input_frame / MAX_PARAM_SPATIAL_SUBFRAMES ); /* Allocate and initialize FB mixer handle */ - IF( ( error = ivas_FB_mixer_open( &( hMCParamUpmix->hFbMixer ), input_Fs, fb_cfg, 0 ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_FB_mixer_open_fx( &( hMCParamUpmix->hFbMixer ), input_Fs, fb_cfg, 0 ) ) != IVAS_ERR_OK ) { return error; } @@ -605,7 +605,7 @@ void ivas_mc_paramupmix_enc_close( IF( ( *hMCParamUpmix )->hFbMixer != NULL ) { - ivas_FB_mixer_close( &( *hMCParamUpmix )->hFbMixer, input_Fs, 0 ); + ivas_FB_mixer_close_fx( &( *hMCParamUpmix )->hFbMixer, input_Fs, 0 ); } FOR( i = 0; i < MC_PARAMUPMIX_COMBINATIONS; i++ ) diff --git a/lib_enc/ivas_mcmasa_enc.c b/lib_enc/ivas_mcmasa_enc.c index c38bd5ec6..fa699e0af 100644 --- a/lib_enc/ivas_mcmasa_enc.c +++ b/lib_enc/ivas_mcmasa_enc.c @@ -128,42 +128,6 @@ static void computeEvenLayout_fx( static void computeLfeEnergy_fx( MCMASA_ENC_HANDLE hMcMasa, Word32 *data_fx[], const Word16 input_frame, Word16 q_fac ); -static Word16 ivas_getScaleFactor32( /* o: measured headroom in range [0..31], 0 if all x[i] == 0 */ - const Word32 *x, /* i: array containing 32-bit data */ - const Word16 len_x ) /* i: length of the array to scan */ -{ - Word16 i, i_min, i_max; - Word32 x_min, x_max; - - - x_max = 0; - move32(); - x_min = 0; - move32(); - FOR( i = 0; i < len_x; i++ ) - { - IF( x[i] >= 0 ) - x_max = L_max( x_max, x[i] ); - IF( x[i] < 0 ) - x_min = L_min( x_min, x[i] ); - } - - i_max = 0x1f; - move16(); - i_min = 0x1f; - move16(); - - IF( x_max != 0 ) - i_max = norm_l( x_max ); - - IF( x_min != 0 ) - i_min = norm_l( x_min ); - - i = s_and( s_min( i_max, i_min ), 0x1F ); - - - return i; -} #endif #ifdef IVAS_FLOAT_FIXED @@ -297,11 +261,6 @@ ivas_error ivas_mcmasa_enc_open_fx( return error; } - /* Allocate and initialize FB mixer handle */ - IF( NE_32( ( error = ivas_FB_mixer_open( &( hMcMasa->hFbMixer ), input_Fs, fb_cfg, 0 ) ), IVAS_ERR_OK ) ) - { - return error; - } /* Allocate and initialize FB mixer handle */ IF( NE_32( ( error = ivas_FB_mixer_open_fx( &( hMcMasa->hFbMixer ), input_Fs, fb_cfg, 0 ) ), IVAS_ERR_OK ) ) { @@ -332,10 +291,6 @@ ivas_error ivas_mcmasa_enc_open_fx( return error; } - IF( NE_32( ( error = ivas_FB_mixer_open( &( hMcMasa->hFbMixerLfe ), input_Fs, fb_cfgLfe, 0 ) ), IVAS_ERR_OK ) ) - { - return error; - } IF( NE_32( ( error = ivas_FB_mixer_open_fx( &( hMcMasa->hFbMixerLfe ), input_Fs, fb_cfgLfe, 0 ) ), IVAS_ERR_OK ) ) { return error; @@ -1073,11 +1028,11 @@ void ivas_mcmasa_enc_close_fx( } } - ivas_FB_mixer_close( &( *hMcMasa )->hFbMixer, input_Fs, 0 ); + ivas_FB_mixer_close_fx( &( *hMcMasa )->hFbMixer, input_Fs, 0 ); IF( !( *hMcMasa )->separateChannelEnabled ) { - ivas_FB_mixer_close( &( *hMcMasa )->hFbMixerLfe, input_Fs, 0 ); + ivas_FB_mixer_close_fx( &( *hMcMasa )->hFbMixerLfe, input_Fs, 0 ); } /* intensity 3-dim */ @@ -1761,8 +1716,8 @@ void ivas_mcmasa_param_est_enc_fx( FOR( i = 0; i < numAnalysisChannels; i++ ) { pcm_in[i] += l_ts; - cr_q = s_min( cr_q, ivas_getScaleFactor32( Chnl_ImagBuffer_fx[i], DIRAC_NO_FB_BANDS_MAX ) ); - ci_q = s_min( ci_q, ivas_getScaleFactor32( Chnl_RealBuffer_fx[i], DIRAC_NO_FB_BANDS_MAX ) ); + cr_q = s_min( cr_q, L_norm_arr( Chnl_ImagBuffer_fx[i], DIRAC_NO_FB_BANDS_MAX ) ); + ci_q = s_min( ci_q, L_norm_arr( Chnl_RealBuffer_fx[i], DIRAC_NO_FB_BANDS_MAX ) ); } sf = sub( s_min( cr_q, ci_q ), 5 ); diff --git a/lib_enc/ivas_osba_enc.c b/lib_enc/ivas_osba_enc.c index ec1e0f9fa..aafe494b4 100644 --- a/lib_enc/ivas_osba_enc.c +++ b/lib_enc/ivas_osba_enc.c @@ -427,7 +427,7 @@ ivas_error ivas_osba_enc_reconfig( /* FB mixer handle */ IF( hDirAC->hFbMixer != NULL ) { - ivas_FB_mixer_close( &( hDirAC->hFbMixer ), hEncoderConfig->input_Fs, 0 ); + ivas_FB_mixer_close_fx( &( hDirAC->hFbMixer ), hEncoderConfig->input_Fs, 0 ); hDirAC->hFbMixer = NULL; } spar_reconfig_flag = 1; diff --git a/lib_enc/ivas_pca_enc.c b/lib_enc/ivas_pca_enc.c index aff3a54e9..4e81efaac 100644 --- a/lib_enc/ivas_pca_enc.c +++ b/lib_enc/ivas_pca_enc.c @@ -89,35 +89,12 @@ static void ivas_bitstream_write_int32( #endif -#ifndef IVAS_FLOAT_FIXED -static void pca_enc_reset( - PCA_ENC_STATE *hPCA ) -{ - int16_t i; - - /* reset states for interpolation and multiplexing */ - eye_matrix( hPCA->prev_eigVec, FOA_CHANNELS, 1.0f ); - set_zero( hPCA->prev_ql, IVAS_PCA_INTERP ); - hPCA->prev_ql[0] = 1.0f; - set_zero( hPCA->prev_qr, IVAS_PCA_INTERP ); - hPCA->prev_qr[0] = 1.0f; - - for ( i = 0; i < FOA_CHANNELS; i++ ) - { - hPCA->prev_D[i] = 0.25f; - } - - eye_matrix( hPCA->mem_eigVec_interp, FOA_CHANNELS, 1.0f ); - set_zero( hPCA->old_r_sm, FOA_CHANNELS * FOA_CHANNELS ); - - return; -} -#else static void pca_enc_reset_fx( PCA_ENC_STATE *hPCA ) { Word16 i; + /* reset states for interpolation and multiplexing */ eye_matrix_fx( hPCA->prev_eigVec_fx, FOA_CHANNELS, MAX_WORD16 ); set16_fx( hPCA->prev_ql_fx, 0, IVAS_PCA_INTERP ); hPCA->prev_ql_fx[0] = MAX_WORD16; @@ -137,39 +114,7 @@ static void pca_enc_reset_fx( return; } -#endif -#ifndef IVAS_FLOAT_FIXED -static void pca_transform_sub( - float *eigVec, - float *transformed_data[8], /* i : input/transformed audio channels */ - const int16_t start, - const int16_t len, - const int16_t n_channels ) -{ - int16_t i, j, k; - float temp; - float buffer_data[FOA_CHANNELS]; - for ( j = 0; j < len; j++ ) - { - for ( k = 0; k < n_channels; k++ ) - { - buffer_data[k] = transformed_data[k][j + start]; - } - for ( k = 0; k < n_channels; k++ ) - { - temp = 0.0f; - for ( i = 0; i < n_channels; i++ ) - { - temp += eigVec[i * IVAS_PCA_INTERP + k] * buffer_data[i]; - } - transformed_data[k][j + start] = temp; - } - } - - return; -} -#else static void pca_transform_sub_fx( Word16 *eigVec, Word32 *transformed_data[8], /* i : input/transformed audio channels Q11 */ @@ -204,38 +149,7 @@ static void pca_transform_sub_fx( return; } -#endif - -#ifndef IVAS_FLOAT_FIXED -static void pca_enc_transform( - PCA_ENC_STATE *hPCA, - float *ql, - float *qr, - float *transformed_data[8], /* i : input/transformed audio channels */ - const int16_t input_frame, - const int16_t n_channels ) -{ - float eigVec_interp[FOA_CHANNELS * FOA_CHANNELS]; /* eigenvectors in current frame */ - float ql_interp[IVAS_PCA_LEN_INTERP_Q], qr_interp[IVAS_PCA_LEN_INTERP_Q]; - int16_t time_slot; - int16_t slot_len; - quat_shortestpath( hPCA->prev_ql, ql, hPCA->prev_qr, qr ); - - pca_interp_preproc( hPCA->prev_ql, hPCA->prev_qr, ql, qr, IVAS_PCA_N_SLOTS, ql_interp, qr_interp ); - - slot_len = (int16_t) ( input_frame / IVAS_PCA_N_SLOTS ); - - for ( time_slot = 0; time_slot < IVAS_PCA_N_SLOTS; time_slot++ ) - { - /* convert from double quaternion to 4D matrix */ - dquat2mat( &ql_interp[IVAS_PCA_INTERP * time_slot], &qr_interp[IVAS_PCA_INTERP * time_slot], eigVec_interp ); - pca_transform_sub( eigVec_interp, transformed_data, slot_len * time_slot, slot_len, n_channels ); - } - - return; -} -#else static void pca_enc_transform_fx( PCA_ENC_STATE *hPCA, Word16 *ql_fx, // Q15 @@ -263,23 +177,7 @@ static void pca_enc_transform_fx( return; } -#endif -#ifndef IVAS_FLOAT_FIXED -static void pca_update_state( - PCA_ENC_STATE *hPCA, - float *ql, - float *qr, - float *eigVec, - const int16_t n_channels ) -{ - mvr2r( qr, hPCA->prev_qr, IVAS_PCA_INTERP ); - mvr2r( ql, hPCA->prev_ql, IVAS_PCA_INTERP ); - mvr2r( eigVec, hPCA->prev_eigVec, n_channels * n_channels ); - - return; -} -#else static void pca_update_state_fx( PCA_ENC_STATE *hPCA, Word16 *ql, // Q15 @@ -293,33 +191,7 @@ static void pca_update_state_fx( return; } -#endif - -#ifndef IVAS_FLOAT_FIXED -static void swap_eigvec( - float *eigVec, - const int16_t i, - const int16_t j ) -{ - float eigVec_tmp[FOA_CHANNELS]; - int16_t k; - - for ( k = 0; k < FOA_CHANNELS; k++ ) - { - eigVec_tmp[k] = eigVec[k * FOA_CHANNELS + i]; - } - for ( k = 0; k < FOA_CHANNELS; k++ ) - { - eigVec[k * FOA_CHANNELS + i] = eigVec[k * FOA_CHANNELS + j]; - } - for ( k = 0; k < FOA_CHANNELS; k++ ) - { - eigVec[k * FOA_CHANNELS + j] = eigVec_tmp[k]; - } - return; -} -#else static void swap_eigvec_fx( Word32 *eigVec, // Q31 const Word32 i, @@ -346,52 +218,7 @@ static void swap_eigvec_fx( return; } -#endif -#ifndef IVAS_FLOAT_FIXED -static void sort4_D_eigVec( - float *D, - float *eigVec ) -{ - float tempr; - - if ( D[0] < D[1] ) - { - SWAP( D[0], D[1] ); - swap_eigvec( eigVec, 0, 1 ); - } - - if ( D[2] < D[3] ) - { - SWAP( D[2], D[3] ); - swap_eigvec( eigVec, 2, 3 ); - } - - if ( D[0] < D[2] ) - { - SWAP( D[0], D[2] ); - swap_eigvec( eigVec, 0, 2 ); - } - - if ( D[1] < D[3] ) - { - SWAP( D[1], D[3] ); - swap_eigvec( eigVec, 1, 3 ); - } - - if ( D[1] < D[2] ) - { - SWAP( D[1], D[2] ); - swap_eigvec( eigVec, 1, 2 ); - } - - /* swap last 2 values */ - SWAP( D[2], D[3] ); - swap_eigvec( eigVec, 2, 3 ); - - return; -} -#else static void sort4_D_eigVec_fx( Word32 *D, // Q Word32 *eigVec // Q31 @@ -435,7 +262,6 @@ static void sort4_D_eigVec_fx( return; } -#endif /*------------------------------------------------------------------------- * ivas_pca_enc_init() @@ -472,343 +298,6 @@ void ivas_pca_enc_init( * PCA encoder *------------------------------------------------------------------------*/ -#ifndef IVAS_FLOAT_FIXED -void ivas_pca_enc( - const ENCODER_CONFIG_HANDLE hEncoderConfig, /* i : configuration structure */ - PCA_ENC_STATE *hPCA, /* i : PCA encoder structure */ - BSTR_ENC_HANDLE hMetaData, /* i/o: MetaData handle */ - float *data_f[8], /* i : input/transformed audio channels */ - const int16_t input_frame, /* i : input frame length */ - const int16_t n_channels /* i : number of channels */ -) -{ - int16_t i, j, k, l; - int16_t len_subfr; - float r[FOA_CHANNELS * FOA_CHANNELS]; /* covariance matrix */ - float eigVec[FOA_CHANNELS * FOA_CHANNELS]; /* eigenvectors in current frame */ - float eigVec_tmp[FOA_CHANNELS * FOA_CHANNELS]; /* transpose / tmp matrix for permutation */ - float cost_mtx[FOA_CHANNELS * FOA_CHANNELS]; /* cost matrix */ - int16_t path[FOA_CHANNELS]; - float D[FOA_CHANNELS]; /* eigenvalues in current frame */ - float ql[IVAS_PCA_INTERP], qr[IVAS_PCA_INTERP]; - float det; - float temp; - float *ptr_sig[FOA_CHANNELS]; - int32_t index[2]; - float fac_D, sum_D; - float fac_cost; - float r_sm[16]; - float alpha; - float D_tmp[FOA_CHANNELS]; - int32_t ivas_total_brate; - float min_dot, dotl, dotr; - float min_dot2; - int16_t bypass_decision; - float dist_alt; - - ivas_total_brate = hEncoderConfig->ivas_total_brate; - - /* if PCA is disabled, just pass-through */ - if ( hEncoderConfig->Opt_PCA_ON == 0 ) - { - /* write by-pass indicator */ - push_next_indice( hMetaData, PCA_MODE_INACTIVE, 1 ); - - return; - } - - /* handle bitrate switching */ - if ( ivas_total_brate != PCA_BRATE ) - { - pca_enc_reset( hPCA ); - - if ( hEncoderConfig->last_ivas_total_brate != PCA_BRATE ) - { - eye_matrix( hPCA->mem_eigVec_interp, FOA_CHANNELS, 1.0f ); - /* copy input data into output directly as previous frame was already in by-pass mode */ - for ( k = 0; k < n_channels; k++ ) - { - // ToDo: TBV - } - } - else - { - /* set PCA by-pass mode in current frame and interpolate transform as previous frame used PCA */ - pca_enc_transform( hPCA, ql, qr, data_f, input_frame, n_channels ); - } - - pca_update_state( hPCA, ql, qr, eigVec, n_channels ); - - hPCA->prev_bypass_decision = PCA_MODE_INACTIVE; - - return; - } - - /*-----------------------------------------------------------------* - * Covariance - *-----------------------------------------------------------------*/ - - len_subfr = input_frame / 2; - - for ( i = 0; i < input_frame; i += len_subfr ) - { - for ( k = 0; k < FOA_CHANNELS; k++ ) - { - ptr_sig[k] = &data_f[k][i]; - } - - cov_subfr( ptr_sig, r, n_channels, input_frame / 2 ); - - alpha = IVAS_PCA_SM_FAC; - for ( k = 0; k < 16; k++ ) - { - r_sm[k] = alpha * r[k] + ( 1.f - alpha ) * hPCA->old_r_sm[k]; - hPCA->old_r_sm[k] = r_sm[k]; - } - } - - /* conditioning */ - for ( k = 0; k < FOA_CHANNELS; k++ ) - { - temp = r_sm[k * FOA_CHANNELS + k]; - - - if ( temp < IVAS_PCA_COV_THRES ) - { - temp = IVAS_PCA_COV_THRES; - } - r_sm[k * FOA_CHANNELS + k] = temp; /* pointer reuse */ - } - - /*-----------------------------------------------------------------* - * Eigenvalue decomposition - *-----------------------------------------------------------------*/ - - eig_qr( r_sm, IVAS_PCA_N_ITER_QR, eigVec, D, n_channels ); - - /* force positive eigenvalues */ - sum_D = 0.0; - for ( k = 0; k < n_channels; k++ ) - { - if ( D[k] < 0.f ) - { - D[k] = -D[k]; - - for ( l = 0; l < n_channels; l++ ) - { - eigVec[l * n_channels + k] = -eigVec[l * n_channels + k]; - } - } - sum_D += D[k]; - } - - /* normalize */ - fac_D = 1 / sum_D; - for ( k = 0; k < n_channels; k++ ) - { - D[k] *= fac_D; - } - - /* sorting (sanity check) with SPAR inversion of last two channels */ - sort4_D_eigVec( D, eigVec ); - - /* normalize and compute amount of decorrelation */ - dist_alt = 0.0; - for ( k = 0; k < FOA_CHANNELS; k++ ) - { - dist_alt += logf( r[k * FOA_CHANNELS + k] * fac_D + 1e-8f ); - dist_alt -= logf( D[k] + 1e-8f ); - } - - /*-----------------------------------------------------------------* - * Eigenvector alignment - *-----------------------------------------------------------------*/ - - if ( hPCA->prev_bypass_decision == PCA_MODE_ACTIVE ) - { - /* compute absolute cost matrix */ - for ( k = 0; k < n_channels; k++ ) /* column */ - { - for ( l = 0; l < n_channels; l++ ) /* row */ - { - fac_cost = hPCA->prev_D[l] * D[k]; - temp = 0.0; - for ( i = 0; i < n_channels; i++ ) /* row */ - { - temp += hPCA->prev_eigVec[i * n_channels + l] * eigVec[i * n_channels + k]; - } - if ( temp < 0 ) - { - temp = -temp; - } - cost_mtx[k * n_channels + l] = temp * fac_cost; - } - } - - /* find optimal permutation */ - exhst_4x4( cost_mtx, path, 1 ); - } - else - { - /* no alignment needed if previous PCA is inactive */ - for ( i = 0; i < 4; i++ ) - { - path[i] = i; - } - } - - /* permute eigenvectors */ - for ( k = 0; k < n_channels; k++ ) - { - j = path[k]; - /* copy j-th column to column k */ - for ( l = 0; l < n_channels; l++ ) - { - eigVec_tmp[l * n_channels + k] = eigVec[l * n_channels + j]; - } - D_tmp[k] = D[j]; - } - - for ( k = 0; k < n_channels * n_channels; k++ ) - { - eigVec[k] = eigVec_tmp[k]; - } - - /* check for sign inversions */ - for ( k = 0; k < n_channels; k++ ) /* column */ - { - temp = 0.0; - for ( i = 0; i < n_channels; i++ ) /* row */ - { - temp += hPCA->prev_eigVec[i * n_channels + k] * eigVec[i * n_channels + k]; - } - - if ( temp < 0 ) - { - for ( i = 0; i < n_channels; i++ ) - { - eigVec[i * n_channels + k] = -eigVec[i * n_channels + k]; - } - } - } - - /* force rotation matrix(det = +1) */ - det = mat_det4( eigVec ); - if ( det < 0 ) - { - swap_eigvec( eigVec, 2, 3 ); - temp = D_tmp[3]; - D_tmp[3] = D_tmp[2]; - D_tmp[2] = temp; - } - - /* update state */ - for ( k = 0; k < n_channels; k++ ) - { - hPCA->prev_D[k] = D_tmp[k]; - } - - /*-----------------------------------------------------------------* - * Rotation matrix parametrization and quantization - *-----------------------------------------------------------------*/ - - /* convert frrm rotation matrix to double quaternion */ - mat2dquat( eigVec, ql, qr ); - - dotl = dotp( hPCA->prev_ql, ql, 4 ); - dotr = dotp( hPCA->prev_qr, qr, 4 ); - if ( dotl < dotr ) - { - min_dot = dotl; - } - else - { - min_dot = dotr; - } - - if ( ql[0] < qr[0] ) - { - min_dot2 = ql[0]; - } - else - { - min_dot2 = qr[0]; - } - - bypass_decision = PCA_MODE_ACTIVE; - if ( dist_alt < IVAS_PCA_THRES_DIST_ALT ) - { - bypass_decision = PCA_MODE_INACTIVE; - } - if ( min_dot < IVAS_PCA_THRES_MIN_DOT ) - { - bypass_decision = PCA_MODE_INACTIVE; - } - if ( min_dot2 < IVAS_PCA_THRES_MIN_DOT2 ) - { - bypass_decision = PCA_MODE_INACTIVE; - } - - /* if PCA is inactive */ - if ( bypass_decision == PCA_MODE_INACTIVE ) - { - eye_matrix( eigVec, 4, 1. ); - set_zero( ql, 4 ); - set_zero( qr, 4 ); - ql[0] = 1.; - qr[0] = 1.; - - /* write by-pass indicator */ - push_next_indice( hMetaData, PCA_MODE_INACTIVE, 1 ); - if ( hPCA->prev_bypass_decision == PCA_MODE_INACTIVE ) - { - eye_matrix( hPCA->mem_eigVec_interp, FOA_CHANNELS, 1.0f ); - } - else - { - /* set PCA by-pass mode in current frame and interpolate transform as previous frame used PCA */ - pca_enc_transform( hPCA, ql, qr, data_f, input_frame, n_channels ); - } - - pca_update_state( hPCA, ql, qr, eigVec, n_channels ); - hPCA->prev_bypass_decision = PCA_MODE_INACTIVE; - - return; - } - - /* force ql to have first component with positive sign */ - if ( ql[0] < 0 ) - { - for ( i = 0; i < 4; i++ ) - { - ql[i] = -ql[i]; - qr[i] = -qr[i]; - } - } - - /* quantize double quaternion */ - pca_enc_s3( ql, &index[0] ); - pca_enc_s3( qr, &index[1] ); - - /* write bypass flag to bitstream to indicate active mode */ - push_next_indice( hMetaData, PCA_MODE_ACTIVE, 1 ); - - ivas_bitstream_write_int32( hMetaData, index[0], IVAS_PCA_QBITS - 1 ); - ivas_bitstream_write_int32( hMetaData, index[1], IVAS_PCA_QBITS ); - - /* transform */ - pca_enc_transform( hPCA, ql, qr, data_f, input_frame, n_channels ); - - /*-----------------------------------------------------------------* - * update state for next frame - *-----------------------------------------------------------------*/ - - hPCA->prev_bypass_decision = bypass_decision; - pca_update_state( hPCA, ql, qr, eigVec, n_channels ); - - return; -} -#else void ivas_pca_enc_fx( const ENCODER_CONFIG_HANDLE hEncoderConfig, /* i : configuration structure */ PCA_ENC_STATE *hPCA, /* i : PCA encoder structure */ @@ -1254,4 +743,3 @@ void ivas_pca_enc_fx( pca_update_state_fx( hPCA, ql_fx, qr_fx, eigVec_fx16, n_channels ); return; } -#endif diff --git a/lib_enc/ivas_sba_enc.c b/lib_enc/ivas_sba_enc.c index 501c6796a..c1e8a4b42 100644 --- a/lib_enc/ivas_sba_enc.c +++ b/lib_enc/ivas_sba_enc.c @@ -221,7 +221,7 @@ ivas_error ivas_sba_enc_reconfigure( /* FB mixer handle */ IF( hDirAC->hFbMixer != NULL ) { - ivas_FB_mixer_close( &( hDirAC->hFbMixer ), hEncoderConfig->input_Fs, 0 ); + ivas_FB_mixer_close_fx( &( hDirAC->hFbMixer ), hEncoderConfig->input_Fs, 0 ); hDirAC->hFbMixer = NULL; } spar_reconfig_flag = 1; diff --git a/lib_enc/ivas_spar_encoder.c b/lib_enc/ivas_spar_encoder.c index af5829365..bb0a77866 100644 --- a/lib_enc/ivas_spar_encoder.c +++ b/lib_enc/ivas_spar_encoder.c @@ -53,7 +53,7 @@ * Local function prototypes *--------------------------------------------------------------------*/ -static ivas_error ivas_spar_enc_process( Encoder_Struct *st_ivas, const ENCODER_CONFIG_HANDLE hEncoderConfig, BSTR_ENC_HANDLE hMetaData, const int16_t front_vad_flag, float *data_f[] ); +static ivas_error ivas_spar_enc_process_fx( Encoder_Struct *st_ivas, const ENCODER_CONFIG_HANDLE hEncoderConfig, BSTR_ENC_HANDLE hMetaData, const Word16 front_vad_flag, Word32 *data_fx[], const Word16 q_data ); #if 0 static Word16 Q_factor_L_abs( float x ); #endif @@ -131,7 +131,7 @@ ivas_error ivas_spar_enc_open( table_idx = ivas_get_spar_table_idx_fx( ivas_total_brate, sba_order_internal, SPAR_CONFIG_BW, NULL, NULL ); /* MD handle */ - if ( ( error = ivas_spar_md_enc_open( &( hSpar->hMdEnc ), hEncoderConfig, sba_order_internal ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_spar_md_enc_open_fx( &( hSpar->hMdEnc ), hEncoderConfig, sba_order_internal ) ) != IVAS_ERR_OK ) { return error; } @@ -145,7 +145,7 @@ ivas_error ivas_spar_enc_open( fb_cfg->remix_order = remix_order_set[hSpar->hMdEnc->spar_md_cfg.remix_unmix_order]; /* FB mixer handle */ - if ( ( error = ivas_FB_mixer_open( &( hSpar->hFbMixer ), input_Fs, fb_cfg, spar_reconfig_flag ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_FB_mixer_open_fx( &( hSpar->hFbMixer ), input_Fs, fb_cfg, spar_reconfig_flag ) ) != IVAS_ERR_OK ) { return error; } @@ -524,7 +524,7 @@ void ivas_spar_enc_close( assert( num_chans <= nchan_inp ); /* MD handle */ - ivas_spar_md_enc_close( &( *hSpar )->hMdEnc ); + ivas_spar_md_enc_close_fx( &( *hSpar )->hMdEnc ); /* Covar. State handle */ #ifdef IVAS_FLOAT_FIXED @@ -534,7 +534,7 @@ void ivas_spar_enc_close( #endif /* FB mixer handle */ - ivas_FB_mixer_close( &( *hSpar )->hFbMixer, input_Fs, spar_reconfig_flag ); + ivas_FB_mixer_close_fx( &( *hSpar )->hFbMixer, input_Fs, spar_reconfig_flag ); /* AGC */ #ifdef IVAS_FLOAT_FIXED @@ -629,13 +629,42 @@ ivas_error ivas_spar_enc( { ivas_sba_zero_vert_comp( data_f, st_ivas->sba_analysis_order, hEncoderConfig->sba_planar, input_frame ); } +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + Word32 data_fx_arr[MAX_INPUT_CHANNELS + MAX_NUM_OBJECTS][L_FRAME48k]; + Word32 *data_fx[MAX_INPUT_CHANNELS + MAX_NUM_OBJECTS]; + Word16 i, q_data = Q11; + Word16 num_ch = ivas_sba_get_nchan_fx( st_ivas->sba_analysis_order, 0 ); /*planar input arg. deliberately set to zero since input always in ACN/SN3D*/ + for ( i = 0; i < num_ch; i++ ) + { + data_fx[i] = data_fx_arr[i]; + if ( data_f[i] != NULL ) + { + floatToFixed_arrL( data_f[i], data_fx[i], q_data, input_frame ); + } + } + FOR( i = 0; i < st_ivas->hSpar->hFbMixer->fb_cfg->num_in_chans; i++ ) + { + scale_sig32( st_ivas->hSpar->hFbMixer->ppFilterbank_prior_input_fx[i], st_ivas->hSpar->hFbMixer->fb_cfg->prior_input_length, sub( q_data, st_ivas->hSpar->hFbMixer->q_ppFilterbank_prior_input_fx[i] ) ); + st_ivas->hSpar->hFbMixer->q_ppFilterbank_prior_input_fx[i] = q_data; + } +#endif /* SPAR encoder */ - if ( ( error = ivas_spar_enc_process( st_ivas, hEncoderConfig, hMetaData, st_ivas->hSpar->front_vad_flag, data_f ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_spar_enc_process_fx( st_ivas, hEncoderConfig, hMetaData, st_ivas->hSpar->front_vad_flag, data_fx, q_data ) ), IVAS_ERR_OK ) ) { return error; } +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + for ( i = 0; i < num_ch; i++ ) + { + if ( data_f[i] != NULL ) + { + fixedToFloat_arrL( data_fx[i], data_f[i], q_data, input_frame ); + } + } +#endif + *nb_bits_metadata = hMetaData->nb_bits_tot; /* Force IVAS front pre-proc decision for higher bitrates */ @@ -654,7 +683,7 @@ ivas_error ivas_spar_enc( * Process call for SPAR covariance and MD encoder *-------------------------------------------------------------------*/ -static ivas_error ivas_spar_cov_md_process( +static ivas_error ivas_spar_cov_md_process_fx( const ENCODER_CONFIG_HANDLE hEncoderConfig, SPAR_ENC_HANDLE hSpar, const IVAS_QMETADATA_HANDLE hQMetaData, @@ -709,7 +738,7 @@ static ivas_error ivas_spar_cov_md_process( test(); IF( NE_32( hEncoderConfig->ivas_total_brate, hEncoderConfig->last_ivas_total_brate ) && !hSpar->spar_reconfig_flag ) { - IF( NE_32( ( error = ivas_spar_md_enc_init( hSpar->hMdEnc, hEncoderConfig, sba_order ) ), IVAS_ERR_OK ) ) + IF( NE_32( ( error = ivas_spar_md_enc_init_fx( hSpar->hMdEnc, hEncoderConfig, sba_order ) ), IVAS_ERR_OK ) ) { return error; } @@ -934,49 +963,34 @@ static ivas_error ivas_spar_cov_md_process( *-----------------------------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED -static ivas_error ivas_spar_enc_process( +static ivas_error ivas_spar_enc_process_fx( Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ const ENCODER_CONFIG_HANDLE hEncoderConfig, /* i : configuration structure */ BSTR_ENC_HANDLE hMetaData, /* i/o: MetaData handle */ - const int16_t front_vad_flag, /* i : front-VAD decision */ - float *data_f[] /* i/o: input/transport audio channels */ -) + const Word16 front_vad_flag, /* i : front-VAD decision */ + Word32 *data_fx[], /* i/o: input/transport audio channels */ + const Word16 q_data ) { - float pcm_tmp[DIRAC_MAX_ANA_CHANS][L_FRAME48k * 2]; - float *p_pcm_tmp[DIRAC_MAX_ANA_CHANS]; -#ifdef IVAS_FLOAT_FIXED Word32 pcm_tmp_fx[DIRAC_MAX_ANA_CHANS][L_FRAME48k * 2]; Word32 *p_pcm_tmp_fx[DIRAC_MAX_ANA_CHANS]; - // Word16 q_pcm_tmp_fx[DIRAC_MAX_ANA_CHANS][L_FRAME48k * 2]; - // Word16 *q_p_pcm_tmp_fx[DIRAC_MAX_ANA_CHANS]; Word16 q_pcm_fx[DIRAC_MAX_ANA_CHANS]; -#endif -#ifdef IVAS_FLOAT_FIXED - // Word32 *ppIn_FR_real_fx[IVAS_SPAR_MAX_CH], *ppIn_FR_imag_fx[IVAS_SPAR_MAX_CH]; - // Word32 wyzx_del_buf_fx[FOA_CHANNELS][IVAS_FB_1MS_48K_SAMP]; - Word32 data_fix[MAX_INPUT_CHANNELS + MAX_NUM_OBJECTS][L_FRAME48k]; - Word16 q_data_fix[MAX_INPUT_CHANNELS + MAX_NUM_OBJECTS]; - Word32 *data_fx[MAX_INPUT_CHANNELS + MAX_NUM_OBJECTS]; - // Word16 q_cmplx[IVAS_SPAR_MAX_CH]; Word16 q_p_pcm_tmp_fx[DIRAC_MAX_ANA_CHANS]; -#endif - int16_t i, j, input_frame, dtx_vad; - int16_t transient_det[2]; - int16_t hodirac_flag; - int32_t ivas_total_brate, input_Fs; - int16_t nchan_inp, sba_order, nchan_transport; - int16_t in_out_mixer_map[IVAS_MAX_FB_MIXER_OUT_CH][IVAS_MAX_SPAR_FB_MIXER_IN_CH]; + Word16 i, j, input_frame, dtx_vad; + Word16 transient_det[2]; + Word16 hodirac_flag; + Word32 ivas_total_brate, input_Fs; + Word16 nchan_inp, sba_order, nchan_transport; + Word16 in_out_mixer_map[IVAS_MAX_FB_MIXER_OUT_CH][IVAS_MAX_SPAR_FB_MIXER_IN_CH]; ivas_error error; - const int16_t *order; + const Word16 *order; SPAR_ENC_HANDLE hSpar = st_ivas->hSpar; IVAS_QMETADATA_HANDLE hQMetaData = st_ivas->hQMetaData; - int16_t ts, l_ts, num_del_samples, b, i_ts; + Word16 ts, l_ts, num_del_samples, b, i_ts; - float *ppIn_FR_real[IVAS_SPAR_MAX_CH], *ppIn_FR_imag[IVAS_SPAR_MAX_CH]; Word32 *ppIn_FR_real_fx[IVAS_SPAR_MAX_CH], *ppIn_FR_imag_fx[IVAS_SPAR_MAX_CH]; - float wyzx_del_buf[FOA_CHANNELS][IVAS_FB_1MS_48K_SAMP]; - int16_t dyn_active_w_flag; - int16_t nchan_fb_in; + Word32 wyzx_del_buf[FOA_CHANNELS][IVAS_FB_1MS_48K_SAMP]; + Word16 dyn_active_w_flag; + Word16 nchan_fb_in; push_wmops( "ivas_spar_enc_process" ); @@ -985,43 +999,36 @@ static ivas_error ivas_spar_enc_process( *-----------------------------------------------------------------------------------------*/ error = IVAS_ERR_OK; + move32(); input_Fs = hEncoderConfig->input_Fs; + move32(); ivas_total_brate = hEncoderConfig->ivas_total_brate; + move32(); num_del_samples = hSpar->hFbMixer->fb_cfg->fb_latency; + move16(); - input_frame = (int16_t) ( input_Fs / FRAMES_PER_SEC ); - sba_order = min( st_ivas->sba_analysis_order, IVAS_MAX_SBA_ORDER ); -#ifndef IVAS_FLOAT_FIXED - nchan_inp = ivas_sba_get_nchan_metadata( sba_order, hEncoderConfig->ivas_total_brate ); -#else + Word32 res_dec, res_frac; + iDiv_and_mod_32( input_Fs, FRAMES_PER_SEC, &res_dec, &res_frac, 0 ); + input_frame = extract_l( res_dec ); + + sba_order = s_min( st_ivas->sba_analysis_order, IVAS_MAX_SBA_ORDER ); nchan_inp = ivas_sba_get_nchan_metadata_fx( sba_order, hEncoderConfig->ivas_total_brate ); -#endif assert( nchan_inp <= hEncoderConfig->nchan_inp ); nchan_fb_in = hSpar->hFbMixer->fb_cfg->nchan_fb_in; + move16(); nchan_transport = st_ivas->nchan_transport; + move16(); - for ( i = FOA_CHANNELS + 1; i < nchan_fb_in; i++ ) + FOR( i = FOA_CHANNELS + 1; i < nchan_fb_in; i++ ) { - mvr2r( data_f[HOA_keep_ind[i]], data_f[i], input_frame ); + Copy32( data_fx[HOA_keep_ind[i]], data_fx[i], input_frame ); } - /*-----------------------------------------------------------------------------------------* * Transient detector *-----------------------------------------------------------------------------------------*/ -#ifdef IVAS_FLOAT_FIXED - { - // Word32 data_fix[L_FRAME48k]; - FOR( i = 0; i < input_frame; i++ ) - { - data_fix[0][i] = (Word32) ( data_f[0][i] * ( 1 << Q14 ) ); - } - ivas_transient_det_process_fx( hSpar->hTranDet, data_fix[0], input_frame, transient_det ); - } -#else - ivas_transient_det_process( hSpar->hTranDet, data_f[0], input_frame, transient_det ); -#endif + ivas_transient_det_process_fx( hSpar->hTranDet, data_fx[0], input_frame, transient_det ); #ifdef DEBUGGING { @@ -1032,125 +1039,50 @@ static ivas_error ivas_spar_enc_process( } #endif - if ( ivas_total_brate < IVAS_24k4 ) + if ( LT_32( ivas_total_brate, IVAS_24k4 ) ) { transient_det[1] = 0; + move16(); } /* store previous input samples for W in local buffer */ assert( num_del_samples <= IVAS_FB_1MS_48K_SAMP ); - if ( hSpar->hFbMixer->fb_cfg->active_w_mixing == 0 ) + IF( hSpar->hFbMixer->fb_cfg->active_w_mixing == 0 ) { /* fill delay (1 ms) buffer for all Transport channels */ - for ( i = 0; i < FOA_CHANNELS; i++ ) + FOR( i = 0; i < FOA_CHANNELS; i++ ) { - int16_t idx = hSpar->hFbMixer->fb_cfg->remix_order[i]; - mvr2r( &hSpar->hFbMixer->ppFilterbank_prior_input[idx][hSpar->hFbMixer->fb_cfg->prior_input_length - num_del_samples], wyzx_del_buf[idx], num_del_samples ); + Word16 idx = hSpar->hFbMixer->fb_cfg->remix_order[i]; + move16(); + Copy32( &hSpar->hFbMixer->ppFilterbank_prior_input_fx[idx][hSpar->hFbMixer->fb_cfg->prior_input_length - num_del_samples], wyzx_del_buf[idx], num_del_samples ); } } /*-----------------------------------------------------------------------------------------* * FB mixer ingest *-----------------------------------------------------------------------------------------*/ - - for ( i = 0; i < nchan_fb_in; i++ ) - { - p_pcm_tmp[i] = pcm_tmp[i]; - } - - FOR( i = 0; i < nchan_fb_in; i++ ) { - - p_pcm_tmp[i] = pcm_tmp[i]; -#ifdef IVAS_FLOAT_FIXED p_pcm_tmp_fx[i] = pcm_tmp_fx[i]; - move32(); -#endif } /* Need to remove flt to fix conversions */ -#ifdef IVAS_FLOAT_FIXED -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + ivas_fb_mixer_pcm_ingest_fx( hSpar->hFbMixer, data_fx, p_pcm_tmp_fx, input_frame, hSpar->hMdEnc->HOA_md_ind, q_data, q_p_pcm_tmp_fx ); FOR( i = 0; i < hSpar->hFbMixer->fb_cfg->num_in_chans; i++ ) { - hSpar->hFbMixer->q_ppFilterbank_prior_input_fx[i] = Q_factor_arrL( hSpar->hFbMixer->ppFilterbank_prior_input[i], hSpar->hFbMixer->fb_cfg->prior_input_length ); - - floatToFixed_arrL( hSpar->hFbMixer->ppFilterbank_prior_input[i], - hSpar->hFbMixer->ppFilterbank_prior_input_fx[i], hSpar->hFbMixer->q_ppFilterbank_prior_input_fx[i], hSpar->hFbMixer->fb_cfg->prior_input_length ); + /* changing q format to q_data*/ + scale_sig32( p_pcm_tmp_fx[i], input_frame, sub( q_data, q_p_pcm_tmp_fx[i] ) ); } - /* In order to get the number of channels */ - Word16 num_chs_alloc; - - IF( hSpar->hFbMixer->fb_cfg->active_w_mixing == -1 ) - { - num_chs_alloc = 0; - } - ELSE IF( hSpar->hFbMixer->fb_cfg->active_w_mixing ) - { - num_chs_alloc = hSpar->hFbMixer->fb_cfg->num_in_chans; - } - ELSE - { - num_chs_alloc = 1; /* only W channel processed for predicting YZX */ - } -#ifdef MSAN_FIX - FOR( Word16 m = 0; m < nchan_fb_in; m++ ) -#else - FOR( Word16 m = 0; m <= nchan_fb_in + nchan_transport; m++ ) -#endif - { - IF( data_f[m] != NULL ) - { - q_data_fix[m] = Q_factor_arrL( data_f[m], input_frame ); - floatToFixed_arrL( data_f[m], data_fix[m], q_data_fix[m], input_frame ); - data_fx[m] = data_fix[m]; - } - } -#endif - ivas_fb_mixer_pcm_ingest_fx( hSpar->hFbMixer, data_fx, p_pcm_tmp_fx, input_frame, hSpar->hMdEnc->HOA_md_ind, q_data_fix, q_p_pcm_tmp_fx ); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - FOR( i = 0; i < hSpar->hFbMixer->fb_cfg->num_in_chans; i++ ) - { - me2f_buf( p_pcm_tmp_fx[i], 31 - q_p_pcm_tmp_fx[i], p_pcm_tmp[i], input_frame * 2 ); - } - FOR( Word16 x = 0; x < num_chs_alloc; x++ ) - { - me2f_buf( p_pcm_tmp_fx[hSpar->hFbMixer->fb_cfg->remix_order[x]], 31 - q_p_pcm_tmp_fx[hSpar->hFbMixer->fb_cfg->remix_order[x]], p_pcm_tmp[hSpar->hFbMixer->fb_cfg->remix_order[x]], input_frame * 2 ); - - hSpar->hFbMixer->q_ppFilterbank_inFR_re_fx[hSpar->hFbMixer->fb_cfg->remix_order[x]] = q_p_pcm_tmp_fx[hSpar->hFbMixer->fb_cfg->remix_order[x]]; - hSpar->hFbMixer->q_ppFilterbank_inFR_im_fx[hSpar->hFbMixer->fb_cfg->remix_order[x]] = q_p_pcm_tmp_fx[hSpar->hFbMixer->fb_cfg->remix_order[x]]; - } - /* Need to remove fix to flt conversions */ -#endif -#else - ivas_fb_mixer_pcm_ingest( hSpar->hFbMixer, data_f, p_pcm_tmp, input_frame, hSpar->hMdEnc->HOA_md_ind ); -#endif /* prepare Parameter MDFT analysis */ -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - for ( i = 0; i < nchan_fb_in; i++ ) - { - ppIn_FR_real[i] = p_pcm_tmp[i]; - ppIn_FR_imag[i] = p_pcm_tmp[i] + input_frame; - p_pcm_tmp[i] = data_f[i]; - } -#endif - - for ( i = 0; i < nchan_fb_in; i++ ) + FOR( i = 0; i < nchan_fb_in; i++ ) { ppIn_FR_real_fx[i] = p_pcm_tmp_fx[i]; ppIn_FR_imag_fx[i] = p_pcm_tmp_fx[i] + input_frame; p_pcm_tmp_fx[i] = data_fx[i]; } -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - FOR( i = 0; i < nchan_fb_in; i++ ) - { - floatToFixed_arrL( p_pcm_tmp[i], p_pcm_tmp_fx[i], Q14, input_frame ); - floatToFixed_arrL( hSpar->hFbMixer->ppFilterbank_prior_input[i], hSpar->hFbMixer->ppFilterbank_prior_input_fx[i], Q14, input_frame ); - } -#endif - l_ts = input_frame / MAX_PARAM_SPATIAL_SUBFRAMES; + l_ts = idiv1616( input_frame, MAX_PARAM_SPATIAL_SUBFRAMES ); + Word16 gb = find_guarded_bits_fx( l_ts ); FOR( ts = 0; ts < MAX_PARAM_SPATIAL_SUBFRAMES; ts++ ) { @@ -1166,137 +1098,70 @@ static ivas_error ivas_spar_enc_process( } } -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - /*To be removed*/ - FOR( i = 0; i < nchan_fb_in; i++ ) - { - fixedToFloat_arrL( hSpar->hFbMixer->ppFilterbank_prior_input_fx[i], hSpar->hFbMixer->ppFilterbank_prior_input[i], Q14, input_frame ); - } - - for ( ts = 0; ts < MAX_PARAM_SPATIAL_SUBFRAMES; ts++ ) - { - for ( i = 0; i < nchan_fb_in; i++ ) - { - p_pcm_tmp_fx[i] -= l_ts; - ppIn_FR_real_fx[i] -= l_ts; - ppIn_FR_imag_fx[i] -= l_ts; - } - } - for ( ts = 0; ts < MAX_PARAM_SPATIAL_SUBFRAMES; ts++ ) - { - for ( int ch_idx = 0; ch_idx < nchan_fb_in; ch_idx++ ) - { - fixedToFloat_arrL( ppIn_FR_real_fx[ch_idx], ppIn_FR_real[ch_idx], Q14 - gb, l_ts ); - fixedToFloat_arrL( ppIn_FR_imag_fx[ch_idx], ppIn_FR_imag[ch_idx], Q14 - gb, l_ts ); - fixedToFloat_arrL( p_pcm_tmp_fx[ch_idx], p_pcm_tmp[ch_idx], Q14, l_ts ); - } - for ( i = 0; i < nchan_fb_in; i++ ) - { - p_pcm_tmp_fx[i] += l_ts; - ppIn_FR_real_fx[i] += l_ts; - ppIn_FR_imag_fx[i] += l_ts; - - p_pcm_tmp[i] += l_ts; - ppIn_FR_real[i] += l_ts; - ppIn_FR_imag[i] += l_ts; - } - } -#endif /* turn pointers back to the local buffer, needed for the following processing */ - for ( i = 0; i < nchan_fb_in; i++ ) - { - ppIn_FR_real[i] = pcm_tmp[i]; - ppIn_FR_imag[i] = pcm_tmp[i] + input_frame; - p_pcm_tmp[i] = pcm_tmp[i]; - } FOR( i = 0; i < nchan_fb_in; i++ ) { ppIn_FR_real_fx[i] = pcm_tmp_fx[i]; ppIn_FR_imag_fx[i] = pcm_tmp_fx[i] + input_frame; p_pcm_tmp_fx[i] = pcm_tmp_fx[i]; } - - dtx_vad = ( hEncoderConfig->Opt_DTX_ON == 1 ) ? front_vad_flag : 1; + IF( EQ_16( hEncoderConfig->Opt_DTX_ON, 1 ) ) + { + dtx_vad = front_vad_flag; + move16(); + } + ELSE + { + dtx_vad = 1; + move16(); + } /*-----------------------------------------------------------------------------------------* * DirAC encoding *-----------------------------------------------------------------------------------------*/ -#ifdef IVAS_FLOAT_FIXED hodirac_flag = ivas_get_hodirac_flag_fx( ivas_total_brate, st_ivas->sba_analysis_order ); -#else - hodirac_flag = ivas_get_hodirac_flag( ivas_total_brate, st_ivas->sba_analysis_order ); -#endif -#ifdef IVAS_FLOAT_FIXED -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - Word16 pcm_q; + /*Finding max possible q*/ Word16 pp_fr_q; - float max_val = 0.0f; - /* Find Q-factor */ - for ( i = 0; i < nchan_fb_in; i++ ) - { - for ( j = 0; j < input_frame; j++ ) - { - max_val = max( max_val, (float) fabs( data_f[i][j] ) ); - } - } - pcm_q = Q_factor_L( max_val ); - - max_val = 0; - for ( i = 0; i < nchan_fb_in; i++ ) - { - for ( j = 0; j < input_frame; j++ ) - { - max_val = max( max_val, (float) fabs( ppIn_FR_real[i][j] ) ); - max_val = max( max_val, (float) fabs( ppIn_FR_imag[i][j] ) ); - } - } - pp_fr_q = Q_factor_L( max_val ); - - Word32 fr_real_fx[DIRAC_MAX_ANA_CHANS][L_FRAME48k * 2]; - Word32 fr_imag_fx[DIRAC_MAX_ANA_CHANS][L_FRAME48k * 2]; - Word32 data_f_buf[DIRAC_MAX_ANA_CHANS][L_FRAME48k]; - Word32 *pp_fr_real_fx[DIRAC_MAX_ANA_CHANS]; - Word32 *pp_fr_imag_fx[DIRAC_MAX_ANA_CHANS]; - Word32 *data_f_fx[DIRAC_MAX_ANA_CHANS]; - for ( i = 0; i < nchan_fb_in; i++ ) + pp_fr_q = sub( q_data, gb ); + Word16 re_q = MAX_16, im_q = MAX_16, FR_q; + move16(); + move16(); + FOR( i = 0; i < nchan_fb_in; i++ ) { - data_f_fx[i] = data_f_buf[i]; - pp_fr_real_fx[i] = fr_real_fx[i]; - pp_fr_imag_fx[i] = fr_imag_fx[i]; - for ( j = 0; j < input_frame; j++ ) - { - data_f_fx[i][j] = float_to_fix( data_f[i][j], pcm_q ); - pp_fr_real_fx[i][j] = float_to_fix( ppIn_FR_real[i][j], pp_fr_q ); - pp_fr_imag_fx[i][j] = float_to_fix( ppIn_FR_imag[i][j], pp_fr_q ); - } + re_q = s_min( re_q, L_norm_arr( ppIn_FR_real_fx[i], input_frame ) ); + im_q = s_min( im_q, L_norm_arr( ppIn_FR_imag_fx[i], input_frame ) ); } -#endif - IF( ( error = ivas_dirac_enc_fx( st_ivas->hDirAC, hQMetaData, hMetaData, data_f_fx, pp_fr_real_fx, pp_fr_imag_fx, pp_fr_q, input_frame, dtx_vad, hEncoderConfig->ivas_format, hodirac_flag ) ) != IVAS_ERR_OK ) + FR_q = s_min( re_q, im_q ); + FOR( i = 0; i < nchan_fb_in; i++ ) { - return error; + scale_sig32( ppIn_FR_real_fx[i], input_frame, FR_q ); + scale_sig32( ppIn_FR_imag_fx[i], input_frame, FR_q ); } -#else + pp_fr_q = add( FR_q, pp_fr_q ); - if ( ( error = ivas_dirac_enc( st_ivas->hDirAC, hQMetaData, hMetaData, data_f, ppIn_FR_real, ppIn_FR_imag, input_frame, dtx_vad, hEncoderConfig->ivas_format, hodirac_flag ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_dirac_enc_fx( st_ivas->hDirAC, hQMetaData, hMetaData, data_fx, ppIn_FR_real_fx, ppIn_FR_imag_fx, pp_fr_q, input_frame, dtx_vad, hEncoderConfig->ivas_format, hodirac_flag ) ), IVAS_ERR_OK ) ) { return error; } -#endif /* Set Energy Ratio to 0.0 if the mono flag has been set */ - if ( hQMetaData->dirac_mono_flag ) + IF( hQMetaData->dirac_mono_flag ) { - for ( b = hQMetaData->q_direction->cfg.start_band; b < hQMetaData->q_direction->cfg.nbands; b++ ) + FOR( b = hQMetaData->q_direction->cfg.start_band; b < hQMetaData->q_direction->cfg.nbands; b++ ) { - for ( i_ts = 0; i_ts < ( ( dtx_vad == 1 ) ? hQMetaData->q_direction[0].cfg.nblocks : 1 ); i_ts++ ) + Word16 loop_count = 1; + move16(); + IF( EQ_16( dtx_vad, 1 ) ) + { + loop_count = hQMetaData->q_direction[0].cfg.nblocks; + move16(); + } + FOR( i_ts = 0; i_ts < loop_count; i_ts++ ) { -#ifndef IVAS_FLOAT_FIXED - hQMetaData->q_direction[0].band_data[b].energy_ratio[i_ts] = 0.0f; -#else hQMetaData->q_direction[0].band_data[b].energy_ratio_fx[i_ts] = 0; -#endif + move32(); } } } @@ -1304,15 +1169,7 @@ static ivas_error ivas_spar_enc_process( /*-----------------------------------------------------------------------------------------* * Covariance and MD processing *-----------------------------------------------------------------------------------------*/ -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - for ( int ch_idx = 0; ch_idx < nchan_fb_in; ch_idx++ ) - { - floatToFixed_arrL32( ppIn_FR_real[ch_idx], ppIn_FR_real_fx[ch_idx], Q14 - gb, input_frame ); - floatToFixed_arrL32( ppIn_FR_imag[ch_idx], ppIn_FR_imag_fx[ch_idx], Q14 - gb, input_frame ); - } -#endif - - if ( ( error = ivas_spar_cov_md_process( hEncoderConfig, st_ivas->hSpar, st_ivas->hQMetaData, hMetaData, nchan_inp, sba_order, ppIn_FR_real_fx, ppIn_FR_imag_fx, transient_det, dtx_vad, nchan_transport, &dyn_active_w_flag, Q14 - gb ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_spar_cov_md_process_fx( hEncoderConfig, st_ivas->hSpar, st_ivas->hQMetaData, hMetaData, nchan_inp, sba_order, ppIn_FR_real_fx, ppIn_FR_imag_fx, transient_det, dtx_vad, nchan_transport, &dyn_active_w_flag, pp_fr_q ) ), IVAS_ERR_OK ) ) { return error; } @@ -1321,7 +1178,7 @@ static ivas_error ivas_spar_enc_process( * FB mixer *-----------------------------------------------------------------------------------------*/ - ivas_fb_mixer_get_in_out_mapping( hSpar->hFbMixer->fb_cfg, in_out_mixer_map ); + ivas_fb_mixer_get_in_out_mapping_fx( hSpar->hFbMixer->fb_cfg, in_out_mixer_map ); #ifdef DEBUG_SPAR_DIRAC_WRITE_OUT_PRED_PARS { @@ -1334,142 +1191,77 @@ static ivas_error ivas_spar_enc_process( fprintf( fid, "%.6f\n", hSpar->hMdEnc->mixer_mat[1][0][band] ); } #endif -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - Word16 q_p_pcm_tmp_loc_fx[DIRAC_MAX_ANA_CHANS]; -#endif - // both mixer_mat_fx and prior mixer_mat_fx should have a common q as there are values being copied inside function - // or need to do loop for updating values for unused values - ivas_fb_mixer_process( hSpar->hFbMixer, hSpar->hMdEnc->mixer_mat_fx, &hSpar->hMdEnc->q_mixer_mat_fx, p_pcm_tmp_fx, q_p_pcm_tmp_loc_fx, input_frame, in_out_mixer_map ); + ivas_fb_mixer_process_fx( hSpar->hFbMixer, hSpar->hMdEnc->mixer_mat_fx, &hSpar->hMdEnc->q_mixer_mat_fx, p_pcm_tmp_fx, q_p_pcm_tmp_fx, input_frame, in_out_mixer_map ); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - for ( int ch = ( hSpar->hFbMixer->fb_cfg->active_w_mixing == 0 ); ch < hSpar->hFbMixer->fb_cfg->num_out_chans; ch++ ) + FOR( Word32 ch = ( hSpar->hFbMixer->fb_cfg->active_w_mixing == 0 ); ch < hSpar->hFbMixer->fb_cfg->num_out_chans; ch++ ) { - for ( int k = 0; k < input_frame; k++ ) - { - p_pcm_tmp[ch][k] = (float) fixedToFloat( p_pcm_tmp_fx[ch][k], q_p_pcm_tmp_loc_fx[ch] ); - } + /* changing q format to q_data*/ + scale_sig32( p_pcm_tmp_fx[ch], input_frame, sub( q_data, q_p_pcm_tmp_fx[ch] ) ); + q_p_pcm_tmp_fx[ch] = q_data; + move16(); } -#endif - if ( hSpar->hFbMixer->fb_cfg->active_w_mixing == 0 ) + IF( hSpar->hFbMixer->fb_cfg->active_w_mixing == 0 ) { - /*cross fade between new active W channels and old passive W channel*/ - if ( dyn_active_w_flag == 1 ) + IF( EQ_16( dyn_active_w_flag, 1 ) ) { - if ( hSpar->hMdEnc->spar_md.prior_dyn_active_w_flag != dyn_active_w_flag ) + IF( NE_16( hSpar->hMdEnc->spar_md.prior_dyn_active_w_flag, dyn_active_w_flag ) ) { - float new_w[L_FRAME48k]; - Word32 new_w_fx[L_FRAME48k]; + Word32 new_w[L_FRAME48k]; /* delayed W */ - mvr2r( wyzx_del_buf[0], p_pcm_tmp[0], num_del_samples ); - mvr2r( data_f[0], p_pcm_tmp[0] + num_del_samples, input_frame - num_del_samples ); + Copy32( wyzx_del_buf[0], p_pcm_tmp_fx[0], num_del_samples ); + Copy32( data_fx[0], p_pcm_tmp_fx[0] + num_del_samples, sub( input_frame, num_del_samples ) ); - mvr2r( wyzx_del_buf[hSpar->hMdEnc->spar_md.res_ind], new_w, num_del_samples ); - mvr2r( data_f[hSpar->hMdEnc->spar_md.res_ind], &new_w[num_del_samples], input_frame - num_del_samples ); + Copy32( wyzx_del_buf[hSpar->hMdEnc->spar_md.res_ind], new_w, num_del_samples ); + Copy32( data_fx[hSpar->hMdEnc->spar_md.res_ind], &new_w[num_del_samples], sub( input_frame, num_del_samples ) ); - if ( hSpar->hMdEnc->spar_md.prior_dyn_active_w_flag == 0 && dyn_active_w_flag == 1 ) + test(); + test(); + IF( hSpar->hMdEnc->spar_md.prior_dyn_active_w_flag == 0 && EQ_16( dyn_active_w_flag, 1 ) ) { -#ifndef IVAS_FLOAT_FIXED - ivas_fb_mixer_cross_fading( hSpar->hFbMixer, p_pcm_tmp, p_pcm_tmp[0], new_w, 0, input_frame, 0 ); -#else -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - floatToFixed_arrL32( new_w, new_w_fx, Q11, input_frame ); - FOR( i = 0; i < hSpar->hFbMixer->fb_cfg->num_out_chans; i++ ) - { - p_pcm_tmp_fx[i] = &pcm_tmp_fx[i][0]; - floatToFixed_arrL32( p_pcm_tmp[i], p_pcm_tmp_fx[i], Q11, input_frame ); - } -#endif - ivas_fb_mixer_cross_fading_fx( hSpar->hFbMixer, p_pcm_tmp_fx, p_pcm_tmp_fx[0], new_w_fx, 0, input_frame, 0 ); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - FOR( i = 0; i < hSpar->hFbMixer->fb_cfg->num_out_chans; i++ ) - { - fixedToFloat_arrL32( p_pcm_tmp_fx[i], p_pcm_tmp[i], Q11, input_frame ); - } -#endif -#endif + ivas_fb_mixer_cross_fading_fx( hSpar->hFbMixer, p_pcm_tmp_fx, p_pcm_tmp_fx[0], new_w, 0, input_frame, 0 ); } - else if ( hSpar->hMdEnc->spar_md.prior_dyn_active_w_flag == 1 && dyn_active_w_flag == 0 ) + ELSE IF( EQ_16( hSpar->hMdEnc->spar_md.prior_dyn_active_w_flag, 1 ) && dyn_active_w_flag == 0 ) { -#ifndef IVAS_FLOAT_FIXED - ivas_fb_mixer_cross_fading( hSpar->hFbMixer, p_pcm_tmp, new_w, p_pcm_tmp[0], 0, input_frame, 0 ); -#else -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - floatToFixed_arrL32( new_w, new_w_fx, Q11, input_frame ); - FOR( i = 0; i < hSpar->hFbMixer->fb_cfg->num_out_chans; i++ ) - { - p_pcm_tmp_fx[i] = &pcm_tmp_fx[i][0]; - floatToFixed_arrL32( p_pcm_tmp[i], p_pcm_tmp_fx[i], Q11, input_frame ); - } -#endif - ivas_fb_mixer_cross_fading_fx( hSpar->hFbMixer, p_pcm_tmp_fx, new_w_fx, p_pcm_tmp_fx[0], 0, input_frame, 0 ); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - FOR( i = 0; i < hSpar->hFbMixer->fb_cfg->num_out_chans; i++ ) - { - fixedToFloat_arrL32( p_pcm_tmp_fx[i], p_pcm_tmp[i], Q11, input_frame ); - } -#endif -#endif + ivas_fb_mixer_cross_fading_fx( hSpar->hFbMixer, p_pcm_tmp_fx, new_w, p_pcm_tmp_fx[0], 0, input_frame, 0 ); } } - else + ELSE { - mvr2r( wyzx_del_buf[hSpar->hMdEnc->spar_md.res_ind], p_pcm_tmp[0], num_del_samples ); - mvr2r( data_f[hSpar->hMdEnc->spar_md.res_ind], p_pcm_tmp[0] + num_del_samples, input_frame - num_del_samples ); + Copy32( wyzx_del_buf[hSpar->hMdEnc->spar_md.res_ind], p_pcm_tmp_fx[0], num_del_samples ); + Copy32( data_fx[hSpar->hMdEnc->spar_md.res_ind], p_pcm_tmp_fx[0] + num_del_samples, sub( input_frame, num_del_samples ) ); } } - else + ELSE { /* delayed W */ - mvr2r( wyzx_del_buf[0], p_pcm_tmp[0], num_del_samples ); - mvr2r( data_f[0], p_pcm_tmp[0] + num_del_samples, input_frame - num_del_samples ); + Copy32( wyzx_del_buf[0], p_pcm_tmp_fx[0], num_del_samples ); + Copy32( data_fx[0], p_pcm_tmp_fx[0] + num_del_samples, sub( input_frame, num_del_samples ) ); } - for ( i = 1; i < hSpar->hFbMixer->fb_cfg->num_out_chans; i++ ) + FOR( i = 1; i < hSpar->hFbMixer->fb_cfg->num_out_chans; i++ ) { - int16_t idx = hSpar->hFbMixer->fb_cfg->remix_order[i]; + Word16 idx = hSpar->hFbMixer->fb_cfg->remix_order[i]; + move16(); /* delayed, reorderd and accumulated with (negative) prediction from W */ - v_add( wyzx_del_buf[idx], p_pcm_tmp[i], p_pcm_tmp[i], num_del_samples ); - v_add( data_f[idx], p_pcm_tmp[i] + num_del_samples, p_pcm_tmp[i] + num_del_samples, input_frame - num_del_samples ); + v_add_fx( wyzx_del_buf[idx], p_pcm_tmp_fx[i], p_pcm_tmp_fx[i], num_del_samples ); + v_add_fx( data_fx[idx], p_pcm_tmp_fx[i] + num_del_samples, p_pcm_tmp_fx[i] + num_del_samples, sub( input_frame, num_del_samples ) ); } } - /*-----------------------------------------------------------------------------------------* * PCA encoder *-----------------------------------------------------------------------------------------*/ - if ( hSpar->hPCA != NULL ) + IF( hSpar->hPCA != NULL ) { -#ifdef IVAS_FLOAT_FIXED - FOR( i = 0; i < hSpar->hFbMixer->fb_cfg->num_out_chans; i++ ) - { - p_pcm_tmp_fx[i] = &pcm_tmp_fx[i][0]; - q_pcm_fx[i] = Q11; - FOR( j = 0; j < input_frame; j++ ) - { - p_pcm_tmp_fx[i][j] = float_to_fix( p_pcm_tmp[i][j], q_pcm_fx[i] ); - } - } - ivas_pca_enc_fx( hEncoderConfig, hSpar->hPCA, hMetaData, p_pcm_tmp_fx, input_frame, FOA_CHANNELS ); - FOR( i = 0; i < hSpar->hFbMixer->fb_cfg->num_out_chans; i++ ) - { - p_pcm_tmp_fx[i] = &pcm_tmp_fx[i][0]; - q_pcm_fx[i] = Q11; - FOR( j = 0; j < input_frame; j++ ) - { - p_pcm_tmp[i][j] = fix_to_float( p_pcm_tmp_fx[i][j], q_pcm_fx[i] ); - } - } -#else - ivas_pca_enc( hEncoderConfig, hSpar->hPCA, hMetaData, p_pcm_tmp, input_frame, FOA_CHANNELS ); -#endif } - else + ELSE { - if ( ivas_total_brate == PCA_BRATE && sba_order == SBA_FOA_ORDER ) + test(); + IF( EQ_32( ivas_total_brate, PCA_BRATE ) && EQ_16( sba_order, SBA_FOA_ORDER ) ) { /* write PCA bypass bit */ push_next_indice( hMetaData, PCA_MODE_INACTIVE, 1 ); @@ -1481,33 +1273,24 @@ static ivas_error ivas_spar_enc_process( * AGC *-----------------------------------------------------------------------------------------*/ - if ( dtx_vad == 1 ) + IF( EQ_16( dtx_vad, 1 ) ) { - if ( hSpar->AGC_Enable != 0 ) + IF( hSpar->AGC_Enable != 0 ) { -#ifdef IVAS_FLOAT_FIXED FOR( i = 0; i < hSpar->hFbMixer->fb_cfg->num_out_chans; i++ ) { - p_pcm_tmp_fx[i] = &pcm_tmp_fx[i][0]; - q_pcm_fx[i] = Q_factor_arrL( &p_pcm_tmp[i][0], input_frame ); - FOR( j = 0; j < input_frame; j++ ) - { - p_pcm_tmp_fx[i][j] = float_to_fix( p_pcm_tmp[i][j], q_pcm_fx[i] ); - } + q_pcm_fx[i] = q_data; + move16(); } ivas_agc_enc_process_fx( hSpar->hAgcEnc, hMetaData, p_pcm_tmp_fx, p_pcm_tmp_fx, hSpar->hFbMixer->fb_cfg->num_out_chans, hEncoderConfig, q_pcm_fx ); FOR( i = 0; i < hSpar->hFbMixer->fb_cfg->num_out_chans; i++ ) { - FOR( j = 0; j < input_frame; j++ ) - { - p_pcm_tmp[i][j] = fix_to_float( p_pcm_tmp_fx[i][j], q_pcm_fx[i] ); - } + scale_sig32( p_pcm_tmp_fx[i], input_frame, sub( q_data, q_pcm_fx[i] ) ); + q_pcm_fx[i] = q_data; + move16(); } -#else - ivas_agc_enc_process( hSpar->hAgcEnc, hMetaData, p_pcm_tmp, p_pcm_tmp, hSpar->hFbMixer->fb_cfg->num_out_chans, hEncoderConfig ); -#endif } } @@ -1517,24 +1300,26 @@ static ivas_error ivas_spar_enc_process( *-----------------------------------------------------------------------------------------*/ order = remix_order_set[hSpar->hMdEnc->spar_md_cfg.remix_unmix_order]; + move16(); - for ( j = 0; j < nchan_transport; j++ ) + FOR( j = 0; j < nchan_transport; j++ ) { - if ( st_ivas->nchan_transport < 3 ) + IF( LT_16( st_ivas->nchan_transport, 3 ) ) { - mvr2r( p_pcm_tmp[j], data_f[j], input_frame ); + Copy32( p_pcm_tmp_fx[j], data_fx[j], input_frame ); } - else + ELSE { - mvr2r( p_pcm_tmp[j], data_f[order[j]], input_frame ); + Copy32( p_pcm_tmp_fx[j], data_fx[order[j]], input_frame ); } } - for ( ; j < IVAS_SPAR_MAX_DMX_CHS; j++ ) + FOR( ; j < IVAS_SPAR_MAX_DMX_CHS; j++ ) { - set_f( data_f[order[j]], 0.0f, input_frame ); + set32_fx( data_fx[order[j]], 0, input_frame ); } hSpar->hMdEnc->spar_md.prior_dyn_active_w_flag = dyn_active_w_flag; + move16(); pop_wmops(); diff --git a/lib_enc/ivas_spar_md_enc.c b/lib_enc/ivas_spar_md_enc.c index 11c2007a1..2c75c4f98 100644 --- a/lib_enc/ivas_spar_md_enc.c +++ b/lib_enc/ivas_spar_md_enc.c @@ -97,9 +97,10 @@ static int16_t ivas_get_arith_coded_bs( ivas_spar_md_enc_state_t *hMdEnc, BSTR_E #endif -static void ivas_spar_set_enc_config( ivas_spar_md_enc_state_t *hMdEnc, int16_t *max_freq_per_chan, const int16_t nchan_transport, float *pFC, const int16_t nchan_inp ); #ifdef IVAS_FLOAT_FIXED static void ivas_spar_set_enc_config_fx( ivas_spar_md_enc_state_t *hMdEnc, Word16 *max_freq_per_chan, const Word16 nchan_transport, Word32 *pFC, const Word16 nchan_inp ); +#else +static void ivas_spar_set_enc_config( ivas_spar_md_enc_state_t *hMdEnc, int16_t *max_freq_per_chan, const int16_t nchan_transport, float *pFC, const int16_t nchan_inp ); #endif // IVAS_FLOAT_FIXED #ifdef IVAS_FLOAT_FIXED @@ -285,27 +286,27 @@ ivas_error ivas_spar_md_enc_open_fx( *------------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED -void ivas_spar_md_enc_close( +void ivas_spar_md_enc_close_fx( ivas_spar_md_enc_state_t **hMdEnc_in /* i/o: SPAR MD encoder handle */ ) { - int16_t num_channels, i, j; + Word16 num_channels, i, j; ivas_spar_md_enc_state_t *hMdEnc; - if ( hMdEnc_in == NULL || *hMdEnc_in == NULL ) + IF( hMdEnc_in == NULL || *hMdEnc_in == NULL ) { return; } hMdEnc = *hMdEnc_in; num_channels = hMdEnc->num_umx_ch; + move16(); - if ( hMdEnc->spar_md.band_coeffs != NULL ) + IF( hMdEnc->spar_md.band_coeffs != NULL ) { free( hMdEnc->spar_md.band_coeffs ); hMdEnc->spar_md.band_coeffs = NULL; } -#ifdef IVAS_FLOAT_FIXED IF( hMdEnc->mixer_mat_fx != NULL ) { FOR( i = 0; i < num_channels; i++ ) @@ -318,7 +319,6 @@ void ivas_spar_md_enc_close( } free( hMdEnc->mixer_mat_fx ); } -#endif free( *hMdEnc_in ); *hMdEnc_in = NULL; @@ -387,6 +387,7 @@ void ivas_spar_md_enc_close( * SPAR MD encoder initialization *-----------------------------------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED ivas_error ivas_spar_md_enc_init( ivas_spar_md_enc_state_t *hMdEnc, /* o : MD encoder handle */ const ENCODER_CONFIG_HANDLE hEncoderConfig, /* i : configuration structure */ @@ -398,15 +399,10 @@ ivas_error ivas_spar_md_enc_init( float PR_minmax[2]; int16_t num_channels, i, j, k; -#ifndef IVAS_FLOAT_FIXED ivas_sba_get_spar_hoa_md_flag( sba_order, hEncoderConfig->ivas_total_brate, &hMdEnc->spar_hoa_md_flag, &hMdEnc->spar_hoa_dirac2spar_md_flag ); num_channels = ivas_sba_get_nchan_metadata( sba_order, hEncoderConfig->ivas_total_brate ); ivas_sba_get_spar_hoa_ch_ind( num_channels, hEncoderConfig->ivas_total_brate, hMdEnc->HOA_md_ind ); -#else - ivas_sba_get_spar_hoa_md_flag_fx( sba_order, hEncoderConfig->ivas_total_brate, &hMdEnc->spar_hoa_md_flag, &hMdEnc->spar_hoa_dirac2spar_md_flag ); - num_channels = ivas_sba_get_nchan_metadata_fx( sba_order, hEncoderConfig->ivas_total_brate ); - ivas_sba_get_spar_hoa_ch_ind_fx( num_channels, hEncoderConfig->ivas_total_brate, hMdEnc->HOA_md_ind ); -#endif + table_idx = ivas_get_spar_table_idx( hEncoderConfig->ivas_total_brate, sba_order, SPAR_CONFIG_BW, NULL, NULL ); hMdEnc->spar_md.prior_dyn_active_w_flag = 0; @@ -427,13 +423,8 @@ ivas_error ivas_spar_md_enc_init( return IVAS_ERR_INTERNAL; } -#ifndef IVAS_FLOAT_FIXED ivas_spar_arith_coeffs_com_init( &hMdEnc->arith_coeffs, &hMdEnc->spar_md_cfg, table_idx, ENC ); ivas_spar_huff_coeffs_com_init( &hMdEnc->huff_coeffs, NULL, table_idx, ENC ); -#else - ivas_spar_arith_coeffs_com_init_fx( &hMdEnc->arith_coeffs, &hMdEnc->spar_md_cfg, table_idx, ENC ); - ivas_spar_huff_coeffs_com_init_fx( &hMdEnc->huff_coeffs, NULL, table_idx, ENC ); -#endif if ( hEncoderConfig->Opt_DTX_ON == 1 ) { @@ -468,7 +459,7 @@ ivas_error ivas_spar_md_enc_init( return IVAS_ERR_OK; } -#ifdef IVAS_FLOAT_FIXED +#else ivas_error ivas_spar_md_enc_init_fx( ivas_spar_md_enc_state_t *hMdEnc, /* o : MD encoder handle */ const ENCODER_CONFIG_HANDLE hEncoderConfig, /* i : configuration structure */ @@ -557,6 +548,7 @@ ivas_error ivas_spar_md_enc_init_fx( * Set configuration for SPAR MD encoder *-----------------------------------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED static void ivas_spar_set_enc_config( ivas_spar_md_enc_state_t *hMdEnc, int16_t *max_freq_per_chan, @@ -598,7 +590,7 @@ static void ivas_spar_set_enc_config( return; } -#ifdef IVAS_FLOAT_FIXED +#else static void ivas_spar_set_enc_config_fx( ivas_spar_md_enc_state_t *hMdEnc, Word16 *max_freq_per_chan, @@ -735,7 +727,7 @@ static void ivas_band_mixing_fx( * *-----------------------------------------------------------------------------------------*/ -static void write_metadata_buffer( +static void write_metadata_buffer_fx( BSTR_ENC_HANDLE hMetaData_tmp, BSTR_ENC_HANDLE hMetaData, const Word16 bit_pos_start, @@ -1170,7 +1162,7 @@ ivas_error ivas_spar_md_enc_process_fx( test(); IF( EQ_16( hMetaData->nb_bits_tot, bit_pos_start ) || LT_16( hMetaData_tmp.nb_bits_tot, sub( hMetaData->nb_bits_tot, bit_pos_start ) ) ) { - write_metadata_buffer( &hMetaData_tmp, hMetaData, bit_pos_start, next_ind_start ); + write_metadata_buffer_fx( &hMetaData_tmp, hMetaData, bit_pos_start, next_ind_start ); code_strat = strat; move16(); } diff --git a/lib_enc/ivas_stat_enc.h b/lib_enc/ivas_stat_enc.h index 84b5fa9cb..e154ab7ca 100644 --- a/lib_enc/ivas_stat_enc.h +++ b/lib_enc/ivas_stat_enc.h @@ -491,8 +491,8 @@ typedef struct stereo_td_enc_data_structure Word16 tdm_lp_reuse_flag; /* Flag that indicate if it is possible to reuse the LP coefficient from the primary channel or not */ Word16 tdm_low_rate_mode; /* secondary channel low rate mode flag */ - float tdm_Pri_pitch_buf[NB_SUBFR]; #ifndef IVAS_FLOAT_FIXED + float tdm_Pri_pitch_buf[NB_SUBFR]; float tdm_lt_corr_RM; /* Long term right-mono correlation */ float tdm_lt_corr_LM; /* Long term left-mono correlation */ float tdm_last_diff_lt_corr; /* long term correlation difference mem */ @@ -954,9 +954,9 @@ typedef struct ivas_dirac_enc_data_structure float **direction_vector[DIRAC_NUM_DIMS]; float diffuseness_m[DIRAC_MAX_NBANDS]; #endif - int16_t band_grouping[DIRAC_MAX_NBANDS + 1]; - int16_t block_grouping[5]; - int16_t firstrun_sector_params; + Word16 band_grouping[DIRAC_MAX_NBANDS + 1]; + Word16 block_grouping[5]; + Word16 firstrun_sector_params; #ifdef IVAS_FLOAT_FIXED Word32 sec_I_vec_smth_x_fx[NUM_ANA_SECTORS][IVAS_MAX_NUM_BANDS]; @@ -984,8 +984,8 @@ typedef struct ivas_dirac_enc_data_structure /* diffuseness */ - int16_t index_buffer_intensity; - int16_t no_col_avg_diff; + Word16 index_buffer_intensity; + Word16 no_col_avg_diff; #ifdef IVAS_FLOAT_FIXED Word32 **buffer_intensity_real_fx[DIRAC_NUM_DIMS]; Word16 buffer_intensity_real_q[DIRAC_NUM_DIMS][DIRAC_NO_COL_AVG_DIFF][DIRAC_MAX_NBANDS]; @@ -997,7 +997,7 @@ typedef struct ivas_dirac_enc_data_structure #endif /* Frame count for detecting mono */ - int16_t mono_frame_count; + Word16 mono_frame_count; } DIRAC_ENC_DATA, *DIRAC_ENC_HANDLE; @@ -1085,14 +1085,6 @@ typedef struct ivas_spar_md_enc_state_t typedef struct { Word16 prev_bypass_decision; -#ifndef IVAS_FLOAT_FIXED - float prev_eigVec[FOA_CHANNELS * FOA_CHANNELS]; - float prev_ql[IVAS_PCA_INTERP]; - float prev_qr[IVAS_PCA_INTERP]; - float prev_D[IVAS_PCA_INTERP]; - float mem_eigVec_interp[FOA_CHANNELS * FOA_CHANNELS]; - float old_r_sm[FOA_CHANNELS * FOA_CHANNELS]; -#else Word16 prev_eigVec_fx[FOA_CHANNELS * FOA_CHANNELS]; // Q15 Word16 prev_ql_fx[IVAS_PCA_INTERP]; // Q15 Word16 prev_qr_fx[IVAS_PCA_INTERP]; // Q15 @@ -1100,7 +1092,6 @@ typedef struct Word16 mem_eigVec_interp_fx[FOA_CHANNELS * FOA_CHANNELS]; // Q15 Word32 old_r_sm_fx[FOA_CHANNELS * FOA_CHANNELS]; // old_r_sm_q Word16 old_r_sm_q; -#endif } PCA_ENC_STATE; diff --git a/lib_enc/ivas_stereo_switching_enc.c b/lib_enc/ivas_stereo_switching_enc.c index 5cb71c096..c8c0fdc95 100644 --- a/lib_enc/ivas_stereo_switching_enc.c +++ b/lib_enc/ivas_stereo_switching_enc.c @@ -681,9 +681,6 @@ ivas_error stereo_memory_enc_fx( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DTX variables\n" ) ); } } -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - floatToFixed_arr( st->lsp_old1, st->lsp_old1_fx, Q15, M ); -#endif dtx_enc_init_fx( st, 0, FIXED_SID_RATE ); IF( st->hTdCngEnc != NULL ) diff --git a/lib_enc/ivas_tcx_core_enc.c b/lib_enc/ivas_tcx_core_enc.c index 8a73b6616..d007e50a5 100644 --- a/lib_enc/ivas_tcx_core_enc.c +++ b/lib_enc/ivas_tcx_core_enc.c @@ -470,11 +470,6 @@ void stereo_tcx_core_enc( floatToFixed_arrL( st->Bin_E_old, st->Bin_E_old_fx, q_comm_Bin, 128 ); floatToFixed_arrL( st->Bin_E, st->Bin_E_fx, q_comm_Bin, 256 ); - floatToFixed_arr( st->lsp_old, st->lsp_old_fx, Q15, M ); - for ( int j = 0; j < M; j++ ) - { - st->lsf_old_fx[j] = (Word16) ( st->lsf_old[j] * 2.56f ); - } floatToFixed_arr( st->lspold_enc, st->lspold_enc_fx, Q15, M ); @@ -509,7 +504,6 @@ void stereo_tcx_core_enc( Q_new = 0; st->hTcxCfg->bandwidth = float_to_fix16( st->hTcxCfg->bandwidth_flt, Q15 ); - floatToFixed_arr( st->lsp_old16k, st->lsp_old16k_fx, Q15, M ); Word16 exp_exc; f2me_buf_16( st->hLPDmem->old_exc_flt, st->hLPDmem->old_exc, &exp_exc, L_EXC_MEM ); Q_exc = 15 - exp_exc; diff --git a/lib_enc/prot_fx_enc.h b/lib_enc/prot_fx_enc.h index d41b70076..057372853 100644 --- a/lib_enc/prot_fx_enc.h +++ b/lib_enc/prot_fx_enc.h @@ -4164,8 +4164,8 @@ void pvq_encode_frame_ivas_fx( const Word16 core /* i : core */ ); #endif -Word16 Interpol_4( /* o : interpolated value */ - Word16 *x, /* i : i vector */ +Word16 Interpol_4( /*Qx o : interpolated value */ + Word16 *x, /*Qx i : i vector */ Word16 frac /* i : fraction (-4..+3) */ ); diff --git a/lib_enc/speech_music_classif_fx.c b/lib_enc/speech_music_classif_fx.c index 56efcb482..2453ebf94 100644 --- a/lib_enc/speech_music_classif_fx.c +++ b/lib_enc/speech_music_classif_fx.c @@ -2079,19 +2079,21 @@ Word16 ivas_smc_gmm_fx( *pFV++ = mfcc[12];*/ /* calculation of differential normalized power spectrum */ - sum_PS_fx = 1; + sum_PS_fx = 0; + Word16 sum_PS_e = 0; move32(); + move16(); FOR( i = LOWEST_FBIN; i < HIGHEST_FBIN; i++ ) { - sum_PS_fx = L_add( L_shr( PS_fx[i], Q7 ), sum_PS_fx ); // Qfact_PS - Q7 + sum_PS_fx = BASOP_Util_Add_Mant32Exp( sum_PS_fx, sum_PS_e, PS_fx[i], sub( 31, Qfact_PS ), &sum_PS_e ); // sum_PS_e } + sum_PS_e = add( sum_PS_e, 1 ); // to avoid overflow + sum_PS_fx = L_add( L_shr( sum_PS_fx, 1 ), L_shr( 21475 /*1 e-5 q31*/, sum_PS_e ) ); // 31-sum_PS_e - temp_exp = 0; - move16(); FOR( i = LOWEST_FBIN; i < HIGHEST_FBIN; i++ ) { - temp32 = BASOP_Util_Divide3232_Scale( PS_fx[i], sum_PS_fx, &temp_exp ); - PS_norm_fx[i] = L_shl( temp32, sub( Qfact_PS_past, add( sub( 15, temp_exp ), 7 ) ) ); // Qfact_PS_past + temp32 = BASOP_Util_Divide3232_Scale_cadence( PS_fx[i], sum_PS_fx, &temp_exp ); // 31-temp_exp + PS_norm_fx[i] = L_shl( temp32, sub( Qfact_PS_past, add( sub( 31, temp_exp ), sub( Qfact_PS, sub( 31, sum_PS_e ) ) ) ) ); // Qfact_PS_past move32(); dPS_fx[i] = L_abs( L_sub( PS_norm_fx[i], hSpMusClas->past_PS_fx[i - LOWEST_FBIN] ) ); move32(); diff --git a/lib_enc/stat_enc.h b/lib_enc/stat_enc.h index 87076409e..849397efc 100644 --- a/lib_enc/stat_enc.h +++ b/lib_enc/stat_enc.h @@ -437,15 +437,18 @@ typedef struct td_cng_enc_structure Word32 ho_env_hist_fx[HO_HIST_SIZE * NUM_ENV_CNG]; /* Q6 */ #endif - Word16 ho_lsp_circ_fx[HO_HIST_SIZE * M]; /* CNG and DTX - old LSP buffer for averaging */ - Word32 ho_ener_circ_fx[HO_HIST_SIZE]; /* CNG and DTX - energy buffer for averaging */ - Word32 ho_env_circ_fx[HO_HIST_SIZE * NUM_ENV_CNG]; - int16_t act_cnt; /* CNG and DTX - counter of active frames */ - int16_t ho_circ_size; /* CNG and DTX - size of DTX hangover history buffer for averaging, <0,HO_HIST_SIZE> */ - int16_t ho_circ_ptr; /* CNG and DTX - pointer for averaging buffers */ + int16_t act_cnt; /* CNG and DTX - counter of active frames */ + int16_t ho_circ_size; /* CNG and DTX - size of DTX hangover history buffer for averaging, <0,HO_HIST_SIZE> */ + int16_t ho_circ_ptr; /* CNG and DTX - pointer for averaging buffers */ +#ifndef IVAS_FLOAT_FIXED float ho_lsp_circ[HO_HIST_SIZE * M]; /* CNG and DTX - old LSP buffer for averaging */ float ho_ener_circ[HO_HIST_SIZE]; /* CNG and DTX - energy buffer for averaging */ float ho_env_circ[HO_HIST_SIZE * NUM_ENV_CNG]; +#else + Word16 ho_lsp_circ_fx[HO_HIST_SIZE * M]; /* CNG and DTX - old LSP buffer for averaging Q15 */ + Word32 ho_ener_circ_fx[HO_HIST_SIZE]; /* CNG and DTX - energy buffer for averaging Q6 */ + Word32 ho_env_circ_fx[HO_HIST_SIZE * NUM_ENV_CNG]; /* Q6 */ +#endif int16_t burst_ho_cnt; /* CNG and DTX - counter of hangover frames at end of active burst */ int16_t cng_buf_cnt; /* CNG and DTX - Counter of buffered CNG parameters */ float cng_exc2_buf_flt[HO_HIST_SIZE * L_FFT]; /* CNG and DTX - exc2 buffer for storing */ @@ -2080,21 +2083,24 @@ typedef struct enc_core_structure LPD_state_HANDLE hLPDmem; /* ACELP LPDmem memories */ - float Bin_E[L_FFT]; /* per bin energy of two frames */ - float lsp_old1[M]; /* old unquantized LSP vector at the end of the frame at 12k8 */ - float lsf_old1[M]; /* old unquantized LSF vector at the end of the frame at 12k8 */ - float lsp_old[M]; /* old LSP vector at the end of the frame */ - float lsf_old[M]; /* old LSF vector at the end of the frame */ - float lsp_old16k[M]; /* old LSP vector at the end of the frame @16kHz */ - float lspold_enc[M]; /* old lsp (immittance spectral pairs) */ - Word32 Bin_E_fx[L_FFT]; /* Q_new + Q_SCALE -2 per bin energy of two frames */ - Word16 lsp_old1_fx[M]; /* old unquantized LSP vector at the end of the frame */ - Word16 lsf_old1_fx[M]; /* old LSF vector at the end of the frame */ - Word16 lsp_old_fx[M]; /* old LSP vector at the end of the frame */ // Q15 - Word16 lsf_old_fx[M]; /* old LSF vector at the end of the frame Qlog2(2.56) */ - Word16 lsp_old16k_fx[M]; /* old LSP vector at the end of the frame @16kHz */ - Word16 lspold_enc_fx[M]; /* old LSP vector at the end of the frame @16kHz */ - int16_t pstreaklen; /* LSF quantizer */ + float Bin_E[L_FFT]; /* per bin energy of two frames */ + Word32 Bin_E_fx[L_FFT]; /* Q_new + Q_SCALE -2 per bin energy of two frames */ +#ifndef IVAS_FLOAT_FIXED + float lsp_old1[M]; /* old unquantized LSP vector at the end of the frame at 12k8 */ + float lsf_old1[M]; /* old unquantized LSF vector at the end of the frame at 12k8 */ + float lsp_old[M]; /* old LSP vector at the end of the frame */ + float lsf_old[M]; /* old LSF vector at the end of the frame */ + float lsp_old16k[M]; /* old LSP vector at the end of the frame @16kHz */ +#else + Word16 lsp_old1_fx[M]; /* old unquantized LSP vector at the end of the frame Q15 */ + Word16 lsf_old1_fx[M]; /* old LSF vector at the end of the frame Qlog2(2.56) */ + Word16 lsp_old_fx[M]; /* old LSP vector at the end of the frame Q15 */ + Word16 lsf_old_fx[M]; /* old LSF vector at the end of the frame Qlog2(2.56) */ + Word16 lsp_old16k_fx[M]; /* old LSP vector at the end of the frame @16kHz Q15 */ +#endif + float lspold_enc[M]; /* old lsp (immittance spectral pairs) */ + Word16 lspold_enc_fx[M]; /* old LSP vector at the end of the frame @16kHz */ + int16_t pstreaklen; /* LSF quantizer */ #ifndef IVAS_FLOAT_FIXED float streaklimit; /* LSF quantizer */ float stab_fac; /* LSF stability factor */ @@ -2207,10 +2213,13 @@ typedef struct enc_core_structure int16_t spike_hyst; /* Hysteresis to prevent UC after sharp energy spike */ int16_t last_harm_flag_acelp; /* harmonicity flag for ACELP @32kbps rate */ float old_Aq_12_8[M + 1]; /* old Aq[] for core switching */ - float old_Es_pred; /* old Es_pred for core switching */ Word16 old_Aq_12_8_fx[M + 1]; /* Q12 old Aq[] for core switching */ - Word16 old_Es_pred_fx; /* Q8 old Es_pred for core switching */ - Word16 music_hysteresis_fx; /* Counter of frames after AUDIO coding mode to prevent UC */ +#ifndef IVAS_FLOAT_FIXED + float old_Es_pred; /* old Es_pred for core switching */ +#else + Word16 old_Es_pred_fx; /* old Es_pred for core switching Q8 */ +#endif + Word16 music_hysteresis_fx; /* Counter of frames after AUDIO coding mode to prevent UC */ Word16 last_vad_spa_fx; Word16 last_L_frame; /* ACELP@16kHz - last L_frame value */ @@ -2224,26 +2233,36 @@ typedef struct enc_core_structure Word16 last_code_preq; /* ACELP@16kHz - last coefficient of the pre-quantizer contribution */ Word16 use_acelp_preq; /* ACELP@16kHz - flag of prequantizer usage */ - Word16 bpf_off; /* Bass post-filter - do not use BPF when this flag is set to 1 */ - float old_pitch_buf[2 * NB_SUBFR16k]; /* Bass post-filter - buffer of old subframe pitch values */ - Word16 old_pitch_buf_fx[2 * NB_SUBFR16k]; /*Q6 Bass post-filter - buffer of old subframe pitch values */ - float pst_mem_deemp_err; /* Bass post-filter - filter memory of noise LP filter */ - Word16 pst_mem_deemp_err_fx; /* Bass post-filter - filter memory of noise LP filter */ - float pst_lp_ener; /* Bass post-filter - long-term energy */ - Word16 pst_lp_ener_fx; /* Bass post-filter - long-term energy */ + Word16 bpf_off; /* Bass post-filter - do not use BPF when this flag is set to 1 */ +#ifndef IVAS_FLOAT_FIXED + float old_pitch_buf[2 * NB_SUBFR16k]; /* Bass post-filter - buffer of old subframe pitch values */ + float pst_mem_deemp_err; /* Bass post-filter - filter memory of noise LP filter */ + float pst_lp_ener; /* Bass post-filter - long-term energy */ +#else + Word16 old_pitch_buf_fx[2 * NB_SUBFR16k]; /* Bass post-filter - buffer of old subframe pitch values Q6 */ + Word16 pst_mem_deemp_err_fx; /* Bass post-filter - filter memory of noise LP filter */ + Word16 pst_lp_ener_fx; /* Bass post-filter - long-term energy */ +#endif /* stable short pitch detection */ +#ifndef IVAS_FLOAT_FIXED float voicing0_sm; float voicing_sm; float LF_EnergyRatio_sm; +#else Word16 voicing0_sm_fx; Word16 voicing_sm_fx; Word16 LF_EnergyRatio_sm_fx; +#endif int16_t predecision_flag; +#ifndef IVAS_FLOAT_FIXED float diff_sm; float energy_sm; - Word32 diff_sm_fx; - Word32 energy_sm_fx; +#else + Word32 diff_sm_fx; /* Q7 */ + Word32 energy_sm_fx; /* Q7 */ +#endif + Word16 finalVAD; int16_t flag_noisy_speech_snr; /* encoder detector for noisy speech */ @@ -2335,14 +2354,14 @@ typedef struct enc_core_structure #ifndef IVAS_FLOAT_FIXED float bckr_tilt_lt_flt; #else - Word32 bckr_tilt_lt; /* Q16 */ + Word32 bckr_tilt_lt; /* Q16 */ #endif float lp_speech; Word16 lp_speech_fx; // Q8 #ifndef IVAS_FLOAT_FIXED float lp_noise; /* CNG and DTX - LP filtered total noise estimation */ #else - Word16 lp_noise_fx; /* CNG and DTX - LP filtered total noise estimation Q8 */ + Word16 lp_noise_fx; /* CNG and DTX - LP filtered total noise estimation Q8 */ #endif Word16 Opt_HE_SAD_ON_fx; Word16 nb_active_frames_HE_SAD_fx; @@ -2381,8 +2400,8 @@ typedef struct enc_core_structure float last_totalNoise; float totalNoise_increase_hist[TOTALNOISE_HIST_SIZE]; #else - Word16 last_totalNoise_fx; /* Q8 */ - Word16 totalNoise_increase_hist_fx[TOTALNOISE_HIST_SIZE]; /* Q8 */ + Word16 last_totalNoise_fx; /* Q8 */ + Word16 totalNoise_increase_hist_fx[TOTALNOISE_HIST_SIZE]; /* Q8 */ #endif int16_t totalNoise_increase_len; @@ -3237,7 +3256,9 @@ typedef struct enc_core_structure typedef struct GainItemStr { +#ifndef IVAS_FLOAT_FIXED float nmrValue; +#endif int16_t gainIndex; } GainItem; @@ -3245,14 +3266,15 @@ typedef struct context_rc_mem_struct { int16_t nbits_old; int16_t ctx; +#ifndef IVAS_FLOAT_FIXED float bit_estimate; - int16_t rateFlag; - int16_t lastnz; - int16_t nt_half; -#ifdef IVAS_FLOAT_FIXED +#else Word32 bit_estimate_fx; Word16 bit_estimate_e; #endif + int16_t rateFlag; + int16_t lastnz; + int16_t nt_half; } RC_CONTEXT_MEM, *HANDLE_RC_CONTEXT_MEM; -- GitLab From 3f3128964ad031be616a35cefcdd86f2267219ec Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Thu, 7 Nov 2024 18:34:32 +0530 Subject: [PATCH 094/128] SBA path cleanup for encoder, Q-info updates in lib_com --- lib_com/ivas_agc_com_fx.c | 20 +- lib_com/ivas_cnst.h | 206 +++--- lib_com/ivas_cov_smooth.c | 76 +-- lib_com/ivas_dirac_com.c | 138 ++-- lib_com/ivas_fb_mixer.c | 210 +++--- lib_com/ivas_prot.h | 2 +- lib_com/ivas_prot_fx.h | 36 +- lib_com/ivas_spar_com.c | 618 ++++++++++++++++- lib_com/ivas_stereo_ica_com_fx.c | 208 +++--- lib_com/prot_fx.h | 100 +-- lib_com/tcx_ltp_fx.c | 791 ++++++++++----------- lib_com/tcx_mdct_window.c | 107 +-- lib_dec/evs_dec_fx.c | 246 +++---- lib_dec/fd_cng_dec.c | 246 +++---- lib_dec/fd_cng_dec_fx.c | 948 +++++++++++++------------- lib_enc/core_enc_switch.c | 5 - lib_enc/ext_sig_ana.c | 41 +- lib_enc/igf_enc.c | 45 -- lib_enc/init_enc.c | 5 - lib_enc/ivas_corecoder_enc_reconfig.c | 3 +- lib_enc/ivas_enc.c | 2 +- lib_enc/ivas_mc_paramupmix_enc.c | 1 + lib_enc/ivas_mcmasa_enc.c | 3 +- lib_enc/ivas_mct_enc.c | 268 +++----- lib_enc/ivas_mdct_core_enc.c | 98 --- lib_enc/ivas_spar_encoder.c | 34 +- lib_enc/ivas_stereo_mdct_core_enc.c | 91 +-- lib_enc/stat_enc.h | 76 +-- 28 files changed, 2436 insertions(+), 2188 deletions(-) diff --git a/lib_com/ivas_agc_com_fx.c b/lib_com/ivas_agc_com_fx.c index db5ae0d21..26bbe6590 100644 --- a/lib_com/ivas_agc_com_fx.c +++ b/lib_com/ivas_agc_com_fx.c @@ -58,35 +58,35 @@ *-----------------------------------------------------------------------------------------*/ void ivas_agc_initWindowFunc_fx( - Word16 *pWinFunc, + Word16 *pWinFunc, // o: Q15 const Word16 length ) { Word16 i; Word16 a; const Word16 *cos_val; - a = A_FX; /* for DBSTEP -6.f */ + a = A_FX; /* for DBSTEP -6.f */ // Q15 move16(); SWITCH( length ) { case 128: - cos_val = cos_pi_by_127; + cos_val = cos_pi_by_127; // Q15 BREAK; case 256: - cos_val = cos_pi_by_255; + cos_val = cos_pi_by_255; // Q15 BREAK; case 384: - cos_val = cos_pi_by_383; + cos_val = cos_pi_by_383; // Q15 BREAK; default: - cos_val = cos_pi_by_383; + cos_val = cos_pi_by_383; // Q15 BREAK; } FOR( i = 0; i < length; i++ ) { - pWinFunc[i] = add( MAX_16, extract_l( Mpy_32_16_1( L_sub( cos_val[i], MAX_16 ), a ) ) ); + pWinFunc[i] = add( MAX_16, extract_l( Mpy_32_16_1( L_sub( cos_val[i], MAX_16 ), a ) ) ); // Q15 + Q15 - 15 = Q15 move16(); } @@ -100,9 +100,9 @@ void ivas_agc_initWindowFunc_fx( *-----------------------------------------------------------------------------------------*/ void ivas_agc_calcGainParams_fx( - UWord16 *absEmin, - UWord16 *betaE, - UWord16 *maxAttExp, + UWord16 *absEmin, // o: Q0 + UWord16 *betaE, // o: Q0 + UWord16 *maxAttExp, // o: Q0 const Word16 numCoeffs ) { assert( numCoeffs == IVAS_SPAR_MAX_DMX_CHS ); diff --git a/lib_com/ivas_cnst.h b/lib_com/ivas_cnst.h index 1356d695e..4f3aa5ae1 100644 --- a/lib_com/ivas_cnst.h +++ b/lib_com/ivas_cnst.h @@ -45,44 +45,44 @@ #define PI_OVER_2 ( EVS_PI / 2.0f ) #define PI_OVER_180 ( EVS_PI / 180.0f ) -#define ONE_BY_PI_OVER_180_Q25 ( 1922527360 ) -#define PI_OVER_180_Q22 ( 73204 ) +#define ONE_BY_PI_OVER_180_Q25 ( 1922527360 ) // Q25 +#define PI_OVER_180_Q22 ( 73204 ) // Q22 #define _180_OVER_PI ( 180.0f / EVS_PI ) #ifdef IVAS_FLOAT_FIXED -#define _180_OVER_PI_Q25 1922527338 -#define PI_OVER_180_Q25 ( 585635 ) -#define _180_IN_Q22 (754974720) -#define _360_IN_Q22 (1509949440) -#define _180_OVER_PI_FX (Word32) (( 180.0f / EVS_PI ) *ONE_IN_Q10) -#define PI_OVER_180_Q15 ( 572 ) -#define _180_OVER_PI_Q9 ( 29335 ) -#define PI_OVER_4_Q29 421657440 -#define _180_OVER_PI_Q9 ( 29335 ) -#define PI_OVER_Q29 1686629760 -#define Q31_0_99 2126008811 -#define Q31_0_01 21474836 -#define PI_OVER_180_FX (Word32) (( EVS_PI / 180.0f ) * ONE_IN_Q31) +#define _180_OVER_PI_Q25 ( 1922527338 ) // Q25 +#define PI_OVER_180_Q25 ( 585635 ) // Q25 +#define _180_IN_Q22 ( 754974720 ) // Q22 +#define _360_IN_Q22 ( 1509949440 ) // Q22 +#define _180_OVER_PI_FX ( (Word32) ( ( 180.0f / EVS_PI ) * ONE_IN_Q10 ) ) +#define PI_OVER_180_Q15 ( 572 ) // Q15 +#define _180_OVER_PI_Q9 ( 29335 ) // Q9 +#define PI_OVER_4_Q29 ( 421657440 ) // Q29 +#define _180_OVER_PI_Q9 ( 29335 ) // Q9 +#define PI_OVER_Q29 ( 1686629760 ) // Q29 +#define Q31_0_99 ( 2126008811 ) // Q31 +#define Q31_0_01 ( 21474836 ) // Q31 +#define PI_OVER_180_FX ( (Word32) ( ( EVS_PI / 180.0f ) * ONE_IN_Q31 ) ) // Q31 #endif -#define PI_OVER_4_Q29 421657440 -#define PI_OVER_Q29 1686629760 -#define PI2_C_ADP_RATE_Q31 449767936 //(2.0f * EVS_PI * pOTR->centerAdaptationRate)// -#define PI2_C_Q28 1686629760 -#define OFF_C_ADP_RATE_Q31 268435456 -#define C_ADP_RATE_Q31 71582792 +#define PI_OVER_4_Q29 ( 421657440 ) // Q29 +#define PI_OVER_Q29 ( 1686629760 ) // Q29 +#define PI2_C_ADP_RATE_Q31 ( 449767936 ) // Q31 (2.0f * EVS_PI * pOTR->centerAdaptationRate) +#define PI2_C_Q28 ( 1686629760 ) // Q28 +#define OFF_C_ADP_RATE_Q31 ( 268435456 ) // Q31 +#define C_ADP_RATE_Q31 ( 71582792 ) // Q31 #define SQRT2 1.414213562373095f -#define SQRT2_FIXED 1518500250 // Q30 +#define SQRT2_FIXED 1518500250 // Q30 #define SQRT2_OVER_2 (SQRT2 / 2.0f) -#define SQRT2_OVER_2_FIXED 1518500250 // Q31 +#define SQRT2_OVER_2_FIXED 1518500250 // Q31 #define INV_SQRT2 7.071067811865475e-1f /* 1/sqrt(2) */ #define INV_SQRT3 0.577350269189626f /* 1/sqrt(3) */ -#define INV_SQRT2_FX 1518500224 /* 1/sqrt(2) in Q31 */ +#define INV_SQRT2_FX ( 1518500224 ) /* 1/sqrt(2) in Q31 */ #ifdef IVAS_FLOAT_FIXED -#define INV_SQRT2_FX_Q15 23170 /* 1/sqrt(2) Q15*/ -#define INV_SQRT3_FX 18918 /* 1/sqrt(3) Q15*/ +#define INV_SQRT2_FX_Q15 ( 23170 ) /* 1/sqrt(2) Q15 */ +#define INV_SQRT3_FX ( 18918 ) /* 1/sqrt(3) Q15 */ #endif #define LOG_10 2.30258509299f @@ -341,32 +341,32 @@ typedef enum #define ISM_AZIMUTH_NBITS 7 #define ISM_AZIMUTH_MIN -180.0f #define ISM_AZIMUTH_MAX 180.0f -#define ISM_AZIMUTH_MIN_FX -754974720 -#define ISM_AZIMUTH_MAX_FX 754974720 +#define ISM_AZIMUTH_MIN_FX ( -754974720 ) // Q22 +#define ISM_AZIMUTH_MAX_FX ( 754974720 ) // Q22 #define ISM_AZIMUTH_LOW_BORDER -140.0f #define ISM_AZIMUTH_HIGH_BORDER 135.0f -#define ISM_AZIMUTH_LOW_BORDER_FX -587202560 -#define ISM_AZIMUTH_HIGH_BORDER_FX 566231040 +#define ISM_AZIMUTH_LOW_BORDER_FX ( -587202560 ) // Q22 +#define ISM_AZIMUTH_HIGH_BORDER_FX ( 566231040 ) // Q22 #define ISM_ELEVATION_NBITS 6 #define ISM_ELEVATION_MIN -90.0f #define ISM_ELEVATION_MAX 90.0f -#define ISM_ELEVATION_MIN_FX -377487360 -#define ISM_ELEVATION_MAX_FX 377487360 +#define ISM_ELEVATION_MIN_FX ( -377487360 ) // Q22 +#define ISM_ELEVATION_MAX_FX ( 377487360 ) // Q22 #define ISM_ELEVATION_LOW_BORDER -70.0f #define ISM_ELEVATION_HIGH_BORDER 65.0f -#define ISM_ELEVATION_LOW_BORDER_FX -293601280 -#define ISM_ELEVATION_HIGH_BORDER_FX 272629760 +#define ISM_ELEVATION_LOW_BORDER_FX ( -293601280 ) // Q22 +#define ISM_ELEVATION_HIGH_BORDER_FX ( 272629760 ) // Q22 #define ISM_Q_STEP 2.5f -#define ISM_Q_STEP_FX 10485760 +#define ISM_Q_STEP_FX ( 10485760 ) // Q22 #define ISM_Q_STEP_BORDER 5.0f -#define ISM_Q_STEP_BORDER_FX 20971520 +#define ISM_Q_STEP_BORDER_FX ( 20971520 ) // Q22 #define ISM_RADIUS_NBITS 6 #define ISM_RADIUS_MIN 0.0f #define ISM_RADIUS_MIN_Q9 0 #define ISM_RADIUS_DELTA 0.25f /* Max radius = (2^ISM_RADIUS_NBITS-1)*0.25 = 15.75 */ -#define ISM_RADIUS_DELTA_Q8 64 +#define ISM_RADIUS_DELTA_Q8 64 // Q8 #define ISM_EXTENDED_METADATA_BRATE IVAS_64k #define ISM_METADATA_IS_NDP_BITS 1 #define ISM_EXTENDED_METADATA_BITS 1 @@ -388,21 +388,21 @@ typedef enum #define STEP_PARAM_ISM_POW_RATIO_NBITS_Q15 (4681) /* 1.0f / (float)((1 << PARAM_ISM_POW_RATIO_NBITS) - 1) */ /* ISM DTX */ -#define ISM_Q_STEP_FX 10485760 -#define ISM_Q_STEP_BORDER_FX 20971520 +#define ISM_Q_STEP_FX ( 10485760 ) // Q22 +#define ISM_Q_STEP_BORDER_FX ( 20971520 ) // Q22 #define ISM_DTX_COH_SCA_BITS 4 #define ISM_DTX_AZI_BITS_HIGH 8 #define ISM_DTX_ELE_BITS_HIGH 7 #define ISM_Q_STEP_HIGH (ISM_Q_STEP / 2) #define ISM_Q_STEP_BORDER_HIGH (ISM_Q_STEP_BORDER / 2) -#define ISM_Q_STEP_HIGH_FX 5 * (1 << (22-2)) -#define ISM_Q_STEP_BORDER_HIGH_FX 5 * (1 << (22-1)) +#define ISM_Q_STEP_HIGH_FX ( 5 * ( 1 << ( 22 - 2 ) ) ) // Q22 +#define ISM_Q_STEP_BORDER_HIGH_FX ( 5 * ( 1 << ( 22 - 1 ) ) ) // Q22 #define ISM_DTX_AZI_BITS_LOW 6 #define ISM_DTX_ELE_BITS_LOW 5 #define ISM_Q_STEP_LOW (ISM_Q_STEP * 2) #define ISM_Q_STEP_BORDER_LOW (ISM_Q_STEP_BORDER * 2) -#define ISM_Q_STEP_LOW_FX 5 * (1 << 22) -#define ISM_Q_STEP_BORDER_LOW_FX 10 * (1 << 22) +#define ISM_Q_STEP_LOW_FX ( 5 * (1 << 22) ) // Q22 +#define ISM_Q_STEP_BORDER_LOW_FX ( 10 * (1 << 22) ) // Q22 /* ISM modes */ typedef enum @@ -589,15 +589,15 @@ typedef enum #define STEREO_DFT_SIDEGAIN_NBITS 5 #define STEREO_DFT_FEC_THRESHOLD 10 #ifdef IVAS_FLOAT_FIXED -#define STEREO_DFT_FEC_THRESHOLD_PLUS_1_INV_Q31 ( 195225786 ) -#define STEREO_DFT_BITDIFF_LP_FAC_Q31 ( 128849019 ) /* Low-pass filter coefficient for filtering bit difference between absolute and differential coding */ -#define STEREO_DFT_BITDIFF_ABS_SELECT_Q31 ( 1717986918 ) /* Constant to set tendency for selecting absolute coding mode */ +#define STEREO_DFT_FEC_THRESHOLD_PLUS_1_INV_Q31 ( 195225786 ) // Q31 +#define STEREO_DFT_BITDIFF_LP_FAC_Q31 ( 128849019 ) // Q31 /* Low-pass filter coefficient for filtering bit difference between absolute and differential coding */ +#define STEREO_DFT_BITDIFF_ABS_SELECT_Q31 ( 1717986918 ) // Q31 /* Constant to set tendency for selecting absolute coding mode */ #else #define STEREO_DFT_BITDIFF_LP_FAC (0.06f) /* Low-pass filter coefficient for filtering bit difference between absolute and differential coding */ #define STEREO_DFT_BITDIFF_ABS_SELECT (0.8f) /* Constant to set tendency for selecting absolute coding mode */ #endif #define STEREO_DFT_BITDIFF_INIT (12.0f) /* Init value for low-pass bit difference */ -#define STEREO_DFT_BITDIFF_INIT_FX (12288) /* Init value for low-pass bit difference in Q10*/ +#define STEREO_DFT_BITDIFF_INIT_FX (12288) // Q10 /* Init value for low-pass bit difference in Q10*/ #define STEREO_DFT_SIDE_GAIN_NBITS 5 #define STEREO_DFT_IPD_NBITS 3 @@ -619,8 +619,8 @@ typedef enum #define STEREO_DFT_COH_MAXBAND 6 #define STEREO_DFT_SID_GIPD_NBITS 2 #define STEREO_DFT_FD_FILT 0.9f -#define STEREO_DFT_FD_FILT_Q31 1932735283 -#define STEREO_DFT_FD_FILT_COMP_Q31 214748364 /* 1.0 - STEREO_DFT_FD_FILT */ +#define STEREO_DFT_FD_FILT_Q31 1932735283 // Q31 +#define STEREO_DFT_FD_FILT_COMP_Q31 214748364 // Q31 /* 1.0 - STEREO_DFT_FD_FILT */ #define STEREO_DFT_CNG_ITD_CNT 8 @@ -646,9 +646,9 @@ typedef enum #define STEREO_DFT_RES_GAINS_BITS 3 #define STEREO_DFT_RES_COD_SNR_MIN 10 -#define STEREO_DFT_RES_COD_SNR_MIN_Q25 335544320 +#define STEREO_DFT_RES_COD_SNR_MIN_Q25 335544320 // Q25 #define STEREO_DFT_RES_COD_SNR_MAX 40 -#define STEREO_DFT_RES_COD_SNR_MAX_Q25 1342177280 +#define STEREO_DFT_RES_COD_SNR_MAX_Q25 1342177280 // Q25 #define STEREO_DFT_L_SUBFR_8k 32 #define STEREO_DFT_NBPSF_PIT_MAX_8k NBPSF_PIT_MAX / 2 @@ -731,9 +731,9 @@ enum #define ECSQ_GLOBAL_GAIN_INDEX_ALL_ZERO 127 /* indicates that all values in the vector are zero */ #define ECLVQ_GLOBAL_GAIN_FACTOR ( 20.0f * 127.0f / 90.0f ) -#define ECLVQ_GLOBAL_GAIN_FACTOR_Q26 1893961218 +#define ECLVQ_GLOBAL_GAIN_FACTOR_Q26 1893961218 // Q26 #define ECLVQ_INV_GLOBAL_GAIN_FACTOR ( 1.0f / ( 20.0f * 127.0f / 90.0f ) ) -#define ECLVQ_INV_GLOBAL_GAIN_FACTOR_Q24 594468 +#define ECLVQ_INV_GLOBAL_GAIN_FACTOR_Q24 594468 // Q24 /* the currently defined configuration indexes are: 0: un-optimized using uniform 4 bit parameters (reserved) @@ -826,12 +826,12 @@ enum fea_names #define STEREO_BITS_TCA_CORRSTATS 5 /* target corrStats */ #define STEREO_BITS_TCA_GD 5 /* target gain */ #define STEREO_TCA_GDMIN -1.0f -#define STEREO_TCA_GDMIN_FX -32768 +#define STEREO_TCA_GDMIN_FX -32768 // Q15 #define STEREO_TCA_GDSTEP 0.05f -#define STEREO_TCA_GDSTEP_FX 819 +#define STEREO_TCA_GDSTEP_FX 819 // Q14 #ifdef IVAS_FLOAT_FIXED -#define STEREO_TCA_GDMIN_FX_Q14 (-16384) -#define STEREO_TCA_GDSTEP_FX_Q13 (410) +#define STEREO_TCA_GDMIN_FX_Q14 (-16384) // Q14 +#define STEREO_TCA_GDSTEP_FX_Q13 (410) // Q13 #endif #define STEREO_BITS_TCA ( STEREO_BITS_TCA_CHAN + STEREO_BITS_TCA_CORRSTATS + STEREO_BITS_TCA_GD ) @@ -848,14 +848,14 @@ enum fea_names #define MAX_DELAYREGLEN 12 /* max regression length */ #define INV_MAX_DELAYREGLEN 0.083333333333333f /* (1/MAX_DELAYREGLEN) */ -#define INV_MAX_DELAYREGLEN_FX_Q15 2731 /* (1/MAX_DELAYREGLEN) */ +#define INV_MAX_DELAYREGLEN_FX_Q15 2731 // Q15 /* (1/MAX_DELAYREGLEN) */ #define MAX_INTERPOLATE 11 #define ADDED_MEM_DS 40 #define STEREO_L_TCA_OVLP_NS 5000000L /* overlap length of the ICA gain scaling */ -#define STEREO_DMX_GAIN_Q13 29066 /* calculated this -->"powf( 10, ( ( 1 << STEREO_BITS_TCA_GD ) - 1 ) * STEREO_TCA_GDSTEP + STEREO_TCA_GDMIN )"*/ +#define STEREO_DMX_GAIN_Q13 29066 // Q13 /* calculated this -->"powf( 10, ( ( 1 << STEREO_BITS_TCA_GD ) - 1 ) * STEREO_TCA_GDSTEP + STEREO_TCA_GDMIN )"*/ /*----------------------------------------------------------------------------------* * TD Stereo Constants *----------------------------------------------------------------------------------*/ @@ -913,7 +913,7 @@ enum fea_names #define SNS_MEANS_BITS_4_FRAC 14 #define MDCT_ST_PLC_FADEOUT_MIN_NOISE_NRG 0.001f -#define MDCT_ST_PLC_FADEOUT_MIN_NOISE_NRG_Q31 2147483 +#define MDCT_ST_PLC_FADEOUT_MIN_NOISE_NRG_Q31 2147483 // Q31 #define MDCT_ST_PLC_FADEOUT_MAX_CONC_FRAME 2 * FRAMES_PER_SEC #define MDCT_ST_PLC_FADEOUT_TO_ZERO_LEN 20 #define MDCT_ST_PLC_FADEOUT_DELAY_4_LSP_FADE 3 @@ -1009,7 +1009,7 @@ typedef enum #define DIRAC_DIFF_NUM_AMBI_COMP 4 #define DIRAC_HOA_RENDERING_NUM_VIRT_DECORR_LS 8 #define DIRAC_GAIN_LIMIT 31.622776601683793f /* 30db gain limitiation */ -#define DIRAC_GAIN_LIMIT_Q26 ( 2122168614 ) /* 30db gain limitiation */ +#define DIRAC_GAIN_LIMIT_Q26 ( 2122168614 ) // Q26 /* 30db gain limitiation */ #define DIRAC_MAX_NUM_DECORR_FILTERS 22 #define DIRAC_MAX_DECORR_FILTER_LEN 20 #define DIRAC_DECORR_NUM_SPLIT_BANDS 3 @@ -1020,10 +1020,10 @@ typedef enum #define DIRAC_ONSET_BETA 0.995f #define DIRAC_ONSET_GAIN 4.0f #ifdef IVAS_FLOAT_FIXED -#define DIRAC_ONSET_ALPHA_FX 31129//Q15 -#define DIRAC_ONSET_BETA_FX 32604 //Q15 -#define ONE_DIRAC_ONSET_BETA_FX 163 //Q15 -#define DIRAC_ONSET_GAIN_FX 16384 //Q12 +#define DIRAC_ONSET_ALPHA_FX 31129 // Q15 +#define DIRAC_ONSET_BETA_FX 32604 // Q15 +#define ONE_DIRAC_ONSET_BETA_FX 163 // Q15 +#define DIRAC_ONSET_GAIN_FX 16384 // Q12 #endif #define DELAY_DIRAC_ENC_CMP_NS 9500000L /* Delay to be compensated on DirAC encoder */ @@ -1263,7 +1263,7 @@ enum #endif #define BITS_MASA2TOTTAL_DCT0 6 #define STEP_M2T 0.1f -#define STEP_M2T_FX 214748365 +#define STEP_M2T_FX 214748365 // Q31 #define MASA_HEADER_BITS 2 #define MASA_SUBFRAME_BITS 1 #define MASA_LOWBITRATE_MODE_BITS 1 @@ -1306,16 +1306,16 @@ enum #define MASA_COHERENCE_TOLERANCE 0.1f #define MASA_COHERENCE_THRESHOLD 0.1f #ifdef IVAS_FLOAT_FIXED -#define MASA_COHERENCE_TOLERANCE_FX 419430/*0.1 Q22*/ +#define MASA_COHERENCE_TOLERANCE_FX 419430 // 0.1 in Q22 #define MASA_COHERENCE_THRESHOLD_FX 214748365 // 0.1 in Q31 #endif #define MASA_RATIO_TOLERANCE 0.1f #define MASA_RATIO_THRESHOLD 0.1f #define MASA_ANGLE_TOLERANCE 0.5f #ifdef IVAS_FLOAT_FIXED -#define MASA_RATIO_THRESHOLD_FX 214748365 // 0.1 in Q31 -#define MASA_RATIO_TOLERANCE_FX 419430/*0.1 Q22*/ -#define MASA_ANGLE_TOLERANCE_FX ONE_IN_Q21/*0.5f q22*/ +#define MASA_RATIO_THRESHOLD_FX 214748365 // 0.1 in Q31 +#define MASA_RATIO_TOLERANCE_FX 419430 // 0.1 in Q22 +#define MASA_ANGLE_TOLERANCE_FX ONE_IN_Q21 // 0.5 in Q22 #endif #define MASA_LIMIT_NO_BANDS_SUR_COH 8 #define MINIMUM_BIT_BUDGET_NORMAL_META 100 @@ -1331,16 +1331,16 @@ enum #define MASA_NO_POINTS_EQUATOR 430 #define MASA_NO_CIRCLES 121 #ifdef IVAS_FLOAT_FIXED -#define MASA_NO_CIRCLES_Q23 ( 1015021568 ) +#define MASA_NO_CIRCLES_Q23 ( 1015021568 ) // Q23 #endif #define MASA_ASIN_OFFSET 0.0064471690266724975f -#define MASA_ASIN_OFFSET_Q15 ( 211 ) +#define MASA_ASIN_OFFSET_Q15 ( 211 ) // Q15 #define MASA_NTOT2_FAC 32768.00566947353f -#define MASA_NTOT2_FAC_Q15 ( 1073741952 ) +#define MASA_NTOT2_FAC_Q15 ( 1073741952 ) // Q15 #define MASA_ANGLE_AT_EQUATOR 0.012894427382667f -#define MASA_ANGLE_AT_EQUATOR_Q31 ( 27690572 ) +#define MASA_ANGLE_AT_EQUATOR_Q31 ( 27690572 ) // Q31 #define MASA_ANGLE_AT_EQUATOR_DEG 0.738796268264740f -#define MASA_ANGLE_AT_EQUATOR_DEG_Q31 ( 1586552905l ) +#define MASA_ANGLE_AT_EQUATOR_DEG_Q31 ( 1586552905l ) // Q31 #define MASA_INV_ANGLE_AT_EQUATOR_DEG 1.353553128183453f #define MASA_STEREO_MIN_BITRATE IVAS_24k4 #define MAXIMUM_OMASA_FREQ_BANDS 8 /* Corresponds to maximum number of coding bands at 32 kbps */ @@ -1406,8 +1406,8 @@ typedef enum #define MCMASA_MAX_ANA_CHANS 11 /* Maximum number of channels currently used in analysis of multichannel formats */ #ifdef IVAS_FLOAT_FIXED -#define MCMASA_MONOBITRATIO_64k_Q31 ( 536870912 ) -#define MCMASA_MONOBITRATIO_Q31 ( 644245095 ) +#define MCMASA_MONOBITRATIO_64k_Q31 ( 536870912 ) // Q31 +#define MCMASA_MONOBITRATIO_Q31 ( 644245095 ) // Q31 #else #define MCMASA_MONOBITRATIO 0.3f #define MCMASA_MONOBITRATIO_64k 0.25f @@ -1420,21 +1420,21 @@ typedef enum #define MCMASA_LFE_ALPHA 0.67f #define MCMASA_LFE_BETA 0.09f #ifdef IVAS_FLOAT_FIXED -#define MCMASA_LFE_1BIT_THRES_Q30 32212255 /* 0.03f in Q30 */ +#define MCMASA_LFE_1BIT_THRES_Q30 32212255 /* 0.03f in Q30 */ #define MCMASA_LFE_ALPHA_Q30 719407022 /* 0.67f in Q30 */ -#define MCMASA_LFE_BETA_Q30 96636764 /* 0.09f in Q30 */ +#define MCMASA_LFE_BETA_Q30 96636764 /* 0.09f in Q30 */ #endif #define MCMASA_LFE_THETA 1.3f #define MCMASA_LFE_SYNTH_ALPHA 0.95f /* Smoothing coefficient for LFE synthesis */ #ifdef IVAS_FLOAT_FIXED -#define MCMASA_LFE_SYNTH_ALPHA_Q15 (31129) +#define MCMASA_LFE_SYNTH_ALPHA_Q15 (31129) // Q15 #endif -#define MCMASA_LFE_ALPHA_Q15 (21954) -#define MCMASA_LFE_BETA_Q15 (2949) -#define MCMASA_LFE_BETA_Q14 (1474) -#define MCMASA_LFE_THETA_Q14 (21299) -#define MCMASA_LFE_QLOW_Q12 (-26624) -#define MCMASA_LFE_DELTA_Q11 (2048) +#define MCMASA_LFE_ALPHA_Q15 (21954) // Q15 +#define MCMASA_LFE_BETA_Q15 (2949) // Q15 +#define MCMASA_LFE_BETA_Q14 (1474) // Q14 +#define MCMASA_LFE_THETA_Q14 (21299) // Q14 +#define MCMASA_LFE_QLOW_Q12 (-26624) // Q12 +#define MCMASA_LFE_DELTA_Q11 (2048) // Q11 #define NUM_ELEVATED_SPEAKERS 4 @@ -1534,8 +1534,8 @@ typedef enum } PARAM_MC_SYNTHESIS_CONF; #ifdef IVAS_FLOAT_FIXED -#define PARAM_MC_REG_SX_FX (429496729) /* Regularization factor for mixing matrix calculation */ -#define PARAM_MC_REG_GHAT_FX (2147483) /* Regularization factor for mixing matrix calculation */ +#define PARAM_MC_REG_SX_FX (429496729) // Q31 /* Regularization factor for mixing matrix calculation */ +#define PARAM_MC_REG_GHAT_FX (2147483) // Q31 /* Regularization factor for mixing matrix calculation */ #endif #define PARAM_MC_REG_SX (0.2f) /* Regularization factor for mixing matrix calculation */ @@ -1572,7 +1572,7 @@ typedef enum #define PARAM_MC_NUM_BITS_ILD_SCALAR_QUANT 4 /* Number of bits for ILD uniform coding */ #define PARAM_MC_DEFAULT_MIN_ILD (-92.0f) /* Default relative channel level for untransmitted channel energies */ #ifdef IVAS_FLOAT_FIXED -#define PARAM_MC_DEFAULT_MIN_ILD_FX (-23552) /* Default relative channel level for untransmitted channel energies *//*Q8*/ +#define PARAM_MC_DEFAULT_MIN_ILD_FX (-23552) // Q8 /* Default relative channel level for untransmitted channel energies */ #endif // IVAS_FLOAT_FIXED #define PARAM_MC_MAX_BITS 1024 /* Maximum number of bits for the Parametric MC metadata */ #define PARAM_MC_MAX_BAND_ABS_COV_ENC 10 @@ -1586,11 +1586,11 @@ typedef enum #define PARAM_MC_ENER_LIMIT_MAX_DELTA_FAC_FX_Q21 31457280 #define PARAM_MC_NUM_ATTACK_ILD_THRESH (3) #define PARAM_MC_LFE_ON_THRESH (8000.0f) -#define PARAM_MC_LFE_ON_THRESH_FX 8000 //Q0 +#define PARAM_MC_LFE_ON_THRESH_FX 8000 // Q0 #define PARAM_MC_BAND_TO_MDCT_BAND_RATIO 16 /* Ratio of resolution of CLDFB Bands to MDCT Bands */ #define PARAM_MC_SLOT_ENC_NS 2500000L #define PARAM_MC_MDFT_NO_SLOTS 8 -#define INV_PARAM_MC_MDFT_NO_SLOTS_FX 4096 //Q15 +#define INV_PARAM_MC_MDFT_NO_SLOTS_FX 4096 // Q15 #define PARAM_MC_CLDFB_TO_MDFT_FAC 2 /*----------------------------------------------------------------------------------* @@ -1638,7 +1638,7 @@ typedef enum #define IVAS_ZERO_PAD_LEN_MULT_FAC (0.5f) -#define IVAS_ZERO_PAD_LEN_MULT_FAC_fx 16384 //0.5*Q15 +#define IVAS_ZERO_PAD_LEN_MULT_FAC_fx 16384 // 0.5 in Q15 /* LFE PLC */ #define LFE_PLC_BUFLEN 240 @@ -1654,10 +1654,10 @@ typedef enum /*----------------------------------------------------------------------------------* * HO Dirac Constants *----------------------------------------------------------------------------------*/ -#define HODIRAC_BETA (214748368) /* 0.2f in Q30 */ -#define HODIRAC_FAC1 (951579008) /* 1.772454f in Q29 */ -#define HODIRAC_FAC2 (549393984) /* 1.023326f in Q29 */ -#define HODIRAC_FAC3 (317192992) /* 0.590818f in Q29 */ +#define HODIRAC_BETA (214748368) /* 0.2f in Q30 */ +#define HODIRAC_FAC1 (951579008) /* 1.772454f in Q29 */ +#define HODIRAC_FAC2 (549393984) /* 1.023326f in Q29 */ +#define HODIRAC_FAC3 (317192992) /* 0.590818f in Q29 */ /*----------------------------------------------------------------------------------* * Amplitude Panning (EFAP, VBAP) constants @@ -1704,9 +1704,9 @@ typedef enum #define HRTF_NUM_BINS 60 #define REVERB_PREDELAY_MAX 20 /* Max input delay for reverb module */ #define GAIN_LFE 1.88364911f /* Gain applied to LFE during renderering */ -#define GAIN_LFE_WORD32 2022552831 /* Gain applied to LFE during renderering */ +#define GAIN_LFE_WORD32 2022552831 // Q30 /* Gain applied to LFE during renderering */ #ifdef IVAS_FLOAT_FIXED -#define GAIN_LFE_FX 30862 /*Q.14 Gain applied to LFE during renderering */ +#define GAIN_LFE_FX 30862 // Q14 /* Gain applied to LFE during renderering */ #endif // IVAS_FLOAT_FIXED #define LOW_BIT_RATE_BINAURAL_EQ_BINS 17 /* Number of bins in an EQ applied at low bit rates in binauralization */ #define LOW_BIT_RATE_BINAURAL_EQ_OFFSET 14 /* Offset of bins where the low-bit-rate EQ starts*/ @@ -1755,11 +1755,11 @@ typedef enum #define LR_IAC_LENGTH_NR_FC ( RV_LENGTH_NR_FC ) -#define DEG_360_IN_Q22 (360 << Q22) -#define DEG_180_IN_Q22 (180 << Q22) -#define DEG_90_IN_Q22 (90 << Q22) -#define ONE_BY_360_Q31 ( 5965232 ) -#define ONE_BY_180_Q31 ( 11930465 ) +#define DEG_360_IN_Q22 ( 360 << Q22 ) // Q22 +#define DEG_180_IN_Q22 ( 180 << Q22 ) // Q22 +#define DEG_90_IN_Q22 ( 90 << Q22 ) // Q22 +#define ONE_BY_360_Q31 ( 5965232 ) // Q31 +#define ONE_BY_180_Q31 ( 11930465 ) // Q31 /* ----- Enums - TD Renderer ----- */ diff --git a/lib_com/ivas_cov_smooth.c b/lib_com/ivas_cov_smooth.c index d03d548b6..5f9262803 100644 --- a/lib_com/ivas_cov_smooth.c +++ b/lib_com/ivas_cov_smooth.c @@ -52,8 +52,8 @@ * To calculate the update factor *-----------------------------------------------------------------------------------------*/ -static Word32 ivas_calculate_update_factor_fx( - Word32 *p_bin_to_band, +static Word32 ivas_calculate_update_factor_fx( // o: Q22 + Word32 *p_bin_to_band, // i: Q22 Word16 active_bins ) { Word32 update_factor_temp = 0; @@ -65,7 +65,7 @@ static Word32 ivas_calculate_update_factor_fx( update_factor_temp = L_add( update_factor_temp, p_bin_to_band[k] ); // Q22 } - return update_factor_temp; + return update_factor_temp; // Q22 } #else /*-----------------------------------------------------------------------------------------* @@ -99,8 +99,8 @@ static float ivas_calculate_update_factor( *-----------------------------------------------------------------------------------------*/ static void ivas_calculate_smoothning_factor_fx( - Word32 *Smoothing_factor, - Word32 update_factor, + Word32 *Smoothing_factor, // o: Q31 + Word32 update_factor, // i: Q22 const Word16 min_pool_size, const Word32 max_update_rate, const COV_SMOOTHING_TYPE smooth_mode, @@ -112,7 +112,7 @@ static void ivas_calculate_smoothning_factor_fx( move32(); move16(); - tmp = BASOP_Util_Divide3232_Scale( update_factor, L_shl( L_deposit_l( min_pool_size ), Q22 ), &exp_diff ); // (Q15 - exp_diff) + tmp = BASOP_Util_Divide3232_Scale( update_factor, L_shl( L_deposit_l( min_pool_size ), Q22 ), &exp_diff ); // Q(31 - exp_diff) *Smoothing_factor = L_shl_sat( L_deposit_l( tmp ), add( Q16, exp_diff ) ); // Q31 move32(); @@ -120,12 +120,12 @@ static void ivas_calculate_smoothning_factor_fx( { IF( LT_32( ivas_total_brate, IVAS_24k4 ) ) { - smooth_fact = (Word32) ( ONE_IN_Q30 ); + smooth_fact = (Word32) ( ONE_IN_Q30 ); // 0.5 in Q31 move32(); } ELSE { - smooth_fact = (Word32) ( 1610612735 ); + smooth_fact = (Word32) ( 1610612735 ); // 0.75 in Q31 move32(); } @@ -138,7 +138,7 @@ static void ivas_calculate_smoothning_factor_fx( IF( GT_32( *Smoothing_factor, max_update_rate ) ) // Q31 { - *Smoothing_factor = max_update_rate; + *Smoothing_factor = max_update_rate; // Q31 move32(); } @@ -195,7 +195,7 @@ static void ivas_calculate_smoothning_factor( static void ivas_set_up_cov_smoothing_fx( ivas_cov_smooth_state_t *hCovState, ivas_filterbank_t *pFb, - const Word32 max_update_rate, + const Word32 max_update_rate, // i: Q31 const Word16 min_pool_size, const COV_SMOOTHING_TYPE smooth_mode, /* i : flag multichannel vs SPAR */ const Word32 ivas_total_brate ) @@ -209,7 +209,7 @@ static void ivas_set_up_cov_smoothing_fx( { Word16 active_bins = pFb->fb_bin_to_band.pFb_active_bins_per_band[j]; move16(); - update_factor = ivas_calculate_update_factor_fx( pFb->fb_bin_to_band.pFb_bin_to_band_fx[j], active_bins ); + update_factor = ivas_calculate_update_factor_fx( pFb->fb_bin_to_band.pFb_bin_to_band_fx[j], active_bins ); // Q22 ivas_calculate_smoothning_factor_fx( &hCovState->pSmoothing_factor_fx[j], update_factor, min_pool_size, max_update_rate, smooth_mode, ivas_total_brate, j ); } } @@ -217,10 +217,10 @@ static void ivas_set_up_cov_smoothing_fx( { FOR( j = 0; j < pFb->filterbank_num_bands; j++ ) { - Word32 *p_bin_to_band = pFb->fb_bin_to_band.pp_short_stride_bin_to_band_fx[j]; + Word32 *p_bin_to_band = pFb->fb_bin_to_band.pp_short_stride_bin_to_band_fx[j]; // Q22 Word16 active_bins = pFb->fb_bin_to_band.p_short_stride_num_bins_per_band[j]; move16(); - update_factor = ivas_calculate_update_factor_fx( p_bin_to_band, active_bins ); + update_factor = ivas_calculate_update_factor_fx( p_bin_to_band, active_bins ); // Q22 ivas_calculate_smoothning_factor_fx( &hCovState->pSmoothing_factor_fx[j], update_factor, min_pool_size, max_update_rate, smooth_mode, ivas_total_brate, j ); } } @@ -471,8 +471,8 @@ void ivas_spar_covar_smooth_enc_close( static void ivas_compute_smooth_cov_fx( ivas_cov_smooth_state_t *hCovState, ivas_filterbank_t *pFb, - Word32 *pCov_buf[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], - Word32 *pPrior_cov_buf[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + Word32 *pCov_buf[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], // i/o: Q(q_cov[i][j]) + Word32 *pPrior_cov_buf[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], // i: hCovState->q_cov_real_per_band[i][j][k] const Word32 fac, const Word16 start_band, const Word16 end_band, @@ -501,15 +501,15 @@ static void ivas_compute_smooth_cov_fx( { FOR( j = 0; j < num_ch; j++ ) { - set16_fx( hCovState->q_cov_real_per_band[i][j], q_cov[i][j], sub( end_band, start_band ) ); + set16_fx( hCovState->q_cov_real_per_band[i][j], q_cov[i][j], sub( end_band, start_band ) ); // assign q_cov[i][j] to hCovState->q_cov_real_per_band[i][j][k] } } FOR( i = 0; i < num_ch; i++ ) { FOR( k = start_band; k < end_band; k++ ) { - L_tmp = Mpy_32_32( hCovState->pSmoothing_factor_fx[k], fac ); // (Q31, Q31) -> Q31 - pCov_buf[i][i][k] = L_add( pCov_buf[i][i][k], L_shl( L_tmp, sub( hCovState->q_cov_real_per_band[i][i][k], Q31 ) ) ); + L_tmp = Mpy_32_32( hCovState->pSmoothing_factor_fx[k], fac ); // (Q31, Q31) -> Q31 + pCov_buf[i][i][k] = L_add( pCov_buf[i][i][k], L_shl( L_tmp, sub( hCovState->q_cov_real_per_band[i][i][k], Q31 ) ) ); // hCovState->q_cov_real_per_band[i][j][k] move32(); } } @@ -523,7 +523,7 @@ static void ivas_compute_smooth_cov_fx( { IF( EQ_16( i, j ) ) { - factor = fac; + factor = fac; // Q31 move32(); } ELSE @@ -535,25 +535,25 @@ static void ivas_compute_smooth_cov_fx( set16_fx( q_tmp, q_cov[i][j], sub( end_band, start_band ) ); FOR( k = start_band; k < non_sm_b_idx; k++ ) { - L_tmp = Mpy_32_32( hCovState->pSmoothing_factor_fx[k], pCov_buf[i][j][k] ); // (Q31, q_cov[i][j]) -> q_cov[i][j] - L_tmp1 = Mpy_32_32( L_sub( ONE_IN_Q31, hCovState->pSmoothing_factor_fx[k] ), pPrior_cov_buf[i][j][k] ); // (Q31, hCovState->q_cov_real_per_band[i][j][k]) -> hCovState->q_cov_real_per_band[i][j][k] - pCov_buf[i][j][k] = BASOP_Util_Add_Mant32Exp( L_tmp, sub( Q31, q_cov[i][j] ), L_tmp1, sub( Q31, hCovState->q_prior_cov_real_per_band[i][j][k] ), &q_tmp[k] ); + L_tmp = Mpy_32_32( hCovState->pSmoothing_factor_fx[k], pCov_buf[i][j][k] ); // (Q31, q_cov[i][j]) -> q_cov[i][j] + L_tmp1 = Mpy_32_32( L_sub( ONE_IN_Q31, hCovState->pSmoothing_factor_fx[k] ), pPrior_cov_buf[i][j][k] ); // (Q31, hCovState->q_cov_real_per_band[i][j][k]) -> hCovState->q_cov_real_per_band[i][j][k] + pCov_buf[i][j][k] = BASOP_Util_Add_Mant32Exp( L_tmp, sub( Q31, q_cov[i][j] ), L_tmp1, sub( Q31, hCovState->q_prior_cov_real_per_band[i][j][k] ), &q_tmp[k] ); // Q(31 - q_tmp[k]) move32(); - q_tmp[k] = sub( Q31, q_tmp[k] ); + q_tmp[k] = sub( Q31, q_tmp[k] ); // Q of pConv_buf[i][j][k] is now q_tmp[k] move16(); L_tmp = L_shl( Mpy_32_32( hCovState->pSmoothing_factor_fx[k], factor ), sub( q_tmp[k], Q31 ) ); // ((Q31, Q31) -> Q31) -> q_tmp[k] - pCov_buf[i][j][k] = L_add( pCov_buf[i][j][k], L_tmp ); + pCov_buf[i][j][k] = L_add( pCov_buf[i][j][k], L_tmp ); // q_tmp[k] move32(); } - Copy( q_tmp, hCovState->q_cov_real_per_band[i][j], sub( end_band, start_band ) ); + Copy( q_tmp, hCovState->q_cov_real_per_band[i][j], sub( end_band, start_band ) ); // Q of pCov_buf[i][j][k] is hCovState->q_cov_real_per_band[i][j][j] } } FOR( i = 0; i < num_ch; i++ ) { FOR( k = non_sm_b_idx; k < end_band; k++ ) { - L_tmp = Mpy_32_32( hCovState->pSmoothing_factor_fx[k], fac ); // (Q31, Q31) -> Q31 - pCov_buf[i][i][k] = L_add( pCov_buf[i][i][k], L_shl( L_tmp, sub( hCovState->q_cov_real_per_band[i][i][k], Q31 ) ) ); + L_tmp = Mpy_32_32( hCovState->pSmoothing_factor_fx[k], fac ); // (Q31, Q31) -> Q31 + pCov_buf[i][i][k] = L_add( pCov_buf[i][i][k], L_shl( L_tmp, sub( hCovState->q_cov_real_per_band[i][i][k], Q31 ) ) ); // hCovState->q_cov_real_per_band[i][j][j] move32(); } } @@ -566,7 +566,7 @@ static void ivas_compute_smooth_cov_fx( { IF( EQ_16( i, j ) ) { - factor = fac; + factor = fac; // Q31 move32(); } ELSE @@ -577,17 +577,17 @@ static void ivas_compute_smooth_cov_fx( FOR( k = start_band; k < end_band; k++ ) { - L_tmp = Mpy_32_32( hCovState->pSmoothing_factor_fx[k], pCov_buf[i][j][k] ); // (Q31, q_cov[i][j]) -> q_cov[i][j] - L_tmp1 = Mpy_32_32( L_sub( ONE_IN_Q31, hCovState->pSmoothing_factor_fx[k] ), pPrior_cov_buf[i][j][k] ); // (Q31, hCovState->q_cov_real_per_band[i][j][k]) -> hCovState->q_cov_real_per_band[i][j][k] - pCov_buf[i][j][k] = BASOP_Util_Add_Mant32Exp( L_tmp, sub( Q31, q_cov[i][j] ), L_tmp1, sub( Q31, hCovState->q_prior_cov_real_per_band[i][j][k] ), &q_tmp[k] ); + L_tmp = Mpy_32_32( hCovState->pSmoothing_factor_fx[k], pCov_buf[i][j][k] ); // (Q31, q_cov[i][j]) -> q_cov[i][j] + L_tmp1 = Mpy_32_32( L_sub( ONE_IN_Q31, hCovState->pSmoothing_factor_fx[k] ), pPrior_cov_buf[i][j][k] ); // (Q31, hCovState->q_cov_real_per_band[i][j][k]) -> hCovState->q_cov_real_per_band[i][j][k] + pCov_buf[i][j][k] = BASOP_Util_Add_Mant32Exp( L_tmp, sub( Q31, q_cov[i][j] ), L_tmp1, sub( Q31, hCovState->q_prior_cov_real_per_band[i][j][k] ), &q_tmp[k] ); // Q(31 - q_tmp[k]) move32(); - q_tmp[k] = sub( Q31, q_tmp[k] ); + q_tmp[k] = sub( Q31, q_tmp[k] ); // Q of pConv_buf[i][j][k] is now q_tmp[k] move16(); L_tmp = L_shl( Mpy_32_32( hCovState->pSmoothing_factor_fx[k], factor ), sub( q_tmp[k], Q31 ) ); // ((Q31, Q31) -> Q31) -> q_tmp[k] - pCov_buf[i][j][k] = L_add( pCov_buf[i][j][k], L_tmp ); + pCov_buf[i][j][k] = L_add( pCov_buf[i][j][k], L_tmp ); // q_tmp[k] move32(); } - Copy( q_tmp, hCovState->q_cov_real_per_band[i][j], sub( end_band, start_band ) ); + Copy( q_tmp, hCovState->q_cov_real_per_band[i][j], sub( end_band, start_band ) ); // Q of pCov_buf[i][j][k] is hCovState->q_cov_real_per_band[i][j][j] } } } @@ -697,9 +697,9 @@ static void ivas_compute_smooth_cov( *-----------------------------------------------------------------------------------------*/ void ivas_cov_smooth_process_fx( - ivas_cov_smooth_state_t *hCovState, /* i/o: Covariance state handle */ - Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], - ivas_filterbank_t *pFb, /* i/o: FB handle */ + ivas_cov_smooth_state_t *hCovState, /* i/o: Covariance state handle */ + Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], // Q(hCovState->q_cov_real_per_band[i][j][k]) + ivas_filterbank_t *pFb, /* i/o: FB handle */ const Word16 start_band, const Word16 end_band, const Word16 num_ch, @@ -715,7 +715,7 @@ void ivas_cov_smooth_process_fx( { FOR( j = 0; j < num_ch; j++ ) { - Copy32( &cov_real[i][j][start_band], &hCovState->pPrior_cov_real_fx[i][j][start_band], num_bands ); + Copy32( &cov_real[i][j][start_band], &hCovState->pPrior_cov_real_fx[i][j][start_band], num_bands ); // Q of hCovState->pPrior_cov_real_fx[i][j][start_band + k] will be hCovState->q_cov_real_per_band[i][j][start_band + k] FOR( k = 0; k < num_bands; k++ ) { hCovState->q_prior_cov_real_per_band[i][j][start_band + k] = hCovState->q_cov_real_per_band[i][j][start_band + k]; diff --git a/lib_com/ivas_dirac_com.c b/lib_com/ivas_dirac_com.c index f07dcd4be..8bc0f6749 100644 --- a/lib_com/ivas_dirac_com.c +++ b/lib_com/ivas_dirac_com.c @@ -240,8 +240,9 @@ ivas_error ivas_dirac_config_fx( move16(); move16(); - set_c( (Word8 *) hQMetaData->twoDirBands, (Word8) 1, hQMetaData->q_direction[0].cfg.nbands ); + set8_fx( (Word8 *) hQMetaData->twoDirBands, (Word8) 1, hQMetaData->q_direction[0].cfg.nbands ); hQMetaData->numTwoDirBands = (UWord8) hQMetaData->q_direction[0].cfg.nbands; + move16(); } } @@ -557,8 +558,9 @@ void ivas_dirac_config_bands_fx( IF( useLowerBandRes ) { Word16 step = DIRAC_LOW_BANDRES_STEP; + move16(); Word16 reduced_band; - FOR( ( band = add( enc_param_start_band, 2 ), reduced_band = add( enc_param_start_band, 1 ) ); band <= DIRAC_MAX_NBANDS; ( band = add( band, step ), reduced_band++ ) ) + FOR( ( band = enc_param_start_band + 2, reduced_band = enc_param_start_band + 1 ); band <= DIRAC_MAX_NBANDS; ( band += step, reduced_band++ ) ) { band_grouping[reduced_band] = band_grouping[band]; move16(); @@ -592,7 +594,7 @@ void ivas_dirac_config_bands_fx( } /* Limit the band range to band max */ - FOR( i = 0; i < add( nbands, 1 ); i++ ) + FOR( i = 0; i < nbands + 1; i++ ) { IF( GT_16( band_grouping[i], max_band ) ) { @@ -703,6 +705,7 @@ void ivas_get_dirac_sba_max_md_bits_fx( *bits_frame_nominal = extract_l( Mpy_32_32( sba_total_brate, ONE_BY_FRAMES_PER_SEC_Q31 ) ); move16(); *metadata_max_bits = MAX16B; /* no limit */ + move16(); } Word32 var1 = L_mult0( *metadata_max_bits, nbands ); Word16 exp = 0; @@ -1000,14 +1003,14 @@ ivas_error ivas_dirac_sba_config( #ifdef IVAS_FLOAT_FIXED void computeDirectionVectors_fixed( - Word32 *intensity_real_x, - Word32 *intensity_real_y, - Word32 *intensity_real_z, + Word32 *intensity_real_x, /* i: exp = i_e */ + Word32 *intensity_real_y, /* i: exp = i_e */ + Word32 *intensity_real_z, /* i: exp = i_e */ const Word16 enc_param_start_band, const Word16 num_frequency_bands, - Word32 *direction_vector_x, /*Q30*/ - Word32 *direction_vector_y, /*Q30*/ - Word32 *direction_vector_z, /*Q30*/ + Word32 *direction_vector_x, /* o: Q30*/ + Word32 *direction_vector_y, /* o: Q30*/ + Word32 *direction_vector_z, /* o: Q30*/ Word16 i_e /*Exponent of all the intensity buffers*/ ) { Word16 i; @@ -1071,22 +1074,22 @@ void computeDirectionVectors_fixed( *------------------------------------------------------------------------*/ void computeDirectionVectors_fx( - Word32 *intensity_real_x, - Word32 *intensity_real_y, - Word32 *intensity_real_z, + Word32 *intensity_real_x, // i: Q( i_q ) + Word32 *intensity_real_y, // i: Q( i_q ) + Word32 *intensity_real_z, // i: Q( i_q ) const Word16 enc_param_start_band, const Word16 num_frequency_bands, - Word32 *direction_vector_x, - Word32 *direction_vector_y, - Word32 *direction_vector_z, - Word16 *i_q /*input/output Q*/ + Word32 *direction_vector_x, // o: Q( i_q ) + Word32 *direction_vector_y, // o: Q( i_q ) + Word32 *direction_vector_z, // o: Q( i_q ) + Word16 *i_q /*input/output Q*/ ) { Word16 i; Word32 intensityNorm; - Word16 sq = sub( 31, sub( 2 * ( *i_q ), 31 ) ); - Word16 sq1 = sub( 2 * ( *i_q ), 31 ); + Word16 sq = sub( 31, sub( shl( *i_q, 1 ), 31 ) ); + Word16 sq1 = sub( shl( *i_q, 1 ), 31 ); Word16 exp = sq; Word16 local_i_q = sq1; Word16 min_factor = 30; @@ -1136,7 +1139,7 @@ void computeDirectionVectors_fx( IF( LE_32( intensityNorm, EPSILON_FX ) ) { intensityNorm = L_shl( 1, min_factor ); - *( direction_vector_x++ ) = L_shl( 1, min_factor ); + *( direction_vector_x++ ) = L_shl( 1, min_factor ); // Q is min_factor *( direction_vector_y++ ) = 0; *( direction_vector_z++ ) = 0; intensity_real_x++; @@ -1149,13 +1152,13 @@ void computeDirectionVectors_fx( } ELSE { - intensityNorm = ISqrt32( intensityNorm, &exp ); // Q31-exp - Word32 temp = L_shr( Mpy_32_32( *( intensity_real_x++ ), intensityNorm ), ( *i_q - exp - min_factor ) ); - *( direction_vector_x++ ) = temp; // i_q + Q31-exp -31 = i_q -exp - temp = L_shr( Mpy_32_32( *( intensity_real_y++ ), intensityNorm ), ( *i_q - exp - min_factor ) ); - *( direction_vector_y++ ) = temp; // i_q + Q31-exp -31 = i_q -exp - temp = L_shr( Mpy_32_32( *( intensity_real_z++ ), intensityNorm ), ( *i_q - exp - min_factor ) ); - *( direction_vector_z++ ) = temp; // i_q + Q31-exp-31 = i_q -exp + intensityNorm = ISqrt32( intensityNorm, &exp ); // Q31-exp + Word32 temp = L_shr( Mpy_32_32( *( intensity_real_x++ ), intensityNorm ), ( *i_q - exp - min_factor ) ); // Q is min_factor + *( direction_vector_x++ ) = temp; // i_q + Q31-exp -31 = i_q -exp + temp = L_shr( Mpy_32_32( *( intensity_real_y++ ), intensityNorm ), ( *i_q - exp - min_factor ) ); // Q is min_factor + *( direction_vector_y++ ) = temp; // i_q + Q31-exp -31 = i_q -exp + temp = L_shr( Mpy_32_32( *( intensity_real_z++ ), intensityNorm ), ( *i_q - exp - min_factor ) ); // Q is min_factor + *( direction_vector_z++ ) = temp; // i_q + Q31-exp-31 = i_q -exp move32(); move32(); @@ -1222,10 +1225,10 @@ void computeDirectionVectors( *------------------------------------------------------------------------*/ void computeDiffuseness_fx( - Word32 *buffer_intensity[DIRAC_NUM_DIMS][DIRAC_NO_COL_AVG_DIFF], - const Word32 *buffer_energy, + Word32 *buffer_intensity[DIRAC_NUM_DIMS][DIRAC_NO_COL_AVG_DIFF], // i: Q(q_factor_intensity) + const Word32 *buffer_energy, // i: Q(q_factor_energy) const Word16 num_freq_bands, - Word32 *diffuseness, + Word32 *diffuseness, // o: exp(out_exp) Word16 q_factor_intensity, Word16 q_factor_energy, Word16 *out_exp /*Ouput Q*/ @@ -1272,7 +1275,7 @@ void computeDiffuseness_fx( /* intensity_slow.^2 + intensity_slow_abs*/ FOR( j = 0; j < DIRAC_NUM_DIMS; ++j ) { - p_tmp = intensity_slow + imult1616( j, num_freq_bands ); + p_tmp = intensity_slow + j * num_freq_bands; FOR( k = 0; k < num_freq_bands; k++ ) { @@ -1282,7 +1285,8 @@ void computeDiffuseness_fx( move32(); } } - Word16 init_exp = sub( 31, sub( ( ( 2 * ( q_factor_intensity ) ) ), 31 ) ), exp; + Word16 init_exp = sub( 62, shl( q_factor_intensity, 1 ) ); // 31 - ( 2 * q_factor_intensity - 31 ) + Word16 exp; Word16 exp1 = 0, exp2; move16(); @@ -1291,6 +1295,7 @@ void computeDiffuseness_fx( FOR( i = 0; i < num_freq_bands; ++i ) { exp = init_exp; + move16(); Word32 temp = *( p_tmp++ ); move32(); tmp_1 = Sqrt32( temp, &exp ); @@ -1338,10 +1343,10 @@ void computeDiffuseness_fx( *------------------------------------------------------------------------*/ void computeDiffuseness_fixed( - Word32 *buffer_intensity[DIRAC_NUM_DIMS][DIRAC_NO_COL_AVG_DIFF], - const Word32 *buffer_energy, + Word32 *buffer_intensity[DIRAC_NUM_DIMS][DIRAC_NO_COL_AVG_DIFF], // i: Q(q_factor_intensity) + const Word32 *buffer_energy, // i: Q(q_factor_energy) const Word16 num_freq_bands, - Word32 *diffuseness, + Word32 *diffuseness, // o: exp(out_exp) Word16 *q_factor_intensity, Word16 *q_factor_energy, Word16 *q_diffuseness /*Ouput Q*/ @@ -1389,7 +1394,7 @@ void computeDiffuseness_fixed( FOR( i = 0; i < DIRAC_NO_COL_AVG_DIFF; ++i ) { /* Energy slow */ - p_tmp_c = buffer_energy + i_mult( i, num_freq_bands ); + p_tmp_c = buffer_energy + i * num_freq_bands; q_tmp = add( q_factor_energy[i], min_q_shift1 ); FOR( k = 0; k < num_freq_bands; k++ ) @@ -1418,12 +1423,12 @@ void computeDiffuseness_fixed( tmp = L_shl( p_tmp[k], min_q_shift2 ); IF( LT_16( q_intensity, q_tmp ) ) { - intensity_slow[add( i_mult( j, num_freq_bands ), k )] = L_add( intensity_slow[add( i_mult( j, num_freq_bands ), k )], L_shr( tmp, sub( q_tmp, q_intensity ) ) ); + intensity_slow[j * num_freq_bands + k] = L_add( intensity_slow[j * num_freq_bands + k], L_shr( tmp, sub( q_tmp, q_intensity ) ) ); move32(); } ELSE { - intensity_slow[add( i_mult( j, num_freq_bands ), k )] = L_add( L_shr( intensity_slow[add( i_mult( j, num_freq_bands ), k )], sub( q_intensity, q_tmp ) ), tmp ); + intensity_slow[j * num_freq_bands + k] = L_add( L_shr( intensity_slow[j * num_freq_bands + k], sub( q_intensity, q_tmp ) ), tmp ); move32(); } } @@ -1439,7 +1444,7 @@ void computeDiffuseness_fixed( /* intensity_slow.^2 + intensity_slow_abs*/ FOR( j = 0; j < DIRAC_NUM_DIMS; ++j ) { - p_tmp = intensity_slow + i_mult( j, num_freq_bands ); + p_tmp = intensity_slow + j * num_freq_bands; FOR( k = 0; k < num_freq_bands; k++ ) { @@ -1627,12 +1632,12 @@ float deindex_azimuth( } #ifdef IVAS_FLOAT_FIXED -Word32 deindex_azimuth_fx( - Word16 id_phi, /* i : index */ - const Word16 no_bits, /* i : number of bits for the spherical grid */ - const Word16 id_th, /* i : elevation index */ - const Word16 remap, /* i : remapping flag */ - const MC_LS_SETUP mc_format /* i : channel format if in MC-mode */ +Word32 deindex_azimuth_fx( /* o : output Q22 */ + Word16 id_phi, /* i : index */ + const Word16 no_bits, /* i : number of bits for the spherical grid */ + const Word16 id_th, /* i : elevation index */ + const Word16 remap, /* i : remapping flag */ + const MC_LS_SETUP mc_format /* i : channel format if in MC-mode */ ) { Word16 flag_delta; @@ -1643,12 +1648,12 @@ Word32 deindex_azimuth_fx( { IF( s_and( id_phi, 1 ) == 0 ) { - phi_hat_fx = cb_azi_chan_fx[shr( id_phi, 1 )]; + phi_hat_fx = cb_azi_chan_fx[id_phi / 2]; // Q22 move32(); } ELSE { - phi_hat_fx = L_negate( cb_azi_chan_fx[shr( add( id_phi, 1 ), 1 )] ); + phi_hat_fx = L_negate( cb_azi_chan_fx[( id_phi + 1 ) / 2] ); // Q22 } return phi_hat_fx; } @@ -1656,13 +1661,13 @@ Word32 deindex_azimuth_fx( IF( remap ) { - id_phi = add( ivas_qmetadata_dereorder_generic( id_phi ), shr( no_phi_masa[sub( no_bits, 1 )][id_th], 1 ) ); + id_phi = add( ivas_qmetadata_dereorder_generic( id_phi ), shr( no_phi_masa[no_bits - 1][id_th], 1 ) ); } - delta_phi_fx = Mpy_32_32( 1509949440, no_phi_masa_inv_fx[sub( no_bits, 1 )][id_th] ); // q = 22 + delta_phi_fx = Mpy_32_32( 1509949440, no_phi_masa_inv_fx[no_bits - 1][id_th] ); // q = 22 test(); test(); - IF( EQ_16( flag_delta, 1 ) && GT_16( no_phi_masa[sub( no_bits, 1 )][id_th], 2 ) && EQ_32( mc_format, MC_LS_SETUP_INVALID ) ) + IF( EQ_16( flag_delta, 1 ) && GT_16( no_phi_masa[no_bits - 1][id_th], 2 ) && EQ_32( mc_format, MC_LS_SETUP_INVALID ) ) { dd_fx = Mpy_32_32( delta_phi_fx, 1073741824 ); // q = 22 } @@ -1672,11 +1677,20 @@ Word32 deindex_azimuth_fx( move32(); } - id_phi = sub( id_phi, shr( no_phi_masa[sub( no_bits, 1 )][id_th], 1 ) ); - phi_hat_fx = L_add( id_phi * delta_phi_fx, dd_fx ); + id_phi = sub( id_phi, shr( no_phi_masa[no_bits - 1][id_th], 1 ) ); + phi_hat_fx = L_add( imult3216( delta_phi_fx, id_phi ), dd_fx ); IF( NE_32( mc_format, MC_LS_SETUP_INVALID ) ) { - phi_hat_fx = companding_azimuth_fx( phi_hat_fx, mc_format, ( id_th * delta_theta_masa[no_bits - 3] > MC_MASA_THR_ELEVATION ), -1 ); + Word32 a = L_shr( imult3216( delta_theta_masa_fx[no_bits - 3], id_th ), 22 ); // Q22 -> Q0 + move32(); + Word16 flag = 0; + move16(); + if ( GT_32( a, MC_MASA_THR_ELEVATION ) ) + { + flag = 1; + move16(); + } + phi_hat_fx = companding_azimuth_fx( phi_hat_fx, mc_format, flag, -1 ); } return phi_hat_fx; } @@ -1731,8 +1745,8 @@ void deindex_spherical_component( #else void deindex_spherical_component_fx( const UWord16 sph_idx, /* i : spherical index */ - Word32 *az_fx, /* o : decoded azimuth value */ - Word32 *el_fx, /* o : decoded elevation value */ + Word32 *az_fx, /* o : decoded azimuth value Q22 */ + Word32 *el_fx, /* o : decoded elevation value Q22 */ UWord16 *az_idx, /* o : azimuth index */ UWord16 *el_idx, /* o : elevation index */ const UWord16 no_bits, /* i : number of bits for the spherical grid */ @@ -2478,12 +2492,12 @@ static uint16_t deindex_sph_idx_general( } #else static UWord16 deindex_sph_idx_general_fx( - const Word16 idx_sph, /* i : spherical index */ - const Word16 no_bits, /* i : number of bits in the spherical grid*/ - Word32 *theta_dec_fx, /* o : decoded elevation value */ - Word32 *phi_dec_fx, /* o : decoded azimuth value */ - UWord16 *p_id_phi, /* o : decoded azimuth index */ - const MC_LS_SETUP mc_format /* i : channel format if in MC-mode */ + const Word16 idx_sph, /* i : spherical index */ + const Word16 no_bits, /* i : number of bits in the spherical grid */ + Word32 *theta_dec_fx, /* o : decoded elevation value Q22 */ + Word32 *phi_dec_fx, /* o : decoded azimuth value Q22 */ + UWord16 *p_id_phi, /* o : decoded azimuth index */ + const MC_LS_SETUP mc_format /* i : channel format if in MC-mode */ ) { Word16 i; @@ -2594,7 +2608,7 @@ static UWord16 deindex_sph_idx_general_fx( q_id_th = norm_l( id_th ); id_th_fx = L_shl( id_th, q_id_th ); - *theta_dec_fx = L_shl( Mpy_32_32( id_th_fx, delta_theta_masa_fx[no_bits - 3] ), sub( 31, q_id_th ) ); + *theta_dec_fx = L_shl( Mpy_32_32( id_th_fx, delta_theta_masa_fx[no_bits - 3] ), sub( 31, q_id_th ) ); // Q22 move32(); IF( GE_32( *theta_dec_fx, 90 << Q22 ) ) @@ -2610,7 +2624,7 @@ static UWord16 deindex_sph_idx_general_fx( { *theta_dec_fx *= sign_theta; - *phi_dec_fx = deindex_azimuth_fx( id_phi, no_bits, id_th, 0, mc_format ); + *phi_dec_fx = deindex_azimuth_fx( id_phi, no_bits, id_th, 0, mc_format ); // Q22 move32(); *p_id_phi = id_phi; move16(); diff --git a/lib_com/ivas_fb_mixer.c b/lib_com/ivas_fb_mixer.c index 0a45a3600..93ea0528d 100644 --- a/lib_com/ivas_fb_mixer.c +++ b/lib_com/ivas_fb_mixer.c @@ -48,12 +48,20 @@ /*------------------------------------------------------------------------------------------* * Static functions declarations *------------------------------------------------------------------------------------------*/ -static void ivas_cmult_fix( Word32 in1_re, Word32 in1_im, Word32 in2_re, Word32 in2_im, Word32 *out1_re, Word32 *out1_im ); +#ifdef IVAS_FLOAT_FIXED +static void ivas_cmult_fix( + Word32 in1_re, // i: Qx + Word32 in1_im, // i: Qx + Word32 in2_re, // i: Qx + Word32 in2_im, // i: Qx + Word32 *out1_re, // o: 2 * Qx - 31 + Word32 *out1_im // o: 2 * Qx - 31 +); static void ivas_get_active_bins_fx( const Word16 **pActive_bins, const Word16 **pActive_bins_abs, const Word16 **pStart_offset, const Word16 **pStart_offset_ab, const Word32 sampling_rate ); static void ivas_get_ld_fb_resp_fx( Word32 **ppIdeal_FRs_re_fx, Word32 **ppIdeal_FRs_im_fx, Word32 **ppNew_FRs_re_fx, Word32 **ppNew_FRs_im_fx, const Word16 *pActive_bins, const Word16 *pStart_offset, const Word16 num_bands, const Word16 delay, const Word32 sampling_rate ); static ivas_error ivas_filterbank_setup_fx( IVAS_FB_MIXER_HANDLE hFbMixer, const Word32 sampling_rate, Word16 *index ); static ivas_error ivas_fb_mixer_get_window_fx( const Word16 fade_len, const Word32 sampling_rate, const Word16 **pWindow ); - +#endif #ifdef IVAS_FLOAT_FIXED /*-----------------------------------------------------------------------------------------* @@ -643,10 +651,10 @@ void ivas_fb_mixer_pcm_ingest( } #else void ivas_fb_mixer_pcm_ingest_fx( - IVAS_FB_MIXER_HANDLE hFbMixer, /* i/o: FB mixer handle */ + IVAS_FB_MIXER_HANDLE hFbMixer, /* i/o: FB mixer handle */ Word32 *pcm_in[], /* i : input audio channels Qq_data_fix[] */ Word32 **ppOut_pcm, /* o : output audio channels Qq_ppOut_pcm[] */ - const Word16 frame_len, /* i : frame length */ + const Word16 frame_len, /* i : frame length */ const Word16 HOA_md_ind[IVAS_SPAR_MAX_CH], Word16 q_data_fix, Word16 *q_ppOut_pcm ) @@ -703,7 +711,7 @@ void ivas_fb_mixer_pcm_ingest_fx( FOR( i = 0; i < num_chs_ingest; i++ ) { Word16 q_shift = sub( L_norm_arr( ppOut_pcm[fb_cfg->remix_order[i]], shl( frame_len, 1 ) ), guard_bits ); - Scale_sig32( ppOut_pcm[fb_cfg->remix_order[i]], shl( frame_len, 1 ), q_shift ); + Scale_sig32( ppOut_pcm[fb_cfg->remix_order[i]], shl( frame_len, 1 ), q_shift ); // Qq_ppOut_pcm -> Qq_ppOut_pcm + q_shift q_ppOut_pcm[fb_cfg->remix_order[i]] = add( q_ppOut_pcm[fb_cfg->remix_order[i]], q_shift ); move16(); @@ -769,7 +777,7 @@ void ivas_fb_mixer_update_prior_input_fx( #ifdef IVAS_FLOAT_FIXED void ivas_fb_mixer_get_windowed_fr_fx( IVAS_FB_MIXER_HANDLE hFbMixer, /* i/o: FB mixer handle */ - Word32 *pcm_in_fx[], + Word32 *pcm_in_fx[], // i: Qx Word32 *frame_f_real_fx[], Word32 *frame_f_imag_fx[], const Word16 length, /* i : number of new samples in time slot */ @@ -791,27 +799,27 @@ void ivas_fb_mixer_get_windowed_fr_fx( FOR( ch_idx = 0; ch_idx < nchan_fb_in; ch_idx++ ) { - Copy32( &hFbMixer->ppFilterbank_prior_input_fx[ch_idx][offset + hFbMixer->fb_cfg->windowed_fr_offset], &fr_in_block_fx[offset], n_old_samples - offset ); - Copy32( pcm_in_fx[ch_idx], &fr_in_block_fx[n_old_samples], n_new_samples ); + Copy32( &hFbMixer->ppFilterbank_prior_input_fx[ch_idx][offset + hFbMixer->fb_cfg->windowed_fr_offset], &fr_in_block_fx[offset], sub( n_old_samples, offset ) ); // Qx + Copy32( pcm_in_fx[ch_idx], &fr_in_block_fx[n_old_samples], n_new_samples ); // Qx win_ptr_fx = hFbMixer->pAna_window_fx; /*Q15*/ FOR( j = offset; j < sub( shl( mdft_len, 1 ), length ); j++ ) { - fr_in_block_fx[j] = Mpy_32_16_1( fr_in_block_fx[j], ( *( win_ptr_fx++ ) ) ); - move16(); + fr_in_block_fx[j] = Mpy_32_16_1( fr_in_block_fx[j], ( *( win_ptr_fx++ ) ) ); // Qx + 15 - 15 = Qx + move32(); } FOR( j = rev_offset; j < shl( mdft_len, 1 ); j++ ) { - fr_in_block_fx[j] = Mpy_32_16_1( fr_in_block_fx[j], ( *( --win_ptr_fx ) ) ); - move16(); + fr_in_block_fx[j] = Mpy_32_16_1( fr_in_block_fx[j], ( *( --win_ptr_fx ) ) ); // Qx + 15 - 15 = Qx + move32(); } FOR( Word16 i = 0; i < shl( mdft_len, 1 ); i++ ) { - fr_in_block_fx[i] = L_shr( fr_in_block_fx[i], gb ); - move16(); + fr_in_block_fx[i] = L_shr( fr_in_block_fx[i], gb ); // Qx - gb + move32(); } ivas_mdft_fx( fr_in_block_fx, frame_f_real_fx[ch_idx], frame_f_imag_fx[ch_idx], shl( mdft_len, 1 ), mdft_len ); @@ -875,9 +883,9 @@ void ivas_fb_mixer_get_windowed_fr( #ifdef IVAS_FLOAT_FIXED void ivas_fb_mixer_cross_fading_fx( IVAS_FB_MIXER_HANDLE hFbMixer, - Word32 **ppOut_pcm_fx, - Word32 *pMdft_out_old_fx, - Word32 *pMdft_out_new_fx, + Word32 **ppOut_pcm_fx, // o: Qx + Word32 *pMdft_out_old_fx, // i: Qx + Word32 *pMdft_out_new_fx, // i: Qx const Word16 ch, const Word16 frame_len, const Word16 cf_offset ) @@ -893,19 +901,19 @@ void ivas_fb_mixer_cross_fading_fx( FOR( k = 0; k < fade_start_offset; k++ ) { - ppOut_pcm_fx[ch][k] = pMdft_out_old_fx[k + cf_offset]; + ppOut_pcm_fx[ch][k] = pMdft_out_old_fx[k + cf_offset]; // Qx move32(); } FOR( k = fade_start_offset; k < fade_end_offset; k++ ) { - ppOut_pcm_fx[ch][k] = L_add( Mpy_32_16_1( pMdft_out_new_fx[k + cf_offset], hFbMixer->pFilterbank_cross_fade_fx[k - fade_start_offset] ), Mpy_32_16_1( pMdft_out_old_fx[k + cf_offset], sub( 32767, hFbMixer->pFilterbank_cross_fade_fx[k - fade_start_offset] ) ) ); + ppOut_pcm_fx[ch][k] = L_add( Mpy_32_16_1( pMdft_out_new_fx[k + cf_offset], hFbMixer->pFilterbank_cross_fade_fx[k - fade_start_offset] ), Mpy_32_16_1( pMdft_out_old_fx[k + cf_offset], sub( 32767, hFbMixer->pFilterbank_cross_fade_fx[k - fade_start_offset] ) ) ); // Qx + Q15 - 15 = Qx move32(); } FOR( k = fade_end_offset; k < frame_len; k++ ) { - ppOut_pcm_fx[ch][k] = pMdft_out_new_fx[k + cf_offset]; + ppOut_pcm_fx[ch][k] = pMdft_out_new_fx[k + cf_offset]; // Qx move32(); } } @@ -916,7 +924,7 @@ void ivas_fb_mixer_cross_fading_fx( FOR( k = 0; k < frame_len; k++ ) { - ppOut_pcm_fx[ch][k] = pMdft_out_new_fx[k + cf_offset]; + ppOut_pcm_fx[ch][k] = pMdft_out_new_fx[k + cf_offset]; // Qx move32(); } } @@ -931,7 +939,14 @@ void ivas_fb_mixer_cross_fading_fx( * Filter bank process *-----------------------------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED -void ivas_cmult_fix( Word32 in1_re, Word32 in1_im, Word32 in2_re, Word32 in2_im, Word32 *out1_re, Word32 *out1_im ) +void ivas_cmult_fix( + Word32 in1_re, // i: Qx + Word32 in1_im, // i: Qx + Word32 in2_re, // i: Qx + Word32 in2_im, // i: Qx + Word32 *out1_re, // o: 2 * Qx - 31 + Word32 *out1_im // o: 2 * Qx - 31 +) { *out1_re = L_sub_sat( Mpy_32_32( in1_re, in2_re ), Mpy_32_32( in1_im, in2_im ) ); move32(); @@ -942,11 +957,11 @@ void ivas_cmult_fix( Word32 in1_re, Word32 in1_im, Word32 in2_re, Word32 in2_im, void ivas_fb_mixer_process_fx( IVAS_FB_MIXER_HANDLE hFbMixer, /* i/o: FB mixer handle */ Word32 ***mixer_mat_fx, /* i : mixer matrix */ - Word16 *q_mixer_mat_fx, /* i : mixer matrix */ + Word16 *q_mixer_mat_fx, /* i : mixer matrix Q-factor */ Word32 **ppOut_pcm_fx, /* o : output audio channels */ - Word16 *q_ppOut_pcm_fx, /*ppOut_pcm_fx resultant q*/ + Word16 *q_ppOut_pcm_fx, /* o : output audio channels Q-factor */ const Word16 frame_len, /* i : frame length in samples */ - Word16 in_out_mixer_map[IVAS_MAX_FB_MIXER_OUT_CH][IVAS_MAX_SPAR_FB_MIXER_IN_CH] /* i/o: mixing mapping */ + Word16 in_out_mixer_map[IVAS_MAX_FB_MIXER_OUT_CH][IVAS_MAX_SPAR_FB_MIXER_IN_CH] /* i/o: mixing mapping */ ) { ivas_filterbank_t *pFb = hFbMixer->pFb; @@ -984,8 +999,8 @@ void ivas_fb_mixer_process_fx( Word32 filterbank_mixer_bins_re_fx[L_FRAME48k]; Word32 filterbank_mixer_bins_im_fx[L_FRAME48k]; - Word32 *pFb_inFR_re_fx = hFbMixer->ppFilterbank_inFR_re_fx[j]; - Word32 *pFb_inFR_im_fx = hFbMixer->ppFilterbank_inFR_im_fx[j]; + Word32 *pFb_inFR_re_fx = hFbMixer->ppFilterbank_inFR_re_fx[j]; // Q(hFbMixer->q_ppFilterbank_inFR_re_fx) + Word32 *pFb_inFR_im_fx = hFbMixer->ppFilterbank_inFR_im_fx[j]; // Q(hFbMixer->q_ppFilterbank_inFR_im_fx) set_zero_fx( filterbank_mixer_bins_re_fx, frame_len ); set_zero_fx( filterbank_mixer_bins_im_fx, frame_len ); @@ -998,23 +1013,23 @@ void ivas_fb_mixer_process_fx( move16(); Word16 num_bins = pFb->fb_consts.pFilterbank_bins_per_band[i]; move16(); - Word32 mixer_const_fx = hFbMixer->prior_mixer_fx[ch][j][i]; + Word32 mixer_const_fx = hFbMixer->prior_mixer_fx[ch][j][i]; // Q(hFbMixer->q_prior_mixer_fx) move32(); - pFilterbank_bin_to_band_re_fx = pFb->fb_consts.ppFilterbank_FRs_fx[0][i]; - pFilterbank_bin_to_band_im_fx = pFb->fb_consts.ppFilterbank_FRs_fx[1][i]; + pFilterbank_bin_to_band_re_fx = pFb->fb_consts.ppFilterbank_FRs_fx[0][i]; // Q30 + pFilterbank_bin_to_band_im_fx = pFb->fb_consts.ppFilterbank_FRs_fx[1][i]; // Q30 FOR( k = start_offset; k < num_bins + start_offset; k++ ) { - filterbank_mixer_bins_re_fx[k] = L_add_sat( filterbank_mixer_bins_re_fx[k], L_shr( Mpy_32_32( *pFilterbank_bin_to_band_re_fx, mixer_const_fx ), total_guard ) ); + filterbank_mixer_bins_re_fx[k] = L_add_sat( filterbank_mixer_bins_re_fx[k], L_shr( Mpy_32_32( *pFilterbank_bin_to_band_re_fx, mixer_const_fx ), total_guard ) ); // Q30 + hFbMixer->q_prior_mixer_fx - 31 - total_guard move32(); - filterbank_mixer_bins_im_fx[k] = L_add_sat( filterbank_mixer_bins_im_fx[k], L_shr( Mpy_32_32( *pFilterbank_bin_to_band_im_fx, mixer_const_fx ), total_guard ) ); + filterbank_mixer_bins_im_fx[k] = L_add_sat( filterbank_mixer_bins_im_fx[k], L_shr( Mpy_32_32( *pFilterbank_bin_to_band_im_fx, mixer_const_fx ), total_guard ) ); // Q30 + hFbMixer->q_prior_mixer_fx - 31 - total_guard move32(); /*filterbank_mixer_bins_im_fx q 30 */ /*mixer_const_fx q q_ppOut_pcm_fx */ pFilterbank_bin_to_band_re_fx++; pFilterbank_bin_to_band_im_fx++; } - hFbMixer->prior_mixer_fx[ch][j][i] = mixer_mat_fx[ch][j][i]; + hFbMixer->prior_mixer_fx[ch][j][i] = mixer_mat_fx[ch][j][i]; // Q(q_mixer_mat_fx) move32(); } Word16 res_q = 0; @@ -1029,21 +1044,21 @@ void ivas_fb_mixer_process_fx( Word16 q_check = s_min( q_pOut_fr_fx, res_q ); IF( NE_16( q_check, q_pOut_fr_fx ) ) { - pOut_fr_re_fx[k] = L_shr( pOut_fr_re_fx[k], sub( q_pOut_fr_fx, q_check ) ); + pOut_fr_re_fx[k] = L_shr( pOut_fr_re_fx[k], sub( q_pOut_fr_fx, q_check ) ); // q_pOut_fr_fx -> q_check move32(); - pOut_fr_im_fx[k] = L_shr( pOut_fr_im_fx[k], sub( q_pOut_fr_fx, q_check ) ); + pOut_fr_im_fx[k] = L_shr( pOut_fr_im_fx[k], sub( q_pOut_fr_fx, q_check ) ); // q_pOut_fr_fx -> q_check move32(); } IF( NE_16( q_check, res_q ) ) { - temp_out_re_fx = L_shr( temp_out_re_fx, sub( res_q, q_check ) ); - temp_out_im_fx = L_shr( temp_out_im_fx, sub( res_q, q_check ) ); + temp_out_re_fx = L_shr( temp_out_re_fx, sub( res_q, q_check ) ); // res_q -> q_check + temp_out_im_fx = L_shr( temp_out_im_fx, sub( res_q, q_check ) ); // res_q -> q_check } res_q = q_check; move16(); - pOut_fr_re_fx[k] = L_add_sat( pOut_fr_re_fx[k], temp_out_re_fx ); + pOut_fr_re_fx[k] = L_add_sat( pOut_fr_re_fx[k], temp_out_re_fx ); // res_q move32(); - pOut_fr_im_fx[k] = L_add_sat( pOut_fr_im_fx[k], temp_out_im_fx ); + pOut_fr_im_fx[k] = L_add_sat( pOut_fr_im_fx[k], temp_out_im_fx ); // res_q move32(); } q_pOut_fr_fx = res_q; @@ -1243,8 +1258,8 @@ static Word16 ivas_calculate_abs_fr_fx( FOR( i = 0; i < bands; i++ ) { - const Word32 *long_mdft_ptr_re_fx = pFb->fb_consts.ppFilterbank_FRs_fx[0][i]; - const Word32 *long_mdft_ptr_im_fx = pFb->fb_consts.ppFilterbank_FRs_fx[1][i]; + const Word32 *long_mdft_ptr_re_fx = pFb->fb_consts.ppFilterbank_FRs_fx[0][i]; // Q30 + const Word32 *long_mdft_ptr_im_fx = pFb->fb_consts.ppFilterbank_FRs_fx[1][i]; // Q30 Word16 start_offset = pFb->fb_consts.pFilterbank_bins_start_offset[i]; move16(); @@ -1286,24 +1301,24 @@ static Word16 ivas_calculate_abs_fr_fx( Word16 sq_abs_e; // Word32 real = L_shr( *long_mdft_ptr_re_fx, 3 ); // Q27 - Word32 real = *long_mdft_ptr_re_fx; // Q31 + Word32 real = *long_mdft_ptr_re_fx; // Q30 move32(); // Word32 imag = L_shr( *long_mdft_ptr_im_fx, 3 ); // Q27 - Word32 imag = *long_mdft_ptr_im_fx; // Q31 + Word32 imag = *long_mdft_ptr_im_fx; // Q30 Word16 real_exp, imag_exp; move32(); Word32 real_sq, imag_sq; - real_sq = Mpy_32_32( real, real ); + real_sq = Mpy_32_32( real, real ); // Q30 + Q30 - 31 = Q29 real_exp = 2; move32(); - imag_sq = Mpy_32_32( imag, imag ); + imag_sq = Mpy_32_32( imag, imag ); // Q30 + Q30 - 31 = Q29 imag_exp = 2; move32(); - sq_abs_fx = BASOP_Util_Add_Mant32Exp( real_sq, real_exp, imag_sq, imag_exp, &sq_abs_e ); // Q22 + sq_abs_fx = BASOP_Util_Add_Mant32Exp( real_sq, real_exp, imag_sq, imag_exp, &sq_abs_e ); // Q(31 - sq_abs_e) long_mdft_ptr_re_fx++; long_mdft_ptr_im_fx++; @@ -1311,6 +1326,8 @@ static Word16 ivas_calculate_abs_fr_fx( /* accumulate bin energies within a short stride bin */ short_stride_nrg_fx = L_add( short_stride_nrg_fx, L_shl( sq_abs_fx, sub( Q22, sub( Q31, sq_abs_e ) ) ) ); + short_stride_nrg_fx = L_add( short_stride_nrg_fx, L_shl( sq_abs_fx, sub( Q22, sub( Q31, sq_abs_e ) ) ) ); // Q(31 - sq_abs_e) -> Q22 + move32(); IF( !( ( j + 1 ) % num_bins_per_short_stride_bin ) ) { @@ -1328,8 +1345,8 @@ static Word16 ivas_calculate_abs_fr_fx( IF( !( ( j + 1 ) % num_bins_per_cldfb_band ) ) { Word32 temp = Sqrt32( cldfb_nrg_fx, &cldfb_nrg_e ); - temp = L_shl( temp, sub( cldfb_nrg_e, Q9 ) ); // Q22 - pFb->fb_bin_to_band.pp_cldfb_weights_per_spar_band_fx[j / num_bins_per_cldfb_band][i] = temp; + temp = L_shl( temp, sub( cldfb_nrg_e, Q9 ) ); // Q22 + pFb->fb_bin_to_band.pp_cldfb_weights_per_spar_band_fx[j / num_bins_per_cldfb_band][i] = temp; // Q22 move32(); cldfb_nrg_fx = 0; move32(); @@ -1344,7 +1361,7 @@ static Word16 ivas_calculate_abs_fr_fx( tmp = BASOP_Util_Divide3232_Scale( short_stride_pow_spec_fx[j], short_stride_max_per_spar_band_fx, &exp_diff ); short_stride_pow_spec_fx[j] = L_shl( L_deposit_l( tmp ), add( Q7, exp_diff ) ); // Q22 move32(); - short_stride_pow_spec_fx[j] = L_max( L_sub( short_stride_pow_spec_fx[j], 1258291 ), 0 ); // 0.3f * ONE_IN_Q22c + short_stride_pow_spec_fx[j] = L_max( L_sub( short_stride_pow_spec_fx[j], 1258291 ), 0 ); // 0.3f * ONE_IN_Q22 move32(); tmp = BASOP_Util_Divide3232_Scale( short_stride_pow_spec_fx[j], 2936012, &exp_diff ); // 0.7f * ONE_IN_Q22 short_stride_pow_spec_fx[j] = L_shl( L_deposit_l( tmp ), add( Q7, exp_diff ) ); // Q22 @@ -1360,12 +1377,12 @@ static Word16 ivas_calculate_abs_fr_fx( pFb->fb_bin_to_band.p_short_stride_start_bin_per_band[i] = j; move16(); - pFb->fb_bin_to_band.pp_short_stride_bin_to_band_fx[i] = &pFb->fb_bin_to_band.p_short_stride_bin_to_band_fx[idx_short_stride_bin_to_band]; + pFb->fb_bin_to_band.pp_short_stride_bin_to_band_fx[i] = &pFb->fb_bin_to_band.p_short_stride_bin_to_band_fx[idx_short_stride_bin_to_band]; // Q22 index[i] = idx_short_stride_bin_to_band; move16(); } - pFb->fb_bin_to_band.p_short_stride_bin_to_band_fx[idx_short_stride_bin_to_band] = short_stride_pow_spec_fx[j]; + pFb->fb_bin_to_band.p_short_stride_bin_to_band_fx[idx_short_stride_bin_to_band] = short_stride_pow_spec_fx[j]; // Q22 move32(); idx_short_stride_bin_to_band = add( idx_short_stride_bin_to_band, 1 ); @@ -1390,18 +1407,20 @@ static Word16 ivas_calculate_abs_fr_fx( FOR( i = 0; i < bands; i++ ) { - sum_over_spar_bands_fx = L_add( sum_over_spar_bands_fx, pFb->fb_bin_to_band.pp_cldfb_weights_per_spar_band_fx[j][i] ); + sum_over_spar_bands_fx = L_add( sum_over_spar_bands_fx, pFb->fb_bin_to_band.pp_cldfb_weights_per_spar_band_fx[j][i] ); // Q22 + move32(); IF( pFb->fb_bin_to_band.pp_cldfb_weights_per_spar_band_fx[j][i] > max_spar_band_contribution_fx ) { - max_spar_band_contribution_fx = pFb->fb_bin_to_band.pp_cldfb_weights_per_spar_band_fx[j][i]; + max_spar_band_contribution_fx = pFb->fb_bin_to_band.pp_cldfb_weights_per_spar_band_fx[j][i]; // Q22 move32(); pFb->fb_bin_to_band.p_cldfb_map_to_spar_band[j] = i; move16(); } } - sum_over_spar_bands_fx = L_max( sum_over_spar_bands_fx, EPSILON_FX ); + sum_over_spar_bands_fx = L_max( sum_over_spar_bands_fx, EPSILON_FX ); // Q22 + move32(); FOR( i = 0; i < bands; i++ ) { @@ -1435,9 +1454,9 @@ static Word16 ivas_calculate_abs_fr_fx( /*Commented logic is for calculating number of active bands, can be removed if not needed */ FOR( i = 0; i < bands; i++ ) { - const Word32 *pFilterbank_bin_to_band_re_fx = pFb->fb_consts.ppFilterbank_FRs_fx[0][i]; + const Word32 *pFilterbank_bin_to_band_re_fx = pFb->fb_consts.ppFilterbank_FRs_fx[0][i]; // Q30 move32(); - const Word32 *pFilterbank_bin_to_band_im_fx = pFb->fb_consts.ppFilterbank_FRs_fx[1][i]; + const Word32 *pFilterbank_bin_to_band_im_fx = pFb->fb_consts.ppFilterbank_FRs_fx[1][i]; // Q30 move32(); Word16 start_offset = pFb->fb_consts.pFilterbank_bins_start_offset[i]; @@ -1459,11 +1478,11 @@ static Word16 ivas_calculate_abs_fr_fx( Word16 exp_diff = 0; move16(); Word32 real = L_shr( *pFilterbank_bin_to_band_re_fx, 3 ); // Q27 - Word32 imag = L_shr( *pFilterbank_bin_to_band_im_fx, 3 ); + Word32 imag = L_shr( *pFilterbank_bin_to_band_im_fx, 3 ); // Q27 Word32 real_sq, imag_sq; - real_sq = Mpy_32_32( real, real ); - imag_sq = Mpy_32_32( imag, imag ); + real_sq = Mpy_32_32( real, real ); // Q27 + Q27 - 31 = Q23 + imag_sq = Mpy_32_32( imag, imag ); // Q27 + Q27 - 31 = Q23 temp_fx = L_add( L_shr( real_sq, 1 ), L_shr( imag_sq, 1 ) ); // Q22 @@ -1476,7 +1495,8 @@ static Word16 ivas_calculate_abs_fr_fx( pFilterbank_bin_to_band_re_fx++; pFilterbank_bin_to_band_im_fx++; - temp_fx = L_sub( temp_fx, 1258291 ); + temp_fx = L_sub( temp_fx, 1258291 ); // 0.3 in Q22 + move32(); if ( temp_fx < 0 ) { @@ -1488,13 +1508,13 @@ static Word16 ivas_calculate_abs_fr_fx( test(); IF( LT_16( j, add( abs_active_bins, abs_start_offset ) ) && GE_16( j, abs_start_offset ) && NE_16( alloc_fb_resp, -1 ) ) { - pFb->fb_bin_to_band.pFb_bin_to_band_fx[i][idx] = temp_fx; + pFb->fb_bin_to_band.pFb_bin_to_band_fx[i][idx] = temp_fx; // Q22 move32(); idx = add( idx, 1 ); } - ppFilterbank_FRs_s_fx[j] = L_add( ppFilterbank_FRs_s_fx[j], temp_fx ); + ppFilterbank_FRs_s_fx[j] = L_add( ppFilterbank_FRs_s_fx[j], temp_fx ); // Q22 move32(); } } @@ -1503,7 +1523,7 @@ static Word16 ivas_calculate_abs_fr_fx( { if ( ppFilterbank_FRs_s_fx[i] < 0 ) { - ppFilterbank_FRs_s_fx[i] = 419430; + ppFilterbank_FRs_s_fx[i] = 419430; // 0.1 in Q22 move32(); } } @@ -1710,8 +1730,8 @@ static ivas_error ivas_filterbank_setup_fx( FOR( j = 0; j < pFb->filterbank_num_bands; j++ ) { - pFb->fb_consts.ppFilterbank_FRs_fx[0][j] = &pAll_fb_fr_fx[0][offset]; - pFb->fb_consts.ppFilterbank_FRs_fx[1][j] = &pAll_fb_fr_fx[1][offset]; + pFb->fb_consts.ppFilterbank_FRs_fx[0][j] = &pAll_fb_fr_fx[0][offset]; // Q30 + pFb->fb_consts.ppFilterbank_FRs_fx[1][j] = &pAll_fb_fr_fx[1][offset]; // Q30 offset = add( offset, pFb->fb_consts.pFilterbank_bins_per_band[j] ); } @@ -1744,13 +1764,13 @@ static ivas_error ivas_filterbank_setup_fx( IF( j < start_diff_band_non48k ) { - pFb->fb_consts.ppFilterbank_FRs_fx[0][j] = &pAll_fb_fr_fx[0][offset]; - pFb->fb_consts.ppFilterbank_FRs_fx[1][j] = &pAll_fb_fr_fx[1][offset]; + pFb->fb_consts.ppFilterbank_FRs_fx[0][j] = &pAll_fb_fr_fx[0][offset]; // Q30 + pFb->fb_consts.ppFilterbank_FRs_fx[1][j] = &pAll_fb_fr_fx[1][offset]; // Q30 } ELSE { - Copy32( &pAll_fb_fr_fx[0][offset], pFb->fb_consts.ppFilterbank_FRs_non48k_fx[0][j], num_active_bins ); - Copy32( &pAll_fb_fr_fx[1][offset], pFb->fb_consts.ppFilterbank_FRs_non48k_fx[1][j], num_active_bins ); + Copy32( &pAll_fb_fr_fx[0][offset], pFb->fb_consts.ppFilterbank_FRs_non48k_fx[0][j], num_active_bins ); // Q30 + Copy32( &pAll_fb_fr_fx[1][offset], pFb->fb_consts.ppFilterbank_FRs_non48k_fx[1][j], num_active_bins ); // Q30 } offset = add( offset, pAll_bins_per_band_48k[j] ); @@ -1759,8 +1779,8 @@ static ivas_error ivas_filterbank_setup_fx( FOR( j = start_diff_band_non48k; j < pFb->filterbank_num_bands; j++ ) { - ppFilterbank_FRs_re_temp_fx[j - start_diff_band_non48k] = pFb->fb_consts.ppFilterbank_FRs_non48k_fx[0][j]; - ppFilterbank_FRs_im_temp_fx[j - start_diff_band_non48k] = pFb->fb_consts.ppFilterbank_FRs_non48k_fx[1][j]; + ppFilterbank_FRs_re_temp_fx[j - start_diff_band_non48k] = pFb->fb_consts.ppFilterbank_FRs_non48k_fx[0][j]; // Q30 + ppFilterbank_FRs_im_temp_fx[j - start_diff_band_non48k] = pFb->fb_consts.ppFilterbank_FRs_non48k_fx[1][j]; // Q30 active_bins_temp[j - start_diff_band_non48k] = pFb->fb_consts.pFilterbank_bins_per_band[j]; start_offset_temp[j - start_diff_band_non48k] = pFb->fb_consts.pFilterbank_bins_start_offset[j]; @@ -1775,8 +1795,8 @@ static ivas_error ivas_filterbank_setup_fx( FOR( j = start_diff_band_non48k; j < pFb->filterbank_num_bands; j++ ) { - pFb->fb_consts.ppFilterbank_FRs_fx[0][j] = (const Word32 *) pFb->fb_consts.ppFilterbank_FRs_non48k_fx[0][j]; - pFb->fb_consts.ppFilterbank_FRs_fx[1][j] = (const Word32 *) pFb->fb_consts.ppFilterbank_FRs_non48k_fx[1][j]; + pFb->fb_consts.ppFilterbank_FRs_fx[0][j] = (const Word32 *) pFb->fb_consts.ppFilterbank_FRs_non48k_fx[0][j]; // Q30 + pFb->fb_consts.ppFilterbank_FRs_fx[1][j] = (const Word32 *) pFb->fb_consts.ppFilterbank_FRs_non48k_fx[1][j]; // Q30 } /******************************************** Calculate abs fr ****************************************************/ @@ -1875,10 +1895,10 @@ static const Word32 *ivas_get_cheby_ramp_fx( #ifdef IVAS_FLOAT_FIXED static void ivas_get_ld_fb_resp_fx( - Word32 **ppIdeal_FRs_re_fx, - Word32 **ppIdeal_FRs_im_fx, - Word32 **ppNew_FRs_re_fx, - Word32 **ppNew_FRs_im_fx, + Word32 **ppIdeal_FRs_re_fx, // i: Q30 + Word32 **ppIdeal_FRs_im_fx, // i: Q30 + Word32 **ppNew_FRs_re_fx, // o: Q30 + Word32 **ppNew_FRs_im_fx, // o: Q30 const Word16 *pActive_bins, const Word16 *pStart_offset, const Word16 num_bands, @@ -1931,18 +1951,18 @@ static void ivas_get_ld_fb_resp_fx( { set32_fx( scratch2_fx, 0, shl( frame_len, 1 ) ); - Copy32( ppIdeal_FRs_re_fx[b], &scratch2_fx[pStart_offset[b]], pActive_bins[b] ); + Copy32( ppIdeal_FRs_re_fx[b], &scratch2_fx[pStart_offset[b]], pActive_bins[b] ); // Q30 Copy32( ppIdeal_FRs_im_fx[b], &scratch2_fx[frame_len + pStart_offset[b]], pActive_bins[b] ); // Q30 Word16 guard_bits = sub( L_norm_arr( scratch2_fx, shl( L_FRAME32k, 1 ) ), find_guarded_bits_fx( shl( frame_len, 1 ) ) ); - Scale_sig32( scratch2_fx, shl( L_FRAME32k, 1 ), guard_bits ); + Scale_sig32( scratch2_fx, shl( L_FRAME32k, 1 ), guard_bits ); // Q30 + guard_bits ivas_imdft_fx( scratch2_fx, &scratch2_fx[frame_len], scratch1_fx, frame_len ); FOR( Word16 x = 0; x < shl( L_FRAME32k, 1 ); x++ ) { - scratch2_fx[x] = L_shr( scratch2_fx[x], guard_bits ); - scratch1_fx[x] = L_shr( scratch1_fx[x], guard_bits ); + scratch2_fx[x] = L_shr( scratch2_fx[x], guard_bits ); // (Q30 + guard_bits) - guard_bits = Q30 + scratch1_fx[x] = L_shr( scratch1_fx[x], guard_bits ); // (Q30 + guard_bits) - guard_bits = Q30 move32(); move32(); @@ -1953,21 +1973,21 @@ static void ivas_get_ld_fb_resp_fx( FOR( s = delay; s < frame_len + delay; s++ ) { - scratch2_fx[sub( s, delay )] = Mpy_32_32( scratch1_fx[s], L_sub( ONE_IN_Q31, han_win_fx[sub( s, delay )] ) ); // Q(30 + 31 - 31) == Q30 + scratch2_fx[s - delay] = Mpy_32_32( scratch1_fx[s], L_sub( ONE_IN_Q31, han_win_fx[s - delay] ) ); // Q(30 + 31 - 31) == Q30 move32(); } FOR( ; s < 2 * frame_len; s++ ) { - scratch2_fx[sub( s, delay )] = Mpy_32_32( scratch1_fx[s], han_win_fx[sub( s, add( frame_len, delay ) )] ); // Q30 + scratch2_fx[s - delay] = Mpy_32_32( scratch1_fx[s], han_win_fx[s - ( frame_len + delay )] ); // Q30 move32(); } FOR( s = 0; s < delay; s++ ) { - scratch2_fx[add( sub( shl( frame_len, 1 ), delay ), s )] = L_negate( Mpy_32_32( scratch1_fx[s], han_win_fx[add( sub( frame_len, delay ), s )] ) ); // Q30 + scratch2_fx[( ( ( frame_len * 2 ) - delay ) + s )] = L_negate( Mpy_32_32( scratch1_fx[s], han_win_fx[( frame_len - delay ) + s] ) ); // Q30 move32(); } @@ -1975,7 +1995,7 @@ static void ivas_get_ld_fb_resp_fx( FOR( s = 0; s < delay + 1; s++ ) { - scratch1_fx[s] = Mpy_32_32( scratch2_fx[s], pCheby_fx[sub( delay, s )] ); // Q30 + scratch1_fx[s] = Mpy_32_32( scratch2_fx[s], pCheby_fx[delay - s] ); // Q30 move32(); } @@ -1993,31 +2013,31 @@ static void ivas_get_ld_fb_resp_fx( FOR( ; s < 2 * frame_len; s++ ) { - scratch1_fx[s] = Mpy_32_32( scratch2_fx[s], L_sub( ONE_IN_Q31, pCheby_fx[sub( s, sub( shl( frame_len, 1 ), delay ) )] ) ); // Q30 + scratch1_fx[s] = Mpy_32_32( scratch2_fx[s], L_sub( ONE_IN_Q31, pCheby_fx[s - ( 2 * frame_len - delay )] ) ); // Q30 move32(); } /*IR - pre ring + post ring*/ FOR( s = 1; s < 2 * frame_len; s++ ) { - scratch2_fx[s] = L_sub( L_sub( scratch2_fx[s] /*pre ring*/, scratch1_fx[s] /*post ring*/ ), scratch1_fx[sub( shl( frame_len, 1 ), s )] ); + scratch2_fx[s] = L_sub( L_sub( scratch2_fx[s] /*pre ring*/, scratch1_fx[s] /*post ring*/ ), scratch1_fx[frame_len * 2 - s] ); move32(); } FOR( s = 0; s < 2 * frame_len - delay; s++ ) { - scratch1_fx[add( s, delay )] = scratch2_fx[s]; + scratch1_fx[s + delay] = scratch2_fx[s]; move32(); } FOR( ; s < 2 * frame_len; s++ ) { - scratch1_fx[sub( s, sub( shl( frame_len, 1 ), delay ) )] = L_negate( scratch2_fx[s] ); + scratch1_fx[( s - ( ( frame_len * 2 ) - delay ) )] = L_negate( scratch2_fx[s] ); move32(); } /* apply final window*/ - const Word32 *sine_till_delay = ivas_sine_delay_32_fx; + const Word32 *sine_till_delay = ivas_sine_delay_32_fx; // Q30 Word16 offset = 1; Word16 delay_16 = 0; @@ -2032,7 +2052,7 @@ static void ivas_get_ld_fb_resp_fx( FOR( s = 0; s < delay; s++ ) { - scratch1_fx[s] = Mpy_32_32( scratch1_fx[s], sine_till_delay[add( s, imult1616( offset, delay_16 ) )] ); + scratch1_fx[s] = Mpy_32_32( scratch1_fx[s], sine_till_delay[s + offset * delay_16] ); // Q30 + Q30 - 31 = Q29 offset = add( offset, 1 ); scratch1_fx[s] = L_shl( scratch1_fx[s], 1 ); // Q30 @@ -2045,16 +2065,18 @@ static void ivas_get_ld_fb_resp_fx( IF( EQ_16( delay, IVAS_FB_1MS_16K_SAMP ) ) { sine_till_frame_len = ivas_sine_frame_len_640_del_16_fx; // Q30 + move32(); } ELSE { sine_till_frame_len = ivas_sine_frame_len_640_del_32_fx; // Q30 + move32(); } Word16 iterator = 0; move16(); FOR( s = 2 * delay; s < frame_len + 1; s++ ) { - scratch1_fx[s] = Mpy_32_32( scratch1_fx[s], sine_till_frame_len[iterator] ); + scratch1_fx[s] = Mpy_32_32( scratch1_fx[s], sine_till_frame_len[iterator] ); // Q30 + Q30 - 31 = Q29 iterator = add( iterator, 1 ); scratch1_fx[s] = L_shl( scratch1_fx[s], 1 ); // Q30 @@ -2072,8 +2094,8 @@ static void ivas_get_ld_fb_resp_fx( /*compute frequency response*/ ivas_mdft_fx( scratch1_fx, scratch2_fx, &scratch2_fx[frame_len], shl( frame_len, 1 ), frame_len ); - Copy32( &scratch2_fx[pStart_offset[b]], ppNew_FRs_re_fx[b], pActive_bins[b] ); - Copy32( &scratch2_fx[add( frame_len, pStart_offset[b] )], ppNew_FRs_im_fx[b], pActive_bins[b] ); + Copy32( &scratch2_fx[pStart_offset[b]], ppNew_FRs_re_fx[b], pActive_bins[b] ); // Q30 + Copy32( &scratch2_fx[( frame_len + pStart_offset[b] )], ppNew_FRs_im_fx[b], pActive_bins[b] ); // Q30 } return; diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index 6b5cf7868..bf819845c 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -789,7 +789,7 @@ void ivas_renderer_select( Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ ); -ivas_error ivas_mc_enc_config( +ivas_error ivas_mc_enc_config_fx( Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ ); diff --git a/lib_com/ivas_prot_fx.h b/lib_com/ivas_prot_fx.h index b93158e31..eff881370 100644 --- a/lib_com/ivas_prot_fx.h +++ b/lib_com/ivas_prot_fx.h @@ -253,13 +253,13 @@ void ivas_agc_read_bits_fx( // ivas_agc_com_fx.c void ivas_agc_initWindowFunc_fx( - Word16 *pWinFunc, + Word16 *pWinFunc, // o: Q15 const Word16 length ); void ivas_agc_calcGainParams_fx( - UWord16 *absEmin, - UWord16 *betaE, - UWord16 *maxAttExp, + UWord16 *absEmin, // o: Q0 + UWord16 *betaE, // o: Q0 + UWord16 *maxAttExp, // o: Q0 const Word16 numCoeffs ); void ivas_transient_det_process_fx( @@ -3836,12 +3836,12 @@ void ivas_fb_mixer_pcm_ingest_fx( void ivas_fb_mixer_process_fx( IVAS_FB_MIXER_HANDLE hFbMixer, /* i/o: FB mixer handle */ - Word32 ***mixer_mat_fx, /* i : mixer matrix in q_mixer_mat_fx */ - Word16 *q_mixer_mat_fx, /* i : mixer matrix */ - Word32 **ppOut_pcm_fx, /* o : output audio channels in ppOut_pcm_fx resultant */ - Word16 *q_ppOut_pcm_fx, /*ppOut_pcm_fx resultant q*/ + Word32 ***mixer_mat_fx, /* i : mixer matrix */ + Word16 *q_mixer_mat_fx, /* i : mixer matrix Q-factor */ + Word32 **ppOut_pcm_fx, /* o : output audio channels */ + Word16 *q_ppOut_pcm_fx, /* o : output audio channels Q-factor */ const Word16 frame_len, /* i : frame length in samples */ - Word16 in_out_mixer_map[IVAS_MAX_FB_MIXER_OUT_CH][IVAS_MAX_SPAR_FB_MIXER_IN_CH] /* i/o: mixing mapping */ + Word16 in_out_mixer_map[IVAS_MAX_FB_MIXER_OUT_CH][IVAS_MAX_SPAR_FB_MIXER_IN_CH] /* i/o: mixing mapping */ ); Word16 ivas_get_num_bands_from_bw_idx( @@ -5333,6 +5333,24 @@ void ivas_create_fullr_dmx_mat_fx( const Word16 active_w, ivas_spar_md_com_cfg *hMdCfg ); +void ivas_get_spar_md_from_dirac_enc_fx( + Word32 azi_dirac_fx[IVAS_MAX_NUM_BANDS][MAX_PARAM_SPATIAL_SUBFRAMES], // Q22 + Word32 ele_dirac_fx[IVAS_MAX_NUM_BANDS][MAX_PARAM_SPATIAL_SUBFRAMES], // Q22 + Word32 diffuseness_fx[IVAS_MAX_NUM_BANDS], // Q30 + const Word16 n_ts, + Word32 ***mixer_mat_fx, /*q_mixer_mat_fx*/ + Word16 *q_mixer_mat_fx, + ivas_spar_md_t *hSpar_md, + ivas_spar_md_com_cfg *hSpar_md_cfg, + const Word16 start_band, + const Word16 end_band, + const Word16 order, + const Word16 dtx_vad, + Word32 Wscale_d[IVAS_MAX_NUM_BANDS], // Q29 + const UWord8 useLowerRes, + const Word16 active_w_vlbr, + const Word16 dyn_active_w_flag ); + void ivas_get_spar_md_from_dirac_fx( Word32 azi_dirac_fx[IVAS_MAX_NUM_BANDS][MAX_PARAM_SPATIAL_SUBFRAMES], // Q22 Word32 ele_dirac_fx[IVAS_MAX_NUM_BANDS][MAX_PARAM_SPATIAL_SUBFRAMES], // Q22 diff --git a/lib_com/ivas_spar_com.c b/lib_com/ivas_spar_com.c index 4b206e1ca..236d60859 100644 --- a/lib_com/ivas_spar_com.c +++ b/lib_com/ivas_spar_com.c @@ -2250,11 +2250,19 @@ static void ivas_calc_post_pred_per_band_enc_fx( q_postpred_cov_re_per_value[i][j] = q_tmp_re; move16(); - q_tmp_re = W_norm( tmp_re ); - postpred_cov_re[i][j] = W_extract_h( W_shl( tmp_re, q_tmp_re ) ); /* q_tmp_re+ q_postpred_cov_re_per_value[i][j] -32*/ - move32(); - q_postpred_cov_re_per_value[i][j] = sub( add( q_tmp_re, q_postpred_cov_re_per_value[i][j] ), 32 ); - move16(); + IF( tmp_re == 0 ) + { + postpred_cov_re[i][j] = W_extract_l( tmp_re ); /* q_tmp_re*/ + move32(); + } + ELSE + { + q_tmp_re = W_norm( tmp_re ); + postpred_cov_re[i][j] = W_extract_h( W_shl( tmp_re, q_tmp_re ) ); /* q_tmp_re+ q_postpred_cov_re_per_value[i][j] -32*/ + move32(); + q_postpred_cov_re_per_value[i][j] = sub( add( q_tmp_re, q_postpred_cov_re_per_value[i][j] ), 32 ); + move16(); + } *q_postpred_cov_re = s_min( *q_postpred_cov_re, q_postpred_cov_re_per_value[i][j] ); move16(); } @@ -4067,7 +4075,8 @@ Word32 diff_norm_order3_table[8] = { 0, 1879048192, 939524096, 626349376, 469762 #define ONE_BY_THREE_Q31 715827882 #define ONE_BY_FIVE_Q31 429496729 #define ONE_BY_SEVEN_Q31 306783378 -void ivas_get_spar_md_from_dirac_fx( + +void ivas_get_spar_md_from_dirac_enc_fx( Word32 azi_dirac_fx[IVAS_MAX_NUM_BANDS][MAX_PARAM_SPATIAL_SUBFRAMES], // Q22 Word32 ele_dirac_fx[IVAS_MAX_NUM_BANDS][MAX_PARAM_SPATIAL_SUBFRAMES], // Q22 Word32 diffuseness_fx[IVAS_MAX_NUM_BANDS], // Q30 @@ -4093,7 +4102,9 @@ void ivas_get_spar_md_from_dirac_fx( Word32 response_avg_fx[MAX_OUTPUT_CHANNELS]; Word32 response_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MAX_OUTPUT_CHANNELS]; Word32 cov_real_dirac_fx[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH][IVAS_MAX_NUM_BANDS]; + Word16 q_cov_real_dirac_fx[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH][IVAS_MAX_NUM_BANDS]; Word32 *pCov_real_fx[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH]; + Word16 *p_q_Cov_real_fx[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH]; Word32 dm_fv_re_fx[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS]; Word16 q_dm_fv_re_fx = 0; Word16 q_Wscale[IVAS_MAX_NUM_BANDS]; @@ -4132,10 +4143,8 @@ void ivas_get_spar_md_from_dirac_fx( FOR( j = 0; j < IVAS_MAX_SPAR_FB_MIXER_IN_CH; j++ ) { pMixer_mat_fx[i][j] = mixer_mat_local_fx[i][j]; - move32(); } ppMixer_mat_fx[i] = pMixer_mat_fx[i]; - move32(); } test(); @@ -4155,43 +4164,38 @@ void ivas_get_spar_md_from_dirac_fx( move32(); FOR( i = 0; i < max( 0, sub( foa_ch, ndm ) ); i++ ) { - P_norm_fx[0] = L_add( P_norm_fx[0], Mpy_32_32( hSpar_md->band_coeffs[start_band - 1].P_re_fx[i], hSpar_md->band_coeffs[start_band - 1].P_re_fx[i] ) ); // q25 + P_norm_fx[0] = L_add( P_norm_fx[0], Mpy_32_32( hSpar_md->band_coeffs[start_band - 1].P_re_fx[i], hSpar_md->band_coeffs[start_band - 1].P_re_fx[i] ) ); // 2*q_P_re - 31 move32(); } - P_norm_fx[0] = Mpy_32_32( L_shl( P_norm_fx[0], 3 ), diff_norm_order1_table[min( diff_norm_order1_fx, max( 0, sub( foa_ch, ndm ) ) )] ); // q25 + P_norm_fx[0] = Mpy_32_32( L_shl( P_norm_fx[0], 3 ), diff_norm_order1_table[min( diff_norm_order1_fx, max( 0, sub( foa_ch, ndm ) ) )] ); // 2*q_P_re - 31 move32(); P_norm_fx[1] = 0; move32(); FOR( ; i < max( 0, ( min( num_ch, hoa2_ch ) - ndm ) ); i++ ) { - P_norm_fx[1] = L_add( P_norm_fx[1], Mpy_32_32( hSpar_md->band_coeffs[start_band - 1].P_re_fx[i], hSpar_md->band_coeffs[start_band - 1].P_re_fx[i] ) ); // q25 + P_norm_fx[1] = L_add( P_norm_fx[1], Mpy_32_32( hSpar_md->band_coeffs[start_band - 1].P_re_fx[i], hSpar_md->band_coeffs[start_band - 1].P_re_fx[i] ) ); // 2*q_P_re - 31 move32(); } - P_norm_fx[1] = Mpy_32_32( L_shl( P_norm_fx[1], 3 ), diff_norm_order2_table[min( diff_norm_order2_fx, max( 0, ( min( num_ch, hoa2_ch ) - ndm ) ) )] ); // q25 + P_norm_fx[1] = Mpy_32_32( L_shl( P_norm_fx[1], 3 ), diff_norm_order2_table[min( diff_norm_order2_fx, max( 0, ( min( num_ch, hoa2_ch ) - ndm ) ) )] ); // 2*q_P_re - 31 move32(); P_norm_fx[2] = 0; move32(); FOR( ; i < ( num_ch - ndm ); i++ ) { - P_norm_fx[2] = L_add( P_norm_fx[2], Mpy_32_32( hSpar_md->band_coeffs[start_band - 1].P_re_fx[i], hSpar_md->band_coeffs[start_band - 1].P_re_fx[i] ) ); // q25 + P_norm_fx[2] = L_add( P_norm_fx[2], Mpy_32_32( hSpar_md->band_coeffs[start_band - 1].P_re_fx[i], hSpar_md->band_coeffs[start_band - 1].P_re_fx[i] ) ); // 2*q_P_re - 31 move32(); } - P_norm_fx[2] = Mpy_32_32( L_shl( P_norm_fx[2], 3 ), diff_norm_order3_table[min( diff_norm_order3_fx, max( 0, ( num_ch - ndm ) ) )] ); // q25 + P_norm_fx[2] = Mpy_32_32( L_shl( P_norm_fx[2], 3 ), diff_norm_order3_table[min( diff_norm_order3_fx, max( 0, ( num_ch - ndm ) ) )] ); // 2*q_P_re - 31 move32(); FOR( i = 0; i < max( 0, ( foa_ch - ndm ) ); i++ ) { idx = sub( remix_order[i + ndm], ndm ); - P_dir_fact_fx[idx] = Mpy_32_32( hSpar_md->band_coeffs[start_band - 1].P_re_fx[i], hSpar_md->band_coeffs[start_band - 1].P_re_fx[i] ); // q25 + P_dir_fact_fx[idx] = Mpy_32_32( hSpar_md->band_coeffs[start_band - 1].P_re_fx[i], hSpar_md->band_coeffs[start_band - 1].P_re_fx[i] ); // 2*q_P_re - 31 move32(); - IF( P_dir_fact_fx[idx] == 0 ) - { - P_dir_fact_fx[idx] = 0; - move32(); - } - ELSE + IF( P_dir_fact_fx[idx] != 0 ) { P_dir_fact_fx[idx] = divide3232( P_dir_fact_fx[idx], L_max( P_norm_fx[0], IVAS_FIX_EPS ) ); // q15 move32(); @@ -4202,13 +4206,8 @@ void ivas_get_spar_md_from_dirac_fx( FOR( ; i < max( 0, ( min( num_ch, hoa2_ch ) - ndm ) ); i++ ) { idx = sub( remix_order[i + ndm], ndm ); - P_dir_fact_fx[idx] = Mpy_32_32( hSpar_md->band_coeffs[start_band - 1].P_re_fx[i], hSpar_md->band_coeffs[start_band - 1].P_re_fx[i] ); // q25 - IF( P_dir_fact_fx[idx] == 0 ) - { - P_dir_fact_fx[idx] = 0; - move32(); - } - ELSE + P_dir_fact_fx[idx] = Mpy_32_32( hSpar_md->band_coeffs[start_band - 1].P_re_fx[i], hSpar_md->band_coeffs[start_band - 1].P_re_fx[i] ); // 2*q_P_re - 31 + IF( P_dir_fact_fx[idx] != 0 ) { P_dir_fact_fx[idx] = divide3232( P_dir_fact_fx[idx], L_max( P_norm_fx[1], IVAS_FIX_EPS ) ); // q15 move32(); @@ -4219,14 +4218,9 @@ void ivas_get_spar_md_from_dirac_fx( FOR( ; i < ( num_ch - ndm ); i++ ) { idx = sub( remix_order[i + ndm], ndm ); - P_dir_fact_fx[idx] = Mpy_32_32( hSpar_md->band_coeffs[start_band - 1].P_re_fx[i], hSpar_md->band_coeffs[start_band - 1].P_re_fx[i] ); // q25 + P_dir_fact_fx[idx] = Mpy_32_32( hSpar_md->band_coeffs[start_band - 1].P_re_fx[i], hSpar_md->band_coeffs[start_band - 1].P_re_fx[i] ); // 2*q_P_re - 31 move32(); - IF( P_dir_fact_fx[idx] == 0 ) - { - P_dir_fact_fx[idx] = 0; - move32(); - } - ELSE + IF( P_dir_fact_fx[idx] != 0 ) { P_dir_fact_fx[idx] = divide3232( P_dir_fact_fx[idx], L_max( P_norm_fx[2], IVAS_FIX_EPS ) ); // q15 move32(); @@ -4434,6 +4428,560 @@ void ivas_get_spar_md_from_dirac_fx( /*normalize 3rd order*/ norm_fx = 0; + move32(); + FOR( ch = hoa2_ch_order; ch < num_ch_order; ch++ ) + { + norm_fx = L_add( norm_fx, Mpy_32_32( response_avg_fx[ch], response_avg_fx[ch] ) ); // q29 + } + norm_q = sub( 31, ( sub( add( 29, 29 ), 31 ) ) ); + IF( norm_fx ) + { + norm_fx = Sqrt32( norm_fx, &norm_q ); // q=31-norm_q + } + ELSE + { + norm_fx = EPSILON_FX; + move32(); + } + IF( norm_q < 0 ) + { + norm_fx = L_shr( norm_fx, negate( norm_q ) ); // q31 + norm_q = 0; + move16(); + } + norm_fx = L_shr( norm_fx, sub( 1, norm_q ) ); // q30 + FOR( ch = hoa2_ch_order; ch < num_ch_order; ch++ ) + { + IF( LT_32( norm_fx, EPSILON_FX_THR ) ) + { + response_avg_fx[ch] = response_avg_fx[ch]; // q30 + response_avg_fx[ch] = divide3232( response_avg_fx[ch], EPSILON_FX_THR ); // q15 + response_avg_fx[ch] = L_shl( response_avg_fx[ch], 15 ); // q30 + move32(); + move32(); + move32(); + } + ELSE IF( GT_32( response_avg_fx[ch], norm_fx ) ) + { + response_avg_fx[ch] = ONE_IN_Q30; // 1 q30 + move32(); + } + ELSE + { + response_avg_fx[ch] = divide3232( response_avg_fx[ch], norm_fx ); // q15 + move32(); + response_avg_fx[ch] = L_shl( response_avg_fx[ch], 15 ); // q30 + move32(); + } + } + } + } + + FOR( i = add( FOA_CHANNELS, 1 ); i < num_ch; i++ ) + { + response_avg_fx[i] = response_avg_fx[HOA_keep_ind[i]]; // q30 + move32(); + } + + + en_ratio_fac_fx = L_shl( L_sub( ONE_IN_Q30 - EPSILON_FX /* Guard to prevent overflow if diffuseness_fx is 0 */, diffuseness_fx[band] ), 1 ); // assuming q of dissusion 30=>q31 + en_ratio_fac_fx = L_max( en_ratio_fac_fx, 0 ); // q31 + + FOR( i = 0; i < num_ch; i++ ) + { + FOR( j = 0; j < num_ch; j++ ) + { + IF( EQ_16( i, j ) ) + { + IF( i == 0 ) + { + cov_real_dirac_fx[i][i][band] = ONE_IN_Q30; // 1 q30 + move32(); + } + ELSE + { + Word32 en_ratio_fac_sq = 0; + move32(); + cov_real_dirac_fx[i][j][band] = Mpy_32_32( L_shl_sat( Mpy_32_32( en_ratio_fac_fx, response_avg_fx[i] ), 1 ), response_avg_fx[j] ); // q30 + move32(); + + IF( LE_16( hSpar_md_cfg->nchan_transport, 2 ) ) + { + cov_real_dirac_fx[i][j][band] = Mpy_32_32( cov_real_dirac_fx[i][j][band], en_ratio_fac_fx ); // q30 + move32(); + test(); + IF( ( GE_16( i, ndm ) ) && ( EQ_16( dtx_vad, 1 ) ) ) + { + en_ratio_fac_sq = Mpy_32_32( en_ratio_fac_fx, en_ratio_fac_fx ); // q31 + cov_real_dirac_fx[i][j][band] = L_add( cov_real_dirac_fx[i][j][band], Mpy_32_32( L_sub( ONE_IN_Q31, en_ratio_fac_sq ), P_dir_fact_fx[i - ndm] ) ); // q30 + move32(); + } + ELSE + { + IF( LT_16( i, foa_ch ) ) + { + en_ratio_fac_sq = Mpy_32_32( en_ratio_fac_fx, en_ratio_fac_fx ); // q31 + Word32 temp = Mpy_32_32( L_sub( ONE_IN_Q31 /*1 q31*/, en_ratio_fac_sq ), ONE_BY_THREE_Q31 /*1/3 q31*/ ); // q31 + cov_real_dirac_fx[i][j][band] = L_add( cov_real_dirac_fx[i][j][band], L_shr( temp, 1 ) ); // q30 + move32(); + } + ELSE IF( LT_16( i, hoa2_ch ) ) + { + en_ratio_fac_sq = Mpy_32_32( en_ratio_fac_fx, en_ratio_fac_fx ); // q31 + Word32 temp = Mpy_32_32( L_sub( ONE_IN_Q31, en_ratio_fac_sq ), ONE_BY_FIVE_Q31 /*1/5 q31*/ ); // q31 + cov_real_dirac_fx[i][j][band] = L_add( cov_real_dirac_fx[i][j][band], L_shr( temp, 1 ) ); // q30 + move32(); + } + ELSE + { + en_ratio_fac_sq = Mpy_32_32( en_ratio_fac_fx, en_ratio_fac_fx ); // q31 + Word32 temp = Mpy_32_32( L_sub( ONE_IN_Q31, en_ratio_fac_sq ), ONE_BY_SEVEN_Q31 /*1/7 q31*/ ); // q31 + cov_real_dirac_fx[i][j][band] = L_add( cov_real_dirac_fx[i][j][band], L_shr( temp, 1 ) ); // q30 + move32(); + } + } + } + ELSE + { + IF( LT_16( i, foa_ch ) ) + { + cov_real_dirac_fx[i][j][band] = L_add( cov_real_dirac_fx[i][j][band], L_shr( Mpy_32_32( L_sub( ONE_IN_Q31, en_ratio_fac_fx ), ONE_BY_THREE_Q31 /*1/3 q31*/ ), 1 ) ); // q30 + move32(); + } + ELSE IF( LT_16( i, hoa2_ch ) ) + { + cov_real_dirac_fx[i][j][band] = L_add( cov_real_dirac_fx[i][j][band], L_shr( Mpy_32_32( L_sub( ONE_IN_Q31, en_ratio_fac_fx ), ONE_BY_FIVE_Q31 /*1/5 q31*/ ), 1 ) ); // q30 + move32(); + } + ELSE + { + cov_real_dirac_fx[i][j][band] = L_add( cov_real_dirac_fx[i][j][band], L_shr( Mpy_32_32( L_sub( ONE_IN_Q31, en_ratio_fac_fx ), ONE_BY_SEVEN_Q31 /*1/7 q31*/ ), 1 ) ); // q30 + move32(); + } + } + } + } + ELSE + { + cov_real_dirac_fx[i][j][band] = L_shl( Mpy_32_32( Mpy_32_32( en_ratio_fac_fx, response_avg_fx[i] ), response_avg_fx[j] ), 1 ); // q30 + move32(); + } + } + } + } + + FOR( i = 0; i < num_ch; i++ ) + { + FOR( j = 0; j < num_ch; j++ ) + { + pCov_real_fx[i][j] = cov_real_dirac_fx[i][j]; // q30 + p_q_Cov_real_fx[i][j] = q_cov_real_dirac_fx[i][j]; // q30 + set16_fx( q_cov_real_dirac_fx[i][j], Q30, IVAS_MAX_NUM_BANDS ); + } + } + + test(); + active_w = ( EQ_16( dyn_active_w_flag, 1 ) ) || ( EQ_16( hSpar_md_cfg->active_w, 1 ) ); + ivas_compute_spar_params_enc_fx( pCov_real_fx, p_q_Cov_real_fx, dm_fv_re_fx, &q_dm_fv_re_fx, i_ts, ppMixer_mat_fx, &q_ppMixer_mat, start_band, end_band, dtx_vad, num_ch, 1, active_w, active_w_vlbr, hSpar_md_cfg, hSpar_md, Wscale_fx, q_Wscale, 1, dyn_active_w_flag ); + + IF( mixer_mat_fx != NULL ) + { + if ( *q_mixer_mat_fx == 0 ) + { + *q_mixer_mat_fx = q_ppMixer_mat; + move16(); + } + FOR( band = start_band; band < end_band; band++ ) + { + ndm = hSpar_md_cfg->num_dmx_chans_per_band[band]; + move16(); + + FOR( i = 0; i < ndm; i++ ) + { + FOR( j = 0; j < num_ch; j++ ) + { + mixer_mat_fx[i][j][band + ( i_ts * IVAS_MAX_NUM_BANDS )] = L_shl( ppMixer_mat_fx[i][j][band], sub( *q_mixer_mat_fx, q_ppMixer_mat ) ); // q_mixer_mat_fx + move32(); + } + } + + FOR( i = ndm; i < num_ch; i++ ) + { + FOR( j = 0; j < num_ch; j++ ) + { + mixer_mat_fx[i][j][band + ( i_ts * IVAS_MAX_NUM_BANDS )] = 0; + move32(); + } + } + + test(); + IF( ( EQ_16( ndm, 1 ) ) && ( Wscale_d != NULL ) ) + { + FOR( j = 0; j < num_ch; j++ ) + { + mixer_mat_fx[0][j][band + ( i_ts * IVAS_MAX_NUM_BANDS )] = Mpy_32_32( L_shl( mixer_mat_fx[0][j][band + ( i_ts * IVAS_MAX_NUM_BANDS )], 2 ), Wscale_d[band] ); // q_mixer_mat_fx + move32(); + } + } + } + } + } + + return; +} + + +void ivas_get_spar_md_from_dirac_fx( + Word32 azi_dirac_fx[IVAS_MAX_NUM_BANDS][MAX_PARAM_SPATIAL_SUBFRAMES], // Q22 + Word32 ele_dirac_fx[IVAS_MAX_NUM_BANDS][MAX_PARAM_SPATIAL_SUBFRAMES], // Q22 + Word32 diffuseness_fx[IVAS_MAX_NUM_BANDS], // Q30 + const Word16 n_ts, + Word32 ***mixer_mat_fx, /*q_mixer_mat_fx*/ + Word16 *q_mixer_mat_fx, + ivas_spar_md_t *hSpar_md, + ivas_spar_md_com_cfg *hSpar_md_cfg, + const Word16 start_band, + const Word16 end_band, + const Word16 order, + const Word16 dtx_vad, + Word32 Wscale_d[IVAS_MAX_NUM_BANDS], // Q29 + const UWord8 useLowerRes, + const Word16 active_w_vlbr, + const Word16 dyn_active_w_flag ) +{ + + Word16 num_ch, band, i, j; + Word16 block, ch; + Word16 azimuth, elevation; + + Word32 response_avg_fx[MAX_OUTPUT_CHANNELS]; + Word32 response_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MAX_OUTPUT_CHANNELS]; + Word32 cov_real_dirac_fx[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH][IVAS_MAX_NUM_BANDS]; + Word32 *pCov_real_fx[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH]; + Word32 dm_fv_re_fx[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS]; + Word16 q_dm_fv_re_fx = 0; + Word16 q_Wscale[IVAS_MAX_NUM_BANDS]; + Word32 Wscale_fx[IVAS_MAX_NUM_BANDS]; + Word32 mixer_mat_local_fx[IVAS_MAX_FB_MIXER_OUT_CH][IVAS_MAX_SPAR_FB_MIXER_IN_CH][IVAS_MAX_NUM_BANDS]; + Word32 **ppMixer_mat_fx[IVAS_MAX_FB_MIXER_OUT_CH]; + Word32 *pMixer_mat_fx[IVAS_MAX_FB_MIXER_OUT_CH][IVAS_MAX_SPAR_FB_MIXER_IN_CH]; + Word16 q_ppMixer_mat = 0; + Word32 en_ratio_fac_fx, diff_norm_order1_fx, diff_norm_order2_fx, diff_norm_order3_fx; + Word16 active_w; + move16(); + move16(); + + Word16 ndm, foa_ch, hoa2_ch; + Word32 P_dir_fact_fx[IVAS_SPAR_MAX_CH - 1]; + const Word16 *remix_order; + + set16_fx( q_Wscale, 0, IVAS_MAX_NUM_BANDS ); + set32_fx( Wscale_fx, 0, IVAS_MAX_NUM_BANDS ); + remix_order = remix_order_set[hSpar_md_cfg->remix_unmix_order]; + + num_ch = ivas_sba_get_nchan_metadata_fx( order, IVAS_256k /*dummy value as order is always 1 in this function*/ ); + + hoa2_ch = ivas_sba_get_nchan_metadata_fx( SBA_HOA2_ORDER, IVAS_256k /*dummy value as order is always 1 in this function*/ ); + foa_ch = FOA_CHANNELS; + move16(); + diff_norm_order1_fx = 3; + move32(); + diff_norm_order2_fx = 5; + move32(); + diff_norm_order3_fx = 7; + move32(); + + FOR( i = 0; i < IVAS_MAX_FB_MIXER_OUT_CH; i++ ) + { + FOR( j = 0; j < IVAS_MAX_SPAR_FB_MIXER_IN_CH; j++ ) + { + pMixer_mat_fx[i][j] = mixer_mat_local_fx[i][j]; + } + ppMixer_mat_fx[i] = pMixer_mat_fx[i]; + } + + test(); + test(); + test(); + test(); + test(); + test(); + IF( ( GE_16( start_band, 6 ) && LE_16( hSpar_md_cfg->nchan_transport, 2 ) && ( EQ_16( dtx_vad, 1 ) ) ) || ( useLowerRes && GE_16( start_band, 3 ) && LE_16( hSpar_md_cfg->nchan_transport, 2 ) && ( EQ_16( dtx_vad, 1 ) ) ) ) + { + Word32 P_norm_fx[3]; + Word16 idx; + + ndm = hSpar_md_cfg->num_dmx_chans_per_band[start_band - 1]; + move16(); + P_norm_fx[0] = 0; + move32(); + FOR( i = 0; i < max( 0, sub( foa_ch, ndm ) ); i++ ) + { + P_norm_fx[0] = L_add( P_norm_fx[0], Mpy_32_32( hSpar_md->band_coeffs[start_band - 1].P_re_fx[i], hSpar_md->band_coeffs[start_band - 1].P_re_fx[i] ) ); // 2*q_P_re - 31 + move32(); + } + P_norm_fx[0] = Mpy_32_32( L_shl( P_norm_fx[0], 3 ), diff_norm_order1_table[min( diff_norm_order1_fx, max( 0, sub( foa_ch, ndm ) ) )] ); // 2*q_P_re - 31 + move32(); + + P_norm_fx[1] = 0; + move32(); + FOR( ; i < max( 0, ( min( num_ch, hoa2_ch ) - ndm ) ); i++ ) + { + P_norm_fx[1] = L_add( P_norm_fx[1], Mpy_32_32( hSpar_md->band_coeffs[start_band - 1].P_re_fx[i], hSpar_md->band_coeffs[start_band - 1].P_re_fx[i] ) ); // 2*q_P_re - 31 + move32(); + } + P_norm_fx[1] = Mpy_32_32( L_shl( P_norm_fx[1], 3 ), diff_norm_order2_table[min( diff_norm_order2_fx, max( 0, ( min( num_ch, hoa2_ch ) - ndm ) ) )] ); // 2*q_P_re - 31 + move32(); + + P_norm_fx[2] = 0; + move32(); + FOR( ; i < ( num_ch - ndm ); i++ ) + { + P_norm_fx[2] = L_add( P_norm_fx[2], Mpy_32_32( hSpar_md->band_coeffs[start_band - 1].P_re_fx[i], hSpar_md->band_coeffs[start_band - 1].P_re_fx[i] ) ); // 2*q_P_re - 31 + move32(); + } + P_norm_fx[2] = Mpy_32_32( L_shl( P_norm_fx[2], 3 ), diff_norm_order3_table[min( diff_norm_order3_fx, max( 0, ( num_ch - ndm ) ) )] ); // 2*q_P_re - 31 + move32(); + + FOR( i = 0; i < max( 0, ( foa_ch - ndm ) ); i++ ) + { + idx = sub( remix_order[i + ndm], ndm ); + P_dir_fact_fx[idx] = Mpy_32_32( hSpar_md->band_coeffs[start_band - 1].P_re_fx[i], hSpar_md->band_coeffs[start_band - 1].P_re_fx[i] ); // 2*q_P_re - 31 + move32(); + IF( P_dir_fact_fx[idx] != 0 ) + { + P_dir_fact_fx[idx] = divide3232( P_dir_fact_fx[idx], L_max( P_norm_fx[0], IVAS_FIX_EPS ) ); // q15 + move32(); + P_dir_fact_fx[idx] = L_shl( P_dir_fact_fx[idx], 15 ); // q30 + move32(); + } + } + FOR( ; i < max( 0, ( min( num_ch, hoa2_ch ) - ndm ) ); i++ ) + { + idx = sub( remix_order[i + ndm], ndm ); + P_dir_fact_fx[idx] = Mpy_32_32( hSpar_md->band_coeffs[start_band - 1].P_re_fx[i], hSpar_md->band_coeffs[start_band - 1].P_re_fx[i] ); // 2*q_P_re - 31 + IF( P_dir_fact_fx[idx] != 0 ) + { + P_dir_fact_fx[idx] = divide3232( P_dir_fact_fx[idx], L_max( P_norm_fx[1], IVAS_FIX_EPS ) ); // q15 + move32(); + P_dir_fact_fx[idx] = L_shl( P_dir_fact_fx[idx], 15 ); // q30 + move32(); + } + } + FOR( ; i < ( num_ch - ndm ); i++ ) + { + idx = sub( remix_order[i + ndm], ndm ); + P_dir_fact_fx[idx] = Mpy_32_32( hSpar_md->band_coeffs[start_band - 1].P_re_fx[i], hSpar_md->band_coeffs[start_band - 1].P_re_fx[i] ); // 2*q_P_re - 31 + move32(); + IF( P_dir_fact_fx[idx] != 0 ) + { + P_dir_fact_fx[idx] = divide3232( P_dir_fact_fx[idx], L_max( P_norm_fx[2], IVAS_FIX_EPS ) ); // q15 + move32(); + P_dir_fact_fx[idx] = L_shl( P_dir_fact_fx[idx], 15 ); // q30 + move32(); + } + } + } + + FOR( Word16 i_ts = 0; i_ts < n_ts; i_ts++ ) + { + FOR( band = start_band; band < end_band; band++ ) + { + ndm = hSpar_md_cfg->num_dmx_chans_per_band[band]; + move16(); + + /*SPAR from DirAC*/ + set32_fx( response_avg_fx, 0, MAX_OUTPUT_CHANNELS ); + + IF( GT_16( n_ts, 1 ) ) + { + IF( ele_dirac_fx[band][i_ts] < 0 ) + { + elevation = negate( extract_l( L_shr( L_negate( ele_dirac_fx[band][i_ts] ), Q22 ) ) ); // q0 + } + ELSE + { + elevation = extract_l( L_shr( ele_dirac_fx[band][i_ts], Q22 ) ); // q0 + } + IF( azi_dirac_fx[band][i_ts] < 0 ) + { + azimuth = negate( extract_l( L_shr( L_negate( azi_dirac_fx[band][i_ts] ), Q22 ) ) ); // q0 + } + ELSE + { + azimuth = extract_l( L_shr( azi_dirac_fx[band][i_ts], Q22 ) ); // q0 + } + ivas_dirac_dec_get_response_fx( azimuth, elevation, response_avg_fx, order, Q30 ); + } + ELSE IF( useLowerRes ) + { + IF( ele_dirac_fx[band][0] < 0 ) + { + elevation = negate( extract_l( L_shr( L_negate( ele_dirac_fx[band][0] ), Q22 ) ) ); // q0 + } + ELSE + { + elevation = extract_l( L_shr( ele_dirac_fx[band][0], Q22 ) ); // q0 + } + IF( azi_dirac_fx[band][0] < 0 ) + { + azimuth = negate( extract_l( L_shr( L_negate( azi_dirac_fx[band][0] ), Q22 ) ) ); // q0 + } + ELSE + { + azimuth = extract_l( L_shr( azi_dirac_fx[band][0], Q22 ) ); // q0 + } + ivas_dirac_dec_get_response_fx( azimuth, elevation, response_avg_fx, order, Q30 ); + } + ELSE + { + FOR( block = 0; block < MAX_PARAM_SPATIAL_SUBFRAMES; block++ ) + { + IF( ele_dirac_fx[band][block] < 0 ) + { + elevation = negate( extract_l( L_shr( L_negate( ele_dirac_fx[band][block] ), Q22 ) ) ); // q0 + } + ELSE + { + elevation = extract_l( L_shr( ele_dirac_fx[band][block], Q22 ) ); // q0 + } + IF( azi_dirac_fx[band][block] < 0 ) + { + azimuth = negate( extract_l( L_shr( L_negate( azi_dirac_fx[band][block] ), Q22 ) ) ); // q0 + } + ELSE + { + azimuth = extract_l( L_shr( azi_dirac_fx[band][block], Q22 ) ); // q0 + } + ivas_dirac_dec_get_response_fx( azimuth, elevation, &( response_fx[block][0] ), order, Q30 ); + } + + /* average responses in all subframes*/ + { + Word32 norm_fx; + Word16 norm_q; + Word16 num_ch_order, hoa2_ch_order; + + num_ch_order = ivas_sba_get_nchan_fx( order, 0 ); + hoa2_ch_order = ivas_sba_get_nchan_fx( SBA_HOA2_ORDER, 0 ); + + FOR( ch = 0; ch < num_ch_order; ch++ ) + { + Word64 temp = 0; + move64(); + FOR( block = 0; block < MAX_PARAM_SPATIAL_SUBFRAMES; block++ ) + { + temp = W_add( temp, W_deposit32_l( response_fx[block][ch] ) ); // q30 + } + response_avg_fx[ch] = W_extract_l( W_shr( temp, 2 ) ); // q30 + move32(); + } + + /*normalize 1st order*/ + norm_fx = 0; + move32(); + norm_q = 0; + move16(); + FOR( ch = 1; ch < foa_ch; ch++ ) + { + norm_fx = L_add( norm_fx, Mpy_32_32( response_avg_fx[ch], response_avg_fx[ch] ) ); // q29 + } + + norm_q = sub( 31, ( sub( add( 30, 30 ), 31 ) ) ); + IF( norm_fx ) + { + norm_fx = Sqrt32( norm_fx, &norm_q ); // q=31-norm_q + } + ELSE + { + norm_fx = EPSILON_FX; + move32(); + } + IF( norm_q <= 0 ) + { + norm_fx = L_shr( norm_fx, ( negate( norm_q ) ) ); // q=31 + norm_q = 0; + move16(); + } + norm_fx = L_shr( norm_fx, sub( 1, norm_q ) ); // q30 + FOR( ch = 1; ch < foa_ch; ch++ ) + { + IF( LT_32( norm_fx, EPSILON_FX_THR ) ) + { + IF( response_avg_fx[ch] != 0 ) + { + response_avg_fx[ch] = divide3232( response_avg_fx[ch], EPSILON_FX_THR ); // q15 + move32(); + } + response_avg_fx[ch] = L_shl( response_avg_fx[ch], 15 ); // q30 + move32(); + } + ELSE IF( GT_32( response_avg_fx[ch], norm_fx ) ) + { + response_avg_fx[ch] = ONE_IN_Q30; // 1 q30 + move32(); + } + ELSE + { + response_avg_fx[ch] = divide3232( response_avg_fx[ch], norm_fx ); // q15 + move32(); + response_avg_fx[ch] = L_shl( response_avg_fx[ch], 15 ); // q30 + move32(); + } + } + + /*normalize 2nd order*/ + norm_fx = 0; + move32(); + FOR( ch = foa_ch; ch < min( hoa2_ch_order, num_ch_order ); ch++ ) + { + norm_fx = L_add( norm_fx, Mpy_32_32( response_avg_fx[ch], response_avg_fx[ch] ) ); // q29 + } + norm_q = sub( 31, ( sub( add( 29, 29 ), 31 ) ) ); + IF( norm_fx ) + { + norm_fx = Sqrt32( norm_fx, &norm_q ); // q=31-norm_q + } + ELSE + { + norm_fx = EPSILON_FX; + move32(); + } + IF( norm_q < 0 ) + { + norm_fx = L_shr( norm_fx, negate( norm_q ) ); // q31 + norm_q = 0; + move16(); + } + norm_fx = L_shr( norm_fx, sub( 1, norm_q ) ); // q30 + FOR( ch = foa_ch; ch < min( hoa2_ch_order, num_ch_order ); ch++ ) + { + IF( LT_32( norm_fx, EPSILON_FX_THR ) ) + { + response_avg_fx[ch] = response_avg_fx[ch]; // q30 + response_avg_fx[ch] = divide3232( response_avg_fx[ch], EPSILON_FX_THR ); // q15 + response_avg_fx[ch] = L_shl( response_avg_fx[ch], 15 ); // q30 + move32(); + move32(); + move32(); + } + ELSE IF( GT_32( response_avg_fx[ch], norm_fx ) ) + { + response_avg_fx[ch] = ONE_IN_Q30; // q30 + move32(); + } + ELSE + { + response_avg_fx[ch] = divide3232( response_avg_fx[ch], norm_fx ); // q15 + response_avg_fx[ch] = L_shl( response_avg_fx[ch], 15 ); // q30 + move32(); + move32(); + } + } + + /*normalize 3rd order*/ + norm_fx = 0; + move32(); FOR( ch = hoa2_ch_order; ch < num_ch_order; ch++ ) { norm_fx = L_add( norm_fx, Mpy_32_32( response_avg_fx[ch], response_avg_fx[ch] ) ); // q29 diff --git a/lib_com/ivas_stereo_ica_com_fx.c b/lib_com/ivas_stereo_ica_com_fx.c index 829f4e5e8..e408d6b96 100644 --- a/lib_com/ivas_stereo_ica_com_fx.c +++ b/lib_com/ivas_stereo_ica_com_fx.c @@ -59,7 +59,7 @@ Word32 table_596[N_MAX_SHIFT_CHANGE + 1] = { 0, 2441216, 1220608, 813738, 610304, 488243, 406869, 348745, 305152, 271246, 244121, 221928, 203434, 187785, 174372, 162747, 152576, 143600, 135623, 128485, 122060 -}; // Q21 +}; // Q12 Word32 inv_table_596[N_MAX_SHIFT_CHANGE + 1] = { 0, 7206320, 14412641, 21618962, 28825283, 36031605, 43237924, 50444244, @@ -77,53 +77,53 @@ Word32 table_298[N_MAX_SHIFT_CHANGE + 1] = { 0, 1220608, 610304, 406869, 305152, 244121, 203434, 174372, 152576, 135623, 122060, 110964, 101717, 93892, 87186, 81373, 76288, 71800, 67811, 64242, 61030 -}; +}; // Q12 Word32 inv_table_298[N_MAX_SHIFT_CHANGE + 1] = { 0, 14412641, 28825283, 43237924, 57650567, 72063211, 86475849, 100888489, 115301135, 129713778, 144126422, 158539056, 172951698, 187364347, 201776979, 216189627, 230602270, 245014919, 259427557, 273840192, 288252845 -}; +}; // Q31 Word32 tableD1_298[N_MAX_SHIFT_CHANGE + 1] = { 0, 1731, 13849, 46741, 110794, 216396, 373932, 593791, 886359, 1262023, 1731170, 2304187, 2991462, 3803381, 4750330, 5842699, 7090873, 8505240, 10096185, 11874096, 13849363 -}; +}; // Q35 Word32 table_290[N_MAX_SHIFT_CHANGE + 1] = { 0, 1187840, 593920, 395946, 296960, 237568, 197973, 169691, 148480, 131982, 118784, 107985, 98986, 91372, 84845, 79189, 74240, 69872, 65991, 62517, 59392 -}; +}; // Q12 Word32 inv_table_290[N_MAX_SHIFT_CHANGE + 1] = { 0, 14810232, 29620464, 44430697, 59240928, 74051160, 88861394, 103671628, 118481856, 133292091, 148102320, 162912554, 177722789, 192533022, 207343256, 222153473, 236963712, 251773958, 266584183, 281394409, 296204640 -}; +}; // Q31 Word32 tableD1_290[N_MAX_SHIFT_CHANGE + 1] = { 0, 1878, 15027, 50717, 120219, 234803, 405740, 644300, 961755, 1369374, 1878428, 2500187, 3245924, 4126907, 5154407, 6339694, - 7694041, 9228719, 10954993, 12884138, 15027425 }; + 7694041, 9228719, 10954993, 12884138, 15027425 }; // Q35 Word32 table_145[N_MAX_SHIFT_CHANGE + 1] = { 0, 593920, 296960, 197973, 148480, 118784, 98986, 84845, 74240, 65991, 59392, 53992, 49493, 45686, 42422, 39594, 37120, 34936, 32995, 31258, 29696 -}; +}; // Q12 Word32 inv_table_145[N_MAX_SHIFT_CHANGE + 1] = { 0, 29620464, 59240928, 88861394, 118481856, 148102320, 177722789, 207343256, 236963712, 266584183, 296204640, 325825109, 355445578, 385066045, 414686513, 444306946, 473927425, 503547916, 533168367, 562788819, 592409281 -}; +}; // Q31 Word32 tableD1_145[N_MAX_SHIFT_CHANGE + 1] = { 0, 15027, 120219, 405740, 961755, 1878428, 3245924, 5154407, 7694041, 10954993, 15027425, 20001503, 25967392, 33015256, 41235259, 50717555, - 61552334, 73829752, 87639951, 103073111, 120219402 }; + 61552334, 73829752, 87639951, 103073111, 120219402 }; // Q35 #ifdef IVAS_FLOAT_FIXED static void interpTargetChannel_fx( - Word32 *target_fx, - const Word16 prevShift, - const Word16 currShift, - const Word16 L_shift_adapt ) + Word32 *target_fx, // qsynth + const Word16 prevShift, // Q0 + const Word16 currShift, // Q0 + const Word16 L_shift_adapt ) // Q0 { Word16 i, j, k, /*m,*/ d, N, signShift, lim1, lim2; const Word32 *win_fx; @@ -160,43 +160,43 @@ static void interpTargetChannel_fx( SWITCH( N ) { case 596: - table_pointer = table_596; - inv_table_pointer = inv_table_596; - table_D1_pointer = tableD1_596; + table_pointer = table_596; // Q12 + inv_table_pointer = inv_table_596; // Q31 + table_D1_pointer = tableD1_596; // Q35 BREAK; case 298: - table_pointer = table_298; - inv_table_pointer = inv_table_298; - table_D1_pointer = tableD1_298; + table_pointer = table_298; // Q12 + inv_table_pointer = inv_table_298; // Q31 + table_D1_pointer = tableD1_298; // Q35 BREAK; case 290: - table_pointer = table_290; - inv_table_pointer = inv_table_290; - table_D1_pointer = tableD1_290; + table_pointer = table_290; // Q12 + inv_table_pointer = inv_table_290; // Q31 + table_D1_pointer = tableD1_290; // Q35 BREAK; case 145: - table_pointer = table_145; - inv_table_pointer = inv_table_145; - table_D1_pointer = tableD1_145; + table_pointer = table_145; // Q12 + inv_table_pointer = inv_table_145; // Q31 + table_D1_pointer = tableD1_145; // Q35 BREAK; default: assert( 0 ); } - factor_fx = table_pointer[L_abs( d )]; + factor_fx = table_pointer[abs( d )]; // Q12 move32(); - interp_factor2_fx = L_shr( factor_fx, 1 ); - spread_factor2_fx = inv_table_pointer[L_abs( d )]; + interp_factor2_fx = L_shr( factor_fx, 1 ); // Q12 + spread_factor2_fx = inv_table_pointer[abs( d )]; // Q31 move32(); /* start from (target - N - d + 1) : (extra lag = step1) :to: (target - 1 - d) : (extra lag = d) */ /* sinc interp by a factor of 2 */ - win_fx = ica_sincInterp2_fx + SINC_ORDER1; - ptr1_fx = target_fx; + win_fx = ica_sincInterp2_fx + SINC_ORDER1; // Q31 + ptr1_fx = target_fx; // qsynth ptr2_fx = tempBuff1_fx + ( N_MAX_SHIFT_CHANGE + 1 ) * INTERP_FACTOR1; - FOR( i = -( N_MAX_SHIFT_CHANGE + 1 ) * INTERP_FACTOR1; i < imult1616( ( add( add( N, N_MAX_SHIFT_CHANGE ), 1 ) ), INTERP_FACTOR1 ); i++ ) + FOR( i = -( N_MAX_SHIFT_CHANGE + 1 ) * INTERP_FACTOR1; i < ( N + N_MAX_SHIFT_CHANGE + 1 ) * INTERP_FACTOR1; i++ ) { IF( s_and( i, 0x1 ) ) { @@ -210,38 +210,38 @@ static void interpTargetChannel_fx( FOR( j = lim1; j <= lim2; j++ ) { - ptr2_fx[i] = L_add( Mpy_32_32( win_fx[sub( imult1616( j, INTERP_FACTOR1 ), i )], ptr1_fx[j] ), ptr2_fx[i] ); + ptr2_fx[i] = L_add( Mpy_32_32( win_fx[j * INTERP_FACTOR1 - i], ptr1_fx[j] ), ptr2_fx[i] ); // qsynth move32(); } } ELSE { - ptr2_fx[i] = ptr1_fx[shr( i, 1 )]; + ptr2_fx[i] = ptr1_fx[i / 2]; // qsynth move32(); } } /* cubic spline interp */ - ptr1_fx = ptr2_fx; - ptr2_fx = tempBuff2_fx; + ptr1_fx = ptr2_fx; // qsynth + ptr2_fx = tempBuff2_fx; // qsynth - tempD1_fx = W_deposit32_l( table_D1_pointer[L_abs( d )] ); - tempD2_fx = W_mult0_32_32( 3, table_D1_pointer[L_abs( d )] ); + tempD1_fx = W_deposit32_l( table_D1_pointer[abs( d )] ); // Q35 + tempD2_fx = W_mult0_32_32( 3, table_D1_pointer[abs( d )] ); // Q35 IF( EQ_16( signShift, 1 ) ) { - tempF1_fx = ONE_IN_Q12; + tempF1_fx = ONE_IN_Q12; // Q12 move32(); } ELSE { - tempF1_fx = -ONE_IN_Q12; + tempF1_fx = -ONE_IN_Q12; // Q12 move32(); } - tempF1_fx = L_sub( imult3216( factor_fx, d ), tempF1_fx ); + tempF1_fx = L_sub( imult3216( factor_fx, d ), tempF1_fx ); // Q12 FOR( k = 0; k < sub( N, 1 ); k++ ) { - Word32 local = L_sub( W_extract_l( W_shr( W_mult0_32_32( tempF1_fx, spread_factor2_fx ), 31 ) ), ONE_IN_Q12 ); + Word32 local = L_sub( W_extract_l( W_shr( W_mult0_32_32( tempF1_fx, spread_factor2_fx ), 31 ) ), ONE_IN_Q12 ); // Q12 Word32 sign_local; IF( local > 0 ) { @@ -253,7 +253,7 @@ static void interpTargetChannel_fx( sign_local = -1; move32(); } - Word32 local_int = W_extract_l( W_shr( W_abs( local ), 12 ) ); + Word32 local_int = W_extract_l( W_shr( W_abs( local ), 12 ) ); // Q0 Word32 res_a1, res_a2, res_a3; Word32 res_b1, res_b2, res_b3; Word32 res_c1, res_c2, res_c3; @@ -262,79 +262,79 @@ static void interpTargetChannel_fx( Word64 res_a, res_b, res_c, res_d; Word64 tempa, tempb; Word64 mult_a_D1, mult_b_D2; - local_int = W_extract_l( W_mult0_32_32( sign_local, local_int ) ); - local_int_scaled = W_deposit32_l( L_shl( local_int, 12 ) ); - lim1 = extract_l( local_int ); - if ( W_sub( local_int_scaled, local ) > 0 ) + local_int = W_extract_l( W_mult0_32_32( sign_local, local_int ) ); // Q0 + local_int_scaled = W_deposit32_l( L_shl( local_int, 12 ) ); // Q12 + lim1 = extract_l( local_int ); // Q0 + IF( W_sub( local_int_scaled, local ) > 0 ) // Q21 { - lim1 = sub( lim1, 1 ); + lim1 = sub( lim1, 1 ); // Q0 } - y_fx[0] = ptr1_fx[lim1]; + y_fx[0] = ptr1_fx[lim1]; // qsynth move32(); - y_fx[1] = ptr1_fx[add( lim1, 1 )]; + y_fx[1] = ptr1_fx[lim1 + 1]; // qsynth move32(); - y_fx[2] = ptr1_fx[add( lim1, 2 )]; + y_fx[2] = ptr1_fx[lim1 + 2]; // qsynth move32(); - y_fx[3] = ptr1_fx[add( lim1, 3 )]; + y_fx[3] = ptr1_fx[lim1 + 3]; // qsynth move32(); - x_fx[0] = imult3216( interp_factor2_fx, lim1 ); + x_fx[0] = imult3216( interp_factor2_fx, lim1 ); // Q12 move32(); - x_fx[1] = L_add( x_fx[0], interp_factor2_fx ); + x_fx[1] = L_add( x_fx[0], interp_factor2_fx ); // Q12 move32(); - x_fx[2] = L_add( x_fx[1], interp_factor2_fx ); + x_fx[2] = L_add( x_fx[1], interp_factor2_fx ); // Q12 move32(); - x_fx[3] = L_add( x_fx[2], interp_factor2_fx ); + x_fx[3] = L_add( x_fx[2], interp_factor2_fx ); // Q12 move32(); - res_a1 = L_sub( tempF1_fx, x_fx[0] ); - res_a2 = L_sub( tempF1_fx, x_fx[1] ); - res_a3 = L_sub( tempF1_fx, x_fx[2] ); - res_a = W_shr( W_mult0_32_32( res_a1, res_a2 ), 12 ) * res_a3; - res_a = ( y_fx[3] * W_shr( res_a, 16 ) ); + res_a1 = L_sub( tempF1_fx, x_fx[0] ); // Q12 + res_a2 = L_sub( tempF1_fx, x_fx[1] ); // Q12 + res_a3 = L_sub( tempF1_fx, x_fx[2] ); // Q12 + res_a = W_shr( W_mult0_32_32( res_a1, res_a2 ), 12 ) * res_a3; // Q24 + res_a = ( y_fx[3] * W_shr( res_a, 16 ) ); // qsynth+8 - res_b1 = L_sub( tempF1_fx, x_fx[1] ); - res_b2 = L_sub( tempF1_fx, x_fx[2] ); - res_b3 = L_sub( tempF1_fx, x_fx[3] ); - res_b = W_shr( W_mult0_32_32( res_b1, res_b2 ), 12 ) * res_b3; - res_b = ( y_fx[0] * W_shr( res_b, 16 ) ); + res_b1 = L_sub( tempF1_fx, x_fx[1] ); // Q12 + res_b2 = L_sub( tempF1_fx, x_fx[2] ); // Q12 + res_b3 = L_sub( tempF1_fx, x_fx[3] ); // Q12 + res_b = W_shr( W_mult0_32_32( res_b1, res_b2 ), 12 ) * res_b3; // Q24 + res_b = ( y_fx[0] * W_shr( res_b, 16 ) ); // qsynth+8 - res_c1 = L_sub( tempF1_fx, x_fx[0] ); - res_c2 = L_sub( tempF1_fx, x_fx[2] ); - res_c3 = L_sub( tempF1_fx, x_fx[3] ); - res_c = W_shr( W_mult0_32_32( res_c1, res_c2 ), 12 ) * res_c3; - res_c = ( y_fx[1] * W_shr( res_c, 16 ) ); + res_c1 = L_sub( tempF1_fx, x_fx[0] ); // Q12 + res_c2 = L_sub( tempF1_fx, x_fx[2] ); // Q12 + res_c3 = L_sub( tempF1_fx, x_fx[3] ); // Q12 + res_c = W_shr( W_mult0_32_32( res_c1, res_c2 ), 12 ) * res_c3; // Q24 + res_c = ( y_fx[1] * W_shr( res_c, 16 ) ); // qsynth+8 - res_d1 = L_sub( tempF1_fx, x_fx[0] ); - res_d2 = L_sub( tempF1_fx, x_fx[1] ); - res_d3 = L_sub( tempF1_fx, x_fx[3] ); - res_d = W_shr( W_mult0_32_32( res_d1, res_d2 ), 12 ) * res_d3; - res_d = ( y_fx[2] * W_shr( res_d, 16 ) ); + res_d1 = L_sub( tempF1_fx, x_fx[0] ); // Q12 + res_d2 = L_sub( tempF1_fx, x_fx[1] ); // Q12 + res_d3 = L_sub( tempF1_fx, x_fx[3] ); // Q12 + res_d = W_shr( W_mult0_32_32( res_d1, res_d2 ), 12 ) * res_d3; // Q24 + res_d = ( y_fx[2] * W_shr( res_d, 16 ) ); // qsynth+8 - tempa = W_sub( res_a, res_b ); - tempb = W_sub( res_c, res_d ); + tempa = W_sub( res_a, res_b ); // qsynth+8 + tempb = W_sub( res_c, res_d ); // qsynth+8 - mult_a_D1 = W_shr( ( tempD1_fx * W_shr( tempa, 14 ) ), 15 ); - mult_b_D2 = W_shr( ( tempD2_fx * W_shr( tempb, 14 ) ), 15 ); + mult_a_D1 = W_shr( ( tempD1_fx * W_shr( tempa, 14 ) ), 15 ); // Q38 + mult_b_D2 = W_shr( ( tempD2_fx * W_shr( tempb, 14 ) ), 15 ); // Q38 ptr2_fx[k] = W_extract_l( ( W_shr( W_add( mult_a_D1, mult_b_D2 ), 14 ) ) ); // 38-14 move32(); IF( EQ_16( signShift, 1 ) ) { - tempF1_fx = W_extract_l( W_add( tempF1_fx, L_sub( factor_fx, ONE_IN_Q12 ) ) ); + tempF1_fx = W_extract_l( W_add( tempF1_fx, L_sub( factor_fx, ONE_IN_Q12 ) ) ); // Q12 move32(); } ELSE { - tempF1_fx = W_extract_l( W_add( tempF1_fx, L_sub( factor_fx, -ONE_IN_Q12 ) ) ); + tempF1_fx = W_extract_l( W_add( tempF1_fx, L_sub( factor_fx, -ONE_IN_Q12 ) ) ); // Q12 move32(); } } - ptr1_fx = target_fx; - Copy32( ptr2_fx, ptr1_fx, sub( N, 1 ) ); + ptr1_fx = target_fx; // qsynth + Copy32( ptr2_fx, ptr1_fx, sub( N, 1 ) ); // qsynth return; } @@ -347,10 +347,10 @@ static void interpTargetChannel_fx( * ---------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED static void targetCh_AlignStereoDFT_fx( - Word32 *target_fx, - const Word16 prevShift, - const Word16 currShift, - const Word16 L_shift_adapt ) + Word32 *target_fx, // qsynth + const Word16 prevShift, // Q0 + const Word16 currShift, // Q0 + const Word16 L_shift_adapt ) // Q0 { Word16 i; Word32 winSlope_fx, alpha_fx; @@ -359,10 +359,10 @@ static void targetCh_AlignStereoDFT_fx( Word32 fadeOutBuff_fx[L_SHIFT_ADAPT_MAX]; Word32 fadeInBuff_fx[L_SHIFT_ADAPT_MAX]; - d = negate( sub( currShift, prevShift ) ); + d = negate( sub( currShift, prevShift ) ); // Q0 - Copy32( target_fx + d, fadeOutBuff_fx, L_shift_adapt ); - Copy32( target_fx, fadeInBuff_fx, L_shift_adapt ); + Copy32( target_fx + d, fadeOutBuff_fx, L_shift_adapt ); // qsynth + Copy32( target_fx, fadeInBuff_fx, L_shift_adapt ); // qsynth IF( L_shift_adapt > 0 ) { @@ -370,37 +370,37 @@ static void targetCh_AlignStereoDFT_fx( SWITCH( L_shift_adapt ) { case 596: - winSlope_fx = 3603160; + winSlope_fx = 3603160; /* ( 1 / 596 ) in Q31 */ // Q31 move32(); BREAK; case 298: - winSlope_fx = 7206320; + winSlope_fx = 7206320; /* ( 1 / 298 ) in Q31 */ // Q31 move32(); BREAK; case 290: - winSlope_fx = 7405116; + winSlope_fx = 7405116; /* ( 1 / 290 ) in Q31 */ // Q31 move32(); BREAK; case 145: - winSlope_fx = 14810232; + winSlope_fx = 14810232; /* ( 1 / 145 ) in Q31 */ // Q31 move32(); BREAK; default: - winSlope_fx = ONE_IN_Q31; + winSlope_fx = ONE_IN_Q31; // Q31 move32(); BREAK; } FOR( i = 0; i < L_shift_adapt; i++ ) { - target_fx[i] = L_add( Mpy_32_32( alpha_fx, fadeInBuff_fx[i] ), Mpy_32_32( L_sub( ONE_IN_Q31, alpha_fx ), fadeOutBuff_fx[i] ) ); + target_fx[i] = L_add( Mpy_32_32( alpha_fx, fadeInBuff_fx[i] ), Mpy_32_32( L_sub( ONE_IN_Q31, alpha_fx ), fadeOutBuff_fx[i] ) ); // qsynth move32(); - alpha_fx = L_add_sat( alpha_fx, winSlope_fx ); + alpha_fx = L_add_sat( alpha_fx, winSlope_fx ); // Q31 } } ELSE { - Copy32( fadeInBuff_fx, target_fx, L_shift_adapt ); + Copy32( fadeInBuff_fx, target_fx, L_shift_adapt ); // qsynth } return; @@ -414,11 +414,11 @@ static void targetCh_AlignStereoDFT_fx( * ---------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED void adjustTargetSignal_fx( - Word32 *target_fx, - const Word16 prevShift, - const Word16 currShift, - const Word16 L_shift_adapt, - const Word16 method ) + Word32 *target_fx, // qsynth + const Word16 prevShift, // Q0 + const Word16 currShift, // Q0 + const Word16 L_shift_adapt, // Q0 + const Word16 method ) // Q0 { /* inter-frame shift variation and target shifting */ diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index 4bead686b..089a92b53 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -4047,20 +4047,25 @@ Word16 getTcxLpcShapedAri( ); // tcx_mdct_window.c -void mdct_window_sine( PWord16 *window, Word16 n ); +void mdct_window_sine( + PWord16 *window, /* Qx */ + Word16 n /* Q0 */ +); void mdct_window_sine_IVAS_updated( - PWord16 *window, - const int32_t Fs, - const int16_t n, - const int16_t window_type, - const int16_t element_mode ); + PWord16 *window, /* Qx */ + const Word32 Fs, /* Q0 */ + const Word16 n, /* Q0 */ + const Word16 window_type, /* Q0 */ + const Word16 element_mode /* Q0 */ +); void mdct_window_aldo( - Word16 *window1, - PWord16 *window1_trunc, - PWord16 *window2, - Word16 n ); + Word16 *window1, /* Q15 */ + PWord16 *window1_trunc, /* Q15 */ + PWord16 *window2, /* Q15 */ + Word16 n /* Q0 */ +); // tcx_utils.c Word16 getInvFrameLen( const Word16 L_frame ); /* returns 1/L_frame in Q21 format */ @@ -5578,53 +5583,58 @@ void phase_dispersion( // tcx_ltp_fx.c void tcx_ltp_get_lpc( - Word16 *x, - const Word16 L, - Word16 *A, - const Word16 order ); + Word16 *x, /* Qx */ + const Word16 L, /* Q0 */ + Word16 *A, /* Qx */ + const Word16 order /* Q0 */ +); void tcx_ltp_get_lpc_fx( - Word32 *x, - const Word16 L, - Word32 *A, - const Word16 order ); + Word32 *x, /* Qx */ + const Word16 L, /* Q0 */ + Word32 *A, /* Qx */ + const Word16 order /* Q0 */ +); void predict_signal( - const Word16 excI[], /* i : i excitation buffer */ - Word16 excO[], /* o : output excitation buffer */ - const Word16 T0, /* i : integer pitch lag */ - Word16 frac, /* i : fraction of lag */ - const Word16 frac_max, /* i : max fraction */ - const Word16 L_subfr /* i : subframe size */ -); - -Word16 tcx_ltp_decode_params( Word16 *ltp_param, - Word16 *pitch_int, - Word16 *pitch_fr, - Word16 *gain, - const Word16 pitmin, - const Word16 pitfr1, - const Word16 pitfr2, - const Word16 pitmax, - const Word16 pitres ); + const Word16 excI[], /* i : input excitation buffer Qx*/ + Word16 excO[], /* o : output excitation buffer Qx*/ + const Word16 T0, /* i : integer pitch lag Q0*/ + Word16 frac, /* i : fraction of lag Q0*/ + const Word16 frac_max, /* i : max fraction Q0*/ + const Word16 L_subfr /* i : subframe size Q0*/ +); + +Word16 tcx_ltp_decode_params( + Word16 *ltp_param, /* Q0 */ + Word16 *pitch_int, /* Q0 */ + Word16 *pitch_fr, /* Q0 */ + Word16 *gain, /* Q13 */ + const Word16 pitmin, /* Q0 */ + const Word16 pitfr1, /* Q0 */ + const Word16 pitfr2, /* Q0 */ + const Word16 pitmax, /* Q0 */ + const Word16 pitres /* Q0 */ +); void tcx_ltp_post( Decoder_State *st, TCX_LTP_DEC_HANDLE hTcxLtpDec, - Word16 core, - Word16 output_frame, - Word16 delay, - Word16 *sig, - Word16 *tcx_buf ); + Word16 core, /* Q0 */ + Word16 output_frame, /* Q0 */ + Word16 delay, /* Q0 */ + Word16 *sig, /* Qx */ + Word16 *tcx_buf /* Qx */ +); void tcx_ltp_post32( Decoder_State *st, TCX_LTP_DEC_HANDLE hTcxLtpDec, - Word16 core, - Word16 output_frame, - Word16 delay, - Word32 *sig, - Word32 *tcx_buf, + Word16 core, /* Q0 */ + Word16 output_frame, /* Q0 */ + Word16 delay, /* Q0 */ + Word32 *sig, /* sig_q */ + Word32 *tcx_buf, /* sig_q */ Word16 sig_q ); // gs_inact_switching_fx.c diff --git a/lib_com/tcx_ltp_fx.c b/lib_com/tcx_ltp_fx.c index 89965f8de..a42272f0b 100644 --- a/lib_com/tcx_ltp_fx.c +++ b/lib_com/tcx_ltp_fx.c @@ -17,10 +17,11 @@ #define MAX_TRANSITION_LEN 240 /* L_FRAME_48K / 4 */ void tcx_ltp_get_lpc( - Word16 *x, - const Word16 L, - Word16 *A, - const Word16 order ) + Word16 *x, /* Qx */ + const Word16 L, /* Q0 */ + Word16 *A, /* Qx */ + const Word16 order /* Q0 */ +) { Word16 i, j, s, s2, tmp; Word32 r, L_tmp; @@ -37,25 +38,25 @@ void tcx_ltp_get_lpc( r = L_deposit_l( 0 ); FOR( j = 0; j < L; j++ ) { - L_tmp = L_sub( r, 0x40000000 ); + L_tmp = L_sub( r, 0x40000000 /* 1 in Q30 */ ); /* Q30 */ if ( L_tmp > 0 ) s = sub( s, 1 ); if ( L_tmp > 0 ) r = L_shr( r, 2 ); - tmp = shl( x[j], s ); + tmp = shl( x[j], s ); /* Qx + s */ #ifdef BASOP_NOGLOB - r = L_mac0_sat( r, tmp, tmp ); + r = L_mac0_sat( r, tmp, tmp ); /* Q30 */ #else r = L_mac0( r, tmp, tmp ); #endif } - r = L_max( r, L_shl( 100, shl( s, 1 ) ) ); - r = Mpy_32_16_1( r, 16386 /*1.0001f Q14*/ ); + r = L_max( r, L_shl( 100, shl( s, 1 ) ) ); /* Q30 */ + r = Mpy_32_16_1( r, 16386 /*1.0001f Q14*/ ); /* Q29 */ s2 = norm_l( r ); r = L_shl( r, s2 ); s2 = sub( s2, 1 ); - r_l[0] = L_Extract_lc( r, &r_h[0] ); + r_l[0] = L_Extract_lc( r, &r_h[0] ); /* Q14 */ move16(); move16(); @@ -70,18 +71,18 @@ void tcx_ltp_get_lpc( move64(); FOR( j = 0; j < L; j++ ) { - tmpbuf[j] = mult_r( x[j], tmp ); + tmpbuf[j] = mult_r( x[j], tmp ); /* Qx */ move16(); - r64 = W_mac0_16_16( r64, tmpbuf[j], tmpbuf[j] ); + r64 = W_mac0_16_16( r64, tmpbuf[j], tmpbuf[j] ); /* Q30 */ } - r = W_sat_l( r64 ); + r = W_sat_l( r64 ); /* Q30 */ } - r = L_max( r, L_shl( 100, shl( s, 1 ) ) ); - r = Mpy_32_16_1( r, 16386 /*1.0001f Q14*/ ); + r = L_max( r, L_shl( 100, shl( s, 1 ) ) ); /* Q30 */ + r = Mpy_32_16_1( r, 16386 /*1.0001f Q14*/ ); /* Q29 */ s2 = norm_l( r ); r = L_shl( r, s2 ); s2 = sub( s2, 1 ); - r_l[0] = L_Extract_lc( r, &r_h[0] ); + r_l[0] = L_Extract_lc( r, &r_h[0] ); /* Q14 */ move16(); move16(); @@ -99,12 +100,12 @@ void tcx_ltp_get_lpc( move64(); FOR( j = 0; j < tmp; j++ ) { - r64 = W_mac0_16_16( r64, p[j], p[j + i] ); + r64 = W_mac0_16_16( r64, p[j], p[j + i] ); /* Q30 */ } r = W_sat_l( r64 ); } r = L_shl( r, s2 ); - r_l[i] = L_Extract_lc( r, &r_h[i] ); + r_l[i] = L_Extract_lc( r, &r_h[i] ); /* Q14 */ move16(); move16(); } @@ -113,10 +114,11 @@ void tcx_ltp_get_lpc( } void tcx_ltp_get_lpc_fx( - Word32 *x, - const Word16 L, - Word32 *A, - const Word16 order ) + Word32 *x, /* Qx */ + const Word16 L, /* Q0 */ + Word32 *A, /* Qx */ + const Word16 order /* Q0 */ +) { Word16 i, j, s, s2; Word32 r, tmp, L_tmp; @@ -133,21 +135,21 @@ void tcx_ltp_get_lpc_fx( r = L_deposit_l( 0 ); FOR( j = 0; j < L; j++ ) { - L_tmp = L_sub( r, 0x40000000 ); + L_tmp = L_sub( r, 0x40000000 /* 1 in Q30 */ ); /* Q30 */ if ( L_tmp > 0 ) s = sub( s, 1 ); if ( L_tmp > 0 ) r = L_shr( r, 2 ); - tmp = L_shl( x[j], s ); + tmp = L_shl( x[j], s ); /* Qx + s */ r = Madd_32_32( r, tmp, tmp ); } - r = L_max( r, L_shl( 100, shl( s, 1 ) ) ); - r = Mpy_32_16_1( r, 16386 /*1.0001f Q14*/ ); + r = L_max( r, L_shl( 100, shl( s, 1 ) ) ); /* Q30 */ + r = Mpy_32_16_1( r, 16386 /*1.0001f Q14*/ ); /* Q29 */ s2 = norm_l( r ); r = L_shl( r, s2 ); s2 = sub( s2, 1 ); - r_l[0] = L_Extract_lc( r, &r_h[0] ); + r_l[0] = L_Extract_lc( r, &r_h[0] ); /* Q14 */ move16(); move16(); @@ -168,12 +170,12 @@ void tcx_ltp_get_lpc_fx( } r = W_sat_l( r64 ); } - r = L_max( r, L_shl( 100, shl( s, 1 ) ) ); - r = Mpy_32_16_1( r, 16386 /*1.0001f Q14*/ ); + r = L_max( r, L_shl( 100, shl( s, 1 ) ) ); /* Q30 */ + r = Mpy_32_16_1( r, 16386 /*1.0001f Q14*/ ); /* Q29 */ s2 = norm_l( r ); r = L_shl( r, s2 ); s2 = sub( s2, 1 ); - r_l[0] = L_Extract_lc( r, &r_h[0] ); + r_l[0] = L_Extract_lc( r, &r_h[0] ); /* Q14 */ move16(); move16(); @@ -191,12 +193,12 @@ void tcx_ltp_get_lpc_fx( move64(); FOR( j = 0; j < tmp; j++ ) { - r64 = W_add( r64, Mpy_32_32( p[j], p[j + i] ) ); + r64 = W_add( r64, Mpy_32_32( p[j], p[j + i] ) ); /* Q30 */ } r = W_sat_l( r64 ); } r = L_shl( r, s2 ); - r_l[i] = L_Extract_lc( r, &r_h[i] ); + r_l[i] = L_Extract_lc( r, &r_h[i] ); /* Q14 */ move16(); move16(); } @@ -205,17 +207,18 @@ void tcx_ltp_get_lpc_fx( } static void tcx_ltp_get_zir( - Word16 *zir, - const Word16 length, - Word16 *synth_ltp, - Word16 *synth, - Word16 *A, - const Word16 lpcorder, - const Word16 gain, - const Word16 pitch_int, - const Word16 pitch_fr, - const Word16 pitres, - const Word16 filtIdx ) + Word16 *zir, /* Qx */ + const Word16 length, /* Q0 */ + Word16 *synth_ltp, /* Qx */ + Word16 *synth, /* Qx */ + Word16 *A, /* Qx */ + const Word16 lpcorder, /* Q0 */ + const Word16 gain, /* Q15 */ + const Word16 pitch_int, /* Q0 */ + const Word16 pitch_fr, /* Q0 */ + const Word16 pitres, /* Q0 */ + const Word16 filtIdx /* Q0 */ +) { Word16 buf[TCXLTP_LTP_ORDER], alpha, step; Word16 *x0, *x1; @@ -224,18 +227,18 @@ static void tcx_ltp_get_zir( const Word16 *w0, *w1, *v0, *v1; Word16 i, j, k, L; - x0 = &synth_ltp[-pitch_int]; + x0 = &synth_ltp[-pitch_int]; /* Qx */ x1 = x0 - 1; - y0 = synth; + y0 = synth; /* Qx */ y1 = y0 - 1; assert( filtIdx >= 0 ); - w0 = &tcxLtpFilters[filtIdx].filt[pitch_fr]; - w1 = &tcxLtpFilters[filtIdx].filt[sub( pitres, pitch_fr )]; - v0 = &tcxLtpFilters[filtIdx].filt[0]; - v1 = &tcxLtpFilters[filtIdx].filt[pitres]; - L = tcxLtpFilters[filtIdx].length; + w0 = &tcxLtpFilters[filtIdx].filt[pitch_fr]; /* Q15 */ + w1 = &tcxLtpFilters[filtIdx].filt[pitres - pitch_fr]; /* Q15 */ + v0 = &tcxLtpFilters[filtIdx].filt[0]; /* Q15 */ + v1 = &tcxLtpFilters[filtIdx].filt[pitres]; /* Q15 */ + L = tcxLtpFilters[filtIdx].length; /* Q0 */ move16(); FOR( j = 0; j < lpcorder; j++ ) @@ -247,20 +250,20 @@ static void tcx_ltp_get_zir( FOR( i = 0; i < L; i++ ) { #ifdef BASOP_NOGLOB - s = L_mac_sat( L_mac_sat( s, w0[k], x0[i] ), w1[k], x1[-i] ); - s2 = L_mac_sat( L_mac_sat( s2, v0[k], y0[i] ), v1[k], y1[-i] ); + s = L_mac_sat( L_mac_sat( s, w0[k], x0[i] ), w1[k], x1[-i] ); /* Qx */ + s2 = L_mac_sat( L_mac_sat( s2, v0[k], y0[i] ), v1[k], y1[-i] ); /* Qx */ #else s = L_mac( L_mac( s, w0[k], x0[i] ), w1[k], x1[-i] ); s2 = L_mac( L_mac( s2, v0[k], y0[i] ), v1[k], y1[-i] ); #endif - k = add( k, pitres ); + k = k + pitres; } /* s2 *= ALPHA; buf[j] = ( synth[j] - gain * s2 ) - ( synth_ltp[j] - gain * s ); */ #ifdef BASOP_NOGLOB i = sub_sat( round_fx_sat( s ), mult_r_sat( round_fx_sat( s2 ), ALPHA ) ); - buf[j] = add_sat( sub_sat( synth[j], synth_ltp[j] ), mult_r_sat( gain, i ) ); + buf[j] = add_sat( sub_sat( synth[j], synth_ltp[j] ), mult_r_sat( gain, i ) ); /* Qx */ #else i = sub( round_fx( s ), mult_r( round_fx( s2 ), ALPHA ) ); buf[j] = add( sub( synth[j], synth_ltp[j] ), mult_r( gain, i ) ); @@ -277,13 +280,13 @@ static void tcx_ltp_get_zir( E_UTIL_synthesis( 0, A, zir, zir, length, buf, 0, lpcorder ); - alpha = 0x7FFF; + alpha = 0x7FFF; /* 1 in Q15 */ move16(); /* step = 1.f/(float)(length/2); */ step = shl( 4, norm_s( length ) ); if ( s_and( length, sub( length, 1 ) ) != 0 ) { - step = mult_r( step, 26214 /*64.f/80.f Q15*/ ); + step = mult_r( step, 26214 /*64.f/80.f Q15*/ ); /* Q15 */ } if ( EQ_16( length, 240 ) ) { @@ -291,26 +294,27 @@ static void tcx_ltp_get_zir( move16(); } - FOR( j = shr( length, 1 ); j < length; j++ ) + FOR( j = length / 2; j < length; j++ ) { - zir[j] = mult_r( zir[j], alpha ); + zir[j] = mult_r( zir[j], alpha ); /* Qx */ move16(); alpha = sub( alpha, step ); } } static void tcx_ltp_get_zir_fx( - Word32 *zir, - const Word16 length, - Word32 *synth_ltp, - Word32 *synth, - Word32 *A, - const Word16 lpcorder, - const Word16 gain, - const Word16 pitch_int, - const Word16 pitch_fr, - const Word16 pitres, - const Word16 filtIdx ) + Word32 *zir, /* Qx */ + const Word16 length, /* Q0 */ + Word32 *synth_ltp, /* Qx */ + Word32 *synth, /* Qx */ + Word32 *A, /* Qx */ + const Word16 lpcorder, /* Q0 */ + const Word16 gain, /* Q15 */ + const Word16 pitch_int, /* Q0 */ + const Word16 pitch_fr, /* Q0 */ + const Word16 pitres, /* Q0 */ + const Word16 filtIdx /* Q0 */ +) { Word32 buf[TCXLTP_LTP_ORDER]; Word16 alpha, step; @@ -321,18 +325,18 @@ static void tcx_ltp_get_zir_fx( Word32 i; Word16 j, k, L; - x0 = &synth_ltp[-pitch_int]; + x0 = &synth_ltp[-pitch_int]; /* Qx */ x1 = x0 - 1; - y0 = synth; + y0 = synth; /* Qx */ y1 = y0 - 1; assert( filtIdx >= 0 ); - w0 = &tcxLtpFilters[filtIdx].filt[pitch_fr]; - w1 = &tcxLtpFilters[filtIdx].filt[sub( pitres, pitch_fr )]; - v0 = &tcxLtpFilters[filtIdx].filt[0]; - v1 = &tcxLtpFilters[filtIdx].filt[pitres]; - L = tcxLtpFilters[filtIdx].length; + w0 = &tcxLtpFilters[filtIdx].filt[pitch_fr]; /* Q15 */ + w1 = &tcxLtpFilters[filtIdx].filt[pitres - pitch_fr]; /* Q15 */ + v0 = &tcxLtpFilters[filtIdx].filt[0]; /* Q15 */ + v1 = &tcxLtpFilters[filtIdx].filt[pitres]; /* Q15 */ + L = tcxLtpFilters[filtIdx].length; /* Q0 */ move16(); FOR( j = 0; j < lpcorder; j++ ) @@ -343,15 +347,15 @@ static void tcx_ltp_get_zir_fx( move16(); FOR( i = 0; i < L; i++ ) { - s = Madd_32_16_r( Madd_32_16_r( s, x0[i], w0[k] ), x1[-i], w1[k] ); - s2 = Madd_32_16_r( Madd_32_16_r( s2, y0[i], v0[k] ), y1[-i], v1[k] ); - k = add( k, pitres ); + s = Madd_32_16_r( Madd_32_16_r( s, x0[i], w0[k] ), x1[-i], w1[k] ); /* Qx */ + s2 = Madd_32_16_r( Madd_32_16_r( s2, y0[i], v0[k] ), y1[-i], v1[k] ); /* Qx */ + k = k + pitres; } /* s2 *= ALPHA; buf[j] = ( synth[j] - gain * s2 ) - ( synth_ltp[j] - gain * s ); */ - i = L_sub_sat( s, Mpy_32_16_1( s2, ALPHA ) ); - buf[j] = L_add_sat( L_sub_sat( synth[j], synth_ltp[j] ), Mpy_32_16_1( i, gain ) ); + i = L_sub_sat( s, Mpy_32_16_1( s2, ALPHA ) ); /* Qx */ + buf[j] = L_add_sat( L_sub_sat( synth[j], synth_ltp[j] ), Mpy_32_16_1( i, gain ) ); /* Qx */ move16(); @@ -365,13 +369,13 @@ static void tcx_ltp_get_zir_fx( E_UTIL_synthesis_fx( 0, A, zir, zir, length, buf, 0, lpcorder ); - alpha = 0x7FFF; + alpha = 0x7FFF; /* 1 in Q15 */ move16(); /* step = 1.f/(float)(length/2); */ step = shl( 4, norm_s( length ) ); if ( s_and( length, sub( length, 1 ) ) != 0 ) { - step = mult_r( step, 26214 /*64.f/80.f Q15*/ ); + step = mult_r( step, 26214 /*64.f/80.f Q15*/ ); /* Q15 */ } if ( EQ_16( length, 240 ) ) { @@ -381,19 +385,19 @@ static void tcx_ltp_get_zir_fx( FOR( j = shr( length, 1 ); j < length; j++ ) { - zir[j] = Mpy_32_16_r( zir[j], alpha ); + zir[j] = Mpy_32_16_r( zir[j], alpha ); /* Qx */ move32(); alpha = sub( alpha, step ); } } void predict_signal( - const Word16 excI[], /* i : input excitation buffer */ - Word16 excO[], /* o : output excitation buffer */ - const Word16 T0, /* i : integer pitch lag */ - Word16 frac, /* i : fraction of lag */ - const Word16 frac_max, /* i : max fraction */ - const Word16 L_subfr /* i : subframe size */ + const Word16 excI[], /* i : input excitation buffer Qx*/ + Word16 excO[], /* o : output excitation buffer Qx*/ + const Word16 T0, /* i : integer pitch lag Q0*/ + Word16 frac, /* i : fraction of lag Q0*/ + const Word16 frac_max, /* i : max fraction Q0*/ + const Word16 L_subfr /* i : subframe size Q0*/ ) { Word16 j; @@ -412,17 +416,17 @@ void predict_signal( x0--; } - win = &inter4_2tcx2[frac][0]; + win = &inter4_2tcx2[frac][0]; /* Q15 */ if ( EQ_16( frac_max, 6 ) ) - win = &inter6_2tcx2[frac][0]; + win = &inter6_2tcx2[frac][0]; /* Q15 */ FOR( j = 0; j < L_subfr; j++ ) { #ifdef BASOP_NOGLOB - s = L_mult_o( win[0], x0[0], &Overflow ); - s = L_mac_o( s, win[1], x0[1], &Overflow ); - s = L_mac_o( s, win[2], x0[2], &Overflow ); - excO[j] = mac_ro( s, win[3], x0[3], &Overflow ); + s = L_mult_o( win[0], x0[0], &Overflow ); /* Qx + 16 */ + s = L_mac_o( s, win[1], x0[1], &Overflow ); /* Qx + 16 */ + s = L_mac_o( s, win[2], x0[2], &Overflow ); /* Qx + 16 */ + excO[j] = mac_ro( s, win[3], x0[3], &Overflow ); /* Qx + 16 */ #else s = L_mult( win[0], x0[0] ); s = L_mac( s, win[1], x0[1] ); @@ -436,16 +440,17 @@ void predict_signal( } static void tcx_ltp_synth_filter( - Word16 *synth_ltp, - Word16 *synth, - Word16 length, - Word16 pitch_int, - Word16 pitch_fr, - Word16 gain, - Word16 pitch_res, - Word16 *zir, /* can be NULL */ - Word16 fade, /* 0=normal, +1=fade-in, -1=fade-out */ - Word16 filtIdx ) + Word16 *synth_ltp, /* Qx */ + Word16 *synth, /* Qx */ + Word16 length, /* Q0 */ + Word16 pitch_int, /* Q0 */ + Word16 pitch_fr, /* Q0 */ + Word16 gain, /* Q15 */ + Word16 pitch_res, /* Q0 */ + Word16 *zir, /* can be NULL */ + Word16 fade, /* 0=normal, +1=fade-in, -1=fade-out Q0*/ + Word16 filtIdx /* Q0 */ +) { Word16 *x0, *x1; Word16 *y0, *y1; @@ -458,19 +463,19 @@ static void tcx_ltp_synth_filter( IF( gain > 0 ) { - x0 = &synth_ltp[-pitch_int]; + x0 = &synth_ltp[-pitch_int]; /* Qx */ x1 = x0 - 1; - y0 = synth; + y0 = synth; /* Qx */ y1 = y0 - 1; assert( filtIdx >= 0 ); - w0 = &tcxLtpFilters[filtIdx].filt[pitch_fr]; - w1 = &tcxLtpFilters[filtIdx].filt[sub( pitch_res, pitch_fr )]; - v0 = &tcxLtpFilters[filtIdx].filt[0]; - v1 = &tcxLtpFilters[filtIdx].filt[pitch_res]; + w0 = &tcxLtpFilters[filtIdx].filt[pitch_fr]; /* Q15 */ + w1 = &tcxLtpFilters[filtIdx].filt[pitch_res - pitch_fr]; /* Q15 */ + v0 = &tcxLtpFilters[filtIdx].filt[0]; /* Q15 */ + v1 = &tcxLtpFilters[filtIdx].filt[pitch_res]; /* Q15 */ - L = tcxLtpFilters[filtIdx].length; + L = tcxLtpFilters[filtIdx].length; /* Q0 */ move16(); alpha = 0; @@ -479,7 +484,7 @@ static void tcx_ltp_synth_filter( { if ( fade < 0 ) { - alpha = 0x7FFF; + alpha = 0x7FFF; /* 1 in Q15 */ move16(); } @@ -487,7 +492,7 @@ static void tcx_ltp_synth_filter( step = shl( 2, norm_s( length ) ); if ( s_and( length, sub( length, 1 ) ) != 0 ) { - step = mult_r( step, 26214 /*64.f/80.f Q15*/ ); + step = mult_r( step, 26214 /*64.f/80.f Q15*/ ); /* Q15 */ } if ( EQ_16( length, 240 ) ) { @@ -508,13 +513,13 @@ static void tcx_ltp_synth_filter( FOR( i = 0; i < L; i++ ) { #ifdef BASOP_NOGLOB - s = L_mac_sat( L_mac_sat( s, w0[k], x0[i] ), w1[k], x1[-i] ); - s2 = L_mac_sat( L_mac_sat( s2, v0[k], y0[i] ), v1[k], y1[-i] ); + s = L_mac_sat( L_mac_sat( s, w0[k], x0[i] ), w1[k], x1[-i] ); /* Qx */ + s2 = L_mac_sat( L_mac_sat( s2, v0[k], y0[i] ), v1[k], y1[-i] ); /* Qx */ #else s = L_mac( L_mac( s, w0[k], x0[i] ), w1[k], x1[-i] ); s2 = L_mac( L_mac( s2, v0[k], y0[i] ), v1[k], y1[-i] ); #endif - k = add( k, pitch_res ); + k = k + pitch_res; } /* s2 *= ALPHA; @@ -522,18 +527,18 @@ static void tcx_ltp_synth_filter( zir: synth_ltp[j] = synth[j] - gain * s2 + gain * s - zir[j]; fade-in/out: synth_ltp[j] = synth[j] - alpha * gain * s2 + alpha * gain * s; */ #ifdef BASOP_NOGLOB - i = sub_sat( round_fx_sat( s ), mult_r_sat( round_fx_sat( s2 ), ALPHA ) ); + i = sub_sat( round_fx_sat( s ), mult_r_sat( round_fx_sat( s2 ), ALPHA ) ); /* Qx */ #else i = sub( round_fx( s ), mult_r( round_fx( s2 ), ALPHA ) ); #endif - k = mult_r( gain, i ); + k = mult_r( gain, i ); /* Qx */ if ( fade != 0 ) - k = mult_r( k, alpha ); + k = mult_r( k, alpha ); /* Qx */ #ifdef BASOP_NOGLOB - k = add_sat( synth[j], k ); + k = add_sat( synth[j], k ); /* Qx */ if ( zir != NULL ) { - k = sub_sat( k, zir[j] ); + k = sub_sat( k, zir[j] ); /* Qx */ } #else k = add( synth[j], k ); @@ -541,7 +546,7 @@ static void tcx_ltp_synth_filter( k = sub( k, zir[j] ); #endif - synth_ltp[j] = k; + synth_ltp[j] = k; /* Qx */ move16(); BASOP_SATURATE_WARNING_OFF_EVS; @@ -564,21 +569,22 @@ static void tcx_ltp_synth_filter( } ELSE { - Copy( synth, synth_ltp, length ); + Copy( synth, synth_ltp, length ); /* Qx */ } } static void tcx_ltp_synth_filter32( - Word32 *synth_ltp, - Word32 *synth, - Word16 length, - Word16 pitch_int, - Word16 pitch_fr, - Word16 gain, - Word16 pitch_res, - Word32 *zir, /* can be NULL */ - Word16 fade, /* 0=normal, +1=fade-in, -1=fade-out */ - Word16 filtIdx ) + Word32 *synth_ltp, /* Qx */ + Word32 *synth, /* Qx */ + Word16 length, /* Q0 */ + Word16 pitch_int, /* Q0 */ + Word16 pitch_fr, /* Q0 */ + Word16 gain, /* Q15 */ + Word16 pitch_res, /* Q0 */ + Word32 *zir, /* can be NULL Qx*/ + Word16 fade, /* 0=normal, +1=fade-in, -1=fade-out Q0*/ + Word16 filtIdx /* Q0 */ +) { Word32 *x0, *x1; Word32 *y0, *y1; @@ -591,19 +597,19 @@ static void tcx_ltp_synth_filter32( IF( gain > 0 ) { - x0 = &synth_ltp[-pitch_int]; + x0 = &synth_ltp[-pitch_int]; /* Qx */ x1 = x0 - 1; - y0 = synth; + y0 = synth; /* Qx */ y1 = y0 - 1; assert( filtIdx >= 0 ); - w0 = &tcxLtpFilters[filtIdx].filt[pitch_fr]; - w1 = &tcxLtpFilters[filtIdx].filt[sub( pitch_res, pitch_fr )]; - v0 = &tcxLtpFilters[filtIdx].filt[0]; - v1 = &tcxLtpFilters[filtIdx].filt[pitch_res]; + w0 = &tcxLtpFilters[filtIdx].filt[pitch_fr]; /* Q15 */ + w1 = &tcxLtpFilters[filtIdx].filt[pitch_res - pitch_fr]; /* Q15 */ + v0 = &tcxLtpFilters[filtIdx].filt[0]; /* Q15 */ + v1 = &tcxLtpFilters[filtIdx].filt[pitch_res]; /* Q15 */ - L = tcxLtpFilters[filtIdx].length; + L = tcxLtpFilters[filtIdx].length; /* Q0 */ move16(); alpha = 0; @@ -612,7 +618,7 @@ static void tcx_ltp_synth_filter32( { if ( fade < 0 ) { - alpha = 0x7FFF; + alpha = 0x7FFF; /* 1 in Q15 */ move16(); } @@ -620,7 +626,7 @@ static void tcx_ltp_synth_filter32( step = shl( 2, norm_s( length ) ); if ( s_and( length, sub( length, 1 ) ) != 0 ) { - step = mult_r( step, 26214 /*64.f/80.f Q15*/ ); + step = mult_r( step, 26214 /*64.f/80.f Q15*/ ); /* Q15 */ } if ( EQ_16( length, 240 ) ) { @@ -641,13 +647,13 @@ static void tcx_ltp_synth_filter32( FOR( i = 0; i < L; i++ ) { #ifdef BASOP_NOGLOB - s = Madd_32_16_r( Madd_32_16_r( s, x0[i], w0[k] ), x1[-i], w1[k] ); - s2 = Madd_32_16_r( Madd_32_16_r( s2, y0[i], v0[k] ), y1[-i], v1[k] ); + s = Madd_32_16_r( Madd_32_16_r( s, x0[i], w0[k] ), x1[-i], w1[k] ); /* Qx */ + s2 = Madd_32_16_r( Madd_32_16_r( s2, y0[i], v0[k] ), y1[-i], v1[k] ); /* Qx */ #else s = L_mac( L_mac( s, w0[k], x0[i] ), w1[k], x1[-i] ); s2 = L_mac( L_mac( s2, v0[k], y0[i] ), v1[k], y1[-i] ); #endif - k = add( k, pitch_res ); + k = k + pitch_res; } /* s2 *= ALPHA; @@ -655,18 +661,18 @@ static void tcx_ltp_synth_filter32( zir: synth_ltp[j] = synth[j] - gain * s2 + gain * s - zir[j]; fade-in/out: synth_ltp[j] = synth[j] - alpha * gain * s2 + alpha * gain * s; */ #ifdef BASOP_NOGLOB - L_tmp = L_sub_sat( s, Mpy_32_16_r( s2, ALPHA ) ); + L_tmp = L_sub_sat( s, Mpy_32_16_r( s2, ALPHA ) ); /* Qx */ #else i = sub( round_fx( s ), mult_r( round_fx( s2 ), ALPHA ) ); #endif - L_tmp2 = Mpy_32_16_r( L_tmp, gain ); + L_tmp2 = Mpy_32_16_r( L_tmp, gain ); /* Qx */ IF( fade != 0 ) - L_tmp2 = Mpy_32_16_r( L_tmp2, alpha ); + L_tmp2 = Mpy_32_16_r( L_tmp2, alpha ); /* Qx */ #ifdef BASOP_NOGLOB - L_tmp2 = L_add_sat( synth[j], L_tmp2 ); + L_tmp2 = L_add_sat( synth[j], L_tmp2 ); /* Qx */ if ( zir != NULL ) { - L_tmp2 = L_sub_sat( L_tmp2, zir[j] ); + L_tmp2 = L_sub_sat( L_tmp2, zir[j] ); /* Qx */ } #else L_tmp2 = add( synth[j], L_tmp2 ); @@ -674,7 +680,7 @@ static void tcx_ltp_synth_filter32( L_tmp2 = sub( L_tmp2, zir[j] ); #endif - synth_ltp[j] = L_tmp2; + synth_ltp[j] = L_tmp2; /* Qx */ move16(); BASOP_SATURATE_WARNING_OFF_EVS; @@ -697,19 +703,20 @@ static void tcx_ltp_synth_filter32( } ELSE { - Copy32( synth, synth_ltp, length ); + Copy32( synth, synth_ltp, length ); /* Qx */ } } static void tcx_ltp_synth_filter_10( - Word16 *out, - Word16 *in, - const Word16 length, - const Word16 pitch_int, - const Word16 pitch_fr, - const Word16 gain, - const Word16 pitch_res, - const Word16 filtIdx ) + Word16 *out, /* Qx */ + Word16 *in, /* Qx */ + const Word16 length, /* Q0 */ + const Word16 pitch_int, /* Q0 */ + const Word16 pitch_fr, /* Q0 */ + const Word16 gain, /* Q15 */ + const Word16 pitch_res, /* Q0 */ + const Word16 filtIdx /* Q0 */ +) { Word16 *x0, *x1; Word16 *y0, *y1; @@ -719,22 +726,23 @@ static void tcx_ltp_synth_filter_10( Word16 i, j, k, L; Word16 curr_gain, gain_step; - x0 = &out[-pitch_int]; + x0 = &out[-pitch_int]; /* Qx */ x1 = x0 - 1; - y0 = in; + y0 = in; /* Qx */ y1 = y0 - 1; assert( GE_16( filtIdx, 0 ) ); - w0 = &tcxLtpFilters[filtIdx].filt[pitch_fr]; - w1 = &tcxLtpFilters[filtIdx].filt[sub( pitch_res, pitch_fr )]; - v0 = &tcxLtpFilters[filtIdx].filt[0]; - v1 = &tcxLtpFilters[filtIdx].filt[pitch_res]; - L = tcxLtpFilters[filtIdx].length; + w0 = &tcxLtpFilters[filtIdx].filt[pitch_fr]; /* Q15 */ + w1 = &tcxLtpFilters[filtIdx].filt[pitch_res - pitch_fr]; /* Q15 */ + v0 = &tcxLtpFilters[filtIdx].filt[0]; /* Q15 */ + v1 = &tcxLtpFilters[filtIdx].filt[pitch_res]; /* Q15 */ + L = tcxLtpFilters[filtIdx].length; /* Q0 */ curr_gain = gain; move16(); - gain_step = negate( gain ) / length; + + gain_step = div_s( negate( gain ), length ); /* Q15 */ FOR( j = 0; j < length; j++ ) { @@ -746,12 +754,12 @@ static void tcx_ltp_synth_filter_10( move16(); FOR( i = 0; i < L; i++ ) { - s = L_mac_sat( L_mac_sat( s, w0[k], x0[i] ), w1[k], x1[-i] ); - s2 = L_mac_sat( L_mac_sat( s2, v0[k], y0[i] ), v1[k], y1[-i] ); + s = L_mac_sat( L_mac_sat( s, w0[k], x0[i] ), w1[k], x1[-i] ); /* Qx */ + s2 = L_mac_sat( L_mac_sat( s2, v0[k], y0[i] ), v1[k], y1[-i] ); /* Qx */ k = add( k, pitch_res ); } - out[j] = add_sat( in[j], mult_r_sat( curr_gain, sub_sat( round_fx_sat( s ), mult_r_sat( round_fx_sat( s2 ), ALPHA ) ) ) ); + out[j] = add_sat( in[j], mult_r_sat( curr_gain, sub_sat( round_fx_sat( s ), mult_r_sat( round_fx_sat( s2 ), ALPHA ) ) ) ); /* Qx */ x0++; x1++; @@ -765,14 +773,15 @@ static void tcx_ltp_synth_filter_10( } static void tcx_ltp_synth_filter_10_fx( - Word32 *out, - Word32 *in, - const Word16 length, - const Word16 pitch_int, - const Word16 pitch_fr, - const Word16 gain, - const Word16 pitch_res, - const Word16 filtIdx ) + Word32 *out, /* Qx */ + Word32 *in, /* Qx */ + const Word16 length, /* Q0 */ + const Word16 pitch_int, /* Q0 */ + const Word16 pitch_fr, /* Q0 */ + const Word16 gain, /* Q15 */ + const Word16 pitch_res, /* Q0 */ + const Word16 filtIdx /* Q0 */ +) { Word32 *x0, *x1; Word32 *y0, *y1; @@ -782,18 +791,18 @@ static void tcx_ltp_synth_filter_10_fx( Word16 i, j, k, L; Word16 curr_gain, gain_step; - x0 = &out[-pitch_int]; + x0 = &out[-pitch_int]; /* Qx */ x1 = x0 - 1; - y0 = in; + y0 = in; /* Qx */ y1 = y0 - 1; assert( filtIdx >= 0 ); - w0 = &tcxLtpFilters[filtIdx].filt[pitch_fr]; - w1 = &tcxLtpFilters[filtIdx].filt[pitch_res - pitch_fr]; - v0 = &tcxLtpFilters[filtIdx].filt[0]; - v1 = &tcxLtpFilters[filtIdx].filt[pitch_res]; - L = tcxLtpFilters[filtIdx].length; + w0 = &tcxLtpFilters[filtIdx].filt[pitch_fr]; /* Q15 */ + w1 = &tcxLtpFilters[filtIdx].filt[pitch_res - pitch_fr]; /* Q15 */ + v0 = &tcxLtpFilters[filtIdx].filt[0]; /* Q15 */ + v1 = &tcxLtpFilters[filtIdx].filt[pitch_res]; /* Q15 */ + L = tcxLtpFilters[filtIdx].length; /* Q0 */ curr_gain = gain; move16(); @@ -809,12 +818,12 @@ static void tcx_ltp_synth_filter_10_fx( move16(); FOR( i = 0; i < L; i++ ) { - s = Madd_32_16_r( Madd_32_16_r( s, x0[i], w0[k] ), x1[-i], w1[k] ); - s2 = Madd_32_16_r( Madd_32_16_r( s2, y0[i], v0[k] ), y1[-i], v1[k] ); - k = add( k, pitch_res ); + s = Madd_32_16_r( Madd_32_16_r( s, x0[i], w0[k] ), x1[-i], w1[k] ); /* Qx */ + s2 = Madd_32_16_r( Madd_32_16_r( s2, y0[i], v0[k] ), y1[-i], v1[k] ); /* Qx */ + k = k + pitch_res; } - out[j] = L_add_sat( in[j], Mpy_32_16_1( L_sub_sat( s, Mpy_32_16_1( s2, ALPHA ) ), curr_gain ) ); + out[j] = L_add_sat( in[j], Mpy_32_16_1( L_sub_sat( s, Mpy_32_16_1( s2, ALPHA ) ), curr_gain ) ); /* Qx */ move32(); x0++; x1++; @@ -828,14 +837,15 @@ static void tcx_ltp_synth_filter_10_fx( } static void tcx_ltp_synth_filter_01( - Word16 *out, - Word16 *in, - const Word16 length, - const Word16 pitch_int, - const Word16 pitch_fr, - const Word16 gain, - const Word16 pitch_res, - const Word16 filtIdx ) + Word16 *out, /* Qx */ + Word16 *in, /* Qx */ + const Word16 length, /* Q0 */ + const Word16 pitch_int, /* Q0 */ + const Word16 pitch_fr, /* Q0 */ + const Word16 gain, /* Q15 */ + const Word16 pitch_res, /* Q0 */ + const Word16 filtIdx /* Q0 */ +) { Word16 *x0, *x1; Word16 *y0, *y1; @@ -845,18 +855,18 @@ static void tcx_ltp_synth_filter_01( Word16 i, j, k, L; Word16 curr_gain, gain_step; - x0 = &out[negate( pitch_int )]; + x0 = &out[-( pitch_int )]; /* Qx */ x1 = x0 - 1; - y0 = in; + y0 = in; /* Qx */ y1 = y0 - 1; assert( filtIdx >= 0 ); - w0 = &tcxLtpFilters[filtIdx].filt[pitch_fr]; - w1 = &tcxLtpFilters[filtIdx].filt[pitch_res - pitch_fr]; - v0 = &tcxLtpFilters[filtIdx].filt[0]; - v1 = &tcxLtpFilters[filtIdx].filt[pitch_res]; - L = tcxLtpFilters[filtIdx].length; + w0 = &tcxLtpFilters[filtIdx].filt[pitch_fr]; /* Q15 */ + w1 = &tcxLtpFilters[filtIdx].filt[pitch_res - pitch_fr]; /* Q15 */ + v0 = &tcxLtpFilters[filtIdx].filt[0]; /* Q15 */ + v1 = &tcxLtpFilters[filtIdx].filt[pitch_res]; /* Q15 */ + L = tcxLtpFilters[filtIdx].length; /* Q0 */ curr_gain = 0; move16(); @@ -869,13 +879,13 @@ static void tcx_ltp_synth_filter_01( s2 = 0; move16(); - for ( i = 0, k = 0; i < L; i++, k = add( k, pitch_res ) ) + for ( i = 0, k = 0; i < L; i++, k = k + pitch_res ) { - s = L_mac_sat( L_mac_sat( s, w0[k], x0[i] ), w1[k], x1[-i] ); - s2 = L_mac_sat( L_mac_sat( s2, v0[k], y0[i] ), v1[k], y1[-i] ); + s = L_mac_sat( L_mac_sat( s, w0[k], x0[i] ), w1[k], x1[-i] ); /* Qx */ + s2 = L_mac_sat( L_mac_sat( s2, v0[k], y0[i] ), v1[k], y1[-i] ); /* Qx */ } - out[j] = add_sat( in[j], mult_r_sat( curr_gain, sub_sat( round_fx_sat( s ), mult_r_sat( round_fx_sat( s2 ), ALPHA ) ) ) ); + out[j] = add_sat( in[j], mult_r_sat( curr_gain, sub_sat( round_fx_sat( s ), mult_r_sat( round_fx_sat( s2 ), ALPHA ) ) ) ); /* Qx */ move32(); x0++; @@ -890,14 +900,15 @@ static void tcx_ltp_synth_filter_01( } static void tcx_ltp_synth_filter_01_fx( - Word32 *out, - Word32 *in, - const Word16 length, - const Word16 pitch_int, - const Word16 pitch_fr, - const Word16 gain, - const Word16 pitch_res, - const Word16 filtIdx ) + Word32 *out, /* Qx */ + Word32 *in, /* Qx */ + const Word16 length, /* Q0 */ + const Word16 pitch_int, /* Q0 */ + const Word16 pitch_fr, /* Q0 */ + const Word16 gain, /* Q15 */ + const Word16 pitch_res, /* Q0 */ + const Word16 filtIdx /* Q0 */ +) { Word32 *x0, *x1; Word32 *y0, *y1; @@ -907,18 +918,18 @@ static void tcx_ltp_synth_filter_01_fx( Word16 i, j, k, L; Word16 curr_gain, gain_step; - x0 = &out[negate( pitch_int )]; + x0 = &out[-( pitch_int )]; /* Qx */ x1 = x0 - 1; - y0 = in; + y0 = in; /* Qx */ y1 = y0 - 1; assert( filtIdx >= 0 ); - w0 = &tcxLtpFilters[filtIdx].filt[pitch_fr]; - w1 = &tcxLtpFilters[filtIdx].filt[pitch_res - pitch_fr]; - v0 = &tcxLtpFilters[filtIdx].filt[0]; - v1 = &tcxLtpFilters[filtIdx].filt[pitch_res]; - L = tcxLtpFilters[filtIdx].length; + w0 = &tcxLtpFilters[filtIdx].filt[pitch_fr]; /* Q15 */ + w1 = &tcxLtpFilters[filtIdx].filt[pitch_res - pitch_fr]; /* Q15 */ + v0 = &tcxLtpFilters[filtIdx].filt[0]; /* Q15 */ + v1 = &tcxLtpFilters[filtIdx].filt[pitch_res]; /* Q15 */ + L = tcxLtpFilters[filtIdx].length; /* Q0 */ curr_gain = 0; move16(); @@ -934,12 +945,12 @@ static void tcx_ltp_synth_filter_01_fx( move16(); FOR( i = 0; i < L; i++ ) { - s = Madd_32_16_r( Madd_32_16_r( s, x0[i], w0[k] ), x1[-i], w1[k] ); - s2 = Madd_32_16_r( Madd_32_16_r( s2, y0[i], v0[k] ), y1[-i], v1[k] ); - k = add( k, pitch_res ); + s = Madd_32_16_r( Madd_32_16_r( s, x0[i], w0[k] ), x1[-i], w1[k] ); /* Qx */ + s2 = Madd_32_16_r( Madd_32_16_r( s2, y0[i], v0[k] ), y1[-i], v1[k] ); /* Qx */ + k = k + pitch_res; } - out[j] = L_add_sat( in[j], Mpy_32_16_r( L_sub_sat( s, Mpy_32_16_1( s2, ALPHA ) ), curr_gain ) ); + out[j] = L_add_sat( in[j], Mpy_32_16_r( L_sub_sat( s, Mpy_32_16_1( s2, ALPHA ) ), curr_gain ) ); /* Qx */ move32(); x0++; @@ -965,19 +976,20 @@ static void tcx_ltp_synth_filter_01_fx( ---------------------------------------------------------------------*/ static void tcx_ltp_synth_filter_11_unequal_pitch( - Word16 *out, - Word16 *in, - const Word16 length, - const Word16 cur_pitch_int, - const Word16 cur_pitch_fr, - const Word16 cur_gain, - const Word16 pitch_res, - const Word16 filtIdx, - const Word16 prev_pitch_int, - const Word16 prev_pitch_fr, - const Word16 prev_gain, - const Word16 prev_pitch_res, - const Word16 prev_filtIdx ) + Word16 *out, /* Qx */ + Word16 *in, /* Qx */ + const Word16 length, /* Q0 */ + const Word16 cur_pitch_int, /* Q0 */ + const Word16 cur_pitch_fr, /* Q0 */ + const Word16 cur_gain, /* Q15 */ + const Word16 pitch_res, /* Q0 */ + const Word16 filtIdx, /* Q0 */ + const Word16 prev_pitch_int, /* Q0 */ + const Word16 prev_pitch_fr, /* Q0 */ + const Word16 prev_gain, /* Q15 */ + const Word16 prev_pitch_res, /* Q0 */ + const Word16 prev_filtIdx /* Q0 */ +) { Word16 *x0, *x1; Word16 *y0, *y1; @@ -994,27 +1006,27 @@ static void tcx_ltp_synth_filter_11_unequal_pitch( Word16 *temp_ptr; Word16 gain, gain_step; - x0 = &out[negate( prev_pitch_int )]; + x0 = &out[-( prev_pitch_int )]; x1 = x0 - 1; y0 = in; y1 = y0 - 1; assert( ( filtIdx >= 0 ) && ( prev_filtIdx >= 0 ) ); - w0 = &tcxLtpFilters[prev_filtIdx].filt[prev_pitch_fr]; - w1 = &tcxLtpFilters[prev_filtIdx].filt[prev_pitch_res - prev_pitch_fr]; - v0 = &tcxLtpFilters[prev_filtIdx].filt[0]; - v1 = &tcxLtpFilters[prev_filtIdx].filt[prev_pitch_res]; + w0 = &tcxLtpFilters[prev_filtIdx].filt[prev_pitch_fr]; /* Q15 */ + w1 = &tcxLtpFilters[prev_filtIdx].filt[prev_pitch_res - prev_pitch_fr]; /* Q15 */ + v0 = &tcxLtpFilters[prev_filtIdx].filt[0]; /* Q15 */ + v1 = &tcxLtpFilters[prev_filtIdx].filt[prev_pitch_res]; /* Q15 */ - prev_L = tcxLtpFilters[prev_filtIdx].length; + prev_L = tcxLtpFilters[prev_filtIdx].length; /* Q0 */ move16(); - p0 = &tcxLtpFilters[filtIdx].filt[cur_pitch_fr]; - p1 = &tcxLtpFilters[filtIdx].filt[pitch_res - cur_pitch_fr]; - q0 = &tcxLtpFilters[filtIdx].filt[0]; - q1 = &tcxLtpFilters[filtIdx].filt[pitch_res]; + p0 = &tcxLtpFilters[filtIdx].filt[cur_pitch_fr]; /* Q15 */ + p1 = &tcxLtpFilters[filtIdx].filt[pitch_res - cur_pitch_fr]; /* Q15 */ + q0 = &tcxLtpFilters[filtIdx].filt[0]; /* Q15 */ + q1 = &tcxLtpFilters[filtIdx].filt[pitch_res]; /* Q15 */ - L = tcxLtpFilters[filtIdx].length; + L = tcxLtpFilters[filtIdx].length; /* Q0 */ move16(); /* 1. decreasing gain filter. The first filter unit with the parameters associated to the previous interval and scaling towards 0 */ @@ -1032,12 +1044,12 @@ static void tcx_ltp_synth_filter_11_unequal_pitch( move16(); FOR( i = 0; i < prev_L; i++ ) { - s = L_mac_sat( L_mac_sat( s, w0[k], x0[i] ), w1[k], x1[-i] ); - s2 = L_mac_sat( L_mac_sat( s2, v0[k], y0[i] ), v1[k], y1[-i] ); - k = add( k, prev_pitch_res ); + s = L_mac_sat( L_mac_sat( s, w0[k], x0[i] ), w1[k], x1[-i] ); /* Qx */ + s2 = L_mac_sat( L_mac_sat( s2, v0[k], y0[i] ), v1[k], y1[-i] ); /* Qx */ + k = k + prev_pitch_res; } - out[j] = add_sat( in[j], mult_r_sat( gain, sub_sat( round_fx_sat( s ), mult_r_sat( round_fx_sat( s2 ), ALPHA ) ) ) ); + out[j] = add_sat( in[j], mult_r_sat( gain, sub_sat( round_fx_sat( s ), mult_r_sat( round_fx_sat( s2 ), ALPHA ) ) ) ); /* Qx */ x0++; x1++; @@ -1047,13 +1059,13 @@ static void tcx_ltp_synth_filter_11_unequal_pitch( gain = add( gain, gain_step ); } - Copy( out - L, temp_buf, length + L ); - Copy( in + length, temp_buf + length + L, L ); + Copy( out - L, temp_buf, length + L ); /* Qx */ + Copy( in + length, temp_buf + length + L, L ); /* Qx */ temp_ptr = &temp_buf[0] + L; - m0 = temp_ptr; - m1 = temp_ptr - 1; - l0 = &out[negate( cur_pitch_int )]; + m0 = temp_ptr; /* Qx */ + m1 = temp_ptr - 1; /* Qx */ + l0 = &out[-( cur_pitch_int )]; /* Qx */ l1 = l0 - 1; /* 2. increasing gain filter. The second filter unit with the parameters associated to the current interval and scaling from 0 towards current gain */ @@ -1071,12 +1083,12 @@ static void tcx_ltp_synth_filter_11_unequal_pitch( move16(); FOR( i = 0; i < L; i++ ) { - s3 = L_mac_sat( L_mac_sat( s3, p0[k], l0[i] ), p1[k], l1[-i] ); - s4 = L_mac_sat( L_mac_sat( s4, q0[k], m0[i] ), q1[k], m1[-i] ); - k = add( k, pitch_res ); + s3 = L_mac_sat( L_mac_sat( s3, p0[k], l0[i] ), p1[k], l1[-i] ); /* Qx */ + s4 = L_mac_sat( L_mac_sat( s4, q0[k], m0[i] ), q1[k], m1[-i] ); /* Qx */ + k = k + pitch_res; } - out[j] = add_sat( *( temp_ptr + j ), mult_r_sat( gain, sub_sat( round_fx_sat( s3 ), mult_r_sat( round_fx_sat( s4 ), ALPHA ) ) ) ); + out[j] = add_sat( *( temp_ptr + j ), mult_r_sat( gain, sub_sat( round_fx_sat( s3 ), mult_r_sat( round_fx_sat( s4 ), ALPHA ) ) ) ); /* Qx */ move32(); l0++; @@ -1091,19 +1103,20 @@ static void tcx_ltp_synth_filter_11_unequal_pitch( } static void tcx_ltp_synth_filter_11_unequal_pitch_fx( - Word32 *out, - Word32 *in, - const Word16 length, - const Word16 cur_pitch_int, - const Word16 cur_pitch_fr, - const Word16 cur_gain, - const Word16 pitch_res, - const Word16 filtIdx, - const Word16 prev_pitch_int, - const Word16 prev_pitch_fr, - const Word16 prev_gain, - const Word16 prev_pitch_res, - const Word16 prev_filtIdx ) + Word32 *out, /* Qx */ + Word32 *in, /* Qx */ + const Word16 length, /* Q0 */ + const Word16 cur_pitch_int, /* Q0 */ + const Word16 cur_pitch_fr, /* Q0 */ + const Word16 cur_gain, /* Q15 */ + const Word16 pitch_res, /* Q0 */ + const Word16 filtIdx, /* Q0 */ + const Word16 prev_pitch_int, /* Q0 */ + const Word16 prev_pitch_fr, /* Q0 */ + const Word16 prev_gain, /* Q15 */ + const Word16 prev_pitch_res, /* Q0 */ + const Word16 prev_filtIdx /* Q0 */ +) { Word32 *x0, *x1; Word32 *y0, *y1; @@ -1120,27 +1133,27 @@ static void tcx_ltp_synth_filter_11_unequal_pitch_fx( Word32 *temp_ptr; Word16 gain, gain_step; - x0 = &out[negate( prev_pitch_int )]; + x0 = &out[-( prev_pitch_int )]; /* Qx */ x1 = x0 - 1; - y0 = in; + y0 = in; /* Qx */ y1 = y0 - 1; assert( GE_16( filtIdx, 0 ) && GE_16( prev_filtIdx, 0 ) ); - w0 = &tcxLtpFilters[prev_filtIdx].filt[prev_pitch_fr]; - w1 = &tcxLtpFilters[prev_filtIdx].filt[prev_pitch_res - prev_pitch_fr]; - v0 = &tcxLtpFilters[prev_filtIdx].filt[0]; - v1 = &tcxLtpFilters[prev_filtIdx].filt[prev_pitch_res]; + w0 = &tcxLtpFilters[prev_filtIdx].filt[prev_pitch_fr]; /* Q15 */ + w1 = &tcxLtpFilters[prev_filtIdx].filt[prev_pitch_res - prev_pitch_fr]; /* Q15 */ + v0 = &tcxLtpFilters[prev_filtIdx].filt[0]; /* Q15 */ + v1 = &tcxLtpFilters[prev_filtIdx].filt[prev_pitch_res]; /* Q15 */ - prev_L = tcxLtpFilters[prev_filtIdx].length; + prev_L = tcxLtpFilters[prev_filtIdx].length; /* Q0 */ move16(); - p0 = &tcxLtpFilters[filtIdx].filt[cur_pitch_fr]; - p1 = &tcxLtpFilters[filtIdx].filt[pitch_res - cur_pitch_fr]; - q0 = &tcxLtpFilters[filtIdx].filt[0]; - q1 = &tcxLtpFilters[filtIdx].filt[pitch_res]; + p0 = &tcxLtpFilters[filtIdx].filt[cur_pitch_fr]; /* Q15 */ + p1 = &tcxLtpFilters[filtIdx].filt[pitch_res - cur_pitch_fr]; /* Q15 */ + q0 = &tcxLtpFilters[filtIdx].filt[0]; /* Q15 */ + q1 = &tcxLtpFilters[filtIdx].filt[pitch_res]; /* Q15 */ - L = tcxLtpFilters[filtIdx].length; + L = tcxLtpFilters[filtIdx].length; /* Q0 */ move16(); /* 1. decreasing gain filter. The first filter unit with the parameters associated to the previous interval and scaling towards 0 */ @@ -1158,12 +1171,12 @@ static void tcx_ltp_synth_filter_11_unequal_pitch_fx( move16(); FOR( i = 0; i < prev_L; i++ ) { - s = Madd_32_16_r( Madd_32_16_r( s, x0[i], w0[k] ), x1[-i], w1[k] ); - s2 = Madd_32_16_r( Madd_32_16_r( s2, y0[i], v0[k] ), y1[-i], v1[k] ); - k = add( k, prev_pitch_res ); + s = Madd_32_16_r( Madd_32_16_r( s, x0[i], w0[k] ), x1[-i], w1[k] ); /* Qx */ + s2 = Madd_32_16_r( Madd_32_16_r( s2, y0[i], v0[k] ), y1[-i], v1[k] ); /* Qx */ + k += prev_pitch_res; } - out[j] = L_add_sat( in[j], Mpy_32_16_r( L_sub_sat( s, Mpy_32_16_1( s2, ALPHA ) ), gain ) ); + out[j] = L_add_sat( in[j], Mpy_32_16_r( L_sub_sat( s, Mpy_32_16_1( s2, ALPHA ) ), gain ) ); /* Qx */ move32(); x0++; x1++; @@ -1173,13 +1186,13 @@ static void tcx_ltp_synth_filter_11_unequal_pitch_fx( gain = add( gain, gain_step ); } - Copy32( out - L, temp_buf, length + L ); - Copy32( in + length, temp_buf + length + L, L ); - temp_ptr = &temp_buf[0] + L; + Copy32( out - L, temp_buf, length + L ); /* Qx */ + Copy32( in + length, temp_buf + length + L, L ); /* Qx */ + temp_ptr = &temp_buf[0] + L; /* Qx */ - m0 = temp_ptr; + m0 = temp_ptr; /* Qx */ m1 = temp_ptr - 1; - l0 = &out[negate( cur_pitch_int )]; + l0 = &out[-( cur_pitch_int )]; /* Qx */ l1 = l0 - 1; /* 2. increasing gain filter. The second filter unit with the parameters associated to the current interval and scaling from 0 towards current gain */ @@ -1196,12 +1209,12 @@ static void tcx_ltp_synth_filter_11_unequal_pitch_fx( k = 0; FOR( i = 0; i < L; i++ ) { - s3 = Madd_32_16_r( Madd_32_16_r( s3, l0[i], p0[k] ), l1[-i], p1[k] ); - s4 = Madd_32_16_r( Madd_32_16_r( s4, m0[i], q0[k] ), m1[-i], q1[k] ); + s3 = Madd_32_16_r( Madd_32_16_r( s3, l0[i], p0[k] ), l1[-i], p1[k] ); /* Qx */ + s4 = Madd_32_16_r( Madd_32_16_r( s4, m0[i], q0[k] ), m1[-i], q1[k] ); /* Qx */ k = add( k, pitch_res ); } - out[j] = L_add_sat( *( temp_ptr + j ), Mpy_32_16_r( L_sub_sat( s3, Mpy_32_16_1( s4, ALPHA ) ), gain ) ); + out[j] = L_add_sat( *( temp_ptr + j ), Mpy_32_16_r( L_sub_sat( s3, Mpy_32_16_1( s4, ALPHA ) ), gain ) ); /* Qx */ move32(); l0++; @@ -1216,15 +1229,16 @@ static void tcx_ltp_synth_filter_11_unequal_pitch_fx( } Word16 tcx_ltp_decode_params( - Word16 *ltp_param, - Word16 *pitch_int, - Word16 *pitch_fr, - Word16 *gain, - const Word16 pitmin, - const Word16 pitfr1, - const Word16 pitfr2, - const Word16 pitmax, - const Word16 pitres ) + Word16 *ltp_param, /* Q0 */ + Word16 *pitch_int, /* Q0 */ + Word16 *pitch_fr, /* Q0 */ + Word16 *gain, /* Q13 */ + const Word16 pitmin, /* Q0 */ + const Word16 pitfr1, /* Q0 */ + const Word16 pitfr2, /* Q0 */ + const Word16 pitmax, /* Q0 */ + const Word16 pitres /* Q0 */ +) { Word16 tmp, tmp2; @@ -1233,47 +1247,47 @@ Word16 tcx_ltp_decode_params( test(); IF( ltp_param != 0 && ltp_param[0] != 0 ) { - tmp = imult1616( sub( pitfr2, pitmin ), pitres ); + tmp = imult1616( sub( pitfr2, pitmin ), pitres ); /* Q0 */ IF( LT_16( ltp_param[1], tmp ) ) { tmp2 = idiv1616U( ltp_param[1], pitres ); - *pitch_int = add( pitmin, tmp2 ); + *pitch_int = add( pitmin, tmp2 ); /* Q0 */ move16(); - tmp2 = sub( *pitch_int, pitmin ); - *pitch_fr = sub( ltp_param[1], imult1616( tmp2, pitres ) ); + tmp2 = sub( *pitch_int, pitmin ); /* Q0 */ + *pitch_fr = sub( ltp_param[1], imult1616( tmp2, pitres ) ); /* Q0 */ move16(); } ELSE { - tmp2 = imult1616( sub( pitfr1, pitfr2 ), shr( pitres, 1 ) ); + tmp2 = imult1616( sub( pitfr1, pitfr2 ), shr( pitres, 1 ) ); /* Q0 */ IF( LT_16( ltp_param[1], add( tmp, tmp2 ) ) ) { - tmp2 = idiv1616U( sub( ltp_param[1], tmp ), shr( pitres, 1 ) ); + tmp2 = idiv1616U( sub( ltp_param[1], tmp ), shr( pitres, 1 ) ); /* Q0 */ - *pitch_int = add( pitfr2, tmp2 ); + *pitch_int = add( pitfr2, tmp2 ); /* Q0 */ move16(); - *pitch_fr = shl( sub( sub( ltp_param[1], tmp ), imult1616( tmp2, shr( pitres, 1 ) ) ), 1 ); + *pitch_fr = shl( sub( sub( ltp_param[1], tmp ), imult1616( tmp2, shr( pitres, 1 ) ) ), 1 ); /* Q0 */ move16(); } ELSE { - *pitch_int = sub( add( ltp_param[1], pitfr1 ), add( tmp, tmp2 ) ); + *pitch_int = sub( add( ltp_param[1], pitfr1 ), add( tmp, tmp2 ) ); /* Q0 */ move16(); *pitch_fr = 0; move16(); } } - *gain = imult1616( add( ltp_param[2], 1 ), 0x1400 ); + *gain = imult1616( add( ltp_param[2], 1 ), 0x1400 /* 0.625 in Q13 */ ); /* Q13 */ move16(); IF( LT_16( *pitch_int, PIT_MIN_SHORTER ) ) { /*pitch out of range due to bit error */ - *pitch_int = PIT_MIN_SHORTER; + *pitch_int = PIT_MIN_SHORTER; /* Q0 */ move16(); return 1; } @@ -1281,14 +1295,14 @@ Word16 tcx_ltp_decode_params( IF( GT_16( *pitch_int, PIT_MAX_MAX ) ) { /*pitch out of range due to bit error */ - *pitch_int = PIT_MAX_MAX; + *pitch_int = PIT_MAX_MAX; /* Q0 */ move16(); return 1; } } ELSE { - *pitch_int = pitmax; + *pitch_int = pitmax; /* Q0 */ move16(); *pitch_fr = 0; move16(); @@ -1302,11 +1316,12 @@ Word16 tcx_ltp_decode_params( void tcx_ltp_post( Decoder_State *st, TCX_LTP_DEC_HANDLE hTcxLtpDec, - Word16 core, - Word16 output_frame, - Word16 delay, - Word16 *sig, - Word16 *tcx_buf ) + Word16 core, /* Q0 */ + Word16 output_frame, /* Q0 */ + Word16 delay, /* Q0 */ + Word16 *sig, /* Qx */ + Word16 *tcx_buf /* Qx */ +) { Word16 tmp, L_transition, lpcorder, filtIdx; Word16 gain, gain2; @@ -1318,17 +1333,17 @@ void tcx_ltp_post( Word16 tcx_buf_len, bfi, L_frame_core, SideInfoOnly; Word32 total_brate; - total_brate = st->total_brate; + total_brate = st->total_brate; /* Q0 */ move32(); IF( EQ_16( st->element_mode, IVAS_CPE_MDCT ) ) { - total_brate = L_mult0( st->bits_frame_nominal, FRAMES_PER_SEC ); + total_brate = L_mult0( st->bits_frame_nominal, FRAMES_PER_SEC ); /* Q0 */ move32(); } filtIdx = 0; /* just to avoid comilation warnings */ move16(); - tcx_buf_len = NS2SA( st->output_Fs, TCXLTP_DELAY_NS ); + tcx_buf_len = NS2SA( st->output_Fs, TCXLTP_DELAY_NS ); /* Q0 */ SideInfoOnly = 0; move16(); if ( GE_32( total_brate, HQ_96k ) ) @@ -1337,12 +1352,12 @@ void tcx_ltp_post( move16(); } - L_frame_core = st->L_frame; + L_frame_core = st->L_frame; /* Q0 */ move16(); if ( EQ_16( st->element_mode, IVAS_CPE_MDCT ) ) { - L_frame_core = L_FRAME; + L_frame_core = L_FRAME; /* Q0 */ move16(); } @@ -1356,15 +1371,15 @@ void tcx_ltp_post( move16(); gain = 0; move16(); - L_frame_core = st->L_frame_past; + L_frame_core = st->L_frame_past; /* Q0 */ move16(); } ELSE { - bfi = st->bfi; - pitch_int = hTcxLtpDec->tcxltp_pitch_int; - pitch_fr = hTcxLtpDec->tcxltp_pitch_fr; - gain = hTcxLtpDec->tcxltp_gain; + bfi = st->bfi; /* Q0 */ + pitch_int = hTcxLtpDec->tcxltp_pitch_int; /* Q0 */ + pitch_fr = hTcxLtpDec->tcxltp_pitch_fr; /* Q0 */ + gain = hTcxLtpDec->tcxltp_gain; /* Q15 */ move16(); move16(); move16(); @@ -1374,23 +1389,23 @@ void tcx_ltp_post( /* Parameters */ - L_transition = shr( output_frame, 2 ); + L_transition = shr( output_frame, 2 ); /* Q0 */ lpcorder = TCXLTP_LTP_ORDER; move16(); /* Input buffer */ sig_in = buf_in + tcx_buf_len; - Copy( hTcxLtpDec->tcxltp_mem_in, buf_in, tcx_buf_len ); - Copy( sig, buf_in + tcx_buf_len, output_frame ); + Copy( hTcxLtpDec->tcxltp_mem_in, buf_in, tcx_buf_len ); /* exp(exp_tcxltp_mem_in) */ + Copy( sig, buf_in + tcx_buf_len, output_frame ); /* Qx */ IF( GT_16( core, ACELP_CORE ) ) { - Copy( tcx_buf, sig_in + output_frame, tcx_buf_len ); + Copy( tcx_buf, sig_in + output_frame, tcx_buf_len ); /* Qx */ } - Copy( sig + output_frame - tcx_buf_len, hTcxLtpDec->tcxltp_mem_in, tcx_buf_len ); + Copy( sig + output_frame - tcx_buf_len, hTcxLtpDec->tcxltp_mem_in, tcx_buf_len ); /* Qx */ /* Output buffer */ sig_out = buf_out + output_frame; - Copy( hTcxLtpDec->tcxltp_mem_out, buf_out, output_frame ); + Copy( hTcxLtpDec->tcxltp_mem_out, buf_out, output_frame ); /* exp(exp_tcxltp_mem_out) */ /* TCX-LTP parameters: integer pitch, fractional pitch, gain */ test(); @@ -1417,30 +1432,30 @@ void tcx_ltp_post( tmp32 = L_mult0( add( imult1616( pitch_int, st->pit_res_max ), pitch_fr ), tmp ); /* Q13 */ tmp = round_fx( L_shl( tmp32, 3 ) ); /* Q0 */ pitch_int = idiv1616U( tmp, st->pit_res_max ); - pitch_fr = sub( tmp, imult1616( pitch_int, st->pit_res_max ) ); + pitch_fr = sub( tmp, imult1616( pitch_int, st->pit_res_max ) ); /* Q0 */ } test(); test(); IF( EQ_32( total_brate, 48000 ) && EQ_16( L_frame_core, L_FRAME16k ) ) { - gain = mult_r( gain, 10486 /*0.32f Q15*/ ); + gain = mult_r( gain, 10486 /*0.32f Q15*/ ); /* Q15 */ } ELSE IF( EQ_32( total_brate, 48000 ) && EQ_16( L_frame_core, 512 ) ) { - gain = mult_r( gain, 13107 /*0.40f Q15*/ ); + gain = mult_r( gain, 13107 /*0.40f Q15*/ ); /* Q15 */ } ELSE { - gain = mult_r( gain, 20972 /*0.64f Q15*/ ); + gain = mult_r( gain, 20972 /*0.64f Q15*/ ); /* Q15 */ } } ELSE IF( GT_16( st->element_mode, IVAS_SCE ) && GE_32( total_brate, IVAS_96k ) ) { - gain = mult_r( gain, 13107 /*0.40f Q15*/ ); + gain = mult_r( gain, 13107 /*0.40f Q15*/ ); /* Q15 */ } ELSE { - gain = mult_r( gain, 20972 /*0.64f Q15*/ ); + gain = mult_r( gain, 20972 /*0.64f Q15*/ ); /* Q15 */ } } ELSE @@ -1578,7 +1593,7 @@ void tcx_ltp_post( IF( gain == 0 && hTcxLtpDec->tcxltp_gain_post_prev == 0 ) { /* The filtering is deactivated, just copy input to the output */ - Copy( sig_in + delay, sig_out + delay, L_transition ); + Copy( sig_in + delay, sig_out + delay, L_transition ); /* Qx */ } ELSE IF( gain == 0 && hTcxLtpDec->tcxltp_gain_post_prev != 0 ) { @@ -1609,7 +1624,7 @@ void tcx_ltp_post( test(); IF( gain == 0 && hTcxLtpDec->tcxltp_gain_post_prev == 0 ) { - Copy( sig_in + delay, sig_out + delay, L_transition ); + Copy( sig_in + delay, sig_out + delay, L_transition ); /* Qx */ } ELSE IF( hTcxLtpDec->tcxltp_gain_post_prev == 0 ) { @@ -1645,7 +1660,7 @@ void tcx_ltp_post( /* copy to output */ - Copy( sig_out, sig, output_frame ); + Copy( sig_out, sig, output_frame ); /* Qx */ /* Update */ hTcxLtpDec->tcxltp_pitch_int_post_prev = pitch_int; @@ -1658,18 +1673,18 @@ void tcx_ltp_post( move16(); st->pit_res_max_past = st->pit_res_max; move16(); - Copy( sig_out, hTcxLtpDec->tcxltp_mem_out, output_frame ); + Copy( sig_out, hTcxLtpDec->tcxltp_mem_out, output_frame ); /* Qx */ } void tcx_ltp_post32( Decoder_State *st, TCX_LTP_DEC_HANDLE hTcxLtpDec, - Word16 core, - Word16 output_frame, - Word16 delay, - Word32 *sig, - Word32 *tcx_buf, + Word16 core, /* Q0 */ + Word16 output_frame, /* Q0 */ + Word16 delay, /* Q0 */ + Word32 *sig, /* sig_q */ + Word32 *tcx_buf, /* sig_q */ Word16 sig_q ) { Word16 tmp, L_transition, lpcorder, filtIdx; @@ -1692,7 +1707,7 @@ void tcx_ltp_post32( filtIdx = 0; /* just to avoid comilation warnings */ move16(); - tcx_buf_len = NS2SA_FX2( st->output_Fs, TCXLTP_DELAY_NS ); + tcx_buf_len = NS2SA_FX2( st->output_Fs, TCXLTP_DELAY_NS ); /* Q0 */ move16(); SideInfoOnly = 0; move16(); @@ -1702,7 +1717,7 @@ void tcx_ltp_post32( move16(); } - L_frame_core = st->L_frame; + L_frame_core = st->L_frame; /* Q0 */ move16(); if ( EQ_16( st->element_mode, IVAS_CPE_MDCT ) ) @@ -1717,7 +1732,7 @@ void tcx_ltp_post32( pitch_int = 0; pitch_fr = 0; gain = 0; - L_frame_core = st->L_frame_past; + L_frame_core = st->L_frame_past; /* Q0 */ move16(); move16(); move16(); @@ -1725,10 +1740,10 @@ void tcx_ltp_post32( } ELSE { - bfi = st->bfi; - pitch_int = hTcxLtpDec->tcxltp_pitch_int; - pitch_fr = hTcxLtpDec->tcxltp_pitch_fr; - gain = hTcxLtpDec->tcxltp_gain; + bfi = st->bfi; /* Q0 */ + pitch_int = hTcxLtpDec->tcxltp_pitch_int; /* Q0 */ + pitch_fr = hTcxLtpDec->tcxltp_pitch_fr; /* Q0 */ + gain = hTcxLtpDec->tcxltp_gain; /* Q15 */ move16(); move16(); move16(); @@ -1738,25 +1753,25 @@ void tcx_ltp_post32( /* Parameters */ - L_transition = shr( output_frame, 2 ); + L_transition = shr( output_frame, 2 ); /* Q0 */ lpcorder = TCXLTP_LTP_ORDER; move16(); /* Input buffer */ sig_in = buf_in + tcx_buf_len; - Copy32( hTcxLtpDec->tcxltp_mem_in_32, buf_in, tcx_buf_len ); + Copy32( hTcxLtpDec->tcxltp_mem_in_32, buf_in, tcx_buf_len ); /* exp(exp_tcxltp_mem_in)*/ scale_sig32( buf_in, tcx_buf_len, sub( hTcxLtpDec->exp_tcxltp_mem_in, sub( 31, sig_q ) ) ); - Copy32( sig, buf_in + tcx_buf_len, output_frame ); + Copy32( sig, buf_in + tcx_buf_len, output_frame ); /* sig_q */ IF( core > ACELP_CORE ) { - Copy32( tcx_buf, sig_in + output_frame, tcx_buf_len ); + Copy32( tcx_buf, sig_in + output_frame, tcx_buf_len ); /* sig_q */ } - Copy32( sig + output_frame - tcx_buf_len, hTcxLtpDec->tcxltp_mem_in_32, tcx_buf_len ); + Copy32( sig + output_frame - tcx_buf_len, hTcxLtpDec->tcxltp_mem_in_32, tcx_buf_len ); /* sig_q */ hTcxLtpDec->exp_tcxltp_mem_in = sub( 31, sig_q ); move16(); /* Output buffer */ sig_out = buf_out + output_frame; - Copy32( hTcxLtpDec->tcxltp_mem_out_32, buf_out, output_frame ); + Copy32( hTcxLtpDec->tcxltp_mem_out_32, buf_out, output_frame ); /* exp(exp_tcxltp_mem_out) */ scale_sig32( buf_out, output_frame, sub( hTcxLtpDec->exp_tcxltp_mem_out, sub( 31, sig_q ) ) ); /* TCX-LTP parameters: integer pitch, fractional pitch, gain */ @@ -1781,7 +1796,7 @@ void tcx_ltp_post32( tmp32 = L_mult0( add( imult1616( pitch_int, st->pit_res_max ), pitch_fr ), tmp ); /* Q13 */ tmp = round_fx( L_shl( tmp32, 3 ) ); /* Q0 */ pitch_int = idiv1616U( tmp, st->pit_res_max ); - pitch_fr = sub( tmp, imult1616( pitch_int, st->pit_res_max ) ); + pitch_fr = sub( tmp, imult1616( pitch_int, st->pit_res_max ) ); /* Q0 */ } IF( st->element_mode == EVS_MONO ) /* hard tunings for EVS_MONO, HQ_48k is TCX only */ { @@ -1789,24 +1804,24 @@ void tcx_ltp_post32( test(); IF( EQ_32( total_brate, 48000 ) && EQ_16( L_frame_core, L_FRAME16k ) ) { - gain = mult_r( gain, 10486 /*0.32f Q15*/ ); + gain = mult_r( gain, 10486 /*0.32f Q15*/ ); /* Q15 */ } ELSE IF( EQ_32( total_brate, 48000 ) && EQ_16( L_frame_core, 512 ) ) { - gain = mult_r( gain, 13107 /*0.40f Q15*/ ); + gain = mult_r( gain, 13107 /*0.40f Q15*/ ); /* Q15 */ } ELSE { - gain = mult_r( gain, 20972 /*0.64f Q15*/ ); + gain = mult_r( gain, 20972 /*0.64f Q15*/ ); /* Q15 */ } } ELSE IF( GT_16( st->element_mode, IVAS_SCE ) && GE_32( total_brate, IVAS_96k ) ) { - gain = mult_r( gain, 13107 /*0.40f Q15*/ ); + gain = mult_r( gain, 13107 /*0.40f Q15*/ ); /* Q15 */ } ELSE { - gain = mult_r( gain, 20972 /*0.64f Q15*/ ); + gain = mult_r( gain, 20972 /*0.64f Q15*/ ); /* Q15 */ } } ELSE @@ -1815,11 +1830,11 @@ void tcx_ltp_post32( * PLC: LTP and bad frame (concealment) */ IF( st->pit_res_max == st->pit_res_max_past ) /* ensure consistent core SR to previous frame; otherwise, set gain to 0 */ { - pitch_int = hTcxLtpDec->tcxltp_pitch_int_post_prev; + pitch_int = hTcxLtpDec->tcxltp_pitch_int_post_prev; /* Q0 */ move16(); - pitch_fr = hTcxLtpDec->tcxltp_pitch_fr_post_prev; + pitch_fr = hTcxLtpDec->tcxltp_pitch_fr_post_prev; /* Q0 */ move16(); - gain = shl( mult_r( hTcxLtpDec->tcxltp_gain_post_prev, st->hTcxDec->damping ), 1 ); + gain = shl( mult_r( hTcxLtpDec->tcxltp_gain_post_prev, st->hTcxDec->damping ), 1 ); /* Q15 */ } ELSE { @@ -1940,7 +1955,7 @@ void tcx_ltp_post32( IF( gain == 0 && hTcxLtpDec->tcxltp_gain_post_prev == 0 ) { /* The filtering is deactivated, just copy input to the output */ - Copy32( sig_in + delay, sig_out + delay, L_transition ); + Copy32( sig_in + delay, sig_out + delay, L_transition ); /* sig_q */ } ELSE IF( gain == 0 && hTcxLtpDec->tcxltp_gain_post_prev != 0 ) { @@ -1970,7 +1985,7 @@ void tcx_ltp_post32( test(); IF( gain == 0 && hTcxLtpDec->tcxltp_gain_post_prev == 0 ) { - Copy32( sig_in + delay, sig_out + delay, L_transition ); + Copy32( sig_in + delay, sig_out + delay, L_transition ); /* sig_q */ } ELSE IF( hTcxLtpDec->tcxltp_gain_post_prev == 0 ) { @@ -2006,7 +2021,7 @@ void tcx_ltp_post32( /* copy to output */ - Copy32( sig_out, sig, output_frame ); + Copy32( sig_out, sig, output_frame ); /* sig_q */ /* Update */ hTcxLtpDec->tcxltp_pitch_int_post_prev = pitch_int; @@ -2018,7 +2033,7 @@ void tcx_ltp_post32( hTcxLtpDec->tcxltp_filt_idx_prev = filtIdx; move16(); st->pit_res_max_past = st->pit_res_max; - Copy32( sig_out, hTcxLtpDec->tcxltp_mem_out_32, output_frame ); + Copy32( sig_out, hTcxLtpDec->tcxltp_mem_out_32, output_frame ); /* sig_q */ hTcxLtpDec->exp_tcxltp_mem_out = sub( 31, sig_q ); move16(); } diff --git a/lib_com/tcx_mdct_window.c b/lib_com/tcx_mdct_window.c index adda4b8d2..c466a8271 100644 --- a/lib_com/tcx_mdct_window.c +++ b/lib_com/tcx_mdct_window.c @@ -109,21 +109,22 @@ void mdct_window_sine_flt( void mdct_window_sine_IVAS_updated( - PWord16 *window, - const Word32 Fs, - const Word16 n, - const Word16 window_type, - const Word16 element_mode ) + PWord16 *window, /* Qx */ + const Word32 Fs, /* Q0 */ + const Word16 n, /* Q0 */ + const Word16 window_type, /* Q0 */ + const Word16 element_mode /* Q0 */ +) { - IF( EQ_16( element_mode, EVS_MONO ) ) + IF( element_mode == EVS_MONO ) { const PWord16 *table; table = getSineWindowTable( n ); - FOR( Word32 i = 0; i < shr( n, 1 ); i++ ) + FOR( Word32 i = 0; i < n / 2; i++ ) { - window[i].v.re = table[i].v.re; + window[i].v.re = table[i].v.re; /* Qx */ move16(); - window[i].v.im = table[i].v.im; + window[i].v.im = table[i].v.im; /* Qx */ move16(); } // PMT("getSineWindowTable needs to be updated for IVAS") @@ -138,17 +139,17 @@ void mdct_window_sine_IVAS_updated( SWITCH( window_type ) { case FULL_OVERLAP: - window_table = tcx_mdct_window_48_fx; + window_table = tcx_mdct_window_48_fx; /* Q15 */ buf_in_size = 420; move16(); BREAK; case HALF_OVERLAP: - window_table = tcx_mdct_window_half_48_fx; + window_table = tcx_mdct_window_half_48_fx; /* Q15 */ buf_in_size = 180; BREAK; case TRANSITION_OVERLAP: case MIN_OVERLAP: - window_table = tcx_mdct_window_trans_48_fx; + window_table = tcx_mdct_window_trans_48_fx; /* Q15 */ buf_in_size = 60; move16(); BREAK; @@ -160,25 +161,28 @@ void mdct_window_sine_IVAS_updated( IF( EQ_32( Fs, 48000 ) ) { - Copy( window_table, temp, n ); + Copy( window_table, temp, n ); /* Q15 */ } ELSE { lerp( window_table, temp, n, buf_in_size ); } - FOR( Word32 i = 0; i < shr( n, 1 ); i++ ) + FOR( Word32 i = 0; i < n / 2; i++ ) { - window[i].v.re = temp[n - 1 - i]; + window[i].v.re = temp[n - 1 - i]; /* Qx */ move16(); - window[i].v.im = temp[i]; + window[i].v.im = temp[i]; /* Qx */ move16(); } } } ////Use mdct_window_sine_IVAS_updated for IVAS (EVS path covered as well) -void mdct_window_sine( PWord16 *window, Word16 n ) +void mdct_window_sine( + PWord16 *window, /* Qx */ + Word16 n /* Q0 */ +) { #ifdef IVAS_CODE if ( element_mode == EVS_MONO ) @@ -186,11 +190,11 @@ void mdct_window_sine( PWord16 *window, Word16 n ) { const PWord16 *table; table = getSineWindowTable( n ); - FOR( Word32 i = 0; i < shr( n, 1 ); i++ ) + FOR( Word32 i = 0; i < n / 2; i++ ) { - window[i].v.re = table[i].v.re; + window[i].v.re = table[i].v.re; /* Qx */ move16(); - window[i].v.im = table[i].v.im; + window[i].v.im = table[i].v.im; /* Qx */ move16(); } // PMT("getSineWindowTable needs to be updated for IVAS") @@ -388,10 +392,11 @@ void mdct_window_aldo_flt( void mdct_window_aldo( - Word16 *window1, - PWord16 *window1_trunc, - PWord16 *window2, - Word16 n ) + Word16 *window1, /* Q15 */ + PWord16 *window1_trunc, /* Q15 */ + PWord16 *window2, /* Q15 */ + Word16 n /* Q0 */ +) { Word16 i, n0, n1, n2, d, tmp; const Word16 *p1, *p2; @@ -400,36 +405,36 @@ void mdct_window_aldo( SWITCH( n ) { case 320 / 2: - p1 = window_48kHz_fx + 2; - p2 = window_48kHz_fx + 1110 - 3; + p1 = window_48kHz_fx + 2; /* Q15 */ + p2 = window_48kHz_fx + 1110 - 3; /* Q15 */ d = 6; move16(); BREAK; case 512 / 2: - p1 = window_256kHz; - p2 = window_256kHz + 592 - 1; + p1 = window_256kHz; /* Q15 */ + p2 = window_256kHz + 592 - 1; /* Q15 */ d = 2; BREAK; case 640 / 2: - p1 = window_48kHz_fx + 1; - p2 = window_48kHz_fx + 1110 - 2; + p1 = window_48kHz_fx + 1; /* Q15 */ + p2 = window_48kHz_fx + 1110 - 2; /* Q15 */ d = 3; move16(); BREAK; case 1024 / 2: - p1 = window_256kHz; - p2 = window_256kHz + 592 - 1; + p1 = window_256kHz; /* Q15 */ + p2 = window_256kHz + 592 - 1; /* Q15 */ d = 1; move16(); BREAK; case 1280 / 2: - p1 = window_48kHz_fx + 1; - p2 = window_48kHz_fx + 1110 - 2; + p1 = window_48kHz_fx + 1; /* Q15 */ + p2 = window_48kHz_fx + 1110 - 2; /* Q15 */ d = 3; BREAK; case 1920 / 2: - p1 = window_48kHz_fx; - p2 = window_48kHz_fx + 1110 - 1; + p1 = window_48kHz_fx; /* Q15 */ + p2 = window_48kHz_fx + 1110 - 1; /* Q15 */ d = 1; move16(); BREAK; @@ -448,7 +453,7 @@ void mdct_window_aldo( { FOR( i = 0; i < n0; i++ ) { - *window1 = *p1; + *window1 = *p1; /* Q15 */ move16(); window1++; p1 += d; @@ -457,7 +462,7 @@ void mdct_window_aldo( tmp = shr( n, 1 ); FOR( ; i < tmp; i++ ) { - window1_trunc->v.im = *p1; + window1_trunc->v.im = *p1; /* Q15 */ move16(); window1_trunc++; p1 += d; @@ -470,7 +475,7 @@ void mdct_window_aldo( FOR( ; i < n1; i++ ) { window1_trunc--; - window1_trunc->v.re = *p1; + window1_trunc->v.re = *p1; /* Q15 */ move16(); p1 += d; } @@ -481,12 +486,12 @@ void mdct_window_aldo( FOR( i = 0; i < n0; i += 2 ) { - *window1 = *p1; + *window1 = *p1; /* Q15 */ move16(); window1++; p1 += d; - *window1 = *pi; + *window1 = *pi; /* Q15 */ move16(); window1++; pi++; @@ -495,12 +500,12 @@ void mdct_window_aldo( tmp = shr( n, 1 ); FOR( ; i < tmp; i += 2 ) { - window1_trunc->v.im = *p1; + window1_trunc->v.im = *p1; /* Q15 */ move16(); window1_trunc++; p1 += d; - window1_trunc->v.im = *pi; + window1_trunc->v.im = *pi; /* Q15 */ move16(); window1_trunc++; pi++; @@ -509,12 +514,12 @@ void mdct_window_aldo( FOR( ; i < n1; i += 2 ) { window1_trunc--; - window1_trunc->v.re = *pi; + window1_trunc->v.re = *pi; /* Q15 */ move16(); pi++; window1_trunc--; - window1_trunc->v.re = *p1; + window1_trunc->v.re = *p1; /* Q15 */ move16(); p1 += d; } @@ -526,7 +531,7 @@ void mdct_window_aldo( tmp = shr( n2, 1 ); FOR( i = 0; i < tmp; i++ ) { - window2->v.im = *p2; + window2->v.im = *p2; /* Q15 */ move16(); window2++; p2 -= d; @@ -539,7 +544,7 @@ void mdct_window_aldo( FOR( ; i < n2; i++ ) { window2--; - window2->v.re = *p2; + window2->v.re = *p2; /* Q15 */ move16(); p2 -= d; } @@ -551,12 +556,12 @@ void mdct_window_aldo( tmp = shr( n2, 1 ); FOR( i = 0; i < tmp; i += 2 ) { - window2->v.im = *p2; + window2->v.im = *p2; /* Q15 */ move16(); window2++; p2 -= d; - window2->v.im = *pi; + window2->v.im = *pi; /* Q15 */ move16(); window2++; pi--; @@ -565,12 +570,12 @@ void mdct_window_aldo( FOR( ; i < n2; i += 2 ) { window2--; - window2->v.re = *pi; + window2->v.re = *pi; /* Q15 */ move16(); pi--; window2--; - window2->v.re = *p2; + window2->v.re = *p2; /* Q15 */ move16(); p2 -= d; } diff --git a/lib_dec/evs_dec_fx.c b/lib_dec/evs_dec_fx.c index eb44da8c9..d0a5d1d12 100644 --- a/lib_dec/evs_dec_fx.c +++ b/lib_dec/evs_dec_fx.c @@ -18,7 +18,7 @@ ivas_error evs_dec_fx( Decoder_State *st_fx, /* i/o : Decoder state structure */ - Word16 output_sp[], /* o : output synthesis signal */ + Word16 output_sp[], /* o : output synthesis signal Q0*/ frameMode_fx frameMode /* i : Decoder frame mode */ ) { @@ -99,7 +99,7 @@ ivas_error evs_dec_fx( st_fx->idchan = 0; move16(); - st_fx->element_brate = st_fx->total_brate; + st_fx->element_brate = st_fx->total_brate; /*Q0*/ move32(); st_fx->flag_ACELP16k = set_ACELP_flag( EVS_MONO, -1, st_fx->total_brate, 0, 0, -1, -1 ); @@ -118,7 +118,7 @@ ivas_error evs_dec_fx( move16(); } - output_frame = st_fx->output_frame_fx; + output_frame = st_fx->output_frame_fx; /*Q0*/ move16(); core_switching_flag = 0; @@ -138,9 +138,9 @@ ivas_error evs_dec_fx( IF( EQ_16( st_fx->bfi, 1 ) ) { - hq_core_type = hHQ_core->last_hq_core_type; + hq_core_type = hHQ_core->last_hq_core_type; /*Q0*/ move16(); - st_fx->coder_type = st_fx->last_coder_type; + st_fx->coder_type = st_fx->last_coder_type; /*Q0*/ move16(); } ELSE @@ -165,7 +165,7 @@ ivas_error evs_dec_fx( FOR( i = 0; i < hTcxDec->L_frameTCX; i++ ) { #ifdef BASOP_NOGLOB - hHQ_core->old_out_fx[i] = shl_sat( mult_r( hHQ_core->old_out_fx[i], st_fx->plcInfo.recovery_gain ), 1 ); + hHQ_core->old_out_fx[i] = shl_sat( mult_r( hHQ_core->old_out_fx[i], st_fx->plcInfo.recovery_gain ), 1 ); /*hHQ_core->exp_old_out*/ #else hHQ_core->old_out_fx[i] = shl( mult_r( hHQ_core->old_out_fx[i], st_fx->plcInfo.recovery_gain ), 1 ); #endif @@ -174,7 +174,7 @@ ivas_error evs_dec_fx( FOR( i = 0; i < st_fx->L_frame; i++ ) { #ifdef BASOP_NOGLOB - hHQ_core->old_out_LB_fx[i] = shl_sat( mult_r( hHQ_core->old_out_LB_fx[i], st_fx->plcInfo.recovery_gain ), 1 ); + hHQ_core->old_out_LB_fx[i] = shl_sat( mult_r( hHQ_core->old_out_LB_fx[i], st_fx->plcInfo.recovery_gain ), 1 ); /*hHQ_core->exp_old_out*/ #else hHQ_core->old_out_LB_fx[i] = shl( mult_r( hHQ_core->old_out_LB_fx[i], st_fx->plcInfo.recovery_gain ), 1 ); #endif @@ -190,11 +190,11 @@ ivas_error evs_dec_fx( f = L_deposit_l( hTcxDec->conceal_eof_gain ); /*Q14*/ s = norm_l( f ); s = sub( 16, s ); - tmp1 = extract_l( L_shr_r( f, s ) ); + tmp1 = extract_l( L_shr_r( f, s ) ); /*Q14 - s*/ FOR( i = 0; i < st_fx->hTcxCfg->tcx_mdct_window_lengthFB; i++ ) { #ifdef BASOP_NOGLOB - hTcxDec->syn_OverlFB[i] = shl_sat( mult_sat( tmp1, hTcxDec->syn_OverlFB[i] ), add( s, 1 ) ); + hTcxDec->syn_OverlFB[i] = shl_sat( mult_sat( tmp1, hTcxDec->syn_OverlFB[i] ), add( s, 1 ) ); /*hTcxDec->Q_syn_Overl*/ #else hTcxDec->syn_OverlFB[i] = shl( mult( tmp1, hTcxDec->syn_OverlFB[i] ), add( s, 1 ) ); #endif @@ -202,11 +202,11 @@ ivas_error evs_dec_fx( } s = norm_l( f ); s = sub( 16, s ); - tmp1 = extract_l( L_shr_r( f, s ) ); + tmp1 = extract_l( L_shr_r( f, s ) ); /*Q14 - s*/ FOR( i = 0; i < st_fx->hTcxCfg->tcx_mdct_window_length; i++ ) { #ifdef BASOP_NOGLOB - hTcxDec->syn_Overl[i] = shl_sat( mult_sat( tmp1, hTcxDec->syn_Overl[i] ), s ); + hTcxDec->syn_Overl[i] = shl_sat( mult_sat( tmp1, hTcxDec->syn_Overl[i] ), s ); /*hTcxDec->Q_syn_Overl*/ #else hTcxDec->syn_Overl[i] = shl( mult( tmp1, hTcxDec->syn_Overl[i] ), s ); #endif @@ -241,7 +241,7 @@ ivas_error evs_dec_fx( IF( NE_16( frameMode, FRAMEMODE_MISSING ) ) /* frame mode normal or future frame */ { getPartialCopyInfo( st_fx, &st_fx->coder_type, &sharpFlag ); - frameMode = st_fx->bfi; + frameMode = st_fx->bfi; /*Q0*/ move16(); } @@ -251,7 +251,7 @@ ivas_error evs_dec_fx( /* the partial copy is a RF FRAME_NO_DATA frame and should follow the concealment path*/ st_fx->bfi = 1; move16(); - st_fx->codec_mode = st_fx->last_codec_mode; + st_fx->codec_mode = st_fx->last_codec_mode; /*Q0*/ move16(); frameMode = FRAMEMODE_MISSING; move16(); @@ -268,7 +268,7 @@ ivas_error evs_dec_fx( { st_fx->bfi = 1; move16(); - st_fx->codec_mode = st_fx->last_codec_mode; + st_fx->codec_mode = st_fx->last_codec_mode; /*Q0*/ move16(); frameMode = FRAMEMODE_MISSING; move16(); @@ -287,7 +287,7 @@ ivas_error evs_dec_fx( { st_fx->bfi = 1; move16(); - st_fx->codec_mode = st_fx->last_codec_mode; + st_fx->codec_mode = st_fx->last_codec_mode; /*Q0*/ move16(); frameMode = FRAMEMODE_MISSING; move16(); @@ -311,14 +311,14 @@ ivas_error evs_dec_fx( decision_matrix_dec_fx( st_fx, &sharpFlag, &hq_core_type, &core_switching_flag ); IF( NE_16( st_fx->bfi, 1 ) ) { - st_fx->sr_core = i_mult( st_fx->L_frame, FRAMES_PER_SEC ); - st_fx->fscale_old = st_fx->fscale; + st_fx->sr_core = i_mult( st_fx->L_frame, FRAMES_PER_SEC ); /*Q0*/ + st_fx->fscale_old = st_fx->fscale; /*Q0*/ move16(); - st_fx->fscale = sr2fscale_fx( st_fx->sr_core ); + st_fx->fscale = sr2fscale_fx( st_fx->sr_core ); /*Q0*/ } ELSE { - frameMode = FRAMEMODE_MISSING; + frameMode = FRAMEMODE_MISSING; /*Q0*/ move16(); } } @@ -423,7 +423,7 @@ ivas_error evs_dec_fx( #ifdef ADD_IVAS_BWE 0, #endif - output_frame, voice_factors_fx, pitch_buf_fx, st_fx, &Qpostd ); + output_frame, voice_factors_fx, pitch_buf_fx, st_fx, &Qpostd ); /*Q0*/ } /*---------------------------------------------------------------------* @@ -474,11 +474,11 @@ ivas_error evs_dec_fx( #ifdef ADD_IVAS_BWE 0, #endif - output_frame, &Qpostd ); + output_frame, &Qpostd ); /*Q0*/ } ELSE IF( EQ_16( st_fx->extl, SWB_BWE_HIGHRATE ) || EQ_16( st_fx->extl, FB_BWE_HIGHRATE ) ) { - hb_synth_fx_exp = swb_bwe_dec_hr_fx( st_fx, old_syn_12k8_16k_fx, Qpostd, hb_synth_fx, output_frame, unbits, pitch_buf_fx ); + hb_synth_fx_exp = swb_bwe_dec_hr_fx( st_fx, old_syn_12k8_16k_fx, Qpostd, hb_synth_fx, output_frame, unbits, pitch_buf_fx ); /*Q0*/ } /*---------------------------------------------------------------------* @@ -497,13 +497,13 @@ ivas_error evs_dec_fx( move16(); } /*output_frame/FRAC_BWE_SMOOTH*/ - j = shr( output_frame, 1 ); + j = shr( output_frame, 1 ); /*Q0*/ tmp16_2 = 0; move16(); FOR( i = 0; i < j; i++ ) { /*hb_synth[i] *= (i*tmp);*/ - hb_synth_fx[i] = mult_r( hb_synth_fx[i], tmp16_2 ); + hb_synth_fx[i] = mult_r( hb_synth_fx[i], tmp16_2 ); /*hb_synth_fx_exp*/ move16(); #ifdef BASOP_NOGLOB tmp16_2 = add_o( tmp16_2, tmp16, &Overflow ); @@ -535,24 +535,24 @@ ivas_error evs_dec_fx( IF( GE_16( output_frame, L_FRAME16k ) ) { - tmps = NS2SA_FX2( st_fx->output_Fs, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS ); + tmps = NS2SA_FX2( st_fx->output_Fs, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS ); /*Q0*/ exp = s_min( Qpostd, st_fx->Qprev_synth_buffer_fx ); - Scale_sig( synth_fx, output_frame, sub( exp, Qpostd ) ); + Scale_sig( synth_fx, output_frame, sub( exp, Qpostd ) ); /*exp*/ Qpostd = exp; move16(); - Scale_sig( st_fx->prev_synth_buffer_fx, tmps, sub( exp, st_fx->Qprev_synth_buffer_fx ) ); + Scale_sig( st_fx->prev_synth_buffer_fx, tmps, sub( exp, st_fx->Qprev_synth_buffer_fx ) ); /*exp*/ st_fx->Qprev_synth_buffer_fx = exp; move16(); - Copy( synth_fx, tmp_buffer_fx, output_frame ); - Copy( st_fx->prev_synth_buffer_fx, synth_fx, tmps ); - Copy( tmp_buffer_fx, synth_fx + tmps, output_frame - tmps ); - Copy( tmp_buffer_fx + output_frame - tmps, st_fx->prev_synth_buffer_fx, tmps ); + Copy( synth_fx, tmp_buffer_fx, output_frame ); /*exp*/ + Copy( st_fx->prev_synth_buffer_fx, synth_fx, tmps ); /*st_fx->Qprev_synth_buffer_fx*/ + Copy( tmp_buffer_fx, synth_fx + tmps, output_frame - tmps ); /*exp*/ + Copy( tmp_buffer_fx + output_frame - tmps, st_fx->prev_synth_buffer_fx, tmps ); /*exp*/ } ELSE { exp = s_min( Qpostd, st_fx->Qprev_synth_buffer_fx ); - Scale_sig( synth_fx, output_frame, sub( exp, Qpostd ) ); + Scale_sig( synth_fx, output_frame, sub( exp, Qpostd ) ); /*exp*/ Qpostd = exp; move16(); st_fx->Qprev_synth_buffer_fx = exp; @@ -573,7 +573,7 @@ ivas_error evs_dec_fx( move16(); IF( GE_16( output_frame, L_FRAME16k ) ) { - tmps = NS2SA_FX2( st_fx->output_Fs, DELAY_BWE_TOTAL_NS ); + tmps = NS2SA_FX2( st_fx->output_Fs, DELAY_BWE_TOTAL_NS ); /*Q0*/ } waveform_adj2_fix( st_fx->tonalMDCTconceal.secondLastPcmOut, @@ -605,7 +605,7 @@ ivas_error evs_dec_fx( IF( EQ_16( st_fx->L_frame, L_FRAME ) ) { /* TBE on top of ACELP@12.8kHz */ - tmps = NS2SA_FX2( st_fx->output_Fs, MAX_DELAY_TBE_NS - DELAY_SWB_TBE_12k8_NS ); + tmps = NS2SA_FX2( st_fx->output_Fs, MAX_DELAY_TBE_NS - DELAY_SWB_TBE_12k8_NS ); /*Q0*/ } ELSE { @@ -613,12 +613,12 @@ ivas_error evs_dec_fx( IF( EQ_16( st_fx->extl, SWB_BWE_HIGHRATE ) || EQ_16( st_fx->extl, FB_BWE_HIGHRATE ) ) { /* HR SWB BWE on top of ACELP@16kHz */ - tmps = NS2SA_FX2( st_fx->output_Fs, DELAY_BWE_TOTAL_NS ); + tmps = NS2SA_FX2( st_fx->output_Fs, DELAY_BWE_TOTAL_NS ); /*Q0*/ } ELSE { /* TBE on top of ACELP@16kHz */ - tmps = NS2SA_FX2( st_fx->output_Fs, MAX_DELAY_TBE_NS - DELAY_SWB_TBE_16k_NS ); + tmps = NS2SA_FX2( st_fx->output_Fs, MAX_DELAY_TBE_NS - DELAY_SWB_TBE_16k_NS ); /*Q0*/ } } @@ -630,12 +630,12 @@ ivas_error evs_dec_fx( IF( ( NE_16( st_fx->extl, st_fx->last_extl ) || ( EQ_16( st_fx->extl, st_fx->last_extl ) && EQ_16( ( st_fx->core ^ st_fx->last_core ), HQ_CORE ) ) ) && !( EQ_16( st_fx->extl, SWB_CNG ) && EQ_16( st_fx->last_extl, SWB_TBE ) ) ) { /*incr = (short) ( L_FRAME / (tmps + 0.5f) );*/ - incr = idiv1616( L_FRAME * 2, add( shl( tmps, 1 ), 1 ) ); + incr = idiv1616( L_FRAME * 2, add( shl( tmps, 1 ), 1 ) ); /*Q0*/ tmp16 = 0; move16(); FOR( i = 0; i < tmps; i++ ) { - hb_synth_fx[i] = mult_r( hb_synth_fx[i], sin_table256_fx[tmp16] ); + hb_synth_fx[i] = mult_r( hb_synth_fx[i], sin_table256_fx[tmp16] /*Q15*/ ); /*Q15 - hb_synth_fx_exp*/ move16(); tmp16 = add( tmp16, incr ); } @@ -645,28 +645,28 @@ ivas_error evs_dec_fx( { /* the previous frame was TBE on top of ACELP@16kHz and the current frame is TBE on top of ACELP@12.8kHz */ /*incr = (short) ( L_FRAME / (tmps + 0.5f) );*/ - incr = idiv1616( L_FRAME * 2, add( shl( tmps, 1 ), 1 ) ); + incr = idiv1616( L_FRAME * 2, add( shl( tmps, 1 ), 1 ) ); /*Q0*/ tmp16 = 0; move16(); FOR( i = 0; i < tmps; i++ ) { - tmp_buffer_fx[i] = round_fx( L_mac( L_mult( st_fx->hb_prev_synth_buffer_fx[i], sin_table256_fx[sub( 255, tmp16 )] ), - st_fx->hb_prev_synth_buffer_fx[sub( sub( st_fx->old_bwe_delay, 1 ), i )], sin_table256_fx[tmp16] ) ); + tmp_buffer_fx[i] = round_fx( L_mac( L_mult( st_fx->hb_prev_synth_buffer_fx[i], sin_table256_fx[( 255 - tmp16 )] ), + st_fx->hb_prev_synth_buffer_fx[( ( st_fx->old_bwe_delay - 1 ) - i )], sin_table256_fx[tmp16] /*Q15*/ ) ); /*Q15 - hBWE_TD->prev_hb_synth_fx_exp*/ move16(); tmp16 = add( tmp16, incr ); } - Copy( tmp_buffer_fx, st_fx->hb_prev_synth_buffer_fx, tmps ); + Copy( tmp_buffer_fx, st_fx->hb_prev_synth_buffer_fx, tmps ); /*Q15 - hBWE_TD->prev_hb_synth_fx_exp*/ } ELSE IF( GT_16( tmps, st_fx->old_bwe_delay ) ) { /* the previous frame was TBE on top of ACELP@12.8kHz and the current frame is TBE on top of ACELP@16kHz */ /*incr = (short)( L_FRAME / (st->old_bwe_delay + 0.5f) );*/ - incr = idiv1616( L_FRAME * 2, add( shl( st_fx->old_bwe_delay, 1 ), 1 ) ); + incr = idiv1616( L_FRAME * 2, add( shl( st_fx->old_bwe_delay, 1 ), 1 ) ); /*Q0*/ tmp16 = 0; move16(); FOR( i = 0; i < st_fx->old_bwe_delay; i++ ) { - tmp_buffer_fx[i] = mult_r( st_fx->hb_prev_synth_buffer_fx[i], sin_table256_fx[sub( 255, tmp16 )] ); + tmp_buffer_fx[i] = mult_r( st_fx->hb_prev_synth_buffer_fx[i], sin_table256_fx[( 255 - tmp16 )] ); /*Q15 - hBWE_TD->prev_hb_synth_fx_exp*/ move16(); tmp16 = add( tmp16, incr ); } @@ -679,23 +679,23 @@ ivas_error evs_dec_fx( FOR( i = 0; i < st_fx->old_bwe_delay; i++ ) { /*tmp_buffer[tmps - 1 - i] += st->hb_prev_synth_buffer[st->old_bwe_delay - 1 - i] * sin_table256[i * incr];*/ - tmp_buffer_fx[sub( sub( tmps, 1 ), i )] = round_fx( L_mac( L_mult( tmp_buffer_fx[sub( sub( tmps, 1 ), i )], 32767 ), st_fx->hb_prev_synth_buffer_fx[sub( sub( st_fx->old_bwe_delay, 1 ), i )], sin_table256_fx[tmp16 /*i * incr*/] ) ); + tmp_buffer_fx[( ( tmps - 1 ) - i )] = round_fx( L_mac( L_mult( tmp_buffer_fx[( ( tmps - 1 ) - i )], 32767 ), st_fx->hb_prev_synth_buffer_fx[( ( st_fx->old_bwe_delay - 1 ) - i )], sin_table256_fx[tmp16 /*i * incr*/] ) ); /*Q15 - hBWE_TD->prev_hb_synth_fx_exp*/ move16(); tmp16 = add( tmp16, incr ); } - Copy( tmp_buffer_fx, st_fx->hb_prev_synth_buffer_fx, tmps ); + Copy( tmp_buffer_fx, st_fx->hb_prev_synth_buffer_fx, tmps ); /*Q15 - hBWE_TD->prev_hb_synth_fx_exp*/ } /* Delay hb_synth */ tmp16 = sub( hb_synth_fx_exp, hBWE_TD->prev_hb_synth_fx_exp ); IF( tmp16 != 0 ) { - Scale_sig( st_fx->hb_prev_synth_buffer_fx, tmps, tmp16 ); + Scale_sig( st_fx->hb_prev_synth_buffer_fx, tmps, tmp16 ); /*Q15 - hb_synth_fx_exp*/ } - Copy( hb_synth_fx, tmp_buffer_fx, output_frame ); - Copy( st_fx->hb_prev_synth_buffer_fx, hb_synth_fx, tmps ); - Copy( tmp_buffer_fx, hb_synth_fx + tmps, sub( output_frame, tmps ) ); - Copy( tmp_buffer_fx + sub( output_frame, tmps ), st_fx->hb_prev_synth_buffer_fx, tmps ); + Copy( hb_synth_fx, tmp_buffer_fx, output_frame ); /*Q15 - hb_synth_fx_exp*/ + Copy( st_fx->hb_prev_synth_buffer_fx, hb_synth_fx, tmps ); /*Q15 - hb_synth_fx_exp*/ + Copy( tmp_buffer_fx, hb_synth_fx + tmps, sub( output_frame, tmps ) ); /*Q15 - hb_synth_fx_exp*/ + Copy( tmp_buffer_fx + sub( output_frame, tmps ), st_fx->hb_prev_synth_buffer_fx, tmps ); /*Q15 - hb_synth_fx_exp*/ st_fx->old_bwe_delay = tmps; move16(); @@ -707,7 +707,7 @@ ivas_error evs_dec_fx( test(); IF( ( st_fx->ppp_mode_dec || ( EQ_16( st_fx->nelp_mode_dec, 1 ) && EQ_16( st_fx->bfi, 1 ) ) ) && EQ_16( st_fx->L_frame, st_fx->last_L_frame ) && ( GT_16( st_fx->bws_cnt, 1 ) || NE_16( st_fx->last_extl, -1 ) ) ) { - Copy( hBWE_TD->old_hb_synth_fx, hb_synth_fx, output_frame ); + Copy( hBWE_TD->old_hb_synth_fx, hb_synth_fx, output_frame ); /*Q15 - hb_synth_fx_exp*/ IF( LT_16( hBWE_TD->prev_hb_synth_fx_exp, 14 ) ) { hb_synth_fx_exp = add( hBWE_TD->prev_hb_synth_fx_exp, 1 ); @@ -720,7 +720,7 @@ ivas_error evs_dec_fx( } ELSE { - Copy( hb_synth_fx, hBWE_TD->old_hb_synth_fx, output_frame ); + Copy( hb_synth_fx, hBWE_TD->old_hb_synth_fx, output_frame ); /*Q15 - hb_synth_fx_exp*/ } add_vec_fx( synth_fx, Qpostd, hb_synth_fx, hb_synth_fx_exp, synth_fx, Qpostd, output_frame ); @@ -749,10 +749,10 @@ ivas_error evs_dec_fx( BREAK; /*Q15*/ } - L_tmp = L_deposit_l( 1 ); /*Q2*hb_synth_fx_exp*/ + L_tmp = L_deposit_l( 1 ); FOR( i = 0; i < output_frame; i++ ) { - L_tmp = L_add( L_tmp, Mpy_32_16_1( L_mult0( hb_synth_fx[i], hb_synth_fx[i] ), tmp16 ) ); /*Q2*hb_synth_fx_exp*/ + L_tmp = L_add( L_tmp, Mpy_32_16_1( L_mult0( hb_synth_fx[i], hb_synth_fx[i] ), tmp16 ) ); /*Q30 - 2*hb_synth_fx_exp*/ } exp = norm_l( L_tmp ); fra = Log2_norm_lc( L_shl( L_tmp, exp ) ); @@ -769,14 +769,14 @@ ivas_error evs_dec_fx( move16(); /* TCX-LTP Postfilter: used in MODE1 to update memories and to avoid discontinuities when the past frame was TCX */ - delta = NS2SA_FX2( st_fx->output_Fs, TCXLTP_DELAY_NS ); - Scale_sig( hTcxLtpDec->tcxltp_mem_in, delta, sub( Qpostd, Qpostd_prev ) ); - Scale_sig( hTcxLtpDec->tcxltp_mem_out, output_frame, sub( Qpostd, Qpostd_prev ) ); + delta = NS2SA_FX2( st_fx->output_Fs, TCXLTP_DELAY_NS ); /*Q0*/ + Scale_sig( hTcxLtpDec->tcxltp_mem_in, delta, sub( Qpostd, Qpostd_prev ) ); /*Qpostd*/ + Scale_sig( hTcxLtpDec->tcxltp_mem_out, output_frame, sub( Qpostd, Qpostd_prev ) ); /*Qpostd*/ tcx_ltp_post( st_fx, hTcxLtpDec, ACELP_CORE, output_frame, 0, synth_fx, NULL ); /* final output of synthesis signal */ - Copy( synth_fx, output_sp, output_frame ); + Copy( synth_fx, output_sp, output_frame ); /*Qpostd*/ } ELSE /* MODE2 PART */ { @@ -828,7 +828,7 @@ ivas_error evs_dec_fx( dec_acelp_tcx_frame_fx( st_fx, &concealWholeFrame, output_sp, st_fx->p_bpf_noise_buf, pcmbufFB, bwe_exc_extended_fx, voice_factors_fx, pitch_buf_fx ); - concealWholeFrameTmp = concealWholeFrame; + concealWholeFrameTmp = concealWholeFrame; /*Q0*/ move16(); if ( st_fx->bfi ) { @@ -900,7 +900,7 @@ ivas_error evs_dec_fx( move16(); } - st_fx->core_brate = L_sub( st_fx->total_brate, st_fx->extl_brate ); + st_fx->core_brate = L_sub( st_fx->total_brate, st_fx->extl_brate ); /*Q0*/ st_fx->bws_cnt = 0; move16(); @@ -931,7 +931,7 @@ ivas_error evs_dec_fx( fb_tbe_dec_fx( st_fx, fb_exc_fx, Q_fb_exc, hb_synth_fx, hb_synth_fx_exp ); } } - Copy( hb_synth_fx, hBWE_TD->old_hb_synth_fx, output_frame ); + Copy( hb_synth_fx, hBWE_TD->old_hb_synth_fx, output_frame ); /*Q15 - hb_synth_fx_exp*/ } ELSE { @@ -992,9 +992,9 @@ ivas_error evs_dec_fx( /* -------------------------------------------------------------- */ { - nab = s_min( st_fx->cldfbAna->no_channels, st_fx->cldfbSyn->no_channels ); - st_fx->cldfbSyn->lsb = s_min( st_fx->cldfbAna->no_channels, st_fx->cldfbSyn->no_channels ); - st_fx->cldfbSyn->usb = st_fx->cldfbSyn->no_channels; + nab = s_min( st_fx->cldfbAna->no_channels, st_fx->cldfbSyn->no_channels ); /*Q0*/ + st_fx->cldfbSyn->lsb = s_min( st_fx->cldfbAna->no_channels, st_fx->cldfbSyn->no_channels ); /*Q0*/ + st_fx->cldfbSyn->usb = st_fx->cldfbSyn->no_channels; /*Q0*/ move16(); st_fx->cldfbAna->lsb = st_fx->cldfbAna->no_channels; move16(); @@ -1015,12 +1015,12 @@ ivas_error evs_dec_fx( HANDLE_FD_CNG_DEC hFdCngDec = st_fx->hFdCngDec; noisy_speech_detection_fx( st_fx->hFdCngDec, st_fx->VAD && EQ_16( st_fx->m_frame_type, ACTIVE_FRAME ), output_sp, 0 ); - hFdCngDec->hFdCngCom->likelihood_noisy_speech = mult_r( hFdCngDec->hFdCngCom->likelihood_noisy_speech, 32440 /*0.99 Q15*/ ); + hFdCngDec->hFdCngCom->likelihood_noisy_speech = mult_r( hFdCngDec->hFdCngCom->likelihood_noisy_speech, 32440 /*0.99 Q15*/ ); /*Q15*/ if ( hFdCngDec->hFdCngCom->flag_noisy_speech != 0 ) { - hFdCngDec->hFdCngCom->likelihood_noisy_speech = add( hFdCngDec->hFdCngCom->likelihood_noisy_speech, 328 /*0.01 Q15*/ ); + hFdCngDec->hFdCngCom->likelihood_noisy_speech = add( hFdCngDec->hFdCngCom->likelihood_noisy_speech, 328 /*0.01 Q15*/ ); /*Q15*/ } - st_fx->lp_noise = hFdCngDec->lp_noise; + st_fx->lp_noise = hFdCngDec->lp_noise; /*Q9.23*/ move32(); #ifdef IVAS_CODE_CNG_FIX185_PLC_FADEOUT ApplyFdCng_fx( output, NULL, realBuffer, imagBuffer, st, concealWholeFrame, 0 ); @@ -1046,7 +1046,7 @@ ivas_error evs_dec_fx( FOR( i = 0; i < st_fx->L_frame / 2; i++ ) { #ifdef BASOP_NOGLOB - output_sp[i] = add_sat( output_sp[i], st_fx->hFdCngDec->hFdCngCom->olapBufferSynth2[i + 5 * st_fx->L_frame / 4] ); + output_sp[i] = add_sat( output_sp[i], st_fx->hFdCngDec->hFdCngCom->olapBufferSynth2[i + 5 * st_fx->L_frame / 4] ); /*Q0*/ #else output_sp[i] = add( output_sp[i], st_fx->hFdCngDec->hFdCngCom->olapBufferSynth2[i + 5 * st_fx->L_frame / 4] ); #endif @@ -1061,7 +1061,7 @@ ivas_error evs_dec_fx( { timeIn_e = s_max( 0, s_min( sub( getScaleFactor16( pcmbufFB, hTcxDec->L_frameTCX ), 3 ), timeIn_e ) ); } - Scale_sig( output_sp, st_fx->L_frame, timeIn_e ); + Scale_sig( output_sp, st_fx->L_frame, timeIn_e ); /*timeIn_e*/ timeIn_e = negate( timeIn_e ); cldfbAnalysisFiltering( st_fx->cldfbAna, realBuffer, imagBuffer, &st_fx->scaleFactor, output_sp, timeIn_e, CLDFB_NO_COL_MAX, workBuffer ); st_fx->scaleFactor.hb_scale = st_fx->scaleFactor.lb_scale; @@ -1072,8 +1072,8 @@ ivas_error evs_dec_fx( Word16 timeDomainBuffer[L_FRAME16k]; Word16 A[M + 1]; - Copy( st_fx->hFdCngDec->hFdCngCom->timeDomainBuffer, timeDomainBuffer, st_fx->L_frame ); - Copy( st_fx->hFdCngDec->hFdCngCom->A_cng, A, M + 1 ); + Copy( st_fx->hFdCngDec->hFdCngCom->timeDomainBuffer, timeDomainBuffer, st_fx->L_frame ); /*Q0*/ + Copy( st_fx->hFdCngDec->hFdCngCom->A_cng, A, M + 1 ); /*Q12*/ update_decoder_LPD_cng( st_fx, st_fx->coder_type, timeDomainBuffer, A, st_fx->p_bpf_noise_buf ); /* Generate additional comfort noise to mask potential coding artefacts */ @@ -1090,7 +1090,7 @@ ivas_error evs_dec_fx( { FOR( i = 0; i < st_fx->L_frame / 2; i++ ) { - timeDomainBuffer[i] = add( timeDomainBuffer[i], st_fx->hFdCngDec->hFdCngCom->olapBufferSynth2[add( i, i_mult( 5, shr( st_fx->L_frame, 2 ) ) )] ); + timeDomainBuffer[i] = add( timeDomainBuffer[i], st_fx->hFdCngDec->hFdCngCom->olapBufferSynth2[( i + ( 5 * ( st_fx->L_frame / 4 ) ) )] ); /*Q0*/ move16(); } } @@ -1117,10 +1117,10 @@ ivas_error evs_dec_fx( timeIn_e = 2; move16(); - Scale_sig( timeDomainBuffer, st_fx->L_frame, timeIn_e ); + Scale_sig( timeDomainBuffer, st_fx->L_frame, timeIn_e ); /*timeIn_e*/ IF( st_fx->p_bpf_noise_buf ) { - Scale_sig( st_fx->p_bpf_noise_buf, st_fx->L_frame, timeIn_e ); + Scale_sig( st_fx->p_bpf_noise_buf, st_fx->L_frame, timeIn_e ); /*timeIn_e*/ } timeIn_e = negate( timeIn_e ); @@ -1147,7 +1147,7 @@ ivas_error evs_dec_fx( IF( NE_16( st_fx->m_frame_type, ACTIVE_FRAME ) ) { - Scale_sig( st_fx->p_bpf_noise_buf, st_fx->L_frame, timeIn_e ); + Scale_sig( st_fx->p_bpf_noise_buf, st_fx->L_frame, timeIn_e ); /*timeIn_e*/ } } @@ -1179,28 +1179,28 @@ ivas_error evs_dec_fx( /* MODE1 MDCT to ACELP 2 transition */ delay_comp = NS2SA_FX2( st_fx->output_Fs, DELAY_CLDFB_NS ); - Scale_sig( st_fx->delay_buf_out_fx, delay_comp, negate( hHQ_core->Q_old_postdec ) ); + Scale_sig( st_fx->delay_buf_out_fx, delay_comp, negate( hHQ_core->Q_old_postdec ) ); /*Q0*/ hHQ_core->Q_old_postdec = 0; move16(); - delay_tdbwe = NS2SA_FX2( st_fx->output_Fs, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS ); + delay_tdbwe = NS2SA_FX2( st_fx->output_Fs, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS ); /*Q0*/ IF( GE_16( output_frame, L_FRAME16k ) ) { - Scale_sig( st_fx->prev_synth_buffer_fx, delay_tdbwe, sub( Qpostd, st_fx->Qprev_synth_buffer_fx ) ); + Scale_sig( st_fx->prev_synth_buffer_fx, delay_tdbwe, sub( Qpostd, st_fx->Qprev_synth_buffer_fx ) ); /*Qpostd*/ } test(); IF( EQ_16( st_fx->last_codec_mode, MODE1 ) && GT_16( st_fx->last_core_bfi, ACELP_CORE ) ) { - Copy_Scale_sig( st_fx->delay_buf_out_fx, output_sp, delay_comp, negate( timeIn_e ) ); /* copy the HQ/ACELP delay synchronization buffer at the beginning of ACELP frame */ + Copy_Scale_sig( st_fx->delay_buf_out_fx, output_sp, delay_comp, negate( timeIn_e ) ); /* copy the HQ/ACELP delay synchronization buffer at the beginning of ACELP frame */ /*-timeIn_e*/ IF( EQ_16( st_fx->core, ACELP_CORE ) ) { Word16 step, alpha, nz; i = 15; move16(); - tmps = NS2SA_FX2( st_fx->output_Fs, 3000000L ); - nz = NS2SA_FX2( st_fx->output_Fs, N_ZERO_MDCT_NS ); - step = Inv16( tmps, &i ); + tmps = NS2SA_FX2( st_fx->output_Fs, 3000000L ); /*Q0*/ + nz = NS2SA_FX2( st_fx->output_Fs, N_ZERO_MDCT_NS ); /*Q0*/ + step = Inv16( tmps, &i ); /*Q15 - i*/ step = shl( step, i ); alpha = 0; move16(); @@ -1208,11 +1208,11 @@ ivas_error evs_dec_fx( test(); IF( st_fx->prev_bfi && hHQ_core->HqVoicing ) { - Copy( hHQ_core->fer_samples_fx, &hHQ_core->old_out_fx[nz], tmps ); + Copy( hHQ_core->fer_samples_fx, &hHQ_core->old_out_fx[nz], tmps ); /*hHQ_core->Q_fer_samples*/ } ELSE { - Scale_sig( hHQ_core->old_out_fx, nz + tmps, negate( hHQ_core->Q_old_wtda ) ); + Scale_sig( hHQ_core->old_out_fx, nz + tmps, negate( hHQ_core->Q_old_wtda ) ); /*Q0*/ } hHQ_core->Q_old_wtda = 0; move16(); @@ -1220,7 +1220,7 @@ ivas_error evs_dec_fx( FOR( i = 0; i < tmps; i++ ) { #ifdef BASOP_NOGLOB - output_sp[i + delay_comp] = msu_r_sat( L_mult_sat( output_sp[i + delay_comp], alpha ), shr( hHQ_core->old_out_fx[i + nz], timeIn_e ), add( alpha, -32768 ) ); + output_sp[i + delay_comp] = msu_r_sat( L_mult_sat( output_sp[i + delay_comp], alpha ), shr( hHQ_core->old_out_fx[i + nz], timeIn_e ), add( alpha, -32768 ) ); /*timeIn_e*/ #else output_sp[i + delay_comp] = msu_r( L_mult( output_sp[i + delay_comp], alpha ), shr( hHQ_core->old_out_fx[i + nz], timeIn_e ), add( alpha, -32768 ) ); #endif @@ -1232,12 +1232,12 @@ ivas_error evs_dec_fx( { IF( EQ_32( st_fx->output_Fs, 8000 ) ) { - Copy( st_fx->delay_buf_out_fx, hTcxDec->FBTCXdelayBuf, delay_comp ); + Copy( st_fx->delay_buf_out_fx, hTcxDec->FBTCXdelayBuf, delay_comp ); /*Q0*/ } ELSE { - Copy( st_fx->prev_synth_buffer_fx, hTcxDec->FBTCXdelayBuf, delay_tdbwe ); - Copy( st_fx->delay_buf_out_fx, hTcxDec->FBTCXdelayBuf + delay_tdbwe, delay_comp ); + Copy( st_fx->prev_synth_buffer_fx, hTcxDec->FBTCXdelayBuf, delay_tdbwe ); /*st_fx->q_prev_synth_buffer_fx*/ + Copy( st_fx->delay_buf_out_fx, hTcxDec->FBTCXdelayBuf + delay_tdbwe, delay_comp ); /*Q0*/ } } } @@ -1247,30 +1247,30 @@ ivas_error evs_dec_fx( IF( EQ_16( st_fx->core, ACELP_CORE ) && !( st_fx->con_tcx ) ) { set16_fx( st_fx->delay_buf_out_fx, 0, delay_comp ); - Copy_Scale_sig( output_sp, st_fx->previoussynth_fx, output_frame, timeIn_e ); + Copy_Scale_sig( output_sp, st_fx->previoussynth_fx, output_frame, timeIn_e ); /*timeIn_e*/ } ELSE { - Copy( hTcxDec->old_synthFB_fx + sub( hTcxDec->old_synth_lenFB, delay_comp ), st_fx->delay_buf_out_fx, delay_comp ); + Copy( hTcxDec->old_synthFB_fx + sub( hTcxDec->old_synth_lenFB, delay_comp ), st_fx->delay_buf_out_fx, delay_comp ); /*Q0*/ IF( EQ_32( st_fx->output_Fs, 8000 ) ) { - Copy( hTcxDec->FBTCXdelayBuf, st_fx->previoussynth_fx, delay_comp ); + Copy( hTcxDec->FBTCXdelayBuf, st_fx->previoussynth_fx, delay_comp ); /*st_fx->q_prev_synth_buffer_fx*/ } ELSE { - Copy( hTcxDec->FBTCXdelayBuf + delay_tdbwe, st_fx->previoussynth_fx, delay_comp ); + Copy( hTcxDec->FBTCXdelayBuf + delay_tdbwe, st_fx->previoussynth_fx, delay_comp ); /*st_fx->q_prev_synth_buffer_fx*/ } - Copy( pcmbufFB, st_fx->previoussynth_fx + delay_comp, sub( output_frame, delay_comp ) ); + Copy( pcmbufFB, st_fx->previoussynth_fx + delay_comp, sub( output_frame, delay_comp ) ); /*Q0*/ } } /* Delay compensation for TD-BWE*/ IF( GE_16( output_frame, L_FRAME16k ) ) { - Copy( output_sp, tmp_buffer_fx, output_frame ); - Copy_Scale_sig( st_fx->prev_synth_buffer_fx, output_sp, delay_tdbwe, negate( timeIn_e ) ); - Copy( tmp_buffer_fx, output_sp + delay_tdbwe, sub( output_frame, delay_tdbwe ) ); - Copy_Scale_sig( tmp_buffer_fx + sub( output_frame, delay_tdbwe ), st_fx->prev_synth_buffer_fx, delay_tdbwe, timeIn_e ); + Copy( output_sp, tmp_buffer_fx, output_frame ); /*timeIn_e*/ + Copy_Scale_sig( st_fx->prev_synth_buffer_fx, output_sp, delay_tdbwe, negate( timeIn_e ) ); /*st_fx->q_prev_synth_buffer_fx*/ + Copy( tmp_buffer_fx, output_sp + delay_tdbwe, sub( output_frame, delay_tdbwe ) ); /*timeIn_e*/ + Copy_Scale_sig( tmp_buffer_fx + sub( output_frame, delay_tdbwe ), st_fx->prev_synth_buffer_fx, delay_tdbwe, timeIn_e ); /*timeIn_e*/ } test(); @@ -1311,13 +1311,13 @@ ivas_error evs_dec_fx( IF( EQ_32( st_fx->output_Fs, 8000 ) ) { - tmps = NS2SA_FX2( st_fx->output_Fs, DELAY_CLDFB_NS ); + tmps = NS2SA_FX2( st_fx->output_Fs, DELAY_CLDFB_NS ); /*Q0*/ } ELSE { - tmps = NS2SA_FX2( st_fx->output_Fs, DELAY_BWE_TOTAL_NS ); + tmps = NS2SA_FX2( st_fx->output_Fs, DELAY_BWE_TOTAL_NS ); /*Q0*/ } - delta = NS2SA_FX2( st_fx->output_Fs, TCXLTP_DELAY_NS ); + delta = NS2SA_FX2( st_fx->output_Fs, TCXLTP_DELAY_NS ); /*Q0*/ test(); test(); @@ -1330,8 +1330,8 @@ ivas_error evs_dec_fx( test(); IF( GT_16( st_fx->last_core_bfi, ACELP_CORE ) || ( st_fx->bfi && st_fx->last_core > ACELP_CORE ) || ( st_fx->prev_bfi && st_fx->last_con_tcx ) ) { - Copy_Scale_sig( hTcxDec->FBTCXdelayBuf, output_sp, tmps, negate( timeIn_e ) ); - Copy_Scale_sig( pcmbufFB, output_sp + tmps, sub( hTcxDec->L_frameTCX, tmps ), negate( timeIn_e ) ); + Copy_Scale_sig( hTcxDec->FBTCXdelayBuf, output_sp, tmps, negate( timeIn_e ) ); /*Q0*/ + Copy_Scale_sig( pcmbufFB, output_sp + tmps, sub( hTcxDec->L_frameTCX, tmps ), negate( timeIn_e ) ); /*Q0*/ } ELSE { @@ -1347,14 +1347,14 @@ ivas_error evs_dec_fx( FOR( i = 0; i < tmps; i++ ) { #ifdef BASOP_NOGLOB - output_sp[i + tmps] = msu_r_sat( L_mult_sat( shr( pcmbufFB[i], timeIn_e ), alpha ), output_sp[i + tmps], add( alpha, -32768 ) ); + output_sp[i + tmps] = msu_r_sat( L_mult_sat( shr( pcmbufFB[i], timeIn_e ), alpha ), output_sp[i + tmps], add( alpha, -32768 ) ); /*Q0*/ #else output_sp[i + tmps] = msu_r( L_mult( shr( pcmbufFB[i], timeIn_e ), alpha ), output_sp[i + tmps], add( alpha, -32768 ) ); #endif move16(); alpha = add( alpha, step ); } - Copy_Scale_sig( pcmbufFB + tmps, output_sp + shl( tmps, 1 ), sub( hTcxDec->L_frameTCX, shl( tmps, 1 ) ), negate( timeIn_e ) ); + Copy_Scale_sig( pcmbufFB + tmps, output_sp + shl( tmps, 1 ), sub( hTcxDec->L_frameTCX, shl( tmps, 1 ) ), negate( timeIn_e ) ); /*Q0*/ } Copy( pcmbufFB + sub( hTcxDec->L_frameTCX, tmps ), hTcxDec->FBTCXdelayBuf, tmps ); @@ -1364,12 +1364,12 @@ ivas_error evs_dec_fx( { IF( EQ_32( st_fx->output_Fs, 8000 ) ) { - Copy( hTcxDec->FBTCXdelayBuf, st_fx->delay_buf_out_fx, NS2SA( st_fx->output_Fs, DELAY_CLDFB_NS ) ); + Copy( hTcxDec->FBTCXdelayBuf, st_fx->delay_buf_out_fx, NS2SA( st_fx->output_Fs, DELAY_CLDFB_NS ) ); /*st_fx->q_prev_synth_buffer_fx*/ } ELSE { - Copy( hTcxDec->FBTCXdelayBuf, st_fx->prev_synth_buffer_fx, NS2SA( st_fx->output_Fs, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS ) ); - Copy( hTcxDec->FBTCXdelayBuf + NS2SA( st_fx->output_Fs, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS ), st_fx->delay_buf_out_fx, NS2SA( st_fx->output_Fs, DELAY_CLDFB_NS ) ); + Copy( hTcxDec->FBTCXdelayBuf, st_fx->prev_synth_buffer_fx, NS2SA( st_fx->output_Fs, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS ) ); /*st_fx->Qprev_synth_buffer_fx*/ + Copy( hTcxDec->FBTCXdelayBuf + NS2SA( st_fx->output_Fs, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS ), st_fx->delay_buf_out_fx, NS2SA( st_fx->output_Fs, DELAY_CLDFB_NS ) ); /*Q0*/ } } } @@ -1377,7 +1377,7 @@ ivas_error evs_dec_fx( { Word16 step, alpha; - Copy_Scale_sig( hTcxDec->FBTCXdelayBuf, output_sp, delta, negate( timeIn_e ) ); + Copy_Scale_sig( hTcxDec->FBTCXdelayBuf, output_sp, delta, negate( timeIn_e ) ); /*Q0*/ i = 15; move16(); @@ -1389,7 +1389,7 @@ ivas_error evs_dec_fx( FOR( i = delta; i < tmps; i++ ) { #ifdef BASOP_NOGLOB - output_sp[i] = msu_r_sat( L_mult( output_sp[i], alpha ), shr_sat( hTcxDec->FBTCXdelayBuf[i], timeIn_e ), add( alpha, -32768 ) ); + output_sp[i] = msu_r_sat( L_mult( output_sp[i], alpha ), shr_sat( hTcxDec->FBTCXdelayBuf[i], timeIn_e ), add( alpha, -32768 ) ); /*Q0*/ #else output_sp[i] = msu_r( L_mult( output_sp[i], alpha ), shr( hTcxDec->FBTCXdelayBuf[i], timeIn_e ), add( alpha, -32768 ) ); #endif @@ -1402,14 +1402,14 @@ ivas_error evs_dec_fx( } } - Scale_sig( hTcxLtpDec->tcxltp_mem_in, delta, sub( Qpostd, Qpostd_prev ) ); - Scale_sig( hTcxLtpDec->tcxltp_mem_out, output_frame, sub( Qpostd, Qpostd_prev ) ); + Scale_sig( hTcxLtpDec->tcxltp_mem_in, delta, sub( Qpostd, Qpostd_prev ) ); /*Qpostd*/ + Scale_sig( hTcxLtpDec->tcxltp_mem_out, output_frame, sub( Qpostd, Qpostd_prev ) ); /*Qpostd*/ - Scale_sig( output_sp, output_frame, timeIn_e ); + Scale_sig( output_sp, output_frame, timeIn_e ); /*timeIn_e*/ tcx_ltp_post( st_fx, hTcxLtpDec, st_fx->core, output_frame /*hTcxDec->L_frameTCX*/, NS2SA_FX2( st_fx->output_Fs, ACELP_LOOK_NS ) + tmps, output_sp, hTcxDec->FBTCXdelayBuf ); - Copy( output_sp, synth_fx, output_frame ); + Copy( output_sp, synth_fx, output_frame ); /*timeIn_e*/ } /* end of MODE2 */ @@ -1422,28 +1422,28 @@ ivas_error evs_dec_fx( IF( EQ_16( st_fx->codec_mode, MODE1 ) ) { - Copy( hTcxDec->synth_history_fx + output_frame, hTcxDec->synth_history_fx, add( sub( output_frame, post_hq_delay ), NS2SA_FX2( st_fx->output_Fs, PH_ECU_MEM_NS ) ) ); - Copy_Scale_sig( synth_fx, hTcxDec->old_synthFB_fx + sub( output_frame, post_hq_delay ), output_frame, negate( Qpostd ) ); /* output_sp not initialized yet */ + Copy( hTcxDec->synth_history_fx + output_frame, hTcxDec->synth_history_fx, add( sub( output_frame, post_hq_delay ), NS2SA_FX2( st_fx->output_Fs, PH_ECU_MEM_NS ) ) ); /*hTcxDec->q_synth_history_fx*/ + Copy_Scale_sig( synth_fx, hTcxDec->old_synthFB_fx + sub( output_frame, post_hq_delay ), output_frame, negate( Qpostd ) ); /* output_sp not initialized yet */ /* reset the remaining buffer, which is read in TCX concealment the necessary samples to fill this buffer are not available for all cases, the impact on the output is limited */ set16_fx( hTcxDec->old_synthFB_fx + sub( shl( output_frame, 1 ), post_hq_delay ), 0, post_hq_delay ); IF( GE_16( output_frame, L_FRAME16k ) ) { - Copy_Scale_sig( st_fx->prev_synth_buffer_fx, hTcxDec->old_synthFB_fx + sub( shl( output_frame, 1 ), NS2SA_FX2( st_fx->output_Fs, DELAY_BWE_TOTAL_NS ) ), NS2SA_FX2( st_fx->output_Fs, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS ), negate( st_fx->Qprev_synth_buffer_fx ) ); + Copy_Scale_sig( st_fx->prev_synth_buffer_fx, hTcxDec->old_synthFB_fx + sub( shl( output_frame, 1 ), NS2SA_FX2( st_fx->output_Fs, DELAY_BWE_TOTAL_NS ) ), NS2SA_FX2( st_fx->output_Fs, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS ), negate( st_fx->Qprev_synth_buffer_fx ) ); /*Q0*/ } IF( NE_16( st_fx->core, ACELP_CORE ) ) { IF( GE_16( output_frame, L_FRAME16k ) ) { - Copy_Scale_sig( synth_fx + output_frame, hTcxDec->old_synthFB_fx + sub( shl( output_frame, 1 ), NS2SA_FX2( st_fx->output_Fs, DELAY_CLDFB_NS ) ), NS2SA_FX2( st_fx->output_Fs, DELAY_CLDFB_NS ), negate( Qpostd ) ); - Copy_Scale_sig( hHQ_core->old_out_fx + NS2SA_FX2( st_fx->output_Fs, N_ZERO_MDCT_NS ), hTcxDec->old_synthFB_fx + shl( output_frame, 1 ), NS2SA_FX2( st_fx->output_Fs, PH_ECU_LOOKAHEAD_NS ), negate( hHQ_core->Q_old_wtda ) ); + Copy_Scale_sig( synth_fx + output_frame, hTcxDec->old_synthFB_fx + sub( shl( output_frame, 1 ), NS2SA_FX2( st_fx->output_Fs, DELAY_CLDFB_NS ) ), NS2SA_FX2( st_fx->output_Fs, DELAY_CLDFB_NS ), negate( Qpostd ) ); /*Q0*/ + Copy_Scale_sig( hHQ_core->old_out_fx + NS2SA_FX2( st_fx->output_Fs, N_ZERO_MDCT_NS ), hTcxDec->old_synthFB_fx + shl( output_frame, 1 ), NS2SA_FX2( st_fx->output_Fs, PH_ECU_LOOKAHEAD_NS ), negate( hHQ_core->Q_old_wtda ) ); /*Q0*/ } ELSE { - Copy_Scale_sig( synth_fx + output_frame, hTcxDec->old_synthFB_fx + sub( shl( output_frame, 1 ), NS2SA_FX2( st_fx->output_Fs, DELAY_BWE_TOTAL_NS ) ), NS2SA_FX2( st_fx->output_Fs, DELAY_CLDFB_NS ), negate( Qpostd ) ); - Copy_Scale_sig( hHQ_core->old_out_fx + NS2SA_FX2( st_fx->output_Fs, N_ZERO_MDCT_NS ), hTcxDec->old_synthFB_fx + shl( output_frame, 1 ) - NS2SA_FX2( st_fx->output_Fs, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS ), NS2SA_FX2( st_fx->output_Fs, PH_ECU_LOOKAHEAD_NS ), negate( hHQ_core->Q_old_wtda ) ); + Copy_Scale_sig( synth_fx + output_frame, hTcxDec->old_synthFB_fx + sub( shl( output_frame, 1 ), NS2SA_FX2( st_fx->output_Fs, DELAY_BWE_TOTAL_NS ) ), NS2SA_FX2( st_fx->output_Fs, DELAY_CLDFB_NS ), negate( Qpostd ) ); /*Q0*/ + Copy_Scale_sig( hHQ_core->old_out_fx + NS2SA_FX2( st_fx->output_Fs, N_ZERO_MDCT_NS ), hTcxDec->old_synthFB_fx + shl( output_frame, 1 ) - NS2SA_FX2( st_fx->output_Fs, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS ), NS2SA_FX2( st_fx->output_Fs, PH_ECU_LOOKAHEAD_NS ), negate( hHQ_core->Q_old_wtda ) ); /*Q0*/ } } } @@ -1453,7 +1453,7 @@ ivas_error evs_dec_fx( st_fx->Qprev_synth_buffer_fx = Qpostd; move16(); - Scale_sig32( st_fx->L_mem_hp_out_fx, 4, sub( Qpostd, Qpostd_prev ) ); + Scale_sig32( st_fx->L_mem_hp_out_fx, 4, sub( Qpostd, Qpostd_prev ) ); /*Qpostd*/ hp20( synth_fx, 1 /*stride*/, output_frame, st_fx->L_mem_hp_out_fx, L_mult0( output_frame, 50 ) ); /*----------------------------------------------------------------* @@ -1467,7 +1467,7 @@ ivas_error evs_dec_fx( } ELSE { - Copy( synth_fx, output_sp, output_frame ); + Copy( synth_fx, output_sp, output_frame ); /*Q0*/ } /*--------------------------------------------------------* diff --git a/lib_dec/fd_cng_dec.c b/lib_dec/fd_cng_dec.c index 0c3f8afd6..81a5ae151 100644 --- a/lib_dec/fd_cng_dec.c +++ b/lib_dec/fd_cng_dec.c @@ -362,16 +362,16 @@ void configureFdCngDec( #ifdef IVAS_FLOAT_FIXED void configureFdCngDec_ivas_fx( HANDLE_FD_CNG_DEC hFdCngDec, /* i/o: Contains the variables related to the FD-based CNG process */ - const Word16 bwidth, - const Word32 total_brate, - const Word16 L_frame, - const Word16 last_L_frame, - const Word16 element_mode ) + const Word16 bwidth, /*Q0*/ + const Word32 total_brate, /*Q0*/ + const Word16 L_frame, /*Q0*/ + const Word16 last_L_frame, /*Q0*/ + const Word16 element_mode /*Q0*/ ) { Word16 j, stopBandFR; HANDLE_FD_CNG_COM hsCom = hFdCngDec->hFdCngCom; - hsCom->CngBandwidth = bwidth; + hsCom->CngBandwidth = bwidth; /*Q0*/ move16(); if ( EQ_16( hsCom->CngBandwidth, FB ) ) { @@ -381,7 +381,7 @@ void configureFdCngDec_ivas_fx( test(); IF( NE_32( total_brate, FRAME_NO_DATA ) && NE_32( total_brate, SID_2k40 ) ) { - hsCom->CngBitrate = total_brate; + hsCom->CngBitrate = total_brate; /*Q0*/ move32(); } ELSE IF( EQ_32( hsCom->CngBitrate, -1 ) ) @@ -504,7 +504,7 @@ void configureFdCngDec_ivas_fx( hsCom->startBand = 2; move16(); - hsCom->stopBand = add( hsCom->FdCngSetup.sidPartitions[sub( hsCom->FdCngSetup.numPartitions, 1 )], 1 ); + hsCom->stopBand = add( hsCom->FdCngSetup.sidPartitions[( hsCom->FdCngSetup.numPartitions - 1 )], 1 ); /*Q0*/ initPartitions( hsCom->FdCngSetup.sidPartitions, hsCom->FdCngSetup.numPartitions, hsCom->startBand, hsCom->stopBand, hsCom->part, &hsCom->npart, hsCom->midband, hsCom->psize, hsCom->psize_norm, &hsCom->psize_norm_exp, hsCom->psize_inv, 0 ); IF( EQ_16( hsCom->stopFFTbin, 160 ) ) @@ -522,13 +522,13 @@ void configureFdCngDec_ivas_fx( hsCom->nFFTpart = 21; move16(); } - hsCom->nCLDFBpart = sub( hsCom->npart, hsCom->nFFTpart ); + hsCom->nCLDFBpart = sub( hsCom->npart, hsCom->nFFTpart ); /*Q0*/ move16(); FOR( j = 0; j < hsCom->nCLDFBpart; j++ ) { - hsCom->CLDFBpart[j] = sub( hsCom->part[add( j, hsCom->nFFTpart )], sub( hsCom->stopFFTbin, hsCom->startBand ) ); + hsCom->CLDFBpart[j] = sub( hsCom->part[( j + hsCom->nFFTpart )], sub( hsCom->stopFFTbin, hsCom->startBand ) ); /*Q0*/ move16(); - hsCom->CLDFBpsize_inv[j] = hsCom->psize_inv[add( j, hsCom->nFFTpart )]; + hsCom->CLDFBpsize_inv[j] = hsCom->psize_inv[( j + hsCom->nFFTpart )]; move16(); } @@ -536,13 +536,13 @@ void configureFdCngDec_ivas_fx( move16(); if ( GT_16( stopBandFR, hsCom->stopFFTbin ) ) { - stopBandFR = hsCom->stopFFTbin; + stopBandFR = hsCom->stopFFTbin; /*Q0*/ move16(); } initPartitions( hsCom->FdCngSetup.shapingPartitions, hsCom->FdCngSetup.numShapingPartitions, hsCom->startBand, hsCom->stopFFTbin, hFdCngDec->part_shaping, &hFdCngDec->npart_shaping, hFdCngDec->midband_shaping, hFdCngDec->psize_shaping, hFdCngDec->psize_shaping_norm, &hFdCngDec->psize_shaping_norm_exp, hFdCngDec->psize_inv_shaping, stopBandFR ); - hFdCngDec->nFFTpart_shaping = hFdCngDec->npart_shaping; + hFdCngDec->nFFTpart_shaping = hFdCngDec->npart_shaping; /*Q0*/ move16(); BASOP_getTables( &hsCom->olapWinAna, NULL, NULL, shr( hsCom->fftlen, 1 ) ); @@ -551,18 +551,18 @@ void configureFdCngDec_ivas_fx( SWITCH( hsCom->fftlen ) { case 512: - hsCom->olapWinAna_fx = olapWinAna512_fx; + hsCom->olapWinAna_fx = olapWinAna512_fx; /*Q30*/ hsCom->fftSineTab_fx = NULL; - hsCom->olapWinSyn_fx = olapWinSyn256_fx; + hsCom->olapWinSyn_fx = olapWinSyn256_fx; /*Q15*/ hsCom->fftlenShift = 8; move16(); hsCom->fftlenFac = 32767 /*1.0 Q15*/; move16(); BREAK; case 640: - hsCom->olapWinAna_fx = olapWinAna640_fx; - hsCom->fftSineTab_fx = fftSineTab640_fx; - hsCom->olapWinSyn_fx = olapWinSyn320_fx; + hsCom->olapWinAna_fx = olapWinAna640_fx; /*Q30*/ + hsCom->fftSineTab_fx = fftSineTab640_fx; /*Q15*/ + hsCom->olapWinSyn_fx = olapWinSyn320_fx; /*Q15*/ hsCom->fftlenShift = 9; move16(); hsCom->fftlenFac = 20480 /*0.625 Q15*/; @@ -1305,13 +1305,13 @@ void FdCng_decodeSID_ivas_fx( const Word16 gain_q_offset = tmp16; /* Q0 */ move16(); - invTrfMatrix_fx = (Word32 *) tmpRAM_fx; + invTrfMatrix_fx = (Word32 *) tmpRAM_fx; /*Q31*/ hFdCngCom = ( st->hFdCngDec )->hFdCngCom; - sidNoiseEst = hFdCngCom->sidNoiseEst; + sidNoiseEst = hFdCngCom->sidNoiseEst; /*Q16*/ - N = hFdCngCom->npart; + N = hFdCngCom->npart; /*Q0*/ move16(); gain = 0; move32(); @@ -1321,7 +1321,7 @@ void FdCng_decodeSID_ivas_fx( /* Read bitstream */ FOR( i = 0; i < FD_CNG_stages_37bits; i++ ) { - indices[i] = get_next_indice_fx( st, bits_37bits[i] ); + indices[i] = get_next_indice_fx( st, bits_37bits[i] ); /*Q0*/ move16(); } @@ -1350,7 +1350,7 @@ void FdCng_decodeSID_ivas_fx( move16(); FOR( i = 0; i < N; i++ ) { - sidNoiseEst[i] = BASOP_util_Pow2( Mpy_32_32( L_add( v[i], gain ), LOG_10_BASE_2_BY_10_Q31 ), Q16, &res_exp[i] ); + sidNoiseEst[i] = BASOP_util_Pow2( Mpy_32_32( L_add( v[i], gain ), LOG_10_BASE_2_BY_10_Q31 ), Q16, &res_exp[i] ); /*Q31 - res_exp[i]*/ move32(); if ( LT_16( max_res_exp, res_exp[i] ) ) { @@ -1361,7 +1361,7 @@ void FdCng_decodeSID_ivas_fx( FOR( i = 0; i < N; i++ ) { - sidNoiseEst[i] = L_shr( sidNoiseEst[i], sub( max_res_exp, res_exp[i] ) ); + sidNoiseEst[i] = L_shr( sidNoiseEst[i], sub( max_res_exp, res_exp[i] ) ); /*Q31 - max_res_exp*/ move32(); } @@ -1372,14 +1372,14 @@ void FdCng_decodeSID_ivas_fx( IF( hFdCngCom->CngBandwidth == NB ) { - sidNoiseEst[sub( N, 1 )] = Mpy_32_16_1( sidNoiseEst[sub( N, 1 )], NB_LAST_BAND_SCALE ); + sidNoiseEst[( N - 1 )] = Mpy_32_16_1( sidNoiseEst[( N - 1 )], NB_LAST_BAND_SCALE ); /*Q31 - max_res_exp*/ move32(); } test(); IF( EQ_16( hFdCngCom->CngBandwidth, SWB ) && LE_32( hFdCngCom->CngBitrate, ACELP_13k20 ) ) { - sidNoiseEst[sub( N, 1 )] = Mpy_32_16_1( sidNoiseEst[sub( N, 1 )], SWB_13k2_LAST_BAND_SCALE ); + sidNoiseEst[( N - 1 )] = Mpy_32_16_1( sidNoiseEst[( N - 1 )], SWB_13k2_LAST_BAND_SCALE ); /*Q31 - max_res_exp*/ move32(); } @@ -1916,16 +1916,16 @@ void generate_masking_noise( *-------------------------------------------------------------------*/ void generate_masking_noise_ivas_fx( - Word32 *timeDomainBuffer, /* i/o: time-domain signal */ + Word32 *timeDomainBuffer, /* i/o: time-domain signal Q31 - *exp_out*/ Word16 *exp_out, /* o : time-domain signal exp */ HANDLE_FD_CNG_COM hFdCngCom, /* i/o: FD_CNG structure containing all buffers and variables */ - const Word16 length, /* i : frame size */ - const Word16 core, /* i : core */ - const Word16 return_noise, /* i : noise is returned instead of added */ - const Word16 secondary, /* i : flag to indicate secondary noise generation */ - const Word16 element_mode, /* i : element mode */ + const Word16 length, /* i : frame size Q0*/ + const Word16 core, /* i : core Q0*/ + const Word16 return_noise, /* i : noise is returned instead of added Q0*/ + const Word16 secondary, /* i : flag to indicate secondary noise generation Q0*/ + const Word16 element_mode, /* i : element mode Q0*/ STEREO_CNG_DEC_HANDLE hStereoCng, /* i : stereo CNG handle */ - const Word16 nchan_out /* i : number of output channels */ + const Word16 nchan_out /* i : number of output channels Q0*/ ) { Word32 *cngNoiseLevel_fx = hFdCngCom->cngNoiseLevel; @@ -1941,14 +1941,14 @@ void generate_masking_noise_ivas_fx( Word16 shift; scale_fx = 0x40000000; // 1.0 in Q30 move32(); - startBand = hFdCngCom->startBand; + startBand = hFdCngCom->startBand; /*Q0*/ move16(); shift = getScaleFactor32( hFdCngCom->cngNoiseLevel, FFTCLDFBLEN ); if ( LT_16( sub( hFdCngCom->cngNoiseLevelExp, shift ), 4 ) ) { - shift = sub( hFdCngCom->cngNoiseLevelExp, 4 ); + shift = sub( hFdCngCom->cngNoiseLevelExp, 4 ); /*Q0*/ } - scale_sig32( hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, shift ); + scale_sig32( hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, shift ); /*hFdCngCom->cngNoiseLevelExp*/ hFdCngCom->cngNoiseLevelExp = sub( hFdCngCom->cngNoiseLevelExp, shift ); move16(); @@ -2004,11 +2004,11 @@ void generate_masking_noise_ivas_fx( IF( startBand == 0 ) { rand_gauss_fx( &fftBuffer_fx[0], seed, *exp_out ); // Q15 - ptr_r_fx = fftBuffer_fx + 2; + ptr_r_fx = fftBuffer_fx + 2; /*Q31 - hFdCngCom->fftBuffer_exp*/ Word16 exp1; exp1 = add( hFdCngCom->cngNoiseLevelExp, 1 ); Word32 mpy1; - mpy1 = Sqrt32( Mpy_32_32( scale_fx, *ptr_level_fx ), &exp1 ); // Q = noise_exp-1 + mpy1 = Sqrt32( Mpy_32_32( scale_fx, *ptr_level_fx ), &exp1 ); /*Q31 - exp1*/ mpy1 = L_shl( mpy1, exp1 ); // Q31 fftBuffer_fx[0] = Mpy_32_32( fftBuffer_fx[0], mpy1 ); /* DC component in FFT */ // Q = Q15 ptr_level_fx++; @@ -2018,7 +2018,7 @@ void generate_masking_noise_ivas_fx( fftBuffer_fx[0] = 0; move32(); set32_fx( fftBuffer_fx + 2, 0, shl( sub( startBand, 1 ), 1 ) ); - ptr_r_fx = fftBuffer_fx + shl( startBand, 1 ); + ptr_r_fx = fftBuffer_fx + shl( startBand, 1 ); /*Q31 - hFdCngCom->fftBuffer_exp*/ } ptr_i_fx = ptr_r_fx + 1; FOR( ; ptr_level_fx < cngNoiseLevel_fx + hFdCngCom->stopFFTbin - startBand; ptr_level_fx++ ) @@ -2028,7 +2028,7 @@ void generate_masking_noise_ivas_fx( Word16 exp2; exp2 = add( hFdCngCom->cngNoiseLevelExp, 1 ); Word32 mpy2; - mpy2 = Sqrt32( L_shr( Mpy_32_32( scale_fx, *ptr_level_fx ), 1 ), &exp2 ); // Q = noise_exp-1 + mpy2 = Sqrt32( L_shr( Mpy_32_32( scale_fx, *ptr_level_fx ), 1 ), &exp2 ); /*Q31 - exp2*/ ( *ptr_r_fx ) = L_shl( Mpy_32_32( *ptr_r_fx, mpy2 ), exp2 ); // Q = Q15 move32(); ptr_r_fx += 2; @@ -2068,11 +2068,11 @@ void generate_masking_noise_ivas_fx( /* Add some comfort noise on top of decoded signal */ IF( return_noise ) { - Copy32( maskingNoise_fx, timeDomainBuffer, s_min( hFdCngCom->frameSize, length ) ); + Copy32( maskingNoise_fx, timeDomainBuffer, s_min( hFdCngCom->frameSize, length ) ); /*Q31 - *exp_out*/ } ELSE { - v_add_fixed( maskingNoise_fx, timeDomainBuffer, timeDomainBuffer, s_min( hFdCngCom->frameSize, length ), 0 ); + v_add_fixed( maskingNoise_fx, timeDomainBuffer, timeDomainBuffer, s_min( hFdCngCom->frameSize, length ), 0 ); /*Q31 - *exp_out*/ } return; @@ -2339,14 +2339,14 @@ void generate_stereo_masking_noise( *-------------------------------------------------------------------*/ void generate_stereo_masking_noise_fx( - Word16 *syn, /* i/o: time-domain signal */ + Word16 *syn, /* i/o: time-domain signal Q_syn*/ Word16 Q_syn, Decoder_State *st, /* i/o: decoder state structure */ STEREO_TD_DEC_DATA_HANDLE hStereoTD, /* i : TD stereo structure */ - const Word16 flag_sec_CNA, /* i : CNA flag for secondary channel */ - const Word16 fadeOut, /* i : only fade out of previous state */ + const Word16 flag_sec_CNA, /* i : CNA flag for secondary channel Q0*/ + const Word16 fadeOut, /* i : only fade out of previous state Q0*/ STEREO_CNG_DEC_HANDLE hStereoCng, /* i : Stereo CNG handle */ - const Word16 nchan_out /* i : number of output channels */ + const Word16 nchan_out /* i : number of output channels Q0*/ ) { HANDLE_FD_CNG_COM hFdCngCom; @@ -2361,22 +2361,22 @@ void generate_stereo_masking_noise_fx( IF( st->idchan == 0 ) { hFdCngCom = st->hFdCngDec->hFdCngCom; - Copy_Scale_sig_16_32( hStereoCng->olapBufferSynth22_fx, Ns_fx, shr( hFdCngCom->frameSize, 1 ), sub( Q6, st->Q_syn ) ); - Copy32( hFdCngCom->olapBufferSynth2_fx, Np_fx, shr( hFdCngCom->frameSize, 1 ) ); + Copy_Scale_sig_16_32( hStereoCng->olapBufferSynth22_fx, Ns_fx, shr( hFdCngCom->frameSize, 1 ), sub( Q6, st->Q_syn ) ); /*Q6*/ + Copy32( hFdCngCom->olapBufferSynth2_fx, Np_fx, shr( hFdCngCom->frameSize, 1 ) ); /*st->Q_syn*/ - set32_fx( &Np_fx[shr( hFdCngCom->frameSize, 1 )], 0, shr( hFdCngCom->frameSize, 1 ) ); - set32_fx( &Ns_fx[shr( hFdCngCom->frameSize, 1 )], 0, shr( hFdCngCom->frameSize, 1 ) ); + set32_fx( &Np_fx[( hFdCngCom->frameSize / 2 )], 0, shr( hFdCngCom->frameSize, 1 ) ); + set32_fx( &Ns_fx[( hFdCngCom->frameSize / 2 )], 0, shr( hFdCngCom->frameSize, 1 ) ); IF( !fadeOut ) { - Copy_Scale_sig_16_32( hStereoCng->olapBufferSynth22_fx, hStereoCng->olapBufferSynth22_32fx, hFdCngCom->fftlen, sub( Q15, st->Q_syn ) ); + Copy_Scale_sig_16_32( hStereoCng->olapBufferSynth22_fx, hStereoCng->olapBufferSynth22_32fx, hFdCngCom->fftlen, sub( Q15, st->Q_syn ) ); /*Q15*/ generate_masking_noise_ivas_fx( N1_fx, &N1_fx_exp, hFdCngCom, hFdCngCom->frameSize, 0, 1, 0, st->element_mode, hStereoCng, nchan_out ); // N1_fx Q6 /* Generate masking noise for secondary channel */ IF( flag_sec_CNA ) { generate_masking_noise_ivas_fx( N2_fx, &N2_fx_exp, hFdCngCom, hFdCngCom->frameSize, 0, 1, 1, st->element_mode, hStereoCng, nchan_out ); // N2_fx Q6 - gamma_fx = L_shr( Mpy_32_32( hStereoCng->c_PS_LT_fx, hStereoCng->c_PS_LT_fx ), 1 ); + gamma_fx = L_shr( Mpy_32_32( hStereoCng->c_PS_LT_fx, hStereoCng->c_PS_LT_fx ), 1 ); /*Q30*/ scale_fx = ONE_IN_Q30; move32(); IF( LT_32( gamma_fx, 966367642 /* 0.9 in Q30 */ ) ) @@ -2394,7 +2394,7 @@ void generate_stereo_masking_noise_fx( move16(); move16(); move16(); - gamma_fx = Sqrt32( L_add( gamma_fx, ONE_IN_Q30 ), &exp_gamma1 ); + gamma_fx = Sqrt32( L_add( gamma_fx, ONE_IN_Q30 ), &exp_gamma1 ); /*Q31 - exp_gamma1*/ Word32 temp; temp = Sqrt32( gamma_fx, &exp_gamma2 ); // Q31-exp_gamma1 gamma_fx = L_sub( gamma_fx, L_shl( temp, sub( exp_gamma2, exp_gamma1 ) ) ); // Q31-exp_gamma1 @@ -2418,9 +2418,9 @@ void generate_stereo_masking_noise_fx( add2 = Mpy_32_32( scale_fx, L_shl( L_sub( N1_fx[i], Mpy_32_32( gamma_fx, L_shl( N2_fx[i], Q1 ) ) ), Q1 ) ); // Q6 if ( hStereoCng->c_PS_LT_fx < 0 ) { - add2 = L_negate( add2 ); + add2 = L_negate( add2 ); /*Q6*/ } - Ns_fx[i] = L_add( Ns_fx[i], add2 ); + Ns_fx[i] = L_add( Ns_fx[i], add2 ); /*Q6*/ move32(); } FOR( ; i < hFdCngCom->frameSize; i++ ) @@ -2440,13 +2440,13 @@ void generate_stereo_masking_noise_fx( FOR( i = 0; i < shr( hFdCngCom->frameSize, 1 ); i++ ) { hFdCngCom->olapBufferSynth2[i] = (Word16) L_shr( Mpy_32_32( scale_fx_tmp, - L_add( L_shr( hFdCngCom->olapBufferSynth2[add( i, i_mult( 5, shr( hFdCngCom->frameSize, 2 ) ) )], Q15 ), - Mpy_32_16_1( gamma_fx, hStereoCng->olapBufferSynth22_fx[add( i, i_mult( 5, shr( hFdCngCom->frameSize, 2 ) ) )] ) ) ), + L_add( L_shr( hFdCngCom->olapBufferSynth2[( i + ( 5 * ( hFdCngCom->frameSize / 4 ) ) )], Q15 ), + Mpy_32_16_1( gamma_fx, hStereoCng->olapBufferSynth22_fx[( i + ( 5 * ( hFdCngCom->frameSize / 4 ) ) )] ) ) ), Q14 ); // Q_olap move16(); hStereoCng->olapBufferSynth22_fx[i] = (Word16) L_shr( Mpy_32_32( scale_fx_tmp, - L_sub( L_shr( hFdCngCom->olapBufferSynth2[add( i, i_mult( 5, shr( hFdCngCom->frameSize, 2 ) ) )], Q15 ), - Mpy_32_16_1( gamma_fx, hStereoCng->olapBufferSynth22_fx[add( i, i_mult( 5, shr( hFdCngCom->frameSize, 2 ) ) )] ) ) ), + L_sub( L_shr( hFdCngCom->olapBufferSynth2[( i + ( 5 * ( hFdCngCom->frameSize / 4 ) ) )], Q15 ), + Mpy_32_16_1( gamma_fx, hStereoCng->olapBufferSynth22_fx[( i + ( 5 * ( hFdCngCom->frameSize / 4 ) ) )] ) ) ), Q14 ); // Q_olap move16(); } @@ -2458,16 +2458,16 @@ void generate_stereo_masking_noise_fx( Np_fx[i] = L_add( Np_fx[i], N1_fx[i] ); // Q6 move32(); } - Copy32( &N1_fx[shr( hFdCngCom->frameSize, 1 )], &Np_fx[shr( hFdCngCom->frameSize, 1 )], shr( hFdCngCom->frameSize, 1 ) ); - scale_fx = L_shl( shr( hFdCngCom->fftlen, 1 ), Q22 ); // Q21 + Copy32( &N1_fx[( hFdCngCom->frameSize / 2 )], &Np_fx[( hFdCngCom->frameSize / 2 )], shr( hFdCngCom->frameSize, 1 ) ); /*Q6*/ + scale_fx = L_shl( shr( hFdCngCom->fftlen, 1 ), Q22 ); // Q21 FOR( i = 0; i < hFdCngCom->frameSize; i++ ) { - hFdCngCom->olapBufferSynth2[i] = (Word16) L_shr( Mpy_32_16_1( scale_fx, hFdCngCom->olapBufferSynth2[add( i, i_mult( 5, shr( hFdCngCom->frameSize, 2 ) ) )] ), Q6 ); // Q_olap + hFdCngCom->olapBufferSynth2[i] = (Word16) L_shr( Mpy_32_16_1( scale_fx, hFdCngCom->olapBufferSynth2[( i + ( 5 * ( hFdCngCom->frameSize / 4 ) ) )] ), Q6 ); // Q_olap move16(); } } - Copy_Scale_sig_32_16( hStereoCng->olapBufferSynth22_32fx, hStereoCng->olapBufferSynth22_fx, hFdCngCom->fftlen, sub( st->Q_syn, 15 ) ); + Copy_Scale_sig_32_16( hStereoCng->olapBufferSynth22_32fx, hStereoCng->olapBufferSynth22_fx, hFdCngCom->fftlen, sub( st->Q_syn, 15 ) ); /*st->Q_syn*/ } ELSE { @@ -2495,9 +2495,9 @@ void generate_stereo_masking_noise_fx( ELSE IF( hStereoCng->enableSecCNA ) { Word16 SP_ratio_fx; - SP_ratio_fx = extract_h( hStereoTD->SP_ratio_LT_fx ); /* Use long-term SP ratio based on L/R synthesis */ + SP_ratio_fx = extract_h( hStereoTD->SP_ratio_LT_fx ); /* Use long-term SP ratio based on L/R synthesis Q15*/ Word16 prevSP_ratio_fx; - prevSP_ratio_fx = hStereoTD->prevSP_ratio_fx; /* Use long-term SP ratio based on L/R synthesis */ + prevSP_ratio_fx = hStereoTD->prevSP_ratio_fx; /* Use long-term SP ratio based on L/R synthesis Q15*/ move16(); /* scale and add masking noise */ FOR( i = 0; i < shr( *hStereoCng->frameSize, 2 ); i++ ) @@ -2506,20 +2506,20 @@ void generate_stereo_masking_noise_fx( Word16 scale_fx_tmp; scale_fx_tmp = BASOP_Util_Divide3216_Scale( L_add( L_mult0( prevSP_ratio_fx, sub( shr( *hStereoCng->frameSize, 2 ), i ) ), L_mult0( SP_ratio_fx, i ) ), shr( *hStereoCng->frameSize, 2 ), &s ); // Q15 scale_fx_tmp = shl( scale_fx_tmp, s ); - syn[i] = add( syn[i], mult( scale_fx_tmp, shr( hStereoCng->maskingNoiseS_fx[i], sub( Q6, Q_syn ) ) ) ); + syn[i] = add( syn[i], mult( scale_fx_tmp, shr( hStereoCng->maskingNoiseS_fx[i], sub( Q6, Q_syn ) ) ) ); /*Q_syn*/ move16(); } FOR( ; i < *hStereoCng->frameSize / 2; i++ ) { - syn[i] = add( syn[i], mult( SP_ratio_fx, shr( hStereoCng->maskingNoiseS_fx[i], sub( Q6, Q_syn ) ) ) ); + syn[i] = add( syn[i], mult( SP_ratio_fx, shr( hStereoCng->maskingNoiseS_fx[i], sub( Q6, Q_syn ) ) ) ); /*Q_syn*/ move16(); } FOR( ; i < *hStereoCng->frameSize; i++ ) { - syn[i] = add( syn[i], mult( SP_ratio_fx, shr( hStereoCng->maskingNoiseS_fx[i], sub( Q6, Q_syn ) ) ) ); + syn[i] = add( syn[i], mult( SP_ratio_fx, shr( hStereoCng->maskingNoiseS_fx[i], sub( Q6, Q_syn ) ) ) ); /*Q_syn*/ move16(); } - hStereoTD->prevSP_ratio_fx = extract_h( hStereoTD->SP_ratio_LT_fx ); + hStereoTD->prevSP_ratio_fx = extract_h( hStereoTD->SP_ratio_LT_fx ); /*Q15*/ move16(); } @@ -2651,14 +2651,14 @@ void generate_masking_noise_lb_dirac( #ifdef IVAS_FLOAT_FIXED void generate_masking_noise_lb_dirac_fx( HANDLE_FD_CNG_COM hFdCngCom, /* i/o: FD_CNG structure containing all buffers and variables */ - Word32 *tdBuffer, /* i/o: time-domain signal, if NULL no LB-CNA */ - const Word16 nCldfbTs, /* i : number of CLDFB slots that will be rendered */ - const Word16 cna_flag /* i : CNA flag for LB and HB */ + Word32 *tdBuffer, /* i/o: time-domain signal, if NULL no LB-CNA Q11*/ + const Word16 nCldfbTs, /* i : number of CLDFB slots that will be rendered Q0*/ + const Word16 cna_flag /* i : CNA flag for LB and HB Q0*/ ) { Word16 i; - Word32 *cngNoiseLevel = hFdCngCom->cngNoiseLevel; - Word32 *fftBuffer = hFdCngCom->fftBuffer; + Word32 *cngNoiseLevel = hFdCngCom->cngNoiseLevel; /*hFdCngCom->cngNoiseLevelExp*/ + Word32 *fftBuffer = hFdCngCom->fftBuffer; /*hFdCngCom->fftBuffer_exp*/ Word32 *ptr_r; Word32 *ptr_i; Word32 *ptr_level; @@ -2710,19 +2710,19 @@ void generate_masking_noise_lb_dirac_fx( IF( scale != 0 ) { /*Generate LF comfort noise only at first slot, for the whole frame*/ - ptr_level = cngNoiseLevel; + ptr_level = cngNoiseLevel; /*hFdCngCom->cngNoiseLevelExp*/ /* Generate Gaussian random noise in real and imaginary parts of the FFT bins Amplitudes are adjusted to the estimated noise level cngNoiseLevel_flt in each bin */ IF( EQ_16( hFdCngCom->startBand, 0 ) ) { rand_gauss_fx( &fftBuffer[0], seed, exp_out ); - ptr_r = fftBuffer + 2; + ptr_r = fftBuffer + 2; /*hFdCngCom->fftBuffer_exp*/ Word16 exp2 = sub( 31, hFdCngCom->cngNoiseLevelExp ); - Word32 sqr = Sqrt32( L_shr( Mpy_32_32( scale, *ptr_level ), 1 ), &exp2 ); /* DC component in FFT */ - sqr = L_shl( sqr, exp2 ); - fftBuffer[0] = Mpy_32_32( fftBuffer[0], sqr ); /* DC component in FFT */ + Word32 sqr = Sqrt32( L_shr( Mpy_32_32( scale, *ptr_level ), 1 ), &exp2 ); /* DC component in FFT Q31 - exp2*/ + sqr = L_shl( sqr, exp2 ); /*Q31*/ + fftBuffer[0] = Mpy_32_32( fftBuffer[0], sqr ); /* DC component in FFT Q31 - hFdCngCom->fftBuffer_exp*/ move32(); ptr_level++; } @@ -2731,22 +2731,22 @@ void generate_masking_noise_lb_dirac_fx( fftBuffer[0] = 0; move32(); set32_fx( fftBuffer + 2, 0, shl( sub( hFdCngCom->startBand, 1 ), 1 ) ); - ptr_r = fftBuffer + shl( hFdCngCom->startBand, 1 ); + ptr_r = fftBuffer + shl( hFdCngCom->startBand, 1 ); /*hFdCngCom->fftBuffer_exp*/ } - ptr_i = ptr_r + 1; + ptr_i = ptr_r + 1; /*hFdCngCom->fftBuffer_exp*/ FOR( ; ptr_level < cngNoiseLevel + sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ); ptr_level++ ) { rand_gauss_fx( ptr_r, seed, exp_out ); Word16 exp2 = hFdCngCom->cngNoiseLevelExp; - Word32 mpy2 = Sqrt32( Mpy_32_32( scale, *ptr_level ), &exp2 ); - ( *ptr_r ) = L_shl( Mpy_32_32( *ptr_r, mpy2 ), exp2 ); // hFdCngCom->fftBuffer_exp + exp2 - 31 + Word32 mpy2 = Sqrt32( Mpy_32_32( scale, *ptr_level ), &exp2 ); /*Q31 - exp2*/ + ( *ptr_r ) = L_shl( Mpy_32_32( *ptr_r, mpy2 ), exp2 ); /*Q31 - hFdCngCom->fftBuffer_exp*/ move32(); ptr_r += 2; /* Imaginary part in FFT bins */ rand_gauss_fx( ptr_i, seed, exp_out ); - ( *ptr_i ) = L_shl( Mpy_32_32( *ptr_i, mpy2 ), exp2 ); + ( *ptr_i ) = L_shl( Mpy_32_32( *ptr_i, mpy2 ), exp2 ); /*Q31 - hFdCngCom->fftBuffer_exp*/ move32(); ptr_i += 2; } @@ -2887,12 +2887,12 @@ void generate_masking_noise_dirac( void generate_masking_noise_dirac_ivas_fx( HANDLE_FD_CNG_COM hFdCngCom, /* i/o: FD_CNG structure containing all buffers and variables */ HANDLE_CLDFB_FILTER_BANK h_cldfb, /* i : filterbank state */ - Word32 *tdBuffer_fx, /* i/o: time-domain signal, if NULL no LB-CNA */ - Word32 *Cldfb_RealBuffer_fx, /* o : CLDFD real buffer */ - Word32 *Cldfb_ImagBuffer_fx, /* o : CLDFD imaginary buffer */ - const Word16 slot_index, /* i : CLDFB slot index */ - const Word16 cna_flag, /* i : CNA flag for LB and HB */ - const Word16 fd_cng_flag, /* i : FD-CNG flag for HB */ + Word32 *tdBuffer_fx, /* i/o: time-domain signal, if NULL no LB-CNA q_input*/ + Word32 *Cldfb_RealBuffer_fx, /* o : CLDFD real buffer q_cldfb*/ + Word32 *Cldfb_ImagBuffer_fx, /* o : CLDFD imaginary buffer q_cldfb*/ + const Word16 slot_index, /* i : CLDFB slot index Q0*/ + const Word16 cna_flag, /* i : CNA flag for LB and HB Q0*/ + const Word16 fd_cng_flag, /* i : FD-CNG flag for HB Q0*/ Word16 q_input, Word16 *q_cldfb ) { @@ -2948,12 +2948,12 @@ void generate_masking_noise_dirac_ivas_fx( IF( scale_fx != 0 ) { /* LF CLDFB*/ - cldfbAnalysis_ts_fx_fixed_q( &( tdBuffer_fx[L_mult0( hFdCngCom->numCoreBands, slot_index )] ), Cldfb_RealBuffer_fx, Cldfb_ImagBuffer_fx, hFdCngCom->numCoreBands, h_cldfb, q_cldfb ); + cldfbAnalysis_ts_fx_fixed_q( &( tdBuffer_fx[( hFdCngCom->numCoreBands * slot_index )] ), Cldfb_RealBuffer_fx, Cldfb_ImagBuffer_fx, hFdCngCom->numCoreBands, h_cldfb, q_cldfb ); } ELSE { /* LB ana CLDFB*/ - cldfbAnalysis_ts_fx_fixed_q( &( tdBuffer_fx[L_mult0( hFdCngCom->numCoreBands, slot_index )] ), Cldfb_RealBuffer_fx, Cldfb_ImagBuffer_fx, hFdCngCom->numCoreBands, h_cldfb, q_cldfb ); + cldfbAnalysis_ts_fx_fixed_q( &( tdBuffer_fx[( hFdCngCom->numCoreBands * slot_index )] ), Cldfb_RealBuffer_fx, Cldfb_ImagBuffer_fx, hFdCngCom->numCoreBands, h_cldfb, q_cldfb ); } } @@ -2967,11 +2967,11 @@ void generate_masking_noise_dirac_ivas_fx( q_scale = 27; move16(); q_shift = norm_l( scale_fx ); - scale_fx = L_shl( scale_fx, q_shift ); + scale_fx = L_shl( scale_fx, q_shift ); /*q_scale+q_shift*/ q_scale = add( q_scale, q_shift ); scale_fx = Mpy_32_32( scale_fx, Mpy_32_16_1( L_mult( h_cldfb->scale, h_cldfb->scale ), CLDFB_SCALING ) ); // Q = q_scale + 2 * Q8 - 34 q_scale = sub( add( q_scale, 2 * Q8 ), 31 ); - ptr_level_fx = hFdCngCom->cngNoiseLevel + sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ); + ptr_level_fx = hFdCngCom->cngNoiseLevel + sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ); /*Q31 - hFdCngCom->cngNoiseLevelExp*/ q_ptr_level = sub( 31, hFdCngCom->cngNoiseLevelExp ); FOR( i = hFdCngCom->numCoreBands; i < hFdCngCom->regularStopBand; i++ ) @@ -2979,12 +2979,12 @@ void generate_masking_noise_dirac_ivas_fx( Word32 num; Word16 exp, q_num; q_shift = norm_l( scale_fx ); - scale_fx = L_shl( scale_fx, q_shift ); + scale_fx = L_shl( scale_fx, q_shift ); /*q_scale+q_shift*/ q_scale = add( q_scale, q_shift ); - num = Mpy_32_32( scale_fx, *ptr_level_fx ); + num = Mpy_32_32( scale_fx, *ptr_level_fx ); /*q_num*/ q_num = sub( add( q_scale, q_ptr_level ), 31 ); exp = sub( 31, q_num ); - num = Sqrt32( num, &exp ); + num = Sqrt32( num, &exp ); /*Q31 - exp*/ /* Real part in CLDFB band */ rand_gauss_fx( &Cldfb_RealBuffer_fx[i], seed, *q_cldfb ); Cldfb_RealBuffer_fx[i] = L_shl( Mpy_32_32( Cldfb_RealBuffer_fx[i], num ), exp ); @@ -3049,8 +3049,8 @@ void FdCngDecodeMDCTStereoSID_fx( FOR( ch = 0; ch < CPE_CHANNELS; ch++ ) { sts[ch] = hCPE->hCoreCoder[ch]; - ms_ptr_fx[ch] = &logNoiseEst_fx[ch][0]; - lr_ptr_fx[ch] = &sts[ch]->hFdCngDec->hFdCngCom->sidNoiseEst[0]; + ms_ptr_fx[ch] = &logNoiseEst_fx[ch][0]; /*Q20*/ + lr_ptr_fx[ch] = &sts[ch]->hFdCngDec->hFdCngCom->sidNoiseEst[0]; /*Q18*/ } /* decode noise shapes and gains */ @@ -3060,7 +3060,7 @@ void FdCngDecodeMDCTStereoSID_fx( hFdCngCom = ( sts[ch]->hFdCngDec )->hFdCngCom; N = hFdCngCom->npart; move16(); - hFdCngCom->sid_frame_counter = add( hFdCngCom->sid_frame_counter, 1 ); + hFdCngCom->sid_frame_counter = add( hFdCngCom->sid_frame_counter, 1 ); /*Q0*/ move16(); IF( ch ) @@ -3077,7 +3077,7 @@ void FdCngDecodeMDCTStereoSID_fx( /* read bitstream */ FOR( i = 0; i < stages; i++ ) { - indices[i] = get_next_indice_fx( sts[ch], bits_37bits[i] ); + indices[i] = get_next_indice_fx( sts[ch], bits_37bits[i] ); /*Q0*/ move16(); } { @@ -3111,12 +3111,12 @@ void FdCngDecodeMDCTStereoSID_fx( hFdCngCom = sts[ch]->hFdCngDec->hFdCngCom; FOR( p = 0; p < N; p++ ) { - tmp32 = L_add( ms_ptr_fx[ch][p], gain_fx[ch] ); // Q20 - tmp32_arr[p] = BASOP_util_Pow2( Mpy_32_32( tmp32, LOG_10_BASE_2_BY_10_Q31 ), Q11, &exp_arr[p] ); + tmp32 = L_add( ms_ptr_fx[ch][p], gain_fx[ch] ); // Q20 + tmp32_arr[p] = BASOP_util_Pow2( Mpy_32_32( tmp32, LOG_10_BASE_2_BY_10_Q31 ), Q11, &exp_arr[p] ); /*Q31 - exp_arr[p]*/ move32(); if ( LT_16( exp_arr[max_exp_idx], exp_arr[p] ) ) { - max_exp_idx = p; + max_exp_idx = p; /*Q0*/ move16(); } } @@ -3124,7 +3124,7 @@ void FdCngDecodeMDCTStereoSID_fx( // Bringing in same exponent FOR( p = 0; p < N; p++ ) { - lr_ptr_fx[ch][p] = L_shl( tmp32_arr[p], sub( exp_arr[p], exp_arr[max_exp_idx] ) ); + lr_ptr_fx[ch][p] = L_shl( tmp32_arr[p], sub( exp_arr[p], exp_arr[max_exp_idx] ) ); /*Q31 - exp_arr[max_exp_idx]*/ move32(); } @@ -3149,12 +3149,12 @@ void FdCngDecodeMDCTStereoSID_fx( { IF( GT_16( exp_diff, 0 ) ) { - sts[0]->hFdCngDec->hFdCngCom->sidNoiseEst[p] = L_add( L_shr( sts[0]->hFdCngDec->hFdCngCom->sidNoiseEst[p], 1 ), L_shr( sts[1]->hFdCngDec->hFdCngCom->sidNoiseEst[p], add( exp_diff, 1 ) ) ); + sts[0]->hFdCngDec->hFdCngCom->sidNoiseEst[p] = L_add( L_shr( sts[0]->hFdCngDec->hFdCngCom->sidNoiseEst[p], 1 ), L_shr( sts[1]->hFdCngDec->hFdCngCom->sidNoiseEst[p], add( exp_diff, 1 ) ) ); /*Q18*/ move32(); } ELSE { - sts[0]->hFdCngDec->hFdCngCom->sidNoiseEst[p] = L_add( L_shr( sts[0]->hFdCngDec->hFdCngCom->sidNoiseEst[p], sub( 1, exp_diff ) ), L_shr( sts[1]->hFdCngDec->hFdCngCom->sidNoiseEst[p], 1 ) ); + sts[0]->hFdCngDec->hFdCngCom->sidNoiseEst[p] = L_add( L_shr( sts[0]->hFdCngDec->hFdCngCom->sidNoiseEst[p], sub( 1, exp_diff ) ), L_shr( sts[1]->hFdCngDec->hFdCngCom->sidNoiseEst[p], 1 ) ); /*Q18*/ move32(); } } @@ -3302,26 +3302,26 @@ void FdCngDecodeDiracMDCTStereoSID_fx( FOR( ch = 0; ch < CPE_CHANNELS; ch++ ) { sts[ch] = hCPE->hCoreCoder[ch]; - ms_ptr_fx[ch] = &logNoiseEst_fx[ch][0]; - lr_ptr_fx[ch] = &sts[ch]->hFdCngDec->hFdCngCom->sidNoiseEst[0]; - ( sts[ch]->hFdCngDec )->hFdCngCom->sid_frame_counter++; + ms_ptr_fx[ch] = &logNoiseEst_fx[ch][0]; /*Q20*/ + lr_ptr_fx[ch] = &sts[ch]->hFdCngDec->hFdCngCom->sidNoiseEst[0]; /*Q20*/ + ( sts[ch]->hFdCngDec )->hFdCngCom->sid_frame_counter++; /*Q18*/ } /* decode noise shapes and gains */ hFdCngCom = ( sts[0]->hFdCngDec )->hFdCngCom; - N = hFdCngCom->npart; + N = hFdCngCom->npart; /*Q0*/ move16(); /* read bitstream */ FOR( i = 0; i < FD_CNG_stages_37bits; i++ ) { - indices[i] = get_next_indice_fx( sts[0], bits_37bits[i] ); + indices[i] = get_next_indice_fx( sts[0], bits_37bits[i] ); /*Q0*/ move16(); } gain_fx[0] = Mpy_32_32( L_shl( L_sub( get_next_indice_fx( sts[0], 7 ), GAIN_Q_OFFSET_IVAS_FX ), Q20 ), TWO_BY_THREE_Q31 /* 2/3 in Q31 */ ); // Q20 move32(); - gain_fx[1] = gain_fx[0]; + gain_fx[1] = gain_fx[0]; /*Q20*/ move32(); /* MSVQ decoder */ @@ -3330,7 +3330,7 @@ void FdCngDecodeDiracMDCTStereoSID_fx( Scale_sig32( ms_ptr_fx[0], N, shift ); // Q20 - Copy32( ms_ptr_fx[0], ms_ptr_fx[1], N ); + Copy32( ms_ptr_fx[0], ms_ptr_fx[1], N ); /*Q20*/ FOR( ch = 0; ch < CPE_CHANNELS; ch++ ) { @@ -3340,12 +3340,12 @@ void FdCngDecodeDiracMDCTStereoSID_fx( FOR( p = 0; p < N; p++ ) { - tmp32 = L_add( ms_ptr_fx[ch][p], gain_fx[ch] ); // Q20 - tmp32_arr[p] = BASOP_util_Pow2( Mpy_32_32( tmp32, LOG_10_BASE_2_BY_10_Q31 ), Q11, &exp_arr[p] ); + tmp32 = L_add( ms_ptr_fx[ch][p], gain_fx[ch] ); // Q20 + tmp32_arr[p] = BASOP_util_Pow2( Mpy_32_32( tmp32, LOG_10_BASE_2_BY_10_Q31 ), Q11, &exp_arr[p] ); /*Q31 - exp_arr[p]*/ move32(); if ( LT_16( exp_arr[max_exp_idx], exp_arr[p] ) ) { - max_exp_idx = p; + max_exp_idx = p; /*Q0*/ move16(); } } @@ -3353,23 +3353,23 @@ void FdCngDecodeDiracMDCTStereoSID_fx( // Bringing in same exponent FOR( p = 0; p < N; p++ ) { - lr_ptr_fx[ch][p] = L_shl( tmp32_arr[p], sub( exp_arr[p], exp_arr[max_exp_idx] ) ); + lr_ptr_fx[ch][p] = L_shl( tmp32_arr[p], sub( exp_arr[p], exp_arr[max_exp_idx] ) ); /*Q20*/ move32(); } - hFdCngCom->sidNoiseEstExp = exp_arr[max_exp_idx]; + hFdCngCom->sidNoiseEstExp = exp_arr[max_exp_idx]; /*Q0*/ move16(); /* NB last band energy compensation */ test(); IF( hFdCngCom->CngBandwidth == NB ) { - lr_ptr_fx[ch][sub( N, 1 )] = Mpy_32_32( lr_ptr_fx[ch][sub( N, 1 )], NB_LAST_BAND_SCALE_Q31 ); + lr_ptr_fx[ch][( N - 1 )] = Mpy_32_32( lr_ptr_fx[ch][( N - 1 )], NB_LAST_BAND_SCALE_Q31 ); /*Q20*/ move32(); } ELSE IF( EQ_16( hFdCngCom->CngBandwidth, SWB ) && LE_32( hFdCngCom->CngBitrate, ACELP_13k20 ) ) { - lr_ptr_fx[ch][sub( N, 1 )] = Mpy_32_32( lr_ptr_fx[ch][sub( N, 1 )], SWB_13k2_LAST_BAND_SCALE_Q31 ); + lr_ptr_fx[ch][( N - 1 )] = Mpy_32_32( lr_ptr_fx[ch][( N - 1 )], SWB_13k2_LAST_BAND_SCALE_Q31 ); /*Q20*/ move32(); } @@ -3393,12 +3393,12 @@ void FdCngDecodeDiracMDCTStereoSID_fx( { IF( exp_diff > 0 ) { - sts[0]->hFdCngDec->hFdCngCom->sidNoiseEst[p] = L_add( L_shr( sts[0]->hFdCngDec->hFdCngCom->sidNoiseEst[p], 1 ), L_shr( sts[1]->hFdCngDec->hFdCngCom->sidNoiseEst[p], add( exp_diff, 1 ) ) ); + sts[0]->hFdCngDec->hFdCngCom->sidNoiseEst[p] = L_add( L_shr( sts[0]->hFdCngDec->hFdCngCom->sidNoiseEst[p], 1 ), L_shr( sts[1]->hFdCngDec->hFdCngCom->sidNoiseEst[p], add( exp_diff, 1 ) ) ); /*Q18*/ move32(); } ELSE { - sts[0]->hFdCngDec->hFdCngCom->sidNoiseEst[p] = L_add( L_shr( sts[0]->hFdCngDec->hFdCngCom->sidNoiseEst[p], sub( 1, exp_diff ) ), L_shr( sts[1]->hFdCngDec->hFdCngCom->sidNoiseEst[p], 1 ) ); + sts[0]->hFdCngDec->hFdCngCom->sidNoiseEst[p] = L_add( L_shr( sts[0]->hFdCngDec->hFdCngCom->sidNoiseEst[p], sub( 1, exp_diff ) ), L_shr( sts[1]->hFdCngDec->hFdCngCom->sidNoiseEst[p], 1 ) ); /*Q18*/ move32(); } } diff --git a/lib_dec/fd_cng_dec_fx.c b/lib_dec/fd_cng_dec_fx.c index ae5f0c2b1..984c1495e 100644 --- a/lib_dec/fd_cng_dec_fx.c +++ b/lib_dec/fd_cng_dec_fx.c @@ -73,7 +73,7 @@ ivas_error createFdCngDec_fx( HANDLE_FD_CNG_DEC *hFdCngDec ) #ifdef IVAS_FLOAT_FIXED void initFdCngDec_ivas_fx( DEC_CORE_HANDLE st, /* i/o: decoder state structure */ - Word16 scale ) + Word16 scale /*Q15*/ ) { /* Initialize common */ HANDLE_FD_CNG_DEC hFdCngDec; @@ -176,14 +176,14 @@ void initFdCngDec_ivas_fx( move16(); hFdCngDec->cna_rescale_fact_fx = 0; move16(); - hFdCngDec->cna_seed = 5687; + hFdCngDec->cna_seed = 5687; /*Q0*/ move16(); set16_fx( hFdCngDec->cna_cm_fx, 0, STEREO_DFT_BAND_MAX ); set16_fx( hFdCngDec->cna_g_state_fx, 0, STEREO_DFT_BAND_MAX ); st->CNG_mode = -1; move16(); - Copy( st->lsp_old_fx, st->lspCNG_fx, M ); + Copy( st->lsp_old_fx, st->lspCNG_fx, M ); /*Q15*/ #ifdef MSAN_FIX hFdCngDec->hFdCngCom->sid_frame_counter = 0; #endif @@ -192,7 +192,7 @@ void initFdCngDec_ivas_fx( void initFdCngDec_fx( DEC_CORE_HANDLE st, /* i/o: decoder state structure */ - Word16 scale ) + Word16 scale /*Q15*/ ) { /* Initialize common */ HANDLE_FD_CNG_DEC hFdCngDec; @@ -322,17 +322,17 @@ void initFdCngDec_fx( */ void configureFdCngDec_fx( HANDLE_FD_CNG_DEC hFdCngDec, /* i/o: Contains the variables related to the CLDFB-based CNG process */ - Word16 bwidth, - Word32 total_brate, - Word16 L_frame, - const Word16 Last_L_frame, - const Word16 element_mode ) + Word16 bwidth, /*Q0*/ + Word32 total_brate, /*Q0*/ + Word16 L_frame, /*Q0*/ + const Word16 Last_L_frame, /*Q0*/ + const Word16 element_mode /*Q0*/ ) { Word16 j, stopBandFR; HANDLE_FD_CNG_COM hsCom = hFdCngDec->hFdCngCom; - hsCom->CngBandwidth = bwidth; + hsCom->CngBandwidth = bwidth; /*Q0*/ move16(); if ( EQ_16( hsCom->CngBandwidth, FB ) ) { @@ -342,7 +342,7 @@ void configureFdCngDec_fx( test(); IF( total_brate != FRAME_NO_DATA && NE_32( total_brate, SID_2k40 ) ) { - hsCom->CngBitrate = total_brate; + hsCom->CngBitrate = total_brate; /*Q0*/ move32(); } ELSE IF( EQ_32( hsCom->CngBitrate, -1 ) ) @@ -454,16 +454,16 @@ void configureFdCngDec_fx( } } } - hsCom->fftlen = hsCom->FdCngSetup.fftlen; + hsCom->fftlen = hsCom->FdCngSetup.fftlen; /*Q0*/ move16(); - hsCom->stopFFTbin = hsCom->FdCngSetup.stopFFTbin; + hsCom->stopFFTbin = hsCom->FdCngSetup.stopFFTbin; /*Q0*/ move16(); /* Configure the SID quantizer and the Confort Noise Generator */ hsCom->startBand = 2; move16(); - hsCom->stopBand = add( hsCom->FdCngSetup.sidPartitions[sub( hsCom->FdCngSetup.numPartitions, 1 )], 1 ); + hsCom->stopBand = add( hsCom->FdCngSetup.sidPartitions[( hsCom->FdCngSetup.numPartitions - 1 )], 1 ); /*Q0*/ move16(); initPartitions( hsCom->FdCngSetup.sidPartitions, hsCom->FdCngSetup.numPartitions, hsCom->startBand, hsCom->stopBand, hsCom->part, &hsCom->npart, hsCom->midband, hsCom->psize, hsCom->psize_norm, &hsCom->psize_norm_exp, hsCom->psize_inv, 0 ); @@ -485,9 +485,9 @@ void configureFdCngDec_fx( move16(); FOR( j = 0; j < hsCom->nCLDFBpart; j++ ) { - hsCom->CLDFBpart[j] = sub( hsCom->part[add( j, hsCom->nFFTpart )], sub( hsCom->stopFFTbin, hsCom->startBand ) ); + hsCom->CLDFBpart[j] = sub( hsCom->part[( j + hsCom->nFFTpart )], sub( hsCom->stopFFTbin, hsCom->startBand ) ); /*Q0*/ move16(); - hsCom->CLDFBpsize_inv[j] = hsCom->psize_inv[add( j, hsCom->nFFTpart )]; + hsCom->CLDFBpsize_inv[j] = hsCom->psize_inv[( j + hsCom->nFFTpart )]; /*Q15*/ move16(); } @@ -495,14 +495,14 @@ void configureFdCngDec_fx( move16(); if ( GT_16( stopBandFR, hsCom->stopFFTbin ) ) { - stopBandFR = hsCom->stopFFTbin; + stopBandFR = hsCom->stopFFTbin; /*Q0*/ move16(); } initPartitions( hsCom->FdCngSetup.shapingPartitions, hsCom->FdCngSetup.numShapingPartitions, hsCom->startBand, hsCom->stopFFTbin, hFdCngDec->part_shaping, &hFdCngDec->npart_shaping, hFdCngDec->midband_shaping, hFdCngDec->psize_shaping, hFdCngDec->psize_shaping_norm, &hFdCngDec->psize_shaping_norm_exp, hFdCngDec->psize_inv_shaping, stopBandFR ); - hFdCngDec->nFFTpart_shaping = hFdCngDec->npart_shaping; + hFdCngDec->nFFTpart_shaping = hFdCngDec->npart_shaping; /*Q0*/ move16(); SWITCH( hsCom->fftlen ) @@ -579,17 +579,17 @@ void deleteFdCngDec_fx( HANDLE_FD_CNG_DEC *hFdCngDec ) error */ Word16 ApplyFdCng_fx( - Word16 *timeDomainInput, /* i : pointer to time domain input */ + Word16 *timeDomainInput, /* i : pointer to time domain input Q*/ Word16 Q, #ifdef IVAS_CODE_CNG_FIX185_PLC_FADEOUT Word16 *powerSpectrum, #endif - Word32 **cldfbBufferReal, /* i/o: real part of the CLDFB buffer */ - Word32 **cldfbBufferImag, /* i/o: imaginary part of the CLDFB buffer */ + Word32 **cldfbBufferReal, /* i/o: real part of the CLDFB buffer cldfbBufferScale*/ + Word32 **cldfbBufferImag, /* i/o: imaginary part of the CLDFB buffer cldfbBufferScale*/ Word16 *cldfbBufferScale, /* o : pointer to the scalefactor for real and imaginary part of the CLDFB buffer */ Decoder_State *st, - const Word16 concealWholeFrame, /* i : binary flag indicating frame loss */ - Word16 is_music ) + const Word16 concealWholeFrame, /* i : binary flag indicating frame loss Q0*/ + Word16 is_music /*Q0*/ ) { Word16 j, k, nBins; Word16 s, s1, s2, num, denom; @@ -636,7 +636,7 @@ Word16 ApplyFdCng_fx( test(); move16(); } - cngNoiseLevel = hFdCngCom->cngNoiseLevel; + cngNoiseLevel = hFdCngCom->cngNoiseLevel; /*Q31 - hFdCngCom->cngNoiseLevelExp*/ move32(); cngNoiseLevel_exp = &hFdCngCom->cngNoiseLevelExp; move16(); @@ -743,21 +743,21 @@ Word16 ApplyFdCng_fx( IF( hFdCngDec->partNoiseShape[k] != 0 ) { s1 = norm_l( hFdCngCom->sidNoiseEst[k] ); - L_tmp = L_shl( hFdCngCom->sidNoiseEst[k], s1 ); + L_tmp = L_shl( hFdCngCom->sidNoiseEst[k], s1 ); /*Q31 - hFdCngCom->sidNoiseEstExp + s1*/ L_tmp_exp = sub( hFdCngCom->sidNoiseEstExp, s1 ); L_tmp = BASOP_Util_Add_Mant32Exp( L_tmp, L_tmp_exp, DELTA_MANTISSA_W32, DELTA_EXPONENT, &L_tmp_exp ); L_tmp = L_shr( L_tmp, 1 ); s = add( L_tmp_exp, 1 ); - num = extract_h( L_tmp ); + num = extract_h( L_tmp ); /*Q15 - L_tmp_exp*/ s1 = norm_l( hFdCngDec->partNoiseShape[k] ); - L_tmp = L_shl( hFdCngDec->partNoiseShape[k], s1 ); + L_tmp = L_shl( hFdCngDec->partNoiseShape[k], s1 ); /*Q31 - hFdCngDec->partNoiseShape_exp + s1*/ L_tmp_exp = sub( hFdCngDec->partNoiseShape_exp, s1 ); L_tmp = BASOP_Util_Add_Mant32Exp( L_tmp, L_tmp_exp, DELTA_MANTISSA_W32, DELTA_EXPONENT, &L_tmp_exp ); s = sub( s, L_tmp_exp ); - denom = extract_h( L_tmp ); + denom = extract_h( L_tmp ); /*Q15 - L_tmp_exp*/ - facTab[k] = div_s( num, denom ); + facTab[k] = div_s( num, denom ); /*Q15 - s*/ move16(); facTabExp[k] = s; move16(); @@ -777,7 +777,7 @@ Word16 ApplyFdCng_fx( s = s_max( s_min( s, WORD32_BITS - 1 ), -( WORD32_BITS - 1 ) ); FOR( ; j <= hFdCngCom->part[k]; j++ ) { - cngNoiseLevel[j] = L_shl( Mpy_32_16_1( hFdCngDec->bandNoiseShape[j], facTab[k] ), s ); + cngNoiseLevel[j] = L_shl( Mpy_32_16_1( hFdCngDec->bandNoiseShape[j], facTab[k] ), s ); /*Q31 - hFdCngDec->bandNoiseShape_exp*/ move32(); } } @@ -790,7 +790,7 @@ Word16 ApplyFdCng_fx( { FOR( ; j <= hFdCngCom->part[k]; j++ ) { - cngNoiseLevel[j] = L_shl( cngNoiseLevel[j], s ); + cngNoiseLevel[j] = L_shl( cngNoiseLevel[j], s ); /*Q31 - hFdCngDec->bandNoiseShape_exp + s*/ move32(); } } @@ -807,7 +807,7 @@ Word16 ApplyFdCng_fx( test(); IF( !( EQ_16( st->element_mode, IVAS_CPE_TD ) ) || ( EQ_16( st->element_mode, IVAS_CPE_TD ) && !hFdCngDec->flag_dtx_mode && !st->VAD ) ) { - Copy32( hFdCngDec->bandNoiseShape, cngNoiseLevel, nBins ); + Copy32( hFdCngDec->bandNoiseShape, cngNoiseLevel, nBins ); /*Q31 - hFdCngDec->bandNoiseShape_exp*/ *cngNoiseLevel_exp = hFdCngDec->bandNoiseShape_exp; move16(); } @@ -832,7 +832,7 @@ Word16 ApplyFdCng_fx( Carry = 0; move16(); #ifdef BASOP_NOGLOB - L_tmp = L_add_co( L_tmp, *( cngNoiseLevel + j ), &Carry, &Overflow ); + L_tmp = L_add_co( L_tmp, *( cngNoiseLevel + j ), &Carry, &Overflow ); /*Q31*/ #else L_tmp = L_add_c( L_tmp, *( cngNoiseLevel + j ) ); #endif @@ -841,28 +841,28 @@ Word16 ApplyFdCng_fx( IF( *( cngNoiseLevel + j ) < 0 ) { - L_c = L_msuNs( L_c, 0, 0 ); + L_c = L_msuNs( L_c, 0, 0 ); /*Q-1*/ } IF( *( cngNoiseLevel + j ) >= 0 ) { #ifdef BASOP_NOGLOB - L_c = L_macNs_co( L_c, 0, 0, &Carry, &Overflow ); + L_c = L_macNs_co( L_c, 0, 0, &Carry, &Overflow ); /*Q-1*/ #else L_c = L_macNs( L_c, 0, 0 ); #endif } } - L_tmp = norm_llQ31( L_c, L_tmp, &L_tmp_exp ); + L_tmp = norm_llQ31( L_c, L_tmp, &L_tmp_exp ); /*Q31 - L_tmp_exp*/ L_tmp_exp = sub( add( L_tmp_exp, *cngNoiseLevel_exp ), 1 ); - L_tmp = Mpy_32_16_1( L_tmp, hFdCngCom->fftlen ); /*Q16*/ + L_tmp = Mpy_32_16_1( L_tmp, hFdCngCom->fftlen ); /*Q16 - L_tmp_exp*/ L_tmp = Mpy_32_16_1( L_tmp, T_DIV_L_Frame[L_shl( L_mac( -28000, st->L_frame, 95 ), 1 - 15 )] ); /*Q16,exp -7*/ L_tmp_exp = add( L_tmp_exp, -7 ); /*->Q16, L_tmp_exp */ L_tmp_exp = add( L_tmp_exp, 31 - 16 ); /*->Q31, L_tmp_exp*/ #ifdef BASOP_NOGLOB - st->cngTDLevel = round_fx_sat( Sqrt32( L_tmp, &L_tmp_exp ) ); + st->cngTDLevel = round_fx_sat( Sqrt32( L_tmp, &L_tmp_exp ) ); /*Q15 - L_tmp_exp*/ #else st->cngTDLevel = round_fx( Sqrt32( L_tmp, &L_tmp_exp ) ); #endif @@ -901,7 +901,7 @@ Word16 ApplyFdCng_fx( #ifndef IVAS_CODE_CNG_FIX185_PLC_FADEOUT lpc_from_spectrum( hFdCngCom, hFdCngCom->startBand, hFdCngCom->stopFFTbin, 0 ); E_LPC_a_lsp_conversion( hFdCngCom->A_cng, lsp_cng, st->lspold_cng, M ); - Copy( lsp_cng, st->lspold_cng, M ); + Copy( lsp_cng, st->lspold_cng, M ); /*Q15*/ lsp2lsf_fx( lsp_cng, st->lsf_cng, M, st->sr_core ); #else @@ -982,7 +982,7 @@ Word16 ApplyFdCng_fx( hFdCngDec->bandNoiseShape_exp = hFdCngDec->msNoiseEst_exp; move16(); /* This sets the new CNG levels until a SID update overwrites it */ - Copy32( hFdCngDec->bandNoiseShape, cngNoiseLevel, sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ) ); /* This sets the new CNG levels until a SID update overwrites it */ + Copy32( hFdCngDec->bandNoiseShape, cngNoiseLevel, sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ) ); /* This sets the new CNG levels until a SID update overwrites it Q31 - hFdCngDec->bandNoiseShape_exp*/ *cngNoiseLevel_exp = hFdCngDec->bandNoiseShape_exp; move16(); #ifdef IVAS_CODE_CNG_FIX185_PLC_FADEOUT @@ -998,17 +998,17 @@ Word16 ApplyFdCng_fx( Carry = 0; move16(); #ifdef BASOP_NOGLOB /* Critical Carry/Overflow */ - L_tmp = L_add_co( L_tmp, *( cngNoiseLevel + j ), &Carry, &Overflow ); + L_tmp = L_add_co( L_tmp, *( cngNoiseLevel + j ), &Carry, &Overflow ); /*Q31*/ Overflow = 0; move16(); IF( *( cngNoiseLevel + j ) < 0 ) { - L_c = L_msuNs_co( L_c, 0, 0, &Carry, &Overflow ); + L_c = L_msuNs_co( L_c, 0, 0, &Carry, &Overflow ); /*Q-1*/ } IF( *( cngNoiseLevel + j ) >= 0 ) { - L_c = L_macNs_co( L_c, 0, 0, &Carry, &Overflow ); + L_c = L_macNs_co( L_c, 0, 0, &Carry, &Overflow ); /*Q-1*/ } #else L_tmp = L_add_c( L_tmp, *( cngNoiseLevel + j ) ); @@ -1024,17 +1024,17 @@ Word16 ApplyFdCng_fx( } #endif } - L_tmp = norm_llQ31( L_c, L_tmp, &L_tmp_exp ); + L_tmp = norm_llQ31( L_c, L_tmp, &L_tmp_exp ); /*Q31 - L_tmp_exp*/ L_tmp_exp = sub( add( L_tmp_exp, *cngNoiseLevel_exp ), 1 ); - L_tmp = Mpy_32_16_1( L_tmp, hFdCngCom->fftlen ); /*Q16*/ + L_tmp = Mpy_32_16_1( L_tmp, hFdCngCom->fftlen ); /*Q16 - L_tmp_exp*/ L_tmp = Mpy_32_16_1( L_tmp, T_DIV_L_Frame[L_shl( L_mac( -28000, st->L_frame, 95 ), 1 - 15 )] ); /*Q16,exp -7*/ L_tmp_exp = add( L_tmp_exp, -7 ); /*->Q16, L_tmp_exp */ L_tmp_exp = add( L_tmp_exp, 31 - 16 ); /*->Q31, L_tmp_exp*/ #ifdef BASOP_NOGLOB /* Critical Carry/Overflow */ - st->cngTDLevel = round_fx_o( Sqrt32( L_tmp, &L_tmp_exp ), &Overflow ); + st->cngTDLevel = round_fx_o( Sqrt32( L_tmp, &L_tmp_exp ), &Overflow ); /*Q15 - L_tmp_exp*/ move16(); #else st->cngTDLevel = round_fx( Sqrt32( L_tmp, &L_tmp_exp ) ); @@ -1116,21 +1116,21 @@ Word16 ApplyFdCng_fx( IF( hFdCngDec->partNoiseShape[k] != 0 ) { s1 = norm_l( hFdCngCom->sidNoiseEst[k] ); - L_tmp = L_shl( hFdCngCom->sidNoiseEst[k], s1 ); + L_tmp = L_shl( hFdCngCom->sidNoiseEst[k], s1 ); /*Q31 - hFdCngCom->sidNoiseEstExp + s1*/ L_tmp_exp = sub( hFdCngCom->sidNoiseEstExp, s1 ); L_tmp = BASOP_Util_Add_Mant32Exp( hFdCngCom->sidNoiseEst[k], hFdCngCom->sidNoiseEstExp, DELTA_MANTISSA_W32, DELTA_EXPONENT, &L_tmp_exp ); L_tmp = L_shr( L_tmp, 1 ); s = add( L_tmp_exp, 1 ); - num = extract_h( L_tmp ); + num = extract_h( L_tmp ); /*Q15 - L_tmp_exp*/ s1 = norm_l( hFdCngDec->partNoiseShape[k] ); - L_tmp = L_shl( hFdCngDec->partNoiseShape[k], s1 ); + L_tmp = L_shl( hFdCngDec->partNoiseShape[k], s1 ); /*Q31 - hFdCngDec->partNoiseShape_exp + s1*/ L_tmp_exp = sub( hFdCngDec->partNoiseShape_exp, s1 ); L_tmp = BASOP_Util_Add_Mant32Exp( L_tmp, L_tmp_exp, DELTA_MANTISSA_W32, DELTA_EXPONENT, &L_tmp_exp ); s = sub( s, L_tmp_exp ); - denom = extract_h( L_tmp ); + denom = extract_h( L_tmp ); /*Q15 - L_tmp_exp*/ - facTab[k] = div_s( num, denom ); + facTab[k] = div_s( num, denom ); /*Q15 - s*/ move16(); facTabExp[k] = s; move16(); @@ -1150,7 +1150,7 @@ Word16 ApplyFdCng_fx( s = s_max( s_min( s, WORD32_BITS - 1 ), -( WORD32_BITS - 1 ) ); FOR( ; j <= hFdCngCom->part[k]; j++ ) { - cngNoiseLevel[j] = L_shl( Mpy_32_16_1( hFdCngDec->bandNoiseShape[j], facTab[k] ), s ); + cngNoiseLevel[j] = L_shl( Mpy_32_16_1( hFdCngDec->bandNoiseShape[j], facTab[k] ), s ); /*Q31 - hFdCngDec->bandNoiseShape_exp*/ move32(); } } @@ -1160,7 +1160,7 @@ Word16 ApplyFdCng_fx( { FOR( ; j <= hFdCngCom->part[k]; j++ ) { - cngNoiseLevel[j] = L_shl( cngNoiseLevel[j], s ); + cngNoiseLevel[j] = L_shl( cngNoiseLevel[j], s ); /*Q31 - hFdCngDec->bandNoiseShape_exp + s*/ move32(); } } @@ -1204,16 +1204,16 @@ Word16 ApplyFdCng_fx( #ifdef IVAS_FLOAT_FIXED Word16 ApplyFdCng_ivas_fx( - Word16 *timeDomainInput, /* i : pointer to time domain input */ + Word16 *timeDomainInput, /* i : pointer to time domain input Q*/ Word16 Q, - Word32 *powerSpectrum, + Word32 *powerSpectrum, /*Q_power_spectrum*/ Word16 Q_power_spectrum, - Word32 **cldfbBufferReal, /* i/o: real part of the CLDFB buffer */ - Word32 **cldfbBufferImag, /* i/o: imaginary part of the CLDFB buffer */ + Word32 **cldfbBufferReal, /* i/o: real part of the CLDFB buffer cldfbBufferScale*/ + Word32 **cldfbBufferImag, /* i/o: imaginary part of the CLDFB buffer cldfbBufferScale*/ Word16 *cldfbBufferScale, /* o : pointer to the scalefactor for real and imaginary part of the CLDFB buffer */ Decoder_State *st, - const Word16 concealWholeFrame, /* i : binary flag indicating frame loss */ - Word16 is_music ) + const Word16 concealWholeFrame, /* i : binary flag indicating frame loss Q0*/ + Word16 is_music /*Q0*/ ) { Word16 j, k, nBins; Word16 s, s1, s2, num, denom; @@ -1239,7 +1239,7 @@ Word16 ApplyFdCng_ivas_fx( hFdCngDec = st->hFdCngDec; hFdCngCom = hFdCngDec->hFdCngCom; - Word32 *sidNoiseEst = hFdCngCom->sidNoiseEst; + Word32 *sidNoiseEst = hFdCngCom->sidNoiseEst; /*Q31 - hFdCngCom->sidNoiseEstExp*/ /* limit L_frame and core fs values for MDCT-Stereo modes which can have higher core sampling than 16kHz, but use a downsampled buffer */ L_frame = s_min( st->L_frame, L_FRAME16k ); @@ -1336,7 +1336,7 @@ Word16 ApplyFdCng_ivas_fx( j = 0; move16(); // s2 = -( WORD32_BITS - 1 ); - s2 = negate( sub( WORD32_BITS, 1 ) ); + s2 = -( WORD32_BITS - 1 ); move16(); FOR( k = 0; k < hFdCngCom->nFFTpart; k++ ) { @@ -1349,21 +1349,21 @@ Word16 ApplyFdCng_ivas_fx( IF( hFdCngDec->partNoiseShape[k] != 0 ) { s1 = norm_l( hFdCngCom->sidNoiseEst[k] ); - L_tmp = L_shl( hFdCngCom->sidNoiseEst[k], s1 ); + L_tmp = L_shl( hFdCngCom->sidNoiseEst[k], s1 ); /*Q31 - hFdCngCom->sidNoiseEstExp + s1*/ L_tmp_exp = sub( hFdCngCom->sidNoiseEstExp, s1 ); L_tmp = BASOP_Util_Add_Mant32Exp( L_tmp, L_tmp_exp, DELTA_MANTISSA_W32, DELTA_EXPONENT, &L_tmp_exp ); L_tmp = L_shr( L_tmp, 1 ); s = add( L_tmp_exp, 1 ); - num = extract_h( L_tmp ); + num = extract_h( L_tmp ); /*Q15 - L_tmp_exp*/ s1 = norm_l( hFdCngDec->partNoiseShape[k] ); - L_tmp = L_shl( hFdCngDec->partNoiseShape[k], s1 ); + L_tmp = L_shl( hFdCngDec->partNoiseShape[k], s1 ); /*Q31 - hFdCngDec->partNoiseShape_exp + s1*/ L_tmp_exp = sub( hFdCngDec->partNoiseShape_exp, s1 ); L_tmp = BASOP_Util_Add_Mant32Exp( L_tmp, L_tmp_exp, DELTA_MANTISSA_W32, DELTA_EXPONENT, &L_tmp_exp ); s = sub( s, L_tmp_exp ); - denom = extract_h( L_tmp ); + denom = extract_h( L_tmp ); /*Q15 - L_tmp_exp*/ - facTab[k] = div_s( num, denom ); + facTab[k] = div_s( num, denom ); /*Q15 - s*/ move16(); facTabExp[k] = s; move16(); @@ -1371,7 +1371,7 @@ Word16 ApplyFdCng_ivas_fx( /* Set unique exponent, if mantissa is equal to zero */ IF( EQ_16( facTab[k], 0 ) ) { - facTabExp[k] = negate( sub( WORD32_BITS, 1 ) ); + facTabExp[k] = -( ( WORD32_BITS - 1 ) ); move16(); } s2 = s_max( s2, facTabExp[k] ); @@ -1380,10 +1380,10 @@ Word16 ApplyFdCng_ivas_fx( FOR( k = 0; k < hFdCngCom->nFFTpart; k++ ) { s = sub( facTabExp[k], s2 ); - s = s_max( s_min( s, sub( WORD32_BITS, 1 ) ), negate( sub( WORD32_BITS, 1 ) ) ); + s = s_max( s_min( s, ( WORD32_BITS - 1 ) ), -( ( WORD32_BITS - 1 ) ) ); FOR( ; j <= hFdCngCom->part[k]; j++ ) { - cngNoiseLevel[j] = L_shl( Mpy_32_16_1( hFdCngDec->bandNoiseShape[j], facTab[k] ), s ); + cngNoiseLevel[j] = L_shl( Mpy_32_16_1( hFdCngDec->bandNoiseShape[j], facTab[k] ), s ); /*Q31 - hFdCngDec->bandNoiseShape_exp*/ move32(); } } @@ -1399,7 +1399,7 @@ Word16 ApplyFdCng_ivas_fx( Word16 q_norm = L_norm_arr( &cngNoiseLevel[j], sub( FFTCLDFBLEN, j ) ); IF( GT_16( s, q_norm ) ) { - scale_sig32( cngNoiseLevel, j, sub( q_norm, s ) ); + scale_sig32( cngNoiseLevel, j, sub( q_norm, s ) ); /*q_norm*/ e_shift = sub( s, q_norm ); } } @@ -1407,7 +1407,7 @@ Word16 ApplyFdCng_ivas_fx( { FOR( ; j <= hFdCngCom->part[k]; j++ ) { - cngNoiseLevel[j] = L_shl( cngNoiseLevel[j], sub( s, e_shift ) ); + cngNoiseLevel[j] = L_shl( cngNoiseLevel[j], sub( s, e_shift ) ); /*Q: s*/ move32(); } } @@ -1424,7 +1424,7 @@ Word16 ApplyFdCng_ivas_fx( test(); IF( !( EQ_16( st->element_mode, IVAS_CPE_TD ) ) || ( EQ_16( st->element_mode, IVAS_CPE_TD ) && !hFdCngDec->flag_dtx_mode && !st->VAD ) ) { - Copy32( hFdCngDec->bandNoiseShape, cngNoiseLevel, nBins ); + Copy32( hFdCngDec->bandNoiseShape, cngNoiseLevel, nBins ); /*Q31 - hFdCngDec->bandNoiseShape_exp*/ *cngNoiseLevel_exp = hFdCngDec->bandNoiseShape_exp; move16(); } @@ -1442,7 +1442,7 @@ Word16 ApplyFdCng_ivas_fx( Carry = 0; move16(); #ifdef BASOP_NOGLOB - L_tmp = L_add_co( L_tmp, *( cngNoiseLevel + j ), &Carry, &Overflow ); + L_tmp = L_add_co( L_tmp, *( cngNoiseLevel + j ), &Carry, &Overflow ); /*Q31*/ #else L_tmp = L_add_c( L_tmp, *( cngNoiseLevel + j ) ); #endif @@ -1451,28 +1451,28 @@ Word16 ApplyFdCng_ivas_fx( IF( *( cngNoiseLevel + j ) < 0 ) { - L_c = L_msuNs( L_c, 0, 0 ); + L_c = L_msuNs( L_c, 0, 0 ); /*Q-1*/ } IF( *( cngNoiseLevel + j ) >= 0 ) { #ifdef BASOP_NOGLOB - L_c = L_macNs_co( L_c, 0, 0, &Carry, &Overflow ); + L_c = L_macNs_co( L_c, 0, 0, &Carry, &Overflow ); /*Q-1*/ #else L_c = L_macNs( L_c, 0, 0 ); #endif } } - L_tmp = norm_llQ31( L_c, L_tmp, &L_tmp_exp ); + L_tmp = norm_llQ31( L_c, L_tmp, &L_tmp_exp ); /*Q31 - L_tmp_exp*/ L_tmp_exp = sub( add( L_tmp_exp, *cngNoiseLevel_exp ), 1 ); - L_tmp = Mpy_32_16_1( L_tmp, 1 ); + L_tmp = Mpy_32_16_1( L_tmp, 1 ); /*Q16 - L_tmp_exp*/ L_tmp = Mpy_32_16_1( L_tmp, shr( T_DIV_L_Frame[L_shl( L_mac( -28000, NORM_MDCT_FACTOR, 95 ), 1 - 15 )], 1 ) ); /*Q16,exp -7*/ L_tmp_exp = add( L_tmp_exp, -7 ); /*->Q16, L_tmp_exp */ L_tmp_exp = add( L_tmp_exp, 31 - 16 ); /*->Q31, L_tmp_exp*/ #ifdef BASOP_NOGLOB - st->hTcxDec->conCngLevelBackgroundTrace = round_fx_sat( Sqrt32( L_tmp, &L_tmp_exp ) ); + st->hTcxDec->conCngLevelBackgroundTrace = round_fx_sat( Sqrt32( L_tmp, &L_tmp_exp ) ); /*Q15 - L_tmp_exp*/ #else st->hTcxDec->conCngLevelBackgroundTrace = round_fx( Sqrt32( L_tmp, &L_tmp_exp ) ); #endif @@ -1493,7 +1493,7 @@ Word16 ApplyFdCng_ivas_fx( Carry = 0; move16(); #ifdef BASOP_NOGLOB - L_tmp = L_add_co( L_tmp, *( cngNoiseLevel + j ), &Carry, &Overflow ); + L_tmp = L_add_co( L_tmp, *( cngNoiseLevel + j ), &Carry, &Overflow ); /*Q31 - L_tmp_exp*/ #else L_tmp = L_add_c( L_tmp, *( cngNoiseLevel + j ) ); #endif @@ -1502,28 +1502,28 @@ Word16 ApplyFdCng_ivas_fx( IF( *( cngNoiseLevel + j ) < 0 ) { - L_c = L_msuNs( L_c, 0, 0 ); + L_c = L_msuNs( L_c, 0, 0 ); /*Q-1*/ } IF( *( cngNoiseLevel + j ) >= 0 ) { #ifdef BASOP_NOGLOB - L_c = L_macNs_co( L_c, 0, 0, &Carry, &Overflow ); + L_c = L_macNs_co( L_c, 0, 0, &Carry, &Overflow ); /*Q-1*/ #else L_c = L_macNs( L_c, 0, 0 ); #endif } } - L_tmp = norm_llQ31( L_c, L_tmp, &L_tmp_exp ); + L_tmp = norm_llQ31( L_c, L_tmp, &L_tmp_exp ); /*Q31 - L_tmp_exp*/ L_tmp_exp = sub( add( L_tmp_exp, *cngNoiseLevel_exp ), 1 ); - L_tmp = Mpy_32_16_1( L_tmp, hFdCngCom->fftlen ); /*Q16*/ + L_tmp = Mpy_32_16_1( L_tmp, hFdCngCom->fftlen ); /*Q16 - L_tmp_exp*/ L_tmp = Mpy_32_16_1( L_tmp, T_DIV_L_Frame[L_shl( L_mac( -28000, st->L_frame, 95 ), 1 - 15 )] ); /*Q16,exp -7*/ L_tmp_exp = add( L_tmp_exp, -7 ); /*->Q16, L_tmp_exp */ L_tmp_exp = add( L_tmp_exp, 31 - 16 ); /*->Q31, L_tmp_exp*/ #ifdef BASOP_NOGLOB - st->hTcxDec->conCngLevelBackgroundTrace = round_fx_sat( Sqrt32( L_tmp, &L_tmp_exp ) ); + st->hTcxDec->conCngLevelBackgroundTrace = round_fx_sat( Sqrt32( L_tmp, &L_tmp_exp ) ); /*Q15 - L_tmp_exp*/ move16(); #else st->hTcxDec->conCngLevelBackgroundTrace = round_fx( Sqrt32( L_tmp, &L_tmp_exp ) ); @@ -1542,7 +1542,7 @@ Word16 ApplyFdCng_ivas_fx( Carry = 0; move16(); #ifdef BASOP_NOGLOB - L_tmp = L_add_co( L_tmp, *( cngNoiseLevel + j ), &Carry, &Overflow ); + L_tmp = L_add_co( L_tmp, *( cngNoiseLevel + j ), &Carry, &Overflow ); /*Q31 - L_tmp_exp*/ #else L_tmp = L_add_c( L_tmp, *( cngNoiseLevel + j ) ); #endif @@ -1551,28 +1551,28 @@ Word16 ApplyFdCng_ivas_fx( IF( *( cngNoiseLevel + j ) < 0 ) { - L_c = L_msuNs( L_c, 0, 0 ); + L_c = L_msuNs( L_c, 0, 0 ); /*Q-1*/ } IF( *( cngNoiseLevel + j ) >= 0 ) { #ifdef BASOP_NOGLOB - L_c = L_macNs_co( L_c, 0, 0, &Carry, &Overflow ); + L_c = L_macNs_co( L_c, 0, 0, &Carry, &Overflow ); /*Q-1*/ #else L_c = L_macNs( L_c, 0, 0 ); #endif } } - L_tmp = norm_llQ31( L_c, L_tmp, &L_tmp_exp ); + L_tmp = norm_llQ31( L_c, L_tmp, &L_tmp_exp ); /*Q31 - L_tmp_exp*/ L_tmp_exp = sub( add( L_tmp_exp, *cngNoiseLevel_exp ), 1 ); - L_tmp = Mpy_32_16_1( L_tmp, hFdCngCom->fftlen ); /*Q16*/ + L_tmp = Mpy_32_16_1( L_tmp, hFdCngCom->fftlen ); /*Q16 - L_tmp_exp*/ L_tmp = Mpy_32_16_1( L_tmp, T_DIV_L_Frame[L_shl( L_mac( -28000, st->L_frame, 95 ), 1 - 15 )] ); /*Q16,exp -7*/ L_tmp_exp = add( L_tmp_exp, -7 ); /*->Q16, L_tmp_exp */ L_tmp_exp = add( L_tmp_exp, 31 - 16 ); /*->Q31, L_tmp_exp*/ #ifdef BASOP_NOGLOB - st->cngTDLevel = round_fx_sat( Sqrt32( L_tmp, &L_tmp_exp ) ); + st->cngTDLevel = round_fx_sat( Sqrt32( L_tmp, &L_tmp_exp ) ); /*Q15 - L_tmp_exp*/ #else st->cngTDLevel = round_fx( Sqrt32( L_tmp, &L_tmp_exp ) ); #endif @@ -1604,7 +1604,7 @@ Word16 ApplyFdCng_ivas_fx( move32(); FOR( j = hFdCngCom->startBand; j < hFdCngCom->stopFFTbin; j++ ) { - L_tmp = L_add_sat( L_tmp, L_shl_sat( cngNoiseLevel[j], sub( 31, *cngNoiseLevel_exp ) ) ); + L_tmp = L_add_sat( L_tmp, L_shl_sat( cngNoiseLevel[j], sub( 31, *cngNoiseLevel_exp ) ) ); /*Q31*/ } L_tmp_exp = 0; move16(); @@ -1624,9 +1624,9 @@ Word16 ApplyFdCng_ivas_fx( { lpc_from_spectrum( hFdCngCom, hFdCngCom->startBand, hFdCngCom->stopFFTbin, 0 ); E_LPC_a_lsp_conversion( hFdCngCom->A_cng, lsp_cng, st->lspold_cng, M ); - Copy( lsp_cng, st->lspold_cng, M ); + Copy( lsp_cng, st->lspold_cng, M ); /*Q15*/ - lsp2lsf_fx( lsp_cng, st->lsf_cng, M, st->sr_core ); + lsp2lsf_fx( lsp_cng, st->lsf_cng, M, st->sr_core ); /*x2.56*/ } st->plcBackgroundNoiseUpdated = 1; @@ -1659,7 +1659,7 @@ Word16 ApplyFdCng_ivas_fx( hFdCngDec->bandNoiseShape_exp = hFdCngDec->msNoiseEst_exp; move16(); /* This sets the new CNG levels until a SID update overwrites it */ - Copy32( hFdCngDec->bandNoiseShape, cngNoiseLevel, sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ) ); /* This sets the new CNG levels until a SID update overwrites it */ + Copy32( hFdCngDec->bandNoiseShape, cngNoiseLevel, sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ) ); /* This sets the new CNG levels until a SID update overwrites it */ /*Q31 - hFdCngDec->bandNoiseShape_exp*/ *cngNoiseLevel_exp = hFdCngDec->bandNoiseShape_exp; move16(); @@ -1672,18 +1672,18 @@ Word16 ApplyFdCng_ivas_fx( Carry = 0; move16(); -#ifdef BASOP_NOGLOB /* Critical Carry/Overflow */ - L_tmp = L_add_co( L_tmp, *( cngNoiseLevel + j ), &Carry, &Overflow ); +#ifdef BASOP_NOGLOB /* Critical Carry/Overflow */ + L_tmp = L_add_co( L_tmp, *( cngNoiseLevel + j ), &Carry, &Overflow ); /*Q31 - L_tmp_exp*/ Overflow = 0; move16(); IF( *( cngNoiseLevel + j ) < 0 ) { - L_c = L_msuNs_co( L_c, 0, 0, &Carry, &Overflow ); + L_c = L_msuNs_co( L_c, 0, 0, &Carry, &Overflow ); /*Q-1*/ } IF( *( cngNoiseLevel + j ) >= 0 ) { - L_c = L_macNs_co( L_c, 0, 0, &Carry, &Overflow ); + L_c = L_macNs_co( L_c, 0, 0, &Carry, &Overflow ); /*Q-1*/ } #else L_tmp = L_add_c( L_tmp, *( cngNoiseLevel + j ) ); @@ -1699,17 +1699,17 @@ Word16 ApplyFdCng_ivas_fx( } #endif } - L_tmp = norm_llQ31( L_c, L_tmp, &L_tmp_exp ); + L_tmp = norm_llQ31( L_c, L_tmp, &L_tmp_exp ); /*Q31 - L_tmp_exp*/ L_tmp_exp = sub( add( L_tmp_exp, *cngNoiseLevel_exp ), 1 ); - L_tmp = Mpy_32_16_1( L_tmp, hFdCngCom->fftlen ); /*Q16*/ + L_tmp = Mpy_32_16_1( L_tmp, hFdCngCom->fftlen ); /*Q16 - L_tmp_exp*/ L_tmp = Mpy_32_16_1( L_tmp, T_DIV_L_Frame[L_shl( L_mac( -28000, st->L_frame, 95 ), 1 - 15 )] ); /*Q16,exp -7*/ L_tmp_exp = add( L_tmp_exp, -7 ); /*->Q16, L_tmp_exp */ L_tmp_exp = add( L_tmp_exp, 31 - 16 ); /*->Q31, L_tmp_exp*/ -#ifdef BASOP_NOGLOB /* Critical Carry/Overflow */ - st->cngTDLevel = round_fx_o( Sqrt32( L_tmp, &L_tmp_exp ), &Overflow ); +#ifdef BASOP_NOGLOB /* Critical Carry/Overflow */ + st->cngTDLevel = round_fx_o( Sqrt32( L_tmp, &L_tmp_exp ), &Overflow ); /*Q15 - L_tmp_exp*/ #else st->cngTDLevel = round_fx( Sqrt32( L_tmp, &L_tmp_exp ) ); #endif @@ -1740,7 +1740,7 @@ Word16 ApplyFdCng_ivas_fx( &hFdCngDec->partNoiseShape_exp ); IF( EQ_16( st->element_mode, IVAS_CPE_DFT ) ) { - Copy32( hFdCngDec->hFdCngCom->sidNoiseEst, hFdCngDec->hFdCngCom->sidNoiseEstLp, NPART ); + Copy32( hFdCngDec->hFdCngCom->sidNoiseEst, hFdCngDec->hFdCngCom->sidNoiseEstLp, NPART ); /*Q31 - hFdCngDec->sidNoiseEstExp*/ } } @@ -1758,7 +1758,7 @@ Word16 ApplyFdCng_ivas_fx( { if ( EQ_16( st->element_mode, IVAS_CPE_DFT ) ) { - sidNoiseEst = hFdCngCom->sidNoiseEstLp; + sidNoiseEst = hFdCngCom->sidNoiseEstLp; /*Q31 - hFdCngDec->sidNoiseEstExp*/ } /* Interpolate the CLDFB band levels from the SID (partition) levels */ IF( GT_16( hFdCngCom->regularStopBand, hFdCngCom->numCoreBands ) ) @@ -1770,7 +1770,7 @@ Word16 ApplyFdCng_ivas_fx( move16(); } - s2 = negate( sub( WORD32_BITS, 1 ) ); + s2 = -( ( WORD32_BITS - 1 ) ); move16(); /* Shape the SID noise levels in each FFT bin */ j = 0; @@ -1785,21 +1785,21 @@ Word16 ApplyFdCng_ivas_fx( IF( hFdCngDec->partNoiseShape[k] != 0 ) { s1 = norm_l( sidNoiseEst[k] ); - L_tmp = L_shl( sidNoiseEst[k], s1 ); + L_tmp = L_shl( sidNoiseEst[k], s1 ); /*Q31 - ( hFdCngCom->sidNoiseEstExp - s1 )*/ L_tmp_exp = sub( hFdCngCom->sidNoiseEstExp, s1 ); L_tmp = BASOP_Util_Add_Mant32Exp( sidNoiseEst[k], hFdCngCom->sidNoiseEstExp, DELTA_MANTISSA_W32, DELTA_EXPONENT, &L_tmp_exp ); L_tmp = L_shr( L_tmp, 1 ); s = add( L_tmp_exp, 1 ); - num = extract_h( L_tmp ); + num = extract_h( L_tmp ); /*Q15 - L_tmp_exp*/ s1 = norm_l( hFdCngDec->partNoiseShape[k] ); - L_tmp = L_shl( hFdCngDec->partNoiseShape[k], s1 ); + L_tmp = L_shl( hFdCngDec->partNoiseShape[k], s1 ); /*Q31 - ( hFdCngDec->partNoiseShape_ex - s1 )*/ L_tmp_exp = sub( hFdCngDec->partNoiseShape_exp, s1 ); L_tmp = BASOP_Util_Add_Mant32Exp( L_tmp, L_tmp_exp, DELTA_MANTISSA_W32, DELTA_EXPONENT, &L_tmp_exp ); s = sub( s, L_tmp_exp ); - denom = extract_h( L_tmp ); + denom = extract_h( L_tmp ); /*Q15 - L_tmp_exp*/ - facTab[k] = div_s( num, denom ); + facTab[k] = div_s( num, denom ); /*Q15 - s*/ move16(); facTabExp[k] = s; move16(); @@ -1807,7 +1807,7 @@ Word16 ApplyFdCng_ivas_fx( /* Set unique exponent, IF mantissa is equal to zero */ IF( EQ_16( facTab[k], 0 ) ) { - facTabExp[k] = negate( sub( WORD32_BITS, 1 ) ); + facTabExp[k] = -( ( WORD32_BITS - 1 ) ); move16(); } s2 = s_max( s2, facTabExp[k] ); @@ -1820,10 +1820,10 @@ Word16 ApplyFdCng_ivas_fx( FOR( k = 0; k < hFdCngCom->nFFTpart; k++ ) { s = sub( facTabExp[k], s2 ); - s = s_max( s_min( s, sub( WORD32_BITS, 1 ) ), negate( sub( WORD32_BITS, 1 ) ) ); + s = s_max( s_min( s, ( WORD32_BITS - 1 ) ), -( ( WORD32_BITS - 1 ) ) ); FOR( ; j <= hFdCngCom->part[k]; j++ ) { - cngNoiseLevel[j] = L_shl( Mpy_32_16_1( hFdCngDec->bandNoiseShape[j], facTab[k] ), s ); + cngNoiseLevel[j] = L_shl( Mpy_32_16_1( hFdCngDec->bandNoiseShape[j], facTab[k] ), s ); /*Q31 - hFdCngDec->bandNoiseShape_exp*/ move32(); } } @@ -1833,7 +1833,7 @@ Word16 ApplyFdCng_ivas_fx( { FOR( ; j <= hFdCngCom->part[k]; j++ ) { - cngNoiseLevel[j] = L_shl( cngNoiseLevel[j], s ); + cngNoiseLevel[j] = L_shl( cngNoiseLevel[j], s ); /*Q31 - hFdCngDec->bandNoiseShape_exp + s*/ move32(); } } @@ -1845,7 +1845,7 @@ Word16 ApplyFdCng_ivas_fx( { IF( !( LT_16( hFdCngCom->msFrCnt_init_counter, hFdCngCom->msFrCnt_init_thresh ) ) ) { - s2 = negate( sub( WORD32_BITS, 1 ) ); + s2 = -( ( WORD32_BITS - 1 ) ); /* Shape the SID noise levels in each FFT bin */ j = 0; move16(); @@ -1859,21 +1859,21 @@ Word16 ApplyFdCng_ivas_fx( IF( hFdCngDec->partNoiseShape[k] != 0 ) { s1 = norm_l( hFdCngCom->sidNoiseEstLp[k] ); - L_tmp = L_shl( hFdCngCom->sidNoiseEstLp[k], s1 ); + L_tmp = L_shl( hFdCngCom->sidNoiseEstLp[k], s1 ); /*Q31 - ( hFdCngCom->sidNoiseEstExp - s1 )*/ L_tmp_exp = sub( hFdCngCom->sidNoiseEstExp, s1 ); L_tmp = BASOP_Util_Add_Mant32Exp( hFdCngCom->sidNoiseEstLp[k], hFdCngCom->sidNoiseEstExp, DELTA_MANTISSA_W32, DELTA_EXPONENT, &L_tmp_exp ); L_tmp = L_shr( L_tmp, 1 ); s = add( L_tmp_exp, 1 ); - num = extract_h( L_tmp ); + num = extract_h( L_tmp ); /*Q15 - L_tmp_exp*/ s1 = norm_l( hFdCngDec->partNoiseShape[k] ); - L_tmp = L_shl( hFdCngDec->partNoiseShape[k], s1 ); + L_tmp = L_shl( hFdCngDec->partNoiseShape[k], s1 ); /*Q31 - ( hFdCngDec->partNoiseShape_exp - s1 )*/ L_tmp_exp = sub( hFdCngDec->partNoiseShape_exp, s1 ); L_tmp = BASOP_Util_Add_Mant32Exp( L_tmp, L_tmp_exp, DELTA_MANTISSA_W32, DELTA_EXPONENT, &L_tmp_exp ); s = sub( s, L_tmp_exp ); - denom = extract_h( L_tmp ); + denom = extract_h( L_tmp ); /*Q15 - L_tmp_exp*/ - facTab[k] = div_s( num, denom ); + facTab[k] = div_s( num, denom ); /*Q15 - s*/ move16(); facTabExp[k] = s; move16(); @@ -1897,7 +1897,7 @@ Word16 ApplyFdCng_ivas_fx( s = s_max( s_min( s, sub( WORD32_BITS, 1 ) ), negate( sub( WORD32_BITS, 1 ) ) ); FOR( ; j <= hFdCngCom->part[k]; j++ ) { - cngNoiseLevel[j] = L_shl( Mpy_32_16_1( hFdCngDec->bandNoiseShape[j], facTab[k] ), s ); + cngNoiseLevel[j] = L_shl( Mpy_32_16_1( hFdCngDec->bandNoiseShape[j], facTab[k] ), s ); /*Q31 - hFdCngDec->bandNoiseShape_exp*/ move32(); } } @@ -1907,7 +1907,7 @@ Word16 ApplyFdCng_ivas_fx( { FOR( ; j <= hFdCngCom->part[k]; j++ ) { - cngNoiseLevel[j] = L_shl( cngNoiseLevel[j], s ); + cngNoiseLevel[j] = L_shl( cngNoiseLevel[j], s ); /*Q31 - hFdCngDec->bandNoiseShape_exp + s*/ move32(); } } @@ -1948,7 +1948,7 @@ Word16 ApplyFdCng_ivas_fx( void */ void perform_noise_estimation_dec_fx( - const Word16 *timeDomainInput, /* i: pointer to time domain input */ + const Word16 *timeDomainInput, /* i: pointer to time domain input Q*/ const Word16 Q, #ifdef IVAS_CODE_CNG_FIX185_PLC_FADEOUT float *power_spectrum, @@ -1977,22 +1977,22 @@ void perform_noise_estimation_dec_fx( /* pointer initialization */ - periodog = hFdCngDec->hFdCngCom->periodog; - fftBuffer = hFdCngDec->hFdCngCom->fftBuffer; + periodog = hFdCngDec->hFdCngCom->periodog; /*Q31 - hFdCngDec->hFdCngCom->periodog_exp*/ + fftBuffer = hFdCngDec->hFdCngCom->fftBuffer; /*Q31 - hFdCngDec->hFdCngCom->fftBuffer_exp*/ - part = hFdCngDec->part_shaping; - psize_inv = hFdCngDec->psize_inv_shaping; - psize_norm = hFdCngDec->psize_shaping_norm; + part = hFdCngDec->part_shaping; /*Q0*/ + psize_inv = hFdCngDec->psize_inv_shaping; /*Q15*/ + psize_norm = hFdCngDec->psize_shaping_norm; /*Q15 - hFdCngDec->psize_shaping_norm_exp*/ /* variable initialization */ - startBand = hFdCngDec->hFdCngCom->startBand; + startBand = hFdCngDec->hFdCngCom->startBand; /*Q0*/ move16(); - stopFFTbin = hFdCngDec->hFdCngCom->stopFFTbin; + stopFFTbin = hFdCngDec->hFdCngCom->stopFFTbin; /*Q0*/ move16(); - npart = hFdCngDec->npart_shaping; + npart = hFdCngDec->npart_shaping; /*Q0*/ move16(); - nFFTpart = hFdCngDec->nFFTpart_shaping; + nFFTpart = hFdCngDec->nFFTpart_shaping; /*Q0*/ move16(); /* Perform STFT analysis */ @@ -2278,36 +2278,36 @@ void perform_noise_estimation_dec_fx( len = sub( stopFFTbin, startBand ); - s = getScaleFactor32( &fftBuffer[shl( startBand, 1 )], shl( len, 1 ) ); + s = getScaleFactor32( &fftBuffer[( startBand * 2 )], shl( len, 1 ) ); s = sub( s, 1 ); ptr_per = periodog; IF( startBand == 0 ) { /* DC component */ - tmp_r = extract_h( L_shl( fftBuffer[0], s ) ); + tmp_r = extract_h( L_shl( fftBuffer[0], s ) ); /*Q15 - fftBuffer_exp + s*/ - tmp = L_mult( tmp_r, tmp_r ); - *ptr_per = tmp; + tmp = L_mult( tmp_r, tmp_r ); /*Q31 - 2*(fftBuffer_exp - s)*/ + *ptr_per = tmp; /*Q31 - 2*(fftBuffer_exp - s)*/ move32(); ptr_per++; - ptr_r = fftBuffer + 2; + ptr_r = fftBuffer + 2; /*Q31 - fftBuffer_exp*/ len = sub( len, 1 ); } ELSE { - ptr_r = fftBuffer + shl( startBand, 1 ); + ptr_r = fftBuffer + shl( startBand, 1 ); /*fftBuffer_exp*/ } ptr_i = ptr_r + 1; FOR( i = 0; i < len; i++ ) { - tmp_r = extract_h( L_shl( *ptr_r, s ) ); - tmp_i = extract_h( L_shl( *ptr_i, s ) ); + tmp_r = extract_h( L_shl( *ptr_r, s ) ); /*Q15 - fftBuffer_exp + s*/ + tmp_i = extract_h( L_shl( *ptr_i, s ) ); /*Q15 - fftBuffer_exp + s*/ - tmp = L_mac( L_mult( tmp_r, tmp_r ), tmp_i, tmp_i ); - *ptr_per = tmp; + tmp = L_mac( L_mult( tmp_r, tmp_r ), tmp_i, tmp_i ); /*Q31 - 2*(fftBuffer_exp - s)*/ + *ptr_per = tmp; /*Q31 - 2*(fftBuffer_exp - s)*/ move32(); ptr_r += 2; @@ -2348,7 +2348,7 @@ void perform_noise_estimation_dec_fx( len = sub( stopFFTbin, startBand ); FOR( i = 0; i < len; i++ ) { - hFdCngDec->hFdCngCom->periodog[i] = Mpy_32_16_1( hFdCngDec->hFdCngCom->periodog[i], fac ); + hFdCngDec->hFdCngCom->periodog[i] = Mpy_32_16_1( hFdCngDec->hFdCngCom->periodog[i], fac ); /*Q31 - hFdCngDec->hFdCngCom->periodog_exp*/ move32(); } hFdCngDec->hFdCngCom->periodog_exp = add( hFdCngDec->hFdCngCom->periodog_exp, sub( 2, s ) ); @@ -2404,17 +2404,17 @@ void perform_noise_estimation_dec_fx( #ifdef IVAS_FLOAT_FIXED void perform_noise_estimation_dec_ivas_fx( - const Word16 *timeDomainInput, /* i: pointer to time domain input */ + const Word16 *timeDomainInput, /* i: pointer to time domain input Q*/ const Word16 Q, - Word32 *power_spectrum, + Word32 *power_spectrum, /*Q_power_spectrum*/ Word16 Q_power_spectrum, HANDLE_FD_CNG_DEC hFdCngDec, /* i/o: FD_CNG structure containing all buffers and variables */ - const Word16 element_mode, /* i : element mode */ - const Word16 bwidth, /* i : audio bandwidth */ - const Word16 L_frame, /* i : frame length at internal Fs */ - const Word16 last_L_frame, /* i : frame length of the last frame at internal Fs */ - const Word32 last_core_brate, /* i : previous frame core bitrate */ - const Word16 VAD /* i : VAD flag in the decoder */ + const Word16 element_mode, /* i : element mode Q0*/ + const Word16 bwidth, /* i : audio bandwidth Q0*/ + const Word16 L_frame, /* i : frame length at internal Fs Q0*/ + const Word16 last_L_frame, /* i : frame length of the last frame at internal Fs Q0*/ + const Word32 last_core_brate, /* i : previous frame core bitrate Q0*/ + const Word16 VAD /* i : VAD flag in the decoder Q0*/ ) { Word16 i, p, fftBuffer_exp = 0; @@ -2442,15 +2442,15 @@ void perform_noise_estimation_dec_ivas_fx( /* pointer initialization */ - periodog = hFdCngDec->hFdCngCom->periodog; - fftBuffer = hFdCngDec->hFdCngCom->fftBuffer; - ptr_per = periodog; - msPeriodog = hFdCngDec->msPeriodog; - msNoiseEst = hFdCngDec->msNoiseEst; + periodog = hFdCngDec->hFdCngCom->periodog; /*Q31 - hFdCngDec->hFdCngCom->periodog_exp*/ + fftBuffer = hFdCngDec->hFdCngCom->fftBuffer; /*Q31 - hFdCngDec->hFdCngCom->fftBuffer_exp*/ + ptr_per = periodog; /*Q31 - hFdCngDec->hFdCngCom->periodog_exp*/ + msPeriodog = hFdCngDec->msPeriodog; /*Q31 - hFdCngDec->msPeriodog_exp*/ + msNoiseEst = hFdCngDec->msNoiseEst; /*Q31 - hFdCngDec->msNoiseEst_exp*/ - part = hFdCngDec->part_shaping; - psize_inv = hFdCngDec->psize_inv_shaping; - psize_norm = hFdCngDec->psize_shaping_norm; + part = hFdCngDec->part_shaping; /*Q0*/ + psize_inv = hFdCngDec->psize_inv_shaping; /*Q15*/ + psize_norm = hFdCngDec->psize_shaping_norm; /*Q15 - hFdCngDec->psize_shaping_norm_exp*/ /* variable initialization */ startBand = hFdCngDec->hFdCngCom->startBand; @@ -2494,39 +2494,39 @@ void perform_noise_estimation_dec_ivas_fx( /* Calculate periodogram (squared magnitude in each FFT bin) */ IF( startBand == 0 ) { - W_tmp = W_mult0_32_32( fftBuffer[0], fftBuffer[0] ); + W_tmp = W_mult0_32_32( fftBuffer[0], fftBuffer[0] ); /*Q31 - 2*fftBuffer_exp*/ tmp_s = W_norm( W_tmp ); - ( *ptr_per ) = W_extract_h( W_shl( W_tmp, tmp_s ) ); + ( *ptr_per ) = W_extract_h( W_shl( W_tmp, tmp_s ) ); /*tmp_q*/ tmp_q = sub( add( i_mult( sub( 31, fftBuffer_exp ), 2 ), tmp_s ), 32 ); min_q = tmp_q; move16(); ptr_per++; - ptr_r = fftBuffer + 2; + ptr_r = fftBuffer + 2; /*Q31 - fftBuffer_exp*/ } ELSE { - ptr_r = fftBuffer + i_mult( 2, startBand ); + ptr_r = fftBuffer + i_mult( 2, startBand ); /*Q31 - fftBuffer_exp*/ } - ptr_i = ptr_r + 1; + ptr_i = ptr_r + 1; /*Q31 - fftBuffer_exp*/ FOR( ; ptr_per < periodog + sub( stopFFTbin, startBand ); ptr_per++ ) { - W_tmp = W_add( W_mult0_32_32( ( *ptr_r ), ( *ptr_r ) ), W_mult0_32_32( ( *ptr_i ), ( *ptr_i ) ) ); + W_tmp = W_add( W_mult0_32_32( ( *ptr_r ), ( *ptr_r ) ), W_mult0_32_32( ( *ptr_i ), ( *ptr_i ) ) ); /*Q31 - 2*(fftBuffer_exp)*/ tmp_s = W_norm( W_tmp ); tmp_q = sub( add( i_mult( sub( 31, fftBuffer_exp ), 2 ), tmp_s ), 32 ); - *ptr_per = W_extract_h( W_shl( W_tmp, tmp_s ) ); + *ptr_per = W_extract_h( W_shl( W_tmp, tmp_s ) ); /*tmp_q*/ IF( LT_16( tmp_q, min_q ) ) { - reIter = ptr_per; + reIter = ptr_per; /*tmp_q*/ Word16 diff; diff = sub( min_q, tmp_q ); WHILE( reIter > periodog ) { reIter--; - *reIter = L_shr( *reIter, diff ); + *reIter = L_shr( *reIter, diff ); /*tmp_q*/ move32(); } min_q = tmp_q; @@ -2536,7 +2536,7 @@ void perform_noise_estimation_dec_ivas_fx( { Word16 diff; diff = sub( tmp_q, min_q ); - ( *ptr_per ) = L_shr( ( *ptr_per ), diff ); + ( *ptr_per ) = L_shr( ( *ptr_per ), diff ); /*min_q*/ } /* Rescale to get energy/sample: it should be 2*(1/N)*(2/N), parseval relation with 1/N,*2 for nrg computed till Nyquist only, 2/N as windowed samples correspond to half a frame*/ @@ -2560,7 +2560,7 @@ void perform_noise_estimation_dec_ivas_fx( move16(); FOR( p = 0; p < stopFFTbin - startBand; p++ ) { - periodog[p] = L_shl( periodog[p], tmp_s ); + periodog[p] = L_shl( periodog[p], tmp_s ); /*Q31 - hFdCngDec->hFdCngCom->periodog_exp*/ move32(); } } @@ -2576,9 +2576,9 @@ void perform_noise_estimation_dec_ivas_fx( move16(); FOR( ; i <= part[p]; i++ ) { - temp = L_add( temp, periodog[i] ); + temp = L_add( temp, periodog[i] ); /*Q31 - hFdCngDec->hFdCngCom->periodog_exp*/ } - msPeriodog[p] = Mpy_32_16_1( temp, psize_inv[p] ); // Qtemp = Qperiodog + msPeriodog[p] = Mpy_32_16_1( temp, psize_inv[p] ); /*Q31 - hFdCngDec->hFdCngCom->periodog_exp*/ move32(); } @@ -2596,7 +2596,7 @@ void perform_noise_estimation_dec_ivas_fx( { FOR( p = 0; p < NPART_SHAPING; p++ ) { - msPeriodog[p] = L_shr( msPeriodog[p], sub( -16, hFdCngDec->msPeriodog_exp ) ); + msPeriodog[p] = L_shr( msPeriodog[p], sub( -16, hFdCngDec->msPeriodog_exp ) ); /*Q31 - (-16)*/ move32(); } hFdCngDec->msPeriodog_exp = -16; @@ -2612,8 +2612,8 @@ void perform_noise_estimation_dec_ivas_fx( move64(); FOR( ; i <= part[p]; i++ ) { - delta = L_sub( periodog[i], msPeriodog[p] ); - W_tmp = W_add( W_tmp, W_mult0_32_32( delta, delta ) ); + delta = L_sub( periodog[i], msPeriodog[p] ); /*Q31 - hFdCngDec->hFdCngCom->periodog_exp*/ + W_tmp = W_add( W_tmp, W_mult0_32_32( delta, delta ) ); /*Q31 - 2*(hFdCngDec->hFdCngCom->periodog_exp)*/ } tmp_s = W_norm( W_tmp ); temp = W_extract_h( W_shl( W_tmp, tmp_s ) ); // Q = 63 - 2*(31-exp) - tmp_s @@ -2622,25 +2622,25 @@ void perform_noise_estimation_dec_ivas_fx( /* compensate for the loss of variance */ e_temp = sub( 63, add( i_mult( sub( 31, hFdCngDec->hFdCngCom->periodog_exp ), 2 ), tmp_s ) ); - temp = Sqrt32( temp, &e_temp ); + temp = Sqrt32( temp, &e_temp ); /*Q31 - e_temp*/ IF( LT_16( e_temp, 0 ) ) { - temp = L_shr( temp, abs_s( e_temp ) ); + temp = L_shr( temp, abs_s( e_temp ) ); /*Q31*/ e_temp = 0; move16(); } - ftemp = rand_gauss( &hFdCngDec->cna_seed ); + ftemp = rand_gauss( &hFdCngDec->cna_seed ); /*Q29*/ - L_tmp = Mpy_32_32( temp, ftemp ); - L_tmp = L_shr( L_tmp, sub( sub( hFdCngDec->hFdCngCom->periodog_exp, e_temp ), 2 ) ); + L_tmp = Mpy_32_32( temp, ftemp ); /*Q29*/ + L_tmp = L_shr( L_tmp, sub( sub( hFdCngDec->hFdCngCom->periodog_exp, e_temp ), 2 ) ); /*Q31 - hFdCngDec->msPeriodog_exp*/ - msPeriodog[p] = L_add( msPeriodog[p], L_tmp ); + msPeriodog[p] = L_add( msPeriodog[p], L_tmp ); /*Q31 - hFdCngDec->msPeriodog_exp*/ move32(); - IF( LT_32( msPeriodog[p], L_shr( 21474, hFdCngDec->msPeriodog_exp ) ) ) + IF( LT_32( msPeriodog[p], L_shr( 21474 /*Q31*/, hFdCngDec->msPeriodog_exp ) ) ) { - msPeriodog[p] = L_shr( 21474, hFdCngDec->msPeriodog_exp ); + msPeriodog[p] = L_shr( 21474 /*Q31*/, hFdCngDec->msPeriodog_exp ); /*Q31 - hFdCngDec->msPeriodog_exp*/ move32(); } } @@ -2652,7 +2652,7 @@ void perform_noise_estimation_dec_ivas_fx( { FOR( p = 0; p < npart; p++ ) { - msPeriodog[p] = L_shr( msPeriodog[p], sub( 5, tmp_s ) ); + msPeriodog[p] = L_shr( msPeriodog[p], sub( 5, tmp_s ) ); /*Q31 - hFdCngDec->msPeriodog_exp - 5 + tmp_s*/ move32(); } hFdCngDec->msPeriodog_exp = add( hFdCngDec->msPeriodog_exp, sub( 5, tmp_s ) ); @@ -2664,13 +2664,13 @@ void perform_noise_estimation_dec_ivas_fx( move32(); IF( GE_16( hFdCngDec->msNoiseEst_exp, hFdCngDec->msPeriodog_exp ) ) { - enr_tot = L_add_sat( L_shr( sum32_fx( msPeriodog, npart ), sub( hFdCngDec->msNoiseEst_exp, hFdCngDec->msPeriodog_exp ) ), 1 ); + enr_tot = L_add_sat( L_shr( sum32_fx( msPeriodog, npart ), sub( hFdCngDec->msNoiseEst_exp, hFdCngDec->msPeriodog_exp ) ), 1 ); /*Q31 - hFdCngDec->msNoiseEst_exp*/ enr_tot0 = L_add_sat( sum32_fx( msNoiseEst, npart ), 1 ); } ELSE IF( LT_16( hFdCngDec->msNoiseEst_exp, hFdCngDec->msPeriodog_exp ) ) { enr_tot = L_add_sat( sum32_fx( msPeriodog, npart ), 1 ); - enr_tot0 = L_add_sat( L_shr( sum32_fx( msNoiseEst, npart ), sub( hFdCngDec->msPeriodog_exp, hFdCngDec->msNoiseEst_exp ) ), 1 ); + enr_tot0 = L_add_sat( L_shr( sum32_fx( msNoiseEst, npart ), sub( hFdCngDec->msPeriodog_exp, hFdCngDec->msNoiseEst_exp ) ), 1 ); /*Q31 - hFdCngDec->msPeriodog_exp*/ } /* update short-term periodogram on larger partitions */ @@ -2680,7 +2680,7 @@ void perform_noise_estimation_dec_ivas_fx( test(); IF( max_l && GT_16( q_shift, norm_shift ) ) { - scale_sig32( hFdCngDec->msPeriodog_ST_fx, NPART_SHAPING, sub( norm_shift, q_shift ) ); + scale_sig32( hFdCngDec->msPeriodog_ST_fx, NPART_SHAPING, sub( norm_shift, q_shift ) ); /*Q31 - hFdCngDec->msPeriodog_ST_exp + ( norm_shift - q_shift )*/ hFdCngDec->msPeriodog_ST_exp = sub( hFdCngDec->msPeriodog_ST_exp, sub( norm_shift, q_shift ) ); move16(); q_shift = norm_shift; @@ -2693,14 +2693,14 @@ void perform_noise_estimation_dec_ivas_fx( IF( NE_16( L_frame, last_L_frame ) || LE_32( last_core_brate, SID_2k40 ) ) { /* core Fs has changed or last frame was SID/NO_DATA -> re-initialize short-term periodogram */ - hFdCngDec->msPeriodog_ST_fx[p] = L_shl( msPeriodog[p], q_shift ); + hFdCngDec->msPeriodog_ST_fx[p] = L_shl( msPeriodog[p], q_shift ); /*Q31 - hFdCngDec->hFdCngCom->periodog_exp*/ move32(); } ELSE { #ifdef IVAS_ENH32_CADENCE_CHANGES - temp = L_shl( msPeriodog[p], q_shift ); - hFdCngDec->msPeriodog_ST_fx[p] = Madd_32_16( Mpy_32_16_1( hFdCngDec->msPeriodog_ST_fx[p], ST_PERIODOG_FACT_Q15 ), temp, MAX_16 - ST_PERIODOG_FACT_Q15 ); + temp = L_shl( msPeriodog[p], q_shift ); /*Q31 - hFdCngDec->hFdCngCom->periodog_exp*/ + hFdCngDec->msPeriodog_ST_fx[p] = Madd_32_16( Mpy_32_16_1( hFdCngDec->msPeriodog_ST_fx[p], ST_PERIODOG_FACT_Q15 ), temp, MAX_16 - ST_PERIODOG_FACT_Q15 ); /*Q31 - hFdCngDec->msPeriodog_ST_exp*/ #else hFdCngDec->msPeriodog_ST_fx[p] = L_add( Mpy_32_16_1( hFdCngDec->msPeriodog_ST_fx[p], ST_PERIODOG_FACT_Q15 ), Mpy_32_16_1( temp, sub( MAX_16, ST_PERIODOG_FACT_Q15 ) ) ); #endif @@ -2711,7 +2711,7 @@ void perform_noise_estimation_dec_ivas_fx( IF( max_l ) { q_shift = sub( norm_l( max_l ), 2 ); - scale_sig32( hFdCngDec->msPeriodog_ST_fx, NPART_SHAPING, q_shift ); + scale_sig32( hFdCngDec->msPeriodog_ST_fx, NPART_SHAPING, q_shift ); /*Q31 - hFdCngDec->msPeriodog_ST_exp + q_shift*/ hFdCngDec->msPeriodog_ST_exp = sub( hFdCngDec->msPeriodog_ST_exp, q_shift ); move16(); } @@ -2731,32 +2731,32 @@ void perform_noise_estimation_dec_ivas_fx( test(); IF( EQ_16( last_L_frame, L_FRAME16k ) && EQ_16( L_frame, L_FRAME ) ) { - msNoiseEst[61] = msNoiseEst[58]; + msNoiseEst[61] = msNoiseEst[58]; /*Q31 - hFdCngDec->msNoiseEst_exp*/ move32(); - msNoiseEst[60] = L_min( msNoiseEst[58], msNoiseEst[57] ); + msNoiseEst[60] = L_min( msNoiseEst[58], msNoiseEst[57] ); /*Q31 - hFdCngDec->msNoiseEst_exp*/ move32(); - msNoiseEst[59] = msNoiseEst[57]; + msNoiseEst[59] = msNoiseEst[57]; /*Q31 - hFdCngDec->msNoiseEst_exp*/ move32(); - msNoiseEst[58] = msNoiseEst[56]; + msNoiseEst[58] = msNoiseEst[56]; /*Q31 - hFdCngDec->msNoiseEst_exp*/ move32(); - msNoiseEst[57] = msNoiseEst[56]; + msNoiseEst[57] = msNoiseEst[56]; /*Q31 - hFdCngDec->msNoiseEst_exp*/ move32(); - msNoiseEst[56] = L_min( msNoiseEst[56], msNoiseEst[55] ); + msNoiseEst[56] = L_min( msNoiseEst[56], msNoiseEst[55] ); /*Q31 - hFdCngDec->msNoiseEst_exp*/ move32(); } ELSE IF( EQ_16( last_L_frame, L_FRAME ) && EQ_16( L_frame, L_FRAME16k ) ) { - msNoiseEst[56] = L_min( msNoiseEst[56], msNoiseEst[57] ); + msNoiseEst[56] = L_min( msNoiseEst[56], msNoiseEst[57] ); /*Q31 - hFdCngDec->msNoiseEst_exp*/ move32(); - msNoiseEst[57] = L_min( msNoiseEst[58], msNoiseEst[59] ); + msNoiseEst[57] = L_min( msNoiseEst[58], msNoiseEst[59] ); /*Q31 - hFdCngDec->msNoiseEst_exp*/ move32(); - msNoiseEst[58] = L_min( msNoiseEst[60], msNoiseEst[61] ); + msNoiseEst[58] = L_min( msNoiseEst[60], msNoiseEst[61] ); /*Q31 - hFdCngDec->msNoiseEst_exp*/ move32(); - msNoiseEst[59] = 0; + msNoiseEst[59] = 0; /*Q31 - hFdCngDec->msNoiseEst_exp*/ move32(); - msNoiseEst[60] = 0; + msNoiseEst[60] = 0; /*Q31 - hFdCngDec->msNoiseEst_exp*/ move32(); - msNoiseEst[61] = 0; + msNoiseEst[61] = 0; /*Q31 - hFdCngDec->msNoiseEst_exp*/ move32(); hFdCngDec->ms_cnt_bw_up = FIRST_CNA_NOISE_UPD_FRAMES; @@ -2773,15 +2773,15 @@ void perform_noise_estimation_dec_ivas_fx( /* background noise update with moving average */ IF( hFdCngDec->first_cna_noise_update_cnt != 0 ) { - alpha = Inv16( add( hFdCngDec->first_cna_noise_update_cnt, 1 ), &e ); - alpha = shl_sat( alpha, e ); // Q15 + alpha = Inv16( add( hFdCngDec->first_cna_noise_update_cnt, 1 ), &e ); /*Q15*/ + alpha = shl_sat( alpha, e ); // Q15 maximum_32_fx( msPeriodog, npart, &max_l ); q_shift = sub( hFdCngDec->hFdCngCom->periodog_exp, hFdCngDec->msNoiseEst_exp ); norm_shift = norm_l( max_l ); test(); IF( max_l && GT_16( q_shift, norm_shift ) ) { - scale_sig32( msNoiseEst, NPART_SHAPING, sub( norm_shift, q_shift ) ); + scale_sig32( msNoiseEst, NPART_SHAPING, sub( norm_shift, q_shift ) ); /*Q31 - hFdCngDec->msNoiseEst_exp + ( norm_shift - q_shift )*/ hFdCngDec->msNoiseEst_exp = sub( hFdCngDec->msNoiseEst_exp, sub( norm_shift, q_shift ) ); move16(); q_shift = norm_shift; @@ -2791,7 +2791,7 @@ void perform_noise_estimation_dec_ivas_fx( { temp = L_shl( msPeriodog[p], q_shift ); #ifdef IVAS_ENH32_CADENCE_CHANGES - msNoiseEst[p] = Madd_32_16( Mpy_32_16_1( msNoiseEst[p], sub( MAX_16, alpha ) ), temp, alpha ); + msNoiseEst[p] = Madd_32_16( Mpy_32_16_1( msNoiseEst[p], sub( MAX_16, alpha ) ), temp, alpha ); /*Q31 - hFdCngDec->msNoiseEst_exp*/ #else msNoiseEst[p] = L_add( Mpy_32_16_1( msNoiseEst[p], sub( MAX_16, alpha ) ), Mpy_32_16_1( temp, alpha ) ); #endif @@ -2801,8 +2801,8 @@ void perform_noise_estimation_dec_ivas_fx( ELSE { Word16 tmp = s_max( sub( hFdCngDec->msPeriodog_exp, getScaleFactor32( msPeriodog, npart ) ), sub( hFdCngDec->msNoiseEst_exp, getScaleFactor32( &msNoiseEst[npart], sub( NPART_SHAPING, npart ) ) ) ); - Copy_Scale_sig32( msPeriodog, msNoiseEst, npart, sub( hFdCngDec->msPeriodog_exp, tmp ) ); - scale_sig32( &msNoiseEst[npart], sub( NPART_SHAPING, npart ), sub( hFdCngDec->msNoiseEst_exp, tmp ) ); + Copy_Scale_sig32( msPeriodog, msNoiseEst, npart, sub( hFdCngDec->msPeriodog_exp, tmp ) ); /*Q31 - tmp*/ + scale_sig32( &msNoiseEst[npart], sub( NPART_SHAPING, npart ), sub( hFdCngDec->msNoiseEst_exp, tmp ) ); /*Q31 - tmp*/ hFdCngDec->msNoiseEst_exp = tmp; move16(); } @@ -2810,7 +2810,7 @@ void perform_noise_estimation_dec_ivas_fx( /* check, if we reached the required number of first CNA noise update frames */ IF( LT_16( hFdCngDec->first_cna_noise_update_cnt, FIRST_CNA_NOISE_UPD_FRAMES - 1 ) ) { - hFdCngDec->first_cna_noise_update_cnt = add( hFdCngDec->first_cna_noise_update_cnt, 1 ); + hFdCngDec->first_cna_noise_update_cnt = add( hFdCngDec->first_cna_noise_update_cnt, 1 ); /*Q0*/ move16(); } ELSE @@ -2838,10 +2838,10 @@ void perform_noise_estimation_dec_ivas_fx( { Word16 scale; /* no updates during active frames except for significant energy drops */ - enr_ratio = BASOP_Util_Divide3232_Scale( enr_tot, enr_tot0, &scale ); + enr_ratio = BASOP_Util_Divide3232_Scale( enr_tot, enr_tot0, &scale ); /*Q15 - scale*/ IF( scale <= 0 ) { - enr_ratio = shl( enr_ratio, scale ); + enr_ratio = shl( enr_ratio, scale ); /*Q15*/ scale = 15; move16(); } @@ -2852,7 +2852,7 @@ void perform_noise_estimation_dec_ivas_fx( IF( LT_16( enr_ratio, shl( 1, sub( scale, 1 ) ) ) ) { /* total energy significantly decreases during active frames -> downward update */ - wght = lin_interp_fx( enr_ratio, 0, shr( 26214, sub( 15, scale ) ) /*0.8f in Q15*/, shr( 16384, sub( 15, scale ) ) /*0.5f in Q15*/, shr( 31130, sub( 15, scale ) ) /*0.95f in Q15*/, shr( 32767, sub( 15, scale ) ) /*1 in Q15*/ ); + wght = lin_interp_fx( enr_ratio, 0, shr( 26214, sub( 15, scale ) ) /*0.8f in Q15*/, shr( 16384, sub( 15, scale ) ) /*0.5f in Q15*/, shr( 31130, sub( 15, scale ) ) /*0.95f in Q15*/, shr( 32767, sub( 15, scale ) ) /*1 in Q15*/ ); /*scale*/ Word16 temp_q_msNoiseEst[NPART_SHAPING]; Word16 min_q_msNoiseEst = MAX_16; move16(); @@ -2867,7 +2867,7 @@ void perform_noise_estimation_dec_ivas_fx( IF( LT_32( L_tmp, msNoiseEst[p] ) ) { #ifdef IVAS_ENH32_CADENCE_CHANGES - msNoiseEst[p] = Madd_32_16( Mpy_32_16_1( msNoiseEst[p], wght ), L_tmp, (Word16) L_sub( shr( MAX_16, sub( 15, scale ) ), wght ) ); + msNoiseEst[p] = Madd_32_16( Mpy_32_16_1( msNoiseEst[p], wght ), L_tmp, (Word16) L_sub( shr( MAX_16, sub( 15, scale ) ), wght ) ); /*temp_q_msNoiseEst[p]*/ #else msNoiseEst[p] = L_add( Mpy_32_16_1( msNoiseEst[p], wght ), Mpy_32_16_1( L_tmp, (Word16) L_sub( shr( MAX_16, sub( 15, scale ) ), wght ) ) ); #endif @@ -2879,7 +2879,7 @@ void perform_noise_estimation_dec_ivas_fx( } FOR( p = 0; p < NPART_SHAPING; p++ ) { - msNoiseEst[p] = L_shl( msNoiseEst[p], sub( min_q_msNoiseEst, temp_q_msNoiseEst[p] ) ); + msNoiseEst[p] = L_shl( msNoiseEst[p], sub( min_q_msNoiseEst, temp_q_msNoiseEst[p] ) ); /*min_q_msNoiseEst*/ move32(); } hFdCngDec->msNoiseEst_exp = min_q_msNoiseEst; @@ -2890,11 +2890,11 @@ void perform_noise_estimation_dec_ivas_fx( /* energy significantly decreases in one of the larger partitions during active frames -> downward update */ FOR( p = CNA_ACT_DN_LARGE_PARTITION; p < npart; p++ ) { - L_tmp = L_shr_sat( hFdCngDec->msPeriodog_ST_fx[p], sub( hFdCngDec->msNoiseEst_exp, hFdCngDec->msPeriodog_ST_exp ) ); + L_tmp = L_shr_sat( hFdCngDec->msPeriodog_ST_fx[p], sub( hFdCngDec->msNoiseEst_exp, hFdCngDec->msPeriodog_ST_exp ) ); /*Q31 - hFdCngDec->msPeriodog_ST_exp*/ IF( LT_32( L_tmp, msNoiseEst[p] ) ) { #ifdef IVAS_ENH32_CADENCE_CHANGES - msNoiseEst[p] = Madd_32_16( Mpy_32_16_1( msNoiseEst[p], CNA_ACT_DN_FACT_Q15 ), L_tmp, ONE_IN_Q15 - CNA_ACT_DN_FACT_Q15 ); + msNoiseEst[p] = Madd_32_16( Mpy_32_16_1( msNoiseEst[p], CNA_ACT_DN_FACT_Q15 ), L_tmp, ONE_IN_Q15 - CNA_ACT_DN_FACT_Q15 ); /*Q31 - hFdCngDec->msNoiseEst_exp*/ #else msNoiseEst[p] = L_add( Mpy_32_16_1( msNoiseEst[p], CNA_ACT_DN_FACT_Q15 ), Mpy_32_16_1( L_tmp, ONE_IN_Q15 - CNA_ACT_DN_FACT_Q15 ) ); #endif @@ -2915,12 +2915,12 @@ void perform_noise_estimation_dec_ivas_fx( hFdCngDec->ms_last_inactive_bwidth = bwidth; move16(); /* update background noise during inactive frames */ - ptr_per = msNoiseEst; + ptr_per = msNoiseEst; /*Q31 - hFdCngDec->msNoiseEst_exp*/ FOR( p = 0; p < npart; p++ ) { Word16 i_e = 15; move16(); - enr = msPeriodog[p]; + enr = msPeriodog[p]; /*Q31 - hFdCngDec->msPeriodog_exp*/ move32(); enr_e = hFdCngDec->msPeriodog_exp; move16(); @@ -2930,7 +2930,7 @@ void perform_noise_estimation_dec_ivas_fx( test(); IF( GT_16( hFdCngDec->ms_cnt_bw_up, 0 ) && GT_16( p, 55 ) ) { - alpha = Inv16( add( hFdCngDec->ms_cnt_bw_up, 1 ), &i_e ); + alpha = Inv16( add( hFdCngDec->ms_cnt_bw_up, 1 ), &i_e ); /*Q15 - i_e*/ IF( i_e < 0 ) { alpha = shr( alpha, negate( i_e ) ); // Q15 @@ -2948,14 +2948,14 @@ void perform_noise_estimation_dec_ivas_fx( test(); IF( ( norm_l( *ptr_per ) == 0 ) && *ptr_per ) { - enr = *ptr_per; + enr = *ptr_per; /*Q31 - hFdCngDec->msNoiseEst_exp*/ scale_sig32( msNoiseEst, NPART_SHAPING, -1 ); hFdCngDec->msNoiseEst_exp = add( hFdCngDec->msNoiseEst_exp, 1 ); move16(); } ELSE { - enr = L_shl( *ptr_per, 1 ); + enr = L_shl( *ptr_per, 1 ); /*Q31 - hFdCngDec->msNoiseEst_exp*/ } enr_e = hFdCngDec->msNoiseEst_exp; move16(); @@ -2965,7 +2965,7 @@ void perform_noise_estimation_dec_ivas_fx( test(); IF( *ptr_per != 0 && alpha != 0 ) { - *ptr_per = Mpy_32_16_1( ( *ptr_per ), alpha ); + *ptr_per = Mpy_32_16_1( ( *ptr_per ), alpha ); /*Q31 - hFdCngDec->msNoiseEst_exp*/ move32(); if ( *ptr_per == 0 ) { @@ -2985,19 +2985,19 @@ void perform_noise_estimation_dec_ivas_fx( norm_shift = norm_l( enr ); IF( LE_16( q_shift, norm_shift ) ) { - enr = L_shl( enr, q_shift ); + enr = L_shl( enr, q_shift ); /*Q31 - hFdCngDec->msNoiseEst_exp + q_shift*/ move32(); } ELSE { enr_e = sub( enr_e, norm_shift ); - enr = L_shl( enr, norm_shift ); - scale_sig32( msNoiseEst, NPART_SHAPING, sub( norm_shift, q_shift ) ); + enr = L_shl( enr, norm_shift ); /*Q31 - hFdCngDec->msNoiseEst_exp + norm_shift*/ + scale_sig32( msNoiseEst, NPART_SHAPING, sub( norm_shift, q_shift ) ); /*Q31 - ( hFdCngDec->msNoiseEst_exp - ( norm_shift - q_shift ) )*/ hFdCngDec->msNoiseEst_exp = sub( hFdCngDec->msNoiseEst_exp, sub( norm_shift, q_shift ) ); move16(); } } - *ptr_per = Madd_32_16( ( *ptr_per ), enr, sub( MAX_16, alpha ) ); + *ptr_per = Madd_32_16( ( *ptr_per ), enr, sub( MAX_16, alpha ) ); /*Q31 - enr_e*/ move32(); #else *ptr_per = L_add( ( *ptr_per ), Mpy_32_16_1( enr, sub( MAX_16, alpha ) ) ); @@ -3016,12 +3016,12 @@ void perform_noise_estimation_dec_ivas_fx( IF( max_l ) { q_shift = sub( norm_l( max_l ), 2 ); - scale_sig32( msNoiseEst, NPART_SHAPING, q_shift ); + scale_sig32( msNoiseEst, NPART_SHAPING, q_shift ); /*Q31 - ( hFdCngDec->msNoiseEst_exp - q_shift )*/ hFdCngDec->msNoiseEst_exp = sub( hFdCngDec->msNoiseEst_exp, q_shift ); move16(); } - Copy32( msNoiseEst, hFdCngDec->msPsd_fx, npart ); + Copy32( msNoiseEst, hFdCngDec->msPsd_fx, npart ); /*Q31 - ( hFdCngDec->msNoiseEst_exp )*/ hFdCngDec->msPsd_exp_fft = hFdCngDec->msNoiseEst_exp; move16(); @@ -3029,7 +3029,7 @@ void perform_noise_estimation_dec_ivas_fx( scalebands_fx( msNoiseEst, part, nFFTpart, hFdCngDec->midband_shaping, nFFTpart, sub( stopFFTbin, startBand ), hFdCngDec->bandNoiseShape, 1 ); hFdCngDec->bandNoiseShape_exp = hFdCngDec->msNoiseEst_exp; move16(); - Copy32( hFdCngDec->bandNoiseShape, &hFdCngDec->smoothed_psd_fx[startBand], sub( stopFFTbin, startBand ) ); + Copy32( hFdCngDec->bandNoiseShape, &hFdCngDec->smoothed_psd_fx[startBand], sub( stopFFTbin, startBand ) ); /*Q31 - hFdCngDec->bandNoiseShape_exp*/ hFdCngDec->smoothed_psd_exp = hFdCngDec->bandNoiseShape_exp; move16(); set32_fx( &hFdCngDec->smoothed_psd_fx[stopFFTbin], 0, sub( L_FRAME16k, stopFFTbin ) ); @@ -3040,7 +3040,7 @@ void perform_noise_estimation_dec_ivas_fx( IF( EQ_16( element_mode, IVAS_CPE_MDCT ) && power_spectrum != NULL ) { /* use power spectrum calculated in the MDCT-domain instead of calculating new power spectrum */ - periodog = power_spectrum; + periodog = power_spectrum; /*Q_power_spectrum*/ periodog_exp = sub( 31, Q_power_spectrum ); } ELSE @@ -3048,20 +3048,20 @@ void perform_noise_estimation_dec_ivas_fx( /* Compute the squared magnitude in each FFT bin */ IF( startBand == 0 ) { - W_tmp = W_mult0_32_32( fftBuffer[0], fftBuffer[0] ); /* DC component */ + W_tmp = W_mult0_32_32( fftBuffer[0], fftBuffer[0] ); /* DC component */ /*Q31 - 2*fftBuffer_exp*/ min_q = 2; move16(); ( *ptr_per ) = W_extract_l( W_shr( W_tmp, sub( i_mult( sub( 31, fftBuffer_exp ), 2 ), min_q ) ) ); move32(); ptr_per++; - ptr_r = fftBuffer + 2; + ptr_r = fftBuffer + 2; /*Q31 - fftBuffer_exp*/ } ELSE { - ptr_r = fftBuffer + i_mult( 2, startBand ); + ptr_r = fftBuffer + i_mult( 2, startBand ); /*Q31 - fftBuffer_exp*/ } - ptr_i = ptr_r + 1; + ptr_i = ptr_r + 1; /*Q31 - fftBuffer_exp*/ SWITCH( hFdCngDec->hFdCngCom->fftlen ) { @@ -3083,17 +3083,17 @@ void perform_noise_estimation_dec_ivas_fx( FOR( ; ptr_per < periodog + stopFFTbin - startBand; ptr_per++ ) { - W_tmp = W_add( W_mult0_32_32( ( *ptr_r ), ( *ptr_r ) ), W_mult0_32_32( ( *ptr_i ), ( *ptr_i ) ) ); + W_tmp = W_add( W_mult0_32_32( ( *ptr_r ), ( *ptr_r ) ), W_mult0_32_32( ( *ptr_i ), ( *ptr_i ) ) ); /*Q31 - 2*(fftBuffer_exp)*/ - tmp_s = W_norm( W_tmp ); + tmp_s = W_norm( W_tmp ); /*tmp_q*/ tmp_q = sub( add( i_mult( sub( 31, fftBuffer_exp ), 2 ), tmp_s ), 32 ); IF( tmp_q < 0 ) { - W_tmp = W_shr( W_tmp, negate( tmp_q ) ); + W_tmp = W_shr( W_tmp, negate( tmp_q ) ); /*Q31 - 2*(fftBuffer_exp) + tmp_q*/ } IF( LT_16( tmp_q, min_q ) ) { - reIter = ptr_per; + reIter = ptr_per; /*tmp_q*/ Word16 diff; IF( ( tmp_q <= 0 ) ) { @@ -3107,7 +3107,7 @@ void perform_noise_estimation_dec_ivas_fx( WHILE( reIter > periodog ) { reIter--; - *reIter = L_shr( *reIter, diff ); + *reIter = L_shr( *reIter, diff ); /*tmp_q*/ move32(); } IF( tmp_q >= 0 ) @@ -3150,7 +3150,7 @@ void perform_noise_estimation_dec_ivas_fx( move16(); FOR( p = 0; p < stopFFTbin - startBand; p++ ) { - periodog[p] = L_shl( periodog[p], tmp_s ); + periodog[p] = L_shl( periodog[p], tmp_s ); /*Q31 - hFdCngDec->hFdCngCom->periodog_exp + tmp_s*/ move32(); } } @@ -3245,24 +3245,24 @@ void FdCng_decodeSID_fx( HANDLE_FD_CNG_COM st, Decoder_State *corest ) invTrfMatrix_fx = (Word32 *) tmpRAM_fx; - sidNoiseEst = st->sidNoiseEst; + sidNoiseEst = st->sidNoiseEst; /*Q31 - st->sidNoiseEstExp*/ move16(); - preemph_fac = corest->preemph_fac; + preemph_fac = corest->preemph_fac; /*Q15*/ move16(); - N = st->npart; + N = st->npart; /*Q0*/ move16(); - st->sid_frame_counter = add( st->sid_frame_counter, 1 ); + st->sid_frame_counter = add( st->sid_frame_counter, 1 ); /*Q15*/ move16(); /* Read bitstream */ FOR( i = 0; i < stages_37bits; i++ ) { - indices[i] = get_next_indice_fx( corest, bits_37bits[i] ); + indices[i] = get_next_indice_fx( corest, bits_37bits[i] ); /*Q0*/ move16(); } - index = get_next_indice_fx( corest, 7 ); + index = get_next_indice_fx( corest, 7 ); /*Q0*/ /* MSVQ decoder */ IF( corest->element_mode != EVS_MONO ) @@ -3282,7 +3282,7 @@ void FdCng_decodeSID_fx( HANDLE_FD_CNG_COM st, Decoder_State *corest ) FOR( i = 0; i < N; i++ ) { - v[i] = L_deposit_h( v16[i] ); + v[i] = L_deposit_h( v16[i] ); /*Q23*/ move32(); } } @@ -3290,8 +3290,8 @@ void FdCng_decodeSID_fx( HANDLE_FD_CNG_COM st, Decoder_State *corest ) /* decode gain, format gain: Q9.23 */ gain = L_shl( L_deposit_l( index ), WORD32_BITS - 1 - 8 ); - gain = L_sub( gain, 503316480l /*60.0 Q23*/ ); - gain = Mpy_32_16_1( gain, 21845 /*2.0f/3.0f Q15*/ ); + gain = L_sub( gain, 503316480l /*60.0 Q23*/ ); /*Q23*/ + gain = Mpy_32_16_1( gain, 21845 /*2.0f/3.0f Q15*/ ); /*Q23*/ /* Apply gain and undo log */ @@ -3300,11 +3300,11 @@ void FdCng_decodeSID_fx( HANDLE_FD_CNG_COM st, Decoder_State *corest ) maxVal = L_add( 0x80000000 /*-1.0 Q31*/, 0 ); FOR( i = 0; i < N; i++ ) { - maxVal = L_max( maxVal, v[i] ); + maxVal = L_max( maxVal, v[i] ); /*Q23*/ } - maxVal = L_add( maxVal, gain ); - maxVal = L_shl( Mpy_32_16_1( maxVal, 21771 /*0.66438561897 Q15*/ ), 1 ); + maxVal = L_add( maxVal, gain ); /*Q23*/ + maxVal = L_shl( Mpy_32_16_1( maxVal, 21771 /*0.66438561897 Q15*/ ), 1 ); /*Q23*/ sidNoiseEst_Exp = 0; move16(); @@ -3319,25 +3319,25 @@ void FdCng_decodeSID_fx( HANDLE_FD_CNG_COM st, Decoder_State *corest ) /* format v: Q9.23, format sidNoiseEst: Q6.26, 0.66438561897 = log10(10)/log10(2.0) / 10.0 * 2.0 */ FOR( i = 0; i < N; i++ ) { - tmp = L_add( v[i], gain ); - tmp = L_shl( Mpy_32_16_1( tmp, 21771 /*0.66438561897 Q15*/ ), 1 ); + tmp = L_add( v[i], gain ); /*Q23*/ + tmp = L_shl( Mpy_32_16_1( tmp, 21771 /*0.66438561897 Q15*/ ), 1 ); /*Q23*/ tmp = L_sub( tmp, E_ExpLd64 ); assert( tmp < 0 ); - st->sidNoiseEst[i] = BASOP_Util_InvLog2( tmp ); + st->sidNoiseEst[i] = BASOP_Util_InvLog2( tmp ); /*Q31 - st->sidNoiseEstExp*/ move32(); } /* NB last band energy compensation */ IF( st->CngBandwidth == NB ) { - st->sidNoiseEst[sub( N, 1 )] = Mpy_32_16_1( st->sidNoiseEst[sub( N, 1 )], NB_LAST_BAND_SCALE ); + st->sidNoiseEst[( N - 1 )] = Mpy_32_16_1( st->sidNoiseEst[( N - 1 )], NB_LAST_BAND_SCALE ); /*Q31 - st->sidNoiseEstExp*/ move32(); } test(); IF( EQ_16( st->CngBandwidth, SWB ) && LE_32( st->CngBitrate, ACELP_13k20 ) ) { - st->sidNoiseEst[sub( N, 1 )] = Mpy_32_16_1( st->sidNoiseEst[sub( N, 1 )], SWB_13k2_LAST_BAND_SCALE ); + st->sidNoiseEst[( N - 1 )] = Mpy_32_16_1( st->sidNoiseEst[( N - 1 )], SWB_13k2_LAST_BAND_SCALE ); /*Q31 - st->sidNoiseEstExp*/ move32(); } @@ -3374,8 +3374,8 @@ void FdCng_decodeSID_fx( HANDLE_FD_CNG_COM st, Decoder_State *corest ) #ifdef IVAS_FLOAT_FIXED void noisy_speech_detection_fx( HANDLE_FD_CNG_DEC hFdCngDec, /* i/o: FD_CNG structure */ - const Word16 vad, - const Word16 *syn, /* i : input time-domain frame */ + const Word16 vad, /*Q0*/ + const Word16 *syn, /* i : input time-domain frame Q*/ const Word16 Q ) { Word16 i; @@ -3392,7 +3392,7 @@ void noisy_speech_detection_fx( IF( vad == 0 ) { - totalNoise = dotWord32_16_Mant32Exp( hFdCngDec->msNoiseEst, hFdCngDec->msNoiseEst_exp, hFdCngDec->psize_shaping_norm, hFdCngDec->psize_shaping_norm_exp, hFdCngDec->nFFTpart_shaping, &totalNoise_exp ); + totalNoise = dotWord32_16_Mant32Exp( hFdCngDec->msNoiseEst, hFdCngDec->msNoiseEst_exp, hFdCngDec->psize_shaping_norm, hFdCngDec->psize_shaping_norm_exp, hFdCngDec->nFFTpart_shaping, &totalNoise_exp ); /*Q31 - totalNoise_exp*/ /* - logTotalNoise is scaled by LD_DATA_SCALE+2 @@ -3402,16 +3402,16 @@ void noisy_speech_detection_fx( */ IF( totalNoise == 0 ) { - logTotalNoise = L_add( -1677721600l /*-0.78125 Q31*/, 0 ); + logTotalNoise = L_add( -1677721600l /*-0.78125 Q31*/, 0 ); /*Q31*/ } ELSE { - logTotalNoise = BASOP_Util_Log2( totalNoise ); + logTotalNoise = BASOP_Util_Log2( totalNoise ); /*Q25*/ logTotalNoiseExp = L_shl( L_deposit_l( totalNoise_exp ), WORD32_BITS - 1 - LD_DATA_SCALE ); - logTotalNoise = Mpy_32_16_1( L_add( logTotalNoise, logTotalNoiseExp ), 24660 /*0.75257498916 Q15*/ ); + logTotalNoise = Mpy_32_16_1( L_add( logTotalNoise, logTotalNoiseExp ), 24660 /*0.75257498916 Q15*/ ); /*Q31 - logTotalNoiseExp*/ } - hFdCngDec->lp_noise = L_add( Mpy_32_16_1( hFdCngDec->lp_noise, 32604 /*0.995 Q15*/ ), L_shr( Mpy_32_16_1( logTotalNoise, 20972 /*0.64 Q15*/ ), 7 ) ); + hFdCngDec->lp_noise = L_add( Mpy_32_16_1( hFdCngDec->lp_noise, 32604 /*0.995 Q15*/ ), L_shr( Mpy_32_16_1( logTotalNoise, 20972 /*0.64 Q15*/ ), 7 ) ); /*hFdCngDec->q_lp_noise*/ move32(); } ELSE @@ -3422,11 +3422,11 @@ void noisy_speech_detection_fx( move16(); FOR( i = 0; i < hFdCngDec->hFdCngCom->frameSize; i++ ) { - tmp = L_shr_r( L_mult0( syn[i], syn[i] ), sub( Etot_exp, 31 ) ); + tmp = L_shr_r( L_mult0( syn[i], syn[i] ), sub( Etot_exp, 31 ) ); /*2*(Q) - (Etot_exp - 31)*/ IF( LT_32( L_sub( maxWord32, tmp ), Etot ) ) { Etot_exp = add( Etot_exp, 1 ); - Etot = L_shr_r( Etot, 1 ); + Etot = L_shr_r( Etot, 1 ); /*Q31 - Etot_exp*/ tmp = L_shr_r( tmp, 1 ); } Etot = L_add( Etot, tmp ); @@ -3441,32 +3441,32 @@ void noisy_speech_detection_fx( */ IF( Etot == 0 ) { - logEtot = L_add( -1677721600l /*-0.78125 Q31*/, 0 ); + logEtot = L_add( -1677721600l /*-0.78125 Q31*/, 0 ); /*Q31*/ } ELSE { - logEtot = BASOP_Util_Log2( Etot ); + logEtot = BASOP_Util_Log2( Etot ); /*Q25*/ logEtotExp = L_shl( L_deposit_l( Etot_exp ), WORD32_BITS - 1 - LD_DATA_SCALE ); - logEtot = Mpy_32_16_1( L_add( logEtot, logEtotExp ), 24660 /*0.75257498916 Q15*/ ); + logEtot = Mpy_32_16_1( L_add( logEtot, logEtotExp ), 24660 /*0.75257498916 Q15*/ ); /*Q31 - logEtotExp*/ IF( EQ_16( hFdCngDec->hFdCngCom->frameSize, L_FRAME16k ) ) { - logEtot = L_add( logEtot, -184894985l /*-0.086098436822497 Q31*/ ); + logEtot = L_add( logEtot, -184894985l /*-0.086098436822497 Q31*/ ); /*Q31 - logEtotExp*/ } ELSE { - logEtot = L_add( logEtot, -176765584l /*-0.082312889439370 Q31*/ ); + logEtot = L_add( logEtot, -176765584l /*-0.082312889439370 Q31*/ ); /*Q31 - logEtotExp*/ } } - hFdCngDec->lp_speech = L_add( Mpy_32_16_1( hFdCngDec->lp_speech, 32604 /*0.995 Q15*/ ), L_shr( Mpy_32_16_1( logEtot, 20972 /*0.64 Q15*/ ), 7 ) ); + hFdCngDec->lp_speech = L_add( Mpy_32_16_1( hFdCngDec->lp_speech, 32604 /*0.995 Q15*/ ), L_shr( Mpy_32_16_1( logEtot, 20972 /*0.64 Q15*/ ), 7 ) ); /*hFdCngDec->q_lp_speech*/ move32(); } - tmp = L_sub( hFdCngDec->lp_speech, 377487360l /*45.0 Q23*/ ); + tmp = L_sub( hFdCngDec->lp_speech, 377487360l /*45.0 Q23*/ ); /*Q23*/ if ( LT_32( hFdCngDec->lp_noise, tmp ) ) { - hFdCngDec->lp_noise = tmp; + hFdCngDec->lp_noise = tmp; /*Q23*/ move32(); } @@ -3485,13 +3485,13 @@ void noisy_speech_detection_fx( #ifdef IVAS_FLOAT_FIXED void generate_comfort_noise_dec_fx( - Word32 **bufferReal, /* o : matrix to real part of input bands */ - Word32 **bufferImag, /* o : matrix to imaginary part of input bands */ + Word32 **bufferReal, /* o : matrix to real part of input bands bufferScale*/ + Word32 **bufferImag, /* o : matrix to imaginary part of input bands bufferScale*/ Word16 *bufferScale, /* o : pointer to scalefactor for real and imaginary part of input bands */ Decoder_State *st, Word16 *Q_new, - Word16 gen_exc, - const Word16 nchan_out /* i : number of output channels */ + Word16 gen_exc, /*Q0*/ + const Word16 nchan_out /* i : number of output channels Q0*/ ) { Word16 i, j, s, sc, sn, cnt; @@ -3525,15 +3525,15 @@ void generate_comfort_noise_dec_fx( /* pointer initialization */ - cngNoiseLevel = hFdCngCom->cngNoiseLevel; + cngNoiseLevel = hFdCngCom->cngNoiseLevel; /*Q31 - hFdCngCom->cngNoiseLevelExp*/ cngNoiseLevelExp = hFdCngCom->cngNoiseLevelExp; - ptr_level = cngNoiseLevel; + ptr_level = cngNoiseLevel; /*Q31 - hFdCngCom->cngNoiseLevelExp*/ seed = &( hFdCngCom->seed ); - fftBuffer = hFdCngCom->fftBuffer; + fftBuffer = hFdCngCom->fftBuffer; /*Q31 - hFdCngCom->fftBuffer_exp*/ timeDomainOutput = hFdCngCom->timeDomainBuffer; /* scaleCLDFB: CLDFBinvScalingFactor_EXP + 1 */ - scaleCLDFB = mult( hFdCngCom->invScalingFactor, CLDFB_SCALING ); + scaleCLDFB = mult( hFdCngCom->invScalingFactor, CLDFB_SCALING ); /*CLDFBinvScalingFactor_EXP + 1*/ /* Generate Gaussian random noise in real and imaginary parts of the FFT bins @@ -3557,32 +3557,32 @@ void generate_comfort_noise_dec_fx( /* DC component in FFT */ s = 0; move16(); - sqrtNoiseLevel = Sqrt32( L_shr( *ptr_level, sn ), &s ); + sqrtNoiseLevel = Sqrt32( L_shr( *ptr_level, sn ), &s ); /*Q31 - s*/ - fftBuffer[0] = L_shl( Mpy_32_32( rand_gauss( seed ), sqrtNoiseLevel ), s ); + fftBuffer[0] = L_shl( Mpy_32_32( rand_gauss( seed ), sqrtNoiseLevel ), s ); /*Q31 - hFdCngCom->fftBuffer_exp*/ move32(); /* Nyquist frequency is discarded */ fftBuffer[1] = L_deposit_l( 0 ); ptr_level = ptr_level + 1; - ptr_r = fftBuffer + 2; + ptr_r = fftBuffer + 2; /*Q31 - hFdCngCom->fftBuffer_exp*/ cnt = sub( cnt, 1 ); } ELSE { - startBand2 = shl( hFdCngCom->startBand, 1 ); + startBand2 = shl( hFdCngCom->startBand, 1 ); /*Q0*/ set32_fx( fftBuffer, 0, startBand2 ); - ptr_r = fftBuffer + startBand2; + ptr_r = fftBuffer + startBand2; /*Q31 - hFdCngCom->fftBuffer_exp*/ } sn = add( sn, 1 ); - ptr_i = ptr_r + 1; + ptr_i = ptr_r + 1; /*Q31 - hFdCngCom->fftBuffer_exp*/ FOR( i = 0; i < cnt; i++ ) { s = 0; move16(); - sqrtNoiseLevel = Sqrt32( L_shr( *ptr_level, sn ), &s ); + sqrtNoiseLevel = Sqrt32( L_shr( *ptr_level, sn ), &s ); /*Q31 - s*/ /* Real part in FFT bins */ *ptr_r = L_shl( Mpy_32_32( rand_gauss( seed ), sqrtNoiseLevel ), s ); @@ -3627,16 +3627,16 @@ void generate_comfort_noise_dec_fx( /* calculate the residual signal energy */ /*enr = dotp( hFdCngCom->exc_cng, hFdCngCom->exc_cng, hFdCngCom->frameSize ) / hFdCngCom->frameSize;*/ - Lener = Dot_productSq16HQ( 1, hFdCngCom->exc_cng, st->L_frame, &exp ); - exp = add( sub( shl( sub( 15, *Q_new ), 1 ), 8 ), exp ); /*8 = log2(256)*/ + Lener = Dot_productSq16HQ( 1, hFdCngCom->exc_cng, st->L_frame, &exp ); /*Q31 - exp*/ + exp = add( sub( shl( sub( 15, *Q_new ), 1 ), 8 ), exp ); /*8 = log2(256)*/ /* convert log2 of residual signal energy */ /*(float)log10( enr + 0.1f ) / (float)log10( 2.0f );*/ - Lener = BASOP_Util_Log2( Lener ); + Lener = BASOP_Util_Log2( Lener ); /*Q25*/ Lener = L_add( Lener, L_shl( L_deposit_l( exp ), WORD32_BITS - 1 - LD_DATA_SCALE ) ); /*Q25*/ if ( EQ_16( st->L_frame, L_FRAME16k ) ) { - Lener = L_sub( Lener, 10802114l /*0.3219280949f Q25*/ ); /*log2(320) = 8.3219280949f*/ + Lener = L_sub( Lener, 10802114l /*0.3219280949f Q25*/ ); /*log2(320) = 8.3219280949f Q25*/ } /* decrease the energy in case of WB input */ IF( st->bwidth != NB ) @@ -3646,24 +3646,24 @@ void generate_comfort_noise_dec_fx( IF( st->CNG_mode >= 0 ) { /* Bitrate adapted attenuation */ - att = L_shl( L_deposit_l( ENR_ATT_fx[st->CNG_mode] ), 17 ); + att = L_shl( L_deposit_l( ENR_ATT_fx[st->CNG_mode] ), 17 ); /*Q23*/ } ELSE { /* Use least attenuation for higher bitrates */ - att = L_shl( L_deposit_l( ENR_ATT_fx[4] ), 17 ); + att = L_shl( L_deposit_l( ENR_ATT_fx[4] ), 17 ); /*Q23*/ } } ELSE { - att = 384 << 17; - move16(); /*1.5 Q8<<17=Q25*/ + att = 384 << 17; /*1.5 Q8<<17=Q25*/ + move16(); } - Lener = L_sub( Lener, att ); + Lener = L_sub( Lener, att ); /*Q23*/ } /*st->lp_ener = 0.8f * stcod->lp_ener + 0.2f * pow( 2.0f, enr );*/ - Lener = BASOP_util_Pow2( Lener, 6, &exp ); - Lener = Mult_32_16( Lener, 6554 /*0.2f Q15*/ ); + Lener = BASOP_util_Pow2( Lener, 6, &exp ); /*Q31 - exp*/ + Lener = Mult_32_16( Lener, 6554 /*0.2f Q15*/ ); /*Q31 - exp*/ exp = sub( 25, exp ); Lener = L_shr( Lener, exp ); /*Q6*/ st->lp_ener_fx = L_add( Mult_32_16( st->lp_ener_fx, 26214 /*0.8f Q15*/ ), Lener ); /*Q6*/ @@ -3688,17 +3688,17 @@ void generate_comfort_noise_dec_fx( /* scaleCLDFB: CLDFBinvScalingFactor_EXP + 1 */ s = 0; move16(); - sqrtNoiseLevel = Sqrt32( L_shr( Mpy_32_16_1( *ptr_level, scaleCLDFB ), sn ), &s ); + sqrtNoiseLevel = Sqrt32( L_shr( Mpy_32_16_1( *ptr_level, scaleCLDFB ), sn ), &s ); /*Q31 - s*/ FOR( i = 0; i < hFdCngCom->numSlots; i++ ) { /* Real part in CLDFB band */ - bufferReal[i][j] = L_shl( Mpy_32_32( rand_gauss( seed ), sqrtNoiseLevel ), s ); + bufferReal[i][j] = L_shl( Mpy_32_32( rand_gauss( seed ), sqrtNoiseLevel ), s ); /*bufferScale*/ move32(); /*fprintf(pFile,"%13.10f\n",WORD322FL_SCALE(bufferReal[i][j],sc));*/ /* Imaginary part in CLDFB band */ - bufferImag[i][j] = L_shl( Mpy_32_32( rand_gauss( seed ), sqrtNoiseLevel ), s ); + bufferImag[i][j] = L_shl( Mpy_32_32( rand_gauss( seed ), sqrtNoiseLevel ), s ); /*bufferScale*/ move32(); /*fprintf(pFile,"%13.10f\n",WORD322FL_SCALE(bufferImag[i][j],sc));*/ } @@ -3726,14 +3726,14 @@ void generate_comfort_noise_dec_fx( seed_loc = hFdCngCom->seed; move16(); - N = hFdCngCom->frameSize; + N = hFdCngCom->frameSize; /*Q0*/ move16(); N2 = shr( hFdCngCom->frameSize, 1 ); IF( st->last_core_bfi > ACELP_CORE ) { Word16 left_overlap_mode; - left_overlap_mode = st->hTcxCfg->tcx_last_overlap_mode; + left_overlap_mode = st->hTcxCfg->tcx_last_overlap_mode; /*Q0*/ move16(); if ( EQ_16( left_overlap_mode, ALDO_WINDOW ) ) { @@ -3747,7 +3747,7 @@ void generate_comfort_noise_dec_fx( { FOR( i = 0; i < sub( hFdCngCom->frameSize, NS2SA( st->sr_core, N_ZERO_MDCT_NS ) ); i++ ) { - timeDomainOutput[i] = add( timeDomainOutput[i], shr_r( st->hHQ_core->old_out_LB_fx[i + NS2SA( st->sr_core, N_ZERO_MDCT_NS )], st->hHQ_core->Q_old_wtda_LB ) ); + timeDomainOutput[i] = add( timeDomainOutput[i], shr_r( st->hHQ_core->old_out_LB_fx[i + NS2SA( st->sr_core, N_ZERO_MDCT_NS )], st->hHQ_core->Q_old_wtda_LB ) ); /*st->q_old_outLB_fx*/ move16(); } } @@ -3758,7 +3758,7 @@ void generate_comfort_noise_dec_fx( FOR( i = 0; i < st->hTcxCfg->tcx_mdct_window_length; i++ ) { - timeDomainOutput[i] = add( timeDomainOutput[i], shl( hTcxDec->syn_Overl[i], TCX_IMDCT_HEADROOM ) ); + timeDomainOutput[i] = add( timeDomainOutput[i], shl( hTcxDec->syn_Overl[i], TCX_IMDCT_HEADROOM ) ); /*st->q_old_outLB_fx*/ move16(); } } @@ -3780,12 +3780,12 @@ void generate_comfort_noise_dec_fx( lpcorder = M; move16(); - old_Aq = st->old_Aq_12_8_fx; - old_exc = st->old_exc_fx + sub( L_EXC_MEM_DEC, N2 ); - old_syn_pe = st->mem_syn2_fx; - old_syn = st->syn[lpcorder]; + old_Aq = st->old_Aq_12_8_fx; /*Q12*/ + old_exc = st->old_exc_fx + sub( L_EXC_MEM_DEC, N2 ); /*Q_exc*/ + old_syn_pe = st->mem_syn2_fx; /*Q_syn*/ + old_syn = st->syn[lpcorder]; /*Q_syn*/ move16(); - preemph_fac = st->preemph_fac; + preemph_fac = st->preemph_fac; /*Q15*/ move16(); Q_exc = st->Q_exc; move16(); @@ -3802,16 +3802,16 @@ void generate_comfort_noise_dec_fx( normShiftEM1 = sub( normShiftE, 1 ); normShiftP2 = add( normShiftE, CNG_NORM_RECIPROCAL_RANGE_SHIFT ); - old_exc_ener = L_shr( L_mult( old_exc[0], old_exc[0] ), normShiftP2 ); + old_exc_ener = L_shr( L_mult( old_exc[0], old_exc[0] ), normShiftP2 ); /*2*(Q_exc)+1+normShiftP2*/ FOR( i = 1; i < N2; i++ ) { - old_exc_ener = L_add( old_exc_ener, L_shr( L_mult( old_exc[i], old_exc[i] ), normShiftP2 ) ); + old_exc_ener = L_add( old_exc_ener, L_shr( L_mult( old_exc[i], old_exc[i] ), normShiftP2 ) ); /*2*(Q_exc)+1+normShiftP2*/ } - old_exc_ener = L_shl( Mpy_32_16_1( old_exc_ener, shl( normFacE, normShiftEM1 ) ), 1 ); + old_exc_ener = L_shl( Mpy_32_16_1( old_exc_ener, shl( normFacE, normShiftEM1 ) ), 1 ); /*Q31*/ old_exc_ener_exp = 0; move16(); - old_exc_ener = Sqrt32( old_exc_ener, &old_exc_ener_exp ); + old_exc_ener = Sqrt32( old_exc_ener, &old_exc_ener_exp ); /*Q31 - old_exc_ener_exp*/ old_exc_ener_exp = add( old_exc_ener_exp, ( sub( 15, Q_exc ) ) ); /* shift to be in the range of values supported by getNormReciprocalWord16() */ @@ -3832,14 +3832,14 @@ void generate_comfort_noise_dec_fx( move16(); gain = L_add( gain, L_shr( L_mult( noise[i], noise[i] ), normShiftP2 ) ); } - gain = L_shl( Mpy_32_16_1( gain, shl( normFacG, normShiftGM1 ) ), 1 ); + gain = L_shl( Mpy_32_16_1( gain, shl( normFacG, normShiftGM1 ) ), 1 ); /*Q31 - gain_exp*/ gain_exp = 2 * CNG_RAND_GAUSS_SHIFT; move16(); - gain = ISqrt32( gain, &gain_exp ); + gain = ISqrt32( gain, &gain_exp ); /*Q31 - gain_exp*/ - gain = Mpy_32_32( old_exc_ener, gain ); - gain16 = extract_h( gain ); + gain = Mpy_32_32( old_exc_ener, gain ); /*Q31 - old_exc_ener_exp - gain_exp*/ + gain16 = extract_h( gain ); /*Q15 - old_exc_ener_exp - gain_exp*/ gain_exp = add( old_exc_ener_exp, gain_exp ); noiseExp = add( CNG_RAND_GAUSS_SHIFT, gain_exp ); @@ -3848,7 +3848,7 @@ void generate_comfort_noise_dec_fx( FOR( i = 0; i < N; i++ ) { #ifdef BASOP_NOGLOB - noise[i] = shr_sat( mult( noise[i], gain16 ), s ); + noise[i] = shr_sat( mult( noise[i], gain16 ), s ); /*Q15 - noiseExp*/ #else noise[i] = shr( mult( noise[i], gain16 ), s ); #endif @@ -3861,7 +3861,7 @@ void generate_comfort_noise_dec_fx( FOR( i = 0; i < lpcorder; i++ ) { #ifdef BASOP_NOGLOB - old_syn_pe_tmp[i] = shr_sat( old_syn_pe[i], s ); + old_syn_pe_tmp[i] = shr_sat( old_syn_pe[i], s ); /*Q0*/ #else old_syn_pe_tmp[i] = shr( old_syn_pe[i], s ); #endif @@ -3892,11 +3892,11 @@ void generate_comfort_noise_dec_fx( FOR( i = 0; i < N4; i++ ) { - tmp = mult( noise[i], hFdCngCom->olapWinSyn[i].v.re ); + tmp = mult( noise[i], hFdCngCom->olapWinSyn[i].v.re ); /*Q15 - noiseExp*/ timeDomainOutput[i] = add( timeDomainOutput[i], tmp ); move16(); - tmp = mult( noise[add( i, N4 )], hFdCngCom->olapWinSyn[sub( sub( N4, 1 ), i )].v.im ); - timeDomainOutput[add( i, N4 )] = add( timeDomainOutput[add( i, N4 )], tmp ); + tmp = mult( noise[( i + N4 )], hFdCngCom->olapWinSyn[( ( N4 - 1 ) - i )].v.im ); /*Q15 - noiseExp*/ + timeDomainOutput[( i + N4 )] = add( timeDomainOutput[( i + N4 )], tmp ); move16(); } } @@ -3904,13 +3904,13 @@ void generate_comfort_noise_dec_fx( } void generate_comfort_noise_dec_ivas_fx( - Word32 **bufferReal, /* o : Real part of input bands */ - Word32 **bufferImag, /* o : Imaginary part of input bands */ + Word32 **bufferReal, /* o : Real part of input bands bufferScale*/ + Word32 **bufferImag, /* o : Imaginary part of input bands bufferScale*/ Word16 *bufferScale, /* o : pointer to scalefactor for real and imaginary part of input bands */ Decoder_State *st, /* i/o: decoder state structure */ Word16 *Q_new, - Word16 gen_exc, - const Word16 nchan_out /* i : number of output channels */ + Word16 gen_exc, /*Q0*/ + const Word16 nchan_out /* i : number of output channels Q0*/ ) { Word16 i, j, s; @@ -3927,7 +3927,7 @@ void generate_comfort_noise_dec_ivas_fx( Word16 c1, c2; Word32 tmp1, tmp2; Word16 scaleCldfb; - Word32 *fftBuffer = hFdCngCom->fftBuffer; + Word32 *fftBuffer = hFdCngCom->fftBuffer; /*hFdCngCom->fftBuffer_exp*/ Word16 fftBuffer_exp = hFdCngCom->fftBuffer_exp; Word16 fftBuffer_temp_exp[FFTLEN]; Word16 *timeDomainOutput = hFdCngCom->timeDomainBuffer; @@ -3944,19 +3944,19 @@ void generate_comfort_noise_dec_ivas_fx( hTcxDec = st->hTcxDec; - scaleCldfb = mult( hFdCngCom->invScalingFactor, CLDFB_SCALING ); + scaleCldfb = mult( hFdCngCom->invScalingFactor, CLDFB_SCALING ); /*CLDFBinvScalingFactor_EXP + 1*/ temp = 0; move16(); - c1 = Sqrt16( hFdCngCom->coherence_fx, &temp ); - c1 = shl( c1, temp ); + c1 = Sqrt16( hFdCngCom->coherence_fx, &temp ); /*Q15 - temp*/ + c1 = shl( c1, temp ); /*Q15*/ temp = 0; move16(); - c2 = Sqrt16( sub( MAX_16, hFdCngCom->coherence_fx ), &temp ); - c2 = shl( c2, temp ); + c2 = Sqrt16( sub( MAX_16, hFdCngCom->coherence_fx ), &temp ); /*Q15 - temp*/ + c2 = shl( c2, temp ); /*Q15*/ temp = getScaleFactor32( fftBuffer, FFTLEN ); - scale_sig32( fftBuffer, FFTLEN, temp ); + scale_sig32( fftBuffer, FFTLEN, temp ); /*Q31 - hFdCngCom->fftBuffer_exp + temp*/ fftBuffer_exp = sub( fftBuffer_exp, temp ); hFdCngCom->fftBuffer_exp = fftBuffer_exp; move16(); @@ -3982,7 +3982,7 @@ void generate_comfort_noise_dec_ivas_fx( { rand_gauss_fx( &tmp1, seed, Q15 ); rand_gauss_fx( &tmp2, seed2, Q15 ); - fftBuffer[0] = L_add( Mpy_32_16_1( tmp1, c1 ), Mpy_32_16_1( tmp2, c2 ) ); + fftBuffer[0] = L_add( Mpy_32_16_1( tmp1, c1 ), Mpy_32_16_1( tmp2, c2 ) ); /*Q0*/ move32(); fftBuffer_temp_exp[0] = Q16 + Q15; move16(); @@ -3995,13 +3995,13 @@ void generate_comfort_noise_dec_ivas_fx( } sqrtNoiseLevel_exp = cngNoiseLevel_exp; move16(); - sqrtNoiseLevel = Sqrt32( *ptr_level, &sqrtNoiseLevel_exp ); - fftBuffer[0] = Mpy_32_32( fftBuffer[0], sqrtNoiseLevel ); + sqrtNoiseLevel = Sqrt32( *ptr_level, &sqrtNoiseLevel_exp ); /*Q31 - sqrtNoiseLevel_exp*/ + fftBuffer[0] = Mpy_32_32( fftBuffer[0], sqrtNoiseLevel ); /*Q31 - (sqrtNoiseLevel_exp + fftBuffer_temp_exp[0])*/ move32(); fftBuffer_temp_exp[0] = add( sqrtNoiseLevel_exp, fftBuffer_temp_exp[0] ); move16(); ptr_level++; - ptr_r = fftBuffer + 2; + ptr_r = fftBuffer + 2; /*Q31 - (fftBuffer_temp_exp)*/ idx = 2; } ELSE @@ -4009,11 +4009,11 @@ void generate_comfort_noise_dec_ivas_fx( fftBuffer[0] = 0; move16(); set32_fx( fftBuffer + 2, 0, shl( sub( hFdCngCom->startBand, 1 ), 1 ) ); - ptr_r = fftBuffer + shl( hFdCngCom->startBand, 1 ); - idx = shl( hFdCngCom->startBand, 1 ); + ptr_r = fftBuffer + shl( hFdCngCom->startBand, 1 ); /*Q31 - fftBuffer_exp*/ + idx = shl( hFdCngCom->startBand, 1 ); /*Q0*/ } - ptr_i = ptr_r + 1; + ptr_i = ptr_r + 1; /*Q31 - fftBuffer_exp*/ FOR( ; ptr_level < cngNoiseLevel + sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ); ptr_level++ ) { /* Real part in FFT bins */ @@ -4021,23 +4021,23 @@ void generate_comfort_noise_dec_ivas_fx( test(); IF( EQ_16( st->element_mode, IVAS_CPE_MDCT ) || ( EQ_16( st->element_mode, IVAS_SCE ) && st->cng_ism_flag ) ) { - rand_gauss_fx( &tmp1, seed, Q15 ); - rand_gauss_fx( &tmp2, seed2, Q15 ); - *ptr_r = L_add( Mpy_32_16_1( tmp1, c1 ), Mpy_32_16_1( tmp2, c2 ) ); + rand_gauss_fx( &tmp1, seed, Q15 ); /*Q15*/ + rand_gauss_fx( &tmp2, seed2, Q15 ); /*Q15*/ + *ptr_r = L_add( Mpy_32_16_1( tmp1, c1 ), Mpy_32_16_1( tmp2, c2 ) ); /*Q15*/ move32(); fftBuffer_temp_exp[idx] = Q16; move16(); } ELSE { - rand_gauss_fx( ptr_r, seed, Q15 ); + rand_gauss_fx( ptr_r, seed, Q15 ); /*Q15*/ fftBuffer_temp_exp[idx] = Q16; move16(); } sqrtNoiseLevel_exp = sub( cngNoiseLevel_exp, 1 ); - sqrtNoiseLevel = Sqrt32( *ptr_level, &sqrtNoiseLevel_exp ); - ( *ptr_r ) = Mpy_32_32( ( *ptr_r ), sqrtNoiseLevel ); + sqrtNoiseLevel = Sqrt32( *ptr_level, &sqrtNoiseLevel_exp ); /*Q31 - sqrtNoiseLevel_exp*/ + ( *ptr_r ) = Mpy_32_32( ( *ptr_r ), sqrtNoiseLevel ); /*Q15 - sqrtNoiseLevel_exp*/ move32(); fftBuffer_temp_exp[idx] = add( fftBuffer_temp_exp[idx], sqrtNoiseLevel_exp ); move16(); @@ -4049,22 +4049,22 @@ void generate_comfort_noise_dec_ivas_fx( test(); IF( EQ_16( st->element_mode, IVAS_CPE_MDCT ) || ( EQ_16( st->element_mode, IVAS_SCE ) && st->cng_ism_flag ) ) { - rand_gauss_fx( &tmp1, seed, Q15 ); - rand_gauss_fx( &tmp2, seed2, Q15 ); - *ptr_i = L_add( Mpy_32_16_1( tmp1, c1 ), Mpy_32_16_1( tmp2, c2 ) ); + rand_gauss_fx( &tmp1, seed, Q15 ); /*Q15*/ + rand_gauss_fx( &tmp2, seed2, Q15 ); /*Q15*/ + *ptr_i = L_add( Mpy_32_16_1( tmp1, c1 ), Mpy_32_16_1( tmp2, c2 ) ); /*Q15*/ move32(); fftBuffer_temp_exp[idx] = Q16; move16(); } ELSE { - rand_gauss_fx( ptr_i, seed, Q15 ); + rand_gauss_fx( ptr_i, seed, Q15 ); /*Q15*/ fftBuffer_temp_exp[idx] = Q16; move16(); } sqrtNoiseLevel_exp = sub( cngNoiseLevel_exp, 1 ); - sqrtNoiseLevel = Sqrt32( *ptr_level, &sqrtNoiseLevel_exp ); - ( *ptr_i ) = Mpy_32_32( ( *ptr_i ), sqrtNoiseLevel ); + sqrtNoiseLevel = Sqrt32( *ptr_level, &sqrtNoiseLevel_exp ); /*Q31 - sqrtNoiseLevel_exp*/ + ( *ptr_i ) = Mpy_32_32( ( *ptr_i ), sqrtNoiseLevel ); /*Q15 - sqrtNoiseLevel_exp*/ move32(); fftBuffer_temp_exp[idx] = add( fftBuffer_temp_exp[idx], sqrtNoiseLevel_exp ); move16(); @@ -4097,7 +4097,7 @@ void generate_comfort_noise_dec_ivas_fx( fftBuffer_exp = sub( 31, fftBuffer_exp ); FOR( i = 0; i < FFTLEN; i++ ) { - fftBuffer[i] = L_shr( fftBuffer[i], sub( fftBuffer_exp, fftBuffer_temp_exp[i] ) ); + fftBuffer[i] = L_shr( fftBuffer[i], sub( fftBuffer_exp, fftBuffer_temp_exp[i] ) ); /*Q31 - fftBuffer_temp_exp[i]*/ move32(); } @@ -4119,7 +4119,7 @@ void generate_comfort_noise_dec_ivas_fx( /* Perform STFT synthesis */ SynthesisSTFT_ivas_fx( fftBuffer, fftBuffer_exp, timeDomainOutput, hFdCngCom->olapBufferSynth, hFdCngCom->olapWinSyn, tcx_transition, hFdCngCom, gen_exc, Q_new, st->element_mode, nchan_out ); - scale_sig32( fftBuffer + hFdCngCom->fftlen, sub( FFTLEN, hFdCngCom->fftlen ), sub( fftBuffer_exp, hFdCngCom->fftBuffer_exp ) ); + scale_sig32( fftBuffer + hFdCngCom->fftlen, sub( FFTLEN, hFdCngCom->fftlen ), sub( fftBuffer_exp, hFdCngCom->fftBuffer_exp ) ); /*Q31 - fftBuffer_exp*/ { Word32 Lener, att; @@ -4128,12 +4128,12 @@ void generate_comfort_noise_dec_ivas_fx( /* calculate the residual signal energy */ /*enr = dotp( hFdCngCom->exc_cng, hFdCngCom->exc_cng, hFdCngCom->frameSize ) / hFdCngCom->frameSize;*/ - Lener = Dot_productSq16HQ( 1, hFdCngCom->exc_cng, st->L_frame, &exp ); - exp = add( sub( shl( sub( 15, *Q_new ), 1 ), 8 ), exp ); /*8 = log2(256)*/ + Lener = Dot_productSq16HQ( 1, hFdCngCom->exc_cng, st->L_frame, &exp ); /*Q31 - exp*/ + exp = add( sub( shl( sub( 15, *Q_new ), 1 ), 8 ), exp ); /*8 = log2(256)*/ /* convert log2 of residual signal energy */ /*(float)log10( enr + 0.1f ) / (float)log10( 2.0f );*/ - Lener = BASOP_Util_Log2( Lener ); + Lener = BASOP_Util_Log2( Lener ); /*Q25*/ Lener = L_add( Lener, L_shl( L_deposit_l( exp ), WORD32_BITS - 1 - LD_DATA_SCALE ) ); /*Q25*/ if ( EQ_16( st->L_frame, L_FRAME16k ) ) { @@ -4147,24 +4147,24 @@ void generate_comfort_noise_dec_ivas_fx( IF( st->CNG_mode >= 0 ) { /* Bitrate adapted attenuation */ - att = L_shl( L_deposit_l( ENR_ATT_fx[st->CNG_mode] ), 17 ); + att = L_shl( L_deposit_l( ENR_ATT_fx[st->CNG_mode] ), 17 ); /*Q25*/ } ELSE { /* Use least attenuation for higher bitrates */ - att = L_shl( L_deposit_l( ENR_ATT_fx[4] ), 17 ); + att = L_shl( L_deposit_l( ENR_ATT_fx[4] ), 17 ); /*Q25*/ } } ELSE { - att = 384 << 17; - move16(); /*1.5 Q8<<17=Q25*/ + att = 384 << 17; /*1.5 Q8<<17=Q25*/ + move16(); } Lener = L_sub( Lener, att ); } /*st->lp_ener = 0.8f * stcod->lp_ener + 0.2f * pow( 2.0f, enr );*/ - Lener = BASOP_util_Pow2( Lener, 6, &exp ); - Lener = Mult_32_16( Lener, 6554 /*0.2f Q15*/ ); + Lener = BASOP_util_Pow2( Lener, 6, &exp ); /*Q31 - exp*/ + Lener = Mult_32_16( Lener, 6554 /*0.2f Q15*/ ); /*Q31 - exp*/ exp = sub( 25, exp ); Lener = L_shr( Lener, exp ); /*Q6*/ st->lp_ener_fx = L_add( Mult_32_16( st->lp_ener_fx, 26214 /*0.8f Q15*/ ), Lener ); /*Q6*/ @@ -4184,29 +4184,29 @@ void generate_comfort_noise_dec_ivas_fx( FOR( j = hFdCngCom->numCoreBands; j < hFdCngCom->regularStopBand; j++ ) { sqrtNoiseLevel_exp = add( CLDFBinvScalingFactor_EXP, sub( cngNoiseLevel_exp, 1 ) ); - sqrtNoiseLevel = Sqrt32( Mpy_32_16_1( *ptr_level, scaleCldfb ), &sqrtNoiseLevel_exp ); + sqrtNoiseLevel = Sqrt32( Mpy_32_16_1( *ptr_level, scaleCldfb ), &sqrtNoiseLevel_exp ); /*Q31 - sqrtNoiseLevel_exp*/ FOR( i = 0; i < hFdCngCom->numSlots; i++ ) { /* Real part in CLDFB band */ IF( EQ_16( st->element_mode, IVAS_CPE_MDCT ) || ( EQ_16( st->element_mode, IVAS_SCE ) && st->cng_ism_flag ) ) { - rand_gauss_fx( &tmp1, seed, Q15 ); - rand_gauss_fx( &tmp2, seed2, Q15 ); - bufferReal[i][j] = L_add( Mpy_32_16_1( tmp1, c1 ), Mpy_32_16_1( tmp2, c2 ) ); + rand_gauss_fx( &tmp1, seed, Q15 ); /*Q15*/ + rand_gauss_fx( &tmp2, seed2, Q15 ); /*Q15*/ + bufferReal[i][j] = L_add( Mpy_32_16_1( tmp1, c1 ), Mpy_32_16_1( tmp2, c2 ) ); /*Q15*/ move32(); bufferReal_exp[j] = Q16; move16(); } ELSE { - rand_gauss_fx( &bufferReal[i][j], seed, Q15 ); + rand_gauss_fx( &bufferReal[i][j], seed, Q15 ); /*Q15*/ move32(); bufferReal_exp[j] = Q16; move16(); } - bufferReal[i][j] = Mpy_32_32( bufferReal[i][j], sqrtNoiseLevel ); + bufferReal[i][j] = Mpy_32_32( bufferReal[i][j], sqrtNoiseLevel ); /*Q31 - ( bufferReal_exp[j] + sqrtNoiseLevel_exp )*/ move32(); bufferReal_exp[j] = add( bufferReal_exp[j], sqrtNoiseLevel_exp ); move16(); @@ -4214,20 +4214,20 @@ void generate_comfort_noise_dec_ivas_fx( /* Imaginary part in CLDFB band */ IF( EQ_16( st->element_mode, IVAS_CPE_MDCT ) || ( EQ_16( st->element_mode, IVAS_SCE ) && st->cng_ism_flag ) ) { - rand_gauss_fx( &tmp1, seed, Q15 ); - rand_gauss_fx( &tmp2, seed2, Q15 ); - bufferImag[i][j] = L_add( Mpy_32_16_1( tmp1, c1 ), Mpy_32_16_1( tmp2, c2 ) ); + rand_gauss_fx( &tmp1, seed, Q15 ); /*Q15*/ + rand_gauss_fx( &tmp2, seed2, Q15 ); /*Q15*/ + bufferImag[i][j] = L_add( Mpy_32_16_1( tmp1, c1 ), Mpy_32_16_1( tmp2, c2 ) ); /*Q15*/ move32(); bufferImag_exp[j] = Q16; move16(); } ELSE { - rand_gauss_fx( &bufferImag[i][j], seed, Q15 ); + rand_gauss_fx( &bufferImag[i][j], seed, Q15 ); /*Q15*/ bufferImag_exp[j] = Q16; move16(); } - bufferImag[i][j] = Mpy_32_32( bufferImag[i][j], sqrtNoiseLevel ); + bufferImag[i][j] = Mpy_32_32( bufferImag[i][j], sqrtNoiseLevel ); /*Q31 - ( bufferReal_exp[j] + sqrtNoiseLevel_exp )*/ bufferImag_exp[j] = add( bufferImag_exp[j], sqrtNoiseLevel_exp ); move16(); @@ -4248,9 +4248,9 @@ void generate_comfort_noise_dec_ivas_fx( { FOR( i = 0; i < hFdCngCom->numSlots; i++ ) { - bufferImag[i][j] = L_shr( bufferImag[i][j], sub( *bufferScale, bufferImag_exp[j] ) ); + bufferImag[i][j] = L_shr( bufferImag[i][j], sub( *bufferScale, bufferImag_exp[j] ) ); /*bufferImag_exp*/ move32(); - bufferReal[i][j] = L_shr( bufferReal[i][j], sub( *bufferScale, bufferReal_exp[j] ) ); + bufferReal[i][j] = L_shr( bufferReal[i][j], sub( *bufferScale, bufferReal_exp[j] ) ); /*bufferReal_exp*/ move32(); } } @@ -4271,9 +4271,9 @@ void generate_comfort_noise_dec_ivas_fx( assert( hFdCngCom->frameSize <= 640 ); - seed_loc = hFdCngCom->seed; + seed_loc = hFdCngCom->seed; /*Q0*/ move16(); - N = hFdCngCom->frameSize; + N = hFdCngCom->frameSize; /*Q0*/ move16(); N2 = shr( hFdCngCom->frameSize, 1 ); @@ -4294,7 +4294,7 @@ void generate_comfort_noise_dec_ivas_fx( { FOR( i = 0; i < sub( hFdCngCom->frameSize, NS2SA( st->sr_core, N_ZERO_MDCT_NS ) ); i++ ) { - timeDomainOutput[i] = add( timeDomainOutput[i], shr_r( st->hHQ_core->old_out_LB_fx[i + NS2SA( st->sr_core, N_ZERO_MDCT_NS )], st->hHQ_core->Q_old_wtda_LB ) ); + timeDomainOutput[i] = add( timeDomainOutput[i], shr_r( st->hHQ_core->old_out_LB_fx[i + NS2SA( st->sr_core, N_ZERO_MDCT_NS )], st->hHQ_core->Q_old_wtda_LB ) ); /*st->q_old_outLB_fx*/ move16(); } } @@ -4305,7 +4305,7 @@ void generate_comfort_noise_dec_ivas_fx( FOR( i = 0; i < st->hTcxCfg->tcx_mdct_window_length; i++ ) { - timeDomainOutput[i] = add( timeDomainOutput[i], shl( hTcxDec->syn_Overl[i], TCX_IMDCT_HEADROOM ) ); + timeDomainOutput[i] = add( timeDomainOutput[i], shl( hTcxDec->syn_Overl[i], TCX_IMDCT_HEADROOM ) ); /*st->q_old_outLB_fx*/ move16(); } } @@ -4327,12 +4327,12 @@ void generate_comfort_noise_dec_ivas_fx( lpcorder = M; move16(); - old_Aq = st->old_Aq_12_8_fx; - old_exc = st->old_exc_fx + sub( L_EXC_MEM_DEC, N2 ); - old_syn_pe = st->mem_syn2_fx; - old_syn = st->syn[lpcorder]; + old_Aq = st->old_Aq_12_8_fx; /*Q12*/ + old_exc = st->old_exc_fx + sub( L_EXC_MEM_DEC, N2 ); /*Q_exc*/ + old_syn_pe = st->mem_syn2_fx; /*Q_syn*/ + old_syn = st->syn[lpcorder]; /*Q_syn*/ move16(); - preemph_fac = st->preemph_fac; + preemph_fac = st->preemph_fac; /*Q15*/ move16(); Q_exc = st->Q_exc; move16(); @@ -4349,16 +4349,16 @@ void generate_comfort_noise_dec_ivas_fx( normShiftEM1 = sub( normShiftE, 1 ); normShiftP2 = add( normShiftE, CNG_NORM_RECIPROCAL_RANGE_SHIFT ); - old_exc_ener = L_shr( L_mult( old_exc[0], old_exc[0] ), normShiftP2 ); + old_exc_ener = L_shr( L_mult( old_exc[0], old_exc[0] ), normShiftP2 ); /*2*(Q_exc)+1+normShiftP2*/ FOR( i = 1; i < N2; i++ ) { - old_exc_ener = L_add( old_exc_ener, L_shr( L_mult( old_exc[i], old_exc[i] ), normShiftP2 ) ); + old_exc_ener = L_add( old_exc_ener, L_shr( L_mult( old_exc[i], old_exc[i] ), normShiftP2 ) ); /*2*(Q_exc)+1+normShiftP2*/ } - old_exc_ener = L_shl( Mpy_32_16_1( old_exc_ener, shl( normFacE, normShiftEM1 ) ), 1 ); + old_exc_ener = L_shl( Mpy_32_16_1( old_exc_ener, shl( normFacE, normShiftEM1 ) ), 1 ); /*Q31*/ old_exc_ener_exp = 0; move16(); - old_exc_ener = Sqrt32( old_exc_ener, &old_exc_ener_exp ); + old_exc_ener = Sqrt32( old_exc_ener, &old_exc_ener_exp ); /*Q31 - old_exc_ener_exp*/ old_exc_ener_exp = add( old_exc_ener_exp, ( sub( 15, Q_exc ) ) ); /* shift to be in the range of values supported by getNormReciprocalWord16() */ @@ -4379,14 +4379,14 @@ void generate_comfort_noise_dec_ivas_fx( move16(); gain = L_add( gain, L_shr( L_mult( noise[i], noise[i] ), normShiftP2 ) ); } - gain = L_shl( Mpy_32_16_1( gain, shl( normFacG, normShiftGM1 ) ), 1 ); + gain = L_shl( Mpy_32_16_1( gain, shl( normFacG, normShiftGM1 ) ), 1 ); /*Q31 - gain_exp*/ gain_exp = 2 * CNG_RAND_GAUSS_SHIFT; move16(); - gain = ISqrt32( gain, &gain_exp ); + gain = ISqrt32( gain, &gain_exp ); /*Q31 - gain_exp*/ - gain = Mpy_32_32( old_exc_ener, gain ); - gain16 = extract_h( gain ); + gain = Mpy_32_32( old_exc_ener, gain ); /*Q31 - old_exc_ener_exp - gain_exp*/ + gain16 = extract_h( gain ); /*Q15 - old_exc_ener_exp - gain_exp*/ gain_exp = add( old_exc_ener_exp, gain_exp ); noiseExp = add( CNG_RAND_GAUSS_SHIFT, gain_exp ); @@ -4395,7 +4395,7 @@ void generate_comfort_noise_dec_ivas_fx( FOR( i = 0; i < N; i++ ) { #ifdef BASOP_NOGLOB - noise[i] = shr_sat( mult( noise[i], gain16 ), s ); + noise[i] = shr_sat( mult( noise[i], gain16 ), s ); /*Q15 - noiseExp*/ #else noise[i] = shr( mult( noise[i], gain16 ), s ); #endif @@ -4408,7 +4408,7 @@ void generate_comfort_noise_dec_ivas_fx( FOR( i = 0; i < lpcorder; i++ ) { #ifdef BASOP_NOGLOB - old_syn_pe_tmp[i] = shr_sat( old_syn_pe[i], s ); + old_syn_pe_tmp[i] = shr_sat( old_syn_pe[i], s ); /*Q0*/ #else old_syn_pe_tmp[i] = shr( old_syn_pe[i], s ); #endif @@ -4439,11 +4439,11 @@ void generate_comfort_noise_dec_ivas_fx( FOR( i = 0; i < N4; i++ ) { - tmp = mult( noise[i], hFdCngCom->olapWinSyn[i].v.re ); + tmp = mult( noise[i], hFdCngCom->olapWinSyn[i].v.re ); /*Q15 - noiseExp*/ timeDomainOutput[i] = add( timeDomainOutput[i], tmp ); move16(); - tmp = mult( noise[add( i, N4 )], hFdCngCom->olapWinSyn[sub( sub( N4, 1 ), i )].v.im ); - timeDomainOutput[add( i, N4 )] = add( timeDomainOutput[add( i, N4 )], tmp ); + tmp = mult( noise[( i + N4 )], hFdCngCom->olapWinSyn[( ( N4 - 1 ) - i )].v.im ); /*Q15 - noiseExp*/ + timeDomainOutput[( i + N4 )] = add( timeDomainOutput[( i + N4 )], tmp ); move16(); move16(); } @@ -4453,8 +4453,8 @@ void generate_comfort_noise_dec_ivas_fx( } void generate_comfort_noise_dec_hf_fx( - Word32 **bufferReal, /* o : matrix to real part of input bands */ - Word32 **bufferImag, /* o : matrix to imaginary part of input bands */ + Word32 **bufferReal, /* o : matrix to real part of input bands bufferScale*/ + Word32 **bufferImag, /* o : matrix to imaginary part of input bands bufferScale*/ Word16 *bufferScale, /* o : pointer to scalefactor for real and imaginary part of input bands */ Decoder_State *st ) { @@ -4468,14 +4468,14 @@ void generate_comfort_noise_dec_hf_fx( Word32 *ptr_level; HANDLE_FD_CNG_COM hFdCngCom = st->hFdCngDec->hFdCngCom; - cngNoiseLevel = hFdCngCom->cngNoiseLevel + sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ); + cngNoiseLevel = hFdCngCom->cngNoiseLevel + sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ); /*Q31 - hFdCngCom->cngNoiseLevelExp*/ cngNoiseLevelExp = hFdCngCom->cngNoiseLevelExp; move16(); - ptr_level = cngNoiseLevel; + ptr_level = cngNoiseLevel; /*Q31 - hFdCngCom->cngNoiseLevelExp*/ seed = &( hFdCngCom->seed ); /* scaleCLDFB: CLDFBinvScalingFactor_EXP + 1 */ - scaleCLDFB = mult( hFdCngCom->invScalingFactor, CLDFB_SCALING ); + scaleCLDFB = mult( hFdCngCom->invScalingFactor, CLDFB_SCALING ); /*CLDFBinvScalingFactor_EXP + 1*/ sn = 0; move16(); @@ -4500,21 +4500,21 @@ void generate_comfort_noise_dec_hf_fx( /* scaleCLDFB: CLDFBinvScalingFactor_EXP + 1 */ s = 0; move16(); - sqrtNoiseLevel = Sqrt32( L_shr( Mpy_32_16_1( *ptr_level, scaleCLDFB ), sn ), &s ); + sqrtNoiseLevel = Sqrt32( L_shr( Mpy_32_16_1( *ptr_level, scaleCLDFB ), sn ), &s ); /*Q31 - s*/ FOR( i = 0; i < hFdCngCom->numSlots; i++ ) { /* Real part in CLDFB band */ - bufferReal[i][j] = L_shl( Mpy_32_32( rand_gauss( seed ), sqrtNoiseLevel ), s ); + bufferReal[i][j] = L_shl( Mpy_32_32( rand_gauss( seed ), sqrtNoiseLevel ), s ); /*bufferScale*/ move32(); /*fprintf(pFile,"%13.10f\n",WORD322FL_SCALE(bufferReal[i][j],sc));*/ /* Imaginary part in CLDFB band */ - bufferImag[i][j] = L_shl( Mpy_32_32( rand_gauss( seed ), sqrtNoiseLevel ), s ); + bufferImag[i][j] = L_shl( Mpy_32_32( rand_gauss( seed ), sqrtNoiseLevel ), s ); /*bufferScale*/ move32(); /*fprintf(pFile,"%13.10f\n",WORD322FL_SCALE(bufferImag[i][j],sc));*/ } - ptr_level = ptr_level + 1; + ptr_level = ptr_level + 1; /*Q31 - hFdCngCom->cngNoiseLevelExp*/ } *bufferScale = sub( sc, 15 ); move16(); @@ -4522,11 +4522,11 @@ void generate_comfort_noise_dec_hf_fx( } void generate_comfort_noise_dec_hf_ivas_fx( - Word32 **bufferReal, /* o : matrix to real part of input bands */ - Word32 **bufferImag, /* o : matrix to imaginary part of input bands */ + Word32 **bufferReal, /* o : matrix to real part of input bands bufferScale*/ + Word32 **bufferImag, /* o : matrix to imaginary part of input bands bufferScale*/ Word16 *bufferScale, /* o : pointer to scalefactor for real and imaginary part of input bands */ HANDLE_FD_CNG_COM hFdCngCom, /* i/o: FD_CNG structure containing all buffers and variables */ - const Word16 cng_coh_flag /* i : CNG Flag for coherence handling */ + const Word16 cng_coh_flag /* i : CNG Flag for coherence handling Q0*/ ) { Word16 i, j, s, sc, sn; @@ -4541,15 +4541,15 @@ void generate_comfort_noise_dec_hf_ivas_fx( Word32 *cngNoiseLevel; Word32 tmp1, tmp2; - cngNoiseLevel = hFdCngCom->cngNoiseLevel + sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ); + cngNoiseLevel = hFdCngCom->cngNoiseLevel + sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ); /*Q31 - hFdCngCom->cngNoiseLevelExp*/ cngNoiseLevelExp = hFdCngCom->cngNoiseLevelExp; move16(); - ptr_level = cngNoiseLevel; + ptr_level = cngNoiseLevel; /*Q31 - hFdCngCom->cngNoiseLevelExp*/ seed = &( hFdCngCom->seed ); /* scaleCLDFB: CLDFBinvScalingFactor_EXP + 1 */ - scaleCLDFB = mult( hFdCngCom->invScalingFactor, CLDFB_SCALING ); + scaleCLDFB = mult( hFdCngCom->invScalingFactor, CLDFB_SCALING ); /*CLDFBinvScalingFactor_EXP + 1*/ seed2 = &( hFdCngCom->seed ); @@ -4567,13 +4567,13 @@ void generate_comfort_noise_dec_hf_ivas_fx( s = 0; move16(); - c1 = Sqrt16( hFdCngCom->coherence_fx, &s ); - c1 = shl( c1, s ); // Q15 + c1 = Sqrt16( hFdCngCom->coherence_fx, &s ); /*Q15 - s*/ + c1 = shl( c1, s ); // Q15 s = 0; move16(); - c2 = Sqrt16( sub( MAX16B, hFdCngCom->coherence_fx ), &s ); - c2 = shl( c2, s ); // Q15 + c2 = Sqrt16( sub( MAX16B, hFdCngCom->coherence_fx ), &s ); /*Q15 - s*/ + c2 = shl( c2, s ); // Q15 } sn = 0; @@ -4605,38 +4605,38 @@ void generate_comfort_noise_dec_hf_ivas_fx( /* scaleCLDFB: CLDFBinvScalingFactor_EXP + 1 */ s = 0; move16(); - sqrtNoiseLevel = Sqrt32( L_shr( Mpy_32_16_1( *ptr_level, scaleCLDFB ), sn ), &s ); + sqrtNoiseLevel = Sqrt32( L_shr( Mpy_32_16_1( *ptr_level, scaleCLDFB ), sn ), &s ); /*Q31 - s*/ IF( cng_coh_flag ) { - rand_gauss_fx( &tmp1, seed, Q28 ); - rand_gauss_fx( &tmp2, seed2, Q28 ); + rand_gauss_fx( &tmp1, seed, Q28 ); /*Q28*/ + rand_gauss_fx( &tmp2, seed2, Q28 ); /*Q28*/ - bufferReal[i][j] = L_add( Mpy_32_16_1( tmp1, c1 ), Mpy_32_16_1( tmp2, c2 ) ); + bufferReal[i][j] = L_add( Mpy_32_16_1( tmp1, c1 ), Mpy_32_16_1( tmp2, c2 ) ); /*bufferScale*/ move32(); - bufferReal[i][j] = L_shl( Mpy_32_32( bufferReal[i][j], sqrtNoiseLevel ), s ); + bufferReal[i][j] = L_shl( Mpy_32_32( bufferReal[i][j], sqrtNoiseLevel ), s ); /*bufferScale*/ move32(); - rand_gauss_fx( &tmp1, seed, Q28 ); - rand_gauss_fx( &tmp2, seed2, Q28 ); + rand_gauss_fx( &tmp1, seed, Q28 ); /*Q28*/ + rand_gauss_fx( &tmp2, seed2, Q28 ); /*Q28*/ - bufferImag[i][j] = L_add( Mpy_32_16_1( tmp1, c1 ), Mpy_32_16_1( tmp2, c2 ) ); + bufferImag[i][j] = L_add( Mpy_32_16_1( tmp1, c1 ), Mpy_32_16_1( tmp2, c2 ) ); /*bufferScale*/ move32(); - bufferImag[i][j] = L_shl( Mpy_32_32( bufferImag[i][j], sqrtNoiseLevel ), s ); + bufferImag[i][j] = L_shl( Mpy_32_32( bufferImag[i][j], sqrtNoiseLevel ), s ); /*bufferScale*/ move32(); } ELSE { /* Real part in CLDFB band */ - bufferReal[i][j] = L_shl( Mpy_32_32( L_shr( rand_gauss( seed ), 1 ), sqrtNoiseLevel ), s ); + bufferReal[i][j] = L_shl( Mpy_32_32( L_shr( rand_gauss( seed ), 1 ), sqrtNoiseLevel ), s ); /*bufferScale*/ move32(); /* Imaginary part in CLDFB band */ - bufferImag[i][j] = L_shl( Mpy_32_32( L_shr( rand_gauss( seed ), 1 ), sqrtNoiseLevel ), s ); + bufferImag[i][j] = L_shl( Mpy_32_32( L_shr( rand_gauss( seed ), 1 ), sqrtNoiseLevel ), s ); /*bufferScale*/ move32(); } } - ptr_level = ptr_level + 1; + ptr_level = ptr_level + 1; /*Q31 - hFdCngCom->cngNoiseLevelExp*/ } *bufferScale = sub( sc, 15 ); move16(); @@ -4669,8 +4669,8 @@ void generate_masking_noise_fx( Word16 Q, HANDLE_FD_CNG_COM hFdCngCom /* i/o : pointer to FD_CNG_COM structure */ , - Word16 length, - Word16 core ) + Word16 length, /*Q0*/ + Word16 core /*Q0*/ ) { Word16 i, s, s1, s2, sq, cnt, startBand2, stopFFTbin2; Word16 scaleExp, fftBufferExp, cngNoiseLevelExp; @@ -4684,8 +4684,8 @@ void generate_masking_noise_fx( // PMTE(); /*IVAS CODE need to be added */ /* pointer initializations */ - cngNoiseLevel = hFdCngCom->cngNoiseLevel; - fftBuffer = hFdCngCom->fftBuffer; + cngNoiseLevel = hFdCngCom->cngNoiseLevel; /*Q31 - hFdCngCom->cngNoiseLevelExp*/ + fftBuffer = hFdCngCom->fftBuffer; /*Q31 - hFdCngCom->fftBuffer_exp*/ seed = &( hFdCngCom->seed ); /* Compute additional CN level */ @@ -4707,7 +4707,7 @@ void generate_masking_noise_fx( IF( ( EQ_16( hFdCngCom->CngBandwidth, scaleTable_cn_only[i].bwmode ) ) && ( GE_32( hFdCngCom->CngBitrate, scaleTable_cn_only[i].bitrateFrom ) ) && ( LT_32( hFdCngCom->CngBitrate, scaleTable_cn_only[i].bitrateTo ) ) ) { - scale = scaleTable_cn_only[i].scale; + scale = scaleTable_cn_only[i].scale; /*Q14*/ move16(); BREAK; } @@ -4726,7 +4726,7 @@ void generate_masking_noise_fx( { IF( GE_32( hFdCngCom->CngBitrate, scaleTable_cn_only_amrwbio[i][0] ) ) { - scale = scaleTable_cn_only_amrwbio[i][1]; + scale = scaleTable_cn_only_amrwbio[i][1]; /*Q14*/ move16(); BREAK; } @@ -4740,7 +4740,7 @@ void generate_masking_noise_fx( /* scaleTable_cn_only[i].scale is scaled by 1 bit */ scaleExp = sub( 1, add( s1, s2 ) ); - scale = mult_r( shl( scale, s1 ), shl( hFdCngCom->likelihood_noisy_speech, s2 ) ); + scale = mult_r( shl( scale, s1 ), shl( hFdCngCom->likelihood_noisy_speech, s2 ) ); /*Q15 - scaleExp*/ { /* add exponent of scale and cngNoiseLevel */ @@ -4756,7 +4756,7 @@ void generate_masking_noise_fx( /* consider scaling of random noise */ fftBufferExp = add( fftBufferExp, CNG_RAND_GAUSS_SHIFT ); - cnt = sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ); + cnt = sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ); /*Q0*/ /* Generate Gaussian random noise in real and imaginary parts of the FFT bins Amplitudes are adjusted to the estimated noise level cngNoiseLevel in each bin @@ -4769,8 +4769,8 @@ void generate_masking_noise_fx( /* -s => consider scalefactor adaptation for sqrt calculation */ sq = sub( 0, s ); - sqrtNoiseLevel = Sqrt32( Mpy_32_16_1( *cngNoiseLevel, scale ), &sq ); - hFdCngCom->fftBuffer[0] = L_shl( Mpy_32_32( rand_gauss( seed ), sqrtNoiseLevel ), sq ); + sqrtNoiseLevel = Sqrt32( Mpy_32_16_1( *cngNoiseLevel, scale ), &sq ); /*Q31 - sq*/ + hFdCngCom->fftBuffer[0] = L_shl( Mpy_32_32( rand_gauss( seed ), sqrtNoiseLevel ), sq ); /*q31 - hFdCngCom->fftBuffer_exp*/ move32(); hFdCngCom->fftBuffer[1] = 0; move32(); @@ -4784,26 +4784,26 @@ void generate_masking_noise_fx( { startBand2 = shl( hFdCngCom->startBand, 1 ); set32_fx( hFdCngCom->fftBuffer, 0, startBand2 ); - fftBuffer = hFdCngCom->fftBuffer + startBand2; + fftBuffer = hFdCngCom->fftBuffer + startBand2; /*Q31 - hFdCngCom->fftBuffer_exp*/ } FOR( i = 0; i < cnt; i++ ) { /* -1 => weighting with 0.5, -s => consider scalefactor adaptation for sqrt calculation */ sq = sub( -1, s ); - sqrtNoiseLevel = Sqrt32( Mpy_32_16_1( *cngNoiseLevel, scale ), &sq ); + sqrtNoiseLevel = Sqrt32( Mpy_32_16_1( *cngNoiseLevel, scale ), &sq ); /*Q31 - sq*/ /* real part in FFT bins */ /* random noise is scaled by CNG_RAND_GAUSS_SHIFT bits */ - *fftBuffer = L_shl( Mpy_32_32( rand_gauss( seed ), sqrtNoiseLevel ), sq ); + *fftBuffer = L_shl( Mpy_32_32( rand_gauss( seed ), sqrtNoiseLevel ), sq ); /*Q31 - hFdCngCom->fftBuffer_exp*/ move32(); fftBuffer++; /* imaginary part in FFT bins */ /* random noise is scaled by CNG_RAND_GAUSS_SHIFT bits */ - *fftBuffer = L_shl( Mpy_32_32( rand_gauss( seed ), sqrtNoiseLevel ), sq ); + *fftBuffer = L_shl( Mpy_32_32( rand_gauss( seed ), sqrtNoiseLevel ), sq ); /*Q31 - hFdCngCom->fftBuffer_exp*/ move32(); fftBuffer++; @@ -4827,7 +4827,7 @@ void generate_masking_noise_fx( { FOR( i = 0; i < length; i++ ) { - timeDomainBuffer[i] = add( timeDomainBuffer[i], shr_r( maskingNoise[i], -Q ) ); + timeDomainBuffer[i] = add( timeDomainBuffer[i], shr_r( maskingNoise[i], -Q ) ); /*Q0*/ move16(); } } @@ -4836,7 +4836,7 @@ void generate_masking_noise_fx( FOR( i = 0; i < hFdCngCom->frameSize; i++ ) { #ifdef BASOP_NOGLOB - timeDomainBuffer[i] = add_sat( timeDomainBuffer[i], shr_r_sat( maskingNoise[i], -Q ) ); + timeDomainBuffer[i] = add_sat( timeDomainBuffer[i], shr_r_sat( maskingNoise[i], -Q ) ); /*Q0*/ #else timeDomainBuffer[i] = add( timeDomainBuffer[i], shr_r( maskingNoise[i], -Q ) ); #endif @@ -4865,18 +4865,18 @@ void generate_masking_noise_update_seed_fx( /* pointer initializations */ seed = &( hFdCngCom->seed ); - cnt = sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ); + cnt = sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ); /*Q0*/ IF( hFdCngCom->startBand == 0 ) { - rand_gauss( seed ); + rand_gauss( seed ); /*Q15*/ cnt = sub( cnt, 1 ); } FOR( i = 0; i < cnt; i++ ) { - rand_gauss( seed ); - rand_gauss( seed ); + rand_gauss( seed ); /*Q15*/ + rand_gauss( seed ); /*Q15*/ } @@ -4889,7 +4889,7 @@ void generate_masking_noise_update_seed_fx( ************************************************************/ #ifdef IVAS_FLOAT_FIXED void generate_masking_noise_mdct_fx( - Word32 *mdctBuffer, /* i/o: time-domain signal */ + Word32 *mdctBuffer, /* i/o: time-domain signal Q31 - mdctBuffer_e*/ Word16 *mdctBuffer_e, /* i/o: exponent time-domain signal */ HANDLE_FD_CNG_COM hFdCngCom /* i/o: FD_CNG structure containing all buffers and variables */ , @@ -4907,7 +4907,7 @@ void generate_masking_noise_mdct_fx( // PMTE(); /*IVAS CODE need to be added */ /* pointer initializations */ - cngNoiseLevel = hFdCngCom->cngNoiseLevel; + cngNoiseLevel = hFdCngCom->cngNoiseLevel; /*Q31 - hFdCngCom->cngNoiseLevelExp*/ seed = &( hFdCngCom->seed ); /* Compute additional CN level */ @@ -4927,7 +4927,7 @@ void generate_masking_noise_mdct_fx( test(); IF( ( EQ_16( hFdCngCom->CngBandwidth, scaleTable_cn_only[i].bwmode ) ) && ( GE_32( hFdCngCom->CngBitrate, scaleTable_cn_only[i].bitrateFrom ) ) && ( LT_32( hFdCngCom->CngBitrate, scaleTable_cn_only[i].bitrateTo ) ) ) { - scale = scaleTable_cn_only[i].scale; + scale = scaleTable_cn_only[i].scale; /*Q14*/ move16(); BREAK; } @@ -4940,7 +4940,7 @@ void generate_masking_noise_mdct_fx( /* scaleTable_cn_only[i].scale is scaled by 1 bit */ scaleExp = sub( 1, add( s1, s2 ) ); - scale = mult_r( shl( scale, s1 ), shl( hFdCngCom->likelihood_noisy_speech, s2 ) ); + scale = mult_r( shl( scale, s1 ), shl( hFdCngCom->likelihood_noisy_speech, s2 ) ); /*Q15 - scaleExp*/ /* add exponent of scale and cngNoiseLevel */ maskingNoiseExp = add( scaleExp, cngNoiseLevelExp ); @@ -4955,7 +4955,7 @@ void generate_masking_noise_mdct_fx( /* consider scaling of random noise */ maskingNoiseExp = add( maskingNoiseExp, CNG_RAND_GAUSS_SHIFT ); - cnt = sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ); + cnt = sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ); /*Q0*/ /* Generate Gaussian random noise in real and imaginary parts of the FFT bins @@ -4969,11 +4969,11 @@ void generate_masking_noise_mdct_fx( /* -1 => weighting with 0.5, -s => consider scalefactor adaptation for sqrt calculation */ sq = sub( -1, s ); - sqrtNoiseLevel = Sqrt32( Mpy_32_16_1( *cngNoiseLevel, scale ), &sq ); - maskingNoise[0] = L_shl( Mpy_32_32( rand_gauss( seed ), sqrtNoiseLevel ), sq ); + sqrtNoiseLevel = Sqrt32( Mpy_32_16_1( *cngNoiseLevel, scale ), &sq ); /*Q31 - sq*/ + maskingNoise[0] = L_shl( Mpy_32_32( rand_gauss( seed ), sqrtNoiseLevel ), sq ); /*Q15*/ move32(); - pMaskingNoise = &maskingNoise[1]; + pMaskingNoise = &maskingNoise[1]; /*Q15*/ cngNoiseLevel++; cnt = sub( cnt, 1 ); @@ -4981,19 +4981,19 @@ void generate_masking_noise_mdct_fx( ELSE { set32_fx( maskingNoise, 0, hFdCngCom->startBand ); - pMaskingNoise = maskingNoise + hFdCngCom->startBand; + pMaskingNoise = maskingNoise + hFdCngCom->startBand; /*Q15*/ } FOR( i = 0; i < cnt; i++ ) { /* -1 => weighting with 0.5, -s => consider scalefactor adaptation for sqrt calculation */ sq = sub( -1, s ); - sqrtNoiseLevel = Sqrt32( Mpy_32_16_1( *cngNoiseLevel, scale ), &sq ); + sqrtNoiseLevel = Sqrt32( Mpy_32_16_1( *cngNoiseLevel, scale ), &sq ); /*Q31 - sq*/ /* real part in FFT bins */ /* random noise is scaled by CNG_RAND_GAUSS_SHIFT bits */ - *pMaskingNoise = L_shl( Mpy_32_32( rand_gauss( seed ), sqrtNoiseLevel ), sq ); + *pMaskingNoise = L_shl( Mpy_32_32( rand_gauss( seed ), sqrtNoiseLevel ), sq ); /*Q15*/ move32(); pMaskingNoise++; @@ -5022,14 +5022,14 @@ void generate_masking_noise_mdct_fx( { /* If shifting negative noise values the lowest result is -1 but never 0. Shift positive noise values to avoid unwanted amplification of these small values later */ - noise = L_shr( Mpy_32_16_1( L_abs( maskingNoise[i] ), 25905 /*0.79056941504 Q15*/ ), s2 ); + noise = L_shr( Mpy_32_16_1( L_abs( maskingNoise[i] ), 25905 /*0.79056941504 Q15*/ ), s2 ); /*Q31 - maskingNoiseExp - s2*/ if ( maskingNoise[i] < 0 ) { noise = L_negate( noise ); } - mdctBuffer[i] = L_add( mdctBuffer[i], noise ); + mdctBuffer[i] = L_add( mdctBuffer[i], noise ); /*Q31 - s*/ move32(); } } @@ -5038,12 +5038,12 @@ void generate_masking_noise_mdct_fx( FOR( i = 0; i < hFdCngCom->stopFFTbin; i++ ) { mdctBuffer[i] = L_add( L_shr( mdctBuffer[i], s1 ), - Mpy_32_16_1( maskingNoise[i], 25905 /*0.79056941504 Q15*/ ) ); + Mpy_32_16_1( maskingNoise[i], 25905 /*0.79056941504 Q15*/ ) ); /*Q31 - s*/ move32(); } FOR( i = hFdCngCom->stopFFTbin; i < L_frame; i++ ) { - mdctBuffer[i] = L_shr( mdctBuffer[i], s1 ); + mdctBuffer[i] = L_shr( mdctBuffer[i], s1 ); /*Q31 - s*/ move32(); } *mdctBuffer_e = s; @@ -5053,7 +5053,7 @@ void generate_masking_noise_mdct_fx( } void generate_masking_noise_mdct_ivas_fx( - Word32 *mdctBuffer, /* i/o: time-domain signal */ + Word32 *mdctBuffer, /* i/o: time-domain signal Q31 - mdctBuffer_e*/ Word16 *mdctBuffer_e, /* i/o: exponent time-domain signal */ HANDLE_FD_CNG_COM hFdCngCom /* i/o: FD_CNG structure containing all buffers and variables */ ) { @@ -5068,7 +5068,7 @@ void generate_masking_noise_mdct_ivas_fx( // PMTE(); /*IVAS CODE need to be added */ /* pointer initializations */ - cngNoiseLevel = hFdCngCom->cngNoiseLevel; + cngNoiseLevel = hFdCngCom->cngNoiseLevel; /*Q31 - hFdCngCom->cngNoiseLevelExp*/ seed = &( hFdCngCom->seed ); /* Compute additional CN level */ @@ -5109,21 +5109,21 @@ void generate_masking_noise_mdct_ivas_fx( sq = cngNoiseLevelExp; move16(); - sqrtNoiseLevel = Sqrt32( temp, &sq ); + sqrtNoiseLevel = Sqrt32( temp, &sq ); /*Q31 - sq*/ rand_gauss_fx( &temp, seed, Q15 ); // Q15 maskingNoise[0] = L_shl( Mpy_32_32( temp, sqrtNoiseLevel ), sq ); // Q15 move32(); - pMaskingNoise = &maskingNoise[1]; + pMaskingNoise = &maskingNoise[1]; /*Q15*/ cngNoiseLevel++; cnt = sub( cnt, 1 ); } ELSE { set32_fx( maskingNoise, 0, hFdCngCom->startBand ); - pMaskingNoise = maskingNoise + hFdCngCom->startBand; + pMaskingNoise = maskingNoise + hFdCngCom->startBand; /*Q15*/ } FOR( i = 0; i < cnt; i++ ) @@ -5134,7 +5134,7 @@ void generate_masking_noise_mdct_ivas_fx( sq = cngNoiseLevelExp; move16(); - sqrtNoiseLevel = Sqrt32( temp, &sq ); + sqrtNoiseLevel = Sqrt32( temp, &sq ); /*Q31 - sq*/ rand_gauss_fx( &temp, seed, Q15 ); // Q15 diff --git a/lib_enc/core_enc_switch.c b/lib_enc/core_enc_switch.c index d39efad14..3dee5f2bc 100644 --- a/lib_enc/core_enc_switch.c +++ b/lib_enc/core_enc_switch.c @@ -251,11 +251,6 @@ void core_coder_mode_switch_ivas_fx( { me2f_buf_16( st->hLPDmem->old_exc, st->hLPDmem->e_old_exc, st->hLPDmem->old_exc_flt, L_EXC_MEM ); } - IF( st->igf && st->hIGFEnc != NULL ) - { - st->hIGFEnc->tns_predictionGain_flt = fix16_to_float( st->hIGFEnc->tns_predictionGain, Q23 ); - me2f_buf( st->hIGFEnc->spec_be_igf, st->hIGFEnc->spec_be_igf_e, st->hIGFEnc->spec_be_igf_flt, N_MAX_TCX - IGF_START_MN ); - } #endif } diff --git a/lib_enc/ext_sig_ana.c b/lib_enc/ext_sig_ana.c index 33c3201b0..2a594cd18 100644 --- a/lib_enc/ext_sig_ana.c +++ b/lib_enc/ext_sig_ana.c @@ -527,58 +527,19 @@ void core_signal_analysis_high_bitrate( q_spectrum = L_get_q_buf1( hTcxEnc->spectrum[frameno], hTcxEnc->L_frameTCX / nSubframes ); if ( st->hIGFEnc ) { - q_spectrum = min( q_spectrum, L_get_q_buf1( st->hIGFEnc->spec_be_igf_flt, st->hIGFEnc->infoStopLine - IGF_START_MN ) ); + q_spectrum = min( q_spectrum, 31 - st->hIGFEnc->spec_be_igf_e ); } floatToFixed_arrL32( hTcxEnc->spectrum[frameno], hTcxEnc->spectrum_fx[frameno], q_spectrum, hTcxEnc->L_frameTCX / nSubframes ); - if ( st->hIGFEnc ) - { - floatToFixed_arrL32( st->hIGFEnc->spec_be_igf_flt, st->hIGFEnc->spec_be_igf, q_spectrum, st->hIGFEnc->infoStopLine - IGF_START_MN ); - st->hIGFEnc->spec_be_igf_e = 31 - q_spectrum; - } Word32 powerSpec_fx[N_MAX + L_MDCT_OVLP_MAX]; /* Buffer for TCX20/TCX10 windowing */ Word16 q_powerSpec; q_powerSpec = L_get_q_buf1( powerSpec, L_subframe ); floatToFixed_arrL32( powerSpec, powerSpec_fx, q_powerSpec, L_subframe ); - - if ( st->hIGFEnc ) - { - st->hIGFEnc->tns_predictionGain = float_to_fix16( st->hIGFEnc->tns_predictionGain_flt, Q23 ); - } - - IGF_ENC_PRIVATE_DATA_HANDLE hPrivateData = &st->hIGFEnc->igfData; #endif ProcessIGF_ivas_fx( st, hTcxEnc->spectrum_fx[frameno], hTcxEnc->spectrum_fx[frameno], &q_spectrum, powerSpec_fx, &q_powerSpec, transform_type[frameno] == TCX_20, frameno, 0, vad_hover_flag ); #ifdef IVAS_FLOAT_FIXED_CONVERSIONS fixedToFloat_arrL32( hTcxEnc->spectrum_fx[frameno], hTcxEnc->spectrum[frameno], q_spectrum, hTcxEnc->L_frameTCX / nSubframes ); fixedToFloat_arrL32( powerSpec_fx, powerSpec, q_powerSpec, L_subframe ); - - if ( st->hIGFEnc ) - { - st->hIGFEnc->tns_predictionGain_flt = fix16_to_float( st->hIGFEnc->tns_predictionGain, Q23 ); - me2f_buf( st->hIGFEnc->spec_be_igf, st->hIGFEnc->spec_be_igf_e, st->hIGFEnc->spec_be_igf_flt, st->hIGFEnc->infoStopLine - IGF_START_MN ); - } - - for ( Word16 sfb = 0; sfb < 23; sfb++ ) - { - hPrivateData->prevSFM_FIR_SFB_TB[sfb] = me2f_16( hPrivateData->prevSFM_FIR_SFB_TB_fx[sfb], hPrivateData->prevSFB_FIR_TB_e[sfb] ); - hPrivateData->prevSFM_IIR_SFB_TB[sfb] = me2f_16( hPrivateData->prevSFM_IIR_SFB_TB_fx[sfb], hPrivateData->prevSFB_IIR_TB_e[sfb] ); - hPrivateData->prevSFM_FIR_SFB_SB[sfb] = me2f_16( hPrivateData->prevSFM_FIR_SFB_SB_fx[sfb], hPrivateData->prevSFB_FIR_SB_e[sfb] ); - hPrivateData->prevSFM_IIR_SFB_SB[sfb] = me2f_16( hPrivateData->prevSFM_IIR_SFB_SB_fx[sfb], hPrivateData->prevSFB_IIR_SB_e[sfb] ); - hPrivateData->SFM_tb[sfb] = me2f_16( hPrivateData->SFM_tb_fx[sfb], hPrivateData->sfb_tb_e[sfb] ); - hPrivateData->SFM_sb[sfb] = me2f_16( hPrivateData->SFM_sb_fx[sfb], hPrivateData->sfb_sb_e[sfb] ); - hPrivateData->prevDampingFactor_IIR[sfb] = me2f_16( hPrivateData->prevDampingFactor_IIR_fx[sfb], hPrivateData->prevDampingFactor_IIR_e[sfb] ); - } - - for ( i = 0; i < IGF_MAX_TILES; i++ ) - { - hPrivateData->prevSFM_FIR_flt[i] = fixedToFloat( hPrivateData->prevSFM_FIR[i], 16 ); /*15Q16*/ - hPrivateData->prevSFM_IIR_flt[i] = fixedToFloat( hPrivateData->prevSFM_IIR[i], 13 ); /*2Q13*/ - for ( int j = 0; j < IGF_PAST_SFM_LEN; j++ ) - { - hPrivateData->igfPastSFM[i][j] = fixedToFloat( hPrivateData->igfPastSFM_fx[i][j], 13 ); - } - } #endif #else ProcessIGF( st, hTcxEnc->spectrum[frameno], hTcxEnc->spectrum[frameno], powerSpec, transform_type[frameno] == TCX_20, frameno, 0, vad_hover_flag ); diff --git a/lib_enc/igf_enc.c b/lib_enc/igf_enc.c index a78e88139..52ca1a022 100644 --- a/lib_enc/igf_enc.c +++ b/lib_enc/igf_enc.c @@ -3672,23 +3672,6 @@ static int16_t IGF_WriteFlatteningTrigger( * updates the start/stop frequency of IGF according to igfGridIdx *-------------------------------------------------------------------*/ -static void IGF_UpdateInfo_ivas( - const IGF_ENC_INSTANCE_HANDLE hIGFEnc, /* i : instance handle of IGF Encoder */ - const int16_t igfGridIdx /* i : IGF grid index */ -) -{ - H_IGF_GRID hGrid; - - hGrid = &hIGFEnc->igfData.igfInfo.grid[igfGridIdx]; - hIGFEnc->infoStartFrequency = hGrid->startFrequency; - hIGFEnc->infoStopFrequency = hGrid->stopFrequency; - hIGFEnc->infoStartLine = hGrid->startLine; - hIGFEnc->infoStopLine = hGrid->stopLine; - - return; -} - - /*-------------------------------------------------------------------* * IGFEncWriteBitstream() * @@ -3798,11 +3781,6 @@ void IGFEncSetMode( set_s( hPrivateData->igfPrevWhiteningLevel, 0, IGF_MAX_TILES ); set_s( hPrivateData->igfWhiteningHangoverCnt, 0, IGF_MAX_TILES ); - for ( i = 0; i < IGF_MAX_TILES; i++ ) - { - set_f( hPrivateData->igfPastSFM[i], -1.f, IGF_PAST_SFM_LEN ); - } - hPrivateData->igfPastSFM_pos = 0; for ( i = 0; i < IGF_BITBUFSIZE / 8; i++ ) @@ -3811,21 +3789,12 @@ void IGFEncSetMode( } hPrivateData->wasTransient = 0; - set_f( hPrivateData->prevSFM_FIR_flt, 0, IGF_MAX_TILES ); - set_f( hPrivateData->prevSFM_IIR_flt, 0, IGF_MAX_TILES ); set_s( hPrivateData->dampingFactorSmoothing, 2, IGF_MAX_SFB ); - set_f( hPrivateData->prevSFM_FIR_SFB_SB, 0, IGF_MAX_SFB ); - set_f( hPrivateData->prevSFM_IIR_SFB_SB, 0, IGF_MAX_SFB ); - set_f( hPrivateData->prevSFM_FIR_SFB_TB, 0, IGF_MAX_SFB ); - set_f( hPrivateData->prevSFM_IIR_SFB_TB, 0, IGF_MAX_SFB ); - set_f( hPrivateData->prevDampingFactor_IIR, -1, IGF_MAX_SFB ); #ifdef IVAS_FLOAT_FIXED set_s( hPrivateData->prevDampingFactor_IIR_fx, MIN16B, IGF_MAX_SFB ); set_s( hPrivateData->prevDampingFactor_IIR_e, 0, IGF_MAX_SFB ); #endif set_s( hPrivateData->logSpec, 0, L_FRAME_PLUS ); - set_f( hPrivateData->SFM_sb, 0.f, IGF_MAX_SFB ); - set_f( hPrivateData->SFM_tb, 0.f, IGF_MAX_SFB ); #ifndef IVAS_FLOAT_FIXED if ( IGFCommonFuncsIGFConfiguration_flt( total_brate, bwidth, element_mode, &hPrivateData->igfInfo, rf_mode ) ) @@ -3856,8 +3825,6 @@ void IGFEncSetMode( hIGFEnc->infoTotalBitsWritten = 0; hIGFEnc->infoTotalBitsPerFrameWritten = 0; hIGFEnc->flatteningTrigger = 0; - hIGFEnc->tns_predictionGain_flt = 0; - set_f( hIGFEnc->spec_be_igf_flt, 0, N_MAX_TCX - IGF_START_MN ); return; } @@ -4488,18 +4455,6 @@ void IGFSaveSpectrumForITF_ivas_fx( return; } #endif -void IGFSaveSpectrumForITF( - IGF_ENC_INSTANCE_HANDLE hIGFEnc, /* i/o: instance handle of IGF Encoder */ - const int16_t igfGridIdx, /* i : IGF grid index */ - const float *pITFSpectrum /* i : MDCT spectrum */ -) -{ - IGF_UpdateInfo_ivas( hIGFEnc, igfGridIdx ); - - mvr2r( pITFSpectrum + IGF_START_MN, hIGFEnc->spec_be_igf_flt, hIGFEnc->infoStopLine - IGF_START_MN ); - - return; -} #ifndef IVAS_FLOAT_FIXED ivas_error IGF_Reconfig( diff --git a/lib_enc/init_enc.c b/lib_enc/init_enc.c index d8bccaa05..acf99f33d 100644 --- a/lib_enc/init_enc.c +++ b/lib_enc/init_enc.c @@ -2301,11 +2301,6 @@ ivas_error init_encoder_ivas_fx( { me2f_buf_16( st->hLPDmem->old_exc, st->hLPDmem->e_old_exc, st->hLPDmem->old_exc_flt, L_EXC_MEM ); } - IF( st->igf && st->hIGFEnc != NULL ) - { - st->hIGFEnc->tns_predictionGain_flt = fix16_to_float( st->hIGFEnc->tns_predictionGain, Q23 ); - me2f_buf( st->hIGFEnc->spec_be_igf, st->hIGFEnc->spec_be_igf_e, st->hIGFEnc->spec_be_igf_flt, N_MAX_TCX - IGF_START_MN ); - } #endif /*-----------------------------------------------------------------* * FD-CNG encoder diff --git a/lib_enc/ivas_corecoder_enc_reconfig.c b/lib_enc/ivas_corecoder_enc_reconfig.c index c36c6eabd..c7b25cee8 100644 --- a/lib_enc/ivas_corecoder_enc_reconfig.c +++ b/lib_enc/ivas_corecoder_enc_reconfig.c @@ -507,7 +507,7 @@ ivas_error ivas_corecoder_enc_reconfig_fx( Word16 len_inp_memory, n_CoreCoder_existing, nSCE_existing, nCPE_existing; Word32 input_buff_fx[MCT_MAX_BLOCKS][L_FRAME48k + NS2SA( 48000, IVAS_FB_ENC_DELAY_NS )]; - FOR( int i = 0; i < MCT_MAX_BLOCKS; i++ ) + FOR( Word32 i = 0; i < MCT_MAX_BLOCKS; i++ ) { set32_fx( input_buff_fx[i], 0, L_FRAME48k + NS2SA( 48000, IVAS_FB_ENC_DELAY_NS ) ); } @@ -525,6 +525,7 @@ ivas_error ivas_corecoder_enc_reconfig_fx( hEncoderConfig = st_ivas->hEncoderConfig; error = IVAS_ERR_OK; + move32(); len_inp_memory = idiv1616U( extract_l( L_shr( hEncoderConfig->input_Fs, 1 ) ), FRAMES_PER_SEC / 2 ); IF( EQ_16( hEncoderConfig->ivas_format, SBA_FORMAT ) ) diff --git a/lib_enc/ivas_enc.c b/lib_enc/ivas_enc.c index 580ac60a8..17cc8661b 100644 --- a/lib_enc/ivas_enc.c +++ b/lib_enc/ivas_enc.c @@ -1141,7 +1141,7 @@ ivas_error ivas_enc( ELSE IF( EQ_32( ivas_format, MC_FORMAT ) ) { /* select MC format mode; write MC LS setup; reconfigure the MC format encoder */ - IF( ( error = ivas_mc_enc_config( st_ivas ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_mc_enc_config_fx( st_ivas ) ) != IVAS_ERR_OK ) { return error; } diff --git a/lib_enc/ivas_mc_paramupmix_enc.c b/lib_enc/ivas_mc_paramupmix_enc.c index 0671e2f3f..335ef7b91 100644 --- a/lib_enc/ivas_mc_paramupmix_enc.c +++ b/lib_enc/ivas_mc_paramupmix_enc.c @@ -544,6 +544,7 @@ void ivas_mc_paramupmix_enc_close( Word16 i, k; Word16 b, j; + test(); IF( hMCParamUpmix == NULL || *hMCParamUpmix == NULL ) { return; diff --git a/lib_enc/ivas_mcmasa_enc.c b/lib_enc/ivas_mcmasa_enc.c index fa699e0af..92ceb710a 100644 --- a/lib_enc/ivas_mcmasa_enc.c +++ b/lib_enc/ivas_mcmasa_enc.c @@ -906,13 +906,14 @@ ivas_error ivas_mcmasa_enc_reconfig_fx( Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ ) { - int32_t ivas_total_brate; + Word32 ivas_total_brate; ivas_error error; error = IVAS_ERR_OK; move32(); ivas_total_brate = st_ivas->hEncoderConfig->ivas_total_brate; + move32(); IF( NE_32( ivas_total_brate, st_ivas->hEncoderConfig->last_ivas_total_brate ) ) { diff --git a/lib_enc/ivas_mct_enc.c b/lib_enc/ivas_mct_enc.c index 07379e99c..51aff96df 100644 --- a/lib_enc/ivas_mct_enc.c +++ b/lib_enc/ivas_mct_enc.c @@ -51,7 +51,7 @@ * Local function prototypes *-----------------------------------------------------------------------*/ -static ivas_error ivas_mc_enc_reconfig( Encoder_Struct *st_ivas, const int16_t last_mc_mode ); +static ivas_error ivas_mc_enc_reconfig_fx( Encoder_Struct *st_ivas, const Word16 last_mc_mode ); /*-------------------------------------------------------------------* @@ -621,7 +621,6 @@ ivas_error ivas_mct_enc( Encoder_State *sts_tmp[MCT_MAX_CHANNELS]; Encoder_State *st; Word16 i; - IGF_ENC_INSTANCE_HANDLE hIGFEnc[CPE_CHANNELS]; nCPE = shr( hMCT->nchan_out_woLFE, 1 ); // nChannels / CPE_CHANNELS /*in case of odd number of channels*/ @@ -676,43 +675,6 @@ ivas_error ivas_mct_enc( } } } - for ( int b = 0; b < hMCT->nchan_out_woLFE; b++ ) - { - st = sts_tmp[b]; - if ( st->hIGFEnc ) - { - ch = 0; - hIGFEnc[ch] = st->hIGFEnc; - IGF_ENC_PRIVATE_DATA_HANDLE hPrivateData; - - hPrivateData = &hIGFEnc[ch]->igfData; - - for ( Word16 sfb = 0; sfb < 23; sfb++ ) - { - hPrivateData->prevSFM_FIR_SFB_TB[sfb] = me2f_16( hPrivateData->prevSFM_FIR_SFB_TB_fx[sfb], hPrivateData->prevSFB_FIR_TB_e[sfb] ); - hPrivateData->prevSFM_IIR_SFB_TB[sfb] = me2f_16( hPrivateData->prevSFM_IIR_SFB_TB_fx[sfb], hPrivateData->prevSFB_IIR_TB_e[sfb] ); - hPrivateData->prevSFM_FIR_SFB_SB[sfb] = me2f_16( hPrivateData->prevSFM_FIR_SFB_SB_fx[sfb], hPrivateData->prevSFB_FIR_SB_e[sfb] ); - hPrivateData->prevSFM_IIR_SFB_SB[sfb] = me2f_16( hPrivateData->prevSFM_IIR_SFB_SB_fx[sfb], hPrivateData->prevSFB_IIR_SB_e[sfb] ); - hPrivateData->SFM_tb[sfb] = me2f_16( hPrivateData->SFM_tb_fx[sfb], hPrivateData->sfb_tb_e[sfb] ); - hPrivateData->SFM_sb[sfb] = me2f_16( hPrivateData->SFM_sb_fx[sfb], hPrivateData->sfb_sb_e[sfb] ); - hPrivateData->prevDampingFactor_IIR[sfb] = me2f_16( hPrivateData->prevDampingFactor_IIR_fx[sfb], hPrivateData->prevDampingFactor_IIR_e[sfb] ); - } - for ( int k = 0; k < IGF_MAX_TILES; k++ ) - { - hPrivateData->prevSFM_FIR_flt[k] = fixedToFloat( hPrivateData->prevSFM_FIR[k], 16 ); /*15Q16*/ - hPrivateData->prevSFM_IIR_flt[k] = fixedToFloat( hPrivateData->prevSFM_IIR[k], 13 ); /*2Q13*/ - for ( int j = 0; j < IGF_PAST_SFM_LEN; j++ ) - { - hPrivateData->igfPastSFM[k][j] = fixedToFloat( hPrivateData->igfPastSFM_fx[k][j], 13 ); - } - } - } - if ( st->hIGFEnc ) - { - st->hIGFEnc->tns_predictionGain_flt = fix16_to_float( st->hIGFEnc->tns_predictionGain, Q23 ); - me2f_buf( st->hIGFEnc->spec_be_igf, st->hIGFEnc->spec_be_igf_e, st->hIGFEnc->spec_be_igf_flt, N_MAX_TCX - IGF_START_MN ); - } - } #endif /* Spectrum quantization and coding */ @@ -1533,7 +1495,7 @@ void ivas_mct_enc_close( * - reconfigure the MC format encoder *-------------------------------------------------------------------------*/ -ivas_error ivas_mc_enc_config( +ivas_error ivas_mc_enc_config_fx( Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ ) { @@ -1542,24 +1504,32 @@ ivas_error ivas_mc_enc_config( ivas_error error; error = IVAS_ERR_OK; + move32(); last_mc_mode = st_ivas->mc_mode; + move32(); /* select MC format mode */ -#ifndef IVAS_FLOAT_FIXED - st_ivas->mc_mode = ivas_mc_mode_select( st_ivas->hEncoderConfig->mc_input_setup, st_ivas->hEncoderConfig->ivas_total_brate ); -#else st_ivas->mc_mode = ivas_mc_mode_select_fx( st_ivas->hEncoderConfig->mc_input_setup, st_ivas->hEncoderConfig->ivas_total_brate ); -#endif + move32(); /* write MC LS setup */ - st0 = ( st_ivas->nSCE > 0 ) ? st_ivas->hSCE[0]->hCoreCoder[0] : st_ivas->hCPE[0]->hCoreCoder[0]; + IF( st_ivas->nSCE > 0 ) + { + st0 = st_ivas->hSCE[0]->hCoreCoder[0]; + } + ELSE + { + st0 = st_ivas->hCPE[0]->hCoreCoder[0]; + } + push_indice( st0->hBstr, IND_SMODE, st_ivas->hEncoderConfig->mc_input_setup, MC_LS_SETUP_BITS ); /* MC format switching */ - if ( st_ivas->hEncoderConfig->last_ivas_total_brate != st_ivas->hEncoderConfig->ivas_total_brate || st_ivas->mc_mode != last_mc_mode ) + test(); + IF( NE_32( st_ivas->hEncoderConfig->last_ivas_total_brate, st_ivas->hEncoderConfig->ivas_total_brate ) || NE_32( st_ivas->mc_mode, last_mc_mode ) ) { - if ( ( error = ivas_mc_enc_reconfig( st_ivas, last_mc_mode ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_mc_enc_reconfig_fx( st_ivas, last_mc_mode ) ), IVAS_ERR_OK ) ) { return error; } @@ -1575,149 +1545,128 @@ ivas_error ivas_mc_enc_config( * Reconfigure the MC format encoder *-------------------------------------------------------------------------*/ -static ivas_error ivas_mc_enc_reconfig( - Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ - const int16_t last_mc_mode /* i : last frame mc mode */ +static ivas_error ivas_mc_enc_reconfig_fx( + Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ + const Word16 last_mc_mode /* i : last frame mc mode */ ) { - int16_t nchan_transport_old, nSCE_old, nCPE_old; + Word16 nchan_transport_old, nSCE_old, nCPE_old; ivas_error error; - int32_t new_brate_SCE, new_brate_CPE; + Word32 new_brate_SCE, new_brate_CPE; error = IVAS_ERR_OK; + move32(); nchan_transport_old = st_ivas->nchan_transport; + move16(); nSCE_old = st_ivas->nSCE; + move16(); nCPE_old = st_ivas->nCPE; + move16(); /*-----------------------------------------------------------------* * Reconfigure MC modules *-----------------------------------------------------------------*/ - if ( st_ivas->mc_mode == MC_MODE_MCT ) + IF( EQ_32( st_ivas->mc_mode, MC_MODE_MCT ) ) { st_ivas->nSCE = 0; - st_ivas->nCPE = st_ivas->hEncoderConfig->nchan_inp / 2; + move16(); + st_ivas->nCPE = shr( st_ivas->hEncoderConfig->nchan_inp, 1 ); + move16(); -#ifndef IVAS_FLOAT_FIXED - st_ivas->nchan_transport = ivas_mc_ls_setup_get_num_channels( st_ivas->hEncoderConfig->mc_input_setup ); -#else st_ivas->nchan_transport = ivas_mc_ls_setup_get_num_channels_fx( st_ivas->hEncoderConfig->mc_input_setup ); -#endif + move16(); - if ( last_mc_mode != MC_MODE_MCT ) + IF( NE_32( last_mc_mode, MC_MODE_MCT ) ) { - if ( st_ivas->hLFE != NULL ) + IF( st_ivas->hLFE != NULL ) { /* LFE handle */ ivas_lfe_enc_close( &( st_ivas->hLFE ) ); } /* create LFE handle */ - if ( ( error = ivas_create_lfe_enc( &st_ivas->hLFE, st_ivas->hEncoderConfig->input_Fs ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_create_lfe_enc( &st_ivas->hLFE, st_ivas->hEncoderConfig->input_Fs ) ), IVAS_ERR_OK ) ) { return error; } /*De-allocate handles for other MC modes*/ -#ifdef IVAS_FLOAT_FIXED ivas_param_mc_enc_close_fx( &( st_ivas->hParamMC ), st_ivas->hEncoderConfig->input_Fs ); -#else - ivas_param_mc_enc_close( &( st_ivas->hParamMC ), st_ivas->hEncoderConfig->input_Fs ); -#endif ivas_mc_paramupmix_enc_close( &( st_ivas->hMCParamUpmix ), st_ivas->hEncoderConfig->input_Fs ); -#ifdef IVAS_FLOAT_FIXED /* De-allocate McMasa-related handles */ ivas_mcmasa_enc_close_fx( &( st_ivas->hMcMasa ), st_ivas->hEncoderConfig->input_Fs ); -#else - ivas_mcmasa_enc_close( &( st_ivas->hMcMasa ), st_ivas->hEncoderConfig->input_Fs ); -#endif ivas_masa_enc_close( &( st_ivas->hMasa ) ); ivas_qmetadata_close( &st_ivas->hQMetaData ); } } - else if ( st_ivas->mc_mode == MC_MODE_PARAMUPMIX ) + ELSE IF( EQ_32( st_ivas->mc_mode, MC_MODE_PARAMUPMIX ) ) { st_ivas->nSCE = 0; - st_ivas->nCPE = MC_PARAMUPMIX_MAX_TRANSPORT_CHANS / 2; + move16(); + st_ivas->nCPE = MC_PARAMUPMIX_MAX_TRANSPORT_CHANS >> 1; + move16(); st_ivas->nchan_transport = MC_PARAMUPMIX_MAX_TRANSPORT_CHANS; + move16(); - if ( last_mc_mode != MC_MODE_PARAMUPMIX ) + IF( NE_32( last_mc_mode, MC_MODE_PARAMUPMIX ) ) { - if ( st_ivas->hLFE != NULL ) + IF( st_ivas->hLFE != NULL ) { /* LFE handle */ ivas_lfe_enc_close( &( st_ivas->hLFE ) ); } /* create LFE handle */ - if ( ( error = ivas_create_lfe_enc( &st_ivas->hLFE, st_ivas->hEncoderConfig->input_Fs ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_create_lfe_enc( &st_ivas->hLFE, st_ivas->hEncoderConfig->input_Fs ) ), IVAS_ERR_OK ) ) { return error; } } - if ( last_mc_mode != MC_MODE_PARAMUPMIX ) + IF( NE_32( last_mc_mode, MC_MODE_PARAMUPMIX ) ) { - if ( ( error = ivas_mc_paramupmix_enc_open( st_ivas ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_mc_paramupmix_enc_open( st_ivas ) ), IVAS_ERR_OK ) ) { return error; } } /*De-allocate handles for other MC modes*/ -#ifdef IVAS_FLOAT_FIXED ivas_param_mc_enc_close_fx( &st_ivas->hParamMC, st_ivas->hEncoderConfig->input_Fs ); -#else - ivas_param_mc_enc_close( &st_ivas->hParamMC, st_ivas->hEncoderConfig->input_Fs ); -#endif /* De-allocate McMasa-related handles */ -#ifdef IVAS_FLOAT_FIXED ivas_mcmasa_enc_close_fx( &( st_ivas->hMcMasa ), st_ivas->hEncoderConfig->input_Fs ); -#else - ivas_mcmasa_enc_close( &( st_ivas->hMcMasa ), st_ivas->hEncoderConfig->input_Fs ); -#endif ivas_masa_enc_close( &( st_ivas->hMasa ) ); ivas_qmetadata_close( &st_ivas->hQMetaData ); } - else if ( st_ivas->mc_mode == MC_MODE_PARAMMC ) + ELSE IF( EQ_32( st_ivas->mc_mode, MC_MODE_PARAMMC ) ) { - if ( last_mc_mode != MC_MODE_PARAMMC ) + IF( NE_32( last_mc_mode, MC_MODE_PARAMMC ) ) { -#ifdef IVAS_FLOAT_FIXED - if ( ( error = ivas_param_mc_enc_open_fx( st_ivas ) ) != IVAS_ERR_OK ) -#else - if ( ( error = ivas_param_mc_enc_open( st_ivas ) ) != IVAS_ERR_OK ) -#endif + IF( NE_32( ( error = ivas_param_mc_enc_open_fx( st_ivas ) ), IVAS_ERR_OK ) ) { return error; } } - else + ELSE { -#ifdef IVAS_FLOAT_FIXED - if ( ( error = ivas_param_mc_enc_reconfig_fx( st_ivas ) ) != IVAS_ERR_OK ) -#else - if ( ( error = ivas_param_mc_enc_reconfig( st_ivas ) ) != IVAS_ERR_OK ) -#endif + IF( NE_32( ( error = ivas_param_mc_enc_reconfig_fx( st_ivas ) ), IVAS_ERR_OK ) ) { return error; } } /* De-allocate McMasa-related handles */ -#ifdef IVAS_FLOAT_FIXED ivas_mcmasa_enc_close_fx( &( st_ivas->hMcMasa ), st_ivas->hEncoderConfig->input_Fs ); -#else - ivas_mcmasa_enc_close( &( st_ivas->hMcMasa ), st_ivas->hEncoderConfig->input_Fs ); -#endif - if ( st_ivas->hMasa != NULL ) + + IF( st_ivas->hMasa != NULL ) { ivas_masa_enc_close( &( st_ivas->hMasa ) ); st_ivas->hMasa = NULL; @@ -1725,7 +1674,8 @@ static ivas_error ivas_mc_enc_reconfig( ivas_mc_paramupmix_enc_close( &( st_ivas->hMCParamUpmix ), st_ivas->hEncoderConfig->input_Fs ); - if ( last_mc_mode == MC_MODE_PARAMUPMIX && st_ivas->hLFE != NULL ) + test(); + IF( EQ_32( last_mc_mode, MC_MODE_PARAMUPMIX ) && st_ivas->hLFE != NULL ) { /* LFE handle */ ivas_lfe_enc_close( &( st_ivas->hLFE ) ); @@ -1734,79 +1684,60 @@ static ivas_error ivas_mc_enc_reconfig( ivas_qmetadata_close( &st_ivas->hQMetaData ); /* De-allocate MCT handle if last mode was MCT */ - if ( last_mc_mode == MC_MODE_MCT && st_ivas->nchan_transport <= CPE_CHANNELS ) + test(); + IF( EQ_32( last_mc_mode, MC_MODE_MCT ) && LE_16( st_ivas->nchan_transport, CPE_CHANNELS ) ) { ivas_mct_enc_close( &( st_ivas->hMCT ) ); } - if ( last_mc_mode == MC_MODE_MCT && st_ivas->hLFE != NULL ) + test(); + IF( EQ_32( last_mc_mode, MC_MODE_MCT ) && st_ivas->hLFE != NULL ) { /* LFE handle */ ivas_lfe_enc_close( &( st_ivas->hLFE ) ); } } - else if ( st_ivas->mc_mode == MC_MODE_MCMASA ) + ELSE IF( EQ_32( st_ivas->mc_mode, MC_MODE_MCMASA ) ) { - if ( last_mc_mode != MC_MODE_MCMASA ) + IF( NE_32( last_mc_mode, MC_MODE_MCMASA ) ) { -#ifndef IVAS_FLOAT_FIXED - ivas_mcmasa_setNumTransportChannels( &( st_ivas->nchan_transport ), &( st_ivas->hEncoderConfig->element_mode_init ), st_ivas->hEncoderConfig->ivas_total_brate ); -#else ivas_mcmasa_setNumTransportChannels_fx( &( st_ivas->nchan_transport ), &( st_ivas->hEncoderConfig->element_mode_init ), st_ivas->hEncoderConfig->ivas_total_brate ); -#endif - if ( ( error = ivas_qmetadata_open( &( st_ivas->hQMetaData ) ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_qmetadata_open( &( st_ivas->hQMetaData ) ) ), IVAS_ERR_OK ) ) { return error; } - if ( ( error = ivas_masa_enc_open( st_ivas ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_masa_enc_open( st_ivas ) ), IVAS_ERR_OK ) ) { return error; } -#ifdef IVAS_FLOAT_FIXED - if ( NE_32( ( error = ivas_mcmasa_enc_open_fx( st_ivas ) ), IVAS_ERR_OK ) ) + IF( NE_32( ( error = ivas_mcmasa_enc_open_fx( st_ivas ) ), IVAS_ERR_OK ) ) { return error; } -#else - if ( ( error = ivas_mcmasa_enc_open( st_ivas ) ) != IVAS_ERR_OK ) - { - return error; - } -#endif } - else + ELSE { /* reconfigure McMASA instance */ -#ifdef IVAS_FLOAT_FIXED - if ( NE_32( ( error = ivas_mcmasa_enc_reconfig_fx( st_ivas ) ), IVAS_ERR_OK ) ) - { - return error; - } -#else - if ( ( error = ivas_mcmasa_enc_reconfig( st_ivas ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_mcmasa_enc_reconfig_fx( st_ivas ) ), IVAS_ERR_OK ) ) { return error; } -#endif } -#ifdef IVAS_FLOAT_FIXED ivas_param_mc_enc_close_fx( &( st_ivas->hParamMC ), st_ivas->hEncoderConfig->input_Fs ); -#else - ivas_param_mc_enc_close( &( st_ivas->hParamMC ), st_ivas->hEncoderConfig->input_Fs ); -#endif ivas_mc_paramupmix_enc_close( &( st_ivas->hMCParamUpmix ), st_ivas->hEncoderConfig->input_Fs ); - if ( last_mc_mode == MC_MODE_PARAMUPMIX && st_ivas->hLFE != NULL ) + test(); + IF( EQ_32( last_mc_mode, MC_MODE_PARAMUPMIX ) && st_ivas->hLFE != NULL ) { /* LFE handle */ ivas_lfe_enc_close( &( st_ivas->hLFE ) ); } - if ( last_mc_mode == MC_MODE_MCT ) + IF( EQ_32( last_mc_mode, MC_MODE_MCT ) ) { /* LFE handle */ ivas_lfe_enc_close( &( st_ivas->hLFE ) ); @@ -1815,15 +1746,17 @@ static ivas_error ivas_mc_enc_reconfig( } } - if ( st_ivas->mc_mode != MC_MODE_MCMASA ) + IF( NE_32( st_ivas->mc_mode, MC_MODE_MCMASA ) ) { - if ( st_ivas->nchan_transport == 1 ) + IF( EQ_16( st_ivas->nchan_transport, 1 ) ) { st_ivas->hEncoderConfig->element_mode_init = IVAS_SCE; + move16(); } - else + ELSE { st_ivas->hEncoderConfig->element_mode_init = IVAS_CPE_MDCT; + move16(); } } @@ -1835,74 +1768,77 @@ static ivas_error ivas_mc_enc_reconfig( and might have IGF and TranDet static memory not allocated and the bit stream index list not set, set correct mct_chan_mode and init missing static mem do it here since it is _very_ MC specific */ - if ( last_mc_mode == MC_MODE_MCT && st_ivas->mc_mode == MC_MODE_PARAMMC && st_ivas->nchan_transport > CPE_CHANNELS ) + test(); + test(); + IF( EQ_32( last_mc_mode, MC_MODE_MCT ) && EQ_32( st_ivas->mc_mode, MC_MODE_PARAMMC ) && GT_16( st_ivas->nchan_transport, CPE_CHANNELS ) ) { Encoder_State *st = st_ivas->hCPE[1]->hCoreCoder[1]; - if ( st_ivas->nchan_transport == 3 ) + IF( EQ_16( st_ivas->nchan_transport, 3 ) ) { st->mct_chan_mode = MCT_CHAN_MODE_IGNORE; + move32(); } - else + ELSE { st->mct_chan_mode = MCT_CHAN_MODE_REGULAR; + move32(); } - if ( st->hTranDet == NULL ) + IF( st->hTranDet == NULL ) { - if ( ( st->hTranDet = (TRAN_DET_HANDLE) malloc( sizeof( TRAN_DET_DATA ) ) ) == NULL ) + IF( ( st->hTranDet = (TRAN_DET_HANDLE) malloc( sizeof( TRAN_DET_DATA ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Transient Detection\n" ) ); } -#ifdef IVAS_FLOAT_FIXED InitTransientDetection_ivas_fx( shl( div_l( st->input_Fs, FRAMES_PER_SEC ), 1 ), NS2SA_FX2( st->input_Fs, DELAY_FIR_RESAMPL_NS ), st->hTranDet, 0 ); -#else - InitTransientDetection( (int16_t) ( st->input_Fs / FRAMES_PER_SEC ), NS2SA( st->input_Fs, DELAY_FIR_RESAMPL_NS ), st->hTranDet, 0 ); -#endif } - if ( st->hIGFEnc == NULL ) + IF( st->hIGFEnc == NULL ) { - if ( ( st->hIGFEnc = (IGF_ENC_INSTANCE_HANDLE) malloc( sizeof( IGF_ENC_INSTANCE ) ) ) == NULL ) + IF( ( st->hIGFEnc = (IGF_ENC_INSTANCE_HANDLE) malloc( sizeof( IGF_ENC_INSTANCE ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for hIGFEnc\n" ) ); } } -#ifndef IVAS_FLOAT_FIXED - st->igf = getIgfPresent( st->element_mode, st->total_brate, st->bwidth, st->rf_mode ); -#else st->igf = getIgfPresent_fx( st->element_mode, st->total_brate, st->bwidth, st->rf_mode ); -#endif + move16(); /* set last core to TCX20 */ st->last_core = TCX_20_CORE; + move16(); } - if ( st_ivas->mc_mode == MC_MODE_MCMASA ) + IF( EQ_32( st_ivas->mc_mode, MC_MODE_MCMASA ) ) { -#ifndef IVAS_FLOAT_FIXED - ivas_mcmasa_split_brate( st_ivas->hMcMasa->separateChannelEnabled, st_ivas->hEncoderConfig->ivas_total_brate, st_ivas->nSCE, st_ivas->nCPE, &new_brate_SCE, &new_brate_CPE ); -#else ivas_mcmasa_split_brate_fx( st_ivas->hMcMasa->separateChannelEnabled, st_ivas->hEncoderConfig->ivas_total_brate, st_ivas->nSCE, st_ivas->nCPE, &new_brate_SCE, &new_brate_CPE ); -#endif } - else if ( st_ivas->mc_mode == MC_MODE_MCT ) + ELSE IF( EQ_32( st_ivas->mc_mode, MC_MODE_MCT ) ) { new_brate_SCE = 0; - new_brate_CPE = ( st_ivas->hEncoderConfig->ivas_total_brate / ( st_ivas->nchan_transport - 1 ) ) * CPE_CHANNELS; + move32(); + Word32 res_dec, res_frac; + iDiv_and_mod_32( st_ivas->hEncoderConfig->ivas_total_brate, sub( st_ivas->nchan_transport, 1 ), &res_dec, &res_frac, 0 ); + new_brate_CPE = imult3216( res_dec, CPE_CHANNELS ); } - else if ( st_ivas->mc_mode == MC_MODE_PARAMUPMIX ) + ELSE IF( EQ_32( st_ivas->mc_mode, MC_MODE_PARAMUPMIX ) ) { new_brate_SCE = 0; - new_brate_CPE = ( st_ivas->hEncoderConfig->ivas_total_brate / ( st_ivas->nchan_transport - 1 ) ) * CPE_CHANNELS; + move32(); + Word32 res_dec, res_frac; + iDiv_and_mod_32( st_ivas->hEncoderConfig->ivas_total_brate, sub( st_ivas->nchan_transport, 1 ), &res_dec, &res_frac, 0 ); + new_brate_CPE = imult3216( res_dec, CPE_CHANNELS ); } - else + ELSE { new_brate_SCE = 0; /*st_ivas->hEncoderConfig->ivas_total_brate / st_ivas->nchan_transport;*/ - new_brate_CPE = ( st_ivas->hEncoderConfig->ivas_total_brate / st_ivas->nchan_transport ) * CPE_CHANNELS; + move32(); + Word32 res_dec, res_frac; + iDiv_and_mod_32( st_ivas->hEncoderConfig->ivas_total_brate, st_ivas->nchan_transport, &res_dec, &res_frac, 0 ); + new_brate_CPE = imult3216( res_dec, CPE_CHANNELS ); } - if ( ( error = ivas_corecoder_enc_reconfig_fx( st_ivas, nSCE_old, nCPE_old, nchan_transport_old, new_brate_SCE, new_brate_CPE, last_mc_mode ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_corecoder_enc_reconfig_fx( st_ivas, nSCE_old, nCPE_old, nchan_transport_old, new_brate_SCE, new_brate_CPE, last_mc_mode ) ), IVAS_ERR_OK ) ) { return error; } diff --git a/lib_enc/ivas_mdct_core_enc.c b/lib_enc/ivas_mdct_core_enc.c index f8787ab7d..8d7aa9855 100644 --- a/lib_enc/ivas_mdct_core_enc.c +++ b/lib_enc/ivas_mdct_core_enc.c @@ -1931,75 +1931,6 @@ void ivas_mdct_core_whitening_enc( st->hTcxEnc->exp_buf_speech_ltp = 15 - q_fac; } - IF( NE_16( st->element_mode, IVAS_CPE_MDCT ) && st->igf ) - { - if ( st->hIGFEnc ) - { - st->hIGFEnc->tns_predictionGain = float_to_fix16( st->hIGFEnc->tns_predictionGain_flt, Q23 ); - } - - IGF_ENC_PRIVATE_DATA_HANDLE hPrivateData = &st->hIGFEnc->igfData; - - float max_sb = 0; - float max_tb = 0; - Word16 max_sb_fx = 0; - Word16 max_tb_fx = 0; - - float max_fir_tb = 0; - float max_iir_tb = 0; - float max_fir_sb = 0; - float max_iir_sb = 0; - - Word16 max_fir_tb_fx = 0; - Word16 max_iir_tb_fx = 0; - Word16 max_fir_sb_fx = 0; - Word16 max_iir_sb_fx = 0; - FOR( Word16 sfb = 0; sfb < 23; sfb++ ) - { - f2me_16( hPrivateData->prevDampingFactor_IIR[sfb], &hPrivateData->prevDampingFactor_IIR_fx[sfb], &hPrivateData->prevDampingFactor_IIR_e[sfb] ); - - max_fir_tb = fmaxf( fabsf( hPrivateData->prevSFM_FIR_SFB_TB[sfb] ), max_fir_tb ); - f2me_16( max_fir_tb, &max_fir_tb_fx, &hPrivateData->prevSFB_FIR_TB_e[sfb] ); - hPrivateData->prevSFM_FIR_SFB_TB_fx[sfb] = float_to_fix16( hPrivateData->prevSFM_FIR_SFB_TB[sfb], sub( 15, hPrivateData->prevSFB_FIR_TB_e[sfb] ) ); - - max_iir_tb = fmaxf( fabsf( hPrivateData->prevSFM_IIR_SFB_TB[sfb] ), max_iir_tb ); - f2me_16( max_iir_tb, &max_iir_tb_fx, &hPrivateData->prevSFB_IIR_TB_e[sfb] ); - hPrivateData->prevSFM_IIR_SFB_TB_fx[sfb] = float_to_fix16( hPrivateData->prevSFM_IIR_SFB_TB[sfb], sub( 15, hPrivateData->prevSFB_IIR_TB_e[sfb] ) ); - - max_fir_sb = fmaxf( fabsf( hPrivateData->prevSFM_FIR_SFB_SB[sfb] ), max_fir_sb ); - f2me_16( max_fir_sb, &max_fir_sb_fx, &hPrivateData->prevSFB_FIR_SB_e[sfb] ); - hPrivateData->prevSFM_FIR_SFB_SB_fx[sfb] = float_to_fix16( hPrivateData->prevSFM_FIR_SFB_SB[sfb], sub( 15, hPrivateData->prevSFB_FIR_SB_e[sfb] ) ); - - max_iir_sb = fmaxf( fabsf( hPrivateData->prevSFM_IIR_SFB_SB[sfb] ), max_iir_sb ); - f2me_16( max_iir_sb, &max_iir_sb_fx, &hPrivateData->prevSFB_IIR_SB_e[sfb] ); - hPrivateData->prevSFM_IIR_SFB_SB_fx[sfb] = float_to_fix16( hPrivateData->prevSFM_IIR_SFB_SB[sfb], sub( 15, hPrivateData->prevSFB_IIR_SB_e[sfb] ) ); - - max_tb = fmaxf( fabsf( hPrivateData->SFM_tb[sfb] ), max_tb ); - f2me_16( max_tb, &max_tb_fx, &hPrivateData->sfb_tb_e[sfb] ); - hPrivateData->SFM_tb_fx[sfb] = float_to_fix16( hPrivateData->SFM_tb[sfb], sub( 15, hPrivateData->sfb_tb_e[sfb] ) ); - - max_sb = fmaxf( fabsf( hPrivateData->SFM_sb[sfb] ), max_sb ); - f2me_16( max_sb, &max_sb_fx, &hPrivateData->sfb_sb_e[sfb] ); - hPrivateData->SFM_sb_fx[sfb] = float_to_fix16( hPrivateData->SFM_sb[sfb], sub( 15, hPrivateData->sfb_sb_e[sfb] ) ); - } - - for ( i = 0; i < IGF_MAX_TILES; i++ ) - { - hPrivateData->prevSFM_FIR[i] = float_to_fix( hPrivateData->prevSFM_FIR_flt[i], 16 ); /*15Q16*/ - hPrivateData->prevSFM_IIR[i] = float_to_fix16( hPrivateData->prevSFM_IIR_flt[i], 13 ); /*2Q13*/ - for ( int j = 0; j < IGF_PAST_SFM_LEN; j++ ) - { - hPrivateData->igfPastSFM_fx[i][j] = float_to_fix16( hPrivateData->igfPastSFM[i][j], 13 ); - } - } - } - if ( st->hIGFEnc ) - { - Word16 q_spectrum; - q_spectrum = L_get_q_buf1( st->hIGFEnc->spec_be_igf_flt, st->hIGFEnc->infoStopLine - IGF_START_MN ); - floatToFixed_arrL32( st->hIGFEnc->spec_be_igf_flt, st->hIGFEnc->spec_be_igf, q_spectrum, st->hIGFEnc->infoStopLine - IGF_START_MN ); - st->hIGFEnc->spec_be_igf_e = 31 - q_spectrum; - } Word16 q_spectrum = L_get_q_buf1( hTcxEnc->spectrum[0], st->hTcxEnc->L_frameTCX / nSubframes ); hTcxEnc->spectrum_e[0] = 31 - q_spectrum; floatToFixed_arrL32( hTcxEnc->spectrum[0], hTcxEnc->spectrum_fx[0], sub( Q31, hTcxEnc->spectrum_e[0] ), st->hTcxEnc->L_frameTCX / nSubframes ); @@ -2014,35 +1945,6 @@ void ivas_mdct_core_whitening_enc( #endif core_signal_analysis_high_bitrate_ivas_fx( new_samples_fx[ch] + L_INP_MEM, T_op[ch], NULL, NULL, st, tnsSize[ch], tnsBits[ch], param_core[ch], <pBits[ch], windowedSignal_fx[ch], st->L_frame, st->hTcxEnc->L_frameTCX, hCPE->last_element_mode, 0, mdst_spectrum_fx[ch], mdst_spectrum_e[ch], &Q_new ); #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - IF( NE_16( st->element_mode, IVAS_CPE_MDCT ) && st->igf ) - { - if ( st->hIGFEnc ) - { - st->hIGFEnc->tns_predictionGain_flt = fix16_to_float( st->hIGFEnc->tns_predictionGain, Q23 ); - me2f_buf( st->hIGFEnc->spec_be_igf, st->hIGFEnc->spec_be_igf_e, st->hIGFEnc->spec_be_igf_flt, st->hIGFEnc->infoStopLine - IGF_START_MN ); - } - IGF_ENC_PRIVATE_DATA_HANDLE hPrivateData = &st->hIGFEnc->igfData; - for ( Word16 sfb = 0; sfb < 23; sfb++ ) - { - hPrivateData->prevSFM_FIR_SFB_TB[sfb] = me2f_16( hPrivateData->prevSFM_FIR_SFB_TB_fx[sfb], hPrivateData->prevSFB_FIR_TB_e[sfb] ); - hPrivateData->prevSFM_IIR_SFB_TB[sfb] = me2f_16( hPrivateData->prevSFM_IIR_SFB_TB_fx[sfb], hPrivateData->prevSFB_IIR_TB_e[sfb] ); - hPrivateData->prevSFM_FIR_SFB_SB[sfb] = me2f_16( hPrivateData->prevSFM_FIR_SFB_SB_fx[sfb], hPrivateData->prevSFB_FIR_SB_e[sfb] ); - hPrivateData->prevSFM_IIR_SFB_SB[sfb] = me2f_16( hPrivateData->prevSFM_IIR_SFB_SB_fx[sfb], hPrivateData->prevSFB_IIR_SB_e[sfb] ); - hPrivateData->SFM_tb[sfb] = me2f_16( hPrivateData->SFM_tb_fx[sfb], hPrivateData->sfb_tb_e[sfb] ); - hPrivateData->SFM_sb[sfb] = me2f_16( hPrivateData->SFM_sb_fx[sfb], hPrivateData->sfb_sb_e[sfb] ); - hPrivateData->prevDampingFactor_IIR[sfb] = me2f_16( hPrivateData->prevDampingFactor_IIR_fx[sfb], hPrivateData->prevDampingFactor_IIR_e[sfb] ); - } - - for ( i = 0; i < IGF_MAX_TILES; i++ ) - { - hPrivateData->prevSFM_FIR_flt[i] = fixedToFloat( hPrivateData->prevSFM_FIR[i], 16 ); /*15Q16*/ - hPrivateData->prevSFM_IIR_flt[i] = fixedToFloat( hPrivateData->prevSFM_IIR[i], 13 ); /*2Q13*/ - for ( int j = 0; j < IGF_PAST_SFM_LEN; j++ ) - { - hPrivateData->igfPastSFM[i][j] = fixedToFloat( hPrivateData->igfPastSFM_fx[i][j], 13 ); - } - } - } IF( NE_16( st->element_mode, IVAS_CPE_MDCT ) ) { diff --git a/lib_enc/ivas_spar_encoder.c b/lib_enc/ivas_spar_encoder.c index bb0a77866..788f9dec2 100644 --- a/lib_enc/ivas_spar_encoder.c +++ b/lib_enc/ivas_spar_encoder.c @@ -902,22 +902,6 @@ static ivas_error ivas_spar_cov_md_process_fx( move32(); } -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - FOR( b = 0; b < IVAS_MAX_NUM_BANDS; b++ ) - { - FOR( i = 0; i < IVAS_SPAR_MAX_CH - 1; i++ ) - { - hSpar->hMdEnc->spar_md.band_coeffs[b].P_re_fx[i] = L_shr( hSpar->hMdEnc->spar_md.band_coeffs[b].P_re_fx[i], Q6 ); - move32(); - hSpar->hMdEnc->spar_md.band_coeffs[b].pred_re_fx[i] = L_shr( hSpar->hMdEnc->spar_md.band_coeffs[b].pred_re_fx[i], Q6 ); - move32(); - } - hSpar->hMdEnc->spar_md.band_coeffs[b].q_P_re_fx = Q22; - move16(); - hSpar->hMdEnc->spar_md.band_coeffs[b].q_pred_re_fx = Q22; - move16(); - } -#endif IF( hSpar->hMdEnc->spar_hoa_md_flag == 0 ) { order = sba_order; @@ -928,23 +912,7 @@ static ivas_error ivas_spar_cov_md_process_fx( order = 1; move16(); } - ivas_get_spar_md_from_dirac_fx( azi_dirac_fx, ele_dirac_fx, diffuseness_fx, 1, hSpar->hMdEnc->mixer_mat_fx, &hSpar->hMdEnc->q_mixer_mat_fx, &hSpar->hMdEnc->spar_md, &hSpar->hMdEnc->spar_md_cfg, d_start_band, d_end_band, order, dtx_vad, Wscale_d_fx, hQMetaData->useLowerRes, active_w_vlbr, *dyn_active_w_flag ); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - FOR( b = 0; b < IVAS_MAX_NUM_BANDS; b++ ) - { - FOR( i = 0; i < IVAS_SPAR_MAX_CH - 1; i++ ) - { - hSpar->hMdEnc->spar_md.band_coeffs[b].P_re_fx[i] = L_shl( hSpar->hMdEnc->spar_md.band_coeffs[b].P_re_fx[i], Q6 ); - move32(); - hSpar->hMdEnc->spar_md.band_coeffs[b].pred_re_fx[i] = L_shl( hSpar->hMdEnc->spar_md.band_coeffs[b].pred_re_fx[i], Q6 ); - move32(); - } - hSpar->hMdEnc->spar_md.band_coeffs[b].q_P_re_fx = Q28; - move16(); - hSpar->hMdEnc->spar_md.band_coeffs[b].q_pred_re_fx = Q28; - move16(); - } -#endif + ivas_get_spar_md_from_dirac_enc_fx( azi_dirac_fx, ele_dirac_fx, diffuseness_fx, 1, hSpar->hMdEnc->mixer_mat_fx, &hSpar->hMdEnc->q_mixer_mat_fx, &hSpar->hMdEnc->spar_md, &hSpar->hMdEnc->spar_md_cfg, d_start_band, d_end_band, order, dtx_vad, Wscale_d_fx, hQMetaData->useLowerRes, active_w_vlbr, *dyn_active_w_flag ); } IF( hSpar->hMdEnc->spar_hoa_md_flag ) diff --git a/lib_enc/ivas_stereo_mdct_core_enc.c b/lib_enc/ivas_stereo_mdct_core_enc.c index 6854716ae..041913efd 100644 --- a/lib_enc/ivas_stereo_mdct_core_enc.c +++ b/lib_enc/ivas_stereo_mdct_core_enc.c @@ -1239,25 +1239,6 @@ void stereo_mdct_core_enc( hGrid = &hPrivateData->igfInfo.grid[(Word16) igfGridIdx]; me2f_buf( sts[ch]->hTcxEnc->spectrum_fx[n], sts[ch]->hTcxEnc->spectrum_e[n], sts[ch]->hTcxEnc->spectrum[n], hGrid->infoGranuleLen ); me2f_buf( &p_powerSpec_fx[ch][0], sts[ch]->hTcxEnc->spectrum_e[n], &p_powerSpec[ch][0], hGrid->infoGranuleLen ); - for ( Word16 sfb = 0; sfb < 23; sfb++ ) - { - hPrivateData->prevSFM_FIR_SFB_TB[sfb] = me2f_16( hPrivateData->prevSFM_FIR_SFB_TB_fx[sfb], hPrivateData->prevSFB_FIR_TB_e[sfb] ); - hPrivateData->prevSFM_IIR_SFB_TB[sfb] = me2f_16( hPrivateData->prevSFM_IIR_SFB_TB_fx[sfb], hPrivateData->prevSFB_IIR_TB_e[sfb] ); - hPrivateData->prevSFM_FIR_SFB_SB[sfb] = me2f_16( hPrivateData->prevSFM_FIR_SFB_SB_fx[sfb], hPrivateData->prevSFB_FIR_SB_e[sfb] ); - hPrivateData->prevSFM_IIR_SFB_SB[sfb] = me2f_16( hPrivateData->prevSFM_IIR_SFB_SB_fx[sfb], hPrivateData->prevSFB_IIR_SB_e[sfb] ); - hPrivateData->SFM_tb[sfb] = me2f_16( hPrivateData->SFM_tb_fx[sfb], hPrivateData->sfb_tb_e[sfb] ); - hPrivateData->SFM_sb[sfb] = me2f_16( hPrivateData->SFM_sb_fx[sfb], hPrivateData->sfb_sb_e[sfb] ); - hPrivateData->prevDampingFactor_IIR[sfb] = me2f_16( hPrivateData->prevDampingFactor_IIR_fx[sfb], hPrivateData->prevDampingFactor_IIR_e[sfb] ); - } - for ( i = 0; i < IGF_MAX_TILES; i++ ) - { - hPrivateData->prevSFM_FIR_flt[i] = fixedToFloat( hPrivateData->prevSFM_FIR[i], 16 ); /*15Q16*/ - hPrivateData->prevSFM_IIR_flt[i] = fixedToFloat( hPrivateData->prevSFM_IIR[i], 13 ); /*2Q13*/ - for ( int j = 0; j < IGF_PAST_SFM_LEN; j++ ) - { - hPrivateData->igfPastSFM[i][j] = fixedToFloat( hPrivateData->igfPastSFM_fx[i][j], 13 ); - } - } } #endif /**********************************fix to flt ends here*******************************************************/ #else @@ -1298,14 +1279,9 @@ void stereo_mdct_core_enc( q_spectrum = L_get_q_buf1( orig_spectrum[ch][n], hPrivateData->igfInfo.grid[igfGridIdx].stopLine ); if ( st->hIGFEnc ) { - q_spectrum = min( q_spectrum, L_get_q_buf1( st->hIGFEnc->spec_be_igf_flt, hPrivateData->igfInfo.grid[igfGridIdx].stopLine - IGF_START_MN ) ); + q_spectrum = min( q_spectrum, 31 - st->hIGFEnc->spec_be_igf_e ); } floatToFixed_arrL32( orig_spectrum[ch][n], orig_spectrum_fx[ch][n], q_spectrum, hPrivateData->igfInfo.grid[igfGridIdx].stopLine ); - if ( st->hIGFEnc ) - { - floatToFixed_arrL32( st->hIGFEnc->spec_be_igf_flt, st->hIGFEnc->spec_be_igf, q_spectrum, hPrivateData->igfInfo.grid[igfGridIdx].stopLine - IGF_START_MN ); - st->hIGFEnc->spec_be_igf_e = 31 - q_spectrum; - } q_spectrum = L_get_q_buf1( st->hTcxEnc->spectrum[n], hPrivateData->igfInfo.grid[igfGridIdx].infoGranuleLen ); floatToFixed_arrL32( st->hTcxEnc->spectrum[n], st->hTcxEnc->spectrum_fx[n], q_spectrum, hPrivateData->igfInfo.grid[igfGridIdx].infoGranuleLen ); @@ -1319,33 +1295,6 @@ void stereo_mdct_core_enc( #ifdef IVAS_FLOAT_FIXED_CONVERSIONS fixedToFloat_arrL32( st->hTcxEnc->spectrum_fx[n], st->hTcxEnc->spectrum[n], q_spectrum, hPrivateData->igfInfo.grid[igfGridIdx].infoGranuleLen ); fixedToFloat_arrL32( &powerSpec_fx[ch][n * L_subframeTCX], &powerSpec[ch][n * L_subframeTCX], q_powerSpec, hPrivateData->igfInfo.grid[igfGridIdx].infoGranuleLen ); - - if ( st->hIGFEnc ) - { - st->hIGFEnc->tns_predictionGain_flt = fix16_to_float( st->hIGFEnc->tns_predictionGain, Q23 ); - me2f_buf( st->hIGFEnc->spec_be_igf, st->hIGFEnc->spec_be_igf_e, st->hIGFEnc->spec_be_igf_flt, hPrivateData->igfInfo.grid[igfGridIdx].stopLine - IGF_START_MN ); - } - - for ( Word16 sfb = 0; sfb < 23; sfb++ ) - { - hPrivateData->prevSFM_FIR_SFB_TB[sfb] = me2f_16( hPrivateData->prevSFM_FIR_SFB_TB_fx[sfb], hPrivateData->prevSFB_FIR_TB_e[sfb] ); - hPrivateData->prevSFM_IIR_SFB_TB[sfb] = me2f_16( hPrivateData->prevSFM_IIR_SFB_TB_fx[sfb], hPrivateData->prevSFB_IIR_TB_e[sfb] ); - hPrivateData->prevSFM_FIR_SFB_SB[sfb] = me2f_16( hPrivateData->prevSFM_FIR_SFB_SB_fx[sfb], hPrivateData->prevSFB_FIR_SB_e[sfb] ); - hPrivateData->prevSFM_IIR_SFB_SB[sfb] = me2f_16( hPrivateData->prevSFM_IIR_SFB_SB_fx[sfb], hPrivateData->prevSFB_IIR_SB_e[sfb] ); - hPrivateData->SFM_tb[sfb] = me2f_16( hPrivateData->SFM_tb_fx[sfb], hPrivateData->sfb_tb_e[sfb] ); - hPrivateData->SFM_sb[sfb] = me2f_16( hPrivateData->SFM_sb_fx[sfb], hPrivateData->sfb_sb_e[sfb] ); - hPrivateData->prevDampingFactor_IIR[sfb] = me2f_16( hPrivateData->prevDampingFactor_IIR_fx[sfb], hPrivateData->prevDampingFactor_IIR_e[sfb] ); - } - - for ( i = 0; i < IGF_MAX_TILES; i++ ) - { - hPrivateData->prevSFM_FIR_flt[i] = fixedToFloat( hPrivateData->prevSFM_FIR[i], 16 ); /*15Q16*/ - hPrivateData->prevSFM_IIR_flt[i] = fixedToFloat( hPrivateData->prevSFM_IIR[i], 13 ); /*2Q13*/ - for ( int j = 0; j < IGF_PAST_SFM_LEN; j++ ) - { - hPrivateData->igfPastSFM[i][j] = fixedToFloat( hPrivateData->igfPastSFM_fx[i][j], 13 ); - } - } #endif #else ProcessIGF( st, st->hTcxEnc->spectrum[n], orig_spectrum[ch][n], &powerSpec[ch][n * L_subframeTCX], st->core == TCX_20_CORE, n, hCPE->hCoreCoder[0]->sp_aud_decision0, 0 ); @@ -1395,14 +1344,9 @@ void stereo_mdct_core_enc( q_spectrum = L_get_q_buf1( orig_spectrum[ch][n], hPrivateData->igfInfo.grid[igfGridIdx].stopLine ); if ( st->hIGFEnc ) { - q_spectrum = min( q_spectrum, L_get_q_buf1( st->hIGFEnc->spec_be_igf_flt, hPrivateData->igfInfo.grid[igfGridIdx].stopLine - IGF_START_MN ) ); + q_spectrum = min( q_spectrum, 31 - st->hIGFEnc->spec_be_igf_e ); } floatToFixed_arrL32( orig_spectrum[ch][n], orig_spectrum_fx[ch][n], q_spectrum, hPrivateData->igfInfo.grid[igfGridIdx].stopLine ); - if ( st->hIGFEnc ) - { - floatToFixed_arrL32( st->hIGFEnc->spec_be_igf_flt, st->hIGFEnc->spec_be_igf, q_spectrum, hPrivateData->igfInfo.grid[igfGridIdx].stopLine - IGF_START_MN ); - st->hIGFEnc->spec_be_igf_e = 31 - q_spectrum; - } q_spectrum = L_get_q_buf1( st->hTcxEnc->spectrum[n], hPrivateData->igfInfo.grid[igfGridIdx].infoGranuleLen ); floatToFixed_arrL32( st->hTcxEnc->spectrum[n], st->hTcxEnc->spectrum_fx[n], q_spectrum, hPrivateData->igfInfo.grid[igfGridIdx].infoGranuleLen ); @@ -1410,42 +1354,11 @@ void stereo_mdct_core_enc( q_powerSpec = L_get_q_buf1( &powerSpec[ch][n * L_subframeTCX], hPrivateData->igfInfo.grid[igfGridIdx].infoGranuleLen ); floatToFixed_arrL32( &powerSpec[ch][n * L_subframeTCX], &powerSpec_fx[ch][n * L_subframeTCX], q_powerSpec, hPrivateData->igfInfo.grid[igfGridIdx].infoGranuleLen ); - if ( st->hIGFEnc ) - { - st->hIGFEnc->tns_predictionGain = float_to_fix16( st->hIGFEnc->tns_predictionGain_flt, Q23 ); - } #endif ProcessIGF_ivas_fx( st, st->hTcxEnc->spectrum_fx[n], orig_spectrum_fx[ch][n], &q_spectrum, &powerSpec_fx[ch][n * L_subframeTCX], &q_powerSpec, st->core == TCX_20_CORE, n, hCPE->hCoreCoder[0]->sp_aud_decision0, 0 ); #ifdef IVAS_FLOAT_FIXED_CONVERSIONS fixedToFloat_arrL32( st->hTcxEnc->spectrum_fx[n], st->hTcxEnc->spectrum[n], q_spectrum, hPrivateData->igfInfo.grid[igfGridIdx].infoGranuleLen ); fixedToFloat_arrL32( &powerSpec_fx[ch][n * L_subframeTCX], &powerSpec[ch][n * L_subframeTCX], q_powerSpec, hPrivateData->igfInfo.grid[igfGridIdx].infoGranuleLen ); - - if ( st->hIGFEnc ) - { - st->hIGFEnc->tns_predictionGain_flt = fix16_to_float( st->hIGFEnc->tns_predictionGain, Q23 ); - me2f_buf( st->hIGFEnc->spec_be_igf, st->hIGFEnc->spec_be_igf_e, st->hIGFEnc->spec_be_igf_flt, hPrivateData->igfInfo.grid[igfGridIdx].stopLine - IGF_START_MN ); - } - - for ( Word16 sfb = 0; sfb < 23; sfb++ ) - { - hPrivateData->prevSFM_FIR_SFB_TB[sfb] = me2f_16( hPrivateData->prevSFM_FIR_SFB_TB_fx[sfb], hPrivateData->prevSFB_FIR_TB_e[sfb] ); - hPrivateData->prevSFM_IIR_SFB_TB[sfb] = me2f_16( hPrivateData->prevSFM_IIR_SFB_TB_fx[sfb], hPrivateData->prevSFB_IIR_TB_e[sfb] ); - hPrivateData->prevSFM_FIR_SFB_SB[sfb] = me2f_16( hPrivateData->prevSFM_FIR_SFB_SB_fx[sfb], hPrivateData->prevSFB_FIR_SB_e[sfb] ); - hPrivateData->prevSFM_IIR_SFB_SB[sfb] = me2f_16( hPrivateData->prevSFM_IIR_SFB_SB_fx[sfb], hPrivateData->prevSFB_IIR_SB_e[sfb] ); - hPrivateData->SFM_tb[sfb] = me2f_16( hPrivateData->SFM_tb_fx[sfb], hPrivateData->sfb_tb_e[sfb] ); - hPrivateData->SFM_sb[sfb] = me2f_16( hPrivateData->SFM_sb_fx[sfb], hPrivateData->sfb_sb_e[sfb] ); - hPrivateData->prevDampingFactor_IIR[sfb] = me2f_16( hPrivateData->prevDampingFactor_IIR_fx[sfb], hPrivateData->prevDampingFactor_IIR_e[sfb] ); - } - - for ( i = 0; i < IGF_MAX_TILES; i++ ) - { - hPrivateData->prevSFM_FIR_flt[i] = fixedToFloat( hPrivateData->prevSFM_FIR[i], 16 ); /*15Q16*/ - hPrivateData->prevSFM_IIR_flt[i] = fixedToFloat( hPrivateData->prevSFM_IIR[i], 13 ); /*2Q13*/ - for ( int j = 0; j < IGF_PAST_SFM_LEN; j++ ) - { - hPrivateData->igfPastSFM[i][j] = fixedToFloat( hPrivateData->igfPastSFM_fx[i][j], 13 ); - } - } #endif #else ProcessIGF( st, st->hTcxEnc->spectrum[n], orig_spectrum[ch][n], &powerSpec[ch][n * L_subframeTCX], st->core == TCX_20_CORE, n, hCPE->hCoreCoder[0]->sp_aud_decision0, 0 ); diff --git a/lib_enc/stat_enc.h b/lib_enc/stat_enc.h index 849397efc..d067986e2 100644 --- a/lib_enc/stat_enc.h +++ b/lib_enc/stat_enc.h @@ -632,18 +632,18 @@ typedef struct fd_cng_enc_structure typedef struct dtx_enc_structure { - int16_t cnt_SID; /* CNG and DTX - counter of SID update for the interop. mode or DTX, if enabled */ - int16_t first_CNG; /* CNG and DTX - first CNG frame flag */ - int16_t cng_cnt; /* CNG and DTX - counter of CNG frames for averaging */ - int16_t max_SID; /* CNG and DTX - max allowed number of CNG FRAME_NO_DATA frames */ - int16_t CNG_mode; /* CNG and DTX - mode for DTX configuration */ + Word16 cnt_SID; /* CNG and DTX - counter of SID update for the interop. mode or DTX, if enabled */ + Word16 first_CNG; /* CNG and DTX - first CNG frame flag */ + Word16 cng_cnt; /* CNG and DTX - counter of CNG frames for averaging */ + Word16 max_SID; /* CNG and DTX - max allowed number of CNG FRAME_NO_DATA frames */ + Word16 CNG_mode; /* CNG and DTX - mode for DTX configuration */ #ifndef IVAS_FLOAT_FIXED float lspCNG[M]; /* CNG and DTX - LP filtered ISPs */ #else Word16 lspCNG_fx[M]; /* CNG and DTX - LP filtered lsps Q15 */ #endif - int16_t VarDTX_cnt_voiced; /* CNG and DTX - counter for variable DTX activation (speech) */ - int16_t VarDTX_cnt_noise; /* CNG and DTX - counter for variable DTX activation (noise) */ + Word16 VarDTX_cnt_voiced; /* CNG and DTX - counter for variable DTX activation (speech) */ + Word16 VarDTX_cnt_noise; /* CNG and DTX - counter for variable DTX activation (noise) */ #ifndef IVAS_FLOAT_FIXED float lt_ener_voiced; /* CNG and DTX - long-term energy of signal (measured on voiced parts) */ float lt_ener_noise; /* CNG and DTX - long-term energy of background noise */ @@ -653,16 +653,16 @@ typedef struct dtx_enc_structure Word32 lt_ener_noise_fx; /* CNG and DTX - long-term energy of background noise Q(-7) */ Word32 frame_ener_fx; /* Q(-7) */ #endif - int16_t cng_hist_size; /* CNG and DTX - size of CNG history buffer for averaging, <0,DTX_HIST_SIZE> */ + Word16 cng_hist_size; /* CNG and DTX - size of CNG history buffer for averaging, <0,DTX_HIST_SIZE> */ #ifndef IVAS_FLOAT_FIXED float lt_ener_last_SID; /* CNG and DTX - long-term energy of last SID frame */ #else Word32 lt_ener_last_SID_fx; /* CNG and DTX - long-term energy of last SID frame Q(-7) */ #endif - int16_t last_CNG_L_frame; /* CNG and DTX - last CNG frame length */ - int16_t var_SID_rate_flag; /* CNG and DTX - flag for variable SID rate */ - int16_t interval_SID; /* CNG and DTX - interval of SID update, default 8 */ - int32_t last_active_brate; /* CNG and DTX - last active frame bitrate used for CNG_mode control */ + Word16 last_CNG_L_frame; /* CNG and DTX - last CNG frame length */ + Word16 var_SID_rate_flag; /* CNG and DTX - flag for variable SID rate */ + Word16 interval_SID; /* CNG and DTX - interval of SID update, default 8 */ + Word32 last_active_brate; /* CNG and DTX - last active frame bitrate used for CNG_mode control */ } DTX_ENC_DATA, *DTX_ENC_HANDLE; @@ -698,7 +698,7 @@ typedef struct igfscfenc_public_data_struct typedef struct igf_enc_private_data_struct { IGF_INFO igfInfo; - int16_t igfScfQuantized[IGF_MAX_SFB]; + Word16 igfScfQuantized[IGF_MAX_SFB]; IGFSCFENC_INSTANCE hIGFSCFArithEnc; #ifdef IVAS_FLOAT_FIXED Word16 prevSFM_FIR_SFB_TB_fx[IGF_MAX_SFB]; @@ -718,31 +718,21 @@ typedef struct igf_enc_private_data_struct Word16 igfPastSFM_fx[IGF_MAX_TILES][IGF_PAST_SFM_LEN]; /*2Q13*/ #endif // IVAS_FLOAT_FIXED - float prevSFM_FIR_SFB_TB[IGF_MAX_SFB]; - float prevSFM_IIR_SFB_TB[IGF_MAX_SFB]; - float prevSFM_FIR_SFB_SB[IGF_MAX_SFB]; - float prevSFM_IIR_SFB_SB[IGF_MAX_SFB]; - int16_t logSpec[L_FRAME_PLUS]; - - float prevDampingFactor_IIR[IGF_MAX_SFB]; - int16_t dampingFactorSmoothing[IGF_MAX_SFB]; - float SFM_tb[IGF_MAX_SFB]; - float SFM_sb[IGF_MAX_SFB]; - - int16_t igfCurrWhiteningLevel[IGF_MAX_TILES]; - int16_t igfPrevWhiteningLevel[IGF_MAX_TILES]; - int16_t igfWhiteningHangoverCnt[IGF_MAX_TILES]; - float igfPastSFM[IGF_MAX_TILES][IGF_PAST_SFM_LEN]; - int16_t igfPastSFM_pos; - - float prevSFM_FIR_flt[IGF_MAX_TILES]; - float prevSFM_IIR_flt[IGF_MAX_TILES]; + Word16 logSpec[L_FRAME_PLUS]; + + Word16 dampingFactorSmoothing[IGF_MAX_SFB]; + + Word16 igfCurrWhiteningLevel[IGF_MAX_TILES]; + Word16 igfPrevWhiteningLevel[IGF_MAX_TILES]; + Word16 igfWhiteningHangoverCnt[IGF_MAX_TILES]; + Word16 igfPastSFM_pos; + Word32 prevSFM_FIR[IGF_MAX_TILES]; /* 15Q16 */ Word16 prevSFM_IIR[IGF_MAX_TILES]; /* 2Q13 */ - int16_t wasTransient; + Word16 wasTransient; UWord8 igfBitstream[IGF_BITBUFSIZE / 8]; - int16_t igfBitstreamBits; + Word16 igfBitstreamBits; } IGF_ENC_PRIVATE_DATA, *IGF_ENC_PRIVATE_DATA_HANDLE; @@ -750,16 +740,14 @@ typedef struct igf_enc_private_data_struct typedef struct igf_enc_instance_struct { IGF_ENC_PRIVATE_DATA igfData; - int32_t infoSamplingRate; - int16_t infoStartFrequency; - int16_t infoStopFrequency; - int16_t infoStartLine; - int16_t infoStopLine; - int16_t infoTotalBitsWritten; - int16_t infoTotalBitsPerFrameWritten; - int16_t flatteningTrigger; - float spec_be_igf_flt[N_MAX_TCX - IGF_START_MN]; - float tns_predictionGain_flt; + Word32 infoSamplingRate; + Word16 infoStartFrequency; + Word16 infoStopFrequency; + Word16 infoStartLine; + Word16 infoStopLine; + Word16 infoTotalBitsWritten; + Word16 infoTotalBitsPerFrameWritten; + Word16 flatteningTrigger; Word32 spec_be_igf[N_MAX_TCX - IGF_START_MN]; /* copy of MDCT spectrum */ Word16 spec_be_igf_e; /* exponent of copy of MDCT spectrum */ Word16 tns_predictionGain; -- GitLab From ed67d2f56167b001f0c53c771c3cbbfcc53bbac1 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Thu, 7 Nov 2024 18:38:11 +0530 Subject: [PATCH 095/128] Fix for 3GPP issue 887: Noise burst during silence in ISM 2 at 48 kbps [x] Bug fix in generate_comfort_noise_dec_ivas_fx --- lib_dec/fd_cng_dec_fx.c | 952 ++++++++++++++++++++-------------------- 1 file changed, 476 insertions(+), 476 deletions(-) diff --git a/lib_dec/fd_cng_dec_fx.c b/lib_dec/fd_cng_dec_fx.c index ae5f0c2b1..cce8ed419 100644 --- a/lib_dec/fd_cng_dec_fx.c +++ b/lib_dec/fd_cng_dec_fx.c @@ -73,7 +73,7 @@ ivas_error createFdCngDec_fx( HANDLE_FD_CNG_DEC *hFdCngDec ) #ifdef IVAS_FLOAT_FIXED void initFdCngDec_ivas_fx( DEC_CORE_HANDLE st, /* i/o: decoder state structure */ - Word16 scale ) + Word16 scale /*Q15*/ ) { /* Initialize common */ HANDLE_FD_CNG_DEC hFdCngDec; @@ -176,14 +176,14 @@ void initFdCngDec_ivas_fx( move16(); hFdCngDec->cna_rescale_fact_fx = 0; move16(); - hFdCngDec->cna_seed = 5687; + hFdCngDec->cna_seed = 5687; /*Q0*/ move16(); set16_fx( hFdCngDec->cna_cm_fx, 0, STEREO_DFT_BAND_MAX ); set16_fx( hFdCngDec->cna_g_state_fx, 0, STEREO_DFT_BAND_MAX ); st->CNG_mode = -1; move16(); - Copy( st->lsp_old_fx, st->lspCNG_fx, M ); + Copy( st->lsp_old_fx, st->lspCNG_fx, M ); /*Q15*/ #ifdef MSAN_FIX hFdCngDec->hFdCngCom->sid_frame_counter = 0; #endif @@ -192,7 +192,7 @@ void initFdCngDec_ivas_fx( void initFdCngDec_fx( DEC_CORE_HANDLE st, /* i/o: decoder state structure */ - Word16 scale ) + Word16 scale /*Q15*/ ) { /* Initialize common */ HANDLE_FD_CNG_DEC hFdCngDec; @@ -322,17 +322,17 @@ void initFdCngDec_fx( */ void configureFdCngDec_fx( HANDLE_FD_CNG_DEC hFdCngDec, /* i/o: Contains the variables related to the CLDFB-based CNG process */ - Word16 bwidth, - Word32 total_brate, - Word16 L_frame, - const Word16 Last_L_frame, - const Word16 element_mode ) + Word16 bwidth, /*Q0*/ + Word32 total_brate, /*Q0*/ + Word16 L_frame, /*Q0*/ + const Word16 Last_L_frame, /*Q0*/ + const Word16 element_mode /*Q0*/ ) { Word16 j, stopBandFR; HANDLE_FD_CNG_COM hsCom = hFdCngDec->hFdCngCom; - hsCom->CngBandwidth = bwidth; + hsCom->CngBandwidth = bwidth; /*Q0*/ move16(); if ( EQ_16( hsCom->CngBandwidth, FB ) ) { @@ -342,7 +342,7 @@ void configureFdCngDec_fx( test(); IF( total_brate != FRAME_NO_DATA && NE_32( total_brate, SID_2k40 ) ) { - hsCom->CngBitrate = total_brate; + hsCom->CngBitrate = total_brate; /*Q0*/ move32(); } ELSE IF( EQ_32( hsCom->CngBitrate, -1 ) ) @@ -454,16 +454,16 @@ void configureFdCngDec_fx( } } } - hsCom->fftlen = hsCom->FdCngSetup.fftlen; + hsCom->fftlen = hsCom->FdCngSetup.fftlen; /*Q0*/ move16(); - hsCom->stopFFTbin = hsCom->FdCngSetup.stopFFTbin; + hsCom->stopFFTbin = hsCom->FdCngSetup.stopFFTbin; /*Q0*/ move16(); /* Configure the SID quantizer and the Confort Noise Generator */ hsCom->startBand = 2; move16(); - hsCom->stopBand = add( hsCom->FdCngSetup.sidPartitions[sub( hsCom->FdCngSetup.numPartitions, 1 )], 1 ); + hsCom->stopBand = add( hsCom->FdCngSetup.sidPartitions[( hsCom->FdCngSetup.numPartitions - 1 )], 1 ); /*Q0*/ move16(); initPartitions( hsCom->FdCngSetup.sidPartitions, hsCom->FdCngSetup.numPartitions, hsCom->startBand, hsCom->stopBand, hsCom->part, &hsCom->npart, hsCom->midband, hsCom->psize, hsCom->psize_norm, &hsCom->psize_norm_exp, hsCom->psize_inv, 0 ); @@ -485,9 +485,9 @@ void configureFdCngDec_fx( move16(); FOR( j = 0; j < hsCom->nCLDFBpart; j++ ) { - hsCom->CLDFBpart[j] = sub( hsCom->part[add( j, hsCom->nFFTpart )], sub( hsCom->stopFFTbin, hsCom->startBand ) ); + hsCom->CLDFBpart[j] = sub( hsCom->part[( j + hsCom->nFFTpart )], sub( hsCom->stopFFTbin, hsCom->startBand ) ); /*Q0*/ move16(); - hsCom->CLDFBpsize_inv[j] = hsCom->psize_inv[add( j, hsCom->nFFTpart )]; + hsCom->CLDFBpsize_inv[j] = hsCom->psize_inv[( j + hsCom->nFFTpart )]; /*Q15*/ move16(); } @@ -495,14 +495,14 @@ void configureFdCngDec_fx( move16(); if ( GT_16( stopBandFR, hsCom->stopFFTbin ) ) { - stopBandFR = hsCom->stopFFTbin; + stopBandFR = hsCom->stopFFTbin; /*Q0*/ move16(); } initPartitions( hsCom->FdCngSetup.shapingPartitions, hsCom->FdCngSetup.numShapingPartitions, hsCom->startBand, hsCom->stopFFTbin, hFdCngDec->part_shaping, &hFdCngDec->npart_shaping, hFdCngDec->midband_shaping, hFdCngDec->psize_shaping, hFdCngDec->psize_shaping_norm, &hFdCngDec->psize_shaping_norm_exp, hFdCngDec->psize_inv_shaping, stopBandFR ); - hFdCngDec->nFFTpart_shaping = hFdCngDec->npart_shaping; + hFdCngDec->nFFTpart_shaping = hFdCngDec->npart_shaping; /*Q0*/ move16(); SWITCH( hsCom->fftlen ) @@ -579,17 +579,17 @@ void deleteFdCngDec_fx( HANDLE_FD_CNG_DEC *hFdCngDec ) error */ Word16 ApplyFdCng_fx( - Word16 *timeDomainInput, /* i : pointer to time domain input */ + Word16 *timeDomainInput, /* i : pointer to time domain input Q*/ Word16 Q, #ifdef IVAS_CODE_CNG_FIX185_PLC_FADEOUT Word16 *powerSpectrum, #endif - Word32 **cldfbBufferReal, /* i/o: real part of the CLDFB buffer */ - Word32 **cldfbBufferImag, /* i/o: imaginary part of the CLDFB buffer */ + Word32 **cldfbBufferReal, /* i/o: real part of the CLDFB buffer cldfbBufferScale*/ + Word32 **cldfbBufferImag, /* i/o: imaginary part of the CLDFB buffer cldfbBufferScale*/ Word16 *cldfbBufferScale, /* o : pointer to the scalefactor for real and imaginary part of the CLDFB buffer */ Decoder_State *st, - const Word16 concealWholeFrame, /* i : binary flag indicating frame loss */ - Word16 is_music ) + const Word16 concealWholeFrame, /* i : binary flag indicating frame loss Q0*/ + Word16 is_music /*Q0*/ ) { Word16 j, k, nBins; Word16 s, s1, s2, num, denom; @@ -636,7 +636,7 @@ Word16 ApplyFdCng_fx( test(); move16(); } - cngNoiseLevel = hFdCngCom->cngNoiseLevel; + cngNoiseLevel = hFdCngCom->cngNoiseLevel; /*Q31 - hFdCngCom->cngNoiseLevelExp*/ move32(); cngNoiseLevel_exp = &hFdCngCom->cngNoiseLevelExp; move16(); @@ -743,21 +743,21 @@ Word16 ApplyFdCng_fx( IF( hFdCngDec->partNoiseShape[k] != 0 ) { s1 = norm_l( hFdCngCom->sidNoiseEst[k] ); - L_tmp = L_shl( hFdCngCom->sidNoiseEst[k], s1 ); + L_tmp = L_shl( hFdCngCom->sidNoiseEst[k], s1 ); /*Q31 - hFdCngCom->sidNoiseEstExp + s1*/ L_tmp_exp = sub( hFdCngCom->sidNoiseEstExp, s1 ); L_tmp = BASOP_Util_Add_Mant32Exp( L_tmp, L_tmp_exp, DELTA_MANTISSA_W32, DELTA_EXPONENT, &L_tmp_exp ); L_tmp = L_shr( L_tmp, 1 ); s = add( L_tmp_exp, 1 ); - num = extract_h( L_tmp ); + num = extract_h( L_tmp ); /*Q15 - L_tmp_exp*/ s1 = norm_l( hFdCngDec->partNoiseShape[k] ); - L_tmp = L_shl( hFdCngDec->partNoiseShape[k], s1 ); + L_tmp = L_shl( hFdCngDec->partNoiseShape[k], s1 ); /*Q31 - hFdCngDec->partNoiseShape_exp + s1*/ L_tmp_exp = sub( hFdCngDec->partNoiseShape_exp, s1 ); L_tmp = BASOP_Util_Add_Mant32Exp( L_tmp, L_tmp_exp, DELTA_MANTISSA_W32, DELTA_EXPONENT, &L_tmp_exp ); s = sub( s, L_tmp_exp ); - denom = extract_h( L_tmp ); + denom = extract_h( L_tmp ); /*Q15 - L_tmp_exp*/ - facTab[k] = div_s( num, denom ); + facTab[k] = div_s( num, denom ); /*Q15 - s*/ move16(); facTabExp[k] = s; move16(); @@ -777,7 +777,7 @@ Word16 ApplyFdCng_fx( s = s_max( s_min( s, WORD32_BITS - 1 ), -( WORD32_BITS - 1 ) ); FOR( ; j <= hFdCngCom->part[k]; j++ ) { - cngNoiseLevel[j] = L_shl( Mpy_32_16_1( hFdCngDec->bandNoiseShape[j], facTab[k] ), s ); + cngNoiseLevel[j] = L_shl( Mpy_32_16_1( hFdCngDec->bandNoiseShape[j], facTab[k] ), s ); /*Q31 - hFdCngDec->bandNoiseShape_exp*/ move32(); } } @@ -790,7 +790,7 @@ Word16 ApplyFdCng_fx( { FOR( ; j <= hFdCngCom->part[k]; j++ ) { - cngNoiseLevel[j] = L_shl( cngNoiseLevel[j], s ); + cngNoiseLevel[j] = L_shl( cngNoiseLevel[j], s ); /*Q31 - hFdCngDec->bandNoiseShape_exp + s*/ move32(); } } @@ -807,7 +807,7 @@ Word16 ApplyFdCng_fx( test(); IF( !( EQ_16( st->element_mode, IVAS_CPE_TD ) ) || ( EQ_16( st->element_mode, IVAS_CPE_TD ) && !hFdCngDec->flag_dtx_mode && !st->VAD ) ) { - Copy32( hFdCngDec->bandNoiseShape, cngNoiseLevel, nBins ); + Copy32( hFdCngDec->bandNoiseShape, cngNoiseLevel, nBins ); /*Q31 - hFdCngDec->bandNoiseShape_exp*/ *cngNoiseLevel_exp = hFdCngDec->bandNoiseShape_exp; move16(); } @@ -832,7 +832,7 @@ Word16 ApplyFdCng_fx( Carry = 0; move16(); #ifdef BASOP_NOGLOB - L_tmp = L_add_co( L_tmp, *( cngNoiseLevel + j ), &Carry, &Overflow ); + L_tmp = L_add_co( L_tmp, *( cngNoiseLevel + j ), &Carry, &Overflow ); /*Q31*/ #else L_tmp = L_add_c( L_tmp, *( cngNoiseLevel + j ) ); #endif @@ -841,28 +841,28 @@ Word16 ApplyFdCng_fx( IF( *( cngNoiseLevel + j ) < 0 ) { - L_c = L_msuNs( L_c, 0, 0 ); + L_c = L_msuNs( L_c, 0, 0 ); /*Q-1*/ } IF( *( cngNoiseLevel + j ) >= 0 ) { #ifdef BASOP_NOGLOB - L_c = L_macNs_co( L_c, 0, 0, &Carry, &Overflow ); + L_c = L_macNs_co( L_c, 0, 0, &Carry, &Overflow ); /*Q-1*/ #else L_c = L_macNs( L_c, 0, 0 ); #endif } } - L_tmp = norm_llQ31( L_c, L_tmp, &L_tmp_exp ); + L_tmp = norm_llQ31( L_c, L_tmp, &L_tmp_exp ); /*Q31 - L_tmp_exp*/ L_tmp_exp = sub( add( L_tmp_exp, *cngNoiseLevel_exp ), 1 ); - L_tmp = Mpy_32_16_1( L_tmp, hFdCngCom->fftlen ); /*Q16*/ + L_tmp = Mpy_32_16_1( L_tmp, hFdCngCom->fftlen ); /*Q16 - L_tmp_exp*/ L_tmp = Mpy_32_16_1( L_tmp, T_DIV_L_Frame[L_shl( L_mac( -28000, st->L_frame, 95 ), 1 - 15 )] ); /*Q16,exp -7*/ L_tmp_exp = add( L_tmp_exp, -7 ); /*->Q16, L_tmp_exp */ L_tmp_exp = add( L_tmp_exp, 31 - 16 ); /*->Q31, L_tmp_exp*/ #ifdef BASOP_NOGLOB - st->cngTDLevel = round_fx_sat( Sqrt32( L_tmp, &L_tmp_exp ) ); + st->cngTDLevel = round_fx_sat( Sqrt32( L_tmp, &L_tmp_exp ) ); /*Q15 - L_tmp_exp*/ #else st->cngTDLevel = round_fx( Sqrt32( L_tmp, &L_tmp_exp ) ); #endif @@ -901,7 +901,7 @@ Word16 ApplyFdCng_fx( #ifndef IVAS_CODE_CNG_FIX185_PLC_FADEOUT lpc_from_spectrum( hFdCngCom, hFdCngCom->startBand, hFdCngCom->stopFFTbin, 0 ); E_LPC_a_lsp_conversion( hFdCngCom->A_cng, lsp_cng, st->lspold_cng, M ); - Copy( lsp_cng, st->lspold_cng, M ); + Copy( lsp_cng, st->lspold_cng, M ); /*Q15*/ lsp2lsf_fx( lsp_cng, st->lsf_cng, M, st->sr_core ); #else @@ -982,7 +982,7 @@ Word16 ApplyFdCng_fx( hFdCngDec->bandNoiseShape_exp = hFdCngDec->msNoiseEst_exp; move16(); /* This sets the new CNG levels until a SID update overwrites it */ - Copy32( hFdCngDec->bandNoiseShape, cngNoiseLevel, sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ) ); /* This sets the new CNG levels until a SID update overwrites it */ + Copy32( hFdCngDec->bandNoiseShape, cngNoiseLevel, sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ) ); /* This sets the new CNG levels until a SID update overwrites it Q31 - hFdCngDec->bandNoiseShape_exp*/ *cngNoiseLevel_exp = hFdCngDec->bandNoiseShape_exp; move16(); #ifdef IVAS_CODE_CNG_FIX185_PLC_FADEOUT @@ -998,17 +998,17 @@ Word16 ApplyFdCng_fx( Carry = 0; move16(); #ifdef BASOP_NOGLOB /* Critical Carry/Overflow */ - L_tmp = L_add_co( L_tmp, *( cngNoiseLevel + j ), &Carry, &Overflow ); + L_tmp = L_add_co( L_tmp, *( cngNoiseLevel + j ), &Carry, &Overflow ); /*Q31*/ Overflow = 0; move16(); IF( *( cngNoiseLevel + j ) < 0 ) { - L_c = L_msuNs_co( L_c, 0, 0, &Carry, &Overflow ); + L_c = L_msuNs_co( L_c, 0, 0, &Carry, &Overflow ); /*Q-1*/ } IF( *( cngNoiseLevel + j ) >= 0 ) { - L_c = L_macNs_co( L_c, 0, 0, &Carry, &Overflow ); + L_c = L_macNs_co( L_c, 0, 0, &Carry, &Overflow ); /*Q-1*/ } #else L_tmp = L_add_c( L_tmp, *( cngNoiseLevel + j ) ); @@ -1024,17 +1024,17 @@ Word16 ApplyFdCng_fx( } #endif } - L_tmp = norm_llQ31( L_c, L_tmp, &L_tmp_exp ); + L_tmp = norm_llQ31( L_c, L_tmp, &L_tmp_exp ); /*Q31 - L_tmp_exp*/ L_tmp_exp = sub( add( L_tmp_exp, *cngNoiseLevel_exp ), 1 ); - L_tmp = Mpy_32_16_1( L_tmp, hFdCngCom->fftlen ); /*Q16*/ + L_tmp = Mpy_32_16_1( L_tmp, hFdCngCom->fftlen ); /*Q16 - L_tmp_exp*/ L_tmp = Mpy_32_16_1( L_tmp, T_DIV_L_Frame[L_shl( L_mac( -28000, st->L_frame, 95 ), 1 - 15 )] ); /*Q16,exp -7*/ L_tmp_exp = add( L_tmp_exp, -7 ); /*->Q16, L_tmp_exp */ L_tmp_exp = add( L_tmp_exp, 31 - 16 ); /*->Q31, L_tmp_exp*/ #ifdef BASOP_NOGLOB /* Critical Carry/Overflow */ - st->cngTDLevel = round_fx_o( Sqrt32( L_tmp, &L_tmp_exp ), &Overflow ); + st->cngTDLevel = round_fx_o( Sqrt32( L_tmp, &L_tmp_exp ), &Overflow ); /*Q15 - L_tmp_exp*/ move16(); #else st->cngTDLevel = round_fx( Sqrt32( L_tmp, &L_tmp_exp ) ); @@ -1116,21 +1116,21 @@ Word16 ApplyFdCng_fx( IF( hFdCngDec->partNoiseShape[k] != 0 ) { s1 = norm_l( hFdCngCom->sidNoiseEst[k] ); - L_tmp = L_shl( hFdCngCom->sidNoiseEst[k], s1 ); + L_tmp = L_shl( hFdCngCom->sidNoiseEst[k], s1 ); /*Q31 - hFdCngCom->sidNoiseEstExp + s1*/ L_tmp_exp = sub( hFdCngCom->sidNoiseEstExp, s1 ); L_tmp = BASOP_Util_Add_Mant32Exp( hFdCngCom->sidNoiseEst[k], hFdCngCom->sidNoiseEstExp, DELTA_MANTISSA_W32, DELTA_EXPONENT, &L_tmp_exp ); L_tmp = L_shr( L_tmp, 1 ); s = add( L_tmp_exp, 1 ); - num = extract_h( L_tmp ); + num = extract_h( L_tmp ); /*Q15 - L_tmp_exp*/ s1 = norm_l( hFdCngDec->partNoiseShape[k] ); - L_tmp = L_shl( hFdCngDec->partNoiseShape[k], s1 ); + L_tmp = L_shl( hFdCngDec->partNoiseShape[k], s1 ); /*Q31 - hFdCngDec->partNoiseShape_exp + s1*/ L_tmp_exp = sub( hFdCngDec->partNoiseShape_exp, s1 ); L_tmp = BASOP_Util_Add_Mant32Exp( L_tmp, L_tmp_exp, DELTA_MANTISSA_W32, DELTA_EXPONENT, &L_tmp_exp ); s = sub( s, L_tmp_exp ); - denom = extract_h( L_tmp ); + denom = extract_h( L_tmp ); /*Q15 - L_tmp_exp*/ - facTab[k] = div_s( num, denom ); + facTab[k] = div_s( num, denom ); /*Q15 - s*/ move16(); facTabExp[k] = s; move16(); @@ -1150,7 +1150,7 @@ Word16 ApplyFdCng_fx( s = s_max( s_min( s, WORD32_BITS - 1 ), -( WORD32_BITS - 1 ) ); FOR( ; j <= hFdCngCom->part[k]; j++ ) { - cngNoiseLevel[j] = L_shl( Mpy_32_16_1( hFdCngDec->bandNoiseShape[j], facTab[k] ), s ); + cngNoiseLevel[j] = L_shl( Mpy_32_16_1( hFdCngDec->bandNoiseShape[j], facTab[k] ), s ); /*Q31 - hFdCngDec->bandNoiseShape_exp*/ move32(); } } @@ -1160,7 +1160,7 @@ Word16 ApplyFdCng_fx( { FOR( ; j <= hFdCngCom->part[k]; j++ ) { - cngNoiseLevel[j] = L_shl( cngNoiseLevel[j], s ); + cngNoiseLevel[j] = L_shl( cngNoiseLevel[j], s ); /*Q31 - hFdCngDec->bandNoiseShape_exp + s*/ move32(); } } @@ -1204,16 +1204,16 @@ Word16 ApplyFdCng_fx( #ifdef IVAS_FLOAT_FIXED Word16 ApplyFdCng_ivas_fx( - Word16 *timeDomainInput, /* i : pointer to time domain input */ + Word16 *timeDomainInput, /* i : pointer to time domain input Q*/ Word16 Q, - Word32 *powerSpectrum, + Word32 *powerSpectrum, /*Q_power_spectrum*/ Word16 Q_power_spectrum, - Word32 **cldfbBufferReal, /* i/o: real part of the CLDFB buffer */ - Word32 **cldfbBufferImag, /* i/o: imaginary part of the CLDFB buffer */ + Word32 **cldfbBufferReal, /* i/o: real part of the CLDFB buffer cldfbBufferScale*/ + Word32 **cldfbBufferImag, /* i/o: imaginary part of the CLDFB buffer cldfbBufferScale*/ Word16 *cldfbBufferScale, /* o : pointer to the scalefactor for real and imaginary part of the CLDFB buffer */ Decoder_State *st, - const Word16 concealWholeFrame, /* i : binary flag indicating frame loss */ - Word16 is_music ) + const Word16 concealWholeFrame, /* i : binary flag indicating frame loss Q0*/ + Word16 is_music /*Q0*/ ) { Word16 j, k, nBins; Word16 s, s1, s2, num, denom; @@ -1239,7 +1239,7 @@ Word16 ApplyFdCng_ivas_fx( hFdCngDec = st->hFdCngDec; hFdCngCom = hFdCngDec->hFdCngCom; - Word32 *sidNoiseEst = hFdCngCom->sidNoiseEst; + Word32 *sidNoiseEst = hFdCngCom->sidNoiseEst; /*Q31 - hFdCngCom->sidNoiseEstExp*/ /* limit L_frame and core fs values for MDCT-Stereo modes which can have higher core sampling than 16kHz, but use a downsampled buffer */ L_frame = s_min( st->L_frame, L_FRAME16k ); @@ -1336,7 +1336,7 @@ Word16 ApplyFdCng_ivas_fx( j = 0; move16(); // s2 = -( WORD32_BITS - 1 ); - s2 = negate( sub( WORD32_BITS, 1 ) ); + s2 = -( WORD32_BITS - 1 ); move16(); FOR( k = 0; k < hFdCngCom->nFFTpart; k++ ) { @@ -1349,21 +1349,21 @@ Word16 ApplyFdCng_ivas_fx( IF( hFdCngDec->partNoiseShape[k] != 0 ) { s1 = norm_l( hFdCngCom->sidNoiseEst[k] ); - L_tmp = L_shl( hFdCngCom->sidNoiseEst[k], s1 ); + L_tmp = L_shl( hFdCngCom->sidNoiseEst[k], s1 ); /*Q31 - hFdCngCom->sidNoiseEstExp + s1*/ L_tmp_exp = sub( hFdCngCom->sidNoiseEstExp, s1 ); L_tmp = BASOP_Util_Add_Mant32Exp( L_tmp, L_tmp_exp, DELTA_MANTISSA_W32, DELTA_EXPONENT, &L_tmp_exp ); L_tmp = L_shr( L_tmp, 1 ); s = add( L_tmp_exp, 1 ); - num = extract_h( L_tmp ); + num = extract_h( L_tmp ); /*Q15 - L_tmp_exp*/ s1 = norm_l( hFdCngDec->partNoiseShape[k] ); - L_tmp = L_shl( hFdCngDec->partNoiseShape[k], s1 ); + L_tmp = L_shl( hFdCngDec->partNoiseShape[k], s1 ); /*Q31 - hFdCngDec->partNoiseShape_exp + s1*/ L_tmp_exp = sub( hFdCngDec->partNoiseShape_exp, s1 ); L_tmp = BASOP_Util_Add_Mant32Exp( L_tmp, L_tmp_exp, DELTA_MANTISSA_W32, DELTA_EXPONENT, &L_tmp_exp ); s = sub( s, L_tmp_exp ); - denom = extract_h( L_tmp ); + denom = extract_h( L_tmp ); /*Q15 - L_tmp_exp*/ - facTab[k] = div_s( num, denom ); + facTab[k] = div_s( num, denom ); /*Q15 - s*/ move16(); facTabExp[k] = s; move16(); @@ -1371,7 +1371,7 @@ Word16 ApplyFdCng_ivas_fx( /* Set unique exponent, if mantissa is equal to zero */ IF( EQ_16( facTab[k], 0 ) ) { - facTabExp[k] = negate( sub( WORD32_BITS, 1 ) ); + facTabExp[k] = -( ( WORD32_BITS - 1 ) ); move16(); } s2 = s_max( s2, facTabExp[k] ); @@ -1380,10 +1380,10 @@ Word16 ApplyFdCng_ivas_fx( FOR( k = 0; k < hFdCngCom->nFFTpart; k++ ) { s = sub( facTabExp[k], s2 ); - s = s_max( s_min( s, sub( WORD32_BITS, 1 ) ), negate( sub( WORD32_BITS, 1 ) ) ); + s = s_max( s_min( s, ( WORD32_BITS - 1 ) ), -( ( WORD32_BITS - 1 ) ) ); FOR( ; j <= hFdCngCom->part[k]; j++ ) { - cngNoiseLevel[j] = L_shl( Mpy_32_16_1( hFdCngDec->bandNoiseShape[j], facTab[k] ), s ); + cngNoiseLevel[j] = L_shl( Mpy_32_16_1( hFdCngDec->bandNoiseShape[j], facTab[k] ), s ); /*Q31 - hFdCngDec->bandNoiseShape_exp*/ move32(); } } @@ -1399,7 +1399,7 @@ Word16 ApplyFdCng_ivas_fx( Word16 q_norm = L_norm_arr( &cngNoiseLevel[j], sub( FFTCLDFBLEN, j ) ); IF( GT_16( s, q_norm ) ) { - scale_sig32( cngNoiseLevel, j, sub( q_norm, s ) ); + scale_sig32( cngNoiseLevel, j, sub( q_norm, s ) ); /*q_norm*/ e_shift = sub( s, q_norm ); } } @@ -1407,7 +1407,7 @@ Word16 ApplyFdCng_ivas_fx( { FOR( ; j <= hFdCngCom->part[k]; j++ ) { - cngNoiseLevel[j] = L_shl( cngNoiseLevel[j], sub( s, e_shift ) ); + cngNoiseLevel[j] = L_shl( cngNoiseLevel[j], sub( s, e_shift ) ); /*Q: s*/ move32(); } } @@ -1424,7 +1424,7 @@ Word16 ApplyFdCng_ivas_fx( test(); IF( !( EQ_16( st->element_mode, IVAS_CPE_TD ) ) || ( EQ_16( st->element_mode, IVAS_CPE_TD ) && !hFdCngDec->flag_dtx_mode && !st->VAD ) ) { - Copy32( hFdCngDec->bandNoiseShape, cngNoiseLevel, nBins ); + Copy32( hFdCngDec->bandNoiseShape, cngNoiseLevel, nBins ); /*Q31 - hFdCngDec->bandNoiseShape_exp*/ *cngNoiseLevel_exp = hFdCngDec->bandNoiseShape_exp; move16(); } @@ -1442,7 +1442,7 @@ Word16 ApplyFdCng_ivas_fx( Carry = 0; move16(); #ifdef BASOP_NOGLOB - L_tmp = L_add_co( L_tmp, *( cngNoiseLevel + j ), &Carry, &Overflow ); + L_tmp = L_add_co( L_tmp, *( cngNoiseLevel + j ), &Carry, &Overflow ); /*Q31*/ #else L_tmp = L_add_c( L_tmp, *( cngNoiseLevel + j ) ); #endif @@ -1451,28 +1451,28 @@ Word16 ApplyFdCng_ivas_fx( IF( *( cngNoiseLevel + j ) < 0 ) { - L_c = L_msuNs( L_c, 0, 0 ); + L_c = L_msuNs( L_c, 0, 0 ); /*Q-1*/ } IF( *( cngNoiseLevel + j ) >= 0 ) { #ifdef BASOP_NOGLOB - L_c = L_macNs_co( L_c, 0, 0, &Carry, &Overflow ); + L_c = L_macNs_co( L_c, 0, 0, &Carry, &Overflow ); /*Q-1*/ #else L_c = L_macNs( L_c, 0, 0 ); #endif } } - L_tmp = norm_llQ31( L_c, L_tmp, &L_tmp_exp ); + L_tmp = norm_llQ31( L_c, L_tmp, &L_tmp_exp ); /*Q31 - L_tmp_exp*/ L_tmp_exp = sub( add( L_tmp_exp, *cngNoiseLevel_exp ), 1 ); - L_tmp = Mpy_32_16_1( L_tmp, 1 ); + L_tmp = Mpy_32_16_1( L_tmp, 1 ); /*Q16 - L_tmp_exp*/ L_tmp = Mpy_32_16_1( L_tmp, shr( T_DIV_L_Frame[L_shl( L_mac( -28000, NORM_MDCT_FACTOR, 95 ), 1 - 15 )], 1 ) ); /*Q16,exp -7*/ L_tmp_exp = add( L_tmp_exp, -7 ); /*->Q16, L_tmp_exp */ L_tmp_exp = add( L_tmp_exp, 31 - 16 ); /*->Q31, L_tmp_exp*/ #ifdef BASOP_NOGLOB - st->hTcxDec->conCngLevelBackgroundTrace = round_fx_sat( Sqrt32( L_tmp, &L_tmp_exp ) ); + st->hTcxDec->conCngLevelBackgroundTrace = round_fx_sat( Sqrt32( L_tmp, &L_tmp_exp ) ); /*Q15 - L_tmp_exp*/ #else st->hTcxDec->conCngLevelBackgroundTrace = round_fx( Sqrt32( L_tmp, &L_tmp_exp ) ); #endif @@ -1493,7 +1493,7 @@ Word16 ApplyFdCng_ivas_fx( Carry = 0; move16(); #ifdef BASOP_NOGLOB - L_tmp = L_add_co( L_tmp, *( cngNoiseLevel + j ), &Carry, &Overflow ); + L_tmp = L_add_co( L_tmp, *( cngNoiseLevel + j ), &Carry, &Overflow ); /*Q31 - L_tmp_exp*/ #else L_tmp = L_add_c( L_tmp, *( cngNoiseLevel + j ) ); #endif @@ -1502,28 +1502,28 @@ Word16 ApplyFdCng_ivas_fx( IF( *( cngNoiseLevel + j ) < 0 ) { - L_c = L_msuNs( L_c, 0, 0 ); + L_c = L_msuNs( L_c, 0, 0 ); /*Q-1*/ } IF( *( cngNoiseLevel + j ) >= 0 ) { #ifdef BASOP_NOGLOB - L_c = L_macNs_co( L_c, 0, 0, &Carry, &Overflow ); + L_c = L_macNs_co( L_c, 0, 0, &Carry, &Overflow ); /*Q-1*/ #else L_c = L_macNs( L_c, 0, 0 ); #endif } } - L_tmp = norm_llQ31( L_c, L_tmp, &L_tmp_exp ); + L_tmp = norm_llQ31( L_c, L_tmp, &L_tmp_exp ); /*Q31 - L_tmp_exp*/ L_tmp_exp = sub( add( L_tmp_exp, *cngNoiseLevel_exp ), 1 ); - L_tmp = Mpy_32_16_1( L_tmp, hFdCngCom->fftlen ); /*Q16*/ + L_tmp = Mpy_32_16_1( L_tmp, hFdCngCom->fftlen ); /*Q16 - L_tmp_exp*/ L_tmp = Mpy_32_16_1( L_tmp, T_DIV_L_Frame[L_shl( L_mac( -28000, st->L_frame, 95 ), 1 - 15 )] ); /*Q16,exp -7*/ L_tmp_exp = add( L_tmp_exp, -7 ); /*->Q16, L_tmp_exp */ L_tmp_exp = add( L_tmp_exp, 31 - 16 ); /*->Q31, L_tmp_exp*/ #ifdef BASOP_NOGLOB - st->hTcxDec->conCngLevelBackgroundTrace = round_fx_sat( Sqrt32( L_tmp, &L_tmp_exp ) ); + st->hTcxDec->conCngLevelBackgroundTrace = round_fx_sat( Sqrt32( L_tmp, &L_tmp_exp ) ); /*Q15 - L_tmp_exp*/ move16(); #else st->hTcxDec->conCngLevelBackgroundTrace = round_fx( Sqrt32( L_tmp, &L_tmp_exp ) ); @@ -1542,7 +1542,7 @@ Word16 ApplyFdCng_ivas_fx( Carry = 0; move16(); #ifdef BASOP_NOGLOB - L_tmp = L_add_co( L_tmp, *( cngNoiseLevel + j ), &Carry, &Overflow ); + L_tmp = L_add_co( L_tmp, *( cngNoiseLevel + j ), &Carry, &Overflow ); /*Q31 - L_tmp_exp*/ #else L_tmp = L_add_c( L_tmp, *( cngNoiseLevel + j ) ); #endif @@ -1551,28 +1551,28 @@ Word16 ApplyFdCng_ivas_fx( IF( *( cngNoiseLevel + j ) < 0 ) { - L_c = L_msuNs( L_c, 0, 0 ); + L_c = L_msuNs( L_c, 0, 0 ); /*Q-1*/ } IF( *( cngNoiseLevel + j ) >= 0 ) { #ifdef BASOP_NOGLOB - L_c = L_macNs_co( L_c, 0, 0, &Carry, &Overflow ); + L_c = L_macNs_co( L_c, 0, 0, &Carry, &Overflow ); /*Q-1*/ #else L_c = L_macNs( L_c, 0, 0 ); #endif } } - L_tmp = norm_llQ31( L_c, L_tmp, &L_tmp_exp ); + L_tmp = norm_llQ31( L_c, L_tmp, &L_tmp_exp ); /*Q31 - L_tmp_exp*/ L_tmp_exp = sub( add( L_tmp_exp, *cngNoiseLevel_exp ), 1 ); - L_tmp = Mpy_32_16_1( L_tmp, hFdCngCom->fftlen ); /*Q16*/ + L_tmp = Mpy_32_16_1( L_tmp, hFdCngCom->fftlen ); /*Q16 - L_tmp_exp*/ L_tmp = Mpy_32_16_1( L_tmp, T_DIV_L_Frame[L_shl( L_mac( -28000, st->L_frame, 95 ), 1 - 15 )] ); /*Q16,exp -7*/ L_tmp_exp = add( L_tmp_exp, -7 ); /*->Q16, L_tmp_exp */ L_tmp_exp = add( L_tmp_exp, 31 - 16 ); /*->Q31, L_tmp_exp*/ #ifdef BASOP_NOGLOB - st->cngTDLevel = round_fx_sat( Sqrt32( L_tmp, &L_tmp_exp ) ); + st->cngTDLevel = round_fx_sat( Sqrt32( L_tmp, &L_tmp_exp ) ); /*Q15 - L_tmp_exp*/ #else st->cngTDLevel = round_fx( Sqrt32( L_tmp, &L_tmp_exp ) ); #endif @@ -1604,7 +1604,7 @@ Word16 ApplyFdCng_ivas_fx( move32(); FOR( j = hFdCngCom->startBand; j < hFdCngCom->stopFFTbin; j++ ) { - L_tmp = L_add_sat( L_tmp, L_shl_sat( cngNoiseLevel[j], sub( 31, *cngNoiseLevel_exp ) ) ); + L_tmp = L_add_sat( L_tmp, L_shl_sat( cngNoiseLevel[j], sub( 31, *cngNoiseLevel_exp ) ) ); /*Q31*/ } L_tmp_exp = 0; move16(); @@ -1624,9 +1624,9 @@ Word16 ApplyFdCng_ivas_fx( { lpc_from_spectrum( hFdCngCom, hFdCngCom->startBand, hFdCngCom->stopFFTbin, 0 ); E_LPC_a_lsp_conversion( hFdCngCom->A_cng, lsp_cng, st->lspold_cng, M ); - Copy( lsp_cng, st->lspold_cng, M ); + Copy( lsp_cng, st->lspold_cng, M ); /*Q15*/ - lsp2lsf_fx( lsp_cng, st->lsf_cng, M, st->sr_core ); + lsp2lsf_fx( lsp_cng, st->lsf_cng, M, st->sr_core ); /*x2.56*/ } st->plcBackgroundNoiseUpdated = 1; @@ -1659,7 +1659,7 @@ Word16 ApplyFdCng_ivas_fx( hFdCngDec->bandNoiseShape_exp = hFdCngDec->msNoiseEst_exp; move16(); /* This sets the new CNG levels until a SID update overwrites it */ - Copy32( hFdCngDec->bandNoiseShape, cngNoiseLevel, sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ) ); /* This sets the new CNG levels until a SID update overwrites it */ + Copy32( hFdCngDec->bandNoiseShape, cngNoiseLevel, sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ) ); /* This sets the new CNG levels until a SID update overwrites it */ /*Q31 - hFdCngDec->bandNoiseShape_exp*/ *cngNoiseLevel_exp = hFdCngDec->bandNoiseShape_exp; move16(); @@ -1672,18 +1672,18 @@ Word16 ApplyFdCng_ivas_fx( Carry = 0; move16(); -#ifdef BASOP_NOGLOB /* Critical Carry/Overflow */ - L_tmp = L_add_co( L_tmp, *( cngNoiseLevel + j ), &Carry, &Overflow ); +#ifdef BASOP_NOGLOB /* Critical Carry/Overflow */ + L_tmp = L_add_co( L_tmp, *( cngNoiseLevel + j ), &Carry, &Overflow ); /*Q31 - L_tmp_exp*/ Overflow = 0; move16(); IF( *( cngNoiseLevel + j ) < 0 ) { - L_c = L_msuNs_co( L_c, 0, 0, &Carry, &Overflow ); + L_c = L_msuNs_co( L_c, 0, 0, &Carry, &Overflow ); /*Q-1*/ } IF( *( cngNoiseLevel + j ) >= 0 ) { - L_c = L_macNs_co( L_c, 0, 0, &Carry, &Overflow ); + L_c = L_macNs_co( L_c, 0, 0, &Carry, &Overflow ); /*Q-1*/ } #else L_tmp = L_add_c( L_tmp, *( cngNoiseLevel + j ) ); @@ -1699,17 +1699,17 @@ Word16 ApplyFdCng_ivas_fx( } #endif } - L_tmp = norm_llQ31( L_c, L_tmp, &L_tmp_exp ); + L_tmp = norm_llQ31( L_c, L_tmp, &L_tmp_exp ); /*Q31 - L_tmp_exp*/ L_tmp_exp = sub( add( L_tmp_exp, *cngNoiseLevel_exp ), 1 ); - L_tmp = Mpy_32_16_1( L_tmp, hFdCngCom->fftlen ); /*Q16*/ + L_tmp = Mpy_32_16_1( L_tmp, hFdCngCom->fftlen ); /*Q16 - L_tmp_exp*/ L_tmp = Mpy_32_16_1( L_tmp, T_DIV_L_Frame[L_shl( L_mac( -28000, st->L_frame, 95 ), 1 - 15 )] ); /*Q16,exp -7*/ L_tmp_exp = add( L_tmp_exp, -7 ); /*->Q16, L_tmp_exp */ L_tmp_exp = add( L_tmp_exp, 31 - 16 ); /*->Q31, L_tmp_exp*/ -#ifdef BASOP_NOGLOB /* Critical Carry/Overflow */ - st->cngTDLevel = round_fx_o( Sqrt32( L_tmp, &L_tmp_exp ), &Overflow ); +#ifdef BASOP_NOGLOB /* Critical Carry/Overflow */ + st->cngTDLevel = round_fx_o( Sqrt32( L_tmp, &L_tmp_exp ), &Overflow ); /*Q15 - L_tmp_exp*/ #else st->cngTDLevel = round_fx( Sqrt32( L_tmp, &L_tmp_exp ) ); #endif @@ -1740,7 +1740,7 @@ Word16 ApplyFdCng_ivas_fx( &hFdCngDec->partNoiseShape_exp ); IF( EQ_16( st->element_mode, IVAS_CPE_DFT ) ) { - Copy32( hFdCngDec->hFdCngCom->sidNoiseEst, hFdCngDec->hFdCngCom->sidNoiseEstLp, NPART ); + Copy32( hFdCngDec->hFdCngCom->sidNoiseEst, hFdCngDec->hFdCngCom->sidNoiseEstLp, NPART ); /*Q31 - hFdCngDec->sidNoiseEstExp*/ } } @@ -1758,7 +1758,7 @@ Word16 ApplyFdCng_ivas_fx( { if ( EQ_16( st->element_mode, IVAS_CPE_DFT ) ) { - sidNoiseEst = hFdCngCom->sidNoiseEstLp; + sidNoiseEst = hFdCngCom->sidNoiseEstLp; /*Q31 - hFdCngDec->sidNoiseEstExp*/ } /* Interpolate the CLDFB band levels from the SID (partition) levels */ IF( GT_16( hFdCngCom->regularStopBand, hFdCngCom->numCoreBands ) ) @@ -1770,7 +1770,7 @@ Word16 ApplyFdCng_ivas_fx( move16(); } - s2 = negate( sub( WORD32_BITS, 1 ) ); + s2 = -( ( WORD32_BITS - 1 ) ); move16(); /* Shape the SID noise levels in each FFT bin */ j = 0; @@ -1785,21 +1785,21 @@ Word16 ApplyFdCng_ivas_fx( IF( hFdCngDec->partNoiseShape[k] != 0 ) { s1 = norm_l( sidNoiseEst[k] ); - L_tmp = L_shl( sidNoiseEst[k], s1 ); + L_tmp = L_shl( sidNoiseEst[k], s1 ); /*Q31 - ( hFdCngCom->sidNoiseEstExp - s1 )*/ L_tmp_exp = sub( hFdCngCom->sidNoiseEstExp, s1 ); L_tmp = BASOP_Util_Add_Mant32Exp( sidNoiseEst[k], hFdCngCom->sidNoiseEstExp, DELTA_MANTISSA_W32, DELTA_EXPONENT, &L_tmp_exp ); L_tmp = L_shr( L_tmp, 1 ); s = add( L_tmp_exp, 1 ); - num = extract_h( L_tmp ); + num = extract_h( L_tmp ); /*Q15 - L_tmp_exp*/ s1 = norm_l( hFdCngDec->partNoiseShape[k] ); - L_tmp = L_shl( hFdCngDec->partNoiseShape[k], s1 ); + L_tmp = L_shl( hFdCngDec->partNoiseShape[k], s1 ); /*Q31 - ( hFdCngDec->partNoiseShape_ex - s1 )*/ L_tmp_exp = sub( hFdCngDec->partNoiseShape_exp, s1 ); L_tmp = BASOP_Util_Add_Mant32Exp( L_tmp, L_tmp_exp, DELTA_MANTISSA_W32, DELTA_EXPONENT, &L_tmp_exp ); s = sub( s, L_tmp_exp ); - denom = extract_h( L_tmp ); + denom = extract_h( L_tmp ); /*Q15 - L_tmp_exp*/ - facTab[k] = div_s( num, denom ); + facTab[k] = div_s( num, denom ); /*Q15 - s*/ move16(); facTabExp[k] = s; move16(); @@ -1807,7 +1807,7 @@ Word16 ApplyFdCng_ivas_fx( /* Set unique exponent, IF mantissa is equal to zero */ IF( EQ_16( facTab[k], 0 ) ) { - facTabExp[k] = negate( sub( WORD32_BITS, 1 ) ); + facTabExp[k] = -( ( WORD32_BITS - 1 ) ); move16(); } s2 = s_max( s2, facTabExp[k] ); @@ -1820,10 +1820,10 @@ Word16 ApplyFdCng_ivas_fx( FOR( k = 0; k < hFdCngCom->nFFTpart; k++ ) { s = sub( facTabExp[k], s2 ); - s = s_max( s_min( s, sub( WORD32_BITS, 1 ) ), negate( sub( WORD32_BITS, 1 ) ) ); + s = s_max( s_min( s, ( WORD32_BITS - 1 ) ), -( ( WORD32_BITS - 1 ) ) ); FOR( ; j <= hFdCngCom->part[k]; j++ ) { - cngNoiseLevel[j] = L_shl( Mpy_32_16_1( hFdCngDec->bandNoiseShape[j], facTab[k] ), s ); + cngNoiseLevel[j] = L_shl( Mpy_32_16_1( hFdCngDec->bandNoiseShape[j], facTab[k] ), s ); /*Q31 - hFdCngDec->bandNoiseShape_exp*/ move32(); } } @@ -1833,7 +1833,7 @@ Word16 ApplyFdCng_ivas_fx( { FOR( ; j <= hFdCngCom->part[k]; j++ ) { - cngNoiseLevel[j] = L_shl( cngNoiseLevel[j], s ); + cngNoiseLevel[j] = L_shl( cngNoiseLevel[j], s ); /*Q31 - hFdCngDec->bandNoiseShape_exp + s*/ move32(); } } @@ -1845,7 +1845,7 @@ Word16 ApplyFdCng_ivas_fx( { IF( !( LT_16( hFdCngCom->msFrCnt_init_counter, hFdCngCom->msFrCnt_init_thresh ) ) ) { - s2 = negate( sub( WORD32_BITS, 1 ) ); + s2 = -( ( WORD32_BITS - 1 ) ); /* Shape the SID noise levels in each FFT bin */ j = 0; move16(); @@ -1859,21 +1859,21 @@ Word16 ApplyFdCng_ivas_fx( IF( hFdCngDec->partNoiseShape[k] != 0 ) { s1 = norm_l( hFdCngCom->sidNoiseEstLp[k] ); - L_tmp = L_shl( hFdCngCom->sidNoiseEstLp[k], s1 ); + L_tmp = L_shl( hFdCngCom->sidNoiseEstLp[k], s1 ); /*Q31 - ( hFdCngCom->sidNoiseEstExp - s1 )*/ L_tmp_exp = sub( hFdCngCom->sidNoiseEstExp, s1 ); L_tmp = BASOP_Util_Add_Mant32Exp( hFdCngCom->sidNoiseEstLp[k], hFdCngCom->sidNoiseEstExp, DELTA_MANTISSA_W32, DELTA_EXPONENT, &L_tmp_exp ); L_tmp = L_shr( L_tmp, 1 ); s = add( L_tmp_exp, 1 ); - num = extract_h( L_tmp ); + num = extract_h( L_tmp ); /*Q15 - L_tmp_exp*/ s1 = norm_l( hFdCngDec->partNoiseShape[k] ); - L_tmp = L_shl( hFdCngDec->partNoiseShape[k], s1 ); + L_tmp = L_shl( hFdCngDec->partNoiseShape[k], s1 ); /*Q31 - ( hFdCngDec->partNoiseShape_exp - s1 )*/ L_tmp_exp = sub( hFdCngDec->partNoiseShape_exp, s1 ); L_tmp = BASOP_Util_Add_Mant32Exp( L_tmp, L_tmp_exp, DELTA_MANTISSA_W32, DELTA_EXPONENT, &L_tmp_exp ); s = sub( s, L_tmp_exp ); - denom = extract_h( L_tmp ); + denom = extract_h( L_tmp ); /*Q15 - L_tmp_exp*/ - facTab[k] = div_s( num, denom ); + facTab[k] = div_s( num, denom ); /*Q15 - s*/ move16(); facTabExp[k] = s; move16(); @@ -1897,7 +1897,7 @@ Word16 ApplyFdCng_ivas_fx( s = s_max( s_min( s, sub( WORD32_BITS, 1 ) ), negate( sub( WORD32_BITS, 1 ) ) ); FOR( ; j <= hFdCngCom->part[k]; j++ ) { - cngNoiseLevel[j] = L_shl( Mpy_32_16_1( hFdCngDec->bandNoiseShape[j], facTab[k] ), s ); + cngNoiseLevel[j] = L_shl( Mpy_32_16_1( hFdCngDec->bandNoiseShape[j], facTab[k] ), s ); /*Q31 - hFdCngDec->bandNoiseShape_exp*/ move32(); } } @@ -1907,7 +1907,7 @@ Word16 ApplyFdCng_ivas_fx( { FOR( ; j <= hFdCngCom->part[k]; j++ ) { - cngNoiseLevel[j] = L_shl( cngNoiseLevel[j], s ); + cngNoiseLevel[j] = L_shl( cngNoiseLevel[j], s ); /*Q31 - hFdCngDec->bandNoiseShape_exp + s*/ move32(); } } @@ -1948,7 +1948,7 @@ Word16 ApplyFdCng_ivas_fx( void */ void perform_noise_estimation_dec_fx( - const Word16 *timeDomainInput, /* i: pointer to time domain input */ + const Word16 *timeDomainInput, /* i: pointer to time domain input Q*/ const Word16 Q, #ifdef IVAS_CODE_CNG_FIX185_PLC_FADEOUT float *power_spectrum, @@ -1977,22 +1977,22 @@ void perform_noise_estimation_dec_fx( /* pointer initialization */ - periodog = hFdCngDec->hFdCngCom->periodog; - fftBuffer = hFdCngDec->hFdCngCom->fftBuffer; + periodog = hFdCngDec->hFdCngCom->periodog; /*Q31 - hFdCngDec->hFdCngCom->periodog_exp*/ + fftBuffer = hFdCngDec->hFdCngCom->fftBuffer; /*Q31 - hFdCngDec->hFdCngCom->fftBuffer_exp*/ - part = hFdCngDec->part_shaping; - psize_inv = hFdCngDec->psize_inv_shaping; - psize_norm = hFdCngDec->psize_shaping_norm; + part = hFdCngDec->part_shaping; /*Q0*/ + psize_inv = hFdCngDec->psize_inv_shaping; /*Q15*/ + psize_norm = hFdCngDec->psize_shaping_norm; /*Q15 - hFdCngDec->psize_shaping_norm_exp*/ /* variable initialization */ - startBand = hFdCngDec->hFdCngCom->startBand; + startBand = hFdCngDec->hFdCngCom->startBand; /*Q0*/ move16(); - stopFFTbin = hFdCngDec->hFdCngCom->stopFFTbin; + stopFFTbin = hFdCngDec->hFdCngCom->stopFFTbin; /*Q0*/ move16(); - npart = hFdCngDec->npart_shaping; + npart = hFdCngDec->npart_shaping; /*Q0*/ move16(); - nFFTpart = hFdCngDec->nFFTpart_shaping; + nFFTpart = hFdCngDec->nFFTpart_shaping; /*Q0*/ move16(); /* Perform STFT analysis */ @@ -2278,36 +2278,36 @@ void perform_noise_estimation_dec_fx( len = sub( stopFFTbin, startBand ); - s = getScaleFactor32( &fftBuffer[shl( startBand, 1 )], shl( len, 1 ) ); + s = getScaleFactor32( &fftBuffer[( startBand * 2 )], shl( len, 1 ) ); s = sub( s, 1 ); ptr_per = periodog; IF( startBand == 0 ) { /* DC component */ - tmp_r = extract_h( L_shl( fftBuffer[0], s ) ); + tmp_r = extract_h( L_shl( fftBuffer[0], s ) ); /*Q15 - fftBuffer_exp + s*/ - tmp = L_mult( tmp_r, tmp_r ); - *ptr_per = tmp; + tmp = L_mult( tmp_r, tmp_r ); /*Q31 - 2*(fftBuffer_exp - s)*/ + *ptr_per = tmp; /*Q31 - 2*(fftBuffer_exp - s)*/ move32(); ptr_per++; - ptr_r = fftBuffer + 2; + ptr_r = fftBuffer + 2; /*Q31 - fftBuffer_exp*/ len = sub( len, 1 ); } ELSE { - ptr_r = fftBuffer + shl( startBand, 1 ); + ptr_r = fftBuffer + shl( startBand, 1 ); /*fftBuffer_exp*/ } ptr_i = ptr_r + 1; FOR( i = 0; i < len; i++ ) { - tmp_r = extract_h( L_shl( *ptr_r, s ) ); - tmp_i = extract_h( L_shl( *ptr_i, s ) ); + tmp_r = extract_h( L_shl( *ptr_r, s ) ); /*Q15 - fftBuffer_exp + s*/ + tmp_i = extract_h( L_shl( *ptr_i, s ) ); /*Q15 - fftBuffer_exp + s*/ - tmp = L_mac( L_mult( tmp_r, tmp_r ), tmp_i, tmp_i ); - *ptr_per = tmp; + tmp = L_mac( L_mult( tmp_r, tmp_r ), tmp_i, tmp_i ); /*Q31 - 2*(fftBuffer_exp - s)*/ + *ptr_per = tmp; /*Q31 - 2*(fftBuffer_exp - s)*/ move32(); ptr_r += 2; @@ -2348,7 +2348,7 @@ void perform_noise_estimation_dec_fx( len = sub( stopFFTbin, startBand ); FOR( i = 0; i < len; i++ ) { - hFdCngDec->hFdCngCom->periodog[i] = Mpy_32_16_1( hFdCngDec->hFdCngCom->periodog[i], fac ); + hFdCngDec->hFdCngCom->periodog[i] = Mpy_32_16_1( hFdCngDec->hFdCngCom->periodog[i], fac ); /*Q31 - hFdCngDec->hFdCngCom->periodog_exp*/ move32(); } hFdCngDec->hFdCngCom->periodog_exp = add( hFdCngDec->hFdCngCom->periodog_exp, sub( 2, s ) ); @@ -2404,17 +2404,17 @@ void perform_noise_estimation_dec_fx( #ifdef IVAS_FLOAT_FIXED void perform_noise_estimation_dec_ivas_fx( - const Word16 *timeDomainInput, /* i: pointer to time domain input */ + const Word16 *timeDomainInput, /* i: pointer to time domain input Q*/ const Word16 Q, - Word32 *power_spectrum, + Word32 *power_spectrum, /*Q_power_spectrum*/ Word16 Q_power_spectrum, HANDLE_FD_CNG_DEC hFdCngDec, /* i/o: FD_CNG structure containing all buffers and variables */ - const Word16 element_mode, /* i : element mode */ - const Word16 bwidth, /* i : audio bandwidth */ - const Word16 L_frame, /* i : frame length at internal Fs */ - const Word16 last_L_frame, /* i : frame length of the last frame at internal Fs */ - const Word32 last_core_brate, /* i : previous frame core bitrate */ - const Word16 VAD /* i : VAD flag in the decoder */ + const Word16 element_mode, /* i : element mode Q0*/ + const Word16 bwidth, /* i : audio bandwidth Q0*/ + const Word16 L_frame, /* i : frame length at internal Fs Q0*/ + const Word16 last_L_frame, /* i : frame length of the last frame at internal Fs Q0*/ + const Word32 last_core_brate, /* i : previous frame core bitrate Q0*/ + const Word16 VAD /* i : VAD flag in the decoder Q0*/ ) { Word16 i, p, fftBuffer_exp = 0; @@ -2442,15 +2442,15 @@ void perform_noise_estimation_dec_ivas_fx( /* pointer initialization */ - periodog = hFdCngDec->hFdCngCom->periodog; - fftBuffer = hFdCngDec->hFdCngCom->fftBuffer; - ptr_per = periodog; - msPeriodog = hFdCngDec->msPeriodog; - msNoiseEst = hFdCngDec->msNoiseEst; + periodog = hFdCngDec->hFdCngCom->periodog; /*Q31 - hFdCngDec->hFdCngCom->periodog_exp*/ + fftBuffer = hFdCngDec->hFdCngCom->fftBuffer; /*Q31 - hFdCngDec->hFdCngCom->fftBuffer_exp*/ + ptr_per = periodog; /*Q31 - hFdCngDec->hFdCngCom->periodog_exp*/ + msPeriodog = hFdCngDec->msPeriodog; /*Q31 - hFdCngDec->msPeriodog_exp*/ + msNoiseEst = hFdCngDec->msNoiseEst; /*Q31 - hFdCngDec->msNoiseEst_exp*/ - part = hFdCngDec->part_shaping; - psize_inv = hFdCngDec->psize_inv_shaping; - psize_norm = hFdCngDec->psize_shaping_norm; + part = hFdCngDec->part_shaping; /*Q0*/ + psize_inv = hFdCngDec->psize_inv_shaping; /*Q15*/ + psize_norm = hFdCngDec->psize_shaping_norm; /*Q15 - hFdCngDec->psize_shaping_norm_exp*/ /* variable initialization */ startBand = hFdCngDec->hFdCngCom->startBand; @@ -2494,39 +2494,39 @@ void perform_noise_estimation_dec_ivas_fx( /* Calculate periodogram (squared magnitude in each FFT bin) */ IF( startBand == 0 ) { - W_tmp = W_mult0_32_32( fftBuffer[0], fftBuffer[0] ); + W_tmp = W_mult0_32_32( fftBuffer[0], fftBuffer[0] ); /*Q31 - 2*fftBuffer_exp*/ tmp_s = W_norm( W_tmp ); - ( *ptr_per ) = W_extract_h( W_shl( W_tmp, tmp_s ) ); + ( *ptr_per ) = W_extract_h( W_shl( W_tmp, tmp_s ) ); /*tmp_q*/ tmp_q = sub( add( i_mult( sub( 31, fftBuffer_exp ), 2 ), tmp_s ), 32 ); min_q = tmp_q; move16(); ptr_per++; - ptr_r = fftBuffer + 2; + ptr_r = fftBuffer + 2; /*Q31 - fftBuffer_exp*/ } ELSE { - ptr_r = fftBuffer + i_mult( 2, startBand ); + ptr_r = fftBuffer + i_mult( 2, startBand ); /*Q31 - fftBuffer_exp*/ } - ptr_i = ptr_r + 1; + ptr_i = ptr_r + 1; /*Q31 - fftBuffer_exp*/ FOR( ; ptr_per < periodog + sub( stopFFTbin, startBand ); ptr_per++ ) { - W_tmp = W_add( W_mult0_32_32( ( *ptr_r ), ( *ptr_r ) ), W_mult0_32_32( ( *ptr_i ), ( *ptr_i ) ) ); + W_tmp = W_add( W_mult0_32_32( ( *ptr_r ), ( *ptr_r ) ), W_mult0_32_32( ( *ptr_i ), ( *ptr_i ) ) ); /*Q31 - 2*(fftBuffer_exp)*/ tmp_s = W_norm( W_tmp ); tmp_q = sub( add( i_mult( sub( 31, fftBuffer_exp ), 2 ), tmp_s ), 32 ); - *ptr_per = W_extract_h( W_shl( W_tmp, tmp_s ) ); + *ptr_per = W_extract_h( W_shl( W_tmp, tmp_s ) ); /*tmp_q*/ IF( LT_16( tmp_q, min_q ) ) { - reIter = ptr_per; + reIter = ptr_per; /*tmp_q*/ Word16 diff; diff = sub( min_q, tmp_q ); WHILE( reIter > periodog ) { reIter--; - *reIter = L_shr( *reIter, diff ); + *reIter = L_shr( *reIter, diff ); /*tmp_q*/ move32(); } min_q = tmp_q; @@ -2536,7 +2536,7 @@ void perform_noise_estimation_dec_ivas_fx( { Word16 diff; diff = sub( tmp_q, min_q ); - ( *ptr_per ) = L_shr( ( *ptr_per ), diff ); + ( *ptr_per ) = L_shr( ( *ptr_per ), diff ); /*min_q*/ } /* Rescale to get energy/sample: it should be 2*(1/N)*(2/N), parseval relation with 1/N,*2 for nrg computed till Nyquist only, 2/N as windowed samples correspond to half a frame*/ @@ -2560,7 +2560,7 @@ void perform_noise_estimation_dec_ivas_fx( move16(); FOR( p = 0; p < stopFFTbin - startBand; p++ ) { - periodog[p] = L_shl( periodog[p], tmp_s ); + periodog[p] = L_shl( periodog[p], tmp_s ); /*Q31 - hFdCngDec->hFdCngCom->periodog_exp*/ move32(); } } @@ -2576,9 +2576,9 @@ void perform_noise_estimation_dec_ivas_fx( move16(); FOR( ; i <= part[p]; i++ ) { - temp = L_add( temp, periodog[i] ); + temp = L_add( temp, periodog[i] ); /*Q31 - hFdCngDec->hFdCngCom->periodog_exp*/ } - msPeriodog[p] = Mpy_32_16_1( temp, psize_inv[p] ); // Qtemp = Qperiodog + msPeriodog[p] = Mpy_32_16_1( temp, psize_inv[p] ); /*Q31 - hFdCngDec->hFdCngCom->periodog_exp*/ move32(); } @@ -2596,7 +2596,7 @@ void perform_noise_estimation_dec_ivas_fx( { FOR( p = 0; p < NPART_SHAPING; p++ ) { - msPeriodog[p] = L_shr( msPeriodog[p], sub( -16, hFdCngDec->msPeriodog_exp ) ); + msPeriodog[p] = L_shr( msPeriodog[p], sub( -16, hFdCngDec->msPeriodog_exp ) ); /*Q31 - (-16)*/ move32(); } hFdCngDec->msPeriodog_exp = -16; @@ -2612,8 +2612,8 @@ void perform_noise_estimation_dec_ivas_fx( move64(); FOR( ; i <= part[p]; i++ ) { - delta = L_sub( periodog[i], msPeriodog[p] ); - W_tmp = W_add( W_tmp, W_mult0_32_32( delta, delta ) ); + delta = L_sub( periodog[i], msPeriodog[p] ); /*Q31 - hFdCngDec->hFdCngCom->periodog_exp*/ + W_tmp = W_add( W_tmp, W_mult0_32_32( delta, delta ) ); /*Q31 - 2*(hFdCngDec->hFdCngCom->periodog_exp)*/ } tmp_s = W_norm( W_tmp ); temp = W_extract_h( W_shl( W_tmp, tmp_s ) ); // Q = 63 - 2*(31-exp) - tmp_s @@ -2622,25 +2622,25 @@ void perform_noise_estimation_dec_ivas_fx( /* compensate for the loss of variance */ e_temp = sub( 63, add( i_mult( sub( 31, hFdCngDec->hFdCngCom->periodog_exp ), 2 ), tmp_s ) ); - temp = Sqrt32( temp, &e_temp ); + temp = Sqrt32( temp, &e_temp ); /*Q31 - e_temp*/ IF( LT_16( e_temp, 0 ) ) { - temp = L_shr( temp, abs_s( e_temp ) ); + temp = L_shr( temp, abs_s( e_temp ) ); /*Q31*/ e_temp = 0; move16(); } - ftemp = rand_gauss( &hFdCngDec->cna_seed ); + ftemp = rand_gauss( &hFdCngDec->cna_seed ); /*Q29*/ - L_tmp = Mpy_32_32( temp, ftemp ); - L_tmp = L_shr( L_tmp, sub( sub( hFdCngDec->hFdCngCom->periodog_exp, e_temp ), 2 ) ); + L_tmp = Mpy_32_32( temp, ftemp ); /*Q29*/ + L_tmp = L_shr( L_tmp, sub( sub( hFdCngDec->hFdCngCom->periodog_exp, e_temp ), 2 ) ); /*Q31 - hFdCngDec->msPeriodog_exp*/ - msPeriodog[p] = L_add( msPeriodog[p], L_tmp ); + msPeriodog[p] = L_add( msPeriodog[p], L_tmp ); /*Q31 - hFdCngDec->msPeriodog_exp*/ move32(); - IF( LT_32( msPeriodog[p], L_shr( 21474, hFdCngDec->msPeriodog_exp ) ) ) + IF( LT_32( msPeriodog[p], L_shr( 21474 /*Q31*/, hFdCngDec->msPeriodog_exp ) ) ) { - msPeriodog[p] = L_shr( 21474, hFdCngDec->msPeriodog_exp ); + msPeriodog[p] = L_shr( 21474 /*Q31*/, hFdCngDec->msPeriodog_exp ); /*Q31 - hFdCngDec->msPeriodog_exp*/ move32(); } } @@ -2652,7 +2652,7 @@ void perform_noise_estimation_dec_ivas_fx( { FOR( p = 0; p < npart; p++ ) { - msPeriodog[p] = L_shr( msPeriodog[p], sub( 5, tmp_s ) ); + msPeriodog[p] = L_shr( msPeriodog[p], sub( 5, tmp_s ) ); /*Q31 - hFdCngDec->msPeriodog_exp - 5 + tmp_s*/ move32(); } hFdCngDec->msPeriodog_exp = add( hFdCngDec->msPeriodog_exp, sub( 5, tmp_s ) ); @@ -2664,13 +2664,13 @@ void perform_noise_estimation_dec_ivas_fx( move32(); IF( GE_16( hFdCngDec->msNoiseEst_exp, hFdCngDec->msPeriodog_exp ) ) { - enr_tot = L_add_sat( L_shr( sum32_fx( msPeriodog, npart ), sub( hFdCngDec->msNoiseEst_exp, hFdCngDec->msPeriodog_exp ) ), 1 ); + enr_tot = L_add_sat( L_shr( sum32_fx( msPeriodog, npart ), sub( hFdCngDec->msNoiseEst_exp, hFdCngDec->msPeriodog_exp ) ), 1 ); /*Q31 - hFdCngDec->msNoiseEst_exp*/ enr_tot0 = L_add_sat( sum32_fx( msNoiseEst, npart ), 1 ); } ELSE IF( LT_16( hFdCngDec->msNoiseEst_exp, hFdCngDec->msPeriodog_exp ) ) { enr_tot = L_add_sat( sum32_fx( msPeriodog, npart ), 1 ); - enr_tot0 = L_add_sat( L_shr( sum32_fx( msNoiseEst, npart ), sub( hFdCngDec->msPeriodog_exp, hFdCngDec->msNoiseEst_exp ) ), 1 ); + enr_tot0 = L_add_sat( L_shr( sum32_fx( msNoiseEst, npart ), sub( hFdCngDec->msPeriodog_exp, hFdCngDec->msNoiseEst_exp ) ), 1 ); /*Q31 - hFdCngDec->msPeriodog_exp*/ } /* update short-term periodogram on larger partitions */ @@ -2680,7 +2680,7 @@ void perform_noise_estimation_dec_ivas_fx( test(); IF( max_l && GT_16( q_shift, norm_shift ) ) { - scale_sig32( hFdCngDec->msPeriodog_ST_fx, NPART_SHAPING, sub( norm_shift, q_shift ) ); + scale_sig32( hFdCngDec->msPeriodog_ST_fx, NPART_SHAPING, sub( norm_shift, q_shift ) ); /*Q31 - hFdCngDec->msPeriodog_ST_exp + ( norm_shift - q_shift )*/ hFdCngDec->msPeriodog_ST_exp = sub( hFdCngDec->msPeriodog_ST_exp, sub( norm_shift, q_shift ) ); move16(); q_shift = norm_shift; @@ -2693,14 +2693,14 @@ void perform_noise_estimation_dec_ivas_fx( IF( NE_16( L_frame, last_L_frame ) || LE_32( last_core_brate, SID_2k40 ) ) { /* core Fs has changed or last frame was SID/NO_DATA -> re-initialize short-term periodogram */ - hFdCngDec->msPeriodog_ST_fx[p] = L_shl( msPeriodog[p], q_shift ); + hFdCngDec->msPeriodog_ST_fx[p] = L_shl( msPeriodog[p], q_shift ); /*Q31 - hFdCngDec->hFdCngCom->periodog_exp*/ move32(); } ELSE { #ifdef IVAS_ENH32_CADENCE_CHANGES - temp = L_shl( msPeriodog[p], q_shift ); - hFdCngDec->msPeriodog_ST_fx[p] = Madd_32_16( Mpy_32_16_1( hFdCngDec->msPeriodog_ST_fx[p], ST_PERIODOG_FACT_Q15 ), temp, MAX_16 - ST_PERIODOG_FACT_Q15 ); + temp = L_shl( msPeriodog[p], q_shift ); /*Q31 - hFdCngDec->hFdCngCom->periodog_exp*/ + hFdCngDec->msPeriodog_ST_fx[p] = Madd_32_16( Mpy_32_16_1( hFdCngDec->msPeriodog_ST_fx[p], ST_PERIODOG_FACT_Q15 ), temp, MAX_16 - ST_PERIODOG_FACT_Q15 ); /*Q31 - hFdCngDec->msPeriodog_ST_exp*/ #else hFdCngDec->msPeriodog_ST_fx[p] = L_add( Mpy_32_16_1( hFdCngDec->msPeriodog_ST_fx[p], ST_PERIODOG_FACT_Q15 ), Mpy_32_16_1( temp, sub( MAX_16, ST_PERIODOG_FACT_Q15 ) ) ); #endif @@ -2711,7 +2711,7 @@ void perform_noise_estimation_dec_ivas_fx( IF( max_l ) { q_shift = sub( norm_l( max_l ), 2 ); - scale_sig32( hFdCngDec->msPeriodog_ST_fx, NPART_SHAPING, q_shift ); + scale_sig32( hFdCngDec->msPeriodog_ST_fx, NPART_SHAPING, q_shift ); /*Q31 - hFdCngDec->msPeriodog_ST_exp + q_shift*/ hFdCngDec->msPeriodog_ST_exp = sub( hFdCngDec->msPeriodog_ST_exp, q_shift ); move16(); } @@ -2731,32 +2731,32 @@ void perform_noise_estimation_dec_ivas_fx( test(); IF( EQ_16( last_L_frame, L_FRAME16k ) && EQ_16( L_frame, L_FRAME ) ) { - msNoiseEst[61] = msNoiseEst[58]; + msNoiseEst[61] = msNoiseEst[58]; /*Q31 - hFdCngDec->msNoiseEst_exp*/ move32(); - msNoiseEst[60] = L_min( msNoiseEst[58], msNoiseEst[57] ); + msNoiseEst[60] = L_min( msNoiseEst[58], msNoiseEst[57] ); /*Q31 - hFdCngDec->msNoiseEst_exp*/ move32(); - msNoiseEst[59] = msNoiseEst[57]; + msNoiseEst[59] = msNoiseEst[57]; /*Q31 - hFdCngDec->msNoiseEst_exp*/ move32(); - msNoiseEst[58] = msNoiseEst[56]; + msNoiseEst[58] = msNoiseEst[56]; /*Q31 - hFdCngDec->msNoiseEst_exp*/ move32(); - msNoiseEst[57] = msNoiseEst[56]; + msNoiseEst[57] = msNoiseEst[56]; /*Q31 - hFdCngDec->msNoiseEst_exp*/ move32(); - msNoiseEst[56] = L_min( msNoiseEst[56], msNoiseEst[55] ); + msNoiseEst[56] = L_min( msNoiseEst[56], msNoiseEst[55] ); /*Q31 - hFdCngDec->msNoiseEst_exp*/ move32(); } ELSE IF( EQ_16( last_L_frame, L_FRAME ) && EQ_16( L_frame, L_FRAME16k ) ) { - msNoiseEst[56] = L_min( msNoiseEst[56], msNoiseEst[57] ); + msNoiseEst[56] = L_min( msNoiseEst[56], msNoiseEst[57] ); /*Q31 - hFdCngDec->msNoiseEst_exp*/ move32(); - msNoiseEst[57] = L_min( msNoiseEst[58], msNoiseEst[59] ); + msNoiseEst[57] = L_min( msNoiseEst[58], msNoiseEst[59] ); /*Q31 - hFdCngDec->msNoiseEst_exp*/ move32(); - msNoiseEst[58] = L_min( msNoiseEst[60], msNoiseEst[61] ); + msNoiseEst[58] = L_min( msNoiseEst[60], msNoiseEst[61] ); /*Q31 - hFdCngDec->msNoiseEst_exp*/ move32(); - msNoiseEst[59] = 0; + msNoiseEst[59] = 0; /*Q31 - hFdCngDec->msNoiseEst_exp*/ move32(); - msNoiseEst[60] = 0; + msNoiseEst[60] = 0; /*Q31 - hFdCngDec->msNoiseEst_exp*/ move32(); - msNoiseEst[61] = 0; + msNoiseEst[61] = 0; /*Q31 - hFdCngDec->msNoiseEst_exp*/ move32(); hFdCngDec->ms_cnt_bw_up = FIRST_CNA_NOISE_UPD_FRAMES; @@ -2773,15 +2773,15 @@ void perform_noise_estimation_dec_ivas_fx( /* background noise update with moving average */ IF( hFdCngDec->first_cna_noise_update_cnt != 0 ) { - alpha = Inv16( add( hFdCngDec->first_cna_noise_update_cnt, 1 ), &e ); - alpha = shl_sat( alpha, e ); // Q15 + alpha = Inv16( add( hFdCngDec->first_cna_noise_update_cnt, 1 ), &e ); /*Q15*/ + alpha = shl_sat( alpha, e ); // Q15 maximum_32_fx( msPeriodog, npart, &max_l ); q_shift = sub( hFdCngDec->hFdCngCom->periodog_exp, hFdCngDec->msNoiseEst_exp ); norm_shift = norm_l( max_l ); test(); IF( max_l && GT_16( q_shift, norm_shift ) ) { - scale_sig32( msNoiseEst, NPART_SHAPING, sub( norm_shift, q_shift ) ); + scale_sig32( msNoiseEst, NPART_SHAPING, sub( norm_shift, q_shift ) ); /*Q31 - hFdCngDec->msNoiseEst_exp + ( norm_shift - q_shift )*/ hFdCngDec->msNoiseEst_exp = sub( hFdCngDec->msNoiseEst_exp, sub( norm_shift, q_shift ) ); move16(); q_shift = norm_shift; @@ -2791,7 +2791,7 @@ void perform_noise_estimation_dec_ivas_fx( { temp = L_shl( msPeriodog[p], q_shift ); #ifdef IVAS_ENH32_CADENCE_CHANGES - msNoiseEst[p] = Madd_32_16( Mpy_32_16_1( msNoiseEst[p], sub( MAX_16, alpha ) ), temp, alpha ); + msNoiseEst[p] = Madd_32_16( Mpy_32_16_1( msNoiseEst[p], sub( MAX_16, alpha ) ), temp, alpha ); /*Q31 - hFdCngDec->msNoiseEst_exp*/ #else msNoiseEst[p] = L_add( Mpy_32_16_1( msNoiseEst[p], sub( MAX_16, alpha ) ), Mpy_32_16_1( temp, alpha ) ); #endif @@ -2801,8 +2801,8 @@ void perform_noise_estimation_dec_ivas_fx( ELSE { Word16 tmp = s_max( sub( hFdCngDec->msPeriodog_exp, getScaleFactor32( msPeriodog, npart ) ), sub( hFdCngDec->msNoiseEst_exp, getScaleFactor32( &msNoiseEst[npart], sub( NPART_SHAPING, npart ) ) ) ); - Copy_Scale_sig32( msPeriodog, msNoiseEst, npart, sub( hFdCngDec->msPeriodog_exp, tmp ) ); - scale_sig32( &msNoiseEst[npart], sub( NPART_SHAPING, npart ), sub( hFdCngDec->msNoiseEst_exp, tmp ) ); + Copy_Scale_sig32( msPeriodog, msNoiseEst, npart, sub( hFdCngDec->msPeriodog_exp, tmp ) ); /*Q31 - tmp*/ + scale_sig32( &msNoiseEst[npart], sub( NPART_SHAPING, npart ), sub( hFdCngDec->msNoiseEst_exp, tmp ) ); /*Q31 - tmp*/ hFdCngDec->msNoiseEst_exp = tmp; move16(); } @@ -2810,7 +2810,7 @@ void perform_noise_estimation_dec_ivas_fx( /* check, if we reached the required number of first CNA noise update frames */ IF( LT_16( hFdCngDec->first_cna_noise_update_cnt, FIRST_CNA_NOISE_UPD_FRAMES - 1 ) ) { - hFdCngDec->first_cna_noise_update_cnt = add( hFdCngDec->first_cna_noise_update_cnt, 1 ); + hFdCngDec->first_cna_noise_update_cnt = add( hFdCngDec->first_cna_noise_update_cnt, 1 ); /*Q0*/ move16(); } ELSE @@ -2838,10 +2838,10 @@ void perform_noise_estimation_dec_ivas_fx( { Word16 scale; /* no updates during active frames except for significant energy drops */ - enr_ratio = BASOP_Util_Divide3232_Scale( enr_tot, enr_tot0, &scale ); + enr_ratio = BASOP_Util_Divide3232_Scale( enr_tot, enr_tot0, &scale ); /*Q15 - scale*/ IF( scale <= 0 ) { - enr_ratio = shl( enr_ratio, scale ); + enr_ratio = shl( enr_ratio, scale ); /*Q15*/ scale = 15; move16(); } @@ -2852,7 +2852,7 @@ void perform_noise_estimation_dec_ivas_fx( IF( LT_16( enr_ratio, shl( 1, sub( scale, 1 ) ) ) ) { /* total energy significantly decreases during active frames -> downward update */ - wght = lin_interp_fx( enr_ratio, 0, shr( 26214, sub( 15, scale ) ) /*0.8f in Q15*/, shr( 16384, sub( 15, scale ) ) /*0.5f in Q15*/, shr( 31130, sub( 15, scale ) ) /*0.95f in Q15*/, shr( 32767, sub( 15, scale ) ) /*1 in Q15*/ ); + wght = lin_interp_fx( enr_ratio, 0, shr( 26214, sub( 15, scale ) ) /*0.8f in Q15*/, shr( 16384, sub( 15, scale ) ) /*0.5f in Q15*/, shr( 31130, sub( 15, scale ) ) /*0.95f in Q15*/, shr( 32767, sub( 15, scale ) ) /*1 in Q15*/ ); /*scale*/ Word16 temp_q_msNoiseEst[NPART_SHAPING]; Word16 min_q_msNoiseEst = MAX_16; move16(); @@ -2867,7 +2867,7 @@ void perform_noise_estimation_dec_ivas_fx( IF( LT_32( L_tmp, msNoiseEst[p] ) ) { #ifdef IVAS_ENH32_CADENCE_CHANGES - msNoiseEst[p] = Madd_32_16( Mpy_32_16_1( msNoiseEst[p], wght ), L_tmp, (Word16) L_sub( shr( MAX_16, sub( 15, scale ) ), wght ) ); + msNoiseEst[p] = Madd_32_16( Mpy_32_16_1( msNoiseEst[p], wght ), L_tmp, (Word16) L_sub( shr( MAX_16, sub( 15, scale ) ), wght ) ); /*temp_q_msNoiseEst[p]*/ #else msNoiseEst[p] = L_add( Mpy_32_16_1( msNoiseEst[p], wght ), Mpy_32_16_1( L_tmp, (Word16) L_sub( shr( MAX_16, sub( 15, scale ) ), wght ) ) ); #endif @@ -2879,7 +2879,7 @@ void perform_noise_estimation_dec_ivas_fx( } FOR( p = 0; p < NPART_SHAPING; p++ ) { - msNoiseEst[p] = L_shl( msNoiseEst[p], sub( min_q_msNoiseEst, temp_q_msNoiseEst[p] ) ); + msNoiseEst[p] = L_shl( msNoiseEst[p], sub( min_q_msNoiseEst, temp_q_msNoiseEst[p] ) ); /*min_q_msNoiseEst*/ move32(); } hFdCngDec->msNoiseEst_exp = min_q_msNoiseEst; @@ -2890,11 +2890,11 @@ void perform_noise_estimation_dec_ivas_fx( /* energy significantly decreases in one of the larger partitions during active frames -> downward update */ FOR( p = CNA_ACT_DN_LARGE_PARTITION; p < npart; p++ ) { - L_tmp = L_shr_sat( hFdCngDec->msPeriodog_ST_fx[p], sub( hFdCngDec->msNoiseEst_exp, hFdCngDec->msPeriodog_ST_exp ) ); + L_tmp = L_shr_sat( hFdCngDec->msPeriodog_ST_fx[p], sub( hFdCngDec->msNoiseEst_exp, hFdCngDec->msPeriodog_ST_exp ) ); /*Q31 - hFdCngDec->msPeriodog_ST_exp*/ IF( LT_32( L_tmp, msNoiseEst[p] ) ) { #ifdef IVAS_ENH32_CADENCE_CHANGES - msNoiseEst[p] = Madd_32_16( Mpy_32_16_1( msNoiseEst[p], CNA_ACT_DN_FACT_Q15 ), L_tmp, ONE_IN_Q15 - CNA_ACT_DN_FACT_Q15 ); + msNoiseEst[p] = Madd_32_16( Mpy_32_16_1( msNoiseEst[p], CNA_ACT_DN_FACT_Q15 ), L_tmp, ONE_IN_Q15 - CNA_ACT_DN_FACT_Q15 ); /*Q31 - hFdCngDec->msNoiseEst_exp*/ #else msNoiseEst[p] = L_add( Mpy_32_16_1( msNoiseEst[p], CNA_ACT_DN_FACT_Q15 ), Mpy_32_16_1( L_tmp, ONE_IN_Q15 - CNA_ACT_DN_FACT_Q15 ) ); #endif @@ -2915,12 +2915,12 @@ void perform_noise_estimation_dec_ivas_fx( hFdCngDec->ms_last_inactive_bwidth = bwidth; move16(); /* update background noise during inactive frames */ - ptr_per = msNoiseEst; + ptr_per = msNoiseEst; /*Q31 - hFdCngDec->msNoiseEst_exp*/ FOR( p = 0; p < npart; p++ ) { Word16 i_e = 15; move16(); - enr = msPeriodog[p]; + enr = msPeriodog[p]; /*Q31 - hFdCngDec->msPeriodog_exp*/ move32(); enr_e = hFdCngDec->msPeriodog_exp; move16(); @@ -2930,7 +2930,7 @@ void perform_noise_estimation_dec_ivas_fx( test(); IF( GT_16( hFdCngDec->ms_cnt_bw_up, 0 ) && GT_16( p, 55 ) ) { - alpha = Inv16( add( hFdCngDec->ms_cnt_bw_up, 1 ), &i_e ); + alpha = Inv16( add( hFdCngDec->ms_cnt_bw_up, 1 ), &i_e ); /*Q15 - i_e*/ IF( i_e < 0 ) { alpha = shr( alpha, negate( i_e ) ); // Q15 @@ -2948,14 +2948,14 @@ void perform_noise_estimation_dec_ivas_fx( test(); IF( ( norm_l( *ptr_per ) == 0 ) && *ptr_per ) { - enr = *ptr_per; + enr = *ptr_per; /*Q31 - hFdCngDec->msNoiseEst_exp*/ scale_sig32( msNoiseEst, NPART_SHAPING, -1 ); hFdCngDec->msNoiseEst_exp = add( hFdCngDec->msNoiseEst_exp, 1 ); move16(); } ELSE { - enr = L_shl( *ptr_per, 1 ); + enr = L_shl( *ptr_per, 1 ); /*Q31 - hFdCngDec->msNoiseEst_exp*/ } enr_e = hFdCngDec->msNoiseEst_exp; move16(); @@ -2965,7 +2965,7 @@ void perform_noise_estimation_dec_ivas_fx( test(); IF( *ptr_per != 0 && alpha != 0 ) { - *ptr_per = Mpy_32_16_1( ( *ptr_per ), alpha ); + *ptr_per = Mpy_32_16_1( ( *ptr_per ), alpha ); /*Q31 - hFdCngDec->msNoiseEst_exp*/ move32(); if ( *ptr_per == 0 ) { @@ -2985,19 +2985,19 @@ void perform_noise_estimation_dec_ivas_fx( norm_shift = norm_l( enr ); IF( LE_16( q_shift, norm_shift ) ) { - enr = L_shl( enr, q_shift ); + enr = L_shl( enr, q_shift ); /*Q31 - hFdCngDec->msNoiseEst_exp + q_shift*/ move32(); } ELSE { enr_e = sub( enr_e, norm_shift ); - enr = L_shl( enr, norm_shift ); - scale_sig32( msNoiseEst, NPART_SHAPING, sub( norm_shift, q_shift ) ); + enr = L_shl( enr, norm_shift ); /*Q31 - hFdCngDec->msNoiseEst_exp + norm_shift*/ + scale_sig32( msNoiseEst, NPART_SHAPING, sub( norm_shift, q_shift ) ); /*Q31 - ( hFdCngDec->msNoiseEst_exp - ( norm_shift - q_shift ) )*/ hFdCngDec->msNoiseEst_exp = sub( hFdCngDec->msNoiseEst_exp, sub( norm_shift, q_shift ) ); move16(); } } - *ptr_per = Madd_32_16( ( *ptr_per ), enr, sub( MAX_16, alpha ) ); + *ptr_per = Madd_32_16( ( *ptr_per ), enr, sub( MAX_16, alpha ) ); /*Q31 - enr_e*/ move32(); #else *ptr_per = L_add( ( *ptr_per ), Mpy_32_16_1( enr, sub( MAX_16, alpha ) ) ); @@ -3016,12 +3016,12 @@ void perform_noise_estimation_dec_ivas_fx( IF( max_l ) { q_shift = sub( norm_l( max_l ), 2 ); - scale_sig32( msNoiseEst, NPART_SHAPING, q_shift ); + scale_sig32( msNoiseEst, NPART_SHAPING, q_shift ); /*Q31 - ( hFdCngDec->msNoiseEst_exp - q_shift )*/ hFdCngDec->msNoiseEst_exp = sub( hFdCngDec->msNoiseEst_exp, q_shift ); move16(); } - Copy32( msNoiseEst, hFdCngDec->msPsd_fx, npart ); + Copy32( msNoiseEst, hFdCngDec->msPsd_fx, npart ); /*Q31 - ( hFdCngDec->msNoiseEst_exp )*/ hFdCngDec->msPsd_exp_fft = hFdCngDec->msNoiseEst_exp; move16(); @@ -3029,7 +3029,7 @@ void perform_noise_estimation_dec_ivas_fx( scalebands_fx( msNoiseEst, part, nFFTpart, hFdCngDec->midband_shaping, nFFTpart, sub( stopFFTbin, startBand ), hFdCngDec->bandNoiseShape, 1 ); hFdCngDec->bandNoiseShape_exp = hFdCngDec->msNoiseEst_exp; move16(); - Copy32( hFdCngDec->bandNoiseShape, &hFdCngDec->smoothed_psd_fx[startBand], sub( stopFFTbin, startBand ) ); + Copy32( hFdCngDec->bandNoiseShape, &hFdCngDec->smoothed_psd_fx[startBand], sub( stopFFTbin, startBand ) ); /*Q31 - hFdCngDec->bandNoiseShape_exp*/ hFdCngDec->smoothed_psd_exp = hFdCngDec->bandNoiseShape_exp; move16(); set32_fx( &hFdCngDec->smoothed_psd_fx[stopFFTbin], 0, sub( L_FRAME16k, stopFFTbin ) ); @@ -3040,7 +3040,7 @@ void perform_noise_estimation_dec_ivas_fx( IF( EQ_16( element_mode, IVAS_CPE_MDCT ) && power_spectrum != NULL ) { /* use power spectrum calculated in the MDCT-domain instead of calculating new power spectrum */ - periodog = power_spectrum; + periodog = power_spectrum; /*Q_power_spectrum*/ periodog_exp = sub( 31, Q_power_spectrum ); } ELSE @@ -3048,20 +3048,20 @@ void perform_noise_estimation_dec_ivas_fx( /* Compute the squared magnitude in each FFT bin */ IF( startBand == 0 ) { - W_tmp = W_mult0_32_32( fftBuffer[0], fftBuffer[0] ); /* DC component */ + W_tmp = W_mult0_32_32( fftBuffer[0], fftBuffer[0] ); /* DC component */ /*Q31 - 2*fftBuffer_exp*/ min_q = 2; move16(); ( *ptr_per ) = W_extract_l( W_shr( W_tmp, sub( i_mult( sub( 31, fftBuffer_exp ), 2 ), min_q ) ) ); move32(); ptr_per++; - ptr_r = fftBuffer + 2; + ptr_r = fftBuffer + 2; /*Q31 - fftBuffer_exp*/ } ELSE { - ptr_r = fftBuffer + i_mult( 2, startBand ); + ptr_r = fftBuffer + i_mult( 2, startBand ); /*Q31 - fftBuffer_exp*/ } - ptr_i = ptr_r + 1; + ptr_i = ptr_r + 1; /*Q31 - fftBuffer_exp*/ SWITCH( hFdCngDec->hFdCngCom->fftlen ) { @@ -3083,17 +3083,17 @@ void perform_noise_estimation_dec_ivas_fx( FOR( ; ptr_per < periodog + stopFFTbin - startBand; ptr_per++ ) { - W_tmp = W_add( W_mult0_32_32( ( *ptr_r ), ( *ptr_r ) ), W_mult0_32_32( ( *ptr_i ), ( *ptr_i ) ) ); + W_tmp = W_add( W_mult0_32_32( ( *ptr_r ), ( *ptr_r ) ), W_mult0_32_32( ( *ptr_i ), ( *ptr_i ) ) ); /*Q31 - 2*(fftBuffer_exp)*/ - tmp_s = W_norm( W_tmp ); + tmp_s = W_norm( W_tmp ); /*tmp_q*/ tmp_q = sub( add( i_mult( sub( 31, fftBuffer_exp ), 2 ), tmp_s ), 32 ); IF( tmp_q < 0 ) { - W_tmp = W_shr( W_tmp, negate( tmp_q ) ); + W_tmp = W_shr( W_tmp, negate( tmp_q ) ); /*Q31 - 2*(fftBuffer_exp) + tmp_q*/ } IF( LT_16( tmp_q, min_q ) ) { - reIter = ptr_per; + reIter = ptr_per; /*tmp_q*/ Word16 diff; IF( ( tmp_q <= 0 ) ) { @@ -3107,7 +3107,7 @@ void perform_noise_estimation_dec_ivas_fx( WHILE( reIter > periodog ) { reIter--; - *reIter = L_shr( *reIter, diff ); + *reIter = L_shr( *reIter, diff ); /*tmp_q*/ move32(); } IF( tmp_q >= 0 ) @@ -3150,7 +3150,7 @@ void perform_noise_estimation_dec_ivas_fx( move16(); FOR( p = 0; p < stopFFTbin - startBand; p++ ) { - periodog[p] = L_shl( periodog[p], tmp_s ); + periodog[p] = L_shl( periodog[p], tmp_s ); /*Q31 - hFdCngDec->hFdCngCom->periodog_exp + tmp_s*/ move32(); } } @@ -3245,24 +3245,24 @@ void FdCng_decodeSID_fx( HANDLE_FD_CNG_COM st, Decoder_State *corest ) invTrfMatrix_fx = (Word32 *) tmpRAM_fx; - sidNoiseEst = st->sidNoiseEst; + sidNoiseEst = st->sidNoiseEst; /*Q31 - st->sidNoiseEstExp*/ move16(); - preemph_fac = corest->preemph_fac; + preemph_fac = corest->preemph_fac; /*Q15*/ move16(); - N = st->npart; + N = st->npart; /*Q0*/ move16(); - st->sid_frame_counter = add( st->sid_frame_counter, 1 ); + st->sid_frame_counter = add( st->sid_frame_counter, 1 ); /*Q15*/ move16(); /* Read bitstream */ FOR( i = 0; i < stages_37bits; i++ ) { - indices[i] = get_next_indice_fx( corest, bits_37bits[i] ); + indices[i] = get_next_indice_fx( corest, bits_37bits[i] ); /*Q0*/ move16(); } - index = get_next_indice_fx( corest, 7 ); + index = get_next_indice_fx( corest, 7 ); /*Q0*/ /* MSVQ decoder */ IF( corest->element_mode != EVS_MONO ) @@ -3282,7 +3282,7 @@ void FdCng_decodeSID_fx( HANDLE_FD_CNG_COM st, Decoder_State *corest ) FOR( i = 0; i < N; i++ ) { - v[i] = L_deposit_h( v16[i] ); + v[i] = L_deposit_h( v16[i] ); /*Q23*/ move32(); } } @@ -3290,8 +3290,8 @@ void FdCng_decodeSID_fx( HANDLE_FD_CNG_COM st, Decoder_State *corest ) /* decode gain, format gain: Q9.23 */ gain = L_shl( L_deposit_l( index ), WORD32_BITS - 1 - 8 ); - gain = L_sub( gain, 503316480l /*60.0 Q23*/ ); - gain = Mpy_32_16_1( gain, 21845 /*2.0f/3.0f Q15*/ ); + gain = L_sub( gain, 503316480l /*60.0 Q23*/ ); /*Q23*/ + gain = Mpy_32_16_1( gain, 21845 /*2.0f/3.0f Q15*/ ); /*Q23*/ /* Apply gain and undo log */ @@ -3300,11 +3300,11 @@ void FdCng_decodeSID_fx( HANDLE_FD_CNG_COM st, Decoder_State *corest ) maxVal = L_add( 0x80000000 /*-1.0 Q31*/, 0 ); FOR( i = 0; i < N; i++ ) { - maxVal = L_max( maxVal, v[i] ); + maxVal = L_max( maxVal, v[i] ); /*Q23*/ } - maxVal = L_add( maxVal, gain ); - maxVal = L_shl( Mpy_32_16_1( maxVal, 21771 /*0.66438561897 Q15*/ ), 1 ); + maxVal = L_add( maxVal, gain ); /*Q23*/ + maxVal = L_shl( Mpy_32_16_1( maxVal, 21771 /*0.66438561897 Q15*/ ), 1 ); /*Q23*/ sidNoiseEst_Exp = 0; move16(); @@ -3319,25 +3319,25 @@ void FdCng_decodeSID_fx( HANDLE_FD_CNG_COM st, Decoder_State *corest ) /* format v: Q9.23, format sidNoiseEst: Q6.26, 0.66438561897 = log10(10)/log10(2.0) / 10.0 * 2.0 */ FOR( i = 0; i < N; i++ ) { - tmp = L_add( v[i], gain ); - tmp = L_shl( Mpy_32_16_1( tmp, 21771 /*0.66438561897 Q15*/ ), 1 ); + tmp = L_add( v[i], gain ); /*Q23*/ + tmp = L_shl( Mpy_32_16_1( tmp, 21771 /*0.66438561897 Q15*/ ), 1 ); /*Q23*/ tmp = L_sub( tmp, E_ExpLd64 ); assert( tmp < 0 ); - st->sidNoiseEst[i] = BASOP_Util_InvLog2( tmp ); + st->sidNoiseEst[i] = BASOP_Util_InvLog2( tmp ); /*Q31 - st->sidNoiseEstExp*/ move32(); } /* NB last band energy compensation */ IF( st->CngBandwidth == NB ) { - st->sidNoiseEst[sub( N, 1 )] = Mpy_32_16_1( st->sidNoiseEst[sub( N, 1 )], NB_LAST_BAND_SCALE ); + st->sidNoiseEst[( N - 1 )] = Mpy_32_16_1( st->sidNoiseEst[( N - 1 )], NB_LAST_BAND_SCALE ); /*Q31 - st->sidNoiseEstExp*/ move32(); } test(); IF( EQ_16( st->CngBandwidth, SWB ) && LE_32( st->CngBitrate, ACELP_13k20 ) ) { - st->sidNoiseEst[sub( N, 1 )] = Mpy_32_16_1( st->sidNoiseEst[sub( N, 1 )], SWB_13k2_LAST_BAND_SCALE ); + st->sidNoiseEst[( N - 1 )] = Mpy_32_16_1( st->sidNoiseEst[( N - 1 )], SWB_13k2_LAST_BAND_SCALE ); /*Q31 - st->sidNoiseEstExp*/ move32(); } @@ -3374,8 +3374,8 @@ void FdCng_decodeSID_fx( HANDLE_FD_CNG_COM st, Decoder_State *corest ) #ifdef IVAS_FLOAT_FIXED void noisy_speech_detection_fx( HANDLE_FD_CNG_DEC hFdCngDec, /* i/o: FD_CNG structure */ - const Word16 vad, - const Word16 *syn, /* i : input time-domain frame */ + const Word16 vad, /*Q0*/ + const Word16 *syn, /* i : input time-domain frame Q*/ const Word16 Q ) { Word16 i; @@ -3392,7 +3392,7 @@ void noisy_speech_detection_fx( IF( vad == 0 ) { - totalNoise = dotWord32_16_Mant32Exp( hFdCngDec->msNoiseEst, hFdCngDec->msNoiseEst_exp, hFdCngDec->psize_shaping_norm, hFdCngDec->psize_shaping_norm_exp, hFdCngDec->nFFTpart_shaping, &totalNoise_exp ); + totalNoise = dotWord32_16_Mant32Exp( hFdCngDec->msNoiseEst, hFdCngDec->msNoiseEst_exp, hFdCngDec->psize_shaping_norm, hFdCngDec->psize_shaping_norm_exp, hFdCngDec->nFFTpart_shaping, &totalNoise_exp ); /*Q31 - totalNoise_exp*/ /* - logTotalNoise is scaled by LD_DATA_SCALE+2 @@ -3402,16 +3402,16 @@ void noisy_speech_detection_fx( */ IF( totalNoise == 0 ) { - logTotalNoise = L_add( -1677721600l /*-0.78125 Q31*/, 0 ); + logTotalNoise = L_add( -1677721600l /*-0.78125 Q31*/, 0 ); /*Q31*/ } ELSE { - logTotalNoise = BASOP_Util_Log2( totalNoise ); + logTotalNoise = BASOP_Util_Log2( totalNoise ); /*Q25*/ logTotalNoiseExp = L_shl( L_deposit_l( totalNoise_exp ), WORD32_BITS - 1 - LD_DATA_SCALE ); - logTotalNoise = Mpy_32_16_1( L_add( logTotalNoise, logTotalNoiseExp ), 24660 /*0.75257498916 Q15*/ ); + logTotalNoise = Mpy_32_16_1( L_add( logTotalNoise, logTotalNoiseExp ), 24660 /*0.75257498916 Q15*/ ); /*Q31 - logTotalNoiseExp*/ } - hFdCngDec->lp_noise = L_add( Mpy_32_16_1( hFdCngDec->lp_noise, 32604 /*0.995 Q15*/ ), L_shr( Mpy_32_16_1( logTotalNoise, 20972 /*0.64 Q15*/ ), 7 ) ); + hFdCngDec->lp_noise = L_add( Mpy_32_16_1( hFdCngDec->lp_noise, 32604 /*0.995 Q15*/ ), L_shr( Mpy_32_16_1( logTotalNoise, 20972 /*0.64 Q15*/ ), 7 ) ); /*hFdCngDec->q_lp_noise*/ move32(); } ELSE @@ -3422,11 +3422,11 @@ void noisy_speech_detection_fx( move16(); FOR( i = 0; i < hFdCngDec->hFdCngCom->frameSize; i++ ) { - tmp = L_shr_r( L_mult0( syn[i], syn[i] ), sub( Etot_exp, 31 ) ); + tmp = L_shr_r( L_mult0( syn[i], syn[i] ), sub( Etot_exp, 31 ) ); /*2*(Q) - (Etot_exp - 31)*/ IF( LT_32( L_sub( maxWord32, tmp ), Etot ) ) { Etot_exp = add( Etot_exp, 1 ); - Etot = L_shr_r( Etot, 1 ); + Etot = L_shr_r( Etot, 1 ); /*Q31 - Etot_exp*/ tmp = L_shr_r( tmp, 1 ); } Etot = L_add( Etot, tmp ); @@ -3441,32 +3441,32 @@ void noisy_speech_detection_fx( */ IF( Etot == 0 ) { - logEtot = L_add( -1677721600l /*-0.78125 Q31*/, 0 ); + logEtot = L_add( -1677721600l /*-0.78125 Q31*/, 0 ); /*Q31*/ } ELSE { - logEtot = BASOP_Util_Log2( Etot ); + logEtot = BASOP_Util_Log2( Etot ); /*Q25*/ logEtotExp = L_shl( L_deposit_l( Etot_exp ), WORD32_BITS - 1 - LD_DATA_SCALE ); - logEtot = Mpy_32_16_1( L_add( logEtot, logEtotExp ), 24660 /*0.75257498916 Q15*/ ); + logEtot = Mpy_32_16_1( L_add( logEtot, logEtotExp ), 24660 /*0.75257498916 Q15*/ ); /*Q31 - logEtotExp*/ IF( EQ_16( hFdCngDec->hFdCngCom->frameSize, L_FRAME16k ) ) { - logEtot = L_add( logEtot, -184894985l /*-0.086098436822497 Q31*/ ); + logEtot = L_add( logEtot, -184894985l /*-0.086098436822497 Q31*/ ); /*Q31 - logEtotExp*/ } ELSE { - logEtot = L_add( logEtot, -176765584l /*-0.082312889439370 Q31*/ ); + logEtot = L_add( logEtot, -176765584l /*-0.082312889439370 Q31*/ ); /*Q31 - logEtotExp*/ } } - hFdCngDec->lp_speech = L_add( Mpy_32_16_1( hFdCngDec->lp_speech, 32604 /*0.995 Q15*/ ), L_shr( Mpy_32_16_1( logEtot, 20972 /*0.64 Q15*/ ), 7 ) ); + hFdCngDec->lp_speech = L_add( Mpy_32_16_1( hFdCngDec->lp_speech, 32604 /*0.995 Q15*/ ), L_shr( Mpy_32_16_1( logEtot, 20972 /*0.64 Q15*/ ), 7 ) ); /*hFdCngDec->q_lp_speech*/ move32(); } - tmp = L_sub( hFdCngDec->lp_speech, 377487360l /*45.0 Q23*/ ); + tmp = L_sub( hFdCngDec->lp_speech, 377487360l /*45.0 Q23*/ ); /*Q23*/ if ( LT_32( hFdCngDec->lp_noise, tmp ) ) { - hFdCngDec->lp_noise = tmp; + hFdCngDec->lp_noise = tmp; /*Q23*/ move32(); } @@ -3485,13 +3485,13 @@ void noisy_speech_detection_fx( #ifdef IVAS_FLOAT_FIXED void generate_comfort_noise_dec_fx( - Word32 **bufferReal, /* o : matrix to real part of input bands */ - Word32 **bufferImag, /* o : matrix to imaginary part of input bands */ + Word32 **bufferReal, /* o : matrix to real part of input bands bufferScale*/ + Word32 **bufferImag, /* o : matrix to imaginary part of input bands bufferScale*/ Word16 *bufferScale, /* o : pointer to scalefactor for real and imaginary part of input bands */ Decoder_State *st, Word16 *Q_new, - Word16 gen_exc, - const Word16 nchan_out /* i : number of output channels */ + Word16 gen_exc, /*Q0*/ + const Word16 nchan_out /* i : number of output channels Q0*/ ) { Word16 i, j, s, sc, sn, cnt; @@ -3525,15 +3525,15 @@ void generate_comfort_noise_dec_fx( /* pointer initialization */ - cngNoiseLevel = hFdCngCom->cngNoiseLevel; + cngNoiseLevel = hFdCngCom->cngNoiseLevel; /*Q31 - hFdCngCom->cngNoiseLevelExp*/ cngNoiseLevelExp = hFdCngCom->cngNoiseLevelExp; - ptr_level = cngNoiseLevel; + ptr_level = cngNoiseLevel; /*Q31 - hFdCngCom->cngNoiseLevelExp*/ seed = &( hFdCngCom->seed ); - fftBuffer = hFdCngCom->fftBuffer; + fftBuffer = hFdCngCom->fftBuffer; /*Q31 - hFdCngCom->fftBuffer_exp*/ timeDomainOutput = hFdCngCom->timeDomainBuffer; /* scaleCLDFB: CLDFBinvScalingFactor_EXP + 1 */ - scaleCLDFB = mult( hFdCngCom->invScalingFactor, CLDFB_SCALING ); + scaleCLDFB = mult( hFdCngCom->invScalingFactor, CLDFB_SCALING ); /*CLDFBinvScalingFactor_EXP + 1*/ /* Generate Gaussian random noise in real and imaginary parts of the FFT bins @@ -3557,32 +3557,32 @@ void generate_comfort_noise_dec_fx( /* DC component in FFT */ s = 0; move16(); - sqrtNoiseLevel = Sqrt32( L_shr( *ptr_level, sn ), &s ); + sqrtNoiseLevel = Sqrt32( L_shr( *ptr_level, sn ), &s ); /*Q31 - s*/ - fftBuffer[0] = L_shl( Mpy_32_32( rand_gauss( seed ), sqrtNoiseLevel ), s ); + fftBuffer[0] = L_shl( Mpy_32_32( rand_gauss( seed ), sqrtNoiseLevel ), s ); /*Q31 - hFdCngCom->fftBuffer_exp*/ move32(); /* Nyquist frequency is discarded */ fftBuffer[1] = L_deposit_l( 0 ); ptr_level = ptr_level + 1; - ptr_r = fftBuffer + 2; + ptr_r = fftBuffer + 2; /*Q31 - hFdCngCom->fftBuffer_exp*/ cnt = sub( cnt, 1 ); } ELSE { - startBand2 = shl( hFdCngCom->startBand, 1 ); + startBand2 = shl( hFdCngCom->startBand, 1 ); /*Q0*/ set32_fx( fftBuffer, 0, startBand2 ); - ptr_r = fftBuffer + startBand2; + ptr_r = fftBuffer + startBand2; /*Q31 - hFdCngCom->fftBuffer_exp*/ } sn = add( sn, 1 ); - ptr_i = ptr_r + 1; + ptr_i = ptr_r + 1; /*Q31 - hFdCngCom->fftBuffer_exp*/ FOR( i = 0; i < cnt; i++ ) { s = 0; move16(); - sqrtNoiseLevel = Sqrt32( L_shr( *ptr_level, sn ), &s ); + sqrtNoiseLevel = Sqrt32( L_shr( *ptr_level, sn ), &s ); /*Q31 - s*/ /* Real part in FFT bins */ *ptr_r = L_shl( Mpy_32_32( rand_gauss( seed ), sqrtNoiseLevel ), s ); @@ -3627,16 +3627,16 @@ void generate_comfort_noise_dec_fx( /* calculate the residual signal energy */ /*enr = dotp( hFdCngCom->exc_cng, hFdCngCom->exc_cng, hFdCngCom->frameSize ) / hFdCngCom->frameSize;*/ - Lener = Dot_productSq16HQ( 1, hFdCngCom->exc_cng, st->L_frame, &exp ); - exp = add( sub( shl( sub( 15, *Q_new ), 1 ), 8 ), exp ); /*8 = log2(256)*/ + Lener = Dot_productSq16HQ( 1, hFdCngCom->exc_cng, st->L_frame, &exp ); /*Q31 - exp*/ + exp = add( sub( shl( sub( 15, *Q_new ), 1 ), 8 ), exp ); /*8 = log2(256)*/ /* convert log2 of residual signal energy */ /*(float)log10( enr + 0.1f ) / (float)log10( 2.0f );*/ - Lener = BASOP_Util_Log2( Lener ); + Lener = BASOP_Util_Log2( Lener ); /*Q25*/ Lener = L_add( Lener, L_shl( L_deposit_l( exp ), WORD32_BITS - 1 - LD_DATA_SCALE ) ); /*Q25*/ if ( EQ_16( st->L_frame, L_FRAME16k ) ) { - Lener = L_sub( Lener, 10802114l /*0.3219280949f Q25*/ ); /*log2(320) = 8.3219280949f*/ + Lener = L_sub( Lener, 10802114l /*0.3219280949f Q25*/ ); /*log2(320) = 8.3219280949f Q25*/ } /* decrease the energy in case of WB input */ IF( st->bwidth != NB ) @@ -3646,24 +3646,24 @@ void generate_comfort_noise_dec_fx( IF( st->CNG_mode >= 0 ) { /* Bitrate adapted attenuation */ - att = L_shl( L_deposit_l( ENR_ATT_fx[st->CNG_mode] ), 17 ); + att = L_shl( L_deposit_l( ENR_ATT_fx[st->CNG_mode] ), 17 ); /*Q23*/ } ELSE { /* Use least attenuation for higher bitrates */ - att = L_shl( L_deposit_l( ENR_ATT_fx[4] ), 17 ); + att = L_shl( L_deposit_l( ENR_ATT_fx[4] ), 17 ); /*Q23*/ } } ELSE { - att = 384 << 17; - move16(); /*1.5 Q8<<17=Q25*/ + att = 384 << 17; /*1.5 Q8<<17=Q25*/ + move16(); } - Lener = L_sub( Lener, att ); + Lener = L_sub( Lener, att ); /*Q23*/ } /*st->lp_ener = 0.8f * stcod->lp_ener + 0.2f * pow( 2.0f, enr );*/ - Lener = BASOP_util_Pow2( Lener, 6, &exp ); - Lener = Mult_32_16( Lener, 6554 /*0.2f Q15*/ ); + Lener = BASOP_util_Pow2( Lener, 6, &exp ); /*Q31 - exp*/ + Lener = Mult_32_16( Lener, 6554 /*0.2f Q15*/ ); /*Q31 - exp*/ exp = sub( 25, exp ); Lener = L_shr( Lener, exp ); /*Q6*/ st->lp_ener_fx = L_add( Mult_32_16( st->lp_ener_fx, 26214 /*0.8f Q15*/ ), Lener ); /*Q6*/ @@ -3688,17 +3688,17 @@ void generate_comfort_noise_dec_fx( /* scaleCLDFB: CLDFBinvScalingFactor_EXP + 1 */ s = 0; move16(); - sqrtNoiseLevel = Sqrt32( L_shr( Mpy_32_16_1( *ptr_level, scaleCLDFB ), sn ), &s ); + sqrtNoiseLevel = Sqrt32( L_shr( Mpy_32_16_1( *ptr_level, scaleCLDFB ), sn ), &s ); /*Q31 - s*/ FOR( i = 0; i < hFdCngCom->numSlots; i++ ) { /* Real part in CLDFB band */ - bufferReal[i][j] = L_shl( Mpy_32_32( rand_gauss( seed ), sqrtNoiseLevel ), s ); + bufferReal[i][j] = L_shl( Mpy_32_32( rand_gauss( seed ), sqrtNoiseLevel ), s ); /*bufferScale*/ move32(); /*fprintf(pFile,"%13.10f\n",WORD322FL_SCALE(bufferReal[i][j],sc));*/ /* Imaginary part in CLDFB band */ - bufferImag[i][j] = L_shl( Mpy_32_32( rand_gauss( seed ), sqrtNoiseLevel ), s ); + bufferImag[i][j] = L_shl( Mpy_32_32( rand_gauss( seed ), sqrtNoiseLevel ), s ); /*bufferScale*/ move32(); /*fprintf(pFile,"%13.10f\n",WORD322FL_SCALE(bufferImag[i][j],sc));*/ } @@ -3726,14 +3726,14 @@ void generate_comfort_noise_dec_fx( seed_loc = hFdCngCom->seed; move16(); - N = hFdCngCom->frameSize; + N = hFdCngCom->frameSize; /*Q0*/ move16(); N2 = shr( hFdCngCom->frameSize, 1 ); IF( st->last_core_bfi > ACELP_CORE ) { Word16 left_overlap_mode; - left_overlap_mode = st->hTcxCfg->tcx_last_overlap_mode; + left_overlap_mode = st->hTcxCfg->tcx_last_overlap_mode; /*Q0*/ move16(); if ( EQ_16( left_overlap_mode, ALDO_WINDOW ) ) { @@ -3747,7 +3747,7 @@ void generate_comfort_noise_dec_fx( { FOR( i = 0; i < sub( hFdCngCom->frameSize, NS2SA( st->sr_core, N_ZERO_MDCT_NS ) ); i++ ) { - timeDomainOutput[i] = add( timeDomainOutput[i], shr_r( st->hHQ_core->old_out_LB_fx[i + NS2SA( st->sr_core, N_ZERO_MDCT_NS )], st->hHQ_core->Q_old_wtda_LB ) ); + timeDomainOutput[i] = add( timeDomainOutput[i], shr_r( st->hHQ_core->old_out_LB_fx[i + NS2SA( st->sr_core, N_ZERO_MDCT_NS )], st->hHQ_core->Q_old_wtda_LB ) ); /*st->q_old_outLB_fx*/ move16(); } } @@ -3758,7 +3758,7 @@ void generate_comfort_noise_dec_fx( FOR( i = 0; i < st->hTcxCfg->tcx_mdct_window_length; i++ ) { - timeDomainOutput[i] = add( timeDomainOutput[i], shl( hTcxDec->syn_Overl[i], TCX_IMDCT_HEADROOM ) ); + timeDomainOutput[i] = add( timeDomainOutput[i], shl( hTcxDec->syn_Overl[i], TCX_IMDCT_HEADROOM ) ); /*st->q_old_outLB_fx*/ move16(); } } @@ -3780,12 +3780,12 @@ void generate_comfort_noise_dec_fx( lpcorder = M; move16(); - old_Aq = st->old_Aq_12_8_fx; - old_exc = st->old_exc_fx + sub( L_EXC_MEM_DEC, N2 ); - old_syn_pe = st->mem_syn2_fx; - old_syn = st->syn[lpcorder]; + old_Aq = st->old_Aq_12_8_fx; /*Q12*/ + old_exc = st->old_exc_fx + sub( L_EXC_MEM_DEC, N2 ); /*Q_exc*/ + old_syn_pe = st->mem_syn2_fx; /*Q_syn*/ + old_syn = st->syn[lpcorder]; /*Q_syn*/ move16(); - preemph_fac = st->preemph_fac; + preemph_fac = st->preemph_fac; /*Q15*/ move16(); Q_exc = st->Q_exc; move16(); @@ -3802,16 +3802,16 @@ void generate_comfort_noise_dec_fx( normShiftEM1 = sub( normShiftE, 1 ); normShiftP2 = add( normShiftE, CNG_NORM_RECIPROCAL_RANGE_SHIFT ); - old_exc_ener = L_shr( L_mult( old_exc[0], old_exc[0] ), normShiftP2 ); + old_exc_ener = L_shr( L_mult( old_exc[0], old_exc[0] ), normShiftP2 ); /*2*(Q_exc)+1+normShiftP2*/ FOR( i = 1; i < N2; i++ ) { - old_exc_ener = L_add( old_exc_ener, L_shr( L_mult( old_exc[i], old_exc[i] ), normShiftP2 ) ); + old_exc_ener = L_add( old_exc_ener, L_shr( L_mult( old_exc[i], old_exc[i] ), normShiftP2 ) ); /*2*(Q_exc)+1+normShiftP2*/ } - old_exc_ener = L_shl( Mpy_32_16_1( old_exc_ener, shl( normFacE, normShiftEM1 ) ), 1 ); + old_exc_ener = L_shl( Mpy_32_16_1( old_exc_ener, shl( normFacE, normShiftEM1 ) ), 1 ); /*Q31*/ old_exc_ener_exp = 0; move16(); - old_exc_ener = Sqrt32( old_exc_ener, &old_exc_ener_exp ); + old_exc_ener = Sqrt32( old_exc_ener, &old_exc_ener_exp ); /*Q31 - old_exc_ener_exp*/ old_exc_ener_exp = add( old_exc_ener_exp, ( sub( 15, Q_exc ) ) ); /* shift to be in the range of values supported by getNormReciprocalWord16() */ @@ -3832,14 +3832,14 @@ void generate_comfort_noise_dec_fx( move16(); gain = L_add( gain, L_shr( L_mult( noise[i], noise[i] ), normShiftP2 ) ); } - gain = L_shl( Mpy_32_16_1( gain, shl( normFacG, normShiftGM1 ) ), 1 ); + gain = L_shl( Mpy_32_16_1( gain, shl( normFacG, normShiftGM1 ) ), 1 ); /*Q31 - gain_exp*/ gain_exp = 2 * CNG_RAND_GAUSS_SHIFT; move16(); - gain = ISqrt32( gain, &gain_exp ); + gain = ISqrt32( gain, &gain_exp ); /*Q31 - gain_exp*/ - gain = Mpy_32_32( old_exc_ener, gain ); - gain16 = extract_h( gain ); + gain = Mpy_32_32( old_exc_ener, gain ); /*Q31 - old_exc_ener_exp - gain_exp*/ + gain16 = extract_h( gain ); /*Q15 - old_exc_ener_exp - gain_exp*/ gain_exp = add( old_exc_ener_exp, gain_exp ); noiseExp = add( CNG_RAND_GAUSS_SHIFT, gain_exp ); @@ -3848,7 +3848,7 @@ void generate_comfort_noise_dec_fx( FOR( i = 0; i < N; i++ ) { #ifdef BASOP_NOGLOB - noise[i] = shr_sat( mult( noise[i], gain16 ), s ); + noise[i] = shr_sat( mult( noise[i], gain16 ), s ); /*Q15 - noiseExp*/ #else noise[i] = shr( mult( noise[i], gain16 ), s ); #endif @@ -3861,7 +3861,7 @@ void generate_comfort_noise_dec_fx( FOR( i = 0; i < lpcorder; i++ ) { #ifdef BASOP_NOGLOB - old_syn_pe_tmp[i] = shr_sat( old_syn_pe[i], s ); + old_syn_pe_tmp[i] = shr_sat( old_syn_pe[i], s ); /*Q0*/ #else old_syn_pe_tmp[i] = shr( old_syn_pe[i], s ); #endif @@ -3892,11 +3892,11 @@ void generate_comfort_noise_dec_fx( FOR( i = 0; i < N4; i++ ) { - tmp = mult( noise[i], hFdCngCom->olapWinSyn[i].v.re ); + tmp = mult( noise[i], hFdCngCom->olapWinSyn[i].v.re ); /*Q15 - noiseExp*/ timeDomainOutput[i] = add( timeDomainOutput[i], tmp ); move16(); - tmp = mult( noise[add( i, N4 )], hFdCngCom->olapWinSyn[sub( sub( N4, 1 ), i )].v.im ); - timeDomainOutput[add( i, N4 )] = add( timeDomainOutput[add( i, N4 )], tmp ); + tmp = mult( noise[( i + N4 )], hFdCngCom->olapWinSyn[( ( N4 - 1 ) - i )].v.im ); /*Q15 - noiseExp*/ + timeDomainOutput[( i + N4 )] = add( timeDomainOutput[( i + N4 )], tmp ); move16(); } } @@ -3904,13 +3904,13 @@ void generate_comfort_noise_dec_fx( } void generate_comfort_noise_dec_ivas_fx( - Word32 **bufferReal, /* o : Real part of input bands */ - Word32 **bufferImag, /* o : Imaginary part of input bands */ + Word32 **bufferReal, /* o : Real part of input bands bufferScale*/ + Word32 **bufferImag, /* o : Imaginary part of input bands bufferScale*/ Word16 *bufferScale, /* o : pointer to scalefactor for real and imaginary part of input bands */ Decoder_State *st, /* i/o: decoder state structure */ Word16 *Q_new, - Word16 gen_exc, - const Word16 nchan_out /* i : number of output channels */ + Word16 gen_exc, /*Q0*/ + const Word16 nchan_out /* i : number of output channels Q0*/ ) { Word16 i, j, s; @@ -3927,7 +3927,7 @@ void generate_comfort_noise_dec_ivas_fx( Word16 c1, c2; Word32 tmp1, tmp2; Word16 scaleCldfb; - Word32 *fftBuffer = hFdCngCom->fftBuffer; + Word32 *fftBuffer = hFdCngCom->fftBuffer; /*hFdCngCom->fftBuffer_exp*/ Word16 fftBuffer_exp = hFdCngCom->fftBuffer_exp; Word16 fftBuffer_temp_exp[FFTLEN]; Word16 *timeDomainOutput = hFdCngCom->timeDomainBuffer; @@ -3944,19 +3944,19 @@ void generate_comfort_noise_dec_ivas_fx( hTcxDec = st->hTcxDec; - scaleCldfb = mult( hFdCngCom->invScalingFactor, CLDFB_SCALING ); + scaleCldfb = mult( hFdCngCom->invScalingFactor, CLDFB_SCALING ); /*CLDFBinvScalingFactor_EXP + 1*/ temp = 0; move16(); - c1 = Sqrt16( hFdCngCom->coherence_fx, &temp ); - c1 = shl( c1, temp ); + c1 = Sqrt16( hFdCngCom->coherence_fx, &temp ); /*Q15 - temp*/ + c1 = shl( c1, temp ); /*Q15*/ temp = 0; move16(); - c2 = Sqrt16( sub( MAX_16, hFdCngCom->coherence_fx ), &temp ); - c2 = shl( c2, temp ); + c2 = Sqrt16( sub( MAX_16, hFdCngCom->coherence_fx ), &temp ); /*Q15 - temp*/ + c2 = shl( c2, temp ); /*Q15*/ temp = getScaleFactor32( fftBuffer, FFTLEN ); - scale_sig32( fftBuffer, FFTLEN, temp ); + scale_sig32( fftBuffer, FFTLEN, temp ); /*Q31 - hFdCngCom->fftBuffer_exp + temp*/ fftBuffer_exp = sub( fftBuffer_exp, temp ); hFdCngCom->fftBuffer_exp = fftBuffer_exp; move16(); @@ -3982,7 +3982,7 @@ void generate_comfort_noise_dec_ivas_fx( { rand_gauss_fx( &tmp1, seed, Q15 ); rand_gauss_fx( &tmp2, seed2, Q15 ); - fftBuffer[0] = L_add( Mpy_32_16_1( tmp1, c1 ), Mpy_32_16_1( tmp2, c2 ) ); + fftBuffer[0] = L_add( Mpy_32_16_1( tmp1, c1 ), Mpy_32_16_1( tmp2, c2 ) ); /*Q0*/ move32(); fftBuffer_temp_exp[0] = Q16 + Q15; move16(); @@ -3995,13 +3995,13 @@ void generate_comfort_noise_dec_ivas_fx( } sqrtNoiseLevel_exp = cngNoiseLevel_exp; move16(); - sqrtNoiseLevel = Sqrt32( *ptr_level, &sqrtNoiseLevel_exp ); - fftBuffer[0] = Mpy_32_32( fftBuffer[0], sqrtNoiseLevel ); + sqrtNoiseLevel = Sqrt32( *ptr_level, &sqrtNoiseLevel_exp ); /*Q31 - sqrtNoiseLevel_exp*/ + fftBuffer[0] = Mpy_32_32( fftBuffer[0], sqrtNoiseLevel ); /*Q31 - (sqrtNoiseLevel_exp + fftBuffer_temp_exp[0])*/ move32(); fftBuffer_temp_exp[0] = add( sqrtNoiseLevel_exp, fftBuffer_temp_exp[0] ); move16(); ptr_level++; - ptr_r = fftBuffer + 2; + ptr_r = fftBuffer + 2; /*Q31 - (fftBuffer_temp_exp)*/ idx = 2; } ELSE @@ -4009,11 +4009,11 @@ void generate_comfort_noise_dec_ivas_fx( fftBuffer[0] = 0; move16(); set32_fx( fftBuffer + 2, 0, shl( sub( hFdCngCom->startBand, 1 ), 1 ) ); - ptr_r = fftBuffer + shl( hFdCngCom->startBand, 1 ); - idx = shl( hFdCngCom->startBand, 1 ); + ptr_r = fftBuffer + shl( hFdCngCom->startBand, 1 ); /*Q31 - fftBuffer_exp*/ + idx = shl( hFdCngCom->startBand, 1 ); /*Q0*/ } - ptr_i = ptr_r + 1; + ptr_i = ptr_r + 1; /*Q31 - fftBuffer_exp*/ FOR( ; ptr_level < cngNoiseLevel + sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ); ptr_level++ ) { /* Real part in FFT bins */ @@ -4021,23 +4021,23 @@ void generate_comfort_noise_dec_ivas_fx( test(); IF( EQ_16( st->element_mode, IVAS_CPE_MDCT ) || ( EQ_16( st->element_mode, IVAS_SCE ) && st->cng_ism_flag ) ) { - rand_gauss_fx( &tmp1, seed, Q15 ); - rand_gauss_fx( &tmp2, seed2, Q15 ); - *ptr_r = L_add( Mpy_32_16_1( tmp1, c1 ), Mpy_32_16_1( tmp2, c2 ) ); + rand_gauss_fx( &tmp1, seed, Q15 ); /*Q15*/ + rand_gauss_fx( &tmp2, seed2, Q15 ); /*Q15*/ + *ptr_r = L_add( Mpy_32_16_1( tmp1, c1 ), Mpy_32_16_1( tmp2, c2 ) ); /*Q15*/ move32(); fftBuffer_temp_exp[idx] = Q16; move16(); } ELSE { - rand_gauss_fx( ptr_r, seed, Q15 ); + rand_gauss_fx( ptr_r, seed, Q15 ); /*Q15*/ fftBuffer_temp_exp[idx] = Q16; move16(); } sqrtNoiseLevel_exp = sub( cngNoiseLevel_exp, 1 ); - sqrtNoiseLevel = Sqrt32( *ptr_level, &sqrtNoiseLevel_exp ); - ( *ptr_r ) = Mpy_32_32( ( *ptr_r ), sqrtNoiseLevel ); + sqrtNoiseLevel = Sqrt32( *ptr_level, &sqrtNoiseLevel_exp ); /*Q31 - sqrtNoiseLevel_exp*/ + ( *ptr_r ) = Mpy_32_32( ( *ptr_r ), sqrtNoiseLevel ); /*Q15 - sqrtNoiseLevel_exp*/ move32(); fftBuffer_temp_exp[idx] = add( fftBuffer_temp_exp[idx], sqrtNoiseLevel_exp ); move16(); @@ -4049,22 +4049,22 @@ void generate_comfort_noise_dec_ivas_fx( test(); IF( EQ_16( st->element_mode, IVAS_CPE_MDCT ) || ( EQ_16( st->element_mode, IVAS_SCE ) && st->cng_ism_flag ) ) { - rand_gauss_fx( &tmp1, seed, Q15 ); - rand_gauss_fx( &tmp2, seed2, Q15 ); - *ptr_i = L_add( Mpy_32_16_1( tmp1, c1 ), Mpy_32_16_1( tmp2, c2 ) ); + rand_gauss_fx( &tmp1, seed, Q15 ); /*Q15*/ + rand_gauss_fx( &tmp2, seed2, Q15 ); /*Q15*/ + *ptr_i = L_add( Mpy_32_16_1( tmp1, c1 ), Mpy_32_16_1( tmp2, c2 ) ); /*Q15*/ move32(); fftBuffer_temp_exp[idx] = Q16; move16(); } ELSE { - rand_gauss_fx( ptr_i, seed, Q15 ); + rand_gauss_fx( ptr_i, seed, Q15 ); /*Q15*/ fftBuffer_temp_exp[idx] = Q16; move16(); } sqrtNoiseLevel_exp = sub( cngNoiseLevel_exp, 1 ); - sqrtNoiseLevel = Sqrt32( *ptr_level, &sqrtNoiseLevel_exp ); - ( *ptr_i ) = Mpy_32_32( ( *ptr_i ), sqrtNoiseLevel ); + sqrtNoiseLevel = Sqrt32( *ptr_level, &sqrtNoiseLevel_exp ); /*Q31 - sqrtNoiseLevel_exp*/ + ( *ptr_i ) = Mpy_32_32( ( *ptr_i ), sqrtNoiseLevel ); /*Q15 - sqrtNoiseLevel_exp*/ move32(); fftBuffer_temp_exp[idx] = add( fftBuffer_temp_exp[idx], sqrtNoiseLevel_exp ); move16(); @@ -4082,7 +4082,7 @@ void generate_comfort_noise_dec_ivas_fx( fftBuffer_exp = MAX_16; move16(); - FOR( i = 0; i < FFTLEN; i++ ) + FOR( i = 0; i < hFdCngCom->fftlen; i++ ) { IF( fftBuffer[i] != 0 ) { @@ -4095,9 +4095,9 @@ void generate_comfort_noise_dec_ivas_fx( move16(); } fftBuffer_exp = sub( 31, fftBuffer_exp ); - FOR( i = 0; i < FFTLEN; i++ ) + FOR( i = 0; i < hFdCngCom->fftlen; i++ ) { - fftBuffer[i] = L_shr( fftBuffer[i], sub( fftBuffer_exp, fftBuffer_temp_exp[i] ) ); + fftBuffer[i] = L_shr( fftBuffer[i], sub( fftBuffer_exp, fftBuffer_temp_exp[i] ) ); /*Q31 - fftBuffer_temp_exp[i]*/ move32(); } @@ -4119,7 +4119,7 @@ void generate_comfort_noise_dec_ivas_fx( /* Perform STFT synthesis */ SynthesisSTFT_ivas_fx( fftBuffer, fftBuffer_exp, timeDomainOutput, hFdCngCom->olapBufferSynth, hFdCngCom->olapWinSyn, tcx_transition, hFdCngCom, gen_exc, Q_new, st->element_mode, nchan_out ); - scale_sig32( fftBuffer + hFdCngCom->fftlen, sub( FFTLEN, hFdCngCom->fftlen ), sub( fftBuffer_exp, hFdCngCom->fftBuffer_exp ) ); + scale_sig32( fftBuffer + hFdCngCom->fftlen, sub( FFTLEN, hFdCngCom->fftlen ), sub( fftBuffer_exp, hFdCngCom->fftBuffer_exp ) ); /*Q31 - fftBuffer_exp*/ { Word32 Lener, att; @@ -4128,12 +4128,12 @@ void generate_comfort_noise_dec_ivas_fx( /* calculate the residual signal energy */ /*enr = dotp( hFdCngCom->exc_cng, hFdCngCom->exc_cng, hFdCngCom->frameSize ) / hFdCngCom->frameSize;*/ - Lener = Dot_productSq16HQ( 1, hFdCngCom->exc_cng, st->L_frame, &exp ); - exp = add( sub( shl( sub( 15, *Q_new ), 1 ), 8 ), exp ); /*8 = log2(256)*/ + Lener = Dot_productSq16HQ( 1, hFdCngCom->exc_cng, st->L_frame, &exp ); /*Q31 - exp*/ + exp = add( sub( shl( sub( 15, *Q_new ), 1 ), 8 ), exp ); /*8 = log2(256)*/ /* convert log2 of residual signal energy */ /*(float)log10( enr + 0.1f ) / (float)log10( 2.0f );*/ - Lener = BASOP_Util_Log2( Lener ); + Lener = BASOP_Util_Log2( Lener ); /*Q25*/ Lener = L_add( Lener, L_shl( L_deposit_l( exp ), WORD32_BITS - 1 - LD_DATA_SCALE ) ); /*Q25*/ if ( EQ_16( st->L_frame, L_FRAME16k ) ) { @@ -4147,24 +4147,24 @@ void generate_comfort_noise_dec_ivas_fx( IF( st->CNG_mode >= 0 ) { /* Bitrate adapted attenuation */ - att = L_shl( L_deposit_l( ENR_ATT_fx[st->CNG_mode] ), 17 ); + att = L_shl( L_deposit_l( ENR_ATT_fx[st->CNG_mode] ), 17 ); /*Q25*/ } ELSE { /* Use least attenuation for higher bitrates */ - att = L_shl( L_deposit_l( ENR_ATT_fx[4] ), 17 ); + att = L_shl( L_deposit_l( ENR_ATT_fx[4] ), 17 ); /*Q25*/ } } ELSE { - att = 384 << 17; - move16(); /*1.5 Q8<<17=Q25*/ + att = 384 << 17; /*1.5 Q8<<17=Q25*/ + move16(); } Lener = L_sub( Lener, att ); } /*st->lp_ener = 0.8f * stcod->lp_ener + 0.2f * pow( 2.0f, enr );*/ - Lener = BASOP_util_Pow2( Lener, 6, &exp ); - Lener = Mult_32_16( Lener, 6554 /*0.2f Q15*/ ); + Lener = BASOP_util_Pow2( Lener, 6, &exp ); /*Q31 - exp*/ + Lener = Mult_32_16( Lener, 6554 /*0.2f Q15*/ ); /*Q31 - exp*/ exp = sub( 25, exp ); Lener = L_shr( Lener, exp ); /*Q6*/ st->lp_ener_fx = L_add( Mult_32_16( st->lp_ener_fx, 26214 /*0.8f Q15*/ ), Lener ); /*Q6*/ @@ -4184,29 +4184,29 @@ void generate_comfort_noise_dec_ivas_fx( FOR( j = hFdCngCom->numCoreBands; j < hFdCngCom->regularStopBand; j++ ) { sqrtNoiseLevel_exp = add( CLDFBinvScalingFactor_EXP, sub( cngNoiseLevel_exp, 1 ) ); - sqrtNoiseLevel = Sqrt32( Mpy_32_16_1( *ptr_level, scaleCldfb ), &sqrtNoiseLevel_exp ); + sqrtNoiseLevel = Sqrt32( Mpy_32_16_1( *ptr_level, scaleCldfb ), &sqrtNoiseLevel_exp ); /*Q31 - sqrtNoiseLevel_exp*/ FOR( i = 0; i < hFdCngCom->numSlots; i++ ) { /* Real part in CLDFB band */ IF( EQ_16( st->element_mode, IVAS_CPE_MDCT ) || ( EQ_16( st->element_mode, IVAS_SCE ) && st->cng_ism_flag ) ) { - rand_gauss_fx( &tmp1, seed, Q15 ); - rand_gauss_fx( &tmp2, seed2, Q15 ); - bufferReal[i][j] = L_add( Mpy_32_16_1( tmp1, c1 ), Mpy_32_16_1( tmp2, c2 ) ); + rand_gauss_fx( &tmp1, seed, Q15 ); /*Q15*/ + rand_gauss_fx( &tmp2, seed2, Q15 ); /*Q15*/ + bufferReal[i][j] = L_add( Mpy_32_16_1( tmp1, c1 ), Mpy_32_16_1( tmp2, c2 ) ); /*Q15*/ move32(); bufferReal_exp[j] = Q16; move16(); } ELSE { - rand_gauss_fx( &bufferReal[i][j], seed, Q15 ); + rand_gauss_fx( &bufferReal[i][j], seed, Q15 ); /*Q15*/ move32(); bufferReal_exp[j] = Q16; move16(); } - bufferReal[i][j] = Mpy_32_32( bufferReal[i][j], sqrtNoiseLevel ); + bufferReal[i][j] = Mpy_32_32( bufferReal[i][j], sqrtNoiseLevel ); /*Q31 - ( bufferReal_exp[j] + sqrtNoiseLevel_exp )*/ move32(); bufferReal_exp[j] = add( bufferReal_exp[j], sqrtNoiseLevel_exp ); move16(); @@ -4214,20 +4214,20 @@ void generate_comfort_noise_dec_ivas_fx( /* Imaginary part in CLDFB band */ IF( EQ_16( st->element_mode, IVAS_CPE_MDCT ) || ( EQ_16( st->element_mode, IVAS_SCE ) && st->cng_ism_flag ) ) { - rand_gauss_fx( &tmp1, seed, Q15 ); - rand_gauss_fx( &tmp2, seed2, Q15 ); - bufferImag[i][j] = L_add( Mpy_32_16_1( tmp1, c1 ), Mpy_32_16_1( tmp2, c2 ) ); + rand_gauss_fx( &tmp1, seed, Q15 ); /*Q15*/ + rand_gauss_fx( &tmp2, seed2, Q15 ); /*Q15*/ + bufferImag[i][j] = L_add( Mpy_32_16_1( tmp1, c1 ), Mpy_32_16_1( tmp2, c2 ) ); /*Q15*/ move32(); bufferImag_exp[j] = Q16; move16(); } ELSE { - rand_gauss_fx( &bufferImag[i][j], seed, Q15 ); + rand_gauss_fx( &bufferImag[i][j], seed, Q15 ); /*Q15*/ bufferImag_exp[j] = Q16; move16(); } - bufferImag[i][j] = Mpy_32_32( bufferImag[i][j], sqrtNoiseLevel ); + bufferImag[i][j] = Mpy_32_32( bufferImag[i][j], sqrtNoiseLevel ); /*Q31 - ( bufferReal_exp[j] + sqrtNoiseLevel_exp )*/ bufferImag_exp[j] = add( bufferImag_exp[j], sqrtNoiseLevel_exp ); move16(); @@ -4248,9 +4248,9 @@ void generate_comfort_noise_dec_ivas_fx( { FOR( i = 0; i < hFdCngCom->numSlots; i++ ) { - bufferImag[i][j] = L_shr( bufferImag[i][j], sub( *bufferScale, bufferImag_exp[j] ) ); + bufferImag[i][j] = L_shr( bufferImag[i][j], sub( *bufferScale, bufferImag_exp[j] ) ); /*bufferImag_exp*/ move32(); - bufferReal[i][j] = L_shr( bufferReal[i][j], sub( *bufferScale, bufferReal_exp[j] ) ); + bufferReal[i][j] = L_shr( bufferReal[i][j], sub( *bufferScale, bufferReal_exp[j] ) ); /*bufferReal_exp*/ move32(); } } @@ -4271,9 +4271,9 @@ void generate_comfort_noise_dec_ivas_fx( assert( hFdCngCom->frameSize <= 640 ); - seed_loc = hFdCngCom->seed; + seed_loc = hFdCngCom->seed; /*Q0*/ move16(); - N = hFdCngCom->frameSize; + N = hFdCngCom->frameSize; /*Q0*/ move16(); N2 = shr( hFdCngCom->frameSize, 1 ); @@ -4294,7 +4294,7 @@ void generate_comfort_noise_dec_ivas_fx( { FOR( i = 0; i < sub( hFdCngCom->frameSize, NS2SA( st->sr_core, N_ZERO_MDCT_NS ) ); i++ ) { - timeDomainOutput[i] = add( timeDomainOutput[i], shr_r( st->hHQ_core->old_out_LB_fx[i + NS2SA( st->sr_core, N_ZERO_MDCT_NS )], st->hHQ_core->Q_old_wtda_LB ) ); + timeDomainOutput[i] = add( timeDomainOutput[i], shr_r( st->hHQ_core->old_out_LB_fx[i + NS2SA( st->sr_core, N_ZERO_MDCT_NS )], st->hHQ_core->Q_old_wtda_LB ) ); /*st->q_old_outLB_fx*/ move16(); } } @@ -4305,7 +4305,7 @@ void generate_comfort_noise_dec_ivas_fx( FOR( i = 0; i < st->hTcxCfg->tcx_mdct_window_length; i++ ) { - timeDomainOutput[i] = add( timeDomainOutput[i], shl( hTcxDec->syn_Overl[i], TCX_IMDCT_HEADROOM ) ); + timeDomainOutput[i] = add( timeDomainOutput[i], shl( hTcxDec->syn_Overl[i], TCX_IMDCT_HEADROOM ) ); /*st->q_old_outLB_fx*/ move16(); } } @@ -4327,12 +4327,12 @@ void generate_comfort_noise_dec_ivas_fx( lpcorder = M; move16(); - old_Aq = st->old_Aq_12_8_fx; - old_exc = st->old_exc_fx + sub( L_EXC_MEM_DEC, N2 ); - old_syn_pe = st->mem_syn2_fx; - old_syn = st->syn[lpcorder]; + old_Aq = st->old_Aq_12_8_fx; /*Q12*/ + old_exc = st->old_exc_fx + sub( L_EXC_MEM_DEC, N2 ); /*Q_exc*/ + old_syn_pe = st->mem_syn2_fx; /*Q_syn*/ + old_syn = st->syn[lpcorder]; /*Q_syn*/ move16(); - preemph_fac = st->preemph_fac; + preemph_fac = st->preemph_fac; /*Q15*/ move16(); Q_exc = st->Q_exc; move16(); @@ -4349,16 +4349,16 @@ void generate_comfort_noise_dec_ivas_fx( normShiftEM1 = sub( normShiftE, 1 ); normShiftP2 = add( normShiftE, CNG_NORM_RECIPROCAL_RANGE_SHIFT ); - old_exc_ener = L_shr( L_mult( old_exc[0], old_exc[0] ), normShiftP2 ); + old_exc_ener = L_shr( L_mult( old_exc[0], old_exc[0] ), normShiftP2 ); /*2*(Q_exc)+1+normShiftP2*/ FOR( i = 1; i < N2; i++ ) { - old_exc_ener = L_add( old_exc_ener, L_shr( L_mult( old_exc[i], old_exc[i] ), normShiftP2 ) ); + old_exc_ener = L_add( old_exc_ener, L_shr( L_mult( old_exc[i], old_exc[i] ), normShiftP2 ) ); /*2*(Q_exc)+1+normShiftP2*/ } - old_exc_ener = L_shl( Mpy_32_16_1( old_exc_ener, shl( normFacE, normShiftEM1 ) ), 1 ); + old_exc_ener = L_shl( Mpy_32_16_1( old_exc_ener, shl( normFacE, normShiftEM1 ) ), 1 ); /*Q31*/ old_exc_ener_exp = 0; move16(); - old_exc_ener = Sqrt32( old_exc_ener, &old_exc_ener_exp ); + old_exc_ener = Sqrt32( old_exc_ener, &old_exc_ener_exp ); /*Q31 - old_exc_ener_exp*/ old_exc_ener_exp = add( old_exc_ener_exp, ( sub( 15, Q_exc ) ) ); /* shift to be in the range of values supported by getNormReciprocalWord16() */ @@ -4379,14 +4379,14 @@ void generate_comfort_noise_dec_ivas_fx( move16(); gain = L_add( gain, L_shr( L_mult( noise[i], noise[i] ), normShiftP2 ) ); } - gain = L_shl( Mpy_32_16_1( gain, shl( normFacG, normShiftGM1 ) ), 1 ); + gain = L_shl( Mpy_32_16_1( gain, shl( normFacG, normShiftGM1 ) ), 1 ); /*Q31 - gain_exp*/ gain_exp = 2 * CNG_RAND_GAUSS_SHIFT; move16(); - gain = ISqrt32( gain, &gain_exp ); + gain = ISqrt32( gain, &gain_exp ); /*Q31 - gain_exp*/ - gain = Mpy_32_32( old_exc_ener, gain ); - gain16 = extract_h( gain ); + gain = Mpy_32_32( old_exc_ener, gain ); /*Q31 - old_exc_ener_exp - gain_exp*/ + gain16 = extract_h( gain ); /*Q15 - old_exc_ener_exp - gain_exp*/ gain_exp = add( old_exc_ener_exp, gain_exp ); noiseExp = add( CNG_RAND_GAUSS_SHIFT, gain_exp ); @@ -4395,7 +4395,7 @@ void generate_comfort_noise_dec_ivas_fx( FOR( i = 0; i < N; i++ ) { #ifdef BASOP_NOGLOB - noise[i] = shr_sat( mult( noise[i], gain16 ), s ); + noise[i] = shr_sat( mult( noise[i], gain16 ), s ); /*Q15 - noiseExp*/ #else noise[i] = shr( mult( noise[i], gain16 ), s ); #endif @@ -4408,7 +4408,7 @@ void generate_comfort_noise_dec_ivas_fx( FOR( i = 0; i < lpcorder; i++ ) { #ifdef BASOP_NOGLOB - old_syn_pe_tmp[i] = shr_sat( old_syn_pe[i], s ); + old_syn_pe_tmp[i] = shr_sat( old_syn_pe[i], s ); /*Q0*/ #else old_syn_pe_tmp[i] = shr( old_syn_pe[i], s ); #endif @@ -4439,11 +4439,11 @@ void generate_comfort_noise_dec_ivas_fx( FOR( i = 0; i < N4; i++ ) { - tmp = mult( noise[i], hFdCngCom->olapWinSyn[i].v.re ); + tmp = mult( noise[i], hFdCngCom->olapWinSyn[i].v.re ); /*Q15 - noiseExp*/ timeDomainOutput[i] = add( timeDomainOutput[i], tmp ); move16(); - tmp = mult( noise[add( i, N4 )], hFdCngCom->olapWinSyn[sub( sub( N4, 1 ), i )].v.im ); - timeDomainOutput[add( i, N4 )] = add( timeDomainOutput[add( i, N4 )], tmp ); + tmp = mult( noise[( i + N4 )], hFdCngCom->olapWinSyn[( ( N4 - 1 ) - i )].v.im ); /*Q15 - noiseExp*/ + timeDomainOutput[( i + N4 )] = add( timeDomainOutput[( i + N4 )], tmp ); move16(); move16(); } @@ -4453,8 +4453,8 @@ void generate_comfort_noise_dec_ivas_fx( } void generate_comfort_noise_dec_hf_fx( - Word32 **bufferReal, /* o : matrix to real part of input bands */ - Word32 **bufferImag, /* o : matrix to imaginary part of input bands */ + Word32 **bufferReal, /* o : matrix to real part of input bands bufferScale*/ + Word32 **bufferImag, /* o : matrix to imaginary part of input bands bufferScale*/ Word16 *bufferScale, /* o : pointer to scalefactor for real and imaginary part of input bands */ Decoder_State *st ) { @@ -4468,14 +4468,14 @@ void generate_comfort_noise_dec_hf_fx( Word32 *ptr_level; HANDLE_FD_CNG_COM hFdCngCom = st->hFdCngDec->hFdCngCom; - cngNoiseLevel = hFdCngCom->cngNoiseLevel + sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ); + cngNoiseLevel = hFdCngCom->cngNoiseLevel + sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ); /*Q31 - hFdCngCom->cngNoiseLevelExp*/ cngNoiseLevelExp = hFdCngCom->cngNoiseLevelExp; move16(); - ptr_level = cngNoiseLevel; + ptr_level = cngNoiseLevel; /*Q31 - hFdCngCom->cngNoiseLevelExp*/ seed = &( hFdCngCom->seed ); /* scaleCLDFB: CLDFBinvScalingFactor_EXP + 1 */ - scaleCLDFB = mult( hFdCngCom->invScalingFactor, CLDFB_SCALING ); + scaleCLDFB = mult( hFdCngCom->invScalingFactor, CLDFB_SCALING ); /*CLDFBinvScalingFactor_EXP + 1*/ sn = 0; move16(); @@ -4500,21 +4500,21 @@ void generate_comfort_noise_dec_hf_fx( /* scaleCLDFB: CLDFBinvScalingFactor_EXP + 1 */ s = 0; move16(); - sqrtNoiseLevel = Sqrt32( L_shr( Mpy_32_16_1( *ptr_level, scaleCLDFB ), sn ), &s ); + sqrtNoiseLevel = Sqrt32( L_shr( Mpy_32_16_1( *ptr_level, scaleCLDFB ), sn ), &s ); /*Q31 - s*/ FOR( i = 0; i < hFdCngCom->numSlots; i++ ) { /* Real part in CLDFB band */ - bufferReal[i][j] = L_shl( Mpy_32_32( rand_gauss( seed ), sqrtNoiseLevel ), s ); + bufferReal[i][j] = L_shl( Mpy_32_32( rand_gauss( seed ), sqrtNoiseLevel ), s ); /*bufferScale*/ move32(); /*fprintf(pFile,"%13.10f\n",WORD322FL_SCALE(bufferReal[i][j],sc));*/ /* Imaginary part in CLDFB band */ - bufferImag[i][j] = L_shl( Mpy_32_32( rand_gauss( seed ), sqrtNoiseLevel ), s ); + bufferImag[i][j] = L_shl( Mpy_32_32( rand_gauss( seed ), sqrtNoiseLevel ), s ); /*bufferScale*/ move32(); /*fprintf(pFile,"%13.10f\n",WORD322FL_SCALE(bufferImag[i][j],sc));*/ } - ptr_level = ptr_level + 1; + ptr_level = ptr_level + 1; /*Q31 - hFdCngCom->cngNoiseLevelExp*/ } *bufferScale = sub( sc, 15 ); move16(); @@ -4522,11 +4522,11 @@ void generate_comfort_noise_dec_hf_fx( } void generate_comfort_noise_dec_hf_ivas_fx( - Word32 **bufferReal, /* o : matrix to real part of input bands */ - Word32 **bufferImag, /* o : matrix to imaginary part of input bands */ + Word32 **bufferReal, /* o : matrix to real part of input bands bufferScale*/ + Word32 **bufferImag, /* o : matrix to imaginary part of input bands bufferScale*/ Word16 *bufferScale, /* o : pointer to scalefactor for real and imaginary part of input bands */ HANDLE_FD_CNG_COM hFdCngCom, /* i/o: FD_CNG structure containing all buffers and variables */ - const Word16 cng_coh_flag /* i : CNG Flag for coherence handling */ + const Word16 cng_coh_flag /* i : CNG Flag for coherence handling Q0*/ ) { Word16 i, j, s, sc, sn; @@ -4541,15 +4541,15 @@ void generate_comfort_noise_dec_hf_ivas_fx( Word32 *cngNoiseLevel; Word32 tmp1, tmp2; - cngNoiseLevel = hFdCngCom->cngNoiseLevel + sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ); + cngNoiseLevel = hFdCngCom->cngNoiseLevel + sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ); /*Q31 - hFdCngCom->cngNoiseLevelExp*/ cngNoiseLevelExp = hFdCngCom->cngNoiseLevelExp; move16(); - ptr_level = cngNoiseLevel; + ptr_level = cngNoiseLevel; /*Q31 - hFdCngCom->cngNoiseLevelExp*/ seed = &( hFdCngCom->seed ); /* scaleCLDFB: CLDFBinvScalingFactor_EXP + 1 */ - scaleCLDFB = mult( hFdCngCom->invScalingFactor, CLDFB_SCALING ); + scaleCLDFB = mult( hFdCngCom->invScalingFactor, CLDFB_SCALING ); /*CLDFBinvScalingFactor_EXP + 1*/ seed2 = &( hFdCngCom->seed ); @@ -4567,13 +4567,13 @@ void generate_comfort_noise_dec_hf_ivas_fx( s = 0; move16(); - c1 = Sqrt16( hFdCngCom->coherence_fx, &s ); - c1 = shl( c1, s ); // Q15 + c1 = Sqrt16( hFdCngCom->coherence_fx, &s ); /*Q15 - s*/ + c1 = shl( c1, s ); // Q15 s = 0; move16(); - c2 = Sqrt16( sub( MAX16B, hFdCngCom->coherence_fx ), &s ); - c2 = shl( c2, s ); // Q15 + c2 = Sqrt16( sub( MAX16B, hFdCngCom->coherence_fx ), &s ); /*Q15 - s*/ + c2 = shl( c2, s ); // Q15 } sn = 0; @@ -4605,38 +4605,38 @@ void generate_comfort_noise_dec_hf_ivas_fx( /* scaleCLDFB: CLDFBinvScalingFactor_EXP + 1 */ s = 0; move16(); - sqrtNoiseLevel = Sqrt32( L_shr( Mpy_32_16_1( *ptr_level, scaleCLDFB ), sn ), &s ); + sqrtNoiseLevel = Sqrt32( L_shr( Mpy_32_16_1( *ptr_level, scaleCLDFB ), sn ), &s ); /*Q31 - s*/ IF( cng_coh_flag ) { - rand_gauss_fx( &tmp1, seed, Q28 ); - rand_gauss_fx( &tmp2, seed2, Q28 ); + rand_gauss_fx( &tmp1, seed, Q28 ); /*Q28*/ + rand_gauss_fx( &tmp2, seed2, Q28 ); /*Q28*/ - bufferReal[i][j] = L_add( Mpy_32_16_1( tmp1, c1 ), Mpy_32_16_1( tmp2, c2 ) ); + bufferReal[i][j] = L_add( Mpy_32_16_1( tmp1, c1 ), Mpy_32_16_1( tmp2, c2 ) ); /*bufferScale*/ move32(); - bufferReal[i][j] = L_shl( Mpy_32_32( bufferReal[i][j], sqrtNoiseLevel ), s ); + bufferReal[i][j] = L_shl( Mpy_32_32( bufferReal[i][j], sqrtNoiseLevel ), s ); /*bufferScale*/ move32(); - rand_gauss_fx( &tmp1, seed, Q28 ); - rand_gauss_fx( &tmp2, seed2, Q28 ); + rand_gauss_fx( &tmp1, seed, Q28 ); /*Q28*/ + rand_gauss_fx( &tmp2, seed2, Q28 ); /*Q28*/ - bufferImag[i][j] = L_add( Mpy_32_16_1( tmp1, c1 ), Mpy_32_16_1( tmp2, c2 ) ); + bufferImag[i][j] = L_add( Mpy_32_16_1( tmp1, c1 ), Mpy_32_16_1( tmp2, c2 ) ); /*bufferScale*/ move32(); - bufferImag[i][j] = L_shl( Mpy_32_32( bufferImag[i][j], sqrtNoiseLevel ), s ); + bufferImag[i][j] = L_shl( Mpy_32_32( bufferImag[i][j], sqrtNoiseLevel ), s ); /*bufferScale*/ move32(); } ELSE { /* Real part in CLDFB band */ - bufferReal[i][j] = L_shl( Mpy_32_32( L_shr( rand_gauss( seed ), 1 ), sqrtNoiseLevel ), s ); + bufferReal[i][j] = L_shl( Mpy_32_32( L_shr( rand_gauss( seed ), 1 ), sqrtNoiseLevel ), s ); /*bufferScale*/ move32(); /* Imaginary part in CLDFB band */ - bufferImag[i][j] = L_shl( Mpy_32_32( L_shr( rand_gauss( seed ), 1 ), sqrtNoiseLevel ), s ); + bufferImag[i][j] = L_shl( Mpy_32_32( L_shr( rand_gauss( seed ), 1 ), sqrtNoiseLevel ), s ); /*bufferScale*/ move32(); } } - ptr_level = ptr_level + 1; + ptr_level = ptr_level + 1; /*Q31 - hFdCngCom->cngNoiseLevelExp*/ } *bufferScale = sub( sc, 15 ); move16(); @@ -4669,8 +4669,8 @@ void generate_masking_noise_fx( Word16 Q, HANDLE_FD_CNG_COM hFdCngCom /* i/o : pointer to FD_CNG_COM structure */ , - Word16 length, - Word16 core ) + Word16 length, /*Q0*/ + Word16 core /*Q0*/ ) { Word16 i, s, s1, s2, sq, cnt, startBand2, stopFFTbin2; Word16 scaleExp, fftBufferExp, cngNoiseLevelExp; @@ -4684,8 +4684,8 @@ void generate_masking_noise_fx( // PMTE(); /*IVAS CODE need to be added */ /* pointer initializations */ - cngNoiseLevel = hFdCngCom->cngNoiseLevel; - fftBuffer = hFdCngCom->fftBuffer; + cngNoiseLevel = hFdCngCom->cngNoiseLevel; /*Q31 - hFdCngCom->cngNoiseLevelExp*/ + fftBuffer = hFdCngCom->fftBuffer; /*Q31 - hFdCngCom->fftBuffer_exp*/ seed = &( hFdCngCom->seed ); /* Compute additional CN level */ @@ -4707,7 +4707,7 @@ void generate_masking_noise_fx( IF( ( EQ_16( hFdCngCom->CngBandwidth, scaleTable_cn_only[i].bwmode ) ) && ( GE_32( hFdCngCom->CngBitrate, scaleTable_cn_only[i].bitrateFrom ) ) && ( LT_32( hFdCngCom->CngBitrate, scaleTable_cn_only[i].bitrateTo ) ) ) { - scale = scaleTable_cn_only[i].scale; + scale = scaleTable_cn_only[i].scale; /*Q14*/ move16(); BREAK; } @@ -4726,7 +4726,7 @@ void generate_masking_noise_fx( { IF( GE_32( hFdCngCom->CngBitrate, scaleTable_cn_only_amrwbio[i][0] ) ) { - scale = scaleTable_cn_only_amrwbio[i][1]; + scale = scaleTable_cn_only_amrwbio[i][1]; /*Q14*/ move16(); BREAK; } @@ -4740,7 +4740,7 @@ void generate_masking_noise_fx( /* scaleTable_cn_only[i].scale is scaled by 1 bit */ scaleExp = sub( 1, add( s1, s2 ) ); - scale = mult_r( shl( scale, s1 ), shl( hFdCngCom->likelihood_noisy_speech, s2 ) ); + scale = mult_r( shl( scale, s1 ), shl( hFdCngCom->likelihood_noisy_speech, s2 ) ); /*Q15 - scaleExp*/ { /* add exponent of scale and cngNoiseLevel */ @@ -4756,7 +4756,7 @@ void generate_masking_noise_fx( /* consider scaling of random noise */ fftBufferExp = add( fftBufferExp, CNG_RAND_GAUSS_SHIFT ); - cnt = sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ); + cnt = sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ); /*Q0*/ /* Generate Gaussian random noise in real and imaginary parts of the FFT bins Amplitudes are adjusted to the estimated noise level cngNoiseLevel in each bin @@ -4769,8 +4769,8 @@ void generate_masking_noise_fx( /* -s => consider scalefactor adaptation for sqrt calculation */ sq = sub( 0, s ); - sqrtNoiseLevel = Sqrt32( Mpy_32_16_1( *cngNoiseLevel, scale ), &sq ); - hFdCngCom->fftBuffer[0] = L_shl( Mpy_32_32( rand_gauss( seed ), sqrtNoiseLevel ), sq ); + sqrtNoiseLevel = Sqrt32( Mpy_32_16_1( *cngNoiseLevel, scale ), &sq ); /*Q31 - sq*/ + hFdCngCom->fftBuffer[0] = L_shl( Mpy_32_32( rand_gauss( seed ), sqrtNoiseLevel ), sq ); /*q31 - hFdCngCom->fftBuffer_exp*/ move32(); hFdCngCom->fftBuffer[1] = 0; move32(); @@ -4784,26 +4784,26 @@ void generate_masking_noise_fx( { startBand2 = shl( hFdCngCom->startBand, 1 ); set32_fx( hFdCngCom->fftBuffer, 0, startBand2 ); - fftBuffer = hFdCngCom->fftBuffer + startBand2; + fftBuffer = hFdCngCom->fftBuffer + startBand2; /*Q31 - hFdCngCom->fftBuffer_exp*/ } FOR( i = 0; i < cnt; i++ ) { /* -1 => weighting with 0.5, -s => consider scalefactor adaptation for sqrt calculation */ sq = sub( -1, s ); - sqrtNoiseLevel = Sqrt32( Mpy_32_16_1( *cngNoiseLevel, scale ), &sq ); + sqrtNoiseLevel = Sqrt32( Mpy_32_16_1( *cngNoiseLevel, scale ), &sq ); /*Q31 - sq*/ /* real part in FFT bins */ /* random noise is scaled by CNG_RAND_GAUSS_SHIFT bits */ - *fftBuffer = L_shl( Mpy_32_32( rand_gauss( seed ), sqrtNoiseLevel ), sq ); + *fftBuffer = L_shl( Mpy_32_32( rand_gauss( seed ), sqrtNoiseLevel ), sq ); /*Q31 - hFdCngCom->fftBuffer_exp*/ move32(); fftBuffer++; /* imaginary part in FFT bins */ /* random noise is scaled by CNG_RAND_GAUSS_SHIFT bits */ - *fftBuffer = L_shl( Mpy_32_32( rand_gauss( seed ), sqrtNoiseLevel ), sq ); + *fftBuffer = L_shl( Mpy_32_32( rand_gauss( seed ), sqrtNoiseLevel ), sq ); /*Q31 - hFdCngCom->fftBuffer_exp*/ move32(); fftBuffer++; @@ -4827,7 +4827,7 @@ void generate_masking_noise_fx( { FOR( i = 0; i < length; i++ ) { - timeDomainBuffer[i] = add( timeDomainBuffer[i], shr_r( maskingNoise[i], -Q ) ); + timeDomainBuffer[i] = add( timeDomainBuffer[i], shr_r( maskingNoise[i], -Q ) ); /*Q0*/ move16(); } } @@ -4836,7 +4836,7 @@ void generate_masking_noise_fx( FOR( i = 0; i < hFdCngCom->frameSize; i++ ) { #ifdef BASOP_NOGLOB - timeDomainBuffer[i] = add_sat( timeDomainBuffer[i], shr_r_sat( maskingNoise[i], -Q ) ); + timeDomainBuffer[i] = add_sat( timeDomainBuffer[i], shr_r_sat( maskingNoise[i], -Q ) ); /*Q0*/ #else timeDomainBuffer[i] = add( timeDomainBuffer[i], shr_r( maskingNoise[i], -Q ) ); #endif @@ -4865,18 +4865,18 @@ void generate_masking_noise_update_seed_fx( /* pointer initializations */ seed = &( hFdCngCom->seed ); - cnt = sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ); + cnt = sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ); /*Q0*/ IF( hFdCngCom->startBand == 0 ) { - rand_gauss( seed ); + rand_gauss( seed ); /*Q15*/ cnt = sub( cnt, 1 ); } FOR( i = 0; i < cnt; i++ ) { - rand_gauss( seed ); - rand_gauss( seed ); + rand_gauss( seed ); /*Q15*/ + rand_gauss( seed ); /*Q15*/ } @@ -4889,7 +4889,7 @@ void generate_masking_noise_update_seed_fx( ************************************************************/ #ifdef IVAS_FLOAT_FIXED void generate_masking_noise_mdct_fx( - Word32 *mdctBuffer, /* i/o: time-domain signal */ + Word32 *mdctBuffer, /* i/o: time-domain signal Q31 - mdctBuffer_e*/ Word16 *mdctBuffer_e, /* i/o: exponent time-domain signal */ HANDLE_FD_CNG_COM hFdCngCom /* i/o: FD_CNG structure containing all buffers and variables */ , @@ -4907,7 +4907,7 @@ void generate_masking_noise_mdct_fx( // PMTE(); /*IVAS CODE need to be added */ /* pointer initializations */ - cngNoiseLevel = hFdCngCom->cngNoiseLevel; + cngNoiseLevel = hFdCngCom->cngNoiseLevel; /*Q31 - hFdCngCom->cngNoiseLevelExp*/ seed = &( hFdCngCom->seed ); /* Compute additional CN level */ @@ -4927,7 +4927,7 @@ void generate_masking_noise_mdct_fx( test(); IF( ( EQ_16( hFdCngCom->CngBandwidth, scaleTable_cn_only[i].bwmode ) ) && ( GE_32( hFdCngCom->CngBitrate, scaleTable_cn_only[i].bitrateFrom ) ) && ( LT_32( hFdCngCom->CngBitrate, scaleTable_cn_only[i].bitrateTo ) ) ) { - scale = scaleTable_cn_only[i].scale; + scale = scaleTable_cn_only[i].scale; /*Q14*/ move16(); BREAK; } @@ -4940,7 +4940,7 @@ void generate_masking_noise_mdct_fx( /* scaleTable_cn_only[i].scale is scaled by 1 bit */ scaleExp = sub( 1, add( s1, s2 ) ); - scale = mult_r( shl( scale, s1 ), shl( hFdCngCom->likelihood_noisy_speech, s2 ) ); + scale = mult_r( shl( scale, s1 ), shl( hFdCngCom->likelihood_noisy_speech, s2 ) ); /*Q15 - scaleExp*/ /* add exponent of scale and cngNoiseLevel */ maskingNoiseExp = add( scaleExp, cngNoiseLevelExp ); @@ -4955,7 +4955,7 @@ void generate_masking_noise_mdct_fx( /* consider scaling of random noise */ maskingNoiseExp = add( maskingNoiseExp, CNG_RAND_GAUSS_SHIFT ); - cnt = sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ); + cnt = sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ); /*Q0*/ /* Generate Gaussian random noise in real and imaginary parts of the FFT bins @@ -4969,11 +4969,11 @@ void generate_masking_noise_mdct_fx( /* -1 => weighting with 0.5, -s => consider scalefactor adaptation for sqrt calculation */ sq = sub( -1, s ); - sqrtNoiseLevel = Sqrt32( Mpy_32_16_1( *cngNoiseLevel, scale ), &sq ); - maskingNoise[0] = L_shl( Mpy_32_32( rand_gauss( seed ), sqrtNoiseLevel ), sq ); + sqrtNoiseLevel = Sqrt32( Mpy_32_16_1( *cngNoiseLevel, scale ), &sq ); /*Q31 - sq*/ + maskingNoise[0] = L_shl( Mpy_32_32( rand_gauss( seed ), sqrtNoiseLevel ), sq ); /*Q15*/ move32(); - pMaskingNoise = &maskingNoise[1]; + pMaskingNoise = &maskingNoise[1]; /*Q15*/ cngNoiseLevel++; cnt = sub( cnt, 1 ); @@ -4981,19 +4981,19 @@ void generate_masking_noise_mdct_fx( ELSE { set32_fx( maskingNoise, 0, hFdCngCom->startBand ); - pMaskingNoise = maskingNoise + hFdCngCom->startBand; + pMaskingNoise = maskingNoise + hFdCngCom->startBand; /*Q15*/ } FOR( i = 0; i < cnt; i++ ) { /* -1 => weighting with 0.5, -s => consider scalefactor adaptation for sqrt calculation */ sq = sub( -1, s ); - sqrtNoiseLevel = Sqrt32( Mpy_32_16_1( *cngNoiseLevel, scale ), &sq ); + sqrtNoiseLevel = Sqrt32( Mpy_32_16_1( *cngNoiseLevel, scale ), &sq ); /*Q31 - sq*/ /* real part in FFT bins */ /* random noise is scaled by CNG_RAND_GAUSS_SHIFT bits */ - *pMaskingNoise = L_shl( Mpy_32_32( rand_gauss( seed ), sqrtNoiseLevel ), sq ); + *pMaskingNoise = L_shl( Mpy_32_32( rand_gauss( seed ), sqrtNoiseLevel ), sq ); /*Q15*/ move32(); pMaskingNoise++; @@ -5022,14 +5022,14 @@ void generate_masking_noise_mdct_fx( { /* If shifting negative noise values the lowest result is -1 but never 0. Shift positive noise values to avoid unwanted amplification of these small values later */ - noise = L_shr( Mpy_32_16_1( L_abs( maskingNoise[i] ), 25905 /*0.79056941504 Q15*/ ), s2 ); + noise = L_shr( Mpy_32_16_1( L_abs( maskingNoise[i] ), 25905 /*0.79056941504 Q15*/ ), s2 ); /*Q31 - maskingNoiseExp - s2*/ if ( maskingNoise[i] < 0 ) { noise = L_negate( noise ); } - mdctBuffer[i] = L_add( mdctBuffer[i], noise ); + mdctBuffer[i] = L_add( mdctBuffer[i], noise ); /*Q31 - s*/ move32(); } } @@ -5038,12 +5038,12 @@ void generate_masking_noise_mdct_fx( FOR( i = 0; i < hFdCngCom->stopFFTbin; i++ ) { mdctBuffer[i] = L_add( L_shr( mdctBuffer[i], s1 ), - Mpy_32_16_1( maskingNoise[i], 25905 /*0.79056941504 Q15*/ ) ); + Mpy_32_16_1( maskingNoise[i], 25905 /*0.79056941504 Q15*/ ) ); /*Q31 - s*/ move32(); } FOR( i = hFdCngCom->stopFFTbin; i < L_frame; i++ ) { - mdctBuffer[i] = L_shr( mdctBuffer[i], s1 ); + mdctBuffer[i] = L_shr( mdctBuffer[i], s1 ); /*Q31 - s*/ move32(); } *mdctBuffer_e = s; @@ -5053,7 +5053,7 @@ void generate_masking_noise_mdct_fx( } void generate_masking_noise_mdct_ivas_fx( - Word32 *mdctBuffer, /* i/o: time-domain signal */ + Word32 *mdctBuffer, /* i/o: time-domain signal Q31 - mdctBuffer_e*/ Word16 *mdctBuffer_e, /* i/o: exponent time-domain signal */ HANDLE_FD_CNG_COM hFdCngCom /* i/o: FD_CNG structure containing all buffers and variables */ ) { @@ -5068,7 +5068,7 @@ void generate_masking_noise_mdct_ivas_fx( // PMTE(); /*IVAS CODE need to be added */ /* pointer initializations */ - cngNoiseLevel = hFdCngCom->cngNoiseLevel; + cngNoiseLevel = hFdCngCom->cngNoiseLevel; /*Q31 - hFdCngCom->cngNoiseLevelExp*/ seed = &( hFdCngCom->seed ); /* Compute additional CN level */ @@ -5109,21 +5109,21 @@ void generate_masking_noise_mdct_ivas_fx( sq = cngNoiseLevelExp; move16(); - sqrtNoiseLevel = Sqrt32( temp, &sq ); + sqrtNoiseLevel = Sqrt32( temp, &sq ); /*Q31 - sq*/ rand_gauss_fx( &temp, seed, Q15 ); // Q15 maskingNoise[0] = L_shl( Mpy_32_32( temp, sqrtNoiseLevel ), sq ); // Q15 move32(); - pMaskingNoise = &maskingNoise[1]; + pMaskingNoise = &maskingNoise[1]; /*Q15*/ cngNoiseLevel++; cnt = sub( cnt, 1 ); } ELSE { set32_fx( maskingNoise, 0, hFdCngCom->startBand ); - pMaskingNoise = maskingNoise + hFdCngCom->startBand; + pMaskingNoise = maskingNoise + hFdCngCom->startBand; /*Q15*/ } FOR( i = 0; i < cnt; i++ ) @@ -5134,7 +5134,7 @@ void generate_masking_noise_mdct_ivas_fx( sq = cngNoiseLevelExp; move16(); - sqrtNoiseLevel = Sqrt32( temp, &sq ); + sqrtNoiseLevel = Sqrt32( temp, &sq ); /*Q31 - sq*/ rand_gauss_fx( &temp, seed, Q15 ); // Q15 -- GitLab From b5467e163500208c4ccaa4caf42b57b0a65cd76f Mon Sep 17 00:00:00 2001 From: norvell Date: Fri, 8 Nov 2024 08:03:57 +0000 Subject: [PATCH 096/128] Add "ls -lh public" to get the size of the pages. --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 67e905a6c..a2fd5457f 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1526,7 +1526,7 @@ pages: - *update-scripts-repo - python3 ci/setup_pages.py - ls - - ls public + - ls -lh public artifacts: paths: - public -- GitLab From 9a4c870acef2f722f6b0ae9405cc61191e48a66a Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Fri, 8 Nov 2024 16:00:36 +0530 Subject: [PATCH 097/128] SBA encoder path cleanup, Q-info updates for lib_com [x] sba-enc-reconfigure cleanup [x] NOISE_EST_DATA: disabled 5 float members [x] Q-info updates for lib_com files --- lib_com/cldfb.c | 14 ++- lib_com/cng_exc_fx.c | 101 ++++++++++--------- lib_com/cnst.h | 1 + lib_com/codec_tcx_common.c | 96 +++++++++--------- lib_com/common_api_types.h | 10 +- lib_com/fd_cng_com_fx.c | 2 +- lib_com/igf_base_fx.c | 66 ++----------- lib_com/ivas_dirac_com.c | 10 +- lib_com/ivas_prot.h | 18 +--- lib_com/ivas_prot_fx.h | 17 ++++ lib_com/prot.h | 3 - lib_com/prot_fx.h | 18 ++-- lib_dec/fd_cng_dec_fx.c | 2 +- lib_dec/igf_scf_dec_fx.c | 2 +- lib_dec/ivas_sba_dec.c | 2 +- lib_enc/cod_tcx_fx.c | 15 ++- lib_enc/fd_cng_enc.c | 2 +- lib_enc/fd_cng_enc_fx.c | 2 +- lib_enc/igf_scf_enc_fx.c | 19 ++-- lib_enc/init_enc.c | 8 +- lib_enc/ivas_agc_enc.c | 3 +- lib_enc/ivas_core_pre_proc.c | 1 + lib_enc/ivas_core_pre_proc_front.c | 58 ----------- lib_enc/ivas_corecoder_enc_reconfig.c | 4 +- lib_enc/ivas_cpe_enc.c | 53 ++++------ lib_enc/ivas_front_vad.c | 75 +------------- lib_enc/ivas_init_enc.c | 7 +- lib_enc/ivas_mct_enc.c | 10 +- lib_enc/ivas_osba_enc.c | 2 +- lib_enc/ivas_sba_enc.c | 2 +- lib_enc/ivas_sce_enc.c | 2 +- lib_enc/ivas_spar_encoder.c | 42 +++----- lib_enc/ivas_spar_md_enc.c | 1 + lib_enc/ivas_stat_enc.h | 1 - lib_enc/ivas_stereo_switching_enc.c | 2 +- lib_enc/nois_est_fx.c | 136 +++++++++++--------------- lib_enc/prot_fx_enc.h | 6 +- lib_enc/rom_enc.c | 92 +++++++++++------ lib_enc/rom_enc.h | 9 +- lib_enc/speech_music_classif_fx.c | 66 +++++-------- lib_enc/stat_enc.h | 29 ++---- 41 files changed, 405 insertions(+), 604 deletions(-) diff --git a/lib_com/cldfb.c b/lib_com/cldfb.c index f5efb77d2..d324afcc5 100644 --- a/lib_com/cldfb.c +++ b/lib_com/cldfb.c @@ -1974,7 +1974,7 @@ void analysisCldfbEncoder_ivas_fx( Word16 *ppBuf_Real16[CLDFB_NO_COL_MAX]; Word16 *ppBuf_Imag16[CLDFB_NO_COL_MAX]; Word32 l_timeIn[L_FRAME48k]; - Word16 norm_timeIn = L_norm_arr( timeIn, samplesToProcess ); + Word16 norm_timeIn = s_min( L_norm_arr( timeIn, samplesToProcess ), L_norm_arr( st->cldfbAnaEnc->cldfb_state_fx, sub( st->cldfbAnaEnc->p_filter_length, st->cldfbAnaEnc->no_channels ) ) ); Word16 guard_bits = find_guarded_bits_fx( shl( samplesToProcess, 1 ) ); Word16 shift = 0; move16(); @@ -1990,6 +1990,7 @@ void analysisCldfbEncoder_ivas_fx( { shift = sub( guard_bits, norm_timeIn ); v_shr_32( timeIn, l_timeIn, samplesToProcess, shift ); + scale_sig32( st->cldfbAnaEnc->cldfb_state_fx, sub( st->cldfbAnaEnc->p_filter_length, st->cldfbAnaEnc->no_channels ), negate( shift ) ); } ELSE { @@ -1998,6 +1999,12 @@ void analysisCldfbEncoder_ivas_fx( cldfbAnalysis_ivas_fx( l_timeIn, ppBuf_Real, ppBuf_Imag, samplesToProcess, st->cldfbAnaEnc ); + IF( GT_16( guard_bits, norm_timeIn ) ) + { + shift = sub( guard_bits, norm_timeIn ); + scale_sig32( st->cldfbAnaEnc->cldfb_state_fx, sub( st->cldfbAnaEnc->p_filter_length, st->cldfbAnaEnc->no_channels ), shift ); + } + scale->lb_scale = sub( 16 + 5, sub( timeInq, shift ) ); enerScale.lb_scale = negate( scale->lb_scale ); enerScale.lb_scale16 = negate( scale->lb_scale ); @@ -2148,6 +2155,11 @@ void deleteCldfb_ivas_fx( free( hs->cldfb_state_fx ); } + IF( hs->FilterStates ) + { + free( hs->FilterStates ); + } + free( hs ); *h_cldfb = NULL; diff --git a/lib_com/cng_exc_fx.c b/lib_com/cng_exc_fx.c index b68ac560e..696b58640 100644 --- a/lib_com/cng_exc_fx.c +++ b/lib_com/cng_exc_fx.c @@ -28,24 +28,24 @@ void CNG_exc_fx( Word16 *seed, /* i/o: random generator seed */ Word16 exc[], /* o : current non-enhanced excitation Q_new */ Word16 exc2[], /* o : current enhanced excitation Q_new */ - Word32 *lp_ener, /* i/o: LP filtered E */ + Word32 *lp_ener, /* i/o: LP filtered E Q6 */ const Word32 last_core_brate, /* i : previous frame core bitrate */ Word16 *first_CNG, /* i/o: first CNG frame flag for energy init. */ Word16 *cng_ener_seed, /* i/o: random generator seed for CNG energy */ - Word16 bwe_exc[], /* o : excitation for SWB TBE */ + Word16 bwe_exc[], /* o : excitation for SWB TBE Q_syn */ const Word16 allow_cn_step, /* i : allow CN step */ Word16 *last_allow_cn_step, /* i/o: last allow step */ const Word16 OldQ_exc, /* i : Old excitation scaling */ const Word16 Q_exc, /* i : excitation scaling */ const Word16 num_ho, /* i : number of selected hangover frames */ - Word32 q_env[], - Word32 *lp_env, - Word32 *old_env, - Word16 *exc_mem, - Word16 *exc_mem1, + Word32 q_env[], /*Q6*/ + Word32 *lp_env, /*Q6*/ + Word32 *old_env, /*Q6*/ + Word16 *exc_mem, /*Q0*/ + Word16 *exc_mem1, /*Q0*/ Word16 *sid_bw, Word16 *cng_ener_seed1, - Word16 exc3[], + Word16 exc3[], /*Q_exc*/ Word16 Opt_AMR_WB, const int16_t element_mode /* i : IVAS Element mode */ ) @@ -93,9 +93,9 @@ void CNG_exc_fx( L_tmp_ener = Mult_32_16( L_tmp_ener, 9079 ); /* divide by PIT_MAX (in Q15 + Q6 to get output in Q6)*/ L_tmp_ener = L_shr( L_tmp_ener, Q_ener ); /* -> If we want ener in Q6 */ - if ( EQ_16( L_frame, L_FRAME16k ) ) + IF( EQ_16( L_frame, L_FRAME16k ) ) { - L_tmp_ener = Mult_32_16( L_tmp_ener, 26214 ); /* Compensate for 16kHz */ + L_tmp_ener = Mult_32_16( L_tmp_ener, 26214 /*.8f in Q15*/ ); /* Compensate for 16kHz */ } *Enew = L_tmp_ener; move32(); @@ -123,14 +123,14 @@ void CNG_exc_fx( IF( LT_16( num_ho, 3 ) || LT_32( Mult_32_16( *Enew, 21845 /*1/1.5f, Q15*/ ), *lp_ener ) ) { /**lp_ener = 0.8f * *lp_ener + 0.2f * *Enew;*/ - L_tmp_ener = Mult_32_16( *lp_ener, 26214 ); - L_tmp_ener = Madd_32_16( L_tmp_ener, *Enew, 6554 ); + L_tmp_ener = Mult_32_16( *lp_ener, 26214 /*.8f in Q15*/ ); + L_tmp_ener = Madd_32_16( L_tmp_ener, *Enew, 6554 /*.2f in Q15*/ ); } ELSE { /**lp_ener = 0.95f * *lp_ener + 0.05f * *Enew;*/ - L_tmp_ener = Mult_32_16( *lp_ener, 31130 ); - L_tmp_ener = Madd_32_16( L_tmp_ener, *Enew, 1638 ); + L_tmp_ener = Mult_32_16( *lp_ener, 31130 /*.95f in Q15*/ ); + L_tmp_ener = Madd_32_16( L_tmp_ener, *Enew, 1638 /* .05f in Q15*/ ); } } ELSE @@ -192,8 +192,8 @@ FOR( i_subfr = 0; i_subfr < L_frame; i_subfr += L_SUBFR ) * Insert random variation for excitation energy * (random variation is scaled according to *lp_ener value) *------------------------------------------------------------*/ - L_tmp = Mult_32_16( *lp_ener, Random( cng_ener_seed ) ); - L_tmp = Mult_32_16( L_tmp, GAIN_VAR ); + L_tmp = Mult_32_16( *lp_ener, Random( cng_ener_seed ) ); // Q6 + L_tmp = Mult_32_16( L_tmp, GAIN_VAR ); // Q6 #ifdef BASOP_NOGLOB L_tmp = L_add_sat( L_tmp, *lp_ener ); #else @@ -212,11 +212,11 @@ FOR( i_subfr = 0; i_subfr < L_frame; i_subfr += L_SUBFR ) exp = sub( exp, exp2 ); - if ( GT_16( tmp, tmp2 ) ) + IF( GT_16( tmp, tmp2 ) ) { exp = add( exp, 1 ); } - if ( GT_16( tmp, tmp2 ) ) + IF( GT_16( tmp, tmp2 ) ) { tmp = shr( tmp, 1 ); } @@ -233,12 +233,13 @@ FOR( i_subfr = 0; i_subfr < L_frame; i_subfr += L_SUBFR ) FOR( i = 0; i < L_SUBFR; i++ ) { /* exc2[i] *= enr */ - L_tmp = L_mult( exc2[add( i_subfr, i )], tmp ); /* Q-4 * Q_exc+19 -> Q_exc +16 */ + L_tmp = L_mult( exc2[i_subfr + i], tmp ); /* Q-4 * Q_exc+19 -> Q_exc +16 */ #ifdef BASOP_NOGLOB - exc2[add( i_subfr, i )] = round_fx_sat( L_shl_sat( L_tmp, exp ) ); + exc2[i_subfr + i] = round_fx_sat( L_shl_sat( L_tmp, exp ) ); #else exc2[i_subfr + i] = round_fx( L_shl( L_tmp, exp ) ); #endif + move16(); } } IF( NE_16( Opt_AMR_WB, 1 ) ) @@ -298,8 +299,8 @@ IF( NE_16( Opt_AMR_WB, 1 ) ) { /* 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 ); - lp_env[i] = L_add( L_tmp, Mult_32_16( old_env[i], 3277 ) ); + 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 */ } @@ -381,8 +382,8 @@ IF( NE_16( Opt_AMR_WB, 1 ) ) 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 ) ); - L_tmp = Mult_32_16( L_tmp, GAIN_VAR ); + L_tmp = Mult_32_16( denv[i], Random( cng_ener_seed1 ) ); // Q6 + L_tmp = Mult_32_16( L_tmp, GAIN_VAR ); // Q6 #ifdef BASOP_NOGLOB L_tmp = L_add_sat( L_tmp, denv[i] ); itmp[i] = L_add_sat( L_tmp, itmp[i] ); @@ -394,7 +395,8 @@ IF( NE_16( Opt_AMR_WB, 1 ) ) if ( itmp[i] < 0 ) { - itmp[i] = L_deposit_l( 0 ); + itmp[i] = 0; + move32(); } } ptR = &fft_io[1]; @@ -413,11 +415,11 @@ IF( NE_16( Opt_AMR_WB, 1 ) ) exp2 = sub( 31 - 6, exp2 ); /* in Q15 (L_tmp in Q6)*/ exp = sub( exp2, exp ); /* Denormalize and substract */ - if ( GT_16( tmp2, tmp ) ) + IF( GT_16( tmp2, tmp ) ) { exp = add( exp, 1 ); } - if ( GT_16( tmp2, tmp ) ) + IF( GT_16( tmp2, tmp ) ) { tmp2 = shr( tmp2, 1 ); } @@ -452,7 +454,8 @@ IF( NE_16( Opt_AMR_WB, 1 ) ) /* enr1 = dotp( fft_io, fft_io, L_frame ) / L_frame; */ - enr1 = L_deposit_l( 1 ); + enr1 = 1; + move32(); pt_fft_io = fft_io; IF( EQ_16( L_frame, L_FRAME ) ) { @@ -498,11 +501,11 @@ IF( NE_16( Opt_AMR_WB, 1 ) ) exp = sub( exp, exp2 ); - if ( GT_16( tmp, tmp2 ) ) + IF( GT_16( tmp, tmp2 ) ) { exp = add( exp, 1 ); } - if ( GT_16( tmp, tmp2 ) ) + IF( GT_16( tmp, tmp2 ) ) { tmp = shr( tmp, 1 ); } @@ -529,8 +532,8 @@ IF( NE_16( Opt_AMR_WB, 1 ) ) FOR( i = 0; i < L_SUBFR; i++ ) { /* fft_io[i] *= enr */ - L_tmp = L_mult( fft_io[add( i_subfr, i )], tmp ); /* Q_exc + 16 - exp */ - fft_io[add( i_subfr, i )] = round_fx( L_shl( L_tmp, exp ) ); /*Q_exc*/ + 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(); } } @@ -538,7 +541,7 @@ IF( NE_16( Opt_AMR_WB, 1 ) ) FOR( i = 0; i < L_frame; i++ ) { /* fft_io[i] = 0.75f*fft_io[i] + exc2[i];*/ - tmp = mult( fft_io[i], 24576 ); + tmp = mult( fft_io[i], 24576 /*.75f in Q15*/ ); #ifdef BASOP_NOGLOB fft_io[i] = add_sat( tmp, exc2[i] ); #else @@ -549,7 +552,8 @@ IF( NE_16( Opt_AMR_WB, 1 ) ) /* enr = (dotp( fft_io, fft_io, L_frame ) / L_frame) + 0.01f */ - L_tmp2 = L_deposit_l( 1 ); + L_tmp2 = 1; + move32(); pt_fft_io = fft_io; IF( EQ_16( L_frame, L_FRAME ) ) { @@ -598,11 +602,11 @@ IF( NE_16( Opt_AMR_WB, 1 ) ) exp2 = sub( 31 - 6, exp2 ); /* in Q15 (L_tmp in Q6)*/ exp = sub( exp2, exp ); /* Denormalize and substract */ - if ( GT_16( tmp2, tmp ) ) + IF( GT_16( tmp2, tmp ) ) { exp = add( exp, 1 ); } - if ( GT_16( tmp2, tmp ) ) + IF( GT_16( tmp2, tmp ) ) { tmp2 = shr( tmp2, 1 ); } @@ -654,7 +658,7 @@ void cng_params_postupd_fx( const Word16 *const cng_exc2_buf, /* i : Excitation buffer Q_exc */ const Word16 *const cng_Qexc_buf, /* i : Q_exc buffer Q0 */ const Word32 *const cng_brate_buf, /* i : bit rate buffer Q0 */ - Word32 ho_env_circ[] /* i/o: Envelope buffer */ + Word32 ho_env_circ[] /* i/o: Envelope buffer Q6 */ #ifdef IVAS_CODE_CNG_COM , const Word16 element_mode, /* i : Element mode */ @@ -683,7 +687,7 @@ void cng_params_postupd_fx( #endif ptr = add( sub( ho_circ_ptr, *cng_buf_cnt ), 1 ); - if ( ptr < 0 ) + IF( ptr < 0 ) { ptr = add( ptr, HO_HIST_SIZE ); } @@ -782,7 +786,7 @@ void cng_params_postupd_ivas_fx( const Word16 *const cng_exc2_buf, /* i : Excitation buffer Q_exc */ const Word16 *const cng_Qexc_buf, /* i : Q_exc buffer Q0 */ const Word32 *const cng_brate_buf, /* i : bit rate buffer Q0 */ - Word32 ho_env_circ[], /* i/o: Envelope buffer */ + Word32 ho_env_circ[], /* i/o: Envelope buffer Q6 */ const Word16 element_mode, /* i : Element mode */ const Word16 bwidth /* i : Audio bandwidth */ ) @@ -808,7 +812,7 @@ void cng_params_postupd_ivas_fx( #endif ptr = add( sub( ho_circ_ptr, *cng_buf_cnt ), 1 ); - if ( ptr < 0 ) + IF( ptr < 0 ) { ptr = add( ptr, HO_HIST_SIZE ); } @@ -922,7 +926,7 @@ void cng_params_upd_fx( Word16 ho_lsp_circ[], /* o : old LSP buffer for CNG averaging Q15 */ const Word16 Q_exc, /* i : Q value of excitation */ const Word16 enc_dec_flag, /* i : Flag indicating encoder or decoder (ENC,DEC) */ - Word32 ho_env_circ[], /* i/o: Envelope buffer */ + Word32 ho_env_circ[], /* i/o: Envelope buffer Q6 */ Word16 *cng_buf_cnt, /* i/o: Counter of postponed FFT-processing instances */ Word16 cng_exc2_buf[], /* i/o: Excitation buffer Q_exc */ Word16 cng_Qexc_buf[], /* i/o: Q_exc buffer Q0 */ @@ -979,7 +983,8 @@ void cng_params_upd_fx( scale = norm_s( maxv ); pt_exc2 = exc2; - L_ener = L_deposit_l( 0 ); + L_ener = 0; + move32(); IF( EQ_16( L_frame, L_FRAME ) ) { FOR( j = 0; j < 128; j++ ) @@ -1046,7 +1051,7 @@ void cng_params_upd_fx( cng_Qexc_buf[*ho_circ_ptr] = Q_exc; move16(); cng_brate_buf[*ho_circ_ptr] = last_active_brate; - move16(); + move32(); } ELSE { @@ -1137,7 +1142,7 @@ void cng_params_upd_ivas_fx( Word16 ho_lsp_circ[], /* o : old LSP buffer for CNG averaging Q15 */ const Word16 Q_exc, /* i : Q value of excitation */ const Word16 enc_dec_flag, /* i : Flag indicating encoder or decoder (ENC,DEC) */ - Word32 ho_env_circ[], /* i/o: Envelope buffer */ + Word32 ho_env_circ[], /* i/o: Envelope buffer Q(6+shift) */ Word16 *cng_buf_cnt, /* i/o: Counter of postponed FFT-processing instances */ Word16 cng_exc2_buf[], /* i/o: Excitation buffer Q_exc */ Word16 cng_Qexc_buf[], /* i/o: Q_exc buffer Q0 */ @@ -1192,7 +1197,8 @@ void cng_params_upd_ivas_fx( scale = norm_s( maxv ); pt_exc2 = exc2; - L_ener = L_deposit_l( 0 ); + L_ener = 0; + move32(); IF( EQ_16( L_frame, L_FRAME ) ) { FOR( j = 0; j < 128; j++ ) @@ -1259,7 +1265,7 @@ void cng_params_upd_ivas_fx( cng_Qexc_buf[*ho_circ_ptr] = Q_exc; move16(); cng_brate_buf[*ho_circ_ptr] = last_active_brate; - move16(); + move32(); } ELSE { @@ -1305,7 +1311,6 @@ void cng_params_upd_ivas_fx( att_fx = pow_10_q23[index]; // Q23 move32(); tmp = extract_h( att_fx ); // Q7 - move16(); shift = 8; move16(); } @@ -1336,7 +1341,7 @@ void cng_params_upd_ivas_fx( /* update the circular buffer of old residual envelope */ /* Copy32( env, &(ho_env_circ[add(shl(*ho_circ_ptr,4),shl(*ho_circ_ptr,2))]), NUM_ENV_CNG ); */ Copy32( env, &( ho_env_circ[( *ho_circ_ptr ) * NUM_ENV_CNG] ), NUM_ENV_CNG ); - scale_sig32( &( ho_env_circ[( *ho_circ_ptr ) * NUM_ENV_CNG] ), NUM_ENV_CNG, shift ); + scale_sig32( &( ho_env_circ[( *ho_circ_ptr ) * NUM_ENV_CNG] ), NUM_ENV_CNG, shift ); // Q(6+shift) } *ho_circ_size = add( *ho_circ_size, 1 ); move16(); diff --git a/lib_com/cnst.h b/lib_com/cnst.h index 6bcb3ea4b..2f886ed1e 100644 --- a/lib_com/cnst.h +++ b/lib_com/cnst.h @@ -1940,6 +1940,7 @@ typedef enum _DCTTYPE #define N_SMC_FEATURES 15 /* number of features */ #define N_SMC_MIXTURES 6 /* number of mixtures */ #define N_PCA_COEF 12 /* number of PCA components */ +#define HALF_N_PCA_COEF_LOG_P12_Q19 5781461//Q19 of (0.5f * N_PCA_COEF *logf( PI2 )) #define SMC_ST_MEAN_FACT 0.5 /* forgetting factor of short-term IIR mean filter */ #define SMC_ST_MEAN_RSHIFT_FACT_FX 1 /* SMC_ST_MEAN_FACT equivalent right shift factor */ diff --git a/lib_com/codec_tcx_common.c b/lib_com/codec_tcx_common.c index 9beef9275..85e353d59 100644 --- a/lib_com/codec_tcx_common.c +++ b/lib_com/codec_tcx_common.c @@ -19,7 +19,8 @@ Word16 tcxGetNoiseFillingTilt( const Word16 lpcorder, const Word16 L_frame, const Word16 mode, - Word16 *noiseTiltFactor ) + Word16 *noiseTiltFactor /*Q15*/ +) { Word16 firstLine; Word32 tmp; @@ -36,7 +37,7 @@ Word16 tcxGetNoiseFillingTilt( { firstLine = shr( L_frame, 3 ); - Copy_Scale_sig( A, As, add( lpcorder, 1 ), sub( norm_s( A[0] ), 2 ) ); + Copy_Scale_sig( A, As, add( lpcorder, 1 ), sub( norm_s( A[0] ), 2 ) ); // Q(12) tmp = get_gain( As + 1, As, lpcorder ); BASOP_SATURATE_WARNING_OFF_EVS; #ifdef BASOP_NOGLOB @@ -54,10 +55,10 @@ Word16 tcxGetNoiseFillingTilt( void tcxFormantEnhancement( - Word16 xn_buf[], - const Word16 gainlpc[], + Word16 xn_buf[], // Q(15-xn_buf_e) + const Word16 gainlpc[], // Q(15-gainlpc_e) const Word16 gainlpc_e[], - Word32 spectrum[], + Word32 spectrum[], // Q(31-spectrum_e) Word16 *spectrum_e, const Word16 L_frame, const Word16 L_frameTCX ) @@ -88,13 +89,13 @@ void tcxFormantEnhancement( e = gainlpc_e[0]; move16(); m = Sqrt16( gainlpc[0], &e ); - xn_buf[0] = shl( m, sub( e, xn_buf_e ) ); + xn_buf[0] = shl( m, sub( e, xn_buf_e ) ); // Q(15-xn_buf_e) move16(); e = gainlpc_e[1]; move16(); m = Sqrt16( gainlpc[1], &e ); - xn_buf[1] = shl( m, sub( e, xn_buf_e ) ); + xn_buf[1] = shl( m, sub( e, xn_buf_e ) ); // Q(15-xn_buf_e) move16(); fac0 = s_min( xn_buf[0], xn_buf[1] ); @@ -107,7 +108,7 @@ void tcxFormantEnhancement( e = gainlpc_e[i + 1]; move16(); m = Sqrt16( gainlpc[i + 1], &e ); - xn_buf[i + 1] = shl( m, sub( e, xn_buf_e ) ); + xn_buf[i + 1] = shl( m, sub( e, xn_buf_e ) ); // Q(15-xn_buf_e) move16(); test(); @@ -122,10 +123,10 @@ void tcxFormantEnhancement( move16(); tmp = sub( e, fac_e ); - if ( tmp > 0 ) - fac0 = shr( fac0, tmp ); - if ( tmp < 0 ) - fac1 = shl( fac1, tmp ); + IF( tmp > 0 ) + fac0 = shr( fac0, tmp ); + IF( tmp < 0 ) + fac1 = shl( fac1, tmp ); if ( tmp > 0 ) { @@ -144,7 +145,7 @@ void tcxFormantEnhancement( fac = add( fac0, mult( d, extract_l( L_mult0( j, inv_int[n] ) ) ) ); BASOP_SATURATE_WARNING_OFF_EVS; #ifdef BASOP_NOGLOB - xn_buf[add( l, j )] = s_min( xn_one, shl_o( mult( xn_buf[add( l, j )], fac ), fac_e, &Overflow ) ); + xn_buf[l + j] = s_min( xn_one, shl_o( mult( xn_buf[l + j], fac ), fac_e, &Overflow ) ); #else xn_buf[l + j] = s_min( xn_one, shl( mult( xn_buf[l + j], fac ), fac_e ) ); #endif @@ -171,10 +172,10 @@ void tcxFormantEnhancement( move16(); tmp = sub( e, fac_e ); - if ( tmp > 0 ) - fac0 = shr( fac0, tmp ); - if ( tmp < 0 ) - fac1 = shl( fac1, tmp ); + IF( tmp > 0 ) + fac0 = shr( fac0, tmp ); + IF( tmp < 0 ) + fac1 = shl( fac1, tmp ); if ( tmp > 0 ) { @@ -193,7 +194,7 @@ void tcxFormantEnhancement( fac = add( fac0, mult( d, extract_l( L_mult0( j, inv_int[n] ) ) ) ); BASOP_SATURATE_WARNING_OFF_EVS; #ifdef BASOP_NOGLOB - xn_buf[add( l, j )] = s_min( xn_one, shl_sat( mult( xn_buf[add( l, j )], fac ), fac_e ) ); + xn_buf[l + j] = s_min( xn_one, shl_sat( mult( xn_buf[l + j], fac ), fac_e ) ); #else xn_buf[l + j] = s_min( xn_one, shl( mult( xn_buf[l + j], fac ), fac_e ) ); #endif @@ -209,7 +210,7 @@ void tcxFormantEnhancement( { FOR( l = 0; l < k; l++ ) { - *spectrum = Mpy_32_16_1( *spectrum, *xn_buf ); + *spectrum = Mpy_32_16_1( *spectrum, *xn_buf ); // Q(15-xn_buf_e)+Q(31-spectrum_e)+1 -16 move32(); spectrum++; } @@ -219,7 +220,7 @@ void tcxFormantEnhancement( tmp = sub( L_frameTCX, L_frame ); FOR( i = 0; i < tmp; i++ ) { - spectrum[i] = L_shr( spectrum[i], xn_buf_e ); + spectrum[i] = L_shr( spectrum[i], xn_buf_e ); // Q(31-(specturm_e+xn_buf_e)) move32(); } *spectrum_e = add( *spectrum_e, xn_buf_e ); @@ -227,11 +228,11 @@ void tcxFormantEnhancement( } void tcxFormantEnhancement_with_shift( - Word16 xn_buf[], + Word16 xn_buf[], // Q(15-xn_buf_e_out) Word16 *xn_buf_e_out, - const Word16 gainlpc[], + const Word16 gainlpc[], // Q(15-gainlpc_e) const Word16 gainlpc_e[], - Word32 spectrum[], + Word32 spectrum[], // Q(31-spectrum_e) Word16 *spectrum_e, const Word16 L_frame, const Word16 L_frameTCX ) @@ -262,13 +263,13 @@ void tcxFormantEnhancement_with_shift( e = gainlpc_e[0]; move16(); m = Sqrt16( gainlpc[0], &e ); - xn_buf[0] = shl( m, sub( e, xn_buf_e ) ); + xn_buf[0] = shl( m, sub( e, xn_buf_e ) ); // Q(15-xn_buf_e) move16(); e = gainlpc_e[1]; move16(); m = Sqrt16( gainlpc[1], &e ); - xn_buf[1] = shl( m, sub( e, xn_buf_e ) ); + xn_buf[1] = shl( m, sub( e, xn_buf_e ) ); // Q(15-xn_buf_e) move16(); fac0 = s_min( xn_buf[0], xn_buf[1] ); @@ -281,7 +282,7 @@ void tcxFormantEnhancement_with_shift( e = gainlpc_e[i + 1]; move16(); m = Sqrt16( gainlpc[i + 1], &e ); - xn_buf[i + 1] = shl( m, sub( e, xn_buf_e ) ); + xn_buf[i + 1] = shl( m, sub( e, xn_buf_e ) ); // Q(15-xn_buf_e) move16(); test(); @@ -322,7 +323,7 @@ void tcxFormantEnhancement_with_shift( fac = add( fac0, mult( d, extract_l( L_mult0( j, inv_int[n] ) ) ) ); BASOP_SATURATE_WARNING_OFF_EVS; #ifdef BASOP_NOGLOB - xn_buf[add( l, j )] = s_min( xn_one, shl_o( mult( xn_buf[add( l, j )], fac ), fac_e, &Overflow ) ); + xn_buf[l + j] = s_min( xn_one, shl_o( mult( xn_buf[l + j], fac ), fac_e, &Overflow ) ); #else xn_buf[l + j] = s_min( xn_one, shl( mult( xn_buf[l + j], fac ), fac_e ) ); #endif @@ -349,10 +350,10 @@ void tcxFormantEnhancement_with_shift( move16(); tmp = sub( e, fac_e ); - if ( tmp > 0 ) - fac0 = shr( fac0, tmp ); - if ( tmp < 0 ) - fac1 = shl( fac1, tmp ); + IF( tmp > 0 ) + fac0 = shr( fac0, tmp ); + IF( tmp < 0 ) + fac1 = shl( fac1, tmp ); if ( tmp > 0 ) { @@ -371,7 +372,7 @@ void tcxFormantEnhancement_with_shift( fac = add( fac0, mult( d, extract_l( L_mult0( j, inv_int[n] ) ) ) ); BASOP_SATURATE_WARNING_OFF_EVS; #ifdef BASOP_NOGLOB - xn_buf[add( l, j )] = s_min( xn_one, shl_o( mult( xn_buf[add( l, j )], fac ), fac_e, &Overflow ) ); + xn_buf[l + j] = s_min( xn_one, shl_o( mult( xn_buf[l + j], fac ), fac_e, &Overflow ) ); #else xn_buf[l + j] = s_min( xn_one, shl( mult( xn_buf[l + j], fac ), fac_e ) ); #endif @@ -387,7 +388,7 @@ void tcxFormantEnhancement_with_shift( { FOR( l = 0; l < k; l++ ) { - *spectrum = Mpy_32_16_1( *spectrum, *xn_buf ); + *spectrum = Mpy_32_16_1( *spectrum, *xn_buf ); // Q(15-xn_buf_e)+Q(31-spectrum_e)+1 -16 move32(); spectrum++; } @@ -397,7 +398,7 @@ void tcxFormantEnhancement_with_shift( tmp = sub( L_frameTCX, L_frame ); FOR( i = 0; i < tmp; i++ ) { - spectrum[i] = L_shr( spectrum[i], xn_buf_e ); + spectrum[i] = L_shr( spectrum[i], xn_buf_e ); // Q(31-(specturm_e+xn_buf_e)) move32(); } *spectrum_e = add( *spectrum_e, xn_buf_e ); @@ -409,8 +410,8 @@ void tcxFormantEnhancement_with_shift( void tcxInvertWindowGrouping( TCX_CONFIG_HANDLE hTcxCfg, /* i : configuration of TCX */ - Word32 xn_buf[], - Word32 spectrum[], + Word32 xn_buf[], // Qx + Word32 spectrum[], // Qx const Word16 L_frame, const Word8 fUseTns, const Word16 last_core, @@ -461,7 +462,7 @@ void tcxInvertWindowGrouping( } p = spectrum + sub( L_frame, 1 ); - FOR( i = sub( L_frame, 1 ); i > L_win; i -= 2 ) + FOR( i = L_frame - 1; i > L_win; i -= 2 ) { *p-- = spectrum[i]; move32(); @@ -632,7 +633,8 @@ void tcx5TnsUngrouping( void tcx5SpectrumInterleaving_fx( const Word16 tcx5Size, - Word32 *spectrum ) + Word32 *spectrum // Qx +) { Word16 i; Word32 interleaveBuf[N_TCX10_MAX]; @@ -643,7 +645,9 @@ void tcx5SpectrumInterleaving_fx( FOR( i = 0; i < tcx5Size; i++ ) { interleaveBuf[2 * i] = spectrum[i]; - interleaveBuf[add( 2 * i, 1 )] = spectrum[add( tcx5Size, i )]; + interleaveBuf[2 * i + 1] = spectrum[tcx5Size + i]; + move32(); + move32(); } Copy32( interleaveBuf, spectrum, shl( tcx5Size, 1 ) ); @@ -659,7 +663,8 @@ void tcx5SpectrumInterleaving_fx( void tcx5SpectrumDeinterleaving_fx( const Word16 tcx5Size, - Word32 *spectrum ) + Word32 *spectrum // Qx +) { Word16 i; Word32 interleaveBuf[N_TCX10_MAX]; @@ -670,7 +675,9 @@ void tcx5SpectrumDeinterleaving_fx( FOR( i = 0; i < tcx5Size; i++ ) { interleaveBuf[i] = spectrum[2 * i]; - interleaveBuf[add( tcx5Size, i )] = spectrum[add( 2 * i, 1 )]; + interleaveBuf[tcx5Size + i] = spectrum[2 * i + 1]; + move32(); + move32(); } Copy32( interleaveBuf, spectrum, shl( tcx5Size, 1 ) ); @@ -687,7 +694,8 @@ void tcx5SpectrumDeinterleaving_fx( void tcx5TnsGrouping_fx( const Word16 L_frame, /* i : frame length (TCX5) */ const Word16 L_spec, /* i : coded spec length (TCX5, derived from filter borders*/ - Word32 *spectrum ) + Word32 *spectrum /*Qx*/ +) { /* rearrange LF sub-window lines prior to TNS synthesis filtering */ IF( LT_16( L_spec, L_frame ) ) @@ -716,8 +724,8 @@ void tcx5TnsGrouping_fx( void tcx5TnsUngrouping_fx( const Word16 L_frame, /* i : frame length (TCX5) */ const Word16 L_spec, /* i : coded spec length (TCX5, derived from filter borders*/ - Word32 *spectrum, - const Word16 enc_dec /* i : 0: encoder, else decoder */ + Word32 *spectrum, /*Qx*/ + const Word16 enc_dec /* i : 0: encoder, else decoder */ ) { /* undo rearrangement of LF sub-window lines prior to TNS analysis */ diff --git a/lib_com/common_api_types.h b/lib_com/common_api_types.h index ed75c249b..9a6e2ceed 100644 --- a/lib_com/common_api_types.h +++ b/lib_com/common_api_types.h @@ -195,8 +195,8 @@ typedef struct _IVAS_LS_CUSTOM_LAYOUT float azimuth[IVAS_MAX_OUTPUT_CHANNELS]; float elevation[IVAS_MAX_OUTPUT_CHANNELS]; #ifdef IVAS_FLOAT_FIXED - Word32 azimuth_fx[IVAS_MAX_OUTPUT_CHANNELS]; - Word32 elevation_fx[IVAS_MAX_OUTPUT_CHANNELS]; + Word32 azimuth_fx[IVAS_MAX_OUTPUT_CHANNELS]; // Q22 + Word32 elevation_fx[IVAS_MAX_OUTPUT_CHANNELS]; // Q22 #endif int16_t num_lfe; int16_t lfe_idx[IVAS_MAX_OUTPUT_CHANNELS]; @@ -235,9 +235,9 @@ typedef struct _IVAS_ROOM_ACOUSTICS_CONFIG float acousticPreDelay; /* Time elapsed between input signal and late reverberation start, float, range [0.001..10] */ float inputPreDelay; /* Offset in seconds from where DSR is computed in the RIR (0 = at source), float, range [0.001..10] */ #ifdef IVAS_FLOAT_FIXED - Word32 pFc_input_fx[IVAS_CLDFB_NO_CHANNELS_MAX]; /* Center frequencies for which following values are provided: */ - Word32 pAcoustic_rt60_fx[IVAS_CLDFB_NO_CHANNELS_MAX]; /* - The room's T60 per center frequency */ - Word32 pAcoustic_dsr_fx[IVAS_CLDFB_NO_CHANNELS_MAX]; /* - The room's Diffuse to Source Ratio per center frequency */ + Word32 pFc_input_fx[IVAS_CLDFB_NO_CHANNELS_MAX]; /*Q16 Center frequencies for which following values are provided: */ + Word32 pAcoustic_rt60_fx[IVAS_CLDFB_NO_CHANNELS_MAX]; /*Q26 - The room's T60 per center frequency */ + Word32 pAcoustic_dsr_fx[IVAS_CLDFB_NO_CHANNELS_MAX]; /*Q30 - The room's Diffuse to Source Ratio per center frequency */ Word32 acousticPreDelay_fx; /* Time elapsed between input signal and late reverberation start, float, range [0.001..10] */ /*Assumed Q-27*/ Word32 inputPreDelay_fx; /* Offset in seconds from where DSR is computed in the RIR (0 = at source), float, range [0.001..10] */ /* Assumed Q-27*/ #endif // IVAS_FLOAT_FIXED diff --git a/lib_com/fd_cng_com_fx.c b/lib_com/fd_cng_com_fx.c index 69228a482..ac1fa1a2b 100644 --- a/lib_com/fd_cng_com_fx.c +++ b/lib_com/fd_cng_com_fx.c @@ -279,7 +279,7 @@ void initFdCngCom( HANDLE_FD_CNG_COM hFdCngCom, Word16 scale ) * * Delete an instance of type FD_CNG_COM *-------------------------------------------------------------------*/ -void deleteFdCngCom( HANDLE_FD_CNG_COM *hFdCngCom ) /* i/o: Contains the variables related to the CLDFB-based CNG process */ +void deleteFdCngCom_fx( HANDLE_FD_CNG_COM *hFdCngCom ) /* i/o: Contains the variables related to the CLDFB-based CNG process */ { HANDLE_FD_CNG_COM hsCom; hsCom = *hFdCngCom; diff --git a/lib_com/igf_base_fx.c b/lib_com/igf_base_fx.c index 5b2f81f93..a7ebb203f 100644 --- a/lib_com/igf_base_fx.c +++ b/lib_com/igf_base_fx.c @@ -1432,19 +1432,19 @@ Word16 IGFCommonFuncsIGFConfiguration_ivas_fx( /**********************************************************************/ /* selects cumulative frequency tables and offsets for the IGF SCF arithmetic coder **************************************************************************/ -Word16 IGFCommonFuncsIGFGetCFTables( +Word16 IGFCommonFuncsIGFGetCFTables_fx( const Word32 total_brate, /* i : bitrate in bs e.g. 9600 for 9.6kbs */ const Word16 bwidth, /* i : audio bandwidth */ const Word16 element_mode, /* i : element mode */ const Word16 rf_mode, /* i : flag to signal the RF mode */ - const uint16_t **cf_se00, /* o : CF table for t == 0 and f == 0 */ - const uint16_t **cf_se01, /* o : CF table for t == 0 and f == 1 */ + const UWord16 **cf_se00, /* o : CF table for t == 0 and f == 0 */ + const UWord16 **cf_se01, /* o : CF table for t == 0 and f == 1 */ Word16 *cf_off_se01, /* o : offset for CF table above */ - const uint16_t **cf_se02, /* o : CF tables for t == 0 and f >= 2 */ + const UWord16 **cf_se02, /* o : CF tables for t == 0 and f >= 2 */ const Word16 **cf_off_se02, /* o : offsets for CF tables above */ - const uint16_t **cf_se10, /* o : CF table for t == 1 and f == 0 */ + const UWord16 **cf_se10, /* o : CF table for t == 1 and f == 0 */ Word16 *cf_off_se10, /* o : offset for CF table above */ - const uint16_t **cf_se11, /* o : CF tables for t == 1 and f >= 1 */ + const UWord16 **cf_se11, /* o : CF tables for t == 1 and f >= 1 */ const Word16 **cf_off_se11 /* o : offsets for CF tables above */ ) { @@ -1523,15 +1523,6 @@ Word16 IGFCommonFuncsIGFGetCFTables( *cf_off_se10 = cf_off_se10_tab; *cf_se11 = &cf_se11_tab[0][0][0]; *cf_off_se11 = &cf_off_se11_tab[0][0]; - move16(); - move16(); - move16(); - move16(); - move16(); - move16(); - move16(); - move16(); - move16(); BREAK; case IGF_BITRATE_FB_16400: @@ -1547,15 +1538,6 @@ Word16 IGFCommonFuncsIGFGetCFTables( *cf_off_se10 = cf_off_se10_tab; *cf_se11 = &cf_se11_tab[0][0][0]; *cf_off_se11 = &cf_off_se11_tab[0][0]; - move16(); - move16(); - move16(); - move16(); - move16(); - move16(); - move16(); - move16(); - move16(); BREAK; case IGF_BITRATE_FB_48000: case IGF_BITRATE_FB_64000: @@ -1569,15 +1551,6 @@ Word16 IGFCommonFuncsIGFGetCFTables( *cf_off_se10 = cf_off_se10_tab; *cf_se11 = &cf_se11_tab[0][0][0]; *cf_off_se11 = &cf_off_se11_tab[0][0]; - move16(); - move16(); - move16(); - move16(); - move16(); - move16(); - move16(); - move16(); - move16(); BREAK; case IGF_BITRATE_FB_96000: case IGF_BITRATE_FB_128000: @@ -1594,15 +1567,6 @@ Word16 IGFCommonFuncsIGFGetCFTables( *cf_off_se10 = cf_off_se10_tab; *cf_se11 = &cf_se11_tab[0][0][0]; *cf_off_se11 = &cf_off_se11_tab[0][0]; - move16(); - move16(); - move16(); - move16(); - move16(); - move16(); - move16(); - move16(); - move16(); BREAK; case IGF_BITRATE_SWB_48000_CPE: bitRateIndex = IGF_BITRATE_SWB_16400; @@ -1615,15 +1579,6 @@ Word16 IGFCommonFuncsIGFGetCFTables( *cf_off_se10 = cf_off_se10_tab; *cf_se11 = &cf_se11_tab[0][0][0]; *cf_off_se11 = &cf_off_se11_tab[0][0]; - move16(); - move16(); - move16(); - move16(); - move16(); - move16(); - move16(); - move16(); - move16(); BREAK; case IGF_BITRATE_SWB_64000_CPE: case IGF_BITRATE_SWB_80000_CPE: @@ -1638,15 +1593,6 @@ Word16 IGFCommonFuncsIGFGetCFTables( *cf_off_se10 = cf_off_se10_tab; *cf_se11 = &cf_se11_tab[0][0][0]; *cf_off_se11 = &cf_off_se11_tab[0][0]; - move16(); - move16(); - move16(); - move16(); - move16(); - move16(); - move16(); - move16(); - move16(); BREAK; case IGF_BITRATE_UNKNOWN: default: diff --git a/lib_com/ivas_dirac_com.c b/lib_com/ivas_dirac_com.c index 8bc0f6749..214910cd3 100644 --- a/lib_com/ivas_dirac_com.c +++ b/lib_com/ivas_dirac_com.c @@ -80,7 +80,7 @@ Word16 ivas_get_hodirac_flag_fx( return 0; } } -#endif +#else int16_t ivas_get_hodirac_flag( const int32_t ivas_total_brate, /* i : IVAS total bitrate */ @@ -96,7 +96,7 @@ int16_t ivas_get_hodirac_flag( return 0; } } - +#endif /*------------------------------------------------------------------------- * ivas_dirac_sba_config() * @@ -852,7 +852,7 @@ ivas_error ivas_dirac_sba_config_fx( move32(); move16(); - hodirac_flag = ivas_get_hodirac_flag_fx( sba_total_brate, sba_order ); // implemented on 100861_dirac_dec + hodirac_flag = ivas_get_hodirac_flag_fx( sba_total_brate, sba_order ); /* map the bitrate for SID frame */ IF( EQ_32( sba_total_brate, IVAS_SID_5k2 ) ) @@ -883,13 +883,13 @@ ivas_error ivas_dirac_sba_config_fx( } nbands_coded = nbands; + move16(); IF( LE_32( sba_total_brate, res ) ) { hQMetaData->useLowerBandRes = 1; - Word16 tmp = nbands % 2; + Word16 tmp = s_and( nbands, 1 ); - move16(); move16(); nbands_coded = add( shr( nbands, 1 ), tmp ); } diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index bf819845c..a22e45e87 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -118,11 +118,6 @@ ivas_error create_mct_enc( Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ ); -ivas_error mct_enc_reconfigure( - Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ - const uint16_t b_nchan_change /* i : flag indicating different channel count */ -); - ivas_error ivas_sba_enc_reconfigure( Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ ); @@ -367,10 +362,6 @@ ivas_error ivas_init_encoder( Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ ); -void destroy_core_enc( - ENC_CORE_HANDLE hCoreCoder /* i/o: core encoder structure */ -); - void ivas_destroy_enc( Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ ); @@ -3793,11 +3784,13 @@ void ivas_sba_dirac_stereo_config( STEREO_DFT_CONFIG_DATA_HANDLE hConfig /* o : DFT stereo configuration */ ); +#ifndef IVAS_FLOAT_FIXED /*! r: HO-DirAC flag */ int16_t ivas_get_hodirac_flag( const int32_t ivas_total_brate, /* i : IVAS total bitrate */ const int16_t sba_order /* i : Ambisonic (SBA) order */ ); +#endif Word16 ivas_get_sba_dirac_stereo_flag( Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ @@ -4362,13 +4355,6 @@ ivas_error ivas_spar_enc_open( const int16_t spar_reconfig_flag /* i : SPAR reconfiguration flag */ ); -void ivas_spar_enc_close( - SPAR_ENC_HANDLE *hSpar, /* i/o: SPAR encoder handle */ - const int32_t input_Fs, /* i : input sampling rate */ - const int16_t nchan_inp, /* i : number of input channels */ - const int16_t spar_reconfig_flag /* i : SPAR reconfiguration flag */ -); - ivas_error ivas_spar_enc( Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ float *data_f[], /* i/o: input/transport audio channels */ diff --git a/lib_com/ivas_prot_fx.h b/lib_com/ivas_prot_fx.h index eff881370..59be73bfb 100644 --- a/lib_com/ivas_prot_fx.h +++ b/lib_com/ivas_prot_fx.h @@ -775,6 +775,10 @@ void destroy_sce_dec( SCE_DEC_HANDLE hSCE /* i/o: SCE decoder structure */ ); +void destroy_core_enc_fx( + ENC_CORE_HANDLE hCoreCoder /* i/o: core encoder structure */ +); + ivas_error ivas_sce_dec_fx( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ const Word16 sce_id, /* i : SCE # identifier */ @@ -3346,6 +3350,12 @@ void ivas_mct_core_enc_fx( const Word16 sba_order /* i : Ambisonic (SBA) order */ ); + +ivas_error mct_enc_reconfigure_fx( + Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ + const UWord16 b_nchan_change /* i : flag indicating different channel count */ +); + Word16 quantize_phi_chan_compand_fx( Word32 phi, /* i : azimuth value Q22 */ Word32 *phi_hat, /* o : quantized azimuth Q22 */ @@ -5205,6 +5215,13 @@ ivas_error ivas_spar_enc_open_fx( const Word16 spar_reconfig_flag /* i : SPAR reconfiguration flag */ ); +void ivas_spar_enc_close_fx( + SPAR_ENC_HANDLE *hSpar, /* i/o: SPAR encoder handle */ + const Word32 input_Fs, /* i : input sampling rate */ + const Word16 nchan_inp, /* i : number of input channels */ + const Word16 spar_reconfig_flag /* i : SPAR reconfiguration flag */ +); + void ivas_spar_dec_close_fx( SPAR_DEC_HANDLE *hSpar, /* i/o: SPAR decoder handle */ const Word32 output_Fs, /* i : output sampling rate */ diff --git a/lib_com/prot.h b/lib_com/prot.h index 7564cdc48..444817758 100644 --- a/lib_com/prot.h +++ b/lib_com/prot.h @@ -2286,9 +2286,6 @@ void LPDmem_enc_init( LPD_state_HANDLE hLPDmem /* i/o: LP memories */ ); -void destroy_cldfb_encoder( - Encoder_State *st /* i/o: state structure */ -); ivas_error evs_enc( Encoder_State *st, /* i/o: state structure */ const int16_t *data, /* i : input signal */ diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index 089a92b53..ea3dd0530 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -5027,7 +5027,7 @@ ivas_error createFdCngCom( HANDLE_FD_CNG_COM *hFdCngCom ); void initFdCngCom( HANDLE_FD_CNG_COM hFdCngCom, Word16 scale ); /* Delete the instance of type FD_CNG */ -void deleteFdCngCom( HANDLE_FD_CNG_COM *hFdCngCom ); +void deleteFdCngCom_fx( HANDLE_FD_CNG_COM *hFdCngCom ); /* Initialize the spectral partitioning */ void initPartitions( @@ -5734,19 +5734,19 @@ Word16 IGFCommonFuncsIGFConfiguration_ivas_fx( const Word16 rf_mode /* i : flag to signal the RF mode */ ); -Word16 IGFCommonFuncsIGFGetCFTables( +Word16 IGFCommonFuncsIGFGetCFTables_fx( const Word32 total_brate, /* i : bitrate in bs e.g. 9600 for 9.6kbs */ const Word16 bwidth, /* i : audio bandwidth */ const Word16 element_mode, /* i : element mode */ const Word16 rf_mode, /* i : flag to signal the RF mode */ - const uint16_t **cf_se00, /* o : CF table for t == 0 and f == 0 */ - const uint16_t **cf_se01, /* o : CF table for t == 0 and f == 1 */ + const UWord16 **cf_se00, /* o : CF table for t == 0 and f == 0 */ + const UWord16 **cf_se01, /* o : CF table for t == 0 and f == 1 */ Word16 *cf_off_se01, /* o : offset for CF table above */ - const uint16_t **cf_se02, /* o : CF tables for t == 0 and f >= 2 */ + const UWord16 **cf_se02, /* o : CF tables for t == 0 and f >= 2 */ const Word16 **cf_off_se02, /* o : offsets for CF tables above */ - const uint16_t **cf_se10, /* o : CF table for t == 1 and f == 0 */ + const UWord16 **cf_se10, /* o : CF table for t == 1 and f == 0 */ Word16 *cf_off_se10, /* o : offset for CF table above */ - const uint16_t **cf_se11, /* o : CF tables for t == 1 and f >= 1 */ + const UWord16 **cf_se11, /* o : CF tables for t == 1 and f >= 1 */ const Word16 **cf_off_se11 /* o : offsets for CF tables above */ ); // ari_fx.c @@ -7565,6 +7565,10 @@ void destroy_cldfb_decoder_fx( Decoder_State *st_fx /* o: Decoder static variables structure */ ); +void destroy_cldfb_encoder_fx( + Encoder_State *st /* i/o: state structure */ +); + // swb_bwe_dec_fx.c Word16 WB_BWE_gain_deq_fx( Decoder_State *st_fx, /* i/o: decoder state structure */ diff --git a/lib_dec/fd_cng_dec_fx.c b/lib_dec/fd_cng_dec_fx.c index cce8ed419..9645e3bbe 100644 --- a/lib_dec/fd_cng_dec_fx.c +++ b/lib_dec/fd_cng_dec_fx.c @@ -549,7 +549,7 @@ void deleteFdCngDec_fx( HANDLE_FD_CNG_DEC *hFdCngDec ) IF( hsDec != NULL ) { - deleteFdCngCom( &( hsDec->hFdCngCom ) ); + deleteFdCngCom_fx( &( hsDec->hFdCngCom ) ); free( hsDec ); *hFdCngDec = NULL; } diff --git a/lib_dec/igf_scf_dec_fx.c b/lib_dec/igf_scf_dec_fx.c index fe670df56..73af50879 100644 --- a/lib_dec/igf_scf_dec_fx.c +++ b/lib_dec/igf_scf_dec_fx.c @@ -36,7 +36,7 @@ void IGFSCFDecoderOpen( hPublicData->t = 0; move16(); /* protect against the invalid request of starting decoding with a dependent block */ - IGFCommonFuncsIGFGetCFTables( total_brate, bwidth, element_mode, rf_mode, &hPublicData->cf_se00, &hPublicData->cf_se01, &hPublicData->cf_off_se01, &hPublicData->cf_se02, &hPublicData->cf_off_se02, &hPublicData->cf_se10, &hPublicData->cf_off_se10, &hPublicData->cf_se11, &hPublicData->cf_off_se11 ); + IGFCommonFuncsIGFGetCFTables_fx( total_brate, bwidth, element_mode, rf_mode, &hPublicData->cf_se00, &hPublicData->cf_se01, &hPublicData->cf_off_se01, &hPublicData->cf_se02, &hPublicData->cf_off_se02, &hPublicData->cf_se10, &hPublicData->cf_off_se10, &hPublicData->cf_se11, &hPublicData->cf_off_se11 ); } diff --git a/lib_dec/ivas_sba_dec.c b/lib_dec/ivas_sba_dec.c index 71c6eeb9e..2b91f3811 100644 --- a/lib_dec/ivas_sba_dec.c +++ b/lib_dec/ivas_sba_dec.c @@ -1033,7 +1033,7 @@ ivas_error ivas_sba_dec_reconfigure_fx( ivas_mono_dmx_renderer_close( &st_ivas->hMonoDmxRenderer ); } - if ( NE_32( ( error = ivas_dirac_sba_config_fx( st_ivas->hQMetaData, &st_ivas->element_mode_init, ivas_total_brate, st_ivas->sba_analysis_order, ivas_get_hodirac_flag( ivas_total_brate, st_ivas->sba_analysis_order ) ? IVAS_MAX_NUM_BANDS : ( IVAS_MAX_NUM_BANDS - SPAR_DIRAC_SPLIT_START_BAND ), + if ( NE_32( ( error = ivas_dirac_sba_config_fx( st_ivas->hQMetaData, &st_ivas->element_mode_init, ivas_total_brate, st_ivas->sba_analysis_order, ivas_get_hodirac_flag_fx( ivas_total_brate, st_ivas->sba_analysis_order ) ? IVAS_MAX_NUM_BANDS : ( IVAS_MAX_NUM_BANDS - SPAR_DIRAC_SPLIT_START_BAND ), st_ivas->ivas_format ) ), IVAS_ERR_OK ) ) { diff --git a/lib_enc/cod_tcx_fx.c b/lib_enc/cod_tcx_fx.c index e2b193791..04d572606 100644 --- a/lib_enc/cod_tcx_fx.c +++ b/lib_enc/cod_tcx_fx.c @@ -1658,15 +1658,14 @@ void QuantizeSpectrum_ivas_fx( QuantizeTCXSpectrum_fx( st, frame_cnt, hTcxEnc->spectrum_fx[frame_cnt], hTcxEnc->spectrum_e[frame_cnt], gainlpc_fx, gainlpc_e, Aqind, tnsSize, nb_bits, vad_hover_flag, &L_frameTCX, &L_frame, &L_spec, &tcx_offset, &noiseFillingBorder, quantized_spectrum_fx, &quantized_spectrum_e, hm_cfg, &hm_active, lf_deemph_fact_fx, &nf_seed, &ener_fx, &ener_e, &gain_tcx_fx, &gain_tcx_e, prm ); - Word16 s = sub( getScaleFactor32( st->hTcxEnc->spectrum_fx[frame_cnt], L_frame ), 6 ); - scale_sig32( st->hTcxEnc->spectrum_fx[frame_cnt], L_frame, s ); - st->hTcxEnc->spectrum_e[frame_cnt] = sub( st->hTcxEnc->spectrum_e[frame_cnt], s ); - move16(); + Word16 s1 = sub( getScaleFactor32( st->hTcxEnc->spectrum_fx[frame_cnt], L_frame ), 6 ); + Word16 s2 = getScaleFactor32( quantized_spectrum_fx, s_max( L_frame, L_spec ) ); + Word16 max_e = s_max( sub( hTcxEnc->spectrum_e[frame_cnt], s1 ), sub( quantized_spectrum_e, s2 ) ); - IF( NE_16( quantized_spectrum_e, hTcxEnc->spectrum_e[frame_cnt] ) ) - { - scale_sig32( quantized_spectrum_fx, s_max( L_frame, L_spec ), sub( quantized_spectrum_e, hTcxEnc->spectrum_e[frame_cnt] ) ); - } + scale_sig32( quantized_spectrum_fx, s_max( L_frame, L_spec ), sub( quantized_spectrum_e, max_e ) ); // max_e + scale_sig32( st->hTcxEnc->spectrum_fx[frame_cnt], L_frame, sub( hTcxEnc->spectrum_e[frame_cnt], max_e ) ); // max_e + hTcxEnc->spectrum_e[frame_cnt] = max_e; + move16(); /*-----------------------------------------------------------* * Estimate and quantize noise factor * diff --git a/lib_enc/fd_cng_enc.c b/lib_enc/fd_cng_enc.c index d78459371..481d7fdf1 100644 --- a/lib_enc/fd_cng_enc.c +++ b/lib_enc/fd_cng_enc.c @@ -314,7 +314,7 @@ void deleteFdCngEnc( IF( hsEnc != NULL ) { - deleteFdCngCom_flt( &( hsEnc->hFdCngCom ) ); + deleteFdCngCom_fx( &( hsEnc->hFdCngCom ) ); free( hsEnc ); *hFdCngEnc = NULL; } diff --git a/lib_enc/fd_cng_enc_fx.c b/lib_enc/fd_cng_enc_fx.c index e439e5f22..1c5a0a177 100644 --- a/lib_enc/fd_cng_enc_fx.c +++ b/lib_enc/fd_cng_enc_fx.c @@ -412,7 +412,7 @@ void deleteFdCngEnc_fx( HANDLE_FD_CNG_ENC *hFdCngEnc ) move16(); IF( hsEnc != NULL ) { - deleteFdCngCom( &( hsEnc->hFdCngCom ) ); + deleteFdCngCom_fx( &( hsEnc->hFdCngCom ) ); free( hsEnc ); *hFdCngEnc = NULL; move16(); diff --git a/lib_enc/igf_scf_enc_fx.c b/lib_enc/igf_scf_enc_fx.c index 28d228e63..b8125cbd6 100644 --- a/lib_enc/igf_scf_enc_fx.c +++ b/lib_enc/igf_scf_enc_fx.c @@ -19,10 +19,10 @@ initialization of an instance of this module void IGFSCFEncoderOpen_fx( IGFSCFENC_INSTANCE_HANDLE hPublicData, /* i/o: handle to public data */ H_IGF_INFO hIgfInfo, /* i : IGF info handle */ - const int32_t total_brate, /* i : total bitrate */ - const int16_t bwidth, /* i : audio bandwidth */ - const int16_t element_mode, /* i : IVAS element mode */ - const int16_t rf_mode /* i : flag to signal the RF mode */ + const Word32 total_brate, /* i : total bitrate */ + const Word16 bwidth, /* i : audio bandwidth */ + const Word16 element_mode, /* i : IVAS element mode */ + const Word16 rf_mode /* i : flag to signal the RF mode */ ) { @@ -44,17 +44,14 @@ void IGFSCFEncoderOpen_fx( set16_fx( hPublicData->prev, 0, 64 ); set16_fx( hPublicData->prevSave, 0, 64 ); - hPublicData->scfCountLongBlock[0] = hIgfInfo->grid[0].swb_offset_len - 1; - hPublicData->scfCountLongBlock[1] = hIgfInfo->grid[1].swb_offset_len - 1; - hPublicData->scfCountLongBlock[2] = hIgfInfo->grid[2].swb_offset_len - 1; - move16(); - move16(); - move16(); + hPublicData->scfCountLongBlock[0] = sub( hIgfInfo->grid[0].swb_offset_len, 1 ); + hPublicData->scfCountLongBlock[1] = sub( hIgfInfo->grid[1].swb_offset_len, 1 ); + hPublicData->scfCountLongBlock[2] = sub( hIgfInfo->grid[2].swb_offset_len, 1 ); hPublicData->t = 0; move16(); /* protect against the invalid request of starting encoding with a dependent block */ - IGFCommonFuncsIGFGetCFTables( total_brate, bwidth, element_mode, rf_mode, &hPublicData->cf_se00, &hPublicData->cf_se01, &hPublicData->cf_off_se01, &hPublicData->cf_se02, &hPublicData->cf_off_se02, &hPublicData->cf_se10, &hPublicData->cf_off_se10, &hPublicData->cf_se11, &hPublicData->cf_off_se11 ); + IGFCommonFuncsIGFGetCFTables_fx( total_brate, bwidth, element_mode, rf_mode, &hPublicData->cf_se00, &hPublicData->cf_se01, &hPublicData->cf_off_se01, &hPublicData->cf_se02, &hPublicData->cf_off_se02, &hPublicData->cf_se10, &hPublicData->cf_off_se10, &hPublicData->cf_se11, &hPublicData->cf_off_se11 ); } diff --git a/lib_enc/init_enc.c b/lib_enc/init_enc.c index acf99f33d..0792fce03 100644 --- a/lib_enc/init_enc.c +++ b/lib_enc/init_enc.c @@ -2437,14 +2437,14 @@ void LPDmem_enc_init( * Free memory which was allocated in init_encoder() *-----------------------------------------------------------------------*/ -void destroy_cldfb_encoder( +void destroy_cldfb_encoder_fx( Encoder_State *st /* i/o: Encoder static variables structure */ ) { - deleteCldfb_ivas( &st->cldfbSynTd ); - deleteCldfb_ivas( &st->cldfbAnaEnc ); + deleteCldfb_ivas_fx( &st->cldfbSynTd ); + deleteCldfb_ivas_fx( &st->cldfbAnaEnc ); - deleteFdCngEnc( &st->hFdCngEnc ); + deleteFdCngEnc_fx( &st->hFdCngEnc ); return; } diff --git a/lib_enc/ivas_agc_enc.c b/lib_enc/ivas_agc_enc.c index 51ddc9080..17bc8c2fe 100644 --- a/lib_enc/ivas_agc_enc.c +++ b/lib_enc/ivas_agc_enc.c @@ -465,7 +465,8 @@ void ivas_spar_agc_enc_close_fx( { ivas_agc_enc_state_t *hAgc; - if ( hAgcEnc == NULL || *hAgcEnc == NULL ) + test(); + IF( hAgcEnc == NULL || *hAgcEnc == NULL ) { return; } diff --git a/lib_enc/ivas_core_pre_proc.c b/lib_enc/ivas_core_pre_proc.c index 7902d1cf8..ecb5d2ecd 100644 --- a/lib_enc/ivas_core_pre_proc.c +++ b/lib_enc/ivas_core_pre_proc.c @@ -1871,6 +1871,7 @@ ivas_error ivas_compute_core_buffers( ELSE IF( GT_32( input_Fs, 8000 ) ) { lerp( st->old_inp_12k8_fx + L_INP_MEM - L_INP_MEM * 4 / 5, st->old_inp_16k_fx, L_INP_MEM, L_INP_MEM * 4 / 5 ); + Scale_sig( st->old_inp_16k_fx, L_INP_MEM, sub( -1 /* Q st->old_inp_16k_fx = -1 */, sub( 15, st->exp_old_inp_12k8 ) ) ); } IF( inp16k_out != NULL ) diff --git a/lib_enc/ivas_core_pre_proc_front.c b/lib_enc/ivas_core_pre_proc_front.c index bac876c57..1dfe55f3b 100644 --- a/lib_enc/ivas_core_pre_proc_front.c +++ b/lib_enc/ivas_core_pre_proc_front.c @@ -1606,11 +1606,6 @@ ivas_error pre_proc_front_ivas_fx( #ifdef IVAS_FLOAT_FIXED_CONVERSIONS /*float to fix conversions for noise_est_pre_32fx*/ Etot_fx = (Word32) ( Etot * ( 1 << 24 ) ); - st->hNoiseEst->Etot_l_lp_32fx = (Word32) ( st->hNoiseEst->Etot_l_lp * 16777216.0 ); - st->hNoiseEst->Etot_last_32fx = (Word32) ( st->hNoiseEst->Etot_last * 16777216.0 ); - st->hNoiseEst->Etot_v_h2_32fx = (Word32) ( st->hNoiseEst->Etot_v_h2 * 16777216.0 ); - st->hNoiseEst->Etot_lp_32fx = (Word32) ( st->hNoiseEst->Etot_lp * 16777216.0 ); - st->hNoiseEst->sign_dyn_lp_32fx = (Word32) ( st->hNoiseEst->sign_dyn_lp * 16777216.0 ); /*float to fix conversions for wb_vad_ivas_fx*/ Word16 Q_new = Q_factor_arr( fr_bands, 40 ) + 3; @@ -1620,9 +1615,6 @@ ivas_error pre_proc_front_ivas_fx( floatToFixed_arrL( st->hNoiseEst->enrO, st->hNoiseEst->enrO_fx, Q_new + QSCALE, 20 ); st->flag_noisy_speech_snr_fx = (Word8) st->flag_noisy_speech_snr; - /*float to fix for dtx_hangover_addition_fx*/ - st->hNoiseEst->Etot_lp_fx = (Word16) ( st->hNoiseEst->Etot_lp * ( 1 << 8 ) ); - if ( st->cldfbAnaEnc ) st->cldfbAnaEnc->scale = (Word16) ( st->cldfbAnaEnc->scale_flt * ( 1 << 8 ) ); @@ -1637,10 +1629,6 @@ ivas_error pre_proc_front_ivas_fx( floatToFixed_arrL( hCPE->hFrontVad[1]->hNoiseEst->bckr, hCPE->hFrontVad[1]->hNoiseEst->bckr_fx, Q_bands1 + QSCALE, NB_BANDS ); Etot_LR_fx[0] = float_to_fix16( Etot_LR[0], 8 ); Etot_LR_fx[1] = float_to_fix16( Etot_LR[1], 8 ); - hCPE->hFrontVad[0]->hNoiseEst->Etot_last_fx = float_to_fix16( hCPE->hFrontVad[0]->hNoiseEst->Etot_last, 8 ); - hCPE->hFrontVad[1]->hNoiseEst->Etot_last_fx = float_to_fix16( hCPE->hFrontVad[1]->hNoiseEst->Etot_last, 8 ); - hCPE->hFrontVad[0]->hNoiseEst->Etot_v_h2_fx = float_to_fix16( hCPE->hFrontVad[0]->hNoiseEst->Etot_v_h2, 8 ); - hCPE->hFrontVad[1]->hNoiseEst->Etot_v_h2_fx = float_to_fix16( hCPE->hFrontVad[1]->hNoiseEst->Etot_v_h2, 8 ); } #endif // IVAS_FLOAT_FIXED_TO_BE_REMOVED @@ -1675,8 +1663,6 @@ ivas_error pre_proc_front_ivas_fx( move16(); } - st->hNoiseEst->Etot_v_h2_fx = extract_h( st->hNoiseEst->Etot_v_h2_32fx ); /*q24 to q8*/ - st->hNoiseEst->sign_dyn_lp_fx = extract_h( st->hNoiseEst->sign_dyn_lp_32fx ); /*q24 to q8*/ st->vad_flag = wb_vad_ivas_fx( st, fr_bands_fx, &i, &i, &i, &snr_sum_he_fx, &localVAD_HE_SAD, &( st->flag_noisy_speech_snr_fx ), Q_new, NULL, NULL, -MAX_16, -MAX_16 ); //-100000f == max 16bit float move16(); move16(); @@ -1783,20 +1769,12 @@ ivas_error pre_proc_front_ivas_fx( corr_shiftR_fx = correlation_shift_fx( hCPE->hFrontVad[1]->hNoiseEst->totalNoise_fx ); } #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - /*cleanup changes for noise_est_pre_32fx*/ - st->hNoiseEst->Etot_l_lp = (float) ( st->hNoiseEst->Etot_l_lp_32fx / 16777216.0 ); - st->hNoiseEst->Etot_last = (float) ( st->hNoiseEst->Etot_last_32fx / 16777216.0 ); - st->hNoiseEst->Etot_lp = (float) ( st->hNoiseEst->Etot_lp_32fx / 16777216.0 ); - - /*cleanup changes for wb_vad_ivas_fx*/ - st->hNoiseEst->sign_dyn_lp = fixedToFloat( st->hNoiseEst->sign_dyn_lp_fx, 8 ); st->flag_noisy_speech_snr = (Word16) st->flag_noisy_speech_snr_fx; /*fixed to float for noise_est_down*/ fixedToFloat_arrL( st->hNoiseEst->bckr_fx, st->hNoiseEst->bckr, Q_new + QSCALE, NB_BANDS ); fixedToFloat_arrL( tmpN_fx, tmpN, Q_new + QSCALE, 20 ); fixedToFloat_arrL( tmpE_fx, tmpE, Q_new + QSCALE, 20 ); - st->hNoiseEst->Etot_v_h2 = fixedToFloat( st->hNoiseEst->Etot_v_h2_fx, 8 ); /*fixed to float for noise_est_down_fx concerned with fr_bands_LR*/ IF( lr_vad_enabled && st->idchan == 0 ) @@ -1805,10 +1783,8 @@ ivas_error pre_proc_front_ivas_fx( fixedToFloat_arrL( hCPE->hFrontVad[1]->hNoiseEst->bckr_fx, hCPE->hFrontVad[1]->hNoiseEst->bckr, Q_bands1 + QSCALE, NB_BANDS ); fixedToFloat_arrL( tmpN_LR_fx[0], tmpN_LR[0], Q_bands0 + QSCALE, 20 ); fixedToFloat_arrL( tmpE_LR_fx[0], tmpE_LR[0], Q_bands0 + QSCALE, 20 ); - hCPE->hFrontVad[0]->hNoiseEst->Etot_v_h2 = fixedToFloat( hCPE->hFrontVad[0]->hNoiseEst->Etot_v_h2_fx, 8 ); fixedToFloat_arrL( tmpN_LR_fx[1], tmpN_LR[1], Q_bands1 + QSCALE, 20 ); fixedToFloat_arrL( tmpE_LR_fx[1], tmpE_LR[1], Q_bands1 + QSCALE, 20 ); - hCPE->hFrontVad[1]->hNoiseEst->Etot_v_h2 = fixedToFloat( hCPE->hFrontVad[1]->hNoiseEst->Etot_v_h2_fx, 8 ); // performing fix to float conversion of (corr_shift_fx) corr_shiftL = fix16_to_float( corr_shiftL_fx, 15 ); @@ -2354,24 +2330,13 @@ ivas_error pre_proc_front_ivas_fx( L_Extract( epsP_fx[j], &epsP_h[j], &epsP_l[j] ); } - st->hNoiseEst->Etot_lp_fx = float_to_fix16( st->hNoiseEst->Etot_lp, Q8 ); - st->hNoiseEst->Etot_v_h2_fx = float_to_fix16( st->hNoiseEst->Etot_v_h2, Q8 ); - st->hNoiseEst->Etot_l_lp_fx = float_to_fix16( st->hNoiseEst->Etot_l_lp, Q8 ); - st->hNoiseEst->sign_dyn_lp_fx = float_to_fix16( st->hNoiseEst->sign_dyn_lp, Q8 ); - if ( lr_vad_enabled && st->idchan == 0 ) { for ( int j = 0; j < 2; j++ ) { - hCPE->hFrontVad[j]->hNoiseEst->Etot_lp_fx = float_to_fix16( hCPE->hFrontVad[j]->hNoiseEst->Etot_lp, Q8 ); - hCPE->hFrontVad[j]->hNoiseEst->Etot_v_h2_fx = float_to_fix16( hCPE->hFrontVad[j]->hNoiseEst->Etot_v_h2, Q8 ); - hCPE->hFrontVad[j]->hNoiseEst->Etot_l_lp_fx = float_to_fix16( hCPE->hFrontVad[j]->hNoiseEst->Etot_l_lp, Q8 ); - hCPE->hFrontVad[j]->hNoiseEst->sign_dyn_lp_fx = float_to_fix16( hCPE->hFrontVad[j]->hNoiseEst->sign_dyn_lp, Q8 ); Etot_LR_fx[j] = float_to_fix16( Etot_LR[j], Q8 ); } } - - st->hNoiseEst->Etot_last_fx = float_to_fix16( st->hNoiseEst->Etot_last, Q8 ); #endif // IVAS_FLOAT_FIXED_CONVERSIONS /* Detection of very short stable pitch period */ @@ -2476,22 +2441,6 @@ ivas_error pre_proc_front_ivas_fx( fixedToFloat_arrL32( st->hNoiseEst->fr_bands2_fx, st->hNoiseEst->fr_bands2, q_fr_bands, NB_BANDS ); fixedToFloat_arrL32( st->hNoiseEst->ave_enr_fx, st->hNoiseEst->ave_enr, q_fr_bands, NB_BANDS ); fixedToFloat_arrL32( st->hNoiseEst->ave_enr2_fx, st->hNoiseEst->ave_enr2, q_fr_bands, NB_BANDS ); - - st->hNoiseEst->Etot_lp = fixedToFloat_16( st->hNoiseEst->Etot_lp_fx, Q8 ); - st->hNoiseEst->Etot_v_h2 = fixedToFloat_16( st->hNoiseEst->Etot_v_h2_fx, Q8 ); - st->hNoiseEst->Etot_l_lp = fixedToFloat_16( st->hNoiseEst->Etot_l_lp_fx, Q8 ); - st->hNoiseEst->sign_dyn_lp = fixedToFloat_16( st->hNoiseEst->sign_dyn_lp_fx, Q8 ); - if ( lr_vad_enabled && st->idchan == 0 ) - { - for ( int j = 0; j < 2; j++ ) - { - hCPE->hFrontVad[j]->hNoiseEst->Etot_lp = fixedToFloat_16( hCPE->hFrontVad[j]->hNoiseEst->Etot_lp_fx, Q8 ); - hCPE->hFrontVad[j]->hNoiseEst->Etot_v_h2 = fixedToFloat_16( hCPE->hFrontVad[j]->hNoiseEst->Etot_v_h2_fx, Q8 ); - hCPE->hFrontVad[j]->hNoiseEst->Etot_l_lp = fixedToFloat_16( hCPE->hFrontVad[j]->hNoiseEst->Etot_l_lp_fx, Q8 ); - hCPE->hFrontVad[j]->hNoiseEst->sign_dyn_lp = fixedToFloat_16( hCPE->hFrontVad[j]->hNoiseEst->sign_dyn_lp_fx, Q8 ); - } - } - #endif #else @@ -2676,13 +2625,11 @@ ivas_error pre_proc_front_ivas_fx( Etot_fx = float_to_fix( Etot, 8 ); Etot16_fx = extract_l( Etot_fx ); st->lp_speech_fx = float_to_fix16( st->lp_speech, 8 ); - st->hNoiseEst->Etot_last_fx = float_to_fix16( st->hNoiseEst->Etot_last, 8 ); #endif ivas_long_enr_fx( st, Etot16_fx, localVAD_HE_SAD, high_lpn_flag, NULL, 1, NULL, NULL ); #ifdef IVAS_FLOAT_FIXED_CONVERSIONS // conv params from fix to float st->lp_speech = fix16_to_float( st->lp_speech_fx, 8 ); - st->hNoiseEst->Etot_last = fix16_to_float( st->hNoiseEst->Etot_last_fx, 8 ); #endif #endif mvr2r( fr_bands + NB_BANDS, st->hNoiseEst->enrO, NB_BANDS ); @@ -2698,11 +2645,6 @@ ivas_error pre_proc_front_ivas_fx( Etot_LR_fx[1] = float_to_fix16( Etot_LR[1], 8 ); #endif ivas_long_enr_fx( st, -1, localVAD_HE_SAD, high_lpn_flag, hCPE->hFrontVad, CPE_CHANNELS, localVAD_HE_SAD_LR, Etot_LR_fx ); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - hCPE->hFrontVad[0]->hNoiseEst->Etot_last = fix16_to_float( hCPE->hFrontVad[0]->hNoiseEst->Etot_last_fx, 8 ); - hCPE->hFrontVad[1]->hNoiseEst->Etot_last = fix16_to_float( hCPE->hFrontVad[1]->hNoiseEst->Etot_last_fx, 8 ); - -#endif #endif mvr2r( fr_bands_LR[0] + NB_BANDS, hCPE->hFrontVad[0]->hNoiseEst->enrO, NB_BANDS ); mvr2r( fr_bands_LR[1] + NB_BANDS, hCPE->hFrontVad[1]->hNoiseEst->enrO, NB_BANDS ); diff --git a/lib_enc/ivas_corecoder_enc_reconfig.c b/lib_enc/ivas_corecoder_enc_reconfig.c index c7b25cee8..e0bc2f18f 100644 --- a/lib_enc/ivas_corecoder_enc_reconfig.c +++ b/lib_enc/ivas_corecoder_enc_reconfig.c @@ -584,7 +584,7 @@ ivas_error ivas_corecoder_enc_reconfig_fx( IF( GT_16( st_ivas->nCPE, 1 ) ) { - IF( ( error = mct_enc_reconfigure( st_ivas, 0 ) ) != IVAS_ERR_OK ) + IF( ( error = mct_enc_reconfigure_fx( st_ivas, 0 ) ) != IVAS_ERR_OK ) { return error; } @@ -1040,7 +1040,7 @@ ivas_error ivas_corecoder_enc_reconfig_fx( } ELSE IF( st_ivas->hMCT != NULL && GT_16( st_ivas->nCPE, 1 ) ) { - IF( ( error = mct_enc_reconfigure( st_ivas, st_ivas->nchan_transport != nchan_transport_old ) ) != IVAS_ERR_OK ) + IF( ( error = mct_enc_reconfigure_fx( st_ivas, st_ivas->nchan_transport != nchan_transport_old ) ) != IVAS_ERR_OK ) { return error; } diff --git a/lib_enc/ivas_cpe_enc.c b/lib_enc/ivas_cpe_enc.c index ec599c5fc..4796a9a7b 100644 --- a/lib_enc/ivas_cpe_enc.c +++ b/lib_enc/ivas_cpe_enc.c @@ -264,11 +264,6 @@ ivas_error ivas_cpe_enc( hCPE->hFrontVad[n]->mem_preemph_fx = (Word16) floatToFixed( hCPE->hFrontVad[n]->mem_preemph, Q_inp - 1 ); Q_buffer[n] = Q_factor_arr( hCPE->hFrontVad[n]->buffer_12k8 + L_FFT, L_FFT / 2 ); floatToFixed_arr( hCPE->hFrontVad[n]->buffer_12k8, hCPE->hFrontVad[n]->buffer_12k8_fx, Q_buffer[n], 384 ); - hCPE->hFrontVad[n]->hNoiseEst->Etot_l_lp_32fx = (Word32) ( hCPE->hFrontVad[n]->hNoiseEst->Etot_l_lp * 16777216.0 ); - hCPE->hFrontVad[n]->hNoiseEst->Etot_last_32fx = (Word32) ( hCPE->hFrontVad[n]->hNoiseEst->Etot_last * 16777216.0 ); - hCPE->hFrontVad[n]->hNoiseEst->Etot_v_h2_32fx = (Word32) ( hCPE->hFrontVad[n]->hNoiseEst->Etot_v_h2 * 16777216.0 ); - hCPE->hFrontVad[n]->hNoiseEst->Etot_lp_32fx = (Word32) ( hCPE->hFrontVad[n]->hNoiseEst->Etot_lp * 16777216.0 ); - hCPE->hFrontVad[n]->hNoiseEst->sign_dyn_lp_32fx = (Word32) ( hCPE->hFrontVad[n]->hNoiseEst->sign_dyn_lp * 16777216.0 ); floatToFixed_arrL( hCPE->hFrontVad[n]->hNoiseEst->bckr, hCPE->hFrontVad[n]->hNoiseEst->bckr_fx, Q_new_old + QSCALE, 20 ); floatToFixed_arrL( hCPE->hFrontVad[n]->hNoiseEst->enrO, hCPE->hFrontVad[n]->hNoiseEst->enrO_fx, Q_new_old + QSCALE, 20 ); } @@ -302,12 +297,6 @@ ivas_error ivas_cpe_enc( Etot_LR[n] = fixedToFloat( Etot_LR_fx[n], Q8 ); fixedToFloat_arrL( hCPE->hFrontVad[n]->hNoiseEst->bckr_fx, hCPE->hFrontVad[n]->hNoiseEst->bckr, Q_new_old + QSCALE, 20 ); fixedToFloat_arrL( hCPE->hFrontVad[n]->hNoiseEst->enrO_fx, hCPE->hFrontVad[n]->hNoiseEst->enrO, Q_new_old + QSCALE, 20 ); - hCPE->hFrontVad[n]->hNoiseEst->Etot_l_lp = (float) ( hCPE->hFrontVad[n]->hNoiseEst->Etot_l_lp_32fx / 16777216.0 ); - hCPE->hFrontVad[n]->hNoiseEst->Etot_last = (float) ( hCPE->hFrontVad[n]->hNoiseEst->Etot_last_32fx / 16777216.0 ); - // hCPE->hFrontVad[n]->hNoiseEst->Etot_v_h2 = (float) ( hCPE->hFrontVad[n]->hNoiseEst->Etot_v_h2_32fx / 16777216.0 ); - hCPE->hFrontVad[n]->hNoiseEst->Etot_lp = (float) ( hCPE->hFrontVad[n]->hNoiseEst->Etot_lp_32fx / 16777216.0 ); - hCPE->hFrontVad[n]->hNoiseEst->Etot_v_h2 = (float) ( hCPE->hFrontVad[n]->hNoiseEst->Etot_v_h2_fx / ( 256.0 ) ); - hCPE->hFrontVad[n]->hNoiseEst->sign_dyn_lp = (float) ( hCPE->hFrontVad[n]->hNoiseEst->sign_dyn_lp_fx / ( 256.0 ) ); if ( front_create_flag ) { fixedToFloat_arrL( hCPE->hFrontVad[n]->hNoiseEst->fr_bands1_fx, hCPE->hFrontVad[n]->hNoiseEst->fr_bands1, Q17, NB_BANDS ); @@ -316,7 +305,6 @@ ivas_error ivas_cpe_enc( fixedToFloat_arrL( hCPE->hFrontVad[n]->hNoiseEst->ave_enr2_fx, hCPE->hFrontVad[n]->hNoiseEst->ave_enr2, Q8, NB_BANDS ); } } - // fixedToFloat_arrL( band_energies_fx, band_energies, Q_new + QSCALE + 2, 40 ); fixedToFloat_arrL( &band_energies_LR_fx[0], &band_energies_LR[0], Q_buffer[1] + QSCALE - band_ener_guardbits, 40 ); } #endif @@ -728,8 +716,6 @@ ivas_error ivas_cpe_enc( floatToFixed_arr16( sts[0]->input, sts[0]->input_fx, 0, input_frame ); floatToFixed_arr16( sts[1]->input, sts[1]->input_fx, 0, input_frame ); - sts[0]->hNoiseEst->Etot_last_fx = float_to_fix16( sts[0]->hNoiseEst->Etot_last, Q8 ); - sts[1]->hNoiseEst->Etot_last_fx = float_to_fix16( sts[1]->hNoiseEst->Etot_last, Q8 ); sts[0]->old_corr_fx = float_to_fix16( sts[0]->old_corr, Q15 ); sts[1]->old_corr_fx = float_to_fix16( sts[1]->old_corr, Q15 ); @@ -737,8 +723,6 @@ ivas_error ivas_cpe_enc( { floatToFixed_arr16( sts[0]->input, sts[0]->input_fx, 0, input_frame ); floatToFixed_arr16( sts[1]->input, sts[1]->input_fx, 0, input_frame ); - sts[0]->hNoiseEst->Etot_last_fx = float_to_fix16( sts[0]->hNoiseEst->Etot_last, Q8 ); - sts[1]->hNoiseEst->Etot_last_fx = float_to_fix16( sts[1]->hNoiseEst->Etot_last, Q8 ); sts[0]->old_corr_fx = float_to_fix16( sts[0]->old_corr, Q15 ); sts[1]->old_corr_fx = float_to_fix16( sts[1]->old_corr, Q15 ); } @@ -747,10 +731,6 @@ ivas_error ivas_cpe_enc( tdm_ratio_idx = stereo_tdm_ener_analysis_fx( ivas_format, hCPE, input_frame, &tdm_SM_or_LRTD_Pri, &tdm_ratio_idx_SM ); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - sts[0]->hNoiseEst->Etot_last = fix16_to_float( sts[0]->hNoiseEst->Etot_last_fx, Q8 ); - sts[1]->hNoiseEst->Etot_last = fix16_to_float( sts[1]->hNoiseEst->Etot_last_fx, Q8 ); -#endif /* Compute the downmix signal based on the ratio index */ #ifdef IVAS_FLOAT_FIXED @@ -782,15 +762,25 @@ ivas_error ivas_cpe_enc( /* signal the bitrate for BW selection in the SCh */ sts[0]->bits_frame_channel = 0; - sts[1]->bits_frame_channel = (int16_t) ( hCPE->element_brate / FRAMES_PER_SEC ); - sts[1]->bits_frame_channel += (int16_t) ( hCPE->brate_surplus / FRAMES_PER_SEC ); - if ( st_ivas->hQMetaData != NULL ) + sts[1]->bits_frame_channel = extract_l( Mpy_32_32( hCPE->element_brate, ONE_BY_FRAMES_PER_SEC_Q31 ) ); + sts[1]->bits_frame_channel = add( sts[1]->bits_frame_channel, extract_l( Mpy_32_32( hCPE->brate_surplus, ONE_BY_FRAMES_PER_SEC_Q31 ) ) ); + move16(); + move16(); + move16(); + IF( st_ivas->hQMetaData != NULL ) { - sts[1]->bits_frame_channel -= st_ivas->hQMetaData->metadata_max_bits; + sts[1]->bits_frame_channel = sub( sts[1]->bits_frame_channel, st_ivas->hQMetaData->metadata_max_bits ); + move16(); } - Etot_last[0] = sts[0]->hNoiseEst->Etot_last; - Etot_last[1] = sts[1]->hNoiseEst->Etot_last; + Etot_last_fx[0] = sts[0]->hNoiseEst->Etot_last_fx; + Etot_last_fx[1] = sts[1]->hNoiseEst->Etot_last_fx; + move16(); + move16(); +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + Etot_last[0] = fix16_to_float( Etot_last_fx[0], Q8 ); + Etot_last[1] = fix16_to_float( Etot_last_fx[1], Q8 ); +#endif } else if ( hCPE->element_mode == IVAS_CPE_MDCT ) { @@ -840,7 +830,6 @@ ivas_error ivas_cpe_enc( /* iDFT at input sampling rate */ #ifdef IVAS_FLOAT_FIXED - // stereo_dft_enc_synthesize( hCPE->hStereoDft, sts[0]->input, 0, input_Fs, input_Fs, 0 ); Word16 out_start_ind, out_end_ind; Word16 out_12k8_start_ind[CPE_CHANNELS], out_12k8_end_ind[CPE_CHANNELS]; Word16 out_16k_start_ind = 0, out_16k_end_ind = 0; @@ -849,20 +838,17 @@ ivas_error ivas_cpe_enc( stereo_dft_enc_synthesize_fx( hCPE->hStereoDft, sts[0]->input32_fx, &out_start_ind, &out_end_ind, 0, input_Fs, input_Fs, 0, NULL ); /* iDFT & resampling to 12.8kHz internal sampling rate */ - // stereo_dft_enc_synthesize( hCPE->hStereoDft, old_inp_12k8[0] + L_INP_MEM, 0, input_Fs, INT_FS_12k8, 0 ); stereo_dft_enc_synthesize_fx( hCPE->hStereoDft, old_inp_12k8_fx[0] + L_INP_MEM, &out_12k8_start_ind[0], &out_12k8_end_ind[0], 0, input_Fs, INT_FS_12k8, 0, NULL ); /* iDFT & resampling to 16kHz internal sampling rate for M channel */ IF( EQ_32( input_Fs, internal_Fs ) ) { - // mvr2r( sts[0]->input - STEREO_DFT_OVL_16k, old_inp_16k[0] + L_INP_MEM - STEREO_DFT_OVL_16k, input_frame + STEREO_DFT_OVL_16k ); Copy32( sts[0]->input32_fx - STEREO_DFT_OVL_16k, old_inp_16k_fx[0] + L_INP_MEM - STEREO_DFT_OVL_16k, input_frame + STEREO_DFT_OVL_16k ); out_16k_start_ind = -STEREO_DFT_OVL_16k; out_16k_end_ind = out_16k_start_ind + input_frame + STEREO_DFT_OVL_16k; } ELSE { - // stereo_dft_enc_synthesize( hCPE->hStereoDft, old_inp_16k[0] + L_INP_MEM, 0, input_Fs, internal_Fs, 0 ); stereo_dft_enc_synthesize_fx( hCPE->hStereoDft, old_inp_16k_fx[0] + L_INP_MEM, &out_16k_start_ind, &out_16k_end_ind, 0, input_Fs, internal_Fs, 0, NULL ); } @@ -870,13 +856,10 @@ ivas_error ivas_cpe_enc( test(); IF( EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) && hCPE->hStereoDft->res_cod_mode[STEREO_DFT_OFFSET] ) { - // mvr2r( sts[1]->old_inp_12k8, old_inp_12k8[1], L_INP_MEM ); Copy_Scale_sig_16_32_no_sat( sts[1]->old_inp_12k8_fx, old_inp_12k8_fx[1], L_INP_MEM, 16 - 0 ); - // stereo_dft_enc_synthesize( hCPE->hStereoDft, old_inp_12k8[1] + L_INP_MEM, 1, input_Fs, 8000, 0 ); stereo_dft_enc_synthesize_fx( hCPE->hStereoDft, old_inp_12k8_fx[1] + L_INP_MEM, &out_12k8_start_ind[1], &out_12k8_end_ind[1], 1, input_Fs, 8000, 0, NULL ); /* update old input signal buffer */ - // mvr2r( old_inp_12k8[1] + L_FRAME8k, sts[1]->old_inp_12k8, L_INP_MEM ); Copy_Scale_sig_32_16( old_inp_12k8_fx[1] + L_FRAME8k, sts[1]->old_inp_12k8_fx, L_INP_MEM, 0 - 16 ); } @@ -2792,7 +2775,7 @@ FOR( n = 0; n < CPE_CHANNELS; n++ ) IF( st != NULL ) { - destroy_core_enc( st ); + destroy_core_enc_fx( st ); st = NULL; } } @@ -2837,7 +2820,7 @@ IF( hCPE->hFrontVad[0] != NULL ) { FOR( n = 0; n < CPE_CHANNELS; n++ ) { - front_vad_destroy( &hCPE->hFrontVad[n] ); + front_vad_destroy_fx( &hCPE->hFrontVad[n] ); hCPE->hFrontVad[n] = NULL; } } diff --git a/lib_enc/ivas_front_vad.c b/lib_enc/ivas_front_vad.c index cdca90692..af515d836 100644 --- a/lib_enc/ivas_front_vad.c +++ b/lib_enc/ivas_front_vad.c @@ -423,8 +423,6 @@ ivas_error front_vad_fx( /* wb_vad */ Scale_sig32( hFrontVads[n]->hNoiseEst->bckr_fx, NB_BANDS, Q_new + QSCALE - ( Q_new_old + QSCALE ) ); Scale_sig32( hFrontVads[n]->hNoiseEst->enrO_fx, NB_BANDS, Q_new + QSCALE - ( Q_new_old + QSCALE ) ); - hFrontVad->hNoiseEst->sign_dyn_lp_fx = extract_h( hFrontVad->hNoiseEst->sign_dyn_lp_32fx ); - hFrontVad->hNoiseEst->Etot_v_h2_fx = extract_h( hFrontVad->hNoiseEst->Etot_v_h2_32fx ); hFrontVad->hVAD->vad_flag = wb_vad_ivas_fx( sts[n], fr_bands_fx[n], &dummy, &dummy, &dummy, &snr_sum_he_fx, &localVAD_HE_SAD[n], &dummy_short, Q_new, hFrontVad->hVAD, hFrontVad->hNoiseEst, hFrontVad->lp_speech_fx, hFrontVad->lp_noise_fx ); test(); @@ -729,9 +727,6 @@ ivas_error front_vad_spar( Word32 tmpN_fx[NB_BANDS] = { 0 }; Word32 tmpE_fx[NB_BANDS] = { 0 }; float corr_shift; - // float res_energy; - // float ncharX; - // float sp_div, dummy; Word16 corr_shift_fx; #if 1 @@ -796,15 +791,7 @@ ivas_error front_vad_spar( FILE *fptmpE_fx = fopen( "tmpE_fx.txt", "ab+" ); FILE *fpbckr_fx = fopen( "bckr_fx.txt", "ab+" ); #endif -#if 1 - FILE *fp_pitch = fopen( "fp_pitch.txt", "ab+" ); - FILE *fp_voice = fopen( "fp_voice.txt", "ab+" ); - /* FILE *fpbckr_fl = fopen( "bckr_fl.txt", "ab+" ); - FILE *fptmpN_fx = fopen( "tmpN_fx.txt", "ab+" ); - FILE *fptmpE_fx = fopen( "tmpE_fx.txt", "ab+" ); - FILE *fpbckr_fx = fopen( "bckr_fx.txt", "ab+" );*/ -#endif push_wmops( "front_vad_SPAR" ); error = IVAS_ERR_OK; hFrontVad = hSpar->hFrontVad; @@ -828,7 +815,6 @@ ivas_error front_vad_spar( floatToFixed_arr( st->old_wsp, st->old_wsp_fx, Q9, L_WSP_MEM ); floatToFixed_arr( st->old_wsp2, st->old_wsp2_fx, Q9, ( L_WSP_MEM - L_INTERPOL ) / OPL_DECIM ); floatToFixed_arr( st->mem_decim2, st->mem_decim2_fx, Q9, 3 ); - // st->mem_wsp_fx = (Word16) floatToFixed( st->mem_wsp, Q_inp_12k8 ); MVR2R_WORD16( st->old_wsp_fx, old_wsp_fx, L_WSP_MEM ); wsp = old_wsp + L_WSP_MEM; @@ -847,15 +833,7 @@ ivas_error front_vad_spar( delay_signal_float( st->input, input_frame, hFrontVad->delay_buf, hFrontVad->delay_samples ); Word16 Q_inp; Q_inp = Q_factor_arr( st->input, L_FRAME48k ); -#if 0 - FILE *fp = fopen( "input_before.txt", "ab+" ); - for ( int i = 0; i < L_FRAME48k; i++ ) - { - fprintf( fp, "%d\t", i ); - fprintf( fp, "%f\n", st->input[i] ); - } - fclose( fp ); -#endif + floatToFixed_arr( st->input, st->input_fx, Q_inp, L_FRAME48k ); Word16 Q_add = 0; move16(); @@ -880,11 +858,6 @@ ivas_error front_vad_spar( hFrontVad->mem_preemph_fx = (Word16) floatToFixed( hFrontVad->mem_preemph, Q_inp - 1 ); Word16 Q_buffer = Q_factor_arr( hFrontVad->buffer_12k8 + L_FFT, L_FFT / 2 ); floatToFixed_arr( hFrontVad->buffer_12k8, hFrontVad->buffer_12k8_fx, Q_buffer, 384 ); - hFrontVad->hNoiseEst->Etot_l_lp_32fx = (Word32) ( hFrontVad->hNoiseEst->Etot_l_lp * 16777216.0 ); - hFrontVad->hNoiseEst->Etot_last_32fx = (Word32) ( hFrontVad->hNoiseEst->Etot_last * 16777216.0 ); - hFrontVad->hNoiseEst->Etot_v_h2_32fx = (Word32) ( hFrontVad->hNoiseEst->Etot_v_h2 * 16777216.0 ); - hFrontVad->hNoiseEst->Etot_lp_32fx = (Word32) ( hFrontVad->hNoiseEst->Etot_lp * 16777216.0 ); - hFrontVad->hNoiseEst->sign_dyn_lp_32fx = (Word32) ( hFrontVad->hNoiseEst->sign_dyn_lp * 16777216.0 ); st->lp_speech_fx = (Word16) floatToFixed( st->lp_speech, Q8 ); floatToFixed_arrL( hFrontVad->hNoiseEst->bckr, hFrontVad->hNoiseEst->bckr_fx, Q_new_old + QSCALE + 2, 20 ); floatToFixed_arrL( hFrontVad->hNoiseEst->enrO, hFrontVad->hNoiseEst->enrO_fx, Q_new_old + QSCALE + 2, 20 ); @@ -910,14 +883,6 @@ ivas_error front_vad_spar( } fixedToFloat_arrL( PS_fx, PS, Q_buffer + QSCALE, 128 ); Etot[0] = fixedToFloat( Etot_fx[0], Q8 ); - hFrontVad->hNoiseEst->Etot_l_lp = (float) ( hFrontVad->hNoiseEst->Etot_l_lp_32fx / 16777216.0 ); - hFrontVad->hNoiseEst->Etot_last = (float) ( hFrontVad->hNoiseEst->Etot_last_32fx / 16777216.0 ); - // hFrontVad->hNoiseEst->Etot_v_h2 = (float) ( hFrontVad->hNoiseEst->Etot_v_h2_32fx / 16777216.0 ); - hFrontVad->hNoiseEst->Etot_lp = (float) ( hFrontVad->hNoiseEst->Etot_lp_32fx / 16777216.0 ); - // hFrontVad->hNoiseEst->sign_dyn_lp = (float) ( hFrontVad->hNoiseEst->sign_dyn_lp_32fx / 16777216.0 ); - - hFrontVad->hNoiseEst->Etot_v_h2 = (float) ( hFrontVad->hNoiseEst->Etot_v_h2_fx / ( 256.0 ) ); - hFrontVad->hNoiseEst->sign_dyn_lp = (float) ( hFrontVad->hNoiseEst->sign_dyn_lp_fx / ( 256.0 ) ); fixedToFloat_arrL( &band_energies_fx[0], &band_energies[0], Q_buffer + QSCALE + 2 - band_ener_guardbits, 40 ); #endif #endif @@ -932,10 +897,7 @@ ivas_error front_vad_spar( floatToFixed_arrL( tmpE, tmpE_fx, Q_bands + QSCALE, NB_BANDS ); #endif Etot_fx[0] = (Word16) ( Etot[0] * ONE_IN_Q8 ); - hFrontVad->hNoiseEst->Etot_last_fx = (Word16) ( hFrontVad->hNoiseEst->Etot_last * ONE_IN_Q8 ); - hFrontVad->hNoiseEst->Etot_v_h2_fx = (Word16) ( hFrontVad->hNoiseEst->Etot_v_h2 * ONE_IN_Q8 ); noise_est_down_fx( fr_bands_fx[0], hFrontVad->hNoiseEst->bckr_fx, tmpN_fx, tmpE_fx, st->min_band, st->max_band, &hFrontVad->hNoiseEst->totalNoise_fx, Etot_fx[0], &hFrontVad->hNoiseEst->Etot_last_fx, &hFrontVad->hNoiseEst->Etot_v_h2_fx, Q_bands, e_min_scaled ); - // noise_est_down( fr_bands[0], hFrontVad->hNoiseEst->bckr, tmpN, tmpE, st->min_band, st->max_band, &hFrontVad->hNoiseEst->totalNoise, Etot[0], &hFrontVad->hNoiseEst->Etot_last, &hFrontVad->hNoiseEst->Etot_v_h2 ); #ifdef DUMP_VAD_SPAR for ( Word16 i = 0; i < 20; i++ ) { @@ -948,9 +910,6 @@ ivas_error front_vad_spar( fixedToFloat_arrL( hFrontVad->hNoiseEst->bckr_fx, hFrontVad->hNoiseEst->bckr, Q_bands + Q7, NB_BANDS ); fixedToFloat_arrL( tmpN_fx, tmpN, Q_bands + QSCALE, 20 ); fixedToFloat_arrL( tmpE_fx, tmpE, Q_bands + QSCALE, 20 ); - // Etot[0] = (float) Etot_fx[0] / ONE_IN_Q8; - hFrontVad->hNoiseEst->Etot_last = (float) hFrontVad->hNoiseEst->Etot_last_fx / ONE_IN_Q8; - hFrontVad->hNoiseEst->Etot_v_h2 = (float) hFrontVad->hNoiseEst->Etot_v_h2_fx / ONE_IN_Q8; #ifdef DUMP_VAD_SPAR for ( Word16 i = 0; i < 20; i++ ) { @@ -965,7 +924,6 @@ ivas_error front_vad_spar( #if 1 Q_inp_12k8 = Q_factor_arr( inp_12k8, 3 * L_FRAME / 2 ); floatToFixed_arr( inp_12k8, inp_12k8_fx, Q_inp_12k8, 3 * L_FRAME / 2 ); - // Q_lp_noise = Q_factor( st->lp_noise ); dtx_ivas_fx( st, hEncoderConfig->ivas_total_brate, vad_flag_dtx[0], inp_12k8_fx, Q_inp_12k8 ); #else dtx( st, hEncoderConfig->ivas_total_brate, vad_flag_dtx[0], inp_12k8 ); @@ -1014,7 +972,6 @@ ivas_error front_vad_spar( ivas_find_wsp( L_FRAME, L_SUBFR, NB_SUBFR, A_fx, Aw_fx, inp_12k8_fx, TILT_FAC_FX, wsp_fx, &st->mem_wsp_fx, GAMMA1, L_LOOK_12k8 ); fixedToFloat_arr( wsp_fx, wsp, Q_inp_12k8, 368 ); fixedToFloat_arr( Aw_fx, Aw, Q12, NB_SUBFR16k * ( M + 1 ) ); - // st->mem_wsp = fixedToFloat( st->mem_wsp_fx, Q_inp_12k8 ); #endif if ( st->vad_flag == 0 ) @@ -1047,14 +1004,6 @@ ivas_error front_vad_spar( fixedToFloat_arr( st->old_wsp2_fx, st->old_wsp2, Q8, 115 ); fixedToFloat_arr( st->mem_decim2_fx, st->mem_decim2, Q8, 3 ); st->old_corr = fixedToFloat( st->old_corr_fx, Q15 ); - // corr_shift_fx = floatToFixed( corr_shift, Q15 ); - // st->old_thres_fx = floatToFixed( relE, Q8 ); - /*for ( Word16 i = 0; i < 3; i++ ) - { - fprintf( fp_pitch, "%d\n", st->pitch[i] ); - fprintf( fp_voice, "%f\n", st->voicing[i] ); - }*/ - // fprintf( fpbckr_fl, "%f\n", hFrontVad->hNoiseEst->bckr[i] ); #else pitch_ol( st->pitch, st->voicing, &st->old_pitch, &st->old_corr, corr_shift, &st->old_thres, &st->delta_pit, st->old_wsp2, wsp, st->mem_decim2, relE, L_LOOK_12k8, st->clas, st->input_bwidth, st->Opt_SC_VBR ); #endif @@ -1100,11 +1049,7 @@ ivas_error front_vad_spar( floatToFixed_arrL( hFrontVad->hNoiseEst->fr_bands2, hFrontVad->hNoiseEst->fr_bands2_fx, Q_bands + QSCALE, NB_BANDS ); floatToFixed_arrL( hFrontVad->hNoiseEst->ave_enr, hFrontVad->hNoiseEst->ave_enr_fx, Q_bands + QSCALE, NB_BANDS ); floatToFixed_arrL( hFrontVad->hNoiseEst->ave_enr2, hFrontVad->hNoiseEst->ave_enr2_fx, Q_bands + QSCALE, NB_BANDS ); - hFrontVad->hNoiseEst->sign_dyn_lp_fx = (Word16) floatToFixed( hFrontVad->hNoiseEst->sign_dyn_lp, Q8 ); - hFrontVad->hNoiseEst->Etot_l_lp_fx = (Word16) floatToFixed( hFrontVad->hNoiseEst->Etot_l_lp, Q8 ); - hFrontVad->hNoiseEst->Etot_lp_fx = (Word16) floatToFixed( hFrontVad->hNoiseEst->Etot_lp, Q8 ); - hFrontVad->hNoiseEst->Etot_v_h2_fx = (Word16) floatToFixed( hFrontVad->hNoiseEst->Etot_v_h2, Q8 ); corr_shift_fx = (Word16) floatToFixed( corr_shift, Q15 ); floatToFixed_arrL( hFrontVad->hNoiseEst->bckr, hFrontVad->hNoiseEst->bckr_fx, Q_bands + QSCALE, NB_BANDS ); @@ -1138,13 +1083,8 @@ ivas_error front_vad_spar( #else SP_MUS_CLAS_HANDLE hSpMusClas = st->hSpMusClas; #if 1 - // Word16 relE_fx; - // Word16 lsp_new_fx[M]; - // Word32 PS_fx[128]; - // Word32 epsP_fx[M + 1]; cor_map_sum_fx = float_to_fix16( cor_map_sum, Q8 ); Word16 non_sta_fx = float_to_fix16( non_staX, Q6 ); - // Word32 epsP_fx[M + 1]; Word16 Etot_fx_0 = float_to_fix16( Etot[0], Q8 ); floatToFixed_arr( lsp_new, lsp_new_fx, Q15, M ); relE_fx = float_to_fix16( relE, 8 ); @@ -1162,14 +1102,10 @@ ivas_error front_vad_spar( fixedToFloat_arrL32( hSpMusClas->past_PS_fx, hSpMusClas->past_PS, Qfact_PS_past, 67 ); #endif #endif -#if 0 - /* long-term energy update */ - long_enr( st, -1, localVAD_HE_SAD[0], high_lpn_flag, &hFrontVad, 1, localVAD_HE_SAD, Etot ); -#else + /* long-term energy update */ ivas_long_enr_fx( st, -1, localVAD_HE_SAD[0], high_lpn_flag, &hFrontVad, 1, localVAD_HE_SAD, Etot_fx ); - hFrontVad->hNoiseEst->Etot_last = fixedToFloat( hFrontVad->hNoiseEst->Etot_last_fx, Q8 ); -#endif + /* increase ini_frame counter */ hFrontVad->ini_frame = min( hFrontVad->ini_frame + 1, MAX_FRAME_COUNTER ); st->ini_frame = hFrontVad->ini_frame; @@ -1198,10 +1134,7 @@ ivas_error front_vad_spar( fclose( fptmpE_fx ); fclose( fpbckr_fx ); #endif -#if 1 - fclose( fp_pitch ); - fclose( fp_voice ); -#endif + pop_wmops(); return error; } diff --git a/lib_enc/ivas_init_enc.c b/lib_enc/ivas_init_enc.c index e0fd58802..2378bd8d4 100644 --- a/lib_enc/ivas_init_enc.c +++ b/lib_enc/ivas_init_enc.c @@ -1949,13 +1949,13 @@ ivas_error ivas_init_encoder_fx( * Close core encoder handles *-------------------------------------------------------------------------*/ -void destroy_core_enc( +void destroy_core_enc_fx( ENC_CORE_HANDLE hCoreCoder /* i/o: core encoder structure */ ) { Word16 i; - destroy_cldfb_encoder( hCoreCoder ); + destroy_cldfb_encoder_fx( hCoreCoder ); IF( hCoreCoder->hSignalBuf != NULL ) { @@ -1969,6 +1969,7 @@ void destroy_core_enc( FOR( i = 0; i < hCoreCoder->hBstr->nb_ind_tot; i++ ) { hCoreCoder->hBstr->ind_list[i].nb_bits = -1; + move16(); } free( hCoreCoder->hBstr ); hCoreCoder->hBstr = NULL; @@ -2185,7 +2186,7 @@ void ivas_destroy_enc( ivas_param_ism_enc_close( &( st_ivas->hParamIsm ), st_ivas->hEncoderConfig->input_Fs ); /* SPAR handle */ - ivas_spar_enc_close( &( st_ivas->hSpar ), st_ivas->hEncoderConfig->input_Fs, nchan_inp, 0 ); + ivas_spar_enc_close_fx( &( st_ivas->hSpar ), st_ivas->hEncoderConfig->input_Fs, nchan_inp, 0 ); /* MASA handle */ ivas_masa_enc_close( &( st_ivas->hMasa ) ); diff --git a/lib_enc/ivas_mct_enc.c b/lib_enc/ivas_mct_enc.c index 51aff96df..4750162a7 100644 --- a/lib_enc/ivas_mct_enc.c +++ b/lib_enc/ivas_mct_enc.c @@ -121,12 +121,6 @@ static void set_mct_enc_params( set16_fx( hMCT->lowE_ch, 0, MCT_MAX_CHANNELS ); -#if 1 // TODO: To be removed later - for ( n = 0; n < MCT_MAX_CHANNELS; n++ ) - { - set_f( hMCT->lastxCorrMatrix[n], 0, MCT_MAX_CHANNELS ); - } -#endif FOR( n = 0; n < MCT_MAX_CHANNELS; n++ ) { set32_fx( hMCT->lastxCorrMatrix_fx[n], 0, MCT_MAX_CHANNELS ); @@ -1228,7 +1222,7 @@ ivas_error mct_enc_reconfigure( return error; } #else -ivas_error mct_enc_reconfigure( +ivas_error mct_enc_reconfigure_fx( Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ const UWord16 b_nchan_change /* i : flag indicating different channel count */ ) @@ -1305,7 +1299,7 @@ ivas_error mct_enc_reconfigure( } /* in case we have an uneven number of transport channels, indicate last channel ID as inactive */ - IF( hMCT->nchan_out_woLFE % 2 ) + IF( s_and( hMCT->nchan_out_woLFE, 1 ) ) { st_ivas->hCPE[st_ivas->nCPE - 1]->hCoreCoder[1]->mct_chan_mode = MCT_CHAN_MODE_IGNORE; move16(); diff --git a/lib_enc/ivas_osba_enc.c b/lib_enc/ivas_osba_enc.c index aafe494b4..f9fcd6ca9 100644 --- a/lib_enc/ivas_osba_enc.c +++ b/lib_enc/ivas_osba_enc.c @@ -432,7 +432,7 @@ ivas_error ivas_osba_enc_reconfig( } spar_reconfig_flag = 1; move16(); - ivas_spar_enc_close( &( st_ivas->hSpar ), hEncoderConfig->input_Fs, hEncoderConfig->nchan_inp, spar_reconfig_flag ); + ivas_spar_enc_close_fx( &( st_ivas->hSpar ), hEncoderConfig->input_Fs, hEncoderConfig->nchan_inp, spar_reconfig_flag ); IF( ( error = ivas_spar_enc_open( st_ivas, spar_reconfig_flag ) ) != IVAS_ERR_OK ) { diff --git a/lib_enc/ivas_sba_enc.c b/lib_enc/ivas_sba_enc.c index c1e8a4b42..f246cb49d 100644 --- a/lib_enc/ivas_sba_enc.c +++ b/lib_enc/ivas_sba_enc.c @@ -226,7 +226,7 @@ ivas_error ivas_sba_enc_reconfigure( } spar_reconfig_flag = 1; move16(); - ivas_spar_enc_close( &( st_ivas->hSpar ), hEncoderConfig->input_Fs, hEncoderConfig->nchan_inp, spar_reconfig_flag ); + ivas_spar_enc_close_fx( &( st_ivas->hSpar ), hEncoderConfig->input_Fs, hEncoderConfig->nchan_inp, spar_reconfig_flag ); IF( ( error = ivas_spar_enc_open( st_ivas, spar_reconfig_flag ) ) != IVAS_ERR_OK ) { diff --git a/lib_enc/ivas_sce_enc.c b/lib_enc/ivas_sce_enc.c index 6637128dd..7c86f194a 100644 --- a/lib_enc/ivas_sce_enc.c +++ b/lib_enc/ivas_sce_enc.c @@ -687,7 +687,7 @@ void destroy_sce_enc( } ELSE { - destroy_core_enc( st ); + destroy_core_enc_fx( st ); st = NULL; } } diff --git a/lib_enc/ivas_spar_encoder.c b/lib_enc/ivas_spar_encoder.c index 788f9dec2..6e506a125 100644 --- a/lib_enc/ivas_spar_encoder.c +++ b/lib_enc/ivas_spar_encoder.c @@ -489,75 +489,65 @@ ivas_error ivas_spar_enc_open_fx( * Deallocate SPAR encoder handle *------------------------------------------------------------------------*/ -void ivas_spar_enc_close( - SPAR_ENC_HANDLE *hSpar, /* i/o: SPAR encoder handle */ - const int32_t input_Fs, /* i : input sampling rate */ - const int16_t nchan_inp, /* i : number of input channels */ - const int16_t spar_reconfig_flag /* i : SPAR reconfiguration flag */ +void ivas_spar_enc_close_fx( + SPAR_ENC_HANDLE *hSpar, /* i/o: SPAR encoder handle */ + const Word32 input_Fs, /* i : input sampling rate */ + const Word16 nchan_inp, /* i : number of input channels */ + const Word16 spar_reconfig_flag /* i : SPAR reconfiguration flag */ ) { - int16_t num_chans; + Word16 num_chans; - if ( hSpar == NULL || *hSpar == NULL ) + test(); + IF( hSpar == NULL || *hSpar == NULL ) { return; } - if ( !spar_reconfig_flag ) + IF( !spar_reconfig_flag ) { /* core-coder-VAD handle */ - if ( ( *hSpar )->hCoreCoderVAD != NULL ) + IF( ( *hSpar )->hCoreCoderVAD != NULL ) { - destroy_core_enc( ( *hSpar )->hCoreCoderVAD ); + destroy_core_enc_fx( ( *hSpar )->hCoreCoderVAD ); ( *hSpar )->hCoreCoderVAD = NULL; } /* front-VAD handle */ - if ( ( *hSpar )->hFrontVad != NULL ) + IF( ( *hSpar )->hFrontVad != NULL ) { - front_vad_destroy( &( *hSpar )->hFrontVad ); + front_vad_destroy_fx( &( *hSpar )->hFrontVad ); ( *hSpar )->hFrontVad = NULL; } } num_chans = ( *hSpar )->hFbMixer->fb_cfg->num_in_chans; + move16(); assert( num_chans <= nchan_inp ); /* MD handle */ ivas_spar_md_enc_close_fx( &( *hSpar )->hMdEnc ); /* Covar. State handle */ -#ifdef IVAS_FLOAT_FIXED ivas_spar_covar_enc_close_fx( &( *hSpar )->hCovEnc, num_chans ); -#else - ivas_spar_covar_enc_close( &( *hSpar )->hCovEnc, num_chans ); -#endif /* FB mixer handle */ ivas_FB_mixer_close_fx( &( *hSpar )->hFbMixer, input_Fs, spar_reconfig_flag ); /* AGC */ -#ifdef IVAS_FLOAT_FIXED ivas_spar_agc_enc_close_fx( &( *hSpar )->hAgcEnc ); -#else - ivas_spar_agc_enc_close( &( *hSpar )->hAgcEnc ); -#endif /* PCA */ - if ( ( *hSpar )->hPCA != NULL ) + IF( ( *hSpar )->hPCA != NULL ) { free( ( *hSpar )->hPCA ); ( *hSpar )->hPCA = NULL; } - if ( !spar_reconfig_flag ) + IF( !spar_reconfig_flag ) { /* Trans Det handle */ -#ifdef IVAS_FLOAT_FIXED ivas_transient_det_close_fx( &( *hSpar )->hTranDet ); -#else - ivas_transient_det_close( &( *hSpar )->hTranDet ); -#endif free( ( *hSpar ) ); ( *hSpar ) = NULL; } diff --git a/lib_enc/ivas_spar_md_enc.c b/lib_enc/ivas_spar_md_enc.c index 2c75c4f98..8ca0113c3 100644 --- a/lib_enc/ivas_spar_md_enc.c +++ b/lib_enc/ivas_spar_md_enc.c @@ -293,6 +293,7 @@ void ivas_spar_md_enc_close_fx( Word16 num_channels, i, j; ivas_spar_md_enc_state_t *hMdEnc; + test(); IF( hMdEnc_in == NULL || *hMdEnc_in == NULL ) { return; diff --git a/lib_enc/ivas_stat_enc.h b/lib_enc/ivas_stat_enc.h index e154ab7ca..da7514f9d 100644 --- a/lib_enc/ivas_stat_enc.h +++ b/lib_enc/ivas_stat_enc.h @@ -1587,7 +1587,6 @@ typedef struct mct_enc_data_structure int16_t bitsChannelPairIndex; /* bits needed to code channel pair index, depends on number of active channels */ MCT_BLOCK_DATA_HANDLE hBlockData[MCT_MAX_BLOCKS]; - float lastxCorrMatrix[MCT_MAX_CHANNELS][MCT_MAX_CHANNELS]; #ifdef IVAS_FLOAT_FIXED Word32 lastxCorrMatrix_fx[MCT_MAX_CHANNELS][MCT_MAX_CHANNELS]; Word16 lastxCorrMatrix_e; diff --git a/lib_enc/ivas_stereo_switching_enc.c b/lib_enc/ivas_stereo_switching_enc.c index c8c0fdc95..e6c8341a8 100644 --- a/lib_enc/ivas_stereo_switching_enc.c +++ b/lib_enc/ivas_stereo_switching_enc.c @@ -463,7 +463,7 @@ ivas_error stereo_memory_enc_fx( IF( hCPE->hCoreCoder[1]->hFdCngEnc != NULL ) { - deleteFdCngEnc( &hCPE->hCoreCoder[1]->hFdCngEnc ); + deleteFdCngEnc_fx( &hCPE->hCoreCoder[1]->hFdCngEnc ); } } diff --git a/lib_enc/nois_est_fx.c b/lib_enc/nois_est_fx.c index 1bfc4a4bf..d5f2028f0 100644 --- a/lib_enc/nois_est_fx.c +++ b/lib_enc/nois_est_fx.c @@ -51,8 +51,10 @@ #define LN_E_MIN_PLUS_ONE_FX 1 /* max(1, ln(E_MIN+1.0)) = max(1,ln(0.0035f+1f)) in Q8 */ #define COR_MAX_NNE_FX 27853 /* 0.85 Q15 */ -#define HE_LT_THR1_FX 2560 /*10.0 Q8*/ -#define HE_LT_THR2_FX 7680 /*30.0 Q8*/ +#define HE_LT_THR1_FX 2560 /*10.0 Q8*/ +#define HE_LT_THR2_FX 7680 /*30.0 Q8*/ +#define HE_LT_THR1_Q24 167772160 /*10.0 Q24 */ +#define HE_LT_THR2_Q24 503316480 /*30.0 Q24 */ /*-----------------------------------------------------------------* * noise_est_AR1_Qx() @@ -224,20 +226,7 @@ void noise_est_init_fx( move16(); hNoiseEst->lt_aEn_zero_fx = 0; move16(); - hNoiseEst->Etot_h_32fx = 0; - move32(); - hNoiseEst->Etot_l_32fx = 0; - move32(); - hNoiseEst->Etot_l_lp_32fx = 0; - move32(); - hNoiseEst->Etot_last_32fx = 0; - move32(); - hNoiseEst->Etot_v_h2_32fx = 0; - move32(); - hNoiseEst->Etot_lp_32fx = 0; - move32(); - hNoiseEst->sign_dyn_lp_32fx = 0; - move32(); + /* Tonal detector */ FOR( i = 0; i < L_FFT / 2; i++ ) { @@ -293,12 +282,6 @@ void noise_est_init_ivas_fx( hNoiseEst->harm_cor_cnt = 0; hNoiseEst->bg_cnt = 0; hNoiseEst->low_tn_track_cnt = 0; - - hNoiseEst->Etot_lp = 0.0f; - hNoiseEst->Etot_l_lp = 0.0f; - hNoiseEst->Etot_last = 0.0f; - hNoiseEst->Etot_v_h2 = 0.0f; - hNoiseEst->sign_dyn_lp = 0.0f; #endif FOR( i = 0; i < NB_BANDS; i++ ) { @@ -358,20 +341,7 @@ void noise_est_init_ivas_fx( move16(); hNoiseEst->lt_aEn_zero_fx = 0; move16(); - hNoiseEst->Etot_h_32fx = 0; - move32(); - hNoiseEst->Etot_l_32fx = 0; - move32(); - hNoiseEst->Etot_l_lp_32fx = 0; - move32(); - hNoiseEst->Etot_last_32fx = 0; - move32(); - hNoiseEst->Etot_v_h2_32fx = 0; - move32(); - hNoiseEst->Etot_lp_32fx = 0; - move32(); - hNoiseEst->sign_dyn_lp_32fx = 0; - move32(); + /* Tonal detector */ FOR( i = 0; i < L_FFT / 2; i++ ) { @@ -514,83 +484,82 @@ void noise_est_pre_fx( } void noise_est_pre_32fx( - const Word32 Etot, /* i : Energy of current frame */ - const Word16 ini_frame_fx, /* i : Frame number (init) */ - NOISE_EST_HANDLE hNoiseEst, /* i/o: Noise estimation handle */ - const int16_t idchan, /* i : channel ID */ - const int16_t element_mode, /* i : element mode */ - const int16_t last_element_mode /* i : last element mode */ + const Word32 Etot, /* i : Energy of current frame Q24 */ + const Word16 ini_frame_fx, /* i : Frame number (init) */ + NOISE_EST_HANDLE hNoiseEst, /* i/o: Noise estimation handle */ + const Word16 idchan, /* i : channel ID */ + const Word16 element_mode, /* i : element mode */ + const Word16 last_element_mode /* i : last element mode */ ) { Word32 tmp; + Word32 Etot_h_32fx; + Word32 Etot_l_32fx; + Word32 Etot_lp_32fx; + test(); + test(); + test(); IF( LE_16( ini_frame_fx, 1 ) || ( EQ_16( idchan, 1 ) && EQ_16( element_mode, IVAS_CPE_TD ) && EQ_16( last_element_mode, IVAS_CPE_DFT ) ) ) { - hNoiseEst->Etot_h_32fx = Etot; - move16(); - hNoiseEst->Etot_l_32fx = Etot; - move16(); - hNoiseEst->Etot_l_lp_32fx = Etot; - move16(); - hNoiseEst->Etot_last_32fx = Etot; + Etot_h_32fx = Etot; + move32(); + Etot_l_32fx = Etot; + move32(); + hNoiseEst->Etot_l_lp_fx = extract_h( Etot ); // Q8 move16(); - hNoiseEst->Etot_v_h2_32fx = 0; + hNoiseEst->Etot_last_fx = extract_h( Etot ); // Q8 move16(); - hNoiseEst->Etot_lp_32fx = Etot; + hNoiseEst->Etot_v_h2_fx = 0; move16(); - hNoiseEst->sign_dyn_lp_32fx = 0; + Etot_lp_32fx = Etot; + move32(); + hNoiseEst->sign_dyn_lp_fx = 0; move16(); } ELSE { /* *Etot_lp = 0.20f*Etot + 0.80f* *Etot_lp; */ - hNoiseEst->Etot_lp_32fx = L_add( Mpy_32_32( 429496730, Etot ), Mpy_32_32( 1717986918, hNoiseEst->Etot_lp_32fx ) ); - move16(); - - hNoiseEst->Etot_h_32fx = L_sub( hNoiseEst->Etot_h_32fx, 671089 ); - move16(); /* 10=0.04 in Q8 */ - hNoiseEst->Etot_h_32fx = L_max( hNoiseEst->Etot_h_32fx, Etot ); - move16(); - hNoiseEst->Etot_l_32fx = L_add( hNoiseEst->Etot_l_32fx, 1342177 ); - move16(); /* 20 = .08 in Q8 */ + Etot_lp_32fx = L_add( Mpy_32_32( 429496730 /* 0.2 in Q31 */, Etot ), Mpy_32_32( 1717986918 /* 0.8 in Q31 */, L_deposit_h( hNoiseEst->Etot_lp_fx ) ) ); + Etot_h_32fx = L_sub( L_deposit_h( hNoiseEst->Etot_h_fx ), 671089 ); /* 671089=0.04 in Q24 */ + Etot_h_32fx = L_max( Etot_h_32fx, Etot ); + Etot_l_32fx = L_add( L_deposit_h( hNoiseEst->Etot_l_fx ), 1342177 ); /* 1342177 = .08 in Q24 */ /* Could even be higher but it also delays first entry to DTX */ IF( GT_16( hNoiseEst->harm_cor_cnt, HE_LT_CNT_PRE_FX ) ) { test(); - IF( ( LT_16( ini_frame_fx, s_min( HE_LT_CNT_INIT_FX, MAX_FRAME_COUNTER - 1 ) ) ) && ( LT_32( L_sub( hNoiseEst->Etot_h_32fx, hNoiseEst->Etot_lp_32fx ), (Word32) 3 * 16777216 ) ) /* 3.0 Q8 */ + IF( ( LT_16( ini_frame_fx, s_min( HE_LT_CNT_INIT_FX, MAX_FRAME_COUNTER - 1 ) ) ) && ( LT_32( L_sub( Etot_h_32fx, Etot_lp_32fx ), (Word32) 3 * ONE_IN_Q24 ) ) /* 3.0 Q24 */ ) { /* *Etot_l += min(2,(*Etot_last-*Etot_l)*0.1f); */ - tmp = Mpy_32_32( L_sub( hNoiseEst->Etot_last_32fx, hNoiseEst->Etot_l_32fx ), 214748365 ); /* factor in Q15 3277 .1*32768 */ - tmp = L_min( 33554432, tmp ); /* 2.0 in Q8 is 512*/ - hNoiseEst->Etot_l_32fx = L_add( hNoiseEst->Etot_l_32fx, tmp ); - move16(); /* Q8 */ + tmp = Mpy_32_32( L_sub( L_deposit_h( hNoiseEst->Etot_last_fx ), Etot_l_32fx ), 214748365 ); /* 0.1f factor in Q31 */ + tmp = L_min( 33554432, tmp ); /* 2.0 in Q24 is 33554432 */ + Etot_l_32fx = L_add( Etot_l_32fx, tmp ); /* Q24 */ } /* Avoids large steps in short active segments */ test(); - IF( ( GT_32( L_sub( hNoiseEst->Etot_last_32fx, hNoiseEst->Etot_l_32fx ), 503316480 ) ) /* 30.0f*Q8 */ + IF( ( GT_32( L_sub( L_deposit_h( hNoiseEst->Etot_last_fx ), Etot_l_32fx ), 503316480 ) ) /* 30.0f*Q24 */ && ( GT_16( hNoiseEst->harm_cor_cnt, HE_LT_CNT_PRE_SHORT_FX ) ) ) { /* *Etot_l += (*Etot_last-*Etot_l)*0.02f; */ - hNoiseEst->Etot_l_32fx = L_add( hNoiseEst->Etot_l_32fx, Mpy_32_32( L_sub( hNoiseEst->Etot_last_32fx, hNoiseEst->Etot_l_32fx ), 42949673 ) ); - move16(); /* 0.02 = 655 Q8*/ + Etot_l_32fx = L_add( Etot_l_32fx, Mpy_32_32( L_sub( L_deposit_h( hNoiseEst->Etot_last_fx ), Etot_l_32fx ), 42949673 ) ); /* 0.02 in Q24*/ } - ELSE IF( GT_32( L_sub( hNoiseEst->Etot_last_32fx, hNoiseEst->Etot_l_32fx ), 167772160 ) ) /* 10.0 in Q8*/ + ELSE IF( GT_32( L_sub( L_deposit_h( hNoiseEst->Etot_last_fx ), Etot_l_32fx ), 167772160 ) ) /* 10.0 in Q24*/ { - hNoiseEst->Etot_l_32fx = L_add( hNoiseEst->Etot_l_32fx, 1342177 ); - move16(); /* 0.08 is 20 in Q8*/ + Etot_l_32fx = L_add( Etot_l_32fx, 1342177 ); /* 0.08 in Q24*/ } } - hNoiseEst->Etot_l_32fx = L_min( hNoiseEst->Etot_l_32fx, Etot ); + Etot_l_32fx = L_min( Etot_l_32fx, Etot ); // Q24 - IF( LT_16( ini_frame_fx, 100 ) && LT_32( hNoiseEst->Etot_l_32fx, hNoiseEst->Etot_l_lp_32fx ) ) + test(); + IF( LT_16( ini_frame_fx, 100 ) && LT_32( Etot_l_32fx, L_deposit_h( hNoiseEst->Etot_l_lp_fx ) ) ) { /**Etot_l_lp = 0.1f * *Etot_l + (1.0f - 0.1) * *Etot_l_lp; */ - hNoiseEst->Etot_l_lp_32fx = L_add( Mpy_32_32( 214748364, hNoiseEst->Etot_l_32fx ), Mpy_32_32( 1932735283, hNoiseEst->Etot_l_lp_32fx ) ); + hNoiseEst->Etot_l_lp_fx = extract_h( L_add( Mpy_32_32( 214748364 /* 0.1f in Q31*/, Etot_l_32fx ), Mpy_32_32( 1932735283 /* 0.9f in Q31*/, L_deposit_h( hNoiseEst->Etot_l_lp_fx ) ) ) ); // Q8 move16(); } ELSE @@ -599,22 +568,31 @@ void noise_est_pre_32fx( test(); test(); test(); - IF( ( ( GT_16( hNoiseEst->harm_cor_cnt, HE_LT_CNT_FX ) ) && ( GT_32( L_sub_sat( hNoiseEst->Etot_last_32fx, hNoiseEst->Etot_l_32fx ), 503316480 ) ) ) || ( ( sub( hNoiseEst->harm_cor_cnt, HE_LT_CNT_FX ) > 0 ) && ( LT_16( ini_frame_fx, HE_LT_CNT_INIT_FX ) ) ) || ( GT_32( L_sub_sat( hNoiseEst->Etot_l_lp_32fx, hNoiseEst->Etot_l_32fx ), 503316480 ) ) ) + IF( ( ( GT_16( hNoiseEst->harm_cor_cnt, HE_LT_CNT_FX ) ) && ( GT_32( L_sub_sat( L_deposit_h( hNoiseEst->Etot_last_fx ), Etot_l_32fx ), HE_LT_THR2_Q24 ) ) ) || ( ( sub( hNoiseEst->harm_cor_cnt, HE_LT_CNT_FX ) > 0 ) && ( LT_16( ini_frame_fx, HE_LT_CNT_INIT_FX ) ) ) || ( GT_32( L_sub_sat( L_deposit_h( hNoiseEst->Etot_l_lp_fx ), Etot_l_32fx ), HE_LT_THR2_Q24 ) ) ) { /**Etot_l_lp = 0.03f * *Etot_l + (1.0f - 0.03f) * *Etot_l_lp; */ - hNoiseEst->Etot_l_lp_32fx = L_add( Mpy_32_32( 64424509, hNoiseEst->Etot_l_32fx ), Mpy_32_32( 2083059139, hNoiseEst->Etot_l_lp_32fx ) ); + hNoiseEst->Etot_l_lp_fx = extract_h( L_add( Mpy_32_32( 64424509 /* 0.03f in Q31*/, Etot_l_32fx ), Mpy_32_32( 2083059139 /* 0.97f in Q31*/, L_deposit_h( hNoiseEst->Etot_l_lp_fx ) ) ) ); // Q8 move16(); } ELSE { /* *Etot_l_lp = 0.02f * *Etot_l + (1.0f - 0.02f) * *Etot_l_lp; */ - hNoiseEst->Etot_l_lp_32fx = L_add( Mpy_32_32( 42949673, hNoiseEst->Etot_l_32fx ), Mpy_32_32( 2104533975, hNoiseEst->Etot_l_lp_32fx ) ); + hNoiseEst->Etot_l_lp_fx = extract_h( L_add( Mpy_32_32( 42949673 /* 0.02f in Q31*/, Etot_l_32fx ), Mpy_32_32( 2104533975 /* 0.98f in Q31*/, L_deposit_h( hNoiseEst->Etot_l_lp_fx ) ) ) ); // Q8 + move16(); } } /**sign_dyn_lp = 0.1f * (*Etot_h - *Etot_l) + (1.0f - 0.1f) * *sign_dyn_lp;*/ - hNoiseEst->sign_dyn_lp_32fx = L_add( Mpy_32_32( 214748365, L_sub_sat( hNoiseEst->Etot_h_32fx, hNoiseEst->Etot_l_32fx ) ), Mpy_32_32( 1932735283, hNoiseEst->sign_dyn_lp_32fx ) ); + hNoiseEst->sign_dyn_lp_fx = extract_h( L_add( Mpy_32_32( 214748365 /* 0.1f in Q31*/, L_sub_sat( Etot_h_32fx, Etot_l_32fx ) ), Mpy_32_32( 1932735283 /*( 1.0f - 0.1f ) in Q31*/, L_deposit_h( hNoiseEst->sign_dyn_lp_fx ) ) ) ); // Q8 + move16(); } + hNoiseEst->Etot_l_fx = extract_h( Etot_l_32fx ); // Q8 + hNoiseEst->Etot_h_fx = extract_h( Etot_h_32fx ); // Q8 + hNoiseEst->Etot_lp_fx = extract_h( Etot_lp_32fx ); // Q8 + move16(); + move16(); + move16(); + return; } /*==================================================================================*/ diff --git a/lib_enc/prot_fx_enc.h b/lib_enc/prot_fx_enc.h index 057372853..c126c56e9 100644 --- a/lib_enc/prot_fx_enc.h +++ b/lib_enc/prot_fx_enc.h @@ -428,9 +428,9 @@ void noise_est_pre_fx( ); void noise_est_pre_32fx( - const Word32 Etot, /* i : Energy of current frame */ - const Word16 ini_frame_fx, /* i : Frame number (init) */ - NOISE_EST_HANDLE hNoiseEst, /* i/o: Noise estimation handle */ + const Word32 Etot, /* i : Energy of current frame Q24 */ + const Word16 ini_frame_fx, /* i : Frame number (init) */ + NOISE_EST_HANDLE hNoiseEst, /* i/o: Noise estimation handle */ const Word16 idchan, /* i : channel ID */ const Word16 element_mode, /* i : element mode */ const Word16 last_element_mode /* i : last element mode */ diff --git a/lib_enc/rom_enc.c b/lib_enc/rom_enc.c index c8fe848f5..7e6b1cf11 100644 --- a/lib_enc/rom_enc.c +++ b/lib_enc/rom_enc.c @@ -539,23 +539,32 @@ const float means_speech[N_SMC_MIXTURES*N_PCA_COEF] = #ifdef IVAS_FLOAT_FIXED const Word32 means_speech_fx[N_SMC_MIXTURES*N_PCA_COEF] = { - //Q27 - 556269120, -59860300, -9435775, 48301740, -5395016, -15873260, 86538896, -23373078, --15379338, 88411368, 37326888, -35021164, -4035256, -161975568, 85803920, -81899120, --7169642, 64167884, -82728320, -29112898, 81431240, 15287399, -468956, 29038140, --256403904, -208488720, 86349912, 56074020, 36843036, 19549348, 1753688, -32431970, -29630308, 14530545, -8338545, 4083037, 253332208, -116034448, -127942512, -33905276, -8696369, -14094204, -30782970, 37237904, 4475893, -12044833, -4461531, 2582617, --55476752, -239552208, -25126230, -52574964, -32635712, -29946256, -2421556, 17400254, -18426080, -6647267, 3984253, -3254377, -93225080, -235751824, 80155632, 138254992, -39954200, 51441360, 18226768, -23774524, 12971472, -36022428, -20379082, -13683497, + //Q20 + 4345853, +-467659, -73717, 377357, -42149, -124010, 676085, -182602, -120151, +690714, 291616, -273603, -31525, -1265434, 670343, -639837, -56013, +501312, -646315, -227445, 636182, 119433, -3664, 226860, -2003156, +-1628818, 674609, 438078, 287836, 152729, 13701, -253375, 231487, +113520, -65145, 31899, 1979158, -906519, -999551, -264885, 67940, +-110111, -240492, 290921, 34968, -94100, -34856, 20177, -433412, +-1871502, -196299, -410742, -254967, -233955, -18918, 135939, 143954, +-51932, 31127, -25425, -728321, -1841811, 626216, 1080117, 312142, +401886, 142397, -185738, 101340, -281425, -159212, -106902, }; #endif const float log_det_chol_speech[N_SMC_MIXTURES] = { 6.500575f, 5.852711f, 5.579274f, 6.652653f, 4.752021f, 5.338445f, }; - +const Word32 log_det_chol_speech_fx[N_SMC_MIXTURES] = +{//Q19 + 3408173, + 3068506, + 2925146, + 3487906, + 2491427, + 2798882, +}; const float prec_chol_speech[N_SMC_MIXTURES*(N_PCA_COEF*N_PCA_COEF + N_PCA_COEF) / 2] = { 0.865878f, -0.223069f, 1.134475f, -0.467260f, 0.369334f, 1.214700f, -0.211695f, 0.172669f, 0.139801f, 1.227951f, 0.116632f, -0.073137f, 0.119470f, 0.215339f, 1.501916f, 0.013243f, 0.241111f, -0.233638f, 0.209664f, -0.018477f, 1.781218f, -0.379717f, -0.055418f, 0.148630f, -0.151909f, -0.176478f, 0.700080f, 1.271311f, 0.079390f, -0.578062f, 0.405159f, -0.535997f, -0.075627f, -0.020922f, 0.275374f, 2.125945f, 0.814927f, -0.606386f, -0.240098f, -0.027454f, -0.137439f, -0.139499f, -0.299115f, 0.030554f, 2.224794f, -0.568133f, -0.955587f, -0.171094f, -0.289375f, -0.522709f, -0.635692f, -0.351548f, 0.418509f, 0.752386f, 2.817156f, -0.775162f, 0.841142f, 0.217873f, 0.245892f, -0.180432f, 0.026225f, -0.382074f, 0.147919f, -1.265659f, -0.335493f, 2.967484f, 0.754874f, 0.141008f, 0.037836f, 0.308811f, 0.275340f, -0.452874f, -0.553189f, -0.418168f, 0.103281f, 0.201651f, 0.314494f, 3.377585f, @@ -649,16 +658,17 @@ const float means_music[N_SMC_MIXTURES*N_PCA_COEF] = #ifdef IVAS_FLOAT_FIXED const Word32 means_music_fx[N_SMC_MIXTURES*N_PCA_COEF] = { - //Q27 - 88128840, 204692912, 12705453, 71462352, 12596468, 40563280, -1386066, -52265056, --39146480, -6666997, 9846481, 10781844, -57806772, -1044348, 8851928, -134822384, --26193530, -61436556, 53966400, 37307696, -3429397, 19347082, 13950591, -11268518, --48344556, 197877728, -36032360, -8134399, -1136958, -20838778, -32593702, 16027207, --26324122, -40342764, -3959959, 8085410, -332178944, 164642336, -341718, 34049964, --15855543, 8985877, 22481872, 6408225, -40554556, 2538594, 4626216, 1585111, --126774552, 174976704, 43837656, 59459124, 45605440, 47483012, 108907616, -26984474, -7563974, 110854584, 57102664, -53801580, 324371776, 133068016, -33550808, -35531324, --528952, -32556524, -15345650, 24060810, 11499641, -221325, -35890224, 3875939, + //Q20 + 688507, +1599163, 99261, 558300, 98410, 316901, -10829, -408321, -305832, +-52086, 76926, 84233, -451615, -8159, 69156, -1053300, -204637, +-479973, 421613, 291466, -26792, 151149, 108989, -88035, -377692, +1545920, -281503, -63550, -8882, -162803, -254638, 125213, -205657, +-315178, -30937, 63167, -2595148, 1286268, -2670, 266015, -123871, +70202, 175640, 50064, -316832, 19833, 36142, 12384, -990426, +1367006, 342482, 464524, 356293, 370961, 850841, -210816, 59094, +866051, 446115, -420325, 2534155, 1039594, -262116, -277588, -4132, +-254348, -119888, 187975, 89841, -1729, -280392, 30281, }; #endif const float log_det_chol_music[N_SMC_MIXTURES] = @@ -666,6 +676,15 @@ const float log_det_chol_music[N_SMC_MIXTURES] = 3.236255f, 3.517110f, 5.675361f, 2.875446f, -2.234983f, 7.961542f, }; +const Word32 log_det_chol_music_fx[N_SMC_MIXTURES] = +{//Q19 + 1696729, + 1843978, + 2975523, + 1507561, + -1171774, + 4174141, +}; const float prec_chol_music[N_SMC_MIXTURES*(N_PCA_COEF*N_PCA_COEF + N_PCA_COEF) / 2] = { 0.865468f, 0.096250f, 0.875676f, -0.081846f, -0.330935f, 1.076934f, 0.141790f, 0.047793f, 0.095596f, 0.805507f, 0.014703f, 0.133837f, -0.185849f, 0.065923f, 0.878885f, -0.023521f, -0.109075f, 0.293645f, -0.004503f, 0.103060f, 1.017106f, -0.140600f, -0.264764f, 0.386274f, -0.037347f, -0.140433f, -0.230523f, 1.476784f, -0.097932f, 0.056998f, -0.001711f, -0.088553f, 0.012943f, -0.094897f, 0.176247f, 1.239658f, 0.145315f, 0.034242f, -0.028931f, -0.132416f, 0.080181f, 0.025223f, -0.464244f, 0.005253f, 1.895192f, -0.096706f, -0.029121f, 0.072887f, 0.005231f, -0.191996f, -0.169344f, 0.616334f, -0.105826f, -0.302582f, 2.184961f, -0.173989f, -0.194028f, 0.036340f, -0.116044f, -0.145628f, -0.150018f, 0.249165f, 0.112598f, 0.374794f, 0.091387f, 2.450082f, 0.253605f, 0.179610f, -0.178889f, 0.182902f, -0.015903f, 0.219889f, -0.718143f, -0.189849f, -0.115940f, -0.439124f, -0.679777f, 2.330453f, @@ -759,23 +778,32 @@ const float means_noise[N_SMC_MIXTURES*N_PCA_COEF] = #ifdef IVAS_FLOAT_FIXED const Word32 means_noise_fx[N_SMC_MIXTURES*N_PCA_COEF] = { - //Q27 - 139344176, 85522728, -140739360, -127496240, -11822971, -83343840, -30885916, 128914920, -55142280, 43453528, -85148664, 1472368, -161889936, -113373848, -98158928, -153415568, --42456556, -57162792, 60016264, 208695008, -13554783, 127521472, -30868064, -26999372, -178972768, 74413936, -168077904, -33409476, 6877316, -59676692, -21294850, 147021424, -33076482, 7783688, -105503456, 23490786, 165446160, 44187832, -118290112, -7072334, -20942126, -40746756, -14936017, 106057376, 17580778, 8650601, -64193252, 13850330, --267202400, -97157928, -160526960, -237423248, -46269548, -90877888, -34388460, 181443312, --47476032, 103093176, -51608460, -49874636, -282058432, -173686864, -25287426, -247458976, --105534592, -72460928, 32371168, 214770112, -40301020, 164500864, 10863583, -31030468, + //Q20 + 1088626, +668146, -1099526, -996064, -92367, -651124, -241296, 1007148, 430799, +339481, -665224, 11503, -1264765, -885733, -766867, -1198559, -331692, +-446584, 468877, 1630430, -105897, 996262, -241157, -210933, 1398225, +581359, -1313109, -261012, 53729, -466224, -166366, 1148605, 258410, +60810, -824246, 183522, 1292548, 345217, -924142, -55253, 163610, +-318334, -116688, 828573, 137350, 67583, -501510, 108206, -2087519, +-759046, -1254117, -1854869, -361481, -709984, -268660, 1417526, -370907, +805415, -403191, -389646, -2203582, -1356929, -197558, -1933273, -824489, +-566101, 252900, 1677892, -314852, 1285163, 84872, -242426, }; #endif const float log_det_chol_noise[N_SMC_MIXTURES] = { 11.878154f, 13.025598f, 12.831137f, 7.099546f, 13.242941f, 11.898383f, }; - +const Word32 log_det_chol_noise_fx[N_SMC_MIXTURES] = +{//Q19 + 6227573, + 6829164, + 6727211, + 3722206, + 6943115, + 6238179, +}; const float prec_chol_noise[N_SMC_MIXTURES*(N_PCA_COEF*N_PCA_COEF + N_PCA_COEF) / 2] = { 1.632699f, -0.379077f, 1.966804f, -0.344223f, -0.149261f, 2.120968f, -0.643124f, 0.344982f, 0.335749f, 1.870530f, -0.261820f, 0.059065f, 0.158862f, -0.280203f, 2.457868f, 0.081479f, 0.745744f, -0.249165f, -0.769764f, -1.012361f, 2.160652f, -0.156229f, 0.672157f, -0.261424f, 0.116279f, -0.228307f, -0.056947f, 3.407241f, 0.356097f, -0.736238f, 0.705233f, -1.408321f, -0.717390f, -1.037433f, 0.333510f, 2.484870f, 0.323039f, -1.483297f, -0.500337f, -0.090107f, -0.439007f, -0.290405f, 0.327256f, -0.243020f, 2.511947f, 0.442037f, 0.525936f, -1.436016f, 0.336699f, 0.176533f, -0.643667f, 0.793828f, -0.342947f, 0.672485f, 4.147797f, 0.332162f, 0.594025f, -1.072022f, 0.522281f, 0.199482f, 0.046997f, 0.786233f, -0.726740f, -1.173474f, 0.744190f, 3.950012f, -0.607163f, -0.630364f, 1.025563f, -0.779746f, -0.553567f, 0.336951f, -1.148469f, 0.489795f, 0.770505f, -1.178058f, -0.433118f, 6.111872f, diff --git a/lib_enc/rom_enc.h b/lib_enc/rom_enc.h index 87537fc80..42b1f408c 100644 --- a/lib_enc/rom_enc.h +++ b/lib_enc/rom_enc.h @@ -135,11 +135,14 @@ extern const Word32 bcox_add_cnst_fx[N_SMC_FEATURES]; extern const Word32 prec_chol_speech_fx[]; extern const Word32 prec_chol_music_fx[]; extern const Word32 prec_chol_noise_fx[]; -extern const Word32 means_speech_fx[]; -extern const Word32 means_music_fx[]; -extern const Word32 means_noise_fx[]; +extern const Word32 means_speech_fx[];//Q20 +extern const Word32 means_music_fx[];//Q20 +extern const Word32 means_noise_fx[];//Q20 extern const Word32 mel_fb_fx[]; extern const Word32 dct_mtx_fx[]; +extern const Word32 log_det_chol_speech_fx[];//Q19 +extern const Word32 log_det_chol_music_fx[];//Q19 +extern const Word32 log_det_chol_noise_fx[];//Q19 #endif extern const float log_det_chol_speech[]; extern const float prec_chol_music[]; diff --git a/lib_enc/speech_music_classif_fx.c b/lib_enc/speech_music_classif_fx.c index 2453ebf94..cc240abe4 100644 --- a/lib_enc/speech_music_classif_fx.c +++ b/lib_enc/speech_music_classif_fx.c @@ -73,28 +73,28 @@ static void order_spectrum_fx( Word16 *vec, Word16 len ); static void detect_sparseness_fx( Encoder_State *st_fx, const Word16 localVAD_HE_SAD, const Word16 voi_fv ); // Q19 Word32 log_weights_speech_compute[N_SMC_MIXTURES] = { - -3529378, - -3679759, - -3803054, - -3229859, - -4048972, - -3929047, + -1156091, + -966805, + -946740, + -936304, + -758939, + -946469, }; Word32 log_weights_music_compute[N_SMC_MIXTURES] = { - -5058325, - -4983143, - -3436984, - -5133896, - -8505198, - -2561831, + -973594, + -1045660, + -631047, + -859997, + -1551963, + -954511, }; Word32 log_weights_noise_compute[N_SMC_MIXTURES] = { - -433769, - -105783, - 407264, - -3350157, - 103199, - -627672, + -879882, + -1153486, + -538486, + -1290903, + -1058455, + -1084391, }; /*---------------------------------------------------------------------* * speech_music_clas_init_fx() @@ -2304,43 +2304,27 @@ Word16 ivas_smc_gmm_fx( move32(); move32(); move32(); + FOR( m = 0; m < N_SMC_MIXTURES; m++ ) { - Word32 temp[N_PCA_COEF]; - FOR( Word16 ind = 0; ind < N_PCA_COEF; ind++ ) - { - temp[ind] = L_shr( means_speech_fx[m * N_PCA_COEF + ind], sub( 27, Qfact_FV ) ); - move32(); - } - v_sub32_fx( FV_fx, temp, fvm_fx, N_PCA_COEF ); + v_sub32_fx( FV_fx, &means_speech_fx[m * N_PCA_COEF], fvm_fx, N_PCA_COEF ); fvm_exp = sub( 31, Qfact_FV ); lprob_exp = 0; move16(); lprob_fx = dot_product_cholesky_fixed( fvm_fx, &prec_chol_speech_fx[m * ( N_PCA_COEF * N_PCA_COEF + N_PCA_COEF ) / 2], N_PCA_COEF, fvm_exp, 31 - 28, &lprob_exp ); - ps_fx[m] = L_sub( log_weights_speech_compute[m], L_shl( lprob_fx, sub( Q19 - 1, sub( Q31, lprob_exp ) ) ) ); + ps_fx[m] = L_sub( L_sub( L_add( log_weights_speech_compute[m], log_det_chol_speech_fx[m] ), L_shl( lprob_fx, sub( Q19 - 1, sub( Q31, lprob_exp ) ) ) ), HALF_N_PCA_COEF_LOG_P12_Q19 ); // Q19 move32(); - FOR( Word16 ind = 0; ind < N_PCA_COEF; ind++ ) - { - temp[ind] = L_shr( means_music_fx[m * N_PCA_COEF + ind], sub( 27, Qfact_FV ) ); - move32(); - } - v_sub32_fx( FV_fx, temp, fvm_fx, N_PCA_COEF ); + v_sub32_fx( FV_fx, &means_music_fx[m * N_PCA_COEF], fvm_fx, N_PCA_COEF ); lprob_exp = 0; move16(); lprob_fx = dot_product_cholesky_fixed( fvm_fx, &prec_chol_music_fx[m * ( N_PCA_COEF * N_PCA_COEF + N_PCA_COEF ) / 2], N_PCA_COEF, fvm_exp, 31 - 28, &lprob_exp ); - pm_fx[m] = L_sub( log_weights_music_compute[m], L_shl( lprob_fx, sub( Q19 - 1, sub( Q31, lprob_exp ) ) ) ); + pm_fx[m] = L_sub( L_sub( L_add( log_weights_music_compute[m], log_det_chol_music_fx[m] ), L_shl( lprob_fx, sub( Q19 - 1, sub( Q31, lprob_exp ) ) ) ), HALF_N_PCA_COEF_LOG_P12_Q19 ); // Q19 move32(); - FOR( Word16 ind = 0; ind < N_PCA_COEF; ind++ ) - { - temp[ind] = L_shr( means_noise_fx[m * N_PCA_COEF + ind], sub( 27, Qfact_FV ) ); - move32(); - } - v_sub32_fx( FV_fx, temp, fvm_fx, N_PCA_COEF ); - + v_sub32_fx( FV_fx, &means_noise_fx[m * N_PCA_COEF], fvm_fx, N_PCA_COEF ); lprob_exp = 0; move16(); lprob_fx = dot_product_cholesky_fixed( fvm_fx, &prec_chol_noise_fx[m * ( N_PCA_COEF * N_PCA_COEF + N_PCA_COEF ) / 2], N_PCA_COEF, fvm_exp, 31 - 28, &lprob_exp ); - pn_fx[m] = L_sub( log_weights_noise_compute[m], L_shl( lprob_fx, sub( Q19 - 1, sub( Q31, lprob_exp ) ) ) ); + pn_fx[m] = L_sub( L_sub( L_add( log_weights_noise_compute[m], log_det_chol_noise_fx[m] ), L_shl( lprob_fx, sub( Q19 - 1, sub( Q31, lprob_exp ) ) ) ), HALF_N_PCA_COEF_LOG_P12_Q19 ); // Q19 move32(); } diff --git a/lib_enc/stat_enc.h b/lib_enc/stat_enc.h index d067986e2..d5fbcc018 100644 --- a/lib_enc/stat_enc.h +++ b/lib_enc/stat_enc.h @@ -786,24 +786,24 @@ typedef struct noise_estimation_structure Word32 bckr_fx[NB_BANDS]; /* Q_new + Q_SCALE Noise estimator - background noise estimation per critical band */ Word32 ave_enr_fx[NB_BANDS]; /* Q_new + Q_SCALE Noise estimator - long-term average energy per critical band */ - int16_t aEn; /* Noise estimator - noise estimator adaptation flag */ + Word16 aEn; /* Noise estimator - noise estimator adaptation flag */ #ifndef IVAS_FLOAT_FIXED float totalNoise; /* Noise estimator - total noise energy */ #endif Word16 totalNoise_fx; /* Q8 Noise estimator - total noise energy */ - int16_t first_noise_updt; /* Noise estimator - flag used to determine if the first noise update frame */ - int16_t first_noise_updt_cnt; /* Noise estimator - counter of frame after first noise update */ - int16_t harm_cor_cnt; /* Noise estimator - 1st memory counter of harm or correlation frame */ - int16_t bg_cnt; /* Noise estimator - pause length counter */ + Word16 first_noise_updt; /* Noise estimator - flag used to determine if the first noise update frame */ + Word16 first_noise_updt_cnt; /* Noise estimator - counter of frame after first noise update */ + Word16 harm_cor_cnt; /* Noise estimator - 1st memory counter of harm or correlation frame */ + Word16 bg_cnt; /* Noise estimator - pause length counter */ #ifndef IVAS_FLOAT_FIXED float Etot_l; /* Noise estimator - Track energy from below */ float Etot_h; /* Noise estimator - Track energy from above */ -#endif + float Etot_l_lp; /* Noise estimator - Smoothed low energy */ float Etot_last; /* Noise estimator - Energy of last frame */ float Etot_lp; /* Noise estimator - Filtered input energy */ -#ifndef IVAS_FLOAT_FIXED + float lt_tn_track; float lt_tn_dist; float lt_Ellp_dist; @@ -815,17 +815,11 @@ typedef struct noise_estimation_structure Word16 Etot_last_fx; /*Q8*/ Word16 Etot_lp_fx; /* Q8 Noise estimator - Filtered input energy */ - Word32 Etot_l_32fx; /* Q24 Noise estimator - Track energy from below */ - Word32 Etot_h_32fx; /* Q24 Noise estimator - Track energy from above */ - Word32 Etot_l_lp_32fx; /* Q24 Noise estimator - Smoothed low energy */ - Word32 Etot_last_32fx; /*Q24*/ - Word32 Etot_lp_32fx; /* Q24 Noise estimator - Filtered input energy */ - Word16 lt_tn_track_fx; /* Q15 */ Word16 lt_tn_dist_fx; /* Q8*/ Word16 lt_Ellp_dist_fx; /* Etot low lp same domain as *Etot_l_lp, Q8 */ Word16 lt_haco_ev_fx; /* Q15 */ - int16_t low_tn_track_cnt; + Word16 low_tn_track_cnt; #ifndef IVAS_FLOAT_FIXED float epsP_0_2_lp; float epsP_0_2_ad_lp; @@ -842,22 +836,19 @@ typedef struct noise_estimation_structure Word16 epsP_2_16_dlp_lp2_fx; /* Q12 */ Word16 lt_aEn_zero_fx; /* Q15 */ +#ifndef IVAS_FLOAT_FIXED float Etot_v_h2; float sign_dyn_lp; -#ifndef IVAS_FLOAT_FIXED float Etot_st_est; /* Noise estimation - short term estimate of E{ Etot } */ float Etot_sq_st_est; /* Noise estimation - short term estimate of E{ Etot^2 } */ #endif Word16 Etot_v_h2_fx; Word16 sign_dyn_lp_fx; /*Q8*/ - Word32 Etot_v_h2_32fx; - Word32 sign_dyn_lp_32fx; /*Q8*/ - Word16 Etot_st_est_fx; /* Q8 Noise estimation - short term estimate of E{ Etot } */ Word16 Etot_sq_st_est_fx; /* Q2 Noise estimation - short term estimate of E{ Etot^2 } */ - int16_t aEn_inac_cnt; + Word16 aEn_inac_cnt; } NOISE_EST_DATA, *NOISE_EST_HANDLE; -- GitLab From bca0142f85d0a9a10da81be4d53f4b06f1773203 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Fri, 8 Nov 2024 16:07:35 +0530 Subject: [PATCH 098/128] Fix for 3GPP issue 1007: Decoder crash for ISM 3 FER, Bandwidth Switching at 96kbps, 128 kbps link: #1007 --- lib_com/swb_tbe_com_fx.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/lib_com/swb_tbe_com_fx.c b/lib_com/swb_tbe_com_fx.c index 70ab9f418..e9b9530f3 100644 --- a/lib_com/swb_tbe_com_fx.c +++ b/lib_com/swb_tbe_com_fx.c @@ -2939,19 +2939,16 @@ void GenShapedSHBExcitation_ivas_fx( } Q_pow1 = shl( *Q_bwe_exc, 1 ); - test(); -#if 1 // ADD_IVAS_TBE_CODE - IF( EQ_16( flag_ACELP16k, 0 ) ) -#else - IF( ( LE_32( bitrate, ACELP_13k20 ) ) && ( GE_32( bitrate, ACELP_7k20 ) ) ) -#endif + IF( flag_ACELP16k == 0 ) { /* varEnvShape = mean_fx(voice_factors, 4); */ /* unroll the loop */ L_tmp = L_mult( voice_factors[0], 8192 ); L_tmp = L_mac( L_tmp, voice_factors[1], 8192 ); L_tmp = L_mac( L_tmp, voice_factors[2], 8192 ); - varEnvShape = mac_r( L_tmp, voice_factors[3], 8192 ); /* varEnvShape in Q15 */ + varEnvShape = mac_r_sat( L_tmp, voice_factors[3], 8192 ); /* varEnvShape in Q15 */ + /* varEnvShape is the mean value of voice_factors (Q15) + In any case, varEnvShape is not expected to exceed 32767, hence saturation is added */ } ELSE /* 16k core */ { @@ -2961,7 +2958,9 @@ void GenShapedSHBExcitation_ivas_fx( L_tmp = L_mac( L_tmp, voice_factors[1], 6554 ); L_tmp = L_mac( L_tmp, voice_factors[2], 6554 ); L_tmp = L_mac( L_tmp, voice_factors[3], 6554 ); - varEnvShape = mac_r( L_tmp, voice_factors[4], 6554 ); /* varEnvShape in Q15 */ + varEnvShape = mac_r_sat( L_tmp, voice_factors[4], 6554 ); /* varEnvShape in Q15 */ + /* varEnvShape is the mean value of voice_factors (Q15) + In any case, varEnvShape is not expected to exceed 32767, hence saturation is added */ } IF( EQ_16( extl, FB_TBE ) ) -- GitLab From 8f64dd2f998b899ffa508faecfec2e7ef04aec06 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Fri, 8 Nov 2024 16:12:48 +0530 Subject: [PATCH 099/128] Clang formatting changes --- lib_enc/rom_enc.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib_enc/rom_enc.h b/lib_enc/rom_enc.h index 42b1f408c..27e368e2a 100644 --- a/lib_enc/rom_enc.h +++ b/lib_enc/rom_enc.h @@ -135,14 +135,14 @@ extern const Word32 bcox_add_cnst_fx[N_SMC_FEATURES]; extern const Word32 prec_chol_speech_fx[]; extern const Word32 prec_chol_music_fx[]; extern const Word32 prec_chol_noise_fx[]; -extern const Word32 means_speech_fx[];//Q20 -extern const Word32 means_music_fx[];//Q20 -extern const Word32 means_noise_fx[];//Q20 +extern const Word32 means_speech_fx[]; // Q20 +extern const Word32 means_music_fx[]; // Q20 +extern const Word32 means_noise_fx[]; // Q20 extern const Word32 mel_fb_fx[]; extern const Word32 dct_mtx_fx[]; -extern const Word32 log_det_chol_speech_fx[];//Q19 -extern const Word32 log_det_chol_music_fx[];//Q19 -extern const Word32 log_det_chol_noise_fx[];//Q19 +extern const Word32 log_det_chol_speech_fx[]; // Q19 +extern const Word32 log_det_chol_music_fx[]; // Q19 +extern const Word32 log_det_chol_noise_fx[]; // Q19 #endif extern const float log_det_chol_speech[]; extern const float prec_chol_music[]; -- GitLab From 2cca86ac23190031d4e97f8fe1bcf3d5c188bbbe Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Fri, 8 Nov 2024 16:16:42 +0530 Subject: [PATCH 100/128] Fix for 3GPP issue 993: Crash in decoder_tcx_noisefilling_fx in OMASA JBM link #993 --- lib_dec/tonalMDCTconcealment_fx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_dec/tonalMDCTconcealment_fx.c b/lib_dec/tonalMDCTconcealment_fx.c index 0a079d45d..c4fb3259e 100644 --- a/lib_dec/tonalMDCTconcealment_fx.c +++ b/lib_dec/tonalMDCTconcealment_fx.c @@ -1867,7 +1867,7 @@ void TonalMDCTConceal_InsertNoise_ivas_fx( num = L_shr( num, 1 ); // Q31- exp -1 exp = add( exp, 1 ); } - tmp = div_l( num, round_fx( den ) ); + tmp = div_l( num, extract_h( den ) ); tmp = Sqrt16( tmp, &exp ); FOR( i = 0; i < crossOverFreq; i++ ) -- GitLab From fa3f2e2445cc8b3e0099924fecc95da572095835 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Fri, 8 Nov 2024 17:30:33 +0530 Subject: [PATCH 101/128] Fix for 3GPP issue 981: Stereo decoding with JBM: energy difference in right channel despite similar TSM link: #981 --- lib_com/prot_fx.h | 8 ++++++- lib_dec/core_dec_init_fx.c | 4 ++++ lib_dec/hq_core_dec_fx.c | 14 +++++++++++++ lib_dec/ivas_core_dec.c | 8 ++++++- lib_dec/ivas_mdct_core_dec.c | 4 +--- lib_dec/ivas_tcx_core_dec.c | 9 +++++++- lib_dec/stat_dec.h | 2 ++ lib_dec/tonalMDCTconcealment_fx.c | 35 ++++++++++++++++++++++++++++--- 8 files changed, 75 insertions(+), 9 deletions(-) diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index ea3dd0530..66e80a6b3 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -6407,7 +6407,13 @@ void TonalMDCTConceal_SaveTimeSignal( TonalMDCTConcealPtr hTonalMDCTConc, Word16 *timeSignal, Word16 nNewSamples ); - +#ifdef IVAS_FLOAT_FIXED +void TonalMDCTConceal_SaveTimeSignal_ivas_fx( + TonalMDCTConcealPtr hTonalMDCTConc, + Word16 *timeSignal, + Word16 q_timeSignal, + Word16 nNewSamples ); +#endif // decision_matrix_dec_fx.c void decision_matrix_dec_fx( diff --git a/lib_dec/core_dec_init_fx.c b/lib_dec/core_dec_init_fx.c index a3c76e23c..537b586f3 100644 --- a/lib_dec/core_dec_init_fx.c +++ b/lib_dec/core_dec_init_fx.c @@ -1050,6 +1050,8 @@ void open_decoder_LPD_fx( move16(); st->tonalMDCTconceal.lastPcmOut = 0x0; move16(); + st->tonalMDCTconceal.q_lastPcmOut = Q15; + move16(); st->tonalMDCTconceal.lastBlockData.tonalConcealmentActive = 0; move16(); st->tonalMDCTconceal.lastBlockData.nSamples = 0; @@ -2121,6 +2123,8 @@ void open_decoder_LPD_ivas_fx( move16(); st->hTonalMDCTConc->lastPcmOut = 0x0; move16(); + st->hTonalMDCTConc->q_lastPcmOut = Q15; + move16(); st->hTonalMDCTConc->lastBlockData.tonalConcealmentActive = 0; move16(); st->hTonalMDCTConc->lastBlockData.nSamples = 0; diff --git a/lib_dec/hq_core_dec_fx.c b/lib_dec/hq_core_dec_fx.c index c31727f29..cc047f9d0 100644 --- a/lib_dec/hq_core_dec_fx.c +++ b/lib_dec/hq_core_dec_fx.c @@ -507,6 +507,13 @@ void hq_core_dec_fx( st_fx->plcInfo.recovery_gain = shl( st_fx->plcInfo.recovery_gain, *Q_synth ); move16(); #endif + IF( st_fx->tonalMDCTconceal.q_lastPcmOut != 0 ) + { + Scale_sig( st_fx->tonalMDCTconceal.secondLastPcmOut, shr( st_fx->plcInfo.FrameSize, 1 ), negate( st_fx->tonalMDCTconceal.q_lastPcmOut ) ); + Scale_sig( st_fx->tonalMDCTconceal.lastPcmOut, st_fx->plcInfo.FrameSize, negate( st_fx->tonalMDCTconceal.q_lastPcmOut ) ); + st_fx->tonalMDCTconceal.q_lastPcmOut = 0; + move16(); + } waveform_adj2_fix( st_fx->tonalMDCTconceal.secondLastPcmOut, synth, st_fx->plcInfo.data_noise, @@ -1136,6 +1143,13 @@ void ivas_hq_core_dec_fx( st_fx->plcInfo.recovery_gain = shl( st_fx->plcInfo.recovery_gain, *Q_synth ); #endif move16(); + IF( st_fx->tonalMDCTconceal.q_lastPcmOut != 0 ) + { + Scale_sig( st_fx->tonalMDCTconceal.secondLastPcmOut, shr( st_fx->plcInfo.FrameSize, 1 ), negate( st_fx->tonalMDCTconceal.q_lastPcmOut ) ); + Scale_sig( st_fx->tonalMDCTconceal.lastPcmOut, st_fx->plcInfo.FrameSize, negate( st_fx->tonalMDCTconceal.q_lastPcmOut ) ); + st_fx->tonalMDCTconceal.q_lastPcmOut = 0; + move16(); + } waveform_adj2_fix( st_fx->tonalMDCTconceal.secondLastPcmOut, synth, st_fx->plcInfo.data_noise, diff --git a/lib_dec/ivas_core_dec.c b/lib_dec/ivas_core_dec.c index 8d44af509..d8f9a8b90 100644 --- a/lib_dec/ivas_core_dec.c +++ b/lib_dec/ivas_core_dec.c @@ -1295,7 +1295,13 @@ ivas_error ivas_core_dec_fx( IF( EQ_16( st->core, ACELP_CORE ) && !st->bfi && st->prev_bfi && GE_32( st->last_total_brate, HQ_48k ) && EQ_16( st->last_codec_mode, MODE2 ) && ( EQ_16( st->last_core_bfi, TCX_20_CORE ) || EQ_16( st->last_core_bfi, TCX_10_CORE ) ) && EQ_16( st->hPlcInfo->concealment_method, TCX_NONTONAL ) && LT_16( st->hPlcInfo->nbLostCmpt, 4 ) ) { tmps = NS2SA_FX2( output_Fs, DELAY_CLDFB_NS ); - + IF( st->tonalMDCTconceal.q_lastPcmOut != 0 ) + { + Scale_sig( st->tonalMDCTconceal.secondLastPcmOut, shr( st->plcInfo.FrameSize, 1 ), negate( st->tonalMDCTconceal.q_lastPcmOut ) ); + Scale_sig( st->tonalMDCTconceal.lastPcmOut, st->plcInfo.FrameSize, negate( st->tonalMDCTconceal.q_lastPcmOut ) ); + st->tonalMDCTconceal.q_lastPcmOut = 0; + move16(); + } waveform_adj2_fix( st->hTonalMDCTConc->secondLastPcmOut, synth_16_fx[n] + tmps, st->plcInfo.data_noise, &st->plcInfo.outx_new_n1_fx, &st->plcInfo.nsapp_gain_fx, &st->plcInfo.nsapp_gain_n_fx, &st->plcInfo.recovery_gain, st->plcInfo.step_concealgain_fx, st->plcInfo.Pitch_fx, st->plcInfo.FrameSize, tmps, add( st->hPlcInfo->nbLostCmpt, 1 ), st->bfi ); diff --git a/lib_dec/ivas_mdct_core_dec.c b/lib_dec/ivas_mdct_core_dec.c index 0550189ac..57d08a708 100644 --- a/lib_dec/ivas_mdct_core_dec.c +++ b/lib_dec/ivas_mdct_core_dec.c @@ -2117,9 +2117,7 @@ void ivas_mdct_core_reconstruct_fx( test(); IF( ( bfi == 0 ) && st->hTonalMDCTConc != NULL ) { - Word16 synth_tmp[L_FRAME48k]; - Copy_Scale_sig( synthFB_fx, synth_tmp, st->hTonalMDCTConc->nSamples, 2 ); - TonalMDCTConceal_SaveTimeSignal( st->hTonalMDCTConc, synth_tmp, L_frameTCX[ch] ); + TonalMDCTConceal_SaveTimeSignal_ivas_fx( st->hTonalMDCTConc, synthFB_fx, q_win, L_frameTCX[ch] ); } decoder_tcx_post_ivas_fx( st, synth_fx, synthFB_fx, q_win, NULL, bfi, MCT_flag ); diff --git a/lib_dec/ivas_tcx_core_dec.c b/lib_dec/ivas_tcx_core_dec.c index 407f6d68d..4ac2bc814 100644 --- a/lib_dec/ivas_tcx_core_dec.c +++ b/lib_dec/ivas_tcx_core_dec.c @@ -710,6 +710,13 @@ void stereo_tcx_core_dec_fx( ( GE_32( st->last_total_brate, HQ_48k ) && /* recovery */ EQ_16( st->last_codec_mode, MODE2 ) ) ) { + IF( st->hTonalMDCTConc->q_lastPcmOut != 0 ) + { + Scale_sig( st->hTonalMDCTConc->secondLastPcmOut, shr( hTcxDec->L_frameTCX, 1 ), negate( st->hTonalMDCTConc->q_lastPcmOut ) ); + Scale_sig( st->hTonalMDCTConc->lastPcmOut, hTcxDec->L_frameTCX, negate( st->hTonalMDCTConc->q_lastPcmOut ) ); + st->hTonalMDCTConc->q_lastPcmOut = 0; + move16(); + } /* waveform adjustment */ concealment_signal_tuning_fx( bfi, st->core, synthFB_fx, &st->plcInfo, st->nbLostCmpt, st->prev_bfi, st->hTonalMDCTConc->secondLastPcmOut, st->last_core_bfi, st->hTonalMDCTConc->lastPcmOut, st ); @@ -730,7 +737,7 @@ void stereo_tcx_core_dec_fx( IF( !bfi && st->hTonalMDCTConc != NULL ) { - TonalMDCTConceal_SaveTimeSignal( st->hTonalMDCTConc, synthFB_fx, hTcxDec->L_frameTCX ); + TonalMDCTConceal_SaveTimeSignal_ivas_fx( st->hTonalMDCTConc, synthFB_fx, 0, hTcxDec->L_frameTCX ); } decoder_tcx_post_ivas_fx( st, synth_fx, synthFB_fx, 0, Aq_fx, bfi, 0 ); diff --git a/lib_dec/stat_dec.h b/lib_dec/stat_dec.h index cc6f7c5be..509051c18 100644 --- a/lib_dec/stat_dec.h +++ b/lib_dec/stat_dec.h @@ -403,6 +403,8 @@ typedef struct tonalmdctconceal Word16 *secondLastPcmOut; + Word16 q_lastPcmOut; + Word16 *secondLastPowerSpectrum; Word16 secondLastPowerSpectrum_exp; diff --git a/lib_dec/tonalMDCTconcealment_fx.c b/lib_dec/tonalMDCTconcealment_fx.c index c4fb3259e..0170aa985 100644 --- a/lib_dec/tonalMDCTconcealment_fx.c +++ b/lib_dec/tonalMDCTconcealment_fx.c @@ -773,7 +773,7 @@ static void ivas_CalcPowerSpecAndDetectTonalComponents_fx( move16(); /* It is taken into account that the MDCT is not normalized. */ - floorPowerSpectrum /*Q0*/ = extract_l( Mpy_32_16_1( L_mult0( hTonalMDCTConc->nSamples, hTonalMDCTConc->nSamples ), 82 ) ); /*1/400 = 82 Q15*/ + floorPowerSpectrum /*Q0*/ = extract_l( Mpy_32_32( L_mult0( hTonalMDCTConc->nSamples, hTonalMDCTConc->nSamples ), 5368709 ) ); /*1/400 = 5368709 Q31*/ powerSpectrum_exp = 0; move16(); @@ -1247,9 +1247,9 @@ void TonalMDCTConceal_Detect_ivas_fx( nSamples = hTonalMDCTConc->nSamples; move16(); - secondLastMDST_exp = 16; /*time signal Q-1*/ + secondLastMDST_exp = sub( 16, hTonalMDCTConc->q_lastPcmOut ); /*time signal Q-1 - hTonalMDCTConc->q_lastPcmOut*/ move16(); - secondLastMDCT_exp = 16; /*time signal Q-1*/ + secondLastMDCT_exp = sub( 16, hTonalMDCTConc->q_lastPcmOut ); /*time signal Q-1 - hTonalMDCTConc->q_lastPcmOut*/ move16(); test(); test(); @@ -3163,6 +3163,35 @@ void TonalMDCTConceal_SaveTimeSignal( return; } +#ifdef IVAS_FLOAT_FIXED +void TonalMDCTConceal_SaveTimeSignal_ivas_fx( + TonalMDCTConcealPtr hTonalMDCTConc, + Word16 *timeSignal, // q_timeSignal + Word16 q_timeSignal, + Word16 nNewSamples ) +{ + IF( EQ_16( nNewSamples, hTonalMDCTConc->nSamples ) ) + { + assert( nNewSamples <= L_FRAME_MAX ); + IF( !hTonalMDCTConc->secondLastBlockData.tonalConcealmentActive ) + { + Word16 exp, len; + len = shr( hTonalMDCTConc->nSamples, 1 ); + Copy( hTonalMDCTConc->lastPcmOut + len, hTonalMDCTConc->secondLastPcmOut, len ); + exp = sub( q_timeSignal, hTonalMDCTConc->q_lastPcmOut ); + IF( exp != 0 ) + { + Scale_sig( hTonalMDCTConc->secondLastPcmOut, len, exp ); // q_timeSignal + } + } + Copy( timeSignal, hTonalMDCTConc->lastPcmOut, hTonalMDCTConc->nSamples ); + hTonalMDCTConc->q_lastPcmOut = q_timeSignal; + move16(); + } + + return; +} +#endif static void CalcPowerSpec( const Word32 *mdctSpec, /* i: MDCT spectrum Q31-mdctSpec_exp */ const Word16 mdctSpec_exp, /* i: exponent of MDCT spectrum */ -- GitLab From f876a6964f62ffbc708bd33c2e02c1fe4442212e Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Fri, 8 Nov 2024 17:35:04 +0530 Subject: [PATCH 102/128] Fix for 3GPP issue 926: Usage of L_shl(), L_shl_o(), L_shl_sat() and L_shr(), L_shr_o(), L_shr_sat() link: #926 --- lib_com/ivas_spar_com.c | 91 ++++++++++++++------------------ lib_dec/ivas_mc_paramupmix_dec.c | 20 +++---- lib_rend/ivas_sba_rendering.c | 12 ++--- 3 files changed, 57 insertions(+), 66 deletions(-) diff --git a/lib_com/ivas_spar_com.c b/lib_com/ivas_spar_com.c index 236d60859..a79d05945 100644 --- a/lib_com/ivas_spar_com.c +++ b/lib_com/ivas_spar_com.c @@ -544,7 +544,7 @@ static void ivas_get_pred_coeffs_enc_fx( Word16 i, j, k, b; Word32 abs_value; Word32 w_norm_fac; - Word32 one_in_q, L_tmp; + Word32 L_tmp; Word16 q_tmp, e_tmp; Word64 abs_value64, tmp64; Word16 q_ppPred_coeffs_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS]; @@ -628,35 +628,29 @@ static void ivas_get_pred_coeffs_enc_fx( e_tmp = sub( 31, sub( add( q_pPred_temp[k], tmp_shift ), 32 ) ); L_tmp = Sqrt32( W_extract_h( W_shl( pPred_temp[k], tmp_shift ) ), &e_tmp ); // Q=31-e_tmp - one_in_q = L_shl_sat( 1, sub( 31, e_tmp ) ); // 1 in Q(31-e_tmp) - - IF( LT_32( one_in_q, L_tmp ) ) + IF( BASOP_Util_Cmp_Mant32Exp( L_tmp, e_tmp, ONE_IN_Q31, 0 ) <= 0 ) { - div_factor[k] = BASOP_Util_Divide3232_Scale( one_in_q, L_tmp, &s_div ); // Q=15-s_div - move16(); - div_factor[k] = shl_sat( div_factor[k], s_div ); // Q = Q15 - move16(); - div_factor_e[k] = 0; - move16(); - } - ELSE - { - div_factor[k] = ONE_IN_Q15 - 1; /*1 in Q15*/ - move16(); - div_factor_e[k] = 0; + L_tmp = ONE_IN_Q31; + move32(); + e_tmp = 0; move16(); } + + div_factor[k] = BASOP_Util_Divide3232_Scale( 1, L_tmp, &s_div ); // exp(0-e_tmp+s_div) + move16(); + div_factor[k] = shl( div_factor[k], sub( add( s_div, 30 ), e_tmp ) ); // Q = Q14 + move16(); } - tmp_shift = 31; + tmp_shift = Q30; // To avoid saturation for Q31 move16(); FOR( i = 0; i < pred_dim; i++ ) { FOR( k = start_band; k < end_band; k++ ) { - IF( NE_16( div_factor[k], ONE_IN_Q15 - 1 /*1 in Q15*/ ) ) + IF( NE_16( div_factor[k], ONE_IN_Q14 /*1 in Q14*/ ) ) { - ppPred_coeffs_re[i][k] = Mpy_32_16_1( ppPred_coeffs_re[i][k], div_factor[k] ); // Q = q_ppPred_coeffs_re[i][k] + ppPred_coeffs_re[i][k] = L_shl( Mpy_32_16_1( ppPred_coeffs_re[i][k], div_factor[k] ), 1 ); // Q = q_ppPred_coeffs_re[i][k] move32(); } ppDM_Fv_re[i][k] = 0; @@ -678,7 +672,7 @@ static void ivas_get_pred_coeffs_enc_fx( } *q_pred_coeffs = tmp_shift; move16(); - *q_dm_fv_re = 31; + *q_dm_fv_re = 30; // To avoid saturation in Q31 move16(); } ELSE @@ -1152,9 +1146,9 @@ static void ivas_get_pred_coeffs_enc_fx( } } - *q_pred_coeffs = 31; + *q_pred_coeffs = 30; // To avoid saturation in Q31 move16(); - *q_dm_fv_re = 31; + *q_dm_fv_re = 30; // To avoid saturation in Q31 move16(); FOR( i = 0; i < pred_dim; i++ ) @@ -1987,11 +1981,11 @@ void ivas_create_fullr_dmx_mat_fx( { FOR( b = start_band; b < end_band; b++ ) { - tmp_p2_re[j][j][b] = L_shl_sat( 1, q_pred_coeffs_re ); // q=q_pred_coeffs_re + tmp_p2_re[j][j][b] = L_shl( 1, q_pred_coeffs_re ); // q=q_pred_coeffs_re move32(); - max_val_tmp_p2 = L_max( max_val_tmp_p2, L_abs( tmp_p2_re[j][j][b] ) ); // q=q_pred_coeffs_re } } + max_val_tmp_p2 = L_shl( 1, q_pred_coeffs_re ); // q=q_pred_coeffs_re FOR( j = 1; j < in_chans; j++ ) { @@ -2015,11 +2009,11 @@ void ivas_create_fullr_dmx_mat_fx( { FOR( b = start_band; b < end_band; b++ ) { - tmp_p1_re[j][j][b] = L_shl_sat( 1, q_dm_fv_re ); // q=q_dm_fv_re + tmp_p1_re[j][j][b] = L_shl( 1, q_dm_fv_re ); // q=q_dm_fv_re move32(); - max_val = L_max( max_val, L_abs( tmp_p1_re[j][j][b] ) ); // q=q_dm_fv_re } } + max_val = L_shl( 1, q_dm_fv_re ); // q=q_dm_fv_re FOR( j = 1; j < in_chans; j++ ) { @@ -5055,7 +5049,7 @@ void ivas_get_spar_md_from_dirac_fx( { Word32 en_ratio_fac_sq = 0; move32(); - cov_real_dirac_fx[i][j][band] = Mpy_32_32( L_shl_sat( Mpy_32_32( en_ratio_fac_fx, response_avg_fx[i] ), 1 ), response_avg_fx[j] ); // q30 + cov_real_dirac_fx[i][j][band] = Mpy_32_32( L_shl( Mpy_32_32( en_ratio_fac_fx, response_avg_fx[i] ), 1 ), response_avg_fx[j] ); // q30 move32(); IF( LE_16( hSpar_md_cfg->nchan_transport, 2 ) ) @@ -5804,7 +5798,7 @@ Word32 local_result_table[91][9] /*q30*/ = { 284546880, }, { - -1073741824, + -1073741823, 759250176, 379625056, -929887680, @@ -6300,7 +6294,7 @@ Word32 local_result_table[91][9] /*q30*/ = { }, { -66, - 1073741824, + 1073741823, -759250112, -81, 929887872, @@ -6313,12 +6307,12 @@ Word32 local_result_table[91][9] /*q30*/ = { Word32 local_result_table_2[91][9] /*q30*/ = { { - -1073741824, + -1073741823, 0, - 1073741824, + 1073741823, 0, 0, - -1073741824, + -1073741823, 0, 0, 0, @@ -7376,28 +7370,25 @@ void ivas_dirac_dec_get_response_fx( f_fx = 1; move16(); } - cos_1_fx = dirac_gains_trg_term_fx[az][0]; // q31 - move32(); - cos_2_fx = Mpy_32_32( cos_1_fx, cos_1_fx ); // q31 - sin_1_fx = dirac_gains_trg_term_fx[az][1]; // q31 - move32(); + cos_1_fx = L_shr( dirac_gains_trg_term_fx[az][0], 1 ); // q30 + cos_2_fx = L_shl( Mpy_32_32( cos_1_fx, cos_1_fx ), 1 ); // q30 + sin_1_fx = L_shr( dirac_gains_trg_term_fx[az][1], 1 ); // q30 if ( EQ_32( f_fx, -1 ) ) { - sin_1_fx = L_negate( sin_1_fx ); // q31 - move32(); + sin_1_fx = L_negate( sin_1_fx ); // q30 } - cos_az_fx[0] = cos_1_fx; // q31 + cos_az_fx[0] = cos_1_fx; // q30 move32(); - cos_az_fx[1] = L_shl_sat( L_sub( cos_2_fx, ONE_IN_Q30 /*0.5 q31*/ ), 1 ); /*q31*/ + cos_az_fx[1] = L_shl( L_sub( cos_2_fx, ONE_IN_Q29 /*0.5 q30*/ ), 1 ); /*q30*/ move32(); - cos_az_fx[2] = L_shl_sat( L_sub( Mpy_32_32( cos_1_fx, cos_az_fx[1] ), L_shr( cos_az_fx[0], 1 ) /* cos_az_fx[0]/2 q31*/ ), 1 ); /*q31*/ + cos_az_fx[2] = L_sub( L_shl( Mpy_32_32( cos_1_fx, cos_az_fx[1] ), 2 ), cos_az_fx[0] /* cos_az_fx[0] q30*/ ); /*q30*/ move32(); - sin_az_fx[0] = sin_1_fx; /*q31*/ + sin_az_fx[0] = sin_1_fx; /*q30*/ move32(); - sin_az_fx[1] = L_shl_sat( Mpy_32_32( sin_1_fx, cos_1_fx ), 1 ); /*q31*/ + sin_az_fx[1] = L_shl( Mpy_32_32( sin_1_fx, cos_1_fx ), 2 ); /*q30*/ move32(); - sin_az_fx[2] = L_shl_sat( Mpy_32_32( sin_1_fx, L_sub( cos_2_fx, ONE_IN_Q29 /*1/4 q31*/ ) ), 2 ); /*q31*/ + sin_az_fx[2] = L_shl( Mpy_32_32( sin_1_fx, L_sub( cos_2_fx, ONE_IN_Q28 /*1/4 q30*/ ) ), 3 ); /*q30*/ move32(); response_fx[0] = L_shl_sat( 1, Q_out ); // Q_out @@ -7414,11 +7405,11 @@ void ivas_dirac_dec_get_response_fx( move16(); c_fx_better = local_result_table[el][a]; // q30 move32(); - response_fx[b] = L_shl_sat( Mpy_32_32( c_fx_better, sin_az_fx[l - m - 1] ), sub( Q_out, 30 ) ); // Q_out + response_fx[b] = L_shl( Mpy_32_32( c_fx_better, sin_az_fx[l - m - 1] ), sub( Q_out, 29 ) ); // Q_out move32(); b1 = sub( b1_2, m ); - response_fx[b1] = L_shl_sat( Mpy_32_32( c_fx_better, cos_az_fx[l - m - 1] ), sub( Q_out, 30 ) ); // Q_out + response_fx[b1] = L_shl( Mpy_32_32( c_fx_better, cos_az_fx[l - m - 1] ), sub( Q_out, 29 ) ); // Q_out move32(); } @@ -7433,10 +7424,10 @@ void ivas_dirac_dec_get_response_fx( { c_fx_better = L_negate( c_fx_better ); // q30 } - response_fx[b] = L_shl_sat( Mpy_32_32( c_fx_better, sin_az_fx[l - m - 1] ), sub( Q_out, 30 ) ); // Q_out + response_fx[b] = L_shl( Mpy_32_32( c_fx_better, sin_az_fx[l - m - 1] ), sub( Q_out, 29 ) ); // Q_out move32(); b1 = sub( b1_2, m ); - response_fx[b1] = L_shl_sat( Mpy_32_32( c_fx_better, cos_az_fx[l - m - 1] ), sub( Q_out, 30 ) ); // Q_out + response_fx[b1] = L_shl( Mpy_32_32( c_fx_better, cos_az_fx[l - m - 1] ), sub( Q_out, 29 ) ); // Q_out move32(); } @@ -7453,7 +7444,7 @@ void ivas_dirac_dec_get_response_fx( move32(); } } - response_fx[b] = L_shl_sat( c_fx_better, sub( Q_out, 30 ) ); // Q_out + response_fx[b] = L_shl( c_fx_better, sub( Q_out, 30 ) ); // Q_out move32(); } diff --git a/lib_dec/ivas_mc_paramupmix_dec.c b/lib_dec/ivas_mc_paramupmix_dec.c index 1e867d4db..a492fcf65 100644 --- a/lib_dec/ivas_mc_paramupmix_dec.c +++ b/lib_dec/ivas_mc_paramupmix_dec.c @@ -684,14 +684,14 @@ static void ps_pred_process_sf( vsim_fx = qmf_side_im_fx[ismp][iqmf]; // Q6 move32(); - res_a = L_shl_sat( Mpy_32_32( alpha_smp_fx, vmre_fx ), Q31 - Q28 ); // Q6 - res_b = L_shl_sat( Mpy_32_32( beta_smp_fx, vsre_fx ), Q31 - Q28 ); // Q6 - qmf_side_re_fx[ismp][iqmf] = L_add_sat( res_a, res_b ); // Q6 + res_a = L_shl( Mpy_32_32( alpha_smp_fx, vmre_fx ), Q31 - Q28 ); // Q6 + res_b = L_shl( Mpy_32_32( beta_smp_fx, vsre_fx ), Q31 - Q28 ); // Q6 + qmf_side_re_fx[ismp][iqmf] = L_add( res_a, res_b ); // Q6 move32(); - res_a = L_shl_sat( Mpy_32_32( alpha_smp_fx, vmim_fx ), Q31 - Q28 ); // Q6 - res_b = L_shl_sat( Mpy_32_32( beta_smp_fx, vsim_fx ), Q31 - Q28 ); // Q6 - qmf_side_im_fx[ismp][iqmf] = L_add_sat( res_a, res_b ); + res_a = L_shl( Mpy_32_32( alpha_smp_fx, vmim_fx ), Q31 - Q28 ); // Q6 + res_b = L_shl( Mpy_32_32( beta_smp_fx, vsim_fx ), Q31 - Q28 ); // Q6 + qmf_side_im_fx[ismp][iqmf] = L_add( res_a, res_b ); move32(); ismp = add( ismp, 1 ); @@ -778,10 +778,10 @@ static void ivas_mc_paramupmix_dec_sf( move32(); move32(); - Cldfb_RealBuffer_fx[2 * ch][slot_idx][k] = L_add_sat( qlre_fx, qrre_fx ); - Cldfb_ImagBuffer_fx[2 * ch][slot_idx][k] = L_add_sat( qlim_fx, qrim_fx ); - Cldfb_RealBuffer_fx[2 * ch + 1][slot_idx][k] = L_sub_sat( qlre_fx, qrre_fx ); - Cldfb_ImagBuffer_fx[2 * ch + 1][slot_idx][k] = L_sub_sat( qlim_fx, qrim_fx ); + Cldfb_RealBuffer_fx[2 * ch][slot_idx][k] = L_add( qlre_fx, qrre_fx ); + Cldfb_ImagBuffer_fx[2 * ch][slot_idx][k] = L_add( qlim_fx, qrim_fx ); + Cldfb_RealBuffer_fx[2 * ch + 1][slot_idx][k] = L_sub( qlre_fx, qrre_fx ); + Cldfb_ImagBuffer_fx[2 * ch + 1][slot_idx][k] = L_sub( qlim_fx, qrim_fx ); move32(); move32(); move32(); diff --git a/lib_rend/ivas_sba_rendering.c b/lib_rend/ivas_sba_rendering.c index ccf81a09d..1867e4263 100644 --- a/lib_rend/ivas_sba_rendering.c +++ b/lib_rend/ivas_sba_rendering.c @@ -181,12 +181,12 @@ void ivas_sba_prototype_renderer_fx( FOR( spar_band = bin2band->p_spar_start_bands[cldfb_band]; spar_band < num_spar_bands; spar_band++ ) { /* accumulate contributions from all SPAR bands */ - cldfb_par_fx = L_add_sat( cldfb_par_fx, Mpy_32_32( mixer_mat_fx[out_ch][in_ch][spar_band], bin2band->pp_cldfb_weights_per_spar_band_fx[cldfb_band][spar_band] ) ); // hMdDec->Q_mixer_matrix + cldfb_par_fx = L_add( cldfb_par_fx, Mpy_32_32( mixer_mat_fx[out_ch][in_ch][spar_band], bin2band->pp_cldfb_weights_per_spar_band_fx[cldfb_band][spar_band] ) ); // hMdDec->Q_mixer_matrix } } - out_re_fx[out_ch] = L_add_sat( out_re_fx[out_ch], Mpy_32_32( inRe_fx[in_ch][ts][cldfb_band], cldfb_par_fx ) ); // hMdDec->Q_mixer_matrix+q_cldfb[i][j] -31 - out_im_fx[out_ch] = L_add_sat( out_im_fx[out_ch], Mpy_32_32( inIm_fx[in_ch][ts][cldfb_band], cldfb_par_fx ) ); // hMdDec->Q_mixer_matrix+q_cldfb[i][j] -31 + out_re_fx[out_ch] = L_add( out_re_fx[out_ch], Mpy_32_32( inRe_fx[in_ch][ts][cldfb_band], cldfb_par_fx ) ); // hMdDec->Q_mixer_matrix+q_cldfb[i][j] -31 + out_im_fx[out_ch] = L_add( out_im_fx[out_ch], Mpy_32_32( inIm_fx[in_ch][ts][cldfb_band], cldfb_par_fx ) ); // hMdDec->Q_mixer_matrix+q_cldfb[i][j] -31 move32(); move32(); } @@ -195,8 +195,8 @@ void ivas_sba_prototype_renderer_fx( /*update CLDFB data with the parameter-modified data*/ FOR( out_ch = firstOutCh; out_ch < outChEnd; out_ch++ ) { - inRe_fx[out_ch][ts][cldfb_band] = L_shl_sat( out_re_fx[out_ch], 1 ); // hMdDec->Q_mixer_matrix+q_cldfb[i][j] -31 +1; + q1 //to keep constat q to entire buffer - inIm_fx[out_ch][ts][cldfb_band] = L_shl_sat( out_im_fx[out_ch], 1 ); // hMdDec->Q_mixer_matrix+q_cldfb[i][j] -31 +1; + q1 //to keep constat q to entire buffer + inRe_fx[out_ch][ts][cldfb_band] = L_shl( out_re_fx[out_ch], 1 ); // hMdDec->Q_mixer_matrix+q_cldfb[i][j] -31 +1; + q1 //to keep constat q to entire buffer + inIm_fx[out_ch][ts][cldfb_band] = L_shl( out_im_fx[out_ch], 1 ); // hMdDec->Q_mixer_matrix+q_cldfb[i][j] -31 +1; + q1 //to keep constat q to entire buffer move32(); move32(); } @@ -228,7 +228,7 @@ void ivas_sba_prototype_renderer_fx( { FOR( b = 0; b < num_spar_bands; b++ ) { - hSpar->hMdDec->mixer_mat_prev_fx[4][out_ch][in_ch][b] = hSpar->hMdDec->mixer_mat_fx[out_ch][in_ch][add( b, imult1616( md_sf, IVAS_MAX_NUM_BANDS ) )]; + hSpar->hMdDec->mixer_mat_prev_fx[4][out_ch][in_ch][b] = hSpar->hMdDec->mixer_mat_fx[out_ch][in_ch][b + ( md_sf * IVAS_MAX_NUM_BANDS )]; move32(); } } -- GitLab From 16864af47a5dee73d2c92ecdda3ec8655e61933b Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Fri, 8 Nov 2024 18:41:21 +0530 Subject: [PATCH 103/128] Encoder float struct emnts cleanup, Q-info addition and LTV crash fix --- lib_com/basop_util.c | 4 +- lib_com/lpc_tools_fx.c | 2 +- lib_com/prot.h | 6 +- lib_com/prot_fx.h | 93 +- lib_com/reordvct_fx.c | 2 +- lib_com/residu.c | 8 +- lib_com/residu_fx.c | 8 +- lib_com/rom_basic_math.c | 16 +- lib_com/rom_basic_math.h | 16 +- lib_com/rom_basop_util.c | 77 +- lib_com/rom_basop_util.h | 6 +- lib_com/rom_com.c | 1709 +++++++++++++------------- lib_com/rom_com.h | 2091 ++++++++++++++++---------------- lib_com/rom_com_fx.c | 20 +- lib_com/rom_com_fx.h | 114 +- lib_com/scale_mem_fx.c | 26 +- lib_com/stab_est_fx.c | 10 +- lib_com/stat_com.h | 474 ++++---- lib_com/stat_noise_uv_mod_fx.c | 30 +- lib_enc/core_enc_switch.c | 1 - lib_enc/core_switching_enc.c | 17 +- lib_enc/ivas_core_enc.c | 48 +- lib_enc/ivas_masa_enc.c | 2 +- lib_enc/ivas_omasa_enc.c | 4 +- lib_enc/stat_enc.h | 57 +- lib_enc/swb_pre_proc.c | 28 +- lib_enc/swb_tbe_enc.c | 24 +- lib_enc/swb_tbe_enc_fx.c | 6 +- 28 files changed, 2469 insertions(+), 2430 deletions(-) diff --git a/lib_com/basop_util.c b/lib_com/basop_util.c index 1a2ef14f8..c465428fc 100644 --- a/lib_com/basop_util.c +++ b/lib_com/basop_util.c @@ -49,8 +49,8 @@ #define WMC_TOOL_SKIP -extern const Word32 SqrtTable[32]; -extern const Word16 SqrtDiffTable[32]; +extern const Word32 SqrtTable[32]; // Q31 +extern const Word16 SqrtDiffTable[32]; /* Q15 */ extern const Word32 ISqrtTable[32]; extern const Word16 ISqrtDiffTable[32]; diff --git a/lib_com/lpc_tools_fx.c b/lib_com/lpc_tools_fx.c index bec794e31..b1bbbae7b 100644 --- a/lib_com/lpc_tools_fx.c +++ b/lib_com/lpc_tools_fx.c @@ -1281,7 +1281,7 @@ Word32 E_LPC_schur( Word32 r[] /*Qr*/, Word16 reflCoeff[] /*Q15*/, Word32 epsP[] } -extern const PWord16 *w_a[7]; +extern const PWord16 *w_a[7]; // Q15 extern const PWord16 w19N[127]; extern const PWord16 w18N[127]; extern void BASOP_getTables( const PWord16 **ptwiddle, const PWord16 **sin_twiddle, Word16 *psin_step, Word16 length ); diff --git a/lib_com/prot.h b/lib_com/prot.h index 444817758..dc328e5d4 100644 --- a/lib_com/prot.h +++ b/lib_com/prot.h @@ -1153,11 +1153,11 @@ void residu( #ifdef IVAS_FLOAT_FIXED void residu_ivas_fx( - const Word16 *a, /* i : LP filter coefficients */ + const Word16 *a, /* i : LP filter coefficients Q31-a_exp*/ const Word16 a_exp, const Word16 m, /* i : order of LP filter */ - const Word32 *x, /* i : input signal (usually speech) */ - Word32 *y, /* o : output signal (usually residual) */ + const Word32 *x, /* i : input signal (usually speech) Qx*/ + Word32 *y, /* o : output signal (usually residual) Qx*/ const Word16 l /* i : size of filtering */ ); #endif diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index 66e80a6b3..1ac9d84c0 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -1336,16 +1336,16 @@ scale_mem_fx.c /========================================================================================================*/ Word16 Rescale_exc( - Word16 dct_post_old_exc_fx[], /* i/o: Music post processing memory */ + Word16 dct_post_old_exc_fx[], /* i/o: Music post processing memory Q_exc*/ Word16 exc[], /* i/o: excitation to rescale Q_exc */ - Word16 bwe_exc[], - Word16 *last_exc_dct_in, - Word16 lg, /* i : frame size */ + Word16 bwe_exc[], /* Q_exc */ + Word16 *last_exc_dct_in, /* Q_exc */ + Word16 lg, /* i : frame size */ Word16 lg32, Word32 L_gain_code, /* i : decoded codebook gain Q16 */ Word16 *sQ_exc, /* i/o: Excitation scaling factor */ Word16 *sQsubfr, /* i/o: Past excitation scaling factors */ - Word16 exc2[], /* o : local excitation vector */ + Word16 exc2[], /* o : local excitation vector Q_exc */ Word16 i_subfr, /* i : subframe number */ const Word16 coder_type ); @@ -1353,14 +1353,14 @@ void Rescale_mem( const Word16 Q_exc, /* i : current excitation scaling (>=0) */ Word16 *prev_Q_syn, /* i/o : scaling factor of previous frame */ Word16 *Q_syn, /* i/o : scaling factor of frame */ - Word16 *mem_syn2, /* i/o : modified synthesis memory */ - Word16 *mem_syn_clas_estim_fx, /* i/o : old 12k8 core memory for classification */ + Word16 *mem_syn2, /* i/o : modified synthesis memory Qexp_scale */ + Word16 *mem_syn_clas_estim_fx, /* i/o : old 12k8 core memory for classification Qexp_scale*/ const Word16 MaxScaling, /* i: Minimal difference between excitation scaling and synthesis scaling */ - Word16 *mem_deemph, /* i/o: speech deemph filter memory */ - Word16 *pst_old_syn, /* i/o: psfiler */ - Word16 *pst_mem_deemp_err, /* i/o: psfiler */ - Word16 *mem_agc, - PFSTAT_HANDLE hPFstat, /* i/o: All memories related to NB post filter */ + Word16 *mem_deemph, /* i/o: speech deemph filter memory Qexp_scale */ + Word16 *pst_old_syn, /* i/o: psfiler Qexp_scale*/ + Word16 *pst_mem_deemp_err, /* i/o: psfiler Qexp_scale */ + Word16 *mem_agc, /*Qexp_scale*/ + PFSTAT_HANDLE hPFstat, /* i/o: All memories related to NB post filter */ const Word16 Vad_flag, const Word16 Cna_flag, const Word16 *tmp_buffer /* tmp_buffer in Q-1 */ @@ -2192,7 +2192,7 @@ Word32 hq2_bit_alloc_fx( ); void reordvct_fx( - Word16 *y, /* i/o: vector to rearrange */ + Word16 *y, /* i/o: vector to rearrange Q0*/ const Word16 N, /* i : dimensions */ Word16 *idx /* o : reordered vector index */ ); @@ -2477,9 +2477,9 @@ void Residu3_fx( void calc_residu_fx( Encoder_State *st, /* i/o: state structure */ - const Word16 *speech, /* i : weighted speech signal */ - Word16 *res, /* o : residual signal */ - const Word16 *p_Aq /* i : quantized LP filter coefficients */ + const Word16 *speech, /* i : weighted speech signal Qx*/ + Word16 *res, /* o : residual signal Qx+1*/ + const Word16 *p_Aq /* i : quantized LP filter coefficients Q12*/ ); // inerpol_lc.c Word32 Interpol_lc_fx( /* o : interpolated value Q15 */ @@ -5482,12 +5482,12 @@ void bitallocsum_fx( // stab_est_fx.c Word16 stab_est_fx( - Word16 etot, /* i : Total energy of the current frame */ - Word16 *lt_diff_etot, /* i/o : Long term total energy variation */ - Word16 *mem_etot, /* i/o : Total energy memory */ + Word16 etot, /* i : Total energy of the current frame Q8*/ + Word16 *lt_diff_etot, /* i/o : Long term total energy variation Q8*/ + Word16 *mem_etot, /* i/o : Total energy memory Q8*/ Word16 *nb_thr_3, /* i/o : Number of consecutives frames of level 3 */ Word16 *nb_thr_1, /* i/o : Number of consecutives frames of level 1 */ - Word16 *thresh, /* i/o : Detection thresold */ + Word16 *thresh, /* i/o : Detection thresold Q11*/ Word16 *last_music_flag, /* i/o : Previous music detection ouptut */ const Word16 vad_flag /* i : VAD flag */ ); @@ -8361,26 +8361,26 @@ void stat_noise_uv_dec_fx( // stat_noise_uv_mod_fx.c void stat_noise_uv_mod_fx( - const Word16 coder_type, /* i : Coder type */ - Word16 noisiness, /* i : noisiness parameter */ - const Word16 *lsp_old, /* i : old LSP vector at 4th sfr */ - const Word16 *lsp_new, /* i : LSP vector at 4th sfr */ - const Word16 *lsp_mid, /* i : LSP vector at 2nd sfr */ - Word16 *Aq, /* o : A(z) quantized for the 4 subframes */ - Word16 *exc2, /* i/o: excitation buffer */ + const Word16 coder_type, /* i : Coder type */ + Word16 noisiness, /* i : noisiness parameter Q0 */ + const Word16 *lsp_old, /* i : old LSP vector at 4th sfr Q15 */ + const Word16 *lsp_new, /* i : LSP vector at 4th sfr Q15 */ + const Word16 *lsp_mid, /* i : LSP vector at 2nd sfr Q15 */ + Word16 *Aq, /* o : A(z) quantized for the 4 subframes Q12 */ + Word16 *exc2, /* i/o: excitation buffer Q_exc */ Word16 Q_exc, /* i : Q of exc2 excitation buffer [11..-1] expected */ - const Word16 bfi, /* i : Bad frame indicator */ - Word32 *ge_sm, /* i/o: smoothed excitation gain */ - Word16 *uv_count, /* i/o: unvoiced counter */ - Word16 *act_count, /* i/o: activation counter */ - Word16 lspold_s[], /* i/o: old LSP */ - Word16 *noimix_seed, /* i/o: mixture seed */ - Word16 *st_min_alpha, /* i/o: minimum alpha */ - Word16 *exc_pe, /* i/o: scale Q_stat_noise */ - const Word32 bitrate, /* i : core bitrate */ - const Word16 bwidth_fx, /* i : i bandwidth */ - Word16 *Q_stat_noise, /* i/o: noise scaling */ - Word16 *Q_stat_noise_ge /* i/o: noise scaling */ + const Word16 bfi, /* i : Bad frame indicator */ + Word32 *ge_sm, /* i/o: smoothed excitation gain Q_ge */ + Word16 *uv_count, /* i/o: unvoiced counter */ + Word16 *act_count, /* i/o: activation counter */ + Word16 lspold_s[], /* i/o: old LSP Q15 */ + Word16 *noimix_seed, /* i/o: mixture seed Q0 */ + Word16 *st_min_alpha, /* i/o: minimum alpha Q15 */ + Word16 *exc_pe, /* i/o: scale Q_stat_noise Q_stat_noise */ + const Word32 bitrate, /* i : core bitrate */ + const Word16 bwidth_fx, /* i : input bandwidth */ + Word16 *Q_stat_noise, /* i/o: noise scaling */ + Word16 *Q_stat_noise_ge /* i/o: noise scaling */ ); void stat_noise_uv_mod_ivas_fx( @@ -8393,11 +8393,11 @@ void stat_noise_uv_mod_ivas_fx( Word16 *exc2, /* i/o: excitation buffer Q=Q_exc*/ Word16 Q_exc, /* i : Q of exc2 excitation buffer [11..-1] expected */ const Word16 bfi, /* i : Bad frame indicator */ - Word32 *ge_sm, /* i/o: smoothed excitation gain Q=Q_stat_noise_ge (6) */ + Word32 *ge_sm, /* i/o: smoothed excitation gain Q=Q_stat_noise_ge (6)*/ Word16 *uv_count, /* i/o: unvoiced counter */ Word16 *act_count, /* i/o: activation counter */ Word16 lspold_s[], /* i/o: old LSP Q=15*/ - Word16 *noimix_seed, /* i/o: mixture seed */ + Word16 *noimix_seed, /* i/o: mixture seed Q0 */ Word16 *st_min_alpha, /* i/o: minimum alpha Q=15*/ Word16 *exc_pe, /* i/o: scale Q_stat_noise Q=Q_stat_noise*/ const Word32 bitrate, /* i : core bitrate */ @@ -10716,12 +10716,11 @@ void Copy_Scale_sig32( ); void swb_pre_proc_ivas_fx( - Encoder_State *st, /* i/o: encoder state structure */ - Word16 *new_swb_speech, /* o : original input signal at 32kHz - Q0 */ - Word32 *new_swb_speech_fx, /* o : original input signal at 32kHz - Q - q_reImBuffer */ - Word16 *shb_speech, /* o : SHB target signal (6-14kHz) at 16kHz- Q0 */ - Word32 *shb_speech_32, /* o : SHB target signal (6-14kHz) at 16kHz- Q - q_reImBuffer */ - Word16 *use_shb32, /* o : flags valid data in 32-bit shb buffer for better precision. */ + Encoder_State *st, /* i/o: encoder state structure */ + Word16 *new_swb_speech, /* o : original input signal at 32kHz - Q0 */ + Word32 *new_swb_speech_fx, /* o : original input signal at 32kHz - Q - q_reImBuffer */ + Word16 *shb_speech, /* o : SHB target signal (6-14kHz) at 16kHz- Q(Q_shb_spch) */ + Word16 *Q_shb_spch, Word32 realBuffer[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i : real buffer Q - q_reImbuffer */ Word32 imagBuffer[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i : imag buffer Q - q_reImbuffer */ Word16 q_reImBuffer, /* i : scale data of real and imag CLDFB buffers */ diff --git a/lib_com/reordvct_fx.c b/lib_com/reordvct_fx.c index 07bc21bc8..3b741203a 100644 --- a/lib_com/reordvct_fx.c +++ b/lib_com/reordvct_fx.c @@ -42,7 +42,7 @@ *--------------------------------------------------------------------------*/ void reordvct_fx( - Word16 *y, /* i/o: vector to rearrange */ + Word16 *y, /* i/o: vector to rearrange Q0*/ const Word16 N, /* i : dimensions */ Word16 *idx /* o : reordered vector index */ ) diff --git a/lib_com/residu.c b/lib_com/residu.c index e05210598..28574a072 100644 --- a/lib_com/residu.c +++ b/lib_com/residu.c @@ -79,11 +79,11 @@ void residu( #ifdef IVAS_FLOAT_FIXED void residu_ivas_fx( - const Word16 *a, /* i : LP filter coefficients */ + const Word16 *a, /* i : LP filter coefficients Q31-a_exp*/ const Word16 a_exp, const Word16 m, /* i : order of LP filter */ - const Word32 *x, /* i : input signal (usually speech) */ - Word32 *y, /* o : output signal (usually residual) */ + const Word32 *x, /* i : input signal (usually speech) Qx*/ + Word32 *y, /* o : output signal (usually residual) Qx*/ const Word16 l /* i : size of filtering */ ) { @@ -96,7 +96,7 @@ void residu_ivas_fx( move32(); FOR( j = 1; j <= m; j++ ) { - s = L_add( s, L_shl( Mpy_32_16_1( x[sub( i, j )], a[j] ), sub( Q15, a_exp ) ) ); + s = L_add( s, L_shl( Mpy_32_16_1( x[i - j], a[j] ), sub( Q15, a_exp ) ) ); // Qx } y[i] = s; move32(); diff --git a/lib_com/residu_fx.c b/lib_com/residu_fx.c index e06ef40ea..c2e6d43a6 100644 --- a/lib_com/residu_fx.c +++ b/lib_com/residu_fx.c @@ -29,6 +29,7 @@ void Residu3_lc_fx( Word16 q; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move16(); #endif q = add( norm_s( a[0] ), 1 ); @@ -151,6 +152,7 @@ void Residu3_fx( Word16 q; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move16(); #endif q = add( norm_s( a[0] ), 1 ); if ( shift != 0 ) @@ -195,9 +197,9 @@ void Residu3_fx( void calc_residu_fx( Encoder_State *st, /* i/o: state structure */ - const Word16 *speech, /* i : weighted speech signal */ - Word16 *res, /* o : residual signal */ - const Word16 *p_Aq /* i : quantized LP filter coefficients */ + const Word16 *speech, /* i : weighted speech signal Qx*/ + Word16 *res, /* o : residual signal Qx+1*/ + const Word16 *p_Aq /* i : quantized LP filter coefficients Q12*/ ) { Word16 i_subfr; diff --git a/lib_com/rom_basic_math.c b/lib_com/rom_basic_math.c index 07535d524..589935254 100644 --- a/lib_com/rom_basic_math.c +++ b/lib_com/rom_basic_math.c @@ -2,7 +2,7 @@ #include "cnst.h" /* Decoder static structure */ #include "stl.h" /* math_op.c */ -const Word32 L_table_isqrt[48] = { +const Word32 L_table_isqrt[48] = { // Q31 2147418112L, 2083389440L, 2024669184L, 1970667520L, 1920794624L, 1874460672L, 1831403520L, 1791098880L, 1753415680L, 1717960704L, 1684602880L, 1653145600L, @@ -18,7 +18,7 @@ const Word32 L_table_isqrt[48] = { }; /* table of table_isqrt[i] - table_isqrt[i+1] */ -const Word16 table_isqrt_diff[48] = { +const Word16 table_isqrt_diff[48] = { // Q15 977, 896, 824, 761, 707, 657, 615, 575, 541, 509, 480, 455, 431, 409, 389, 371, 353, 338, 324, 310, 297, 285, 275, 264, @@ -29,7 +29,7 @@ const Word16 table_isqrt_diff[48] = { const Word16 shift_Isqrt_lc[] = { 9, 10 }; -const Word16 table_pow2[32] = { +const Word16 table_pow2[32] = { // Q15 16384, 16743, 17109, 17484, 17867, 18258, 18658, 19066, 19484, 19911, 20347, 20792, 21247, 21713, 22188, 22674, 23170, 23678, 24196, 24726, 25268, 25821, 26386, 26964, 27554, 28158, 28774, 29405, 30048, 30706, @@ -37,14 +37,14 @@ const Word16 table_pow2[32] = { }; /* table of table_pow2[i+1] - table_pow2[i] */ -const Word16 table_pow2_diff_x32[32] = { +const Word16 table_pow2_diff_x32[32] = { // Q15 11488, 11712, 12000, 12256, 12512, 12800, 13056, 13376, 13664, 13952, 14240, 14560, 14912, 15200, 15552, 15872, 16256, 16576, 16960, 17344, 17696, 18080, 18496, 18880, 19328, 19712, 20192, 20576, 21056, 21536, 21984, 22432 }; -const Word16 sqrt_table[49] = { +const Word16 sqrt_table[49] = { // Q15 16384, 16888, 17378, 17854, 18318, 18770, 19212, 19644, 20066, 20480, 20886, 21283, 21674, 22058, 22435, 22806, 23170, 23530, 23884, 24232, 24576, @@ -55,7 +55,7 @@ const Word16 sqrt_table[49] = { }; /* log2.c */ -const Word32 L_table_Log2_norm_lc[32] = { +const Word32 L_table_Log2_norm_lc[32] = { // Q31 -32768L, 95322112L, 187793408L, 277577728L, 364871680L, 449740800L, 532381696L, 612859904L, 691306496L, 767787008L, 842432512L, 915308544L, @@ -66,14 +66,14 @@ const Word32 L_table_Log2_norm_lc[32] = { 1947435008L, 1998618624L, 2049015808L, 2098626560L }; -const Word16 table_diff_Log2_norm_lc[32] = { +const Word16 table_diff_Log2_norm_lc[32] = { // Q15 1455, 1411, 1370, 1332, 1295, 1261, 1228, 1197, 1167, 1139, 1112, 1087, 1063, 1039, 1016, 995, 975, 955, 936, 918, 901, 883, 868, 852, 836, 822, 809, 794, 781, 769, 757, 744 }; -const Word16 log2_tab[33] = { +const Word16 log2_tab[33] = { // Q15 0x7800, 0x782D, 0x785A, 0x7884, 0x78AE, 0x78D6, 0x78FE, 0x7924, 0x794A, 0x796E, 0x7992, 0x79B4, 0x79D6, 0x79F8, 0x7A18, 0x7A38, 0x7A57, 0x7A75, 0x7A93, 0x7AB1, 0x7ACD, 0x7AE9, 0x7B05, 0x7B20, diff --git a/lib_com/rom_basic_math.h b/lib_com/rom_basic_math.h index 93f9a825c..0f4826d0c 100644 --- a/lib_com/rom_basic_math.h +++ b/lib_com/rom_basic_math.h @@ -3,23 +3,23 @@ #include "stl.h" /* math_op.c */ -extern const Word32 L_table_isqrt[48]; +extern const Word32 L_table_isqrt[48]; // Q31 /* table of table_isqrt[i] - table_isqrt[i+1] */ -extern const Word16 table_isqrt_diff[48]; +extern const Word16 table_isqrt_diff[48]; // Q15 extern const Word16 shift_Isqrt_lc[]; -extern const Word16 table_pow2[32]; +extern const Word16 table_pow2[32]; // Q15 /* table of table_pow2[i+1] - table_pow2[i] */ -extern const Word16 table_pow2_diff_x32[32]; +extern const Word16 table_pow2_diff_x32[32]; // Q15 -extern const Word16 sqrt_table[49]; +extern const Word16 sqrt_table[49]; // Q15 /* log2.c */ -extern const Word32 L_table_Log2_norm_lc[32]; +extern const Word32 L_table_Log2_norm_lc[32]; // Q31 -extern const Word16 table_diff_Log2_norm_lc[32]; +extern const Word16 table_diff_Log2_norm_lc[32]; // Q15 -extern const Word16 log2_tab[33]; +extern const Word16 log2_tab[33]; // Q15 diff --git a/lib_com/rom_basop_util.c b/lib_com/rom_basop_util.c index 9bb6f0a93..38c61d6bc 100644 --- a/lib_com/rom_basop_util.c +++ b/lib_com/rom_basop_util.c @@ -46,6 +46,7 @@ } const PWord16 SineTable512[] = { + // Q15 STCP( 0x7fffffff, 0x00000000 ), STCP( 0x7fffd886, 0x006487e3 ), STCP( 0x7fff6216, 0x00c90f88 ), @@ -305,7 +306,7 @@ const PWord16 SineTable512[] = { STCP( 0x5a82799a, 0x5a82799a ), }; -const PWord16 SineTable320[] = { +const PWord16 SineTable320[] = { // Q15 STCP( 0x7fffffff, 0x00000000 ), STCP( 0x7fff9aef, 0x00a0d951 ), STCP( 0x7ffe6bbf, 0x0141b1a5 ), STCP( 0x7ffc726f, 0x01e287fc ), STCP( 0x7ff9af04, 0x02835b5a ), STCP( 0x7ff62182, 0x03242abf ), @@ -399,6 +400,7 @@ const PWord16 SineTable320[] = { } const PWord16 SineWindow10[5] = { + // Q15 WTCP( 0x7f9afcb9, 0x0a0af299 ), WTCP( 0x7c769e18, 0x1de189a6 ), WTCP( 0x7641af3d, 0x30fbc54d ), @@ -407,6 +409,7 @@ const PWord16 SineWindow10[5] = { }; const PWord16 SineWindow16[8] = { + // Q15 WTCP( 0x7fd8878e, 0x0647d97c ), WTCP( 0x7e9d55fc, 0x12c8106f ), WTCP( 0x7c29fbee, 0x1f19f97b ), @@ -418,6 +421,7 @@ const PWord16 SineWindow16[8] = { }; const PWord16 SineWindow20[10] = { + // Q15 WTCP( 0x7fe6bcb0, 0x05067734 ), WTCP( 0x7f1cde01, 0x0f0b7727 ), WTCP( 0x7d8a5f40, 0x18f8b83c ), @@ -431,6 +435,7 @@ const PWord16 SineWindow20[10] = { }; const PWord16 SineWindow30[15] = { + // Q15 WTCP( 0x7ff4c56f, 0x0359c428 ), WTCP( 0x7f9afcb9, 0x0a0af299 ), WTCP( 0x7ee7aa4c, 0x10b5150f ), @@ -448,7 +453,7 @@ const PWord16 SineWindow30[15] = { WTCP( 0x5cd91140, 0x581c00b3 ), }; -const PWord16 SineWindow32[16] = { +const PWord16 SineWindow32[16] = { // Q15 WTCP( 0x7ff62182, 0x03242abf ), WTCP( 0x7fa736b4, 0x096a9049 ), WTCP( 0x7f0991c4, 0x0fab272b ), WTCP( 0x7e1d93ea, 0x15e21445 ), WTCP( 0x7ce3ceb2, 0x1c0b826a ), WTCP( 0x7b5d039e, 0x2223a4c5 ), WTCP( 0x798a23b1, 0x2826b928 ), WTCP( 0x776c4edb, 0x2e110a62 ), WTCP( 0x7504d345, 0x33def287 ), WTCP( 0x72552c85, 0x398cdd32 ), WTCP( 0x6f5f02b2, 0x3f1749b8 ), WTCP( 0x6c242960, 0x447acd50 ), @@ -456,6 +461,7 @@ const PWord16 SineWindow32[16] = { }; const PWord16 SineWindow40[20] = { + // Q15 WTCP( 0x7ff9af04, 0x02835b5a ), WTCP( 0x7fc72ae2, 0x07891418 ), WTCP( 0x7f62368f, 0x0c8bd35e ), @@ -478,7 +484,7 @@ const PWord16 SineWindow40[20] = { WTCP( 0x5c44ee40, 0x58b71632 ), }; -const PWord16 SineWindow48[24] = { +const PWord16 SineWindow48[24] = { // Q15 WTCP( 0x7ffb9d15, 0x02182427 ), WTCP( 0x7fd8878e, 0x0647d97c ), WTCP( 0x7f92661d, 0x0a75d60e ), WTCP( 0x7f294bfd, 0x0ea0f48c ), WTCP( 0x7e9d55fc, 0x12c8106f ), WTCP( 0x7deeaa7a, 0x16ea0646 ), WTCP( 0x7d1d7958, 0x1b05b40f ), WTCP( 0x7c29fbee, 0x1f19f97b ), WTCP( 0x7b1474fd, 0x2325b847 ), WTCP( 0x79dd3098, 0x2727d486 ), WTCP( 0x78848414, 0x2b1f34eb ), WTCP( 0x770acdec, 0x2f0ac320 ), @@ -488,6 +494,7 @@ const PWord16 SineWindow48[24] = { }; const PWord16 SineWindow60[60] = { + // Q15 WTCP( 0x7ffd3154, 0x01aceb7c ), WTCP( 0x7fe6bcb0, 0x05067734 ), WTCP( 0x7fb9d759, 0x085f2137 ), @@ -521,6 +528,7 @@ const PWord16 SineWindow60[60] = { }; const PWord16 SineWindow64[32] = { + // Q15 WTCP( 0x7ffd885a, 0x01921d20 ), WTCP( 0x7fe9cbc0, 0x04b6195d ), WTCP( 0x7fc25596, 0x07d95b9e ), @@ -556,6 +564,7 @@ const PWord16 SineWindow64[32] = { }; const PWord16 SineWindow80[40] = { + // Q15 WTCP( 0x7ffe6bbf, 0x0141b1a5 ), WTCP( 0x7ff1c9ef, 0x03c4f52f ), WTCP( 0x7fd8878e, 0x0647d97c ), @@ -598,7 +607,7 @@ const PWord16 SineWindow80[40] = { WTCP( 0x5b64d492, 0x599de2ee ), }; -const PWord16 SineWindow70[35] = { +const PWord16 SineWindow70[35] = { // Q15 WTCP( 0x7ffdeffe, 0x016fa5fd ), WTCP( 0x7fed7058, 0x044ec292 ), WTCP( 0x7fcc732b, 0x072d5101 ), WTCP( 0x7f9afcb9, 0x0a0af299 ), WTCP( 0x7f591361, 0x0ce748ca ), WTCP( 0x7f06bfa3, 0x0fc1f52d ), WTCP( 0x7ea40c1b, 0x129a9991 ), WTCP( 0x7e310583, 0x1570d80b ), WTCP( 0x7dadbaaf, 0x184452fd ), WTCP( 0x7d1a3c8a, 0x1b14ad24 ), WTCP( 0x7c769e18, 0x1de189a6 ), WTCP( 0x7bc2f470, 0x20aa8c19 ), @@ -610,7 +619,7 @@ const PWord16 SineWindow70[35] = { WTCP( 0x5f7133d4, 0x554ad83c ), WTCP( 0x5d811e90, 0x576994c8 ), WTCP( 0x5b84fbb6, 0x597d0cc7 ) }; -const PWord16 SineWindow96[48] = { +const PWord16 SineWindow96[48] = { // Q15 WTCP( 0x7ffee744, 0x010c1460 ), WTCP( 0x7ff62182, 0x03242abf ), WTCP( 0x7fe49698, 0x053c0a01 ), WTCP( 0x7fca47b9, 0x07538d6b ), WTCP( 0x7fa736b4, 0x096a9049 ), WTCP( 0x7f7b65ef, 0x0b80edf1 ), WTCP( 0x7f46d86c, 0x0d9681c2 ), WTCP( 0x7f0991c4, 0x0fab272b ), WTCP( 0x7ec3962a, 0x11beb9aa ), WTCP( 0x7e74ea6a, 0x13d114d0 ), WTCP( 0x7e1d93ea, 0x15e21445 ), WTCP( 0x7dbd98a4, 0x17f193c5 ), @@ -625,7 +634,7 @@ const PWord16 SineWindow96[48] = { WTCP( 0x5f8ab487, 0x552e4605 ), WTCP( 0x5e22a487, 0x56bb8a90 ), WTCP( 0x5cb420e0, 0x5842dd54 ), WTCP( 0x5b3f42ae, 0x59c42381 ) }; -const PWord16 SineWindow112[56] = { +const PWord16 SineWindow112[56] = { // Q15 WTCP( 0x7fff31bf, 0x00e5c87e ), WTCP( 0x7ff8bfc7, 0x02b14de9 ), WTCP( 0x7febdc2a, 0x047cb09e ), WTCP( 0x7fd8878e, 0x0647d97c ), WTCP( 0x7fbec2ec, 0x0812b164 ), WTCP( 0x7f9e8f91, 0x09dd213a ), WTCP( 0x7f77ef1c, 0x0ba711ea ), WTCP( 0x7f4ae37e, 0x0d706c64 ), WTCP( 0x7f176efc, 0x0f3919a0 ), WTCP( 0x7edd942d, 0x110102a0 ), WTCP( 0x7e9d55fc, 0x12c8106f ), WTCP( 0x7e56b7a4, 0x148e2c22 ), @@ -643,6 +652,7 @@ const PWord16 SineWindow112[56] = { }; const PWord16 SineWindow120[60] = { + // Q15 WTCP( 0x7fff4c54, 0x00d676eb ), WTCP( 0x7ff9af04, 0x02835b5a ), WTCP( 0x7fee74a2, 0x0430238f ), @@ -706,6 +716,7 @@ const PWord16 SineWindow120[60] = { }; const PWord16 SineWindow128[64] = { + // Q15 WTCP( 0x7fff6216, 0x00c90f88 ), WTCP( 0x7ffa72d1, 0x025b26d7 ), WTCP( 0x7ff09478, 0x03ed26e6 ), @@ -772,7 +783,7 @@ const PWord16 SineWindow128[64] = { WTCP( 0x5b1035cf, 0x59f3de12 ), }; -const PWord16 SineWindow140[70] = { +const PWord16 SineWindow140[70] = { // Q15 WTCP( 0x7fff7bff, 0x00b7d3bc ), WTCP( 0x7ffb5c00, 0x02277547 ), WTCP( 0x7ff31c25, 0x0397050d ), WTCP( 0x7fe6bcb0, 0x05067734 ), WTCP( 0x7fd63e09, 0x0675bfe7 ), WTCP( 0x7fc1a0b6, 0x07e4d34d ), WTCP( 0x7fa8e564, 0x0953a594 ), WTCP( 0x7f8c0cdc, 0x0ac22ae8 ), WTCP( 0x7f6b180f, 0x0c30577a ), WTCP( 0x7f46080a, 0x0d9e1f7d ), WTCP( 0x7f1cde01, 0x0f0b7727 ), WTCP( 0x7eef9b46, 0x107852b2 ), @@ -794,6 +805,7 @@ const PWord16 SineWindow140[70] = { }; const PWord16 SineWindow160[80] = { + // Q15 WTCP( 0x7fff9aef, 0x00a0d951 ), WTCP( 0x7ffc726f, 0x01e287fc ), WTCP( 0x7ff62182, 0x03242abf ), @@ -877,6 +889,7 @@ const PWord16 SineWindow160[80] = { }; const PWord16 SineWindow180[90] = { + // Q15 WTCP( 0x7fffb026, 0x008efa17 ), WTCP( 0x7ffd3154, 0x01aceb7c ), WTCP( 0x7ff833bd, 0x02cad485 ), @@ -970,7 +983,7 @@ const PWord16 SineWindow180[90] = { }; -const PWord16 SineWindow224[112] = { +const PWord16 SineWindow224[112] = { // Q15 WTCP( 0x7fffcc70, 0x0072e46e ), WTCP( 0x7ffe2fee, 0x0158abd6 ), WTCP( 0x7ffaf6f1, 0x023e6ee8 ), WTCP( 0x7ff62182, 0x03242abf ), WTCP( 0x7fefafb1, 0x0409dc76 ), WTCP( 0x7fe7a192, 0x04ef8129 ), WTCP( 0x7fddf741, 0x05d515f5 ), WTCP( 0x7fd2b0da, 0x06ba97f4 ), WTCP( 0x7fc5ce84, 0x07a00445 ), WTCP( 0x7fb75068, 0x08855802 ), WTCP( 0x7fa736b4, 0x096a9049 ), WTCP( 0x7f95819c, 0x0a4faa38 ), @@ -1003,6 +1016,7 @@ const PWord16 SineWindow224[112] = { const PWord16 SineWindow256[128] = { + // Q15 WTCP( 0x7fffd886, 0x006487e3 ), WTCP( 0x7ffe9cb2, 0x012d96b1 ), WTCP( 0x7ffc250f, 0x01f6a297 ), @@ -1133,7 +1147,7 @@ const PWord16 SineWindow256[128] = { WTCP( 0x5ac973b5, 0x5a3b47ab ), }; -const PWord16 SineWindow280[140] = { +const PWord16 SineWindow280[140] = { // Q15 WTCP( 0x7fffdf00, 0x005be9f6 ), WTCP( 0x7ffed6ff, 0x0113bd23 ), WTCP( 0x7ffcc6ff, 0x01cb8e18 ), WTCP( 0x7ff9af04, 0x02835b5a ), WTCP( 0x7ff58f15, 0x033b236c ), WTCP( 0x7ff0673a, 0x03f2e4d4 ), WTCP( 0x7fea377e, 0x04aa9e17 ), WTCP( 0x7fe2ffee, 0x05624dba ), WTCP( 0x7fdac098, 0x0619f243 ), WTCP( 0x7fd1798e, 0x06d18a36 ), WTCP( 0x7fc72ae2, 0x07891418 ), WTCP( 0x7fbbd4aa, 0x08408e70 ), @@ -1172,6 +1186,7 @@ const PWord16 SineWindow280[140] = { }; const PWord16 SineWindow320[160] = { + // Q15 WTCP( 0x7fffe6bc, 0x00506cb9 ), WTCP( 0x7fff1c9b, 0x00f145ab ), WTCP( 0x7ffd885a, 0x01921d20 ), @@ -1335,7 +1350,7 @@ const PWord16 SineWindow320[160] = { }; -const PWord16 SineWindow420[210] = { +const PWord16 SineWindow420[210] = { // Q15 WTCP( 0x7ffff155, 0x003d46a7 ), WTCP( 0x7fff7bff, 0x00b7d3bc ), WTCP( 0x7ffe9154, 0x01326029 ), WTCP( 0x7ffd3154, 0x01aceb7c ), WTCP( 0x7ffb5c00, 0x02277547 ), WTCP( 0x7ff9115b, 0x02a1fd18 ), WTCP( 0x7ff65166, 0x031c8280 ), WTCP( 0x7ff31c25, 0x0397050d ), WTCP( 0x7fef7199, 0x0411844f ), WTCP( 0x7feb51c6, 0x048bffd7 ), WTCP( 0x7fe6bcb0, 0x05067734 ), WTCP( 0x7fe1b25b, 0x0580e9f6 ), @@ -1392,7 +1407,7 @@ const PWord16 SineWindow420[210] = { }; -const PWord16 *const windowSlopes[1][2][8] = { +const PWord16 *const windowSlopes[1][2][8] = { // Q15 { /* Sine */ { /* Radix 2 */ @@ -1422,7 +1437,7 @@ const PWord16 *const windowSlopes[1][2][8] = { #define DCTIV_SINETABLE320 SineTable320 #define DCTIV_SINETABLE320_SIZE_LD 8 -void BASOP_getTables( const PWord16 **ptwiddle, const PWord16 **sin_twiddle, Word16 *psin_step, Word16 length ) +void BASOP_getTables( const PWord16 **ptwiddle /*Q15*/, const PWord16 **sin_twiddle /*Q15*/, Word16 *psin_step, Word16 length ) { const PWord16 *twiddle; const PWord16 *sine; @@ -1441,7 +1456,7 @@ void BASOP_getTables( const PWord16 **ptwiddle, const PWord16 **sin_twiddle, Wor move16(); sine = DCTIV_SINETABLE320; sin_step = shl( 1, sub( DCTIV_SINETABLE320_SIZE_LD + 1, ld2_length ) ); - twiddle = windowSlopes[0][1][sub( ld2_length, 1 )]; + twiddle = windowSlopes[0][1][ld2_length - 1]; // Q15 BREAK; case 0x8000: /* radix 2 */ @@ -1449,7 +1464,7 @@ void BASOP_getTables( const PWord16 **ptwiddle, const PWord16 **sin_twiddle, Wor move16(); sine = DCTIV_SINETABLE; sin_step = shl( 1, sub( DCTIV_SINETABLE_SIZE_LD + 1, ld2_length ) ); - twiddle = windowSlopes[0][0][sub( ld2_length, 2 )]; + twiddle = windowSlopes[0][0][ld2_length - 2]; // Q15 BREAK; default: /* not instrumented, probably obsolete */ @@ -1486,55 +1501,55 @@ const PWord16 *getSineWindowTable( Word16 length ) switch ( length ) { case 10: - p = SineWindow10; + p = SineWindow10; // Q15 BREAK; case 16: - p = SineWindow16; + p = SineWindow16; // Q15 BREAK; case 20: - p = SineWindow20; + p = SineWindow20; // Q15 BREAK; case 30: - p = SineWindow30; + p = SineWindow30; // Q15 BREAK; case 32: - p = SineWindow32; + p = SineWindow32; // Q15 BREAK; case 40: - p = SineWindow40; + p = SineWindow40; // Q15 BREAK; case 48: - p = SineWindow48; + p = SineWindow48; // Q15 BREAK; case 60: - p = SineWindow60; + p = SineWindow60; // Q15 BREAK; case 70: - p = SineWindow70; + p = SineWindow70; // Q15 BREAK; case 96: - p = SineWindow96; + p = SineWindow96; // Q15 BREAK; case 112: - p = SineWindow112; + p = SineWindow112; // Q15 BREAK; case 120: - p = SineWindow120; + p = SineWindow120; // Q15 BREAK; case 140: - p = SineWindow140; + p = SineWindow140; // Q15 BREAK; case 180: - p = SineWindow180; + p = SineWindow180; // Q15 BREAK; case 224: - p = SineWindow224; + p = SineWindow224; // Q15 BREAK; case 280: - p = SineWindow280; + p = SineWindow280; // Q15 BREAK; case 420: - p = SineWindow420; + p = SineWindow420; // Q15 BREAK; } diff --git a/lib_com/rom_basop_util.h b/lib_com/rom_basop_util.h index 2626f6f43..f2e81f0a1 100644 --- a/lib_com/rom_basop_util.h +++ b/lib_com/rom_basop_util.h @@ -40,14 +40,14 @@ #include "typedef.h" #include "basop_util.h" -extern const PWord16 SineTable512[257]; -extern const PWord16 SineTable320[161]; +extern const PWord16 SineTable512[257]; // Q15 +extern const PWord16 SineTable320[161]; // Q15 /** * \ brief Lookup for sine tables and windows. */ -void BASOP_getTables( const PWord16 **ptwiddle, const PWord16 **sin_twiddle, Word16 *sin_step, Word16 length ); +void BASOP_getTables( const PWord16 **ptwiddle /*Q15*/, const PWord16 **sin_twiddle /*Q15*/, Word16 *psin_step, Word16 length ); const PWord16 *getSineWindowTable( Word16 length ); #endif diff --git a/lib_com/rom_com.c b/lib_com/rom_com.c index a1fc49304..acf416c0a 100644 --- a/lib_com/rom_com.c +++ b/lib_com/rom_com.c @@ -50,13 +50,13 @@ *----------------------------------------------------------------------------------*/ #define W16(x) ((Word16)x) -const int32_t brate_tbl[SIZE_BRATE_TBL] = +const Word32 brate_tbl[SIZE_BRATE_TBL] = // Q0 { ACELP_7k20, ACELP_8k00, ACELP_9k60, ACELP_13k20, ACELP_16k40, ACELP_24k40, ACELP_32k, ACELP_48k, ACELP_64k, HQ_96k, HQ_128k }; -const int32_t brate_intermed_tbl[SIZE_BRATE_INTERMED_TBL] = +const Word32 brate_intermed_tbl[SIZE_BRATE_INTERMED_TBL] = // Q0 { ACELP_5k00, ACELP_6k15, ACELP_7k20, ACELP_8k00, ACELP_9k60, ACELP_11k60, ACELP_12k15, ACELP_12k85, ACELP_13k20, ACELP_14k80, ACELP_16k40, ACELP_22k60, ACELP_24k40, ACELP_29k00, ACELP_29k20, ACELP_30k20, @@ -109,7 +109,7 @@ const FrameSizeParams FrameSizeConfig[FRAME_SIZE_NB] = * - the other values represent indices created by combining different parameters into a single value through the macro SIG2IND() *----------------------------------------------------------------------------------*/ -const int32_t acelp_sig_tbl[MAX_ACELP_SIG] = +const Word32 acelp_sig_tbl[MAX_ACELP_SIG] = // Q0 { /* GENERIC UNVOICED VOICED TRANSITION AUDIO INACTIVE */ ACELP_7k20, 4, @@ -160,7 +160,7 @@ const int32_t acelp_sig_tbl[MAX_ACELP_SIG] = *----------------------------------------------------------------------------------*/ /* bit allocation table for end-frame LSF quantizer */ -const int16_t LSF_bits_tbl[] = +const Word16 LSF_bits_tbl[] = // Q0 { /* IC UC VC GC TC AC */ 22, 31, 24, 29, 24, 22, /* ACELP_5k00 */ @@ -186,7 +186,7 @@ const int16_t LSF_bits_tbl[] = }; /* bit allocation table for mid-frame LSF quantizer */ -const int16_t mid_LSF_bits_tbl[] = +const Word16 mid_LSF_bits_tbl[] = // Q0 { /* IC UC VC GC TC AC */ 2, 5, 1, 2, 2, 2, /* ACELP_5k00 */ @@ -213,7 +213,7 @@ const int16_t mid_LSF_bits_tbl[] = /* bit allocation table for scaled innovation energy prediction */ -const int16_t Es_pred_bits_tbl[] = +const Word16 Es_pred_bits_tbl[] = // Q0 { /* UC VC GC TC */ 0, 0, 0, 4, /* ACELP_5k00 */ @@ -240,7 +240,7 @@ const int16_t Es_pred_bits_tbl[] = /* bit allocation table for gain quantizer (ACELP@12.8kHz) */ /* the 4 values allocated correspond to 4 subframes */ -const int16_t gain_bits_tbl[] = +const Word16 gain_bits_tbl[] = // Q0 { /* UC VC GC TC0_0 TC0_64 TC0_128 TC0_192 TC64 TC128 TC192 */ 6,6,6,6, 7,6,6,6, 7,6,6,6, 5,5,5,5, 5,5,6,5, 5,3,6,6, 5,3,3,6, 3,6,6,6, 3,3,6,6, 3,3,3,10, /* ACELP_5k00 */ @@ -261,7 +261,7 @@ const int16_t gain_bits_tbl[] = /* bit allocation table for gain gain quantizer (ACELP@16kHz) */ /* the 5 values allocated correspond to 5 subframes */ -const int16_t gain_bits_16kHz_tbl[] = +const Word16 gain_bits_16kHz_tbl[] = // Q0 { /* IC GC TC0 TC64 TC128 TC192 TC256 */ 0,0,0,0,0, 6,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0, 0, /* ACELP_8k00 */ @@ -279,7 +279,7 @@ const int16_t gain_bits_16kHz_tbl[] = /* bit allocation table for adaptive codebook (pitch) (ACELP@12.8kHz) */ /* the 4 values correspond to 4 subframes */ -const int16_t ACB_bits_tbl[] = +const Word16 ACB_bits_tbl[] = // Q0 { /* UC VC GC TC0_0 TC0_64 TC0_128 TC0_192 TC64 TC128 TC192 */ 0,0,0,0, 9,5,5,5, 8,5, 8,5, 6,5,6,6, 0,7,6,6, 0,0,7,6, 0,0,0,7, 0,0,9,6, 0,0,5,9, 0,0,0,8, /* ACELP_5k00 */ @@ -299,7 +299,7 @@ const int16_t ACB_bits_tbl[] = /* bit allocation table for adaptive codebook (pitch) (ACELP@16kHz) */ /* the 5 values correspond to 5 subframes */ -const int16_t ACB_bits_16kHz_tbl[] = +const Word16 ACB_bits_16kHz_tbl[] = // Q0 { /* IC GC TC0 TC64 TC128 TC192 TC256 */ 0,0, 0,0,0, 9,0, 0,0,0, 0,0, 0,0,0, 0,0, 0,0,0, 0,0, 0,0,0, 0,0,0, 0,0, 0,0,0,0, 0, /* ACELP_8k00 */ @@ -317,7 +317,7 @@ const int16_t ACB_bits_16kHz_tbl[] = /* bit allocation table for algebraic (fixed) codebook (innovation) (ACELP@12.8kHz) */ /* the 4 values correspond to 4 subframes */ -const int16_t FCB_bits_tbl[] = +const Word16 FCB_bits_tbl[] = // Q0 { /* UC VC GC TC0_0 TC0_64 TC0_128 TC0_192 TC64 TC128 TC192 */ 8,8,8,8, 12,12,12,20, 7, 7, 0, 7, 12, 7,12,12, 12,12, 7,12, 12,12,12,12, 12,12,20,12, 12,12,12,12, 12,12,12,12, 12,12,12,20, /* ACELP_5k00 */ @@ -337,7 +337,7 @@ const int16_t FCB_bits_tbl[] = /* bit allocation table for algebraic (fixed) codebook (innovation) (ACELP@16kHz) */ /* the 5 values correspond to 5 subframes */ -const int16_t FCB_bits_16kHz_tbl[] = +const Word16 FCB_bits_16kHz_tbl[] = // Q0 { /* IC GC TC0 TC64 TC128 TC192 TC256 */ 0, 0, 0, 0, 0, 12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* ACELP_8k00 */ @@ -354,7 +354,7 @@ const int16_t FCB_bits_16kHz_tbl[] = }; /* bit allocation table for AVQ bits in active segments (ACELP@16kHz) */ -const int16_t AVQ_bits_16kHz_tbl[] = +const Word16 AVQ_bits_16kHz_tbl[] = // Q0 { /* IC GC TC0 TC64 TC128 TC192 TC256 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* ACELP_8k00 */ @@ -371,7 +371,7 @@ const int16_t AVQ_bits_16kHz_tbl[] = }; /* bit allocation table for reserved bits (ACELP@12.8kHz) */ -const int16_t reserved_bits_tbl[] = +const Word16 reserved_bits_tbl[] = // Q0 { /* UC VC GC TC0_0 TC0_64 TC0_128 TC0_192 TC64 TC128 TC192 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* ACELP_5k00 */ @@ -390,24 +390,24 @@ const int16_t reserved_bits_tbl[] = }; /* NRG mode */ -const uint8_t ACELP_NRG_MODE[RATE_MODE_MAX][BANDWIDTH_MODE_MAX][ACELP_MODE_MAX+RF_MODE_MAX] = +const UWord8 ACELP_NRG_MODE[RATE_MODE_MAX][BANDWIDTH_MODE_MAX][ACELP_MODE_MAX+RF_MODE_MAX] = // Q0 { {{0,0,1,1,0,0,0,0},{2,2,1,1,0,0,0,0}}, {{1,1,1,1,0,0,0,0},{1,1,1,1,1,1,1,0}}, }; /* NRG bits : (0/2/3 bits) */ -const uint8_t ACELP_NRG_BITS[3] = { 0, 3, 4 }; +const uint8_t ACELP_NRG_BITS[3] = { 0, 3, 4 }; // Q0 /* LTP MODE*/ -const uint8_t ACELP_LTP_MODE[RATE_MODE_MAX][BANDWIDTH_MODE_MAX][ACELP_MODE_MAX+RF_MODE_MAX] = +const UWord8 ACELP_LTP_MODE[RATE_MODE_MAX][BANDWIDTH_MODE_MAX][ACELP_MODE_MAX+RF_MODE_MAX] = // Q0 { {{0,0,1,2,0,0,0,0},{0,0,1,2,0,0,0,0}}, {{4,4,3,4,0,0,0,0},{4,4,3,4,8,0,9,0}}, }; /* LTP bits */ -const uint8_t ACELP_LTP_BITS_SFR[8+RF_MODE_MAX][5] = +const UWord8 ACELP_LTP_BITS_SFR[8+RF_MODE_MAX][5] = // Q0 { {0,0,0,0,0}, {8,4,4,4,4}, @@ -423,25 +423,25 @@ const uint8_t ACELP_LTP_BITS_SFR[8+RF_MODE_MAX][5] = /* LTF modes (0 - LOW_PASS (LP filtering), 1 - FULL_BAND (no filtering), 2 - NORMAL_OPERATION (adaptive)) */ /* Mode 2 ACELP: INACTIVE,UNVOICED,VOICED,GENERIC */ -const uint8_t ACELP_LTF_MODE[RATE_MODE_MAX][BANDWIDTH_MODE_MAX][ACELP_MODE_MAX+RF_MODE_MAX] = +const UWord8 ACELP_LTF_MODE[RATE_MODE_MAX][BANDWIDTH_MODE_MAX][ACELP_MODE_MAX+RF_MODE_MAX] = // Q0 { {{1,1,1,0,0,0,0,0},{1,1,1,0,0,0,0,0}}, {{0,0,2,0,0,0,0,0},{0,0,2,0,1,1,1,0}}, }; /* LTF bits */ -const uint8_t ACELP_LTF_BITS[4] = { 0, 0, 4, 0 }; +const UWord8 ACELP_LTF_BITS[4] = { 0, 0, 4, 0 }; // Q0 /* GAINS ELEMENT */ /* 5 modes: (EVS: 5b/subframe), (AMRWB: 7b/subframe),(AMRWB: 6b/subframe),(UC: 5b/subframe) */ -const uint8_t ACELP_GAINS_MODE[RATE_MODE_MAX][BANDWIDTH_MODE_MAX][ACELP_MODE_MAX+RF_MODE_MAX] = +const UWord8 ACELP_GAINS_MODE[RATE_MODE_MAX][BANDWIDTH_MODE_MAX][ACELP_MODE_MAX+RF_MODE_MAX] = // Q0 { {{6,6,1,1,0,0,0,0},{7,7,1,1,0,0,0,0}}, {{2,2,3,3,0,0,0,0},{2,2,3,3,3,2,1,0}}, }; /* gains bits */ -const uint8_t ACELP_GAINS_BITS[10] = +const UWord8 ACELP_GAINS_BITS[10] = // Q0 { 0, /* skip sub-frame wise gain coding*/ 5, @@ -456,14 +456,14 @@ const uint8_t ACELP_GAINS_BITS[10] = }; /* BPF modes (0 - no filtering, 1 - filtering, 2 - adaptive) */ -const uint8_t ACELP_BPF_MODE[RATE_MODE_MAX][BANDWIDTH_MODE_MAX][ACELP_MODE_MAX+RF_MODE_MAX] = +const UWord8 ACELP_BPF_MODE[RATE_MODE_MAX][BANDWIDTH_MODE_MAX][ACELP_MODE_MAX+RF_MODE_MAX] = // Q0 { {{1,1,1,1,0,0,0,0},{1,1,1,1,0,0,0,0}}, {{1,1,2,2,0,0,0,0},{1,1,2,2,1,1,1,1}}, }; /* BPF bits */ -const uint8_t ACELP_BPF_BITS[3] = { 0, 0, 2 }; +const UWord8 ACELP_BPF_BITS[3] = { 0, 0, 2 }; // Q0 const Word16 ACELP_CDK_BITS[ACELP_FIXED_CDK_NB] = { 7, 10, 12, 15, 17, 20, 24, 26, 28, 30, 32, 34, 36, 40, 43, 46, @@ -495,12 +495,12 @@ const float crit_bins_corr[CRIT_NOIS_BAND] = 0.60f, 0.6f, 0.6f, 0.6f, 0.6f, 0.6f, 0.6f, 0.6f, 0.6f, 0.6f, 0.6f, 0.6f }; const Word16 crit_bins_corr_fx[CRIT_NOIS_BAND] = -{ +{//Q15 /*.9f, .9f, .85f, .8f, .775f, .75f, .725f , .7f , .675f, .65f, .625f , .60f, .6f, .6f, .6f, .6f, .6f, .6f, .6f, .6f, .6f, .6f, .6f*/ 29491, 29491, 27853, 26214, 25395, 24576, 23577 , 22938, 22118, 21299, 20480, 19661, 19661, 19661, 19661, 19661, 19661, 19661, 19661, 19661, 19661, 19661, 19661 }; -const int16_t crit_bins[CRIT_NOIS_BAND] = +const Word16 crit_bins[CRIT_NOIS_BAND] = // Q0 { 4, 4, 4, 4, 4, 5, 6, 6, 6, 8, 8, 10, 11, 13, 15, 18, 22, 16, 16, 20, 20, 20, 16 }; @@ -511,7 +511,7 @@ const float crit_bands_loc[CRIT_NOIS_BAND] = 1720.0f, 2000.0f, 2320.0f, 2700.0f, 3150.0f, 3700.0f, 4100.0f, 4500.0f, 5000.0f, 5500.0f, 6000.0f, 6375.0f }; const Word16 crit_bands_loc_fx[CRIT_NOIS_BAND] = -{ +{//Q0 100, 200, 300, 400, 510, 630, 770, 920, 1080, 1270, 1480, 1720, 2000, 2320, 2700, 3150, 3700, 4100, 4500, 5000, 5500, 6000, 6375 }; @@ -553,7 +553,7 @@ const float inv_tbl[130] = 0.0077519380f /* last val = 1/129 */ }; -const Word16 inv_tbl_fx[146] = +const Word16 inv_tbl_fx[146] =//Q15 { 0, 32767, 16384, 10923, 8192, 6554, 5462, 4681, 4096, 3641, 3277, 2979, 2731, 2521, 2341, 2185, @@ -639,7 +639,7 @@ const Word32 thren_fx[39] = /* Q8 */ 108, 76, 54 }; -const Word16 dicnlg2[40] = +const Word16 dicnlg2[40] = // Q0 { 34, 33, 32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, @@ -655,13 +655,13 @@ const float mfreq_loc_LD[] = { 100.0f, 200.0f, 300.0f, 400.0f, 510.0f, 630.0f, 7 1720.0f, 2000.0f, 2320.0f, 2700.0f, 3150.0f, 3700.0f, 4400.0f, 5300.0f, (6400.0f-BIN_16kdct) }; -const Word16 mfreq_loc_LD_fx[] = { 100, 200, 300, 400, 510, 630, 770, 920, 1080, 1270, 1480, +const Word16 mfreq_loc_LD_fx[] = { 100, 200, 300, 400, 510, 630, 770, 920, 1080, 1270, 1480,//Q0 1720, 2000, 2320, 2700, 3150, 3700, 4400, 5300, (6400 - BIN_16kdct_fx) }; -const int16_t mfreq_bindiv_LD[] = {10, 10, 10, 10, 11, 12, 14, 15, 16, 19, 21, 24, 28, 32, 38, 45, 55, 70, 90, 110}; +const Word16 mfreq_bindiv_LD[] = {10, 10, 10, 10, 11, 12, 14, 15, 16, 19, 21, 24, 28, 32, 38, 45, 55, 70, 90, 110}; // Q0 const float sc_qnoise[] = {0.1f,0.1f,0.1f,0.1f,0.1f,0.1f,0.09091f,0.09091f,0.09091f,0.09091f,0.09091f,0.09091f,0.09091f,0.09091f,0.09091f,0.06667f,0.06667f,0.06667f,0.06667f,0.06667f}; -const Word16 sc_qnoise_fx[] = { 3277, 3277, 3277, 3277, 3277, 3277, 2979, 2979, 2979, 2979, 2979, 2979, 2979, 2979, 2979, 2185, 2185, 2185, 2185, 2185 }; +const Word16 sc_qnoise_fx[] = { 3277, 3277, 3277, 3277, 3277, 3277, 2979, 2979, 2979, 2979, 2979, 2979, 2979, 2979, 2979, 2185, 2185, 2185, 2185, 2185 };//Q15 const Word16 inv_mfreq_bindiv_LD_fx[] = { 3277, 3277, 3277, 3277, 2979, 2731, 2341, 2185, 2048, 1725, 1560, 1365, 1170, 1024, 862, 728, 596, 468, 364, 298 }; /*Q15 */ const Word16 inv_mfreq_bindiv_LD_M1_fx[] = { 3641, 3641, 3641, 3641, 3277, 2979, 2521, 2341, 2185, 1820, 1638, 1425, 1214, 1057, 886, 745, 607, 475, 368, 301 }; /*Q15 */ @@ -723,9 +723,9 @@ const Word16 post_dct_wind_fx[OFFSET2] = /*Q15 */ const float MAX_SNR_SNR1_tab[MBANDS_GN_LD] = { 1.026316f, 1.026316f, 1.026316f, 1.026316f, 1.026316f, 1.026316f, 1.026316f, 1.026316f, 1.026316f, 1.026316f, 1.026316f, 1.026316f, 1.026316f, 1.026316f, 1.026316f, 1.02631627f, 1.043478f, 1.043478f, 1.043478f, 1.043478f}; const float INV_MAX_SNR_tab[MBANDS_GN_LD] = { .026316f, .026316f, .026316f, .026316f, .026316f, .026316f, .026316f, .026316f, .026316f, .026316f, .026316f, .026316f, .026316f, .026316f, .026316f, .026316f, .043478f, .043478f, .043478f, .043478f}; -const Word16 MAX_SNR_SNR1_tab_FX[MBANDS_GN_LD] = { 16815, 16815, 16815, 16815, 16815, 16815, 16815, 16815, 16815, 16815, 16815, 16815, 16815, 16815, 16815, 16815, 17096, 17096, 17096, 17096 }; +const Word16 MAX_SNR_SNR1_tab_FX[MBANDS_GN_LD] = { 16815, 16815, 16815, 16815, 16815, 16815, 16815, 16815, 16815, 16815, 16815, 16815, 16815, 16815, 16815, 16815, 17096, 17096, 17096, 17096 };//Q14 -const Word16 INV_MAX_SNR_tab_FX[MBANDS_GN_LD] = { 862, 862, 862, 862, 862, 862, 862, 862, 862, 862, 862, 862, 862, 862, 862, 862, 1425, 1425, 1425, 1425 }; +const Word16 INV_MAX_SNR_tab_FX[MBANDS_GN_LD] = { 862, 862, 862, 862, 862, 862, 862, 862, 862, 862, 862, 862, 862, 862, 862, 862, 1425, 1425, 1425, 1425 };//Q15 const float wind_sss[LEN_WIN_SSS] = /* window for subsampling */ { @@ -746,7 +746,7 @@ const float wind_sss[LEN_WIN_SSS] = /* window for subsampling */ 1.000000f, 0.979530f, 0.918958f, 0.820763f, 0.688967f, 0.528964f, 0.347305f, 0.151428f }; const Word16 wind_sss_fx[LEN_WIN_SSS] = /*window for subsampling*/ -{ +{//Q15 2621, 2627, 2645, 2675, 2717, 2771, 2836, 2914, 3003, 3103, 3216, 3340, 3475, 3621, 3779, 3948, 4127, 4318, 4519, 4730, 4952, 5184, 5426, 5677, @@ -1198,13 +1198,13 @@ const float lag_window_48k_flt[17] = 0.994801176082f, 0.993973102356f, 0.993084457589f, 0.992135405511f }; -const Word16 lag_window_8k[2][16] = /* LAGW_STRONG */ +const Word16 lag_window_8k[2][16] = /* LAGW_STRONG Q15*/ { /* h */ { 32728, 32619, 32438, 32187, 31867, 31480, 31029, 30517, 29946, 29321, 28645, 27923, 27158, 26356, 25521, 24658 }, /* l */ { 11904, 17280, 30720, 25856, 24192, 28992, 24384, 7360, 19456, 14720, 22080, 12928, 31040, 27328, 22080, 5184 } }; const Word16 lag_window_12k8[NUM_LAGW_STRENGTHS][2][16] = -{ +{//Q15 /* LAGW_WEAK */ { /* h */ { 32763, 32758, 32750, 32739, 32725, 32707, 32687, 32663, 32637, 32607, 32574, 32538, 32498, 32456, 32411, 32362 }, @@ -1222,7 +1222,7 @@ const Word16 lag_window_12k8[NUM_LAGW_STRENGTHS][2][16] = } }; const Word16 lag_window_16k[NUM_LAGW_STRENGTHS][2][16] = -{ +{//Q15 /* LAGW_WEAK */ { /* h */ { 32763, 32760, 32755, 32748, 32739, 32728, 32715, 32700, 32682, 32663, 32642, 32619, 32594, 32567, 32538, 32507 }, @@ -1240,7 +1240,7 @@ const Word16 lag_window_16k[NUM_LAGW_STRENGTHS][2][16] = } }; const Word16 lag_window_25k6[NUM_LAGW_STRENGTHS][2][16] = -{ +{//Q15 /* LAGW_WEAK */ { /* h */ { 32764, 32763, 32761, 32758, 32754, 32750, 32745, 32739, 32732, 32725, 32716, 32707, 32698, 32687, 32676, 32663 }, @@ -1258,7 +1258,7 @@ const Word16 lag_window_25k6[NUM_LAGW_STRENGTHS][2][16] = } }; const Word16 lag_window_32k[NUM_LAGW_STRENGTHS][2][16] = -{ +{//Q15 /* LAGW_WEAK */ { /* h */ { 32764, 32763, 32762, 32760, 32758, 32755, 32752, 32748, 32744, 32739, 32734, 32728, 32722, 32715, 32707, 32700 }, @@ -1276,19 +1276,19 @@ const Word16 lag_window_32k[NUM_LAGW_STRENGTHS][2][16] = } }; const Word16 lag_window_48k[2][16] = /* LAGW_STRONG */ -{ +{//Q15 /* h */ { 32763, 32760, 32755, 32748, 32739, 32728, 32715, 32700, 32682, 32663, 32642, 32619, 32594, 32567, 32538, 32507 }, /* l */ { 23360, 22272, 20672, 18304, 15360, 11904, 8000, 3648, 31808, 27008, 22080, 17280, 12608, 8256, 4480, 1344 } }; /* 32 bit declarations */ const Word32 lag_window_8k_32[16] = /* LAGW_STRONG */ -{ +{//Q31 2144886016, 2137753344, 2125918208, 2109458944, 2088484096, 2063131264, 2033565312, 1999976832, 1962579968, 1921610496, 1877322880, 1829987584, 1779888768, 1727321472, 1672588416, 1615997056 }; const Word32 lag_window_12k8_32[NUM_LAGW_STRENGTHS][16] = -{ +{//Q31 /* LAGW_WEAK */ { 2147165440, 2146854912, 2146337792, 2145613824, 2144683392, 2143546880, 2142204288, 2140656384, 2138903424, 2136945792, 2134784256, 2132419328, 2129851776, 2127082368, 2124111616, 2120940800 @@ -1304,7 +1304,7 @@ const Word32 lag_window_12k8_32[NUM_LAGW_STRENGTHS][16] = }; const Word32 lag_window_16k_32[NUM_LAGW_STRENGTHS][16] = -{ +{//Q31 /* LAGW_WEAK */ { 2147202688, 2147003904, 2146673024, 2146209536, 2145613824, 2144886016, 2144026240, 2143034496, 2141911168, 2140656384, 2139270272, 2137753344, 2136105600, 2134327424, 2132419328, 2130381440 @@ -1319,7 +1319,7 @@ const Word32 lag_window_16k_32[NUM_LAGW_STRENGTHS][16] = } }; const Word32 lag_window_25k6_32[NUM_LAGW_STRENGTHS][16] = -{ +{//Q31 /* LAGW_WEAK */ { 2147243008, 2147165440, 2147036032, 2146854912, 2146622336, 2146337792, 2146001664, 2145613824, 2145174400, 2144683392, 2144140928, 2143546880, 2142901376, 2142204288, 2141456000, 2140656384 @@ -1334,7 +1334,7 @@ const Word32 lag_window_25k6_32[NUM_LAGW_STRENGTHS][16] = } }; const Word32 lag_window_32k_32[NUM_LAGW_STRENGTHS][16] = -{ +{//Q31 /* LAGW_WEAK */ { 2147252352, 2147202688, 2147119872, 2147003904, 2146854912, 2146673024, 2146457728, 2146209536, 2145928192, 2145613824, 2145266432, 2144886016, 2144472576, 2144026240, 2143546880, 2143034496 @@ -1349,7 +1349,7 @@ const Word32 lag_window_32k_32[NUM_LAGW_STRENGTHS][16] = } }; const Word32 lag_window_48k_32[16] = /* LAGW_STRONG */ -{ +{//Q31 2147202688, 2147003904, 2146673024, 2146209536, 2145613824, 2144886016, 2144026240, 2143034496, 2141911168, 2140656384, 2139270272, 2137753344, 2136105600, 2134327424, 2132419328, 2130381440 }; /*----------------------------------------------------------------------------------* @@ -1374,7 +1374,7 @@ const float grid40[(GRID40_POINTS-1)/2 - 1] = #ifdef IVAS_FLOAT_FIXED const Word16 grid50_fx[(GRID50_POINTS - 1) / 2 - 1] = -{ +{//Q15 32703, 32510, 32188, 31739, 31164, 30467, 29649, 28715, 27667, 26510, 25248, 23887, 22431, 20887, 19261, 17558, 15786, 13952, @@ -1382,7 +1382,7 @@ const Word16 grid50_fx[(GRID50_POINTS - 1) / 2 - 1] = }; const Word16 grid40_fx[(GRID40_POINTS - 1) / 2 - 1] = -{ +{//Q15 32667, 32365, 31863, 31164, 30274, 29197, 27939, 26510, 24917, 23170, 21281, 19261, 17121, 14876, 12540, 10126, 7650, 5126, @@ -1588,7 +1588,7 @@ const float sincos_t_ext[641] = -0.676092703575316f, -0.680600997795453f, -0.685083667772700f, -0.689540544737067f, -0.693971460889654f, -0.698376249408973f, -0.702754744457225f, -0.707106781186547f }; const Word16 sincos_t_ext_fx[641] = -{ +{//Q15 0, 201, 402, 603, 804, 1005, 1206, 1407, 1608, 1809, 2009, 2210, 2411, 2611, 2811, 3012, 3212, 3412, 3612, 3812, 4011, 4211, 4410, 4609, @@ -1733,7 +1733,8 @@ const Word16 Asr_LP48_fx[61] = 0, -407, -592, -571, -408, -192, 0, 123, 167, 146, 93, 38, 0 }; -const Word16 fft256_read_indexes[]= + +const Word16 fft256_read_indexes[]= // Q0 { 0, 128, 64, 192, 32, 160, 96, 224, 16, 144, 80, 208, 48, 176, 112, 240, 8, 136, 72, 200, 40, 168, 104, 232, 24, 152, 88, 216, 56, 184, 120, 248, @@ -1792,7 +1793,7 @@ const float sin_table256[] = }; const Word16 sin_table256_fx[] = -{ +{//Q15 101, 302, 503, 704, 905, 1106, 1307, 1507, 1708, 1909, 2110, 2310, 2511, 2711, 2912, 3112, 3312, 3512, 3712, 3911, 4111, 4310, 4510, 4709, 4907, 5106, 5305, @@ -1850,7 +1851,7 @@ const float inter4_2[65] = const Word16 inter4_2_fx_Q15[65] = -{ +{//Q15 30801, 28062, 20718, 11061, 1935, -4294, -6533, -5195, -1846, @@ -1871,7 +1872,7 @@ const Word16 inter4_2_fx_Q15[65] = }; const Word16 inter4_2_fx[] = -{ +{//evs table , some mismatch in values compared to float is observed 0, 1, 2, 1, -2, -7, -10, -7, 4, 19, 28, 22, @@ -2116,7 +2117,7 @@ static const float filter_LP12_180H[] = /* Sincfilt.m: N=180*2+1, Fmin=0, Fmax }; const Word16 filter_LP12_180H_fx[] = /* Sincfilt.m: N=180*2+1, Fmin=0, Fmax=1/12, hann( N )' */ -{ +{//Q14 16384, 16196, 15641, 14741, 13533, 12067, 10402, 8604, 6742, 4887, 3105, 1459, 0, -1230, -2202, -2900, -3322, -3478, @@ -2150,7 +2151,7 @@ const Word16 filter_LP12_180H_fx[] = /* Sincfilt.m: N=180*2+1, Fmin=0, Fmax=1/ 0 }; const Word16 filter_LP12_180H_13b_fx[] = /*Q13 Sincfilt.m: N=180*2+1, Fmin=0, Fmax=1/12, hann( N )*/ -{ +{//Q13 8192, 8098, 7820, 7370, 6766, 6033, 5201, 4302, 3371, 2443, 1553, 729, 0, -615, -1101, -1450, -1661, -1739, @@ -2226,7 +2227,7 @@ static const float filter_LP15_180H[] = /* Sincfilt.m: N=180*2+1, Fmin=0, Fmax }; const Word16 filter_LP15_180H_fx[] = /* Sincfilt.m: N=180*2+1, Fmin=0, Fmax=1/15, hann( N )' */ -{ +{//Q14 16384, 16263, 15904, 15317, 14516, 13524, 12366, 11073, 9678, 8216, 6723, 5236, 3790, 2416, 1144, 0, -997, -1831, @@ -2261,7 +2262,7 @@ const Word16 filter_LP15_180H_fx[] = /* Sincfilt.m: N=180*2+1, Fmin=0, Fmax=1/ }; const Word16 filter_LP15_180H_13b_fx[6 * 31] = /*Q13 Sincfilt.m: N=180*2+1, Fmin=0, Fmax=1/12, hann( N )'*/ -{ +{//Q13 8192, 8132, 7952, 7658, 7258, 6762, 6183, 5536, 4839, 4108, 3362, 2618, 1895, 1208, 572, 0, -498, -915, @@ -2321,7 +2322,7 @@ static const float filter_LP24_90H[] = { }; const Word16 filter_LP24_90H_fx[] = -{ +{//Q14 10240, 10208, 10111, 9951, 9731, 9452, 9119, 8734, 8304, 7834, @@ -2348,7 +2349,7 @@ const Word16 filter_LP24_90H_fx[] = }; const Word16 filter_LP24_90H_13b_fx[] = -{ +{//Q13 5120, 5104, 5056, 4976, 4865, 4726, 4559, 4367, 4152, 3917, @@ -2395,7 +2396,7 @@ static const float filter_LP3_90H[] = /* Sincfilt.m: N=90*2+1, Fmin=0, Fmax=1/ }; const Word16 filter_LP3_90H_fx[] = /* Sincfilt.m: N=90*2+1, Fmin=0, Fmax=1/3, hann( N )' */ -{ +{//Q14 16384, 13545, 6766, 0, -3371, -2689, 0, 1907, 1661, 0, -1314, -1187, 0, 990, 911, 0, -783, -729, @@ -2465,7 +2466,7 @@ static const float filter_LP15_360H[] = /* Sincfilt.m: N=360*2+1, Fmin=0, Fmax }; const Word16 filter_LP15_360H_13b_fx[] = /* Sincfilt.m: N=360*2+1, Fmin=0, Fmax=1/15, hann( N )' */ -{ +{//Q13 8192, 8132, 7954, 7662, 7265, 6772, 6196, 5552, 4857, 4127, 3381, 2636, 1911, 1220, 579, 0, @@ -2560,7 +2561,7 @@ static const float filter_LP30_300K[LFE_PLC_FDEL + 1] = /* 800/24000 LP filter }; static const Word16 filter_LP30_300K_fx[LFE_PLC_FDEL + 1] = -{ +{//Q14 16395,16364,16273,16123,15913,15646,15323,14947,14520,14045,13524,12963,12363,11730,11067,10379,9669, 8943,8205,7460,6712,5965,5225,4495,3779,3082,2408,1759,1140,552,0,-515,-991,-1426,-1819,-2169,-2475, -2736,-2953,-3126,-3257,-3345,-3392,-3400,-3371,-3307,-3210,-3083,-2928,-2749,-2547,-2327,-2091,-1842, @@ -2623,7 +2624,7 @@ const float interpol_frac2[NB_SUBFR] = { 0.5f, 0.5f, 1.0f, 1.0f }; -const Word16 interpol_frac2_fx[NB_SUBFR] = { +const Word16 interpol_frac2_fx[NB_SUBFR] = {//Q15 16384, 16384, 32767, 32767 }; @@ -2634,7 +2635,7 @@ const float interpol_frac2_mid[NB_SUBFR*3] = { 0.0f, 0.25f, 0.75f }; -const Word16 interpol_frac2_mid_fx[NB_SUBFR * 3] = { +const Word16 interpol_frac2_mid_fx[NB_SUBFR * 3] = {//Q15 8191, 24575, 0, 8191, 24575, 0, 0, 8191, 24575, @@ -2645,12 +2646,13 @@ const float interpol_frac_12k8[NB_SUBFR] = { 0.25f, 0.5f, 0.75f, 1.0f }; -const Word16 interpol_frac_12k8_fx[NB_SUBFR] = { +const Word16 interpol_frac_12k8_fx[NB_SUBFR] = {//Q15 8191, 16383, 24575, 32767 }; const Word16 interpol_frac_fx[NB_SUBFR] = { 8192, 16384, 24576,32767 };/*Q15*/ + const float interpol_isp_amr_wb[NB_SUBFR] = { 0.45f, 0.8f, 0.96f, 1.0f }; @@ -2661,7 +2663,9 @@ const float interpol_frac_16k[NB_SUBFR16k] = { 0.2f, 0.4f, 0.6f, 0.8f, 1.0f }; -const Word16 interpol_frac_16k_fx[NB_SUBFR16k] = { 6554, 13107, 19661, 26214, 32767 };/*Q15*/ + +const Word16 interpol_frac_16k_fx[NB_SUBFR16k] = { 6554, 13107, 19661, 26214, 32767 };//Q15 + const float interpol_frac_mid[NB_SUBFR*3] = { 0.5f, 0.5f, 0.0f, @@ -2669,7 +2673,7 @@ const float interpol_frac_mid[NB_SUBFR*3] = { 0.0f, 0.5f, 0.5f, 0.0f, 0.0f, 1.0f }; -const Word16 interpol_frac_mid_fx[NB_SUBFR * 3] = { 16384, 16384, 0, +const Word16 interpol_frac_mid_fx[NB_SUBFR * 3] = { 16384, 16384, 0,//Q15 0, 32767, 0, 0, 16384, 16384, 0, 0, 32767 @@ -2682,7 +2686,7 @@ const float interpol_frac_mid_16k[NB_SUBFR16k*3] = { 0.0f, 0.35f, 0.65f, 0.0f, 0.0f, 1.0f }; -const Word16 interpol_frac_mid_16k_fx[NB_SUBFR16k * 3] = { 18022, 14746, 0, +const Word16 interpol_frac_mid_16k_fx[NB_SUBFR16k * 3] = { 18022, 14746, 0,//Q15 4915, 27853, 0, 0, 24576, 8192, 0, 11469, 21299, @@ -2695,7 +2699,7 @@ const float interpol_frac_mid_relaxprev_12k8[NB_SUBFR*3] = { 0.0f, 0.0f, 1.0f }; -const Word16 interpol_frac_mid_relaxprev_12k8_fx[NB_SUBFR * 3] = { 0, 22938, 9830, +const Word16 interpol_frac_mid_relaxprev_12k8_fx[NB_SUBFR * 3] = { 0, 22938, 9830,//Q15 0, 0, 32767, 0, 0, 32767, 0, 0, 32767 @@ -2706,7 +2710,7 @@ const float interpol_frac_mid_FEC[NB_SUBFR*3] = { 0.00f, 0.45f, 0.55f, 0.00f, 0.00f, 1.00f }; -const Word16 interpol_frac_mid_FEC_fx[NB_SUBFR * 3] = { 8192, 18022, 6554, +const Word16 interpol_frac_mid_FEC_fx[NB_SUBFR * 3] = { 8192, 18022, 6554,//Q15 0, 22938, 9830, 0, 14746, 18022, 0, 0, 32767 @@ -2719,7 +2723,7 @@ const float interpol_frac_mid_relaxprev_pred_12k8[NB_SUBFR*3] = { 0.00f, 0.50f, 0.50f, 0.00f, 0.0f, 1.00f }; -const Word16 interpol_frac_mid_relaxprev_pred_12k8_fx[NB_SUBFR * 3] = { 4915, 22938, 4915, +const Word16 interpol_frac_mid_relaxprev_pred_12k8_fx[NB_SUBFR * 3] = { 4915, 22938, 4915,//Q15 1638, 21299, 9830, 0, 16384, 16384, 0, 0, 32767 @@ -2732,7 +2736,7 @@ const float interpol_frac_mid_relaxprev_16k[NB_SUBFR16k*3] = { 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f }; -const Word16 interpol_frac_mid_relaxprev_16k_fx[NB_SUBFR16k * 3] = { 0, 22938, 9830, +const Word16 interpol_frac_mid_relaxprev_16k_fx[NB_SUBFR16k * 3] = { 0, 22938, 9830,//Q15 0, 0, 32767, 0, 0, 32767, 0, 0, 32767, @@ -2747,7 +2751,7 @@ const float interpol_frac_mid_16k_FEC[NB_SUBFR16k*3] = { 0.0f, 0.15f, 0.85f, 0.0f, 0.00f, 1.00f }; -const Word16 interpol_frac_mid_16k_FEC_fx[NB_SUBFR16k * 3] = { 13107, 13107, 6554, +const Word16 interpol_frac_mid_16k_FEC_fx[NB_SUBFR16k * 3] = { 13107, 13107, 6554,//Q15 0, 26214, 6554, 0, 21299, 11469, 0, 4915, 27853, @@ -2761,7 +2765,7 @@ const float interpol_frac_mid_relaxprev_pred_16k[NB_SUBFR16k*3] = { 0.00f, 0.15f, 0.85f, 0.00f, 0.0f, 1.00f }; -const Word16 interpol_frac_mid_relaxprev_pred_16k_fx[NB_SUBFR16k * 3] = { 4915, 22938, 4915, +const Word16 interpol_frac_mid_relaxprev_pred_16k_fx[NB_SUBFR16k * 3] = { 4915, 22938, 4915,//Q15 1638, 21299, 9830, 0, 16384, 16384, 0, 4915, 27853, @@ -2981,7 +2985,7 @@ const float gain_qua_mless_7b[128*2] = 1.2298f, 1.0376f }; const Word16 gain_qua_mless_7b_fx[128*2] = -{ +{//Q14 419, 28, 1499, 607, 1586, 322, @@ -3180,7 +3184,7 @@ const float gain_qua_mless_6b_stereo[64*2]= }; const Word16 gain_qua_mless_6b_stereo_fx[64 * 2] = -{ +{//Q14 570, 695, 932, 535, 972, 913, @@ -3315,7 +3319,7 @@ const float gain_qua_mless_6b[64*2] = 1.1911f, 0.6722f }; const Word16 gain_qua_mless_6b_fx[64 * 2] = -{ +{//Q14 1676, 71, 2128, 198, 2318, 491, @@ -3417,7 +3421,7 @@ const float gain_qua_mless_5b[32*2] = 1.1529f, 0.9632f }; const Word16 gain_qua_mless_5b_fx[32 * 2] = -{ +{//Q14 2695, 109, 3444, 271, 3529, 433, @@ -3452,8 +3456,8 @@ const Word16 gain_qua_mless_5b_fx[32 * 2] = 18889, 493, }; -const int16_t E_ROM_qua_gain5b_const[NB_QUA_GAIN5B * 2]= -{ +const Word16 E_ROM_qua_gain5b_const[NB_QUA_GAIN5B * 2]= +{//Q0 1774,577, 2090,1805, 2103,3371, @@ -3489,7 +3493,7 @@ const int16_t E_ROM_qua_gain5b_const[NB_QUA_GAIN5B * 2]= }; const Word16 E_ROM_qua_gain6b_const[NB_QUA_GAIN6B * 2] = -{ +{//Q0 0,2758, 143,3562, 397,2146, @@ -3556,8 +3560,8 @@ const Word16 E_ROM_qua_gain6b_const[NB_QUA_GAIN6B * 2] = 18576,3563, }; -const int16_t E_ROM_qua_gain7b_const[NB_QUA_GAIN7B * 2] = -{ +const Word16 E_ROM_qua_gain7b_const[NB_QUA_GAIN7B * 2] = +{//Q0 123,2777, 369,2102, 404,4368, @@ -3693,7 +3697,7 @@ const int16_t E_ROM_qua_gain7b_const[NB_QUA_GAIN7B * 2] = *----------------------------------------------------------------------------------*/ const float pred_gain[GAIN_PRED_ORDER] = { 0.5f, 0.4f, 0.3f, 0.2f }; -const Word16 pred_gain_fx[GAIN_PRED_ORDER] = { 8192, 6554, 4915, 3277 }; +const Word16 pred_gain_fx[GAIN_PRED_ORDER] = { 8192, 6554, 4915, 3277 };//Q14 /*----------------------------------------------------------------------------------* * 6-bit gain quantization table (only for AMR-WB IO mode) @@ -3767,7 +3771,7 @@ const float t_qua_gain6b[64*2] = 1.243327f, 7.268204f }; const Word16 t_qua_gain6b_fx[64 * 2] = -{ +{//Q14 1566, 1332, 1577, 3557, 3071, 6490, @@ -3971,7 +3975,7 @@ const float t_qua_gain7b[128*2] = 1.296012f, 9.684225f }; const Word16 t_qua_gain7b_fx[128 * 2] = -{ +{//Q14 204, 441, 464, 1977, 869, 1077, @@ -4142,7 +4146,7 @@ const float Es_pred_qua_5b[32] = 65.0000f }; const Word16 Es_pred_qua_5b_fx[32] = -{ +{//Q8 -2048, -525, 642, @@ -4198,7 +4202,7 @@ const float Es_pred_qua_4b[16] = 65.0000f }; const Word16 Es_pred_qua_4b_fx[16] = -{ +{//Q8 -2048, -36, 1828, @@ -4306,7 +4310,7 @@ const float b_3sfr[6] = { -0.11658f, 0.02674f, 0.13513f, 0.79682f, 0.02241f, 0.17815f }; -const Word16 b_3sfr_fx[6] = +const Word16 b_3sfr_fx[6] =//Q12 { -478, 110, 553, 3264, 92, 730 }; @@ -4315,7 +4319,7 @@ const float b_4sfr[8] = { -0.09296f, 0.01578f, -0.06606f, 0.20416f, 0.79254f, 0.00829f, 0.03499f, 0.15859f }; -const Word16 b_4sfr_fx[8] = +const Word16 b_4sfr_fx[8] =//Q12 { -381, 65, -271, 836, 3246, 34, 143, 650 }; @@ -6597,7 +6601,7 @@ const float deem_tab[56] = 0.595767611250409f, 0.595627053220407f, 0.595508161367956f, 0.595410914747406f, 0.595335296233253f, 0.595281292513031f, 0.595248894081778f }; const Word16 deem_tab_fx[56] = -{ +{//Q15 20668, 20625, 20583, 20541, 20501, 20462, 20423, 20385, 20348, 20313, 20277, 20243, 20210, 20177, 20146, 20115, 20085, 20055, 20027, 19999, 19972, 19946, 19921, 19896, @@ -6622,7 +6626,7 @@ const float filt_hp[56] = 0.983792375705577f, 0.992691651376520f }; const Word16 filt_hp_fx[56] = -{ +{//Q15 53, 153, 274, 415, 578, 765, 978, 1217, 1483, 1778, 2102, 2457, 2843, 3261, 3710, 4192, 4706, 5252, 5829, 6438, 7077, 7746, 8443, 9168, 9918, 10693, 11489, 12306, 13141, 13992, @@ -6692,7 +6696,7 @@ const float HP_gain[16] = 0.511779785156250f, 0.599822998046875f, 0.741241455078125f, 0.998779296875000f }; const Word16 HP_gain_fx[16] = -{ +{//Q15 3624, 4673, 5597, 6479, 7425, 8378, 9324, 10264, 11210, 12206, 13391, 14844, 16770, 19655, 24289, 32728 }; @@ -6750,7 +6754,7 @@ const float fir_6k_7k[31] = -0.001005f }; const Word16 fir_6k_7k_fx[31] = -{ +{//Q15 -32, 47, 32, -27, -369, 1122, -1421, 0, 3798, -8880, 12349, -10984, 3548, 7766, -18001, @@ -6760,7 +6764,7 @@ const Word16 fir_6k_7k_fx[31] = -32 }; const Word16 no_lead_fx[][MAX_NO_SCALES * 2] = -{ +{//Q0 { 1, 0, 0, 1, 0, 0, }, /* 14 */ { 2, 0, 0, 1, 0, 0, }, /* 15 */ { 4, 2, 0, 1, 0, 0, }, /* 18 */ @@ -6899,7 +6903,7 @@ const Word16 no_lead_fx[][MAX_NO_SCALES * 2] = }; -const Word16 no_lead_p_fx[][MAX_NO_SCALES * 2] = +const Word16 no_lead_p_fx[][MAX_NO_SCALES * 2] = // Q0 { { 2, 1, 0, 0, 0, 0, }, /* 9 (8.464) */ @@ -7192,7 +7196,7 @@ const Word16 filt_lp_16kHz_fx[1 + L_FILT16k] = * Pulse indexing tables for ACELP innovation coding *-------------------------------------------------------------------*/ -const int32_t PI_select_table[23][8] = +const Word32 PI_select_table[23][8] = // Q0 { {1, 0, 0, 0, 0, 0, 0, 0}, {1, 1, 0, 0, 0, 0, 0, 0}, @@ -7219,7 +7223,7 @@ const int32_t PI_select_table[23][8] = {1, 22, 231, 1540, 7315, 26334, 74613, 1705444} }; -const int32_t PI_offset[8][8] = +const Word32 PI_offset[8][8] = // Q0 { /* for 0p(0). */ {0x00000,0x00000,0x00000,0x00000,0x00000,0x00000,0x00000,0x00000}, @@ -7239,15 +7243,15 @@ const int32_t PI_offset[8][8] = {0x00000,0x00000,0x165800,0x454400,0x654200,0x6E2500,0x6F2B80,0x6F36C0} }; -const int16_t PI_factor[7] = {0,0,120,560,1820,4368,8008}; +const Word16 PI_factor[7] = {0,0,120,560,1820,4368,8008}; // Q0 /* ACELP pulse coding */ -const Word16 hi_to_low_tmpl[10] = { 0, 0, 0, 3, 9, 5, 3, 1, 8, 8 }; -const uint16_t low_len[10] = { 0, 0, 8, 5, 7,11,13,15,16,16 }; -const uint16_t low_mask[10] = { 0, 0, 255,31,127,2047,8191,32767,65535,65535 }; -const uint16_t indx_fact[10] = { 0, 0,2,172,345,140,190,223,463,1732 }; -const int16_t index_len[3] = { 0, 5, 9 }; -const int16_t index_mask_ACELP[3] = { 0, 31, 511 }; +const Word16 hi_to_low_tmpl[10] = { 0, 0, 0, 3, 9, 5, 3, 1, 8, 8 }; // Q0 +const UWord16 low_len[10] = { 0, 0, 8, 5, 7,11,13,15,16,16 }; // Q0 +const UWord16 low_mask[10] = { 0, 0, 255,31,127,2047,8191,32767,65535,65535 }; // Q0 +const UWord16 indx_fact[10] = { 0, 0,2,172,345,140,190,223,463,1732 }; // Q0 +const Word16 index_len[3] = { 0, 5, 9 }; // Q0 +const Word16 index_mask_ACELP[3] = { 0, 31, 511 }; // Q0 /*------------------------------------------------------------------------------* @@ -7734,7 +7738,7 @@ const Word16 edct_table_80_fx[80] = /*Q16 */ }; const Word16 edct_table_100_fx[] = -{ +{/*Q16 */ 20723, 20718, 20708, 20692, 20672, 20646, 20616, 20580, 20539, 20493, 20442, 20386, 20325, 20259, 20188, 20112, 20031, 19946, 19855, 19759, 19658, 19553, 19443, 19328, @@ -7877,7 +7881,7 @@ const Word16 edct_table_480_fx[480] = /*Q16 */ 344, 298, 252, 206, 160, 115, 69, 23 }; -const Word16 edct_table_600_fx[] = +const Word16 edct_table_600_fx[] =/*Q16 */ { 26483, 26483, 26483, 26482, 26481, 26481, 26479, 26478, 26477, 26475, 26473, 26471, 26469, 26467, 26464, 26461, @@ -8017,7 +8021,7 @@ const Word16 edct_table_20_fx[20] = /*Q16 */ }; -const Word16 edct_table_64_fx[] = +const Word16 edct_table_64_fx[] =/*Q16 */ { 23167, 23153, 23125, 23083, 23027, 22958, 22874, 22777, 22666, 22542, 22403, 22252, 22087, 21908, 21717, 21512, @@ -8030,7 +8034,7 @@ const Word16 edct_table_64_fx[] = }; -const Word16 edct_table_200_fx[] = +const Word16 edct_table_200_fx[] =/*Q16 */ { 17427, 17426, 17423, 17420, 17416, 17411, 17404, 17397, 17388, 17378, 17368, 17356, 17343, 17329, 17314, 17298, @@ -8059,7 +8063,7 @@ const Word16 edct_table_200_fx[] = 1026, 889, 753, 616, 479, 342, 205, 68 }; -const Word16 edct_table_240_fx[] = +const Word16 edct_table_240_fx[] =/*Q16 */ { 16650, 16650, 16648, 16646, 16643, 16640, 16635, 16630, 16625, 16618, 16611, 16603, 16595, 16585, 16575, 16565, @@ -8093,7 +8097,7 @@ const Word16 edct_table_240_fx[] = 817, 708, 599, 490, 381, 272, 163, 54 }; -const Word16 edct_table_256_fx[] = +const Word16 edct_table_256_fx[] =/*Q16 */ { 16384, 16383, 16382, 16380, 16378, 16375, 16371, 16367, 16362, 16356, 16350, 16343, 16336, 16328, 16319, 16310, @@ -8129,7 +8133,7 @@ const Word16 edct_table_256_fx[] = 754, 653, 553, 452, 352, 251, 151, 50 }; -const Word16 edct_table_400_fx[] = +const Word16 edct_table_400_fx[] =/*Q16 */ { 29308, 29308, 29307, 29306, 29304, 29302, 29299, 29296, 29292, 29288, 29284, 29279, 29273, 29267, 29261, 29254, @@ -8183,7 +8187,7 @@ const Word16 edct_table_400_fx[] = 863, 748, 633, 518, 403, 288, 173, 58 }; -const Word16 edct_table_320_16fx[320] = +const Word16 edct_table_320_16fx[320] =/*Q16 */ { 7747, 7747, 7747, 7746, 7746, 7745, 7744, 7742, 7741, 7739, 7737, 7735, 7733, 7730, 7728, 7725, @@ -8245,7 +8249,7 @@ const Word16 edct_table_128_16fx[128] = /*Q15 */ 1842, 1724, 1607, 1489, 1370, 1252, 1133, 1014, 895, 776, 657, 538, 418, 299, 179, 60 }; -const Word16 edct_table_160_16fx[160] = +const Word16 edct_table_160_16fx[160] =//Q15 { 9213, 9212, 9211, 9208, 9204, 9200, 9195, 9188, 9181, 9173, 9164, 9155, 9144, 9132, 9120, 9107, @@ -8294,7 +8298,7 @@ const float mean_isf_amr_wb[M] = 1576.906494f }; -const Word16 mean_isf_amr_wb_fx[M] = +const Word16 mean_isf_amr_wb_fx[M] =/*Qlog2(2.56)*/ { 738, 1326, 2336, 3578, 4596, 5662, 6711, 7730, 8750, 9753,10705, 11728, 12833, 13971,15043, 4037 @@ -8324,7 +8328,7 @@ const float mean_isf_noise_amr_wb[M] = 1485.457031f }; -const Word16 mean_isf_noise_amr_wb_fx[M] = +const Word16 mean_isf_noise_amr_wb_fx[M] =/*Qlog2(2.56)*/ { 478, 1100, 2213, 3267, 4219, 5222, 6198, 7240, 8229, 9153,10098, 11108, 12144, 13184,14165, 3803 @@ -8335,7 +8339,7 @@ const Word16 mean_isf_noise_amr_wb_fx[M] = * Indirection for 1st stage 1st split of 46 bit cb. : The transmitted_index = indirect_dico1[found_index]; *------------------------------------------------------*/ -const Word16 Indirect_dico1[SIZE_BK1] = +const Word16 Indirect_dico1[SIZE_BK1] = // Q0 { 2, 6, 18, 22, 34, 35, 38, 50, 66, 67, 70, 82, 98, 99, 102, 130, @@ -8531,7 +8535,7 @@ const Word16 gaus_dico_swb_fx[256] = * CLDFB tables *----------------------------------------------------------------------------------*/ -const int16_t freqTable[2] = {20, 40}; +const Word16 freqTable[2] = {20, 40}; // Q0 /* SNR: 109.44, PHASE: 3.500000000000000 */ const float CLDFB80_10_flt[100] = @@ -9824,7 +9828,7 @@ const float rot_vec_ana_im_L60[30] = * abs. max Val: 1.04 * scale: 0.50 */ -const Word16 CLDFB80_10[] = +const Word16 CLDFB80_10[] =//Q.5 { W16(0x0000), W16(0xfffc), W16(0xffdf), W16(0x0132), W16(0x23b5), W16(0x0000), W16(0xffff), W16(0xfff3), W16(0x018d), W16(0x2a98), @@ -9856,7 +9860,7 @@ const Word16 CLDFB80_10[] = * abs. max Val: 1.04 * scale: 0.50 */ -const Word16 CLDFB80_16[] = +const Word16 CLDFB80_16[] =//Q.5 { W16(0x0000), W16(0xfffb), W16(0xffdd), W16(0x0123), W16(0x2266), W16(0x0000), W16(0xfffe), W16(0xffe7), W16(0x0157), W16(0x26c0), @@ -9900,7 +9904,7 @@ const Word16 CLDFB80_16[] = * abs. max Val: 1.04 * scale: 0.50 */ -const Word16 CLDFB80_20[] = +const Word16 CLDFB80_20[] =//Q.5 { W16(0x0000), W16(0xfffb), W16(0xffdf), W16(0x011e), W16(0x21f7), W16(0x0000), W16(0xfffd), W16(0xffe1), W16(0x0146), W16(0x2573), @@ -9952,7 +9956,7 @@ const Word16 CLDFB80_20[] = * abs. max Val: 1.04 * scale: 0.50 */ -const Word16 CLDFB80_32[] = +const Word16 CLDFB80_32[] =//Q.5 { W16(0x0000), W16(0xfffb), W16(0xffe2), W16(0x0115), W16(0x214f), W16(0x0000), W16(0xfffc), W16(0xffde), W16(0x012f), W16(0x237e), @@ -10028,7 +10032,7 @@ const Word16 CLDFB80_32[] = * abs. max Val: 1.04 * scale: 0.50 */ -const Word16 CLDFB80_40[] = +const Word16 CLDFB80_40[] =//Q.5 { W16(0x0000), W16(0xfffa), W16(0xffe2), W16(0x0112), W16(0x2117), W16(0x0000), W16(0xfffb), W16(0xffdc), W16(0x0128), W16(0x22d6), @@ -10120,7 +10124,7 @@ const Word16 CLDFB80_40[] = * abs. max Val: 1.04 * scale: 0.50 */ -const Word16 CLDFB80_60[] = +const Word16 CLDFB80_60[] =//Q.5 { W16(0x0000), W16(0xfffa), W16(0xffe2), W16(0x010f), W16(0x20cd), W16(0x0000), W16(0xfffb), W16(0xffdf), W16(0x011e), W16(0x21f7), @@ -10244,7 +10248,7 @@ const Word16 CLDFB80_60[] = W16(0x0002), W16(0x0020), W16(0xff00), W16(0xe05e), W16(0x00a9) }; -const Word16 CLDFB80_30[] = +const Word16 CLDFB80_30[] =//Q.5 { 0, -5, -30, 278, 8546, 0, -4, -33, 306, 9141, @@ -10307,7 +10311,7 @@ const Word16 CLDFB80_30[] = 0, 18, -223, -7348, 682, 0, 32, -249, -7947, 282 }; - +#if 0// Not used anywhere const Word16 LDQMF_10_enc_fx[] = { 2, -21, 79, -1890, 8640, @@ -10750,7 +10754,7 @@ const Word16 LDQMF_60_enc_fx[] = 9, -121, 1012, -9642, -21, 12, -113, 1199, -9421, -13 }; - +#endif /*! * \brief CLDFB rRotVectr * @@ -10758,7 +10762,7 @@ const Word16 LDQMF_60_enc_fx[] = * global gain: 8.00 * scale: sqrt(1.0/16.00) */ -const Word16 rRotVectr_10[] = +const Word16 rRotVectr_10[] =//Q(sqrt(1.0/16.00)) { W16(0x5a71), W16(0x54ea), W16(0x4714), W16(0x3249), W16(0x1891) }; @@ -10770,7 +10774,7 @@ const Word16 rRotVectr_10[] = * global gain: 8.00 * scale: sqrt(1.0/16.00) */ -const Word16 iRotVectr_10[] = +const Word16 iRotVectr_10[] =//Q(sqrt(1.0/16.00)) { W16(0xfc72), W16(0xe0ac), W16(0xc7f7), W16(0xb4be), W16(0xa8e3) }; @@ -10782,7 +10786,7 @@ const Word16 iRotVectr_10[] = * global gain: 5.00 * scale: sqrt(1.0/8.00) */ -const Word16 rRotVectr_16[] = +const Word16 rRotVectr_16[] =//Q(sqrt(1.0/8.00)) { W16(0x652a), W16(0x62bc), W16(0x5c83), W16(0x52bc), W16(0x45c7), W16(0x3623), W16(0x246b), W16(0x114d) @@ -10795,7 +10799,7 @@ const Word16 rRotVectr_16[] = * global gain: 5.00 * scale: sqrt(1.0/8.00) */ -const Word16 iRotVectr_16[] = +const Word16 iRotVectr_16[] =//Q(sqrt(1.0/8.00)) { W16(0xfd84), W16(0xe9d4), W16(0xd6fe), W16(0xc5bb), W16(0xb6b6), W16(0xaa82), W16(0xa196), W16(0x9c4c) @@ -10808,7 +10812,7 @@ const Word16 iRotVectr_16[] = * global gain: 4.00 * scale: sqrt(1.0/8.00) */ -const Word16 rRotVectr_20[] = +const Word16 rRotVectr_20[] =//Q(sqrt(1.0/8.00)) { W16(0x5a7e), W16(0x591a), W16(0x5584), W16(0x4fd3), W16(0x482a), W16(0x3ebb), W16(0x33c1), W16(0x2780), W16(0x1a46), W16(0x0c67) @@ -10821,7 +10825,7 @@ const Word16 rRotVectr_20[] = * global gain: 4.00 * scale: sqrt(1.0/8.00) */ -const Word16 iRotVectr_20[] = +const Word16 iRotVectr_20[] =//Q(sqrt(1.0/8.00) { W16(0xfe39), W16(0xf017), W16(0xe259), W16(0xd556), W16(0xc95f), W16(0xbec1), W16(0xb5bf), W16(0xae90), W16(0xa963), W16(0xa658) @@ -10834,7 +10838,7 @@ const Word16 iRotVectr_20[] = * global gain: 2.50 * scale: sqrt(1.0/4.00) */ -const Word16 rRotVectr_30[] = +const Word16 rRotVectr_30[] =//Q(sqrt(1.0/4.00)) { 25902, 25725, 25265, 24529, 23525, 22262, 20756, 19022, 17080, 14950, 12657, 10226, 7682, 5054, 2370 }; @@ -10846,7 +10850,7 @@ const Word16 rRotVectr_30[] = * global gain: 2.50 * scale: sqrt(1.0/4.00) */ -const Word16 iRotVectr_30[] = +const Word16 iRotVectr_30[] =//Q(sqrt(1.0/4.00)) { -339, -3045, -5717, -8327, -10845, -13245, -15499, -17584, -19476, -21154, -22601, -23801, -24739, -25406, -25796 }; @@ -10857,7 +10861,7 @@ const Word16 iRotVectr_30[] = * global gain: 2.50 * scale: sqrt(1.0/4.00) */ -const Word16 rRotVectr_32[] = +const Word16 rRotVectr_32[] =//Q(sqrt(1.0/4.00)) { W16(0x652f), W16(0x6494), W16(0x6300), W16(0x6078), W16(0x5d02), W16(0x58a7), W16(0x5371), W16(0x4d6e), W16(0x46ac), W16(0x3f3b), @@ -10872,7 +10876,7 @@ const Word16 rRotVectr_32[] = * global gain: 2.50 * scale: sqrt(1.0/4.00) */ -const Word16 iRotVectr_32[] = +const Word16 iRotVectr_32[] =//Q(sqrt(1.0/4.00)) { W16(0xfec2), W16(0xf4d9), W16(0xeb0b), W16(0xe170), W16(0xd821), W16(0xcf35), W16(0xc6c1), W16(0xbed9), W16(0xb793), W16(0xb0ff), @@ -10887,7 +10891,7 @@ const Word16 iRotVectr_32[] = * global gain: 2.00 * scale: sqrt(1.0/4.00) */ -const Word16 rRotVectr_40[] = +const Word16 rRotVectr_40[] =//Q(sqrt(1.0/4.00)) { W16(0x5a81), W16(0x5a28), W16(0x5941), W16(0x57cc), W16(0x55cd), W16(0x5347), W16(0x503d), W16(0x4cb4), W16(0x48b3), W16(0x443e), @@ -10902,7 +10906,7 @@ const Word16 rRotVectr_40[] = * global gain: 2.00 * scale: sqrt(1.0/4.00) */ -const Word16 iRotVectr_40[] = +const Word16 iRotVectr_40[] =//Q(sqrt(1.0/4.00)) { W16(0xff1d), W16(0xf803), W16(0xf0f7), W16(0xea02), W16(0xe330), W16(0xdc8b), W16(0xd61f), W16(0xcff4), W16(0xca15), W16(0xc48c), @@ -10917,7 +10921,7 @@ const Word16 iRotVectr_40[] = * global gain: 1.33 * scale: sqrt(1.0/2.00) */ -const Word16 rRotVectr_60[] = +const Word16 rRotVectr_60[] =//Q(sqrt(1.0/2.00)) { W16(0x6882), W16(0x6855), W16(0x67de), W16(0x671e), W16(0x6615), W16(0x64c5), W16(0x632f), W16(0x6153), W16(0x5f32), W16(0x5ccf), @@ -10934,7 +10938,7 @@ const Word16 rRotVectr_60[] = * global gain: 1.33 * scale: sqrt(1.0/2.00) */ -const Word16 iRotVectr_60[] = +const Word16 iRotVectr_60[] =//Q(sqrt(1.0/2.00)) { W16(0xff51), W16(0xf9d9), W16(0xf465), W16(0xeefa), W16(0xe99a), W16(0xe44a), W16(0xdf0e), W16(0xd9e9), W16(0xd4de), W16(0xcff2), @@ -10944,15 +10948,15 @@ const Word16 iRotVectr_60[] = W16(0x9ae0), W16(0x99a2), W16(0x98ac), W16(0x97fe), W16(0x9799) }; -const Word16 cldfb_anaScale[] = +const Word16 cldfb_anaScale[] = // Q0 { SCALE_CLDFB_ANA_10, SCALE_CLDFB_ANA_16, SCALE_CLDFB_ANA_20, SCALE_CLDFB_ANA_32, SCALE_CLDFB_ANA_40, SCALE_CLDFB_ANA_60, SCALE_CLDFB_ANA_30 }; -const Word16 cldfb_synScale[] = +const Word16 cldfb_synScale[] = // Q0 { SCALE_CLDFB_SYN_10, SCALE_CLDFB_SYN_16, SCALE_CLDFB_SYN_20, SCALE_CLDFB_SYN_32, SCALE_CLDFB_SYN_40, SCALE_CLDFB_SYN_60, SCALE_CLDFB_SYN_30 }; -const Word16 cldfb_synGain[] = +const Word16 cldfb_synGain[] =//Q0 { 0x6666, /* 10 bands */ 0x51EC, /* 16 bands */ @@ -10966,7 +10970,7 @@ const Word16 *cldfb_protoFilter_2_5ms[] = { CLDFB80_10, CLDFB80_16, CLDFB80_20, CLDFB80_32, CLDFB80_40, CLDFB80_60, CLDFB80_30 }; -#ifdef IVAS_FLOAT_FIXED +#if 0 //def IVAS_FLOAT_FIXED not used anywhere const Word16 *cldfb_protoFilter_5_0ms[] = { LDQMF_10_enc_fx, LDQMF_16_enc_fx, LDQMF_20_enc_fx, LDQMF_32_enc_fx, LDQMF_40_enc_fx, LDQMF_60_enc_fx, LDQMF_30_enc_fx @@ -11737,39 +11741,39 @@ const Word16 scaleTable_cn_only_amrwbio[3][2] = { ACELP_8k85, 16306/*0.9952622652 Q14*/ }, { ACELP_12k65, 9583/*0.5848932266 Q14*/ }, }; -const Word32 scaleTable_cn_only_amrwbio_fx_by_10f[SIZE_SCALE_TABLE_CN_AMRWB][2] = +const Word32 scaleTable_cn_only_amrwbio_fx_by_10f[SIZE_SCALE_TABLE_CN_AMRWB][2] =//Q29 { { ACELP_6k60, 858993459 }, { ACELP_8k85, 644245094 }, { ACELP_12k65, 429496729 } }; -const int16_t sidparts_encoder_noise_est[SIZE_SIDPARTS_ENC_NOISE_EST] = { 4, 8, 12, 16, 20, 24, 30, 36, 42, 50, 58, 68, 80, 92, 108, 126, 148, 176, 212, 255, 259, 264, 269, 279 }; +const Word16 sidparts_encoder_noise_est[SIZE_SIDPARTS_ENC_NOISE_EST] = { 4, 8, 12, 16, 20, 24, 30, 36, 42, 50, 58, 68, 80, 92, 108, 126, 148, 176, 212, 255, 259, 264, 269, 279 }; // Q0 -const int16_t sidPartitions_nb[] = { 4, 8, 12, 16, 20, 24, 30, 36, 42, 50, 58, 68, 80, 92, 108, 126, 159 }; -const int16_t sidPartitions_wb1[] = { 4, 8, 12, 16, 20, 24, 30, 36, 42, 50, 58, 68, 80, 92, 108, 126, 148, 176, 212, 255 }; -const int16_t sidPartitions_wb2[] = { 4, 8, 12, 16, 20, 24, 30, 36, 42, 50, 58, 68, 80, 92, 108, 126, 148, 176, 212, 255, 259 }; -const int16_t sidPartitions_wb3[] = { 4, 8, 12, 16, 20, 24, 30, 36, 42, 50, 58, 68, 80, 92, 108, 126, 148, 176, 212, 255, 319 }; -const int16_t sidPartitions_swb1[] = { 4, 8, 12, 16, 20, 24, 30, 36, 42, 50, 58, 68, 80, 92, 108, 126, 148, 176, 212, 255, 259, 264, 269, 274 }; -const int16_t sidPartitions_swb2[] = { 4, 8, 12, 16, 20, 24, 30, 36, 42, 50, 58, 68, 80, 92, 108, 126, 148, 176, 212, 255, 319, 324, 329, 339 }; +const Word16 sidPartitions_nb[] = { 4, 8, 12, 16, 20, 24, 30, 36, 42, 50, 58, 68, 80, 92, 108, 126, 159 }; // Q0 +const Word16 sidPartitions_wb1[] = { 4, 8, 12, 16, 20, 24, 30, 36, 42, 50, 58, 68, 80, 92, 108, 126, 148, 176, 212, 255 }; // Q0 +const Word16 sidPartitions_wb2[] = { 4, 8, 12, 16, 20, 24, 30, 36, 42, 50, 58, 68, 80, 92, 108, 126, 148, 176, 212, 255, 259 }; // Q0 +const Word16 sidPartitions_wb3[] = { 4, 8, 12, 16, 20, 24, 30, 36, 42, 50, 58, 68, 80, 92, 108, 126, 148, 176, 212, 255, 319 }; // Q0 +const Word16 sidPartitions_swb1[] = { 4, 8, 12, 16, 20, 24, 30, 36, 42, 50, 58, 68, 80, 92, 108, 126, 148, 176, 212, 255, 259, 264, 269, 274 }; // Q0 +const Word16 sidPartitions_swb2[] = { 4, 8, 12, 16, 20, 24, 30, 36, 42, 50, 58, 68, 80, 92, 108, 126, 148, 176, 212, 255, 319, 324, 329, 339 }; // Q0 -const int16_t shapingPartitions_nb[] = { 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 25, 28, 31, 34, 37, 40, 43, 47, 51, 55, 59, 64, 69, 74, 80, 86, 93, 100, 108, 117, 126, 136, 159 }; -const int16_t shapingPartitions_wb1[] = { 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 25, 28, 31, 34, 37, 40, 43, 47, 51, 55, 59, 64, 69, 74, 80, 86, 93, 100, 108, 117, 126, 135, 148, 162, 176, 192, 212, 232, 255 }; -const int16_t shapingPartitions_wb2[] = { 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 25, 28, 31, 34, 37, 40, 43, 47, 51, 55, 59, 64, 69, 74, 80, 86, 93, 100, 108, 117, 126, 135, 148, 162, 176, 192, 212, 232, 255 }; -const int16_t shapingPartitions_wb3[] = { 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 25, 28, 31, 34, 37, 40, 43, 47, 51, 55, 59, 64, 69, 74, 80, 86, 93, 100, 108, 117, 126, 136, 148, 176, 212, 256, 308, 319 }; -const int16_t shapingPartitions_swb1[] = { 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 25, 28, 31, 34, 37, 40, 43, 47, 51, 55, 59, 64, 69, 74, 80, 86, 93, 100, 108, 117, 126, 135, 148, 162, 176, 192, 212, 232, 255 }; -const int16_t shapingPartitions_swb2[] = { 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 25, 28, 31, 34, 37, 40, 43, 47, 51, 55, 59, 64, 69, 74, 80, 86, 93, 100, 108, 117, 126, 136, 148, 176, 212, 256, 308, 319 }; +const Word16 shapingPartitions_nb[] = { 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 25, 28, 31, 34, 37, 40, 43, 47, 51, 55, 59, 64, 69, 74, 80, 86, 93, 100, 108, 117, 126, 136, 159 }; // Q0 +const Word16 shapingPartitions_wb1[] = { 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 25, 28, 31, 34, 37, 40, 43, 47, 51, 55, 59, 64, 69, 74, 80, 86, 93, 100, 108, 117, 126, 135, 148, 162, 176, 192, 212, 232, 255 }; // Q0 +const Word16 shapingPartitions_wb2[] = { 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 25, 28, 31, 34, 37, 40, 43, 47, 51, 55, 59, 64, 69, 74, 80, 86, 93, 100, 108, 117, 126, 135, 148, 162, 176, 192, 212, 232, 255 }; // Q0 +const Word16 shapingPartitions_wb3[] = { 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 25, 28, 31, 34, 37, 40, 43, 47, 51, 55, 59, 64, 69, 74, 80, 86, 93, 100, 108, 117, 126, 136, 148, 176, 212, 256, 308, 319 }; // Q0 +const Word16 shapingPartitions_swb1[] = { 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 25, 28, 31, 34, 37, 40, 43, 47, 51, 55, 59, 64, 69, 74, 80, 86, 93, 100, 108, 117, 126, 135, 148, 162, 176, 192, 212, 232, 255 }; // Q0 +const Word16 shapingPartitions_swb2[] = { 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 25, 28, 31, 34, 37, 40, 43, 47, 51, 55, 59, 64, 69, 74, 80, 86, 93, 100, 108, 117, 126, 136, 148, 176, 212, 256, 308, 319 }; // Q0 -const FD_CNG_SETUP FdCngSetup_nb = { 512, 160, sizeof(sidPartitions_nb)/sizeof(int16_t), sidPartitions_nb, sizeof(shapingPartitions_nb)/sizeof(int16_t), shapingPartitions_nb }; -const FD_CNG_SETUP FdCngSetup_wb1 = { 512, 256, sizeof(sidPartitions_wb1)/sizeof(int16_t), sidPartitions_wb1, sizeof(shapingPartitions_wb1)/sizeof(int16_t), shapingPartitions_wb1 }; -const FD_CNG_SETUP FdCngSetup_wb2 = { 512, 256, sizeof(sidPartitions_wb2)/sizeof(int16_t), sidPartitions_wb2, sizeof(shapingPartitions_wb2)/sizeof(int16_t), shapingPartitions_wb2 }; -const FD_CNG_SETUP FdCngSetup_wb3 = { 640, 320, sizeof(sidPartitions_wb3)/sizeof(int16_t), sidPartitions_wb3, sizeof(shapingPartitions_wb3)/sizeof(int16_t), shapingPartitions_wb3 }; -const FD_CNG_SETUP FdCngSetup_swb1 = { 512, 256, sizeof(sidPartitions_swb1)/sizeof(int16_t), sidPartitions_swb1, sizeof(shapingPartitions_swb1)/sizeof(int16_t), shapingPartitions_swb1 }; -const FD_CNG_SETUP FdCngSetup_swb2 = { 640, 320, sizeof(sidPartitions_swb2)/sizeof(int16_t), sidPartitions_swb2, sizeof(shapingPartitions_swb2)/sizeof(int16_t), shapingPartitions_swb2 }; +const FD_CNG_SETUP FdCngSetup_nb = { 512, 160, sizeof(sidPartitions_nb)/sizeof(Word16), sidPartitions_nb, sizeof(shapingPartitions_nb)/sizeof(Word16), shapingPartitions_nb }; +const FD_CNG_SETUP FdCngSetup_wb1 = { 512, 256, sizeof(sidPartitions_wb1)/sizeof(Word16), sidPartitions_wb1, sizeof(shapingPartitions_wb1)/sizeof(Word16), shapingPartitions_wb1 }; +const FD_CNG_SETUP FdCngSetup_wb2 = { 512, 256, sizeof(sidPartitions_wb2)/sizeof(Word16), sidPartitions_wb2, sizeof(shapingPartitions_wb2)/sizeof(Word16), shapingPartitions_wb2 }; +const FD_CNG_SETUP FdCngSetup_wb3 = { 640, 320, sizeof(sidPartitions_wb3)/sizeof(Word16), sidPartitions_wb3, sizeof(shapingPartitions_wb3)/sizeof(Word16), shapingPartitions_wb3 }; +const FD_CNG_SETUP FdCngSetup_swb1 = { 512, 256, sizeof(sidPartitions_swb1)/sizeof(Word16), sidPartitions_swb1, sizeof(shapingPartitions_swb1)/sizeof(Word16), shapingPartitions_swb1 }; +const FD_CNG_SETUP FdCngSetup_swb2 = { 640, 320, sizeof(sidPartitions_swb2)/sizeof(Word16), sidPartitions_swb2, sizeof(shapingPartitions_swb2)/sizeof(Word16), shapingPartitions_swb2 }; -const int16_t levels_37bits[FD_CNG_stages_37bits] = { 128, 64, 64, 64, 64, 64 }; -const int16_t bits_37bits[FD_CNG_stages_37bits] = { 7, 6, 6, 6, 6, 6 }; +const Word16 levels_37bits[FD_CNG_stages_37bits] = { 128, 64, 64, 64, 64, 64 }; // Q0 +const Word16 bits_37bits[FD_CNG_stages_37bits] = { 7, 6, 6, 6, 6, 6 }; // Q0 /* IDCT_MATRIX_ROM: 18*24 Word16 = 432 Word16 */ /* or compressed IDCT_MATRIX_ROM: 18*24 Word8 + 25 = 230 Word16 + WMOPS (INDIRECT(432) and STORE(432) ) */ @@ -11782,8 +11786,8 @@ const int16_t bits_37bits[FD_CNG_stages_37bits] = { 7, 6, 6, 6, 6, 6 }; /* additional minor Table ROM ( dct_mid points 18 Word16, dct_col_upshifts 52, scaleFactors 2*2 = ~= 74 Word16s */ -const Word16 cdk1_ivas_entries_per_segment[FDCNG_VQ_DCT_NSEGM] = { 16, 17, 17, 78 }; -const Word16 cdk1_ivas_cum_entries_per_segment[FDCNG_VQ_DCT_NSEGM + 1] = { 0, 16 ,33, 50, 128 }; +const Word16 cdk1_ivas_entries_per_segment[FDCNG_VQ_DCT_NSEGM] = { 16, 17, 17, 78 }; // Q0 +const Word16 cdk1_ivas_cum_entries_per_segment[FDCNG_VQ_DCT_NSEGM + 1] = { 0, 16 ,33, 50, 128 }; // Q0 const Word16 /* DCT trunc_len */ cdk1_ivas_cols_per_segment[FDCNG_VQ_DCT_NSEGM] = { FDCNG_VQ_DCT_MINTRUNC, 10, 16, FDCNG_VQ_DCT_MAXTRUNC }; /* 8, 10, 16, 18 */ const Word16 /* segment inner DCT trunc_len */ cdk1_ivas_trunc_dct_cols_per_segment[FDCNG_VQ_DCT_NSEGM] = { FDCNG_VQ_DCT_MAXTRUNC - FDCNG_VQ_DCT_MINTRUNC, FDCNG_VQ_DCT_MAXTRUNC - 10 , FDCNG_VQ_DCT_MAXTRUNC - 16 , 0 }; @@ -11810,30 +11814,30 @@ const Word8* const cdk_37bits_ivas_stage1_W8Qx_dct_sections[] = { cdk1_ivas_dct_ /* scaling constants */ const float fdcng_dct_scaleF[3] = { 0.420288085937500f , (0.420288085937500f / 16.0f) , (0.420288085937500f * 0.420288085937500f) / (16.0f*16.0f) }; const float fdcng_dct_invScaleF[2] = { 2.379272460937500f ,2.379272460937500f*16.0f }; -const Word32 fdcng_dct_scaleF_fx[3] = { 902561792, 56410112,1481781 }; +const Word32 fdcng_dct_scaleF_fx[3] = { 902561792, 56410112,1481781 };//Q31 -const Word16 stage1_col_syn_shift_segm0[8] = { +const Word16 stage1_col_syn_shift_segm0[8] = { // Q0 4, 4, 4, 3, 2, 2, 2, 1 }; -const Word16 stage1_col_syn_shift_segm1[10] = { +const Word16 stage1_col_syn_shift_segm1[10] = { // Q0 4, 4, 4, 3, 2, 2, 2, 1, 1, 1 }; -const Word16 stage1_col_syn_shift_segm2[16] = { +const Word16 stage1_col_syn_shift_segm2[16] = { // Q0 4, 4, 4, 3, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 0, 1 }; -const Word16 stage1_col_syn_shift_segm3[18] = { +const Word16 stage1_col_syn_shift_segm3[18] = { // Q0 4, 4, 3, 2, 2, 2, 2, 1, 1, 1, 1, 0, 1, 1, 0, 1, 0, 1 }; /* segment individual shiftfactor to Q4 for each stored DCT Word8 coeff column */ -const Word16 * stage1_dct_col_syn_shift[FDCNG_VQ_DCT_NSEGM] = { stage1_col_syn_shift_segm0, stage1_col_syn_shift_segm1,stage1_col_syn_shift_segm2,stage1_col_syn_shift_segm3 }; +const Word16 * stage1_dct_col_syn_shift[FDCNG_VQ_DCT_NSEGM] = { stage1_col_syn_shift_segm0, stage1_col_syn_shift_segm1,stage1_col_syn_shift_segm2,stage1_col_syn_shift_segm3 }; // Q0 -/* 25 unique abs values of idct24_18matrixQ16 */ +/* 25 unique abs values of idct24_18matrix Q16 */ const Word16 unique_idctT2_24coeffsQ16[25] = { 0, 1237, 2469, 3691, 4896, 6081, 7240, 8367, 9459, 10511, 11517, 12474, 13377, 14224, 15009, 15730, @@ -11857,10 +11861,10 @@ const Word8 idctT2_24_compressed_idx[(FDCNG_VQ_DCT_MAXTRUNC * FDCNG_VQ_MAX_LEN) 12, 5, -14, -15, 4, 23, 6, -13, -16, 3, 22, 7, -12, -17, 2, 21, 8, -11, 12, 3, -18, -9, 12, 15, -6, -21, 0, 21, 6, -15, -12, 9, 18, -3, -24, -3, 12, 1, -22, -3, 20, 5, -18, -7, 16, 9, -14, -11, 12, 13, -10, -15, 8, 17 -}; +}; // Q0 -const Word16 unique_idctT2_21coeffsQ16[23] = { +const Word16 unique_idctT2_21coeffsQ16[23] = {//Q16 0, 1511, 3014, 4500, 5961, 7389, 8775, 10112, 11393, 12610, 13756, 14301, 14826, 15812, 16711, 17515, 18222, 18827, 19326, 19718, 19999, 20168, 20225 @@ -11889,7 +11893,7 @@ const Word8 idctT2_21_compressed_idx[(FDCNG_VQ_DCT_MAXTRUNC *( (21/2) + 1)) /* /*tables in truncated DCTII_24 domain */ -const Word8 /*seg 0, 16 x 8 */ cdk1_ivas_dct_s0_W8[128] = { +const Word8 /*seg 0, 16 x 8 */ cdk1_ivas_dct_s0_W8[128] = { // Q0 29, -126, 8, -34, -45, -42, -13, 2, 22, -120, 0, -27, -41, -50, -25, 42, 20, -116, -2, -39, -61, -33, -22, -25, @@ -11908,7 +11912,7 @@ const Word8 /*seg 0, 16 x 8 */ cdk1_ivas_dct_s0_W8[128] = { -17, 125, 6, 74, 21, 85, 5, 98 }; -const Word8 /*seg 1, 17 x 10 */ cdk1_ivas_dct_s1_W8[170] = { +const Word8 /*seg 1, 17 x 10 */ cdk1_ivas_dct_s1_W8[170] = { // Q0 20, -127, -12, -9, 1, -30, -2, -1, -43, -54, 24, -113, 3, -39, -49, -25, -15, -27, 6, 2, 55, 17, 74, 22, 78, 77, 87, 97, 89, 61, @@ -11928,7 +11932,7 @@ const Word8 /*seg 1, 17 x 10 */ cdk1_ivas_dct_s1_W8[170] = { -8, 127, 23, 24, 58, 89, 46, 20, 14, 54 }; -const Word8 /*seg 2, 17 x 16 */ cdk1_ivas_dct_s2_W8[272] = { +const Word8 /*seg 2, 17 x 16 */ cdk1_ivas_dct_s2_W8[272] = { // Q0 32, -69, 21, 3, -9, 17, 3, 14, 15, 35, -17, -10, -20, 28, -52, -19, 24, -49, 17, 9, -6, 14, 22, 33, 51, 38, 21, 14, 5, 38, 13, -5, 27, -8, 30, 9, 93, 65, 65, 66, 67, 30, 39, 21, 9, 22, 5, -17, @@ -11948,7 +11952,7 @@ const Word8 /*seg 2, 17 x 16 */ cdk1_ivas_dct_s2_W8[272] = { 4, 117, 37, 43, 44, 32, 13, 75, 32, 33, 15, -70, 51, 39, 68, 15 }; -const Word8 /*seg 3, 78 x 18 */ cdk1_ivas_dct_s3_W8[1404] = { +const Word8 /*seg 3, 78 x 18 */ cdk1_ivas_dct_s3_W8[1404] = { // Q0 21, -127, -23, -10, 7, -26, 1, 6, -39, -53, -19, -84, -34, 16, -10, -24, -75, 9, 76, -117, 124, -63, 75, 72, -9, 115, 42, 100, -36, 120, -37, 66, 46, 72, -34, 18, 24, -115, 3, -65, -47, -24, -7, -13, 1, -18, -10, -58, -30, 2, -37, -27, -78, 9, @@ -12032,7 +12036,7 @@ const Word8 /*seg 3, 78 x 18 */ cdk1_ivas_dct_s3_W8[1404] = { /* stage1 low complex search tables */ /* segm_neighbour_fwd/segm_neighbour_rev nex/previous indeces in an circularly ordered list of close MSE neighbours */ -const Word8 cdk1_ivas_segm_neighbour_fwd[128] = { +const Word8 cdk1_ivas_segm_neighbour_fwd[128] = { // Q0 3, 0, 4, 62, 5, 58, 64, 59, 33, 19, 9, 127, 26, 12, 28, 31, 1, 2, 51, 38, 18, 25, 43, 21, @@ -12050,7 +12054,7 @@ const Word8 cdk1_ivas_segm_neighbour_fwd[128] = { 82, 103, 121, 110, 109, 115, 40, 123, 116, 122, 120, 46, 93, 20, 125, 45 }; -const Word8 cdk1_ivas_segm_neighbour_rev[128] = { +const Word8 cdk1_ivas_segm_neighbour_rev[128] = { // Q0 1, 16, 17, 0, 2, 4, 63, 51, 65, 10, 44, 27, 13, 29, 30, 49, 50, 57, 20, 9, 125, 23, 36, 26, @@ -12547,7 +12551,7 @@ const float * const cdk_37bits_flt[] = { cdk_37bits_1, cdk_37bits_2, cdk_37bits_ const float * const cdk_37bits_ivas[] = { NULL, cdk_37bits_2, cdk_37bits_3, cdk_37bits_4, cdk_37bits_5, cdk_37bits_6 }; -const Word16 cdk_37bits_1_fx[3072] = +const Word16 cdk_37bits_1_fx[3072] =//Q7 { W16(0x017B), W16(0x0548), W16(0x068C), W16(0x058B), W16(0x0572), W16(0x0577), W16(0x04BC), W16(0x03C0), W16(0x0399), W16(0x0237), W16(0x00A1), W16(0xFEB3), W16(0xFCFA), W16(0xFC2F), W16(0xFACB), W16(0xFA70), @@ -12935,7 +12939,7 @@ const Word16 cdk_37bits_1_fx[3072] = W16(0xF82A), W16(0xF775), W16(0xF601), W16(0xF4EB), W16(0xF453), W16(0xF321), W16(0xF2CA), W16(0xF274) }; -const Word16 cdk_37bits_2_fx[1536] = +const Word16 cdk_37bits_2_fx[1536] =//Q7 { W16(0xFFB3), W16(0xFFD1), W16(0xFFDB), W16(0xFFB1), W16(0xFFE5), W16(0x0002), W16(0xFFE4), W16(0xFFED), W16(0x0018), W16(0x0058), W16(0x005D), W16(0x006D), W16(0x0055), W16(0x0018), W16(0xFFB1), W16(0xFF83), @@ -13131,7 +13135,7 @@ const Word16 cdk_37bits_2_fx[1536] = W16(0xFFF7), W16(0xFFF5), W16(0xFFFF), W16(0x0001), W16(0x0022), W16(0x003E), W16(0x0047), W16(0x0037) }; -const Word16 cdk_37bits_3_fx[1536] = +const Word16 cdk_37bits_3_fx[1536] =//Q7 { W16(0xFFCD), W16(0xFFFB), W16(0xFFC7), W16(0x0024), W16(0x0000), W16(0xFFAB), W16(0x014C), W16(0xFF9A), W16(0xFFF0), W16(0xFFF1), W16(0x0002), W16(0x0015), W16(0xFFF3), W16(0xFFDC), W16(0xFFD2), W16(0x000F), @@ -13327,7 +13331,7 @@ const Word16 cdk_37bits_3_fx[1536] = W16(0xFFA4), W16(0xFFEA), W16(0x001A), W16(0x002C), W16(0x0003), W16(0x002A), W16(0x005F), W16(0x0077) }; -const Word16 cdk_37bits_4_fx[1536] = +const Word16 cdk_37bits_4_fx[1536] =//Q7 { W16(0xFFF5), W16(0xFFA9), W16(0x000E), W16(0xFFC8), W16(0xFFCB), W16(0xFFB9), W16(0xFFD4), W16(0xFFCC), W16(0xFFCB), W16(0xFFC8), W16(0xFFD3), W16(0x001A), W16(0x0049), W16(0x003A), W16(0x001F), W16(0x0044), @@ -13523,7 +13527,7 @@ const Word16 cdk_37bits_4_fx[1536] = W16(0x0029), W16(0x0046), W16(0x0084), W16(0x0071), W16(0x004F), W16(0x0045), W16(0x0040), W16(0x0038) }; -const Word16 cdk_37bits_5_fx[1536] = +const Word16 cdk_37bits_5_fx[1536] =//Q7 { W16(0xFFF5), W16(0x0024), W16(0xFFA1), W16(0xFFDD), W16(0x0022), W16(0x004B), W16(0x003F), W16(0x0001), W16(0x0040), W16(0xFFF4), W16(0xFFEE), W16(0xFFE4), W16(0xFFA4), W16(0xFFD7), W16(0xFFEA), W16(0xFFFD), @@ -13719,7 +13723,7 @@ const Word16 cdk_37bits_5_fx[1536] = W16(0x001F), W16(0x0028), W16(0x0033), W16(0x003A), W16(0x0021), W16(0xFFE2), W16(0xFFB8), W16(0xFFAF) }; -const Word16 cdk_37bits_6_fx[1536] = +const Word16 cdk_37bits_6_fx[1536] =//Q7 { W16(0x0003), W16(0xFFDA), W16(0x0007), W16(0x0012), W16(0x0022), W16(0xFFFC), W16(0x001A), W16(0x0047), W16(0x001D), W16(0x0029), W16(0x0015), W16(0xFFF4), W16(0xFFE2), W16(0xFFC7), W16(0xFFD7), W16(0xFFDC), @@ -13917,11 +13921,11 @@ const Word16 cdk_37bits_6_fx[1536] = const Word16 * const cdk_37bits[] = { cdk_37bits_1_fx, cdk_37bits_2_fx, cdk_37bits_3_fx, cdk_37bits_4_fx, cdk_37bits_5_fx, cdk_37bits_6_fx -}; +}; // Q7 const Word16 * const ivas_cdk_37bits_fx[] = { NULL, cdk_37bits_2_fx, cdk_37bits_3_fx, cdk_37bits_4_fx, cdk_37bits_5_fx, cdk_37bits_6_fx -}; +}; // Q7 /* Sine tables for FFT */ /* for (j=0; jfftlen/2+1; j++) hs->fftSineTab[j] = (float)sin(2.0*EVS_PI*j/hs->fftlen); */ @@ -14514,7 +14518,7 @@ const float olapWinSyn256[256] = 0.0061358846f }; const Word16 olapWinSyn256_fx[256] = -{ +{//Q15 201, 603, 1005, 1407, 1808, 2210, 2611, 3011, 3411, 3811, 4210, 4609, 5006, 5403, 5800, 6195, 6589, 6983, 7375, 7766, 8156, 8545, 8933, 9319, 9704, 10087, 10469, 10849, 11228, 11605, 11980, 12353, 12725, 13094, 13462, 13828, 14191, 14552, 14912, 15269, 15623, 15976, 16325, 16673, 17018, 17360, 17700, 18037, @@ -14570,7 +14574,7 @@ const float olapWinSyn320[320] = }; const Word16 olapWinSyn320_fx[320] = -{ +{//Q15 160, 482, 804, 1125, 1447, 1768, 2089, 2410, 2731, 3051, 3371, 3691, 4011, 4330, 4648, 4967, 5284, 5602, 5918, 6234, 6550, 6865, 7179, 7493, 7805, 8117, 8429, 8739, 9049, 9358, @@ -14880,7 +14884,7 @@ const float dico1_isf[] = }; const Word16 dico1_isf_fx[] = -{ +{/*Qlog2(2.56)*/ 740, 1263, 1292, 1006, 997, 1019, 1017, 976, 923, 557, 946, 1049, 867, 846, 990, 1112, 1262, 1241, 633, 898, 996, 756, 662, 683, 783, 909, 996, @@ -15433,7 +15437,7 @@ const float dico2_isf[] = /* ISF codebook - common 1st stage, 2nd split (only in AMR-WB IO mode) */ const Word16 dico2_isf_fx[] = -{ +{/*Qlog2(2.56)*/ 1357, 1313, 1136, 784, 438, 181, 145, 636, 648, 667, 568, 442, 217, 362, 427, 440, 674, 524, 332, 117, -417, @@ -15779,7 +15783,7 @@ const float dico21_isf_46b[] = /* ISF codebook - 46b, 2nd stage, 1st split (only in AMR-WB IO mode) */ const Word16 dico21_isf_46b_fx[] = -{ +{/*Qlog2(2.56)*/ 329, 409, 249, -33, 505, 160, -29, -14, 582, @@ -15984,7 +15988,7 @@ const float dico22_isf_46b[] = /* ISF codebook - 46b, 2nd stage, 2st split (only in AMR-WB IO mode) */ const Word16 dico22_isf_46b_fx[] = -{ +{/*Qlog2(2.56)*/ -127, 310, 42, -242, 197, 5, -151, 84, -17, @@ -16253,7 +16257,7 @@ const float dico23_isf_46b[] = /* ISF codebook - 46b, 2nd stage, 3rd split (only in AMR-WB IO mode) */ const Word16 dico23_isf_46b_fx[] = -{ +{/*Qlog2(2.56)*/ -10, 151, 359, 136, 298, 223, 255, -104, 290, @@ -16426,7 +16430,7 @@ const float dico24_isf_46b[] = /* ISF codebook - 46b, 2nd stage, 4th split (only in AMR-WB IO mode) */ const Word16 dico24_isf_46b_fx[] = -{ +{/*Qlog2(2.56)*/ -79, -89, -4, -171, 77, -211, 160, -193, 98, @@ -16503,7 +16507,7 @@ const float dico25_isf_46b[] = /* ISF codebook - 46b, 2nd stage, 5th split (only in AMR-WB IO mode) */ const Word16 dico25_isf_46b_fx[] = -{ +{/*Qlog2(2.56)*/ 169, 142, -119, 115, 206, -20, 94, 226, -106, 313, -21, 16, @@ -16688,7 +16692,7 @@ const float dico21_isf_36b[] = /* ISF codebook - 36b, 2nd stage, 1st split (only in AMR-WB IO mode) */ const Word16 dico21_isf_36b_fx[] = -{ +{/*Qlog2(2.56)*/ -52, -96, 212, 315, -73, 82, -204, 363, 136, -197, -126, -331, 183, 218, 143, @@ -16957,7 +16961,7 @@ const float dico22_isf_36b[] = /* ISF codebook - 36b, 2nd stage, 2nd split (only in AMR-WB IO mode) */ const Word16 dico22_isf_36b_fx[] = -{ +{/*Qlog2(2.56)*/ -298, -6, 95, 31, -213, -87, -122, 261, 4, -49, 208, 14, @@ -17162,7 +17166,7 @@ const float dico23_isf_36b[] = /* ISF codebook - 36b, 2nd stage, 3rd split (only in AMR-WB IO mode) */ const Word16 dico23_isf_36b_fx[] = -{ +{/*Qlog2(2.56)*/ 81, -18, 68, -27, -122, -280, -4, 45, -177, 209, -30, -136, -74, 131, -44, 101, -75, -88, -48, -137, -54, @@ -17315,7 +17319,7 @@ const float dico1_ns_28b[64*2] = /* ISF codebook for SID frames - 28b, 1st split */ const Word16 dico1_ns_28b_fx[] = -{ +{/*Qlog2(2.56)*/ -269, -673, -222, -537, -233, -430, @@ -17456,7 +17460,7 @@ const float dico2_ns_28b[64*3] = /* ISF codebook for SID frames - 28b, 2nd spilt */ const Word16 dico2_ns_28b_fx[] = -{ +{/*Qlog2(2.56)*/ -824, -884, -949, -805, -456, -418, -442, -438, -541, @@ -17597,7 +17601,7 @@ const float dico3_ns_28b[64*3] = /* ISF codebook for SID frames - 28b, 3rd spilt */ const Word16 dico3_ns_28b_fx[] = -{ +{/*Qlog2(2.56)*/ -805, -838, -774, -522, -627, -828, -477, -486, -603, @@ -17706,7 +17710,7 @@ const float dico4_ns_28b[32*4] = /* ISF codebook for SID frames - 28b, 4th spilt */ const Word16 dico4_ns_28b_fx[] = -{ +{/*Qlog2(2.56)*/ -776, -854, -891, -920, -552, -610, -663, -741, -321, -370, -476, -565, @@ -17783,7 +17787,7 @@ const float dico5_ns_28b[32*4] = /* ISF codebook for SID frames - 28b, 5th spilt */ const Word16 dico5_ns_28b_fx[] = -{ +{/*Qlog2(2.56)*/ -810, -879, -945, -254, 248, 184, 671, 128, 288, 703, 918, 99, @@ -19033,7 +19037,7 @@ const Word16 lsf_cdk_wb_vc_stg3[] = /* 14Q1*1.28 */ 13, 12, 1888, 3621, 3935, 4000, 3607, 2932, 2128 }; -const Word16 *const lsf_codebook[2][2][TCXLPC_NUMSTAGES] = +const Word16 *const lsf_codebook[2][2][TCXLPC_NUMSTAGES] = /* 14Q1*1.28 */ { { { lsf_cdk_wb_gc_stg1, lsf_cdk_wb_gc_stg2, lsf_cdk_wb_gc_stg3 }, @@ -19045,12 +19049,12 @@ const Word16 *const lsf_codebook[2][2][TCXLPC_NUMSTAGES] = } }; -const int16_t lsf_numbits[TCXLPC_NUMSTAGES] = { 5, 4, 4 }; +const Word16 lsf_numbits[TCXLPC_NUMSTAGES] = { 5, 4, 4 }; // Q0 -const int16_t lsf_dims_ivas[TCXLPC_NUMSTAGES] = { 16, 6, 10 }; -const int16_t lsf_offs_ivas[TCXLPC_NUMSTAGES] = { 0, 0, 6 }; -const Word16 lsf_dims[TCXLPC_NUMSTAGES] = { 16, 8, 12 }; -const Word16 lsf_offs[TCXLPC_NUMSTAGES] = { 0, 0, 4 }; +const Word16 lsf_dims_ivas[TCXLPC_NUMSTAGES] = { 16, 6, 10 }; // Q0 +const Word16 lsf_offs_ivas[TCXLPC_NUMSTAGES] = { 0, 0, 6 }; // Q0 +const Word16 lsf_dims[TCXLPC_NUMSTAGES] = { 16, 8, 12 }; // Q0 +const Word16 lsf_offs[TCXLPC_NUMSTAGES] = { 0, 0, 4 }; // Q0 const float lsf_ind_cdk_nb_gc_stg4_flt[] = { @@ -19119,17 +19123,17 @@ const Word16 lsf_ind_cdk_wb_vc_stg4[] = /* 14Q1*1.28 */ 2256, 2704, 0 }; -const Word16 *const lsf_ind_codebook[2][2][TCXLPC_IND_NUMSTAGES] = +const Word16 *const lsf_ind_codebook[2][2][TCXLPC_IND_NUMSTAGES] = /* 14Q1*1.28 */ { { { lsf_ind_cdk_wb_gc_stg4 }, { lsf_ind_cdk_wb_vc_stg4 } }, { { lsf_ind_cdk_nb_gc_stg4 }, { lsf_ind_cdk_nb_vc_stg4 } } }; -const int16_t lsf_ind_numbits[TCXLPC_IND_NUMSTAGES] = { 2 }; +const Word16 lsf_ind_numbits[TCXLPC_IND_NUMSTAGES] = { 2 }; // Q0 -const int16_t lsf_ind_dims_ivas[TCXLPC_IND_NUMSTAGES] = { 2 }; -const Word16 lsf_ind_dims[TCXLPC_IND_NUMSTAGES] = { 4 }; -const int16_t lsf_ind_offs[TCXLPC_IND_NUMSTAGES] = { 0 }; +const Word16 lsf_ind_dims_ivas[TCXLPC_IND_NUMSTAGES] = { 2 }; // Q0 +const Word16 lsf_ind_dims[TCXLPC_IND_NUMSTAGES] = { 4 }; // Q0 +const Word16 lsf_ind_offs[TCXLPC_IND_NUMSTAGES] = { 0 }; // Q0 const Word16 min_distance_thr[2][2] = /* 14Q1*1.28 */ { @@ -19682,11 +19686,11 @@ const float stable_LSP[M] = /* Stable ISP vector in Q15 */ const Word16 stable_ISP_fx[16] = { 32139, 30274, 27247, 23170, 18206, 12540, 6393, 0, -6390, -12537, -18203, -23170, -27243, -30271, -32139, 1475 }; /* Stable LSP vector in Q15 */ -/* This LSP corresponds to GEWB_Ave_fx */ +/* This LSP corresponds to GEWB_Ave_fx Q15*/ const Word16 stable_LSP_fx[16] = { 32437, 31676, 29486, 25681, 21564, 16413, 10838, 5385, -735, -6405, -11986, -17040, -22052, -26346, -29678, -31784 }; /* stable ISF vector */ -const Word16 stable_ISF_fx[M] = +const Word16 stable_ISF_fx[M] =/*15Q16*/ { 1023, 2048, 3072, 4096, 5120, 6144, 7168, 8192, 9216, 10240, 11264, 12288, 13311, 14335, 15361, 3978 }; /*----------------------------------------------------------------------------------* @@ -19795,22 +19799,22 @@ const float AUWB2_Ave[16] = 364.4531f, 681.6406f, 1187.5000f, 1623.8281f, 2101.1719f, 2535.1563f, 2986.7188f, 3408.2031f, 3848.4375f, 4269.5313f, 4771.0938f, 5330.8594f, 5883.5938f, 6366.0156f, 6889.0625f, 7331.2500f }; -const Word16 SVWB2_Ave_fx[16] = { 998, 1488, 2682, 3823, 5084, 6305, 7485, 8686, 9861, 11004, 12339, 13664, 15088, 16330, 17663, 18754 }; +const Word16 SVWB2_Ave_fx[16] = { 998, 1488, 2682, 3823, 5084, 6305, 7485, 8686, 9861, 11004, 12339, 13664, 15088, 16330, 17663, 18754 }; // Q2.56 /* An 16-by-1 matrix */ const Word16 IANB_Ave_fx[16] = { 726, 1433, 2493, 3408, 4340, 5215, 6103, 6947, 7772, 8536, 9252, 10012, 10909, 12427, 13997, 15193 -}; +}; // Q2.56 /* An 16-by-1 matrix */ const Word16 IAWB_Ave_fx[16] = { 577, 1350, 2526, 3535, 4539, 5504, 6497, 7460, 8445, 9396, 10371, 11319, 12307, 13268, 14249, 15207 -}; +}; // Q2.56 /* An 16-by-1 matrix */ const Word16 IAWB2_Ave_fx[16] = { 731, 1777, 3194, 4386, 5629, 6806, 8012, 9164, 10329, 11469, 12731, 14037, 15326, 16538, 17801, 18927 -}; +}; // Q2.56 /* Length 16 vector in Scale = 2.56f */ const Word16 UVNB_Ave_fx[16] = { 1018, 1764, 2856, 3751, 4611, 5410, 6233, 6961, 7685, 8304, 8859, 9325, 9977, 11741, 13699, 15074 }; /* Length 16 vector in Scale = 2.56f */ @@ -20354,7 +20358,7 @@ const float CNG_SN1[256] = /* An 16-by-16 matrix */ const Word16 CNG_SN1_fx[256] = -{ +{//Qlog2(2.56) 600, 1640, 3039, 4257, 5512, 6740, 7989, 9169, 10393, 11612, 12880, 14100, 15378, 16554, 17816, 18918, 1188, 2487, 3746, 4903, 6103, 7261, 8437, 9587, 10776, 11954, 13172, 14355, 15564, 16712, 17913, 19012, 346, 799, 2259, 3555, 4876, 6175, 7516, 8803, 10073, 11323, 12631, 13938, 15282, 16553, 17817, 19039, @@ -20514,7 +20518,7 @@ const float SVWB2_SN1[256] = { -91.02f, -115.23f, -227.34f, -448.05f, -339.84f, 30.08f, 56.25f, 130.86f, 105.08f, 196.09f, 249.22f, 280.86f, 240.23f, 146.88f, 85.55f, 67.19f }; -const Word16 SVWB2_SN1_fx[256] = { +const Word16 SVWB2_SN1_fx[256] = {//Qlog2(2.56) -257, -385, -673, 926, 1408, 874, 735, 512, 624, 587, 493, 688, 845, 521, 428, 95, -32, -90, 1046, 666, 329, -59, -324, -282, -712, -783, -229, 28, -354, -434, -497, -351, 182, 111, 512, 746, 365, 91, -214, -477, -401, -496, -931, -1180, -1422, -1085, -456, -9, @@ -20554,7 +20558,7 @@ const float SVWB2_SN2[256] = { }; /* An 16-by-16 matrix */ -const Word16 SVWB2_SN2_fx[256] = { +const Word16 SVWB2_SN2_fx[256] = {//Qlog2(2.56) -100, -130, -545, -834, 489, 501, 523, 297, 137, 198, 270, 172, 17, -50, -147, -63, 333, 351, 143, 142, 47, -137, -131, -323, -216, -32, 105, 264, 541, 425, 342, 153, -93, -168, 184, 605, 372, 237, 186, 175, 307, 321, 448, 205, -128, -481, -477, -512, @@ -20597,7 +20601,7 @@ const float SVWB2_AR2[128] = { }; /* SVWB2_AR1 * 2.56f */ -const Word16 SVWB2_AR1_fx[128] = { +const Word16 SVWB2_AR1_fx[128] = {//Qlog2(2.56) -28, -38, -122, 74, 296, 148, 146, 120, 148, 36, -11, -163, -223, -299, -290, -320, -22, -30, -138, -319, -385, 159, 124, 51, 32, -44, -15, -78, -96, -53, 40, 64, -96, -144, -205, -96, 80, 96, 152, 246, 206, 193, 265, 333, 320, 232, 131, 32, @@ -20609,7 +20613,7 @@ const Word16 SVWB2_AR1_fx[128] = { }; /* SVWB2_AR2 * 2.56f */ -const Word16 SVWB2_AR2_fx[128] = { +const Word16 SVWB2_AR2_fx[128] = {//Qlog2(2.56) 12, 16, -46, -156, -329, -293, 43, 141, 61, 15, -9, 29, -74, -41, -37, 16, -47, -81, -136, 82, -33, -111, -268, -293, 109, 136, 53, -58, -51, 62, 64, 14, -15, -19, -171, -347, 258, 161, 88, 13, -57, -26, -59, 24, 10, 14, -41, -8, @@ -20623,7 +20627,7 @@ const Word16 SVWB2_AR2_fx[128] = { /*----------------------------------------------------------------------------------* * LSF quantization - LSF mode/codebook selection tables *----------------------------------------------------------------------------------*/ -const int16_t CB_lsf[] = +const Word16 CB_lsf[] = { -1, /* Mode 0 : INACTIVE NB, Safety net */ -1, /* Mode 1 : UNVOICED NB, Safety net */ @@ -20644,9 +20648,9 @@ const int16_t CB_lsf[] = 10, /* Mode 16 : TRANSITION WB16k, Safety net */ -1, /* Mode 17 : AUDIO WB16k, Safety net */ 13 /* Mode 18 : CNG, Safety net */ -}; +}; // Q0 -const int16_t CB_p_lsf[] = +const Word16 CB_p_lsf[] = { 0, /* Mode 0 : INACTIVE NB, Predictive */ 1, /* Mode 1 : UNVOICED NB, Predictive */ @@ -20667,7 +20671,7 @@ const int16_t CB_p_lsf[] = -1, /* Mode 16 : TRANSITION WB16k, Predictive */ 10, /* Mode 17 : AUDIO WB16k, Predictive */ 9, /* Mode 18 : GENERIC WB, MA Predictive */ -}; +}; // Q0 const float * const ModeMeans[] = {IANB_Ave, UVNB_Ave, SVNB_Ave, GENB_Ave, TRNB_Ave, AUNB_Ave, IAWB_Ave, UVWB_Ave, @@ -20678,21 +20682,21 @@ const float * const Predictors[] = {Predictor6, NULL, Predictor1, Predictor3, NU }; const Word16 *const ModeMeans_fx[] = { IANB_Ave_fx, UVNB_Ave_fx, SVNB_Ave_fx, GENB_Ave_fx, TRNB_Ave_fx, AUNB_Ave_fx, IAWB_Ave_fx, UVWB_Ave_fx, SVWB_Ave_fx, GEWB_Ave_fx, TRWB_Ave_fx, AUWB_Ave_fx, IAWB2_Ave_fx, NULL, SVWB2_Ave_fx, GEWB2_Ave_fx, TRWB2_Ave_fx, AUWB2_Ave_fx -}; +}; //Qlog2(2.56) const Word16 * const Predictors_fx[] = { Predictor6_fx, NULL, Predictor1_fx, Predictor3_fx, NULL, Predictor6_fx,Predictor5_fx, NULL, Predictor0_fx, Predictor2_fx, NULL, Predictor5_fx, Predictor7_fx, NULL, Predictor8_fx, Predictor4_fx, NULL, Predictor7_fx -}; +}; // Q15 const float means_nb_31bits_ma_lsf_float[16] = {336.3281f , 531.2500f , 886.7188f , 1266.7969f , 1629.2969f , 1973.4375f , 2348.4375f , 2646.8750f , 2998.4375f , 3292.1875f , 3591.4062f , 3806.2500f , 4132.8125f , 4652.7344f , 5250.0000f , 5883.2031f}; const float means_wb_31bits_ma_lsf_float[16] = {319.5312f , 548.0469f , 934.3750f , 1353.5156f , 1730.0781f , 2120.3125f , 2505.4688f , 2860.5469f , 3243.7500f , 3601.9531f , 3969.5312f , 4332.4219f , 4736.3281f , 5137.8906f , 5562.8906f , 5963.2812f}; -const int16_t CBsizes[] = +const Word16 CBsizes[] = { 1,2,4,8,16,32,64 -}; +}; // Q0 -const int16_t CBbits[] = +const Word16 CBbits[] = { -1, /* Mode 0 : INACTIVE NB, Safety net */ -1, /* Mode 1 : UNVOICED NB, Safety net */ @@ -20713,10 +20717,10 @@ const int16_t CBbits[] = 4, /* Mode 16 : TRANSITION WB16k, Safety net */ -1, /* Mode 17 : AUDIO WB16k, Safety net */ 4, /* Mode 18: CNG, Safety net */ -}; +}; // Q0 -const int16_t CBbits_p[] = +const Word16 CBbits_p[] = { 5, /* Mode 0 : INACTIVE NB, Predictive */ 4, /* Mode 1 : UNVOICED NB, Predictive */ @@ -20737,11 +20741,11 @@ const int16_t CBbits_p[] = -1, /* Mode 16 : TRANSITION WB16k, Predictive */ 5, /* Mode 17 : AUDIO WB16k, Predictive */ 5, /* Mode 9 : GENERIC WB, Predictive */ -}; +}; // Q0 -const int16_t BitsVQ[]= +const Word16 BitsVQ[]= { -1, /* Mode 0 : INACTIVE NB, Safety net */ -1, /* Mode 1 : UNVOICED NB, Safety net */ @@ -20762,10 +20766,10 @@ const int16_t BitsVQ[]= 8, /* Mode 16 : TRANSITION WB16k, Safety net */ -1, /* Mode 17 : AUDIO WB16k, Safety net */ 4, /* Mode 18: CNG, Safety net */ -}; +}; // Q0 -const int16_t BitsVQ_p[]= +const Word16 BitsVQ_p[]= { 5, /* Mode 0 : INACTIVE NB, Predictive */ 8, /* Mode 1 : UNVOICED NB, Predictive */ @@ -20786,7 +20790,7 @@ const int16_t BitsVQ_p[]= -1, /* Mode 16 : TRANSITION WB16k, Predictive */ 5, /* Mode 17 : AUDIO WB16k, Predictive */ 5, /* Mode 18 : GENERIC WB, MA Predictive */ -}; +}; // Q0 const int16_t predmode_tab_float[][6] = @@ -20803,7 +20807,7 @@ const Word16 predmode_tab[][6] = {1,1,2,2,0,2}, {1,-1,2,1,0,1}, {1,1,2,1,0,2} /* should check how is the cb for audio mode at 13.2*/ -}; +}; // Q0 const float * const Quantizers[] = {SVNB_SN1, SVNB_SN2, GETRNB_SN1, GETRNB_SN2, AUNB_SN1,SVWB_SN1, SVWB_SN2, GETRWB_SN1, GETRWB_SN2, AUWB_SN1,TRWB2_SN1, TRWB2_SN2, AUWB2_SN1, CNG_SN1, SVWB2_SN1, SVWB2_SN2 }; @@ -20813,7 +20817,7 @@ const float * const Quantizers_p[] = {IAA_MA1, UVD_MA1, UVD_MA2, UVWB_MA3, GESVN const Word16 SVNB_SN1_fx[256] = -{ +{//Qlog2(2.56) 135, 109, 135, -153, -549, 214, 416, 195, 291, 247, 100, -127, -579, -160, -66, -32, -107, -150, -274, -149, 642, 594, 338, 183, 81, -31, -14, -150, -387, -40, -44, -18, 73, 42, 171, 339, 213, 42, -137, -277, -379, -441, -440, -478, 270, 126, -4, 6, @@ -20834,7 +20838,7 @@ const Word16 SVNB_SN1_fx[256] = /* An 16-by-16 matrix in Scale = 2.56f */ const Word16 SVNB_SN2_fx[256] = -{ +{//Qlog2(2.56) -16, 111, 111, -89, -115, -404, -514, 162, 277, 41, -94, -89, 15, 31, 2, 2, -82, -99, -25, -287, -464, 204, 18, -123, -38, 56, 109, 198, 160, 96, 41, 19, -95, -62, -242, -415, 318, 118, -121, 44, 74, 40, 85, 114, 52, 36, 21, 8, @@ -20854,7 +20858,7 @@ const Word16 SVNB_SN2_fx[256] = }; const Word16 GETRNB_SN1_fx[512] = -{ +{//Qlog2(2.56) -119, -271, -427, 447, 321, 58, 37, -105, -65, 99, 106, 21, -277, 53, 9, -6, -93, -241, -433, -826, -1028, 17, 180, 138, 320, 234, 152, 235, 973, 594, 199, 96, -300, -474, -553, -497, -374, -231, -224, -170, -145, 51, 154, 714, 1338, 690, 271, 118, @@ -20891,7 +20895,7 @@ const Word16 GETRNB_SN1_fx[512] = /* An 16-by-16 matrix in Scale = 2.56f */ const Word16 GETRNB_SN2_fx[256] = -{ +{//Qlog2(2.56) -27, 71, 45, -4, 28, 69, 25, 94, 45, 90, 45, 87, -177, -567, -116, -59, -208, -147, 531, 399, 199, 113, -21, -28, -34, -38, -48, -46, -47, 18, -1, -1, 69, -20, -115, -355, -380, 388, 379, 193, 134, 37, -42, -60, -35, 29, 6, 5, @@ -20912,7 +20916,7 @@ const Word16 GETRNB_SN2_fx[256] = /* An 16-by-16 matrix in Scale = 2.56f */ const Word16 AUNB_SN1_fx[256] = -{ +{//Qlog2(2.56) -180, -79, -51, 39, 66, 99, 48, 108, 56, 127, 34, 46, -470, -845, -141, -90, -212, 82, 284, 422, 416, 416, 313, 289, 233, 210, 108, 55, -439, -1323, -336, -123, -9, 405, 532, 659, 710, 798, 844, 971, 1072, 1181, 1464, 1913, 2028, 1232, 549, 265, @@ -20932,7 +20936,7 @@ const Word16 AUNB_SN1_fx[256] = }; const Word16 SVWB_SN1_fx[256] = -{ +{//Qlog2(2.56) -71, -61, -170, -563, -962, -845, 186, 421, 282, 344, 260, 155, 186, 52, -18, -11, -107, -139, -289, -270, 788, 615, 249, 174, -1, -24, 159, 106, -46, -183, -187, -107, -144, -221, -215, 359, 192, -34, -186, -326, -256, -124, -49, 84, 214, 237, 186, 91, @@ -20952,7 +20956,7 @@ const Word16 SVWB_SN1_fx[256] = }; const Word16 SVWB_SN2_fx[256] = -{ +{//Qlog2(2.56) -126, -152, -342, -423, 311, 95, 3, 29, -93, 4, 227, 193, 142, 120, 93, 62, 190, 258, 382, 310, 166, -11, -77, -67, -217, -327, -330, -378, -461, -309, -142, -47, -16, -58, -77, -339, -534, 469, 399, 237, 290, 135, 34, 86, -14, -77, -30, 10, @@ -20972,7 +20976,7 @@ const Word16 SVWB_SN2_fx[256] = }; const Word16 GETRWB_SN1_fx[512] = -{ +{//Qlog2(2.56) -232, -191, 282, 248, 344, 390, 428, 490, 538, 592, 620, 607, 533, 372, 261, 136, -59, -227, -418, -288, -247, -448, -501, -644, -760, -922, -1112, -1204, -523, -130, 12, 131, 139, 838, 1402, 1327, 1465, 1391, 1371, 1342, 1220, 1147, 1041, 910, 733, 518, 335, 181, @@ -21008,7 +21012,7 @@ const Word16 GETRWB_SN1_fx[512] = }; const Word16 GETRWB_SN2_fx[256] = -{ +{//Qlog2(2.56) -202, -246, -356, -356, -232, -164, -79, 4, 78, 130, 152, 165, 170, 141, 90, 70, 38, 78, -72, -185, -446, -552, 269, 295, 104, 77, -54, -184, -168, -72, -32, -2, 69, 93, 39, 116, 100, 46, 50, -1, -2, 62, 8, -105, -404, -656, -494, -224, @@ -21028,7 +21032,7 @@ const Word16 GETRWB_SN2_fx[256] = }; const Word16 AUWB_SN1_fx[256] = -{ +{//Qlog2(2.56) 328, 137, 358, 330, 184, 145, -60, -294, -555, -784, -945, -872, -601, -337, -155, -33, 32, -212, -488, -651, -752, -877, -892, -886, -853, -795, -705, -549, -330, -224, -127, -9, 372, 327, 197, 33, 13, -55, -87, -124, -125, -148, -144, -168, -175, -184, -127, -125, @@ -21049,7 +21053,7 @@ const Word16 AUWB_SN1_fx[256] = /* An 16-by-16 matrix in Scale = 2.56f */ const Word16 TRWB2_SN1_fx[256] = -{ +{//Qlog2(2.56) -74, -384, -764, -964, -1122, -912, -819, -740, -728, -572, -379, -317, -250, -51, -67, 85, -311, -618, -439, -108, 156, 257, 404, 543, 643, 729, 732, 572, 446, 329, 236, 164, 523, 1549, 1557, 1476, 1374, 1192, 1068, 923, 901, 788, 717, 401, 262, 6, -100, -368, @@ -21070,7 +21074,7 @@ const Word16 TRWB2_SN1_fx[256] = /* An 16-by-16 matrix in Scale = 2.56f */ const Word16 TRWB2_SN2_fx[256] = -{ +{//Qlog2(2.56) 50, -66, -486, -850, 504, 345, 261, 10, -207, -218, -174, -18, 72, 69, 3, 24, -171, -439, -632, 390, 143, -89, -292, -314, -227, -157, 33, 181, 185, 204, 128, 167, 458, 459, 78, -250, -365, -381, -353, -382, -327, -284, -191, -18, 3, 37, 29, 95, @@ -21091,7 +21095,7 @@ const Word16 TRWB2_SN2_fx[256] = /* An 16-by-16 matrix in Scale = 2.56f */ const Word16 AUWB2_SN1_fx[256] = -{ +{//Qlog2(2.56) -107, -446, -835, -1041, -1152, -1161, -1146, -969, -828, -533, -251, -242, -139, 172, 95, 466, 1052, 1008, 1052, 875, 864, 748, 783, 690, 754, 715, 688, 342, 195, -32, -251, -509, -311, -170, 366, 632, 748, 863, 983, 1042, 1118, 1188, 1133, 895, 728, 621, 460, 418, @@ -21112,7 +21116,7 @@ const Word16 AUWB2_SN1_fx[256] = /* An 16-by-32 matrix */ const Word16 IAA_MA1_fx[512] = -{ +{//Qlog2(2.56) -175, -490, -520, -631, -645, -614, -610, -548, -503, -432, -353, -301, -238, -141, -67, 26, 301, 407, 227, 96, -12, -18, -13, 2, 39, 107, 124, 92, 83, 100, 62, 72, -280, -737, -569, -164, -9, 100, 141, 211, 252, 281, 274, 217, 206, 219, 117, 106, @@ -21149,7 +21153,7 @@ const Word16 IAA_MA1_fx[512] = /* An 16-by-16 matrix in Scale = 2.56f */ const Word16 UVD_MA1_fx[256] = -{ +{//Qlog2(2.56) -301, -503, -426, -187, -131, -64, -45, -20, 11, 56, 63, 90, 110, 175, 97, 33, 161, 353, 474, 502, 709, 782, 794, 765, 632, 532, 406, 285, 230, 145, 97, 52, -37, -5, 205, 323, 412, 349, 221, 91, -6, -59, -86, -112, -32, 209, 73, 23, @@ -21170,7 +21174,7 @@ const Word16 UVD_MA1_fx[256] = /* An 16-by-16 matrix in Scale = 2.56f */ const Word16 UVD_MA2_fx[256] = -{ +{//Qlog2(2.56) -75, -64, -150, -231, -272, -278, -248, -194, -156, -107, -74, -43, -92, -21, 9, 5, 393, 275, -12, -156, -208, -215, -162, -132, -115, -109, -94, -85, -104, -10, 5, -1, -297, -389, -99, -78, -66, -19, -12, 8, 0, -3, -15, -22, -113, -82, -16, 2, @@ -21191,7 +21195,7 @@ const Word16 UVD_MA2_fx[256] = /* An 16-by-16 matrix in Scale = 2.56f */ const Word16 UVWB_MA3_fx[256] = -{ +{//Qlog2(2.56) -26, 23, 7, -6, -1, 3, 40, 35, -43, -24, 56, 157, 265, 423, 382, 260, 61, -300, -130, -101, -8, 106, 108, 114, 88, 43, -2, -33, -56, 67, 29, 13, -31, 47, 45, -121, 46, 22, 111, 233, -256, -252, -123, -71, -31, 54, 56, 33, @@ -21212,7 +21216,7 @@ const Word16 UVWB_MA3_fx[256] = /* An 16-by-8 matrix in Scale = 2.56f */ const Word16 GESVNB_AR1_fx[128] = -{ +{//Qlog2(2.56) -25, -64, -140, -118, 270, 240, 127, 70, 20, -40, -56, -111, -82, 64, 2, 5, 81, 104, 71, 70, 0, -49, -54, -73, -59, -92, -102, -201, -404, -52, -40, -15, -112, -217, -251, -202, -34, 57, 58, 62, 79, 127, 177, 306, 524, 315, 112, 53, @@ -21225,7 +21229,7 @@ const Word16 GESVNB_AR1_fx[128] = /* An 16-by-8 matrix in Scale = 2.56f */ const Word16 GESVNB_AR2_fx[128] = -{ +{//Qlog2(2.56) -22, -35, -31, -166, -164, 217, 212, 155, 166, 123, 67, 33, -21, -41, -3, -1, -14, -20, -16, -70, -77, -53, 23, -7, -98, -123, -99, -49, 357, 114, 36, 19, -57, -119, -303, -215, -33, -103, -97, -117, -105, -102, -67, -134, -176, 113, 16, 8, @@ -21238,7 +21242,7 @@ const Word16 GESVNB_AR2_fx[128] = /* An 16-by-8 matrix in Scale = 2.56f */ const Word16 GESVWB_AR1_fx[128] = -{ +{//Qlog2(2.56) -3, -16, -31, 2, -81, -123, -226, -260, -196, -122, -20, 78, 178, 145, 84, 46, 55, 42, 15, 32, -48, -81, -109, -137, -187, -264, -330, -387, -363, -176, -38, 37, -32, -70, -144, -269, -337, -183, 59, 58, 44, 49, 42, 51, 72, 50, 26, 38, @@ -21251,7 +21255,7 @@ const Word16 GESVWB_AR1_fx[128] = /* An 16-by-8 matrix in Scale = 2.56f */ const Word16 GESVWB_AR2_fx[128] = -{ +{//Qlog2(2.56) -147, -326, -421, -91, -22, -25, -14, -21, 32, 76, 104, 102, 65, 47, 50, 41, -39, -16, 61, -13, -38, -56, 47, 153, 195, 213, 212, 220, 245, 245, 209, 86, -34, -73, 82, 387, 199, 71, 56, -18, -33, -56, -88, -79, -5, 59, 55, 29, @@ -21264,7 +21268,7 @@ const Word16 GESVWB_AR2_fx[128] = /* An 16-by-32 matrix in Scale = 2.56f */ const Word16 GEWB2_MA1_fx[512] = -{ +{//Qlog2(2.56) 659, 1694, 1634, 1513, 1305, 1098, 933, 805, 733, 624, 525, 339, 239, 50, -35, -215, 6, 65, 125, 55, -85, -126, -272, -316, -507, -586, -1010, -1278, -1941, -1910, -426, 78, 281, 315, 236, -4, -102, -171, -232, -335, -362, -425, -488, -603, -669, -736, -648, -593, @@ -21301,7 +21305,7 @@ const Word16 GEWB2_MA1_fx[512] = /* An 16-by-32 matrix in Scale = 2.56f */ const Word16 GEWB_MA1_fx[512] = -{ +{//Qlog2(2.56) 269, 268, 416, 287, 157, 7, -132, -276, -482, -701, -1025, -1350, -1642, -982, -321, -49, 237, 949, 1374, 1228, 1337, 1219, 1123, 1016, 852, 752, 664, 559, 448, 306, 194, 83, -6, -176, -373, -111, -221, -387, -483, -639, -753, -786, -774, -655, -328, -114, -25, 27, @@ -21338,7 +21342,7 @@ const Word16 GEWB_MA1_fx[512] = /* An 16-by-32 matrix in Scale = 2.56f */ const Word16 AUWB2_MA1_fx[512] = -{ +{//Qlog2(2.56) 391, 298, 179, -37, -225, -387, -627, -864, -1216, -1644, -2108, -804, -277, -5, 121, 468, 351, 213, 141, -75, -130, -164, -332, -410, -524, -573, -575, -474, -331, -103, -22, 201, 81, 874, 1137, 1223, 1242, 1262, 1238, 1185, 1141, 1085, 993, 733, 570, 424, 256, 145, @@ -21376,11 +21380,11 @@ const Word16 AUWB2_MA1_fx[512] = const Word16 *const Quantizers_fx[] = { SVNB_SN1_fx, SVNB_SN2_fx, GETRNB_SN1_fx, GETRNB_SN2_fx, AUNB_SN1_fx,SVWB_SN1_fx, SVWB_SN2_fx, GETRWB_SN1_fx, GETRWB_SN2_fx, AUWB_SN1_fx,/* U13, */ TRWB2_SN1_fx, TRWB2_SN2_fx, AUWB2_SN1_fx, CNG_SN1_fx, SVWB2_SN1_fx, SVWB2_SN2_fx -}; +};//Qlog2(2.56) const Word16 *const Quantizers_p_fx[] = { IAA_MA1_fx, UVD_MA1_fx, UVD_MA2_fx, UVWB_MA3_fx, GESVNB_AR1_fx, GESVNB_AR2_fx, GESVWB_AR1_fx, GESVWB_AR2_fx, GEWB2_MA1_fx,GEWB_MA1_fx, AUWB2_MA1_fx, SVWB2_AR1_fx, SVWB2_AR2_fx -}; +};//Qlog2(2.56) const float vals[NO_LEADERS][MAX_NO_VALS]= { @@ -21487,9 +21491,9 @@ const Word16 vals_fx[NO_LEADERS][MAX_NO_VALS] = /*Q1 */ {7, 3, 1, 0}, }; -const int16_t no_vals[NO_LEADERS]= {2,1,2,2,2,2,3,2,1,3,2,2,2,3,3,3,2,3,3,2,3,2,3,2,3,3,4,2,3,2,2,3,2,2,4,2,2,3,3,3,3,4,4,2,3,1,3,3,3}; +const Word16 no_vals[NO_LEADERS]= {2,1,2,2,2,2,3,2,1,3,2,2,2,3,3,3,2,3,3,2,3,2,3,2,3,3,4,2,3,2,2,3,2,2,4,2,2,3,3,3,3,4,4,2,3,1,3,3,3}; // Q0 -const int16_t no_vals_ind[NO_LEADERS][MAX_NO_VALS]= +const Word16 no_vals_ind[NO_LEADERS][MAX_NO_VALS]= { {2,6,0,0}, {8,0,0,0}, @@ -21540,7 +21544,7 @@ const int16_t no_vals_ind[NO_LEADERS][MAX_NO_VALS]= {1,5,2,0}, {2,2,4,0}, {1,2,5,0} -}; +}; // Q0 const int16_t C_VQ[LATTICE_DIM+1][LATTICE_DIM+1] = @@ -21567,27 +21571,27 @@ const Word16 C_VQ_fx[LATTICE_DIM + 1][LATTICE_DIM + 1] = {1,6,15,20,15,6,1,0,0}, {1,7,21,35,35,21,7,1,0}, {1,8,28,56,70,56,28,8,1} -}; +}; // Q0 -const UWord32 table_no_cv[] = +const UWord32 table_no_cv[] = //Q0 { 0, 112, 240, 1360, 1376, 2400, 4192, 5536, 9120, 9376, 18336, 18448, 25616, 26640, 33808, 40528, 40752, 49712, 56880, 83760, 84208, 88688, 95856, 117360, 124528, 142448, 153200, 155888, 159472, 195312, 198896, 199920, 235760, 236880, 238928, 274768, 274784, 275808, 311648, 333152, 340320, 367200, 410208, 423648, 423760, 425104, 425232, 446736, 500496, 522000, 0 }; - +//Q0 const Word32 table_no_cv_fx[] = { 0, 112, 240, 1360, 1376, 2400, 4192, 5536, 9120, 9376, 18336, 18448, 25616, 26640, 33808, 40528, 40752, 49712, 56880, 83760, 84208, 88688, 95856, 117360, 124528, 142448, 153200, 155888, 159472, 195312, 198896, 199920, 235760, 236880, 238928, 274768, 274784, 275808, 311648, 333152, 340320, 367200, 410208, 423648,423760, 425104, 425232, 446736, 500496, 522000 ,0 -}; +}; // Q0 -const int16_t pi0[] = +const Word16 pi0[] = { 28,1,70,8,8,28,168,28,1,280,28,56,8,56,420,56, 70, 56,420, 56, 280, 56, 168, 28, 560, 168,336,28,280,28,8, 280,70, 8, 1120, 8, 8, 280, 168, 56, 420, 336, 840, 28, 168, 1, 168, 420, 168 -}; +}; // Q0 @@ -21700,10 +21704,10 @@ const Word16 pl_HQ_fx[] = /* Q1 vectors in first layers */ * LSF quantization for CNG *----------------------------------------------------------------------------------*/ -const int16_t cng_sort[] = {/*5f */1,1,0,1,0,0, /* 4f */0,1,0,1,0,0,1,1,1,1}; +const Word16 cng_sort[] = {/*5f */1,1,0,1,0,0, /* 4f */0,1,0,1,0,0,1,1,1,1}; // Q0 -const int16_t perm_MSLVQ[][4] = +const Word16 perm_MSLVQ[][4] = { /* 5f*/ {6,11,7,15}, @@ -21723,15 +21727,15 @@ const int16_t perm_MSLVQ[][4] = {6,11,7,12}, {6,11,7,12}, {6,11,7,12} -}; +}; // Q0 -const int16_t pl_par[] = /* 1 if even number of signs */ +const Word16 pl_par[] = /* 1 if even number of signs */ { 0, 1, 0, 0, -1, 0, 0, 1, 0, 0, 0, -1, 1, 0, 0, 0, 1, -1, 0, 0, 0, -1, 1, 0, 0, 0, 0, 1, -1, 1, -1, 0, 0, 0, 0, 0, -1, 1, -1, 1, 0, 0, 0, 0, 0, 1, -1, 1, -1 -}; +}; // Q0 const float scales[][MAX_NO_SCALES*2]= /* 2 subvectors */ @@ -22177,7 +22181,7 @@ const float scales_p[][MAX_NO_SCALES*2]= /* 2 subvectors 20 modes */ {0.787f, 1.257f, 0.596f, 1.106f, 0.735f, 1.659f, }, /* 37 (36.961) */ /* AUDIO 16k */ }; -const Word16 scales_fx[][6] = +const Word16 scales_fx[][6] =//Q11 { {3129, 0, 0, 3138, 0, 0, }, /* 14 */ {3287, 0, 0, 3138, 0, 0, }, /* 15 */ @@ -22328,7 +22332,7 @@ const Word16 scales_fx[][6] = };/* An 6-by-146 matrix in Scale = 2048.00f */ const Word16 scales_p_fx[][6] = -{ +{//Q11 {2998, 4862, 0, 0, 0, 0, }, {2591, 5251, 0, 3355, 0, 0, }, {2177, 3488, 5745, 2650, 4819, 0, }, @@ -22525,7 +22529,7 @@ const float sigma_MSLVQ[][16] = {74.8535156f, 97.3632813f, 100.1464844f, 91.6992188f, 90.3808594f, 89.6484375f, 83.2031250f, 84.0820313f, 81.9335938f, 96.4355469f, 110.9863281f, 92.6757813f, 83.4960938f, 82.1289063f, 77.8808594f, 70.8984375f} }; const Word16 sigma_MSLVQ_fx[][16] = -{ +{//Qlog2(2.56) {3}, {3}, {107, 113, 160, 185, 202, 211, 219, 222, 222, 217, 218, 270, 327, 176, 66, 43}, @@ -22602,7 +22606,7 @@ const float inv_sigma_MSLVQ[][16] = }; /* An 16-by-33 matrix in Scale = 32768.00f */ -const Word16 inv_sigma_MSLVQ_fx[][16] = +const Word16 inv_sigma_MSLVQ_fx[][16] =//Q15 { {32767}, {32767}, @@ -22687,7 +22691,7 @@ const float inv_sigma_p[][16] = {0.0143820f, 0.0124726f, 0.0098699f, 0.0099081f, 0.0093902f, 0.0089943f, 0.0092922f, 0.0088505f, 0.0085690f, 0.0085333f, 0.0082681f, 0.0079938f, 0.0076475f, 0.0077693f, 0.0081045f, 0.0095300f} /* G WB for MA*/ }; /* An 16-by-19 matrix in Scale = 32768.00f */ -const Word16 inv_sigma_p_fx[][16] = +const Word16 inv_sigma_p_fx[][16] =//Q15 { {552, 513, 469, 494, 486, 478, 492, 496, 496, 482, 480, 388, 339, 276, 743, 760}, {640, 492, 472, 478, 482, 471, 470, 471, 623, 504, 501, 477, 459, 425, 421, 408}, @@ -22711,7 +22715,7 @@ const Word16 inv_sigma_p_fx[][16] = }; const Word16 sigma_p_fx[][16] = -{ +{//Qlog2(2.56) {152, 164, 179, 170, 172, 176, 171, 169, 169, 174, 175, 216, 247, 304, 113, 110}, {131, 171, 178, 176, 174, 178, 178, 178, 135, 166, 167, 176, 183, 197, 199, 206}, {84, 89, 120, 142, 154, 175, 184, 186, 189, 181, 178, 198, 245, 190, 54, 28}, @@ -22734,7 +22738,7 @@ const Word16 sigma_p_fx[][16] = }; const Word16 sigma_p_ivas_fx[][16] = -{ +{//Qlog2(2.56) {152, 164, 179, 170, 172, 176, 171, 169, 169, 174, 175, 216, 247, 304, 113, 110}, {131, 171, 178, 176, 174, 178, 178, 178, 135, 166, 167, 176, 183, 197, 199, 206}, {84, 89, 120, 142, 154, 175, 184, 186, 189, 181, 178, 198, 245, 190, 54, 28}, @@ -22757,7 +22761,7 @@ const Word16 sigma_p_ivas_fx[][16] = }; const Word16 inv_sigma_p_ivas_fx[][16] = -{ +{//Qlog2(2.56) {552, 513, 470, 494, 487, 478, 492, 496, 496, 482, 480, 389, 339, 276, 743, 760}, {640, 492, 472, 478, 482, 471, 470, 471, 623, 504, 501, 477, 459, 425, 420, 408}, {1002, 939, 696, 589, 545, 480, 456, 450, 444, 462, 472, 424, 342, 441, 1568, 2996}, @@ -22779,7 +22783,7 @@ const Word16 inv_sigma_p_ivas_fx[][16] = {471, 409, 323, 325, 308, 295, 304, 290, 281, 280, 271, 262, 251, 255, 266, 312} }; -const Word8 leaders_short[][MAX_NO_SCALES] = +const Word8 leaders_short[][MAX_NO_SCALES] = // Q0 {{ 0, 0, 0}, { 1, 0, 0}, { 15, 3, 3}, @@ -23057,7 +23061,7 @@ const Word8 leaders_short[][MAX_NO_SCALES] = { 48, 48, 47}, { 48, 48, 48}}; -const UWord8 no_lead_idx[][2] = { +const UWord8 no_lead_idx[][2] = { // Q0 { 1, 1}, { 4, 1}, { 41, 1}, @@ -23228,7 +23232,7 @@ const UWord8 no_lead_idx[][2] = { { 55, 31}, { 81, 7}, }; -const UWord8 no_lead_p_idx[][2] = { +const UWord8 no_lead_p_idx[][2] = { // Q0 { 5, 0}, { 3, 0}, { 41, 0}, @@ -23469,20 +23473,21 @@ const UWord8 no_lead_p_idx[][2] = { }; const int16_t min_lat_bits_SN[] = {-1, -1, 17, 12, 17, 17, -1, -1, 17, 12, 17, 17, -1, -1, 22, -1, 32, 26 }; - +//Q0 const Word16 min_lat_bits_SN_fx[] = { -1, -1, 17, 12, 17, 17, -1, -1, 17, 12, 17, 17, -1, -1, 22, -1, 32, 26 }; const int16_t min_lat_bits_pred[] = {17, 18, 9, 15, -1, 21, 17, 14, 9, 15, -1, 21, 17, -1, 24, 26, -1, 26, 16}; - +//Q0 const Word16 min_lat_bits_pred_fx[] = { 17, 18, 9, 15, -1, 21, 17, 14, 9, 15, -1, 21, 17, -1, 24, 26, -1, 26, 16 }; const int16_t offset_lvq_modes_SN[] = {-1,-1,33,64,96, 129,-1,-1,12,43,79,109,-1,-1,137,-1,107,135, 112 }; /* CNG */ - +//Q0 const Word16 offset_lvq_modes_SN_fx[] = { -1,-1,26,51,77,96,-1,-1,12,36,66,90,-1,-1,105,-1,88,102,112 }; /* CNG */ const int16_t offset_lvq_modes_pred[] = {119, 153, 31, 67, -1, 102, 126, 160, 0, 46, -1, 82, 146, -1, 175, 191, -1, 225, 203}; +//Qlog2(1.6) const Word16 offset_lvq_modes_pred_fx[] = { 74, 95, 15, 45, -1, 66, 81, 102, 0, 30, -1, 60, 88, -1, 109, 117, -1, 139, 124 }; const int16_t offset_in_lvq_mode_SN[][21] = @@ -23508,7 +23513,7 @@ const int16_t offset_in_lvq_mode_SN[][21] = }; const Word16 offset_in_lvq_mode_SN_fx[][21] = -{ +{//Q0 {0}, /* I NB */ {0,1,1,1,1,1,2,3,3,3,3,4,4,4,5}, /* UV NB*/ {0,1,1,1,1,2,3,4,5,5,6,6,7,7,7,7,7,8,8,8,9}, /* V NB */ @@ -23553,7 +23558,7 @@ const int16_t offset_in_lvq_mode_pred[][32] = }; const Word16 offset_in_lvq_mode_pred_fx[][32] = -{ +{//Q0 {0,0,0,0,1,2,2,2,3,4,5,5,5,5,5,5,5,5,5,6}, /* I NB */ {0,1,1,1,2,3,4,4,4,4,4,5,5,5,6}, /* UV NB */ {0,0,0,0,0,0,0,0,0,0,1,1,1,1,2,3,4,4,5,6,7,8,9,10,10,11,12,13,13,13,14}, /* V NB */ @@ -23578,28 +23583,28 @@ const Word16 offset_in_lvq_mode_pred_fx[][32] = /*-----------------------------------------------------------------* * BC-TCVQ frame-end quantization tables (BC-TCVQ is used in Voiced mode for 16kHz isf) *-----------------------------------------------------------------*/ -const int16_t NTRANS[4][NUM_STATE] = {{0,2,4,6,8,10,12,14,0,2,4,6,8,10,12,14}, /* indices of previous state of first branche */ +const Word16 NTRANS[4][NUM_STATE] = {{0,2,4,6,8,10,12,14,0,2,4,6,8,10,12,14}, /* indices of previous state of first branche */ {1,3,5,7,9,11,13,15,1,3,5,7,9,11,13,15}, /* indices of previous state of second branches */ {4,2,1,3,0,2,1,3,2,0,3,1,7,0,3,1}, /* indices of previous subset of first branch */ {2,0,3,6,2,0,3,1,0,2,1,3,0,2,1,5} /* indices of previous subset of second branch */ -}; +}; // Q0 -const int16_t NTRANS2[4][NUM_STATE] = {{0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7}, +const Word16 NTRANS2[4][NUM_STATE] = {{0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7}, {8,8,9,9,10,10,11,11,12,12,13,13,14,14,15,15}, {4,2,2,0,1,3,3,6,0,2,2,0,1,3,3,1}, {2,0,0,2,3,1,1,3,7,0,0,2,3,1,1,5} -}; +}; // Q0 /* BC-TCQ Bit Allocations */ -const int16_t BC_TCVQ_BIT_ALLOC_40B[M/2+4] = {1, 4, 5,5,4,4, 2,2,2,2, 5,4 }; /*1+39bit*/ +const Word16 BC_TCVQ_BIT_ALLOC_40B[M/2+4] = {1, 4, 5,5,4,4, 2,2,2,2, 5,4 }; /*1+39bit Q0*/ -const int16_t FixBranch_tbl[4][4][N_STAGE_VQ - 4] = +const Word16 FixBranch_tbl[4][4][N_STAGE_VQ - 4] = { {{0, 0, 0, 0}, {1, 0, 0, 0}, {0, 1, 0, 0}, {1, 1, 0, 0}}, /* incase of initial state 0 */ {{0, 0, 1, 0}, {1, 0, 1, 0}, {0, 1, 1, 0}, {1, 1, 1, 0}}, /* incase of initial state 4 */ {{0, 0, 0, 1}, {1, 0, 0, 1}, {0, 1, 0, 1}, {1, 1, 0, 1}}, /* incase of initial state 8 */ {{0, 0, 1, 1}, {1, 0, 1, 1}, {0, 1, 1, 1}, {1, 1, 1, 1}} /* incase of initial state 12 */ -}; +}; // Q0 /* Intra-Prediction */ const float AR_IntraCoeff[N_STAGE_VQ-1][2][2] = @@ -23759,7 +23764,7 @@ const float AR_TCVQ_CB_SUB3[4][32][2] = }; const Word16 AR_TCVQ_CB_SUB1_fx[2][128][2] = /* x2.65 */ -{ +{//Qlog2(2.56) { {-435 , -434}, {-233 , 124}, {-381 , 44}, {-274 , -88}, {-332 , -224}, {-563 , -600}, {-332 , 134}, { 53 , -739}, {-567 , 0}, { 149 , 316}, {-191 , 541}, {-123 , 317}, {-493 , -634}, {-528 , 268}, {-321 , -386}, {-432 , -220}, @@ -23798,7 +23803,7 @@ const Word16 AR_TCVQ_CB_SUB1_fx[2][128][2] = /* x2.65 */ } }; const Word16 AR_TCVQ_CB_SUB2_fx[2][64][2] = -{ +{//Qlog2(2.56) { {-357 , -53}, {-525 , 167}, {-232 , 255}, {-132 , -359}, {-940 , -221}, { -260 , -1296}, {-1197 , -455}, { -833 , 49}, {-132 , -1}, {-401 , -280}, {-212 , -217}, {-194 , 92}, {-580 , -710}, { -862 , -750}, { -669 , 430}, { -521 , 719}, @@ -23821,7 +23826,7 @@ const Word16 AR_TCVQ_CB_SUB2_fx[2][64][2] = } }; const Word16 AR_TCVQ_CB_SUB3_fx[4][32][2] = -{ +{//Qlog2(2.56) { {-487 , 9}, {-456 , -400}, { 96 , 451}, {-239 , 422}, {-685 , -1309}, { 68 , -709}, {-302 , -1185}, { 481 , -287}, {-287 , -697}, {-194 , 73}, {-159 , -132}, {-161 , -312}, {-809 , 417}, {-860 , -926}, { -26 , -71}, {-1052 , -432}, @@ -23947,7 +23952,7 @@ const float SN_TCVQ_CB_SUB3[4][32][2] = }; const Word16 SN_TCVQ_CB_SUB1_fx[2][128][2] = -{ +{//Qlog2(2.56) { {-639 , 105}, {-488 , -449}, {-530 , -811}, {-419 , -634}, {-781 , -1061}, {-585 , 386}, {-501 , -737}, {-489 , -728}, {-702 , -685}, {-510 , -762}, {-390 , -287}, {-379 , -379}, {-573 , -848}, {-583 , -778}, {-500 , -810}, {-671 , -420}, @@ -23987,7 +23992,7 @@ const Word16 SN_TCVQ_CB_SUB1_fx[2][128][2] = }; const Word16 SN_TCVQ_CB_SUB2_fx[2][64][2] = -{ +{//Qlog2(2.56) { {-709 , -609}, {-615 , -1025}, {-430 , -321}, { -44 , 1032}, {-1050 , -32}, {-1028 , -1856}, {-970 , -109}, { -572 , -1426}, {-568 , 154}, {-142 , -189}, { -80 , 533}, { -38 , -632}, { -391 , 1275}, { -986 , -732}, {-479 , -510}, { -966 , 96}, @@ -24010,7 +24015,7 @@ const Word16 SN_TCVQ_CB_SUB2_fx[2][64][2] = } }; const Word16 SN_TCVQ_CB_SUB3_fx[4][32][2] = -{ +{//Qlog2(2.56) { {-377 , -872}, {-407 , 801}, {-611 , -449}, {-397 , -87}, {-476 , -1063}, {-797 , -249}, {-263 , -662}, {-473 , 1508}, {-716 , 310}, {-616 , -982}, {-742 , -1326}, { 197 , 327}, {-894 , -1556}, {-871 , -1259}, {-708 , -1380}, {-789 , -848}, @@ -24095,7 +24100,7 @@ const float AR_SVQ_CB2[16][8] = }; const Word16 AR_SVQ_CB1_fx[32][8] = /* x2.56 */ -{ +{//Qlog2(2.56) { -1, 4, 16, 4, 45, -110, 10, 167, }, { -3, 2, 8, -12, -7, 23, 279, -46, }, { 0, 2, 1, 8, -73, -40, 71, -97, }, @@ -24131,7 +24136,7 @@ const Word16 AR_SVQ_CB1_fx[32][8] = /* x2.56 */ }; const Word16 AR_SVQ_CB2_fx[16][8] = /* x2.56 */ -{ +{//Qlog2(2.56) { -37, -59, 208, -88, 54, 58, -16, -24, }, { 0, -98, 9, -65, -182, -21, 19, 9, }, { -1, 110, -8, 59, 201, 9, -38, -22, }, @@ -24178,7 +24183,7 @@ const Word16 HO_ATT_FX[5] = /* Q15 */ 17597, 20205, 22410, 23198, 23198 }; -const int16_t uniform_model[] = { MAX_AR_FREQ, MAX_AR_FREQ / 2, 0 }; +const Word16 uniform_model[] = { MAX_AR_FREQ, MAX_AR_FREQ / 2, 0 }; // Q0 /*-----------------------------------------------------------------* @@ -24192,7 +24197,7 @@ const float tbl_mid_gen_wb_2b[] = 0.4828f, 0.4701f, 0.1855f, 0.2034f, 0.1897f, 0.1691f, 0.1876f, 0.1558f, 0.1762f, 0.1863f, 0.1950f, 0.1997f, 0.2279f, 0.2492f, 0.3031f, 0.2513f, 0.8591f, 0.9902f, 0.8941f, 0.8507f, 0.8395f, 0.8579f, 0.8529f, 0.8665f, 0.8549f, 0.8490f, 0.8456f, 0.8310f, 0.8161f, 0.7884f, 0.7167f, 0.7381f }; -const Word16 tbl_mid_gen_wb_2b_fx[] = +const Word16 tbl_mid_gen_wb_2b_fx[] =//Q13 { 3814, 5145, 5856, 5290, 5277, 4880, 4877, 4273, 3868, 3776, 3392, 3163, 3120, 3019, 3395, 5814, 1482, 861, 1968, 3198, 3105, 3737, 3749, 4525, 4982, 4828, 5023, 5335, 5327, 5296, 5092, 3444, @@ -24220,7 +24225,7 @@ const float tbl_mid_gen_wb_4b[] = }; const Word16 tbl_mid_gen_wb_4b_fx[] = -{ +{//Q13 5532, 5133, 2125, 3516, 4905, 5624, 6338, 6918, 6854, 6354, 5345, 3996, 3603, 5588, 6962, 7511, 4218, 4157, 4892, 6332, 5786, 2931, 2749, 2306, 3420, 4629, 5591, 6249, 6638, 7273, 7904, 8379, 993, 369, 2927, 5138, 4840, 5892, 5331, 5158, 3956, 3130, 3324, 5022, 5292, 3974, 2488, 1119, @@ -24275,7 +24280,7 @@ const float tbl_mid_gen_wb_5b[] = 0.3360f, 0.8495f, 0.8652f, 0.5642f, 0.3230f, 0.2924f, 0.2144f, 0.0397f, 0.0596f, 0.0316f, -0.0152f, -0.0704f, -0.0675f, 0.0751f, 0.0680f, 0.5636f }; const Word16 tbl_mid_gen_wb_5b_fx[] = -{ +{//Q13 6510, 8058, 7103, 6095, 6483, 5866, 6026, 6443, 6882, 6907, 7015, 6581, 5649, 4044, 2816, 2519, 3778, 2123, 3580, 4221, 2598, 4631, 2844, 4905, 5446, 4529, 5186, 6228, 6210, 5693, 6213, -4670, 9050, 9934, 8441, 7921, 7546, 7840, 7977, 8335, 8679, 8706, 8703, 8607, 8560, 8375, 7759, 6405, @@ -24377,7 +24382,7 @@ const Word16 tbl_mid_voi_wb_1b_fx[] = /* Q13*/ 4551, 4599, 4754, 5035, 4982, 5228, 5318, 5603, 5699, 5652, 5642, 5766, 5825, 5874, 5819, 6056, 3816, 3355, 2321, 2712, 2900, 2715, 2790, 2508, 2506, 2610, 2617, 2419, 2538, 2622, 3004, 2725, }; -const Word16 tbl_mid_voi_wb_4b_fx[] = +const Word16 tbl_mid_voi_wb_4b_fx[] =//Q13 { 4337, 4235, 3526, 4083, 3514, 5457, 3168, 2509, 4418, 5021, 1313, 2952, 5347, 3893, 8325, 11758, 4180, 4037, 3965, 3481, 4028, 3284, 2644, 4585, 4749, 3076, 3211, 1101, 4175, 7440, 5745, -4105, @@ -24396,7 +24401,7 @@ const Word16 tbl_mid_voi_wb_4b_fx[] = 3394, 2776, 1970, 2707, 2983, 3931, 3247, 1729, 449, -109, -46, -469, 397, 1980, 2305, 1573, 3259, 1870, 242, 392, 748, 615, 1185, 1285, 2259, 2687, 2212, 1762, 2174, 1887, 1847, 2073, }; -const Word16 tbl_mid_voi_wb_5b_fx[] = +const Word16 tbl_mid_voi_wb_5b_fx[] =//Q13 { 4182, 3820, 4103, 5620, 4100, 4478, 3949, 5053, 2918, 3083, 4229, 3732, 1823, 6350, 17230, 4601, 4361, 4077, 2236, 4128, 3216, 4673, 6022, 6522, 5746, 4282, 3121, 4448, 6457, 12573, 4401, 7796, @@ -24488,7 +24493,7 @@ const float tbl_mid_unv_wb_5b[] = 0.5444f, 0.5385f, 0.4809f, 0.5395f, 1.1487f, -0.3404f, -0.3082f, -0.3512f, -0.2280f, 0.3479f, 0.5481f, 0.4996f, 0.3860f, 0.4747f, 0.4639f, 0.4263f, 0.7822f, 1.0122f, 1.0295f, 1.0430f, 1.0629f, 1.1165f, 1.1447f, 1.1354f, 1.1063f, 1.0919f, 1.0188f, 0.9977f, 0.8758f, 0.8855f, 0.7471f, 0.9058f }; -const Word16 tbl_mid_unv_wb_4b_fx[] = +const Word16 tbl_mid_unv_wb_4b_fx[] =//Q13 { 5190, 3143, 50, 2521, 5180, 6320, 3890, 3365, 3582, 3517, 3406, 3049, 2864, 1621, 1932, -950, 6813, 6650, 2135, 972, 452, 1453, 3221, 1697, 3165, 4443, 5924, 6297, 3907, 2862, 3586, 4625, @@ -24508,7 +24513,7 @@ const Word16 tbl_mid_unv_wb_4b_fx[] = 5380, 7307, 7727, 8135, 8270, 8471, 8792, 8573, 8335, 8420, 8057, 7562, 7119, 7458, 6806, 7385, }; const Word16 tbl_mid_unv_wb_5b_fx[] = -{ +{//Q13 6237, 6323, 1151, 763, 4218, 6546, 8437, 8701, 7456, 6604, 4631, 2901, 3050, 1793, 1955, 2260, 5542, 4318, 5343, 5521, 5999, 5477, 5265, 5234, 4616, 3329, 3444, 1816, -442, 45, -2, 8922, 6370, 8208, 6583, 5630, 5401, 5458, 5188, 5595, 6637, 6891, 6962, 6967, 7014, 6330, 5445, 3101, @@ -24548,110 +24553,110 @@ const Word16 tbl_mid_unv_wb_5b_fx[] = * AVQ - RE8 tables *------------------------------------------------------------------------------*/ -const int16_t select_table22[5][9] = +const Word16 select_table22[5][9] = { {1, 1, 1, 1, 1, 1, 1, 1, 1}, {0, 1, 2, 3, 4, 5, 6, 7, 8}, {0, 0, 1, 3, 6, 10, 15, 21, 28}, {0, 0, 0, 1, 4, 10, 20, 35, 56}, {0, 0, 0, 0, 1, 5, 15, 35, 70} -}; +}; // Q0 /* value of leader element */ -const int16_t vals_a[36][4] = +const Word16 vals_a[36][4] = { {1}, {0,2}, {0,2}, {1,3}, {0,4}, {2,0}, {1,3}, {0,2,4}, {2}, {1,3}, {2,0,4}, {0,4}, {1,5}, {1,3}, {2,0,4}, {0,2,4}, {1,3,5}, {0,2,6}, {0,4}, {0,2,6}, {0,2,4,6}, {1,7}, {0,8}, {0,6}, {0,2,8}, {0,4,8}, {1,9}, {0,2,10}, {0,8}, {0,6,10}, {0,12}, {0,4,12}, {0,10}, {0,2,14}, {0,8,12}, {0,16} -}; +}; // Q0 /* code parameter for every leader */ -const int16_t vals_q[36][4] = +const Word16 vals_q[36][4] = { {7,1}, {2,2,2}, {4,2,4}, {7,2,1}, {1,2,1}, {6,2,2}, {7,2,2}, {3,3,3,1}, {8,1}, {7,2,3}, {5,3,4,1}, {2,2,2}, {7,2,1}, {7,2,4}, {7,3,2,1}, {4,3,4,2}, {7,3,2,1}, {2,3,2,1}, {3,2,3}, {4,3,4,1}, {3,4,3,2}, {7,2,1}, {1,2,1}, {2,2,2}, {3,3,3,1}, {2,3,2,1}, {7,2,1}, {2,3,2,1}, {2,2,2}, {2,3,2,1}, {1,2,1}, {2,3,2,1}, {2,2,2}, {2,3,2,1}, {2,3,2,1}, {1,2,1} -}; +}; // Q0 /* codebook start address for every leader */ -const uint16_t Is[36] = +const UWord16 Is[36] = { 0, 128, 256, 1376, 240, 0, 1792, 2400, 5376, 5632, 12800, 3744, 21760, 22784, 31744, 38912, 45632, 3856, 52800, 53248, 57728, 60416, 4080, 61440, 61552, 62896, 63120, 64144, 64368, 64480, 64704, 64720, 64944, 65056, 65280, 65504 -}; +}; // Q0 /* A3 - Number of the absolute leaders in codebook Q3 */ -const int16_t AA3[NB_LDQ3] = +const Word16 AA3[NB_LDQ3] = { 0, 1, 4, 2, 3, 7, 11, 17, 22 -}; +}; // Q0 /* A4 - Number of the absolute leaders in codebook Q4 */ -const int16_t AA4[NB_LDQ4] = +const Word16 AA4[NB_LDQ4] = { 5, 6, 8, 9, 10, 12, 13, 14, 15, 16, 18, 19, 20, 21, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35 -}; +}; // Q0 /* I3 - Cardinality offsets for absolute leaders in Q3 */ -const uint16_t II3[NB_LDQ3] = +const UWord16 II3[NB_LDQ3] = { 0, 128, 240, 256, 1376, 2400, 3744, 3856, 4080 -}; +}; // Q0 /* I4 - Cardinality offset for absolute leaders in Q4 */ -const uint16_t II4[NB_LDQ4] = +const UWord16 II4[NB_LDQ4] = { 0, 1792, 5376, 5632, 12800, 21760, 22784, 31744, 38912, 45632, 52800, 53248, 57728, 60416, 61440, 61552, 62896, 63120, 64144, 64368, 64480, 64704, 64720, 64944, 65056, 65280, 65504 -}; +}; // Q0 /* Position of the first absolute leader on a spherical shell (or sphere) */ -const int16_t Da_pos[NB_SPHERE] = +const Word16 Da_pos[NB_SPHERE] = { 0, 2, 5, 8, 13, 18, 20, 22, 23, 25, 26, 27, 27, 28, 28, 28, 29, 30, 31, 31, 32, 32, 32, 32, 32, 34, 35, 35, 35, 35, 35, 35 -}; +}; // Q0 /* Number of absolute leaders on a spherical shell */ -const int16_t Da_nb[NB_SPHERE] = +const Word16 Da_nb[NB_SPHERE] = { 2, 3, 3, 5, 5, 2, 2, 1, 2, 1, 1, 0, 1, 0, 0, 1, 1, 1, 0, 1, 0, 0, 0, 0, 2, 1, 0, 0, 0, 0, 0, 1 -}; +}; // Q0 /* Identification code of an absolute leader */ -const int16_t Da_id[NB_LEADER] = +const Word16 Da_id[NB_LEADER] = { 0x0001, 0x0004, 0x0008, 0x000B, 0x0020, 0x000C, 0x0015, 0x0024, 0x0010, 0x001F, 0x0028, 0x0040, 0x004F, 0x0029, 0x002C, 0x0044, 0x0059, 0x00A4, 0x0060, 0x00A8, 0x00C4, 0x012D, 0x0200, 0x0144, 0x0204, 0x0220, 0x0335, 0x04E4, 0x0400, 0x0584, 0x0A20, 0x0A40, 0x09C4, 0x12C4, 0x0C20, 0x2000 -}; +}; // Q0 /* Codebook number for each absolute leader */ -const int16_t Da_nq[NB_LEADER+2] = +const Word16 Da_nq[NB_LEADER+2] = { 2, 2, 3, 3, 2, 4, 4, 3, 4, 4, 4, 3, 4, 4, 4, 4, 4, 3, 4, 4, 4, 4, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 0, 100 -}; +}; // Q0 /*------------------------------------------------------------------------------* * SWB TBE tables *------------------------------------------------------------------------------*/ -const int16_t skip_bands_SWB_TBE[NUM_SHB_SUBFR+1] = {0, 20, 40, 60, 80, 100, 120, 140, 160, 180, 200, 220, 240, 260, 280, 300, 320}; /* bands for SWB TBE quantisation */ -const int16_t skip_bands_WB_TBE[NUM_SHB_SUBFR/2+1] = {0, 10, 20, 30, 40, 50, 60, 70, 80}; /* bands for WB TBE quantisation */ +const Word16 skip_bands_SWB_TBE[NUM_SHB_SUBFR+1] = {0, 20, 40, 60, 80, 100, 120, 140, 160, 180, 200, 220, 240, 260, 280, 300, 320}; /* bands for SWB TBE quantisation Q0*/ +const Word16 skip_bands_WB_TBE[NUM_SHB_SUBFR/2+1] = {0, 10, 20, 30, 40, 50, 60, 70, 80}; /* bands for WB TBE quantisation Q0*/ const float interpol_frac_shb_flt[NB_SUBFR*2] = { 0.7f, 0.3f, 0.4f, 0.6f, 0.1f, 0.9f, 0.0f, 1.0f }; const Word16 interpol_frac_shb[NB_SUBFR * 2] = @@ -24778,7 +24783,7 @@ const Word16 window_wb_fx[L_SHB_LAHEAD / 4] =/*sin, 1 */ const float subwin_wb[SHB_OVERLAP_LEN/2+1]= {0.00000000f, 0.15643448f, 0.30901700f, 0.45399052f, 0.58778524f, 0.70710677f, 0.80901700f, 0.89100653f, 0.95105654f, 0.98768836f, 1.0000000f}; const Word16 subwin_wb_fx[SHB_OVERLAP_LEN / 2 + 1] = -{ 0, 5126, 10126, 14876, 19261, 23170, 26510, 29197, 31164, 32365, 32767 }; +{ 0, 5126, 10126, 14876, 19261, 23170, 26510, 29197, 31164, 32365, 32767 }; // Q15 /* Window for calculating SHB LPC coeffs */ const float win_lpc_shb[(L_LOOK_12k8 + L_SUBFR + L_FRAME) * 5/8]= @@ -24853,7 +24858,7 @@ const float win_lpc_hb_wb[(L_LOOK_12k8 + L_SUBFR + L_FRAME) * 5/32]= 0.991627454f, 0.995722431f, 0.998458667f, 0.999828662f }; const Word16 win_lpc_hb_wb_fx[(L_LOOK_12k8 + L_SUBFR + L_FRAME) * 5 / 32] = -{ +{//Q15 17, 70, 157, 279, 435, 625, 849, 1106, 1396, 1718, 2071, 2454, 2867, 3309, 3779, 4276, 4799, 5346, 5917, 6510, 7125, 7759, 8411, 9081, @@ -24880,7 +24885,7 @@ const float ola_win_shb_switch_fold[L_SUBFR16k] = 0.989176510f, 0.991866698f, 0.994174502f, 0.996099033f, 0.997639549f, 0.998795456f, 0.999566309f, 0.999951809f }; const Word16 ola_win_shb_switch_fold_fx[L_SUBFR16k] = -{ +{//Q15 322, 965, 1608, 2250, 2892, 3532, 4171, 4808, 5444, 6077, 6708, 7336, 7962, 8585, 9204, 9819, 10431, 11039, 11643, 12242, 12836, 13426, 14010, 14589, @@ -25212,7 +25217,7 @@ const float wb_bwe_lsfvq_cbook_8bit[256*6] = 0.240476170f, 0.27948010f, 0.32327234f, 0.37258368f, 0.41532038f, 0.45744253f }; const Word16 wb_bwe_lsfvq_cbook_8bit_fx[256 * 6] = -{ +{//Q15 2107, 3430, 5123, 6677, 9403, 13197, 4031, 5069, 7343, 8910, 10647, 12245, 2037, 3542, 6708, 8763, 10505, 12655, @@ -25999,7 +26004,7 @@ const float wac_swb[LPC_SHB_ORDER + 1] = 0.98239158f, 0.97776669f, 0.97262346f }; const Word16 wac_swb_h[LPC_SHB_ORDER] = -{ +{//Q15 32758, 32731, 32686, @@ -26013,7 +26018,7 @@ const Word16 wac_swb_h[LPC_SHB_ORDER] = }; const Word16 wac_swb_l[LPC_SHB_ORDER] = -{ +{//Q15 29673, 20874, 7850, @@ -26160,7 +26165,7 @@ const float HBCB_SubGain5bit[128] = -2.728315f, -6.770474f, -8.485444f, -4.669493f }; const Word16 HBCB_SubGain5bit_fx[128] = -{ +{//Q8 -15224, -17789, -9897, -5048, -456, -1232, -2238, -2782, -3391, -3864, -4026, -4045, -2017, -1311, -878, -1973, -12837, -15376, -8273, -4141, -2791, -3037, -2403, -342, @@ -26314,12 +26319,12 @@ const float lsf_q_cb_3b[8] = const float * const lsf_q_cb[NUM_Q_LSF] = { lsf_q_cb_4b, lsf_q_cb_4b, lsf_q_cb_3b, lsf_q_cb_3b, lsf_q_cb_3b }; -const int16_t lsf_q_cb_size[NUM_Q_LSF] = {16, 16, 8, 8, 8}; -const int16_t lsf_q_num_bits[NUM_Q_LSF] = { 4, 4, 3, 3, 3 }; +const Word16 lsf_q_cb_size[NUM_Q_LSF] = {16, 16, 8, 8, 8}; // Q0 +const Word16 lsf_q_num_bits[NUM_Q_LSF] = { 4, 4, 3, 3, 3 }; // Q0 /* Tables for approximation of upper half of SWB LSFs */ const float mirror_point_q_cb[MIRROR_POINT_Q_CB_SIZE] = { 0.01436178f, 0.02111641f, 0.02735687f, 0.03712105f }; -const Word16 mirror_point_q_cb_fx[MIRROR_POINT_Q_CB_SIZE] = { 471, 692, 896, 1216 }; +const Word16 mirror_point_q_cb_fx[MIRROR_POINT_Q_CB_SIZE] = { 471, 692, 896, 1216 }; // Q15 const float lsf_grid[4][5] = { @@ -26439,8 +26444,8 @@ const Word16 F_2_5_fx[64] = /*Q10 */ * SWB BWE tables *------------------------------------------------------------------------------*/ -const int16_t swb_bwe_trans_subband[SWB_FENV_TRANS+1] = {240, 316, 392, 476, 560}; -const int16_t swb_bwe_trans_subband_width[SWB_FENV_TRANS] = {76, 76, 84, 84}; +const Word16 swb_bwe_trans_subband[SWB_FENV_TRANS+1] = {240, 316, 392, 476, 560}; // Q0 +const Word16 swb_bwe_trans_subband_width[SWB_FENV_TRANS] = {76, 76, 84, 84}; // Q0 const Word16 sqrt_swb_bwe_trans_subband_width_fx[SWB_FENV_TRANS] = { 17854, 17854, 18770, 18770 };/*Q11 */ @@ -26448,21 +26453,21 @@ const Word16 sqrt_swb_bwe_subband_fx_L1[SWB_FENV] = { 16384, 20066, 16384, 20066 const Word16 sqrt_swb_bwe_subband_fx_L2[SWB_FENV / 2] = { 25905, 25905, 25905, 25905, 28378, 28378, 32767 }; /*Q12 */ -const int16_t swb_bwe_subband[SWB_FENV+1] = {240, 256, 280, 296, 320, 336, 360, 376, 400, 424, 448, 472, 496, 528, 560}; -const Word16 fb_bwe_subband[DIM_FB + 1] = { 640, 680, 720, 800 }; -const Word16 fb_bwe_sm_subband[DIM_FB] = { 656, 696, 760 }; +const Word16 swb_bwe_subband[SWB_FENV+1] = {240, 256, 280, 296, 320, 336, 360, 376, 400, 424, 448, 472, 496, 528, 560}; // Q0 +const Word16 fb_bwe_subband[DIM_FB + 1] = { 640, 680, 720, 800 }; // Q0 +const Word16 fb_bwe_sm_subband[DIM_FB] = { 656, 696, 760 }; // Q0 const float swb_inv_bwe_subband_width[SWB_FENV] = {0.0625f, 0.04167f, 0.0625f, 0.04167f, 0.0625f, 0.04167f, 0.0625f, 0.04167f, 0.04167f, 0.04167f, 0.04167f, 0.04167f, 0.03125f, 0.03125f}; -const Word16 swb_inv_bwe_subband_width_fx[SWB_FENV] = { 2048,1365,2048,1365,2048,1365,2048,1365,1365,1365,1365,1365,1024,1024 }; -const int16_t swb_bwe_sm_subband[SWB_FENV] = {248, 268, 288, 308, 328, 348, 368, 388, 412, 436, 460, 484, 512, 544}; +const Word16 swb_inv_bwe_subband_width_fx[SWB_FENV] = { 2048,1365,2048,1365,2048,1365,2048,1365,1365,1365,1365,1365,1024,1024 };//Q15 +const Word16 swb_bwe_sm_subband[SWB_FENV] = {248, 268, 288, 308, 328, 348, 368, 388, 412, 436, 460, 484, 512, 544}; // Q0 const float smooth_factor[SWB_FENV-1] = {0.05f, 0.05f, 0.05f, 0.05f, 0.05f, 0.05f, 0.05f, 0.0417f, 0.0417f, 0.0417f, 0.0417f, 0.03125f, 0.03125f}; -const Word16 smooth_factor_fx[SWB_FENV - 1] = { 1638, 1638, 1638, 1638, 1638, 1638, 1638, 1366, 1366, 1366, 1366, 1024, 1024 }; +const Word16 smooth_factor_fx[SWB_FENV - 1] = { 1638, 1638, 1638, 1638, 1638, 1638, 1638, 1366, 1366, 1366, 1366, 1024, 1024 };//Q15 -const int16_t fb_bwe_subband_float[DIM_FB+1] = {640, 680, 720, 800}; +const Word16 fb_bwe_subband_float[DIM_FB+1] = {640, 680, 720, 800}; // Q0 const float fb_inv_bwe_subband_width[DIM_FB] = {0.0250f, 0.0250f, 0.0125f}; -const Word16 fb_inv_bwe_subband_width_fx[DIM_FB] = { 819, 819, 409 }; -const int16_t fb_bwe_sm_subband_float[DIM_FB] = {656, 696, 760}; +const Word16 fb_inv_bwe_subband_width_fx[DIM_FB] = { 819, 819, 409 };//Q15 +const Word16 fb_bwe_sm_subband_float[DIM_FB] = {656, 696, 760}; // Q0 const float fb_smooth_factor[DIM_FB] = {0.03125f, 0.0250f, 0.015625f}; -const Word16 fb_smooth_factor_fx[DIM_FB] = { 1024, 819, 512 }; +const Word16 fb_smooth_factor_fx[DIM_FB] = { 1024, 819, 512 };//Q15 const float EnvCdbk11 [N_CB11 * DIM11] = { -8.6703f, 0.1116f, 4.5639f, 8.2950f, 8.5148f, 4.7195f, 2.8963f, @@ -27641,15 +27646,15 @@ const float gain_table_SWB_BWE[NB_SWB_SUBBANDS] = {-0.4f, 0.1f, 0.6f, 1.1f}; const Word16 gain_table_SWB_BWE_fx[NB_SWB_SUBBANDS] = { -6554/*-0.4f*/, 1638/*0.1f*/, 9830/*0.6f*/, 18022/*1.1f*/ }; /* Q14 */ -const int16_t bits_lagIndices_modeNormal[NB_SWB_SUBBANDS] = {2, 2, 1, 1}; -const int16_t subband_offsets_12KBPS[NB_SWB_SUBBANDS] = {SWB_SB_OFF0_12KBPS, SWB_SB_OFF1_12KBPS, SWB_SB_OFF2_12KBPS, SWB_SB_OFF3_12KBPS}; -const int16_t subband_offsets_16KBPS[NB_SWB_SUBBANDS] = {SWB_SB_OFF0_16KBPS, SWB_SB_OFF1_16KBPS, SWB_SB_OFF2_16KBPS, SWB_SB_OFF3_16KBPS}; +const Word16 bits_lagIndices_modeNormal[NB_SWB_SUBBANDS] = {2, 2, 1, 1}; // Q0 +const Word16 subband_offsets_12KBPS[NB_SWB_SUBBANDS] = {SWB_SB_OFF0_12KBPS, SWB_SB_OFF1_12KBPS, SWB_SB_OFF2_12KBPS, SWB_SB_OFF3_12KBPS}; // Q0 +const Word16 subband_offsets_16KBPS[NB_SWB_SUBBANDS] = {SWB_SB_OFF0_16KBPS, SWB_SB_OFF1_16KBPS, SWB_SB_OFF2_16KBPS, SWB_SB_OFF3_16KBPS}; // Q0 /* Search offset for the subbands that use a partial search */ -const int16_t subband_search_offsets[NB_SWB_SUBBANDS] = +const Word16 subband_search_offsets[NB_SWB_SUBBANDS] = { 0, 0, 64, 64 -}; +}; // Q0 @@ -27662,32 +27667,32 @@ const Word16 bw_SPT_tbl[2][SPT_SHORTEN_SBNUM]= /* Harmonic Mode */ -const int16_t bits_lagIndices_mode0_Har[NB_SWB_SUBBANDS_HAR_SEARCH_SB] = {1,1}; +const Word16 bits_lagIndices_mode0_Har[NB_SWB_SUBBANDS_HAR_SEARCH_SB] = {1,1}; // Q0 /* 13.2 kbps */ -const int16_t subband_offsets_sub5_13p2kbps_Har[NB_SWB_SUBBANDS_HAR] = +const Word16 subband_offsets_sub5_13p2kbps_Har[NB_SWB_SUBBANDS_HAR] = { SWB_SB_OFF0_SUB5_12KBPS_HAR, SWB_SB_OFF1_SUB5_12KBPS_HAR, SWB_SB_OFF2_SUB5_12KBPS_HAR, SWB_SB_OFF3_SUB5_12KBPS_HAR -}; +}; // Q0 /* Search offset for the subbands that use a partial search */ -const int16_t subband_search_offsets_13p2kbps_Har[NB_SWB_SUBBANDS_HAR_SEARCH_SB] = +const Word16 subband_search_offsets_13p2kbps_Har[NB_SWB_SUBBANDS_HAR_SEARCH_SB] = { 120, 210 -}; +}; // Q0 /* 16.4 kbps */ -const int16_t subband_offsets_sub5_16p4kbps_Har[NB_SWB_SUBBANDS_HAR] = +const Word16 subband_offsets_sub5_16p4kbps_Har[NB_SWB_SUBBANDS_HAR] = { SWB_SB_OFF0_SUB5_16KBPS_HAR, SWB_SB_OFF1_SUB5_16KBPS_HAR, SWB_SB_OFF2_SUB5_16KBPS_HAR, SWB_SB_OFF3_SUB5_16KBPS_HAR -}; +}; // Q0 /* Search offset for the subbands that use a partial search */ -const int16_t subband_search_offsets_16p4kbps_Har[NB_SWB_SUBBANDS_HAR_SEARCH_SB] = +const Word16 subband_search_offsets_16p4kbps_Har[NB_SWB_SUBBANDS_HAR_SEARCH_SB] = { 120, 210 -}; +}; // Q0 /*------------------------------------------------------------------------------* @@ -27797,7 +27802,7 @@ const float wscw16q15_8[40] = 0.137023925781250f, 0.098022460937500f, 0.058868408203125f, 0.019622802734375f, }; -const Word16 wscw16q15_fx[240] = +const Word16 wscw16q15_fx[240] =/*Q15 */ { -32768, -32766, -32764, -32759, -32754, -32747, -32738, -32729, -32717, -32705, -32691, -32675, -32658, -32640, -32621, -32600, -32577, -32553, -32528, -32501, -32473, -32444, @@ -27822,7 +27827,7 @@ const Word16 wscw16q15_fx[240] = 4171, 3958, 3745, 3532, 3319, 3105, 2892, 2678, 2464, 2250, 2036, 1822, 1608, 1394, 1179, 965, 751, 536, 322, 107 }; -const Word16 wscw16q15_8_fx[40] = +const Word16 wscw16q15_8_fx[40] =/*Q15 */ { -32762, -32711, -32610, -32459, -32258, -32007, -31706, -31357, -30959, -30514, -30022, -29483, -28899, -28270, -27598, -26883, @@ -27830,7 +27835,7 @@ const Word16 wscw16q15_8_fx[40] = 18736, 17666, 16569, 15447, 14300, 13132, 11943, 10736, 9512, 8274, 7022, 5760, 4490, 3212, 1929, 643 }; -const Word16 wscw16q15_16_fx[80] = +const Word16 wscw16q15_16_fx[80] =/*Q15 */ { -32766, -32754, -32729, -32691, -32640, -32577, -32501, -32413, -32313, -32200, -32074, -31936, -31786, -31624, -31449, -31262, @@ -27843,7 +27848,7 @@ const Word16 wscw16q15_16_fx[80] = 9819, 9204, 8585, 7962, 7336, 6708, 6077, 5444, 4808, 4171, 3532, 2892, 2250, 1608, 965, 322 }; -const Word16 wscw16q15_32_fx[160] = +const Word16 wscw16q15_32_fx[160] =/*Q15 */ { -32768, -32764, -32758, -32749, -32736, -32720, -32701, -32679, -32654, -32626, -32594, -32559, -32522, -32481, -32437, -32389, -32339, -32286, -32229, -32169, -32107, -32041, @@ -27972,16 +27977,16 @@ const Word32 dicn_pg_fx[45] = /* Q12 */ 16384, 11585, 8192, 5793, 4096, 2896, 2048, 1448, 1024, 724 }; -const int16_t expPkEnrg_tbl[45] = +const Word16 expPkEnrg_tbl[45] = { 0, 0, 0, 0, 0, 2, 2, 2, 2, 4, 4, 4, 6, 6, 8, 8, 10, 10, 12, 12, 14, 14, 16, 16, 18, 18, 20, 20, 22, 22, 24, 24, 26, 26, 28, 28, 30, 30, 32, 32, 34, 34, 36, 36, 38 -}; +}; // Q0 -const int32_t manPkEnrg_tbl[45] = +const Word32 manPkEnrg_tbl[45] = { 2147483646, 1518500308, 1073741787, 759250076, 536870912, 1518500294, 1073741787, 759250076, 536870912, 1518500294, @@ -27992,8 +27997,8 @@ const int32_t manPkEnrg_tbl[45] = 1073744140, 536870912, 1073744140, 536870912, 1073697800, 536870912, 1073697800, 536870912, 1073883168, 536870912, 1073512448, 536870912, 1073512448, 536870912, 1073512448 -}; -const int32_t E_max5_tbl[40] = +}; // Q0 +const Word32 E_max5_tbl[40] = { 2047999999, 1448154663, 1024000000, 1448154663, 1024000000, 1448154663, 1024000000, 1448154663, 1024000000, 1448154663, @@ -28003,73 +28008,73 @@ const int32_t E_max5_tbl[40] = 1448156250, 1024000000, 1448156250, 1024000000, 1448156250, 1024000000, 1448156250, 1024000000, 1448125000, 1024000000, 1448125000, 1024000000, 1448250000, 1024000000, 1448000000 -}; +}; // Q0 -const int16_t resize_huffsizn[32] = +const Word16 resize_huffsizn[32] = { 0, 0, 0, 0, 0, 11, 10, 10, 9, 8, 7, 6, 5, 4, 3, 2, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 0, 0, 0, 0, 0, 0 -}; +}; // Q0 -const int16_t huffsizn[32] = +const Word16 huffsizn[32] = { 7, 7, 7, 7, 7, 7, 7, 7, 6, 6, 6, 6, 4, 4, 3, 3, 3, 3, 4, 4, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7 -}; +}; // Q0 -const int16_t huffnorm_tran[32] = +const Word16 huffnorm_tran[32] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,122, 10, 6, 1, 0, 3, 2, 26, 58, 186, 442, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 -}; +}; // Q0 -const int16_t huffsizn_tran[32] = +const Word16 huffsizn_tran[32] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 5, 3, 2, 2, 2, 4, 6, 8, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 -}; +}; // Q0 -const int16_t pgain_huffsizn[32] = +const Word16 pgain_huffsizn[32] = { 10, 11, 10, 10, 9, 8, 6, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 6, 7, 7, 8, 10, 10, 12, 12 -}; +}; // Q0 -const int16_t dicnlg2_float[40] = +const Word16 dicnlg2_float[40] = { 34, 33, 32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, -1, -2, -3, -4, -5 -}; +}; // Q0 /*** Table for quantization of MLT coefficients ***/ -const int16_t norm_order_48[NB_SFM] = +const Word16 norm_order_48[NB_SFM] = { 0, 1, 8, 9, 16, 20, 24, 28, 32, 36, 40, 41, 37, 33, 29, 25, 21, 17, 11, 10, 3, 2, 4, 5, 12, 13, 18, 22, 26, 30, 34, 38, 42, 43, 39, 35, 31, 27, 23, 19, 15, 14, 7, 6 -}; +}; // Q0 -const int16_t norm_order_32[SFM_N_SWB] = +const Word16 norm_order_32[SFM_N_SWB] = { 0, 1, 8, 9, 16, 20, 24, 28, 32, 36, 37, 33, 29, 25, 21, 17, 11, 10, 3, 2, 4, 5, 12, 13, 18, 22, 26, 30, 34, 38, 35, 31, 27, 23, 19, 15, 14, 7, 6 -}; +}; // Q0 -const int16_t norm_order_16[SFM_N_WB] = +const Word16 norm_order_16[SFM_N_WB] = { 0, 1, 8, 9, 16, 20, 24, 21, 17, 11, 10, 3, 2, 4, 5, 12, 13, 18, 22, 25, 23, 19, 15, 14, 7, 6 -}; +}; // Q0 -const int16_t intl_bw_16[N_INTL_GRP_16] = {16, 16}; -const int16_t intl_bw_32[N_INTL_GRP_32] = {16, 24}; -const int16_t intl_bw_48[N_INTL_GRP_48] = {16, 24, 32}; +const Word16 intl_bw_16[N_INTL_GRP_16] = {16, 16}; // Q0 +const Word16 intl_bw_32[N_INTL_GRP_32] = {16, 24}; // Q0 +const Word16 intl_bw_48[N_INTL_GRP_48] = {16, 24, 32}; // Q0 -const int16_t intl_cnt_16[N_INTL_GRP_16] = {4, 1}; -const int16_t intl_cnt_32[N_INTL_GRP_32] = {4, 4}; -const int16_t intl_cnt_48[N_INTL_GRP_48] = {4, 3, 2}; +const Word16 intl_cnt_16[N_INTL_GRP_16] = {4, 1}; // Q0 +const Word16 intl_cnt_32[N_INTL_GRP_32] = {4, 4}; // Q0 +const Word16 intl_cnt_48[N_INTL_GRP_48] = {4, 3, 2}; // Q0 const Word16 band_start_HQ[44] = { @@ -28077,7 +28082,7 @@ const Word16 band_start_HQ[44] = 96, 104, 112, 120, 128, 144, 160, 176, 192, 208, 224, 240, 256, 280, 304, 328, 352, 376, 400, 424, 448, 472, 496, 520, 544, 576, 608, 640, 672, 704, 736, 768 -}; +}; // Q0 const Word16 band_end_HQ[44] = { @@ -28085,7 +28090,7 @@ const Word16 band_end_HQ[44] = 104, 112, 120, 128, 144, 160, 176, 192, 208, 224, 240, 256, 280, 304, 328, 352, 376, 400, 424, 448, 472, 496, 520, 544, 576, 608, 640, 672, 704, 736, 768, 800 -}; +}; // Q0 const Word16 band_len_HQ[44] = { @@ -28093,41 +28098,41 @@ const Word16 band_len_HQ[44] = 8, 8, 8, 8, 16, 16, 16, 16, 16, 16, 16, 16, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 32, 32, 32, 32, 32, 32, 32, 32 -}; +}; // Q0 -const int16_t band_start_wb[26] = +const Word16 band_start_wb[26] = { 0, 8, 16, 24, 32, 40, 48, 56, 64, 72, 80, 88, 96, 104, 112, 120, 128, 144, 160, 176, 192, 208, 224, 240, 256, 288 -}; +}; // Q0 -const int16_t band_end_wb[26] = +const Word16 band_end_wb[26] = { 8, 16, 24, 32, 40, 48, 56, 64, 72, 80, 88, 96, 104, 112, 120, 128, 144, 160, 176, 192, 208, 224, 240, 256, 288, 320 -}; +}; // Q0 -const int16_t band_len_wb[26] = +const Word16 band_len_wb[26] = { 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 16, 16, 16, 16, 16, 16, 16, 16, 32, 32 -}; -const Word16 band_len_harm_float[SFM_N_HARM_FB] = +}; // Q0 +const Word16 band_len_harm_float[SFM_N_HARM_FB] = // Q0 { 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 16, 16, 16, 16, 16, 16, 32, 32, 32, 48, 48, 48, 48, 64, 64, 64, 96 }; -const Word16 band_start_harm[SFM_N_HARM_FB] = +const Word16 band_start_harm[SFM_N_HARM_FB] =//Q0 { 0, 8, 16, 24, 32, 40, 48, 56, 64, 72, 80, 88, 96, 104, 112, 120, 128, 144, 160, 176, 192, 208, 224, 256, 288, 320, 368, 416, 464, 512, 576, 640, 704 }; -const Word16 band_end_harm[SFM_N_HARM_FB] = +const Word16 band_end_harm[SFM_N_HARM_FB] =//Q0 { 8, 16, 24, 32, 40, 48, 56, 64, 72, 80, 88, 96, 104, 112, 120, 128, 144, 160, 176, 192, 208, 224, 256, 288, 320, 368, 416, 464, 512, 576, 640, 704, 800 @@ -28139,10 +28144,10 @@ const float rat_flt[SFM_N_WB] = {1.5f, 1.5f, 1.5f, 1.5f, 1.5f, 1.5f, 1.5f, 1.5f, }; const Word16 rat_fx[SFM_N_WB] = { 24576, 24576, 24576, 24576, 24576, 24576, 24576, 24576, 24576, 24576, 24576, 24576, 24576, 24576, 24576, 24576, 16384, 16384, 16384, 16384, 16384, 16384, 16384, 16384, 13107, 13107 -}; +};//Q14 -const int16_t sfm_width[20] = {3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 5, 5, 6, 6, 6, 7, 8}; -const int16_t a_map[20] = {8, 6, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 5, 7, 11}; +const Word16 sfm_width[20] = {3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 5, 5, 6, 6, 6, 7, 8}; // Q0 +const Word16 a_map[20] = {8, 6, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 5, 7, 11}; // Q0 const Word32 SQRT_DIM_fx[65] = /* sqrt(x) for x = 0, 1, ..., 64. in Q15 */ @@ -28722,7 +28727,7 @@ const float short_window_48kHz[480] = 0.0359802f, 0.0294495f, 0.0229187f, 0.0163574f, 0.00982666f, 0.00326538f }; -const Word16 short_window_48kHz_fx[L_FRAME48k / 2 / 2] = /* second half is symetric and omitted */ +const Word16 short_window_48kHz_fx[L_FRAME48k / 2 / 2] = /* second half is symetric and omitted Q15*/ { 107, 322, 536, 751, 965, 1179, 1394, 1608, 1822, 2036, 2250, 2464, 2678, 2892, 3105, 3319, 3532, 3745, 3958, 4171, 4383, 4596, 4808, 5020, 5232, 5444, 5655, 5866, 6077, 6288, 6498, 6708, @@ -28740,7 +28745,7 @@ const Word16 short_window_48kHz_fx[L_FRAME48k / 2 / 2] = /* second half is sym 32074, 32117, 32159, 32200, 32239, 32276, 32313, 32348, 32381, 32413, 32444, 32473, 32501, 32528, 32553, 32577, 32600, 32621, 32640, 32658, 32675, 32691, 32705, 32717, 32729, 32738, 32747, 32754, 32759, 32764, 32766, 32767, }; -const Word16 short_window_32kHz_fx[L_FRAME32k / 2 / 2] = /* second half is symetric and omitted */ +const Word16 short_window_32kHz_fx[L_FRAME32k / 2 / 2] = /* second half is symetric and omitted Q15*/ { 161, 483, 804, 1126, 1447, 1768, 2090, 2411, 2731, 3052, 3372, 3692, 4011, 4330, 4649, 4967, 5285, 5602, 5919, 6235, 6550, 6865, 7180, 7493, 7806, 8118, 8429, 8740, 9049, 9358, 9666, 9973, @@ -28754,7 +28759,7 @@ const Word16 short_window_32kHz_fx[L_FRAME32k / 2 / 2] = /* second half is sym 32389, 32437, 32481, 32522, 32559, 32594, 32626, 32654, 32679, 32701, 32720, 32736, 32749, 32758, 32764, 32767, }; -const Word16 short_window_16kHz_fx[L_FRAME16k / 2 / 2] = /* second half is symetric and omitted */ +const Word16 short_window_16kHz_fx[L_FRAME16k / 2 / 2] = /* second half is symetric and omitted Q15*/ { 322, 965, 1608, 2250, 2892, 3532, 4171, 4808, 5444, 6077, 6708, 7336, 7962, 8585, 9204, 9819, 10431, 11039, 11643, 12242, 12836, 13426, 14010, 14589, 15162, 15730, 16291, 16846, 17395, 17937, 18472, 18999, @@ -28763,7 +28768,7 @@ const Word16 short_window_16kHz_fx[L_FRAME16k / 2 / 2] = /* second half is sym 31262, 31449, 31624, 31786, 31936, 32074, 32200, 32313, 32413, 32501, 32577, 32640, 32691, 32729, 32754, 32766, }; -const Word16 short_window_8kHz_fx[L_FRAME8k / 2 / 2] = /* second half is symetric and omitted */ +const Word16 short_window_8kHz_fx[L_FRAME8k / 2 / 2] = /* second half is symetric and omitted Q15*/ { 643, 1929, 3212, 4490, 5760, 7022, 8274, 9512, 10736, 11943, 13132, 14300, 15447, 16569, 17666, 18736, @@ -28772,20 +28777,20 @@ const Word16 short_window_8kHz_fx[L_FRAME8k / 2 / 2] = /* second half is symet 31357, 31706, 32007, 32258, 32459, 32610, 32711, 32762, }; -const Word16 inv_jp2[64] = +const Word16 inv_jp2[64] =//Q15 { 16384, 10923, 8192, 6554, 5461, 4681, 4096, 3641, 3277, 2979, 2731, 2521, 2341, 2185, 2048, 1928, 1820, 1725, 1638, 1560, 1489, 1425, 1365, 1311, 1260, 1214, 1170, 1130, 1092, 1057, 1024, 993, 964, 936, 910, 886, 862, 840, 819, 799, 780, 762, 745, 728, 712, 697, 683, 669, 655, 643, 630, 618, 607, 596, 585, 575, 565, 555, 546, 537, 529, 520, 512, 504 }; -const int16_t subf_norm_groups[4][11] = +const Word16 subf_norm_groups[4][11] = { {0,1,8,9,16,20,24,28,32,36,40}, {2,3,10,11,17,21,25,29,33,37,41}, {4,5,12,13,18,22,26,30,34,38,42}, {6,7,14,15,19,23,27,31,35,39,43} -}; +}; // Q0 const float gain_att[MAX_P_ATT] = { @@ -28835,7 +28840,7 @@ const Word16 att_step_fx[4] = /* Q=13 */ 32767, 16384, 10923, 8192 }; -const Word32 table_logcum_fx[563] = +const Word32 table_logcum_fx[563] =//Q16 { 0, 0, 0, 65536, 169408, 300480, 452650, 622058, 806041, 1002649, 1210393, 1428099, 1654816, 1889761, 2132272, 2381791, 2637833, @@ -28914,31 +28919,31 @@ const Word32 pow_getbitsfrompulses_fx[16] = /*Q21 */ 2097152, 2190001, 2286961, 2388214, 2493948, 2604365, 2719671, 2840081, 2965822, 3097129, 3234251, 3377442, 3526976, 3683128, 3846194, 4016480 }; -const Word16 DDP_fx[4] = { 3, 0, 1, 2 }; +const Word16 DDP_fx[4] = { 3, 0, 1, 2 };//Q0 const float DDP[4] = { 3.0f, 0.0f, 1.0f, 2.0f }; -const int16_t step_tcq[8][STATES] = { {0,4}, {0,4}, {1,5}, {1,5}, {2,6}, {2,6}, {3,7}, {3,7} }; -const int16_t denc[8][STATES] = { {0,2}, {2,0}, {1,3}, {3,1}, {2,0}, {0,2}, {3,1}, {1,3} }; /* enc trellis */ -const int16_t ddec[8][STATES] = { {0,2}, {1,3}, {2,0}, {3,1}, {2,0}, {3,1}, {0,2}, {1,3} }; /* dec trellis */ +const Word16 step_tcq[8][STATES] = { {0,4}, {0,4}, {1,5}, {1,5}, {2,6}, {2,6}, {3,7}, {3,7} }; // Q0 +const Word16 denc[8][STATES] = { {0,2}, {2,0}, {1,3}, {3,1}, {2,0}, {0,2}, {3,1}, {1,3} }; /* enc trellis Q0*/ +const Word16 ddec[8][STATES] = { {0,2}, {1,3}, {2,0}, {3,1}, {2,0}, {3,1}, {0,2}, {1,3} }; /* dec trellis Q0*/ -const int16_t step_LSB[STATES_LSB][2] = { {0,1}, {2,3}, {0,1}, {2,3} }; -const int16_t denc_LSB[STATES_LSB][2] = { {0,3}, {2,1}, {3,0}, {1,2} }; -const int16_t dqnt_LSB[STATES_LSB][4] = { {0,8,1,8}, {0,8,1,8}, {8,0,8,1}, {8,0,8,1} }; +const Word16 step_LSB[STATES_LSB][2] = { {0,1}, {2,3}, {0,1}, {2,3} }; // Q0 +const Word16 denc_LSB[STATES_LSB][2] = { {0,3}, {2,1}, {3,0}, {1,2} }; // Q0 +const Word16 dqnt_LSB[STATES_LSB][4] = { {0,8,1,8}, {0,8,1,8}, {8,0,8,1}, {8,0,8,1} }; // Q0 -const int16_t dstep_LSB[4][2] = { {0,2}, {0,2}, {1,3}, {1,3} }; -const int16_t ddec_LSB[4][2] = { {0,3}, {3,0}, {2,1}, {1,2} }; +const Word16 dstep_LSB[4][2] = { {0,2}, {0,2}, {1,3}, {1,3} }; // Q0 +const Word16 ddec_LSB[4][2] = { {0,3}, {3,0}, {2,1}, {1,2} }; // Q0 -const int16_t nextstate[STATES][2] = {{0, 1}, {2, 3}, {4, 5}, {6, 7}, {0, 1}, {2, 3}, {4, 5}, {6, 7}};/*current state points to next two states */ +const Word16 nextstate[STATES][2] = {{0, 1}, {2, 3}, {4, 5}, {6, 7}, {0, 1}, {2, 3}, {4, 5}, {6, 7}};/*current state points to next two states Q0*/ /*------------------------------------------------------------------------------* * PVQ tables *------------------------------------------------------------------------------*/ -const int16_t fine_gain_bits[8] = {0, 0, 0, 1, 2, 2, 4, 5}; +const Word16 fine_gain_bits[8] = {0, 0, 0, 1, 2, 2, 4, 5}; // Q0 const float finegain_1[2] = {-0.7448924f, 0.7718827f}; const float finegain_2[4] = {-1.0847910f, -0.3616628f, 0.3668007f, 1.1455675f}; const float finegain_3[8] = {-1.0000000f, -0.7142857f, -0.4285714f, -0.1428571f, 0.1428571f, 0.4285714f, 0.7142857f, 1.0000000f}; @@ -28960,323 +28965,323 @@ const Word16 finegain_5_fx[32] = /* Q14 */ 449, 1390, 2364, 3433, 4579, 5516, 6769, 7767, 9085, 10152, 11009, 12535, 14765, 17093, 20094, 24716 }; -const Word16* finegain_fx[5] = { finegain_1_fx, finegain_2_fx, finegain_3_fx, finegain_4_fx, finegain_5_fx }; +const Word16* finegain_fx[5] = { finegain_1_fx, finegain_2_fx, finegain_3_fx, finegain_4_fx, finegain_5_fx };/* Q14 */ -const uint8_t hBitsMinus1_N01[2] = {1, 7}; +const UWord8 hBitsMinus1_N01[2] = {1, 7}; // Q0 -const uint8_t hBitsMinus1_N02[65]= +const UWord8 hBitsMinus1_N02[65]= { 64, 15, 23, 28, 31, 34, 36, 38, 39, 41, 42, 43, 44, 45, 46, 47, 47, 48, 49, 49, 50, 51, 52, 53, 54, 54, 55, 56, 57, 57, 58, 59, 60, 61, 62, 63, 63, 64, 65, 65, 67, 68, 69, 69, 70, 71, 72, 72, 73, 74, 75, 76, 77, 78, 79, 80, 80, 81, 82, 83, 84, 85, 86, 87, 87 -}; +}; // Q0 -const uint8_t hBitsMinus1_N03[65]= +const UWord8 hBitsMinus1_N03[65]= { 64, 20, 33, 41, 48, 53, 57, 61, 64, 66, 69, 71, 73, 75, 76, 78, 80, 81, 82, 83, 85, 86, 88, 90, 92, 93, 95, 96, 98, 99, 100, 102, 104, 106, 108, 110, 111, 113, 114, 115, 118, 120, 122, 123, 125, 127, 128, 129, 131, 133, 135, 137, 139, 141, 142, 144, 145, 146, 149, 151, 153, 155, 157, 158, 160 -}; +}; // Q0 -const uint8_t hBitsMinus1_N04[65]= +const UWord8 hBitsMinus1_N04[65]= { 64, 23, 39, 51, 60, 67, 73, 79, 83, 87, 91, 94, 97, 100, 102, 105, 107, 109, 111, 113, 115, 116, 119, 122, 125, 127, 130, 132, 134, 136, 138, 141, 144, 147, 150, 152, 154, 156, 158, 160, 164, 167, 170, 173, 175, 177, 180, 182, 184, 187, 190, 193, 196, 199, 201, 203, 205, 207, 211, 214, 217, 220, 222, 225, 227 -}; +}; // Q0 -const uint8_t hBitsMinus1_N05[54]= +const UWord8 hBitsMinus1_N05[54]= { 53, 26, 45, 59, 70, 79, 87, 94, 100, 105, 110, 114, 118, 122, 125, 128, 131, 134, 136, 139, 141, 144, 148, 152, 155, 158, 161, 164, 167, 170, 172, 176, 181, 184, 188, 191, 194, 197, 200, 202, 207, 211, 215, 219, 222, 225, 228, 231, 233, 238, 242, 246, 250, 253 -}; +}; // Q0 -const uint8_t hBitsMinus1_N06[42]= +const UWord8 hBitsMinus1_N06[42]= { 41, 28, 49, 65, 78, 89, 99, 107, 114, 120, 126, 132, 136, 141, 145, 149, 153, 156, 159, 162, 165, 168, 173, 178, 183, 187, 191, 194, 198, 201, 204, 209, 214, 219, 224, 228, 231, 235, 238, 241, 247, 253 -}; +}; // Q0 -const uint8_t hBitsMinus1_N07[34]= +const UWord8 hBitsMinus1_N07[34]= { 33, 30, 52, 70, 85, 98, 109, 118, 126, 134, 141, 147, 153, 158, 163, 168, 172, 176, 180, 184, 188, 191, 197, 203, 208, 213, 218, 222, 226, 230, 233, 240, 246, 252 -}; +}; // Q0 -const uint8_t hBitsMinus1_N08[29]= +const UWord8 hBitsMinus1_N08[29]= { 28, 31, 55, 75, 91, 105, 117, 128, 138, 146, 154, 161, 168, 174, 180, 185, 190, 195, 200, 204, 208, 212, 219, 226, 232, 238, 243, 248, 253 -}; +}; // Q0 -const uint8_t hBitsMinus1_N09[25]= +const UWord8 hBitsMinus1_N09[25]= { 24, 33, 58, 79, 97, 112, 125, 137, 148, 157, 166, 174, 182, 189, 195, 201, 207, 212, 217, 222, 227, 231, 240, 247, 254 -}; +}; // Q0 -const uint8_t hBitsMinus1_N10[22]= +const UWord8 hBitsMinus1_N10[22]= { 21, 34, 61, 83, 101, 118, 132, 145, 157, 167, 177, 186, 194, 202, 209, 216, 222, 228, 234, 239, 245, 250 -}; +}; // Q0 -const uint8_t hBitsMinus1_N11[19]= +const UWord8 hBitsMinus1_N11[19]= { 18, 35, 63, 86, 106, 123, 139, 152, 165, 176, 187, 197, 206, 214, 222, 230, 237, 243, 250 -}; +}; // Q0 -const uint8_t hBitsMinus1_N12[17]= +const UWord8 hBitsMinus1_N12[17]= { 16, 36, 65, 89, 110, 128, 144, 159, 173, 185, 196, 207, 217, 226, 234, 242, 250 -}; +}; // Q0 -const uint8_t hBitsMinus1_N13[16]= +const UWord8 hBitsMinus1_N13[16]= { 15, 37, 67, 92, 113, 133, 150, 165, 180, 193, 205, 216, 227, 237, 246, 254, -}; +}; // Q0 -const uint8_t hBitsMinus1_N14[14]= +const UWord8 hBitsMinus1_N14[14]= { 13, 38, 68, 94, 117, 137, 155, 171, 186, 200, 213, 225, 236, 247 -}; +}; // Q0 -const uint8_t hBitsMinus1_N15[13]= +const UWord8 hBitsMinus1_N15[13]= { 12, 39, 70, 97, 120, 141, 160, 177, 193, 207, 221, 233, 245 -}; +}; // Q0 -const uint8_t hBitsMinus1_N16[13]= +const UWord8 hBitsMinus1_N16[13]= { 12, 39, 71, 99, 123, 144, 164, 182, 198, 214, 228, 241, 253 -}; +}; // Q0 -const uint8_t hBitsMinus1_N17[12]= +const UWord8 hBitsMinus1_N17[12]= { 11, 40, 73, 101, 126, 148, 168, 187, 204, 220, 234, 248 -}; +}; // Q0 -const uint8_t hBitsMinus1_N18[12]= +const UWord8 hBitsMinus1_N18[12]= { 11, 41, 74, 103, 128, 151, 172, 191, 209, 225, 241, 255 -}; +}; // Q0 -const uint8_t hBitsMinus1_N19[11]= +const UWord8 hBitsMinus1_N19[11]= { 10, 41, 75, 105, 131, 154, 176, 196, 214, 231, 247 -}; +}; // Q0 -const uint8_t hBitsMinus1_N20[11]= +const UWord8 hBitsMinus1_N20[11]= { 10, 42, 77, 107, 133, 157, 179, 200, 219, 236, 253 -}; +}; // Q0 -const uint8_t hBitsMinus1_N21[10]= +const UWord8 hBitsMinus1_N21[10]= { 9, 43, 78, 108, 135, 160, 183, 204, 223, 241 -}; +}; // Q0 -const uint8_t hBitsMinus1_N22[10]= +const UWord8 hBitsMinus1_N22[10]= { 9, 43, 79, 110, 138, 163, 186, 207, 227, 246 -}; +}; // Q0 -const uint8_t hBitsMinus1_N23[10]= +const UWord8 hBitsMinus1_N23[10]= { 9, 44, 80, 111, 140, 165, 189, 211, 231, 250 -}; +}; // Q0 -const uint8_t hBitsMinus1_N24[10]= +const UWord8 hBitsMinus1_N24[10]= { 9, 44, 81, 113, 142, 168, 192, 214, 235, 255 -}; +}; // Q0 -const uint8_t hBitsMinus1_N25[9]= +const UWord8 hBitsMinus1_N25[9]= { 8, 45, 82, 114, 143, 170, 195, 217, 239 -}; +}; // Q0 -const uint8_t hBitsMinus1_N26[9]= +const UWord8 hBitsMinus1_N26[9]= { 8, 45, 83, 116, 145, 172, 197, 221, 242 -}; +}; // Q0 -const uint8_t hBitsMinus1_N27[9]= +const UWord8 hBitsMinus1_N27[9]= { 8, 46, 84, 117, 147, 175, 200, 224, 246 -}; +}; // Q0 -const uint8_t hBitsMinus1_N28[9]= +const UWord8 hBitsMinus1_N28[9]= { 8, 46, 84, 118, 149, 177, 202, 227, 249 -}; -const uint8_t hBitsMinus1_N29[9]= +}; // Q0 +const UWord8 hBitsMinus1_N29[9]= { 8, 46, 85, 119, 150, 179, 205, 229, 252 -}; -const uint8_t hBitsMinus1_N30[8]= +}; // Q0 +const UWord8 hBitsMinus1_N30[8]= { 7, 47, 86, 121, 152, 181, 207, 232 -}; -const uint8_t hBitsMinus1_N31[8]= +}; // Q0 +const UWord8 hBitsMinus1_N31[8]= { 7, 47, 87, 122, 153, 182, 209, 235 -}; -const uint8_t hBitsMinus1_N32[8]= +}; // Q0 +const UWord8 hBitsMinus1_N32[8]= { 7, 47, 87, 123, 155, 184, 212, 237 -}; -const uint8_t hBitsMinus1_N33[8]= +}; // Q0 +const UWord8 hBitsMinus1_N33[8]= { 7, 48, 88, 124, 156, 186, 214, 240 -}; -const uint8_t hBitsMinus1_N34[8]= +}; // Q0 +const UWord8 hBitsMinus1_N34[8]= { 7, 48, 89, 125, 158, 188, 216, 242 -}; -const uint8_t hBitsMinus1_N35[8]= +}; // Q0 +const UWord8 hBitsMinus1_N35[8]= { 7, 49, 90, 126, 159, 189, 218, 245 -}; -const uint8_t hBitsMinus1_N36[8]= +}; // Q0 +const UWord8 hBitsMinus1_N36[8]= { 7, 49, 90, 127, 160, 191, 220, 247 -}; +}; // Q0 const uint8_t hBitsMinus1_N37[8]= { 7, 49, 91, 128, 162, 193, 222, 249 -}; -const uint8_t hBitsMinus1_N38[8]= +}; // Q0 +const UWord8 hBitsMinus1_N38[8]= { 7, 49, 91, 129, 163, 194, 224, 251 -}; -const uint8_t hBitsMinus1_N39[8]= +}; // Q0 +const UWord8 hBitsMinus1_N39[8]= { 7, 50, 92, 130, 164, 196, 225, 253 -}; -const uint8_t hBitsMinus1_N40[8]= +}; // Q0 +const UWord8 hBitsMinus1_N40[8]= { 7, 50, 93, 131, 165, 197, 227, 255 -}; -const uint8_t hBitsMinus1_N41[7]= +}; // Q0 +const UWord8 hBitsMinus1_N41[7]= { 6, 50, 93, 131, 166, 199, 229 -}; -const uint8_t hBitsMinus1_N42[7]= +}; // Q0 +const UWord8 hBitsMinus1_N42[7]= { 6, 51, 94, 132, 167, 200, 230 -}; -const uint8_t hBitsMinus1_N43[7]= +}; // Q0 +const UWord8 hBitsMinus1_N43[7]= { 6, 51, 94, 133, 168, 201, 232 -}; -const uint8_t hBitsMinus1_N44[7]= +}; // Q0 +const UWord8 hBitsMinus1_N44[7]= { 6, 51, 95, 134, 170, 203, 234 -}; -const uint8_t hBitsMinus1_N45[7]= +}; // Q0 +const UWord8 hBitsMinus1_N45[7]= { 6, 51, 95, 135, 171, 204, 235 -}; -const uint8_t hBitsMinus1_N46[7]= +}; // Q0 +const UWord8 hBitsMinus1_N46[7]= { 6, 52, 96, 135, 172, 205, 237 -}; -const uint8_t hBitsMinus1_N47[7]= +}; // Q0 +const UWord8 hBitsMinus1_N47[7]= { 6, 52, 96, 136, 173, 206, 238 -}; -const uint8_t hBitsMinus1_N48[7]= +}; // Q0 +const UWord8 hBitsMinus1_N48[7]= { 6, 52, 97, 137, 174, 208, 240 -}; -const uint8_t hBitsMinus1_N49[7]= +}; // Q0 +const UWord8 hBitsMinus1_N49[7]= { 6, 52, 97, 138, 175, 209, 241 -}; -const uint8_t hBitsMinus1_N50[7]= +}; // Q0 +const UWord8 hBitsMinus1_N50[7]= { 6, 53, 98, 138, 175, 210, 243 -}; -const uint8_t hBitsMinus1_N51[7]= +}; // Q0 +const UWord8 hBitsMinus1_N51[7]= { 6, 53, 98, 139, 176, 211, 244 -}; -const uint8_t hBitsMinus1_N52[7]= +}; // Q0 +const UWord8 hBitsMinus1_N52[7]= { 6, 53, 99, 140, 177, 212, 245 -}; -const uint8_t hBitsMinus1_N53[7]= +}; // Q0 +const UWord8 hBitsMinus1_N53[7]= { 6, 53, 99, 140, 178, 213, 247 -}; -const uint8_t hBitsMinus1_N54[7]= +}; // Q0 +const UWord8 hBitsMinus1_N54[7]= { 6, 54, 100, 141, 179, 214, 248 -}; -const uint8_t hBitsMinus1_N55[7]= +}; // Q0 +const UWord8 hBitsMinus1_N55[7]= { 6, 54, 100, 142, 180, 216, 249 -}; -const uint8_t hBitsMinus1_N56[7]= +}; // Q0 +const UWord8 hBitsMinus1_N56[7]= { 6, 54, 100, 142, 181, 217, 250 -}; +}; // Q0 const uint8_t hBitsMinus1_N57[7]= { 6, 54, 101, 143, 181, 218, 252 }; -const uint8_t hBitsMinus1_N58[7]= +const UWord8 hBitsMinus1_N58[7]= { 6, 54, 101, 143, 182, 219, 253 -}; -const uint8_t hBitsMinus1_N59[7]= +}; // Q0 +const UWord8 hBitsMinus1_N59[7]= { 6, 55, 102, 144, 183, 220, 254 -}; -const uint8_t hBitsMinus1_N60[7]= +}; // Q0 +const UWord8 hBitsMinus1_N60[7]= { 6, 55, 102, 145, 184, 221, 255 -}; -const uint8_t hBitsMinus1_N61[6]= +}; // Q0 +const UWord8 hBitsMinus1_N61[6]= { 5, 55, 102, 145, 185, 221 -}; -const uint8_t hBitsMinus1_N62[6]= +}; // Q0 +const UWord8 hBitsMinus1_N62[6]= { 5, 55, 103, 146, 185, 222 -}; -const uint8_t hBitsMinus1_N63[6]= +}; // Q0 +const UWord8 hBitsMinus1_N63[6]= { 5, 55, 103, 146, 186, 223 -}; -const uint8_t hBitsMinus1_N64[6]= +}; // Q0 +const UWord8 hBitsMinus1_N64[6]= { 5, 55, 103, 147, 187, 224 -}; -const int16_t dsHighDiracsTab[PVQ_MAX_BAND_SIZE - DS_INDEX_LINEAR_END ] = +}; // Q0 +const Word16 dsHighDiracsTab[PVQ_MAX_BAND_SIZE - DS_INDEX_LINEAR_END ] = { 23, 25, 27, 29, 31, 33, 35, 37, 39, 43, 47, 51, 55, 59, 63, 67, 71, 75, 83, 91, 99, 107, 115, 123, 131, 139, 147, 163, 179, 195, 211, 227, 243, 259, 275, 291, 323, 355, 387, 419, 451, 483, 512 -}; +}; // Q0 -const uint32_t intLimCDivInvDQ31[67+1] = +const UWord32 intLimCDivInvDQ31[67+1] = { 0x00000000, 0x80000000, 0x40000000, 0x2aaaaaab, 0x20000000, 0x1999999a, 0x15555556, 0x12492493, 0x10000000, 0x0e38e38f, 0x0ccccccd, 0x0ba2e8bb, 0x0aaaaaab, 0x09d89d8a, 0x0924924a, 0x08888889, @@ -29287,9 +29292,9 @@ const uint32_t intLimCDivInvDQ31[67+1] = 0x02aaaaab, 0x029cbc15, 0x028f5c29, 0x02828283, 0x02762763, 0x026a43a0, 0x025ed098, 0x0253c826, 0x02492493, 0x023ee090, 0x0234f72d, 0x022b63cc, 0x02222223, 0x02192e2a, 0x02108422, 0x02082083, 0x02000000, 0x01f81f82, 0x01f07c20, 0x01e9131b -}; +}; // Q0 -const uint8_t obtainEnergyQuantizerDensity_f[57] = +const UWord8 obtainEnergyQuantizerDensity_f[57] = { 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 4, 4, 4, @@ -29298,11 +29303,11 @@ const uint8_t obtainEnergyQuantizerDensity_f[57] = 16,18,20,20,22,24,26,30, 32,34,38,42,46,50,54,58, 64,70,76,82,90,98,108,118, 128 -}; +}; // Q0 /* (char)ceil(log2(hBitsN[N][0])) - 2) */ -const uint8_t f_log2_n[ PVQ_MAX_BAND_SIZE + 1] = +const UWord8 f_log2_n[ PVQ_MAX_BAND_SIZE + 1] = { 0xff, 0xff, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x03, 0x03, 0x03, 0x03, 0x02, 0x02, 0x02, 0x02, @@ -29312,9 +29317,9 @@ const uint8_t f_log2_n[ PVQ_MAX_BAND_SIZE + 1] = 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01}; + 0x01}; // Q0 -const uint8_t * const hBitsN[ PVQ_MAX_BAND_SIZE + 1 ]= +const UWord8 * const hBitsN[ PVQ_MAX_BAND_SIZE + 1 ]= { f_log2_n/*N=0*/, hBitsMinus1_N01, hBitsMinus1_N02, hBitsMinus1_N03, hBitsMinus1_N04, hBitsMinus1_N05, hBitsMinus1_N06, hBitsMinus1_N07, hBitsMinus1_N08, hBitsMinus1_N09, @@ -29329,9 +29334,9 @@ hBitsMinus1_N45, hBitsMinus1_N46, hBitsMinus1_N47, hBitsMinus1_N48, hBit hBitsMinus1_N50, hBitsMinus1_N51, hBitsMinus1_N52, hBitsMinus1_N53, hBitsMinus1_N54, hBitsMinus1_N55, hBitsMinus1_N56, hBitsMinus1_N57, hBitsMinus1_N58, hBitsMinus1_N59, hBitsMinus1_N60, hBitsMinus1_N61, hBitsMinus1_N62, hBitsMinus1_N63, hBitsMinus1_N64, -}; +}; // Q0 -const int16_t lim_neg_inv_tbl_fx[MAX_SPLITS + 1 ] = +const Word16 lim_neg_inv_tbl_fx[MAX_SPLITS + 1 ] = { /* 1 = optimized inv_tbl_fx constant for div by 1, Q15 */ /* 2-10 = negated inv_tbl_fx Q15*/ 0, @@ -29341,7 +29346,7 @@ const int16_t lim_neg_inv_tbl_fx[MAX_SPLITS + 1 ] = const Word16 Idx2Freq_Tbl[] = { 6554/*12.8*512*/, 48 * 512, 13108/*25.6*512*/, 32 * 512, 16 * 512, 8 * 512 }; /* in Q9 */ -const int16_t fg_inv_tbl_fx [HQ_MAX_BAND_LEN/8 + 1 ] = +const Word16 fg_inv_tbl_fx [HQ_MAX_BAND_LEN/8 + 1 ] = { /* i/8 , slice of inv_tbl_fx , Q15 */ 0, 4096, 2048, 1366, 1024, 820, 683, @@ -29349,7 +29354,7 @@ const int16_t fg_inv_tbl_fx [HQ_MAX_BAND_LEN/8 + 1 ] = }; -const uint32_t exactdivodd[ODD_DIV_SIZE] = +const UWord32 exactdivodd[ODD_DIV_SIZE] = { /* exactdivodd[0]=1/1, exactdivodd[1]=1/3, exactdivodd[n]=1/(2*n+1), exactdivodd[47]=1/95 ) */ 1U, 2863311531U, 3435973837U, 3067833783U, 954437177U, 3123612579U, 3303820997U, 4008636143U, @@ -29358,17 +29363,17 @@ const uint32_t exactdivodd[ODD_DIV_SIZE] = 438261969U, 4210752251U, 2350076445U, 1483715975U, 3089362441U, 2693454067U, 3238827797U, 3204181951U, 3237744577U, 128207979U, 2738819725U, 3811027319U, 3353604601U, 2519714147U, 1059797125U, 1631000239U, 2014922929U, 724452315U, 4244438269U, 1875962727U, 4198451177U, 3539808211U, 1062196213U, 3571604383U -}; +}; // Q0 -const int16_t gain_cb_size[MAX_GAIN_BITS] = {2, 4, 8, 16, 32}; +const Word16 gain_cb_size[MAX_GAIN_BITS] = {2, 4, 8, 16, 32}; // Q0 -const int16_t inner_frame_tbl[4] = {L_FRAME8k, L_FRAME16k, L_FRAME32k, L_FRAME48k}; /* corresponds to NB, WB, SWB, FB */ +const Word16 inner_frame_tbl[4] = {L_FRAME8k, L_FRAME16k, L_FRAME32k, L_FRAME48k}; /* corresponds to NB, WB, SWB, FB Q0*/ const Word16 hq_nominal_scaling_inv[7] = { 0, 8192, 11585, 0, 16384, 0, 20066 }; /*Q13 */ const Word16 hq_nominal_scaling[7] = { 0, 32767, 23170, 0, 16384, 0, 13377 }; /*Q15 */ -const int16_t l_spec_tbl[4] = {L_SPEC8k, L_SPEC16k, L_SPEC32k, L_SPEC48k}; /* corresponds to NB, WB, SWB, FB */ -const int16_t l_spec_ext_tbl[4] = {0, L_SPEC16k_EXT, L_SPEC32k_EXT, L_SPEC48k_EXT}; /* corresponds to NB, WB, SWB, FB */ -const Word16 sinq_16k[3 * L_FRAME16k / 20] = +const Word16 l_spec_tbl[4] = {L_SPEC8k, L_SPEC16k, L_SPEC32k, L_SPEC48k}; /* corresponds to NB, WB, SWB, FB Q0*/ +const Word16 l_spec_ext_tbl[4] = {0, L_SPEC16k_EXT, L_SPEC32k_EXT, L_SPEC48k_EXT}; /* corresponds to NB, WB, SWB, FB Q0*/ +const Word16 sinq_16k[3 * L_FRAME16k / 20] =/*Q15 */ { 536, 1608, 2678, 3745, 4808, 5866, 6918, 7962, 8998, 10024, 11039, 12043, 13033, 14010, 14972, 15917, @@ -29377,7 +29382,7 @@ const Word16 sinq_16k[3 * L_FRAME16k / 20] = 28642, 29147, 29622, 30064, 30475, 30852, 31197, 31508, 31786, 32029, 32238, 32413, 32553, 32658, 32728, 32763 }; -const Word16 sinq_32k[3 * L_FRAME32k / 20] = +const Word16 sinq_32k[3 * L_FRAME32k / 20] =/*Q15 */ { 268, 804, 1340, 1876, 2411, 2945, 3479, 4011, 4543, 5073, 5602, 6130, 6655, 7180, 7702, 8222, 8740, 9255, 9768, 10279, 10786, 11291, 11793, 12292, @@ -29388,7 +29393,7 @@ const Word16 sinq_32k[3 * L_FRAME32k / 20] = 30375, 30572, 30761, 30941, 31114, 31278, 31433, 31580, 31719, 31849, 31971, 32084, 32189, 32285, 32372, 32451, 32521, 32582, 32634, 32678, 32713, 32740, 32757, 32766 }; -const Word16 sinq_48k[3 * L_FRAME48k / 20] = +const Word16 sinq_48k[3 * L_FRAME48k / 20] =/*Q15 */ { 179, 536, 893, 1251, 1608, 1965, 2321, 2678, 3034, 3390, 3745, 4100, 4454, 4808, 5161, 5514, 5866, 6217, 6568, 6918, 7267, 7615, 7962, 8308, @@ -29410,29 +29415,29 @@ const Word16 sinq_48k[3 * L_FRAME48k / 20] = /* subband width tables */ /* NB short win: 7200/8000/9600, 13200/16400/24400 */ -const int16_t band_width_40_4_6_0_0_0[4] = { 6, 8, 11, 15 }; -const int16_t band_width_40_5_6_0_0_0[5] = { 6, 7, 7, 9, 11 }; +const Word16 band_width_40_4_6_0_0_0[4] = { 6, 8, 11, 15 }; // Q0 +const Word16 band_width_40_5_6_0_0_0[5] = { 6, 7, 7, 9, 11 }; // Q0 /* NB long win: 7200, 8000, 9600, 13200, 16400 */ -const int16_t band_width_160_13_6_2_0_0[13] = { 6, 6, 6, 6, 7, 8, 9, 10, 13, 15, 19, 24, 31 }; -const int16_t band_width_160_14_6_3_0_0[14] = { 6, 6, 6, 6, 6, 7, 8, 9, 10, 12, 15, 18, 22, 29 }; -const int16_t band_width_160_17_6_3_0_0[17] = { 6, 6, 6, 6, 6, 6, 7, 7, 8, 8, 9, 10, 11, 13, 15, 17, 19 }; -const int16_t band_width_160_18_6_4_0_0[18] = { 6, 6, 6, 6, 6, 6, 6, 7, 7, 8, 8, 9, 10, 11, 12, 14, 15, 17 }; +const Word16 band_width_160_13_6_2_0_0[13] = { 6, 6, 6, 6, 7, 8, 9, 10, 13, 15, 19, 24, 31 }; // Q0 +const Word16 band_width_160_14_6_3_0_0[14] = { 6, 6, 6, 6, 6, 7, 8, 9, 10, 12, 15, 18, 22, 29 }; // Q0 +const Word16 band_width_160_17_6_3_0_0[17] = { 6, 6, 6, 6, 6, 6, 7, 7, 8, 8, 9, 10, 11, 13, 15, 17, 19 }; // Q0 +const Word16 band_width_160_18_6_4_0_0[18] = { 6, 6, 6, 6, 6, 6, 6, 7, 7, 8, 8, 9, 10, 11, 12, 14, 15, 17 }; // Q0 /* WB short win: 13200/16400/24400 */ -const int16_t band_width_80_7_6_0_0_0[7] = { 6, 7, 8, 10, 12, 16, 21 }; +const Word16 band_width_80_7_6_0_0_0[7] = { 6, 7, 8, 10, 12, 16, 21 }; // Q0 /* WB long win: 13200, 16400 */ -const int16_t band_width_320_18_6_3_0_0[18] = { 6, 6, 6, 6, 6, 7, 7, 8, 10, 11, 13, 16, 19, 24, 30, 37, 47, 61 }; -const int16_t band_width_320_20_6_3_0_0[20] = { 6, 6, 6, 6, 6, 6, 7, 8, 8, 9, 11, 12, 14, 17, 20, 23, 28, 34, 42, 51 }; +const Word16 band_width_320_18_6_3_0_0[18] = { 6, 6, 6, 6, 6, 7, 7, 8, 10, 11, 13, 16, 19, 24, 30, 37, 47, 61 }; // Q0 +const Word16 band_width_320_20_6_3_0_0[20] = { 6, 6, 6, 6, 6, 6, 7, 8, 8, 9, 11, 12, 14, 17, 20, 23, 28, 34, 42, 51 }; // Q0 /* SWB short win: 13200, 16400 */ -const int16_t band_width_142_8_8_0_0_0[8] = {7,8,10,11,15,21,29,41}; -const int16_t band_width_160_8_8_0_0_0[8] = { 8, 9, 11,13,17,23,32,47}; +const Word16 band_width_142_8_8_0_0_0[8] = {7,8,10,11,15,21,29,41}; // Q0 +const Word16 band_width_160_8_8_0_0_0[8] = { 8, 9, 11,13,17,23,32,47}; // Q0 /* SWB long win: 13200, 16400 */ -const int16_t band_width_568_22_6_2_0_0[22] = { 6, 6, 6, 6, 6, 6, 7, 8, 9, 10, 11, 13, 16, 19, 23, 28, 34, 42, 55, 68, 84, 105}; -const int16_t band_width_640_24_6_4_0_0[24] = { 6, 6, 6, 6, 6, 6, 7,7,8,9,10,11,13,15,18,21,26,32,39,48,59, 74,92,115}; +const Word16 band_width_568_22_6_2_0_0[22] = { 6, 6, 6, 6, 6, 6, 7, 8, 9, 10, 11, 13, 16, 19, 23, 28, 34, 42, 55, 68, 84, 105}; // Q0 +const Word16 band_width_640_24_6_4_0_0[24] = { 6, 6, 6, 6, 6, 6, 7,7,8,9,10,11,13,15,18,21,26,32,39,48,59, 74,92,115}; // Q0 /* LR-MDCT: NB configuration tables */ const Xcore_Config xcore_config_8kHz_007200bps_long = { 13, L_FRAME8k, band_width_160_13_6_2_0_0, 536870912L, 24576, 24576/*eref*/, 13107, 13107/*bit_alloc_weight*/, 2, 2, 0, 0.0f, 0 /*p2a_th*/, 0.40f, 13107/*pd_thresh*/, 0.13f, 4260/*ld_slope*/, 1.2f, 19661/*ni_coef*/, 0.32f }; @@ -29459,31 +29464,31 @@ const Xcore_Config xcore_config_32kHz_013200bps_short = { 8, 568 / NUM_TIME_SWIT const Xcore_Config xcore_config_32kHz_016400bps_short = { 8, 640 / NUM_TIME_SWITCHING_BLOCKS, band_width_160_8_8_0_0_0, 644245094L, 24576, 24576/*eref*/, 8192, 8192/*bit_alloc_weight*/, 2, 4, 0, 0.0f, 0 /*p2a_th*/, 0.30f, 9830 /*pd_thresh*/, 0.13f, 4260/*ld_slope*/, 1.2f, 19661/*ni_coef*/, 0.32f }; /* bandwidths */ -const int16_t Nb[ NB_SFM] = +const Word16 Nb[ NB_SFM] = { 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 16, 16, 16, 16, 16, 16, 16, 16, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 32, 32, 32, 32, 32, 32, 32, 32 -}; +}; // Q0 /* log2(Nb) to calculate minimum bits for one pulse in PVQ */ -const int16_t LNb[ NB_SFM] = +const Word16 LNb[ NB_SFM] = { 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5 -}; +}; // Q0 /*------------------------------------------------------------------------------* * GSC tables *------------------------------------------------------------------------------*/ -const int16_t gsc_sfm_start[MBANDS_GN] = {0, 16, 32, 48, 64, 80, 96, 112, 128, 144, 160, 176, 192, 208, 224, 240}; +const Word16 gsc_sfm_start[MBANDS_GN] = {0, 16, 32, 48, 64, 80, 96, 112, 128, 144, 160, 176, 192, 208, 224, 240}; // Q0 -const int16_t gsc_sfm_end[MBANDS_GN] = {16, 32, 48, 64, 80, 96, 112, 128, 144, 160, 176, 192, 208, 224, 240, 256}; +const Word16 gsc_sfm_end[MBANDS_GN] = {16, 32, 48, 64, 80, 96, 112, 128, 144, 160, 176, 192, 208, 224, 240, 256}; // Q0 -const int16_t gsc_sfm_size[MBANDS_GN] = {16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16}; +const Word16 gsc_sfm_size[MBANDS_GN] = {16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16}; // Q0 const float sm_table[] = { @@ -29507,9 +29512,9 @@ const Word16 sm_table_fx[] = 5521, 5171, 4830, 4499, 4178, 3870, 3572, 3287, 3011, 2746, 2494, 2254, 2025, 1809, 1602, 1412, 1229, 1062, 904, 760, 629, 511, 403, 308, 226, 157, 102, 56, 26, 7, -}; +}; // Q15 -const int16_t GSC_freq_bits[] = +const Word16 GSC_freq_bits[] = { 21, 66, -6, 25, 15, 11, 10, 5, 0, 0, 5, 4, 0, 0, 4, 0, 0, /* ACELP_5k00*/ 21, 66, -6, 25, 15, 11, 10, 5, 0, 0, 5, 4, 0, 0, 4, 0, 0, /* ACELP_6k15*/ @@ -29524,9 +29529,9 @@ const int16_t GSC_freq_bits[] = 26, 96, -1, 28, 18, 13, 12,10,10, 5, 4, 4, 1, 0, 1, 3, 4, /* ACELP_16k40*/ 26, 96, 0, 28, 18, 13, 12,10,10, 5, 4, 4, 1, 0, 1, 3, 4, /* ACELP_22k60*/ 26, 96, 0, 28, 18, 13, 12,10,10, 5, 4, 4, 1, 0, 1, 3, 4 /* ACELP_24k40*/ -}; +}; // Q0 #ifdef MOD_BIT_ALLOC_ROM_TABLE -const Word32 GSC_freq_bits_fx[] = +const Word32 GSC_freq_bits_fx[] =/*Q18*/ { 5505024, 17563648, -1572864, 6553600, 3932160, 2883584, 2621440, 1310720, 0, 0, 1310720, 1048576, 0, 0, 1048576, 0, 0, /* ACELP_5k00*/ 5505024, 17563648, -1572864, 6553600, 3932160, 2883584, 2621440, 1310720, 0, 0, 1310720, 1048576, 0, 0, 1048576, 0, 0, /* ACELP_6k15*/ @@ -29542,7 +29547,7 @@ const Word32 GSC_freq_bits_fx[] = 8126464, 25165824, 0, 7340032, 4718592, 3407872, 3145728, 2621440, 2621440, 1310720, 1048576, 1048576, 262144, 0, 262144, 786432, 1048576, /* ACELP_22k60*/ 26, 96, -1, 28, 18, 13, 12,10,10, 5, 4, 4, 1, 0, 1, 3, 4, /* ACELP_16k40*/ }; -const Word32 GSC_freq_bits_fx_Q18[] = +const Word32 GSC_freq_bits_fx_Q18[] =/*Q18*/ { 5505024, 17301504, -1572864, 6553600, 3932160, 2883584, 2621440, 1310720, 0, 0, 1310720, 1048576, 0, 0, 1048576, 0, 0, 5505024, 17301504, -1572864, 6553600, 3932160, 2883584, 2621440, 1310720, 0, 0, 1310720, 1048576, 0, 0, 1048576, 0, 0, @@ -29569,10 +29574,10 @@ const Word32 GSC_freq_bits_fx[] = 8126464, 25165824, -1048576, 7340032, 4718592, 3407872, 3145728, 2621440, 2621440, 1310720, 1048576, 1048576, 262144, 0, 262144, 786432, 1048576, /* ACELP_13k20*/ }; #endif -const int16_t Compl_GSC_freq_bits[] = +const Word16 Compl_GSC_freq_bits[] = { 5, 10, 10, 10 /* bitrate > ACELP_16k40 && FS = 16kHz */ -}; +}; // Q0 const float mfreq_loc[] = { @@ -29580,7 +29585,7 @@ const float mfreq_loc[] = 4375.0f, 4775.0f, 5175.0f, 5575.0f, 6375.0f, 7175.0f, 7975.0f }; -const int16_t mfreq_bindiv_loc[] = { 8, 8, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 32, 32, 32 }; +const Word16 mfreq_bindiv_loc[] = { 8, 8, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 32, 32, 32 }; // Q0 const float mean_gp[] = { 0.5853f }; const Word16 mean_gp_fx[] = { 9590 }; /*Q14*/ @@ -30671,7 +30676,7 @@ const float YGain_mean_LR[] = -0.0113f, -0.0029f, 0.0156f, 0.0123f, 0.0288f, 0.0167f, 0.0324f, 0.0369f, }; -const Word16 YGain_mean_LR_fx[1 * 12] = +const Word16 YGain_mean_LR_fx[1 * 12] =/* Q12 */ { -385, -178, -143, -116, -46, -12, 64, 50, 118, 68, 133, 151 @@ -31618,7 +31623,7 @@ const float YG_dicL2G_16kHz[] = 0.2962f, 0.3062f, }; -const Word16 YG_dicL2G_16kHz_fx[] = +const Word16 YG_dicL2G_16kHz_fx[] =//Q12 { -255, 122, 296, 314, @@ -31630,11 +31635,11 @@ const Word16 YG_dicL2G_16kHz_fx[] = 1213, 1254, }; -const int16_t Odx_fft64[64] = +const Word16 Odx_fft64[64] = { 0,59,54,49,44,39,34,29,24,19,14,9,4,63,58,53,48,43,38,33,28,23,18,13,8,3,62,57,52,47,42,37, 32,27,22,17,12,7,2,61,56,51,46,41,36,31,26,21,16,11,6,1,60,55,50,45,40,35,30,25,20,15,10,5 -}; +}; // Q0 const float w_fft64[32] = { @@ -31644,51 +31649,51 @@ const float w_fft64[32] = 0.95694035f,0.29028469f,0.47139674f,0.88192123f,0.77301043f,0.63439327f,0.098017141f,0.99518472f }; -const int16_t Ip_fft64[6] = { 32,1,0,64,32,96 }; +const Word16 Ip_fft64[6] = { 32,1,0,64,32,96 }; // Q0 -const int16_t Odx_fft32_15[32] = { 0,17,2,19,4,21,6,23,8,25,10,27,12,29,14,31,16,1,18,3,20,5,22,7,24,9,26,11,28,13,30,15 }; +const Word16 Odx_fft32_15[32] = { 0,17,2,19,4,21,6,23,8,25,10,27,12,29,14,31,16,1,18,3,20,5,22,7,24,9,26,11,28,13,30,15 }; // Q0 const float w_fft32[16] = { 1.0000000f,0.00000000f,0.70710677f,0.70710677f,0.92387950f,0.38268346f,0.38268346f,0.92387950f, 0.98078525f,0.19509032f,0.55557024f,0.83146960f,0.83146960f,0.55557024f,0.19509032f,0.98078525f }; -const Word32 w_fft32_16fx[16] = +const Word32 w_fft32_16fx[16] =//Q30 { 1073741824, 0, 759250113, 759250113, 992008059, 410903236, 410903236, 992008059, 1053110143, 209476636, 596539003, 892783685, 892783685, 596539003, 209476636, 1053110143 }; -const int16_t Ip_fft32[6] = { 16,1,0,32,16,48 }; +const Word16 Ip_fft32[6] = { 16,1,0,32,16,48 }; // Q0 -const int16_t Odx_fft32_5[32] = { 0,27,22,17,12,7,2,29,24,19,14,9,4,31,26,21,16,11,6,1,28,23,18,13,8,3,30,25,20,15,10,5 }; +const Word16 Odx_fft32_5[32] = { 0,27,22,17,12,7,2,29,24,19,14,9,4,31,26,21,16,11,6,1,28,23,18,13,8,3,30,25,20,15,10,5 }; // Q0 -const int16_t Odx_fft16[16] = {0,11,6,1,12,7,2,13,8,3,14,9,4,15,10,5}; +const Word16 Odx_fft16[16] = {0,11,6,1,12,7,2,13,8,3,14,9,4,15,10,5}; // Q0 const float w_fft16[8] = { 1.0000000f,0.00000000f,0.70710677f,0.70710677f,0.92387950f,0.38268346f,0.38268346f,0.92387950f }; -const int16_t Ip_fft16[6] = {8,1,0,16,8,24}; +const Word16 Ip_fft16[6] = {8,1,0,16,8,24}; // Q0 const float w_fft8[8] = {1.0000000f,0.00000000f,0.70710677f,0.70710677f }; -const int16_t Ip_fft8[6] = {4,1,0,8,4,12}; +const Word16 Ip_fft8[6] = {4,1,0,8,4,12}; // Q0 -const int16_t Idx_dortft80[80] = +const Word16 Idx_dortft80[80] = { 0,65,50,35,20,5,70,55,40,25,10,75,60,45,30,15,16,1,66,51,36,21,6,71,56,41,26,11,76,61, 46,31,32,17,2,67,52,37,22,7,72,57,42,27,12,77,62,47,48,33,18,3,68,53,38,23,8,73,58,43, 28,13,78,63,64,49,34,19,4,69,54,39,24,9,74,59,44,29,14,79 -}; +}; // Q0 -const int16_t Idx_dortft120[120] = +const Word16 Idx_dortft120[120] = { 0,105,90,75,60,45,30,15,16,1,106,91,76,61,46,31,32,17,2,107,92,77,62,47, 48,33,18,3,108,93,78,63,64,49,34,19,4,109,94,79,80,65,50,35,20,5,110,95, 96,81,66,51,36,21,6,111,112,97,82,67,52,37,22,7,8,113,98,83,68,53,38,23, 24,9,114,99,84,69,54,39,40,25,10,115,100,85,70,55,56,41,26,11,116,101,86, 71,72,57,42,27,12,117,102,87,88,73,58,43,28,13,118,103,104,89,74,59,44,29,14,119 -}; +}; // Q0 -const int16_t Idx_dortft160[160] = +const Word16 Idx_dortft160[160] = { 0,65,130,35,100,5,70,135,40,105,10,75,140,45,110,15,80,145, 50,115,20,85,150,55,120,25,90,155,60,125,30,95,96,1,66,131, @@ -31699,9 +31704,9 @@ const int16_t Idx_dortft160[160] = 108,13,78,143,48,113,18,83,148,53,118,23,88,153,58,123,28,93, 158,63,64,129,34,99,4,69,134,39,104,9,74,139,44,109,14,79, 144,49,114,19,84,149,54,119,24,89,154,59,124,29,94,159 -}; +}; // Q0 -const int16_t Idx_dortft320[320] = +const Word16 Idx_dortft320[320] = { 0,65,130,195,260,5,70,135,200,265,10,75,140,205,270,15,80,145,210,275,20,85,150,215,280,25,90,155,220,285,30,95, 160,225,290,35,100,165,230,295,40,105,170,235,300,45,110,175,240,305,50,115,180,245,310,55,120,185,250,315,60,125, @@ -31714,9 +31719,9 @@ const int16_t Idx_dortft320[320] = 58,123,188,253,318,63,64,129,194,259,4,69,134,199,264,9,74,139,204,269,14,79,144,209,274,19,84,149,214,279,24,89,154, 219,284,29,94,159,224,289,34,99,164,229,294,39,104,169,234,299,44,109,174,239,304,49,114,179,244,309,54,119,184,249, 314,59,124,189,254,319 -}; +}; // Q0 -const int16_t Idx_dortft480[480] = +const Word16 Idx_dortft480[480] = { 0,225,450,195,420,165,390,135,360,105,330,75,300,45,270,15,240,465,210,435,180,405,150,375,120,345, 90,315,60,285,30,255,256,1,226,451,196,421,166,391,136,361,106,331,76,301,46,271,16,241,466,211,436, @@ -31736,9 +31741,9 @@ const int16_t Idx_dortft480[480] = 117,342,87,312,57,282,27,252,477,222,447,448,193,418,163,388,133,358,103,328,73,298,43,268,13,238,463, 208,433,178,403,148,373,118,343,88,313,58,283,28,253,478,223,224,449,194,419,164,389,134,359,104,329,74, 299,44,269,14,239,464,209,434,179,404,149,374,119,344,89,314,59,284,29,254,479 -}; +}; // Q0 -const int16_t Ip_fft128[10] = { 64, 1, 0, 128, 64, 192, 32, 160, 96, 224 }; +const Word16 Ip_fft128[10] = { 64, 1, 0, 128, 64, 192, 32, 160, 96, 224 }; // Q0 const float w_fft128[64] = { @@ -31761,9 +31766,9 @@ const Word32 w_fft128_16fx[64] = 1041563136, 260897968, 552013632, 920979072, 862437504, 639627264, 157550640, 1062120192, 1062120192, 157550640, 639627264, 862437504, 920979072, 552013632, 260897968, 1041563136, 1010975232, 361732736, 459083776, 970651136, 795590208, 721080960, 52686008, 1072448448, -}; +}; // Q30 -const int16_t Ip_fft256[10] = {128, 1, 0, 256, 128, 384, 64, 320,192, 448}; +const Word16 Ip_fft256[10] = {128, 1, 0, 256, 128, 384, 64, 320,192, 448}; // Q0 const float w_fft256[128] = { @@ -31785,7 +31790,7 @@ const float w_fft256[128] = 0.93299280f, 0.35989504f, 0.40524131f, 0.91420976f, 0.72424708f, 0.68954054f, 0.02454123f, 0.99969882f }; -const int16_t Ip_fft512[18] = {256, 1, 0, 512, 256, 768, 128, 640,384, 896, 64, 576, 320, 832, 192, 704,448, 960}; +const Word16 Ip_fft512[18] = {256, 1, 0, 512, 256, 768, 128, 640,384, 896, 64, 576, 320, 832, 192, 704,448, 960}; // Q0 const float w_fft512[256] = { @@ -31822,7 +31827,7 @@ const float w_fft512[256] = 0.98310549f, 0.18303989f, 0.56573181f, 0.82458930f, 0.83822471f, 0.54532499f, 0.20711138f, 0.97831737f, 0.92850608f, 0.37131719f, 0.39399204f, 0.91911385f, 0.71573083f, 0.69837625f, 0.01227154f, 0.99992470f }; -const Word16 w_fft512_fx_evs[256] = +const Word16 w_fft512_fx_evs[256] =//Q14 { 16384, 0, 11585, 11585, 15137, 6270, 6270, 15137, 16069, 3196, 9102, 13623, 13623, 9102, 3196, 16069, @@ -31857,18 +31862,18 @@ const Word16 w_fft512_fx_evs[256] = 16107, 2999, 9269, 13510, 13733, 8935, 3393, 16029, 15213, 6084, 6455, 15059, 11727, 11442, 201, 16383 }; -const int16_t Idx_dortft40[40] = +const Word16 Idx_dortft40[40] = { 0, 25, 10, 35, 20, 5, 30, 15, 16, 1, 26, 11, 36, 21, 6, 31, 32, 17, 2, 27, 12, 37, 22, 7, 8, 33, 18, 3, 28, 13, 38, 23, 24, 9, 34, 19, 4, 29, 14, 39 -}; +}; // Q0 -const int16_t Odx_fft8_5[8] = {0, 3, 6, 1, 4, 7, 2, 5}; -const int16_t Idx_dortft20[20] = {0, 5, 10, 15, 16, 1, 6, 11, 12, 17, 2, 7, 8, 13, 18, 3, 4, 9, 14, 19}; -const int16_t Odx_fft4_5[4] = {0, 3, 2, 1}; +const Word16 Odx_fft8_5[8] = {0, 3, 6, 1, 4, 7, 2, 5}; // Q0 +const Word16 Idx_dortft20[20] = {0, 5, 10, 15, 16, 1, 6, 11, 12, 17, 2, 7, 8, 13, 18, 3, 4, 9, 14, 19}; // Q0 +const Word16 Odx_fft4_5[4] = {0, 3, 2, 1}; // Q0 const float w_fft4[2] = {1.0000000f, 0.00000000f}; -const int16_t Ip_fft4[6] = {2,1,0,4,2,6}; -const int16_t ip_edct2_64[6] = {16, 64, 0, 32, 16, 48}; +const Word16 Ip_fft4[6] = {2,1,0,4,2,6}; // Q0 +const Word16 ip_edct2_64[6] = {16, 64, 0, 32, 16, 48}; // Q0 const float w_edct2_64[80] = { @@ -32624,16 +32629,16 @@ const Word16 hvq_class_c_fx[16] = /* Q15 */ 6914, 2136, -14387, -7617 }; -const int16_t hvq_cb_search_overlap24k[17] = +const Word16 hvq_cb_search_overlap24k[17] = { 0, 8, 17, 27, 39, 53, 69, 89, 113, 128, 128, 128, 128, 128, 128, 128, 128 -}; +}; // Q0 -const int16_t hvq_cb_search_overlap32k[21] = +const Word16 hvq_cb_search_overlap32k[21] = { 0, 6, 13, 21, 30, 40, 51, 64, @@ -32641,7 +32646,7 @@ const int16_t hvq_cb_search_overlap32k[21] = 128, 128, 128, 128, 128, 128, 128, 128, 128 -}; +}; // Q0 const float hvq_peak_cb[1024] = { @@ -33009,43 +33014,43 @@ const Word16 hvq_peak_cb_fx[1024] = /* Q15 */ 6066, 4720, 25084,-28951 }; -const int16_t hvq_pg_huff_offset[NUM_PG_HUFFLEN] = {0,2,3,8,9,11,13,15,19}; -const int16_t hvq_pg_huff_thres[NUM_PG_HUFFLEN] = {0,0x2,0x4,0x18,0x20,0x40,0x80,0x100,0x300}; +const Word16 hvq_pg_huff_offset[NUM_PG_HUFFLEN] = {0,2,3,8,9,11,13,15,19}; // Q0 +const Word16 hvq_pg_huff_thres[NUM_PG_HUFFLEN] = {0,0x2,0x4,0x18,0x20,0x40,0x80,0x100,0x300}; // Q0 -const int16_t hvq_pg_huff_tab[32] = +const Word16 hvq_pg_huff_tab[32] = { 30, 31, 1, 0, 2, 3, 28, 29, 4, 5, 27, 25, 26, 6, 24, 7, 8, 22, 23, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21 -}; +}; // Q0 -const int16_t hvq_cp_huff_len[52] = +const Word16 hvq_cp_huff_len[52] = { 3, 4, 5, 6, 6, 6, 6, 6, 4, 4, 5, 5, 5, 5, 4, 4, 4, 5, 5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 8, 8, 8, 8, 8, 9, 10, 10, 11, 11, 11, 10, 10, 10, 10, 11, 12, 12, 13, 13, 12, 12, 11, 12 -}; +}; // Q0 -const int16_t hvq_cp_huff_val[52] = +const Word16 hvq_cp_huff_val[52] = { 7, 8, 6, 3, 4, 5, 6, 7, 9, 10, 7, 8, 9, 10, 11, 12, 13, 11, 12, 13, 14, 15, 8, 9, 10, 11, 4, 5, 3, 4, 5, 6, 7, 5, 4, 5, 3, 4, 5, 6, 7, 8, 9, 6, 1, 2, 0, 1, 3, 4, 7, 5 -}; +}; // Q0 -const int16_t hvq_cp_layer1_map5[HVQ_CP_MAP_LEN] = { 16, 8, 4, 2, 1, 18, 17, 9 }; +const Word16 hvq_cp_layer1_map5[HVQ_CP_MAP_LEN] = { 16, 8, 4, 2, 1, 18, 17, 9 }; // Q0 -const int16_t hvq_cp_huff_thres[HVQ_CP_HUFF_NUM_LEN] = { 0x0, 0x2, 0xC, 0x20, 0x50, 0x60, 0x100, 0x180, 0x600, 0x1000, 0x1C00 }; -const int16_t hvq_cp_huff_offset[HVQ_CP_HUFF_NUM_LEN] = { 0, 2, 7, 12, 18, 19, 24, 26, 35, 45, 51 }; +const Word16 hvq_cp_huff_thres[HVQ_CP_HUFF_NUM_LEN] = { 0x0, 0x2, 0xC, 0x20, 0x50, 0x60, 0x100, 0x180, 0x600, 0x1000, 0x1C00 }; // Q0 +const Word16 hvq_cp_huff_offset[HVQ_CP_HUFF_NUM_LEN] = { 0, 2, 7, 12, 18, 19, 24, 26, 35, 45, 51 }; // Q0 -const int16_t hvq_cp_huff_tab[52] = +const Word16 hvq_cp_huff_tab[52] = { 46, 47, 44, 45, 48, 49, 51, 36, 37, 38, 43, 50, 34, 35, 39, 40, 41, 42, 33, 28, 29, 30, 31, 32, 26, 27, 3, 4, 5, 6, 7, 22, 23, 24, 25, 2, 10, 11, 12, 13, 17, 18, 19, 20, 21, 1, 8, 9, 14, 15, 16, 0 -}; +}; // Q0 /*----------------------------------------------------------------------------------* * FEC for HQ core *----------------------------------------------------------------------------------*/ -const int16_t Num_bands_NB[MAX_SB_NB] = {8,8,2}; +const Word16 Num_bands_NB[MAX_SB_NB] = {8,8,2}; // Q0 const float SmoothingWin_NB875[70] = { @@ -33074,7 +33079,7 @@ const float SmoothingWin_NB2[16] = 0.69134172f,0.77778512f,0.85355339f,0.91573481f,0.96193977f,0.99039264f }; const Word16 SmoothingWin_NB2_fx[16] = -{ +{/* Q15 */ 0, 315, 1247, 2761, 4799, 7282, 10114, 13188, 16384, 19580, 22654, 25486, 27969, 30007, 31521, 32453 }; /*----------------------------------------------------------------------------------* @@ -33979,11 +33984,11 @@ const float erb_NB[NUM_ERB_NB+1] = {0.0f, 92.8061f, 185.6121f, 278.4182f, 371.22 }; /* ERB table for PPP-ampl-quant */ -const Word16 erb_WB_fx[NUM_ERB_WB + 1] = { 0, 238, 475, 713, 950, 1188, 1426, 1663, 1911, 2185, 2490, 2826, 3205, 3624, 4094, 4620, 5210, 5875, 6626, 7478, 8448, 9558, 11264, 13568, 16387 }; +const Word16 erb_WB_fx[NUM_ERB_WB + 1] = { 0, 238, 475, 713, 950, 1188, 1426, 1663, 1911, 2185, 2490, 2826, 3205, 3624, 4094, 4620, 5210, 5875, 6626, 7478, 8448, 9558, 11264, 13568, 16387 };//Q(log2(2.56) /* ERB table for PPP-ampl-quant */ -const Word16 erb_NB_fx[NUM_ERB_NB + 1] = { 0, 238, 475, 713, 950, 1188, 1426, 1663, 1911, 2185, 2490, 2826, 3205, 3624, 4094, 4620, 5210, 5875, 6626, 7478, 8448, 9558, 10243 }; +const Word16 erb_NB_fx[NUM_ERB_NB + 1] = { 0, 238, 475, 713, 950, 1188, 1426, 1663, 1911, 2185, 2490, 2826, 3205, 3624, 4094, 4620, 5210, 5875, 6626, 7478, 8448, 9558, 10243 };//Q(log2(2.56) @@ -34059,7 +34064,7 @@ const float AmpCB1_WB[64][10] = }; const Word16 AmpCB1_WB_fx[640] = -{ +{//Q13 5655, 1589, -653, 3568, -3173, -1852, -3204, -4623, -2100, -5103, -923, -67, -7152, -4958, -2019, -1810, -8532, -648, 6581, 8043, 160, 778, -1535, 863, 5482, 1674, -3576, 123, -3163, -3595, @@ -34195,7 +34200,7 @@ const float AmpCB2_WB[64][NUM_ERB_WB-11] = }; const Word16 AmpCB2_WB_fx[64 * (NUM_ERB_WB - 13)] = -{ +{//Q13 -5276, -7711, -3518, -2416, -382, 319, -1900, -900, 1725, 884, 4071, -4052, -2430, -336, 2136, 3006, 591, -3893, -2731, 2625, 2390, -1047, -883, -3368, -4235, -3726, 189, -1803, 784, 2336, @@ -34338,7 +34343,7 @@ const float AmpCB1_NB[64][10] = }; const Word16 AmpCB1_NB_fx[640] = -{ +{//Q13 -1355, 185, -222, -221, 1976, 3119, 540, 1333, -3646, -2511, -979, 1664, 2087, 951, 787, -1687, -855, 1594, 1264, -4990, -1957, -215, -850, 1369, -113, 2541, -2904, 743, 634, -657, @@ -34474,7 +34479,7 @@ const float AmpCB2_NB[64][NUM_ERB_NB-11] = }; const Word16 AmpCB2_NB_fx[64 * (NUM_ERB_NB - 13)] = -{ +{//Q13 -2681, -4389, -4270, -4727, -239, 1938, 1748, 2311, 4300, -3957, -1299, 3487, 1595, -377, 295, -1193, -1588, 2112, -1573, -6362, -504, 1796, -2521, -68, 1322, 1223, 2263, -503, -3906, 3686, @@ -35097,7 +35102,7 @@ const float hp12800_16000[21] = -0.01235466f, 0.01161181f, -0.00632535f, 0.00212227f, -0.00000000f }; const Word16 hp12800_16000_fx[21] = -{ +{//Q15 -0, 70, -207, 380, -405, 0, 1041, -2668, 4505, -5968, 6526, -5968, 4505, -2668, 1041, 0, -405, 380, -207, 70, -0 @@ -35113,7 +35118,7 @@ const float hp12800_32000[41] = -0.00000000f }; const Word16 hp12800_32000_fx[41] = -{ +{//Q15 -0, 45, 35, -47, -104, 0, 191, 156, -203, -422, -0, 675, 523, -656, -1341, 0, 2264, 1943, -2999, -9872, 19678, -9872, -2999, 1943, @@ -35133,7 +35138,7 @@ const float hp12800_48000[61] = -0.00413694f, 0.00122967f, 0.00427438f, 0.00388820f, 0.00136699f, -0.00111583f, -0.00211804f, -0.00156225f, -0.00030497f, 0.00071064f, 0.00101850f, 0.00067336f, -0.00000000f }; -const Word16 hp12800_48000_fx[61] = +const Word16 hp12800_48000_fx[61] =//Q15 { -0, 22, 33, 23, -10, -51, -69, -37, 45, 127, 140, 40, -136, -271, -238, 0, 326, 507, 349, -143, @@ -35151,7 +35156,7 @@ const float hp16000_32000[33] = -0.00000000f, -0.01594711f, -0.00000000f, 0.00824247f, -0.00000000f, -0.00386248f, -0.00000000f, 0.00188788f, -0.00000000f }; -const Word16 hp16000_32000_fx[33] = +const Word16 hp16000_32000_fx[33] =//Q15 { -0, 62, -0, -127, -0, 270, -0, -523, -0, 940, -0, -1662, -0, 3212, -0, -10353, 16407, -10353, -0, 3212, @@ -35169,7 +35174,7 @@ const float hp16000_48000[49] = 0.00534416f, 0.00421805f, -0.00000000f, -0.00254135f, -0.00195325f, -0.00000000f, 0.00119953f, 0.00100660f, -0.00000000f }; -const Word16 hp16000_48000_fx[49] = +const Word16 hp16000_48000_fx[49] =//Q15 { -0, 33, 39, -0, -64, -83, -0, 138, 175, 0, -272, -334, -0, 493, 596, 0, -870, -1059, -0, 1636, @@ -35223,7 +35228,7 @@ const double cu4[6][3] = /* 5:*/ { 0.5833333333, 1.0208333333, 1.7864583333 } /*1.75*/ }; -const int16_t ct2[7][13] = +const Word16 ct2[7][13] = { /* accepted configurations */ /*input 12.8, output :*/ @@ -35236,7 +35241,7 @@ const int16_t ct2[7][13] = /*12*/ { 9, 3, 4, 5, 9, 0, 0, 0, 5, 0, 5, 5, 4}, /*32*/ { 4, 4, 4, 4, 4, 0, 0, 0, 2, 1, 1, 4, 4}, /*48*/ {18, 18, 18, 18, 18, 0, 0, 0, 5, 2, 1, 4, 15}, -}; +}; // Q0 const Word16 ct2_fx[7][14] = { /* accepted configurations */ @@ -35303,7 +35308,7 @@ const Word16 cu4_fx[6][3] = /*Q13*/ *----------------------------------------------------------------------------------*/ const float h_high[5] = { -0.0125f, -0.1090f, 0.7813f, -0.1090f, -0.0125f }; -const Word16 h_high_fx[5] = { -410, -3572, 25602, -3572, -410 }; +const Word16 h_high_fx[5] = { -410, -3572, 25602, -3572, -410 };//Q15 const float sincos_t_rad3[T_SIN_PI_2+1] = { @@ -35358,7 +35363,7 @@ const float sincos_t_rad3[T_SIN_PI_2+1] = 1.000000000000000f }; const Word16 sincos_t_rad3_fx[T_SIN_PI_2 + 1] = -{ +{//Q15 0, 134, 268, 402, 536, 670, 804, 938, 1072, 1206, 1340, 1474, 1608, 1742, 1876, 2009, 2143, 2277, 2411, 2544, 2678, 2811, 2945, 3078, @@ -35545,7 +35550,7 @@ const float inter_core_25_6kHz_output_48kHz_flt[] = 0.0000000f }; -const TCX_LTP_FILTER_FLT tcxLtpFilters_flt[12] = +const TCX_LTP_FILTER_FLT tcxLtpFilters_flt[12] =//Q15 { { inter_core_12_8kHz_output_8kHz_flt, 2 }, { inter_core_12_8kHz_output_16kHz_flt, 3 }, @@ -35693,7 +35698,7 @@ const SCALE_TCX_SETUP scaleTcxTable[SIZE_SCALE_TABLE_TCX] = * Arithmetic coder *----------------------------------------------------------------------------------*/ -const uint8_t ari_lookup_s17_LC[4096] = +const UWord8 ari_lookup_s17_LC[4096] = // Q0 { 0x01,0x04,0x29,0x13,0x0A,0x0D,0x05,0x10, 0x10,0x0D,0x00,0x0D,0x2A,0x2A,0x22,0x25, @@ -36209,7 +36214,7 @@ const uint8_t ari_lookup_s17_LC[4096] = 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A }; -const uint16_t ari_pk_s17_LC_ext[64][18] = +const UWord16 ari_pk_s17_LC_ext[64][18] = // Q0 { { 16384, 16368,16337,16231,16143,16115,16059,15916,15793,15710,15586,15472,15367,15302,15201,15107,15020, @@ -36469,7 +36474,7 @@ const uint16_t ari_pk_s17_LC_ext[64][18] = } }; -const int16_t NumRatioBits[2][17] = +const Word16 NumRatioBits[2][17] = { /* NB */ { @@ -36480,7 +36485,7 @@ const int16_t NumRatioBits[2][17] = { 5, 5, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4, 2, 2, 2 } -}; +}; // Q0 const float Ratios_WB_2[32] = /* 2 */ { 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 60, 64, 72 }; @@ -36632,37 +36637,37 @@ const float * const Ratios[2][17] = /* 7Q8 */ const Word16 Ratios_WB_2_fx[32] = /* 2 */{ 768, 1024, 1280, 1536, 1792, 2048, 2304, 2560, 2816, 3072, 3328, 3584, 3840, 4096, 4352, 4608, 4864, 5120, 5376, 5632, 6144, 6656, 7168, 7680, 8192, 8704, 9216, 9728, 10240, 15360, 16384, 18432 }; -const Word16 Ratios_WB_3_fx[32] = +const Word16 Ratios_WB_3_fx[32] =/* 7Q8 */ /* 3 */{ 256, 512, 768, 1024, 1280, 1536, 1792, 2048, 2304, 2560, 3072, 3584, 4096, 4608, 5120, 5632, 6144, 6656, 7168, 7680, 8192, 8704, 9216, 9728, 10240, 11264, 12288, 13824, 15360, 17408, 19968, 20480 }; -const Word16 Ratios_WB_4_fx[32] = +const Word16 Ratios_WB_4_fx[32] =/* 7Q8 */ /* 4 */{ 384, 512, 640, 768, 1024, 1280, 1536, 1792, 2048, 2304, 2560, 3072, 3584, 4096, 4608, 5120, 5632, 6144, 6656, 7168, 7680, 8192, 8704, 9216, 9728, 10240, 10752, 11264, 12288, 13312, 13824, 17408 }; -const Word16 Ratios_WB_5_fx[32] = +const Word16 Ratios_WB_5_fx[32] =/* 7Q8 */ /* 5 */{ 256, 384, 512, 640, 768, 1024, 1280, 1536, 1792, 2048, 2304, 2560, 2816, 3072, 3328, 3584, 3840, 4096, 4608, 5120, 5632, 6144, 6656, 7168, 7680, 8192, 8704, 9216, 10240, 11264, 12288, 13824 }; -const Word16 Ratios_WB_6_fx[32] = +const Word16 Ratios_WB_6_fx[32] =/* 7Q8 */ /* 6 */{ 256, 384, 512, 640, 768, 896, 1024, 1152, 1280, 1408, 1536, 1664, 1792, 1920, 2048, 2304, 2560, 2816, 3072, 3328, 3584, 3840, 4096, 4608, 5120, 5632, 6144, 6656, 7168, 8704, 10240, 10496 }; -const Word16 Ratios_WB_7_fx[32] = +const Word16 Ratios_WB_7_fx[32] =/* 7Q8 */ /* 7 */{ 256, 384, 512, 640, 768, 896, 1024, 1152, 1280, 1536, 1792, 2048, 2304, 2560, 2816, 3072, 3328, 3584, 3840, 4096, 4352, 4608, 4864, 5120, 5376, 5760, 6144, 6400, 6912, 7168, 7680, 8960 }; -const Word16 Ratios_WB_8_fx[16] = +const Word16 Ratios_WB_8_fx[16] =/* 7Q8 */ /* 8 */{ 128, 256, 384, 512, 640, 768, 896, 1024, 1152, 1280, 1408, 1536, 1792, 2048, 2304, 2560 }; -const Word16 Ratios_WB_9_fx[16] = +const Word16 Ratios_WB_9_fx[16] =/* 7Q8 */ /* 9 */{ 256, 512, 640, 768, 1024, 1280, 1536, 1792, 2048, 2304, 2560, 3072, 3840, 4096, 4608, 6912 }; -const Word16 Ratios_WB_10_fx[16] = +const Word16 Ratios_WB_10_fx[16] =/* 7Q8 */ /* 10 */{ 256, 384, 512, 640, 768, 896, 1024, 1280, 1536, 2048, 2560, 3840, 4608, 5632, 6144, 6656 }; -const Word16 Ratios_WB_11_fx[16] = +const Word16 Ratios_WB_11_fx[16] =/* 7Q8 */ /* 11 */{ 256, 384, 512, 640, 768, 896, 1024, 1280, 1536, 2048, 2560, 3072, 3328, 3584, 4608, 5376 }; -const Word16 Ratios_WB_12_fx[16] = +const Word16 Ratios_WB_12_fx[16] =/* 7Q8 */ /* 12 */{ 128, 256, 384, 512, 640, 768, 1024, 1280, 1536, 2048, 2304, 2816, 3072, 3456, 4096, 5120 }; -const Word16 Ratios_WB_13_fx[16] = +const Word16 Ratios_WB_13_fx[16] =/* 7Q8 */ /* 13 */{ 128, 256, 384, 512, 640, 768, 1024, 1280, 1536, 1792, 2048, 2560, 2816, 3072, 3584, 5120 }; -const Word16 Ratios_WB_14_fx[16] = +const Word16 Ratios_WB_14_fx[16] =/* 7Q8 */ /* 14 */{ 128, 256, 384, 512, 640, 768, 1024, 1152, 1536, 1920, 2304, 2560, 3072, 3584, 3840, 4608 }; -const Word16 Ratios_WB_15_fx[16] = +const Word16 Ratios_WB_15_fx[16] =/* 7Q8 */ /* 15 */{ 128, 256, 320, 384, 448, 512, 640, 768, 896, 1024, 1152, 1280, 1536, 2048, 2304, 3584 }; -const Word16 Ratios_WB_16_fx[4] = +const Word16 Ratios_WB_16_fx[4] =/* 7Q8 */ /* 16 */{ 128, 256, 512, 1024 }; -const Word16 Ratios_WB_17_fx[4] = +const Word16 Ratios_WB_17_fx[4] =/* 7Q8 */ /* 17 */{ 256, 384, 512, 1024 }; -const Word16 Ratios_WB_18_fx[4] = +const Word16 Ratios_WB_18_fx[4] =/* 7Q8 */ /* 18 */{ 256, 512, 768, 1024 }; /******************************************************************************/ @@ -36670,42 +36675,42 @@ const Word16 Ratios_WB_18_fx[4] = /* 7Q8 */ const Word16 Ratios_NB_2_fx[32] = /* 2 */{ 768, 1024, 1280, 1536, 1792, 2048, 2304, 2560, 2816, 3072, 3328, 3584, 3840, 4096, 4352, 4608, 4864, 5120, 5376, 5632, 5888, 6144, 6400, 6656, 6912, 7168, 7680, 8192, 8704, 9216, 9728, 10240 }; -const Word16 Ratios_NB_3_fx[16] = +const Word16 Ratios_NB_3_fx[16] =/* 7Q8 */ /* 3 */{ 128, 256, 512, 768, 1024, 1280, 1536, 1792, 2048, 2304, 2560, 3072, 4096, 5120, 6144, 7680 }; -const Word16 Ratios_NB_4_fx[16] = +const Word16 Ratios_NB_4_fx[16] =/* 7Q8 */ /* 4 */{ 512, 768, 1024, 1280, 1536, 1792, 2048, 2304, 2560, 3072, 3584, 4096, 4608, 5120, 6144, 7680 }; -const Word16 Ratios_NB_5_fx[16] = +const Word16 Ratios_NB_5_fx[16] =/* 7Q8 */ /* 5 */{ 512, 768, 1024, 1280, 1536, 1792, 2048, 2304, 2560, 3072, 3584, 4096, 4608, 5120, 6144, 7680 }; -const Word16 Ratios_NB_6_fx[16] = +const Word16 Ratios_NB_6_fx[16] =/* 7Q8 */ /* 6 */{ 512, 640, 768, 896, 1024, 1280, 1536, 1792, 2048, 2304, 2560, 3072, 3584, 4096, 4608, 5120 }; -const Word16 Ratios_NB_7_fx[16] = +const Word16 Ratios_NB_7_fx[16] =/* 7Q8 */ /* 7 */{ 256, 512, 640, 768, 1024, 1280, 1536, 1792, 2048, 2304, 2560, 3072, 3584, 4096, 4608, 5120 }; -const Word16 Ratios_NB_8_fx[16] = +const Word16 Ratios_NB_8_fx[16] =/* 7Q8 */ /* 8 */{ 256, 384, 512, 640, 768, 896, 1024, 1152, 1280, 1536, 1792, 2048, 2304, 2560, 3072, 4096 }; -const Word16 Ratios_NB_9_fx[8] = +const Word16 Ratios_NB_9_fx[8] =/* 7Q8 */ /* 9 */{ 256, 512, 768, 1024, 1280, 1536, 2048, 2560 }; -const Word16 Ratios_NB_10_fx[8] = +const Word16 Ratios_NB_10_fx[8] =/* 7Q8 */ /* 10 */{ 256, 512, 768, 1024, 1280, 1536, 2048, 2560 }; -const Word16 Ratios_NB_11_fx[8] = +const Word16 Ratios_NB_11_fx[8] =/* 7Q8 */ /* 11 */{ 256, 384, 512, 768, 1024, 1280, 1536, 2048 }; -const Word16 Ratios_NB_12_fx[8] = +const Word16 Ratios_NB_12_fx[8] =/* 7Q8 */ /* 12 */{ 256, 512, 640, 768, 1024, 1280, 1536, 2048 }; -const Word16 Ratios_NB_13_fx[4] = +const Word16 Ratios_NB_13_fx[4] =/* 7Q8 */ /* 13 */{ 256, 512, 768, 1024 }; -const Word16 Ratios_NB_14_fx[4] = +const Word16 Ratios_NB_14_fx[4] =/* 7Q8 */ /* 14 */{ 256, 512, 1024, 1536 }; -const Word16 Ratios_NB_15_fx[4] = +const Word16 Ratios_NB_15_fx[4] =/* 7Q8 */ /* 15 */{ 256, 512, 768, 1024 }; -const Word16 Ratios_NB_16_fx[4] = +const Word16 Ratios_NB_16_fx[4] =/* 7Q8 */ /* 16 */{ 256, 384, 512, 1024 }; -const Word16 Ratios_NB_17_fx[4] = +const Word16 Ratios_NB_17_fx[4] =/* 7Q8 */ /* 17 */{ 256, 384, 512, 768 }; -const Word16 Ratios_NB_18_fx[4] = +const Word16 Ratios_NB_18_fx[4] =/* 7Q8 */ /* 18 */{ 128, 256, 512, 768 }; /******************************************************************************/ -const Word16 *const Ratios_fx[2][17] = +const Word16 *const Ratios_fx[2][17] =/* 7Q8 */ { /* NB */ { @@ -37184,7 +37189,7 @@ const Coding * const codesTnsCoeffSWBTCX20[] = { codesTnsCoeff0TCX20, codesTnsCo const Coding * const codesTnsCoeffSWBTCX10[] = { codesTnsCoeff0TCX10, codesTnsCoeff1TCX10, codesTnsCoeff2TCX10, codesTnsCoeff3TCX10, codesTnsCoeff4TCX10, codesTnsCoeff5, codesTnsCoeff6, codesTnsCoeff7 }; const Coding * const codesTnsCoeffWBTCX20[] = { codesTnsCoeff0WBTCX20, codesTnsCoeff1WBTCX20, codesTnsCoeff2WB, codesTnsCoeff3WB, codesTnsCoeff456, codesTnsCoeff456, codesTnsCoeff456, codesTnsCoeff7 }; -const int16_t nTnsCoeffTables = sizeof(codesTnsCoeffSWBTCX20)/sizeof(codesTnsCoeffSWBTCX20[0]); +const Word16 nTnsCoeffTables = sizeof(codesTnsCoeffSWBTCX20)/sizeof(codesTnsCoeffSWBTCX20[0]); // Q0 const Coding codesTnsOrderTCX20[] = { @@ -37220,7 +37225,7 @@ const Coding codesTnsOrder[] = { 8, 0, 1 } /* 0 */ }; -const int16_t nTnsOrderCodes = sizeof(codesTnsOrder)/sizeof(codesTnsOrder[0]); +const Word16 nTnsOrderCodes = sizeof(codesTnsOrder)/sizeof(codesTnsOrder[0]); // Q0 const ParamsBitMap tnsSWBTCX20FilterCoeffBitMap = { @@ -37400,7 +37405,7 @@ const Word16 tnsCoeff4[16] = * IGF settings for each bitrate *----------------------------------------------------------------------------------*/ -const Word16 swb_offset_LB_new[IGF_BITRATE_UNKNOWN][IGF_MAX_SFB] = +const Word16 swb_offset_LB_new[IGF_BITRATE_UNKNOWN][IGF_MAX_SFB] = // Q0 { /* 0: for 9600 kbs WB */ { @@ -37548,7 +37553,7 @@ const Word16 swb_offset_LB_new[IGF_BITRATE_UNKNOWN][IGF_MAX_SFB] = } };/*Q0*/ -const int16_t igf_tile_offset_table[IGF_BITRATE_UNKNOWN][2*IGF_MAX_TILES+1] = { +const Word16 igf_tile_offset_table[IGF_BITRATE_UNKNOWN][2*IGF_MAX_TILES+1] = { // Q0 { 2, 2, 0, 3, 0}, /* 9600 WB*/ { 2, 2, 0, 3, 0}, /* 13200 WB RF */ { 3, 1, 0, 2, 32, 3, 46}, /* 9600 SWB */ @@ -38045,7 +38050,7 @@ const Word16 igf_whitening_TH[][2][IGF_MAX_TILES] = /* IGF SCF arithmetic coder cumulative frequency tables and offsets */ -const int16_t cf_off_se01_tab[10] = { +const Word16 cf_off_se01_tab[10] = { // Q0 +1, /* 9.6 kbs B*/ +1, /* 13.2 kbs WB RF B*/ +1, /* 9.6 kbs SWB B*/ @@ -38058,7 +38063,7 @@ const int16_t cf_off_se01_tab[10] = { -1 /* 64.0 kbs B*/ }; -const int16_t cf_off_se02_tab[10][IGF_CTX_COUNT] = { +const Word16 cf_off_se02_tab[10][IGF_CTX_COUNT] = { // Q0 { +1, +2, +2, +2, +3, +3, +4}, /* 9.6 kbs B*/ { +1, +2, +2, +2, +3, +3, +4}, /* 13.2 kbs WB RF B*/ { +0, +2, +3, +3, +2, +2, +4}, /* 9.6 kbs SWB B*/ @@ -38071,9 +38076,9 @@ const int16_t cf_off_se02_tab[10][IGF_CTX_COUNT] = { { +3, +2, +3, +2, +3, +3, +6} /* 64.0 kbs B*/ }; -const int16_t cf_off_se10_tab = -7; +const Word16 cf_off_se10_tab = -7; // Q0 -const int16_t cf_off_se11_tab[IGF_CTX_COUNT][IGF_CTX_COUNT] = +const Word16 cf_off_se11_tab[IGF_CTX_COUNT][IGF_CTX_COUNT] = // Q0 { { -5, +0, +0, +0, +0, +0, +0}, { +0, +0, +0, +0, +0, +0, +0}, @@ -38084,12 +38089,12 @@ const int16_t cf_off_se11_tab[IGF_CTX_COUNT][IGF_CTX_COUNT] = { +0, +1, +0, +0, +3, +0, +3} }; -const uint16_t cf_se00_tab[IGF_SYMBOLS_IN_TABLE + 1] = +const UWord16 cf_se00_tab[IGF_SYMBOLS_IN_TABLE + 1] = // Q0 { 16384, 16356, 16299, 16185, 15904, 15282, 14669, 13598, 11886, 9541, 6613, 3845, 1799, 606, 153, 32, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 }; -const uint16_t cf_se01_tab[10][IGF_SYMBOLS_IN_TABLE + 1] = +const UWord16 cf_se01_tab[10][IGF_SYMBOLS_IN_TABLE + 1] = // Q0 { {16384, 16320, 16285, 16237, 16163, 16049, 15864, 15604, 15187, 14557, 13612, 12308, 10590, 8535, 6346, 4396, 2900, 1917, 1289, 870, 593, 408, 279, 181, 122, 78, 52, 0}, /* 9.6 kbs B*/ {16384, 16320, 16285, 16237, 16163, 16049, 15864, 15604, 15187, 14557, 13612, 12308, 10590, 8535, 6346, 4396, 2900, 1917, 1289, 870, 593, 408, 279, 181, 122, 78, 52, 0}, /* 13.2 kbs WB RF B*/ @@ -38103,7 +38108,7 @@ const uint16_t cf_se01_tab[10][IGF_SYMBOLS_IN_TABLE + 1] = {16384, 16368, 16355, 16334, 16291, 16212, 16071, 15816, 15359, 14523, 13014, 10534, 7345, 4272, 2228, 1149, 626, 357, 215, 139, 93, 67, 53, 43, 36, 28, 22, 0} /* 64.0 kbs B*/ }; -const uint16_t cf_se02_tab[10][IGF_CTX_COUNT][IGF_SYMBOLS_IN_TABLE + 1] = +const UWord16 cf_se02_tab[10][IGF_CTX_COUNT][IGF_SYMBOLS_IN_TABLE + 1] = // Q0 { { /* 9.6 kbs B */ { 16384, 16369, 16348, 16316, 16256, 16172, 16017, 15735, 15246, 14363, 13036, 11139, 8916, 6724, 4757, 3282, 2221, 1549, 1105, 771, 548, 364, 238, 151, 89, 50, 30, 0}, @@ -38199,12 +38204,12 @@ const uint16_t cf_se02_tab[10][IGF_CTX_COUNT][IGF_SYMBOLS_IN_TABLE + 1] = /* only needed for >= 48 kbps */ -const uint16_t cf_se10_tab[IGF_SYMBOLS_IN_TABLE + 1] = +const UWord16 cf_se10_tab[IGF_SYMBOLS_IN_TABLE + 1] = // Q0 { 16384, 15493, 15154, 14810, 14331, 13701, 13086, 12403, 11585, 10923, 10293, 9631, 8943, 8385, 7760, 7182, 6593, 6009, 5540, 5082, 4571, 4133, 3711, 3299, 2887, 2460, 2043, 0 }; -const uint16_t cf_se11_tab[IGF_CTX_COUNT][IGF_CTX_COUNT][IGF_SYMBOLS_IN_TABLE + 1] = +const UWord16 cf_se11_tab[IGF_CTX_COUNT][IGF_CTX_COUNT][IGF_SYMBOLS_IN_TABLE + 1] = // Q0 { { { 16384, 16313, 16312, 16241, 16206, 16099, 15957, 15386, 14601, 12852, 10282, 7534, 4964, 2966, 1824, 896, 504, 255, 113, 112, 41, 40, 39, 38, 37, 36, 1, 0}, @@ -38329,7 +38334,7 @@ const float * const w_a_float[7] = {w1N8_float, w2N8_float, w3N8_float, w4N8_flo #define STCP( a, b ) {{ WORD322WORD16( a ), WORD322WORD16( b ) }} -const PWord16 SineTable512_fx[] = +const PWord16 SineTable512_fx[] =//Q15 { STCP(0x7fffffff, 0x00000000), STCP(0x7fffd886, 0x006487e3), STCP(0x7fff6216, 0x00c90f88), STCP(0x7ffe9cb2, 0x012d96b1), STCP(0x7ffd885a, 0x01921d20), STCP(0x7ffc250f, 0x01f6a297), STCP(0x7ffa72d1, 0x025b26d7), STCP(0x7ff871a2, 0x02bfa9a4), @@ -38399,7 +38404,7 @@ const PWord16 SineTable512_fx[] = }; /* Lookup-Table for binary logarithm */ -const Word16 ldCoeff[7] = +const Word16 ldCoeff[7] =//Q15 { -32768, -16384, -10923, -8192, -6554, -5461, -4681 /* -4096, -3641, -3277 */ @@ -38407,7 +38412,7 @@ const Word16 ldCoeff[7] = /* Lookup-Table for binary power algorithm */ /* This table is used for lookup 2^x with x in range [0...1.0[ in steps of 1/32 */ -const UWord32 exp2_tab_long[32] = +const UWord32 exp2_tab_long[32] =//Q31 { 0x40000000,0x4166C34C,0x42D561B4,0x444C0740, 0x45CAE0F2,0x47521CC6,0x48E1E9BA,0x4A7A77D4, @@ -38421,7 +38426,7 @@ const UWord32 exp2_tab_long[32] = /* Lookup-Table for binary power algorithm */ /* This table is used for lookup 2^x with x in range [0...1/32[ in steps of 1/1024 */ -const UWord32 exp2w_tab_long[32] = +const UWord32 exp2w_tab_long[32] =//Q31 { 0x40000000,0x400B1818,0x4016321B,0x40214E0C, 0x402C6BE9,0x40378BB4,0x4042AD6D,0x404DD113, @@ -38435,7 +38440,7 @@ const UWord32 exp2w_tab_long[32] = /* Lookup-Table for binary power algorithm */ /* This table is used for lookup 2^x with x in range [0...1/1024[ in steps of 1/32768 */ -const UWord32 exp2x_tab_long[32] = +const UWord32 exp2x_tab_long[32] =//Q31 { 0x40000000,0x400058B9,0x4000B173,0x40010A2D, 0x400162E8,0x4001BBA3,0x4002145F,0x40026D1B, @@ -38456,7 +38461,7 @@ const Word32 SqrtTable[32] = /* Q31 */ 0x77BBCF60, 0x78CC4545, 0x79DA5A00, 0x7AE61D3E, 0x7BEF9E07, 0x7CF6EAC2, 0x7DFC113F, 0x7EFF1EC0 }; -const Word16 SqrtDiffTable[32] = /* Q21 */ +const Word16 SqrtDiffTable[32] = /* Q15 */ { 0x59CF, 0x5875, 0x572B, 0x55EE, 0x54BF, 0x539C, 0x5284, 0x5177, 0x5074, 0x4F7A, 0x4E89, 0x4DA1, 0x4CC0, 0x4BE7, 0x4B15, 0x4A4A, @@ -38472,7 +38477,7 @@ const Word32 ISqrtTable[32] = /* Q31 */ 0x60C1E8C8, 0x5FE7AE45, 0x5F131EBE, 0x5E43FC76, 0x5D7A0D4F, 0x5CB51A81, 0x5BF4F061, 0x5B395E26 }; -const Word16 ISqrtDiffTable[32] = /* Q21 */ +const Word16 ISqrtDiffTable[32] = /* Q15 */ { 0x7D0C, 0x777E, 0x7256, 0x6D8A, 0x6911, 0x64E5, 0x60FD, 0x5D54, 0x59E5, 0x56AA, 0x53A0, 0x50C2, 0x4E0D, 0x4B7E, 0x4912, 0x46C6, @@ -38489,7 +38494,7 @@ const Word32 InvTable[32] = /* Q31 */ 0x4923D31D, 0x47DB5CAE, 0x469E3974, 0x456BD608, 0x4443A8D9, 0x43253159, 0x420FF746, 0x41038A01 }; -const Word16 InvDiffTable[32] = /* Q20 */ +const Word16 InvDiffTable[32] = /* Q15 */ { 0x7C14, 0x74C8, 0x6E1C, 0x67FF, 0x6260, 0x5D33, 0x586C, 0x5400, 0x4FE7, 0x4C19, 0x4890, 0x4543, 0x422F, 0x3F4F, 0x3C9D, 0x3A17, @@ -38544,7 +38549,7 @@ const float tcx_mdct_window_48[420] = 0.99936891f , 0.99949473f , 0.99960661f , 0.99970454f , 0.99978846f , 0.99985838f , 0.99991435f , 0.99995631f , 0.99998426f , 0.99999827f , }; -const Word16 tcx_mdct_window_48_fx[420] = +const Word16 tcx_mdct_window_48_fx[420] =//Q15 { 61, 183, 306, 428, 551, 673, 796, 919, 1041, 1163, 1286, 1408, 1531, 1653, 1776, 1898, 2020, 2143, 2265, 2387, 2509, 2632, 2754, 2876, 2998, 3120, 3242, 3364, 3486, 3607, 3729, @@ -38609,7 +38614,7 @@ const float tcx_mdct_window_half_48[180] = 0.99656552f , 0.99725020f , 0.99785894f , 0.99839169f , 0.99884838f , 0.99922901f , 0.99953359f , 0.99976200f , 0.99991435f , 0.99999046f , }; -const Word16 tcx_mdct_window_half_48_fx[180] = +const Word16 tcx_mdct_window_half_48_fx[180] =//Q15 { 142, 428, 714, 1000, 1286, 1572, 1857, 2143, 2428, 2713, 2998, 3282, 3567, 3851, 4135, 4418, 4701, 4984, 5267, 5549, 5830, @@ -38639,7 +38644,7 @@ const float tcx_mdct_window_trans_48[60] = 0.96923089f , 0.97534233f , 0.98078531f , 0.98555607f , 0.98965138f , 0.99306846f , 0.99580491f , 0.99785894f , 0.99922901f , 0.99991435f , }; -const Word16 tcx_mdct_window_trans_48_fx[60] = +const Word16 tcx_mdct_window_trans_48_fx[60] =//Q15 { 428, 1286, 2143, 2998, 3851, 4701, 5549, 6392, 7231, 8065, 8894, 9717, 10532, 11341, 12142, 12934, 13718, 14492, 15257, 16011, 16754, 17485, 18204, 18911, 19605, 20286, 20953, 21605, 22242, 22865, 23471, @@ -38658,7 +38663,7 @@ const float sigma_BWE[] = { 0.008809121277345f, 0.008799007638233f, 0.009070002122415f, 0.009080199707624f, 0.009739951681282f, 0.010572954192948f, 0.018255917586799f, 0.018995351636606f }; /* for 3 bits first stage */ -const Word32 sigma_BWE_fx[] = { +const Word32 sigma_BWE_fx[] = {//Q31 17011214, 16701976, 17561200, 17474996, 19251270, 20645372, 39204284, 40792208, 18917444, 18895726, 19477682, @@ -38674,7 +38679,7 @@ const float inv_sigma_BWE[] = { }; -const Word16 inv_modified_sigma_BWE_fx[] = { +const Word16 inv_modified_sigma_BWE_fx[] = {//Q1 259, 254, 267, @@ -38693,7 +38698,7 @@ const Word16 inv_modified_sigma_BWE_fx[] = { 622 }; -const Word16 modified_sigma_BWE_fx[] = +const Word16 modified_sigma_BWE_fx[] =//Q(log2(2.56) { 323, 329, 313, @@ -38715,7 +38720,7 @@ const float SHB_LSF_mean[10] = { 0.04131f, 0.08078f, 0.12348f, 0.16567f, 0.21045f, 0.25449f, 0.30101f, 0.34693f, 0.39605f, 0.44428f }; -const Word16 SHB_LSF_mean_fx[10] = { +const Word16 SHB_LSF_mean_fx[10] = {//Q15 1353, 2646, 4046, 5428, 6896, 8339, 9863, 11368, 12977, 14558 @@ -38756,7 +38761,7 @@ const float SHB_LSF_VQ3[48] = { const float *const cb_LSF_BWE[] = { SHB_LSF_VQ4, SHB_LSF_VQ3 }; -const Word16 SHB_LSF_VQ4_fx[96] = +const Word16 SHB_LSF_VQ4_fx[96] =//Q15 { 150, 51, -507, -986, -1115, -944, -184, -77, 95, 232, 440, 497, -115, -107, -109, -242, -446, -592, 387, 799, @@ -38772,7 +38777,7 @@ const Word16 SHB_LSF_VQ4_fx[96] = 234, -377, -629, -296, -95, 21, 63, -206, -456, 518, 472, 179, 22 }; /* 3 bit VQ first stage */ -const Word16 SHB_LSF_VQ3_fx[48] = +const Word16 SHB_LSF_VQ3_fx[48] =//Q15 { 278, 403, 285, 65, -206, -337, 386, 770, 838, 753, 599, 445, -196, -455, -609, -524, -206, -78, 39, 199, @@ -38780,21 +38785,21 @@ const Word16 SHB_LSF_VQ3_fx[48] = -1241, -1225, -976, -52, -98, -216, -422, -599, -688, 127, 137, 0, 52, 301, 412, -278, -422, 9, 199, 137, 72 }; -const Word16 *const cb_LSF_BWE_fx[] = { SHB_LSF_VQ4_fx, SHB_LSF_VQ3_fx }; +const Word16 *const cb_LSF_BWE_fx[] = { SHB_LSF_VQ4_fx, SHB_LSF_VQ3_fx }; // Q15 -const int16_t mslvq_SHB_min_bits[] = {14, 12}; /* for 4 bits and 3 bits respectively */ +const Word16 mslvq_SHB_min_bits[] = {14, 12}; /* for 4 bits and 3 bits respectively Q0*/ const float scales_BWE[] = { 0.932f, 1.677f, 2.811f, /* 14 bits*/ 0.891f, 1.770f, 3.002f, /* 15 bits */ 0.849f, 1.769f, 3.226f}; /* 16 bits */ -const Word16 scales_BWE_fx[] = { +const Word16 scales_BWE_fx[] = {//Q13 7634, 13737, 23027, 7299, 14499, 24592, 6955, 14491, 26427 }; -const Word16 scales_BWE_fx_new[] = { +const Word16 scales_BWE_fx_new[] = {//Q11 1908, 3434, @@ -38806,7 +38811,7 @@ const Word16 scales_BWE_fx_new[] = { 3622, 6606 }; -const Word8 no_lead_BWE[] = { +const Word8 no_lead_BWE[] = { // Q0 8, 6, 5, /* 14 bits */ 10,9,5, /* 15 bits*/ 16, 11, 5}; /* 16 bits */ @@ -38818,13 +38823,13 @@ const float scales_BWE_3b[] = { 0.885f, 1.549f, 2.815f /* 14 bits*/ }; -const Word16 scales_BWE_3b_fx[] = { +const Word16 scales_BWE_3b_fx[] = {//Q13 7847, 14262, 28934, 7610, 12771, 21544, 7249, 12689, 23060 }; -const Word16 scales_BWE_3b_fx_new[] = { +const Word16 scales_BWE_3b_fx_new[] = {//Q11 1961, 3565, 7233, @@ -38836,7 +38841,7 @@ const Word16 scales_BWE_3b_fx_new[] = { 5765 }; -const Word8 no_lead_BWE_3b[] = { +const Word8 no_lead_BWE_3b[] = { // Q0 4, 5, 2, /* 12 bits */ 5, 5, 5, /* 13 bits */ 8, 6, 5 /* 14 bits */ @@ -38847,7 +38852,7 @@ const float LastCoefPred_0bit[18] = { 0.00817f, -0.00645f, -0.00937f, -0.00726f, 0.00363f, 0.02148f, 0.08237f, 0.20400f, 0.00000f }; -const Word32 LastCoefPred_0bit_fx[18] = +const Word32 LastCoefPred_0bit_fx[18] =//Q31 { 10930692, -29356102, -14495515, -11918534, 3435973, 89292368, 269423296, @@ -38862,14 +38867,14 @@ const float LastCoefPred_1bit[36] = { -0.01554f, -0.02277f, -0.00474f, 0.00468f, 0.01070f, 0.04327f, 0.09857f, 0.26611f, -0.01164f }; -const Word32 LastCoefPred_1bit_fx[36] = { +const Word32 LastCoefPred_1bit_fx[36] = {//Q31 37795712, -47094316, 24910810, 18060338, 38268160, 87424056, 217346816, 810181184, 9685151, 53107272, -26843546, 11703786, -7301444, 20444044, 22655952, 138448272, 307648512, 9234180 }; -const int16_t config_LSF_BWE[] = { +const Word16 config_LSF_BWE[] = { // Q0 4, 16, 1, /* 21 bits */ 4, 16, 1, /* 20 */ 4, 16, 1, /* 19 */ @@ -38939,7 +38944,7 @@ const Word16 f_atan_expand_range[MAXSFTAB - (MINSFTAB - 1)] = }; -const Word16 Grid[GRID100_POINTS + 1] = +const Word16 Grid[GRID100_POINTS + 1] =//Q15 { 32767, 32751, 32703, 32622, 32509, 32364, 32187, 31978, 31738, 31466, 31164, 30830, @@ -38960,7 +38965,7 @@ const Word16 Grid[GRID100_POINTS + 1] = -32509, -32622, -32703, -32751, -32760 }; -const Word16 pwAlpha[10] = { 0x6666, 0x51ec, 0x4189, 0x346e, 0x29f1, +const Word16 pwAlpha[10] = { 0x6666, 0x51ec, 0x4189, 0x346e, 0x29f1,//Q15 0x218e, 0x1ad8, 0x157a, 0x112e, 0x0dbe }; @@ -39001,7 +39006,7 @@ const Word8 Ind_Guess[256] = 14, 13, 12, 11, 10, 8, 7, 5 }; -const Word16 cos_table_129[129] = +const Word16 cos_table_129[129] =//Q15 { 32767, 32758, 32729, 32679, 32610, 32522, 32413, 32286, 32138, @@ -39022,7 +39027,7 @@ const Word16 cos_table_129[129] = -32286, -32413, -32522, -32610, -32679, -32729, -32758, -32768 }; -const Word16 acos_slope[128] = +const Word16 acos_slope[128] =//Q15 { -26214, -9039, -5243, -3799, -2979, -2405, -2064, -1771, -1579, -1409, -1279, -1170, -1079, -1004, -933, -880, @@ -39043,9 +39048,9 @@ const Word16 acos_slope[128] = }; #define SHC(x) ((Word16)x) -const Word16 cos_coef_new[4] = { SHC(0x02BA), SHC(0xE60A), SHC(0xEEEF), SHC(0xAAAB) }; +const Word16 cos_coef_new[4] = { SHC(0x02BA), SHC(0xE60A), SHC(0xEEEF), SHC(0xAAAB) };//Q15 -const Word16 cos_table[512] = +const Word16 cos_table[512] =//Q15 { SHC(0x7fff), SHC(0x7ffe), @@ -39694,7 +39699,7 @@ const PWord16 w7N8[15] = {{ 14010/*0.427555 Q15*/, 29622/*0.903989 Q15*/}} }; -const PWord16 *w_a[7] = { w1N8, w2N8, w3N8, w4N8, w5N8, w6N8, w7N8 }; +const PWord16 *w_a[7] = { w1N8, w2N8, w3N8, w4N8, w5N8, w6N8, w7N8 };//Q15 const PWord16 w19N[127] = { @@ -39963,7 +39968,7 @@ const PWord16 w18N[127] = * for fractional pitch search * Used in lib_enc\pit_enc.c Q14 *-------------------------------------------------------------------*/ -const Word16 inter4_1_fx[32] = +const Word16 inter4_1_fx[32] =//Q14 { -12, -26, 32, 206, 420, 455, 73, -766, @@ -39977,13 +39982,13 @@ const Word16 inter4_1_fx[32] = const Word16 sin_switch_8[15] = { 3212, 6393, 9512, 12540, 15447, 18205, 20788, 23170, 25330, 27246, 28899, 30274, 31357, 32138, 32610 -}; +};//Q15 const Word16 sin_switch_16[30] = { 1660, 3315, 4962, 6596, 8213, 9810, 11380, 12922, 14431, 15902, 17333, 18719, 20057, 21344, 22576, 23750, 24863, 25912, 26895, 27808, 28651, 29419, 30112, 30728, 31265, 31722, 32097, 32390, 32600, 32726 -}; +};//Q15 const Word16 sin_switch_32[60] = { 844, 1687, 2529, 3369, 4207, 5043, 5875, 6703, @@ -39994,7 +39999,7 @@ const Word16 sin_switch_32[60] = { 844, 1687, 2529, 3369, 4207, 5043, 5875, 6703 28518, 28924, 29311, 29678, 30026, 30354, 30662, 30949, 31216, 31462, 31688, 31892, 32075, 32237, 32378, 32497, 32594, 32670, 32725, 32757 -}; +};//Q15 const Word16 sin_switch_48[90] = { 566, 1131, 1696, 2261, 2825, 3388, 3950, 4511, @@ -40009,7 +40014,7 @@ const Word16 sin_switch_48[90] = { 566, 1131, 1696, 2261, 2825, 3388, 3950, 4511 31199, 31367, 31526, 31676, 31816, 31946, 32068, 32179, 32281, 32373, 32456, 32529, 32592, 32646, 32690, 32724, 32748, 32763 -}; +};//Q15 const Word16 one_on_win_48k_fx[210] = { @@ -40040,7 +40045,7 @@ const Word16 one_on_win_48k_fx[210] = 22924, 22996, 23069, 23142, 23216, 23291, 23367, 23443, 23521, 23599, 23677, 23757, 23837, 23918, 24000, 24083, 24167, 24251 -}; +};//Q14 const Word16 one_on_win_8k_16k_48k_fx[70] = { @@ -40053,7 +40058,7 @@ const Word16 one_on_win_8k_16k_48k_fx[70] = 20268, 20411, 20558, 20709, 20865, 21024, 21188, 21357, 21530, 21708, 21891, 22079, 22273, 22472, 22677, 22888, 23105, 23329, 23560, 23797, 24041, 24251 -}; +};//Q14 const Word16 window_8_16_32kHz_fx[370] = { @@ -40104,7 +40109,7 @@ const Word16 window_8_16_32kHz_fx[370] = 7026, 6675, 6322, 5965, 5606, 5243, 4878, 4508, 4136, 3759, 3378, 2993, 2603, 2208, 1807, 1397, 978, 545 -}; +};//Q15 const Word16 window_48kHz_fx[1110] = { @@ -40247,9 +40252,9 @@ const Word16 window_48kHz_fx[1110] = 3058, 2929, 2800, 2669, 2539, 2407, 2275, 2142, 2009, 1875, 1740, 1604, 1467, 1330, 1191, 1051, 909, 766, 621, 474, 324, 169 -}; +};//Q15 -const Word16 window_256kHz[592] = /*ALDO at 25.6 maybe not needed ?*/ +const Word16 window_256kHz[592] = /*ALDO at 25.6 maybe not needed ?Q15*/ { 1, 3, 7, 12, 19, 27, 36, 47, 58, 72, 86, 102, 119, 138, 157, 178, @@ -40327,7 +40332,7 @@ const Word16 window_256kHz[592] = /*ALDO at 25.6 maybe not needed ?*/ 2139, 1888, 1635, 1379, 1119, 854, 583, 304 }; -const Word16 small_overlap_48[R2_48 / 7] = +const Word16 small_overlap_48[R2_48 / 7] =//Q15 { 429, 1286, 2143, 2998, 3851, 4702, 5549, 6393, 7232, 8066, 8895, 9717, 10533, 11342, 12142, 12935, @@ -40339,7 +40344,7 @@ const Word16 small_overlap_48[R2_48 / 7] = 32631, 32698, 32743, 32765 }; -const Word16 small_overlap_25[R2_25 / 7] = +const Word16 small_overlap_25[R2_25 / 7] =//Q15 { 804, 2411, 4011, 5602, 7180, 8740, 10279, 11793, 13279, 14733, 16151, 17531, 18868, 20160, 21403, 22595, @@ -40347,7 +40352,7 @@ const Word16 small_overlap_25[R2_25 / 7] = 30572, 31114, 31581, 31972, 32286, 32522, 32679, 32758 }; -const Word16 small_overlap_int[R2_16 / 7] = +const Word16 small_overlap_int[R2_16 / 7] =//Q15 { 2571, 5126, 7650, 10126, 12540, 14876, 17121, 19261, 21281, 22865, @@ -40356,7 +40361,7 @@ const Word16 small_overlap_int[R2_16 / 7] = }; -const Word16 half_overlap_48[3 * R2_48 / 7] = +const Word16 half_overlap_48[3 * R2_48 / 7] =//Q15 { 143, 429, 715, 1001, 1286, 1572, 1858, 2143, 2428, 2713, @@ -40384,7 +40389,7 @@ const Word16 half_overlap_48[3 * R2_48 / 7] = 32765, 32767 }; -const Word16 half_overlap_25[3 * R2_25 / 7] = +const Word16 half_overlap_25[3 * R2_25 / 7] =//Q15 { 268, 804, 1340, 1876, 2411, 2945, 3479, 4011, 4543, 5073, 5602, 6130, 6655, 7180, 7702, 8222, @@ -40400,7 +40405,7 @@ const Word16 half_overlap_25[3 * R2_25 / 7] = 32522, 32583, 32635, 32679, 32714, 32741, 32758, 32767 }; -const Word16 half_overlap_int[3 * R2_16 / 7] = +const Word16 half_overlap_int[3 * R2_16 / 7] =//Q15 { 858, 1715, 2571, 3425, 4277, 5126, 5971, 6813, 7650, 8481, 9307, 10126, 10938, 11743, @@ -40411,7 +40416,7 @@ const Word16 half_overlap_int[3 * R2_16 / 7] = 30592, 30888, 31164, 31419, 31651, 31863, 32052, 32219, 32365, 32488, 32588, 32667, 32723, 32757 }; -const Word16 wac_h[LPC_SHB_ORDER] = +const Word16 wac_h[LPC_SHB_ORDER] =//Q15 { 32763, 32751, @@ -40425,7 +40430,7 @@ const Word16 wac_h[LPC_SHB_ORDER] = 32366 }; -const Word16 wac_l[LPC_SHB_ORDER] = +const Word16 wac_l[LPC_SHB_ORDER] =//Q15 { 31381, 27317, @@ -40452,20 +40457,20 @@ const Word16 dsDiracsTab[65] = 512 }; -const Word16 pwf_fx[17] = +const Word16 pwf_fx[17] =//Q12 { 22938, 16056, 11239, 7868, 5507, 3855, 2699, 1889, 1322, 926, 648, 454, 317, 222, 156, 109, 76 }; -const Word32 inverse_table[] = +const Word32 inverse_table[] =//Q29 { 0, 134217728, 67108864, 44739242, 33554432, 26843545, 22369621, 19173961, 16777216, 14913080, 13421772, 12201611, 11184810, 10324440, 9586980, 8947848, 8388608, 7895160, 7456540, 7064090, 6710886, 6391320, 6100805, 5835553, 5592405, 5368709, 5162220, 4971026, 4793490, 4628197, 4473924, 4329604, 4194304, 4067203, 3947580, 3834792, 3728270, 3627506, 3532045, 3441480, 3355443, 3273603, 3195660, 3121342, 3050402, 2982616, 2917776, 2855696, 2796202, 2739137, 2684354, 2631720, 2581110, 2532409, 2485513, 2440322, 2396745, 2354696, 2314098, 2274876, 2236962, 2200290, 2164802, 2130440, 2097152, 2064888, 2033601, 2003249, 1973790, 1945184, 1917396, 1890390, 1864135, 1838599, 1813753, 1789569, 1766022, 1743087, 1720740, 1698958, 1677721, 1657008, 1636801, 1617081, 1597830, 1579032, 1560671, 1542732, 1525201, 1508064, 1491308, 1474920, 1458888, 1443201, 1427848, 1412818, 1398101, 1383687, 1369568, 1355734, 1342177, 1328888, 1315860, 1303084, 1290555, 1278264, 1266204, 1254371, 1242756, 1231355, 1220161, 1209168, 1198372, 1187767, 1177348, 1167110, 1157049, 1147160, 1137438, 1127880, 1118481, 1109237, 1100145, 1091201, 1082401, 1073741, 1065220, 1056832, 1048576, 1040447, 1032444, 1024562, 1016800, 1009155, 1001624, 994205, 986895, 979691, 972592, 965595, 958698, 951898, 945195, 938585, 932067, 925639, 919299, 913045, 906876, 900790, 894784, 888859, 883011, 877240, 871543, 865920, 860370, 854889, 849479, 844136, 838860, 833650, 828504, 823421, 818400, 813440, 808540, 803698, 798915, 794187, 789516, 784898, 780335, 775825, 771366, 766958, 762600, 758292, 754032, 749819, 745654, 741534, 737460, 733430, 729444, 725501, 721600, 717741, 713924, 710146, 706409, 702710, 699050, 695428, 691843, 688296, 684784, 681308, 677867, 674460, 671088, 667749, 664444, 661171, 657930, 654720, 651542, 648394, 645277, 642190, 639132, 636102, 633102, 630130, 627185, 624268, 621378, 618514, 615677, 612866, 610080, 607320, 604584, 601873, 599186, 596523, 593883, 591267, 588674, 586103, 583555, 581029, 578524, 576041, 573580, 571139, 568719, 566319, 563940, 561580, 559240, 556920, 554618, 552336, 550072, 547827, 545600, 543391, 541200, 539027, 536870, 534731, 532610, 530504, 528416, 526344, }; -const Word16 cos_diff_table[512] = +const Word16 cos_diff_table[512] =//Q15 { SHC(0xFFFF), SHC(0xFFF8), SHC(0xFFF4), SHC(0xFFEF), SHC(0xFFE9), SHC(0xFFE5), SHC(0xFFE0), SHC(0xFFDB), SHC(0xFFD6), SHC(0xFFD2), SHC(0xFFCC), SHC(0xFFC7), SHC(0xFFC3), SHC(0xFFBE), SHC(0xFFB8), SHC(0xFFB4), @@ -40620,7 +40625,8 @@ const Word16 sincos_t_ext_fx[ 641 ] = { }; #endif -const Word16 fftSineTab640_fx[ 321 ] = { +const Word16 fftSineTab640_fx[ 321 ] = +{//Q15 SHC( 0x0000 ), SHC( 0x0141 ), SHC( 0x0283 ), SHC( 0x03c4 ), SHC( 0x0506 ), SHC( 0x0647 ), SHC( 0x0789 ), SHC( 0x08ca ), SHC( 0x0a0a ), SHC( 0x0b4b ), SHC( 0x0c8b ), SHC( 0x0dcb ), SHC( 0x0f0b ), SHC( 0x104a ), SHC( 0x1189 ), SHC( 0x12c8 ), SHC( 0x1406 ), SHC( 0x1543 ), SHC( 0x1680 ), SHC( 0x17bc ), SHC( 0x18f8 ), SHC( 0x1a33 ), SHC( 0x1b6e ), SHC( 0x1ca8 ), @@ -40665,7 +40671,7 @@ const Word16 fftSineTab640_fx[ 321 ] = { }; -const Word32 bwMode2fs[4] = { 8000, 16000, 32000, 48000 }; +const Word32 bwMode2fs[4] = { 8000, 16000, 32000, 48000 };//Q0 const Word16 cos_pi_by_127[128] = /* Q15 */ { @@ -40833,7 +40839,7 @@ const Word16 cos_pi_by_383[384] = /* Q15 */ -32762 ,-32765 ,-32767 }; -const Word16 swb_lsp_prev_interp_init[10] = { 32767, 31164, 26510, 19261, 10126, 0, -10126, -19261, -26510, -31164 }; +const Word16 swb_lsp_prev_interp_init[10] = { 32767, 31164, 26510, 19261, 10126, 0, -10126, -19261, -26510, -31164 };//Q15 /* st->swb_lsp_prev_interp[i] = (float)cos( (float)i * PI / (float)10.0f )*/ //ivas_sns_com_fx.c @@ -40880,9 +40886,9 @@ const Word32 pow_tilt_32k[64] = { 1029387260, 1121709444, 1222311686, 1331936594, 1451393382, 1581563835, 1723408827, 1877975405 }; -const Word16 L_frame_inv[8] = { 0x4000, 0x369D, 0x3333, 0x2D83, 0x2AAB, 0x28F6, 0, 0x2222 }; +const Word16 L_frame_inv[8] = { 0x4000, 0x369D, 0x3333, 0x2D83, 0x2AAB, 0x28F6, 0, 0x2222 }; // Q14 -const Word16 InvIntTable[65] = +const Word16 InvIntTable[65] = // Q15 { 0x7FFF, 0x7FFF, 0x4000, 0x2AAB, 0x2000, 0x199A, 0x1555, 0x1249, 0x1000, @@ -40895,7 +40901,7 @@ const Word16 InvIntTable[65] = 0x023F, 0x0235, 0x022B, 0x0222, 0x0219, 0x0211, 0x0208, 0x0200 }; -const Word16 TecLowBandTable[] = { 0, 2, 4, 6 }; +const Word16 TecLowBandTable[] = { 0, 2, 4, 6 }; //Q0 const Word16 TecSC_Fx[] = { 23999/*0.3662f*2.0f Q15*/, 7065/*0.1078f*2.0f Q15*/, 7825/*0.1194f*2.0f Q15*/, @@ -40942,7 +40948,7 @@ const Word16 sqrt_table_pitch_search[256 + 1] = /* Q11 */ }; // fft_evs.c -const Word16 RotVector_32[2 * 20] = { +const Word16 RotVector_32[2 * 20] = { // Q15 /** * \brief Twiddle factors are unscaled */ @@ -40956,7 +40962,7 @@ const Word16 RotVector_32[2 * 20] = { /** * \brief Twiddle factors are unscaled */ -const Word16 RotVector_480[2 * ( 480 - 30 )] = { +const Word16 RotVector_480[2 * ( 480 - 30 )] = { // Q15 SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7ff5 ), SHC( 0xfca6 ), SHC( 0x7fd3 ), SHC( 0xf94d ), SHC( 0x7f9b ), SHC( 0xf5f5 ), SHC( 0x7f4c ), SHC( 0xf29f ), SHC( 0x7ee8 ), SHC( 0xef4b ), SHC( 0x7e6d ), SHC( 0xebfa ), SHC( 0x7ddb ), SHC( 0xe8ad ), SHC( 0x7d34 ), SHC( 0xe563 ), SHC( 0x7c77 ), SHC( 0xe21e ), @@ -41072,7 +41078,7 @@ const Word16 RotVector_480[2 * ( 480 - 30 )] = { SHC( 0x30fc ), SHC( 0x7642 ), SHC( 0x471d ), SHC( 0x6a6e ), SHC( 0x5a82 ), SHC( 0x5a82 ), SHC( 0x6a6e ), SHC( 0x471d ) }; -const Word16 RotVector_600[2 * ( 600 - 30 )] = { +const Word16 RotVector_600[2 * ( 600 - 30 )] = { // Q15 SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7ff9 ), SHC( 0xfd52 ), SHC( 0x7fe3 ), SHC( 0xfaa4 ), SHC( 0x7fbf ), SHC( 0xf7f6 ), SHC( 0x7f8d ), SHC( 0xf54a ), SHC( 0x7f4c ), SHC( 0xf29f ), SHC( 0x7efe ), SHC( 0xeff5 ), SHC( 0x7ea0 ), SHC( 0xed4d ), SHC( 0x7e35 ), SHC( 0xeaa7 ), SHC( 0x7dbc ), SHC( 0xe804 ), @@ -41222,7 +41228,7 @@ const Word16 RotVector_600[2 * ( 600 - 30 )] = { /** * \brief Twiddle factors are unscaled */ -const Word16 RotVector_256[2 * ( 256 - 32 )] = { +const Word16 RotVector_256[2 * ( 256 - 32 )] = { // Q15 SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7ff6 ), SHC( 0xfcdc ), SHC( 0x7fd9 ), SHC( 0xf9b8 ), SHC( 0x7fa7 ), SHC( 0xf695 ), SHC( 0x7f62 ), SHC( 0xf374 ), SHC( 0x7f0a ), SHC( 0xf055 ), SHC( 0x7e9d ), SHC( 0xed38 ), SHC( 0x7e1e ), SHC( 0xea1e ), SHC( 0x7d8a ), SHC( 0xe707 ), SHC( 0x7ce4 ), SHC( 0xe3f4 ), SHC( 0x7c2a ), SHC( 0xe0e6 ), SHC( 0x7b5d ), SHC( 0xdddc ), @@ -41284,7 +41290,7 @@ const Word16 RotVector_256[2 * ( 256 - 32 )] = { /** * \brief Twiddle factors are unscaled */ -const Word16 RotVector_320[2 * ( 320 - 20 )] = { +const Word16 RotVector_320[2 * ( 320 - 20 )] = { // Q15 SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7fe7 ), SHC( 0xfafa ), SHC( 0x7f9b ), SHC( 0xf5f5 ), SHC( 0x7f1d ), SHC( 0xf0f5 ), SHC( 0x7e6d ), SHC( 0xebfa ), SHC( 0x7d8a ), SHC( 0xe707 ), SHC( 0x7c77 ), SHC( 0xe21e ), SHC( 0x7b32 ), SHC( 0xdd41 ), SHC( 0x79bc ), SHC( 0xd872 ), SHC( 0x7817 ), SHC( 0xd3b2 ), SHC( 0x7642 ), SHC( 0xcf04 ), SHC( 0x743e ), SHC( 0xca69 ), @@ -41368,7 +41374,7 @@ const Word16 RotVector_320[2 * ( 320 - 20 )] = { * Rotation factor table, real and imaginary part interleaved, for dim1=20,dim2=20 */ -const Word16 RotVector_400[2 * ( 400 - 20 )] = { +const Word16 RotVector_400[2 * ( 400 - 20 )] = { // Q15 SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7ff0 ), SHC( 0xfbfb ), SHC( 0x7fbf ), SHC( 0xf7f6 ), SHC( 0x7f6f ), SHC( 0xf3f4 ), SHC( 0x7efe ), SHC( 0xeff5 ), SHC( 0x7e6d ), SHC( 0xebfa ), SHC( 0x7dbc ), SHC( 0xe804 ), SHC( 0x7ceb ), SHC( 0xe414 ), SHC( 0x7bfb ), SHC( 0xe02b ), SHC( 0x7aeb ), SHC( 0xdc4a ), SHC( 0x79bc ), SHC( 0xd872 ), SHC( 0x786f ), SHC( 0xd4a4 ), @@ -41466,7 +41472,7 @@ const Word16 RotVector_400[2 * ( 400 - 20 )] = { SHC( 0x080a ), SHC( 0x7fbf ), SHC( 0x2d3f ), SHC( 0x77bd ), SHC( 0x4e74 ), SHC( 0x6524 ), SHC( 0x68b9 ), SHC( 0x499a ) }; -const Word16 FFT_W64[( 64 * 2 ) * 2] = { +const Word16 FFT_W64[( 64 * 2 ) * 2] = { // Q15 16384, 0, 16364, -804, 16305, -1606, 16207, -2404, 16069, -3196, 15893, -3981, 15679, -4756, 15426, -5520, 15137, -6270, 14811, -7005, 14449, -7723, 14053, -8423, @@ -41503,7 +41509,7 @@ const Word16 FFT_W64[( 64 * 2 ) * 2] = { -32138, -6393, -32413, -4808, -32610, -3212, -32729, -1608 }; -const Word16 FFT_W128[] = { +const Word16 FFT_W128[] = { // Q15 /* part of table that is not scaled by 2 */ 16384, 0, 16379, -402, 16364, -804, 16339, -1205, 16305, -1606, 16260, -2006, 16206, -2404, 16142, -2801, @@ -41572,7 +41578,7 @@ const Word16 FFT_W128[] = { -32610, -3212, -32678, -2410, -32728, -1608, -32758, -804 }; -const Word16 FFT_W256[( 256 * 2 ) * 2] = { +const Word16 FFT_W256[( 256 * 2 ) * 2] = { // Q15 /* Each adjacent pair represents the real and imaginary part of a complex number: */ /* W = exp{-j*(PI*n/256)} = cos(PI*n/256)*16384 -j*sin(PI*n/256)*16384 for n=0, 1, ..., 255. */ 16384, 0, 16383, -201, 16379, -402, 16373, -603, @@ -41708,7 +41714,7 @@ const Word16 FFT_W256[( 256 * 2 ) * 2] = { -32729, -1608, -32746, -1206, -32758, -804, -32766, -402 }; -const Word16 FFT_W512[( 512 * 2 ) * 2] = { +const Word16 FFT_W512[( 512 * 2 ) * 2] = { // Q15 16384, 0, 16384, -101, 16383, -201, 16381, -302, 16379, -402, 16376, -503, 16373, -603, 16369, -704, 16364, -804, 16359, -904, 16353, -1005, 16347, -1105, @@ -42043,19 +42049,19 @@ const Word16 Gamma_19661_Tbl_fx[] = { const Word16 Gamma_29491_Tbl[] = { 29491, 26542, 23888, 21499, 19349, 17414, 15672, 14105, 12694, 11425, 10282, 9254, 8329, 7496, 6746, 6071 -}; +}; // Q15 /*---------------------------------------------------------------------* * NB post-filter tables *---------------------------------------------------------------------*/ -const Word16 tab_hup_s_fx[SIZ_TAB_HUP_S] = { +const Word16 tab_hup_s_fx[SIZ_TAB_HUP_S] = { // Q15 -188, 2873, 31650, -1597, -484, 7041, 28469, -2147, -933, 12266, 23705, -1992, -1492, 18050, 18050, -1492, -1992, 23705, 12266, -933, -2147, 28469, 7041, -484, -1597, 31650, 2873, -188 }; -const Word16 tab_hup_l_fx[SIZ_TAB_HUP_L] = { +const Word16 tab_hup_l_fx[SIZ_TAB_HUP_L] = { // Q15 -40, 72, -156, 315, -579, 1023, -1874, 4439, 31915, -3390, 1595, -887, 501, -266, 130, -59, -77, 147, -317, 631, -1150, 2030, -3773, 9639, @@ -42072,8 +42078,8 @@ const Word16 tab_hup_l_fx[SIZ_TAB_HUP_L] = { 4439, -1874, 1023, -579, 315, -156, 72, -40 }; -const Word16 mfreq_loc_Q2fx[] = { 700, 1500, 3100, 4700, 6300, 7900, 9500, 11100, 12700, 14300, 15900, 17500, 19100, 20700, 22300, 25500, 28700, 31900 }; -const Word16 mfreq_loc_div_25[] = { 7, 15, 31, 47, 63, 79, 95, 111, 127, 143, 159, 175, 191, 207, 223, 255, 287, 319 }; +const Word16 mfreq_loc_Q2fx[] = { 700, 1500, 3100, 4700, 6300, 7900, 9500, 11100, 12700, 14300, 15900, 17500, 19100, 20700, 22300, 25500, 28700, 31900 }; // Q0 +const Word16 mfreq_loc_div_25[] = { 7, 15, 31, 47, 63, 79, 95, 111, 127, 143, 159, 175, 191, 207, 223, 255, 287, 319 }; // Q0 // low_rate_band_att_fx.c /* %* lowered Table ROM, call with band_len_idx[sfm_size>>3] */ @@ -42082,25 +42088,26 @@ const Word16 mfreq_loc_div_25[] = { 7, 15, 31, 47, 63, 79, 95, 111, 127, 143, 15 /* % idx= 0 1 2 3 4 5 6 7; */ /* call with band_len_idx[sfm_size>>3] */ const Word16 band_len_idx[1 + ( MAX_SFM_LEN_FX / 8 )] = { + // Q0 /*sfm/8*/ /*1*/ /*2 */ /*3 */ /*4 */ /*6 */ /*8 */ /*10*/ /*12*/ -1, 0 /*8*/, 1 /*16*/, 2 /*24*/, 3 /*32*/, -1, 4 /*48 */, -1, 5 /*64 */, -1, 6 /*80*/, -1, 7 /*96*/ }; -const Word16 band_len_ener_shift[8] = { 1, 2, 2, 2, 3, 3, 4 /*sfm==80*/, 4 /*sfm==96*/ }; /* 96 requires 1 bit more than 48 */ +const Word16 band_len_ener_shift[8] = { 1, 2, 2, 2, 3, 3, 4 /*sfm==80*/, 4 /*sfm==96*/ }; /* 96 requires 1 bit more than 48 */ // Q0 /*% sfms=[8,16,24,32,48,64,80,96], round(sqrt(sfms)*2^11) */ const Word16 fine_gain_pred_sqrt_bw[8] = { 5793, 8192, 10033, 11585, 14189, 16384, 18318, 20066 }; /* (Q11) */ #ifdef IVAS_FLOAT_FIXED const Word16 ivas_band_len_idx[1 + ( MAX_SFM_LEN_FX / 8 )] = { - /*sfm/8*/ /*1*/ /*2 */ /*3 */ /*4 */ /*6 */ /*8 */ /*10*/ /*12*/ - -1, 0 /*8*/, 1 /*16*/, 2 /*24*/, 3 /*32*/, 4 /*40*/, 5 /*48 */, -1, 6 /*64 */, -1, 7 /*80*/, -1, 8 /*96*/ -}; -const Word16 ivas_band_len_ener_shift[9] = { 1, 2, 2, 2, 3, 3, 3, 4 /*sfm==80*/, 4 /*sfm==96*/ }; /* 96 requires 1 bit more than 48 */ + /*sfm/8*/ /*1*/ /*2 */ /*3 */ /*4 */ /*6 */ /*8 */ /*10*/ /*12*/ + -1, 0 /*8*/, 1 /*16*/, 2 /*24*/, 3 /*32*/, 4 /*40*/, 5 /*48 */, -1, 6 /*64 */, -1, 7 /*80*/, -1, 8 /*96*/ +}; // Q0 +const Word16 ivas_band_len_ener_shift[9] = { 1, 2, 2, 2, 3, 3, 3, 4 /*sfm==80*/, 4 /*sfm==96*/ }; // Q0 /* 96 requires 1 bit more than 48 */ const Word16 ivas_fine_gain_pred_sqrt_bw[9] = { 5793, 8192, 10033, 11585, 12953, 14189, 16384, 18318, 20066 }; /* (Q11) */ /*% sfms=[8,16,24,32,40,48,64,80,96], round(sqrt(sfms)*2^11) */ #endif /*----------------------------------------------------------------------------------* * means of ISFs for WB active speech *----------------------------------------------------------------------------------*/ -const Word16 Mean_isf_wb[M] = /* G722.2 active speech ISF's means */ +const Word16 Mean_isf_wb[M] = /* G722.2 active speech ISF's means Q2.56*/ { 738, 1326, 2336, 3578, 4596, 5662, 6711, 7730, 8750, 9753, 10705, 11728, 12833, 13971, 15043, 4037 @@ -42144,7 +42151,7 @@ const Word16 tab_ari_qnew[4][4] = { { 0x0000, 0x0CCC, 0x0CCC, 0x0CCC }, { 0x0BBB, 0x2000, 0x4000, 0x0CCC }, { 0x0BBB, 0x0BBB, 0x4000, 0x4000 } }; -const Word16 phs_tbl_dec[64 * 2] = { +const Word16 phs_tbl_dec[64 * 2] = { // Q15 /* part of table that is not scaled by 2 */ 16384, 0, 16305, -1606, 16069, -3196, 15678, -4756, 15136, -6270, 14449, -7723, 13622, -9102, 12665, -10394, 11585, -11585, 10394, -12665, @@ -42164,7 +42171,7 @@ const Word16 phs_tbl_dec[64 * 2] = { }; /* 2.0 - 6.4 kHz phase dispersion */ -const Word16 Low_H_phasedisp[L_SUBFR] = { +const Word16 Low_H_phasedisp[L_SUBFR] = { // Q15 16389, 16381, 16386, 16382, 16382, 16383, 16381, 16384, 16385, 10265, 10154, 9894, 14052, 16343, -531, 13216, 16373, 15510, 9407, 15949, 4726, 14593, 10404, 9796, -16336, -1815, -10623, 12647, 14556, -12683, @@ -42175,7 +42182,7 @@ const Word16 Low_H_phasedisp[L_SUBFR] = { }; /* 3.2 - 6.4 kHz phase dispersion */ -const Word16 Mid_H_phasedisp[L_SUBFR] = { +const Word16 Mid_H_phasedisp[L_SUBFR] = { // Q15 16382, 16382, 16384, 16385, 16386, 16388, 16387, 16383, 16387, 16383, 16386, 16386, 16386, 16384, 16382, 16388, 14847, 9629, 13249, 14487, 10995, 643, 13818, 13779, 6468, 8665, 11634, 9781, -14636, -982, @@ -42189,10 +42196,10 @@ const Word16 Mid_H_phasedisp[L_SUBFR] = { const Word16 Tab_esc_nb[4] = { 0 << ( NBITS_CONTEXT + NBITS_RATEQ ), 1 << ( NBITS_CONTEXT + NBITS_RATEQ ), 2 << ( NBITS_CONTEXT + NBITS_RATEQ ), - 3 << ( NBITS_CONTEXT + NBITS_RATEQ ) }; + 3 << ( NBITS_CONTEXT + NBITS_RATEQ ) }; // Q0 -const Word16 pow2tab[15] = { 0x0001, 0x0002, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, 0x0080, 0x0100, 0x0200, 0x0400, 0x0800, 0x1000, 0x2000, 0x4000 }; -const Word32 pow2[] = { +const Word16 pow2tab[15] = { 0x0001, 0x0002, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, 0x0080, 0x0100, 0x0200, 0x0400, 0x0800, 0x1000, 0x2000, 0x4000 }; // Q0 +const Word32 pow2[] = { // Q0 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288, 1048576 }; // d_gain2p.c @@ -42256,7 +42263,7 @@ const Word16 num_nelp_lp_fx[NELP_LP_ORDER + 1] = /*Q13*/ 726 }; -const Word16 den_nelp_lp_fx[NELP_LP_ORDER + 1] = { +const Word16 den_nelp_lp_fx[NELP_LP_ORDER + 1] = { // Q13 8192, 8819, 21618, @@ -42271,7 +42278,7 @@ const Word16 den_nelp_lp_fx[NELP_LP_ORDER + 1] = { /*----------------------------------------------------------------------------------* * AMR-WB IO WB BWE - band-pass 6-8kHz FIR filter, values in Q15: *----------------------------------------------------------------------------------*/ -const Word16 fir_6k_8k_fx[31] = { +const Word16 fir_6k_8k_fx[31] = { // Q15 44, -155, 323, -482, 563, -590, 726, -1180, 1986, -2818, 3028, -1991, -423, 3583, -6281, 7342, -6281, 3583, -423, -1991, 3028, -2818, 1986, -1180, 726, -590, 563, -482, 323, -155, 44 @@ -42285,7 +42292,7 @@ const Word16 pwf78_fx[17] = { 25559, 19936, 15550, 12129, 9460, 7379, 5755, 4489 * lag window for windowing the autocorrelations in LP analysis * Used in lib_enc\analy_lp_fx.c *------------------------------------------------------------------------------*/ -const Word16 hamcos_window_fx[L_LP_AMR_WB] = { +const Word16 hamcos_window_fx[L_LP_AMR_WB] = { // Q15 2621, 2622, 2626, 2632, 2640, 2650, 2662, 2677, 2694, 2714, 2735, 2759, 2785, 2814, 2844, 2877, 2912, 2949, 2989, 3031, 3075, 3121, 3169, 3220, @@ -42337,7 +42344,7 @@ const Word16 hamcos_window_fx[L_LP_AMR_WB] = { }; -const Word16 CNG_burst_att_fx[6][8] = { +const Word16 CNG_burst_att_fx[6][8] = { // Q15 { 30076, 27793, 25832, 24129, 22637, 21319, 20146, 19095 }, { 29714, 27181, 25046, 23222, 21646, 20270, 20205, 20205 }, { 29415, 26685, 24418, 22506, 22410, 22410, 22410, 22410 }, @@ -42346,7 +42353,7 @@ const Word16 CNG_burst_att_fx[6][8] = { { 29789, 27307, 25206, 23406, 21845, 20480, 19661, 19661 } }; -const Word16 lpc_weights_fx[LPC_SHB_ORDER + 1] = { +const Word16 lpc_weights_fx[LPC_SHB_ORDER + 1] = { // Q15 32767, 31948, 31150, 30371, 29612, 28871, 28149, 27446, 26760, 26091, 25438 }; @@ -42521,7 +42528,7 @@ const Word16 E_ROM_inter6_1_fx[PIT_UP_SAMP6 * L_INTERPOL1 + 1] = { -108 /*-0.00656128F Q14*/, 0 /*0.000000F Q14*/ }; -const Word16 kLog2TableFrac_x[256] = { +const Word16 kLog2TableFrac_x[256] = { // Q8 0, 1, 3, 4, 6, 7, 9, 10, 11, 13, 14, 16, 17, 18, 20, 21, 22, 24, 25, 26, 28, 29, 30, 32, @@ -42608,7 +42615,7 @@ const Word16 One_div_fx[] = /* in Q15 */ 4096 /* 1/8 */ }; -const Word32 tbl_two_pow_shift_by_4[35] = { +const Word32 tbl_two_pow_shift_by_4[35] = { // Q30 1073741824, 902905664, 759250112, 638450688, 536870912, 451452832, 379625056, 319225344, 268435456, 225726416, 189812528, 159612672, 134217728, 112863208, 94906264, 79806336, 67108864, 56431604, 47453132, 39903168, 33554432, 28215802, 23726566, 19951584, @@ -42617,7 +42624,7 @@ const Word32 tbl_two_pow_shift_by_4[35] = { }; -const Word16 ivas_tan_panning_gain_tbl_fx[601] = { +const Word16 ivas_tan_panning_gain_tbl_fx[601] = { // Q15 SHC( 0x0000 ), SHC( 0x0042 ), SHC( 0x0084 ), SHC( 0x00c6 ), SHC( 0x0109 ), SHC( 0x014b ), SHC( 0x018e ), SHC( 0x01d1 ), SHC( 0x0214 ), SHC( 0x0257 ), SHC( 0x029b ), SHC( 0x02de ), SHC( 0x0322 ), SHC( 0x0365 ), SHC( 0x03a9 ), SHC( 0x03ed ), SHC( 0x0431 ), SHC( 0x0475 ), SHC( 0x04ba ), SHC( 0x04fe ), SHC( 0x0543 ), SHC( 0x0588 ), SHC( 0x05cd ), SHC( 0x0612 ), @@ -42696,7 +42703,7 @@ const Word16 ivas_tan_panning_gain_tbl_fx[601] = { SHC( 0x7fff ) }; -const Word16 ivas_sine_panning_tbl_fx[601] = { +const Word16 ivas_sine_panning_tbl_fx[601] = { // Q15 SHC( 0xc001 ), SHC( 0xc032 ), SHC( 0xc064 ), SHC( 0xc095 ), SHC( 0xc0c7 ), SHC( 0xc0f9 ), SHC( 0xc12b ), SHC( 0xc15c ), SHC( 0xc18e ), SHC( 0xc1c0 ), SHC( 0xc1f2 ), SHC( 0xc224 ), SHC( 0xc256 ), SHC( 0xc289 ), SHC( 0xc2bb ), SHC( 0xc2ed ), SHC( 0xc31f ), SHC( 0xc352 ), SHC( 0xc384 ), SHC( 0xc3b6 ), SHC( 0xc3e9 ), SHC( 0xc41b ), SHC( 0xc44e ), SHC( 0xc481 ), @@ -42775,7 +42782,7 @@ const Word16 ivas_sine_panning_tbl_fx[601] = { SHC( 0x3fff ) }; -const Word16 ivas_sin_az_fx[361] = { +const Word16 ivas_sin_az_fx[361] = { // Q15 SHC( 0x0000 ), SHC( 0xfdc5 ), SHC( 0xfb89 ), SHC( 0xf94e ), SHC( 0xf713 ), SHC( 0xf4d9 ), SHC( 0xf29f ), SHC( 0xf067 ), SHC( 0xee30 ), SHC( 0xebfa ), SHC( 0xe9c6 ), SHC( 0xe794 ), SHC( 0xe564 ), SHC( 0xe335 ), SHC( 0xe109 ), SHC( 0xdee0 ), SHC( 0xdcb8 ), SHC( 0xda94 ), SHC( 0xd873 ), SHC( 0xd654 ), SHC( 0xd439 ), SHC( 0xd221 ), SHC( 0xd00d ), SHC( 0xcdfd ), @@ -44210,7 +44217,7 @@ const Word16 cos_scale_tbl_800[800] = { /* Q15 */ }; #endif // IVAS_FLOAT_FIXED -const Word16 scales_ivas_fx[][MAX_NO_SCALES * 2] = /* 2 subvectors */ +const Word16 scales_ivas_fx[][MAX_NO_SCALES * 2] = /* 2 subvectors Q11*/ { { 3129, diff --git a/lib_com/rom_com.h b/lib_com/rom_com.h index 9035c3144..833ae46b6 100644 --- a/lib_com/rom_com.h +++ b/lib_com/rom_com.h @@ -75,9 +75,9 @@ typedef struct typedef struct { - int16_t bands; - int16_t bw; - const int16_t *band_width; + Word16 bands; // Q0 + Word16 bw; // Q0 + const Word16 *band_width; // Q0 Word32 L_qint; Word16 eref_fx; @@ -86,9 +86,9 @@ typedef struct Word16 bit_alloc_weight_fx; Word16 bit_alloc_weight; - int16_t gqlevs; - int16_t Ngq; - int16_t p2a_bands; + Word16 gqlevs; // Q0 + Word16 Ngq; // Q0 + Word16 p2a_bands; // Q0 float p2a_th_float; Word16 p2a_th; @@ -107,119 +107,119 @@ typedef struct } Xcore_Config; -extern const Word16 filter_LP15_180H_fx[]; /* Sincfilt.m: N=180*2+1, Fmin=0, Fmax=1/15, hann( N )' */ -extern const Word16 filter_LP3_90H_fx[]; /* Sincfilt.m: N=90*2+1, Fmin=0, Fmax=1/3, hann( N )' */ -extern const Word16 filter_LP12_180H_13b_fx[]; /* Sincfilt.m: N=180*2+1, Fmin=0, Fmax=1/12, hann( N )' */ -extern const Word16 filter_LP15_180H_13b_fx[]; /* Sincfilt.m: N=180*2+1, Fmin=0, Fmax=1/15, hann( N )' */ -extern const Word16 filter_LP15_360H_13b_fx[]; /* Sincfilt.m: N=360*2+1, Fmin=0, Fmax=1/15, hann( N )' */ -extern const Word16 filter_LP24_90H_13b_fx[]; -extern const Word16 filter_LP24_90H_fx[]; +extern const Word16 filter_LP15_180H_fx[]; // Q14 /* Sincfilt.m: N=180*2+1, Fmin=0, Fmax=1/15, hann( N )' */ +extern const Word16 filter_LP3_90H_fx[]; // Q14 /* Sincfilt.m: N=90*2+1, Fmin=0, Fmax=1/3, hann( N )' */ +extern const Word16 filter_LP12_180H_13b_fx[]; // Q13/* Sincfilt.m: N=180*2+1, Fmin=0, Fmax=1/12, hann( N )' */ +extern const Word16 filter_LP15_180H_13b_fx[]; // Q13/* Sincfilt.m: N=180*2+1, Fmin=0, Fmax=1/15, hann( N )' */ +extern const Word16 filter_LP15_360H_13b_fx[]; // Q13/* Sincfilt.m: N=360*2+1, Fmin=0, Fmax=1/15, hann( N )' */ +extern const Word16 filter_LP24_90H_13b_fx[]; // Q13 +extern const Word16 filter_LP24_90H_fx[]; // Q14 /*-----------------------------------------------------------------* * Table of bitrates *-----------------------------------------------------------------*/ -extern const int32_t brate_tbl[SIZE_BRATE_TBL]; -extern const int32_t brate_intermed_tbl[]; -extern const int32_t acelp_sig_tbl[MAX_ACELP_SIG]; +extern const Word32 brate_tbl[SIZE_BRATE_TBL]; // Q0 +extern const Word32 brate_intermed_tbl[]; // Q0 +extern const Word32 acelp_sig_tbl[MAX_ACELP_SIG]; // Q0 /*-----------------------------------------------------------------* * Bit-allocation tables *-----------------------------------------------------------------*/ -extern const int16_t LSF_bits_tbl[]; /* Bit allocation table for end-frame ISF quantizer */ -extern const int16_t mid_LSF_bits_tbl[]; /* Bit allocation table for mid-frame ISF quantizer */ -extern const int16_t Es_pred_bits_tbl[]; /* Bit allocation table for scaled innovation energy prediction */ -extern const int16_t gain_bits_tbl[]; /* Bit allocation table for gain quantizer */ +extern const Word16 LSF_bits_tbl[]; /* Bit allocation table for end-frame ISF quantizer Q0*/ +extern const Word16 mid_LSF_bits_tbl[]; /* Bit allocation table for mid-frame ISF quantizer Q0*/ +extern const Word16 Es_pred_bits_tbl[]; /* Bit allocation table for scaled innovation energy prediction Q0*/ +extern const Word16 gain_bits_tbl[]; /* Bit allocation table for gain quantizer Q0*/ -extern const int16_t ACB_bits_tbl[]; /* Bit allocation table for adaptive codebook (pitch) */ -extern const int16_t FCB_bits_tbl[]; /* Bit allocation table for algebraic (fixed) codebook (innovation) */ -extern const int16_t reserved_bits_tbl[]; /* Bit allocation table for reseved bits */ +extern const Word16 ACB_bits_tbl[]; /* Bit allocation table for adaptive codebook (pitch) Q0*/ +extern const Word16 FCB_bits_tbl[]; /* Bit allocation table for algebraic (fixed) codebook (innovation) Q0*/ +extern const Word16 reserved_bits_tbl[]; /* Bit allocation table for reseved bits Q0*/ -extern const int16_t ACB_bits_16kHz_tbl[]; /* Bit allocation table for adaptive codebook (pitch) @16kHz */ -extern const int16_t FCB_bits_16kHz_tbl[]; /* Bit allocation table for algebraic (fixed) codebook (innovation) @16kHz */ -extern const int16_t gain_bits_16kHz_tbl[]; /* Bit allocation table for gain quantizer @16kHz */ -extern const int16_t AVQ_bits_16kHz_tbl[]; /* Bit allocation table for AVQ bits @16kHz ACELP, active segments */ +extern const Word16 ACB_bits_16kHz_tbl[]; /* Bit allocation table for adaptive codebook (pitch) @16kHz Q0*/ +extern const Word16 FCB_bits_16kHz_tbl[]; /* Bit allocation table for algebraic (fixed) codebook (innovation) @16kHz Q0*/ +extern const Word16 gain_bits_16kHz_tbl[]; /* Bit allocation table for gain quantizer @16kHz Q0*/ +extern const Word16 AVQ_bits_16kHz_tbl[]; /* Bit allocation table for AVQ bits @16kHz ACELP, active segments Q0*/ -extern const uint32_t pulsestostates[17][9]; /* Number of states for any combination of pulses in any combination of vector length */ +extern const UWord32 pulsestostates[17][9]; /* Number of states for any combination of pulses in any combination of vector length Q0*/ -extern const uint8_t ACELP_NRG_MODE[RATE_MODE_MAX][BANDWIDTH_MODE_MAX][ACELP_MODE_MAX + RF_MODE_MAX]; -extern const uint8_t ACELP_NRG_BITS[3]; +extern const UWord8 ACELP_NRG_MODE[RATE_MODE_MAX][BANDWIDTH_MODE_MAX][ACELP_MODE_MAX + RF_MODE_MAX]; // Q0 +extern const UWord8 ACELP_NRG_BITS[3]; // Q0 -extern const uint8_t ACELP_LTP_MODE[RATE_MODE_MAX][BANDWIDTH_MODE_MAX][ACELP_MODE_MAX + RF_MODE_MAX]; -extern const uint8_t ACELP_LTP_BITS[RATE_MODE_MAX][BANDWIDTH_MODE_MAX][ACELP_MODE_MAX + RF_MODE_MAX]; -extern const uint8_t ACELP_LTP_BITS_SFR[8 + RF_MODE_MAX][5]; +extern const UWord8 ACELP_LTP_MODE[RATE_MODE_MAX][BANDWIDTH_MODE_MAX][ACELP_MODE_MAX + RF_MODE_MAX]; // Q0 +extern const UWord8 ACELP_LTP_BITS[RATE_MODE_MAX][BANDWIDTH_MODE_MAX][ACELP_MODE_MAX + RF_MODE_MAX]; // Q0 +extern const UWord8 ACELP_LTP_BITS_SFR[8 + RF_MODE_MAX][5]; // Q0 -extern const uint8_t ACELP_LTF_MODE[RATE_MODE_MAX][BANDWIDTH_MODE_MAX][ACELP_MODE_MAX + RF_MODE_MAX]; -extern const uint8_t ACELP_LTF_BITS[4]; +extern const UWord8 ACELP_LTF_MODE[RATE_MODE_MAX][BANDWIDTH_MODE_MAX][ACELP_MODE_MAX + RF_MODE_MAX]; // Q0 +extern const UWord8 ACELP_LTF_BITS[4]; // Q0 -extern const uint8_t ACELP_GAINS_MODE[RATE_MODE_MAX][BANDWIDTH_MODE_MAX][ACELP_MODE_MAX + RF_MODE_MAX]; -extern const uint8_t ACELP_GAINS_BITS[10]; +extern const UWord8 ACELP_GAINS_MODE[RATE_MODE_MAX][BANDWIDTH_MODE_MAX][ACELP_MODE_MAX + RF_MODE_MAX]; // Q0 +extern const UWord8 ACELP_GAINS_BITS[10]; // Q0 -extern const uint8_t ACELP_BPF_MODE[RATE_MODE_MAX][BANDWIDTH_MODE_MAX][ACELP_MODE_MAX + RF_MODE_MAX]; -extern const uint8_t ACELP_BPF_BITS[3]; -extern const Word16 ACELP_CDK_BITS[]; +extern const UWord8 ACELP_BPF_MODE[RATE_MODE_MAX][BANDWIDTH_MODE_MAX][ACELP_MODE_MAX + RF_MODE_MAX]; // Q0 +extern const UWord8 ACELP_BPF_BITS[3]; // Q0 +extern const Word16 ACELP_CDK_BITS[]; // Q0 /*----------------------------------------------------------------------------------* * Pre-processing *----------------------------------------------------------------------------------*/ -extern const float inv_tbl[]; /* Table of 1/x values */ -extern const Word16 inv_tbl_fx[]; +extern const float inv_tbl[]; /* Table of 1/x values */ +extern const Word16 inv_tbl_fx[]; // Q15 -extern const Word16 hvq_bwe_fac_fx[16]; -extern const Word16 sqac_headroom_fx[146]; -extern const Word16 inv_N_fx[32]; -extern const Word16 band_len_harm[]; +extern const Word16 hvq_bwe_fac_fx[16]; // Q15 +extern const Word16 sqac_headroom_fx[146]; // Q0 +extern const Word16 inv_N_fx[32]; // Q15 +extern const Word16 band_len_harm[]; // Q0 /* PVQ tables */ -extern const Word32 thren_fx[39]; +extern const Word32 thren_fx[39]; // Q8 /* Band structure */ -extern const Word16 dicnlg2[40]; +extern const Word16 dicnlg2[40]; // Q0 extern const Resampling_cfg resampling_cfg_tbl[]; /* table of resampling configurations */ extern const FrameSizeParams FrameSizeConfig[FRAME_SIZE_NB]; -extern const float h_high[]; /* HP filter for filtering random part of excitation in FEC */ -extern const Word16 h_high_fx[5]; +extern const float h_high[]; /* HP filter for filtering random part of excitation in FEC */ +extern const Word16 h_high_fx[5]; // Q15 #ifdef IVAS_FLOAT_FIXED extern const Word32 crit_bands_fx[]; -#endif // IVAS_FLOAT_FIXED -extern const float crit_bands[]; /* Table of critical bands */ -extern const float sincos_t[]; /* FFT - sinus and cosinus tables */ -extern const Word16 sincos_t_fx[161]; +#endif // IVAS_FLOAT_FIXED +extern const float crit_bands[]; /* Table of critical bands */ +extern const float sincos_t[]; /* FFT - sinus and cosinus tables */ +extern const Word16 sincos_t_fx[161]; // Q15 extern const float sincos_t_ext[]; -extern const Word16 sincos_t_ext_fx[]; +extern const Word16 sincos_t_ext_fx[]; // Q15 extern const float sincos_t_rad3[]; -extern const Word16 sincos_t_rad3_fx[]; -extern const Word16 fft256_read_indexes[]; /* FFT */ +extern const Word16 sincos_t_rad3_fx[]; // Q15 +extern const Word16 fft256_read_indexes[]; /* FFT Q0*/ extern const float inter4_2[]; /* 1/4 resolution interpolation filter */ -extern const Word16 inter4_2_fx_Q15[]; /* 1/4 resolution interpolation filter */ +extern const Word16 inter4_2_fx_Q15[]; // Q15 /* 1/4 resolution interpolation filter */ extern const Word16 inter4_2_fx[]; extern const Word16 pitch_inter4_1[UP_SAMP * L_INTERPOL1 + 1]; /*1Q14*/ extern const Word16 pitch_inter4_2[PIT_FIR_SIZE2]; /*1Q14*/ extern const float LP_assym_window[]; /* Assymetric window for LP analysis @12.8kHz */ extern const float LP_assym_window_16k[]; /* Assymetric window for LP analysis @16kHz */ -extern const Word16 Assym_window_W16fx[]; -extern const Word16 assym_window_16k_fx[]; -extern const float hamcos_window[]; /* Hamming-Cosinus window */ -extern const float grid50[]; /* Table of grid points for evaluating Chebyshev polynomials */ -extern const float grid40[]; /* Table of grid points for evaluating Chebyshev polynomials */ +extern const Word16 Assym_window_W16fx[]; // Q15 +extern const Word16 assym_window_16k_fx[]; // Q15 +extern const float hamcos_window[]; /* Hamming-Cosinus window */ +extern const float grid50[]; /* Table of grid points for evaluating Chebyshev polynomials */ +extern const float grid40[]; /* Table of grid points for evaluating Chebyshev polynomials */ #ifdef IVAS_FLOAT_FIXED -extern const Word16 grid50_fx[( GRID50_POINTS - 1 ) / 2 - 1]; -extern const Word16 grid40_fx[( GRID40_POINTS - 1 ) / 2 - 1]; -extern const Word32 crit_bands_fx[]; /* Table of critical bands */ +extern const Word16 grid50_fx[( GRID50_POINTS - 1 ) / 2 - 1]; // Q15 +extern const Word16 grid40_fx[( GRID40_POINTS - 1 ) / 2 - 1]; // Q15 +extern const Word32 crit_bands_fx[]; /* Table of critical bands Q0*/ #endif extern const float grid100[]; /* Table of 100 grid points for evaluating Chebyshev polynomials */ extern const float wind_sss[LEN_WIN_SSS]; /* window for modify_sf ana */ -extern const Word16 wind_sss_fx[LEN_WIN_SSS]; /*window for modify_sf ana*/ +extern const Word16 wind_sss_fx[LEN_WIN_SSS]; // Q15 /*window for modify_sf ana*/ extern const float filter5_39s320_120[]; /* LP FIR filter for 8kHz signal resampling */ -extern const Word16 filter5_39s320_120_fx[]; +extern const Word16 filter5_39s320_120_fx[]; // Q15 extern const float lag_window_8k_flt[17]; extern const float lag_window_12k8_flt[][17]; @@ -227,62 +227,62 @@ extern const float lag_window_16k_flt[][17]; extern const float lag_window_25k6_flt[][17]; extern const float lag_window_32k_flt[][17]; extern const float lag_window_48k_flt[17]; -extern const Word16 lag_window_8k[2][16]; -extern const Word16 lag_window_12k8[NUM_LAGW_STRENGTHS][2][16]; -extern const Word16 lag_window_16k[NUM_LAGW_STRENGTHS][2][16]; -extern const Word16 lag_window_25k6[NUM_LAGW_STRENGTHS][2][16]; -extern const Word16 lag_window_32k[NUM_LAGW_STRENGTHS][2][16]; -extern const Word16 lag_window_48k[2][16]; - -extern const Word32 lag_window_8k_32[16]; -extern const Word32 lag_window_12k8_32[NUM_LAGW_STRENGTHS][16]; -extern const Word32 lag_window_16k_32[NUM_LAGW_STRENGTHS][16]; -extern const Word32 lag_window_25k6_32[NUM_LAGW_STRENGTHS][16]; -extern const Word32 lag_window_32k_32[NUM_LAGW_STRENGTHS][16]; -extern const Word32 lag_window_48k_32[16]; -extern const float interpol_frac2[]; /* LPC interpolation coefficients for two-subframe mode */ -extern const float interpol_frac2_mid[]; /* LPC interpolation coefficients with mid-ISFs for two-subframe mode */ -extern const float interpol_frac_12k8[]; /* LPC interpolation coefficients */ -extern const Word16 interpol_frac2_fx[]; /* LPC interpolation coefficients for two-subframe mode */ -extern const Word16 interpol_frac2_mid_fx[]; /* LPC interpolation coefficients with mid-ISFs for two-subframe mode */ -extern const Word16 interpol_frac_12k8_fx[]; /* LPC interpolation coefficients */ -extern const Word16 interpol_frac_fx[NB_SUBFR]; -extern const float interpol_isp_amr_wb[]; /* LPC interpolation coefficients for AMR-WB interoperable mode */ - -extern const Word16 interpol_isp_amr_wb_fx[]; - -extern const float interpol_frac_16k[]; /* LPC interpolation coefficients @ 16kHz */ -extern const Word16 interpol_frac_16k_fx[NB_SUBFR16k]; -extern const float interpol_frac_mid[]; /* LPC interpolation coefficients with mid-ISFs */ -extern const Word16 interpol_frac_mid_fx[NB_SUBFR * 3]; -extern const float interpol_frac_mid_16k[]; /* LPC interpolation coefficients with mid-ISFs @ 16kHz */ -extern const Word16 interpol_frac_mid_16k_fx[NB_SUBFR16k * 3]; -extern const float interpol_frac_mid_relaxprev_12k8[]; /* LPC interpolation coefficients with mid-ISFs @ 16kHz - relaxed prev frame interp */ -extern const Word16 interpol_frac_mid_relaxprev_12k8_fx[NB_SUBFR * 3]; -extern const float interpol_frac_mid_FEC[]; /* LPC interpolation coefficients with mid-ISFs - FEC */ -extern const Word16 interpol_frac_mid_FEC_fx[NB_SUBFR * 3]; -extern const float interpol_frac_mid_relaxprev_16k[]; /* LPC interpolation coefficients with mid-ISFs @ 16kHz - relaxed prev frame interp */ -extern const Word16 interpol_frac_mid_relaxprev_16k_fx[NB_SUBFR16k * 3]; -extern const float interpol_frac_mid_16k_FEC[]; /* LPC interpolation coefficients with mid-ISFs @ 16kHz - FEC */ -extern const Word16 interpol_frac_mid_16k_FEC_fx[NB_SUBFR16k * 3]; +extern const Word16 lag_window_8k[2][16]; // Q15 +extern const Word16 lag_window_12k8[NUM_LAGW_STRENGTHS][2][16]; // Q15 +extern const Word16 lag_window_16k[NUM_LAGW_STRENGTHS][2][16]; // Q15 +extern const Word16 lag_window_25k6[NUM_LAGW_STRENGTHS][2][16]; // Q15 +extern const Word16 lag_window_32k[NUM_LAGW_STRENGTHS][2][16]; // Q15 +extern const Word16 lag_window_48k[2][16]; // Q15 + +extern const Word32 lag_window_8k_32[16]; // Q31 +extern const Word32 lag_window_12k8_32[NUM_LAGW_STRENGTHS][16]; // Q31 +extern const Word32 lag_window_16k_32[NUM_LAGW_STRENGTHS][16]; // Q31 +extern const Word32 lag_window_25k6_32[NUM_LAGW_STRENGTHS][16]; // Q31 +extern const Word32 lag_window_32k_32[NUM_LAGW_STRENGTHS][16]; // Q31 +extern const Word32 lag_window_48k_32[16]; // Q31 +extern const float interpol_frac2[]; /* LPC interpolation coefficients for two-subframe mode */ +extern const float interpol_frac2_mid[]; /* LPC interpolation coefficients with mid-ISFs for two-subframe mode */ +extern const float interpol_frac_12k8[]; /* LPC interpolation coefficients */ +extern const Word16 interpol_frac2_fx[]; // Q15 /* LPC interpolation coefficients for two-subframe mode */ +extern const Word16 interpol_frac2_mid_fx[]; // Q15 /* LPC interpolation coefficients with mid-ISFs for two-subframe mode */ +extern const Word16 interpol_frac_12k8_fx[]; // Q15 /* LPC interpolation coefficients */ +extern const Word16 interpol_frac_fx[NB_SUBFR]; // Q15 +extern const float interpol_isp_amr_wb[]; /* LPC interpolation coefficients for AMR-WB interoperable mode */ + +extern const Word16 interpol_isp_amr_wb_fx[]; // Q15 + +extern const float interpol_frac_16k[]; /* LPC interpolation coefficients @ 16kHz */ +extern const Word16 interpol_frac_16k_fx[NB_SUBFR16k]; // Q15 +extern const float interpol_frac_mid[]; /* LPC interpolation coefficients with mid-ISFs */ +extern const Word16 interpol_frac_mid_fx[NB_SUBFR * 3]; // Q15 +extern const float interpol_frac_mid_16k[]; /* LPC interpolation coefficients with mid-ISFs @ 16kHz */ +extern const Word16 interpol_frac_mid_16k_fx[NB_SUBFR16k * 3]; // Q15 +extern const float interpol_frac_mid_relaxprev_12k8[]; /* LPC interpolation coefficients with mid-ISFs @ 16kHz - relaxed prev frame interp */ +extern const Word16 interpol_frac_mid_relaxprev_12k8_fx[NB_SUBFR * 3]; // Q15 +extern const float interpol_frac_mid_FEC[]; /* LPC interpolation coefficients with mid-ISFs - FEC */ +extern const Word16 interpol_frac_mid_FEC_fx[NB_SUBFR * 3]; // Q15 +extern const float interpol_frac_mid_relaxprev_16k[]; /* LPC interpolation coefficients with mid-ISFs @ 16kHz - relaxed prev frame interp */ +extern const Word16 interpol_frac_mid_relaxprev_16k_fx[NB_SUBFR16k * 3]; // Q15 +extern const float interpol_frac_mid_16k_FEC[]; /* LPC interpolation coefficients with mid-ISFs @ 16kHz - FEC */ +extern const Word16 interpol_frac_mid_16k_FEC_fx[NB_SUBFR16k * 3]; // Q15 extern const float interpol_frac_mid_relaxprev_pred_12k8[]; -extern const Word16 interpol_frac_mid_relaxprev_pred_12k8_fx[NB_SUBFR * 3]; +extern const Word16 interpol_frac_mid_relaxprev_pred_12k8_fx[NB_SUBFR * 3]; // Q15 extern const float interpol_frac_mid_relaxprev_pred_16k[]; -extern const Word16 interpol_frac_mid_relaxprev_pred_16k_fx[NB_SUBFR16k * 3]; +extern const Word16 interpol_frac_mid_relaxprev_pred_16k_fx[NB_SUBFR16k * 3]; // Q15 extern const float inter6_2[PIT_FIR_SIZE6_2]; extern const Word16 pitch_inter6_2[PIT_FIR_SIZE6_2]; /*1Q14*/ extern const float inter4_2tcx2_flt[4][4]; extern const float inter6_2tcx2_flt[6][4]; -extern const Word16 inter4_2tcx2[4][4]; -extern const Word16 inter6_2tcx2[6][4]; +extern const Word16 inter4_2tcx2[4][4]; // Q15 +extern const Word16 inter6_2tcx2[6][4]; // Q15 typedef struct TCX_LTP_FILTER_FLT { const float *filt; int16_t length; } TCX_LTP_FILTER_FLT; -extern const TCX_LTP_FILTER_FLT tcxLtpFilters_flt[12]; +extern const TCX_LTP_FILTER_FLT tcxLtpFilters_flt[12]; // Q15 typedef struct TCX_LTP_FILTER { const Word16 *filt; @@ -292,37 +292,37 @@ extern const TCX_LTP_FILTER tcxLtpFilters[12]; extern const float gain_qua_mless_7b[]; /* Gain quantization - gain quantization table */ extern const float gain_qua_mless_6b_stereo[]; /* Gain quantization - gain quantization table in IVAS */ -extern const Word16 gain_qua_mless_6b_stereo_fx[]; /* Gain quantization - gain quantization table in IVAS */ +extern const Word16 gain_qua_mless_6b_stereo_fx[]; // Q14 /* Gain quantization - gain quantization table in IVAS */ extern const float gain_qua_mless_6b[]; /* Gain quantization - gain quantization table */ extern const float gain_qua_mless_5b[]; /* Gain quantization - gain quantization table */ -extern const Word16 gain_qua_mless_7b_fx[]; -extern const Word16 gain_qua_mless_6b_fx[]; -extern const Word16 gain_qua_mless_5b_fx[]; - -extern const float pred_gain[]; /* Gain quantization - MA predicition coefficients for gain quantizer */ -extern const float t_qua_gain6b[]; /* Gain quantization - gain quantization table for AMR-WB interoperable mode */ -extern const float t_qua_gain7b[]; /* Gain quantization - gain quantization table for AMR-WB interoperable mode */ -extern const Word16 pred_gain_fx[GAIN_PRED_ORDER]; -extern const Word16 t_qua_gain6b_fx[64 * 2]; -extern const Word16 t_qua_gain7b_fx[128 * 2]; - -extern const float Es_pred_qua_5b[]; /* Gain quantization - quantization table for scaled innovation energy prediciton */ -extern const float Es_pred_qua_4b[]; /* Gain quantization - quantization table for scaled innovation energy prediciton */ -extern const float Es_pred_qua_3b[]; /* Gain quantization - quantization table for scaled innovation energy prediciton */ -extern const float Es_pred_qua_4b_no_ltp[]; /* Gain quantization - quantization table for scaled innovation energy prediciton */ -extern const Word16 Es_pred_qua_5b_fx[32]; -extern const Word16 Es_pred_qua_4b_fx[16]; -extern const Word16 Es_pred_qua_3b_fx[8]; -extern const Word16 Es_pred_qua_4b_no_ltp_fx[16]; - -extern const float b_1sfr[]; /* Gain quantization - gain estimation constants for gain quantizer at 7.2 and 8.0 kbps */ -extern const float b_2sfr[]; /* Gain quantization - gain estimation constants for gain quantizer at 7.2 and 8.0 kbps */ -extern const float b_3sfr[]; /* Gain quantization - gain estimation constants for gain quantizer at 7.2 and 8.0 kbps */ -extern const float b_4sfr[]; /* Gain quantization - gain estimation constants for gain quantizer at 7.2 and 8.0 kbps */ -extern const Word16 b_1sfr_fx[]; -extern const Word16 b_2sfr_fx[]; -extern const Word16 b_3sfr_fx[]; -extern const Word16 b_4sfr_fx[]; +extern const Word16 gain_qua_mless_7b_fx[]; // Q14 +extern const Word16 gain_qua_mless_6b_fx[]; // Q14 +extern const Word16 gain_qua_mless_5b_fx[]; // Q14 + +extern const float pred_gain[]; /* Gain quantization - MA predicition coefficients for gain quantizer */ +extern const float t_qua_gain6b[]; /* Gain quantization - gain quantization table for AMR-WB interoperable mode */ +extern const float t_qua_gain7b[]; /* Gain quantization - gain quantization table for AMR-WB interoperable mode */ +extern const Word16 pred_gain_fx[GAIN_PRED_ORDER]; // Q14 +extern const Word16 t_qua_gain6b_fx[64 * 2]; // Q14 +extern const Word16 t_qua_gain7b_fx[128 * 2]; // Q14 + +extern const float Es_pred_qua_5b[]; /* Gain quantization - quantization table for scaled innovation energy prediciton */ +extern const float Es_pred_qua_4b[]; /* Gain quantization - quantization table for scaled innovation energy prediciton */ +extern const float Es_pred_qua_3b[]; /* Gain quantization - quantization table for scaled innovation energy prediciton */ +extern const float Es_pred_qua_4b_no_ltp[]; /* Gain quantization - quantization table for scaled innovation energy prediciton */ +extern const Word16 Es_pred_qua_5b_fx[32]; // Q8 +extern const Word16 Es_pred_qua_4b_fx[16]; // Q8 +extern const Word16 Es_pred_qua_3b_fx[8]; // Q8 +extern const Word16 Es_pred_qua_4b_no_ltp_fx[16]; // Q8 + +extern const float b_1sfr[]; /* Gain quantization - gain estimation constants for gain quantizer at 7.2 and 8.0 kbps */ +extern const float b_2sfr[]; /* Gain quantization - gain estimation constants for gain quantizer at 7.2 and 8.0 kbps */ +extern const float b_3sfr[]; /* Gain quantization - gain estimation constants for gain quantizer at 7.2 and 8.0 kbps */ +extern const float b_4sfr[]; /* Gain quantization - gain estimation constants for gain quantizer at 7.2 and 8.0 kbps */ +extern const Word16 b_1sfr_fx[]; // Q12 +extern const Word16 b_2sfr_fx[]; // Q12 +extern const Word16 b_3sfr_fx[]; // Q12 +extern const Word16 b_4sfr_fx[]; // Q12 extern const float gp_gamma_1sfr_8b[]; /* Gain quantization - gain quantization table for gain quantizer at 7.2 and 8.0 kbps */ @@ -337,15 +337,15 @@ extern const float gp_gamma_2sfr_6b[]; /* Gain quantization - gain quantization extern const float gp_gamma_3sfr_6b[]; /* Gain quantization - gain quantization table for gain quantizer at 7.2 and 8.0 kbps */ extern const float gp_gamma_4sfr_6b[]; /* Gain quantization - gain quantization table for gain quantizer at 7.2 and 8.0 kbps */ -extern const Word16 gp_gamma_1sfr_8b_fx[]; -extern const Word16 gp_gamma_1sfr_7b_fx[]; -extern const Word16 gp_gamma_1sfr_6b_fx[]; -extern const Word16 gp_gamma_2sfr_7b_fx[]; -extern const Word16 gp_gamma_4sfr_7b_fx[]; -extern const Word16 gp_gamma_2sfr_6b_fx[]; -extern const Word16 gp_gamma_3sfr_7b_fx[]; -extern const Word16 gp_gamma_3sfr_6b_fx[]; -extern const Word16 gp_gamma_4sfr_6b_fx[]; +extern const Word16 gp_gamma_1sfr_8b_fx[]; // Q14/Q9 +extern const Word16 gp_gamma_1sfr_7b_fx[]; // Q14/Q9 +extern const Word16 gp_gamma_1sfr_6b_fx[]; // Q14/Q9 +extern const Word16 gp_gamma_2sfr_7b_fx[]; // Q14/Q9 +extern const Word16 gp_gamma_4sfr_7b_fx[]; // Q14/Q9 +extern const Word16 gp_gamma_2sfr_6b_fx[]; // Q14/Q9 +extern const Word16 gp_gamma_3sfr_7b_fx[]; // Q14/Q9 +extern const Word16 gp_gamma_3sfr_6b_fx[]; // Q14/Q9 +extern const Word16 gp_gamma_4sfr_6b_fx[]; // Q14/Q9 extern const int16_t E_ROM_qua_gain5b_const[]; @@ -354,59 +354,59 @@ extern const int16_t E_ROM_qua_gain7b_const[]; extern const float gain_qua_mless[]; -extern const float tbl_gain_code_tc[]; /* TC - code gain quantization table */ -extern const Word16 tbl_gain_code_tc_fx[N_GAIN_CODE_TC]; -extern const Word16 tbl_gain_code_tc_quant_mean[N_GAIN_CODE_TC - 1]; +extern const float tbl_gain_code_tc[]; /* TC - code gain quantization table */ +extern const Word16 tbl_gain_code_tc_fx[N_GAIN_CODE_TC]; // Q13 +extern const Word16 tbl_gain_code_tc_quant_mean[N_GAIN_CODE_TC - 1]; // Q13 -extern const float tbl_gain_trans_tc[]; /* TC - gain quantization table for g_trans */ -extern const float glottal_cdbk[]; /* TC - table of prototype glottal impulses */ -extern const Word16 tbl_gain_trans_tc_fx[]; -extern const Word16 Glottal_cdbk_fx[]; +extern const float tbl_gain_trans_tc[]; /* TC - gain quantization table for g_trans */ +extern const float glottal_cdbk[]; /* TC - table of prototype glottal impulses */ +extern const Word16 tbl_gain_trans_tc_fx[]; // Q7/Q4 +extern const Word16 Glottal_cdbk_fx[]; // Q13 -extern const int32_t PI_select_table[23][8]; /* selection table for Pulse indexing */ -extern const int32_t PI_offset[8][8]; /* offset table for Pulse indexing */ -extern const int16_t PI_factor[]; /* EVS_PI factor table for Pulse indexing */ +extern const Word32 PI_select_table[23][8]; /* selection table for Pulse indexing Q0*/ +extern const int32_t PI_offset[8][8]; /* offset table for Pulse indexing Q0*/ +extern const Word16 PI_factor[]; /* EVS_PI factor table for Pulse indexing Q0*/ /* ACELP pulse coding */ -extern const Word16 hi_to_low_tmpl[10]; -extern const uint16_t low_len[10]; -extern const uint16_t low_mask[10]; -extern const uint16_t indx_fact[10]; -extern const int16_t index_len[3]; -extern const int16_t index_mask_ACELP[3]; +extern const Word16 hi_to_low_tmpl[10]; // Q0 +extern const uint16_t low_len[10]; // Q0 +extern const uint16_t low_mask[10]; // Q0 +extern const uint16_t indx_fact[10]; // Q0 +extern const int16_t index_len[3]; // Q0 +extern const int16_t index_mask_ACELP[3]; // Q0 -extern const float deem_tab[]; /* HF BWE - de-emphasis coefficients */ -extern const Word16 deem_tab_fx[]; +extern const float deem_tab[]; /* HF BWE - de-emphasis coefficients */ +extern const Word16 deem_tab_fx[]; // Q15 extern const float filt_hp[]; -extern const Word16 filt_hp_fx[]; -extern const float exp_tab_p[]; /* HF BWE - Table of values exp(-j*w*i) */ -extern const Word16 exp_tab_p_fx[]; -extern const float exp_tab_q[]; /* HF BWE - Table of values exp(-j*w*i) */ -extern const Word16 exp_tab_q_fx[]; -extern const float HP_gain[]; /* HF BWE - quantization table for 23.85 */ -extern const Word16 HP_gain_fx[]; -extern const float fir_6k_8k[]; /* HF BWE - band-pass filter coefficients */ - -extern const float b_hp400[]; /* HF (6-7kHz) BWE - 400Hz HP filter coefficients */ -extern const float a_hp400[]; /* HF (6-7kHz) BWE - 400Hz HP filter coefficients */ -extern const float fir_6k_7k[]; /* HF (6-7kHz) BWE - 6.0 - 7.0 kHz BP filter coefficients */ -extern const Word16 fir_6k_7k_fx[]; - -extern const Word16 no_lead_fx[][MAX_NO_SCALES * 2]; -extern const Word16 no_lead_p_fx[][MAX_NO_SCALES * 2]; - -extern const float low_H_flt[]; /* Enhacer - 2.0 - 6.4 kHz impulse response with phase dispersion */ -extern const float mid_H_flt[]; /* Enhancer - 3.2 - 6.4 kHz impulse response with phase dispersion */ -extern const Word16 low_H[64]; -extern const Word16 low_H16k[80]; -extern const Word16 mid_H[64]; -extern const Word16 mid_H16k[80]; +extern const Word16 filt_hp_fx[]; // Q15 +extern const float exp_tab_p[]; /* HF BWE - Table of values exp(-j*w*i) */ +extern const Word16 exp_tab_p_fx[]; // Q14 +extern const float exp_tab_q[]; /* HF BWE - Table of values exp(-j*w*i) */ +extern const Word16 exp_tab_q_fx[]; // Q14 +extern const float HP_gain[]; /* HF BWE - quantization table for 23.85 */ +extern const Word16 HP_gain_fx[]; // Q15 +extern const float fir_6k_8k[]; /* HF BWE - band-pass filter coefficients */ + +extern const float b_hp400[]; /* HF (6-7kHz) BWE - 400Hz HP filter coefficients */ +extern const float a_hp400[]; /* HF (6-7kHz) BWE - 400Hz HP filter coefficients */ +extern const float fir_6k_7k[]; /* HF (6-7kHz) BWE - 6.0 - 7.0 kHz BP filter coefficients */ +extern const Word16 fir_6k_7k_fx[]; // Q15 + +extern const Word16 no_lead_fx[][MAX_NO_SCALES * 2]; // Q0 +extern const Word16 no_lead_p_fx[][MAX_NO_SCALES * 2]; // Q0 + +extern const float low_H_flt[]; /* Enhacer - 2.0 - 6.4 kHz impulse response with phase dispersion */ +extern const float mid_H_flt[]; /* Enhancer - 3.2 - 6.4 kHz impulse response with phase dispersion */ +extern const Word16 low_H[64]; // Q14 +extern const Word16 low_H16k[80]; // Q14 +extern const Word16 mid_H[64]; // Q14 +extern const Word16 mid_H16k[80]; // Q14 extern const float filt_lp[1 + L_FILT]; -extern const Word16 filt_lp_fx[1 + L_FILT]; +extern const Word16 filt_lp_fx[1 + L_FILT]; // Q15 extern const float filt_lp_16kHz[1 + L_FILT16k]; -extern const Word16 filt_lp_16kHz_fx[1 + L_FILT16k]; +extern const Word16 filt_lp_16kHz_fx[1 + L_FILT16k]; // Q15 extern const float tab_hup_l[SIZ_TAB_HUP_L]; /* NB post-filter */ extern const float tab_hup_s[SIZ_TAB_HUP_S]; /* NB post-filter */ @@ -425,80 +425,80 @@ extern const float edct_table_200[]; extern const float edct_table_240[]; extern const float edct_table_256[]; extern const float edct_table_400[]; -extern const float edct_table_600[]; /* EDCT */ -extern const Word16 edct_table_80_fx[]; /* EDCT */ -extern const Word16 edct_table_120_fx[]; /* EDCT */ -extern const Word16 edct_table_100_fx[]; /* EDCT */ -extern const Word16 edct_table_320_fx[]; /* EDCT */ -extern const Word16 edct_table_480_fx[]; /* EDCT */ -extern const Word16 edct_table_600_fx[]; /* EDCT */ -extern const Word16 edct_table_128_fx[]; /* EDCT */ -extern const Word16 edct_table_160_fx[]; /* EDCT */ -extern const Word16 edct_table_40_fx[]; /* EDCT */ -extern const Word16 edct_table_20_fx[]; /* EDCT */ -extern const Word16 edct_table_64_fx[]; -extern const Word16 edct_table_200_fx[]; -extern const Word16 edct_table_240_fx[]; -extern const Word16 edct_table_256_fx[]; -extern const Word16 edct_table_400_fx[]; -extern const Word16 edct_table_160_16fx[160]; -extern const Word16 edct_table_128_16fx[128]; -extern const Word16 edct_table_320_16fx[320]; +extern const float edct_table_600[]; /* EDCT */ +extern const Word16 edct_table_80_fx[]; // Q16 /* EDCT */ +extern const Word16 edct_table_120_fx[]; // Q16 /* EDCT */ +extern const Word16 edct_table_100_fx[]; // Q16 /* EDCT */ +extern const Word16 edct_table_320_fx[]; // Q16 /* EDCT */ +extern const Word16 edct_table_480_fx[]; // Q16 /* EDCT */ +extern const Word16 edct_table_600_fx[]; // Q16 /* EDCT */ +extern const Word16 edct_table_128_fx[]; // Q16 /* EDCT */ +extern const Word16 edct_table_160_fx[]; // Q16 /* EDCT */ +extern const Word16 edct_table_40_fx[]; // Q16 /* EDCT */ +extern const Word16 edct_table_20_fx[]; // Q16 /* EDCT */ +extern const Word16 edct_table_64_fx[]; // Q16 +extern const Word16 edct_table_200_fx[]; // Q16 +extern const Word16 edct_table_240_fx[]; // Q16 +extern const Word16 edct_table_256_fx[]; // Q16 +extern const Word16 edct_table_400_fx[]; // Q16 +extern const Word16 edct_table_160_16fx[160]; // Q15 +extern const Word16 edct_table_128_16fx[128]; // Q15 +extern const Word16 edct_table_320_16fx[320]; // Q16 extern const int16_t crit_bins[]; /* (used only in AMR-WB IO mode) */ extern const float crit_bins_corr[CRIT_NOIS_BAND]; -extern const Word16 crit_bins_corr_fx[]; -extern const float crit_bands_loc[]; /* (used only in AMR-WB IO mode) */ -extern const Word16 crit_bands_loc_fx[]; -extern const float mfreq_loc_LD[]; /* LD music post-filter */ -extern const Word16 mfreq_loc_LD_fx[]; -extern const int16_t mfreq_bindiv_LD[]; +extern const Word16 crit_bins_corr_fx[]; // Q15 +extern const float crit_bands_loc[]; /* (used only in AMR-WB IO mode) */ +extern const Word16 crit_bands_loc_fx[]; // Q0 +extern const float mfreq_loc_LD[]; /* LD music post-filter */ +extern const Word16 mfreq_loc_LD_fx[]; // Q0 +extern const Word16 mfreq_bindiv_LD[]; // Q0 extern const float post_dct_wind[OFFSET2]; -extern const Word16 post_dct_wind_fx[]; +extern const Word16 post_dct_wind_fx[]; // Q15 extern const float MAX_SNR_SNR1_tab[]; extern const float INV_MAX_SNR_tab[]; -extern const Word16 MAX_SNR_SNR1_tab_FX[MBANDS_GN_LD]; -extern const Word16 INV_MAX_SNR_tab_FX[MBANDS_GN_LD]; +extern const Word16 MAX_SNR_SNR1_tab_FX[MBANDS_GN_LD]; // Q14 +extern const Word16 INV_MAX_SNR_tab_FX[MBANDS_GN_LD]; // Q15 extern const float sc_qnoise[]; -extern const Word16 sc_qnoise_fx[]; -extern const Word16 inv_mfreq_bindiv_LD_fx[]; -extern const Word16 inv_mfreq_bindiv_LD_M1_fx[]; +extern const Word16 sc_qnoise_fx[]; // Q15 +extern const Word16 inv_mfreq_bindiv_LD_fx[]; // Q15 +extern const Word16 inv_mfreq_bindiv_LD_M1_fx[]; // Q15 extern const float W_DTX_HO[HO_HIST_SIZE]; -extern const Word16 W_DTX_HO_FX[HO_HIST_SIZE]; +extern const Word16 W_DTX_HO_FX[HO_HIST_SIZE]; // Q15 extern const float ENR_ATT[5]; -extern const Word16 ENR_ATT_fx[5]; +extern const Word16 ENR_ATT_fx[5]; // Q8 extern const float HO_ATT[5]; -extern const Word16 HO_ATT_FX[5]; +extern const Word16 HO_ATT_FX[5]; // Q15 -extern const int16_t hq_swb_bwe_nb_bits[]; +extern const Word16 hq_swb_bwe_nb_bits[]; // Q0 /*----------------------------------------------------------------------------------* * ISF quantization (AMR-WB IO mode) *----------------------------------------------------------------------------------*/ -extern const Word16 Indirect_dico1[SIZE_BK1]; +extern const Word16 Indirect_dico1[SIZE_BK1]; // Q0 extern const float mean_isf_amr_wb[M]; /* Mean ISF vector (only in AMR-WB IO mode) */ -extern const Word16 mean_isf_amr_wb_fx[M]; /* Mean ISF vector (only in AMR-WB IO mode) */ +extern const Word16 mean_isf_amr_wb_fx[M]; /*Qlog2(2.56)*/ /* Mean ISF vector (only in AMR-WB IO mode) */ extern const float mean_isf_noise_amr_wb[]; /* Mean ISF vector for SID frame (only in AMR-WB IO mode) */ -extern const Word16 mean_isf_noise_amr_wb_fx[]; /* Mean ISF vector for SID frame (only in AMR-WB IO mode) */ +extern const Word16 mean_isf_noise_amr_wb_fx[]; /*Qlog2(2.56)*/ /* Mean ISF vector for SID frame (only in AMR-WB IO mode) */ -extern const float gaus_dico[]; /* Gaussian codebook */ -extern const Word16 gaus_dico_fx[]; -extern const float gaus_dico_swb[]; /* Gaussian codebook for SWB TBE */ -extern const Word16 gaus_dico_swb_fx[]; +extern const float gaus_dico[]; /* Gaussian codebook */ +extern const Word16 gaus_dico_fx[]; // Q12 +extern const float gaus_dico_swb[]; /* Gaussian codebook for SWB TBE */ +extern const Word16 gaus_dico_swb_fx[]; // Q15 extern const float dico1_isf[]; /* ISF codebook - common 1st stage, 1st split (only in AMR-WB IO mode) */ -extern const Word16 dico1_isf_fx[]; /* ISF codebook - common 1st stage, 1st split (only in AMR-WB IO mode) */ +extern const Word16 dico1_isf_fx[]; /* ISF codebook - common 1st stage, 1st split (only in AMR-WB IO mode) Qlog2(2.56)*/ extern const float dico2_isf[]; /* ISF codebook - common 1st stage, 2nd split (only in AMR-WB IO mode) */ -extern const Word16 dico2_isf_fx[]; /* ISF codebook - common 1st stage, 2nd split (only in AMR-WB IO mode) */ +extern const Word16 dico2_isf_fx[]; /* ISF codebook - common 1st stage, 2nd split (only in AMR-WB IO mode) Qlog2(2.56)*/ extern const float dico21_isf_46b[]; /* ISF codebook - 46b, 2nd stage, 1st split (only in AMR-WB IO mode) */ extern const float dico22_isf_46b[]; /* ISF codebook - 46b, 2nd stage, 2st split (only in AMR-WB IO mode) */ @@ -506,23 +506,23 @@ extern const float dico23_isf_46b[]; /* ISF codebook - 46b, 2nd stage, 3rd split extern const float dico24_isf_46b[]; /* ISF codebook - 46b, 2nd stage, 4th split (only in AMR-WB IO mode) */ extern const float dico25_isf_46b[]; /* ISF codebook - 46b, 2nd stage, 5th split (only in AMR-WB IO mode) */ -extern const Word16 dico21_isf_46b_fx[]; /* ISF codebook - 46b, 2nd stage, 1st split (only in AMR-WB IO mode) */ -extern const Word16 dico22_isf_46b_fx[]; /* ISF codebook - 46b, 2nd stage, 2st split (only in AMR-WB IO mode) */ -extern const Word16 dico23_isf_46b_fx[]; /* ISF codebook - 46b, 2nd stage, 3rd split (only in AMR-WB IO mode) */ -extern const Word16 dico24_isf_46b_fx[]; /* ISF codebook - 46b, 2nd stage, 4th split (only in AMR-WB IO mode) */ -extern const Word16 dico25_isf_46b_fx[]; /* ISF codebook - 46b, 2nd stage, 5th split (only in AMR-WB IO mode) */ +extern const Word16 dico21_isf_46b_fx[]; /* ISF codebook - 46b, 2nd stage, 1st split (only in AMR-WB IO mode) Qlog2(2.56)*/ +extern const Word16 dico22_isf_46b_fx[]; /* ISF codebook - 46b, 2nd stage, 2st split (only in AMR-WB IO mode) Qlog2(2.56)*/ +extern const Word16 dico23_isf_46b_fx[]; /* ISF codebook - 46b, 2nd stage, 3rd split (only in AMR-WB IO mode) Qlog2(2.56)*/ +extern const Word16 dico24_isf_46b_fx[]; /* ISF codebook - 46b, 2nd stage, 4th split (only in AMR-WB IO mode) Qlog2(2.56)*/ +extern const Word16 dico25_isf_46b_fx[]; /* ISF codebook - 46b, 2nd stage, 5th split (only in AMR-WB IO mode) Qlog2(2.56)*/ extern const float dico21_isf_36b[]; /* ISF codebook - 36b, 2nd stage, 1st split (only in AMR-WB IO mode) */ -extern const Word16 dico21_isf_36b_fx[]; /* ISF codebook - 36b, 2nd stage, 1st split (only in AMR-WB IO mode) */ +extern const Word16 dico21_isf_36b_fx[]; /* ISF codebook - 36b, 2nd stage, 1st split (only in AMR-WB IO mode) Qlog2(2.56)*/ extern const float dico22_isf_36b[]; /* ISF codebook - 36b, 2nd stage, 2nd split (only in AMR-WB IO mode) */ -extern const Word16 dico22_isf_36b_fx[]; /* ISF codebook - 36b, 2nd stage, 2nd split (only in AMR-WB IO mode) */ +extern const Word16 dico22_isf_36b_fx[]; /* ISF codebook - 36b, 2nd stage, 2nd split (only in AMR-WB IO mode) Qlog2(2.56)*/ extern const float dico23_isf_36b[]; /* ISF codebook - 36b, 2nd stage, 3rd split (only in AMR-WB IO mode) */ -extern const Word16 dico23_isf_36b_fx[]; /* ISF codebook - 36b, 2nd stage, 3rd split (only in AMR-WB IO mode) */ +extern const Word16 dico23_isf_36b_fx[]; /* ISF codebook - 36b, 2nd stage, 3rd split (only in AMR-WB IO mode) Qlog2(2.56)*/ extern const float dico1_ns_28b[]; /* ISF codebook for SID frames - 28b, 1st split */ extern const float dico2_ns_28b[]; /* ISF codebook for SID frames - 28b, 2nd spilt */ @@ -530,11 +530,11 @@ extern const float dico3_ns_28b[]; /* ISF codebook for SID frames - 28b, 3rd spi extern const float dico4_ns_28b[]; /* ISF codebook for SID frames - 28b, 4th spilt */ extern const float dico5_ns_28b[]; /* ISF codebook for SID frames - 28b, 5th spilt */ -extern const Word16 dico1_ns_28b_fx[]; /* ISF codebook for SID frames - 28b, 1st split */ -extern const Word16 dico2_ns_28b_fx[]; /* ISF codebook for SID frames - 28b, 2nd spilt */ -extern const Word16 dico3_ns_28b_fx[]; /* ISF codebook for SID frames - 28b, 3rd spilt */ -extern const Word16 dico4_ns_28b_fx[]; /* ISF codebook for SID frames - 28b, 4th spilt */ -extern const Word16 dico5_ns_28b_fx[]; /* ISF codebook for SID frames - 28b, 5th spilt */ +extern const Word16 dico1_ns_28b_fx[]; /*Qlog2(2.56)*/ /* ISF codebook for SID frames - 28b, 1st split Qlog2(2.56)*/ +extern const Word16 dico2_ns_28b_fx[]; /*Qlog2(2.56)*/ /* ISF codebook for SID frames - 28b, 2nd spilt Qlog2(2.56)*/ +extern const Word16 dico3_ns_28b_fx[]; /*Qlog2(2.56)*/ /* ISF codebook for SID frames - 28b, 3rd spilt Qlog2(2.56)*/ +extern const Word16 dico4_ns_28b_fx[]; /*Qlog2(2.56)*/ /* ISF codebook for SID frames - 28b, 4th spilt Qlog2(2.56)*/ +extern const Word16 dico5_ns_28b_fx[]; /*Qlog2(2.56)*/ /* ISF codebook for SID frames - 28b, 5th spilt Qlog2(2.56)*/ extern const float dico1_cng_ev[]; extern const float dico2_cng_ev[]; @@ -549,9 +549,9 @@ extern const float dico5_cng_ev[]; extern const float stable_ISP[]; extern const float stable_LSP[]; extern const float stable_ISF[]; -extern const Word16 stable_ISP_fx[]; -extern const Word16 stable_ISF_fx[]; -extern const Word16 stable_LSP_fx[]; +extern const Word16 stable_ISP_fx[]; /*Q15*/ +extern const Word16 stable_ISF_fx[]; /*15Q16*/ +extern const Word16 stable_LSP_fx[]; /*Q15*/ extern const float UVWB_Ave[]; extern const float UVNB_Ave[]; @@ -564,25 +564,25 @@ extern const float GEWB_Ave[]; extern const float GEWB2_Ave[]; extern const float TRWB_Ave[]; extern const float TRWB2_Ave[]; -extern const Word16 UVWB_Ave_fx[]; -extern const Word16 UVNB_Ave_fx[]; -extern const Word16 SVWB_Ave_fx[]; -extern const Word16 SVNB_Ave_fx[]; -extern const Word16 IANB_Ave_fx[]; -extern const Word16 IAWB_Ave_fx[]; -extern const Word16 IAWB2_Ave_fx[]; -extern const Word16 GENB_Ave_fx[]; -extern const Word16 GEWB_Ave_fx[]; -extern const Word16 GEWB2_Ave_fx[]; -extern const Word16 TRWB_Ave_fx[]; -extern const Word16 TRWB2_Ave_fx[]; +extern const Word16 UVWB_Ave_fx[]; // Qlog2(2.56) +extern const Word16 UVNB_Ave_fx[]; // Qlog2(2.56) +extern const Word16 SVWB_Ave_fx[]; // Qlog2(2.56) +extern const Word16 SVNB_Ave_fx[]; // Qlog2(2.56) +extern const Word16 IANB_Ave_fx[]; // Qlog2(2.56) +extern const Word16 IAWB_Ave_fx[]; // Qlog2(2.56) +extern const Word16 IAWB2_Ave_fx[]; // Qlog2(2.56) +extern const Word16 GENB_Ave_fx[]; // Qlog2(2.56) +extern const Word16 GEWB_Ave_fx[]; // Qlog2(2.56) +extern const Word16 GEWB2_Ave_fx[]; // Qlog2(2.56) +extern const Word16 TRWB_Ave_fx[]; // Qlog2(2.56) +extern const Word16 TRWB2_Ave_fx[]; // Qlog2(2.56) extern const float means_wb_cleanspeech_lsf16k0_flt[]; extern const float means_swb_cleanspeech_lsf25k6_flt[]; extern const float means_swb_cleanspeech_lsf32k0_flt[]; -extern const Word16 means_wb_cleanspeech_lsf16k0[]; -extern const Word16 means_swb_cleanspeech_lsf25k6[]; -extern const Word16 means_swb_cleanspeech_lsf32k0[]; +extern const Word16 means_wb_cleanspeech_lsf16k0[]; // Qlog2(2.56) +extern const Word16 means_swb_cleanspeech_lsf25k6[]; // Qlog2(2.56) +extern const Word16 means_swb_cleanspeech_lsf32k0[]; // Qlog2(2.56) extern const float ModeMean12[]; extern const float Predictor0[]; @@ -594,143 +594,143 @@ extern const float Predictor5[]; extern const float Predictor6[]; extern const float Predictor7[]; extern const float Predictor8[]; -extern const Word16 Predictor0_fx[]; -extern const Word16 Predictor1_fx[]; -extern const Word16 Predictor2_fx[]; -extern const Word16 Predictor3_fx[]; -extern const Word16 Predictor4_fx[]; -extern const Word16 Predictor5_fx[]; -extern const Word16 Predictor6_fx[]; -extern const Word16 Predictor7_fx[]; -extern const Word16 Predictor8_fx[]; +extern const Word16 Predictor0_fx[]; // Q15 +extern const Word16 Predictor1_fx[]; // Q15 +extern const Word16 Predictor2_fx[]; // Q15 +extern const Word16 Predictor3_fx[]; // Q15 +extern const Word16 Predictor4_fx[]; // Q15 +extern const Word16 Predictor5_fx[]; // Q15 +extern const Word16 Predictor6_fx[]; // Q15 +extern const Word16 Predictor7_fx[]; // Q15 +extern const Word16 Predictor8_fx[]; // Q15 extern const float CNG_SN1[]; -extern const Word16 CNG_SN1_fx[]; -extern const int16_t CB_lsf[]; -extern const int16_t CB_p_lsf[]; +extern const Word16 CNG_SN1_fx[]; // Qlog2(2.56) +extern const Word16 CB_lsf[]; // Q0 +extern const Word16 CB_p_lsf[]; // Q0 extern const float *const ModeMeans[]; extern const float *const Predictors[]; -extern const Word16 *const ModeMeans_fx[]; -extern const Word16 *const Predictors_fx[]; -extern const int16_t CBsizes[]; -extern const int16_t CBbits[]; +extern const Word16 *const ModeMeans_fx[]; // Qlog2(2.56) +extern const Word16 *const Predictors_fx[]; // Q15 +extern const Word16 CBsizes[]; // Q0 +extern const Word16 CBbits[]; // Q0 -extern const int16_t CBbits_p[]; +extern const Word16 CBbits_p[]; // Q0 extern const float vals[NO_LEADERS][MAX_NO_VALS]; -extern const Word16 vals_fx[NO_LEADERS][MAX_NO_VALS]; +extern const Word16 vals_fx[NO_LEADERS][MAX_NO_VALS]; // Q1 -extern const int16_t no_vals[NO_LEADERS]; +extern const Word16 no_vals[NO_LEADERS]; // Q0 // extern const Word16 no_vals_fx[NO_LEADERS]; -extern const int16_t no_vals_ind[NO_LEADERS][MAX_NO_VALS]; +extern const Word16 no_vals_ind[NO_LEADERS][MAX_NO_VALS]; // Q0 // extern const Word16 no_vals_ind_fx[NO_LEADERS][MAX_NO_VALS]; -extern const int16_t C_VQ[LATTICE_DIM + 1][LATTICE_DIM + 1]; +extern const Word16 C_VQ[LATTICE_DIM + 1][LATTICE_DIM + 1]; // Q0 // extern const Word16 C_VQ_fx[LATTICE_DIM + 1][LATTICE_DIM + 1]; -extern const int16_t BitsVQ[]; -extern const int16_t BitsVQ_p[]; -extern const UWord8 no_lead_idx[][2]; -extern const UWord8 no_lead_p_idx[][2]; -extern const Word8 leaders_short[][MAX_NO_SCALES]; +extern const Word16 BitsVQ[]; // Q0 +extern const Word16 BitsVQ_p[]; // Q0 +extern const UWord8 no_lead_idx[][2]; // Q0 +extern const UWord8 no_lead_p_idx[][2]; // Q0 +extern const Word8 leaders_short[][MAX_NO_SCALES]; // Q0 extern const float sigma_MSLVQ[][16]; -extern const Word16 sigma_MSLVQ_fx[][16]; +extern const Word16 sigma_MSLVQ_fx[][16]; // Qlog2(2.56) extern const float sigma_p[][16]; -extern const Word16 sigma_p_fx[][16]; -extern const Word16 sigma_p_ivas_fx[][16]; +extern const Word16 sigma_p_fx[][16]; // Qlog2(2.56) +extern const Word16 sigma_p_ivas_fx[][16]; // Qlog2(2.56) extern const float inv_sigma_MSLVQ[][16]; -extern const Word16 inv_sigma_MSLVQ_fx[][16]; +extern const Word16 inv_sigma_MSLVQ_fx[][16]; // Q15 extern const float inv_sigma_p[][16]; -extern const Word16 inv_sigma_p_fx[][16]; -extern const Word16 inv_sigma_p_ivas_fx[][16]; +extern const Word16 inv_sigma_p_fx[][16]; // Q15 +extern const Word16 inv_sigma_p_ivas_fx[][16]; // Qlog2(2.56) extern const float scales[][MAX_NO_SCALES * 2]; extern const float scales_p[][MAX_NO_SCALES * 2]; -extern const Word16 scales_fx[][MAX_NO_SCALES * 2]; -extern const Word16 scales_ivas_fx[][MAX_NO_SCALES * 2]; -extern const Word16 scales_p_ivas_fx[][MAX_NO_SCALES * 2]; -extern const Word16 scales_p_fx[][MAX_NO_SCALES * 2]; +extern const Word16 scales_fx[][MAX_NO_SCALES * 2]; // Q11 +extern const Word16 scales_ivas_fx[][MAX_NO_SCALES * 2]; // Q11 +extern const Word16 scales_p_ivas_fx[][MAX_NO_SCALES * 2]; // Q11 +extern const Word16 scales_p_fx[][MAX_NO_SCALES * 2]; // Q11 extern const int16_t predmode_tab_float[][6]; -extern const Word16 predmode_tab[][6]; +extern const Word16 predmode_tab[][6]; // Q0 extern const float pl_HQ[]; -extern const Word16 pl_HQ_fx[]; +extern const Word16 pl_HQ_fx[]; // Q1 -extern const int16_t pi0[]; +extern const Word16 pi0[]; // Q0 // extern const Word16 pi0_fx[]; -extern const UWord32 table_no_cv[]; -extern const Word32 table_no_cv_fx[]; +extern const UWord32 table_no_cv[]; // Q0 +extern const Word32 table_no_cv_fx[]; // Q0 -extern const int16_t pl_par[]; +extern const Word16 pl_par[]; // Q0 // extern const Word16 pl_par_fx[]; /* 1 if even number of signs */ extern const float *const Quantizers[]; extern const float *const Quantizers_p[]; -extern const Word16 *const Quantizers_p_fx[]; -extern const Word16 *const Quantizers_fx[]; +extern const Word16 *const Quantizers_p_fx[]; // Qlog2(2.56) +extern const Word16 *const Quantizers_fx[]; // Qlog2(2.56) -extern const int16_t cng_sort[]; +extern const Word16 cng_sort[]; // Q0 // extern const Word16 cng_sort_fx[]; -extern const int16_t perm_MSLVQ[][4]; +extern const Word16 perm_MSLVQ[][4]; // Q0 // extern const Word16 perm_MSLVQ_fx[][4]; extern const int16_t min_lat_bits_SN[]; -extern const Word16 min_lat_bits_SN_fx[]; +extern const Word16 min_lat_bits_SN_fx[]; // Q0 extern const int16_t min_lat_bits_pred[]; -extern const Word16 min_lat_bits_pred_fx[]; +extern const Word16 min_lat_bits_pred_fx[]; // Q0 extern const int16_t offset_in_lvq_mode_SN[][21]; -extern const Word16 offset_in_lvq_mode_SN_fx[][21]; +extern const Word16 offset_in_lvq_mode_SN_fx[][21]; // Q0 extern const int16_t offset_in_lvq_mode_pred[][32]; -extern const Word16 offset_in_lvq_mode_pred_fx[][32]; +extern const Word16 offset_in_lvq_mode_pred_fx[][32]; // Q0 extern const int16_t offset_lvq_modes_SN[]; -extern const Word16 offset_lvq_modes_SN_fx[]; +extern const Word16 offset_lvq_modes_SN_fx[]; // Q0 extern const int16_t offset_lvq_modes_pred[]; -extern const Word16 offset_lvq_modes_pred_fx[]; +extern const Word16 offset_lvq_modes_pred_fx[]; // Qlog2(1.6) /*-----------------------------------------------------------------* * LSF quantization - BC-TCVQ tables *-----------------------------------------------------------------*/ -extern const int16_t FixBranch_tbl[4][4][N_STAGE_VQ - 4]; +extern const Word16 FixBranch_tbl[4][4][N_STAGE_VQ - 4]; // Q0 -extern const int16_t BC_TCVQ_BIT_ALLOC_40B[]; +extern const Word16 BC_TCVQ_BIT_ALLOC_40B[]; // Q0 -extern const int16_t NTRANS[4][16]; -extern const int16_t NTRANS2[4][16]; +extern const Word16 NTRANS[4][16]; // Q0 +extern const Word16 NTRANS2[4][16]; // Q0 extern const float AR_IntraCoeff[N_STAGE_VQ - 1][2][2]; extern const float SN_IntraCoeff[N_STAGE_VQ - 1][2][2]; -extern const Word16 AR_IntraCoeff_fx[N_STAGE_VQ - 1][2][2]; -extern const Word16 SN_IntraCoeff_fx[N_STAGE_VQ - 1][2][2]; +extern const Word16 AR_IntraCoeff_fx[N_STAGE_VQ - 1][2][2]; /* Q15 */ +extern const Word16 SN_IntraCoeff_fx[N_STAGE_VQ - 1][2][2]; // Q15 extern const float scale_ARSN[]; -extern const Word16 scale_ARSN_fx[]; +extern const Word16 scale_ARSN_fx[]; /* Q14 */ extern const float scale_inv_ARSN[]; -extern const Word16 scale_inv_ARSN_fx[]; +extern const Word16 scale_inv_ARSN_fx[]; // Q15 extern const float AR_TCVQ_CB_SUB1[2][128][2]; extern const float AR_TCVQ_CB_SUB2[2][64][2]; extern const float AR_TCVQ_CB_SUB3[4][32][2]; -extern const Word16 AR_TCVQ_CB_SUB1_fx[2][128][2]; -extern const Word16 AR_TCVQ_CB_SUB2_fx[2][64][2]; -extern const Word16 AR_TCVQ_CB_SUB3_fx[4][32][2]; +extern const Word16 AR_TCVQ_CB_SUB1_fx[2][128][2]; // Qlog2(2.56) +extern const Word16 AR_TCVQ_CB_SUB2_fx[2][64][2]; // Qlog2(2.56) +extern const Word16 AR_TCVQ_CB_SUB3_fx[4][32][2]; // Qlog2(2.56) extern const float SN_TCVQ_CB_SUB1[2][128][2]; extern const float SN_TCVQ_CB_SUB2[2][64][2]; extern const float SN_TCVQ_CB_SUB3[4][32][2]; -extern const Word16 SN_TCVQ_CB_SUB1_fx[2][128][2]; -extern const Word16 SN_TCVQ_CB_SUB2_fx[2][64][2]; -extern const Word16 SN_TCVQ_CB_SUB3_fx[4][32][2]; +extern const Word16 SN_TCVQ_CB_SUB1_fx[2][128][2]; // Qlog2(2.56) +extern const Word16 SN_TCVQ_CB_SUB2_fx[2][64][2]; // Qlog2(2.56) +extern const Word16 SN_TCVQ_CB_SUB3_fx[4][32][2]; // Qlog2(2.56) extern const float AR_SVQ_CB1[32][8]; extern const float AR_SVQ_CB2[16][8]; -extern const Word16 AR_SVQ_CB1_fx[32][8]; -extern const Word16 AR_SVQ_CB2_fx[16][8]; +extern const Word16 AR_SVQ_CB1_fx[32][8]; // Qlog2(2.56) +extern const Word16 AR_SVQ_CB2_fx[16][8]; // Qlog2(2.56) extern const int16_t uniform_model[]; @@ -742,47 +742,47 @@ extern const int16_t uniform_model[]; extern const float tbl_mid_gen_wb_2b[]; extern const float tbl_mid_gen_wb_4b[]; extern const float tbl_mid_gen_wb_5b[]; -extern const Word16 tbl_mid_gen_wb_2b_fx[]; -extern const Word16 tbl_mid_gen_wb_4b_fx[]; -extern const Word16 tbl_mid_gen_wb_5b_fx[]; +extern const Word16 tbl_mid_gen_wb_2b_fx[]; // Q13 +extern const Word16 tbl_mid_gen_wb_4b_fx[]; // Q13 +extern const Word16 tbl_mid_gen_wb_5b_fx[]; // Q13 extern const float tbl_mid_unv_wb_4b[]; extern const float tbl_mid_unv_wb_5b[]; -extern const Word16 tbl_mid_unv_wb_4b_fx[]; -extern const Word16 tbl_mid_unv_wb_5b_fx[]; +extern const Word16 tbl_mid_unv_wb_4b_fx[]; // Q13 +extern const Word16 tbl_mid_unv_wb_5b_fx[]; // Q13 extern const float tbl_mid_voi_wb_1b[]; extern const float tbl_mid_voi_wb_4b[]; extern const float tbl_mid_voi_wb_5b[]; -extern const Word16 tbl_mid_voi_wb_1b_fx[]; -extern const Word16 tbl_mid_voi_wb_4b_fx[]; -extern const Word16 tbl_mid_voi_wb_5b_fx[]; +extern const Word16 tbl_mid_voi_wb_1b_fx[]; // Q13 +extern const Word16 tbl_mid_voi_wb_4b_fx[]; // Q13 +extern const Word16 tbl_mid_voi_wb_5b_fx[]; // Q13 /*-----------------------------------------------------------------* * LSF quantization - Mode 2 quantization tables *-----------------------------------------------------------------*/ extern const float lsf_init[16]; -extern const Word16 lsf_init_fx[16]; +extern const Word16 lsf_init_fx[16]; /*14Q1*1.28*/ extern const float means_wb_31bits_ma_lsf_float[16]; extern const float means_nb_31bits_ma_lsf_float[16]; extern const float *const lsf_means_float[2]; -extern const Word16 means_nb_31bits_ma_lsf[16]; -extern const Word16 means_wb_31bits_ma_lsf[16]; -extern const Word16 *lsf_means[2]; +extern const Word16 means_nb_31bits_ma_lsf[16]; // Q1 +extern const Word16 means_wb_31bits_ma_lsf[16]; // Q1 +extern const Word16 *lsf_means[2]; // Q1 extern const float *const lsf_codebook_flt[2][2][TCXLPC_NUMSTAGES]; -extern const Word16 *const lsf_codebook[2][2][TCXLPC_NUMSTAGES]; -extern const int16_t lsf_numbits[TCXLPC_NUMSTAGES]; -extern const int16_t lsf_dims_ivas[TCXLPC_NUMSTAGES]; -extern const int16_t lsf_offs_ivas[TCXLPC_NUMSTAGES]; -extern const Word16 lsf_dims[TCXLPC_NUMSTAGES]; -extern const Word16 lsf_offs[TCXLPC_NUMSTAGES]; +extern const Word16 *const lsf_codebook[2][2][TCXLPC_NUMSTAGES]; /* 14Q1*1.28 */ +extern const Word16 lsf_numbits[TCXLPC_NUMSTAGES]; // Q0 +extern const Word16 lsf_dims_ivas[TCXLPC_NUMSTAGES]; // Q0 +extern const Word16 lsf_offs_ivas[TCXLPC_NUMSTAGES]; // Q0 +extern const Word16 lsf_dims[TCXLPC_NUMSTAGES]; // Q0 +extern const Word16 lsf_offs[TCXLPC_NUMSTAGES]; // Q0 extern const float dico_lsf_abs_8b_flt[]; -extern const Word16 dico_lsf_abs_8b[]; +extern const Word16 dico_lsf_abs_8b[]; /* 14Q1*1.28 */ extern const float lsf_q_diff_cb_8b_rf_flt[]; -extern const Word16 lsf_q_diff_cb_8b_rf[]; +extern const Word16 lsf_q_diff_cb_8b_rf[]; // Q6 extern const float lsf_cdk_nb_gc_stg1_flt[]; extern const float lsf_cdk_nb_gc_stg2_flt[]; @@ -801,139 +801,138 @@ extern const float lsf_cdk_wb_vc_stg2_flt[]; extern const float lsf_cdk_wb_vc_stg3_flt[]; extern const float lsf_ind_cdk_wb_vc_stg4_flt[]; -extern const Word16 lsf_cdk_nb_gc_stg1[]; -extern const Word16 lsf_cdk_nb_gc_stg2[]; -extern const Word16 lsf_cdk_nb_gc_stg3[]; -extern const Word16 lsf_ind_cdk_nb_gc_stg4[]; -extern const Word16 lsf_cdk_nb_vc_stg1[]; -extern const Word16 lsf_cdk_nb_vc_stg2[]; -extern const Word16 lsf_cdk_nb_vc_stg3[]; -extern const Word16 lsf_ind_cdk_nb_vc_stg4[]; -extern const Word16 lsf_cdk_wb_gc_stg1[]; -extern const Word16 lsf_cdk_wb_gc_stg2[]; -extern const Word16 lsf_cdk_wb_gc_stg3[]; -extern const Word16 lsf_ind_cdk_wb_gc_stg4[]; -extern const Word16 lsf_cdk_wb_vc_stg1[]; -extern const Word16 lsf_cdk_wb_vc_stg2[]; -extern const Word16 lsf_cdk_wb_vc_stg3[]; -extern const Word16 lsf_ind_cdk_wb_vc_stg4[]; +extern const Word16 lsf_cdk_nb_gc_stg1[]; /* 14Q1*1.28 */ +extern const Word16 lsf_cdk_nb_gc_stg2[]; /* 14Q1*1.28 */ +extern const Word16 lsf_cdk_nb_gc_stg3[]; /* 14Q1*1.28 */ +extern const Word16 lsf_ind_cdk_nb_gc_stg4[]; /* 14Q1*1.28 */ +extern const Word16 lsf_cdk_nb_vc_stg1[]; /* 14Q1*1.28 */ +extern const Word16 lsf_cdk_nb_vc_stg2[]; /* 14Q1*1.28 */ +extern const Word16 lsf_cdk_nb_vc_stg3[]; /* 14Q1*1.28 */ +extern const Word16 lsf_ind_cdk_nb_vc_stg4[]; /* 14Q1*1.28 */ +extern const Word16 lsf_cdk_wb_gc_stg1[]; /* 14Q1*1.28 */ +extern const Word16 lsf_cdk_wb_gc_stg2[]; /* 14Q1*1.28 */ +extern const Word16 lsf_cdk_wb_gc_stg3[]; /* 14Q1*1.28 */ +extern const Word16 lsf_ind_cdk_wb_gc_stg4[]; /* 14Q1*1.28 */ +extern const Word16 lsf_cdk_wb_vc_stg1[]; /* 14Q1*1.28 */ +extern const Word16 lsf_cdk_wb_vc_stg2[]; /* 14Q1*1.28 */ +extern const Word16 lsf_cdk_wb_vc_stg3[]; /* 14Q1*1.28 */ +extern const Word16 lsf_ind_cdk_wb_vc_stg4[]; /* 14Q1*1.28 */ extern const float *const lsf_ind_codebook_flt[2][2][TCXLPC_IND_NUMSTAGES]; -extern const Word16 *const lsf_ind_codebook[2][2][TCXLPC_IND_NUMSTAGES]; -extern const int16_t lsf_ind_numbits[TCXLPC_IND_NUMSTAGES]; -extern const int16_t lsf_ind_dims_ivas[TCXLPC_IND_NUMSTAGES]; -extern const Word16 lsf_ind_dims[TCXLPC_IND_NUMSTAGES]; -extern const int16_t lsf_ind_offs[TCXLPC_IND_NUMSTAGES]; -extern const Word16 min_distance_thr[2][2]; +extern const Word16 *const lsf_ind_codebook[2][2][TCXLPC_IND_NUMSTAGES]; /* 14Q1*1.28 */ +extern const Word16 lsf_ind_numbits[TCXLPC_IND_NUMSTAGES]; // Q0 +extern const Word16 lsf_ind_dims_ivas[TCXLPC_IND_NUMSTAGES]; // Q0 +extern const Word16 lsf_ind_dims[TCXLPC_IND_NUMSTAGES]; // Q0 +extern const Word16 lsf_ind_offs[TCXLPC_IND_NUMSTAGES]; // Q0 +extern const Word16 min_distance_thr[2][2]; /* 14Q1*1.28 */ typedef float lsp_unw_triplet_flt[3]; extern const lsp_unw_triplet_flt p16_gamma0_92to1_float[16]; extern const lsp_unw_triplet_flt p16_gamma0_94to1_float[16]; -typedef Word16 lsp_unw_triplet[3]; +typedef Word16 lsp_unw_triplet[3]; // Q14 extern const lsp_unw_triplet p16_gamma0_92to1[16]; extern const lsp_unw_triplet p16_gamma0_94to1[16]; /*------------------------------------------------------------------------------* * AVQ - RE8 tables *------------------------------------------------------------------------------*/ -extern const int16_t select_table22[][9]; -extern const int16_t vals_a[][4]; /* value of leader element */ -extern const int16_t vals_q[][4]; /* code parameter for every leader */ -extern const uint16_t Is[]; /* codebook start address for every leader */ -extern const int16_t AA3[]; /* A3 - Number of the absolute leaders in codebook Q3 */ -extern const int16_t AA4[]; /* A4 - Number of the absolute leaders in codebook Q4 */ -extern const uint16_t II3[]; /* I3 - Cardinality offsets for absolute leaders in Q3 */ -extern const uint16_t II4[]; /* I4 - Cardinality offset for absolute leaders in Q4 */ -extern const int16_t Da_pos[]; /* Position of the first absolute leader on a spherical shell (or sphere) */ -extern const int16_t Da_nb[]; /* Number of absolute leaders on a spherical shell */ -extern const int16_t Da_id[]; /* identification code of an absolute leader */ -extern const int16_t Da_nq[]; /* Codebook number for each absolute leader */ +extern const Word16 select_table22[][9]; // Q0 +extern const Word16 vals_a[][4]; /* value of leader element */ // Q0 +extern const Word16 vals_q[][4]; /* code parameter for every leader */ // Q0 +extern const UWord16 Is[]; /* codebook start address for every leader */ // Q0 +extern const Word16 AA3[]; /* A3 - Number of the absolute leaders in codebook Q3 */ // Q0 +extern const Word16 AA4[]; /* A4 - Number of the absolute leaders in codebook Q4 */ // Q0 +extern const UWord16 II3[]; /* I3 - Cardinality offsets for absolute leaders in Q3 */ // Q0 +extern const UWord16 II4[]; /* I4 - Cardinality offset for absolute leaders in Q4 */ // Q0 +extern const Word16 Da_pos[]; /* Position of the first absolute leader on a spherical shell (or sphere) */ // Q0 +extern const Word16 Da_nb[]; /* Number of absolute leaders on a spherical shell */ // Q0 +extern const Word16 Da_id[]; /* identification code of an absolute leader */ // Q0 +extern const Word16 Da_nq[]; /* Codebook number for each absolute leader */ // Q0 /*------------------------------------------------------------------------------* * SWB TBE tables *------------------------------------------------------------------------------*/ -extern const int16_t skip_bands_SWB_TBE[]; /* bands for SWB TBE quantisation */ -extern const int16_t skip_bands_WB_TBE[]; /* bands for WB TBE quantisation */ +extern const Word16 skip_bands_SWB_TBE[]; /* bands for SWB TBE quantisation Q0*/ +extern const Word16 skip_bands_WB_TBE[]; /* bands for WB TBE quantisation Q0*/ extern const float interpol_frac_shb_flt[]; -extern const Word16 interpol_frac_shb[NB_SUBFR * 2]; +extern const Word16 interpol_frac_shb[NB_SUBFR * 2]; // Q15 extern const float AP1_STEEP[]; /* All pass filter coeffs for interpolation and decimation by a factor of 2 */ extern const float AP2_STEEP[]; /* All pass filter coeffs for interpolation and decimation by a factor of 2 */ -extern const Word16 AP1_STEEP_FX[]; /* All pass filter coeffs for interpolation and decimation by a factor of 2 */ -extern const Word16 AP2_STEEP_FX[]; /* All pass filter coeffs for interpolation and decimation by a factor of 2 */ +extern const Word16 AP1_STEEP_FX[]; // Q15 /* All pass filter coeffs for interpolation and decimation by a factor of 2 */ +extern const Word16 AP2_STEEP_FX[]; // Q15 /* All pass filter coeffs for interpolation and decimation by a factor of 2 */ extern const float STEPS[]; /* Granuality in conversion from lpc to lsp */ extern const float cos_fb_exc[]; -extern const Word16 cos_fb_exc_fx[32]; +extern const Word16 cos_fb_exc_fx[32]; // Q15 extern const float recip_order[]; extern const float win_lpc_shb[]; /* Window for calculating SHB LPC coeffs */ -extern const Word16 win_lpc_shb_fx[]; /* Window for calculating SHB LPC coeffs */ +extern const Word16 win_lpc_shb_fx[]; // Q15 /* Window for calculating SHB LPC coeffs */ extern const float win_lpc_hb_wb[]; -extern const Word16 win_lpc_hb_wb_fx[]; +extern const Word16 win_lpc_hb_wb_fx[]; // Q15 extern const float ola_win_shb_switch_fold[]; -extern const Word16 ola_win_shb_switch_fold_fx[]; -extern const float win_flatten[]; /* Window for calculating whitening filter for SHB excitation */ -extern const Word16 win_flatten_fx[]; -extern const float win_flatten_4k[]; /* Window for calculating whitening filter for WB excitation */ -extern const Word16 win_flatten_4k_fx[]; -extern const float window_shb[]; /* Overlap add window for SHB excitation used in anal and synth */ -extern const Word16 window_shb_fx[]; -extern const float window_shb_32k[]; /* Upsampled overlap add window for SHB excitation used transition generation */ -extern const Word16 window_shb_32k_fx[]; -extern const float subwin_shb[]; /* Short overlap add window for SHB excitation used in anal and synth */ -extern const Word16 subwin_shb_fx[]; /* Short overlap add window for SHB excitation used in anal and synth */ +extern const Word16 ola_win_shb_switch_fold_fx[]; // Q15 +extern const float win_flatten[]; /* Window for calculating whitening filter for SHB excitation */ +extern const Word16 win_flatten_fx[]; // Q15 +extern const float win_flatten_4k[]; /* Window for calculating whitening filter for WB excitation */ +extern const Word16 win_flatten_4k_fx[]; // Q15 +extern const float window_shb[]; /* Overlap add window for SHB excitation used in anal and synth */ +extern const Word16 window_shb_fx[]; // Q15 +extern const float window_shb_32k[]; /* Upsampled overlap add window for SHB excitation used transition generation */ +extern const Word16 window_shb_32k_fx[]; // Q15 +extern const float subwin_shb[]; /* Short overlap add window for SHB excitation used in anal and synth */ +extern const Word16 subwin_shb_fx[]; // Q15 /* Short overlap add window for SHB excitation used in anal and synth */ extern const float window_wb[]; -extern const float subwin_wb[]; /* Short overlap add window for SHB excitation used in anal and synth */ -extern const Word16 window_wb_fx[]; -extern const Word16 subwin_wb_fx[]; +extern const float subwin_wb[]; /* Short overlap add window for SHB excitation used in anal and synth */ +extern const Word16 window_wb_fx[]; // Q15 +extern const Word16 subwin_wb_fx[]; // Q15 extern const float Hilbert_coeffs[4 * NUM_HILBERTS][HILBERT_ORDER1 + 1]; -extern const Word16 Hilbert_coeffs_fx[4 * NUM_HILBERTS][HILBERT_ORDER1 + 1]; +extern const Word16 Hilbert_coeffs_fx[4 * NUM_HILBERTS][HILBERT_ORDER1 + 1]; // Q14 extern const float wac[]; extern const float wac_swb[]; -extern const Word16 wac_swb_h[]; -extern const Word16 wac_swb_l[]; +extern const Word16 wac_swb_h[]; // Q15 +extern const Word16 wac_swb_l[]; // Q15 extern const float wb_bwe_lsfvq_cbook_8bit[]; -extern const Word16 wb_bwe_lsfvq_cbook_8bit_fx[]; +extern const Word16 wb_bwe_lsfvq_cbook_8bit_fx[]; // Q15 extern const float lbr_wb_bwe_lsfvq_cbook_2bit[]; -extern const Word16 lbr_wb_bwe_lsfvq_cbook_2bit_fx[]; +extern const Word16 lbr_wb_bwe_lsfvq_cbook_2bit_fx[]; // Q15 extern const float swb_tbe_lsfvq_cbook_8b_flt[]; -extern const Word16 swb_tbe_lsfvq_cbook_8b[]; -extern const float SHBCB_SubGain5bit[]; /* 5 bit Quantizer table for SHB gain shapes */ -extern const Word16 SHBCB_SubGain5bit_fx[]; -extern const float HBCB_SubGain5bit[]; /* 5-bit TD WB BWE temporal shaping codebook */ -extern const Word16 HBCB_SubGain5bit_fx[]; -extern const float SHBCB_FrameGain64[]; /* 6 bit Quantizer table for SHB overall gain */ -extern const Word32 SHBCB_FrameGain64_fx[]; +extern const Word16 swb_tbe_lsfvq_cbook_8b[]; // Q15 +extern const float SHBCB_SubGain5bit[]; /* 5 bit Quantizer table for SHB gain shapes */ +extern const Word16 SHBCB_SubGain5bit_fx[]; // Q14 +extern const float HBCB_SubGain5bit[]; /* 5-bit TD WB BWE temporal shaping codebook */ +extern const Word16 HBCB_SubGain5bit_fx[]; // Q8 +extern const float SHBCB_FrameGain64[]; /* 6 bit Quantizer table for SHB overall gain */ +extern const Word32 SHBCB_FrameGain64_fx[]; // Q18 extern const float SHBCB_FrameGain16[]; -extern const Word32 SHBCB_FrameGain16_fx[]; +extern const Word32 SHBCB_FrameGain16_fx[]; /*Q18*/ extern const float full_band_bpf_1[][5]; extern const float full_band_bpf_2[][5]; extern const float full_band_bpf_3[][5]; -extern const Word16 full_band_bpf_1_fx[][5]; -extern const Word16 full_band_bpf_2_fx[][5]; -extern const Word16 full_band_bpf_3_fx[][5]; - -extern const float lsf_q_cb_4b[]; /* 4 bit differential scalar quantizer table for TD SWB BWE LSFs 1 and 2*/ -extern const float lsf_q_cb_3b[]; /* 3 bit differential scalar quantizer table for TD SWB BWE LSFs 3, 4 and 5*/ -extern const float *const lsf_q_cb[]; /* Codebook array for each LSF */ -extern const Word16 *const lsf_q_cb_fx[]; -extern const int16_t lsf_q_cb_size[]; /* Size of each element of the above */ -extern const int16_t lsf_q_num_bits[]; /* Size of each element of the above, in bits */ -extern const float mirror_point_q_cb[]; /* LSF mirroring point codebook */ -extern const Word16 mirror_point_q_cb_fx[]; -extern const float lsf_grid[4][5]; /* LSF mirroring adjustment grid */ -extern const Word16 lsf_grid_fx[4][5]; -extern const float grid_smoothing[]; /* LSF mirroring smoothing table */ -extern const Word16 grid_smoothing_fx[]; /* LSF mirroring smoothing table */ +extern const Word16 full_band_bpf_1_fx[][5]; /*Q13*/ +extern const Word16 full_band_bpf_2_fx[][5]; /*Q13*/ +extern const Word16 full_band_bpf_3_fx[][5]; /*Q13*/ +extern const float lsf_q_cb_4b[]; /* 4 bit differential scalar quantizer table for TD SWB BWE LSFs 1 and 2*/ +extern const float lsf_q_cb_3b[]; /* 3 bit differential scalar quantizer table for TD SWB BWE LSFs 3, 4 and 5*/ +extern const float *const lsf_q_cb[]; /* Codebook array for each LSF */ +extern const Word16 *const lsf_q_cb_fx[]; // Q15 +extern const Word16 lsf_q_cb_size[]; /* Size of each element of the above Q0*/ +extern const Word16 lsf_q_num_bits[]; /* Size of each element of the above, in bits Q0*/ +extern const float mirror_point_q_cb[]; /* LSF mirroring point codebook */ +extern const Word16 mirror_point_q_cb_fx[]; // Q15 +extern const float lsf_grid[4][5]; /* LSF mirroring adjustment grid */ +extern const Word16 lsf_grid_fx[4][5]; // Q15 +extern const float grid_smoothing[]; /* LSF mirroring smoothing table */ +extern const Word16 grid_smoothing_fx[]; /* LSF mirroring smoothing table Q15*/ extern const float overlap_coefs[]; /* HR SWB BWE - overlap coefficients */ extern const float overlap_coefs_48kHz[]; /* HR SWB BWE - overlap coefficients @48kHz */ @@ -943,16 +942,16 @@ extern const Word16 overlap_coefs_48kHz_fx[NSV_OVERLAP * WIDTH_BAND]; /* in Q15 extern const float swb_hr_env_code1[]; /* HR SWB BWE - envelope Q table - first two subabnds in non-transient frames */ extern const float swb_hr_env_code2[]; /* HR SWB BWE - envelope Q table - second two subabnds in non-transient frames*/ extern const float swb_hr_env_code3[]; /* HR SWB BWE - envelope Q table - two subabnds in transient frames */ -extern const Word16 swb_hr_env_code1_fx[]; /* HR SWB BWE - envelope Q table - first two subabnds in non-transient frames */ -extern const Word16 swb_hr_env_code2_fx[]; /* HR SWB BWE - envelope Q table - second two subabnds in non-transient frames*/ -extern const Word16 swb_hr_env_code3_fx[]; /* HR SWB BWE - envelope Q table - two subands in transient frames */ +extern const Word16 swb_hr_env_code1_fx[]; /* HR SWB BWE - envelope Q table - first two subabnds in non-transient frames Q9*/ +extern const Word16 swb_hr_env_code2_fx[]; /* HR SWB BWE - envelope Q table - second two subabnds in non-transient frames Q9*/ +extern const Word16 swb_hr_env_code3_fx[]; /* HR SWB BWE - envelope Q table - two subands in transient frames Q9*/ extern const float allpass_poles_3_ov_2_flt[]; -extern const Word16 allpass_poles_3_ov_2[]; +extern const Word16 allpass_poles_3_ov_2[]; /*Q15*/ extern const float decimate_3_ov_2_lowpass_num[]; -extern const Word16 decimate_3_ov_2_lowpass_num_fx[]; +extern const Word16 decimate_3_ov_2_lowpass_num_fx[]; /*Q15*/ extern const float decimate_3_ov_2_lowpass_den[]; -extern const Word16 decimate_3_ov_2_lowpass_den_fx[]; +extern const Word16 decimate_3_ov_2_lowpass_den_fx[]; /*Q15*/ /*------------------------------------------------------------------------------* @@ -960,57 +959,57 @@ extern const Word16 decimate_3_ov_2_lowpass_den_fx[]; *------------------------------------------------------------------------------*/ extern const float F_2_5[64]; -extern const Word16 F_2_5_fx[64]; +extern const Word16 F_2_5_fx[64]; /*Q10*/ /*------------------------------------------------------------------------------* * SWB BWE tables *------------------------------------------------------------------------------*/ -extern const int16_t swb_bwe_trans_subband[]; -extern const int16_t swb_bwe_trans_subband_width[]; +extern const Word16 swb_bwe_trans_subband[]; // Q0 +extern const Word16 swb_bwe_trans_subband_width[]; // Q0 -extern const Word16 sqrt_swb_bwe_trans_subband_width_fx[]; -extern const Word16 sqrt_swb_bwe_subband_fx_L1[]; -extern const Word16 sqrt_swb_bwe_subband_fx_L2[]; +extern const Word16 sqrt_swb_bwe_trans_subband_width_fx[]; // Q11 +extern const Word16 sqrt_swb_bwe_subband_fx_L1[]; // Q12 +extern const Word16 sqrt_swb_bwe_subband_fx_L2[]; // Q12 -extern const int16_t swb_bwe_subband[]; -extern const Word16 fb_bwe_subband[]; -extern const Word16 fb_bwe_sm_subband[]; +extern const Word16 swb_bwe_subband[]; // Q0 +extern const Word16 fb_bwe_subband[]; // Q0 +extern const Word16 fb_bwe_sm_subband[]; // Q0 extern const float swb_inv_bwe_subband_width[]; -extern const Word16 swb_inv_bwe_subband_width_fx[]; -extern const int16_t swb_bwe_sm_subband[]; +extern const Word16 swb_inv_bwe_subband_width_fx[]; // Q15 +extern const Word16 swb_bwe_sm_subband[]; // Q0 extern const float smooth_factor[]; -extern const Word16 smooth_factor_fx[]; -extern const int16_t fb_bwe_subband_float[]; +extern const Word16 smooth_factor_fx[]; // Q15 +extern const Word16 fb_bwe_subband_float[]; // Q0 extern const float fb_inv_bwe_subband_width[]; -extern const Word16 fb_inv_bwe_subband_width_fx[]; -extern const int16_t fb_bwe_sm_subband_float[]; +extern const Word16 fb_inv_bwe_subband_width_fx[]; // Q15 +extern const Word16 fb_bwe_sm_subband_float[]; // Q0 extern const float fb_smooth_factor[]; -extern const Word16 fb_smooth_factor_fx[]; +extern const Word16 fb_smooth_factor_fx[]; // Q15 extern const float EnvCdbk11[]; extern const float EnvCdbk1st[]; extern const float EnvCdbk2nd[]; extern const float EnvCdbk3rd[]; extern const float EnvCdbk4th[]; -extern const Word16 EnvCdbk11_fx[]; -extern const Word16 EnvCdbk1st_fx[]; -extern const Word16 EnvCdbk2nd_fx[]; -extern const Word16 EnvCdbk3rd_fx[]; -extern const Word16 EnvCdbk4th_fx[]; +extern const Word16 EnvCdbk11_fx[]; /*Q8 */ +extern const Word16 EnvCdbk1st_fx[]; /*Q8 */ +extern const Word16 EnvCdbk2nd_fx[]; /*Q8 */ +extern const Word16 EnvCdbk3rd_fx[]; /*Q8 */ +extern const Word16 EnvCdbk4th_fx[]; /*Q8 */ extern const float EnvCdbkFB[]; -extern const Word16 EnvCdbkFB_fx[]; +extern const Word16 EnvCdbkFB_fx[]; /*Q7 */ extern const float Env_TR_Cdbk1[]; extern const float Env_TR_Cdbk2[]; -extern const Word16 Env_TR_Cdbk1_fx[]; -extern const Word16 Env_TR_Cdbk2_fx[]; +extern const Word16 Env_TR_Cdbk1_fx[]; /*Q8 */ +extern const Word16 Env_TR_Cdbk2_fx[]; /*Q8 */ extern const float w_NOR[]; -extern const Word16 w_NOR_fx[]; +extern const Word16 w_NOR_fx[]; // Q15 extern const float Mean_env[]; -extern const Word16 Mean_env_fx[]; +extern const Word16 Mean_env_fx[]; // Q8 extern const float Mean_env_fb[]; -extern const Word16 Mean_env_fb_fx[]; +extern const Word16 Mean_env_fb_fx[]; /*Q8 */ extern const float Mean_env_tr[]; -extern const Word16 Mean_env_tr_fx[]; +extern const Word16 Mean_env_tr_fx[]; /*Q8 */ /*------------------------------------------------------------------------------* * ACEPL/HQ core switching tables *------------------------------------------------------------------------------*/ @@ -1020,18 +1019,18 @@ extern const float hp16000_32000[]; extern const float hp12800_48000[]; extern const float hp16000_48000[]; extern const float hp12800_16000[]; -extern const Word16 hp12800_32000_fx[]; -extern const Word16 hp16000_32000_fx[]; -extern const Word16 hp12800_48000_fx[]; -extern const Word16 hp16000_48000_fx[]; -extern const Word16 hp12800_16000_fx[]; +extern const Word16 hp12800_32000_fx[]; // Q15 +extern const Word16 hp16000_32000_fx[]; // Q15 +extern const Word16 hp12800_48000_fx[]; // Q15 +extern const Word16 hp16000_48000_fx[]; // Q15 +extern const Word16 hp12800_16000_fx[]; // Q15 extern const double cu15[28][3]; extern const double cu4[6][3]; -extern const Word16 cu15_fx[28][3]; -extern const Word16 cu4_fx[6][3]; -extern const int16_t ct2[7][13]; -extern const Word16 ct2_fx[7][14]; +extern const Word16 cu15_fx[28][3]; // Q13 +extern const Word16 cu4_fx[6][3]; // Q13 +extern const Word16 ct2[7][13]; // Q0 +extern const Word16 ct2_fx[7][14]; // Q13 /*------------------------------------------------------------------------------* * HQ core tables *------------------------------------------------------------------------------*/ @@ -1050,113 +1049,113 @@ extern const float short_window_48kHz[]; extern const float short_window_32kHz[]; extern const float short_window_16kHz[]; extern const float short_window_8kHz[]; -extern const Word16 short_window_48kHz_fx[L_FRAME48k / 2 / 2]; -extern const Word16 short_window_32kHz_fx[L_FRAME32k / 2 / 2]; -extern const Word16 short_window_16kHz_fx[L_FRAME16k / 2 / 2]; -extern const Word16 short_window_8kHz_fx[L_FRAME8k / 2 / 2]; -extern const Word16 inv_jp2[]; +extern const Word16 short_window_48kHz_fx[L_FRAME48k / 2 / 2]; // Q15 +extern const Word16 short_window_32kHz_fx[L_FRAME32k / 2 / 2]; // Q15 +extern const Word16 short_window_16kHz_fx[L_FRAME16k / 2 / 2]; // Q15 +extern const Word16 short_window_8kHz_fx[L_FRAME8k / 2 / 2]; // Q15 +extern const Word16 inv_jp2[]; // Q15 extern const float wscw16q15[]; extern const float wscw16q15_8[]; extern const float wscw16q15_16[]; extern const float wscw16q15_32[]; -extern const Word16 wscw16q15_fx[]; -extern const Word16 wscw16q15_8_fx[]; -extern const Word16 wscw16q15_16_fx[]; -extern const Word16 wscw16q15_32_fx[]; +extern const Word16 wscw16q15_fx[]; /*Q15 */ +extern const Word16 wscw16q15_8_fx[]; /*Q15 */ +extern const Word16 wscw16q15_16_fx[]; /*Q15 */ +extern const Word16 wscw16q15_32_fx[]; /*Q15 */ /* Band structure */ -extern const Word16 band_len_HQ[]; -extern const Word16 band_start_HQ[]; -extern const Word16 band_end_HQ[]; -extern const int16_t band_len_wb[]; -extern const int16_t band_start_wb[]; -extern const int16_t band_end_wb[]; -extern const int16_t band_len_harm_float[]; -extern const Word16 band_start_harm[]; -extern const Word16 band_end_harm[]; +extern const Word16 band_len_HQ[]; // Q0 +extern const Word16 band_start_HQ[]; // Q0 +extern const Word16 band_end_HQ[]; // Q0 +extern const Word16 band_len_wb[]; // Q0 +extern const Word16 band_start_wb[]; // Q0 +extern const Word16 band_end_wb[]; // Q0 +extern const Word16 band_len_harm_float[]; +extern const Word16 band_start_harm[]; // Q0 +extern const Word16 band_end_harm[]; // Q0 extern const float rat_flt[SFM_N_WB]; -extern const Word16 rat_fx[SFM_N_WB]; -extern const int16_t intl_bw_16[N_INTL_GRP_16]; -extern const int16_t intl_bw_32[N_INTL_GRP_32]; -extern const int16_t intl_bw_48[N_INTL_GRP_48]; -extern const int16_t intl_cnt_16[N_INTL_GRP_16]; -extern const int16_t intl_cnt_32[N_INTL_GRP_32]; -extern const int16_t intl_cnt_48[N_INTL_GRP_48]; -extern const int16_t norm_order_48[NB_SFM]; -extern const int16_t norm_order_32[SFM_N_SWB]; -extern const int16_t norm_order_16[SFM_N_WB]; +extern const Word16 rat_fx[SFM_N_WB]; // Q14 +extern const Word16 intl_bw_16[N_INTL_GRP_16]; // Q0 +extern const Word16 intl_bw_32[N_INTL_GRP_32]; // Q0 +extern const Word16 intl_bw_48[N_INTL_GRP_48]; // Q0 +extern const Word16 intl_cnt_16[N_INTL_GRP_16]; // Q0 +extern const Word16 intl_cnt_32[N_INTL_GRP_32]; // Q0 +extern const Word16 intl_cnt_48[N_INTL_GRP_48]; // Q0 +extern const Word16 norm_order_48[NB_SFM]; // Q0 +extern const Word16 norm_order_32[SFM_N_SWB]; // Q0 +extern const Word16 norm_order_16[SFM_N_WB]; // Q0 extern const float dicn_pg[45]; -extern const Word32 dicn_pg_fx[]; -extern const int16_t expPkEnrg_tbl[45]; -extern const int32_t manPkEnrg_tbl[45]; -extern const int32_t E_max5_tbl[40]; +extern const Word32 dicn_pg_fx[]; /*Q12 */ +extern const Word16 expPkEnrg_tbl[45]; // Q0 +extern const Word32 manPkEnrg_tbl[45]; // Q0 +extern const Word32 E_max5_tbl[40]; // Q0 extern const float thren_pg[44]; #ifdef IVAS_FLOAT_FIXED extern const Word32 thren_pg_fx[44]; #endif extern const float dicn[40]; -extern const Word32 dicn_fx[40]; +extern const Word32 dicn_fx[40]; /*Q14 */ extern const float dicn_inv[40]; extern const float thren_HQ[39]; #ifdef IVAS_FLOAT_FIXED -extern const Word32 thren_HQ_fx[39]; +extern const Word32 thren_HQ_fx[39]; /*Q14 */ #endif -extern const int16_t dicnlg2_float[40]; -extern const int16_t huffnorm[32]; -extern const int16_t huffsizn[32]; -extern const int16_t huffcoef[60]; -extern const int16_t pgain_huffnorm[32]; -extern const int16_t pgain_huffsizn[32]; +extern const Word16 dicnlg2_float[40]; // Q0 +extern const Word16 huffnorm[32]; // Q0 +extern const Word16 huffsizn[32]; // Q0 +extern const Word16 huffcoef[60]; // Q0 +extern const Word16 pgain_huffnorm[32]; // Q0 +extern const Word16 pgain_huffsizn[32]; // Q0 -extern const int16_t resize_huffnorm[32]; -extern const int16_t resize_huffsizn[32]; +extern const Word16 resize_huffnorm[32]; // Q0 +extern const Word16 resize_huffsizn[32]; // Q) -extern const int16_t huffnorm_tran[32]; -extern const int16_t huffsizn_tran[32]; +extern const Word16 huffnorm_tran[32]; // Q0 +extern const Word16 huffsizn_tran[32]; // Q0 -extern const int16_t sfm_width[20]; -extern const int16_t a_map[20]; -extern const int16_t subf_norm_groups[4][11]; +extern const Word16 sfm_width[20]; // Q0 +extern const Word16 a_map[20]; // Q0 +extern const Word16 subf_norm_groups[4][11]; // Q0 -extern const Word32 SQRT_DIM_fx[]; +extern const Word32 SQRT_DIM_fx[]; // Q15 /* HQ inner_frame signallisation table */ -extern const int16_t inner_frame_tbl[]; -extern const Word16 hq_nominal_scaling_inv[]; -extern const Word16 hq_nominal_scaling[]; +extern const Word16 inner_frame_tbl[]; // Q0 +extern const Word16 hq_nominal_scaling_inv[]; // Q13 +extern const Word16 hq_nominal_scaling[]; /*Q15 */ /* HQ spectrum length lookup tables */ -extern const int16_t l_spec_tbl[]; -extern const int16_t l_spec_ext_tbl[]; -extern const Word16 sinq_16k[]; -extern const Word16 sinq_32k[]; -extern const Word16 sinq_48k[]; +extern const Word16 l_spec_tbl[]; // Q0 +extern const Word16 l_spec_ext_tbl[]; // Q0 +extern const Word16 sinq_16k[]; /*Q15 */ +extern const Word16 sinq_32k[]; /*Q15 */ +extern const Word16 sinq_48k[]; /*Q15 */ /* NB short win: 7200/8000/9600, 13200/16400 */ -extern const int16_t band_width_40_4_6_0_0_0[4]; -extern const int16_t band_width_40_5_6_0_0_0[5]; +extern const Word16 band_width_40_4_6_0_0_0[4]; // Q0 +extern const Word16 band_width_40_5_6_0_0_0[5]; // Q0 /* NB long win: 7200, 8000, 9600, 13200, 16400 */ -extern const int16_t band_width_160_18_6_4_0_0[18]; -extern const int16_t band_width_160_17_6_3_0_0[17]; -extern const int16_t band_width_160_14_6_3_0_0[14]; -extern const int16_t band_width_160_13_6_2_0_0[13]; +extern const Word16 band_width_160_18_6_4_0_0[18]; // Q0 +extern const Word16 band_width_160_17_6_3_0_0[17]; // Q0 +extern const Word16 band_width_160_14_6_3_0_0[14]; // Q0 +extern const Word16 band_width_160_13_6_2_0_0[13]; // Q0 /* WB short win: 13200/16400 */ -extern const int16_t band_width_80_7_6_0_0_0[7]; +extern const Word16 band_width_80_7_6_0_0_0[7]; // Q0 /* WB long win: 13200, 16400 */ -extern const int16_t band_width_320_18_6_3_0_0[18]; -extern const int16_t band_width_320_20_6_3_0_0[20]; +extern const Word16 band_width_320_18_6_3_0_0[18]; // Q0 +extern const Word16 band_width_320_20_6_3_0_0[20]; // Q0 /* SWB short win: 13200, 16400 */ -extern const int16_t band_width_142_8_8_0_0_0[8]; -extern const int16_t band_width_160_8_8_0_0_0[8]; +extern const Word16 band_width_142_8_8_0_0_0[8]; // Q0 +extern const Word16 band_width_160_8_8_0_0_0[8]; // Q0 /* SWB long win: 13200, 16400 */ -extern const int16_t band_width_568_22_6_2_0_0[22]; -extern const int16_t band_width_640_24_6_4_0_0[24]; +extern const Word16 band_width_568_22_6_2_0_0[22]; // Q0 +extern const Word16 band_width_640_24_6_4_0_0[24]; // Q0 /* LR-MDCT configuration tables */ extern const Xcore_Config xcore_config_8kHz_007200bps_long; @@ -1182,136 +1181,136 @@ extern const Xcore_Config xcore_config_32kHz_013200bps_short; extern const Xcore_Config xcore_config_32kHz_016400bps_short; -extern const int16_t Nb[NB_SFM]; -extern const int16_t LNb[NB_SFM]; +extern const Word16 Nb[NB_SFM]; // Q0 +extern const Word16 LNb[NB_SFM]; // Q0 -extern const Word32 pow_getbitsfrompulses_fx[16]; -extern const Word32 table_logcum_fx[563]; -extern const Word16 DDP_fx[4]; +extern const Word32 pow_getbitsfrompulses_fx[16]; // Q21 +extern const Word32 table_logcum_fx[563]; // Q16 +extern const Word16 DDP_fx[4]; // Q0 extern const float DDP[4]; -extern const int16_t step_tcq[8][STATES]; -extern const int16_t denc[8][STATES]; -extern const int16_t ddec[8][STATES]; +extern const Word16 step_tcq[8][STATES]; // Q0 +extern const Word16 denc[8][STATES]; // Q0 +extern const Word16 ddec[8][STATES]; // Q0 -extern const int16_t step_LSB[STATES_LSB][2]; -extern const int16_t denc_LSB[STATES_LSB][2]; -extern const int16_t dqnt_LSB[STATES_LSB][4]; -extern const int16_t dstep_LSB[4][2]; -extern const int16_t ddec_LSB[4][2]; +extern const Word16 step_LSB[STATES_LSB][2]; // Q0 +extern const Word16 denc_LSB[STATES_LSB][2]; // Q0 +extern const Word16 dqnt_LSB[STATES_LSB][4]; // Q0 +extern const Word16 dstep_LSB[4][2]; // Q0 +extern const Word16 ddec_LSB[4][2]; // Q0 -extern const int16_t nextstate[STATES][2]; +extern const Word16 nextstate[STATES][2]; // Q0 -extern const int16_t fine_gain_bits[]; +extern const Word16 fine_gain_bits[]; // Q0 extern const float *const finegain[]; -extern const Word16 *finegain_fx[5]; -extern const uint8_t hBitsMinus1_N01[2]; -extern const uint8_t hBitsMinus1_N02[65]; -extern const uint8_t hBitsMinus1_N03[65]; -extern const uint8_t hBitsMinus1_N04[65]; -extern const uint8_t hBitsMinus1_N05[54]; -extern const uint8_t hBitsMinus1_N06[42]; -extern const uint8_t hBitsMinus1_N07[34]; -extern const uint8_t hBitsMinus1_N08[29]; -extern const uint8_t hBitsMinus1_N09[25]; -extern const uint8_t hBitsMinus1_N10[22]; -extern const uint8_t hBitsMinus1_N11[19]; -extern const uint8_t hBitsMinus1_N12[17]; -extern const uint8_t hBitsMinus1_N13[16]; -extern const uint8_t hBitsMinus1_N14[14]; -extern const uint8_t hBitsMinus1_N15[13]; -extern const uint8_t hBitsMinus1_N16[13]; -extern const uint8_t hBitsMinus1_N17[12]; -extern const uint8_t hBitsMinus1_N18[12]; -extern const uint8_t hBitsMinus1_N19[11]; -extern const uint8_t hBitsMinus1_N20[11]; -extern const uint8_t hBitsMinus1_N21[10]; -extern const uint8_t hBitsMinus1_N22[10]; -extern const uint8_t hBitsMinus1_N23[10]; -extern const uint8_t hBitsMinus1_N24[10]; -extern const uint8_t hBitsMinus1_N25[9]; -extern const uint8_t hBitsMinus1_N26[9]; -extern const uint8_t hBitsMinus1_N27[9]; -extern const uint8_t hBitsMinus1_N28[9]; -extern const uint8_t hBitsMinus1_N29[9]; -extern const uint8_t hBitsMinus1_N30[8]; -extern const uint8_t hBitsMinus1_N31[8]; -extern const uint8_t hBitsMinus1_N32[8]; -extern const uint8_t hBitsMinus1_N33[8]; -extern const uint8_t hBitsMinus1_N34[8]; -extern const uint8_t hBitsMinus1_N35[8]; -extern const uint8_t hBitsMinus1_N36[8]; -extern const uint8_t hBitsMinus1_N37[8]; -extern const uint8_t hBitsMinus1_N38[8]; -extern const uint8_t hBitsMinus1_N39[8]; -extern const uint8_t hBitsMinus1_N40[8]; -extern const uint8_t hBitsMinus1_N41[7]; -extern const uint8_t hBitsMinus1_N42[7]; -extern const uint8_t hBitsMinus1_N43[7]; -extern const uint8_t hBitsMinus1_N44[7]; -extern const uint8_t hBitsMinus1_N45[7]; -extern const uint8_t hBitsMinus1_N46[7]; -extern const uint8_t hBitsMinus1_N47[7]; -extern const uint8_t hBitsMinus1_N48[7]; -extern const uint8_t hBitsMinus1_N49[7]; -extern const uint8_t hBitsMinus1_N50[7]; -extern const uint8_t hBitsMinus1_N51[7]; -extern const uint8_t hBitsMinus1_N52[7]; -extern const uint8_t hBitsMinus1_N53[7]; -extern const uint8_t hBitsMinus1_N54[7]; -extern const uint8_t hBitsMinus1_N55[7]; -extern const uint8_t hBitsMinus1_N56[7]; -extern const uint8_t hBitsMinus1_N57[7]; -extern const uint8_t hBitsMinus1_N58[7]; -extern const uint8_t hBitsMinus1_N59[7]; -extern const uint8_t hBitsMinus1_N60[7]; -extern const uint8_t hBitsMinus1_N61[6]; -extern const uint8_t hBitsMinus1_N62[6]; -extern const uint8_t hBitsMinus1_N63[6]; -extern const uint8_t hBitsMinus1_N64[6]; -extern const uint8_t *const hBitsN[65]; -extern const int16_t dsHighDiracsTab[43]; -extern const uint32_t intLimCDivInvDQ31[68]; -extern const uint8_t obtainEnergyQuantizerDensity_f[57]; -extern const int16_t lim_neg_inv_tbl_fx[11]; -extern const int16_t fg_inv_tbl_fx[13]; +extern const Word16 *finegain_fx[5]; /* Q14 */ +extern const UWord8 hBitsMinus1_N01[2]; // Q0 +extern const UWord8 hBitsMinus1_N02[65]; // Q0 +extern const UWord8 hBitsMinus1_N03[65]; // Q0 +extern const UWord8 hBitsMinus1_N04[65]; // Q0 +extern const UWord8 hBitsMinus1_N05[54]; // Q0 +extern const UWord8 hBitsMinus1_N06[42]; // Q0 +extern const UWord8 hBitsMinus1_N07[34]; // Q0 +extern const UWord8 hBitsMinus1_N08[29]; // Q0 +extern const UWord8 hBitsMinus1_N09[25]; // Q0 +extern const UWord8 hBitsMinus1_N10[22]; // Q0 +extern const UWord8 hBitsMinus1_N11[19]; // Q0 +extern const UWord8 hBitsMinus1_N12[17]; // Q0 +extern const UWord8 hBitsMinus1_N13[16]; // Q0 +extern const UWord8 hBitsMinus1_N14[14]; // Q0 +extern const UWord8 hBitsMinus1_N15[13]; // Q0 +extern const UWord8 hBitsMinus1_N16[13]; // Q0 +extern const UWord8 hBitsMinus1_N17[12]; // Q0 +extern const UWord8 hBitsMinus1_N18[12]; // Q0 +extern const UWord8 hBitsMinus1_N19[11]; // Q0 +extern const UWord8 hBitsMinus1_N20[11]; // Q0 +extern const UWord8 hBitsMinus1_N21[10]; // Q0 +extern const UWord8 hBitsMinus1_N22[10]; // Q0 +extern const UWord8 hBitsMinus1_N23[10]; // Q0 +extern const UWord8 hBitsMinus1_N24[10]; // Q0 +extern const UWord8 hBitsMinus1_N25[9]; // Q0 +extern const UWord8 hBitsMinus1_N26[9]; // Q0 +extern const UWord8 hBitsMinus1_N27[9]; // Q0 +extern const UWord8 hBitsMinus1_N28[9]; // Q0 +extern const UWord8 hBitsMinus1_N29[9]; // Q0 +extern const UWord8 hBitsMinus1_N30[8]; // Q0 +extern const UWord8 hBitsMinus1_N31[8]; // Q0 +extern const UWord8 hBitsMinus1_N32[8]; // Q0 +extern const UWord8 hBitsMinus1_N33[8]; // Q0 +extern const UWord8 hBitsMinus1_N34[8]; // Q0 +extern const UWord8 hBitsMinus1_N35[8]; // Q0 +extern const UWord8 hBitsMinus1_N36[8]; // Q0 +extern const UWord8 hBitsMinus1_N37[8]; // Q0 +extern const UWord8 hBitsMinus1_N38[8]; // Q0 +extern const UWord8 hBitsMinus1_N39[8]; // Q0 +extern const UWord8 hBitsMinus1_N40[8]; // Q0 +extern const UWord8 hBitsMinus1_N41[7]; // Q0 +extern const UWord8 hBitsMinus1_N42[7]; // Q0 +extern const UWord8 hBitsMinus1_N43[7]; // Q0 +extern const UWord8 hBitsMinus1_N44[7]; // Q0 +extern const UWord8 hBitsMinus1_N45[7]; // Q0 +extern const UWord8 hBitsMinus1_N46[7]; // Q0 +extern const UWord8 hBitsMinus1_N47[7]; // Q0 +extern const UWord8 hBitsMinus1_N48[7]; // Q0 +extern const UWord8 hBitsMinus1_N49[7]; // Q0 +extern const UWord8 hBitsMinus1_N50[7]; // Q0 +extern const UWord8 hBitsMinus1_N51[7]; // Q0 +extern const UWord8 hBitsMinus1_N52[7]; // Q0 +extern const UWord8 hBitsMinus1_N53[7]; // Q0 +extern const UWord8 hBitsMinus1_N54[7]; // Q0 +extern const UWord8 hBitsMinus1_N55[7]; // Q0 +extern const UWord8 hBitsMinus1_N56[7]; // Q0 +extern const UWord8 hBitsMinus1_N57[7]; // Q0 +extern const UWord8 hBitsMinus1_N58[7]; // Q0 +extern const UWord8 hBitsMinus1_N59[7]; // Q0 +extern const UWord8 hBitsMinus1_N60[7]; // Q0 +extern const UWord8 hBitsMinus1_N61[6]; // Q0 +extern const UWord8 hBitsMinus1_N62[6]; // Q0 +extern const UWord8 hBitsMinus1_N63[6]; // Q0 +extern const UWord8 hBitsMinus1_N64[6]; // Q0 +extern const UWord8 *const hBitsN[65]; // Q0 +extern const Word16 dsHighDiracsTab[43]; // Q0 +extern const UWord32 intLimCDivInvDQ31[68]; // Q0 +extern const UWord8 obtainEnergyQuantizerDensity_f[57]; // Q0 +extern const Word16 lim_neg_inv_tbl_fx[11]; // Q0 +extern const Word16 fg_inv_tbl_fx[13]; // Q0 /* functions and tables for pvq_indexing */ -extern const uint32_t exactdivodd[ODD_DIV_SIZE]; +extern const UWord32 exactdivodd[ODD_DIV_SIZE]; // Q0 extern const float gain_att[]; -extern const Word16 gain_att_fx[40]; +extern const Word16 gain_att_fx[40]; // Q15 extern const float att_step[]; -extern const Word16 att_step_fx[4]; +extern const Word16 att_step_fx[4]; // Q13 extern const float gain_qlow[]; extern const int16_t gain_cb_size[]; extern const float stab_trans[]; -extern const Word16 stab_trans_fx[]; +extern const Word16 stab_trans_fx[]; // Q15 extern const float env_stab_tp[2][2]; -extern const Word16 env_stab_tp_fx[2][2]; +extern const Word16 env_stab_tp_fx[2][2]; // Q15 /*----------------------------------------------------------------------------------* * SWB BWE for LR MDCT core *----------------------------------------------------------------------------------*/ extern const float gain_table_SWB_BWE[NB_SWB_SUBBANDS]; -extern const Word16 gain_table_SWB_BWE_fx[NB_SWB_SUBBANDS]; +extern const Word16 gain_table_SWB_BWE_fx[NB_SWB_SUBBANDS]; /*Q14 */ /* HQ_NORMAL mode */ -extern const int16_t bits_lagIndices_modeNormal[NB_SWB_SUBBANDS]; -extern const int16_t subband_offsets_12KBPS[NB_SWB_SUBBANDS]; -extern const int16_t subband_offsets_16KBPS[NB_SWB_SUBBANDS]; -extern const int16_t subband_search_offsets[NB_SWB_SUBBANDS]; +extern const Word16 bits_lagIndices_modeNormal[NB_SWB_SUBBANDS]; // Q0 +extern const Word16 subband_offsets_12KBPS[NB_SWB_SUBBANDS]; // Q0 +extern const Word16 subband_offsets_16KBPS[NB_SWB_SUBBANDS]; // Q0 +extern const Word16 subband_search_offsets[NB_SWB_SUBBANDS]; // Q0 -extern const int16_t bw_SPT_tbl[2][SPT_SHORTEN_SBNUM]; +extern const Word16 bw_SPT_tbl[2][SPT_SHORTEN_SBNUM]; // Q0 /* HQ_HARMONIC mode */ -extern const int16_t bits_lagIndices_mode0_Har[NB_SWB_SUBBANDS_HAR_SEARCH_SB]; +extern const Word16 bits_lagIndices_mode0_Har[NB_SWB_SUBBANDS_HAR_SEARCH_SB]; // Q0 -extern const int16_t subband_offsets_sub5_13p2kbps_Har[NB_SWB_SUBBANDS_HAR]; -extern const int16_t subband_search_offsets_13p2kbps_Har[NB_SWB_SUBBANDS_HAR_SEARCH_SB]; -extern const int16_t subband_offsets_sub5_16p4kbps_Har[NB_SWB_SUBBANDS_HAR]; -extern const int16_t subband_search_offsets_16p4kbps_Har[NB_SWB_SUBBANDS_HAR_SEARCH_SB]; +extern const Word16 subband_offsets_sub5_13p2kbps_Har[NB_SWB_SUBBANDS_HAR]; // Q0 +extern const Word16 subband_search_offsets_13p2kbps_Har[NB_SWB_SUBBANDS_HAR_SEARCH_SB]; // Q0 +extern const Word16 subband_offsets_sub5_16p4kbps_Har[NB_SWB_SUBBANDS_HAR]; // Q0 +extern const Word16 subband_search_offsets_16p4kbps_Har[NB_SWB_SUBBANDS_HAR_SEARCH_SB]; // Q0 /*----------------------------------------------------------------------------------* * SC-VBR @@ -1319,46 +1318,46 @@ extern const int16_t subband_search_offsets_16p4kbps_Har[NB_SWB_SUBBANDS_HAR_SEA /* NELP filter coefficients */ extern const float bp1_num_coef_wb[5]; -extern const Word16 bp1_num_coef_wb_fx[5]; +extern const Word16 bp1_num_coef_wb_fx[5]; /* Q14 */ extern const float bp1_den_coef_wb[5]; -extern const Word16 bp1_den_coef_wb_fx[5]; +extern const Word16 bp1_den_coef_wb_fx[5]; /* Q14 */ extern const float shape1_num_coef[11]; -extern const Word16 shape1_num_coef_fx[11]; +extern const Word16 shape1_num_coef_fx[11]; /* Q15 */ extern const float shape1_den_coef[11]; -extern const Word16 shape1_den_coef_fx[11]; +extern const Word16 shape1_den_coef_fx[11]; /* Q15 */ extern const float shape2_num_coef[11]; -extern const Word16 shape2_num_coef_fx[11]; +extern const Word16 shape2_num_coef_fx[11]; /* Q15 */ extern const float shape2_den_coef[11]; -extern const Word16 shape2_den_coef_fx[11]; +extern const Word16 shape2_den_coef_fx[11]; /* Q15 */ extern const float shape3_num_coef[11]; -extern const Word16 shape3_num_coef_fx[11]; +extern const Word16 shape3_num_coef_fx[11]; /* Q15 */ extern const float shape3_den_coef[11]; -extern const Word16 shape3_den_coef_fx[11]; +extern const Word16 shape3_den_coef_fx[11]; /* Q15 */ extern const float txlpf1_num_coef[11]; -extern const Word16 txlpf1_num_coef_fx[11]; +extern const Word16 txlpf1_num_coef_fx[11]; /* Q13 */ extern const float txlpf1_den_coef[11]; -extern const Word16 txlpf1_den_coef_fx[11]; +extern const Word16 txlpf1_den_coef_fx[11]; /* Q13 */ extern const float txhpf1_num_coef[11]; -extern const Word16 txhpf1_num_coef_fx[11]; +extern const Word16 txhpf1_num_coef_fx[11]; /* Q13 */ extern const float txhpf1_den_coef[11]; -extern const Word16 txhpf1_den_coef_fx[11]; +extern const Word16 txhpf1_den_coef_fx[11]; /* Q13 */ extern const float bp1_num_coef_nb_fx_order7_flt[8]; -extern const Word16 bp1_num_coef_nb_fx_order7[8]; +extern const Word16 bp1_num_coef_nb_fx_order7[8]; /* Q13 */ extern const float bp1_den_coef_nb_fx_order7_flt[8]; -extern const Word16 bp1_den_coef_nb_fx_order7[8]; +extern const Word16 bp1_den_coef_nb_fx_order7[8]; /* Q13 */ extern const float num_nelp_lp[NELP_LP_ORDER + 1]; extern const float den_nelp_lp[NELP_LP_ORDER + 1]; @@ -1367,37 +1366,37 @@ extern const float UVG1CB_WB[UVG1_CBSIZE][2]; extern const float UVG2CB1_WB[UVG2_CBSIZE][5]; extern const float UVG2CB2_WB[UVG2_CBSIZE][5]; -extern const Word16 UVG1CB_WB_FX[UVG1_CBSIZE][2]; -extern const Word16 UVG2CB1_WB_FX[UVG2_CBSIZE][5]; -extern const Word16 UVG2CB2_WB_FX[UVG2_CBSIZE][5]; +extern const Word16 UVG1CB_WB_FX[UVG1_CBSIZE][2]; /* Q13 */ +extern const Word16 UVG2CB1_WB_FX[UVG2_CBSIZE][5]; /* Q12 */ +extern const Word16 UVG2CB2_WB_FX[UVG2_CBSIZE][5]; /* Q12 */ extern const float UVG1CB_NB[UVG1_CBSIZE][2]; extern const float UVG2CB1_NB[UVG2_CBSIZE][5]; extern const float UVG2CB2_NB[UVG2_CBSIZE][5]; -extern const Word16 UVG1CB_NB_FX[UVG1_CBSIZE][2]; -extern const Word16 UVG2CB1_NB_FX[UVG2_CBSIZE][5]; -extern const Word16 UVG2CB2_NB_FX[UVG2_CBSIZE][5]; +extern const Word16 UVG1CB_NB_FX[UVG1_CBSIZE][2]; /* Q13 */ +extern const Word16 UVG2CB1_NB_FX[UVG2_CBSIZE][5]; /* Q12 */ +extern const Word16 UVG2CB2_NB_FX[UVG2_CBSIZE][5]; /* Q12 */ extern const float frac_4sf[NB_SUBFR + 2]; -extern const Word16 frac_4sf_fx[NB_SUBFR + 2]; +extern const Word16 frac_4sf_fx[NB_SUBFR + 2]; /* Q4 */ extern const float erb_WB[NUM_ERB_WB + 1]; extern const float erb_NB[NUM_ERB_NB + 1]; -extern const Word16 erb_WB_fx[NUM_ERB_WB + 1]; -extern const Word16 erb_NB_fx[NUM_ERB_NB + 1]; +extern const Word16 erb_WB_fx[NUM_ERB_WB + 1]; // Q(log2(2.56) +extern const Word16 erb_NB_fx[NUM_ERB_NB + 1]; // Q(log2(2.56) extern const float AmpCB1_WB[64][10]; -extern const Word16 AmpCB1_WB_fx[640]; +extern const Word16 AmpCB1_WB_fx[640]; // Q13 extern const float AmpCB2_WB[64][NUM_ERB_WB - 11]; -extern const Word16 AmpCB2_WB_fx[64 * ( NUM_ERB_WB - 13 )]; +extern const Word16 AmpCB2_WB_fx[64 * ( NUM_ERB_WB - 13 )]; // Q13 extern const float AmpCB1_NB[64][10]; -extern const Word16 AmpCB1_NB_fx[640]; +extern const Word16 AmpCB1_NB_fx[640]; // Q13 extern const float AmpCB2_NB[64][NUM_ERB_NB - 11]; -extern const Word16 AmpCB2_NB_fx[64 * ( NUM_ERB_NB - 13 )]; +extern const Word16 AmpCB2_NB_fx[64 * ( NUM_ERB_NB - 13 )]; // Q13 extern const float PowerCB_WB[64][2]; extern const float PowerCB_NB[64][2]; @@ -1407,153 +1406,153 @@ extern const float sinc[8][12]; extern const Word16 sinc_fx[8][12]; extern const float hvq_thr_adj[5]; -extern const Word16 hvq_thr_adj_fx[5]; +extern const Word16 hvq_thr_adj_fx[5]; /* Q15 */ extern const Word16 hvq_index_mapping_fx[4]; extern const float hvq_peak_cb[1024]; -extern const Word16 hvq_peak_cb_fx[]; +extern const Word16 hvq_peak_cb_fx[]; /* Q15 */ extern const float hvq_class_c[16]; -extern const Word16 hvq_class_c_fx[16]; -extern const int16_t hvq_cb_search_overlap24k[17]; -extern const int16_t hvq_cb_search_overlap32k[21]; +extern const Word16 hvq_class_c_fx[16]; /* Q15 */ +extern const Word16 hvq_cb_search_overlap24k[17]; // Q0 +extern const Word16 hvq_cb_search_overlap32k[21]; // Q0 -extern const int16_t hvq_pg_huff_offset[NUM_PG_HUFFLEN]; -extern const int16_t hvq_pg_huff_thres[NUM_PG_HUFFLEN]; -extern const int16_t hvq_pg_huff_tab[32]; +extern const Word16 hvq_pg_huff_offset[NUM_PG_HUFFLEN]; // Q0 +extern const Word16 hvq_pg_huff_thres[NUM_PG_HUFFLEN]; // Q0 +extern const Word16 hvq_pg_huff_tab[32]; // Q0 -extern const int16_t hvq_cp_huff_len[52]; -extern const int16_t hvq_cp_huff_val[52]; -extern const int16_t hvq_cp_layer1_map5[HVQ_CP_MAP_LEN]; +extern const Word16 hvq_cp_huff_len[52]; // Q0 +extern const Word16 hvq_cp_huff_val[52]; // Q0 +extern const Word16 hvq_cp_layer1_map5[HVQ_CP_MAP_LEN]; // Q0 -extern const int16_t hvq_cp_huff_thres[HVQ_CP_HUFF_NUM_LEN]; -extern const int16_t hvq_cp_huff_offset[HVQ_CP_HUFF_NUM_LEN]; -extern const int16_t hvq_cp_huff_tab[52]; +extern const Word16 hvq_cp_huff_thres[HVQ_CP_HUFF_NUM_LEN]; // Q0 +extern const Word16 hvq_cp_huff_offset[HVQ_CP_HUFF_NUM_LEN]; // Q0 +extern const Word16 hvq_cp_huff_tab[52]; // Q0 /*------------------------------------------------------------------------------* * GSC mode *------------------------------------------------------------------------------*/ extern const float sin_table256[]; -extern const Word16 sin_table256_fx[]; -extern const int16_t gsc_sfm_start[]; -extern const int16_t gsc_sfm_end[]; -extern const int16_t gsc_sfm_size[]; +extern const Word16 sin_table256_fx[]; // Q15 +extern const Word16 gsc_sfm_start[]; // Q0 +extern const Word16 gsc_sfm_end[]; // Q0 +extern const Word16 gsc_sfm_size[]; // Q0 extern const float sm_table[]; -extern const Word16 sm_table_fx[]; +extern const Word16 sm_table_fx[]; // Q15 extern const float mfreq_loc[]; -extern const int16_t mfreq_bindiv_loc[]; +extern const Word16 mfreq_bindiv_loc[]; // Q0 extern const float mean_gp[]; -extern const Word16 mean_gp_fx[]; +extern const Word16 mean_gp_fx[]; /*Q14*/ extern const float dic_gp[]; -extern const Word16 dic_gp_fx[]; +extern const Word16 dic_gp_fx[]; /*Q14*/ extern const float Gain_mean[]; extern const float Gain_meanHR[]; extern const float Gain_mean_dic[]; extern const float Gain_mean_dicHR[]; extern const float YG_mean16[]; -extern const Word16 YG_mean16_fx[]; +extern const Word16 YG_mean16_fx[]; /*Q12 */ extern const float YG_dicMR_1[]; extern const float YG_dicMR_2[]; extern const float YG_dicMR_3[]; extern const float YG_dicMR_4[]; -extern const Word16 YG_dicMR_1_fx[]; -extern const Word16 YG_dicMR_2_fx[]; -extern const Word16 YG_dicMR_3_fx[]; -extern const Word16 YG_dicMR_4_fx[]; +extern const Word16 YG_dicMR_1_fx[]; /*Q12 */ +extern const Word16 YG_dicMR_2_fx[]; /*Q12 */ +extern const Word16 YG_dicMR_3_fx[]; /*Q12 */ +extern const Word16 YG_dicMR_4_fx[]; /*Q12 */ extern const float mean_m[]; -extern const Word16 mean_m_fx[]; +extern const Word16 mean_m_fx[]; /*Q12 */ extern const float mean_gain_dic[]; -extern const Word16 mean_gain_dic_fx[]; +extern const Word16 mean_gain_dic_fx[]; /*Q12 */ extern const float YGain_mean_LR[]; -extern const Word16 YGain_mean_LR_fx[]; +extern const Word16 YGain_mean_LR_fx[]; /* Q12 */ extern const float YGain_dic1_LR[]; extern const float YGain_dic2_LR[]; extern const float YGain_dic3_LR[]; -extern const Word16 YGain_dic1_LR_fx[]; -extern const Word16 YGain_dic2_LR_fx[]; /*Q13 */ -extern const Word16 YGain_dic3_LR_fx[]; /*Q13 */ +extern const Word16 YGain_dic1_LR_fx[]; /* Q12 */ +extern const Word16 YGain_dic2_LR_fx[]; /*Q12 */ +extern const Word16 YGain_dic3_LR_fx[]; /*Q12 */ extern const float Gain_dic2_NBHR[]; extern const float Gain_dic3_NBHR[]; -extern const Word16 Gain_dic3_NBHR_fx[]; -extern const Word16 Gain_dic2_NBHR_fx[]; +extern const Word16 Gain_dic3_NBHR_fx[]; /*Q12 */ +extern const Word16 Gain_dic2_NBHR_fx[]; /*Q12 */ extern const float YG_mean16HR[]; -extern const Word16 YG_mean16HR_fx[]; +extern const Word16 YG_mean16HR_fx[]; /* Q12 */ extern const float YG_dicHR_1[]; -extern const Word16 YG_dicHR_1_fx[]; +extern const Word16 YG_dicHR_1_fx[]; /* Q12 */ extern const float YG_dicHR_2[]; -extern const Word16 YG_dicHR_2_fx[]; +extern const Word16 YG_dicHR_2_fx[]; /* Q12 */ extern const float YG_dicHR_3[]; -extern const Word16 YG_dicHR_3_fx[]; +extern const Word16 YG_dicHR_3_fx[]; /* Q12 */ extern const float YG_mean16HR_16kHz[]; -extern const Word16 YG_mean16HR_16kHz_fx[]; +extern const Word16 YG_mean16HR_16kHz_fx[]; /* Q12 */ extern const float YG_dicHR_4_16kHz[]; -extern const Word16 YG_dicHR_4_16kHz_fx[]; +extern const Word16 YG_dicHR_4_16kHz_fx[]; /* Q12 */ extern const float YG_meanL2G_16kHz[]; -extern const Word16 YG_meanL2G_16kHz_fx[]; +extern const Word16 YG_meanL2G_16kHz_fx[]; /* Q12 */ extern const float YG_dicL2G_16kHz[]; -extern const Word16 YG_dicL2G_16kHz_fx[]; -extern const int16_t GSC_freq_bits[]; -extern const Word32 GSC_freq_bits_fx[]; -extern const Word32 GSC_freq_bits_fx_Q18[]; -extern const int16_t GSC_freq_DL0_bits[]; -extern const int16_t Compl_GSC_freq_bits[]; +extern const Word16 YG_dicL2G_16kHz_fx[]; /* Q12 */ +extern const Word16 GSC_freq_bits[]; // Q0 +extern const Word32 GSC_freq_bits_fx[]; /*Q18*/ +extern const Word32 GSC_freq_bits_fx_Q18[]; /*Q18*/ +extern const Word16 GSC_freq_DL0_bits[]; /* Q0 */ +extern const Word16 Compl_GSC_freq_bits[]; /* Q0 */ extern const float Gain_meanNB[]; -extern const Word16 Gain_meanNB_fx[]; +extern const Word16 Gain_meanNB_fx[]; /*Q12*/ extern const float Gain_mean_dicNB[]; -extern const Word16 Gain_mean_dicNB_fx[]; +extern const Word16 Gain_mean_dicNB_fx[]; /*Q12 */ extern const float Mean_dic_NB[]; -extern const Word16 Mean_dic_NB_fx[]; +extern const Word16 Mean_dic_NB_fx[]; /*Q12 */ extern const float Gain_dic1_NB[]; extern const float Gain_dic2_NB[]; extern const float Gain_dic3_NB[]; -extern const Word16 Gain_dic1_NB_fx[]; -extern const Word16 Gain_dic2_NB_fx[]; -extern const Word16 Gain_dic3_NB_fx[]; +extern const Word16 Gain_dic1_NB_fx[]; /*Q12 */ +extern const Word16 Gain_dic2_NB_fx[]; /*Q12 */ +extern const Word16 Gain_dic3_NB_fx[]; /*Q12 */ /*------------------------------------------------------------------------------* * FFT transform *------------------------------------------------------------------------------*/ -extern const int16_t Odx_fft64[64]; +extern const Word16 Odx_fft64[64]; // Q0 extern const float w_fft64[32]; -extern const int16_t Ip_fft64[6]; -extern const int16_t Odx_fft32_15[32]; +extern const Word16 Ip_fft64[6]; // Q0 +extern const Word16 Odx_fft32_15[32]; // Q0 extern const float w_fft32[16]; -extern const Word32 w_fft32_16fx[16]; -extern const int16_t Ip_fft32[6]; -extern const int16_t Odx_fft32_5[32]; -extern const int16_t Odx_fft16[16]; +extern const Word32 w_fft32_16fx[16]; // Q30 +extern const Word16 Ip_fft32[6]; // Q0 +extern const Word16 Odx_fft32_5[32]; // Q0 +extern const Word16 Odx_fft16[16]; // Q0 extern const float w_fft16[8]; -extern const int16_t Ip_fft16[6]; +extern const Word16 Ip_fft16[6]; // Q0 extern const float w_fft8[8]; -extern const int16_t Ip_fft8[6]; -extern const int16_t Idx_dortft80[80]; -extern const int16_t Idx_dortft120[120]; -extern const int16_t Idx_dortft160[160]; -extern const int16_t Idx_dortft320[320]; -extern const int16_t Idx_dortft480[480]; -extern const int16_t Ip_fft128[10]; +extern const Word16 Ip_fft8[6]; // Q0 +extern const Word16 Idx_dortft80[80]; // Q0 +extern const Word16 Idx_dortft120[120]; // Q0 +extern const Word16 Idx_dortft160[160]; // Q0 +extern const Word16 Idx_dortft320[320]; // Q0 +extern const Word16 Idx_dortft480[480]; // Q0 +extern const Word16 Ip_fft128[10]; // Q0 extern const float w_fft128[64]; -extern const Word32 w_fft128_16fx[64]; -extern const int16_t Ip_fft256[10]; +extern const Word32 w_fft128_16fx[64]; // Q30 +extern const Word16 Ip_fft256[10]; // Q0 extern const float w_fft256[128]; -extern const int16_t Ip_fft512[18]; +extern const Word16 Ip_fft512[18]; // Q0 extern const float w_fft512[256]; -extern const Word16 w_fft512_fx_evs[256]; +extern const Word16 w_fft512_fx_evs[256]; // Q14 // extern const Word16 w_fft512_fx[256]; -extern const int16_t Idx_dortft40[40]; -extern const int16_t Odx_fft8_5[8]; -extern const int16_t ip_edct2_64[6]; +extern const Word16 Idx_dortft40[40]; // Q0 +extern const Word16 Odx_fft8_5[8]; // Q0 +extern const Word16 ip_edct2_64[6]; // Q0 extern const float w_edct2_64[80]; -extern const Word16 w_edct2_64_fx[80]; -extern const int16_t Idx_dortft20[20]; -extern const int16_t Odx_fft4_5[4]; +extern const Word16 w_edct2_64_fx[80]; /*Q14 */ +extern const Word16 Idx_dortft20[20]; // Q0 +extern const Word16 Odx_fft4_5[4]; // Q0 extern const float w_fft4[2]; -extern const int16_t Ip_fft4[6]; +extern const Word16 Ip_fft4[6]; // Q0 extern const float FFT_RotVector_32[40]; extern const float FFT_RotVector_256[448]; @@ -1570,21 +1569,21 @@ extern const float FFT_RotVector_960[1860]; extern const float Asr_LP32[41]; extern const float Asr_LP16[21]; extern const float Asr_LP48[61]; -extern const Word16 Asr_LP32_fx[41]; -extern const Word16 Asr_LP16_fx[21]; -extern const Word16 Asr_LP48_fx[61]; +extern const Word16 Asr_LP32_fx[41]; // Q15 +extern const Word16 Asr_LP16_fx[21]; // Q15 +extern const Word16 Asr_LP48_fx[61]; // Q15 -extern const int16_t Num_bands_NB[]; +extern const Word16 Num_bands_NB[]; // Q0 extern const float SmoothingWin_NB875[]; extern const float SmoothingWin_NB2[]; -extern const Word16 SmoothingWin_NB875_fx[]; -extern const Word16 SmoothingWin_NB2_fx[]; +extern const Word16 SmoothingWin_NB875_fx[]; /* Q15 */ +extern const Word16 SmoothingWin_NB2_fx[]; /* Q15 */ /*----------------------------------------------------------------------------------* * CLDFB *----------------------------------------------------------------------------------*/ -extern const int16_t freqTable[2]; +extern const Word16 freqTable[2]; // Q0 extern const float CLDFB80_10_flt[100]; extern const float CLDFB80_16_flt[160]; @@ -1620,13 +1619,13 @@ extern const float rot_vec_ana_im_L40[20]; extern const float rot_vec_ana_re_L60[30]; extern const float rot_vec_ana_im_L60[30]; -extern const Word16 CLDFB80_10[100]; -extern const Word16 CLDFB80_16[160]; -extern const Word16 CLDFB80_20[200]; -extern const Word16 CLDFB80_32[320]; -extern const Word16 CLDFB80_40[400]; -extern const Word16 CLDFB80_60[600]; -extern const Word16 CLDFB80_30[300]; +extern const Word16 CLDFB80_10[100]; // Q.5 +extern const Word16 CLDFB80_16[160]; // Q.5 +extern const Word16 CLDFB80_20[200]; // Q.5 +extern const Word16 CLDFB80_32[320]; // Q.5 +extern const Word16 CLDFB80_40[400]; // Q.5 +extern const Word16 CLDFB80_60[600]; // Q.5 +extern const Word16 CLDFB80_30[300]; // Q.5 #ifdef IVAS_FLOAT_FIXED extern const Word16 LDQMF_10_enc_fx[100]; extern const Word16 LDQMF_16_enc_fx[160]; @@ -1637,28 +1636,28 @@ extern const Word16 LDQMF_40_enc_fx[400]; extern const Word16 LDQMF_60_enc_fx[600]; #endif -extern const Word16 rRotVectr_10[]; -extern const Word16 iRotVectr_10[]; -extern const Word16 rRotVectr_16[]; -extern const Word16 iRotVectr_16[]; -extern const Word16 rRotVectr_20[]; -extern const Word16 iRotVectr_20[]; -extern const Word16 rRotVectr_32[]; -extern const Word16 iRotVectr_32[]; -extern const Word16 rRotVectr_40[]; -extern const Word16 iRotVectr_40[]; -extern const Word16 rRotVectr_60[]; -extern const Word16 iRotVectr_60[]; -extern const Word16 rRotVectr_30[]; -extern const Word16 iRotVectr_30[]; - -extern const Word16 cldfb_anaScale[]; -extern const Word16 cldfb_synScale[]; -extern const Word16 cldfb_synGain[]; +extern const Word16 rRotVectr_10[]; // Q(sqrt(1.0/16.00)) +extern const Word16 iRotVectr_10[]; // Q(sqrt(1.0/16.00)) +extern const Word16 rRotVectr_16[]; // Q(sqrt(1.0/8.00)) +extern const Word16 iRotVectr_16[]; // Q(sqrt(1.0/8.00)) +extern const Word16 rRotVectr_20[]; // Q(sqrt(1.0/8.00)) +extern const Word16 iRotVectr_20[]; // Q(sqrt(1.0/8.00) +extern const Word16 rRotVectr_32[]; // Q(sqrt(1.0/4.00)) +extern const Word16 iRotVectr_32[]; // Q(sqrt(1.0/4.00)) +extern const Word16 rRotVectr_40[]; // Q(sqrt(1.0/4.00)) +extern const Word16 iRotVectr_40[]; // Q(sqrt(1.0/4.00)) +extern const Word16 rRotVectr_60[]; // Q(sqrt(1.0/2.00)) +extern const Word16 iRotVectr_60[]; // Q(sqrt(1.0/2.00)) +extern const Word16 rRotVectr_30[]; // Q(sqrt(1.0/4.00)) +extern const Word16 iRotVectr_30[]; // Q(sqrt(1.0/4.00)) + +extern const Word16 cldfb_anaScale[]; // Q0 +extern const Word16 cldfb_synScale[]; // Q0 +extern const Word16 cldfb_synGain[]; // Q0 extern const Word16 *cldfb_protoFilter_2_5ms[]; -extern const Word16 *cldfb_protoFilter_5_0ms[]; -extern const Word16 cldfb_scale_2_5ms[7]; -extern const Word16 cldfb_scale_5_0ms[7]; +// extern const Word16 *cldfb_protoFilter_5_0ms[]; +extern const Word16 cldfb_scale_2_5ms[7]; // Q8 +extern const Word16 cldfb_scale_5_0ms[7]; // Q8 extern const float rot_vec_syn_re_L10[5]; @@ -1676,51 +1675,51 @@ extern const float rot_vec_syn_im_L40[20]; extern const float rot_vec_syn_re_L60[30]; extern const float rot_vec_syn_im_L60[30]; -extern const Word32 rot_vec_syn_re_L10_fx[5]; -extern const Word32 rot_vec_syn_im_L10_fx[5]; -extern const Word32 rot_vec_syn_re_L16_fx[8]; -extern const Word32 rot_vec_syn_im_L16_fx[8]; -extern const Word32 rot_vec_syn_re_L20_fx[10]; -extern const Word32 rot_vec_syn_im_L20_fx[10]; -extern const Word32 rot_vec_syn_re_L30_fx[15]; -extern const Word32 rot_vec_syn_im_L30_fx[15]; -extern const Word32 rot_vec_syn_re_L32_fx[16]; -extern const Word32 rot_vec_syn_im_L32_fx[16]; -extern const Word32 rot_vec_syn_re_L40_fx[20]; -extern const Word32 rot_vec_syn_im_L40_fx[20]; -extern const Word32 rot_vec_syn_re_L60_fx[30]; -extern const Word32 rot_vec_syn_im_L60_fx[30]; +extern const Word32 rot_vec_syn_re_L10_fx[5]; // Q31 +extern const Word32 rot_vec_syn_im_L10_fx[5]; // Q31 +extern const Word32 rot_vec_syn_re_L16_fx[8]; // Q31 +extern const Word32 rot_vec_syn_im_L16_fx[8]; // Q31 +extern const Word32 rot_vec_syn_re_L20_fx[10]; // Q31 +extern const Word32 rot_vec_syn_im_L20_fx[10]; // Q31 +extern const Word32 rot_vec_syn_re_L30_fx[15]; // Q31 +extern const Word32 rot_vec_syn_im_L30_fx[15]; // Q31 +extern const Word32 rot_vec_syn_re_L32_fx[16]; // Q31 +extern const Word32 rot_vec_syn_im_L32_fx[16]; // Q31 +extern const Word32 rot_vec_syn_re_L40_fx[20]; // Q31 +extern const Word32 rot_vec_syn_im_L40_fx[20]; // Q31 +extern const Word32 rot_vec_syn_re_L60_fx[30]; // Q31 +extern const Word32 rot_vec_syn_im_L60_fx[30]; // Q31 extern const float bpf_weights_16[CLDFB_NO_COL_MAX]; -extern const Word16 bpf_weights_16_Fx[16]; -extern const Word16 bpf_weights_16_ivas_fx[16]; -extern const Word32 bpf_weights_16_ivas_fx_32[16]; +extern const Word16 bpf_weights_16_Fx[16]; // Q15 +extern const Word16 bpf_weights_16_ivas_fx[16]; // Q15 +extern const Word32 bpf_weights_16_ivas_fx_32[16]; // Q30 extern const float CNG_details_codebook[64][NUM_ENV_CNG]; -extern const Word16 CNG_details_codebook_fx[64][NUM_ENV_CNG]; +extern const Word16 CNG_details_codebook_fx[64][NUM_ENV_CNG]; // Q6 /*----------------------------------------------------------------------------------* * FD CNG *----------------------------------------------------------------------------------*/ -extern const int16_t d_array[SIZE_SCALE_TABLE_CN]; +extern const Word16 d_array[SIZE_SCALE_TABLE_CN]; // Q0 extern const float m_array_flt[SIZE_SCALE_TABLE_CN]; -extern const Word16 m_array[SIZE_SCALE_TABLE_CN]; +extern const Word16 m_array[SIZE_SCALE_TABLE_CN]; // Q15 extern const float msQeqInvAv_thresh_flt[3]; -extern const Word16 msQeqInvAv_thresh[3]; +extern const Word16 msQeqInvAv_thresh[3]; // Q15 extern const float msNoiseSlopeMax_flt[4]; -extern const Word16 msNoiseSlopeMax[4]; +extern const Word16 msNoiseSlopeMax[4]; // Q15 -extern const SCALE_SETUP scaleTableStereo[SIZE_SCALE_TABLE_STEREO]; -extern const SCALE_SETUP scaleTableMono[SIZE_SCALE_TABLE_MONO]; -extern const SCALE_SETUP scaleTable_cn_only[SIZE_SCALE_TABLE_CN]; -extern const SCALE_SETUP scaleTable_cn_dirac[15]; +extern const SCALE_SETUP scaleTableStereo[SIZE_SCALE_TABLE_STEREO]; // Q7 +extern const SCALE_SETUP scaleTableMono[SIZE_SCALE_TABLE_MONO]; // Q7 +extern const SCALE_SETUP scaleTable_cn_only[SIZE_SCALE_TABLE_CN]; // Q14 +extern const SCALE_SETUP scaleTable_cn_dirac[15]; // Q14 extern const float scaleTable_cn_only_amrwbio_flt[SIZE_SCALE_TABLE_CN_AMRWB][2]; -extern const Word16 scaleTable_cn_only_amrwbio[SIZE_SCALE_TABLE_CN_AMRWB][2]; -extern const Word32 scaleTable_cn_only_amrwbio_fx_by_10f[SIZE_SCALE_TABLE_CN_AMRWB][2]; +extern const Word16 scaleTable_cn_only_amrwbio[SIZE_SCALE_TABLE_CN_AMRWB][2]; // Q14 +extern const Word32 scaleTable_cn_only_amrwbio_fx_by_10f[SIZE_SCALE_TABLE_CN_AMRWB][2]; // Q29 -extern const int16_t sidparts_encoder_noise_est[SIZE_SIDPARTS_ENC_NOISE_EST]; +extern const Word16 sidparts_encoder_noise_est[SIZE_SIDPARTS_ENC_NOISE_EST]; // Q0 extern const FD_CNG_SETUP FdCngSetup_nb; @@ -1731,14 +1730,14 @@ extern const FD_CNG_SETUP FdCngSetup_swb1; extern const FD_CNG_SETUP FdCngSetup_swb1_stereo; extern const FD_CNG_SETUP FdCngSetup_swb2; -extern const int16_t levels_37bits[FD_CNG_stages_37bits]; -extern const int16_t bits_37bits[FD_CNG_stages_37bits]; +extern const Word16 levels_37bits[FD_CNG_stages_37bits]; // Q0 +extern const Word16 bits_37bits[FD_CNG_stages_37bits]; // Q0 extern const float *const cdk_37bits_flt[]; extern const float *const cdk_37bits_ivas[]; -extern Word16 const *const cdk_37bits[]; -extern Word16 const *const ivas_cdk_37bits_fx[]; +extern Word16 const *const cdk_37bits[]; // Q7 +extern Word16 const *const ivas_cdk_37bits_fx[]; // Q7 extern const float fftSineTab640[321]; -extern const Word16 fftSineTab640_fx[321]; +extern const Word16 fftSineTab640_fx[321]; // Q15 extern const float olapWinAna512[512]; extern const float olapWinAna640[640]; @@ -1748,50 +1747,50 @@ extern const Word32 olapWinAna640_fx[640]; // Q30 #endif // IVAS_FLOAT_FIXED extern const float olapWinSyn256[256]; -extern const Word16 olapWinSyn256_fx[256]; +extern const Word16 olapWinSyn256_fx[256]; // Q15 extern const float olapWinSyn320[320]; -extern const Word16 olapWinSyn320_fx[320]; +extern const Word16 olapWinSyn320_fx[320]; // Q15 #ifdef ERI_FDCNGVQ_LOW_ROM_TESTING extern const float *const cdk_37bits_ivas_orig[]; #endif -extern const Word8 cdk1_ivas_dct_s0_W8[]; -extern const Word8 cdk1_ivas_dct_s1_W8[]; -extern const Word8 cdk1_ivas_dct_s2_W8[]; -extern const Word8 cdk1_ivas_dct_s3_W8[]; -extern const Word8 *const cdk_37bits_ivas_stage1_W8Qx_dct_sections[]; +extern const Word8 cdk1_ivas_dct_s0_W8[]; // Q0 +extern const Word8 cdk1_ivas_dct_s1_W8[]; // Q0 +extern const Word8 cdk1_ivas_dct_s2_W8[]; // Q0 +extern const Word8 cdk1_ivas_dct_s3_W8[]; // Q0 +extern const Word8 *const cdk_37bits_ivas_stage1_W8Qx_dct_sections[]; // Q0 -extern const Word16 cdk1_ivas_entries_per_segment[]; -extern const Word16 cdk1_ivas_cum_entries_per_segment[]; -extern const Word16 cdk1_ivas_cols_per_segment[]; -extern const Word16 cdk1_ivas_trunc_dct_cols_per_segment[]; +extern const Word16 cdk1_ivas_entries_per_segment[]; // Q0 +extern const Word16 cdk1_ivas_cum_entries_per_segment[]; // Q0 +extern const Word16 cdk1_ivas_cols_per_segment[]; // Q0 +extern const Word16 cdk1_ivas_trunc_dct_cols_per_segment[]; // Q0 -extern const Word16 *stage1_dct_col_syn_shift[]; +extern const Word16 *stage1_dct_col_syn_shift[]; // Q0 extern const float cdk1r_tr_midQ_truncQ[]; #ifdef IVAS_FLOAT_FIXED -extern const Word16 cdk1r_tr_midQ_truncQ_fx[]; +extern const Word16 cdk1r_tr_midQ_truncQ_fx[]; // Q10 #endif extern const float fdcng_dct_invScaleF[]; extern const float fdcng_dct_scaleF[]; -extern const Word32 fdcng_dct_scaleF_fx[]; +extern const Word32 fdcng_dct_scaleF_fx[]; // Q31 -extern const Word16 unique_idctT2_24coeffsQ16[]; +extern const Word16 unique_idctT2_24coeffsQ16[]; // Q16 extern const Word8 idctT2_24_compressed_idx[]; -extern const Word16 unique_idctT2_21coeffsQ16[]; -extern const Word8 idctT2_21_compressed_idx[]; +extern const Word16 unique_idctT2_21coeffsQ16[]; // Q16 +extern const Word8 idctT2_21_compressed_idx[]; // Q0 extern const float idctT2_24_X_matrixFloatQ[]; -extern const Word16 cdk1_ivas_entries_per_segment[]; -extern const Word16 cdk1_ivas_cum_entries_per_segment[]; +extern const Word16 cdk1_ivas_entries_per_segment[]; // Q0 +extern const Word16 cdk1_ivas_cum_entries_per_segment[]; // Q0 /* circular mse ordered list fwd/rev directions for candidate evaluations */ -extern const Word8 cdk1_ivas_segm_neighbour_fwd[]; -extern const Word8 cdk1_ivas_segm_neighbour_rev[]; +extern const Word8 cdk1_ivas_segm_neighbour_fwd[]; // Q0 +extern const Word8 cdk1_ivas_segm_neighbour_rev[]; // Q0 extern const float cdk_37bits_1[]; @@ -1808,20 +1807,20 @@ extern const float cdk_37bits_6[]; extern const float gain_corr_fac_flt[]; extern const float gain_corr_inv_fac_flt[]; -extern const Word16 gain_corr_fac[]; /*pow(10,2^(-n-2)/28)*/ -extern const Word16 gain_corr_inv_fac[]; /*pow(10,-2^(-n-2)/28)*/ +extern const Word16 gain_corr_fac[]; /*pow(10,2^(-n-2)/28)(1Q14)*/ +extern const Word16 gain_corr_inv_fac[]; /*pow(10,-2^(-n-2)/28)(0Q15)*/ -extern const SCALE_TCX_SETUP scaleTcxTable[SIZE_SCALE_TABLE_TCX]; +extern const SCALE_TCX_SETUP scaleTcxTable[SIZE_SCALE_TABLE_TCX]; // Q15 /*----------------------------------------------------------------------------------* * Arithmetic coder *----------------------------------------------------------------------------------*/ -extern const uint8_t ari_lookup_s17_LC[4096]; -extern const uint16_t ari_pk_s17_LC_ext[64][18]; +extern const UWord8 ari_lookup_s17_LC[4096]; // Q0 +extern const UWord16 ari_pk_s17_LC_ext[64][18]; // Q0 -extern const int16_t NumRatioBits[2][17]; +extern const Word16 NumRatioBits[2][17]; // Q0 extern const float Ratios_WB_2[32]; extern const float Ratios_WB_3[32]; extern const float Ratios_WB_4[32]; @@ -1858,41 +1857,41 @@ extern const float Ratios_NB_17[4]; extern const float Ratios_NB_18[4]; extern const float *const Ratios[2][17]; -extern const Word16 Ratios_WB_2_fx[32]; -extern const Word16 Ratios_WB_3_fx[32]; -extern const Word16 Ratios_WB_4_fx[32]; -extern const Word16 Ratios_WB_5_fx[32]; -extern const Word16 Ratios_WB_6_fx[32]; -extern const Word16 Ratios_WB_7_fx[32]; -extern const Word16 Ratios_WB_8_fx[16]; -extern const Word16 Ratios_WB_9_fx[16]; -extern const Word16 Ratios_WB_10_fx[16]; -extern const Word16 Ratios_WB_11_fx[16]; -extern const Word16 Ratios_WB_12_fx[16]; -extern const Word16 Ratios_WB_13_fx[16]; -extern const Word16 Ratios_WB_14_fx[16]; -extern const Word16 Ratios_WB_15_fx[16]; -extern const Word16 Ratios_WB_16_fx[4]; -extern const Word16 Ratios_WB_17_fx[4]; -extern const Word16 Ratios_WB_18_fx[4]; -extern const Word16 Ratios_NB_2_fx[32]; -extern const Word16 Ratios_NB_3_fx[16]; -extern const Word16 Ratios_NB_4_fx[16]; -extern const Word16 Ratios_NB_5_fx[16]; -extern const Word16 Ratios_NB_6_fx[16]; -extern const Word16 Ratios_NB_7_fx[16]; -extern const Word16 Ratios_NB_8_fx[16]; -extern const Word16 Ratios_NB_9_fx[8]; -extern const Word16 Ratios_NB_10_fx[8]; -extern const Word16 Ratios_NB_11_fx[8]; -extern const Word16 Ratios_NB_12_fx[8]; -extern const Word16 Ratios_NB_13_fx[4]; -extern const Word16 Ratios_NB_14_fx[4]; -extern const Word16 Ratios_NB_15_fx[4]; -extern const Word16 Ratios_NB_16_fx[4]; -extern const Word16 Ratios_NB_17_fx[4]; -extern const Word16 Ratios_NB_18_fx[4]; -extern const Word16 *const Ratios_fx[2][17]; +extern const Word16 Ratios_WB_2_fx[32]; /* 7Q8 */ +extern const Word16 Ratios_WB_3_fx[32]; /* 7Q8 */ +extern const Word16 Ratios_WB_4_fx[32]; /* 7Q8 */ +extern const Word16 Ratios_WB_5_fx[32]; /* 7Q8 */ +extern const Word16 Ratios_WB_6_fx[32]; /* 7Q8 */ +extern const Word16 Ratios_WB_7_fx[32]; /* 7Q8 */ +extern const Word16 Ratios_WB_8_fx[16]; /* 7Q8 */ +extern const Word16 Ratios_WB_9_fx[16]; /* 7Q8 */ +extern const Word16 Ratios_WB_10_fx[16]; /* 7Q8 */ +extern const Word16 Ratios_WB_11_fx[16]; /* 7Q8 */ +extern const Word16 Ratios_WB_12_fx[16]; /* 7Q8 */ +extern const Word16 Ratios_WB_13_fx[16]; /* 7Q8 */ +extern const Word16 Ratios_WB_14_fx[16]; /* 7Q8 */ +extern const Word16 Ratios_WB_15_fx[16]; /* 7Q8 */ +extern const Word16 Ratios_WB_16_fx[4]; /* 7Q8 */ +extern const Word16 Ratios_WB_17_fx[4]; /* 7Q8 */ +extern const Word16 Ratios_WB_18_fx[4]; /* 7Q8 */ +extern const Word16 Ratios_NB_2_fx[32]; /* 7Q8 */ +extern const Word16 Ratios_NB_3_fx[16]; /* 7Q8 */ +extern const Word16 Ratios_NB_4_fx[16]; /* 7Q8 */ +extern const Word16 Ratios_NB_5_fx[16]; /* 7Q8 */ +extern const Word16 Ratios_NB_6_fx[16]; /* 7Q8 */ +extern const Word16 Ratios_NB_7_fx[16]; /* 7Q8 */ +extern const Word16 Ratios_NB_8_fx[16]; /* 7Q8 */ +extern const Word16 Ratios_NB_9_fx[8]; /* 7Q8 */ +extern const Word16 Ratios_NB_10_fx[8]; /* 7Q8 */ +extern const Word16 Ratios_NB_11_fx[8]; /* 7Q8 */ +extern const Word16 Ratios_NB_12_fx[8]; /* 7Q8 */ +extern const Word16 Ratios_NB_13_fx[4]; /* 7Q8 */ +extern const Word16 Ratios_NB_14_fx[4]; /* 7Q8 */ +extern const Word16 Ratios_NB_15_fx[4]; /* 7Q8 */ +extern const Word16 Ratios_NB_16_fx[4]; /* 7Q8 */ +extern const Word16 Ratios_NB_17_fx[4]; /* 7Q8 */ +extern const Word16 Ratios_NB_18_fx[4]; /* 7Q8 */ +extern const Word16 *const Ratios_fx[2][17]; /* 7Q8 */ extern const Word16 qGains[2][1 << kTcxHmNumGainBits]; @@ -1916,7 +1915,7 @@ extern const struct TnsParameters tnsParameters48kHz_grouped[2]; extern const struct TnsParameters tnsParameters32kHz_Stereo[2]; extern const float tnsAcfWindow[TNS_MAX_FILTER_ORDER]; -extern const Word16 tnsAcfWindow_fx[TNS_MAX_FILTER_ORDER]; +extern const Word16 tnsAcfWindow_fx[TNS_MAX_FILTER_ORDER]; // Q15 extern const ParamsBitMap tnsEnabledSWBTCX20BitMap; extern const ParamsBitMap tnsEnabledSWBTCX10BitMap; @@ -1948,7 +1947,7 @@ extern const Coding codesTnsCoeff3WB[]; extern const Coding codesTnsCoeff456[]; extern const Coding codesTnsCoeff7[]; -extern const int16_t nTnsCoeffCodes; +extern const Word16 nTnsCoeffCodes; // Q0 extern const Coding *const codesTnsCoeffSWBTCX20[]; extern const Coding *const codesTnsCoeffSWBTCX10[]; @@ -1958,7 +1957,7 @@ extern const int16_t nTnsCoeffTables; extern const Coding codesTnsOrderTCX20[]; extern const Coding codesTnsOrderTCX10[]; extern const Coding codesTnsOrder[]; -extern const int16_t nTnsOrderCodes; +extern const Word16 nTnsOrderCodes; // Q0 extern const float tnsCoeff4_flt[16]; extern const Word16 tnsCoeff4[16]; @@ -1969,48 +1968,48 @@ extern const Word16 tnsCoeff4[16]; typedef struct igf_mode_type { - int32_t sampleRate; - int16_t frameLength; - int16_t igfMinFq; - int16_t maxHopsize; + Word32 sampleRate; // Q0 + Word16 frameLength; // Q0 + Word16 igfMinFq; // Q0 + Word16 maxHopsize; // Q0 } IGF_MODE; extern const IGF_MODE igfMode[IGF_BITRATE_UNKNOWN]; -extern const Word16 swb_offset_LB_new[IGF_BITRATE_UNKNOWN][IGF_MAX_SFB]; -extern const int16_t igf_tile_offset_table[IGF_BITRATE_UNKNOWN][2 * IGF_MAX_TILES + 1]; +extern const Word16 swb_offset_LB_new[IGF_BITRATE_UNKNOWN][IGF_MAX_SFB]; // Q0 +extern const Word16 igf_tile_offset_table[IGF_BITRATE_UNKNOWN][2 * IGF_MAX_TILES + 1]; // Q0 extern const float igf_whitening_TH_flt[IGF_BITRATE_UNKNOWN][2][IGF_MAX_TILES]; -extern const Word16 igf_whitening_TH[][2][IGF_MAX_TILES]; +extern const Word16 igf_whitening_TH[][2][IGF_MAX_TILES]; // Q13 #ifdef IVAS_FLOAT_FIXED -extern const Word16 igf_whitening_TH_ivas_fx[IGF_BITRATE_UNKNOWN][2][IGF_MAX_TILES]; -#endif // IVAS_FLOAT_FIXED -extern const int16_t cf_off_se01_tab[10]; -extern const int16_t cf_off_se10_tab; -extern const int16_t cf_off_se02_tab[10][IGF_CTX_COUNT]; -extern const int16_t cf_off_se11_tab[IGF_CTX_COUNT][IGF_CTX_COUNT]; -extern const uint16_t cf_se00_tab[IGF_SYMBOLS_IN_TABLE + 1]; -extern const uint16_t cf_se01_tab[10][IGF_SYMBOLS_IN_TABLE + 1]; -extern const uint16_t cf_se02_tab[10][IGF_CTX_COUNT][IGF_SYMBOLS_IN_TABLE + 1]; -extern const uint16_t cf_se10_tab[IGF_SYMBOLS_IN_TABLE + 1]; -extern const uint16_t cf_se11_tab[IGF_CTX_COUNT][IGF_CTX_COUNT][IGF_SYMBOLS_IN_TABLE + 1]; +extern const Word16 igf_whitening_TH_ivas_fx[IGF_BITRATE_UNKNOWN][2][IGF_MAX_TILES]; // Q13 +#endif // IVAS_FLOAT_FIXED +extern const Word16 cf_off_se01_tab[10]; // Q0 +extern const Word16 cf_off_se10_tab; // Q0 +extern const Word16 cf_off_se02_tab[10][IGF_CTX_COUNT]; // Q0 +extern const Word16 cf_off_se11_tab[IGF_CTX_COUNT][IGF_CTX_COUNT]; // Q0 +extern const UWord16 cf_se00_tab[IGF_SYMBOLS_IN_TABLE + 1]; // Q0 +extern const UWord16 cf_se01_tab[10][IGF_SYMBOLS_IN_TABLE + 1]; // Q0 +extern const UWord16 cf_se02_tab[10][IGF_CTX_COUNT][IGF_SYMBOLS_IN_TABLE + 1]; // Q0 +extern const UWord16 cf_se10_tab[IGF_SYMBOLS_IN_TABLE + 1]; // Q0 +extern const UWord16 cf_se11_tab[IGF_CTX_COUNT][IGF_CTX_COUNT][IGF_SYMBOLS_IN_TABLE + 1]; // Q0 extern const float normReciprocal[CHEAP_NORM_SIZE]; extern const float *const w_a_float[7]; -extern const PWord16 SineTable512_fx[]; -extern const Word16 ldCoeff[7]; -extern const UWord32 exp2_tab_long[32]; -extern const UWord32 exp2w_tab_long[32]; -extern const UWord32 exp2x_tab_long[32]; -extern const Word16 invTable[INV_TABLE_SIZE + 1]; -extern const Word16 sqrtTable[SQRT_TABLE_SIZE + 1]; -extern const Word16 invSqrtTable[SQRT_TABLE_SIZE + 1]; +extern const PWord16 SineTable512_fx[]; // Q15 +extern const Word16 ldCoeff[7]; // Q15 +extern const UWord32 exp2_tab_long[32]; // Q31 +extern const UWord32 exp2w_tab_long[32]; // Q31 +extern const UWord32 exp2x_tab_long[32]; // Q31 +extern const Word16 invTable[INV_TABLE_SIZE + 1]; // Q15 +extern const Word16 sqrtTable[SQRT_TABLE_SIZE + 1]; // Q15 +extern const Word16 invSqrtTable[SQRT_TABLE_SIZE + 1]; // Q15 extern const float tcx_mdct_window_48[420]; -extern const Word16 tcx_mdct_window_48_fx[420]; +extern const Word16 tcx_mdct_window_48_fx[420]; // Q15 extern const float tcx_mdct_window_half_48[180]; -extern const Word16 tcx_mdct_window_half_48_fx[180]; +extern const Word16 tcx_mdct_window_half_48_fx[180]; // Q15 extern const float tcx_mdct_window_trans_48[60]; -extern const Word16 tcx_mdct_window_trans_48_fx[60]; +extern const Word16 tcx_mdct_window_trans_48_fx[60]; // Q15 /*----------------------------------------------------------------------------------* @@ -2018,140 +2017,140 @@ extern const Word16 tcx_mdct_window_trans_48_fx[60]; *----------------------------------------------------------------------------------*/ extern const float sigma_BWE[]; -extern const Word32 sigma_BWE_fx[]; +extern const Word32 sigma_BWE_fx[]; // Q31 extern const float inv_sigma_BWE[]; -extern const Word16 inv_modified_sigma_BWE_fx[]; -extern const Word16 modified_sigma_BWE_fx[]; +extern const Word16 inv_modified_sigma_BWE_fx[]; // Q1 +extern const Word16 modified_sigma_BWE_fx[]; // Q(log2(2.56) extern const float scales_BWE[]; -extern const Word8 no_lead_BWE[]; +extern const Word8 no_lead_BWE[]; // Q0 extern const float scales_BWE_3b[]; -extern const Word16 scales_BWE_fx[]; -extern const Word16 scales_BWE_fx_new[]; -extern const Word16 scales_BWE_3b_fx[]; -extern const Word16 scales_BWE_3b_fx_new[]; -extern const Word8 no_lead_BWE_3b[]; -extern const int16_t mslvq_SHB_min_bits[]; +extern const Word16 scales_BWE_fx[]; // Q13 +extern const Word16 scales_BWE_fx_new[]; // Q11 +extern const Word16 scales_BWE_3b_fx[]; // Q13 +extern const Word16 scales_BWE_3b_fx_new[]; // Q11 +extern const Word8 no_lead_BWE_3b[]; // Q0 +extern const Word16 mslvq_SHB_min_bits[]; // Q0 extern const float SHB_LSF_mean[]; -extern const Word16 SHB_LSF_mean_fx[]; +extern const Word16 SHB_LSF_mean_fx[]; // Q15 extern const float SHB_LSF_VQ3[48]; extern const float SHB_LSF_VQ4[96]; extern const float *const cb_LSF_BWE[]; -extern const Word16 SHB_LSF_VQ3_fx[48]; -extern const Word16 SHB_LSF_VQ4_fx[96]; -extern const Word16 *const cb_LSF_BWE_fx[]; +extern const Word16 SHB_LSF_VQ3_fx[48]; // Q15 +extern const Word16 SHB_LSF_VQ4_fx[96]; // Q15 +extern const Word16 *const cb_LSF_BWE_fx[]; // Q15 extern const float LastCoefPred_0bit[18]; extern const float LastCoefPred_1bit[36]; -extern const Word32 LastCoefPred_0bit_fx[18]; -extern const Word32 LastCoefPred_1bit_fx[36]; -extern const int16_t config_LSF_BWE[]; +extern const Word32 LastCoefPred_0bit_fx[18]; // Q31 +extern const Word32 LastCoefPred_1bit_fx[36]; // Q31 +extern const Word16 config_LSF_BWE[]; // Q0 // basops -extern const Word32 BASOP_util_normReciprocal[CHEAP_NORM_SIZE]; -extern const Word16 f_atan_expand_range[MAXSFTAB - ( MINSFTAB - 1 )]; +extern const Word32 BASOP_util_normReciprocal[CHEAP_NORM_SIZE]; // Q31 +extern const Word16 f_atan_expand_range[MAXSFTAB - ( MINSFTAB - 1 )]; // Q15 -extern const Word16 Grid[]; -extern const Word16 pwAlpha[10]; +extern const Word16 Grid[]; // Q15 +extern const Word16 pwAlpha[10]; // Q15 extern const Word8 Ind_Guess[256]; -extern const Word16 cos_table_129[129]; -extern const Word16 acos_slope[128]; -extern const Word16 cos_coef_new[4]; -extern const Word16 cos_table[512]; -extern const Word16 inter4_1_fx[]; +extern const Word16 cos_table_129[129]; // Q15 +extern const Word16 acos_slope[128]; // Q15 +extern const Word16 cos_coef_new[4]; // Q15 +extern const Word16 cos_table[512]; // Q15 +extern const Word16 inter4_1_fx[]; // Q14 -extern const Word16 sin_switch_8[15]; -extern const Word16 sin_switch_16[30]; -extern const Word16 sin_switch_32[60]; -extern const Word16 sin_switch_48[90]; +extern const Word16 sin_switch_8[15]; // Q15 +extern const Word16 sin_switch_16[30]; // Q15 +extern const Word16 sin_switch_32[60]; // Q15 +extern const Word16 sin_switch_48[90]; // Q15 extern const Word16 one_on_win_48k_fx[210]; /*Q14 */ extern const Word16 one_on_win_8k_16k_48k_fx[70]; /*Q14 */ -extern const Word16 window_8_16_32kHz_fx[]; -extern const Word16 window_48kHz_fx[]; -extern const Word16 window_256kHz[]; -extern const Word16 half_overlap_25[]; -extern const Word16 half_overlap_48[]; -extern const Word16 half_overlap_int[]; -extern const Word16 small_overlap_25[]; -extern const Word16 small_overlap_48[]; -extern const Word16 small_overlap_int[]; - -extern const Word16 wac_h[]; -extern const Word16 wac_l[]; -extern const short dsDiracsTab[65]; -extern const Word16 pwf_fx[17]; -extern const Word32 inverse_table[]; -extern const Word16 cos_diff_table[512]; -extern const Word32 bwMode2fs[4]; - -extern const Word16 cos_pi_by_127[128]; -extern const Word16 cos_pi_by_255[256]; -extern const Word16 cos_pi_by_383[384]; - -extern const Word16 swb_lsp_prev_interp_init[]; -extern const Word16 L_frame_inv[8]; -extern const Word16 InvIntTable[65]; -extern const Word16 TecLowBandTable[]; -extern const Word16 TecSC_Fx[]; +extern const Word16 window_8_16_32kHz_fx[]; // Q15 +extern const Word16 window_48kHz_fx[]; // Q15 +extern const Word16 window_256kHz[]; // Q15 +extern const Word16 half_overlap_25[]; // Q15 +extern const Word16 half_overlap_48[]; // Q15 +extern const Word16 half_overlap_int[]; // Q15 +extern const Word16 small_overlap_25[]; // Q15 +extern const Word16 small_overlap_48[]; // Q15 +extern const Word16 small_overlap_int[]; // Q15 + +extern const Word16 wac_h[]; // Q15 +extern const Word16 wac_l[]; // Q15 +extern const Word16 dsDiracsTab[65]; // Q0 +extern const Word16 pwf_fx[17]; // Q15 +extern const Word32 inverse_table[]; // Q29 +extern const Word16 cos_diff_table[512]; // Q15 +extern const Word32 bwMode2fs[4]; // Q0 + +extern const Word16 cos_pi_by_127[128]; /* Q15 */ +extern const Word16 cos_pi_by_255[256]; /* Q15 */ +extern const Word16 cos_pi_by_383[384]; /* Q15 */ + +extern const Word16 swb_lsp_prev_interp_init[]; /* Q15 */ +extern const Word16 L_frame_inv[8]; // Q14 +extern const Word16 InvIntTable[65]; // Q15 +extern const Word16 TecLowBandTable[]; // Q0 +extern const Word16 TecSC_Fx[]; // Q15 extern const float TecSC[]; -extern const Word16 sqrt_table_pitch_search[256 + 1]; +extern const Word16 sqrt_table_pitch_search[256 + 1]; // Q11 /* fft_evs.c */ -extern const Word16 RotVector_32[2 * 20]; -extern const Word16 RotVector_256[2 * ( 256 - 32 )]; -extern const Word16 RotVector_320[2 * ( 320 - 20 )]; -extern const Word16 RotVector_400[2 * ( 400 - 20 )]; -extern const Word16 RotVector_480[2 * ( 480 - 30 )]; -extern const Word16 RotVector_600[2 * ( 600 - 30 )]; +extern const Word16 RotVector_32[2 * 20]; // Q15 +extern const Word16 RotVector_256[2 * ( 256 - 32 )]; // Q15 +extern const Word16 RotVector_320[2 * ( 320 - 20 )]; // Q15 +extern const Word16 RotVector_400[2 * ( 400 - 20 )]; // Q15 +extern const Word16 RotVector_480[2 * ( 480 - 30 )]; // Q15 +extern const Word16 RotVector_600[2 * ( 600 - 30 )]; // Q15 extern const Word16 FFT_REORDER_1024[]; -extern const Word16 FFT_W64[]; -extern const Word16 FFT_W128[]; -extern const Word16 FFT_W256[]; -extern const Word16 FFT_W512[]; -extern const Word16 Gamma_19661_Tbl_fx[]; -extern const Word16 Gamma_29491_Tbl[]; +extern const Word16 FFT_W64[]; // Q15 +extern const Word16 FFT_W128[]; // Q15 +extern const Word16 FFT_W256[]; // Q15 +extern const Word16 FFT_W512[]; // Q15 +extern const Word16 Gamma_19661_Tbl_fx[]; // Q15 +extern const Word16 Gamma_29491_Tbl[]; // Q15 /*---------------------------------------------------------------------* * NB post-filter tables *---------------------------------------------------------------------*/ -extern const Word16 tab_hup_s_fx[]; -extern const Word16 tab_hup_l_fx[]; +extern const Word16 tab_hup_s_fx[]; // Q15 +extern const Word16 tab_hup_l_fx[]; // Q15 -extern const Word16 mfreq_loc_Q2fx[]; -extern const Word16 mfreq_loc_div_25[]; +extern const Word16 mfreq_loc_Q2fx[]; // Q0 +extern const Word16 mfreq_loc_div_25[]; // Q0 -extern const Word16 band_len_idx[]; -extern const Word16 band_len_ener_shift[]; -extern const Word16 fine_gain_pred_sqrt_bw[]; +extern const Word16 band_len_idx[]; // Q0 +extern const Word16 band_len_ener_shift[]; // Q0 +extern const Word16 fine_gain_pred_sqrt_bw[]; // Q11 #ifdef IVAS_FLOAT_FIXED -extern const Word16 ivas_band_len_idx[]; -extern const Word16 ivas_band_len_ener_shift[]; -extern const Word16 ivas_fine_gain_pred_sqrt_bw[]; +extern const Word16 ivas_band_len_idx[]; // Q0 +extern const Word16 ivas_band_len_ener_shift[]; // Q0 +extern const Word16 ivas_fine_gain_pred_sqrt_bw[]; // Q11 #endif -extern const Word16 Mean_isf_wb[]; -extern const Word16 lsp_shb_prev_tbl_fx[]; +extern const Word16 Mean_isf_wb[]; // Q2.56 +extern const Word16 lsp_shb_prev_tbl_fx[]; // Q15 #ifdef IVAS_FLOAT_FIXED -extern const Word16 ivas_lsp_shb_prev_tbl_fx[]; +extern const Word16 ivas_lsp_shb_prev_tbl_fx[]; // Q15 #endif extern const Word16 tab_ari_qnew[4][4]; // enhancer.c -extern const Word16 phs_tbl_dec[]; -extern const Word16 Low_H_phasedisp[L_SUBFR]; -extern const Word16 Mid_H_phasedisp[L_SUBFR]; +extern const Word16 phs_tbl_dec[]; // Q15 +extern const Word16 Low_H_phasedisp[L_SUBFR]; // Q15 +extern const Word16 Mid_H_phasedisp[L_SUBFR]; // Q15 // ACcontextMapping_dec_fx.c -extern const Word16 Tab_esc_nb[4]; -extern const Word16 pow2tab[15]; -extern const Word32 pow2[]; -extern const Word16 Es_pred_qua[8]; -extern const Word16 Es_pred_qua_2[16]; -extern const Word16 T_DIV_L_Frame[]; /*0Q15 * 2^-7 */ +extern const Word16 Tab_esc_nb[4]; // Q0 +extern const Word16 pow2tab[15]; // Q0 +extern const Word32 pow2[]; // Q0 +extern const Word16 Es_pred_qua[8]; // Q8 +extern const Word16 Es_pred_qua_2[16]; // Q8 +extern const Word16 T_DIV_L_Frame[]; /*0Q15 * 2^-7 */ // ivas_sns_com_fx.c extern const Word32 pow_tilt_16k[64]; /* Q23 */ @@ -2160,11 +2159,11 @@ extern const Word32 pow_tilt_32k[64]; /* Q23 */ /*EVS basop*/ -extern const Word16 num_nelp_lp_fx[NELP_LP_ORDER + 1]; -extern const Word16 den_nelp_lp_fx[NELP_LP_ORDER + 1]; +extern const Word16 num_nelp_lp_fx[NELP_LP_ORDER + 1]; // Q13 +extern const Word16 den_nelp_lp_fx[NELP_LP_ORDER + 1]; // Q13 -extern const Word16 fir_6k_8k_fx[]; /* HF BWE - band-pass filter coefficients */ -extern const Word16 pwf78_fx[17]; +extern const Word16 fir_6k_8k_fx[]; /* HF BWE - band-pass filter coefficients Q15*/ +extern const Word16 pwf78_fx[17]; // Q15 enum FUNC_GAIN_ENC { @@ -2175,36 +2174,36 @@ enum FUNC_GAIN_ENC FUNC_GAIN_ENC_GACELP_UV /* UV GACELP gain quantizer ((7=5-2bits/subfr) */ }; -extern const Word16 hamcos_window_fx[]; -extern const Word16 CNG_burst_att_fx[6][8]; -extern const Word16 lpc_weights_fx[]; -extern const Word16 SHBCB_SubGain5bit_12_fx[]; /* 5 bit Quantizer table for SHB gain shapes */ -extern const Word16 E_ROM_inter4_1_fx[PIT_UP_SAMP * L_INTERPOL1 + 1]; -extern const Word16 E_ROM_inter6_1_fx[PIT_UP_SAMP6 * L_INTERPOL1 + 1]; -extern const Word16 kLog2TableFrac_x[256]; -extern const Word16 kExp2TableFrac_x[256]; -extern const Word16 One_div_fx[]; +extern const Word16 hamcos_window_fx[]; // Q15 +extern const Word16 CNG_burst_att_fx[6][8]; // Q15 +extern const Word16 lpc_weights_fx[]; // Q15 +extern const Word16 SHBCB_SubGain5bit_12_fx[]; /* 5 bit Quantizer table for SHB gain shapes Q12*/ +extern const Word16 E_ROM_inter4_1_fx[PIT_UP_SAMP * L_INTERPOL1 + 1]; // Q14 +extern const Word16 E_ROM_inter6_1_fx[PIT_UP_SAMP6 * L_INTERPOL1 + 1]; // Q14 +extern const Word16 kLog2TableFrac_x[256]; // Q8 +extern const Word16 kExp2TableFrac_x[256]; // Q15 +extern const Word16 One_div_fx[]; // Q15 // ivas_lfe_dec_fx.c extern const Word32 tbl_two_pow_shift_by_4[35]; /* Q30 */ -extern const Word16 ivas_tan_panning_gain_tbl_fx[601]; -extern const Word16 ivas_sine_panning_tbl_fx[601]; -extern const Word16 ivas_sin_az_fx[361]; +extern const Word16 ivas_tan_panning_gain_tbl_fx[601]; // Q15 +extern const Word16 ivas_sine_panning_tbl_fx[601]; // Q15 +extern const Word16 ivas_sin_az_fx[361]; // Q15 // edct_fx.c -extern const Word16 sin_scale_tbl_960[960]; -extern const Word16 cos_scale_tbl_960[960]; -extern const Word16 cos_scale_tbl_640[640]; -extern const Word16 sin_scale_tbl_640[640]; -extern const Word16 sin_scale_tbl_512[512]; -extern const Word16 cos_scale_tbl_512[512]; -extern const Word16 cos_scale_tbl_1200[1200]; -extern const Word16 sin_scale_tbl_1200[1200]; -extern const Word16 cos_scale_tbl_800[800]; -extern const Word16 sin_scale_tbl_800[800]; - -extern const Word16 scales_ivas_fx[][MAX_NO_SCALES * 2]; -extern const Word16 scales_p_ivas_fx[][MAX_NO_SCALES * 2]; +extern const Word16 sin_scale_tbl_960[960]; // Q15 +extern const Word16 cos_scale_tbl_960[960]; // Q15 +extern const Word16 cos_scale_tbl_640[640]; // Q15 +extern const Word16 sin_scale_tbl_640[640]; // Q15 +extern const Word16 sin_scale_tbl_512[512]; // Q15 +extern const Word16 cos_scale_tbl_512[512]; // Q15 +extern const Word16 cos_scale_tbl_1200[1200]; // Q15 +extern const Word16 sin_scale_tbl_1200[1200]; // Q15 +extern const Word16 cos_scale_tbl_800[800]; // Q15 +extern const Word16 sin_scale_tbl_800[800]; // Q15 + +extern const Word16 scales_ivas_fx[][MAX_NO_SCALES * 2]; // Q11 +extern const Word16 scales_p_ivas_fx[][MAX_NO_SCALES * 2]; // Q11 #endif diff --git a/lib_com/rom_com_fx.c b/lib_com/rom_com_fx.c index 39b94b308..e669a8995 100644 --- a/lib_com/rom_com_fx.c +++ b/lib_com/rom_com_fx.c @@ -46,10 +46,12 @@ #define SHC( x ) ( (Word16) x ) const Word16 w_fft4_fx[2] = { + // Q15 SHC( 0x7fff ), SHC( 0x0000 ), }; const Word16 w_fft8_fx[8] = { + // Q15 SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x5a82 ), @@ -61,6 +63,7 @@ const Word16 w_fft8_fx[8] = { }; const Word16 w_fft16_fx[8] = { + // Q15 SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x5a82 ), @@ -72,6 +75,7 @@ const Word16 w_fft16_fx[8] = { }; const Word16 w_fft32_fx[16] = { + // Q15 SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x5a82 ), @@ -91,6 +95,7 @@ const Word16 w_fft32_fx[16] = { }; const Word16 w_fft64_fx[32] = { + // Q15 SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x5a82 ), @@ -126,6 +131,7 @@ const Word16 w_fft64_fx[32] = { }; const Word16 w_fft128_fx[64] = { + // Q15 SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x5a82 ), @@ -193,6 +199,7 @@ const Word16 w_fft128_fx[64] = { }; const Word16 w_fft256_fx[128] = { + // Q15 SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x5a82 ), @@ -324,6 +331,7 @@ const Word16 w_fft256_fx[128] = { }; const Word16 w_fft512_fx[256] = { + // Q15 SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x5a82 ), @@ -583,6 +591,7 @@ const Word16 w_fft512_fx[256] = { }; const Word16 FFT_RotVector_960_fx[1860] = { + // Q15 SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7ffd ), @@ -2446,6 +2455,7 @@ const Word16 FFT_RotVector_960_fx[1860] = { }; const Word16 FFT_RotVector_640_fx[1240] = { + // Q15 SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7ff9 ), @@ -3689,6 +3699,7 @@ const Word16 FFT_RotVector_640_fx[1240] = { }; const Word16 FFT_RotVector_600_fx[1140] = { + // Q15 SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7ff8 ), @@ -4832,6 +4843,7 @@ const Word16 FFT_RotVector_600_fx[1140] = { }; const Word16 FFT_RotVector_400_fx[760] = { + // Q15 SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7fef ), @@ -5595,6 +5607,7 @@ const Word16 FFT_RotVector_400_fx[760] = { }; const Word16 FFT_RotVector_256_fx[448] = { + // Q15 SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7ff6 ), @@ -6046,6 +6059,7 @@ const Word16 FFT_RotVector_256_fx[448] = { }; const Word16 FFT_RotVector_32_fx[40] = { + // Q15 SHC( 0x7d8a ), SHC( 0xe708 ), SHC( 0x7641 ), @@ -6089,6 +6103,7 @@ const Word16 FFT_RotVector_32_fx[40] = { }; const Word16 cos_twiddle_table_25_5_5[25] = { + // Q15 SHC( 0x7fff ), SHC( 0x7fff ), SHC( 0x7fff ), @@ -6116,6 +6131,7 @@ const Word16 cos_twiddle_table_25_5_5[25] = { SHC( 0xae69 ), }; const Word16 sin_twiddle_table_25_5_5[25] = { + // Q15 SHC( 0x0000 ), SHC( 0x0000 ), SHC( 0x0000 ), @@ -6143,6 +6159,7 @@ const Word16 sin_twiddle_table_25_5_5[25] = { SHC( 0x62a0 ), }; const Word16 cos_twiddle_table_16_8_2[16] = { + // Q15 SHC( 0x7fff ), SHC( 0x7fff ), SHC( 0x7fff ), @@ -6161,6 +6178,7 @@ const Word16 cos_twiddle_table_16_8_2[16] = { SHC( 0x89bf ), }; const Word16 sin_twiddle_table_16_8_2[16] = { + // Q15 SHC( 0x0000 ), SHC( 0x0000 ), SHC( 0x0000 ), @@ -6648,7 +6666,7 @@ const Word16 lsf_q_cb_3b_fx[8] = { 1739, 2011, 2365, 2953 }; -const Word16 *const lsf_q_cb_fx[NUM_Q_LSF] = { lsf_q_cb_4b_fx, lsf_q_cb_4b_fx, lsf_q_cb_3b_fx, lsf_q_cb_3b_fx, lsf_q_cb_3b_fx }; +const Word16 *const lsf_q_cb_fx[NUM_Q_LSF] = { lsf_q_cb_4b_fx, lsf_q_cb_4b_fx, lsf_q_cb_3b_fx, lsf_q_cb_3b_fx, lsf_q_cb_3b_fx }; // Q15 /*Q15*/ const Word16 lsf_grid_fx[4][5] = { diff --git a/lib_com/rom_com_fx.h b/lib_com/rom_com_fx.h index 01ef473c4..4ab4bf819 100644 --- a/lib_com/rom_com_fx.h +++ b/lib_com/rom_com_fx.h @@ -44,47 +44,47 @@ * FFT transform *------------------------------------------------------------------------------*/ -extern const Word16 w_fft64_fx[32]; -extern const Word16 w_fft32_fx[16]; -extern const Word16 w_fft16_fx[8]; -extern const Word16 w_fft8_fx[8]; -extern const Word16 w_fft128_fx[64]; -extern const Word16 w_fft256_fx[128]; -extern const Word16 w_fft512_fx[256]; -extern const Word16 w_fft4_fx[2]; - -extern const Word16 FFT_RotVector_960_fx[1860]; -extern const Word16 FFT_RotVector_640_fx[1240]; -extern const Word16 FFT_RotVector_600_fx[1140]; -extern const Word16 FFT_RotVector_400_fx[760]; -extern const Word16 FFT_RotVector_256_fx[448]; -extern const Word16 FFT_RotVector_32_fx[40]; - -extern const Word16 sincos_t_rad3_fx[T_SIN_PI_2 + 1]; - -extern const Word16 cos_twiddle_table_25_5_5[25]; -extern const Word16 sin_twiddle_table_25_5_5[25]; -extern const Word16 cos_twiddle_table_16_8_2[16]; -extern const Word16 sin_twiddle_table_16_8_2[16]; - - -extern const Word16 CLDFB80_10_fx[100]; -extern const Word16 CLDFB80_16_fx[160]; -extern const Word16 CLDFB80_20_fx[200]; -extern const Word16 CLDFB80_30_fx[300]; -extern const Word16 CLDFB80_32_fx[320]; -extern const Word16 CLDFB80_40_fx[400]; -extern const Word16 CLDFB80_60_fx[600]; +extern const Word16 w_fft64_fx[32]; // Q15 +extern const Word16 w_fft32_fx[16]; // Q15 +extern const Word16 w_fft16_fx[8]; // Q15 +extern const Word16 w_fft8_fx[8]; // Q15 +extern const Word16 w_fft128_fx[64]; // Q15 +extern const Word16 w_fft256_fx[128]; // Q15 +extern const Word16 w_fft512_fx[256]; // Q15 +extern const Word16 w_fft4_fx[2]; // Q15 + +extern const Word16 FFT_RotVector_960_fx[1860]; // Q15 +extern const Word16 FFT_RotVector_640_fx[1240]; // Q15 +extern const Word16 FFT_RotVector_600_fx[1140]; // Q15 +extern const Word16 FFT_RotVector_400_fx[760]; // Q15 +extern const Word16 FFT_RotVector_256_fx[448]; // Q15 +extern const Word16 FFT_RotVector_32_fx[40]; // Q15 + +extern const Word16 sincos_t_rad3_fx[T_SIN_PI_2 + 1]; // Q15 + +extern const Word16 cos_twiddle_table_25_5_5[25]; // Q15 +extern const Word16 sin_twiddle_table_25_5_5[25]; // Q15 +extern const Word16 cos_twiddle_table_16_8_2[16]; // Q15 +extern const Word16 sin_twiddle_table_16_8_2[16]; // Q15 + + +extern const Word16 CLDFB80_10_fx[100]; // Q15 +extern const Word16 CLDFB80_16_fx[160]; // Q15 +extern const Word16 CLDFB80_20_fx[200]; // Q15 +extern const Word16 CLDFB80_30_fx[300]; // Q15 +extern const Word16 CLDFB80_32_fx[320]; // Q15 +extern const Word16 CLDFB80_40_fx[400]; // Q15 +extern const Word16 CLDFB80_60_fx[600]; // Q15 /*5ms delay*/ -extern const Word16 LDQMF_10_fx[100]; -extern const Word16 LDQMF_16_fx[160]; -extern const Word16 LDQMF_20_fx[200]; -extern const Word16 LDQMF_30_fx[300]; -extern const Word16 LDQMF_32_fx[320]; -extern const Word16 LDQMF_40_fx[400]; -extern const Word16 LDQMF_60_fx[600]; - +extern const Word16 LDQMF_10_fx[100]; // Q15 +extern const Word16 LDQMF_16_fx[160]; // Q15 +extern const Word16 LDQMF_20_fx[200]; // Q15 +extern const Word16 LDQMF_30_fx[300]; // Q15 +extern const Word16 LDQMF_32_fx[320]; // Q15 +extern const Word16 LDQMF_40_fx[400]; // Q15 +extern const Word16 LDQMF_60_fx[600]; // Q15 +/* Not used anywhere extern const Word16 LDQMF_10_enc_fx[100]; extern const Word16 LDQMF_16_enc_fx[160]; extern const Word16 LDQMF_20_enc_fx[200]; @@ -92,24 +92,24 @@ extern const Word16 LDQMF_30_enc_fx[300]; extern const Word16 LDQMF_32_enc_fx[320]; extern const Word16 LDQMF_40_enc_fx[400]; extern const Word16 LDQMF_60_enc_fx[600]; - -extern const Word32 rot_vec_delay_re_LDQMF_fx[60]; -extern const Word32 rot_vec_delay_im_LDQMF_fx[60]; - -extern const Word32 rot_vec_ana_re_L10_fx[5]; -extern const Word32 rot_vec_ana_im_L10_fx[5]; -extern const Word32 rot_vec_ana_re_L16_fx[8]; -extern const Word32 rot_vec_ana_im_L16_fx[8]; -extern const Word32 rot_vec_ana_re_L20_fx[10]; -extern const Word32 rot_vec_ana_im_L20_fx[10]; -extern const Word32 rot_vec_ana_re_L30_fx[15]; -extern const Word32 rot_vec_ana_im_L30_fx[15]; -extern const Word32 rot_vec_ana_re_L32_fx[16]; -extern const Word32 rot_vec_ana_im_L32_fx[16]; -extern const Word32 rot_vec_ana_re_L40_fx[20]; -extern const Word32 rot_vec_ana_im_L40_fx[20]; -extern const Word32 rot_vec_ana_re_L60_fx[30]; -extern const Word32 rot_vec_ana_im_L60_fx[30]; +*/ +extern const Word32 rot_vec_delay_re_LDQMF_fx[60]; // Q31 +extern const Word32 rot_vec_delay_im_LDQMF_fx[60]; // Q31 + +extern const Word32 rot_vec_ana_re_L10_fx[5]; // Q29 +extern const Word32 rot_vec_ana_im_L10_fx[5]; // Q29 +extern const Word32 rot_vec_ana_re_L16_fx[8]; // Q29 +extern const Word32 rot_vec_ana_im_L16_fx[8]; // Q29 +extern const Word32 rot_vec_ana_re_L20_fx[10]; // Q29 +extern const Word32 rot_vec_ana_im_L20_fx[10]; // Q29 +extern const Word32 rot_vec_ana_re_L30_fx[15]; // Q29 +extern const Word32 rot_vec_ana_im_L30_fx[15]; // Q29 +extern const Word32 rot_vec_ana_re_L32_fx[16]; // Q29 +extern const Word32 rot_vec_ana_im_L32_fx[16]; // Q29 +extern const Word32 rot_vec_ana_re_L40_fx[20]; // Q29 +extern const Word32 rot_vec_ana_im_L40_fx[20]; // Q29 +extern const Word32 rot_vec_ana_re_L60_fx[30]; // Q29 +extern const Word32 rot_vec_ana_im_L60_fx[30]; // Q29 extern const Word16 LP_assym_window_fx[]; /* Assymetric window for LP analysis @12.8kHz (Q15) */ extern const Word16 LP_assym_window_16k_fx[]; /* Assymetric window for LP analysis @16kHz (Q15) */ diff --git a/lib_com/scale_mem_fx.c b/lib_com/scale_mem_fx.c index c02eff2a5..49e6aef99 100644 --- a/lib_com/scale_mem_fx.c +++ b/lib_com/scale_mem_fx.c @@ -47,16 +47,16 @@ * Scale excitation and total excitation (exc2) *-------------------------------------------------------------------*/ Word16 Rescale_exc( - Word16 dct_post_old_exc_fx[], /* i/o: Music post processing memory */ + Word16 dct_post_old_exc_fx[], /* i/o: Music post processing memory Q_exc*/ Word16 exc[], /* i/o: excitation to rescale Q_exc */ - Word16 bwe_exc[], - Word16 *last_exc_dct_in, - Word16 lg, /* i : frame size */ + Word16 bwe_exc[], /* output Q = Q_exc */ + Word16 *last_exc_dct_in, /* output Q = Q_exc */ + Word16 lg, /* i : frame size */ Word16 lg32, Word32 L_gain_code, /* i : decoded codebook gain Q16 */ Word16 *sQ_exc, /* i/o: Excitation scaling factor */ Word16 *sQsubfr, /* i/o: Past excitation scaling factors */ - Word16 exc2[], /* o : local excitation vector */ + Word16 exc2[], /* o : local excitation vector output Q = Q_exc */ Word16 i_subfr, /* i : subframe number */ const Word16 coder_type ) { @@ -188,14 +188,14 @@ void Rescale_mem( const Word16 Q_exc, /* i : current excitation scaling (>=0) */ Word16 *prev_Q_syn, /* i/o : scaling factor of previous frame */ Word16 *Q_syn, /* i/o : scaling factor of frame */ - Word16 *mem_syn2, /* i/o : modified synthesis memory */ - Word16 *mem_syn_clas_estim_fx, /* i/o : old 12k8 core memory for classification */ + Word16 *mem_syn2, /* i/o : modified synthesis memory Qexp_scale */ + Word16 *mem_syn_clas_estim_fx, /* i/o : old 12k8 core memory for classification Qexp_scale*/ const Word16 MaxScaling, /* i: Minimal difference between excitation scaling and synthesis scaling */ - Word16 *mem_deemph, /* i/o: speech deemph filter memory */ - Word16 *pst_old_syn, /* i/o: psfiler */ - Word16 *pst_mem_deemp_err, /* i/o: psfiler */ - Word16 *mem_agc, - PFSTAT_HANDLE hPFstat, /* i/o: All memories related to NB post filter */ + Word16 *mem_deemph, /* i/o: speech deemph filter memory Qexp_scale */ + Word16 *pst_old_syn, /* i/o: psfiler Qexp_scale*/ + Word16 *pst_mem_deemp_err, /* i/o: psfiler Qexp_scale */ + Word16 *mem_agc, /*Qexp_scale*/ + PFSTAT_HANDLE hPFstat, /* i/o: All memories related to NB post filter */ const Word16 Vad_flag, const Word16 Cna_flag, const Word16 *tmp_buffer /* tmp_buffer in Q-1 */ @@ -337,7 +337,7 @@ Word16 rescale_mem( const Word16 *Q_exc, /* i : current excitation scaling (>=0) */ Word16 *prev_Q_syn, /* i/o : scaling factor of previous frame */ Word16 *Q_syn, /* i/o : scaling factor of frame */ - Word16 *mem_syn2, /* i/o : modified synthesis memory */ + Word16 *mem_syn2, /* i/o : modified synthesis memory Q_syn */ Word16 *syn, /* i/o : synthesis to rescale Q_syn */ Word16 mem_len, /* i : lenght of modified synthesis memory */ Word16 i_subfr /* i : subframe number */ diff --git a/lib_com/stab_est_fx.c b/lib_com/stab_est_fx.c index e0c75e563..73d58af44 100644 --- a/lib_com/stab_est_fx.c +++ b/lib_com/stab_est_fx.c @@ -31,12 +31,12 @@ *------------------------------------------------------------------------*/ Word16 stab_est_fx( - Word16 etot, /* i : Total energy of the current frame */ - Word16 *lt_diff_etot, /* i/o : Long term total energy variation */ - Word16 *mem_etot, /* i/o : Total energy memory */ + Word16 etot, /* i : Total energy of the current frame Q8*/ + Word16 *lt_diff_etot, /* i/o : Long term total energy variation Q8*/ + Word16 *mem_etot, /* i/o : Total energy memory Q8*/ Word16 *nb_thr_3, /* i/o : Number of consecutives frames of level 3 */ Word16 *nb_thr_1, /* i/o : Number of consecutives frames of level 1 */ - Word16 *thresh, /* i/o : Detection thresold */ + Word16 *thresh, /* i/o : Detection thresold Q11*/ Word16 *last_music_flag, /* i/o : Previous music detection ouptut */ const Word16 vad_flag /* i : VAD flag */ ) @@ -121,7 +121,6 @@ Word16 stab_est_fx( music_flag2 = 0; move16(); /* deactivate spectral modification (if music_flag2 != 0 is activated) */ - test(); /*--------------------------------------------------------------------* * statistical deviation < thresh3 and last signal category type >= 3 * (last category was "tonal" and the new one is "very tonal") @@ -182,6 +181,7 @@ Word16 stab_est_fx( *nb_thr_1 = add( *nb_thr_1, 1 ); *nb_thr_3 = 0; move16(); + move16(); } /*------------------------------------------------------------------------* diff --git a/lib_com/stat_com.h b/lib_com/stat_com.h index 487d94dbf..6c19f481a 100644 --- a/lib_com/stat_com.h +++ b/lib_com/stat_com.h @@ -61,13 +61,13 @@ typedef struct Word16 a_fx[MAXLAG_WI]; /* Q(DTFS_STRUCTURE.Q) */ Word16 b_fx[MAXLAG_WI]; /* Q(DTFS_STRUCTURE.Q) */ #endif - int16_t lag; - int16_t nH; - int16_t nH_4kHz; + Word16 lag; + Word16 nH; + Word16 nH_4kHz; // lag and lag_fx to be same - Word16 lag_fx; - Word16 nH_fx; - Word16 nH_4kHz_fx; + Word16 lag_fx; // Q0 + Word16 nH_fx; // Q0 + Word16 nH_4kHz_fx; // Q0 #ifndef IVAS_FLOAT_FIXED float upper_cut_off_freq_of_interest; @@ -76,16 +76,16 @@ typedef struct Word16 upper_cut_off_freq_of_interest_fx; /* Q0 */ Word16 upper_cut_off_freq_fx; /* Q0 */ #endif - int32_t sampling_rate; - Word16 Fs_fx; + Word32 sampling_rate; + Word16 Fs_fx; /* Q0 */ Word16 Q; } DTFS_STRUCTURE; typedef struct { - int16_t lead_sign_ind; + Word16 lead_sign_ind; uint32_t index, size; - int16_t dim, k_val; + Word16 dim, k_val; } PvqEntry; typedef struct @@ -119,20 +119,20 @@ typedef struct typedef struct { /*Coding mode info*/ - int16_t mode_index; + Word16 mode_index; /*LPC info*/ - int16_t midLpc; /*Flag for using or not mid LPC for the current frame*/ - int16_t midLpc_enable; /*Flag enabling or not the mid LPC for the current mode*/ + Word16 midLpc; /*Flag for using or not mid LPC for the current frame*/ + Word16 midLpc_enable; /*Flag enabling or not the mid LPC for the current mode*/ /*ICB flags*/ - int16_t pre_emphasis; /*Flag for triggering pre-emphasis*/ - int16_t pitch_sharpening; /*Flag for triggering pitch sharpening*/ - int16_t phase_scrambling; /*Flag for triggering phase scrambling*/ - int16_t formant_enh; /*Flag for triggering formant enhancement*/ - int16_t formant_tilt; /*Flag for triggering formant tile*/ + Word16 pre_emphasis; /*Flag for triggering pre-emphasis*/ + Word16 pitch_sharpening; /*Flag for triggering pitch sharpening*/ + Word16 phase_scrambling; /*Flag for triggering phase scrambling*/ + Word16 formant_enh; /*Flag for triggering formant enhancement*/ + Word16 formant_tilt; /*Flag for triggering formant tile*/ - int16_t voice_tilt; /*Flag for triggering new voice factor tilt*/ + Word16 voice_tilt; /*Flag for triggering new voice factor tilt*/ #ifndef IVAS_FLOAT_FIXED float formant_enh_num_flt; @@ -142,41 +142,41 @@ typedef struct Word16 formant_enh_den; /* Q15 */ #endif - int16_t bpf_mode; + Word16 bpf_mode; - int16_t nrg_mode; - int16_t nrg_bits; + Word16 nrg_mode; + Word16 nrg_bits; - int16_t ltp_mode; - int16_t ltp_bits; + Word16 ltp_mode; + Word16 ltp_bits; - int16_t ltf_mode; - int16_t ltf_bits; + Word16 ltf_mode; + Word16 ltf_bits; - int16_t gains_mode[NB_SUBFR16k]; + Word16 gains_mode[NB_SUBFR16k]; - int16_t fixed_cdk_index[NB_SUBFR16k]; + Word16 fixed_cdk_index[NB_SUBFR16k]; /* IVAS related parameters */ - int16_t pitch_bits[NB_SUBFR16k]; - int16_t lsf_bits; - int16_t mid_lsf_bits; - int16_t AVQ_cdk_bits[NB_SUBFR16k]; - int16_t FEC_mode; /* 0 == no FEC bits; 1 == class; 2 == clas+energy; 3== class+energy+pulse */ - int16_t ubits; - int16_t fcb_mode; /* 0 == mode1; 1 == mode2 */ + Word16 pitch_bits[NB_SUBFR16k]; + Word16 lsf_bits; + Word16 mid_lsf_bits; + Word16 AVQ_cdk_bits[NB_SUBFR16k]; + Word16 FEC_mode; /* 0 == no FEC bits; 1 == class; 2 == clas+energy; 3== class+energy+pulse */ + Word16 ubits; + Word16 fcb_mode; /* 0 == mode1; 1 == mode2 */ } ACELP_config; typedef struct { - int16_t bits; /* bits per subframe */ - int16_t nbiter; /* number of iterations */ + Word16 bits; /* bits per subframe */ + Word16 nbiter; /* number of iterations */ float alp_flt; /* initial energy of all fixed pulses */ - Word16 alp; /* initial energy of all fixed pulses, exponent = ALP_E */ - int16_t nb_pulse; /* number of pulses */ - int16_t fixedpulses; /* number of pulses whose position is determined from correlation and not by iteration */ - int16_t nbpos[13]; /* number of positions tried in the pair-wise search */ + Word16 alp; /* initial energy of all fixed pulses, exponent = ALP_E Q13*/ + Word16 nb_pulse; /* number of pulses */ + Word16 fixedpulses; /* number of pulses whose position is determined from correlation and not by iteration */ + Word16 nbpos[13]; /* number of positions tried in the pair-wise search */ enum TRACKPOS codetrackpos; /* ordering of tracks -mode */ } PulseConfig; @@ -191,20 +191,20 @@ typedef enum } TNS_ERROR; typedef struct { - uint8_t maxOrder; - uint8_t nMaxFilters; /* Maximum number of filters. */ - uint8_t allowTnsOnWhite; - struct TnsParameters const *pTnsParameters; /* Parameters for each TNS filter */ - int16_t iFilterBorders[TNS_MAX_NUM_OF_FILTERS + 1]; /* Lower borders for each filter. Upper border for the first filter is nsbBorders-1. Upper borders for other filters is the lower border of previous filter. */ + UWord8 maxOrder; + UWord8 nMaxFilters; /* Maximum number of filters. */ + UWord8 allowTnsOnWhite; + struct TnsParameters const *pTnsParameters; /* Parameters for each TNS filter */ + Word16 iFilterBorders[TNS_MAX_NUM_OF_FILTERS + 1]; /* Lower borders for each filter. Upper border for the first filter is nsbBorders-1. Upper borders for other filters is the lower border of previous filter. */ } STnsConfig; typedef struct TNS_filter_structure { - int16_t filterType; - int16_t spectrumLength; /* Number of subbands covered by the filter. */ - int16_t order; /* Filter order. */ - int16_t coefIndex[TNS_MAX_FILTER_ORDER]; /* Quantized filter coefficients. */ + Word16 filterType; + Word16 spectrumLength; /* Number of subbands covered by the filter. */ + Word16 order; /* Filter order. */ + Word16 coefIndex[TNS_MAX_FILTER_ORDER]; /* Quantized filter coefficients. */ #ifndef IVAS_FLOAT_FIXED float predictionGain_flt; /* Prediction gain. The ratio of a signal and TNS residual energy. */ float avgSqrCoef_flt; /* Average squared filter coefficient. */ @@ -216,8 +216,8 @@ typedef struct TNS_filter_structure typedef struct /* TNS data describing all active filters. */ { - int16_t nFilters; /* Number of active filters. */ - int16_t tnsOnWhitenedSpectra; + Word16 nFilters; /* Number of active filters. */ + Word16 tnsOnWhitenedSpectra; STnsFilter filter[TNS_MAX_NUM_OF_FILTERS]; /* Active filters. */ } STnsData; @@ -226,16 +226,16 @@ typedef struct /* TNS data describing all active filters. */ Borders and weighting are available for TCX10 and TCX20 for a specific sampling rate. */ typedef struct { - const uint8_t bandLengthsTCX20[FDNS_NPTS]; /* Length of a band in number of bins. Range is 2..31 */ - const uint8_t bandLengthsTCX10[FDNS_NPTS]; /* Length of a band in number of bins. Range is 2..20, always divisible by 2 */ + const UWord8 bandLengthsTCX20[FDNS_NPTS]; /* Length of a band in number of bins. Range is 2..31 */ + const UWord8 bandLengthsTCX10[FDNS_NPTS]; /* Length of a band in number of bins. Range is 2..20, always divisible by 2 */ } SpectrumWarping; typedef struct { - int16_t nBins; /* Range 0..1200 */ - uint8_t nBands; /* Range 0..64 */ - const uint8_t *bandLengths; /* Length of a band in number of bins. Range is 2..31 */ + Word16 nBins; /* Range 0..1200 */ + UWord8 nBands; /* Range 0..64 */ + const UWord8 *bandLengths; /* Length of a band in number of bins. Range is 2..31 */ } PsychoacousticParameters; @@ -251,29 +251,29 @@ typedef struct TCX_config_structure PWord16 tcx_mdct_window_half[L_MDCT_HALF_OVLP_MAX_CORE_FS]; PWord16 tcx_mdct_window_minimum[L_MDCT_MIN_OVLP_MAX_CORE_FS]; PWord16 tcx_mdct_window_trans[L_MDCT_MIN_OVLP_MAX_CORE_FS]; - Word16 tcx_aldo_window_1[L_FRAME32k * 9 / 32]; + Word16 tcx_aldo_window_1[L_FRAME32k * 9 / 32]; /*Q15*/ PWord16 tcx_aldo_window_1_trunc[L_FRAME32k * 7 / 32]; PWord16 tcx_aldo_window_2[L_FRAME32k * 7 / 32]; - int16_t last_aldo; + Word16 last_aldo; float tcx_mdct_window_half_flt[L_MDCT_HALF_OVLP_MAX_CORE_FS]; float tcx_mdct_window_minimum_flt[L_MDCT_MIN_OVLP_MAX_CORE_FS]; float tcx_mdct_window_trans_flt[L_MDCT_MIN_OVLP_MAX_CORE_FS]; /* transition window for ACELP->TCX */ - int16_t tcx5Size; /* Size of the TCX5 spectrum in number of samples. Always 5ms. */ + Word16 tcx5Size; /* Size of the TCX5 spectrum in number of samples. Always 5ms. */ - int16_t tcx_curr_overlap_mode; /* window overlap of current frame (0: full, 2: none, or 3: half) */ - int16_t tcx_last_overlap_mode; /* previous window overlap, i.e. left-side overlap of current frame */ + Word16 tcx_curr_overlap_mode; /* window overlap of current frame (0: full, 2: none, or 3: half) */ + Word16 tcx_last_overlap_mode; /* previous window overlap, i.e. left-side overlap of current frame */ - int16_t tcx_mdct_window_length; /* length of overlap-add region*/ - int16_t tcx_mdct_window_half_length; /* length of the "half" overlap */ - int16_t tcx_mdct_window_min_length; /* length of the "minimum" overlap */ - int16_t tcx_mdct_window_trans_length; /* length of the ACELP->TCX overlap */ + Word16 tcx_mdct_window_length; /* length of overlap-add region*/ + Word16 tcx_mdct_window_half_length; /* length of the "half" overlap */ + Word16 tcx_mdct_window_min_length; /* length of the "minimum" overlap */ + Word16 tcx_mdct_window_trans_length; /* length of the ACELP->TCX overlap */ - int16_t tcx_mdct_window_delay; /* length of window delay */ - int16_t tcx_offset; /* Offset of the folding point relative to the end of the previous synthetised frame */ - int16_t tcx_mdct_window_length_old; /* for keeping old value for sample rate switching */ + Word16 tcx_mdct_window_delay; /* length of window delay */ + Word16 tcx_offset; /* Offset of the folding point relative to the end of the previous synthetised frame */ + Word16 tcx_mdct_window_length_old; /* for keeping old value for sample rate switching */ float tcx_mdct_windowFB_flt[L_MDCT_OVLP_MAX]; float tcx_aldo_window_1_FB_flt[L_ALDO_WIN1_FB_MAX]; /* ALDO window long slope */ float tcx_aldo_window_2_FB_flt[L_MDCT_OVLP_MAX]; /* ALDO window short slope */ @@ -288,28 +288,28 @@ typedef struct TCX_config_structure PWord16 tcx_mdct_window_halfFB[L_MDCT_HALF_OVLP_MAX]; PWord16 tcx_mdct_window_minimumFB[L_MDCT_MIN_OVLP_MAX]; PWord16 tcx_mdct_window_transFB[L_MDCT_TRANS_OVLP_MAX]; - Word16 tcx_aldo_window_1_FB[L_FRAME_MAX * 9 / 32]; + Word16 tcx_aldo_window_1_FB[L_FRAME_MAX * 9 / 32]; /*Q15*/ PWord16 tcx_aldo_window_1_FB_trunc[L_FRAME_MAX * 7 / 32]; PWord16 tcx_aldo_window_2_FB[L_FRAME_MAX * 7 / 32]; - int16_t tcx5SizeFB; /* Size of the TCX5 spectrum in number of samples. Always 5ms. */ + Word16 tcx5SizeFB; /* Size of the TCX5 spectrum in number of samples. Always 5ms. */ - int16_t tcx_mdct_window_lengthFB; /* length of window, length of overlap-add region */ - int16_t tcx_mdct_window_half_lengthFB; /* length of the "half" overlap window */ - int16_t tcx_mdct_window_min_lengthFB; /* length of the "minimum" overlap window */ - int16_t tcx_mdct_window_trans_lengthFB; /* length of the ACELP->TCX overlap */ + Word16 tcx_mdct_window_lengthFB; /* length of window, length of overlap-add region */ + Word16 tcx_mdct_window_half_lengthFB; /* length of the "half" overlap window */ + Word16 tcx_mdct_window_min_lengthFB; /* length of the "minimum" overlap window */ + Word16 tcx_mdct_window_trans_lengthFB; /* length of the ACELP->TCX overlap */ - int16_t tcx_mdct_window_delayFB; /* length of window delay */ - int16_t tcx_offsetFB; + Word16 tcx_mdct_window_delayFB; /* length of window delay */ + Word16 tcx_offsetFB; - int16_t tcx_coded_lines; /* max number of coded lines, depending on audio bandwidth */ + Word16 tcx_coded_lines; /* max number of coded lines, depending on audio bandwidth */ /* FAC window */ - int16_t lfacNext; - int16_t lfacNextFB; + Word16 lfacNext; + Word16 lfacNextFB; /* TNS */ - int16_t fIsTNSAllowed; + Word16 fIsTNSAllowed; STnsConfig tnsConfig[2][2]; STnsConfig const *pCurrentTnsConfig; @@ -319,18 +319,18 @@ typedef struct TCX_config_structure #else Word16 sq_rounding; /* set the sq deadzone (no deadzone=0.5f) Q15 */ #endif - int16_t tcxRateLoopOpt; + Word16 tcxRateLoopOpt; /*Bandwidth*/ float preemph_fac_flt; /* preemphasis factor */ float bandwidth_flt; - Word16 preemph_fac; /*preemphasis factor*/ + Word16 preemph_fac; /*preemphasis factorQ15*/ Word16 bandwidth; /* Context HM - Residual Quantization*/ - int16_t ctx_hm; /* Flag for enabling Context HM */ - int16_t resq; /* Flag for enabling Residual Quantization */ - int16_t coder_type; /* GC,VC,UC */ + Word16 ctx_hm; /* Flag for enabling Context HM */ + Word16 resq; /* Flag for enabling Residual Quantization */ + Word16 coder_type; /* GC,VC,UC */ #ifndef IVAS_FLOAT_FIXED float na_scale_flt; @@ -354,10 +354,10 @@ typedef struct TCX_config_structure typedef struct { - int32_t low; - int32_t high; + Word32 low; + Word32 high; uint32_t value; - int32_t bits_to_follow; + Word32 bits_to_follow; } Tastat; #ifdef IVAS_FLOAT_FIXED typedef struct @@ -372,22 +372,22 @@ typedef struct typedef struct { - int16_t fftlen; /* FFT length */ - int16_t stopFFTbin; /* Number of FFT bins to be actually processed */ - int16_t numPartitions; /* Number of partitions */ - const int16_t *sidPartitions; /* Upper boundaries for grouping the (sub)bands into partitions when transmitting SID frames (define as NULL pointer to avoid grouping) */ + Word16 fftlen; /* FFT length */ + Word16 stopFFTbin; /* Number of FFT bins to be actually processed */ + Word16 numPartitions; /* Number of partitions */ + const Word16 *sidPartitions; /* Upper boundaries for grouping the (sub)bands into partitions when transmitting SID frames (define as NULL pointer to avoid grouping) */ - int16_t numShapingPartitions; /* Number of partitions */ - const int16_t *shapingPartitions; /* Upper boundaries for grouping the (sub)bands into partitions for shaping at the decoder (define as NULL pointer to avoid grouping) */ + Word16 numShapingPartitions; /* Number of partitions */ + const Word16 *shapingPartitions; /* Upper boundaries for grouping the (sub)bands into partitions for shaping at the decoder (define as NULL pointer to avoid grouping) */ } FD_CNG_SETUP; typedef struct { - int16_t bwmode; + Word16 bwmode; - int32_t bitrateFrom; - int32_t bitrateTo; + Word32 bitrateFrom; + Word32 bitrateTo; #ifndef IVAS_FLOAT_FIXED float scale_flt; @@ -402,30 +402,30 @@ typedef struct { FD_CNG_SETUP FdCngSetup; - int16_t numSlots; /* Number of time slots in CLDFB matrix */ - int16_t regularStopBand; /* Number of CLDFB bands to be considered */ + Word16 numSlots; /* Number of time slots in CLDFB matrix */ + Word16 regularStopBand; /* Number of CLDFB bands to be considered */ - int16_t numCoreBands; /* Number of core bands to be decomposed into FFT subbands */ - int16_t stopBand; /* Total number of (sub)bands to be considered */ - int16_t startBand; /* First (sub)band to be considered */ - int16_t stopFFTbin; /* Total number of FFT subbands */ - int16_t frameSize; /* Frame size in samples */ - int16_t fftlen; /* FFT length used for the decomposition */ - Word16 fftlenShift; - Word16 fftlenFac; + Word16 numCoreBands; /* Number of core bands to be decomposed into FFT subbands */ + Word16 stopBand; /* Total number of (sub)bands to be considered */ + Word16 startBand; /* First (sub)band to be considered */ + Word16 stopFFTbin; /* Total number of FFT subbands */ + Word16 frameSize; /* Frame size in samples */ + Word16 fftlen; /* FFT length used for the decomposition */ + Word16 fftlenShift; // Q0 + Word16 fftlenFac; // Q0 float timeDomainBuffer_flt[L_FRAME16k]; - Word16 timeDomainBuffer[L_FRAME16k]; + Word16 timeDomainBuffer[L_FRAME16k]; /*Q15*/ float fftBuffer_flt[FFTLEN]; float olapBufferAna_flt[FFTLEN]; float olapBufferSynth_flt[FFTLEN]; #ifdef IVAS_FLOAT_FIXED - Word32 olapBufferSynth_fx[FFTLEN]; + Word32 olapBufferSynth_fx[FFTLEN]; /*Q_olapBufferSynth*/ #endif float olapBufferSynth2_flt[FFTLEN]; #ifdef IVAS_FLOAT_FIXED - Word32 olapBufferSynth2_fx[FFTLEN]; + Word32 olapBufferSynth2_fx[FFTLEN]; /*Q_olapBufferSynth2*/ #endif #ifndef IVAS_FLOAT_FIXED const float *olapWinAna_flt; @@ -436,27 +436,27 @@ typedef struct const Word16 *olapWinSyn_fx; /* Q15 */ const Word16 *fftSineTab_fx; /* Q15 */ #endif - Word32 fftBuffer[FFTLEN]; + Word32 fftBuffer[FFTLEN]; // Q31-fftBuffer_exp Word16 fftBuffer_exp; - Word16 *olapBufferAna; /* points to FD_CNG_DEC->olapBufferAna[FFTLEN] in case of decoder */ - Word16 olapBufferAna_fx[FFTLEN]; /* points to FD_CNG_DEC->olapBufferAna[FFTLEN] in case of decoder */ - Word16 olapBufferSynth[FFTLEN]; - Word16 *olapBufferSynth2; /* points to FD_CNG_DEC->olapBufferSynth2[FFTLEN] in case of decoder */ + Word16 *olapBufferAna; /* q_olapBufferAna */ /* points to FD_CNG_DEC->olapBufferAna[FFTLEN] in case of decoder */ + Word16 olapBufferAna_fx[FFTLEN]; /* q_olapBufferAna_fx */ /* points to FD_CNG_DEC->olapBufferAna[FFTLEN] in case of decoder */ + Word16 olapBufferSynth[FFTLEN]; /* q_olapBuffer */ + Word16 *olapBufferSynth2; /*Q_syn*/ /* points to FD_CNG_DEC->olapBufferSynth2[FFTLEN] in case of decoder */ const PWord16 *olapWinAna; const PWord16 *olapWinSyn; float msM_win_flt; float msM_subwin_flt; - Word16 msM_win; - Word16 msM_subwin; + Word16 msM_win; // Q8 + Word16 msM_subwin; // Q11 - int16_t msFrCnt_init_counter; /* Frame counter at initialization */ - int16_t msFrCnt_init_thresh; + Word16 msFrCnt_init_counter; /* Frame counter at initialization */ + Word16 msFrCnt_init_thresh; float init_old_flt; - Word16 init_old; + Word16 init_old; // Q15 - int16_t msFrCnt; /* Frame counter */ + Word16 msFrCnt; /* Frame counter */ #ifndef IVAS_FLOAT_FIXED float msAlphaCor_flt[2]; /* Correction factor (smoothed) */ float msSlope_flt[2]; @@ -464,72 +464,72 @@ typedef struct #else Word32 msAlphaCor[2]; /* Correction factor (smoothed) Q31 */ Word16 msSlope[2]; /* Q14 */ - Word32 msQeqInvAv[2]; + Word32 msQeqInvAv[2]; /* Q31- msQeqInvAv_exp*/ Word16 msQeqInvAv_exp[2]; #endif - int16_t msMinBufferPtr; + Word16 msMinBufferPtr; float msPsdSum_flt[2]; float msPeriodogSum_flt[2]; - Word32 msPsdSum[2]; - Word32 msPeriodogSum[2]; - Word16 msPeriodogSum_exp[2]; + Word32 msPsdSum[2]; /* 16Q15 */ + Word32 msPeriodogSum[2]; /* Q31- msPeriodogSum_exp*/ + Word16 msPeriodogSum_exp[2]; // Q0 - int16_t offsetflag; + Word16 offsetflag; float periodog_flt[PERIODOGLEN]; /* Periodogram */ float cngNoiseLevel_flt[FFTCLDFBLEN]; /* Noise level applied for the CNG in each (sub)band */ - Word32 periodog[PERIODOGLEN]; /* Periodogram */ - Word16 periodog_exp; - Word16 exp_cldfb_periodog; + Word32 periodog[PERIODOGLEN]; /* Periodogram Q31 - periodog_exp*/ + Word16 periodog_exp; // Q0 + Word16 exp_cldfb_periodog; // Q0 - Word32 cngNoiseLevel[FFTCLDFBLEN]; /* Noise level applied for the CNG in each (sub)band */ + Word32 cngNoiseLevel[FFTCLDFBLEN]; /* Noise level applied for the CNG in each (sub)band Q31 - cngNoiseLevelExp*/ // Word16 q_cngNoiseLevel; Word16 cngNoiseLevelExp; - int16_t seed; /* Seed memory (for random function) */ - int16_t seed2; /* Seed for second noise source in MDCT-Stereo DTX */ - int16_t seed3; /* Seed for third noise source in MDCT-Stereo DTX */ + Word16 seed; /* Seed memory (for random function) */ + Word16 seed2; /* Seed for second noise source in MDCT-Stereo DTX */ + Word16 seed3; /* Seed for third noise source in MDCT-Stereo DTX */ - int16_t npart; /* Number of partitions */ - int16_t midband[NPART]; /* Central band of each partition */ - int16_t nFFTpart; /* Number of hybrid spectral partitions */ - int16_t part[NPART]; /* Partition upper boundaries (band indices starting from 0) */ + Word16 npart; /* Number of partitions */ + Word16 midband[NPART]; /* Central band of each partition */ + Word16 nFFTpart; /* Number of hybrid spectral partitions */ + Word16 part[NPART]; /* Partition upper boundaries (band indices starting from 0) */ float psize_flt[NPART]; /* Partition sizes */ float psize_inv_flt[NPART]; /* Inverse of partition sizes */ float FFTscalingFactor_flt; /* Squared ratio between core signal analysis FFT and noise estimator FFT */ float scalingFactor_flt; - Word16 psize[NPART]; /* Partition sizes */ - Word16 psize_norm[NPART]; /* Partition sizes, fractional variable */ - Word16 psize_norm_exp; /* Partition sizes exponent for fractional variable */ - Word16 psize_inv[NPART]; /* Inverse of partition sizes */ - Word16 FFTscalingFactor; /* Squared ratio between core signal analysis FFT and noise estimator FFT */ - Word16 scalingFactor; - Word16 invScalingFactor; - int16_t nCLDFBpart; /* Number of CLDFB spectral partitions */ - int16_t CLDFBpart[NPARTCLDFB]; /* CLDFB Partition upper boundaries (band indices starting from 0 above the core coder bands) */ + Word16 psize[NPART]; /* Partition sizes 6Q9 */ + Word16 psize_norm_exp; /* Partition sizes exponent for fractional variable */ + Word16 psize_norm[NPART]; /* Partition sizes, fractional variable Q15-psize_norm_exp*/ + Word16 psize_inv[NPART]; /* Inverse of partition sizes Q15*/ + // Word16 FFTscalingFactor; /* Squared ratio between core signal analysis FFT and noise estimator FFT */ + Word16 scalingFactor; // Q15 + Word16 invScalingFactor; // Q15 + Word16 nCLDFBpart; /* Number of CLDFB spectral partitions */ + Word16 CLDFBpart[NPARTCLDFB]; /* CLDFB Partition upper boundaries (band indices starting from 0 above the core coder bands) */ float CLDFBpsize_inv_flt[NPARTCLDFB]; /* Inverse of CLDFB partition sizes */ - Word16 CLDFBpsize_inv[NPARTCLDFB]; /* Inverse of CLDFB partition sizes */ + Word16 CLDFBpsize_inv[NPARTCLDFB]; /* Inverse of CLDFB partition sizes Q15*/ - int16_t inactive_frame_counter; - int16_t sid_frame_counter; - int16_t active_frame_counter; /* Active frame counter limited to MSBUFLEN in stereo decoder */ + Word16 inactive_frame_counter; + Word16 sid_frame_counter; + Word16 active_frame_counter; /* Active frame counter limited to MSBUFLEN in stereo decoder */ float sidNoiseEst_flt[NPART]; /* Transmitted noise level */ - Word32 sidNoiseEst[NPART]; /* Transmitted noise level */ + Word32 sidNoiseEst[NPART]; /* Transmitted noise level Q31-sidNoiseEstExp*/ Word16 sidNoiseEstExp; float sidNoiseEstLp_flt[NPART]; - Word32 sidNoiseEstLp[NPART]; + Word32 sidNoiseEstLp[NPART]; // Q(31-sidNoiseEstExp) - int16_t frame_type_previous; + Word16 frame_type_previous; float A_cng_flt[M + 1]; float exc_cng_flt[L_FRAME16k]; - Word16 A_cng[M + 1]; - Word16 exc_cng[L_FRAME16k]; + Word16 A_cng[M + 1]; // Qx + Word16 exc_cng[L_FRAME16k]; // Q_new #ifdef IVAS_FLOAT_FIXED - Word32 exc_cng_32fx[L_FRAME16k]; + Word32 exc_cng_32fx[L_FRAME16k]; // Q_qexc_cng_32fx #endif Word32 CngBitrate; @@ -539,15 +539,15 @@ typedef struct #ifndef IVAS_FLOAT_FIXED float likelihood_noisy_speech_flt; #else - Word16 likelihood_noisy_speech; /* Q15 */ + Word16 likelihood_noisy_speech; /* Q15 */ #endif #ifndef IVAS_FLOAT_FIXED float coherence_flt; /* inter-channel coherence of noise */ #else - Word16 coherence_fx; /* inter-channel coherence of noise Q15 */ + Word16 coherence_fx; /* inter-channel coherence of noise Q15 */ #endif - int16_t no_side_flag; /* indicates whether the side noise shape should be zeroed-out or not */ + Word16 no_side_flag; /* indicates whether the side noise shape should be zeroed-out or not */ } FD_CNG_COM, *HANDLE_FD_CNG_COM; @@ -562,7 +562,7 @@ typedef struct * @param pValue Pointer to the value. * @return Substructure associated with this value or NULL if there is none. */ -typedef void const *( *TGetParamValue )( void const *p, int16_t index, int16_t *pValue ); +typedef void const *( *TGetParamValue )( void const *p, Word16 index, Word16 *pValue ); /** Function that puts specific value to p. * @param p Pointer to a variable that can also be structure or array. @@ -570,21 +570,21 @@ typedef void const *( *TGetParamValue )( void const *p, int16_t index, int16_t * * @param value The value. * @return Substructure associated with this value or NULL if there is none. */ -typedef void *( *TSetParamValue )( void *p, int16_t index, int16_t value ); +typedef void *( *TSetParamValue )( void *p, Word16 index, Word16 value ); /** Function that return required number of bits for a value when it is coded. * @param value The value. * @param index Index of a variable when it is an element of an array, otherwise 0. * @return Number of bits required to code the value. */ -typedef int16_t ( *TGetNumberOfBits )( int16_t value, int16_t index ); +typedef Word16 ( *TGetNumberOfBits )( Word16 value, Word16 index ); /** Function that encodes a value. * @param value The value. * @param index Index of a variable when it is an element of an array, otherwise 0. * @return Coded value. */ -typedef int16_t ( *TEncodeValue )( int16_t value, int16_t index ); +typedef Word16 ( *TEncodeValue )( Word16 value, Word16 index ); /** Function that decodes a value. * @param bitstream Bitstream containing a coded value. @@ -609,7 +609,7 @@ typedef struct ParamBitMap /** Number of bits in a bitstream required for the parameter. * If nBits is equal to 0 then GetNumberOfBits is used. */ - int16_t nBits; + Word16 nBits; /** Function to get the number of bits required for a value of this parameter. * If nBits != 0 it is not used and can be set to NULL. * If fZeroAllowed == 0 then GetNumberOfBits must take care of this. @@ -621,7 +621,7 @@ typedef struct ParamBitMap * must take care of this flag - there is no additional processing in parameter bitmapping. * If EncodeValue is equal to NULL, then the encode/decode function takes care of this. */ - int16_t fZeroAllowed; + Word16 fZeroAllowed; /** Function to get the value of this parameter. * The function returns a pointer to be used in functions in pSubParamBitMap. * If the function returns NULL then the same pointer as for the current @@ -662,7 +662,7 @@ typedef struct ParamBitMap typedef struct ParamsBitMap { /** Number of parameters in params. */ - int16_t nParams; + Word16 nParams; /** Definition of the mapping for each parameter. */ ParamBitMap params[NPARAMS_MAX]; } ParamsBitMap; @@ -688,24 +688,24 @@ struct TnsParameters typedef struct { - uint8_t value; - uint16_t code; - uint8_t nBits; + UWord8 value; + UWord16 code; + UWord8 nBits; } Coding; /* Scale TCX setup */ typedef struct { - int16_t bwmode; + Word16 bwmode; - int32_t bitrateFrom; - int32_t bitrateTo; + Word32 bitrateFrom; + Word32 bitrateTo; #ifndef IVAS_FLOAT_FIXED float scale_flt; #else - Word16 scale; /* Q15 */ + Word16 scale; /* Q15 */ #endif } SCALE_TCX_SETUP; @@ -713,14 +713,14 @@ typedef struct typedef struct { - uint16_t frame_bits; /*Bits per frame*/ - uint16_t frame_net_bits; /*Net Bits per frame*/ - uint8_t transmission_bits; /*max=1*/ - uint8_t transmission_mode[2]; /*SID,VBR/CBR*/ - uint8_t bandwidth_bits; /*max=2*/ - uint8_t bandwidth_min; /*first valid bandwidth (NB,WB,SWB,FB)*/ - uint8_t bandwidth_max; /*last valid bandwidth (NB,WB,SWB,FB)*/ - uint8_t reserved_bits; /*max=1*/ + UWord16 frame_bits; /*Bits per frame*/ + UWord16 frame_net_bits; /*Net Bits per frame*/ + UWord8 transmission_bits; /*max=1*/ + UWord8 transmission_mode[2]; /*SID,VBR/CBR*/ + UWord8 bandwidth_bits; /*max=2*/ + UWord8 bandwidth_min; /*first valid bandwidth (NB,WB,SWB,FB)*/ + UWord8 bandwidth_max; /*last valid bandwidth (NB,WB,SWB,FB)*/ + UWord8 reserved_bits; /*max=1*/ } FrameSizeParams; @@ -741,8 +741,8 @@ typedef struct cldfb_filter_bank_struct #ifndef IVAS_FLOAT_FIXED const float *p_filter_flt; #endif - const Word16 *p_filter; /*!< Pointer to filter coefficients */ - Word16 p_filter_sf; + const Word16 *p_filter; /*!< Pointer to filter coefficients */ // Q15 + Word16 p_filter_sf; // Q0 /* rotation vectors */ @@ -752,11 +752,11 @@ typedef struct cldfb_filter_bank_struct const float *rot_vec_syn_re; const float *rot_vec_syn_im; #else - const Word32 *rot_vec_syn_re_fx; - const Word32 *rot_vec_syn_im_fx; + const Word32 *rot_vec_syn_re_fx; // Q29 + const Word32 *rot_vec_syn_im_fx; // Q29 - const Word32 *rot_vec_syn_delay_re_fx; - const Word32 *rot_vec_syn_delay_im_fx; + const Word32 *rot_vec_syn_delay_re_fx; // Q31 + const Word32 *rot_vec_syn_delay_im_fx; // Q31 #endif /* rotation vectors for delay */ #ifndef IVAS_FLOAT_FIXED @@ -765,35 +765,35 @@ typedef struct cldfb_filter_bank_struct const float *rot_vec_syn_delay_re; const float *rot_vec_syn_delay_im; #else - const Word32 *rot_vec_ana_re_fx; - const Word32 *rot_vec_ana_im_fx; + const Word32 *rot_vec_ana_re_fx; // Q29 + const Word32 *rot_vec_ana_im_fx; // Q29 - const Word32 *rot_vec_ana_delay_re_fx; - const Word32 *rot_vec_ana_delay_im_fx; + const Word32 *rot_vec_ana_delay_re_fx; // Q31 + const Word32 *rot_vec_ana_delay_im_fx; // Q31 #endif // Fix variables - Word16 *FilterStates; /*!< Pointer to buffer of filter states */ + Word16 *FilterStates; /*!< Pointer to buffer of filter states Q15-FilterStates_eg*/ Word16 FilterStates_e[CLDFB_NO_COL_MAX + 9]; /*!< Filter states time slot exponents */ Word16 FilterStates_eg; /*!< Filter states current exponent */ - const Word16 *rRotVctr; /*!< Modulation tables. */ - const Word16 *iRotVctr; - Word16 filterScale; /*!< filter scale */ + const Word16 *rRotVctr; /*!< Modulation tables.Q(sqrt(1.0/16.00)) */ + const Word16 *iRotVctr; /*Q(sqrt(1.0/16.00))*/ + Word16 filterScale; /*!< filter scale Q0*/ - Word16 synGain; /*!< gain for synthesis filterbank */ - Word16 anaScalefactor; /*!< Scale factor of analysis cldfb */ - Word16 synScalefactor; /*!< Scale factor of synthesis cldfb */ - Word16 outScalefactor; /*!< Scale factor of output data (syn only) */ - Word16 synFilterHeadroom; /*!< Headroom for states in synthesis cldfb filterbank */ + Word16 synGain; /*!< gain for synthesis filterbank Q0*/ + Word16 anaScalefactor; /*!< Scale factor of analysis cldfb Q0*/ + Word16 synScalefactor; /*!< Scale factor of synthesis cldfb Q0*/ + Word16 outScalefactor; /*!< Scale factor of output data (syn only) Q0*/ + Word16 synFilterHeadroom; /*!< Headroom for states in synthesis cldfb filterbank Q0*/ /* memory helper states */ #ifndef IVAS_FLOAT_FIXED float *memory_flt; #endif - Word16 *memory; + Word16 *memory; // Qx #ifdef IVAS_FLOAT_FIXED - Word32 *memory32; /*because cldfb_state_fx is word32 which is used to assign values*/ + Word32 *memory32; // Q_cldfb_state /*because cldfb_state_fx is word32 which is used to assign values*/ #endif // IVAS_FLOAT_FIXED UWord16 memory_length; @@ -802,7 +802,7 @@ typedef struct cldfb_filter_bank_struct #ifndef IVAS_FLOAT_FIXED float *cldfb_state; #else - Word32 *cldfb_state_fx; + Word32 *cldfb_state_fx; // Q_cldfb_state Word16 cldfb_state_length; Word16 cldfb_size; Word16 Q_cldfb_state; @@ -848,8 +848,8 @@ typedef enum *----------------------------------------------------------------------------------*/ typedef struct pfstat_structure { - int16_t on; /* On/off flag */ - int16_t reset; /* reset flag */ + Word16 on; /* On/off flag */ + Word16 reset; /* reset flag */ #ifndef IVAS_FLOAT_FIXED float mem_pf_in_flt[L_SUBFR]; /* Input memory */ float mem_stp_flt[L_SUBFR]; /* 1/A(gamma1) memory */ @@ -857,11 +857,11 @@ typedef struct pfstat_structure float mem_zero_flt[M]; /* null memory to compute i.r. of A(gamma2)/A(gamma1) */ float gain_prec_flt; /* for gain adjustment */ #endif - Word16 mem_pf_in[L_SUBFR]; /* Input memory */ - Word16 mem_stp[L_SUBFR]; /* 1/A(gamma1) memory */ - Word16 mem_res2[DECMEM_RES2]; /* A(gamma2) residual */ - Word16 mem_zero[M]; /* null memory to compute i.r. of A(gamma2)/A(gamma1) */ - Word16 gain_prec; /* for gain adjustment */ + Word16 mem_pf_in[L_SUBFR]; /* Input memory Qqmem_pf_in */ + Word16 mem_stp[L_SUBFR]; /* 1/A(gamma1) memory Qqmem_stp*/ + Word16 mem_res2[DECMEM_RES2]; /* A(gamma2) residual Q_syn*/ + Word16 mem_zero[M]; /* null memory to compute i.r. of A(gamma2)/A(gamma1) Q_qmem_zero*/ + Word16 gain_prec; /*Q14*/ /* for gain adjustment */ } PFSTAT, *PFSTAT_HANDLE; @@ -878,22 +878,22 @@ typedef struct typedef struct igf_grid_struct { - int16_t swb_offset[IGF_MAX_SFB]; - int16_t swb_offset_len; - int16_t startFrequency; - int16_t stopFrequency; - int16_t startLine; - int16_t stopLine; - int16_t startSfb; - int16_t stopSfb; - int16_t sfbWrap[IGF_MAX_TILES + 1]; - int16_t sbWrap[IGF_MAX_TILES]; - int16_t nTiles; - int16_t minSrcSubband; - int16_t minSrcFrequency; - int16_t tile[IGF_MAX_TILES + 1]; - int16_t infoIsRefined; - int16_t infoGranuleLen; + Word16 swb_offset[IGF_MAX_SFB]; + Word16 swb_offset_len; + Word16 startFrequency; + Word16 stopFrequency; + Word16 startLine; + Word16 stopLine; + Word16 startSfb; + Word16 stopSfb; + Word16 sfbWrap[IGF_MAX_TILES + 1]; + Word16 sbWrap[IGF_MAX_TILES]; + Word16 nTiles; + Word16 minSrcSubband; + Word16 minSrcFrequency; + Word16 tile[IGF_MAX_TILES + 1]; + Word16 infoIsRefined; + Word16 infoGranuleLen; Word16 infoTransFac; #ifndef IVAS_FLOAT_FIXED float whiteningThreshold_flt[2][IGF_MAX_TILES]; @@ -911,21 +911,21 @@ typedef struct igf_grid_struct typedef struct IGF_INFO_struct { - int16_t *nfSeed; - int16_t nfSeedBuf[2]; - int32_t sampleRate; - int16_t frameLength; - int16_t maxHopsize; + Word16 *nfSeed; + Word16 nfSeedBuf[2]; + Word32 sampleRate; + Word16 frameLength; + Word16 maxHopsize; IGF_GRID grid[IGF_NOF_GRIDS]; - int16_t bitRateIndex; + Word16 bitRateIndex; } IGF_INFO, *H_IGF_INFO; typedef struct { - int16_t *indexBuffer; - int16_t *peakIndices, *holeIndices; - int16_t numPeakIndices, numHoleIndices; + Word16 *indexBuffer; + Word16 *peakIndices, *holeIndices; + Word16 numPeakIndices, numHoleIndices; } CONTEXT_HM_CONFIG; typedef enum diff --git a/lib_com/stat_noise_uv_mod_fx.c b/lib_com/stat_noise_uv_mod_fx.c index c022ab04f..e4771a183 100644 --- a/lib_com/stat_noise_uv_mod_fx.c +++ b/lib_com/stat_noise_uv_mod_fx.c @@ -30,21 +30,21 @@ Word32 L_Sqrt_Q0( const Word32 x ); void stat_noise_uv_mod_fx( const Word16 coder_type, /* i : Coder type */ - Word16 noisiness, /* i : noisiness parameter */ - const Word16 *lsp_old, /* i : old LSP vector at 4th sfr */ - const Word16 *lsp_new, /* i : LSP vector at 4th sfr */ - const Word16 *lsp_mid, /* i : LSP vector at 2nd sfr */ - Word16 *Aq, /* o : A(z) quantized for the 4 subframes */ - Word16 *exc2, /* i/o: excitation buffer */ + Word16 noisiness, /* i : noisiness parameter Q0 */ + const Word16 *lsp_old, /* i : old LSP vector at 4th sfr Q15 */ + const Word16 *lsp_new, /* i : LSP vector at 4th sfr Q15 */ + const Word16 *lsp_mid, /* i : LSP vector at 2nd sfr Q15 */ + Word16 *Aq, /* o : A(z) quantized for the 4 subframes Q12 */ + Word16 *exc2, /* i/o: excitation buffer Q_exc */ Word16 Q_exc, /* i : Q of exc2 excitation buffer [11..-1] expected */ const Word16 bfi, /* i : Bad frame indicator */ - Word32 *ge_sm, /* i/o: smoothed excitation gain */ + Word32 *ge_sm, /* i/o: smoothed excitation gain Q_ge */ Word16 *uv_count, /* i/o: unvoiced counter */ Word16 *act_count, /* i/o: activation counter */ - Word16 lspold_s[], /* i/o: old LSP */ - Word16 *noimix_seed, /* i/o: mixture seed */ - Word16 *st_min_alpha, /* i/o: minimum alpha */ - Word16 *exc_pe, /* i/o: scale Q_stat_noise */ + Word16 lspold_s[], /* i/o: old LSP Q15 */ + Word16 *noimix_seed, /* i/o: mixture seed Q0 */ + Word16 *st_min_alpha, /* i/o: minimum alpha Q15 */ + Word16 *exc_pe, /* i/o: scale Q_stat_noise Q_stat_noise */ const Word32 bitrate, /* i : core bitrate */ const Word16 bwidth_fx, /* i : input bandwidth */ Word16 *Q_stat_noise, /* i/o: noise scaling */ @@ -379,7 +379,7 @@ void stat_noise_uv_mod_ivas_fx( Word16 *uv_count, /* i/o: unvoiced counter */ Word16 *act_count, /* i/o: activation counter */ Word16 lspold_s[], /* i/o: old LSP Q=15*/ - Word16 *noimix_seed, /* i/o: mixture seed */ + Word16 *noimix_seed, /* i/o: mixture seed Q0 */ Word16 *st_min_alpha, /* i/o: minimum alpha Q=15*/ Word16 *exc_pe, /* i/o: scale Q_stat_noise Q=Q_stat_noise*/ const Word32 bitrate, /* i : core bitrate */ @@ -698,7 +698,7 @@ void stat_noise_uv_mod_ivas_fx( *---------------------------------------------------------------------------*/ static Word16 calc_tilt_fx( /* o : Excitation tilt Q15*/ - const Word16 *x, /* i : Signal input */ + const Word16 *x, /* i : Signal input Q_shift*/ const Word16 Q_shift, /* i : input scaling */ const Word16 len /* i : length */ ) @@ -768,8 +768,8 @@ static Word16 calc_tilt_fx( /* o : Excitation tilt Q15*/ * Calculate square root from fractional values (Q0 -> Q0) * Uses 32 bit internal representation for precision *---------------------------------------------------------------------------*/ -Word32 L_Sqrt_Q0( /* o : Square root of input */ - const Word32 x /* i : Input */ +Word32 L_Sqrt_Q0( /* o : Square root of input Q0*/ + const Word32 x /* i : Input Qx */ ) { Word32 log2_work; diff --git a/lib_enc/core_enc_switch.c b/lib_enc/core_enc_switch.c index 3dee5f2bc..3f79d365d 100644 --- a/lib_enc/core_enc_switch.c +++ b/lib_enc/core_enc_switch.c @@ -278,7 +278,6 @@ void core_coder_mode_switch_ivas_fx( set_f( st->hBWE_TD->state_lpc_syn, 0.0f, LPC_SHB_ORDER ); set_f( st->hBWE_TD->state_syn_shbexc, 0.0f, L_SHB_LAHEAD ); set_f( st->hBWE_TD->mem_stp_swb, 0.0f, LPC_SHB_ORDER ); - set_f( st->hBWE_TD->mem_zero_swb, 0, LPC_SHB_ORDER ); st->hBWE_TD->gain_prec_swb = 1.0f; #endif set16_fx( st->hBWE_TD->state_lpc_syn_fx, 0, LPC_SHB_ORDER ); diff --git a/lib_enc/core_switching_enc.c b/lib_enc/core_switching_enc.c index 147a0d015..7bcd3a99c 100644 --- a/lib_enc/core_switching_enc.c +++ b/lib_enc/core_switching_enc.c @@ -376,7 +376,17 @@ void core_switching_pre_enc( mvr2r( old_inp_16k + L_INP_MEM + L_FRAME - Sample_Delay_LP, st->hBWE_FD->old_input_lp, Sample_Delay_LP ); } +#ifndef IVAS_FLOAT_FIXED mvr2r( st->hBWE_TD->old_speech_shb + L_LOOK_16k + L_SUBFR16k - Sample_Delay_HP, st->hBWE_FD->new_input_hp, Sample_Delay_HP ); +#else +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + floatToFixed_arr( st->hBWE_FD->new_input_hp, st->hBWE_FD->new_input_hp_fx, 0, NS2SA( 16000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_NS + DELAY_FIR_RESAMPL_NS - DELAY_CLDFB_NS ) ); +#endif + Copy( st->hBWE_TD->old_speech_shb_fx + L_LOOK_16k + L_SUBFR16k - Sample_Delay_HP, st->hBWE_FD->new_input_hp_fx, Sample_Delay_HP ); +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + fixedToFloat_arr( st->hBWE_FD->new_input_hp_fx, st->hBWE_FD->new_input_hp, 0, NS2SA( 16000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_NS + DELAY_FIR_RESAMPL_NS - DELAY_CLDFB_NS ) ); +#endif +#endif if ( st->last_extl != WB_BWE ) { @@ -954,9 +964,10 @@ void core_switching_post_enc( InitSWBencBufferStates( st->hBWE_TD, NULL ); swb_tbe_reset( st->hBWE_TD->mem_csfilt, st->hBWE_TD->mem_genSHBexc_filt_down_shb, st->hBWE_TD->state_lpc_syn, st->hBWE_TD->syn_overlap, st->hBWE_TD->state_syn_shbexc, &( st->hBWE_TD->tbe_demph ), &( st->hBWE_TD->tbe_premph ), st->hBWE_TD->mem_stp_swb, &( st->hBWE_TD->gain_prec_swb ) ); #endif +#ifndef IVAS_FLOAT_FIXED set_f( st->hBWE_TD->dec_2_over_3_mem, 0.0f, L_FILT_2OVER3 ); set_f( st->hBWE_TD->dec_2_over_3_mem_lp, 0.0f, L_FILT_2OVER3_LP ); -#ifdef IVAS_FLOAT_FIXED +#else set16_fx( st->hBWE_TD->dec_2_over_3_mem_fx, 0, L_FILT_2OVER3 ); set16_fx( st->hBWE_TD->dec_2_over_3_mem_lp_fx, 0, L_FILT_2OVER3_LP ); #endif @@ -966,7 +977,11 @@ void core_switching_post_enc( set_f( st->hBWE_TD->state_lpc_syn, 0.0f, LPC_SHB_ORDER ); set_f( st->hBWE_TD->state_syn_shbexc, 0.0f, L_SHB_LAHEAD ); set_f( st->hBWE_TD->mem_stp_swb, 0.0f, LPC_SHB_ORDER ); +#ifndef IVAS_FLOAT_FIXED set_f( st->hBWE_TD->mem_zero_swb, 0, LPC_SHB_ORDER ); +#else + set16_fx( st->hBWE_TD->mem_zero_swb_fx, 0, LPC_SHB_ORDER ); +#endif st->hBWE_TD->gain_prec_swb = 1.0f; } else if ( st->last_core == TCX_20_CORE || st->last_core == TCX_10_CORE ) diff --git a/lib_enc/ivas_core_enc.c b/lib_enc/ivas_core_enc.c index a550f76de..de065abb6 100644 --- a/lib_enc/ivas_core_enc.c +++ b/lib_enc/ivas_core_enc.c @@ -105,8 +105,7 @@ ivas_error ivas_core_enc( #endif #ifdef IVAS_FLOAT_FIXED Word32 *new_swb_speech_fx; - Word16 shb_speech_fx[L_FRAME16k]; // Q_shb_spch - Word32 shb_speech_fx_32[L_FRAME16k]; // Q_shb_spch + Word16 shb_speech_fx[L_FRAME16k]; // Q_shb_spch Word16 Q_shb_spch; Word32 new_swb_speech_buffer_fx[L_FRAME48k + STEREO_DFT_OVL_MAX]; Word16 new_inp_resamp16k_fx[CPE_CHANNELS][L_FRAME16k]; @@ -154,6 +153,9 @@ ivas_error ivas_core_enc( error = IVAS_ERR_OK; + Q_shb_spch = 0; + move16(); + /*------------------------------------------------------------------* * General initialization *-----------------------------------------------------------------*/ @@ -881,7 +883,6 @@ ivas_error ivas_core_enc( #ifdef IVAS_FLOAT_FIXED_CONVERSIONS Word32 realBuffer_fx[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; Word32 imagBuffer_fx[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; - Word16 use_shb32 = 0; Word16 q_realImagBuffer = Q_factor_arrL( (float *) &realBuffer[n][0][0], CLDFB_NO_COL_MAX * CLDFB_NO_CHANNELS_MAX ); q_realImagBuffer = s_min( q_realImagBuffer, Q_factor_arrL( (float *) &imagBuffer[n][0][0], CLDFB_NO_COL_MAX * CLDFB_NO_CHANNELS_MAX ) ); q_realImagBuffer = s_min( q_realImagBuffer, st->cldfbSynTd->Q_cldfb_state ); @@ -921,23 +922,18 @@ ivas_error ivas_core_enc( st->hBWE_FD->L_old_wtda_swb_fx[idx] = (Word16) st->hBWE_FD->old_wtda_swb[idx]; st->hBWE_FD->old_fdbwe_speech_fx[idx] = (Word16) st->hBWE_FD->old_fdbwe_speech[idx]; } - for ( Word32 idx = 0; idx < ( L_LOOK_16k + L_SUBFR16k ); idx++ ) - { - st->hBWE_TD->old_speech_shb_fx[idx] = (Word16) st->hBWE_TD->old_speech_shb[idx]; - } #endif #endif /* Scaling cldfb_state_fx */ scale_sig32( st->cldfbSynTd->cldfb_state_fx, st->cldfbSynTd->p_filter_length, sub( q_realImagBuffer, st->cldfbSynTd->Q_cldfb_state ) ); - swb_pre_proc_ivas_fx( st, new_swb_speech_fx_16, new_swb_speech_fx, shb_speech_fx, shb_speech_fx_32, &use_shb32, realBuffer_fx, imagBuffer_fx, q_realImagBuffer, hCPE ); + swb_pre_proc_ivas_fx( st, new_swb_speech_fx_16, new_swb_speech_fx, shb_speech_fx, &Q_shb_spch, realBuffer_fx, imagBuffer_fx, q_realImagBuffer, hCPE ); /* Re-scaling cldfb_state_fx */ scale_sig32( st->cldfbSynTd->cldfb_state_fx, st->cldfbSynTd->p_filter_length, negate( sub( q_realImagBuffer, st->cldfbSynTd->Q_cldfb_state ) ) ); #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - fixedToFloat_arr( (Word16 *) &st->hBWE_TD->old_speech_shb_fx[0], (float *) &st->hBWE_TD->old_speech_shb[0], 0, L_LOOK_16k + L_SUBFR16k ); fixedToFloat_arr( (Word16 *) &st->hBWE_FD->old_fdbwe_speech_fx[0], (float *) &st->hBWE_FD->old_fdbwe_speech[0], 0, L_FRAME48k ); fixedToFloat_arr( (Word16 *) &st->hBWE_FD->L_old_wtda_swb_fx[0], (float *) &st->hBWE_FD->old_wtda_swb[0], 0, L_FRAME48k ); for ( int ii = 0; ii < NS2SA( 48000, DELAY_FD_BWE_ENC_NS + DELAY_FIR_RESAMPL_NS ); ii++ ) @@ -945,14 +941,9 @@ ivas_error ivas_core_enc( st->hBWE_FD->old_input[ii] = (Word16) st->hBWE_FD->old_input_fx[ii]; } fixedToFloat_arr( new_swb_speech_fx_16, new_swb_speech, 0, L_FRAME48k ); - if ( use_shb32 == 0 ) - { - fixedToFloat_arr( shb_speech_fx, shb_speech, 0, L_FRAME16k ); - } - else - { - fixedToFloat_arrL( shb_speech_fx_32, shb_speech, q_realImagBuffer - 1, L_FRAME16k ); - } + + fixedToFloat_arr( shb_speech_fx, shb_speech, 0, L_FRAME16k ); + fixedToFloat_arrL32( (Word32 *) &realBuffer_fx[0][0], (float *) &realBuffer[n][0][0], q_realImagBuffer, CLDFB_NO_COL_MAX * CLDFB_NO_CHANNELS_MAX ); fixedToFloat_arrL32( (Word32 *) &imagBuffer_fx[0][0], (float *) &imagBuffer[n][0][0], q_realImagBuffer, CLDFB_NO_COL_MAX * CLDFB_NO_CHANNELS_MAX ); @@ -1003,9 +994,7 @@ ivas_error ivas_core_enc( Q_new[n] = Q_factor_arrL( bwe_exc_extended[n], L_FRAME32k + NL_BUFF_OFFSET ); Q_new[n] = Q_new[n] / 2; - Q_shb_spch = Q_factor_arr( shb_speech, L_FRAME16k ); - Q_shb_spch = min( Q_shb_spch, Q_factor_arr( st->hBWE_TD->old_speech_shb, L_LOOK_16k + L_SUBFR16k ) ); - Q_shb_spch = min( Q_shb_spch, Q_factor_arr( st->hBWE_TD->shb_inv_filt_mem, LPC_SHB_ORDER ) ); + // Q_shb_spch = Q_factor_arr( shb_speech, L_FRAME16k ); if ( st->hBWE_TD != NULL ) { @@ -1030,10 +1019,7 @@ ivas_error ivas_core_enc( if ( st->hBWE_TD != NULL ) { - floatToFixed_arr16( st->hBWE_TD->old_speech_shb, st->hBWE_TD->old_speech_shb_fx, Q_shb_spch, L_LOOK_16k + L_SUBFR16k ); - floatToFixed_arr16( st->hBWE_TD->shb_inv_filt_mem, st->hBWE_TD->shb_inv_filt_mem_fx, Q_shb_spch, LPC_SHB_ORDER ); // Check floatToFixed_arr16( st->hBWE_TD->cur_sub_Aq, st->hBWE_TD->cur_sub_Aq_fx, Q12, M + 1 ); - st->hBWE_TD->prev_pow_exc16kWhtnd_fx32 = floatToFixed( st->hBWE_TD->prev_pow_exc16kWhtnd, 0 ); floatToFixed_arr16( st->hBWE_TD->state_lpc_syn, st->hBWE_TD->state_lpc_syn_fx, ( st->prev_Q_bwe_exc - 16 ), LPC_SHB_ORDER ); floatToFixed_arr32( st->hBWE_TD->mem_csfilt, st->hBWE_TD->mem_csfilt_fx, st->prev_Q_bwe_exc, 2 ); st->hBWE_TD->gain_prec_swb_fx = float_to_fix16( st->hBWE_TD->gain_prec_swb, Q14 ); @@ -1046,10 +1032,7 @@ ivas_error ivas_core_enc( #ifdef IVAS_FLOAT_FIXED_CONVERSIONS if ( st->hBWE_TD != NULL ) { - fixedToFloat_arr( st->hBWE_TD->old_speech_shb_fx, st->hBWE_TD->old_speech_shb, Q_shb_spch, L_LOOK_16k + L_SUBFR16k ); - fixedToFloat_arr( st->hBWE_TD->shb_inv_filt_mem_fx, st->hBWE_TD->shb_inv_filt_mem, Q_shb_spch, LPC_SHB_ORDER ); // Check fixedToFloat_arr( st->hBWE_TD->cur_sub_Aq_fx, st->hBWE_TD->cur_sub_Aq, Q12, M + 1 ); - st->hBWE_TD->prev_pow_exc16kWhtnd = fixedToFloat( st->hBWE_TD->prev_pow_exc16kWhtnd_fx32, 0 ); fixedToFloat_arr( st->hBWE_TD->state_lpc_syn_fx, st->hBWE_TD->state_lpc_syn, ( st->prev_Q_bwe_exc - 16 ), LPC_SHB_ORDER ); fixedToFloat_arrL( st->hBWE_TD->mem_csfilt_fx, st->hBWE_TD->mem_csfilt, st->prev_Q_bwe_exc, 2 ); st->hBWE_TD->gain_prec_swb = fixedToFloat( st->hBWE_TD->gain_prec_swb_fx, Q14 ); @@ -1168,19 +1151,6 @@ ivas_error ivas_core_enc( } floatToFixed_arr( shb_speech, shb_speech_fx, 0, L_FRAME16k ); - - test(); - IF( EQ_32( st->core_brate, SID_2k40 ) || st->core_brate == FRAME_NO_DATA ) - { - IF( st->cng_type == LP_CNG ) - { - IF( GE_32( st->input_Fs, L_FRAME32k * FRAMES_PER_SEC ) ) - { - /* decide if SHB SID encoding or not */ - floatToFixed_arr( st->hBWE_TD->old_speech_shb, st->hBWE_TD->old_speech_shb_fx, 0, L_LOOK_16k + L_SUBFR16k ); - } - } - } #endif swb_CNG_enc_ivas_fx( st, shb_speech_fx, old_syn_12k8_16k_fx[n] ); #else diff --git a/lib_enc/ivas_masa_enc.c b/lib_enc/ivas_masa_enc.c index a2fd102b1..9fc3a0de5 100644 --- a/lib_enc/ivas_masa_enc.c +++ b/lib_enc/ivas_masa_enc.c @@ -8649,7 +8649,7 @@ static void ivas_encode_masaism_metadata_fx( } ELSE { - hOmasaData->masa_to_total_energy_ratio_fx[0][band] = MAX_32; + hOmasaData->masa_to_total_energy_ratio_fx[0][band] = ONE_IN_Q30; // Q30 move32(); } } diff --git a/lib_enc/ivas_omasa_enc.c b/lib_enc/ivas_omasa_enc.c index 48592f1b3..e99d89efd 100644 --- a/lib_enc/ivas_omasa_enc.c +++ b/lib_enc/ivas_omasa_enc.c @@ -1995,9 +1995,9 @@ static void ivas_omasa_param_est_enc_fx( /* Determine energy ratios */ FOR( band_m_idx = 0; band_m_idx < hOMasa->nbands; band_m_idx++ ) { - IF( GT_32( BASOP_Util_Log10( renormalization_factor_diff_fx[band_m_idx], ref_exp ), -( 15 << 25 ) ) ) + IF( EQ_16( BASOP_Util_Cmp_Mant32Exp( renormalization_factor_diff_fx[band_m_idx], renormalization_factor_diff_e[band_m_idx], 1 /*EPSILON Q50*/, -19 ), 1 ) ) { - diffuseness_m_fx[band_m_idx] = BASOP_Util_Divide3232_Scale( diffuseness_m_fx[band_m_idx], L_add( renormalization_factor_diff_fx[band_m_idx], EPSILON_FX ), &temp_e ); + diffuseness_m_fx[band_m_idx] = BASOP_Util_Divide3232_Scale( diffuseness_m_fx[band_m_idx], L_add( renormalization_factor_diff_fx[band_m_idx], EPSILON_FX ), &temp_e ); // Q=15-temp_e temp_e = add( temp_e, sub( diffuseness_e[band_m_idx], renormalization_factor_diff_e[band_m_idx] ) ); } ELSE diff --git a/lib_enc/stat_enc.h b/lib_enc/stat_enc.h index d5fbcc018..0f9646cac 100644 --- a/lib_enc/stat_enc.h +++ b/lib_enc/stat_enc.h @@ -1441,10 +1441,13 @@ typedef struct amrwb_io_enc_structure typedef struct td_bwe_enc_structure { - float old_speech_shb[L_LOOK_16k + L_SUBFR16k]; /* Buffer memories */ +#ifndef IVAS_FLOAT_FIXED + float old_speech_shb[L_LOOK_16k + L_SUBFR16k]; /* Buffer memories */ +#else + Word16 old_speech_shb_fx[L_LOOK_16k + L_SUBFR16k]; /* Buffer memories Q(Q_shb_spch) */ +#endif float old_speech_wb[( L_LOOK_12k8 + L_SUBFR ) * 5 / 16]; /* Buffer memories */ float old_input_fhb[NS2SA( 48000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_12k8_NS + DELAY_FIR_RESAMPL_NS ) - L_FRAME48k / 2]; - Word16 old_speech_shb_fx[L_LOOK_16k + L_SUBFR16k]; /* Buffer memories */ Word16 old_speech_wb_fx[( L_LOOK_12k8 + L_SUBFR ) * 5 / 16]; /* Buffer memories */ Word16 old_input_fhb_fx[NS2SA( 48000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_12k8_NS + DELAY_FIR_RESAMPL_NS ) - L_FRAME48k / 2]; Word16 old_input_fhb_fx_Q; @@ -1467,26 +1470,28 @@ typedef struct td_bwe_enc_structure float old_EnvSHBres[L_FRAME4k]; /* old TD envelope of the SHB residual signal */ Word16 old_EnvSHBres_fx[L_FRAME4k]; /* old TD envelope of the SHB residual signal */ #ifndef IVAS_FLOAT_FIXED - float old_mean_EnvSHBres; /* energy of the last subframe of the SHB residual signal from previous frame */ - float prev_enr_EnvSHBres; /* energy of the residual SHB envelope from the previous frame */ - float prev_shb_env_tilt; /* tilt of the residual SHB envelope from the previous frame */ + float old_mean_EnvSHBres; /* energy of the last subframe of the SHB residual signal from previous frame */ + float prev_enr_EnvSHBres; /* energy of the residual SHB envelope from the previous frame */ + float prev_shb_env_tilt; /* tilt of the residual SHB envelope from the previous frame */ + float prev_pow_exc16kWhtnd; /* power of the LB excitation signal in the previous frame */ #else Word16 old_mean_EnvSHBres_fx; /* energy of the last subframe of the SHB residual signal from previous frame Q15 */ Word32 prev_enr_EnvSHBres_fx; /* energy of the residual SHB envelope from the previous frame Q(31 - prev_enr_EnvSHBres_e) */ Word16 prev_enr_EnvSHBres_e; Word16 prev_shb_env_tilt_fx; /* tilt of the residual SHB envelope from the previous frame Q(prev_shb_env_tilt_q) */ Word16 prev_shb_env_tilt_q; -#endif - float prev_pow_exc16kWhtnd; /* power of the LB excitation signal in the previous frame */ +#if 0 Word16 prev_pow_exc16kWhtnd_fx; /* power of the LB excitation signal in the previous frame */ - Word32 prev_pow_exc16kWhtnd_fx32; /* Use this power of the LB excitation signal in the previous frame Q0 */ +#endif + Word32 prev_pow_exc16kWhtnd_fx32; /* Use this power of the LB excitation signal in the previous frame Q0 */ +#endif #ifndef IVAS_FLOAT_FIXED float prev_mix_factor; /* mixing factor in the previous frame */ + float prev_Env_error; /* error in SHB envelope modelling */ #else Word16 prev_mix_factor_fx; /* mixing factor in the previous frame Q15 */ + Word16 prev_Env_error_fx; /* error in SHB envelope modelling Q0 */ #endif - float prev_Env_error; /* error in SHB envelope modelling */ - Word16 prev_Env_error_fx; /* error in SHB envelope modelling */ /* states for the filters used in generating SHB signal from SHB excitation*/ float state_syn_shbexc[L_SHB_LAHEAD]; @@ -1525,23 +1530,23 @@ typedef struct td_bwe_enc_structure float prev_gainFr_SHB; float lsp_shb_slow_interpl[LPC_SHB_ORDER]; float lsp_shb_fast_interpl[LPC_SHB_ORDER]; + float shb_inv_filt_mem[LPC_SHB_ORDER]; #else Word32 elliptic_bpf_2_48k_mem_fx[4][4]; /* Q(elliptic_bpf_2_48k_mem_fx_Q[4]) */ Word16 elliptic_bpf_2_48k_mem_fx_Q[4]; Word32 prev_fb_energy_fx; /* Q(prev_fb_energy_fx_Q) */ Word16 prev_fb_energy_fx_Q; - Word32 prev_gainFr_SHB_fx; /* Q18 */ - Word16 lsp_shb_slow_interpl_fx[LPC_SHB_ORDER]; /* Q15 */ - Word16 lsp_shb_fast_interpl_fx[LPC_SHB_ORDER]; /* Q15 */ + Word32 prev_gainFr_SHB_fx; /* Q18 */ + Word16 lsp_shb_slow_interpl_fx[LPC_SHB_ORDER]; /* Q15 */ + Word16 lsp_shb_fast_interpl_fx[LPC_SHB_ORDER]; /* Q15 */ + Word16 shb_inv_filt_mem_fx[LPC_SHB_ORDER]; /* Q(Q_shb_spch) */ #endif - float shb_inv_filt_mem[LPC_SHB_ORDER]; - Word16 shb_inv_filt_mem_fx[LPC_SHB_ORDER]; #ifndef IVAS_FLOAT_FIXED float lsp_shb_spacing[3]; float prev_swb_GainShape; #else - Word16 lsp_shb_spacing_fx[3]; /* Q15 */ - Word16 prev_swb_GainShape_fx; /* Q15 */ + Word16 lsp_shb_spacing_fx[3]; /* Q15 */ + Word16 prev_swb_GainShape_fx; /* Q15 */ #endif int16_t prev_frGainAtten; @@ -1550,8 +1555,8 @@ typedef struct td_bwe_enc_structure float prev_wb_GainShape_flt; float swb_lsp_prev_interp[LPC_SHB_ORDER]; #else - Word16 prev_wb_GainShape; /* Q15 */ - Word16 swb_lsp_prev_interp_fx[LPC_SHB_ORDER]; /* Q15 */ + Word16 prev_wb_GainShape; /* Q15 */ + Word16 swb_lsp_prev_interp_fx[LPC_SHB_ORDER]; /* Q15 */ #endif float fb_state_lpc_syn[LPC_SHB_ORDER]; float fb_tbe_demph; @@ -1561,7 +1566,7 @@ typedef struct td_bwe_enc_structure #ifndef IVAS_FLOAT_FIXED float tilt_mem; #else - Word16 tilt_mem_fx; /* Q12 */ + Word16 tilt_mem_fx; /* Q12 */ #endif int16_t prev_coder_type; @@ -1569,8 +1574,8 @@ typedef struct td_bwe_enc_structure float prev_lsf_diff[LPC_SHB_ORDER - 2]; float prev_tilt_para; #else - Word16 prev_lsf_diff_fx[LPC_SHB_ORDER - 2]; /* Q15 */ - Word16 prev_tilt_para_fx; /* Q10 */ + Word16 prev_lsf_diff_fx[LPC_SHB_ORDER - 2]; /* Q15 */ + Word16 prev_tilt_para_fx; /* Q10 */ #endif float cur_sub_Aq[M + 1]; Word16 cur_sub_Aq_fx[M + 1]; /* Q12 */ @@ -1589,23 +1594,29 @@ typedef struct td_bwe_enc_structure int16_t gFrame_WB; int16_t idxGain; +#ifndef IVAS_FLOAT_FIXED float dec_2_over_3_mem[L_FILT_2OVER3]; float dec_2_over_3_mem_lp[L_FILT_2OVER3_LP]; +#else Word16 dec_2_over_3_mem_fx[L_FILT_2OVER3]; Word16 dec_2_over_3_mem_lp_fx[6]; +#endif float tbe_demph; float tbe_premph; float mem_stp_swb[LPC_SHB_ORDER]; float *ptr_mem_stp_swb; float gain_prec_swb; - float mem_zero_swb[LPC_SHB_ORDER]; Word16 tbe_demph_fx; /* Q(prev_Q_bwe_exc - 16 - NOISE_QADJ) */ Word16 tbe_premph_fx; /* Q(prev_Q_bwe_exc - 16) */ Word16 mem_stp_swb_fx[LPC_SHB_ORDER]; /* Q(st->prev_Q_bwe_syn) */ Word16 *ptr_mem_stp_swb_fx; Word16 gain_prec_swb_fx; /* Q14 */ +#ifndef IVAS_FLOAT_FIXED + float mem_zero_swb[LPC_SHB_ORDER]; +#else Word16 mem_zero_swb_fx[LPC_SHB_ORDER]; +#endif } TD_BWE_ENC_DATA, *TD_BWE_ENC_HANDLE; diff --git a/lib_enc/swb_pre_proc.c b/lib_enc/swb_pre_proc.c index b8c891d3c..878c1aa9b 100644 --- a/lib_enc/swb_pre_proc.c +++ b/lib_enc/swb_pre_proc.c @@ -280,12 +280,11 @@ void wb_pre_proc( #ifdef IVAS_FLOAT_FIXED /*full implementation pending*/ void swb_pre_proc_ivas_fx( - Encoder_State *st, /* i/o: encoder state structure */ - Word16 *new_swb_speech, /* o : original input signal at 32kHz - Q0 */ - Word32 *new_swb_speech_fx, /* o : original input signal at 32kHz - Q - q_reImBuffer */ - Word16 *shb_speech, /* o : SHB target signal (6-14kHz) at 16kHz- Q0 */ - Word32 *shb_speech_32, /* o : SHB target signal (6-14kHz) at 16kHz- Q - q_reImBuffer */ - Word16 *use_shb32, /* o : flags valid data in 32-bit shb buffer for better precision. */ + Encoder_State *st, /* i/o: encoder state structure */ + Word16 *new_swb_speech, /* o : original input signal at 32kHz - Q0 */ + Word32 *new_swb_speech_fx, /* o : original input signal at 32kHz - Q - q_reImBuffer */ + Word16 *shb_speech, /* o : SHB target signal (6-14kHz) at 16kHz- Q(Q_shb_spch) */ + Word16 *Q_shb_spch, Word32 realBuffer[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i : real buffer Q - q_reImbuffer */ Word32 imagBuffer[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i : imag buffer Q - q_reImbuffer */ Word16 q_reImBuffer, /* i : scale data of real and imag CLDFB buffers */ @@ -305,6 +304,7 @@ void swb_pre_proc_ivas_fx( Word32 *imagBufferFlipped[CLDFB_NO_COL_MAX]; Word32 realBufferTmp[CLDFB_NO_COL_MAX][20]; Word32 imagBufferTmp[CLDFB_NO_COL_MAX][20]; + Word32 shb_speech_fx_32[L_FRAME16k]; Word16 ts, nB, uB; Word32 v, t, regression; Word16 t_16; @@ -314,9 +314,6 @@ void swb_pre_proc_ivas_fx( Word16 Sample_Delay_SWB_BWE32k, lMemRecalc32k, dft_ovl32k; Word32 one_by_50_Q31 = 42949673; - *use_shb32 = 0; - move16(); - lMemRecalc32k = NS2SA_FX2( 32000, L_MEM_RECALC_NS ); move16(); // exp_lbEner move16(); // lMemRecalc32k @@ -787,11 +784,10 @@ void swb_pre_proc_ivas_fx( thr = icbwe_thr_TDM_fx; regV = icbwe_regressionValuesTDM_fx; - // Copy_Scale_sig_16_32((const Word16 *)&shb_speech[0], (Word32 *)&shb_speech_32[0], L_FRAME16k,Q16); - cldfbSynthesis_ivas_fx( realBufferFlipped, imagBufferFlipped, shb_speech_32, -1, st->cldfbSynTd ); - *use_shb32 = 1; + cldfbSynthesis_ivas_fx( realBufferFlipped, imagBufferFlipped, shb_speech_fx_32, -1, st->cldfbSynTd ); + Copy_Scale_sig_32_16( shb_speech_fx_32, shb_speech, L_FRAME16k, negate( sub( q_reImBuffer, 1 ) ) ); + *Q_shb_spch = 0; move16(); - Copy_Scale_sig_32_16( (const Word32 *) &shb_speech_32[0], (Word16 *) &shb_speech[0], L_FRAME16k, negate( sub( q_reImBuffer, 1 ) ) ); } IF( GE_16( st->element_mode, IVAS_CPE_DFT ) && hCPE->hStereoICBWE != NULL ) @@ -896,8 +892,6 @@ void swb_pre_proc_ivas_fx( IF( ( EQ_16( st->bwidth, FB ) || st->core == ACELP_CORE ) && ( st->element_mode == EVS_MONO ) ) { InitSWBencBufferStates_fx( st->hBWE_TD, shb_speech ); - *use_shb32 = 0; - move16(); } ELSE { @@ -942,8 +936,6 @@ void swb_pre_proc_ivas_fx( } Decimate_allpass_steep_fx( spchTmp, hBWE_TD->state_ana_filt_shb_fx, L_FRAME32k, shb_speech ); - *use_shb32 = 0; - move16(); Copy( shb_speech + L_FRAME16k - ( L_LOOK_16k + L_SUBFR16k ), hBWE_TD->old_speech_shb_fx, L_LOOK_16k + L_SUBFR16k ); @@ -983,8 +975,6 @@ void swb_pre_proc_ivas_fx( shb_speech[i] = mult_r( mult_r( i, 983 /*0.03f Q15*/ ), shb_speech[2 * delay - 1 - i] ); move16(); } - *use_shb32 = 0; - move16(); } return; diff --git a/lib_enc/swb_tbe_enc.c b/lib_enc/swb_tbe_enc.c index dad834fcf..0d3f74364 100644 --- a/lib_enc/swb_tbe_enc.c +++ b/lib_enc/swb_tbe_enc.c @@ -123,7 +123,11 @@ void InitSWBencBuffer( move16(); #endif +#ifndef IVAS_FLOAT_FIXED set_f( hBWE_TD->old_speech_shb, 0.0f, L_LOOK_16k + L_SUBFR16k ); +#else + set16_fx( hBWE_TD->old_speech_shb_fx, 0, L_LOOK_16k + L_SUBFR16k ); +#endif set_f( hBWE_TD->old_speech_wb, 0.0f, ( L_LOOK_12k8 + L_SUBFR ) * 5 / 16 ); set_f( hBWE_TD->old_input_fhb, 0.0f, NS2SA( 48000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_12k8_NS + DELAY_FIR_RESAMPL_NS ) - L_FRAME48k / 2 ); @@ -158,11 +162,12 @@ void InitSWBencBuffer( set16_fx( hBWE_TD->lsp_shb_slow_interpl_fx, 0, LPC_SHB_ORDER ); set16_fx( hBWE_TD->lsp_shb_fast_interpl_fx, 0, LPC_SHB_ORDER ); #endif - set_f( hBWE_TD->shb_inv_filt_mem, 0, LPC_SHB_ORDER ); #ifndef IVAS_FLOAT_FIXED + set_f( hBWE_TD->shb_inv_filt_mem, 0, LPC_SHB_ORDER ); set_f( hBWE_TD->lsp_shb_spacing, 0.1f, 3 ); hBWE_TD->prev_swb_GainShape = 0; #else + set16_fx( hBWE_TD->shb_inv_filt_mem_fx, 0, LPC_SHB_ORDER ); set16_fx( hBWE_TD->lsp_shb_spacing_fx, 3277, 3 ); hBWE_TD->prev_swb_GainShape_fx = 0; #endif @@ -194,23 +199,26 @@ void InitSWBencBuffer( /* TD BWE post-processing */ hBWE_TD->ptr_mem_stp_swb = hBWE_TD->mem_stp_swb + LPC_SHB_ORDER - 1; +#ifndef IVAS_FLOAT_FIXED set_f( hBWE_TD->mem_zero_swb, 0, LPC_SHB_ORDER ); -#ifndef IVAS_FLOAT_FIXED for ( i = 0; i < LPC_SHB_ORDER; i++ ) { hBWE_TD->swb_lsp_prev_interp[i] = (float) cos( (float) i * EVS_PI / (float) 10.0f ); } #else + set16_fx( hBWE_TD->mem_zero_swb_fx, 0, LPC_SHB_ORDER ); + FOR( i = 0; i < LPC_SHB_ORDER; i++ ) { hBWE_TD->swb_lsp_prev_interp_fx[i] = swb_lsp_prev_interp_init[i]; } #endif +#ifndef IVAS_FLOAT_FIXED set_f( hBWE_TD->dec_2_over_3_mem, 0.0f, L_FILT_2OVER3 ); set_f( hBWE_TD->dec_2_over_3_mem_lp, 0.0f, L_FILT_2OVER3_LP ); -#ifdef IVAS_FLOAT_FIXED +#else set16_fx( hBWE_TD->dec_2_over_3_mem_fx, 0, L_FILT_2OVER3 ); set16_fx( hBWE_TD->dec_2_over_3_mem_lp_fx, 0, L_FILT_2OVER3_LP ); #endif @@ -235,7 +243,11 @@ void InitSWBencBufferStates( set_f( shb_speech, 0.0f, L_FRAME16k ); } +#ifndef IVAS_FLOAT_FIXED set_f( hBWE_TD->old_speech_shb, 0.0f, L_LOOK_16k + L_SUBFR16k ); +#else + set16_fx( hBWE_TD->old_speech_shb_fx, 0, L_LOOK_16k + L_SUBFR16k ); +#endif set_f( hBWE_TD->mem_shb_res, 0.0f, MAX_LEN_MA_FILTER ); set16_fx( hBWE_TD->mem_shb_res_fx, 0, MAX_LEN_MA_FILTER ); set32_fx( hBWE_TD->mem_shb_res_32_fx, 0, MAX_LEN_MA_FILTER ); @@ -251,13 +263,15 @@ void InitSWBencBufferStates( hBWE_TD->prev_shb_env_tilt_fx = 0; hBWE_TD->prev_shb_env_tilt_q = 15; #endif - hBWE_TD->prev_pow_exc16kWhtnd = 1.0f; #ifndef IVAS_FLOAT_FIXED + hBWE_TD->prev_pow_exc16kWhtnd = 1.0f; hBWE_TD->prev_mix_factor = 1.0f; + hBWE_TD->prev_Env_error = 0.0f; #else + hBWE_TD->prev_pow_exc16kWhtnd_fx32 = 1; hBWE_TD->prev_mix_factor_fx = 32767; + hBWE_TD->prev_Env_error_fx = 0; #endif - hBWE_TD->prev_Env_error = 0.0f; return; } diff --git a/lib_enc/swb_tbe_enc_fx.c b/lib_enc/swb_tbe_enc_fx.c index e81ec96ba..1304bdedb 100644 --- a/lib_enc/swb_tbe_enc_fx.c +++ b/lib_enc/swb_tbe_enc_fx.c @@ -4258,7 +4258,7 @@ void swb_tbe_enc_ivas_fx( move16(); } - hBWE_TD->prev_Env_error = Env_error_fx; + hBWE_TD->prev_Env_error_fx = Env_error_fx; move16(); /* *Q_white_exc = Q_bwe_exc_mod; move16(); output Qwhiteexc_FB from the GenShapedSHB function*/ @@ -7347,8 +7347,8 @@ void InitSWBencBufferStates_fx( hBWE_TD->prev_enr_EnvSHBres_e = 31; hBWE_TD->prev_shb_env_tilt_fx = 0; hBWE_TD->prev_shb_env_tilt_q = 15; - hBWE_TD->prev_pow_exc16kWhtnd_fx = 32767; /*1.0f in Q15*/ - hBWE_TD->prev_mix_factor_fx = 32767; /*1.0f in Q15*/ + hBWE_TD->prev_pow_exc16kWhtnd_fx32 = 1; /*1.0f in Q0*/ + hBWE_TD->prev_mix_factor_fx = 32767; /*1.0f in Q15*/ hBWE_TD->prev_Env_error_fx = 0; move16(); move16(); -- GitLab From 94b25ac09e1773f58a77f083b4d144def6116493 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Tue, 12 Nov 2024 08:55:33 +0530 Subject: [PATCH 104/128] Fix for 3GPP issue 973: Yet another waveform discrepency in decoding received SBA packets with 15% FER [x] link #973 [x] Added fix for Q modification without scaling. --- lib_dec/hq_core_dec_fx.c | 1 + 1 file changed, 1 insertion(+) diff --git a/lib_dec/hq_core_dec_fx.c b/lib_dec/hq_core_dec_fx.c index cc047f9d0..a08764173 100644 --- a/lib_dec/hq_core_dec_fx.c +++ b/lib_dec/hq_core_dec_fx.c @@ -1098,6 +1098,7 @@ void ivas_hq_core_dec_fx( IF( EQ_16( st_fx->bfi, 1 ) && GE_16( output_frame, L_FRAME16k ) ) { /* PHASE_ECU active */ + Scale_sig32( t_audio_q, L_FRAME48k_EXT, sub( Q15, Q_audio ) ); Q_audio = 15; move16(); window_ola_fx( t_audio_q, synth, &Q_audio, hHQ_core->old_out_fx, &hHQ_core->Q_old_wtda, output_frame, -- GitLab From 6e37811ad86f9b5bbd2bd7cec57aa69461418e6c Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Tue, 12 Nov 2024 09:01:12 +0530 Subject: [PATCH 105/128] Fix for 3GPP issue 978: OSBA 192 kbps: Click in Concealment link #978 --- lib_dec/er_dec_tcx_fx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_dec/er_dec_tcx_fx.c b/lib_dec/er_dec_tcx_fx.c index bbe1276f1..ab1d72279 100644 --- a/lib_dec/er_dec_tcx_fx.c +++ b/lib_dec/er_dec_tcx_fx.c @@ -2105,7 +2105,7 @@ void con_tcx_ivas_fx( /* create aliasing and windowing need for transition to TCX10/5 */ bufferCopyFx( syn + L_frame, hTcxDec->syn_Overl_TDACFB, shr( L_frame, 1 ), Q_syn, 0, -1, 0 ); - hTcxDec->Q_syn_Overl_TDACFB = add( Q_syn, sub( Q_syn, -1 ) ); + hTcxDec->Q_syn_Overl_TDACFB = add( Q_syn, -1 ); move16(); FOR( i = 0; i < W12; i++ ) -- GitLab From 9f6237d8bf3647a267f23b5e5a51d4766eb5f39c Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Tue, 12 Nov 2024 14:04:04 +0530 Subject: [PATCH 106/128] Fix for high Max absolute differences observed with issue 784 fix [x] link #784 --- lib_dec/ivas_ism_param_dec.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_dec/ivas_ism_param_dec.c b/lib_dec/ivas_ism_param_dec.c index 2c72c6b48..19fa6bc62 100644 --- a/lib_dec/ivas_ism_param_dec.c +++ b/lib_dec/ivas_ism_param_dec.c @@ -2110,7 +2110,7 @@ void ivas_param_ism_dec_digest_tc_fx( hSpatParamRendCom = st_ivas->hSpatParamRendCom; assert( hSpatParamRendCom ); output_frame = imult1616( nCldfbSlots, hSpatParamRendCom->num_freq_bands ); - fade_len = shr( output_frame, 2 ); + fade_len = shr( output_frame, 1 ); nchan_transport = st_ivas->nchan_transport; move16(); -- GitLab From b7312111062711972c30448f697113523043d808 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Tue, 12 Nov 2024 15:03:59 +0530 Subject: [PATCH 107/128] Encoder code float struct elements clean up and addition of Q-info for lib_com --- lib_com/cldfb.c | 399 ++++++++++++++++++++++++++-- lib_com/ivas_prot_fx.h | 70 +++++ lib_com/ivas_sba_config.c | 2 +- lib_com/prot.h | 4 + lib_com/prot_fx.h | 6 + lib_com/stat_com.h | 14 +- lib_com/swb_tbe_com.c | 4 + lib_dec/ivas_svd_dec.c | 46 ++-- lib_enc/acelp_core_enc.c | 21 +- lib_enc/core_enc_switch.c | 6 - lib_enc/core_switching_enc.c | 29 +- lib_enc/fd_cng_enc.c | 37 +-- lib_enc/fd_cng_enc_fx.c | 24 +- lib_enc/hq_core_enc.c | 7 + lib_enc/init_enc.c | 14 +- lib_enc/ivas_core_enc.c | 108 ++------ lib_enc/ivas_core_pre_proc_front.c | 152 +++++++---- lib_enc/ivas_cpe_enc.c | 198 +++++++------- lib_enc/ivas_enc.c | 261 +++++++----------- lib_enc/ivas_front_vad.c | 217 ++++++++------- lib_enc/ivas_init_enc.c | 38 +++ lib_enc/ivas_ism_enc.c | 35 +-- lib_enc/ivas_mct_enc.c | 67 +---- lib_enc/ivas_qmetadata_enc.c | 98 +++++++ lib_enc/ivas_sba_enc.c | 36 +++ lib_enc/ivas_sce_enc.c | 344 ++++++++++++++++++++++-- lib_enc/ivas_spar_encoder.c | 47 +--- lib_enc/ivas_stat_enc.h | 14 +- lib_enc/ivas_stereo_dft_enc.c | 26 +- lib_enc/ivas_stereo_dft_enc_itd.c | 5 + lib_enc/ivas_stereo_icbwe_enc.c | 16 +- lib_enc/ivas_stereo_switching_enc.c | 5 +- lib_enc/ivas_stereo_td_enc.c | 2 +- lib_enc/lib_enc.c | 2 +- lib_enc/stat_enc.h | 184 +++++-------- lib_enc/swb_bwe_enc_fx.c | 4 + lib_enc/swb_pre_proc.c | 2 +- lib_enc/swb_tbe_enc.c | 51 +++- lib_enc/swb_tbe_enc_fx.c | 152 ++++++++++- lib_rend/ivas_omasa_ana.c | 2 + 40 files changed, 1839 insertions(+), 910 deletions(-) diff --git a/lib_com/cldfb.c b/lib_com/cldfb.c index d324afcc5..f9b618373 100644 --- a/lib_com/cldfb.c +++ b/lib_com/cldfb.c @@ -59,7 +59,11 @@ static void cldfb_init_proto_and_twiddles( HANDLE_CLDFB_FILTER_BANK hs ); +#ifdef IVAS_FLOAT_FIXED +static void cldfb_init_proto_and_twiddles_enc_fx( HANDLE_CLDFB_FILTER_BANK hs ); +#else static void cldfb_init_proto_and_twiddles_enc( HANDLE_CLDFB_FILTER_BANK hs ); +#endif #ifndef IVAS_FLOAT_FIXED static float GetEnergyCldfb_ivas( float *energyValuesSum, float *energyLookahead, float **realValues, float **imagValues, const int16_t numberBands, int16_t numberCols, TEC_ENC_HANDLE hTecEnc ); @@ -1648,9 +1652,11 @@ void configureCldfb_ivas( return; } -void configureCldfb_ivas_enc( + +#ifdef IVAS_FLOAT_FIXED +void configureCldfb_ivas_enc_fx( HANDLE_CLDFB_FILTER_BANK h_cldfb, /* i/o: filter bank handle */ - const int32_t sampling_rate /* i : sampling rate */ + const Word32 sampling_rate /* i : sampling rate */ ) { @@ -1658,18 +1664,34 @@ void configureCldfb_ivas_enc( h_cldfb->bandsToZero = 0; h_cldfb->nab = 0; - h_cldfb->no_channels = (int16_t) ( sampling_rate * INV_CLDFB_BANDWIDTH + 0.5f ); - h_cldfb->p_filter_length = 10 * h_cldfb->no_channels; -#ifdef IVAS_FLOAT_FIXED + h_cldfb->no_channels = extract_l( Mpy_32_32_r( sampling_rate, INV_CLDFB_BANDWIDTH_Q31 ) ); + h_cldfb->p_filter_length = i_mult( 10, h_cldfb->no_channels ); h_cldfb->zeros = 0; h_cldfb->anaScalefactor = 0; h_cldfb->synScalefactor = 0; h_cldfb->filterScale = 1; -#endif + cldfb_init_proto_and_twiddles_enc_fx( h_cldfb ); + + return; +} +#else +void configureCldfb_ivas_enc( + HANDLE_CLDFB_FILTER_BANK h_cldfb, /* i/o: filter bank handle */ + const int32_t sampling_rate /* i : sampling rate */ +) +{ + + h_cldfb->no_col = CLDFB_NO_COL_MAX; + h_cldfb->bandsToZero = 0; + h_cldfb->nab = 0; + + h_cldfb->no_channels = (int16_t) ( sampling_rate * INV_CLDFB_BANDWIDTH + 0.5f ); + h_cldfb->p_filter_length = 10 * h_cldfb->no_channels; cldfb_init_proto_and_twiddles_enc( h_cldfb ); return; } +#endif #ifdef IVAS_FLOAT_FIXED void configureCldfb_ivas_fx( HANDLE_CLDFB_FILTER_BANK h_cldfb, /* i/o: filter bank handle */ @@ -1822,9 +1844,11 @@ ivas_error openCldfb_ivas_enc( hs->type = type; hs->prototype = prototype; - configureCldfb_ivas_enc( hs, sampling_rate ); #ifndef IVAS_FLOAT_FIXED + configureCldfb_ivas_enc( hs, sampling_rate ); hs->memory_flt = NULL; +#else + configureCldfb_ivas_enc_fx( hs, sampling_rate ); #endif hs->memory_length = 0; @@ -2790,6 +2814,338 @@ static void cldfb_init_proto_and_twiddles( } #endif // IVAS_FLOAT_FIXED +#ifdef IVAS_FLOAT_FIXED +static void cldfb_init_proto_and_twiddles_enc_fx( + HANDLE_CLDFB_FILTER_BANK hs /* i/o: filter bank handle */ +) +{ + /*find appropriate set of rotVecs*/ + SWITCH( hs->no_channels ) + { + case 10: + hs->rot_vec_ana_re_fx = rot_vec_ana_re_L10_fx; + hs->rot_vec_ana_im_fx = rot_vec_ana_im_L10_fx; + hs->rot_vec_syn_re_fx = rot_vec_syn_re_L10_fx; + hs->rot_vec_syn_im_fx = rot_vec_syn_im_L10_fx; + hs->rRotVctr = rRotVectr_10; + hs->iRotVctr = iRotVectr_10; + IF( EQ_16( hs->type, CLDFB_SYNTHESIS ) ) + { + hs->synScalefactor = add( cldfb_synScale[0], hs->filterScale ); + move16(); + } + ELSE + { + hs->anaScalefactor = add( cldfb_anaScale[0], hs->filterScale ); + move16(); + } + IF( EQ_16( hs->prototype, CLDFB_PROTOTYPE_1_25MS ) ) + { + hs->ds = 10; + hs->da = 10; + hs->rot_vec_ana_delay_re_fx = NULL; + hs->rot_vec_ana_delay_im_fx = NULL; + hs->rot_vec_syn_delay_re_fx = NULL; + hs->rot_vec_syn_delay_im_fx = NULL; + hs->p_filter_sf = (Word16) 17036; // Q14 + hs->scale = cldfb_scale_2_5ms[0]; + move16(); + move16(); + hs->p_filter = CLDFB80_10_fx; + } + ELSE IF( EQ_16( hs->prototype, CLDFB_PROTOTYPE_5_00MS ) ) + { + hs->ds = 40; + hs->da = -20; + hs->rot_vec_ana_delay_re_fx = rot_vec_delay_re_LDQMF_fx; + hs->rot_vec_ana_delay_im_fx = rot_vec_delay_im_LDQMF_fx; + hs->rot_vec_syn_delay_re_fx = rot_vec_delay_re_LDQMF_fx; + hs->rot_vec_syn_delay_im_fx = rot_vec_delay_im_LDQMF_fx; + hs->p_filter_sf = (Word16) 15388; // Q14 + hs->p_filter = LDQMF_10_fx; + hs->scale = cldfb_scale_5_0ms[0]; + move16(); + move16(); + } + BREAK; + + case 16: + hs->rot_vec_ana_re_fx = rot_vec_ana_re_L16_fx; + hs->rot_vec_ana_im_fx = rot_vec_ana_im_L16_fx; + hs->rot_vec_syn_re_fx = rot_vec_syn_re_L16_fx; + hs->rot_vec_syn_im_fx = rot_vec_syn_im_L16_fx; + hs->rRotVctr = rRotVectr_16; + hs->iRotVctr = iRotVectr_16; + { + hs->anaScalefactor = add( cldfb_anaScale[1], hs->filterScale ); + move16(); + } + IF( EQ_16( hs->prototype, CLDFB_PROTOTYPE_1_25MS ) ) + { + hs->ds = 20; + hs->da = 20; + hs->rot_vec_ana_delay_re_fx = NULL; + hs->rot_vec_ana_delay_im_fx = NULL; + hs->rot_vec_syn_delay_re_fx = NULL; + hs->rot_vec_syn_delay_im_fx = NULL; + hs->p_filter_sf = (Word16) 17051; // Q14 + hs->p_filter = CLDFB80_16_fx; + hs->scale = cldfb_scale_2_5ms[1]; + move16(); + move16(); + } + ELSE IF( EQ_16( hs->prototype, CLDFB_PROTOTYPE_5_00MS ) ) + { + hs->ds = 80; + hs->da = -40; + hs->rot_vec_ana_delay_re_fx = rot_vec_delay_re_LDQMF_fx; + hs->rot_vec_ana_delay_im_fx = rot_vec_delay_im_LDQMF_fx; + hs->rot_vec_syn_delay_re_fx = rot_vec_delay_re_LDQMF_fx; + hs->rot_vec_syn_delay_im_fx = rot_vec_delay_im_LDQMF_fx; + hs->p_filter_sf = (Word16) 15388; // Q14 + hs->p_filter = LDQMF_16_fx; + hs->scale = cldfb_scale_5_0ms[1]; + move16(); + move16(); + } + BREAK; + + case 20: + + hs->rRotVctr = rRotVectr_20; + hs->iRotVctr = iRotVectr_20; + hs->rot_vec_ana_re_fx = rot_vec_ana_re_L20_fx; + hs->rot_vec_ana_im_fx = rot_vec_ana_im_L20_fx; + hs->rot_vec_syn_re_fx = rot_vec_syn_re_L20_fx; + hs->rot_vec_syn_im_fx = rot_vec_syn_im_L20_fx; + IF( EQ_16( hs->type, CLDFB_SYNTHESIS ) ) + { + hs->synScalefactor = add( cldfb_synScale[2], hs->filterScale ); + move16(); + } + ELSE + { + hs->anaScalefactor = add( cldfb_anaScale[2], hs->filterScale ); + move16(); + } + IF( EQ_16( hs->prototype, CLDFB_PROTOTYPE_1_25MS ) ) + { + hs->ds = 20; + hs->da = 20; + hs->rot_vec_ana_delay_re_fx = NULL; + hs->rot_vec_ana_delay_im_fx = NULL; + hs->rot_vec_syn_delay_re_fx = NULL; + hs->rot_vec_syn_delay_im_fx = NULL; + hs->p_filter_sf = (Word16) 17050; // Q14 + hs->p_filter = CLDFB80_20_fx; + hs->scale = cldfb_scale_2_5ms[2]; + move16(); + move16(); + } + ELSE IF( EQ_16( hs->prototype, CLDFB_PROTOTYPE_5_00MS ) ) + { + hs->ds = 80; + hs->da = -40; + hs->rot_vec_ana_delay_re_fx = rot_vec_delay_re_LDQMF_fx; + hs->rot_vec_ana_delay_im_fx = rot_vec_delay_im_LDQMF_fx; + hs->rot_vec_syn_delay_re_fx = rot_vec_delay_re_LDQMF_fx; + hs->rot_vec_syn_delay_im_fx = rot_vec_delay_im_LDQMF_fx; + hs->p_filter_sf = (Word16) 15390; // Q14 + hs->p_filter = LDQMF_20_fx; + hs->scale = cldfb_scale_5_0ms[2]; + move16(); + move16(); + } + BREAK; + + case 30: + hs->rot_vec_ana_re_fx = rot_vec_ana_re_L30_fx; + hs->rot_vec_ana_im_fx = rot_vec_ana_im_L30_fx; + hs->rot_vec_syn_re_fx = rot_vec_syn_re_L30_fx; + hs->rot_vec_syn_im_fx = rot_vec_syn_im_L30_fx; + hs->rRotVctr = rRotVectr_30; + hs->iRotVctr = iRotVectr_30; + IF( EQ_16( hs->type, CLDFB_SYNTHESIS ) ) + { + hs->synScalefactor = add( cldfb_synScale[6], hs->filterScale ); + move16(); + } + ELSE + { + hs->anaScalefactor = add( cldfb_anaScale[6], hs->filterScale ); + move16(); + } + IF( EQ_16( hs->prototype, CLDFB_PROTOTYPE_1_25MS ) ) + { + hs->ds = 30; + hs->da = 30; + hs->rot_vec_ana_delay_re_fx = NULL; + hs->rot_vec_ana_delay_im_fx = NULL; + hs->rot_vec_syn_delay_re_fx = NULL; + hs->rot_vec_syn_delay_im_fx = NULL; + hs->p_filter_sf = (Word16) 17051; // Q14 + hs->scale = cldfb_scale_2_5ms[6]; + hs->p_filter = CLDFB80_30_fx; + } + ELSE IF( EQ_16( hs->prototype, CLDFB_PROTOTYPE_5_00MS ) ) + { + hs->ds = 120; + hs->da = -60; + hs->rot_vec_ana_delay_re_fx = rot_vec_delay_re_LDQMF_fx; + hs->rot_vec_ana_delay_im_fx = rot_vec_delay_im_LDQMF_fx; + hs->rot_vec_syn_delay_re_fx = rot_vec_delay_re_LDQMF_fx; + hs->rot_vec_syn_delay_im_fx = rot_vec_delay_im_LDQMF_fx; + hs->p_filter_sf = (Word16) 15388; // Q14 + hs->scale = cldfb_scale_5_0ms[6]; + hs->p_filter = LDQMF_30_fx; + move16(); + move16(); + } + BREAK; + + case 32: + hs->rot_vec_ana_re_fx = rot_vec_ana_re_L32_fx; + hs->rot_vec_ana_im_fx = rot_vec_ana_im_L32_fx; + hs->rot_vec_syn_re_fx = rot_vec_syn_re_L32_fx; + hs->rot_vec_syn_im_fx = rot_vec_syn_im_L32_fx; + hs->rRotVctr = rRotVectr_32; + hs->iRotVctr = iRotVectr_32; + { + hs->anaScalefactor = add( cldfb_anaScale[3], hs->filterScale ); + move16(); + } + IF( EQ_16( hs->prototype, CLDFB_PROTOTYPE_1_25MS ) ) + { + hs->ds = 32; + hs->da = 32; + hs->rot_vec_ana_delay_re_fx = NULL; + hs->rot_vec_ana_delay_im_fx = NULL; + hs->rot_vec_syn_delay_re_fx = NULL; + hs->rot_vec_syn_delay_im_fx = NULL; + hs->p_filter_sf = (Word16) 17050; // Q14 + hs->p_filter = CLDFB80_32_fx; + hs->scale = cldfb_scale_2_5ms[3]; + move16(); + move16(); + } + ELSE IF( EQ_16( hs->prototype, CLDFB_PROTOTYPE_5_00MS ) ) + { + hs->ds = 160; + hs->da = -80; + hs->rot_vec_ana_delay_re_fx = rot_vec_delay_re_LDQMF_fx; + hs->rot_vec_ana_delay_im_fx = rot_vec_delay_im_LDQMF_fx; + hs->rot_vec_syn_delay_re_fx = rot_vec_delay_re_LDQMF_fx; + hs->rot_vec_syn_delay_im_fx = rot_vec_delay_im_LDQMF_fx; + hs->p_filter_sf = (Word16) 15392; // Q14 + hs->scale = cldfb_scale_5_0ms[3]; + hs->p_filter = LDQMF_32_fx; + move16(); + move16(); + } + BREAK; + + case 40: + hs->rot_vec_ana_re_fx = rot_vec_ana_re_L40_fx; + hs->rot_vec_ana_im_fx = rot_vec_ana_im_L40_fx; + hs->rot_vec_syn_re_fx = rot_vec_syn_re_L40_fx; + hs->rot_vec_syn_im_fx = rot_vec_syn_im_L40_fx; + hs->rRotVctr = rRotVectr_40; + hs->iRotVctr = iRotVectr_40; + IF( EQ_16( hs->type, CLDFB_SYNTHESIS ) ) + { + hs->synScalefactor = add( cldfb_synScale[4], hs->filterScale ); + move16(); + } + ELSE + { + hs->anaScalefactor = add( cldfb_anaScale[4], hs->filterScale ); + move16(); + } + IF( EQ_16( hs->prototype, CLDFB_PROTOTYPE_1_25MS ) ) + { + hs->ds = 40; + hs->da = 40; + hs->rot_vec_ana_delay_re_fx = NULL; + hs->rot_vec_ana_delay_im_fx = NULL; + hs->rot_vec_syn_delay_re_fx = NULL; + hs->rot_vec_syn_delay_im_fx = NULL; + hs->p_filter_sf = (Word16) 17051; // Q14 + hs->scale = cldfb_scale_2_5ms[4]; + hs->p_filter = CLDFB80_40_fx; + move16(); + move16(); + } + ELSE IF( EQ_16( hs->prototype, CLDFB_PROTOTYPE_5_00MS ) ) + { + hs->ds = 160; + hs->da = -80; + hs->rot_vec_ana_delay_re_fx = rot_vec_delay_re_LDQMF_fx; + hs->rot_vec_ana_delay_im_fx = rot_vec_delay_im_LDQMF_fx; + hs->rot_vec_syn_delay_re_fx = rot_vec_delay_re_LDQMF_fx; + hs->rot_vec_syn_delay_im_fx = rot_vec_delay_im_LDQMF_fx; + hs->p_filter_sf = (Word16) 15391; // Q14 + hs->p_filter = LDQMF_40_fx; + hs->scale = cldfb_scale_5_0ms[4]; + move16(); + move16(); + } + BREAK; + + case 60: + hs->rot_vec_ana_re_fx = rot_vec_ana_re_L60_fx; + hs->rot_vec_ana_im_fx = rot_vec_ana_im_L60_fx; + hs->rot_vec_syn_re_fx = rot_vec_syn_re_L60_fx; + hs->rot_vec_syn_im_fx = rot_vec_syn_im_L60_fx; + hs->rRotVctr = rRotVectr_60; + hs->iRotVctr = iRotVectr_60; + IF( EQ_16( hs->type, CLDFB_SYNTHESIS ) ) + { + hs->synScalefactor = add( cldfb_synScale[5], hs->filterScale ); + move16(); + } + ELSE + { + hs->anaScalefactor = add( cldfb_anaScale[5], hs->filterScale ); + move16(); + } + IF( EQ_16( hs->prototype, CLDFB_PROTOTYPE_1_25MS ) ) + { + hs->ds = 60; + hs->da = 60; + move16(); + move16(); + hs->rot_vec_ana_delay_re_fx = NULL; + hs->rot_vec_ana_delay_im_fx = NULL; + hs->rot_vec_syn_delay_re_fx = NULL; + hs->rot_vec_syn_delay_im_fx = NULL; + hs->p_filter_sf = (Word16) 17051; // Q14 + hs->p_filter = CLDFB80_60_fx; + hs->scale = cldfb_scale_2_5ms[5]; + move16(); + move16(); + } + ELSE IF( EQ_16( hs->prototype, CLDFB_PROTOTYPE_5_00MS ) ) + { + hs->ds = 240; + hs->da = -120; + move16(); + move16(); + hs->rot_vec_ana_delay_re_fx = rot_vec_delay_re_LDQMF_fx; + hs->rot_vec_ana_delay_im_fx = rot_vec_delay_im_LDQMF_fx; + hs->rot_vec_syn_delay_re_fx = rot_vec_delay_re_LDQMF_fx; + hs->rot_vec_syn_delay_im_fx = rot_vec_delay_im_LDQMF_fx; + hs->p_filter_sf = (Word16) 15391; // Q14 + hs->p_filter = LDQMF_60_fx; + hs->scale = cldfb_scale_5_0ms[5]; + move16(); + move16(); + } + break; + } + + return; +} +#else static void cldfb_init_proto_and_twiddles_enc( HANDLE_CLDFB_FILTER_BANK hs /* i/o: filter bank handle */ ) @@ -2825,8 +3181,8 @@ static void cldfb_init_proto_and_twiddles_enc( { hs->ds = 10; hs->da = 10; - hs->scale_flt = CLDFB80_10_SCALE; #ifndef IVAS_FLOAT_FIXED + hs->scale_flt = CLDFB80_10_SCALE; hs->p_filter_flt = CLDFB80_10_flt; hs->rot_vec_ana_delay_re = NULL; hs->rot_vec_ana_delay_im = NULL; @@ -2846,8 +3202,8 @@ static void cldfb_init_proto_and_twiddles_enc( { #ifndef IVAS_FLOAT_FIXED hs->p_filter_flt = LDQMF_10; -#endif hs->scale_flt = LDQMF_10_SCALE; +#endif hs->ds = 40; hs->da = -20; #ifndef IVAS_FLOAT_FIXED @@ -2889,8 +3245,8 @@ static void cldfb_init_proto_and_twiddles_enc( { #ifndef IVAS_FLOAT_FIXED hs->p_filter_flt = CLDFB80_16_flt; -#endif hs->scale_flt = CLDFB80_16_SCALE; +#endif hs->ds = 20; hs->da = 20; #ifndef IVAS_FLOAT_FIXED @@ -2912,8 +3268,8 @@ static void cldfb_init_proto_and_twiddles_enc( { hs->ds = 80; hs->da = -40; - hs->scale_flt = LDQMF_16_SCALE; #ifndef IVAS_FLOAT_FIXED + hs->scale_flt = LDQMF_16_SCALE; hs->p_filter_flt = LDQMF_16; hs->rot_vec_ana_delay_re = rot_vec_delay_re_LDQMF; hs->rot_vec_ana_delay_im = rot_vec_delay_im_LDQMF; @@ -2959,8 +3315,8 @@ static void cldfb_init_proto_and_twiddles_enc( { hs->ds = 20; hs->da = 20; - hs->scale_flt = CLDFB80_20_SCALE; #ifndef IVAS_FLOAT_FIXED + hs->scale_flt = CLDFB80_20_SCALE; hs->p_filter_flt = CLDFB80_20_flt; hs->rot_vec_ana_delay_re = NULL; hs->rot_vec_ana_delay_im = NULL; @@ -2980,8 +3336,8 @@ static void cldfb_init_proto_and_twiddles_enc( { hs->ds = 80; hs->da = -40; - hs->scale_flt = LDQMF_20_SCALE; #ifndef IVAS_FLOAT_FIXED + hs->scale_flt = LDQMF_20_SCALE; hs->p_filter_flt = LDQMF_20; hs->rot_vec_ana_delay_re = rot_vec_delay_re_LDQMF; hs->rot_vec_ana_delay_im = rot_vec_delay_im_LDQMF; @@ -3027,8 +3383,8 @@ static void cldfb_init_proto_and_twiddles_enc( { hs->ds = 30; hs->da = 30; - hs->scale_flt = CLDFB80_30_SCALE; #ifndef IVAS_FLOAT_FIXED + hs->scale_flt = CLDFB80_30_SCALE; hs->p_filter_flt = CLDFB80_30_flt; hs->rot_vec_ana_delay_re = NULL; hs->rot_vec_ana_delay_im = NULL; @@ -3048,8 +3404,8 @@ static void cldfb_init_proto_and_twiddles_enc( { hs->ds = 120; hs->da = -60; - hs->scale_flt = LDQMF_30_SCALE; #ifndef IVAS_FLOAT_FIXED + hs->scale_flt = LDQMF_30_SCALE; hs->p_filter_flt = LDQMF_30; hs->rot_vec_ana_delay_re = rot_vec_delay_re_LDQMF; hs->rot_vec_ana_delay_im = rot_vec_delay_im_LDQMF; @@ -3089,8 +3445,8 @@ static void cldfb_init_proto_and_twiddles_enc( { hs->ds = 32; hs->da = 32; - hs->scale_flt = CLDFB80_32_SCALE; #ifndef IVAS_FLOAT_FIXED + hs->scale_flt = CLDFB80_32_SCALE; hs->p_filter_flt = CLDFB80_32_flt; hs->rot_vec_ana_delay_re = NULL; hs->rot_vec_ana_delay_im = NULL; @@ -3110,8 +3466,8 @@ static void cldfb_init_proto_and_twiddles_enc( { hs->ds = 160; hs->da = -80; - hs->scale_flt = LDQMF_32_SCALE; #ifndef IVAS_FLOAT_FIXED + hs->scale_flt = LDQMF_32_SCALE; hs->p_filter_flt = LDQMF_32; hs->rot_vec_ana_delay_re = rot_vec_delay_re_LDQMF; hs->rot_vec_ana_delay_im = rot_vec_delay_im_LDQMF; @@ -3157,8 +3513,8 @@ static void cldfb_init_proto_and_twiddles_enc( { hs->ds = 40; hs->da = 40; - hs->scale_flt = CLDFB80_40_SCALE; #ifndef IVAS_FLOAT_FIXED + hs->scale_flt = CLDFB80_40_SCALE; hs->p_filter_flt = CLDFB80_40_flt; hs->rot_vec_ana_delay_re = NULL; hs->rot_vec_ana_delay_im = NULL; @@ -3178,8 +3534,8 @@ static void cldfb_init_proto_and_twiddles_enc( { hs->ds = 160; hs->da = -80; - hs->scale_flt = LDQMF_40_SCALE; #ifndef IVAS_FLOAT_FIXED + hs->scale_flt = LDQMF_40_SCALE; hs->p_filter_flt = LDQMF_40; hs->rot_vec_ana_delay_re = rot_vec_delay_re_LDQMF; hs->rot_vec_ana_delay_im = rot_vec_delay_im_LDQMF; @@ -3225,8 +3581,8 @@ static void cldfb_init_proto_and_twiddles_enc( { hs->ds = 60; hs->da = 60; - hs->scale_flt = CLDFB80_60_SCALE; #ifndef IVAS_FLOAT_FIXED + hs->scale_flt = CLDFB80_60_SCALE; hs->p_filter_flt = CLDFB80_60_flt; hs->rot_vec_ana_delay_re = NULL; hs->rot_vec_ana_delay_im = NULL; @@ -3246,8 +3602,8 @@ static void cldfb_init_proto_and_twiddles_enc( { hs->ds = 240; hs->da = -120; - hs->scale_flt = LDQMF_60_SCALE; #ifndef IVAS_FLOAT_FIXED + hs->scale_flt = LDQMF_60_SCALE; hs->p_filter_flt = LDQMF_60; hs->rot_vec_ana_delay_re = rot_vec_delay_re_LDQMF; hs->rot_vec_ana_delay_im = rot_vec_delay_im_LDQMF; @@ -3268,6 +3624,7 @@ static void cldfb_init_proto_and_twiddles_enc( return; } +#endif /*-------------------------------------------------------------------* * cldfb_save_memory_ivas() * diff --git a/lib_com/ivas_prot_fx.h b/lib_com/ivas_prot_fx.h index 59be73bfb..dff4997f0 100644 --- a/lib_com/ivas_prot_fx.h +++ b/lib_com/ivas_prot_fx.h @@ -5763,5 +5763,75 @@ void ivas_spar_get_cldfb_gains_fx( HANDLE_CLDFB_FILTER_BANK cldfbSynDec0, const DECODER_CONFIG_HANDLE hDecoderConfig ); +void ivas_sba_getTCs_fx( + Word32 *sba_data[], /* i : SBA signals Q11 */ + Encoder_Struct *st_ivas, /* i/o: Encoder struct */ + const Word16 input_frame /* i : frame length */ +); + +ivas_error front_vad_spar_fx( + SPAR_ENC_HANDLE hSpar, /* i/o: SPAR encoder structure */ + const Word32 *omni_in, /* i : omnidirectional input signal Q11 */ + ENCODER_CONFIG_HANDLE hEncoderConfig, /* i : encoder configuration handle */ + const Word16 input_frame /* i : input frame length */ +); + +ivas_error ivas_spar_enc_fx( + Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ + Word32 *data_fx[], /* i/o: input/transport audio channel Q11 */ + const Word16 input_frame, /* i : input frame length */ + Word16 *nb_bits_metadata, /* i : number of MD bits written */ + BSTR_ENC_HANDLE hMetaData /* o : MetaData handle */ +); + +ivas_error ivas_ism_enc_fx( + Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ + Word32 *data[], /* i : input signal [channels][samples] Q(q_data) */ + Word16 q_data, /* i : Q-factor of input signal */ + const Word16 input_frame, /* i : input frame length per channel */ + Word16 *nb_bits_metadata, /* i : number of metadata bits */ + const Word16 flag_omasa_ener_brate /* i : less bitrate for objects in OMASA flag */ +); + +ivas_error ivas_sce_enc_fx( + Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ + const Word16 sce_id, /* i : SCE # identifier */ + const Word32 data_fx[], /* i : input signal for single channel Q(q_data_fx) */ + const Word16 q_data_fx, /* i : Q-factor of input signal for single channel */ + const Word16 input_frame, /* i : input frame length per channel */ + const Word16 nb_bits_metadata /* i : number of metadata bits */ +); +ivas_error ivas_cpe_enc_fx( + Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ + const Word16 cpe_id, /* i : CPE # identifier */ + Word32 data_fx_ch0[], /* i : input signal for channel 0 Q(q_data_fx) */ + Word32 data_fx_ch1[], /* i : input signal for channel 1 Q(q_data_fx) */ + Word16 q_data_fx, /* i : Q-factor of input signal for both channels */ + const Word16 input_frame, /* i : input frame length per channel */ + const Word16 nb_bits_metadata /* i : number of metadata bits */ +); + +ivas_error ivas_mct_enc_fx( + Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ + Word32 *data_fx[MCT_MAX_CHANNELS], /* i : input signal buffers Q(q_data_fx) */ + Word16 q_data_fx, /* i : Q-factor of input signal */ + const Word16 input_frame, /* i : input frame length per channel */ + const Word16 nb_bits_metadata /* i : number of metadata bits */ +); + +ivas_error ivas_enc_fx( + Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ + const Word16 *data, /* i : input signal Q0 */ + const Word16 n_samples /* i : number of input samples */ +); + +void reset_metadata_spatial_fx( + const IVAS_FORMAT ivas_format, /* i : IVAS format */ + BSTR_ENC_HANDLE hMetaData, /* i/o: Metadata bitstream handle */ + const Word32 element_brate, /* i : element bitrate */ + Word32 *total_brate, /* o : total bitrate */ + const Word32 core_brate, /* i : core bitrate */ + const Word16 nb_bits_metadata /* i : number of meatdata bits */ +); #endif diff --git a/lib_com/ivas_sba_config.c b/lib_com/ivas_sba_config.c index 424a95b5a..8aa12792c 100644 --- a/lib_com/ivas_sba_config.c +++ b/lib_com/ivas_sba_config.c @@ -583,7 +583,7 @@ void ivas_sba_zero_vert_comp_fx( /* Keep Z if not planar */ IF( !sba_planar && EQ_16( i, 1 ) ) { - continue; + CONTINUE; } FOR( j = ( i * i + 1 ); j < ( ( i + 1 ) * ( i + 1 ) - 1 ); j++ ) diff --git a/lib_com/prot.h b/lib_com/prot.h index dc328e5d4..6c5655f99 100644 --- a/lib_com/prot.h +++ b/lib_com/prot.h @@ -9000,11 +9000,13 @@ void configureFdCngEnc( const int16_t bwidth, const int32_t total_brate ); +#ifndef IVAS_FLOAT_FIXED void initFdCngEnc( HANDLE_FD_CNG_ENC hFdCngEnc, /* i/o: Contains the variables related to the FD-based CNG process */ const int32_t input_Fs, /* i : input signal sampling frequency in Hz */ const float scale /* i : scaling factor */ ); +#endif void resetFdCngEnc( Encoder_State *st /* i/o: encoder state structure */ @@ -9194,10 +9196,12 @@ void configureCldfb_ivas( const int32_t sampling_rate /* i : sampling rate */ ); +#ifndef IVAS_FLOAT_FIXED void configureCldfb_ivas_enc( HANDLE_CLDFB_FILTER_BANK h_cldfb, /* i/o: filter bank handle */ const int32_t sampling_rate /* i : sampling rate */ ); +#endif void analysisCldfbEncoder_ivas( Encoder_State *st, /* i/o: encoder state structure */ diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index 1ac9d84c0..c95597fd7 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -11075,4 +11075,10 @@ ivas_error IGF_Reconfig_fx( const Word16 element_mode, /* i : IVAS element mode */ const Word16 rf_mode /* i : flag to signal the RF mode */ ); + +void configureCldfb_ivas_enc_fx( + HANDLE_CLDFB_FILTER_BANK h_cldfb, /* i/o: filter bank handle */ + const Word32 sampling_rate /* i : sampling rate */ +); + #endif diff --git a/lib_com/stat_com.h b/lib_com/stat_com.h index 6c19f481a..b6e68bd59 100644 --- a/lib_com/stat_com.h +++ b/lib_com/stat_com.h @@ -812,9 +812,11 @@ typedef struct cldfb_filter_bank_struct Word16 bandsToZero; /* bands not synthesized */ Word16 nab; /* number of active bands */ Word16 filtermode; - - float scale_flt; /* scaling of frequency domain */ +#ifndef IVAS_FLOAT_FIXED + float scale_flt; /* scaling of frequency domain */ +#else Word16 scale; /* scaling of frequency domain */ /* Q8 */ +#endif } CLDFB_FILTER_BANK, *HANDLE_CLDFB_FILTER_BANK; @@ -901,10 +903,10 @@ typedef struct igf_grid_struct float fFactor_flt; float lFactor_flt; #else - Word16 whiteningThreshold[2][IGF_MAX_TILES]; /* 2Q13 */ - Word16 gFactor; /* 1Q14 */ - Word16 fFactor; /* 1Q14 */ - Word16 lFactor; /* 1Q14 */ + Word16 whiteningThreshold[2][IGF_MAX_TILES]; /* 2Q13 */ + Word16 gFactor; /* 1Q14 */ + Word16 fFactor; /* 1Q14 */ + Word16 lFactor; /* 1Q14 */ #endif } IGF_GRID, *H_IGF_GRID; diff --git a/lib_com/swb_tbe_com.c b/lib_com/swb_tbe_com.c index 139e15c44..ddb28532a 100644 --- a/lib_com/swb_tbe_com.c +++ b/lib_com/swb_tbe_com.c @@ -59,6 +59,7 @@ static void Hilbert_transform( float tmp_R[], float tmp_I[], float *tmpi_R, floa static void Estimate_mix_factors( const float *shb_res, const float *exc16kWhtnd, const float *White_exc16k, const float pow1, const float pow22, float *vf_modified, int16_t *vf_ind ); #endif +#ifndef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* * swb_tbe_reset() * @@ -88,6 +89,7 @@ void swb_tbe_reset( return; } +#endif /*-------------------------------------------------------------------* @@ -1839,6 +1841,7 @@ void fb_tbe_reset_synth( return; } +#ifndef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* * wb_tbe_extras_reset() * @@ -1854,6 +1857,7 @@ void wb_tbe_extras_reset( return; } +#endif /*-------------------------------------------------------------------* * wb_tbe_extras_reset_synth() diff --git a/lib_dec/ivas_svd_dec.c b/lib_dec/ivas_svd_dec.c index 1cb20cc22..801bb9e2b 100644 --- a/lib_dec/ivas_svd_dec.c +++ b/lib_dec/ivas_svd_dec.c @@ -142,8 +142,8 @@ static void singularVectorsAccumulationLeft_fx( ); static void singularVectorsAccumulationRight_fx( - Word32 singularVectors_Left[][MAX_OUTPUT_CHANNELS], /* Q31 */ - Word32 singularVectors_Right[][MAX_OUTPUT_CHANNELS], /* Q31 */ + Word32 singularVectors_Left[][MAX_OUTPUT_CHANNELS], /* singularVectors_e */ + Word32 singularVectors_Right[][MAX_OUTPUT_CHANNELS], /* singularVectors_e */ Word32 secDiag[MAX_OUTPUT_CHANNELS], /* exp(secDiag_e) */ Word16 singularVectors_e, Word16 secDiag_e, @@ -166,9 +166,9 @@ static void flushToZeroMat_fx( #endif static Word16 BidagonalDiagonalisation_fx( - Word32 singularVectors_Left_fx[][MAX_OUTPUT_CHANNELS], /* i/o: left singular vectors (U) Q31*/ + Word32 singularVectors_Left_fx[][MAX_OUTPUT_CHANNELS], /* i/o: left singular vectors (U) singularValues_fx_e*/ Word32 singularValues_fx[MAX_OUTPUT_CHANNELS], /* i/o: singular values vector (S) singularValues_fx_e*/ - Word32 singularVectors_Right_fx[][MAX_OUTPUT_CHANNELS], /* i/o: right singular vectors (V) Q31*/ + Word32 singularVectors_Right_fx[][MAX_OUTPUT_CHANNELS], /* i/o: right singular vectors (V) singularValues_fx_e*/ Word32 secDiag_fx[MAX_OUTPUT_CHANNELS], /* i/o: secDiag_fx_e*/ Word16 singularValues_fx_e[MAX_OUTPUT_CHANNELS], /* i/o: singular values vector (S) */ Word16 *secDiag_fx_e, /* i/o: */ @@ -205,9 +205,9 @@ static Word32 GivensRotation_fx( Word16 *out_e ); static void ApplyQRTransform_fx( - Word32 singularVectors_Left[][MAX_OUTPUT_CHANNELS], /* i/o: left singular vectors (U) Q31*/ + Word32 singularVectors_Left[][MAX_OUTPUT_CHANNELS], /* i/o: left singular vectors (U) singularValues_e*/ Word32 singularValues[MAX_OUTPUT_CHANNELS], /* i/o: singular values vector (S) singularValues_e*/ - Word32 singularVectors_Right[][MAX_OUTPUT_CHANNELS], /* i/o: right singular vectors (V) Q31*/ + Word32 singularVectors_Right[][MAX_OUTPUT_CHANNELS], /* i/o: right singular vectors (V) singularValues_e*/ Word32 secDiag[MAX_OUTPUT_CHANNELS], /* i/o: secDiag_e*/ Word16 singularValues_e[MAX_OUTPUT_CHANNELS], Word16 secDiag_e[MAX_OUTPUT_CHANNELS], @@ -399,9 +399,9 @@ void svdMat2mat( Word16 svd_fx( Word32 InputMatrix[][MAX_OUTPUT_CHANNELS], /* i : matrix to be decomposed (M) InputMatrix_e*/ Word16 InputMatrix_e, - Word32 singularVectors_Left_fx[][MAX_OUTPUT_CHANNELS], /* o : left singular vectors (U) Q31*/ + Word32 singularVectors_Left_fx[][MAX_OUTPUT_CHANNELS], /* o : left singular vectors (U) singularValues_fx_e*/ Word32 singularValues_fx[MAX_OUTPUT_CHANNELS], /* o : singular values vector (S) singularValues_fx_e*/ - Word32 singularVectors_Right_fx[][MAX_OUTPUT_CHANNELS], /* o : right singular vectors (V) Q31*/ + Word32 singularVectors_Right_fx[][MAX_OUTPUT_CHANNELS], /* o : right singular vectors (V) singularValues_fx_e*/ Word16 singularValues_fx_e[MAX_OUTPUT_CHANNELS], const Word16 nChannelsL, /* i : number of rows in the matrix to be decomposed Q0*/ const Word16 nChannelsC /* i : number of columns in the matrix to be decomposed Q0*/ @@ -428,7 +428,7 @@ Word16 svd_fx( { FOR( jCh = 0; jCh < nChannelsC; jCh++ ) { - singularVectors_Left_fx[iCh][jCh] = InputMatrix[iCh][jCh]; /* Q31 */ + singularVectors_Left_fx[iCh][jCh] = InputMatrix[iCh][jCh]; /* InputMatrix_e */ move32(); } } @@ -474,21 +474,21 @@ Word16 svd_fx( FOR( jCh = 0; jCh < nChannelsL; ++jCh ) { - temp_fx = singularVectors_Left_fx[jCh][iCh]; /* Q31 */ + temp_fx = singularVectors_Left_fx[jCh][iCh]; /* singularValues_fx_e */ move32(); - singularVectors_Left_fx[jCh][iCh] = singularVectors_Left_fx[jCh][iCh + 1]; /* Q31 */ + singularVectors_Left_fx[jCh][iCh] = singularVectors_Left_fx[jCh][iCh + 1]; /* singularValues_fx_e */ move32(); - singularVectors_Left_fx[jCh][iCh + 1] = temp_fx; /* Q31 */ + singularVectors_Left_fx[jCh][iCh + 1] = temp_fx; /* singularValues_fx_e */ move32(); } FOR( jCh = 0; jCh < nChannelsC; ++jCh ) { - temp_fx = singularVectors_Right_fx[jCh][iCh]; /* Q31 */ + temp_fx = singularVectors_Right_fx[jCh][iCh]; /* singularValues_fx_e */ move32(); - singularVectors_Right_fx[jCh][iCh] = singularVectors_Right_fx[jCh][iCh + 1]; /* Q31 */ + singularVectors_Right_fx[jCh][iCh] = singularVectors_Right_fx[jCh][iCh + 1]; /* singularValues_fx_e */ move32(); - singularVectors_Right_fx[jCh][iCh + 1] = temp_fx; /* Q31 */ + singularVectors_Right_fx[jCh][iCh + 1] = temp_fx; /* singularValues_fx_e */ move32(); } } @@ -591,9 +591,9 @@ int16_t svd( #ifdef IVAS_FLOAT_FIXED static Word16 BidagonalDiagonalisation_fx( - Word32 singularVectors_Left_fx[][MAX_OUTPUT_CHANNELS], /* i/o: left singular vectors (U) Q31*/ + Word32 singularVectors_Left_fx[][MAX_OUTPUT_CHANNELS], /* i/o: left singular vectors (U) singularValues_fx_e*/ Word32 singularValues_fx[MAX_OUTPUT_CHANNELS], /* i/o: singular values vector (S) singularValues_fx_e*/ - Word32 singularVectors_Right_fx[][MAX_OUTPUT_CHANNELS], /* i/o: right singular vectors (V) Q31*/ + Word32 singularVectors_Right_fx[][MAX_OUTPUT_CHANNELS], /* i/o: right singular vectors (V) singularValues_fx_e*/ Word32 secDiag_fx[MAX_OUTPUT_CHANNELS], /* i/o: secDiag_fx_e*/ Word16 singularValues_fx_e[MAX_OUTPUT_CHANNELS], /* i/o: singular values vector (S) */ Word16 *secDiag_fx_e, /* i/o: */ @@ -893,10 +893,10 @@ static int16_t BidagonalDiagonalisation( #ifdef IVAS_FLOAT_FIXED static void ApplyQRTransform_fx( - Word32 singularVectors_Left[][MAX_OUTPUT_CHANNELS], /* i/o: left singular vectors (U) Q31*/ - Word32 singularValues[MAX_OUTPUT_CHANNELS], /* i/o: singular values vector (S) singularValues_e*/ - Word32 singularVectors_Right[][MAX_OUTPUT_CHANNELS], /* i/o: right singular vectors (V) Q31*/ - Word32 secDiag[MAX_OUTPUT_CHANNELS], /* i/o: secDiag_e*/ + Word32 singularVectors_Left[][MAX_OUTPUT_CHANNELS], /* i/o: left singular vectors (U) singularValues_e*/ + Word32 singularValues[MAX_OUTPUT_CHANNELS], /* i/o: singular values vector (S) singularValues_e*/ + Word32 singularVectors_Right[][MAX_OUTPUT_CHANNELS], /* i/o: right singular vectors (V) singularValues_e*/ + Word32 secDiag[MAX_OUTPUT_CHANNELS], /* i/o: secDiag_e*/ Word16 singularValues_e[MAX_OUTPUT_CHANNELS], Word16 secDiag_e[MAX_OUTPUT_CHANNELS], const Word16 startIndex, /* i : Q0*/ @@ -1963,8 +1963,8 @@ static void singularVectorsAccumulationLeft( #ifdef IVAS_FLOAT_FIXED static void singularVectorsAccumulationRight_fx( - Word32 singularVectors_Left[][MAX_OUTPUT_CHANNELS], /* Q31 */ - Word32 singularVectors_Right[][MAX_OUTPUT_CHANNELS], /* Q31 */ + Word32 singularVectors_Left[][MAX_OUTPUT_CHANNELS], /* exp(singularVectors_e) */ + Word32 singularVectors_Right[][MAX_OUTPUT_CHANNELS], /* exp(singularVectors_e) */ Word32 secDiag[MAX_OUTPUT_CHANNELS], /* exp(secDiag_e) */ Word16 singularVectors_e, Word16 secDiag_e, diff --git a/lib_enc/acelp_core_enc.c b/lib_enc/acelp_core_enc.c index 36861985c..47ccebb56 100644 --- a/lib_enc/acelp_core_enc.c +++ b/lib_enc/acelp_core_enc.c @@ -545,9 +545,6 @@ ivas_error acelp_core_enc( { if ( st->core_brate == SID_2k40 && st->element_mode != IVAS_CPE_MDCT ) { -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - f2me_buf( st->hFdCngEnc->msNoiseEst, st->hFdCngEnc->msNoiseEst_fx, &st->hFdCngEnc->msNoiseEst_fx_exp, st->hFdCngEnc->npartDec ); -#endif FdCng_encodeSID_ivas_fx( st ); #ifdef IVAS_FLOAT_FIXED_CONVERSIONS me2f_buf( st->hFdCngEnc->hFdCngCom->sidNoiseEst, st->hFdCngEnc->hFdCngCom->sidNoiseEstExp, st->hFdCngEnc->hFdCngCom->sidNoiseEst_flt, st->hFdCngEnc->npartDec ); @@ -575,10 +572,8 @@ ivas_error acelp_core_enc( #ifdef IVAS_FLOAT_FIXED_CONVERSIONS floatToFixed_arr( st->hFdCngEnc->hFdCngCom->A_cng_flt, st->hFdCngEnc->hFdCngCom->A_cng, Q12, ( M + 1 ) ); - // Word16 Q_exc_cng_l = Q_factor_arr( st->hFdCngEnc->hFdCngCom->exc_cng_flt, st->L_frame ); floatToFixed_arr( st->hFdCngEnc->hFdCngCom->exc_cng_flt, st->hFdCngEnc->hFdCngCom->exc_cng, Q_new, st->L_frame ); #endif - // FdCng_exc_flt( st->hFdCngEnc->hFdCngCom, &st->hDtxEnc->CNG_mode, st->L_frame, st->lsp_old, st->hDtxEnc->first_CNG, st->hDtxEnc->lspCNG, Aq, lsp_new, lsf_new, exc, exc2, bwe_exc ); FdCng_exc( st->hFdCngEnc->hFdCngCom, &st->hDtxEnc->CNG_mode, st->L_frame, st->lsp_old_fx, st->hDtxEnc->first_CNG, st->hDtxEnc->lspCNG_fx, Aq_fx, lsp_new_fx, lsf_new_fx, exc_fx, exc2_fx, bwe_exc_fx ); #ifdef IVAS_FLOAT_FIXED_CONVERSIONS fixedToFloat_arr( Aq_fx, Aq, Q12, ( st->L_frame / L_SUBFR ) * ( M + 1 ) ); @@ -1307,10 +1302,11 @@ ivas_error acelp_core_enc( { #ifndef IVAS_FLOAT_FIXED st->hBWE_TD->bwe_non_lin_prev_scale = 0.0f; + set_f( st->hBWE_TD->old_bwe_exc_extended, 0.0f, NL_BUFF_OFFSET ); #else st->hBWE_TD->bwe_non_lin_prev_scale_fx = 0; + set16_fx( st->hBWE_TD->old_bwe_exc_extended_fx, 0, NL_BUFF_OFFSET ); #endif - set_f( st->hBWE_TD->old_bwe_exc_extended, 0.0f, NL_BUFF_OFFSET ); } if ( !st->Opt_SC_VBR && ( st->idchan == 0 || st->element_mode != IVAS_CPE_TD || ( st->idchan == 1 && st->element_mode == IVAS_CPE_TD && st->tdm_LRTD_flag ) ) ) @@ -1323,22 +1319,17 @@ ivas_error acelp_core_enc( floatToFixed_arr( voice_factors, voice_factors_fx, Q15, 5 ); // Saturation Conversion used as last values have garbage values even in float Word32 bwe_exc_extended_fx[L_FRAME32k + NL_BUFF_OFFSET]; - Word16 q_bwe_exc = min( 14, Q_factor_arr( st->hBWE_TD->old_bwe_exc_extended, NL_BUFF_OFFSET ) ); + Word16 q_bwe_exc = sub( st->prev_Q_bwe_exc, 16 ) / 2; q_bwe_exc = min( q_bwe_exc, Q_factor_arr( bwe_exc, ( ( PIT16k_MAX + ( L_FRAME16k + 1 ) + L_SUBFR16k ) * 2 ) - PIT16k_MAX * 2 ) ); floatToFixed_arr16( bwe_exc, bwe_exc_fx, q_bwe_exc, ( ( PIT16k_MAX + ( L_FRAME16k + 1 ) + L_SUBFR16k ) * 2 ) - PIT16k_MAX * 2 ); - floatToFixed_arr16( st->hBWE_TD->old_bwe_exc_extended, st->hBWE_TD->old_bwe_exc_extended_fx, q_bwe_exc, NL_BUFF_OFFSET ); -#endif // IVAS_FLOAT_FIXED_CONVERSIONS - - Copy_Scale_sig_16_32( st->hBWE_TD->old_bwe_exc_extended_fx, bwe_exc_extended_fx, NL_BUFF_OFFSET, 0 ); +#endif // IVAS_FLOAT_FIXED_CONVERSIONS + Copy_Scale_sig_16_32( st->hBWE_TD->old_bwe_exc_extended_fx, bwe_exc_extended_fx, NL_BUFF_OFFSET, ( sub( shl( q_bwe_exc, 1 ), sub( st->prev_Q_bwe_exc, 16 ) ) ) ); // prev_Q_bwe_exc non_linearity_ivas_fx( bwe_exc_fx, bwe_exc_extended_fx + NL_BUFF_OFFSET, L_FRAME32k, &st->hBWE_TD->bwe_non_lin_prev_scale_fx, q_bwe_exc, st->coder_type, voice_factors_fx, st->L_frame ); // Q bwe_exc_extended_fx = 2 * Q bwe_exc_fx = 2 * q_bwe_exc - Copy_Scale_sig_32_16( bwe_exc_extended_fx + L_FRAME32k, st->hBWE_TD->old_bwe_exc_extended_fx, NL_BUFF_OFFSET, -q_bwe_exc ); - + Copy_Scale_sig_32_16( bwe_exc_extended_fx + L_FRAME32k, st->hBWE_TD->old_bwe_exc_extended_fx, NL_BUFF_OFFSET, negate( sub( shl( q_bwe_exc, 1 ), sub( st->prev_Q_bwe_exc, 16 ) ) ) ); // prev_Q_bwe_exc #ifdef IVAS_FLOAT_FIXED_CONVERSIONS fixedToFloat_arrL( bwe_exc_extended_fx, bwe_exc_extended, 2 * q_bwe_exc, L_FRAME32k + NL_BUFF_OFFSET ); - fixedToFloat_arr( st->hBWE_TD->old_bwe_exc_extended_fx, st->hBWE_TD->old_bwe_exc_extended, q_bwe_exc, NL_BUFF_OFFSET ); - #endif // IVAS_FLOAT_FIXED_CONVERSIONS #else non_linearity( bwe_exc, bwe_exc_extended, st->hBWE_TD->old_bwe_exc_extended, L_FRAME32k, &st->hBWE_TD->bwe_non_lin_prev_scale, st->coder_type, voice_factors, st->L_frame ); diff --git a/lib_enc/core_enc_switch.c b/lib_enc/core_enc_switch.c index 3f79d365d..31d300f31 100644 --- a/lib_enc/core_enc_switch.c +++ b/lib_enc/core_enc_switch.c @@ -274,12 +274,6 @@ void core_coder_mode_switch_ivas_fx( } ELSE { -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - set_f( st->hBWE_TD->state_lpc_syn, 0.0f, LPC_SHB_ORDER ); - set_f( st->hBWE_TD->state_syn_shbexc, 0.0f, L_SHB_LAHEAD ); - set_f( st->hBWE_TD->mem_stp_swb, 0.0f, LPC_SHB_ORDER ); - st->hBWE_TD->gain_prec_swb = 1.0f; -#endif set16_fx( st->hBWE_TD->state_lpc_syn_fx, 0, LPC_SHB_ORDER ); set16_fx( st->hBWE_TD->state_syn_shbexc_fx, 0, L_SHB_LAHEAD ); set16_fx( st->hBWE_TD->mem_stp_swb_fx, 0, LPC_SHB_ORDER ); diff --git a/lib_enc/core_switching_enc.c b/lib_enc/core_switching_enc.c index 7bcd3a99c..c5f197eeb 100644 --- a/lib_enc/core_switching_enc.c +++ b/lib_enc/core_switching_enc.c @@ -917,10 +917,6 @@ void core_switching_post_enc( { #ifdef IVAS_FLOAT_FIXED wb_tbe_extras_reset_fx( st->hBWE_TD->mem_genSHBexc_filt_down_wb2_fx, st->hBWE_TD->mem_genSHBexc_filt_down_wb3_fx ); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - set_f( st->hBWE_TD->mem_genSHBexc_filt_down_wb2, 0.0f, ( 2 * ALLPASSSECTIONS_STEEP + 1 ) ); - set_f( st->hBWE_TD->mem_genSHBexc_filt_down_wb3, 0.0f, ( 2 * ALLPASSSECTIONS_STEEP + 1 ) ); -#endif #else wb_tbe_extras_reset( st->hBWE_TD->mem_genSHBexc_filt_down_wb2, st->hBWE_TD->mem_genSHBexc_filt_down_wb3 ); #endif @@ -939,9 +935,15 @@ void core_switching_post_enc( } #endif +#ifndef IVAS_FLOAT_FIXED set_f( st->hBWE_TD->state_syn_shbexc, 0, L_SHB_LAHEAD / 4 ); set_f( st->hBWE_TD->syn_overlap, 0, L_SHB_LAHEAD ); set_f( st->hBWE_TD->mem_csfilt, 0, 2 ); +#else + set16_fx( st->hBWE_TD->state_syn_shbexc_fx, 0, L_SHB_LAHEAD / 4 ); + set16_fx( st->hBWE_TD->syn_overlap_fx, 0, L_SHB_LAHEAD ); + set32_fx( st->hBWE_TD->mem_csfilt_fx, 0, 2 ); +#endif } if ( ( st->extl == SWB_TBE || st->extl == FB_TBE ) && @@ -958,7 +960,6 @@ void core_switching_post_enc( #ifdef IVAS_FLOAT_FIXED_CONVERSIONS /* To be removed later when the function is converted to fixed*/ InitSWBencBufferStates( st->hBWE_TD, NULL ); - swb_tbe_reset( st->hBWE_TD->mem_csfilt, st->hBWE_TD->mem_genSHBexc_filt_down_shb, st->hBWE_TD->state_lpc_syn, st->hBWE_TD->syn_overlap, st->hBWE_TD->state_syn_shbexc, &( st->hBWE_TD->tbe_demph ), &( st->hBWE_TD->tbe_premph ), st->hBWE_TD->mem_stp_swb, &( st->hBWE_TD->gain_prec_swb ) ); #endif #else InitSWBencBufferStates( st->hBWE_TD, NULL ); @@ -974,15 +975,22 @@ void core_switching_post_enc( } else if ( ( st->extl == SWB_TBE || st->extl == FB_TBE ) && ( ( st->element_mode == IVAS_CPE_TD && st->last_extl != SWB_TBE && st->last_extl != FB_TBE ) || ( st->element_mode != IVAS_CPE_TD && st->last_total_brate != st->total_brate ) || ( st->last_bwidth != st->bwidth ) || ( st->last_codec_mode != MODE1 ) || ( st->rf_mode_last != st->rf_mode ) ) ) { +#ifndef IVAS_FLOAT_FIXED set_f( st->hBWE_TD->state_lpc_syn, 0.0f, LPC_SHB_ORDER ); set_f( st->hBWE_TD->state_syn_shbexc, 0.0f, L_SHB_LAHEAD ); - set_f( st->hBWE_TD->mem_stp_swb, 0.0f, LPC_SHB_ORDER ); +#else + set16_fx( st->hBWE_TD->state_lpc_syn_fx, 0, LPC_SHB_ORDER ); + set16_fx( st->hBWE_TD->state_syn_shbexc_fx, 0, L_SHB_LAHEAD ); +#endif #ifndef IVAS_FLOAT_FIXED + set_f( st->hBWE_TD->mem_stp_swb, 0.0f, LPC_SHB_ORDER ); set_f( st->hBWE_TD->mem_zero_swb, 0, LPC_SHB_ORDER ); + st->hBWE_TD->gain_prec_swb = 1.0f; #else + set16_fx( st->hBWE_TD->mem_stp_swb_fx, 0, LPC_SHB_ORDER ); set16_fx( st->hBWE_TD->mem_zero_swb_fx, 0, LPC_SHB_ORDER ); + st->hBWE_TD->gain_prec_swb_fx = ONE_IN_Q14; #endif - st->hBWE_TD->gain_prec_swb = 1.0f; } else if ( st->last_core == TCX_20_CORE || st->last_core == TCX_10_CORE ) { @@ -1010,8 +1018,15 @@ void core_switching_post_enc( /* Fade towards init value for non HQ_CORE */ if ( st->hHQ_core != NULL ) { +#ifndef IVAS_FLOAT_FIXED st->hHQ_core->crest_lp = HQ_CREST_FAC_SM * ( st->hHQ_core->crest_lp ) + ( 1.0f - HQ_CREST_FAC_SM ) * HQ_CREST_THRESHOLD; st->hHQ_core->crest_mod_lp = HQ_CREST_FAC_SM * ( st->hHQ_core->crest_mod_lp ) + ( 1.0f - HQ_CREST_FAC_SM ) * HQ_CREST_MOD_THRESHOLD; +#else + st->hHQ_core->crest_lp_fx = L_add( Mpy_32_32( HQ_CREST_FAC_SM_FX, st->hHQ_core->crest_lp_fx ), Mpy_32_32( L_sub( 2147483647, HQ_CREST_FAC_SM_FX ), HQ_CREST_THRESHOLD_FX ) ); /*Q28*/ + st->hHQ_core->crest_lp_q = Q28; + st->hHQ_core->crest_mod_lp_fx = L_add( Mpy_32_32( HQ_CREST_FAC_SM_FX, st->hHQ_core->crest_mod_lp_fx ), Mpy_32_32( L_sub( 2147483647, HQ_CREST_FAC_SM_FX ), HQ_CREST_MOD_THRESHOLD_FX ) ); /*Q29*/ + st->hHQ_core->crest_mod_lp_q = Q29; +#endif } } diff --git a/lib_enc/fd_cng_enc.c b/lib_enc/fd_cng_enc.c index 481d7fdf1..ab6c2efd1 100644 --- a/lib_enc/fd_cng_enc.c +++ b/lib_enc/fd_cng_enc.c @@ -90,7 +90,7 @@ ivas_error createFdCngEnc( * * Initialize FD_CNG *-------------------------------------------------------------------*/ - +#ifndef IVAS_FLOAT_FIXED void initFdCngEnc( HANDLE_FD_CNG_ENC hFdCngEnc, /* i/o: Contains the variables related to the FD-based CNG process */ const int32_t input_Fs, /* i : input signal sampling frequency in Hz */ @@ -136,43 +136,34 @@ void initFdCngEnc( } /* Initialize the Noise Estimator */ - +#ifndef IVAS_FLOAT_FIXED set_f( hFdCngEnc->msPeriodog, 0.0f, NPART ); -#if 1 // ndef IVAS_FLOAT_FIXED to be disabled - set_f( hFdCngEnc->msAlpha, 0.0f, NPART ); set_f( hFdCngEnc->msBminWin, 0.0f, NPART ); set_f( hFdCngEnc->msBminSubWin, 0.0f, NPART ); + set_f( hFdCngEnc->msAlpha, 0.0f, NPART ); set_f( hFdCngEnc->msPsd, 0.0f, NPART ); - set_f( hFdCngEnc->msNoiseFloor, 0.0f, NPART ); -#endif - set_f( hFdCngEnc->msNoiseEst, 0.0f, NPART ); - set_f( hFdCngEnc->energy_ho, 0.0f, NPART ); - set_f( hFdCngEnc->msNoiseEst_old, 0.0f, NPART ); -#if 1 // ndef IVAS_FLOAT_FIXED to be disabled set_f( hFdCngEnc->msMinBuf, FLT_MAX, MSNUMSUBFR * NPART ); set_f( hFdCngEnc->msCurrentMin, FLT_MAX, NPART ); set_f( hFdCngEnc->msCurrentMinOut, FLT_MAX, NPART ); set_f( hFdCngEnc->msCurrentMinSubWindow, FLT_MAX, NPART ); -#endif - set_s( hFdCngEnc->msLocalMinFlag, 0, NPART ); - set_s( hFdCngEnc->msNewMinFlag, 0, NPART ); -#if 1 // ndef IVAS_FLOAT_FIXED to be disabled set_f( hFdCngEnc->msPsdFirstMoment, 0.0f, NPART ); set_f( hFdCngEnc->msPsdSecondMoment, 0.0f, NPART ); -#endif - hFdCngEnc->msPeriodogBufPtr = 0; - + set_f( hFdCngEnc->msNoiseFloor, 0.0f, NPART ); + set_f( hFdCngEnc->energy_ho, 0.0f, NPART ); set_f( hFdCngEnc->msPeriodogBuf, 0.0f, MSBUFLEN * NPART ); -#if 1 // ndef IVAS_FLOAT_FIXED to be disabled set_f( hFdCngEnc->msLogPeriodog, 0.0f, NPART ); set_f( hFdCngEnc->msLogNoiseEst, 0.0f, NPART ); -#endif - -#ifndef IVAS_FLOAT_FIXED set_f( hFdCngEnc->mem_coherence, EPSILON, 4 ); + set_f( hFdCngEnc->msNoiseEst_old, 0.0f, NPART ); + set_f( hFdCngEnc->msNoiseEst, 0.0f, NPART ); #endif + set_s( hFdCngEnc->msLocalMinFlag, 0, NPART ); + set_s( hFdCngEnc->msNewMinFlag, 0, NPART ); + hFdCngEnc->msPeriodogBufPtr = 0; + return; } +#endif /*-------------------------------------------------------------------* * configureFdCngEnc() @@ -1580,8 +1571,6 @@ void FdCngEncodeMDCTStereoSID_fx( Word32 tmp32, t1, t2; #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - f2me_buf( hCPE->hCoreCoder[0]->hFdCngEnc->msNoiseEst, hCPE->hCoreCoder[0]->hFdCngEnc->msNoiseEst_fx, &hCPE->hCoreCoder[0]->hFdCngEnc->msNoiseEst_fx_exp, hCPE->hCoreCoder[0]->hFdCngEnc->npartDec ); - f2me_buf( hCPE->hCoreCoder[1]->hFdCngEnc->msNoiseEst, hCPE->hCoreCoder[1]->hFdCngEnc->msNoiseEst_fx, &hCPE->hCoreCoder[1]->hFdCngEnc->msNoiseEst_fx_exp, hCPE->hCoreCoder[0]->hFdCngEnc->npartDec ); f2me_buf( hCPE->hCoreCoder[0]->hFdCngEnc->hFdCngCom->sidNoiseEst_flt, hCPE->hCoreCoder[0]->hFdCngEnc->hFdCngCom->sidNoiseEst, &hCPE->hCoreCoder[0]->hFdCngEnc->hFdCngCom->sidNoiseEstExp, hCPE->hCoreCoder[0]->hFdCngEnc->npartDec ); f2me_buf( hCPE->hCoreCoder[1]->hFdCngEnc->hFdCngCom->sidNoiseEst_flt, hCPE->hCoreCoder[1]->hFdCngEnc->hFdCngCom->sidNoiseEst, &hCPE->hCoreCoder[1]->hFdCngEnc->hFdCngCom->sidNoiseEstExp, hCPE->hCoreCoder[0]->hFdCngEnc->npartDec ); #endif @@ -2267,8 +2256,6 @@ void FdCngEncodeDiracMDCTStereoSID_fx( #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - f2me_buf( hCPE->hCoreCoder[0]->hFdCngEnc->msNoiseEst, hCPE->hCoreCoder[0]->hFdCngEnc->msNoiseEst_fx, &hCPE->hCoreCoder[0]->hFdCngEnc->msNoiseEst_fx_exp, hCPE->hCoreCoder[0]->hFdCngEnc->npartDec ); - f2me_buf( hCPE->hCoreCoder[1]->hFdCngEnc->msNoiseEst, hCPE->hCoreCoder[1]->hFdCngEnc->msNoiseEst_fx, &hCPE->hCoreCoder[1]->hFdCngEnc->msNoiseEst_fx_exp, hCPE->hCoreCoder[1]->hFdCngEnc->npartDec ); f2me_buf( hCPE->hCoreCoder[0]->hFdCngEnc->hFdCngCom->sidNoiseEst_flt, hCPE->hCoreCoder[0]->hFdCngEnc->hFdCngCom->sidNoiseEst, &hCPE->hCoreCoder[0]->hFdCngEnc->hFdCngCom->sidNoiseEstExp, hCPE->hCoreCoder[0]->hFdCngEnc->npartDec ); f2me_buf( hCPE->hCoreCoder[1]->hFdCngEnc->hFdCngCom->sidNoiseEst_flt, hCPE->hCoreCoder[1]->hFdCngEnc->hFdCngCom->sidNoiseEst, &hCPE->hCoreCoder[1]->hFdCngEnc->hFdCngCom->sidNoiseEstExp, hCPE->hCoreCoder[1]->hFdCngEnc->npartDec ); f2me_buf( hCPE->hCoreCoder[0]->hFdCngEnc->hFdCngCom->cngNoiseLevel_flt, hCPE->hCoreCoder[0]->hFdCngEnc->hFdCngCom->cngNoiseLevel, &hCPE->hCoreCoder[0]->hFdCngEnc->hFdCngCom->cngNoiseLevelExp, FFTCLDFBLEN ); diff --git a/lib_enc/fd_cng_enc_fx.c b/lib_enc/fd_cng_enc_fx.c index 1c5a0a177..0821a3922 100644 --- a/lib_enc/fd_cng_enc_fx.c +++ b/lib_enc/fd_cng_enc_fx.c @@ -11,7 +11,7 @@ #include "rom_com_fx.h" #include "rom_com.h" #include "rom_enc.h" -//#include "prot_fx.h" +#include "prot.h" #include "prot_fx.h" #include "prot_fx_enc.h" #include "basop_util.h" @@ -57,7 +57,9 @@ void initFdCngEnc_fx( HANDLE_FD_CNG_ENC hsEnc, Word32 input_Fs, Word16 scale ) HANDLE_FD_CNG_COM hsCom = hsEnc->hFdCngCom; /* Initialize common */ - +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + initFdCngCom_flt( hsCom, scale ); +#endif initFdCngCom( hsCom, scale ); /* Configure the Noise Estimator */ @@ -93,7 +95,18 @@ void initFdCngEnc_fx( HANDLE_FD_CNG_ENC hsEnc, Word32 input_Fs, Word16 scale ) move16(); } - initPartitions( sidparts_encoder_noise_est, 24, hsCom->startBand, hsCom->stopBand, hsCom->part, &hsCom->npart, hsCom->midband, hsCom->psize, hsCom->psize_norm, &hsCom->psize_norm_exp, hsCom->psize_inv, 0 ); +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + initPartitions_flt( sidparts_encoder_noise_est, SIZE_SIDPARTS_ENC_NOISE_EST, hsCom->startBand, hsCom->stopBand, hsCom->part, &hsCom->npart, hsCom->midband, hsCom->psize_flt, hsCom->psize_inv_flt, 0 ); + + hsCom->nCLDFBpart = hsCom->npart - hsCom->nFFTpart; + for ( j = 0; j < hsCom->nCLDFBpart; j++ ) + { + hsCom->CLDFBpart[j] = hsCom->part[j + hsCom->nFFTpart] - ( 256 - hsCom->startBand ); + hsCom->CLDFBpsize_inv_flt[j] = hsCom->psize_inv_flt[j + hsCom->nFFTpart]; + } +#endif + + initPartitions( sidparts_encoder_noise_est, SIZE_SIDPARTS_ENC_NOISE_EST, hsCom->startBand, hsCom->stopBand, hsCom->part, &hsCom->npart, hsCom->midband, hsCom->psize, hsCom->psize_norm, &hsCom->psize_norm_exp, hsCom->psize_inv, 0 ); hsCom->nCLDFBpart = sub( hsCom->npart, hsCom->nFFTpart ); FOR( j = 0; j < hsCom->nCLDFBpart; j++ ) @@ -108,6 +121,8 @@ void initFdCngEnc_fx( HANDLE_FD_CNG_ENC hsEnc, Word32 input_Fs, Word16 scale ) move16(); hsEnc->msPeriodog_fx_exp_cldfb = 0; move16(); + hsEnc->msPeriodog_fx_exp = 31; + move16(); set32_fx( hsEnc->msAlpha_fx, 0, NPART ); set32_fx( hsEnc->msBminWin_fx, 0, NPART ); set32_fx( hsEnc->msBminSubWin_fx, 0, NPART ); @@ -117,7 +132,8 @@ void initFdCngEnc_fx( HANDLE_FD_CNG_ENC hsEnc, Word32 input_Fs, Word16 scale ) move16(); set32_fx( hsEnc->energy_ho_fx, 0, NPART ); set32_fx( hsEnc->msNoiseEst_old_fx, 0, NPART ); - + hsEnc->msNoiseEst_old_fx_exp = 0; + move16(); set16_fx( hsEnc->msLogPeriodog_fx, 0, NPART ); set16_fx( hsEnc->msLogNoiseEst_fx, 0, NPART ); set16_fx( hsEnc->msPsd_fx, 0, NPART ); diff --git a/lib_enc/hq_core_enc.c b/lib_enc/hq_core_enc.c index 6345a1c63..e1002faaa 100644 --- a/lib_enc/hq_core_enc.c +++ b/lib_enc/hq_core_enc.c @@ -699,8 +699,15 @@ void HQ_core_enc_init( #endif hHQ_core->last_max_pos_pulse = 0; +#ifndef IVAS_FLOAT_FIXED hHQ_core->crest_lp = HQ_CREST_THRESHOLD; hHQ_core->crest_mod_lp = HQ_CREST_MOD_THRESHOLD; +#else + hHQ_core->crest_lp_fx = HQ_CREST_THRESHOLD_FX; + hHQ_core->crest_lp_q = Q28; + hHQ_core->crest_mod_lp_fx = HQ_CREST_MOD_THRESHOLD_FX; + hHQ_core->crest_mod_lp_q = Q29; +#endif return; } diff --git a/lib_enc/init_enc.c b/lib_enc/init_enc.c index 0792fce03..355aab8d2 100644 --- a/lib_enc/init_enc.c +++ b/lib_enc/init_enc.c @@ -1105,9 +1105,10 @@ ivas_error init_encoder( return error; } - initFdCngEnc( st->hFdCngEnc, st->input_Fs, st->cldfbAnaEnc->scale_flt ); #ifdef IVAS_FLOAT_FIXED initFdCngEnc_fx( st->hFdCngEnc, st->input_Fs, st->cldfbAnaEnc->scale ); +#else + initFdCngEnc( st->hFdCngEnc, st->input_Fs, st->cldfbAnaEnc->scale_flt ); #endif /* initialization for IVAS modes happens in first frame pre-processing */ if ( st->element_mode == EVS_MONO ) @@ -1192,6 +1193,7 @@ ivas_error init_encoder_ivas_fx( Word32 igf_brate; error = IVAS_ERR_OK; + move32(); /*-----------------------------------------------------------------* * General parameters @@ -1463,6 +1465,7 @@ ivas_error init_encoder_ivas_fx( set16_fx( st->inp_16k_mem_stereo_sw_fx, 0, sub( sub( STEREO_DFT_OVL_16k, L_MEM_RECALC_16K ), L_FILT16k ) ); st->sharpFlag = 0; + move16(); /* Stationary noise UV modification */ st->ge_sm_fx = L_deposit_l( 640 ); /*Q(GE_SHIFT)*/ @@ -2312,17 +2315,8 @@ ivas_error init_encoder_ivas_fx( test(); IF( ( idchan == 0 && st->Opt_DTX_ON ) || st->element_mode == EVS_MONO || ( EQ_16( st->element_mode, IVAS_CPE_MDCT ) && st->Opt_DTX_ON ) ) { -#if 0 - IF ((error = createFdCngEnc_fx(&st->hFdCngEnc)) != IVAS_ERR_OK) - { - return error; - } -#endif createFdCngEnc_fx( &st->hFdCngEnc ); initFdCngEnc_fx( st->hFdCngEnc, st->input_Fs, st->cldfbAnaEnc->scale ); -#if 1 - initFdCngEnc( st->hFdCngEnc, st->input_Fs, st->cldfbAnaEnc->scale ); -#endif /* initialization for IVAS modes happens in first frame pre-processing */ IF( st->element_mode == EVS_MONO ) { diff --git a/lib_enc/ivas_core_enc.c b/lib_enc/ivas_core_enc.c index de065abb6..d5939811b 100644 --- a/lib_enc/ivas_core_enc.c +++ b/lib_enc/ivas_core_enc.c @@ -630,12 +630,12 @@ ivas_error ivas_core_enc( IF( NE_16( st->element_mode, EVS_MONO ) ) { - Word16 temp_e; + // Word16 temp_e; - f2me( st->hHQ_core->crest_lp, &st->hHQ_core->crest_lp_fx, &temp_e ); - st->hHQ_core->crest_lp_q = sub( Q31, temp_e ); - f2me( st->hHQ_core->crest_mod_lp, &st->hHQ_core->crest_mod_lp_fx, &temp_e ); - st->hHQ_core->crest_mod_lp_q = sub( Q31, temp_e ); + // f2me( st->hHQ_core->crest_lp, &st->hHQ_core->crest_lp_fx, &temp_e ); + // st->hHQ_core->crest_lp_q = sub( Q31, temp_e ); + // f2me( st->hHQ_core->crest_mod_lp, &st->hHQ_core->crest_mod_lp_fx, &temp_e ); + // st->hHQ_core->crest_mod_lp_q = sub( Q31, temp_e ); } floatToFixed_arr( st->input, st->input_fx, 0, 960 ); @@ -646,8 +646,8 @@ ivas_error ivas_core_enc( #ifdef IVAS_FLOAT_FIXED_CONVERSIONS IF( NE_16( st->element_mode, EVS_MONO ) ) { - st->hHQ_core->crest_lp = fix_to_float( st->hHQ_core->crest_lp_fx, st->hHQ_core->crest_lp_q ); - st->hHQ_core->crest_mod_lp = fix_to_float( st->hHQ_core->crest_mod_lp_fx, st->hHQ_core->crest_mod_lp_q ); + // st->hHQ_core->crest_lp = fix_to_float( st->hHQ_core->crest_lp_fx, st->hHQ_core->crest_lp_q ); + // st->hHQ_core->crest_mod_lp = fix_to_float( st->hHQ_core->crest_mod_lp_fx, st->hHQ_core->crest_mod_lp_q ); } IF( st->element_mode > EVS_MONO ) { @@ -780,17 +780,6 @@ ivas_error ivas_core_enc( /* Temporarily calculating variable Q. Will get Q values from core processing */ Q_new[n] = Q_factor_arrL( bwe_exc_extended[n], L_FRAME32k + NL_BUFF_OFFSET ); Q_new[n] = Q_new[n] / 2; - if ( st->hBWE_TD != NULL ) - { - Word16 tmp_q_1 = Q_factor_arr( st->hBWE_TD->mem_genSHBexc_filt_down_shb, 2 * ALLPASSSECTIONS_STEEP + 1 ); - tmp_q_1 = min( tmp_q_1, Q_factor_arr( st->hBWE_TD->mem_genSHBexc_filt_down_wb2, 2 * ALLPASSSECTIONS_STEEP + 1 ) ); - tmp_q_1 = min( tmp_q_1, Q_factor_arr( st->hBWE_TD->mem_genSHBexc_filt_down_wb3, 2 * ALLPASSSECTIONS_STEEP + 1 ) ); - tmp_q_1 = min( tmp_q_1, Q_factor_arr( st->hBWE_TD->state_syn_shbexc, L_SHB_LAHEAD ) ); - tmp_q_1 = min( tmp_q_1, Q_factor_arr( st->hBWE_TD->state_lpc_syn, L_SHB_LAHEAD ) ); - tmp_q_1 = min( tmp_q_1, Q_factor_arr( st->hBWE_TD->old_bwe_exc_extended, NL_BUFF_OFFSET ) ); - Word16 tmp_q_2 = Q_factor_arrL( st->hBWE_TD->mem_csfilt, 2 ); - st->prev_Q_bwe_exc = min( tmp_q_2, tmp_q_1 + 16 ) - 2 /* Guard bits */; /* This reset need to be looked into once core processing is complete */ - } floatToFixed_arr16( new_inp_resamp16k[n], new_inp_resamp16k_fx[n], -1, L_FRAME16k ); floatToFixed_arr( voice_factors[n], voice_factors_fx[n], Q15, NB_SUBFR16k ); // Saturation Conversion used as last values have garbage values even in float @@ -800,19 +789,6 @@ ivas_error ivas_core_enc( // prev_lsp_wb_temp_fx, prev_lsp_wb_fx and prev_lpc_wb_fx in Q15. No float counterparts floatToFixed_arr16( st->voicing, st->voicing_fx, Q15, 3 ); - if ( st->hBWE_TD != NULL ) - { - floatToFixed_arr16( st->hBWE_TD->old_speech_wb, st->hBWE_TD->old_speech_wb_fx, -1, ( L_LOOK_12k8 + L_SUBFR ) * 5 / 16 ); - floatToFixed_arr16( st->hBWE_TD->mem_genSHBexc_filt_down_shb, st->hBWE_TD->mem_genSHBexc_filt_down_shb_fx, ( st->prev_Q_bwe_exc - 16 ), 2 * ALLPASSSECTIONS_STEEP + 1 ); - floatToFixed_arr16( st->hBWE_TD->mem_genSHBexc_filt_down_wb2, st->hBWE_TD->mem_genSHBexc_filt_down_wb2_fx, ( st->prev_Q_bwe_exc - 16 ), 2 * ALLPASSSECTIONS_STEEP + 1 ); - floatToFixed_arr16( st->hBWE_TD->mem_genSHBexc_filt_down_wb3, st->hBWE_TD->mem_genSHBexc_filt_down_wb3_fx, ( st->prev_Q_bwe_exc - 16 ), 2 * ALLPASSSECTIONS_STEEP + 1 ); - floatToFixed_arr16( st->hBWE_TD->state_syn_shbexc, st->hBWE_TD->state_syn_shbexc_fx, ( st->prev_Q_bwe_exc - 16 ), L_SHB_LAHEAD ); - floatToFixed_arr16( st->hBWE_TD->state_lpc_syn, st->hBWE_TD->state_lpc_syn_fx, ( st->prev_Q_bwe_exc - 16 ), LPC_SHB_ORDER ); - floatToFixed_arr16( st->hBWE_TD->old_bwe_exc_extended, st->hBWE_TD->old_bwe_exc_extended_fx, ( st->prev_Q_bwe_exc - 16 ), NL_BUFF_OFFSET ); - floatToFixed_arr16( st->hBWE_TD->syn_overlap, st->hBWE_TD->syn_overlap_fx, 0, L_SHB_LAHEAD ); - floatToFixed_arr32( st->hBWE_TD->mem_csfilt, st->hBWE_TD->mem_csfilt_fx, st->prev_Q_bwe_exc, 2 ); - } - if ( st->hBWE_FD != NULL ) { floatToFixed_arr16( st->hBWE_FD->old_wtda_swb, st->hBWE_FD->L_old_wtda_swb_fx, -1, L_FRAME48k ); @@ -845,19 +821,6 @@ ivas_error ivas_core_enc( fixedToFloat_arr( pitch_buf_fx[n], pitch_buf[n], Q6, NB_SUBFR16k ); fixedToFloat_arrL( bwe_exc_extended_fx[n], bwe_exc_extended[n], 2 * Q_new[n], L_FRAME32k + NL_BUFF_OFFSET ); - if ( st->hBWE_TD != NULL ) - { - fixedToFloat_arr( st->hBWE_TD->old_speech_wb_fx, st->hBWE_TD->old_speech_wb, -1, ( L_LOOK_12k8 + L_SUBFR ) * 5 / 16 ); - fixedToFloat_arr( st->hBWE_TD->mem_genSHBexc_filt_down_shb_fx, st->hBWE_TD->mem_genSHBexc_filt_down_shb, ( st->prev_Q_bwe_exc - 16 ), 2 * ALLPASSSECTIONS_STEEP + 1 ); - fixedToFloat_arr( st->hBWE_TD->mem_genSHBexc_filt_down_wb2_fx, st->hBWE_TD->mem_genSHBexc_filt_down_wb2, ( st->prev_Q_bwe_exc - 16 ), 2 * ALLPASSSECTIONS_STEEP + 1 ); - fixedToFloat_arr( st->hBWE_TD->mem_genSHBexc_filt_down_wb3_fx, st->hBWE_TD->mem_genSHBexc_filt_down_wb3, ( st->prev_Q_bwe_exc - 16 ), 2 * ALLPASSSECTIONS_STEEP + 1 ); - fixedToFloat_arr( st->hBWE_TD->state_syn_shbexc_fx, st->hBWE_TD->state_syn_shbexc, ( st->prev_Q_bwe_exc - 16 ), L_SHB_LAHEAD ); - fixedToFloat_arr( st->hBWE_TD->state_lpc_syn_fx, st->hBWE_TD->state_lpc_syn, ( st->prev_Q_bwe_exc - 16 ), LPC_SHB_ORDER ); - fixedToFloat_arr( st->hBWE_TD->old_bwe_exc_extended_fx, st->hBWE_TD->old_bwe_exc_extended, ( st->prev_Q_bwe_exc - 16 ), NL_BUFF_OFFSET ); - fixedToFloat_arr( st->hBWE_TD->syn_overlap_fx, st->hBWE_TD->syn_overlap, 0, L_SHB_LAHEAD ); - fixedToFloat_arrL( st->hBWE_TD->mem_csfilt_fx, st->hBWE_TD->mem_csfilt, st->prev_Q_bwe_exc, 2 ); - } - if ( st->hBWE_FD != NULL ) { fixedToFloat_arr( st->hBWE_FD->L_old_wtda_swb_fx, st->hBWE_FD->old_wtda_swb, -1, L_FRAME48k ); @@ -949,7 +912,7 @@ ivas_error ivas_core_enc( if ( st->element_mode == IVAS_CPE_DFT ) { - hCPE->hStereoICBWE->icbweRefEner = me2f( hCPE->hStereoICBWE->icbweRefEner_fx, hCPE->hStereoICBWE->icbweRefEner_fx_e ); + // hCPE->hStereoICBWE->icbweRefEner = me2f( hCPE->hStereoICBWE->icbweRefEner_fx, hCPE->hStereoICBWE->icbweRefEner_fx_e ); fixedToFloat_arrL( hCPE->hStereoDft->output_mem_res_8k_fx, hCPE->hStereoDft->output_mem_res_8k, 16, STEREO_DFT_OVL_8k ); fixedToFloat_arrL( hCPE->hStereoDft->output_mem_dmx_fx, hCPE->hStereoDft->output_mem_dmx, 16, STEREO_DFT_OVL_MAX ); fixedToFloat_arrL( hCPE->hStereoDft->output_mem_dmx_12k8_fx, hCPE->hStereoDft->output_mem_dmx_12k8, 16, STEREO_DFT_OVL_12k8 ); @@ -996,19 +959,6 @@ ivas_error ivas_core_enc( // Q_shb_spch = Q_factor_arr( shb_speech, L_FRAME16k ); - if ( st->hBWE_TD != NULL ) - { - Word16 tmp_q_1 = Q_factor_arr( st->hBWE_TD->mem_genSHBexc_filt_down_shb, 2 * ALLPASSSECTIONS_STEEP + 1 ); - tmp_q_1 = min( tmp_q_1, Q_factor_arr( st->hBWE_TD->state_syn_shbexc, L_SHB_LAHEAD ) ); - tmp_q_1 = min( tmp_q_1, Q_factor_arr( st->hBWE_TD->state_lpc_syn, L_SHB_LAHEAD ) ); - tmp_q_1 = min( tmp_q_1, Q_factor_arr( st->hBWE_TD->old_bwe_exc_extended, NL_BUFF_OFFSET ) ); - Word16 tmp_q_2 = Q_factor_arrL( st->hBWE_TD->mem_csfilt, 2 ); - st->prev_Q_bwe_exc = min( tmp_q_2, tmp_q_1 + 16 ) - 2 /* Guard bits */; /* This reset need to be looked into once core processing is complete */ - - tmp_q_1 = Q_factor_arr( st->hBWE_TD->mem_stp_swb, LPC_SHB_ORDER ); - st->prev_Q_bwe_syn = tmp_q_1; /* This reset need to be looked into once core processing is complete */ - } - floatToFixed_arr( voice_factors[n], voice_factors_fx[n], Q15, NB_SUBFR16k ); // Saturation Conversion used as last values have garbage values even in float floatToFixed_arr( pitch_buf[n], pitch_buf_fx[n], Q6, NB_SUBFR16k ); // Saturation Conversion used as last values have garbage values even in float floatToFixed_arr32( bwe_exc_extended[n], bwe_exc_extended_fx[n], 2 * Q_new[n], L_FRAME32k + NL_BUFF_OFFSET ); @@ -1020,12 +970,6 @@ ivas_error ivas_core_enc( if ( st->hBWE_TD != NULL ) { floatToFixed_arr16( st->hBWE_TD->cur_sub_Aq, st->hBWE_TD->cur_sub_Aq_fx, Q12, M + 1 ); - floatToFixed_arr16( st->hBWE_TD->state_lpc_syn, st->hBWE_TD->state_lpc_syn_fx, ( st->prev_Q_bwe_exc - 16 ), LPC_SHB_ORDER ); - floatToFixed_arr32( st->hBWE_TD->mem_csfilt, st->hBWE_TD->mem_csfilt_fx, st->prev_Q_bwe_exc, 2 ); - st->hBWE_TD->gain_prec_swb_fx = float_to_fix16( st->hBWE_TD->gain_prec_swb, Q14 ); - floatToFixed_arr16( st->hBWE_TD->mem_stp_swb, st->hBWE_TD->mem_stp_swb_fx, st->prev_Q_bwe_syn, LPC_SHB_ORDER ); - floatToFixed_arr( &st->hBWE_TD->tbe_demph, &st->hBWE_TD->tbe_demph_fx, st->prev_Q_bwe_exc - 16 - NOISE_QADJ, 1 ); // Satruation conversion used as -ve Q not handled - floatToFixed_arr( &st->hBWE_TD->tbe_premph, &st->hBWE_TD->tbe_premph_fx, st->prev_Q_bwe_exc - 16, 1 ); // Satruation conversion used as -ve Q not handled } #endif swb_tbe_enc_ivas_fx( st, hStereoICBWE, shb_speech_fx, bwe_exc_extended_fx[n], voice_factors_fx[n], fb_exc_fx, &Q_fb_exc, Q_new[n], Q_shb_spch, st->voicing_fx, pitch_buf_fx[n] ); @@ -1033,12 +977,6 @@ ivas_error ivas_core_enc( if ( st->hBWE_TD != NULL ) { fixedToFloat_arr( st->hBWE_TD->cur_sub_Aq_fx, st->hBWE_TD->cur_sub_Aq, Q12, M + 1 ); - fixedToFloat_arr( st->hBWE_TD->state_lpc_syn_fx, st->hBWE_TD->state_lpc_syn, ( st->prev_Q_bwe_exc - 16 ), LPC_SHB_ORDER ); - fixedToFloat_arrL( st->hBWE_TD->mem_csfilt_fx, st->hBWE_TD->mem_csfilt, st->prev_Q_bwe_exc, 2 ); - st->hBWE_TD->gain_prec_swb = fixedToFloat( st->hBWE_TD->gain_prec_swb_fx, Q14 ); - fixedToFloat_arr( st->hBWE_TD->mem_stp_swb_fx, st->hBWE_TD->mem_stp_swb, st->prev_Q_bwe_syn, LPC_SHB_ORDER ); - st->hBWE_TD->tbe_demph = fixedToFloat( st->hBWE_TD->tbe_demph_fx, st->prev_Q_bwe_exc - 16 - NOISE_QADJ ); - st->hBWE_TD->tbe_premph = fixedToFloat( st->hBWE_TD->tbe_premph_fx, st->prev_Q_bwe_exc - 16 ); } #endif #else @@ -1195,7 +1133,7 @@ ivas_error ivas_core_enc( floatToFixed_arr16( hCPE->hStereoICBWE->icbwe_inp_mem[0], hCPE->hStereoICBWE->icbwe_inp_mem_fx[0], scale_factor, NS2SA( input_Fs, L_MEM_RECALC_TBE_NS ) ); floatToFixed_arr16( hCPE->hStereoICBWE->icbwe_inp_mem[1], hCPE->hStereoICBWE->icbwe_inp_mem_fx[1], scale_factor, NS2SA( input_Fs, L_MEM_RECALC_TBE_NS ) ); - floatToFixed_arr16( hCPE->hStereoICBWE->mem_decim_shb_ch0, hCPE->hStereoICBWE->mem_decim_shb_ch0_fx, 0, 90 ); + // floatToFixed_arr16( hCPE->hStereoICBWE->mem_decim_shb_ch0, hCPE->hStereoICBWE->mem_decim_shb_ch0_fx, 0, 90 ); stereo_icBWE_preproc_fx( hCPE, input_frame, new_swb_speech_buffer_fx16 /*tmp buffer*/, q_new_swb_speech_buffer ); @@ -1214,7 +1152,7 @@ ivas_error ivas_core_enc( fixedToFloat_arr( hCPE->hStereoICBWE->icbwe_inp_mem_fx[0], hCPE->hStereoICBWE->icbwe_inp_mem[0], scale_factor, NS2SA( input_Fs, L_MEM_RECALC_TBE_NS ) ); fixedToFloat_arr( hCPE->hStereoICBWE->icbwe_inp_mem_fx[1], hCPE->hStereoICBWE->icbwe_inp_mem[1], scale_factor, NS2SA( input_Fs, L_MEM_RECALC_TBE_NS ) ); - fixedToFloat_arr( hCPE->hStereoICBWE->mem_decim_shb_ch0_fx, hCPE->hStereoICBWE->mem_decim_shb_ch0, 0, 90 ); + // fixedToFloat_arr( hCPE->hStereoICBWE->mem_decim_shb_ch0_fx, hCPE->hStereoICBWE->mem_decim_shb_ch0, 0, 90 ); #else stereo_icBWE_preproc( hCPE, input_frame, new_swb_speech_buffer /*tmp buffer*/ ); @@ -1245,7 +1183,7 @@ ivas_error ivas_core_enc( f2me_buf_16( hCPE->hStereoICBWE->mem_shb_speech_nonref, hCPE->hStereoICBWE->mem_shb_speech_nonref_fx, &hCPE->hStereoICBWE->mem_shb_speech_nonref_e, L_LOOK_16k ); // shb_speech_ref_e f2me_buf_16( hCPE->hStereoICBWE->mem_shb_speech_ref, hCPE->hStereoICBWE->mem_shb_speech_ref_fx, &hCPE->hStereoICBWE->mem_shb_speech_ref_e, L_LOOK_16k ); // shb_speech_ref_e - f2me( hCPE->hStereoICBWE->icbweRefEner, &hCPE->hStereoICBWE->icbweRefEner_fx, &hCPE->hStereoICBWE->icbweRefEner_e ); + // f2me( hCPE->hStereoICBWE->icbweRefEner, &hCPE->hStereoICBWE->icbweRefEner_fx, &hCPE->hStereoICBWE->icbweRefEner_e ); scale_factor = s_min( scale_factor, Q_factor_arrL( hCPE->hStereoICBWE->mem_lpc_shbsynth_nonref, LPC_SHB_ORDER ) ); floatToFixed_arr32( hCPE->hStereoICBWE->mem_lpc_shbsynth_nonref, hCPE->hStereoICBWE->mem_lpc_shbsynth_nonref_fx, scale_factor, LPC_SHB_ORDER ); #ifdef MSAN_FIX @@ -1263,7 +1201,7 @@ ivas_error ivas_core_enc( IF( EQ_16( st->element_mode, IVAS_CPE_DFT ) ) { - hStereoICBWE->prevSpecMapping = fixedToFloat( hStereoICBWE->prevSpecMapping_fx, 31 ); + // hStereoICBWE->prevSpecMapping = fixedToFloat( hStereoICBWE->prevSpecMapping_fx, 31 ); IF( ( st->extl == SWB_TBE || st->extl == FB_TBE ) && st->flag_ACELP16k == 1 ) { fixedToFloat_arrL( hStereoICBWE->mem_lpc_shbsynth_nonref_fx, hStereoICBWE->mem_lpc_shbsynth_nonref, 31 - hStereoICBWE->mem_lpc_shbsynth_nonref_e, LPC_SHB_ORDER ); @@ -1272,29 +1210,33 @@ ivas_error ivas_core_enc( { me2f_buf_16( hStereoICBWE->shbSynthRef_fx, hStereoICBWE->shbSynthRef_e, hStereoICBWE->shbSynthRef, L_FRAME16k ); } - + /* FOR( i = 0; i < 2; i++ ) { hStereoICBWE->memGsEnerMap[i] = me2f( hStereoICBWE->memGsEnerMap_fx[i], hStereoICBWE->memGsEnerMap_e ); } - - hStereoICBWE->prevgsMapping = me2f( hStereoICBWE->prevgsMapping_fx, 0 ); + */ + // hStereoICBWE->prevgsMapping = me2f( hStereoICBWE->prevgsMapping_fx, 0 ); IF( ( EQ_16( st->extl, SWB_TBE ) || EQ_16( st->extl, WB_TBE ) || EQ_16( st->extl, FB_TBE ) ) && EQ_16( st->flag_ACELP16k, 1 ) ) { - hStereoICBWE->prevSpecMapping = fixedToFloat( hStereoICBWE->prevSpecMapping_fx, Q31 ); + // hStereoICBWE->prevSpecMapping = fixedToFloat( hStereoICBWE->prevSpecMapping_fx, Q31 ); hStereoICBWE->memShbSpecMapping = fixedToFloat( hStereoICBWE->memShbSpecMapping_fx, 31 - hStereoICBWE->memShbSpecMapping_e ); } ELSE { hStereoICBWE->memShbSpecMapping = 0; +#ifndef IVAS_FLOAT_FIXED hStereoICBWE->prevSpecMapping = 0; +#else + hStereoICBWE->prevSpecMapping_fx = 0; +#endif } } ELSE { - hStereoICBWE->prevgsMapping = me2f( hStereoICBWE->prevgsMapping_fx, hStereoICBWE->prevgsMapping_e ); - hStereoICBWE->gDes_pastFrame = me2f( hStereoICBWE->gDes_pastFrame_fx, hStereoICBWE->gDes_pastFrame_e ); + // hStereoICBWE->prevgsMapping = me2f( hStereoICBWE->prevgsMapping_fx, hStereoICBWE->prevgsMapping_e ); + // hStereoICBWE->gDes_pastFrame = me2f( hStereoICBWE->gDes_pastFrame_fx, hStereoICBWE->gDes_pastFrame_e ); IF( ( st->extl == SWB_TBE || st->extl == WB_TBE || st->extl == FB_TBE ) && st->flag_ACELP16k == 1 ) { @@ -1304,13 +1246,13 @@ ivas_error ivas_core_enc( hStereoICBWE->memShbSpecMapping = me2f( hStereoICBWE->memShbSpecMapping_fx, hStereoICBWE->memShbSpecMapping_e ); } - hStereoICBWE->prevRefEner = fixedToFloat( hStereoICBWE->prevRefEner_fx, 31 - hStereoICBWE->prevRefEner_e ); - hStereoICBWE->prevNonRefEner = fixedToFloat( hStereoICBWE->prevNonRefEner_fx, 31 - hStereoICBWE->prevNonRefEner_e ); + // hStereoICBWE->prevRefEner = fixedToFloat( hStereoICBWE->prevRefEner_fx, 31 - hStereoICBWE->prevRefEner_e ); + // hStereoICBWE->prevNonRefEner = fixedToFloat( hStereoICBWE->prevNonRefEner_fx, 31 - hStereoICBWE->prevNonRefEner_e ); IF( ( st->extl == SWB_TBE || st->extl == FB_TBE ) && st->flag_ACELP16k == 1 ) { fixedToFloat_arrL( hStereoICBWE->mem_lpc_shbsynth_nonref_fx, hStereoICBWE->mem_lpc_shbsynth_nonref, 31 - hStereoICBWE->mem_lpc_shbsynth_nonref_e, LPC_SHB_ORDER ); } - hStereoICBWE->gDes_pastFrame = me2f( hStereoICBWE->gDes_pastFrame_fx, hStereoICBWE->gDes_pastFrame_e ); + // hStereoICBWE->gDes_pastFrame = me2f( hStereoICBWE->gDes_pastFrame_fx, hStereoICBWE->gDes_pastFrame_e ); } #endif #else diff --git a/lib_enc/ivas_core_pre_proc_front.c b/lib_enc/ivas_core_pre_proc_front.c index 1dfe55f3b..4bd981654 100644 --- a/lib_enc/ivas_core_pre_proc_front.c +++ b/lib_enc/ivas_core_pre_proc_front.c @@ -73,6 +73,20 @@ static void calculate_energy_buffer_fx( CPE_ENC_HANDLE hCPE, Word64 enerBuffer_d * Front Pre-processing for IVAS * (resampling, spectral analysis, LP analysis, VAD, OL pitch calculation, classification) *--------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +static Word16 get_zero_flag( Word32 arr[], Word16 len ) +{ + FOR( Word16 j = 0; j < len; j++ ) + { + IF( arr[j] != 0 ) + { + return 1; + BREAK; + } + } + return 0; +} +#endif #ifndef IVAS_FLOAT_FIXED ivas_error pre_proc_front_ivas( @@ -1615,9 +1629,6 @@ ivas_error pre_proc_front_ivas_fx( floatToFixed_arrL( st->hNoiseEst->enrO, st->hNoiseEst->enrO_fx, Q_new + QSCALE, 20 ); st->flag_noisy_speech_snr_fx = (Word8) st->flag_noisy_speech_snr; - if ( st->cldfbAnaEnc ) - st->cldfbAnaEnc->scale = (Word16) ( st->cldfbAnaEnc->scale_flt * ( 1 << 8 ) ); - Word16 Q_bands0 = 0, Q_bands1 = 0; IF( lr_vad_enabled && st->idchan == 0 ) { @@ -1851,16 +1862,32 @@ ivas_error pre_proc_front_ivas_fx( #else floatToFixed_arrL( enerBuffer, enerBuffer_fx_loc, ( 31 - enerBuffer_fx_exp ), CLDFB_NO_CHANNELS_MAX ); #endif - Word16 normmsPeriodog = Q_factor_arrL( st->hFdCngEnc->msPeriodog, NPART ); - st->hFdCngEnc->msPeriodog_fx_exp = 31 - normmsPeriodog; - st->hFdCngEnc->msPeriodog_fx_exp_cldfb = 31 - normmsPeriodog; - st->hFdCngEnc->msPeriodog_fx_exp_fft = 31 - normmsPeriodog; - floatToFixed_arrL( st->hFdCngEnc->msPeriodog, st->hFdCngEnc->msPeriodog_fx, 31 - st->hFdCngEnc->msPeriodog_fx_exp, NPART ); - - // not needed actuall its just output - Word16 normmsNoiseEst = Q_factor_arrL( st->hFdCngEnc->msNoiseEst, NPART ); - st->hFdCngEnc->msNoiseEst_fx_exp = 31 - normmsNoiseEst; - floatToFixed_arrL( st->hFdCngEnc->msNoiseEst, st->hFdCngEnc->msNoiseEst_fx, 31 - st->hFdCngEnc->msNoiseEst_fx_exp, NPART ); + Word16 normmsPeriodog_fx = Q31, zero_flag = 0; + move16(); + move16(); + zero_flag = get_zero_flag( st->hFdCngEnc->msPeriodog_fx, NPART ); + IF( zero_flag ) + { + normmsPeriodog_fx = getScaleFactor32( st->hFdCngEnc->msPeriodog_fx, NPART ); + move16(); + } + st->hFdCngEnc->msPeriodog_fx_exp_cldfb = sub( 31, normmsPeriodog_fx ); + st->hFdCngEnc->msPeriodog_fx_exp_fft = sub( 31, normmsPeriodog_fx ); + move16(); + move16(); + Scale_sig32( st->hFdCngEnc->msPeriodog_fx, NPART, normmsPeriodog_fx ); + st->hFdCngEnc->msPeriodog_fx_exp = sub( st->hFdCngEnc->msPeriodog_fx_exp, normmsPeriodog_fx ); + Word16 msNoiseEst_Q = Q31; + move16(); + move16(); + zero_flag = get_zero_flag( st->hFdCngEnc->msNoiseEst_fx, NPART ); + IF( zero_flag ) + { + msNoiseEst_Q = getScaleFactor32( st->hFdCngEnc->msNoiseEst_fx, NPART ); + } + Scale_sig32( st->hFdCngEnc->msNoiseEst_old_fx, NPART, msNoiseEst_Q ); + st->hFdCngEnc->msNoiseEst_fx_exp = sub( st->hFdCngEnc->msNoiseEst_old_fx_exp, msNoiseEst_Q ); + move16(); #ifdef MSAN_FIX floatToFixed_arr( st->hFdCngEnc->hFdCngCom->CLDFBpsize_inv_flt, st->hFdCngEnc->hFdCngCom->CLDFBpsize_inv, 15, st->hFdCngEnc->hFdCngCom->nCLDFBpart ); #else @@ -1868,10 +1895,6 @@ ivas_error pre_proc_front_ivas_fx( #endif #endif perform_noise_estimation_enc_ivas_fx( band_energies_LR_fx, band_energies_LR_fx_exp, enerBuffer_fx_loc, enerBuffer_fx_exp, st->hFdCngEnc, input_Fs, hCPE ); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - fixedToFloat_arrL( st->hFdCngEnc->msNoiseEst_fx, st->hFdCngEnc->msNoiseEst, 31 - st->hFdCngEnc->msNoiseEst_fx_exp, NPART ); - fixedToFloat_arrL( st->hFdCngEnc->msPeriodog_fx, st->hFdCngEnc->msPeriodog, 31 - st->hFdCngEnc->msPeriodog_fx_exp, NPART ); -#endif } else { @@ -1895,16 +1918,32 @@ ivas_error pre_proc_front_ivas_fx( #else floatToFixed_arrL( enerBuffer, enerBuffer_fx_loc, ( 31 - enerBuffer_fx_exp ), CLDFB_NO_CHANNELS_MAX ); #endif - Word16 normmsPeriodog = Q_factor_arrL( st->hFdCngEnc->msPeriodog, NPART ); - st->hFdCngEnc->msPeriodog_fx_exp = 31 - normmsPeriodog; - st->hFdCngEnc->msPeriodog_fx_exp_cldfb = 31 - normmsPeriodog; - st->hFdCngEnc->msPeriodog_fx_exp_fft = 31 - normmsPeriodog; - floatToFixed_arrL( st->hFdCngEnc->msPeriodog, st->hFdCngEnc->msPeriodog_fx, 31 - st->hFdCngEnc->msPeriodog_fx_exp, NPART ); - - // not needed actuall its just output - Word16 normmsNoiseEst = Q_factor_arrL( st->hFdCngEnc->msNoiseEst, NPART ); - st->hFdCngEnc->msNoiseEst_fx_exp = 31 - normmsNoiseEst; - floatToFixed_arrL( st->hFdCngEnc->msNoiseEst, st->hFdCngEnc->msNoiseEst_fx, 31 - st->hFdCngEnc->msNoiseEst_fx_exp, NPART ); + Word16 normmsPeriodog_fx = Q31, zero_flag = 0; + move16(); + move16(); + zero_flag = get_zero_flag( st->hFdCngEnc->msPeriodog_fx, NPART ); + IF( zero_flag ) + { + normmsPeriodog_fx = getScaleFactor32( st->hFdCngEnc->msPeriodog_fx, NPART ); + move16(); + } + st->hFdCngEnc->msPeriodog_fx_exp_cldfb = sub( 31, normmsPeriodog_fx ); + st->hFdCngEnc->msPeriodog_fx_exp_fft = sub( 31, normmsPeriodog_fx ); + move16(); + move16(); + Scale_sig32( st->hFdCngEnc->msPeriodog_fx, NPART, normmsPeriodog_fx ); + st->hFdCngEnc->msPeriodog_fx_exp = st->hFdCngEnc->msPeriodog_fx_exp - normmsPeriodog_fx; + move16(); + Word16 msNoiseEst_Q = Q31; + move16(); + zero_flag = get_zero_flag( st->hFdCngEnc->msNoiseEst_fx, NPART ); + IF( zero_flag ) + { + msNoiseEst_Q = getScaleFactor32( st->hFdCngEnc->msNoiseEst_fx, NPART ); + } + Scale_sig32( st->hFdCngEnc->msNoiseEst_old_fx, NPART, msNoiseEst_Q ); + st->hFdCngEnc->msNoiseEst_fx_exp = st->hFdCngEnc->msNoiseEst_old_fx_exp - msNoiseEst_Q; + move16(); #ifdef MSAN_FIX floatToFixed_arr( st->hFdCngEnc->hFdCngCom->CLDFBpsize_inv_flt, st->hFdCngEnc->hFdCngCom->CLDFBpsize_inv, 15, st->hFdCngEnc->hFdCngCom->nCLDFBpart ); #else @@ -1912,20 +1951,11 @@ ivas_error pre_proc_front_ivas_fx( #endif Word16 normmsperiodog = Q_factor_arrL( st->hFdCngEnc->hFdCngCom->periodog_flt, PERIODOGLEN ); st->hFdCngEnc->hFdCngCom->exp_cldfb_periodog = 31 - normmsperiodog; - // floatToFixed_arrL( st->hFdCngEnc->hFdCngCom->periodog_flt, st->hFdCngEnc->hFdCngCom->periodog, 31 - st->hFdCngEnc->hFdCngCom->exp_cldfb_periodog, PERIODOGLEN); - floatToFixed_arr( st->hFdCngEnc->msPeriodogBuf, st->hFdCngEnc->msPeriodogBuf_fx, 9, MSBUFLEN * NPART ); st->hFdCngEnc->hFdCngCom->init_old = (Word16) ( st->hFdCngEnc->hFdCngCom->init_old_flt * ( 1 << 9 ) ); st->hFdCngEnc->hFdCngCom->scalingFactor = (Word16) ( st->hFdCngEnc->hFdCngCom->scalingFactor * ( 1 << 30 ) ); #endif perform_noise_estimation_enc_ivas_fx( band_energies_fx, band_energies_fx_exp, enerBuffer_fx_loc, enerBuffer_fx_exp, st->hFdCngEnc, input_Fs, hCPE ); - -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - fixedToFloat_arrL( st->hFdCngEnc->msNoiseEst_fx, st->hFdCngEnc->msNoiseEst, 31 - st->hFdCngEnc->msNoiseEst_fx_exp, NPART ); - fixedToFloat_arr( st->hFdCngEnc->msPeriodogBuf_fx, st->hFdCngEnc->msPeriodogBuf, 9, MSBUFLEN * NPART ); - fixedToFloat_arrL( st->hFdCngEnc->msPeriodog_fx, st->hFdCngEnc->msPeriodog, 31 - st->hFdCngEnc->msPeriodog_fx_exp, NPART ); - // fixedToFloat_arrL(st->hFdCngEnc->hFdCngCom->periodog, st->hFdCngEnc->hFdCngCom->periodog_flt, 31 - st->hFdCngEnc->hFdCngCom->exp_cldfb_periodog, PERIODOGLEN); -#endif } } } @@ -1976,30 +2006,44 @@ ivas_error pre_proc_front_ivas_fx( } } - if ( st->hFdCngEnc != NULL && st->Opt_DTX_ON ) + IF( st->hFdCngEnc != NULL && st->Opt_DTX_ON ) { -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - st->hFdCngEnc->msPeriodog_fx_exp = 31 - Q_factor_arrL( st->hFdCngEnc->msPeriodog, NPART ); + Word16 zero_flag = 0, msPeriodog_fx_Q = Q31; + move16(); + move16(); + zero_flag = get_zero_flag( st->hFdCngEnc->msPeriodog_fx, NPART ); + IF( zero_flag ) + { + msPeriodog_fx_Q = getScaleFactor32( st->hFdCngEnc->msPeriodog_fx, NPART ); + } + msPeriodog_fx_Q = sub( sub( 31, msPeriodog_fx_Q ), st->hFdCngEnc->msPeriodog_fx_exp ); + Scale_sig32( st->hFdCngEnc->msPeriodog_fx, NPART, sub( sub( 31, msPeriodog_fx_Q ), st->hFdCngEnc->msPeriodog_fx_exp ) ); + st->hFdCngEnc->msPeriodog_fx_exp = sub( 31, msPeriodog_fx_Q ); + + Word16 energy_ho_fx_Q = Q31; + zero_flag = get_zero_flag( st->hFdCngEnc->energy_ho_fx, NPART ); + IF( zero_flag ) + { + energy_ho_fx_Q = getScaleFactor32( st->hFdCngEnc->energy_ho_fx, NPART ); + } + + Scale_sig32( st->hFdCngEnc->energy_ho_fx, NPART, energy_ho_fx_Q ); + st->hFdCngEnc->energy_ho_fx_exp = st->hFdCngEnc->energy_ho_fx_exp - energy_ho_fx_Q; + + Word16 msNoiseEst_old_Q = Q31; + zero_flag = get_zero_flag( st->hFdCngEnc->msNoiseEst_old_fx, NPART ); + IF( zero_flag ) + { + energy_ho_fx_Q = getScaleFactor32( st->hFdCngEnc->msNoiseEst_old_fx, NPART ); + } + + Scale_sig32( st->hFdCngEnc->msNoiseEst_old_fx, NPART, energy_ho_fx_Q ); + st->hFdCngEnc->msNoiseEst_old_fx_exp = st->hFdCngEnc->msNoiseEst_old_fx_exp - msNoiseEst_old_Q; st->hFdCngEnc->msPeriodog_fx_exp_fft = st->hFdCngEnc->msPeriodog_fx_exp_cldfb = st->hFdCngEnc->msPeriodog_fx_exp; - st->hFdCngEnc->energy_ho_fx_exp = 31 - Q_factor_arrL( st->hFdCngEnc->energy_ho, NPART ); - st->hFdCngEnc->msNoiseEst_fx_exp = 31 - Q_factor_arrL( st->hFdCngEnc->msNoiseEst, NPART ); - st->hFdCngEnc->msNoiseEst_old_fx_exp = 31 - Q_factor_arrL( st->hFdCngEnc->msNoiseEst_old, NPART ); - floatToFixed_arrL( st->hFdCngEnc->msPeriodog, st->hFdCngEnc->msPeriodog_fx, 31 - st->hFdCngEnc->msPeriodog_fx_exp, NPART ); - floatToFixed_arrL( st->hFdCngEnc->energy_ho, st->hFdCngEnc->energy_ho_fx, 31 - st->hFdCngEnc->energy_ho_fx_exp, NPART ); - floatToFixed_arrL( st->hFdCngEnc->msNoiseEst, st->hFdCngEnc->msNoiseEst_fx, 31 - st->hFdCngEnc->msNoiseEst_fx_exp, NPART ); - floatToFixed_arrL( st->hFdCngEnc->msNoiseEst_old, st->hFdCngEnc->msNoiseEst_old_fx, 31 - st->hFdCngEnc->msNoiseEst_old_fx_exp, NPART ); -#endif AdjustFirstSID_fx( st->hFdCngEnc->hFdCngCom->npart, st->hFdCngEnc->msPeriodog_fx, st->hFdCngEnc->msPeriodog_fx_exp, st->hFdCngEnc->energy_ho_fx, &st->hFdCngEnc->energy_ho_fx_exp, st->hFdCngEnc->msNoiseEst_fx, &st->hFdCngEnc->msNoiseEst_fx_exp, st->hFdCngEnc->msNoiseEst_old_fx, &st->hFdCngEnc->msNoiseEst_old_fx_exp, &( st->hFdCngEnc->hFdCngCom->active_frame_counter ), st ); - -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - fixedToFloat_arrL( st->hFdCngEnc->msPeriodog_fx, st->hFdCngEnc->msPeriodog, 31 - st->hFdCngEnc->msPeriodog_fx_exp, NPART ); - fixedToFloat_arrL( st->hFdCngEnc->energy_ho_fx, st->hFdCngEnc->energy_ho, 31 - st->hFdCngEnc->energy_ho_fx_exp, NPART ); - fixedToFloat_arrL( st->hFdCngEnc->msNoiseEst_fx, st->hFdCngEnc->msNoiseEst, 31 - st->hFdCngEnc->msNoiseEst_fx_exp, NPART ); - fixedToFloat_arrL( st->hFdCngEnc->msNoiseEst_old_fx, st->hFdCngEnc->msNoiseEst_old, 31 - st->hFdCngEnc->msNoiseEst_old_fx_exp, NPART ); -#endif } /*----------------------------------------------------------------* diff --git a/lib_enc/ivas_cpe_enc.c b/lib_enc/ivas_cpe_enc.c index 4796a9a7b..b31530d9f 100644 --- a/lib_enc/ivas_cpe_enc.c +++ b/lib_enc/ivas_cpe_enc.c @@ -67,18 +67,19 @@ static void stereo_mode_combined_format_enc( const Encoder_Struct *st_ivas, CPE_ * Channel Pair Element (CPE) encoding routine *-------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED -ivas_error ivas_cpe_enc( - Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ - const Word16 cpe_id, /* i : CPE # identifier */ - float data_f_ch0[], /* i : input signal for channel 0 */ - float data_f_ch1[], /* i : input signal for channel 1 */ - const Word16 input_frame, /* i : input frame length per channel */ - const Word16 nb_bits_metadata /* i : number of metadata bits */ +ivas_error ivas_cpe_enc_fx( + Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ + const Word16 cpe_id, /* i : CPE # identifier */ + Word32 data_fx_ch0[], /* i : input signal for channel 0 Q(q_data_fx) */ + Word32 data_fx_ch1[], /* i : input signal for channel 1 Q(q_data_fx) */ + Word16 q_data_fx, /* i : Q-factor of input signal for both channels */ + const Word16 input_frame, /* i : input frame length per channel */ + const Word16 nb_bits_metadata /* i : number of metadata bits */ ) { CPE_ENC_HANDLE hCPE; Encoder_State **sts; - int16_t n, n_CoreChannels; + Word16 n, n_CoreChannels; #ifdef IVAS_FLOAT_FIXED_CONVERSIONS // required for float to fix conversion float old_inp_12k8[CPE_CHANNELS][L_INP_12k8] = { 0 }; /* buffer of input signal @ 12k8 */ float old_inp_16k[CPE_CHANNELS][L_INP] = { 0 }; /* buffer of input signal @ 16kHz */ @@ -105,8 +106,8 @@ ivas_error ivas_cpe_enc( float epsP[CPE_CHANNELS][M + 1]; /* LP prediction errors */ float lsp_new[CPE_CHANNELS][M]; /* LSPs at the end of the frame */ float lsp_mid[CPE_CHANNELS][M]; /* ISPs in the middle of the frame */ - int16_t vad_hover_flag[CPE_CHANNELS]; /* VAD hangover flag */ - int16_t attack_flag[CPE_CHANNELS]; /* attack flag (GSC or TC) */ + Word16 vad_hover_flag[CPE_CHANNELS]; /* VAD hangover flag */ + Word16 attack_flag[CPE_CHANNELS]; /* attack flag (GSC or TC) */ float realBuffer[CPE_CHANNELS][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; /* real buffer */ float imagBuffer[CPE_CHANNELS][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; /* imag buffer */ float old_wsp[CPE_CHANNELS][L_WSP]; /* old weighted input signal */ @@ -114,39 +115,38 @@ ivas_error ivas_cpe_enc( float voicing_fr[CPE_CHANNELS][NB_SUBFR]; /* fractional pitch gains */ Word16 pitch_fr_fx[CPE_CHANNELS][NB_SUBFR]; /* Q6, fractional pitch values */ Word16 voicing_fr_fx[CPE_CHANNELS][NB_SUBFR]; /* Q15, fractional pitch gains */ - int16_t loc_harm[CPE_CHANNELS]; /* harmonicity flag */ + Word16 loc_harm[CPE_CHANNELS]; /* harmonicity flag */ float cor_map_sum[CPE_CHANNELS]; /* speech/music clasif. parameter */ - int16_t vad_flag_dtx[CPE_CHANNELS]; /* HE-SAD flag with additional DTX HO */ + Word16 vad_flag_dtx[CPE_CHANNELS]; /* HE-SAD flag with additional DTX HO */ float enerBuffer[CPE_CHANNELS][CLDFB_NO_CHANNELS_MAX]; /* energy buffer */ float currFlatness[CPE_CHANNELS] = { 0 }; /* flatness parameter */ #ifdef IVAS_FLOAT_FIXED Word16 currFlatness_fx[CPE_CHANNELS]; /* flatness parameter Q7 */ #endif float fft_buff[CPE_CHANNELS][2 * L_FFT]; /* FFT buffer */ - int16_t tdm_ratio_idx, tdm_ratio_idx_SM; /* temp. TD stereo parameters */ - int16_t tdm_SM_or_LRTD_Pri; /* temp. TD stereo parameters */ -#ifndef IVAS_FLOAT_FIXED - float tdm_last_ratio; /* temp. TD stereo parameters */ -#endif - int16_t nb_bits; /* number of DFT stereo side bits */ + Word16 tdm_ratio_idx, tdm_ratio_idx_SM; /* temp. TD stereo parameters */ + Word16 tdm_SM_or_LRTD_Pri; /* temp. TD stereo parameters */ + + Word16 nb_bits; /* number of DFT stereo side bits */ float fr_bands[CPE_CHANNELS][2 * NB_BANDS]; /* energy in frequency bands */ float Etot_LR[CPE_CHANNELS]; /* total energy */ float lf_E[CPE_CHANNELS][2 * VOIC_BINS]; /* per bin spectrum energy in lf */ - int16_t localVAD_HE_SAD[CPE_CHANNELS]; /* HE-SAD flag without hangover, LR channels */ + Word16 localVAD_HE_SAD[CPE_CHANNELS]; /* HE-SAD flag without hangover, LR channels */ float band_energies_LR[2 * NB_BANDS]; /* energy in critical bands without minimum noise floor E_MIN */ float orig_input[CPE_CHANNELS][L_FRAME48k]; float Etot_last[CPE_CHANNELS]; Word16 Etot_last_fx[CPE_CHANNELS]; - int32_t tmp, input_Fs; - int16_t max_bwidth, ivas_format; + Word32 tmp, input_Fs; + Word16 max_bwidth, ivas_format; ENCODER_CONFIG_HANDLE hEncoderConfig; - int32_t ivas_total_brate; + Word32 ivas_total_brate; ivas_error error; - int32_t cpe_brate; - int32_t element_brate_ref; - int16_t last_bits_frame_nominal; /* last_bits_frame_nominal for M or PCh channel */ + Word32 cpe_brate; + Word32 element_brate_ref; + Word16 last_bits_frame_nominal; /* last_bits_frame_nominal for M or PCh channel */ error = IVAS_ERR_OK; + move32(); push_wmops( "ivas_cpe_enc" ); hCPE = st_ivas->hCPE[cpe_id]; @@ -158,6 +158,12 @@ ivas_error ivas_cpe_enc( ivas_total_brate = hEncoderConfig->ivas_total_brate; element_brate_ref = hCPE->element_brate; last_bits_frame_nominal = sts[0]->bits_frame_nominal; + move16(); + move16(); + move16(); + move32(); + move32(); + move32(); /*------------------------------------------------------------------* * Initialization - general @@ -167,6 +173,9 @@ ivas_error ivas_cpe_enc( tdm_ratio_idx = -1; tdm_ratio_idx_SM = -1; // tdm_last_ratio = 0; + move16(); + move16(); + move16(); set16_fx( pitch_fr_fx[0], 0, NB_SUBFR ); set16_fx( pitch_fr_fx[1], 0, NB_SUBFR ); @@ -183,13 +192,13 @@ ivas_error ivas_cpe_enc( * CPE initialization - core coder *-----------------------------------------------------------------*/ - for ( n = 0; n < CPE_CHANNELS; n++ ) + FOR( n = 0; n < CPE_CHANNELS; n++ ) { sts[n]->idchan = n; sts[n]->core = -1; sts[n]->core_brate = -1; /* updated in dtx() */ sts[n]->max_bwidth = max_bwidth; - if ( st_ivas->hMCT == NULL ) /*already updated before CPE call*/ + IF( st_ivas->hMCT == NULL ) /*already updated before CPE call*/ { sts[n]->input_bwidth = sts[n]->last_input_bwidth; /* updated in BWD */ sts[n]->bwidth = sts[n]->last_bwidth; /* updated in BWD */ @@ -197,15 +206,19 @@ ivas_error ivas_cpe_enc( sts[n]->rate_switching_reset = 0; } - mvr2r( data_f_ch0, sts[0]->input, input_frame ); -#ifdef IVAS_FLOAT_FIXED - floatToFixed_arr16( data_f_ch0, sts[0]->input_fx, 0, input_frame ); + Copy32( data_fx_ch0, sts[0]->input32_fx, input_frame ); // Q(q_data_fx) + Copy_Scale_sig32_16( sts[0]->input32_fx, sts[0]->input_fx, input_frame, sub( Q16, q_data_fx ) ); // Q(q_data_fx) -> Q0 + +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + fixedToFloat_arrL( sts[0]->input32_fx, sts[0]->input, q_data_fx, input_frame ); #endif - if ( data_f_ch1 != NULL ) /*this may happen for cases with odd number of channels*/ + IF( data_fx_ch1 != NULL ) /*this may happen for cases with odd number of channels*/ { - mvr2r( data_f_ch1, sts[1]->input, input_frame ); -#ifdef IVAS_FLOAT_FIXED - floatToFixed_arr16( data_f_ch1, sts[1]->input_fx, 0, input_frame ); + Copy32( data_fx_ch1, sts[1]->input32_fx, input_frame ); // Q(q_data_fx) + Copy_Scale_sig32_16( sts[1]->input32_fx, sts[1]->input_fx, input_frame, sub( Q16, q_data_fx ) ); // Q(q_data_fx) -> Q0 + +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + fixedToFloat_arrL( sts[1]->input32_fx, sts[1]->input, q_data_fx, input_frame ); #endif } @@ -213,20 +226,14 @@ ivas_error ivas_cpe_enc( * Stereo technology selection * Front-VAD on input L and R channels *----------------------------------------------------------------*/ - - if ( sts[0]->ini_frame > 0 && st_ivas->hMCT == NULL ) + test(); + IF( sts[0]->ini_frame > 0 && st_ivas->hMCT == NULL ) { -#ifdef IVAS_FLOAT_FIXED - hCPE->element_mode = select_stereo_mode( hCPE, ivas_format ); -#else hCPE->element_mode = select_stereo_mode( hCPE, ivas_format ); -#endif } -#ifdef IVAS_FLOAT_FIXED + stereo_mode_combined_format_enc_fx( st_ivas, hCPE ); -#else - stereo_mode_combined_format_enc( st_ivas, hCPE ); -#endif + #ifdef IVAS_FLOAT_FIXED Word16 Q_inp = 0; move16(); @@ -271,7 +278,7 @@ ivas_error ivas_cpe_enc( } #endif - if ( ( error = front_vad_fx( hCPE, NULL, hEncoderConfig, &hCPE->hFrontVad[0], st_ivas->hMCT != NULL, input_frame, vad_flag_dtx, fr_bands_fx, Etot_LR_fx, lf_E_fx, localVAD_HE_SAD, vad_hover_flag, band_energies_LR_fx, NULL, NULL, Q_inp, Q_buffer, Q_add, &front_create_flag ) ) != IVAS_ERR_OK ) + IF( ( error = front_vad_fx( hCPE, NULL, hEncoderConfig, &hCPE->hFrontVad[0], st_ivas->hMCT != NULL, input_frame, vad_flag_dtx, fr_bands_fx, Etot_LR_fx, lf_E_fx, localVAD_HE_SAD, vad_hover_flag, band_energies_LR_fx, NULL, NULL, Q_inp, Q_buffer, Q_add, &front_create_flag ) ) != IVAS_ERR_OK ) { return error; } @@ -450,17 +457,17 @@ ivas_error ivas_cpe_enc( * Time Domain Transient Detector *---------------------------------------------------------------*/ - for ( n = 0; n < CPE_CHANNELS; n++ ) + FOR( n = 0; n < CPE_CHANNELS; n++ ) { - if ( sts[n]->hTranDet == NULL ) + IF( sts[n]->hTranDet == NULL ) { currFlatness[n] = 0; - continue; + CONTINUE; } - if ( !( ivas_format == MC_FORMAT && st_ivas->mc_mode == MC_MODE_PARAMMC ) ) + test(); + IF( !( EQ_32( ivas_format, MC_FORMAT ) && EQ_32( st_ivas->mc_mode, MC_MODE_PARAMMC ) ) ) { -#ifdef IVAS_FLOAT_FIXED #ifdef IVAS_FLOAT_FIXED_CONVERSIONS floatToFixed_arr16( sts[n]->input, sts[n]->input_fx, -1, input_frame ); #endif @@ -469,23 +476,18 @@ ivas_error ivas_cpe_enc( sts[n]->hTranDet->subblockEnergies.accSubblockNrg_e = 31 - Q7; move16(); move16(); -#else - RunTransientDetection( sts[n]->input, input_frame, sts[n]->hTranDet ); -#endif } -#ifndef IVAS_FLOAT_FIXED - currFlatness[n] = GetTCXAvgTemporalFlatnessMeasure( sts[n]->hTranDet, NSUBBLOCKS, 0 ); -#else + currFlatness_fx[n] = GetTCXAvgTemporalFlatnessMeasure_ivas_fx( sts[n]->hTranDet, NSUBBLOCKS, 0 ); move16(); #ifdef IVAS_FLOAT_FIXED_CONVERSIONS currFlatness[n] = fix16_to_float( currFlatness_fx[n], Q7 ); -#endif #endif } /* Synchonize detection for downmix-based stereo */ - if ( hCPE->element_mode == IVAS_CPE_DFT || hCPE->element_mode == IVAS_CPE_TD ) + test(); + IF( EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) || EQ_16( hCPE->element_mode, IVAS_CPE_TD ) ) { #ifdef IVAS_FLOAT_FIXED #ifdef IVAS_FLOAT_FIXED_CONVERSIONS @@ -502,37 +504,16 @@ ivas_error ivas_cpe_enc( * Configuration of stereo encoder *----------------------------------------------------------------*/ - for ( n = 0; n < n_CoreChannels; n++ ) + FOR( n = 0; n < n_CoreChannels; n++ ) { /* Force to MODE1 in IVAS */ sts[n]->codec_mode = MODE1; + move16(); sts[n]->element_mode = hCPE->element_mode; + move16(); } - -#ifndef IVAS_FLOAT_FIXED - if ( hCPE->element_mode != IVAS_CPE_MDCT && ( hCPE->element_brate != hCPE->last_element_brate || hCPE->last_element_mode != hCPE->element_mode || sts[0]->ini_frame == 0 || - ( ivas_total_brate != st_ivas->hEncoderConfig->last_ivas_total_brate ) || sts[0]->last_core_brate <= SID_2k40 ) ) /* If the last frame was SID or NO_DATA, we need to run stereo_dft_config here since VAD decision is not known yet */ - { - if ( st_ivas->hQMetaData != NULL ) - { - if ( ivas_format == MASA_ISM_FORMAT && st_ivas->ism_mode != ISM_MODE_NONE ) - { - stereo_dft_config( hCPE->hStereoDft == NULL ? NULL : hCPE->hStereoDft->hConfig, (int32_t) ( 0.70f * st_ivas->hQMetaData->bits_frame_nominal * FRAMES_PER_SEC ), &sts[0]->bits_frame_nominal, &sts[1]->bits_frame_nominal ); - } - else - { - stereo_dft_config( hCPE->hStereoDft == NULL ? NULL : hCPE->hStereoDft->hConfig, st_ivas->hQMetaData->bits_frame_nominal * FRAMES_PER_SEC, &sts[0]->bits_frame_nominal, &sts[1]->bits_frame_nominal ); - } - } - else - { - /* note; "bits_frame_nominal" needed in TD stereo as well */ - stereo_dft_config( hCPE->hStereoDft == NULL ? NULL : hCPE->hStereoDft->hConfig, hCPE->element_brate, &sts[0]->bits_frame_nominal, &sts[1]->bits_frame_nominal ); - } - } -#else test(); test(); test(); @@ -561,22 +542,17 @@ ivas_error ivas_cpe_enc( stereo_dft_config_fx( hCPE->hStereoDft == NULL ? NULL : hCPE->hStereoDft->hConfig, hCPE->element_brate, &sts[0]->bits_frame_nominal, &sts[1]->bits_frame_nominal ); } } -#endif - if ( hCPE->element_mode == IVAS_CPE_TD ) + IF( EQ_16( hCPE->element_mode, IVAS_CPE_TD ) ) { - if ( hCPE->hStereoTD->tdm_LRTD_flag ) + IF( hCPE->hStereoTD->tdm_LRTD_flag ) { sts[0]->bits_frame_nominal = (int16_t) ( ( hCPE->element_brate >> 1 ) / FRAMES_PER_SEC ); sts[1]->bits_frame_nominal = (int16_t) ( ( hCPE->element_brate >> 1 ) / FRAMES_PER_SEC ); } - else + ELSE { -#ifndef IVAS_FLOAT_FIXED - stereo_dft_config( NULL, hCPE->element_brate, &sts[0]->bits_frame_nominal, &sts[1]->bits_frame_nominal ); -#else stereo_dft_config_fx( NULL, hCPE->element_brate, &sts[0]->bits_frame_nominal, &sts[1]->bits_frame_nominal ); -#endif } } @@ -972,7 +948,7 @@ ivas_error ivas_cpe_enc( { if ( hCPE->element_mode == IVAS_CPE_DFT || hCPE->element_mode == IVAS_CPE_TD ) { - reset_metadata_spatial( ivas_format, hCPE->hMetaData, hCPE->element_brate, &tmp, sts[0]->core_brate, nb_bits_metadata ); + reset_metadata_spatial_fx( ivas_format, hCPE->hMetaData, hCPE->element_brate, &tmp, sts[0]->core_brate, nb_bits_metadata ); } } @@ -1007,9 +983,10 @@ ivas_error ivas_cpe_enc( #endif /* Reset metadata */ - if ( sts[0]->cng_sba_flag || ( ivas_format == SBA_FORMAT ) ) + test(); + IF( sts[0]->cng_sba_flag || EQ_32( ivas_format, SBA_FORMAT ) ) { - reset_metadata_spatial( ivas_format, hCPE->hMetaData, hCPE->element_brate, &tmp, sts[0]->core_brate, nb_bits_metadata ); + reset_metadata_spatial_fx( ivas_format, hCPE->hMetaData, hCPE->element_brate, &tmp, sts[0]->core_brate, nb_bits_metadata ); } } @@ -2469,6 +2446,7 @@ ivas_error create_cpe_enc_fx( ivas_error error; error = IVAS_ERR_OK; + move32(); hEncoderConfig = st_ivas->hEncoderConfig; @@ -2476,6 +2454,10 @@ ivas_error create_cpe_enc_fx( element_mode_init = hEncoderConfig->element_mode_init; input_Fs = hEncoderConfig->input_Fs; max_bwidth = hEncoderConfig->max_bwidth; + move16(); + move16(); + move32(); + move16(); /*-----------------------------------------------------------------* * Allocate CPE handle @@ -2495,6 +2477,11 @@ ivas_error create_cpe_enc_fx( hCPE->last_element_brate = hCPE->element_brate; hCPE->element_mode = element_mode_init; hCPE->last_element_mode = element_mode_init; + move16(); + move32(); + move32(); + move16(); + move16(); hCPE->hStereoDft = NULL; hCPE->hStereoTD = NULL; @@ -2508,6 +2495,7 @@ ivas_error create_cpe_enc_fx( hCPE->hFrontVad[1] = NULL; hCPE->brate_surplus = 0; + move32(); /*-----------------------------------------------------------------* * Input memory buffer: allocate and initialize @@ -2515,6 +2503,10 @@ ivas_error create_cpe_enc_fx( FOR( n = 0; n < CPE_CHANNELS; n++ ) { + test(); + test(); + test(); + test(); IF( EQ_16( ivas_format, STEREO_FORMAT ) || EQ_16( ivas_format, MASA_FORMAT ) || ( EQ_16( ivas_format, MC_FORMAT ) && EQ_16( st_ivas->mc_mode, MC_MODE_MCMASA ) ) || EQ_16( ivas_format, MASA_ISM_FORMAT ) ) { IF( ( hCPE->input_mem_fx[n] = (Word16 *) malloc( sizeof( Word16 ) * NS2SA( input_Fs, STEREO_DFT_OVL_NS ) ) ) == NULL ) @@ -2531,7 +2523,7 @@ ivas_error create_cpe_enc_fx( } -#if 1 // TODO: To be removed later +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS // TODO: To be removed later for ( n = 0; n < CPE_CHANNELS; n++ ) { if ( ivas_format == STEREO_FORMAT || ivas_format == MASA_FORMAT || ( ivas_format == MC_FORMAT && st_ivas->mc_mode == MC_MODE_MCMASA ) || ivas_format == MASA_ISM_FORMAT ) @@ -2559,11 +2551,7 @@ ivas_error create_cpe_enc_fx( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for stereo classifier structure\n" ) ); } -#ifndef IVAS_FLOAT_FIXED - stereo_classifier_init( hCPE->hStereoClassif ); -#else stereo_classifier_init_fx( hCPE->hStereoClassif ); -#endif /*-----------------------------------------------------------------* * Metadata: allocate and initialize @@ -2598,7 +2586,9 @@ ivas_error create_cpe_enc_fx( { st->total_brate = L_shr( hCPE->element_brate, CPE_CHANNELS ); /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() */ } + move32(); st->mct_chan_mode = MCT_CHAN_MODE_REGULAR; + move32(); IF( ( error = init_encoder_ivas_fx( st, st_ivas, n, hEncoderConfig->var_SID_rate_flag, hEncoderConfig->interval_SID, 0, ISM_MODE_NONE, hCPE->element_brate ) ) != IVAS_ERR_OK ) { @@ -2608,6 +2598,7 @@ ivas_error create_cpe_enc_fx( IF( st->hFdCngEnc != NULL ) { st->hFdCngEnc->hFdCngCom->CngBitrate = L_sub( hCPE->element_brate, 1 ); + move32(); } hCPE->hCoreCoder[n] = st; @@ -2619,6 +2610,7 @@ ivas_error create_cpe_enc_fx( IF( hEncoderConfig->Opt_DTX_ON ) { + test(); IF( EQ_16( hCPE->element_mode, IVAS_CPE_TD ) || EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) ) { IF( ( hCPE->hStereoCng = (STEREO_CNG_ENC_HANDLE) malloc( sizeof( STEREO_CNG_ENC ) ) ) == NULL ) @@ -2634,6 +2626,7 @@ ivas_error create_cpe_enc_fx( hCPE->hStereoCng = NULL; } + test(); IF( hEncoderConfig->Opt_DTX_ON && EQ_16( element_mode_init, IVAS_CPE_MDCT ) ) { FOR( n = 0; n < CPE_CHANNELS; n++ ) @@ -2696,7 +2689,7 @@ ivas_error create_cpe_enc_fx( * TD stereo initialization *-----------------------------------------------------------------*/ - IF( hCPE->element_mode == IVAS_CPE_TD ) + IF( EQ_16( hCPE->element_mode, IVAS_CPE_TD ) ) { IF( ( hCPE->hStereoTD = (STEREO_TD_ENC_DATA_HANDLE) malloc( sizeof( STEREO_TD_ENC_DATA ) ) ) == NULL ) { @@ -2709,7 +2702,7 @@ ivas_error create_cpe_enc_fx( /*-----------------------------------------------------------------* * MDCT stereo initialization *-----------------------------------------------------------------*/ - + test(); IF( EQ_16( hCPE->element_mode, IVAS_CPE_MDCT ) && EQ_16( st_ivas->nCPE, 1 ) ) { IF( ( hCPE->hStereoMdct = (STEREO_MDCT_ENC_DATA_HANDLE) malloc( sizeof( STEREO_MDCT_ENC_DATA ) ) ) == NULL ) @@ -2718,8 +2711,13 @@ ivas_error create_cpe_enc_fx( } initMdctStereoEncData_fx( hCPE->hStereoMdct, ivas_format, hCPE->element_mode, hCPE->element_brate, max_bwidth, 0, NULL, 1 ); + test(); + test(); hCPE->hStereoMdct->isSBAStereoMode = ( ( EQ_16( ivas_format, SBA_FORMAT ) || EQ_16( ivas_format, SBA_ISM_FORMAT ) ) && EQ_16( st_ivas->nchan_transport, 2 ) ); + move16(); + test(); + test(); IF( EQ_16( hCPE->element_mode, IVAS_CPE_MDCT ) && LE_32( element_brate, MAX_MDCT_ITD_BRATE ) && EQ_16( ivas_format, STEREO_FORMAT ) ) { IF( ( error = initMdctItdHandling( hCPE->hStereoMdct, input_Fs ) ) != IVAS_ERR_OK ) diff --git a/lib_enc/ivas_enc.c b/lib_enc/ivas_enc.c index 17cc8661b..883fa1223 100644 --- a/lib_enc/ivas_enc.c +++ b/lib_enc/ivas_enc.c @@ -630,7 +630,7 @@ ivas_error ivas_enc( return error; } #else -ivas_error ivas_enc( +ivas_error ivas_enc_fx( Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ const Word16 *data, /* i : input signal Q0 */ const Word16 n_samples /* i : number of input samples */ @@ -642,9 +642,6 @@ ivas_error ivas_enc( ENCODER_CONFIG_HANDLE hEncoderConfig; BSTR_ENC_HANDLE hMetaData; Word16 nb_bits_metadata[MAX_SCE + 1]; -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - float *data_f[MAX_INPUT_CHANNELS + MAX_NUM_OBJECTS]; -#endif Word32 *data_fx[MAX_INPUT_CHANNELS + MAX_NUM_OBJECTS]; Word32 ivas_total_brate; ivas_error error; @@ -687,9 +684,6 @@ ivas_error ivas_enc( FOR( n = 0; n < MAX_INPUT_CHANNELS + MAX_NUM_OBJECTS; n++ ) { -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - data_f[n] = st_ivas->p_data_f[n]; // float initialization to be removed -#endif data_fx[n] = st_ivas->p_data_fx[n]; } @@ -701,22 +695,16 @@ ivas_error ivas_enc( { FOR( i = 0; i < n_samples_chan; i++ ) { -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - data_f[n][i] = (float) data[i * nchan_inp + n]; // float initialization to be removed -#endif data_fx[n][i] = L_mult0( data[i * nchan_inp + n], shl( 1, st_ivas->q_data_fx ) ); move32(); } - n = add( n, 1 ); + n++; } IF( LT_16( n_samples_chan, input_frame ) ) { FOR( n = 0; n < nchan_inp; n++ ) { -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - set_f( data_f[n] + n_samples_chan, 0.0f, input_frame - n_samples_chan ); // float initialization to be removed -#endif set32_fx( data_fx[n] + n_samples_chan, 0, sub( input_frame, n_samples_chan ) ); } } @@ -757,14 +745,6 @@ ivas_error ivas_enc( } } -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - for ( i = 0; i < n; i++ ) - { - fixedToFloat_arrL( data_fx[i], data_f[i], st_ivas->q_data_fx, input_frame ); - } -#endif // 1 - - /*----------------------------------------------------------------* * write IVAS format signaling *----------------------------------------------------------------*/ @@ -777,7 +757,8 @@ ivas_error ivas_enc( IF( EQ_32( ivas_format, STEREO_FORMAT ) ) { st_ivas->hCPE[0]->element_brate = ivas_total_brate; - if ( ( error = ivas_cpe_enc( st_ivas, 0, data_f[0], data_f[1], input_frame, 0 /* no metadata */ ) ) != IVAS_ERR_OK ) + move32(); + IF( ( error = ivas_cpe_enc_fx( st_ivas, 0, data_fx[0], data_fx[1], st_ivas->q_data_fx, input_frame, 0 /* no metadata */ ) ) != IVAS_ERR_OK ) { return error; } @@ -785,54 +766,41 @@ ivas_error ivas_enc( ELSE IF( EQ_32( ivas_format, ISM_FORMAT ) ) { /* select ISM format mode; reconfigure the ISM format encoder */ - if ( ( error = ivas_ism_enc_config( st_ivas ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_ism_enc_config( st_ivas ) ) != IVAS_ERR_OK ) { return error; } - if ( st_ivas->ism_mode == ISM_MODE_PARAM ) + IF( EQ_32( st_ivas->ism_mode, ISM_MODE_PARAM ) ) { -#ifdef IVAS_FLOAT_FIXED -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - for ( i = 0; i < st_ivas->hEncoderConfig->nchan_ism; i++ ) - { - floatToFixed_arr32( data_f[i], data_fx[i], Q14, input_frame ); - } - for ( i = 0; i < st_ivas->hEncoderConfig->nchan_ism; i++ ) + FOR( i = 0; i < st_ivas->hEncoderConfig->nchan_ism; i++ ) { + scale_sig32( data_fx[i], input_frame, sub( Q14, st_ivas->q_data_fx ) ); // Q11 -> Q14 scale_sig32( st_ivas->hParamIsm->hFbMixer->ppFilterbank_prior_input_fx[i], st_ivas->hParamIsm->hFbMixer->fb_cfg->prior_input_length, sub( Q14, st_ivas->hParamIsm->hFbMixer->q_ppFilterbank_prior_input_fx[i] ) ); st_ivas->hParamIsm->hFbMixer->q_ppFilterbank_prior_input_fx[i] = Q14; + move16(); } -#endif ivas_param_ism_enc_fx( st_ivas, data_fx, input_frame, Q14 ); /* Stereo DMX generation */ ivas_param_ism_stereo_dmx_fx( st_ivas, data_fx, input_frame ); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - for ( i = 0; i < st_ivas->hEncoderConfig->nchan_ism; i++ ) + FOR( i = 0; i < st_ivas->hEncoderConfig->nchan_ism; i++ ) { - fixedToFloat_arrL32( data_fx[i], data_f[i], Q14, input_frame ); + scale_sig32( data_fx[i], input_frame, sub( st_ivas->q_data_fx, Q14 ) ); // Q14 -> Q11 } -#endif -#else - ivas_param_ism_enc( st_ivas, data_f, input_frame ); - - /* Stereo DMX generation */ - ivas_param_ism_stereo_dmx( st_ivas, data_f, input_frame ); -#endif /* Core coding of Stereo DMX */ - if ( ( error = ivas_ism_enc( st_ivas, data_f, input_frame, nb_bits_metadata, 0 ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_ism_enc_fx( st_ivas, data_fx, st_ivas->q_data_fx, input_frame, nb_bits_metadata, 0 ) ) != IVAS_ERR_OK ) { return error; } } - else if ( st_ivas->ism_mode == ISM_MODE_DISC ) + ELSE IF( EQ_32( st_ivas->ism_mode, ISM_MODE_DISC ) ) { /* Analysis, decision about bitrates per channel & core coding */ - if ( ( error = ivas_ism_enc( st_ivas, data_f, input_frame, nb_bits_metadata, 0 ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_ism_enc_fx( st_ivas, data_fx, st_ivas->q_data_fx, input_frame, nb_bits_metadata, 0 ) ) != IVAS_ERR_OK ) { return error; } @@ -888,7 +856,7 @@ ivas_error ivas_enc( } ELSE IF( EQ_32( ivas_format, SBA_FORMAT ) ) { - IF( ( error = ivas_spar_enc( st_ivas, data_f, input_frame, nb_bits_metadata, hMetaData ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_spar_enc_fx( st_ivas, data_fx, input_frame, nb_bits_metadata, hMetaData ) ) != IVAS_ERR_OK ) { return error; } @@ -896,27 +864,27 @@ ivas_error ivas_enc( IF( EQ_32( ivas_format, SBA_FORMAT ) ) { - ivas_sba_getTCs( data_f, st_ivas, input_frame ); + ivas_sba_getTCs_fx( data_fx, st_ivas, input_frame ); } /* core-coding of transport channels */ IF( EQ_16( st_ivas->nSCE, 1 ) ) { - IF( ( error = ivas_sce_enc( st_ivas, 0, data_f[0], input_frame, nb_bits_metadata[0] ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_sce_enc_fx( st_ivas, 0, data_fx[0], st_ivas->q_data_fx, input_frame, nb_bits_metadata[0] ) ) != IVAS_ERR_OK ) { return error; } } ELSE IF( EQ_16( st_ivas->nCPE, 1 ) ) /* Stereo DMX */ { - IF( ( error = ivas_cpe_enc( st_ivas, 0, data_f[0], data_f[1], input_frame, nb_bits_metadata[0] ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_cpe_enc_fx( st_ivas, 0, data_fx[0], data_fx[1], st_ivas->q_data_fx, input_frame, nb_bits_metadata[0] ) ) != IVAS_ERR_OK ) { return error; } } ELSE IF( GT_16( st_ivas->nCPE, 1 ) ) /* FOA/HOA format */ { - IF( ( error = ivas_mct_enc( st_ivas, data_f, input_frame, nb_bits_metadata[0] ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_mct_enc_fx( st_ivas, data_fx, st_ivas->q_data_fx, input_frame, nb_bits_metadata[0] ) ) != IVAS_ERR_OK ) { return error; } @@ -924,8 +892,8 @@ ivas_error ivas_enc( } ELSE IF( EQ_32( ivas_format, MASA_ISM_FORMAT ) ) { - float *data_separated_object; Word32 *data_separated_object_fx; + Word16 q_data_separated_object; Word16 idx_separated_object; Word16 flag_omasa_ener_brate; @@ -939,13 +907,7 @@ ivas_error ivas_enc( v_multc_fixed( data_fx[hEncoderConfig->nchan_ism], L_deposit_h( INV_SQRT2_FX_Q15 ) /* Q31 */, data_fx[hEncoderConfig->nchan_ism], input_frame ); Copy32( data_fx[hEncoderConfig->nchan_ism], data_fx[hEncoderConfig->nchan_ism + 1], input_frame ); } -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - if ( ( st_ivas->hEncoderConfig->nchan_inp - hEncoderConfig->nchan_ism ) == 1 ) - { - v_multc( data_f[hEncoderConfig->nchan_ism], 1.0f / SQRT2, data_f[hEncoderConfig->nchan_ism], input_frame ); - mvr2r( data_f[hEncoderConfig->nchan_ism], data_f[hEncoderConfig->nchan_ism + 1], input_frame ); - } -#endif + /* Estimate TF-tile energy for the input MASA stream */ ivas_masa_estimate_energy_fx( st_ivas->hMasa, &( data_fx[hEncoderConfig->nchan_ism] ), input_frame, st_ivas->nchan_transport, st_ivas->q_data_fx ); @@ -958,8 +920,9 @@ ivas_error ivas_enc( idx_separated_object = 0; move16(); - data_separated_object = data_f[hEncoderConfig->nchan_ism + CPE_CHANNELS]; - data_separated_object_fx = data_fx[hEncoderConfig->nchan_ism + CPE_CHANNELS]; + data_separated_object_fx = data_fx[hEncoderConfig->nchan_ism + CPE_CHANNELS]; // Q(st_ivas->q_data_fx) + q_data_separated_object = st_ivas->q_data_fx; + move16(); /* put audio object data in SCE's */ IF( NE_32( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) ) @@ -982,13 +945,9 @@ ivas_error ivas_enc( /* Estimate MASA parameters for the objects */ ivas_omasa_enc_fx( st_ivas->hOMasa, st_ivas->hMasa, st_ivas->hIsmMetaData, data_fx, st_ivas->q_data_fx, input_frame, st_ivas->nchan_transport, hEncoderConfig->nchan_ism, st_ivas->ism_mode, data_separated_object_fx, &idx_separated_object ); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - for ( i = 0; i < hEncoderConfig->nchan_ism + st_ivas->nchan_transport; i++ ) - { - fixedToFloat_arrL( data_fx[i], data_f[i], st_ivas->q_data_fx, input_frame ); - } - fixedToFloat_arrL( data_separated_object_fx, data_separated_object, st_ivas->q_data_fx, input_frame ); -#endif // IVAS_FLOAT_FIXED_CONVERSIONS + + q_data_separated_object = st_ivas->q_data_fx; + move16(); } /* Encode ISMs transport channels */ @@ -996,14 +955,14 @@ ivas_error ivas_enc( move16(); IF( EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) ) { - IF( ( error = ivas_sce_enc( st_ivas, 0, data_separated_object, input_frame, nb_bits_metadata[1] ) ) != IVAS_ERR_OK ) /* there are no metadata bits in SCE in this mode */ + IF( ( error = ivas_sce_enc_fx( st_ivas, 0, data_separated_object_fx, q_data_separated_object, input_frame, nb_bits_metadata[1] ) ) != IVAS_ERR_OK ) /* there are no metadata bits in SCE in this mode */ { return error; } } ELSE IF( EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) ) { - IF( ( error = ivas_ism_enc( st_ivas, &data_separated_object, input_frame, &nb_bits_metadata[1], 0 ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_ism_enc_fx( st_ivas, &data_separated_object_fx, q_data_separated_object, input_frame, &nb_bits_metadata[1], 0 ) ) != IVAS_ERR_OK ) { return error; } @@ -1013,7 +972,7 @@ ivas_error ivas_enc( flag_omasa_ener_brate = ivas_omasa_ener_brate_fx( st_ivas->hEncoderConfig->nchan_ism, ivas_total_brate, data_fx, input_frame, sub( 31, st_ivas->q_data_fx ) ); /* Analysis, decision about bitrates per channel & core coding */ - IF( ( error = ivas_ism_enc( st_ivas, data_f, input_frame, &nb_bits_metadata[1], flag_omasa_ener_brate ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_ism_enc_fx( st_ivas, data_fx, st_ivas->q_data_fx, input_frame, &nb_bits_metadata[1], flag_omasa_ener_brate ) ) != IVAS_ERR_OK ) { return error; } @@ -1046,93 +1005,98 @@ ivas_error ivas_enc( ); /* Encode MASA transport channels */ - IF( ( ivas_cpe_enc( st_ivas, 0, data_f[n], data_f[n + 1], input_frame, nb_bits_metadata[0] ) ) != IVAS_ERR_OK ) + IF( ( ivas_cpe_enc_fx( st_ivas, 0, data_fx[n], data_fx[n + 1], st_ivas->q_data_fx, input_frame, nb_bits_metadata[0] ) ) != IVAS_ERR_OK ) { return error; } } ELSE IF( EQ_32( ivas_format, SBA_ISM_FORMAT ) ) { - Word16 planar_sba_orig; + Word16 planar_sba_orig, nchan; planar_sba_orig = hEncoderConfig->sba_planar; -#ifdef IVAS_FLOAT_FIXED + move16(); + /* Analyze objects and determine needed audio signals */ ivas_osba_enc_fx( st_ivas->hOSba, st_ivas->hIsmMetaData, data_fx, input_frame, hEncoderConfig->nchan_ism, st_ivas->ism_mode, st_ivas->sba_analysis_order, hEncoderConfig->input_Fs, hEncoderConfig->sba_planar, &st_ivas->q_data_fx ); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - Word16 nchan; - if ( st_ivas->ism_mode == ISM_MODE_NONE ) - nchan = ( st_ivas->sba_analysis_order + 1 ) * ( st_ivas->sba_analysis_order + 1 ); - else + + IF( st_ivas->ism_mode == ISM_MODE_NONE ) + { + nchan = imult1616( add( st_ivas->sba_analysis_order, 1 ), add( st_ivas->sba_analysis_order, 1 ) ); + } + ELSE + { nchan = hEncoderConfig->nchan_ism; - for ( n = 0; n < nchan; n++ ) + move16(); + } + FOR( n = 0; n < nchan; n++ ) { - fixedToFloat_arrL32( data_fx[n], data_f[n], st_ivas->q_data_fx, input_frame ); + scale_sig32( data_fx[n], input_frame, sub( Q11, st_ivas->q_data_fx ) ); // Q(st_ivas->q_data_fx) -> Q11 } -#endif -#else - /* Analyze objects and determine needed audio signals */ - ivas_osba_enc( st_ivas->hOSba, st_ivas->hIsmMetaData, data_f, input_frame, hEncoderConfig->nchan_ism, st_ivas->ism_mode, st_ivas->sba_analysis_order, hEncoderConfig->input_Fs, hEncoderConfig->sba_planar ); + st_ivas->q_data_fx = Q11; + move16(); -#endif - if ( st_ivas->ism_mode == ISM_MODE_NONE ) + IF( st_ivas->ism_mode == ISM_MODE_NONE ) { /*once SBA and ISM are combined into SBA signal then disable planar flag*/ hEncoderConfig->sba_planar = 0; - if ( st_ivas->nchan_transport == 1 ) + move16(); + IF( EQ_16( st_ivas->nchan_transport, 1 ) ) { hMetaData = st_ivas->hSCE[st_ivas->nSCE - 1]->hMetaData; } - else + ELSE { hMetaData = st_ivas->hCPE[st_ivas->nCPE - 1]->hMetaData; } /* SBA metadata encoding and SBA metadata bitstream writing */ - if ( ( error = ivas_spar_enc( st_ivas, data_f, input_frame, nb_bits_metadata, hMetaData ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_spar_enc_fx( st_ivas, data_fx, input_frame, nb_bits_metadata, hMetaData ) ) != IVAS_ERR_OK ) { return error; } hEncoderConfig->sba_planar = planar_sba_orig; + move16(); } - else + ELSE { n = hEncoderConfig->nchan_ism; + move16(); hMetaData = st_ivas->hCPE[st_ivas->nCPE - 1]->hMetaData; - if ( ( error = ivas_ism_metadata_enc( &st_ivas->hEncoderConfig->ivas_total_brate, n, st_ivas->hEncoderConfig->nchan_ism, st_ivas->hIsmMetaData, NULL, hMetaData, &nb_bits_metadata[1], 0, st_ivas->ism_mode, NULL, st_ivas->hEncoderConfig->ism_extended_metadata_flag, -256 /* -1.0f in Q8 */, 0, NULL, st_ivas->hCPE[0]->hCoreCoder[0]->ini_frame ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_ism_metadata_enc( &st_ivas->hEncoderConfig->ivas_total_brate, n, st_ivas->hEncoderConfig->nchan_ism, st_ivas->hIsmMetaData, NULL, hMetaData, &nb_bits_metadata[1], 0, st_ivas->ism_mode, NULL, st_ivas->hEncoderConfig->ism_extended_metadata_flag, -256 /* -1.0f in Q8 */, 0, NULL, st_ivas->hCPE[0]->hCoreCoder[0]->ini_frame ) ) != IVAS_ERR_OK ) { return error; } /* SBA metadata encoding and SBA metadata bitstream writing */ - if ( ( error = ivas_spar_enc( st_ivas, &data_f[n], input_frame, nb_bits_metadata, hMetaData ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_spar_enc_fx( st_ivas, &data_fx[n], input_frame, nb_bits_metadata, hMetaData ) ) != IVAS_ERR_OK ) { return error; } /* get SBA TCs */ - ivas_sba_getTCs( &data_f[n], st_ivas, input_frame ); + ivas_sba_getTCs_fx( &data_fx[n], st_ivas, input_frame ); } /* core-coding of transport channels */ - if ( st_ivas->nSCE == 1 ) + IF( EQ_16( st_ivas->nSCE, 1 ) ) { - if ( ( error = ivas_sce_enc( st_ivas, 0, data_f[0], input_frame, nb_bits_metadata[0] ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_sce_enc_fx( st_ivas, 0, data_fx[0], st_ivas->q_data_fx, input_frame, nb_bits_metadata[0] ) ) != IVAS_ERR_OK ) { return error; } } - else if ( st_ivas->nCPE == 1 ) /* Stereo DMX */ + ELSE IF( EQ_16( st_ivas->nCPE, 1 ) ) /* Stereo DMX */ { - if ( ( error = ivas_cpe_enc( st_ivas, 0, data_f[0], data_f[1], input_frame, nb_bits_metadata[0] ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_cpe_enc_fx( st_ivas, 0, data_fx[0], data_fx[1], st_ivas->q_data_fx, input_frame, nb_bits_metadata[0] ) ) != IVAS_ERR_OK ) { return error; } } - else if ( st_ivas->nCPE > 1 ) /* FOA/HOA format */ + ELSE IF( GT_16( st_ivas->nCPE, 1 ) ) /* FOA/HOA format */ { - if ( ( error = ivas_mct_enc( st_ivas, data_f, input_frame, nb_bits_metadata[0] ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_mct_enc_fx( st_ivas, data_fx, st_ivas->q_data_fx, input_frame, nb_bits_metadata[0] ) ) != IVAS_ERR_OK ) { return error; } @@ -1146,14 +1110,14 @@ ivas_error ivas_enc( return error; } - // hMetaData = ( st_ivas->nSCE > 0 ) ? st_ivas->hSCE[st_ivas->nSCE - 1]->hMetaData : st_ivas->hCPE[st_ivas->nCPE - 1]->hMetaData; + /* hMetaData = ( st_ivas->nSCE > 0 ) ? st_ivas->hSCE[st_ivas->nSCE - 1]->hMetaData : st_ivas->hCPE[st_ivas->nCPE - 1]->hMetaData; */ IF( st_ivas->nSCE > 0 ) { - hMetaData = st_ivas->hSCE[sub( st_ivas->nSCE, 1 )]->hMetaData; + hMetaData = st_ivas->hSCE[st_ivas->nSCE - 1]->hMetaData; } ELSE { - hMetaData = st_ivas->hCPE[sub( st_ivas->nCPE, 1 )]->hMetaData; + hMetaData = st_ivas->hCPE[st_ivas->nCPE - 1]->hMetaData; } /* LFE low pass filter */ @@ -1173,13 +1137,10 @@ ivas_error ivas_enc( ivas_lfe_enc_fx( st_ivas->hLFE, data_fx[LFE_CHANNEL], st_ivas->q_data_fx, input_frame, st_ivas->hLFE->hBstr ); } -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS // To be removed - fixedToFloat_arrL( data_fx[LFE_CHANNEL], data_f[LFE_CHANNEL], st_ivas->q_data_fx, input_frame ); -#endif IF( EQ_32( st_ivas->mc_mode, MC_MODE_MCT ) ) { - if ( ( error = ivas_mct_enc( st_ivas, data_f, input_frame, 0 ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_mct_enc_fx( st_ivas, data_fx, st_ivas->q_data_fx, input_frame, 0 ) ) != IVAS_ERR_OK ) { return error; } @@ -1187,38 +1148,21 @@ ivas_error ivas_enc( ELSE IF( EQ_32( st_ivas->mc_mode, MC_MODE_PARAMUPMIX ) ) { /* encode MC ParamUpmix parameters and write bitstream */ -#ifdef IVAS_FLOAT_FIXED -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - for ( i = 4; i < 12; i++ ) - { - for ( int l = 0; l < input_frame; l++ ) - { - data_fx[i][l] = floatToFixed( data_f[i][l], st_ivas->q_data_fx ); - } - } -#endif ivas_mc_paramupmix_enc_fx( st_ivas, hMetaData, data_fx, input_frame ); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - for ( i = 4; i < 12; i++ ) + /* st_ivas->hLFE->hBstr = ( st_ivas->nSCE > 0 ) ? st_ivas->hSCE[0]->hCoreCoder[0]->hBstr : st_ivas->hCPE[0]->hCoreCoder[0]->hBstr; */ + IF( st_ivas->nSCE > 0 ) { - for ( int l = 0; l < input_frame; l++ ) - { - data_f[i][l] = fixedToFloat( data_fx[i][l], st_ivas->q_data_fx ); - } + st_ivas->hLFE->hBstr = st_ivas->hSCE[0]->hCoreCoder[0]->hBstr; + } + ELSE + { + st_ivas->hLFE->hBstr = st_ivas->hCPE[0]->hCoreCoder[0]->hBstr; } -#endif -#else - ivas_mc_paramupmix_enc( st_ivas, hMetaData, data_f, input_frame ); - -#endif - st_ivas->hLFE->hBstr = ( st_ivas->nSCE > 0 ) ? st_ivas->hSCE[0]->hCoreCoder[0]->hBstr : st_ivas->hCPE[0]->hCoreCoder[0]->hBstr; ivas_lfe_enc_fx( st_ivas->hLFE, data_fx[LFE_CHANNEL], st_ivas->q_data_fx, input_frame, st_ivas->hLFE->hBstr ); -#if 1 // To be removed - fixedToFloat_arrL( data_fx[LFE_CHANNEL], data_f[LFE_CHANNEL], st_ivas->q_data_fx, input_frame ); -#endif - if ( ( error = ivas_mct_enc( st_ivas, data_f, input_frame, hMetaData->nb_bits_tot ) ) != IVAS_ERR_OK ) + + IF( ( error = ivas_mct_enc_fx( st_ivas, data_fx, st_ivas->q_data_fx, input_frame, hMetaData->nb_bits_tot ) ) != IVAS_ERR_OK ) { return error; } @@ -1226,40 +1170,18 @@ ivas_error ivas_enc( ELSE IF( EQ_32( st_ivas->mc_mode, MC_MODE_PARAMMC ) ) { /* encode Parametric MC parameters and write bitstream */ -#ifdef IVAS_FLOAT_FIXED -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - for ( i = 0; i < st_ivas->hEncoderConfig->nchan_inp; i++ ) - { - for ( int l = 0; l < input_frame; l++ ) - { - data_fx[i][l] = floatToFixed( data_f[i][l], st_ivas->q_data_fx ); - } - } -#endif ivas_param_mc_enc_fx( st_ivas, hMetaData, data_fx, input_frame ); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - for ( i = 0; i < st_ivas->hEncoderConfig->nchan_inp; i++ ) - { - for ( int l = 0; l < input_frame; l++ ) - { - data_f[i][l] = fixedToFloat( data_fx[i][l], st_ivas->q_data_fx ); - } - } -#endif -#else - ivas_param_mc_enc( st_ivas, hMetaData, data_f, input_frame ); -#endif - if ( st_ivas->nCPE == 1 ) /* Stereo DMX */ + IF( EQ_16( st_ivas->nCPE, 1 ) ) /* Stereo DMX */ { - if ( ( error = ivas_cpe_enc( st_ivas, 0, data_f[0], data_f[1], input_frame, hMetaData->nb_bits_tot ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_cpe_enc_fx( st_ivas, 0, data_fx[0], data_fx[1], st_ivas->q_data_fx, input_frame, hMetaData->nb_bits_tot ) ) != IVAS_ERR_OK ) { return error; } } - else if ( st_ivas->nCPE > 1 ) + ELSE IF( GT_16( st_ivas->nCPE, 1 ) ) { - if ( ( error = ivas_mct_enc( st_ivas, data_f, input_frame, hMetaData->nb_bits_tot ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_mct_enc_fx( st_ivas, data_fx, st_ivas->q_data_fx, input_frame, hMetaData->nb_bits_tot ) ) != IVAS_ERR_OK ) { return error; } @@ -1274,18 +1196,20 @@ ivas_error ivas_enc( FOR( i = 0; i < nchan_inp; i++ ) { - scale_sig32( data_fx[i], input_frame, Q8 - Q11 ); // Q11 -> Q8 + scale_sig32( data_fx[i], input_frame, sub( Q8, st_ivas->q_data_fx ) ); // st_ivas->q_data_fx -> Q8 } st_ivas->q_data_fx = Q8; move16(); ivas_mcmasa_enc_fx( st_ivas->hMcMasa, st_ivas->hQMetaData, st_ivas->hMasa, data_fx, input_frame, st_ivas->nchan_transport, nchan_inp, st_ivas->q_data_fx ); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - for ( i = 0; i < nchan_inp; i++ ) + + FOR( i = 0; i < nchan_inp; i++ ) { - fixedToFloat_arrL( data_fx[i], data_f[i], st_ivas->q_data_fx, input_frame ); + scale_sig32( data_fx[i], input_frame, sub( Q11, st_ivas->q_data_fx ) ); // st_ivas->q_data_fx -> Q11 } -#endif + st_ivas->q_data_fx = Q11; + move16(); + /* Scaling down the Q-factor of energy_ratio_fx from Q31 to Q30 */ FOR( i = 0; i < st_ivas->hMcMasa->nbands; i++ ) { @@ -1300,14 +1224,14 @@ ivas_error ivas_enc( IF( st_ivas->hMcMasa->separateChannelEnabled ) { - IF( ( error = ivas_sce_enc( st_ivas, 0, data_f[2], input_frame, 0 ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_sce_enc_fx( st_ivas, 0, data_fx[2], st_ivas->q_data_fx, input_frame, 0 ) ) != IVAS_ERR_OK ) { return error; } st_ivas->hCPE[0]->hCoreCoder[0]->hBstr->ind_list = st_ivas->hSCE[0]->hCoreCoder[0]->hBstr->ind_list + st_ivas->hSCE[0]->hCoreCoder[0]->hBstr->nb_ind_tot; - IF( ( error = ivas_cpe_enc( st_ivas, 0, data_f[0], data_f[1], input_frame, hMetaData->nb_bits_tot ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_cpe_enc_fx( st_ivas, 0, data_fx[0], data_fx[1], st_ivas->q_data_fx, input_frame, hMetaData->nb_bits_tot ) ) != IVAS_ERR_OK ) { return error; } @@ -1316,14 +1240,14 @@ ivas_error ivas_enc( { IF( EQ_16( st_ivas->nSCE, 1 ) ) { - IF( ( error = ivas_sce_enc( st_ivas, 0, data_f[0], input_frame, hMetaData->nb_bits_tot ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_sce_enc_fx( st_ivas, 0, data_fx[0], st_ivas->q_data_fx, input_frame, hMetaData->nb_bits_tot ) ) != IVAS_ERR_OK ) { return error; } } ELSE IF( EQ_16( st_ivas->nCPE, 1 ) ) /* Stereo DMX */ { - IF( ( error = ivas_cpe_enc( st_ivas, 0, data_f[0], data_f[1], input_frame, hMetaData->nb_bits_tot ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_cpe_enc_fx( st_ivas, 0, data_fx[0], data_fx[1], st_ivas->q_data_fx, input_frame, hMetaData->nb_bits_tot ) ) != IVAS_ERR_OK ) { return error; } @@ -1337,6 +1261,7 @@ ivas_error ivas_enc( *----------------------------------------------------------------*/ hEncoderConfig->last_ivas_total_brate = ivas_total_brate; + move32(); #ifdef DEBUG_MODE_INFO { diff --git a/lib_enc/ivas_front_vad.c b/lib_enc/ivas_front_vad.c index af515d836..7bf6300f9 100644 --- a/lib_enc/ivas_front_vad.c +++ b/lib_enc/ivas_front_vad.c @@ -560,6 +560,14 @@ ivas_error front_vad_create( } #ifdef IVAS_FLOAT_FIXED hFrontVad->delay_buf_fx = NULL; + IF( GT_16( hFrontVad->delay_samples, 0 ) ) + { + IF( ( hFrontVad->delay_buf_fx = (Word16 *) malloc( hFrontVad->delay_samples * sizeof( Word16 ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for VAD delay buffer\n" ) ); + } + set16_fx( hFrontVad->delay_buf_fx, 0, hFrontVad->delay_samples ); + } #endif *hFrontVad_out = hFrontVad; @@ -700,35 +708,27 @@ void front_vad_destroy_fx( * Standalone front-VAD module for SPAR *-----------------------------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED -ivas_error front_vad_spar( - SPAR_ENC_HANDLE hSpar, /* i/o: SPAR encoder structure */ - const float *omni_in, /* i : omnidirectional input signal */ - ENCODER_CONFIG_HANDLE hEncoderConfig, /* i : encoder configuration handle */ - const int16_t input_frame /* i : input frame length */ +ivas_error front_vad_spar_fx( + SPAR_ENC_HANDLE hSpar, /* i/o: SPAR encoder structure */ + const Word32 *omni_in, /* i : omnidirectional input signal Q11 */ + ENCODER_CONFIG_HANDLE hEncoderConfig, /* i : encoder configuration handle */ + const Word16 input_frame /* i : input frame length */ ) { FRONT_VAD_ENC_HANDLE hFrontVad; - float input[L_FRAME48k] = { 0 }; Word16 input_fx[L_FRAME48k]; - int16_t vad_flag_dtx[1]; - float fr_bands[1][2 * NB_BANDS]; + Word16 vad_flag_dtx[1]; Word32 fr_bands_fx[1][2 * NB_BANDS] = { { 0 } }; - float Etot[1]; Word16 Etot_fx[1]; - float lf_E[1][2 * VOIC_BINS]; - int16_t localVAD_HE_SAD[1]; - int16_t vad_hover_flag[1]; - float band_energies[2 * NB_BANDS]; + Word16 localVAD_HE_SAD[1]; + Word16 vad_hover_flag[1]; Word32 band_energies_fx[2 * NB_BANDS]; - int16_t high_lpn_flag; + Word16 high_lpn_flag; Encoder_State *st; - float tmpN[NB_BANDS], tmpE[NB_BANDS]; Word32 tmpN_fx[NB_BANDS] = { 0 }; Word32 tmpE_fx[NB_BANDS] = { 0 }; - float corr_shift; Word16 corr_shift_fx; -#if 1 Word32 res_energy_fx; Word16 A_fx[NB_SUBFR16k * ( M + 1 )], Aw_fx[NB_SUBFR16k * ( M + 1 )]; @@ -738,18 +738,9 @@ ivas_error front_vad_spar( Word16 alw_voicing_fx[2]; Word16 lsp_new_fx[M]; Word16 lsp_mid_fx[M]; -#endif - float A[NB_SUBFR16k * ( M + 1 )], Aw[NB_SUBFR16k * ( M + 1 )]; - float epsP[M + 1]; - float lsp_new[M]; - float lsp_mid[M]; - int16_t alw_pitch_lag_12k8[2]; - float alw_voicing[2]; - float cor_map_sum; - float non_staX; - int16_t loc_harm; - float S_map[L_FFT / 2]; -#if 1 + + Word16 alw_pitch_lag_12k8[2]; + Word16 loc_harm; Word16 epsP_h[M + 1]; Word16 epsP_l[M + 1]; Word32 lf_E_fx[1][2 * VOIC_BINS]; @@ -758,63 +749,71 @@ ivas_error front_vad_spar( Word16 Q_sp_div; Word16 non_staX_fx; Word16 sp_floor; -#else - float ncharX; - float sp_div, dummy; -#endif + Word16 cor_map_sum_fx; Word16 dummy_fx; Word16 S_map_fx[L_FFT / 2]; Word16 relE_fx; Word16 *wsp_fx; - float *inp_12k8; -#if 1 Word16 *inp_12k8_fx; -#endif - float old_wsp[L_WSP]; + Word16 old_wsp_fx[L_WSP]; - float *wsp; + Word16 flag_spitch; + Word32 PS_fx[L_FRAME / 2]; + Word16 s, Q_inp; + Word16 tmp; + Word16 old_pitch; + ivas_error error; +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + float input[L_FRAME48k] = { 0 }; + float fr_bands[1][2 * NB_BANDS]; + float Etot[1]; + float lf_E[1][2 * VOIC_BINS]; + float band_energies[2 * NB_BANDS]; + float tmpN[NB_BANDS], tmpE[NB_BANDS]; + float corr_shift; + float A[NB_SUBFR16k * ( M + 1 )], Aw[NB_SUBFR16k * ( M + 1 )]; + float epsP[M + 1]; + float lsp_new[M]; + float lsp_mid[M]; + float alw_voicing[2]; + float cor_map_sum; + float non_staX; + float S_map[L_FFT / 2]; + float *inp_12k8; + float old_wsp[L_WSP]; + float *wsp; float relE; - - int16_t flag_spitch; float PS[L_FRAME / 2]; - Word32 PS_fx[L_FRAME / 2]; - int16_t old_pitch; - ivas_error error; -#ifdef DUMP_VAD_SPAR - FILE *fptmpN_fl = fopen( "tmpN_fl.txt", "ab+" ); - FILE *fptmpE_fl = fopen( "tmpE_fl.txt", "ab+" ); - FILE *fpbckr_fl = fopen( "bckr_fl.txt", "ab+" ); - - FILE *fptmpN_fx = fopen( "tmpN_fx.txt", "ab+" ); - FILE *fptmpE_fx = fopen( "tmpE_fx.txt", "ab+" ); - FILE *fpbckr_fx = fopen( "bckr_fx.txt", "ab+" ); #endif push_wmops( "front_vad_SPAR" ); error = IVAS_ERR_OK; + move32(); hFrontVad = hSpar->hFrontVad; st = hSpar->hCoreCoderVAD; - if ( hEncoderConfig->Opt_DTX_ON && hEncoderConfig->ivas_total_brate <= SBA_DTX_BITRATE_THRESHOLD ) + test(); + IF( hEncoderConfig->Opt_DTX_ON && LE_32( hEncoderConfig->ivas_total_brate, SBA_DTX_BITRATE_THRESHOLD ) ) { /*------------------------------------------------------------------* * Initialization *-----------------------------------------------------------------*/ inp_12k8 = hFrontVad->buffer_12k8; Word16 Q_bands = Q31; -#if 1 Word16 Q_inp_12k8 = Q9; -#endif -#if 1 + move16(); + move16(); + inp_12k8_fx = hFrontVad->buffer_12k8_fx; -#endif mvr2r( st->old_wsp, old_wsp, L_WSP_MEM ); +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS floatToFixed_arr( st->old_wsp, st->old_wsp_fx, Q9, L_WSP_MEM ); floatToFixed_arr( st->old_wsp2, st->old_wsp2_fx, Q9, ( L_WSP_MEM - L_INTERPOL ) / OPL_DECIM ); floatToFixed_arr( st->mem_decim2, st->mem_decim2_fx, Q9, 3 ); +#endif MVR2R_WORD16( st->old_wsp_fx, old_wsp_fx, L_WSP_MEM ); wsp = old_wsp + L_WSP_MEM; @@ -822,19 +821,40 @@ ivas_error front_vad_spar( st->core_brate = -1; /* updated in dtx() */ st->input_bwidth = st->last_input_bwidth; + move32(); + move16(); /*------------------------------------------------------------------* * compensate for SPAR filterbank delay *-----------------------------------------------------------------*/ Q_bands = Q9; + move16(); st->input = input; st->input_fx = input_fx; - mvr2r( omni_in, st->input, input_frame ); - delay_signal_float( st->input, input_frame, hFrontVad->delay_buf, hFrontVad->delay_samples ); - Word16 Q_inp; - Q_inp = Q_factor_arr( st->input, L_FRAME48k ); - floatToFixed_arr( st->input, st->input_fx, Q_inp, L_FRAME48k ); + Copy_Scale_sig32_16( omni_in, st->input_fx, input_frame, Q16 - Q11 ); + delay_signal( st->input_fx, input_frame, hFrontVad->delay_buf_fx, hFrontVad->delay_samples ); + + /* Scaling only if the omni_in buffer contains non-zero values */ + maximum_abs_16_fx( st->input_fx, input_frame, &tmp ); + IF( tmp != 0 ) + { + s = norm_s( tmp ); + } + ELSE + { + s = 15; + move16(); + } + IF( tmp != 0 ) + { + Scale_sig( st->input_fx, input_frame, s ); + } + Q_inp = s; + move16(); +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + fixedToFloat_arr( st->input_fx, st->input, Q_inp, input_frame ); +#endif Word16 Q_add = 0; move16(); /*------------------------------------------------------------------* @@ -866,7 +886,7 @@ ivas_error front_vad_spar( floatToFixed_arrL( &band_energies[0], &band_energies_fx[0], Q_new_old + QSCALE + 2, 40 ); #endif #endif - if ( ( error = front_vad_fx( NULL, st, hEncoderConfig, &hFrontVad, 0 /* MCT_flag */, input_frame, vad_flag_dtx, fr_bands_fx, Etot_fx, lf_E_fx, localVAD_HE_SAD, vad_hover_flag, band_energies_fx, &PS_fx[0], &st->lgBin_E_fx[0], Q_inp, &Q_buffer, Q_add, &front_create_flag ) ) != IVAS_ERR_OK ) + IF( ( error = front_vad_fx( NULL, st, hEncoderConfig, &hFrontVad, 0 /* MCT_flag */, input_frame, vad_flag_dtx, fr_bands_fx, Etot_fx, lf_E_fx, localVAD_HE_SAD, vad_hover_flag, band_energies_fx, &PS_fx[0], &st->lgBin_E_fx[0], Q_inp, &Q_buffer, Q_add, &front_create_flag ) ) != IVAS_ERR_OK ) { return error; } @@ -889,60 +909,45 @@ ivas_error front_vad_spar( Word32 e_min_scaled; e_min_scaled = L_shr_r( L_add( L_shr( E_MIN_FXQ15, sub( 14, add( Q_bands, QSCALE ) ) ), 1 ), 1 ); - // floatToFixed_arr( inp_12k8, inp_12k8_fx, Q_inp_12k8, 3 * L_FRAME / 2 ); - // Q_bands = Q_factor_arrL( fr_bands[0], 2 * NB_BANDS ); + +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS floatToFixed_arrL( fr_bands[0], fr_bands_fx[0], Q_bands + QSCALE, 2 * NB_BANDS ); floatToFixed_arrL( hFrontVad->hNoiseEst->bckr, hFrontVad->hNoiseEst->bckr_fx, Q_bands + QSCALE, NB_BANDS ); #ifndef MSAN_FIX floatToFixed_arrL( tmpE, tmpE_fx, Q_bands + QSCALE, NB_BANDS ); #endif Etot_fx[0] = (Word16) ( Etot[0] * ONE_IN_Q8 ); - noise_est_down_fx( fr_bands_fx[0], hFrontVad->hNoiseEst->bckr_fx, tmpN_fx, tmpE_fx, st->min_band, st->max_band, &hFrontVad->hNoiseEst->totalNoise_fx, Etot_fx[0], &hFrontVad->hNoiseEst->Etot_last_fx, &hFrontVad->hNoiseEst->Etot_v_h2_fx, Q_bands, e_min_scaled ); -#ifdef DUMP_VAD_SPAR - for ( Word16 i = 0; i < 20; i++ ) - { - fprintf( fptmpN_fl, "%f\n", tmpN[i] ); - fprintf( fptmpE_fl, "%f\n", tmpE[i] ); - fprintf( fpbckr_fl, "%f\n", hFrontVad->hNoiseEst->bckr[i] ); - } #endif - // fixedToFloat_arrL( fr_bands_fx[0], fr_bands[0], Q_bands, 2 * NB_BANDS ); + noise_est_down_fx( fr_bands_fx[0], hFrontVad->hNoiseEst->bckr_fx, tmpN_fx, tmpE_fx, st->min_band, st->max_band, &hFrontVad->hNoiseEst->totalNoise_fx, Etot_fx[0], &hFrontVad->hNoiseEst->Etot_last_fx, &hFrontVad->hNoiseEst->Etot_v_h2_fx, Q_bands, e_min_scaled ); + +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS fixedToFloat_arrL( hFrontVad->hNoiseEst->bckr_fx, hFrontVad->hNoiseEst->bckr, Q_bands + Q7, NB_BANDS ); fixedToFloat_arrL( tmpN_fx, tmpN, Q_bands + QSCALE, 20 ); fixedToFloat_arrL( tmpE_fx, tmpE, Q_bands + QSCALE, 20 ); -#ifdef DUMP_VAD_SPAR - for ( Word16 i = 0; i < 20; i++ ) - { - fprintf( fptmpN_fx, "%f\n", tmpN[i] ); - fprintf( fptmpE_fx, "%f\n", tmpE[i] ); - fprintf( fpbckr_fx, "%f\n", hFrontVad->hNoiseEst->bckr[i] ); - } #endif - // corr_shift = correlation_shift( hFrontVad->hNoiseEst->totalNoise ); corr_shift_fx = correlation_shift_fx( hFrontVad->hNoiseEst->totalNoise_fx ); +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS corr_shift = fixedToFloat( corr_shift_fx, Q15 ); -#if 1 Q_inp_12k8 = Q_factor_arr( inp_12k8, 3 * L_FRAME / 2 ); floatToFixed_arr( inp_12k8, inp_12k8_fx, Q_inp_12k8, 3 * L_FRAME / 2 ); - dtx_ivas_fx( st, hEncoderConfig->ivas_total_brate, vad_flag_dtx[0], inp_12k8_fx, Q_inp_12k8 ); -#else - dtx( st, hEncoderConfig->ivas_total_brate, vad_flag_dtx[0], inp_12k8 ); #endif + dtx_ivas_fx( st, hEncoderConfig->ivas_total_brate, vad_flag_dtx[0], inp_12k8_fx, Q_inp_12k8 ); + /* linear prediction analysis */ alw_pitch_lag_12k8[0] = st->old_pitch_la; alw_pitch_lag_12k8[1] = st->old_pitch_la; alw_voicing[0] = st->voicing[2]; alw_voicing[1] = st->voicing[2]; -#if 0 - analy_lp( inp_12k8, L_FRAME, L_LOOK_12k8, &res_energy, A, epsP, lsp_new, lsp_mid, st->lsp_old1, alw_pitch_lag_12k8, alw_voicing, INT_FS_12k8, 0 /* <-- sec_chan_low_rate */ ); -#else - // analy_lp( inp_12k8, L_FRAME, L_LOOK_12k8, &res_energy, A, epsP, lsp_new, lsp_mid, st->lsp_old1, alw_pitch_lag_12k8, alw_voicing, INT_FS_12k8, 0 /* <-- sec_chan_low_rate */ ); - +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS Word16 Q_r[2] = { 0 }; floatToFixed_arr( alw_voicing, alw_voicing_fx, Q15, 2 ); Q_inp_12k8 = Q9; // Q_factor_arr( inp_12k8 - 90, 3 * L_FRAME / 2 + 90 ); floatToFixed_arr( inp_12k8 - 90, inp_12k8_fx - 90, Q_inp_12k8, 3 * L_FRAME / 2 + 90 ); +#endif + analy_lp_ivas_fx( inp_12k8_fx, L_FRAME, L_LOOK_12k8, &res_energy_fx, A_fx, epsP_h, epsP_l, lsp_new_fx, lsp_mid_fx, st->lsp_old1_fx, alw_pitch_lag_12k8, alw_voicing_fx, INT_FS_12k8, 0 /* <-- sec_chan_low_rate */, Q_inp_12k8, Q_r ); + +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS for ( Word16 i = 0; i <= M; i++ ) { epsP_fx[i] = L_Comp( epsP_h[i], epsP_l[i] ); @@ -955,10 +960,8 @@ ivas_error front_vad_spar( #endif relE = Etot[0] - st->lp_speech; -#if 0 - find_wsp( L_FRAME, L_SUBFR, NB_SUBFR, A, Aw, inp_12k8, TILT_FAC, wsp, &st->mem_wsp, GAMMA1_FLT, L_LOOK_12k8 ); -#else +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS Q_inp_12k8 = Q9; // Q_factor_arr( inp_12k8-M, (3 * L_FRAME / 2)+M ); floatToFixed_arr( inp_12k8 - M, inp_12k8_fx - M, Q_inp_12k8, ( 3 * L_FRAME / 2 ) + M ); #ifdef MSAN_FIX @@ -966,26 +969,24 @@ ivas_error front_vad_spar( #else floatToFixed_arr( A, A_fx, Q12, NB_SUBFR16k * ( M + 1 ) ); #endif // MSAN_FIX - st->mem_wsp_fx = (Word16) floatToFixed( st->mem_wsp, Q_inp_12k8 ); - // find_wsp_fx( A_fx, inp_12k8_fx, wsp_fx, &st->mem_wsp_fx, TILT_FAC_FX, L_FRAME, L_LOOK_12k8, L_SUBFR, Aw_fx, GAMMA1, NB_SUBFR ); +#endif + ivas_find_wsp( L_FRAME, L_SUBFR, NB_SUBFR, A_fx, Aw_fx, inp_12k8_fx, TILT_FAC_FX, wsp_fx, &st->mem_wsp_fx, GAMMA1, L_LOOK_12k8 ); + +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS fixedToFloat_arr( wsp_fx, wsp, Q_inp_12k8, 368 ); fixedToFloat_arr( Aw_fx, Aw, Q12, NB_SUBFR16k * ( M + 1 ) ); #endif - if ( st->vad_flag == 0 ) + IF( st->vad_flag == 0 ) { /* reset the OL pitch tracker memories during inactive frames */ -#if 0 - pitch_ol_init( &st->old_thres, &st->old_pitch, &st->delta_pit, &st->old_corr ); -#else pitch_ol_init_fx( &st->old_thres_fx, &st->old_pitch, &st->delta_pit, &st->old_corr_fx ); -#endif } old_pitch = st->pitch[1]; -#if 1 +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS floatToFixed_arr( st->voicing, st->voicing_fx, Q15, 3 ); floatToFixed_arr( wsp, wsp_fx, Q8, 368 ); floatToFixed_arr( st->old_wsp2, st->old_wsp2_fx, Q8, 115 ); @@ -996,16 +997,15 @@ ivas_error front_vad_spar( corr_shift_fx = (Word16) floatToFixed( corr_shift, Q15 ); // st->old_thres_fx = (Word16) floatToFixed( st->old_thres, Q15 ); relE_fx = (Word16) floatToFixed( relE, Q8 ); +#endif pitch_ol_ivas_fx( st->pitch, st->voicing_fx, &st->old_pitch, &st->old_corr_fx, corr_shift_fx, &st->old_thres_fx, &st->delta_pit, st->old_wsp2_fx, wsp_fx, st->mem_decim2_fx, relE_fx, st->clas, st->input_bwidth, st->Opt_SC_VBR ); // pitch_ol( st->pitch, st->voicing, &st->old_pitch, &st->old_corr, corr_shift, &st->old_thres, &st->delta_pit, st->old_wsp2, wsp, st->mem_decim2, relE, L_LOOK_12k8, st->clas, st->input_bwidth, st->Opt_SC_VBR ); - +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS fixedToFloat_arr( st->voicing_fx, st->voicing, Q15, 3 ); fixedToFloat_arr( st->old_wsp2_fx, st->old_wsp2, Q8, 115 ); fixedToFloat_arr( st->mem_decim2_fx, st->mem_decim2, Q8, 3 ); st->old_corr = fixedToFloat( st->old_corr_fx, Q15 ); -#else - pitch_ol( st->pitch, st->voicing, &st->old_pitch, &st->old_corr, corr_shift, &st->old_thres, &st->delta_pit, st->old_wsp2, wsp, st->mem_decim2, relE, L_LOOK_12k8, st->clas, st->input_bwidth, st->Opt_SC_VBR ); #endif /* Updates for adaptive lag window memory */ st->old_pitch_la = st->pitch[2]; @@ -1125,15 +1125,6 @@ ivas_error front_vad_spar( hSpar->front_vad_dtx_flag = 0; hSpar->force_front_vad = 0; } -#ifdef DUMP_VAD_SPAR - fclose( fptmpN_fl ); - fclose( fptmpE_fl ); - fclose( fpbckr_fl ); - - fclose( fptmpN_fx ); - fclose( fptmpE_fx ); - fclose( fpbckr_fx ); -#endif pop_wmops(); return error; diff --git a/lib_enc/ivas_init_enc.c b/lib_enc/ivas_init_enc.c index 2378bd8d4..3c246c0ad 100644 --- a/lib_enc/ivas_init_enc.c +++ b/lib_enc/ivas_init_enc.c @@ -887,10 +887,17 @@ ivas_error ivas_init_encoder( for ( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ ) { +#ifndef IVAS_FLOAT_FIXED if ( ( error = create_sce_enc( st_ivas, sce_id, ivas_total_brate / st_ivas->nchan_transport ) ) != IVAS_ERR_OK ) { return error; } +#else + IF( ( error = create_sce_enc_fx( st_ivas, sce_id, ivas_total_brate / st_ivas->nchan_transport ) ) != IVAS_ERR_OK ) + { + return error; + } +#endif if ( ivas_format == SBA_FORMAT && st_ivas->hEncoderConfig->Opt_DTX_ON ) { @@ -947,6 +954,7 @@ ivas_error ivas_init_encoder( } ism_total_brate = 0; +#ifndef IVAS_FLOAT_FIXED for ( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ ) { ism_total_brate += sep_object_brate[k - 2][st_ivas->nSCE - 1]; @@ -955,6 +963,16 @@ ivas_error ivas_init_encoder( return error; } } +#else + FOR( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ ) + { + ism_total_brate = L_add( ism_total_brate, sep_object_brate[k - 2][st_ivas->nSCE - 1] ); + IF( ( error = create_sce_enc_fx( st_ivas, sce_id, sep_object_brate[k - 2][st_ivas->nSCE - 1] ) ) != IVAS_ERR_OK ) + { + return error; + } + } +#endif if ( ( error = ivas_qmetadata_open( &( st_ivas->hQMetaData ) ) ) != IVAS_ERR_OK ) { @@ -1040,6 +1058,7 @@ ivas_error ivas_init_encoder( if ( st_ivas->ism_mode == ISM_MODE_NONE ) { /* allocate and initialize SBA core-coders */ +#ifndef IVAS_FLOAT_FIXED if ( st_ivas->nchan_transport == 1 ) { if ( ( error = create_sce_enc( st_ivas, 0, ivas_total_brate ) ) != IVAS_ERR_OK ) @@ -1047,6 +1066,15 @@ ivas_error ivas_init_encoder( return error; } } +#else + IF( EQ_16( st_ivas->nchan_transport, 1 ) ) + { + IF( ( error = create_sce_enc_fx( st_ivas, 0, ivas_total_brate ) ) != IVAS_ERR_OK ) + { + return error; + } + } +#endif for ( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) { @@ -1233,6 +1261,7 @@ ivas_error ivas_init_encoder( ivas_mcmasa_split_brate_fx( st_ivas->hMcMasa->separateChannelEnabled, ivas_total_brate, st_ivas->nSCE, st_ivas->nCPE, &brate_sce, &brate_cpe ); #endif +#ifndef IVAS_FLOAT_FIXED for ( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ ) { if ( ( error = create_sce_enc( st_ivas, sce_id, brate_sce ) ) != IVAS_ERR_OK ) @@ -1240,6 +1269,15 @@ ivas_error ivas_init_encoder( return error; } } +#else + FOR( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ ) + { + IF( ( error = create_sce_enc_fx( st_ivas, sce_id, brate_sce ) ) != IVAS_ERR_OK ) + { + return error; + } + } +#endif for ( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) { diff --git a/lib_enc/ivas_ism_enc.c b/lib_enc/ivas_ism_enc.c index 47423d868..e81b89e13 100644 --- a/lib_enc/ivas_ism_enc.c +++ b/lib_enc/ivas_ism_enc.c @@ -419,12 +419,13 @@ ivas_error ivas_ism_enc( return error; } #else -ivas_error ivas_ism_enc( - Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ - float *data[], /* i : input signal [channels][samples] */ - const Word16 input_frame, /* i : input frame length per channel */ - Word16 *nb_bits_metadata, /* i : number of metadata bits */ - const Word16 flag_omasa_ener_brate /* i : less bitrate for objects in OMASA flag */ +ivas_error ivas_ism_enc_fx( + Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ + Word32 *data[], /* i : input signal [channels][samples] Q(q_data) */ + Word16 q_data, /* i : Q-factor of input signal */ + const Word16 input_frame, /* i : input frame length per channel */ + Word16 *nb_bits_metadata, /* i : number of metadata bits */ + const Word16 flag_omasa_ener_brate /* i : less bitrate for objects in OMASA flag */ ) { SCE_ENC_HANDLE hSCE; @@ -526,8 +527,8 @@ ivas_error ivas_ism_enc( /*------------------------------------------------------------------* * Initialization - general *-----------------------------------------------------------------*/ - - mvr2r( data[sce_id], st->input, input_frame ); + Copy32( data[sce_id], st->input32_fx, input_frame ); // Q(q_data) + Copy_Scale_sig32_16( st->input32_fx, st->input_fx, input_frame, sub( Q16 - 1, q_data ) ); // Q(q_data) -> Q(-1) st->element_mode = IVAS_SCE; move16(); @@ -554,28 +555,20 @@ ivas_error ivas_ism_enc( /*---------------------------------------------------------------* * Time Domain Transient Detector *---------------------------------------------------------------*/ - -#ifdef IVAS_FLOAT_FIXED #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - floatToFixed_arr16( st->input, st->input_fx, -1, input_frame ); + fixedToFloat_arrL( st->input32_fx, st->input, q_data, input_frame ); #endif RunTransientDetection_ivas_fx( st->input_fx, input_frame, st->hTranDet ); st->hTranDet->subblockEnergies.subblockNrg_e = 31 - Q7; st->hTranDet->subblockEnergies.accSubblockNrg_e = 31 - Q7; move16(); move16(); -#else - RunTransientDetection( st->input, input_frame, st->hTranDet ); -#endif -#ifdef IVAS_FLOAT_FIXED currFlatness_fx[0] = GetTCXAvgTemporalFlatnessMeasure_fx( (const TransientDetection *) st->hTranDet, NSUBBLOCKS, 0 ); + move16(); #ifdef IVAS_FLOAT_FIXED_CONVERSIONS currFlatness[0] = me2f_16( currFlatness_fx[0], 15 - Q7 ); #endif -#else - currFlatness[0] = GetTCXAvgTemporalFlatnessMeasure( st->hTranDet, NSUBBLOCKS, 0 ); -#endif /*----------------------------------------------------------------* * Configuration of core encoder @@ -620,10 +613,10 @@ ivas_error ivas_ism_enc( /* compute the dominant sce_id using long term energy */ for ( int j = 0; j < st_ivas->nchan_transport; j++ ) { - IF( st_ivas->hSCE[j] && st_ivas->hSCE[j]->hCoreCoder[0] ) - floatToFixed_arrL( st_ivas->hSCE[j]->hCoreCoder[0]->input, st_ivas->hSCE[j]->hCoreCoder[0]->input32_fx, Q11, input_frame ); /*Q0*/ + if ( st_ivas->hSCE[j] && st_ivas->hSCE[j]->hCoreCoder[0] ) + floatToFixed_arrL( st_ivas->hSCE[j]->hCoreCoder[0]->input, st_ivas->hSCE[j]->hCoreCoder[0]->input32_fx, Q11, input_frame ); /*Q0*/ } - FOR( sce_id = 0; sce_id < nchan_transport_ism; sce_id++ ) + for ( sce_id = 0; sce_id < nchan_transport_ism; sce_id++ ) { relE_fx[sce_id][0] = float_to_fix16( relE[sce_id][0], Q8 ); } diff --git a/lib_enc/ivas_mct_enc.c b/lib_enc/ivas_mct_enc.c index 4750162a7..49ae8f695 100644 --- a/lib_enc/ivas_mct_enc.c +++ b/lib_enc/ivas_mct_enc.c @@ -154,7 +154,7 @@ static void set_mct_enc_params( * cpe_id 1: L=data[4] R=data[5] * cpe_id 2: L=data[2] (mid) R=NULL *-------------------------------------------------------------------*/ - +#ifndef IVAS_FLOAT_FIXED static void map_input_to_cpe_channels( const Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ float *pdata[MAX_INPUT_CHANNELS], /* o : mapped input pointers */ @@ -203,7 +203,7 @@ static void map_input_to_cpe_channels( return; } - +#endif static void map_input_to_cpe_channels_ivas_fx( const Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ Word32 *pdata[MAX_INPUT_CHANNELS], /* o : mapped input pointers */ @@ -386,11 +386,12 @@ ivas_error ivas_mct_enc( return error; } #else -ivas_error ivas_mct_enc( - Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ - float *data[MCT_MAX_CHANNELS], /* i : input signal buffers */ - const Word16 input_frame, /* i : input frame length per channel */ - const Word16 nb_bits_metadata /* i : number of metadata bits */ +ivas_error ivas_mct_enc_fx( + Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ + Word32 *data_fx[MCT_MAX_CHANNELS], /* i : input signal buffers Q(q_data_fx) */ + Word16 q_data_fx, /* i : Q-factor of input signal */ + const Word16 input_frame, /* i : input frame length per channel */ + const Word16 nb_bits_metadata /* i : number of metadata bits */ ) { Word16 n, cpe_id; @@ -405,7 +406,7 @@ ivas_error ivas_mct_enc( Word16 max_bwidth; Word32 ivas_total_brate; ivas_error error; - float *pdata[MAX_INPUT_CHANNELS]; + Word32 *pdata_fx[MAX_INPUT_CHANNELS]; error = IVAS_ERR_OK; move32(); @@ -428,7 +429,7 @@ ivas_error ivas_mct_enc( FOR( n = 0; n < CPE_CHANNELS; n++ ) { hCPE = st_ivas->hCPE[cpe_id]; -#if 1 // float initialization to be removed +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS hMCT->p_mdst_spectrum_long[cpe_id][n] = mdst_spectrum_long[cpe_id][n]; hMCT->p_orig_spectrum_long[cpe_id][n] = orig_spectrum_long[cpe_id][n]; #ifdef MSAN_FIX @@ -493,50 +494,12 @@ ivas_error ivas_mct_enc( switch_bw = set_bw_mct_fx( st_ivas->hCPE, st_ivas->nCPE ); /*for MC and MCT remove pointer to LFE input that has been processed separately */ -#ifndef IVAS_FLOAT_FIXED - map_input_to_cpe_channels( st_ivas, pdata, data ); -#else -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - Word32 *pdata_fx[MAX_INPUT_CHANNELS]; - Word32 data_fx_tmp[MCT_MAX_CHANNELS][960]; - Word32 *data_fx[MCT_MAX_CHANNELS]; - Word16 nchan_transport; - for ( int i = 0; i < MAX_INPUT_CHANNELS; i++ ) - { - pdata_fx[i] = NULL; - pdata[i] = NULL; - } - Word16 len = (Word16) ( st_ivas->hEncoderConfig->input_Fs / FRAMES_PER_SEC ); - nchan_transport = st_ivas->nchan_transport; - if ( st_ivas->hEncoderConfig->ivas_format == SBA_ISM_FORMAT && st_ivas->ism_mode == ISM_SBA_MODE_DISC ) - { - nchan_transport += st_ivas->hEncoderConfig->nchan_ism; - } - - for ( int i = 0; i < nchan_transport; i++ ) - { - data_fx[i] = data_fx_tmp[i]; - floatToFixed_arrL( data[i], data_fx[i], Q11, len ); - } - map_input_to_cpe_channels( st_ivas, pdata, data ); -#endif map_input_to_cpe_channels_ivas_fx( st_ivas, pdata_fx, data_fx ); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - for ( int i = 0; i < MCT_MAX_CHANNELS; i++ ) - { - if ( pdata_fx[i] == NULL ) - { - continue; - } - fixedToFloat_arrL( pdata_fx[i], pdata[i], Q11, len ); - } -#endif -#endif /* pre-processing */ FOR( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) { - IF( ( error = ivas_cpe_enc( st_ivas, cpe_id, pdata[cpe_id * CPE_CHANNELS], pdata[cpe_id * CPE_CHANNELS + 1], input_frame, nb_bits_metadata ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_cpe_enc_fx( st_ivas, cpe_id, pdata_fx[cpe_id * CPE_CHANNELS], pdata_fx[cpe_id * CPE_CHANNELS + 1], q_data_fx, input_frame, nb_bits_metadata ) ) != IVAS_ERR_OK ) { return error; } @@ -583,10 +546,6 @@ ivas_error ivas_mct_enc( { for ( ch = 0; ch < CPE_CHANNELS; ch++ ) { - // if ( st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->mct_chan_mode == MCT_CHAN_MODE_IGNORE ) - //{ - // continue; - // } length = st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->hTcxEnc->L_frameTCX / ( ( st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->hTcxEnc->tcxMode == TCX_20 ) ? 1 : NB_DIV ); if ( st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->last_core == ACELP_CORE ) { @@ -635,10 +594,6 @@ ivas_error ivas_mct_enc( i++; } } - FOR( int b = 0; b < hMCT->nchan_out_woLFE; b++ ) - { - st = sts_tmp[b]; - } #endif #endif // 1 diff --git a/lib_enc/ivas_qmetadata_enc.c b/lib_enc/ivas_qmetadata_enc.c index f77bce2a8..8b5f9cd16 100644 --- a/lib_enc/ivas_qmetadata_enc.c +++ b/lib_enc/ivas_qmetadata_enc.c @@ -2126,7 +2126,104 @@ void ivas_qmetadata_enc_sid_encode( * * Reset metadata in spatial formats *------------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +void reset_metadata_spatial_fx( + const IVAS_FORMAT ivas_format, /* i : IVAS format */ + BSTR_ENC_HANDLE hMetaData, /* i/o: metadata bitstream handle */ + const Word32 element_brate, /* i : element bitrate */ + Word32 *total_brate, /* o : total bitrate */ + const Word32 core_brate, /* i : core bitrate */ + const Word16 nb_bits_metadata /* i : number of meatdata bits */ +) +{ + Word16 i, next_ind_sid, last_ind_sid; + Word16 j; + Word16 metadata_sid_bits; + + test(); + IF( EQ_32( core_brate, SID_2k40 ) || core_brate == FRAME_NO_DATA ) + { + test(); + test(); + IF( ( EQ_32( ivas_format, SBA_FORMAT ) || EQ_32( ivas_format, MASA_FORMAT ) ) && core_brate != FRAME_NO_DATA ) + { + IF( EQ_32( ivas_format, SBA_FORMAT ) ) + { + hMetaData->ind_list[0].value = 1; + move16(); + metadata_sid_bits = (Word16) ( IVAS_SID_5k2 - SID_2k40 ) / FRAMES_PER_SEC - SID_FORMAT_NBITS; + move16(); + + WHILE( LT_16( hMetaData->nb_bits_tot, metadata_sid_bits ) ) + { + push_next_indice( hMetaData, 0, 1 ); /*fill bit*/ + } + } + ELSE + { + /* Reset metadata and keep only SID metadata*/ + last_ind_sid = hMetaData->nb_ind_tot; + next_ind_sid = hMetaData->nb_ind_tot; + move16(); + move16(); + WHILE( GT_16( hMetaData->nb_bits_tot, nb_bits_metadata ) ) + { + next_ind_sid--; + hMetaData->nb_bits_tot = sub( hMetaData->nb_bits_tot, hMetaData->ind_list[next_ind_sid].nb_bits ); + move16(); + } + + hMetaData->nb_bits_tot = 0; + move16(); + + FOR( i = 0; i < next_ind_sid; i++ ) + { + hMetaData->ind_list[i].nb_bits = -1; + move16(); + } + + FOR( ( j = 0, i = next_ind_sid ); i < last_ind_sid; ( i++, j++ ) ) + { + hMetaData->ind_list[j].value = hMetaData->ind_list[i].value; + hMetaData->ind_list[j].nb_bits = hMetaData->ind_list[i].nb_bits; + hMetaData->nb_bits_tot = add( hMetaData->nb_bits_tot, hMetaData->ind_list[j].nb_bits ); + hMetaData->ind_list[i].nb_bits = -1; + move16(); + move16(); + move16(); + move16(); + } + hMetaData->nb_ind_tot = j; + move16(); + } + } + ELSE + { + /*Reset metadata*/ + reset_indices_enc( hMetaData, hMetaData->nb_ind_tot ); + } + + *total_brate = element_brate; + move32(); + } + ELSE IF( NE_32( ivas_format, SBA_FORMAT ) ) + { + /* Reset SID metadata bits*/ + WHILE( GT_16( hMetaData->nb_bits_tot, nb_bits_metadata ) ) + { + hMetaData->nb_ind_tot--; + hMetaData->nb_bits_tot = sub( hMetaData->nb_bits_tot, hMetaData->ind_list[hMetaData->nb_ind_tot].nb_bits ); + hMetaData->ind_list[hMetaData->nb_ind_tot].nb_bits = -1; + move16(); + move16(); + move16(); + } + } + + return; +} +#else void reset_metadata_spatial( const IVAS_FORMAT ivas_format, /* i : IVAS format */ BSTR_ENC_HANDLE hMetaData, /* i/o: metadata bitstream handle */ @@ -2204,6 +2301,7 @@ void reset_metadata_spatial( return; } +#endif /*------------------------------------------------------------------------- diff --git a/lib_enc/ivas_sba_enc.c b/lib_enc/ivas_sba_enc.c index f246cb49d..7f5ed5358 100644 --- a/lib_enc/ivas_sba_enc.c +++ b/lib_enc/ivas_sba_enc.c @@ -52,7 +52,42 @@ * * Get TCs from Ambisonics signal in ACN *-------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +void ivas_sba_getTCs_fx( + Word32 *sba_data[], /* i : SBA signals Q11 */ + Encoder_Struct *st_ivas, /* i/o: Encoder struct */ + const Word16 input_frame /* i : frame length */ +) +{ + IF( st_ivas->hEncoderConfig->sba_planar ) + { + ivas_sba_zero_vert_comp_fx( sba_data, st_ivas->sba_analysis_order, st_ivas->hEncoderConfig->sba_planar, input_frame ); + } + + st_ivas->nchan_transport = ivas_get_sba_num_TCs_fx( st_ivas->hEncoderConfig->ivas_total_brate, st_ivas->sba_analysis_order ); + move16(); + IF( GE_16( st_ivas->nchan_transport, 3 ) ) + { + /*convert WYZX downmix to WYXZ*/ + Word16 i = 0; + move16(); + Word32 temp; + FOR( i = 0; i < input_frame; i++ ) + { + temp = sba_data[2][i]; + sba_data[2][i] = sba_data[3][i]; + sba_data[3][i] = temp; + move32(); + move32(); + move32(); + } + } + + + return; +} +#else void ivas_sba_getTCs( float *sba_data[], /* i : SBA signals */ Encoder_Struct *st_ivas, /* i/o: Encoder struct */ @@ -82,6 +117,7 @@ void ivas_sba_getTCs( return; } +#endif /*-------------------------------------------------------------------* * ivas_sba_enc_reconfigure() diff --git a/lib_enc/ivas_sce_enc.c b/lib_enc/ivas_sce_enc.c index 7c86f194a..43f9a9322 100644 --- a/lib_enc/ivas_sce_enc.c +++ b/lib_enc/ivas_sce_enc.c @@ -58,6 +58,305 @@ *-------------------------------------------------------------------*/ Indice ind_list[MAX_NUM_INDICES]; +#ifdef IVAS_FLOAT_FIXED +ivas_error ivas_sce_enc_fx( + Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ + const Word16 sce_id, /* i : SCE # identifier */ + const Word32 data_fx[], /* i : input signal for single channel Q(q_data_fx) */ + const Word16 q_data_fx, /* i : Q-factor of input signal for single channel */ + const Word16 input_frame, /* i : input frame length per channel */ + const Word16 nb_bits_metadata /* i : number of metadata bits */ +) +{ +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS // required for float to fix conversion + float old_inp_12k8[1][L_INP_12k8] = { 0 }; /* buffer of input signal @ 12k8 */ + float old_inp_16k[1][L_INP] = { 0 }; /* buffer of input signal @ 16kHz */ + float ener[1]; /* residual energy from Levinson-Durbin */ + float relE[1]; /* frame relative energy */ + float A[1][NB_SUBFR16k * ( M + 1 )] = { 0 }; /* A(z) unquantized for subframes */ + float Aw[1][NB_SUBFR16k * ( M + 1 )] = { 0 }; /* weighted A(z) unquantized for subframes */ + float epsP[1][M + 1]; /* LP prediction errors */ + float lsp_new[1][M]; /* LSPs at the end of the frame */ + float lsp_mid[1][M]; /* ISPs in the middle of the frame */ + float realBuffer[1][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; /* real buffer */ + float imagBuffer[1][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; /* imag buffer */ + float old_wsp[1][L_WSP]; /* old weighted input signal */ + float pitch_fr[1][NB_SUBFR]; /* fractional pitch values */ + float voicing_fr[1][NB_SUBFR]; /* fractional pitch gains */ + float cor_map_sum[1]; /* speech/music clasif. parameter */ + float enerBuffer[1][CLDFB_NO_CHANNELS_MAX]; /* energy buffer */ + float currFlatness[1]; /* flatness parameter */ + float fft_buff[1][2 * L_FFT]; /* FFT buffer */ + float fr_bands[1][2 * NB_BANDS]; /* energy in frequency bands */ + float Etot_LR[1]; /* total energy */ + float lf_E[1][2 * VOIC_BINS]; /* per bin spectrum energy in lf */ +#endif + Word16 old_inp_12k8_fx[1][L_INP_12k8]; /* buffer of input signal @ 12k8 */ + Word16 vad_hover_flag[1]; /* VAD hangover flag */ + Word16 attack_flag[1]; /* attack flag (GSC or TC) */ + Word16 loc_harm[1]; /* harmonicity flag */ + Word16 vad_flag_dtx[1]; /* HE-SAD flag with additional DTX HO */ + Word16 fft_buff_fx[1][2 * L_FFT]; /* FFT buffer */ + Word16 localVAD_HE_SAD[1]; /* local HE SAD */ + SCE_ENC_HANDLE hSCE; + Encoder_State *st; + IVAS_FORMAT ivas_format; + ivas_error error; + Word16 flag_16k_smc; + + push_wmops( "ivas_sce_enc" ); + + error = IVAS_ERR_OK; + move32(); + + hSCE = st_ivas->hSCE[sce_id]; + st = hSCE->hCoreCoder[0]; + ivas_format = st_ivas->hEncoderConfig->ivas_format; + move32(); + + /*------------------------------------------------------------------* + * Initialization - general + *-----------------------------------------------------------------*/ + Copy32( data_fx, st->input32_fx, input_frame ); // Q(q_data_fx) + Copy_Scale_sig32_16( st->input32_fx, st->input_fx, input_frame, sub( Q16 - 1, q_data_fx ) ); // Q(q_data_fx) -> Q(-1) + +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + fixedToFloat_arrL( st->input32_fx, st->input, q_data_fx, input_frame ); +#endif + + st->element_mode = IVAS_SCE; + move16(); + + /*------------------------------------------------------------------* + * SCE initialization - core coder + *-----------------------------------------------------------------*/ + + st->idchan = 0; + st->core = -1; + st->core_brate = -1; /* updated in dtx() */ + st->max_bwidth = st_ivas->hEncoderConfig->max_bwidth; + st->input_bwidth = st->last_input_bwidth; /* updated in BWD */ + st->bwidth = st->last_bwidth; /* updated in BWD */ + st->rate_switching_reset = 0; + move16(); + move16(); + move32(); + move16(); + move16(); + move16(); + move16(); + + /*---------------------------------------------------------------* + * Time Domain Transient Detector + *---------------------------------------------------------------*/ + test(); + IF( NE_32( ivas_format, MC_FORMAT ) || NE_32( st_ivas->mc_mode, MC_MODE_PARAMMC ) ) + { + RunTransientDetection_ivas_fx( st->input_fx, input_frame, st->hTranDet ); + st->hTranDet->subblockEnergies.subblockNrg_e = 31 - Q7; + st->hTranDet->subblockEnergies.accSubblockNrg_e = 31 - Q7; + move16(); + move16(); + } + + Word16 tmp = GetTCXAvgTemporalFlatnessMeasure_fx( (const TransientDetection *) st->hTranDet, NSUBBLOCKS, 0 ); +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + currFlatness[0] = me2f_16( tmp, 15 - Q7 ); +#endif + + /*----------------------------------------------------------------* + * Configuration of core encoder + *----------------------------------------------------------------*/ + + /* Force to MODE1 in IVAS */ + st->codec_mode = MODE1; + move16(); + + /* set "bits_frame_nominal" */ + test(); + IF( st_ivas->hQMetaData != NULL && st_ivas->hSpar == NULL ) + { + test(); + test(); + IF( ( EQ_32( st_ivas->mc_mode, MC_MODE_MCMASA ) && GE_32( st_ivas->hEncoderConfig->ivas_total_brate, MCMASA_SEPARATE_BRATE ) ) || GE_32( st_ivas->ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) ) + { + st->bits_frame_nominal = extract_l( Mpy_32_32( hSCE->element_brate, ONE_BY_FRAMES_PER_SEC_Q31 ) ); + move16(); + } + ELSE + { + st->bits_frame_nominal = st_ivas->hQMetaData->bits_frame_nominal; + move16(); + } + } + ELSE IF( st_ivas->hSpar != NULL ) + { + st->bits_frame_nominal = extract_l( Mpy_32_32( st_ivas->hSpar->core_nominal_brate, ONE_BY_FRAMES_PER_SEC_Q31 ) ); + move16(); + } + ELSE + { + st->bits_frame_nominal = sub( extract_l( Mpy_32_32( hSCE->element_brate, ONE_BY_FRAMES_PER_SEC_Q31 ) ), ISM_NB_BITS_METADATA_NOMINAL ); + move16(); + } + + /* set "total_brate" */ + st->total_brate = L_sub( hSCE->element_brate, L_mult0( nb_bits_metadata, FRAMES_PER_SEC ) ); + move32(); + + /* set flag for sampling rate of OL S/M classifier */ + flag_16k_smc = 0; + move16(); + test(); + test(); + test(); + if ( EQ_32( st_ivas->hEncoderConfig->ivas_format, SBA_FORMAT ) && ( EQ_32( st_ivas->hEncoderConfig->ivas_total_brate, IVAS_24k4 ) || EQ_32( st_ivas->hEncoderConfig->ivas_total_brate, IVAS_32k ) ) && EQ_32( hSCE->element_brate, hSCE->last_element_brate ) ) + { + flag_16k_smc = 1; + move16(); + } + +#ifdef DEBUG_MODE_INFO + dbgwrite( st->input - NS2SA( st->input_Fs, ACELP_LOOK_NS ), sizeof( float ), input_frame, 1, "res/input_DMX" ); + dbgwrite( &st->element_mode, sizeof( int16_t ), 1, input_frame, fname( debug_dir, "element_mode", 0, st->id_element, ENC ) ); +#endif + + + /*----------------------------------------------------------------* + * Front Pre-processing + *----------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED + error = pre_proc_front_ivas_fx( hSCE, NULL, hSCE->element_brate, nb_bits_metadata, input_frame, 0, old_inp_12k8_fx[0], old_inp_12k8[0], old_inp_16k[0], + &ener[0], &relE[0], A[0], Aw[0], epsP[0], lsp_new[0], lsp_mid[0], &vad_hover_flag[0], &attack_flag[0], + realBuffer[0], imagBuffer[0], old_wsp[0], pitch_fr[0], voicing_fr[0], &loc_harm[0], &cor_map_sum[0], &vad_flag_dtx[0], enerBuffer[0], + fft_buff[0], fft_buff_fx[0], A[0], lsp_new[0], currFlatness[0], 0, fr_bands, Etot_LR, lf_E, localVAD_HE_SAD, NULL, flag_16k_smc, + st_ivas->hSpar != NULL ? st_ivas->hSpar->front_vad_flag : 0, st_ivas->hSpar != NULL ? st_ivas->hSpar->force_front_vad : 0, st_ivas->hSpar != NULL ? st_ivas->hSpar->front_vad_dtx_flag : 0, ivas_format, 0, st_ivas->hEncoderConfig->ivas_total_brate ); +#else + error = pre_proc_front_ivas( hSCE, NULL, hSCE->element_brate, nb_bits_metadata, input_frame, 0, old_inp_12k8[0], old_inp_16k[0], + &ener[0], &relE[0], A[0], Aw[0], epsP[0], lsp_new[0], lsp_mid[0], &vad_hover_flag[0], &attack_flag[0], + realBuffer[0], imagBuffer[0], old_wsp[0], pitch_fr[0], voicing_fr[0], &loc_harm[0], &cor_map_sum[0], &vad_flag_dtx[0], enerBuffer[0], + fft_buff[0], A[0], lsp_new[0], currFlatness[0], 0, fr_bands, Etot_LR, lf_E, localVAD_HE_SAD, NULL, flag_16k_smc, + st_ivas->hSpar != NULL ? st_ivas->hSpar->front_vad_flag : 0, st_ivas->hSpar != NULL ? st_ivas->hSpar->force_front_vad : 0, st_ivas->hSpar != NULL ? st_ivas->hSpar->front_vad_dtx_flag : 0, ivas_format, 0, st_ivas->hEncoderConfig->ivas_total_brate ); +#endif + IF( error != IVAS_ERR_OK ) + { + return error; + } + + /* sanity check -> DTX not supported for more than one SCEs/CPEs */ + IF( sub( add( st_ivas->nSCE, st_ivas->nCPE ), 1 ) > 0 ) + { + test(); + IF( EQ_32( st->core_brate, SID_2k40 ) || st->core_brate == FRAME_NO_DATA ) + { + st->core_brate = -1; + st->total_brate = L_sub( hSCE->element_brate, L_mult0( nb_bits_metadata, FRAMES_PER_SEC ) ); + move32(); + move32(); + } + } + + /*----------------------------------------------------------------* + * Reset metadata + *----------------------------------------------------------------*/ + + reset_metadata_spatial_fx( ivas_format, hSCE->hMetaData, hSCE->element_brate, &st->total_brate, st->core_brate, nb_bits_metadata ); + + /*----------------------------------------------------------------* + * Combined format coding: get the ISM importance and the bit-rate + *----------------------------------------------------------------*/ + test(); + IF( EQ_32( ivas_format, MASA_ISM_FORMAT ) && EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) ) + { + st_ivas->hMasa->data.hOmasaData->lp_noise_CPE_fx = 0; + move16(); + ivas_set_ism_importance_interformat_fx( hSCE->element_brate, 1, st_ivas->hIsmMetaData, st_ivas->hSCE, st_ivas->hMasa->data.hOmasaData->lp_noise_CPE_fx, &st_ivas->hIsmMetaData[0]->ism_imp ); + + st->total_brate = L_sub( ivas_interformat_brate_fx( ISM_MASA_MODE_PARAM_ONE_OBJ, 1, hSCE->element_brate, st_ivas->hIsmMetaData[0]->ism_imp, 0 ), L_mult0( nb_bits_metadata, FRAMES_PER_SEC ) ); + move32(); + } + + /*----------------------------------------------------------------* + * Write IVAS format signaling in SID frames + *----------------------------------------------------------------*/ + + IF( EQ_32( st->core_brate, SID_2k40 ) ) + { + ivas_write_format_sid_fx( ivas_format, IVAS_SCE, st->hBstr ); + } + + /*----------------------------------------------------------------* + * Core codec configuration + *----------------------------------------------------------------*/ + + /* IGF reconfiguration */ + test(); + IF( hSCE->last_element_brate != hSCE->element_brate || st->last_bwidth != st->bwidth ) + { + Word16 igf; + igf = getIgfPresent_fx( st->element_mode, L_mult0( st->bits_frame_nominal, FRAMES_PER_SEC ), st->max_bwidth, st->rf_mode ); + IF( NE_32( ( error = IGF_Reconfig_fx( &st->hIGFEnc, igf, 0, L_mult0( st->bits_frame_nominal, FRAMES_PER_SEC ), st->max_bwidth, st->element_mode, st->rf_mode ) ), IVAS_ERR_OK ) ) + { + return error; + } + } + + /* set ACELP@12k8 / ACELP@16k flag for flexible ACELP core */ + test(); + test(); + IF( st->core_brate == SID_2k40 || st->core_brate == FRAME_NO_DATA ) + { + st->flag_ACELP16k = set_ACELP_flag_IVAS( IVAS_SCE, hSCE->element_brate, st->core_brate, 0, 0, -1, -1 ); + } + ELSE IF( EQ_16( st_ivas->ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) && st->low_rate_mode ) + { + st->flag_ACELP16k = 0; + } + ELSE + { + st->flag_ACELP16k = set_ACELP_flag_IVAS( IVAS_SCE, hSCE->element_brate, st->total_brate, 0, 0, -1, -1 ); + } + move16(); + + /* modify the coder_type depending on the total_brate per channel */ + coder_type_modif( st, relE[0] ); + + /*----------------------------------------------------------------* + * Encoder + *----------------------------------------------------------------*/ + + IF( ( error = ivas_core_enc( hSCE, NULL, NULL, 1, old_inp_12k8, old_inp_16k, ener, A, Aw, epsP, lsp_new, lsp_mid, vad_hover_flag, attack_flag, realBuffer, imagBuffer, old_wsp, loc_harm, cor_map_sum, vad_flag_dtx, enerBuffer, fft_buff, 0, ivas_format, flag_16k_smc ) ) != IVAS_ERR_OK ) + { + return error; + } + + /*----------------------------------------------------------------* + * Common updates + *----------------------------------------------------------------*/ + + /* update input samples buffer */ + mvr2r( st->input, st->old_input_signal, input_frame ); + + hSCE->last_element_brate = hSCE->element_brate; + move32(); + + /* Store previous attack detection flag */ + st->hTranDet->transientDetector.prev_bIsAttackPresent = st->hTranDet->transientDetector.bIsAttackPresent; + move16(); + +#ifdef DEBUG_MODE_INFO + { + float tmpF = hSCE->element_brate / 1000.0f; + dbgwrite( &tmpF, sizeof( float ), 1, input_frame, fname( debug_dir, "element_brate", 0, sce_id, ENC ) ); + } +#endif + + + pop_wmops(); + + return error; +} +#else ivas_error ivas_sce_enc( Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ const int16_t sce_id, /* i : SCE # identifier */ @@ -66,19 +365,19 @@ ivas_error ivas_sce_enc( const int16_t nb_bits_metadata /* i : number of metadata bits */ ) { -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS // required for float to fix conversion - float old_inp_12k8[1][L_INP_12k8] = { 0 }; /* buffer of input signal @ 12k8 */ - float old_inp_16k[1][L_INP] = { 0 }; /* buffer of input signal @ 16kHz */ - Word16 old_inp_12k8_fx[1][L_INP_12k8]; /* buffer of input signal @ 12k8 */ +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS // required for float to fix conversion + float old_inp_12k8[1][L_INP_12k8] = { 0 }; /* buffer of input signal @ 12k8 */ + float old_inp_16k[1][L_INP] = { 0 }; /* buffer of input signal @ 16kHz */ + Word16 old_inp_12k8_fx[1][L_INP_12k8]; /* buffer of input signal @ 12k8 */ #else float old_inp_12k8[1][L_INP_12k8]; /* buffer of input signal @ 12k8 */ float old_inp_16k[1][L_INP]; /* buffer of input signal @ 16kHz */ #endif - float ener[1]; /* residual energy from Levinson-Durbin */ - float relE[1]; /* frame relative energy */ -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS // required for float to fix conversion - float A[1][NB_SUBFR16k * ( M + 1 )] = { 0 }; /* A(z) unquantized for subframes */ - float Aw[1][NB_SUBFR16k * ( M + 1 )] = { 0 }; /* weighted A(z) unquantized for subframes */ + float ener[1]; /* residual energy from Levinson-Durbin */ + float relE[1]; /* frame relative energy */ +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS // required for float to fix conversion + float A[1][NB_SUBFR16k * ( M + 1 )] = { 0 }; /* A(z) unquantized for subframes */ + float Aw[1][NB_SUBFR16k * ( M + 1 )] = { 0 }; /* weighted A(z) unquantized for subframes */ #else float A[1][NB_SUBFR16k * ( M + 1 )]; /* A(z) unquantized for subframes */ float Aw[1][NB_SUBFR16k * ( M + 1 )]; /* weighted A(z) unquantized for subframes */ @@ -365,14 +664,14 @@ ivas_error ivas_sce_enc( return error; } - +#endif /*------------------------------------------------------------------------- * create_sce_enc() * * Create, allocate and initialize IVAS encoder SCE handle *-------------------------------------------------------------------------*/ - +#ifndef IVAS_FLOAT_FIXED ivas_error create_sce_enc( Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ const int16_t sce_id, /* i : SCE # identifier */ @@ -448,7 +747,7 @@ ivas_error create_sce_enc( return error; } -#ifdef IVAS_FLOAT_FIXED +#else ivas_error create_sce_enc_fx( Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ const Word16 sce_id, /* i : SCE # identifier */ @@ -461,6 +760,7 @@ ivas_error create_sce_enc_fx( ivas_error error; error = IVAS_ERR_OK; + move32(); /*-----------------------------------------------------------------* * Allocate SCE handle @@ -478,11 +778,14 @@ ivas_error create_sce_enc_fx( hSCE->sce_id = sce_id; hSCE->element_brate = element_brate; hSCE->last_element_brate = hSCE->element_brate; + move16(); + move32(); + move32(); /*-----------------------------------------------------------------* * Metadata: allocate and initialize *-----------------------------------------------------------------*/ - + test(); IF( NE_16( st_ivas->hEncoderConfig->ivas_format, MONO_FORMAT ) && EQ_16( sce_id, sub( st_ivas->nSCE, 1 ) ) ) { IF( ( error = ivas_initialize_MD_bstr_enc( &( hSCE->hMetaData ), st_ivas ) ) != IVAS_ERR_OK ) @@ -506,13 +809,19 @@ ivas_error create_sce_enc_fx( copy_encoder_config_fx( st_ivas, st, 1 ); + test(); + test(); + test(); IF( EQ_16( st_ivas->hEncoderConfig->ivas_format, MASA_ISM_FORMAT ) && ( EQ_16( st_ivas->ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) || EQ_16( st_ivas->ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) || EQ_16( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) ) ) { st->element_mode = IVAS_SCE; + move16(); } st->total_brate = hSCE->element_brate; /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() */ st->mct_chan_mode = MCT_CHAN_MODE_REGULAR; + move32(); + move32(); IF( ( error = init_encoder_ivas_fx( st, st_ivas, 0, st_ivas->hEncoderConfig->var_SID_rate_flag, st_ivas->hEncoderConfig->interval_SID, 0, st_ivas->ism_mode, hSCE->element_brate ) ) != IVAS_ERR_OK ) { @@ -533,9 +842,9 @@ ivas_error create_sce_enc_fx( *-------------------------------------------------------------------------*/ ivas_error create_evs_sce_enc( - Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ - const int16_t sce_id, /* i : SCE # identifier */ - const int32_t element_brate /* i : element bitrate */ + Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ + const Word16 sce_id, /* i : SCE # identifier */ + const Word32 element_brate /* i : element bitrate */ ) { SCE_ENC_HANDLE hSCE = st_ivas->hSCE[sce_id]; @@ -680,7 +989,8 @@ void destroy_sce_enc( IF( st != NULL ) { - IF( EQ_16( st->element_mode, EVS_MONO ) && is_evs ) + test(); + IF( ( st->element_mode == EVS_MONO ) && is_evs ) { destroy_encoder_fx( hSCE->hCoreCoder[0] ); st = NULL; diff --git a/lib_enc/ivas_spar_encoder.c b/lib_enc/ivas_spar_encoder.c index 6e506a125..2d83970c6 100644 --- a/lib_enc/ivas_spar_encoder.c +++ b/lib_enc/ivas_spar_encoder.c @@ -562,19 +562,21 @@ void ivas_spar_enc_close_fx( * Principal IVAS SPAR encoder routine *-------------------------------------------------------------------*/ -ivas_error ivas_spar_enc( - Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ - float *data_f[], /* i/o: input/transport audio channels */ - const int16_t input_frame, /* i : input frame length */ - int16_t *nb_bits_metadata, /* i : number of MD bits written */ - BSTR_ENC_HANDLE hMetaData /* o : MetaData handle */ +ivas_error ivas_spar_enc_fx( + Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ + Word32 *data_fx[], /* i/o: input/transport audio channel Q11 */ + const Word16 input_frame, /* i : input frame length */ + Word16 *nb_bits_metadata, /* i : number of MD bits written */ + BSTR_ENC_HANDLE hMetaData /* o : MetaData handle */ ) { ENCODER_CONFIG_HANDLE hEncoderConfig; Encoder_State *st0; /* used for bitstream handling */ ivas_error error; - + Word16 i, q_data = Q11; + move16(); error = IVAS_ERR_OK; + move32(); hEncoderConfig = st_ivas->hEncoderConfig; st0 = ( st_ivas->nSCE > 0 ) ? st_ivas->hSCE[0]->hCoreCoder[0] : st_ivas->hCPE[0]->hCoreCoder[0]; @@ -610,34 +612,21 @@ ivas_error ivas_spar_enc( push_indice( hMetaData, IND_ISM_NUM_OBJECTS, hEncoderConfig->nchan_ism - 1, NO_BITS_MASA_ISM_NO_OBJ ); } /* front VAD */ - if ( ( error = front_vad_spar( st_ivas->hSpar, data_f[0], hEncoderConfig, input_frame ) ) != IVAS_ERR_OK ) + IF( ( error = front_vad_spar_fx( st_ivas->hSpar, data_fx[0], hEncoderConfig, input_frame ) ) != IVAS_ERR_OK ) { return error; } - if ( hEncoderConfig->sba_planar ) - { - ivas_sba_zero_vert_comp( data_f, st_ivas->sba_analysis_order, hEncoderConfig->sba_planar, input_frame ); - } -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - Word32 data_fx_arr[MAX_INPUT_CHANNELS + MAX_NUM_OBJECTS][L_FRAME48k]; - Word32 *data_fx[MAX_INPUT_CHANNELS + MAX_NUM_OBJECTS]; - Word16 i, q_data = Q11; - Word16 num_ch = ivas_sba_get_nchan_fx( st_ivas->sba_analysis_order, 0 ); /*planar input arg. deliberately set to zero since input always in ACN/SN3D*/ - for ( i = 0; i < num_ch; i++ ) + IF( hEncoderConfig->sba_planar ) { - data_fx[i] = data_fx_arr[i]; - if ( data_f[i] != NULL ) - { - floatToFixed_arrL( data_f[i], data_fx[i], q_data, input_frame ); - } + ivas_sba_zero_vert_comp_fx( data_fx, st_ivas->sba_analysis_order, hEncoderConfig->sba_planar, input_frame ); } + FOR( i = 0; i < st_ivas->hSpar->hFbMixer->fb_cfg->num_in_chans; i++ ) { scale_sig32( st_ivas->hSpar->hFbMixer->ppFilterbank_prior_input_fx[i], st_ivas->hSpar->hFbMixer->fb_cfg->prior_input_length, sub( q_data, st_ivas->hSpar->hFbMixer->q_ppFilterbank_prior_input_fx[i] ) ); st_ivas->hSpar->hFbMixer->q_ppFilterbank_prior_input_fx[i] = q_data; } -#endif /* SPAR encoder */ IF( NE_32( ( error = ivas_spar_enc_process_fx( st_ivas, hEncoderConfig, hMetaData, st_ivas->hSpar->front_vad_flag, data_fx, q_data ) ), IVAS_ERR_OK ) ) @@ -645,16 +634,6 @@ ivas_error ivas_spar_enc( return error; } -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - for ( i = 0; i < num_ch; i++ ) - { - if ( data_f[i] != NULL ) - { - fixedToFloat_arrL( data_fx[i], data_f[i], q_data, input_frame ); - } - } -#endif - *nb_bits_metadata = hMetaData->nb_bits_tot; /* Force IVAS front pre-proc decision for higher bitrates */ diff --git a/lib_enc/ivas_stat_enc.h b/lib_enc/ivas_stat_enc.h index da7514f9d..ce900485d 100644 --- a/lib_enc/ivas_stat_enc.h +++ b/lib_enc/ivas_stat_enc.h @@ -668,7 +668,9 @@ typedef struct stereo_icbwe_enc_data_structure int16_t refChanIndx_bwe; /* SHB speech resampler memory */ float memHPF[8]; +#ifndef IVAS_FLOAT_FIXED float mem_decim_shb_ch0[2 * L_FILT_MAX]; +#endif /* SHB speech non-ref channel */ float mem_shb_speech_ref[L_LOOK_16k]; @@ -678,14 +680,16 @@ typedef struct stereo_icbwe_enc_data_structure float mem_lpc_shbsynth_nonref[LPC_SHB_ORDER]; /* inter-channel BWE spectral shape adj. */ +#ifndef IVAS_FLOAT_FIXED float prevSpecMapping; + float prevgsMapping; +#endif float memShbSpecMapping; float memShbSpecXcorr[6]; - float prevgsMapping; - +#ifndef IVAS_FLOAT_FIXED float prevRefEner; float prevNonRefEner; - +#endif float memGsEnerMap[2]; float dec_2over3_mem[L_FILT_2OVER3]; @@ -698,8 +702,8 @@ typedef struct stereo_icbwe_enc_data_structure float mem_nrg_R[CPE_CHANNELS]; float mem_nrg_DMX[CPE_CHANNELS]; #endif - float gDes_pastFrame; - float icbweRefEner; + // float gDes_pastFrame; + // float icbweRefEner; float shbSynthRef[L_FRAME16k]; float nlExc16k[L_FRAME16k]; diff --git a/lib_enc/ivas_stereo_dft_enc.c b/lib_enc/ivas_stereo_dft_enc.c index bf03b2825..52c669b13 100644 --- a/lib_enc/ivas_stereo_dft_enc.c +++ b/lib_enc/ivas_stereo_dft_enc.c @@ -626,6 +626,7 @@ ivas_error stereo_dft_enc_create_fx( } hStereoDft_loc->hConfig->force_mono_transmission = 0; + move16(); stereo_dft_config_fx( hStereoDft_loc->hConfig, IVAS_24k4, &tmpS, &tmpS ); @@ -856,18 +857,23 @@ static void stereo_dft_enc_open_fx( /*Sizes*/ hStereoDft->N = extract_l( Mpy_32_32( input_Fs, 42949673 /* STEREO_DFT_HOP_MAX_ENC / 48000 in Q31 */ ) ); // e = div_e + move16(); assert( ( ( input_Fs / FRAMES_PER_SEC ) / hStereoDft->N ) == 1 ); /*Init. DFT sizes*/ // hStereoDft->NFFT = i_mult( STEREO_DFT_N_MAX_ENC, input_Fs_48k ); // e = div_e - hStereoDft->NFFT = extract_l( Mpy_32_32( input_Fs, 85899346 ) ); // e = div_e + hStereoDft->NFFT = extract_l( Mpy_32_32( input_Fs, 85899346 /* STEREO_DFT_N_MAX_ENC / 48000 in Q31 */ ) ); // e = div_e // hStereoDft->dft_ovl = i_mult( STEREO_DFT_OVL_MAX, input_Fs ); // e = div_e - hStereoDft->dft_ovl = extract_l( Mpy_32_32( input_Fs, 18790482 ) ); // e = div_e + hStereoDft->dft_ovl = extract_l( Mpy_32_32( input_Fs, 18790482 /* STEREO_DFT_OVL_MAX / 48000 in Q31 */ ) ); // e = div_e + move16(); + move16(); mdct_window_sine_IVAS_updated( win_p, input_Fs, hStereoDft->dft_ovl, FULL_OVERLAP, IVAS_CPE_DFT ); // win_e = 15 - FOR( Word16 i = 0; i < shr( STEREO_DFT_OVL_MAX, 1 ); i++ ) + FOR( Word16 i = 0; i < ( STEREO_DFT_OVL_MAX / 2 ); i++ ) { win[STEREO_DFT_OVL_MAX - 1 - i] = win_p[i].v.re; win[i] = win_p[i].v.im; + move16(); + move16(); } hStereoDft->win_ana_energy_fx = sub( hStereoDft->N, hStereoDft->dft_ovl ); // e = div_e hStereoDft->win_ana_energy_fx = shr( hStereoDft->win_ana_energy_fx, 15 ); // Q = 15 @@ -875,10 +881,16 @@ static void stereo_dft_enc_open_fx( hStereoDft->win_ana_energy_fx = add( hStereoDft->win_ana_energy_fx, shl( sum_s( win, hStereoDft->dft_ovl ), 1 ) ); // Q = 15 hStereoDft->win_ana_energy_fx = shr( hStereoDft->win_ana_energy_fx, 15 ); hStereoDft->win_ana_energy_fx = div_s( hStereoDft->win_ana_energy_fx, hStereoDft->NFFT ); // Q = 15 + move16(); + move16(); + move16(); + move16(); + move16(); set32_fx( hStereoDft->output_mem_dmx_32k_fx, 0, STEREO_DFT_OVL_32k ); - hStereoDft->dft_zp = (int16_t) ( STEREO_DFT_ZP_MAX_ENC * input_Fs / 48000 ); + hStereoDft->dft_zp = (Word16) ( STEREO_DFT_ZP_MAX_ENC * input_Fs / 48000 ); + move16(); hStereoDft->dft_trigo_8k_fx = dft_trigo_32k_fx; hStereoDft->dft_trigo_12k8_fx = dft_trigo_12k8_fx; @@ -899,6 +911,7 @@ static void stereo_dft_enc_open_fx( { hStereoDft->dft_trigo_fx = dft_trigo_32k_fx; hStereoDft->dft_trigo_step = STEREO_DFT_TRIGO_SRATE_16k_STEP; + move16(); hStereoDft->win_ana_fx = win_ana_16k_fx; hStereoDft->win_fx = win_syn_16k_fx; } @@ -906,6 +919,7 @@ static void stereo_dft_enc_open_fx( { hStereoDft->dft_trigo_fx = dft_trigo_32k_fx; hStereoDft->dft_trigo_step = STEREO_DFT_TRIGO_SRATE_32k_STEP; + move16(); hStereoDft->win_ana_fx = win_ana_32k_fx; hStereoDft->win_fx = win_syn_32k_fx; } @@ -914,6 +928,7 @@ static void stereo_dft_enc_open_fx( assert( EQ_32( input_Fs, 48000 ) ); hStereoDft->dft_trigo_fx = dft_trigo_48k_fx; hStereoDft->dft_trigo_step = STEREO_DFT_TRIGO_SRATE_48k_STEP; + move16(); hStereoDft->win_ana_fx = win_ana_48k_fx; hStereoDft->win_fx = win_syn_48k_fx; } @@ -932,9 +947,12 @@ static void stereo_dft_enc_open_fx( NFFT_inner = imult1616( inner_frame_tbl[max_bwidth], STEREO_DFT_N_MAX_ENC / L_FRAME48k ); hStereoDft->nbands = stereo_dft_band_config_fx( hStereoDft->band_limits, hStereoDft->hConfig->band_res, NFFT_inner, ENC ); hStereoDft->nbands_dmx = stereo_dft_band_config_fx( hStereoDft->band_limits_dmx, 1, NFFT_inner, ENC ); + move16(); + move16(); /*Set configuration*/ set16_fx( hStereoDft->band_res, hStereoDft->hConfig->band_res, STEREO_DFT_ENC_DFT_NB ); + test(); IF( hStereoDft->hConfig->ada_wb_res_cod_mode && EQ_16( hStereoDft->NFFT, STEREO_DFT_N_16k_ENC ) ) { /* residual coding is only applied for 16 kHz sampling rate */ diff --git a/lib_enc/ivas_stereo_dft_enc_itd.c b/lib_enc/ivas_stereo_dft_enc_itd.c index effd61ed8..d19c753c8 100644 --- a/lib_enc/ivas_stereo_dft_enc_itd.c +++ b/lib_enc/ivas_stereo_dft_enc_itd.c @@ -155,13 +155,18 @@ void stereo_dft_hybrid_ITD_flag( { IF( hConfig != NULL ) { + test(); + test(); + test(); IF( hConfig->res_cod_mode || ( hConfig->ada_wb_res_cod_mode && EQ_32( input_Fs, 16000 ) ) || EQ_16( hybrid_itd_max, 1 ) ) { hConfig->hybrid_itd_flag = 1; + move16(); } ELSE { hConfig->hybrid_itd_flag = 0; + move16(); } } ELSE diff --git a/lib_enc/ivas_stereo_icbwe_enc.c b/lib_enc/ivas_stereo_icbwe_enc.c index 63a5f0e11..ca51393e1 100644 --- a/lib_enc/ivas_stereo_icbwe_enc.c +++ b/lib_enc/ivas_stereo_icbwe_enc.c @@ -1571,7 +1571,7 @@ void stereo_icBWE_init_enc( ) { /* SHB speech resampler memory */ - set_f( hStereoICBWE->mem_decim_shb_ch0, 0, ( 2 * L_FILT_MAX ) ); + // set_f( hStereoICBWE->mem_decim_shb_ch0, 0, ( 2 * L_FILT_MAX ) ); /* SHB ref channel */ set_f( hStereoICBWE->mem_shb_speech_ref, 0, L_LOOK_16k ); @@ -1583,15 +1583,15 @@ void stereo_icBWE_init_enc( set_f( hStereoICBWE->mem_lpc_shbsynth_nonref, 0, LPC_SHB_ORDER ); /* inter-channel BWE spectral shape adj. */ - hStereoICBWE->prevSpecMapping = 0; - hStereoICBWE->prevgsMapping = 1.0f; + // hStereoICBWE->prevSpecMapping = 0; + // hStereoICBWE->prevgsMapping = 1.0f; set_f( &( hStereoICBWE->memShbSpecMapping ), 0, 1 ); set_f( hStereoICBWE->memShbSpecXcorr, 0, 6 ); - hStereoICBWE->prevNonRefEner = 1.0f; - hStereoICBWE->prevRefEner = 1.0f; + // hStereoICBWE->prevNonRefEner = 1.0f; + // hStereoICBWE->prevRefEner = 1.0f; - set_f( hStereoICBWE->memGsEnerMap, 1.0f, 2 ); + // set_f( hStereoICBWE->memGsEnerMap, 1.0f, 2 ); set_f( hStereoICBWE->dec_2over3_mem, 0, L_FILT_2OVER3 ); set_f( hStereoICBWE->dec_2over3_mem_lp, 0, L_FILT_2OVER3_LP ); @@ -1613,8 +1613,8 @@ void stereo_icBWE_init_enc( set_f( hStereoICBWE->mem_nrg_R, 0, 2 ); set_f( hStereoICBWE->mem_nrg_DMX, 0, 2 ); #endif - hStereoICBWE->gDes_pastFrame = 1.0f; - hStereoICBWE->icbweRefEner = 0.0f; + // hStereoICBWE->gDes_pastFrame = 1.0f; + // hStereoICBWE->icbweRefEner = 0.0f; hStereoICBWE->MSFlag = 0; return; diff --git a/lib_enc/ivas_stereo_switching_enc.c b/lib_enc/ivas_stereo_switching_enc.c index e6c8341a8..3a3c6c0bb 100644 --- a/lib_enc/ivas_stereo_switching_enc.c +++ b/lib_enc/ivas_stereo_switching_enc.c @@ -695,8 +695,11 @@ ivas_error stereo_memory_enc_fx( { return error; } - +#ifdef IVAS_FLOAT_FIXED + initFdCngEnc_fx( st->hFdCngEnc, st->input_Fs, st->cldfbAnaEnc->scale ); +#else initFdCngEnc( st->hFdCngEnc, st->input_Fs, st->cldfbAnaEnc->scale_flt ); +#endif configureFdCngEnc( st->hFdCngEnc, st->bwidth, st->rf_mode && st->total_brate == ACELP_13k20 ? ACELP_9k60 : st->total_brate ); } } diff --git a/lib_enc/ivas_stereo_td_enc.c b/lib_enc/ivas_stereo_td_enc.c index 346c78d63..01737ac5b 100644 --- a/lib_enc/ivas_stereo_td_enc.c +++ b/lib_enc/ivas_stereo_td_enc.c @@ -1769,7 +1769,7 @@ void stereo_tdm_prep_dwnmx_fx( mener = Sqrt32( mener, &mener_e ); test(); test(); - IF( LT_32( mener, L_shl( 10, sub( 31, mener_e ) ) ) && ( sts[1]->vad_flag == 0 || EQ_16( sts[1]->coder_type_raw, UNVOICED ) ) ) + IF( ( BASOP_Util_Cmp_Mant32Exp( mener, mener_e, 10, Q31 ) < 0 ) && ( sts[1]->vad_flag == 0 || EQ_16( sts[1]->coder_type_raw, UNVOICED ) ) ) { hCPE->hStereoTD->flag_skip_DMX = 0; /* Can start using the TD downmix whenever the right channel is sufficiently low energy to limit switching artefacts */ move16(); diff --git a/lib_enc/lib_enc.c b/lib_enc/lib_enc.c index a8130236d..7d7617431 100644 --- a/lib_enc/lib_enc.c +++ b/lib_enc/lib_enc.c @@ -1875,7 +1875,7 @@ ivas_error IVAS_ENC_EncodeFrameToSerial( } ELSE /* IVAS */ { - IF( NE_32( ( error = ivas_enc( st_ivas, inputBuffer, inputBufferSize ) ), IVAS_ERR_OK ) ) + IF( NE_32( ( error = ivas_enc_fx( st_ivas, inputBuffer, inputBufferSize ) ), IVAS_ERR_OK ) ) { return error; } diff --git a/lib_enc/stat_enc.h b/lib_enc/stat_enc.h index 0f9646cac..c3573d64a 100644 --- a/lib_enc/stat_enc.h +++ b/lib_enc/stat_enc.h @@ -511,8 +511,8 @@ typedef struct td_cng_enc_structure typedef struct fd_cng_enc_structure { HANDLE_FD_CNG_COM hFdCngCom; +#ifndef IVAS_FLOAT_FIXED float msPeriodog[NPART]; /* Periodogram */ -#if 1 // ndef IVAS_FLOAT_FIXED to be disabled float msBminWin[NPART]; float msBminSubWin[NPART]; float msPsd[NPART]; /* Power Spectral Density estimate (i.e., smoothed periodogram) */ @@ -521,6 +521,10 @@ typedef struct fd_cng_enc_structure float msCurrentMinOut[NPART]; float msCurrentMin[NPART]; float msCurrentMinSubWindow[NPART]; + float msPsdFirstMoment[NPART]; + float msPsdSecondMoment[NPART]; + float msNoiseFloor[NPART]; /* Estimated noise floor */ + float msNoiseEst[NPART]; /* Estimated noise level */ #endif Word32 msPeriodog_fx[NPART]; /* Periodogram */ Word16 msPeriodog_fx_exp; /* Common exponent for fft and cldfb energies */ @@ -535,40 +539,36 @@ typedef struct fd_cng_enc_structure Word32 msCurrentMin_fx[NPART]; Word32 msCurrentMinSubWindow_fx[NPART]; - int16_t msLocalMinFlag[NPART]; - int16_t msNewMinFlag[NPART]; -#if 1 // ndef IVAS_FLOAT_FIXED to be disabled - float msPsdFirstMoment[NPART]; - float msPsdSecondMoment[NPART]; - float msNoiseFloor[NPART]; /* Estimated noise floor */ -#endif - float msNoiseEst[NPART]; /* Estimated noise level */ - float energy_ho[NPART]; + Word16 msLocalMinFlag[NPART]; + Word16 msNewMinFlag[NPART]; + Word16 msPsdFirstMoment_fx[NPART]; + Word32 msPsdSecondMoment_fx[NPART]; + Word16 msNoiseFloor_fx[NPART]; /* Estimated noise floor */ +#ifndef IVAS_FLOAT_FIXED float msNoiseEst_old[NPART]; -#if 1 // ndef IVAS_FLOAT_FIXED to be disabled + float energy_ho[NPART]; float msLogPeriodog[NPART]; /* Periodogram */ float msLogNoiseEst[NPART]; /* Estimated noise level */ #endif - Word16 msPsdFirstMoment_fx[NPART]; - Word32 msPsdSecondMoment_fx[NPART]; - Word16 msNoiseFloor_fx[NPART]; /* Estimated noise floor */ - Word32 msNoiseEst_fx[NPART]; /* Estimated noise level */ + Word32 msNoiseEst_fx[NPART]; /* Estimated noise level */ Word16 msNoiseEst_fx_exp; Word32 energy_ho_fx[NPART]; Word16 energy_ho_fx_exp; Word32 msNoiseEst_old_fx[NPART]; Word16 msNoiseEst_old_fx_exp; +#ifndef IVAS_FLOAT_FIXED float msPeriodogBuf[MSBUFLEN * NPART]; +#endif Word16 msPeriodogBuf_fx[MSBUFLEN * NPART]; - int16_t msPeriodogBufPtr; + Word16 msPeriodogBufPtr; - int16_t stopFFTbinDec; - int16_t startBandDec; - int16_t stopBandDec; - int16_t npartDec; - int16_t midbandDec[NPART]; - int16_t nFFTpartDec; - int16_t partDec[NPART]; + Word16 stopFFTbinDec; + Word16 startBandDec; + Word16 stopBandDec; + Word16 npartDec; + Word16 midbandDec[NPART]; + Word16 nFFTpartDec; + Word16 partDec[NPART]; Word16 msLogPeriodog_fx[NPART]; @@ -581,50 +581,7 @@ typedef struct fd_cng_enc_structure Word16 mem_coherence_exp[4]; } FD_CNG_ENC, *HANDLE_FD_CNG_ENC; -// typedef struct -//{ -// HANDLE_FD_CNG_COM hFdCngCom; -// -// Word32 msPeriodog[NPART]; /* Periodogram */ -// Word16 msPeriodog_exp; /* Common exponent for fft and cldfb energies */ -// Word16 msPeriodog_exp_fft; -// Word16 msPeriodog_exp_cldfb; -// Word32 msBminWin[NPART]; -// Word32 msBminSubWin[NPART]; -// Word16 msPsd[NPART]; /* Power Spectral Density estimate (i.e., smoothed periodogram) */ -// Word32 msAlpha[NPART]; /* Optimal smoothing parameter */ -// Word32 msMinBuf[MSNUMSUBFR*NPART]; /* Buffer of minima */ -// Word32 msCurrentMinOut[NPART]; -// Word32 msCurrentMin[NPART]; -// Word32 msCurrentMinSubWindow[NPART]; -// Word16 msLocalMinFlag[NPART]; -// Word16 msNewMinFlag[NPART]; -// Word16 msPsdFirstMoment[NPART]; -// Word32 msPsdSecondMoment[NPART]; -// Word16 msNoiseFloor[NPART]; /* Estimated noise floor */ -// Word32 msNoiseEst[NPART]; /* Estimated noise level */ -// Word16 msNoiseEst_exp; -// Word32 energy_ho[NPART]; -// Word16 energy_ho_exp; -// Word32 msNoiseEst_old[NPART]; -// Word16 msNoiseEst_old_exp; -// -// Word16 msPeriodogBuf[MSBUFLEN*NPART]; -// Word16 msPeriodogBufPtr; -// -// Word16 stopFFTbinDec; -// Word16 startBandDec; -// Word16 stopBandDec; -// Word16 npartDec; -// Word16 midbandDec[NPART]; -// Word16 nFFTpartDec; -// Word16 partDec[NPART]; -// -// Word16 msLogPeriodog[NPART]; -// Word16 msLogNoiseEst[NPART]; -// } -// FD_CNG_ENC_FX; -// typedef FD_CNG_ENC_FX *HANDLE_FD_CNG_ENC_FX; + /*------------------------------------------------------------------------------------------* * Structure for DTX-related variables used in both FD- and TD-CNG *------------------------------------------------------------------------------------------*/ @@ -1213,25 +1170,27 @@ typedef struct gsc_enc_structure typedef struct hq_enc_structure { - int16_t mode_count; /* HQ_HARMONIC mode count */ - int16_t mode_count1; /* HQ_NORMAL mode count */ - int16_t prev_Npeaks; /* number of peaks in previous frame */ - int16_t prev_peaks[HVQ_MAX_PEAKS]; /* indices of the peaks in previous frame */ - int16_t hvq_hangover; - int16_t prev_hqswb_clas; - int16_t prev_SWB_peak_pos[SPT_SHORTEN_SBNUM]; - - int16_t hq_generic_speech_class; + Word16 mode_count; /* HQ_HARMONIC mode count */ + Word16 mode_count1; /* HQ_NORMAL mode count */ + Word16 prev_Npeaks; /* number of peaks in previous frame */ + Word16 prev_peaks[HVQ_MAX_PEAKS]; /* indices of the peaks in previous frame */ + Word16 hvq_hangover; + Word16 prev_hqswb_clas; + Word16 prev_SWB_peak_pos[SPT_SHORTEN_SBNUM]; + + Word16 hq_generic_speech_class; +#ifndef IVAS_FLOAT_FIXED float crest_lp; /* Low-pass filtered crest of high band */ float crest_mod_lp; /* Low-pass filtered noise band detection */ +#endif Word32 crest_lp_fx; Word16 crest_lp_q; Word32 crest_mod_lp_fx; Word16 crest_mod_lp_q; /* SWB BWE LR classification */ - int16_t prev_frm_index[NB_SWB_SUBBANDS_HAR_SEARCH_SB]; - int16_t prev_frm_hfe2; - int16_t prev_stab_hfe2; + Word16 prev_frm_index[NB_SWB_SUBBANDS_HAR_SEARCH_SB]; + Word16 prev_frm_hfe2; + Word16 prev_stab_hfe2; #ifndef IVAS_FLOAT_FIXED float prev_ni_ratio; float prev_En_sb[NB_SWB_SUBBANDS]; @@ -1240,7 +1199,7 @@ typedef struct hq_enc_structure Word16 prev_En_sb_fx[NB_SWB_SUBBANDS]; /* QsEn(4) */ #endif - int16_t last_bitalloc_max_band[2]; + Word16 last_bitalloc_max_band[2]; #ifndef IVAS_FLOAT_FIXED float last_ni_gain[BANDS_MAX]; float last_env[BANDS_MAX]; @@ -1248,7 +1207,7 @@ typedef struct hq_enc_structure Word32 last_ni_gain_fx[BANDS_MAX]; /* Q17 */ Word16 last_env_fx[BANDS_MAX]; /* Q1 */ #endif - int16_t last_max_pos_pulse; + Word16 last_max_pos_pulse; } HQ_ENC_DATA, *HQ_ENC_HANDLE; @@ -1442,13 +1401,13 @@ typedef struct amrwb_io_enc_structure typedef struct td_bwe_enc_structure { #ifndef IVAS_FLOAT_FIXED - float old_speech_shb[L_LOOK_16k + L_SUBFR16k]; /* Buffer memories */ + float old_speech_shb[L_LOOK_16k + L_SUBFR16k]; /* Buffer memories */ + float old_speech_wb[( L_LOOK_12k8 + L_SUBFR ) * 5 / 16]; /* Buffer memories */ #else Word16 old_speech_shb_fx[L_LOOK_16k + L_SUBFR16k]; /* Buffer memories Q(Q_shb_spch) */ + Word16 old_speech_wb_fx[( L_LOOK_12k8 + L_SUBFR ) * 5 / 16]; /* Buffer memories Q(-1) */ #endif - float old_speech_wb[( L_LOOK_12k8 + L_SUBFR ) * 5 / 16]; /* Buffer memories */ float old_input_fhb[NS2SA( 48000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_12k8_NS + DELAY_FIR_RESAMPL_NS ) - L_FRAME48k / 2]; - Word16 old_speech_wb_fx[( L_LOOK_12k8 + L_SUBFR ) * 5 / 16]; /* Buffer memories */ Word16 old_input_fhb_fx[NS2SA( 48000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_12k8_NS + DELAY_FIR_RESAMPL_NS ) - L_FRAME48k / 2]; Word16 old_input_fhb_fx_Q; @@ -1462,8 +1421,11 @@ typedef struct td_bwe_enc_structure Word16 cldfbHBLT; /* Q13 */ #endif /* states for the filters used in generating SHB excitation from WB excitation*/ +#ifndef IVAS_FLOAT_FIXED float mem_csfilt[2]; - Word32 mem_csfilt_fx[2]; /* Q(prev_Q_bwe_exc) */ +#else + Word32 mem_csfilt_fx[2]; /* Q(prev_Q_bwe_exc) */ +#endif float mem_shb_res[MAX_LEN_MA_FILTER]; /* old SHB residual signal */ Word16 mem_shb_res_fx[MAX_LEN_MA_FILTER]; /* old SHB residual signal */ Word32 mem_shb_res_32_fx[MAX_LEN_MA_FILTER]; /* old SHB residual signal */ @@ -1483,46 +1445,46 @@ typedef struct td_bwe_enc_structure #if 0 Word16 prev_pow_exc16kWhtnd_fx; /* power of the LB excitation signal in the previous frame */ #endif - Word32 prev_pow_exc16kWhtnd_fx32; /* Use this power of the LB excitation signal in the previous frame Q0 */ + Word32 prev_pow_exc16kWhtnd_fx32; /* Use this power of the LB excitation signal in the previous frame Q0 */ #endif #ifndef IVAS_FLOAT_FIXED float prev_mix_factor; /* mixing factor in the previous frame */ float prev_Env_error; /* error in SHB envelope modelling */ #else - Word16 prev_mix_factor_fx; /* mixing factor in the previous frame Q15 */ - Word16 prev_Env_error_fx; /* error in SHB envelope modelling Q0 */ + Word16 prev_mix_factor_fx; /* mixing factor in the previous frame Q15 */ + Word16 prev_Env_error_fx; /* error in SHB envelope modelling Q0 */ #endif /* states for the filters used in generating SHB signal from SHB excitation*/ +#ifndef IVAS_FLOAT_FIXED float state_syn_shbexc[L_SHB_LAHEAD]; float state_lpc_syn[LPC_SHB_ORDER]; - float old_bwe_exc[PIT16k_MAX * 2]; /* old excitation */ - Word16 state_syn_shbexc_fx[L_SHB_LAHEAD]; /* Q(prev_Q_bwe_exc - 16) */ - Word16 state_lpc_syn_fx[LPC_SHB_ORDER]; /* Q(prev_Q_bwe_exc - 16) */ - Word16 old_bwe_exc_fx[PIT16k_MAX * 2]; /*Q_exc*/ +#else + Word16 state_syn_shbexc_fx[L_SHB_LAHEAD]; /* Q(prev_Q_bwe_exc - 16) */ + Word16 state_lpc_syn_fx[LPC_SHB_ORDER]; /* Q(prev_Q_bwe_exc - 16) */ +#endif + float old_bwe_exc[PIT16k_MAX * 2]; /* old excitation */ + Word16 old_bwe_exc_fx[PIT16k_MAX * 2]; /*Q_exc*/ int16_t bwe_seed[2]; #ifndef IVAS_FLOAT_FIXED float bwe_non_lin_prev_scale; -#else - Word32 bwe_non_lin_prev_scale_fx; /* Q30 */ -#endif float old_bwe_exc_extended[NL_BUFF_OFFSET]; - float syn_overlap[L_SHB_LAHEAD]; /* overlap buffer used to Adjust SHB Frame Gain*/ - Word16 old_bwe_exc_extended_fx[NL_BUFF_OFFSET]; /* Q(prev_Q_bwe_exc - 16) */ - Word16 syn_overlap_fx[L_SHB_LAHEAD]; /* Q0 not sure */ -#ifndef IVAS_FLOAT_FIXED + float syn_overlap[L_SHB_LAHEAD]; /* overlap buffer used to Adjust SHB Frame Gain */ float decim_state1[( 2 * ALLPASSSECTIONS_STEEP + 1 )]; float decim_state2[( 2 * ALLPASSSECTIONS_STEEP + 1 )]; -#else - Word16 decim_state1_fx[( 2 * ALLPASSSECTIONS_STEEP + 1 )]; /* Q(-1) */ - Word16 decim_state2_fx[( 2 * ALLPASSSECTIONS_STEEP + 1 )]; /* Q(-1) */ -#endif float mem_genSHBexc_filt_down_wb2[( 2 * ALLPASSSECTIONS_STEEP + 1 )]; float mem_genSHBexc_filt_down_wb3[( 2 * ALLPASSSECTIONS_STEEP + 1 )]; float mem_genSHBexc_filt_down_shb[( 2 * ALLPASSSECTIONS_STEEP + 1 )]; +#else + Word32 bwe_non_lin_prev_scale_fx; /* Q30 */ + Word16 old_bwe_exc_extended_fx[NL_BUFF_OFFSET]; /* Q(prev_Q_bwe_exc - 16) */ + Word16 syn_overlap_fx[L_SHB_LAHEAD]; /* overlap buffer used to Adjust SHB Frame Gain */ + Word16 decim_state1_fx[( 2 * ALLPASSSECTIONS_STEEP + 1 )]; /* Q(-1) */ + Word16 decim_state2_fx[( 2 * ALLPASSSECTIONS_STEEP + 1 )]; /* Q(-1) */ Word16 mem_genSHBexc_filt_down_wb2_fx[( 2 * ALLPASSSECTIONS_STEEP + 1 )]; /* Q(prev_Q_bwe_exc - 16) */ Word16 mem_genSHBexc_filt_down_wb3_fx[( 2 * ALLPASSSECTIONS_STEEP + 1 )]; /* Q(prev_Q_bwe_exc - 16) */ Word16 mem_genSHBexc_filt_down_shb_fx[( 2 * ALLPASSSECTIONS_STEEP + 1 )]; /* Q(prev_Q_bwe_exc - 16) */ +#endif #ifndef IVAS_FLOAT_FIXED float elliptic_bpf_2_48k_mem[4][4]; @@ -1531,8 +1493,10 @@ typedef struct td_bwe_enc_structure float lsp_shb_slow_interpl[LPC_SHB_ORDER]; float lsp_shb_fast_interpl[LPC_SHB_ORDER]; float shb_inv_filt_mem[LPC_SHB_ORDER]; + float lsp_shb_spacing[3]; + float prev_swb_GainShape; #else - Word32 elliptic_bpf_2_48k_mem_fx[4][4]; /* Q(elliptic_bpf_2_48k_mem_fx_Q[4]) */ + Word32 elliptic_bpf_2_48k_mem_fx[4][4]; /* Q(elliptic_bpf_2_48k_mem_fx_Q[4]) */ Word16 elliptic_bpf_2_48k_mem_fx_Q[4]; Word32 prev_fb_energy_fx; /* Q(prev_fb_energy_fx_Q) */ Word16 prev_fb_energy_fx_Q; @@ -1540,15 +1504,9 @@ typedef struct td_bwe_enc_structure Word16 lsp_shb_slow_interpl_fx[LPC_SHB_ORDER]; /* Q15 */ Word16 lsp_shb_fast_interpl_fx[LPC_SHB_ORDER]; /* Q15 */ Word16 shb_inv_filt_mem_fx[LPC_SHB_ORDER]; /* Q(Q_shb_spch) */ -#endif -#ifndef IVAS_FLOAT_FIXED - float lsp_shb_spacing[3]; - float prev_swb_GainShape; -#else Word16 lsp_shb_spacing_fx[3]; /* Q15 */ Word16 prev_swb_GainShape_fx; /* Q15 */ #endif - int16_t prev_frGainAtten; #ifndef IVAS_FLOAT_FIXED @@ -1602,19 +1560,19 @@ typedef struct td_bwe_enc_structure Word16 dec_2_over_3_mem_lp_fx[6]; #endif +#ifndef IVAS_FLOAT_FIXED float tbe_demph; float tbe_premph; float mem_stp_swb[LPC_SHB_ORDER]; float *ptr_mem_stp_swb; float gain_prec_swb; + float mem_zero_swb[LPC_SHB_ORDER]; +#else Word16 tbe_demph_fx; /* Q(prev_Q_bwe_exc - 16 - NOISE_QADJ) */ Word16 tbe_premph_fx; /* Q(prev_Q_bwe_exc - 16) */ Word16 mem_stp_swb_fx[LPC_SHB_ORDER]; /* Q(st->prev_Q_bwe_syn) */ Word16 *ptr_mem_stp_swb_fx; Word16 gain_prec_swb_fx; /* Q14 */ -#ifndef IVAS_FLOAT_FIXED - float mem_zero_swb[LPC_SHB_ORDER]; -#else Word16 mem_zero_swb_fx[LPC_SHB_ORDER]; #endif diff --git a/lib_enc/swb_bwe_enc_fx.c b/lib_enc/swb_bwe_enc_fx.c index ba1fe063f..f76a740b9 100644 --- a/lib_enc/swb_bwe_enc_fx.c +++ b/lib_enc/swb_bwe_enc_fx.c @@ -436,6 +436,10 @@ void swb_bwe_enc_ivas_fx( &st_fx->Q_old_wtda, ALDO_WINDOW, ALDO_WINDOW, /* window overlap of current frame (0: full, 2: none, or 3: half) */ inner_frame ); + /* Scaling has been added to avoid the yorig_32 buffer becoming zero inside direct_transform_fx */ + Scale_sig32( L_old_input_fx, inner_frame, Q5 ); + new_input_fx_exp = add( new_input_fx_exp, 5 ); + /* DCT of the ACELP core synthesis */ direct_transform_fx( L_old_input_fx, yorig_32, 0, inner_frame, &new_input_fx_exp, st_fx->element_mode ); diff --git a/lib_enc/swb_pre_proc.c b/lib_enc/swb_pre_proc.c index 878c1aa9b..b30150ead 100644 --- a/lib_enc/swb_pre_proc.c +++ b/lib_enc/swb_pre_proc.c @@ -564,7 +564,7 @@ void swb_pre_proc_ivas_fx( { Word16 out_start_ind, out_end_ind; stereo_dft_enc_synthesize_fx( hCPE->hStereoDft, new_swb_speech_fx, &out_start_ind, &out_end_ind, st->idchan, input_Fs, 32000, 0, NULL ); - Copy_Scale_sig32_16( new_swb_speech_fx - STEREO_DFT_OVL_MAX, new_swb_speech - STEREO_DFT_OVL_MAX, q_reImBuffer, L_FRAME48k + STEREO_DFT_OVL_MAX ); + Copy_Scale_sig32_16( new_swb_speech_fx - STEREO_DFT_OVL_MAX, new_swb_speech - STEREO_DFT_OVL_MAX, L_FRAME48k + STEREO_DFT_OVL_MAX, q_reImBuffer ); Copy( new_swb_speech - Sample_Delay_SWB_BWE32k, hBWE_FD->old_input_fx, Sample_Delay_SWB_BWE32k ); } } diff --git a/lib_enc/swb_tbe_enc.c b/lib_enc/swb_tbe_enc.c index 0d3f74364..18c519939 100644 --- a/lib_enc/swb_tbe_enc.c +++ b/lib_enc/swb_tbe_enc.c @@ -96,8 +96,8 @@ void InitSWBencBuffer( set_f( hBWE_TD->old_bwe_exc, 0.0f, ( PIT16k_MAX * 2 ) ); hBWE_TD->bwe_seed[0] = 23; hBWE_TD->bwe_seed[1] = 59; - set_f( hBWE_TD->old_bwe_exc_extended, 0.0f, NL_BUFF_OFFSET ); #ifndef IVAS_FLOAT_FIXED + set_f( hBWE_TD->old_bwe_exc_extended, 0.0f, NL_BUFF_OFFSET ); hBWE_TD->bwe_non_lin_prev_scale = 0; set_f( hBWE_TD->state_ana_filt_shb, 0.0f, ( 2 * ALLPASSSECTIONS_STEEP + 1 ) ); @@ -108,6 +108,7 @@ void InitSWBencBuffer( set_f( hBWE_TD->elliptic_bpf_2_48k_mem[3], 0.0f, 4 ); hBWE_TD->prev_fb_energy = 0.0f; #else + set16_fx( hBWE_TD->old_bwe_exc_extended_fx, 0, NL_BUFF_OFFSET ); hBWE_TD->bwe_non_lin_prev_scale_fx = 0; set16_fx( hBWE_TD->state_ana_filt_shb_fx, 0, ( 2 * ALLPASSSECTIONS_STEEP + 1 ) ); @@ -125,10 +126,11 @@ void InitSWBencBuffer( #ifndef IVAS_FLOAT_FIXED set_f( hBWE_TD->old_speech_shb, 0.0f, L_LOOK_16k + L_SUBFR16k ); + set_f( hBWE_TD->old_speech_wb, 0.0f, ( L_LOOK_12k8 + L_SUBFR ) * 5 / 16 ); #else set16_fx( hBWE_TD->old_speech_shb_fx, 0, L_LOOK_16k + L_SUBFR16k ); + set16_fx( hBWE_TD->old_speech_wb_fx, 0, ( L_LOOK_12k8 + L_SUBFR ) * 5 / 16 ); #endif - set_f( hBWE_TD->old_speech_wb, 0.0f, ( L_LOOK_12k8 + L_SUBFR ) * 5 / 16 ); set_f( hBWE_TD->old_input_fhb, 0.0f, NS2SA( 48000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_12k8_NS + DELAY_FIR_RESAMPL_NS ) - L_FRAME48k / 2 ); #ifdef IVAS_FLOAT_FIXED @@ -198,8 +200,8 @@ void InitSWBencBuffer( set_f( hBWE_TD->cur_sub_Aq, 0.0f, M + 1 ); /* TD BWE post-processing */ - hBWE_TD->ptr_mem_stp_swb = hBWE_TD->mem_stp_swb + LPC_SHB_ORDER - 1; #ifndef IVAS_FLOAT_FIXED + hBWE_TD->ptr_mem_stp_swb = hBWE_TD->mem_stp_swb + LPC_SHB_ORDER - 1; set_f( hBWE_TD->mem_zero_swb, 0, LPC_SHB_ORDER ); for ( i = 0; i < LPC_SHB_ORDER; i++ ) @@ -207,6 +209,7 @@ void InitSWBencBuffer( hBWE_TD->swb_lsp_prev_interp[i] = (float) cos( (float) i * EVS_PI / (float) 10.0f ); } #else + hBWE_TD->ptr_mem_stp_swb_fx = hBWE_TD->mem_stp_swb_fx + LPC_SHB_ORDER - 1; set16_fx( hBWE_TD->mem_zero_swb_fx, 0, LPC_SHB_ORDER ); FOR( i = 0; i < LPC_SHB_ORDER; i++ ) @@ -287,12 +290,22 @@ void ResetSHBbuffer_Enc( ) { /* states for the filters used in generating SHB excitation from WB excitation*/ +#ifndef IVAS_FLOAT_FIXED set_f( hBWE_TD->mem_genSHBexc_filt_down_shb, 0, ( 2 * ALLPASSSECTIONS_STEEP + 1 ) ); set_f( hBWE_TD->mem_csfilt, 0, 2 ); +#else + set16_fx( hBWE_TD->mem_genSHBexc_filt_down_shb_fx, 0, ( 2 * ALLPASSSECTIONS_STEEP + 1 ) ); + set32_fx( hBWE_TD->mem_csfilt_fx, 0, 2 ); +#endif /* states for the filters used in generating SHB signal from SHB excitation*/ +#ifndef IVAS_FLOAT_FIXED set_f( hBWE_TD->state_syn_shbexc, 0, L_SHB_LAHEAD ); set_f( hBWE_TD->state_lpc_syn, 0, LPC_SHB_ORDER ); +#else + set16_fx( hBWE_TD->state_syn_shbexc_fx, 0, L_SHB_LAHEAD ); + set16_fx( hBWE_TD->state_lpc_syn_fx, 0, LPC_SHB_ORDER ); +#endif set_f( hBWE_TD->fb_state_lpc_syn, 0, LPC_SHB_ORDER ); hBWE_TD->fb_tbe_demph = 0; @@ -300,19 +313,29 @@ void ResetSHBbuffer_Enc( #ifndef IVAS_FLOAT_FIXED set_f( hBWE_TD->decim_state1, 0.0f, ( 2 * ALLPASSSECTIONS_STEEP + 1 ) ); set_f( hBWE_TD->decim_state2, 0.0f, ( 2 * ALLPASSSECTIONS_STEEP + 1 ) ); + set_f( hBWE_TD->mem_genSHBexc_filt_down_wb2, 0, ( 2 * ALLPASSSECTIONS_STEEP + 1 ) ); + set_f( hBWE_TD->mem_genSHBexc_filt_down_wb3, 0, ( 2 * ALLPASSSECTIONS_STEEP + 1 ) ); #else set16_fx( hBWE_TD->decim_state1_fx, 0, ( 2 * ALLPASSSECTIONS_STEEP + 1 ) ); set16_fx( hBWE_TD->decim_state2_fx, 0, ( 2 * ALLPASSSECTIONS_STEEP + 1 ) ); + set16_fx( hBWE_TD->mem_genSHBexc_filt_down_wb2_fx, 0, ( 2 * ALLPASSSECTIONS_STEEP + 1 ) ); + set16_fx( hBWE_TD->mem_genSHBexc_filt_down_wb3_fx, 0, ( 2 * ALLPASSSECTIONS_STEEP + 1 ) ); #endif - set_f( hBWE_TD->mem_genSHBexc_filt_down_wb2, 0, ( 2 * ALLPASSSECTIONS_STEEP + 1 ) ); - set_f( hBWE_TD->mem_genSHBexc_filt_down_wb3, 0, ( 2 * ALLPASSSECTIONS_STEEP + 1 ) ); /* overlap buffer used to Adjust SHB Frame Gain */ +#ifndef IVAS_FLOAT_FIXED set_f( hBWE_TD->mem_stp_swb, 0, LPC_SHB_ORDER ); hBWE_TD->gain_prec_swb = 1.0f; set_f( hBWE_TD->syn_overlap, 0, L_SHB_LAHEAD ); hBWE_TD->tbe_demph = 0.0f; hBWE_TD->tbe_premph = 0.0f; +#else + set16_fx( hBWE_TD->mem_stp_swb_fx, 0, LPC_SHB_ORDER ); + hBWE_TD->gain_prec_swb_fx = ONE_IN_Q14; + set16_fx( hBWE_TD->syn_overlap_fx, 0, L_SHB_LAHEAD ); + hBWE_TD->tbe_demph_fx = 0; + hBWE_TD->tbe_premph_fx = 0; +#endif return; } @@ -2980,13 +3003,26 @@ void TBEreset_enc( if ( bwidth == WB ) { +#ifndef IVAS_FLOAT_FIXED wb_tbe_extras_reset( hBWE_TD->mem_genSHBexc_filt_down_wb2, hBWE_TD->mem_genSHBexc_filt_down_wb3 ); set_f( hBWE_TD->mem_genSHBexc_filt_down_shb, 0, 7 ); set_f( hBWE_TD->state_lpc_syn, 0, 10 ); set_f( hBWE_TD->state_syn_shbexc, 0, L_SHB_LAHEAD / 4 ); +#else + wb_tbe_extras_reset_fx( hBWE_TD->mem_genSHBexc_filt_down_wb2_fx, hBWE_TD->mem_genSHBexc_filt_down_wb3_fx ); + + set16_fx( hBWE_TD->mem_genSHBexc_filt_down_shb_fx, 0, 7 ); + set16_fx( hBWE_TD->state_lpc_syn_fx, 0, 10 ); + set16_fx( hBWE_TD->state_syn_shbexc_fx, 0, L_SHB_LAHEAD / 4 ); +#endif +#ifndef IVAS_FLOAT_FIXED set_f( hBWE_TD->syn_overlap, 0, L_SHB_LAHEAD ); set_f( hBWE_TD->mem_csfilt, 0, 2 ); +#else + set16_fx( hBWE_TD->syn_overlap_fx, 0, L_SHB_LAHEAD ); + set32_fx( hBWE_TD->mem_csfilt_fx, 0, 2 ); +#endif } else if ( bwidth == SWB || bwidth == FB ) { @@ -2996,7 +3032,12 @@ void TBEreset_enc( set_f( hBWE_TD->state_ana_filt_shb, 0.0f, ( 2 * ALLPASSSECTIONS_STEEP + 1 ) ); #endif +#ifdef IVAS_FLOAT_FIXED + swb_tbe_reset_fx( hBWE_TD->mem_csfilt_fx, hBWE_TD->mem_genSHBexc_filt_down_shb_fx, hBWE_TD->state_lpc_syn_fx, hBWE_TD->syn_overlap_fx, hBWE_TD->state_syn_shbexc_fx, &( hBWE_TD->tbe_demph_fx ), &( hBWE_TD->tbe_premph_fx ), hBWE_TD->mem_stp_swb_fx, &( hBWE_TD->gain_prec_swb_fx ) ); +#else swb_tbe_reset( hBWE_TD->mem_csfilt, hBWE_TD->mem_genSHBexc_filt_down_shb, hBWE_TD->state_lpc_syn, hBWE_TD->syn_overlap, hBWE_TD->state_syn_shbexc, &( hBWE_TD->tbe_demph ), &( hBWE_TD->tbe_premph ), hBWE_TD->mem_stp_swb, &( hBWE_TD->gain_prec_swb ) ); +#endif + if ( bwidth == FB ) { diff --git a/lib_enc/swb_tbe_enc_fx.c b/lib_enc/swb_tbe_enc_fx.c index 1304bdedb..9a219d065 100644 --- a/lib_enc/swb_tbe_enc_fx.c +++ b/lib_enc/swb_tbe_enc_fx.c @@ -110,6 +110,16 @@ static void gainFrSmooth_En_fx( Encoder_State *st_fx, Word16 *frGainAttenuate, Word16 *frGainSmoothEn ); +#ifdef IVAS_FLOAT_FIXED +static void gainFrSmooth_En_ivas_fx( Encoder_State *st_fx, + Word16 *shb_frame_fx /* Q_in */, + const Word16 *lpc_shb_fx /* Q12 */, + const Word16 *lsp_shb_fx /* Q15 */, + Word16 *MA_lsp_shb_spacing /* Q15 */, + Word16 *frGainAttenuate /* Q0 */, + Word16 *frGainSmoothEn /* Q0 */ ); +#endif + /*-------------------------------------------------------------------* * find_max_mem_enc() @@ -2966,7 +2976,7 @@ void swb_tbe_enc_ivas_fx( /* Input signal filtering in case of tonal sounds in the high band gain Frame smoothing and attenuation control */ - gainFrSmooth_En_fx( st_fx, shb_frame_fx, lpc_shb_fx, lsf_shb_fx, &MA_lsp_shb_spacing, &frGainAttenuate, &frGainSmoothEn ); + gainFrSmooth_En_ivas_fx( st_fx, shb_frame_fx, lpc_shb_fx, lsf_shb_fx, &MA_lsp_shb_spacing, &frGainAttenuate, &frGainSmoothEn ); test(); test(); @@ -5372,19 +5382,19 @@ static void Quant_shb_ener_sf_ivas_fx( exp = norm_l( sum ); frac = Log2_norm_lc( L_shl( sum, exp ) ); exp = sub( 30, add( exp, Q_ener ) ); /* 30-(exp+Q_ener ) */ - L_tmp1 = Mpy_32_16( exp, frac, 617 ); /* 2466=LOG10(2) in Q11, so answer Ltmp in Q12 */ + L_tmp1 = Mpy_32_16( exp, frac, 308 ); /* 308=LOG10(2) in Q10, so answer Ltmp in Q11 */ - tmp = round_fx( L_shl( L_tmp1, 30 - 14 ) ); /* tmp in Q12 */ + tmp = extract_l( L_tmp1 ); /* tmp in Q11 */ temp_shb_ener_sf_fx = 0; move16(); - idxSubEner_fx = usquant_fx( tmp, &temp_shb_ener_sf_fx, 0, 86, shl( 1, NUM_BITS_SHB_ENER_SF ) ); /* 86 = 0.042f in Q11 = Qin-1 */ - /* o: temp_shb_ener_sf_fx in Q12 */ + idxSubEner_fx = usquant_fx( tmp, &temp_shb_ener_sf_fx, 0, 43, shl( 1, NUM_BITS_SHB_ENER_SF ) ); /* 43 = 0.042f in Q10 = Qin-1 */ + /* o: temp_shb_ener_sf_fx in Q11 */ /* shb_ener_sf_fx[0] = pow(10.0, temp_shb_ener_sf_fx ); */ /* = pow(2, 3.321928*temp_shb_ener_sf_fx) */ - L_tmp = L_mult( temp_shb_ener_sf_fx, 27213 ); /* 3.321928 in Q13 -> L_tmp in Q12+Q13+1 = Q26 */ - L_tmp = L_shl( L_tmp, -10 ); /* bring L_tmp from Q26 to Q16 */ + L_tmp = L_mult( temp_shb_ener_sf_fx, 27213 ); /* 3.321928 in Q13 -> L_tmp in Q11+Q13+1 = Q25 */ + L_tmp = L_shl( L_tmp, -9 ); /* bring L_tmp from Q25 to Q16 */ frac = L_Extract_lc( L_tmp, &exp ); /* Extract exponent */ L_tmp = Pow2( 14, frac ); *shb_ener_sf_Q31 = L_shl( L_tmp, add( sub( exp, 14 ), Q_ener ) ); /* In Q_ener */ @@ -6376,6 +6386,134 @@ static void gainFrSmooth_En_fx( Encoder_State *st_fx, } } +#ifdef IVAS_FLOAT_FIXED +/*-------------------------------------------------------------------* + * gainFrSmooth_En_ivas_fx() + * + * Gain frame smoothing and attenuation control + *-------------------------------------------------------------------*/ +static void gainFrSmooth_En_ivas_fx( Encoder_State *st_fx, + Word16 *shb_frame_fx /* Q_in */, + const Word16 *lpc_shb_fx /* Q12 */, + const Word16 *lsp_shb_fx /* Q15 */, + Word16 *MA_lsp_shb_spacing /* Q15 */, + Word16 *frGainAttenuate /* Q0 */, + Word16 *frGainSmoothEn /* Q0 */ ) +{ + Word16 temp_shb_frame[L_FRAME16k + L_SHB_LAHEAD]; + Word32 lsp_slow_evol_rate, lsp_fast_evol_rate; + Word16 lsp_slow_evol_rate_e, lsp_fast_evol_rate_e; + Word16 lsp_spacing; + + Word32 tempQ31; + Word16 tempQ15_1, tempQ15_2; + Word16 i; + TD_BWE_ENC_HANDLE hBWE_TD = st_fx->hBWE_TD; + + /* inits */ + *frGainAttenuate = 0; + move16(); + *frGainSmoothEn = 0; + move16(); + *MA_lsp_shb_spacing = 16384; /* 0.5f in Q15 */ + move16(); + lsp_spacing = lsp_shb_fx[0]; + move16(); + + /* estimate the mean square error in lsps from current frame to past frames */ + tempQ15_1 = sub( lsp_shb_fx[0], hBWE_TD->lsp_shb_slow_interpl_fx[0] ); + tempQ15_2 = sub( lsp_shb_fx[0], hBWE_TD->lsp_shb_fast_interpl_fx[0] ); + lsp_slow_evol_rate = L_mult( tempQ15_1, tempQ15_1 ); + lsp_slow_evol_rate_e = 0; + move16(); + lsp_fast_evol_rate = L_mult( tempQ15_2, tempQ15_2 ); + lsp_fast_evol_rate_e = 0; + move16(); + + /* update the slow and fast lsp interp for next frame */ + tempQ31 = L_mult( hBWE_TD->lsp_shb_slow_interpl_fx[0], 22937 /* 0.7f in Q15 */ ); + hBWE_TD->lsp_shb_slow_interpl_fx[0] = mac_r( tempQ31, lsp_shb_fx[0], 9830 /* 0.3f in Q15 */ ); + move16(); + tempQ31 = L_mult( hBWE_TD->lsp_shb_fast_interpl_fx[0], 9830 /* 0.3f in Q15 */ ); + hBWE_TD->lsp_shb_fast_interpl_fx[0] = mac_r( tempQ31, lsp_shb_fx[0], 22937 /* 0.7f in Q15 */ ); + move16(); + + FOR( i = 1; i < LPC_SHB_ORDER; i++ ) + { + tempQ15_1 = sub( lsp_shb_fx[i], lsp_shb_fx[i - 1] ); + lsp_spacing = s_min( lsp_spacing, tempQ15_1 ); + + /* estimate the mean square error in lsps from current frame to past frames */ + tempQ15_1 = sub( lsp_shb_fx[i], hBWE_TD->lsp_shb_slow_interpl_fx[i] ); + tempQ15_2 = sub( lsp_shb_fx[i], hBWE_TD->lsp_shb_fast_interpl_fx[i] ); + lsp_slow_evol_rate = BASOP_Util_Add_Mant32Exp( lsp_slow_evol_rate, lsp_slow_evol_rate_e, L_mult( tempQ15_1, tempQ15_1 ), 0, &lsp_slow_evol_rate_e ); + lsp_fast_evol_rate = BASOP_Util_Add_Mant32Exp( lsp_fast_evol_rate, lsp_fast_evol_rate_e, L_mult( tempQ15_2, tempQ15_2 ), 0, &lsp_fast_evol_rate_e ); + + /* update the slow and fast interpolation lsps for next frame */ + tempQ31 = L_mult( hBWE_TD->lsp_shb_slow_interpl_fx[i], 22937 /* 0.7f in Q15 */ ); + hBWE_TD->lsp_shb_slow_interpl_fx[i] = mac_r( tempQ31, lsp_shb_fx[i], 9830 /* 0.3f in Q15 */ ); + move16(); + tempQ31 = L_mult( hBWE_TD->lsp_shb_fast_interpl_fx[i], 9830 /* 0.3f in Q15 */ ); + hBWE_TD->lsp_shb_fast_interpl_fx[i] = mac_r( tempQ31, lsp_shb_fx[i], 22937 /* 0.7f in Q15 */ ); + move16(); + } + + test(); + test(); + IF( NE_16( st_fx->last_extl, SWB_TBE ) && NE_16( st_fx->last_extl, FB_TBE ) && LT_16( lsp_spacing, 262 /* 0.008f in Q15 */ ) ) + { + hBWE_TD->lsp_shb_spacing_fx[0] = lsp_spacing; + move16(); + hBWE_TD->lsp_shb_spacing_fx[1] = lsp_spacing; + move16(); + hBWE_TD->lsp_shb_spacing_fx[2] = lsp_spacing; + move16(); + hBWE_TD->prev_frGainAtten = 1; + move16(); + set16_fx( hBWE_TD->shb_inv_filt_mem_fx, 0, LPC_SHB_ORDER ); + } + + /* Estimate the moving average LSP spacing */ + tempQ31 = L_mult( hBWE_TD->lsp_shb_spacing_fx[0], 3277 ); /* 0.1f in Q15 */ + tempQ31 = L_mac( tempQ31, hBWE_TD->lsp_shb_spacing_fx[1], 6553 ); /* 0.2f in Q15 */ + tempQ31 = L_mac( tempQ31, hBWE_TD->lsp_shb_spacing_fx[2], 9830 ); /* 0.3f in Q15 */ + *MA_lsp_shb_spacing = mac_r( tempQ31, lsp_spacing, 13107 ); /* 0.4f in Q15 */ + + hBWE_TD->lsp_shb_spacing_fx[0] = hBWE_TD->lsp_shb_spacing_fx[1]; + move16(); + hBWE_TD->lsp_shb_spacing_fx[1] = hBWE_TD->lsp_shb_spacing_fx[2]; + move16(); + hBWE_TD->lsp_shb_spacing_fx[2] = lsp_spacing; + move16(); + + test(); + test(); + test(); + IF( ( LT_16( lsp_spacing, 262 /* 0.008f in Q15 */ ) && ( LT_16( *MA_lsp_shb_spacing, 164 /* 0.005f in Q15 */ ) || EQ_16( hBWE_TD->prev_frGainAtten, 1 ) ) ) || LE_16( lsp_spacing, 105 /* 0.0032f in Q15 */ ) ) + { + *frGainAttenuate = 1; + move16(); + + IF( NE_32( st_fx->total_brate, ACELP_24k40 ) ) + { + Copy( shb_frame_fx, temp_shb_frame, L_FRAME16k + L_SHB_LAHEAD ); + fir_fx( temp_shb_frame, lpc_shb_fx, shb_frame_fx, hBWE_TD->shb_inv_filt_mem_fx, L_FRAME16k + L_SHB_LAHEAD, LPC_SHB_ORDER, 1, 3 ); + } + ELSE + { + set16_fx( hBWE_TD->shb_inv_filt_mem_fx, 0, LPC_SHB_ORDER ); + } + + test(); + IF( ( BASOP_Util_Cmp_Mant32Exp( lsp_slow_evol_rate, lsp_slow_evol_rate_e, 2147484l /*0.001f in Q31*/, 0 ) < 0 ) && ( BASOP_Util_Cmp_Mant32Exp( lsp_fast_evol_rate, lsp_fast_evol_rate_e, 2147484l /*0.001f in Q31*/, 0 ) < 0 ) ) + { + *frGainSmoothEn = 1; + move16(); + } + } +} +#endif + #define MAXINT32 MAX_32 static void first_VQstages_fx( const Word16 *const *cb, diff --git a/lib_rend/ivas_omasa_ana.c b/lib_rend/ivas_omasa_ana.c index 1d7e191b4..5fa4901b7 100644 --- a/lib_rend/ivas_omasa_ana.c +++ b/lib_rend/ivas_omasa_ana.c @@ -943,6 +943,8 @@ static void ivas_omasa_param_est_ana_fx( computeIntensityVector_ana_fx( hOMasa->band_grouping, Foa_RealBuffer_fx, Foa_ImagBuffer_fx, num_freq_bands, intensity_real_fx ); intensity_q = sub( shl( add( foa_q, Q1 ), 1 ), 31 ); + direction_q = intensity_q; + move16(); computeDirectionVectors_fx( intensity_real_fx[0], intensity_real_fx[1], intensity_real_fx[2], 0, num_freq_bands, direction_vector_fx[0], direction_vector_fx[1], direction_vector_fx[2], &direction_q ); -- GitLab From 0f18a0e6f85009103c99e62d6580d627969c49aa Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Tue, 12 Nov 2024 16:18:19 +0530 Subject: [PATCH 108/128] Fix for 3GPP issue 996: Low-frequency "thump" in MASA format using bitrate switching and output to MONO link #996 --- lib_rend/ivas_dirac_rend.c | 53 +++++++++----------------------------- 1 file changed, 12 insertions(+), 41 deletions(-) diff --git a/lib_rend/ivas_dirac_rend.c b/lib_rend/ivas_dirac_rend.c index af3d9000c..5bb0dfe1f 100644 --- a/lib_rend/ivas_dirac_rend.c +++ b/lib_rend/ivas_dirac_rend.c @@ -3471,47 +3471,18 @@ void protoSignalComputation2_fx( // 20480 = 10 in Q11 lr_total_bb_ratio_fx = Mpy_32_16_1( temp, 20480 ); // Q21 - temp = Mpy_32_32( a_fx, left_hi_power_fx ); // 2*(q_cldfb+min_q_shift) -31 - IF( LT_16( q_temp, stereo_type_detect->q_left_hi_power ) ) - { - stereo_type_detect->left_hi_power_fx = L_add( temp, L_shr( Mpy_32_32( b_fx, stereo_type_detect->left_hi_power_fx ), sub( stereo_type_detect->q_left_hi_power, q_temp ) ) ); // q_temp - move32(); - stereo_type_detect->q_left_hi_power = q_temp; - move16(); - } - ELSE - { - stereo_type_detect->left_hi_power_fx = L_add( L_shr( temp, sub( q_temp, stereo_type_detect->q_left_hi_power ) ), Mpy_32_32( b_fx, stereo_type_detect->left_hi_power_fx ) ); // stereo_type_detect->q_left_hi_power - move32(); - } - - temp = Mpy_32_32( a_fx, right_hi_power_fx ); // 2*(q_cldfb+min_q_shift) -31 - IF( LT_16( q_temp, stereo_type_detect->q_right_hi_power ) ) - { - stereo_type_detect->right_hi_power_fx = L_add( temp, L_shr( Mpy_32_32( b_fx, stereo_type_detect->right_hi_power_fx ), sub( stereo_type_detect->q_right_hi_power, q_temp ) ) ); // q_temp - move32(); - stereo_type_detect->q_right_hi_power = q_temp; - move16(); - } - ELSE - { - stereo_type_detect->right_hi_power_fx = L_add( L_shr( temp, sub( q_temp, stereo_type_detect->q_right_hi_power ) ), Mpy_32_32( b_fx, stereo_type_detect->right_hi_power_fx ) ); // stereo_type_detect->q_right_hi_power - move32(); - } - - temp = Mpy_32_32( a_fx, total_hi_power_fx ); // 2*(q_cldfb+min_q_shift) -31 - IF( LT_16( q_temp, stereo_type_detect->q_total_hi_power ) ) - { - stereo_type_detect->total_hi_power_fx = L_add( temp, L_shr( Mpy_32_32( b_fx, stereo_type_detect->total_hi_power_fx ), sub( stereo_type_detect->q_total_hi_power, q_temp ) ) ); // q_temp - move32(); - stereo_type_detect->q_total_hi_power = q_temp; - move16(); - } - ELSE - { - stereo_type_detect->total_hi_power_fx = L_add( L_shr( temp, sub( q_temp, stereo_type_detect->q_total_hi_power ) ), Mpy_32_32( b_fx, stereo_type_detect->total_hi_power_fx ) ); // stereo_type_detect->q_total_hi_power - move32(); - } + stereo_type_detect->left_hi_power_fx = BASOP_Util_Add_Mant32Exp( Mpy_32_32( a_fx, left_hi_power_fx ), sub( 31, q_temp ), Mpy_32_32( b_fx, stereo_type_detect->left_hi_power_fx ), sub( 31, stereo_type_detect->q_left_hi_power ), &stereo_type_detect->q_left_hi_power ); + move32(); + stereo_type_detect->q_left_hi_power = sub( 31, stereo_type_detect->q_left_hi_power ); + move16(); + stereo_type_detect->right_hi_power_fx = BASOP_Util_Add_Mant32Exp( Mpy_32_32( a_fx, right_hi_power_fx ), sub( 31, q_temp ), Mpy_32_32( b_fx, stereo_type_detect->right_hi_power_fx ), sub( 31, stereo_type_detect->q_right_hi_power ), &stereo_type_detect->q_right_hi_power ); + move32(); + stereo_type_detect->q_right_hi_power = sub( 31, stereo_type_detect->q_right_hi_power ); + move16(); + stereo_type_detect->total_hi_power_fx = BASOP_Util_Add_Mant32Exp( Mpy_32_32( a_fx, total_hi_power_fx ), sub( 31, q_temp ), Mpy_32_32( b_fx, stereo_type_detect->total_hi_power_fx ), sub( 31, stereo_type_detect->q_total_hi_power ), &stereo_type_detect->q_total_hi_power ); + move32(); + stereo_type_detect->q_total_hi_power = sub( 31, stereo_type_detect->q_total_hi_power ); + move16(); IF( LT_16( stereo_type_detect->q_left_hi_power, stereo_type_detect->q_right_hi_power ) ) { -- GitLab From 29a47f45d50eb04a8fe3caaf6e26f9fd42ef3594 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Tue, 12 Nov 2024 16:25:57 +0530 Subject: [PATCH 109/128] Fix for 3GPP issue 954: High frequency differences above 6 kHz, 7.1+4 MC with FER at 32kbps link #954 --- lib_dec/ivas_dirac_dec.c | 49 ++++++++++++++++++++-- lib_rend/ivas_dirac_output_synthesis_dec.c | 47 +++++++++++++++++---- 2 files changed, 85 insertions(+), 11 deletions(-) diff --git a/lib_dec/ivas_dirac_dec.c b/lib_dec/ivas_dirac_dec.c index 21d6d6175..787379e9f 100644 --- a/lib_dec/ivas_dirac_dec.c +++ b/lib_dec/ivas_dirac_dec.c @@ -4726,13 +4726,41 @@ void ivas_dirac_dec_render_sf_fx( { IF( LT_16( q_reference_power_smooth, DirAC_mem.reference_power_q ) ) { - scale_sig32( reference_power_fx, hSpatParamRendCom->num_freq_bands, sub( q_reference_power_smooth, DirAC_mem.reference_power_q ) ); // q_reference_power_smooth + Word32 temp; + FOR( i = 0; i < hSpatParamRendCom->num_freq_bands; i++ ) + { + temp = L_shl( reference_power_fx[i], sub( q_reference_power_smooth, DirAC_mem.reference_power_q ) ); + test(); + IF( temp == 0 && ( reference_power_fx[i] != 0 ) ) + { + reference_power_fx[i] = 1; + } + ELSE + { + reference_power_fx[i] = temp; + } + move32(); + } DirAC_mem.reference_power_q = q_reference_power_smooth; move16(); } ELSE { - scale_sig32( reference_power_smooth_fx, hSpatParamRendCom->num_freq_bands, sub( DirAC_mem.reference_power_q, q_reference_power_smooth ) ); // reference_power_q + Word32 temp; + FOR( i = 0; i < hSpatParamRendCom->num_freq_bands; i++ ) + { + temp = L_shl( reference_power_smooth_fx[i], sub( DirAC_mem.reference_power_q, q_reference_power_smooth ) ); + test(); + IF( temp == 0 && ( reference_power_smooth_fx[i] != 0 ) ) + { + reference_power_smooth_fx[i] = 1; + } + ELSE + { + reference_power_smooth_fx[i] = temp; + } + move32(); + } q_reference_power_smooth = DirAC_mem.reference_power_q; move16(); } @@ -4940,7 +4968,22 @@ void ivas_dirac_dec_render_sf_fx( } ELSE { - scale_sig32( reference_power_smooth_fx, hSpatParamRendCom->num_freq_bands, sub( hDirACRend->h_output_synthesis_psd_state.reference_power_smooth_prev_q, q_reference_power_smooth ) ); // reference_power_smooth_prev_q + Word32 temp; + FOR( i = 0; i < hSpatParamRendCom->num_freq_bands; i++ ) + { + temp = L_shl( reference_power_smooth_fx[i], sub( hDirACRend->h_output_synthesis_psd_state.reference_power_smooth_prev_q, q_reference_power_smooth ) ); + test(); + IF( temp == 0 && ( reference_power_smooth_fx[i] != 0 ) ) + { + reference_power_smooth_fx[i] = 1; + } + ELSE + { + reference_power_smooth_fx[i] = temp; + } + move32(); + } + q_reference_power_smooth = hDirACRend->h_output_synthesis_psd_state.reference_power_smooth_prev_q; move16(); } diff --git a/lib_rend/ivas_dirac_output_synthesis_dec.c b/lib_rend/ivas_dirac_output_synthesis_dec.c index 0fa4511fd..72c32b57a 100644 --- a/lib_rend/ivas_dirac_output_synthesis_dec.c +++ b/lib_rend/ivas_dirac_output_synthesis_dec.c @@ -3015,7 +3015,6 @@ void ivas_dirac_dec_output_synthesis_process_subframe_psd_ls_fx( /*-----------------------------------------------------------------* * compute target PSDs *-----------------------------------------------------------------*/ - IF( enc_param_start_band == 0 ) { IF( EQ_16( h_dirac_output_synthesis_params->use_onset_filters, 1 ) ) @@ -3447,10 +3446,16 @@ void ivas_dirac_dec_output_synthesis_process_subframe_psd_ls_fx( *( p_cy_auto_dir_smooth_prev++ ) = L_shr_r( L_tmp, q_tmp ); // q_cy_auto_dir_smooth_prev_local move32(); - *( p_cy_cross_dir_smooth_prev ) = L_add( Mpy_32_32( g1, ( *( p_cy_cross_dir_smooth++ ) ) ), + *( p_cy_cross_dir_smooth_prev ) = L_add( Mpy_32_32( g1, ( *( p_cy_cross_dir_smooth ) ) ), Mpy_32_32( g2, ( *( p_cy_cross_dir_smooth_prev ) ) ) ); // (Q31, q_cy_cross_dir_smooth_prev) -> q_cy_cross_dir_smooth_prev move32(); - + test(); + if ( *( p_cy_cross_dir_smooth_prev ) == 0 && ( *( p_cy_cross_dir_smooth ) != 0 ) ) + { + *( p_cy_cross_dir_smooth_prev ) = 1; + move32(); + } + ( p_cy_cross_dir_smooth++ ); power_smooth_temp = L_shl( *p_power_smooth, norm_l( *p_power_smooth ) ); L_tmp = Mpy_32_32( power_smooth_temp, L_tmp ); // proto_power_smooth_q + norm_l( *p_power_smooth ) ) + q_cy_auto_dir_smooth_prev_local - 31 exp = sub( Q31, sub( add( add( h_dirac_output_synthesis_state->proto_power_smooth_q, norm_l( *p_power_smooth ) ), @@ -3481,12 +3486,29 @@ void ivas_dirac_dec_output_synthesis_process_subframe_psd_ls_fx( p_gains_dir++; /*diffuse*/ - *( p_cy_auto_diff_smooth_prev ) = L_add( Mpy_32_32( g1, ( *( p_cy_auto_diff_smooth++ ) ) ), + *( p_cy_auto_diff_smooth_prev ) = L_add( Mpy_32_32( g1, ( *( p_cy_auto_diff_smooth ) ) ), Mpy_32_32( g2, ( *( p_cy_auto_diff_smooth_prev ) ) ) ); // (Q31, q_cy_auto_diff_smooth_prev) -> q_cy_auto_diff_smooth_prev + + test(); + if ( *( p_cy_auto_diff_smooth_prev ) == 0 && ( *( p_cy_auto_diff_smooth ) != 0 ) ) + { + *( p_cy_auto_diff_smooth_prev ) = 1; + move32(); + } + ( p_cy_auto_diff_smooth++ ); move32(); - power_smooth_temp = L_shl( *p_power_smooth, norm_l( *p_power_smooth ) ); // proto_power_smooth_q + norm_l( *p_power_smooth ) - L_tmp = Mpy_32_32( power_smooth_temp, ( *( p_cy_auto_diff_smooth_prev++ ) ) ); // proto_power_smooth_q + norm_l( *p_power_smooth ) ) + q_cy_auto_diff_smooth_prev - 31 + power_smooth_temp = L_shl( *p_power_smooth, norm_l( *p_power_smooth ) ); // proto_power_smooth_q + norm_l( *p_power_smooth ) + L_tmp = Mpy_32_32( power_smooth_temp, ( *( p_cy_auto_diff_smooth_prev ) ) ); // proto_power_smooth_q + norm_l( *p_power_smooth ) ) + q_cy_auto_diff_smooth_prev - 31 + + test(); + test(); + if ( L_tmp == 0 && ( power_smooth_temp != 0 && *( p_cy_auto_diff_smooth_prev ) != 0 ) ) + { + L_tmp = 1; + move32(); + } + ( p_cy_auto_diff_smooth_prev++ ); exp = sub( Q31, sub( add( add( h_dirac_output_synthesis_state->proto_power_smooth_q, norm_l( *p_power_smooth ) ), h_dirac_output_synthesis_state->q_cy_auto_diff_smooth_prev ), Q31 ) ); @@ -6041,8 +6063,17 @@ static void computeTargetPSDs_direct_subframe_fx( Word32 direct_power[CLDFB_NO_CHANNELS_MAX]; /* size: num_freq_bands. */ /* estimate direct and diffuse power */ - v_mult_fixed( direct_power_factor, reference_power, direct_power, num_freq_bands ); // (Q31, q_reference_power) -> q_reference_power - + FOR( i = 0; i < num_freq_bands; i++ ) + { + direct_power[i] = Mpy_32_32( direct_power_factor[i], reference_power[i] ); + move32(); + test(); + if ( direct_power[i] == 0 && ( direct_power_factor[i] != 0 && reference_power[i] != 0 ) ) + { + direct_power[i] = 1; + move32(); + } + } /* compute target auto and cross PSDs of current frame (smoothed) */ FOR( ch_idx = 0; ch_idx < num_channels; ++ch_idx ) { -- GitLab From bd419b1ba8af83931b685304bb74677f20e43a2d Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Tue, 12 Nov 2024 17:36:01 +0530 Subject: [PATCH 110/128] Fix for 3GPP issue 992: Crash in ivas_dirac_dec_render_fx() in OMASA JBM decoding - 2 [x] link #992 [x] Exponent fix for extend_frm and shrink_frm --- lib_dec/jbm_pcmdsp_apa.c | 441 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 439 insertions(+), 2 deletions(-) diff --git a/lib_dec/jbm_pcmdsp_apa.c b/lib_dec/jbm_pcmdsp_apa.c index f8cce92ca..297221eb4 100644 --- a/lib_dec/jbm_pcmdsp_apa.c +++ b/lib_dec/jbm_pcmdsp_apa.c @@ -151,8 +151,12 @@ static bool copy_frm_fx( apa_state_t *ps, const Word16 frm_in[], Word16 frm_out[ static bool shrink_frm_fx( apa_state_t *ps, const Word16 frm_in[], UWord16 maxScaling, Word16 frm_out[], UWord16 *l_frm_out ); +static bool shrink_frm_ivas_fx( apa_state_t *ps, const Word16 frm_in[], UWord16 maxScaling, Word16 frm_out[], Word16 Q_frm_in, UWord16 *l_frm_out ); + static bool extend_frm_fx( apa_state_t *ps, const Word16 frm_in[], Word16 frm_out[], UWord16 *l_frm_out ); +static bool extend_frm_ivas_fx( apa_state_t *ps, const Word16 frm_in[], Word16 frm_out[], Word16 Q_frm_in, UWord16 *l_frm_out ); + /*---------------------------------------------------------------------* * Public functions *---------------------------------------------------------------------*/ @@ -991,12 +995,12 @@ UWord8 apa_exec_ivas_fx( /* shrink */ ELSE IF( LT_32( ps->scale, 100 ) ) { - shrink_frm_fx( ps, frm_in, maxScaling, a_tmp, &l_frm_out ); + shrink_frm_ivas_fx( ps, frm_in, maxScaling, a_tmp, Q_a_out, &l_frm_out ); } /* extend */ ELSE { - extend_frm_fx( ps, frm_in, a_tmp, &l_frm_out ); + extend_frm_ivas_fx( ps, frm_in, a_tmp, Q_a_out, &l_frm_out ); } /* control the amount/frequency of scaling */ IF( NE_32( l_frm_out, ps->l_frm ) ) @@ -1721,6 +1725,180 @@ static bool shrink_frm_fx( return 0; } +static bool shrink_frm_ivas_fx( + apa_state_t *ps, + const Word16 frm_in_fx[], // Qx + UWord16 maxScaling, + Word16 frm_out_fx[], // Qx + Word16 Q_frm_in, + UWord16 *l_frm_out ) +{ + bool findSynchResult = 0; + move16(); + Word16 xtract, l_rem, s_start, s_end; + UWord16 i; + UWord16 over; + Word16 energy_fx = 0; + Word32 quality_fx = 0; + UWord16 l_frm; + UWord16 l_seg; + move16(); + move32(); + + l_frm = ps->l_frm; + move16(); + l_seg = ps->l_seg; + move16(); + + /* only 2nd input frame is used */ + frm_in_fx += l_frm; + + /* set search range */ + // s_start = ( ps->p_min / ps->num_channels ) * ps->num_channels; + Word16 tmp, tmp_e; + tmp = BASOP_Util_Divide3232_Scale( ps->p_min, ps->num_channels, &tmp_e ); + tmp = shr( tmp, sub( 15, tmp_e ) ); + s_start = i_mult( tmp, extract_l( ps->num_channels ) ); + s_end = add( s_start, extract_l( ps->l_search ) ); + IF( GE_32( L_add( s_end, l_seg ), l_frm ) ) + { + s_end = extract_l( L_sub( l_frm, l_seg ) ); + } + + /* calculate overlap position */ + IF( isSilence_fx( frm_in_fx, l_seg, 10 ) ) + { + /* maximum scaling */ + energy_fx = -65 * ( 1 << 8 ); // Q8 + move16(); + quality_fx = 5 << Q16; // Q16 + move32(); + IF( ps->evs_compat_mode == false ) + { + + xtract = maxScaling; + move16(); + /* take samples already in the renderer buf into account */ + xtract = add( xtract, extract_l( ps->l_r_buf ) ); + /* snap to renderer time slot borders */ + xtract = sub( xtract, extract_l( L_sub( ps->l_ts, ( L_add( L_sub( l_frm, xtract ), ps->l_r_buf ) ) % ps->l_ts ) ) ); + WHILE( xtract < 0 ) + { + xtract = add( xtract, extract_l( ps->l_ts ) ); + } + WHILE( GT_32( xtract, sub( s_end, extract_l( ps->num_channels ) ) ) ) + { + /* exceeded the possible shrinking, go back one renderer ts*/ + xtract = sub( xtract, extract_l( ps->l_ts ) ); + } + } + ELSE IF( maxScaling != 0U && GT_16( s_end, add( extract_l( maxScaling ), 1 ) ) ) + { + xtract = maxScaling; + move16(); + } + ELSE + { + /* set to last valid element (i.e. element[len - 1] but note for stereo last element is last pair of samples) */ + xtract = sub( s_end, extract_l( ps->num_channels ) ); + } + } + ELSE + { + /* find synch */ + scaleSignal16( frm_in_fx, ps->frmInScaled, l_frm, ps->signalScaleForCorrelation ); + ps->signalScaleForCorrelation = sub( ps->signalScaleForCorrelation, Q_frm_in ); + move16(); + findSynchResult = find_synch_fx( ps, ps->frmInScaled, l_frm, s_start, (UWord16) ( sub( s_end, s_start ) ), 0, l_seg, 0, &energy_fx, &quality_fx, &xtract ); + ps->signalScaleForCorrelation = add( ps->signalScaleForCorrelation, Q_frm_in ); + move16(); + } + + /* assert synch_pos is cleanly divisible by number of channels */ + assert( xtract % ps->num_channels == 0 ); + + /* set frame overlappable - reset if necessary */ + over = 1; + move16(); + + /* test whether frame has sufficient quality */ + IF( LT_32( quality_fx, L_add( L_sub( ps->targetQuality_fx, + L_mult0( ps->bad_frame_count, 6554 /*0.1 (Q16)*/ ) ), + L_mult0( ps->good_frame_count, 13107 /*0.2 (Q16)*/ ) ) ) ) + { + /* not sufficient */ + over = 0; + move16(); + IF( LT_32( ps->bad_frame_count, ps->qualityred ) ) + { + ps->bad_frame_count = u_extract_l( UL_addNsD( ps->bad_frame_count, 1 ) ); + move16(); + } + IF( GT_32( ps->good_frame_count, 0 ) ) + { + ps->good_frame_count = u_extract_l( UL_subNsD( ps->good_frame_count, 1 ) ); + move16(); + } + } + ELSE + { + /* sufficient quality */ + IF( ps->bad_frame_count > 0 ) + { + ps->bad_frame_count = u_extract_l( UL_subNsD( ps->bad_frame_count, 1 ) ); + move16(); + } + IF( LT_32( ps->good_frame_count, ps->qualityrise ) ) + { + ps->good_frame_count = u_extract_l( UL_addNsD( ps->good_frame_count, 1 ) ); + move16(); + } + } + + /* Calculate output data */ + test(); + IF( over && xtract ) + { + IF( findSynchResult == 1 ) + { + return 1; + } + IF( EQ_16( ps->evs_compat_mode, true ) ) + { + // overlapAddEvs_fx( frm_in_fx, frm_in_fx + xtract, frm_out_fx, l_seg, ps->num_channels, ps->win_fx + ps->l_halfwin_fx, ps->win_fx ); + overlapAdd( frm_in_fx, frm_in_fx + xtract, frm_out_fx, l_seg, ps->num_channels, ps->win_fx + ps->l_halfwin, ps->win_fx, ps->win_incrementor ); + } + ELSE + { + overlapAdd( frm_in_fx, frm_in_fx + xtract, frm_out_fx, l_seg, ps->num_channels, ps->win_fx + ps->l_halfwin, ps->win_fx, ps->win_incrementor ); + } + } + ELSE + { + xtract = 0; + move16(); + FOR( i = 0; i < l_seg; i++ ) + { + frm_out_fx[i] = frm_in_fx[i]; + move16(); + } + } + + /* append remaining samples */ + l_rem = extract_l( L_sub( L_sub( l_frm, xtract ), l_seg ) ); + FOR( i = 0; i < l_rem; i++ ) + { + frm_out_fx[l_seg + i] = frm_in_fx[l_frm - l_rem + i]; + move16(); + } + + /* set output length */ + *l_frm_out = u_extract_l( UL_addNsD( l_seg, l_rem ) ); + move16(); + + return 0; +} + /* ******************************************************************************** * @@ -1994,3 +2172,262 @@ static bool extend_frm_fx( move16(); return 0; } + + +static bool extend_frm_ivas_fx( + apa_state_t *ps, + const Word16 frm_in_fx[], // Qx + Word16 frm_out_fx[], // Qx + Word16 Q_frm_in, + UWord16 *l_frm_out ) +{ + bool findSynchResult = 0; + move16(); + UWord16 l_frm_out_target; + UWord16 n, i; + Word16 N; + Word16 s[MAXN + 2], s_max, s_min; + Word16 xtract[MAXN + 2], sync_start, s_end; + UWord16 over[MAXN + 2]; + Word16 l_rem; + Word16 s_start = 0; + move16(); + Word16 energy_fx; + Word32 quality_fx = 0; + move32(); + UWord16 l_frm, l_seg; + const Word16 *fadeOut_fx, *fadeIn_fx; + Word16 *out_fx; + + l_frm = ps->l_frm; + l_seg = ps->l_seg; + move16(); + move16(); + /* number of segments/iterations */ + l_frm_out_target = (UWord16) ( L_add( l_frm, L_shr( l_frm, 1 ) ) ); + //(l_frm_out_target/l_seg -1 ) + Word16 tmp, tmp_e; + tmp = BASOP_Util_Divide3232_Scale( l_frm_out_target, l_seg, &tmp_e ); + tmp = shr( tmp, sub( 15, tmp_e ) ); + N = sub( ( tmp ), 1 ); + if ( LT_16( N, 1 ) ) + { + N = 1; + move16(); + } + IF( GT_16( N, MAXN ) ) + { + return 1; + } + /* calculate equally spaced search regions */ + /* s[n] are given relative to 2nd frame and point to the start of */ + /* the search region. The first segment (n=1) will not be moved. */ + /* Hence, the iterations will start with n=2. */ + s_min = extract_l( L_negate( L_add( ps->l_search, ps->p_min ) ) ); + /* (make sure not to exceed array dimension) */ + IF( L_add( l_frm, s_min ) < 0 ) + { + s_min = extract_l( L_negate( l_frm ) ); + } + s_max = extract_l( L_sub( L_sub( l_frm, L_shl( l_seg, 1 ) ), ps->l_search ) ); + if ( s_max < s_min ) + { + N = 1; + move16(); + } + /* for just one segment start at s_min */ + if ( N == 1 ) + { + s[2] = s_min; + move16(); + } + /* else, spread linear in between s_min and s_max */ + /* (including s_min and s_max) */ + ELSE + { + FOR( n = 2; n <= ( N + 1 ); n++ ) + { + // s[n] = s_min + ( ( s_max - s_min ) * ( n - 2 ) ) / ( N - 1 ); + Word16 tmp2, tmp2_e; + tmp2 = sub( s_max, s_min ); + tmp2 = i_mult( tmp2, extract_l( L_sub( n, 2 ) ) ); + tmp2 = BASOP_Util_Divide1616_Scale( tmp2, sub( N, 1 ), &tmp2_e ); + tmp2 = shr( tmp2, sub( 15, tmp2_e ) ); + s[n] = add( s_min, tmp2 ); + move16(); + } + } + + /* + * Planning Phase + */ + + xtract[1] = extract_l( L_negate( l_seg ) ); /* make sync_start=0 in 1st iteration */ + move16(); + n = 2; + move16(); + /* define synch segment (to be correlated with search region) */ + sync_start = extract_l( L_add( xtract[n - 1], l_seg ) ); + over[n] = 1; /* will be reset if overlap is not required */ + move16(); + /* check end of search region: should be at least p_min */ + /* samples on the left of synch_start */ + IF( LT_32( L_add( s[n], ps->l_search ), L_sub( sync_start, ( ps->p_min ) ) ) ) + { + s_start = s[n]; + move16(); + s_end = extract_l( L_add( s_start, ps->l_search ) ); + } + ELSE + { + /* shrink search region to enforce minimum shift */ + s_end = extract_l( L_sub( sync_start, ( ps->p_min ) ) ); + IF( LT_16( extract_l( L_add( s[n], ps->l_search ) ), sync_start ) ) + { + s_start = s[n]; /* just do it with normal start position */ + move16(); + } + ELSE IF( EQ_32( n, L_add( N, 1 ) ) ) /* move search region left for last segment */ + { + s_start = extract_l( L_sub( s_end, L_sub( ps->l_search, ps->p_min ) ) ); + } + ELSE + { + over[n] = 0; /* don't search/overlap (just copy down) */ + move16(); + } + } + + IF( over[n] ) + { + /* calculate overlap position */ + IF( isSilence_fx( frm_in_fx, l_seg, 10 ) ) + { + /* maximum scaling */ + energy_fx = -65 * ( 1 << 8 ); // Q8 + move16(); + quality_fx = 5 << 16; // Q16 + move32(); + xtract[n] = extract_l( L_add( s_start, ps->num_channels ) ); + move16(); + IF( ps->evs_compat_mode == false ) + { + /* take renderer buffer samples into accout */ + xtract[n] = extract_l( L_add( xtract[n], ps->l_r_buf ) ); + /* snap to next renderer time slot border to resynchronize */ + // xtract[n] -= ( ( N - 1 ) * l_seg - xtract[n] + ps->l_r_buf ) % ps->l_ts; + Word16 tmp3; + tmp3 = extract_l( L_add( L_sub( W_extract_l( W_mult0_32_32( L_sub( N, 1 ), l_seg ) ), xtract[n] ), ps->l_r_buf ) ); + xtract[n] = sub( xtract[n], tmp3 % ps->l_ts ); + move16(); + move16(); + } + } + ELSE + { + Word16 *frmInScaled; + frmInScaled = ps->frmInScaled; + assert( sizeof( ps->frmInScaled ) / sizeof( ps->frmInScaled[0] ) >= 2 * (size_t) l_frm ); + scaleSignal16( frm_in_fx, frmInScaled, shl( l_frm, 1 ), ps->signalScaleForCorrelation ); + ps->signalScaleForCorrelation = sub( ps->signalScaleForCorrelation, Q_frm_in ); + findSynchResult = find_synch_fx( ps, frmInScaled, extract_l( L_shl( l_frm, 1 ) ), s_start, sub( s_end, s_start ), sync_start, l_seg, l_frm, &energy_fx, &quality_fx, &xtract[n] ); + ps->signalScaleForCorrelation = add( ps->signalScaleForCorrelation, Q_frm_in ); + } + /* assert synch_pos is cleanly divisible by number of channels */ + assert( xtract[n] % ps->num_channels == 0 ); + + /* test for sufficient quality */ + IF( LT_32( quality_fx, L_add( L_sub( ps->targetQuality_fx, + L_mult0( ps->bad_frame_count, 6554 /*.1f in Q16*/ ) ), + L_mult0( ps->good_frame_count, 13107 /*.1f in Q16*/ ) ) ) ) + { + /* not sufficient */ + over[n] = 0; + move16(); + xtract[n] = sync_start; + move16(); + IF( LT_32( ps->bad_frame_count, ps->qualityred ) ) + { + ps->bad_frame_count = u_extract_l( UL_addNsD( ps->bad_frame_count, 1 ) ); + move16(); + } + IF( GT_32( ps->good_frame_count, 0 ) ) + { + ps->good_frame_count = u_extract_l( UL_subNsD( ps->good_frame_count, 1 ) ); + move16(); + } + } + ELSE + { + /* sufficient quality */ + IF( GT_32( ps->bad_frame_count, 0 ) ) + { + ps->bad_frame_count = u_extract_l( UL_subNsD( ps->bad_frame_count, 1 ) ); + move16(); + } + IF( LT_32( ps->good_frame_count, ps->qualityrise ) ) + { + ps->good_frame_count = u_extract_l( UL_addNsD( ps->good_frame_count, 1 ) ); + move16(); + } + } + IF( findSynchResult ) + { + return 1; + } + } + ELSE + { + xtract[n] = sync_start; + move16(); + } + + + /* Calculate output data */ + FOR( n = 2; n <= N; n++ ) + { + test(); + IF( over[n] && NE_16( extract_l( L_add( xtract[n - 1], l_seg ) ), xtract[n] ) ) + { + /* mix 2nd half of previous segment with 1st half of current segment */ + fadeOut_fx = frm_in_fx + l_frm + xtract[n - 1] + l_seg; + fadeIn_fx = frm_in_fx + l_frm + xtract[n]; + out_fx = frm_out_fx + ( n - 2 ) * l_seg; + IF( EQ_16( ps->evs_compat_mode, true ) ) + { + // overlapAddEvs_fx( fadeOut_fx, fadeIn_fx, out_fx, l_seg, ps->num_channels, ps->win_fx + ps->l_halfwin_fx, ps->win_fx ); + overlapAdd( fadeOut_fx, fadeIn_fx, out_fx, l_seg, ps->num_channels, ps->win_fx + ps->l_halfwin, ps->win_fx, ps->win_incrementor ); + } + ELSE + { + overlapAdd( fadeOut_fx, fadeIn_fx, out_fx, l_seg, ps->num_channels, ps->win_fx + ps->l_halfwin, ps->win_fx, ps->win_incrementor ); + } + } + ELSE + { + /* just copy down 1st half of current segment (= 2nd half of previous segment) */ + Word16 *frm_out_ptr; + const Word16 *frm_in_ptr; + frm_out_ptr = &( frm_out_fx[( n - 2 ) * l_seg] ); + frm_in_ptr = &( frm_in_fx[l_frm + xtract[n]] ); + FOR( i = 0; i < l_seg; i++ ) + { + frm_out_ptr[i] = frm_in_ptr[i]; + move16(); + } + } + } + + /* append remaining samples */ + l_rem = l_frm - ( xtract[N] + l_seg ); + FOR( i = 0; i < l_rem; i++ ) + { + frm_out_fx[( N - 1 ) * l_seg + i] = frm_in_fx[2 * l_frm - l_rem + i]; + move16(); + } + + /* set output length */ + *l_frm_out = (UWord16) ( W_mult0_32_32( L_sub( N, 1 ), L_add( l_seg, l_rem ) ) ); + move16(); + return 0; +} -- GitLab From 805cf3ce9a16a03d2cd8710879780eb61b9ed324 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Tue, 12 Nov 2024 17:40:04 +0530 Subject: [PATCH 111/128] Fix for 3GPP issue 1011: IVAS_rend OMASA BINAURAL rendering has very low gain for ISM --- lib_rend/lib_rend.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib_rend/lib_rend.c b/lib_rend/lib_rend.c index 90ac02ce1..2094ce820 100644 --- a/lib_rend/lib_rend.c +++ b/lib_rend/lib_rend.c @@ -12699,6 +12699,8 @@ static ivas_error renderInputMasa( Scale_sig32( tmpBuffer_buff_fx[0], L_FRAME48k, sub( Q11, *outAudio.pq_fact ) ); /* Q11 */ Scale_sig32( tmpBuffer_buff_fx[1], L_FRAME48k, sub( Q11, *outAudio.pq_fact ) ); /* Q11 */ + scale_sig32( outAudio.data_fx, i_mult( outAudio.config.numChannels, outAudio.config.numSamplesPerChannel ), sub( Q11, *outAudio.pq_fact ) ); + ivas_masa_ext_rend_parambin_render_fx( masaInput->hMasaExtRend, *masaInput->base.ctx.pCombinedOrientationData, tmpBuffer_fx, num_subframes ); *outAudio.pq_fact = Q11; move16(); -- GitLab From ad36eba23882e593d968cf8c9d0a34f47466dea6 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Tue, 12 Nov 2024 17:44:03 +0530 Subject: [PATCH 112/128] Fix for 3GPP issue 1027: Decoder crash for FOA at 32kbps JBM operation in highband_exc_dct_in_ivas_fx() link #1027 --- lib_com/gs_noisefill_fx.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib_com/gs_noisefill_fx.c b/lib_com/gs_noisefill_fx.c index 9f4ef9810..36845a545 100644 --- a/lib_com/gs_noisefill_fx.c +++ b/lib_com/gs_noisefill_fx.c @@ -1321,9 +1321,9 @@ void highband_exc_dct_in_ivas_fx( { FOR( i = 0; i < last_bin; i++ ) { - Ener_per_bd_iQ[i] = s_min( Ener_per_bd_iQ[i], sub( sub( lt_ener_per_band_fx[i], 154 ), Ener_per_bd_yQ[i] ) ); + Ener_per_bd_iQ[i] = s_min( Ener_per_bd_iQ[i], sub_sat( sub_sat( lt_ener_per_band_fx[i], 154 ), Ener_per_bd_yQ[i] ) ); move16(); - lt_ener_per_band_fx[i] = sub( lt_ener_per_band_fx[i], 77 ); + lt_ener_per_band_fx[i] = sub_sat( lt_ener_per_band_fx[i], 77 ); move16(); } FOR( ; i < MBANDS_GN; i++ ) -- GitLab From c29561ba43940cefae2d4a956d104b64b187346d Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Wed, 13 Nov 2024 09:41:36 +0530 Subject: [PATCH 113/128] Fix for 3GPP issue 975: Higher MLD in MDCT-Stereo mono output than in stereo out --- lib_dec/ivas_stereo_mdct_stereo_dec.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/lib_dec/ivas_stereo_mdct_stereo_dec.c b/lib_dec/ivas_stereo_mdct_stereo_dec.c index b83432db3..91c192c5b 100644 --- a/lib_dec/ivas_stereo_mdct_stereo_dec.c +++ b/lib_dec/ivas_stereo_mdct_stereo_dec.c @@ -604,7 +604,7 @@ void stereo_decoder_tcx_fx( Word16 i, k, sfb, nSubframes; STEREO_MDCT_BAND_PARAMETERS *sfbConf = NULL; Word32 nrgRatio, inv_nrgRatio, tmp_32; - Word16 tmp, tmp_e, shift; + Word16 tmp_e, shift; nSubframes = 2; move16(); @@ -717,11 +717,12 @@ void stereo_decoder_tcx_fx( IF( !mct_on ) { - tmp = BASOP_Util_Divide3216_Scale( ( SMDCT_ILD_RANGE << 26 ), hStereoMdct->global_ild[k], &tmp_e ); - tmp_32 = L_shr( (Word32) tmp, negate( add( 1, tmp_e ) ) ); /* nrgRatio = nrg[1]/nrg[0] */ // Q26 - nrgRatio = L_sub( tmp_32, 67108864 ); /* 1.0f in Q26 */ + tmp_32 = BASOP_Util_Divide3232_Scale_cadence( SMDCT_ILD_RANGE << 16, L_deposit_h( hStereoMdct->global_ild[k] ), &tmp_e ); + tmp_32 = L_shr( tmp_32, sub( 5, tmp_e ) ); /* nrgRatio = nrg[1]/nrg[0] */ // Q26 + nrgRatio = L_sub( tmp_32, ONE_IN_Q26 ); // Q26 - hStereoMdct->smooth_ratio_fx = L_add( Mpy_32_32( POINT_8_FIXED, hStereoMdct->smooth_ratio_fx ), Mpy_32_32( POINT_2_FIXED, nrgRatio ) ); // Q26 + hStereoMdct->smooth_ratio_fx = W_extract_h( W_mac_32_32( W_mult_32_32( POINT_8_FIXED, hStereoMdct->smooth_ratio_fx ), POINT_2_FIXED, nrgRatio ) ); // Q26 + move32(); /* set flag to reverse dmx computation in case of right-side panning, only relevant for mono output */ IF( GT_32( hStereoMdct->smooth_ratio_fx, ONE_POINT_3_FIXED ) ) { @@ -771,8 +772,7 @@ void stereo_decoder_tcx_fx( } ELSE IF( ( LT_32( nrgRatio, ONE_IN_Q26 ) ) && ( LT_16( k, tmp2 ) ) ) { - tmp = BASOP_Util_Divide3232_Scale( ONE_IN_Q26, nrgRatio, &tmp_e ); - inv_nrgRatio = L_deposit_h( tmp ); /* Q31 - tmp_e */ + inv_nrgRatio = BASOP_Util_Divide3232_Scale_cadence( ONE_IN_Q26, nrgRatio, &tmp_e ); shift = sub( 5, tmp_e ); v_multc_fixed( spec_l[k], inv_nrgRatio, spec_l[k], L_frameTCX_l ); /* spec_r will be in Qx - tmp_e */ Scale_sig32( spec_l[k], L_frameTCX_l, sub( 5, shift ) ); /* Qx */ -- GitLab From a3388112d14f071b9d70b59c8c68149ed5845029 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Wed, 13 Nov 2024 10:54:16 +0530 Subject: [PATCH 114/128] LTV crash fixes for encoder, float struct elements cleanup --- lib_com/ivas_dirac_com.c | 18 ++-- lib_dec/er_dec_tcx_fx.c | 5 +- lib_dec/tonalMDCTconcealment_fx.c | 4 + lib_enc/core_switching_enc.c | 11 ++- lib_enc/init_enc.c | 9 +- lib_enc/ivas_core_enc.c | 11 ++- lib_enc/ivas_core_pre_proc.c | 1 + lib_enc/ivas_masa_enc.c | 6 +- lib_enc/ivas_spar_encoder.c | 8 +- lib_enc/ivas_stereo_switching_enc.c | 4 +- lib_enc/ivas_stereo_td_enc.c | 5 +- lib_enc/ivas_tcx_core_enc.c | 7 +- lib_enc/prot_fx_enc.h | 4 + lib_enc/stat_enc.h | 58 +++++-------- lib_enc/swb_bwe_enc_fx.c | 90 ++++++++++++++------ lib_enc/swb_tbe_enc.c | 68 +++------------ lib_enc/swb_tbe_enc_fx.c | 127 +++++++++++++++++++++++++--- 17 files changed, 270 insertions(+), 166 deletions(-) diff --git a/lib_com/ivas_dirac_com.c b/lib_com/ivas_dirac_com.c index 214910cd3..aea7d7664 100644 --- a/lib_com/ivas_dirac_com.c +++ b/lib_com/ivas_dirac_com.c @@ -2100,7 +2100,8 @@ void calculate_hodirac_sector_parameters_fx( normI_fx = BASOP_Util_Add_Mant32Exp( tmp32, tmp_e, tmp_z, shl( *p_sec_I_vec_smth_z_exp, 1 ), &normI_exp ); normI_fx = Sqrt32( normI_fx, &normI_exp ); - tmp_xy_hypo = Sqrt32( tmp32, &tmp_e ); // sqrt(x^2 + y^2) + tmp32 = BASOP_Util_Add_Mant32Exp( tmp32, tmp_e, 0, 0, &tmp_e ); // normalising value of tmp32 + tmp_xy_hypo = Sqrt32( tmp32, &tmp_e ); // sqrt(x^2 + y^2) tmp16 = BASOP_util_atan2( *p_sec_I_vec_smth_y_fx, *p_sec_I_vec_smth_x_fx, sub( *p_sec_I_vec_smth_y_exp, *p_sec_I_vec_smth_x_exp ) ); // Q13 *p_azi_fx = Mpy_32_32( L_deposit_h( tmp16 ), _180_OVER_PI_Q25 ); // (Q13 + 16) + Q25 - 31 = 54 - 31 = Q23 @@ -2124,9 +2125,8 @@ void calculate_hodirac_sector_parameters_fx( move32(); tmp_diff_exp = *p_diff_exp; move16(); - // NOTE: here, assuming abs(tmp_diff) <= 1.0. --> Q30 - tmp_diff_fx = L_shr( tmp_diff_fx, sub( 1, tmp_diff_exp ) ); - tmp_diff_exp = 1; + tmp_diff_fx = L_shr( tmp_diff_fx, sub( 2, tmp_diff_exp ) ); // Q29 + tmp_diff_exp = 2; move16(); IF( tmp_diff_fx < 0 ) @@ -2134,7 +2134,7 @@ void calculate_hodirac_sector_parameters_fx( *p_diff_fx = 0; move32(); } - IF( GT_32( tmp_diff_fx, ( ONE_IN_Q30 / 2 ) ) ) + IF( GT_32( tmp_diff_fx, ( ONE_IN_Q29 / 2 ) ) ) { IF( hDirAC->firstrun_sector_params ) { @@ -2145,13 +2145,13 @@ void calculate_hodirac_sector_parameters_fx( } ELSE { - *p_azi_fx = L_shl( L_add( Mpy_32_32( L_sub( ONE_IN_Q30, tmp_diff_fx ), *p_azi_fx ), Mpy_32_32( L_sub( tmp_diff_fx, ONE_IN_Q30 / 2 ), *p_azi_prev_fx ) ), 1 ); // Q30 + Q23 - 31 = Q22 + *p_azi_fx = L_shl( L_add( Mpy_32_32( L_sub( ONE_IN_Q29, tmp_diff_fx ), *p_azi_fx ), Mpy_32_32( L_sub( tmp_diff_fx, ONE_IN_Q29 / 2 ), *p_azi_prev_fx ) ), 1 ); // Q29 + Q23 - 31 = Q21 move32(); - *p_ele_fx = L_shl( L_add( Mpy_32_32( L_sub( ONE_IN_Q30, tmp_diff_fx ), *p_ele_fx ), Mpy_32_32( L_sub( tmp_diff_fx, ONE_IN_Q30 / 2 ), *p_ele_prev_fx ) ), 1 ); // Q30 + Q23 - 31 = Q22 + *p_ele_fx = L_shl( L_add( Mpy_32_32( L_sub( ONE_IN_Q29, tmp_diff_fx ), *p_ele_fx ), Mpy_32_32( L_sub( tmp_diff_fx, ONE_IN_Q29 / 2 ), *p_ele_prev_fx ) ), 1 ); // Q29 + Q23 - 31 = Q21 move32(); - *p_azi_fx = L_shl( *p_azi_fx, 1 ); // Q22 -> Q23; + *p_azi_fx = L_shl( *p_azi_fx, 2 ); // Q21 -> Q23; move32(); - *p_ele_fx = L_shl( *p_ele_fx, 1 ); // Q22 -> Q23; + *p_ele_fx = L_shl( *p_ele_fx, 2 ); // Q21 -> Q23; move32(); } } diff --git a/lib_dec/er_dec_tcx_fx.c b/lib_dec/er_dec_tcx_fx.c index ab1d72279..897d6f2e7 100644 --- a/lib_dec/er_dec_tcx_fx.c +++ b/lib_dec/er_dec_tcx_fx.c @@ -2104,8 +2104,9 @@ void con_tcx_ivas_fx( move16(); /* create aliasing and windowing need for transition to TCX10/5 */ - bufferCopyFx( syn + L_frame, hTcxDec->syn_Overl_TDACFB, shr( L_frame, 1 ), Q_syn, 0, -1, 0 ); - hTcxDec->Q_syn_Overl_TDACFB = add( Q_syn, -1 ); + // bufferCopyFx( syn + L_frame, hTcxDec->syn_Overl_TDACFB, shr( L_frame, 1 ), Q_syn, 0, -1, 0 ); + Copy_Scale_sig( syn + L_frame, hTcxDec->syn_Overl_TDACFB, shr( L_frame, 1 ), sub( Q_syn, 1 ) ); + hTcxDec->Q_syn_Overl_TDACFB = sub( Q_syn, 1 ); move16(); FOR( i = 0; i < W12; i++ ) diff --git a/lib_dec/tonalMDCTconcealment_fx.c b/lib_dec/tonalMDCTconcealment_fx.c index 0170aa985..fa085d987 100644 --- a/lib_dec/tonalMDCTconcealment_fx.c +++ b/lib_dec/tonalMDCTconcealment_fx.c @@ -231,6 +231,10 @@ ivas_error TonalMDCTConceal_Init_ivas_fx( move16(); move16(); /* just the second half of the second last pcm output is needed */ + +#ifdef MSAN_FIX + set16_fx( hTonalMDCTConc->timeDataBuffer, 0, ( 3 * L_FRAME_MAX ) / 2 ); +#endif hTonalMDCTConc->secondLastPcmOut = &hTonalMDCTConc->timeDataBuffer[( 3 * L_FRAME_MAX ) / 2 - ( 3 * min( L_FRAME_MAX, nSamples ) / 2 )]; hTonalMDCTConc->lastPcmOut = &hTonalMDCTConc->timeDataBuffer[( 3 * L_FRAME_MAX ) / 2 - min( L_FRAME_MAX, nSamples )]; /* If the second last frame was lost, we reuse saved TonalComponentsInfo and don't update pcm buffers */ diff --git a/lib_enc/core_switching_enc.c b/lib_enc/core_switching_enc.c index c5f197eeb..142248112 100644 --- a/lib_enc/core_switching_enc.c +++ b/lib_enc/core_switching_enc.c @@ -957,10 +957,6 @@ void core_switching_post_enc( #ifdef IVAS_FLOAT_FIXED InitSWBencBufferStates_fx( st->hBWE_TD, NULL ); swb_tbe_reset_fx( st->hBWE_TD->mem_csfilt_fx, st->hBWE_TD->mem_genSHBexc_filt_down_shb_fx, st->hBWE_TD->state_lpc_syn_fx, st->hBWE_TD->syn_overlap_fx, st->hBWE_TD->state_syn_shbexc_fx, &( st->hBWE_TD->tbe_demph_fx ), &( st->hBWE_TD->tbe_premph_fx ), st->hBWE_TD->mem_stp_swb_fx, &( st->hBWE_TD->gain_prec_swb_fx ) ); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - /* To be removed later when the function is converted to fixed*/ - InitSWBencBufferStates( st->hBWE_TD, NULL ); -#endif #else InitSWBencBufferStates( st->hBWE_TD, NULL ); swb_tbe_reset( st->hBWE_TD->mem_csfilt, st->hBWE_TD->mem_genSHBexc_filt_down_shb, st->hBWE_TD->state_lpc_syn, st->hBWE_TD->syn_overlap, st->hBWE_TD->state_syn_shbexc, &( st->hBWE_TD->tbe_demph ), &( st->hBWE_TD->tbe_premph ), st->hBWE_TD->mem_stp_swb, &( st->hBWE_TD->gain_prec_swb ) ); @@ -1007,11 +1003,14 @@ void core_switching_post_enc( /* Interp_3_2 CNG buffers reset */ if ( st->extl == FB_TBE && ( ( st->last_extl != FB_TBE && st->last_core != TCX_20_CORE && st->last_core != TCX_10_CORE ) || st->L_frame != st->last_L_frame ) ) { - set_f( st->hBWE_TD->fb_state_lpc_syn, 0, LPC_SHB_ORDER ); - st->hBWE_TD->fb_tbe_demph = 0; #ifdef IVAS_FLOAT_FIXED + set16_fx( st->hBWE_TD->fb_state_lpc_syn_fx, 0, LPC_SHB_ORDER ); + st->hBWE_TD->fb_tbe_demph_fx = 0; + move16(); fb_tbe_reset_enc_fx( st->hBWE_TD->elliptic_bpf_2_48k_mem_fx, &st->hBWE_TD->prev_fb_energy_fx, st->hBWE_TD->elliptic_bpf_2_48k_mem_fx_Q, &st->hBWE_TD->prev_fb_energy_fx_Q ); #else + set_f( st->hBWE_TD->fb_state_lpc_syn, 0, LPC_SHB_ORDER ); + st->hBWE_TD->fb_tbe_demph = 0; fb_tbe_reset_enc( st->hBWE_TD->elliptic_bpf_2_48k_mem, &st->hBWE_TD->prev_fb_energy ); #endif } diff --git a/lib_enc/init_enc.c b/lib_enc/init_enc.c index 355aab8d2..c754fe4bb 100644 --- a/lib_enc/init_enc.c +++ b/lib_enc/init_enc.c @@ -827,9 +827,13 @@ ivas_error init_encoder( InitSWBencBuffer( st->hBWE_TD ); #ifdef IVAS_FLOAT_FIXED - InitSWBencBuffer_fx( st ); + InitSWBencBuffer_ivas_fx( st ); #endif +#ifndef IVAS_FLOAT_FIXED ResetSHBbuffer_Enc( st->hBWE_TD ); +#else + ResetSHBbuffer_Enc_fx( st ); +#endif } else { @@ -1991,11 +1995,10 @@ ivas_error init_encoder_ivas_fx( return error; } - InitSWBencBuffer_fx( st ); + InitSWBencBuffer_ivas_fx( st ); ResetSHBbuffer_Enc_fx( st ); #if 1 InitSWBencBuffer( st->hBWE_TD ); - ResetSHBbuffer_Enc( st->hBWE_TD ); #endif } ELSE diff --git a/lib_enc/ivas_core_enc.c b/lib_enc/ivas_core_enc.c index d5939811b..a80c36ad4 100644 --- a/lib_enc/ivas_core_enc.c +++ b/lib_enc/ivas_core_enc.c @@ -905,7 +905,7 @@ ivas_error ivas_core_enc( } fixedToFloat_arr( new_swb_speech_fx_16, new_swb_speech, 0, L_FRAME48k ); - fixedToFloat_arr( shb_speech_fx, shb_speech, 0, L_FRAME16k ); + fixedToFloat_arr( shb_speech_fx, shb_speech, Q_shb_spch, L_FRAME16k ); fixedToFloat_arrL32( (Word32 *) &realBuffer_fx[0][0], (float *) &realBuffer[n][0][0], q_realImagBuffer, CLDFB_NO_COL_MAX * CLDFB_NO_CHANNELS_MAX ); fixedToFloat_arrL32( (Word32 *) &imagBuffer_fx[0][0], (float *) &imagBuffer[n][0][0], q_realImagBuffer, CLDFB_NO_COL_MAX * CLDFB_NO_CHANNELS_MAX ); @@ -930,9 +930,12 @@ ivas_error ivas_core_enc( if ( st->hBWE_TD != NULL ) { #ifdef IVAS_FLOAT_FIXED +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + floatToFixed_arr( shb_speech, shb_speech_fx, Q_shb_spch, L_FRAME16k ); +#endif InitSWBencBufferStates_fx( st->hBWE_TD, shb_speech_fx ); #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - InitSWBencBufferStates( st->hBWE_TD, shb_speech ); + fixedToFloat_arr( shb_speech_fx, shb_speech, Q_shb_spch, L_FRAME16k ); #endif #else InitSWBencBufferStates( st->hBWE_TD, shb_speech ); @@ -997,15 +1000,11 @@ ivas_error ivas_core_enc( // Q_input is being calculated inside already Word16 Q_input = 0; floatToFixed_arr( st->input_buff, st->input_buff_fx, Q_input, L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ) ); - Word16 len_old_input_fhb_fx = NS2SA( 48000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_12k8_NS + DELAY_FIR_RESAMPL_NS ) - L_FRAME48k / 2; - st->hBWE_TD->old_input_fhb_fx_Q = Q_factor_arr( st->hBWE_TD->old_input_fhb, len_old_input_fhb_fx ); - floatToFixed_arr( st->hBWE_TD->old_input_fhb, st->hBWE_TD->old_input_fhb_fx, st->hBWE_TD->old_input_fhb_fx_Q, len_old_input_fhb_fx ); #endif fb_tbe_enc_ivas_fx( st, st->input_fx, fb_exc_fx, Q_fb_exc ); #ifdef IVAS_FLOAT_FIXED_CONVERSIONS fixedToFloat_arr( fb_exc_fx, fb_exc, Q_fb_exc, L_FRAME16k ); fixedToFloat_arr( st->input_fx, st->input, Q_input, L_FRAME48k ); - fixedToFloat_arr( st->hBWE_TD->old_input_fhb_fx, st->hBWE_TD->old_input_fhb, st->hBWE_TD->old_input_fhb_fx_Q, len_old_input_fhb_fx ); #endif #endif } diff --git a/lib_enc/ivas_core_pre_proc.c b/lib_enc/ivas_core_pre_proc.c index ecb5d2ecd..bef00f87a 100644 --- a/lib_enc/ivas_core_pre_proc.c +++ b/lib_enc/ivas_core_pre_proc.c @@ -1165,6 +1165,7 @@ ivas_error ivas_compute_core_buffers( floatToFixed_arr16( new_inp_resamp16k, new_inp_resamp16k_fx, Q_old_inp_16k, L_FRAME16k ); #endif + f2me_buf_16( st->old_inp_12k8, st->old_inp_12k8_fx, &st->exp_old_inp_12k8, 240 ); floatToFixed_arr16( st->old_inp_16k, st->old_inp_16k_fx, Q_old_inp_16k, L_INP_MEM ); floatToFixed_arr16( st->mem_decim16k, st->mem_decim16k_fx, Q_old_inp_16k, 2 * L_FILT_MAX ); floatToFixed_arr16( st->inp_16k_mem_stereo_sw, st->inp_16k_mem_stereo_sw_fx, Q_old_inp_16k, STEREO_DFT_OVL_16k - L_MEM_RECALC_16K - L_FILT16k ); diff --git a/lib_enc/ivas_masa_enc.c b/lib_enc/ivas_masa_enc.c index 9fc3a0de5..7d841a9a0 100644 --- a/lib_enc/ivas_masa_enc.c +++ b/lib_enc/ivas_masa_enc.c @@ -5150,9 +5150,9 @@ static void average_masa_metadata_fx( FOR( j = 0; j < MAX_PARAM_SPATIAL_SUBFRAMES; j++ ) { - azi_rad_fx = extract_l( Mpy_32_32( hMeta->directional_meta[i].azimuth_fx[j][k], 2670177 /*1/(2*pi) in Q24*/ ) ); /*=angle *(1/2pi) brings the azi_rad_fx in -32767 to 32767 in q15 (this argument is further passed in cos and sin functions)*/ /*22+24-31=15*/ - ele_rad_fx = extract_l( Mpy_32_32( hMeta->directional_meta[i].elevation_fx[j][k], 2670177 /*1/(2*pi) in Q24*/ ) ); /*=angle *(1/2pi) brings the azi_rad_fx in -32767 to 32767 in q15 (this argument is further passed in cos and sin functions)*/ /*22+24-31=15*/ - vec_len_fx = extract_l( Mpy_32_32( hMeta->directional_meta[i].energy_ratio_fx[j][k] /*q30*/, energy[j][k] ) ); /*exponent=energy_e+1*/ + azi_rad_fx = extract_l( Mpy_32_32( hMeta->directional_meta[i].azimuth_fx[j][k], 46603 /*1/(360) in Q24*/ ) ); /*=angle *(1/2pi) brings the azi_rad_fx in -32767 to 32767 in q15 (this argument is further passed in cos and sin functions)*/ /*22+24-31=15*/ + ele_rad_fx = extract_l( Mpy_32_32( hMeta->directional_meta[i].elevation_fx[j][k], 46603 /*1/(360) in Q24*/ ) ); /*=angle *(1/2pi) brings the azi_rad_fx in -32767 to 32767 in q15 (this argument is further passed in cos and sin functions)*/ /*22+24-31=15*/ + vec_len_fx = Mpy_32_32( hMeta->directional_meta[i].energy_ratio_fx[j][k] /*q30*/, energy[j][k] ); /*exponent=energy_e+1*/ vec_len_e = add( energy_e[j][k], 1 ); /* energy-weighted sum over subframes */ diff --git a/lib_enc/ivas_spar_encoder.c b/lib_enc/ivas_spar_encoder.c index 2d83970c6..6339bc639 100644 --- a/lib_enc/ivas_spar_encoder.c +++ b/lib_enc/ivas_spar_encoder.c @@ -1002,12 +1002,13 @@ static ivas_error ivas_spar_enc_process_fx( { p_pcm_tmp_fx[i] = pcm_tmp_fx[i]; } - /* Need to remove flt to fix conversions */ + + /* run Filter Bank overlapping MDFT analysis first, then we can use the temporary buffer for Parameter MDFT analysis*/ ivas_fb_mixer_pcm_ingest_fx( hSpar->hFbMixer, data_fx, p_pcm_tmp_fx, input_frame, hSpar->hMdEnc->HOA_md_ind, q_data, q_p_pcm_tmp_fx ); FOR( i = 0; i < hSpar->hFbMixer->fb_cfg->num_in_chans; i++ ) { /* changing q format to q_data*/ - scale_sig32( p_pcm_tmp_fx[i], input_frame, sub( q_data, q_p_pcm_tmp_fx[i] ) ); + scale_sig32( p_pcm_tmp_fx[i], shl( input_frame, 1 ), sub( q_data, q_p_pcm_tmp_fx[i] ) ); } /* prepare Parameter MDFT analysis */ @@ -1032,6 +1033,8 @@ static ivas_error ivas_spar_enc_process_fx( p_pcm_tmp_fx[i] += l_ts; ppIn_FR_real_fx[i] += l_ts; ppIn_FR_imag_fx[i] += l_ts; + q_p_pcm_tmp_fx[i] = sub( q_data, gb ); // updating the q for p_pcm + move16(); } } @@ -1111,6 +1114,7 @@ static ivas_error ivas_spar_enc_process_fx( return error; } + set16_fx( q_p_pcm_tmp_fx, pp_fr_q, nchan_fb_in ); /*-----------------------------------------------------------------------------------------* * FB mixer *-----------------------------------------------------------------------------------------*/ diff --git a/lib_enc/ivas_stereo_switching_enc.c b/lib_enc/ivas_stereo_switching_enc.c index 3a3c6c0bb..cf683d621 100644 --- a/lib_enc/ivas_stereo_switching_enc.c +++ b/lib_enc/ivas_stereo_switching_enc.c @@ -524,8 +524,8 @@ ivas_error stereo_memory_enc_fx( } InitSWBencBuffer( st->hBWE_TD ); - InitSWBencBuffer_fx( st ); - ResetSHBbuffer_Enc( st->hBWE_TD ); + InitSWBencBuffer_ivas_fx( st ); + ResetSHBbuffer_Enc_fx( st ); IF( ( st->hBWE_FD = (FD_BWE_ENC_HANDLE) malloc( sizeof( FD_BWE_ENC_DATA ) ) ) == NULL ) { diff --git a/lib_enc/ivas_stereo_td_enc.c b/lib_enc/ivas_stereo_td_enc.c index 01737ac5b..b0e3355c8 100644 --- a/lib_enc/ivas_stereo_td_enc.c +++ b/lib_enc/ivas_stereo_td_enc.c @@ -421,12 +421,9 @@ ivas_error stereo_set_tdm_fx( InitSWBencBuffer( st->hBWE_TD ); #ifdef IVAS_FLOAT_FIXED - InitSWBencBuffer_fx( st ); + InitSWBencBuffer_ivas_fx( st ); #endif - ResetSHBbuffer_Enc( st->hBWE_TD ); -#ifdef IVAS_FLOAT_FIXED ResetSHBbuffer_Enc_fx( st ); -#endif IF( ( st->hBWE_FD = (FD_BWE_ENC_HANDLE) malloc( sizeof( FD_BWE_ENC_DATA ) ) ) == NULL ) { diff --git a/lib_enc/ivas_tcx_core_enc.c b/lib_enc/ivas_tcx_core_enc.c index d007e50a5..cea581a94 100644 --- a/lib_enc/ivas_tcx_core_enc.c +++ b/lib_enc/ivas_tcx_core_enc.c @@ -2075,6 +2075,11 @@ Word16 ivas_acelp_tcx20_switching_fx( move32(); } + Word32 mean_voicing_fr = L_mult0( voicing_fr_local[0], /* 1/4 in Q15 */ 8192 ); // Q30 + mean_voicing_fr = L_mac0( mean_voicing_fr, voicing_fr_local[1], /* 1/4 in Q15 */ 8192 ); // Q30 + mean_voicing_fr = L_mac0( mean_voicing_fr, voicing_fr_local[2], /* 1/4 in Q15 */ 8192 ); // Q30 + mean_voicing_fr = L_mac0( mean_voicing_fr, voicing_fr_local[3], /* 1/4 in Q15 */ 8192 ); // Q30 + test(); test(); test(); @@ -2085,7 +2090,7 @@ Word16 ivas_acelp_tcx20_switching_fx( test(); test(); test(); - if ( ( !flag_16k_smc ) && ( LT_32( offset_tcx, 0x18950F ) ) && GT_16( non_staX, 1280 /*5.0f Q8*/ ) && ( GE_32( snr_acelp, L_sub( tcx_snr, 262144 /*4.0f in Q16*/ ) ) ) && GE_16( st->Nb_ACELP_frames, 1 ) && ( ( GT_16( st->hSpMusClas->lps_fx, st->hSpMusClas->lpm_fx ) && GE_16( shr( sum16_fx( voicing_fr_local, 4 ), 2 ), 9830 ) ) || ( GE_16( st->Nb_ACELP_frames, 6 ) && GT_16( st->hSpMusClas->lps_fx, sub( st->hSpMusClas->lpm_fx, 192 /*1.5in Q7*/ ) ) ) ) && ( st->sp_aud_decision0 == 0 ) && st->vad_flag ) + if ( ( !flag_16k_smc ) && ( LT_32( offset_tcx, 0x18950F ) ) && GT_16( non_staX, 1280 /*5.0f Q8*/ ) && ( GE_32( snr_acelp, L_sub( tcx_snr, 262144 /*4.0f in Q16*/ ) ) ) && GE_16( st->Nb_ACELP_frames, 1 ) && ( ( GT_16( st->hSpMusClas->lps_fx, st->hSpMusClas->lpm_fx ) && GE_32( mean_voicing_fr, /* 0.3 in Q30 */ 322122547 ) ) || ( GE_16( st->Nb_ACELP_frames, 6 ) && GT_16( st->hSpMusClas->lps_fx, sub( st->hSpMusClas->lpm_fx, 192 /*1.5in Q7*/ ) ) ) ) && ( st->sp_aud_decision0 == 0 ) && st->vad_flag ) { /* Fine tuned across various databases based on various metrics to detect TCX frames in speech.*/ dsnr = 262144; /*4.0f Q16*/ diff --git a/lib_enc/prot_fx_enc.h b/lib_enc/prot_fx_enc.h index c126c56e9..8b2669996 100644 --- a/lib_enc/prot_fx_enc.h +++ b/lib_enc/prot_fx_enc.h @@ -3993,6 +3993,10 @@ void InitSWBencBuffer_fx( Encoder_State *st_fx /* i/o: SHB encoder structure */ ); +void InitSWBencBuffer_ivas_fx( + Encoder_State *st_fx /* i/o: SHB encoder structure */ +); + void ResetSHBbuffer_Enc_fx( Encoder_State *st_fx /* i/o: SHB encoder structure */ ); diff --git a/lib_enc/stat_enc.h b/lib_enc/stat_enc.h index c3573d64a..8f0dd5c8a 100644 --- a/lib_enc/stat_enc.h +++ b/lib_enc/stat_enc.h @@ -1403,19 +1403,15 @@ typedef struct td_bwe_enc_structure #ifndef IVAS_FLOAT_FIXED float old_speech_shb[L_LOOK_16k + L_SUBFR16k]; /* Buffer memories */ float old_speech_wb[( L_LOOK_12k8 + L_SUBFR ) * 5 / 16]; /* Buffer memories */ -#else - Word16 old_speech_shb_fx[L_LOOK_16k + L_SUBFR16k]; /* Buffer memories Q(Q_shb_spch) */ - Word16 old_speech_wb_fx[( L_LOOK_12k8 + L_SUBFR ) * 5 / 16]; /* Buffer memories Q(-1) */ -#endif float old_input_fhb[NS2SA( 48000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_12k8_NS + DELAY_FIR_RESAMPL_NS ) - L_FRAME48k / 2]; - Word16 old_input_fhb_fx[NS2SA( 48000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_12k8_NS + DELAY_FIR_RESAMPL_NS ) - L_FRAME48k / 2]; - Word16 old_input_fhb_fx_Q; - -#ifndef IVAS_FLOAT_FIXED float prev_lsp_shb[LPC_SHB_ORDER]; float state_ana_filt_shb[2 * ALLPASSSECTIONS_STEEP + 1]; /* states for the analysis filters */ float cldfbHBLT_flt; #else + Word16 old_speech_shb_fx[L_LOOK_16k + L_SUBFR16k]; /* Buffer memories Q(Q_shb_spch) */ + Word16 old_speech_wb_fx[( L_LOOK_12k8 + L_SUBFR ) * 5 / 16]; /* Buffer memories Q(-1) */ + Word16 old_input_fhb_fx[NS2SA( 48000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_12k8_NS + DELAY_FIR_RESAMPL_NS ) - L_FRAME48k / 2]; /* Q(old_input_fhb_fx_Q) */ + Word16 old_input_fhb_fx_Q; Word16 prev_lsp_shb_fx[LPC_SHB_ORDER]; /* Q15 */ Word16 state_ana_filt_shb_fx[( 2 * ALLPASSSECTIONS_STEEP + 1 )]; /* states for the analysis filters */ Word16 cldfbHBLT; /* Q13 */ @@ -1423,34 +1419,27 @@ typedef struct td_bwe_enc_structure /* states for the filters used in generating SHB excitation from WB excitation*/ #ifndef IVAS_FLOAT_FIXED float mem_csfilt[2]; + float mem_shb_res[MAX_LEN_MA_FILTER]; /* old SHB residual signal */ + float old_EnvSHBres[L_FRAME4k]; /* old TD envelope of the SHB residual signal */ + float old_mean_EnvSHBres; /* energy of the last subframe of the SHB residual signal from previous frame */ + float prev_enr_EnvSHBres; /* energy of the residual SHB envelope from the previous frame */ + float prev_shb_env_tilt; /* tilt of the residual SHB envelope from the previous frame */ + float prev_pow_exc16kWhtnd; /* power of the LB excitation signal in the previous frame */ + float prev_mix_factor; /* mixing factor in the previous frame */ + float prev_Env_error; /* error in SHB envelope modelling */ #else Word32 mem_csfilt_fx[2]; /* Q(prev_Q_bwe_exc) */ -#endif - float mem_shb_res[MAX_LEN_MA_FILTER]; /* old SHB residual signal */ - Word16 mem_shb_res_fx[MAX_LEN_MA_FILTER]; /* old SHB residual signal */ - Word32 mem_shb_res_32_fx[MAX_LEN_MA_FILTER]; /* old SHB residual signal */ - float old_EnvSHBres[L_FRAME4k]; /* old TD envelope of the SHB residual signal */ - Word16 old_EnvSHBres_fx[L_FRAME4k]; /* old TD envelope of the SHB residual signal */ -#ifndef IVAS_FLOAT_FIXED - float old_mean_EnvSHBres; /* energy of the last subframe of the SHB residual signal from previous frame */ - float prev_enr_EnvSHBres; /* energy of the residual SHB envelope from the previous frame */ - float prev_shb_env_tilt; /* tilt of the residual SHB envelope from the previous frame */ - float prev_pow_exc16kWhtnd; /* power of the LB excitation signal in the previous frame */ -#else + Word16 mem_shb_res_fx[MAX_LEN_MA_FILTER]; /* old SHB residual signal Q(prev_Q_shb) */ + Word16 old_EnvSHBres_fx[L_FRAME4k]; /* old TD envelope of the SHB residual signal Q(prev_Q_shb) */ Word16 old_mean_EnvSHBres_fx; /* energy of the last subframe of the SHB residual signal from previous frame Q15 */ Word32 prev_enr_EnvSHBres_fx; /* energy of the residual SHB envelope from the previous frame Q(31 - prev_enr_EnvSHBres_e) */ Word16 prev_enr_EnvSHBres_e; - Word16 prev_shb_env_tilt_fx; /* tilt of the residual SHB envelope from the previous frame Q(prev_shb_env_tilt_q) */ - Word16 prev_shb_env_tilt_q; + Word16 prev_shb_env_tilt_fx; /* tilt of the residual SHB envelope from the previous frame Q(prev_Q_shb) */ + Word16 prev_Q_shb; #if 0 Word16 prev_pow_exc16kWhtnd_fx; /* power of the LB excitation signal in the previous frame */ #endif Word32 prev_pow_exc16kWhtnd_fx32; /* Use this power of the LB excitation signal in the previous frame Q0 */ -#endif -#ifndef IVAS_FLOAT_FIXED - float prev_mix_factor; /* mixing factor in the previous frame */ - float prev_Env_error; /* error in SHB envelope modelling */ -#else Word16 prev_mix_factor_fx; /* mixing factor in the previous frame Q15 */ Word16 prev_Env_error_fx; /* error in SHB envelope modelling Q0 */ #endif @@ -1512,19 +1501,16 @@ typedef struct td_bwe_enc_structure #ifndef IVAS_FLOAT_FIXED float prev_wb_GainShape_flt; float swb_lsp_prev_interp[LPC_SHB_ORDER]; + float fb_state_lpc_syn[LPC_SHB_ORDER]; + float fb_tbe_demph; + float tilt_mem; #else Word16 prev_wb_GainShape; /* Q15 */ Word16 swb_lsp_prev_interp_fx[LPC_SHB_ORDER]; /* Q15 */ -#endif - float fb_state_lpc_syn[LPC_SHB_ORDER]; - float fb_tbe_demph; Word16 fb_state_lpc_syn_fx[LPC_SHB_ORDER]; Word16 prev_Q_bwe_exc_fb; Word16 fb_tbe_demph_fx; -#ifndef IVAS_FLOAT_FIXED - float tilt_mem; -#else - Word16 tilt_mem_fx; /* Q12 */ + Word16 tilt_mem_fx; /* Q12 */ #endif int16_t prev_coder_type; @@ -1532,8 +1518,8 @@ typedef struct td_bwe_enc_structure float prev_lsf_diff[LPC_SHB_ORDER - 2]; float prev_tilt_para; #else - Word16 prev_lsf_diff_fx[LPC_SHB_ORDER - 2]; /* Q15 */ - Word16 prev_tilt_para_fx; /* Q10 */ + Word16 prev_lsf_diff_fx[LPC_SHB_ORDER - 2]; /* Q15 */ + Word16 prev_tilt_para_fx; /* Q10 */ #endif float cur_sub_Aq[M + 1]; Word16 cur_sub_Aq_fx[M + 1]; /* Q12 */ diff --git a/lib_enc/swb_bwe_enc_fx.c b/lib_enc/swb_bwe_enc_fx.c index f76a740b9..91ffef59d 100644 --- a/lib_enc/swb_bwe_enc_fx.c +++ b/lib_enc/swb_bwe_enc_fx.c @@ -40,7 +40,7 @@ static Word16 SWB_BWE_encoding_ivas_fx( const Word16 *insig_lp_fx, /* i : delayed original lowband input signal at 32kHz */ const Word16 *insig_hp_fx, /* i : delayed original highband input signal at 32kHz */ const Word16 *synth_fx, /* i : delayed ACELP core synthesis at 12.8kHz */ - const Word16 *yos_fx, /* i : MDCT coefficients of the windowed original input signal at 32kHz */ + const Word32 *yos_fx, /* i : MDCT coefficients of the windowed original input signal at 32kHz */ Word16 *SWB_fenv_fx, /* o : frequency-domain quantized BWE envelope */ const Word16 tilt_nb_fx, /* i : SWB tilt */ const Word16 st_offset, /* i : start frequency offset for BWE envelope */ @@ -324,6 +324,7 @@ void swb_bwe_enc_ivas_fx( move32(); #endif Word16 fb_band_begin; + Word16 sf; FD_BWE_ENC_HANDLE hBWE_FD = st_fx->hBWE_FD; TD_BWE_ENC_HANDLE hBWE_TD = st_fx->hBWE_TD; @@ -437,8 +438,9 @@ void swb_bwe_enc_ivas_fx( inner_frame ); /* Scaling has been added to avoid the yorig_32 buffer becoming zero inside direct_transform_fx */ - Scale_sig32( L_old_input_fx, inner_frame, Q5 ); - new_input_fx_exp = add( new_input_fx_exp, 5 ); + sf = L_norm_arr( L_old_input_fx, inner_frame ); + scale_sig32( L_old_input_fx, inner_frame, sf ); + new_input_fx_exp = add( new_input_fx_exp, sf ); // It is Q, not exp /* DCT of the ACELP core synthesis */ direct_transform_fx( L_old_input_fx, yorig_32, 0, inner_frame, &new_input_fx_exp, st_fx->element_mode ); @@ -572,13 +574,13 @@ void swb_bwe_enc_ivas_fx( /* SWB BWE encoding */ IF( EQ_16( st_fx->L_frame, L_FRAME16k ) ) { - SWB_BWE_encoding_ivas_fx( st_fx, old_input_fx, old_input_lp_fx, new_input_hp_fx, old_syn_12k8_16k_fx, yorig_fx, - SWB_fenv_fx, tilt_nb_fx, 80, Q_slb_speech, Q_shb, Q_synth_hf, Q_synth ); + SWB_BWE_encoding_ivas_fx( st_fx, old_input_fx, old_input_lp_fx, new_input_hp_fx, old_syn_12k8_16k_fx, yorig_32, + SWB_fenv_fx, tilt_nb_fx, 80, Q_slb_speech, Q_shb, new_input_fx_exp, Q_synth ); } ELSE { - SWB_BWE_encoding_ivas_fx( st_fx, old_input_fx, old_input_lp_fx, new_input_hp_fx, old_syn_12k8_16k_fx, yorig_fx, - SWB_fenv_fx, tilt_nb_fx, 6, Q_slb_speech, Q_shb, Q_synth_hf, Q_synth ); + SWB_BWE_encoding_ivas_fx( st_fx, old_input_fx, old_input_lp_fx, new_input_hp_fx, old_syn_12k8_16k_fx, yorig_32, + SWB_fenv_fx, tilt_nb_fx, 6, Q_slb_speech, Q_shb, new_input_fx_exp, Q_synth ); } @@ -2054,7 +2056,7 @@ static void calculate_Tonality_fx( { max = gen_spec[n_coeff];move16(); }*/ - max = s_max( max, org_spec[n_coeff] ); + max = s_max( max, gen_spec[n_coeff] ); } l_shift = norm_s( max ); FOR( n_coeff = 0; n_coeff < length; n_coeff++ ) @@ -2974,7 +2976,7 @@ static Word16 SWB_BWE_encoding_ivas_fx( const Word16 *insig_lp_fx, /* i : delayed original lowband input signal at 32kHz */ const Word16 *insig_hp_fx, /* i : delayed original highband input signal at 32kHz */ const Word16 *synth_fx, /* i : delayed ACELP core synthesis at 12.8kHz */ - const Word16 *yos_fx, /* i : MDCT coefficients of the windowed original input signal at 32kHz */ + const Word32 *yos_fx, /* i : MDCT coefficients of the windowed original input signal at 32kHz */ Word16 *SWB_fenv_fx, /* o : frequency-domain quantized BWE envelope */ const Word16 tilt_nb_fx, /* i : SWB tilt */ const Word16 st_offset, /* i : start frequency offset for BWE envelope */ @@ -2991,10 +2993,13 @@ static Word16 SWB_BWE_encoding_ivas_fx( Word16 tmp; Word32 energy_fx; + Word64 energy_fx_64; Word16 tilt_fx; Word32 global_gain_fx; Word32 L_tmp; + Word64 W_tmp; Word32 L_SWB_fenv_fx[SWB_FENV]; + Word16 q_SWB_fenv[SWB_FENV]; Word16 SWB_tenv_fx[SWB_TENV]; Word32 L_SWB_tenv, WB_tenv_syn_fx, WB_tenv_orig_fx; Word16 exp, expn, expd; @@ -3008,6 +3013,10 @@ static Word16 SWB_BWE_encoding_ivas_fx( Flag Overflow = 0; move32(); #endif + Word16 inner_frame; + Word16 q_shift; + Word16 yos_fx_16[L_FRAME_MAX]; + Word16 sf; FD_BWE_ENC_HANDLE hBWE_FD = st_fx->hBWE_FD; BSTR_ENC_HANDLE hBstr = st_fx->hBstr; @@ -3023,6 +3032,17 @@ static Word16 SWB_BWE_encoding_ivas_fx( move16(); } + IF( EQ_16( st_fx->extl, FB_BWE ) ) + { + inner_frame = L_FRAME48k; + move16(); + } + ELSE + { + inner_frame = L_FRAME32k; + move16(); + } + /* HF transient detect */ IsTransient = detect_transient_fx( insig_hp_fx, L_FRAME16k, Q_shb, st_fx ); st_fx->EnergyLT_fx_exp = shl( Q_shb, 1 ); @@ -3076,15 +3096,29 @@ static Word16 SWB_BWE_encoding_ivas_fx( global_gain_fx = L_deposit_l( 0 ); FOR( n_band = 0; n_band < SWB_FENV_TRANS; n_band++ ) { - energy_fx = L_deposit_l( 0 ); + energy_fx_64 = W_deposit32_l( 0 ); FOR( n_coeff = swb_bwe_trans_subband[n_band] + st_offset; n_coeff < swb_bwe_trans_subband[n_band + 1] + st_offset; n_coeff++ ) { - L_tmp = L_shr( L_mult0( yos_fx[n_coeff], yos_fx[n_coeff] ), 7 ); /*2*Q_synth-7 */ - energy_fx = L_add( L_tmp, energy_fx ); /*2*Q_synth-7 */ + W_tmp = W_mult0_32_32( yos_fx[n_coeff], yos_fx[n_coeff] ); /*2*Q_synth */ + energy_fx_64 = W_add( W_tmp, energy_fx_64 ); /*2*Q_synth */ } - global_gain_fx = L_add( global_gain_fx, L_shr( energy_fx, sub( sub( shl( Q_synth, 1 ), 7 ), shl( Q_shb, 1 ) ) ) ); /*2*Q_shb */ + q_shift = W_norm( energy_fx_64 ); + energy_fx = W_extract_h( W_shl( energy_fx_64, q_shift ) ); /*2*Q_synth + q_shift - 32*/ + q_shift = sub( q_shift, 32 ); + + global_gain_fx = L_add( global_gain_fx, L_shr( energy_fx, sub( add( shl( Q_synth, 1 ), q_shift ), shl( Q_shb, 1 ) ) ) ); /*2*Q_shb */ L_SWB_fenv_fx[n_band] = energy_fx; move32(); + IF( L_SWB_fenv_fx[n_band] == 0 ) + { + q_SWB_fenv[n_band] = Q31; + move16(); + } + ELSE + { + q_SWB_fenv[n_band] = add( shl( Q_synth, 1 ), q_shift ); + move16(); + } } global_gain_fx = L_shr( global_gain_fx, 1 ); /*2*Q_shb */ @@ -3092,10 +3126,10 @@ static Word16 SWB_BWE_encoding_ivas_fx( { expd = norm_s( swb_bwe_trans_subband_width[n_band] ); tmp = div_s( shl( 1, sub( 14, expd ) ), swb_bwe_trans_subband_width[n_band] ); /*Q(29-expd) */ - L_tmp = Mult_32_16( L_SWB_fenv_fx[n_band], tmp ); /*2*Q_synth-7+29-expd - 15 */ + L_tmp = Mult_32_16( L_SWB_fenv_fx[n_band], tmp ); /*q_SWB_fenv[n_band]+29-expd - 15 */ exp = norm_l( L_tmp ); tmp = Log2_norm_lc( L_shl( L_tmp, exp ) ); - exp = sub( sub( 30, exp ), sub( add( shl( Q_synth, 1 ), 7 ), expd ) ); + exp = sub( sub( 30, exp ), sub( add( q_SWB_fenv[n_band], Q14 ), expd ) ); L_tmp = Mpy_32_16( exp, tmp, 24660 ); /* Q14 */ /*10log10(2) in Q13 */ tmp = round_fx( L_shl( L_tmp, 10 ) ); /* Q8 */ @@ -3371,37 +3405,45 @@ static Word16 SWB_BWE_encoding_ivas_fx( global_gain_fx = L_deposit_l( 0 ); FOR( n_band = 0; n_band < SWB_FENV; n_band++ ) { - energy_fx = L_deposit_l( 0 ); + energy_fx_64 = W_deposit32_l( 0 ); FOR( n_coeff = swb_bwe_subband[n_band] + st_offset; n_coeff < swb_bwe_subband[n_band + 1] + st_offset; n_coeff++ ) { - L_tmp = L_shr( L_mult0( yos_fx[n_coeff], yos_fx[n_coeff] ), 5 ); /*2*Q_synth-5 */ - energy_fx = L_add( L_tmp, energy_fx ); /*2*Q_synth-5 */ + W_tmp = W_mult0_32_32( yos_fx[n_coeff], yos_fx[n_coeff] ); /*2*Q_synth */ + energy_fx_64 = W_add( W_tmp, energy_fx_64 ); /*2*Q_synth */ } + q_shift = W_norm( energy_fx_64 ); + energy_fx = W_extract_h( W_shl( energy_fx_64, q_shift ) ); /*2*Q_synth + q_shift - 32*/ + q_shift = sub( q_shift, 32 ); IF( LT_16( n_band, SWB_FENV - 2 ) ) { - global_gain_fx = L_add( global_gain_fx, L_shr( energy_fx, sub( sub( shl( Q_synth, 1 ), 5 ), shl( Q_shb, 1 ) ) ) ); /*2*Q_shb */ + global_gain_fx = L_add( global_gain_fx, L_shr( energy_fx, sub( add( shl( Q_synth, 1 ), q_shift ), shl( Q_shb, 1 ) ) ) ); /*2*Q_shb */ } L_SWB_fenv_fx[n_band] = energy_fx; move32(); + q_SWB_fenv[n_band] = add( shl( Q_synth, 1 ), q_shift ); + move16(); } global_gain_fx = L_shr( global_gain_fx, 1 ); /*2*Q_shb */ - mode = FD_BWE_class_fx( yos_fx, global_gain_fx, tilt_nb_fx, Q_synth, Q_shb, st_fx ); + + sf = getScaleFactor32( yos_fx, inner_frame ); + Copy_Scale_sig32_16( yos_fx, yos_fx_16, inner_frame, sf ); + mode = FD_BWE_class_fx( yos_fx_16, global_gain_fx, tilt_nb_fx, sub( add( Q_synth, sf ), Q16 ), Q_shb, st_fx ); push_indice( hBstr, IND_SWB_CLASS, mode, 2 ); - energy_control_ivas_fx( st_fx, ACELP_CORE, mode, -1, yos_fx, st_offset, energy_factor_fx, Q_synth_lf ); + energy_control_ivas_fx( st_fx, ACELP_CORE, mode, -1, yos_fx_16, st_offset, energy_factor_fx, sub( add( Q_synth_lf, sf ), Q16 ) ); FOR( n_band = 0; n_band < SWB_FENV; n_band++ ) { - L_tmp = Mult_32_16( L_SWB_fenv_fx[n_band], energy_factor_fx[n_band] ); /*2*Q_synth-5 */ - L_tmp = Mult_32_16( L_tmp, swb_inv_bwe_subband_width_fx[n_band] ); /*2*Q_synth-5 */ + L_tmp = Mult_32_16( L_SWB_fenv_fx[n_band], energy_factor_fx[n_band] ); /*q_SWB_fenv[n_band] */ + L_tmp = Mult_32_16( L_tmp, swb_inv_bwe_subband_width_fx[n_band] ); /*q_SWB_fenv[n_band] */ IF( L_tmp != 0 ) { expn = norm_l( L_tmp ); tmp = Log2_norm_lc( L_shl( L_tmp, expn ) ); - expn = sub( 30, add( expn, sub( shl( Q_synth, 1 ), 5 ) ) ); + expn = sub( 30, add( expn, q_SWB_fenv[n_band] ) ); L_tmp = Mpy_32_16( expn, tmp, 24660 ); /* Q14 */ /*10log10(2) in Q13 */ SWB_fenv_fx[n_band] = round_fx( L_shl( L_tmp, 10 ) ); /* Q8 */ move16(); diff --git a/lib_enc/swb_tbe_enc.c b/lib_enc/swb_tbe_enc.c index 18c519939..e8d285903 100644 --- a/lib_enc/swb_tbe_enc.c +++ b/lib_enc/swb_tbe_enc.c @@ -127,18 +127,15 @@ void InitSWBencBuffer( #ifndef IVAS_FLOAT_FIXED set_f( hBWE_TD->old_speech_shb, 0.0f, L_LOOK_16k + L_SUBFR16k ); set_f( hBWE_TD->old_speech_wb, 0.0f, ( L_LOOK_12k8 + L_SUBFR ) * 5 / 16 ); + set_f( hBWE_TD->old_input_fhb, 0.0f, NS2SA( 48000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_12k8_NS + DELAY_FIR_RESAMPL_NS ) - L_FRAME48k / 2 ); #else set16_fx( hBWE_TD->old_speech_shb_fx, 0, L_LOOK_16k + L_SUBFR16k ); set16_fx( hBWE_TD->old_speech_wb_fx, 0, ( L_LOOK_12k8 + L_SUBFR ) * 5 / 16 ); + set16_fx( hBWE_TD->old_input_fhb_fx, 0, NS2SA( 48000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_12k8_NS + DELAY_FIR_RESAMPL_NS ) - L_FRAME48k / 2 ); #endif - set_f( hBWE_TD->old_input_fhb, 0.0f, NS2SA( 48000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_12k8_NS + DELAY_FIR_RESAMPL_NS ) - L_FRAME48k / 2 ); #ifdef IVAS_FLOAT_FIXED InitSWBencBufferStates_fx( hBWE_TD, NULL ); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - /* To be removed */ - InitSWBencBufferStates( hBWE_TD, NULL ); -#endif #else InitSWBencBufferStates( hBWE_TD, NULL ); #endif @@ -176,14 +173,14 @@ void InitSWBencBuffer( hBWE_TD->prev_frGainAtten = 0; #ifndef IVAS_FLOAT_FIXED hBWE_TD->prev_wb_GainShape_flt = 0; -#else - hBWE_TD->prev_wb_GainShape = 0; -#endif set_f( hBWE_TD->fb_state_lpc_syn, 0, LPC_SHB_ORDER ); hBWE_TD->fb_tbe_demph = 0.0f; -#ifndef IVAS_FLOAT_FIXED hBWE_TD->tilt_mem = 0.0f; #else + hBWE_TD->prev_wb_GainShape = 0; + set16_fx( hBWE_TD->fb_state_lpc_syn_fx, 0, LPC_SHB_ORDER ); + hBWE_TD->fb_tbe_demph_fx = 0; + move16(); hBWE_TD->tilt_mem_fx = 0; move16(); #endif @@ -230,6 +227,7 @@ void InitSWBencBuffer( } +#ifndef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* * InitSWBencBufferStates() * @@ -246,35 +244,15 @@ void InitSWBencBufferStates( set_f( shb_speech, 0.0f, L_FRAME16k ); } -#ifndef IVAS_FLOAT_FIXED set_f( hBWE_TD->old_speech_shb, 0.0f, L_LOOK_16k + L_SUBFR16k ); -#else - set16_fx( hBWE_TD->old_speech_shb_fx, 0, L_LOOK_16k + L_SUBFR16k ); -#endif set_f( hBWE_TD->mem_shb_res, 0.0f, MAX_LEN_MA_FILTER ); - set16_fx( hBWE_TD->mem_shb_res_fx, 0, MAX_LEN_MA_FILTER ); - set32_fx( hBWE_TD->mem_shb_res_32_fx, 0, MAX_LEN_MA_FILTER ); set_f( hBWE_TD->old_EnvSHBres, 0.0f, L_FRAME4k ); -#ifndef IVAS_FLOAT_FIXED hBWE_TD->old_mean_EnvSHBres = 0.0f; hBWE_TD->prev_enr_EnvSHBres = 1.0f; hBWE_TD->prev_shb_env_tilt = 0.0f; -#else - hBWE_TD->old_mean_EnvSHBres_fx = 0; - hBWE_TD->prev_enr_EnvSHBres_fx = 1; /*1.0f in Q0*/ - hBWE_TD->prev_enr_EnvSHBres_e = 31; - hBWE_TD->prev_shb_env_tilt_fx = 0; - hBWE_TD->prev_shb_env_tilt_q = 15; -#endif -#ifndef IVAS_FLOAT_FIXED hBWE_TD->prev_pow_exc16kWhtnd = 1.0f; hBWE_TD->prev_mix_factor = 1.0f; hBWE_TD->prev_Env_error = 0.0f; -#else - hBWE_TD->prev_pow_exc16kWhtnd_fx32 = 1; - hBWE_TD->prev_mix_factor_fx = 32767; - hBWE_TD->prev_Env_error_fx = 0; -#endif return; } @@ -290,58 +268,32 @@ void ResetSHBbuffer_Enc( ) { /* states for the filters used in generating SHB excitation from WB excitation*/ -#ifndef IVAS_FLOAT_FIXED set_f( hBWE_TD->mem_genSHBexc_filt_down_shb, 0, ( 2 * ALLPASSSECTIONS_STEEP + 1 ) ); set_f( hBWE_TD->mem_csfilt, 0, 2 ); -#else - set16_fx( hBWE_TD->mem_genSHBexc_filt_down_shb_fx, 0, ( 2 * ALLPASSSECTIONS_STEEP + 1 ) ); - set32_fx( hBWE_TD->mem_csfilt_fx, 0, 2 ); -#endif /* states for the filters used in generating SHB signal from SHB excitation*/ -#ifndef IVAS_FLOAT_FIXED set_f( hBWE_TD->state_syn_shbexc, 0, L_SHB_LAHEAD ); set_f( hBWE_TD->state_lpc_syn, 0, LPC_SHB_ORDER ); -#else - set16_fx( hBWE_TD->state_syn_shbexc_fx, 0, L_SHB_LAHEAD ); - set16_fx( hBWE_TD->state_lpc_syn_fx, 0, LPC_SHB_ORDER ); -#endif set_f( hBWE_TD->fb_state_lpc_syn, 0, LPC_SHB_ORDER ); hBWE_TD->fb_tbe_demph = 0; /* states for the filters used in generating WB signal from WB excitation*/ -#ifndef IVAS_FLOAT_FIXED set_f( hBWE_TD->decim_state1, 0.0f, ( 2 * ALLPASSSECTIONS_STEEP + 1 ) ); set_f( hBWE_TD->decim_state2, 0.0f, ( 2 * ALLPASSSECTIONS_STEEP + 1 ) ); set_f( hBWE_TD->mem_genSHBexc_filt_down_wb2, 0, ( 2 * ALLPASSSECTIONS_STEEP + 1 ) ); set_f( hBWE_TD->mem_genSHBexc_filt_down_wb3, 0, ( 2 * ALLPASSSECTIONS_STEEP + 1 ) ); -#else - set16_fx( hBWE_TD->decim_state1_fx, 0, ( 2 * ALLPASSSECTIONS_STEEP + 1 ) ); - set16_fx( hBWE_TD->decim_state2_fx, 0, ( 2 * ALLPASSSECTIONS_STEEP + 1 ) ); - set16_fx( hBWE_TD->mem_genSHBexc_filt_down_wb2_fx, 0, ( 2 * ALLPASSSECTIONS_STEEP + 1 ) ); - set16_fx( hBWE_TD->mem_genSHBexc_filt_down_wb3_fx, 0, ( 2 * ALLPASSSECTIONS_STEEP + 1 ) ); -#endif /* overlap buffer used to Adjust SHB Frame Gain */ -#ifndef IVAS_FLOAT_FIXED set_f( hBWE_TD->mem_stp_swb, 0, LPC_SHB_ORDER ); hBWE_TD->gain_prec_swb = 1.0f; set_f( hBWE_TD->syn_overlap, 0, L_SHB_LAHEAD ); hBWE_TD->tbe_demph = 0.0f; hBWE_TD->tbe_premph = 0.0f; -#else - set16_fx( hBWE_TD->mem_stp_swb_fx, 0, LPC_SHB_ORDER ); - hBWE_TD->gain_prec_swb_fx = ONE_IN_Q14; - set16_fx( hBWE_TD->syn_overlap_fx, 0, L_SHB_LAHEAD ); - hBWE_TD->tbe_demph_fx = 0; - hBWE_TD->tbe_premph_fx = 0; -#endif return; } -#ifndef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* * wb_tbe_enc() * @@ -3041,11 +2993,13 @@ void TBEreset_enc( if ( bwidth == FB ) { - set_f( hBWE_TD->fb_state_lpc_syn, 0, LPC_SHB_ORDER ); - hBWE_TD->fb_tbe_demph = 0; #ifdef IVAS_FLOAT_FIXED + set16_fx( hBWE_TD->fb_state_lpc_syn_fx, 0, LPC_SHB_ORDER ); + hBWE_TD->fb_tbe_demph_fx = 0; fb_tbe_reset_enc_fx( hBWE_TD->elliptic_bpf_2_48k_mem_fx, &hBWE_TD->prev_fb_energy_fx, hBWE_TD->elliptic_bpf_2_48k_mem_fx_Q, &hBWE_TD->prev_fb_energy_fx_Q ); #else + set_f( hBWE_TD->fb_state_lpc_syn, 0, LPC_SHB_ORDER ); + hBWE_TD->fb_tbe_demph = 0; fb_tbe_reset_enc( hBWE_TD->elliptic_bpf_2_48k_mem, &hBWE_TD->prev_fb_energy ); #endif } diff --git a/lib_enc/swb_tbe_enc_fx.c b/lib_enc/swb_tbe_enc_fx.c index 9a219d065..52ac2398d 100644 --- a/lib_enc/swb_tbe_enc_fx.c +++ b/lib_enc/swb_tbe_enc_fx.c @@ -498,6 +498,108 @@ void InitSWBencBuffer_fx( return; } +void InitSWBencBuffer_ivas_fx( + Encoder_State *st_fx /* i/o: SHB encoder structure */ +) +{ + Word16 i; + TD_BWE_ENC_HANDLE hBWE_TD = st_fx->hBWE_TD; + + set16_fx( hBWE_TD->old_bwe_exc_fx, 0, ( PIT16k_MAX * 2 ) ); + hBWE_TD->bwe_seed[0] = 23; + move16(); + hBWE_TD->bwe_seed[1] = 59; + move16(); + set16_fx( hBWE_TD->old_bwe_exc_extended_fx, 0, NL_BUFF_OFFSET ); + hBWE_TD->bwe_non_lin_prev_scale_fx = L_deposit_l( 0 ); + move32(); + + set16_fx( hBWE_TD->state_ana_filt_shb_fx, 0, ( 2 * ALLPASSSECTIONS_STEEP + 1 ) ); + set32_fx( hBWE_TD->elliptic_bpf_2_48k_mem_fx[0], 0, 4 ); + set32_fx( hBWE_TD->elliptic_bpf_2_48k_mem_fx[1], 0, 4 ); + set32_fx( hBWE_TD->elliptic_bpf_2_48k_mem_fx[2], 0, 4 ); + set32_fx( hBWE_TD->elliptic_bpf_2_48k_mem_fx[3], 0, 4 ); + hBWE_TD->prev_fb_energy_fx = 0; + move16(); + + set16_fx( hBWE_TD->old_speech_shb_fx, 0, L_LOOK_16k + L_SUBFR16k ); + set16_fx( hBWE_TD->old_speech_wb_fx, 0, ( L_LOOK_12k8 + L_SUBFR ) * 5 / 16 ); + set16_fx( hBWE_TD->old_input_fhb_fx, 0, NS2SA( 48000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_12k8_NS + DELAY_FIR_RESAMPL_NS ) - L_FRAME48k / 2 ); + hBWE_TD->old_input_fhb_fx_Q = 0; + move16(); + + // IVAS_CODE + // set_f(hBWE_TD->mem_shb_res, 0.0f, MAX_LEN_MA_FILTER); + // set_f(hBWE_TD->old_EnvSHBres, 0.0f, L_FRAME4k); + // hBWE_TD->old_mean_EnvSHBres = 0.0f; + // hBWE_TD->prev_enr_EnvSHBres = 1.0f; + // hBWE_TD->prev_shb_env_tilt = 0.0f; + // hBWE_TD->prev_pow_exc16kWhtnd = 1.0f; + // hBWE_TD->prev_mix_factor = 1.0f; + // hBWE_TD->prev_Env_error = 0.0f; + set16_fx( hBWE_TD->prev_lsp_shb_fx, 0, 10 ); + + hBWE_TD->cldfbHBLT = 8192; /* 1.0f Q13 */ + move16(); + hBWE_TD->prev_gainFr_SHB_fx = 0; + move32(); + set16_fx( hBWE_TD->lsp_shb_slow_interpl_fx, 0, LPC_SHB_ORDER ); + set16_fx( hBWE_TD->lsp_shb_fast_interpl_fx, 0, LPC_SHB_ORDER ); + set16_fx( hBWE_TD->shb_inv_filt_mem_fx, 0, LPC_SHB_ORDER ); + set16_fx( hBWE_TD->lsp_shb_spacing_fx, 3277 /* 0.1f in Q15 */, 3 ); + set16_fx( hBWE_TD->elliptic_bpf_2_48k_mem_fx_Q, 0, 4 ); + + hBWE_TD->prev_swb_GainShape_fx = 0; + move16(); + hBWE_TD->prev_frGainAtten = 0; + move16(); + hBWE_TD->prev_wb_GainShape = 0; + move16(); + hBWE_TD->prev_Q_bwe_exc_fb = 51; + move16(); + set16_fx( hBWE_TD->fb_state_lpc_syn_fx, 0, LPC_SHB_ORDER ); + hBWE_TD->fb_tbe_demph_fx = 0; + move16(); + hBWE_TD->tilt_mem_fx = 0; + move16(); + + hBWE_TD->prev_coder_type = GENERIC; + move16(); + set16_fx( hBWE_TD->prev_lsf_diff_fx, 16384 /* 0.5f in Q15 */, LPC_SHB_ORDER - 2 ); + hBWE_TD->prev_tilt_para_fx = 0; + move16(); + set16_fx( hBWE_TD->cur_sub_Aq_fx, 0, M + 1 ); + + /* TD BWE post-processing */ + hBWE_TD->ptr_mem_stp_swb_fx = hBWE_TD->mem_stp_swb_fx + LPC_SHB_ORDER - 1; + set16_fx( hBWE_TD->mem_zero_swb_fx, 0, LPC_SHB_ORDER ); + + FOR( i = 0; i < LPC_SHB_ORDER; i++ ) + { + hBWE_TD->swb_lsp_prev_interp_fx[i] = swb_lsp_prev_interp_init[i]; + move16(); + } + + set16_fx( hBWE_TD->dec_2_over_3_mem_fx, 0, 12 ); + set16_fx( hBWE_TD->dec_2_over_3_mem_lp_fx, 0, 6 ); + + + hBWE_TD->prev_fb_energy_fx_Q = 0; + move16(); + + + // TV2TV IVAS_CODE -> To be verify if it has to be moved to hBWE_TD + st_fx->prev_Q_bwe_exc = 31; + move16(); + st_fx->prev_Q_bwe_syn = 31; + move16(); + set16_fx( st_fx->prev_lsp_wb_fx, 0, 6 ); + set16_fx( st_fx->prev_lsp_wb_temp_fx, 0, 6 ); + set16_fx( st_fx->prev_lpc_wb_fx, 0, LPC_SHB_ORDER_WB ); + + return; +} + /*-------------------------------------------------------------------* * ResetSHBbuffer_Enc() * @@ -3275,7 +3377,8 @@ void swb_tbe_enc_ivas_fx( IF( EQ_32( st_fx->extl_brate, SWB_TBE_1k10 ) || EQ_32( st_fx->extl_brate, SWB_TBE_1k75 ) ) { /* calculate the TD envelope of the SHB residual signal */ - find_td_envelope_fx( shb_res_fx, L_FRAME16k, 20, hBWE_TD->mem_shb_res_fx, EnvSHBres_fx ); /* Q_shb */ + Scale_sig( hBWE_TD->mem_shb_res_fx, MAX_LEN_MA_FILTER, sub( hBWE_TD->prev_Q_shb, Q_shb ) ); /* Q(hBWE_TD->prev_Q_shb) -> Q(Q_shb) */ + find_td_envelope_fx( shb_res_fx, L_FRAME16k, 20, hBWE_TD->mem_shb_res_fx, EnvSHBres_fx ); /* Q_shb */ /* downsample the TD envelope by 4 */ FOR( k = 0; k < L_FRAME4k; k++ ) @@ -3353,7 +3456,7 @@ void swb_tbe_enc_ivas_fx( lls_interp_n_fx( seg_mean, 4, &shb_env_tilt_fx, &temp, 0 ); /* copy previous residual envelope to the buffer */ - Copy( hBWE_TD->old_EnvSHBres_fx, buf_EnvSHBres_fx, L_FRAME4k ); // Qs to be handled + Copy_Scale_sig( hBWE_TD->old_EnvSHBres_fx, buf_EnvSHBres_fx, L_FRAME4k, sub( hBWE_TD->prev_Q_shb, Q_shb ) ); /* Q(hBWE_TD->prev_Q_shb) -> Q(Q_shb) */ /* subtract mean value from the normalized SHB residual envelope */ p_buf = &buf_EnvSHBres_fx[L_FRAME4k]; @@ -3365,7 +3468,7 @@ void swb_tbe_enc_ivas_fx( } /* update memory */ - Copy( &buf_EnvSHBres_fx[L_FRAME4k], hBWE_TD->old_EnvSHBres_fx, L_FRAME4k ); // Qs to be handled + Copy( &buf_EnvSHBres_fx[L_FRAME4k], hBWE_TD->old_EnvSHBres_fx, L_FRAME4k ); /* calculate energy normalization factor for the auto-correlation function */ // pow0 = sum2_f( &buf_EnvSHBres[L_FRAME4k], L_FRAME4k ) + 1.0f; @@ -3471,7 +3574,7 @@ void swb_tbe_enc_ivas_fx( hBWE_TD->prev_shb_env_tilt_fx = shb_env_tilt_fx; move16(); - hBWE_TD->prev_shb_env_tilt_q = Q_shb; + hBWE_TD->prev_Q_shb = Q_shb; move16(); } @@ -3813,7 +3916,7 @@ void swb_tbe_enc_ivas_fx( test(); test(); test(); - IF( LT_16( acorr_v2a_fx, 13107 ) /* 0.4f in Q15 */ && GE_16( vf_ind_fx, 5 ) && LT_16( abs_s( GainShape_tilt_fx ), 6554 /* 0.2f in Q15 */ ) && LT_32( L_deposit_l( shb_env_tilt_fx ), L_shl( 500, Q_shb ) ) && LT_32( L_deposit_l( hBWE_TD->prev_shb_env_tilt_fx ), L_shl( 500, hBWE_TD->prev_shb_env_tilt_q ) ) ) + IF( LT_16( acorr_v2a_fx, 13107 ) /* 0.4f in Q15 */ && GE_16( vf_ind_fx, 5 ) && LT_16( abs_s( GainShape_tilt_fx ), 6554 /* 0.2f in Q15 */ ) && LT_32( L_deposit_l( shb_env_tilt_fx ), L_shl( 500, Q_shb ) ) && LT_32( L_deposit_l( hBWE_TD->prev_shb_env_tilt_fx ), L_shl( 500, hBWE_TD->prev_Q_shb ) ) ) { /* stronger smoothing in case of unvoiced SHB residual signal with gaussian excitation */ // feedback = lin_interp(acorr_v2a, 0.4f, 0.0f, 0.0f, 0.95f, 0); @@ -7481,18 +7584,20 @@ void InitSWBencBufferStates_fx( set16_fx( hBWE_TD->mem_shb_res_fx, 0, MAX_LEN_MA_FILTER ); set16_fx( hBWE_TD->old_EnvSHBres_fx, 0, L_FRAME4k ); hBWE_TD->old_mean_EnvSHBres_fx = 0; + move16(); hBWE_TD->prev_enr_EnvSHBres_fx = 1; /*1.0f in Q0*/ + move32(); hBWE_TD->prev_enr_EnvSHBres_e = 31; - hBWE_TD->prev_shb_env_tilt_fx = 0; - hBWE_TD->prev_shb_env_tilt_q = 15; - hBWE_TD->prev_pow_exc16kWhtnd_fx32 = 1; /*1.0f in Q0*/ - hBWE_TD->prev_mix_factor_fx = 32767; /*1.0f in Q15*/ - hBWE_TD->prev_Env_error_fx = 0; - move16(); move16(); + hBWE_TD->prev_shb_env_tilt_fx = 0; move16(); + hBWE_TD->prev_Q_shb = 15; move16(); + hBWE_TD->prev_pow_exc16kWhtnd_fx32 = 1; /*1.0f in Q0*/ + move32(); + hBWE_TD->prev_mix_factor_fx = 32767; /*1.0f in Q15*/ move16(); + hBWE_TD->prev_Env_error_fx = 0; move16(); return; -- GitLab From 59e700e7831c9e502ec764a61c2bf44697ee4cb2 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Wed, 13 Nov 2024 12:07:32 +0530 Subject: [PATCH 115/128] EVS Bitexactness issue fix [x] Bitt exactness afftected with bug fix made for EVS code. Created a copy to address the bug. --- lib_enc/swb_bwe_enc_fx.c | 178 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 175 insertions(+), 3 deletions(-) diff --git a/lib_enc/swb_bwe_enc_fx.c b/lib_enc/swb_bwe_enc_fx.c index 91ffef59d..e4e4cb32d 100644 --- a/lib_enc/swb_bwe_enc_fx.c +++ b/lib_enc/swb_bwe_enc_fx.c @@ -2056,7 +2056,7 @@ static void calculate_Tonality_fx( { max = gen_spec[n_coeff];move16(); }*/ - max = s_max( max, gen_spec[n_coeff] ); + max = s_max( max, org_spec[n_coeff] ); } l_shift = norm_s( max ); FOR( n_coeff = 0; n_coeff < length; n_coeff++ ) @@ -2163,6 +2163,178 @@ static void calculate_Tonality_fx( return; } +#ifdef IVAS_FLOAT_FIXED +/*-------------------------------------------------------------------* + * calculate_Tonality_ivas_fx() + * + * Calculate tonality + *-------------------------------------------------------------------*/ + +static void calculate_Tonality_ivas_fx( + const Word16 *org, /* i : MDCT coefficients of original Q_new*/ + const Word16 *gen, /* i : MDCT coefficients of generated signal Q15*/ + Word16 *SFM_org, /* o : Spectral Flatness results Q12*/ + Word16 *SFM_gen, /* o : Spectral Flatness results Q12*/ + const Word16 length /* i : length for calculating tonality */ +) +{ + Word16 n_coeff; + Word16 inv_len, max; + Word16 exp, e_tmp, f_tmp; + Word32 L_tmp, L_tmp2, L_am_org, L_am_gen, L_tmp1; + Word16 org_spec[80], gen_spec[80]; + Word32 L_log_gm_org, L_log_gm_gen; + Word16 l_shift; +#ifdef BASOP_NOGLOB_DECLARE_LOCAL + Flag Overflow = 0; + move32(); +#endif + + /* to reduce dynamic range of original spectrum */ + max = 0; + move16(); + FOR( n_coeff = 0; n_coeff < length; n_coeff++ ) + { + org_spec[n_coeff] = abs_s( org[n_coeff] ); + move16(); /*Q_new */ + /*test(); */ + /*if( sub(max, org_spec[n_coeff]) < 0) */ + /*{ */ + /* max = org_spec[n_coeff];move16();//Q_new */ + /*} */ + max = s_max( max, org_spec[n_coeff] ); + } + l_shift = norm_s( max ); + FOR( n_coeff = 0; n_coeff < length; n_coeff++ ) + { + org_spec[n_coeff] = shl( org_spec[n_coeff], l_shift ); + move16(); + IF( org_spec[n_coeff] == 0 ) + { + org_spec[n_coeff] = shl( 1, l_shift ); + move16(); + } + } + + max = 0; + move16(); + FOR( n_coeff = 0; n_coeff < length; n_coeff++ ) + { + gen_spec[n_coeff] = abs_s( gen[n_coeff] ); + move16(); /*Q15 */ + /*test(); + if( sub(max,gen_spec[n_coeff]) < 0) + { + max = gen_spec[n_coeff];move16(); + }*/ + max = s_max( max, gen_spec[n_coeff] ); + } + l_shift = norm_s( max ); + FOR( n_coeff = 0; n_coeff < length; n_coeff++ ) + { +#ifdef BASOP_NOGLOB + gen_spec[n_coeff] = shl_sat( gen_spec[n_coeff], l_shift ); +#else + gen_spec[n_coeff] = shl( gen_spec[n_coeff], l_shift ); +#endif + move16(); + IF( gen_spec[n_coeff] == 0 ) + { + gen_spec[n_coeff] = shl( 1, l_shift ); + move16(); + } + } + + exp = norm_s( length ); + inv_len = div_s( shl( 1, exp ), shl( length, exp ) ); /*Q15 */ + + L_am_org = L_deposit_l( 0 ); + L_am_gen = L_deposit_l( 0 ); + L_log_gm_org = 0; + move32(); + L_log_gm_gen = 0; + move32(); + + FOR( n_coeff = 0; n_coeff < length; n_coeff++ ) + { + L_am_org = L_add( L_am_org, L_deposit_l( org_spec[n_coeff] ) ); /*Q10 */ + L_am_gen = L_add( L_am_gen, L_deposit_l( gen_spec[n_coeff] ) ); /*Q10 */ + + IF( org_spec[n_coeff] != 0 ) + { + L_tmp = L_deposit_h( org_spec[n_coeff] ); /*Q26 */ + e_tmp = norm_l( L_tmp ); + f_tmp = Log2_norm_lc( L_shl( L_tmp, e_tmp ) ); + e_tmp = sub( sub( 30, e_tmp ), 26 ); + L_tmp = Mpy_32_16( e_tmp, f_tmp, 24660 ); /* Q14 */ /*10log10(2) in Q13 */ + L_log_gm_org = L_add( L_log_gm_org, L_tmp ); /*Q14 */ + } + + IF( gen_spec[n_coeff] != 0 ) + { + L_tmp = L_deposit_h( gen_spec[n_coeff] ); /*Q26 */ + e_tmp = norm_l( L_tmp ); + f_tmp = Log2_norm_lc( L_shl( L_tmp, e_tmp ) ); + e_tmp = sub( sub( 30, e_tmp ), 26 ); + L_tmp = Mpy_32_16( e_tmp, f_tmp, 24660 ); /* Q14 */ /*10log10(2) in Q13 */ + L_log_gm_gen = L_add( L_log_gm_gen, L_tmp ); /*Q14 */ + } + } + + IF( L_am_org != 0 ) + { + L_tmp = Mpy_32_16_1( L_am_org, inv_len ); /*Q10 */ + e_tmp = norm_l( L_tmp ); + f_tmp = Log2_norm_lc( L_shl( L_tmp, e_tmp ) ); + e_tmp = sub( sub( 30, e_tmp ), 10 ); + L_tmp1 = Mpy_32_16( e_tmp, f_tmp, 24660 ); /* Q14 */ /*10log10(2) in Q13 */ + } + ELSE + { + L_tmp1 = L_deposit_l( 0 ); + } + + L_tmp2 = Mpy_32_16_1( L_log_gm_org, inv_len ); /* Q14 */ + + L_tmp = L_sub( L_tmp1, L_tmp2 ); +#ifdef BASOP_NOGLOB + *SFM_org = round_fx_o( L_shl_o( L_tmp, 14, &Overflow ), &Overflow ); /*Q12 */ +#else + *SFM_org = round_fx( L_shl( L_tmp, 14 ) ); /*Q12 */ +#endif + move16(); + *SFM_org = s_max( 0, s_min( *SFM_org, 24547 ) ); + move16(); /*0.0001 and 5.993 in Q12 */ + + IF( L_am_gen != 0 ) + { + L_tmp = Mpy_32_16_1( L_am_gen, inv_len ); /*Q10 */ + e_tmp = norm_l( L_tmp ); + f_tmp = Log2_norm_lc( L_shl( L_tmp, e_tmp ) ); + e_tmp = sub( sub( 30, e_tmp ), 10 ); + L_tmp1 = Mpy_32_16( e_tmp, f_tmp, 24660 ); /* Q14 */ /*10log10(2) in Q13 */ + } + ELSE + { + L_tmp1 = L_deposit_l( 0 ); + } + + L_tmp2 = Mpy_32_16_1( L_log_gm_gen, inv_len ); /* Q14 */ + + L_tmp = L_sub( L_tmp1, L_tmp2 ); +#ifdef BASOP_NOGLOB + *SFM_gen = round_fx_o( L_shl_o( L_tmp, 14, &Overflow ), &Overflow ); /*Q12 */ +#else + *SFM_gen = round_fx( L_shl( L_tmp, 14 ) ); /*Q12 */ +#endif + move16(); + *SFM_gen = s_max( 0, s_min( *SFM_gen, 24547 ) ); + move16(); /*0.0001 and 5.993 in Q12 */ + + return; +} +#endif + /*-------------------------------------------------------------------* * energy_control_fx() * @@ -2333,8 +2505,8 @@ static void energy_control_ivas_fx( FOR( n_band = 0; n_band < max_band; ) { - calculate_Tonality_fx( org_fx + swb_bwe_subband[n_band] + offset, SWB_signal_fx + swb_bwe_subband[n_band] + offset, - &SFM_org_fx[n_band], &SFM_gen_fx[n_band], swb_bwe_subband[n_band + band_step] - swb_bwe_subband[n_band] ); + calculate_Tonality_ivas_fx( org_fx + swb_bwe_subband[n_band] + offset, SWB_signal_fx + swb_bwe_subband[n_band] + offset, + &SFM_org_fx[n_band], &SFM_gen_fx[n_band], swb_bwe_subband[n_band + band_step] - swb_bwe_subband[n_band] ); IF( LT_16( SFM_gen_fx[n_band], mult_r( 24576, SFM_org_fx[n_band] ) ) ) { -- GitLab From 99a8a25b9a06d9e37276220bae95b14700487992 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Wed, 13 Nov 2024 13:00:46 +0530 Subject: [PATCH 116/128] EVS bit exactness issue fix --- lib_dec/core_dec_init_fx.c | 2 +- lib_dec/tonalMDCTconcealment_fx.c | 17 ++++++++++------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/lib_dec/core_dec_init_fx.c b/lib_dec/core_dec_init_fx.c index 537b586f3..b723bea2c 100644 --- a/lib_dec/core_dec_init_fx.c +++ b/lib_dec/core_dec_init_fx.c @@ -1057,7 +1057,7 @@ void open_decoder_LPD_fx( st->tonalMDCTconceal.lastBlockData.nSamples = 0; move16(); - TonalMDCTConceal_Init_ivas_fx( &st->tonalMDCTconceal, hTcxDec->L_frameTCX, st->L_frame, FDNS_NPTS, st->hTcxCfg ); + TonalMDCTConceal_Init( &st->tonalMDCTconceal, hTcxDec->L_frameTCX, st->L_frame, FDNS_NPTS, st->hTcxCfg ); } st->last_tns_active = 0; move16(); diff --git a/lib_dec/tonalMDCTconcealment_fx.c b/lib_dec/tonalMDCTconcealment_fx.c index fa085d987..6e3ddcfd2 100644 --- a/lib_dec/tonalMDCTconcealment_fx.c +++ b/lib_dec/tonalMDCTconcealment_fx.c @@ -83,7 +83,10 @@ ivas_error TonalMDCTConceal_Init( hTonalMDCTConc->secondLastBlockData.blockIsConcealed = 0; move16(); + hTonalMDCTConc->pTCI = (TonalComponentsInfo *) hTonalMDCTConc->timeDataBuffer; move16(); + + hTonalMDCTConc->lastPitchLag = L_deposit_l( 0 ); IF( NE_16( hTonalMDCTConc->nSamples, nSamples ) ) @@ -103,14 +106,14 @@ ivas_error TonalMDCTConceal_Init( move16(); #ifdef IVAS_CODE_CNG_FIX185_PLC_FADEOUT PMTE() - set_zero( hTonalMDCTConc->scaleFactorsBackground_flt, FDNS_NPTS ); + set_zero( hTonalMDCTConc->scaleFactorsBackground, FDNS_NPTS ); PsychoacousticParameters_Init( INT_FS_16k, L_FRAME16k, 64, 1, 1, &hTonalMDCTConc->psychParamsTCX20 ); PsychoacousticParameters_Init( INT_FS_16k, L_FRAME16k / 2, 64, 0, 1, &hTonalMDCTConc->psychParamsTCX10 ); hTonalMDCTConc->psychParams = NULL; - hTonalMDCTConc->scf_fadeout_flt = 1.0f; - hTonalMDCTConc->last_block_nrg_flt = 0.0f; - hTonalMDCTConc->curr_noise_nrg_flt = 0.0f; - hTonalMDCTConc->faded_signal_nrg_flt = 0.0f; + hTonalMDCTConc->scf_fadeout = 1.0f; + hTonalMDCTConc->last_block_nrg = 0.0f; + hTonalMDCTConc->curr_noise_nrg = 0.0f; + hTonalMDCTConc->faded_signal_nrg = 0.0f; #endif /* Offset the pointer to the end of buffer, so that pTCI is not destroyed when @@ -118,8 +121,8 @@ ivas_error TonalMDCTConceal_Init( move16(); move16(); /* just the second half of the second last pcm output is needed */ - hTonalMDCTConc->secondLastPcmOut = &hTonalMDCTConc->timeDataBuffer[( 3 * L_FRAME_MAX ) / 2 - ( 3 * ( min( L_FRAME_MAX, nSamples ) ) / 2 )]; - hTonalMDCTConc->lastPcmOut = &hTonalMDCTConc->timeDataBuffer[( 3 * L_FRAME_MAX ) / 2 - min( L_FRAME_MAX, nSamples )]; + hTonalMDCTConc->secondLastPcmOut = &hTonalMDCTConc->timeDataBuffer[sub( ( 3 * L_FRAME_MAX ) / 2, 3 * ( s_min( L_FRAME_MAX, nSamples ) ) / 2 )]; + hTonalMDCTConc->lastPcmOut = &hTonalMDCTConc->timeDataBuffer[sub( ( 3 * L_FRAME_MAX ) / 2, s_min( L_FRAME_MAX, nSamples ) )]; /* If the second last frame was lost, we reuse saved TonalComponentsInfo and don't update pcm buffers */ assert( sizeof( *hTonalMDCTConc->pTCI ) <= ( hTonalMDCTConc->lastPcmOut - hTonalMDCTConc->timeDataBuffer ) * sizeof( hTonalMDCTConc->timeDataBuffer[0] ) ); -- GitLab From 030ac1b88becc534c6ebe32572780ac286840219 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Wed, 13 Nov 2024 13:34:19 +0530 Subject: [PATCH 117/128] Fix for 3GPP issue 1006: Very high MLD for 7_1_4, 160kbps, -26LKFS input, with deterministic packet loss pattern link #1006 --- lib_dec/ivas_lfe_plc_fx.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/lib_dec/ivas_lfe_plc_fx.c b/lib_dec/ivas_lfe_plc_fx.c index efd158caf..52b94b46f 100644 --- a/lib_dec/ivas_lfe_plc_fx.c +++ b/lib_dec/ivas_lfe_plc_fx.c @@ -1201,7 +1201,7 @@ static void recover_samples_fx( Word16 d_r_q_fx[LFE_PLC_LPCORD + 1], d_a_q_fx[LFE_PLC_LPCORD + 1]; Word32 d_r_fx[LFE_PLC_LPCORD + 1], zeroes_fx[LFE_PLC_RECLEN]; Word32 delta_fx, fac_fx, att_fx, temp; - Word16 delta_q_fx, fac_q_fx, att_q_fx, temp_q, exp1, exp2; + Word16 delta_q_fx, fac_q_fx, temp_q, exp1, exp2; Copy32( outbuf_fx, d_outbuf_fx, LFE_PLC_BUFLEN ); @@ -1229,17 +1229,14 @@ static void recover_samples_fx( fac_q_fx = Q29; move16(); } - att_fx = ONE_IN_Q30; + att_fx = ONE_IN_Q31; move32(); - att_q_fx = Q30; - move16(); IF( GE_16( bfi_count, LFE_PLC_MUTE_THR ) ) { att_fx = LFE_PLC_BURST_ATT_Q31; move32(); fac_fx = Mpy_32_32( fac_fx, att_fx ); - fac_q_fx = sub( add( fac_q_fx, att_q_fx ), 31 ); } FOR( i = 1; i <= LFE_PLC_LPCORD; i++ ) @@ -1265,10 +1262,9 @@ static void recover_samples_fx( temp_q = Q30; move16(); } - exp1 = norm_l( att_fx ); exp2 = norm_l( temp ); - temp = Mpy_32_32( L_shl( att_fx, exp1 ), L_shl( temp, exp2 ) ); - temp_q = sub( add( add( att_q_fx, exp1 ), add( temp_q, exp2 ) ), 31 ); + temp = Mpy_32_32( att_fx, L_shl( temp, exp2 ) ); + temp_q = add( temp_q, exp2 ); exp1 = norm_l( fac_fx ); exp2 = norm_l( temp ); -- GitLab From 6f5ead8f990d6b1a47cd8590549a7d597b2a928f Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Wed, 13 Nov 2024 14:20:41 +0530 Subject: [PATCH 118/128] Integration of encod_unvoiced_ivas_fx, encod_tran_ivas_fx, encod_gen_voic_ivas_fx, encod_audio_ivas_fx stacks --- lib_com/ivas_prot_fx.h | 4 +- lib_com/swb_tbe_com_fx.c | 27 +- lib_enc/acelp_core_enc.c | 442 ++++++-------- lib_enc/acelp_enc_util_fx.c | 29 + lib_enc/avq_cod_fx.c | 496 +++++++++++++++- lib_enc/cod2t32_fx.c | 389 +++++++++++- lib_enc/cod4t64_fast.c | 40 +- lib_enc/cod4t64_fx.c | 422 ++++++++++++- lib_enc/core_enc_init.c | 2 - lib_enc/core_enc_switch.c | 3 +- lib_enc/corr_xh_fx.c | 141 ++++- lib_enc/enc_acelp_fx.c | 68 ++- lib_enc/enc_acelpx_fx.c | 270 +++++++++ lib_enc/enc_gen_voic_fx.c | 385 +++++++++++- lib_enc/enc_higher_acelp_fx.c | 420 ++++++++++++- lib_enc/enc_pit_exc_fx.c | 526 +++++++++++++++- lib_enc/enc_tran_fx.c | 405 +++++++++++++ lib_enc/enc_uv_fx.c | 263 +++++++- lib_enc/eval_pit_contr_fx.c | 393 +++++++++++- lib_enc/gain_enc_fx.c | 481 ++++++++++++++- lib_enc/gaus_enc_fx.c | 115 +++- lib_enc/gp_clip_fx.c | 2 +- lib_enc/gs_enc_fx.c | 354 ++++++++++- lib_enc/hq_core_enc.c | 3 +- lib_enc/init_enc.c | 3 +- lib_enc/inov_enc_fx.c | 211 +++---- lib_enc/ivas_tcx_core_enc.c | 2 +- lib_enc/ivas_td_low_rate_enc.c | 29 +- lib_enc/pit_enc_fx.c | 10 +- lib_enc/prot_fx_enc.h | 302 ++++++++++ lib_enc/set_impulse_fx.c | 4 + lib_enc/stat_enc.h | 2 - lib_enc/transition_enc_fx.c | 1022 +++++++++++++++++++++++++++++++- 33 files changed, 6782 insertions(+), 483 deletions(-) diff --git a/lib_com/ivas_prot_fx.h b/lib_com/ivas_prot_fx.h index dff4997f0..2cf76473c 100644 --- a/lib_com/ivas_prot_fx.h +++ b/lib_com/ivas_prot_fx.h @@ -3008,7 +3008,7 @@ void encod_gen_2sbfr( Word16 *bwe_exc, /* o : excitation for SWB TBE */ const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag */ const Word16 tdm_Pri_pitch_buf[], /* i : pitch values for primary channel */ - Word16 *Q_new ); + Word16 Q_new ); void acelp_fast_fx( BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ @@ -4439,7 +4439,7 @@ void tdm_low_rate_enc( /* i : current frame ISF vector */ // x2.56 Word16 *tmp_noise, /* o : long-term noise energy */ // Q8 - Word16 *Q_new ); + Word16 Q_new ); void tdm_low_rate_dec_fx( Decoder_State *st, /* i/o: decoder static memory */ diff --git a/lib_com/swb_tbe_com_fx.c b/lib_com/swb_tbe_com_fx.c index e9b9530f3..aa4a1e2be 100644 --- a/lib_com/swb_tbe_com_fx.c +++ b/lib_com/swb_tbe_com_fx.c @@ -6486,7 +6486,7 @@ void prep_tbe_exc_ivas_fx( #ifdef BASOP_NOGLOB pitch = shl_o( add( shl_o( T0, 2, &Overflow ), T0_frac ), 5, &Overflow ); /* Q7 */ #else /* BASOP_NOGLOB */ - pitch = shl( add( shl( T0, 2 ), T0_frac ), 5 ); /* Q7 */ + pitch = shl( add( shl( T0, 2 ), T0_frac ), 5 ); /* Q7 */ #endif /* BASOP_NOGLOB */ test(); @@ -6518,20 +6518,21 @@ void prep_tbe_exc_ivas_fx( #ifdef BASOP_NOGLOB gain_code16 = round_fx_o( L_shl_o( gain_code_fx, Q_exc, &Overflow ), &Overflow ); /*Q_exc */ #else - gain_code16 = round_fx( L_shl( gain_code_fx, Q_exc ) ); /*Q_exc */ + gain_code16 = round_fx( L_shl( gain_code_fx, Q_exc ) ); /*Q_exc */ #endif FOR( i = 0; i < L_subfr * HIBND_ACB_L_FAC; i++ ) { - L_tmp = L_mult( gain_code16, tmp_code_fx[i] ); /* Q9 + Q_exc + 1*/ - L_tmp = L_shl( L_tmp, 5 ); /* Q9 + Q_exc + Q6*/ - L_tmp = L_mac( L_tmp, gain_pit_fx, bwe_exc_fx[i + i_subfr_fx * HIBND_ACB_L_FAC] ); /*Q15+Q_exc */ + L_tmp = L_mult( gain_code16, tmp_code_fx[i] ); /* Q9 + Q_exc + 1*/ + L_tmp = L_shl( L_tmp, 5 ); /* Q9 + Q_exc + Q6*/ #ifdef BASOP_NOGLOB - L_tmp = L_shl_o( L_tmp, 1, &Overflow ); /*16+Q_exc */ /* saturation can occur here */ - bwe_exc_fx[i + i_subfr_fx * HIBND_ACB_L_FAC] = round_fx_o( L_tmp, &Overflow ); /*Q_exc */ -#else /* BASOP_NOGLOB */ - L_tmp = L_shl( L_tmp, 1 ); /*16+Q_exc */ /* saturation can occur here */ - bwe_exc_fx[i + i_subfr_fx * HIBND_ACB_L_FAC] = round_fx( L_tmp ); /*Q_exc */ -#endif /* BASOP_NOGLOB */ + L_tmp = L_mac_o( L_tmp, gain_pit_fx, bwe_exc_fx[i + i_subfr_fx * HIBND_ACB_L_FAC], &Overflow ); /*Q15+Q_exc */ + L_tmp = L_shl_o( L_tmp, 1, &Overflow ); /*16+Q_exc */ /* saturation can occur here */ + bwe_exc_fx[i + i_subfr_fx * HIBND_ACB_L_FAC] = round_fx_o( L_tmp, &Overflow ); /*Q_exc */ +#else /* BASOP_NOGLOB */ + L_tmp = L_mac( L_tmp, gain_pit_fx, bwe_exc_fx[i + i_subfr_fx * HIBND_ACB_L_FAC] ); /*Q15+Q_exc */ + L_tmp = L_shl( L_tmp, 1 ); /*16+Q_exc */ /* saturation can occur here */ + bwe_exc_fx[i + i_subfr_fx * HIBND_ACB_L_FAC] = round_fx( L_tmp ); /*Q_exc */ +#endif /* BASOP_NOGLOB */ move16(); } } @@ -6558,8 +6559,8 @@ void prep_tbe_exc_ivas_fx( tmp_code_preInt_fx[i] = round_fx_o( L_add_o( Ltemp1, Ltemp2, &Overflow ), &Overflow ); /* Q_exc */ #else /* BASOP_NOGLOB */ - Ltemp1 = L_shl( Ltemp1, Q_exc + 6 /*Q_exc+16-19*/ ); /*Q_exc+16 */ - Ltemp2 = L_shl( Ltemp2, Q_exc + 4 /*Q_exc+16-13*/ ); /*Q_exc+16 */ + Ltemp1 = L_shl( Ltemp1, Q_exc + 6 /*Q_exc+16-19*/ ); /*Q_exc+16 */ + Ltemp2 = L_shl( Ltemp2, Q_exc + 4 /*Q_exc+16-13*/ ); /*Q_exc+16 */ tmp_code_preInt_fx[i] = round_fx( L_add( Ltemp1, Ltemp2 ) ); /* Q_exc */ #endif /* BASOP_NOGLOB */ diff --git a/lib_enc/acelp_core_enc.c b/lib_enc/acelp_core_enc.c index 47ccebb56..e5d162502 100644 --- a/lib_enc/acelp_core_enc.c +++ b/lib_enc/acelp_core_enc.c @@ -95,10 +95,10 @@ ivas_error acelp_core_enc( float Aq[NB_SUBFR16k * ( M + 1 )]; /* A(z) quantized for the 4 subframes */ float syn[L_FRAME16k]; /* synthesis signal buffer */ float res[L_FRAME16k]; /* Residual signal for FER protection */ -#endif // IVAS_FLOAT_FIXED_CONVERSIONS - float exc2[L_FRAME16k]; /* enhanced excitation */ - float Es_pred; /* predicited scaled innovation energy */ - float tmp_noise; /* NB post-filter long-term noise energy*/ +#endif // IVAS_FLOAT_FIXED_CONVERSIONS + float exc2[L_FRAME16k]; /* enhanced excitation */ + float Es_pred; /* predicited scaled innovation energy */ + // float tmp_noise; /* NB post-filter long-term noise energy*/ Word16 tc_subfr; /* TC sub-frame indication */ float old_bwe_exc[( PIT16k_MAX + ( L_FRAME16k + 1 ) + L_SUBFR16k ) * 2]; /* excitation buffer */ float *bwe_exc; /* excitation for SWB TBE */ @@ -108,7 +108,7 @@ ivas_error acelp_core_enc( /* SC-VBR - back-up memories for LSF quantizer and synthesis filter */ Word16 pstreaklen; - float mem_MA[M], mem_AR[M], Bin_E[L_FFT], Bin_E_old[L_FFT / 2], lsp_new_bck[M], lsp_mid_bck[M], mem_syn_bck[M]; + float /* mem_MA[M], mem_AR[M], Bin_E[L_FFT], Bin_E_old[L_FFT / 2],*/ lsp_new_bck[M], lsp_mid_bck[M], mem_syn_bck[M]; float q_env[NUM_ENV_CNG]; Word16 sid_bw = -1; @@ -121,12 +121,12 @@ ivas_error acelp_core_enc( // float tmpF; Word16 ppp_mode, nelp_mode; Word16 tdm_lp_reuse_flag, tdm_low_rate_mode, tdm_Pitch_reuse_flag; - float *tdm_Pri_pitch_buf; + // float *tdm_Pri_pitch_buf; /* bitstream */ BSTR_ENC_HANDLE hBstr = st->hBstr; #if 1 - Word16 Q_exc = 0; + // Word16 Q_exc = 0; move16(); Word16 A_fx[85], Aw_fx[85]; Word16 old_exc_fx[L_EXC], *exc_fx; /* excitation signal buffer */ @@ -140,7 +140,7 @@ ivas_error acelp_core_enc( // Word16 tc_subfr_fx; /* TC sub-frame indication */ Word16 old_bwe_exc_fx[( PIT16k_MAX + ( L_FRAME16k + 1 ) + L_SUBFR16k ) * 2]; /* excitation buffer */ - Word16 Q_old_bwe_exc; + // Word16 Q_old_bwe_exc; Word16 *bwe_exc_fx; /* excitation for SWB TBE */ // Word16 allow_cn_step_fx; // Word16 int_fs_fx; @@ -183,8 +183,8 @@ ivas_error acelp_core_enc( Word16 tmpF_fx; #endif #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - Word16 pitch_buf_fx[NB_SUBFR16k]; /* To be removed once this is taken as input arg of function */ - Word16 voice_factors_fx[NB_SUBFR16k]; /* To be removed once this is taken as input arg of function */ + Word16 pitch_buf_fx[NB_SUBFR16k] = { 0 }; /* To be removed once this is taken as input arg of function */ + Word16 voice_factors_fx[NB_SUBFR16k] = { 0 }; /* To be removed once this is taken as input arg of function */ Word16 tmp; set_zero( old_bwe_exc, 1380 ); for ( i = 0; i < NB_SUBFR16k; i++ ) @@ -194,34 +194,42 @@ ivas_error acelp_core_enc( f2me_buf_16( &A[i * ( M + 1 )], &A_fx[i * ( M + 1 )], &tmp, ( M + 1 ) ); f2me_buf_16( &Aw[i * ( M + 1 )], &Aw_fx[i * ( M + 1 )], &tmp, ( M + 1 ) ); } - IF( st->hLPDmem ) - f2me_buf_16( &st->hLPDmem->old_exc_flt[-M - 1], &st->hLPDmem->old_exc[-M - 1], &st->hLPDmem->e_old_exc, L_EXC_MEM + M + 1 ); - IF( st->hBWE_TD ) - floatToFixed_arr16( st->hBWE_TD->old_bwe_exc, st->hBWE_TD->old_bwe_exc_fx, Q_exc, PIT16k_MAX * 2 ); floatToFixed_arr16( lsp_mid, lsp_mid_fx, 15, M ); floatToFixed_arr16( lsp_new, lsp_new_fx, 15, M ); + Word16 inp_buff[L_FRAME16k + M + 1]; + Word16 *inp_fx; + inp_fx = &inp_buff[M + 1]; + Word16 q_comm_Bin, Q_new /* Q_new will be later passed from parent function as arg */; + q_comm_Bin = min( Q_factor_arrL( st->Bin_E_old, 128 ), Q_factor_arrL( st->Bin_E, 256 ) ); + Q_new = Q_factor_arr( &inp[-M - 1], L_FRAME16k + M + 1 ); + Q_new = min( Q_new, q_comm_Bin - ( QSCALE - 2 ) ); + Q_new = min( Q_new, 5 ); + IF( st->hBWE_TD ) + { + Q_new = min( Q_new, Q_factor_arrL( st->hBWE_TD->old_bwe_exc, PIT16k_MAX * 2 ) ); + } IF( st->hLPDmem ) { + Q_new = min( Q_new, Q_factor_arrL( &st->hLPDmem->old_exc_flt[-M - 1], L_EXC_MEM + M + 1 ) ); + floatToFixed_arr( &st->hLPDmem->old_exc_flt[-M - 1], &st->hLPDmem->old_exc[-M - 1], Q_new, L_EXC_MEM + M + 1 ); Word16 Q_temp = s_min( Q_factor_arr( st->hLPDmem->mem_syn_flt, 16 ), s_min( Q_factor_arr( st->hLPDmem->mem_syn1_flt, 16 ), s_min( Q_factor_arr( st->hLPDmem->mem_syn2_flt, 16 ), s_min( Q_factor_arr( st->hLPDmem->mem_syn3_flt, 16 ), Q_factor_arr( st->hLPDmem->mem_syn_r_flt, 60 ) ) ) ) ); - st->hLPDmem->e_mem_syn = Q31 - Q_temp; - floatToFixed_arr( st->hLPDmem->mem_syn_flt, st->hLPDmem->mem_syn, Q_temp, 16 ); - floatToFixed_arr( st->hLPDmem->mem_syn1_flt, st->hLPDmem->mem_syn1_fx, Q_temp, 16 ); - floatToFixed_arr( st->hLPDmem->mem_syn2_flt, st->hLPDmem->mem_syn2, Q_temp, 16 ); - floatToFixed_arr( st->hLPDmem->mem_syn3_flt, st->hLPDmem->mem_syn3, Q_temp, 16 ); - floatToFixed_arr( st->hLPDmem->mem_syn_r_flt, st->hLPDmem->mem_syn_r, Q_temp, 60 ); + Q_new = min( Q_temp, Q_new ); + // st->hLPDmem->mem_syn_q = Q_new; + floatToFixed_arr( st->hLPDmem->mem_syn_flt, st->hLPDmem->mem_syn, Q_new - 1, 16 ); + floatToFixed_arr( st->hLPDmem->mem_syn1_flt, st->hLPDmem->mem_syn1_fx, Q_new - 1, 16 ); + floatToFixed_arr( st->hLPDmem->mem_syn2_flt, st->hLPDmem->mem_syn2, Q_new - 1, 16 ); + floatToFixed_arr( st->hLPDmem->mem_syn3_flt, st->hLPDmem->mem_syn3, Q_new - 1, 16 ); + floatToFixed_arr( st->hLPDmem->mem_syn_r_flt, st->hLPDmem->mem_syn_r, Q_new - 1, 60 ); + } + // Q_new = Q_new - 3; //guard bits + IF( st->hBWE_TD ) + { + floatToFixed_arr( st->hBWE_TD->old_bwe_exc, st->hBWE_TD->old_bwe_exc_fx, Q_new, PIT16k_MAX * 2 ); } - Word16 inp_buff[L_FRAME16k + M + 1]; - Word16 *inp_fx; - inp_fx = &inp_buff[M + 1]; - Word16 q_comm_Bin, Q_new /* Q_new will be later passed from parent function as arg */; - q_comm_Bin = s_min( Q_factor_arrL( st->Bin_E_old, 128 ), Q_factor_arrL( st->Bin_E, 256 ) ); - Q_new = Q_factor_arr( &inp[-M - 1], L_FRAME16k + M + 1 ); - Q_new = s_min( Q_new, q_comm_Bin - ( QSCALE - 2 ) ); - Q_new = s_min( Q_new, 5 ); - floatToFixed_arr( &inp[-M - 1], &inp_fx[-M - 1], Q_new, L_FRAME16k + M + 1 ); + floatToFixed_arr( &inp[-M - 1], &inp_fx[-M - 1], Q_new - 1, L_FRAME16k + M + 1 ); floatToFixed_arrL( st->Bin_E_old, st->Bin_E_old_fx, Q_new + Q_SCALE - 2, 128 ); floatToFixed_arrL( st->Bin_E, st->Bin_E_fx, Q_new + Q_SCALE - 2, 256 ); #endif @@ -307,7 +315,6 @@ ivas_error acelp_core_enc( move32(); } - tmp_noise = 0; tmp_noise_fx = 0; move16(); tc_subfr = -1; @@ -349,16 +356,12 @@ ivas_error acelp_core_enc( test(); /* TD stereo */ - float tdm_Pri_pitch_buf_flt[NB_SUBFR]; - set_zero( tdm_Pri_pitch_buf_flt, NB_SUBFR ); IF( EQ_16( st->element_mode, IVAS_CPE_TD ) && EQ_16( st->idchan, 1 ) ) { tdm_lp_reuse_flag = hStereoTD->tdm_lp_reuse_flag; tdm_low_rate_mode = hStereoTD->tdm_low_rate_mode; tdm_Pitch_reuse_flag = hStereoTD->tdm_Pitch_reuse_flag; tdm_Pri_pitch_buf_fx = hStereoTD->tdm_Pri_pitch_buf_fx; - fixedToFloat_arr( tdm_Pri_pitch_buf_fx, tdm_Pri_pitch_buf_flt, Q6, NB_SUBFR ); - tdm_Pri_pitch_buf = tdm_Pri_pitch_buf_flt; } ELSE { @@ -371,7 +374,6 @@ ivas_error acelp_core_enc( move16(); } tdm_Pitch_reuse_flag = 0; - tdm_Pri_pitch_buf = NULL; tdm_Pri_pitch_buf_fx = NULL; } move16(); @@ -438,15 +440,16 @@ ivas_error acelp_core_enc( #ifdef IVAS_FLOAT_FIXED_CONVERSIONS IF( st->hLPDmem ) { - Word16 Q_temp = Q31 - st->hLPDmem->e_mem_syn; - fixedToFloat_arr( st->hLPDmem->mem_syn, st->hLPDmem->mem_syn_flt, Q_temp, 16 ); - fixedToFloat_arr( st->hLPDmem->mem_syn1_fx, st->hLPDmem->mem_syn1_flt, Q_temp, 16 ); - fixedToFloat_arr( st->hLPDmem->mem_syn2, st->hLPDmem->mem_syn2_flt, Q_temp, 16 ); - fixedToFloat_arr( st->hLPDmem->mem_syn3, st->hLPDmem->mem_syn3_flt, Q_temp, 16 ); - fixedToFloat_arr( st->hLPDmem->mem_syn_r, st->hLPDmem->mem_syn_r_flt, Q_temp, 60 ); + fixedToFloat_arr( st->hLPDmem->mem_syn, st->hLPDmem->mem_syn_flt, Q_new - 1, 16 ); + fixedToFloat_arr( st->hLPDmem->mem_syn1_fx, st->hLPDmem->mem_syn1_flt, Q_new - 1, 16 ); + fixedToFloat_arr( st->hLPDmem->mem_syn2, st->hLPDmem->mem_syn2_flt, Q_new - 1, 16 ); + fixedToFloat_arr( st->hLPDmem->mem_syn3, st->hLPDmem->mem_syn3_flt, Q_new - 1, 16 ); + fixedToFloat_arr( st->hLPDmem->mem_syn_r, st->hLPDmem->mem_syn_r_flt, Q_new - 1, 60 ); } - me2f_buf_16( &st->hLPDmem->old_exc[-M - 1], st->hLPDmem->e_old_exc, &st->hLPDmem->old_exc_flt[-M - 1], L_EXC_MEM + M + 1 ); - me2f_buf_16( old_exc_fx, st->hLPDmem->e_old_exc, old_exc_flt, L_EXC_MEM ); + // me2f_buf_16( &st->hLPDmem->old_exc[-M - 1], st->hLPDmem->e_old_exc, &st->hLPDmem->old_exc_flt[-M - 1], L_EXC_MEM + M + 1 ); + fixedToFloat_arr( &st->hLPDmem->old_exc[-M - 1], &st->hLPDmem->old_exc_flt[-M - 1], Q_new, L_EXC_MEM + M + 1 ); + // me2f_buf_16( old_exc_fx, st->hLPDmem->e_old_exc, old_exc_flt, L_EXC_MEM ); + fixedToFloat_arr( old_exc_fx, old_exc_flt, Q_new, L_EXC_MEM ); for ( i = 0; i < NB_SUBFR16k; i++ ) { // Array is getting modified in chunks of 17 inside. @@ -483,25 +486,22 @@ ivas_error acelp_core_enc( #endif cng_params_postupd_ivas_fx( st->hTdCngEnc->ho_circ_ptr, &st->hTdCngEnc->cng_buf_cnt, st->hTdCngEnc->cng_exc2_buf, st->hTdCngEnc->cng_Qexc_buf, st->hTdCngEnc->cng_brate_buf, st->hTdCngEnc->ho_env_circ_fx, st->element_mode, st->hFdCngEnc->hFdCngCom->CngBandwidth ); #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - Word16 q_inp; floatToFixed_arr( Aq, Aq_fx, NB_SUBFR16k * ( M + 1 ), Q12 ); - q_inp = Q_factor_arr( inp, st->L_frame ); - floatToFixed_arr( inp, inp_fx, q_inp, st->L_frame ); floatToFixed_arr( lsp_mid, lsp_mid_fx, Q15, M ); floatToFixed_arr( lsp_new, lsp_new_fx, Q15, M ); - floatToFixed_arr( st->hTdCngEnc->exc_mem2, st->hTdCngEnc->exc_mem2_fx, q_inp, 30 ); + floatToFixed_arr( st->hTdCngEnc->exc_mem2, st->hTdCngEnc->exc_mem2_fx, Q_new - 1, 30 ); for ( i = 0; i < M; i++ ) { lsf_new_fx[i] = (Word16) ( lsf_new[i] * 2.56f ); } #endif /* encode CNG parameters */ - CNG_enc_ivas_fx( st, Aq_fx, inp_fx, /*ener_fx,*/ lsp_mid_fx, lsp_new_fx, lsf_new_fx, &allow_cn_step, q_inp, q_env_fx, &sid_bw ); + CNG_enc_ivas_fx( st, Aq_fx, inp_fx, /*ener_fx,*/ lsp_mid_fx, lsp_new_fx, lsf_new_fx, &allow_cn_step, sub( Q_new, 1 ), q_env_fx, &sid_bw ); #ifdef IVAS_FLOAT_FIXED_CONVERSIONS fixedToFloat_arr( Aq_fx, Aq, Q12, NB_SUBFR16k * ( M + 1 ) ); fixedToFloat_arr( lsp_new_fx, lsp_new, Q15, M ); fixedToFloat_arrL32( q_env_fx, q_env, Q6, NUM_ENV_CNG ); - fixedToFloat_arr( st->hTdCngEnc->exc_mem2_fx, st->hTdCngEnc->exc_mem2, q_inp, 30 ); + fixedToFloat_arr( st->hTdCngEnc->exc_mem2_fx, st->hTdCngEnc->exc_mem2, Q_new - 1, 30 ); for ( i = 0; i < M; i++ ) { lsf_new[i] = ( (float) lsf_new_fx[i] / 2.56f ); @@ -519,8 +519,8 @@ ivas_error acelp_core_enc( // Word16 Q_exc_l = Q_factor_arr( st->hTdCngEnc->exc_mem, 24 ); // Word16 Q_exc1_l = Q_factor_arr( st->hTdCngEnc->exc_mem1, 30 ); // Q_exc_l = min( Q_exc_l, Q_exc1_l ); - floatToFixed_arr( st->hTdCngEnc->exc_mem, st->hTdCngEnc->exc_mem_fx, Q_new, 24 ); - floatToFixed_arr( st->hTdCngEnc->exc_mem1, st->hTdCngEnc->exc_mem1_fx, Q_new, 30 ); + floatToFixed_arr( st->hTdCngEnc->exc_mem, st->hTdCngEnc->exc_mem_fx, Q_new - 1, 24 ); + floatToFixed_arr( st->hTdCngEnc->exc_mem1, st->hTdCngEnc->exc_mem1_fx, Q_new - 1, 30 ); #endif /* comfort noise generation */ @@ -528,17 +528,17 @@ ivas_error acelp_core_enc( //&st->hTdCngEnc->cng_ener_seed, bwe_exc, allow_cn_step, &st->hTdCngEnc->last_allow_cn_step, st->hTdCngEnc->num_ho, q_env, st->hTdCngEnc->lp_env, st->hTdCngEnc->old_env, // st->hTdCngEnc->exc_mem, st->hTdCngEnc->exc_mem1, &sid_bw, &st->hTdCngEnc->cng_ener_seed1, exc3, st->Opt_AMR_WB, EVS_MONO ); CNG_exc_fx( st->core_brate, st->L_frame, &st->hTdCngEnc->Enew_fx, &st->hTdCngEnc->cng_seed, exc_fx, exc2_fx, &st->hTdCngEnc->lp_ener_fx, st->last_core_brate, - &st->hDtxEnc->first_CNG, &st->hTdCngEnc->cng_ener_seed, bwe_exc_fx, allow_cn_step, &st->hTdCngEnc->last_allow_cn_step, sub( st->prev_Q_new, 1 ), Q_new, st->hTdCngEnc->num_ho, + &st->hDtxEnc->first_CNG, &st->hTdCngEnc->cng_ener_seed, bwe_exc_fx, allow_cn_step, &st->hTdCngEnc->last_allow_cn_step, sub( st->prev_Q_new, 1 ), sub( Q_new, 1 ), st->hTdCngEnc->num_ho, q_env_fx, st->hTdCngEnc->lp_env_fx, st->hTdCngEnc->old_env_fx, st->hTdCngEnc->exc_mem_fx, st->hTdCngEnc->exc_mem1_fx, &sid_bw, &st->hTdCngEnc->cng_ener_seed1, exc3_fx, st->Opt_AMR_WB, EVS_MONO ); #ifdef IVAS_FLOAT_FIXED_CONVERSIONS fixedToFloat_arrL( q_env_fx, q_env, Q6, NUM_ENV_CNG ); - fixedToFloat_arr( exc_fx, exc, Q_new, st->L_frame ); - fixedToFloat_arr( exc2_fx, exc2, Q_new, st->L_frame ); - fixedToFloat_arr( exc3_fx, exc3, Q_new, st->L_frame ); - fixedToFloat_arr( bwe_exc_fx, bwe_exc, Q_new, st->L_frame ); - fixedToFloat_arr( st->hTdCngEnc->exc_mem_fx, st->hTdCngEnc->exc_mem, Q_new, 24 ); - fixedToFloat_arr( st->hTdCngEnc->exc_mem1_fx, st->hTdCngEnc->exc_mem1, Q_new, 30 ); + fixedToFloat_arr( exc_fx, exc, Q_new - 1, st->L_frame ); + fixedToFloat_arr( exc2_fx, exc2, Q_new - 1, st->L_frame ); + fixedToFloat_arr( exc3_fx, exc3, Q_new - 1, st->L_frame ); + fixedToFloat_arr( bwe_exc_fx, bwe_exc, Q_new - 1, st->L_frame ); + fixedToFloat_arr( st->hTdCngEnc->exc_mem_fx, st->hTdCngEnc->exc_mem, Q_new - 1, 24 ); + fixedToFloat_arr( st->hTdCngEnc->exc_mem1_fx, st->hTdCngEnc->exc_mem1, Q_new - 1, 30 ); #endif } else @@ -627,24 +627,23 @@ ivas_error acelp_core_enc( } #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - Word16 Q_syn_l, Q_exc_l; + Word16 Q_exc_l; Q_exc_l = Q_factor_arr( exc3, st->L_frame ); floatToFixed_arr( exc3, exc3_fx, Q_exc_l, st->L_frame ); - Q_syn_l = Q_factor_arr( hLPDmem->mem_syn3_flt, M ); - floatToFixed_arr( hLPDmem->mem_syn3_flt, hLPDmem->mem_syn3, Q_syn_l, M ); + floatToFixed_arr( hLPDmem->mem_syn3_flt, hLPDmem->mem_syn3, st->Q_syn, M ); floatToFixed_arr( Aq, Aq_fx, Q12, NB_SUBFR16k * ( M + 1 ) ); #endif /* synthesis at 12.8kHz sampling rate */ - syn_12k8_fx( st->L_frame, Aq_fx, exc3_fx, syn1_fx, hLPDmem->mem_syn3, 1, Q_exc_l, Q_syn_l ); + syn_12k8_fx( st->L_frame, Aq_fx, exc3_fx, syn1_fx, hLPDmem->mem_syn3, 1, Q_exc_l, st->Q_syn ); #ifdef IVAS_FLOAT_FIXED_CONVERSIONS fixedToFloat_arr( Aq_fx, Aq, Q12, NB_SUBFR16k * ( M + 1 ) ); fixedToFloat_arr( exc3_fx, exc, Q_exc_l, st->L_frame ); - fixedToFloat_arr( hLPDmem->mem_syn3, hLPDmem->mem_syn3_flt, Q_syn_l, M ); - fixedToFloat_arr( syn1_fx, syn1, Q_syn_l, st->L_frame ); + fixedToFloat_arr( hLPDmem->mem_syn3, hLPDmem->mem_syn3_flt, st->Q_syn, M ); + fixedToFloat_arr( syn1_fx, syn1, st->Q_syn, st->L_frame ); #endif /* reset the encoder */ @@ -667,44 +666,33 @@ ivas_error acelp_core_enc( { #ifdef IVAS_FLOAT_FIXED_CONVERSIONS Word16 old_syn_12k8_16k_fx[L_FRAME16k]; - Word16 Q_syn1_l = Q_factor_arr( syn1, st->L_frame ); - Word16 Q_old_syn_l = Q_factor_arr( st->hBWE_FD->old_syn_12k8_16k, NS2SA( 16000, DELAY_FD_BWE_ENC_NS ) ); - Q_syn1_l = min( Q_syn1_l, Q_old_syn_l ); - Word16 Q_deemph_l = Q_factor( st->hBWE_FD->mem_deemph_old_syn ); - Q_syn1_l = min( Q_syn1_l, Q_deemph_l ); - // Q_syn1_l = sub( Q_syn1_l, 1 ); - st->hBWE_FD->mem_deemph_old_syn_fx = float_to_fix16_thrld( st->hBWE_FD->mem_deemph_old_syn, Q_syn1_l ); - floatToFixed_arr( syn1, syn1_fx, Q_syn1_l, st->L_frame ); - floatToFixed_arr( st->hBWE_FD->old_syn_12k8_16k, st->hBWE_FD->old_syn_12k8_16k_fx, Q_syn1_l, NS2SA( 16000, DELAY_FD_BWE_ENC_NS ) ); + st->hBWE_FD->mem_deemph_old_syn_fx = float_to_fix16_thrld( st->hBWE_FD->mem_deemph_old_syn, st->Q_syn ); + floatToFixed_arr( syn1, syn1_fx, st->Q_syn, st->L_frame ); + floatToFixed_arr( st->hBWE_FD->old_syn_12k8_16k, st->hBWE_FD->old_syn_12k8_16k_fx, st->Q_syn, NS2SA( 16000, DELAY_FD_BWE_ENC_NS ) ); st->preemph_fac = float_to_fix16( st->preemph_fac_flt, Q15 ); #endif // save_old_syn( st->L_frame, syn1, old_syn_12k8_16k, st->hBWE_FD->old_syn_12k8_16k, st->preemph_fac_flt, &st->hBWE_FD->mem_deemph_old_syn ); save_old_syn_fx( st->L_frame, syn1_fx, old_syn_12k8_16k_fx, st->hBWE_FD->old_syn_12k8_16k_fx, st->preemph_fac, &st->hBWE_FD->mem_deemph_old_syn_fx ); #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - fixedToFloat_arr( syn1_fx, syn1, Q_syn1_l, st->L_frame ); - fixedToFloat_arr( old_syn_12k8_16k_fx, old_syn_12k8_16k, Q_syn1_l, st->L_frame ); - st->hBWE_FD->mem_deemph_old_syn = fix16_to_float( st->hBWE_FD->mem_deemph_old_syn_fx, Q_syn1_l ); - fixedToFloat_arr( st->hBWE_FD->old_syn_12k8_16k_fx, st->hBWE_FD->old_syn_12k8_16k, Q_syn1_l, NS2SA( 16000, DELAY_FD_BWE_ENC_NS ) ); + fixedToFloat_arr( syn1_fx, syn1, st->Q_syn, st->L_frame ); + fixedToFloat_arr( old_syn_12k8_16k_fx, old_syn_12k8_16k, st->Q_syn, st->L_frame ); + st->hBWE_FD->mem_deemph_old_syn = fix16_to_float( st->hBWE_FD->mem_deemph_old_syn_fx, st->Q_syn ); + fixedToFloat_arr( st->hBWE_FD->old_syn_12k8_16k_fx, st->hBWE_FD->old_syn_12k8_16k, st->Q_syn, NS2SA( 16000, DELAY_FD_BWE_ENC_NS ) ); st->preemph_fac_flt = fix16_to_float( st->preemph_fac, Q15 ); #endif } #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - Word16 /* Q_syn_l, */ Q_lpd_syn_l; - Q_syn_l = Q_factor_arr( syn1, st->L_frame ); - Q_lpd_syn_l = Q_factor_arr( hLPDmem->syn_flt, ( M + 1 ) ); - Q_syn_l = min( Q_syn_l, Q_lpd_syn_l ); - - floatToFixed_arr( syn1, syn1_fx, Q_syn_l, st->L_frame ); - floatToFixed_arr( hLPDmem->syn_flt, hLPDmem->syn, Q_syn_l, ( M + 1 ) ); + floatToFixed_arr( syn1, syn1_fx, st->Q_syn, st->L_frame ); + floatToFixed_arr( hLPDmem->syn_flt, hLPDmem->syn, st->Q_syn, ( M + 1 ) ); st->preemph_fac = float_to_fix16( st->preemph_fac_flt, Q15 ); #endif /*Update MODE2 core switching memory*/ // deemph( syn1, st->preemph_fac_flt, st->L_frame, &( hLPDmem->syn_flt[M] ) ); deemph_fx( syn1_fx, st->preemph_fac, st->L_frame, &( hLPDmem->syn[M] ) ); #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - fixedToFloat_arr( syn1_fx, syn1, Q_syn_l, st->L_frame ); - fixedToFloat_arr( hLPDmem->syn, hLPDmem->syn_flt, Q_syn_l, ( M + 1 ) ); + fixedToFloat_arr( syn1_fx, syn1, st->Q_syn, st->L_frame ); + fixedToFloat_arr( hLPDmem->syn, hLPDmem->syn_flt, st->Q_syn, ( M + 1 ) ); #endif mvr2r( syn1 + st->L_frame - M - 1, hLPDmem->syn_flt, M + 1 ); } @@ -729,13 +717,13 @@ ivas_error acelp_core_enc( IF( st->hLPDmem ) { st->hLPDmem->tilt_code = float_to_fix16( st->hLPDmem->tilt_code_flt, Q15 ); - f2me_buf_16( &st->hLPDmem->mem_syn_flt[-1], &st->hLPDmem->mem_syn[-1], &st->hLPDmem->e_mem_syn, M + 1 ); // -1 to sync the exponent of mem_syn with mem_w0 + floatToFixed_arr( &st->hLPDmem->mem_syn_flt[-1], &st->hLPDmem->mem_syn[-1], Q_new - 1, M + 1 ); // -1 to sync the exponent of mem_syn with mem_w0 } floatToFixed_arr( lsp_new, lsp_new_fx, Q15, M ); floatToFixed_arr( lsp_mid, lsp_mid_fx, Q15, M ); st->clip_var_fx[0] = (Word16) ( st->clip_var[0] * 2.56f ); st->clip_var_fx[1] = float_to_fix16( st->clip_var[1], Q14 ); - st->clip_var_fx[2] = float_to_fix16( st->clip_var[2], Q7 ); + st->clip_var_fx[2] = float_to_fix16( st->clip_var[2], Q8 ); st->clip_var_fx[3] = float_to_fix16( st->clip_var[3], 0 ); st->clip_var_fx[4] = float_to_fix16( st->clip_var[4], Q14 ); st->clip_var_fx[5] = float_to_fix16( st->clip_var[5], Q14 ); @@ -744,14 +732,14 @@ ivas_error acelp_core_enc( IF( tdm_lsfQ_PCh ) tdm_lsfQ_PCh_fx[idx] = (Word16) ( tdm_lsfQ_PCh[idx] * 2.56f ); } - Q_old_bwe_exc = Q_factor_arr( old_bwe_exc, 1380 ); - floatToFixed_arr( old_bwe_exc, old_bwe_exc_fx, Q_old_bwe_exc, 1380 ); - Q_exc = Q_factor_arr( old_exc_flt, st->L_frame ); + // Q_old_bwe_exc = Q_factor_arr( old_bwe_exc, 1380 ); + floatToFixed_arr( old_bwe_exc, old_bwe_exc_fx, Q_new, 1380 ); + /*Q_exc = Q_factor_arr( old_exc_flt, st->L_frame ); hLPDmem->e_old_exc = Q_factor_arr( &hLPDmem->old_exc_flt[-M - 1], L_EXC_MEM + M + 1 ) - 1; - Q_exc = s_min( Q_exc, hLPDmem->e_old_exc ); - hLPDmem->e_old_exc = Q15 - Q_exc; - floatToFixed_arr( &hLPDmem->old_exc_flt[-M - 1], &hLPDmem->old_exc[-M - 1], Q15 - hLPDmem->e_old_exc, L_EXC_MEM + M + 1 ); - floatToFixed_arr16( old_exc_flt, old_exc_fx, Q_exc, st->L_frame ); + Q_exc = min(s_min( Q_exc, hLPDmem->e_old_exc ), Q_new); + hLPDmem->e_old_exc = Q15 - Q_exc;*/ + floatToFixed_arr( &hLPDmem->old_exc_flt[-M - 1], &hLPDmem->old_exc[-M - 1], Q_new, L_EXC_MEM + M + 1 ); + floatToFixed_arr( old_exc_flt, old_exc_fx, Q_new, st->L_frame ); st->preemph_fac = float_to_fix16( st->preemph_fac_flt, Q15 ); floatToFixed_arr( st->voicing, st->voicing_fx, Q15, 3 ); @@ -874,8 +862,9 @@ ivas_error acelp_core_enc( /* Prepare ACB memory from last HQ frame */ tmpF_fx = hLPDmem->old_exc[0]; PREEMPH_FX( hLPDmem->old_exc, st->preemph_fac, st->L_frame, &tmpF_fx ); - hLPDmem->e_mem_syn = hLPDmem->e_old_exc; + // hLPDmem->e_mem_syn = hLPDmem->e_old_exc; Copy( hLPDmem->old_exc + sub( st->L_frame, M ), hLPDmem->mem_syn, M ); + // Copy_Scale_sig( hLPDmem->old_exc + sub( st->L_frame, M ), hLPDmem->mem_syn, M, sub( Q_new, st->prev_Q_new ) ); Residu3_fx( Aq_fx, hLPDmem->old_exc, old_exc_fx, st->L_frame, 0 ); } @@ -891,7 +880,7 @@ ivas_error acelp_core_enc( { lerp( old_exc_fx, old_bwe_exc_fx, L_EXC_MEM_DEC * 2, L_EXC_MEM_DEC ); } - Q_old_bwe_exc = Q_exc; + // Q_old_bwe_exc = Q_exc; move16(); } @@ -913,7 +902,7 @@ ivas_error acelp_core_enc( IF( EQ_16( st->coder_type, TRANSITION ) ) { - tc_classif_enc_fx( Q_new + 1, st->L_frame, &tc_subfr, &position, attack_flag, st->pitch[0], res_fx ); + tc_classif_enc_fx( Q_new, st->L_frame, &tc_subfr, &position, attack_flag, st->pitch[0], res_fx ); config_acelp1_IVAS( ENC, st->total_brate, st->core_brate, st->core, st->extl, st->extl_brate, st->L_frame, -1, &( st->acelp_cfg ), hBstr->nb_bits_tot, st->coder_type, tc_subfr, 1, NULL, unbits, st->element_mode, &uc_two_stage_flag, tdm_lp_reuse_flag, tdm_low_rate_mode, st->idchan, st->active_cnt, tdm_Pitch_reuse_flag, st->tdm_LRTD_flag, st->GSC_IVAS_mode ); } @@ -925,214 +914,138 @@ ivas_error acelp_core_enc( IF( nb_bits > 0 ) { - Es_pred_enc_fx( &Es_pred_fx, &i, st->L_frame, res_fx, st->voicing_fx, nb_bits, uc_two_stage_flag, Q_new + 1 ); + Es_pred_enc_fx( &Es_pred_fx, &i, st->L_frame, res_fx, st->voicing_fx, nb_bits, uc_two_stage_flag, Q_new ); push_indice( hBstr, IND_ES_PRED, i, nb_bits ); } /*------------------------------------------------------------* * Encode excitation according to coding type *------------------------------------------------------------*/ - Word16 Q_exc2 = add( Q_new, 1 ); +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + Word16 shift; + shift = 0; + move16(); +#endif + test(); + test(); IF( tdm_low_rate_mode ) /* tdm stereo low rate mode */ { IF( LE_16( st->coder_type, UNVOICED ) ) { - tdm_low_rate_enc( st, Aq_fx, res_fx, syn_fx, exc_fx, pitch_buf_fx, voice_factors_fx, bwe_exc_fx, 0 /*attack_flag*/, lsf_new_fx, &tmp_noise_fx, &Q_exc2 ); + tdm_low_rate_enc( st, Aq_fx, res_fx, syn_fx, exc_fx, pitch_buf_fx, voice_factors_fx, bwe_exc_fx, 0 /*attack_flag*/, lsf_new_fx, &tmp_noise_fx, Q_new ); } ELSE /* GENERIC */ { - encod_gen_2sbfr( st, inp_fx, Aw_fx, Aq_fx, res_fx, syn_fx, exc_fx, exc2_fx, pitch_buf_fx, voice_factors_fx, bwe_exc_fx, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf_fx, &Q_exc2 ); + encod_gen_2sbfr( st, inp_fx, Aw_fx, Aq_fx, res_fx, syn_fx, exc_fx, exc2_fx, pitch_buf_fx, voice_factors_fx, bwe_exc_fx, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf_fx, Q_new ); } } ELSE IF( nelp_mode ) { /* SC-VBR - NELP frames */ - encod_nelp_ivas_fx( st, inp_fx, Aw_fx, Aq_fx, res_fx, syn_fx, &tmp_noise_fx, exc_fx, exc2_fx, pitch_buf_fx, voice_factors_fx, bwe_exc_fx, Q_new, 0 ); - } -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - st->mem_deemp_preQ = fixedToFloat( st->mem_deemp_preQ_fx, -1 ); - - st->clip_var[0] = (float) st->clip_var_fx[0] / 2.56f; - st->clip_var[1] = fix16_to_float( st->clip_var_fx[1], Q14 ); - st->clip_var[2] = fix16_to_float( st->clip_var_fx[2], Q7 ); - st->clip_var[3] = fix16_to_float( st->clip_var_fx[3], 0 ); - st->clip_var[4] = fix16_to_float( st->clip_var_fx[4], Q14 ); - st->clip_var[5] = fix16_to_float( st->clip_var_fx[5], Q14 ); - - for ( int ii = 0; ii < M; ii++ ) - { - mem_AR[ii] = (float) mem_AR_fx[ii] / 2.56f; - mem_MA[ii] = (float) mem_MA_fx[ii] / 2.56f; - } - fixedToFloat_arr( lsp_new_bck_fx, lsp_new_bck, Q15, M ); - fixedToFloat_arr( lsp_mid_bck_fx, lsp_mid_bck, Q15, M ); - me2f_buf_16( mem_syn_bck_fx, st->hLPDmem->e_mem_syn, mem_syn_bck, M ); - fixedToFloat_arr( lsp_new_fx, lsp_new, 15, M ); - fixedToFloat_arr( lsp_mid_fx, lsp_mid, 15, M ); - for ( i = 0; i < M; i++ ) - { - - lsf_new[i] = lsf_new_fx[i] / 2.56f; - } - fixedToFloat_arrL( st->Bin_E_old_fx, st->Bin_E_old, q_comm_Bin, 128 ); - fixedToFloat_arrL( st->Bin_E_fx, st->Bin_E, q_comm_Bin, 256 ); - st->clip_var[0] = st->clip_var_fx[0] / 2.56f; - fixedToFloat_arr( &st->clip_var_fx[1], &st->clip_var[1], Q14, 5 ); - for ( i = 0; i < NB_SUBFR16k; i++ ) - { - // Array is getting modified in chunks of 17 inside. - // So each chunk might have a different Q which is predicted by 1st element. - fixedToFloat_arr( &Aq_fx[i * ( M + 1 )], &Aq[i * ( M + 1 )], 14 - norm_s( Aq_fx[i * ( M + 1 )] ), ( M + 1 ) ); + encod_nelp_ivas_fx( st, inp_fx, Aw_fx, Aq_fx, res_fx, syn_fx, &tmp_noise_fx, exc_fx, exc2_fx, pitch_buf_fx, voice_factors_fx, bwe_exc_fx, Q_new, shift ); } - fixedToFloat_arr( old_exc_fx, old_exc_flt, Q15 - hLPDmem->e_old_exc, st->L_frame ); - me2f_buf_16( &hLPDmem->old_exc[-M - 1], hLPDmem->e_old_exc, &hLPDmem->old_exc_flt[-M - 1], L_EXC_MEM + M + 1 ); - fixedToFloat_arr( old_bwe_exc_fx, old_bwe_exc, Q_old_bwe_exc, 1380 ); - fixedToFloat_arr( res_fx, res, Q_new + 1, st->L_frame ); - Es_pred = fix16_to_float( Es_pred_fx, Q8 ); - - me2f_buf_16( &st->hLPDmem->mem_w0, st->hLPDmem->e_mem_syn, &st->hLPDmem->mem_w0_flt, M + 1 ); - fixedToFloat_arr( exc_fx, exc, Q_exc, L_FRAME ); - fixedToFloat_arr( exc2_fx, exc2, Q_exc, L_FRAME16k ); - if ( st->hBWE_TD ) - fixedToFloat_arr( bwe_exc_fx, bwe_exc, Q_exc, L_FRAME32k ); - st->hGSCEnc->Last_frame_ener = fixedToFloat_32( st->hGSCEnc->Last_frame_ener_fx, Q4 ); - me2f_buf_16( st->hGSCEnc->last_exc_dct_in_fx, Q15 - st->hGSCEnc->Q_last_exc_dct_in, st->hGSCEnc->last_exc_dct_in, L_FRAME16k ); - fixedToFloat_arr( syn_fx, syn, Q_exc2, L_FRAME16k ); - fixedToFloat_arr( voice_factors_fx, voice_factors, Q15, NB_SUBFR16k ); - fixedToFloat_arr( pitch_buf_fx, pitch_buf, Q6, NB_SUBFR ); - tmp_noise = fix16_to_float( tmp_noise_fx, Q8 ); - IF( st->hLPDmem ) - st->hLPDmem->tilt_code_flt = fix16_to_float( st->hLPDmem->tilt_code, Q15 ); #endif -#endif - if ( tdm_low_rate_mode ) /* tdm stereo low rate mode */ - { - } - else if ( nelp_mode ) - { - } - else if ( st->coder_type == UNVOICED ) + ELSE IF( EQ_16( st->coder_type, UNVOICED ) ) { /* UNVOICED frames (Gauss. excitation) */ - encod_unvoiced( st, inp, Aw, Aq, Es_pred, uc_two_stage_flag, res, syn, &tmp_noise, exc, pitch_buf, voice_factors, bwe_exc ); + // encod_unvoiced( st, inp, Aw, Aq, Es_pred, uc_two_stage_flag, res, syn, &tmp_noise, exc, pitch_buf, voice_factors, bwe_exc ); + encod_unvoiced_ivas_fx( st, inp_fx, Aw_fx, Aq_fx, Es_pred_fx, uc_two_stage_flag, res_fx, syn_fx, &tmp_noise_fx, exc_fx, pitch_buf_fx, voice_factors_fx, bwe_exc_fx, Q_new, shift ); } - else if ( st->coder_type == TRANSITION ) + ELSE IF( EQ_16( st->coder_type, TRANSITION ) ) { - encod_tran( st, inp, Aw, Aq, Es_pred, res, syn, exc, exc2, pitch_buf, voice_factors, bwe_exc, tc_subfr, position, unbits ); + // encod_tran( st, inp, Aw, Aq, Es_pred, res, syn, exc, exc2, pitch_buf, voice_factors, bwe_exc, tc_subfr, position, unbits ); + encod_tran_ivas_fx( st, inp_fx, Aw_fx, Aq_fx, Es_pred_fx, res_fx, syn_fx, exc_fx, exc2_fx, pitch_buf_fx, voice_factors_fx, bwe_exc_fx, tc_subfr, position, unbits, shift, Q_new ); } - else if ( ppp_mode ) + ELSE IF( ppp_mode ) { /* SC-VBR - PPP frames */ -#ifdef IVAS_FLOAT_FIXED -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - Word16 shift; - shift = 0; - move16(); -#endif IF( ( error = encod_ppp_fx( st, inp_fx, Aw_fx, Aq_fx, res_fx, syn_fx, exc_fx, exc2_fx, pitch_buf_fx, voice_factors_fx, bwe_exc_fx, Q_new, shift ) ) != IVAS_ERR_OK ) { return error; } -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - for ( i = 0; i < NB_SUBFR16k; i++ ) - { - // Array is getting modified in chunks of 17 inside. - // So each chunk might have a different Q which is predicted by 1st element. - fixedToFloat_arr( &Aq_fx[i * ( M + 1 )], &Aq[i * ( M + 1 )], 14 - norm_s( Aq_fx[i * ( M + 1 )] ), ( M + 1 ) ); - } - fixedToFloat_arr( res_fx, res, Q_new + 1, st->L_frame ); - fixedToFloat_arr( syn_fx, syn, Q_exc2, L_FRAME16k ); - fixedToFloat_arr( exc_fx, exc, Q_exc, L_FRAME ); - fixedToFloat_arr( exc2_fx, exc2, Q_exc, L_FRAME16k ); - fixedToFloat_arr( pitch_buf_fx, pitch_buf, Q6, NB_SUBFR ); - fixedToFloat_arr( voice_factors_fx, voice_factors, Q15, NB_SUBFR16k ); - if ( st->hBWE_TD ) - { - fixedToFloat_arr( bwe_exc_fx, bwe_exc, Q_exc, L_FRAME32k ); - } -#endif -#else - if ( ( error = encod_ppp( st, inp, Aw, Aq, res, syn, exc, exc2, pitch_buf, voice_factors, bwe_exc ) ) != IVAS_ERR_OK ) - { - return error; - } -#endif - if ( st->hSC_VBR->bump_up ) /* PPP failed, bump up */ + IF( st->hSC_VBR->bump_up ) /* PPP failed, bump up */ { /* restore memories of LSF quantizer and synthesis filter */ -#ifdef IVAS_FLOAT_FIXED -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - floatToFixed_arr( lsp_new_bck, lsp_new_bck_fx, Q15, M ); - floatToFixed_arr( lsp_mid_bck, lsp_mid_bck_fx, Q15, M ); - q_comm_Bin = s_min( Q_factor_arrL( st->Bin_E_old, L_FFT / 2 ), Q_factor_arrL( st->Bin_E, L_FFT ) ); - floatToFixed_arrL( Bin_E, Bin_E_fx, q_comm_Bin, L_FFT ); - floatToFixed_arrL( Bin_E_old, Bin_E_old_fx, q_comm_Bin, L_FFT / 2 ); - Word16 mem_syn = Q_factor_arr( mem_syn_bck, M ); - floatToFixed_arr( mem_syn_bck, mem_syn_bck_fx, mem_syn, M ); - for ( i = 0; i < M; i++ ) - { - mem_AR_fx[i] = (Word16) ( mem_AR[i] * 2.56f ); - mem_MA_fx[i] = (Word16) ( mem_MA[i] * 2.56f ); - } -#endif lsf_syn_mem_restore_ivas_fx( st, tilt_code_bck_fx, gc_threshold_bck_fx, clip_var_bck_fx, next_force_sf_bck, lsp_new_fx, lsp_mid_fx, clip_var_fx, mem_AR_fx, mem_MA_fx, lsp_new_bck_fx, lsp_mid_bck_fx, Bin_E_fx, Bin_E_old_fx, mem_syn_bck_fx, mem_w0_bck_fx, streaklimit_fx, pstreaklen ); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - st->hLPDmem->tilt_code_flt = fix16_to_float( st->hLPDmem->tilt_code, Q15 ); - st->clip_var[0] = st->clip_var_fx[0] / 2.56f; - st->clip_var[1] = fix16_to_float( st->clip_var_fx[1], Q14 ); - st->clip_var[2] = fix16_to_float( st->clip_var_fx[2], Q7 ); - st->clip_var[3] = fix16_to_float( st->clip_var_fx[3], 0 ); - st->clip_var[4] = fix16_to_float( st->clip_var_fx[4], Q14 ); - st->clip_var[5] = fix16_to_float( st->clip_var_fx[5], Q14 ); - fixedToFloat_arr( lsp_new_fx, lsp_new, Q15, M ); - fixedToFloat_arr( lsp_mid_fx, lsp_mid, Q15, M ); - fixedToFloat_arrL( st->Bin_E_fx, st->Bin_E, q_comm_Bin, L_FFT ); - fixedToFloat_arrL( st->Bin_E_old_fx, st->Bin_E_old, q_comm_Bin, L_FFT / 2 ); - fixedToFloat_arr( st->hLPDmem->mem_syn, st->hLPDmem->mem_syn_flt, mem_syn, M ); - st->hLPDmem->mem_w0_flt = me2f( st->hLPDmem->mem_w0, st->hLPDmem->e_mem_syn ); -#endif -#else - lsf_syn_mem_restore( st, tilt_code_bck, gc_threshold_bck, clip_var_bck, next_force_sf_bck, lsp_new, lsp_mid, clip_var, mem_AR, mem_MA, lsp_new_bck, lsp_mid_bck, Bin_E, Bin_E_old, mem_syn_bck, mem_w0_bck, streaklimit, pstreaklen ); -#endif /* Configure ACELP bit allocation */ config_acelp1_IVAS( ENC, st->total_brate, st->core_brate, st->core, st->extl, st->extl_brate, st->L_frame, -1, &( st->acelp_cfg ), hBstr->nb_bits_tot, st->coder_type, tc_subfr, 0, &nb_bits, unbits, 0, &uc_two_stage_flag, 0, 0, st->idchan, st->active_cnt, tdm_Pitch_reuse_flag, st->tdm_LRTD_flag, st->GSC_IVAS_mode ); /* redo LSF quantization */ -#ifdef IVAS_FLOAT_FIXED lsf_enc_ivas_fx( st, lsf_new_fx, lsp_new_fx, lsp_mid_fx, Aq_fx, tdm_low_rate_mode, 0, NULL, Q_new ); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - for ( i = 0; i < M; i++ ) - { - - lsf_new[i] = lsf_new_fx[i] / 2.56f; - } - fixedToFloat_arr( Aq_fx, Aq, 12, NB_SUBFR16k * ( M + 1 ) ); - fixedToFloat_arr( lsp_mid_fx, lsp_mid, Q15, M ); -#endif -#else - lsf_enc( st, lsf_new, lsp_new, lsp_mid, Aq, tdm_low_rate_mode, 0, NULL ); -#endif /* recalculation of LP residual (filtering through A[z] filter) */ - calc_residu( inp, res, Aq, st->L_frame ); + // calc_residu( inp, res, Aq, st->L_frame ); + calc_residu_fx( st, inp_fx, res_fx, Aq_fx ); st->hTdCngEnc->burst_ho_cnt = 0; /* VOICED frames in SC-VBR */ - encod_gen_voic( st, inp, Aw, Aq, Es_pred, res, syn, exc, exc2, pitch_buf, voice_factors, bwe_exc, unbits, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf ); + // encod_gen_voic( st, inp, Aw, Aq, Es_pred, res, syn, exc, exc2, pitch_buf, voice_factors, bwe_exc, unbits, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf ); + encod_gen_voic_ivas_fx( st, inp_fx, Aw_fx, Aq_fx, Es_pred_fx, res_fx, syn_fx, exc_fx, exc2_fx, pitch_buf_fx, voice_factors_fx, bwe_exc_fx, unbits, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf_fx, shift, Q_new ); } } - else if ( st->coder_type == AUDIO || ( st->coder_type == INACTIVE && st->inactive_coder_type_flag ) ) + ELSE IF( EQ_16( st->coder_type, AUDIO ) || ( EQ_16( st->coder_type, INACTIVE ) && st->inactive_coder_type_flag ) ) { /* AUDIO and INACTIVE frames (coded by GSC technology) */ - encod_audio( st, inp, Aw, Aq, res, syn, exc, pitch_buf, voice_factors, bwe_exc, attack_flag, lsf_new, &tmp_noise, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf ); + // encod_audio( st, inp, Aw, Aq, res, syn, exc, pitch_buf, voice_factors, bwe_exc, attack_flag, lsf_new, &tmp_noise, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf ); + encod_audio_ivas_fx( st, inp_fx, Aw_fx, Aq_fx, res_fx, syn_fx, exc_fx, pitch_buf_fx, voice_factors_fx, bwe_exc_fx, attack_flag, lsf_new_fx, &tmp_noise_fx, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf_fx, Q_new, shift ); } - else + ELSE { /* GENERIC, VOICED and INACTIVE frames (coded by AVQ technology) */ - encod_gen_voic( st, inp, Aw, Aq, Es_pred, res, syn, exc, exc2, pitch_buf, voice_factors, bwe_exc, unbits, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf ); + // encod_gen_voic( st, inp, Aw, Aq, Es_pred, res, syn, exc, exc2, pitch_buf, voice_factors, bwe_exc, unbits, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf ); + + encod_gen_voic_ivas_fx( st, inp_fx, Aw_fx, Aq_fx, Es_pred_fx, res_fx, syn_fx, exc_fx, exc2_fx, pitch_buf_fx, voice_factors_fx, bwe_exc_fx, unbits, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf_fx, shift, Q_new ); } +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + st->mem_deemp_preQ = fixedToFloat( st->mem_deemp_preQ_fx, -1 ); + + st->clip_var[0] = (float) st->clip_var_fx[0] / 2.56f; + st->clip_var[1] = fix16_to_float( st->clip_var_fx[1], Q14 ); + st->clip_var[2] = fix16_to_float( st->clip_var_fx[2], Q8 ); + st->clip_var[3] = fix16_to_float( st->clip_var_fx[3], 0 ); + st->clip_var[4] = fix16_to_float( st->clip_var_fx[4], Q14 ); + st->clip_var[5] = fix16_to_float( st->clip_var_fx[5], Q14 ); + + fixedToFloat_arr( lsp_new_bck_fx, lsp_new_bck, Q15, M ); + fixedToFloat_arr( lsp_mid_bck_fx, lsp_mid_bck, Q15, M ); + fixedToFloat_arr( mem_syn_bck_fx, mem_syn_bck, Q_new, M ); + fixedToFloat_arr( lsp_new_fx, lsp_new, 15, M ); + fixedToFloat_arr( lsp_mid_fx, lsp_mid, 15, M ); + for ( i = 0; i < M; i++ ) + { + + lsf_new[i] = lsf_new_fx[i] / 2.56f; + } + fixedToFloat_arrL( st->Bin_E_old_fx, st->Bin_E_old, q_comm_Bin, 128 ); + fixedToFloat_arrL( st->Bin_E_fx, st->Bin_E, q_comm_Bin, 256 ); + for ( i = 0; i < NB_SUBFR16k; i++ ) + { + // Array is getting modified in chunks of 17 inside. + // So each chunk might have a different Q which is predicted by 1st element. + fixedToFloat_arr( &Aq_fx[i * ( M + 1 )], &Aq[i * ( M + 1 )], 14 - norm_s( Aq_fx[i * ( M + 1 )] ), ( M + 1 ) ); + } + fixedToFloat_arr( old_exc_fx, old_exc_flt, Q_new, st->L_frame ); + // me2f_buf_16(&hLPDmem->old_exc[-M - 1], hLPDmem->e_old_exc, &hLPDmem->old_exc_flt[-M - 1], L_EXC_MEM + M + 1); + fixedToFloat_arr( &hLPDmem->old_exc[-M - 1], &hLPDmem->old_exc_flt[-M - 1], Q_new, L_EXC_MEM + M + 1 ); + fixedToFloat_arr( old_bwe_exc_fx, old_bwe_exc, Q_new, 1380 ); + fixedToFloat_arr( res_fx, res, Q_new, st->L_frame ); + Es_pred = fix16_to_float( Es_pred_fx, Q8 ); + + fixedToFloat_arr( st->hLPDmem->mem_syn, st->hLPDmem->mem_syn_flt, Q_new - 1, M ); + st->hLPDmem->mem_w0_flt = fixedToFloat( st->hLPDmem->mem_w0, Q_new - 1 ); + fixedToFloat_arr( exc_fx, exc, Q_new, L_FRAME16k + 1 ); + fixedToFloat_arr( exc2_fx, exc2, Q_new, L_FRAME16k ); + if ( st->hBWE_TD ) + fixedToFloat_arr( bwe_exc_fx, bwe_exc, Q_new, L_FRAME32k ); + st->hGSCEnc->Last_frame_ener = fixedToFloat_32( st->hGSCEnc->Last_frame_ener_fx, Q4 ); + me2f_buf_16( st->hGSCEnc->last_exc_dct_in_fx, Q15 - st->hGSCEnc->Q_last_exc_dct_in, st->hGSCEnc->last_exc_dct_in, L_FRAME16k ); + fixedToFloat_arr( syn_fx, syn, Q_new - 1, L_FRAME16k ); + fixedToFloat_arr( voice_factors_fx, voice_factors, Q15, NB_SUBFR16k ); + fixedToFloat_arr( pitch_buf_fx, pitch_buf, Q6, NB_SUBFR16k ); + st->hLPDmem->tilt_code_flt = fix16_to_float( st->hLPDmem->tilt_code, Q15 ); +#endif /* update mem_syn1_flt for ACELP core switching */ mvr2r( hLPDmem->mem_syn_flt, hLPDmem->mem_syn1_flt, M ); @@ -1170,21 +1083,16 @@ ivas_error acelp_core_enc( /*Update MODE2 core switching memory*/ mvr2r( syn, syn1, st->L_frame ); #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - Word16 Q_syn_l, Q_lpd_syn_l; - Q_syn_l = Q_factor_arr( syn1, st->L_frame ); - Q_lpd_syn_l = Q_factor_arr( hLPDmem->syn_flt, ( M + 1 ) ); - Q_syn_l = min( Q_syn_l, Q_lpd_syn_l ); - - floatToFixed_arr( syn1, syn1_fx, Q_syn_l, st->L_frame ); - floatToFixed_arr( hLPDmem->syn_flt, hLPDmem->syn, Q_syn_l, ( M + 1 ) ); + floatToFixed_arr( syn1, syn1_fx, st->Q_syn, st->L_frame ); + floatToFixed_arr( hLPDmem->syn_flt, hLPDmem->syn, st->Q_syn, ( M + 1 ) ); st->preemph_fac = float_to_fix16( st->preemph_fac_flt, Q15 ); #endif /*Update MODE2 core switching memory*/ deemph_fx( syn1_fx, st->preemph_fac, st->L_frame, &( hLPDmem->syn[M] ) ); // deemph( syn1, st->preemph_fac_flt, st->L_frame, &( hLPDmem->syn_flt[M] ) ); #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - fixedToFloat_arr( syn1_fx, syn1, Q_syn_l, st->L_frame ); - fixedToFloat_arr( hLPDmem->syn, hLPDmem->syn_flt, Q_syn_l, ( M + 1 ) ); + fixedToFloat_arr( syn1_fx, syn1, st->Q_syn, st->L_frame ); + fixedToFloat_arr( hLPDmem->syn, hLPDmem->syn_flt, st->Q_syn, ( M + 1 ) ); #endif mvr2r( syn1 + st->L_frame - M - 1, hLPDmem->syn_flt, M + 1 ); @@ -1206,7 +1114,7 @@ ivas_error acelp_core_enc( #else #ifdef IVAS_FLOAT_FIXED_CONVERSIONS // conv params from float to fix - Q_exc2 = Q_factor_arr( exc2, L_FRAME ); + Word16 Q_exc2 = Q_factor_arr( exc2, L_FRAME ); #ifndef MSAN_FIX floatToFixed_arr( exc2, exc2_fx, Q_exc2, L_FRAME16k ); #else @@ -1362,9 +1270,7 @@ ivas_error acelp_core_enc( lsf_new_fx[i] = (Word16) ( lsf_new[i] * 2.56f ); }; - Word16 q_old_exc = Q_factor_arr( old_exc_flt, L_EXC ); - floatToFixed_arr16( old_exc_flt, old_exc_fx, q_old_exc, L_EXC ); - st->hLPDmem->e_old_exc = sub( 15, q_old_exc ); + floatToFixed_arr( old_exc_flt, old_exc_fx, Q_new, L_EXC ); Word16 q_old_bwe_exc = 0; IF( st->hBWE_TD != NULL ) @@ -1383,7 +1289,7 @@ ivas_error acelp_core_enc( updt_enc_fx( st, old_exc_fx, pitch_buf_fx, Es_pred_fx, Aq_fx, lsf_new_fx, lsp_new_fx, old_bwe_exc_fx ); #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - fixedToFloat_arr( st->hLPDmem->old_exc, st->hLPDmem->old_exc_flt, q_old_exc, L_EXC_MEM ); + fixedToFloat_arr( st->hLPDmem->old_exc, st->hLPDmem->old_exc_flt, Q_new, L_EXC_MEM ); IF( !st->Opt_AMR_WB && st->hBWE_TD != NULL ) { fixedToFloat_arr( st->hBWE_TD->old_bwe_exc_fx, st->hBWE_TD->old_bwe_exc, q_old_bwe_exc, PIT16k_MAX * 2 ); @@ -1468,7 +1374,9 @@ ivas_error acelp_core_enc( #endif } } - +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + st->prev_Q_new = Q_new; +#endif pop_wmops(); return error; diff --git a/lib_enc/acelp_enc_util_fx.c b/lib_enc/acelp_enc_util_fx.c index ffdf837c4..f7f1d45b6 100644 --- a/lib_enc/acelp_enc_util_fx.c +++ b/lib_enc/acelp_enc_util_fx.c @@ -197,6 +197,35 @@ void E_ACELP_conv( } } +void E_ACELP_conv_ivas( + const Word16 xn2[], /* i */ + const Word16 h2[], /* i */ + Word16 cn2[] /* o */ +) +{ + Word16 i, k; + Word32 L_tmp; +#ifdef BASOP_NOGLOB_DECLARE_LOCAL + Flag Overflow = 0; +#endif + FOR( k = 0; k < L_SUBFR; k++ ) + { + /*cn2[k] = xn2[k]; */ + Word64 L_tmp_64; + L_tmp_64 = W_deposit32_l( L_mult0( xn2[k], 0x800 ) ); + FOR( i = 0; i < k; i++ ) + { + /*cn2[k]-=cn2[i]*h2[k-i];*/ + L_tmp_64 = W_msu0_16_16( L_tmp_64, cn2[i], h2[k - i] ); /*h2 4Q11*/ + } + L_tmp = W_sat_l( L_tmp_64 ); +#ifdef BASOP_NOGLOB + cn2[k] = round_fx_o( L_shl_o( L_tmp, 5, &Overflow ), &Overflow ); +#else + cn2[k] = round_fx( L_shl( L_tmp, 5 ) ); +#endif + } +} void E_ACELP_build_code( Word16 nb_pulse, /* i */ const Word16 codvec[], /* i */ diff --git a/lib_enc/avq_cod_fx.c b/lib_enc/avq_cod_fx.c index ece84e4e9..c303d9ea5 100644 --- a/lib_enc/avq_cod_fx.c +++ b/lib_enc/avq_cod_fx.c @@ -16,6 +16,7 @@ * Local prototypes *-------------------------------------------------------------------*/ static void wrte_cv( BSTR_ENC_HANDLE hBstr, const Word16 nq, const Word16 i_ind, const Word16 kv_ind, UWord16 I, Word16 kv[], Word16 *bits ); +static void wrte_cv_ivas( BSTR_ENC_HANDLE hBstr, const Word16 nq, const Word16 i_ind, const Word16 kv_ind, UWord16 I, Word16 kv[], Word16 *bits ); /*-------------------------------------------------------------------* * Function AVQ_cod() * @@ -408,7 +409,7 @@ void AVQ_encmux_fx( bits = sub( bits, 1 ); } - wrte_cv( hBstr, nq[k], i_ind, kv_ind, I[k], &kv[shl( k, 3 )], &bits ); + wrte_cv( hBstr, nq[k], i_ind, kv_ind, I[k], &kv[k * 8], &bits ); } } /* for */ /* Bit Saving Solution */ @@ -545,7 +546,7 @@ void AVQ_encmux_fx( move16(); /* write codebook indices (rank I and event. Voronoi index kv) */ - wrte_cv( hBstr, nq[i], i_ind, kv_ind, I[i], &kv[shl( i, 3 )], &bits ); + wrte_cv( hBstr, nq[i], i_ind, kv_ind, I[i], &kv[i * 8], &bits ); bits = sub( bits, dummy_bits ); @@ -566,6 +567,437 @@ void AVQ_encmux_fx( return; } +void AVQ_encmux_ivas_fx( + BSTR_ENC_HANDLE hBstr, /* i/o: bitstream handle */ + const Word16 extl, /* i : extension layer */ + Word16 xriq[], /* i/o: rounded subvectors [0..8*Nsv-1] followed + by rounded bit allocations [8*Nsv..8*Nsv+Nsv-1] */ + Word16 *nb_bits, /* i/o: number of allocated bits */ + const Word16 Nsv, /* i: number of subvectors */ + Word16 nq_out[], /* o : AVQ nq index */ + Word16 avq_bit_sFlag, /* i : flag for AVQ bit saving solution */ + Word16 trgtSvPos /* i : target SV for AVQ bit savings */ +) +{ + Word16 i, j = 0, bits, pos, pos_max, overflow, pos_tmp, bit_tmp; + Word16 sort_idx[NSV_MAX], nq[NSV_MAX], kv[NSV_MAX * 8]; + Word16 *t; + UWord16 I[NSV_MAX]; + Word16 nq_ind, i_ind, kv_ind; + Word16 nq_est, unused_bits, unused_bits_idx; + Word16 bitsMod, Nsvm1, Nsvm2; + Word16 unusedbitsFlag; + Word16 svOrder[NSV_MAX], k, nullVec, dummy_bits; + Word16 tmp; + + test(); + IF( EQ_16( extl, SWB_BWE_HIGHRATE ) || EQ_16( extl, FB_BWE_HIGHRATE ) ) + { + nq_ind = IND_NQ2; + move16(); + i_ind = IND_I2; + move16(); + kv_ind = IND_KV2; + move16(); + } + ELSE + { + nq_ind = IND_NQ; + move16(); + i_ind = IND_I; + move16(); + kv_ind = IND_KV; + move16(); + } + + FOR( i = 0; i < NSV_MAX; i++ ) + { + I[i] = (UWord16) -1; + move16(); + } + unusedbitsFlag = 0; + bitsMod = 0; + move16(); + move16(); + /*----------------------------------------------------------------- + * Encode subvectors and fix possible overflows in total bit budget, + * i.e. find for each subvector a codebook index nq (nq=0,2,3,4,...,NSV_MAX), + * a base codebook index (I), and a Voronoi index (kv) + *-----------------------------------------------------------------*/ + + /* sort subvectors by estimated bit allocations in decreasing order */ + t = kv; + move16(); /* reuse vector to save memory */ + move16(); /*ptr init*/ + FOR( i = 0; i < Nsv; i++ ) + { + t[i] = xriq[8 * Nsv + i]; + move16(); + } + + FOR( i = 0; i < Nsv; i++ ) + { + bits = t[0]; + move16(); + pos = 0; + move16(); + FOR( j = 1; j < Nsv; j++ ) + { + if ( GT_16( t[j], bits ) ) + { + pos = j; + move16(); + } + bits = s_max( t[j], bits ); + } + sort_idx[i] = pos; + move16(); + t[pos] = -1; + move16(); + } + + /* compute multi-rate indices and avoid bit budget overflow */ + pos_max = 0; + move16(); + bits = 0; + move16(); + FOR( i = 0; i < Nsv; i++ ) + { + /* find vector to quantize (criteria: nb of estimated bits) */ + pos = sort_idx[i]; + move16(); + + /* compute multi-rate index of rounded subvector (nq,I,kv[]) */ + re8_cod_fx( &xriq[pos * 8], &nq[pos], &I[pos], &kv[8 * pos] ); + + IF( nq[pos] > 0 ) + { + j = pos_max; + move16(); + j = s_max( pos, j ); + + /* compute (number of bits -1) to describe Q #nq */ + IF( GE_16( nq[pos], 2 ) ) + { + overflow = sub( i_mult2( nq[pos], 5 ), 1 ); + } + ELSE + { + overflow = 0; + move16(); + } + + /* check for overflow and compute number of bits-1 (n) */ + IF( GT_16( add( bits, add( overflow, j ) ), *nb_bits ) ) + { + /* if budget overflow */ + pos_tmp = add( shl( pos, 3 ), 8 ); /*(pos*8)+8*/ + FOR( j = pos * 8; j < pos_tmp; j++ ) + { + xriq[j] = 0; + move16(); + } + nq[pos] = 0; + move16(); /* force Q0 */ + } + ELSE + { + bits = add( bits, overflow ); + pos_max = j; + move16(); /* update index of the last described subvector */ + } + } + } + nullVec = 0; + Nsvm1 = sub( Nsv, 1 ); + Nsvm2 = sub( Nsvm1, 1 ); + dummy_bits = 0; + svOrder[Nsvm1] = trgtSvPos; + svOrder[0] = 0; + svOrder[1] = 1; + i = 2; + j = i; + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + if ( EQ_16( avq_bit_sFlag, 2 ) ) + { + j = add( i, 1 ); + } + WHILE( LT_16( i, Nsvm1 ) ) + { + svOrder[i] = j; + move16(); + i++; /*ptr*/ + j = add( j, 1 ); + } + /* write indexes to the bitstream */ + /* ============================== */ + + bits = *nb_bits; + move16(); + overflow = 0; + move16(); + FOR( i = 0; i < Nsv; i++ ) + { + k = svOrder[i]; + move16(); + test(); + test(); + test(); + test(); + test(); + tmp = bits; + move16(); + WHILE( GE_16( tmp, 5 ) ) + { + tmp = sub( tmp, 5 ); + } + assert( tmp == bits % 5 ); + IF( EQ_16( avq_bit_sFlag, 2 ) && EQ_16( tmp, 4 ) && GT_16( bits, 8 ) && LT_16( bits, 30 ) && GE_16( k, trgtSvPos ) && LT_16( i, Nsvm1 ) ) + { + ordr_esti( sub( Nsv, i ), &trgtSvPos, &svOrder[i], Nsv ); + k = svOrder[i]; + move16(); + avq_bit_sFlag = 1; + move16(); + } + + test(); + IF( EQ_16( k, trgtSvPos ) && avq_bit_sFlag > 0 ) + { + test(); + test(); + IF( EQ_16( sub( *nb_bits, bits ), 7 ) || LT_16( bits, BIT_SAVING_LOW_THR ) || GE_16( bits, BIT_SAVING_HIGH_THR ) ) + { + avq_bit_sFlag = 0; + move16(); + } + ELSE + { + BREAK; + } + } + + if ( EQ_16( sub( i_mult2( 5, nq[k] ), 1 ), bits ) ) /* check the overflow */ + { + overflow = 1; + move16(); + } + + IF( GT_16( bits, 8 ) ) + { + /* write the unary code for nq[i] */ + j = sub( nq[k], 1 ); + IF( nq[k] > 0 ) + { + /* write the unary code */ + FOR( ; j > 16; j -= 16 ) + { + push_indice( hBstr, nq_ind, 65535, 16 ); + bits = sub( bits, 16 ); + } + + IF( j > 0 ) + { + push_indice( hBstr, nq_ind, extract_l( L_sub( L_shl( 1L, j ), 1L ) ), j ); + bits = sub( bits, j ); + } + } + IF( !overflow ) + { + /* write the stop bit */ + push_indice( hBstr, nq_ind, 0, 1 ); + bits = sub( bits, 1 ); + } + + wrte_cv_ivas( hBstr, nq[k], i_ind, kv_ind, I[k], &kv[k * 8], &bits ); + } + } /* for */ + /* Bit Saving Solution */ + test(); + IF( avq_bit_sFlag > 0 && bits > 8 ) + { + // PMT("code not validated yet") + // bitsMod = bits%5; + bitsMod = bits; + WHILE( GE_16( bitsMod, 5 ) ) + { + bitsMod = sub( bitsMod, 5 ); + } + assert( bitsMod == bits % 5 ); + i = svOrder[Nsvm1]; + move16(); + IF( NE_16( i, Nsvm1 ) ) + { + nullVec = 0; + move16(); + FOR( j = i; j < Nsv - 1; j++ ) + { + if ( nq[svOrder[j]] == 0 ) + { + nullVec = add( nullVec, 1 ); + } + } + /*nq_est = bits / 5;*/ + nq_est = mult( bits, 6554 ); + assert( nq_est == bits / 5 ); + + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + IF( ( bitsMod > 0 || ( EQ_16( nullVec, 4 ) && EQ_16( nq_est, 5 ) ) ) && NE_16( bitsMod, 4 ) && GE_16( add( bits, nullVec ), add( add( shl( nq_est, 2 ), nq_est ), 4 ) ) /*5 * nq_est + 4*/ && nq[svOrder[Nsvm2]] == 0 ) /* detect need for dummy bits */ + { + dummy_bits = sub( 5, bitsMod ); + bits = add( bits, dummy_bits ); /* add dummy bits */ + bitsMod = 0; + move16(); + } + ELSE IF( nq_est > 4 && ( ( bitsMod == 0 && nullVec > 3 && nullVec < 6 ) || ( bitsMod == 4 && nullVec == 5 ) ) && nq[svOrder[Nsvm2]] == 0 ) /* wasted bits 4, 5 for nq 6,7..*/ + { + overflow = 0; + move16(); + tmp = add( bitsMod, nullVec ); + WHILE( GE_16( tmp, 5 ) ) + { + tmp = sub( tmp, 5 ); + } + assert( tmp == add( bitsMod, nullVec ) % 5 ); + if ( tmp != 0 ) + { + overflow = 1; + move16(); + } + dummy_bits = add( nullVec, overflow ); + bits = add( bits, dummy_bits ); /* add dummy bits */ + bitsMod = 0; + move16(); + } + } + + overflow = 1; + move16(); + IF( NE_16( bitsMod, 4 ) ) + { + overflow = 0; + move16(); + bits = sub( bits, bitsMod ); + } + bits = add( bits, overflow ); /*add fake bit */ + unused_bits = sub( bits, add( shl( nq[i], 2 ), nq[i] ) ); + if ( nq[i] == 0 ) /*no bit savings*/ + { + unused_bits = sub( unused_bits, 1 ); /*Stop Bit*/ + } + /*unused_bits_idx = (int16_t)unused_bits / 5;*/ + IF( unused_bits >= 0 ) + { + unused_bits_idx = mult( unused_bits, 6554 ); + } + ELSE + { + unused_bits_idx = negate( mult( negate( unused_bits ), 6554 ) ); + } + assert( unused_bits_idx == unused_bits / 5 ); + unusedbitsFlag = 0; + move16(); + IF( dummy_bits == 0 ) + { + test(); + test(); + IF( EQ_16( unused_bits_idx, 1 ) && GT_16( bits, BIT_SAVING_LOW_THR ) ) + { + unused_bits_idx = 0; + unusedbitsFlag = 1; + move16(); + move16(); + } + ELSE IF( unused_bits_idx == 0 && GT_16( bits, BIT_SAVING_LOW_THR ) ) + { + unused_bits_idx = 1; + unusedbitsFlag = -1; + move16(); + move16(); + } + } + + j = unused_bits_idx; + move16(); + /*Encode Unused Bit Unary Codeword */ + IF( j > 0 ) + { + /* write the unary code */ + push_indice( hBstr, nq_ind, u_extract_l( L_sub( L_shl_sat( 1, j ), 1 ) ), j ); + assert( abs( ( 1 << j ) - 1 ) <= 65536 ); + } + + IF( nq[i] != 0 ) + { + /* write the stop bit */ + push_indice( hBstr, nq_ind, 0, 1 ); + } + + /*Compute AVQ code book number from unused Bits */ + // bit_tmp = add( unusedbitsFlag, unused_bits_idx ); + /*nq_est = (int16_t)ceil(0.2f * (bits - 5 * (unusedbitsFlag + unused_bits_idx)));*/ + // nq_est = mult( 6554, sub( bits, add( shl( bit_tmp, 2 ), bit_tmp ) ) ); + bit_tmp = sub( bits, imult1616( 5, add( unusedbitsFlag, unused_bits_idx ) ) ); + nq_est = 0; + WHILE( bit_tmp > 0 ) + { + nq_est = add( nq_est, 1 ); + bit_tmp = sub( bit_tmp, 5 ); + } + assert( (int16_t) ceil( 0.2f * ( bits - 5 * ( unusedbitsFlag + unused_bits_idx ) ) ) == nq_est ); + + if ( EQ_16( nq_est, 1 ) ) + { + nq_est = 0; + move16(); + } + bits = sub( bits, overflow ); + + bits = sub( bits, j ); + + if ( nq_est != 0 ) + { + bits = sub( bits, 1 ); + } + nq[i] = nq_est; + move16(); + + /* write codebook indices (rank I and event. Voronoi index kv) */ + wrte_cv_ivas( hBstr, nq[i], i_ind, kv_ind, I[i], &kv[i * 8], &bits ); + + bits = sub( bits, dummy_bits ); + + if ( NE_16( bitsMod, 4 ) ) + { + bits = add( bits, bitsMod ); + } + } + *nb_bits = bits; + move16(); + + FOR( i = 0; i < Nsv; i++ ) + { + nq_out[i] = nq[i]; + move16(); + } + + return; +} /*-------------------------------------------------------------------* * Function AVQ_cod_lpc_fx() * @@ -715,3 +1147,63 @@ static void wrte_cv( move16(); return; } + +static void wrte_cv_ivas( + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + const Word16 nq, /* i : AVQ nq index */ + const Word16 i_ind, /* i : Base Bitstream index */ + const Word16 kv_ind, /* i : Vornoi Bitstream index */ + UWord16 I, /* o : rank I code book index */ + Word16 kv[], /* o : Vornoi index kv */ + Word16 *nbits /* i/o: bits */ +) +{ + int16_t pos, j; + int16_t bits, nq4; + + bits = *nbits; + move16(); + + /* write codebook indices (rank I and event. Voronoi index kv) */ + IF( nq == 0 ) /* Q0 */ + { + /* nothing to write */ + } + ELSE IF( LT_16( nq, 5 ) ) /* Q2, Q3, Q4 */ + { + nq4 = shl( nq, 2 ); + push_indice( hBstr, i_ind, I, nq4 ); + bits = sub( bits, nq4 ); + } + ELSE IF( EQ_16( s_and( nq, 1 ), 0 ) ) /* Q4 + Voronoi extensions r=1,2,3,... */ + { + push_indice( hBstr, i_ind, I, 4 * 4 ); + bits = sub( bits, 4 * 4 ); + /*pos = (int16_t)(nq / 2 - 2);*/ /* Voronoi order determination */ + pos = sub( shr( nq, 1 ), 2 ); + FOR( j = 0; j < 8; j++ ) + { + push_indice( hBstr, kv_ind, kv[j], pos ); + } + + bits = sub( bits, shl( pos, 3 ) ); + } + ELSE /* Q3 + Voronoi extensions r=1,2,3,... */ + { + push_indice( hBstr, i_ind, I, 4 * 3 ); + bits = sub( bits, 4 * 3 ); + + /*pos = (int16_t)(nq / 2 - 1);*/ /* Voronoi order determination */ + pos = sub( shr( nq, 1 ), 1 ); + FOR( j = 0; j < 8; j++ ) + { + push_indice( hBstr, kv_ind, kv[j], pos ); + } + + bits = sub( bits, shl( pos, 3 ) ); + } + + *nbits = bits; + move16(); + return; +} diff --git a/lib_enc/cod2t32_fx.c b/lib_enc/cod2t32_fx.c index 06c4d31f0..04105f232 100644 --- a/lib_enc/cod2t32_fx.c +++ b/lib_enc/cod2t32_fx.c @@ -2,10 +2,10 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ -#include "cnst.h" /* Common constants */ -#include "rom_com.h" /* Common constants */ -//#include "prot_fx.h" /* Function prototypes */ +#include "options.h" /* Compilation switches */ +#include "cnst.h" /* Common constants */ +#include "rom_com.h" /* Common constants */ +#include "prot.h" /* Function prototypes */ #include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ @@ -341,6 +341,318 @@ void acelp_2t32_fx( return; } +void acelp_2t32_ivas_fx( + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + const Word16 dn[], /* i : corr. between target and h[]. */ + const Word16 h[], /* i : impulse response of weighted synthesis filter */ + Word16 code[], /* o : algebraic (fixed) codebook excitation */ + Word16 y[] /* o : filtered fixed codebook excitation */ +) +{ + Word16 i, j, k, i0, i1, ix, iy, pos, pos2, sign0, sign1, index; + Word16 ps1, ps2, alpk, alp1, alp2; + Word16 sq, psk; + Word16 pol[L_SUBFR], dn_p[L_SUBFR]; + Word16 ii, jj; + Word16 *p0, *p1, *p2; + const Word16 *ptr_h1, *ptr_h2, *ptr_hf; + + Word32 s, L_cor; + Word32 L_tmp; + Word16 rrixix[NB_TRACK_FCB_2T][NB_POS_FCB_2T]; + Word16 rrixiy[MSIZE]; +#ifdef BASOP_NOGLOB_DECLARE_LOCAL + Flag Overflow = 0; +#endif + /*----------------------------------------------------------------* + * Compute rrixix[][] needed for the codebook search. + *----------------------------------------------------------------*/ + + /* Init pointers to last position of rrixix[] */ + p0 = &rrixix[0][NB_POS_FCB_2T - 1]; + move16(); + p1 = &rrixix[1][NB_POS_FCB_2T - 1]; + move16(); + + ptr_h1 = h; + move16(); + L_cor = L_deposit_h( 1 ); + FOR( i = 0; i < NB_POS_FCB_2T; i++ ) + { +#ifdef BASOP_NOGLOB + L_cor = L_mac_o( L_cor, *ptr_h1, *ptr_h1, &Overflow ); +#else + L_cor = L_mac( L_cor, *ptr_h1, *ptr_h1 ); +#endif + ptr_h1++; + *p1-- = extract_h( L_cor ); + move16(); /*Q9 Q7*/ +#ifdef BASOP_NOGLOB + L_cor = L_mac_o( L_cor, *ptr_h1, *ptr_h1, &Overflow ); +#else + L_cor = L_mac( L_cor, *ptr_h1, *ptr_h1 ); +#endif + ptr_h1++; + *p0-- = extract_h( L_cor ); + move16(); /*Q9 Q7*/ + } + + p0 = rrixix[0]; + move16(); + p1 = rrixix[1]; + move16(); + + FOR( i = 0; i < NB_POS_FCB_2T; i++ ) + { + *p0 = shr( *p0, 1 ); + move16(); + p0++; + *p1 = shr( *p1, 1 ); + move16(); + p1++; + } + + /*------------------------------------------------------------* + * Compute rrixiy[][] needed for the codebook search. + *------------------------------------------------------------*/ + + pos = MSIZE - 1; + move16(); + pos2 = MSIZE - 2; + move16(); + ptr_hf = h + 1; + move16(); + + FOR( k = 0; k < NB_POS_FCB_2T; k++ ) + { + /* Init pointers to last position of diagonals */ + p1 = &rrixiy[pos]; + move16(); + p0 = &rrixiy[pos2]; + move16(); + + ptr_h1 = h; + move16(); + ptr_h2 = ptr_hf; + move16(); + + L_cor = L_mult( *ptr_h1++, *ptr_h2++ ); + FOR( i = k; i < NB_POS_FCB_2T - 1; i++ ) + { +#ifdef BASOP_NOGLOB + *p1 = round_fx_o( L_cor, &Overflow ); + L_cor = L_mac_o( L_cor, *ptr_h1++, *ptr_h2++, &Overflow ); +#else + *p1 = round_fx( L_cor ); + L_cor = L_mac( L_cor, *ptr_h1++, *ptr_h2++ ); +#endif +#ifdef BASOP_NOGLOB + *p0 = round_fx_o( L_cor, &Overflow ); + L_cor = L_mac_o( L_cor, *ptr_h1++, *ptr_h2++, &Overflow ); +#else + *p0 = round_fx( L_cor ); + L_cor = L_mac( L_cor, *ptr_h1++, *ptr_h2++ ); +#endif + p1 -= ( NB_POS_FCB_2T + 1 ); + move16(); + p0 -= ( NB_POS_FCB_2T + 1 ); + move16(); + } + +#ifdef BASOP_NOGLOB + *p1 = round_fx_o( L_cor, &Overflow ); +#else + *p1 = round_fx( L_cor ); +#endif + pos -= NB_POS_FCB_2T; + move16(); + pos2--; + ptr_hf += STEP; + move16(); + } + + /*----------------------------------------------------------------* + * computing reference vector and pre-selection of polarities + *----------------------------------------------------------------*/ + + L_tmp = L_deposit_h( dn[0] ); + FOR( i = 0; i < L_SUBFR; i++ ) + { + /* FIR high-pass filtering */ + IF( i == 0 ) + { + L_tmp = L_msu( L_tmp, dn[1], 11469 ); + } + ELSE IF( EQ_16( i, L_SUBFR - 1 ) ) + { + L_tmp = L_deposit_h( dn[i] ); + L_tmp = L_msu( L_tmp, dn[i - 1], 11469 ); + } + ELSE + { + L_tmp = L_deposit_h( dn[i] ); + L_tmp = L_msu( L_tmp, dn[i - 1], 11469 ); + L_tmp = L_msu( L_tmp, dn[i + 1], 11469 ); + } + + /* pre-selection of polarities */ + IF( L_tmp >= 0 ) + { + pol[i] = 1; + move16(); + dn_p[i] = dn[i]; + move16(); + } + ELSE + { + pol[i] = -1; + move16(); + dn_p[i] = negate( dn[i] ); + move16(); + } + } + + /*----------------------------------------------------------------* + * compute denominator ( multiplied by polarity ) + *----------------------------------------------------------------*/ + + k = 0; + ii = 0; + move16(); + move16(); + FOR( i = 0; i < NB_POS_FCB_2T; i++ ) + { + jj = 1; + move16(); + FOR( j = 0; j < NB_POS_FCB_2T; j++ ) + { + test(); + if ( EQ_16( s_and( pol[ii], pol[jj] ), 1 ) && EQ_16( s_or( pol[ii], pol[jj] ), -1 ) ) + { + rrixiy[k + j] = negate( rrixiy[k + j] ); + move16(); + } + jj = add( jj, 2 ); + } + ii = add( ii, 2 ); + k = add( k, NB_POS_FCB_2T ); + } + + /*----------------------------------------------------------------* + * search 2 pulses + * All combinaisons are tested: + * 32 pos x 32 pos x 2 signs = 2048 tests + *----------------------------------------------------------------*/ + + p0 = rrixix[0]; + move16(); + p1 = rrixix[1]; + move16(); + p2 = rrixiy; + move16(); + psk = -1; + move16(); + alpk = 1; + move16(); + ix = 0; + move16(); + iy = 1; + move16(); + + FOR( i0 = 0; i0 < L_SUBFR; i0 += STEP ) + { + ps1 = dn_p[i0]; + move16(); + alp1 = *p0++; + move16(); + pos = -1; + move16(); + FOR( i1 = 1; i1 < L_SUBFR; i1 += STEP ) + { + ps2 = add( ps1, dn_p[i1] ); +#ifdef BASOP_NOGLOB + alp2 = add_o( alp1, add_o( *p1++, *p2++, &Overflow ), &Overflow ); +#else + alp2 = add( alp1, add( *p1++, *p2++ ) ); +#endif + sq = mult( ps2, ps2 ); +#ifdef BASOP_NOGLOB + s = L_msu_o( L_mult( alpk, sq ), psk, alp2, &Overflow ); +#else + s = L_msu( L_mult( alpk, sq ), psk, alp2 ); +#endif + IF( s > 0 ) + { + psk = sq; + move16(); + alpk = alp2; + move16(); + pos = i1; + move16(); + } + } + p1 -= NB_POS_FCB_2T; + move16(); + + IF( pos >= 0 ) + { + ix = i0; + move16(); + iy = pos; + move16(); + } + } + + i0 = shr( ix, 1 ); + i1 = shr( iy, 1 ); + + sign0 = shl( pol[ix], 9 ); + sign1 = shl( pol[iy], 9 ); + + /*-------------------------------------------------------------------* + * Build the codeword, the filtered codeword and index of codevector. + *-------------------------------------------------------------------*/ + + set16_fx( code, 0, L_SUBFR ); + + code[ix] = sign0; + move16(); + code[iy] = sign1; + move16(); + + index = add( shl( i0, 6 ), i1 ); + + + if ( sign0 < 0 ) + { + index = add( index, 0x800 ); + } + if ( sign1 < 0 ) + { + index = add( index, 0x20 ); /* move16();*/ + } + + set16_fx( y, 0, L_SUBFR ); + /* y_Q9 = sign_Q9<<3 * h_Q12 */ + + sign0 = shl( sign0, 3 ); + sign1 = shl( sign1, 3 ); + + FOR( i = ix; i < L_SUBFR; i++ ) + { + y[i] = mult_r( sign0, h[i - ix] ); + move16(); + } + FOR( i = iy; i < L_SUBFR; i++ ) + { + y[i] = round_fx( L_mac( L_deposit_h( y[i] ), sign1, h[i - iy] ) ); + } + { + /* write index to array of indices */ + push_indice( hBstr, IND_ALG_CDBK_2T32, index, 12 ); + } + return; +} /*---------------------------------------------------------------------------------- * Function acelp_1t64() * @@ -418,3 +730,72 @@ void acelp_1t64_fx( return; } + +void acelp_1t64_ivas_fx( + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + const Word16 dn[], /* i : corr. between target and h[]. */ + const Word16 h[], /* i : impulse response of weighted synthesis filter */ + Word16 code[], /* o : algebraic (fixed) codebook excitation */ + Word16 y[], /* o : filtered fixed codebook excitation */ + const Word16 L_subfr /* i : subframe length */ +) +{ + Word16 i, pos, sgn, index; + Word32 L_tmp; + /*-------------------------------------------------------------------* + * Find position and sign of maximum impulse. + *-------------------------------------------------------------------*/ + pos = emaximum_fx( 0, dn, L_subfr, &L_tmp ); + + IF( dn[pos] < 0 ) + { + sgn = -512; + move16(); + } + ELSE + { + sgn = 512; + move16(); + } + + /*-------------------------------------------------------------------* + * Build the codeword, the filtered codeword and index of codevector. + *-------------------------------------------------------------------*/ + + set16_fx( code, 0, L_subfr ); + code[pos] = sgn; + move16(); + + set16_fx( y, 0, L_subfr ); + + FOR( i = pos; i < L_subfr; i++ ) + { + IF( sgn > 0 ) + { + y[i] = shr_r( h[i - pos], 3 ); + move16(); + } + ELSE + { + y[i] = negate( shr_r( h[i - pos], 3 ) ); + move16(); + } + } + + index = pos; + move16(); + if ( sgn > 0 ) + { + index = add( index, L_subfr ); + } + IF( EQ_16( L_subfr, L_SUBFR ) ) + { + push_indice( hBstr, IND_ALG_CDBK_1T64, index, 7 ); + } + ELSE /* L_subfr == 2*L_SUBFR */ + { + push_indice( hBstr, IND_ALG_CDBK_1T64, index, 8 ); + } + + return; +} diff --git a/lib_enc/cod4t64_fast.c b/lib_enc/cod4t64_fast.c index 85c5d157f..51cc780c3 100644 --- a/lib_enc/cod4t64_fast.c +++ b/lib_enc/cod4t64_fast.c @@ -842,6 +842,7 @@ void acelp_fast_fx( Word16 track_order[NB_TRACK_FCB_4T * MAX_NUM_INTER], m0_track[NB_TRACK_FCB_4T]; Word16 ind_stream[NPMAXPT * NB_TRACK_FCB_4T], idx; Word16 G, G1, G2, G3, Gn, Gd; + Word32 Gd32; Word16 y_tmp[L_SUBFR_MAX]; Word32 dn[L_SUBFR_MAX]; Word32 crit_num, crit_den, crit_num_max, crit_den_max, L_tmp1, L_tmp2; @@ -1332,9 +1333,10 @@ void acelp_fast_fx( IF( GE_16( nb_pulse, 3 ) ) { - Gn = add( Gn, i_mult( s[1], shr( dn_orig[m[1]], 1 ) ) ); // Q_dn -1 - Gd = add( Gd, add( alp[0], i_mult( i_mult( shl( s[0], 1 ), s[1] ), alp[m[0] - m[1]] ) ) ); // Q6 - G = Gn; // Q_dn - 1 + Gn = add( Gn, i_mult( s[1], shr( dn_orig[m[1]], 1 ) ) ); // Q_dn -1 + Gd32 = Gd; + Gd32 = L_add( Gd32, L_add( alp[0], L_mult0( i_mult( shl( s[0], 1 ), s[1] ), alp[m[0] - m[1]] ) ) ); // Q6 + G = Gn; // Q_dn - 1 move16(); G1 = i_mult( G, s[1] ); // Q_dn-1 G = i_mult( G, s[0] ); // Q_dn-1 @@ -1346,7 +1348,7 @@ void acelp_fast_fx( FOR( i = track; i < L_subfr; i += nb_tracks ) { - dn[i] = L_shr( L_msu( L_msu0( L_mult0( Gd, dn_orig[i] ), G, *alp_pos0 ), G1, *alp_pos1 ), 6 ); // Q_dn + dn[i] = L_shr( L_msu( L_msu0( imult3216( Gd32, dn_orig[i] ), G, *alp_pos0 ), G1, *alp_pos1 ), 6 ); // Q_dn move32(); alp_pos0 += nb_tracks; alp_pos1 += nb_tracks; @@ -1362,9 +1364,10 @@ void acelp_fast_fx( IF( GE_16( nb_pulse, 4 ) ) { - Gn = add( Gn, i_mult( s[2], shr( dn_orig[m[2]], 1 ) ) ); // Q_dn-1 - Gd = add( Gd, add( add( alp[0], i_mult( i_mult( shl( s[0], 1 ), s[2] ), alp[m[0] - m[2]] ) ), i_mult( i_mult( shl( s[1], 1 ), s[2] ), alp[m[1] - m[2]] ) ) ); // Q6 - G = Gn; // Q_dn-1 + Gn = add( Gn, i_mult( s[2], shr( dn_orig[m[2]], 1 ) ) ); // Q_dn-1 + Gd32 = Gd; + Gd32 = L_add( Gd32, L_add( L_add( alp[0], L_mult0( i_mult( shl( s[0], 1 ), s[2] ), alp[m[0] - m[2]] ) ), L_mult0( i_mult( shl( s[1], 1 ), s[2] ), alp[m[1] - m[2]] ) ) ); // Q6 + G = Gn; // Q_dn-1 move16(); G1 = i_mult( G, s[1] ); // Q_dn-1 G2 = i_mult( G, s[2] ); // Q_dn-1 @@ -1378,7 +1381,7 @@ void acelp_fast_fx( FOR( i = track; i < L_subfr; i += nb_tracks ) { - dn[i] = L_shr( L_msu( L_msu( L_msu( L_mult0( Gd, dn_orig[i] ), G, *alp_pos0 ), G1, *alp_pos1 ), G2, *alp_pos2 ), 6 ); // Q_dn + dn[i] = L_shr( L_msu( L_msu( L_msu( imult3216( Gd32, dn_orig[i] ), G, *alp_pos0 ), G1, *alp_pos1 ), G2, *alp_pos2 ), 6 ); // Q_dn move32(); alp_pos0 += nb_tracks; alp_pos1 += nb_tracks; @@ -1400,13 +1403,14 @@ void acelp_fast_fx( IF( GE_16( nb_pulse, 5 ) ) { - Gn = add( Gn, i_mult( s[3], shr( dn_orig[m[3]], 1 ) ) ); // Q_dn-1 - Gd = add( Gd, add( add( add( alp[0], i_mult( i_mult( shl( s[0], 1 ), s[3] ), alp[m[0] - m[3]] ) ), i_mult( i_mult( shl( s[1], 1 ), s[3] ), alp[m[1] - m[3]] ) ), i_mult( i_mult( shl( s[2], 1 ), s[3] ), alp[m[2] - m[3]] ) ) ); // Q6 - G = Gn; // Q_dn-1 - G1 = i_mult( G, s[1] ); // Q_dn-1 - G2 = i_mult( G, s[2] ); // Q_dn-1 - G3 = i_mult( G, s[3] ); // Q_dn-1 - G = i_mult( G, s[0] ); // Q_dn-1 + Gn = add( Gn, i_mult( s[3], shr( dn_orig[m[3]], 1 ) ) ); // Q_dn-1 + Gd32 = Gd; + Gd32 = L_add( Gd32, L_add( L_add( L_add( alp[0], L_mult0( i_mult( shl( s[0], 1 ), s[3] ), alp[m[0] - m[3]] ) ), L_mult0( i_mult( shl( s[1], 1 ), s[3] ), alp[m[1] - m[3]] ) ), L_mult0( i_mult( shl( s[2], 1 ), s[3] ), alp[m[2] - m[3]] ) ) ); // Q6 + G = Gn; // Q_dn-1 + G1 = i_mult( G, s[1] ); // Q_dn-1 + G2 = i_mult( G, s[2] ); // Q_dn-1 + G3 = i_mult( G, s[3] ); // Q_dn-1 + G = i_mult( G, s[0] ); // Q_dn-1 IF( EQ_16( cdk_index, 6 ) ) { @@ -1420,7 +1424,7 @@ void acelp_fast_fx( FOR( i = track; i < L_subfr; i += nb_tracks ) { - dn[i] = L_shr( L_msu( L_msu( L_msu( L_msu( L_mult0( Gd, dn_orig[i] ), G, *alp_pos0 ), G1, *alp_pos1 ), G2, *alp_pos2 ), G3, *alp_pos3 ), 6 ); // Q_dn + dn[i] = L_shr( L_msu( L_msu( L_msu( L_msu( imult3216( Gd32, dn_orig[i] ), G, *alp_pos0 ), G1, *alp_pos1 ), G2, *alp_pos2 ), G3, *alp_pos3 ), 6 ); // Q_dn move32(); alp_pos0 += nb_tracks; alp_pos1 += nb_tracks; @@ -1440,7 +1444,7 @@ void acelp_fast_fx( FOR( i = 0; i < L_subfr; i++ ) { - dn[i] = L_shr( L_msu( L_msu( L_msu( L_msu( L_mult0( Gd, dn_orig[i] ), G, *alp_pos0 ), G1, *alp_pos1 ), G2, *alp_pos2 ), G3, *alp_pos3 ), 6 ); /*Q_dn*/ + dn[i] = L_shr( L_msu( L_msu( L_msu( L_msu( imult3216( Gd32, dn_orig[i] ), G, *alp_pos0 ), G1, *alp_pos1 ), G2, *alp_pos2 ), G3, *alp_pos3 ), 6 ); /*Q_dn*/ move16(); alp_pos0++; alp_pos1++; @@ -1570,7 +1574,7 @@ void acelp_fast_fx( set16_fx( code, 0, L_subfr ); FOR( q = 0; q < nb_pulse; q++ ) { - code[m_max[q]] = add( code[m_max[q]], s_max[q] ); // Q0 + code[m_max[q]] = add( code[m_max[q]], shl( s_max[q], Q9 ) ); // Q9 move16(); } test(); diff --git a/lib_enc/cod4t64_fx.c b/lib_enc/cod4t64_fx.c index b20c94daf..19b195615 100644 --- a/lib_enc/cod4t64_fx.c +++ b/lib_enc/cod4t64_fx.c @@ -2,10 +2,10 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ #include -#include "options.h" /* VMR-WB compilation switches */ -#include "cnst.h" /* Common constants */ -#include "rom_enc.h" /* Encoder static table prototypes */ -//#include "prot_fx.h" /* Function prototypes */ +#include "options.h" /* VMR-WB compilation switches */ +#include "cnst.h" /* Common constants */ +#include "rom_enc.h" /* Encoder static table prototypes */ +#include "prot.h" /* Function prototypes */ #include "rom_com_fx.h" /* Static table prototypes */ #include "rom_com.h" /* Static table prototypes */ #include "prot_fx.h" /* Function prototypes */ @@ -471,6 +471,420 @@ Word16 acelp_4t64_fx( } +Word16 acelp_4t64_ivas_fx( + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + Word16 dn[], /* i : corr. between target and h[]. */ + const Word16 cn[], /* i : residual after long term prediction Q_new*/ + const Word16 H[], /* i : impulse response of weighted synthesis filter Q12*/ + Word16 R[], /* i : autocorrelation values */ + const Word16 acelpautoc, /* i : autocorrealtion flag */ + Word16 code[], /* o : algebraic (fixed) codebook excitation Q9*/ + Word16 y[], /* o : filtered fixed codebook excitation Q9*/ + Word16 nbbits, /* i : number of bits per codebook */ + const Word16 cmpl_flag, /* i : complexity reduction flag */ + const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ + Word16 element_mode ) +{ + + Word16 i, k, index, track; + Word32 L_index; + Word16 ind[NPMAXPT * NB_TRACK_FCB_4T + 32]; /* VE3: why +32 ???*/ + Word16 codvec[NB_PULSE_MAX + 4] = { 0 }; + Word16 saved_bits = 0; + + PulseConfig config; + Word16 indexing_indices[6], wordcnt, bitcnt; + + set16_fx( codvec, 0, NB_PULSE_MAX + 4 ); + SWITCH( nbbits ) + { + + case 20: /* EVS/AMR-WB pulse indexing: 20 bits, 4 pulses, 4 tracks */ + config.nbiter = 4; + move16(); /* 4x12x16=768 loop */ + config.alp = 16384; + move16(); /* 2 in Q13*/ + config.nb_pulse = 4; + move16(); + config.fixedpulses = 0; + move16(); + config.nbpos[0] = 4; + move16(); + config.nbpos[1] = 8; + move16(); + BREAK; + + case 28: /* EVS pulse indexing: 28 bits, 6 pulses, 4 tracks */ + config.nbiter = 4; + move16(); /* 4x20x16=1280 loops */ + config.alp = 8192; + move16(); /* coeff FOR sign setting */ + config.nb_pulse = 6; + move16(); + config.fixedpulses = 0; + move16(); + config.nbpos[0] = 6; + move16(); + config.nbpos[1] = 6; + move16(); + config.nbpos[2] = 8; + move16(); + BREAK; + + case 36: /* EVS/AMR-WB pulse indexing: 36 bits, 8 pulses, 4 tracks */ + config.nbiter = 4; + move16(); /* 4x20x16=1280 loops */ + config.alp = 8192; + move16(); /* coeff FOR sign setting */ + config.nb_pulse = 8; + move16(); + config.fixedpulses = 2; + move16(); + config.nbpos[0] = 4; + move16(); + config.nbpos[1] = 8; + move16(); + config.nbpos[2] = 8; + move16(); + BREAK; + + case 43: /* EVS pulse indexing: 43 bits, 10 pulses, 4 tracks */ + case 44: /* AMR-WB pulse indexing: 44 bits, 10 pulses, 4 tracks */ + config.nbiter = 4; + move16(); /* 4x26x16=1664 loops */ + config.alp = 8192; + move16(); + config.nb_pulse = 10; + move16(); + config.fixedpulses = 2; + move16(); + config.nbpos[0] = 4; + move16(); + config.nbpos[1] = 6; + move16(); + config.nbpos[2] = 8; + move16(); + config.nbpos[3] = 8; + move16(); + BREAK; + + case 50: /* EVS pulse indexing: 50 bits, 12 pulses, 4 tracks */ + case 52: /* AMR-WB pulse indexing: 52 bits, 12 pulses, 4 tracks */ + config.nbiter = 4; + move16(); /* 4x26x16=1664 loops */ + config.alp = 8192; + move16(); + config.nb_pulse = 12; + move16(); + config.fixedpulses = 4; + move16(); + config.nbpos[0] = 4; + move16(); + config.nbpos[1] = 6; + move16(); + config.nbpos[2] = 8; + move16(); + config.nbpos[3] = 8; + move16(); + BREAK; + + case 62: /* EVS pulse indexing: 62 bits, 16 pulses, 4 tracks */ + case 64: /* AMR-WB pulse indexing: 64 bits, 16 pulses, 4 tracks */ + config.nbiter = 3; + move16(); /* 3x36x16=1728 loops */ + config.alp = 6554; + move16(); + config.nb_pulse = 16; + move16(); + config.fixedpulses = 4; + move16(); + config.nbpos[0] = 4; + move16(); + config.nbpos[1] = 4; + move16(); + config.nbpos[2] = 6; + move16(); + config.nbpos[3] = 6; + move16(); + config.nbpos[4] = 8; + move16(); + config.nbpos[5] = 8; + move16(); + BREAK; + + case 72: /* AMR-WB pulse indexing: 72 bits, 18 pulses, 4 tracks */ + config.nbiter = 3; + move16(); /* 3x35x16=1680 loops */ + config.alp = 6144; + move16(); + config.nb_pulse = 18; + move16(); + config.fixedpulses = 4; + move16(); + config.nbpos[0] = 2; + move16(); + config.nbpos[1] = 3; + move16(); + config.nbpos[2] = 4; + move16(); + config.nbpos[3] = 5; + move16(); + config.nbpos[4] = 6; + move16(); + config.nbpos[5] = 7; + move16(); + config.nbpos[6] = 8; + move16(); + BREAK; + + case 88: /* AMR-WB pulse indexing: 88 bits, 24 pulses, 4 tracks */ + config.nbiter = 2; + move16(); /* 2x53x16=1696 loop */ + config.alp = 4096; + move16(); + config.nb_pulse = 24; + move16(); + config.fixedpulses = 4; + move16(); + config.nbpos[0] = 2; + move16(); + config.nbpos[1] = 2; + move16(); + config.nbpos[2] = 3; + move16(); + config.nbpos[3] = 4; + move16(); + config.nbpos[4] = 5; + move16(); + config.nbpos[5] = 6; + move16(); + config.nbpos[6] = 7; + move16(); + config.nbpos[7] = 8; + move16(); + config.nbpos[8] = 8; + move16(); + config.nbpos[9] = 8; + move16(); + BREAK; + + case 87: /* EVS pulse indexing: 87 bits, 26 pulses, 4 tracks */ + config.nbiter = 1; + move16(); + config.alp = 4096; + move16(); + config.nb_pulse = 26; + move16(); + config.fixedpulses = 4; + move16(); + config.nbpos[0] = 4; + move16(); + config.nbpos[1] = 6; + move16(); + config.nbpos[2] = 6; + move16(); + config.nbpos[3] = 8; + move16(); + config.nbpos[4] = 8; + move16(); + config.nbpos[5] = 8; + move16(); + config.nbpos[6] = 8; + move16(); + config.nbpos[7] = 8; + move16(); + config.nbpos[8] = 8; + move16(); + config.nbpos[9] = 8; + move16(); + config.nbpos[10] = 8; + move16(); + BREAK; + } + + /* reduce the number of iterations as a compromise between the performance and complexity */ + if ( cmpl_flag > 0 ) + { + config.nbiter = cmpl_flag; + move16(); + } + + config.codetrackpos = TRACKPOS_FIXED_FIRST; + move16(); + config.bits = nbbits; + move16(); + + IF( acelpautoc ) + { + E_ACELP_4tsearchx_ivas_fx( dn, cn, R, code, &config, ind, element_mode ); + + /* Generate weighted code */ + E_ACELP_weighted_code( code, H, 12, y ); + } + ELSE + { + E_ACELP_4tsearch_fx( dn, cn, H, code, &config, ind, y ); + + FOR( i = 0; i < L_SUBFR; i++ ) + { + y[i] = shr( y[i], 3 ); + move16(); /*Q9 */ + } + } + + /*-----------------------------------------------------------------* + * Indexing + *-----------------------------------------------------------------*/ + + IF( !Opt_AMR_WB ) + { + saved_bits = E_ACELP_indexing_fx( code, &config, NB_TRACK_FCB_4T, indexing_indices ); + + saved_bits = 0; + move16(); + + wordcnt = shr( nbbits, 4 ); + bitcnt = s_and( nbbits, 15 ); + FOR( i = 0; i < wordcnt; i++ ) + { + push_indice( hBstr, IND_ALG_CDBK_4T64, indexing_indices[i], 16 ); + } + IF( bitcnt ) + { + push_indice( hBstr, IND_ALG_CDBK_4T64, indexing_indices[i], bitcnt ); + } + } + ELSE + { + /* AMR-WB pulse indexing */ + + IF( EQ_16( nbbits, 20 ) ) + { + FOR( track = 0; track < NB_TRACK_FCB_4T; track++ ) + { + k = i_mult2( track, NPMAXPT ); + index = quant_1p_N1_fx( ind[k], 4 ); + push_indice( hBstr, IND_ALG_CDBK_4T64, index, 5 ); + } + } + ELSE IF( EQ_16( nbbits, 36 ) ) + { + FOR( track = 0; track < NB_TRACK_FCB_4T; track++ ) + { + + k = i_mult2( track, NPMAXPT ); /* k = track * NPMAXPT;*/ + index = quant_2p_2N1_fx( ind[k], ind[k + 1], 4 ); + push_indice( hBstr, IND_ALG_CDBK_4T64, index, 9 ); + } + } + ELSE IF( EQ_16( nbbits, 44 ) ) /* AMR-WB pulse indexing */ + { + FOR( track = 0; track < ( NB_TRACK_FCB_4T - 2 ); track++ ) + { + k = i_mult2( track, NPMAXPT ); + index = quant_3p_3N1_fx( ind[k], ind[k + 1], ind[k + 2], 4 ); + push_indice( hBstr, IND_ALG_CDBK_4T64, index, 13 ); + } + + FOR( track = 2; track < NB_TRACK_FCB_4T; track++ ) + { + k = i_mult2( track, NPMAXPT ); + index = quant_2p_2N1_fx( ind[k], ind[k + 1], 4 ); + push_indice( hBstr, IND_ALG_CDBK_4T64, index, 9 ); + } + } + ELSE IF( EQ_16( nbbits, 52 ) ) /* AMR-WB pulse indexing */ + { + FOR( track = 0; track < NB_TRACK_FCB_4T; track++ ) + { + k = i_mult2( track, NPMAXPT ); + index = quant_3p_3N1_fx( ind[k], ind[k + 1], ind[k + 2], 4 ); + push_indice( hBstr, IND_ALG_CDBK_4T64, index, 13 ); + } + } + ELSE IF( EQ_16( nbbits, 64 ) ) /* AMR-WB pulse indexing */ + { + FOR( track = 0; track < NB_TRACK_FCB_4T; track++ ) + { + k = i_mult2( track, NPMAXPT ); + L_index = quant_4p_4N_fx( &ind[k], 4 ); + index = extract_l( L_shr( L_index, 14 ) & 3 ); + logic16(); + push_indice( hBstr, IND_ALG_CDBK_4T64_1, index, 2 ); + } + + FOR( track = 0; track < NB_TRACK_FCB_4T; track++ ) + { + k = i_mult2( track, NPMAXPT ); + L_index = quant_4p_4N_fx( &ind[k], 4 ); + index = extract_l( L_index & 0x3FFF ); + logic16(); + push_indice( hBstr, IND_ALG_CDBK_4T64_2, index, 14 ); + } + } + ELSE IF( EQ_16( nbbits, 72 ) ) + { + FOR( track = 0; track < ( NB_TRACK_FCB_4T - 2 ); track++ ) + { + k = i_mult2( track, NPMAXPT ); + L_index = quant_5p_5N_fx( &ind[k], 4 ); + index = extract_l( L_shr( L_index, 10 ) & 0x03FF ); + logic16(); + push_indice( hBstr, IND_ALG_CDBK_4T64_1, index, 10 ); + } + + FOR( track = 2; track < NB_TRACK_FCB_4T; track++ ) + { + k = i_mult2( track, NPMAXPT ); + L_index = quant_4p_4N_fx( &ind[k], 4 ); + index = extract_l( L_shr( L_index, 14 ) & 3 ); + logic16(); + push_indice( hBstr, IND_ALG_CDBK_4T64_1, index, 2 ); + } + + FOR( track = 0; track < ( NB_TRACK_FCB_4T - 2 ); track++ ) + { + k = i_mult2( track, NPMAXPT ); + L_index = quant_5p_5N_fx( &ind[k], 4 ); + index = extract_l( L_index & 0x03FF ); + logic16(); + push_indice( hBstr, IND_ALG_CDBK_4T64_2, index, 10 ); + } + + FOR( track = 2; track < NB_TRACK_FCB_4T; track++ ) + { + k = i_mult2( track, NPMAXPT ); + L_index = quant_4p_4N_fx( &ind[k], 4 ); + index = extract_l( L_index & 0x3FFF ); + logic16(); + push_indice( hBstr, IND_ALG_CDBK_4T64_2, index, 14 ); + } + } + ELSE IF( EQ_16( nbbits, 88 ) ) + { + FOR( track = 0; track < NB_TRACK_FCB_4T; track++ ) + { + k = i_mult2( track, NPMAXPT ); + L_index = quant_6p_6N_2_fx( &ind[k], 4 ); + index = extract_l( L_shr( L_index, 11 ) & 0x07FF ); + logic16(); + push_indice( hBstr, IND_ALG_CDBK_4T64_1, index, 11 ); + } + + FOR( track = 0; track < NB_TRACK_FCB_4T; track++ ) + { + k = i_mult2( track, NPMAXPT ); + L_index = quant_6p_6N_2_fx( &ind[k], 4 ); + index = extract_l( L_index & 0x07FF ); + logic16(); + push_indice( hBstr, IND_ALG_CDBK_4T64_2, index, 11 ); + } + } + } + + return saved_bits; +} + /*---------------------------------------------------------------------* *encode class for 3p 4p 5p 6p/track * *---------------------------------------------------------------------*/ diff --git a/lib_enc/core_enc_init.c b/lib_enc/core_enc_init.c index b1fd1d7f2..b4837eecc 100644 --- a/lib_enc/core_enc_init.c +++ b/lib_enc/core_enc_init.c @@ -1685,8 +1685,6 @@ static void init_acelp_ivas_fx( Encoder_State *st, Word16 L_frame_old, Word16 sh move16(); set16_fx( hLPDmem->old_exc, 0, L_EXC_MEM ); move16(); - hLPDmem->e_old_exc = 0; - move16(); /*Resamp others memories*/ /*Size of LPC syn memory*/ /* 1.25/20.0 = 1.0/16.0 -> shift 4 to the right. */ diff --git a/lib_enc/core_enc_switch.c b/lib_enc/core_enc_switch.c index 31d300f31..0a90b3648 100644 --- a/lib_enc/core_enc_switch.c +++ b/lib_enc/core_enc_switch.c @@ -249,7 +249,8 @@ void core_coder_mode_switch_ivas_fx( fixedToFloat_arr( st->lspold_enc_fx, st->lspold_enc, Q15, M ); IF( st->hLPDmem != NULL ) { - me2f_buf_16( st->hLPDmem->old_exc, st->hLPDmem->e_old_exc, st->hLPDmem->old_exc_flt, L_EXC_MEM ); + // me2f_buf_16( st->hLPDmem->old_exc, st->hLPDmem->e_old_exc, st->hLPDmem->old_exc_flt, L_EXC_MEM ); + fixedToFloat_arr( st->hLPDmem->old_exc, st->hLPDmem->old_exc_flt, st->prev_Q_new, L_EXC_MEM ); } #endif } diff --git a/lib_enc/corr_xh_fx.c b/lib_enc/corr_xh_fx.c index a999b8930..92b3c7eba 100644 --- a/lib_enc/corr_xh_fx.c +++ b/lib_enc/corr_xh_fx.c @@ -88,24 +88,147 @@ void corr_xh_ivas_fx( const Word16 L_subfr /* i : length of the subframe */ ) { - Word16 i, j; - Word32 s; - Word32 y32[2 * L_SUBFR]; + Word16 i, j, scale; + Word64 s64; Word16 shift = add( norm_s( h[0] ), 1 ); + scale = sub( sub( 15, shift ), 2 ); FOR( i = 0; i < L_subfr; i++ ) { - s = 0; - move32(); + s64 = 0; + move16(); FOR( j = i; j < L_subfr; j++ ) { - s = L_add( s, shl( mult( x[j], h[j - i] ), shift ) ); // Q_new - 1 + s64 = W_mac0_16_16( s64, x[j], h[j - i] ); // Q_new - 1 + 15 - shift } - y32[i] = s; // Q_new - 1 - move32(); + y[i] = extract_l( W_extract_l( W_shr( s64, scale ) ) ); // Q_new + 1 + move16(); } - Copy_Scale_sig32_16( y32, y, L_subfr, 18 ); // Q_new + 1 return; } + +void corr_hh_ivas_fx( + const Word16 *h, /* i : target signal e(norm_s(h1[0])+1) */ + Word16 *y, /* o : correlation between x[] and h[] Q_new + 1 */ + Word16 *Qy, + const Word16 L_subfr /* i : length of the subframe */ +) +{ + Word16 i, j, k; + Word32 L_tmp, y32[L_SUBFR * 2], L_maxloc, L_tot; +#ifdef BASOP_NOGLOB_DECLARE_LOCAL + Flag Overflow = 0; +#endif + + /* first keep the result on 32 bits and find absolute maximum */ + L_tot = L_deposit_l( 1 ); + + FOR( k = 0; k < NB_TRACK; k++ ) + { + L_maxloc = L_deposit_l( 0 ); + FOR( i = k; i < L_subfr; i += STEP ) + { + L_tmp = L_mac( 1L, h[i], h[0] ); /* 1 -> to avoid null dn[] */ // 2*(15 - norm_s(h[0])) - 1 + FOR( j = i; j < L_subfr - 1; j++ ) + { +#ifdef BASOP_NOGLOB + L_tmp = L_mac_o( L_tmp, h[j + 1], h[j + 1 - i], &Overflow ); // 2*(15 - norm_s(h[0])) - 1 +#else + L_tmp = L_mac( L_tmp, x[j + 1], h[j + 1 - i] ); +#endif + } + + y32[i] = L_tmp; + move32(); + L_tmp = L_abs( L_tmp ); + L_maxloc = L_max( L_tmp, L_maxloc ); + } + /* tot += 3*max / 8 */ + L_maxloc = L_shr( L_maxloc, 2 ); +#ifdef BASOP_NOGLOB + L_tot = L_add_o( L_tot, L_maxloc, &Overflow ); /* +max/4 */ + L_tot = L_add_o( L_tot, L_shr( L_maxloc, 1 ), &Overflow ); /* +max/8 */ +#else + L_tot = L_add( L_tot, L_maxloc ); /* +max/4 */ + L_tot = L_add( L_tot, L_shr( L_maxloc, 1 ) ); /* +max/8 */ +#endif + } + + /* Find the number of right shifts to do on y32[] so that */ + /* 6.0 x sumation of max of dn[] in each track not saturate. */ + + j = sub( norm_l( L_tot ), 4 ); /* 4 -> 16 x tot */ + + FOR( i = 0; i < L_subfr; i++ ) + { + y[i] = round_fx( L_shl( y32[i], j ) ); // 2*(15 - norm_s(h[0])) - 1 +j - 16 + } + + *Qy = sub( add( shl( sub( 15, norm_s( h[0] ) ), 1 ), j ), 17 ); + return; +} + +void corr_xh_ivas_fx2( + const Word16 x[], /* i : target signal */ + const Word16 Qx, + Word16 dn[], /* o : correlation between x[] and h[] */ + Word16 *Qdn, + const Word16 h[], /* i : impulse response (of weighted synthesis filter) */ + const Word16 L_subfr /* i : length of the subframe */ +) +{ + Word16 i, j, k; + Word32 L_tmp, y32[L_SUBFR * 2], L_maxloc, L_tot; +#ifdef BASOP_NOGLOB_DECLARE_LOCAL + Flag Overflow = 0; +#endif + + /* first keep the result on 32 bits and find absolute maximum */ + L_tot = L_deposit_l( 1 ); + + FOR( k = 0; k < NB_TRACK; k++ ) + { + L_maxloc = L_deposit_l( 0 ); + FOR( i = k; i < L_subfr; i += STEP ) + { + L_tmp = L_mac( 1L, x[i], h[0] ); /* 1 -> to avoid null dn[] */ // Qx+(15 - norm_s(h[0])) + FOR( j = i; j < L_subfr - 1; j++ ) + { +#ifdef BASOP_NOGLOB + L_tmp = L_mac_o( L_tmp, x[j + 1], h[j + 1 - i], &Overflow ); // Qx+(15 - norm_s(h[0])) +#else + L_tmp = L_mac( L_tmp, x[j + 1], h[j + 1 - i] ); +#endif + } + + y32[i] = L_tmp; + move32(); + L_tmp = L_abs( L_tmp ); + L_maxloc = L_max( L_tmp, L_maxloc ); + } + /* tot += 3*max / 8 */ + L_maxloc = L_shr( L_maxloc, 2 ); +#ifdef BASOP_NOGLOB + L_tot = L_add_o( L_tot, L_maxloc, &Overflow ); /* +max/4 */ + L_tot = L_add_o( L_tot, L_shr( L_maxloc, 1 ), &Overflow ); /* +max/8 */ +#else + L_tot = L_add( L_tot, L_maxloc ); /* +max/4 */ + L_tot = L_add( L_tot, L_shr( L_maxloc, 1 ) ); /* +max/8 */ +#endif + } + + /* Find the number of right shifts to do on y32[] so that */ + /* 6.0 x sumation of max of dn[] in each track not saturate. */ + + j = sub( norm_l( L_tot ), 4 ); /* 4 -> 16 x tot */ + + FOR( i = 0; i < L_subfr; i++ ) + { + dn[i] = round_fx( L_shl( y32[i], j ) ); // Qx+(15 - norm_s(h[0])) +j - 16 + } + + *Qdn = sub( add( add( Qx, sub( 15, norm_s( h[0] ) ) ), j ), 16 ); + return; +} diff --git a/lib_enc/enc_acelp_fx.c b/lib_enc/enc_acelp_fx.c index a60172827..ee57efffe 100644 --- a/lib_enc/enc_acelp_fx.c +++ b/lib_enc/enc_acelp_fx.c @@ -355,7 +355,7 @@ static void E_ACELP_1pulse_search( UWord8 tracks[2], move16(); sqk[0] = -1; move16(); - if ( mac_r( alp0, cor_x[shr( tracks[0], 2 )], _1_ ) < 0 ) + if ( mac_r_sat( alp0, cor_x[shr( tracks[0], 2 )], _1_ ) < 0 ) { sqk[0] = 1; move16(); @@ -382,7 +382,7 @@ static void E_ACELP_1pulse_search( UWord8 tracks[2], ps1 = add( ps0, dn[x] ); /*alp1 = alp0 + cor_x[x>>2]; SHIFT(1);ADD(1);*/ - alp1 = mac_r( alp0, cor_x[shr( x, 2 )], _1_ ); /*Q6*/ + alp1 = mac_r_sat( alp0, cor_x[shr( x, 2 )], _1_ ); /*Q6*/ alpk[1 - ik] = alp1; move16(); @@ -1569,6 +1569,70 @@ void E_ACELP_4t_fx( return; } +void E_ACELP_4t_ivas_fx( + Word16 dn[], + Word16 cn[] /* Q_xn */, + Word16 H[], + Word16 R[], + Word8 acelpautoc, + Word16 code[], + Word16 cdk_index, + Word16 _index[], + const Word16 L_frame, + const Word16 last_L_frame, + const Word32 total_brate, + const Word16 i_subfr, + const int16_t cmpl_flag, + Word16 element_mode ) +{ + PulseConfig config; + Word16 ind[NPMAXPT * 4]; + Word16 y[L_SUBFR]; + + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + memcpy( &config, &PulseConfTable[cdk_index], sizeof( PulseConfTable[cdk_index] ) ); + + + if ( cmpl_flag > 0 ) + { + config.nbiter = cmpl_flag; + move16(); + } + test(); + test(); + IF( NE_16( L_frame, last_L_frame ) && EQ_32( total_brate, ACELP_24k40 ) && LT_32( i_subfr, 5 * L_SUBFR ) ) + { + config.nbiter = sub( config.nbiter, 1 ); + config.nbiter = s_max( config.nbiter, 1 ); + } + + IF( acelpautoc ) + { + E_ACELP_4tsearchx_ivas_fx( dn, cn, R, code, &config, ind, element_mode ); + } + ELSE + { + E_ACELP_4tsearch_fx( dn, cn, H, code, &config, ind, y ); + } + E_ACELP_indexing_fx( code, &config, NB_TRACK_FCB_4T, _index ); + return; +} + static void E_ACELP_indexing_shift( Word16 wordcnt, /* i: 16-bit word count including the newly shifted-in bits */ Word16 shift_bits, /* i: number of bits to shift in from the lsb */ diff --git a/lib_enc/enc_acelpx_fx.c b/lib_enc/enc_acelpx_fx.c index cac1c81ed..43df35a55 100644 --- a/lib_enc/enc_acelpx_fx.c +++ b/lib_enc/enc_acelpx_fx.c @@ -621,3 +621,273 @@ void E_ACELP_4tsearchx_fx( */ E_ACELP_build_code( nb_pulse, codvec, sign, code, ind ); } + +void E_ACELP_4tsearchx_ivas_fx( + Word16 dn[], + const Word16 cn[], + Word16 Rw[], + Word16 code[], + const PulseConfig *config, + Word16 ind[], + Word16 element_mode ) +{ + Word16 sign[L_SUBFR], vec[L_SUBFR]; + Word16 cor[L_SUBFR]; + Word16 R_buf[2 * L_SUBFR - 1], *R; + Word16 dn2[L_SUBFR]; + Word16 ps2k, ps /* same format as dn[] */, ps2, alpk, alp = 0 /* Q13 and later Q_Rw*Q_signval=Q_cor*Q_signval */; + Word32 s; + Word16 codvec[NB_PULSE_MAX]; + Word16 pos_max[4]; + Word16 dn2_pos[8 * 4]; + UWord8 ipos[NB_PULSE_MAX]; + Word16 i, j, k, st, pos = 0; + Word16 scale; + Word16 sign_val_1, sign_val_2; + Word16 nb_pulse, nb_pulse_m2; + Word16 psk; + Word16 val, index, track; + + psk = ps = 0; /* to avoid compilation warnings */ + + + alp = config->alp; /* Q13 */ + move16(); + nb_pulse = config->nb_pulse; + move16(); + move16(); + nb_pulse_m2 = sub( nb_pulse, 2 ); + + /* Init to avoid crash when the search does not find a solution */ + FOR( k = 0; k < nb_pulse; k++ ) + { + codvec[k] = k; + move16(); + } + + scale = 0; + move16(); + s = L_mult0( Rw[0], Rw[0] ); + FOR( i = 1; i < L_SUBFR; i++ ) + { + s = L_mac0( s, Rw[i], Rw[i] ); + } + if ( s_and( (Word16) GE_16( nb_pulse, 9 ), (Word16) GT_32( s, 0x800000 ) ) ) + { + scale = -1; + move16(); + } + if ( s_and( (Word16) GE_16( nb_pulse, 13 ), (Word16) GT_32( s, 0x4000000 ) ) ) + { + scale = -2; + move16(); + } + IF( GE_16( nb_pulse, 18 ) ) + { + if ( GT_32( s, 0x200000 ) ) + { + scale = -1; + move16(); + } + if ( GT_32( s, 0x400000 ) ) + { + scale = -2; + move16(); + } + if ( GT_32( s, 0x4000000 ) ) + { + scale = -3; + move16(); + } + } + if ( s_and( (Word16) GE_16( nb_pulse, 28 ), (Word16) GT_32( s, 0x800000 ) ) ) + { + scale = -3; + move16(); + } + if ( s_and( (Word16) GE_16( nb_pulse, 36 ), (Word16) GT_32( s, 0x4000000 ) ) ) + { + scale = -4; + move16(); + } + + /* Set up autocorrelation vector */ + R = R_buf + L_SUBFR - 1; + Copy_Scale_sig( Rw, R, L_SUBFR, scale ); + FOR( k = 1; k < L_SUBFR; k++ ) + { + R[-k] = R[k]; + move16(); + } + + /* Sign value */ + sign_val_2 = 0x2000; + move16(); + if ( GE_16( nb_pulse, 24 ) ) + { + sign_val_2 = shr( sign_val_2, 1 ); + } + sign_val_1 = shr( sign_val_2, 1 ); + + /* + * Find sign for each pulse position. + */ + E_ACELP_pulsesign( cn, dn, dn2, sign, vec, alp, sign_val_2, L_SUBFR ); + + /* + * Select the most important 8 position per track according to dn2[]. + */ + E_ACELP_findcandidates( dn2, dn2_pos, pos_max ); + + /* + * Deep first search: + */ + + /* Ensure that in the loop below s > 0 in the first iteration, the actual values do not matter. */ + ps2k = -1; + move16(); + alpk = 1; + move16(); + + /* Number of iterations */ + FOR( k = 0; k < config->nbiter; k++ ) + { + E_ACELP_setup_pulse_search_pos( config, k, ipos ); + + /* index to first non-fixed position */ + pos = config->fixedpulses; + move16(); + + IF( config->fixedpulses == 0 ) /* 1100, 11, 1110, 1111, 2211 */ + { + ps = 0; + move16(); + alp = 0; + move16(); + set16_fx( cor, 0, L_SUBFR ); + } + ELSE + { + assert( config->fixedpulses == 2 || config->fixedpulses == 4 ); + + /* set fixed positions */ + FOR( i = 0; i < pos; ++i ) + { + ind[i] = pos_max[ipos[i]]; + move16(); + } + + /* multiplication of autocorrelation with signed fixed pulses */ + E_ACELP_update_cor( ind, config->fixedpulses, sign, R, NULL, cor ); + + /* normalisation contribution of fixed part */ + s = L_mult0( cor[ind[0]], sign[ind[0]] ); + ps = dn[ind[0]]; + move16(); + FOR( i = 1; i < pos; ++i ) + { + s = L_mac0( s, cor[ind[i]], sign[ind[i]] ); /*Q12+Q9+1=Q6 */ + ps = add( ps, dn[ind[i]] ); + } + alp = round_fx( s ); /*mac0 >>1 sign = 2*/ + } + + /* other stages of 2 pulses */ + st = 0; + move16(); + FOR( j = pos; j < nb_pulse; j += 2 ) + { + IF( GE_16( nb_pulse_m2, j ) ) /* pair-wise search */ + { + /* + * Calculate correlation of all possible positions + * of the next 2 pulses with previous fixed pulses. + * Each pulse can have 16 possible positions. + */ + + E_ACELP_2pulse_searchx( config->nbpos[st], ipos[j], ipos[j + 1], R, &ps, &alp, + &ind[j], &ind[j + 1], dn, dn2_pos, cor, sign, sign_val_2 ); + } + ELSE /* single pulse search */ + { + E_ACELP_1pulse_searchx( &ipos[j], R, &ps, &alp, + &ind[j], dn, cor, sign, sign_val_1 ); + } + + IF( GT_16( alp, ONE_IN_Q14 ) ) + { + alp = shr( alp, 1 ); + Scale_sig( cor, L_SUBFR, -1 ); + Scale_sig( R_buf, 2 * L_SUBFR - 1, -1 ); + Scale_sig( dn, 2 * L_SUBFR, -1 ); + } + + + st = add( st, 1 ); + } + + /* memorise the best codevector */ + /*ps2 = ps * ps; MULT(1);*/ + ps2 = mult( ps, ps ); + + /*s = (alpk * ps2) - (ps2k * alp); MULT(2);ADD(1);*/ + s = L_msu( L_mult( alpk, ps2 ), ps2k, alp ); + + IF( s > 0 ) + { + ps2k = ps2; + move16(); + psk = ps; + move16(); + alpk = alp; + move16(); + Copy( ind, codvec, nb_pulse ); + } + } + + + /* + * Store weighted energy of code, build the codeword and index of codevector. + */ + IF( EQ_16( element_mode, EVS_MONO ) ) + { + E_ACELP_build_code( nb_pulse, codvec, sign, code, ind ); + } + ELSE + { + /* Store weighted energy of code, build the codeword and index of codevector. */ + set16_fx( code, 0, L_SUBFR ); + set16_fx( ind, -1, NPMAXPT * 4 ); + + FOR( k = 0; k < config->nb_pulse; k++ ) + { + i = codvec[k]; /* read pulse position */ + move16(); + val = sign[i]; /* read sign */ + move16(); + + index = shr( i, 2 ); /* pos of pulse (0..15) */ + // track = i % 4; + track = s_and( i, 3 ); + IF( L_mult0( val, psk ) > 0 ) + { + code[i] = add( code[i], ONE_IN_Q9 /*1.0f*/ ); + codvec[k] = add( codvec[k], 2 * L_SUBFR ); + } + ELSE + { + code[i] = sub( code[i], ONE_IN_Q9 /*1.0f*/ ); + index = add( index, 16 ); + } + + i = imult1616( track, NPMAXPT ); + WHILE( ind[i] >= 0 ) + { + i++; + } + + ind[i] = index; + move16(); + } + } +} diff --git a/lib_enc/enc_gen_voic_fx.c b/lib_enc/enc_gen_voic_fx.c index b0a9264ae..4b4a4deac 100644 --- a/lib_enc/enc_gen_voic_fx.c +++ b/lib_enc/enc_gen_voic_fx.c @@ -2,9 +2,9 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ -#include "cnst.h" /* Common constants */ -//#include "prot_fx.h" /* Function prototypes */ +#include "options.h" /* Compilation switches */ +#include "cnst.h" /* Common constants */ +#include "prot.h" /* Function prototypes */ #include "rom_com_fx.h" /* Static table prototypes */ #include "rom_com.h" /* Static table prototypes */ #include "prot_fx.h" /* Function prototypes */ @@ -425,3 +425,382 @@ void encod_gen_voic_fx( } return; } + +void encod_gen_voic_ivas_fx( + Encoder_State *st_fx, /* i/o: state structure */ + const Word16 speech_fx[], /* i : input speech */ + const Word16 Aw_fx[], /* i : weighted A(z) unquantized for subframes */ + const Word16 Aq_fx[], /* i : 12k8 Lp coefficient */ + const Word16 Es_pred_fx, /* i : predicted scaled innov. energy */ + const Word16 *res_fx, /* i : residual signal */ + Word16 *syn_fx, /* i/o: core synthesis */ + Word16 *exc_fx, /* i/o: current non-enhanced excitation */ + Word16 *exc2_fx, /* i/o: current enhanced excitation */ + Word16 *pitch_buf_fx, /* i/o: floating pitch values for each subframe */ + Word16 *voice_factors_fx, /* o : voicing factors */ + Word16 *bwe_exc_fx, /* o : excitation for SWB TBE */ + Word16 *unbits_fx, /* i/o: number of unused bits */ + const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag */ + const Word16 tdm_Pri_pitch_buf[], /* i : primary channel pitch buffer */ + Word16 shift, + Word16 Q_new ) +{ + Word16 xn_fx[L_SUBFR]; /* Target vector for pitch search */ + Word16 xn2_fx[L_SUBFR]; /* Target vector for codebook search */ + Word16 cn_fx[L_SUBFR]; /* Target vector in residual domain */ + Word16 h1_fx[L_SUBFR + ( M + 1 )]; /* Impulse response vector */ + Word16 h2_fx[L_SUBFR + ( M + 1 )]; /* Impulse response vector */ + Word16 code_fx[L_SUBFR]; /* Fixed codebook excitation */ + Word16 y1_fx[L_SUBFR] = { 0 }; /* Filtered adaptive excitation */ + Word16 y2_fx[L_SUBFR]; /* Filtered algebraic excitation */ + Word16 gain_pit_fx = 0; /* Pitch gain */ + Word16 voice_fac_fx; /* Voicing factor */ + Word32 gain_code_fx = 0; /* Gain of code */ + Word16 gain_inov_fx = 0; /* inovation gain */ + Word32 gc_mem[NB_SUBFR - 1]; /* gain_code from previous subframes */ + Word16 gp_mem[NB_SUBFR - 1]; /* gain_pitch from previous subframes*/ + Word16 i, i_subfr_fx; /* tmp variables */ + Word16 T0_fx = 0, T0_frac_fx = 0; /* close loop integer pitch and fractional part */ + Word16 T0_min_fx, T0_max_fx; /* pitch variables */ + Word16 *pt_pitch_fx; /* pointer to floating pitch buffer */ + Word16 g_corr_fx[10]; /* ACELP correl, values + gain pitch */ + Word16 clip_gain_fx; /* LSF clip gain */ + const Word16 *p_Aw_fx, *p_Aq_fx; /* pointer to LP filter coeff. vector*/ + Word16 error_fx = 0; + Word16 gain_preQ_fx = 0; /* Gain of prequantizer excitation */ + Word16 code_preQ_fx[L_SUBFR]; /* Prequantizer excitation */ + Word16 unbits_PI_fx = 0; /* number of unused bits for PI */ + Word32 norm_gain_code_fx = 0; + Word16 pitch_limit_flag; + Word16 gcode16; + Word32 Ltmp; + Word32 Ltmp1; + Word32 Lgcode; + Word16 tmp1_fx; + Word16 shift_wsp; + Word16 harm_flag_acelp; + Word16 lp_select, lp_flag, L_frame; +#ifdef BASOP_NOGLOB_DECLARE_LOCAL + Flag Overflow = 0; +#endif + SC_VBR_ENC_HANDLE hSC_VBR = st_fx->hSC_VBR; + BSTR_ENC_HANDLE hBstr = st_fx->hBstr; + SP_MUS_CLAS_HANDLE hSpMusClas = st_fx->hSpMusClas; + LPD_state_HANDLE hLPDmem = st_fx->hLPDmem; + + /*------------------------------------------------------------------* + * Initializations + *------------------------------------------------------------------*/ + + gain_pit_fx = 0; + move16(); + gain_code_fx = L_deposit_l( 0 ); + gain_preQ_fx = 0; + move16(); + unbits_PI_fx = 0; + move16(); + error_fx = 0; + move16(); + L_frame = st_fx->L_frame; + move16(); + + + IF( EQ_16( L_frame, L_FRAME ) ) + { + T0_max_fx = PIT_MAX; + move16(); + T0_min_fx = PIT_MIN; + move16(); + } + ELSE /* L_frame == L_FRAME16k */ + { + T0_max_fx = PIT16k_MAX; + move16(); + T0_min_fx = PIT16k_MIN; + move16(); + } + lp_flag = st_fx->acelp_cfg.ltf_mode; + move16(); + + *unbits_fx = 0; + move16(); + + p_Aw_fx = Aw_fx; + p_Aq_fx = Aq_fx; + pt_pitch_fx = pitch_buf_fx; + gain_preQ_fx = 0; + move16(); + set16_fx( code_preQ_fx, 0, L_SUBFR ); + + shift_wsp = add( Q_new, shift ); + + /* set and write harmonicity flag */ + harm_flag_acelp = 0; + move16(); + test(); + test(); + IF( GE_32( st_fx->core_brate, MIN_BRATE_AVQ_EXC ) && LE_32( st_fx->core_brate, MAX_BRATE_AVQ_EXC_TD ) && EQ_16( st_fx->coder_type, GENERIC ) ) + { + if ( GT_16( st_fx->last_harm_flag_acelp, 2 ) ) + { + harm_flag_acelp = 1; + move16(); + } + + push_indice( hBstr, IND_HARM_FLAG_ACELP, harm_flag_acelp, 1 ); + } + + /*------------------------------------------------------------------* + * ACELP subframe loop + *------------------------------------------------------------------*/ + + FOR( i_subfr_fx = 0; i_subfr_fx < L_frame; i_subfr_fx += L_SUBFR ) + { + + /*----------------------------------------------------------------* + * Find the the excitation search target "xn" and innovation + * target in residual domain "cn" + * Compute impulse response, h1[], of weighted synthesis filter + *----------------------------------------------------------------*/ + + Copy( &res_fx[i_subfr_fx], &exc_fx[i_subfr_fx], L_SUBFR ); + + find_targets_fx( speech_fx, hLPDmem->mem_syn, i_subfr_fx, &hLPDmem->mem_w0, p_Aq_fx, + res_fx, L_SUBFR, p_Aw_fx, st_fx->preemph_fac, xn_fx, cn_fx, h1_fx ); + + Copy_Scale_sig( h1_fx, h2_fx, L_SUBFR, -2 ); + Scale_sig( h1_fx, L_SUBFR, add( 1, shift ) ); /* set h1[] in Q14 with scaling for convolution */ + + /* scaling of xn[] to limit dynamic at 12 bits */ + Scale_sig( xn_fx, L_SUBFR, shift ); + + *pt_pitch_fx = pit_encode_ivas_fx( hBstr, st_fx->acelp_cfg.pitch_bits, st_fx->core_brate, 0, L_frame, st_fx->coder_type, &pitch_limit_flag, i_subfr_fx, exc_fx, + L_SUBFR, st_fx->pitch, &T0_min_fx, &T0_max_fx, &T0_fx, &T0_frac_fx, h1_fx, xn_fx, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf ); + + // tbe_celp_exc(L_frame, i_subfr_fx, T0_fx, T0_frac_fx, &error_fx, bwe_exc_fx); + tbe_celp_exc_ivas( st_fx->element_mode, st_fx->idchan, L_frame, L_SUBFR, i_subfr_fx, T0_fx, T0_frac_fx, &error_fx, bwe_exc_fx, st_fx->tdm_LRTD_flag ); + + /*-----------------------------------------------------------------* + * Find adaptive exitation + *-----------------------------------------------------------------*/ + + pred_lt4( &exc_fx[i_subfr_fx], &exc_fx[i_subfr_fx], T0_fx, T0_frac_fx, L_SUBFR + 1, pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP ); + + /*-----------------------------------------------------------------* + * Gain clipping test to avoid unstable synthesis on frame erasure + *-----------------------------------------------------------------*/ + + clip_gain_fx = gp_clip_fx( st_fx->element_mode, st_fx->core_brate, st_fx->voicing_fx, i_subfr_fx, st_fx->coder_type, xn_fx, st_fx->clip_var_fx, sub( shift_wsp, 1 ) ); + + if ( EQ_16( st_fx->coder_type, INACTIVE ) ) + { + /* in case of AVQ inactive, limit the gain to 0.65 */ + clip_gain_fx = 2; + move16(); + } + + /*-----------------------------------------------------------------* + * LP filtering of the adaptive excitation, codebook target computation + *-----------------------------------------------------------------*/ + + lp_select = lp_filt_exc_enc_fx( MODE1, st_fx->coder_type, i_subfr_fx, exc_fx, h1_fx, + xn_fx, y1_fx, xn2_fx, L_SUBFR, L_frame, g_corr_fx, clip_gain_fx, &gain_pit_fx, &lp_flag ); + + IF( EQ_16( lp_flag, NORMAL_OPERATION ) ) + { + push_indice( hBstr, IND_LP_FILT_SELECT, lp_select, 1 ); + } + + /*st_fx->lowrate_pitchGain = 0.9f * st_fx->lowrate_pitchGain + 0.1f * gain_pit_fx;*/ +#ifdef BASOP_NOGLOB + hSpMusClas->lowrate_pitchGain = round_fx_o( L_mac_o( L_mult( 29491, hSpMusClas->lowrate_pitchGain ), 6554, gain_pit_fx, &Overflow ), &Overflow ); /*Q14*Q16(0.1) + Q15 -> Q15*/ +#else + hSpMusClas->lowrate_pitchGain = round_fx( L_mac( L_mult( 29491, hSpMusClas->lowrate_pitchGain ), 6554, gain_pit_fx ) ); /*Q14*Q16(0.1) + Q15 -> Q15*/ +#endif + + /*-----------------------------------------------------------------* + * Transform domain contribution encoding - active frames + *-----------------------------------------------------------------*/ + + test(); + IF( GE_32( st_fx->core_brate, MIN_BRATE_AVQ_EXC ) && NE_16( st_fx->coder_type, INACTIVE ) ) + { + transf_cdbk_enc_ivas_fx( st_fx, harm_flag_acelp, i_subfr_fx, cn_fx, exc_fx, p_Aq_fx, p_Aw_fx, h1_fx, xn_fx, + xn2_fx, y1_fx, y2_fx, Es_pred_fx, &gain_pit_fx, gain_code_fx, g_corr_fx, clip_gain_fx, &gain_preQ_fx, code_preQ_fx, unbits_fx, Q_new, shift ); + } + + /*-----------------------------------------------------------------* + * Innovation encoding + *-----------------------------------------------------------------*/ + + inov_encode_ivas_fx( st_fx, st_fx->core_brate, 0, L_frame, st_fx->last_L_frame, + st_fx->coder_type, st_fx->bwidth, st_fx->sharpFlag, i_subfr_fx, -1, p_Aq_fx, + gain_pit_fx, cn_fx, exc_fx, h2_fx, hLPDmem->tilt_code, *pt_pitch_fx, xn2_fx, code_fx, y2_fx, &unbits_PI_fx, L_SUBFR, shift, Q_new ); + + /*-----------------------------------------------------------------* + * Gain encoding + *-----------------------------------------------------------------*/ + + IF( LE_32( st_fx->core_brate, ACELP_8k00 ) ) + { + gain_enc_lbr_ivas_fx( hBstr, st_fx->acelp_cfg.gains_mode, st_fx->coder_type, i_subfr_fx, xn_fx, y1_fx, sub( shift_wsp, 1 ), y2_fx, code_fx, + &gain_pit_fx, &gain_code_fx, &gain_inov_fx, &norm_gain_code_fx, g_corr_fx, gc_mem, gp_mem, clip_gain_fx, L_SUBFR ); + } + ELSE IF( GT_32( st_fx->core_brate, ACELP_32k ) ) + { + gain_enc_SQ_ivas_fx( hBstr, st_fx->acelp_cfg.gains_mode, i_subfr_fx, xn_fx, y1_fx, y2_fx, code_fx, Es_pred_fx, + &gain_pit_fx, &gain_code_fx, &gain_inov_fx, &norm_gain_code_fx, g_corr_fx, clip_gain_fx, sub( shift_wsp, 1 ) ); + } + ELSE + { + gain_enc_mless_ivas_fx( hBstr, st_fx->acelp_cfg.gains_mode, st_fx->element_mode, L_frame, i_subfr_fx, -1, xn_fx, y1_fx, sub( shift_wsp, 1 ), y2_fx, code_fx, Es_pred_fx, + &gain_pit_fx, &gain_code_fx, &gain_inov_fx, &norm_gain_code_fx, g_corr_fx, clip_gain_fx ); + } + IF( st_fx->Opt_SC_VBR ) + { + if ( EQ_16( hSC_VBR->last_ppp_mode, 1 ) ) + { + /* SC-VBR - all other st->clip_var values will be updated even in a PPP frame */ + st_fx->clip_var_fx[1] = gain_pit_fx; + move16(); + } + } + gp_clip_test_gain_pit_fx( st_fx->element_mode, st_fx->core_brate, gain_pit_fx, st_fx->clip_var_fx ); + +#ifdef BASOP_NOGLOB + Lgcode = L_shl_o( gain_code_fx, Q_new, &Overflow ); /* scaled gain_code with Qnew -> Q16*/ + gcode16 = round_fx_o( Lgcode, &Overflow ); +#else + Lgcode = L_shl( gain_code_fx, Q_new ); /* scaled gain_code with Qnew -> Q16*/ + gcode16 = round_fx( Lgcode ); +#endif + + hLPDmem->tilt_code = Est_tilt2( &exc_fx[i_subfr_fx], gain_pit_fx, code_fx, Lgcode, &voice_fac_fx, shift ); + + /*-----------------------------------------------------------------* + * Transform domain contribution encoding - inactive frames + *-----------------------------------------------------------------*/ + + test(); + IF( GE_32( st_fx->total_brate, MAX_GSC_INACTIVE_BRATE ) && EQ_16( st_fx->coder_type, INACTIVE ) ) + { + transf_cdbk_enc_ivas_fx( st_fx, 0, i_subfr_fx, cn_fx, exc_fx, p_Aq_fx, p_Aw_fx, h1_fx, xn_fx, xn2_fx, y1_fx, y2_fx, + Es_pred_fx, &gain_pit_fx, gain_code_fx, g_corr_fx, clip_gain_fx, &gain_preQ_fx, code_preQ_fx, unbits_fx, Q_new, shift ); + } + + /*-----------------------------------------------------------------* + * Update memory of the weighting filter + *-----------------------------------------------------------------*/ + + /* st_fx->mem_w0 = xn[L_SUBFR-1] - (gain_pit*y1[L_SUBFR-1]) - (gain_code*y2[L_SUBFR-1]); */ + Ltmp = L_mult0( gcode16, y2_fx[L_SUBFR - 1] ); + Ltmp = L_shl( Ltmp, add( 5, shift ) ); // Q_new+14+shift + Ltmp = L_negate( Ltmp ); + Ltmp = L_mac( Ltmp, xn_fx[L_SUBFR - 1], 16384 ); // Q_new-1+15+shift + Ltmp = L_msu( Ltmp, y1_fx[L_SUBFR - 1], gain_pit_fx ); // Q_new-1+15+shift +#ifdef BASOP_NOGLOB + Ltmp = L_shl_sat( Ltmp, sub( 1, shift ) ); // Q_new+15 + hLPDmem->mem_w0 = round_fx_sat( Ltmp ); /*Q_new-1 */ +#else + Ltmp = L_shl( Ltmp, sub( 1, shift ) ); + hLPDmem->mem_w0 = round_fx( Ltmp ); /*Q_new-1 */ +#endif + IF( gain_preQ_fx != 0 ) + { + tmp1_fx = add( 16 - ( 2 + Q_AVQ_OUT_DEC + 1 ), Q_new ); + + FOR( i = 0; i < L_SUBFR; i++ ) + { +#ifdef BASOP_NOGLOB + /* Contribution from AVQ layer */ + Ltmp1 = L_mult_o( gain_preQ_fx, code_preQ_fx[i], &Overflow ); /* Q2 + Q6 -> Q9*/ + Ltmp1 = L_shl_o( Ltmp1, tmp1_fx, &Overflow ); /* Q16 + Q_exc */ + + /* Compute exc2 */ + Ltmp = L_shl_o( L_mult( gain_pit_fx, exc_fx[i + i_subfr_fx] ), 1, &Overflow ); + exc2_fx[i + i_subfr_fx] = round_fx_o( L_add_o( Ltmp, Ltmp1, &Overflow ), &Overflow ); +#else + /* Contribution from AVQ layer */ + Ltmp1 = L_mult( gain_preQ_fx, code_preQ_fx[i] ); /* Q2 + Q6 -> Q9*/ + Ltmp1 = L_shl( Ltmp1, tmp1_fx ); /* Q16 + Q_exc */ + + /* Compute exc2 */ + Ltmp = L_shl( L_mult( gain_pit_fx, exc_fx[i + i_subfr_fx] ), 1 ); + exc2_fx[i + i_subfr_fx] = round_fx( L_add( Ltmp, Ltmp1 ) ); +#endif + + /* code in Q9, gain_pit in Q14 */ + Ltmp = L_mult( gcode16, code_fx[i] ); + Ltmp = L_shl( Ltmp, 5 ); + Ltmp = L_mac( Ltmp, exc_fx[i + i_subfr_fx], gain_pit_fx ); +#ifdef BASOP_NOGLOB + Ltmp = L_shl_o( Ltmp, 1, &Overflow ); /* saturation can occur here */ + exc_fx[i + i_subfr_fx] = round_fx_o( L_add_o( Ltmp, Ltmp1, &Overflow ), &Overflow ); +#else + Ltmp = L_shl( Ltmp, 1 ); /* saturation can occur here */ + + exc_fx[i + i_subfr_fx] = round_fx( L_add( Ltmp, Ltmp1 ) ); +#endif + } + } + ELSE + { + /*-----------------------------------------------------------------* + * Construct adaptive part of the excitation + * Save the non-enhanced excitation for FEC_exc + *-----------------------------------------------------------------*/ + FOR( i = 0; i < L_SUBFR; i++ ) + { + /* code in Q9, gain_pit in Q14 */ + Ltmp = L_mult( gcode16, code_fx[i] ); +#ifdef BASOP_NOGLOB + Ltmp = L_shl_o( Ltmp, 5, &Overflow ); + Ltmp = L_mac_o( Ltmp, exc_fx[i + i_subfr_fx], gain_pit_fx, &Overflow ); + Ltmp = L_shl_o( Ltmp, 1, &Overflow ); /* saturation can occur here */ + exc_fx[i + i_subfr_fx] = round_fx_o( Ltmp, &Overflow ); +#else + Ltmp = L_shl( Ltmp, 5 ); + Ltmp = L_mac( Ltmp, exc_fx[i + i_subfr_fx], gain_pit_fx ); + Ltmp = L_shl( Ltmp, 1 ); /* saturation can occur here */ + exc_fx[i + i_subfr_fx] = round_fx( Ltmp ); +#endif + } + } + /*-----------------------------------------------------------------* + * Prepare TBE excitation + *-----------------------------------------------------------------*/ + + prep_tbe_exc_ivas_fx( L_frame, L_SUBFR, i_subfr_fx, gain_pit_fx, gain_code_fx, code_fx, voice_fac_fx, + &voice_factors_fx[i_subfr_fx / L_SUBFR], bwe_exc_fx, gain_preQ_fx, code_preQ_fx, Q_new, + T0_fx, T0_frac_fx, st_fx->coder_type, st_fx->core_brate, + st_fx->element_mode, st_fx->idchan, st_fx->hBWE_TD != NULL, st_fx->tdm_LRTD_flag ); + + /*-----------------------------------------------------------------* + * Synthesize speech to update mem_syn[]. + * Update A(z) filters + *-----------------------------------------------------------------*/ + + Syn_filt_s( 1, p_Aq_fx, M, &exc_fx[i_subfr_fx], &syn_fx[i_subfr_fx], L_SUBFR, hLPDmem->mem_syn, 1 ); + + p_Aw_fx += ( M + 1 ); + p_Aq_fx += ( M + 1 ); + pt_pitch_fx++; + } + + /* write reserved bits */ + WHILE( unbits_PI_fx > 0 ) + { + i = s_min( unbits_PI_fx, 16 ); + push_indice( hBstr, IND_UNUSED, 0, i ); + unbits_PI_fx -= i; + } + IF( st_fx->Opt_SC_VBR ) + { + /* SC-VBR */ + hSC_VBR->prev_ppp_gain_pit_fx = gain_pit_fx; + move16(); + hSC_VBR->prev_tilt_code_fx = hLPDmem->tilt_code; + move16(); + } + return; +} diff --git a/lib_enc/enc_higher_acelp_fx.c b/lib_enc/enc_higher_acelp_fx.c index a228b0b6d..da58fe721 100644 --- a/lib_enc/enc_higher_acelp_fx.c +++ b/lib_enc/enc_higher_acelp_fx.c @@ -2,9 +2,9 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ -#include "cnst.h" /* Common constants */ -//#include "prot_fx.h" /* Function prototypes */ +#include "options.h" /* Compilation switches */ +#include "cnst.h" /* Common constants */ +#include "prot.h" /* Function prototypes */ #include "rom_com_fx.h" /* Static table prototypes */ #include "rom_com.h" /* Static table prototypes */ #include "prot_fx.h" @@ -423,6 +423,420 @@ void transf_cdbk_enc_fx( return; } +void transf_cdbk_enc_ivas_fx( + Encoder_State *st_fx, /* i/o: encoder state structure */ + const Word16 harm_flag_acelp, /* i : harmonic flag for higher rates ACELP */ + const Word16 i_subfr, /* i : subframe index */ + Word16 cn[], /* i/o: target vector in residual domain */ + Word16 exc[], /* i/o: pointer to excitation signal frame */ + const Word16 *p_Aq, /* i : 12k8 Lp coefficient */ + const Word16 Ap[], /* i : weighted LP filter coefficients */ + const Word16 h1[], /* i : weighted filter input response */ + Word16 xn[], /* i/o: target vector */ + Word16 xn2[], /* i/o: target vector for innovation search */ + Word16 y1[], /* i/o: zero-memory filtered adaptive excitation */ + const Word16 y2[], /* i : zero-memory filtered innovative excitation */ + const Word16 Es_pred, /* i : predicited scaled innovation energy */ + Word16 *gain_pit, /* i/o: adaptive excitation gain */ + const Word32 gain_code, /* i : innovative excitation gain */ + Word16 g_corr[], /* o : ACELP correlation values */ + const Word16 clip_gain, /* i : adaptive gain clipping flag */ + Word16 *gain_preQ, /* o : prequantizer excitation gain */ + Word16 code_preQ[], /* o : prequantizer excitation */ + Word16 *unbits, /* o : number of AVQ unused bits */ + const Word16 Q_new, /* i : Current frame scaling */ + const Word16 shift /* i : shifting applied to y1, xn,... */ +) +{ + Word16 i, index, nBits, Nsv, Es_pred_loc; + Word16 x_in[L_SUBFR], x_tran[L_SUBFR], gcode16, stmp; + Word16 e_corr, m_corr, e_ener, m_ener, m_den, e_den; + Word16 x_norm[L_SUBFR + L_SUBFR / WIDTH_BAND]; + Word32 L_corr, L_ener, Ltmp, Ltmp1; + Word16 nq[L_SUBFR / WIDTH_BAND]; + Word32 out32[L_SUBFR]; + Word16 Qdct; + Word16 avq_bit_sFlag; + Word16 trgtSvPos; +#ifdef BASOP_NOGLOB_DECLARE_LOCAL + Flag Overflow = 0; +#endif + + avq_bit_sFlag = 0; + move16(); + if ( GT_16( st_fx->element_mode, EVS_MONO ) ) + { + avq_bit_sFlag = 1; + move16(); + } + + /*--------------------------------------------------------------* + * Set bit-allocation + *--------------------------------------------------------------*/ + + Nsv = 8; + move16(); + nBits = st_fx->acelp_cfg.AVQ_cdk_bits[shr( i_subfr, 6 )]; + move16(); + + /* increase # of AVQ allocated bits by unused bits from the previous subframe */ + nBits = add( nBits, *unbits ); + + /*--------------------------------------------------------------* + * Compute/Update target + * For inactive frame, find target in residual domain + * Deemphasis + *--------------------------------------------------------------*/ + IF( EQ_16( st_fx->coder_type, INACTIVE ) ) + { +#ifdef BASOP_NOGLOB + gcode16 = round_fx_o( L_shl_o( gain_code, Q_new, &Overflow ), &Overflow ); +#else + gcode16 = round_fx( L_shl( gain_code, Q_new ) ); +#endif + FOR( i = 0; i < L_SUBFR; i++ ) + { + /*x_tran[i] = xn[i] - *gain_pit * y1[i] - gain_code * y2[i];*/ + Ltmp = L_mult( gcode16, y2[i] ); + Ltmp = L_shl( Ltmp, add( 5, shift ) ); + Ltmp = L_negate( Ltmp ); + Ltmp = L_mac( Ltmp, xn[i], 16384 ); + Ltmp = L_msu( Ltmp, y1[i], *gain_pit ); +#ifdef BASOP_NOGLOB + Ltmp = L_shl_sat( Ltmp, sub( 1, shift ) ); + x_tran[i] = round_fx_sat( Ltmp ); /*Q_new-1 */ +#else + Ltmp = L_shl( Ltmp, sub( 1, shift ) ); + x_tran[i] = round_fx( Ltmp ); /*Q_new-1 */ +#endif + } + find_cn_fx( x_tran, Ap, p_Aq, x_in ); + } + ELSE + { + updt_tar_fx( cn, x_in, &exc[i_subfr], *gain_pit, L_SUBFR ); + } + Deemph2( x_in, FAC_PRE_AVQ_FX, L_SUBFR, &( st_fx->mem_deemp_preQ_fx ) ); + + /*--------------------------------------------------------------* + * DCT-II + *--------------------------------------------------------------*/ + + test(); + test(); + test(); + IF( NE_16( st_fx->coder_type, INACTIVE ) && LE_32( st_fx->core_brate, MAX_BRATE_AVQ_EXC_TD ) && GE_32( st_fx->core_brate, MIN_BRATE_AVQ_EXC ) && !harm_flag_acelp ) + { + Copy_Scale_sig( x_in, x_tran, L_SUBFR, -Q_MINUS + 1 ); /*Q_new-1 -> Q_new-4*/ + /*Copy( x_in, x_tran, L_SUBFR );*/ + Qdct = sub( Q_new, Q_MINUS ); + } + ELSE + { + Qdct = 0; + move16(); + edct2_fx( L_SUBFR, -1, x_in, out32, &Qdct, ip_edct2_64, w_edct2_64_fx ); + Qdct = negate( Qdct ); + Copy_Scale_sig_32_16( out32, x_tran, L_SUBFR, sub( Qdct, Q_MINUS - 1 ) ); /* Output in Q_new-4 */ + Qdct = sub( Q_new, Q_MINUS ); + } + + /*--------------------------------------------------------------* + * Split algebraic vector quantizer based on RE8 lattice + *--------------------------------------------------------------*/ + AVQ_cod_fx( x_tran, x_norm, nBits, Nsv, 0 ); + + /*--------------------------------------------------------------* + * Find prequantizer excitation gain + * Quantize the gain + *--------------------------------------------------------------*/ + L_corr = L_deposit_l( 0 ); + L_ener = L_deposit_l( 0 ); + FOR( i = 0; i < Nsv * 8; i++ ) + { + /*fcorr += fx_tran[i]*(float)ix_norm[i];*/ + /*fener += (float)ix_norm[i]*(float)ix_norm[i];*/ +#ifdef BASOP_NOGLOB + stmp = shl_sat( x_norm[i], Q_AVQ_OUT ); + L_corr = L_mac_sat( L_corr, x_tran[i], stmp ); + L_ener = L_mac_sat( L_ener, stmp, stmp ); +#else + stmp = shl( x_norm[i], Q_AVQ_OUT ); + L_corr = L_mac( L_corr, x_tran[i], stmp ); + L_ener = L_mac( L_ener, stmp, stmp ); +#endif + } + L_ener = L_max( L_ener, 1 ); + + /* No negative gains allowed in the quantizer*/ + L_corr = L_max( L_corr, 0 ); + + e_corr = norm_l( L_corr ); + m_corr = extract_h( L_shl( L_corr, e_corr ) ); + e_corr = sub( 30, add( e_corr, sub( Qdct, Q_AVQ_OUT ) ) ); + e_ener = norm_l( L_ener ); + m_ener = extract_h( L_shl( L_ener, e_ener ) ); + e_ener = sub( 30, e_ener ); + + IF( GT_16( m_corr, m_ener ) ) + { + m_corr = shr( m_corr, 1 ); + e_corr = add( e_corr, 1 ); + } + m_corr = div_s( m_corr, m_ener ); + e_corr = sub( e_corr, e_ener ); +#ifdef BASOP_NOGLOB + Ltmp = L_shl_sat( m_corr, s_min( add( e_corr, 1 ), 31 ) ); /* Lgain in Q16 */ +#else + Ltmp = L_shl( m_corr, s_min( add( e_corr, 1 ), 31 ) ); /* Lgain in Q16 */ +#endif + IF( EQ_16( st_fx->coder_type, INACTIVE ) ) + { + Ltmp1 = L_max( gain_code, 1 ); + e_den = norm_l( Ltmp1 ); +#ifdef BASOP_NOGLOB + m_den = extract_h( L_shl_sat( Ltmp1, e_den ) ); +#else + m_den = extract_h( L_shl( Ltmp1, e_den ) ); +#endif + /* ensure m_corr < m_den */ + test(); + IF( m_corr > 0 && m_den > 0 ) + { + m_corr = div_s( 16384, m_den ); + e_corr = sub( 14 + 4, e_den ); + Ltmp = L_shr( Mult_32_16( Ltmp, m_corr ), e_corr ); /*Q12*/ +#ifdef BASOP_NOGLOB + stmp = round_fx_o( L_shl_o( Ltmp, 16, &Overflow ), &Overflow ); +#else + stmp = round_fx( L_shl( Ltmp, 16 ) ); +#endif + } + ELSE + { + stmp = 0; + move16(); + } + IF( GT_32( st_fx->core_brate, 56000 ) ) + { + index = usquant_fx( stmp, &stmp, G_AVQ_MIN_INACT_64k_Q12, G_AVQ_DELTA_INACT_64k_Q12 >> 1, ( 1 << G_AVQ_BITS ) ); + } + ELSE IF( GT_32( st_fx->core_brate, 42000 ) ) + { + index = usquant_fx( stmp, &stmp, G_AVQ_MIN_INACT_48k_Q12, G_AVQ_DELTA_INACT_48k_Q12 >> 1, ( 1 << G_AVQ_BITS ) ); + } + ELSE + { + index = usquant_fx( stmp, &stmp, G_AVQ_MIN_INACT_Q12, G_AVQ_DELTA_INACT_Q12 >> 1, ( 1 << G_AVQ_BITS ) ); + } + Ltmp = Mult_32_16( gain_code, stmp ); /* Q16 * Q12 - 15 -> Q13*/ +#ifdef BASOP_NOGLOB + Ltmp = L_shl_sat( Ltmp, 5 ); /* Q13 -> Q18*/ + *gain_preQ = round_fx_sat( Ltmp ); /* Q2*/ +#else + Ltmp = L_shl( Ltmp, 5 ); /* Q13 -> Q18*/ + *gain_preQ = round_fx( Ltmp ); /* Q2*/ +#endif + } + ELSE + { + IF( Es_pred < 0 ) + { + Es_pred_loc = shr( negate( Es_pred ), 2 ); + } + ELSE + { + Es_pred_loc = Es_pred; + move16(); + } + + e_den = norm_s( Es_pred_loc ); + m_den = shl( Es_pred_loc, e_den ); + /* ensure m_corr < m_den */ + test(); + IF( m_corr > 0 && m_den > 0 ) + { + m_corr = div_s( 16384, m_den ); + e_corr = sub( 14 - 8, e_den ); + Ltmp = L_shr( Mult_32_16( Ltmp, m_corr ), e_corr ); + } + ELSE + { + Ltmp = L_deposit_l( 0 ); + } + test(); + IF( LE_32( st_fx->core_brate, 42000 ) && GT_32( st_fx->core_brate, ACELP_24k40 ) ) + { + index = gain_quant_fx( &Ltmp, &stmp, LG10_G_AVQ_MIN_32kbps_Q14, LG10_G_AVQ_MAX_Q13, G_AVQ_BITS, &e_den ); + } + ELSE + { + index = gain_quant_fx( &Ltmp, &stmp, LG10_G_AVQ_MIN_Q14, LG10_G_AVQ_MAX_Q13, G_AVQ_BITS, &e_den ); + } + Ltmp = L_mult( stmp, Es_pred_loc ); /* Q0*Q8 -> Q9*/ + Ltmp = L_shl( Ltmp, add( e_den, 9 ) ); /* Q18*/ + *gain_preQ = round_fx( Ltmp ); /* Q2*/ + } + push_indice( st_fx->hBstr, IND_AVQ_GAIN, index, G_AVQ_BITS ); + + /*--------------------------------------------------------------* + * Encode and multiplex subvectors into bit-stream + *--------------------------------------------------------------*/ + trgtSvPos = Nsv - 1; + move16(); + test(); + test(); + test(); + test(); + test(); + IF( avq_bit_sFlag && GT_16( nBits, 85 ) && !harm_flag_acelp && ( EQ_16( st_fx->coder_type, GENERIC ) || EQ_16( st_fx->coder_type, TRANSITION ) || EQ_16( st_fx->coder_type, INACTIVE ) ) ) + { + trgtSvPos = 2; + avq_bit_sFlag = 2; + move16(); + move16(); + } + + AVQ_encmux_ivas_fx( st_fx->hBstr, -1, x_norm, &nBits, Nsv, nq, avq_bit_sFlag, trgtSvPos ); + + /* save # of AVQ unused bits for next subframe */ + *unbits = nBits; + move16(); + + /* at the last subframe, write AVQ unused bits */ + test(); + test(); + IF( EQ_16( i_subfr, 4 * L_SUBFR ) && NE_16( st_fx->extl, SWB_BWE_HIGHRATE ) && NE_16( st_fx->extl, FB_BWE_HIGHRATE ) ) + { + WHILE( *unbits > 0 ) + { + i = s_min( *unbits, 16 ); + push_indice( st_fx->hBstr, IND_UNUSED, 0, i ); + *unbits -= i; + } + } + + /*--------------------------------------------------------------* + * DCT transform + *--------------------------------------------------------------*/ + + FOR( i = 0; i < Nsv * WIDTH_BAND; i++ ) + { +#ifdef BASOP_NOGLOB + x_tran[i] = shl_o( x_norm[i], Q_AVQ_OUT_DEC, &Overflow ); +#else + x_tran[i] = shl( x_norm[i], Q_AVQ_OUT_DEC ); +#endif + move16(); + } + set16_fx( x_tran + Nsv * WIDTH_BAND, 0, sub( L_SUBFR, i_mult2( WIDTH_BAND, Nsv ) ) ); + + test(); + test(); + test(); + IF( NE_16( st_fx->coder_type, INACTIVE ) && LE_32( st_fx->core_brate, MAX_BRATE_AVQ_EXC_TD ) && GE_32( st_fx->core_brate, MIN_BRATE_AVQ_EXC ) && !harm_flag_acelp ) + { + Copy( x_tran, code_preQ, L_SUBFR ); + } + ELSE + { + Qdct = 0; + move16(); + edct2_fx( L_SUBFR, 1, x_tran, out32, &Qdct, ip_edct2_64, w_edct2_64_fx ); + /*qdct = sub(Q_AVQ_OUT_DEC,qdct+Q_AVQ_OUT_DEC);*/ + Qdct = negate( Qdct ); + Copy_Scale_sig_32_16( out32, code_preQ, L_SUBFR, Qdct ); /* Output in Q_AVQ_OUT_DEC */ + /*qdct = Q_AVQ_OUT_DEC;*/ + } + + /*--------------------------------------------------------------* + * Preemphasise + *--------------------------------------------------------------*/ + /* in extreme cases at subframe boundaries, lower the preemphasis memory to avoid a saturation */ + test(); + if ( ( nq[7] != 0 ) && ( GT_16( sub( st_fx->last_nq_preQ, nq[0] ), 7 ) ) ) + { + /* *mem_preemp /= 16; */ + st_fx->mem_preemp_preQ_fx = shr( st_fx->mem_preemp_preQ_fx, 4 ); + move16(); + } + st_fx->last_nq_preQ = nq[7]; + move16(); +#if 1 // def IVAS_CODE + /* TD pre-quantizer: in extreme cases at subframe boundaries, lower the preemphasis memory to avoid a saturation */ + test(); + test(); + test(); + test(); + test(); + IF( GT_16( st_fx->element_mode, EVS_MONO ) && NE_16( st_fx->coder_type, INACTIVE ) && GE_32( st_fx->core_brate, MIN_BRATE_AVQ_EXC ) && LE_32( st_fx->core_brate, MAX_BRATE_AVQ_EXC_TD ) && !harm_flag_acelp && code_preQ[0] != 0 ) + { + // if ( (float) abs( st->last_code_preq ) > 16.0f * (float) fabs( code_preQ[0] ) ) + if ( GT_16( abs_s( st_fx->last_code_preq ), shl_sat( abs_s( code_preQ[0] ), 4 ) ) ) + { + st_fx->mem_preemp_preQ_fx = shr( st_fx->mem_preemp_preQ_fx, 4 ); + move16(); + } + // else if ( (float) abs( st->last_code_preq ) > 8.0f * (float) fabs( code_preQ[0] ) ) + if ( GT_16( abs_s( st_fx->last_code_preq ), shl_sat( abs_s( code_preQ[0] ), 3 ) ) ) + { + st_fx->mem_preemp_preQ_fx = shr( st_fx->mem_preemp_preQ_fx, 3 ); + move16(); + } + } + + // st->last_code_preq = (int16_t) code_preQ[L_SUBFR - 1]; + st_fx->last_code_preq = shr( code_preQ[L_SUBFR - 1], 9 ); // Q0 +#endif + PREEMPH_FX( code_preQ, FAC_PRE_AVQ_FX, L_SUBFR, &( st_fx->mem_preemp_preQ_fx ) ); + + /*--------------------------------------------------------------* + * For inactive segments + * - Zero-memory filtered pre-filter excitation + * - Update of targets and gain_pit + * For inactive segments + * - Update xn[L_subfr-1] for updating the memory of the weighting filter + *--------------------------------------------------------------*/ + + IF( EQ_16( st_fx->coder_type, INACTIVE ) ) + { + /*ftemp = fcode_preQ[0] *fh1[L_SUBFR-1];*/ + Ltmp = L_mult( code_preQ[0], h1[L_SUBFR - 1] ); /*1+14+shift + Q_AVQ_OUT */ + FOR( i = 1; i < L_SUBFR; i++ ) + { + /*ftemp += fcode_preQ[i] * fh1[L_SUBFR-1-i];*/ + Ltmp = L_mac( Ltmp, code_preQ[i], h1[L_SUBFR - 1 - i] ); + } + /*fxn[L_SUBFR-1] -= *fgain_preQ * ftemp;*/ + Ltmp = L_shr( Mult_32_16( Ltmp, *gain_preQ ), sub( add( Q_AVQ_OUT_DEC, 2 ), Q_new ) ); /* (2 + 1 + 14 +shift+Q_AVQ_OUT)-(Q_AVQ_OUT+2-Q_new) = 15 + Q_new + shift */ + xn[L_SUBFR - 1] = round_fx( L_sub( L_mult( xn[L_SUBFR - 1], 32767 ), Ltmp ) ); /* -> Q_new + shift -1 */ + } + ELSE + { + conv_fx( code_preQ, h1, x_tran, L_SUBFR ); + updt_tar_HR_fx( cn, cn, code_preQ, *gain_preQ, sub( Q_new, add( -15 + 2, Q_AVQ_OUT_DEC ) ), L_SUBFR ); + + updt_tar_HR_fx( xn, xn, x_tran, *gain_preQ, sub( Q_new, add( -15 + 2, Q_AVQ_OUT_DEC ) ), L_SUBFR ); +#ifdef BASOP_NOGLOB + *gain_pit = corr_xy1_fx( xn, y1, g_corr, L_SUBFR, 0, &Overflow ); +#else + *gain_pit = corr_xy1_fx( xn, y1, g_corr, L_SUBFR, 0 ); +#endif + /* clip gain if necessary to avoid problems at decoder */ + test(); + if ( EQ_16( clip_gain, 1 ) && GT_16( *gain_pit, 15565 ) ) + { + *gain_pit = 15565; + move16(); + } + updt_tar_fx( xn, xn2, y1, *gain_pit, L_SUBFR ); + } + + st_fx->use_acelp_preq = 1; + move16(); + + return; +} /*-------------------------------------------------------------------* * Find target in residual domain - cn[] *-------------------------------------------------------------------*/ diff --git a/lib_enc/enc_pit_exc_fx.c b/lib_enc/enc_pit_exc_fx.c index 6385420fe..03b02fe96 100644 --- a/lib_enc/enc_pit_exc_fx.c +++ b/lib_enc/enc_pit_exc_fx.c @@ -2,11 +2,11 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ -#include "cnst.h" /* Common constants */ -#include "rom_com_fx.h" /* Static table prototypes */ -#include "rom_com.h" /* Static table prototypes */ -//#include "prot_fx.h" /* Function prototypes */ +#include "options.h" /* Compilation switches */ +#include "cnst.h" /* Common constants */ +#include "rom_com_fx.h" /* Static table prototypes */ +#include "rom_com.h" /* Static table prototypes */ +#include "prot.h" /* Function prototypes */ #include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ @@ -554,6 +554,522 @@ void enc_pit_exc_fx( } } +#ifdef BASOP_NOGLOB + cum_gpit = shl_o( cum_gpit, 1, &Overflow ); /*Q15*/ +#else /* BASOP_NOGLOB */ + cum_gpit = shl( cum_gpit, 1 ); /*Q15*/ +#endif + *gpit = round_fx( L_mac( L_mult( 3277, *gpit ), 29491, cum_gpit ) ); /*Q15*/ +} + +void enc_pit_exc_ivas_fx( + Encoder_State *st_fx, /* i/o: State structure */ + const Word16 *speech, /* i : Input speech */ + const Word16 Aw[], /* i : weighted A(z) unquantized for subframes */ + const Word16 Aq[], /* i : 12k8 Lp coefficient */ + const Word16 Es_pred, /* i : predicted scaled innov. energy */ + const Word16 *res, /* i : residual signal */ + Word16 *synth, /* i/o: core synthesis */ + Word16 *exc, /* i/o: current non-enhanced excitation */ + Word16 *T0, /* i/o: close loop integer pitch */ + Word16 *T0_frac, /* i/o: close-loop pitch period - fractional part */ + Word16 *pitch_buf, /* i/o: Fractionnal per subframe pitch */ + const Word16 nb_subfr, /* i : Number of subframe considered */ + Word16 *gpit, /* o : pitch mean gpit */ + Word16 *saved_bit_pos, /* o : saved position in the bitstream before pitch contribution */ + const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag */ + const Word16 tdm_Pri_pitch_buf[], /* i : primary channel pitch buffer */ + Word16 Q_new, + Word16 shift ) +{ + Word16 xn[PIT_EXC_L_SUBFR]; /* Target vector for pitch search */ + Word16 xn2[PIT_EXC_L_SUBFR]; /* Target vector for codebook search */ + Word16 h1[PIT_EXC_L_SUBFR + ( M + 1 )]; /* Impulse response vector */ + Word16 y1[PIT_EXC_L_SUBFR]; /* Filtered adaptive excitation */ + Word16 code[2 * L_SUBFR]; /* Fixed codebook excitation */ + Word16 y2[2 * L_SUBFR]; /* Filtered algebraic excitation */ + Word16 voice_fac; /* Voicing factor */ + Word32 gain_code; /* Gain of code */ + Word16 gain_inov; /* inovation gain */ + Word16 gain_pit; /* Pitch gain */ + Word16 pit_idx, i_subfr; /* tmp variables */ + Word16 T0_min, T0_max; /* pitch variables */ + Word16 g_corr[10]; /* ACELP correlation values + gain pitch */ + Word16 clip_gain, i; /* LSF clip gain and LP flag */ + const Word16 *p_Aw, *p_Aq; /* pointer to LP filter coefficient vector */ + Word16 cn1[PIT_EXC_L_SUBFR], *cn; /* (Used only when L_subfr == L_SUBFR) Target vector in residual domain */ + Word16 *pt_pitch; /* pointer to floating pitch */ + Word16 L_subfr; + Word16 cum_gpit, gpit_tmp; + Word32 Local_BR, Pitch_BR; + Word16 Pitch_CT, unbits_PI = 0; /* saved bits for PI */ + Word32 norm_gain_code; + Word16 pitch_limit_flag; + Word16 h2[PIT_EXC_L_SUBFR + ( M + 1 )]; /* Impulse response vector */ + Word32 Ltmp; + Word32 Lgcode; + Word16 gcode16; + Word16 shift_wsp; + Word16 lp_select, lp_flag; + Word16 use_fcb; + Word32 gc_mem[NB_SUBFR - 1]; /* gain_code from previous subframes */ + Word16 gp_mem[NB_SUBFR - 1]; /* gain_pitch from previous subframes*/ + SP_MUS_CLAS_HANDLE hSpMusClas = st_fx->hSpMusClas; + BSTR_ENC_HANDLE hBstr = st_fx->hBstr; + GSC_ENC_HANDLE hGSCEnc = st_fx->hGSCEnc; + LPD_state_HANDLE hLPDmem = st_fx->hLPDmem; +#ifdef BASOP_NOGLOB_DECLARE_LOCAL + Flag Overflow = 0; +#endif + + /*------------------------------------------------------------------* + * Initialization + *------------------------------------------------------------------*/ + + pitch_limit_flag = 1; + move16(); /* always extended pitch Q range */ + use_fcb = 0; + unbits_PI = 0; + test(); + test(); + Pitch_CT = GENERIC; + move16(); + + IF( st_fx->GSC_IVAS_mode > 0 && ( st_fx->GSC_noisy_speech || GT_32( st_fx->core_brate, GSC_H_RATE_STG ) ) ) + { + Local_BR = ACELP_8k00; + Pitch_BR = ACELP_8k00; + move32(); + move32(); + IF( EQ_16( st_fx->L_frame, L_FRAME16k ) ) + { + Local_BR = ACELP_14k80; + move32(); + if ( st_fx->GSC_IVAS_mode > 0 ) + { + Local_BR = ACELP_9k60; + move32(); + } + Pitch_BR = st_fx->core_brate; + move32(); + } + } + ELSE IF( st_fx->GSC_noisy_speech ) + { + Local_BR = ACELP_7k20; + move32(); + Pitch_BR = ACELP_7k20; + move32(); + Pitch_CT = GENERIC; + move16(); + if ( EQ_16( st_fx->L_frame, L_FRAME16k ) ) + { + Pitch_BR = st_fx->core_brate; + move32(); + } + } + ELSE + { + + Local_BR = ACELP_7k20; + move32(); + Pitch_BR = st_fx->core_brate; + move32(); + Pitch_CT = AUDIO; + move16(); + + if ( EQ_16( st_fx->L_frame, L_FRAME16k ) ) + { + Local_BR = ACELP_13k20; + move32(); + Pitch_CT = GENERIC; + move16(); + } + } + gain_code = 0; + move16(); + + IF( EQ_16( st_fx->L_frame, L_FRAME16k ) ) + { + T0_max = PIT16k_MAX; + T0_min = PIT16k_MIN; + } + ELSE + { + T0_max = PIT_MAX; + move16(); + T0_min = PIT_MIN; + move16(); + } + cum_gpit = 0; + move16(); + + L_subfr = mult_r( st_fx->L_frame, div_s( 1, nb_subfr ) ); + + lp_flag = st_fx->acelp_cfg.ltf_mode; + + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + IF( ( ( GE_32( st_fx->core_brate, MIN_RATE_FCB ) || ( EQ_16( st_fx->GSC_noisy_speech, 1 ) && + ( ( EQ_16( st_fx->L_frame, L_FRAME ) && GE_32( st_fx->core_brate, ACELP_13k20 ) ) || + ( EQ_16( st_fx->L_frame, L_FRAME16k ) && GE_32( st_fx->core_brate, GSC_H_RATE_STG ) ) || st_fx->GSC_IVAS_mode == 0 ) ) ) && + EQ_16( L_subfr, L_SUBFR ) ) ) + { + use_fcb = 1; + move16(); + } + ELSE IF( st_fx->GSC_IVAS_mode > 0 && EQ_16( L_subfr, 2 * L_SUBFR ) && LT_16( st_fx->GSC_IVAS_mode, 3 ) ) + { + use_fcb = 2; + st_fx->acelp_cfg.fcb_mode = 1; + move16(); + move16(); + set16_fx( st_fx->acelp_cfg.gains_mode, 6, NB_SUBFR ); + set16_fx( st_fx->acelp_cfg.pitch_bits, 9, NB_SUBFR ); + set16_fx( st_fx->acelp_cfg.fixed_cdk_index, 14, NB_SUBFR16k ); + } + + *saved_bit_pos = st_fx->next_bit_pos_fx; + move16(); + + /*------------------------------------------------------------------* + * ACELP subframe loop + *------------------------------------------------------------------*/ + cn = NULL; + if ( EQ_16( L_subfr, L_SUBFR ) || EQ_16( L_subfr, L_SUBFR * 2 ) ) + { + cn = cn1; + move16(); + } + p_Aw = Aw; + + p_Aq = Aq; + pt_pitch = pitch_buf; /* pointer to the pitch buffer */ + shift_wsp = add( Q_new, shift ); + FOR( i_subfr = 0; i_subfr < st_fx->L_frame; i_subfr += L_subfr ) + { + + /*----------------------------------------------------------------* + * Bandwidth expansion of A(z) filter coefficients + * Find the the excitation search target "xn" and innovation + * target in residual domain "cn" + * Compute impulse response, h1[], of weighted synthesis filter + *----------------------------------------------------------------*/ + Copy( &res[i_subfr], &exc[i_subfr], L_subfr ); + /* condition on target (compared to float) has been put outside the loop */ +#if 1 // ndef BUG_FIX + find_targets_fx( speech, hLPDmem->mem_syn, i_subfr, &hLPDmem->mem_w0, p_Aq, + res, L_subfr, p_Aw, st_fx->preemph_fac, xn, cn, h1 ); +#else + find_targets_fx( speech, hGSCEnc->mem_syn_tmp_fx, i_subfr, &hLPDmem->mem_w0, p_Aq, /*_DIFF_FLOAT_FIX_ --> Here I think mem_syn_tmp_fx should be used */ + res, L_subfr, p_Aw, st_fx->preemph_fac, xn, cn, h1 ); +#endif + Copy_Scale_sig( h1, h2, L_subfr, -2 ); + Scale_sig( h1, L_subfr, add( 1, shift ) ); /* set h1[] in Q14 with scaling for convolution */ + + /* scaling of xn[] to limit dynamic at 12 bits */ + Scale_sig( xn, L_subfr, shift ); + + /*----------------------------------------------------------------* + * Close-loop pitch search and quantization + * Adaptive exc. construction + *----------------------------------------------------------------*/ + *pt_pitch = pit_encode_ivas_fx( hBstr, st_fx->acelp_cfg.pitch_bits, Pitch_BR, 0, st_fx->L_frame, Pitch_CT, &pitch_limit_flag, i_subfr, exc, + L_subfr, st_fx->pitch, &T0_min, &T0_max, T0, T0_frac, h1, xn, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf ); + /*-----------------------------------------------------------------* + * Find adaptive exitation + *-----------------------------------------------------------------*/ + + pred_lt4( &exc[i_subfr], &exc[i_subfr], *T0, *T0_frac, L_subfr + 1, pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP ); + /*-----------------------------------------------------------------* + * Gain clipping test to avoid unstable synthesis on frame erasure + * or in case of floating point encoder & fixed p. decoder + *-----------------------------------------------------------------*/ + + clip_gain = gp_clip_fx( st_fx->element_mode, st_fx->core_brate, st_fx->voicing_fx, i_subfr, AUDIO, xn, st_fx->clip_var_fx, sub( shift_wsp, 1 ) ); + + /*-----------------------------------------------------------------* + * Codebook target computation + * (No LP filtering of the adaptive excitation) + *-----------------------------------------------------------------*/ + + lp_select = lp_filt_exc_enc_fx( MODE1, AUDIO, i_subfr, exc, h1, + xn, y1, xn2, L_subfr, st_fx->L_frame, g_corr, clip_gain, &gain_pit, &lp_flag ); + + IF( EQ_16( lp_flag, NORMAL_OPERATION ) ) + { + push_indice( hBstr, IND_LP_FILT_SELECT, lp_select, 1 ); + } + + /*st_fx->lowrate_pitchGain = 0.9f * st_fx->lowrate_pitchGain + 0.1f * gain_pit;*/ +#ifdef BASOP_NOGLOB + hSpMusClas->lowrate_pitchGain = round_fx_o( L_mac_o( L_mult( 29491, hSpMusClas->lowrate_pitchGain ), 6554, gain_pit, &Overflow ), &Overflow ); /*Q14*Q16(0.1) + Q15 -> Q15*/ +#else + hSpMusClas->lowrate_pitchGain = round_fx( L_mac( L_mult( 29491, hSpMusClas->lowrate_pitchGain ), 6554, gain_pit ) ); /*Q14*Q16(0.1) + Q15 -> Q15*/ +#endif + + gpit_tmp = gain_pit; + move16(); /*Q14*/ + test(); + IF( use_fcb > 0 ) + { + /* h2 in Q12 for codebook search */ + /* h1 has been scaled with 1 + shift so we need to remove 2 and (1+shift) = -3 - shift*/ + Copy_Scale_sig( h1, h2, L_subfr, sub( -2 - 1, shift ) ); + } + + IF( use_fcb == 0 ) + { + IF( GE_32( st_fx->core_brate, MIN_RATE_FCB ) ) + { + pit_idx = vquant_fx( &gain_pit, mean_gp_fx, &gain_pit, dic_gp_fx, 1, 32 ); + push_indice( hBstr, IND_PIT_IDX, pit_idx, 5 ); + } + ELSE + { + pit_idx = vquant_fx( &gain_pit, mean_gp_fx, &gain_pit, dic_gp_fx, 1, 16 ); + push_indice( hBstr, IND_PIT_IDX, pit_idx, 4 ); + } + } + else if ( use_fcb == 2 ) + { + /*-----------------------------------------------------------------* + * Innovation encoding + *-----------------------------------------------------------------*/ + + inov_encode_ivas_fx( st_fx, st_fx->core_brate, 0, st_fx->L_frame, st_fx->last_L_frame, GENERIC, st_fx->bwidth, 0, i_subfr, -1, p_Aq, + gain_pit, cn, exc, h2, st_fx->hLPDmem->tilt_code, *pt_pitch, xn2, code, y2, &unbits_PI, 2 * L_SUBFR, shift, Q_new ); + // PMT("code to be validated") + /*-----------------------------------------------------------------* + * Gain encoding + *-----------------------------------------------------------------*/ + + gain_enc_lbr_ivas_fx( st_fx->hBstr, st_fx->acelp_cfg.gains_mode, GENERIC, i_subfr, xn, y1, sub( shift_wsp, 1 ), y2, code, &gain_pit, &gain_code, &gain_inov, &norm_gain_code, g_corr, gc_mem, gp_mem, clip_gain, 2 * L_SUBFR ); + } + ELSE + { + /*-----------------------------------------------------------------* + * Innovation & gain encoding + *-----------------------------------------------------------------*/ + + inov_encode_ivas_fx( st_fx, Local_BR, 0, st_fx->L_frame, st_fx->last_L_frame, LOCAL_CT, WB, 1, i_subfr, -1, p_Aq, + gain_pit, cn, exc, h2, hLPDmem->tilt_code, *pt_pitch, xn2, code, y2, &unbits_PI, L_SUBFR, shift, Q_new ); + /*-----------------------------------------------------------------* + * Gain encoding + *-----------------------------------------------------------------*/ + gain_enc_mless_ivas_fx( hBstr, st_fx->acelp_cfg.gains_mode, st_fx->element_mode, L_FRAME, i_subfr, -1, xn, y1, sub( shift_wsp, 1 ), y2, code, Es_pred, + &gain_pit, &gain_code, &gain_inov, &norm_gain_code, g_corr, clip_gain ); + } + gp_clip_test_gain_pit_fx( st_fx->element_mode, st_fx->core_brate, gain_pit, st_fx->clip_var_fx ); + +#ifdef BASOP_NOGLOB + Lgcode = L_shl_sat( gain_code, Q_new ); /* scaled gain_code with Qnew -> Q16*/ + gcode16 = round_fx_sat( Lgcode ); +#else + Lgcode = L_shl( gain_code, Q_new ); /* scaled gain_code with Qnew -> Q16*/ + gcode16 = round_fx( Lgcode ); +#endif + IF( use_fcb != 0 ) + { + hLPDmem->tilt_code = Est_tilt2( &exc[i_subfr], gain_pit, code, Lgcode, &voice_fac, shift ); + move16(); + } + ELSE + { + hLPDmem->tilt_code = 0; + move16(); + } + /*-----------------------------------------------------------------* + * Update memory of the weighting filter + *-----------------------------------------------------------------*/ + IF( use_fcb != 0 ) + { + Ltmp = L_mult0( gcode16, y2[L_subfr - 1] ); +#ifdef BASOP_NOGLOB + Ltmp = L_shl_o( Ltmp, add( 5, shift ), &Overflow ); // Q_new+14+shift + Ltmp = L_negate( Ltmp ); + Ltmp = L_mac_o( Ltmp, xn[L_subfr - 1], 16384, &Overflow ); // Q_new-1+15+shift + Ltmp = L_msu_o( Ltmp, y1[L_subfr - 1], gain_pit, &Overflow ); // Q_new-1+15+shift + Ltmp = L_shl_o( Ltmp, sub( 1, shift ), &Overflow ); // Q_new+15 + hLPDmem->mem_w0 = round_fx_o( Ltmp, &Overflow ); /*Q_new-1 */ +#else + Ltmp = L_mult( gcode16, y2[L_subfr - 1] ); + Ltmp = L_shl( Ltmp, add( 5, shift ) ); + Ltmp = L_negate( Ltmp ); + Ltmp = L_mac( Ltmp, xn[L_subfr - 1], 16384 ); + Ltmp = L_msu( Ltmp, y1[L_subfr - 1], gain_pit ); + Ltmp = L_shl( Ltmp, sub( 1, shift ) ); + hLPDmem->mem_w0 = round_fx( Ltmp ); /*Q_new-1 */ +#endif + } + ELSE + { + Ltmp = L_mult( xn[L_subfr - 1], 16384 ); +#ifdef BASOP_NOGLOB + Ltmp = L_msu_sat( Ltmp, y1[L_subfr - 1], gain_pit ); + Ltmp = L_shl_sat( Ltmp, sub( 1, shift ) ); + hLPDmem->mem_w0 = round_fx_sat( Ltmp ); /*Q_new-1 */ +#else + Ltmp = L_msu( Ltmp, y1[L_subfr - 1], gain_pit ); + Ltmp = L_shl( Ltmp, sub( 1, shift ) ); + hLPDmem->mem_w0 = round_fx( Ltmp ); /*Q_new-1 */ +#endif + } + + /*-----------------------------------------------------------------* + * Construct adaptive part of the excitation + * Save the non-enhanced excitation for FEC_exc + *-----------------------------------------------------------------*/ + IF( use_fcb != 0 ) + { + FOR( i = 0; i < L_subfr; i++ ) + { + /* code in Q9, gain_pit in Q14 */ + Ltmp = L_mult( gcode16, code[i] ); +#ifdef BASOP_NOGLOB + Ltmp = L_shl_o( Ltmp, 5, &Overflow ); + Ltmp = L_mac_o( Ltmp, exc[i + i_subfr], gain_pit, &Overflow ); + Ltmp = L_shl_o( Ltmp, 1, &Overflow ); /* saturation can occur here */ + exc[i + i_subfr] = round_fx_o( Ltmp, &Overflow ); +#else + Ltmp = L_mult( gcode16, code[i] ); + Ltmp = L_shl( Ltmp, 5 ); + Ltmp = L_mac( Ltmp, exc[i + i_subfr], gain_pit ); + Ltmp = L_shl( Ltmp, 1 ); /* saturation can occur here */ + exc[i + i_subfr] = round_fx( Ltmp ); +#endif + } + } + ELSE + { + FOR( i = 0; i < L_subfr; i++ ) + { + + Ltmp = L_mult( exc[i + i_subfr], gain_pit ); +#ifdef BASOP_NOGLOB + Ltmp = L_shl_sat( Ltmp, 1 ); /* saturation can occur here */ + exc[i + i_subfr] = round_fx_sat( Ltmp ); +#else + Ltmp = L_shl( Ltmp, 1 ); /* saturation can occur here */ + exc[i + i_subfr] = round_fx( Ltmp ); +#endif + } + } + + /*-----------------------------------------------------------------* + * Synthesize speech to update mem_syn[]. + * Update A(z) filters + *-----------------------------------------------------------------*/ + + Syn_filt_s( 1, p_Aq, M, &exc[i_subfr], &synth[i_subfr], L_subfr, hGSCEnc->mem_syn_tmp_fx, 1 ); + + IF( EQ_16( L_subfr, 5 * L_SUBFR ) ) + { + cum_gpit = gpit_tmp; + move16(); + pt_pitch++; + *pt_pitch = *( pt_pitch - 1 ); + move16(); + pt_pitch++; + *pt_pitch = *( pt_pitch - 1 ); + move16(); + pt_pitch++; + *pt_pitch = *( pt_pitch - 1 ); + move16(); + pt_pitch++; + *pt_pitch = *( pt_pitch - 1 ); + move16(); + pt_pitch++; + + p_Aw += 5 * ( M + 1 ); + p_Aq += 5 * ( M + 1 ); + } + ELSE IF( EQ_16( L_subfr, 5 * L_SUBFR / 2 ) ) + { + IF( i_subfr == 0 ) + { + cum_gpit = mult_r( gpit_tmp, 13107 ); /* .4f*/ + pt_pitch++; + *pt_pitch = *( pt_pitch - 1 ); + move16(); + pt_pitch++; + p_Aw += 2 * ( M + 1 ); + p_Aq += 2 * ( M + 1 ); + } + ELSE + { + cum_gpit = add( cum_gpit, mult_r( gpit_tmp, 19660 ) ); /*0.6*/ + pt_pitch++; + *pt_pitch = *( pt_pitch - 1 ); + move16(); + pt_pitch++; + *pt_pitch = *( pt_pitch - 1 ); + move16(); + pt_pitch++; + p_Aw += 3 * ( M + 1 ); + p_Aq += 3 * ( M + 1 ); + } + } + ELSE IF( EQ_16( L_subfr, 2 * L_SUBFR ) ) + { + IF( i_subfr == 0 ) + { + cum_gpit = mult_r( gpit_tmp, 16384 ); + } + ELSE + { + cum_gpit = add( cum_gpit, mult_r( gpit_tmp, 16384 ) ); + } + p_Aw += 2 * ( M + 1 ); + move16(); + p_Aq += 2 * ( M + 1 ); + move16(); + pt_pitch++; + *pt_pitch = *( pt_pitch - 1 ); + move16(); + pt_pitch++; + } + ELSE IF( EQ_16( L_subfr, 4 * L_SUBFR ) ) + { + cum_gpit = gpit_tmp; + move16(); + + pt_pitch++; + *pt_pitch = *( pt_pitch - 1 ); + move16(); + pt_pitch++; + *pt_pitch = *( pt_pitch - 1 ); + move16(); + pt_pitch++; + *pt_pitch = *( pt_pitch - 1 ); + pt_pitch++; + p_Aw += 4 * ( M + 1 ); + p_Aq += 4 * ( M + 1 ); + } + ELSE + { + IF( i_subfr == 0 ) + { + + cum_gpit = mult_r( gpit_tmp, 8192 ); + } + ELSE + { + cum_gpit = add( cum_gpit, mult_r( gpit_tmp, 8192 ) ); + } + + pt_pitch++; + p_Aw += ( M + 1 ); + p_Aq += ( M + 1 ); + } + } + #ifdef BASOP_NOGLOB cum_gpit = shl_o( cum_gpit, 1, &Overflow ); /*Q15*/ #else /* BASOP_NOGLOB */ diff --git a/lib_enc/enc_tran_fx.c b/lib_enc/enc_tran_fx.c index d3127ccda..395a73d20 100644 --- a/lib_enc/enc_tran_fx.c +++ b/lib_enc/enc_tran_fx.c @@ -7,6 +7,7 @@ //#include "prot_fx.h" /* Function prototypes */ #include "rom_com_fx.h" /* Static table prototypes */ #include "rom_com.h" /* Static table prototypes */ +#include "prot.h" /* Function prototypes */ #include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ @@ -446,3 +447,407 @@ Word16 encod_tran_fx( return tc_subfr; } + +Word16 encod_tran_ivas_fx( + Encoder_State *st_fx, /* i/o: state structure */ + const Word16 speech_fx[], /* i : input speech */ + const Word16 Aw_fx[], /* i : weighted A(z) unquantized for subframes */ + const Word16 Aq_fx[], /* i : 12k8 Lp coefficient */ + const Word16 Es_pred_fx, /* i : predicted scaled innov. energy */ + const Word16 *res_fx, /* i : residual signal */ + Word16 *syn_fx, /* i/o: core synthesis */ + Word16 *exc_fx, /* i/o: current non-enhanced excitation */ + Word16 *exc2_fx, /* i/o: current enhanced excitation */ + Word16 *pitch_buf_fx, /* i/o: floating pitch values for each subframe */ + Word16 *voice_factors, /* o : voicing factors */ + Word16 *bwe_exc_fx, /* i/o: excitation for SWB TBE */ + Word16 tc_subfr, /* i/o: TC subframe classification */ + Word16 position, /* i : maximum of residual signal index */ + Word16 *unbits, /* i/o: number of unused bits */ + const Word16 shift, /* i : Scaling to get 12 bits */ + const Word16 Q_new /* i : Input scaling */ +) +{ + Word16 xn[L_SUBFR]; /* Target vector for pitch search */ + Word16 xn2[L_SUBFR]; /* Target vector for codebook search */ + Word16 cn[L_SUBFR]; /* Target vector in residual domain */ + Word16 h1[L_SUBFR + ( M + 1 )]; /* Impulse response vector */ + Word16 h2_fx[L_SUBFR + ( M + 1 )]; /* Impulse response vector */ + Word16 code[L_SUBFR]; /* Fixed codebook excitation */ + Word16 y1[L_SUBFR]; /* Filtered adaptive excitation */ + Word16 y2[L_SUBFR]; /* Filtered algebraic excitation */ + Word16 gain_pit = 0, Gain_pitX2, gcode16; /* Pitch gain */ + Word16 voice_fac; /* Voicing factor */ + Word32 gain_code = 0; /* Gain of code */ + Word32 Lgcode; + Word16 gain_inov = 0; /* inovation gain */ + Word16 i, i_subfr, tmp1_fx, tmp_fx; /* tmp variables */ + Word16 unbits_ACELP; + Word16 T0_min, T0_max; /* pitch and TC variables */ + Word16 T0, T0_frac; /* close loop integer pitch and fractional part */ + Word16 *pt_pitch; /* pointer to floating pitch buffer */ + Word16 g_corr[10]; /* ACELP correlation values and gain pitch */ + Word16 clip_gain; /* LSF clip gain */ + const Word16 *p_Aw, *p_Aq; /* pointer to LP filter coefficient vector */ + Word16 gain_preQ = 0; /* Gain of prequantizer excitation */ + Word16 code_preQ[L_SUBFR]; /* Prequantizer excitation */ + Word16 Jopt_flag; /* joint optimization flag */ + Word16 unbits_PI = 0; /* saved bits for PI */ + Word32 norm_gain_code = 0; + Word16 L_frame_fx; + Word16 shift_wsp; + Word32 L_tmp; +#ifdef BASOP_NOGLOB_DECLARE_LOCAL + Flag Overflow = 0; +#endif + BSTR_ENC_HANDLE hBstr = st_fx->hBstr; + SC_VBR_ENC_HANDLE hSC_VBR = st_fx->hSC_VBR; + LPD_state_HANDLE hLPDmem = st_fx->hLPDmem; + + L_frame_fx = st_fx->L_frame; + move16(); + /*------------------------------------------------------------------* + * Initializations + *------------------------------------------------------------------*/ + gain_pit = 0; + move16(); + gain_code = L_deposit_l( 0 ); + gain_preQ = 0; + move16(); + unbits_PI = 0; + move16(); + IF( EQ_16( L_frame_fx, L_FRAME ) ) + { + T0_max = PIT_MAX; + move16(); + T0_min = PIT_MIN; + move16(); + } + ELSE /* L_frame == L_FRAME16k */ + { + T0_max = PIT16k_MAX; + move16(); + T0_min = PIT16k_MIN; + move16(); + } + + /**unbits = 0;move16();*/ + Jopt_flag = 0; + move16(); + unbits_ACELP = *unbits; + move16(); + *unbits = 0; + move16(); + + p_Aw = Aw_fx; + p_Aq = Aq_fx; + pt_pitch = pitch_buf_fx; + gain_preQ = 0; + move16(); + set16_fx( code_preQ, 0, L_SUBFR ); + shift_wsp = add( Q_new, shift ); + + /*----------------------------------------------------------------* + * ACELP subframe loop + *----------------------------------------------------------------*/ + + FOR( i_subfr = 0; i_subfr < L_frame_fx; i_subfr += L_SUBFR ) + { + /*----------------------------------------------------------------* + * Find the the excitation search target "xn" and innovation + * target in residual domain "cn" + * Compute impulse response, h1[], of weighted synthesis filter + *----------------------------------------------------------------*/ + + Copy( &res_fx[i_subfr], &exc_fx[i_subfr], L_SUBFR ); + + find_targets_fx( speech_fx, hLPDmem->mem_syn, i_subfr, &hLPDmem->mem_w0, p_Aq, + res_fx, L_SUBFR, p_Aw, st_fx->preemph_fac, xn, cn, h1 ); + + Copy_Scale_sig( h1, h2_fx, L_SUBFR, -2 ); + Scale_sig( h1, L_SUBFR, add( 1, shift ) ); /* set h1[] in Q14 with scaling for convolution */ + + /* scaling of xn[] to limit dynamic at 12 bits */ + Scale_sig( xn, L_SUBFR, shift ); + + /*-----------------------------------------------------------------* + * TC: subframe determination & + * adaptive/glottal part of excitation construction + *-----------------------------------------------------------------*/ + + transition_enc_ivas_fx( st_fx, i_subfr, &tc_subfr, &Jopt_flag, &position, &T0, &T0_frac, &T0_min, &T0_max, exc_fx, y1, + h1, xn, xn2, st_fx->clip_var_fx, &gain_pit, g_corr, &clip_gain, &pt_pitch, bwe_exc_fx, &unbits_ACELP, Q_new, shift ); + + /*-----------------------------------------------------------------* + * Transform domain contribution encoding - active frames + *-----------------------------------------------------------------*/ + + IF( GE_32( st_fx->core_brate, MIN_BRATE_AVQ_EXC ) ) + { + transf_cdbk_enc_ivas_fx( st_fx, 0, i_subfr, cn, exc_fx, p_Aq, Aw_fx, h1, xn, xn2, y1, y2, Es_pred_fx, + &gain_pit, gain_code, g_corr, clip_gain, &gain_preQ, code_preQ, unbits, Q_new, shift ); + } + + /*-----------------------------------------------------------------* + * ACELP codebook search + pitch sharpening + *-----------------------------------------------------------------*/ + + inov_encode_ivas_fx( st_fx, st_fx->core_brate, 0, L_frame_fx, st_fx->last_L_frame, st_fx->coder_type, st_fx->bwidth, st_fx->sharpFlag, + i_subfr, tc_subfr, p_Aq, gain_pit, cn, exc_fx, h2_fx, hLPDmem->tilt_code, *pt_pitch, xn2, code, y2, &unbits_PI, L_SUBFR, shift, Q_new ); + + test(); + test(); + test(); + if ( ( EQ_16( st_fx->L_frame, L_FRAME16k ) ) && ( tc_subfr == 0 ) && ( EQ_16( i_subfr, L_SUBFR ) ) && ( EQ_16( T0, 2 * L_SUBFR ) ) ) + { + Jopt_flag = 1; + move16(); + } + /*-----------------------------------------------------------------* + * Quantize the gains + * Test quantized gain of pitch for pitch clipping algorithm + * Update tilt of code: 0.0 (unvoiced) to 0.5 (voiced) + *-----------------------------------------------------------------*/ + IF( Jopt_flag == 0 ) + { + /* SQ gain_code */ + gain_enc_tc_ivas_fx( hBstr, st_fx->acelp_cfg.gains_mode, i_subfr, xn, y2, code, Es_pred_fx, + &gain_pit, &gain_code, &gain_inov, &norm_gain_code, sub( shift_wsp, 1 ) ); + } + ELSE + { + IF( GT_32( st_fx->core_brate, ACELP_32k ) ) + { + /* SQ gain_pit and gain_code */ + gain_enc_SQ_ivas_fx( hBstr, st_fx->acelp_cfg.gains_mode, i_subfr, xn, y1, y2, code, Es_pred_fx, + &gain_pit, &gain_code, &gain_inov, &norm_gain_code, g_corr, clip_gain, sub( shift_wsp, 1 ) ); + } + ELSE + { + /* VQ gain_pit and gain_code */ + gain_enc_mless_ivas_fx( hBstr, st_fx->acelp_cfg.gains_mode, st_fx->element_mode, L_frame_fx, i_subfr, tc_subfr, xn, y1, sub( shift_wsp, 1 ), y2, code, Es_pred_fx, + &gain_pit, &gain_code, &gain_inov, &norm_gain_code, g_corr, clip_gain ); + } + } + gp_clip_test_gain_pit_fx( st_fx->element_mode, st_fx->core_brate, gain_pit, st_fx->clip_var_fx ); + +#ifdef BASOP_NOGLOB + Lgcode = L_shl_o( gain_code, Q_new, &Overflow ); /* scaled gain_code with Qnew -> Q16*/ + gcode16 = round_fx_o( Lgcode, &Overflow ); +#else + Lgcode = L_shl( gain_code, Q_new ); /* scaled gain_code with Qnew -> Q16*/ + gcode16 = round_fx( Lgcode ); +#endif + hLPDmem->tilt_code = Est_tilt2( &exc_fx[i_subfr], gain_pit, code, Lgcode, &voice_fac, shift ); + /*-----------------------------------------------------------------* + * Update memory of the weighting filter + *-----------------------------------------------------------------*/ + + /*st->mem_w0 = xn[L_SUBFR-1] - (gain_pit*y1[L_SUBFR-1]) - (gain_code*y2[L_SUBFR-1]);*/ + L_tmp = L_mult0( gcode16, y2[L_SUBFR - 1] ); + L_tmp = L_shl( L_tmp, add( 5, shift ) ); // Q_new+14+shift + L_tmp = L_negate( L_tmp ); + L_tmp = L_mac( L_tmp, xn[L_SUBFR - 1], 16384 ); // Q_new-1+15+shift + L_tmp = L_msu( L_tmp, y1[L_SUBFR - 1], gain_pit ); // Q_new-1+15+shift +#ifdef BASOP_NOGLOB + L_tmp = L_shl_sat( L_tmp, sub( 1, shift ) ); // Q_new+15 + hLPDmem->mem_w0 = round_fx_sat( L_tmp ); /*Q_new-1*/ +#else + L_tmp = L_shl( L_tmp, sub( 1, shift ) ); + hLPDmem->mem_w0 = round_fx( L_tmp ); /*Q_new-1*/ +#endif + /*-----------------------------------------------------------------* + * Construct adaptive part of the excitation + * Save the non-enhanced excitation for FEC_exc + *-----------------------------------------------------------------*/ + + /* Here, all these conditions have one purpose: to use */ + /* the most efficient loop (the one with the least ops) */ + /* This is done by upscaling gain_pit_fx and/or gain_code16 */ + /* when they don't use all 16 bits of precision */ + + /* exc Q_exc, gpit Q14, code Q12, gcode Q0 */ + IF( norm_s( gain_pit ) == 0 ) + { + FOR( i = 0; i < L_SUBFR; i++ ) + { +#ifdef BASOP_NOGLOB + exc2_fx[i + i_subfr] = round_fx_sat( L_shl_sat( L_mult_sat( gain_pit, exc_fx[i + i_subfr] ), 1 ) ); +#else + exc2_fx[i + i_subfr] = round_fx( L_shl( L_mult( gain_pit, exc_fx[i + i_subfr] ), 1 ) ); +#endif + } + } + ELSE + { + Gain_pitX2 = shl( gain_pit, 1 ); + FOR( i = 0; i < L_SUBFR; i++ ) + { + exc2_fx[i + i_subfr] = mult_r( Gain_pitX2, exc_fx[i + i_subfr] ); + } + } + + /*-----------------------------------------------------------------* + * Construct adaptive part of the excitation + * Save the non-enhanced excitation for FEC_exc + *-----------------------------------------------------------------*/ + FOR( i = 0; i < L_SUBFR; i++ ) + { + /* code in Q9, gain_pit in Q14 */ + L_tmp = L_mult( gcode16, code[i] ); +#ifdef BASOP_NOGLOB + L_tmp = L_shl_o( L_tmp, 5, &Overflow ); + L_tmp = L_mac_o( L_tmp, exc_fx[i + i_subfr], gain_pit, &Overflow ); + L_tmp = L_shl_o( L_tmp, 1, &Overflow ); /* saturation can occur here */ + exc_fx[i + i_subfr] = round_fx_o( L_tmp, &Overflow ); +#else + L_tmp = L_shl( L_tmp, 5 ); + L_tmp = L_mac( L_tmp, exc_fx[i + i_subfr], gain_pit ); + L_tmp = L_shl( L_tmp, 1 ); /* saturation can occur here */ + exc_fx[i + i_subfr] = round_fx( L_tmp ); +#endif + } + + /*-----------------------------------------------------------------* + * Add the ACELP pre-quantizer contribution + *-----------------------------------------------------------------*/ + + IF( GE_32( st_fx->core_brate, MIN_BRATE_AVQ_EXC ) ) + { + tmp1_fx = add( 16 - ( 2 + Q_AVQ_OUT_DEC + 1 ), Q_new ); + FOR( i = 0; i < L_SUBFR; i++ ) + { + L_tmp = L_mult( gain_preQ, code_preQ[i] ); /* Q2 + Q10 -> Q13*/ +#ifdef BASOP_NOGLOB + L_tmp = L_shl_o( L_tmp, tmp1_fx, &Overflow ); /* Q16 + Q_exc */ + tmp_fx = round_fx_o( L_tmp, &Overflow ); + + exc2_fx[i + i_subfr] = add_o( exc2_fx[i + i_subfr], tmp_fx, &Overflow ); + move16(); + exc_fx[i + i_subfr] = add_o( exc_fx[i + i_subfr], tmp_fx, &Overflow ); + move16(); +#else + L_tmp = L_shl( L_tmp, tmp1_fx ); /* Q16 + Q_exc */ + tmp_fx = round_fx( L_tmp ); + + exc2_fx[i + i_subfr] = add( exc2_fx[i + i_subfr], tmp_fx ); + move16(); + exc_fx[i + i_subfr] = add( exc_fx[i + i_subfr], tmp_fx ); + move16(); +#endif + } + } + + /*-----------------------------------------------------------------* + * Prepare TBE excitation + *-----------------------------------------------------------------*/ + + prep_tbe_exc_ivas_fx( L_frame_fx, L_SUBFR, i_subfr, gain_pit, gain_code, code, voice_fac, &voice_factors[i_subfr / L_SUBFR], + bwe_exc_fx, gain_preQ, code_preQ, Q_new, T0, T0_frac, st_fx->coder_type, st_fx->core_brate, + st_fx->element_mode, st_fx->idchan, st_fx->hBWE_TD != NULL, st_fx->tdm_LRTD_flag ); + + /*-----------------------------------------------------------------* + * Synthesize speech to update mem_syn[]. + * Update A(z) filters + *-----------------------------------------------------------------*/ + + Syn_filt_s( 1, p_Aq, M, &exc_fx[i_subfr], &syn_fx[i_subfr], L_SUBFR, hLPDmem->mem_syn, 1 ); + + p_Aw += ( M + 1 ); + p_Aq += ( M + 1 ); + pt_pitch++; + } + + /* write reserved bits */ + WHILE( unbits_PI > 0 ) + { + i = s_min( unbits_PI, 16 ); + push_indice( hBstr, IND_UNUSED, 0, i ); + unbits_PI -= i; + } + + /* write TC configuration */ + IF( EQ_16( L_frame_fx, L_FRAME ) ) + { + IF( EQ_16( tc_subfr, TC_0_0 ) ) + { + push_indice( hBstr, IND_TC_SUBFR, 1, 1 ); + } + ELSE IF( EQ_16( tc_subfr, TC_0_64 ) ) + { + push_indice( hBstr, IND_TC_SUBFR, 0, 1 ); + push_indice( hBstr, IND_TC_SUBFR, 1, 1 ); + push_indice( hBstr, IND_TC_SUBFR, 0, 1 ); + push_indice( hBstr, IND_TC_SUBFR, 1, 1 ); + } + ELSE IF( EQ_16( tc_subfr, TC_0_128 ) ) + { + push_indice( hBstr, IND_TC_SUBFR, 0, 1 ); + push_indice( hBstr, IND_TC_SUBFR, 1, 1 ); + push_indice( hBstr, IND_TC_SUBFR, 0, 1 ); + push_indice( hBstr, IND_TC_SUBFR, 0, 1 ); + } + ELSE IF( EQ_16( tc_subfr, TC_0_192 ) ) + { + push_indice( hBstr, IND_TC_SUBFR, 0, 1 ); + push_indice( hBstr, IND_TC_SUBFR, 1, 1 ); + push_indice( hBstr, IND_TC_SUBFR, 1, 1 ); + } + ELSE IF( EQ_16( tc_subfr, L_SUBFR ) ) + { + push_indice( hBstr, IND_TC_SUBFR, 0, 1 ); + push_indice( hBstr, IND_TC_SUBFR, 0, 1 ); + push_indice( hBstr, IND_TC_SUBFR, 1, 1 ); + } + ELSE IF( EQ_16( tc_subfr, 2 * L_SUBFR ) ) + { + push_indice( hBstr, IND_TC_SUBFR, 0, 1 ); + push_indice( hBstr, IND_TC_SUBFR, 0, 1 ); + push_indice( hBstr, IND_TC_SUBFR, 0, 1 ); + push_indice( hBstr, IND_TC_SUBFR, 1, 1 ); + } + ELSE IF( EQ_16( tc_subfr, 3 * L_SUBFR ) ) + { + push_indice( hBstr, IND_TC_SUBFR, 0, 1 ); + push_indice( hBstr, IND_TC_SUBFR, 0, 1 ); + push_indice( hBstr, IND_TC_SUBFR, 0, 1 ); + push_indice( hBstr, IND_TC_SUBFR, 0, 1 ); + } + } + ELSE /* L_frame == L_FRAME16k */ + { + IF( tc_subfr == 0 ) + { + push_indice( hBstr, IND_TC_SUBFR, 0, 2 ); + } + ELSE IF( EQ_16( tc_subfr, L_SUBFR ) ) + { + push_indice( hBstr, IND_TC_SUBFR, 1, 2 ); + } + ELSE IF( EQ_16( tc_subfr, 2 * L_SUBFR ) ) + { + push_indice( hBstr, IND_TC_SUBFR, 2, 2 ); + } + ELSE IF( EQ_16( tc_subfr, 3 * L_SUBFR ) ) + { + push_indice( hBstr, IND_TC_SUBFR, 3, 2 ); + push_indice( hBstr, IND_TC_SUBFR, 0, 1 ); + } + ELSE IF( EQ_16( tc_subfr, 4 * L_SUBFR ) ) + { + push_indice( hBstr, IND_TC_SUBFR, 3, 2 ); + push_indice( hBstr, IND_TC_SUBFR, 1, 1 ); + } + } + + IF( st_fx->Opt_SC_VBR ) + { + /* SC-VBR */ + hSC_VBR->prev_ppp_gain_pit_fx = gain_pit; + move16(); + hSC_VBR->prev_tilt_code_fx = hLPDmem->tilt_code; + move16(); + } + + return tc_subfr; +} diff --git a/lib_enc/enc_uv_fx.c b/lib_enc/enc_uv_fx.c index 981d02a86..f87220008 100644 --- a/lib_enc/enc_uv_fx.c +++ b/lib_enc/enc_uv_fx.c @@ -5,7 +5,7 @@ #include #include "options.h" /* Compilation switches */ #include "cnst.h" /* Common constants */ -//#include "prot_fx.h" /* Function prototypes */ +#include "prot.h" /* Function prototypes */ #include "rom_com.h" #include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ @@ -262,3 +262,264 @@ void encod_unvoiced_fx( return; } + +void encod_unvoiced_ivas_fx( + Encoder_State *st_fx, /* i/o: state structure */ + const Word16 *speech_fx, /* i : Input speech */ + const Word16 Aw_fx[], /* i : weighted A(z) unquantized for subframes */ + const Word16 *Aq_fx, /* i : 12k8 Lp coefficient */ + const Word16 Es_pred, /* i : predicted scaled innov. energy */ + const Word16 uc_two_stage_flag, /* i : flag indicating two-stage UC */ + const Word16 *res_fx, /* i : residual signal */ + Word16 *syn_fx, /* o : core synthesis */ + Word16 *tmp_noise_fx, /* o : long-term noise energy */ + Word16 *exc_fx, /* i/o: current non-enhanced excitation */ + Word16 *pitch_buf_fx, /* o : floating pitch values for each subframe */ + Word16 *voice_factors_fx, /* o : voicing factors */ + Word16 *bwe_exc_fx, /* i/o: excitation for SWB TBE */ + const Word16 Q_new, + const Word16 shift ) +{ + Word16 xn_fx[L_SUBFR]; /* Target vector for pitch search */ + Word16 h1_fx[L_SUBFR]; /* Impulse response vector */ + Word16 code_fx[L_SUBFR]; /* Fixed codebook excitation */ + Word16 y2_fx[L_SUBFR]; /* Filtered algebraic excitation */ + Word16 *pt_pitch_fx; /* pointer to floating pitch buffer */ + Word16 gain_pit_fx; /* Pitch gain */ + Word16 voice_fac_fx; /* Voicing factor */ + Word32 L_gain_code_fx; /* gain of code */ + Word16 gain_inov_fx; /* inovative gain */ + Word16 cn_fx[L_SUBFR]; /* Target vector in residual domain */ + Word16 y1[L_SUBFR]; /* Filtered adaptive excitation */ + Word16 code2[L_SUBFR]; /* Gaussian excitation */ + Word16 y22[L_SUBFR]; /* Filtered Gaussian excitation */ + // Word16 prm_t[2 * NPRM_DIV], *prm = prm_t; + const Word16 *p_Aw_fx, *p_Aq_fx; /* pointer to LP filter coeff. vector */ + Word32 norm_gain_code_fx; + ACELP_config *acelp_cfg; + ACELP_CbkCorr g_corr; + Word32 gain_code2; + Word32 gain_code_vect[2], Ltmp, Ltmp2; +#if 0 + Word16 i_subfr, clip_gain, Q_xn, Q_new_p5, tmp2, j, i; + Word16 exc2[L_SUBFR], index, i_subfr_idx; +#else + Word16 i_subfr, Q_xn, Q_new_p5, tmp2, j, i; + Word16 index, i_subfr_idx; + Word16 unbits_PI; +#endif + acelp_cfg = &( st_fx->acelp_cfg ); + SC_VBR_ENC_HANDLE hSC_VBR = st_fx->hSC_VBR; + LPD_state_HANDLE hLPDmem = st_fx->hLPDmem; + + /*------------------------------------------------------------------* + * Initializations + *------------------------------------------------------------------*/ + gain_pit_fx = 0; + move16(); + + test(); + test(); + test(); + IF( st_fx->Opt_SC_VBR && st_fx->vad_flag == 0 && ( EQ_16( hSC_VBR->last_ppp_mode, 1 ) || EQ_16( hSC_VBR->last_nelp_mode, 1 ) ) ) + { + /* SC_VBR - reset the encoder, to avoid memory not updated issue for the + case when UNVOICED mode is used to code inactive speech */ + CNG_reset_enc_fx( st_fx, hLPDmem, pitch_buf_fx, voice_factors_fx, 1 ); + } + + p_Aw_fx = Aw_fx; + p_Aq_fx = Aq_fx; + pt_pitch_fx = pitch_buf_fx; + move16(); + Q_xn = add( sub( Q_new, 1 ), shift ); + Q_new_p5 = add( Q_new, 5 ); + + + FOR( i_subfr = 0; i_subfr < L_FRAME; i_subfr += L_SUBFR ) + { + /*----------------------------------------------------------------* + * Bandwidth expansion of A(z) filter coefficients + * Find the excitation search target "xn" and innovation target in residual domain "cn" + * Compute impulse response, h1[], of weighted synthesis filter + *----------------------------------------------------------------*/ + i_subfr_idx = shr( i_subfr, 6 ); + Copy( &res_fx[i_subfr], &exc_fx[i_subfr], L_SUBFR ); + + find_targets_fx( speech_fx, hLPDmem->mem_syn, i_subfr, &hLPDmem->mem_w0, p_Aq_fx, + res_fx, L_SUBFR, p_Aw_fx, st_fx->preemph_fac, xn_fx, cn_fx, h1_fx ); + + /*Copy_Scale_sig(h1_fx, h2_fx, L_SUBFR, -2);*/ + Scale_sig( h1_fx, L_SUBFR, add( 1, shift ) ); /* set h1[] in Q14 with scaling for convolution */ + + /* scaling of xn[] to limit dynamic at 12 bits */ + Scale_sig( xn_fx, L_SUBFR, shift ); + /*----------------------------------------------------------------* + * Unvoiced subframe processing + *----------------------------------------------------------------*/ + IF( !uc_two_stage_flag ) + { + *pt_pitch_fx = gaus_encode_ivas_fx( st_fx, i_subfr, h1_fx, xn_fx, exc_fx, &hLPDmem->mem_w0, st_fx->clip_var_fx, + &hLPDmem->tilt_code, code_fx, &L_gain_code_fx, y2_fx, &gain_inov_fx, + &voice_fac_fx, &gain_pit_fx, Q_new, shift, &norm_gain_code_fx ); + } + ELSE + { + /*----------------------------------------------------------------* + * Unvoiced subframe processing in two stages + *----------------------------------------------------------------*/ + // PMT("The code below needs validation, never been tested") + /* No adaptive codebook (UC) */ + set16_fx( y1, 0, L_SUBFR ); + set16_fx( exc_fx + i_subfr, 0, L_SUBFR ); + /*-----------------------------------------------------------------* + * Gain clipping test to avoid unstable synthesis on frame erasure + * or in case of floating point encoder & fixed p. decoder + *-----------------------------------------------------------------*/ +#if 0 + clip_gain = Mode2_gp_clip(st_fx->voicing_fx, i_subfr, st_fx->coder_type, xn_fx, st_fx->clip_var_fx, L_SUBFR, Q_xn); +#else + Mode2_gp_clip( st_fx->voicing_fx, i_subfr, st_fx->coder_type, xn_fx, st_fx->clip_var_fx, L_SUBFR, Q_xn ); +#endif + *pt_pitch_fx = L_SUBFR << 6; + move16(); + /*----------------------------------------------------------------------* + * Encode the algebraic innovation * + *----------------------------------------------------------------------*/ + + // E_ACELP_innovative_codebook_ivas_fx( exc_fx, *pt_pitch_fx, 0, 1, gain_pit_fx, hLPDmem->tilt_code, acelp_cfg, i_subfr, p_Aq_fx, h1_fx, xn_fx, cn_fx, y1, y2_fx, (Word8) st_fx->acelp_autocorr, &prm, code_fx, shift, st_fx->L_frame, st_fx->last_L_frame, st_fx->total_brate, st_fx->element_mode ); + inov_encode_ivas_fx( st_fx, st_fx->core_brate, 0, L_FRAME, st_fx->last_L_frame, + UNVOICED, st_fx->bwidth, st_fx->sharpFlag, i_subfr, -1, p_Aq_fx, + gain_pit_fx, cn_fx, exc_fx, h1_fx, hLPDmem->tilt_code, *pt_pitch_fx, xn_fx, code_fx, y2_fx, &unbits_PI, L_SUBFR, shift, Q_new ); + + E_ACELP_xy2_corr( xn_fx, y1, y2_fx, &g_corr, L_SUBFR, Q_xn ); + + g_corr.y2y2_e = sub( g_corr.y2y2_e, 18 ); /* -18 (y2*y2: Q9*Q9) */ + g_corr.xy2_e = sub( g_corr.xy2_e, add( Q_xn, 9 ) ); /* -(Q_xn+9) (xn: Q_xn y2: Q9) */ + g_corr.y1y2_e = sub( g_corr.y1y2_e, add( Q_xn, 9 ) ); /* -(Q_xn+9) (y1: Q_xn y2: Q9) */ + g_corr.xx_e = sub( g_corr.xx_e, add( Q_xn, Q_xn ) ); /* -(Q_xn+Q_xn) (xn: Q_xn) */ + + assert( gain_pit_fx == 0 ); + gauss_L2_fx( h1_fx, code2, y2_fx, y22, &gain_code2, &g_corr, gain_pit_fx, hLPDmem->tilt_code, p_Aq_fx, acelp_cfg->formant_enh_num, &( st_fx->seed_acelp ), shift ); + + /*----------------------------------------------------------* + * - Compute the fixed codebook gain * + * - quantize fixed codebook gain * + *----------------------------------------------------------*/ + + index = gain_enc_uv_fx( code_fx, code2, L_SUBFR, &gain_pit_fx, &L_gain_code_fx, &gain_code2, + st_fx->flag_noisy_speech_snr_fx, &g_corr, Es_pred, &norm_gain_code_fx, &gain_inov_fx, FUNC_GAIN_ENC_GACELP_UV ); + +#ifdef DEBUGGING + assert( st_fx->acelp_cfg.gains_mode[i_subfr_idx] == 7 && "Error: UC two-stage, only 5+2 gain Q is supported" ); +#endif + push_indice( st_fx->hBstr, IND_GAIN, index, st_fx->acelp_cfg.gains_mode[i_subfr_idx] ); + + gp_clip_test_gain_pit_fx( st_fx->element_mode, st_fx->core_brate, gain_pit_fx, st_fx->clip_var_fx ); + + gain_code_vect[0] = L_gain_code_fx; + move32(); + gain_code_vect[1] = L_gain_code_fx; + move32(); + + /*----------------------------------------------------------* + * - voice factor (for pitch enhancement) * + *----------------------------------------------------------*/ + E_UTIL_voice_factor( exc_fx, i_subfr, code_fx, gain_pit_fx, L_gain_code_fx, &voice_fac_fx, &( hLPDmem->tilt_code ), L_SUBFR, acelp_cfg->voice_tilt, Q_new, shift ); + + IF( st_fx->Opt_RF_ON ) + { + st_fx->hRF->rf_tilt_buf[i_subfr_idx] = hLPDmem->tilt_code; + } + /*-----------------------------------------------------------------* + * Update memory of the weighting filter + *-----------------------------------------------------------------*/ + /* st_fx->mem_w0 = xn[L_SUBFR-1] - (gain_pit*y1[L_SUBFR-1]) - (gain_code*y2[L_SUBFR-1]); */ + Ltmp = Mpy_32_16_1( L_gain_code_fx, y2_fx[L_SUBFR - 1] ); + Ltmp = L_shl( Ltmp, add( 5, Q_xn ) ); // Qxn+15 + Ltmp = L_mac( Ltmp, y1[L_SUBFR - 1], gain_pit_fx ); + /* Add Gaussian contribution*/ + Ltmp2 = Mpy_32_16_1( gain_code2, y22[L_SUBFR - 1] ); + Ltmp2 = L_shl( Ltmp2, add( 5, Q_xn ) ); // Q_xn+15 + Ltmp = L_add( Ltmp, Ltmp2 ); + hLPDmem->mem_w0 = sub( xn_fx[L_SUBFR - 1], round_fx( Ltmp ) ); // Q_xn-1 + move16(); + BASOP_SATURATE_WARNING_OFF_EVS; +#ifdef BASOP_NOGLOB + hLPDmem->mem_w0 = shr_sat( hLPDmem->mem_w0, shift ); /*Qnew-1*/ +#else + hLPDmem->mem_w0 = shr( hLPDmem->mem_w0, shift ); /*Qnew-1*/ +#endif + BASOP_SATURATE_WARNING_ON_EVS; + + /*-------------------------------------------------------* + * - Find the total excitation. * + *-------------------------------------------------------*/ + + tmp2 = shr( L_SUBFR, 1 ); + FOR( j = 0; j < 2; j++ ) + { + FOR( i = sub( tmp2, shr( L_SUBFR, 1 ) ); i < tmp2; i++ ) + { + /* code in Q9, gain_pit in Q14; exc Q_new */ + Ltmp = Mpy_32_16_1( gain_code2, code2[i] ); +#ifdef BASOP_NOGLOB + Ltmp = L_shl_sat( Ltmp, Q_new_p5 ); + Ltmp = L_mac_sat( Ltmp, gain_pit_fx, exc_fx[i + i_subfr] ); +#else + Ltmp = L_shl( Ltmp, Q_new_p5 ); + Ltmp = L_mac( Ltmp, gain_pit_fx, exc_fx[i + i_subfr] ); +#endif +#if 0 + BASOP_SATURATE_WARNING_OFF_EVS + exc2[i] = round_fx(L_shl(Ltmp, 1)); + BASOP_SATURATE_WARNING_ON_EVS +#endif + Ltmp2 = Mpy_32_16_1( gain_code_vect[j], code_fx[i] ); +#ifdef BASOP_NOGLOB + Ltmp2 = L_shl_sat( Ltmp2, Q_new_p5 ); + Ltmp = L_add_sat( Ltmp, Ltmp2 ); + Ltmp = L_shl_sat( Ltmp, 1 ); /* saturation can occur here */ + exc_fx[i + i_subfr] = round_fx_sat( Ltmp ); +#else + BASOP_SATURATE_WARNING_OFF_EVS + Ltmp2 = L_shl( Ltmp2, Q_new_p5 ); + Ltmp = L_add( Ltmp, Ltmp2 ); + Ltmp = L_shl( Ltmp, 1 ); /* saturation can occur here */ + BASOP_SATURATE_WARNING_ON_EVS + exc_fx[i + i_subfr] = round_fx( Ltmp ); +#endif + } + tmp2 = L_SUBFR; + move16(); + } + } + + *tmp_noise_fx = extract_h( norm_gain_code_fx ); + voice_factors_fx[i_subfr / L_SUBFR] = 0; + move16(); + + interp_code_5over2_fx( &exc_fx[i_subfr], &bwe_exc_fx[i_subfr * HIBND_ACB_L_FAC], L_SUBFR ); + + /*-----------------------------------------------------------------* + * Synthesize speech to update mem_syn[]. + * Update A(z) filters + *-----------------------------------------------------------------*/ + Syn_filt_s( 1, p_Aq_fx, M, &exc_fx[i_subfr], &syn_fx[i_subfr], L_SUBFR, hLPDmem->mem_syn, 1 ); + + p_Aw_fx += ( M + 1 ); + p_Aq_fx += ( M + 1 ); + pt_pitch_fx++; + } + + /* SC-VBR */ + IF( hSC_VBR ) + { + hSC_VBR->prev_ppp_gain_pit_fx = gain_pit_fx; + move16(); + hSC_VBR->prev_tilt_code_fx = hLPDmem->tilt_code; + move16(); + } + + return; +} diff --git a/lib_enc/eval_pit_contr_fx.c b/lib_enc/eval_pit_contr_fx.c index f1cc54606..f295e1736 100644 --- a/lib_enc/eval_pit_contr_fx.c +++ b/lib_enc/eval_pit_contr_fx.c @@ -2,11 +2,11 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ -#include "cnst.h" /* Common constants */ -#include "rom_com_fx.h" /* Static table prototypes */ -#include "rom_com.h" /* Static table prototypes */ -//#include "prot_fx.h" /* Function prototypes */ +#include "options.h" /* Compilation switches */ +#include "cnst.h" /* Common constants */ +#include "rom_com_fx.h" /* Static table prototypes */ +#include "rom_com.h" /* Static table prototypes */ +#include "prot.h" /* Function prototypes */ #include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ @@ -430,3 +430,386 @@ Word16 Pit_exc_contribution_len_fx( /* o : bin where pit return last_pit_bin; } + + +Word16 Pit_exc_contribution_len_ivas_fx( /* o : bin where pitch contribution is significant */ + Encoder_State *st_fx, /* i/o: state structure */ + const Word16 *dct_res, /* i : DCT of residual */ + Word16 *dct_pitex, /* i/o: DCT of pitch contribution */ + Word16 *pitch_buf, /* i/o: Pitch per subframe */ + const Word16 nb_subfr, /* i : Number of subframe considered */ + Word16 *hangover, /* i : hangover for the time contribution switching */ + Word16 Qnew ) +{ + + Word16 corr_dct_pit[MBANDS_LOC]; + Word32 corr_tmp, L_tmp; + Word16 av_corr, min_corr, ftmp, tmp_ex, tmp_res; + Word16 freq, i, j; + Word16 last_pit_band, pit_contr_idx, last_pit_bin; + Word32 ener_res; + Word32 ener_pit; + Word16 low_pit, F1st_harm, F8th_harm; + Word16 corr_dct_pit_tmp[MBANDS_LOC]; + Word16 time_flg = 0; + Word16 Len, max_len; + Word16 tmp_dec; + Word16 Mbands_loc = MBANDS_LOC - 2; + Word16 exp1, tmp, exp2; + Word32 L_tmp1, ener_init; + Word16 exp_norm; + Word16 norm; + Word16 val_thrs; + SP_MUS_CLAS_HANDLE hSpMusClas = st_fx->hSpMusClas; + BSTR_ENC_HANDLE hBstr = st_fx->hBstr; + GSC_ENC_HANDLE hGSCEnc = st_fx->hGSCEnc; + + if ( EQ_16( st_fx->L_frame, L_FRAME16k ) ) + { + Mbands_loc = MBANDS_LOC; + move16(); + } + + minimum_fx( pitch_buf, nb_subfr, &low_pit ); + exp1 = norm_s( low_pit ); + tmp = shl( low_pit, exp1 ); + tmp_dec = 12800; + move16(); + if ( EQ_16( st_fx->L_frame, L_FRAME16k ) ) + { + tmp_dec = 16000; + move16(); + } + /*F1st_harm = (12800.0f|160000.f)/low_pit;*/ + tmp = div_s( tmp_dec, tmp ); /*15-6-exp1(->9-exp1)*/ + F1st_harm = shr_r( tmp, sub( 5, exp1 ) ); /*Q4*/ + + /*F8th_harm = 8.0f*F1st_harm;*/ + F8th_harm = extract_l( L_shr_r( L_mult0( F1st_harm, 8 ), 2 ) ); /*Q2*/ + + freq = 0; + move16(); + ener_init = L_shl( 3, 2 * Qnew - 5 ); /*(0.1->3 in Q5) 2*Qnew*/ + FOR( i = 0; i < Mbands_loc; i++ ) /* up to maximum allowed voiced critical band */ + { + corr_tmp = L_deposit_l( 0 ); + ener_res = L_add( ener_init, 0 ); + ener_pit = L_add( ener_init, 0 ); + + FOR( j = 0; j < mfreq_bindiv_loc[i]; j++ ) /* up to maximum allowed voiced critical band */ + { + tmp_ex = mult_r( dct_pitex[j + freq], 8192 ); + tmp_res = mult_r( dct_res[j + freq], 8192 ); + corr_tmp = L_mac0( corr_tmp, tmp_res, tmp_ex ); /*2*Qnew*/ + ener_res = L_mac0( ener_res, tmp_res, tmp_res ); /*2*Qnew*/ + ener_pit = L_mac0( ener_pit, tmp_ex, tmp_ex ); /*2*Qnew*/ + } + + L_tmp1 = Mult_32_32( ener_res, ener_pit ); + exp2 = norm_l( L_tmp1 ); + L_tmp1 = L_shl( L_tmp1, exp2 ); + exp_norm = sub( 30, exp2 ); + L_tmp1 = Isqrt_lc( L_tmp1, &exp_norm ); + norm = extract_h( L_tmp1 ); /*15-exp_norm*/ + L_tmp1 = L_shl( Mult_32_16( corr_tmp, norm ), exp_norm ); + corr_dct_pit[i] = round_fx( L_shl( L_tmp1, 14 ) ); /*Q14*/ + + freq = add( freq, mfreq_bindiv_loc[i] ); + } + + val_thrs = 8192; + move16(); /* 0.5 in Q14*/ + /* Smooth the inter-correlation value and skip the last band for the average (since last band is almost always 0)*/ + tmp = mac_r( L_mult( ALPA_FX, corr_dct_pit[0] ), ALPAM1_FX, corr_dct_pit[1] ); /*Qnew*/ + tmp = s_max( tmp, val_thrs ); + + corr_dct_pit_tmp[0] = shl( sub( tmp, val_thrs ), 1 ); + move16(); + + FOR( i = 1; i < Mbands_loc - 1; i++ ) /* up to maximum allowed voiced critical band */ + { + L_tmp = L_mult( BETA_FX, corr_dct_pit[i - 1] ); + L_tmp = L_mac( L_tmp, BETA_FX, corr_dct_pit[i + 1] ); + + tmp = mac_r( L_tmp, ALPA_FX, corr_dct_pit[i] ); + tmp = s_max( tmp, val_thrs ); + + corr_dct_pit_tmp[i] = shl( sub( tmp, val_thrs ), 1 ); + move16(); + } + tmp = mac_r( L_mult( ALPA_FX, corr_dct_pit[i] ), ALPAM1_FX, corr_dct_pit[i - 1] ); /*Qnew*/ + tmp = s_max( tmp, val_thrs ); + corr_dct_pit_tmp[i] = shl( sub( tmp, val_thrs ), 1 ); + move16(); + + Copy( corr_dct_pit_tmp, corr_dct_pit, Mbands_loc ); + + L_tmp1 = L_mult( DIV_NB_VOIC_FX, corr_dct_pit[0] ); /*Qnew*/ + FOR( i = 1; i < NB_VOIC_FX; i++ ) /* up to maximum allowed voiced critical band */ + { + L_tmp1 = L_mac( L_tmp1, DIV_NB_VOIC_FX, corr_dct_pit[i] ); + } + av_corr = round_fx( L_tmp1 ); /*Qnew*/ + + /* Find the cut-off freq similarly to HSX */ + last_pit_band = 0; + move16(); + av_corr = round_fx( L_shl( L_mult0( av_corr, 6400 ), 16 - 12 ) ); /*Q14*Q0-12=Q2*/ + + if ( EQ_16( st_fx->L_frame, L_FRAME16k ) ) + { + /*av_corr *= 1.25f;*/ + av_corr = add( av_corr, shr( av_corr, 2 ) ); + } + test(); + if ( GE_16( st_fx->GSC_IVAS_mode, 1 ) || LT_32( st_fx->core_brate, ACELP_9k60 ) ) + { + av_corr = shl_sat( av_corr, 1 ); /*Q2 Correlation really poor at low rate, time domain still valide*/ + } + min_corr = abs_s( sub( mfreq_loc_Q2fx[0], av_corr ) ); /*Q2*/ + + FOR( i = 1; i < Mbands_loc; i++ ) /* up to maximum allowed voiced critical band */ + { + ftmp = abs_s( sub( mfreq_loc_Q2fx[i], av_corr ) ); /*Q2*/ + + IF( LT_16( ftmp, min_corr ) ) + { + last_pit_band = i; + move16(); + min_corr = ftmp; + move16(); + } + } + + IF( GT_16( F8th_harm, mfreq_loc_Q2fx[last_pit_band] ) ) + { + DO + { + last_pit_band = add( last_pit_band, 1 ); + } + WHILE( GE_16( F8th_harm, mfreq_loc_Q2fx[last_pit_band] ) ); + } + if ( GE_16( st_fx->GSC_IVAS_mode, 1 ) ) + { + last_pit_band = s_max( last_pit_band, 7 ); + } + test(); + test(); + test(); + IF( GT_16( last_pit_band, 7 + BAND1k2 ) && ( LT_32( st_fx->core_brate, CFREQ_BITRATE ) || EQ_16( st_fx->bwidth, NB ) ) ) /*Added for 9.1*/ + { + last_pit_band = 7 + BAND1k2; + move16(); + } + ELSE IF( GT_16( last_pit_band, 10 + BAND1k2 ) && GE_32( st_fx->core_brate, CFREQ_BITRATE ) ) + { + last_pit_band = add( 10, BAND1k2 ); + } + + time_flg = 0; + move16(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + IF( ( hGSCEnc->mem_last_pit_band > 0 && GT_16( st_fx->old_corr_fx, 16384 ) && GT_16( hSpMusClas->mold_corr_fx, 16384 ) && GE_16( hGSCEnc->lt_gpitch_fx, 19661 ) /*1.5f*GPIT_THR*/ ) || ( GT_16( last_pit_band, 6 ) ) || ( GE_16( last_pit_band, 4 ) && GE_16( hGSCEnc->lt_gpitch_fx, 19661 ) /*1.5f*GPIT_THR*/ && GT_16( st_fx->old_corr_fx, 22938 ) ) || ( GT_16( last_pit_band, BAND1k2 ) && GT_16( hSpMusClas->mold_corr_fx, 26214 ) && GE_16( hGSCEnc->lt_gpitch_fx, 13107 ) /*GPIT_THR*/ ) ) + { + tmp_dec = 1; + move16(); + } + ELSE + { + tmp_dec = 0; + move16(); + } + + /* Different past and current decision */ + test(); + test(); + test(); + IF( ( hGSCEnc->mem_last_pit_band == 0 && EQ_16( tmp_dec, 1 ) ) || ( hGSCEnc->mem_last_pit_band > 0 && tmp_dec == 0 ) ) + { + IF( *hangover == 0 ) + { + time_flg = tmp_dec; + move16(); + *hangover = HANGOVER_DELAY; + move16(); + } + ELSE + { + time_flg = 0; + move16(); + if ( hGSCEnc->mem_last_pit_band > 0 ) + { + time_flg = 1; + move16(); + } + + ( *hangover ) = sub( ( *hangover ), 1 ); + if ( *hangover < 0 ) + { + *hangover = 0; + move16(); + } + } + } + ELSE + { + time_flg = tmp_dec; + move16(); + *hangover = HANGOVER_DELAY; + move16(); + } + + /* Decicison on final length of time contribution */ + pit_contr_idx = 0; + move16(); + test(); + test(); + IF( EQ_16( time_flg, 1 ) || NE_16( st_fx->coder_type, INACTIVE ) || st_fx->GSC_noisy_speech ) + { + test(); + test(); + /*if(st_fx->core_brate core_brate, ACELP_9k60 ) && LT_16( low_pit, 4096 ) ) + { + last_pit_band = add( 9, BAND1k2 ); + if ( EQ_16( st_fx->bwidth, NB ) ) + { + last_pit_band = add( 7, BAND1k2 ); + } + } + ELSE IF( LT_32( st_fx->core_brate, ACELP_9k60 ) && LT_16( low_pit, 8192 ) ) + { + last_pit_band = add( 5, BAND1k2 ); + } + ELSE IF( LT_32( st_fx->core_brate, ACELP_9k60 ) ) + { + last_pit_band = add( 3, BAND1k2 ); + } + ELSE IF( LT_16( last_pit_band, add( BAND1k2, 1 ) ) ) + { + last_pit_band = add( BAND1k2, 1 ); + } + last_pit_bin = mfreq_loc_div_25[last_pit_band]; + move16(); + + st_fx->bpf_off = 0; + move16(); + + max_len = sub( st_fx->L_frame, last_pit_bin ); + + if ( EQ_16( st_fx->bwidth, NB ) ) + { + max_len = sub( 160, last_pit_bin ); + } + + Len = 80; + move16(); + if ( LT_16( max_len, 80 ) ) + { + Len = max_len; + move16(); + } + test(); + IF( ( EQ_32( st_fx->core_brate, ACELP_8k00 ) ) && ( NE_16( st_fx->bwidth, NB ) ) ) + { + move16(); /*ptr init*/ + FOR( i = 0; i < max_len; i++ ) + { + dct_pitex[i + last_pit_bin] = 0; + move16(); + } + } + ELSE + { + + FOR( i = 0; i < Len; i++ ) + { + dct_pitex[i + last_pit_bin] = mult_r( dct_pitex[i + last_pit_bin], sm_table_fx[i] ); + } + FOR( ; i < max_len; i++ ) + { + dct_pitex[i + last_pit_bin] = 0; + move16(); + } + } + hGSCEnc->mem_last_pit_band = last_pit_band; + move16(); + pit_contr_idx = sub( last_pit_band, BAND1k2 ); + } + ELSE + { + set16_fx( dct_pitex, 0, st_fx->L_frame ); + st_fx->bpf_off = 1; + move16(); + last_pit_bin = 0; + move16(); + last_pit_band = 0; + move16(); + pit_contr_idx = 0; + move16(); + hGSCEnc->mem_last_pit_band = 0; + move16(); + + set16_fx( pitch_buf, shl( L_SUBFR, 6 ), NB_SUBFR16k ); + /* pitch contribution useless - delete all previously written indices belonging to pitch contribution */ + FOR( i = TAG_ACELP_SUBFR_LOOP_START; i < TAG_ACELP_SUBFR_LOOP_END; i++ ) + { +#if 0 // ndef IVAS_CODE_BITSTREAM + IF( hBstr->ind_list[i].nb_bits != -1 ) + { + hBstr->nb_bits_tot = sub( hBstr->nb_bits_tot, hBstr->ind_list[i].nb_bits ); + hBstr->ind_list[i].nb_bits = -1; + move16(); + } +#else + delete_indice( hBstr, i ); +#endif + } + +#if 0 // ndef IVAS_CODE_BITSTREAM + IF( hBstr->ind_list[IND_ES_PRED].nb_bits != -1 ) + { + hBstr->nb_bits_tot = sub( hBstr->nb_bits_tot, hBstr->ind_list[IND_ES_PRED].nb_bits ); + hBstr->ind_list[IND_ES_PRED].nb_bits = -1; + move16(); + } +#else + delete_indice( hBstr, i ); +#endif + } + IF( LT_32( st_fx->core_brate, CFREQ_BITRATE ) ) + { + IF( LT_32( st_fx->core_brate, ACELP_9k60 ) ) + { + if ( pit_contr_idx > 0 ) + { + pit_contr_idx = 1; + move16(); + } + + IF( EQ_16( st_fx->coder_type, INACTIVE ) ) + { + push_indice( hBstr, IND_PIT_CONTR_IDX, pit_contr_idx, 1 ); + } + } + ELSE + { + push_indice( hBstr, IND_PIT_CONTR_IDX, pit_contr_idx, 3 ); + } + } + ELSE + { + push_indice( hBstr, IND_PIT_CONTR_IDX, pit_contr_idx, 4 ); + } + + return last_pit_bin; +} diff --git a/lib_enc/gain_enc_fx.c b/lib_enc/gain_enc_fx.c index 2e53060b5..630dd5aeb 100644 --- a/lib_enc/gain_enc_fx.c +++ b/lib_enc/gain_enc_fx.c @@ -811,8 +811,8 @@ void gain_enc_mless_ivas_fx( qua_table = gain_qua_mless_6b_fx; if ( GT_16( element_mode, EVS_MONO ) ) { -#ifdef IVAS_CODE - qua_table = gain_qua_mless_6b_stereo; +#if 1 // def IVAS_CODE + qua_table = gain_qua_mless_6b_stereo_fx; #else // PMTE() #endif @@ -1174,6 +1174,297 @@ void gain_enc_SQ_fx( return; } +void gain_enc_SQ_ivas_fx( + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + const Word16 gains_mode[], /* i : gain bits */ + const Word16 i_subfr, /* i : subframe index */ + const Word16 *xn, /* i : target vector Q_xn */ + const Word16 *yy1, /* i : zero-memory filtered adaptive excitation Q_xn */ + const Word16 *y2, /* i : zero-memory filtered algebraic codebook excitation Q9 */ + const Word16 *code, /* i : algebraic excitation Q9 */ + const Word16 Es_pred, /* i : predicted scaled innovation energy Q8 */ + Word16 *gain_pit, /* o : quantized pitch gain Q14 */ + Word32 *gain_code, /* o : quantized codebook gain Q16 */ + Word16 *gain_inov, /* o : gain of the innovation (used for normalization) Q12 */ + Word32 *norm_gain_code, /* o : norm. gain of the codebook excitation Q16 */ + Word16 *g_corr, /* i/o: correlations , ,, -2 and 2 */ + const Word16 clip_gain, /* i : gain pitch clipping flag (1 = clipping) */ + const Word16 Q_xn /* i : xn and y1 scaling */ +) +{ + Word16 index, nBits_pitch, nBits_code; + Word16 gcode0, Ei, gain_code16; + Word16 coeff[5], exp_coeff[5]; + Word16 exp, exp_code, exp_inov, exp_gcode0, frac, tmp; + + Word32 L_tmp, L_tmp1, L_tmp2; + Word16 tmp1, expg; + Word16 exp1, exp2; + Word16 exp_num, exp_den, exp_div, frac_den; + Word32 L_frac_num, L_frac_den, L_div; +#ifdef BASOP_NOGLOB_DECLARE_LOCAL + Flag Overflow = 0; +#endif + + /*-----------------------------------------------------------------* + * calculate the rest of the correlation coefficients + * c2 = , c3 = -2, c4 = 2 + *-----------------------------------------------------------------*/ + /*g_corr[1] *= -0.5;*/ + /*g_corr[2] = dotp( y2, y2, L_SUBFR ) + 0.01f;*/ + /*g_corr[3] = dotp( xn, y2, L_SUBFR ) - 0.02f;*/ + /*g_corr[4] = dotp( yy1, y2, L_SUBFR ) + 0.02f;*/ + + coeff[0] = g_corr[0]; + move16(); + exp_coeff[0] = g_corr[1]; + move16(); + coeff[1] = g_corr[2]; + move16(); /* coeff[1] = xn yy1 */ + exp_coeff[1] = g_corr[3]; + move16(); + + /* Compute scalar product */ + coeff[2] = extract_h( Dot_product12( y2, y2, L_SUBFR, &exp ) ); + exp_coeff[2] = add( sub( exp, 18 ), shl( Q_xn, 1 ) ); + move16(); /* -18 (y2 Q9) */ + + /* Compute scalar product */ + coeff[3] = extract_h( Dot_product12( xn, y2, L_SUBFR, &exp ) ); + exp_coeff[3] = add( sub( exp, 9 ), Q_xn ); + move16(); /* -9 (y2 Q9), (xn y2) */ + + /* Compute scalar product */ + coeff[4] = extract_h( Dot_product12( yy1, y2, L_SUBFR, &exp ) ); + exp_coeff[4] = add( sub( exp, 9 ), Q_xn ); + move16(); /* -9 (y2 Q9), (y1 y2) */ + + /*-----------------------------------------------------------------* + * calculate the unscaled innovation energy + * calculate the predicted gain code + * calculate optimal gains + *-----------------------------------------------------------------*/ + /*Ecode = (dotp( code, code, L_SUBFR) + 0.01f) / L_SUBFR;*/ + /**gain_inov = 1.0f / (float)sqrt( Ecode );*/ + + L_tmp = Dot_product12( code, code, L_SUBFR, &exp_code ); + exp_inov = sub( exp_code, 18 + 6 ); + exp_code = sub( exp_code, 30 ); + + /*Ei = 10 * log10((dot_product(code, code, L_SUBFR) + 0.01) / L_SUBFR) */ + /*----------------------------------------------------------------* + * calculate the predicted gain code + *----------------------------------------------------------------*/ + tmp = norm_l( L_tmp ); + frac = Log2_norm_lc( L_shl( L_tmp, tmp ) ); + tmp = add( 30 - 18 - 6 - 1, sub( exp_code, tmp ) ); /* exp: -18 (code in Q9), -6 (/L_SUBFR) */ + L_tmp1 = Mpy_32_16( tmp, frac, 12330 ); /* Q13 */ + Ei = round_fx( L_shl( L_tmp1, 11 ) ); /* Q8 */ + + /* predicted codebook gain */ + gcode0 = sub( Es_pred, Ei ); /* Q8 */ + + /*---------------------------------------------------------------* + * Decode codebook gain and the adaptive excitation low-pass + * filtering factor (Finalize computation ) + *---------------------------------------------------------------*/ + /* gain_inov = 1.0f / sqrt((dot_product(code, code, L_SUBFR) + 0.01) / L_SUBFR) */ + L_tmp = Isqrt_lc( L_tmp, &exp_inov ); + *gain_inov = extract_h( L_shl( L_tmp, sub( exp_inov, 3 ) ) ); /* gain_inov in Q12 */ + + /* gcode0 = pow(10, 0.05 * (Es_pred - Ei)) */ + /*----------------------------------------------------------------* + * gcode0 = pow(10.0, gcode0/20) + * = pow(2, 3.321928*gcode0/20) + * = pow(2, 0.166096*gcode0) + *----------------------------------------------------------------*/ + + L_tmp = L_mult( gcode0, 21771 ); /* *0.166096 in Q17 -> Q26 */ + L_tmp = L_shr( L_tmp, 10 ); /* From Q26 to Q16 */ + frac = L_Extract_lc( L_tmp, &exp_gcode0 ); /* Extract exponent of gcode0 */ + + gcode0 = extract_l( Pow2( 14, frac ) ); /* Put 14 as exponent so that */ + /* output of Pow2() will be: */ + /* 16384 < Pow2() <= 32767 */ + exp_gcode0 = sub( exp_gcode0, 14 ); + + + /*tmp1 = (g_corr[0]*g_corr[2]) - (g_corr[4]*g_corr[4]); + tmp2 = g_corr[1]/tmp1; + tmp1 = g_corr[3]/tmp1; + + *gain_pit = (g_corr[2]*tmp2) - (g_corr[4]*tmp1); + *gain_code = (g_corr[0]*tmp1) - (g_corr[4]*tmp2);*/ + + /* *gain_pit = (g_corr[2]*tmp2) - (g_corr[4]*tmp3); + = ((g_corr[1]*g_corr[2]) - (g_corr[3]*g_corr[4]))/tmp1;*/ + + /* *gain_code = (g_corr[0]*tmp3) - (g_corr[4]*tmp2); + = ((g_corr[3]*g_corr[0]) - (g_corr[1]*g_corr[4]))/tmp1;*/ + + L_tmp1 = L_mult( coeff[0], coeff[2] ); /*Q31*/ + exp1 = add( exp_coeff[0], exp_coeff[2] ); + +#ifdef BASOP_NOGLOB + L_tmp2 = L_mult_o( coeff[4], coeff[4], &Overflow ); /*Q31*/ +#else + L_tmp2 = L_mult( coeff[4], coeff[4] ); /*Q31*/ +#endif + exp2 = add( exp_coeff[4], exp_coeff[4] ); + + IF( GT_16( exp1, exp2 ) ) + { + L_tmp2 = L_shr( L_tmp2, sub( exp1, exp2 ) ); /*Q31*/ + exp_den = exp1; + move16(); + } + ELSE + { + L_tmp1 = L_shr( L_tmp1, sub( exp2, exp1 ) ); /*Q31*/ + exp_den = exp2; + move16(); + } + L_frac_den = L_sub( L_tmp1, L_tmp2 ); /*Q31*/ + + frac_den = extract_h( L_frac_den ); + frac_den = s_max( frac_den, 1 ); + L_frac_den = L_max( L_frac_den, 1 ); + exp = norm_l( L_frac_den ); + tmp = div_s( shl( 1, sub( 14, exp ) ), frac_den ); /*Q(14-exp)*/ + + + L_tmp1 = L_mult( coeff[3], coeff[4] ); /*Q31*/ + exp1 = add( exp_coeff[3], exp_coeff[4] ); + + L_tmp2 = L_mult( coeff[1], coeff[2] ); /*Q31*/ + exp2 = add( exp_coeff[1], exp_coeff[2] ); + + IF( GT_16( exp1, exp2 ) ) + { + L_tmp2 = L_shr( L_tmp2, sub( exp1, exp2 ) ); /*Q31*/ + exp_num = exp1; + move16(); + } + ELSE + { + L_tmp1 = L_shr( L_tmp1, sub( exp2, exp1 ) ); /*Q31*/ + exp_num = exp2; + move16(); + } +#ifdef BASOP_NOGLOB + L_frac_num = L_sub_o( L_tmp2, L_tmp1, &Overflow ); /*Q31*/ +#else /* BASOP_NOGLOB */ + L_frac_num = L_sub( L_tmp2, L_tmp1 ); /*Q31*/ +#endif /* BASOP_NOGLOB */ + + L_div = Mult_32_16( L_frac_num, tmp ); /*Q(30-exp)*/ + exp_div = sub( exp_num, exp_den ); + +#ifdef BASOP_NOGLOB + *gain_pit = round_fx_o( L_shl_o( L_div, add( exp, exp_div ), &Overflow ), &Overflow ); /*Q14*/ +#else /* BASOP_NOGLOB */ + *gain_pit = round_fx( L_shl( L_div, add( exp, exp_div ) ) ); /*Q14*/ +#endif /* BASOP_NOGLOB */ + + L_tmp1 = L_mult( coeff[1], coeff[4] ); /*Q31*/ + exp1 = add( exp_coeff[1], exp_coeff[4] ); + + L_tmp2 = L_mult( coeff[0], coeff[3] ); /*Q31*/ + exp2 = add( exp_coeff[0], exp_coeff[3] ); + + IF( GT_16( exp1, exp2 ) ) + { + L_tmp2 = L_shr( L_tmp2, sub( exp1, exp2 ) ); /*Q31*/ + exp_num = exp1; + } + ELSE + { + L_tmp1 = L_shr( L_tmp1, sub( exp2, exp1 ) ); /*Q31*/ + exp_num = exp2; + } +#ifdef BASOP_NOGLOB + L_frac_num = L_sub_o( L_tmp2, L_tmp1, &Overflow ); /*Q31*/ +#else /* BASOP_NOGLOB */ + L_frac_num = L_sub( L_tmp2, L_tmp1 ); /*Q31*/ +#endif /* BASOP_NOGLOB */ + + L_div = Mult_32_16( L_frac_num, tmp ); /*Q(30-exp)*/ + exp_div = sub( exp_num, exp_den ); + +#ifdef BASOP_NOGLOB + *gain_code = L_shl_sat( L_div, s_max( -31, sub( add( exp, exp_div ), 14 ) ) ); +#else + *gain_code = L_shl( L_div, s_max( -31, sub( add( exp, exp_div ), 14 ) ) ); +#endif + move32(); /*Q16*/ + + *gain_pit = s_max( G_PITCH_MIN_Q14, s_min( *gain_pit, G_PITCH_MAX_Q14 ) ); + + /*-----------------------------------------------------------------* + * limit the pitch gain searching range (if indicated by clip_gain) + *-----------------------------------------------------------------*/ + + test(); + test(); + IF( EQ_16( clip_gain, 1 ) && GT_16( *gain_pit, 15565 ) ) + { + *gain_pit = 15565; + move16(); + } + ELSE IF( EQ_16( clip_gain, 2 ) && GT_16( *gain_pit, 10650 ) ) + { + *gain_pit = 10650; + move16(); + } + + /*-----------------------------------------------------------------* + * search for the best quantized values + *-----------------------------------------------------------------*/ + + nBits_pitch = gains_mode[shr( i_subfr, 6 )]; + + /* set number of bits for two SQs */ + nBits_code = shr( add( nBits_pitch, 1 ), 1 ); + nBits_pitch = shr( nBits_pitch, 1 ); + + /* gain_pit Q */ + /*tmp1 = (G_PITCH_MAX - G_PITCH_MIN) / ((1 << nBits_pitch) - 1);*/ /* set quantization step */ + tmp1 = mult_r( G_PITCH_MAX_Q13, div_s( 1, sub( shl( 1, nBits_pitch ), 1 ) ) ); /*Q13*/ /* set quantization step */ + + index = usquant_fx( *gain_pit, gain_pit, G_PITCH_MIN_Q14, tmp1, shl( 1, nBits_pitch ) ); + move16(); + push_indice( hBstr, IND_GAIN_PIT, index, nBits_pitch ); + + /* gain_code Q */ + /* *gain_code /= gcode0; */ + IF( gcode0 != 0 ) + { + tmp = div_s( 16384, gcode0 ); /*Q15*/ + L_tmp = Mult_32_16( *gain_code, tmp ); /*Q16*/ + *gain_code = L_shr( L_tmp, add( 14, exp_gcode0 ) ); /*Q16*/ + } + + index = gain_quant_fx( gain_code, &gain_code16, LG10_G_CODE_MIN_Q14, LG10_G_CODE_MAX_Q13, nBits_code, &expg ); + push_indice( hBstr, IND_GAIN_CODE, index, nBits_code ); + L_tmp = L_mult( gain_code16, gcode0 ); /*Q0*Q0 -> Q1*/ +#ifdef BASOP_NOGLOB + *gain_code = L_shl_sat( L_tmp, add( add( expg, exp_gcode0 ), 15 ) ); +#else + *gain_code = L_shl( L_tmp, add( add( expg, exp_gcode0 ), 15 ) ); +#endif + move32(); /*Q16*/ + + /* *norm_gain_code = *gain_code / *gain_inov; */ + exp = sub( norm_s( *gain_inov ), 1 ); + exp = s_max( exp, 0 ); + + tmp = div_s( shr( 8192, exp ), *gain_inov ); + *norm_gain_code = L_shr( Mult_32_16( *gain_code, tmp ), sub( 1, exp ) ); + move32(); + + return; +} + /*-------------------------------------------------------------------* * gain_enc_gaus() * @@ -1426,6 +1717,192 @@ void gain_enc_tc_fx( move32(); return; } + +void gain_enc_tc_ivas_fx( + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + const Word16 gains_mode[], /* i : gain bits */ + const Word16 i_subfr, /* i : subframe index */ + const Word16 xn_fx[], /* i : target vector */ + const Word16 y2_fx[], /* i : zero-memory filtered algebraic codebook excitation */ + const Word16 code_fx[], /* i : algebraic excitation */ + const Word16 Es_pred_fx, /* i : predicted scaled innovation energy */ + Word16 *gain_pit_fx, /* o : Pitch gain / Quantized pitch gain */ + Word32 *gain_code_fx, /* o : quantized codebook gain */ + Word16 *gain_inov_fx, /* o : innovation gain */ + Word32 *norm_gain_code_fx, /* o : norm. gain of the codebook excitation */ + const Word16 Q_xn /* i : xn and y1 scaling Q0 */ +) +{ + Word16 i, index = 0, nBits, num, den, exp_num, exp_den; + Word16 Ei_fx, g_code_fx, gcode0_fx; + Word16 expg, expg2, e_tmp, f_tmp, exp_gcode0, tmp_fx, frac, tmp16; + Word32 L_tmp, L_tmp1; + Word16 wgain_code = 0, gain_code16; + *gain_pit_fx = 0; + move16(); + /*----------------------------------------------------------------* + * get number of bits for gain quantization + *----------------------------------------------------------------*/ + nBits = gains_mode[shr( i_subfr, 6 )]; + + /*----------------------------------------------------------------* + * find the code pitch (for current subframe) + *----------------------------------------------------------------*/ + + /**gain_code = dotp( xn, y2, L_SUBFR )/( dotp( y2, y2, L_SUBFR ) + 0.01f );*/ + /* Compute scalar product */ + L_tmp = Dot_product( y2_fx, y2_fx, L_SUBFR ); /* -18 (y2 Q9) */ + exp_den = norm_l( L_tmp ); + den = extract_h( L_shl( L_tmp, exp_den ) ); + exp_den = sub( add( exp_den, 18 ), shl( Q_xn, 1 ) ); + + /* Compute scalar product */ + L_tmp1 = Dot_product( xn_fx, y2_fx, L_SUBFR ); /* -9 (y2 Q9) */ + exp_num = sub( norm_l( L_tmp1 ), 1 ); + num = extract_h( L_shl( L_tmp1, exp_num ) ); + exp_num = sub( add( exp_num, 8 ), Q_xn ); + + tmp16 = s_or( shr( num, 16 ), 1 ); /* extract sign if num < 0 tmp16 = -1 else tmp16 = 1 */ + num = abs_s( num ); + + /*----------------------------------------------------------------* + * compute gain = xy/yy + *----------------------------------------------------------------*/ + g_code_fx = div_s( num, den ); + + i = sub( exp_num, exp_den ); /* Gain_trans in Q7 */ + g_code_fx = i_mult2( g_code_fx, tmp16 ); /* apply sign */ +#ifdef BASOP_NOGLOB + *gain_code_fx = L_shr_sat( L_deposit_l( g_code_fx ), i ); +#else + *gain_code_fx = L_shr( L_deposit_l( g_code_fx ), i ); +#endif + move32(); + + /*----------------------------------------------------------------* + * calculate the predicted gain code + * decode codebook gain + *----------------------------------------------------------------*/ + + *gain_pit_fx = 0; + move16(); + + /*Ecode = (dotp( code, code, L_SUBFR) + 0.01f) / L_SUBFR; + *gain_inov = 1.0f / (float)sqrt( Ecode );*/ + + L_tmp = Dot_product12( code_fx, code_fx, L_SUBFR, &expg ); + expg = sub( expg, 18 + 6 ); /* exp: -18 (code in Q9), -6 (/L_SUBFR) */ + expg2 = expg; + move16(); + L_tmp1 = L_tmp; /* sets to 'L_tmp' in 1 clock */ + move32(); + L_tmp = Isqrt_lc( L_tmp, &expg ); + + *gain_inov_fx = extract_h( L_shl( L_tmp, sub( expg, 3 ) ) ); + move16(); /* gain_inov in Q12 */ + + /*Ei = 10 * (float)log10( Ecode );*/ + e_tmp = norm_l( L_tmp1 ); + f_tmp = Log2_norm_lc( L_shl( L_tmp1, e_tmp ) ); + e_tmp = sub( expg2, add( 1, e_tmp ) ); + L_tmp1 = Mpy_32_16( e_tmp, f_tmp, 12330 ); /* Q13 */ /* 10*log10(2) in Q12*/ + Ei_fx = round_fx( L_shl( L_tmp1, 11 ) ); /* Q8 */ + /*gcode0 = (float) pow(10, 0.05 * (Es_pred - Ei));*/ + gcode0_fx = sub( Es_pred_fx, Ei_fx ); /* Q8 */ + /*-----------------------------------------------------------------* + * gcode0 = pow(10.0, gcode0/20) + * = pow(2, 3.321928*gcode0/20) + * = pow(2, 0.166096*gcode0) + *-----------------------------------------------------------------*/ + L_tmp = L_mult( gcode0_fx, 21771 ); /* *0.166096 in Q17 -> Q26 */ + L_tmp = L_shr( L_tmp, 10 ); /* From Q26 to Q16 */ + frac = L_Extract_lc( L_tmp, &exp_gcode0 ); /* Extract exponent of gcode0 */ + gcode0_fx = extract_l( Pow2( 14, frac ) ); /* Put 14 as exponent so that */ + exp_gcode0 = sub( exp_gcode0, 14 ); + IF( GT_16( nBits, 3 ) ) + { + /*g_code = *gain_code / gcode0;*/ + IF( gcode0_fx != 0 ) + { + tmp16 = div_s( 16384, gcode0_fx ); /*Q15*/ + L_tmp = Mult_32_16( *gain_code_fx, tmp16 ); /*Q16*/ + *gain_code_fx = L_shr( L_tmp, add( 14, exp_gcode0 ) ); /*Q16*/ + } + ELSE + { + *gain_code_fx = MAX_32; + move32(); + } + + /*index = gain_quant( &g_code, G_CODE_MIN, G_CODE_MAX, nBits );*/ + index = gain_quant_fx( gain_code_fx, &gain_code16, LG10_G_CODE_MIN_TC_Q14, LG10_G_CODE_MAX_TC_Q13, nBits, &expg ); + + /**gain_code = g_code * gcode0;*/ + L_tmp = L_mult( gain_code16, gcode0_fx ); /*Q0*Q0 -> Q1*/ + *gain_code_fx = L_shl( L_tmp, add( add( expg, exp_gcode0 ), 15 ) ); /*Q16*/ + move32(); + + push_indice( hBstr, IND_GAIN_CODE, index, nBits ); + } + ELSE + { + index = N_GAIN_CODE_TC - 1; + move16(); + FOR( i = 0; i < N_GAIN_CODE_TC - 1; i++ ) + { + L_tmp = L_mult( tbl_gain_code_tc_quant_mean[i], gcode0_fx ); /* Q13*Q0 -> Q14 */ + L_tmp = L_shl( L_tmp, add( exp_gcode0, 2 ) ); /* Q14 -> Q16 */ + + IF( LT_32( *gain_code_fx, L_tmp ) ) + { + index = i; + move16(); + BREAK; + } + } + /*----------------------------------------------------------------* + * 3-bit -> 2-bit encoding + *----------------------------------------------------------------*/ + IF( EQ_16( nBits, 2 ) ) + { + /* 2-bit -> 3-bit decoding */ + index = shr( index, 1 ); + wgain_code = tbl_gain_code_tc_fx[shl( index, 1 )]; + move16(); + /**gain_code *= gcode0;*/ + L_tmp = L_mult( wgain_code, gcode0_fx ); /* Q13*Q0 -> Q14 */ + *gain_code_fx = L_shl( L_tmp, add( exp_gcode0, 2 ) ); + move32(); /* Q14 -> Q16 */ + push_indice( hBstr, IND_GAIN_CODE, index, nBits ); + } + ELSE /* nBits == 3 */ + { + wgain_code = tbl_gain_code_tc_fx[index]; + move16(); + /**gain_code *= gcode0;*/ + L_tmp = L_mult( wgain_code, gcode0_fx ); /* Q13*Q0 -> Q14 */ +#ifdef BASOP_NOGLOB + *gain_code_fx = L_shl_sat( L_tmp, add( exp_gcode0, 2 ) ); +#else + *gain_code_fx = L_shl( L_tmp, add( exp_gcode0, 2 ) ); +#endif + move32(); /* Q14 -> Q16 */ + push_indice( hBstr, IND_GAIN_CODE, index, nBits ); + } + } + + /*-----------------------------------------------------------------* + * decode normalized codebook gain + *-----------------------------------------------------------------*/ + /**norm_gain_code = *gain_code / *gain_inov;*/ + expg = sub( norm_s( *gain_inov_fx ), 1 ); + expg = s_max( expg, 0 ); + + tmp_fx = div_s( shr( 8192, expg ), *gain_inov_fx ); + *norm_gain_code_fx = L_shr( Mult_32_16( *gain_code_fx, tmp_fx ), sub( 1, expg ) ); + move32(); + return; +} /*-----------------------------------------------------------------* * Find_Opt_gainQ_fx() * diff --git a/lib_enc/gaus_enc_fx.c b/lib_enc/gaus_enc_fx.c index 57a336ec2..5bded2603 100644 --- a/lib_enc/gaus_enc_fx.c +++ b/lib_enc/gaus_enc_fx.c @@ -2,12 +2,12 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ -#include "cnst.h" /* Common constants */ -#include "rom_com_fx.h" /* Static table prototypes */ -#include "rom_com.h" /* Static table prototypes */ -#include "rom_enc.h" /* Static table prototypes */ -//#include "prot_fx.h" /* Function prototypes */ +#include "options.h" /* Compilation switches */ +#include "cnst.h" /* Common constants */ +#include "rom_com_fx.h" /* Static table prototypes */ +#include "rom_com.h" /* Static table prototypes */ +#include "rom_enc.h" /* Static table prototypes */ +#include "prot.h" /* Function prototypes */ #include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ //#include "basop_mpy.h" @@ -141,6 +141,109 @@ Word16 gaus_encode_fx( return ( L_SUBFR << 6 ); } +Word16 gaus_encode_ivas_fx( + Encoder_State *st_fx, /* i/o: encoder state structure */ + const Word16 i_subfr, /* i : subframe index */ + const Word16 *h1, /* i : weighted filter input response */ + const Word16 *xn, /* i : target vector */ + Word16 *exc, /* o : pointer to excitation signal frame */ + Word16 *mem_w0, /* o : weighting filter denominator memory */ + Word16 *clip_gain, /* o : memory of gain of pitch clipping algorithm */ + Word16 *tilt_code, /* o : synthesis excitation spectrum tilt */ + Word16 *code, /* o : algebraic excitation Q9 */ + Word32 *gain_code, /* o : Code gain. Q16 */ + Word16 *y2, /* o : zero-memory filtered adaptive excitation Q9 */ + Word16 *gain_inov, /* o : innovation gain Q12 */ + Word16 *voice_fac, /* o : voicing factor Q15 */ + Word16 *gain_pit, /* o : adaptive excitation gain Q14 */ + const Word16 Q_new, /* i : scaling factor */ + const Word16 shift, /* i : scaling factor */ + Word32 *norm_gain_code /* o : normalized innovative cb. gain Q16 */ +) +{ + Word16 nb_bits, idx; + Word16 i = 0; + Word32 Ltmp; + Word16 dn[L_SUBFR], exp_code, gcode; /* Correlation between xn and h1 */ + Word16 exp, tmp, tmp_idx; +#ifdef BASOP_NOGLOB_DECLARE_LOCAL + Flag Overflow = 0; +#endif + + /*----------------------------------------------------------------* + * Encode gaussian excitation + *----------------------------------------------------------------*/ + + /* Correlation between target xn2[] and impulse response h1[] */ + corr_xh_fx( xn, dn, h1 ); + + tmp_idx = shr( i_subfr, 6 ); + nb_bits = st_fx->acelp_cfg.fixed_cdk_index[tmp_idx]; + move16(); + + gauss2v_fx( st_fx->hBstr, h1, xn, dn, code, y2, gain_code, L_SUBFR, shift, Q_new, shr( nb_bits, 1 ) ); + + /*----------------------------------------------------------------* + * Encode gaussian gain + *----------------------------------------------------------------*/ + + /* codeword energy computation */ + Ltmp = Dot_product12( code, code, L_SUBFR, &exp_code ); + + exp_code = sub( exp_code, 18 + 6 ); /* exp: -18 (code in Q9), -6 (L_subfr = 64) */ + Ltmp = Isqrt_lc( Ltmp, &exp_code ); + *gain_inov = extract_h( L_shl( Ltmp, sub( exp_code, 3 ) ) ); /* g_code_inov in Q12 */ + + nb_bits = st_fx->acelp_cfg.gains_mode[tmp_idx]; + move16(); + /* low bound = -30; stepSize = 1.71875; inv_stepSize = 0.5818181 */ + idx = gain_enc_gaus_fx( gain_code, nb_bits, -7680, 28160, 19065 ); + push_indice( st_fx->hBstr, IND_GAIN, idx, nb_bits ); + + /*----------------------------------------------------------------* + * Total excitation for Unvoiced coders + *----------------------------------------------------------------*/ +#ifdef BASOP_NOGLOB + gcode = round_fx_o( L_shl_o( *gain_code, Q_new, &Overflow ), &Overflow ); /* scaled gain_code with Qnew */ +#else /* BASOP_NOGLOB */ + gcode = round_fx( L_shl( *gain_code, Q_new ) ); /* scaled gain_code with Qnew */ +#endif /* BASOP_NOGLOB */ + FOR( i = 0; i < L_SUBFR; i++ ) + { + exc[i + i_subfr] = round_fx( L_shl( L_mult( gcode, code[i] ), 15 - 9 ) ); + } + + /*----------------------------------------------------------------* + * Updates: last value of new target is stored in mem_w0 + *----------------------------------------------------------------*/ + + Ltmp = L_mult( gcode, y2[L_SUBFR - 1] ); + Ltmp = L_shl( Ltmp, add( 5, shift ) ); + Ltmp = L_negate( Ltmp ); + Ltmp = L_mac( Ltmp, xn[L_SUBFR - 1], 16384 ); +#ifdef BASOP_NOGLOB + Ltmp = L_shl_sat( Ltmp, sub( 1, shift ) ); + *mem_w0 = round_fx_sat( Ltmp ); +#else + Ltmp = L_shl( Ltmp, sub( 1, shift ) ); + *mem_w0 = round_fx( Ltmp ); +#endif + init_gp_clip_fx( clip_gain ); /* reset pitch clipping parameters */ + + *gain_pit = 0; + *tilt_code = 0; + move16(); /* purely unvoiced */ + *voice_fac = -32768; + move16(); /* purely unvoiced */ + exp = sub( norm_s( *gain_inov ), 1 ); + exp = s_max( exp, 0 ); + + tmp = div_s( shr( 8192, exp ), *gain_inov ); + *norm_gain_code = L_shr( Mult_32_16( *gain_code, tmp ), sub( 1, exp ) ); + move16(); + + return ( L_SUBFR << 6 ); +} /*-------------------------------------------------------------------* * gauss2v() * diff --git a/lib_enc/gp_clip_fx.c b/lib_enc/gp_clip_fx.c index 6a98b1d47..9eba45cb8 100644 --- a/lib_enc/gp_clip_fx.c +++ b/lib_enc/gp_clip_fx.c @@ -160,7 +160,7 @@ Word16 gp_clip_fx( e_ener = norm_l( ener ); f_ener = Log2_norm_lc( L_shl( ener, e_ener ) ); e_ener = sub( 30, e_ener ); - e_ener = sub( e_ener, Q_new ); + e_ener = sub( e_ener, Q_new * 2 + 1 ); ener = Mpy_32_16( e_ener, f_ener, LG10 ); wener = round_fx( L_shl( ener, 10 ) ); diff --git a/lib_enc/gs_enc_fx.c b/lib_enc/gs_enc_fx.c index 95557d238..e1cd71e0a 100644 --- a/lib_enc/gs_enc_fx.c +++ b/lib_enc/gs_enc_fx.c @@ -372,6 +372,358 @@ void encod_audio_fx( return; } +void encod_audio_ivas_fx( + Encoder_State *st_fx, /* i/o: State structure */ + const Word16 speech[], /* i : input speech Q_new */ + const Word16 Aw[], /* i : weighted A(z) unquantized for subframes */ + const Word16 Aq[], /* i : 12k8 Lp coefficient */ + const Word16 *res, /* i : residual signal Q_new */ + Word16 *synth, /* i/o: core synthesis Q-1 */ + Word16 *exc, /* i/o: current non-enhanced excitation Q_new */ + Word16 *pitch_buf, /* i/o: floating pitch values for each subframe Q6 */ + Word16 *voice_factors, /* o : voicing factors Q15 */ + Word16 *bwe_exc, /* o : excitation for SWB TBE Q0 */ + const Word16 attack_flag, /* i : Flag that point to an attack coded with AC mode (GSC) */ + Word16 *lsf_new, /* i : current frame ISF vector */ + Word16 *tmp_noise, /* o : noise energy */ + const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag */ + const Word16 tdm_Pri_pitch_buf[], /* i : primary channel pitch buffer */ + Word16 Q_new, + Word16 shift ) +{ + const Word16 *p_Aq; + Word16 i, i_subfr, nb_subfr, last_pit_bin; + Word16 T0_tmp, T0_frac_tmp, nb_subfr_flag; + Word16 tmp_nb_bits_tot = 0; + Word16 Es_pred; + Word16 dct_res[L_FRAME16k], dct_epit[L_FRAME16k]; + Word16 m_mean = 0; + Word16 saved_bit_pos; + Word16 exc_wo_nf[L_FRAME16k]; + Word32 Lm_mean; + Word16 nb_bits; + Word16 indice; + SP_MUS_CLAS_HANDLE hSpMusClas = st_fx->hSpMusClas; + GSC_ENC_HANDLE hGSCEnc = st_fx->hGSCEnc; + BSTR_ENC_HANDLE hBstr = st_fx->hBstr; + LPD_state_HANDLE hLPDmem = st_fx->hLPDmem; + + m_mean = 0; + move16(); + tmp_nb_bits_tot = 0; + move16(); + + T0_tmp = 64; + move16(); + T0_frac_tmp = 0; + move16(); + Copy( hLPDmem->mem_syn, hGSCEnc->mem_syn_tmp_fx, M ); + hGSCEnc->mem_w0_tmp_fx = hLPDmem->mem_w0; + move16(); + Es_pred = 0; + move16(); + + /*---------------------------------------------------------------* + * Encode GSC IVAS mode + * Encode GSC attack flag (used to reduce possible pre-echo) + * Encode GSC SWB speech flag + *---------------------------------------------------------------*/ +#if 1 // def GSC_IVAS // TVB -->>>>>> + test(); + if ( GT_16( st_fx->element_mode, EVS_MONO ) && st_fx->idchan == 0 ) + { + push_indice( hBstr, IND_GSC_IVAS_SP, st_fx->GSC_IVAS_mode, 2 ); + } +#endif + IF( attack_flag > 0 ) + { + push_indice( hBstr, IND_GSC_ATTACK, 1, 1 ); + } + ELSE + { + push_indice( hBstr, IND_GSC_ATTACK, 0, 1 ); + } + + + test(); + test(); + test(); + test(); + test(); + test(); + IF( GE_16( st_fx->GSC_IVAS_mode, 1 ) || ( NE_16( st_fx->coder_type, INACTIVE ) && ( ( EQ_16( st_fx->element_mode, EVS_MONO ) && GE_32( st_fx->total_brate, ACELP_13k20 ) ) || + ( GT_16( st_fx->element_mode, EVS_MONO ) && GT_32( st_fx->total_brate, MIN_BRATE_GSC_NOISY_FLAG ) && GE_16( st_fx->bwidth, SWB ) && !st_fx->flag_ACELP16k ) ) ) ) + { + push_indice( hBstr, IND_GSC_SWB_SPEECH, st_fx->GSC_noisy_speech, 1 ); + } + /*---------------------------------------------------------------* + * Find and encode the number of subframes + *---------------------------------------------------------------*/ + test(); + IF( GE_32( st_fx->core_brate, ACELP_9k60 ) && LE_32( st_fx->core_brate, ACELP_13k20 ) ) + { + FOR( i = 0; i < 5; i++ ) + { + test(); + if ( GT_16( abs_s( hSpMusClas->gsc_lt_diff_etot_fx[MAX_LT - i - 1] ), 1536 ) && EQ_16( hGSCEnc->cor_strong_limit, 1 ) ) + { + hGSCEnc->cor_strong_limit = 0; + move16(); + } + } + } + test(); + IF( GE_16( st_fx->GSC_IVAS_mode, 1 ) || ( st_fx->GSC_noisy_speech && st_fx->GSC_IVAS_mode == 0 ) ) + { + nb_subfr = NB_SUBFR; + move16(); + test(); + test(); + if ( st_fx->GSC_IVAS_mode > 0 && LT_16( st_fx->GSC_IVAS_mode, 3 ) && LT_32( st_fx->core_brate, GSC_L_RATE_STG ) ) + { + nb_subfr = 2; + move16(); + } + hGSCEnc->cor_strong_limit = 0; + move16(); + nb_subfr_flag = 1; + move16(); + } + ELSE IF( EQ_16( st_fx->L_frame, L_FRAME16k ) && ( LE_32( st_fx->core_brate, ACELP_13k20 ) || EQ_16( st_fx->coder_type, INACTIVE ) ) ) + { + hGSCEnc->cor_strong_limit = 0; + nb_subfr = SWNB_SUBFR; + nb_subfr_flag = 1; + move16(); + move16(); + move16(); + } + ELSE + { + test(); + test(); + IF( ( hGSCEnc->cor_strong_limit == 0 || EQ_16( st_fx->coder_type, INACTIVE ) ) && GE_32( st_fx->core_brate, ACELP_9k60 ) ) + { + nb_subfr = 2; + move16(); + nb_subfr_flag = 0; + move16(); + hGSCEnc->cor_strong_limit = 0; + move16(); + } + ELSE + { + nb_subfr = SWNB_SUBFR; + move16(); + nb_subfr_flag = 1; + move16(); + } + IF( EQ_16( st_fx->L_frame, L_FRAME16k ) && ( GT_16( hSpMusClas->mold_corr_fx, 26214 ) && GE_32( st_fx->core_brate, MIN_RATE_4SBFR ) && NE_16( st_fx->coder_type, INACTIVE ) ) ) + { + nb_subfr = shl( nb_subfr, 1 ); + nb_subfr_flag |= 0x2; + logic16(); + } + + IF( EQ_16( st_fx->L_frame, L_FRAME16k ) && GE_32( st_fx->core_brate, MIN_RATE_4SBFR ) ) + { + push_indice( hBstr, IND_HF_NOISE, nb_subfr_flag, 2 ); + } + ELSE IF( GE_32( st_fx->core_brate, ACELP_9k60 ) ) + { + /* nb_subfr_flag can only have the value 0 or 1 */ + push_indice( hBstr, IND_HF_NOISE, nb_subfr_flag, 1 ); + } + } + test(); + if ( EQ_16( st_fx->L_frame, L_FRAME16k ) && EQ_16( nb_subfr, NB_SUBFR ) ) + { + nb_subfr = NB_SUBFR16k; + move16(); + } + + /*---------------------------------------------------------------* + * Compute adaptive (pitch) excitation contribution + *---------------------------------------------------------------*/ + + test(); + IF( !( st_fx->GSC_IVAS_mode > 0 && EQ_16( st_fx->L_frame, i_mult( nb_subfr, 2 * L_SUBFR ) ) && LT_16( st_fx->GSC_IVAS_mode, 3 ) ) && + ( ( GE_32( st_fx->core_brate, MIN_RATE_FCB ) || st_fx->GSC_noisy_speech ) && + ( ( EQ_16( nb_subfr, NB_SUBFR ) && EQ_16( st_fx->L_frame, L_FRAME ) ) || ( EQ_16( nb_subfr, NB_SUBFR16k ) && EQ_16( st_fx->L_frame, L_FRAME16k ) ) ) ) ) + { + IF( GT_16( st_fx->element_mode, EVS_MONO ) ) + { + nb_bits = 5; + } + ELSE + { + nb_bits = Es_pred_bits_tbl[BIT_ALLOC_IDX_fx( st_fx->core_brate, GENERIC, -1, -1 )]; + move16(); + } + Es_pred_enc_fx( &Es_pred, &indice, st_fx->L_frame, res, st_fx->voicing_fx, nb_bits, 0, Q_new ); + push_indice( hBstr, IND_ES_PRED, indice, nb_bits ); + } + + enc_pit_exc_ivas_fx( st_fx, speech, Aw, Aq, Es_pred, res, synth, exc, &T0_tmp, + &T0_frac_tmp, pitch_buf, nb_subfr, &hGSCEnc->lt_gpitch_fx, &saved_bit_pos, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf, Q_new, shift ); + + /*---------------------------------------------------------------* + * DCT transform + *---------------------------------------------------------------*/ + edct_16fx( exc, dct_epit, st_fx->L_frame, 7, st_fx->element_mode ); + edct_16fx( res, dct_res, st_fx->L_frame, 7, st_fx->element_mode ); + /*---------------------------------------------------------------* + * Calculate energy dynamics + *---------------------------------------------------------------*/ + Lm_mean = L_deposit_l( 0 ); + FOR( i = 7; i < 15; i++ ) + { + /*m_mean = add(m_mean,edyn_fx( dct_res+i*16, 16, Q_new )); */ + Lm_mean = L_mac( Lm_mean, edyn_fx( dct_res + i * 16, 16, Q_new ), 4096 ); /*Q7*/ + } + m_mean = round_fx( Lm_mean ); /*Q7*/ + + IF( GT_16( m_mean, hGSCEnc->mid_dyn_fx ) ) + { + /*st_fx->mid_dyn_fx = 0.2f * st_fx->mid_dyn_fx + 0.8f * m_mean;*/ + hGSCEnc->mid_dyn_fx = round_fx( L_mac( L_mult( 26214, m_mean ), 6554, hGSCEnc->mid_dyn_fx ) ); /*Q7*/ + } + ELSE + { + /*st_fx->mid_dyn_fx = 0.6f * st_fx->mid_dyn_fx + 0.4f * m_mean;*/ + hGSCEnc->mid_dyn_fx = round_fx( L_mac( L_mult( 13107, m_mean ), 19661, hGSCEnc->mid_dyn_fx ) ); /*Q7*/ + } + IF( NE_16( st_fx->coder_type, INACTIVE ) ) + { + hGSCEnc->noise_lev = sub( ( NOISE_LEVEL_SP3 + 1 ), usquant_fx( hGSCEnc->mid_dyn_fx, &m_mean, MIN_DYNAMIC_FX, shr( GSF_NF_DELTA_FX, 1 ), GSC_NF_STEPS ) ); + + hGSCEnc->noise_lev = s_min( hGSCEnc->noise_lev, NOISE_LEVEL_SP3 ); + } + + hGSCEnc->past_dyn_dec = hGSCEnc->noise_lev; + move16(); + IF( GE_16( st_fx->GSC_IVAS_mode, 1 ) ) + { + hGSCEnc->noise_lev = NOISE_LEVEL_SP2; + IF( EQ_16( st_fx->GSC_IVAS_mode, 3 ) ) /* Music like */ + { + hGSCEnc->noise_lev = NOISE_LEVEL_SP0; + move16(); + } + ELSE IF( st_fx->GSC_noisy_speech == 0 ) + { + hGSCEnc->noise_lev = NOISE_LEVEL_SP3; + move16(); + } + } + ELSE IF( LE_32( st_fx->core_brate, ACELP_8k00 ) ) + { + hGSCEnc->noise_lev = s_max( hGSCEnc->noise_lev, NOISE_LEVEL_SP2 ); + push_indice( hBstr, IND_NOISE_LEVEL, sub( hGSCEnc->noise_lev, NOISE_LEVEL_SP2 ), 2 ); + } + ELSE IF( st_fx->GSC_noisy_speech ) + { + hGSCEnc->noise_lev = NOISE_LEVEL_SP3; + move16(); + } + ELSE + { + push_indice( hBstr, IND_NOISE_LEVEL, sub( hGSCEnc->noise_lev, NOISE_LEVEL_SP0 ), 3 ); + } + + /*---------------------------------------------------------------* + * Find and encode the last band where the adaptive (pitch) contribution is significant + *---------------------------------------------------------------*/ + + last_pit_bin = Pit_exc_contribution_len_ivas_fx( st_fx, dct_res, dct_epit, pitch_buf, nb_subfr, &hGSCEnc->pit_exc_hangover, Q_new ); + + IF( last_pit_bin == 0 ) + { + hLPDmem->tilt_code = 0; + move16(); + } + ELSE + { + /*last_pit_bin++;*/ + last_pit_bin = add( last_pit_bin, 1 ); + } + + /*--------------------------------------------------------------------------------------* + * GSC encoder + *--------------------------------------------------------------------------------------*/ + + /* Find the current total number of bits used */ + tmp_nb_bits_tot = hBstr->nb_bits_tot; + move16(); + + + if ( st_fx->extl_brate > 0 ) + { + /* subtract 1 bit for TBE/BWE BWE flag (bit counted in extl_brate) */ + tmp_nb_bits_tot = sub( tmp_nb_bits_tot, 1 ); + } + test(); + test(); + if ( EQ_16( st_fx->coder_type, INACTIVE ) && LE_32( st_fx->core_brate, ACELP_9k60 ) && st_fx->idchan == 0 ) + { + /* add 5 bits for noisiness */ + tmp_nb_bits_tot = add( tmp_nb_bits_tot, 5 ); + } + + Word16 Q_exc = Q_new; + move16(); + gsc_enc_ivas_fx( st_fx, dct_res, dct_epit, last_pit_bin, tmp_nb_bits_tot, nb_subfr, lsf_new, exc_wo_nf, tmp_noise, &Q_exc ); + + /*--------------------------------------------------------------------------------------* + * iDCT transform + *--------------------------------------------------------------------------------------*/ + + edct_16fx( dct_epit, exc, st_fx->L_frame, 7, st_fx->element_mode ); + edct_16fx( exc_wo_nf, exc_wo_nf, st_fx->L_frame, 7, st_fx->element_mode ); + /*--------------------------------------------------------------------------------------* + * Remove potential pre-echo in case an onset has been detected + *--------------------------------------------------------------------------------------*/ + + pre_echo_att_fx( &hGSCEnc->Last_frame_ener_fx, exc, attack_flag, Q_exc, st_fx->last_coder_type, st_fx->L_frame ); + + /*--------------------------------------------------------------------------------------* + * Update BWE excitation + *--------------------------------------------------------------------------------------*/ + IF( st_fx->hBWE_TD != NULL ) + { + IF( EQ_16( st_fx->L_frame, L_FRAME16k ) ) + { + set16_fx( voice_factors, 0, NB_SUBFR16k ); + interp_code_4over2_fx( exc, bwe_exc, L_FRAME16k ); + } + ELSE + { + set16_fx( voice_factors, 0, NB_SUBFR ); + interp_code_5over2_fx( exc, bwe_exc, L_FRAME ); + } + } + /*--------------------------------------------------------------------------------------* + * Synthesis + *--------------------------------------------------------------------------------------*/ + + p_Aq = Aq; + FOR( i_subfr = 0; i_subfr < st_fx->L_frame; i_subfr += L_SUBFR ) + { + Syn_filt_s( 1, p_Aq, M, &exc_wo_nf[i_subfr], &synth[i_subfr], L_SUBFR, hLPDmem->mem_syn, 1 ); + p_Aq += ( M + 1 ); + } + + /*--------------------------------------------------------------------------------------* + * Updates + *--------------------------------------------------------------------------------------*/ + + hLPDmem->mem_w0 = hGSCEnc->mem_w0_tmp_fx; /*_DIFF_FLOAT_FIX_ The way it is written in the original fix point is that at this point mem_w0 falls back to its original value (before enc_pit_exc, seems not the case in float */ + move16(); + Copy( exc_wo_nf, exc, st_fx->L_frame ); + + return; +} + /*================================================================================*/ /* FUNCTION : void gsc_enc_fx () */ /*--------------------------------------------------------------------------------*/ @@ -737,7 +1089,7 @@ void gsc_enc_ivas_fx( } move16(); - Ener_per_band_comp_ivas_fx_2( exc_diff_fx, Ener_per_bd_iQ_fx, *Q_exc, MBANDS_GN, 1, st->L_frame ); + Ener_per_band_comp_ivas_fx( exc_diff_fx, Ener_per_bd_iQ_fx, *Q_exc, MBANDS_GN, 1, st->L_frame ); /*--------------------------------------------------------------------------------------* * Gain quantizaion diff --git a/lib_enc/hq_core_enc.c b/lib_enc/hq_core_enc.c index e1002faaa..56bd1dbb1 100644 --- a/lib_enc/hq_core_enc.c +++ b/lib_enc/hq_core_enc.c @@ -405,7 +405,8 @@ void hq_core_enc_ivas_fx( { /* Store LB synthesis in case of switch to ACELP */ Copy( output_fx, st->hLPDmem->old_exc, L_FRAME16k ); - st->hLPDmem->e_old_exc = 15; + // st->hLPDmem->e_old_exc = 15; + st->prev_Q_new = 0; move16(); } pop_wmops(); diff --git a/lib_enc/init_enc.c b/lib_enc/init_enc.c index c754fe4bb..0573450d4 100644 --- a/lib_enc/init_enc.c +++ b/lib_enc/init_enc.c @@ -2305,7 +2305,8 @@ ivas_error init_encoder_ivas_fx( fixedToFloat_arr( st->lspold_enc_fx, st->lspold_enc, Q15, M ); IF( st->hLPDmem != NULL ) { - me2f_buf_16( st->hLPDmem->old_exc, st->hLPDmem->e_old_exc, st->hLPDmem->old_exc_flt, L_EXC_MEM ); + // me2f_buf_16( st->hLPDmem->old_exc, st->hLPDmem->e_old_exc, st->hLPDmem->old_exc_flt, L_EXC_MEM ); + fixedToFloat_arr( st->hLPDmem->old_exc, st->hLPDmem->old_exc_flt, st->prev_Q_new, L_EXC_MEM ); } #endif /*-----------------------------------------------------------------* diff --git a/lib_enc/inov_enc_fx.c b/lib_enc/inov_enc_fx.c index 448c95ab6..5c9e1a7de 100644 --- a/lib_enc/inov_enc_fx.c +++ b/lib_enc/inov_enc_fx.c @@ -449,7 +449,7 @@ Word16 inov_encode_ivas_fx( Word16 shift, Word16 Q_new ) { - Word16 dn[2 * L_SUBFR]; + Word16 dn[2 * L_SUBFR], Qdn; Word16 nBits, cmpl_flag; Word16 stack_pulses; Word16 g1, g2; @@ -493,12 +493,17 @@ Word16 inov_encode_ivas_fx( cb_shape_fx( 1, 1, 0, sharpFlag, 0, g1, g2, p_Aq, h2, tilt_code, shr( add( pt_pitch, 26 ), 6 ), 0, L_SUBFR ); /* h2: Q11, Rw: (Rw_e)Q */ - /* Rw_e = */ E_ACELP_hh_corr( h2, Rw, L_SUBFR, 3 ); + // Word16 Rw_e = E_ACELP_hh_corr( h2, Rw, L_SUBFR, 3 ); + Word16 Rw_q; + corr_hh_ivas_fx( h2, Rw, &Rw_q, L_subfr ); // Q(Rw) = Q11-2 - E_ACELP_conv( xn2, h2, cn ); + E_ACELP_conv_ivas( xn2, h2, cn ); // Qcn = Qxn2 /* dn_e -> Rw_e*Q_xn */ - /*dn_e = */ E_ACELP_toeplitz_mul_fx( Rw, cn, dn, L_SUBFR, 1 ); + // Scale_sig(Rw, L_SUBFR, sub(5, Rw_e)); //Q9 + Word16 j = E_ACELP_toeplitz_mul_fx( Rw, cn, dn, L_SUBFR, 1 ); + Qdn = add( add( Q_new - 1 + shift, Rw_q ), j + 1 ); + // Scale_sig(Rw, L_subfr, -3); //Q9->Q6 } ELSE { @@ -509,7 +514,7 @@ Word16 inov_encode_ivas_fx( Scale_sig( cn, L_subfr, shift ); cb_shape_fx( 1, 1, 0, sharpFlag, 0, g1, g2, p_Aq, h2, tilt_code, shr( add( pt_pitch, 26 ), 6 ), 0, L_subfr ); - corr_xh_ivas_fx( xn2, dn, h2, L_subfr ); // Q(dn) = Q_new+1 + corr_xh_ivas_fx2( xn2, Q_new - 1 + shift, dn, &Qdn, h2, L_subfr ); // Q(dn) = Q_new+1 } /*-----------------------------------------------------------------* @@ -528,106 +533,109 @@ Word16 inov_encode_ivas_fx( move16(); } } - ELSE IF( EQ_16( L_frame, L_FRAME ) && EQ_16( coder_type, TRANSITION ) ) - { - test(); - test(); - if ( EQ_32( core_brate, ACELP_8k00 ) && i_subfr == 0 && LT_16( tc_subfr, L_SUBFR ) ) - { - cmpl_flag = 3; - move16(); - } - test(); - test(); - test(); - test(); - test(); - if ( EQ_32( core_brate, ACELP_11k60 ) && ( ( i_subfr == 0 && LT_16( tc_subfr, L_SUBFR ) ) || EQ_16( tc_subfr, TC_0_0 ) || ( EQ_16( i_subfr, 3 * L_SUBFR ) && EQ_16( tc_subfr, TC_0_64 ) ) ) ) - { - cmpl_flag = 3; - move16(); - } - test(); - test(); - test(); - test(); - if ( ( EQ_32( core_brate, ACELP_13k20 ) || EQ_32( core_brate, ACELP_12k15 ) ) && ( ( i_subfr == 0 && LT_16( tc_subfr, L_SUBFR ) ) || LE_16( tc_subfr, TC_0_64 ) ) ) - { - cmpl_flag = 3; - move16(); - } - } - - IF( EQ_16( L_frame, L_FRAME16k ) ) + ELSE { - IF( LE_32( core_brate, ACELP_32k ) ) + IF( EQ_16( L_frame, L_FRAME ) && EQ_16( coder_type, TRANSITION ) ) { - cmpl_flag = 4; - move16(); - test(); - IF( EQ_16( coder_type, TRANSITION ) && GT_16( bwidth, WB ) ) + test(); + if ( EQ_32( core_brate, ACELP_8k00 ) && i_subfr == 0 && LT_16( tc_subfr, L_SUBFR ) ) { - IF( LE_16( i_subfr, L_SUBFR ) ) - { - cmpl_flag = sub( cmpl_flag, 1 ); - } - ELSE - { - cmpl_flag = sub( cmpl_flag, 2 ); - } + cmpl_flag = 3; + move16(); } - } - ELSE IF( LE_32( core_brate, ACELP_48k ) ) - { - cmpl_flag = 3; - move16(); - - IF( EQ_16( coder_type, TRANSITION ) ) + test(); + test(); + test(); + test(); + test(); + if ( EQ_32( core_brate, ACELP_11k60 ) && ( ( i_subfr == 0 && LT_16( tc_subfr, L_SUBFR ) ) || EQ_16( tc_subfr, TC_0_0 ) || ( EQ_16( i_subfr, 3 * L_SUBFR ) && EQ_16( tc_subfr, TC_0_64 ) ) ) ) { - IF( LE_16( i_subfr, L_SUBFR ) ) - { - cmpl_flag = sub( cmpl_flag, 1 ); - } - ELSE - { - cmpl_flag = sub( cmpl_flag, 2 ); - } + cmpl_flag = 3; + move16(); + } + test(); + test(); + test(); + test(); + if ( ( EQ_32( core_brate, ACELP_13k20 ) || EQ_32( core_brate, ACELP_12k15 ) ) && ( ( i_subfr == 0 && LT_16( tc_subfr, L_SUBFR ) ) || LE_16( tc_subfr, TC_0_64 ) ) ) + { + cmpl_flag = 3; + move16(); } } - ELSE - { - cmpl_flag = 4; - move16(); - IF( EQ_16( coder_type, TRANSITION ) ) + IF( EQ_16( L_frame, L_FRAME16k ) ) + { + IF( LE_32( core_brate, ACELP_32k ) ) { - IF( LE_16( i_subfr, L_SUBFR ) ) + cmpl_flag = 4; + move16(); + + test(); + IF( EQ_16( coder_type, TRANSITION ) && GT_16( bwidth, WB ) ) { - cmpl_flag = sub( cmpl_flag, 1 ); + IF( LE_16( i_subfr, L_SUBFR ) ) + { + cmpl_flag = sub( cmpl_flag, 1 ); + } + ELSE + { + cmpl_flag = sub( cmpl_flag, 2 ); + } } - ELSE + } + ELSE IF( LE_32( core_brate, ACELP_48k ) ) + { + cmpl_flag = 3; + move16(); + + IF( EQ_16( coder_type, TRANSITION ) ) { - cmpl_flag = sub( cmpl_flag, 2 ); + IF( LE_16( i_subfr, L_SUBFR ) ) + { + cmpl_flag = sub( cmpl_flag, 1 ); + } + ELSE + { + cmpl_flag = sub( cmpl_flag, 2 ); + } } } - - if ( EQ_16( coder_type, INACTIVE ) ) + ELSE { cmpl_flag = 4; move16(); + + IF( EQ_16( coder_type, TRANSITION ) ) + { + IF( LE_16( i_subfr, L_SUBFR ) ) + { + cmpl_flag = sub( cmpl_flag, 1 ); + } + ELSE + { + cmpl_flag = sub( cmpl_flag, 2 ); + } + } + + if ( EQ_16( coder_type, INACTIVE ) ) + { + cmpl_flag = 4; + move16(); + } } } - } - test(); - test(); - test(); - IF( NE_16( L_frame, st_fx->last_L_frame ) && GT_32( core_brate, ACELP_13k20 ) && ( LT_32( core_brate, ACELP_32k ) || EQ_16( bwidth, WB ) ) ) - { - if ( GT_16( cmpl_flag, 1 ) ) + test(); + test(); + test(); + IF( NE_16( L_frame, st_fx->last_L_frame ) && GT_32( core_brate, ACELP_13k20 ) && ( LT_32( core_brate, ACELP_32k ) || EQ_16( bwidth, WB ) ) ) { - cmpl_flag = sub( cmpl_flag, 1 ); + if ( GT_16( cmpl_flag, 1 ) ) + { + cmpl_flag = sub( cmpl_flag, 1 ); + } } } @@ -670,27 +678,27 @@ Word16 inov_encode_ivas_fx( IF( EQ_16( nBits, 8 ) ) { - acelp_1t64_fx( hBstr, dn, h2, code, y2, L_subfr ); + acelp_1t64_ivas_fx( hBstr, dn, h2, code, y2, L_subfr ); } ELSE { - acelp_fast_fx( hBstr, nBits, dn, add( Q_new, 1 ), cn, h2, code, y2, L_subfr ); + acelp_fast_fx( hBstr, nBits, dn, Qdn, cn, h2, code, y2, L_subfr ); } } ELSE IF( ( EQ_16( st_fx->idchan, 1 ) && LE_16( st_fx->acelp_cfg.fixed_cdk_index[idx2], 7 ) ) || ( st_fx->idchan == 0 && LE_16( st_fx->acelp_cfg.fixed_cdk_index[idx2], 3 ) ) ) { IF( st_fx->acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR] == 0 ) { - acelp_1t64_fx( hBstr, dn, h2, code, y2, L_subfr ); + acelp_1t64_ivas_fx( hBstr, dn, h2, code, y2, L_subfr ); } ELSE { - acelp_fast_fx( hBstr, st_fx->acelp_cfg.fixed_cdk_index[idx2], dn, add( Q_new, 1 ), cn, h2, code, y2, L_SUBFR ); + acelp_fast_fx( hBstr, st_fx->acelp_cfg.fixed_cdk_index[idx2], dn, Qdn, cn, h2, code, y2, L_SUBFR ); } } ELSE { - E_ACELP_4t_fx( dn, cn, h2, Rw, (Word8) acelpautoc, code, st_fx->acelp_cfg.fixed_cdk_index[idx2], prm, L_frame, last_L_frame, st_fx->total_brate, i_subfr, cmpl_flag ); + E_ACELP_4t_ivas_fx( dn, cn, h2, Rw, (Word8) acelpautoc, code, st_fx->acelp_cfg.fixed_cdk_index[idx2], prm, L_frame, last_L_frame, st_fx->total_brate, i_subfr, cmpl_flag, st_fx->element_mode ); wordcnt = shr( ACELP_FIXED_CDK_BITS( st_fx->acelp_cfg.fixed_cdk_index[idx2] ), 4 ); move16(); @@ -708,6 +716,7 @@ Word16 inov_encode_ivas_fx( /* Generate weighted code */ set16_fx( y2, 0, L_SUBFR ); + Word16 sh = add( norm_s( h2[0] ), 1 ); FOR( i = 0; i < L_SUBFR; i++ ) { /* Code is sparse, so check which samples are non-zero */ @@ -715,7 +724,7 @@ Word16 inov_encode_ivas_fx( { FOR( k = 0; k < L_SUBFR - i; k++ ) { - y2[i + k] += code[i] * h2[k]; + y2[i + k] = add( y2[i + k], mult_r( code[i], shl_sat( h2[k], sh ) ) ); } } } @@ -743,15 +752,15 @@ Word16 inov_encode_ivas_fx( IF( EQ_16( nBits, 7 ) ) { - acelp_1t64_fx( hBstr, dn, h2, code, y2, L_SUBFR ); + acelp_1t64_ivas_fx( hBstr, dn, h2, code, y2, L_SUBFR ); } ELSE IF( EQ_16( nBits, 12 ) ) { - acelp_2t32_fx( hBstr, dn, h2, code, y2 ); + acelp_2t32_ivas_fx( hBstr, dn, h2, code, y2 ); } ELSE { - *unbits = add( *unbits, acelp_4t64_fx( hBstr, dn, cn, h2, Rw, acelpautoc, code, y2, nBits, cmpl_flag, Opt_AMR_WB ) ); + *unbits = add( *unbits, acelp_4t64_ivas_fx( hBstr, dn, cn, h2, Rw, acelpautoc, code, y2, nBits, cmpl_flag, Opt_AMR_WB, st_fx->element_mode ) ); move16(); } } @@ -760,39 +769,39 @@ Word16 inov_encode_ivas_fx( { IF( EQ_32( core_brate, ACELP_6k60 ) ) { - acelp_2t32_fx( hBstr, dn, h2, code, y2 ); + acelp_2t32_ivas_fx( hBstr, dn, h2, code, y2 ); } ELSE IF( ( EQ_32( core_brate, ACELP_8k85 ) ) ) { - acelp_4t64_fx( hBstr, dn, cn, h2, Rw, acelpautoc, code, y2, 20, cmpl_flag, Opt_AMR_WB ); + acelp_4t64_ivas_fx( hBstr, dn, cn, h2, Rw, acelpautoc, code, y2, 20, cmpl_flag, Opt_AMR_WB, st_fx->element_mode ); } ELSE IF( EQ_32( core_brate, ACELP_12k65 ) ) { - acelp_4t64_fx( hBstr, dn, cn, h2, Rw, acelpautoc, code, y2, 36, cmpl_flag, Opt_AMR_WB ); + acelp_4t64_ivas_fx( hBstr, dn, cn, h2, Rw, acelpautoc, code, y2, 36, cmpl_flag, Opt_AMR_WB, st_fx->element_mode ); } ELSE IF( EQ_32( core_brate, ACELP_14k25 ) ) { - acelp_4t64_fx( hBstr, dn, cn, h2, Rw, acelpautoc, code, y2, 44, cmpl_flag, Opt_AMR_WB ); + acelp_4t64_ivas_fx( hBstr, dn, cn, h2, Rw, acelpautoc, code, y2, 44, cmpl_flag, Opt_AMR_WB, st_fx->element_mode ); } ELSE IF( EQ_32( core_brate, ACELP_15k85 ) ) { - acelp_4t64_fx( hBstr, dn, cn, h2, Rw, acelpautoc, code, y2, 52, cmpl_flag, Opt_AMR_WB ); + acelp_4t64_ivas_fx( hBstr, dn, cn, h2, Rw, acelpautoc, code, y2, 52, cmpl_flag, Opt_AMR_WB, st_fx->element_mode ); } ELSE IF( EQ_32( core_brate, ACELP_18k25 ) ) { - acelp_4t64_fx( hBstr, dn, cn, h2, Rw, acelpautoc, code, y2, 64, cmpl_flag, Opt_AMR_WB ); + acelp_4t64_ivas_fx( hBstr, dn, cn, h2, Rw, acelpautoc, code, y2, 64, cmpl_flag, Opt_AMR_WB, st_fx->element_mode ); } ELSE IF( EQ_32( core_brate, ACELP_19k85 ) ) { - acelp_4t64_fx( hBstr, dn, cn, h2, Rw, acelpautoc, code, y2, 72, cmpl_flag, Opt_AMR_WB ); + acelp_4t64_ivas_fx( hBstr, dn, cn, h2, Rw, acelpautoc, code, y2, 72, cmpl_flag, Opt_AMR_WB, st_fx->element_mode ); } ELSE IF( EQ_32( core_brate, ACELP_23k05 ) ) { - acelp_4t64_fx( hBstr, dn, cn, h2, Rw, acelpautoc, code, y2, 88, cmpl_flag, Opt_AMR_WB ); + acelp_4t64_ivas_fx( hBstr, dn, cn, h2, Rw, acelpautoc, code, y2, 88, cmpl_flag, Opt_AMR_WB, st_fx->element_mode ); } ELSE IF( EQ_32( core_brate, ACELP_23k85 ) ) { - acelp_4t64_fx( hBstr, dn, cn, h2, Rw, acelpautoc, code, y2, 88, 1, Opt_AMR_WB ); + acelp_4t64_ivas_fx( hBstr, dn, cn, h2, Rw, acelpautoc, code, y2, 88, 1, Opt_AMR_WB, st_fx->element_mode ); } } diff --git a/lib_enc/ivas_tcx_core_enc.c b/lib_enc/ivas_tcx_core_enc.c index cea581a94..26a1d1ffb 100644 --- a/lib_enc/ivas_tcx_core_enc.c +++ b/lib_enc/ivas_tcx_core_enc.c @@ -507,7 +507,7 @@ void stereo_tcx_core_enc( Word16 exp_exc; f2me_buf_16( st->hLPDmem->old_exc_flt, st->hLPDmem->old_exc, &exp_exc, L_EXC_MEM ); Q_exc = 15 - exp_exc; - st->hLPDmem->e_old_exc = exp_exc; + st->prev_Q_new = Q_exc; if ( st->hTdCngEnc != NULL ) { floatToFixed_arr( st->hTdCngEnc->cng_exc2_buf_flt, st->hTdCngEnc->cng_exc2_buf, Q_exc, HO_HIST_SIZE * L_FFT ); diff --git a/lib_enc/ivas_td_low_rate_enc.c b/lib_enc/ivas_td_low_rate_enc.c index 42cea4ce6..22e3fcc2e 100644 --- a/lib_enc/ivas_td_low_rate_enc.c +++ b/lib_enc/ivas_td_low_rate_enc.c @@ -173,7 +173,7 @@ void tdm_low_rate_enc( const Word16 attack_flag, /* i : GSC attack flag */ const Word16 *lsf_new, /* i : current frame ISF vector */ Word16 *tmp_noise, /* o : long-term noise energy */ - Word16 *Q_new ) + Word16 Q_new ) { const Word16 *p_Aq; Word16 i_subfr, nb_subfr, last_pit_bin; @@ -207,7 +207,7 @@ void tdm_low_rate_enc( * DCT transform of the residual and create a subsample residual *---------------------------------------------------------------*/ - edct_16fx( res, dct_res_fx, L_FRAME, st->element_mode, *Q_new ); + edct_16fx( res, dct_res_fx, L_FRAME, 7, st->element_mode ); /*--------------------------------------------------------------------------------------* * GSC encoder @@ -223,7 +223,7 @@ void tdm_low_rate_enc( tmp_nb_bits_tot = sub( tmp_nb_bits_tot, 1 ); } - Word16 Q_exc = *Q_new; + Word16 Q_exc = Q_new; move16(); gsc_enc_ivas_fx( st, dct_res_fx, dct_epit_fx, last_pit_bin, tmp_nb_bits_tot, nb_subfr, lsf_new, exc_wo_nf_fx, tmp_noise, &Q_exc ); @@ -231,9 +231,9 @@ void tdm_low_rate_enc( * iDCT transform *--------------------------------------------------------------------------------------*/ - edct_16fx( dct_epit_fx, exc_fx, L_FRAME, st->element_mode, Q_exc ); + edct_16fx( dct_epit_fx, exc_fx, L_FRAME, 7, st->element_mode ); - edct_16fx( exc_wo_nf_fx, exc_wo_nf_fx, L_FRAME, st->element_mode, Q_exc ); + edct_16fx( exc_wo_nf_fx, exc_wo_nf_fx, L_FRAME, 7, st->element_mode ); /*--------------------------------------------------------------------------------------* * Remove potential pre-echo in case an onset has been detected @@ -275,9 +275,6 @@ void tdm_low_rate_enc( *--------------------------------------------------------------------------------------*/ Copy( exc_wo_nf_fx, exc_fx, L_FRAME ); - *Q_new = Q_exc; - move16(); - return; } #endif @@ -489,7 +486,7 @@ void encod_gen_2sbfr( Word16 *bwe_exc, /* o : excitation for SWB TBE Q_new */ const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag */ const Word16 tdm_Pri_pitch_buf[], /* i : pitch values for primary channel Q4 */ - Word16 *Q_new ) + Word16 Q_new ) { Word16 xn[2 * L_SUBFR]; /* Target vector for pitch search */ Word16 xn2[2 * L_SUBFR]; /* Target vector for codebook search */ @@ -563,8 +560,8 @@ void encod_gen_2sbfr( Copy( &res[i_subfr], &exc[i_subfr], 2 * L_SUBFR ); // Q_new // Scaling mem_syn buffer to Q_new - 1 from e_mem_syn - Scale_sig( &hLPDmem->mem_w0, M + 1, sub( add( *Q_new, hLPDmem->e_mem_syn ), Q16 ) ); // M + 1 to sync mem_syn exponent with mem_w0 exponent - hLPDmem->e_mem_syn = sub( Q16, *Q_new ); + // Scale_sig( &hLPDmem->mem_w0, M + 1, sub( add( *Q_new, hLPDmem->e_mem_syn ), Q16 ) ); // M + 1 to sync mem_syn exponent with mem_w0 exponent + // hLPDmem->e_mem_syn = sub( Q16, *Q_new ); find_targets_ivas_fx( speech, hLPDmem->mem_syn, i_subfr, &hLPDmem->mem_w0, p_Aq, res, 2 * L_SUBFR, p_Aw, st->preemph_fac, xn, cn, h1 ); @@ -587,7 +584,7 @@ void encod_gen_2sbfr( * Gain clipping test to avoid unstable synthesis on frame erasure *-----------------------------------------------------------------*/ - clip_gain = gp_clip_fx( st->element_mode, st->core_brate, st->voicing_fx, i_subfr, coder_type, xn, st->clip_var_fx, *Q_new ); // Q0 + clip_gain = gp_clip_fx( st->element_mode, st->core_brate, st->voicing_fx, i_subfr, coder_type, xn, st->clip_var_fx, Q_new ); // Q0 /*-----------------------------------------------------------------* * LP filtering of the adaptive excitation, codebook target computation @@ -603,13 +600,13 @@ void encod_gen_2sbfr( * Innovation encoding *-----------------------------------------------------------------*/ - inov_encode_ivas_fx( st, st->core_brate, 0, L_frame, st->last_L_frame, coder_type, st->bwidth, st->sharpFlag, i_subfr, -1, p_Aq, gain_pit, cn, exc, h1, hLPDmem->tilt_code, *pt_pitch, xn2, code, y2, &i, 2 * L_SUBFR, 0, *Q_new ); + inov_encode_ivas_fx( st, st->core_brate, 0, L_frame, st->last_L_frame, coder_type, st->bwidth, st->sharpFlag, i_subfr, -1, p_Aq, gain_pit, cn, exc, h1, hLPDmem->tilt_code, *pt_pitch, xn2, code, y2, &i, 2 * L_SUBFR, 0, Q_new ); /*-----------------------------------------------------------------* * Gain encoding *-----------------------------------------------------------------*/ - gain_enc_lbr_ivas_fx( st->hBstr, st->acelp_cfg.gains_mode, coder_type, i_subfr, xn, y1, add( sub( *Q_new, 1 ), shift ), y2, code, &gain_pit, &gain_code, &gain_inov, &norm_gain_code, g_corr, gc_mem, gp_mem, clip_gain, 2 * L_SUBFR ); + gain_enc_lbr_ivas_fx( st->hBstr, st->acelp_cfg.gains_mode, coder_type, i_subfr, xn, y1, add( sub( Q_new, 1 ), shift ), y2, code, &gain_pit, &gain_code, &gain_inov, &norm_gain_code, g_corr, gc_mem, gp_mem, clip_gain, 2 * L_SUBFR ); IF( st->Opt_SC_VBR ) { @@ -627,7 +624,7 @@ void encod_gen_2sbfr( gp_clip_test_gain_pit_fx( st->element_mode, st->core_brate, gain_pit, st->clip_var_fx ); - hLPDmem->tilt_code = est_tilt_ivas_fx( exc + i_subfr, gain_pit, code, gain_code, &voice_fac, *Q_new, 2 * L_SUBFR, 0 ); + hLPDmem->tilt_code = est_tilt_ivas_fx( exc + i_subfr, gain_pit, code, gain_code, &voice_fac, Q_new, 2 * L_SUBFR, 0 ); move16(); /*-----------------------------------------------------------------* @@ -654,7 +651,7 @@ void encod_gen_2sbfr( * Prepare TBE excitation *-----------------------------------------------------------------*/ - prep_tbe_exc_ivas_fx( L_frame, L_SUBFR, i_subfr, gain_pit, gain_code, code, voice_fac, &voice_factors[i_subfr / L_SUBFR], bwe_exc, 0, NULL, *Q_new, T0, T0_frac, coder_type, st->core_brate, st->element_mode, st->idchan, st->hBWE_TD != NULL, st->tdm_LRTD_flag ); + prep_tbe_exc_ivas_fx( L_frame, L_SUBFR, i_subfr, gain_pit, gain_code, code, voice_fac, &voice_factors[i_subfr / L_SUBFR], bwe_exc, 0, NULL, Q_new, T0, T0_frac, coder_type, st->core_brate, st->element_mode, st->idchan, st->hBWE_TD != NULL, st->tdm_LRTD_flag ); voice_factors[i_subfr / L_SUBFR + 1] = voice_factors[i_subfr / L_SUBFR]; move16(); diff --git a/lib_enc/pit_enc_fx.c b/lib_enc/pit_enc_fx.c index b49e52fad..609e24343 100644 --- a/lib_enc/pit_enc_fx.c +++ b/lib_enc/pit_enc_fx.c @@ -500,7 +500,7 @@ Word16 pit_encode_ivas_fx( /* o : Fractional Word16 pit_flag, delta, mult_Top, nBits; Word16 L_sufr_sft; Word16 T_op[2]; /* values for two half-frames */ -#ifdef REMOVE_IVAS_UNUSED_PARAMETERS_WARNING +#if 0 // def REMOVE_IVAS_UNUSED_PARAMETERS_WARNING (void) tdm_Pitch_reuse_flag; #endif @@ -645,7 +645,7 @@ Word16 pit_encode_ivas_fx( /* o : Fractional /* search and encode the closed loop pitch period */ *T0 = pitch_fr4_fx( &exc[i_subfr], xn, h1, *T0_min, *T0_max, T0_frac, pit_flag, *limit_flag, PIT_MAX, PIT_MAX, L_FRAME, L_subfr ); - pit_Q_enc_fx( hBstr, 0, nBits, delta, pit_flag, *limit_flag, *T0, *T0_frac, T0_min, T0_max ); + pit_Q_enc_ivas_fx( hBstr, 0, nBits, delta, pit_flag, *limit_flag, *T0, *T0_frac, T0_min, T0_max ); } ELSE IF( EQ_16( coder_type, VOICED ) ) { @@ -681,7 +681,7 @@ Word16 pit_encode_ivas_fx( /* o : Fractional move16(); } - pit_Q_enc_fx( hBstr, 0, nBits, delta, pit_flag, *limit_flag, *T0, *T0_frac, T0_min, T0_max ); + pit_Q_enc_ivas_fx( hBstr, 0, nBits, delta, pit_flag, *limit_flag, *T0, *T0_frac, T0_min, T0_max ); } #if 1 //#ifdef ADD_LRTD @@ -725,7 +725,7 @@ Word16 pit_encode_ivas_fx( /* o : Fractional *T0_frac = 0; move16(); } - pit_Q_enc_fx( hBstr, 0, nBits, delta, pit_flag, *limit_flag, *T0, *T0_frac, T0_min, T0_max ); + pit_Q_enc_ivas_fx( hBstr, 0, nBits, delta, pit_flag, *limit_flag, *T0, *T0_frac, T0_min, T0_max ); } ELSE { @@ -890,7 +890,7 @@ Word16 pit_encode_ivas_fx( /* o : Fractional *T0 = pitch_fr4_fx( &exc[i_subfr], xn, h1, *T0_min, *T0_max, T0_frac, pit_flag, *limit_flag, PIT_FR2_9b, PIT_FR1_9b, L_FRAME, L_SUBFR ); } - pit_Q_enc_fx( hBstr, 1, nBits, delta, pit_flag, *limit_flag, *T0, *T0_frac, T0_min, T0_max ); + pit_Q_enc_ivas_fx( hBstr, 1, nBits, delta, pit_flag, *limit_flag, *T0, *T0_frac, T0_min, T0_max ); } /*-------------------------------------------------------* diff --git a/lib_enc/prot_fx_enc.h b/lib_enc/prot_fx_enc.h index 8b2669996..27c9e404e 100644 --- a/lib_enc/prot_fx_enc.h +++ b/lib_enc/prot_fx_enc.h @@ -127,6 +127,18 @@ void AVQ_encmux_fx( Word16 trgtSvPos /* i : target SV for AVQ bit savings */ ); +void AVQ_encmux_ivas_fx( + BSTR_ENC_HANDLE hBstr, /* i/o: bitstream handle */ + const Word16 extl, /* i : extension layer */ + Word16 xriq[], /* i/o: rounded subvectors [0..8*Nsv-1] followed + by rounded bit allocations [8*Nsv..8*Nsv+Nsv-1] */ + Word16 *nb_bits, /* i/o: number of allocated bits */ + const Word16 Nsv, /* i: number of subvectors */ + Word16 nq_out[], /* o : AVQ nq index */ + Word16 avq_bit_sFlag, /* i : flag for AVQ bit saving solution */ + Word16 trgtSvPos /* i : target SV for AVQ bit savings */ +); + void bw_detect_fx( Encoder_State *st, /* i/o: Encoder State */ const Word16 signal_in[], /* i : i signal */ @@ -1509,6 +1521,22 @@ void E_ACELP_4t_fx( const Word16 i_subfr, const Word16 cmpl_flag ); +void E_ACELP_4t_ivas_fx( + Word16 dn[], + Word16 cn[] /* Q_xn */, + Word16 H[], + Word16 R[], + Word8 acelpautoc, + Word16 code[], + Word16 cdk_index, + Word16 _index[], + const Word16 L_frame, + const Word16 last_L_frame, + const Word32 total_brate, + const Word16 i_subfr, + const int16_t cmpl_flag, + Word16 element_mode ); + void E_ACELP_innovative_codebook_fx( Word16 *exc, /* i : pointer to the excitation frame Q_new */ Word16 T0, /* i : integer pitch lag Q0 */ @@ -1833,6 +1861,26 @@ Word16 encod_tran_fx( const Word16 Q_new /* i : Input scaling */ ); +Word16 encod_tran_ivas_fx( + Encoder_State *st_fx, /* i/o: state structure */ + const Word16 speech_fx[], /* i : input speech */ + const Word16 Aw_fx[], /* i : weighted A(z) unquantized for subframes */ + const Word16 Aq_fx[], /* i : 12k8 Lp coefficient */ + const Word16 Es_pred_fx, /* i : predicted scaled innov. energy */ + const Word16 *res_fx, /* i : residual signal */ + Word16 *syn_fx, /* i/o: core synthesis */ + Word16 *exc_fx, /* i/o: current non-enhanced excitation */ + Word16 *exc2_fx, /* i/o: current enhanced excitation */ + Word16 *pitch_buf_fx, /* i/o: floating pitch values for each subframe */ + Word16 *voice_factors, /* o : voicing factors */ + Word16 *bwe_exc_fx, /* i/o: excitation for SWB TBE */ + Word16 tc_subfr, /* i/o: TC subframe classification */ + Word16 position, /* i : maximum of residual signal index */ + Word16 *unbits, /* i/o: number of unused bits */ + const Word16 shift, /* i : Scaling to get 12 bits */ + const Word16 Q_new /* i : Input scaling */ +); + /* Delete the instance of type FD_CNG */ void deleteFdCngEnc_fx( HANDLE_FD_CNG_ENC *hFdCngEnc ); @@ -1917,6 +1965,23 @@ void encod_unvoiced_fx( const Word16 Q_new, const Word16 shift ); +void encod_unvoiced_ivas_fx( + Encoder_State *st_fx, /* i/o: state structure */ + const Word16 *speech_fx, /* i : Input speech */ + const Word16 Aw_fx[], /* i : weighted A(z) unquantized for subframes */ + const Word16 *Aq_fx, /* i : 12k8 Lp coefficient */ + const Word16 Es_pred, /* i : predicted scaled innov. energy */ + const Word16 uc_two_stage_flag, /* i : flag indicating two-stage UC */ + const Word16 *res_fx, /* i : residual signal */ + Word16 *syn_fx, /* o : core synthesis */ + Word16 *tmp_noise_fx, /* o : long-term noise energy */ + Word16 *exc_fx, /* i/o: current non-enhanced excitation */ + Word16 *pitch_buf_fx, /* o : floating pitch values for each subframe */ + Word16 *voice_factors_fx, /* o : voicing factors */ + Word16 *bwe_exc_fx, /* i/o: excitation for SWB TBE */ + const Word16 Q_new, + const Word16 shift ); + void enc_acelp_tcx_main_fx( const Word16 new_samples[], /* i : new samples */ Encoder_State *st, /* i/o: encoder state structure */ @@ -1962,6 +2027,25 @@ void encod_gen_voic_fx( Word16 shift, Word16 Q_new ); +void encod_gen_voic_ivas_fx( + Encoder_State *st_fx, /* i/o: state structure */ + const Word16 speech_fx[], /* i : input speech */ + const Word16 Aw_fx[], /* i : weighted A(z) unquantized for subframes */ + const Word16 Aq_fx[], /* i : 12k8 Lp coefficient */ + const Word16 Es_pred_fx, /* i : predicted scaled innov. energy */ + const Word16 *res_fx, /* i : residual signal */ + Word16 *syn_fx, /* i/o: core synthesis */ + Word16 *exc_fx, /* i/o: current non-enhanced excitation */ + Word16 *exc2_fx, /* i/o: current enhanced excitation */ + Word16 *pitch_buf_fx, /* i/o: floating pitch values for each subframe */ + Word16 *voice_factors_fx, /* o : voicing factors */ + Word16 *bwe_exc_fx, /* o : excitation for SWB TBE */ + Word16 *unbits_fx, /* i/o: number of unused bits */ + const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag */ + const Word16 tdm_Pri_pitch_buf[], /* i : primary channel pitch buffer */ + Word16 shift, + Word16 Q_new ); + void encod_audio_fx( Encoder_State *st_fx, /* i/o: State structure */ const Word16 speech[], /* i : i speech Q_new */ @@ -1980,6 +2064,26 @@ void encod_audio_fx( const Word16 tdm_Pri_pitch_buf[], /* i : primary channel pitch buffer */ Word16 Q_new, Word16 shift ); + +void encod_audio_ivas_fx( + Encoder_State *st_fx, /* i/o: State structure */ + const Word16 speech[], /* i : input speech Q_new */ + const Word16 Aw[], /* i : weighted A(z) unquantized for subframes */ + const Word16 Aq[], /* i : 12k8 Lp coefficient */ + const Word16 *res, /* i : residual signal Q_new */ + Word16 *synth, /* i/o: core synthesis Q-1 */ + Word16 *exc, /* i/o: current non-enhanced excitation Q_new */ + Word16 *pitch_buf, /* i/o: floating pitch values for each subframe Q6 */ + Word16 *voice_factors, /* o : voicing factors Q15 */ + Word16 *bwe_exc, /* o : excitation for SWB TBE Q0 */ + const Word16 attack_flag, /* i : Flag that point to an attack coded with AC mode (GSC) */ + Word16 *lsf_new, /* i : current frame ISF vector */ + Word16 *tmp_noise, /* o : noise energy */ + const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag */ + const Word16 tdm_Pri_pitch_buf[], /* i : primary channel pitch buffer */ + Word16 Q_new, + Word16 shift ); + void stat_noise_uv_enc_fx( Encoder_State *st_fx, /* i/o: state structure */ const Word32 *LepsP, /* i : LP prediction errors */ @@ -2077,6 +2181,15 @@ void tcx_hm_analyse_fx( ); void E_ACELP_4tsearchx_fx( Word16 dn[], const Word16 cn[], Word16 Rw[], Word16 code[], const PulseConfig *config, Word16 ind[] ); +void E_ACELP_4tsearchx_ivas_fx( + Word16 dn[], + const Word16 cn[], + Word16 Rw[], + Word16 code[], + const PulseConfig *config, + Word16 ind[], + Word16 element_mode ); + void E_ACELP_weighted_code( const Word16 code[], /* i: code */ const Word16 H[], /* i: impulse response */ @@ -2539,6 +2652,12 @@ void E_ACELP_conv( Word16 cn2[] /* o */ ); +void E_ACELP_conv_ivas( + const Word16 xn2[], /* i */ + const Word16 h2[], /* i */ + Word16 cn2[] /* o */ +); + void gPLC_encInfo_fx( PLC_ENC_EVS_HANDLE self, const Word32 modeBitrate, @@ -2740,6 +2859,22 @@ void corr_xh_ivas_fx( const Word16 L_subfr /* i : length of the subframe */ ); +void corr_hh_ivas_fx( + const Word16 *h, /* i : target signal e(norm_s(h1[0])+1) */ + Word16 *y, /* o : correlation between x[] and h[] Q_new + 1 */ + Word16 *Qy, + const Word16 L_subfr /* i : length of the subframe */ +); + +void corr_xh_ivas_fx2( + const Word16 x[], /* i : target signal */ + const Word16 Qx, + Word16 dn[], /* o : correlation between x[] and h[] */ + Word16 *Qdn, + const Word16 h[], /* i : impulse response (of weighted synthesis filter) */ + const Word16 L_subfr /* i : length of the subframe */ +); + void qlpc_avq_fx( const Word16 *lsf, /* i : Input LSF vectors (14Q1*1.28) */ const Word16 *lsfmid, /* i : Input LSF vectors (14Q1*1.28) */ @@ -3412,6 +3547,31 @@ void transf_cdbk_enc_fx( const Word16 shift /* i : shifting applied to y1, xn,... */ ); +void transf_cdbk_enc_ivas_fx( + Encoder_State *st_fx, /* i/o: encoder state structure */ + const Word16 harm_flag_acelp, /* i : harmonic flag for higher rates ACELP */ + const Word16 i_subfr, /* i : subframe index */ + Word16 cn[], /* i/o: target vector in residual domain */ + Word16 exc[], /* i/o: pointer to excitation signal frame */ + const Word16 *p_Aq, /* i : 12k8 Lp coefficient */ + const Word16 Ap[], /* i : weighted LP filter coefficients */ + const Word16 h1[], /* i : weighted filter input response */ + Word16 xn[], /* i/o: target vector */ + Word16 xn2[], /* i/o: target vector for innovation search */ + Word16 y1[], /* i/o: zero-memory filtered adaptive excitation */ + const Word16 y2[], /* i : zero-memory filtered innovative excitation */ + const Word16 Es_pred, /* i : predicited scaled innovation energy */ + Word16 *gain_pit, /* i/o: adaptive excitation gain */ + const Word32 gain_code, /* i : innovative excitation gain */ + Word16 g_corr[], /* o : ACELP correlation values */ + const Word16 clip_gain, /* i : adaptive gain clipping flag */ + Word16 *gain_preQ, /* o : prequantizer excitation gain */ + Word16 code_preQ[], /* o : prequantizer excitation */ + Word16 *unbits, /* o : number of AVQ unused bits */ + const Word16 Q_new, /* i : Current frame scaling */ + const Word16 shift /* i : shifting applied to y1, xn,... */ +); + void gain_enc_lbr_fx( BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ const Word16 gains_mode[], /* i : gain bits */ @@ -3472,6 +3632,24 @@ void gain_enc_SQ_fx( const Word16 Q_xn /* i : xn and y1 scaling */ ); +void gain_enc_SQ_ivas_fx( + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + const Word16 gains_mode[], /* i : gain bits */ + const Word16 i_subfr, /* i : subframe index */ + const Word16 *xn, /* i : target vector Q_xn */ + const Word16 *yy1, /* i : zero-memory filtered adaptive excitation Q_xn */ + const Word16 *y2, /* i : zero-memory filtered algebraic codebook excitation Q9 */ + const Word16 *code, /* i : algebraic excitation Q9 */ + const Word16 Es_pred, /* i : predicted scaled innovation energy Q8 */ + Word16 *gain_pit, /* o : quantized pitch gain Q14 */ + Word32 *gain_code, /* o : quantized codebook gain Q16 */ + Word16 *gain_inov, /* o : gain of the innovation (used for normalization) Q12 */ + Word32 *norm_gain_code, /* o : norm. gain of the codebook excitation Q16 */ + Word16 *g_corr, /* i/o: correlations , ,, -2 and 2 */ + const Word16 clip_gain, /* i : gain pitch clipping flag (1 = clipping) */ + const Word16 Q_xn /* i : xn and y1 scaling */ +); + void updt_tar_fx( const Word16 *x, /* i : old target (for pitch search) */ Word16 *x2, /* o : new target (for codebook search) */ @@ -3545,6 +3723,33 @@ void transition_enc_fx( ); +void transition_enc_ivas_fx( + Encoder_State *st_fx, /* i/o: encoder state structure */ + const Word16 i_subfr, /* i : subframe index */ + Word16 *tc_subfr, /* i/o: TC subframe index */ + Word16 *Jopt_flag, /* i : joint optimization flag */ + Word16 *position, /* i/o: maximum of residual signal index */ + Word16 *T0, /* i/o: close loop integer pitch Q0*/ + Word16 *T0_frac, /* i/o: close loop fractional part of the pitch Q0*/ + Word16 *T0_min, /* i/o: lower limit for close-loop search Q0*/ + Word16 *T0_max, /* i/o: higher limit for close-loop search Q0*/ + Word16 *exc_fx, /* i/o: pointer to excitation signal frame Q_new*/ + Word16 *y1_fx, /* o : zero-memory filtered adaptive excitation Q_new-1+shift*/ + const Word16 *h1_fx, /* i : weighted filter input response Q(14+shift)*/ + const Word16 *xn_fx, /* i : target vector Q_new-1+shift*/ + Word16 *xn2_fx, /* o : target vector for innovation search Q_new-1+shift*/ + Word16 *gp_cl_fx, /* i/o: memory of gain of pitch clipping algorithm */ + Word16 *gain_pit_fx, /* o : adaptive excitation gain Q14*/ + Word16 *g_corr_fx, /* o : ACELP correlation values */ + Word16 *clip_gain, /* i/o: adaptive gain clipping flag */ + Word16 **pt_pitch_fx, /* o : floating pitch values */ + Word16 *bwe_exc_fx, /* o : excitation for SWB TBE Q_new*/ + Word16 *unbits_ACELP, /* i/o: unused bits */ + Word16 Q_new, /* i : Current scaling */ + Word16 shift /* i : downscaling needs for 12 bits convolutions */ + +); + void transf_cdbk_enc_fx( Encoder_State *st_fx, /* i/o: encoder state structure */ const Word16 harm_flag_acelp, /* i : harmonic flag for higher rates ACELP */ @@ -3584,6 +3789,21 @@ void gain_enc_tc_fx( const Word16 Q_xn /* i : xn and y1 scaling Q0 */ ); +void gain_enc_tc_ivas_fx( + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + const Word16 gains_mode[], /* i : gain bits */ + const Word16 i_subfr, /* i : subframe index */ + const Word16 xn_fx[], /* i : target vector */ + const Word16 y2_fx[], /* i : zero-memory filtered algebraic codebook excitation */ + const Word16 code_fx[], /* i : algebraic excitation */ + const Word16 Es_pred_fx, /* i : predicted scaled innovation energy */ + Word16 *gain_pit_fx, /* o : Pitch gain / Quantized pitch gain */ + Word32 *gain_code_fx, /* o : quantized codebook gain */ + Word16 *gain_inov_fx, /* o : innovation gain */ + Word32 *norm_gain_code_fx, /* o : norm. gain of the codebook excitation */ + const Word16 Q_xn /* i : xn and y1 scaling Q0 */ +); + Word16 gaus_encode_fx( Encoder_State *st_fx, /* i/o: encoder state structure */ const Word16 i_subfr, /* i : subframe index */ @@ -3603,6 +3823,27 @@ Word16 gaus_encode_fx( const Word16 shift, /* i : scaling factor */ Word32 *norm_gain_code /* o : normalized innovative cb. gain Q16 */ ); + +Word16 gaus_encode_ivas_fx( + Encoder_State *st_fx, /* i/o: encoder state structure */ + const Word16 i_subfr, /* i : subframe index */ + const Word16 *h1, /* i : weighted filter input response */ + const Word16 *xn, /* i : target vector */ + Word16 *exc, /* o : pointer to excitation signal frame */ + Word16 *mem_w0, /* o : weighting filter denominator memory */ + Word16 *clip_gain, /* o : memory of gain of pitch clipping algorithm */ + Word16 *tilt_code, /* o : synthesis excitation spectrum tilt */ + Word16 *code, /* o : algebraic excitation Q9 */ + Word32 *gain_code, /* o : Code gain. Q16 */ + Word16 *y2, /* o : zero-memory filtered adaptive excitation Q9 */ + Word16 *gain_inov, /* o : innovation gain Q12 */ + Word16 *voice_fac, /* o : voicing factor Q15 */ + Word16 *gain_pit, /* o : adaptive excitation gain Q14 */ + const Word16 Q_new, /* i : scaling factor */ + const Word16 shift, /* i : scaling factor */ + Word32 *norm_gain_code /* o : normalized innovative cb. gain Q16 */ +); + void pre_proc_fx( Encoder_State *st, /* i/o: encoder state structure */ const Word16 input_frame, /* i : frame length */ @@ -3669,6 +3910,27 @@ void enc_pit_exc_fx( const Word16 tdm_Pri_pitch_buf[], /* i : primary channel pitch buffer */ Word16 Q_new, Word16 shift ); + +void enc_pit_exc_ivas_fx( + Encoder_State *st_fx, /* i/o: State structure */ + const Word16 *speech, /* i : Input speech */ + const Word16 Aw[], /* i : weighted A(z) unquantized for subframes */ + const Word16 Aq[], /* i : 12k8 Lp coefficient */ + const Word16 Es_pred, /* i : predicted scaled innov. energy */ + const Word16 *res, /* i : residual signal */ + Word16 *synth, /* i/o: core synthesis */ + Word16 *exc, /* i/o: current non-enhanced excitation */ + Word16 *T0, /* i/o: close loop integer pitch */ + Word16 *T0_frac, /* i/o: close-loop pitch period - fractional part */ + Word16 *pitch_buf, /* i/o: Fractionnal per subframe pitch */ + const Word16 nb_subfr, /* i : Number of subframe considered */ + Word16 *gpit, /* o : pitch mean gpit */ + Word16 *saved_bit_pos, /* o : saved position in the bitstream before pitch contribution */ + const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag */ + const Word16 tdm_Pri_pitch_buf[], /* i : primary channel pitch buffer */ + Word16 Q_new, + Word16 shift ); + Word16 Pit_exc_contribution_len_fx( /* o : bin where pitch contribution is significant */ Encoder_State *st_fx, /* i/o: state structure */ const Word16 *dct_res, /* i : DCT of residual */ @@ -3678,6 +3940,15 @@ Word16 Pit_exc_contribution_len_fx( /* o : bin where pit Word16 *hangover, /* i : hangover for the time contribution switching */ Word16 Qnew ); +Word16 Pit_exc_contribution_len_ivas_fx( /* o : bin where pitch contribution is significant */ + Encoder_State *st_fx, /* i/o: state structure */ + const Word16 *dct_res, /* i : DCT of residual */ + Word16 *dct_pitex, /* i/o: DCT of pitch contribution */ + Word16 *pitch_buf, /* i/o: Pitch per subframe */ + const Word16 nb_subfr, /* i : Number of subframe considered */ + Word16 *hangover, /* i : hangover for the time contribution switching */ + Word16 Qnew ); + Word16 pvq_core_enc_fx( BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ Word16 coefs_norm[], /* i/o: normalized coefficients to encode */ @@ -4011,6 +4282,15 @@ void acelp_1t64_fx( const Word16 L_subfr /* i : subframe length */ ); +void acelp_1t64_ivas_fx( + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + const Word16 dn[], /* i : corr. between target and h[]. */ + const Word16 h[], /* i : impulse response of weighted synthesis filter */ + Word16 code[], /* o : algebraic (fixed) codebook excitation */ + Word16 y[], /* o : filtered fixed codebook excitation */ + const Word16 L_subfr /* i : subframe length */ +); + void acelp_2t32_fx( BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ const Word16 dn[], /* i : corr. between target and h[]. */ @@ -4019,6 +4299,14 @@ void acelp_2t32_fx( Word16 y[] /* o : filtered fixed codebook excitation */ ); +void acelp_2t32_ivas_fx( + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + const Word16 dn[], /* i : corr. between target and h[]. */ + const Word16 h[], /* i : impulse response of weighted synthesis filter */ + Word16 code[], /* o : algebraic (fixed) codebook excitation */ + Word16 y[] /* o : filtered fixed codebook excitation */ +); + Word16 acelp_4t64_fx( BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ Word16 dn[], /* i : corr. between target and h[]. */ @@ -4033,6 +4321,20 @@ Word16 acelp_4t64_fx( const Word16 Opt_AMR_WB /* i : flag indicating AMR-WB IO mode */ ); +Word16 acelp_4t64_ivas_fx( + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + Word16 dn[], /* i : corr. between target and h[]. */ + const Word16 cn[], /* i : residual after long term prediction Q_new*/ + const Word16 H[], /* i : impulse response of weighted synthesis filter Q12*/ + Word16 R[], /* i : autocorrelation values */ + const Word16 acelpautoc, /* i : autocorrealtion flag */ + Word16 code[], /* o : algebraic (fixed) codebook excitation Q9*/ + Word16 y[], /* o : filtered fixed codebook excitation Q9*/ + Word16 nbbits, /* i : number of bits per codebook */ + const Word16 cmpl_flag, /* i : complexity reduction flag */ + const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ + Word16 element_mode ); + ivas_error evs_enc_fx( Encoder_State *st, /* i/o: encoder state structure */ const Word16 *data, /* i : i signal */ diff --git a/lib_enc/set_impulse_fx.c b/lib_enc/set_impulse_fx.c index f9efcacca..ebdfe8689 100644 --- a/lib_enc/set_impulse_fx.c +++ b/lib_enc/set_impulse_fx.c @@ -190,7 +190,11 @@ void set_impulse_fx( FOR( j = 1; j <= L_IMPULSE2; j++ ) { /*rr[L_SUBFR-1] += gh[j]*gh[j];*/ +#ifdef BASOP_NOGLOB + Lrr = L_mac_sat( Lrr, gh_fx[j], gh_fx[j] ); +#else Lrr = L_mac( Lrr, gh_fx[j], gh_fx[j] ); +#endif } rr_fx[L_SUBFR - 1] = Lrr; move32(); diff --git a/lib_enc/stat_enc.h b/lib_enc/stat_enc.h index 8f0dd5c8a..51cbc7a7e 100644 --- a/lib_enc/stat_enc.h +++ b/lib_enc/stat_enc.h @@ -1075,7 +1075,6 @@ typedef struct lpd_state_structure Word16 syn[1 + M]; /* Synthesis memory (non-pe) */ Word16 old_exc[L_EXC_MEM]; /* ACELP exc memory (Aq) */ - Word16 e_old_exc; float mem_w0_flt; float mem_syn_flt[M]; /* ACELP synthesis memory (pe) before post-proc */ @@ -1090,7 +1089,6 @@ typedef struct lpd_state_structure Word16 mem_syn2[M]; /* ACELP synthesis memory (pe) after post-proc */ Word16 mem_syn_r[L_SYN_MEM]; /* ACELP synthesis memory for 1.25ms */ Word16 mem_syn3[M]; - Word16 e_mem_syn; float tilt_code_flt; Word16 tilt_code; /* Q15 */ diff --git a/lib_enc/transition_enc_fx.c b/lib_enc/transition_enc_fx.c index 3a9fabba0..513ea4098 100644 --- a/lib_enc/transition_enc_fx.c +++ b/lib_enc/transition_enc_fx.c @@ -3,11 +3,11 @@ ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ -#include "cnst.h" /* Common constants */ -#include "rom_com_fx.h" /* Static table prototypes */ -#include "rom_com.h" /* Static table prototypes */ -//#include "prot_fx.h" /* Function prototypes */ +#include "options.h" /* Compilation switches */ +#include "cnst.h" /* Common constants */ +#include "rom_com_fx.h" /* Static table prototypes */ +#include "rom_com.h" /* Static table prototypes */ +#include "prot.h" /* Function prototypes */ #include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ @@ -18,6 +18,7 @@ static void gain_trans_enc_fx( Word32 gain_trans32, Word16 exc[], Word16 *quant_index, Word16 *quant_sign, Word16 Q_new ); static void tc_enc_fx( Encoder_State *st_fx, const Word16 i_subfr, Word16 *tc_subfr, Word16 *position, const Word16 *h1_fx, const Word16 *xn_fx, Word16 *exc_fx, Word16 *yy1_fx, Word16 *T0_min, Word16 *T0_max, Word16 *T0, Word16 *T0_frac, Word16 *gain_pit_fx, Word16 g_corr_fx[], Word16 *bwe_exc_fx, Word16 Q_new ); +static void tc_enc_ivas_fx( Encoder_State *st_fx, const Word16 i_subfr, Word16 *tc_subfr, Word16 *position, const Word16 *h1_fx, const Word16 *xn_fx, Word16 *exc_fx, Word16 *yy1_fx, Word16 *T0_min, Word16 *T0_max, Word16 *T0, Word16 *T0_frac, Word16 *gain_pit_fx, Word16 g_corr_fx[], Word16 *bwe_exc_fx, Word16 Q_new ); /*==========================================================================*/ @@ -852,6 +853,801 @@ void transition_enc_fx( return; } +void transition_enc_ivas_fx( + Encoder_State *st_fx, /* i/o: encoder state structure */ + const Word16 i_subfr, /* i : subframe index */ + Word16 *tc_subfr, /* i/o: TC subframe index */ + Word16 *Jopt_flag, /* i : joint optimization flag */ + Word16 *position, /* i/o: maximum of residual signal index */ + Word16 *T0, /* i/o: close loop integer pitch Q0*/ + Word16 *T0_frac, /* i/o: close loop fractional part of the pitch Q0*/ + Word16 *T0_min, /* i/o: lower limit for close-loop search Q0*/ + Word16 *T0_max, /* i/o: higher limit for close-loop search Q0*/ + Word16 *exc_fx, /* i/o: pointer to excitation signal frame Q_new*/ + Word16 *y1_fx, /* o : zero-memory filtered adaptive excitation Q_new-1+shift*/ + const Word16 *h1_fx, /* i : weighted filter input response Q(14+shift)*/ + const Word16 *xn_fx, /* i : target vector Q_new-1+shift*/ + Word16 *xn2_fx, /* o : target vector for innovation search Q_new-1+shift*/ + Word16 *gp_cl_fx, /* i/o: memory of gain of pitch clipping algorithm */ + Word16 *gain_pit_fx, /* o : adaptive excitation gain Q14*/ + Word16 *g_corr_fx, /* o : ACELP correlation values */ + Word16 *clip_gain, /* i/o: adaptive gain clipping flag */ + Word16 **pt_pitch_fx, /* o : floating pitch values */ + Word16 *bwe_exc_fx, /* o : excitation for SWB TBE Q_new*/ + Word16 *unbits_ACELP, /* i/o: unused bits */ + Word16 Q_new, /* i : Current scaling */ + Word16 shift /* i : downscaling needs for 12 bits convolutions */ + +) +{ + Word16 pit_flag, pit_start, pit_limit, index, nBits; + Word16 tmp, tmp1, i; + Word32 offset; + Word16 shift_wsp; + Word16 limit_flag, mult_Top, lp_select, lp_flag; + Word16 T_op[2]; /* values for two half-frames */ + BSTR_ENC_HANDLE hBstr = st_fx->hBstr; + + /* set limit_flag to 0 for restrained limits, and 1 for extended limits */ + limit_flag = 0; + move16(); + + pit_start = PIT_MIN; + move16(); + + /*----------------------------------------------------------------* + * convert pitch values to 16kHz domain + *----------------------------------------------------------------*/ + + IF( EQ_16( st_fx->L_frame, L_FRAME ) /*|| (tdm_Pri_pitch_buf != NULL && tdm_Pri_pitch_buf[0] < 0)*/ ) + { + Copy( st_fx->pitch, T_op, 2 ); + } + ELSE /* L_frame == L_FRAME16k */ + { + /*T_op[0] = (int16_t)(pitch[0] * 1.25f + 0.5f); + T_op[1] = (int16_t)(pitch[1] * 1.25f + 0.5f);*/ + T_op[0] = add( st_fx->pitch[0], mult_r( st_fx->pitch[0], 8192 /*0.25f Q15*/ ) ); + T_op[1] = add( st_fx->pitch[1], mult_r( st_fx->pitch[1], 8192 /*0.25f Q15*/ ) ); + } + shift_wsp = add( Q_new, shift ); + + lp_flag = st_fx->acelp_cfg.ltf_mode; + move16(); + /*-----------------------------------------------------------------* + * TC: subrame determination for glottal shape search + * ------------------------------------------------------- + * tc_subfr == 0 - TC in 1st subframe + * tc_subfr == TC_0_0 - TC in 1st subframe + information about T0 + * tc_subfr == L_SUBFR - TC in 2nd subframe + * tc_subfr == 2*L_SUBFR - TC in 3rd subframe + * tc_subfr == 3*L_SUBFR - TC in 4th subframe + *-----------------------------------------------------------------*/ + + IF( i_subfr == 0 ) + { + mult_Top = 1; + IF( limit_flag == 0 ) + { + test(); + IF( EQ_16( st_fx->L_frame, L_FRAME ) && LT_16( T_op[1], PIT_MIN ) ) + { + mult_Top = 2; + move16(); + } + test(); + if ( EQ_16( st_fx->L_frame, L_FRAME16k ) && LT_16( T_op[1], PIT16k_MIN ) ) + { + mult_Top = 2; + move16(); + } + } + + limit_T0_fx( st_fx->L_frame, 8, 0, limit_flag, mult_Top * T_op[1], 0, T0_min, T0_max ); + } + /*-----------------------------------------------------------------* + * zero adaptive excitation signal construction + *-----------------------------------------------------------------*/ + IF( GT_16( *tc_subfr, i_subfr ) ) + { + *gain_pit_fx = 0; + move16(); + *clip_gain = 0; + move16(); + g_corr_fx[0] = 16384; + move16(); + g_corr_fx[1] = add( shl( sub( shift_wsp, 1 ), 1 ), 1 ); + move16(); + g_corr_fx[2] = -16384; + move16(); + g_corr_fx[3] = shl( sub( shift_wsp, 1 ), 1 ); + + set16_fx( &exc_fx[i_subfr], 0, L_SUBFR ); /* set excitation for current subrame to 0 */ + + IF( EQ_16( st_fx->L_frame, L_FRAME ) ) + { + set16_fx( &bwe_exc_fx[i_subfr * HIBND_ACB_L_FAC], 0, (Word16) ( L_SUBFR * HIBND_ACB_L_FAC ) ); /* set past excitation buffer to 0 */ + } + ELSE + { + set16_fx( &bwe_exc_fx[i_subfr * 2], 0, L_SUBFR * 2 ); /* set past excitation buffer to 0 */ + } + + set16_fx( y1_fx, 0, L_SUBFR ); /* set filtered adaptive excitation to 0 */ + Copy( xn_fx, xn2_fx, L_SUBFR ); /* target vector for codebook search */ + *T0 = L_SUBFR; + move16(); + *T0_frac = 0; + move16(); + + **pt_pitch_fx = shl( add( shl( *T0, 2 ), *T0_frac ), 4 ); + move16(); /* save subframe pitch values Q6 */ + } + + /*-----------------------------------------------------------------* + * glottal codebook contribution construction + *-----------------------------------------------------------------*/ + ELSE IF( EQ_16( *tc_subfr, i_subfr ) ) + { + IF( EQ_16( st_fx->L_frame, L_FRAME ) ) + { + set16_fx( bwe_exc_fx - PIT_MAX * HIBND_ACB_L_FAC, 0, PIT_MAX * HIBND_ACB_L_FAC ); /* set past excitation buffer to 0 */ + } + ELSE + { + set16_fx( bwe_exc_fx - PIT16k_MAX * 2, 0, PIT16k_MAX * 2 ); /* set past excitation buffer to 0 */ + } + + tc_enc_ivas_fx( st_fx, i_subfr, tc_subfr, position, h1_fx, xn_fx, exc_fx, + y1_fx, T0_min, T0_max, T0, T0_frac, gain_pit_fx, g_corr_fx, bwe_exc_fx, Q_new ); + + IF( EQ_16( *tc_subfr, TC_0_0 ) ) + { + /* this is called only to compute unused bits */ + config_acelp1( ENC, st_fx->total_brate, st_fx->core_brate, st_fx->core, st_fx->extl, st_fx->extl_brate, + L_FRAME, -1, &( st_fx->acelp_cfg ), hBstr->nb_bits_tot, TRANSITION, TC_0_0, 3, NULL, unbits_ACELP, + st_fx->element_mode, &i /*dummy*/, 0 /*tdm_lp_reuse_flag*/, 0 /*tdm_low_rate_mode*/, st_fx->idchan, st_fx->active_fr_cnt_fx, 0 /*tdm_Pitch_reuse_flag*/, st_fx->tdm_LRTD_flag, 0 /*GSC_IVAS_mode*/ + ); + } + *clip_gain = gp_clip_fx( st_fx->element_mode, st_fx->core_brate, st_fx->voicing_fx, i_subfr, TRANSITION, xn_fx, gp_cl_fx, sub( shift_wsp, 1 ) ); + updt_tar_fx( xn_fx, xn2_fx, y1_fx, *gain_pit_fx, L_SUBFR ); + + **pt_pitch_fx = shl( add( shl( *T0, 2 ), *T0_frac ), 4 ); + move16(); + *Jopt_flag = 1; + move16(); + } + + /*--------------------------------------------------------------* + * other subframes -> GENERIC encoding type, + * standard adaptive excitation contribution + * - exemption only in case when first glottal impulse is + * in the 1st subframe and the second one in 2nd subframe + * and later + *--------------------------------------------------------------*/ + ELSE IF( LT_16( *tc_subfr, i_subfr ) ) + { + IF( EQ_16( st_fx->L_frame, L_FRAME ) ) + { + *Jopt_flag = 1; + move16(); + /* pit_flag for T0 bits number coding determination */ + test(); + IF( ( EQ_16( sub( i_subfr, *tc_subfr ), L_SUBFR ) ) || ( EQ_16( sub( i_subfr, *tc_subfr ), L_SUBFR - TC_0_0 ) ) ) + { + pit_flag = 0; + move16(); + } + ELSE + { + pit_flag = L_SUBFR; + move16(); + } + + IF( EQ_16( *tc_subfr, TC_0_0 ) ) + { + IF( EQ_16( i_subfr, L_SUBFR ) ) + { + limit_T0_fx( L_FRAME, 8, pit_flag, limit_flag, *T0, 0, T0_min, T0_max ); + } + pit_flag = 1; + move16(); + } + + /*----------------------------------------------------------* + * if tc_subfr==0, change tc_subfr corresponding to the + * second glot. impulse position + *----------------------------------------------------------*/ + test(); + IF( ( *tc_subfr == 0 ) && ( EQ_16( i_subfr, L_SUBFR ) ) ) + { + IF( GT_16( PIT_MIN, ( *position ) ) ) + { + pit_start = sub( L_SUBFR, ( *position ) ); + } + ELSE + { + pit_start = PIT_MIN; + move16(); + } + pit_start = s_max( pit_start, PIT_MIN ); + + pit_limit = add( shl( pit_start, 1 ), *position ); + + /* Find the closed loop pitch period */ + + *T0 = pitch_fr4_fx( &exc_fx[i_subfr], xn_fx, h1_fx, *T0_min, *T0_max, T0_frac, pit_flag, limit_flag, pit_start, pit_limit, L_FRAME, L_SUBFR ); + + offset = tbe_celp_exc_offset( *T0, *T0_frac, st_fx->L_frame ); + + + FOR( i = 0; i < L_SUBFR * HIBND_ACB_L_FAC; i++ ) + { + bwe_exc_fx[i + i_subfr * HIBND_ACB_L_FAC] = bwe_exc_fx[i + i_subfr * HIBND_ACB_L_FAC - offset]; + } + + + test(); + IF( GT_16( ( *T0 ), sub( 2 * L_SUBFR, ( *position ) ) ) ) + { + IF( GE_16( add( ( *T0 ), ( *position ) ), 3 * L_SUBFR ) ) + { + /* second glottal impulse is in the 4th subframe */ + *tc_subfr = TC_0_192; + move16(); + } + ELSE + { + /* second glottal impulse is in the 3rd subframe */ + *tc_subfr = TC_0_128; + move16(); + } + } + ELSE IF( ( *tc_subfr == 0 ) && ( EQ_16( i_subfr, L_SUBFR ) ) ) + { + /* second glottal impulse is in the 2nd subframe */ + *tc_subfr = TC_0_64; + move16(); + } + } + + IF( LE_16( sub( i_subfr, *tc_subfr ), L_SUBFR ) ) + { + config_acelp1( ENC, st_fx->total_brate, st_fx->core_brate, st_fx->core, st_fx->extl, st_fx->extl_brate, + st_fx->L_frame, -1, &( st_fx->acelp_cfg ), hBstr->nb_bits_tot, TRANSITION, *tc_subfr, 2, NULL, + unbits_ACELP, st_fx->element_mode, &i /*dummy*/, 0 /*tdm_lp_reuse_flag*/, 0 /*tdm_low_rate_mode*/, st_fx->idchan, st_fx->active_fr_cnt_fx, 0 /*tdm_Pitch_reuse_flag*/, st_fx->tdm_LRTD_flag, 0 /*GSC_IVAS_mode*/ ); + } + /*-----------------------------------------------------------------* + * get number of bits for pitch encoding + *-----------------------------------------------------------------*/ + + nBits = st_fx->acelp_cfg.pitch_bits[shr( i_subfr, 6 )]; + move16(); + + /*-----------------------------------------------------------------* + * Find adaptive part of excitation, encode pitch period + *-----------------------------------------------------------------*/ + test(); + test(); + test(); + test(); + test(); + test(); + /* first glottal impulse is in the 1st subrame */ + IF( ( EQ_16( i_subfr, L_SUBFR ) ) && ( GE_16( *tc_subfr, TC_0_128 ) ) ) + { + /*--------------------------------------------------------* + * second glottal impulse is in the 3rd or 4th subframe + * - build exc[] in 2nd subframe + *--------------------------------------------------------*/ + *T0 = 2 * L_SUBFR; + move16(); + *T0_frac = 0; + move16(); + *Jopt_flag = 0; + move16(); + set16_fx( &exc_fx[i_subfr], 0, (Word16) ( L_SUBFR + 1 ) ); + set16_fx( &bwe_exc_fx[i_subfr * HIBND_ACB_L_FAC], 0, (Word16) ( L_SUBFR * HIBND_ACB_L_FAC ) ); + } + ELSE IF( ( EQ_16( i_subfr, L_SUBFR ) ) && ( EQ_16( *tc_subfr, TC_0_64 ) ) ) + { + /*--------------------------------------------------------* + * second glottal impulse is in the 2nd subframe, + * - build exc[] in 2nd subframe + + *--------------------------------------------------------*/ + IF( LT_16( add( *T0, *position ), L_SUBFR ) ) + { + /* impulse must be in the 2nd subframe (not in 1st) */ + *T0 = sub( L_SUBFR, ( *position ) ); + move16(); + *T0_frac = 0; + move16(); + } + IF( GE_16( add( *T0, *position ), 2 * L_SUBFR ) ) + { + /* impulse must be in the 2nd subframe (not in 3rd) */ + *T0 = sub( 2 * L_SUBFR - 1, ( *position ) ); + move16(); + *T0_frac = 2; + move16(); + } + + limit_T0_fx( L_FRAME, 8, pit_flag, limit_flag, *T0, 0, T0_min, T0_max ); /* find T0_min and T0_max for delta search */ + + /* 7bit ENCODER */ + /* index = (*T0-pit_start)*2 + *T0_frac/2;*/ + index = add( shl( sub( *T0, pit_start ), 1 ), shr( *T0_frac, 1 ) ); + push_indice( hBstr, IND_PITCH, index, nBits ); + + /* Find the adaptive codebook vector - ACELP long-term prediction */ + pred_lt4( &exc_fx[i_subfr], &exc_fx[i_subfr], *T0, *T0_frac, L_SUBFR + 1, pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP ); + + + offset = tbe_celp_exc_offset( *T0, *T0_frac, st_fx->L_frame ); + + FOR( i = 0; i < L_SUBFR * HIBND_ACB_L_FAC; i++ ) + { + bwe_exc_fx[i + i_subfr * HIBND_ACB_L_FAC] = bwe_exc_fx[i + i_subfr * HIBND_ACB_L_FAC - offset]; + } + } + ELSE IF( ( EQ_16( i_subfr, 2 * L_SUBFR ) ) && ( EQ_16( *tc_subfr, TC_0_128 ) ) ) + { + /*--------------------------------------------------------* + * second glottal impulse is in the 3rd subframe + * - build exc[] in 3rd subframe + *--------------------------------------------------------*/ + + pit_start = sub( 2 * L_SUBFR, ( *position ) ); + pit_flag = 0; + move16(); + + *T0 = pitch_fr4_fx( &exc_fx[i_subfr], xn_fx, h1_fx, *T0_min, *T0_max, T0_frac, pit_flag, limit_flag, pit_start, 3 * L_SUBFR, L_FRAME, L_SUBFR ); + + IF( LT_16( add( ( *T0 ), ( *position ) ), 2 * L_SUBFR ) ) + { + /* impulse must be in the 3rd subframe (not in 2nd) */ + *T0 = sub( 2 * L_SUBFR, ( *position ) ); + move16(); + *T0_frac = 0; + move16(); + } + + IF( GE_16( add( ( *T0 ), ( *position ) ), 3 * L_SUBFR ) ) + { + /* impulse must be in the 3rd subframe (not in 4th) */ + *T0 = sub( 3 * L_SUBFR - 1, ( *position ) ); + move16(); + *T0_frac = 2; + move16(); + } + + limit_T0_fx( L_FRAME, 8, pit_flag, limit_flag, *T0, 0, T0_min, T0_max ); /* find T0_min and T0_max for delta search */ + + index = add( shl( sub( *T0, pit_start ), 1 ), shr( *T0_frac, 1 ) ); + push_indice( hBstr, IND_PITCH, index, nBits ); + + /* Find the adaptive codebook vector - ACELP long-term prediction */ + pred_lt4( &exc_fx[i_subfr], &exc_fx[i_subfr], *T0, *T0_frac, L_SUBFR + 1, pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP ); + + offset = tbe_celp_exc_offset( *T0, *T0_frac, st_fx->L_frame ); + + + FOR( i = 0; i < L_SUBFR * HIBND_ACB_L_FAC; i++ ) + { + bwe_exc_fx[i + i_subfr * HIBND_ACB_L_FAC] = bwe_exc_fx[i + i_subfr * HIBND_ACB_L_FAC - offset]; + } + } + ELSE IF( ( EQ_16( i_subfr, 2 * L_SUBFR ) ) && ( EQ_16( *tc_subfr, TC_0_192 ) ) ) + { + /*--------------------------------------------------------* + * second glottal impulse is in the 4th subframe + * - build exc[] in 3rd subframe + *--------------------------------------------------------*/ + *T0 = 4 * L_SUBFR; + move16(); + *T0_frac = 0; + move16(); + *Jopt_flag = 0; + move16(); + set16_fx( &exc_fx[i_subfr], 0, (Word16) ( L_SUBFR + 1 ) ); + set16_fx( &bwe_exc_fx[i_subfr * HIBND_ACB_L_FAC], 0, (Word16) ( L_SUBFR * HIBND_ACB_L_FAC ) ); + } + ELSE IF( ( EQ_16( i_subfr, 3 * L_SUBFR ) ) && ( EQ_16( *tc_subfr, TC_0_192 ) ) ) + { + /*--------------------------------------------------------* + * second glottal impulse is in the 4th subframe + * - build exc[] in 4th subframe + *--------------------------------------------------------*/ + /* always T0_frac = 0 */ + pit_flag = 0; + move16(); + + *T0 = pitch_fr4_fx( &exc_fx[i_subfr], xn_fx, h1_fx, *T0_min, *T0_max, T0_frac, pit_flag, limit_flag, PIT_MIN, PIT_FR1_8b, L_FRAME, L_SUBFR ); + + IF( LT_16( add( *T0, *position ), 3 * L_SUBFR ) ) + { + /* impulse must be in the 4th subframe (not in 3rd) */ + *T0 = sub( 3 * L_SUBFR, ( *position ) ); + move16(); + *T0_frac = 0; + move16(); + } + + pit_start = sub( 3 * L_SUBFR, ( *position ) ); + pit_limit = sub( 2 * L_FRAME - PIT_MAX - 2, shl( *position, 1 ) ); + + IF( LT_16( ( *T0 ), pit_limit ) ) + { + index = add( shl( sub( *T0, pit_start ), 1 ), shr( *T0_frac, 1 ) ); + } + ELSE + { + index = add( sub( *T0, pit_limit ), shl( sub( pit_limit, pit_start ), 1 ) ); + *T0_frac = 0; + move16(); + } + push_indice( hBstr, IND_PITCH, index, nBits ); + + /* Find the adaptive codebook vector - ACELP long-term prediction */ + pred_lt4( &exc_fx[i_subfr], &exc_fx[i_subfr], *T0, *T0_frac, L_SUBFR + 1, pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP ); + + offset = tbe_celp_exc_offset( *T0, *T0_frac, st_fx->L_frame ); + + FOR( i = 0; i < L_SUBFR * HIBND_ACB_L_FAC; i++ ) + { + bwe_exc_fx[i + i_subfr * HIBND_ACB_L_FAC] = bwe_exc_fx[i + i_subfr * HIBND_ACB_L_FAC - offset]; + move16(); + } + } + ELSE IF( ( EQ_16( i_subfr, 3 * L_SUBFR ) ) && ( EQ_16( *tc_subfr, TC_0_128 ) ) ) + { + /*--------------------------------------------------------* + * second glottal impulse in the 3rd subframe + * build exc[] in 4th subframe + *--------------------------------------------------------*/ + pit_flag = L_SUBFR; + move16(); + *T0 = pitch_fr4_fx( &exc_fx[i_subfr], xn_fx, h1_fx, *T0_min, *T0_max, T0_frac, pit_flag, limit_flag, PIT_MIN, PIT_FR1_8b, L_FRAME, L_SUBFR ); + index = delta_pit_enc_fx( 2, *T0, *T0_frac, *T0_min ); + push_indice( hBstr, IND_PITCH, index, nBits ); + + /* Find the adaptive codebook vector - ACELP long-term prediction */ + pred_lt4( &exc_fx[i_subfr], &exc_fx[i_subfr], *T0, *T0_frac, L_SUBFR + 1, pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP ); + + offset = tbe_celp_exc_offset( *T0, *T0_frac, st_fx->L_frame ); + + + FOR( i = 0; i < L_SUBFR * HIBND_ACB_L_FAC; i++ ) + { + bwe_exc_fx[i + i_subfr * HIBND_ACB_L_FAC] = bwe_exc_fx[i + i_subfr * HIBND_ACB_L_FAC - offset]; + } + } + + /*------------------------------------------------------------* + * first glottal impulse is NOT in the 1st subframe, + * or two impulses are in the 1st subframe + *------------------------------------------------------------*/ + ELSE + { + test(); + IF( EQ_16( nBits, 8 ) || EQ_16( nBits, 5 ) ) + { + test(); + IF( !( ( *tc_subfr == 0 ) && ( EQ_16( i_subfr, L_SUBFR ) ) ) ) + { + *T0 = pitch_fr4_fx( &exc_fx[i_subfr], xn_fx, h1_fx, *T0_min, *T0_max, T0_frac, pit_flag, limit_flag, PIT_MIN, PIT_FR1_8b, L_FRAME, L_SUBFR ); + } + } + ELSE + { + *T0 = pitch_fr4_fx( &exc_fx[i_subfr], xn_fx, h1_fx, *T0_min, *T0_max, T0_frac, pit_flag, limit_flag, PIT_FR2_9b, PIT_FR1_9b, L_FRAME, L_SUBFR ); + } + pit_Q_enc_ivas_fx( hBstr, 0, nBits, 8, pit_flag, limit_flag, *T0, *T0_frac, T0_min, T0_max ); + + /* Find the adaptive codebook vector - ACELP long-term prediction */ + pred_lt4( &exc_fx[i_subfr], &exc_fx[i_subfr], *T0, *T0_frac, L_SUBFR + 1, pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP ); + + offset = tbe_celp_exc_offset( *T0, *T0_frac, st_fx->L_frame ); + + FOR( i = 0; i < L_SUBFR * HIBND_ACB_L_FAC; i++ ) + { + bwe_exc_fx[i + i_subfr * HIBND_ACB_L_FAC] = bwe_exc_fx[i + i_subfr * HIBND_ACB_L_FAC - offset]; + } + } + + /*-----------------------------------------------------------------* + * - gain clipping test to avoid unstable synthesis + * - LP filtering of the adaptive excitation (if non-zero) + * - codebook target computation + *-----------------------------------------------------------------*/ + IF( *Jopt_flag == 0 ) + { + /* adaptive/TC excitation is zero */ + Copy( xn_fx, xn2_fx, L_SUBFR ); + g_corr_fx[0] = 0; + move16(); + g_corr_fx[1] = 0; + move16(); + g_corr_fx[2] = 0; + move16(); + g_corr_fx[3] = 0; + move16(); + *clip_gain = 0; + move16(); + } + ELSE + { + *clip_gain = gp_clip_fx( st_fx->element_mode, st_fx->core_brate, st_fx->voicing_fx, i_subfr, TRANSITION, xn_fx, gp_cl_fx, ( Q_new + shift - 1 ) ); + + lp_select = lp_filt_exc_enc_fx( MODE1, TRANSITION, i_subfr, exc_fx, h1_fx, + xn_fx, y1_fx, xn2_fx, L_SUBFR, st_fx->L_frame, g_corr_fx, *clip_gain, gain_pit_fx, &lp_flag ); + + IF( EQ_16( lp_flag, NORMAL_OPERATION ) ) + { + push_indice( hBstr, IND_LP_FILT_SELECT, lp_select, 1 ); + } + } + + **pt_pitch_fx = shl( add( shl( *T0, 2 ), *T0_frac ), 4 ); + move16(); + /*---------------------------------------------------------------------* + * fill the pitch buffer - needed for post-processing + *---------------------------------------------------------------------*/ + test(); + test(); + test(); + test(); + test(); + IF( ( *tc_subfr >= 2 * L_SUBFR ) && ( i_subfr == 3 * L_SUBFR ) ) + { + tmp = shl( add( shl( *T0, 2 ), *T0_frac ), 4 ); + ( *pt_pitch_fx ) -= 3; + move16(); + **pt_pitch_fx = tmp; + move16(); + ( *pt_pitch_fx )++; + move16(); + **pt_pitch_fx = tmp; + move16(); + ( *pt_pitch_fx )++; + move16(); + **pt_pitch_fx = tmp; + move16(); + ( *pt_pitch_fx )++; + } + ELSE IF( ( *tc_subfr == L_SUBFR ) && ( i_subfr == 2 * L_SUBFR ) ) + { + tmp = shl( add( shl( *T0, 2 ), *T0_frac ), 4 ); + ( *pt_pitch_fx ) -= 2; + move16(); + **pt_pitch_fx = tmp; + move16(); + ( *pt_pitch_fx )++; + move16(); + **pt_pitch_fx = tmp; + move16(); + ( *pt_pitch_fx )++; + move16(); + } + ELSE IF( ( *tc_subfr == TC_0_64 ) && ( i_subfr == L_SUBFR ) ) + { + tmp = shl( add( shl( *T0, 2 ), *T0_frac ), 4 ); + ( *pt_pitch_fx ) -= 1; + move16(); + **pt_pitch_fx = tmp; + move16(); + ( *pt_pitch_fx )++; + move16(); + } + ELSE IF( ( *tc_subfr == TC_0_128 ) && ( i_subfr == 2 * L_SUBFR ) ) + { + tmp = shl( add( shl( *T0, 2 ), *T0_frac ), 4 ); + ( *pt_pitch_fx ) -= 2; + move16(); + **pt_pitch_fx = tmp; + move16(); + ( *pt_pitch_fx )++; + move16(); + **pt_pitch_fx = tmp; + move16(); + ( *pt_pitch_fx )++; + move16(); + } + ELSE IF( ( *tc_subfr == TC_0_192 ) && ( i_subfr == 3 * L_SUBFR ) ) + { + tmp = shl( add( shl( *T0, 2 ), *T0_frac ), 4 ); + ( *pt_pitch_fx ) -= 3; + move16(); + **pt_pitch_fx = tmp; + move16(); + ( *pt_pitch_fx )++; + move16(); + **pt_pitch_fx = tmp; + move16(); + ( *pt_pitch_fx )++; + move16(); + **pt_pitch_fx = tmp; + move16(); + ( *pt_pitch_fx )++; + move16(); + } + } + ELSE /* L_frame == L_FRAME16k */ + { + if ( GE_16( i_subfr, 2 * L_SUBFR ) ) + { + limit_flag = 1; + move16(); + } + IF( LE_16( i_subfr, 2 * L_SUBFR ) ) + { + IF( LT_16( i_subfr, 2 * L_SUBFR ) ) + { + mult_Top = 1; + move16(); + if ( LT_16( T_op[0], PIT16k_MIN ) ) + { + mult_Top = 2; + move16(); + } + + limit_T0_fx( L_FRAME16k, 8, 0, limit_flag, mult_Top * T_op[0], 0, T0_min, T0_max ); /* TC0 second subfr. */ + } + ELSE + { + limit_T0_fx( L_FRAME16k, 8, 0, limit_flag, T_op[1], 0, T0_min, T0_max ); /* TC0 third subfr., or TC64 third subfr. */ + } + } + + /*-----------------------------------------------------------------* + * get number of bits for pitch encoding + *-----------------------------------------------------------------*/ + + nBits = st_fx->acelp_cfg.pitch_bits[shr( i_subfr, 6 )]; + move16(); + + /*-----------------------------------------------------------------* + * Find adaptive part of excitation, encode pitch period + *-----------------------------------------------------------------*/ + + IF( EQ_16( nBits, 10 ) ) + { + *T0 = pitch_fr4_fx( &exc_fx[i_subfr], xn_fx, h1_fx, *T0_min, *T0_max, T0_frac, 0, limit_flag, PIT16k_FR2_EXTEND_10b, PIT16k_MAX, st_fx->L_frame, L_SUBFR ); + pit16k_Q_enc_ivas_fx( hBstr, nBits, limit_flag, *T0, *T0_frac, T0_min, T0_max ); + } + ELSE IF( EQ_16( nBits, 8 ) ) /* tc_subfr==0 && i_subfr==L_SUBFR */ + { + /*-----------------------------------------------------------------------------* + * The pitch range is encoded absolutely with 8 bits and is divided as follows: + * PIT16k_MIN to PIT16k_FR2_TC0_2SUBFR-1 resolution 1/4 (frac = 0,1,2 or 3) + * PIT16k_FR2_TC0_2SUBFR to 2*L_SUBFR resolution 1/2 (frac = 0 or 2) + *-----------------------------------------------------------------------------*/ + *T0 = pitch_fr4_fx( &exc_fx[i_subfr], xn_fx, h1_fx, *T0_min, *T0_max, T0_frac, 0, limit_flag, PIT16k_FR2_TC0_2SUBFR, 2 * L_SUBFR, st_fx->L_frame, L_SUBFR ); + + IF( GT_16( *T0_max, 2 * L_SUBFR ) ) + { + *T0 = 2 * L_SUBFR; + move16(); + *T0_frac = 0; + move16(); + } + + IF( LT_16( *T0, PIT16k_FR2_TC0_2SUBFR ) ) + { + /*index = (*T0)*4 + (*T0_frac) - (PIT16k_MIN*4);*/ + index = add( shl( *T0, 2 ), sub( *T0_frac, PIT16k_MIN * 4 ) ); + } + ELSE + { + /*index = (*T0)*2 + ((*T0_frac)>>1) - (PIT16k_FR2_TC0_2SUBFR*2) + ((PIT16k_FR2_TC0_2SUBFR-PIT16k_MIN)*4);*/ + index = add( sub( add( shl( *T0, 1 ), shr( *T0_frac, 1 ) ), ( PIT16k_FR2_TC0_2SUBFR * 2 ) ), ( PIT16k_FR2_TC0_2SUBFR - PIT16k_MIN ) * 4 ); + } + push_indice( hBstr, IND_PITCH, index, nBits ); + } + ELSE IF( EQ_16( nBits, 6 ) ) + { + /* delta search */ + *T0 = pitch_fr4_fx( &exc_fx[i_subfr], xn_fx, h1_fx, *T0_min, *T0_max, T0_frac, L_SUBFR, limit_flag, PIT16k_FR2_EXTEND_9b, PIT16k_FR1_EXTEND_9b, st_fx->L_frame, L_SUBFR ); + + index = delta_pit_enc_fx( 4, *T0, *T0_frac, *T0_min ); + push_indice( hBstr, IND_PITCH, index, nBits ); + } + IF( EQ_16( nBits, 6 ) ) + { + limit_T0_fx( L_FRAME16k, 8, L_SUBFR, limit_flag, *T0, *T0_frac, T0_min, T0_max ); + } + + /*-----------------------------------------------------------------* + * - gain clipping test to avoid unstable synthesis + * - LP filtering of the adaptive excitation + * - codebook target computation + *-----------------------------------------------------------------*/ + test(); + IF( ( EQ_16( i_subfr, L_SUBFR ) ) && ( EQ_16( *T0, 2 * L_SUBFR ) ) ) + { + *gain_pit_fx = 0; + move16(); + *clip_gain = 0; + move16(); + g_corr_fx[0] = 0; + move16(); + g_corr_fx[1] = 0; + move16(); + *Jopt_flag = 0; + move16(); + + set16_fx( &exc_fx[i_subfr], 0, L_SUBFR + 1 ); /* set excitation for current subrame to 0 */ + push_indice( hBstr, IND_LP_FILT_SELECT, 0, 1 ); /* this bit is actually not needed */ + + Copy( xn_fx, xn2_fx, L_SUBFR ); /* target vector for codebook search */ + set16_fx( y1_fx, 0, L_SUBFR ); /* set filtered adaptive excitation to 0 */ + set16_fx( &bwe_exc_fx[i_subfr * 2], 0, L_SUBFR * 2 ); + } + ELSE + { + /* Find the adaptive codebook vector - ACELP long-term prediction */ + pred_lt4( &exc_fx[i_subfr], &exc_fx[i_subfr], *T0, *T0_frac, L_SUBFR + 1, pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP ); + offset = L_deposit_l( 0 ); + + tmp = extract_l( L_mult( *T0_frac, 32 ) ); /*Q8, 0.25 in Q7*/ + tmp = add( 512, tmp ); /*Q8; 2 in Q8*/ + tmp = mult_r( tmp, 256 ); /*Q16->Q0; 2 in Q7*/ + + tmp1 = sub( *T0, 2 ); /*Q0*/ + tmp1 = shl( tmp1, 1 ); /*Q0 */ + + offset = add( tmp, tmp1 ); /*Q0*/ + FOR( i = 0; i < L_SUBFR * 2; i++ ) + { + /* bwe_exc_fx[i + i_subfr * 2] = bwe_exc_fx[i + i_subfr * 2 - *T0 * 2 - (int) ((float) *T0_frac * 0.5f + 4 + 0.5f) + 4];move16();*/ + bwe_exc_fx[i + i_subfr * 2] = bwe_exc_fx[i + i_subfr * 2 - offset + 4]; + } + + *clip_gain = gp_clip_fx( st_fx->element_mode, st_fx->core_brate, st_fx->voicing_fx, i_subfr, TRANSITION, xn_fx, gp_cl_fx, Q_new ); + + lp_select = lp_filt_exc_enc_fx( MODE1, TRANSITION, i_subfr, exc_fx, h1_fx, + xn_fx, y1_fx, xn2_fx, L_SUBFR, st_fx->L_frame, g_corr_fx, *clip_gain, gain_pit_fx, &lp_flag ); + + IF( EQ_16( lp_flag, NORMAL_OPERATION ) ) + { + push_indice( hBstr, IND_LP_FILT_SELECT, lp_select, 1 ); + } + + *Jopt_flag = 1; + move16(); + } + + /***pt_pitch = (float)(*T0) + (float)(*T0_frac)/4.0f;*/ /* save subframe pitch value */ + /***pt_pitch_fx = shl(add(*T0,shr(*T0_frac,2)),4); move16();*/ + tmp = shl( add( shl( *T0, 2 ), *T0_frac ), 4 ); + **pt_pitch_fx = tmp; + move16(); + + /*---------------------------------------------------------------------* + * fill the pitch buffer - needed for post-processing + *---------------------------------------------------------------------*/ + test(); + test(); + IF( ( EQ_16( sub( i_subfr, *tc_subfr ), L_SUBFR ) ) || ( *tc_subfr == 0 && EQ_16( i_subfr, 2 * L_SUBFR ) ) ) + { + index = shr( i_subfr, 6 ); + ( *pt_pitch_fx ) -= index; + move16(); + + FOR( i = 0; i < index; i++ ) + { + **pt_pitch_fx = tmp; + move16(); + ( *pt_pitch_fx )++; + } + } + } + } + + return; +} + /*-------------------------------------------------------------------------------------------* * tc_enc() * @@ -1084,6 +1880,222 @@ static void tc_enc_fx( return; } +static void tc_enc_ivas_fx( + Encoder_State *st_fx, /* i/o: encoder state structure */ + const Word16 i_subfr, /* i : subrame index */ + Word16 *tc_subfr, /* i/o: TC subframe index */ + Word16 *position, /* i/o: index of the residual signal maximum */ + const Word16 *h1_fx, /* i : weighted filter input response Q(14+shift)*/ + const Word16 *xn_fx, /* i : target signal Q_new-1+shift*/ + Word16 *exc_fx, /* o : glottal codebook contribution Q_new*/ + Word16 *yy1_fx, /* o : filtered glottal codebook contribution */ + Word16 *T0_min, /* o : lower pitch limit Q0*/ + Word16 *T0_max, /* o : higher pitch limit Q0*/ + Word16 *T0, /* o : close loop integer pitch Q0*/ + Word16 *T0_frac, /* o : close loop fractional part of the pitch Q0*/ + Word16 *gain_pit_fx, /* o : pitch gain (0..GAIN_PIT_MAX) Q14*/ + Word16 g_corr_fx[], /* o : correlations and -2 */ + Word16 *bwe_exc_fx, /* i/o: excitation for SWB TBE Q_new*/ + Word16 Q_new /* i : input scaling */ +) +{ + Word16 i, imp_shape, imp_pos, index, nBits, h1_tmp_fx[L_SUBFR]; + Word16 pitch_index, pitch_sign_fx; + Word32 gain_trans32; + BSTR_ENC_HANDLE hBstr = st_fx->hBstr; +#ifdef BASOP_NOGLOB_DECLARE_LOCAL + Flag Overflow = 0; +#endif + imp_pos = sub( *position, i_subfr ); + FOR( i = 0; i < L_SUBFR; i++ ) + { + h1_tmp_fx[i] = h1_fx[i]; + move16(); + } + /*-----------------------------------------------------------------* + * get number of bits for pitch encoding + *-----------------------------------------------------------------*/ + + nBits = st_fx->acelp_cfg.pitch_bits[shr( i_subfr, 6 )]; + + /*--------------------------------------------------------------* + * Closed loop pitch search + *--------------------------------------------------------------*/ + + *T0_frac = 0; + move16(); + + IF( EQ_16( st_fx->L_frame, L_FRAME ) ) + { + test(); + IF( ( LE_16( *T0_min, L_SUBFR ) ) || ( EQ_16( *tc_subfr, 3 * L_SUBFR ) ) ) + { + IF( EQ_16( nBits, 9 ) ) + { + *T0 = pitch_fr4_fx( &exc_fx[i_subfr], xn_fx, h1_fx, *T0_min, *T0_max, T0_frac, 0, 0, PIT_FR2_9b, PIT_FR1_9b, L_FRAME, L_SUBFR ); + } + ELSE IF( EQ_16( nBits, 6 ) ) + { + *T0 = pitch_fr4_fx( &exc_fx[i_subfr], xn_fx, h1_fx, *T0_min, *T0_max, T0_frac, 0, 0, PIT_MIN, L_SUBFR, L_FRAME, L_SUBFR ); + } + ELSE + { + *T0 = pitch_fr4_fx( &exc_fx[i_subfr], xn_fx, h1_fx, *T0_min, *T0_max, T0_frac, 0, 0, PIT_MAX, PIT_MIN, L_FRAME, L_SUBFR ); + } + } + ELSE + { + *T0 = L_SUBFR; + move16(); + } + test(); + if ( EQ_16( *tc_subfr, L_SUBFR ) && LT_16( *T0, L_SUBFR ) ) + { + *T0 = L_SUBFR; + move16(); + } + } + ELSE /* st_fx->L_frame == L_FRAME16k */ + { + IF( EQ_16( nBits, 10 ) ) + { + *T0 = pitch_fr4_fx( &exc_fx[i_subfr], xn_fx, h1_fx, *T0_min, *T0_max, T0_frac, 0, 1, PIT16k_FR2_EXTEND_10b, PIT16k_MAX, L_FRAME16k, L_SUBFR ); + } + ELSE IF( EQ_16( nBits, 6 ) ) + { + /* T0_frac with 1/2 sample resolution */ + *T0 = pitch_fr4_fx( &exc_fx[i_subfr], xn_fx, h1_fx, *T0_min, *T0_max, T0_frac, 0, 0, PIT16k_MIN, L_SUBFR, L_FRAME16k, L_SUBFR ); + IF( *T0 > L_SUBFR ) + { + *T0 = L_SUBFR; + move16(); + *T0_frac = 0; + move16(); + } + } + } + + + /* set tc_subfr to TC_0_0 */ + test(); + test(); + test(); + if ( i_subfr == 0 && EQ_16( st_fx->L_frame, L_FRAME ) && ( LT_16( *T0, L_SUBFR ) || EQ_16( *tc_subfr, 3 * L_SUBFR ) ) ) + { + *tc_subfr = TC_0_0; + move16(); + } + + /*--------------------------------------------------------------* + * Builds glottal codebook contribution + *--------------------------------------------------------------*/ + + set_impulse_fx( xn_fx, h1_tmp_fx, &exc_fx[i_subfr], yy1_fx, &imp_shape, &imp_pos, &gain_trans32, Q_new ); /*chk h1_tmp_fx*/ + + /*--------------------------------------------------------------* + * quantize gain_trans and scale glottal codebook contribution + *--------------------------------------------------------------*/ + + gain_trans_enc_fx( gain_trans32, &exc_fx[i_subfr], &pitch_index, &pitch_sign_fx, Q_new ); + + /* set past excitation buffer to zeros */ + set16_fx( exc_fx - L_EXC_MEM, 0, L_EXC_MEM ); + /*--------------------------------------------------------------* + * adapt. search of the second impulse in the same subframe + * (when appears) + *--------------------------------------------------------------*/ + + pred_lt4_tc_fx( exc_fx, *T0, *T0_frac, inter4_2_fx, imp_pos, i_subfr ); + IF( st_fx->hBWE_TD != NULL ) + { + IF( EQ_16( st_fx->L_frame, L_FRAME ) ) + { + interp_code_5over2_fx( &exc_fx[i_subfr], &bwe_exc_fx[i_subfr * HIBND_ACB_L_FAC], L_SUBFR ); + } + ELSE + { + interp_code_4over2_fx( &exc_fx[i_subfr], &bwe_exc_fx[i_subfr * 2], L_SUBFR ); + } + } + /*--------------------------------------------------------------* + * compute glottal-shape codebook excitation + *--------------------------------------------------------------*/ + + /* create filtered glottal codebook contribution */ + conv_fx( &exc_fx[i_subfr], h1_fx, yy1_fx, L_SUBFR ); + + /* gain_pit computation */ +#ifdef BASOP_NOGLOB + *gain_pit_fx = corr_xy1_fx( xn_fx, yy1_fx, g_corr_fx, L_SUBFR, 0, &Overflow ); +#else + *gain_pit_fx = corr_xy1_fx( xn_fx, yy1_fx, g_corr_fx, L_SUBFR, 0 ); +#endif + /*--------------------------------------------------------------* + * Encode parameters and write indices + *--------------------------------------------------------------*/ + IF( EQ_16( st_fx->L_frame, L_FRAME ) ) + { + test(); + test(); + IF( ( ( i_subfr != 0 ) || ( EQ_16( *tc_subfr, TC_0_0 ) ) ) && ( NE_16( *tc_subfr, L_SUBFR ) ) ) + { + test(); + /* write pitch index */ + IF( ( GE_16( *T0, L_SUBFR ) ) && ( NE_16( *tc_subfr, 3 * L_SUBFR ) ) ) + { + push_indice( hBstr, IND_PITCH, 0, nBits ); + } + ELSE IF( EQ_16( *tc_subfr, 3 * L_SUBFR ) ) + { + IF( EQ_16( nBits, 9 ) ) + { + index = abs_pit_enc_fx( 4, 0, *T0, *T0_frac ); + } + ELSE + { + index = abs_pit_enc_fx( 2, 0, *T0, *T0_frac ); + } + push_indice( hBstr, IND_PITCH, index, nBits ); + + limit_T0_fx( L_FRAME, 8, 0, 0, *T0, 0, T0_min, T0_max ); + } + ELSE + { + IF( EQ_16( nBits, 6 ) ) + { + index = delta_pit_enc_fx( 2, *T0, *T0_frac, PIT_MIN - 1 ); + push_indice( hBstr, IND_PITCH, index, nBits ); + } + ELSE + { + index = delta_pit_enc_fx( 0, *T0, *T0_frac, PIT_MIN - 1 ); + push_indice( hBstr, IND_PITCH, index, nBits ); + } + } + } + } + ELSE /* st_fx->L_frame == L_FRAME16k */ + { + IF( EQ_16( nBits, 10 ) ) + { + pit16k_Q_enc_ivas_fx( hBstr, nBits, 1, *T0, *T0_frac, T0_min, T0_max ); + } + ELSE IF( EQ_16( nBits, 6 ) ) + { + index = add( shl( sub( *T0, PIT16k_MIN ), 1 ), shr( *T0_frac, 1 ) ); + push_indice( hBstr, IND_PITCH, index, nBits ); + } + } + push_indice( hBstr, IND_TC_IMP_SHAPE, imp_shape, 3 ); + push_indice( hBstr, IND_TC_IMP_POS, imp_pos, 6 ); + push_indice( hBstr, IND_TC_IMP_SIGN, pitch_sign_fx, 1 ); + push_indice( hBstr, IND_TC_IMP_GAIN, pitch_index, 3 ); + + *position = add( imp_pos, i_subfr ); + move16(); + return; +} + /*-----------------------------------------------------------------* * gain_trans_enc() -- GitLab From 1183f0463c2944ce7e44a79af34e457ab85581b1 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Wed, 13 Nov 2024 16:15:56 +0530 Subject: [PATCH 119/128] EVS BE fix --- lib_enc/gp_clip_fx.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib_enc/gp_clip_fx.c b/lib_enc/gp_clip_fx.c index 9eba45cb8..d99636a1b 100644 --- a/lib_enc/gp_clip_fx.c +++ b/lib_enc/gp_clip_fx.c @@ -160,7 +160,14 @@ Word16 gp_clip_fx( e_ener = norm_l( ener ); f_ener = Log2_norm_lc( L_shl( ener, e_ener ) ); e_ener = sub( 30, e_ener ); - e_ener = sub( e_ener, Q_new * 2 + 1 ); + IF( GT_16( element_mode, EVS_MONO ) ) + { + e_ener = sub( e_ener, Q_new * 2 + 1 ); + } + ELSE + { + e_ener = sub( e_ener, Q_new ); + } ener = Mpy_32_16( e_ener, f_ener, LG10 ); wener = round_fx( L_shl( ener, 10 ) ); -- GitLab From d185b9319a42b666ab2864a664ba0e257e173ebf Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Thu, 14 Nov 2024 14:39:00 +0530 Subject: [PATCH 120/128] Encoder code float stucture elements cleanup, LTV crash fixes, Q-info updates for lib_com files [x] Encoder LTV crash fixes [x] Q-info for lib_com files [x] Float structure elements cleanup for encoder --- lib_com/cldfb.c | 24 + lib_com/fd_cng_com.c | 35 +- lib_com/hq_tools_fx.c | 860 ++++++++++---------- lib_com/ivas_prot.h | 29 +- lib_com/ivas_prot_fx.h | 17 + lib_com/modif_fs.c | 8 +- lib_com/prot.h | 23 +- lib_com/prot_fx.h | 18 +- lib_com/stat_com.h | 158 ++-- lib_com/swb_bwe_com_fx.c | 333 ++++---- lib_com/swb_bwe_com_hr_fx.c | 58 +- lib_com/swb_bwe_com_lr_fx.c | 5 +- lib_com/swb_tbe_com.c | 24 +- lib_com/swb_tbe_com_fx.c | 371 +++++---- lib_com/syn_filt_fx.c | 48 +- lib_com/tcq_position_arith.c | 2 + lib_com/tcq_position_arith_fx.c | 102 +-- lib_com/tcx_mdct_fx.c | 2 +- lib_com/tec_com.c | 385 ++++----- lib_com/tns_base.c | 327 ++++---- lib_com/trans_direct_fx.c | 96 +-- lib_com/trans_inv_fx.c | 395 ++++----- lib_enc/acelp_core_enc.c | 64 +- lib_enc/acelp_enc_util_fx.c | 1 + lib_enc/avq_cod_fx.c | 11 +- lib_enc/cod2t32_fx.c | 5 +- lib_enc/core_enc_init.c | 31 +- lib_enc/core_enc_switch.c | 3 - lib_enc/core_switching_enc.c | 53 +- lib_enc/corr_xh_fx.c | 37 +- lib_enc/enc_acelpx_fx.c | 8 +- lib_enc/enc_gen_voic.c | 2 + lib_enc/enc_pit_exc.c | 2 + lib_enc/enc_pit_exc_fx.c | 8 +- lib_enc/enc_tran.c | 2 + lib_enc/enc_uv.c | 2 + lib_enc/enc_uv_fx.c | 18 +- lib_enc/eval_pit_contr.c | 2 + lib_enc/fd_cng_enc.c | 28 +- lib_enc/fd_cng_enc_fx.c | 17 +- lib_enc/find_tar.c | 2 + lib_enc/gaus_enc.c | 2 + lib_enc/gp_clip.c | 2 + lib_enc/gs_enc.c | 24 + lib_enc/init_enc.c | 44 +- lib_enc/inov_enc_fx.c | 24 +- lib_enc/ivas_core_enc.c | 52 +- lib_enc/ivas_core_pre_proc.c | 1190 +++++----------------------- lib_enc/ivas_core_pre_proc_front.c | 141 ++-- lib_enc/ivas_cpe_enc.c | 11 - lib_enc/ivas_front_vad.c | 4 - lib_enc/ivas_masa_enc.c | 4 +- lib_enc/pitch_ol.c | 12 +- lib_enc/prot_fx_enc.h | 9 +- lib_enc/q_gain2p.c | 2 + lib_enc/rst_enc.c | 19 +- lib_enc/speech_music_classif.c | 6 +- lib_enc/stat_enc.h | 153 ++-- lib_enc/swb_bwe_enc_fx.c | 14 +- lib_enc/tcq_core_enc.c | 2 + lib_enc/tns_base_enc_fx.c | 2 +- lib_enc/transition_enc.c | 2 +- lib_enc/voiced_enc.c | 27 +- 63 files changed, 2293 insertions(+), 3069 deletions(-) diff --git a/lib_com/cldfb.c b/lib_com/cldfb.c index f9b618373..ccca93784 100644 --- a/lib_com/cldfb.c +++ b/lib_com/cldfb.c @@ -2843,6 +2843,8 @@ static void cldfb_init_proto_and_twiddles_enc_fx( { hs->ds = 10; hs->da = 10; + move16(); + move16(); hs->rot_vec_ana_delay_re_fx = NULL; hs->rot_vec_ana_delay_im_fx = NULL; hs->rot_vec_syn_delay_re_fx = NULL; @@ -2857,6 +2859,8 @@ static void cldfb_init_proto_and_twiddles_enc_fx( { hs->ds = 40; hs->da = -20; + move16(); + move16(); hs->rot_vec_ana_delay_re_fx = rot_vec_delay_re_LDQMF_fx; hs->rot_vec_ana_delay_im_fx = rot_vec_delay_im_LDQMF_fx; hs->rot_vec_syn_delay_re_fx = rot_vec_delay_re_LDQMF_fx; @@ -2884,6 +2888,8 @@ static void cldfb_init_proto_and_twiddles_enc_fx( { hs->ds = 20; hs->da = 20; + move16(); + move16(); hs->rot_vec_ana_delay_re_fx = NULL; hs->rot_vec_ana_delay_im_fx = NULL; hs->rot_vec_syn_delay_re_fx = NULL; @@ -2898,6 +2904,8 @@ static void cldfb_init_proto_and_twiddles_enc_fx( { hs->ds = 80; hs->da = -40; + move16(); + move16(); hs->rot_vec_ana_delay_re_fx = rot_vec_delay_re_LDQMF_fx; hs->rot_vec_ana_delay_im_fx = rot_vec_delay_im_LDQMF_fx; hs->rot_vec_syn_delay_re_fx = rot_vec_delay_re_LDQMF_fx; @@ -2932,6 +2940,8 @@ static void cldfb_init_proto_and_twiddles_enc_fx( { hs->ds = 20; hs->da = 20; + move16(); + move16(); hs->rot_vec_ana_delay_re_fx = NULL; hs->rot_vec_ana_delay_im_fx = NULL; hs->rot_vec_syn_delay_re_fx = NULL; @@ -2946,6 +2956,8 @@ static void cldfb_init_proto_and_twiddles_enc_fx( { hs->ds = 80; hs->da = -40; + move16(); + move16(); hs->rot_vec_ana_delay_re_fx = rot_vec_delay_re_LDQMF_fx; hs->rot_vec_ana_delay_im_fx = rot_vec_delay_im_LDQMF_fx; hs->rot_vec_syn_delay_re_fx = rot_vec_delay_re_LDQMF_fx; @@ -2979,6 +2991,8 @@ static void cldfb_init_proto_and_twiddles_enc_fx( { hs->ds = 30; hs->da = 30; + move16(); + move16(); hs->rot_vec_ana_delay_re_fx = NULL; hs->rot_vec_ana_delay_im_fx = NULL; hs->rot_vec_syn_delay_re_fx = NULL; @@ -2991,6 +3005,8 @@ static void cldfb_init_proto_and_twiddles_enc_fx( { hs->ds = 120; hs->da = -60; + move16(); + move16(); hs->rot_vec_ana_delay_re_fx = rot_vec_delay_re_LDQMF_fx; hs->rot_vec_ana_delay_im_fx = rot_vec_delay_im_LDQMF_fx; hs->rot_vec_syn_delay_re_fx = rot_vec_delay_re_LDQMF_fx; @@ -3018,6 +3034,8 @@ static void cldfb_init_proto_and_twiddles_enc_fx( { hs->ds = 32; hs->da = 32; + move16(); + move16(); hs->rot_vec_ana_delay_re_fx = NULL; hs->rot_vec_ana_delay_im_fx = NULL; hs->rot_vec_syn_delay_re_fx = NULL; @@ -3032,6 +3050,8 @@ static void cldfb_init_proto_and_twiddles_enc_fx( { hs->ds = 160; hs->da = -80; + move16(); + move16(); hs->rot_vec_ana_delay_re_fx = rot_vec_delay_re_LDQMF_fx; hs->rot_vec_ana_delay_im_fx = rot_vec_delay_im_LDQMF_fx; hs->rot_vec_syn_delay_re_fx = rot_vec_delay_re_LDQMF_fx; @@ -3065,6 +3085,8 @@ static void cldfb_init_proto_and_twiddles_enc_fx( { hs->ds = 40; hs->da = 40; + move16(); + move16(); hs->rot_vec_ana_delay_re_fx = NULL; hs->rot_vec_ana_delay_im_fx = NULL; hs->rot_vec_syn_delay_re_fx = NULL; @@ -3079,6 +3101,8 @@ static void cldfb_init_proto_and_twiddles_enc_fx( { hs->ds = 160; hs->da = -80; + move16(); + move16(); hs->rot_vec_ana_delay_re_fx = rot_vec_delay_re_LDQMF_fx; hs->rot_vec_ana_delay_im_fx = rot_vec_delay_im_LDQMF_fx; hs->rot_vec_syn_delay_re_fx = rot_vec_delay_re_LDQMF_fx; diff --git a/lib_com/fd_cng_com.c b/lib_com/fd_cng_com.c index 37a10990b..d81159dde 100644 --- a/lib_com/fd_cng_com.c +++ b/lib_com/fd_cng_com.c @@ -50,9 +50,9 @@ /*------------------------------------------------------------------- * Local function prototypes *-------------------------------------------------------------------*/ - +#ifndef IVAS_FLOAT_FIXED static void mhvals_flt( const int16_t d, float *m ); - +#endif static void getmidbands( int16_t *part, const int16_t npart, int16_t *midband, float *psize_flt, float *psize_inv_flt ); @@ -85,11 +85,12 @@ ivas_error createFdCngCom_flt( * * *-------------------------------------------------------------------*/ - +#ifndef IVAS_FLOAT_FIXED void initFdCngCom_flt( HANDLE_FD_CNG_COM hFdCngCom, /* i/o: FD_CNG structure containing all buffers and variables */ const float scale ) { + /* Calculate FFT scaling factor */ hFdCngCom->scalingFactor_flt = 1 / ( scale * scale * 8.f ); @@ -100,28 +101,20 @@ void initFdCngCom_flt( /* Initialize the comfort noise generation */ set_f( hFdCngCom->fftBuffer_flt, 0.0f, FFTLEN ); - set_f( hFdCngCom->cngNoiseLevel_flt, 0.0f, FFTCLDFBLEN ); set_f( hFdCngCom->olapBufferSynth2_flt, 0.0f, FFTLEN ); + set_f( hFdCngCom->cngNoiseLevel_flt, 0.0f, FFTCLDFBLEN ); /* Initialize quantizer */ set_f( hFdCngCom->sidNoiseEst_flt, 0.0f, NPART ); set_f( hFdCngCom->A_cng_flt, 0.0f, M + 1 ); hFdCngCom->A_cng_flt[0] = 1.f; -#ifdef IVAS_FLOAT_FIXED - set16_fx( hFdCngCom->A_cng, 0, M + 1 ); - hFdCngCom->A_cng[0] = MAX_16; -#endif /* Set some counters and flags */ hFdCngCom->inactive_frame_counter = 0; /* Either SID or zero frames */ hFdCngCom->active_frame_counter = 0; hFdCngCom->frame_type_previous = ACTIVE_FRAME; hFdCngCom->flag_noisy_speech = 0; -#ifndef IVAS_FLOAT_FIXED hFdCngCom->likelihood_noisy_speech_flt = 0.f; -#else - hFdCngCom->likelihood_noisy_speech = 0; -#endif hFdCngCom->numCoreBands = 0; hFdCngCom->stopBand = 0; hFdCngCom->startBand = 0; @@ -136,33 +129,24 @@ void initFdCngCom_flt( set_f( hFdCngCom->periodog_flt, 0.0f, PERIODOGLEN ); mhvals_flt( MSNUMSUBFR * MSSUBFRLEN, &( hFdCngCom->msM_win_flt ) ); mhvals_flt( MSSUBFRLEN, &( hFdCngCom->msM_subwin_flt ) ); - set_f( hFdCngCom->msPeriodogSum_flt, 0.0f, 2 ); set_f( hFdCngCom->msPsdSum_flt, 0.0f, 2 ); -#ifndef IVAS_FLOAT_FIXED + set_f( hFdCngCom->msPeriodogSum_flt, 0.0f, 2 ); set_f( hFdCngCom->msSlope_flt, 0.0f, 2 ); set_f( hFdCngCom->msQeqInvAv_flt, 0.0f, 2 ); -#else - set16_fx( hFdCngCom->msSlope, 0, 2 ); - set32_fx( hFdCngCom->msQeqInvAv, 0, 2 ); -#endif hFdCngCom->init_old_flt = 0; + hFdCngCom->msFrCnt_init_counter = 0; hFdCngCom->msFrCnt_init_thresh = 1; hFdCngCom->offsetflag = 0; hFdCngCom->msFrCnt = MSSUBFRLEN; hFdCngCom->msMinBufferPtr = 0; -#ifndef IVAS_FLOAT_FIXED set_f( hFdCngCom->msAlphaCor_flt, 0.3f, 2 ); hFdCngCom->coherence_flt = 0.5f; -#else - set32_fx( hFdCngCom->msAlphaCor, 644245120l /*0.3f Q31*/, 2 ); - - hFdCngCom->coherence_fx = 16384; /* 0.5 in Q15 */ -#endif return; } +#endif /*------------------------------------------------------------------- @@ -1238,7 +1222,7 @@ void SynthesisSTFT_dirac_fx( * * Compute some values used in the bias correction of the minimum statistics algorithm *-------------------------------------------------------------------*/ - +#ifndef IVAS_FLOAT_FIXED static void mhvals_flt( const int16_t d, float *m ) @@ -1278,6 +1262,7 @@ static void mhvals_flt( return; } +#endif /*------------------------------------------------------------------- * rand_gauss_flt() diff --git a/lib_com/hq_tools_fx.c b/lib_com/hq_tools_fx.c index 5ce398247..d84973511 100644 --- a/lib_com/hq_tools_fx.c +++ b/lib_com/hq_tools_fx.c @@ -60,8 +60,8 @@ static void overlap_hq_bwe_fx( const Word32 *hq_swb_overlap_buf, Word32 *coeff_o void hq_swb_harmonic_calc_norm_envelop_fx( const Word32 *L_SWB_signal, /* i : input signal Q=12*/ Word32 *L_envelope, /* o : output envelope Q=12*/ - const Word16 L_swb_norm, /* i : length of normaliztion */ - const Word16 SWB_flength /* i : length of input signal */ + const Word16 L_swb_norm, /* i : length of normaliztion Q0*/ + const Word16 SWB_flength /* i : length of input signal Q0*/ ) { @@ -73,7 +73,7 @@ void hq_swb_harmonic_calc_norm_envelop_fx( Word16 i; Word32 L_tmp; - lookback = shr( L_swb_norm, 1 ); + lookback = shr( L_swb_norm, 1 ); /*Q0*/ env_index = 0; move16(); FOR( n_freq = 0; n_freq < lookback; n_freq++ ) @@ -86,9 +86,9 @@ void hq_swb_harmonic_calc_norm_envelop_fx( FOR( n_lag = 0; n_lag < n_lag_now; n_lag++ ) { - L_tmp = L_abs( L_SWB_signal[n_lag] ); + L_tmp = L_abs( L_SWB_signal[n_lag] ); /*Q12*/ #ifdef BASOP_NOGLOB - L_envelope[env_index] = L_add_sat( L_envelope[env_index], L_tmp ); + L_envelope[env_index] = L_add_sat( L_envelope[env_index], L_tmp ); /*Q12*/ #else L_envelope[env_index] = L_add( L_envelope[env_index], L_tmp ); #endif @@ -97,7 +97,7 @@ void hq_swb_harmonic_calc_norm_envelop_fx( env_index = add( env_index, 1 ); } - n_lag_now = L_swb_norm; + n_lag_now = L_swb_norm; /*Q0*/ move16(); FOR( n_freq = 0; n_freq < SWB_flength - L_swb_norm; n_freq++ ) @@ -107,9 +107,9 @@ void hq_swb_harmonic_calc_norm_envelop_fx( move16(); FOR( n_lag = 0; n_lag < n_lag_now; n_lag++ ) { - L_tmp = L_abs( L_SWB_signal[add( n_freq, n_lag )] ); + L_tmp = L_abs( L_SWB_signal[( n_freq + n_lag )] ); /*Q12*/ #ifdef BASOP_NOGLOB - L_envelope[env_index] = L_add_sat( L_envelope[env_index], L_tmp ); + L_envelope[env_index] = L_add_sat( L_envelope[env_index], L_tmp ); /*Q12*/ #else L_envelope[env_index] = L_add( L_envelope[env_index], L_tmp ); #endif @@ -129,9 +129,9 @@ void hq_swb_harmonic_calc_norm_envelop_fx( move32(); FOR( n_lag = 0; n_lag < n_lag_now; n_lag++ ) { - L_tmp = L_abs( L_SWB_signal[add( n_freq, n_lag )] ); + L_tmp = L_abs( L_SWB_signal[( n_freq + n_lag )] ); /*Q12*/ #ifdef BASOP_NOGLOB - L_envelope[env_index] = L_add_sat( L_envelope[env_index], L_tmp ); + L_envelope[env_index] = L_add_sat( L_envelope[env_index], L_tmp ); /*Q12*/ #else L_envelope[env_index] = L_add( L_envelope[env_index], L_tmp ); #endif @@ -152,10 +152,10 @@ void hq_swb_harmonic_calc_norm_envelop_fx( *--------------------------------------------------------------------------*/ void limit_band_noise_level_calc_fx( - const Word16 *wnorm, /* i : reordered norm of sub-vectors */ - Word16 *limit, /* o : highest band of bit allocation */ - const Word32 core_brate, /* i : bit rate */ - Word16 *noise_level /* o : noise level Q15 */ + const Word16 *wnorm, /* i : reordered norm of sub-vectors Q0*/ + Word16 *limit, /* o : highest band of bit allocation Q0*/ + const Word32 core_brate, /* i : bit rate Q0*/ + Word16 *noise_level /* o : noise level Q15*/ ) { Word16 ener_limit, ener_sum; @@ -164,7 +164,7 @@ void limit_band_noise_level_calc_fx( Word32 fact; Word16 tmp; - nb_sfm = *limit; + nb_sfm = *limit; /*Q0*/ move16(); ener_limit = 0; move16(); @@ -172,37 +172,37 @@ void limit_band_noise_level_calc_fx( move16(); FOR( i = 0; i < 10; i++ ) { - ener_limit = add( ener_limit, wnorm[i] ); - *noise_level = add( *noise_level, abs_s( sub( wnorm[i + 1], wnorm[i] ) ) ); + ener_limit = add( ener_limit, wnorm[i] ); /*Q0*/ + *noise_level = add( *noise_level, abs_s( sub( wnorm[i + 1], wnorm[i] ) ) ); /*Q15*/ move16(); } - ener_sum = ener_limit; + ener_sum = ener_limit; /*Q0*/ move16(); tmp = sub( nb_sfm, 1 ); FOR( i = 10; i < tmp; i++ ) { - ener_sum = add( ener_sum, wnorm[i] ); - *noise_level = add( *noise_level, abs_s( sub( wnorm[i + 1], wnorm[i] ) ) ); + ener_sum = add( ener_sum, wnorm[i] ); /*Q0*/ + *noise_level = add( *noise_level, abs_s( sub( wnorm[i + 1], wnorm[i] ) ) ); /*Q15*/ move16(); } - ener_sum = add( ener_sum, wnorm[nb_sfm - 1] ); + ener_sum = add( ener_sum, wnorm[nb_sfm - 1] ); /*Q0*/ - fact = 2022929597; + fact = 2022929597; /*Q31*/ move32(); if ( LT_32( core_brate, HQ_BWE_CROSSOVER_BRATE ) ) { - fact = L_add( 1900523029, 1 ); + fact = L_add( 1900523029, 1 ); /*Q31*/ } - fact = Mult_32_16( fact, ener_sum ); + fact = Mult_32_16( fact, ener_sum ); /*Q16*/ i = 9; move16(); test(); WHILE( LT_32( L_deposit_h( ener_limit ), fact ) && LT_16( add( i, 1 ), nb_sfm ) ) { - ener_limit = add( ener_limit, wnorm[++i] ); + ener_limit = add( ener_limit, wnorm[++i] ); /*Q0*/ test(); } *limit = i; @@ -224,11 +224,11 @@ void limit_band_noise_level_calc_fx( { IF( ener_sum != 0 ) { - *noise_level = sub( 8192, div_s( *noise_level, ener_sum ) ); + *noise_level = sub( 8192 /*Q15*/, div_s( *noise_level, ener_sum ) ); } ELSE { - *noise_level = 8192; + *noise_level = 8192; /*Q15*/ } move16(); } @@ -273,7 +273,7 @@ Word16 build_nf_codebook_fx( /* o : Number of coe IF( flag_32K_env_ho ) { /* Build compressed (+/- 1) noise-fill codebook */ - sfm_base = sfm_start[sfm]; + sfm_base = sfm_start[sfm]; /*Q0*/ move16(); FOR( i = 0; i < sfmsize[sfm] / 8; i++ ) { @@ -283,14 +283,14 @@ Word16 build_nf_codebook_fx( /* o : Number of coe { IF( coeff[j] > 0 ) { - CodeBook_mod[cb_size] = 1 << 12; - move16(); /* set to 1, Q value 12 */ + CodeBook_mod[cb_size] = 1 << 12; /*Q12*/ + move16(); E_cb_vec = add( E_cb_vec, 1 ); } ELSE IF( coeff[j] < 0 ) { - CodeBook_mod[cb_size] = -1 * ( 1 << 12 ); - move16(); /* set to -1, Q value 12 */ + CodeBook_mod[cb_size] = -1 * ( 1 << 12 ); /*Q12*/ + move16(); E_cb_vec = add( E_cb_vec, 1 ); } ELSE @@ -311,7 +311,7 @@ Word16 build_nf_codebook_fx( /* o : Number of coe { FOR( j = sfm_start[sfm]; j < sfm_end[sfm]; j++ ) { - CodeBook[cb_size] = coeff[j]; + CodeBook[cb_size] = coeff[j]; /*Q12*/ move16(); cb_size = add( cb_size, 1 ); } @@ -326,29 +326,29 @@ Word16 build_nf_codebook_fx( /* o : Number of coe IF( CodeBook_mod[j] != 0 ) { /* Densify codebook */ - CodeBook[j] = -4096; - move16(); /* -1 in Q12 */ + CodeBook[j] = -4096; /*Q12*/ + move16(); if ( CodeBook_mod[j] > 0 ) { - CodeBook[j] = 4096; - move16(); /* 1 in Q12 */ + CodeBook[j] = 4096; /*Q12*/ + move16(); } IF( CodeBook_mod[cb_size - j - 1] != 0 ) { - CodeBook[j] = shl( CodeBook[j], 1 ); - move16(); /* Mult by 2 */ + CodeBook[j] = shl( CodeBook[j], 1 ); /*Q12*/ + move16(); /* Mult by 2 */ } } ELSE { - CodeBook[j] = CodeBook_mod[cb_size - j - 1]; + CodeBook[j] = CodeBook_mod[cb_size - j - 1]; /*Q12*/ move16(); } } } - return cb_size; + return cb_size; /*Q0*/ } @@ -359,25 +359,25 @@ Word16 build_nf_codebook_fx( /* o : Number of coe *--------------------------------------------------------------------------*/ Word16 find_last_band_fx( /* o : index of last band */ - const Word16 *bitalloc, /* i : bit allocation */ - const Word16 nb_sfm /* i : number of possibly coded bands */ + const Word16 *bitalloc, /* i : bit allocation Q0*/ + const Word16 nb_sfm /* i : number of possibly coded bands Q0*/ ) { Word16 sfm, core_sfm; - core_sfm = sub( nb_sfm, 1 ); + core_sfm = sub( nb_sfm, 1 ); /*Q0*/ FOR( sfm = nb_sfm - 1; sfm >= 0; sfm-- ) { IF( bitalloc[sfm] != 0 ) { - core_sfm = sfm; + core_sfm = sfm; /*Q0*/ move16(); BREAK; } } - return core_sfm; + return core_sfm; /*Q0*/ } /*--------------------------------------------------------------------------* @@ -429,7 +429,7 @@ void apply_noisefill_HQ_fx( { FOR( i = 0; i < sfmsize[sfm]; i++ ) { - cb_buff[i] = CodeBook_mod[cb_pos++]; + cb_buff[i] = CodeBook_mod[cb_pos++]; /*Q12*/ move16(); L_E_cb_vec = L_mac0_sat( L_E_cb_vec, cb_buff[i], cb_buff[i] ); /*Q24 (12+12) */ @@ -444,7 +444,7 @@ void apply_noisefill_HQ_fx( { FOR( i = 0; i < sfmsize[sfm]; i++ ) { - cb_buff[i] = CodeBook[cb_pos++]; + cb_buff[i] = CodeBook[cb_pos++]; /*Q12*/ move16(); L_E_cb_vec = L_mac0_sat( L_E_cb_vec, cb_buff[i], cb_buff[i] ); /*Q24 (12+12) */ @@ -464,7 +464,7 @@ void apply_noisefill_HQ_fx( L_E_corr = Isqrt( L_E_corr ); /*Q19 (31-24/2) */ E_corr = extract_h( L_shl( L_E_corr, 10 ) ); /*Q13 (13-(19-16)) */ - istart = sfm_start[sfm]; + istart = sfm_start[sfm]; /*Q0*/ move16(); FOR( j = istart; j < sfm_end[sfm]; j++ ) { @@ -477,7 +477,7 @@ void apply_noisefill_HQ_fx( { FOR( j = sfm_start[sfm]; j < sfm_end[sfm]; j++ ) { - coeff[j] = CodeBook[cb_pos++]; + coeff[j] = CodeBook[cb_pos++]; /*Q12*/ move16(); if ( GE_16( cb_pos, cb_size ) ) { @@ -500,17 +500,17 @@ void apply_noisefill_HQ_fx( *--------------------------------------------------------------------------*/ void harm_bwe_fine_fx( - const Word16 *R, /* i : bit allocation */ - const Word16 last_sfm, /* i : last coded subband */ - const Word16 high_sfm, /* i : higher transition band to BWE */ - const Word16 num_sfm, /* i : total number of bands */ - const Word16 *norm, /* i : quantization indices for norms */ - const Word16 *sfm_start, /* i : Subband start coefficient */ - const Word16 *sfm_end, /* i : Subband end coefficient */ - Word16 *prev_L_swb_norm, /* i/o: last normalize length */ - Word16 *coeff, /* i/o: coded/noisefilled normalized spectrum */ - Word32 *coeff_out, /* o : coded/noisefilled spectrum */ - Word16 *coeff_fine /* o : BWE fine structure */ + const Word16 *R, /* i : bit allocation Q0*/ + const Word16 last_sfm, /* i : last coded subband Q0*/ + const Word16 high_sfm, /* i : higher transition band to BWE Q0*/ + const Word16 num_sfm, /* i : total number of bands Q0*/ + const Word16 *norm, /* i : quantization indices for norms Q0*/ + const Word16 *sfm_start, /* i : Subband start coefficient Q0*/ + const Word16 *sfm_end, /* i : Subband end coefficient Q0*/ + Word16 *prev_L_swb_norm, /* i/o: last normalize length Q0*/ + Word16 *coeff, /* i/o: coded/noisefilled normalized spectrum Q12*/ + Word32 *coeff_out, /* o : coded/noisefilled spectrum Q12*/ + Word16 *coeff_fine /* o : BWE fine structure Q15*/ ) { Word16 sfm; @@ -530,7 +530,7 @@ void harm_bwe_fine_fx( { IF( R[sfm] != 0 ) { - normq = dicn_fx[norm[sfm]]; + normq = dicn_fx[norm[sfm]]; /*Q14*/ move32(); FOR( i = sfm_start[sfm]; i < sfm_end[sfm]; i++ ) @@ -543,14 +543,14 @@ void harm_bwe_fine_fx( { FOR( i = sfm_start[sfm]; i < sfm_end[sfm]; i++ ) { - coeff_out[i] = L_deposit_l( 0 ); + coeff_out[i] = L_deposit_l( 0 ); /*Q12*/ move16(); } } } /* excitation replication */ - Copy32( coeff_out, L_signal, L_HARMONIC_EXC ); + Copy32( coeff_out, L_signal, L_HARMONIC_EXC ); /*Q12*/ calc_normal_length_fx_32( HQ_CORE, coeff_out, HQ_HARMONIC, -1, &norm_width, prev_L_swb_norm ); hq_swb_harmonic_calc_norm_envelop_fx( L_signal, envelope, norm_width, L_HARMONIC_EXC ); @@ -560,10 +560,10 @@ void harm_bwe_fine_fx( IF( L_signal[i] > 0 ) { norm_signal = norm_l( envelope[i] ); - enve_lo[i] = L_Extract_lc( L_shl( envelope[i], norm_signal ), &enve_hi[i] ); - L_signal[i] = Div_32( L_signal[i], enve_hi[i], enve_lo[i] ); + enve_lo[i] = L_Extract_lc( L_shl( envelope[i], norm_signal ), &enve_hi[i] ); /*Q12+norm_signal-16*/ + L_signal[i] = Div_32( L_signal[i], enve_hi[i], enve_lo[i] ); /*Q31 - norm_signal*/ #ifdef BASOP_NOGLOB - SWB_signal[i] = round_fx_sat( L_shl_sat( L_signal[i], norm_signal ) ); + SWB_signal[i] = round_fx_sat( L_shl_sat( L_signal[i], norm_signal ) ); /*Q15*/ #else SWB_signal[i] = round_fx( L_shl( L_signal[i], norm_signal ) ); #endif @@ -574,10 +574,10 @@ void harm_bwe_fine_fx( ELSE { norm_signal = norm_l( envelope[i] ); - enve_lo[i] = L_Extract_lc( L_shl( envelope[i], norm_signal ), &enve_hi[i] ); - L_signal[i] = L_negate( Div_32( L_negate( L_signal[i] ), enve_hi[i], enve_lo[i] ) ); + enve_lo[i] = L_Extract_lc( L_shl( envelope[i], norm_signal ), &enve_hi[i] ); /*Q12+norm_signal-16*/ + L_signal[i] = L_negate( Div_32( L_negate( L_signal[i] ), enve_hi[i], enve_lo[i] ) ); /*Q31 - norm_signal*/ #ifdef BASOP_NOGLOB - SWB_signal[i] = round_fx_sat( L_shl_sat( L_signal[i], norm_signal ) ); + SWB_signal[i] = round_fx_sat( L_shl_sat( L_signal[i], norm_signal ) ); /*Q15*/ #else SWB_signal[i] = round_fx( L_shl( L_signal[i], norm_signal ) ); #endif @@ -587,16 +587,16 @@ void harm_bwe_fine_fx( } } - dst = coeff_fine + sfm_end[last_sfm]; - end = coeff_fine + sfm_end[num_sfm - 1]; + dst = coeff_fine + sfm_end[last_sfm]; /*Q15*/ + end = coeff_fine + sfm_end[num_sfm - 1]; /*Q15*/ IF( LE_16( sub( sfm_end[last_sfm], sfm_end[high_sfm] ), ( L_HARMONIC_EXC - START_EXC ) ) ) { - src = SWB_signal + START_EXC + sub( sfm_end[last_sfm], sfm_end[high_sfm] ); + src = SWB_signal + START_EXC + sub( sfm_end[last_sfm], sfm_end[high_sfm] ); /*Q15*/ } ELSE { - src = SWB_signal + L_HARMONIC_EXC - 1; + src = SWB_signal + L_HARMONIC_EXC - 1; /*Q15*/ } WHILE( dst < end ) @@ -604,7 +604,7 @@ void harm_bwe_fine_fx( logic32(); WHILE( dst < end && src < &SWB_signal[L_HARMONIC_EXC] ) { - *dst++ = *src++; + *dst++ = *src++; /*Q15*/ move16(); } src--; @@ -612,7 +612,7 @@ void harm_bwe_fine_fx( logic32(); WHILE( dst < end && src >= &SWB_signal[START_EXC] ) { - *dst++ = *src--; + *dst++ = *src--; /*Q15*/ move16(); } src++; @@ -676,17 +676,17 @@ void hvq_bwe_fine_fx( tmp = div_s( 1 << 14, tmp ); /* 15+14-(-4+s)=Q(33-s) */ Mpy_32_16_ss( L_coeff[i], tmp, &L_tmp, &lsb ); /* 12+33-s+1-16=Q(30-s) */ shift2 = add( shift, 1 ); - tmp = round_fx( L_shl( L_tmp, shift2 ) ); /* 30-s+s+1-16=Q(15) */ - SWB_signal[i] = add( tmp, extract_l( L_shr( lsb, sub( 32, shift2 ) ) ) ); - move16(); /* Q15 */ - /*SWB_signal[i] = round_fx(L_shl(L_tmp, add(shift, 1))); // 30-s+s+1-16=Q(15) */ + tmp = round_fx( L_shl( L_tmp, shift2 ) ); /* 30-s+s+1-16=Q(15) */ + SWB_signal[i] = add( tmp, extract_l( L_shr( lsb, sub( 32, shift2 ) ) ) ); /* Q15 */ + move16(); + /*SWB_signal[i] = round_fx(L_shl(L_tmp, add(shift, 1))); // 30-s+s+1-16=Q(15) */ } - dst = coeff_fine; - end = coeff_fine + sfm_end[num_sfm - 1] - sfm_end[last_sfm]; + dst = coeff_fine; /*Q15*/ + end = coeff_fine + sfm_end[num_sfm - 1] - sfm_end[last_sfm]; /*Q15*/ - src = SWB_signal + START_EXC; - peak_src = peak_pos + START_EXC; + src = SWB_signal + START_EXC; /*Q15*/ + peak_src = peak_pos + START_EXC; /*Q0*/ FOR( i = 0; i < Npeaks; i++ ) { @@ -718,29 +718,29 @@ void hvq_bwe_fine_fx( move16(); } - peak_dst = bwe_peaks + sfm_end[last_sfm]; + peak_dst = bwe_peaks + sfm_end[last_sfm]; /*Q0*/ WHILE( dst < end ) { test(); WHILE( dst < end && src < &SWB_signal[L_HARMONIC_EXC] ) { - *dst++ = *src++; + *dst++ = *src++; /*Q15*/ move16(); - *peak_dst++ = *peak_src++; + *peak_dst++ = *peak_src++; /*Q0*/ move16(); } - peak_src--; + peak_src--; /*Q0*/ src--; test(); WHILE( dst < end && src >= &SWB_signal[START_EXC] ) { - *dst++ = *src--; + *dst++ = *src--; /*Q15*/ move16(); - *peak_dst++ = *peak_src--; + *peak_dst++ = *peak_src--; /*Q0*/ move16(); } - peak_src++; + peak_src++; /*Q0*/ src++; } @@ -764,27 +764,30 @@ void hq_fold_bwe_fx( Word16 first_coeff; Word16 *src, *dst, *end; - low_coeff = shr( sfm_end[last_sfm], 1 ); - src = coeff + sfm_end[last_sfm] - 1; + low_coeff = shr( sfm_end[last_sfm], 1 ); /*Q0*/ + src = coeff + sfm_end[last_sfm] - 1; /*Q12*/ - first_coeff = sfm_end[last_sfm]; + first_coeff = sfm_end[last_sfm]; /*Q0*/ move16(); - dst = coeff + sfm_end[last_sfm]; - end = coeff + sfm_end[num_sfm - 1]; + dst = coeff + sfm_end[last_sfm]; /*Q12*/ + end = coeff + sfm_end[num_sfm - 1]; /*Q12*/ WHILE( dst < end ) { + test(); WHILE( dst < end && src >= &coeff[low_coeff] ) { - *dst++ = *src--; + test(); + *dst++ = *src--; /*Q12*/ move16(); } src++; - + test(); WHILE( dst < end && src < &coeff[first_coeff] ) { - *dst++ = *src++; + test(); + *dst++ = *src++; /*Q12*/ move16(); } } @@ -816,7 +819,7 @@ void apply_nf_gain_fx( FOR( j = sfm_start[sfm]; j < sfm_end[sfm]; j++ ) { /* Scale NoiseFill */ - coeff[j] = shr( coeff[j], nf_idx ); + coeff[j] = shr( coeff[j], nf_idx ); /*Q12*/ move16(); } } @@ -834,20 +837,20 @@ void apply_nf_gain_fx( #ifdef IVAS_FLOAT_FIXED void ivas_harm_bwe_fx( - const Word16 *coeff_fine, /* i : fine structure for BWE */ - const Word16 *coeff, /* i : coded/noisefilled normalized spectrum */ - const Word16 num_sfm, /* i : Number of subbands */ - const Word16 *sfm_start, /* i : Subband start coefficient */ - const Word16 *sfm_end, /* i : Subband end coefficient */ - const Word16 last_sfm, /* i : last coded subband */ - const Word16 *R, /* i : bit allocation */ - const Word16 prev_hq_mode, /* i : previous hq mode */ - Word16 *norm, /* i/o: quantization indices for norms */ - Word16 *noise_level, /* i/o: noise levels for harmonic modes */ - Word16 *prev_noise_level, /* i/o: noise factor in previous frame */ - Word16 *bwe_seed, /* i/o: random seed for generating BWE input */ - Word32 *coeff_out, /* o : coded/noisefilled spectrum */ - const Word16 element_mode /* i : IVAS element mode */ + const Word16 *coeff_fine, /* i : fine structure for BWE Q12*/ + const Word16 *coeff, /* i : coded/noisefilled normalized spectrum Q12*/ + const Word16 num_sfm, /* i : Number of subbands Q0*/ + const Word16 *sfm_start, /* i : Subband start coefficient Q0*/ + const Word16 *sfm_end, /* i : Subband end coefficient Q0*/ + const Word16 last_sfm, /* i : last coded subband Q0*/ + const Word16 *R, /* i : bit allocation Q0*/ + const Word16 prev_hq_mode, /* i : previous hq mode Q0*/ + Word16 *norm, /* i/o: quantization indices for norms Q0*/ + Word16 *noise_level, /* i/o: noise levels for harmonic modes Q15*/ + Word16 *prev_noise_level, /* i/o: noise factor in previous frame Q15*/ + Word16 *bwe_seed, /* i/o: random seed for generating BWE input Q0*/ + Word32 *coeff_out, /* o : coded/noisefilled spectrum Q12*/ + const Word16 element_mode /* i : IVAS element mode Q0*/ ) { Word16 i, j; @@ -871,35 +874,35 @@ void ivas_harm_bwe_fx( FOR( i = sfm_start[sfm]; i < sfm_end[sfm]; i++ ) { - coeff_out[i] = L_shl( Mult_32_16( normq, coeff[i] ), 1 ); - move32(); /*12 Q(14 +12+1-16 +1) */ + coeff_out[i] = L_shl( Mult_32_16( normq, coeff[i] ), 1 ); /*Q12*/ + move32(); } } } - noise_level[1] = noise_level[0]; + noise_level[1] = noise_level[0]; /*Q15*/ move16(); /* shaping the BWE spectrum further by envelopes and noise factors */ - L_tmp = L_mult( 29491, prev_noise_level[0] ); /* 15 +1 +15 */ - noise_level[0] = round_fx( L_mac( L_tmp, 3277, noise_level[0] ) ); /*15 */ + L_tmp = L_mult( 29491 /*0.9 in Q15*/, prev_noise_level[0] ); /* 15 +1 +15 */ + noise_level[0] = round_fx( L_mac( L_tmp, 3277 /*0.1 in Q15*/, noise_level[0] ) ); /*15 */ move16(); - L_tmp = L_mult( 29491, prev_noise_level[1] ); - noise_level[1] = round_fx( L_mac( L_tmp, 3277, noise_level[1] ) ); + L_tmp = L_mult( 29491 /*0.9 in Q15*/, prev_noise_level[1] ); /*Q31*/ + noise_level[1] = round_fx( L_mac( L_tmp, 3277 /*0.1 in Q15*/, noise_level[1] ) ); /*Q15*/ move16(); test(); - IF( EQ_16( prev_hq_mode, HQ_NORMAL ) || EQ_16( prev_hq_mode, HQ_GEN_SWB ) ) + IF( ( prev_hq_mode == HQ_NORMAL ) || EQ_16( prev_hq_mode, HQ_GEN_SWB ) ) { IF( LT_16( noise_level[0], 8192 ) ) { - noise_level[0] = shl( noise_level[0], 2 ); + noise_level[0] = shl( noise_level[0], 2 ); /*Q15*/ move16(); } IF( LT_16( noise_level[1], 8192 ) ) { - noise_level[1] = shl( noise_level[1], 2 ); + noise_level[1] = shl( noise_level[1], 2 ); /*Q15*/ move16(); } } @@ -914,18 +917,18 @@ void ivas_harm_bwe_fx( E_L = L_add( E_L, L_shr( L_tmp, 6 ) ); /*Q24 */ } - normq = dicn_fx[norm[i]]; + normq = dicn_fx[norm[i]]; /*Q14*/ move32(); - alfa = noise_level[0]; + alfa = noise_level[0]; /*Q15*/ move16(); IF( GT_16( i, 27 ) ) { - alfa = noise_level[1]; + alfa = noise_level[1]; /*Q15*/ move16(); } - band_width = sub( sfm_end[i], sfm_start[i] ); /* */ + band_width = sub( sfm_end[i], sfm_start[i] ); /* Q0 */ exp1 = norm_l( E_L ); IF( EQ_16( exp1, 0 ) ) { @@ -946,7 +949,7 @@ void ivas_harm_bwe_fx( } exp1 = norm_s( alfa ); - tmp1 = shl( alfa, exp1 ); + tmp1 = shl( alfa, exp1 ); /*Q15+exp1*/ IF( EQ_16( element_mode, EVS_MONO ) ) { exp1 = add( 1, exp1 ); @@ -960,11 +963,11 @@ void ivas_harm_bwe_fx( tmp1 = s_max( tmp1, 16384 ); tmp1 = div_s( 16384, tmp1 ); L_tmp2 = L_deposit_h( tmp1 ); - L_tmp2 = Isqrt_lc( L_tmp2, &exp1 ); + L_tmp2 = Isqrt_lc( L_tmp2, &exp1 ); /*Q31 - exp1*/ #ifdef BASOP_NOGLOB - beta = round_fx_sat( L_shl_sat( L_tmp2, exp1 ) ); - beta = shr( beta, 1 ); /*Q15 */ + beta = round_fx_sat( L_shl_sat( L_tmp2, exp1 ) ); /*Q15 */ + beta = shr( beta, 1 ); /*Q15*/ #else beta = round_fx( L_shl( L_tmp2, exp1 ) ); beta = shr( beta, 1 ); /*Q15 */ @@ -993,14 +996,14 @@ void ivas_harm_bwe_fx( } } - prev_noise_level[0] = noise_level[0]; + prev_noise_level[0] = noise_level[0]; /*Q15*/ move16(); - prev_noise_level[1] = noise_level[1]; + prev_noise_level[1] = noise_level[1]; /*Q15*/ move16(); - src = &coeff_out[add( sfm_end[last_sfm], L_HARMONIC_EXC - START_EXC )]; /*Q12 */ + src = &coeff_out[( sfm_end[last_sfm] + L_HARMONIC_EXC - START_EXC )]; /*Q12 */ - dst = src - 1; + dst = src - 1; /*Q12*/ FOR( i = 0; i < 16; i++ ) { *src = Mult_32_16( *src, hvq_bwe_fac_fx[i] ); /* Q12 (12+15+1-16) */ @@ -1019,20 +1022,20 @@ void ivas_harm_bwe_fx( #endif void harm_bwe_fx( - const Word16 *coeff_fine, /* i : fine structure for BWE */ - const Word16 *coeff, /* i : coded/noisefilled normalized spectrum */ - const Word16 num_sfm, /* i : Number of subbands */ - const Word16 *sfm_start, /* i : Subband start coefficient */ - const Word16 *sfm_end, /* i : Subband end coefficient */ - const Word16 last_sfm, /* i : last coded subband */ - const Word16 *R, /* i : bit allocation */ - const Word16 prev_hq_mode, /* i : previous hq mode */ - Word16 *norm, /* i/o: quantization indices for norms */ - Word16 *noise_level, /* i/o: noise levels for harmonic modes */ - Word16 *prev_noise_level, /* i/o: noise factor in previous frame */ - Word16 *bwe_seed, /* i/o: random seed for generating BWE input */ - Word32 *coeff_out, /* o : coded/noisefilled spectrum */ - const Word16 element_mode /* i : IVAS element mode */ + const Word16 *coeff_fine, /* i : fine structure for BWE Q12*/ + const Word16 *coeff, /* i : coded/noisefilled normalized spectrum Q12*/ + const Word16 num_sfm, /* i : Number of subbands Q0*/ + const Word16 *sfm_start, /* i : Subband start coefficient Q0*/ + const Word16 *sfm_end, /* i : Subband end coefficient Q0*/ + const Word16 last_sfm, /* i : last coded subband Q0*/ + const Word16 *R, /* i : bit allocation Q0*/ + const Word16 prev_hq_mode, /* i : previous hq mode Q0*/ + Word16 *norm, /* i/o: quantization indices for norms Q0*/ + Word16 *noise_level, /* i/o: noise levels for harmonic modes Q15*/ + Word16 *prev_noise_level, /* i/o: noise factor in previous frame Q15*/ + Word16 *bwe_seed, /* i/o: random seed for generating BWE input Q0*/ + Word32 *coeff_out, /* o : coded/noisefilled spectrum Q12*/ + const Word16 element_mode /* i : IVAS element mode Q0*/ ) { Word16 i, j; @@ -1056,12 +1059,12 @@ void harm_bwe_fx( FOR( i = sfm_start[sfm]; i < sfm_end[sfm]; i++ ) { - coeff_out[i] = L_shl( Mult_32_16( normq, coeff[i] ), 1 ); - move32(); /*12 Q(14 +12+1-16 +1) */ + coeff_out[i] = L_shl( Mult_32_16( normq, coeff[i] ), 1 ); /*12 Q(14 +12+1-16 +1) */ + move32(); } } } - noise_level[1] = noise_level[0]; + noise_level[1] = noise_level[0]; /*Q15*/ move16(); /* shaping the BWE spectrum further by envelopes and noise factors */ @@ -1069,22 +1072,22 @@ void harm_bwe_fx( noise_level[0] = round_fx( L_mac( L_tmp, 3277, noise_level[0] ) ); /*15 */ move16(); - L_tmp = L_mult( 29491, prev_noise_level[1] ); - noise_level[1] = round_fx( L_mac( L_tmp, 3277, noise_level[1] ) ); + L_tmp = L_mult( 29491 /*0.9 in Q15*/, prev_noise_level[1] ); /*Q31*/ + noise_level[1] = round_fx( L_mac( L_tmp, 3277, noise_level[1] ) ); /*Q15*/ move16(); test(); IF( prev_hq_mode == HQ_NORMAL || EQ_16( prev_hq_mode, HQ_GEN_SWB ) ) { - IF( LT_16( noise_level[0], 8192 ) ) + IF( LT_16( noise_level[0], 8192 /*Q15*/ ) ) { - noise_level[0] = shl( noise_level[0], 2 ); + noise_level[0] = shl( noise_level[0], 2 ); /*Q15*/ move16(); } - IF( LT_16( noise_level[1], 8192 ) ) + IF( LT_16( noise_level[1], 8192 /*Q15*/ ) ) { - noise_level[1] = shl( noise_level[1], 2 ); + noise_level[1] = shl( noise_level[1], 2 ); /*Q15*/ move16(); } } @@ -1099,14 +1102,14 @@ void harm_bwe_fx( E_L = L_add( E_L, L_shr( L_tmp, 6 ) ); /*Q24 */ } - normq = dicn_fx[norm[i]]; + normq = dicn_fx[norm[i]]; /*Q14*/ move32(); - alfa = noise_level[0]; + alfa = noise_level[0]; /*Q15*/ move16(); if ( GT_16( i, 27 ) ) { - alfa = noise_level[1]; + alfa = noise_level[1]; /*Q15*/ move16(); } @@ -1143,12 +1146,12 @@ void harm_bwe_fx( } #endif tmp1 = s_max( tmp1, 16384 ); - tmp1 = div_s( 16384, tmp1 ); - L_tmp2 = L_deposit_h( tmp1 ); - L_tmp2 = Isqrt_lc( L_tmp2, &exp1 ); + tmp1 = div_s( 16384, tmp1 ); /*Q15*/ + L_tmp2 = L_deposit_h( tmp1 ); /*Q31*/ + L_tmp2 = Isqrt_lc( L_tmp2, &exp1 ); /*Q31 - exp1*/ - beta = round_fx( L_shl( L_tmp2, exp1 ) ); - beta = shr( beta, 1 ); /*Q15 */ + beta = round_fx( L_shl( L_tmp2, exp1 ) ); /*Q15*/ + beta = shr( beta, 1 ); /*Q15 */ FOR( sfm = sfm_start[i]; sfm < sfm_end[i]; sfm++ ) @@ -1173,12 +1176,12 @@ void harm_bwe_fx( } } - prev_noise_level[0] = noise_level[0]; + prev_noise_level[0] = noise_level[0]; /*Q15*/ move16(); - prev_noise_level[1] = noise_level[1]; + prev_noise_level[1] = noise_level[1]; /*Q15*/ move16(); - src = &coeff_out[add( sfm_end[last_sfm], L_HARMONIC_EXC - START_EXC )]; /*Q12 */ + src = &coeff_out[( sfm_end[last_sfm] + L_HARMONIC_EXC - START_EXC )]; /*Q12 */ dst = src - 1; FOR( i = 0; i < 16; i++ ) @@ -1236,7 +1239,7 @@ void hvq_bwe_fx( Word16 norm_ind; Word32 *L_src, *L_dst; Word16 istart, iend; - Word16 offset = sfm_end[last_sfm]; + Word16 offset = sfm_end[last_sfm]; /*Q0*/ /* Fx specific variables */ Word32 L_tmp0, L_tmp1; @@ -1251,13 +1254,13 @@ void hvq_bwe_fx( move32(); /* L_tmp_norm */ move16(); /* bwe_noise_th */ - bwe_noise_th = add( bin_th, shr( sub( sfm_end[sub( num_sfm, 1 )], bin_th ), 1 ) ); + bwe_noise_th = add( bin_th, shr( sub( sfm_end[( num_sfm - 1 )], bin_th ), 1 ) ); logqnorm_fx( &L_coeff_out[sfm_start[last_sfm]], qout, &norm[last_sfm], 40, sfm_len[last_sfm], 0 ); move16(); /* shaping the BWE spectrum further by envelopes and noise factors */ - noise_level[0] = round_fx( L_mac( L_mult( 29491, prev_noise_level[0] ), 3277, noise_level[0] ) ); /* Q15 (15+15+1-16) */ - noise_level[1] = round_fx( L_mac( L_mult( 29491, prev_noise_level[1] ), 3277, noise_level[1] ) ); /* Q15 (15+15+1-16) */ + noise_level[0] = round_fx( L_mac( L_mult( 29491 /*0.9 Q15*/, prev_noise_level[0] ), 3277 /*0.1 Q15*/, noise_level[0] ) ); /* Q15 (15+15+1-16) */ + noise_level[1] = round_fx( L_mac( L_mult( 29491 /*0.9 Q15*/, prev_noise_level[1] ), 3277 /*0.1 Q15*/, noise_level[1] ) ); /* Q15 (15+15+1-16) */ move16(); move16(); @@ -1266,13 +1269,13 @@ void hvq_bwe_fx( { IF( LT_16( noise_level[0], 8192 /* 0.25f */ ) ) { - noise_level[0] = shl( noise_level[0], 2 ); + noise_level[0] = shl( noise_level[0], 2 ); /*Q15*/ move16(); } IF( LT_16( noise_level[1], 8192 /* 0.25f */ ) ) { - noise_level[1] = shl( noise_level[1], 2 ); + noise_level[1] = shl( noise_level[1], 2 ); /*Q15*/ move16(); } } @@ -1287,7 +1290,7 @@ void hvq_bwe_fx( move16(); FOR( i = sfm_start[norm_ind]; i < sfm_end[norm_ind + 1]; i++ ) { - tmp2 = abs_s( coeff_fine[i - offset] ); + tmp2 = abs_s( coeff_fine[i - offset] ); /*Qin*/ tmp = s_max( tmp, tmp2 ); } band_size = sub( sfm_end[norm_ind + 1], sfm_start[norm_ind] ); @@ -1303,9 +1306,9 @@ void hvq_bwe_fx( move16(); } /* E_L += coeff_fine[i-offset] * coeff_fine[i-offset]; */ - coeff_s[i] = shl( coeff_fine[i - offset], shift ); - move16(); /* Q15 + shift */ - L_E = L_mac0( L_E, coeff_s[i], coeff_s[i] ); /* Q2*(qin + shift) */ + coeff_s[i] = shl( coeff_fine[i - offset], shift ); /*Qin*/ + move16(); /* Q15 + shift */ + L_E = L_mac0( L_E, coeff_s[i], coeff_s[i] ); /* Q2*(qin + shift) */ } power_shift = shl( shift, 1 ); @@ -1322,8 +1325,8 @@ void hvq_bwe_fx( /* normq = 0.1f*dicn[norm[norm_ind-1]] + 0.8f*dicn[norm[norm_ind]] + 0.1f*dicn[norm[norm_ind+1]]; */ /* tmp_norm = 0.1f*dicn[norm[norm_ind]] + 0.8f*dicn[norm[norm_ind+1]] + 0.1f*dicn[norm[norm_ind+2]]; */ - L_tmp0 = L_add( dicn_fx[norm[norm_ind]], 0 ); - L_tmp1 = L_add( dicn_fx[norm[norm_ind + 1]], 0 ); + L_tmp0 = L_add( dicn_fx[norm[norm_ind]], 0 ); /*Q14*/ + L_tmp1 = L_add( dicn_fx[norm[norm_ind + 1]], 0 ); /*Q14*/ L_normq = Madd_32_16( Madd_32_16( Mult_32_16( L_tmp0, 26214 /* Q15, 0.8f */ ), dicn_fx[norm[norm_ind - 1]], 3277 /* Q15, 0.1f */ ), L_tmp1, 3277 /* Q15, 0.1f */ ); /* Q14 (14+15+1-16) */ move16(); L_tmp_norm = Madd_32_16( Madd_32_16( Mult_32_16( L_tmp1, 26214 /* Q15, 0.8f */ ), dicn_fx[norm[norm_ind + 2]], 3277 /* Q15, 0.1f */ ), L_tmp0, 3277 /* Q15, 0.1f */ ); /* Q14 (14+15+1-16) */ @@ -1366,26 +1369,26 @@ void hvq_bwe_fx( IF( L_tmp0 != 0 ) { /* Normalize with 1 bit headroom for addition */ - tmp = 30 - ( qin + 2 ); /* Assuming fixed Q values */ + tmp = sub( 30, add( qin, 2 ) ); /* Assuming fixed Q values */ tmp = s_min( norm_l( L_tmp0 ), tmp ); tmp = sub( tmp, 1 ); L_tmp0 = L_add( L_shl( L_tmp0, tmp ), L_shr( lsb, sub( 16, tmp ) ) ); /* Qin+2+tmp */ - L_tmp0 = L_add( L_tmp0, L_shr( L_mult0( noise_level[0], Random( bwe_seed ) ), sub( 30 - ( qin + 2 ), tmp ) ) ); /* Qin+2+tmp */ - tmp = round_fx( L_shl( L_tmp0, 27 - ( qin + 2 ) - tmp ) ); /* Q11 (Qin+2+tmp+27-qin-2-tmp-16) */ + L_tmp0 = L_add( L_tmp0, L_shr( L_mult0( noise_level[0], Random( bwe_seed ) ), sub( sub( 30, add( qin, 2 ) ), tmp ) ) ); /* Qin+2+tmp */ + tmp = round_fx( L_shl( L_tmp0, sub( sub( 27, add( qin, 2 ) ), tmp ) ) ); /* Q11 (Qin+2+tmp+27-qin-2-tmp-16) */ - Mpy_32_16_ss( L_tmp1, tmp, &L_tmp0, &lsb ); /* Q10 (14+11+1-16) */ - L_coeff_out[i] = L_add( L_shl( L_tmp0, qout - 10 ), L_shr( lsb, 10 + 16 - qout ) ); - move32(); /* Qout (10+qout-10) */ + Mpy_32_16_ss( L_tmp1, tmp, &L_tmp0, &lsb ); /* Q10 (14+11+1-16) */ + L_coeff_out[i] = L_add( L_shl( L_tmp0, sub( qout, 10 ) ), L_shr( lsb, add( 10, sub( 16, qout ) ) ) ); /*Qout*/ + move32(); } ELSE { L_tmp0 = L_mult0( noise_level[0], Random( bwe_seed ) ); /* Q30 (15+15) */ tmp = round_fx( L_tmp0 ); /* Q14 (30-16) */ Mpy_32_16_ss( L_tmp1, tmp, &L_tmp0, &lsb ); /* Q13 (14+14+1-16) */ - L_coeff_out[i] = L_shr( L_tmp0, 13 - qout ); - move32(); /* Qout (13-(13-qout)) */ + L_coeff_out[i] = L_shr( L_tmp0, sub( 13, qout ) ); /*Qout*/ + move32(); } } @@ -1451,7 +1454,7 @@ void hvq_bwe_fx( } power_shift = shl( shift, 1 ); - L_E = L_shr( L_E, sub( power_shift, 28 - 2 * qin ) ); /* Q28 */ + L_E = L_shr( L_E, sub( power_shift, sub( 28, imult1616( 2, qin ) ) ) ); /* Q28 */ /* E_L = (float)sqrt((iend - istart)/E_L); */ L_E = Mult_32_16( L_E, inv_tbl_fx[band_size] ); /* Q28 (28+15+1-16) */ @@ -1487,17 +1490,17 @@ void hvq_bwe_fx( move16(); high = s_min( add( norm_ind, 1 ), last_norm_ind ); move16(); - sel_norm = norm[norm_ind - 1]; + sel_norm = norm[norm_ind - 1]; /*Q0*/ move16(); FOR( j = low; j <= high; j++ ) { if ( GT_16( norm[j], sel_norm ) ) { - sel_norm = norm[j]; + sel_norm = norm[j]; /*Q0*/ move16(); } } - L_normq = dicn_fx[sel_norm]; + L_normq = dicn_fx[sel_norm]; /*Q14*/ move16(); } @@ -1523,26 +1526,26 @@ void hvq_bwe_fx( { FOR( i = sfm_start[norm_ind]; i < sfm_end[norm_ind]; i++ ) { - L_coeff_out[i] = L_coeff[i]; /* Scaling already applied */ + L_coeff_out[i] = L_coeff[i]; /* Scaling already applied Q12*/ move32(); } } } - prev_noise_level[0] = noise_level[0]; + prev_noise_level[0] = noise_level[0]; /*Q15*/ move16(); - prev_noise_level[1] = noise_level[1]; + prev_noise_level[1] = noise_level[1]; /*Q15*/ move16(); - L_src = &L_coeff_out[add( sfm_end[last_sfm], L_HARMONIC_EXC - START_EXC )]; /* Address initialization */ - L_dst = L_src - 1; /* Address computation */ + L_src = &L_coeff_out[( sfm_end[last_sfm] + L_HARMONIC_EXC - START_EXC )]; /* Address initialization Qout*/ + L_dst = L_src - 1; /* Address computation Qout*/ FOR( i = 0; i < 16; i++ ) { - *L_src = Mult_32_16( *L_src, hvq_bwe_fac_fx[i] ); - L_src++; /* Qout (Qout+15+1-16) */ + *L_src = Mult_32_16( *L_src, hvq_bwe_fac_fx[i] ); /* Qout (Qout+15+1-16) */ + L_src++; /* Qout (Qout+15+1-16) */ move32(); - *L_dst = Mult_32_16( *L_dst, hvq_bwe_fac_fx[i] ); - L_dst--; /* Qout (Qout+15+1-16) */ + *L_dst = Mult_32_16( *L_dst, hvq_bwe_fac_fx[i] ); /* Qout (Qout+15+1-16) */ + L_dst--; /* Qout (Qout+15+1-16) */ move32(); } @@ -1555,12 +1558,12 @@ void hvq_bwe_fx( * Compute the band limits for concatenated bands for PVQ target signal in HVQ *--------------------------------------------------------------------------*/ void hvq_concat_bands_fx( - const Word16 pvq_bands, /* i : Number of bands in concatenated PVQ target */ - const Word16 *sel_bnds, /* i : Array of selected high bands */ - const Word16 n_sel_bnds, /* i : Number of selected high bands */ - Word16 *hvq_band_start, /* i : Band start indices */ - Word16 *hvq_band_width, /* i : Band widths */ - Word16 *hvq_band_end /* i : Band end indices */ + const Word16 pvq_bands, /* i : Number of bands in concatenated PVQ target Q0*/ + const Word16 *sel_bnds, /* i : Array of selected high bands Q0*/ + const Word16 n_sel_bnds, /* i : Number of selected high bands Q0*/ + Word16 *hvq_band_start, /* i : Band start indices Q0*/ + Word16 *hvq_band_width, /* i : Band widths Q0*/ + Word16 *hvq_band_end /* i : Band end indices Q0*/ ) { Word16 k, k_1; @@ -1573,20 +1576,21 @@ void hvq_concat_bands_fx( IF( GE_16( k, sub( pvq_bands, n_sel_bnds ) ) ) { k_1 = sub( k, 1 ); - hvq_band_start[k] = hvq_band_end[k_1]; + hvq_band_start[k] = hvq_band_end[k_1]; /*Q0*/ move16(); - hvq_band_width[k] = band_len_harm[*pSelBnds++]; + hvq_band_width[k] = band_len_harm[*pSelBnds++]; /*Q0*/ move16(); move16(); - hvq_band_end[k] = add( hvq_band_end[k_1], hvq_band_width[k] ); + hvq_band_end[k] = add( hvq_band_end[k_1], hvq_band_width[k] ); /*Q0*/ move16(); } ELSE { - hvq_band_start[k] = extract_l( L_mult0( k, HVQ_PVQ_COEFS ) ); - hvq_band_width[k] = HVQ_PVQ_COEFS; + hvq_band_start[k] = extract_l( L_mult0( k, HVQ_PVQ_COEFS ) ); /*Q0*/ move16(); - hvq_band_end[k] = add( hvq_band_start[k], HVQ_PVQ_COEFS ); + hvq_band_width[k] = HVQ_PVQ_COEFS; /*Q0*/ + move16(); + hvq_band_end[k] = add( hvq_band_start[k], HVQ_PVQ_COEFS ); /*Q0*/ move16(); } } @@ -1627,21 +1631,21 @@ void noise_mix_fx( tmp = s_min( norm_l( L_tmp0 ), tmp ); tmp = sub( tmp, 1 ); - L_tmp0 = L_add( L_shl( L_tmp0, tmp ), L_shr( lsb, sub( 16, tmp ) ) ); /* Qin+2+tmp */ - L_tmp0 = L_add( L_tmp0, L_shr( L_mult0( noise_level, Random( seed ) ), sub( 30 - ( qin + 2 ), tmp ) ) ); /* Qin+2+tmp */ + L_tmp0 = L_add( L_shl( L_tmp0, tmp ), L_shr( lsb, sub( 16, tmp ) ) ); /* Qin+2+tmp */ + L_tmp0 = L_add( L_tmp0, L_shr( L_mult0( noise_level, Random( seed ) ), sub( sub( 30, add( qin, 2 ) ), tmp ) ) ); /* Qin+2+tmp */ - tmp = round_fx( L_shl( L_tmp0, sub( sub( 27, add( qin, 2 ) ), tmp ) ) ); /* Q11 (Qin+2+tmp+27-qin-2-tmp-16) */ - Mpy_32_16_ss( L_normq, tmp, &L_tmp0, &lsb ); /* Q10 (14+11+1-16) */ - L_coeff_out[i] = L_add( L_shl( L_tmp0, qout - 10 ), L_shr( lsb, 10 + 16 - qout ) ); - move32(); /* Qout (10+qout-10) */ + tmp = round_fx( L_shl( L_tmp0, sub( sub( 27, add( qin, 2 ) ), tmp ) ) ); /* Q11 (Qin+2+tmp+27-qin-2-tmp-16) */ + Mpy_32_16_ss( L_normq, tmp, &L_tmp0, &lsb ); /* Q10 (14+11+1-16) */ + L_coeff_out[i] = L_add( L_shl( L_tmp0, sub( qout, 10 ) ), L_shr( lsb, add( 10, sub( 16, qout ) ) ) ); /* Qout (10+qout-10) */ + move32(); } ELSE { - L_tmp0 = L_mult0( noise_level, Random( seed ) ); /* Q30 (15+15) */ - tmp = round_fx( L_tmp0 ); /* Q14 (30-16) */ - Mpy_32_16_ss( L_normq, tmp, &L_tmp0, &lsb ); /* Q13 (14+14+1-16) */ - L_coeff_out[i] = L_shr( L_tmp0, 13 - qout ); - move32(); /* Qout (13-(13-qout)) */ + L_tmp0 = L_mult0( noise_level, Random( seed ) ); /* Q30 (15+15) */ + tmp = round_fx( L_tmp0 ); /* Q14 (30-16) */ + Mpy_32_16_ss( L_normq, tmp, &L_tmp0, &lsb ); /* Q13 (14+14+1-16) */ + L_coeff_out[i] = L_shr( L_tmp0, sub( 13, qout ) ); /* Qout (13-(13-qout)) */ + move32(); } } } @@ -1653,12 +1657,12 @@ void noise_mix_fx( * Prepare HQ GENERIC HF fine structure *--------------------------------------------------------------------------*/ void hq_generic_fine_fx( - Word16 *coeff, /* i : coded/noisefilled normalized spectrum */ - const Word16 last_sfm, /* i : Last coded band */ - const Word16 *sfm_start, /* i : Subband start coefficient */ - const Word16 *sfm_end, /* i : Subband end coefficient */ - Word16 *bwe_seed, /* i/o: random seed for generating BWE input */ - Word16 *coeff_out1 /* o : HQ GENERIC input */ + Word16 *coeff, /* i : coded/noisefilled normalized spectrum Q12*/ + const Word16 last_sfm, /* i : Last coded band Q0*/ + const Word16 *sfm_start, /* i : Subband start coefficient Q0*/ + const Word16 *sfm_end, /* i : Subband end coefficient Q0*/ + Word16 *bwe_seed, /* i/o: random seed for generating BWE input Q0*/ + Word16 *coeff_out1 /* o : HQ GENERIC input Q12*/ ) { Word16 sfm; @@ -1670,17 +1674,17 @@ void hq_generic_fine_fx( { IF( coeff[i] == 0 ) { - coeff_out1[i] = -2048; + coeff_out1[i] = -2048; /*Q12*/ move16(); if ( Random( bwe_seed ) > 0 ) { - coeff_out1[i] = 2048; + coeff_out1[i] = 2048; /*Q12*/ move16(); } } ELSE { - coeff_out1[i] = coeff[i]; + coeff_out1[i] = coeff[i]; /*Q12*/ move16(); } } @@ -1695,23 +1699,23 @@ void hq_generic_fine_fx( * Overlapping at the boundary between HQ core and BWE *--------------------------------------------------------------------------*/ static void overlap_hq_bwe_fx( - const Word32 *hq_swb_overlap_buf, /* i : spectrum from HQ core */ - Word32 *coeff_out, /* i/o: spectrum from BWE, overlapped output */ - const Word16 n_swb_overlap_offset, /* i : starting offset of overlapping */ - const Word16 n_swb_overlap, /* i : length of overlapping */ - const Word16 *R, - const Word16 num_env_bands, - const Word16 num_sfm, - const Word16 *sfm_end ) + const Word32 *hq_swb_overlap_buf, /* i : spectrum from HQ core Q12*/ + Word32 *coeff_out, /* i/o: spectrum from BWE, overlapped output Q12*/ + const Word16 n_swb_overlap_offset, /* i : starting offset of overlapping Q0*/ + const Word16 n_swb_overlap, /* i : length of overlapping Q0*/ + const Word16 *R, /*Q0*/ + const Word16 num_env_bands, /*Q0*/ + const Word16 num_sfm, /*Q0*/ + const Word16 *sfm_end /*Q0*/ ) { Word16 i; Word16 weighting; Word16 step; Word16 exp, tmp, n_band; - IF( R[sub( num_env_bands, 1 )] != 0 ) + IF( R[( num_env_bands - 1 )] != 0 ) { - Copy32( hq_swb_overlap_buf, &coeff_out[n_swb_overlap_offset], n_swb_overlap ); + Copy32( hq_swb_overlap_buf, &coeff_out[n_swb_overlap_offset], n_swb_overlap ); /*Q12*/ } ELSE { @@ -1723,8 +1727,8 @@ static void overlap_hq_bwe_fx( move16(); FOR( i = 0; i < n_swb_overlap; i++ ) { - coeff_out[add( n_swb_overlap_offset, i )] = L_add( coeff_out[add( n_swb_overlap_offset, i )], - Mult_32_16( L_sub( hq_swb_overlap_buf[i], coeff_out[add( n_swb_overlap_offset, i )] ), weighting ) ); + coeff_out[( n_swb_overlap_offset + i )] = L_add( coeff_out[( n_swb_overlap_offset + i )], + Mult_32_16( L_sub( hq_swb_overlap_buf[i], coeff_out[( n_swb_overlap_offset + i )] ), weighting ) ); /*Q12*/ move32(); weighting = sub( weighting, step ); } @@ -1734,9 +1738,9 @@ static void overlap_hq_bwe_fx( { IF( R[n_band] != 0 ) { - FOR( i = sfm_end[sub( n_band, 1 )]; i < sfm_end[n_band]; ++i ) + FOR( i = sfm_end[( n_band - 1 )]; i < sfm_end[n_band]; ++i ) { - coeff_out[i] = hq_swb_overlap_buf[sub( i, n_swb_overlap_offset )]; + coeff_out[i] = hq_swb_overlap_buf[( i - n_swb_overlap_offset )]; /*Q12*/ move32(); } } @@ -1750,65 +1754,65 @@ static void overlap_hq_bwe_fx( * mapping high frequency envelope to high band norm *--------------------------------------------------------------------------*/ void map_hq_generic_fenv_norm_fx( - const Word16 hqswb_clas, + const Word16 hqswb_clas, /*Q0*/ const Word16 *hq_generic_fenv, /* Q1, frequency-domain BWE envelope */ - Word16 *ynrm, - Word16 *normqlg2, - const Word16 num_env_bands, - const Word16 nb_sfm, - const Word16 hq_generic_offset ) + Word16 *ynrm, /*Q0*/ + Word16 *normqlg2, /*Q0*/ + const Word16 num_env_bands, /*Q0*/ + const Word16 nb_sfm, /*Q0*/ + const Word16 hq_generic_offset /*Q0*/ ) { - Word32 env_fl[17]; /*Q10 */ + Word32 env_fl[17]; /*Q8 */ Word16 i; set32_fx( env_fl, 0, 17 ); IF( EQ_16( hq_generic_offset, 144 ) ) { - env_fl[0] = L_shl( hq_generic_fenv[1], 7 ); + env_fl[0] = L_shl( hq_generic_fenv[1], 7 ); /*Q8*/ move32(); - env_fl[1] = L_add( L_mult0( hq_generic_fenv[2], 85 ), L_mult0( hq_generic_fenv[3], 43 ) ); + env_fl[1] = L_add( L_mult0( hq_generic_fenv[2], 85 ), L_mult0( hq_generic_fenv[3], 43 ) ); /*Q8*/ move32(); - env_fl[2] = L_add( L_mult0( hq_generic_fenv[3], 85 ), L_mult0( hq_generic_fenv[4], 43 ) ); + env_fl[2] = L_add( L_mult0( hq_generic_fenv[3], 85 ), L_mult0( hq_generic_fenv[4], 43 ) ); /*Q8*/ move32(); - env_fl[3] = L_add( L_mult0( hq_generic_fenv[4], 43 ), L_mult0( hq_generic_fenv[5], 85 ) ); + env_fl[3] = L_add( L_mult0( hq_generic_fenv[4], 43 ), L_mult0( hq_generic_fenv[5], 85 ) ); /*Q8*/ move32(); - env_fl[4] = L_add( L_mult0( hq_generic_fenv[5], 43 ), L_mult0( hq_generic_fenv[6], 85 ) ); + env_fl[4] = L_add( L_mult0( hq_generic_fenv[5], 43 ), L_mult0( hq_generic_fenv[6], 85 ) ); /*Q8*/ move32(); - env_fl[5] = L_shl( hq_generic_fenv[7], 7 ); + env_fl[5] = L_shl( hq_generic_fenv[7], 7 ); /*Q8*/ move32(); - env_fl[6] = L_add( L_mult0( hq_generic_fenv[8], 96 ), L_mult0( hq_generic_fenv[9], 32 ) ); + env_fl[6] = L_add( L_mult0( hq_generic_fenv[8], 96 ), L_mult0( hq_generic_fenv[9], 32 ) ); /*Q8*/ move32(); - env_fl[7] = L_add( L_mult0( hq_generic_fenv[9], 96 ), L_mult0( hq_generic_fenv[10], 32 ) ); + env_fl[7] = L_add( L_mult0( hq_generic_fenv[9], 96 ), L_mult0( hq_generic_fenv[10], 32 ) ); /*Q8*/ move32(); - env_fl[8] = L_add( L_mult0( hq_generic_fenv[10], 32 ), L_mult0( hq_generic_fenv[11], 96 ) ); + env_fl[8] = L_add( L_mult0( hq_generic_fenv[10], 32 ), L_mult0( hq_generic_fenv[11], 96 ) ); /*Q8*/ move32(); } ELSE { - env_fl[0] = L_add( L_mult0( hq_generic_fenv[0], 43 ), L_mult0( hq_generic_fenv[1], 85 ) ); + env_fl[0] = L_add( L_mult0( hq_generic_fenv[0], 43 ), L_mult0( hq_generic_fenv[1], 85 ) ); /*Q8*/ move32(); - env_fl[1] = L_add( L_mult0( hq_generic_fenv[1], 43 ), L_mult0( hq_generic_fenv[2], 85 ) ); + env_fl[1] = L_add( L_mult0( hq_generic_fenv[1], 43 ), L_mult0( hq_generic_fenv[2], 85 ) ); /*Q8*/ move32(); - env_fl[2] = L_shl( hq_generic_fenv[3], 7 ); + env_fl[2] = L_shl( hq_generic_fenv[3], 7 ); /*Q8*/ move32(); - env_fl[3] = L_add( L_mult0( hq_generic_fenv[4], 85 ), L_mult0( hq_generic_fenv[5], 43 ) ); + env_fl[3] = L_add( L_mult0( hq_generic_fenv[4], 85 ), L_mult0( hq_generic_fenv[5], 43 ) ); /*Q8*/ move32(); - env_fl[4] = L_add( L_mult0( hq_generic_fenv[5], 85 ), L_mult0( hq_generic_fenv[6], 43 ) ); + env_fl[4] = L_add( L_mult0( hq_generic_fenv[5], 85 ), L_mult0( hq_generic_fenv[6], 43 ) ); /*Q8*/ move32(); - env_fl[5] = L_add( L_mult0( hq_generic_fenv[6], 43 ), L_mult0( hq_generic_fenv[7], 85 ) ); + env_fl[5] = L_add( L_mult0( hq_generic_fenv[6], 43 ), L_mult0( hq_generic_fenv[7], 85 ) ); /*Q8*/ move32(); - env_fl[6] = L_add( L_mult0( hq_generic_fenv[7], 43 ), L_mult0( hq_generic_fenv[8], 85 ) ); + env_fl[6] = L_add( L_mult0( hq_generic_fenv[7], 43 ), L_mult0( hq_generic_fenv[8], 85 ) ); /*Q8*/ move32(); - env_fl[7] = L_add( L_mult0( hq_generic_fenv[8], 43 ), L_mult0( hq_generic_fenv[9], 85 ) ); + env_fl[7] = L_add( L_mult0( hq_generic_fenv[8], 43 ), L_mult0( hq_generic_fenv[9], 85 ) ); /*Q8*/ move32(); - env_fl[8] = L_add( L_mult0( hq_generic_fenv[9], 43 ), L_mult0( hq_generic_fenv[10], 85 ) ); + env_fl[8] = L_add( L_mult0( hq_generic_fenv[9], 43 ), L_mult0( hq_generic_fenv[10], 85 ) ); /*Q8*/ move32(); - env_fl[9] = L_add( L_mult0( hq_generic_fenv[10], 32 ), L_mult0( hq_generic_fenv[11], 96 ) ); + env_fl[9] = L_add( L_mult0( hq_generic_fenv[10], 32 ), L_mult0( hq_generic_fenv[11], 96 ) ); /*Q8*/ move32(); - env_fl[10] = L_shl( hq_generic_fenv[12], 7 ); + env_fl[10] = L_shl( hq_generic_fenv[12], 7 ); /*Q8*/ move32(); - env_fl[11] = L_shl( hq_generic_fenv[13], 7 ); + env_fl[11] = L_shl( hq_generic_fenv[13], 7 ); /*Q8*/ move32(); } @@ -1816,28 +1820,28 @@ void map_hq_generic_fenv_norm_fx( { IF( EQ_16( hq_generic_offset, 144 ) ) { - env_fl[9] = L_shl( hq_generic_fenv[12], 7 ); + env_fl[9] = L_shl( hq_generic_fenv[12], 7 ); /*Q8*/ move32(); - env_fl[10] = L_add( L_mult0( hq_generic_fenv[12], 32 ), L_mult0( hq_generic_fenv[13], 96 ) ); + env_fl[10] = L_add( L_mult0( hq_generic_fenv[12], 32 ), L_mult0( hq_generic_fenv[13], 96 ) ); /*Q8*/ move32(); - env_fl[11] = L_add( L_mult0( hq_generic_fenv[13], 64 ), L_mult0( hq_generic_fenv[14], 64 ) ); + env_fl[11] = L_add( L_mult0( hq_generic_fenv[13], 64 ), L_mult0( hq_generic_fenv[14], 64 ) ); /*Q8*/ move32(); - env_fl[12] = L_shl( hq_generic_fenv[12], 7 ); + env_fl[12] = L_shl( hq_generic_fenv[12], 7 ); /*Q8*/ move32(); - env_fl[13] = env_fl[12]; + env_fl[13] = env_fl[12]; /*Q8*/ move32(); } ELSE { - env_fl[12] = L_shl( hq_generic_fenv[14], 7 ); + env_fl[12] = L_shl( hq_generic_fenv[14], 7 ); /*Q8*/ move32(); - env_fl[13] = L_add( L_mult0( hq_generic_fenv[14], 32 ), L_mult0( hq_generic_fenv[15], 96 ) ); + env_fl[13] = L_add( L_mult0( hq_generic_fenv[14], 32 ), L_mult0( hq_generic_fenv[15], 96 ) ); /*Q8*/ move32(); - env_fl[14] = L_add( L_mult0( hq_generic_fenv[15], 64 ), L_mult0( hq_generic_fenv[16], 64 ) ); + env_fl[14] = L_add( L_mult0( hq_generic_fenv[15], 64 ), L_mult0( hq_generic_fenv[16], 64 ) ); /*Q8*/ move32(); - env_fl[15] = L_shl( hq_generic_fenv[16], 7 ); + env_fl[15] = L_shl( hq_generic_fenv[16], 7 ); /*Q8*/ move32(); - env_fl[16] = env_fl[15]; + env_fl[16] = env_fl[15]; /*Q8*/ move32(); } } @@ -1846,15 +1850,15 @@ void map_hq_generic_fenv_norm_fx( FOR( i = num_env_bands; i < nb_sfm; ++i ) { - normqlg2[i] = dicnlg2[s_min( add( ynrm[i], 10 ), 39 )]; + normqlg2[i] = dicnlg2[s_min( add( ynrm[i], 10 ), 39 )]; /*Q0*/ move16(); } return; } -static void update_rsubband_fx( const Word16 nb_sfm, - Word16 *Rsubband, /* Q3 */ - Word16 b_add_bits_denv ) +static void update_rsubband_fx( const Word16 nb_sfm, /*Q0*/ + Word16 *Rsubband, /* Q3 */ + Word16 b_add_bits_denv /*Q0*/ ) { Word16 i; @@ -1862,13 +1866,14 @@ static void update_rsubband_fx( const Word16 nb_sfm, WHILE( b_add_bits_denv > 0 ) { i = sub( nb_sfm, 1 ); + test(); WHILE( b_add_bits_denv > 0 && i >= 0 ) { IF( GT_16( Rsubband[i], 24 ) ) { - Rsubband[i] = sub( Rsubband[i], 8 ); + Rsubband[i] = sub( Rsubband[i], 8 ); /*Q3*/ move16(); - b_add_bits_denv = sub( b_add_bits_denv, 1 ); + b_add_bits_denv = sub( b_add_bits_denv, 1 ); /*Q0*/ } i = sub( i, 1 ); } @@ -1879,11 +1884,11 @@ static void update_rsubband_fx( const Word16 nb_sfm, Word16 get_nor_delta_hf_fx( Decoder_State *st, - Word16 *ynrm, - Word16 *Rsubband, /* Q3 */ - const Word16 num_env_bands, - const Word16 nb_sfm, - const Word16 core_sfm ) + Word16 *ynrm, /*Q0*/ + Word16 *Rsubband, /* Q3 */ + const Word16 num_env_bands, /*Q0*/ + const Word16 nb_sfm, /*Q0*/ + const Word16 core_sfm /*Q0*/ ) { Word16 i; Word16 delta, bitsforDelta, add_bits_denv; @@ -1892,7 +1897,7 @@ Word16 get_nor_delta_hf_fx( move16(); IF( GE_16( core_sfm, num_env_bands ) ) { - bitsforDelta = (Word16) get_next_indice_fx( st, 2 ); + bitsforDelta = (Word16) get_next_indice_fx( st, 2 ); /*Q0*/ bitsforDelta = add( bitsforDelta, 2 ); add_bits_denv = add( add_bits_denv, 2 ); @@ -1900,13 +1905,13 @@ Word16 get_nor_delta_hf_fx( { IF( Rsubband[i] != 0 ) { - delta = (Word16) get_next_indice_fx( st, bitsforDelta ); - ynrm[i] = add( ynrm[i], sub( delta, ( shl( 1, sub( bitsforDelta, 1 ) ) ) ) ); + delta = (Word16) get_next_indice_fx( st, bitsforDelta ); /*Q0*/ + ynrm[i] = add( ynrm[i], sub( delta, ( shl( 1, sub( bitsforDelta, 1 ) ) ) ) ); /*Q0*/ move16(); /* safety check in case of bit errors */ test(); - if ( ynrm[i] < 0 || GT_16( ynrm[i], 39 ) ) + IF( ynrm[i] < 0 || GT_16( ynrm[i], 39 ) ) { ynrm[i] = 39; move16(); @@ -1930,13 +1935,13 @@ Word16 get_nor_delta_hf_fx( Word16 calc_nor_delta_hf_ivas_fx( BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ const Word32 *t_audio, /* i : transform-domain coefficients Qx*/ - Word16 *ynrm, /* i/o: norm indices */ - Word16 *Rsubband, /* i/o: sub-band bit allocation */ - const Word16 num_env_bands, /* i : Number coded envelope bands */ - const Word16 nb_sfm, /* i : Number of envelope bands */ - const Word16 *sfmsize, /* i : band length */ - const Word16 *sfm_start, /* i : Start index of bands */ - const Word16 core_sfm /* i : index of the end band for core */ + Word16 *ynrm, /* i/o: norm indices Q0*/ + Word16 *Rsubband, /* i/o: sub-band bit allocation Q0*/ + const Word16 num_env_bands, /* i : Number coded envelope bands Q0*/ + const Word16 nb_sfm, /* i : Number of envelope bands Q0*/ + const Word16 *sfmsize, /* i : band length Q0*/ + const Word16 *sfm_start, /* i : Start index of bands Q0*/ + const Word16 core_sfm /* i : index of the end band for core Q0*/ ) { Word16 i; @@ -1952,18 +1957,18 @@ Word16 calc_nor_delta_hf_ivas_fx( { IF( Rsubband[i] != 0 ) { - delta = sub( ynrm_t[i], ynrm[i] ); + delta = sub( ynrm_t[i], ynrm[i] ); /*Q0*/ IF( delta > 0 ) { - delta = add( delta, 1 ); + delta = add( delta, 1 ); /*Q0*/ } ELSE { - delta = negate( delta ); + delta = negate( delta ); /*Q0*/ } if ( GT_16( delta, max_delta ) ) { - max_delta = delta; + max_delta = delta; /*Q0*/ move16(); } } @@ -1976,7 +1981,7 @@ Word16 calc_nor_delta_hf_ivas_fx( move16(); FOR( ; max_delta >= 2; max_delta >>= 1 ) { - bitsforDelta = add( bitsforDelta, 1 ); + bitsforDelta = add( bitsforDelta, 1 ); /*Q0*/ } } ELSE @@ -1984,8 +1989,8 @@ Word16 calc_nor_delta_hf_ivas_fx( bitsforDelta = 5; move16(); } - max_delta = sub( shl( 1, sub( bitsforDelta, 1 ) ), 1 ); - min_delta = negate( add( max_delta, 1 ) ); + max_delta = sub( shl( 1, sub( bitsforDelta, 1 ) ), 1 ); /*Q0*/ + min_delta = negate( add( max_delta, 1 ) ); /*Q0*/ /* updating norm & storing delta norm */ add_bits_denv = 2; @@ -1998,16 +2003,16 @@ Word16 calc_nor_delta_hf_ivas_fx( delta = sub( ynrm_t[i], ynrm[i] ); IF( GT_16( delta, max_delta ) ) { - delta = max_delta; + delta = max_delta; /*Q0*/ move16(); } ELSE IF( LT_16( delta, min_delta ) ) { - delta = min_delta; + delta = min_delta; /*Q0*/ move16(); } push_indice( hBstr, IND_DELTA_ENV_HQ, delta - min_delta, bitsforDelta ); - ynrm[i] = add( ynrm[i], delta ); + ynrm[i] = add( ynrm[i], delta ); /*Q0*/ move16(); add_bits_denv = add( add_bits_denv, bitsforDelta ); } @@ -2026,14 +2031,14 @@ Word16 calc_nor_delta_hf_ivas_fx( *--------------------------------------------------------------------------*/ Word16 calc_nor_delta_hf_fx( BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - const Word32 *t_audio, /* i : transform-domain coefficients */ - Word16 *ynrm, /* i/o: norm indices */ - Word16 *Rsubband, /* i/o: sub-band bit allocation */ - const Word16 num_env_bands, /* i : Number coded envelope bands */ - const Word16 nb_sfm, /* i : Number of envelope bands */ - const Word16 *sfmsize, /* i : band length */ - const Word16 *sfm_start, /* i : Start index of bands */ - const Word16 core_sfm /* i : index of the end band for core */ + const Word32 *t_audio, /* i : transform-domain coefficients Qx*/ + Word16 *ynrm, /* i/o: norm indices Q0*/ + Word16 *Rsubband, /* i/o: sub-band bit allocation Q0*/ + const Word16 num_env_bands, /* i : Number coded envelope bands Q0*/ + const Word16 nb_sfm, /* i : Number of envelope bands Q0*/ + const Word16 *sfmsize, /* i : band length Q0*/ + const Word16 *sfm_start, /* i : Start index of bands Q0*/ + const Word16 core_sfm /* i : index of the end band for core Q0*/ ) { Word16 i; @@ -2052,15 +2057,15 @@ Word16 calc_nor_delta_hf_fx( delta = sub( ynrm_t[i], ynrm[i] ); IF( delta > 0 ) { - delta = add( delta, 1 ); + delta = add( delta, 1 ); /*Q0*/ } ELSE { - delta = negate( delta ); + delta = negate( delta ); /*Q0*/ } if ( GT_16( delta, max_delta ) ) { - max_delta = delta; + max_delta = delta; /*Q0*/ move16(); } } @@ -2073,7 +2078,7 @@ Word16 calc_nor_delta_hf_fx( move16(); FOR( ; max_delta >= 2; max_delta >>= 1 ) { - bitsforDelta = add( bitsforDelta, 1 ); + bitsforDelta = add( bitsforDelta, 1 ); /*Q0*/ } } ELSE @@ -2081,8 +2086,8 @@ Word16 calc_nor_delta_hf_fx( bitsforDelta = 5; move16(); } - max_delta = sub( shl( 1, sub( bitsforDelta, 1 ) ), 1 ); - min_delta = negate( add( max_delta, 1 ) ); + max_delta = sub( shl( 1, sub( bitsforDelta, 1 ) ), 1 ); /*Q0*/ + min_delta = negate( add( max_delta, 1 ) ); /*Q0*/ /* updating norm & storing delta norm */ add_bits_denv = 2; @@ -2092,19 +2097,19 @@ Word16 calc_nor_delta_hf_fx( { IF( Rsubband[i] != 0 ) { - delta = sub( ynrm_t[i], ynrm[i] ); + delta = sub( ynrm_t[i], ynrm[i] ); /*Q0*/ IF( GT_16( delta, max_delta ) ) { - delta = max_delta; + delta = max_delta; /*Q0*/ move16(); } ELSE IF( LT_16( delta, min_delta ) ) { - delta = min_delta; + delta = min_delta; /*Q0*/ move16(); } push_indice_fx( hBstr, IND_DELTA_ENV_HQ, delta - min_delta, bitsforDelta ); - ynrm[i] = add( ynrm[i], delta ); + ynrm[i] = add( ynrm[i], delta ); /*Q0*/ move16(); add_bits_denv = add( add_bits_denv, bitsforDelta ); } @@ -2123,27 +2128,27 @@ Word16 calc_nor_delta_hf_fx( * HQ GENERIC *--------------------------------------------------------------------------*/ void hq_bwe_fx( - const Word16 HQ_mode, /* i : HQ mode */ - Word32 *coeff_out1, /* i/o: BWE input & temporary buffer */ - const Word16 *hq_generic_fenv, /* i : SWB frequency envelopes */ - Word32 *coeff_out, /* o : SWB signal in MDCT domain */ - const Word16 hq_generic_offset, /* i : frequency offset for representing hq generic*/ - Word16 *prev_L_swb_norm, /* i/o: last normalize length */ - const Word16 hq_generic_exc_clas, /* i : hq generic hf excitation class */ - const Word16 *sfm_end, /* i : End of bands */ - const Word16 num_sfm, /* i : Number of bands */ - const Word16 num_env_bands, /* i : Number of coded envelope bands */ - const Word16 *R /* i : Bit allocation */ + const Word16 HQ_mode, /* i : HQ mode Q0*/ + Word32 *coeff_out1, /* i/o: BWE input & temporary buffer Q12*/ + const Word16 *hq_generic_fenv, /* i : SWB frequency envelopes Q1*/ + Word32 *coeff_out, /* o : SWB signal in MDCT domain Q12*/ + const Word16 hq_generic_offset, /* i : frequency offset for representing hq generic Q0*/ + Word16 *prev_L_swb_norm, /* i/o: last normalize length Q0*/ + const Word16 hq_generic_exc_clas, /* i : hq generic hf excitation class Q0*/ + const Word16 *sfm_end, /* i : End of bands Q0*/ + const Word16 num_sfm, /* i : Number of bands Q0*/ + const Word16 num_env_bands, /* i : Number of coded envelope bands Q0*/ + const Word16 *R /* i : Bit allocation Q0*/ ) { Word16 n_swb_overlap_offset, n_swb_overlap; Word32 hq_swb_overlap_buf_fx[L_FRAME32k]; n_swb_overlap_offset = add( swb_bwe_subband[0], hq_generic_offset ); - n_swb_overlap = sub( sfm_end[sub( num_env_bands, 1 )], n_swb_overlap_offset ); + n_swb_overlap = sub( sfm_end[( num_env_bands - 1 )], n_swb_overlap_offset ); /*Q0*/ - Copy32( &coeff_out[n_swb_overlap_offset], hq_swb_overlap_buf_fx, sub( add( n_swb_overlap, sfm_end[sub( num_sfm, 1 )] ), sfm_end[sub( num_env_bands, 1 )] ) ); + Copy32( &coeff_out[n_swb_overlap_offset], hq_swb_overlap_buf_fx, sub( add( n_swb_overlap, sfm_end[( num_sfm - 1 )] ), sfm_end[( num_env_bands - 1 )] ) ); /*Q12*/ hq_generic_decoding_fx( HQ_mode, coeff_out1, hq_generic_fenv, coeff_out, hq_generic_offset, prev_L_swb_norm, hq_generic_exc_clas, R ); @@ -2159,23 +2164,23 @@ void hq_bwe_fx( *--------------------------------------------------------------------------*/ void hq_wb_nf_bwe_fx( - const Word16 *coeff_fx, /* i : coded/noisefilled normalized spectrum */ - const Word16 is_transient, - const Word16 prev_bfi, /* i : previous bad frame indicator */ - const Word32 *L_normq_v, - const Word16 num_sfm, /* i : Number of subbands */ - const Word16 *sfm_start, /* i : Subband start coefficient */ - const Word16 *sfm_end, /* i : Subband end coefficient */ - const Word16 *sfmsize, /* i : Subband band width */ - const Word16 last_sfm, /* i : last coded subband */ - const Word16 *R, /* i : bit allocation */ - const Word16 prev_is_transient, /* i : previous transient flag */ - Word32 *prev_normq_fx, /* i/o: previous norms */ - Word32 *prev_env_fx, /* i/o: previous noise envelopes */ - Word16 *bwe_seed, /* i/o: random seed for generating BWE input */ - Word32 *prev_coeff_out_fx, /* i/o: decoded spectrum in previous frame */ - Word16 *prev_R, /* i/o: bit allocation info. in previous frame */ - Word32 *L_coeff_out, /* o : coded/noisefilled spectrum */ + const Word16 *coeff_fx, /* i : coded/noisefilled normalized spectrum Q12*/ + const Word16 is_transient, /*Q0*/ + const Word16 prev_bfi, /* i : previous bad frame indicator Q0*/ + const Word32 *L_normq_v, /*Q14*/ + const Word16 num_sfm, /* i : Number of subbands Q0*/ + const Word16 *sfm_start, /* i : Subband start coefficient Q0*/ + const Word16 *sfm_end, /* i : Subband end coefficient Q0*/ + const Word16 *sfmsize, /* i : Subband band width Q0*/ + const Word16 last_sfm, /* i : last coded subband Q0*/ + const Word16 *R, /* i : bit allocation Q0*/ + const Word16 prev_is_transient, /* i : previous transient flag Q0*/ + Word32 *prev_normq_fx, /* i/o: previous norms Q14*/ + Word32 *prev_env_fx, /* i/o: previous noise envelopes prev_env_Q*/ + Word16 *bwe_seed, /* i/o: random seed for generating BWE input Q0*/ + Word32 *prev_coeff_out_fx, /* i/o: decoded spectrum in previous frame Q12*/ + Word16 *prev_R, /* i/o: bit allocation info. in previous frame Q0*/ + Word32 *L_coeff_out, /* o : coded/noisefilled spectrum Q12*/ Word16 *prev_env_Q ) { Word16 i; @@ -2184,7 +2189,10 @@ void hq_wb_nf_bwe_fx( Word16 num; Word32 env_fx, peak_fx, fabs_coeff_out_fx, min_coef_fx; Word32 L_tmp1, L_tmp2 = 0, L_tmp3, L_tmp4; + move32(); Word16 tmp1, exp = 0, exp1, exp2, exp3, harm_para_fx, sharp_fx, step_fx, alfa_fx = 4096; + move16(); + move16(); Word32 avrg_norm_fx, prev_avrg_norm_fx; Word16 bitalloc_var_fx; Word16 tmp; @@ -2195,7 +2203,7 @@ void hq_wb_nf_bwe_fx( { IF( EQ_16( prev_bfi, 1 ) ) { - Copy32( L_normq_v, prev_normq_fx, SFM_N_WB ); + Copy32( L_normq_v, prev_normq_fx, SFM_N_WB ); /*Q14*/ } /* the variance of bit allocation */ @@ -2206,9 +2214,9 @@ void hq_wb_nf_bwe_fx( FOR( sfm = 8; sfm <= last_sfm; sfm++ ) { - tmp = abs_s( sub( R[sfm], R[sub( sfm, 1 )] ) ); + tmp = abs_s( sub( R[sfm], R[( sfm - 1 )] ) ); /*Q0*/ bitalloc_var_fx = add( bitalloc_var_fx, tmp ); - total_bit = add( total_bit, R[sfm] ); + total_bit = add( total_bit, R[sfm] ); /*Q0*/ } test(); IF( GT_16( last_sfm, 8 ) && total_bit > 0 ) @@ -2249,7 +2257,7 @@ void hq_wb_nf_bwe_fx( move16(); FOR( i = sfm_start[sfm]; i < sfm_end[sfm]; i++ ) { - fabs_coeff_out_fx = L_abs( L_coeff_out[i] ); + fabs_coeff_out_fx = L_abs( L_coeff_out[i] ); /*Q12*/ #ifdef BASOP_NOGLOB mean_fx = L_add_sat( mean_fx, fabs_coeff_out_fx ); /*Q12 */ #else @@ -2294,11 +2302,11 @@ void hq_wb_nf_bwe_fx( } ELSE { - sharp_fx = 16384; - move16(); /*Q14 = 1 */ + sharp_fx = 16384; /*Q14 = 1 */ + move16(); } - harm_para_fx = sharp_fx; - move16(); /*Q14 */ + harm_para_fx = sharp_fx; /*Q14 */ + move16(); IF( last_sfm == 0 ) { @@ -2317,8 +2325,8 @@ void hq_wb_nf_bwe_fx( #else step_fx = round_fx( L_shl( L_tmp, 16 ) ); /*Q15 */ #endif - alfa_fx = 20480; - move16(); /*Q13 = 2.5 */ + alfa_fx = 20480; /*Q13 = 2.5 */ + move16(); /* fill noise for the insaturable subbands */ FOR( sfm = 0; sfm < num_sfm; sfm++ ) { @@ -2336,21 +2344,21 @@ void hq_wb_nf_bwe_fx( L_tmp1 = Mult_32_32( L_tmp4, L_tmp4 ); /*2*exp1-3 14+exp1+14+exp1 -31 */ L_tmp2 = L_deposit_l( 0 ); peak_fx = L_deposit_l( 0 ); - min_coef_fx = 0x7fffffff; + min_coef_fx = 0x7fffffff; /*Q31*/ move32(); FOR( i = sfm_start[sfm]; i < sfm_end[sfm]; i++ ) { - fabs_coeff_out_fx = L_abs( L_coeff_out[i] ); + fabs_coeff_out_fx = L_abs( L_coeff_out[i] ); /*Q12*/ test(); if ( LT_32( fabs_coeff_out_fx, min_coef_fx ) && L_coeff_out[i] != 0 ) { - min_coef_fx = fabs_coeff_out_fx; + min_coef_fx = fabs_coeff_out_fx; /*Q12*/ move32(); } if ( GT_32( fabs_coeff_out_fx, peak_fx ) ) { - peak_fx = fabs_coeff_out_fx; + peak_fx = fabs_coeff_out_fx; /*Q12*/ move32(); } } @@ -2400,10 +2408,10 @@ void hq_wb_nf_bwe_fx( } ELSE { - avrg_norm_fx = L_add( L_shr( L_normq_v[sub( sfm, 1 )], 1 ), L_shr( L_normq_v[sfm], 1 ) ); /*13 */ - avrg_norm_fx = L_add( avrg_norm_fx, L_shr( L_normq_v[sfm + 1], 1 ) ); /*13 */ - prev_avrg_norm_fx = L_add( L_shr( prev_normq_fx[sub( sfm, 1 )], 1 ), L_shr( prev_normq_fx[sfm], 1 ) ); /*13 */ - prev_avrg_norm_fx = L_add( prev_avrg_norm_fx, L_shr( prev_normq_fx[add( sfm, 1 )], 1 ) ); /*13 */ + avrg_norm_fx = L_add( L_shr( L_normq_v[( sfm - 1 )], 1 ), L_shr( L_normq_v[sfm], 1 ) ); /*13 */ + avrg_norm_fx = L_add( avrg_norm_fx, L_shr( L_normq_v[sfm + 1], 1 ) ); /*13 */ + prev_avrg_norm_fx = L_add( L_shr( prev_normq_fx[( sfm - 1 )], 1 ), L_shr( prev_normq_fx[sfm], 1 ) ); /*13 */ + prev_avrg_norm_fx = L_add( prev_avrg_norm_fx, L_shr( prev_normq_fx[( sfm + 1 )], 1 ) ); /*13 */ } test(); @@ -2413,13 +2421,13 @@ void hq_wb_nf_bwe_fx( Word16 exp_p; exp_p = norm_l( peak_fx ); exp = sub( 31, exp ); - env_fx = Isqrt_lc( env_fx, &exp ); + env_fx = Isqrt_lc( env_fx, &exp ); /*Q31 - exp*/ L_tmp1 = Mult_32_32( env_fx, L_shl( peak_fx, exp_p ) ); /*12+exp2-exp 31-exp+12+exp1-31 */ L_tmp2 = Mult_32_16( avrg_norm_fx, harm_para_fx ); /*12 13 + 14 + 1 -16 */ exp1 = norm_l( L_tmp1 ); L_tmp1 = L_shl( L_tmp1, exp1 ); /* 12+exp2-exp+exp1 */ exp = add( sub( 12, exp ), add( exp1, exp_p ) ); - L_tmp2 = Div_32( L_tmp2, extract_h( L_tmp1 ), extract_l( L_tmp1 ) ); + L_tmp2 = Div_32( L_tmp2, extract_h( L_tmp1 ), extract_l( L_tmp1 ) ); /*Q31 - (43-exp)*/ exp = sub( 43, exp ); } ELSE @@ -2428,11 +2436,11 @@ void hq_wb_nf_bwe_fx( IF( LT_32( L_tmp1, peak_fx ) ) { exp = sub( 31, exp ); - env_fx = Isqrt_lc( env_fx, &exp ); + env_fx = Isqrt_lc( env_fx, &exp ); /*Q31 - exp*/ exp1 = norm_l( env_fx ); env_fx = L_shl( env_fx, exp1 ); /* 31-exp+exp1 */ exp = add( sub( 31, exp ), exp1 ); - L_tmp1 = (Word32) sharp_fx; + L_tmp1 = L_deposit_l( sharp_fx ); /*Q14*/ L_tmp2 = Div_32( L_tmp1, extract_h( env_fx ), extract_l( env_fx ) ); /* 45-exp 14 - exp + 31 //39-exp 8 - exp + 31 */ exp = sub( 45, exp ); exp1 = norm_l( peak_fx ); @@ -2444,17 +2452,17 @@ void hq_wb_nf_bwe_fx( ELSE { exp = sub( 31, exp ); - env_fx = Isqrt_lc( env_fx, &exp ); + env_fx = Isqrt_lc( env_fx, &exp ); /*Q31 - exp*/ exp1 = norm_l( env_fx ); env_fx = L_shl( env_fx, exp1 ); /* 31-exp+exp1 */ exp = add( sub( 31, exp ), exp1 ); - L_tmp1 = (Word32) ( sharp_fx ); + L_tmp1 = L_deposit_l( sharp_fx ); /*Q14*/ L_tmp2 = Div_32( L_tmp1, extract_h( env_fx ), extract_l( env_fx ) ); /* 45-exp 14 - exp + 31 //39-exp 8 - exp + 31 */ exp = sub( 45, exp ); } #ifdef BASOP_NOGLOB - sharp_fx = add_sat( sharp_fx, shr( step_fx, 1 ) ); + sharp_fx = add_sat( sharp_fx, shr( step_fx, 1 ) ); /*Q14*/ #else sharp_fx = add( sharp_fx, shr( step_fx, 1 ) ); #endif @@ -2504,10 +2512,10 @@ void hq_wb_nf_bwe_fx( { IF( coeff_fx[i] == 0 ) { - tmp1 = Random( bwe_seed ); /*Q15 */ - L_tmp1 = Mult_32_16( L_tmp2, tmp1 ); /*exp exp+15+1 -16 */ - L_tmp1 = L_shl( L_tmp1, sub( 12, exp ) ); - L_coeff_out[i] = L_tmp1; + tmp1 = Random( bwe_seed ); /*Q15 */ + L_tmp1 = Mult_32_16( L_tmp2, tmp1 ); /*exp exp+15+1 -16 */ + L_tmp1 = L_shl( L_tmp1, sub( 12, exp ) ); /*Q12*/ + L_coeff_out[i] = L_tmp1; /*Q12*/ move32(); } } @@ -2528,12 +2536,12 @@ void hq_wb_nf_bwe_fx( { tmp1 = Random( bwe_seed ); /*Q15 */ L_tmp1 = Mult_32_16( L_normq_v[sfm], tmp1 ); /*14 14+15+1 -16 */ - L_tmp1 = L_shr( L_tmp1, 2 ); /* */ - L_coeff_out[i] = L_tmp1; + L_tmp1 = L_shr( L_tmp1, 2 ); /*Q12 */ + L_coeff_out[i] = L_tmp1; /*Q12*/ move32(); } } - L_tmp2 = L_normq_v[sfm]; + L_tmp2 = L_normq_v[sfm]; /*Q14*/ move32(); exp = 14; move16(); @@ -2549,7 +2557,7 @@ void hq_wb_nf_bwe_fx( IF( EQ_16( sfm, sub( SFM_N_WB, 1 ) ) && prev_is_transient == 0 && GT_32( prev_normq_fx[sfm], L_shr( L_normq_v[sfm], 1 ) ) && LT_32( prev_normq_fx[sfm], L_shl( L_normq_v[sfm], 1 ) ) && LE_16( bitalloc_var_fx, 4915 ) ) #endif { - Word32 *p_prev_coeff_out = prev_coeff_out_fx; + Word32 *p_prev_coeff_out = prev_coeff_out_fx; /*Q12*/ FOR( i = add( sfm_start[sfm], 12 ); i < sfm_end[sfm]; i++ ) { test(); @@ -2563,18 +2571,18 @@ void hq_wb_nf_bwe_fx( #endif { #ifdef BASOP_NOGLOB - L_tmp = L_add_sat( L_shr( L_abs( L_coeff_out[i] ), 1 ), L_shr( L_abs( *p_prev_coeff_out ), 1 ) ); + L_tmp = L_add_sat( L_shr( L_abs( L_coeff_out[i] ), 1 ), L_shr( L_abs( *p_prev_coeff_out ), 1 ) ); /*Q12*/ #else L_tmp = L_add( L_shr( L_abs( L_coeff_out[i] ), 1 ), L_shr( L_abs( *p_prev_coeff_out ), 1 ) ); #endif if ( L_coeff_out[i] <= 0 ) { - L_tmp = L_negate( L_tmp ); + L_tmp = L_negate( L_tmp ); /*Q12*/ } - L_coeff_out[i] = L_tmp; + L_coeff_out[i] = L_tmp; /*Q12*/ move32(); } - p_prev_coeff_out++; + p_prev_coeff_out++; /*Q12*/ } } prev_env_Q[sfm] = exp; @@ -2594,8 +2602,8 @@ void hq_wb_nf_bwe_fx( { tmp1 = Random( bwe_seed ); /*Q15 */ L_tmp1 = Mult_32_16( L_normq_v[sfm], tmp1 ); /*14 14+15+1 -16 */ - L_tmp1 = L_shr( L_tmp1, 2 ); /* */ - L_coeff_out[i] = L_tmp1; + L_tmp1 = L_shr( L_tmp1, 2 ); /*Q12*/ + L_coeff_out[i] = L_tmp1; /*Q12*/ move32(); } } @@ -2604,9 +2612,9 @@ void hq_wb_nf_bwe_fx( set32_fx( prev_env_fx, 0, SFM_N_WB ); } - Copy32( L_normq_v, prev_normq_fx, SFM_N_WB ); - Copy32( L_coeff_out + L_FRAME16k - L_HQ_WB_BWE, prev_coeff_out_fx, L_HQ_WB_BWE ); - *prev_R = R[SFM_N_WB - 1]; + Copy32( L_normq_v, prev_normq_fx, SFM_N_WB ); /*Q14*/ + Copy32( L_coeff_out + L_FRAME16k - L_HQ_WB_BWE, prev_coeff_out_fx, L_HQ_WB_BWE ); /*Q12*/ + *prev_R = R[SFM_N_WB - 1]; /*Q0*/ move16(); return; @@ -2636,7 +2644,7 @@ void enforce_zero_for_min_envelope_fx( { FOR( j = sfm_start[0]; j < sfm_end[0]; j++ ) { - L_coefsq[j] = L_deposit_l( 0 ); + L_coefsq[j] = L_deposit_l( 0 ); /*Q12*/ move32(); } } @@ -2647,7 +2655,7 @@ void enforce_zero_for_min_envelope_fx( { FOR( j = sfm_start[i]; j < sfm_end[i]; j++ ) { - L_coefsq[j] = L_deposit_l( 0 ); + L_coefsq[j] = L_deposit_l( 0 ); /*Q12*/ move32(); } } @@ -2680,15 +2688,15 @@ void apply_envelope_enc_ivas_fx( FOR( sfm = 0; sfm < num_sfm; sfm++ ) { - normq = dicn_fx[norm[sfm]]; + normq = dicn_fx[norm[sfm]]; /*Q14*/ move16(); FOR( i = sfm_start[sfm]; i < sfm_end[sfm]; i++ ) { /*coeff_out[i] = coeff[i]*normq; */ Mpy_32_16_ss( normq, coeff[i], &L_tmp, &lsb ); - coeff_out[i] = L_add( L_shl( L_tmp, 1 ), L_shr( lsb, 15 ) ); - move32(); /* Q12 (14+12+1-16)+1 */ + coeff_out[i] = L_add( L_shl( L_tmp, 1 ), L_shr( lsb, 15 ) ); /*Q12*/ + move32(); } } @@ -2731,14 +2739,14 @@ void apply_envelope_fx( test(); if ( EQ_16( HQ_mode, HQ_GEN_SWB ) || EQ_16( HQ_mode, HQ_GEN_FB ) ) { - len = add( last_sfm, 1 ); + len = add( last_sfm, 1 ); /*Q0*/ } IF( EQ_16( length, L_FRAME16k ) ) { FOR( sfm = 0; sfm < num_sfm; sfm++ ) { - normq_v[sfm] = dicn_fx[norm[sfm]]; + normq_v[sfm] = dicn_fx[norm[sfm]]; /*Q14*/ move16(); move32(); /*normq = normq_v[sfm] * norm_adj[sfm]; */ @@ -2748,8 +2756,8 @@ void apply_envelope_fx( { /*coeff_out[i] = coeff[i]*normq; */ Mpy_32_16_ss( normq, coeff[i], &L_tmp, &lsb ); - coeff_out[i] = L_add( L_shl( L_tmp, 1 ), L_shr( lsb, 15 ) ); - move32(); /* Q12 (14+12+1-16)+1 */ + coeff_out[i] = L_add( L_shl( L_tmp, 1 ), L_shr( lsb, 15 ) ); /* Q12 (14+12+1-16)+1 */ + move32(); } } } @@ -2757,21 +2765,21 @@ void apply_envelope_fx( { FOR( sfm = 0; sfm < len; sfm++ ) { - normq_v[sfm] = dicn_fx[norm[sfm]]; + normq_v[sfm] = dicn_fx[norm[sfm]]; /*Q14*/ move16(); move32(); /*normq_v[sfm] *= norm_adj[sfm]; */ - Mpy_32_16_ss( normq_v[sfm], norm_adj[sfm], &normq_v[sfm], &lsb ); - move32(); /* Q14 (14+15+1-16) */ + Mpy_32_16_ss( normq_v[sfm], norm_adj[sfm], &normq_v[sfm], &lsb ); /* Q14 (14+15+1-16) */ + move32(); - normq = normq_v[sfm]; + normq = normq_v[sfm]; /*Q14*/ move32(); FOR( i = sfm_start[sfm]; i < sfm_end[sfm]; i++ ) { /*coeff_out[i] = coeff[i]*normq; */ Mpy_32_16_ss( normq, coeff[i], &L_tmp, &lsb ); - coeff_out[i] = L_add( L_shl( L_tmp, 1 ), L_shr( lsb, 15 ) ); - move32(); /* Q12 (14+12+1-16)+1 */ + coeff_out[i] = L_add( L_shl( L_tmp, 1 ), L_shr( lsb, 15 ) ); /* Q12 (14+12+1-16)+1 */ + move32(); } } @@ -2786,8 +2794,8 @@ void apply_envelope_fx( { /*coeff_out1[i] = coeff_out1[i]*normq; */ Mpy_32_16_ss( normq, coeff1[i], &L_tmp, &lsb ); - coeff_out1[i] = L_add( L_shl( L_tmp, 1 ), L_shr( lsb, 15 ) ); - move32(); /* Q12 (14+12+1-16)+1 */ + coeff_out1[i] = L_add( L_shl( L_tmp, 1 ), L_shr( lsb, 15 ) ); /* Q12 (14+12+1-16)+1 */ + move32(); } } } diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index a22e45e87..4296a51fd 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -280,6 +280,7 @@ ivas_error pre_proc_ivas( const int32_t last_element_brate, /* i : last element bitrate */ const int16_t input_frame, /* i : frame length */ float old_inp_12k8[], /* i/o: buffer of old input signal */ + Word16 old_inp_12k8_fx[], /* i/o: buffer of old input signal */ float old_inp_16k[], /* i/o: buffer of old input signal @ 16kHz */ float **inp, /* o : ptr. to inp. signal in the current frame*/ float *ener, /* o : residual energy from Levinson-Durbin */ @@ -290,7 +291,7 @@ ivas_error pre_proc_ivas( float lsp_mid[M], /* i/o: LSPs in the middle of the frame */ float *new_inp_resamp16k, /* o : new input signal @16kHz, non pre-emphasised, used by the WB TBE/BWE */ int16_t *Voicing_flag, /* o : voicing flag for HQ FEC */ - const float old_wsp[], /* i : weighted input signal buffer */ + float old_wsp[], /* i : weighted input signal buffer */ const int16_t loc_harm, /* i : harmonicity flag */ #ifndef IVAS_FLOAT_FIXED const float cor_map_sum, /* i : speech/music clasif. parameter */ @@ -313,32 +314,6 @@ ivas_error pre_proc_ivas( #endif ); -ivas_error ivas_compute_core_buffers( - Encoder_State *st, /* i/o: encoder state structure */ - float **inp16k_out, /* o : ptr. to inp. signal in the current frame */ - float *old_inp_16k, /* i/o: buffer of old input signal @ 16kHz */ - float new_inp_resamp16k_out[], /* o : new input signal @16kHz, non pre-emphasised, used by the WB TBE/BWE */ - const int16_t input_frame, /* i : frame length */ - const int16_t last_element_mode, /* i : last element mode */ - const int32_t sr_core, /* i : core-coder sampling rate */ - float *ener, /* o : residual energy from Levinson-Durbin */ -#ifndef IVAS_FLOAT_FIXED - float A[NB_SUBFR16k * (M + 1)], /* i/o: A(z) unquantized for the 4 subframes */ - float Aw[NB_SUBFR16k * (M + 1)], /* i/o: weighted A(z) unquantized for subframes */ -#else - Word16 A_fx[NB_SUBFR16k * (M + 1)], /* i/o: A(z) unquantized for the 4 subframes */ - Word16 Aw_Fx[NB_SUBFR16k * (M + 1)], /* i/o: weighted A(z) unquantized for subframes */ -#endif - float epsP[M + 1], /* i/o: LP prediction errors */ -#ifndef IVAS_FLOAT_FIXED - float lsp_new[M], /* i/o: LSPs at the end of the frame */ - float lsp_mid[M] /* i/o: LSPs in the middle of the frame */ -#else - Word16 lsp_new_fx[M], /* i/o: LSPs at the end of the frame */ - Word16 lsp_mid_fx[M] /* i/o: LSPs in the middle of the frame */ -#endif -); - /*! r: number of clipped samples */ uint32_t ivas_syn_output( float *synth[], /* i/o: float synthesis signal */ diff --git a/lib_com/ivas_prot_fx.h b/lib_com/ivas_prot_fx.h index 2cf76473c..e0c66f460 100644 --- a/lib_com/ivas_prot_fx.h +++ b/lib_com/ivas_prot_fx.h @@ -5820,6 +5820,23 @@ ivas_error ivas_mct_enc_fx( const Word16 nb_bits_metadata /* i : number of metadata bits */ ); +ivas_error ivas_compute_core_buffers_fx( + Encoder_State *st, /* i/o: encoder state structure */ + Word16 **inp16k_out_fx, /* o : ptr. to inp. signal in the current frame */ + Word16 *old_inp_16k_fx, /* i/o: buffer of old input signal @ 16kHz */ + Word16 new_inp_resamp16k_out_fx[], /* o : new input signal @16kHz, non pre-emphasised, used by the WB TBE/BWE */ + const Word16 input_frame, /* i : frame length */ + const Word16 last_element_mode, /* i : last element mode */ + const Word32 sr_core, /* i : core-coder sampling rate */ + Word32 *ener, /* o : residual energy from Levinson-Durbin */ + Word16 A_fx[NB_SUBFR16k * ( M + 1 )], /* i/o: A(z) unquantized for the 4 subframes */ + Word16 Aw_fx[NB_SUBFR16k * ( M + 1 )], /* i/o: weighted A(z) unquantized for subframes */ + Word32 epsP[M + 1], /* i/o: LP prediction errors */ + Word16 lsp_new_fx[M], /* i/o: LSPs at the end of the frame */ + Word16 lsp_mid_fx[M], /* i/o: LSPs in the middle of the frame */ + Word16 Q_old_inp_16k, + Word16 Q_r[2] ); + ivas_error ivas_enc_fx( Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ const Word16 *data, /* i : input signal Q0 */ diff --git a/lib_com/modif_fs.c b/lib_com/modif_fs.c index 5bc57cc4b..f0b9b45e8 100644 --- a/lib_com/modif_fs.c +++ b/lib_com/modif_fs.c @@ -534,11 +534,11 @@ void Interpolate_allpass_steep( void Interpolate_allpass_steep_32( const Word32 *in_fx, /* i : input array of size N Qx */ Word32 *mem_fx, /* i/o: memory Qx */ - const int16_t N, /* i : number of input samples */ + const Word16 N, /* i : number of input samples */ Word32 *out_fx /* o : output array of size 2*N Qx */ ) { - int16_t n, k; + Word16 n, k; Word32 temp_fx[ALLPASSSECTIONS_STEEP - 1]; #ifdef IVAS_ENH32_CADENCE_CHANGES @@ -890,12 +890,12 @@ void interpolate_3_over_2_allpass( #ifdef IVAS_FLOAT_FIXED void interpolate_3_over_2_allpass_32( const Word32 *input, /* i : input signal Qx*/ - const int16_t len, /* i : number of input samples */ + const Word16 len, /* i : number of input samples */ Word32 *out, /* o : output signal Qx*/ Word32 *mem /* i/o: memory Qx*/ ) { - int16_t i, loop_len; + Word16 i, loop_len; Word32 Vu[2], Vm[2], Vl[2]; /* Outputs of three cascaded allpass stages (upper, middle, and lower) */ Word32 out1_buff[L_FRAME32k * 3]; Word32 *out1; diff --git a/lib_com/prot.h b/lib_com/prot.h index 6c5655f99..d0f46467a 100644 --- a/lib_com/prot.h +++ b/lib_com/prot.h @@ -2027,6 +2027,7 @@ void ar_encoder_done( void ar_decoder_done( PARCODEC arInst ); +#ifndef IVAS_FLOAT_FIXED float GetISCScale( float *quants, int16_t size, @@ -2042,6 +2043,7 @@ float GetISCScale( float *abuffer, float *mbuffer, float *sbuffer ); +#endif Word32 Mult_32_16( Word32 a, @@ -2051,13 +2053,16 @@ Word32 Mult_32_32( Word32 a, Word32 b ); +#ifndef IVAS_FLOAT_FIXED void decode_position_ari_fx_ivas( PARCODEC pardec, Word16 size, Word16 npulses, Word16 *nz, Word32 *position ); +#endif +#ifndef IVAS_FLOAT_FIXED void decode_magnitude_usq_fx_ivas( ARCODEC *pardec, Word16 size, @@ -2065,6 +2070,7 @@ void decode_magnitude_usq_fx_ivas( Word16 nzpos, Word32 *positions, Word32 *out ); +#endif void decode_mangitude_tcq_fx_ivas( ARCODEC *pardec, @@ -2086,11 +2092,13 @@ void srt_vec_ind_fx_ivas( Word16 *I, Word16 length ); +#ifndef IVAS_FLOAT_FIXED Word16 GetScale_fx_ivas( Word16 blen, Word32 bits_fx /*Q16*/, Word32 *surplus_fx /*Q16*/ ); +#endif void bit_allocation_second_fx2( Word32 *Rk, @@ -2104,11 +2112,13 @@ void bit_allocation_second_fx2( const Word16 *last_bitalloc, const Word16 input_frame ); +#ifndef IVAS_FLOAT_FIXED Word32 encode_position_ari_fx_ivas( PARCODEC parenc, float *quants, Word16 size, Word32 *est_bits_frame_fx ); +#endif Word32 encode_magnitude_tcq_fx_ivas( ARCODEC *parenc, @@ -2171,8 +2181,10 @@ void tcq_core_LR_dec( const int16_t adjustFlag, const int16_t *is_transient ); +#ifndef IVAS_FLOAT_FIXED void InitLSBTCQ( int16_t *bcount ); +#endif void TCQLSB( int16_t bcount, @@ -3719,12 +3731,8 @@ void find_wsp( ); void pitch_ol_init( -#ifndef IVAS_FLOAT_FIXED - float *old_thres, /* o : threshold for reinforcement of past pitch influence */ -#else - Word16 *old_thres, /* o : threshold for reinforcement of past pitch influence */ -#endif - int16_t *old_pitch, /* o : pitch of the 2nd half-frame of previous frame */ + float *old_thres, /* o : threshold for reinforcement of past pitch influence */ + int16_t *old_pitch, /* o : pitch of the 1st half-frame of previous frame */ int16_t *delta_pit, /* o : pitch evolution extrapolation */ float *old_corr /* o : correlation */ ); @@ -8741,10 +8749,11 @@ ivas_error createFdCngCom_flt( void deleteFdCngCom_flt( HANDLE_FD_CNG_COM *hFdCngCom /* i/o: FD_CNG structure containing all buffers and variables */ ); - +#ifndef IVAS_FLOAT_FIXED void initFdCngCom_flt( HANDLE_FD_CNG_COM hFdCngCom, /* i/o: FD_CNG structure containing all buffers and variables */ const float scale ); +#endif void initPartitions_flt( diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index c95597fd7..be0a12fa6 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -8336,15 +8336,15 @@ void hr_bwe_dec_init( // swb_bwe_com_hr_fx.c void swb_hr_noise_fill_fx( - const Word16 is_transient, /* i : transient flag */ - const Word16 spect_start, /* i : spectrum start point */ - const Word16 spect_end, /* i : spectrum end point */ - const Word16 tilt_wb, /* i : tilt of wideband signal */ - const Word16 pitch, /* i : pitch value */ - const Word16 nq[], /* i : AVQ nq index */ - Word16 Nsv, /* i : number of subband */ - Word16 *bwe_highrate_seed, /* i/o: seed of random noise */ - Word16 *t_audio, /* i/o: mdct spectrum */ + const Word16 is_transient, /* i : transient flag */ + const Word16 spect_start, /* i : spectrum start point */ + const Word16 spect_end, /* i : spectrum end point */ + const Word16 tilt_wb, /* i : tilt of wideband signal Q11 */ + const Word16 pitch, /* i : pitch value Q15 */ + const Word16 nq[], /* i : AVQ nq index */ + Word16 Nsv, /* i : number of subband */ + Word16 *bwe_highrate_seed, /* i/o: seed of random noise */ + Word16 *t_audio, /* i/o: mdct spectrum Q_audio */ Word16 Q_audio ); #ifdef IVAS_FLOAT_FIXED diff --git a/lib_com/stat_com.h b/lib_com/stat_com.h index b6e68bd59..1bbd51a5f 100644 --- a/lib_com/stat_com.h +++ b/lib_com/stat_com.h @@ -402,6 +402,37 @@ typedef struct { FD_CNG_SETUP FdCngSetup; +#ifndef IVAS_FLOAT_FIXED + float timeDomainBuffer_flt[L_FRAME16k]; + float fftBuffer_flt[FFTLEN]; + float olapBufferAna_flt[FFTLEN]; + float olapBufferSynth_flt[FFTLEN]; + float olapBufferSynth2_flt[FFTLEN]; + const float *olapWinAna_flt; + const float *olapWinSyn_flt; + const float *fftSineTab_flt; + float msM_win_flt; + float msM_subwin_flt; + float init_old_flt; + float msAlphaCor_flt[2]; /* Correction factor (smoothed) */ + float msSlope_flt[2]; + float msQeqInvAv_flt[2]; + float msPsdSum_flt[2]; + float msPeriodogSum_flt[2]; + float periodog_flt[PERIODOGLEN]; /* Periodogram */ + float cngNoiseLevel_flt[FFTCLDFBLEN]; /* Noise level applied for the CNG in each (sub)band */ + float psize_flt[NPART]; /* Partition sizes */ + float psize_inv_flt[NPART]; /* Inverse of partition sizes */ + float FFTscalingFactor_flt; /* Squared ratio between core signal analysis FFT and noise estimator FFT */ + float scalingFactor_flt; + float CLDFBpsize_inv_flt[NPARTCLDFB]; /* Inverse of CLDFB partition sizes */ + float sidNoiseEst_flt[NPART]; /* Transmitted noise level */ + float[NPART]; + float A_cng_flt[M + 1]; + float exc_cng_flt[L_FRAME16k]; + float likelihood_noisy_speech_flt; + float coherence_flt; /* inter-channel coherence of noise */ +#endif Word16 numSlots; /* Number of time slots in CLDFB matrix */ Word16 regularStopBand; /* Number of CLDFB bands to be considered */ @@ -414,29 +445,14 @@ typedef struct Word16 fftlenShift; // Q0 Word16 fftlenFac; // Q0 - float timeDomainBuffer_flt[L_FRAME16k]; Word16 timeDomainBuffer[L_FRAME16k]; /*Q15*/ + Word32 olapBufferSynth_fx[FFTLEN]; /*Q_olapBufferSynth*/ + Word32 olapBufferSynth2_fx[FFTLEN]; /*Q_olapBufferSynth2*/ - float fftBuffer_flt[FFTLEN]; - float olapBufferAna_flt[FFTLEN]; - float olapBufferSynth_flt[FFTLEN]; -#ifdef IVAS_FLOAT_FIXED - Word32 olapBufferSynth_fx[FFTLEN]; /*Q_olapBufferSynth*/ -#endif - float olapBufferSynth2_flt[FFTLEN]; -#ifdef IVAS_FLOAT_FIXED - Word32 olapBufferSynth2_fx[FFTLEN]; /*Q_olapBufferSynth2*/ -#endif -#ifndef IVAS_FLOAT_FIXED - const float *olapWinAna_flt; - const float *olapWinSyn_flt; - const float *fftSineTab_flt; -#else - const Word32 *olapWinAna_fx; /* Q30 */ - const Word16 *olapWinSyn_fx; /* Q15 */ - const Word16 *fftSineTab_fx; /* Q15 */ -#endif - Word32 fftBuffer[FFTLEN]; // Q31-fftBuffer_exp + const Word32 *olapWinAna_fx; /* Q30 */ + const Word16 *olapWinSyn_fx; /* Q15 */ + const Word16 *fftSineTab_fx; /* Q15 */ + Word32 fftBuffer[FFTLEN]; // Q31-fftBuffer_exp Word16 fftBuffer_exp; Word16 *olapBufferAna; /* q_olapBufferAna */ /* points to FD_CNG_DEC->olapBufferAna[FFTLEN] in case of decoder */ Word16 olapBufferAna_fx[FFTLEN]; /* q_olapBufferAna_fx */ /* points to FD_CNG_DEC->olapBufferAna[FFTLEN] in case of decoder */ @@ -445,109 +461,69 @@ typedef struct const PWord16 *olapWinAna; const PWord16 *olapWinSyn; - - float msM_win_flt; - float msM_subwin_flt; Word16 msM_win; // Q8 Word16 msM_subwin; // Q11 Word16 msFrCnt_init_counter; /* Frame counter at initialization */ Word16 msFrCnt_init_thresh; - float init_old_flt; Word16 init_old; // Q15 - Word16 msFrCnt; /* Frame counter */ -#ifndef IVAS_FLOAT_FIXED - float msAlphaCor_flt[2]; /* Correction factor (smoothed) */ - float msSlope_flt[2]; - float msQeqInvAv_flt[2]; -#else - Word32 msAlphaCor[2]; /* Correction factor (smoothed) Q31 */ - Word16 msSlope[2]; /* Q14 */ - Word32 msQeqInvAv[2]; /* Q31- msQeqInvAv_exp*/ + Word16 msFrCnt; /* Frame counter */ + Word32 msAlphaCor[2]; /* Correction factor (smoothed) Q31 */ + Word16 msSlope[2]; /* Q14 */ + Word32 msQeqInvAv[2]; /* Q31- msQeqInvAv_exp*/ Word16 msQeqInvAv_exp[2]; -#endif Word16 msMinBufferPtr; - float msPsdSum_flt[2]; - float msPeriodogSum_flt[2]; Word32 msPsdSum[2]; /* 16Q15 */ Word32 msPeriodogSum[2]; /* Q31- msPeriodogSum_exp*/ Word16 msPeriodogSum_exp[2]; // Q0 Word16 offsetflag; - - float periodog_flt[PERIODOGLEN]; /* Periodogram */ - float cngNoiseLevel_flt[FFTCLDFBLEN]; /* Noise level applied for the CNG in each (sub)band */ - Word32 periodog[PERIODOGLEN]; /* Periodogram Q31 - periodog_exp*/ - Word16 periodog_exp; // Q0 - Word16 exp_cldfb_periodog; // Q0 + Word32 periodog[PERIODOGLEN]; /* Periodogram Q31 - periodog_exp*/ + Word16 periodog_exp; // Q0 + Word16 exp_cldfb_periodog; // Q0 Word32 cngNoiseLevel[FFTCLDFBLEN]; /* Noise level applied for the CNG in each (sub)band Q31 - cngNoiseLevelExp*/ - // Word16 q_cngNoiseLevel; Word16 cngNoiseLevelExp; Word16 seed; /* Seed memory (for random function) */ Word16 seed2; /* Seed for second noise source in MDCT-Stereo DTX */ Word16 seed3; /* Seed for third noise source in MDCT-Stereo DTX */ - Word16 npart; /* Number of partitions */ - Word16 midband[NPART]; /* Central band of each partition */ - Word16 nFFTpart; /* Number of hybrid spectral partitions */ - Word16 part[NPART]; /* Partition upper boundaries (band indices starting from 0) */ - float psize_flt[NPART]; /* Partition sizes */ - float psize_inv_flt[NPART]; /* Inverse of partition sizes */ - float FFTscalingFactor_flt; /* Squared ratio between core signal analysis FFT and noise estimator FFT */ - float scalingFactor_flt; - Word16 psize[NPART]; /* Partition sizes 6Q9 */ - Word16 psize_norm_exp; /* Partition sizes exponent for fractional variable */ - Word16 psize_norm[NPART]; /* Partition sizes, fractional variable Q15-psize_norm_exp*/ - Word16 psize_inv[NPART]; /* Inverse of partition sizes Q15*/ - // Word16 FFTscalingFactor; /* Squared ratio between core signal analysis FFT and noise estimator FFT */ - Word16 scalingFactor; // Q15 - Word16 invScalingFactor; // Q15 - Word16 nCLDFBpart; /* Number of CLDFB spectral partitions */ - Word16 CLDFBpart[NPARTCLDFB]; /* CLDFB Partition upper boundaries (band indices starting from 0 above the core coder bands) */ - float CLDFBpsize_inv_flt[NPARTCLDFB]; /* Inverse of CLDFB partition sizes */ - Word16 CLDFBpsize_inv[NPARTCLDFB]; /* Inverse of CLDFB partition sizes Q15*/ + Word16 npart; /* Number of partitions */ + Word16 midband[NPART]; /* Central band of each partition */ + Word16 nFFTpart; /* Number of hybrid spectral partitions */ + Word16 part[NPART]; /* Partition upper boundaries (band indices starting from 0) */ + Word16 psize[NPART]; /* Partition sizes 6Q9 */ + Word16 psize_norm_exp; /* Partition sizes exponent for fractional variable */ + Word16 psize_norm[NPART]; /* Partition sizes, fractional variable Q15-psize_norm_exp*/ + Word16 psize_inv[NPART]; /* Inverse of partition sizes Q15*/ + // Word16 FFTscalingFactor; /* Squared ratio between core signal analysis FFT and noise estimator FFT */ + Word16 scalingFactor; // Q15 + Word16 invScalingFactor; // Q15 + Word16 nCLDFBpart; /* Number of CLDFB spectral partitions */ + Word16 CLDFBpart[NPARTCLDFB]; /* CLDFB Partition upper boundaries (band indices starting from 0 above the core coder bands) */ + Word16 CLDFBpsize_inv[NPARTCLDFB]; /* Inverse of CLDFB partition sizes Q15*/ Word16 inactive_frame_counter; Word16 sid_frame_counter; Word16 active_frame_counter; /* Active frame counter limited to MSBUFLEN in stereo decoder */ - - float sidNoiseEst_flt[NPART]; /* Transmitted noise level */ - Word32 sidNoiseEst[NPART]; /* Transmitted noise level Q31-sidNoiseEstExp*/ + Word32 sidNoiseEst[NPART]; /* Transmitted noise level Q31-sidNoiseEstExp*/ Word16 sidNoiseEstExp; - - float sidNoiseEstLp_flt[NPART]; Word32 sidNoiseEstLp[NPART]; // Q(31-sidNoiseEstExp) - Word16 frame_type_previous; - - float A_cng_flt[M + 1]; - float exc_cng_flt[L_FRAME16k]; - Word16 A_cng[M + 1]; // Qx - Word16 exc_cng[L_FRAME16k]; // Q_new -#ifdef IVAS_FLOAT_FIXED + Word16 A_cng[M + 1]; // Qx + Word16 exc_cng[L_FRAME16k]; // Q_new Word32 exc_cng_32fx[L_FRAME16k]; // Q_qexc_cng_32fx -#endif Word32 CngBitrate; Word16 CngBandwidth; Word16 flag_noisy_speech; -#ifndef IVAS_FLOAT_FIXED - float likelihood_noisy_speech_flt; -#else - Word16 likelihood_noisy_speech; /* Q15 */ -#endif - -#ifndef IVAS_FLOAT_FIXED - float coherence_flt; /* inter-channel coherence of noise */ -#else - Word16 coherence_fx; /* inter-channel coherence of noise Q15 */ -#endif - Word16 no_side_flag; /* indicates whether the side noise shape should be zeroed-out or not */ + Word16 likelihood_noisy_speech; /* Q15 */ + Word16 coherence_fx; /* inter-channel coherence of noise Q15 */ + Word16 no_side_flag; /* indicates whether the side noise shape should be zeroed-out or not */ } FD_CNG_COM, *HANDLE_FD_CNG_COM; @@ -705,7 +681,7 @@ typedef struct #ifndef IVAS_FLOAT_FIXED float scale_flt; #else - Word16 scale; /* Q15 */ + Word16 scale; /* Q15 */ #endif } SCALE_TCX_SETUP; @@ -752,8 +728,8 @@ typedef struct cldfb_filter_bank_struct const float *rot_vec_syn_re; const float *rot_vec_syn_im; #else - const Word32 *rot_vec_syn_re_fx; // Q29 - const Word32 *rot_vec_syn_im_fx; // Q29 + const Word32 *rot_vec_syn_re_fx; // Q29 + const Word32 *rot_vec_syn_im_fx; // Q29 const Word32 *rot_vec_syn_delay_re_fx; // Q31 const Word32 *rot_vec_syn_delay_im_fx; // Q31 diff --git a/lib_com/swb_bwe_com_fx.c b/lib_com/swb_bwe_com_fx.c index d56f1b784..08c72e016 100644 --- a/lib_com/swb_bwe_com_fx.c +++ b/lib_com/swb_bwe_com_fx.c @@ -64,18 +64,19 @@ /*==========================================================================*/ Word16 WB_BWE_gain_pred_fx( - Word16 *WB_fenv, /* o : WB frequency envelopes */ - const Word16 *core_dec_freq, /* i : Frequency domain core decoded signal */ - const Word16 coder_type, /* i : coding type */ - Word16 prev_coder_type, /* i : coding type of last frame */ - Word16 prev_WB_fenv, /* i : envelope for last frame */ - Word16 *voice_factors, /* i : voicing factors //Q15 */ - const Word16 pitch_buf[], /* i : pitch buffer //Q6 */ - Word32 last_core_brate, /* i : previous frame core bitrate */ - Word16 last_wb_bwe_ener, /* i : previous frame wb bwe signal energy */ - Word16 Q_syn, /* i : synthesis scaling */ - Word16 last_extl_fx, /* i : extl. layer for last frame */ - Word16 tilt_wb_fx ) + Word16 *WB_fenv, /* o : WB frequency envelopes Q3 */ + const Word16 *core_dec_freq, /* i : Frequency domain core decoded signal Q_syn */ + const Word16 coder_type, /* i : coding type */ + Word16 prev_coder_type, /* i : coding type of last frame */ + Word16 prev_WB_fenv, /* i : envelope for last frame Q3 */ + Word16 *voice_factors, /* i : voicing factors Q15 */ + const Word16 pitch_buf[], /* i : pitch buffer Q6 */ + Word32 last_core_brate, /* i : previous frame core bitrate */ + Word16 last_wb_bwe_ener, /* i : previous frame wb bwe signal energy Q3 */ + Word16 Q_syn, /* i : synthesis scaling */ + Word16 last_extl_fx, /* i : extl. layer for last frame */ + Word16 tilt_wb_fx /* Q4 */ +) { Word32 enerL; Word16 n_freq, mode, pitch; @@ -89,7 +90,7 @@ Word16 WB_BWE_gain_pred_fx( Word32 L_tmp; Word32 L_WB_fenv0, L_WB_fenv1; Word16 pitch_buf_tmp[4]; - Word16 alfa = 32767; + Word16 alfa = MAX_16; move16(); mode = NORMAL; @@ -133,7 +134,7 @@ Word16 WB_BWE_gain_pred_fx( L_tmp = L_shr( enerL, 4 ); test(); - IF( GT_32( L_max( L_WB_fenv1, L_WB_fenv0 ), L_tmp ) && GT_16( 9856, pitch ) ) + if ( GT_32( L_max( L_WB_fenv1, L_WB_fenv0 ), L_tmp ) && GT_16( 9856 /* 308 in Q5 */, pitch ) ) { ener_var_flag = 1; move16(); @@ -148,11 +149,11 @@ Word16 WB_BWE_gain_pred_fx( { exp = norm_l( L_WB_fenv0 ); tmp = extract_h( L_shl( L_WB_fenv0, exp ) ); - tmp = div_s( 16384, tmp ); /*Q(15+14-2*Q_syn-exp) */ + tmp = div_s( 16384 /* 1 in Q14 */, tmp ); /*Q(15+14-2*Q_syn-exp) */ L_tmp = L_shr( Mult_32_16( L_shl( L_WB_fenv1, 1 ), tmp ), sub( 15, exp ) ); /*2*Q_syn+15+exp-15->2*Q_syn+exp */ /*L_tmp Q15 */ tmp = extract_l( L_tmp ); - alfa = s_max( tmp, 3277 ); /*Q15 */ + alfa = s_max( tmp, 3277 /* 0.1 in Q15 */ ); /*Q15 */ L_WB_fenv0 = Mult_32_16( L_WB_fenv0, alfa ); /*2*Q_syn+15-15->2*Q_syn */ } #ifdef BASOP_NOGLOB @@ -163,11 +164,11 @@ Word16 WB_BWE_gain_pred_fx( { exp = norm_l( L_WB_fenv1 ); tmp = extract_h( L_shl( L_WB_fenv1, exp ) ); - tmp = div_s( 16384, tmp ); /*Q(15+14-2*Q_syn-exp) */ + tmp = div_s( 16384 /* 1 in Q14 */, tmp ); /*Q(15+14-2*Q_syn-exp) */ L_tmp = L_shr( Mult_32_16( L_shl( L_WB_fenv0, 1 ), tmp ), sub( 15, exp ) ); /*2*Q_syn+15+exp-15->2*Q_syn+exp */ /*L_tmp Q15 */ tmp = extract_l( L_tmp ); - alfa = s_max( tmp, 3277 ); /*Q15 */ + alfa = s_max( tmp, 3277 /* 0.1 in Q15 */ ); /*Q15 */ L_WB_fenv1 = Mult_32_16( L_WB_fenv1, alfa ); /*2*Q_syn+15-15->2*Q_syn */ } @@ -211,9 +212,9 @@ Word16 WB_BWE_gain_pred_fx( IF( NE_16( coder_type, AUDIO ) && NE_16( coder_type, UNVOICED ) && ener_var_flag == 0 ) { #ifdef BASOP_NOGLOB - WB_fenv[0] = add_sat( WB_fenv[0], mult_r_sat( WB_fenv[0], 16384 ) ); + WB_fenv[0] = add_sat( WB_fenv[0], mult_r_sat( WB_fenv[0], 16384 /* 0.5 in Q15 */ ) ); #else - WB_fenv[0] = add( WB_fenv[0], mult_r( WB_fenv[0], 16384 ) ); + WB_fenv[0] = add( WB_fenv[0], mult_r( WB_fenv[0], 16384 /* 0.5 in Q15 */ ) ); #endif move16(); } @@ -230,7 +231,7 @@ Word16 WB_BWE_gain_pred_fx( #else enerL_16 = round_fx( L_shl( L_tmp, sub( exp, 15 ) ) ); /* Q0 */ #endif - enerL_40 = mult_r( 6554, enerL_16 ); /*1/40 in Q18 ->Q3 */ + enerL_40 = mult_r( 6554 /* 0.2 in Q15 */, enerL_16 ); /*1/40 in Q18 ->Q3 */ test(); test(); @@ -239,7 +240,7 @@ Word16 WB_BWE_gain_pred_fx( test(); test(); IF( NE_16( coder_type, TRANSITION ) && NE_16( coder_type, AUDIO ) && NE_16( coder_type, UNVOICED ) && - GT_16( enerL_40, WB_fenv[0] ) && GT_16( alfa, 29491 ) && !( EQ_16( coder_type, prev_coder_type ) && GT_16( WB_fenv[0], prev_WB_fenv ) ) ) + GT_16( enerL_40, WB_fenv[0] ) && GT_16( alfa, 29491 /*0.9 in Q15*/ ) && !( EQ_16( coder_type, prev_coder_type ) && GT_16( WB_fenv[0], prev_WB_fenv ) ) ) { IF( WB_fenv[0] != 0 ) { @@ -251,7 +252,7 @@ Word16 WB_BWE_gain_pred_fx( #else tmp = round_fx( L_shl( L_tmp, sub( exp, 2 ) ) ); /*Q12 */ #endif - tmp = s_min( tmp, 16384 ); + tmp = s_min( tmp, 16384 /*4 in Q12*/ ); L_tmp = L_shr( L_mult0( tmp, WB_fenv[0] ), 12 ); /*Q15 */ WB_fenv[0] = extract_l( L_tmp ); /*Q3 */ move16(); @@ -260,7 +261,7 @@ Word16 WB_BWE_gain_pred_fx( IF( GT_16( WB_fenv[0], prev_WB_fenv ) ) { /*WB_fenv[0]= add(mult_r(9830, WB_fenv[0]), mult_r(22938, prev_WB_fenv)); move16();//Q3 */ - WB_fenv[0] = round_fx( L_mac( L_mult( 9830, WB_fenv[0] ), 22938, prev_WB_fenv ) ); /*Q3 */ + WB_fenv[0] = round_fx( L_mac( L_mult( 9830 /* 0.5 in Q15 */, WB_fenv[0] ), 22938 /* 0.7 in Q15 */, prev_WB_fenv ) ); /*Q3 */ move16(); } } @@ -276,8 +277,8 @@ Word16 WB_BWE_gain_pred_fx( #else tmp = round_fx( L_shl( L_tmp, add( exp, 6 ) ) ); /*14 */ #endif - tmp1 = s_max( tmp, 8192 ); - alfa = s_min( 24576, tmp1 ); /*Q14 */ + tmp1 = s_max( tmp, 8192 /* 0.5 in Q14 */ ); + alfa = s_min( 24576 /* 1.5 in Q14 */, tmp1 ); /*Q14 */ L_tmp = L_mult0( alfa, WB_fenv[0] ); /*Q14+Q3->Q17 */ L_tmp = L_shr( L_tmp, 14 ); /*Q3 */ @@ -309,14 +310,14 @@ Word16 WB_BWE_gain_pred_fx( #else tmp = round_fx( L_shl( L_tmp, sub( exp, 2 ) ) ); /*Q12 */ #endif - tmp = s_min( tmp, 16384 ); + tmp = s_min( tmp, 16384 /*4 in Q12*/ ); L_tmp = L_shr( L_mult0( tmp, WB_fenv[0] ), 12 ); /*Q3 */ WB_fenv[0] = extract_l( L_tmp ); /*Q3 */ move16(); IF( GT_16( WB_fenv[0], prev_WB_fenv ) ) { /*WB_fenv[0] = add(mult_r(9830, WB_fenv[0]), mult_r(22938, prev_WB_fenv));//Q3 */ - WB_fenv[0] = round_fx( L_mac( L_mult( 9830, WB_fenv[0] ), 22938, prev_WB_fenv ) ); /*Q3 */ + WB_fenv[0] = round_fx( L_mac( L_mult( 9830 /* 0.3 in Q15 */, WB_fenv[0] ), 22938 /* 0.7 in Q15 */, prev_WB_fenv ) ); /*Q3 */ move16(); } } @@ -330,18 +331,18 @@ Word16 WB_BWE_gain_pred_fx( IF( NE_16( coder_type, AUDIO ) ) { - tmp = mult_r( voice_factor, 19661 ); /*Q12 */ - tmp = s_max( tmp, 4096 ); + tmp = mult_r( voice_factor, 19661 /* 1.2 in Q14 */ ); /*Q12 */ + tmp = s_max( tmp, 4096 /* 1 in Q12 */ ); exp = norm_s( tmp ); tmp = div_s( shl( 1, sub( 14, exp ) ), tmp ); /*Q(29-exp-12) */ L_tmp = L_mult( WB_fenv[0], tmp ); /*Q(21-exp) */ WB_fenv[0] = round_fx( L_shl( L_tmp, sub( exp, 2 ) ) ); /*Q3 */ move16(); - tmp1 = mult_r( 328, pitch ); /*Q7 */ - tmp = s_min( s_max( tmp1, 16 ), 256 ); /*Q7 */ - L_tmp = L_shr( L_mult0( WB_fenv[0], tmp ), 7 ); /*Q3 */ - /*WB_fenv[0] = saturate(L_tmp); //Q3 */ + tmp1 = mult_r( 328 /* (1/400) in Q17 */, pitch ); /*Q7 */ + tmp = s_min( s_max( tmp1, 16 /* 0.125 in Q7 */ ), 256 /* 1 in Q7 */ ); /*Q7 */ + L_tmp = L_shr( L_mult0( WB_fenv[0], tmp ), 7 ); /*Q3 */ + /*WB_fenv[0] = saturate(L_tmp); //Q3 */ #ifdef BASOP_NOGLOB WB_fenv[0] = round_fx_sat( L_shl_sat( L_tmp, 16 ) ); /*Q3 */ move16(); @@ -353,21 +354,21 @@ Word16 WB_BWE_gain_pred_fx( IF( GT_32( last_core_brate, ACELP_8k00 ) && GT_16( WB_fenv[0], last_wb_bwe_ener ) ) { /*WB_fenv[0]= add(mult_r(29491, last_wb_bwe_ener), mult_r(3277, WB_fenv[0]));//Q3 */ - WB_fenv[0] = round_fx( L_mac( L_mult( 29491, last_wb_bwe_ener ), 3277, WB_fenv[0] ) ); /*Q3 */ + WB_fenv[0] = round_fx( L_mac( L_mult( 29491 /* 0.9 in Q15 */, last_wb_bwe_ener ), 3277, WB_fenv[0] ) ); /*Q3 */ move16(); } - IF( NE_16( last_extl_fx, WB_BWE ) && LT_16( tilt_wb_fx, 128 ) ) + IF( NE_16( last_extl_fx, WB_BWE ) && LT_16( tilt_wb_fx, 128 /* 8 in Q4 */ ) ) { - WB_fenv[0] = mult_r( s_min( 16384, shl( tilt_wb_fx, 8 ) ), WB_fenv[0] ); + WB_fenv[0] = mult_r( s_min( 16384 /* 0.5 in Q15 */, shl( tilt_wb_fx, 8 ) ), WB_fenv[0] ); move16(); } IF( EQ_16( env_var_flag, 1 ) ) { - WB_fenv[1] = add( WB_fenv[0], mult_r( WB_fenv[0], 16384 ) ); + WB_fenv[1] = add( WB_fenv[0], mult_r( WB_fenv[0], 16384 /* 0.5 in Q15 */ ) ); move16(); - WB_fenv[0] = mult_r( 24576, WB_fenv[0] ); + WB_fenv[0] = mult_r( 24576 /* 0.75 in Q15 */, WB_fenv[0] ); move16(); /*Q3 */ } ELSE @@ -471,9 +472,9 @@ static void calc_norm_envelop_lf_fx( FOR( n_lag = 0; n_lag < n_lag_now; n_lag++ ) { #ifdef BASOP_NOGLOB - L_tmp = L_add_sat( L_tmp, L_abs( SWB_signal[add( sub( n_freq, lookback ), n_lag )] ) ); + L_tmp = L_add_sat( L_tmp, L_abs( SWB_signal[n_freq - lookback + n_lag] ) ); #else - L_tmp = L_add( L_tmp, L_abs( SWB_signal[add( sub( n_freq, lookback ), n_lag )] ) ); + L_tmp = L_add( L_tmp, L_abs( SWB_signal[n_freq - lookback + n_lag] ) ); #endif } @@ -490,12 +491,12 @@ static void calc_norm_envelop_lf_fx( *-------------------------------------------------------------------*/ void calc_normal_length_fx( - const Word16 core, /* i : core */ - const Word16 *sp, /* i : input signal */ - const Word16 mode, /* i : input mode */ - const Word16 extl, /* i : extension layer */ - Word16 *L_swb_norm, /* o : normalize length */ - Word16 *prev_L_swb_norm, /*i/o : last normalize length */ + const Word16 core, /* i : core */ + const Word16 *sp, /* i : input signal Q_syn */ + const Word16 mode, /* i : input mode */ + const Word16 extl, /* i : extension layer */ + Word16 *L_swb_norm, /* o : normalize length */ + Word16 *prev_L_swb_norm, /*i/o : last normalize length */ Word16 Q_syn ) { Word16 i, n_freq, n_band, THRES; @@ -562,8 +563,8 @@ void calc_normal_length_fx( IF( EQ_16( core, ACELP_CORE ) ) { - L_swb_norm_trans = add( 4, mult( n_band, 8192 ) ); - L_swb_norm_norm = add( 8, mult( n_band, 16384 ) ); + L_swb_norm_trans = add( 4, mult( n_band, 8192 /* 0.25 in Q15 */ ) ); + L_swb_norm_norm = add( 8, mult( n_band, 16384 /* 0.5 in Q15 */ ) ); L_tmp = L_add( 65536, L_mult0( n_band, 4096 ) ); /*Q16 */ L_swb_norm_harm = s_max( round_fx( L_shl( L_tmp, 5 ) ), 24 ); /* Q0 */ @@ -593,7 +594,7 @@ void calc_normal_length_fx( test(); IF( EQ_16( mode, HQ_HARMONIC ) || EQ_16( mode, HQ_HVQ ) ) { - L_tmp = L_add( 65536, L_mult( n_band, 2560 ) ); + L_tmp = L_add( 65536, L_mult( n_band, 2560 /* 2.5 in Q10*/ ) ); L_swb_norm_cur = round_fx( L_shl( L_tmp, 5 ) ); /*Q0 */ } ELSE @@ -603,7 +604,7 @@ void calc_normal_length_fx( } /**L_swb_norm = add(mult_r(L_swb_norm_cur, 3277), mult_r(*prev_L_swb_norm, 29491)); */ - *L_swb_norm = round_fx( L_mac( L_mult( L_swb_norm_cur, 3277 ), *prev_L_swb_norm, 29491 ) ); + *L_swb_norm = round_fx( L_mac( L_mult( L_swb_norm_cur, 3277 /* 0.1 in Q15 */ ), *prev_L_swb_norm, 29491 /* 0.9 in Q15 */ ) ); move16(); *prev_L_swb_norm = L_swb_norm_cur; move16(); @@ -617,10 +618,10 @@ void calc_normal_length_fx( * calculate tilt parameter *-------------------------------------------------------------------*/ -Word32 calc_tilt_bwe_fx( /* o : Tilt in Q24 */ - const Word16 *sp, /* i : input signal */ - const Word16 exp_sp, /* i : Exp of inp signal */ - const Word16 N /* i : signal length */ +Word32 calc_tilt_bwe_fx( /* o : Tilt in Q24 */ + const Word16 *sp, /* i : input signal Q(15 - exp_sp) */ + const Word16 exp_sp, /* i : Exp of inp signal */ + const Word16 N /* i : signal length */ ) { Word16 i, j; @@ -648,20 +649,20 @@ Word32 calc_tilt_bwe_fx( /* o : Tilt in Q24 */ /* Divide Frame Length by 32 */ FOR( j = shr( N, 5 ); j > 0; j-- ) { -#ifdef BASOP_NOGLOB /* Critical Overflow and all those below*/ - tmp1 = mult_ro( *ptr++, 8192, &Overflow ); /* Divide by 4 */ +#ifdef BASOP_NOGLOB /* Critical Overflow and all those below*/ + tmp1 = mult_ro( *ptr++, 8192 /*0.25 in Q15 */, &Overflow ); /* Divide by 4 */ #else - tmp1 = mult_r( *ptr++, 8192 ); /* Divide by 4 */ + tmp1 = mult_r( *ptr++, 8192 /*0.25 in Q15 */ ); /* Divide by 4 */ #endif L_ener = L_mult0( tmp1, tmp1 ); /* With the shift by 4 and the L_mult0, no overflow possible for 32 samples */ FOR( i = 1; i < 32; i++ ) { -#ifdef BASOP_NOGLOB /* Critical Overflow */ - tmp1 = mult_ro( *ptr++, 8192, &Overflow ); /* Divide by 4 */ +#ifdef BASOP_NOGLOB /* Critical Overflow */ + tmp1 = mult_ro( *ptr++, 8192 /*0.25 in Q15 */, &Overflow ); /* Divide by 4 */ L_ener = L_mac0_o( L_ener, tmp1, tmp1, &Overflow ); #else - tmp1 = mult_r( *ptr++, 8192 ); /* Divide by 4 */ + tmp1 = mult_r( *ptr++, 8192 ); /* Divide by 4 */ L_ener = L_mac0( L_ener, tmp1, tmp1 ); #endif } @@ -743,10 +744,10 @@ Word32 calc_tilt_bwe_fx( /* o : Tilt in Q24 */ return L_temp; } #ifdef IVAS_FLOAT_FIXED -Word16 ivas_calc_tilt_bwe_fx( /* o : Tilt in Q24 */ - const Word32 *sp, /* i : input signal */ - const Word16 exp_sp, /* i : Exp of inp signal */ - const Word16 N /* i : signal length */ +Word16 ivas_calc_tilt_bwe_fx( /* o : Tilt in Q24 */ + const Word32 *sp, /* i : input signal */ + const Word16 exp_sp, /* i : Exp of inp signal Q(15 - exp_sp) */ + const Word16 N /* i : signal length */ ) { Word16 i, j; @@ -855,7 +856,7 @@ Word16 ivas_calc_tilt_bwe_fx( /* o : Tilt in Q24 */ void calc_norm_envelop_fx( const Word16 SWB_signal[], /* i : SWB spectrum Q_syn*/ Word32 *envelope, /* o : normalized envelope Q_syn*/ - const Word16 L_swb_norm, /* i : length of envelope Q0 */ + const Word16 L_swb_norm, /* i : length of envelope Q0 */ const Word16 SWB_flength, /* i : Length of input/output */ const Word16 st_offset /* i : offset */ ) @@ -1005,11 +1006,11 @@ void WB_BWE_decoding_fx( IF( NE_16( mode, HARMONIC ) ) { tmp = add( shl( inv_L_wb_norm, 1 ), inv_L_wb_norm ); - weight = s_max( s_min( tmp, 16384 ), 8192 ); + weight = s_max( s_min( tmp, 16384 /* 0.5 in Q15 */ ), 8192 /*0.25 in Q15 */ ); } ELSE { - weight = 8192; + weight = 8192; /*0.25 in Q15 */ move16(); } FOR( n_freq = swb_bwe_subband[0]; n_freq < swb_bwe_subband[4]; n_freq++ ) @@ -1113,7 +1114,7 @@ void WB_BWE_decoding_fx( } EnergyL = L_deposit_l( 0 ); - IF( core_type == 1 ) + IF( EQ_16( core_type, 1 ) ) { test(); IF( NE_16( prev_coder_type, AUDIO ) && LE_32( total_brate, ACELP_8k00 ) ) @@ -1290,17 +1291,17 @@ void WB_BWE_decoding_fx( test(); IF( EQ_16( last_extl, WB_BWE ) && GT_32( EnergyL, L_shr( *prev_Energy, 1 ) ) && GT_32( *prev_Energy, L_shr( EnergyL, 1 ) ) ) { - L_tmp1 = L_mac( L_mult( 8192, wfenv[0] ), 12288, prev_WB_fenv[0] ); - wfenv[0] = round_fx( L_mac( L_tmp1, 12288, prev_WB_fenv[1] ) ); + L_tmp1 = L_mac( L_mult( 8192 /* 0.25 in Q15 */, wfenv[0] ), 12288 /* 0.375 in Q15 */, prev_WB_fenv[0] ); /* Q3 */ + wfenv[0] = round_fx( L_mac( L_tmp1, 12288 /* 0.375 in Q15 */, prev_WB_fenv[1] ) ); /* Q3 */ } FOR( n_freq = swb_bwe_subband[0]; n_freq < swb_bwe_subband[4]; n_freq++ ) { WB_signal_32[n_freq] = Mult_32_16( WB_signal_32[n_freq], wfenv[0] ); move32(); /* Q_syn+3+1 */ } - prev_WB_fenv[0] = wfenv[0]; + prev_WB_fenv[0] = wfenv[0]; /* Q3 */ move16(); - prev_WB_fenv[1] = wfenv[0]; + prev_WB_fenv[1] = wfenv[0]; /* Q3 */ move16(); } @@ -1312,9 +1313,9 @@ void WB_BWE_decoding_fx( FOR( n_freq = 0; n_freq < 16; n_freq++ ) { - tmp1 = extract_l( L_mult0( n_freq, 1638 ) ); /*Q15 */ - tmp2 = add( 6554, tmp1 ); /*Q15 */ - L_tmp1 = Mult_32_16( *pit1, tmp2 ); /*Q_syn+3+1 */ + tmp1 = extract_l( L_mult0( n_freq, 1638 /* 0.05 in Q15 */ ) ); /*Q15 */ + tmp2 = add( 6554 /* 0.2 in Q15 */, tmp1 ); /*Q15 */ + L_tmp1 = Mult_32_16( *pit1, tmp2 ); /*Q_syn+3+1 */ *( pit1++ ) = L_tmp1; move32(); } @@ -1324,7 +1325,7 @@ void WB_BWE_decoding_fx( pit1 = &WB_signal_32[280]; FOR( n_freq = 0; n_freq < 40; n_freq++ ) { - tmp1 = extract_l( L_mult0( n_freq, 655 ) ); /*Q15 */ + tmp1 = extract_l( L_mult0( n_freq, 655 /* 0.02 in Q15 */ ) ); /*Q15 */ tmp2 = sub( 32767, tmp1 ); L_tmp1 = Mult_32_16( *pit1, tmp2 ); /*Q_syn+3+1 */ *( pit1++ ) = L_tmp1; @@ -1336,7 +1337,7 @@ void WB_BWE_decoding_fx( pit1 = &WB_signal_32[300]; FOR( n_freq = 0; n_freq < 20; n_freq++ ) { - tmp1 = extract_l( L_mult0( n_freq, 1311 ) ); /*Q15 */ + tmp1 = extract_l( L_mult0( n_freq, 1311 /* 0.04 in Q15 */ ) ); /*Q15 */ tmp2 = sub( 32767, tmp1 ); L_tmp1 = Mult_32_16( *pit1, tmp2 ); /*Q_syn+3+1 */ *( pit1++ ) = L_tmp1; @@ -1516,7 +1517,7 @@ void SWB_BWE_decoding_fx( 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, tmp ); /*Q(15+exp) */ + 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 ); /*Q15 */ move16(); @@ -1590,7 +1591,7 @@ void SWB_BWE_decoding_fx( move16(); } - *prev_weight = 16384; + *prev_weight = 16384 /* 0.5 in Q15 */; move16(); } ELSE @@ -1622,21 +1623,23 @@ void SWB_BWE_decoding_fx( #endif } + test(); IF( NE_16( last_extl, SWB_BWE ) && NE_16( last_extl, FB_BWE ) ) { - IF( Energy_16 < shr( EnergyL_16, 4 ) && EQ_16( extl, FB_BWE ) ) + test(); + IF( LT_16( Energy_16, shr( EnergyL_16, 4 ) ) && EQ_16( extl, FB_BWE ) ) { FOR( n_band = 0; n_band < SWB_FENV; n_band++ ) { - SWB_fenv[n_band] = mult_r( SWB_fenv[n_band], 6554 ); + SWB_fenv[n_band] = mult_r( SWB_fenv[n_band], 6554 /* 0.2 in Q15 */ ); move16(); } - fenvL_16 = mult_r( fenvL_16, 6554 ); + fenvL_16 = mult_r( fenvL_16, 6554 /* 0.2 in Q15 */ ); } Copy( SWB_fenv, prev_SWB_fenv, SWB_FENV ); } - IF( mode == HARMONIC ) + IF( EQ_16( mode, HARMONIC ) ) { Copy( core_dec_freq, &SWB_signal[240 + st_offset], 240 ); Copy( &core_dec_freq[128], &SWB_signal[480 + st_offset], 80 ); @@ -1651,9 +1654,9 @@ void SWB_BWE_decoding_fx( test(); test(); test(); - IF( EQ_16( mode, NOISE ) || ( ( GT_16( Energy_16, EnergyL_16 ) || ( GT_16( tilt_nb, 14336 ) && GT_16( Energy_16, shr( EnergyL_16, 1 ) ) ) || - GT_16( tilt_nb, 24576 ) ) && - GT_16( Energy_16, 600 ) && GT_16( fenvL_16, 200 ) ) ) + IF( EQ_16( mode, NOISE ) || ( ( GT_16( Energy_16, EnergyL_16 ) || ( GT_16( tilt_nb, 14336 /*7 in Q11*/ ) && GT_16( Energy_16, shr( EnergyL_16, 1 ) ) ) || + GT_16( tilt_nb, 24576 /*12 in Q11*/ ) ) && + GT_16( Energy_16, 600 /* 75 in Q3*/ ) && GT_16( fenvL_16, 200 /* 25 in Q3*/ ) ) ) { tmp = add( swb_bwe_subband[SWB_FENV], st_offset ); FOR( n_freq = add( swb_bwe_subband[0], st_offset ); n_freq < tmp; n_freq++ ) @@ -1674,16 +1677,16 @@ void SWB_BWE_decoding_fx( /* modify SHB frequency envelopes when SHB spectrum is unflat */ FOR( n_band = 0; n_band < 13; n_band++ ) { - IF( GT_16( mult_r( SWB_fenv[n_band], 29491 ), SWB_fenv[n_band + 1] ) ) + IF( GT_16( mult_r( SWB_fenv[n_band], 29491 /* 0.9 in Q15 */ ), SWB_fenv[n_band + 1] ) ) { - tmp = extract_l( L_mac0( 26214, n_band, 492 ) ); /*Q15; 0.015 in Q15 = 492 */ + tmp = extract_l( L_mac0( 26214 /* 0.8 in Q15 */, n_band, 492 ) ); /*Q15; 0.015 in Q15 = 492 */ SWB_fenv[n_band + 1] = mult_r( SWB_fenv[n_band + 1], tmp ); move16(); /*Q1 */ } - IF( GT_16( mult_r( SWB_fenv[n_band + 1], 29491 ), SWB_fenv[n_band] ) ) + IF( GT_16( mult_r( SWB_fenv[n_band + 1], 29491 /* 0.9 in Q15 */ ), SWB_fenv[n_band] ) ) { - tmp = extract_l( L_mac0( 26214, n_band, 492 ) ); /*Q15; 0.015 in Q15 = 492 */ + tmp = extract_l( L_mac0( 26214 /* 0.8 in Q15 */, n_band, 492 ) ); /*Q15; 0.015 in Q15 = 492 */ SWB_fenv[n_band] = mult_r( SWB_fenv[n_band], tmp ); move16(); /*Q1 */ } @@ -1703,7 +1706,7 @@ void SWB_BWE_decoding_fx( move16(); test(); - IF( ( tmp2 == 0 ) || ( LT_16( tmp2, mult_r( tmp1, 9830 ) ) ) ) + IF( ( tmp2 == 0 ) || ( LT_16( tmp2, mult_r( tmp1, 9830 /* 0.3 in Q15*/ ) ) ) ) { tmp3 = 9830; move16(); /*0.3 in Q15 */ @@ -1713,9 +1716,9 @@ void SWB_BWE_decoding_fx( move16(); /*Q_syn */ pit1++; #ifdef BASOP_NOGLOB - tmp3 = add_sat( tmp3, 3277 ); /*Q15 */ + tmp3 = add_sat( tmp3, 3277 /* 0.1 in Q15*/ ); /*Q15 */ #else - tmp3 = add( tmp3, 3277 ); /*Q15 */ + tmp3 = add( tmp3, 3277 /* 0.1 in Q15*/ ); /*Q15 */ #endif } } @@ -1734,7 +1737,7 @@ void SWB_BWE_decoding_fx( move16(); /*Q_syn */ pit1++; #ifdef BASOP_NOGLOB - tmp3 = add_sat( tmp3, 3277 ); /*Q15 */ + tmp3 = add_sat( tmp3, 3277 /* 0.1 in Q15*/ ); /*Q15 */ #else tmp3 = add( tmp3, 3277 ); /*Q15 */ #endif @@ -1743,7 +1746,7 @@ void SWB_BWE_decoding_fx( pit1 = &SWB_signal[367 + st_offset]; - IF( GT_16( mult_r( tmp1, 6554 ), tmp2 ) ) + IF( GT_16( mult_r( tmp1, 6554 /*0.2 in Q15*/ ), tmp2 ) ) { /*20480 = 5 in Q12 */ FOR( tmp3 = 20480; tmp3 > 4096; tmp3 -= 2048 ) @@ -1768,7 +1771,7 @@ void SWB_BWE_decoding_fx( pit1 = &SWB_signal[496 + st_offset]; test(); - IF( ( tmp2 == 0 ) || ( LT_16( tmp2, mult_r( tmp1, 9830 ) ) ) ) + IF( ( tmp2 == 0 ) || ( LT_16( tmp2, mult_r( tmp1, 9830 /* 0.3 in Q15 */ ) ) ) ) { tmp3 = 9830; move16(); /*0.3 in Q15 */ @@ -1778,9 +1781,9 @@ void SWB_BWE_decoding_fx( move16(); /*Q_syn */ pit1++; #ifdef BASOP_NOGLOB - tmp3 = add_sat( tmp3, 3277 ); /*Q15 */ + tmp3 = add_sat( tmp3, 3277 /* 0.1 in Q15 */ ); /*Q15 */ #else - tmp3 = add( tmp3, 3277 ); /*Q15 */ + tmp3 = add( tmp3, 3277 /* 0.1 in Q15 */ ); /*Q15 */ #endif } } @@ -1799,24 +1802,24 @@ void SWB_BWE_decoding_fx( move16(); /*Q_syn */ pit1++; #ifdef BASOP_NOGLOB - tmp3 = add_sat( tmp3, 3277 ); /*Q15 */ + tmp3 = add_sat( tmp3, 3277 /* 0.1 in Q15 */ ); /*Q15 */ #else - tmp3 = add( tmp3, 3277 ); /*Q15 */ + tmp3 = add( tmp3, 3277 /* 0.1 in Q15 */ ); /*Q15 */ #endif } } pit1 = &SWB_signal[495 + st_offset]; - L_tmp3 = L_deposit_h( tmp1 ); /*Q17 */ - L_tmp4 = Mult_32_16( L_tmp3, 1638 ); /*Q17 */ + L_tmp3 = L_deposit_h( tmp1 ); /*Q17 */ + L_tmp4 = Mult_32_16( L_tmp3, 1638 /* 0.05 in Q15*/ ); /*Q17 */ exp = 14; move16(); IF( tmp2 != 0 ) { exp = norm_s( tmp2 ); - tmp = div_s( shl( 1, sub( 14, exp ) ), tmp2 ); /*Q(29-exp) */ - L_tmp3 = L_shr( L_mult( tmp1, tmp ), 1 ); /*Q(30-exp+1)->Q(30-exp) (+1) due to *0.5 */ - L_tmp4 = Mult_32_16( L_tmp3, 1638 ); /*Q(30-exp) */ + tmp = div_s( shl( 1, sub( 14, exp ) ), tmp2 ); /*Q(29-exp) */ + L_tmp3 = L_shr( L_mult( tmp1, tmp ), 1 ); /*Q(30-exp+1)->Q(30-exp) (+1) due to *0.5 */ + L_tmp4 = Mult_32_16( L_tmp3, 1638 /* 0.05 in Q15 */ ); /*Q(30-exp) */ } L_tmp1 = L_shl( 1L, sub( 30, exp ) ); @@ -1844,15 +1847,15 @@ void SWB_BWE_decoding_fx( IF( NE_16( mode, HARMONIC ) ) { tmp = add( shl( inv_L_swb_norm, 1 ), inv_L_swb_norm ); - weight = s_max( s_min( tmp, 16384 ), 6554 ); + weight = s_max( s_min( tmp, 16384 /* 0.5 in Q15 */ ), 6554 /* 0.2 in Q15 */ ); } ELSE { - weight = 6554; + weight = 6554; /* 0.2 in Q15 */ move16(); } - weight = mac_r( L_mult( 13107, weight ), 19661, ( *prev_weight ) ); + weight = mac_r( L_mult( 13107 /* 0.4 in Q15 */, weight ), 19661 /* 0.6 in Q15 */, ( *prev_weight ) ); FOR( n_freq = L; n_freq < swb_bwe_subband[SWB_FENV] + st_offset; n_freq++ ) { @@ -1892,7 +1895,7 @@ void SWB_BWE_decoding_fx( 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, tmp ); /* Q(15+exp) */ + 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 */ @@ -1911,7 +1914,7 @@ 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 ), 6554 ); /* Q15 */ + *prev_weight = s_max( s_min( tmp, 16384 /* 0.5 in Q15 */ ), 6554 /* 0.2 in Q15 */ ); /* Q15 */ move16(); } @@ -1927,13 +1930,13 @@ IF( EQ_16( mode, HARMONIC ) ) L_mean = L_add( L_mean, abs_s( *pit1 ) ); /*Q15 */ pit1++; } - mean = extract_l( Mult_32_16( L_mean, 2048 ) ); /*Q15 */ + 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 ); /*Q15*/ + *pit1 = mult_r( *pit1, 6554 /* 0.2 in Q15 */ ); /*Q15*/ move16(); } pit1++; @@ -2023,15 +2026,15 @@ IF( GT_16( tmp, 4 ) ) tmp = 12; move16(); factor = fenvL_16; - move16(); /*Q3 */ - factor1 = mult_r( sub( shl( wfenv, 2 ), fenvL_16 ), 4096 ); /*Q3 */ + 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 ); /*Q1 */ + 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 ); @@ -2131,7 +2134,7 @@ FOR( n_band = 0; n_band < SWB_FENV; n_band++ ) 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 ); /*15+Qsyn */ + L_tmp1 = Mult_32_16( *pit1_32, 16384 /* 0.5 in Q15 */ ); /*15+Qsyn */ *( pit1_32++ ) = L_tmp1; move32(); } @@ -2209,9 +2212,9 @@ void time_envelop_shaping_fx( test(); #ifdef BASOP_NOGLOB - IF( LT_32( SWB_tenv[i], 65536 ) && LT_32( Energy, L_shl_sat( SWB_tenv[i], sub( 16, exp ) ) ) ) + IF( LT_32( SWB_tenv[i], 65536 /* 2 in Q15 */ ) && LT_32( Energy, L_shl_sat( SWB_tenv[i], sub( 16, exp ) ) ) ) #else - IF( LT_32( SWB_tenv[i], 65536 ) && LT_32( Energy, L_shl( SWB_tenv[i], sub( 16, exp ) ) ) ) + IF( LT_32( SWB_tenv[i], 65536 /* 2 in Q15 */ ) && LT_32( Energy, L_shl( SWB_tenv[i], sub( 16, exp ) ) ) ) #endif { *Q_synth = add( *Q_synth, 3 ); @@ -2323,8 +2326,8 @@ void time_reduce_pre_echo_fx( FOR( i = 0; i < 3; i++ ) { - L_tmp = Mult_32_16( energyL[i], 29491 ); /*Q14 */ - IF( GT_32( L_shr( energyL[i + 1], 1 ), L_tmp ) && GT_32( energyL[i + 1], 1638400 ) ) + L_tmp = Mult_32_16( energyL[i], 29491 /* 0.9 in Q15 */ ); /*Q14 */ + IF( GT_32( L_shr( energyL[i + 1], 1 ), L_tmp ) && GT_32( energyL[i + 1], 1638400 /* 100 in Q14 */ ) ) { pos = add( i, 1 ); move16(); @@ -2367,7 +2370,7 @@ void time_reduce_pre_echo_fx( energy_16 = round_fx( L_shl( energy, sub( exp, 15 ) ) ); /*Q0 */ } - tmp = mult_r( energy_16, 6554 ); /*Q0 */ + tmp = mult_r( energy_16, 6554 /* 0.2 in Q15 */ ); /*Q0 */ if ( LT_16( prev_td_energy, tmp ) ) { prev_td_energy = tmp; @@ -2525,7 +2528,7 @@ void calc_normal_length_fx_32( L_tmp1 = Mult_32_16( peak, shl( add( 15, THRES ), 10 ) ); L_tmp2 = Mult_32_16( mean, shl( THRES, 10 ) ); test(); - IF( GT_32( L_tmp1, L_tmp2 ) && GT_32( peak, 40960 ) ) + IF( GT_32( L_tmp1, L_tmp2 ) && GT_32( peak, 40960 /* 10 in Q12 */ ) ) { n_band = add( n_band, 1 ); } @@ -2570,7 +2573,7 @@ void calc_normal_length_fx_32( L_swb_norm_cur = add( 8, shr( n_band, 1 ) ); } - *L_swb_norm = extract_h( L_add( L_mac( L_mult( L_swb_norm_cur, 3276 ), *prev_L_swb_norm, 29491 ), 32768 ) ); + *L_swb_norm = extract_h( L_add( L_mac( L_mult( L_swb_norm_cur, 3276 /* 0.1 in Q15 */ ), *prev_L_swb_norm, 29491 /* 0.9 in Q15 */ ), 32768 /* 1 in Q15 */ ) ); *prev_L_swb_norm = L_swb_norm_cur; move16(); move16(); @@ -2609,9 +2612,9 @@ void calc_norm_envelop_fx_32( FOR( n_lag = 0; n_lag < n_lag_now; n_lag++ ) { #ifdef BASOP_NOGLOB - envelope_fx[env_index] = L_add_sat( envelope_fx[env_index], L_abs( SWB_signal_fx[add( n_freq, n_lag )] ) ); + envelope_fx[env_index] = L_add_sat( envelope_fx[env_index], L_abs( SWB_signal_fx[n_freq + n_lag] ) ); #else - envelope_fx[env_index] = L_add( envelope_fx[env_index], L_abs( SWB_signal_fx[add( n_freq, n_lag )] ) ); + envelope_fx[env_index] = L_add( envelope_fx[env_index], L_abs( SWB_signal_fx[n_freq + n_lag] ) ); #endif move32(); } @@ -2630,7 +2633,7 @@ void calc_norm_envelop_fx_32( L_tmp = L_deposit_l( 0 ); FOR( n_lag = 0; n_lag < n_lag_now; n_lag++ ) { - L_tmp = L_add( L_tmp, L_abs( SWB_signal_fx[add( n_freq, n_lag )] ) ); + L_tmp = L_add( L_tmp, L_abs( SWB_signal_fx[n_freq + n_lag] ) ); } envelope_fx[env_index] = L_tmp; move32(); @@ -2941,23 +2944,23 @@ void hq_generic_decoding_fx( } } - Copy32( &coeff_out1_fx[HQ_GENERIC_OFFSET], &coeff_out_fx[add( HQ_GENERIC_HIGH0, hq_generic_offset )], HQ_GENERIC_LEN0 ); - Copy32( &coeff_out1_fx[HQ_GENERIC_OFFSET], &coeff_out_fx[add( HQ_GENERIC_HIGH1, hq_generic_offset )], HQ_GENERIC_LEN0 ); + Copy32( &coeff_out1_fx[HQ_GENERIC_OFFSET], &coeff_out_fx[HQ_GENERIC_HIGH0 + hq_generic_offset], HQ_GENERIC_LEN0 ); + Copy32( &coeff_out1_fx[HQ_GENERIC_OFFSET], &coeff_out_fx[HQ_GENERIC_HIGH1 + hq_generic_offset], HQ_GENERIC_LEN0 ); IF( LE_16( hq_generic_offset, HQ_GENERIC_FOFFSET_24K4 ) ) { - Copy32( &coeff_out1_fx[HQ_GENERIC_LOW0], &coeff_out_fx[add( HQ_GENERIC_HIGH2, hq_generic_offset )], sub( HQ_GENERIC_END_FREQ, HQ_GENERIC_HIGH2 ) ); + Copy32( &coeff_out1_fx[HQ_GENERIC_LOW0], &coeff_out_fx[HQ_GENERIC_HIGH2 + hq_generic_offset], HQ_GENERIC_END_FREQ - HQ_GENERIC_HIGH2 ); } IF( EQ_16( HQ_mode, HQ_GEN_FB ) ) { IF( LE_16( hq_generic_offset, HQ_GENERIC_FOFFSET_24K4 ) ) { - Copy32( &coeff_out1_fx[sub( add( HQ_GENERIC_LOW0, HQ_GENERIC_END_FREQ ), HQ_GENERIC_HIGH2 )], &coeff_out_fx[fb_bwe_subband[0]], 160 ); + Copy32( &coeff_out1_fx[HQ_GENERIC_LOW0 + HQ_GENERIC_END_FREQ - HQ_GENERIC_HIGH2], &coeff_out_fx[fb_bwe_subband[0]], 160 ); } ELSE { - Copy32( &coeff_out1_fx[add( HQ_GENERIC_OFFSET, HQ_GENERIC_LEN0 )], &coeff_out_fx[fb_bwe_subband[0]], 160 ); + Copy32( &coeff_out1_fx[HQ_GENERIC_OFFSET + HQ_GENERIC_LEN0], &coeff_out_fx[fb_bwe_subband[0]], 160 ); } } @@ -2966,11 +2969,11 @@ void hq_generic_decoding_fx( L_tmp2 = L_deposit_l( 0 ); FOR( i = 0; i < 5; ++i ) { - L_tmp1 = L_add( L_tmp1, L_abs( coeff_out_fx[add( add( HQ_GENERIC_HIGH1, hq_generic_offset ), i )] ) ); - L_tmp2 = L_add( L_tmp2, L_abs( coeff_out_fx[sub( add( sub( HQ_GENERIC_HIGH1, 2 ), hq_generic_offset ), i )] ) ); + L_tmp1 = L_add( L_tmp1, L_abs( coeff_out_fx[HQ_GENERIC_HIGH1 + hq_generic_offset + i] ) ); + L_tmp2 = L_add( L_tmp2, L_abs( coeff_out_fx[HQ_GENERIC_HIGH1 - 2 + hq_generic_offset - i] ) ); } - pit1_fx = &coeff_out_fx[add( HQ_GENERIC_HIGH1, hq_generic_offset )]; + pit1_fx = &coeff_out_fx[HQ_GENERIC_HIGH1 + hq_generic_offset]; L_tmp1 = L_max( L_tmp1, 1 ); L_tmp2 = L_max( L_tmp2, 1 ); exp1 = norm_l( L_tmp1 ); @@ -2980,9 +2983,9 @@ void hq_generic_decoding_fx( tmp3_fx = div_s( tmp2_fx, tmp1_fx ); /*15 + exp2 + 15 - (exp1 + 15) */ tmp3_fx = shr( tmp3_fx, add( 5, sub( exp2, exp1 ) ) ); /*10 */ - if ( LT_16( tmp3_fx, 307 ) ) + if ( LT_16( tmp3_fx, 307 /*0.3 in Q10 */ ) ) { - tmp3_fx = 307; + tmp3_fx = 307 /*0.3 in Q10 */; move16(); } FOR( ; tmp3_fx < 1024; tmp3_fx += 102 ) @@ -2992,7 +2995,7 @@ void hq_generic_decoding_fx( pit1_fx++; } - pit1_fx = &coeff_out_fx[add( sub( HQ_GENERIC_HIGH1, 1 ), hq_generic_offset )]; + pit1_fx = &coeff_out_fx[HQ_GENERIC_HIGH1 - 1 + hq_generic_offset]; exp1 = sub( norm_l( L_tmp1 ), 1 ); exp2 = norm_l( L_tmp2 ); @@ -3014,11 +3017,11 @@ void hq_generic_decoding_fx( IF( LE_16( hq_generic_offset, HQ_GENERIC_FOFFSET_24K4 ) ) { - L_tmp1 = L_add( L_abs( coeff_out_fx[add( HQ_GENERIC_HIGH2, hq_generic_offset )] ), L_abs( coeff_out_fx[add( add( HQ_GENERIC_HIGH2, 1 ), hq_generic_offset )] ) ); - L_tmp2 = L_add( L_abs( coeff_out_fx[add( sub( HQ_GENERIC_HIGH2, 4 ), hq_generic_offset )] ), L_add( L_abs( coeff_out_fx[add( sub( HQ_GENERIC_HIGH2, 3 ), hq_generic_offset )] ), - L_add( L_abs( coeff_out_fx[add( sub( HQ_GENERIC_HIGH2, 2 ), hq_generic_offset )] ), L_abs( coeff_out_fx[add( sub( HQ_GENERIC_HIGH2, 1 ), hq_generic_offset )] ) ) ) ); + L_tmp1 = L_add( L_abs( coeff_out_fx[HQ_GENERIC_HIGH2 + hq_generic_offset] ), L_abs( coeff_out_fx[HQ_GENERIC_HIGH2 + 1 + hq_generic_offset] ) ); + L_tmp2 = L_add( L_abs( coeff_out_fx[HQ_GENERIC_HIGH2 - 4 + hq_generic_offset] ), L_add( L_abs( coeff_out_fx[HQ_GENERIC_HIGH2 - 3 + hq_generic_offset] ), + L_add( L_abs( coeff_out_fx[HQ_GENERIC_HIGH2 - 2 + hq_generic_offset] ), L_abs( coeff_out_fx[HQ_GENERIC_HIGH2 - 1 + hq_generic_offset] ) ) ) ); - pit1_fx = &coeff_out_fx[add( HQ_GENERIC_HIGH2, hq_generic_offset )]; + pit1_fx = &coeff_out_fx[HQ_GENERIC_HIGH2 + hq_generic_offset]; L_tmp1 = L_max( L_tmp1, 1 ); L_tmp2 = L_max( L_tmp2, 1 ); @@ -3032,9 +3035,9 @@ void hq_generic_decoding_fx( #else tmp3_fx = shr( tmp3_fx, add( 5, sub( exp2, exp1 ) ) ); /*10 */ #endif - if ( LT_16( tmp3_fx, 307 ) ) + if ( LT_16( tmp3_fx, 307 /* 0.3 in Q10*/ ) ) { - tmp3_fx = 307; + tmp3_fx = 307; /* 0.3 in Q10*/ move16(); } FOR( ; tmp3_fx < 1024; tmp3_fx += 102 ) @@ -3044,7 +3047,7 @@ void hq_generic_decoding_fx( move32(); } - pit1_fx = &coeff_out_fx[add( sub( HQ_GENERIC_HIGH2, 1 ), hq_generic_offset )]; + pit1_fx = &coeff_out_fx[HQ_GENERIC_HIGH2 - 1 + hq_generic_offset]; exp1 = sub( norm_l( L_tmp1 ), 1 ); exp2 = norm_l( L_tmp2 ); @@ -3053,8 +3056,8 @@ void hq_generic_decoding_fx( tmp3_fx = div_s( tmp1_fx, tmp2_fx ); /*15 + exp2 + 15 - (exp1 + 15) */ tmp3_fx = shr( tmp3_fx, add( 5, sub( exp1, exp2 ) ) ); /*10 */ tmp3_fx = shr( tmp3_fx, 1 ); - tmp4_fx = mult_r( tmp3_fx, 1638 ); - WHILE( tmp3_fx > 1024 ) + tmp4_fx = mult_r( tmp3_fx, 1638 /* 0.05 in Q15 */ ); + WHILE( tmp3_fx > 1024 /* 1 in Q10*/ ) { #ifdef EVS_FUNC_MODIFIED L_tmp1 = L_shl( Mult_32_16( *pit1_fx, tmp3_fx ), 5 ); /*15 + 5 + 10 -15 */ @@ -3092,10 +3095,10 @@ void hq_generic_decoding_fx( k = sub( nenv, 2 ); FOR( n_band = 0; n_band < k; n_band++ ) { - wfenv_fx = hq_generic_fenv_fx[add( n_band, 1 )]; + wfenv_fx = hq_generic_fenv_fx[n_band + 1]; move16(); /*1 */ - tmp2 = swb_bwe_sm_subband[add( n_band, 1 )] + hq_generic_offset; + tmp2 = swb_bwe_sm_subband[n_band + 1] + hq_generic_offset; FOR( i = 0; n_freq < tmp2; i++ ) { L_tmp1 = L_mult( sub( wfenv_fx, hq_generic_fenv_fx[n_band] ), smooth_factor_fx[n_band] ); /*17 */ @@ -3111,14 +3114,14 @@ void hq_generic_decoding_fx( } } - wfenv_fx = hq_generic_fenv_fx[sub( nenv, 1 )]; + wfenv_fx = hq_generic_fenv_fx[nenv - 1]; move16(); /*1 */ - tmp2 = add( swb_bwe_sm_subband[sub( nenv, 1 )], hq_generic_offset ); + tmp2 = add( swb_bwe_sm_subband[nenv - 1], hq_generic_offset ); FOR( i = 0; n_freq < tmp2; i++ ) { - L_tmp1 = L_mult( sub( wfenv_fx, hq_generic_fenv_fx[sub( nenv, 2 )] ), smooth_factor_fx[sub( nenv, 2 )] ); /*17 */ - L_tmp1 = Mult_32_16( L_tmp1, shl( i, 10 ) ); /*17 + 10 - 15 */ - L_tmp1 = L_add( L_tmp1, L_shl( hq_generic_fenv_fx[sub( nenv, 2 )], 11 ) ); /*12 */ + L_tmp1 = L_mult( sub( wfenv_fx, hq_generic_fenv_fx[nenv - 2] ), smooth_factor_fx[nenv - 2] ); /*17 */ + L_tmp1 = Mult_32_16( L_tmp1, shl( i, 10 ) ); /*17 + 10 - 15 */ + L_tmp1 = L_add( L_tmp1, L_shl( hq_generic_fenv_fx[nenv - 2], 11 ) ); /*12 */ cs = norm_l( L_tmp1 ); tmp = extract_h( L_shl( L_tmp1, cs ) ); /*12 + cs - 16 */ @@ -3134,7 +3137,7 @@ void hq_generic_decoding_fx( { wfenv_fx = hq_generic_fenv_fx[n_band]; move16(); /*1 */ - tmp2 = add( swb_bwe_subband[add( n_band, 1 )], hq_generic_offset ); + tmp2 = add( swb_bwe_subband[n_band + 1], hq_generic_offset ); FOR( ; n_freq < tmp2; n_freq++ ) { L_tmp = Mult_32_16( coeff_out_fx[n_freq], wfenv_fx ); /*15 + 12 + 1 - 15 */ @@ -3146,9 +3149,9 @@ void hq_generic_decoding_fx( ELSE { test(); - IF( hq_generic_fenv_fx[sub( nenv, 1 )] - hq_generic_fenv_fx[nenv] > 30 || hq_generic_fenv_fx[nenv] < 10 ) + IF( GT_16( sub( hq_generic_fenv_fx[nenv - 1], hq_generic_fenv_fx[nenv] ), 30 ) || LT_16( hq_generic_fenv_fx[nenv], 10 ) ) { - wfenv_fx = hq_generic_fenv_fx[sub( nenv, 1 )]; + wfenv_fx = hq_generic_fenv_fx[nenv - 1]; move16(); /*1 */ FOR( i = 0; n_freq < fb_bwe_subband[0]; i++ ) { @@ -3160,9 +3163,9 @@ void hq_generic_decoding_fx( FOR( n_band = 0; n_band < DIM_FB; n_band++ ) { - wfenv_fx = hq_generic_fenv_fx[add( n_band, nenv )]; + wfenv_fx = hq_generic_fenv_fx[n_band + nenv]; move16(); /*1 */ - tmp2 = fb_bwe_subband[add( n_band, 1 )]; + tmp2 = fb_bwe_subband[n_band + 1]; FOR( i = 0; n_freq < tmp2; i++ ) { L_tmp = Mult_32_16( coeff_out_fx[n_freq], wfenv_fx ); /*15 + 12 + 1 - 15 */ @@ -3176,14 +3179,14 @@ void hq_generic_decoding_fx( { FOR( n_band = 0; n_band < DIM_FB; n_band++ ) { - wfenv_fx = hq_generic_fenv_fx[sub( add( n_band, nenv ), 1 )]; + wfenv_fx = hq_generic_fenv_fx[n_band + nenv - 1]; move16(); /*1 */ FOR( i = 0; n_freq < fb_bwe_sm_subband[n_band]; i++ ) { - L_tmp1 = L_mult( sub( wfenv_fx, hq_generic_fenv_fx[add( n_band, nenv )] ), fb_smooth_factor_fx[n_band] ); /*17 */ - L_tmp1 = Mult_32_16( L_tmp1, shl( i, 9 ) ); /*17 + 9 - 15 */ - L_tmp1 = L_add( L_tmp1, L_shl( hq_generic_fenv_fx[add( n_band, nenv )], 10 ) ); /*11 */ + L_tmp1 = L_mult( sub( wfenv_fx, hq_generic_fenv_fx[n_band + nenv] ), fb_smooth_factor_fx[n_band] ); /*17 */ + L_tmp1 = Mult_32_16( L_tmp1, shl( i, 9 ) ); /*17 + 9 - 15 */ + L_tmp1 = L_add( L_tmp1, L_shl( hq_generic_fenv_fx[n_band + nenv], 10 ) ); /*11 */ cs = norm_l( L_tmp1 ); tmp = extract_h( L_shl( L_tmp1, cs ) ); /*11 + cs - 16 */ @@ -3194,7 +3197,7 @@ void hq_generic_decoding_fx( } } - wfenv_fx = hq_generic_fenv_fx[sub( tenv, 1 )]; + wfenv_fx = hq_generic_fenv_fx[tenv - 1]; move16(); /*1 */ FOR( ; n_freq < fb_bwe_subband[DIM_FB]; n_freq++ ) diff --git a/lib_com/swb_bwe_com_hr_fx.c b/lib_com/swb_bwe_com_hr_fx.c index cac0ed123..7755ec697 100644 --- a/lib_com/swb_bwe_com_hr_fx.c +++ b/lib_com/swb_bwe_com_hr_fx.c @@ -12,11 +12,11 @@ * SWB BWE HR noise filling of zero subbands *-------------------------------------------------------------------*/ static void swb_hr_nonzero_subband_noise_fill_fx( - const Word16 tilt_wb_fx, /* i : tilt of wideband signal */ - Word16 *t_audio_fx, /* i/o: mdct spectrum */ - Word16 *bwe_highrate_seed, /* i/o: seed of random noise */ - const Word16 N, /* i : length of subband */ - const Word16 Nsv, /* i : number of subband */ + const Word16 tilt_wb_fx, /* i : tilt of wideband signal Q11 */ + Word16 *t_audio_fx, /* i/o: mdct spectrum Q_audio */ + Word16 *bwe_highrate_seed, /* i/o: seed of random noise */ + const Word16 N, /* i : length of subband */ + const Word16 Nsv, /* i : number of subband */ Word16 Q_audio ) { Word16 i, j; @@ -24,18 +24,18 @@ static void swb_hr_nonzero_subband_noise_fill_fx( Word16 min_bwe_fx, max_bwe_fx, tmpF_fx; Word16 tmp; - IF( GT_16( tilt_wb_fx, 10240 ) ) + IF( GT_16( tilt_wb_fx, 10240 /* 5 in Q11 */ ) ) { FOR( i = 0; i < Nsv; i++ ) { - min_bwe_fx = 32767; + min_bwe_fx = MAX_16; move16(); max_bwe_fx = 0; move16(); tmp = i_mult2( i, N ); FOR( j = 0; j < N; j++ ) { - tmpF_fx = abs_s( t_audio_fx[tmp + j] ); + tmpF_fx = abs_s( t_audio_fx[tmp + j] ); // Q_audio max_bwe_fx = s_max( tmpF_fx, max_bwe_fx ); if ( tmpF_fx > 0 ) @@ -47,7 +47,7 @@ static void swb_hr_nonzero_subband_noise_fill_fx( test(); if ( EQ_16( max_bwe_fx, min_bwe_fx ) && GT_16( min_bwe_fx, shl( 1, Q_audio ) ) ) { - min_bwe_fx = mult_r( min_bwe_fx, 16384 ); + min_bwe_fx = mult_r( min_bwe_fx, 16384 /* 0.5 in Q15 */ ); // Q_audio + Q15 - Q15 -> Q_audio } ptr_fx = &t_audio_fx[tmp]; @@ -55,12 +55,12 @@ static void swb_hr_nonzero_subband_noise_fill_fx( { IF( *ptr_fx == 0 ) { - tmp = mult_r( min_bwe_fx, 16384 ); - if ( Random( bwe_highrate_seed ) <= 0 ) + tmp = mult_r( min_bwe_fx, 16384 /* 0.5 in Q15 */ ); + if ( Random( bwe_highrate_seed ) <= 0 ) // Q_audio + Q15 - Q15 -> Q_audio { tmp = negate( tmp ); } - *ptr_fx = tmp; + *ptr_fx = tmp; // Q_audio move16(); } ptr_fx++; @@ -77,15 +77,15 @@ static void swb_hr_nonzero_subband_noise_fill_fx( * SWB BWE HR noise filling *-------------------------------------------------------------------*/ void swb_hr_noise_fill_fx( - const Word16 is_transient, /* i : transient flag */ - const Word16 spect_start, /* i : spectrum start point */ - const Word16 spect_end, /* i : spectrum end point */ - const Word16 tilt_wb_fx, /* i : tilt of wideband signal */ - const Word16 pitch_fx, /* i : pitch value */ - const Word16 nq[], /* i : AVQ nq index */ - Word16 Nsv, /* i : number of subband */ - Word16 *bwe_highrate_seed, /* i/o: seed of random noise */ - Word16 *t_audio_fx, /* i/o: mdct spectrum */ + const Word16 is_transient, /* i : transient flag */ + const Word16 spect_start, /* i : spectrum start point */ + const Word16 spect_end, /* i : spectrum end point */ + const Word16 tilt_wb_fx, /* i : tilt of wideband signal Q11 */ + const Word16 pitch_fx, /* i : pitch value Q4 */ + const Word16 nq[], /* i : AVQ nq index */ + Word16 Nsv, /* i : number of subband */ + Word16 *bwe_highrate_seed, /* i/o: seed of random noise */ + Word16 *t_audio_fx, /* i/o: mdct spectrum Q_audio */ Word16 Q_audio ) { Word16 i, j, k; @@ -116,14 +116,14 @@ void swb_hr_noise_fill_fx( Nsv = shr( sub( spect_end, spect_start ), 3 ); alpha_fx = 8192; move16(); /*Q15 */ - IF( GT_16( tilt_wb_fx, 10240 ) ) + IF( GT_16( tilt_wb_fx, 10240 /* 5 in Q11 */ ) ) { beta_fx = 8192; move16(); /*Q15 */ } ELSE { - IF( GT_16( 6400, pitch_fx ) ) + IF( GT_16( 6400 /* 400 in Q4 */, pitch_fx ) ) { beta_fx = 8192; move16(); /*Q15 */ @@ -176,9 +176,9 @@ void swb_hr_noise_fill_fx( tmp1 = shl( incr, 3 ); FOR( k = 0; k < WIDTH_BAND; k++ ) { - tmp2 = mult_r( alpha_fx, t_audio_fx[tmp1 + k] ); - tmp3 = mult_r( beta_fx, shr( Random( bwe_highrate_seed ), tmp_exp ) ); - t_audio_fx[tmp + k] = add( tmp2, tmp3 ); + tmp2 = mult_r( alpha_fx, t_audio_fx[tmp1 + k] ); // Q_audio + Q15 - Q15 -> Q_audio + tmp3 = mult_r( beta_fx, shr( Random( bwe_highrate_seed ), tmp_exp ) ); // Q_audio + Q15 - Q15 -> Q_audio + t_audio_fx[tmp + k] = add( tmp2, tmp3 ); // Q_audio move16(); } @@ -234,9 +234,9 @@ void swb_hr_noise_fill_fx( tmp1 = shl( incr, 3 ); FOR( k = 0; k < WIDTH_BAND; k++ ) { - tmp2 = mult_r( alpha_fx, t_audio_fx[tmp1 + k] ); - tmp3 = mult_r( beta_fx, shr( Random( bwe_highrate_seed ), tmp_exp ) ); - t_audio_fx[tmp + k] = add( tmp2, tmp3 ); + tmp2 = mult_r( alpha_fx, t_audio_fx[tmp1 + k] ); // // Q_audio + Q15 - Q15 -> Q_audio + tmp3 = mult_r( beta_fx, shr( Random( bwe_highrate_seed ), tmp_exp ) ); // // Q_audio + Q15 - Q15 -> Q_audio + t_audio_fx[tmp + k] = add( tmp2, tmp3 ); // Q_audio move16(); } /*incr = (incr == 0) ? sub(pos_start, 1) : sub(incr, 1); */ diff --git a/lib_com/swb_bwe_com_lr_fx.c b/lib_com/swb_bwe_com_lr_fx.c index c9b4a27fa..1e7112a02 100644 --- a/lib_com/swb_bwe_com_lr_fx.c +++ b/lib_com/swb_bwe_com_lr_fx.c @@ -2585,8 +2585,9 @@ void Gettonl_scalfact_fx( IF( L_est_ton_ene[k_fx] <= 0x0L ) { /* 1.0 */ - L_est_ton_ene[k_fx] = L_deposit_l( 32767 ); + L_est_ton_ene[k_fx] = L_deposit_l( MAX_16 ); QetEne = 15; + move16(); } /*ton_sf= (float) sqrt(be_tonal[band_pos]/est_ton_ene[k]);*/ /* be_tonal: QbeL, est_ton_ene: (Qss-exp_safe)*2+1 */ @@ -3473,6 +3474,8 @@ void updat_prev_frm_fx( } } + test(); + test(); IF( ( EQ_32( L_bwe_br, HQ_16k40 ) || EQ_32( L_bwe_br, HQ_13k20 ) ) && EQ_16( bwidth_fx, SWB ) ) { *prev_hqswb_clas = hqswb_clas_fx; diff --git a/lib_com/swb_tbe_com.c b/lib_com/swb_tbe_com.c index ddb28532a..18e5b1f2a 100644 --- a/lib_com/swb_tbe_com.c +++ b/lib_com/swb_tbe_com.c @@ -1242,11 +1242,11 @@ void GenSHBSynth_fx_32( // shb_syn_speech_32k[i] = ( ( i % 2 ) == 0 ) ? ( -speech_buf_32k[i] ) : ( speech_buf_32k[i] ); IF( i % 2 == 0 ) { - shb_syn_speech_32k[i] = L_negate( speech_buf_32k[i] ); + shb_syn_speech_32k[i] = L_negate( speech_buf_32k[i] ); // Qx } ELSE { - shb_syn_speech_32k[i] = speech_buf_32k[i]; + shb_syn_speech_32k[i] = speech_buf_32k[i]; // Qx } move32(); } @@ -1412,9 +1412,9 @@ void ScaleShapedSHB_32( FOR( k = 0; k < shr( length, 1 ); k++ ) { sum_gain_fx = mult_r( subwin_fx[2 * k + 2], subgain_fx[0] ); - mod_syn_fx[add( skip[0], k )] = Mpy_32_16_1( synSHB_fx[add( skip[0], k )], sum_gain_fx ); - move32(); // Qx - mod_syn_fx[add( add( skip[0], k ), shr( length, 1 ) )] = Mpy_32_16_1( synSHB_fx[add( add( skip[0], k ), shr( length, 1 ) )], subgain_fx[0] ); // Qx + mod_syn_fx[skip[0] + k] = Mpy_32_16_1( synSHB_fx[skip[0] + k], sum_gain_fx ); + move32(); // Qx + mod_syn_fx[skip[0] + k + length / 2] = Mpy_32_16_1( synSHB_fx[skip[0] + k + length / 2], subgain_fx[0] ); // Qx move32(); } FOR( i = 1; i < NUM_SHB_SUBFR / 2; i++ ) @@ -1423,14 +1423,14 @@ void ScaleShapedSHB_32( { L_tmp = L_mult0( subwin_fx[k + 1], subgain_fx[i] ); sum_gain_fx = round_fx( L_mac0( L_tmp, subwin_fx[length - k - 1], subgain_fx[i - 1] ) ); - mod_syn_fx[add( skip[i], k )] = L_shl( Mpy_32_16_1( synSHB_fx[add( skip[i], k )], sum_gain_fx ), 1 ); // Qx + mod_syn_fx[skip[i] + k] = L_shl( Mpy_32_16_1( synSHB_fx[skip[i] + k], sum_gain_fx ), 1 ); // Qx move32(); } } FOR( k = 0; k < shr( length, 1 ); k++ ) { - sum_gain_fx = mult_r( subwin_fx[sub( sub( length, shl( k, 1 ) ), 2 )], subgain_fx[i - 1] ); - mod_syn_fx[add( skip[i], k )] = Mpy_32_16_1( synSHB_fx[add( skip[i], k )], sum_gain_fx ); // Qx + sum_gain_fx = mult_r( subwin_fx[length - k * 2 - 2], subgain_fx[i - 1] ); + mod_syn_fx[skip[i] + k] = Mpy_32_16_1( synSHB_fx[skip[i] + k], sum_gain_fx ); // Qx move32(); } } @@ -1451,15 +1451,15 @@ void ScaleShapedSHB_32( { FOR( k = 0; k < join_length - length; k++ ) { - mod_syn_fx[j] = Mpy_32_16_1( synSHB_fx[j], subgain_fx[i_mult( i, num_join )] ); // Qx + mod_syn_fx[j] = Mpy_32_16_1( synSHB_fx[j], subgain_fx[i * num_join] ); // Qx move32(); j = add( j, 1 ); } FOR( k = 0; k < length; k++ ) { - L_tmp = L_mult0( subwin_fx[length - k - 1], subgain_fx[i_mult( i, num_join )] ); - mod_syn_fx[j] = L_shl( Mpy_32_16_1( synSHB_fx[j], round_fx( L_mac0( L_tmp, subwin_fx[k + 1], subgain_fx[i_mult( ( i + 1 ), num_join )] ) ) ), 1 ); // Qx + L_tmp = L_mult0( subwin_fx[length - k - 1], subgain_fx[i * num_join] ); + mod_syn_fx[j] = L_shl( Mpy_32_16_1( synSHB_fx[j], round_fx( L_mac0( L_tmp, subwin_fx[k + 1], subgain_fx[( i + 1 ) * num_join] ) ) ), 1 ); // Qx move32(); j = add( j, 1 ); } @@ -1472,7 +1472,7 @@ void ScaleShapedSHB_32( } FOR( k = 0; k < length; k++ ) { - mod_syn_fx[j] = Mpy_32_16_1( synSHB_fx[j], mult_r( subwin_fx[sub( sub( length, k ), 1 )], subgain_fx[( NUM_SHB_SUBGAINS - 1 ) * num_join] ) ); // Qx + mod_syn_fx[j] = Mpy_32_16_1( synSHB_fx[j], mult_r( subwin_fx[length - k - 1], subgain_fx[( NUM_SHB_SUBGAINS - 1 ) * num_join] ) ); // Qx move32(); j = add( j, 1 ); } diff --git a/lib_com/swb_tbe_com_fx.c b/lib_com/swb_tbe_com_fx.c index aa4a1e2be..95421581d 100644 --- a/lib_com/swb_tbe_com_fx.c +++ b/lib_com/swb_tbe_com_fx.c @@ -131,8 +131,8 @@ void fb_tbe_reset_synth_fx( *-------------------------------------------------------------------*/ Word16 tbe_celp_exc_offset( - const Word16 T0_fx, /* i : Integer pitch */ - const Word16 T0_frac_fx, /* i : Fractional part of the pitch */ + const Word16 T0_fx, /* i : Integer pitch Q0 */ + const Word16 T0_frac_fx, /* i : Fractional part of the pitch Q1 */ const Word16 L_frame /* i : frame lenght */ ) { @@ -168,12 +168,12 @@ Word16 tbe_celp_exc_offset( * Compute tbe bwe celp excitation *-------------------------------------------------------------------*/ void tbe_celp_exc( - const Word16 L_frame_fx, /* i : Frame lenght */ - const Word16 i_subfr_fx, /* i : sub frame */ - const Word16 T0_fx, /* i : Integer pitch */ - const Word16 T0_frac_fx, /* i : Fractional part of the pitch */ - Word16 *error_fx, /* i/o: Error */ - Word16 *bwe_exc_fx /* i/o: bandwitdh extension signal */ + const Word16 L_frame_fx, /* i : Frame lenght */ + const Word16 i_subfr_fx, /* i : sub frame */ + const Word16 T0_fx, /* i : Integer pitch Q0 */ + const Word16 T0_frac_fx, /* i : Fractional part of the pitch Q1 */ + Word16 *error_fx, /* i/o: Error Q5 */ + Word16 *bwe_exc_fx /* i/o: bandwitdh extension signal */ ) { Word16 offset_fx, tmp_fx, i; @@ -198,7 +198,7 @@ void tbe_celp_exc( FOR( i = 0; i < L_SUBFR * HIBND_ACB_L_FAC; i++ ) { - bwe_exc_fx[i + i_subfr_fx * HIBND_ACB_L_FAC] = bwe_exc_fx[i + i_subfr_fx * HIBND_ACB_L_FAC - offset_fx + tmp_fx]; + bwe_exc_fx[i + i_subfr_fx * HIBND_ACB_L_FAC] = bwe_exc_fx[i + i_subfr_fx * HIBND_ACB_L_FAC - offset_fx + tmp_fx]; // Qx move16(); } tmp_fx = extract_l( L_mult( T0_frac_fx, 1 ) ); /*Q3; 0.25 in Q2*/ @@ -226,7 +226,7 @@ void tbe_celp_exc( FOR( i = 0; i < L_SUBFR * 2; i++ ) { - bwe_exc_fx[i + i_subfr_fx * 2] = bwe_exc_fx[i + i_subfr_fx * 2 - offset_fx + tmp_fx]; + bwe_exc_fx[i + i_subfr_fx * 2] = bwe_exc_fx[i + i_subfr_fx * 2 - offset_fx + tmp_fx]; // Qx move16(); } @@ -246,21 +246,23 @@ void tbe_celp_exc( * Compute tbe bwe celp excitation *-------------------------------------------------------------------*/ void tbe_celp_exc_ivas( - const int16_t element_mode, /* i : element mode */ - const int16_t idchan, /* i : channel ID */ - const Word16 L_frame_fx, /* i : Frame lenght */ - const int16_t L_subfr, /* i : subframe length */ - const Word16 i_subfr_fx, /* i : sub frame */ - const Word16 T0_fx, /* i : Integer pitch */ - const Word16 T0_frac_fx, /* i : Fractional part of the pitch */ - Word16 *error_fx, /* i/o: Error */ - Word16 *bwe_exc_fx, /* i/o: bandwitdh extension signal */ - const int16_t tdm_LRTD_flag /* i : LRTD stereo mode flag */ + const Word16 element_mode, /* i : element mode */ + const Word16 idchan, /* i : channel ID */ + const Word16 L_frame_fx, /* i : Frame lenght */ + const Word16 L_subfr, /* i : subframe length */ + const Word16 i_subfr_fx, /* i : sub frame */ + const Word16 T0_fx, /* i : Integer pitch Q0 */ + const Word16 T0_frac_fx, /* i : Fractional part of the pitch Q1 */ + Word16 *error_fx, /* i/o: Error Q5 */ + Word16 *bwe_exc_fx, /* i/o: bandwitdh extension signal Qx */ + const Word16 tdm_LRTD_flag /* i : LRTD stereo mode flag */ ) { Word16 offset_fx, tmp_fx, i; - if ( element_mode == IVAS_CPE_TD && idchan == 1 && !tdm_LRTD_flag ) + test(); + test(); + IF( EQ_16( element_mode, IVAS_CPE_TD ) && EQ_16( idchan, 1 ) && !tdm_LRTD_flag ) { return; } @@ -584,7 +586,7 @@ void flip_and_downmix_generic_fx_32( Copy32( tmp_R + length, mem2_ext + HILBERT_ORDER2, HILBERT_ORDER2 ); Copy32( tmp_I + length, mem3_ext + HILBERT_ORDER2, HILBERT_ORDER2 ); - if ( *phase_state >= period ) + if ( GE_16( *phase_state, period ) ) { *phase_state = 0; move16(); @@ -595,18 +597,20 @@ void flip_and_downmix_generic_fx_32( j = *phase_state; move16(); - WHILE( i < length ) + WHILE( LT_16( i, length ) ) { WHILE( ( j < period ) && ( i < length ) ) { + test(); L_tmp = Mult_32_16( tmp_R[i + 4], local_cos_table[j] ); /*//Qx+16 */ L_tmp = Madd_32_16( L_tmp, tmp_I[i + 4], local_negsin_table[j] ); /*Qx+16 */ output[i] = L_tmp; /*Qx */ + move32(); i++; j++; } - if ( j >= period ) + if ( GE_16( j, period ) ) { j = 0; move16(); @@ -633,7 +637,7 @@ static void Hilbert_transform_fx( Word16 i, hb_filter_stage, offset; Word32 L_tmp; - hb_filter_stage = 2 * HB_stage_id; + hb_filter_stage = shl( HB_stage_id, 1 ); offset = 0; move16(); if ( HB_stage_id == 0 ) @@ -644,7 +648,7 @@ static void Hilbert_transform_fx( test(); test(); - IF( HB_stage_id == 0 || HB_stage_id == 2 ) + IF( HB_stage_id == 0 || EQ_16( HB_stage_id, 2 ) ) { FOR( i = 0; i < length; i++ ) { @@ -661,7 +665,7 @@ static void Hilbert_transform_fx( move32(); /*Qx+16 */ } } - ELSE IF( HB_stage_id == 1 || HB_stage_id == 3 ) + ELSE IF( EQ_16( HB_stage_id, 1 ) || EQ_16( HB_stage_id, 3 ) ) { FOR( i = 0; i < length; i++ ) { @@ -788,7 +792,7 @@ void Calc_rc0_h( acf1 = extract_h( L_acc ); /* Compute 1st parcor */ - if ( acf0 == 0 ) + IF( acf0 == 0 ) { *rc0 = 0; move16(); @@ -803,7 +807,7 @@ void Calc_rc0_h( } *rc0 = div_s( abs_s( acf1 ), acf0 ); move16(); - if ( acf1 > 0 ) + IF( acf1 > 0 ) { *rc0 = negate( *rc0 ); move16(); @@ -1125,7 +1129,7 @@ void flip_spectrum_and_decimby4_fx( } Decimate_allpass_steep_fx( input_change, mem1, length, tmp ); - Decimate_allpass_steep_fx( tmp, mem2, length / 2, output ); + Decimate_allpass_steep_fx( tmp, mem2, shr( length, 1 ), output ); return; } @@ -1204,13 +1208,14 @@ void ivas_GenShapedWBExcitation_fx( Word16 avg_voice_fac; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move16(); #endif /*0.25f*sum_f(voice_factors, NB_SUBFR)*/ - L_tmp = L_mult( voice_factors[0], 8192 ); + L_tmp = L_mult( voice_factors[0], 8192 /* 0.25 in Q15 */ ); FOR( i = 1; i < NB_SUBFR; i++ ) { - L_tmp = L_mac( L_tmp, voice_factors[i], 8192 ); + L_tmp = L_mac( L_tmp, voice_factors[i], 8192 /* 0.25 in Q15 */ ); } avg_voice_fac = round_fx( L_tmp ); @@ -1218,14 +1223,14 @@ void ivas_GenShapedWBExcitation_fx( test(); test(); test(); - IF( igf_flag != 0 && ( EQ_16( coder_type, VOICED ) || GT_16( avg_voice_fac, 11469 ) ) ) /*Q15 -> 0.35f*/ + IF( igf_flag != 0 && ( EQ_16( coder_type, VOICED ) || GT_16( avg_voice_fac, 11469 /* 0.35 in Q15 */ ) ) ) /*Q15 -> 0.35f*/ { csfilt_num2[0] = 6554; move16(); /*Q15 -> 0.2f*/ neg_csfilt_den2[1] = 26214; move16(); /*Q15 -> 0.8f*/ } - ELSE IF( igf_flag != 0 && ( EQ_16( coder_type, UNVOICED ) || LT_16( avg_voice_fac, 6654 ) ) ) /*Q15 -> 0.2f*/ + ELSE IF( igf_flag != 0 && ( EQ_16( coder_type, UNVOICED ) || LT_16( avg_voice_fac, 6654 /* 0.2 in Q15*/ ) ) ) /*Q15 -> 0.2f*/ { csfilt_num2[0] = 328; move16(); /*Q15 -> 0.01f*/ @@ -1375,7 +1380,7 @@ void ivas_GenShapedWBExcitation_fx( test(); test(); - IF( EQ_16( coder_type, UNVOICED ) || ( igf_flag != 0 && LT_16( avg_voice_fac, 6654 ) ) ) + IF( EQ_16( coder_type, UNVOICED ) || ( igf_flag != 0 && LT_16( avg_voice_fac, 6654 /* 0.2 in Q15 */ ) ) ) { L_tmp = root_a_over_b_fx( pow1, sub( 19, shl( n1, 1 ) ), pow22, sub( 19, shl( n2, 1 ) ), &exp ); #ifdef BASOP_NOGLOB @@ -1506,10 +1511,10 @@ void GenShapedWBExcitation_fx( move16(); /*0.25f*sum_f(voice_factors, NB_SUBFR)*/ - L_tmp = L_mult( voice_factors[0], 8192 ); + L_tmp = L_mult( voice_factors[0], 8192 /*0.25 in Q15 */ ); FOR( i = 1; i < NB_SUBFR; i++ ) { - L_tmp = L_mac( L_tmp, voice_factors[i], 8192 ); + L_tmp = L_mac( L_tmp, voice_factors[i], 8192 /*0.25 in Q15 */ ); } avg_voice_fac = round_fx( L_tmp ); @@ -1517,14 +1522,14 @@ void GenShapedWBExcitation_fx( test(); test(); test(); - IF( igf_flag != 0 && ( EQ_16( coder_type, VOICED ) || GT_16( avg_voice_fac, 11469 ) ) ) /*Q15 -> 0.35f*/ + IF( igf_flag != 0 && ( EQ_16( coder_type, VOICED ) || GT_16( avg_voice_fac, 11469 /* 0.35 in Q15 */ ) ) ) /*Q15 -> 0.35f*/ { csfilt_num2[0] = 6554; move16(); /*Q15 -> 0.2f*/ neg_csfilt_den2[1] = 26214; move16(); /*Q15 -> 0.8f*/ } - ELSE IF( igf_flag != 0 && ( EQ_16( coder_type, UNVOICED ) || LT_16( avg_voice_fac, 6654 ) ) ) /*Q15 -> 0.2f*/ + ELSE IF( igf_flag != 0 && ( EQ_16( coder_type, UNVOICED ) || LT_16( avg_voice_fac, 6654 /* 0.2 in Q15 */ ) ) ) /*Q15 -> 0.2f*/ { csfilt_num2[0] = 328; move16(); /*Q15 -> 0.01f*/ @@ -1674,7 +1679,7 @@ void GenShapedWBExcitation_fx( test(); test(); - IF( EQ_16( coder_type, UNVOICED ) || ( igf_flag != 0 && LT_16( avg_voice_fac, 6654 ) ) ) + IF( EQ_16( coder_type, UNVOICED ) || ( igf_flag != 0 && LT_16( avg_voice_fac, 6654 /*0.2 in Q15 */ ) ) ) { L_tmp = root_a_over_b_fx( pow1, sub( 22, shl( n1, 1 ) ), pow22, sub( 22, shl( n2, 1 ) ), &exp ); #ifdef BASOP_NOGLOB @@ -1802,9 +1807,9 @@ void GenWBSynth_fx( Interpolate_allpass_steep_fx( speech_buf_16k1, state_lsyn_filt_shb2, L_FRAME16k / 2, speech_buf_16k2 ); flip_spectrum_fx( speech_buf_16k2, shb_syn_speech_16k, L_FRAME16k ); - Scale_sig( shb_syn_speech_16k, L_FRAME16k, -nor ); - Scale_sig( state_lsyn_filt_shb1, 2 * ALLPASSSECTIONS_STEEP, -nor ); - Scale_sig( state_lsyn_filt_shb2, 2 * ALLPASSSECTIONS_STEEP, -nor ); + Scale_sig( shb_syn_speech_16k, L_FRAME16k, negate( nor ) ); + Scale_sig( state_lsyn_filt_shb1, 2 * ALLPASSSECTIONS_STEEP, negate( nor ) ); + Scale_sig( state_lsyn_filt_shb2, 2 * ALLPASSSECTIONS_STEEP, negate( nor ) ); return; } @@ -2694,6 +2699,7 @@ void GenShapedSHBExcitation_fx( { L_tmp3 = Mult_32_16( L_tmp2, exc16kWhtnd[i] ); /* *Q_bwe_exc + (31-exp) - 15 */ exc16kWhtnd[i] = round_fx( L_tmp3 ); /* *Q_bwe_exc - exp */ + move16(); } } /* i: L_tmp2 in (Q31-exp) */ @@ -2845,6 +2851,8 @@ void GenShapedSHBExcitation_ivas_fx( Word16 chk1, chk2; chk1 = 0; chk2 = 0; + move16(); + move16(); #if 1 // def ADD_IVAS_TBE_CODE Word16 alpha, step, mem_csfilt_left, mem_csfilt_right, excNoisyEnvLeft[L_FRAME16k], excNoisyEnvRight[L_FRAME16k]; @@ -2939,28 +2947,29 @@ void GenShapedSHBExcitation_ivas_fx( } Q_pow1 = shl( *Q_bwe_exc, 1 ); + test(); +#if 1 // ADD_IVAS_TBE_CODE IF( flag_ACELP16k == 0 ) +#else + IF( ( LE_32( bitrate, ACELP_13k20 ) ) && ( GE_32( bitrate, ACELP_7k20 ) ) ) +#endif { /* varEnvShape = mean_fx(voice_factors, 4); */ /* unroll the loop */ - L_tmp = L_mult( voice_factors[0], 8192 ); - L_tmp = L_mac( L_tmp, voice_factors[1], 8192 ); - L_tmp = L_mac( L_tmp, voice_factors[2], 8192 ); - varEnvShape = mac_r_sat( L_tmp, voice_factors[3], 8192 ); /* varEnvShape in Q15 */ - /* varEnvShape is the mean value of voice_factors (Q15) - In any case, varEnvShape is not expected to exceed 32767, hence saturation is added */ + L_tmp = L_mult( voice_factors[0], 8192 /*0.25 in Q15 */ ); + L_tmp = L_mac( L_tmp, voice_factors[1], 8192 /*0.25 in Q15 */ ); + L_tmp = L_mac( L_tmp, voice_factors[2], 8192 /*0.25 in Q15 */ ); + varEnvShape = mac_r( L_tmp, voice_factors[3], 8192 /*0.25 in Q15 */ ); /* varEnvShape in Q15 */ } ELSE /* 16k core */ { /* varEnvShape = mean_fx(voice_factors, 5); */ /* unroll the loop */ - L_tmp = L_mult( voice_factors[0], 6554 ); - L_tmp = L_mac( L_tmp, voice_factors[1], 6554 ); - L_tmp = L_mac( L_tmp, voice_factors[2], 6554 ); - L_tmp = L_mac( L_tmp, voice_factors[3], 6554 ); - varEnvShape = mac_r_sat( L_tmp, voice_factors[4], 6554 ); /* varEnvShape in Q15 */ - /* varEnvShape is the mean value of voice_factors (Q15) - In any case, varEnvShape is not expected to exceed 32767, hence saturation is added */ + L_tmp = L_mult( voice_factors[0], 6554 /*0.2 in Q15 */ ); + L_tmp = L_mac( L_tmp, voice_factors[1], 6554 /*0.2 in Q15 */ ); + L_tmp = L_mac( L_tmp, voice_factors[2], 6554 /*0.2 in Q15 */ ); + L_tmp = L_mac( L_tmp, voice_factors[3], 6554 /*0.2 in Q15 */ ); + varEnvShape = mac_r( L_tmp, voice_factors[4], 6554 /*0.2 in Q15 */ ); /* varEnvShape in Q15 */ } IF( EQ_16( extl, FB_TBE ) ) @@ -2990,6 +2999,7 @@ void GenShapedSHBExcitation_ivas_fx( test(); test(); #if 1 // def ADD_IVAS_TBE_CODE + test(); IF( EQ_16( element_mode, EVS_MONO ) && *mem_csfilt == 0 && ( ( EQ_32( bitrate, ACELP_9k60 ) ) || ( EQ_32( bitrate, ACELP_16k40 ) ) || ( EQ_32( bitrate, ACELP_24k40 ) ) ) ) #else IF( *mem_csfilt == 0 && ( ( EQ_32( bitrate, ACELP_9k60 ) ) || ( EQ_32( bitrate, ACELP_16k40 ) ) || ( EQ_32( bitrate, ACELP_24k40 ) ) ) ) @@ -3042,9 +3052,10 @@ void GenShapedSHBExcitation_ivas_fx( } test(); /* Track the low band envelope */ - IF( element_mode == IVAS_CPE_TD || element_mode == IVAS_CPE_DFT ) + IF( EQ_16( element_mode, IVAS_CPE_TD ) || EQ_16( element_mode, IVAS_CPE_DFT ) ) { - IF( extl_brate != SWB_TBE_1k10 && extl_brate != SWB_TBE_1k75 ) + test(); + IF( NE_32( extl_brate, SWB_TBE_1k10 ) && NE_32( extl_brate, SWB_TBE_1k75 ) ) { mem_csfilt_left = 0; mem_csfilt_right = 0; @@ -3137,9 +3148,9 @@ void GenShapedSHBExcitation_ivas_fx( { White_exc16k_32[k] = Mpy_32_16_1( temp_pow, White_exc16k[k] ); move32(); - White_exc16k[k] = round_fx( L_shl( White_exc16k_32[k], *Q_bwe_exc - NOISE_QADJ ) ); // Q_bwe_exc - NOISE_QADJ + White_exc16k[k] = round_fx( L_shl( White_exc16k_32[k], sub( *Q_bwe_exc, NOISE_QADJ ) ) ); // Q_bwe_exc - NOISE_QADJ move16(); - L_tmp = max( L_tmp, L_abs( White_exc16k_32[k] ) ); + L_tmp = L_max( L_tmp, L_abs( White_exc16k_32[k] ) ); } Q_temp = norm_l( L_tmp ); IF( L_tmp == 0 ) @@ -3468,6 +3479,7 @@ void GenShapedSHBExcitation_ivas_fx( } } #if 1 // def ADD_IVAS_TBE_CODE + test(); IF( NE_32( extl_brate, SWB_TBE_1k10 ) && NE_32( extl_brate, SWB_TBE_1k75 ) ) #endif { @@ -3484,6 +3496,7 @@ void GenShapedSHBExcitation_ivas_fx( } } #if 1 // def ADD_IVAS_TBE_CODE + test(); IF( GE_16( element_mode, IVAS_CPE_DFT ) && nlExc16k != NULL ) { /* save buffers for IC-BWE */ @@ -3578,7 +3591,8 @@ void GenShapedSHBExcitation_ivas_fx( #endif { #if 1 // def ADD_IVAS_TBE_CODE - IF( coder_type == UNVOICED || MSFlag == 1 ) + test(); + IF( EQ_16( coder_type, UNVOICED ) || EQ_16( MSFlag, 1 ) ) #else IF( EQ_16( coder_type, UNVOICED ) ) #endif @@ -3696,7 +3710,7 @@ void GenShapedSHBExcitation_ivas_fx( exp = 0; move16(); temp = Sqrt16( tempQ15, &exp ); - temp = shl( temp, exp - 1 ); + temp = shl( temp, sub( exp, 1 ) ); temp2 = add( temp, shl( temp1, -1 ) ); /* shift right by 1 to avoid overflow */ temp = div_s( temp, temp2 ); /* Q15 */ @@ -3920,7 +3934,7 @@ void GenSHBSynth_fx( Scale_sig32( Hilbert_Mem, HILBERT_MEM_SIZE, shift ); Interpolate_allpass_steep_fx( input_synspeech_temp, allpass_mem, L_FRAME16k, speech_buf_32k ); /*modify_Fs_fx( input_synspeech, L_FRAME16k, 16000, speech_buf_32k, 32000, allpass_mem, 0);*/ - IF( L_frame == L_FRAME ) + IF( EQ_16( L_frame, L_FRAME ) ) { /* 12.8 k core flipping and downmixing */ flip_and_downmix_generic_fx( speech_buf_32k, shb_syn_speech_32k, L_FRAME32k, @@ -3941,9 +3955,9 @@ void GenSHBSynth_fx( } } - Scale_sig( shb_syn_speech_32k, L_FRAME32k, -shift ); - Scale_sig( allpass_mem, 2 * ALLPASSSECTIONS_STEEP, -shift ); - Scale_sig32( Hilbert_Mem, HILBERT_MEM_SIZE, -shift ); + Scale_sig( shb_syn_speech_32k, L_FRAME32k, negate( shift ) ); + Scale_sig( allpass_mem, 2 * ALLPASSSECTIONS_STEEP, negate( shift ) ); + Scale_sig32( Hilbert_Mem, HILBERT_MEM_SIZE, negate( shift ) ); return; } @@ -4258,6 +4272,7 @@ void ScaleShapedWB_fx( move16(); join_length = i_mult2( num_join, length ); j = 0; /* ptr*/ + move16(); FOR( k = 0; k < length; k++ ) { sum_gain = mult_r( subwin[k + 1], subgain[0] ); /* Q15 */ @@ -4277,8 +4292,8 @@ void ScaleShapedWB_fx( FOR( k = 0; k < length; k++ ) { - L_tmp = L_mult0( subwin[k + 1], subgain[i_mult2( ( i + 1 ), num_join )] ); /* Q30 */ - sum_gain = round_fx( L_mac0( L_tmp, subwin[length - k - 1], subgain[i_mult2( i, num_join )] ) ); /*Q14 */ + L_tmp = L_mult0( subwin[k + 1], subgain[i_mult2( ( i + 1 ), num_join )] ); /* Q30 */ + sum_gain = round_fx( L_mac0( L_tmp, subwin[length - k - 1], subgain[i * num_join] ) ); /*Q14 */ mod_syn[j] = L_shl( L_mult( sum_gain, synSHB[j] ), 1 ); move32(); /* Q_bwe_exc + 16 */ j++; @@ -4339,12 +4354,12 @@ void ScaleShapedWB_fx( /* Qx = (Q_bwe_exc+3) + shift - 16 */ /* make sure 14 > Qx > 2 */ - min_shift = 2 - ( Q_bwe_exc + 3 - 16 ); - max_shift = 13 - ( Q_bwe_exc + 3 - 16 ); + min_shift = sub( 2, sub( add( Q_bwe_exc, 3 ), 16 ) ); + max_shift = sub( 13, sub( add( Q_bwe_exc, 3 ), 16 ) ); max_shift2 = s_min( max_shift, max_headroom ); /* avoid shifting more than the available max_val headroom to avoid overflow */ shift = s_min( min_shift, max_shift2 ); - *Qx = ( Q_bwe_exc + 3 ) + shift - 16; + *Qx = sub( add( add( Q_bwe_exc, 3 ), shift ), 16 ); move16(); } ELSE /* 16k core */ @@ -4353,21 +4368,21 @@ void ScaleShapedWB_fx( /* Qx = (Q_bwe_exc+3) + shift - 16 */ /* make sure 14 > Qx > 3 */ - min_shift = 3 - ( Q_bwe_exc + 3 - 16 ); + min_shift = sub( 3, sub( add( Q_bwe_exc, 3 ), 16 ) ); move16(); - max_shift = 13 - ( Q_bwe_exc + 3 - 16 ); + max_shift = sub( 13, sub( add( Q_bwe_exc, 3 ), 16 ) ); move16(); max_shift2 = s_min( max_shift, max_headroom ); /* avoid shifting more than the available max_val headroom to avoid overflow */ shift = s_min( min_shift, max_shift2 ); - *Qx = ( Q_bwe_exc + 3 ) + shift - 16; + *Qx = sub( add( add( Q_bwe_exc, 3 ), shift ), 16 ); move16(); } /* bring memory st_fx->syn_overlap_fx[] = overlap[i] to new Q = Qx to prepare for addition */ FOR( i = 0; i < l_shb_lahead; i++ ) { - overlap[i] = shl( overlap[i], ( *Qx - prev_Qx ) ); + overlap[i] = shl( overlap[i], sub( *Qx, prev_Qx ) ); move16(); } @@ -4381,6 +4396,7 @@ void ScaleShapedWB_fx( synSHB[i] = add_sat( synSHB[i], overlap[i] ); move16(); /* Qx */ synSHB[i + l_shb_lahead] = round_fx_sat( L_shl_sat( L_tmp, shift ) ); /* Qx */ + move16(); #else synSHB[i] = round_fx( L_shl( Mult_32_16( L_tmp, win[i] ), shift ) ); /* Qx */ synSHB[i] = add( synSHB[i], overlap[i] ); @@ -4533,7 +4549,7 @@ static Word32 non_linearity_scaled_copy_ivas( test(); test(); - IF( input[i] != 0 && prev_scale != 0 && L_tmp == 0 ) + if ( input[i] != 0 && prev_scale != 0 && L_tmp == 0 ) { /* NOTE: this is done to avoid the product to become zero for small non-zero input */ L_tmp = 1; @@ -4553,7 +4569,7 @@ static Word32 non_linearity_scaled_copy_ivas( test(); test(); - IF( input[i] != 0 && prev_scale != 0 && L_tmp == 0 ) + if ( input[i] != 0 && prev_scale != 0 && L_tmp == 0 ) { /* NOTE: this is done to avoid the product to become zero for small non-zero input */ L_tmp = 1; @@ -4572,7 +4588,7 @@ static Word32 non_linearity_scaled_copy_ivas( test(); test(); - IF( input[i] != 0 && prev_scale != 0 && L_tmp == 0 ) + if ( input[i] != 0 && prev_scale != 0 && L_tmp == 0 ) { /* NOTE: this is done to avoid the product to become zero for small non-zero input */ L_tmp = 1; @@ -4600,7 +4616,7 @@ static Word32 non_linearity_scaled_copy_ivas( L_tmp = Mult_32_32( L_tmp, prev_scale ); /* 2*Q_inp */ test(); test(); - IF( input[i] != 0 && prev_scale != 0 && L_tmp == 0 ) + if ( input[i] != 0 && prev_scale != 0 && L_tmp == 0 ) { /* NOTE: this is done to avoid the product to become zero for small non-zero input */ L_tmp = 1; @@ -4654,6 +4670,7 @@ void non_linearity_fx( { Word16 i, j; Word16 max_val = 0; + move16(); Word32 scale; Word16 scale_step; Word16 exp, tmp; @@ -4664,6 +4681,8 @@ void non_linearity_fx( Word16 en_abs = 0; Word16 v_fac = 0; + move16(); + move16(); Word16 ths; Word16 nframes; Word32 prev_scale; @@ -4754,13 +4773,13 @@ void non_linearity_fx( e_tmp = norm_l( scale ); f_tmp = Log2_norm_lc( L_shl( scale, e_tmp ) ); e_tmp = sub( -1, e_tmp ); - L_tmp = Mpy_32_16( e_tmp, f_tmp, 32767 ); /* Q16 */ + L_tmp = Mpy_32_16( e_tmp, f_tmp, MAX_16 ); /* Q16 */ /* Computing log2(prev_scale) */ e_tmp = norm_l( prev_scale ); f_tmp = Log2_norm_lc( L_shl( prev_scale, e_tmp ) ); e_tmp = negate( e_tmp ); - L_tmp1 = Mpy_32_16( e_tmp, f_tmp, 32767 ); /* Q16 */ + L_tmp1 = Mpy_32_16( e_tmp, f_tmp, MAX_16 ); /* Q16 */ /* log2(scale / prev_scale) = log2(scale) - log2(prev_scale) */ L_tmp = L_sub( L_tmp, L_tmp1 ); /* Q16 */ @@ -4808,7 +4827,7 @@ void non_linearity_fx( exp = norm_s( max_val ); tmp = div_s( shl( 1, sub( 14, exp ) ), max_val ); /* Q(29-exp-Q_inp) */ #ifdef BASOP_NOGLOB - scale = L_shl_o( L_mult( 21955, tmp ), add( exp, sub( Q_inp, 14 ) ), &Overflow ); /* Q31 */ + scale = L_shl_o( L_mult( 21955 /* 0.67 in Q15 */, tmp ), add( exp, sub( Q_inp, 14 ) ), &Overflow ); /* Q31 */ #else scale = L_shl( L_mult( 21955, tmp ), add( exp, sub( Q_inp, 14 ) ) ); /* Q31 */ #endif @@ -4923,6 +4942,7 @@ void non_linearity_ivas_fx( { Word16 i, j; Word16 max_val = 0; + move16(); Word32 scale; Word16 scale_step; Word16 exp, tmp; @@ -4933,12 +4953,15 @@ void non_linearity_ivas_fx( Word16 en_abs = 0; Word16 v_fac = 0; + move16(); + move16(); Word16 ths; Word16 nframes; Word32 prev_scale; Word16 length_half; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif @@ -5514,34 +5537,34 @@ void elliptic_bpf_48k_generic_fx( FOR( i = 4; i < L_FRAME48k; i++ ) { #ifdef BASOP_NOGLOB - L_tmpX = L_shr( L_mult( input_fx[sub( i, 4 )], full_band_bpf_fx[0][4] ), 3 ); /*Q_input_fx + 13 + 1 - 3*/ - L_tmpX = L_add_sat( L_shr( L_mult( input_fx[sub( i, 3 )], full_band_bpf_fx[0][3] ), 3 ), L_tmpX ); /*Q_input_fx + 13 + 1 - 3*/ - L_tmpX = L_sub_sat( L_tmpX, L_shl_sat( Mult_32_16( L_tmp[sub( i, 1 )], full_band_bpf_fx[3][1] ), 2 ) ); /*Q_input_fx + 11 + 13 -15 +2*/ - L_tmpX = L_add_sat( L_shr( L_mult( input_fx[sub( i, 2 )], full_band_bpf_fx[0][2] ), 3 ), L_tmpX ); /*Q_input_fx + 13 + 1 - 3*/ - L_tmpX = L_sub_sat( L_tmpX, L_shl_sat( Mult_32_16( L_tmp[sub( i, 2 )], full_band_bpf_fx[3][2] ), 2 ) ); /*Q_input_fx + 11 + 13 -15 +2*/ - L_tmpX = L_add_sat( L_shr( L_mult( input_fx[sub( i, 1 )], full_band_bpf_fx[0][1] ), 3 ), L_tmpX ); /*Q_input_fx + 13 + 1 - 3*/ - L_tmpX = L_sub_sat( L_tmpX, L_shl_sat( Mult_32_16( L_tmp[sub( i, 3 )], full_band_bpf_fx[3][3] ), 2 ) ); /*Q_input_fx + 11 + 13 -15 +2*/ - L_tmpX = L_add_sat( L_shr( L_mult( input_fx[i], full_band_bpf_fx[0][0] ), 3 ), L_tmpX ); /*Q_input_fx + 13 + 1 - 3*/ - L_tmp[i] = L_sub_sat( L_tmpX, L_shl_sat( Mult_32_16( L_tmp[sub( i, 4 )], full_band_bpf_fx[3][4] ), 2 ) ); /*Q_input_fx + 11 + 13 -15 +2*/ + L_tmpX = L_shr( L_mult( input_fx[i - 4], full_band_bpf_fx[0][4] ), 3 ); /*Q_input_fx + 13 + 1 - 3*/ + L_tmpX = L_add_sat( L_shr( L_mult( input_fx[i - 3], full_band_bpf_fx[0][3] ), 3 ), L_tmpX ); /*Q_input_fx + 13 + 1 - 3*/ + L_tmpX = L_sub_sat( L_tmpX, L_shl_sat( Mult_32_16( L_tmp[i - 1], full_band_bpf_fx[3][1] ), 2 ) ); /*Q_input_fx + 11 + 13 -15 +2*/ + L_tmpX = L_add_sat( L_shr( L_mult( input_fx[i - 2], full_band_bpf_fx[0][2] ), 3 ), L_tmpX ); /*Q_input_fx + 13 + 1 - 3*/ + L_tmpX = L_sub_sat( L_tmpX, L_shl_sat( Mult_32_16( L_tmp[i - 2], full_band_bpf_fx[3][2] ), 2 ) ); /*Q_input_fx + 11 + 13 -15 +2*/ + L_tmpX = L_add_sat( L_shr( L_mult( input_fx[i - 1], full_band_bpf_fx[0][1] ), 3 ), L_tmpX ); /*Q_input_fx + 13 + 1 - 3*/ + L_tmpX = L_sub_sat( L_tmpX, L_shl_sat( Mult_32_16( L_tmp[i - 3], full_band_bpf_fx[3][3] ), 2 ) ); /*Q_input_fx + 11 + 13 -15 +2*/ + L_tmpX = L_add_sat( L_shr( L_mult( input_fx[i], full_band_bpf_fx[0][0] ), 3 ), L_tmpX ); /*Q_input_fx + 13 + 1 - 3*/ + L_tmp[i] = L_sub_sat( L_tmpX, L_shl_sat( Mult_32_16( L_tmp[i - 4], full_band_bpf_fx[3][4] ), 2 ) ); /*Q_input_fx + 11 + 13 -15 +2*/ move32(); #else - L_tmpX = L_shr( L_mult( input_fx[sub( i, 4 )], full_band_bpf_fx[0][4] ), 3 ); /*Q_input_fx + 13 + 1 - 3*/ - L_tmpX = L_add( L_shr( L_mult( input_fx[sub( i, 3 )], full_band_bpf_fx[0][3] ), 3 ), L_tmpX ); /*Q_input_fx + 13 + 1 - 3*/ - L_tmpX = L_sub( L_tmpX, L_shl( Mult_32_16( L_tmp[sub( i, 1 )], full_band_bpf_fx[3][1] ), 2 ) ); /*Q_input_fx + 11 + 13 -15 +2*/ - L_tmpX = L_add( L_shr( L_mult( input_fx[sub( i, 2 )], full_band_bpf_fx[0][2] ), 3 ), L_tmpX ); /*Q_input_fx + 13 + 1 - 3*/ - L_tmpX = L_sub( L_tmpX, L_shl( Mult_32_16( L_tmp[sub( i, 2 )], full_band_bpf_fx[3][2] ), 2 ) ); /*Q_input_fx + 11 + 13 -15 +2*/ - L_tmpX = L_add( L_shr( L_mult( input_fx[sub( i, 1 )], full_band_bpf_fx[0][1] ), 3 ), L_tmpX ); /*Q_input_fx + 13 + 1 - 3*/ - L_tmpX = L_sub( L_tmpX, L_shl( Mult_32_16( L_tmp[sub( i, 3 )], full_band_bpf_fx[3][3] ), 2 ) ); /*Q_input_fx + 11 + 13 -15 +2*/ - L_tmpX = L_add( L_shr( L_mult( input_fx[i], full_band_bpf_fx[0][0] ), 3 ), L_tmpX ); /*Q_input_fx + 13 + 1 - 3*/ - L_tmp[i] = L_sub( L_tmpX, L_shl( Mult_32_16( L_tmp[sub( i, 4 )], full_band_bpf_fx[3][4] ), 2 ) ); /*Q_input_fx + 11 + 13 -15 +2*/ + L_tmpX = L_shr( L_mult( input_fx [[i - 4]], full_band_bpf_fx[0][4] ), 3 ); /*Q_input_fx + 13 + 1 - 3*/ + L_tmpX = L_add( L_shr( L_mult( input_fx[i - 3], full_band_bpf_fx[0][3] ), 3 ), L_tmpX ); /*Q_input_fx + 13 + 1 - 3*/ + L_tmpX = L_sub( L_tmpX, L_shl( Mult_32_16( L_tmp[i - 1], full_band_bpf_fx[3][1] ), 2 ) ); /*Q_input_fx + 11 + 13 -15 +2*/ + L_tmpX = L_add( L_shr( L_mult( input_fx[i - 2], full_band_bpf_fx[0][2] ), 3 ), L_tmpX ); /*Q_input_fx + 13 + 1 - 3*/ + L_tmpX = L_sub( L_tmpX, L_shl( Mult_32_16( L_tmp[i - 2], full_band_bpf_fx[3][2] ), 2 ) ); /*Q_input_fx + 11 + 13 -15 +2*/ + L_tmpX = L_add( L_shr( L_mult( input_fx[i - 1], full_band_bpf_fx[0][1] ), 3 ), L_tmpX ); /*Q_input_fx + 13 + 1 - 3*/ + L_tmpX = L_sub( L_tmpX, L_shl( Mult_32_16( L_tmp[i - 3], full_band_bpf_fx[3][3] ), 2 ) ); /*Q_input_fx + 11 + 13 -15 +2*/ + L_tmpX = L_add( L_shr( L_mult( input_fx[i], full_band_bpf_fx[0][0] ), 3 ), L_tmpX ); /*Q_input_fx + 13 + 1 - 3*/ + L_tmp[i] = L_sub( L_tmpX, L_shl( Mult_32_16( L_tmp[i - 4], full_band_bpf_fx[3][4] ), 2 ) ); /*Q_input_fx + 11 + 13 -15 +2*/ move32(); #endif } - memory_fx2[0][0] = input_fx[sub( L_FRAME48k, 4 )]; - memory_fx2[0][1] = input_fx[sub( L_FRAME48k, 3 )]; - memory_fx2[0][2] = input_fx[sub( L_FRAME48k, 2 )]; - memory_fx2[0][3] = input_fx[sub( L_FRAME48k, 1 )]; + memory_fx2[0][0] = input_fx[L_FRAME48k - 4]; + memory_fx2[0][1] = input_fx[L_FRAME48k - 3]; + memory_fx2[0][2] = input_fx[L_FRAME48k - 2]; + memory_fx2[0][3] = input_fx[L_FRAME48k - 1]; move32(); move32(); move32(); @@ -5630,26 +5653,26 @@ void elliptic_bpf_48k_generic_fx( FOR( i = 4; i < L_FRAME48k; i++ ) { #ifdef BASOP_NOGLOB - L_tmpX = L_shr( Mult_32_16( L_tmp[sub( i, 4 )], full_band_bpf_fx[1][4] ), 3 ); /*Q_input_fx + 11 + 13 - 15 -3*/ - L_tmpX = L_add_sat( L_shr( Mult_32_16( L_tmp[sub( i, 3 )], full_band_bpf_fx[1][3] ), 3 ), L_tmpX ); /*Q_input_fx + 11 + 13 - 15 -3*/ - L_tmpX = L_sub_sat( L_tmpX, L_shl_sat( Mult_32_16( L_tmp2[sub( i, 1 )], full_band_bpf_fx[4][1] ), 2 ) ); /*Q_input_fx + 6 +13 -15 +2 */ - L_tmpX = L_add_sat( L_shr( Mult_32_16( L_tmp[sub( i, 2 )], full_band_bpf_fx[1][2] ), 3 ), L_tmpX ); /*Q_input_fx + 11 + 13 - 15 -3*/ - L_tmpX = L_sub_sat( L_tmpX, L_shl_sat( Mult_32_16( L_tmp2[sub( i, 2 )], full_band_bpf_fx[4][2] ), 2 ) ); /*Q_input_fx + 6 +13 -15 +2 */ - L_tmpX = L_add_sat( L_shr( Mult_32_16( L_tmp[sub( i, 1 )], full_band_bpf_fx[1][1] ), 3 ), L_tmpX ); /*Q_input_fx + 11 + 13 - 15 -3*/ - L_tmpX = L_sub_sat( L_tmpX, L_shl_sat( Mult_32_16( L_tmp2[sub( i, 3 )], full_band_bpf_fx[4][3] ), 2 ) ); /*Q_input_fx + 6 +13 -15 +2 */ - L_tmpX = L_add_sat( L_shr( Mult_32_16( L_tmp[i], full_band_bpf_fx[1][0] ), 3 ), L_tmpX ); /*Q_input_fx + 11 + 13 - 15 -3*/ - L_tmp2[i] = L_sub_sat( L_tmpX, L_shl_sat( Mult_32_16( L_tmp2[sub( i, 4 )], full_band_bpf_fx[4][4] ), 2 ) ); /*Q_input_fx + 6 +13 -15 +2 */ + L_tmpX = L_shr( Mult_32_16( L_tmp[i - 4], full_band_bpf_fx[1][4] ), 3 ); /*Q_input_fx + 11 + 13 - 15 -3*/ + L_tmpX = L_add_sat( L_shr( Mult_32_16( L_tmp[i - 3], full_band_bpf_fx[1][3] ), 3 ), L_tmpX ); /*Q_input_fx + 11 + 13 - 15 -3*/ + L_tmpX = L_sub_sat( L_tmpX, L_shl_sat( Mult_32_16( L_tmp2[i - 1], full_band_bpf_fx[4][1] ), 2 ) ); /*Q_input_fx + 6 +13 -15 +2 */ + L_tmpX = L_add_sat( L_shr( Mult_32_16( L_tmp[i - 2], full_band_bpf_fx[1][2] ), 3 ), L_tmpX ); /*Q_input_fx + 11 + 13 - 15 -3*/ + L_tmpX = L_sub_sat( L_tmpX, L_shl_sat( Mult_32_16( L_tmp2[i - 2], full_band_bpf_fx[4][2] ), 2 ) ); /*Q_input_fx + 6 +13 -15 +2 */ + L_tmpX = L_add_sat( L_shr( Mult_32_16( L_tmp[i - 1], full_band_bpf_fx[1][1] ), 3 ), L_tmpX ); /*Q_input_fx + 11 + 13 - 15 -3*/ + L_tmpX = L_sub_sat( L_tmpX, L_shl_sat( Mult_32_16( L_tmp2[i - 3], full_band_bpf_fx[4][3] ), 2 ) ); /*Q_input_fx + 6 +13 -15 +2 */ + L_tmpX = L_add_sat( L_shr( Mult_32_16( L_tmp[i], full_band_bpf_fx[1][0] ), 3 ), L_tmpX ); /*Q_input_fx + 11 + 13 - 15 -3*/ + L_tmp2[i] = L_sub_sat( L_tmpX, L_shl_sat( Mult_32_16( L_tmp2[i - 4], full_band_bpf_fx[4][4] ), 2 ) ); /*Q_input_fx + 6 +13 -15 +2 */ move32(); #else - L_tmpX = L_shr( Mult_32_16( L_tmp[sub( i, 4 )], full_band_bpf_fx[1][4] ), 3 ); /*Q_input_fx + 11 + 13 - 15 -3*/ - L_tmpX = L_add( L_shr( Mult_32_16( L_tmp[sub( i, 3 )], full_band_bpf_fx[1][3] ), 3 ), L_tmpX ); /*Q_input_fx + 11 + 13 - 15 -3*/ - L_tmpX = L_sub( L_tmpX, L_shl( Mult_32_16( L_tmp2[sub( i, 1 )], full_band_bpf_fx[4][1] ), 2 ) ); /*Q_input_fx + 6 +13 -15 +2 */ - L_tmpX = L_add( L_shr( Mult_32_16( L_tmp[sub( i, 2 )], full_band_bpf_fx[1][2] ), 3 ), L_tmpX ); /*Q_input_fx + 11 + 13 - 15 -3*/ - L_tmpX = L_sub( L_tmpX, L_shl( Mult_32_16( L_tmp2[sub( i, 2 )], full_band_bpf_fx[4][2] ), 2 ) ); /*Q_input_fx + 6 +13 -15 +2 */ - L_tmpX = L_add( L_shr( Mult_32_16( L_tmp[sub( i, 1 )], full_band_bpf_fx[1][1] ), 3 ), L_tmpX ); /*Q_input_fx + 11 + 13 - 15 -3*/ - L_tmpX = L_sub( L_tmpX, L_shl( Mult_32_16( L_tmp2[sub( i, 3 )], full_band_bpf_fx[4][3] ), 2 ) ); /*Q_input_fx + 6 +13 -15 +2 */ - L_tmpX = L_add( L_shr( Mult_32_16( L_tmp[i], full_band_bpf_fx[1][0] ), 3 ), L_tmpX ); /*Q_input_fx + 11 + 13 - 15 -3*/ - L_tmp2[i] = L_sub( L_tmpX, L_shl( Mult_32_16( L_tmp2[sub( i, 4 )], full_band_bpf_fx[4][4] ), 2 ) ); /*Q_input_fx + 6 +13 -15 +2 */ + L_tmpX = L_shr( Mult_32_16( L_tmp[i - 4], full_band_bpf_fx[1][4] ), 3 ); /*Q_input_fx + 11 + 13 - 15 -3*/ + L_tmpX = L_add( L_shr( Mult_32_16( L_tmp[i - 3], full_band_bpf_fx[1][3] ), 3 ), L_tmpX ); /*Q_input_fx + 11 + 13 - 15 -3*/ + L_tmpX = L_sub( L_tmpX, L_shl( Mult_32_16( L_tmp2[i - 1], full_band_bpf_fx[4][1] ), 2 ) ); /*Q_input_fx + 6 +13 -15 +2 */ + L_tmpX = L_add( L_shr( Mult_32_16( L_tmp[i - 2], full_band_bpf_fx[1][2] ), 3 ), L_tmpX ); /*Q_input_fx + 11 + 13 - 15 -3*/ + L_tmpX = L_sub( L_tmpX, L_shl( Mult_32_16( L_tmp2[i - 2], full_band_bpf_fx[4][2] ), 2 ) ); /*Q_input_fx + 6 +13 -15 +2 */ + L_tmpX = L_add( L_shr( Mult_32_16( L_tmp[i - 1], full_band_bpf_fx[1][1] ), 3 ), L_tmpX ); /*Q_input_fx + 11 + 13 - 15 -3*/ + L_tmpX = L_sub( L_tmpX, L_shl( Mult_32_16( L_tmp2[i - 3], full_band_bpf_fx[4][3] ), 2 ) ); /*Q_input_fx + 6 +13 -15 +2 */ + L_tmpX = L_add( L_shr( Mult_32_16( L_tmp[i], full_band_bpf_fx[1][0] ), 3 ), L_tmpX ); /*Q_input_fx + 11 + 13 - 15 -3*/ + L_tmp2[i] = L_sub( L_tmpX, L_shl( Mult_32_16( L_tmp2[i - 4], full_band_bpf_fx[4][4] ), 2 ) ); /*Q_input_fx + 6 +13 -15 +2 */ move32(); #endif L_tmpMax = L_max( L_tmpMax, L_abs( L_tmp2[i] ) ); @@ -5659,10 +5682,10 @@ void elliptic_bpf_48k_generic_fx( Q_temp = sub( Q_temp, 4 ); Scale_sig32( L_tmp2, 960, Q_temp ); - memory_fx2[1][0] = L_tmp[sub( L_FRAME48k, 4 )]; - memory_fx2[1][1] = L_tmp[sub( L_FRAME48k, 3 )]; - memory_fx2[1][2] = L_tmp[sub( L_FRAME48k, 2 )]; - memory_fx2[1][3] = L_tmp[sub( L_FRAME48k, 1 )]; + memory_fx2[1][0] = L_tmp[L_FRAME48k - 4]; + memory_fx2[1][1] = L_tmp[L_FRAME48k - 3]; + memory_fx2[1][2] = L_tmp[L_FRAME48k - 2]; + memory_fx2[1][3] = L_tmp[L_FRAME48k - 1]; move32(); move32(); move32(); @@ -5732,18 +5755,18 @@ void elliptic_bpf_48k_generic_fx( FOR( i = 4; i < L_FRAME48k; i++ ) { - L_tmpX = L_shr( Mult_32_16( L_tmp2[sub( i, 4 )], full_band_bpf_fx[2][4] ), 3 ); /*Q_input_fx + 6 +Q_temp+13 -15 -3 */ - L_tmpX = L_add_sat( L_shr( Mult_32_16( L_tmp2[sub( i, 3 )], full_band_bpf_fx[2][3] ), 3 ), L_tmpX ); /*Q_input_fx + 6 +Q_temp +13 -15 -3*/ - L_tmpX = L_sub_sat( L_tmpX, L_shl_sat( Mult_32_16( L_output[sub( i, 1 )], full_band_bpf_fx[5][1] ), 2 ) ); /*Q_input_fx + 1 +Q_temp+13 -15 + 2*/ + L_tmpX = L_shr( Mult_32_16( L_tmp2[i - 4], full_band_bpf_fx[2][4] ), 3 ); /*Q_input_fx + 6 +Q_temp+13 -15 -3 */ + L_tmpX = L_add_sat( L_shr( Mult_32_16( L_tmp2[i - 3], full_band_bpf_fx[2][3] ), 3 ), L_tmpX ); /*Q_input_fx + 6 +Q_temp +13 -15 -3*/ + L_tmpX = L_sub_sat( L_tmpX, L_shl_sat( Mult_32_16( L_output[i - 1], full_band_bpf_fx[5][1] ), 2 ) ); /*Q_input_fx + 1 +Q_temp+13 -15 + 2*/ - L_tmpX = L_add_sat( L_shr( Mult_32_16( L_tmp2[sub( i, 2 )], full_band_bpf_fx[2][2] ), 3 ), L_tmpX ); /*Q_input_fx + 6 +Q_temp+13 -15 -3*/ - L_tmpX = L_sub_sat( L_tmpX, L_shl_sat( Mult_32_16( L_output[sub( i, 2 )], full_band_bpf_fx[5][2] ), 2 ) ); /*Q_input_fx + 1 +Q_temp+13 -15 + 2*/ + L_tmpX = L_add_sat( L_shr( Mult_32_16( L_tmp2[i - 2], full_band_bpf_fx[2][2] ), 3 ), L_tmpX ); /*Q_input_fx + 6 +Q_temp+13 -15 -3*/ + L_tmpX = L_sub_sat( L_tmpX, L_shl_sat( Mult_32_16( L_output[i - 2], full_band_bpf_fx[5][2] ), 2 ) ); /*Q_input_fx + 1 +Q_temp+13 -15 + 2*/ - L_tmpX = L_add_sat( L_shr( Mult_32_16( L_tmp2[sub( i, 1 )], full_band_bpf_fx[2][1] ), 3 ), L_tmpX ); /*Q_input_fx + 6 +Q_temp +13 -15 -3*/ - L_tmpX = L_sub_sat( L_tmpX, L_shl_sat( Mult_32_16( L_output[sub( i, 3 )], full_band_bpf_fx[5][3] ), 2 ) ); /*Q_input_fx + 1 +Q_temp+13 -15 + 2*/ + L_tmpX = L_add_sat( L_shr( Mult_32_16( L_tmp2[i - 1], full_band_bpf_fx[2][1] ), 3 ), L_tmpX ); /*Q_input_fx + 6 +Q_temp +13 -15 -3*/ + L_tmpX = L_sub_sat( L_tmpX, L_shl_sat( Mult_32_16( L_output[i - 3], full_band_bpf_fx[5][3] ), 2 ) ); /*Q_input_fx + 1 +Q_temp+13 -15 + 2*/ - L_tmpX = L_add_sat( L_shr( Mult_32_16( L_tmp2[i], full_band_bpf_fx[2][0] ), 3 ), L_tmpX ); /*Q_input_fx + 6 +Q_temp +13 -15 -3*/ - L_output[i] = L_sub_sat( L_tmpX, L_shl_sat( Mult_32_16( L_output[sub( i, 4 )], full_band_bpf_fx[5][4] ), 2 ) ); /*Q_input_fx + 1 +Q_temp+13 -15 + 2*/ + L_tmpX = L_add_sat( L_shr( Mult_32_16( L_tmp2[i], full_band_bpf_fx[2][0] ), 3 ), L_tmpX ); /*Q_input_fx + 6 +Q_temp +13 -15 -3*/ + L_output[i] = L_sub_sat( L_tmpX, L_shl_sat( Mult_32_16( L_output[i - 4], full_band_bpf_fx[5][4] ), 2 ) ); /*Q_input_fx + 1 +Q_temp+13 -15 + 2*/ move32(); L_tmpMax = L_max( L_tmpMax, L_abs( L_output[i] ) ); } @@ -5798,30 +5821,30 @@ void elliptic_bpf_48k_generic_fx( FOR( i = 4; i < L_FRAME48k; i++ ) { - L_tmpX = L_shr( Mult_32_16( L_tmp2[sub( i, 4 )], full_band_bpf_fx[2][4] ), 3 ); /*Q_input_fx + 6 +Q_temp+13 -15 -3 */ - L_tmpX = L_add( L_shr( Mult_32_16( L_tmp2[sub( i, 3 )], full_band_bpf_fx[2][3] ), 3 ), L_tmpX ); /*Q_input_fx + 6 +Q_temp +13 -15 -3*/ - L_tmpX = L_sub( L_tmpX, L_shl( Mult_32_16( L_output[sub( i, 1 )], full_band_bpf_fx[5][1] ), 2 ) ); /*Q_input_fx + 1 +Q_temp+13 -15 + 2*/ + L_tmpX = L_shr( Mult_32_16( L_tmp2[i - 4], full_band_bpf_fx[2][4] ), 3 ); /*Q_input_fx + 6 +Q_temp+13 -15 -3 */ + L_tmpX = L_add( L_shr( Mult_32_16( L_tmp2[i - 3], full_band_bpf_fx[2][3] ), 3 ), L_tmpX ); /*Q_input_fx + 6 +Q_temp +13 -15 -3*/ + L_tmpX = L_sub( L_tmpX, L_shl( Mult_32_16( L_output[i - 1], full_band_bpf_fx[5][1] ), 2 ) ); /*Q_input_fx + 1 +Q_temp+13 -15 + 2*/ - L_tmpX = L_add( L_shr( Mult_32_16( L_tmp2[sub( i, 2 )], full_band_bpf_fx[2][2] ), 3 ), L_tmpX ); /*Q_input_fx + 6 +Q_temp+13 -15 -3*/ - L_tmpX = L_sub( L_tmpX, L_shl( Mult_32_16( L_output[sub( i, 2 )], full_band_bpf_fx[5][2] ), 2 ) ); /*Q_input_fx + 1 +Q_temp+13 -15 + 2*/ + L_tmpX = L_add( L_shr( Mult_32_16( L_tmp2[i - 2], full_band_bpf_fx[2][2] ), 3 ), L_tmpX ); /*Q_input_fx + 6 +Q_temp+13 -15 -3*/ + L_tmpX = L_sub( L_tmpX, L_shl( Mult_32_16( L_output[i - 2], full_band_bpf_fx[5][2] ), 2 ) ); /*Q_input_fx + 1 +Q_temp+13 -15 + 2*/ - L_tmpX = L_add( L_shr( Mult_32_16( L_tmp2[sub( i, 1 )], full_band_bpf_fx[2][1] ), 3 ), L_tmpX ); /*Q_input_fx + 6 +Q_temp +13 -15 -3*/ - L_tmpX = L_sub( L_tmpX, L_shl( Mult_32_16( L_output[sub( i, 3 )], full_band_bpf_fx[5][3] ), 2 ) ); /*Q_input_fx + 1 +Q_temp+13 -15 + 2*/ + L_tmpX = L_add( L_shr( Mult_32_16( L_tmp2[i - 1], full_band_bpf_fx[2][1] ), 3 ), L_tmpX ); /*Q_input_fx + 6 +Q_temp +13 -15 -3*/ + L_tmpX = L_sub( L_tmpX, L_shl( Mult_32_16( L_output[i - 3], full_band_bpf_fx[5][3] ), 2 ) ); /*Q_input_fx + 1 +Q_temp+13 -15 + 2*/ - L_tmpX = L_add( L_shr( Mult_32_16( L_tmp2[i], full_band_bpf_fx[2][0] ), 3 ), L_tmpX ); /*Q_input_fx + 6 +Q_temp +13 -15 -3*/ - L_output[i] = L_sub( L_tmpX, L_shl( Mult_32_16( L_output[sub( i, 4 )], full_band_bpf_fx[5][4] ), 2 ) ); /*Q_input_fx + 1 +Q_temp+13 -15 + 2*/ + L_tmpX = L_add( L_shr( Mult_32_16( L_tmp2[i], full_band_bpf_fx[2][0] ), 3 ), L_tmpX ); /*Q_input_fx + 6 +Q_temp +13 -15 -3*/ + L_output[i] = L_sub( L_tmpX, L_shl( Mult_32_16( L_output[i - 4], full_band_bpf_fx[5][4] ), 2 ) ); /*Q_input_fx + 1 +Q_temp+13 -15 + 2*/ move32(); L_tmpMax = L_max( L_tmpMax, L_abs( L_output[i] ) ); } #endif - memory_fx2[2][0] = L_tmp2[sub( L_FRAME48k, 4 )]; - memory_fx2[2][1] = L_tmp2[sub( L_FRAME48k, 3 )]; - memory_fx2[2][2] = L_tmp2[sub( L_FRAME48k, 2 )]; - memory_fx2[2][3] = L_tmp2[sub( L_FRAME48k, 1 )]; - memory_fx2[3][0] = L_output[sub( L_FRAME48k, 4 )]; - memory_fx2[3][1] = L_output[sub( L_FRAME48k, 3 )]; - memory_fx2[3][2] = L_output[sub( L_FRAME48k, 2 )]; - memory_fx2[3][3] = L_output[sub( L_FRAME48k, 1 )]; + memory_fx2[2][0] = L_tmp2[L_FRAME48k - 4]; + memory_fx2[2][1] = L_tmp2[L_FRAME48k - 3]; + memory_fx2[2][2] = L_tmp2[L_FRAME48k - 2]; + memory_fx2[2][3] = L_tmp2[L_FRAME48k - 1]; + memory_fx2[3][0] = L_output[L_FRAME48k - 4]; + memory_fx2[3][1] = L_output[L_FRAME48k - 3]; + memory_fx2[3][2] = L_output[L_FRAME48k - 2]; + memory_fx2[3][3] = L_output[L_FRAME48k - 1]; move32(); move32(); move32(); @@ -6017,7 +6040,7 @@ void Estimate_mix_factors_fx( pow3 = Dot_product( shb_res_local, shb_res_local, L_FRAME16k ); /* (2*Q_shb+1) */ - pow3 += L_shl( 21475l /*0.00001f in Q31*/, 2 * Q_shb + 1 - 31 ); /* (2*Q_shb+1) */ + pow3 = L_add( pow3, L_shl( 21475l /*0.00001f in Q31*/, 2 * Q_shb + 1 - 31 ) ); /* (2*Q_shb+1) */ if ( pow3 == 0 ) { pow3 = 1; @@ -6031,10 +6054,8 @@ void Estimate_mix_factors_fx( temp_p1_p3 = root_a_over_b_fx( pow1, Q_pow1, pow3, ( 2 * Q_shb + 1 ), &exp2 ); /* temp_p1_p3 in (Q31+exp2) */ - sc1 = Q_bwe_exc - ( Q_frac - exp1 ); - sc2 = Q_bwe_exc - ( Q_shb - exp2 ); - move16(); - move16(); + sc1 = sub( Q_bwe_exc, sub( Q_frac, exp1 ) ); + sc2 = sub( Q_bwe_exc, sub( Q_shb, exp2 ) ); FOR( i = 0; i < L_FRAME16k; i++ ) { L_tmp1 = Mult_32_16( temp_p1_p2, WN_exc_local[i] ); /* (Q_frac - exp1) +16 */ @@ -6280,7 +6301,7 @@ void prep_tbe_exc_fx( tempQ31 = L_deposit_h( VF_0th_PARAM_FX ); *voice_factors_fx = mac_r( tempQ31, voice_fac_fx, tempQ15 ); move16(); - tmp = 32767; + tmp = MAX_16; move16(); #ifdef BASOP_NOGLOB @@ -6291,7 +6312,7 @@ void prep_tbe_exc_fx( test(); test(); - IF( ( ( EQ_16( coder_type, VOICED ) ) || ( GT_16( pitch, 14784 ) ) ) && ( GT_32( core_brate, ACELP_8k00 ) ) ) + IF( ( ( EQ_16( coder_type, VOICED ) ) || ( GT_16( pitch, 14784 /* 115.5 in Q7 */ ) ) ) && ( GT_32( core_brate, ACELP_8k00 ) ) ) { tmp = MAX_16; move16(); @@ -6351,16 +6372,17 @@ void prep_tbe_exc_fx( Ltemp2 = L_mult( gain_preQ_fx, code_preQ_fx[i] ); /*Q2 * Q10 -> Q12 */ #ifdef BASOP_NOGLOB - Ltemp1 = L_shl_o( Ltemp1, Q_exc + 6 /*Q_exc+16-19*/, &Overflow ); /*Q_exc+16 */ - Ltemp2 = L_shl_o( Ltemp2, Q_exc + 4 /*Q_exc+16-13*/, &Overflow ); /*Q_exc+16 */ + Ltemp1 = L_shl_o( Ltemp1, add( Q_exc, 6 ) /*Q_exc+16-19*/, &Overflow ); /*Q_exc+16 */ + Ltemp2 = L_shl_o( Ltemp2, add( Q_exc, 4 ) /*Q_exc+16-13*/, &Overflow ); /*Q_exc+16 */ tmp_code_preInt_fx[i] = round_fx_o( L_add_o( Ltemp1, Ltemp2, &Overflow ), &Overflow ); /* Q_exc */ -#else /* BASOP_NOGLOB */ + move16(); +#else /* BASOP_NOGLOB */ Ltemp1 = L_shl( Ltemp1, Q_exc + 6 /*Q_exc+16-19*/ ); /*Q_exc+16 */ Ltemp2 = L_shl( Ltemp2, Q_exc + 4 /*Q_exc+16-13*/ ); /*Q_exc+16 */ tmp_code_preInt_fx[i] = round_fx( L_add( Ltemp1, Ltemp2 ) ); /* Q_exc */ -#endif /* BASOP_NOGLOB */ +#endif /* BASOP_NOGLOB */ } } ELSE @@ -6370,8 +6392,9 @@ void prep_tbe_exc_fx( /*code in the encoder is Q9 and there is no <<1 with Mult_32_16 Q16 * Q9 -> Q9 */ Ltemp1 = Mult_32_16( gain_code_fx, code_fx[i] ); /* Q16 + Q9 + 1 - 16 = Q10 */ #ifdef BASOP_NOGLOB - Ltemp1 = L_shl_o( Ltemp1, Q_exc + 6 /*Q_exc+16-19*/, &Overflow ); /*Q_exc+16 */ - tmp_code_preInt_fx[i] = round_fx_o( Ltemp1, &Overflow ); /* Q_exc */ + Ltemp1 = L_shl_o( Ltemp1, add( Q_exc, 6 ) /*Q_exc+16-19*/, &Overflow ); /*Q_exc+16 */ + tmp_code_preInt_fx[i] = round_fx_o( Ltemp1, &Overflow ); /* Q_exc */ + move16(); #else Ltemp1 = L_shl( Ltemp1, Q_exc + 6 /*Q_exc+16-19*/ ); /*Q_exc+16 */ tmp_code_preInt_fx[i] = round_fx( Ltemp1 ); /* Q_exc */ @@ -6458,6 +6481,7 @@ void prep_tbe_exc_ivas_fx( Word16 tmp_code_fx[2 * L_SUBFR * HIBND_ACB_L_FAC]; Word16 tmp_code_preInt_fx[L_SUBFR]; Word16 gain_code16 = 0; + move16(); Word16 tmp /*, tmp1, tmp2*/; /*Word16 random_code[L_SUBFR * HIBND_ACB_L_FAC];*/ Word16 pitch; @@ -6470,6 +6494,7 @@ void prep_tbe_exc_ivas_fx( #endif #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif /**voice_factors = VF_0th_PARAM + VF_1st_PARAM * voice_fac + VF_2nd_PARAM * voice_fac * voice_fac; @@ -6479,8 +6504,9 @@ void prep_tbe_exc_ivas_fx( tempQ15 = mac_r( tempQ31, VF_2nd_PARAM_FX, voice_fac_fx ); tempQ31 = L_deposit_h( VF_0th_PARAM_FX ); *voice_factors_fx = mac_r( tempQ31, voice_fac_fx, tempQ15 ); + move16(); - tmp = 32767; + tmp = MAX_16; move16(); #ifdef BASOP_NOGLOB @@ -6502,8 +6528,11 @@ void prep_tbe_exc_ivas_fx( *voice_factors_fx = s_min( s_max( *voice_factors_fx, 0 ), MAX_16 ); move16(); #if 1 // def ADD_IVAS_TBE_CODE + test(); + test(); IF( EQ_16( element_mode, IVAS_CPE_TD ) && EQ_16( idchan, 1 ) && !tdm_LRTD_flag ) { + test(); IF( flag_TD_BWE && i_subfr_fx == 0 ) { set16_fx( bwe_exc_fx, 0, L_FRAME32k ); @@ -6645,12 +6674,12 @@ Word16 swb_formant_fac_fx( /* o : Formant filter strength formant_fac = mult_r( tmp, SWB_TILT_DELTA_FX ); /* Q12 */ - IF( GT_16( formant_fac, 4096 ) ) + IF( GT_16( formant_fac, 4096 /* 1 in Q12 */ ) ) { - formant_fac = 4096; + formant_fac = 4096; /* 1 in Q12 */ move16(); } - ELSE if ( formant_fac < 0 ) + ELSE IF( formant_fac < 0 ) { formant_fac = 0; move16(); @@ -6658,9 +6687,9 @@ Word16 swb_formant_fac_fx( /* o : Formant filter strength /* now formant_fac in Q12 */ /* formant_fac = 1.0f - 0.5f*formant_fac */ - tmp = mult_r( 16384, formant_fac ); /* 0.5 in Q12 */ + tmp = mult_r( 16384, formant_fac ); /* 0.5 in Q15 */ #ifdef BASOP_NOGLOB - formant_fac = shl_o( sub( 4096, tmp ), 3, &Overflow ); + formant_fac = shl_o( sub( 4096 /* 1 in Q12 */, tmp ), 3, &Overflow ); #else formant_fac = shl( sub( 4096, tmp ), 3 ); #endif diff --git a/lib_com/syn_filt_fx.c b/lib_com/syn_filt_fx.c index 6d5bc99b0..6b000db50 100644 --- a/lib_com/syn_filt_fx.c +++ b/lib_com/syn_filt_fx.c @@ -323,6 +323,26 @@ void E_UTIL_synthesis( const Word16 shift, const Word16 a[], const Word16 x[], W } +/* + * E_UTIL_synthesis_fx + * + * Parameters: + * shift i : scaling to apply for a[0] Q0 + * a[] i : LP filter coefficients Qx + * x[] i : input signal Qx + * y[] o : output signal Qx-s + * lg i : size of filtering Q0 + * mem[] i/o: memory associated with this filtering. Qx-s + * update i : 0=no update, 1=update of memory. Q0 + * m i : order of LP filter Q0 + * + * Function: + * Perform the synthesis filtering 1/A(z). + * Memory size is always M. + * + * Returns: + * void + */ void E_UTIL_synthesis_fx( const Word16 shift, const Word32 a[], const Word32 x[], Word32 y[], const Word16 lg, Word32 mem[], const Word16 update, const Word16 m ) { Word16 i, j; @@ -331,6 +351,7 @@ void E_UTIL_synthesis_fx( const Word16 shift, const Word32 a[], const Word32 x[] Word16 q; Word32 ( *syn_kern )( Word32 L_tmp, const Word32 a[], const Word32 y[] ) = NULL; Flag Overflow = 0; + move32(); if ( EQ_16( m, 6 ) ) { @@ -366,6 +387,7 @@ void E_UTIL_synthesis_fx( const Word16 shift, const Word32 a[], const Word32 x[] L_tmp = syn_kern( Mpy_32_32( a0, *x++ ), a, mem ); L_tmp = L_shl_o( L_tmp, q, &Overflow ); *y++ = L_tmp; + move32(); /* Filtering from Input + Mix of Memory & Output Signal Past */ FOR( i = 1; i < m; i++ ) @@ -419,12 +441,12 @@ void E_UTIL_synthesis_fx( const Word16 shift, const Word32 a[], const Word32 x[] #ifdef IVAS_FLOAT_FIXED void ivas_synth_mem_updt2_fx( - const Word16 L_frame, /* i : frame length */ - const Word16 last_L_frame, /* i : frame length */ - Word16 old_exc[], /* i/o: excitation buffer */ - Word16 mem_syn_r[], /* i/o: synthesis filter memory */ - Word16 mem_syn2[], /* o : synthesis filter memory for find_target */ - Word16 mem_syn[], /* o : synthesis filter memory for find_target */ + const Word16 L_frame, /* i : frame length */ + const Word16 last_L_frame, /* i : frame length */ + Word16 old_exc[], /* i/o: excitation buffer st->Q_syn */ + Word16 mem_syn_r[], /* i/o: synthesis filter memory st->Q_syn */ + Word16 mem_syn2[], /* o : synthesis filter memory for find_target st->Q_syn */ + Word16 mem_syn[], /* o : synthesis filter memory for find_target st->Q_syn */ const Word16 dec #ifndef FIX_907_MEM_UPDATE_ISSUE , /* i : flag for decoder indication */ @@ -542,13 +564,13 @@ void ivas_synth_mem_updt2_fx( } #endif void synth_mem_updt2( - const Word16 L_frame, /* i : frame length */ - const Word16 last_L_frame, /* i : frame length */ - Word16 old_exc[], /* i/o: excitation buffer */ - Word16 mem_syn_r[], /* i/o: synthesis filter memory */ - Word16 mem_syn2[], /* o : synthesis filter memory for find_target */ - Word16 mem_syn[], /* o : synthesis filter memory for find_target */ - const Word16 dec /* i : flag for decoder indication */ + const Word16 L_frame, /* i : frame length */ + const Word16 last_L_frame, /* i : frame length */ + Word16 old_exc[], /* i/o: excitation buffer st->Q_syn */ + Word16 mem_syn_r[], /* i/o: synthesis filter memory st->Q_syn */ + Word16 mem_syn2[], /* o : synthesis filter memory for find_target st->Q_syn */ + Word16 mem_syn[], /* o : synthesis filter memory for find_target st->Q_syn */ + const Word16 dec /* i : flag for decoder indication */ ) { Word16 mem_syn_r_size_old, mem_syn_r_size_new; diff --git a/lib_com/tcq_position_arith.c b/lib_com/tcq_position_arith.c index 7d26888d3..9aff06057 100644 --- a/lib_com/tcq_position_arith.c +++ b/lib_com/tcq_position_arith.c @@ -44,6 +44,7 @@ #include "wmc_auto.h" +#ifndef IVAS_FLOAT_FIXED static void bitstream_save_bit( TCQ_PBITSTREAM pBS, const int16_t bit ); static uint32_t bitstream_load_bit( TCQ_PBITSTREAM pBS ); static void bitstream_rollback( TCQ_PBITSTREAM pBS, int16_t numBits ); @@ -2290,3 +2291,4 @@ void RestoreTCQ( return; } +#endif diff --git a/lib_com/tcq_position_arith_fx.c b/lib_com/tcq_position_arith_fx.c index fdac07f56..2cc28e853 100644 --- a/lib_com/tcq_position_arith_fx.c +++ b/lib_com/tcq_position_arith_fx.c @@ -276,7 +276,7 @@ static void ar_encode_fx( test(); IF( GE_32( low, AR_FIRST ) && LT_32( high, AR_THIRD ) ) { - arInst->bits_to_follow++; + arInst->bits_to_follow = add( arInst->bits_to_follow, 1 ); move16(); low = L_sub( low, AR_FIRST ); @@ -320,7 +320,7 @@ static void ar_encode_uniform_fx( void ar_encoder_done_fx( PARCODEC arInst ) { - arInst->bits_to_follow++; + arInst->bits_to_follow = add( arInst->bits_to_follow, 1 ); move16(); transmission_bits( arInst, arInst->low >= AR_FIRST ); @@ -1063,19 +1063,19 @@ Word32 GetISCScale_fx( Word32 L_tmp; IF( GT_32( 1952247030, scale_fx32 ) ) { - scale_fx32 = L_add( scale_fx32, Mult_32_16( scale_fx32, 3277 ) ); + scale_fx32 = L_add( scale_fx32, Mult_32_16( scale_fx32, 3277 /*0.1 in Q15*/ ) ); } ELSE { L_tmp = L_shr( scale_fx32, 1 ); - scale_fx32 = L_add( L_tmp, Mult_32_16( L_tmp, 3277 ) ); + scale_fx32 = L_add( L_tmp, Mult_32_16( L_tmp, 3277 /*0.1 in Q15*/ ) ); Qscale = sub( Qscale, 1 ); } } if ( LT_16( pulsesnum, pulsescurr ) ) { - scale_fx32 = Mult_32_16( scale_fx32, 29491 ); + scale_fx32 = Mult_32_16( scale_fx32, 29491 /*0.9 in Q15*/ ); } IF( GT_16( pulsesnum, pulsescurr ) ) { @@ -1100,7 +1100,7 @@ Word32 GetISCScale_fx( } ELSE { - magn_fx[i] = -abs_s( add( magn_fx[i], diff ) ); + magn_fx[i] = negate( abs_s( add( magn_fx[i], diff ) ) ); move16(); } @@ -1140,7 +1140,7 @@ Word32 GetISCScale_fx( } ELSE { - magn_fx[i] = -sub( abs_s( magn_fx[i] ), diff ); + magn_fx[i] = negate( sub( abs_s( magn_fx[i] ), diff ) ); move16(); } BREAK; @@ -1236,7 +1236,7 @@ Word32 GetISCScale_fx( } /* Update actual occurred surplus */ - tcqmagnbits_fx = L_sub( L_sub( table_logcum_fx[pulsescurr], table_logcum_fx[nzposcurr] ), table_logcum_fx[sub( pulsescurr, sub( nzposcurr, 1 ) )] ); + tcqmagnbits_fx = L_sub( L_sub( table_logcum_fx[pulsescurr], table_logcum_fx[nzposcurr] ), table_logcum_fx[pulsescurr - ( nzposcurr - 1 )] ); *surplus_fx = L_add( *surplus_fx, L_sub( tcqmagnbits_fx, L_shl( magnbits_fx, 1 ) ) ); move32(); *nzpout = nzposcurr; @@ -1427,36 +1427,36 @@ void TCQLSB_fx( /* decision */ IF( LT_32( L_add( curdist1_fx, newdist1_fx ), L_add( curdist2_fx, newdist2_fx ) ) ) { - path[st][add( shr( i, 1 ), 1 )] = step_LSB[st][0]; + path[st][i / 2 + 1] = step_LSB[st][0]; move16(); - metric_fx[st][add( shr( i, 1 ), 1 )] = L_add( curdist1_fx, newdist1_fx ); + metric_fx[st][i / 2 + 1] = L_add( curdist1_fx, newdist1_fx ); move32(); - quant[st][add( shr( i, 1 ), 1 )] = 0; + quant[st][i / 2 + 1] = 0; move16(); - dquant[st][add( shr( i, 1 ), 1 )] = dqnt_LSB[step_LSB[st][0]][st]; + dquant[st][i / 2 + 1] = dqnt_LSB[step_LSB[st][0]][st]; move16(); } ELSE { - path[st][add( shr( i, 1 ), 1 )] = step_LSB[st][1]; + path[st][i / 2 + 1] = step_LSB[st][1]; move16(); - metric_fx[st][add( shr( i, 1 ), 1 )] = L_add( curdist2_fx, newdist2_fx ); + metric_fx[st][i / 2 + 1] = L_add( curdist2_fx, newdist2_fx ); move32(); - quant[st][add( shr( i, 1 ), 1 )] = 1; + quant[st][i / 2 + 1] = 1; move16(); - dquant[st][add( shr( i, 1 ), 1 )] = dqnt_LSB[step_LSB[st][0]][st]; + dquant[st][i / 2 + 1] = dqnt_LSB[step_LSB[st][0]][st]; move16(); } - if ( GT_32( MaxPath, metric_fx[st][add( shr( i, 1 ), 1 )] ) ) + if ( GT_32( MaxPath, metric_fx[st][i / 2 + 1] ) ) { - MaxPath = L_add( metric_fx[st][add( shr( i, 1 ), 1 )], 0 ); + MaxPath = L_add( metric_fx[st][i / 2 + 1], 0 ); } } /* Metric renormalization to prevent overflow */ FOR( st = 0; st < 4; st++ ) { - metric_fx[st][add( shr( i, 1 ), 1 )] = L_sub( metric_fx[st][add( shr( i, 1 ), 1 )], MaxPath ); + metric_fx[st][i / 2 + 1] = L_sub( metric_fx[st][i / 2 + 1], MaxPath ); move32(); } } @@ -1481,9 +1481,9 @@ void TCQLSB_fx( FOR( ; i >= 0; i -= 2 ) { - qout[i / 2] = quant[position][add( shr( i, 1 ), 1 )]; + qout[i / 2] = quant[position][i / 2 + 1]; move16(); - dpath[i / 2] = dquant[position][add( shr( i, 1 ), 1 )]; + dpath[i / 2] = dquant[position][i / 2 + 1]; move16(); IF( s_and( denc_LSB[position][qout[i / 2]], 0x1 ) ) @@ -1507,7 +1507,7 @@ void TCQLSB_fx( move16(); } - position = path[position][add( shr( i, 1 ), 1 )]; + position = path[position][i / 2 + 1]; move16(); } @@ -1546,12 +1546,12 @@ void TCQLSBdec_fx( IF( s_and( ddec_LSB[state][dpath[i]], 0x2 ) ) { - mbuffer[add( shl( i, 1 ), 1 )] = q; + mbuffer[2 * i + 1] = q; move16(); } ELSE { - mbuffer[add( shl( i, 1 ), 1 )] = negate( q ); + mbuffer[2 * i + 1] = negate( q ); move16(); } @@ -1737,8 +1737,8 @@ Word32 encode_position_ari_fx( btcq_fx = GetBitsFromPulses_fx( pulses, size ); /* Estimate TCQ bits */ - bits_fx = L_sub( table_logcum_fx[size + 1], L_add( table_logcum_fx[nz + 1], table_logcum_fx[add( sub( size, nz ), 1 )] ) ); - bits_fx = L_add( bits_fx, L_sub( btcq_fx, L_sub( table_logcum_fx[size + 1], L_add( table_logcum_fx[nz + 1], table_logcum_fx[add( sub( size, nz ), 1 )] ) ) ) ); + bits_fx = L_sub( table_logcum_fx[size + 1], L_add( table_logcum_fx[nz + 1], table_logcum_fx[size - nz + 1] ) ); + bits_fx = L_add( bits_fx, L_sub( btcq_fx, L_sub( table_logcum_fx[size + 1], L_add( table_logcum_fx[nz + 1], table_logcum_fx[size - nz + 1] ) ) ) ); bits_fx = L_sub( bits_fx, L_sub( table_logcum_fx[pulses], L_add( table_logcum_fx[nz], table_logcum_fx[pulses - ( nz - 1 )] ) ) ); bits_fx = L_sub( bits_fx, nz ); *est_bits_frame_fx = L_add( *est_bits_frame_fx, bits_fx ); @@ -1748,10 +1748,10 @@ Word32 encode_position_ari_fx( FOR( i = 0; i < tmp; i++ ) { pnzp_fx = L_sub( L_deposit_h( add( i, 1 ) ), btcq_fx ); - pnzp_fx = L_add( pnzp_fx, L_add( L_sub( table_logcum_fx[size + 1], L_add( table_logcum_fx[i + 2], table_logcum_fx[sub( size, i )] ) ), - L_sub( table_logcum_fx[pulses], L_add( table_logcum_fx[i + 1], table_logcum_fx[sub( pulses, i )] ) ) ) ); + pnzp_fx = L_add( pnzp_fx, L_add( L_sub( table_logcum_fx[size + 1], L_add( table_logcum_fx[i + 2], table_logcum_fx[size - i] ) ), + L_sub( table_logcum_fx[pulses], L_add( table_logcum_fx[i + 1], table_logcum_fx[pulses - i] ) ) ) ); pnzp_fx = L_add( pnzp_fx, 917498 ); /*16 */ - IF( GT_32( pnzp_fx, 0 ) ) + IF( pnzp_fx > 0 ) { integer = extract_h( pnzp_fx ); frac = extract_l( L_shr( L_sub( pnzp_fx, L_deposit_h( integer ) ), 1 ) ); /*15 */ @@ -1786,7 +1786,7 @@ Word32 encode_position_ari_fx( BREAK; } - IF( nz == ( size - i ) ) + IF( EQ_16( nz, sub( size, i ) ) ) { cp = L_deposit_l( 0 ); } @@ -1799,7 +1799,7 @@ Word32 encode_position_ari_fx( move16(); test(); test(); - IF( ( model_num_nz[pos + 1] == 0 && scp > 0 ) || model_num_nz[pos] == model_num_nz[pos + 1] ) + IF( ( model_num_nz[pos + 1] == 0 && scp > 0 ) || EQ_16( model_num_nz[pos], model_num_nz[pos + 1] ) ) { model_num_nz[pos + 1] = 0; move16(); @@ -1872,7 +1872,7 @@ Word32 encode_magnitude_usq_fx( /*estimate fac bits */ - bits_fx = L_sub( table_logcum_fx[npulses], L_add( table_logcum_fx[nzpos], table_logcum_fx[add( sub( npulses, nzpos ), 1 )] ) ); + bits_fx = L_sub( table_logcum_fx[npulses], L_add( table_logcum_fx[nzpos], table_logcum_fx[npulses - nzpos + 1] ) ); *est_frame_bits_fx = L_add( *est_frame_bits_fx, bits_fx ); test(); @@ -1930,7 +1930,7 @@ Word32 encode_magnitude_usq_fx( move16(); test(); test(); - IF( ( model_m[pos + 1] == 0 && scp > 0 ) || model_m[pos] == model_m[pos + 1] ) + IF( ( model_m[pos + 1] == 0 && scp > 0 ) || EQ_16( model_m[pos], model_m[pos + 1] ) ) { model_m[pos + 1] = 0; move16(); @@ -1988,7 +1988,7 @@ Word32 encode_magnitude_tcq_fx( move16(); bits_fx = L_deposit_l( 0 ); - tcq_bits_fx = L_sub( table_logcum_fx[npulses], L_add( table_logcum_fx[nzpos], table_logcum_fx[sub( npulses, sub( nzpos, 1 ) )] ) ); + tcq_bits_fx = L_sub( table_logcum_fx[npulses], L_add( table_logcum_fx[nzpos], table_logcum_fx[npulses - nzpos - 1] ) ); *est_frame_bits_fx = L_add( *est_frame_bits_fx, tcq_bits_fx ); move32(); @@ -2066,7 +2066,7 @@ Word32 encode_magnitude_tcq_fx( } } - leftnz--; + leftnz = sub( leftnz, 1 ); move16(); leftp = sub( leftp, abs_s( magn_fx[i] ) ); } @@ -2145,8 +2145,8 @@ void decode_position_ari_fx( /*calculate the probability of #nz */ pnzp_fx = L_sub( L_deposit_h( add( i, 1 ) ), btcq_fx ); - pnzp_fx = L_add( pnzp_fx, L_add( L_sub( table_logcum_fx[size + 1], L_add( table_logcum_fx[i + 2], table_logcum_fx[sub( size, i )] ) ), - L_sub( table_logcum_fx[npulses], L_add( table_logcum_fx[i + 1], table_logcum_fx[sub( npulses, i )] ) ) ) ); + pnzp_fx = L_add( pnzp_fx, L_add( L_sub( table_logcum_fx[size + 1], L_add( table_logcum_fx[i + 2], table_logcum_fx[size - i] ) ), + L_sub( table_logcum_fx[npulses], L_add( table_logcum_fx[i + 1], table_logcum_fx[npulses - i] ) ) ) ); pnzp_fx = L_add( pnzp_fx, 917498 ); /*16 */ IF( GT_32( pnzp_fx, 0 ) ) { @@ -2172,7 +2172,7 @@ void decode_position_ari_fx( move16(); nzp = *nz; move16(); - IF( nzp == 1 ) + IF( EQ_16( nzp, 1 ) ) { mode_num_nz[0] = MAX_AR_FREQ; move16(); @@ -2212,13 +2212,13 @@ void decode_position_ari_fx( cp = L_sub( fxone, div_l( L_deposit_h( nzp ), sub( size, i ) ) ); } scp = Mult_32_16( scp, extract_l( cp ) ); - mode_num_nz[sub( sub( add( i, 1 ), storepos ), stpos )] = round_fx( L_shl( scp, 6 ) ); + mode_num_nz[i + 1 - storepos - stpos] = round_fx( L_shl( scp, 6 ) ); test(); test(); - IF( ( mode_num_nz[sub( sub( add( i, 1 ), storepos ), stpos )] == 0 && scp > 0 ) || EQ_16( mode_num_nz[sub( sub( i, storepos ), stpos )], mode_num_nz[sub( sub( add( i, 1 ), storepos ), stpos )] ) ) + IF( ( mode_num_nz[i + 1 - storepos - stpos] == 0 && scp > 0 ) || EQ_16( mode_num_nz[i - storepos - stpos], mode_num_nz[i + 1 - storepos - stpos] ) ) { - mode_num_nz[sub( sub( add( i, 1 ), storepos ), stpos )] = 0; + mode_num_nz[i + 1 - storepos - stpos] = 0; move16(); ovrflag = 1; move16(); @@ -2226,7 +2226,7 @@ void decode_position_ari_fx( storepos = add( storepos, temppos ); scp = L_add( fxp1, 0 ); - IF( temppos == sub( i, stpos ) ) /* esc transmitted */ + IF( EQ_16( temppos, sub( i, stpos ) ) ) /* esc transmitted */ { i = sub( i, 1 ); move16(); @@ -2358,17 +2358,17 @@ void decode_magnitude_usq_fx( cp = L_sub( fxone, div_l( L_deposit_h( magnzp ), sub( magnp, i ) ) ); } - IF( cp == fxone ) + IF( EQ_32( cp, fxone ) ) { BREAK; } scp = Mult_32_16( scp, extract_l( cp ) ); - mmodel[sub( add( i, 1 ), storemagn )] = round_fx( L_shl( scp, 6 ) ); + mmodel[i + 1 - storemagn] = round_fx( L_shl( scp, 6 ) ); move16(); test(); test(); - IF( ( mmodel[sub( add( i, 1 ), storemagn )] == 0 && scp > 0 ) || EQ_16( mmodel[sub( i, storemagn )], mmodel[sub( add( i, 1 ), storemagn )] ) ) + IF( ( mmodel[i + 1 - storemagn] == 0 && scp > 0 ) || EQ_16( mmodel[i - storemagn], mmodel[i + 1 - storemagn] ) ) { mmodel[sub( add( i, 1 ), storemagn )] = 0; move16(); @@ -2376,7 +2376,7 @@ void decode_magnitude_usq_fx( tempmagn = ar_decode_fx( pardec, mmodel ); storemagn = add( storemagn, tempmagn ); - IF( tempmagn < i ) + IF( LT_16( tempmagn, i ) ) { /* just magnitude */ ovrflag = 1; @@ -2394,12 +2394,12 @@ void decode_magnitude_usq_fx( IF( ovrflag ) { - out[magncout] = storemagn + 1; + out[magncout] = add( storemagn, 1 ); move16(); } ELSE { - out[magncout] = ar_decode_fx( pardec, mmodel ) + storemagn + 1; + out[magncout] = add( add( ar_decode_fx( pardec, mmodel ), storemagn ), 1 ); move16(); } magnp = sub( magnp, out[magncout] ); @@ -2425,7 +2425,7 @@ void decode_magnitude_usq_fx( } } } - ELSE IF( magnzp == magnp ) /* rest magnitudes generation */ + ELSE IF( EQ_16( magnzp, magnp ) ) /* rest magnitudes generation */ { FOR( pos = add( pos, 1 ); pos < size; pos++ ) { @@ -2471,7 +2471,7 @@ void decode_mangitude_tcq_fx( move16(); bits_fx = L_deposit_l( 0 ); - tcq_bits_fx = L_sub( table_logcum_fx[npulses], L_add( table_logcum_fx[nzpos], table_logcum_fx[sub( npulses, sub( nzpos, 1 ) )] ) ); + tcq_bits_fx = L_sub( table_logcum_fx[npulses], L_add( table_logcum_fx[nzpos], table_logcum_fx[npulses - nzpos - 1] ) ); IF( EQ_16( nzpos, npulses ) ) { @@ -2671,7 +2671,7 @@ Word16 GetScale_fx( ab = L_add( a, b ); - p_est = extract_h( L_shl( Pow2( extract_l( L_shr( ab, 15 ) ), ab & 0x7FFF ), 16 ) ); /* enable saturationof pow2 result */ + p_est = extract_h( L_shl( Pow2( extract_l( L_shr( ab, 15 ) ), L_and( ab, 0x7FFF ) ), 16 ) ); /* enable saturationof pow2 result */ pulses = s_min( p_est, MAX_PULSES ); diff --git a/lib_com/tcx_mdct_fx.c b/lib_com/tcx_mdct_fx.c index c45513511..beb8ba489 100644 --- a/lib_com/tcx_mdct_fx.c +++ b/lib_com/tcx_mdct_fx.c @@ -228,7 +228,7 @@ void TCX_MDST( } void TCX_MDCT_Inverse( - Word32 *x, /* exp(x_e) */ + Word32 *x, // Q( 31 - x_e ) Word16 x_e, Word16 *y, /* Qy */ const Word16 l, /* Q0 */ diff --git a/lib_com/tec_com.c b/lib_com/tec_com.c index 1d20ae9f6..c51a2cd02 100644 --- a/lib_com/tec_com.c +++ b/lib_com/tec_com.c @@ -64,9 +64,9 @@ void resetTecEnc_Fx( TEC_ENC_HANDLE hTecEnc, Word16 flag ) *-------------------------------------------------------------------*/ static Word32 calcVar_Fix( - const Word32 in[], - const Word32 len, - Word32 *x ) + const Word32 in[], /*Q7*/ + const Word32 len, /*Q0*/ + Word32 *x /*Q7*/ ) { Word32 xx; Word32 i; @@ -83,31 +83,31 @@ static Word32 calcVar_Fix( exp1 = norm_l( in[i] ); r_sft = sub( add( exp1, exp1 ), 24 ); - tmpX = L_shr( Mpy_32_32( L_shl( in[i], exp1 ), L_shl( in[i], exp1 ) ), r_sft ); - xx = L_add( xx, tmpX ); - *x = L_add( *x, in[i] ); + tmpX = L_shr( Mpy_32_32( L_shl( in[i], exp1 ), L_shl( in[i], exp1 ) ), r_sft ); /*Q7*/ + xx = L_add( xx, tmpX ); /*Q7*/ + *x = L_add( *x, in[i] ); /*Q7*/ move32(); } ans = L_deposit_l( 0 ); exp1 = norm_l( *x ); r_sft = sub( add( exp1, exp1 ), 24 ); - tmpX = Mpy_32_32( L_shl( *x, exp1 ), L_shl( *x, exp1 ) ); - tmpX = L_shr( tmpX, r_sft ); + tmpX = Mpy_32_32( L_shl( *x, exp1 ), L_shl( *x, exp1 ) ); /*2*(Q7 + exp1) - 31*/ + tmpX = L_shr( tmpX, r_sft ); /*Q7*/ IF( len == 0 ) { return 0; } ELSE IF( EQ_32( len, 16 ) ) { - ans = L_sub( xx, L_shr( tmpX, 4 ) ); + ans = L_sub( xx, L_shr( tmpX, 4 ) ); /*Q7*/ } ELSE { /* Len = 16 Only */ ans = L_deposit_l( 0 ); } - return ans; + return ans; /*Q7*/ } /*------------------------------------------------------------------- * calcCorrelationCoefficient2() @@ -116,13 +116,13 @@ static Word32 calcVar_Fix( *-------------------------------------------------------------------*/ static Word32 calcCorrelationCoefficient2_Fix( - const Word32 in_vec1[], - const Word32 in_vec2[], - const Word32 len, - Word32 var_x, - Word32 var_y, - Word32 x, - Word32 y ) + const Word32 in_vec1[], /*Q7*/ + const Word32 in_vec2[], /*Q7*/ + const Word32 len, /*Q0*/ + Word32 var_x, /*Q7*/ + Word32 var_y, /*Q7*/ + Word32 x, /*Q7*/ + Word32 y /*Q7*/ ) { Word16 i; @@ -146,8 +146,8 @@ static Word32 calcCorrelationCoefficient2_Fix( exp1 = norm_l( in_vec1[i] ); exp2 = norm_l( in_vec2[i] ); r_sft = sub( add( exp1, exp2 ), 24 ); - tmpXY = L_shr( Mpy_32_32( L_shl( in_vec1[i], exp1 ), L_shl( in_vec2[i], exp2 ) ), r_sft ); - xy = L_add( xy, tmpXY ); + tmpXY = L_shr( Mpy_32_32( L_shl( in_vec1[i], exp1 ), L_shl( in_vec2[i], exp2 ) ), r_sft ); /*Q7*/ + xy = L_add( xy, tmpXY ); /*Q7*/ } @@ -156,8 +156,8 @@ static Word32 calcCorrelationCoefficient2_Fix( exp1 = norm_l( x ); exp2 = norm_l( y ); r_sft = sub( add( exp1, exp2 ), 24 ); - xy2 = L_shr( Mpy_32_32( L_shl( x, exp1 ), L_shl( y, exp2 ) ), r_sft + 4 ); - Val1 = L_sub( xy, xy2 ); + xy2 = L_shr( Mpy_32_32( L_shl( x, exp1 ), L_shl( y, exp2 ) ), r_sft + 4 ); /*Q7*/ + Val1 = L_sub( xy, xy2 ); /*Q7*/ test(); IF( var_x == 0 || var_y == 0 ) @@ -170,26 +170,26 @@ static Word32 calcCorrelationCoefficient2_Fix( Word32 sqrtVal1; Word32 sqrtVal2; exp1 = norm_l( var_x ); - if ( ( exp1 & 0x1 ) != 0 ) + if ( s_and( exp1, 0x1 ) != 0 ) { exp1 = sub( exp1, 1 ); } exp2 = norm_l( var_y ); - if ( ( exp2 & 0x1 ) != 0 ) + if ( s_and( exp2, 0x1 ) != 0 ) { exp2 = sub( exp2, 1 ); } - sqrtVal1 = Sqrt_l( L_shl( var_x, exp1 ), &exp3 ); - sqrtVal1 = L_shr( sqrtVal1, ( shr( add( exp1, 24 ), 1 ) ) ); - sqrtVal2 = Sqrt_l( L_shl( var_y, exp2 ), &exp4 ); - sqrtVal2 = L_shr( sqrtVal2, ( shr( add( exp2, 24 ), 1 ) ) ); + sqrtVal1 = Sqrt_l( L_shl( var_x, exp1 ), &exp3 ); /*Q7 + exp1*/ + sqrtVal1 = L_shr( sqrtVal1, ( shr( add( exp1, 24 ), 1 ) ) ); /*Q7*/ + sqrtVal2 = Sqrt_l( L_shl( var_y, exp2 ), &exp4 ); /*Q7 + exp1*/ + sqrtVal2 = L_shr( sqrtVal2, ( shr( add( exp2, 24 ), 1 ) ) ); /*Q7*/ exp1 = norm_l( sqrtVal1 ); exp2 = norm_l( sqrtVal2 ); r_sft = sub( add( exp1, exp2 ), 24 ); - Val2 = L_shr( Mpy_32_32( L_shl( sqrtVal1, exp1 ), L_shl( sqrtVal2, exp2 ) ), r_sft ); + Val2 = L_shr( Mpy_32_32( L_shl( sqrtVal1, exp1 ), L_shl( sqrtVal2, exp2 ) ), r_sft ); /*Q7*/ exp1 = sub( norm_l( Val1 ), 1 ); exp2 = norm_l( Val2 ); @@ -197,11 +197,11 @@ static Word32 calcCorrelationCoefficient2_Fix( test(); if ( Val1 != 0 && Val2 != 0 ) { - tmpCor = divide3232( L_shl( Val1, exp1 ), L_shl( Val2, exp2 ) ); + tmpCor = divide3232( L_shl( Val1, exp1 ), L_shl( Val2, exp2 ) ); /*Q15 - (exp2 - exp1)*/ } r_sft = sub( 8, sub( exp2, exp1 ) ); - tmpCor = L_shr( tmpCor, r_sft ); + tmpCor = L_shr( tmpCor, r_sft ); /*Q7*/ ans = tmpCor; move16(); } @@ -213,7 +213,7 @@ static Word32 calcCorrelationCoefficient2_Fix( } - return ans; + return ans; /*Q7*/ } /*------------------------------------------------------------------- * calcLoBufferEnc() @@ -223,10 +223,10 @@ static Word32 calcCorrelationCoefficient2_Fix( static void calcLoBufferEnc_Fx( Word32 **pCldfbPow_Fx, /* Q31 */ const Word16 scale, - const Word16 startPos, - const Word16 stopPos, - const Word16 bandOffsetBottom, - Word16 *loBuffer /* Q8 = Q(15 - (LD_DATA_SCALE + 1)) */ + const Word16 startPos, /*Q0*/ + const Word16 stopPos, /*Q0*/ + const Word16 bandOffsetBottom, /*Q0*/ + Word16 *loBuffer /* Q8 = Q(15 - (LD_DATA_SCALE + 1)) */ ) { Word16 lb; @@ -245,7 +245,7 @@ static void calcLoBufferEnc_Fx( FOR( lb = 0; lb < NBTECLOWBAND; lb++ ) { - li = TecLowBandTable[lb]; + li = TecLowBandTable[lb]; /*Q0*/ move16(); ui = sub( TecLowBandTable[lb + 1], 1 ); @@ -253,7 +253,7 @@ static void calcLoBufferEnc_Fx( /* sum up maximum of 2 nrg values, thus leave 1 bits headroom */ nrg = L_add( L_shr( pCldfbPow_Fx[slot][li + bandOffsetBottom], 1 ), - L_shr( pCldfbPow_Fx[slot][ui + bandOffsetBottom], 1 ) ); + L_shr( pCldfbPow_Fx[slot][ui + bandOffsetBottom], 1 ) ); /*Q31 - scale*/ /* assemble log2(EPS) */ @@ -263,7 +263,7 @@ static void calcLoBufferEnc_Fx( IF( nrg != 0 ) { /* assemble log2 value and shift factor */ - nrgLog = L_sub( L_shr( BASOP_Util_Log2( nrg ), 1 ), L_shl( scale, ( WORD32_BITS - 1 ) - ( LD_DATA_SCALE + 1 ) ) ); + nrgLog = L_sub( L_shr( BASOP_Util_Log2( nrg ), 1 ), L_shl( scale, ( WORD32_BITS - 1 ) - ( LD_DATA_SCALE + 1 ) ) ); /*Q31*/ /* /\* assemble log2 value and shift factor *\/ */ /* nrgLog = L_shr(BASOP_Util_Log2(nrg),1); */ @@ -273,7 +273,7 @@ static void calcLoBufferEnc_Fx( } /* 0.50171665944 = 10 * log10(2.0) / NbTecLowBand / 2.0 */ - loBuffer[slot] = extract_h( L_shl( Mpy_32_16_1( tmp, 16440 /*0.50171665944 Q15*/ ), 1 ) ); + loBuffer[slot] = extract_h( L_shl( Mpy_32_16_1( tmp, 16440 /*0.50171665944 Q15*/ ), 1 ) ); /* Q8 = Q(15 - (LD_DATA_SCALE + 1)) */ move16(); } } @@ -286,11 +286,11 @@ static void calcLoBufferEnc_Fx( static void calcHiTempEnv_Fx( Word32 **pCldfbPow, /* Q31 */ Word16 scale, - const Word16 startPos, - const Word16 stopPos, - const Word16 lowSubband, - const Word16 highSubband, - Word16 *hiTempEnv /* Q7 = Q(15 - (LD_DATA_SCALE + 2)) */ + const Word16 startPos, /*Q0*/ + const Word16 stopPos, /*Q0*/ + const Word16 lowSubband, /*Q0*/ + const Word16 highSubband, /*Q0*/ + Word16 *hiTempEnv /* Q7 = Q(15 - (LD_DATA_SCALE + 2)) */ ) { Word16 k; @@ -305,7 +305,7 @@ static void calcHiTempEnv_Fx( s1 = 3; move16(); - bwHigh = sub( highSubband, lowSubband ); + bwHigh = sub( highSubband, lowSubband ); /*Q0*/ normFac = getNormReciprocalWord16( bwHigh ); @@ -318,7 +318,7 @@ static void calcHiTempEnv_Fx( FOR( k = lowSubband; k < highSubband; k++ ) { #ifdef BASOP_NOGLOB - nrg = L_add_sat( nrg, L_shr( pCldfbPow[timeIndex][k], s1 ) ); + nrg = L_add_sat( nrg, L_shr( pCldfbPow[timeIndex][k], s1 ) ); /*Q31 - s1*/ #else nrg = L_add( nrg, L_shr( pCldfbPow[timeIndex][k], s1 ) ); #endif @@ -326,7 +326,7 @@ static void calcHiTempEnv_Fx( s2 = norm_l( nrg ); - nrg = L_shl( nrg, s2 ); + nrg = L_shl( nrg, s2 ); /*Q31 - s1 + s2*/ /* assemble log2(EPS) */ nrgLog = -668792462l /*-0.31143075889 Q31*/; @@ -335,12 +335,12 @@ static void calcHiTempEnv_Fx( if ( nrg != 0 ) { /* assemble log2 value and shift factor */ - nrgLog = L_shr( BASOP_Util_Log2( Mpy_32_16_1( nrg, normFac ) ), 1 ); - nrgLog = L_sub( nrgLog, L_shl( add( scale, s2 ), ( WORD32_BITS - 1 ) - ( LD_DATA_SCALE + 1 ) ) ); + nrgLog = L_shr( BASOP_Util_Log2( Mpy_32_16_1( nrg, normFac ) ), 1 ); /*Q31 - ( scale + s2 )*/ + nrgLog = L_sub( nrgLog, L_shl( add( scale, s2 ), ( WORD32_BITS - 1 ) - ( LD_DATA_SCALE + 1 ) ) ); /*Q31 - ( LD_DATA_SCALE + 1 )*/ } /* 0.75257498916 = 10 * log10(2.0) / 4.0 */ - hiTempEnv[timeIndex] = extract_h( L_shr( L_shl( Mpy_32_16_1( nrgLog, 24660 /*0.75257498916 Q15*/ ), 2 ), 1 ) ); + hiTempEnv[timeIndex] = extract_h( L_shr( L_shl( Mpy_32_16_1( nrgLog, 24660 /*0.75257498916 Q15*/ ), 2 ), 1 ) ); /* Q7 = Q(15 - (LD_DATA_SCALE + 2)) */ move16(); } } @@ -351,12 +351,12 @@ static void calcHiTempEnv_Fx( *-------------------------------------------------------------------*/ static void calcLoBufferDec_Fx( - Word32 **pCldfbReal, - Word32 **pCldfbImag, - Word16 *loBuffer, - const Word16 startPos, - const Word16 stopPos, - const Word16 offset, + Word32 **pCldfbReal, /*scale*/ + Word32 **pCldfbImag, /*scale*/ + Word16 *loBuffer, /*Q15 - ( LD_DATA_SCALE + 1 )*/ + const Word16 startPos, /*Q0*/ + const Word16 stopPos, /*Q0*/ + const Word16 offset, /*Q0*/ const Word16 scale ) { Word16 k; @@ -378,9 +378,9 @@ static void calcLoBufferDec_Fx( Word16 li; Word16 ui; - li = TecLowBandTable[lb]; + li = TecLowBandTable[lb]; /*Q0*/ move16(); - ui = TecLowBandTable[lb + 1]; + ui = TecLowBandTable[lb + 1]; /*Q0*/ move16(); assert( ( ui - li ) == 2 ); @@ -405,26 +405,26 @@ static void calcLoBufferDec_Fx( { Word16 val; - val = extract_h( L_shl( pCldfbReal[slot][k + offset], s1 ) ); - nrg32 = L_mac( nrg32, val, val ); - val = extract_h( L_shl( pCldfbImag[slot][k + offset], s1 ) ); - nrg32 = L_mac( nrg32, val, val ); + val = extract_h( L_shl( pCldfbReal[slot][k + offset], s1 ) ); /*scale+s1-16*/ + nrg32 = L_mac( nrg32, val, val ); /*2*(scale+s1-16)*/ + val = extract_h( L_shl( pCldfbImag[slot][k + offset], s1 ) ); /*scale+s1-16*/ + nrg32 = L_mac( nrg32, val, val ); /*2*(scale+s1-16)*/ } /* square(scale) + square(s1) + 1(inv_bw = 0.5) */ s2 = add( shl( add( scale, s1 ), 1 ), 1 ); /* assemble log value */ - tmp = L_add( tmp, L_shr( BASOP_Util_Log2( nrg32 ), 1 ) ); + tmp = L_add( tmp, L_shr( BASOP_Util_Log2( nrg32 ), 1 ) ); /*s2*/ /* add shift factors */ - tmp = L_sub( tmp, L_shl( s2, ( WORD32_BITS - 1 ) - ( LD_DATA_SCALE + 1 ) ) ); + tmp = L_sub( tmp, L_shl( s2, ( WORD32_BITS - 1 ) - ( LD_DATA_SCALE + 1 ) ) ); /*Q31 - ( LD_DATA_SCALE + 1 )*/ /* add scale of reference */ tmp = L_add( tmp, L_shl( 30, ( WORD32_BITS - 1 ) - ( LD_DATA_SCALE + 1 ) ) ); /* 0.50171665944 = 10 * log10(2.0) / NbTecLowBand / 2.0 */ - loBuffer[slot] = extract_h( L_shl( Mpy_32_16_1( tmp, 16440 /*0.50171665944 Q15*/ ), 1 ) ); + loBuffer[slot] = extract_h( L_shl( Mpy_32_16_1( tmp, 16440 /*0.50171665944 Q15*/ ), 1 ) ); /*Q15 - ( LD_DATA_SCALE + 1 )*/ move16(); } ELSE @@ -442,10 +442,10 @@ static void calcLoBufferDec_Fx( * *-------------------------------------------------------------------*/ static void calcLoTempEnv_Fx( - Word16 *loBuffer_Fx, /* Q8 = Q(15 - (LD_DATA_SCALE+1)) */ - const Word16 noCols, + Word16 *loBuffer_Fx, /* Q8 = Q(15 - (LD_DATA_SCALE+1)) */ + const Word16 noCols, /*Q0*/ Word16 *loTempEnv_Fx, /* Q7 = Q(15 - (LD_DATA_SCALE+2)) */ - const Word16 adjFac_Fx ) + const Word16 adjFac_Fx /*Q15*/ ) { Word16 i; Word16 slot; @@ -454,13 +454,13 @@ static void calcLoTempEnv_Fx( /* TecSC_Fx values are scaled by factor 2.0 */ FOR( slot = 0; slot < noCols; slot++ ) { - accu = L_mult0( TecSC_Fx[0], loBuffer_Fx[slot] ); + accu = L_mult0( TecSC_Fx[0], loBuffer_Fx[slot] ); /*Q23*/ FOR( i = 1; i < TECSMOOTHINGDEG + 1; i++ ) { - accu = L_mac0( accu, TecSC_Fx[i], loBuffer_Fx[sub( slot, i )] ); + accu = L_mac0( accu, TecSC_Fx[i], loBuffer_Fx[( slot - i )] ); /*Q23*/ } /* adjFac is scaled by factor 0.5 */ - loTempEnv_Fx[slot] = extract_h( Mpy_32_16_1( accu, adjFac_Fx ) ); + loTempEnv_Fx[slot] = extract_h( Mpy_32_16_1( accu, adjFac_Fx ) ); /*Q7*/ move16(); } } @@ -471,7 +471,7 @@ static void calcLoTempEnv_Fx( *-------------------------------------------------------------------*/ static void calcLoTempEnv_ns_Fx( Word16 *loBuffer_Fx, /* Q8 = Q(15 - (LD_DATA_SCALE+1)) */ - const Word16 noCols, + const Word16 noCols, /*Q0*/ Word16 *loTempEnv_Fx /* Q7 = Q(15 - (LD_DATA_SCALE+2)) */ ) { @@ -479,7 +479,7 @@ static void calcLoTempEnv_ns_Fx( FOR( slot = 0; slot < noCols; slot++ ) { - loTempEnv_Fx[slot] = shr( loBuffer_Fx[slot], 1 ); + loTempEnv_Fx[slot] = shr( loBuffer_Fx[slot], 1 ); /*Q7*/ move16(); } @@ -491,10 +491,10 @@ static void calcLoTempEnv_ns_Fx( * *-------------------------------------------------------------------*/ static void calcLoTempEnv_TBE_Fx( - Word16 *loBuffer_Fx, /* Q8 = Q(15 - (LD_DATA_SCALE+1)) */ - const Word16 noCols, + Word16 *loBuffer_Fx, /* Q8 = Q(15 - (LD_DATA_SCALE+1)) */ + const Word16 noCols, /*Q0*/ Word16 *loTempEnv_Fx, /* Q7 = Q(15 - (LD_DATA_SCALE+2)) */ - const Word16 adjFac_Fx ) + const Word16 adjFac_Fx /*Q15*/ ) { Word16 i; Word16 slot; @@ -505,13 +505,13 @@ static void calcLoTempEnv_TBE_Fx( /* TecSC_Fx values are scaled by factor 2.0 */ FOR( slot = 0; slot < noCols; slot++ ) { - accu = L_mult0( TecSC_Fx[0], loBuffer_Fx[slot - delay] ); + accu = L_mult0( TecSC_Fx[0], loBuffer_Fx[slot - delay] ); /*Q23*/ FOR( i = 1; i < TECSMOOTHINGDEG + 1; i++ ) { - accu = L_mac0( accu, TecSC_Fx[i], loBuffer_Fx[slot - i - delay] ); + accu = L_mac0( accu, TecSC_Fx[i], loBuffer_Fx[slot - i - delay] ); /*Q23*/ } /* adjFac is scaled by factor 0.5 */ - loTempEnv_Fx[slot] = extract_h( Mpy_32_16_1( accu, adjFac_Fx ) ); + loTempEnv_Fx[slot] = extract_h( Mpy_32_16_1( accu, adjFac_Fx ) ); /*Q7*/ move16(); } } @@ -523,7 +523,7 @@ static void calcLoTempEnv_TBE_Fx( static void calcLoTempEnv_ns_TBE_Fx( Word16 *loBuffer_Fx, /* Q8 = Q(15 - (LD_DATA_SCALE+1)) */ - const Word16 noCols, + const Word16 noCols, /*Q0*/ Word16 *loTempEnv_Fx /* Q7 = Q(15 - (LD_DATA_SCALE+2)) */ ) { @@ -535,7 +535,7 @@ static void calcLoTempEnv_ns_TBE_Fx( FOR( slot = 0; slot < noCols; slot++ ) { /* fac is scaled by factor 0.5 */ - loTempEnv_Fx[slot] = mult_r( fac, loBuffer_Fx[sub( slot, delay )] ); + loTempEnv_Fx[slot] = mult_r( fac, loBuffer_Fx[( slot - delay )] ); /*Q7*/ move16(); } @@ -548,10 +548,10 @@ static void calcLoTempEnv_ns_TBE_Fx( *-------------------------------------------------------------------*/ static void calcGainLinear_TBE_Fx( const Word16 *loTempEnv_m, /* Q7 = Q(15 - (LD_DATA_SCALE+2)) */ - const Word16 startPos, - const Word16 stopPos, - Word16 *pGainTemp_m, /* Q0 */ - Word16 *pGainTemp_e /* Q0 */ + const Word16 startPos, /*Q0*/ + const Word16 stopPos, /*Q0*/ + Word16 *pGainTemp_m, /* Q0 */ + Word16 *pGainTemp_e /* Q0 */ ) { @@ -574,7 +574,7 @@ static void calcGainLinear_TBE_Fx( move16(); /* adapt scale to LD_DATA_SCALE */ - tmp32 = L_shl( L_mult( c, loTempEnv_m[slot] ), 1 ); + tmp32 = L_shl( L_mult( c, loTempEnv_m[slot] ), 1 ); /*Q31*/ IF( tmp32 > 0 ) { @@ -589,19 +589,19 @@ static void calcGainLinear_TBE_Fx( } /* scalefactor for logarithmic domain */ - logScaleFactor = L_shl( L_mult0( 512 /*1.0/(1< 0 ) { Word16 tmp; s = norm_l( nrg32 ); - tmp = extract_h( L_shl( nrg32, s ) ); + tmp = extract_h( L_shl( nrg32, s ) ); /*Q15 - 2*(exp_syn) - s2 + s*/ enr_m[i] = tmp; move16(); enr_e[i] = -s; @@ -778,7 +778,7 @@ static Word16 calcSubfrNrg_Fx( sum16_e = enr_e[i_offset]; move16(); - *sum16_m = enr_m[i_offset]; + *sum16_m = enr_m[i_offset]; /*Q15 - enr_e*/ move16(); FOR( i = i_offset + 1; i < N_TEC_TFA_SUBFR; i++ ) { @@ -808,13 +808,13 @@ static Word16 calcSubfrNrg_Fx( *-------------------------------------------------------------------*/ static Word16 procTec_Fx( - Word16 *hb_synth_Fx, + Word16 *hb_synth_Fx, /*Q15 - exp_syn*/ Word16 exp_syn, - Word16 *gain_m, + Word16 *gain_m, /*Q15 - gain_e*/ Word16 *gain_e, - const Word16 i_offset, - const Word16 l_subfr, - const Word16 code ) + const Word16 i_offset, /*Q0*/ + const Word16 l_subfr, /*Q0*/ + const Word16 code /*Q0*/ ) { Word16 i, j, k; Word16 k_offset, n_subfr; @@ -863,7 +863,7 @@ static Word16 procTec_Fx( &enr_ave_m, l_subfr ); /* divided by n_subfr */ - enr_ave_m = mult_r( enr_ave_m, inv_n_subfr ); + enr_ave_m = mult_r( enr_ave_m, inv_n_subfr ); /*Q15 - enr_ave_e + 3*/ enr_ave_e = sub( enr_ave_e, 3 ); /* calculate the average of gain */ @@ -872,7 +872,7 @@ static Word16 procTec_Fx( n_subfr, &gain_ave_m ); - gain_ave_m = mult_r( gain_ave_m, inv_n_subfr ); + gain_ave_m = mult_r( gain_ave_m, inv_n_subfr ); /*Q15 - enr_ave_e + 3*/ gain_ave_e = sub( gain_ave_e, 3 ); k = k_offset; @@ -895,7 +895,7 @@ static Word16 procTec_Fx( } s = norm_s( inv_curr_enr_m[i] ); - inv_curr_enr_m[i] = shl( inv_curr_enr_m[i], s ); + inv_curr_enr_m[i] = shl( inv_curr_enr_m[i], s ); /*Q15 - inv_curr_enr_e + s*/ move16(); inv_curr_enr_e[i] = sub( inv_curr_enr_e[i], s ); move16(); @@ -922,7 +922,7 @@ static Word16 procTec_Fx( { test(); test(); - IF( ( max_inv_curr_enr_e < inv_curr_enr_e[i] ) || ( max_inv_curr_enr_e == inv_curr_enr_e[i] && max_inv_curr_enr_m < inv_curr_enr_m[i] ) ) + IF( LT_16( max_inv_curr_enr_e, inv_curr_enr_e[i] ) || ( EQ_16( max_inv_curr_enr_e, inv_curr_enr_e[i] ) && LT_16( max_inv_curr_enr_m, inv_curr_enr_m[i] ) ) ) { max_inv_curr_enr_e = inv_curr_enr_e[i]; move16(); @@ -937,7 +937,7 @@ static Word16 procTec_Fx( &min_curr_enr_m, &min_curr_enr_e ); s = norm_s( min_curr_enr_m ); - min_curr_enr_m = shl( min_curr_enr_m, s ); + min_curr_enr_m = shl( min_curr_enr_m, s ); /*Q15 - min_curr_enr_e + s*/ min_curr_enr_e = sub( min_curr_enr_e, s ); lower_limit_gain_e = -3; @@ -978,19 +978,19 @@ static Word16 procTec_Fx( test(); IF( ( GT_16( lower_limit_gain_e, gain_e[i] ) ) || ( EQ_16( lower_limit_gain_e, gain_e[i] ) && GT_16( lower_limit_gain_m, gain_m[i] ) ) ) { - gain_m[i] = lower_limit_gain_m; + gain_m[i] = lower_limit_gain_m; /*Q15 - gain_e*/ move16(); gain_e[i] = lower_limit_gain_e; move16(); } - gain_m[i] = mult_r( gain_m[i], inv_curr_enr_m[i] ); + gain_m[i] = mult_r( gain_m[i], inv_curr_enr_m[i] ); /*Q15 - gain_e - inv_curr_enr_e*/ move16(); gain_e[i] = add( gain_e[i], inv_curr_enr_e[i] ); move16(); s = norm_s( gain_m[i] ); - gain_m[i] = shl( gain_m[i], s ); + gain_m[i] = shl( gain_m[i], s ); /*Q15 - gain_e + s*/ move16(); gain_e[i] = sub( gain_e[i], s ); move16(); @@ -1000,16 +1000,16 @@ static Word16 procTec_Fx( IF( ( LT_16( upper_limit_gain_e, gain_e[i] ) ) || ( EQ_16( upper_limit_gain_e, gain_e[i] ) && LT_16( upper_limit_gain_m, gain_m[i] ) ) ) { - gain_m[i] = upper_limit_gain_m; + gain_m[i] = upper_limit_gain_m; /*Q15 - gain_e*/ move16(); gain_e[i] = upper_limit_gain_e; move16(); } - gain_m[i] = Sqrt16( gain_m[i], &gain_e[i] ); + gain_m[i] = Sqrt16( gain_m[i], &gain_e[i] ); /*Q15 - gain_e*/ move16(); s = norm_s( gain_m[i] ); - gain_m[i] = shl( gain_m[i], s ); + gain_m[i] = shl( gain_m[i], s ); /*Q15 - gain_e + s*/ move16(); gain_e[i] = sub( gain_e[i], s ); move16(); @@ -1017,9 +1017,10 @@ static Word16 procTec_Fx( FOR( j = 0; j < l_subfr; j++ ) { s = norm_s( hb_synth_Fx[k] ); - hb_synth_Fx[k] = mult_r( gain_m[i], shl( hb_synth_Fx[k], s ) ); + hb_synth_Fx[k] = mult_r( gain_m[i], shl( hb_synth_Fx[k], s ) ); /*Q15 - gain_e - exp_syn + s*/ move16(); shift[k] = sub( s, gain_e[i] ); + move16(); if ( GT_16( min_shift, shift[k] ) ) { @@ -1058,7 +1059,7 @@ static Word16 procTec_Fx( if ( s > 0 ) { - hb_synth_Fx[k] = shr( hb_synth_Fx[k], s ); + hb_synth_Fx[k] = shr( hb_synth_Fx[k], s ); /*Q15 - exp_syn - s*/ move16(); } k = add( k, 1 ); @@ -1073,10 +1074,10 @@ static Word16 procTec_Fx( * *-------------------------------------------------------------------*/ static Word16 procTfa_Fx( - Word16 *hb_synth_Fx, + Word16 *hb_synth_Fx, /*Q15 - exp_syn*/ Word16 exp_syn, - const Word16 i_offset, - const Word16 l_subfr ) + const Word16 i_offset, /*Q0*/ + const Word16 l_subfr /*Q0*/ ) { Word16 i, j, k; Word16 k_offset, n_subfr; @@ -1109,7 +1110,7 @@ static Word16 procTfa_Fx( k_offset, &enr_ave_m, l_subfr ); - enr_ave_m = mult_r( enr_ave_m, inv_n_subfr ); + enr_ave_m = mult_r( enr_ave_m, inv_n_subfr ); /*Q15 - enr_ave_e + 3*/ enr_ave_e = sub( enr_ave_e, 3 ); min_shift = 15; /* min_shift <= 15 */ @@ -1134,11 +1135,11 @@ static Word16 procTfa_Fx( move16(); } - gain_m[i] = Sqrt16( gain_m[i], &gain_e[i] ); + gain_m[i] = Sqrt16( gain_m[i], &gain_e[i] ); /*Q15 - gain_e*/ move16(); s = norm_s( gain_m[i] ); - gain_m[i] = shl( gain_m[i], s ); + gain_m[i] = shl( gain_m[i], s ); /*Q15 - gain_e + s*/ move16(); gain_e[i] = sub( gain_e[i], s ); move16(); @@ -1146,7 +1147,7 @@ static Word16 procTfa_Fx( FOR( j = 0; j < l_subfr; j++ ) { s = norm_s( hb_synth_Fx[k] ); - hb_synth_Fx[k] = mult_r( gain_m[i], shl( hb_synth_Fx[k], s ) ); + hb_synth_Fx[k] = mult_r( gain_m[i], shl( hb_synth_Fx[k], s ) ); /*Q15 - gain_e - exp_syn + s*/ move16(); shift[k] = sub( s, gain_e[i] ); move16(); @@ -1188,7 +1189,7 @@ static Word16 procTfa_Fx( if ( s > 0 ) { - hb_synth_Fx[k] = shr( hb_synth_Fx[k], s ); + hb_synth_Fx[k] = shr( hb_synth_Fx[k], s ); /*Q15 - exp_syn - s*/ move16(); } k = add( k, 1 ); @@ -1203,14 +1204,14 @@ static Word16 procTfa_Fx( * *-------------------------------------------------------------------*/ Word16 procTecTfa_TBE_Fx( - Word16 *hb_synth_Fx, + Word16 *hb_synth_Fx, /*Q15 - hb_synth_fx_exp*/ Word16 hb_synth_fx_exp, - Word16 *gain_m, + Word16 *gain_m, /*Q15 - gain_e*/ Word16 *gain_e, - Word16 flat_flag, - Word16 last_core, - Word16 l_subfr, - Word16 code ) + Word16 flat_flag, /*Q0*/ + Word16 last_core, /*Q0*/ + Word16 l_subfr, /*Q0*/ + Word16 code /*Q0*/ ) { Word16 i_offset = 0; move16(); @@ -1226,7 +1227,7 @@ Word16 procTecTfa_TBE_Fx( } ELSE { - if ( NE_16( last_core, ACELP_CORE ) ) + if ( ( last_core != ACELP_CORE ) ) { i_offset = 1; move16(); @@ -1254,12 +1255,12 @@ Word16 procTecTfa_TBE_Fx( *-------------------------------------------------------------------*/ void calcHiEnvLoBuff_Fix( - const Word16 noCols, - const Word16 *pFreqBandTable, /*!< freqbandTable. */ - const Word16 nSfb, /*!< Number of scalefactors. */ - Word32 **pCldfbPow_Fix /*Word32** pCldfbPow*/, - Word16 *loBuffer_Fix /*Word32* loBuffer Q8*/, - Word16 *hiTempEnvOrig_Fix /*Word32* hiTempEnvOrig*/, + const Word16 noCols, /*Q0*/ + const Word16 *pFreqBandTable, /*!< freqbandTable. Q0*/ + const Word16 nSfb, /*!< Number of scalefactors. Q0*/ + Word32 **pCldfbPow_Fix /* pCldfbPow_FixScale*/, + Word16 *loBuffer_Fix /* Q8*/, + Word16 *hiTempEnvOrig_Fix /* Q7*/, Word16 pCldfbPow_FixScale ) { const Word16 BW_LO = TecLowBandTable[NBTECLOWBAND]; @@ -1271,7 +1272,7 @@ void calcHiEnvLoBuff_Fix( Word16 bandOffsetBottom; - Word16 *hiTempEnv = hiTempEnvOrig_Fix + EXT_DELAY_HI_TEMP_ENV; + Word16 *hiTempEnv = hiTempEnvOrig_Fix + EXT_DELAY_HI_TEMP_ENV; /*Q7*/ move16(); move16(); @@ -1304,18 +1305,18 @@ void calcHiEnvLoBuff_Fix( * *-------------------------------------------------------------------*/ void calcLoEnvCheckCorrHiLo_Fix( - const Word16 noCols, - const Word16 *pFreqBandTable, /*!< freqbandTable. */ + const Word16 noCols, /*Q0*/ + const Word16 *pFreqBandTable, /*!< freqbandTable. Q0*/ Word16 *loBuffer_Fix /*Word16* loBuffer Q8*/, Word16 *loTempEnv_Fix /*Word16* loTempEnv Q7*/, - Word16 *loTempEnv_ns_Fix /* Word16* loTempEnv_ns*/, - Word16 *hiTempEnvOrig_Fix /*Word16* hiTempEnvOrig*/, - Word16 *corrFlag /*int* corrFlag*/ + Word16 *loTempEnv_ns_Fix /* Word16* loTempEnv_ns Q7*/, + Word16 *hiTempEnvOrig_Fix /*Word16* hiTempEnvOrig Q7*/, + Word16 *corrFlag /*int* corrFlag Q0*/ ) { const Word16 BW_LO = TecLowBandTable[NBTECLOWBAND]; move16(); - const Word16 lowSubband = pFreqBandTable[0]; + const Word16 lowSubband = pFreqBandTable[0]; /*Q0*/ move16(); Word16 i; @@ -1337,7 +1338,7 @@ void calcLoEnvCheckCorrHiLo_Fix( Word32 loVar_ns_Fix; Word32 diff_hi_lo_sum_Fix; Word32 loSum_ns_Fix; - Word16 *hiTempEnv = hiTempEnvOrig_Fix + EXT_DELAY_HI_TEMP_ENV; + Word16 *hiTempEnv = hiTempEnvOrig_Fix + EXT_DELAY_HI_TEMP_ENV; /*Q7*/ move16(); @@ -1351,10 +1352,10 @@ void calcLoEnvCheckCorrHiLo_Fix( FOR( i = 0; i < noCols + DELAY_TEMP_ENV_BUFF_TEC; i++ ) { - hiTempEnv32_Fix[i] = L_deposit_l( hiTempEnv[i] ); + hiTempEnv32_Fix[i] = L_deposit_l( hiTempEnv[i] ); /*Q7*/ move32(); } - hiVar_Fix = calcVar_Fix( hiTempEnv32_Fix, (Word32) noCols, &hiSum_Fix ); + hiVar_Fix = calcVar_Fix( hiTempEnv32_Fix, (Word32) noCols, &hiSum_Fix ); /*Q7*/ /* ============================================================ */ @@ -1375,14 +1376,14 @@ void calcLoEnvCheckCorrHiLo_Fix( loTempEnv32_ns_Fix[i] = L_deposit_l( loTempEnv_ns_Fix[i] ); move32(); } - loVar_ns_Fix = calcVar_Fix( loTempEnv32_ns_Fix, noCols, &loSum_ns_Fix ); + loVar_ns_Fix = calcVar_Fix( loTempEnv32_ns_Fix, noCols, &loSum_ns_Fix ); /*Q7*/ diff_hi_lo_sum_Fix = L_sub( loSum_ns_Fix, hiSum_Fix ); - EQ4 = L_sub( L_shr( hiVar_Fix, 7 ), 800 ); - EQ5 = L_sub( L_shr( loVar_ns_Fix, 7 ), 720 ); + EQ4 = L_sub( L_shr( hiVar_Fix, 7 ), 800 ); /*Q0*/ + EQ5 = L_sub( L_shr( loVar_ns_Fix, 7 ), 720 ); /*Q0*/ - EQ6 = L_sub( L_shr( diff_hi_lo_sum_Fix, 7 ), 100 ); + EQ6 = L_sub( L_shr( diff_hi_lo_sum_Fix, 7 ), 100 ); /*Q0*/ test(); test(); @@ -1406,9 +1407,9 @@ void calcLoEnvCheckCorrHiLo_Fix( Word16 maxPosHi, maxPosLo; Word16 maxHiFix, maxLoFix; - maxHiFix = hiTempEnv[0]; + maxHiFix = hiTempEnv[0]; /*Q7*/ move16(); - maxLoFix = loTempEnv_ns_Fix[0]; + maxLoFix = loTempEnv_ns_Fix[0]; /*Q7*/ move16(); maxPosHi = maxPosLo = 0; move16(); @@ -1447,7 +1448,7 @@ void calcLoEnvCheckCorrHiLo_Fix( Word16 j; Word16 len_window = EXT_DELAY_HI_TEMP_ENV + 1; move16(); - Word16 *curr_pos_Fix = hiTempEnv; + Word16 *curr_pos_Fix = hiTempEnv; /*Q7*/ move16(); move16(); @@ -1461,7 +1462,7 @@ void calcLoEnvCheckCorrHiLo_Fix( FOR( i = 0; i < 16; i++ ) { - max_local_Fix = min_local_Fix = curr_pos_Fix[0]; + max_local_Fix = min_local_Fix = curr_pos_Fix[0]; /*Q7*/ move16(); move16(); @@ -1469,13 +1470,13 @@ void calcLoEnvCheckCorrHiLo_Fix( { if ( LT_16( max_local_Fix, curr_pos_Fix[-j] ) ) { - max_local_Fix = curr_pos_Fix[-j]; + max_local_Fix = curr_pos_Fix[-j]; /*Q7*/ move16(); } if ( GT_16( min_local_Fix, curr_pos_Fix[-j] ) ) { - min_local_Fix = curr_pos_Fix[-j]; + min_local_Fix = curr_pos_Fix[-j]; /*Q7*/ move16(); } } @@ -1494,7 +1495,7 @@ void calcLoEnvCheckCorrHiLo_Fix( IF( *corrFlag > 0 ) { test(); - if ( ( LE_16( feature_max_Fix, shl( 20, 7 ) ) || GE_16( abs_s( sub( pos_feature_max, maxPosHi ) ), 3 ) ) ) + if ( ( LE_16( feature_max_Fix, 2560 /*20 in Q7*/ ) || GE_16( abs_s( sub( pos_feature_max, maxPosHi ) ), 3 ) ) ) { *corrFlag = 0; move16(); @@ -1514,10 +1515,10 @@ void calcLoEnvCheckCorrHiLo_Fix( FOR( i = 0; i < noCols; i++ ) { - loTempEnv32_Fix[i] = L_deposit_l( loTempEnv_Fix[i] ); + loTempEnv32_Fix[i] = L_deposit_l( loTempEnv_Fix[i] ); /*Q7*/ move32(); } - loVar_Fix = calcVar_Fix( loTempEnv32_Fix, noCols, &loSum_Fix ); + loVar_Fix = calcVar_Fix( loTempEnv32_Fix, noCols, &loSum_Fix ); /*Q7*/ /* = = */ /* ============================================================ */ @@ -1531,9 +1532,9 @@ void calcLoEnvCheckCorrHiLo_Fix( /* ============================================================ */ - EQ1 = L_sub( L_shl( corrCoef_Fix, 8 ), 28819 /*thCorrCoef Q15*/ ); - EQ2 = L_sub( L_shl( hiVar_Fix, 0 ), Mpy_32_16_1( loVar_Fix, 11957 /*thRatio Q15*/ ) ); - EQ3 = L_sub( L_shr( hiVar_Fix, 2 ), Mpy_32_16_1( loVar_Fix, 16620 /*thRatio2 Q13*/ ) ); + EQ1 = L_sub( L_shl( corrCoef_Fix, 8 ), 28819 /*thCorrCoef Q15*/ ); /*Q15*/ + EQ2 = L_sub( L_shl( hiVar_Fix, 0 ), Mpy_32_16_1( loVar_Fix, 11957 /*thRatio Q15*/ ) ); /*Q7*/ + EQ3 = L_sub( L_shr( hiVar_Fix, 2 ), Mpy_32_16_1( loVar_Fix, 16620 /*thRatio2 Q13*/ ) ); /*Q5*/ test(); test(); @@ -1546,13 +1547,13 @@ void calcLoEnvCheckCorrHiLo_Fix( FOR( i = 0; i < MAX_TEC_SMOOTHING_DEG + DELAY_TEMP_ENV_BUFF_TEC; i++ ) { - loBuffer_Fix[i] = loBuffer_Fix[noCols + i]; + loBuffer_Fix[i] = loBuffer_Fix[noCols + i]; /*Q8*/ move16(); } FOR( i = 0; i < DELAY_TEMP_ENV_BUFF_TEC + EXT_DELAY_HI_TEMP_ENV; i++ ) { - hiTempEnvOrig_Fix[i] = hiTempEnvOrig_Fix[noCols + i]; + hiTempEnvOrig_Fix[i] = hiTempEnvOrig_Fix[noCols + i]; /*Q7*/ move16(); } } @@ -1564,9 +1565,9 @@ void calcLoEnvCheckCorrHiLo_Fix( *-------------------------------------------------------------------*/ void tecEnc_TBE_fx( - Word16 *corrFlag, - const Word16 *voicing, - const Word16 coder_type ) + Word16 *corrFlag, /*Q0*/ + const Word16 *voicing, /*Q15*/ + const Word16 coder_type /*Q0*/ ) { Word16 voice_sum; Word16 voice_diff; @@ -1575,8 +1576,8 @@ void tecEnc_TBE_fx( * TEC updates *-----------------------------------------------------------------*/ - voice_sum = add( shr( voicing[0], 1 ), shr( voicing[1], 1 ) ); /*voice_sum = voicing[0] + voicing[1];*/ - voice_diff = sub( voicing[0], voicing[1] ); /*voice_diff = voicing[0] - voicing[1];*/ + voice_sum = add( shr( voicing[0], 1 ), shr( voicing[1], 1 ) ); /*voice_sum = voicing[0] + voicing[1];*/ /*Q15*/ + voice_diff = sub( voicing[0], voicing[1] ); /*voice_diff = voicing[0] - voicing[1]; Q15*/ if ( voice_diff < 0 ) { @@ -1589,7 +1590,7 @@ void tecEnc_TBE_fx( test(); test(); /*if( ((voice_sum > 0.35 * 2 && voice_sum < 0.55 * 2) && (voice_diff < 0.2)) )*/ - if ( EQ_16( coder_type, INACTIVE ) || ( GT_16( voice_sum, 11469 /*0.35 Q15*/ ) && LT_16( voice_sum, 18022 /*0.55 Q15*/ ) && ( sub( voice_diff, 6554 /*0.2 Q15*/ ) < 0 ) ) ) + if ( ( coder_type == INACTIVE ) || ( GT_16( voice_sum, 11469 /*0.35 Q15*/ ) && LT_16( voice_sum, 18022 /*0.55 Q15*/ ) && ( sub( voice_diff, 6554 /*0.2 Q15*/ ) < 0 ) ) ) { *corrFlag = 0; move16(); @@ -1607,9 +1608,9 @@ void tecEnc_TBE_fx( * *-------------------------------------------------------------------*/ void set_TEC_TFA_code_fx( - const Word16 corrFlag, - Word16 *tec_flag, - Word16 *tfa_flag ) + const Word16 corrFlag, /*Q0*/ + Word16 *tec_flag, /*Q0*/ + Word16 *tfa_flag /*Q0*/ ) { *tec_flag = 0; move16(); diff --git a/lib_com/tns_base.c b/lib_com/tns_base.c index 2f37fb102..5e16ff6c2 100644 --- a/lib_com/tns_base.c +++ b/lib_com/tns_base.c @@ -220,13 +220,13 @@ void InitTnsConfiguration( #ifdef IVAS_FLOAT_FIXED void InitTnsConfiguration_ivas_fx( - const Word16 bwidth, - const Word16 frameLength, + const Word16 bwidth, /*Q0*/ + const Word16 frameLength, /*Q0*/ STnsConfig *pTnsConfig, - const Word16 igfStopFreq, - const Word32 total_brate, - const Word16 element_mode, - const Word16 is_mct ) + const Word16 igfStopFreq, /*Q0*/ + const Word32 total_brate, /*Q0*/ + const Word16 element_mode, /*Q0*/ + const Word16 is_mct /*Q0*/ ) { Word16 iFilter = 0; move16(); @@ -238,7 +238,7 @@ void InitTnsConfiguration_ivas_fx( nSampleRate = bwMode2fs[bwidth]; move32(); - startLineFilter = &pTnsConfig->iFilterBorders[1]; + startLineFilter = &pTnsConfig->iFilterBorders[1]; /*Q0*/ /* Sanity checks */ assert( ( nSampleRate > 0 ) && ( frameLength > 0 ) && ( pTnsConfig != NULL ) ); @@ -257,7 +257,7 @@ void InitTnsConfiguration_ivas_fx( IF( LE_32( total_brate, ACELP_32k ) ) { move16(); - pTnsConfig->nMaxFilters = (UWord8) idiv1616( sizeof( tnsParametersIGF32kHz_LowBR ), sizeof( tnsParametersIGF32kHz_LowBR[0] ) ); + pTnsConfig->nMaxFilters = (UWord8) idiv1616( sizeof( tnsParametersIGF32kHz_LowBR ), sizeof( tnsParametersIGF32kHz_LowBR[0] ) ); /*Q0*/ pTnsConfig->pTnsParameters = tnsParametersIGF32kHz_LowBR; } ELSE @@ -265,7 +265,7 @@ void InitTnsConfiguration_ivas_fx( test(); IF( GT_32( nSampleRate, 32000 ) && EQ_32( nSampleRate, L_mult0( 100, frameLength ) ) ) { - pTnsConfig->nMaxFilters = (UWord8) idiv1616( sizeof( tnsParameters48kHz_grouped ), sizeof( tnsParameters48kHz_grouped[0] ) ); + pTnsConfig->nMaxFilters = (UWord8) idiv1616( sizeof( tnsParameters48kHz_grouped ), sizeof( tnsParameters48kHz_grouped[0] ) ); /*Q0*/ move16(); pTnsConfig->pTnsParameters = tnsParameters48kHz_grouped; } @@ -281,7 +281,7 @@ void InitTnsConfiguration_ivas_fx( test(); IF( GT_16( element_mode, IVAS_SCE ) && GE_32( total_brate, L_tmp ) ) { - pTnsConfig->nMaxFilters = (UWord8) idiv1616( sizeof( tnsParameters32kHz_Stereo ), sizeof( tnsParameters32kHz_Stereo[0] ) ); + pTnsConfig->nMaxFilters = (UWord8) idiv1616( sizeof( tnsParameters32kHz_Stereo ), sizeof( tnsParameters32kHz_Stereo[0] ) ); /*Q0*/ move16(); IF( EQ_32( nSampleRate, L_mult0( 100, frameLength ) ) ) /* sub-frame length is <= 10 ms */ { @@ -296,7 +296,7 @@ void InitTnsConfiguration_ivas_fx( { move16(); - pTnsConfig->nMaxFilters = (UWord8) idiv1616( sizeof( tnsParameters32kHz ), sizeof( tnsParameters32kHz[0] ) ); + pTnsConfig->nMaxFilters = (UWord8) idiv1616( sizeof( tnsParameters32kHz ), sizeof( tnsParameters32kHz[0] ) ); /*Q0*/ pTnsConfig->pTnsParameters = tnsParameters32kHz; @@ -311,13 +311,13 @@ void InitTnsConfiguration_ivas_fx( IF( EQ_32( nSampleRate, L_mult0( 100, frameLength ) ) ) /* sub-frame length is <= 10 ms */ { move16(); - pTnsConfig->nMaxFilters = (UWord8) idiv1616( sizeof( tnsParameters16kHz_grouped ), sizeof( tnsParameters16kHz_grouped[0] ) ); + pTnsConfig->nMaxFilters = (UWord8) idiv1616( sizeof( tnsParameters16kHz_grouped ), sizeof( tnsParameters16kHz_grouped[0] ) ); /*Q0*/ pTnsConfig->pTnsParameters = tnsParameters16kHz_grouped; } ELSE { move16(); - pTnsConfig->nMaxFilters = (UWord8) idiv1616( sizeof( tnsParameters16kHz ), sizeof( tnsParameters16kHz[0] ) ); + pTnsConfig->nMaxFilters = (UWord8) idiv1616( sizeof( tnsParameters16kHz ), sizeof( tnsParameters16kHz[0] ) ); /*Q0*/ pTnsConfig->pTnsParameters = tnsParameters16kHz; } } @@ -332,7 +332,7 @@ void InitTnsConfiguration_ivas_fx( assert( pTnsConfig->pTnsParameters[iFilter].startLineFrequency < 0.5f * nSampleRate ); assert( nSampleRate <= 96000 ); move16(); - startLineFilter[iFilter] = divide3232( L_mult0( frameLength, pTnsConfig->pTnsParameters[iFilter].startLineFrequency ), L_shl( nSampleRate, 14 ) ); + startLineFilter[iFilter] = divide3232( L_mult0( frameLength, pTnsConfig->pTnsParameters[iFilter].startLineFrequency ), L_shl( nSampleRate, 14 ) ); /*Q0*/ } IF( igfStopFreq > 0 ) @@ -342,12 +342,12 @@ void InitTnsConfiguration_ivas_fx( s2 = norm_l( nSampleRate ); move16(); - pTnsConfig->iFilterBorders[0] = shr( div_l( L_shl( L_tmp, s1 ), extract_h( L_shl( nSampleRate, s2 ) ) ), sub( WORD16_BITS - 1, sub( s2, s1 ) ) ); + pTnsConfig->iFilterBorders[0] = shr( div_l( L_shl( L_tmp, s1 ), extract_h( L_shl( nSampleRate, s2 ) ) ), sub( WORD16_BITS - 1, sub( s2, s1 ) ) ); /*Q0*/ } ELSE { move16(); - pTnsConfig->iFilterBorders[0] = frameLength; + pTnsConfig->iFilterBorders[0] = frameLength; /*Q0*/ } pTnsConfig->allowTnsOnWhite = 0; @@ -368,8 +368,8 @@ void InitTnsConfiguration_ivas_fx( void ApplyTnsFilter( STnsConfig const *pTnsConfig, STnsData const *pTnsData, - Word32 spectrum[], - const Word8 fIsAnalysis ) + Word32 spectrum[], /*Qx*/ + const Word8 fIsAnalysis /*Q0*/ ) { TLinearPredictionFilter filter; Word32 state[TNS_MAX_FILTER_ORDER]; @@ -382,12 +382,11 @@ void ApplyTnsFilter( filter = IIRLattice; if ( fIsAnalysis ) { - move16(); filter = FIRLattice; } set32_fx( state, 0, TNS_MAX_FILTER_ORDER ); move16(); - pBorders = pTnsConfig->iFilterBorders; + pBorders = pTnsConfig->iFilterBorders; /*Q0*/ FOR( iFilter = pTnsConfig->nMaxFilters - 1; iFilter >= 0; iFilter-- ) { @@ -419,15 +418,15 @@ void ApplyTnsFilter( *-------------------------------------------------------------------*/ void ITF_Apply_fx( - Word32 spectrum[], - Word16 startLine, - Word16 stopLine, - const Word16 *A, + Word32 spectrum[], /*Qx*/ + Word16 startLine, /*Q0*/ + Word16 stopLine, /*Q0*/ + const Word16 *A, /*Q_A*/ Word16 Q_A, - Word16 order ) + Word16 order /*Q0*/ ) { - ITF_TnsFilter_fx( &spectrum[startLine], (Word16) ( stopLine - startLine ), A, Q_A, (Word16) order, &spectrum[startLine] ); + ITF_TnsFilter_fx( &spectrum[startLine], sub( stopLine, startLine ), A, Q_A, order, &spectrum[startLine] ); return /*TNS_NO_ERROR*/; } @@ -438,14 +437,14 @@ void ITF_Apply_fx( *-------------------------------------------------------------------*/ Word16 ITF_Detect_fx( - const Word32 pSpectrum[], - const Word16 startLine, - const Word16 stopLine, - const Word16 maxOrder, - Word16 *A, + const Word32 pSpectrum[], /*Q*/ + const Word16 startLine, /*Q0*/ + const Word16 stopLine, /*Q0*/ + const Word16 maxOrder, /*Q0*/ + Word16 *A, /*Q_A*/ Word16 *Q_A, - Word16 *predictionGain, - Word16 *curr_order, + Word16 *predictionGain, /*Q7*/ + Word16 *curr_order, /*Q0*/ Word16 Q ) { @@ -484,25 +483,25 @@ Word16 ITF_Detect_fx( assert( ( nSubdivisions == 1 ) || ( nSubdivisions == 3 ) ); tmp = sub( stopLine, startLine ); - iStartLine = imult1616( tmp, iSubdivisions ); + iStartLine = imult1616( tmp, iSubdivisions ); /*Q0*/ iEndLine = add( iStartLine, tmp ); if ( EQ_16( nSubdivisions, 3 ) ) - iStartLine = mult( iStartLine, 0x2AAB ); + iStartLine = mult( iStartLine, 0x2AAB ); /*Q0*/ iStartLine = add( iStartLine, startLine ); if ( EQ_16( nSubdivisions, 3 ) ) - iEndLine = mult( iEndLine, 0x2AAB ); + iEndLine = mult( iEndLine, 0x2AAB ); /*Q0*/ iEndLine = add( iEndLine, startLine ); headroom = getScaleFactor32( pSpectrum + iStartLine - IGF_START_MN, sub( iEndLine, iStartLine ) ); /* Calculate norm of spectrum band */ - L_tmp = Norm32Norm( pSpectrum + iStartLine - IGF_START_MN, headroom, sub( iEndLine, iStartLine ), &shift ); + L_tmp = Norm32Norm( pSpectrum + iStartLine - IGF_START_MN, headroom, sub( iEndLine, iStartLine ), &shift ); /*Q31 - shift*/ /* Check threshold HLM_MIN_NRG */ BASOP_SATURATE_WARNING_OFF_EVS; #ifdef BASOP_NOGLOB - tmp32 = L_sub( L_shl_o( L_tmp, sub( shift, sub( 24, Q ) ), &Overflow ), 4194304l /*HLM_MIN_NRG Q7*/ ); -#else /* BASOP_NOGLOB */ + tmp32 = L_sub( L_shl_o( L_tmp, sub( shift, sub( 24, Q ) ), &Overflow ), 4194304l /*HLM_MIN_NRG Q7*/ ); /*Q7*/ +#else /* BASOP_NOGLOB */ tmp32 = L_sub( L_shl( L_tmp, sub( shift, 24 - Q ) ), 4194304l /*HLM_MIN_NRG Q7*/ ); #endif BASOP_SATURATE_WARNING_ON_EVS; @@ -536,7 +535,7 @@ Word16 ITF_Detect_fx( /* calc factor (with 2 bits headroom for sum of 3 subdivisions) */ #ifdef BASOP_NOGLOB - facs[iSubdivisions] = div_s( 0x2000, round_fx_sat( L_tmp ) ); /* L_tmp is >= 0x2000000 */ + facs[iSubdivisions] = div_s( 0x2000, round_fx_sat( L_tmp ) ); /* L_tmp is >= 0x2000000 Q15*/ #else facs[iSubdivisions] = div_s( 0x2000, round_fx( L_tmp ) ); /* L_tmp is >= 0x2000000 */ #endif @@ -559,15 +558,15 @@ Word16 ITF_Detect_fx( assert( ( nSubdivisions == 1 ) || ( nSubdivisions == 3 ) ); - iStartLine = imult1616( spectrumLength, iSubdivisions ); - iEndLine = add( iStartLine, spectrumLength ); + iStartLine = imult1616( spectrumLength, iSubdivisions ); /*Q0*/ + iEndLine = add( iStartLine, spectrumLength ); /*Q0*/ if ( EQ_16( nSubdivisions, 3 ) ) - iStartLine = mult( iStartLine, 0x2AAB ); + iStartLine = mult( iStartLine, 0x2AAB ); /*Q0*/ iStartLine = add( iStartLine, startLine ); if ( EQ_16( nSubdivisions, 3 ) ) - iEndLine = mult( iEndLine, 0x2AAB ); + iEndLine = mult( iEndLine, 0x2AAB ); /*Q0*/ iEndLine = add( iEndLine, startLine ); @@ -578,7 +577,7 @@ Word16 ITF_Detect_fx( assert( n < (Word16) ( sizeof( tmpbuf ) / sizeof( Word16 ) ) ); FOR( i = 0; i < n; i++ ) { - tmpbuf[i] = round_fx_sat( L_shl_sat( pSpectrum[iStartLine + i - IGF_START_MN], shift ) ); + tmpbuf[i] = round_fx_sat( L_shl_sat( pSpectrum[iStartLine + i - IGF_START_MN], shift ) ); /*Q + shift - 16*/ move16(); } @@ -590,13 +589,13 @@ Word16 ITF_Detect_fx( Word64 tmp64 = 0; FOR( i = 0; i < n; i++ ) { - tmp64 = W_mac0_16_16( tmp64, tmpbuf[i], tmpbuf[i + lag] ); + tmp64 = W_mac0_16_16( tmp64, tmpbuf[i], tmpbuf[i + lag] ); /*2*(Q + shift) - 32*/ } - L_tmp = W_sat_l( tmp64 ); + L_tmp = W_sat_l( tmp64 ); /*2*(Q + shift) - 32*/ } - L_tmp = Mpy_32_16_1( L_tmp, facs[iSubdivisions] ); - L_tmp = L_shl( L_tmp, facs_e[iSubdivisions] ); + L_tmp = Mpy_32_16_1( L_tmp, facs[iSubdivisions] ); /*2*(Q + shift) - 32*/ + L_tmp = L_shl( L_tmp, facs_e[iSubdivisions] ); /*2*(Q + shift) - 32 + facs_e*/ rxx[lag] = L_add( rxx[lag], L_tmp ); move32(); @@ -608,7 +607,7 @@ Word16 ITF_Detect_fx( /* Limit the maximum order to spectrum length/4 */ ITF_GetFilterParameters_fx( rxx, s_min( maxOrder, shr( spectrumLength, 2 ) ), A, Q_A, predictionGain ); - *curr_order = maxOrder; + *curr_order = maxOrder; /*Q0*/ move16(); } @@ -616,14 +615,14 @@ Word16 ITF_Detect_fx( } Word16 ITF_Detect_ivas_fx( - const Word32 pSpectrum[], - const Word16 startLine, - const Word16 stopLine, - const Word16 maxOrder, - Word16 *A, + const Word32 pSpectrum[], /*Q*/ + const Word16 startLine, /*Q0*/ + const Word16 stopLine, /*Q0*/ + const Word16 maxOrder, /*Q0*/ + Word16 *A, /*Q_A*/ Word16 *Q_A, - Word16 *predictionGain, - Word16 *curr_order, + Word16 *predictionGain, /*Q7*/ + Word16 *curr_order, /*Q0*/ Word16 Q ) { @@ -661,25 +660,25 @@ Word16 ITF_Detect_ivas_fx( assert( ( nSubdivisions == 1 ) || ( nSubdivisions == 3 ) ); tmp = sub( stopLine, startLine ); - iStartLine = imult1616( tmp, iSubdivisions ); + iStartLine = imult1616( tmp, iSubdivisions ); /*Q0*/ iEndLine = add( iStartLine, tmp ); IF( EQ_16( nSubdivisions, 3 ) ) - iStartLine = mult( iStartLine, 0x2AAB ); + iStartLine = mult( iStartLine, 0x2AAB ); /*Q0*/ iStartLine = add( iStartLine, startLine ); IF( EQ_16( nSubdivisions, 3 ) ) - iEndLine = mult( iEndLine, 0x2AAB ); + iEndLine = mult( iEndLine, 0x2AAB ); /*Q0*/ iEndLine = add( iEndLine, startLine ); headroom = getScaleFactor32( pSpectrum + iStartLine - IGF_START_MN, sub( iEndLine, iStartLine ) ); /* Calculate norm of spectrum band */ - L_tmp = Norm32Norm( pSpectrum + iStartLine - IGF_START_MN, headroom, sub( iEndLine, iStartLine ), &shift ); + L_tmp = Norm32Norm( pSpectrum + iStartLine - IGF_START_MN, headroom, sub( iEndLine, iStartLine ), &shift ); /*Q31 - shift*/ /* Check threshold HLM_MIN_NRG */ BASOP_SATURATE_WARNING_OFF_EVS; #ifdef BASOP_NOGLOB - tmp32 = L_sub( L_shl_o( L_tmp, sub( shift, 24 - Q ), &Overflow ), 4194304l /*HLM_MIN_NRG Q7*/ ); -#else /* BASOP_NOGLOB */ + tmp32 = L_sub( L_shl_o( L_tmp, sub( shift, 24 - Q ), &Overflow ), 4194304l /*HLM_MIN_NRG Q7*/ ); /*Q7*/ +#else /* BASOP_NOGLOB */ tmp32 = L_sub( L_shl( L_tmp, sub( shift, 24 - Q ) ), 4194304l /*HLM_MIN_NRG Q7*/ ); #endif BASOP_SATURATE_WARNING_ON_EVS; @@ -698,8 +697,8 @@ Word16 ITF_Detect_ivas_fx( if ( tmp32 > 0 ) { - facs[iSubdivisions] = 0x7FFF; - move16(); /* normalization not needed for one subdivision */ + facs[iSubdivisions] = 0x7FFF; /*Q15*/ + move16(); /* normalization not needed for one subdivision */ } IF( L_tmp > 0 ) @@ -711,10 +710,10 @@ Word16 ITF_Detect_ivas_fx( L_tmp = L_shl( L_tmp, sub( shift, tmp ) ); /* shift L_tmp to that exponent */ /* calc factor (with 2 bits headroom for sum of 3 subdivisions) */ - facs[iSubdivisions] = div_s( 0x2000, round_fx_o( L_tmp, &Overflow ) ); /* L_tmp is >= 0x2000000 */ + facs[iSubdivisions] = div_s( 0x2000, round_fx_o( L_tmp, &Overflow ) ); /* L_tmp is >= 0x2000000 Q15*/ move16(); } - norms[iSubdivisions] = sum2_32_fx( pSpectrum + sub( iStartLine, IGF_START_MN ), sub( iEndLine, iStartLine ), &norms_e[iSubdivisions] ); + norms[iSubdivisions] = sum2_32_fx( pSpectrum + sub( iStartLine, IGF_START_MN ), sub( iEndLine, iStartLine ), &norms_e[iSubdivisions] ); /*Q31 - norms_e*/ move16(); } @@ -722,21 +721,21 @@ Word16 ITF_Detect_ivas_fx( set32_fx( rxx, 0, ITF_MAX_FILTER_ORDER + 1 ); spectrumLength = sub( stopLine, startLine ); - + test(); FOR( iSubdivisions = 0; ( iSubdivisions < nSubdivisions ) && GT_64( norms[iSubdivisions], W_shl( HLM_MIN_NRG_FX, sub( 31, norms_e[iSubdivisions] ) ) ); iSubdivisions++ ) { test(); assert( ( nSubdivisions == 1 ) || ( nSubdivisions == 3 ) ); - iStartLine = imult1616( spectrumLength, iSubdivisions ); + iStartLine = imult1616( spectrumLength, iSubdivisions ); /*Q0*/ iEndLine = add( iStartLine, spectrumLength ); IF( EQ_16( nSubdivisions, 3 ) ) - iStartLine = mult( iStartLine, 0x2AAB ); + iStartLine = mult( iStartLine, 0x2AAB ); /*Q0*/ iStartLine = add( iStartLine, startLine ); IF( EQ_16( nSubdivisions, 3 ) ) - iEndLine = mult( iEndLine, 0x2AAB ); + iEndLine = mult( iEndLine, 0x2AAB ); /*Q0*/ iEndLine = add( iEndLine, startLine ); @@ -747,7 +746,7 @@ Word16 ITF_Detect_ivas_fx( assert( n < (Word16) ( sizeof( tmpbuf ) / sizeof( Word16 ) ) ); FOR( i = 0; i < n; i++ ) { - tmpbuf[i] = round_fx_o( L_shl( pSpectrum[iStartLine + i - IGF_START_MN], shift ), &Overflow ); + tmpbuf[i] = round_fx_o( L_shl( pSpectrum[iStartLine + i - IGF_START_MN], shift ), &Overflow ); /*Q+shift-16*/ move16(); } @@ -759,15 +758,15 @@ Word16 ITF_Detect_ivas_fx( Word64 tmp64 = 0; FOR( i = 0; i < n; i++ ) { - tmp64 = W_mac0_16_16( tmp64, tmpbuf[i], tmpbuf[i + lag] ); + tmp64 = W_mac0_16_16( tmp64, tmpbuf[i], tmpbuf[i + lag] ); /*2*( Q+shift-16)*/ } - L_tmp = W_sat_l( tmp64 ); + L_tmp = W_sat_l( tmp64 ); /*2*( Q+shift-16)*/ } - L_tmp = Mpy_32_16_1( L_tmp, facs[iSubdivisions] ); + L_tmp = Mpy_32_16_1( L_tmp, facs[iSubdivisions] ); /*2*( Q+shift-16)*/ L_tmp = L_shl( L_tmp, facs_e[iSubdivisions] ); - rxx[lag] = L_add( rxx[lag], L_tmp ); + rxx[lag] = L_add( rxx[lag], L_tmp ); /*2*( Q+shift-16)*/ move32(); } } @@ -781,7 +780,7 @@ Word16 ITF_Detect_ivas_fx( /* Limit the maximum order to spectrum length/4 */ ITF_GetFilterParameters_fx( rxx, s_min( maxOrder, shr( spectrumLength, 2 ) ), A, Q_A, predictionGain ); - *curr_order = maxOrder; + *curr_order = maxOrder; /*Q0*/ move16(); } @@ -793,31 +792,31 @@ Word16 ITF_Detect_ivas_fx( /** Get number of bits from a Huffman table. * The table must be sorted by values. */ -static Word16 GetBitsFromTable( const Word16 value, const Coding codes[], const Word16 nSize ) +static Word16 GetBitsFromTable( const Word16 value /*Q0*/, const Coding codes[], const Word16 nSize /*Q0*/ ) { (void) nSize; assert( ( value >= 0 ) && ( value < nSize ) && ( nSize >= 0 ) && ( nSize <= 256 ) ); move16(); cast16(); - return (Word16) codes[value].nBits; + return (Word16) codes[value].nBits; /*Q0*/ } /** Get the code for a value from a Huffman table. * The table must be sorted by values. */ -static Word16 EncodeUsingTable( const Word16 value, const Coding codes[], const Word16 nSize ) +static Word16 EncodeUsingTable( const Word16 value /*Q0*/, const Coding codes[], const Word16 nSize /*Q0*/ ) { (void) nSize; assert( ( value >= 0 ) && ( value < nSize ) && ( nSize >= 0 ) && ( nSize <= 256 ) ); move16(); - return codes[value].code; + return codes[value].code; /*Q0*/ } /** Decode a value from a bitstream using a Huffman table. */ -static Word16 DecodeUsingTable( Decoder_State *st, Word16 *pValue, const Coding codes[], const Word16 nSize ) +static Word16 DecodeUsingTable( Decoder_State *st, Word16 *pValue /*Q0*/, const Coding codes[], const Word16 nSize /*Q0*/ ) { Word16 code = 0; Word16 nBits = 0; @@ -834,9 +833,10 @@ static Word16 DecodeUsingTable( Decoder_State *st, Word16 *pValue, const Coding WHILE( valueIndex == nSize ) { - code = add( shl( code, 1 ), get_next_indice_fx( st, 1 ) ); + code = add( shl( code, 1 ), get_next_indice_fx( st, 1 ) ); /*Q0*/ nBits = add( nBits, 1 ); - if ( nBits > nSize || nBits > 16 ) + test(); + IF( GT_16( nBits, nSize ) || GT_16( nBits, 16 ) ) { st->BER_detect = 1; move16(); @@ -855,12 +855,12 @@ static Word16 DecodeUsingTable( Decoder_State *st, Word16 *pValue, const Coding } } } - if ( valueIndex < nSize ) + IF( LT_16( valueIndex, nSize ) ) { - *pValue = (Word16) codes[valueIndex].value; + *pValue = (Word16) codes[valueIndex].value; /*Q0*/ move16(); } - else + ELSE { st->BER_detect = 1; move16(); @@ -869,20 +869,20 @@ static Word16 DecodeUsingTable( Decoder_State *st, Word16 *pValue, const Coding return -1; } - return nBits; + return nBits; /*Q0*/ } /* TNS filter coefficients */ -void const *GetTnsFilterCoeff( void const *p, const Word16 index, Word16 *pValue ) +void const *GetTnsFilterCoeff( void const *p, const Word16 index /*Q0*/, Word16 *pValue /*Q0*/ ) { *pValue = ( (Word16 const *) p )[index] + INDEX_SHIFT; move16(); return NULL; } -void *SetTnsFilterCoeff( void *p, const Word16 index, const Word16 value ) +void *SetTnsFilterCoeff( void *p, const Word16 index /*Q0*/, const Word16 value /*Q0*/ ) { ( (Word16 *) p )[index] = sub( value, INDEX_SHIFT ); move16(); @@ -894,63 +894,63 @@ Word16 GetSWBTCX20TnsFilterCoeffBits( const Word16 value, const Word16 index ) { assert( ( index >= 0 ) && ( index < nTnsCoeffTables ) ); - return GetBitsFromTable( value, codesTnsCoeffSWBTCX20[index], nTnsCoeffCodes ); + return GetBitsFromTable( value, codesTnsCoeffSWBTCX20[index], nTnsCoeffCodes ); /*Q0*/ } Word16 EncodeSWBTCX20TnsFilterCoeff( const Word16 value, const Word16 index ) { assert( ( index >= 0 ) && ( index < nTnsCoeffTables ) ); - return EncodeUsingTable( value, codesTnsCoeffSWBTCX20[index], nTnsCoeffCodes ); + return EncodeUsingTable( value, codesTnsCoeffSWBTCX20[index], nTnsCoeffCodes ); /*Q0*/ } Word16 DecodeSWBTCX20TnsFilterCoeff( Decoder_State *st, const Word16 index, Word16 *pValue ) { assert( ( index >= 0 ) && ( index < nTnsCoeffTables ) ); - return DecodeUsingTable( st, pValue, codesTnsCoeffSWBTCX20[index], nTnsCoeffCodes ); + return DecodeUsingTable( st, pValue, codesTnsCoeffSWBTCX20[index], nTnsCoeffCodes ); /*Q0*/ } Word16 GetSWBTCX10TnsFilterCoeffBits( const Word16 value, const Word16 index ) { assert( ( index >= 0 ) && ( index < nTnsCoeffTables ) ); - return GetBitsFromTable( value, codesTnsCoeffSWBTCX10[index], nTnsCoeffCodes ); + return GetBitsFromTable( value, codesTnsCoeffSWBTCX10[index], nTnsCoeffCodes ); /*Q0*/ } Word16 EncodeSWBTCX10TnsFilterCoeff( const Word16 value, const Word16 index ) { assert( ( index >= 0 ) && ( index < nTnsCoeffTables ) ); - return EncodeUsingTable( value, codesTnsCoeffSWBTCX10[index], nTnsCoeffCodes ); + return EncodeUsingTable( value, codesTnsCoeffSWBTCX10[index], nTnsCoeffCodes ); /*Q0*/ } Word16 DecodeSWBTCX10TnsFilterCoeff( Decoder_State *st, const Word16 index, Word16 *pValue ) { assert( ( index >= 0 ) && ( index < nTnsCoeffTables ) ); - return DecodeUsingTable( st, pValue, codesTnsCoeffSWBTCX10[index], nTnsCoeffCodes ); + return DecodeUsingTable( st, pValue, codesTnsCoeffSWBTCX10[index], nTnsCoeffCodes ); /*Q0*/ } Word16 GetWBTCX20TnsFilterCoeffBits( const Word16 value, const Word16 index ) { assert( ( index >= 0 ) && ( index < nTnsCoeffTables ) ); - return GetBitsFromTable( value, codesTnsCoeffWBTCX20[index], nTnsCoeffCodes ); + return GetBitsFromTable( value, codesTnsCoeffWBTCX20[index], nTnsCoeffCodes ); /*Q0*/ } Word16 EncodeWBTCX20TnsFilterCoeff( const Word16 value, const Word16 index ) { assert( ( index >= 0 ) && ( index < nTnsCoeffTables ) ); - return EncodeUsingTable( value, codesTnsCoeffWBTCX20[index], nTnsCoeffCodes ); + return EncodeUsingTable( value, codesTnsCoeffWBTCX20[index], nTnsCoeffCodes ); /*Q0*/ } Word16 DecodeWBTCX20TnsFilterCoeff( Decoder_State *st, const Word16 index, Word16 *pValue ) { assert( ( index >= 0 ) && ( index < nTnsCoeffTables ) ); - return DecodeUsingTable( st, pValue, codesTnsCoeffWBTCX20[index], nTnsCoeffCodes ); + return DecodeUsingTable( st, pValue, codesTnsCoeffWBTCX20[index], nTnsCoeffCodes ); /*Q0*/ } @@ -959,82 +959,82 @@ Word16 DecodeWBTCX20TnsFilterCoeff( Decoder_State *st, const Word16 index, Word1 void const *GetTnsFilterOrder( void const *p, const Word16 index, Word16 *pValue ) { move16(); - *pValue = ( (STnsFilter const *) p )[index].order; + *pValue = ( (STnsFilter const *) p )[index].order; /*Q0*/ move16(); - return ( (STnsFilter const *) p )[index].coefIndex; + return ( (STnsFilter const *) p )[index].coefIndex; /*Q0*/ } void *SetTnsFilterOrder( void *p, const Word16 index, const Word16 value ) { move16(); - ( (STnsFilter *) p )[index].order = value; + ( (STnsFilter *) p )[index].order = value; /*Q0*/ move16(); - return ( (STnsFilter *) p )[index].coefIndex; + return ( (STnsFilter *) p )[index].coefIndex; /*Q0*/ } Word16 GetTnsFilterOrderBitsSWBTCX20( const Word16 value, const Word16 index ) { (void) index; - return GetBitsFromTable( value - 1, codesTnsOrderTCX20, nTnsOrderCodes ); + return GetBitsFromTable( sub( value, 1 ), codesTnsOrderTCX20, nTnsOrderCodes ); /*Q0*/ } Word16 EncodeTnsFilterOrderSWBTCX20( const Word16 value, const Word16 index ) { (void) index; - return EncodeUsingTable( value - 1, codesTnsOrderTCX20, nTnsOrderCodes ); + return EncodeUsingTable( sub( value, 1 ), codesTnsOrderTCX20, nTnsOrderCodes ); /*Q0*/ } Word16 DecodeTnsFilterOrderSWBTCX20( Decoder_State *st, const Word16 index, Word16 *pValue ) { (void) index; - return DecodeUsingTable( st, pValue, codesTnsOrderTCX20, nTnsOrderCodes ); + return DecodeUsingTable( st, pValue, codesTnsOrderTCX20, nTnsOrderCodes ); /*Q0*/ } Word16 GetTnsFilterOrderBitsSWBTCX10( const Word16 value, const Word16 index ) { (void) index; - return GetBitsFromTable( value - 1, codesTnsOrderTCX10, nTnsOrderCodes ); + return GetBitsFromTable( sub( value, 1 ), codesTnsOrderTCX10, nTnsOrderCodes ); /*Q0*/ } Word16 EncodeTnsFilterOrderSWBTCX10( const Word16 value, const Word16 index ) { (void) index; - return EncodeUsingTable( value - 1, codesTnsOrderTCX10, nTnsOrderCodes ); + return EncodeUsingTable( sub( value, 1 ), codesTnsOrderTCX10, nTnsOrderCodes ); /*Q0*/ } Word16 DecodeTnsFilterOrderSWBTCX10( Decoder_State *st, const Word16 index, Word16 *pValue ) { (void) index; - return DecodeUsingTable( st, pValue, codesTnsOrderTCX10, nTnsOrderCodes ); + return DecodeUsingTable( st, pValue, codesTnsOrderTCX10, nTnsOrderCodes ); /*Q0*/ } Word16 GetTnsFilterOrderBits( const Word16 value, const Word16 index ) { (void) index; - return GetBitsFromTable( value - 1, codesTnsOrder, nTnsOrderCodes ); + return GetBitsFromTable( sub( value, 1 ), codesTnsOrder, nTnsOrderCodes ); /*Q0*/ } Word16 EncodeTnsFilterOrder( const Word16 value, const Word16 index ) { (void) index; - return EncodeUsingTable( value - 1, codesTnsOrder, nTnsOrderCodes ); + return EncodeUsingTable( sub( value, 1 ), codesTnsOrder, nTnsOrderCodes ); /*Q0*/ } Word16 DecodeTnsFilterOrder( Decoder_State *st, const Word16 index, Word16 *pValue ) { (void) index; - return DecodeUsingTable( st, pValue, codesTnsOrder, nTnsOrderCodes ); + return DecodeUsingTable( st, pValue, codesTnsOrder, nTnsOrderCodes ); /*Q0*/ } /* Number of TNS filters */ @@ -1042,7 +1042,7 @@ Word16 DecodeTnsFilterOrder( Decoder_State *st, const Word16 index, Word16 *pVal void const *GetNumOfTnsFilters( void const *p, const Word16 index, Word16 *pValue ) { move16(); - *pValue = ( (STnsData const *) p )[index].nFilters; + *pValue = ( (STnsData const *) p )[index].nFilters; /*Q0*/ move16(); return ( (STnsData const *) p )[index].filter; } @@ -1050,7 +1050,7 @@ void const *GetNumOfTnsFilters( void const *p, const Word16 index, Word16 *pValu void *SetNumOfTnsFilters( void *p, const Word16 index, Word16 value ) { move16(); - ( (STnsData *) p )[index].nFilters = value; + ( (STnsData *) p )[index].nFilters = value; /*Q0*/ move16(); return ( (STnsData *) p )[index].filter; } @@ -1110,8 +1110,7 @@ void const *GetTnsEnabledSingleFilter( void const *p, const Word16 index, Word16 void *SetTnsEnabledSingleFilter( void *p, const Word16 index, const Word16 value ) { - move16(); - ( (STnsData *) p )[index].nFilters = value; + ( (STnsData *) p )[index].nFilters = value; /*Q0*/ move16(); return ( (STnsData *) p )[index].filter; } @@ -1135,11 +1134,11 @@ void ResetTnsData( STnsData *pTnsData ) STnsFilter *const pTnsFilter = &pTnsData->filter[iFilter]; pTnsFilter->spectrumLength = 0; move16(); - pTnsFilter->predictionGain = ONE_IN_Q7; + pTnsFilter->predictionGain = ONE_IN_Q7; /*Q7*/ move16(); pTnsFilter->avgSqrCoef = 0; move16(); - pTnsFilter->filterType = TNS_FILTER_OFF; + pTnsFilter->filterType = TNS_FILTER_OFF; /*Q0*/ move16(); ClearTnsFilterCoefficients( pTnsFilter ); } @@ -1180,18 +1179,18 @@ void ClearTnsFilterCoefficients( * @param parCoeff output reflection coefficients. * @param order number of coefficients/values. */ -static void Index2Parcor( const Word16 index[], Word16 parCoeff[], Word16 order ) +static void Index2Parcor( const Word16 index[] /*Q0*/, Word16 parCoeff[] /*Q15*/, Word16 order /*Q0*/ ) { const Word16 *values; Word16 i; move16(); - values = tnsCoeff4; + values = tnsCoeff4; /*Q15*/ FOR( i = 0; i < order; i++ ) { move16(); - parCoeff[i] = values[add( index[i], INDEX_SHIFT )]; + parCoeff[i] = values[( index[i] + INDEX_SHIFT )]; /*Q15*/ } return; } @@ -1199,10 +1198,10 @@ static void Index2Parcor( const Word16 index[], Word16 parCoeff[], Word16 order /* Linear prediction analysis filter. */ static Word32 FIRLattice( - const Word16 order, + const Word16 order, /*Q0*/ const Word16 *parCoeff /*Q15*/, - Word32 *state, - Word32 x /* Q0 */ + Word32 *state, /*Q0*/ + Word32 x /* Q0 */ ) { Word16 i; @@ -1213,40 +1212,40 @@ static Word32 FIRLattice( move32(); FOR( i = 0; i < order - 1; i++ ) { - tmp = L_add( state[i], Mpy_32_16_1( x, parCoeff[i] ) ); - x = L_add( x, Mpy_32_16_1( state[i], parCoeff[i] ) ); /* exponent: 31+0 */ - state[i] = tmpSave; + tmp = L_add( state[i], Mpy_32_16_1( x, parCoeff[i] ) ); /*Q0*/ + x = L_add( x, Mpy_32_16_1( state[i], parCoeff[i] ) ); /* exponent: 31+0 */ + state[i] = tmpSave; /*Q0*/ move32(); - tmpSave = tmp; + tmpSave = tmp; /*Q0*/ move32(); } /* last stage: only need half operations */ - x = L_add( x, Mpy_32_16_1( state[order - 1], parCoeff[order - 1] ) ); - state[order - 1] = tmpSave; + x = L_add( x, Mpy_32_16_1( state[order - 1], parCoeff[order - 1] ) ); /*Q0*/ + state[order - 1] = tmpSave; /*Q0*/ move32(); - return x; + return x; /*Q0*/ } -static Word32 IIRLattice( Word16 order, const Word16 *parCoeff, Word32 *state, Word32 x ) +static Word32 IIRLattice( Word16 order /*Q0*/, const Word16 *parCoeff /*Q15*/, Word32 *state /*Q0*/, Word32 x /*Q0*/ ) { Word16 i; /* first stage: no need to calculate state[order-1] */ - x = Msub_32_16( x, state[order - 1], parCoeff[order - 1] ); + x = Msub_32_16( x, state[order - 1], parCoeff[order - 1] ); /*Q0*/ FOR( i = order - 2; i >= 0; i-- ) { - x = Msub_32_16( x, state[i], parCoeff[i] ); - state[i + 1] = Madd_32_16( state[i], x, parCoeff[i] ); + x = Msub_32_16( x, state[i], parCoeff[i] ); /*Q0*/ + state[i + 1] = Madd_32_16( state[i], x, parCoeff[i] ); /*Q0*/ move32(); } move32(); - state[0] = x; - return x; + state[0] = x; /*Q0*/ + return x; /*Q0*/ } /** TNS analysis/synthesis filter. * @param spectrum input spectrum values. @@ -1259,13 +1258,13 @@ static Word32 IIRLattice( Word16 order, const Word16 *parCoeff, Word32 *state, W Inplace operation is supported, so it can be equal to spectrum. */ static void TnsFilter( - const Word32 spectrum[], - const Word16 numOfLines, - const Word16 parCoeff[], - const Word16 order, + const Word32 spectrum[], /*Qx*/ + const Word16 numOfLines, /*Q0*/ + const Word16 parCoeff[], /*Q15*/ + const Word16 order, /*Q0*/ TLinearPredictionFilter filter, - Word32 *state, - Word32 output[] ) + Word32 *state, /*Q0*/ + Word32 output[] /*Qx*/ ) { Word16 j; @@ -1279,7 +1278,7 @@ static void TnsFilter( test(); IF( s_and( ( spectrum != output ), numOfLines > 0 ) ) { - Copy32( spectrum, output, numOfLines ); + Copy32( spectrum, output, numOfLines ); /*Qx*/ } } ELSE @@ -1289,7 +1288,7 @@ static void TnsFilter( FOR( j = 0; j < numOfLines; j++ ) { move32(); - output[j] = filter( order, parCoeff, state, spectrum[j] ); + output[j] = filter( order, parCoeff, state, spectrum[j] ); /*Qx*/ } } } @@ -1297,12 +1296,12 @@ static void TnsFilter( } static void ITF_TnsFilter_fx( - const Word32 spectrum[], - const Word16 numOfLines, - const Word16 A[], /* ifdef FIX_ITF_OVERFLOW Q_A else Q14 */ + const Word32 spectrum[], /*Qx*/ + const Word16 numOfLines, /*Q0*/ + const Word16 A[], /* ifdef FIX_ITF_OVERFLOW Q_A else Q14 */ const Word16 Q_A, - const Word16 order, - Word32 output[] ) + const Word16 order, /*Q0*/ + Word32 output[] /*Qx*/ ) { Word16 i, j; Word32 buf[ITF_MAX_FILTER_ORDER + N_MAX]; @@ -1317,7 +1316,7 @@ static void ITF_TnsFilter_fx( test(); IF( s_and( ( spectrum != output ), numOfLines > 0 ) ) { - Copy32( spectrum, output, numOfLines ); + Copy32( spectrum, output, numOfLines ); /*Qx*/ } } ELSE @@ -1326,7 +1325,7 @@ static void ITF_TnsFilter_fx( p = buf + ITF_MAX_FILTER_ORDER; set32_fx( buf, 0, ITF_MAX_FILTER_ORDER ); - Copy32( spectrum, p, numOfLines ); + Copy32( spectrum, p, numOfLines ); /*Qx*/ FOR( j = 0; j < numOfLines; j++ ) { Word32 L_tmp; @@ -1334,9 +1333,9 @@ static void ITF_TnsFilter_fx( L_tmp = L_add( p[0], 0 ); FOR( i = 1; i < order; i++ ) { - L_tmp = L_add_sat( L_tmp, L_shl( Mpy_32_16_1( p[-i], A[i] ), shift ) ); + L_tmp = L_add_sat( L_tmp, L_shl( Mpy_32_16_1( p[-i], A[i] ), shift ) ); /*Qx*/ } - output[j] = L_tmp; + output[j] = L_tmp; /*Qx*/ move32(); ++p; } @@ -1345,11 +1344,11 @@ static void ITF_TnsFilter_fx( } static void ITF_GetFilterParameters_fx( - Word32 rxx[], - const Word16 maxOrder, - Word16 *A, /* ifdef FIX_ITF_OVERFLOW Q_A else Q14 */ + Word32 rxx[], /*Qx*/ + const Word16 maxOrder, /*Q0*/ + Word16 *A, /* ifdef FIX_ITF_OVERFLOW Q_A else Q14 */ Word16 *Q_A, - Word16 *predictionGain ) + Word16 *predictionGain /*Q7*/ ) { Word16 i, j, i_2, tmp; Word16 parCoeff[ITF_MAX_FILTER_ORDER]; @@ -1357,8 +1356,8 @@ static void ITF_GetFilterParameters_fx( /* compute filter in ParCor form with LeRoux-Gueguen algorithm */ L_tmp = E_LPC_schur( rxx, parCoeff, epsP, maxOrder ); - BASOP_SATURATE_WARNING_OFF_EVS /* Allow saturation, this value is compared against a threshold. */ - *predictionGain = divide3232( L_shr( epsP[0], PRED_GAIN_E ), L_tmp ); + BASOP_SATURATE_WARNING_OFF_EVS /* Allow saturation, this value is compared against a threshold. */ + *predictionGain = divide3232( L_shr( epsP[0], PRED_GAIN_E ), L_tmp ); /*Q7*/ move16(); BASOP_SATURATE_WARNING_ON_EVS @@ -1381,15 +1380,15 @@ static void ITF_GetFilterParameters_fx( { tmp1_l = L_Extract_lc( A32[i - 1 - j + 1], &tmp1_h ); tmp2_l = L_Extract_lc( A32[j + 1], &tmp2_h ); - A32[j + 1] = Mac_32( A32[j + 1], parCoeff[i], 0, tmp1_h, tmp1_l ); /*+= parCoeff[i] * a[i-1-j+1];*/ + A32[j + 1] = Mac_32( A32[j + 1], parCoeff[i], 0, tmp1_h, tmp1_l ); /*+= parCoeff[i] * a[i-1-j+1]; Q11+16*/ move32(); - A32[i - 1 - j + 1] = Mac_32( A32[i - 1 - j + 1], parCoeff[i], 0, tmp2_h, tmp2_l ); /*+= parCoeff[i] * tmp;*/ + A32[i - 1 - j + 1] = Mac_32( A32[i - 1 - j + 1], parCoeff[i], 0, tmp2_h, tmp2_l ); /*+= parCoeff[i] * tmp; Q11+16*/ move32(); } - if ( i & 1 ) + IF( s_and( i, 1 ) ) { tmp2_l = L_Extract_lc( A32[j + 1], &tmp2_h ); - A32[j + 1] = Mac_32( A32[j + 1], parCoeff[i], 0, tmp2_h, tmp2_l ); /*+= parCoeff[i] * a[j+1];*/ + A32[j + 1] = Mac_32( A32[j + 1], parCoeff[i], 0, tmp2_h, tmp2_l ); /*+= parCoeff[i] * a[j+1]; Q11+16*/ move32(); } diff --git a/lib_com/trans_direct_fx.c b/lib_com/trans_direct_fx.c index 82e2c981c..d4792fb75 100644 --- a/lib_com/trans_direct_fx.c +++ b/lib_com/trans_direct_fx.c @@ -13,12 +13,12 @@ * Transformation of the signal to DCT domain *-------------------------------------------------------------------*/ void direct_transform_fx( - const Word32 in32_fx[], /* i : input signal */ - Word32 out32_fx[], /* o : transformation */ - const Word16 is_transient, /* i : is transient */ - const Word16 L, /* i : length */ + const Word32 in32_fx[], /* i : input signal Q*/ + Word32 out32_fx[], /* o : transformation Q*/ + const Word16 is_transient, /* i : is transient Q0*/ + const Word16 L, /* i : length Q0*/ Word16 *Q, - const Word16 element_mode /* i : IVAS element mode */ + const Word16 element_mode /* i : IVAS element mode Q0*/ ) { @@ -53,54 +53,54 @@ void direct_transform_fx( { IF( EQ_16( L, L_FRAME48k ) ) { - win_fx = wscw16q15_fx; + win_fx = wscw16q15_fx; /*Q15*/ } ELSE IF( EQ_16( L, L_FRAME32k ) ) { - win_fx = wscw16q15_32_fx; + win_fx = wscw16q15_32_fx; /*Q15*/ } ELSE IF( EQ_16( L, L_FRAME8k ) ) { - win_fx = wscw16q15_8_fx; + win_fx = wscw16q15_8_fx; /*Q15*/ } ELSE { - win_fx = wscw16q15_16_fx; + win_fx = wscw16q15_16_fx; /*Q15*/ } - sh_fx = &in32_fx[sub( L, 1 )]; - sl_fx = &in32_r16_fx[sub( L, 1 )]; + sh_fx = &in32_fx[( L - 1 )]; /*Q*/ + sl_fx = &in32_r16_fx[( L - 1 )]; /*Q*/ FOR( i = 0; i < segment_length; i++ ) { - in32_r16_fx[i] = ( *sh_fx-- ); + in32_r16_fx[i] = ( *sh_fx-- ); /*Q*/ move32(); - ( *sl_fx-- ) = in32_fx[i]; + ( *sl_fx-- ) = in32_fx[i]; /*Q*/ move32(); } - iseg_fx = &in32_r16_fx[-segment_length4]; - oseg_fx = out32_fx; + iseg_fx = &in32_r16_fx[-segment_length4]; /*Q*/ + oseg_fx = out32_fx; /*Q*/ - wh_fx = &win_fx[segment_length4]; - wl_fx = wh_fx - 1; + wh_fx = &win_fx[segment_length4]; /*Q15*/ + wl_fx = wh_fx - 1; /*Q15*/ - shift = extract_l( L_mult0( 3, segment_length4 ) ); - sh_fx = &iseg_fx[shift]; - sl_fx2 = sh_fx - 1; + shift = extract_l( L_mult0( 3, segment_length4 ) ); /*Q0*/ + sh_fx = &iseg_fx[shift]; /*Q*/ + sl_fx2 = sh_fx - 1; /*Q*/ FOR( i = 0; i < segment_length4; i++ ) { L_tmp = L_negate( Mult_32_16( ( *sh_fx++ ), ( *wh_fx++ ) ) ); /*Q+15-15=Q */ - dctin32_fx[i] = Madd_32_16( L_tmp, *sl_fx2--, *wl_fx-- ); - move32(); /*Q */ + dctin32_fx[i] = Madd_32_16( L_tmp, *sl_fx2--, *wl_fx-- ); /*Q*/ + move32(); } - sl_fx2 = &iseg_fx[sub( segment_length2, 1 )]; + sl_fx2 = &iseg_fx[( segment_length2 - 1 )]; /*Q*/ FOR( i = segment_length4; i < segment_length2; i++ ) { - dctin32_fx[i] = L_negate( *sl_fx2-- ); + dctin32_fx[i] = L_negate( *sl_fx2-- ); /*Q*/ move32(); } @@ -114,27 +114,27 @@ void direct_transform_fx( FOR( seg = 1; seg < NUM_TIME_SWITCHING_BLOCKS - 1; seg++ ) { - wh_fx = &win_fx[segment_length4]; - wl_fx = wh_fx - 1; - sh_fx = &iseg_fx[shift]; - sl_fx2 = sh_fx - 1; + wh_fx = &win_fx[segment_length4]; /*Q15*/ + wl_fx = wh_fx - 1; /*Q15*/ + sh_fx = &iseg_fx[shift]; /*Q*/ + sl_fx2 = sh_fx - 1; /*Q*/ FOR( i = 0; i < segment_length4; i++ ) { L_tmp = L_negate( Mult_32_16( ( *sh_fx++ ), ( *wh_fx++ ) ) ); /*Q+15-15=Q */ - dctin32_fx[i] = Madd_32_16( L_tmp, *sl_fx2--, *wl_fx-- ); - move32(); /*Q */ + dctin32_fx[i] = Madd_32_16( L_tmp, *sl_fx2--, *wl_fx-- ); /*Q*/ + move32(); } - sh_fx = iseg_fx; - sl_fx2 = &iseg_fx[sub( segment_length2, 1 )]; - wh_fx = &win_fx[sub( segment_length2, 1 )]; - wl_fx = win_fx; + sh_fx = iseg_fx; /*Q*/ + sl_fx2 = &iseg_fx[( segment_length2 - 1 )]; /*Q*/ + wh_fx = &win_fx[( segment_length2 - 1 )]; /*Q15*/ + wl_fx = win_fx; /*Q15*/ FOR( i = segment_length4; i < segment_length2; i++ ) { - L_tmp = Mult_32_16( ( *sh_fx++ ), ( *wh_fx-- ) ); /*Q+15-15=Q */ - dctin32_fx[i] = Madd_32_16( L_tmp, *sl_fx2--, *wl_fx++ ); - move32(); /*Q */ + L_tmp = Mult_32_16( ( *sh_fx++ ), ( *wh_fx-- ) ); /*Q+15-15=Q */ + dctin32_fx[i] = Madd_32_16( L_tmp, *sl_fx2--, *wl_fx++ ); /*Q*/ + move32(); } Qs[seg] = *Q; @@ -146,24 +146,24 @@ void direct_transform_fx( oseg_fx += segment_length2; } - sh_fx = &iseg_fx[sub( shift, 1 )]; + sh_fx = &iseg_fx[( shift - 1 )]; /*Q*/ FOR( i = 0; i < segment_length4; i++ ) { - dctin32_fx[i] = L_negate( *sh_fx-- ); + dctin32_fx[i] = L_negate( *sh_fx-- ); /*Q*/ move32(); } - sh_fx = iseg_fx; - sl_fx2 = &iseg_fx[sub( segment_length2, 1 )]; - wh_fx = &win_fx[sub( segment_length2, 1 )]; - wl_fx = win_fx; + sh_fx = iseg_fx; /*Q*/ + sl_fx2 = &iseg_fx[( segment_length2 - 1 )]; /*Q*/ + wh_fx = &win_fx[( segment_length2 - 1 )]; /*Q15*/ + wl_fx = win_fx; /*Q15*/ FOR( i = segment_length4; i < segment_length2; i++ ) { - L_tmp = Mult_32_16( ( *sl_fx2-- ), ( *wl_fx++ ) ); /*Q+15-15=Q */ - dctin32_fx[i] = Madd_32_16( L_tmp, *sh_fx++, *wh_fx-- ); - move32(); /*Q */ + L_tmp = Mult_32_16( ( *sl_fx2-- ), ( *wl_fx++ ) ); /*Q+15-15=Q */ + dctin32_fx[i] = Madd_32_16( L_tmp, *sh_fx++, *wh_fx-- ); /*Q*/ + move32(); } Qs[NUM_TIME_SWITCHING_BLOCKS - 1] = *Q; move16(); @@ -172,13 +172,13 @@ void direct_transform_fx( *Q = Qmin; move16(); - oseg_fx = out32_fx; + oseg_fx = out32_fx; /*Q*/ FOR( k = 0; k < NUM_TIME_SWITCHING_BLOCKS; k++ ) { shift = sub( Qs[k], *Q ); FOR( i = 0; i < segment_length2; i++ ) { - *oseg_fx = L_shr( ( *oseg_fx ), shift ); + *oseg_fx = L_shr( ( *oseg_fx ), shift ); /*Q*/ move32(); oseg_fx++; } diff --git a/lib_com/trans_inv_fx.c b/lib_com/trans_inv_fx.c index 6916a6cdb..5c41122fb 100644 --- a/lib_com/trans_inv_fx.c +++ b/lib_com/trans_inv_fx.c @@ -111,7 +111,7 @@ void preecho_sb_fx( move16(); smooth_len = 4; move16(); - invsmoothlenp1_fx = 6554; + invsmoothlenp1_fx = 6554; /*0.2 in Q15*/ move16(); IF( EQ_16( nb_flag, 1 ) ) { @@ -123,7 +123,7 @@ void preecho_sb_fx( move16(); } - limmaxnzcr = mult( framelength, 1365 ); /*1/24*/ + limmaxnzcr = mult( framelength, 1365 ); /*1/24 in Q15*/ /*Q0*/ num_subsubframes = 8; move16(); log2_num_subsubframes = 3; @@ -137,15 +137,15 @@ void preecho_sb_fx( move16(); } - len3xLp20 = mult_r( framelength, 7168 ); /*7*framelength/32;*/ + len3xLp20 = mult_r( framelength, 7168 ); /*7*framelength/32;*/ /*Q0*/ /* len3xLp20 = framelength/2-(short)((float)framelength*N_ZERO_MDCT/FRAME_SIZE_MS); in float*/ fxptr1 = imdct_mem_fx; - fx32ptr1 = wtda_audio_fx + len3xLp20 - 1; + fx32ptr1 = wtda_audio_fx + len3xLp20 - 1; /*q_sig32*/ FOR( i = 0; i < len3xLp20; i++ ) { #ifdef BASOP_NOGLOB - *fxptr1++ = negate( extract_h( L_shl_sat( *fx32ptr1--, 15 - q_sig32 ) ) ); + *fxptr1++ = negate( extract_h( L_shl_sat( *fx32ptr1--, sub( 15, q_sig32 ) ) ) ); /*Q-1*/ #else *fxptr1++ = negate( extract_h( L_shl( *fx32ptr1--, 15 - q_sig32 ) ) ); #endif @@ -154,7 +154,7 @@ void preecho_sb_fx( FOR( i = 0; i < L_shr( framelength, 1 ); i++ ) { #ifdef BASOP_NOGLOB - *fxptr1++ = negate( extract_h( L_shl_sat( wtda_audio_fx[i], 15 - q_sig32 ) ) ); + *fxptr1++ = negate( extract_h( L_shl_sat( wtda_audio_fx[i], sub( 15, q_sig32 ) ) ) ); /*Q-1*/ #else *fxptr1++ = negate( extract_h( L_shl( wtda_audio_fx[i], 15 - q_sig32 ) ) ); #endif @@ -162,19 +162,19 @@ void preecho_sb_fx( } qmemp1 = 0; /*already in q-1*/ - subframelength = shr( framelength, LOG2_NUMSF ); - subsubframelength = shr( subframelength, log2_num_subsubframes ); - wmold_fx = *smoothmem_fx; + subframelength = shr( framelength, LOG2_NUMSF ); /*Q0*/ + subsubframelength = shr( subframelength, log2_num_subsubframes ); /*Q0*/ + wmold_fx = *smoothmem_fx; /*Q15*/ move16(); - subframelength_s2 = shr( subframelength, 1 ); - subframelength_s34 = mult( subframelength, 24576 ); + subframelength_s2 = shr( subframelength, 1 ); /*Q0*/ + subframelength_s34 = mult( subframelength, 24576 /*3/4 in Q15*/ ); /*Q0*/ cntnzcr = -1; move16(); - lim16_fx = 3277; + lim16_fx = 3277; /*Q15*/ move16(); - lim32_fx = 328; + lim32_fx = 328; /*Q15*/ move16(); savehalfe_fx = L_deposit_l( 0 ); savehalfe_hb_fx = L_deposit_l( 0 ); @@ -182,34 +182,34 @@ void preecho_sb_fx( IF( *pastpre == 0 ) { /* if past frame mean energies are not known (no preecho_sb in the past frame), limit max attenuation to 1*/ - lim16_fx = 32767; + lim16_fx = 32767; /*Q15*/ move16(); - lim32_fx = 32767; + lim32_fx = 32767; /*Q15*/ move16(); } *pastpre = 2; move16(); - fxptr1 = rec_sig_lb_fx; /*q_sig16*/ - fxptr2 = rec_sig_fx; - fxptr3 = rec_sig_fx + 1; - fxptr4 = rec_sig_fx + 2; + fxptr1 = rec_sig_lb_fx; /*q_sig16*/ + fxptr2 = rec_sig_fx; /*q_sig16*/ + fxptr3 = rec_sig_fx + 1; /*q_sig16*/ + fxptr4 = rec_sig_fx + 2; /*q_sig16*/ #ifdef BASOP_NOGLOB tmp_fxL1 = L_mult( shl_sat( *memfilt_lb_fx, q_sig16 ), 8192 ); /* *memfilt_lb_fx in q0 */ #else tmp_fxL1 = L_mult( shl( *memfilt_lb_fx, q_sig16 ), 8192 ); /* *memfilt_lb_fx in q0 */ #endif - tmp_fxL1 = L_mac( tmp_fxL1, *fxptr3, 8192 ); - *fxptr1 = mac_r( tmp_fxL1, *fxptr2, 16384 ); + tmp_fxL1 = L_mac( tmp_fxL1, *fxptr3, 8192 /*Q15*/ ); /*Q16*/ + *fxptr1 = mac_r( tmp_fxL1, *fxptr2, 16384 /*Q15*/ ); /*Q0*/ move16(); fxptr1++; FOR( j = 2; j < framelength; j++ ) { - tmp_fxL1 = L_mult( *fxptr2, 8192 ); - tmp_fxL1 = L_mac( tmp_fxL1, *fxptr4, 8192 ); - *fxptr1 = mac_r( tmp_fxL1, *fxptr3, 16384 ); + tmp_fxL1 = L_mult( *fxptr2, 8192 /*Q15*/ ); /*Q16*/ + tmp_fxL1 = L_mac( tmp_fxL1, *fxptr4, 8192 /*Q15*/ ); /*Q16*/ + *fxptr1 = mac_r( tmp_fxL1, *fxptr3, 16384 /*Q15*/ ); /*Q0*/ move16(); fxptr1++; fxptr2++; @@ -217,8 +217,8 @@ void preecho_sb_fx( fxptr4++; } - tmp_fxL1 = L_mult( *fxptr2, 8192 ); - *fxptr1 = mac_r( tmp_fxL1, *fxptr3, 16384 ); + tmp_fxL1 = L_mult( *fxptr2, 8192 ); /*Q16*/ + *fxptr1 = mac_r( tmp_fxL1, *fxptr3, 16384 ); /*Q0*/ move16(); fxptr1 = rec_sig_lb_fx; /*q_sig16*/ fxptr2 = rec_sig_fx; /*q_sig16*/ @@ -235,20 +235,20 @@ void preecho_sb_fx( fxptr2--; #ifdef BASOP_NOGLOB - *memfilt_lb_fx = shr_sat( *fxptr2, q_sig16 ); + *memfilt_lb_fx = shr_sat( *fxptr2, q_sig16 ); /*Q0*/ #else *memfilt_lb_fx = shr( *fxptr2, q_sig16 ); #endif move16(); /* *memfilt_lb_fx in q0 */ /* energy of low bands 8 present and 1 future sub-frames */ - sptr1 = zcr; + sptr1 = zcr; /*Q0*/ sptr1_loc = 0; move16(); - sptr2 = maxnzcr; + sptr2 = maxnzcr; /*Q0*/ - fxptr2 = rec_sig_fx; - fxptr3 = rec_sig_hb_fx; + fxptr2 = rec_sig_fx; /*q_sig16*/ + fxptr3 = rec_sig_hb_fx; /*q_sig16*/ fx32ptr1 = es_mdct_fx; fx32ptr5 = es_mdct_half_fx; fx32ptr6 = es_mdct_quart_fx; @@ -259,9 +259,9 @@ void preecho_sb_fx( { tmp_fx2 = sub( j, 1 ); #ifdef BASOP_NOGLOB - tmp_fx1 = shr_sat( *fxptr2, q16p1 ); /*q-1 to avoisd saturation in energy*/ - tmp_fxL1 = L_mac0_sat( 25, tmp_fx1, tmp_fx1 ); - tmp_fxL2 = L_mac0_sat( 100, *fxptr3, *fxptr3 ); + tmp_fx1 = shr_sat( *fxptr2, q16p1 ); /*q-1 to avoisd saturation in energy*/ + tmp_fxL1 = L_mac0_sat( 25, tmp_fx1, tmp_fx1 ); /*2*(Q-1)*/ + tmp_fxL2 = L_mac0_sat( 100, *fxptr3, *fxptr3 ); /*2*(q_sig16)*/ #else tmp_fx1 = shr( *fxptr2, q16p1 ); /*q-1 to avoisd saturation in energy*/ tmp_fxL1 = L_mac0( 25, tmp_fx1, tmp_fx1 ); @@ -278,19 +278,19 @@ void preecho_sb_fx( { if ( EQ_16( i, subframelength_s2 ) ) { - *fx32ptr5 = tmp_fxL1; + *fx32ptr5 = tmp_fxL1; /*2*(Q-1)*/ move32(); } if ( EQ_16( i, subframelength_s34 ) ) { - *fx32ptr6 = tmp_fxL1; + *fx32ptr6 = tmp_fxL1; /*2*(Q-1)*/ move32(); } #ifdef BASOP_NOGLOB - tmp_fx1 = shr_sat( *fxptr2, q16p1 ); /*q-1 to avoisd saturation in energy*/ - tmp_fxL1 = L_mac0_sat( tmp_fxL1, tmp_fx1, tmp_fx1 ); - tmp_fxL2 = L_mac0_sat( tmp_fxL2, *fxptr3, *fxptr3 ); + tmp_fx1 = shr_sat( *fxptr2, q16p1 ); /*q-1 to avoisd saturation in energy*/ + tmp_fxL1 = L_mac0_sat( tmp_fxL1, tmp_fx1, tmp_fx1 ); /*2*(Q-1)*/ + tmp_fxL2 = L_mac0_sat( tmp_fxL2, *fxptr3, *fxptr3 ); /*2*(q_sig16)*/ #else tmp_fx1 = shr( *fxptr2, q16p1 ); /*q-1 to avoisd saturation in energy*/ tmp_fxL1 = L_mac0( tmp_fxL1, tmp_fx1, tmp_fx1 ); @@ -305,7 +305,7 @@ void preecho_sb_fx( test(); if ( ( firstnzcr > 0 ) && ( GT_16( cntnzcr, maxnzcr[tmp_fx2] ) ) ) { - maxnzcr[tmp_fx2] = cntnzcr; + maxnzcr[tmp_fx2] = cntnzcr; /*Q0*/ move16(); } @@ -322,12 +322,12 @@ void preecho_sb_fx( cntnzcr = add( cntnzcr, 1 ); } sptr2_loc = s_max( sptr2_loc, cntnzcr ); - *fx32ptr4 = tmp_fxL2; + *fx32ptr4 = tmp_fxL2; /*2*(q_sig16)*/ move32(); fx32ptr4++; - *sptr1 = sptr1_loc; + *sptr1 = sptr1_loc; /*Q0*/ move16(); - *sptr2 = sptr2_loc; + *sptr2 = sptr2_loc; /*Q0*/ move16(); sptr1++; sptr2++; @@ -335,7 +335,7 @@ void preecho_sb_fx( test(); if ( ( firstnzcr > 0 ) && ( GT_16( cntnzcr, maxnzcr[tmp_fx2] ) ) ) { - maxnzcr[tmp_fx2] = cntnzcr; + maxnzcr[tmp_fx2] = cntnzcr; /*Q0*/ move16(); } @@ -353,17 +353,17 @@ void preecho_sb_fx( move16(); } - *fx32ptr1 = tmp_fxL1; + *fx32ptr1 = tmp_fxL1; /*2*(Q-1)*/ move32(); if ( LT_32( *fx32ptr5, L_shr( *fx32ptr1, 1 ) ) ) { #ifdef BASOP_NOGLOB - tmp_fxL1 = L_shl_sat( L_sub_sat( *fx32ptr1, *fx32ptr5 ), 1 ); + tmp_fxL1 = L_shl_sat( L_sub_sat( *fx32ptr1, *fx32ptr5 ), 1 ); /*2*(Q-1)*/ #else tmp_fxL1 = L_shl( L_sub( *fx32ptr1, *fx32ptr5 ), 1 ); #endif } - *fx32ptr5 = tmp_fxL1; + *fx32ptr5 = tmp_fxL1; /*2*(Q-1)*/ move32(); fx32ptr1++; @@ -373,9 +373,9 @@ void preecho_sb_fx( fxptr2 = imdct_mem_fx; /* q_sig16 or q-1*/ j = NUMSF; - move16(); /* one future subframe but 96 samples (not 80) (enough with ALDO window) */ - tmp_fx1 = shr( *fxptr2, qmemp1 ); /* q-1 shr to avoid overflow in es_mdct_fx*/ - tmp_fxL1 = L_mac0( 25, tmp_fx1, tmp_fx1 ); + move16(); /* one future subframe but 96 samples (not 80) (enough with ALDO window) */ + tmp_fx1 = shr( *fxptr2, qmemp1 ); /* q-1 shr to avoid overflow in es_mdct_fx*/ + tmp_fxL1 = L_mac0( 25, tmp_fx1, tmp_fx1 ); /*2*(Q-1)*/ sptr1_loc = 0; move16(); @@ -385,7 +385,7 @@ void preecho_sb_fx( { tmp_fx1 = shr( *fxptr2, qmemp1 ); /*q-1 to avoisd saturation in energy*/ #ifdef BASOP_NOGLOB - tmp_fxL1 = L_mac0_sat( tmp_fxL1, tmp_fx1, tmp_fx1 ); + tmp_fxL1 = L_mac0_sat( tmp_fxL1, tmp_fx1, tmp_fx1 ); /*2*(Q-1)*/ #else tmp_fxL1 = L_mac0( tmp_fxL1, tmp_fx1, tmp_fx1 ); #endif @@ -396,27 +396,27 @@ void preecho_sb_fx( fxptr2++; } - *fx32ptr1 = tmp_fxL1; + *fx32ptr1 = tmp_fxL1; /*2*(Q-1)*/ move32(); - *sptr1 = sptr1_loc; - fxptr2 = imdct_mem_fx; - fxptr3 = imdct_mem_fx + 1; - fxptr4 = imdct_mem_fx + 2; - tmp_fxL1 = L_mult( rec_sig_fx[framelength_m1], -8192 ); - tmp_fxL1 = L_mac( tmp_fxL1, *fxptr3, -8192 ); - tmp_fx1 = mac_r( tmp_fxL1, *fxptr2, 16384 ); + *sptr1 = sptr1_loc; /*Q0*/ + fxptr2 = imdct_mem_fx; /*q_sig16*/ + fxptr3 = imdct_mem_fx + 1; /*q_sig16*/ + fxptr4 = imdct_mem_fx + 2; /*q_sig16*/ + tmp_fxL1 = L_mult( rec_sig_fx[framelength_m1], -8192 /*Q15*/ ); /*q_sig16+Q16*/ + tmp_fxL1 = L_mac( tmp_fxL1, *fxptr3, -8192 ); /*q_sig16+Q16*/ + tmp_fx1 = mac_r( tmp_fxL1, *fxptr2, 16384 /*Q15*/ ); /*q_sig16*/ tmp_fxL2 = L_deposit_l( 100 ); - tmp_fxL2 = L_mac0( tmp_fxL2, tmp_fx1, tmp_fx1 ); + tmp_fxL2 = L_mac0( tmp_fxL2, tmp_fx1, tmp_fx1 ); /*2*(q_sig16)*/ FOR( j = 1; j < tmp_fx3; j++ ) /* tmp_fx3 still contains subframelength*1.2-1 */ { - tmp_fxL1 = L_mult( *fxptr2, -8192 ); + tmp_fxL1 = L_mult( *fxptr2, -8192 /*Q15*/ ); /*q_sig16+Q16*/ #ifdef BASOP_NOGLOB - tmp_fxL1 = L_mac_sat( tmp_fxL1, *fxptr4, -8192 ); - tmp_fx1 = mac_r_sat( tmp_fxL1, *fxptr3, 16384 ); + tmp_fxL1 = L_mac_sat( tmp_fxL1, *fxptr4, -8192 ); /*q_sig16+Q16*/ + tmp_fx1 = mac_r_sat( tmp_fxL1, *fxptr3, 16384 /*Q15*/ ); /*q_sig16*/ - tmp_fxL2 = L_mac0_sat( tmp_fxL2, tmp_fx1, tmp_fx1 ); + tmp_fxL2 = L_mac0_sat( tmp_fxL2, tmp_fx1, tmp_fx1 ); /*2*(q_sig16)*/ #else tmp_fxL1 = L_mac( tmp_fxL1, *fxptr4, -8192 ); tmp_fx1 = mac_r( tmp_fxL1, *fxptr3, 16384 ); @@ -428,10 +428,10 @@ void preecho_sb_fx( fxptr4++; } - tmp_fxL1 = L_mult( *fxptr2, -8192 ); + tmp_fxL1 = L_mult( *fxptr2, -8192 /*Q15*/ ); /*q_sig16+Q16*/ #ifdef BASOP_NOGLOB - tmp_fx1 = mac_r_sat( tmp_fxL1, *fxptr3, 16384 ); - es_mdct_hb_fx[NUMSF] = L_mac0_sat( tmp_fxL2, tmp_fx1, tmp_fx1 ); + tmp_fx1 = mac_r_sat( tmp_fxL1, *fxptr3, 16384 /*Q15*/ ); /*q_sig16*/ + es_mdct_hb_fx[NUMSF] = L_mac0_sat( tmp_fxL2, tmp_fx1, tmp_fx1 ); /*2*(q_sig16)*/ #else tmp_fx1 = mac_r( tmp_fxL1, *fxptr3, 16384 ); es_mdct_hb_fx[NUMSF] = L_mac0( tmp_fxL2, tmp_fx1, tmp_fx1 ); @@ -481,11 +481,11 @@ void preecho_sb_fx( FOR( i = 0; i < maxind; i++ ) /* only subbands before max energy subband are handled */ { - g_fx = 32767; - move16(); /* default gain */ - min_g_fx[i] = 32767; + g_fx = 32767; /*Q15*/ + move16(); /* default gain */ + min_g_fx[i] = 32767; /*Q15*/ move16(); - min_g_hb_fx[i] = 32767; + min_g_hb_fx[i] = 32767; /*Q15*/ move16(); Mpy_32_16_ss( es_mdct_half_fx[i], 328, &tmp_fxL1, &tmp_u16 ); /* 328 for 1/100*/ @@ -515,13 +515,13 @@ void preecho_sb_fx( { IF( LT_32( es_mdct_fx[i], L_shr( max_es_fx, 4 ) ) ) { - g_fx = lim16_fx; + g_fx = lim16_fx; /*Q15*/ move16(); cnt5 = add( cnt5, 1 ); IF( LT_32( es_mdct_fx[i], L_shr( max_es_fx, 5 ) ) ) { - g_fx = lim32_fx; + g_fx = lim32_fx; /*Q15*/ move16(); cnt2 = add( cnt2, 1 ); } @@ -550,14 +550,14 @@ void preecho_sb_fx( move16(); } test(); - IF( ( LT_16( zcr[i], limzcr / 2 ) ) || ( GT_16( maxnzcr[i], limmaxnzcr ) ) ) + IF( ( LT_16( zcr[i], shr( limzcr, 1 ) ) ) || ( GT_16( maxnzcr[i], limmaxnzcr ) ) ) { if ( LT_16( min_g_fx[i], 32767 ) ) /* *mean_prev < es_mdct[i]) */ { mean_prev_fx_loc = L_add( es_mdct_fx[i], 0 ); } - min_g_fx[i] = 32767; - move16(); /* not noise-like, do not touch the amplitude, but may do in HB*/ + min_g_fx[i] = 32767; /*Q15*/ + move16(); /* not noise-like, do not touch the amplitude, but may do in HB*/ } } ELSE @@ -572,21 +572,21 @@ void preecho_sb_fx( move16(); /* no preecho reduction after the first subframe with gain 1*/ } } - gt_fx[i] = g_fx; + gt_fx[i] = g_fx; /*Q15*/ move16(); - gt_hb_fx[i] = g_fx; + gt_hb_fx[i] = g_fx; /*Q15*/ move16(); } FOR( i = maxind; i <= NUMSF; i++ ) /* also for the first memory subframe */ { - gt_fx[i] = 32767; + gt_fx[i] = 32767; /*Q15*/ move16(); - min_g_fx[i] = 32767; + min_g_fx[i] = 32767; /*Q15*/ move16(); - gt_hb_fx[i] = 32767; + gt_hb_fx[i] = 32767; /*Q15*/ move16(); - min_g_hb_fx[i] = 32767; + min_g_hb_fx[i] = 32767; /*Q15*/ move16(); } @@ -610,10 +610,10 @@ void preecho_sb_fx( ind2_m1 = sub( ind2, 1 ); ind2_sfl = i_mult( subframelength, ind2 ); numsf_ind2 = sub( NUMSF, ind2 ); - fxptr3 = gt_fx; - fxptr4 = gt_hb_fx; - fxptr5 = min_g_fx; - fxptr6 = min_g_hb_fx; + fxptr3 = gt_fx; /*Q15*/ + fxptr4 = gt_hb_fx; /*Q15*/ + fxptr5 = min_g_fx; /*Q15*/ + fxptr6 = min_g_hb_fx; /*Q15*/ fxptr1 = preechogain_fx + smooth_len; pre_g_ch_tab[0] = smooth_len; @@ -636,7 +636,7 @@ void preecho_sb_fx( fxptr1++; fxptr2++; } - pre_g_ch_tab[add( i, 1 )] = add( pre_g_ch_tab[i], subframelength ); + pre_g_ch_tab[( i + 1 )] = add( pre_g_ch_tab[i], subframelength ); fxptr3++; fxptr4++; fxptr5++; @@ -645,22 +645,23 @@ void preecho_sb_fx( max_plus_es_mdct_fx = L_deposit_l( 0 ); adv = smooth_len; - move16(); /* samples needed to have near 1 gain after smoothing at the beggining of the attack subframe*/ - advmem = adv; + move16(); /* samples needed to have near 1 gain after smoothing at the beggining of the attack subframe*/ + advmem = adv; /*Q0*/ move16(); test(); test(); IF( ind2 > 0 || LT_16( wmold_fx, 32767 ) || LT_16( *wmold_hb_fx, 32767 ) ) { - ptr_fx = imdct_mem_fx; + ptr_fx = imdct_mem_fx; /*q_sig16*/ qtmp = qmemp1; pluslim = num_subsubframes; move16(); /* if ind2 == NUMSF */ IF( numsf_ind2 > 0 ) { - ptr_fx = rec_sig_fx + ind2_sfl; + ptr_fx = rec_sig_fx + ind2_sfl; /*q_sig16*/ qtmp = q16p1; + move16(); pluslim = i_mult( numsf_ind2, num_subsubframes ); } @@ -670,21 +671,21 @@ void preecho_sb_fx( sum_plus_es_fx = L_add( mean_prev_nc_fx_loc, 0 ); /* 8 times mean sususb enenrgy (=maxcrit)*/ pluslim = num_subsubframes; move16(); - oldgain_fx = wmold_fx; + oldgain_fx = wmold_fx; /*Q15*/ move16(); - oldgain_hb_fx = *wmold_hb_fx; + oldgain_hb_fx = *wmold_hb_fx; /*Q15*/ move16(); } ELSE /* ind2 > 0*/ { sum_plus_es_fx = es_mdct_fx[ind2_m1]; - move32(); /* 8 times mean sususb enenrgy (=maxcrit)*/ - oldgain_fx = gt_fx[ind2_m1]; + move32(); /* 8 times mean sususb enenrgy (=maxcrit)*/ + oldgain_fx = gt_fx[ind2_m1]; /*Q15*/ move16(); - oldgain_hb_fx = gt_hb_fx[ind2_m1]; + oldgain_hb_fx = gt_hb_fx[ind2_m1]; /*Q15*/ move16(); - tmp_fx1 = mult_r( gt_fx[ind2_m1], gt_fx[ind2_m1] ); + tmp_fx1 = mult_r( gt_fx[ind2_m1], gt_fx[ind2_m1] ); /*Q15*/ Mpy_32_16_ss( es_mdct_fx[ind2_m1], tmp_fx1, &maxcrit_fx, &tmp_u16 ); Mpy_32_16_ss( max_es_fx, 410, &tmp_fxL1, &tmp_u16 ); /* 410 for 1/80*/ @@ -705,7 +706,7 @@ void preecho_sb_fx( tmp_fx1 = shr( *ptr_fx, qtmp ); /* q-1, to have same shift as es_mdct_.. */ #ifdef BASOP_NOGLOB - tmp_fxL1 = L_mac0_sat( tmp_fxL1, tmp_fx1, tmp_fx1 ); + tmp_fxL1 = L_mac0_sat( tmp_fxL1, tmp_fx1, tmp_fx1 ); /*2*(Q-1)*/ #else tmp_fxL1 = L_mac0( tmp_fxL1, tmp_fx1, tmp_fx1 ); #endif @@ -717,11 +718,11 @@ void preecho_sb_fx( } #ifdef BASOP_NOGLOB - sum_plus_es_fx = L_add_sat( sum_plus_es_fx, L_shl_sat( tmp_fxL1, 2 ) ); + sum_plus_es_fx = L_add_sat( sum_plus_es_fx, L_shl_sat( tmp_fxL1, 2 ) ); /*2*(Q-1)*/ #else sum_plus_es_fx = L_add( sum_plus_es_fx, L_shl( tmp_fxL1, 2 ) ); #endif - *fx32ptr1 = tmp_fxL1; + *fx32ptr1 = tmp_fxL1; /*2*(Q-1)*/ fx32ptr1++; Mpy_32_16_ss( sum_plus_es_fx, inv_jp2[j], fx32ptr4, &tmp_u16 ); /* 410 for 1/80*/ if ( LT_32( *fx32ptr4, maxcrit_fx ) ) @@ -732,18 +733,18 @@ void preecho_sb_fx( fx32ptr4++; } *fx32ptr4 = -1; - move32(); /*mean_plus_es_fx[pluslim] = -1; */ - *mean_plus_es_fx = *plus_es_mdct_fx; - move32(); /* index [0] */ + move32(); /*mean_plus_es_fx[pluslim] = -1; */ + *mean_plus_es_fx = *plus_es_mdct_fx; /*2*(Q-1)*/ + move32(); /* index [0] */ if ( LT_32( *mean_plus_es_fx, maxcrit_fx ) ) { - *mean_plus_es_fx = maxcrit_fx; + *mean_plus_es_fx = maxcrit_fx; /*2*(Q-1)*/ move32(); } j = 0; move16(); - WHILE( ( LT_32( plus_es_mdct_fx[j], mean_plus_es_fx[j] ) ) && ( LT_32( plus_es_mdct_fx[j], max_plus_es_mdct_fx / 8 ) ) ) + WHILE( ( LT_32( plus_es_mdct_fx[j], mean_plus_es_fx[j] ) ) && ( LT_32( plus_es_mdct_fx[j], L_shr( max_plus_es_mdct_fx, 3 ) ) ) ) { test(); j = add( j, 1 ); @@ -757,10 +758,10 @@ void preecho_sb_fx( FOR( i = 0; i < tmp_fx3; i++ ) { - *fxptr1 = oldgain_fx; - move16(); /*keep the gain of the previous subframe*/ - *fxptr2 = oldgain_hb_fx; - move16(); /*keep the gain of the previous subframe*/ + *fxptr1 = oldgain_fx; /*Q15*/ + move16(); /*keep the gain of the previous subframe*/ + *fxptr2 = oldgain_hb_fx; /*Q15*/ + move16(); /*keep the gain of the previous subframe*/ fxptr1++; fxptr2++; } @@ -777,16 +778,16 @@ void preecho_sb_fx( IF( ind4 > 0 ) { /* case of 3 points is simply */ - eshbmean2_fx = L_add( es_mdct_hb_fx[ind4], es_mdct_hb_fx[ind5] ); + eshbmean2_fx = L_add( es_mdct_hb_fx[ind4], es_mdct_hb_fx[ind5] ); /*2*(q_sig16)*/ sxyhb2_fx = L_sub( es_mdct_hb_fx[ind4], es_mdct_hb_fx[ind5] ); /* / eshbmean2 * 2; 04042013: division not needed, only sign of sxyhb2 is used*/ IF( GT_16( ind3, 2 ) ) { - tmp_fxL1 = L_add( eshbmean2_fx, es_mdct_hb_fx[ind6] ); - Mpy_32_16_ss( tmp_fxL1, 4369, &eshbmean3_fx, &tmp_u16 ); /*10922 : 1/3*/ - sxylb3_fx = L_sub( es_mdct_fx[ind4], es_mdct_fx[ind6] ); /* /eslbmean3 / 2; /2 for 3 points regression calc; 04042013: division not needed, only sign of sxylb3 is used*/ - tmp_fxL1 = L_sub( es_mdct_hb_fx[ind4], es_mdct_hb_fx[ind6] ); + tmp_fxL1 = L_add( eshbmean2_fx, es_mdct_hb_fx[ind6] ); /*2*(q_sig16)*/ + Mpy_32_16_ss( tmp_fxL1, 4369, &eshbmean3_fx, &tmp_u16 ); /*10922 : 1/3*/ + sxylb3_fx = L_sub( es_mdct_fx[ind4], es_mdct_fx[ind6] ); /* /eslbmean3 / 2; /2 for 3 points regression calc; 04042013: division not needed, only sign of sxylb3 is used*/ + tmp_fxL1 = L_sub( es_mdct_hb_fx[ind4], es_mdct_hb_fx[ind6] ); /*2*(q_sig16)*/ test(); IF( ( LT_32( tmp_fxL1, eshbmean3_fx ) ) || ( sxylb3_fx < 0 ) ) { @@ -811,10 +812,10 @@ void preecho_sb_fx( } } - tmp_fxL1 = L_add( eshbmean2_fx, es_mdct_hb_fx[ind3] ); + tmp_fxL1 = L_add( eshbmean2_fx, es_mdct_hb_fx[ind3] ); /*2*(q_sig16)*/ Mpy_32_16_ss( tmp_fxL1, 4369, &eshbmean3_fx, &tmp_u16 ); /*10922 : 1/3*/ - tmp_fxL1 = L_sub( es_mdct_hb_fx[ind3], es_mdct_hb_fx[ind5] ); + tmp_fxL1 = L_sub( es_mdct_hb_fx[ind3], es_mdct_hb_fx[ind5] ); /*2*(q_sig16)*/ IF( LT_32( tmp_fxL1, eshbmean3_fx ) ) { ind2 = 0; @@ -844,82 +845,82 @@ void preecho_sb_fx( } tmp_fx1 = add( stind, smooth_len ); - fxptr1 = preechogain_fx + tmp_fx1; - fxptr2 = preechogain_hb_fx + stind_hb; + fxptr1 = preechogain_fx + tmp_fx1; /*Q15*/ + fxptr2 = preechogain_hb_fx + stind_hb; /*Q15*/ FOR( i = tmp_fx1; i < framelength; i++ ) /* rest of the gains, without 4 (PREECHO_SMOOTH_LEN) 1 for fadeout */ { - *( fxptr1++ ) = 32767; + *( fxptr1++ ) = 32767; /*Q15*/ move16(); } - pre_g_ch_tab[ind2] = s_min( tmp_fx1, framelength ); + pre_g_ch_tab[ind2] = s_min( tmp_fx1, framelength ); /*Q0*/ move16(); FOR( i = stind_hb; i < framelength; i++ ) /* rest of the gains*/ { - *( fxptr2++ ) = 32767; + *( fxptr2++ ) = 32767; /*Q15*/ move16(); } - fxptr1 = preechogain_fx; + fxptr1 = preechogain_fx; /*Q15*/ FOR( i = 0; i < smooth_len; i++ ) { - *( fxptr1++ ) = *smoothmem_fx; + *( fxptr1++ ) = *smoothmem_fx; /*Q15*/ move16(); } - fattnext_fx = 32767; + fattnext_fx = 32767; /*Q15*/ move16(); if ( GT_16( stind, framelength ) ) { - fattnext_fx = gt_fx[ind2_m1]; + fattnext_fx = gt_fx[ind2_m1]; /*Q15*/ move16(); } - fxptr1 = preechogain_fx + framelength; + fxptr1 = preechogain_fx + framelength; /*Q15*/ FOR( i = 0; i < smooth_len; i++ ) { - *( fxptr1++ ) = fattnext_fx; + *( fxptr1++ ) = fattnext_fx; /*Q15*/ move16(); } FOR( i = 0; i <= ind2; i++ ) { - tmp_fx1 = pre_g_ch_tab[i]; + tmp_fx1 = pre_g_ch_tab[i]; /*Q0*/ move16(); tmp_fx2 = sub( tmp_fx1, smooth_len ); /* any index in the previous subframe*/ - tmp_fx3 = mult_r( sub( preechogain_fx[tmp_fx1], preechogain_fx[tmp_fx2] ), invsmoothlenp1_fx ); /*step*/ - tmp_fx1 = tmp_fx3; - move16(); /*cumulated step*/ - fxptr1 = preechogain_fx + tmp_fx2; + tmp_fx3 = mult_r( sub( preechogain_fx[tmp_fx1], preechogain_fx[tmp_fx2] ), invsmoothlenp1_fx ); /*step Q15*/ + tmp_fx1 = tmp_fx3; /*Q15*/ + move16(); /*cumulated step*/ + fxptr1 = preechogain_fx + tmp_fx2; /*Q15*/ FOR( j = 0; j < smooth_len; j++ ) { #ifdef BASOP_NOGLOB - *fxptr1 = add_sat( *fxptr1, tmp_fx1 ); + *fxptr1 = add_sat( *fxptr1, tmp_fx1 ); /*Q15*/ #else *fxptr1 = add( *fxptr1, tmp_fx1 ); #endif move16(); - tmp_fx1 = add( tmp_fx1, tmp_fx3 ); + tmp_fx1 = add( tmp_fx1, tmp_fx3 ); /*Q15*/ fxptr1++; } } - *smoothmem_fx = fattnext_fx; + *smoothmem_fx = fattnext_fx; /*Q15*/ move16(); - *wmold_hb_fx = preechogain_hb_fx[framelength_m1]; + *wmold_hb_fx = preechogain_hb_fx[framelength_m1]; /*Q15*/ move16(); /* apply gain */ - fxptr1 = preechogain_fx; - fxptr2 = preechogain_hb_fx; - fxptr3 = rec_sig_fx; - fxptr4 = rec_sig_lb_fx; - fxptr5 = rec_sig_hb_fx; + fxptr1 = preechogain_fx; /*Q15*/ + fxptr2 = preechogain_hb_fx; /*Q15*/ + fxptr3 = rec_sig_fx; /*q_sig16*/ + fxptr4 = rec_sig_lb_fx; /*q_sig16*/ + fxptr5 = rec_sig_hb_fx; /*q_sig16*/ FOR( i = 0; i < framelength; i++ ) { - tmp_fxL1 = L_mult( *fxptr4, *fxptr1 ); - *fxptr3 = mac_r( tmp_fxL1, *fxptr5, *fxptr2 ); + tmp_fxL1 = L_mult( *fxptr4, *fxptr1 ); /*q_sig16 + Q16*/ + *fxptr3 = mac_r( tmp_fxL1, *fxptr5, *fxptr2 ); /*q_sig16*/ move16(); fxptr1++; fxptr2++; @@ -928,16 +929,16 @@ void preecho_sb_fx( fxptr5++; } - mean_prev_nc_fx_loc = L_add( es_mdct_fx[0], 0 ); /* compute mean not corrected by the actual gains*/ + mean_prev_nc_fx_loc = L_add( es_mdct_fx[0], 0 ); /* compute mean not corrected by the actual gains 2*(Q-1)*/ FOR( i = 1; i < NUMSF; i++ ) /* all present subbands */ { if ( EQ_16( i, NUMSF_S2 ) ) { - savehalfe_fx = L_add( mean_prev_nc_fx_loc, 0 ); + savehalfe_fx = L_add( mean_prev_nc_fx_loc, 0 ); /*2*(Q-1)*/ } #ifdef BASOP_NOGLOB - mean_prev_nc_fx_loc = L_add_sat( mean_prev_nc_fx_loc, es_mdct_fx[i] ); + mean_prev_nc_fx_loc = L_add_sat( mean_prev_nc_fx_loc, es_mdct_fx[i] ); /*2*(Q-1)*/ #else mean_prev_nc_fx_loc = L_add( mean_prev_nc_fx_loc, es_mdct_fx[i] ); #endif @@ -946,52 +947,52 @@ void preecho_sb_fx( if ( LT_32( savehalfe_fx, L_shr( mean_prev_nc_fx_loc, 1 ) ) ) { #ifdef BASOP_NOGLOB - mean_prev_nc_fx_loc = L_shl_sat( L_sub_sat( mean_prev_nc_fx_loc, savehalfe_fx ), 1 ); + mean_prev_nc_fx_loc = L_shl_sat( L_sub_sat( mean_prev_nc_fx_loc, savehalfe_fx ), 1 ); /*2*(Q-1)*/ #else mean_prev_nc_fx_loc = L_shl( L_sub( mean_prev_nc_fx_loc, savehalfe_fx ), 1 ); #endif } - mean_prev_nc_fx_loc = L_shr( mean_prev_nc_fx_loc, 3 ); /* >> LOG2_NUMSF in fixpoint */ + mean_prev_nc_fx_loc = L_shr( mean_prev_nc_fx_loc, 3 ); /* >> LOG2_NUMSF in fixpoint 2*(Q-1)*/ FOR( i = 0; i < ind2; i++ ) /* only subbands before max energy subband are handled*/ { - tmp_fx1 = mult_r( gt_fx[i], gt_fx[i] ); + tmp_fx1 = mult_r( gt_fx[i], gt_fx[i] ); /*Q15*/ Mpy_32_16_ss( es_mdct_fx[i], tmp_fx1, &es_mdct_fx[i], &tmp_u16 ); - tmp_fx1 = mult_r( gt_hb_fx[i], gt_hb_fx[i] ); + tmp_fx1 = mult_r( gt_hb_fx[i], gt_hb_fx[i] ); /*Q15*/ Mpy_32_16_ss( es_mdct_hb_fx[i], tmp_fx1, &es_mdct_hb_fx[i], &tmp_u16 ); } - mean_prev_fx_loc = L_shr( es_mdct_fx[0], 3 ); /* compute mean used in next frame to limit gain*/ - mean_prev_hb_fx_loc = L_shr( es_mdct_hb_fx[0], 3 ); /* compute mean used in next frame to limit gain*/ + mean_prev_fx_loc = L_shr( es_mdct_fx[0], 3 ); /* compute mean used in next frame to limit gain 2*(Q-1)*/ + mean_prev_hb_fx_loc = L_shr( es_mdct_hb_fx[0], 3 ); /* compute mean used in next frame to limit gain 2*(q_sig16)*/ FOR( i = 1; i < NUMSF; i++ ) /* all present subbands */ { IF( EQ_16( i, NUMSF_S2 ) ) { - savehalfe_fx = L_add( mean_prev_fx_loc, 0 ); - savehalfe_hb_fx = L_add( mean_prev_hb_fx_loc, 0 ); + savehalfe_fx = L_add( mean_prev_fx_loc, 0 ); /*2*(Q-1)*/ + savehalfe_hb_fx = L_add( mean_prev_hb_fx_loc, 0 ); /*2*(q_sig16)*/ } - mean_prev_fx_loc = L_add( mean_prev_fx_loc, L_shr( es_mdct_fx[i], 3 ) ); - mean_prev_hb_fx_loc = L_add( mean_prev_hb_fx_loc, L_shr( es_mdct_hb_fx[i], 3 ) ); + mean_prev_fx_loc = L_add( mean_prev_fx_loc, L_shr( es_mdct_fx[i], 3 ) ); /*2*(Q-1)*/ + mean_prev_hb_fx_loc = L_add( mean_prev_hb_fx_loc, L_shr( es_mdct_hb_fx[i], 3 ) ); /*2*(q_sig16)*/ } - tmp_fxL1 = L_sub( mean_prev_fx_loc, savehalfe_fx ); + tmp_fxL1 = L_sub( mean_prev_fx_loc, savehalfe_fx ); /*2*(Q-1)*/ if ( LT_32( savehalfe_fx, L_shr( mean_prev_fx_loc, 1 ) ) ) { - mean_prev_fx_loc = L_shl( tmp_fxL1, 1 ); + mean_prev_fx_loc = L_shl( tmp_fxL1, 1 ); /*2*(Q-1)*/ } - tmp_fxL1 = L_sub( mean_prev_hb_fx_loc, savehalfe_hb_fx ); + tmp_fxL1 = L_sub( mean_prev_hb_fx_loc, savehalfe_hb_fx ); /*2*(q_sig16)*/ if ( LT_32( savehalfe_hb_fx, L_shr( mean_prev_hb_fx_loc, 1 ) ) ) { - mean_prev_hb_fx_loc = L_shl( tmp_fxL1, 1 ); + mean_prev_hb_fx_loc = L_shl( tmp_fxL1, 1 ); /*2*(q_sig16)*/ } #ifdef BASOP_NOGLOB - last2_fx = L_shr( L_add_sat( es_mdct_fx[NUMSF_M1], es_mdct_fx[NUMSF_M2] ), 1 ); - last2_hb_fx = L_shr( L_add_sat( es_mdct_hb_fx[NUMSF_M1], es_mdct_hb_fx[NUMSF_M2] ), 1 ); + last2_fx = L_shr( L_add_sat( es_mdct_fx[NUMSF_M1], es_mdct_fx[NUMSF_M2] ), 1 ); /*q_sig16*/ + last2_hb_fx = L_shr( L_add_sat( es_mdct_hb_fx[NUMSF_M1], es_mdct_hb_fx[NUMSF_M2] ), 1 ); /*q_sig16*/ #else last2_fx = L_shr( L_add( es_mdct_fx[NUMSF_M1], es_mdct_fx[NUMSF_M2] ), 1 ); last2_hb_fx = L_shr( L_add( es_mdct_hb_fx[NUMSF_M1], es_mdct_hb_fx[NUMSF_M2] ), 1 ); @@ -1003,17 +1004,17 @@ void preecho_sb_fx( if ( GT_32( last2_hb_fx, mean_prev_hb_fx_loc ) ) { - mean_prev_hb_fx_loc = L_add( last2_hb_fx, 0 ); + mean_prev_hb_fx_loc = L_add( last2_hb_fx, 0 ); /*2*(q_sig16)*/ } - *mean_prev_fx = mean_prev_fx_loc; + *mean_prev_fx = mean_prev_fx_loc; /*2*(Q-1)*/ move32(); #ifdef BASOP_NOGLOB - *mean_prev_hb_fx = L_shr_sat( mean_prev_hb_fx_loc, shl_sat( q_sig16, 1 ) ); + *mean_prev_hb_fx = L_shr_sat( mean_prev_hb_fx_loc, shl_sat( q_sig16, 1 ) ); /*Q0*/ #else *mean_prev_hb_fx = L_shr( mean_prev_hb_fx_loc, shl( q_sig16, 1 ) ); #endif - move32(); /*save in Q0*/ - *mean_prev_nc_fx = mean_prev_nc_fx_loc; + move32(); /*save in Q0*/ + *mean_prev_nc_fx = mean_prev_nc_fx_loc; /*2*(Q-1)*/ move32(); } @@ -1027,13 +1028,13 @@ void preecho_sb_fx( *--------------------------------------------------------------------------*/ void Inverse_Transform( - const Word32 *in_mdct, /* i : input MDCT vector */ + const Word32 *in_mdct, /* i : input MDCT vector Q */ Word16 *Q, /* i/o: Q value of input */ - Word32 *out, /* o : output vector */ - const Word16 is_transient, /* i : transient flag */ - const Word16 L, /* i : output frame length */ - const Word16 L_inner, /* i : length of the transform */ - const Word16 element_mode /* i : IVAS element mode */ + Word32 *out, /* o : output vector Q */ + const Word16 is_transient, /* i : transient flag Q0 */ + const Word16 L, /* i : output frame length Q0 */ + const Word16 L_inner, /* i : length of the transform Q0 */ + const Word16 element_mode /* i : IVAS element mode Q0 */ ) { Word16 ta, seg, tmp16; @@ -1064,30 +1065,30 @@ void Inverse_Transform( IF( EQ_16( L, L_FRAME48k ) ) { - win = short_window_48kHz_fx; + win = short_window_48kHz_fx; /*Q15*/ } ELSE IF( EQ_16( L, L_FRAME32k ) ) { - win = short_window_32kHz_fx; + win = short_window_32kHz_fx; /*Q15*/ } ELSE IF( EQ_16( L, L_FRAME16k ) ) { - win = short_window_16kHz_fx; + win = short_window_16kHz_fx; /*Q15*/ } ELSE /* L == L_FRAME8k */ { - win = short_window_8kHz_fx; + win = short_window_8kHz_fx; /*Q15*/ } set32_fx( out_alias, 0, L ); - in_segment = in_mdct; + in_segment = in_mdct; /*Q*/ in_segment_modif = in_mdct_modif; tmp16 = sub( L, L_inner ); IF( tmp16 == 0 ) { - Copy32( in_mdct, in_mdct_modif, L ); + Copy32( in_mdct, in_mdct_modif, L ); /*Q*/ } ELSE IF( tmp16 > 0 ) { @@ -1095,7 +1096,7 @@ void Inverse_Transform( { FOR( ta = 0; ta < L_inner; ta += NUM_TIME_SWITCHING_BLOCKS ) { - *in_segment_modif++ = *in_segment++; + *in_segment_modif++ = *in_segment++; /*Q*/ move32(); } @@ -1112,16 +1113,16 @@ void Inverse_Transform( { FOR( ta = 0; ta < segment_length_div2; ta++ ) { - *in_segment_modif++ = *in_segment++; + *in_segment_modif++ = *in_segment++; /*Q*/ move32(); } - in_segment += shr( sub( L_inner, L ), 2 ); + in_segment += shr( sub( L_inner, L ), 2 ); /*Q*/ move32(); } } out_segment = out_alias - segment_length_div4; - in_segment = in_mdct_modif; + in_segment = in_mdct_modif; /*Q*/ tmp = *Q; /* output of 'iedct_short_fx' has up to 'output frame length'/2 # of Elements */ @@ -1139,21 +1140,21 @@ void Inverse_Transform( FOR( ta = segment_length_div4; ta < segment_length_div2; ta++ ) { - out_segment[ta] = L_shr( alias[ta], tmp ); + out_segment[ta] = L_shr( alias[ta], tmp ); /*q_out*/ move32(); } /* This previous loop fills the output buffer from [0..seg_len_div4-1] */ - win2 = &win[segment_length_div2]; + win2 = &win[segment_length_div2]; /*Q15*/ FOR( ta = segment_length_div2; ta < segment_length; ta++ ) { - out_segment[ta] = L_shr( Mult_32_16( alias[ta], *--win2 ), tmp ); + out_segment[ta] = L_shr( Mult_32_16( alias[ta], *--win2 ), tmp ); /*q_out*/ move32(); } /* This previous loop fills the output buffer from [seg_len_div4..seg_len-seg_len_div4-1] */ - out_segment += segment_length_div2; - in_segment += segment_length_div2; + out_segment += segment_length_div2; /*q_out*/ + in_segment += segment_length_div2; /*Q*/ FOR( seg = 1; seg < NUM_TIME_SWITCHING_BLOCKS - 1; seg++ ) { @@ -1165,17 +1166,17 @@ void Inverse_Transform( FOR( ta = 0; ta < segment_length_div2; ta++ ) { - out_segment[ta] = L_add( out_segment[ta], L_shr( Mult_32_16( alias[ta], *win2++ ), tmp ) ); + out_segment[ta] = L_add( out_segment[ta], L_shr( Mult_32_16( alias[ta], *win2++ ), tmp ) ); /*q_out*/ move32(); } FOR( ; ta < segment_length; ta++ ) { - out_segment[ta] = L_add( out_segment[ta], L_shr( Mult_32_16( alias[ta], *--win2 ), tmp ) ); + out_segment[ta] = L_add( out_segment[ta], L_shr( Mult_32_16( alias[ta], *--win2 ), tmp ) ); /*q_out*/ move32(); } - in_segment += segment_length_div2; - out_segment += segment_length_div2; + in_segment += segment_length_div2; /*Q*/ + out_segment += segment_length_div2; /*q_out*/ } tmp = *Q; @@ -1185,23 +1186,23 @@ void Inverse_Transform( FOR( ta = 0; ta < segment_length_div2; ta++ ) { - out_segment[ta] = L_add( out_segment[ta], L_shr( Mult_32_16( alias[ta], *win2++ ), tmp ) ); + out_segment[ta] = L_add( out_segment[ta], L_shr( Mult_32_16( alias[ta], *win2++ ), tmp ) ); /*q_out*/ move32(); } - seg = add( segment_length_div2, shr( segment_length_div2, 1 ) ); /* seg = 3*segment_length/4 */ + seg = add( segment_length_div2, shr( segment_length_div2, 1 ) ); /* seg = 3*segment_length/4 Q0*/ FOR( ta = segment_length_div2; ta < seg; ta++ ) { - out_segment[ta] = L_shr( alias[ta], tmp ); + out_segment[ta] = L_shr( alias[ta], tmp ); /*q_out*/ move32(); } FOR( ta = 0; ta < segment_length; ta++ ) { L_temp = L_add( out_alias[ta], 0 ); - out[ta] = out_alias[L - 1 - ta]; + out[ta] = out_alias[L - 1 - ta]; /*q_out*/ move32(); - out[L - 1 - ta] = L_temp; + out[L - 1 - ta] = L_temp; /*q_out*/ move32(); } diff --git a/lib_enc/acelp_core_enc.c b/lib_enc/acelp_core_enc.c index e5d162502..45e429430 100644 --- a/lib_enc/acelp_core_enc.c +++ b/lib_enc/acelp_core_enc.c @@ -543,37 +543,43 @@ ivas_error acelp_core_enc( } else { - if ( st->core_brate == SID_2k40 && st->element_mode != IVAS_CPE_MDCT ) + IF( EQ_32( st->core_brate, SID_2k40 ) && NE_16( st->element_mode, IVAS_CPE_MDCT ) ) { FdCng_encodeSID_ivas_fx( st ); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - me2f_buf( st->hFdCngEnc->hFdCngCom->sidNoiseEst, st->hFdCngEnc->hFdCngCom->sidNoiseEstExp, st->hFdCngEnc->hFdCngCom->sidNoiseEst_flt, st->hFdCngEnc->npartDec ); - me2f_buf( st->hFdCngEnc->hFdCngCom->cngNoiseLevel, st->hFdCngEnc->hFdCngCom->cngNoiseLevelExp, st->hFdCngEnc->hFdCngCom->cngNoiseLevel_flt, FFTCLDFBLEN ); - fixedToFloat_arr( st->hFdCngEnc->hFdCngCom->A_cng, st->hFdCngEnc->hFdCngCom->A_cng_flt, 14 - norm_s( st->hFdCngEnc->hFdCngCom->A_cng[0] ), M + 1 ); -#endif st->hDtxEnc->last_CNG_L_frame = st->L_frame; + move16(); } + Word16 Q_cngNoise = Q31, zero_flag = 0; + move16(); + move16(); + FOR( Word16 j = 0; j < NPART; j++ ) + { + IF( st->hFdCngEnc->hFdCngCom->cngNoiseLevel[j] != 0 ) + { + zero_flag = 1; + move16(); + BREAK; + } + } + IF( zero_flag ) + { + Q_cngNoise = getScaleFactor32( st->hFdCngEnc->hFdCngCom->cngNoiseLevel, NPART ); + } + Scale_sig32( st->hFdCngEnc->hFdCngCom->cngNoiseLevel, NPART, Q_cngNoise ); + st->hFdCngEnc->hFdCngCom->cngNoiseLevelExp = sub( st->hFdCngEnc->hFdCngCom->cngNoiseLevelExp, Q_cngNoise ); + move16(); + #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - Word16 Q_cngNoise = Q_factor_arrL( st->hFdCngEnc->hFdCngCom->cngNoiseLevel_flt, FFTCLDFBLEN ); - floatToFixed_arrL( st->hFdCngEnc->hFdCngCom->cngNoiseLevel_flt, st->hFdCngEnc->hFdCngCom->cngNoiseLevel, Q_cngNoise, FFTCLDFBLEN ); - st->hFdCngEnc->hFdCngCom->cngNoiseLevelExp = sub( 31, Q_cngNoise ); st->preemph_fac = float_to_fix16( st->preemph_fac_flt, Q15 ); #endif - // generate_comfort_noise_enc( st ); generate_comfort_noise_enc_ivas_fx( st, Q_new, 1 ); #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - fixedToFloat_arr( st->hFdCngEnc->hFdCngCom->exc_cng, st->hFdCngEnc->hFdCngCom->exc_cng_flt, Q_new, st->L_frame ); - fixedToFloat_arr( st->hFdCngEnc->hFdCngCom->olapBufferSynth, st->hFdCngEnc->hFdCngCom->olapBufferSynth_flt, st->hFdCngEnc->hFdCngCom->fftlenShift, FFTLEN ); - fixedToFloat_arr( st->hFdCngEnc->hFdCngCom->timeDomainBuffer, st->hFdCngEnc->hFdCngCom->timeDomainBuffer_flt, Q_new, st->hFdCngEnc->hFdCngCom->frameSize ); fixedToFloat_arr( st->hTcxEnc->Txnq, st->hTcxEnc->Txnq_flt, Q_new, ( L_FRAME32k / 2 + 64 ) ); #endif -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - floatToFixed_arr( st->hFdCngEnc->hFdCngCom->A_cng_flt, st->hFdCngEnc->hFdCngCom->A_cng, Q12, ( M + 1 ) ); - floatToFixed_arr( st->hFdCngEnc->hFdCngCom->exc_cng_flt, st->hFdCngEnc->hFdCngCom->exc_cng, Q_new, st->L_frame ); -#endif + Scale_sig( st->hFdCngEnc->hFdCngCom->A_cng, ( M + 1 ), sub( Q12, sub( 14, norm_s( st->hFdCngEnc->hFdCngCom->A_cng[0] ) ) ) ); FdCng_exc( st->hFdCngEnc->hFdCngCom, &st->hDtxEnc->CNG_mode, st->L_frame, st->lsp_old_fx, st->hDtxEnc->first_CNG, st->hDtxEnc->lspCNG_fx, Aq_fx, lsp_new_fx, lsf_new_fx, exc_fx, exc2_fx, bwe_exc_fx ); #ifdef IVAS_FLOAT_FIXED_CONVERSIONS fixedToFloat_arr( Aq_fx, Aq, Q12, ( st->L_frame / L_SUBFR ) * ( M + 1 ) ); @@ -716,17 +722,10 @@ ivas_error acelp_core_enc( st->mem_deemp_preQ_fx = (Word16) floatToFixed( st->mem_deemp_preQ, -1 ); IF( st->hLPDmem ) { - st->hLPDmem->tilt_code = float_to_fix16( st->hLPDmem->tilt_code_flt, Q15 ); floatToFixed_arr( &st->hLPDmem->mem_syn_flt[-1], &st->hLPDmem->mem_syn[-1], Q_new - 1, M + 1 ); // -1 to sync the exponent of mem_syn with mem_w0 } floatToFixed_arr( lsp_new, lsp_new_fx, Q15, M ); floatToFixed_arr( lsp_mid, lsp_mid_fx, Q15, M ); - st->clip_var_fx[0] = (Word16) ( st->clip_var[0] * 2.56f ); - st->clip_var_fx[1] = float_to_fix16( st->clip_var[1], Q14 ); - st->clip_var_fx[2] = float_to_fix16( st->clip_var[2], Q8 ); - st->clip_var_fx[3] = float_to_fix16( st->clip_var[3], 0 ); - st->clip_var_fx[4] = float_to_fix16( st->clip_var[4], Q14 ); - st->clip_var_fx[5] = float_to_fix16( st->clip_var[5], Q14 ); FOR( Word16 idx = 0; idx < M; idx++ ) { IF( tdm_lsfQ_PCh ) @@ -750,9 +749,6 @@ ivas_error acelp_core_enc( st->hGSCEnc->Last_frame_ener_fx = floatToFixed_32( st->hGSCEnc->Last_frame_ener, Q4 ); f2me_buf_16( st->hGSCEnc->last_exc_dct_in, st->hGSCEnc->last_exc_dct_in_fx, &st->hGSCEnc->Q_last_exc_dct_in, L_FRAME16k ); st->hGSCEnc->Q_last_exc_dct_in = Q15 - st->hGSCEnc->Q_last_exc_dct_in; - st->hGSCEnc->last_ener_fx = (Word16) st->hGSCEnc->last_ener; - IF( st->hLPDmem ) - st->hLPDmem->tilt_code = float_to_fix16( st->hLPDmem->tilt_code_flt, Q15 ); #endif /*-----------------------------------------------------------------* * Configure ACELP bit allocation @@ -1001,13 +997,6 @@ ivas_error acelp_core_enc( #ifdef IVAS_FLOAT_FIXED_CONVERSIONS st->mem_deemp_preQ = fixedToFloat( st->mem_deemp_preQ_fx, -1 ); - st->clip_var[0] = (float) st->clip_var_fx[0] / 2.56f; - st->clip_var[1] = fix16_to_float( st->clip_var_fx[1], Q14 ); - st->clip_var[2] = fix16_to_float( st->clip_var_fx[2], Q8 ); - st->clip_var[3] = fix16_to_float( st->clip_var_fx[3], 0 ); - st->clip_var[4] = fix16_to_float( st->clip_var_fx[4], Q14 ); - st->clip_var[5] = fix16_to_float( st->clip_var_fx[5], Q14 ); - fixedToFloat_arr( lsp_new_bck_fx, lsp_new_bck, Q15, M ); fixedToFloat_arr( lsp_mid_bck_fx, lsp_mid_bck, Q15, M ); fixedToFloat_arr( mem_syn_bck_fx, mem_syn_bck, Q_new, M ); @@ -1044,7 +1033,6 @@ ivas_error acelp_core_enc( fixedToFloat_arr( syn_fx, syn, Q_new - 1, L_FRAME16k ); fixedToFloat_arr( voice_factors_fx, voice_factors, Q15, NB_SUBFR16k ); fixedToFloat_arr( pitch_buf_fx, pitch_buf, Q6, NB_SUBFR16k ); - st->hLPDmem->tilt_code_flt = fix16_to_float( st->hLPDmem->tilt_code, Q15 ); #endif /* update mem_syn1_flt for ACELP core switching */ @@ -1279,11 +1267,6 @@ ivas_error acelp_core_enc( floatToFixed_arr16( &old_bwe_exc[L_FRAME32k], &old_bwe_exc_fx[L_FRAME32k], q_old_bwe_exc, PIT16k_MAX * 2 ); st->Q_exc = q_old_bwe_exc; } - - IF( st->hGSCEnc != NULL ) - { - st->hGSCEnc->mid_dyn_fx = float_to_fix16( st->hGSCEnc->mid_dyn, Q7 ); - } #endif // IVAS_FLOAT_FIXED_CONVERSIONS updt_enc_fx( st, old_exc_fx, pitch_buf_fx, Es_pred_fx, Aq_fx, lsf_new_fx, lsp_new_fx, old_bwe_exc_fx ); @@ -1294,7 +1277,6 @@ ivas_error acelp_core_enc( { fixedToFloat_arr( st->hBWE_TD->old_bwe_exc_fx, st->hBWE_TD->old_bwe_exc, q_old_bwe_exc, PIT16k_MAX * 2 ); } - st->hGSCEnc->mid_dyn = fixedToFloat( st->hGSCEnc->mid_dyn_fx, Q7 ); fixedToFloat_arr( st->old_Aq_12_8_fx, st->old_Aq_12_8, Q12, M + 1 ); // Q12 #endif #else diff --git a/lib_enc/acelp_enc_util_fx.c b/lib_enc/acelp_enc_util_fx.c index f7f1d45b6..8fb741297 100644 --- a/lib_enc/acelp_enc_util_fx.c +++ b/lib_enc/acelp_enc_util_fx.c @@ -224,6 +224,7 @@ void E_ACELP_conv_ivas( #else cn2[k] = round_fx( L_shl( L_tmp, 5 ) ); #endif + move16(); } } void E_ACELP_build_code( diff --git a/lib_enc/avq_cod_fx.c b/lib_enc/avq_cod_fx.c index c303d9ea5..094d3fd78 100644 --- a/lib_enc/avq_cod_fx.c +++ b/lib_enc/avq_cod_fx.c @@ -949,16 +949,9 @@ void AVQ_encmux_ivas_fx( } /*Compute AVQ code book number from unused Bits */ - // bit_tmp = add( unusedbitsFlag, unused_bits_idx ); + bit_tmp = add( unusedbitsFlag, unused_bits_idx ); /*nq_est = (int16_t)ceil(0.2f * (bits - 5 * (unusedbitsFlag + unused_bits_idx)));*/ - // nq_est = mult( 6554, sub( bits, add( shl( bit_tmp, 2 ), bit_tmp ) ) ); - bit_tmp = sub( bits, imult1616( 5, add( unusedbitsFlag, unused_bits_idx ) ) ); - nq_est = 0; - WHILE( bit_tmp > 0 ) - { - nq_est = add( nq_est, 1 ); - bit_tmp = sub( bit_tmp, 5 ); - } + nq_est = mult( 6554, sub( bits, add( shl( bit_tmp, 2 ), bit_tmp ) ) ); assert( (int16_t) ceil( 0.2f * ( bits - 5 * ( unusedbitsFlag + unused_bits_idx ) ) ) == nq_est ); if ( EQ_16( nq_est, 1 ) ) diff --git a/lib_enc/cod2t32_fx.c b/lib_enc/cod2t32_fx.c index 04105f232..d93398997 100644 --- a/lib_enc/cod2t32_fx.c +++ b/lib_enc/cod2t32_fx.c @@ -363,6 +363,7 @@ void acelp_2t32_ivas_fx( Word16 rrixiy[MSIZE]; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif /*----------------------------------------------------------------* * Compute rrixix[][] needed for the codebook search. @@ -749,12 +750,12 @@ void acelp_1t64_ivas_fx( IF( dn[pos] < 0 ) { - sgn = -512; + sgn = -512; //-1 in Q9 move16(); } ELSE { - sgn = 512; + sgn = 512; // 1 in Q9 move16(); } diff --git a/lib_enc/core_enc_init.c b/lib_enc/core_enc_init.c index b4837eecc..ef2e5408b 100644 --- a/lib_enc/core_enc_init.c +++ b/lib_enc/core_enc_init.c @@ -1258,7 +1258,11 @@ static void init_acelp( st->rate_switching_reset = 1; if ( hLPDmem != NULL ) { +#ifndef IVAS_FLOAT_FIXED hLPDmem->tilt_code_flt = TILT_CODE_FLT; +#else + hLPDmem->tilt_code = TILT_CODE; +#endif set_zero( hLPDmem->old_exc_flt, L_EXC_MEM ); set_zero( hLPDmem->syn_flt, 1 + M ); hLPDmem->mem_w0_flt = 0.0f; @@ -1387,7 +1391,11 @@ static void init_acelp( /*reset partly some memories*/ if ( hLPDmem != NULL ) { +#ifndef IVAS_FLOAT_FIXED hLPDmem->tilt_code_flt = TILT_CODE_FLT; +#else + hLPDmem->tilt_code = TILT_CODE; +#endif set_zero( hLPDmem->old_exc_flt, L_EXC_MEM ); /*Resamp others memories*/ @@ -1449,10 +1457,20 @@ static void init_acelp( /* Post-processing */ if ( hLPDmem != NULL ) { - set_zero( hLPDmem->dispMem_flt, 8 ); #ifndef IVAS_FLOAT_FIXED + set_zero( hLPDmem->dispMem_flt, 8 ); hLPDmem->gc_threshold_flt = 0.0f; #else + hLPDmem->dm_fx.prev_state = 0; + move16(); /* This corresponds to st_fx->dispMem in FLP */ + hLPDmem->dm_fx.prev_gain_code = 0; + move32(); + + FOR( Word16 i = 2; i < 8; i++ ) + { + hLPDmem->dm_fx.prev_gain_pit[i - 2] = 0; + move16(); + } hLPDmem->gc_threshold = 0; #endif } @@ -1739,7 +1757,16 @@ static void init_acelp_ivas_fx( Encoder_State *st, Word16 L_frame_old, Word16 sh if ( hLPDmem != NULL ) { - set32_fx( hLPDmem->dispMem, 0, 8 ); + hLPDmem->dm_fx.prev_state = 0; + move16(); /* This corresponds to st_fx->dispMem in FLP */ + hLPDmem->dm_fx.prev_gain_code = 0; + move32(); + + FOR( Word16 i = 2; i < 8; i++ ) + { + hLPDmem->dm_fx.prev_gain_pit[i - 2] = 0; + move16(); + } hLPDmem->gc_threshold = 0; move16(); } diff --git a/lib_enc/core_enc_switch.c b/lib_enc/core_enc_switch.c index 0a90b3648..9e6ffbcf4 100644 --- a/lib_enc/core_enc_switch.c +++ b/lib_enc/core_enc_switch.c @@ -129,9 +129,6 @@ void core_coder_mode_switch_ivas_fx( /* switch IGF configuration */ IF( st->igf ) { -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - IGFEncSetMode( st->hIGFEnc, st->total_brate, st->bwidth, st->element_mode, st->rf_mode ); -#endif IGFEncSetMode_fx( st->hIGFEnc, st->total_brate, st->bwidth, st->element_mode, st->rf_mode ); } st->hTcxCfg->tcx_coded_lines = getNumTcxCodedLines( st->bwidth ); diff --git a/lib_enc/core_switching_enc.c b/lib_enc/core_switching_enc.c index 142248112..5bbd80968 100644 --- a/lib_enc/core_switching_enc.c +++ b/lib_enc/core_switching_enc.c @@ -229,24 +229,36 @@ void core_switching_pre_enc( set_f( hLPDmem->mem_syn_flt, 0.0f, M ); set_f( hLPDmem->mem_syn1_flt, 0.0f, M ); hLPDmem->mem_w0_flt = 0.0f; - hLPDmem->tilt_code_flt = 0.0f; #ifndef IVAS_FLOAT_FIXED + hLPDmem->tilt_code_flt = 0.0f; hLPDmem->gc_threshold_flt = 0.0f; + set_f( hLPDmem->dispMem_flt, 0, 8 ); #else + hLPDmem->tilt_code = 0; hLPDmem->gc_threshold = 0; + hLPDmem->dm_fx.prev_state = 0; + move16(); /* This corresponds to st_fx->dispMem in FLP */ + hLPDmem->dm_fx.prev_gain_code = 0; + move32(); + + FOR( Word16 i = 2; i < 8; i++ ) + { + hLPDmem->dm_fx.prev_gain_pit[i - 2] = 0; + move16(); + } #endif - set_f( hLPDmem->dispMem_flt, 0, 8 ); } st->Nb_ACELP_frames = 0; #ifndef IVAS_FLOAT_FIXED set_zero( st->mem_MA, M ); mvr2r( GEWB_Ave, st->mem_AR, M ); + init_gp_clip( st->clip_var ); #else set16_fx( st->mem_MA_fx, 0, M ); Copy( GEWB_Ave_fx, st->mem_AR_fx, M ); + init_gp_clip_fx( st->clip_var_fx ); #endif - init_gp_clip( st->clip_var ); st->last_coder_type = GENERIC; @@ -290,14 +302,29 @@ void core_switching_pre_enc( if ( hLPDmem != NULL ) { hLPDmem->mem_w0_flt = 0.0f; +#ifndef IVAS_FLOAT_FIXED hLPDmem->tilt_code_flt = 0.0f; - init_gp_clip( st->clip_var ); +#else + hLPDmem->tilt_code = 0; +#endif #ifndef IVAS_FLOAT_FIXED + init_gp_clip( st->clip_var ); hLPDmem->gc_threshold_flt = 0.0f; + set_f( hLPDmem->dispMem_flt, 0, 8 ); #else + init_gp_clip_fx( st->clip_var_fx ); hLPDmem->gc_threshold = 0; + hLPDmem->dm_fx.prev_state = 0; + move16(); /* This corresponds to st_fx->dispMem in FLP */ + hLPDmem->dm_fx.prev_gain_code = 0; + move32(); + + FOR( Word16 i = 2; i < 8; i++ ) + { + hLPDmem->dm_fx.prev_gain_pit[i - 2] = 0; + move16(); + } #endif - set_f( hLPDmem->dispMem_flt, 0, 8 ); } st->last_coder_type = GENERIC; @@ -867,15 +894,7 @@ void core_switching_post_enc( floatToFixed_arr( old_inp_12k8, old_inp_12k8_fx, Q_new, L_INP_12k8 ); floatToFixed_arr( old_inp_16k, old_inp_16k_fx, Q_new, L_INP ); floatToFixed_arr( A, A_fx, 12, NB_SUBFR16k * ( M + 1 ) ); - float temp = (float) st->clip_var[0] * ( 2.56f ); - st->clip_var_fx[0] = float_to_fix16( temp, 0 ); - st->clip_var_fx[1] = float_to_fix16( st->clip_var[1], 14 ); - st->clip_var_fx[2] = float_to_fix16( st->clip_var[2], 8 ); - st->clip_var_fx[3] = float_to_fix16( st->clip_var[3], 0 ); - st->clip_var_fx[4] = float_to_fix16( st->clip_var[4], 14 ); - st->clip_var_fx[5] = float_to_fix16( st->clip_var[5], 14 ); floatToFixed_arr( st->voicing, st->voicing_fx, 15, 3 ); - st->hLPDmem->tilt_code = float_to_fix16( st->hLPDmem->tilt_code_flt, 15 ); floatToFixed_arr( st->old_Aq_12_8, st->old_Aq_12_8_fx, 12, M + 1 ); st->hLPDmem->mem_w0 = float_to_fix16( st->hLPDmem->mem_w0_flt, Q_new - 1 ); floatToFixed_arr( st->hLPDmem->mem_syn_flt, st->hLPDmem->mem_syn, Q_new - 1, M ); @@ -885,14 +904,6 @@ void core_switching_post_enc( #ifdef IVAS_FLOAT_FIXED_CONVERSIONS // conv params from fix to float fixedToFloat_arr( st->old_input_signal_fx, st->old_input_signal, 0, L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ) ); - temp = (float) fix16_to_float( st->clip_var_fx[0], 0 ) / 2.56f; - st->clip_var[0] = temp; - st->clip_var[1] = fix16_to_float( st->clip_var_fx[1], 14 ); - st->clip_var[2] = fix16_to_float( st->clip_var_fx[2], 8 ); - st->clip_var[3] = fix16_to_float( st->clip_var_fx[3], 0 ); - st->clip_var[4] = fix16_to_float( st->clip_var_fx[4], 14 ); - st->clip_var[5] = fix16_to_float( st->clip_var_fx[5], 14 ); - st->hLPDmem->tilt_code = float_to_fix16( st->hLPDmem->tilt_code_flt, 15 ); st->hLPDmem->mem_w0_flt = fix16_to_float( st->hLPDmem->mem_w0, Q_new - 1 ); #endif #endif diff --git a/lib_enc/corr_xh_fx.c b/lib_enc/corr_xh_fx.c index 92b3c7eba..5c209460d 100644 --- a/lib_enc/corr_xh_fx.c +++ b/lib_enc/corr_xh_fx.c @@ -33,6 +33,7 @@ void corr_xh_fx( Word32 L_tmp, y32[L_SUBFR], L_maxloc, L_tot; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move16(); #endif /* first keep the result on 32 bits and find absolute maximum */ @@ -81,34 +82,6 @@ void corr_xh_fx( return; } -void corr_xh_ivas_fx( - const Word16 *x, /* i : target signal Q_new - 1 */ - Word16 *y, /* o : correlation between x[] and h[] Q_new + 1 */ - const Word16 *h, /* i : impulse response (of weighted synthesis filter) e(norm_s(h1[0])+1) */ - const Word16 L_subfr /* i : length of the subframe */ -) -{ - Word16 i, j, scale; - Word64 s64; - - Word16 shift = add( norm_s( h[0] ), 1 ); - scale = sub( sub( 15, shift ), 2 ); - FOR( i = 0; i < L_subfr; i++ ) - { - s64 = 0; - move16(); - FOR( j = i; j < L_subfr; j++ ) - { - s64 = W_mac0_16_16( s64, x[j], h[j - i] ); // Q_new - 1 + 15 - shift - } - - y[i] = extract_l( W_extract_l( W_shr( s64, scale ) ) ); // Q_new + 1 - move16(); - } - - return; -} - void corr_hh_ivas_fx( const Word16 *h, /* i : target signal e(norm_s(h1[0])+1) */ Word16 *y, /* o : correlation between x[] and h[] Q_new + 1 */ @@ -120,6 +93,7 @@ void corr_hh_ivas_fx( Word32 L_tmp, y32[L_SUBFR * 2], L_maxloc, L_tot; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move16(); #endif /* first keep the result on 32 bits and find absolute maximum */ @@ -164,13 +138,15 @@ void corr_hh_ivas_fx( FOR( i = 0; i < L_subfr; i++ ) { y[i] = round_fx( L_shl( y32[i], j ) ); // 2*(15 - norm_s(h[0])) - 1 +j - 16 + move16(); } *Qy = sub( add( shl( sub( 15, norm_s( h[0] ) ), 1 ), j ), 17 ); + move16(); return; } -void corr_xh_ivas_fx2( +void corr_xh_ivas_fx( const Word16 x[], /* i : target signal */ const Word16 Qx, Word16 dn[], /* o : correlation between x[] and h[] */ @@ -183,6 +159,7 @@ void corr_xh_ivas_fx2( Word32 L_tmp, y32[L_SUBFR * 2], L_maxloc, L_tot; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move16(); #endif /* first keep the result on 32 bits and find absolute maximum */ @@ -227,8 +204,10 @@ void corr_xh_ivas_fx2( FOR( i = 0; i < L_subfr; i++ ) { dn[i] = round_fx( L_shl( y32[i], j ) ); // Qx+(15 - norm_s(h[0])) +j - 16 + move16(); } *Qdn = sub( add( add( Qx, sub( 15, norm_s( h[0] ) ) ), j ), 16 ); + move16(); return; } diff --git a/lib_enc/enc_acelpx_fx.c b/lib_enc/enc_acelpx_fx.c index 43df35a55..ae445a35b 100644 --- a/lib_enc/enc_acelpx_fx.c +++ b/lib_enc/enc_acelpx_fx.c @@ -647,15 +647,18 @@ void E_ACELP_4tsearchx_ivas_fx( Word16 nb_pulse, nb_pulse_m2; Word16 psk; Word16 val, index, track; + move16(); + move16(); psk = ps = 0; /* to avoid compilation warnings */ + move16(); + move16(); alp = config->alp; /* Q13 */ move16(); nb_pulse = config->nb_pulse; move16(); - move16(); nb_pulse_m2 = sub( nb_pulse, 2 ); /* Init to avoid crash when the search does not find a solution */ @@ -872,11 +875,14 @@ void E_ACELP_4tsearchx_ivas_fx( IF( L_mult0( val, psk ) > 0 ) { code[i] = add( code[i], ONE_IN_Q9 /*1.0f*/ ); + move16(); codvec[k] = add( codvec[k], 2 * L_SUBFR ); + move16(); } ELSE { code[i] = sub( code[i], ONE_IN_Q9 /*1.0f*/ ); + move16(); index = add( index, 16 ); } diff --git a/lib_enc/enc_gen_voic.c b/lib_enc/enc_gen_voic.c index 99c500a73..7339c7e7c 100644 --- a/lib_enc/enc_gen_voic.c +++ b/lib_enc/enc_gen_voic.c @@ -41,6 +41,7 @@ #include "rom_com.h" #include "wmc_auto.h" +#ifndef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* * encod_gen_voic() * @@ -322,3 +323,4 @@ void encod_gen_voic( return; } +#endif diff --git a/lib_enc/enc_pit_exc.c b/lib_enc/enc_pit_exc.c index e419e092f..791f5c59c 100644 --- a/lib_enc/enc_pit_exc.c +++ b/lib_enc/enc_pit_exc.c @@ -41,6 +41,7 @@ #include "prot.h" #include "wmc_auto.h" +#ifndef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* * enc_pit_exc() * @@ -412,3 +413,4 @@ void enc_pit_exc( return; } +#endif diff --git a/lib_enc/enc_pit_exc_fx.c b/lib_enc/enc_pit_exc_fx.c index 03b02fe96..f9f50bb65 100644 --- a/lib_enc/enc_pit_exc_fx.c +++ b/lib_enc/enc_pit_exc_fx.c @@ -910,11 +910,11 @@ void enc_pit_exc_ivas_fx( } ELSE { - Ltmp = L_mult( xn[L_subfr - 1], 16384 ); + Ltmp = L_mult( xn[L_subfr - 1], 16384 ); // Q_new-1+15+shift #ifdef BASOP_NOGLOB - Ltmp = L_msu_sat( Ltmp, y1[L_subfr - 1], gain_pit ); - Ltmp = L_shl_sat( Ltmp, sub( 1, shift ) ); - hLPDmem->mem_w0 = round_fx_sat( Ltmp ); /*Q_new-1 */ + Ltmp = L_msu_sat( Ltmp, y1[L_subfr - 1], gain_pit ); // Q_new-1+15+shift + Ltmp = L_shl_sat( Ltmp, sub( 1, shift ) ); // Q_new+15 + hLPDmem->mem_w0 = round_fx_sat( Ltmp ); /*Q_new-1 */ #else Ltmp = L_msu( Ltmp, y1[L_subfr - 1], gain_pit ); Ltmp = L_shl( Ltmp, sub( 1, shift ) ); diff --git a/lib_enc/enc_tran.c b/lib_enc/enc_tran.c index 08e9d5c7f..206227c2f 100644 --- a/lib_enc/enc_tran.c +++ b/lib_enc/enc_tran.c @@ -40,6 +40,7 @@ #include "rom_com.h" #include "wmc_auto.h" +#ifndef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* * encod_tran() * @@ -340,3 +341,4 @@ int16_t encod_tran( return tc_subfr; } +#endif diff --git a/lib_enc/enc_uv.c b/lib_enc/enc_uv.c index c45c84f1d..8e080956d 100644 --- a/lib_enc/enc_uv.c +++ b/lib_enc/enc_uv.c @@ -42,6 +42,7 @@ #include "prot.h" #include "wmc_auto.h" +#ifndef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* * encod_unvoiced() * @@ -238,3 +239,4 @@ void encod_unvoiced( return; } +#endif diff --git a/lib_enc/enc_uv_fx.c b/lib_enc/enc_uv_fx.c index f87220008..7708c0e1c 100644 --- a/lib_enc/enc_uv_fx.c +++ b/lib_enc/enc_uv_fx.c @@ -331,7 +331,6 @@ void encod_unvoiced_ivas_fx( p_Aw_fx = Aw_fx; p_Aq_fx = Aq_fx; pt_pitch_fx = pitch_buf_fx; - move16(); Q_xn = add( sub( Q_new, 1 ), shift ); Q_new_p5 = add( Q_new, 5 ); @@ -353,7 +352,7 @@ void encod_unvoiced_ivas_fx( Scale_sig( h1_fx, L_SUBFR, add( 1, shift ) ); /* set h1[] in Q14 with scaling for convolution */ /* scaling of xn[] to limit dynamic at 12 bits */ - Scale_sig( xn_fx, L_SUBFR, shift ); + Scale_sig( xn_fx, L_SUBFR, shift ); // Q_new - 1 + shift /*----------------------------------------------------------------* * Unvoiced subframe processing *----------------------------------------------------------------*/ @@ -362,6 +361,7 @@ void encod_unvoiced_ivas_fx( *pt_pitch_fx = gaus_encode_ivas_fx( st_fx, i_subfr, h1_fx, xn_fx, exc_fx, &hLPDmem->mem_w0, st_fx->clip_var_fx, &hLPDmem->tilt_code, code_fx, &L_gain_code_fx, y2_fx, &gain_inov_fx, &voice_fac_fx, &gain_pit_fx, Q_new, shift, &norm_gain_code_fx ); + move16(); } ELSE { @@ -387,7 +387,7 @@ void encod_unvoiced_ivas_fx( * Encode the algebraic innovation * *----------------------------------------------------------------------*/ - // E_ACELP_innovative_codebook_ivas_fx( exc_fx, *pt_pitch_fx, 0, 1, gain_pit_fx, hLPDmem->tilt_code, acelp_cfg, i_subfr, p_Aq_fx, h1_fx, xn_fx, cn_fx, y1, y2_fx, (Word8) st_fx->acelp_autocorr, &prm, code_fx, shift, st_fx->L_frame, st_fx->last_L_frame, st_fx->total_brate, st_fx->element_mode ); + // E_ACELP_innovative_codebook_fx( exc_fx, *pt_pitch_fx, 0, 1, gain_pit_fx, hLPDmem->tilt_code, acelp_cfg, i_subfr, p_Aq_fx, h1_fx, xn_fx, cn_fx, y1, y2_fx, (Word8) st_fx->acelp_autocorr, &prm, code_fx, shift, st_fx->L_frame, st_fx->last_L_frame, st_fx->total_brate, st_fx->element_mode ); inov_encode_ivas_fx( st_fx, st_fx->core_brate, 0, L_FRAME, st_fx->last_L_frame, UNVOICED, st_fx->bwidth, st_fx->sharpFlag, i_subfr, -1, p_Aq_fx, gain_pit_fx, cn_fx, exc_fx, h1_fx, hLPDmem->tilt_code, *pt_pitch_fx, xn_fx, code_fx, y2_fx, &unbits_PI, L_SUBFR, shift, Q_new ); @@ -398,6 +398,10 @@ void encod_unvoiced_ivas_fx( g_corr.xy2_e = sub( g_corr.xy2_e, add( Q_xn, 9 ) ); /* -(Q_xn+9) (xn: Q_xn y2: Q9) */ g_corr.y1y2_e = sub( g_corr.y1y2_e, add( Q_xn, 9 ) ); /* -(Q_xn+9) (y1: Q_xn y2: Q9) */ g_corr.xx_e = sub( g_corr.xx_e, add( Q_xn, Q_xn ) ); /* -(Q_xn+Q_xn) (xn: Q_xn) */ + move16(); + move16(); + move16(); + move16(); assert( gain_pit_fx == 0 ); gauss_L2_fx( h1_fx, code2, y2_fx, y22, &gain_code2, &g_corr, gain_pit_fx, hLPDmem->tilt_code, p_Aq_fx, acelp_cfg->formant_enh_num, &( st_fx->seed_acelp ), shift ); @@ -427,9 +431,10 @@ void encod_unvoiced_ivas_fx( *----------------------------------------------------------*/ E_UTIL_voice_factor( exc_fx, i_subfr, code_fx, gain_pit_fx, L_gain_code_fx, &voice_fac_fx, &( hLPDmem->tilt_code ), L_SUBFR, acelp_cfg->voice_tilt, Q_new, shift ); - IF( st_fx->Opt_RF_ON ) + if ( st_fx->Opt_RF_ON ) { st_fx->hRF->rf_tilt_buf[i_subfr_idx] = hLPDmem->tilt_code; + move16(); } /*-----------------------------------------------------------------* * Update memory of the weighting filter @@ -442,7 +447,7 @@ void encod_unvoiced_ivas_fx( Ltmp2 = Mpy_32_16_1( gain_code2, y22[L_SUBFR - 1] ); Ltmp2 = L_shl( Ltmp2, add( 5, Q_xn ) ); // Q_xn+15 Ltmp = L_add( Ltmp, Ltmp2 ); - hLPDmem->mem_w0 = sub( xn_fx[L_SUBFR - 1], round_fx( Ltmp ) ); // Q_xn-1 + hLPDmem->mem_w0 = sub( xn_fx[L_SUBFR - 1], round_fx( L_shl( Ltmp, 1 ) ) ); // Q_xn move16(); BASOP_SATURATE_WARNING_OFF_EVS; #ifdef BASOP_NOGLOB @@ -450,6 +455,7 @@ void encod_unvoiced_ivas_fx( #else hLPDmem->mem_w0 = shr( hLPDmem->mem_w0, shift ); /*Qnew-1*/ #endif + move16(); BASOP_SATURATE_WARNING_ON_EVS; /*-------------------------------------------------------* @@ -489,6 +495,7 @@ void encod_unvoiced_ivas_fx( BASOP_SATURATE_WARNING_ON_EVS exc_fx[i + i_subfr] = round_fx( Ltmp ); #endif + move16(); } tmp2 = L_SUBFR; move16(); @@ -496,6 +503,7 @@ void encod_unvoiced_ivas_fx( } *tmp_noise_fx = extract_h( norm_gain_code_fx ); + move16(); voice_factors_fx[i_subfr / L_SUBFR] = 0; move16(); diff --git a/lib_enc/eval_pit_contr.c b/lib_enc/eval_pit_contr.c index e101a812b..aee0b4a47 100644 --- a/lib_enc/eval_pit_contr.c +++ b/lib_enc/eval_pit_contr.c @@ -42,6 +42,7 @@ #include "prot.h" #include "wmc_auto.h" +#ifndef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* * Local constantes *-------------------------------------------------------------------*/ @@ -355,3 +356,4 @@ int16_t Pit_exc_contribution_len( return last_pit_bin; } +#endif diff --git a/lib_enc/fd_cng_enc.c b/lib_enc/fd_cng_enc.c index ab6c2efd1..a947768a3 100644 --- a/lib_enc/fd_cng_enc.c +++ b/lib_enc/fd_cng_enc.c @@ -136,7 +136,6 @@ void initFdCngEnc( } /* Initialize the Noise Estimator */ -#ifndef IVAS_FLOAT_FIXED set_f( hFdCngEnc->msPeriodog, 0.0f, NPART ); set_f( hFdCngEnc->msBminWin, 0.0f, NPART ); set_f( hFdCngEnc->msBminSubWin, 0.0f, NPART ); @@ -156,7 +155,6 @@ void initFdCngEnc( set_f( hFdCngEnc->mem_coherence, EPSILON, 4 ); set_f( hFdCngEnc->msNoiseEst_old, 0.0f, NPART ); set_f( hFdCngEnc->msNoiseEst, 0.0f, NPART ); -#endif set_s( hFdCngEnc->msLocalMinFlag, 0, NPART ); set_s( hFdCngEnc->msNewMinFlag, 0, NPART ); hFdCngEnc->msPeriodogBufPtr = 0; @@ -1570,11 +1568,6 @@ void FdCngEncodeMDCTStereoSID_fx( Word16 size_value, temp_e, gb, shift; Word32 tmp32, t1, t2; -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - f2me_buf( hCPE->hCoreCoder[0]->hFdCngEnc->hFdCngCom->sidNoiseEst_flt, hCPE->hCoreCoder[0]->hFdCngEnc->hFdCngCom->sidNoiseEst, &hCPE->hCoreCoder[0]->hFdCngEnc->hFdCngCom->sidNoiseEstExp, hCPE->hCoreCoder[0]->hFdCngEnc->npartDec ); - f2me_buf( hCPE->hCoreCoder[1]->hFdCngEnc->hFdCngCom->sidNoiseEst_flt, hCPE->hCoreCoder[1]->hFdCngEnc->hFdCngCom->sidNoiseEst, &hCPE->hCoreCoder[1]->hFdCngEnc->hFdCngCom->sidNoiseEstExp, hCPE->hCoreCoder[0]->hFdCngEnc->npartDec ); -#endif - is_inp_ms = 0; move16(); IF( EQ_16( hCPE->hCoreCoder[0]->cng_sba_flag, 1 ) ) @@ -1843,11 +1836,7 @@ void FdCngEncodeMDCTStereoSID_fx( /* pad with zeros to reach common SID frame size */ push_indice( sts[1]->hBstr, IND_ENERGY, 0, ( IVAS_SID_5k2 - 4400 ) / FRAMES_PER_SEC ); -#ifdef IVAS_FLOAT_FIXED - me2f_buf( sts[0]->hFdCngEnc->hFdCngCom->cngNoiseLevel, sts[0]->hFdCngEnc->hFdCngCom->cngNoiseLevelExp, sts[0]->hFdCngEnc->hFdCngCom->cngNoiseLevel_flt, FFTCLDFBLEN ); - me2f_buf( sts[1]->hFdCngEnc->hFdCngCom->cngNoiseLevel, sts[1]->hFdCngEnc->hFdCngCom->cngNoiseLevelExp, sts[1]->hFdCngEnc->hFdCngCom->cngNoiseLevel_flt, FFTCLDFBLEN ); - me2f_buf( sts[0]->hFdCngEnc->hFdCngCom->sidNoiseEst, sts[0]->hFdCngEnc->hFdCngCom->sidNoiseEstExp, sts[0]->hFdCngEnc->hFdCngCom->sidNoiseEst_flt, sts[0]->hFdCngEnc->npartDec ); - me2f_buf( sts[1]->hFdCngEnc->hFdCngCom->sidNoiseEst, sts[1]->hFdCngEnc->hFdCngCom->sidNoiseEstExp, sts[1]->hFdCngEnc->hFdCngCom->sidNoiseEst_flt, sts[0]->hFdCngEnc->npartDec ); +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS sts[0]->preemph_fac_flt = fixedToFloat( sts[0]->preemph_fac, Q15 ); sts[1]->preemph_fac_flt = fixedToFloat( sts[1]->preemph_fac, Q15 ); #endif @@ -2254,15 +2243,6 @@ void FdCngEncodeDiracMDCTStereoSID_fx( Word32 t1, t2, tmp32; /* set pointers and initialize */ - -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - f2me_buf( hCPE->hCoreCoder[0]->hFdCngEnc->hFdCngCom->sidNoiseEst_flt, hCPE->hCoreCoder[0]->hFdCngEnc->hFdCngCom->sidNoiseEst, &hCPE->hCoreCoder[0]->hFdCngEnc->hFdCngCom->sidNoiseEstExp, hCPE->hCoreCoder[0]->hFdCngEnc->npartDec ); - f2me_buf( hCPE->hCoreCoder[1]->hFdCngEnc->hFdCngCom->sidNoiseEst_flt, hCPE->hCoreCoder[1]->hFdCngEnc->hFdCngCom->sidNoiseEst, &hCPE->hCoreCoder[1]->hFdCngEnc->hFdCngCom->sidNoiseEstExp, hCPE->hCoreCoder[1]->hFdCngEnc->npartDec ); - f2me_buf( hCPE->hCoreCoder[0]->hFdCngEnc->hFdCngCom->cngNoiseLevel_flt, hCPE->hCoreCoder[0]->hFdCngEnc->hFdCngCom->cngNoiseLevel, &hCPE->hCoreCoder[0]->hFdCngEnc->hFdCngCom->cngNoiseLevelExp, FFTCLDFBLEN ); - f2me_buf( hCPE->hCoreCoder[1]->hFdCngEnc->hFdCngCom->cngNoiseLevel_flt, hCPE->hCoreCoder[1]->hFdCngEnc->hFdCngCom->cngNoiseLevel, &hCPE->hCoreCoder[1]->hFdCngEnc->hFdCngCom->cngNoiseLevelExp, FFTCLDFBLEN ); -#endif - - FOR( ch = 0; ch < CPE_CHANNELS; ch++ ) { sts[ch] = hCPE->hCoreCoder[ch]; @@ -2453,11 +2433,7 @@ void FdCngEncodeDiracMDCTStereoSID_fx( } push_indice( sts[0]->hBstr, IND_ENERGY, gain_idx[0], 7 ); -#ifdef IVAS_FLOAT_FIXED - me2f_buf( sts[0]->hFdCngEnc->hFdCngCom->cngNoiseLevel, sts[0]->hFdCngEnc->hFdCngCom->cngNoiseLevelExp, sts[0]->hFdCngEnc->hFdCngCom->cngNoiseLevel_flt, FFTCLDFBLEN ); - me2f_buf( sts[1]->hFdCngEnc->hFdCngCom->cngNoiseLevel, sts[1]->hFdCngEnc->hFdCngCom->cngNoiseLevelExp, sts[1]->hFdCngEnc->hFdCngCom->cngNoiseLevel_flt, FFTCLDFBLEN ); - me2f_buf( sts[0]->hFdCngEnc->hFdCngCom->sidNoiseEst, sts[0]->hFdCngEnc->hFdCngCom->sidNoiseEstExp, sts[0]->hFdCngEnc->hFdCngCom->sidNoiseEst_flt, sts[0]->hFdCngEnc->npartDec ); - me2f_buf( sts[1]->hFdCngEnc->hFdCngCom->sidNoiseEst, sts[1]->hFdCngEnc->hFdCngCom->sidNoiseEstExp, sts[1]->hFdCngEnc->hFdCngCom->sidNoiseEst_flt, sts[1]->hFdCngEnc->npartDec ); +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS sts[0]->preemph_fac_flt = fixedToFloat( sts[0]->preemph_fac, Q15 ); sts[1]->preemph_fac_flt = fixedToFloat( sts[1]->preemph_fac, Q15 ); #endif diff --git a/lib_enc/fd_cng_enc_fx.c b/lib_enc/fd_cng_enc_fx.c index 0821a3922..111cd2dc0 100644 --- a/lib_enc/fd_cng_enc_fx.c +++ b/lib_enc/fd_cng_enc_fx.c @@ -57,9 +57,6 @@ void initFdCngEnc_fx( HANDLE_FD_CNG_ENC hsEnc, Word32 input_Fs, Word16 scale ) HANDLE_FD_CNG_COM hsCom = hsEnc->hFdCngCom; /* Initialize common */ -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - initFdCngCom_flt( hsCom, scale ); -#endif initFdCngCom( hsCom, scale ); /* Configure the Noise Estimator */ @@ -95,17 +92,6 @@ void initFdCngEnc_fx( HANDLE_FD_CNG_ENC hsEnc, Word32 input_Fs, Word16 scale ) move16(); } -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - initPartitions_flt( sidparts_encoder_noise_est, SIZE_SIDPARTS_ENC_NOISE_EST, hsCom->startBand, hsCom->stopBand, hsCom->part, &hsCom->npart, hsCom->midband, hsCom->psize_flt, hsCom->psize_inv_flt, 0 ); - - hsCom->nCLDFBpart = hsCom->npart - hsCom->nFFTpart; - for ( j = 0; j < hsCom->nCLDFBpart; j++ ) - { - hsCom->CLDFBpart[j] = hsCom->part[j + hsCom->nFFTpart] - ( 256 - hsCom->startBand ); - hsCom->CLDFBpsize_inv_flt[j] = hsCom->psize_inv_flt[j + hsCom->nFFTpart]; - } -#endif - initPartitions( sidparts_encoder_noise_est, SIZE_SIDPARTS_ENC_NOISE_EST, hsCom->startBand, hsCom->stopBand, hsCom->part, &hsCom->npart, hsCom->midband, hsCom->psize, hsCom->psize_norm, &hsCom->psize_norm_exp, hsCom->psize_inv, 0 ); hsCom->nCLDFBpart = sub( hsCom->npart, hsCom->nFFTpart ); @@ -113,6 +99,8 @@ void initFdCngEnc_fx( HANDLE_FD_CNG_ENC hsEnc, Word32 input_Fs, Word16 scale ) { hsCom->CLDFBpart[j] = sub( hsCom->part[j + hsCom->nFFTpart], sub( 256, hsCom->startBand ) ); hsCom->CLDFBpsize_inv[j] = hsCom->psize_inv[j + hsCom->nFFTpart]; + move16(); + move16(); } /* Initialize noise estimation algorithm */ @@ -153,7 +141,6 @@ void initFdCngEnc_fx( HANDLE_FD_CNG_ENC hsEnc, Word32 input_Fs, Word16 scale ) set32_fx( hsEnc->mem_coherence_fx, EPSILON_FX, 4 ); set16_fx( hsEnc->mem_coherence_exp, 0, 4 ); - return; } diff --git a/lib_enc/find_tar.c b/lib_enc/find_tar.c index 244720947..bb172ebc2 100644 --- a/lib_enc/find_tar.c +++ b/lib_enc/find_tar.c @@ -40,6 +40,7 @@ #include "prot.h" #include "wmc_auto.h" +#ifndef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* * find_targets() * @@ -118,3 +119,4 @@ void find_targets( return; } +#endif diff --git a/lib_enc/gaus_enc.c b/lib_enc/gaus_enc.c index 9a1334485..3b3b1e43c 100644 --- a/lib_enc/gaus_enc.c +++ b/lib_enc/gaus_enc.c @@ -42,6 +42,7 @@ #include "prot.h" #include "wmc_auto.h" +#ifndef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* * Local constants *-------------------------------------------------------------------*/ @@ -458,3 +459,4 @@ static int16_t cod_2pos( return index; } +#endif diff --git a/lib_enc/gp_clip.c b/lib_enc/gp_clip.c index 51cbd2cab..fecd64220 100644 --- a/lib_enc/gp_clip.c +++ b/lib_enc/gp_clip.c @@ -41,6 +41,7 @@ #include "cnst.h" #include "wmc_auto.h" +#ifndef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* * Local constants *-------------------------------------------------------------------*/ @@ -248,3 +249,4 @@ void gp_clip_test_gain_pit( return; } +#endif diff --git a/lib_enc/gs_enc.c b/lib_enc/gs_enc.c index 309c56a36..f60107866 100644 --- a/lib_enc/gs_enc.c +++ b/lib_enc/gs_enc.c @@ -42,7 +42,11 @@ #include "prot.h" #include "ivas_prot.h" #include "wmc_auto.h" +#ifdef IVAS_FLOAT_FIXED +#include "prot_fx.h" +#endif +#ifndef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* * Local function prototypes *-------------------------------------------------------------------*/ @@ -639,6 +643,7 @@ static float edyn( return dyn; } +#endif /*-------------------------------------------------------------------* @@ -655,19 +660,38 @@ void GSC_enc_init( hGSCEnc->seed_tcx = 15687; hGSCEnc->cor_strong_limit = 1; set_f( hGSCEnc->last_exc_dct_in, 0, L_FRAME16k ); +#ifndef IVAS_FLOAT_FIXED hGSCEnc->last_ener = 0.0f; +#else + hGSCEnc->last_ener_fx = 0; +#endif set_s( hGSCEnc->last_bitallocation_band, 0, 6 ); hGSCEnc->mem_last_pit_band = BAND1k2 + 1; +#ifndef IVAS_FLOAT_FIXED hGSCEnc->lt_gpitch = 0.0f; +#else + hGSCEnc->lt_gpitch_fx = 0; +#endif hGSCEnc->pit_exc_hangover = 0; /* GSC - pitch excitation parameters */ +#ifndef IVAS_FLOAT_FIXED hGSCEnc->mem_w0_tmp = 0.0f; set_f( hGSCEnc->mem_syn_tmp, 0.0f, M ); +#else + hGSCEnc->mem_w0_tmp_fx = 0; + move16(); + set16_fx( hGSCEnc->mem_syn_tmp_fx, 0, M ); +#endif hGSCEnc->Last_frame_ener = (float) MAX_32; +#ifndef IVAS_FLOAT_FIXED hGSCEnc->mid_dyn = 40.0f; +#else + hGSCEnc->mid_dyn_fx = 5120; + move16(); /*40 -> Q7 */ +#endif hGSCEnc->noise_lev = NOISE_LEVEL_SP0; hGSCEnc->past_dyn_dec = 0; diff --git a/lib_enc/init_enc.c b/lib_enc/init_enc.c index 0573450d4..d0071ebeb 100644 --- a/lib_enc/init_enc.c +++ b/lib_enc/init_enc.c @@ -166,14 +166,13 @@ ivas_error init_encoder( set16_fx( st->mem_MA_fx, 0, M ); #endif - init_gp_clip( st->clip_var ); - pitch_ol_init( #ifndef IVAS_FLOAT_FIXED - &st->old_thres, + init_gp_clip( st->clip_var ); + pitch_ol_init( &st->old_thres, &st->old_pitch, &st->delta_pit, &st->old_corr ); #else - &st->old_thres_fx, + init_gp_clip_fx( st->clip_var_fx ); + pitch_ol_init_fx( &st->old_thres_fx, &st->old_pitch, &st->delta_pit, &st->old_corr_fx ); #endif - &st->old_pitch, &st->delta_pit, &st->old_corr ); set_f( st->old_wsp, 0, L_WSP_MEM ); #ifdef IVAS_FLOAT_FIXED set16_fx( st->old_wsp_fx, 0, L_WSP_MEM ); @@ -735,7 +734,11 @@ ivas_error init_encoder( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SC-VBR\n" ) ); } +#ifndef IVAS_FLOAT_FIXED sc_vbr_enc_init( st->hSC_VBR ); +#else + sc_vbr_enc_init_fx( st->hSC_VBR ); +#endif } else { @@ -1301,16 +1304,6 @@ ivas_error init_encoder_ivas_fx( Copy( GEWB_Ave_fx, st->lsfoldbfi0_fx, M ); Copy( GEWB_Ave_fx, st->lsfoldbfi1_fx, M ); Copy( GEWB_Ave_fx, st->lsf_adaptive_mean_fx, M ); -#if 1 // TODO: Float Initializations. To be removed later - init_gp_clip( st->clip_var ); - pitch_ol_init( -#ifndef IVAS_FLOAT_FIXED - &st->old_thres, -#else - &st->old_thres_fx, -#endif - &st->old_pitch, &st->delta_pit, &st->old_corr ); -#endif st->next_force_safety_net = 0; move16(); @@ -1892,9 +1885,6 @@ ivas_error init_encoder_ivas_fx( } sc_vbr_enc_init_fx( st->hSC_VBR ); -#if 1 - sc_vbr_enc_init( st->hSC_VBR ); -#endif } ELSE { @@ -2407,6 +2397,9 @@ void LPDmem_enc_init( LPD_state_HANDLE hLPDmem /* i/o: LP memories */ ) { +#ifdef IVAS_FLOAT_FIXED + Word16 i; +#endif set_zero( hLPDmem->syn_flt, 1 + M ); set_f( hLPDmem->old_exc_flt, 0, L_EXC_MEM ); @@ -2417,13 +2410,24 @@ void LPDmem_enc_init( set_zero( hLPDmem->mem_syn_r_flt, L_SYN_MEM ); set_f( hLPDmem->mem_syn3_flt, 0, M ); - hLPDmem->tilt_code_flt = 0.0f; #ifndef IVAS_FLOAT_FIXED + hLPDmem->tilt_code_flt = 0.0f; hLPDmem->gc_threshold_flt = 0.0f; + set_f( hLPDmem->dispMem_flt, 0, 8 ); #else + hLPDmem->tilt_code = 0; hLPDmem->gc_threshold = 0; + hLPDmem->dm_fx.prev_state = 0; + move16(); /* This corresponds to st_fx->dispMem in FLP */ + hLPDmem->dm_fx.prev_gain_code = 0; + move32(); + + FOR( i = 2; i < 8; i++ ) + { + hLPDmem->dm_fx.prev_gain_pit[i - 2] = 0; + move16(); + } #endif - set_f( hLPDmem->dispMem_flt, 0, 8 ); return; } diff --git a/lib_enc/inov_enc_fx.c b/lib_enc/inov_enc_fx.c index 5c9e1a7de..30288b0dc 100644 --- a/lib_enc/inov_enc_fx.c +++ b/lib_enc/inov_enc_fx.c @@ -457,9 +457,7 @@ Word16 inov_encode_ivas_fx( Word16 acelpautoc; BSTR_ENC_HANDLE hBstr = st_fx->hBstr; Word16 i, k; -#ifdef REMOVE_IVAS_UNUSED_PARAMETERS_WARNING - (void) last_L_frame; -#endif + Word16 Qxn, Rw_q, j; stack_pulses = 0; move16(); @@ -478,6 +476,8 @@ Word16 inov_encode_ivas_fx( move16(); } + Qxn = add( sub( Q_new, 1 ), shift ); + /*----------------------------------------------------------------* * Update target vector for codebook search in residual domain * Preemphasize the impulse response and include fixed-gain pitch contribution into impulse resp. h1[] (pitch sharpenning) @@ -494,15 +494,14 @@ Word16 inov_encode_ivas_fx( cb_shape_fx( 1, 1, 0, sharpFlag, 0, g1, g2, p_Aq, h2, tilt_code, shr( add( pt_pitch, 26 ), 6 ), 0, L_SUBFR ); /* h2: Q11, Rw: (Rw_e)Q */ // Word16 Rw_e = E_ACELP_hh_corr( h2, Rw, L_SUBFR, 3 ); - Word16 Rw_q; corr_hh_ivas_fx( h2, Rw, &Rw_q, L_subfr ); // Q(Rw) = Q11-2 E_ACELP_conv_ivas( xn2, h2, cn ); // Qcn = Qxn2 /* dn_e -> Rw_e*Q_xn */ // Scale_sig(Rw, L_SUBFR, sub(5, Rw_e)); //Q9 - Word16 j = E_ACELP_toeplitz_mul_fx( Rw, cn, dn, L_SUBFR, 1 ); - Qdn = add( add( Q_new - 1 + shift, Rw_q ), j + 1 ); + j = E_ACELP_toeplitz_mul_fx( Rw, cn, dn, L_SUBFR, 1 ); + Qdn = add( add( Qxn, Rw_q ), add( j, 1 ) ); // Scale_sig(Rw, L_subfr, -3); //Q9->Q6 } ELSE @@ -514,7 +513,7 @@ Word16 inov_encode_ivas_fx( Scale_sig( cn, L_subfr, shift ); cb_shape_fx( 1, 1, 0, sharpFlag, 0, g1, g2, p_Aq, h2, tilt_code, shr( add( pt_pitch, 26 ), 6 ), 0, L_subfr ); - corr_xh_ivas_fx2( xn2, Q_new - 1 + shift, dn, &Qdn, h2, L_subfr ); // Q(dn) = Q_new+1 + corr_xh_ivas_fx( xn2, Qxn, dn, &Qdn, h2, L_subfr ); // Q(dn) = Q_new+1 } /*-----------------------------------------------------------------* @@ -666,11 +665,11 @@ Word16 inov_encode_ivas_fx( Word16 wordcnt, bitcnt; Word16 prm[8]; - test(); - test(); - test(); IF( st_fx->acelp_cfg.fixed_cdk_index[idx] >= 0 ) { + test(); + test(); + test(); IF( EQ_16( L_subfr, 2 * L_SUBFR ) ) { nBits = st_fx->acelp_cfg.fixed_cdk_index[idx]; @@ -724,7 +723,8 @@ Word16 inov_encode_ivas_fx( { FOR( k = 0; k < L_SUBFR - i; k++ ) { - y2[i + k] = add( y2[i + k], mult_r( code[i], shl_sat( h2[k], sh ) ) ); + y2[i + k] = add( y2[i + k], round_fx( L_shl( L_mult( code[i], h2[k] ), sh ) ) ); // Q9 + move16(); } } } @@ -746,7 +746,7 @@ Word16 inov_encode_ivas_fx( } ELSE { - nBits = st_fx->acelp_cfg.fixed_cdk_index[shr( i_subfr, 6 )]; + nBits = st_fx->acelp_cfg.fixed_cdk_index[i_subfr >> 6]; move16(); diff --git a/lib_enc/ivas_core_enc.c b/lib_enc/ivas_core_enc.c index a80c36ad4..5b1bf1f14 100644 --- a/lib_enc/ivas_core_enc.c +++ b/lib_enc/ivas_core_enc.c @@ -98,11 +98,7 @@ ivas_error ivas_core_enc( float new_swb_speech_buffer[L_FRAME48k + STEREO_DFT_OVL_MAX]; float bwe_exc_extended[CPE_CHANNELS][L_FRAME32k + NL_BUFF_OFFSET]; Word16 Q_new[CPE_CHANNELS]; -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS // required for float fixed conversions float voice_factors[CPE_CHANNELS][NB_SUBFR16k] = { 0 }; -#else - float voice_factors[CPE_CHANNELS][NB_SUBFR16k]; -#endif #ifdef IVAS_FLOAT_FIXED Word32 *new_swb_speech_fx; Word16 shb_speech_fx[L_FRAME16k]; // Q_shb_spch @@ -226,7 +222,7 @@ ivas_error ivas_core_enc( Word16 fft_buff_fx[2 * L_FFT]; Word32 cor_map_sum_fx = 0; Word16 exp_cor_map_sum = 0; - Word16 q_fft_buff; + Word16 e_fft_buff; Word16 e_enerBuffer; st->preemph_fac = (Word16) floatToFixed( st->preemph_fac_flt, Q15 ); @@ -242,27 +238,10 @@ ivas_error ivas_core_enc( f2me( cor_map_sum[n], &cor_map_sum_fx, &exp_cor_map_sum ); - q_fft_buff = Q_factor_arrL( fft_buff[n], ( 2 * L_FFT ) ); - - if ( q_fft_buff <= 16 ) - { - q_fft_buff = 0; - } - else - { - q_fft_buff = q_fft_buff - 16; - } - - if ( q_fft_buff >= 2 ) - { - q_fft_buff -= 3; - } - else - { - q_fft_buff -= 4; - } + f2me_buf_16( fft_buff[n], fft_buff_fx, &e_fft_buff, ( 2 * L_FFT ) ); + Scale_sig( fft_buff_fx, ( 2 * L_FFT ), -1 ); // To create 1 headroom for addition of magnitude square spectrum + e_fft_buff += 1; - floatToFixed_arr( fft_buff[n], fft_buff_fx, q_fft_buff, ( 2 * L_FFT ) ); f2me_buf( enerBuffer[n], enerBuffer_fx, &e_enerBuffer, (Word32) CLDFB_NO_CHANNELS_MAX ); Word16 tmp_shift = find_guarded_bits_fx( 5 ); // Computing guraded bits necessary in the energyBuffer scale_sig32( enerBuffer_fx, CLDFB_NO_CHANNELS_MAX, -tmp_shift ); // Computing the shift as per guarded bits in the energyBuffer @@ -283,7 +262,11 @@ ivas_error ivas_core_enc( move16(); } #endif - if ( ( error = pre_proc_ivas( st, last_element_mode, element_brate, ivas_format == SBA_FORMAT ? last_element_brate : element_brate, input_frame, old_inp_12k8[n], old_inp_16k[n], +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + Word16 old_inp_12k8_fx[L_INP_12k8]; + floatToFixed_arr16( old_inp_12k8[n], old_inp_12k8_fx, -1, L_INP_12k8 ); +#endif + if ( ( error = pre_proc_ivas( st, last_element_mode, element_brate, ivas_format == SBA_FORMAT ? last_element_brate : element_brate, input_frame, old_inp_12k8[n], old_inp_12k8_fx, old_inp_16k[n], &inp[n], &ener[n], A[n], Aw[n], epsP[n], lsp_new[n], lsp_mid[n], new_inp_resamp16k[n], &Voicing_flag[n], old_wsp[n], loc_harm[n], #ifndef IVAS_FLOAT_FIXED cor_map_sum[n], @@ -446,15 +429,6 @@ ivas_error ivas_core_enc( // floatToFixed_arr( lsp_mid, lsp_mid_fx, Q15, M ); st->hTcxCfg->preemph_fac = float_to_fix16( st->hTcxCfg->preemph_fac_flt, Q15 ); - - { - st->clip_var_fx[0] = (Word16) ( st->clip_var[0] * 2.56f ); - st->clip_var_fx[1] = float_to_fix16( st->clip_var[1], Q14 ); - st->clip_var_fx[2] = float_to_fix16( st->clip_var[2], Q8 ); - st->clip_var_fx[3] = float_to_fix16( st->clip_var[3], 0 ); - st->clip_var_fx[4] = float_to_fix16( st->clip_var[4], Q14 ); - st->clip_var_fx[5] = float_to_fix16( st->clip_var[5], Q14 ); - } st->hTcxEnc->measuredBwRatio = float_to_fix16( st->hTcxEnc->measuredBwRatio_flt, Q14 ); floatToFixed_arr( st->hTcxEnc->Txnq_flt, st->hTcxEnc->Txnq, -1, L_FRAME32k / 2 + 64 ); @@ -473,14 +447,6 @@ ivas_error ivas_core_enc( st->hTcxEnc->measuredBwRatio_flt = fix16_to_float( st->hTcxEnc->measuredBwRatio, Q14 ); - { - st->clip_var[0] = (float) st->clip_var_fx[0] / 2.56f; - st->clip_var[1] = fix16_to_float( st->clip_var_fx[1], Q14 ); - st->clip_var[2] = fix16_to_float( st->clip_var_fx[2], Q8 ); - st->clip_var[3] = fix16_to_float( st->clip_var_fx[3], 0 ); - st->clip_var[4] = fix16_to_float( st->clip_var_fx[4], Q14 ); - st->clip_var[5] = fix16_to_float( st->clip_var_fx[5], Q14 ); - } for ( int k = 0; k < 2; k++ ) { fixedToFloat_arrL( st->hTcxEnc->spectrum_fx[k], st->hTcxEnc->spectrum[k], 31 - st->hTcxEnc->spectrum_e[k], 720 ); diff --git a/lib_enc/ivas_core_pre_proc.c b/lib_enc/ivas_core_pre_proc.c index bef00f87a..d8742856c 100644 --- a/lib_enc/ivas_core_pre_proc.c +++ b/lib_enc/ivas_core_pre_proc.c @@ -53,11 +53,12 @@ ivas_error pre_proc_ivas( Encoder_State *st, /* i/o: encoder state structure */ - const int16_t last_element_mode, /* i : last element mode */ - const int32_t element_brate, /* i : element bitrate */ - const int32_t last_element_brate, /* i : last element bitrate */ - const int16_t input_frame, /* i : frame length */ + const Word16 last_element_mode, /* i : last element mode */ + const Word32 element_brate, /* i : element bitrate */ + const Word32 last_element_brate, /* i : last element bitrate */ + const Word16 input_frame, /* i : frame length */ float old_inp_12k8[], /* i/o: buffer of old input signal */ + Word16 old_inp_12k8_fx[], /* i/o: buffer of old input signal */ float old_inp_16k[], /* i/o: buffer of old input signal @ 16kHz */ float **inp, /* o : ptr. to inp. signal in the current frame*/ float *ener, /* o : residual energy from Levinson-Durbin */ @@ -67,20 +68,13 @@ ivas_error pre_proc_ivas( float lsp_new[M], /* i/o: LSPs at the end of the frame */ float lsp_mid[M], /* i/o: LSPs in the middle of the frame */ float *new_inp_resamp16k, /* o : new input signal @16kHz, non pre-emphasised, used by the WB TBE/BWE */ - int16_t *Voicing_flag, /* o : voicing flag for HQ FEC */ - const float old_wsp[], /* i : weighted input signal buffer */ - const int16_t loc_harm, /* i : harmonicity flag */ -#ifndef IVAS_FLOAT_FIXED - const float cor_map_sum, /* i : speech/music clasif. parameter */ -#endif - const int16_t vad_flag_dtx, /* i : HE-SAD flag with additional DTX HO */ -#ifndef IVAS_FLOAT_FIXED - /*const*/ float enerBuffer[CLDFB_NO_CHANNELS_MAX], /* i : energy buffer */ - /*const*/ float fft_buff[2 * L_FFT], /* i : FFT buffer */ -#endif - const int16_t MCT_flag, /* i : hMCT handle allocated (1) or not (0) */ - const int16_t vad_hover_flag, /* i : VAD hangover flag */ - const int16_t flag_16k_smc /* i : flag to indicate if the OL SMC is run at 16 kHz */ + Word16 *Voicing_flag, /* o : voicing flag for HQ FEC */ + float old_wsp[], /* i : weighted input signal buffer */ + const Word16 loc_harm, /* i : harmonicity flag */ + const Word16 vad_flag_dtx, /* i : HE-SAD flag with additional DTX HO */ + const Word16 MCT_flag, /* i : hMCT handle allocated (1) or not (0) */ + const Word16 vad_hover_flag, /* i : VAD hangover flag */ + const Word16 flag_16k_smc /* i : flag to indicate if the OL SMC is run at 16 kHz */ #ifdef IVAS_FLOAT_FIXED , Word32 enerBuffer_fx[CLDFB_NO_CHANNELS_MAX], @@ -91,21 +85,24 @@ ivas_error pre_proc_ivas( #endif ) { - int16_t L_look, element_mode, lMemRecalc_12k8; + Word16 L_look, element_mode, lMemRecalc_12k8; float *inp_12k8, *new_inp_12k8, *inp_16k; /* pointers to current frame and new data */ - const float *wsp; /* weighted input signal buffer */ - int32_t sr_core_tmp, total_brate_tmp; + Word16 *inp_16k_fx, *new_inp_12k8_fx; + float *wsp; /* weighted input signal buffer */ + Word32 sr_core_tmp, total_brate_tmp; ivas_error error; push_wmops( "pre_proc" ); error = IVAS_ERR_OK; + move32(); /*----------------------------------------------------------------* * Initialization *----------------------------------------------------------------*/ element_mode = st->element_mode; + move16(); #ifdef IVAS_FLOAT_FIXED_CONVERSIONS Word16 A_fx[NB_SUBFR16k * ( M + 1 )]; @@ -119,52 +116,33 @@ ivas_error pre_proc_ivas( floatToFixed_arr16( lsp_mid, lsp_mid_fx, Q15, M ); #endif -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS1 - Word16 old_inp_16k_fx[L_INP_MEM]; - Word16 exp_old_inp_16k = 0; - Word16 old_inp_12k8_fx[496]; - Word16 exp_old_inp_12k8 = 0; - Word16 old_wsp_fx[L_WSP]; - Word16 exp_old_wsp = 0; - Word16 Aw_fx[NB_SUBFR16k * ( M + 1 )], exp_Aw = 0; - Word16 lsp_new_fx[M], exp_lsp_new = 0; - Word16 lsp_mid_fx[M], exp_lsp_mid = 0; - Word16 epsP_fx[M + 1], exp_epsP = 0; - Word32 enerBuffer_fx[CLDFB_NO_CHANNELS_MAX]; - Word16 fft_buff_fx[2 * L_FFT]; - Word32 cor_map_sum_fx = 0; - Word16 exp_cor_map_sum = 0; - Word16 q_fft_buff; - Word16 e_enerBuffer; - - /*input buffers*/ - f2me_buf_16( st->old_inp_16k, old_inp_16k_fx, &exp_old_inp_16k, L_INP_MEM ); - f2me_buf_16( old_inp_12k8, old_inp_12k8_fx, &exp_old_inp_12k8, 496 ); - f2me_buf_16( old_wsp, old_wsp_fx, &exp_old_wsp, L_WSP ); - f2me_buf_16( epsP, epsP_fx, &exp_epsP, M + 1 ); - f2me( cor_map_sum, &cor_map_sum_fx, &exp_cor_map_sum ); -#endif - new_inp_12k8 = old_inp_12k8 + L_INP_MEM; /* pointer to new samples of the input signal in 12.8kHz core */ inp_12k8 = new_inp_12k8 - L_LOOK_12k8; - if ( element_mode != IVAS_CPE_DFT ) + if ( NE_16( element_mode, IVAS_CPE_DFT ) ) { new_inp_12k8 -= L_FILT; } + new_inp_12k8_fx = old_inp_12k8_fx + L_INP_MEM; /* pointer to new samples of the input signal in 12.8kHz core */ + + if ( NE_16( element_mode, IVAS_CPE_DFT ) ) + { + new_inp_12k8_fx -= L_FILT; + } wsp = old_wsp + L_WSP_MEM; /* pointer to the current frame of weighted signal in 12.8kHz core */ lMemRecalc_12k8 = 0; - if ( element_mode == IVAS_CPE_TD ) + move16(); + if ( EQ_16( element_mode, IVAS_CPE_TD ) ) { lMemRecalc_12k8 = NS2SA( INT_FS_12k8, L_MEM_RECALC_NS ); + move16(); } /*----------------------------------------------------------------* * Selection of internal ACELP Fs (12.8 kHz or 16 kHz) *----------------------------------------------------------------*/ -#ifdef IVAS_FLOAT_FIXED test(); test(); test(); @@ -180,7 +158,7 @@ ivas_error pre_proc_ivas( test(); test(); test(); - IF( EQ_32( st->core_brate, FRAME_NO_DATA ) ) + IF( st->core_brate == FRAME_NO_DATA ) { /* prevent "L_frame" changes in CNG segments */ st->L_frame = st->last_L_frame; @@ -217,6 +195,7 @@ ivas_error pre_proc_ivas( test(); test(); Word16 flag_1 = 0; + move16(); IF( EQ_16( st->L_frame, L_FRAME16k ) ) { flag_1 = ACELP_16k40; @@ -232,7 +211,7 @@ ivas_error pre_proc_ivas( configureFdCngEnc_ivas_fx( st->hFdCngEnc, max( st->input_bwidth, WB ), flag_1 ); } - IF( st->ini_frame == 0 ) + if ( st->ini_frame == 0 ) { /* avoid switching of internal ACELP Fs in the very first frame */ st->last_L_frame = st->L_frame; @@ -248,7 +227,6 @@ ivas_error pre_proc_ivas( } ELSE IF( EQ_16( st->L_frame, L_FRAME32k ) ) { - st->gamma = GAMMA16k; st->preemph_fac = PREEMPH_FAC_SWB; move16(); @@ -268,76 +246,12 @@ ivas_error pre_proc_ivas( move32(); move16(); move16(); -#else - if ( st->core_brate == FRAME_NO_DATA ) - { - /* prevent "L_frame" changes in CNG segments */ - st->L_frame = st->last_L_frame; - } - else if ( st->core_brate == SID_2k40 && st->bwidth >= WB && st->hDtxEnc->first_CNG && ( st->hTdCngEnc != NULL && st->hTdCngEnc->act_cnt2 < MIN_ACT_CNG_UPD ) ) - { - /* prevent "L_frame" changes in SID frame after short segment of active frames */ - st->L_frame = st->hDtxEnc->last_CNG_L_frame; - } - else if ( ( ( st->element_mode == IVAS_CPE_MDCT && st->element_brate >= IVAS_64k && st->bwidth >= SWB ) || ( element_mode == IVAS_SCE && st->total_brate > MAX_ACELP_BRATE && st->bwidth >= SWB ) ) && st->core_brate != SID_2k40 ) - { - st->L_frame = L_FRAME32k; - } - else if ( st->bwidth >= SWB && st->total_brate > MAX_ACELP_BRATE_ISM && st->total_brate <= MAX_ACELP_BRATE && element_mode == IVAS_SCE && st->is_ism_format && st->tcxonly && st->core_brate != SID_2k40 ) - { - st->L_frame = L_FRAME25_6k; - } - else if ( st->flag_ACELP16k ) - { - st->L_frame = L_FRAME16k; - } - else - { - st->L_frame = L_FRAME; - } - - if ( st->hFdCngEnc != NULL && st->element_mode != IVAS_CPE_MDCT && ( ( st->hFdCngEnc->hFdCngCom->frameSize != st->L_frame ) || ( st->hFdCngEnc->hFdCngCom->CngBandwidth != st->input_bwidth ) ) ) - { -#ifdef IVAS_FLOAT_FIXED - configureFdCngEnc_ivas_fx( st->hFdCngEnc, max( st->input_bwidth, WB ), st->L_frame == L_FRAME16k ? ACELP_16k40 : ACELP_9k60 ); -#else - configureFdCngEnc( st->hFdCngEnc, max( st->input_bwidth, WB ), st->L_frame == L_FRAME16k ? ACELP_16k40 : ACELP_9k60 ); -#endif - } - - if ( st->ini_frame == 0 ) - { - /* avoid switching of internal ACELP Fs in the very first frame */ - st->last_L_frame = st->L_frame; - } - - if ( st->L_frame == L_FRAME ) - { - st->gamma_flt = GAMMA1_FLT; - st->preemph_fac_flt = PREEMPH_FAC_FLT; - } - else if ( st->L_frame == L_FRAME32k ) - { - st->gamma_flt = GAMMA16k_FLT; - st->preemph_fac_flt = PREEMPH_FAC_SWB_FLT; - } - else - { - st->gamma_flt = GAMMA16k_FLT; - st->preemph_fac_flt = PREEMPH_FAC_16k_FLT; - } - - st->sr_core = st->L_frame * FRAMES_PER_SEC; - st->encoderLookahead_enc = NS2SA( st->sr_core, ACELP_LOOK_NS ); - st->encoderPastSamples_enc = ( st->L_frame * 9 ) >> 4; -#endif /*-----------------------------------------------------------------* * coder_type rewriting in case of switching * IC frames selection * enforce TC frames in case of switching *-----------------------------------------------------------------*/ -#ifdef IVAS_FLOAT_FIXED test(); test(); test(); @@ -415,60 +329,9 @@ ivas_error pre_proc_ivas( st->GSC_noisy_speech = 0; move16(); } -#else - /* enforce TRANSITION frames */ - if ( !( st->element_mode == IVAS_CPE_TD && st->idchan == 1 ) && st->last_L_frame != st->L_frame && st->core_brate != FRAME_NO_DATA && st->core_brate != SID_2k40 && st->last_core_brate != FRAME_NO_DATA && st->last_core_brate != SID_2k40 && st->coder_type_raw != VOICED ) - { - /* enforce TC frame in case of ACELP@12k8 <-> ACELP@16k core switching */ - st->coder_type = TRANSITION; - } - else if ( st->last_core == HQ_CORE && st->coder_type_raw != VOICED ) - { - /* enforce TC frame in case of HQ -> ACELP core switching */ - st->coder_type = TRANSITION; - } - else if ( st->last_core_brate <= SID_2k40 && st->cng_type == FD_CNG && !( element_mode == IVAS_CPE_TD ) ) - { - /* enforce TC frame in case of FD_CNG -> ACELP switching (past excitation not available) */ - st->coder_type = TRANSITION; - } - /* select INACTIVE frames */ - else if ( st->total_brate <= MAX_GSC_INACTIVE_BRATE && st->vad_flag == 0 && st->element_mode != IVAS_CPE_MDCT ) - { - /* inactive frames will be coded by GSC technology */ - /* except for the VBR mode. VBR mode uses NELP for that */ - if ( !( st->Opt_SC_VBR && vad_flag_dtx ) && ( st->idchan == 0 || element_mode != IVAS_CPE_TD ) ) - { - st->coder_type = INACTIVE; - st->hGSCEnc->noise_lev = NOISE_LEVEL_SP3; - } - } - else if ( st->total_brate > MAX_GSC_INACTIVE_BRATE && ( ( st->vad_flag == 0 && st->bwidth >= SWB && st->max_bwidth >= SWB ) || ( st->localVAD == 0 && ( st->bwidth <= WB || st->max_bwidth <= WB ) ) ) ) - { - /* inactive frames will be coded by AVQ technology */ - st->coder_type = INACTIVE; - } - - - /*---------------------------------------------------------------------* - * Decision matrix (selection of technologies) - *---------------------------------------------------------------------*/ - - st->mdct_sw = MODE1; - st->mdct_sw_enable = MODE1; - if ( ( st->total_brate <= MIN_BRATE_GSC_NOISY_FLAG || st->bwidth < SWB || st->flag_ACELP16k ) && st->GSC_IVAS_mode == 0 ) - { - st->GSC_noisy_speech = 0; - } -#endif /* core selection */ -#ifndef IVAS_FLOAT_FIXED - ivas_decision_matrix_enc( st, element_brate, fft_buff, enerBuffer, last_element_mode ); -#else ivas_decision_matrix_enc_fx( st, element_brate, fft_buff_fx, enerBuffer_fx, e_enerBuffer, last_element_mode ); -#endif -#ifdef IVAS_FLOAT_FIXED test(); test(); IF( EQ_16( st->L_frame, L_FRAME16k ) && ( EQ_16( st->coder_type, VOICED ) || EQ_16( st->coder_type, UNVOICED ) ) ) /* VOICED and UNVOICED are not supported in ACELP@16k */ @@ -496,6 +359,7 @@ ivas_error pre_proc_ivas( move32(); st->L_frame = extract_l( Mpy_32_32( st->sr_core, ONE_BY_FRAMES_PER_SEC_Q31 ) ); + move16(); st->encoderLookahead_enc = NS2SA_FX2( st->sr_core, ACELP_LOOK_NS ); st->encoderPastSamples_enc = shr( ( imult1616( st->L_frame, 9 ) ), 4 ); move16(); @@ -674,352 +538,158 @@ ivas_error pre_proc_ivas( *Voicing_flag = 0; move16(); } -#else - if ( st->L_frame == L_FRAME16k && ( st->coder_type == VOICED || st->coder_type == UNVOICED ) ) /* VOICED and UNVOICED are not supported in ACELP@16k */ + + /*-----------------------------------------------------------------* + * Compute core-coder buffers at internal sampling rate + *-----------------------------------------------------------------*/ + IF( st->tcxonly == 0 ) { - st->coder_type = GENERIC; + sr_core_tmp = INT_FS_16k; + move32(); } - - if ( st->core == TCX_20_CORE || st->core == HQ_CORE ) + ELSE { - st->Nb_ACELP_frames = 0; - /* Configure TCX with the same bitrate as given when (re-)initializing TCX */ - total_brate_tmp = st->total_brate; - st->total_brate = st->bits_frame_nominal * FRAMES_PER_SEC; -#ifdef IVAS_FLOAT_FIXED + sr_core_tmp = L_max( INT_FS_16k, st->sr_core ); + } -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - IF( ( NE_32( st->last_bits_frame_nominal * FRAMES_PER_SEC, st->total_brate ) ) || - ( NE_16( st->last_bwidth, st->bwidth ) ) || - ( EQ_16( st->last_codec_mode, MODE1 ) && EQ_16( st->element_mode, EVS_MONO ) ) || - ( ( NE_16( st->last_core, TCX_20_CORE ) && NE_16( st->last_core, TCX_10_CORE ) ) && GT_16( st->element_mode, EVS_MONO ) ) || - ( NE_16( st->rf_mode_last, st->rf_mode ) ) || - ( GT_16( st->element_mode, EVS_MONO ) && st->ini_frame == 0 ) ) - { - Word16 bSwitchFromAmrwbIO = 0, switchWB = 0, fscale; - Word32 sr_core; - move16(); - move16(); + L_look = NS2SA( sr_core_tmp, ACELP_LOOK_NS ); /* lookahead at other sampling rate (16kHz, 25.6kHz, 32kHz) */ + move16(); + + inp_16k = old_inp_16k + L_INP_MEM - L_look; - IF( EQ_16( st->last_core, AMR_WB_CORE ) ) - { - bSwitchFromAmrwbIO = 1; - move16(); - } - sr_core = getCoreSamplerateMode2( st->element_mode, st->total_brate, st->bwidth, st->flag_ACELP16k, st->rf_mode, st->is_ism_format ); - fscale = sr2fscale_fx( sr_core ); - IF( EQ_32( fscale, st->fscale ) && !bSwitchFromAmrwbIO && !switchWB ) - { - st->hTcxCfg->bandwidth_flt = getTcxBandwidth_flt( st->bwidth ); - } - IF( st->envWeighted && !st->enableTcxLpc ) - { - /* Unweight the envelope */ - floatToFixed_arr( st->lsp_old, st->lsp_old_fx, Q15, M ); - st->gamma = (Word16) floatToFixed( st->gamma_flt, Q14 ); - } - } -#endif - SetModeIndex_ivas_fx( st, st->last_bits_frame_nominal * FRAMES_PER_SEC, last_element_mode, MCT_flag ); #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - IF( st->envWeighted && !st->enableTcxLpc ) - { - fixedToFloat_arr( st->lsp_old_fx, st->lsp_old, Q15, M ); - fixedToFloat_arr( st->lsf_old_fx, st->lsf_old, Q15, M ); - } -#endif -#else - SetModeIndex( st, st->last_bits_frame_nominal * FRAMES_PER_SEC, last_element_mode, MCT_flag ); -#endif + Word16 old_inp_16k_fx[L_INP], Q_old_inp_16k = -1; + Word32 ener_fx = 0; + Word16 new_inp_resamp16k_fx[L_FRAME16k]; + Word16 Q_r[2] = { 0 }, exp_wsp; + Word32 epsP_fx[M + 1] = { 0 }; + Word16 old_wsp_fx[L_WSP], wsp_fx[L_FRAME + L_LOOK_12k8]; + floatToFixed_arr16( st->input, st->input_fx, -1, 960 ); + inp_16k_fx = old_inp_16k_fx + L_INP_MEM - L_look; - st->sr_core = getCoreSamplerateMode2_flt( element_mode, st->total_brate, st->bwidth, st->flag_ACELP16k, st->rf_mode, st->is_ism_format ); - st->total_brate = total_brate_tmp; + st->mem_preemph_enc = (Word16) floatToFixed( st->mem_preemph_enc_flt, Q_old_inp_16k ); + st->mem_preemph16k_fx = (Word16) floatToFixed( st->mem_preemph16k, Q_old_inp_16k ); + st->mem_preemph16k_DFT_fx = (Word16) floatToFixed( st->mem_preemph16k_DFT, Q_old_inp_16k ); + st->mem_wsp_enc = (Word16) floatToFixed( st->mem_wsp_enc_flt, Q_old_inp_16k ); - st->L_frame = (int16_t) ( st->sr_core / FRAMES_PER_SEC ); - st->encoderLookahead_enc = NS2SA( st->sr_core, ACELP_LOOK_NS ); - st->encoderPastSamples_enc = ( st->L_frame * 9 ) >> 4; + floatToFixed_arr16( old_inp_16k, old_inp_16k_fx, Q_old_inp_16k, L_INP ); + floatToFixed_arr16( wsp, wsp_fx, Q_old_inp_16k, (Word16) ( L_FRAME + L_LOOK_12k8 ) ); + f2me_buf_16( old_wsp, old_wsp_fx, &exp_wsp, L_WSP ); + f2me_buf_16( st->old_inp_12k8, st->old_inp_12k8_fx, &st->exp_old_inp_12k8, 240 ); + floatToFixed_arr16( st->old_inp_16k, st->old_inp_16k_fx, Q_old_inp_16k, L_INP_MEM ); + floatToFixed_arr16( st->mem_decim16k, st->mem_decim16k_fx, Q_old_inp_16k, 2 * L_FILT_MAX ); + floatToFixed_arr16( st->inp_16k_mem_stereo_sw, st->inp_16k_mem_stereo_sw_fx, Q_old_inp_16k, STEREO_DFT_OVL_16k - L_MEM_RECALC_16K - L_FILT16k ); + floatToFixed_arr16( st->buf_speech_enc_flt, st->buf_speech_enc, Q_old_inp_16k, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k ); + floatToFixed_arr16( st->buf_speech_enc_pe_flt, st->buf_speech_enc_pe, Q_old_inp_16k, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k ); // Should take care of st->speech_enc_pe as wel + floatToFixed_arr16( st->buf_wspeech_enc_flt, st->buf_wspeech_enc, Q_old_inp_16k, L_FRAME16k + L_SUBFR + L_FRAME16k + L_NEXT_MAX_16k + 320 ); // Should take care of st->wspeech_enc + // wspeech_enc - if ( st->sr_core == INT_FS_12k8 ) - { - st->preemph_fac_flt = PREEMPH_FAC_FLT; - st->gamma_flt = GAMMA1_FLT; - } - else if ( st->sr_core == INT_FS_16k ) - { - st->preemph_fac_flt = PREEMPH_FAC_16k_FLT; - st->gamma_flt = GAMMA16k_FLT; - } - else /* st->sr_core >=25600 */ + if ( st->hBWE_FD != NULL ) + { + floatToFixed_arr16( st->hBWE_FD->old_wtda_swb, st->hBWE_FD->L_old_wtda_swb_fx, Q_old_inp_16k, L_FRAME48k ); + st->Q_old_wtda = -1; // This reset needs to be looked into + } +#endif + IF( !flag_16k_smc ) + { + error = ivas_compute_core_buffers_fx( st, &inp_16k_fx, old_inp_16k_fx, new_inp_resamp16k_fx, input_frame, last_element_mode, sr_core_tmp, &ener_fx, + A_fx, Aw_fx, + epsP_fx, + lsp_new_fx, lsp_mid_fx, Q_old_inp_16k, Q_r ); + IF( NE_32( error, IVAS_ERR_OK ) ) { - st->preemph_fac_flt = PREEMPH_FAC_SWB_FLT; - st->gamma_flt = GAMMA16k_FLT; + return error; } + } + test(); + IF( !( EQ_16( st->L_frame, L_FRAME16k ) && NE_16( element_mode, IVAS_CPE_MDCT ) ) ) + { + /* update signal buffers */ + Copy( new_inp_12k8_fx, st->buf_speech_enc_pe + st->L_frame, L_FRAME ); + Copy( st->buf_speech_enc + L_FRAME32k, st->buf_speech_enc + st->L_frame, L_FRAME ); - if ( st->vad_flag == 0 ) - { - st->coder_type = INACTIVE; - } - else if ( st->coder_type > GENERIC ) + test(); + IF( EQ_16( element_mode, IVAS_CPE_DFT ) ) { - st->coder_type = GENERIC; + Copy( st->buf_speech_enc + L_FRAME32k - STEREO_DFT_OVL_12k8, st->buf_speech_enc + st->L_frame - STEREO_DFT_OVL_12k8, STEREO_DFT_OVL_12k8 ); } - if ( st->element_mode != IVAS_CPE_MDCT ) + ELSE IF( EQ_16( element_mode, IVAS_CPE_TD ) || EQ_16( element_mode, IVAS_CPE_MDCT ) ) { - SetTCXModeInfo( st, st->hTranDet, &st->hTcxCfg->tcx_curr_overlap_mode ); + Copy( st->buf_speech_enc + L_FRAME32k - lMemRecalc_12k8 - L_FILT, st->buf_speech_enc + st->L_frame - lMemRecalc_12k8 - L_FILT, lMemRecalc_12k8 + L_FILT ); } - } - else if ( st->element_mode == IVAS_CPE_MDCT ) - { - st->hTcxEnc->tfm_mem = 0.75f; - } - else if ( element_brate != last_element_brate ) - { - if ( st->core_brate != FRAME_NO_DATA ) + ELSE IF( EQ_16( element_mode, IVAS_SCE ) ) { -#ifdef IVAS_FLOAT_FIXED -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - IF( ( NE_32( imult1616( st->last_bits_frame_nominal, FRAMES_PER_SEC ), st->total_brate ) ) || - ( NE_16( st->last_bwidth, st->bwidth ) ) || - ( EQ_16( st->last_codec_mode, MODE1 ) && EQ_16( st->element_mode, EVS_MONO ) ) || - ( ( NE_16( st->last_core, TCX_20_CORE ) && NE_16( st->last_core, TCX_10_CORE ) ) && GT_16( st->element_mode, EVS_MONO ) ) || - ( NE_16( st->rf_mode_last, st->rf_mode ) ) || - ( GT_16( st->element_mode, EVS_MONO ) && st->ini_frame == 0 ) ) - { - Word16 bSwitchFromAmrwbIO = 0, switchWB = 0, fscale; - Word32 sr_core; - move16(); - move16(); - - IF( EQ_16( st->last_core, AMR_WB_CORE ) ) - { - bSwitchFromAmrwbIO = 1; - move16(); - } - sr_core = getCoreSamplerateMode2( st->element_mode, st->total_brate, st->bwidth, st->flag_ACELP16k, st->rf_mode, st->is_ism_format ); - fscale = sr2fscale_fx( sr_core ); - IF( EQ_32( fscale, st->fscale ) && !bSwitchFromAmrwbIO && !switchWB ) - { - st->hTcxCfg->bandwidth_flt = getTcxBandwidth_flt( st->bwidth ); - } - IF( st->envWeighted && !st->enableTcxLpc ) - { - /* Unweight the envelope */ - floatToFixed_arr( st->lsp_old, st->lsp_old_fx, Q15, M ); - st->gamma = (Word16) floatToFixed( st->gamma_flt, Q14 ); - } - } -#endif - SetModeIndex_ivas_fx( st, st->bits_frame_nominal * FRAMES_PER_SEC, element_mode, MCT_flag ); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - IF( st->envWeighted && !st->enableTcxLpc ) - { - fixedToFloat_arr( st->lsp_old_fx, st->lsp_old, Q15, M ); - fixedToFloat_arr( st->lsf_old_fx, st->lsf_old, Q15, M ); - } -#endif -#else - SetModeIndex( st, st->bits_frame_nominal * FRAMES_PER_SEC, element_mode, MCT_flag ); -#endif + Copy( st->buf_speech_enc + L_FRAME32k - L_FILT, st->buf_speech_enc + st->L_frame - L_FILT, L_FILT ); } - if ( st->extl != -1 && st->extl != IGF_BWE && st->igf == 1 ) + IF( st->tcxonly == 0 ) { - st->igf = 0; + Copy( wsp_fx, st->wspeech_enc, L_FRAME + L_LOOK_12k8 ); } } + IF( flag_16k_smc ) + { + Copy( st->buf_speech_enc + L_FRAME16k, new_inp_resamp16k_fx, L_FRAME16k ); + } /*-----------------------------------------------------------------* - * Update of ACELP harmonicity counter (used in ACELP transform codebook @32kbps) + * Updates *-----------------------------------------------------------------*/ - if ( loc_harm == 1 && cor_map_sum > 50 && st->clas == VOICED_CLAS && st->coder_type == GENERIC ) - { - st->last_harm_flag_acelp++; + /* update old weighted speech buffer - for OL pitch analysis */ + Copy( &old_wsp_fx[L_FRAME], st->old_wsp_fx, L_WSP_MEM ); + st->exp_old_wsp = exp_wsp; + move16(); - if ( st->last_harm_flag_acelp > 10 ) - { - st->last_harm_flag_acelp = 10; - } - } - else +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + // No need to do fixed to float for signal_in_fx + st->mem_preemph_enc_flt = fixedToFloat_16( st->mem_preemph_enc, Q_old_inp_16k ); + st->mem_preemph16k = fixedToFloat_16( st->mem_preemph16k_fx, Q_old_inp_16k ); + st->mem_preemph16k_DFT = fixedToFloat_16( st->mem_preemph16k_DFT_fx, Q_old_inp_16k ); + st->mem_wsp_enc_flt = fixedToFloat_16( st->mem_wsp_enc, Q_old_inp_16k ); + + if ( st->L_frame == L_FRAME16k && element_mode != IVAS_CPE_MDCT ) { - st->last_harm_flag_acelp = 0; + *ener = fixedToFloat( ener_fx, Q_r[0] + 1 ); } - /*-----------------------------------------------------------------* - * Update audio frames counter (used for UV decision) - *-----------------------------------------------------------------*/ + fixedToFloat_arr( old_inp_16k_fx, old_inp_16k, Q_old_inp_16k, L_INP ); + fixedToFloat_arr( new_inp_resamp16k_fx, new_inp_resamp16k, Q_old_inp_16k, L_FRAME16k ); + fixedToFloat_arr( st->input_fx, st->input, -1, 960 ); + fixedToFloat_arr( st->old_wsp_fx, st->old_wsp, 15 - st->exp_old_wsp, L_WSP_MEM ); + + fixedToFloat_arr( st->old_inp_16k_fx, st->old_inp_16k, Q_old_inp_16k, L_INP_MEM ); + fixedToFloat_arr( st->mem_decim16k_fx, st->mem_decim16k, Q_old_inp_16k, 2 * L_FILT_MAX ); + fixedToFloat_arr( st->inp_16k_mem_stereo_sw_fx, st->inp_16k_mem_stereo_sw, Q_old_inp_16k, STEREO_DFT_OVL_16k - L_MEM_RECALC_16K - L_FILT16k ); + fixedToFloat_arr( st->buf_speech_enc, st->buf_speech_enc_flt, Q_old_inp_16k, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k ); + fixedToFloat_arr( st->buf_speech_enc_pe, st->buf_speech_enc_pe_flt, Q_old_inp_16k, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k ); // Should take care of st->speech_enc_pe as wel + fixedToFloat_arr( st->buf_wspeech_enc, st->buf_wspeech_enc_flt, Q_old_inp_16k, L_FRAME16k + L_SUBFR + L_FRAME16k + L_NEXT_MAX_16k + 320 ); // Should take care of st->wspeech_enc - if ( st->coder_type == AUDIO ) + if ( st->hBWE_FD != NULL ) { - st->audio_frame_cnt += AUDIO_COUNTER_STEP; + fixedToFloat_arr( st->hBWE_FD->L_old_wtda_swb_fx, st->hBWE_FD->old_wtda_swb, st->Q_old_wtda, L_FRAME48k ); } - else if ( st->coder_type != INACTIVE ) + + if ( st->L_frame == L_FRAME16k && element_mode != IVAS_CPE_MDCT ) { - st->audio_frame_cnt--; + fixedToFloat_arrL( epsP_fx, epsP, Q_r[0] + 1, M + 1 ); } - - if ( st->audio_frame_cnt > AUDIO_COUNTER_MAX ) +#endif + /* set the pointer of the current frame for the ACELP core */ + IF( EQ_16( st->L_frame, L_FRAME ) ) { - st->audio_frame_cnt = AUDIO_COUNTER_MAX; + *inp = inp_12k8; } - - if ( st->audio_frame_cnt < 0 ) + ELSE { - st->audio_frame_cnt = 0; - } - - /*-----------------------------------------------------------------* - * Set formant sharpening flag - *-----------------------------------------------------------------*/ - - st->sharpFlag = 0; - - if ( st->coder_type == GENERIC || st->coder_type == VOICED || st->coder_type == TRANSITION ) - { - if ( element_brate >= FRMT_SHP_MIN_BRATE_IVAS && st->lp_noise > FORMANT_SHARPENING_NOISE_THRESHOLD ) - { - st->sharpFlag = 0; - } - else - { - st->sharpFlag = 1; - } - } - - /* channel-aware mode - due to lack of signaling bit, sharpFlag is 1 always in RF mode */ - if ( st->rf_mode && ( st->coder_type == VOICED || st->coder_type == GENERIC ) ) - { - st->sharpFlag = 1; - } - - /* TD stereo, secondary channel - due to lack of signaling bits, sharpFlag is always 1 */ - if ( element_mode == IVAS_CPE_TD && st->idchan == 1 ) - { - st->sharpFlag = 0; - if ( st->coder_type == GENERIC || st->coder_type == VOICED ) - { - st->sharpFlag = 1; - } - } - - /*-----------------------------------------------------------------* - * Set voicing flag for HQ FEC - *-----------------------------------------------------------------*/ - - if ( st->sp_aud_decision1 == 0 && ( st->coder_type == VOICED || st->coder_type == GENERIC ) ) - { - *Voicing_flag = 1; - } - else - { - *Voicing_flag = 0; - } -#endif - - /*-----------------------------------------------------------------* - * Compute core-coder buffers at internal sampling rate - *-----------------------------------------------------------------*/ - - sr_core_tmp = ( st->tcxonly == 0 ) ? INT_FS_16k : max( INT_FS_16k, st->sr_core ); /* indicates the ACELP sampling rate */ - - L_look = NS2SA( sr_core_tmp, ACELP_LOOK_NS ); /* lookahead at other sampling rate (16kHz, 25.6kHz, 32kHz) */ - - inp_16k = old_inp_16k + L_INP_MEM - L_look; - - if ( !flag_16k_smc ) - { -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS -#endif - error = ivas_compute_core_buffers( st, &inp_16k, old_inp_16k, new_inp_resamp16k, input_frame, last_element_mode, sr_core_tmp, ener, -#ifndef IVAS_FLOAT_FIXED - A, Aw, -#else - A_fx, Aw_fx, -#endif - epsP, -#ifndef IVAS_FLOAT_FIXED - lsp_new, lsp_mid -#else - lsp_new_fx, lsp_mid_fx -#endif - ); - if ( error != IVAS_ERR_OK ) - { - return error; - } - } - - if ( !( st->L_frame == L_FRAME16k && element_mode != IVAS_CPE_MDCT ) ) - { - /* update signal buffers */ - mvr2r( new_inp_12k8, st->buf_speech_enc_pe_flt + st->L_frame, L_FRAME ); - mvr2r( st->buf_speech_enc_flt + L_FRAME32k, st->buf_speech_enc_flt + st->L_frame, L_FRAME ); - - if ( element_mode == IVAS_CPE_DFT ) - { - mvr2r( st->buf_speech_enc_flt + L_FRAME32k - STEREO_DFT_OVL_12k8, st->buf_speech_enc_flt + st->L_frame - STEREO_DFT_OVL_12k8, STEREO_DFT_OVL_12k8 ); - } - else if ( element_mode == IVAS_CPE_TD || element_mode == IVAS_CPE_MDCT ) - { - mvr2r( st->buf_speech_enc_flt + L_FRAME32k - lMemRecalc_12k8 - L_FILT, st->buf_speech_enc_flt + st->L_frame - lMemRecalc_12k8 - L_FILT, lMemRecalc_12k8 + L_FILT ); - } - else if ( element_mode == IVAS_SCE ) - { - mvr2r( st->buf_speech_enc_flt + L_FRAME32k - L_FILT, st->buf_speech_enc_flt + st->L_frame - L_FILT, L_FILT ); - } - - if ( st->tcxonly == 0 ) - { - mvr2r( wsp, st->wspeech_enc_flt, L_FRAME + L_LOOK_12k8 ); - } - } - - if ( flag_16k_smc ) - { - mvr2r( st->buf_speech_enc_flt + L_FRAME16k, new_inp_resamp16k, L_FRAME16k ); - } - - /*-----------------------------------------------------------------* - * Updates - *-----------------------------------------------------------------*/ - - /* update old weighted speech buffer - for OL pitch analysis */ - mvr2r( &old_wsp[L_FRAME], st->old_wsp, L_WSP_MEM ); - - - /* set the pointer of the current frame for the ACELP core */ - if ( st->L_frame == L_FRAME ) - { - *inp = inp_12k8; - } - else - { - *inp = inp_16k; + *inp = inp_16k; } /* Update VAD hangover frame counter in active frames */ -#ifdef IVAS_FLOAT_FIXED test(); test(); - IF( !( EQ_32( st->core_brate, SID_2k40 ) || EQ_32( st->core_brate, FRAME_NO_DATA ) ) && st->tcxonly == 0 ) + IF( !( EQ_32( st->core_brate, SID_2k40 ) || ( st->core_brate == FRAME_NO_DATA ) ) && st->tcxonly == 0 ) { test(); test(); @@ -1028,7 +698,7 @@ ivas_error pre_proc_ivas( { st->hTdCngEnc->burst_ho_cnt = add( st->hTdCngEnc->burst_ho_cnt, 1 ); move16(); - IF( GT_16( st->hTdCngEnc->burst_ho_cnt, HO_HIST_SIZE ) ) + if ( GT_16( st->hTdCngEnc->burst_ho_cnt, HO_HIST_SIZE ) ) { st->hTdCngEnc->burst_ho_cnt = HO_HIST_SIZE; move16(); @@ -1040,23 +710,7 @@ ivas_error pre_proc_ivas( move16(); } } -#else - if ( !( st->core_brate == SID_2k40 || st->core_brate == FRAME_NO_DATA ) && st->tcxonly == 0 ) - { - if ( st->hTdCngEnc != NULL && st->Opt_DTX_ON && vad_hover_flag ) - { - st->hTdCngEnc->burst_ho_cnt++; - if ( st->hTdCngEnc->burst_ho_cnt > HO_HIST_SIZE ) - { - st->hTdCngEnc->burst_ho_cnt = HO_HIST_SIZE; - } - } - else if ( st->hTdCngEnc != NULL && vad_flag_dtx ) - { - st->hTdCngEnc->burst_ho_cnt = 0; - } - } -#endif + #ifdef IVAS_FLOAT_FIXED_CONVERSIONS fixedToFloat_arr( A_fx, A, Q14 - norm_s( A_fx[0] ), NB_SUBFR16k * ( M + 1 ) ); @@ -1075,165 +729,86 @@ ivas_error pre_proc_ivas( * * Compute core-coder buffers at internal sampling rate *--------------------------------------------------------------------*/ - -ivas_error ivas_compute_core_buffers( - Encoder_State *st, /* i/o: encoder state structure */ - float **inp16k_out, /* o : ptr. to inp. signal in the current frame */ - float *old_inp_16k, /* i/o: buffer of old input signal @ 16kHz */ - float new_inp_resamp16k_out[], /* o : new input signal @16kHz, non pre-emphasised, used by the WB TBE/BWE */ - const int16_t input_frame, /* i : frame length */ - const int16_t last_element_mode, /* i : last element mode */ - const int32_t sr_core, /* i : core-coder sampling rate */ - float *ener, /* o : residual energy from Levinson-Durbin */ -#ifndef IVAS_FLOAT_FIXED - float A[NB_SUBFR16k * ( M + 1 )], /* i/o: A(z) unquantized for the 4 subframes */ - float Aw[NB_SUBFR16k * ( M + 1 )], /* i/o: weighted A(z) unquantized for subframes */ -#else - Word16 A_fx[NB_SUBFR16k * ( M + 1 )], /* i/o: A(z) unquantized for the 4 subframes */ - Word16 Aw_fx[NB_SUBFR16k * ( M + 1 )], /* i/o: weighted A(z) unquantized for subframes */ -#endif - float epsP[M + 1], /* i/o: LP prediction errors */ -#ifndef IVAS_FLOAT_FIXED - float lsp_new[M], /* i/o: LSPs at the end of the frame */ - float lsp_mid[M] /* i/o: LSPs in the middle of the frame */ -#else - Word16 lsp_new_fx[M], /* i/o: LSPs at the end of the frame */ - Word16 lsp_mid_fx[M] /* i/o: LSPs in the middle of the frame */ -#endif -) +ivas_error ivas_compute_core_buffers_fx( + Encoder_State *st, /* i/o: encoder state structure */ + Word16 **inp16k_out_fx, /* o : ptr. to inp. signal in the current frame */ + Word16 *old_inp_16k_fx, /* i/o: buffer of old input signal @ 16kHz */ + Word16 new_inp_resamp16k_out_fx[], /* o : new input signal @16kHz, non pre-emphasised, used by the WB TBE/BWE */ + const Word16 input_frame, /* i : frame length */ + const Word16 last_element_mode, /* i : last element mode */ + const Word32 sr_core, /* i : core-coder sampling rate */ + Word32 *ener_fx, /* o : residual energy from Levinson-Durbin */ + Word16 A_fx[NB_SUBFR16k * ( M + 1 )], /* i/o: A(z) unquantized for the 4 subframes */ + Word16 Aw_fx[NB_SUBFR16k * ( M + 1 )], /* i/o: weighted A(z) unquantized for subframes */ + Word32 epsP_fx[M + 1], /* i/o: LP prediction errors */ + Word16 lsp_new_fx[M], /* i/o: LSPs at the end of the frame */ + Word16 lsp_mid_fx[M], /* i/o: LSPs in the middle of the frame */ + Word16 Q_old_inp_16k, + Word16 Q_r[2] ) { - float *inp_16k, *new_inp_16k; -#ifndef IVAS_FLOAT_FIXED - float tmp; - float mem_decim16k_dummy[2 * L_FILT_MAX]; -#endif - /*const*/ float *signal_in; - int16_t delay, element_mode; -#ifdef IVAS_FLOAT_FIXED + Word16 *inp_16k_fx, *new_inp_16k_fx; + Word16 delay, element_mode; Word16 temp1F_icatdmResampBuf_fx[L_FILT_MAX]; /* temp buffers for ICA TDM resamplers */ Word16 mem_decim16k_dummy_fx[2 * L_FILT_MAX]; - Word32 *signal_in_32fx; Word16 *signal_in_fx; -#else - float temp1F_icatdmResampBuf[L_FILT_MAX]; /* temp buffers for ICA TDM resamplers */ -#endif - float new_inp_resamp16k[L_FRAME16k]; - int16_t lMemRecalc, lMemRecalc_16k, L_frame_tmp, L_look; - int32_t input_Fs; + Word16 lMemRecalc, lMemRecalc_16k, L_frame_tmp, L_look; + Word32 input_Fs; - signal_in = st->input; -#ifdef IVAS_FLOAT_FIXED -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS Word16 new_inp_resamp16k_fx[L_FRAME16k], tmp_fx; Word16 Q_tmp, mem_decim16k_size, size_modified; - Word16 old_inp_16k_fx[L_INP]; - // Word16 Q_old_inp_16k = 0; - Word16 Q_old_inp_16k = -1; - Word16 *inp_16k_fx, *new_inp_16k_fx; - Word32 epsP_fx[M + 1]; - Word16 epsP_h[M + 1] = { 0 }; - Word16 epsP_l[M + 1] = { 0 }; - Word16 Q_r[2] = { 0 }; - Word32 ener_fx = 0; - Word16 inp16k_out_buf_fx[2][L_FRAME16k]; - Word16 **inp16k_out_fx = (Word16 **) inp16k_out_buf_fx; - Word16 new_inp_resamp16k_out_fx[L_FRAME16k]; + Word16 epsP_h[M + 1]; + Word16 epsP_l[M + 1]; #ifdef MSAN_FIX set16_fx( new_inp_resamp16k_fx, 0, L_FRAME16k ); #endif - signal_in_32fx = st->input32_fx; + set16_fx( epsP_h, 0, M + 1 ); + set16_fx( epsP_l, 0, M + 1 ); signal_in_fx = st->input_fx; - /* - !!!! ALL BUFFERS CONSIDERED IN Q(-1) for now !!!! - */ - // st->mem_preemph_enc = float_to_fix16( st->mem_preemph_enc_flt, Q_old_inp_16k ); - // st->mem_preemph16k_fx = float_to_fix16( st->mem_preemph16k, Q_old_inp_16k ); - // st->mem_preemph16k_DFT_fx = float_to_fix16( st->mem_preemph16k_DFT, Q_old_inp_16k ); - // st->mem_wsp_enc = float_to_fix16( st->mem_wsp_enc_flt, Q_old_inp_16k ); - - st->mem_preemph_enc = (Word16) floatToFixed( st->mem_preemph_enc_flt, Q_old_inp_16k ); - st->mem_preemph16k_fx = (Word16) floatToFixed( st->mem_preemph16k, Q_old_inp_16k ); - st->mem_preemph16k_DFT_fx = (Word16) floatToFixed( st->mem_preemph16k_DFT, Q_old_inp_16k ); - st->mem_wsp_enc = (Word16) floatToFixed( st->mem_wsp_enc_flt, Q_old_inp_16k ); - - floatToFixed_arrL( signal_in, signal_in_32fx, Q11, 960 ); - - floatToFixed_arr16( old_inp_16k, old_inp_16k_fx, Q_old_inp_16k, L_INP ); - floatToFixed_arr16( signal_in, signal_in_fx, Q_old_inp_16k, 960 ); -#ifndef MSAN_FIX - floatToFixed_arr16( new_inp_resamp16k, new_inp_resamp16k_fx, Q_old_inp_16k, L_FRAME16k ); -#endif - - f2me_buf_16( st->old_inp_12k8, st->old_inp_12k8_fx, &st->exp_old_inp_12k8, 240 ); - floatToFixed_arr16( st->old_inp_16k, st->old_inp_16k_fx, Q_old_inp_16k, L_INP_MEM ); - floatToFixed_arr16( st->mem_decim16k, st->mem_decim16k_fx, Q_old_inp_16k, 2 * L_FILT_MAX ); - floatToFixed_arr16( st->inp_16k_mem_stereo_sw, st->inp_16k_mem_stereo_sw_fx, Q_old_inp_16k, STEREO_DFT_OVL_16k - L_MEM_RECALC_16K - L_FILT16k ); - floatToFixed_arr16( st->buf_speech_enc_flt, st->buf_speech_enc, Q_old_inp_16k, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k ); - floatToFixed_arr16( st->buf_speech_enc_pe_flt, st->buf_speech_enc_pe, Q_old_inp_16k, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k ); // Should take care of st->speech_enc_pe as wel - floatToFixed_arr16( st->buf_wspeech_enc_flt, st->buf_wspeech_enc, Q_old_inp_16k, L_FRAME16k + L_SUBFR + L_FRAME16k + L_NEXT_MAX_16k + 320 ); // Should take care of st->wspeech_enc - // wspeech_enc - - if ( st->hBWE_FD != NULL ) - { - floatToFixed_arr16( st->hBWE_FD->old_wtda_swb, st->hBWE_FD->L_old_wtda_swb_fx, Q_old_inp_16k, L_FRAME48k ); - st->Q_old_wtda = -1; // This reset needs to be looked into - } -#endif -#endif - input_Fs = st->input_Fs; + move32(); element_mode = st->element_mode; + move16(); lMemRecalc_16k = 0; + move16(); lMemRecalc = 0; + move16(); IF( EQ_16( element_mode, IVAS_CPE_TD ) ) { lMemRecalc_16k = NS2SA( INT_FS_16k, L_MEM_RECALC_NS ); + move16(); lMemRecalc = NS2SA( input_Fs, L_MEM_RECALC_NS ); + move16(); } /*---------------------------------------------------------------* * Preprocessing at other sampling frequency rate (16/25.6/32kHz) *----------------------------------------------------------------*/ + IF( st->tcxonly == 0 ) + { - L_frame_tmp = ( st->tcxonly == 0 ) ? L_FRAME16k : max( L_FRAME16k, st->L_frame ); + L_frame_tmp = L_FRAME16k; + move16(); + } + ELSE + { + L_frame_tmp = s_max( L_FRAME16k, st->L_frame ); + } L_look = NS2SA( sr_core, ACELP_LOOK_NS ); /* lookahead at other sampling rate (16kHz, 25.6kHz, 32kHz) */ + move16(); new_inp_16k_fx = old_inp_16k_fx + L_INP_MEM; /* pointer to new samples of the input signal in 16kHz core */ -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - new_inp_16k = old_inp_16k + L_INP_MEM; /* pointer to new samples of the input signal in 16kHz core */ -#endif - inp_16k_fx = new_inp_16k_fx - L_look; /* pointer to the current frame of input signal in 16kHz core */ -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - inp_16k = new_inp_16k - L_look; /* pointer to the current frame of input signal in 16kHz core */ -#endif + inp_16k_fx = new_inp_16k_fx - L_look; /* pointer to the current frame of input signal in 16kHz core */ /* shift the pointer back to take care of resampler memory update */ test(); IF( EQ_16( element_mode, IVAS_CPE_TD ) || EQ_16( element_mode, IVAS_SCE ) ) { -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - new_inp_16k -= NS2SA( sr_core, DELAY_FIR_RESAMPL_NS ); -#endif new_inp_16k_fx -= NS2SA( sr_core, DELAY_FIR_RESAMPL_NS ); } -#ifndef IVAS_FLOAT_FIXED - if ( element_mode == IVAS_CPE_DFT ) - { - mvr2r( st->old_inp_16k, old_inp_16k, L_INP_MEM - STEREO_DFT_OVL_16k ); - } - else if ( element_mode == IVAS_CPE_TD ) - { - mvr2r( st->old_inp_16k, old_inp_16k, L_INP_MEM - L_MEM_RECALC_16K - L_FILT16k ); - } - else - { - mvr2r( st->old_inp_16k, old_inp_16k, L_INP_MEM - L_FILT16k ); - } -#else IF( EQ_16( element_mode, IVAS_CPE_DFT ) ) { Copy( st->old_inp_16k_fx, old_inp_16k_fx, L_INP_MEM - STEREO_DFT_OVL_16k ); @@ -1246,353 +821,11 @@ ivas_error ivas_compute_core_buffers( { Copy( st->old_inp_16k_fx, old_inp_16k_fx, L_INP_MEM - L_FILT16k ); } -#endif /*---------------------------------------------------------------* * Change the sampling frequency to 16/25.6/32 kHz *----------------------------------------------------------------*/ -#ifndef IVAS_FLOAT_FIXED - if ( element_mode == IVAS_SCE ) - { - if ( input_Fs == sr_core ) - { - /* no resampling needed, only delay adjustment to account for the FIR resampling delay */ - delay = NS2SA( input_Fs, DELAY_FIR_RESAMPL_NS ); - mvr2r( st->mem_decim16k + delay, new_inp_16k, delay ); - mvr2r( signal_in, new_inp_16k + delay, input_frame ); - mvr2r( signal_in + input_frame - 2 * delay, st->mem_decim16k, 2 * delay ); - } - else if ( input_Fs == 32000 || input_Fs == 48000 ) - { - modify_Fs( signal_in, input_frame, input_Fs, new_inp_16k, sr_core, st->mem_decim16k, 0 ); - - mvr2r( st->mem_decim16k, mem_decim16k_dummy, 2 * L_FILT_MAX ); - set_f( temp1F_icatdmResampBuf, 0, L_FILT_MAX ); - modify_Fs( temp1F_icatdmResampBuf, NS2SA( input_Fs, DELAY_FIR_RESAMPL_NS ), input_Fs, new_inp_16k + NS2SA( sr_core, FRAME_SIZE_NS ), sr_core, mem_decim16k_dummy, 0 ); - } - } - else if ( element_mode == IVAS_CPE_TD ) - { - if ( input_Fs == sr_core ) - { - /* no resampling needed, only delay adjustment to account for the FIR resampling delay */ - delay = NS2SA( input_Fs, DELAY_FIR_RESAMPL_NS ); - mvr2r( st->mem_decim16k + delay, new_inp_16k - lMemRecalc - delay + L_FILT16k, delay ); - mvr2r( signal_in - lMemRecalc, new_inp_16k - lMemRecalc + L_FILT16k, input_frame + lMemRecalc ); - mvr2r( signal_in + input_frame - lMemRecalc - 2 * delay, st->mem_decim16k, 2 * delay ); - } - else if ( input_Fs == 32000 || input_Fs == 48000 ) - { - /* reconstruct past segment of input signal when switching from MDCT stereo */ - if ( last_element_mode == IVAS_CPE_MDCT /*|| st->idchan == 1*/ ) - { - int16_t length_inp = NS2SA( input_Fs, L_MEM_RECALC_SCH_NS - DELAY_FIR_RESAMPL_NS ); - int16_t length_16k = NS2SA( INT_FS_16k, L_MEM_RECALC_SCH_NS - DELAY_FIR_RESAMPL_NS ); - - mvr2r( signal_in - lMemRecalc - length_inp - 2 * NS2SA( input_Fs, DELAY_FIR_RESAMPL_NS ), st->mem_decim16k, 2 * NS2SA( input_Fs, DELAY_FIR_RESAMPL_NS ) ); - modify_Fs( signal_in - lMemRecalc - length_inp, length_inp, input_Fs, new_inp_16k - lMemRecalc_16k - length_16k, sr_core, st->mem_decim16k, 0 ); - } - - modify_Fs( signal_in - lMemRecalc, input_frame, input_Fs, new_inp_16k - ( lMemRecalc * sr_core ) / st->input_Fs, sr_core, st->mem_decim16k, 0 ); - mvr2r( st->mem_decim16k, mem_decim16k_dummy, 2 * L_FILT_MAX ); - - if ( lMemRecalc > 0 ) - { - modify_Fs( signal_in - lMemRecalc + input_frame, lMemRecalc, input_Fs, new_inp_16k + NS2SA( sr_core, FRAME_SIZE_NS ) - ( lMemRecalc * sr_core ) / st->input_Fs, sr_core, mem_decim16k_dummy, 0 ); - } - - set_f( temp1F_icatdmResampBuf, 0, L_FILT_MAX ); - modify_Fs( temp1F_icatdmResampBuf, NS2SA( input_Fs, DELAY_FIR_RESAMPL_NS ), input_Fs, new_inp_16k + NS2SA( sr_core, FRAME_SIZE_NS ), sr_core, mem_decim16k_dummy, 0 ); - } - } - else if ( st->idchan == 0 ) - { - /* update the FIR resampling filter memory, needed for switching to time-domain (FIR) resampling */ - mvr2r( signal_in + input_frame - NS2SA( input_Fs, L_MEM_RECALC_NS ) - 2 * NS2SA( input_Fs, DELAY_FIR_RESAMPL_NS ), st->mem_decim16k, 2 * NS2SA( input_Fs, DELAY_FIR_RESAMPL_NS ) ); - } - - /*------------------------------------------------* - * Update BWE memories * - *------------------------------------------------*/ - - if ( sr_core == INT_FS_16k && element_mode != IVAS_CPE_MDCT ) - { - delay = NS2SA( INT_FS_16k, DELAY_FD_BWE_ENC_12k8_NS ); - - if ( element_mode == IVAS_CPE_DFT ) - { - /* save input resampled at 16kHz, non-preemphasised.*/ - mvr2r( new_inp_16k, new_inp_resamp16k, L_FRAME16k ); - - if ( st->bwidth == WB ) - { - mvr2r( new_inp_16k - delay, st->hBWE_FD->old_input_wb, delay ); - mvr2r( new_inp_16k - STEREO_DFT_OVL_16k, st->hBWE_FD->old_wtda_swb + L_FRAME16k - STEREO_DFT_OVL_16k + delay, STEREO_DFT_OVL_16k - delay ); - } - } - else if ( element_mode == IVAS_CPE_TD ) - { - /* save input resampled at 16kHz, non-preemphasised */ - mvr2r( new_inp_16k + L_FILT16k, new_inp_resamp16k, L_FRAME16k ); - - if ( st->bwidth == WB && st->hBWE_FD != NULL ) - { - mvr2r( new_inp_16k + L_FILT16k - delay, st->hBWE_FD->old_input_wb, delay ); - mvr2r( new_inp_16k - L_MEM_RECALC_16K, st->hBWE_FD->old_wtda_swb + L_FRAME16k - L_MEM_RECALC_16K - L_FILT16k + delay, L_MEM_RECALC_16K + L_FILT16k - delay ); - } - } - else if ( element_mode == IVAS_SCE ) - { - /* save input resampled at 16kHz, non-preemphasised */ - mvr2r( new_inp_16k + L_FILT16k, new_inp_resamp16k, L_FRAME16k ); - - if ( st->bwidth == WB ) - { - mvr2r( new_inp_16k, st->hBWE_FD->old_input_wb + delay - L_FILT16k, L_FILT16k ); - /* all buffer st->hBWE_FD->old_wtda_swb is correct and does not need to be updated */ - } - } - } - else if ( sr_core > INT_FS_16k ) - { - /* reset the buffer, the signal is needed for WB BWEs */ - set_f( new_inp_resamp16k, 0.0f, L_FRAME16k ); - } - - /*------------------------------------------------------------------* - * Perform fixed preemphasis (16kHz signal) through 1 - g*z^-1 - *-----------------------------------------------------------------*/ - - if ( st->tcxonly == 0 && !( ( element_mode == IVAS_CPE_TD && st->idchan == 1 ) || element_mode == IVAS_CPE_MDCT ) ) - { - st->mem_preemph_enc_flt = new_inp_16k[L_frame_tmp - 1]; - } - -#ifdef IVAS_FLOAT_FIXED - Word16 exp_new_inp_16k_fx = 0; - move16(); -#endif - if ( input_Fs > 8000 && sr_core == INT_FS_16k && element_mode != IVAS_CPE_MDCT ) - { - if ( element_mode == IVAS_CPE_DFT ) - { - mvr2r( new_inp_16k - STEREO_DFT_OVL_16k + L_FRAME16k, st->inp_16k_mem_stereo_sw, STEREO_DFT_OVL_16k - L_MEM_RECALC_16K - L_FILT16k ); /* update for TD/DFT stereo switching */ - - st->mem_preemph16k = st->mem_preemph16k_DFT; - st->mem_preemph16k_DFT = old_inp_16k[L_INP_MEM - STEREO_DFT_OVL_16k + L_FRAME16k - 1]; - - if ( st->L_frame == L_FRAME16k ) - { - mvr2r( new_inp_16k - STEREO_DFT_OVL_16k, st->buf_speech_enc_flt + L_FRAME16k - STEREO_DFT_OVL_16k, L_FRAME16k + STEREO_DFT_OVL_16k ); - } -#ifdef IVAS_FLOAT_FIXED - f2me_buf_16( new_inp_16k - STEREO_DFT_OVL_16k, new_inp_16k_fx - STEREO_DFT_OVL_16k, &exp_new_inp_16k_fx, STEREO_DFT_OVL_16k + L_FRAME16k ); - st->mem_preemph16k_fx = (Word16) floatToFixed( st->mem_preemph16k, 15 - exp_new_inp_16k_fx ); - - PREEMPH_FX( new_inp_16k_fx - STEREO_DFT_OVL_16k, PREEMPH_FAC_16k, L_FRAME16k, &( st->mem_preemph16k_fx ) ); - fixedToFloat_arr( new_inp_16k_fx - STEREO_DFT_OVL_16k, new_inp_16k - STEREO_DFT_OVL_16k, 15 - exp_new_inp_16k_fx, STEREO_DFT_OVL_16k + L_FRAME16k ); - st->mem_preemph16k = fixedToFloat( st->mem_preemph16k_fx, 15 - exp_new_inp_16k_fx ); -#else - preemph( new_inp_16k - STEREO_DFT_OVL_16k, PREEMPH_FAC_16k_FLT, L_FRAME16k, &( st->mem_preemph16k ) ); - tmp = st->mem_preemph16k; -#endif - -#ifdef IVAS_FLOAT_FIXED - exp_new_inp_16k_fx = 0; - move16(); - f2me_buf_16( new_inp_16k - STEREO_DFT_OVL_16k + L_FRAME16k, new_inp_16k_fx - STEREO_DFT_OVL_16k + L_FRAME16k, &exp_new_inp_16k_fx, STEREO_DFT_OVL_16k + L_FRAME16k ); - Word16 tmp_fx = (Word16) floatToFixed( st->mem_preemph16k, 15 - exp_new_inp_16k_fx ); - PREEMPH_FX( new_inp_16k_fx - STEREO_DFT_OVL_16k + L_FRAME16k, PREEMPH_FAC_16k, STEREO_DFT_OVL_16k, &tmp_fx ); - fixedToFloat_arr( new_inp_16k_fx - STEREO_DFT_OVL_16k + L_FRAME16k, new_inp_16k - STEREO_DFT_OVL_16k + L_FRAME16k, 15 - exp_new_inp_16k_fx, STEREO_DFT_OVL_16k + L_FRAME16k ); -#else - preemph( new_inp_16k - STEREO_DFT_OVL_16k + L_FRAME16k, PREEMPH_FAC_16k_FLT, STEREO_DFT_OVL_16k, &tmp ); -#endif - } - else if ( st->element_mode == IVAS_CPE_TD ) - { - if ( last_element_mode == IVAS_CPE_DFT ) - { -#ifdef IVAS_FLOAT_FIXED - Word16 exp_inp_16k_mem_stereo_sw = 0; - move16(); - f2me_buf_16( st->inp_16k_mem_stereo_sw, st->inp_16k_mem_stereo_sw_fx, &exp_inp_16k_mem_stereo_sw, STEREO_DFT_OVL_16k - L_MEM_RECALC_16K - L_FILT16k ); - st->mem_preemph16k_DFT_fx = (Word16) floatToFixed( st->mem_preemph16k_DFT, 15 - exp_inp_16k_mem_stereo_sw ); - - st->mem_preemph16k_fx = st->mem_preemph16k_DFT_fx; - move16(); - Copy( st->inp_16k_mem_stereo_sw_fx, new_inp_16k_fx - L_MEM_RECALC_16K - ( STEREO_DFT_OVL_16k - L_MEM_RECALC_16K - L_FILT16k ), STEREO_DFT_OVL_16k - L_MEM_RECALC_16K - L_FILT16k ); - PREEMPH_FX( new_inp_16k_fx - L_MEM_RECALC_16K - ( STEREO_DFT_OVL_16k - L_MEM_RECALC_16K - L_FILT16k ), PREEMPH_FAC_16k, STEREO_DFT_OVL_16k - L_MEM_RECALC_16K - L_FILT16k, &st->mem_preemph16k_fx ); - - st->mem_preemph16k = fixedToFloat( st->mem_preemph16k_fx, 15 - exp_inp_16k_mem_stereo_sw ); - fixedToFloat_arr( new_inp_16k_fx - L_MEM_RECALC_16K - ( STEREO_DFT_OVL_16k - L_MEM_RECALC_16K - L_FILT16k ), new_inp_16k - L_MEM_RECALC_16K - ( STEREO_DFT_OVL_16k - L_MEM_RECALC_16K - L_FILT16k ), 15 - exp_inp_16k_mem_stereo_sw, L_MEM_RECALC_16K + STEREO_DFT_OVL_16k + L_MEM_RECALC_16K + L_FILT16k ); -#else - st->mem_preemph16k = st->mem_preemph16k_DFT; - mvr2r( st->inp_16k_mem_stereo_sw, new_inp_16k - L_MEM_RECALC_16K - ( STEREO_DFT_OVL_16k - L_MEM_RECALC_16K - L_FILT16k ), STEREO_DFT_OVL_16k - L_MEM_RECALC_16K - L_FILT16k ); - preemph( new_inp_16k - L_MEM_RECALC_16K - ( STEREO_DFT_OVL_16k - L_MEM_RECALC_16K - L_FILT16k ), PREEMPH_FAC_16k_FLT, STEREO_DFT_OVL_16k - L_MEM_RECALC_16K - L_FILT16k, &st->mem_preemph16k ); -#endif - } - - st->mem_preemph16k_DFT = old_inp_16k[L_INP_MEM - STEREO_DFT_OVL_16k + L_FRAME16k - 1]; - - /* preemphasise past segment of input signal when switching from MDCT stereo */ - if ( last_element_mode == IVAS_CPE_MDCT ) - { - int16_t length_16k = NS2SA( INT_FS_16k, L_MEM_RECALC_SCH_NS - DELAY_FIR_RESAMPL_NS ); -#ifdef IVAS_FLOAT_FIXED - exp_new_inp_16k_fx = 0; - move16(); - f2me_buf_16( new_inp_16k - lMemRecalc_16k - length_16k, new_inp_16k_fx - lMemRecalc_16k - length_16k, &exp_new_inp_16k_fx, lMemRecalc_16k + length_16k ); - st->mem_preemph16k_fx = (Word16) floatToFixed( st->mem_preemph16k, 15 - exp_new_inp_16k_fx ); - - PREEMPH_FX( new_inp_16k_fx - lMemRecalc_16k - length_16k, PREEMPH_FAC, length_16k, &st->mem_preemph16k_fx ); - - st->mem_preemph16k = fixedToFloat( st->mem_preemph16k_fx, 15 - exp_new_inp_16k_fx ); - fixedToFloat_arr( new_inp_16k_fx - lMemRecalc_16k - length_16k, new_inp_16k - lMemRecalc_16k - length_16k, 15 - exp_new_inp_16k_fx, lMemRecalc_16k + length_16k ); -#else - preemph( new_inp_16k - lMemRecalc_16k - length_16k, PREEMPH_FAC_FLT, length_16k, &st->mem_preemph16k ); -#endif - } - - if ( st->L_frame == L_FRAME16k ) - { - mvr2r( new_inp_16k - lMemRecalc_16k, st->buf_speech_enc_flt + L_FRAME16k - lMemRecalc_16k - L_FILT16k, L_FRAME16k + lMemRecalc_16k + L_FILT16k ); - } -#ifdef IVAS_FLOAT_FIXED - exp_new_inp_16k_fx = 0; - f2me_buf_16( new_inp_16k - lMemRecalc_16k, new_inp_16k_fx - lMemRecalc_16k, &exp_new_inp_16k_fx, lMemRecalc_16k + L_FRAME16k ); - st->mem_preemph16k_fx = (Word16) floatToFixed( st->mem_preemph16k, 15 - exp_new_inp_16k_fx ); - PREEMPH_FX( new_inp_16k_fx - lMemRecalc_16k, PREEMPH_FAC_16k, L_FRAME16k, &( st->mem_preemph16k_fx ) ); - st->mem_preemph16k = fixedToFloat( st->mem_preemph16k_fx, 15 - exp_new_inp_16k_fx ); - fixedToFloat_arr( new_inp_16k_fx - lMemRecalc_16k, new_inp_16k - lMemRecalc_16k, 15 - exp_new_inp_16k_fx, lMemRecalc_16k + L_FRAME16k ); -#else - preemph( new_inp_16k - lMemRecalc_16k, PREEMPH_FAC_16k_FLT, L_FRAME16k, &( st->mem_preemph16k ) ); - tmp = st->mem_preemph16k; -#endif -#ifdef IVAS_FLOAT_FIXED - exp_new_inp_16k_fx = 0; - f2me_buf_16( new_inp_16k - lMemRecalc_16k, new_inp_16k_fx - lMemRecalc_16k, &exp_new_inp_16k_fx, lMemRecalc_16k + L_FRAME16k ); - Word16 tmp_fx = (Word16) floatToFixed( st->mem_preemph16k, 15 - exp_new_inp_16k_fx ); - PREEMPH_FX( new_inp_16k_fx - lMemRecalc_16k + L_FRAME16k, PREEMPH_FAC_16k, lMemRecalc_16k + L_FILT16k, &tmp_fx ); - fixedToFloat_arr( new_inp_16k_fx - lMemRecalc_16k + L_FRAME16k, new_inp_16k - lMemRecalc_16k + L_FRAME16k, 15 - exp_new_inp_16k_fx, lMemRecalc_16k + L_FRAME16k ); -#else - preemph( new_inp_16k - lMemRecalc_16k + L_FRAME16k, PREEMPH_FAC_16k_FLT, lMemRecalc_16k + L_FILT16k, &tmp ); -#endif - } - else if ( element_mode == IVAS_SCE ) - { -#ifdef IVAS_FLOAT_FIXED - exp_new_inp_16k_fx = 0; - f2me_buf_16( new_inp_16k, new_inp_16k_fx, &exp_new_inp_16k_fx, L_FRAME16k ); - st->mem_preemph16k_fx = (Word16) floatToFixed( st->mem_preemph16k, 15 - exp_new_inp_16k_fx ); - PREEMPH_FX( new_inp_16k_fx, PREEMPH_FAC_16k, L_FRAME16k, &( st->mem_preemph16k_fx ) ); - st->mem_preemph16k = fixedToFloat( st->mem_preemph16k_fx, 15 - exp_new_inp_16k_fx ); - fixedToFloat_arr( new_inp_16k_fx, new_inp_16k, 15 - exp_new_inp_16k_fx, L_FRAME16k ); -#else - preemph( new_inp_16k, PREEMPH_FAC_16k_FLT, L_FRAME16k, &( st->mem_preemph16k ) ); - tmp = st->mem_preemph16k; -#endif - -#ifdef IVAS_FLOAT_FIXED - exp_new_inp_16k_fx = 0; - f2me_buf_16( new_inp_16k + L_FRAME16k, new_inp_16k_fx + L_FRAME16k, &exp_new_inp_16k_fx, L_FRAME16k + L_FILT16k ); - Word16 tmp_fx = (Word16) floatToFixed( st->mem_preemph16k, 15 - exp_new_inp_16k_fx ); - PREEMPH_FX( new_inp_16k_fx + L_FRAME16k, PREEMPH_FAC_16k, L_FILT16k, &tmp_fx ); - fixedToFloat_arr( new_inp_16k_fx + L_FRAME16k, new_inp_16k + L_FRAME16k, 15 - exp_new_inp_16k_fx, L_FRAME16k + L_FILT16k ); -#else - preemph( new_inp_16k + L_FRAME16k, PREEMPH_FAC_16k_FLT, L_FILT16k, &tmp ); -#endif - } - else if ( input_Fs > 8000 ) /* keep memory up-to-date in case of bitrate switching */ - { - if ( element_mode == IVAS_CPE_DFT ) - { - st->mem_preemph16k = new_inp_16k[L_frame_tmp - STEREO_DFT_OVL_16k - 1]; - } - else if ( element_mode == IVAS_CPE_TD ) - { - st->mem_preemph16k = new_inp_16k[L_frame_tmp - lMemRecalc_16k - 1]; - } - else if ( element_mode == IVAS_CPE_MDCT ) - { - st->mem_preemph16k = 0; - } - else /* SCE */ - { - st->mem_preemph16k = new_inp_16k[L_frame_tmp - 1]; - } - st->mem_preemph16k_DFT = st->mem_preemph16k; - } - } - - /*-----------------------------------------------------------------* - * LP analysis at 16kHz if ACELP@16k core was selected - * update buffers - *-----------------------------------------------------------------*/ - - if ( st->L_frame == L_FRAME16k && element_mode != IVAS_CPE_MDCT ) - { - /* update signal buffers */ - if ( element_mode == IVAS_CPE_DFT ) - { - mvr2r( new_inp_16k - STEREO_DFT_OVL_16k, st->buf_speech_enc_pe_flt + L_FRAME16k - STEREO_DFT_OVL_16k, L_FRAME16k + STEREO_DFT_OVL_16k ); - } - else if ( element_mode == IVAS_CPE_TD ) - { - mvr2r( new_inp_16k - lMemRecalc_16k, st->buf_speech_enc_pe_flt + L_FRAME16k - lMemRecalc_16k - L_FILT16k, L_FRAME16k + lMemRecalc_16k + L_FILT16k ); - } - else - { - mvr2r( new_inp_resamp16k, st->buf_speech_enc_flt + L_FRAME16k, L_FRAME16k ); - mvr2r( new_inp_16k, st->buf_speech_enc_pe_flt + L_FRAME16k, L_FRAME16k ); - } - - /*--------------------------------------------------------------* - * LPC analysis - *---------------------------------------------------------------*/ - - if ( st->last_L_frame == L_FRAME ) - { - /* this is just an approximation, but it is sufficient */ - mvr2r( st->lsp_old1, st->lspold_enc, M ); - } - - analy_lp( inp_16k, L_FRAME16k, L_look, ener, A, epsP, lsp_new, lsp_mid, st->lspold_enc, st->pitch, st->voicing, INT_FS_16k, 0 ); - /*--------------------------------------------------------------* - * Compute Weighted Input - *---------------------------------------------------------------*/ - - find_wsp( L_FRAME16k, L_SUBFR, NB_SUBFR16k, A, Aw, st->speech_enc_pe_flt, PREEMPH_FAC_16k_FLT, st->wspeech_enc_flt, &st->mem_wsp_enc_flt, st->gamma_flt, L_LOOK_16k ); - } - - /*-----------------------------------------------------------------* - * Updates - *-----------------------------------------------------------------*/ - - /* update old input signal @16kHz buffer */ - if ( ( element_mode == IVAS_CPE_TD && st->idchan == 1 ) || element_mode == IVAS_CPE_MDCT ) - { - set_f( st->old_inp_16k, 0, L_INP_MEM ); - } - else if ( input_Fs > 8000 && sr_core == INT_FS_16k ) - { - mvr2r( &old_inp_16k[L_frame_tmp], st->old_inp_16k, L_INP_MEM ); - } - else if ( input_Fs > 8000 ) - { - lerp_flt( st->old_inp_12k8 + L_INP_MEM - L_INP_MEM * 4 / 5, st->old_inp_16k, L_INP_MEM, L_INP_MEM * 4 / 5 ); - } - - if ( inp16k_out != NULL ) - { - *inp16k_out = inp_16k; - } - - if ( new_inp_resamp16k_out != NULL ) - { - mvr2r( new_inp_resamp16k, new_inp_resamp16k_out, L_FRAME16k ); - } -#else IF( EQ_16( element_mode, IVAS_SCE ) ) { test(); @@ -1600,6 +833,7 @@ ivas_error ivas_compute_core_buffers( { /* no resampling needed, only delay adjustment to account for the FIR resampling delay */ delay = NS2SA_FX2( input_Fs, DELAY_FIR_RESAMPL_NS ); + move16(); Copy( st->mem_decim16k_fx + delay, new_inp_16k_fx, delay ); Copy( signal_in_fx, new_inp_16k_fx + delay, input_frame ); Copy( signal_in_fx + input_frame - shl( delay, 1 ), st->mem_decim16k_fx, shl( delay, 1 ) ); @@ -1622,6 +856,7 @@ ivas_error ivas_compute_core_buffers( { /* no resampling needed, only delay adjustment to account for the FIR resampling delay */ delay = NS2SA_FX2( input_Fs, DELAY_FIR_RESAMPL_NS ); + move16(); Copy( st->mem_decim16k_fx + delay, new_inp_16k_fx - sub( lMemRecalc, add( delay, L_FILT16k ) ), delay ); Copy( signal_in_fx - lMemRecalc, new_inp_16k_fx - add( lMemRecalc, L_FILT16k ), add( input_frame, lMemRecalc ) ); Copy( signal_in_fx + sub( sub( input_frame, lMemRecalc ), shl( delay, 1 ) ), st->mem_decim16k_fx, shl( delay, 1 ) ); @@ -1632,7 +867,9 @@ ivas_error ivas_compute_core_buffers( IF( EQ_16( last_element_mode, IVAS_CPE_MDCT ) /*|| st->idchan == 1*/ ) { Word16 length_inp = NS2SA_FX2( input_Fs, L_MEM_RECALC_SCH_NS - DELAY_FIR_RESAMPL_NS ); + move16(); Word16 length_16k = NS2SA_FX2( INT_FS_16k, L_MEM_RECALC_SCH_NS - DELAY_FIR_RESAMPL_NS ); + move16(); Copy( signal_in_fx - lMemRecalc - length_inp - 2 * NS2SA( input_Fs, DELAY_FIR_RESAMPL_NS ), st->mem_decim16k_fx, 2 * NS2SA( input_Fs, DELAY_FIR_RESAMPL_NS ) ); size_modified = modify_Fs_ivas_fx( signal_in_fx - lMemRecalc - length_inp, length_inp, input_Fs, new_inp_16k_fx - lMemRecalc_16k - length_16k, sr_core, st->mem_decim16k_fx, 0, &Q_tmp, &mem_decim16k_size ); @@ -1764,6 +1001,7 @@ ivas_error ivas_compute_core_buffers( IF( EQ_16( last_element_mode, IVAS_CPE_MDCT ) ) { Word16 length_16k = NS2SA( INT_FS_16k, L_MEM_RECALC_SCH_NS - DELAY_FIR_RESAMPL_NS ); + move16(); PREEMPH_FX( new_inp_16k_fx - lMemRecalc_16k - length_16k, PREEMPH_FAC, length_16k, &st->mem_preemph16k_fx ); } @@ -1844,7 +1082,7 @@ ivas_error ivas_compute_core_buffers( Copy( st->lsp_old1_fx, st->lspold_enc_fx, M ); } - analy_lp_ivas_fx( inp_16k_fx, L_FRAME16k, L_look, &ener_fx, A_fx, epsP_h, epsP_l, lsp_new_fx, lsp_mid_fx, st->lspold_enc_fx, st->pitch, st->voicing_fx, INT_FS_16k, 0, Q_old_inp_16k, Q_r ); + analy_lp_ivas_fx( inp_16k_fx, L_FRAME16k, L_look, ener_fx, A_fx, epsP_h, epsP_l, lsp_new_fx, lsp_mid_fx, st->lspold_enc_fx, st->pitch, st->voicing_fx, INT_FS_16k, 0, Q_old_inp_16k, Q_r ); /*--------------------------------------------------------------* * Compute Weighted Input @@ -1875,64 +1113,24 @@ ivas_error ivas_compute_core_buffers( Scale_sig( st->old_inp_16k_fx, L_INP_MEM, sub( -1 /* Q st->old_inp_16k_fx = -1 */, sub( 15, st->exp_old_inp_12k8 ) ) ); } - IF( inp16k_out != NULL ) + IF( inp16k_out_fx != NULL ) { -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - *inp16k_out = inp_16k; -#endif *inp16k_out_fx = inp_16k_fx; } - IF( new_inp_resamp16k_out != NULL ) + IF( new_inp_resamp16k_out_fx != NULL ) { Copy( new_inp_resamp16k_fx, new_inp_resamp16k_out_fx, L_FRAME16k ); } - -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - // No need to do fixed to float for signal_in_fx - st->mem_preemph_enc_flt = fixedToFloat_16( st->mem_preemph_enc, Q_old_inp_16k ); - st->mem_preemph16k = fixedToFloat_16( st->mem_preemph16k_fx, Q_old_inp_16k ); - st->mem_preemph16k_DFT = fixedToFloat_16( st->mem_preemph16k_DFT_fx, Q_old_inp_16k ); - st->mem_wsp_enc_flt = fixedToFloat_16( st->mem_wsp_enc, Q_old_inp_16k ); - - if ( st->L_frame == L_FRAME16k && element_mode != IVAS_CPE_MDCT ) - { - *ener = fixedToFloat( ener_fx, Q_r[0] + 1 ); - } - - fixedToFloat_arr( old_inp_16k_fx, old_inp_16k, Q_old_inp_16k, L_INP ); - fixedToFloat_arr( signal_in_fx, signal_in, Q_old_inp_16k, 960 ); - fixedToFloat_arr( new_inp_resamp16k_fx, new_inp_resamp16k, Q_old_inp_16k, L_FRAME16k ); - - if ( new_inp_resamp16k_out != NULL ) - { - fixedToFloat_arr( new_inp_resamp16k_out_fx, new_inp_resamp16k_out, Q_old_inp_16k, L_FRAME16k ); - } - - fixedToFloat_arr( st->old_inp_16k_fx, st->old_inp_16k, Q_old_inp_16k, L_INP_MEM ); - fixedToFloat_arr( st->mem_decim16k_fx, st->mem_decim16k, Q_old_inp_16k, 2 * L_FILT_MAX ); - fixedToFloat_arr( st->inp_16k_mem_stereo_sw_fx, st->inp_16k_mem_stereo_sw, Q_old_inp_16k, STEREO_DFT_OVL_16k - L_MEM_RECALC_16K - L_FILT16k ); - fixedToFloat_arr( st->buf_speech_enc, st->buf_speech_enc_flt, Q_old_inp_16k, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k ); - fixedToFloat_arr( st->buf_speech_enc_pe, st->buf_speech_enc_pe_flt, Q_old_inp_16k, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k ); // Should take care of st->speech_enc_pe as wel - fixedToFloat_arr( st->buf_wspeech_enc, st->buf_wspeech_enc_flt, Q_old_inp_16k, L_FRAME16k + L_SUBFR + L_FRAME16k + L_NEXT_MAX_16k + 320 ); // Should take care of st->wspeech_enc - - if ( st->hBWE_FD != NULL ) - { - fixedToFloat_arr( st->hBWE_FD->L_old_wtda_swb_fx, st->hBWE_FD->old_wtda_swb, st->Q_old_wtda, L_FRAME48k ); - } - - if ( st->L_frame == L_FRAME16k && element_mode != IVAS_CPE_MDCT ) + test(); + IF( EQ_16( st->L_frame, L_FRAME16k ) && NE_16( element_mode, IVAS_CPE_MDCT ) ) { - for ( Word16 i = 0; i < M + 1; i++ ) + FOR( Word16 i = 0; i < M + 1; i++ ) { epsP_fx[i] = L_Comp( epsP_h[i], epsP_l[i] ); move32(); } - - fixedToFloat_arrL( epsP_fx, epsP, Q_r[0] + 1, M + 1 ); } -#endif -#endif return IVAS_ERR_OK; } diff --git a/lib_enc/ivas_core_pre_proc_front.c b/lib_enc/ivas_core_pre_proc_front.c index 4bd981654..c83202108 100644 --- a/lib_enc/ivas_core_pre_proc_front.c +++ b/lib_enc/ivas_core_pre_proc_front.c @@ -1388,11 +1388,16 @@ ivas_error pre_proc_front_ivas_fx( { new_inp_out_size = modify_Fs_ivas_fx( signal_in_fx, input_frame, input_Fs, new_inp_12k8_fx, INT_FS_12k8, st->mem_decim_fx, ( st->max_bwidth == NB ), &Q_new_inp, &mem_decim_size ); Scale_sig( new_inp_12k8_fx, new_inp_out_size, negate( Q_new_inp ) ); /* scaling back to q_input*/ - +#ifdef IVAS_FLOAT_FIXED_TO_BE_REMOVED + fixedToFloat_arr( new_inp_12k8_fx, new_inp_12k8, q_input, new_inp_out_size ); +#endif Copy( st->mem_decim_fx, mem_decim_dummy_fx, 2 * L_FILT_MAX ); set16_fx( temp1F_icatdmResampBuf_fx, 0, L_FILT_MAX ); new_inp_out_size = modify_Fs_ivas_fx( temp1F_icatdmResampBuf_fx, NS2SA_FX2( st->input_Fs, DELAY_FIR_RESAMPL_NS ), input_Fs, new_inp_12k8_fx + L_FRAME, INT_FS_12k8, mem_decim_dummy_fx, 0, &Q_new_inp, &mem_decim_size ); Scale_sig( new_inp_12k8_fx + L_FRAME, new_inp_out_size, negate( Q_new_inp ) ); /* scaling back to q_input*/ +#ifdef IVAS_FLOAT_FIXED_TO_BE_REMOVED + fixedToFloat_arr( new_inp_12k8_fx + L_FRAME, new_inp_12k8 + L_FRAME, q_input, new_inp_out_size ); +#endif } ELSE IF( EQ_16( element_mode, IVAS_CPE_TD ) || EQ_16( element_mode, IVAS_CPE_MDCT ) ) { @@ -1405,20 +1410,31 @@ ivas_error pre_proc_front_ivas_fx( new_inp_out_size = modify_Fs_ivas_fx( signal_in_fx - add( lMemRecalc, length_inp ), length_inp, input_Fs, new_inp_12k8_fx - add( lMemRecalc_12k8, length_12k8 ), INT_FS_12k8, st->mem_decim_fx, 0, &Q_new_inp, &mem_decim_size ); Scale_sig( new_inp_12k8_fx - add( lMemRecalc_12k8, length_12k8 ), new_inp_out_size, negate( Q_new_inp ) ); /* scaling back to q_input*/ +#ifdef IVAS_FLOAT_FIXED_TO_BE_REMOVED + fixedToFloat_arr( new_inp_12k8_fx - add( lMemRecalc_12k8, length_12k8 ), new_inp_12k8 - add( lMemRecalc_12k8, length_12k8 ), q_input, new_inp_out_size ); +#endif } new_inp_out_size = modify_Fs_ivas_fx( signal_in_fx - lMemRecalc, input_frame, input_Fs, new_inp_12k8_fx - lMemRecalc_12k8, INT_FS_12k8, st->mem_decim_fx, ( st->max_bwidth == NB ), &Q_new_inp, &mem_decim_size ); Copy( st->mem_decim_fx, mem_decim_dummy_fx, 2 * L_FILT_MAX ); Scale_sig( new_inp_12k8_fx - lMemRecalc_12k8, new_inp_out_size, negate( Q_new_inp ) ); /* scaling back to q_input*/ - +#ifdef IVAS_FLOAT_FIXED_TO_BE_REMOVED + fixedToFloat_arr( new_inp_12k8_fx - lMemRecalc_12k8, new_inp_12k8 - lMemRecalc_12k8, q_input, new_inp_out_size ); +#endif IF( lMemRecalc > 0 ) { new_inp_out_size = modify_Fs_ivas_fx( signal_in_fx + sub( input_frame, lMemRecalc ), lMemRecalc, input_Fs, new_inp_12k8_fx + sub( L_FRAME, lMemRecalc_12k8 ), INT_FS_12k8, mem_decim_dummy_fx, ( st->max_bwidth == NB ), &Q_new_inp, &mem_decim_size ); Scale_sig( new_inp_12k8_fx + sub( L_FRAME, lMemRecalc_12k8 ), new_inp_out_size, negate( Q_new_inp ) ); /* scaling back to q_input*/ +#ifdef IVAS_FLOAT_FIXED_TO_BE_REMOVED + fixedToFloat_arr( new_inp_12k8_fx + sub( L_FRAME, lMemRecalc_12k8 ), new_inp_12k8 + sub( L_FRAME, lMemRecalc_12k8 ), q_input, new_inp_out_size ); +#endif } set16_fx( temp1F_icatdmResampBuf_fx, 0, L_FILT_MAX ); new_inp_out_size = modify_Fs_ivas_fx( temp1F_icatdmResampBuf_fx, NS2SA_FX2( input_Fs, DELAY_FIR_RESAMPL_NS ), input_Fs, new_inp_12k8_fx + L_FRAME, INT_FS_12k8, mem_decim_dummy_fx, 0, &Q_new_inp, &mem_decim_size ); Scale_sig( new_inp_12k8_fx + L_FRAME, new_inp_out_size, negate( Q_new_inp ) ); /* scaling back to q_input*/ +#ifdef IVAS_FLOAT_FIXED_TO_BE_REMOVED + fixedToFloat_arr( new_inp_12k8_fx + L_FRAME, new_inp_12k8 + L_FRAME, q_input, new_inp_out_size ); +#endif } ELSE /* DFT stereo */ { @@ -1822,18 +1838,6 @@ ivas_error pre_proc_front_ivas_fx( { #ifdef IVAS_FLOAT_FIXED resetFdCngEnc_fx( st ); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - - Word16 totalNoiseIncrease_fx = st->hNoiseEst->totalNoise_fx - st->last_totalNoise_fx; - IF( - ( totalNoiseIncrease_fx > 5 * 256 && st->totalNoise_increase_len == TOTALNOISE_HIST_SIZE && st->ini_frame > 150 ) || - ( st->input_bwidth > st->last_input_bwidth ) || - ( st->last_core == AMR_WB_CORE ) ) - { - st->hFdCngEnc->hFdCngCom->init_old_flt = fix16_to_float( st->hFdCngEnc->hFdCngCom->init_old, Q15 ); - move16(); - } -#endif #else resetFdCngEnc( st ); #endif @@ -1888,11 +1892,6 @@ ivas_error pre_proc_front_ivas_fx( Scale_sig32( st->hFdCngEnc->msNoiseEst_old_fx, NPART, msNoiseEst_Q ); st->hFdCngEnc->msNoiseEst_fx_exp = sub( st->hFdCngEnc->msNoiseEst_old_fx_exp, msNoiseEst_Q ); move16(); -#ifdef MSAN_FIX - floatToFixed_arr( st->hFdCngEnc->hFdCngCom->CLDFBpsize_inv_flt, st->hFdCngEnc->hFdCngCom->CLDFBpsize_inv, 15, st->hFdCngEnc->hFdCngCom->nCLDFBpart ); -#else - floatToFixed_arr( st->hFdCngEnc->hFdCngCom->CLDFBpsize_inv_flt, st->hFdCngEnc->hFdCngCom->CLDFBpsize_inv, 15, NPARTCLDFB ); -#endif #endif perform_noise_estimation_enc_ivas_fx( band_energies_LR_fx, band_energies_LR_fx_exp, enerBuffer_fx_loc, enerBuffer_fx_exp, st->hFdCngEnc, input_Fs, hCPE ); } @@ -1917,6 +1916,7 @@ ivas_error pre_proc_front_ivas_fx( floatToFixed_arrL( enerBuffer, enerBuffer_fx_loc, ( 31 - enerBuffer_fx_exp ), st->cldfbAnaEnc->no_channels ); #else floatToFixed_arrL( enerBuffer, enerBuffer_fx_loc, ( 31 - enerBuffer_fx_exp ), CLDFB_NO_CHANNELS_MAX ); +#endif #endif Word16 normmsPeriodog_fx = Q31, zero_flag = 0; move16(); @@ -1925,7 +1925,6 @@ ivas_error pre_proc_front_ivas_fx( IF( zero_flag ) { normmsPeriodog_fx = getScaleFactor32( st->hFdCngEnc->msPeriodog_fx, NPART ); - move16(); } st->hFdCngEnc->msPeriodog_fx_exp_cldfb = sub( 31, normmsPeriodog_fx ); st->hFdCngEnc->msPeriodog_fx_exp_fft = sub( 31, normmsPeriodog_fx ); @@ -1944,16 +1943,16 @@ ivas_error pre_proc_front_ivas_fx( Scale_sig32( st->hFdCngEnc->msNoiseEst_old_fx, NPART, msNoiseEst_Q ); st->hFdCngEnc->msNoiseEst_fx_exp = st->hFdCngEnc->msNoiseEst_old_fx_exp - msNoiseEst_Q; move16(); -#ifdef MSAN_FIX - floatToFixed_arr( st->hFdCngEnc->hFdCngCom->CLDFBpsize_inv_flt, st->hFdCngEnc->hFdCngCom->CLDFBpsize_inv, 15, st->hFdCngEnc->hFdCngCom->nCLDFBpart ); -#else - floatToFixed_arr( st->hFdCngEnc->hFdCngCom->CLDFBpsize_inv_flt, st->hFdCngEnc->hFdCngCom->CLDFBpsize_inv, 15, NPARTCLDFB ); -#endif - Word16 normmsperiodog = Q_factor_arrL( st->hFdCngEnc->hFdCngCom->periodog_flt, PERIODOGLEN ); - st->hFdCngEnc->hFdCngCom->exp_cldfb_periodog = 31 - normmsperiodog; - st->hFdCngEnc->hFdCngCom->init_old = (Word16) ( st->hFdCngEnc->hFdCngCom->init_old_flt * ( 1 << 9 ) ); + zero_flag = get_zero_flag( st->hFdCngEnc->hFdCngCom->periodog, PERIODOGLEN ); + Word16 normmsperiodog = 31; + IF( zero_flag ) + { + normmsperiodog = getScaleFactor32( st->hFdCngEnc->hFdCngCom->periodog, PERIODOGLEN ); + } + st->hFdCngEnc->hFdCngCom->exp_cldfb_periodog = sub( 31, normmsperiodog ); st->hFdCngEnc->hFdCngCom->scalingFactor = (Word16) ( st->hFdCngEnc->hFdCngCom->scalingFactor * ( 1 << 30 ) ); -#endif + move16(); + move16(); perform_noise_estimation_enc_ivas_fx( band_energies_fx, band_energies_fx_exp, enerBuffer_fx_loc, enerBuffer_fx_exp, st->hFdCngEnc, input_Fs, hCPE ); } @@ -2229,11 +2228,6 @@ ivas_error pre_proc_front_ivas_fx( wsp[i] = fixedToFloat( wsp_fx1[i], q_inp_12k8 ); } st->mem_wsp = fixedToFloat( st->mem_wsp_fx, q_inp_12k8 ); - - IF( EQ_16( st->vad_flag, 0 ) ) - { - st->old_corr = (float) ( st->old_corr_fx ); // no Q-factor used here since it's initialised to 0. - } #endif #else @@ -2256,7 +2250,6 @@ ivas_error pre_proc_front_ivas_fx( floatToFixed_arr( st->old_wsp, st->old_wsp_fx, Q_factor_arr( st->old_wsp, L_WSP_MEM ), L_WSP_MEM ); Copy( st->old_wsp_fx, old_wsp_fx, L_WSP_MEM ); wsp_fx = old_wsp_fx + L_WSP_MEM; - st->old_corr_fx = (Word16) floatToFixed( st->old_corr, Q15 ); floatToFixed_arr( st->voicing, st->voicing_fx, Q15, 3 ); corr_shift_fx = (Word16) floatToFixed( corr_shift, Q15 ); f2me_buf_16( wsp, wsp_fx, &exp_wsp, L_WSP - L_WSP_MEM ); @@ -2272,7 +2265,6 @@ ivas_error pre_proc_front_ivas_fx( &st->delta_pit, st->old_wsp2_fx, wsp_fx, st->mem_decim2_fx, relE_fx, st->clas, st->input_bwidth, st->Opt_SC_VBR ); #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - st->old_corr = fixedToFloat( st->old_corr_fx, Q15 ); fixedToFloat_arr( st->voicing_fx, st->voicing, Q15, 3 ); corr_shift = fixedToFloat( corr_shift_fx, Q15 ); fixedToFloat_arr( st->old_wsp2_fx, st->old_wsp2, Q_wsp, 115 ); @@ -2801,22 +2793,37 @@ ivas_error pre_proc_front_ivas_fx( floatToFixed_arr16( Aw, Aw_fx, Q12, NB_SUBFR16k * ( M + 1 ) ); floatToFixed_arr16( lsp_new, lsp_new_fx, Q15, M ); floatToFixed_arr16( lsp_mid, lsp_mid_fx, Q15, M ); +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + Word16 Q_old_inp_16k = -1; + floatToFixed_arr16( st->input, st->input_fx, -1, 960 ); + + st->mem_preemph_enc = (Word16) floatToFixed( st->mem_preemph_enc_flt, Q_old_inp_16k ); + st->mem_preemph16k_fx = (Word16) floatToFixed( st->mem_preemph16k, Q_old_inp_16k ); + st->mem_preemph16k_DFT_fx = (Word16) floatToFixed( st->mem_preemph16k_DFT, Q_old_inp_16k ); + st->mem_wsp_enc = (Word16) floatToFixed( st->mem_wsp_enc_flt, Q_old_inp_16k ); + + floatToFixed_arr16( old_inp_16k, old_inp_16k_fx, Q_old_inp_16k, 880 ); + floatToFixed_arr16( st->old_inp_16k, st->old_inp_16k_fx, Q_old_inp_16k, L_INP_MEM ); + floatToFixed_arr16( st->mem_decim16k, st->mem_decim16k_fx, Q_old_inp_16k, 2 * L_FILT_MAX ); + floatToFixed_arr16( st->inp_16k_mem_stereo_sw, st->inp_16k_mem_stereo_sw_fx, Q_old_inp_16k, STEREO_DFT_OVL_16k - L_MEM_RECALC_16K - L_FILT16k ); + floatToFixed_arr16( st->buf_speech_enc_flt, st->buf_speech_enc, Q_old_inp_16k, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k ); + floatToFixed_arr16( st->buf_speech_enc_pe_flt, st->buf_speech_enc_pe, Q_old_inp_16k, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k ); // Should take care of st->speech_enc_pe as wel + floatToFixed_arr16( st->buf_wspeech_enc_flt, st->buf_wspeech_enc, Q_old_inp_16k, L_FRAME16k + L_SUBFR + L_FRAME16k + L_NEXT_MAX_16k + 320 ); // Should take care of st->wspeech_enc + // wspeech_enc + + if ( st->hBWE_FD != NULL ) + { + floatToFixed_arr16( st->hBWE_FD->old_wtda_swb, st->hBWE_FD->L_old_wtda_swb_fx, Q_old_inp_16k, L_FRAME48k ); + st->Q_old_wtda = -1; // This reset needs to be looked into + } +#endif #endif /* Compute core-coder buffers at internal sampling rate */ - error = ivas_compute_core_buffers( st, NULL, old_inp_16k, NULL, input_frame, IVAS_SCE /*last_element_mode*/, INT_FS_16k /*sr_core_tmp*/, ener, -#ifndef IVAS_FLOAT_FIXED - A, Aw, -#else - A_fx, Aw_fx, -#endif - epsP, -#ifndef IVAS_FLOAT_FIXED - lsp_new, lsp_mid -#else - lsp_new_fx, lsp_mid_fx -#endif - ); + error = ivas_compute_core_buffers_fx( st, NULL, old_inp_16k_fx, NULL, input_frame, IVAS_SCE /*last_element_mode*/, INT_FS_16k /*sr_core_tmp*/, &ener_fx, + A_fx, Aw_fx, + epsP_fx, + lsp_new_fx, lsp_mid_fx, Q_old_inp_16k, Q_r ); if ( error != IVAS_ERR_OK ) { return error; @@ -2826,6 +2833,37 @@ ivas_error pre_proc_front_ivas_fx( fixedToFloat_arr( lsp_new_fx, lsp_new, Q15, M ); fixedToFloat_arr( lsp_mid_fx, lsp_mid, Q15, M ); #endif +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + // No need to do fixed to float for signal_in_fx + st->mem_preemph_enc_flt = fixedToFloat_16( st->mem_preemph_enc, Q_old_inp_16k ); + st->mem_preemph16k = fixedToFloat_16( st->mem_preemph16k_fx, Q_old_inp_16k ); + st->mem_preemph16k_DFT = fixedToFloat_16( st->mem_preemph16k_DFT_fx, Q_old_inp_16k ); + st->mem_wsp_enc_flt = fixedToFloat_16( st->mem_wsp_enc, Q_old_inp_16k ); + + if ( st->L_frame == L_FRAME16k && element_mode != IVAS_CPE_MDCT ) + { + *ener = fixedToFloat( ener_fx, Q_r[0] + 1 ); + } + + fixedToFloat_arr( old_inp_16k_fx, old_inp_16k, Q_old_inp_16k, L_INP ); + fixedToFloat_arr( st->input_fx, st->input, -1, 960 ); + fixedToFloat_arr( st->old_inp_16k_fx, st->old_inp_16k, Q_old_inp_16k, L_INP_MEM ); + fixedToFloat_arr( st->mem_decim16k_fx, st->mem_decim16k, Q_old_inp_16k, 2 * L_FILT_MAX ); + fixedToFloat_arr( st->inp_16k_mem_stereo_sw_fx, st->inp_16k_mem_stereo_sw, Q_old_inp_16k, STEREO_DFT_OVL_16k - L_MEM_RECALC_16K - L_FILT16k ); + fixedToFloat_arr( st->buf_speech_enc, st->buf_speech_enc_flt, Q_old_inp_16k, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k ); + fixedToFloat_arr( st->buf_speech_enc_pe, st->buf_speech_enc_pe_flt, Q_old_inp_16k, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k ); // Should take care of st->speech_enc_pe as wel + fixedToFloat_arr( st->buf_wspeech_enc, st->buf_wspeech_enc_flt, Q_old_inp_16k, L_FRAME16k + L_SUBFR + L_FRAME16k + L_NEXT_MAX_16k + 320 ); // Should take care of st->wspeech_enc + + if ( st->hBWE_FD != NULL ) + { + fixedToFloat_arr( st->hBWE_FD->L_old_wtda_swb_fx, st->hBWE_FD->old_wtda_swb, st->Q_old_wtda, L_FRAME48k ); + } + + if ( st->L_frame == L_FRAME16k && element_mode != IVAS_CPE_MDCT ) + { + fixedToFloat_arrL( epsP_fx, epsP, Q_r[0] + 1, M + 1 ); + } +#endif #ifdef IVAS_FLOAT_FIXED #ifdef IVAS_FLOAT_FIXED_CONVERSIONS Word16 q_speech_enc; @@ -2970,22 +3008,17 @@ ivas_error pre_proc_front_ivas_fx( floatToFixed_arrL( st->Bin_E, st->Bin_E_fx, Q_new + Q_SCALE - 2, TOD_NSPEC ); floatToFixed_arrL( st->hSpMusClas->tod_lt_Bin_E, st->hSpMusClas->tod_lt_Bin_E_fx, Q_new + Q_SCALE - 2, TOD_NSPEC ); floatToFixed_arr( S_map, S_map_fx, Q7, L_FFT / 2 ); - floatToFixed_arr( st->hSpMusClas->gsc_lt_diff_etot, st->hSpMusClas->gsc_lt_diff_etot_fx, Q8, MAX_LT ); - st->old_corr_fx = float_to_fix16( st->old_corr, Q15 ); floatToFixed_arrL( st->hSpMusClas->finc_prev, st->hSpMusClas->finc_prev_fx, 2 * Q_new, ATT_NSEG ); st->hSpMusClas->lt_finc_fx = floatToFixed( st->hSpMusClas->lt_finc, 2 * Q_new ); - st->hSpMusClas->mold_corr_fx = float_to_fix16( st->hSpMusClas->mold_corr, Q15 ); #endif // IVAS_FLOAT_FIXED_CONVERSIONS /* 2nd stage speech/music classification (ACELP/GSC/TCX core selection) */ ivas_smc_mode_selection_fx( st, element_brate, smc_dec, relE_fx, Etot16_fx, attack_flag, inp_12k8_fx, Q_new, S_map_fx, flag_spitch ); #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - fixedToFloat_arr( st->hSpMusClas->gsc_lt_diff_etot_fx, st->hSpMusClas->gsc_lt_diff_etot, Q8, MAX_LT ); fixedToFloat_arrL( st->hSpMusClas->finc_prev_fx, st->hSpMusClas->finc_prev, 2 * Q_new, ATT_NSEG ); st->hSpMusClas->lt_finc = fixedToFloat( st->hSpMusClas->lt_finc_fx, 2 * Q_new ); fixedToFloat_arrL( st->hSpMusClas->tod_lt_Bin_E_fx, st->hSpMusClas->tod_lt_Bin_E, Q_new + Q_SCALE - 2, TOD_NSPEC ); - st->hSpMusClas->mold_corr = fix16_to_float( st->hSpMusClas->mold_corr_fx, Q15 ); #endif // IVAS_FLOAT_FIXED_CONVERSIONS #else diff --git a/lib_enc/ivas_cpe_enc.c b/lib_enc/ivas_cpe_enc.c index b31530d9f..4d18891c4 100644 --- a/lib_enc/ivas_cpe_enc.c +++ b/lib_enc/ivas_cpe_enc.c @@ -284,10 +284,6 @@ ivas_error ivas_cpe_enc_fx( } #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - if ( sts[0]->hFdCngEnc != NULL ) - { - sts[0]->hFdCngEnc->hFdCngCom->init_old_flt = ( sts[0]->hFdCngEnc->hFdCngCom->init_old == 32767 ) ? FLT_MAX : sts[0]->hFdCngEnc->hFdCngCom->init_old_flt; - } if ( hCPE->hFrontVad[0] != NULL && hCPE->element_mode != IVAS_CPE_MDCT ) { Word16 Qband = -1; @@ -692,15 +688,10 @@ ivas_error ivas_cpe_enc_fx( floatToFixed_arr16( sts[0]->input, sts[0]->input_fx, 0, input_frame ); floatToFixed_arr16( sts[1]->input, sts[1]->input_fx, 0, input_frame ); - sts[0]->old_corr_fx = float_to_fix16( sts[0]->old_corr, Q15 ); - sts[1]->old_corr_fx = float_to_fix16( sts[1]->old_corr, Q15 ); - IF( hCPE->hStereoTD->tdm_last_SM_flag ) { floatToFixed_arr16( sts[0]->input, sts[0]->input_fx, 0, input_frame ); floatToFixed_arr16( sts[1]->input, sts[1]->input_fx, 0, input_frame ); - sts[0]->old_corr_fx = float_to_fix16( sts[0]->old_corr, Q15 ); - sts[1]->old_corr_fx = float_to_fix16( sts[1]->old_corr, Q15 ); } #endif /* Determine the energy ratio between the 2 channels */ @@ -1081,7 +1072,6 @@ ivas_error ivas_cpe_enc_fx( floatToFixed_arr( voicing_fr[1], voicing_fr_fx[1], Q15, NB_SUBFR ); floatToFixed_arr( hCPE->hCoreCoder[0]->voicing, hCPE->hCoreCoder[0]->voicing_fx, Q15, 3 ); floatToFixed_arr( hCPE->hCoreCoder[1]->voicing, hCPE->hCoreCoder[1]->voicing_fx, Q15, 3 ); - hCPE->hCoreCoder[0]->old_corr_fx = float_to_fix16( hCPE->hCoreCoder[0]->old_corr, Q15 ); #endif tdm_ol_pitch_comparison_fx( hCPE, pitch_fr_fx, voicing_fr_fx ); @@ -1093,7 +1083,6 @@ ivas_error ivas_cpe_enc_fx( fixedToFloat_arr( voicing_fr_fx[1], voicing_fr[1], Q15, NB_SUBFR ); fixedToFloat_arr( hCPE->hCoreCoder[0]->voicing_fx, hCPE->hCoreCoder[0]->voicing, Q15, 3 ); fixedToFloat_arr( hCPE->hCoreCoder[1]->voicing_fx, hCPE->hCoreCoder[1]->voicing, Q15, 3 ); - hCPE->hCoreCoder[1]->old_corr = fix16_to_float( hCPE->hCoreCoder[1]->old_corr_fx, Q15 ); #endif #else tdm_ol_pitch_comparison( hCPE, pitch_fr, voicing_fr ); diff --git a/lib_enc/ivas_front_vad.c b/lib_enc/ivas_front_vad.c index 7bf6300f9..e1b06984b 100644 --- a/lib_enc/ivas_front_vad.c +++ b/lib_enc/ivas_front_vad.c @@ -991,9 +991,6 @@ ivas_error front_vad_spar_fx( floatToFixed_arr( wsp, wsp_fx, Q8, 368 ); floatToFixed_arr( st->old_wsp2, st->old_wsp2_fx, Q8, 115 ); floatToFixed_arr( st->mem_decim2, st->mem_decim2_fx, Q8, 3 ); -#ifdef MSAN_FIX - st->old_corr_fx = (Word16) floatToFixed( st->old_corr, Q15 ); -#endif corr_shift_fx = (Word16) floatToFixed( corr_shift, Q15 ); // st->old_thres_fx = (Word16) floatToFixed( st->old_thres, Q15 ); relE_fx = (Word16) floatToFixed( relE, Q8 ); @@ -1005,7 +1002,6 @@ ivas_error front_vad_spar_fx( fixedToFloat_arr( st->voicing_fx, st->voicing, Q15, 3 ); fixedToFloat_arr( st->old_wsp2_fx, st->old_wsp2, Q8, 115 ); fixedToFloat_arr( st->mem_decim2_fx, st->mem_decim2, Q8, 3 ); - st->old_corr = fixedToFloat( st->old_corr_fx, Q15 ); #endif /* Updates for adaptive lag window memory */ st->old_pitch_la = st->pitch[2]; diff --git a/lib_enc/ivas_masa_enc.c b/lib_enc/ivas_masa_enc.c index 7d841a9a0..92c5cebc4 100644 --- a/lib_enc/ivas_masa_enc.c +++ b/lib_enc/ivas_masa_enc.c @@ -8545,7 +8545,7 @@ static void ivas_encode_masaism_metadata_fx( FOR( obj = 0; obj < nchan_ism; obj++ ) { L_tmp = Mpy_32_32( hOmasaData->energy_ism_fx[sf][band], hOmasaData->energy_ratio_ism_fx[sf][band][obj] ); // Q = (31 - hOmasaData->energy_ism_fx_e[sf][band]) + Q30 - 31 - L_tmp_e = sub( 30, hOmasaData->energy_ism_fx_e[sf][band] ); + L_tmp_e = add( 1, hOmasaData->energy_ism_fx_e[sf][band] ); energy_ism_ind[obj] = BASOP_Util_Add_Mant32Exp( energy_ism_ind[obj], energy_ism_ind_e[obj], L_tmp, L_tmp_e, &energy_ism_ind_e[obj] ); move32(); } @@ -8573,7 +8573,7 @@ static void ivas_encode_masaism_metadata_fx( } ELSE { - hOmasaData->masa_to_total_energy_ratio_fx[sf][0] = MAX_32; + hOmasaData->masa_to_total_energy_ratio_fx[sf][0] = ONE_IN_Q30; // q30 move32(); } } diff --git a/lib_enc/pitch_ol.c b/lib_enc/pitch_ol.c index 15051574e..bb2415d0a 100644 --- a/lib_enc/pitch_ol.c +++ b/lib_enc/pitch_ol.c @@ -79,6 +79,7 @@ static int16_t pitch_coherence( const int16_t pitch0, const int16_t pitch1, cons static void lp_decim2( const float x[], float y[], const int16_t l, float *mem ); +#ifndef IVAS_FLOAT_FIXED /*-----------------------------------------------------------------* * pitch_ol_init * @@ -86,27 +87,20 @@ static void lp_decim2( const float x[], float y[], const int16_t l, float *mem ) *-----------------------------------------------------------------*/ void pitch_ol_init( -#ifndef IVAS_FLOAT_FIXED - float *old_thres, /* o : threshold for reinforcement of past pitch influence */ -#else - Word16 *old_thres, /* o : threshold for reinforcement of past pitch influence */ -#endif + float *old_thres, /* o : threshold for reinforcement of past pitch influence */ int16_t *old_pitch, /* o : pitch of the 1st half-frame of previous frame */ int16_t *delta_pit, /* o : pitch evolution extrapolation */ float *old_corr /* o : correlation */ ) { -#ifndef IVAS_FLOAT_FIXED *old_thres = 0.0f; -#else - *old_thres = 0; -#endif *old_pitch = 0; *delta_pit = 0; *old_corr = 0.0f; return; } +#endif /*-----------------------------------------------------------------* * pitch_ol() diff --git a/lib_enc/prot_fx_enc.h b/lib_enc/prot_fx_enc.h index 27c9e404e..a48d3bbd0 100644 --- a/lib_enc/prot_fx_enc.h +++ b/lib_enc/prot_fx_enc.h @@ -2852,13 +2852,6 @@ void corr_xh_fx( const Word16 h[] /* i : impulse response (of weighted synthesis filter) */ ); -void corr_xh_ivas_fx( - const Word16 *x, /* i : target signal Q_new - 1 */ - Word16 *y, /* o : correlation between x[] and h[] Q_new + 1 */ - const Word16 *h, /* i : impulse response (of weighted synthesis filter) e(norm_s(h1[0])+1) */ - const Word16 L_subfr /* i : length of the subframe */ -); - void corr_hh_ivas_fx( const Word16 *h, /* i : target signal e(norm_s(h1[0])+1) */ Word16 *y, /* o : correlation between x[] and h[] Q_new + 1 */ @@ -2866,7 +2859,7 @@ void corr_hh_ivas_fx( const Word16 L_subfr /* i : length of the subframe */ ); -void corr_xh_ivas_fx2( +void corr_xh_ivas_fx( const Word16 x[], /* i : target signal */ const Word16 Qx, Word16 dn[], /* o : correlation between x[] and h[] */ diff --git a/lib_enc/q_gain2p.c b/lib_enc/q_gain2p.c index 40545d271..8c18d3ab1 100644 --- a/lib_enc/q_gain2p.c +++ b/lib_enc/q_gain2p.c @@ -42,6 +42,7 @@ #include "rom_com.h" #include "wmc_auto.h" +#ifndef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------------* * Local function prototypes *-------------------------------------------------------------------------*/ @@ -385,3 +386,4 @@ int16_t gain_enc_gacelp_uv( return index; } +#endif diff --git a/lib_enc/rst_enc.c b/lib_enc/rst_enc.c index 66ea72cc9..2281cefa7 100644 --- a/lib_enc/rst_enc.c +++ b/lib_enc/rst_enc.c @@ -56,19 +56,21 @@ void CNG_reset_enc( float *voice_factors, /* o : voicing factors */ int16_t VBR_cng_reset_flag ) { - init_gp_clip( st->clip_var ); #ifndef IVAS_FLOAT_FIXED + init_gp_clip( st->clip_var ); mvr2r( UVWB_Ave, st->mem_AR, M ); set_f( st->mem_MA, 0, M ); #else + init_gp_clip_fx( st->clip_var_fx ); Copy( UVWB_Ave_fx, st->mem_AR_fx, M ); set16_fx( st->mem_MA_fx, 0, M ); #endif st->hLPDmem->mem_w0_flt = 0.0f; - st->hLPDmem->tilt_code_flt = 0.0f; #ifndef IVAS_FLOAT_FIXED + st->hLPDmem->tilt_code_flt = 0.0f; st->hLPDmem->gc_threshold_flt = 0.0f; #else + st->hLPDmem->tilt_code = 0; st->hLPDmem->gc_threshold = 0; #endif @@ -76,7 +78,20 @@ void CNG_reset_enc( { set_f( st->hLPDmem->mem_syn_flt, 0, M ); } +#ifndef IVAS_FLOAT_FIXED set_f( st->hLPDmem->dispMem_flt, 0, 8 ); +#else + st->hLPDmem->dm_fx.prev_state = 0; + move16(); /* This corresponds to st_fx->dispMem in FLP */ + st->hLPDmem->dm_fx.prev_gain_code = 0; + move32(); + + FOR( Word16 i = 2; i < 8; i++ ) + { + st->hLPDmem->dm_fx.prev_gain_pit[i - 2] = 0; + move16(); + } +#endif /* last good received frame for FEC in ACELP */ st->clas = UNVOICED_CLAS; diff --git a/lib_enc/speech_music_classif.c b/lib_enc/speech_music_classif.c index b8c8f64a0..1e937bf73 100644 --- a/lib_enc/speech_music_classif.c +++ b/lib_enc/speech_music_classif.c @@ -164,16 +164,14 @@ void speech_music_clas_init( hSpMusClas->gsc_thres[1] = TH_1_MIN; hSpMusClas->gsc_thres[2] = TH_2_MIN; hSpMusClas->gsc_thres[3] = TH_3_MIN; -#endif set_f( hSpMusClas->gsc_lt_diff_etot, 0.0f, MAX_LT ); -#ifndef IVAS_FLOAT_FIXED hSpMusClas->gsc_mem_etot = 0.0f; #endif hSpMusClas->gsc_last_music_flag = 0; hSpMusClas->gsc_nb_thr_1 = 0; hSpMusClas->gsc_nb_thr_3 = 0; - hSpMusClas->mold_corr = 0.9f; #ifndef IVAS_FLOAT_FIXED + hSpMusClas->mold_corr = 0.9f; hSpMusClas->mean_avr_dyn = 0.5f; hSpMusClas->last_sw_dyn = 10.0f; #endif @@ -262,7 +260,9 @@ void speech_music_clas_init( #endif set_s( hSpMusClas->lt_corr_pitch, 0, 3 ); hSpMusClas->lt_hangover = 0; +#ifndef IVAS_FLOAT_FIXED hSpMusClas->lowrate_pitchGain_flt = 0; +#endif hSpMusClas->lt_music_hangover = 0; #ifndef IVAS_FLOAT_FIXED diff --git a/lib_enc/stat_enc.h b/lib_enc/stat_enc.h index 51cbc7a7e..605fbbdbe 100644 --- a/lib_enc/stat_enc.h +++ b/lib_enc/stat_enc.h @@ -525,6 +525,12 @@ typedef struct fd_cng_enc_structure float msPsdSecondMoment[NPART]; float msNoiseFloor[NPART]; /* Estimated noise floor */ float msNoiseEst[NPART]; /* Estimated noise level */ + float msNoiseEst_old[NPART]; + float energy_ho[NPART]; + float msLogPeriodog[NPART]; /* Periodogram */ + float msLogNoiseEst[NPART]; /* Estimated noise level */ + float msPeriodogBuf[MSBUFLEN * NPART]; + float mem_coherence[4]; #endif Word32 msPeriodog_fx[NPART]; /* Periodogram */ Word16 msPeriodog_fx_exp; /* Common exponent for fft and cldfb energies */ @@ -544,24 +550,14 @@ typedef struct fd_cng_enc_structure Word16 msPsdFirstMoment_fx[NPART]; Word32 msPsdSecondMoment_fx[NPART]; Word16 msNoiseFloor_fx[NPART]; /* Estimated noise floor */ -#ifndef IVAS_FLOAT_FIXED - float msNoiseEst_old[NPART]; - float energy_ho[NPART]; - float msLogPeriodog[NPART]; /* Periodogram */ - float msLogNoiseEst[NPART]; /* Estimated noise level */ -#endif - Word32 msNoiseEst_fx[NPART]; /* Estimated noise level */ + Word32 msNoiseEst_fx[NPART]; /* Estimated noise level */ Word16 msNoiseEst_fx_exp; Word32 energy_ho_fx[NPART]; Word16 energy_ho_fx_exp; Word32 msNoiseEst_old_fx[NPART]; Word16 msNoiseEst_old_fx_exp; -#ifndef IVAS_FLOAT_FIXED - float msPeriodogBuf[MSBUFLEN * NPART]; -#endif Word16 msPeriodogBuf_fx[MSBUFLEN * NPART]; Word16 msPeriodogBufPtr; - Word16 stopFFTbinDec; Word16 startBandDec; Word16 stopBandDec; @@ -569,15 +565,9 @@ typedef struct fd_cng_enc_structure Word16 midbandDec[NPART]; Word16 nFFTpartDec; Word16 partDec[NPART]; - - Word16 msLogPeriodog_fx[NPART]; Word16 msLogNoiseEst_fx[NPART]; -#ifndef IVAS_FLOAT_FIXED - float mem_coherence[4]; -#else Word32 mem_coherence_fx[4]; -#endif Word16 mem_coherence_exp[4]; } FD_CNG_ENC, *HANDLE_FD_CNG_ENC; @@ -597,7 +587,7 @@ typedef struct dtx_enc_structure #ifndef IVAS_FLOAT_FIXED float lspCNG[M]; /* CNG and DTX - LP filtered ISPs */ #else - Word16 lspCNG_fx[M]; /* CNG and DTX - LP filtered lsps Q15 */ + Word16 lspCNG_fx[M]; /* CNG and DTX - LP filtered lsps Q15 */ #endif Word16 VarDTX_cnt_voiced; /* CNG and DTX - counter for variable DTX activation (speech) */ Word16 VarDTX_cnt_noise; /* CNG and DTX - counter for variable DTX activation (noise) */ @@ -606,15 +596,15 @@ typedef struct dtx_enc_structure float lt_ener_noise; /* CNG and DTX - long-term energy of background noise */ float frame_ener; #else - Word32 lt_ener_voiced_fx; /* CNG and DTX - long-term energy of signal (measured on voiced parts) Q(-7) */ - Word32 lt_ener_noise_fx; /* CNG and DTX - long-term energy of background noise Q(-7) */ - Word32 frame_ener_fx; /* Q(-7) */ + Word32 lt_ener_voiced_fx; /* CNG and DTX - long-term energy of signal (measured on voiced parts) Q(-7) */ + Word32 lt_ener_noise_fx; /* CNG and DTX - long-term energy of background noise Q(-7) */ + Word32 frame_ener_fx; /* Q(-7) */ #endif Word16 cng_hist_size; /* CNG and DTX - size of CNG history buffer for averaging, <0,DTX_HIST_SIZE> */ #ifndef IVAS_FLOAT_FIXED float lt_ener_last_SID; /* CNG and DTX - long-term energy of last SID frame */ #else - Word32 lt_ener_last_SID_fx; /* CNG and DTX - long-term energy of last SID frame Q(-7) */ + Word32 lt_ener_last_SID_fx; /* CNG and DTX - long-term energy of last SID frame Q(-7) */ #endif Word16 last_CNG_L_frame; /* CNG and DTX - last CNG frame length */ Word16 var_SID_rate_flag; /* CNG and DTX - flag for variable SID rate */ @@ -818,7 +808,7 @@ typedef struct sp_mus_clas_structure #ifndef IVAS_FLOAT_FIXED float FV_st[N_SMC_FEATURES]; /* Speech/music classifier - short-term mean of the feature vector */ #else - Word32 FV_st_fx[N_SMC_FEATURES]; /* Speech/music classifier - short-term mean of the feature vector Q20 */ + Word32 FV_st_fx[N_SMC_FEATURES]; /* Speech/music classifier - short-term mean of the feature vector Q20 */ #endif float past_PS[HIGHEST_FBIN - LOWEST_FBIN]; Word32 past_PS_fx[HIGHEST_FBIN - LOWEST_FBIN]; @@ -828,8 +818,8 @@ typedef struct sp_mus_clas_structure float past_epsP; float past_epsP2; #else - Word16 past_ps_diff_fx; /* Q10 */ - Word32 prev_FV_fx[N_SMC_FEATURES]; /* Q20 */ + Word16 past_ps_diff_fx; /* Q10 */ + Word32 prev_FV_fx[N_SMC_FEATURES]; /* Q20 */ Word16 past_epsP_fx; Word16 past_epsP2_fx; /* Q10 */ #endif @@ -866,6 +856,8 @@ typedef struct sp_mus_clas_structure float last_non_sta; float past_log_enr[NB_BANDS_SPMUS]; /* Speech/music classifier - last average per-band log energy used for non_staX */ float gsc_thres[4]; /* Speech/music classifier - classification threshold */ + float gsc_lt_diff_etot[MAX_LT]; /* Speech/music classifier - long-term total energy variation */ + float gsc_mem_etot; /* Speech/music classifier - total energy memory */ #else Word32 dlp_mean_LT_fx; /* Q19 */ Word32 dlp_var_LT_fx; /* Q19 */ @@ -874,26 +866,21 @@ typedef struct sp_mus_clas_structure Word16 last_non_sta_fx; /* Q8 */ Word16 past_log_enr_fx[NB_BANDS_SPMUS]; /* Speech/music classifier - last average per-band log energy used for non_staX Q8 */ Word16 gsc_thres_fx[4]; /* Speech/music classifier - classification threshold Q11 */ -#endif - float gsc_lt_diff_etot[MAX_LT]; /* Speech/music classifier - long-term total energy variation */ - Word16 gsc_lt_diff_etot_fx[MAX_LT]; /* Speech/music classifier - long-term total energy variation Q8 */ -#ifndef IVAS_FLOAT_FIXED - float gsc_mem_etot; /* Speech/music classifier - total energy memory */ -#else + Word16 gsc_lt_diff_etot_fx[MAX_LT]; /* Speech/music classifier - long-term total energy variation Q8 */ Word16 gsc_mem_etot_fx; /* Speech/music classifier - total energy memory Q8 */ #endif int16_t gsc_last_music_flag; /* Speech/music classifier - last music flag */ int16_t gsc_nb_thr_1; /* Speech/music classifier - number of consecutives frames of level 1 */ int16_t gsc_nb_thr_3; /* Speech/music classifier - number of consecutives frames of level 3 */ - float mold_corr; - Word16 mold_corr_fx; /* Q15 */ #ifndef IVAS_FLOAT_FIXED + float mold_corr; float mean_avr_dyn; /* Speech/music classifier - long term average dynamic */ float last_sw_dyn; /* Speech/music classifier - last dynamic */ float lt_dec_thres; /* Speech/music classifier - Long term speech/music thresold values */ float ener_RAT; /* Speech/music classifier - LF/to total energy ratio */ #else + Word16 mold_corr_fx; /* Q15 */ Word16 mean_avr_dyn_fx; /* Speech/music classifier - long term average dynamic Q7 */ Word16 last_sw_dyn_fx; /* Speech/music classifier - last dynamic Q7 */ Word16 lt_dec_thres_fx; /* Speech/music classifier - Long term speech/music thresold values Q9 */ @@ -1012,8 +999,8 @@ typedef struct sp_mus_clas_structure float LT_sparse; #else Word16 sparse_buf_fx[HANG_LEN_INIT]; - Word16 hf_spar_buf_fx[HANG_LEN_INIT]; /* Q15 */ - Word16 LT_sparse_fx; /* Q8 */ + Word16 hf_spar_buf_fx[HANG_LEN_INIT]; /* Q15 */ + Word16 LT_sparse_fx; /* Q8 */ #endif int16_t gsc_cnt; @@ -1025,20 +1012,20 @@ typedef struct sp_mus_clas_structure float lt_corr_flt; float lt_tonality_flt; #else - Word16 lt_voicing; /* Q15 */ - Word16 lt_corr; /* Q15 */ - Word32 lt_tonality; /* Q15 */ + Word16 lt_voicing; /* Q15 */ + Word16 lt_corr; /* Q15 */ + Word32 lt_tonality; /* Q15 */ #endif int16_t lt_corr_pitch[3]; int16_t lt_hangover; - float lowrate_pitchGain_flt; - Word16 lowrate_pitchGain; /* Q14 */ #ifndef IVAS_FLOAT_FIXED + float lowrate_pitchGain_flt; float tdm_lt_Etot; float var_cor_t[VAR_COR_LEN]; #else - Word16 tdm_lt_Etot_fx; /* Q8 */ - Word16 var_cor_t_fx[VAR_COR_LEN]; /* Q11 */ + Word16 lowrate_pitchGain; /* Q14 */ + Word16 tdm_lt_Etot_fx; /* Q8 */ + Word16 var_cor_t_fx[VAR_COR_LEN]; /* Q11 */ #endif int16_t high_stable_cor; @@ -1047,9 +1034,9 @@ typedef struct sp_mus_clas_structure float lpm; float lpn; #else - Word16 lps_fx; /* Q7 */ - Word16 lpm_fx; /* Q7 */ - Word16 lpn_fx; /* Q7 */ + Word16 lps_fx; /* Q7 */ + Word16 lpm_fx; /* Q7 */ + Word16 lpn_fx; /* Q7 */ #endif @@ -1090,16 +1077,15 @@ typedef struct lpd_state_structure Word16 mem_syn_r[L_SYN_MEM]; /* ACELP synthesis memory for 1.25ms */ Word16 mem_syn3[M]; - float tilt_code_flt; - Word16 tilt_code; /* Q15 */ #ifndef IVAS_FLOAT_FIXED + float tilt_code_flt; float gc_threshold_flt; /* Noise enhancer - threshold for gain_code */ + float dispMem_flt[8]; /* Noise enhancer - phase dispersion algorithm memory */ #else - Word32 gc_threshold; /* Noise enhancer - threshold for gain_code. exponent = 15, 15Q16 */ + Word16 tilt_code; /* Q15 */ + Word32 gc_threshold; /* Noise enhancer - threshold for gain_code. exponent = 15, 15Q16 */ + struct dispMem_fx dm_fx; /* Noise enhancer - phase dispersion algorithm memory */ #endif - float dispMem_flt[8]; /* Noise enhancer - phase dispersion algorithm memory */ - Word32 dispMem[8]; /* Noise enhancer - phase dispersion algorithm memory */ - struct dispMem_fx dm_fx; /* Noise enhancer - phase dispersion algorithm memory */ } LPD_state, *LPD_state_HANDLE; @@ -1107,19 +1093,20 @@ typedef struct lpd_state_structure /* Structure for storing correlations between ACELP codebook components and target */ typedef struct acelp_cbkcorr_structure { +#ifndef IVAS_FLOAT_FIXED float xx_flt; /* energy of target x */ float y1y1_flt; /* energy of adaptive cbk contribution y1 */ float y2y2_flt; /* energy of fixed cbk contribution y2 */ float xy1_flt; /* correlation of x and y1 */ float xy2_flt; /* correlation of x and y2 */ float y1y2_flt; /* correlation of y1 and y2 */ - - Word16 xx; /* energy of target x */ - Word16 y1y1; /* energy of adaptive cbk contribution y1 */ - Word16 y2y2; /* energy of fixed cbk contribution y2 */ - Word16 xy1; /* correlation of x and y1 */ - Word16 xy2; /* correlation of x and y2 */ - Word16 y1y2; /* correlation of y1 and y2 */ +#else + Word16 xx; /* energy of target x */ + Word16 y1y1; /* energy of adaptive cbk contribution y1 */ + Word16 y2y2; /* energy of fixed cbk contribution y2 */ + Word16 xy1; /* correlation of x and y1 */ + Word16 xy2; /* correlation of x and y2 */ + Word16 y1y2; /* correlation of y1 and y2 */ Word16 xx_e; /* energy of target x */ Word16 y1y1_e; /* energy of adaptive cbk contribution y1 */ @@ -1127,6 +1114,7 @@ typedef struct acelp_cbkcorr_structure Word16 xy1_e; /* correlation of x and y1 */ Word16 xy2_e; /* correlation of x and y2 */ Word16 y1y2_e; /* correlation of y1 and y2 */ +#endif } ACELP_CbkCorr; @@ -1139,12 +1127,15 @@ typedef struct gsc_enc_structure int16_t seed_tcx; /* AC mode (GSC) - seed for noise fill */ int16_t cor_strong_limit; /* AC mode (GSC) - Indicator about high spectral correlation per band */ int16_t mem_last_pit_band; /* AC mode (GSC) - memory of the last band where pitch contribution was significant */ +#ifndef IVAS_FLOAT_FIXED float mem_w0_tmp; float mem_syn_tmp[M]; float mid_dyn; /* AC mode (GSC) - signal dynamic */ +#else Word16 mem_w0_tmp_fx; Word16 mem_syn_tmp_fx[M]; - Word16 mid_dyn_fx; /* AC mode (GSC) - signal dynamic */ + Word16 mid_dyn_fx; /* AC mode (GSC) - signal dynamic Q7 */ +#endif int16_t noise_lev; /* AC mode (GSC) - noise level */ int16_t past_dyn_dec; /* AC mode (GSC) - Past noise level decision */ float Last_frame_ener; /* AC mode (GSC) - Last frame energy */ @@ -1153,12 +1144,17 @@ typedef struct gsc_enc_structure float last_exc_dct_in[L_FRAME16k]; /* AC mode (GSC) - previous excitation */ Word16 last_exc_dct_in_fx[L_FRAME16k]; /* AC mode (GSC) - previous exciation */ Word16 Q_last_exc_dct_in; - float last_ener; /* AC mode (GSC) - previous energy */ - Word16 last_ener_fx; /* AC mode (GSC) - previous energy */ +#ifndef IVAS_FLOAT_FIXED + float last_ener; /* AC mode (GSC) - previous energy */ +#else + Word16 last_ener_fx; /* AC mode (GSC) - previous energy Q0 */ +#endif int16_t last_bitallocation_band[6]; /* AC mode (GSC) - previous bit allocation of each band */ +#ifndef IVAS_FLOAT_FIXED float lt_gpitch; - - Word16 lt_gpitch_fx; /*Q15 */ +#else + Word16 lt_gpitch_fx; /* Q15 */ +#endif } GSC_ENC_DATA, *GSC_ENC_HANDLE; @@ -1286,10 +1282,13 @@ typedef struct sc_vbr_enc_structure int16_t last_ppp_mode; int16_t last_last_ppp_mode; int16_t ppp_mode; +#ifndef IVAS_FLOAT_FIXED float prev_ppp_gain_pit; float prev_tilt_code; - Word16 prev_ppp_gain_pit_fx; /* Q14 */ - Word16 prev_tilt_code_fx; /* Q15 */ +#else + Word16 prev_ppp_gain_pit_fx; /* Q14 */ + Word16 prev_tilt_code_fx; /* Q15 */ +#endif /* voiced encoder variables */ int16_t firstTime_voicedenc; @@ -2045,11 +2044,12 @@ typedef struct enc_core_structure float old_wsp2[( L_WSP_MEM - L_INTERPOL ) / OPL_DECIM]; /* old decimated weighted signal vector */ float mem_wsp; /* weighted signal vector memory */ float mem_decim2[3]; /* weighted signal decimation filter memory */ - float clip_var[6]; /* pitch gain clipping memory */ #ifndef IVAS_FLOAT_FIXED - float mem_AR[M]; /* AR memory of LSF quantizer (past quantized LSFs without mean) */ - float mem_MA[M]; /* MA memory of LSF quantizer (past quantized residual) (used also in AMR-WB IO mode) */ + float clip_var[6]; /* pitch gain clipping memory */ + float mem_AR[M]; /* AR memory of LSF quantizer (past quantized LSFs without mean) */ + float mem_MA[M]; /* MA memory of LSF quantizer (past quantized residual) (used also in AMR-WB IO mode) */ #else + Word16 clip_var_fx[6]; /* pitch gain clipping memory */ Word16 mem_AR_fx[M]; /* AR memory of LSF quantizer (past quantized LSFs without mean) Qlog2(2.56) */ Word16 mem_MA_fx[M]; /* MA memory of LSF quantizer (past quantized residual) (used also in AMR-WB IO mode) Qlog2(2.56) */ #endif @@ -2071,11 +2071,10 @@ typedef struct enc_core_structure Word16 old_wsp2_fx[( L_WSP_MEM - L_INTERPOL ) / OPL_DECIM]; /* old decimated weighted signal vector qwsp */ Word16 mem_wsp_fx; /* weighted signal vector memory */ Word16 mem_decim2_fx[3]; /* weighted signal decimation filter memory qwsp */ - Word16 clip_var_fx[6]; - Word16 mem_deemph_fx; /* deemphasis filter memory */ - Word32 mem_hp20_in_fx[5]; /* HP filter memory for AMR-WB IO */ - Word16 mCb1_fx; /* LSF quantizer - counter of stationary frames after a transition frame */ - int16_t GSC_noisy_speech; /* AC mode (GSC) - flag to indicate GSC on SWB noisy speech */ + Word16 mem_deemph_fx; /* deemphasis filter memory */ + Word32 mem_hp20_in_fx[5]; /* HP filter memory for AMR-WB IO */ + Word16 mCb1_fx; /* LSF quantizer - counter of stationary frames after a transition frame */ + int16_t GSC_noisy_speech; /* AC mode (GSC) - flag to indicate GSC on SWB noisy speech */ int16_t GSC_IVAS_mode; GSC_ENC_HANDLE hGSCEnc; @@ -2115,13 +2114,13 @@ typedef struct enc_core_structure int16_t last_coder_type; /* previous coding type */ #ifndef IVAS_FLOAT_FIXED float old_thres; /* normalized correlation weighting in open-loop pitch */ + float old_corr; /* normalized correlation in previous frame (mean value) */ #else Word16 old_thres_fx; /* normalized correlation weighting in open-loop pitch Q15 */ + Word16 old_corr_fx; /* normalized correlation in previous frame (mean value) Q15 */ #endif - float old_corr; /* normalized correlation in previous frame (mean value) */ - Word16 old_corr_fx; /* normalized correlation in previous frame (mean value) Q15 */ - int16_t old_pitch; /* previous pitch for open-loop pitch search */ - int16_t delta_pit; /* open-loop pitch extrapolation correction */ + int16_t old_pitch; /* previous pitch for open-loop pitch search */ + int16_t delta_pit; /* open-loop pitch extrapolation correction */ #ifndef IVAS_FLOAT_FIXED float ee_old; /* previous frame low/high frequency energy ratio */ #else diff --git a/lib_enc/swb_bwe_enc_fx.c b/lib_enc/swb_bwe_enc_fx.c index e4e4cb32d..3c673d138 100644 --- a/lib_enc/swb_bwe_enc_fx.c +++ b/lib_enc/swb_bwe_enc_fx.c @@ -324,7 +324,6 @@ void swb_bwe_enc_ivas_fx( move32(); #endif Word16 fb_band_begin; - Word16 sf; FD_BWE_ENC_HANDLE hBWE_FD = st_fx->hBWE_FD; TD_BWE_ENC_HANDLE hBWE_TD = st_fx->hBWE_TD; @@ -437,11 +436,6 @@ void swb_bwe_enc_ivas_fx( &st_fx->Q_old_wtda, ALDO_WINDOW, ALDO_WINDOW, /* window overlap of current frame (0: full, 2: none, or 3: half) */ inner_frame ); - /* Scaling has been added to avoid the yorig_32 buffer becoming zero inside direct_transform_fx */ - sf = L_norm_arr( L_old_input_fx, inner_frame ); - scale_sig32( L_old_input_fx, inner_frame, sf ); - new_input_fx_exp = add( new_input_fx_exp, sf ); // It is Q, not exp - /* DCT of the ACELP core synthesis */ direct_transform_fx( L_old_input_fx, yorig_32, 0, inner_frame, &new_input_fx_exp, st_fx->element_mode ); @@ -3188,7 +3182,6 @@ static Word16 SWB_BWE_encoding_ivas_fx( Word16 inner_frame; Word16 q_shift; Word16 yos_fx_16[L_FRAME_MAX]; - Word16 sf; FD_BWE_ENC_HANDLE hBWE_FD = st_fx->hBWE_FD; BSTR_ENC_HANDLE hBstr = st_fx->hBstr; @@ -3599,12 +3592,11 @@ static Word16 SWB_BWE_encoding_ivas_fx( global_gain_fx = L_shr( global_gain_fx, 1 ); /*2*Q_shb */ - sf = getScaleFactor32( yos_fx, inner_frame ); - Copy_Scale_sig32_16( yos_fx, yos_fx_16, inner_frame, sf ); - mode = FD_BWE_class_fx( yos_fx_16, global_gain_fx, tilt_nb_fx, sub( add( Q_synth, sf ), Q16 ), Q_shb, st_fx ); + Copy_Scale_sig32_16( yos_fx, yos_fx_16, inner_frame, 0 ); + mode = FD_BWE_class_fx( yos_fx_16, global_gain_fx, tilt_nb_fx, sub( Q_synth, Q16 ), Q_shb, st_fx ); push_indice( hBstr, IND_SWB_CLASS, mode, 2 ); - energy_control_ivas_fx( st_fx, ACELP_CORE, mode, -1, yos_fx_16, st_offset, energy_factor_fx, sub( add( Q_synth_lf, sf ), Q16 ) ); + energy_control_ivas_fx( st_fx, ACELP_CORE, mode, -1, yos_fx_16, st_offset, energy_factor_fx, sub( Q_synth_lf, Q16 ) ); FOR( n_band = 0; n_band < SWB_FENV; n_band++ ) { diff --git a/lib_enc/tcq_core_enc.c b/lib_enc/tcq_core_enc.c index c5a5c21e9..9ce8750d8 100644 --- a/lib_enc/tcq_core_enc.c +++ b/lib_enc/tcq_core_enc.c @@ -49,6 +49,7 @@ * Main Generic Audio Encoder Routine for LR-MDCT *---------------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED ivas_error tcq_core_LR_enc( BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ int32_t inp_vector[], @@ -468,3 +469,4 @@ ivas_error tcq_core_LR_enc( return error; } +#endif diff --git a/lib_enc/tns_base_enc_fx.c b/lib_enc/tns_base_enc_fx.c index a703085a8..16499fcfd 100644 --- a/lib_enc/tns_base_enc_fx.c +++ b/lib_enc/tns_base_enc_fx.c @@ -695,7 +695,7 @@ Word16 DetectTnsFilt_ivas_fx( STnsConfig const *pTnsConfig, /* i : TNS Configur assert( n < (Word16) ( sizeof( tmpbuf ) / sizeof( Word16 ) ) ); FOR( i = 0; i < n; i++ ) { - tmpbuf[i] = round_fx( L_shl( pSpectrum[iStartLine + i], shift ) ); + tmpbuf[i] = round_fx_sat( L_shl( pSpectrum[iStartLine + i], shift ) ); // using round_fx_sat to address corner case move16(); } diff --git a/lib_enc/transition_enc.c b/lib_enc/transition_enc.c index cd6e48fe2..190ce580f 100644 --- a/lib_enc/transition_enc.c +++ b/lib_enc/transition_enc.c @@ -43,6 +43,7 @@ #include "wmc_auto.h" #include "prot_fx.h" +#ifndef IVAS_FLOAT_FIXED /*-----------------------------------------------------------------* * Local function prototypes *-----------------------------------------------------------------*/ @@ -970,7 +971,6 @@ static void gain_trans_enc( } -#ifndef IVAS_FLOAT_FIXED /*-----------------------------------------------------------------* * tc_classif_enc() * diff --git a/lib_enc/voiced_enc.c b/lib_enc/voiced_enc.c index 3a0382268..ab1a9f8b8 100644 --- a/lib_enc/voiced_enc.c +++ b/lib_enc/voiced_enc.c @@ -1130,7 +1130,6 @@ static void SynthesisFilter( return; } -#endif /*---------------------------------------------------------------------* @@ -1160,27 +1159,15 @@ void sc_vbr_enc_init( hSC_VBR->set_ppp_generic = 0; hSC_VBR->Q_to_F = 0; - hSC_VBR->numactive = 0; /* keep the count of the frames inside current 600 frame bloack.*/ -#ifndef IVAS_FLOAT_FIXED + hSC_VBR->numactive = 0; /* keep the count of the frames inside current 600 frame bloack.*/ hSC_VBR->sum_of_rates = 0.0f; /* sum of the rates of past 600 active frames*/ hSC_VBR->global_avr_rate = 0.0f; /* global rate upto current time. recorded a (rate in kbps) *6000*/ -#else - hSC_VBR->sum_of_rates_fx = 0; /* sum of the rates of past 600 active frames*/ - move32(); - hSC_VBR->global_avr_rate_fx = 0; /* global rate upto current time. recorded a (rate in kbps) *6000*/ - move32(); -#endif - hSC_VBR->global_frame_cnt = 0; /* 600 active frame block count. Used to update the global rate*/ + hSC_VBR->global_frame_cnt = 0; /* 600 active frame block count. Used to update the global rate*/ hSC_VBR->rate_control = 0; -#ifndef IVAS_FLOAT_FIXED hSC_VBR->SNR_THLD = 67.0f; -#else - hSC_VBR->SNR_THLD_fx = SNR_THLD_FX_Q8; -#endif hSC_VBR->mode_QQF = 1; -#ifndef IVAS_FLOAT_FIXED set_f( hSC_VBR->shape1_filt_mem, 0, 20 ); set_f( hSC_VBR->shape2_filt_mem, 0, 20 ); set_f( hSC_VBR->shape3_filt_mem, 0, 20 ); @@ -1188,15 +1175,6 @@ void sc_vbr_enc_init( set_f( hSC_VBR->txlpf1_filt2_mem, 0, 20 ); set_f( hSC_VBR->txhpf1_filt1_mem, 0, 20 ); set_f( hSC_VBR->txhpf1_filt2_mem, 0, 20 ); -#else - set16_fx( hSC_VBR->shape1_filt_mem_fx, 0, 20 ); - set16_fx( hSC_VBR->shape2_filt_mem_fx, 0, 20 ); - set16_fx( hSC_VBR->shape3_filt_mem_fx, 0, 20 ); - set16_fx( hSC_VBR->txlpf1_filt1_mem_fx, 0, 20 ); - set16_fx( hSC_VBR->txlpf1_filt2_mem_fx, 0, 20 ); - set16_fx( hSC_VBR->txhpf1_filt1_mem_fx, 0, 20 ); - set16_fx( hSC_VBR->txhpf1_filt2_mem_fx, 0, 20 ); -#endif hSC_VBR->last_7k2_coder_type = GENERIC; hSC_VBR->vbr_generic_ho = 0; @@ -1204,3 +1182,4 @@ void sc_vbr_enc_init( return; } +#endif -- GitLab From 903f7d3dfbb232e828a7da0d8821396dcb02e4b0 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Thu, 14 Nov 2024 14:42:56 +0530 Subject: [PATCH 121/128] Fix for 3GPP issue 1008: Serious clicks in ISM + FER at higher bitrates link #1008, #1032 [x] Fixes #1032 as well. --- lib_dec/ivas_tcx_core_dec.c | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/lib_dec/ivas_tcx_core_dec.c b/lib_dec/ivas_tcx_core_dec.c index 4ac2bc814..25d6b9fea 100644 --- a/lib_dec/ivas_tcx_core_dec.c +++ b/lib_dec/ivas_tcx_core_dec.c @@ -316,7 +316,7 @@ void stereo_tcx_core_dec_fx( Word32 L_tmp, mod; /*LPC*/ - Word16 lsf_fx[( NB_DIV + 1 ) * M], lsp_fx[( NB_DIV + 1 ) * M], lspmid_fx[M], lsfmid_fx[M]; + Word16 lsf_fx[( NB_DIV + 1 ) * M], lsp_fx[( NB_DIV + 1 ) * M], lspmid_fx[M], lsfmid_fx[M], lsf_tmp_fx[( NB_DIV + 1 ) * M]; Word16 lspnew_uw_fx[NB_DIV * M], lsfnew_uw_fx[NB_DIV * M]; Word16 Aq_fx[( NB_SUBFR16k + 1 ) * ( M + 1 )]; Word16 pit_gain_fx[NB_SUBFR16k]; @@ -530,17 +530,32 @@ void stereo_tcx_core_dec_fx( hTcxDec->envWeighted = 0; move16(); - Copy( st->lspold_uw, lsp_fx, M ); /* Q15 */ - Copy( st->lsfold_uw, lsf_fx, M ); /* Q2.56 */ + Copy( st->lspold_uw, lsp_fx, M ); /* Q15 */ + Copy( st->lsfold_uw, lsf_fx, M ); /* Q2.56 */ + Copy( st->lsfold_uw, lsf_tmp_fx, M ); /* Q2.56 */ + + Word16 tmp; + Word16 sr_core_ratio = BASOP_Util_Divide3232_Scale( st->sr_core, INT_FS_12k8, &tmp ); FOR( k = 0; k < st->numlpc; k++ ) { - Copy( &lsfnew_uw_fx[k * M], &lsf_fx[( k + 1 ) * M], M ); /* Q2.56 */ + Copy( &lsfnew_uw_fx[k * M], &lsf_fx[( k + 1 ) * M], M ); /* Q2.56 */ + Copy( &lsfnew_uw_fx[k * M], &lsf_tmp_fx[( k + 1 ) * M], M ); /* Q2.56 */ - lsf2lsp_fx( &lsf_fx[( k + 1 ) * M], &lsp_fx[( k + 1 ) * M], M, st->sr_core ); /* Q2.56 */ - lsf2lsp_fx( st->lsf_q_cng, st->lsp_q_cng, M, st->sr_core ); /* Q2.56 */ + v_multc_fixed_16_16( &lsf_tmp_fx[( k + 1 ) * M], sr_core_ratio, &lsf_tmp_fx[( k + 1 ) * M], M ); + Scale_sig( &lsf_tmp_fx[( k + 1 ) * M], M, tmp ); + test(); + IF( !st->lpcQuantization && EQ_32( st->sr_core, INT_FS_16k_FX ) ) + { + lsf2lsp_fx( &lsf_tmp_fx[( k + 1 ) * M], &lsp_fx[( k + 1 ) * M], M, st->sr_core ); + } + ELSE + { + lsf2lsp_fx( &lsf_fx[( k + 1 ) * M], &lsp_fx[( k + 1 ) * M], M, st->sr_core ); + } + lsf2lsp_fx( st->lsf_q_cng, st->lsp_q_cng, M, st->sr_core ); - Copy( &lsp_fx[( k + 1 ) * M], &lspnew_uw_fx[k * M], M ); /* Q2.56 */ + Copy( &lsp_fx[( k + 1 ) * M], &lspnew_uw_fx[k * M], M ); /* Q15 */ } } -- GitLab From 838fbdd6d34fb5b96cbd8d03aba63da528d65901 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Thu, 14 Nov 2024 14:45:41 +0530 Subject: [PATCH 122/128] Fix for 3GPP issue 1029: New Clicks in MDCT-Stereo concealment link #1029 --- lib_dec/ivas_mdct_core_dec.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib_dec/ivas_mdct_core_dec.c b/lib_dec/ivas_mdct_core_dec.c index 57d08a708..e86d211f9 100644 --- a/lib_dec/ivas_mdct_core_dec.c +++ b/lib_dec/ivas_mdct_core_dec.c @@ -2161,6 +2161,11 @@ void ivas_mdct_core_reconstruct_fx( ELSE /*ACELP core for ACELP-PLC */ { assert( EQ_16( st->bfi, 1 ) ); + + Scale_sig( synth_buf_fx, add( add( st->hTcxDec->old_synth_len, L_FRAME_PLUS ), M ), negate( q_syn ) ); // Q0 + Scale_sig( synth_bufFB_fx, add( add( st->hTcxDec->old_synth_lenFB, L_FRAME_PLUS ), M ), negate( q_syn ) ); // Q0 + q_syn = 0; + move16(); /* PLC: [TCX: TD PLC] */ IF( MCT_flag != 0 ) { @@ -2177,6 +2182,8 @@ void ivas_mdct_core_reconstruct_fx( con_tcx_ivas_fx( st, &synthFB_fx[0], hCPE->hStereoMdct->lastCoh_fx, &sts[0]->seed_acelp, 0, &st->hFdCngDec->hFdCngCom->A_cng[0] ); } } + + Scale_sig( synthFB_fx, st->hTcxDec->L_frameTCX, q_syn ); // q_syn IF( ( EQ_16( st->nbLostCmpt, 1 ) ) || ( st->hTcxDec->tcxConceal_recalc_exc != 0 ) ) { Scale_sig( synthFB_fx - add( add( shr( st->hTcxDec->L_frameTCX, 1 ), st->hTcxDec->pit_max_TCX ), 2 * M ), add( add( shr( st->hTcxDec->L_frameTCX, 1 ), st->hTcxDec->pit_max_TCX ), 2 * M ), sub( q_syn, sub( st->Q_exc, 1 ) ) ); // 2 * q_syn - (st->Q_exc - 1) -- GitLab From e413837dbda9d753c1887c87414cee784c2b4517 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Fri, 15 Nov 2024 08:36:16 +0530 Subject: [PATCH 123/128] Encoder paths float code cleanup, LTV crash fixes, Q-info updates for lib_com files [x] Intermediate float conversion cleanup, float structure variable cleanup [x] Q-info updates for lib_com files [x] LTV crash issue fixes for encoder: +10db ltv case: [ltv-Multi-channel 5_1 at 13.2 kbps, 48kHz in, 48kHz out] --- lib_com/cldfb.c | 37 +- lib_com/fd_cng_com_fx.c | 8 +- lib_com/gs_preech.c | 14 +- lib_com/lerp.c | 216 +++---- lib_com/limit_t0_fx.c | 59 +- lib_com/lsf_tools_fx.c | 4 +- lib_com/prot.h | 8 +- lib_com/prot_fx.h | 8 +- lib_com/residu_fx.c | 6 +- lib_com/tcq_position_arith_fx.c | 2 +- lib_com/tcx_mdct_window.c | 2 + lib_com/tcx_utils_fx.c | 786 +++++++++++++------------- lib_enc/core_enc_init.c | 8 +- lib_enc/gs_enc_fx.c | 2 +- lib_enc/ivas_cpe_enc.c | 77 +-- lib_enc/ivas_ism_enc.c | 2 +- lib_enc/ivas_mc_param_enc.c | 4 +- lib_enc/ivas_osba_enc.c | 11 +- lib_enc/ivas_sce_enc.c | 13 +- lib_enc/ivas_stat_enc.h | 2 +- lib_enc/ivas_stereo_dft_enc.c | 31 +- lib_enc/ivas_stereo_dmx_evs.c | 56 +- lib_enc/ivas_stereo_mdct_stereo_enc.c | 7 + lib_enc/prot_fx_enc.h | 7 +- lib_enc/transient_detection_fx.c | 9 +- lib_enc/vad_fx.c | 95 +++- 26 files changed, 749 insertions(+), 725 deletions(-) diff --git a/lib_com/cldfb.c b/lib_com/cldfb.c index ccca93784..264973581 100644 --- a/lib_com/cldfb.c +++ b/lib_com/cldfb.c @@ -1829,54 +1829,43 @@ ivas_error openCldfb_ivas( ivas_error openCldfb_ivas_enc( HANDLE_CLDFB_FILTER_BANK *h_cldfb, /* i/o: filter bank handle */ CLDFB_TYPE type, /* i : analysis or synthesis */ - const int32_t sampling_rate, /* i : sampling rate */ + const Word32 sampling_rate, /* i : sampling rate */ CLDFB_PROTOTYPE prototype /* i : CLDFB version (1.25ms/5ms delay) */ ) { HANDLE_CLDFB_FILTER_BANK hs; - int16_t buf_len; + Word16 buf_len; - if ( ( hs = (HANDLE_CLDFB_FILTER_BANK) malloc( sizeof( CLDFB_FILTER_BANK ) ) ) == NULL ) + IF( ( hs = (HANDLE_CLDFB_FILTER_BANK) malloc( sizeof( CLDFB_FILTER_BANK ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for CLDFB" ); } hs->type = type; + move32(); hs->prototype = prototype; + move32(); -#ifndef IVAS_FLOAT_FIXED - configureCldfb_ivas_enc( hs, sampling_rate ); - hs->memory_flt = NULL; -#else configureCldfb_ivas_enc_fx( hs, sampling_rate ); -#endif hs->memory_length = 0; + move32(); - if ( type == CLDFB_ANALYSIS ) + IF( type == CLDFB_ANALYSIS ) { - buf_len = hs->p_filter_length - hs->no_channels; -#ifdef IVAS_FLOAT_FIXED + buf_len = sub( hs->p_filter_length, hs->no_channels ); hs->FilterStates = (Word16 *) malloc( ( 9 + 16 ) * CLDFB_getNumChannels( sampling_rate ) * sizeof( Word16 ) ); hs->FilterStates_eg = 0; -#endif + move16(); } - else + ELSE { buf_len = hs->p_filter_length; -#ifdef IVAS_FLOAT_FIXED + move16(); hs->FilterStates = (Word16 *) malloc( 2 * ( 9 + 16 ) * CLDFB_getNumChannels( sampling_rate ) * sizeof( Word16 ) ); hs->FilterStates_eg = 0; -#endif + move16(); } -#ifndef IVAS_FLOAT_FIXED - if ( ( hs->cldfb_state = (float *) malloc( buf_len * sizeof( float ) ) ) == NULL ) - { - return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for CLDFB" ); - } - set_f( hs->cldfb_state, 0.0f, buf_len ); -#endif -#ifdef IVAS_FLOAT_FIXED if ( ( hs->cldfb_state_fx = (Word32 *) malloc( buf_len * sizeof( Word32 ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for CLDFB" ); @@ -1890,8 +1879,6 @@ ivas_error openCldfb_ivas_enc( move16(); set16_fx( hs->FilterStates, 0, i_mult( 9 + 16, hs->no_channels ) ); set16_fx( hs->FilterStates_e, 0, sizeof( hs->FilterStates_e ) / sizeof( hs->FilterStates_e[0] ) ); -#endif // IVAS_FLOAT_FIXED - *h_cldfb = hs; diff --git a/lib_com/fd_cng_com_fx.c b/lib_com/fd_cng_com_fx.c index ac1fa1a2b..8c64e6c16 100644 --- a/lib_com/fd_cng_com_fx.c +++ b/lib_com/fd_cng_com_fx.c @@ -175,8 +175,10 @@ void initFdCngCom( HANDLE_FD_CNG_COM hFdCngCom, Word16 scale ) assert( 2048 /*1.0/(1<<4) Q15*/ < mult( scale, scale ) ); /* Exponent invScalingFactor: -16 = -(2*7 (scale) + 2 (8.0) */ hFdCngCom->invScalingFactor = shl( mult( scale, scale ), 1 ); + move16(); /* Exponent scalingFactor: -15 = -(2*7 (scale) + 2 (8.0) - 1 (1.0)) */ hFdCngCom->scalingFactor = div_s( 0x4000, hFdCngCom->invScalingFactor ); + move16(); /* Initialize the overlap-add */ set16_fx( hFdCngCom->timeDomainBuffer, 0, L_FRAME16k ); @@ -185,10 +187,8 @@ void initFdCngCom( HANDLE_FD_CNG_COM hFdCngCom, Word16 scale ) set16_fx( hFdCngCom->olapBufferAna_fx, 0, FFTLEN ); #endif // IVAS_FLOAT_FIXED - move16(); set16_fx( hFdCngCom->olapBufferSynth, 0, FFTLEN ); hFdCngCom->olapBufferSynth2 = NULL; - move16(); /* Initialize the comfort noise generation */ set32_fx( hFdCngCom->fftBuffer, 0, FFTLEN ); @@ -228,9 +228,9 @@ void initFdCngCom( HANDLE_FD_CNG_COM hFdCngCom, Word16 scale ) hFdCngCom->seed = 0; move16(); // hFdCngCom->seed2 = 1; - move16(); + // move16(); // hFdCngCom->seed3 = 2; - move16(); + // move16(); hFdCngCom->CngBitrate = -1; move16(); diff --git a/lib_com/gs_preech.c b/lib_com/gs_preech.c index 1fc23300e..f7964bed6 100644 --- a/lib_com/gs_preech.c +++ b/lib_com/gs_preech.c @@ -376,17 +376,17 @@ void pre_echo_att_ivas_fx( /*-------------------------------------------------------* * In normal cases, just compute the energy of the frame *-------------------------------------------------------*/ + Word16 exp_etmp = sub( 15, Q_new ); + etmp_fx = sum2_16_exp_fx( exc_fx, L_frame, &exp_etmp, 7 ); /* Q = 31-exp_etmp */ - etmp_fx = sum2_fx( exc_fx, L_frame ); /*2*Q_new+1 */ - - etmp_fx = L_shr( etmp_fx, add( 8 + 1 - 4, shl( Q_new, 1 ) ) ); /*2*Q_new+1 //INV_L_FRAME = 1/256 -> Q4*/ + etmp_fx = L_shr( etmp_fx, 8 ); /*31-exp_etmp//INV_L_FRAME = 1/256*/ - if ( EQ_16( L_frame, L_FRAME16k ) ) + IF( EQ_16( L_frame, L_FRAME16k ) ) { - etmp_fx = Mpy_32_16_1( etmp_fx, 26214 /* 0.8 in Q15 */ ); /*2*Q_new+1*/ + etmp_fx = Mpy_32_16_1( etmp_fx, 26214 /* 0.8 in Q15 */ ); /*31 - exp_etmp*/ } - *Last_frame_ener_fx = etmp_fx; - move32(); /*2*Q_new+1*/ + *Last_frame_ener_fx = L_shl( etmp_fx, sub( shl( Q_new, 1 ), sub( 30 /*31-1*/, exp_etmp ) ) ); /*2*Q_new+1*/ + move32(); /*2*Q_new+1*/ } return; diff --git a/lib_com/lerp.c b/lib_com/lerp.c index 42c44ef12..17a39d53c 100644 --- a/lib_com/lerp.c +++ b/lib_com/lerp.c @@ -202,59 +202,59 @@ static void lerp_proc( const Word16 *f, Word16 *f_out, Word16 bufferNewSize, Wor * * *-------------------------------------------------------------*/ -void lerp( const Word16 *f, Word16 *f_out, Word16 bufferNewSize, Word16 bufferOldSize ) +void lerp( const Word16 *f /*Qx*/, Word16 *f_out /*Qx*/, Word16 bufferNewSize /*Q0*/, Word16 bufferOldSize /*Q0*/ ) { Word16 tmp1, tmp2, tmpexp; BASOP_Util_Divide_MantExp( bufferNewSize, 0, bufferOldSize, 0, &tmp1, &tmpexp ); - tmp1 = shr( tmp1, 3 ); /*Q12*/ - tmp1 = shl( tmp1, tmpexp ); + tmp1 = shr( tmp1, 3 ); /*Q12*/ + tmp1 = shl( tmp1, tmpexp ); /*Q12+tmpexp*/ BASOP_Util_Divide_MantExp( bufferOldSize, 0, bufferNewSize, 0, &tmp2, &tmpexp ); - tmp2 = shr( tmp2, 3 ); /*Q12*/ - tmp2 = shl( tmp2, tmpexp ); - IF( GT_16( tmp1, 16224 /*3,9609375 in Q12*/ ) ) + tmp2 = shr( tmp2, 3 ); /*Q12*/ + tmp2 = shl( tmp2, tmpexp ); /*Q12+tmpexp*/ + IF( GT_16( tmp1, 16224 /*3.9609375 in Q12*/ ) ) { - Word16 tmpNewSize = shl( bufferOldSize, 1 ); + Word16 tmpNewSize = shl( bufferOldSize, 1 ); /*Q0*/ WHILE( GT_16( bufferNewSize, bufferOldSize ) ) { BASOP_Util_Divide_MantExp( bufferNewSize, 0, bufferOldSize, 0, &tmp1, &tmpexp ); - tmp1 = shr( tmp1, 3 ); /*Q12*/ - tmp1 = shl( tmp1, tmpexp ); - if ( LE_16( tmp1, 16224 /*3,9609375 in Q12*/ ) ) + tmp1 = shr( tmp1, 3 ); /*Q12*/ + tmp1 = shl( tmp1, tmpexp ); /*Q12+tmpexp*/ + if ( LE_16( tmp1, 16224 /*3.9609375 in Q12*/ ) ) { - tmpNewSize = bufferNewSize; + tmpNewSize = bufferNewSize; /*Q0*/ move16(); } lerp_proc( f, f_out, tmpNewSize, bufferOldSize ); - f = f_out; - bufferOldSize = tmpNewSize; + f = f_out; /*Qx*/ + bufferOldSize = tmpNewSize; /*Q0*/ move16(); - tmpNewSize = shl( tmpNewSize, 1 ); + tmpNewSize = shl( tmpNewSize, 1 ); /*Q0*/ } } - ELSE IF( GT_16( tmp2, 16224 /*3,9609375 in Q12*/ ) ) + ELSE IF( GT_16( tmp2, 16224 /*3.9609375 in Q12*/ ) ) { Word16 tmpNewSize = shr( bufferOldSize, 1 ); WHILE( LT_16( bufferNewSize, bufferOldSize ) ) { BASOP_Util_Divide_MantExp( bufferOldSize, 0, bufferNewSize, 0, &tmp2, &tmpexp ); - tmp2 = shr( tmp2, 3 ); /*Q12*/ - tmp2 = shl( tmp2, tmpexp ); + tmp2 = shr( tmp2, 3 ); /*Q12*/ + tmp2 = shl( tmp2, tmpexp ); /*Q12+tmpexp*/ - if ( LE_16( tmp2, 16224 /*3,9609375 in Q12*/ ) ) + if ( LE_16( tmp2, 16224 /*3.9609375 in Q12*/ ) ) { - tmpNewSize = bufferNewSize; + tmpNewSize = bufferNewSize; /*Q0*/ move16(); } lerp_proc( f, f_out, tmpNewSize, bufferOldSize ); - f = f_out; - bufferOldSize = tmpNewSize; + f = f_out; /*Qx*/ + bufferOldSize = tmpNewSize; /*Q0*/ move16(); - tmpNewSize = shr( tmpNewSize, 1 ); + tmpNewSize = shr( tmpNewSize, 1 ); /*Q0*/ } } ELSE @@ -267,7 +267,7 @@ void lerp( const Word16 *f, Word16 *f_out, Word16 bufferNewSize, Word16 bufferOl * * * * *-------------------------------------------------------------*/ -static void lerp_proc( const Word16 *f, Word16 *f_out, Word16 bufferNewSize, Word16 bufferOldSize ) +static void lerp_proc( const Word16 *f /*Qx*/, Word16 *f_out /*Qx*/, Word16 bufferNewSize /*Q0*/, Word16 bufferOldSize /*Q0*/ ) { Word16 i, idx, n; @@ -276,29 +276,29 @@ static void lerp_proc( const Word16 *f, Word16 *f_out, Word16 bufferNewSize, Wor Word16 buf[2 * L_FRAME_MAX]; Word16 *ptr; - ptr = f_out; + ptr = f_out; /*Qx*/ test(); test(); test(); if ( ( ( f <= f_out ) && ( f + bufferOldSize >= f_out ) ) || ( ( f_out <= f ) && ( f_out + bufferNewSize >= f ) ) ) { - ptr = buf; + ptr = buf; /*Qx*/ } IF( EQ_16( bufferNewSize, bufferOldSize ) ) { - Copy( f, f_out, bufferNewSize ); + Copy( f, f_out, bufferNewSize ); /*Qx*/ return; } - shift = L_shl( L_deposit_l( div_s( bufferOldSize, shl( bufferNewSize, 4 ) ) ), 4 - shift_e + 16 ); + shift = L_shl( L_deposit_l( div_s( bufferOldSize, shl( bufferNewSize, 4 ) ) ), 4 - shift_e + 16 ); /*Q16*/ - pos = L_sub( L_shr( shift, 1 ), 32768l /*1.0f Q15*/ ); + pos = L_sub( L_shr( shift, 1 ), 32768l /*0.5f Q16*/ ); /*Q16*/ /* Adjust interpolation shift to avoid accessing beyond end of input buffer. */ if ( LT_32( shift, 19661l /*0.3f Q16*/ ) ) { - pos = L_sub( pos, 8520l /*0.13f Q16*/ ); + pos = L_sub( pos, 8520l /*0.13f Q16*/ ); /*Q16*/ } assert( pos_e == shift_e ); @@ -307,11 +307,11 @@ static void lerp_proc( const Word16 *f, Word16 *f_out, Word16 bufferNewSize, Wor IF( pos < 0 ) { - diff = shr( extract_l( pos ), 1 ); + diff = shr( extract_l( pos ), 1 ); /*Q15*/ /*buf[0]=f[0]+pos*(f[1]-f[0]);*/ move16(); #ifdef BASOP_NOGLOB - *ptr++ = add_sat( f[0], msu_r( L_mult( diff, f[1] ), diff, f[0] ) ); + *ptr++ = add_sat( f[0], msu_r( L_mult( diff, f[1] ), diff, f[0] ) ); /*Qx*/ #else *ptr++ = add( f[0], msu_r( L_mult( diff, f[1] ), diff, f[0] ) ); #endif @@ -319,13 +319,13 @@ static void lerp_proc( const Word16 *f, Word16 *f_out, Word16 bufferNewSize, Wor ELSE { - idx = extract_h( pos ); + idx = extract_h( pos ); /*Q0*/ - diff = lshr( extract_l( pos ), 1 ); + diff = lshr( extract_l( pos ), 1 ); /*Q15*/ move16(); #ifdef BASOP_NOGLOB - *ptr++ = add_sat( f[idx], msu_r_sat( L_mult( diff, f[idx + 1] ), diff, f[idx] ) ); + *ptr++ = add_sat( f[idx], msu_r_sat( L_mult( diff, f[idx + 1] ), diff, f[idx] ) ); /*Qx*/ #else *ptr++ = add( f[idx], msu_r( L_mult( diff, f[idx + 1] ), diff, f[idx] ) ); #endif @@ -337,21 +337,21 @@ static void lerp_proc( const Word16 *f, Word16 *f_out, Word16 bufferNewSize, Wor n = sub( bufferNewSize, 1 ); FOR( i = 1; i < n; i++ ) { - diff = lshr( extract_l( pos ), 1 ); + diff = lshr( extract_l( pos ), 1 ); /*Q15*/ if ( pos < 0 ) { - diff = sub( 16384 /*0.5f Q15*/, diff ); + diff = sub( 16384 /*0.5f Q15*/, diff ); /*Q15*/ } move16(); #ifdef BASOP_NOGLOB - *ptr++ = add_sat( f[idx], msu_r_sat( L_mult( diff, f[idx + 1] ), diff, f[idx] ) ); + *ptr++ = add_sat( f[idx], msu_r_sat( L_mult( diff, f[idx + 1] ), diff, f[idx] ) ); /*Qx*/ #else *ptr++ = add( f[idx], msu_r( L_mult( diff, f[idx + 1] ), diff, f[idx] ) ); #endif pos = L_add( pos, shift ); - idx = extract_h( pos ); + idx = extract_h( pos ); /*Q0*/ } /* last point */ @@ -363,11 +363,11 @@ static void lerp_proc( const Word16 *f, Word16 *f_out, Word16 bufferNewSize, Wor assert( idx <= 2 * L_FRAME_MAX ); /* diff = t - point;*/ - diff = lshr( extract_l( L_shr( L_sub( pos, L_deposit_h( idx ) ), 1 ) ), 1 ); + diff = lshr( extract_l( L_shr( L_sub( pos, L_deposit_h( idx ) ), 1 ) ), 1 ); /*Q15*/ move16(); #ifdef BASOP_NOGLOB - *ptr++ = add_sat( f[idx], shl_sat( msu_r_sat( L_mult( diff, f[idx + 1] ), diff, f[idx] ), 1 ) ); + *ptr++ = add_sat( f[idx], shl_sat( msu_r_sat( L_mult( diff, f[idx + 1] ), diff, f[idx] ), 1 ) ); /*Qx*/ #else *ptr++ = add( f[idx], shl( msu_r( L_mult( diff, f[idx + 1] ), diff, f[idx] ), 1 ) ); #endif @@ -376,12 +376,12 @@ static void lerp_proc( const Word16 *f, Word16 *f_out, Word16 bufferNewSize, Wor test(); IF( ( ( f <= f_out ) && ( f + bufferOldSize >= f_out ) ) || ( ( f_out <= f ) && ( f_out + bufferNewSize >= f ) ) ) { - Copy( buf, f_out, bufferNewSize ); + Copy( buf, f_out, bufferNewSize ); /*Qx*/ } } -static void lerp_proc32( Word32 *f, Word32 *f_out, Word16 bufferNewSize, Word16 bufferOldSize ) +static void lerp_proc32( Word32 *f /*Qx*/, Word32 *f_out /*Qx*/, Word16 bufferNewSize /*Q0*/, Word16 bufferOldSize /*Q0*/ ) { Word16 i, idx, n; @@ -390,29 +390,29 @@ static void lerp_proc32( Word32 *f, Word32 *f_out, Word16 bufferNewSize, Word16 Word32 buf[2 * L_FRAME_MAX]; Word32 *ptr; - ptr = f_out; + ptr = f_out; /*Qx*/ test(); test(); test(); if ( ( ( f <= f_out ) && ( f + bufferOldSize >= f_out ) ) || ( ( f_out <= f ) && ( f_out + bufferNewSize >= f ) ) ) { - ptr = buf; + ptr = buf; /*Qx*/ } IF( EQ_16( bufferNewSize, bufferOldSize ) ) { - Copy32( f, f_out, bufferNewSize ); + Copy32( f, f_out, bufferNewSize ); /*Qx*/ return; } - shift = L_shl( L_deposit_l( div_s( bufferOldSize, shl( bufferNewSize, 4 ) ) ), add( sub( 4, shift_e ), Q16 ) ); + shift = L_shl( L_deposit_l( div_s( bufferOldSize, shl( bufferNewSize, 4 ) ) ), add( sub( 4, shift_e ), Q16 ) ); /*Q16*/ - pos = L_sub( L_shr( shift, 1 ), 32768l /*1.0f Q15*/ ); + pos = L_sub( L_shr( shift, 1 ), 32768l /*0.5f Q16*/ ); /*Q16*/ /* Adjust interpolation shift to avoid accessing beyond end of input buffer. */ if ( LT_32( shift, 19661l /*0.3f Q16*/ ) ) { - pos = L_sub( pos, 8520l /*0.13f Q16*/ ); + pos = L_sub( pos, 8520l /*0.13f Q16*/ ); /*Q16*/ } assert( pos_e == shift_e ); @@ -421,22 +421,22 @@ static void lerp_proc32( Word32 *f, Word32 *f_out, Word16 bufferNewSize, Word16 IF( pos < 0 ) { - diff = shr( extract_l( pos ), 1 ); + diff = shr( extract_l( pos ), 1 ); /*Q15*/ /*buf[0]=f[0]+pos*(f[1]-f[0]);*/ - *ptr++ = L_add_sat( f[0], Mpy_32_16_1( L_sub( f[1], f[0] ), diff ) ); + *ptr++ = L_add_sat( f[0], Mpy_32_16_1( L_sub( f[1], f[0] ), diff ) ); /*Qx*/ move32(); } ELSE { - idx = extract_h( pos ); - diff = lshr( extract_l( pos ), 1 ); - *ptr++ = L_add_sat( f[idx], Mpy_32_16_1( L_sub( f[add( idx, 1 )], f[idx] ), diff ) ); + idx = extract_h( pos ); /*Q0*/ + diff = lshr( extract_l( pos ), 1 ); /*Q15*/ + *ptr++ = L_add_sat( f[idx], Mpy_32_16_1( L_sub( f[( idx + 1 )], f[idx] ), diff ) ); /*Qx*/ move32(); } - pos = L_add( pos, shift ); - idx = s_max( 0, extract_h( pos ) ); + pos = L_add( pos, shift ); /*Q16*/ + idx = s_max( 0, extract_h( pos ) ); /*Q0*/ n = sub( bufferNewSize, 1 ); FOR( i = 1; i < n; i++ ) @@ -444,11 +444,11 @@ static void lerp_proc32( Word32 *f, Word32 *f_out, Word16 bufferNewSize, Word16 diff = lshr( extract_l( pos ), 1 ); if ( pos < 0 ) { - diff = sub( 16384 /*0.5f Q15*/, diff ); + diff = sub( 16384 /*0.5f Q15*/, diff ); /*Q15*/ } - *ptr++ = L_add_sat( f[idx], Mpy_32_16_1( L_sub( f[idx + 1], f[idx] ), diff ) ); + *ptr++ = L_add_sat( f[idx], Mpy_32_16_1( L_sub( f[idx + 1], f[idx] ), diff ) ); /*Qx*/ move32(); - pos = L_add( pos, shift ); + pos = L_add( pos, shift ); /*Q16*/ idx = extract_h( pos ); } @@ -461,16 +461,16 @@ static void lerp_proc32( Word32 *f, Word32 *f_out, Word16 bufferNewSize, Word16 assert( idx <= 2 * L_FRAME_MAX ); /* diff = t - point;*/ - diff = lshr( extract_l( L_shr( L_sub( pos, L_deposit_h( idx ) ), 1 ) ), 1 ); + diff = lshr( extract_l( L_shr( L_sub( pos, L_deposit_h( idx ) ), 1 ) ), 1 ); /*Q15*/ - *ptr++ = L_add_sat( f[idx], L_shl_sat( Mpy_32_16_1( L_sub( f[add( idx, 1 )], f[idx] ), diff ), 1 ) ); + *ptr++ = L_add_sat( f[idx], L_shl_sat( Mpy_32_16_1( L_sub( f[( idx + 1 )], f[idx] ), diff ), 1 ) ); /*Qx*/ move32(); test(); test(); test(); IF( ( ( f <= f_out ) && ( f + bufferOldSize >= f_out ) ) || ( ( f_out <= f ) && ( f_out + bufferNewSize >= f ) ) ) { - Copy32( buf, f_out, bufferNewSize ); + Copy32( buf, f_out, bufferNewSize ); /*Qx*/ } } @@ -483,22 +483,22 @@ static void L_lerp_proc_fx( const Word32 *f_fx, Word32 *f_out_fx, const Word16 b * * *-------------------------------------------------------------*/ -void L_lerp_fx( Word32 *f, Word32 *f_out, Word16 bufferNewSize, Word16 bufferOldSize, Word16 *q ) +void L_lerp_fx( Word32 *f /*q*/, Word32 *f_out /*q*/, Word16 bufferNewSize /*Q0*/, Word16 bufferOldSize /*Q0*/, Word16 *q ) { Word16 tmpNewSize; Word16 tmp1, tmp2, tmp_e; - tmp1 = BASOP_Util_Divide1616_Scale( bufferNewSize, bufferOldSize, &tmp_e ); - tmp1 = shr( tmp1, sub( 15, tmp_e ) ); + tmp1 = BASOP_Util_Divide1616_Scale( bufferNewSize, bufferOldSize, &tmp_e ); /*Q15 - tmp_e*/ + tmp1 = shr( tmp1, sub( 15, tmp_e ) ); /*Q0*/ - tmp2 = BASOP_Util_Divide1616_Scale( bufferOldSize, bufferNewSize, &tmp_e ); - tmp2 = shr( tmp2, sub( 15, tmp_e ) ); + tmp2 = BASOP_Util_Divide1616_Scale( bufferOldSize, bufferNewSize, &tmp_e ); /*Q15 - tmp_e*/ + tmp2 = shr( tmp2, sub( 15, tmp_e ) ); /*Q0*/ Word16 guard_bits = add( s_max( tmp1, tmp2 ), 1 ); IF( LT_16( getScaleFactor32( f, bufferOldSize ), guard_bits ) ) { *q = sub( *q, guard_bits ); FOR( Word16 ind = 0; ind < bufferNewSize; ind++ ) { - f[ind] = L_shr( f[ind], guard_bits ); + f[ind] = L_shr( f[ind], guard_bits ); /*Q(guard_bits)*/ move32(); } #ifndef MSAN_FIX @@ -509,40 +509,40 @@ void L_lerp_fx( Word32 *f, Word32 *f_out, Word16 bufferNewSize, Word16 bufferOld IF( GT_32( L_mult0( 128, bufferNewSize ), L_mult0( bufferOldSize, 507 ) ) ) { - tmpNewSize = shl( bufferOldSize, 1 ); + tmpNewSize = shl( bufferOldSize, 1 ); /*Q0*/ WHILE( GT_16( bufferNewSize, bufferOldSize ) ) { if ( LE_32( L_mult0( 128, bufferNewSize ), L_mult0( bufferOldSize, 507 ) ) ) { - tmpNewSize = bufferNewSize; + tmpNewSize = bufferNewSize; /*Q0*/ move16(); } L_lerp_proc_fx( f, f_out, tmpNewSize, bufferOldSize ); f = f_out; - bufferOldSize = tmpNewSize; + bufferOldSize = tmpNewSize; /*Q0*/ move16(); - tmpNewSize = shl( tmpNewSize, 1 ); + tmpNewSize = shl( tmpNewSize, 1 ); /*Q0*/ } } ELSE IF( GT_32( L_mult0( 128, bufferOldSize ), L_mult0( bufferNewSize, 507 ) ) ) { - tmpNewSize = shr( bufferOldSize, 1 ); + tmpNewSize = shr( bufferOldSize, 1 ); /*Q0*/ WHILE( LT_16( bufferNewSize, bufferOldSize ) ) { if ( LE_32( L_mult0( 128, bufferOldSize ), L_mult0( bufferNewSize, 507 ) ) ) { - tmpNewSize = bufferNewSize; + tmpNewSize = bufferNewSize; /*Q0*/ move16(); } L_lerp_proc_fx( f, f_out, tmpNewSize, bufferOldSize ); - f = f_out; - bufferOldSize = tmpNewSize; + f = f_out; /*q*/ + bufferOldSize = tmpNewSize; /*Q0*/ move16(); - tmpNewSize = shr( tmpNewSize, 1 ); + tmpNewSize = shr( tmpNewSize, 1 ); /*Q0*/ } } ELSE @@ -552,46 +552,46 @@ void L_lerp_fx( Word32 *f, Word32 *f_out, Word16 bufferNewSize, Word16 bufferOld return; } -void L_lerp_fx_q11( Word32 *f, Word32 *f_out, Word16 bufferNewSize, Word16 bufferOldSize ) +void L_lerp_fx_q11( Word32 *f /*Q11*/, Word32 *f_out /*Q11*/, Word16 bufferNewSize /*Q0*/, Word16 bufferOldSize /*Q0*/ ) { Word16 tmpNewSize; IF( GT_32( L_mult0( 128, bufferNewSize ), L_mult0( bufferOldSize, 507 ) ) ) { - tmpNewSize = shl( bufferOldSize, 1 ); + tmpNewSize = shl( bufferOldSize, 1 ); /*Q0*/ WHILE( GT_16( bufferNewSize, bufferOldSize ) ) { if ( LE_32( L_mult0( 128, bufferNewSize ), L_mult0( bufferOldSize, 507 ) ) ) { - tmpNewSize = bufferNewSize; + tmpNewSize = bufferNewSize; /*Q0*/ move16(); } lerp_proc32( f, f_out, tmpNewSize, bufferOldSize ); - f = f_out; - bufferOldSize = tmpNewSize; + f = f_out; /*Q11*/ + bufferOldSize = tmpNewSize; /*Q0*/ move16(); - tmpNewSize = shl( tmpNewSize, 1 ); + tmpNewSize = shl( tmpNewSize, 1 ); /*Q0*/ } } ELSE IF( GT_32( L_mult0( 128, bufferOldSize ), L_mult0( bufferNewSize, 507 ) ) ) { - tmpNewSize = shr( bufferOldSize, 1 ); + tmpNewSize = shr( bufferOldSize, 1 ); /*Q0*/ WHILE( LT_16( bufferNewSize, bufferOldSize ) ) { if ( LE_32( L_mult0( 128, bufferOldSize ), L_mult0( bufferNewSize, 507 ) ) ) { - tmpNewSize = bufferNewSize; + tmpNewSize = bufferNewSize; /*Q0*/ move16(); } lerp_proc32( f, f_out, tmpNewSize, bufferOldSize ); f = f_out; - bufferOldSize = tmpNewSize; + bufferOldSize = tmpNewSize; /*Q0*/ move16(); - tmpNewSize = shr( tmpNewSize, 1 ); + tmpNewSize = shr( tmpNewSize, 1 ); /*Q0*/ } } ELSE @@ -608,10 +608,10 @@ void L_lerp_fx_q11( Word32 *f, Word32 *f_out, Word16 bufferNewSize, Word16 buffe * * *-------------------------------------------------------------*/ static void L_lerp_proc_fx( - const Word32 *f_fx, - Word32 *f_out_fx, - const Word16 bufferNewSize, - const Word16 bufferOldSize ) + const Word32 *f_fx, /*Qx*/ + Word32 *f_out_fx, /*Qx*/ + const Word16 bufferNewSize, /*Q0*/ + const Word16 bufferOldSize /*Q0*/ ) { Word16 i, idx; Word32 pos_fx, shift_fx, diff_fx; @@ -620,62 +620,62 @@ static void L_lerp_proc_fx( IF( EQ_16( bufferNewSize, bufferOldSize ) ) { - Copy32( f_fx, buf_fx, bufferNewSize ); - Copy32( buf_fx, f_out_fx, bufferNewSize ); + Copy32( f_fx, buf_fx, bufferNewSize ); /*Qx*/ + Copy32( buf_fx, f_out_fx, bufferNewSize ); /*Qx*/ return; } /* Using the basop code to avoid reading beyond end of input for bufferOldSize=320, bufferNewSize=640 */ - tmp = div_s( bufferOldSize, shl( bufferNewSize, 4 ) ); - shift_fx = L_shl( L_deposit_l( tmp ), 4 - 15 + 21 ); // q =21 - pos_fx = Mpy_32_32( L_sub( shift_fx, 1 << 21 ), 1073741824 ); + tmp = div_s( bufferOldSize, shl( bufferNewSize, 4 ) ); /*Q11*/ + shift_fx = L_shl( L_deposit_l( tmp ), 4 - 15 + 21 ); // q =21 + pos_fx = Mpy_32_32( L_sub( shift_fx, 1 << 21 ), ONE_IN_Q30 /*0.5f in Q31*/ ); /*Q21*/ - IF( LT_32( shift_fx, L_shr( 644245094, 31 - 21 ) ) ) + IF( LT_32( shift_fx, L_shr( 644245094 /*0.3 in Q31*/, 31 - 21 ) ) ) { - pos_fx = L_sub( pos_fx, L_shr( 279172874, 31 - 21 ) ); + pos_fx = L_sub( pos_fx, L_shr( 279172874 /*0.13 in Q31*/, 31 - 21 ) ); /*Q21*/ } /* first point of interpolation */ IF( pos_fx < 0 ) { - buf_fx[0] = L_add( f_fx[0], L_shl( Mpy_32_32( pos_fx, L_sub( f_fx[1], f_fx[0] ) ), 31 - 21 ) ); + buf_fx[0] = L_add( f_fx[0], L_shl( Mpy_32_32( pos_fx, L_sub( f_fx[1], f_fx[0] ) ), 31 - 21 ) ); /*Qx*/ move32(); } ELSE { idx = extract_l( L_shr( pos_fx, 21 ) ); - diff_fx = L_sub( pos_fx, L_shl( idx, 21 ) ); - buf_fx[0] = L_add( f_fx[idx], L_shl( Mpy_32_32( diff_fx, L_sub( f_fx[add( idx, 1 )], f_fx[idx] ) ), 31 - 21 ) ); + diff_fx = L_sub( pos_fx, L_shl( idx, 21 ) ); /*Q21*/ + buf_fx[0] = L_add( f_fx[idx], L_shl( Mpy_32_32( diff_fx, L_sub( f_fx[( idx + 1 )], f_fx[idx] ) ), 31 - 21 ) ); /*Qx*/ move32(); } - pos_fx = L_add( pos_fx, shift_fx ); + pos_fx = L_add( pos_fx, shift_fx ); /*Q21*/ FOR( i = 1; i < bufferNewSize - 1; i++ ) { idx = extract_l( L_shr( pos_fx, 21 ) ); - diff_fx = L_sub( pos_fx, L_shl( idx, 21 ) ); + diff_fx = L_sub( pos_fx, L_shl( idx, 21 ) ); /*Q21*/ - buf_fx[i] = L_add( f_fx[idx], L_shl( Mpy_32_32( diff_fx, L_sub( f_fx[idx + 1], f_fx[idx] ) ), 31 - 21 ) ); + buf_fx[i] = L_add( f_fx[idx], L_shl( Mpy_32_32( diff_fx, L_sub( f_fx[idx + 1], f_fx[idx] ) ), 31 - 21 ) ); /*Qx*/ move32(); - pos_fx = L_add( pos_fx, shift_fx ); + pos_fx = L_add( pos_fx, shift_fx ); /*Q21*/ } /* last point */ - idx = extract_l( L_shr( pos_fx, 21 ) ); + idx = extract_l( L_shr( pos_fx, 21 ) ); /*Q0*/ if ( GT_32( pos_fx, L_shl( sub( bufferOldSize, 1 ), 21 ) ) ) { idx = sub( bufferOldSize, 2 ); } - diff_fx = L_sub( pos_fx, L_shl( idx, 21 ) ); + diff_fx = L_sub( pos_fx, L_shl( idx, 21 ) ); /*Q21*/ - buf_fx[sub( bufferNewSize, 1 )] = L_add( f_fx[idx], L_shl( Mpy_32_32( diff_fx, L_sub( f_fx[add( idx, 1 )], f_fx[idx] ) ), 31 - 21 ) ); + buf_fx[( bufferNewSize - 1 )] = L_add( f_fx[idx], L_shl( Mpy_32_32( diff_fx, L_sub( f_fx[( idx + 1 )], f_fx[idx] ) ), 31 - 21 ) ); /*Qx*/ move32(); - Copy32( buf_fx, f_out_fx, bufferNewSize ); + Copy32( buf_fx, f_out_fx, bufferNewSize ); /*Qx*/ return; } diff --git a/lib_com/limit_t0_fx.c b/lib_com/limit_t0_fx.c index 9fc8ac789..d3cff10d9 100644 --- a/lib_com/limit_t0_fx.c +++ b/lib_com/limit_t0_fx.c @@ -23,14 +23,14 @@ *-------------------------------------------------*/ void limit_T0_fx( - const Word16 L_frame, /* i : length of the frame */ - const Word16 delta, /* i : Half the close-loop searched interval */ - const Word16 pit_flag, /* i : selecting absolute(0) or delta(1) pitch quantization */ - const Word16 limit_flag, /* i : flag for Q limits (0=restrained, 1=extended) */ - const Word16 T0, /* i : rough pitch estimate around which the search is done */ - const Word16 T0_frac, /* i : pitch estimate fractional part */ - Word16 *T0_min, /* o : lower pitch limit */ - Word16 *T0_max /* o : higher pitch limit */ + const Word16 L_frame, /* i : length of the frame Q0*/ + const Word16 delta, /* i : Half the close-loop searched interval Q0*/ + const Word16 pit_flag, /* i : selecting absolute(0) or delta(1) pitch quantization Q0*/ + const Word16 limit_flag, /* i : flag for Q limits (0=restrained, 1=extended) Q0*/ + const Word16 T0, /* i : rough pitch estimate around which the search is done Q0*/ + const Word16 T0_frac, /* i : pitch estimate fractional part Q0*/ + Word16 *T0_min, /* o : lower pitch limit Q0*/ + Word16 *T0_max /* o : higher pitch limit Q0*/ ) { @@ -55,7 +55,7 @@ void limit_T0_fx( move16(); } - delta2 = sub( shl( delta, 1 ), 1 ); + delta2 = sub( shl( delta, 1 ), 1 ); /*Q0*/ T1 = T0; move16(); @@ -104,7 +104,7 @@ void limit_T0_fx( move16(); } - delta2 = sub( shl( delta, 1 ), 1 ); + delta2 = sub( shl( delta, 1 ), 1 ); /*Q0*/ move16(); T1 = T0; move16(); @@ -118,7 +118,7 @@ void limit_T0_fx( { /* subframes with absolute search: keep Q range */ *T0_min = s_max( *T0_min, pit_min ); - + move16(); *T0_max = add( *T0_min, delta2 ); move16(); IF( GT_16( *T0_max, pit_max ) ) @@ -136,6 +136,7 @@ void limit_T0_fx( move16(); *T0_min = s_max( *T0_min, L_INTERPOL ); + move16(); *T0_max = *T0_min + delta2; move16(); @@ -162,15 +163,15 @@ void limit_T0_fx( void limit_T0_voiced( const Word16 nbits, const Word16 res, - const Word16 T0, /* i : rough pitch estimate around which the search is done */ - const Word16 T0_frac, /* i : pitch estimate fractional part */ - const Word16 T0_res, /* i : pitch resolution */ - Word16 *T0_min, /* o : lower pitch limit */ - Word16 *T0_min_frac, /* o : lower pitch limit */ - Word16 *T0_max, /* o : higher pitch limit */ - Word16 *T0_max_frac, /* o : higher pitch limit */ - const Word16 pit_min, /* i : Minimum pitch lag */ - const Word16 pit_max /* i : Maximum pitch lag */ + const Word16 T0, /* i : rough pitch estimate around which the search is done Q0*/ + const Word16 T0_frac, /* i : pitch estimate fractional part Q0*/ + const Word16 T0_res, /* i : pitch resolution Q0*/ + Word16 *T0_min, /* o : lower pitch limit Q0*/ + Word16 *T0_min_frac, /* o : lower pitch limit Q0*/ + Word16 *T0_max, /* o : higher pitch limit Q0*/ + Word16 *T0_max_frac, /* o : higher pitch limit Q0*/ + const Word16 pit_min, /* i : Minimum pitch lag Q0*/ + const Word16 pit_max /* i : Maximum pitch lag Q0*/ ) { Word16 T1, temp1, temp2, res2; @@ -178,15 +179,15 @@ void limit_T0_voiced( assert( res > 1 && res <= 6 ); - res2 = res; + res2 = res; /*Q0*/ move16(); if ( EQ_16( res, 6 ) ) { - res2 = shr( res2, 1 ); + res2 = shr( res2, 1 ); /*Q0*/ } /* Mid-point */ - T1 = T0; + T1 = T0; /*Q0*/ test(); if ( GT_16( T0_res, 1 ) && GE_16( T0_frac, ( shr( T0_res, 1 ) ) ) ) { @@ -194,12 +195,12 @@ void limit_T0_voiced( } /* Lower-bound */ - temp1 = sub( i_mult( T1, res ), shl( 1, sub( nbits, 1 ) ) ); + temp1 = sub( i_mult( T1, res ), shl( 1, sub( nbits, 1 ) ) ); /*Q0*/ temp2 = mult( temp1, inv_T0_res[res2] ); if ( EQ_16( res, 6 ) ) { - temp2 = shr( temp2, 1 ); + temp2 = shr( temp2, 1 ); /*Q0*/ } *T0_min = temp2; @@ -217,7 +218,7 @@ void limit_T0_voiced( } /* Higher-bound */ - temp1 = add( i_mult( *T0_min, res ), add( *T0_min_frac, sub( shl( 1, nbits ), 1 ) ) ); + temp1 = add( i_mult( *T0_min, res ), add( *T0_min_frac, sub( shl( 1, nbits ), 1 ) ) ); /*Q0*/ temp2 = mult( temp1, inv_T0_res[res2] ); if ( EQ_16( res, 6 ) ) @@ -241,15 +242,15 @@ void limit_T0_voiced( temp1 = add( i_mult( *T0_max, res ), sub( *T0_max_frac, sub( shl( 1, nbits ), 1 ) ) ); - temp2 = mult( temp1, inv_T0_res[res2] ); + temp2 = mult( temp1, inv_T0_res[res2] ); /*Q0*/ if ( EQ_16( res, 6 ) ) { - temp2 = shr( temp2, 1 ); + temp2 = shr( temp2, 1 ); /*Q0*/ } move16(); *T0_min = temp2; - *T0_min_frac = sub( temp1, i_mult( temp2, res ) ); + *T0_min_frac = sub( temp1, i_mult( temp2, res ) ); /*Q0*/ move16(); } diff --git a/lib_com/lsf_tools_fx.c b/lib_com/lsf_tools_fx.c index d3694637e..ce812b19d 100644 --- a/lib_com/lsf_tools_fx.c +++ b/lib_com/lsf_tools_fx.c @@ -863,11 +863,13 @@ Word16 E_LPC_f_lsp_pol_get( const Word16 lsp[], Word32 f[], const Word16 n, cons Word16 b; Word32 b32; Word16 Ovf = 0; + move16(); Word16 Q_out; Word16 m2; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move16(); #endif Q_out = 31 - 23; @@ -876,7 +878,7 @@ Word16 E_LPC_f_lsp_pol_get( const Word16 lsp[], Word32 f[], const Word16 n, cons move16(); test(); - if ( past_Ovf && isMODE1 ) /* Currently this feature is implemented only in MODE1 */ + IF( past_Ovf && isMODE1 ) /* Currently this feature is implemented only in MODE1 */ { /* In some NB cases, overflow where detectected in f1 or f2 polynomial computation when it diff --git a/lib_com/prot.h b/lib_com/prot.h index d0f46467a..4f795250c 100644 --- a/lib_com/prot.h +++ b/lib_com/prot.h @@ -9243,7 +9243,7 @@ ivas_error openCldfb_ivas( ivas_error openCldfb_ivas_enc( HANDLE_CLDFB_FILTER_BANK *h_cldfb, /* i/o: filter bank handle */ CLDFB_TYPE type, /* i : analysis or synthesis */ - const int32_t sampling_rate, /* i : sampling rate */ + const Word32 sampling_rate, /* i : sampling rate */ CLDFB_PROTOTYPE prototype /* i : CLDFB version (1.25ms/5ms delay) */ ); @@ -9969,12 +9969,6 @@ int16_t getResq( const int32_t total_brate /* i : total bitrate */ ); -int16_t getRestrictedMode( - const int16_t element_mode, /* i : IVAS element mode */ - const int32_t total_brate, /* i : total bitrate */ - const int16_t Opt_AMR_WB /* i : flag indicating AMR-WB IO mode */ -); - int16_t getMdctWindowLength( const int16_t fscale ); diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index be0a12fa6..df01a6775 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -3988,10 +3988,10 @@ Word16 getTnsAllowed( const Word16 element_mode /* i : IVAS element mode */ ); -int16_t getRestrictedMode( - const int16_t element_mode, /* i : IVAS element mode */ - const int32_t total_brate, /* i : total bitrate */ - const int16_t Opt_AMR_WB /* i : flag indicating AMR-WB IO mode */ +Word16 getRestrictedMode( + const Word16 element_mode, /* i : IVAS element mode */ + const Word32 total_brate, /* i : total bitrate */ + const Word16 Opt_AMR_WB /* i : flag indicating AMR-WB IO mode */ ); Word16 getMdctWindowLength_fx( diff --git a/lib_com/residu_fx.c b/lib_com/residu_fx.c index c2e6d43a6..4a543c9ec 100644 --- a/lib_com/residu_fx.c +++ b/lib_com/residu_fx.c @@ -155,11 +155,14 @@ void Residu3_fx( move16(); #endif q = add( norm_s( a[0] ), 1 ); - if ( shift != 0 ) + IF( shift != 0 ) + { q = add( q, shift ); + } FOR( i = 0; i < lg; i++ ) { s64 = 0; + move64(); FOR( j = 0; j <= 15; j++ ) { s64 = W_mac_16_16( s64, x[i - j], a[j] ); @@ -168,6 +171,7 @@ void Residu3_fx( s32 = W_shl_sat_l( s64, q ); #ifdef BASOP_NOGLOB y[i] = round_fx_o( s32, &Overflow ); + move16(); #else /* BASOP_NOGLOB */ y[i] = round_fx( s32 ); #endif diff --git a/lib_com/tcq_position_arith_fx.c b/lib_com/tcq_position_arith_fx.c index 2cc28e853..581ef7395 100644 --- a/lib_com/tcq_position_arith_fx.c +++ b/lib_com/tcq_position_arith_fx.c @@ -2671,7 +2671,7 @@ Word16 GetScale_fx( ab = L_add( a, b ); - p_est = extract_h( L_shl( Pow2( extract_l( L_shr( ab, 15 ) ), L_and( ab, 0x7FFF ) ), 16 ) ); /* enable saturationof pow2 result */ + p_est = extract_h( L_shl( Pow2( extract_l( L_shr( ab, 15 ) ), extract_l( L_and( ab, 0x7FFF ) ) ), 16 ) ); /* enable saturationof pow2 result */ pulses = s_min( p_est, MAX_PULSES ); diff --git a/lib_com/tcx_mdct_window.c b/lib_com/tcx_mdct_window.c index c466a8271..ae72d9cc6 100644 --- a/lib_com/tcx_mdct_window.c +++ b/lib_com/tcx_mdct_window.c @@ -414,6 +414,7 @@ void mdct_window_aldo( p1 = window_256kHz; /* Q15 */ p2 = window_256kHz + 592 - 1; /* Q15 */ d = 2; + move16(); BREAK; case 640 / 2: p1 = window_48kHz_fx + 1; /* Q15 */ @@ -431,6 +432,7 @@ void mdct_window_aldo( p1 = window_48kHz_fx + 1; /* Q15 */ p2 = window_48kHz_fx + 1110 - 2; /* Q15 */ d = 3; + move16(); BREAK; case 1920 / 2: p1 = window_48kHz_fx; /* Q15 */ diff --git a/lib_com/tcx_utils_fx.c b/lib_com/tcx_utils_fx.c index 1d3ddc310..dab13dff4 100644 --- a/lib_com/tcx_utils_fx.c +++ b/lib_com/tcx_utils_fx.c @@ -41,13 +41,13 @@ Word16 getInvFrameLen( /* returns 1/L_frame in Q21 format */ * ------------------------------------------------------------------ - */ void tcx_get_windows( TCX_CONFIG_HANDLE hTcxCfg, /* i : TCX configuration */ - const Word16 left_mode, /* i: overlap mode of left window half */ - const Word16 right_mode, /* i: overlap mode of right window half */ - Word16 *left_overlap, /* o: left overlap length */ - const PWord16 **left_win, /* o: left overlap window */ - Word16 *right_overlap, /* o: right overlap length */ - const PWord16 **right_win, /* o: right overlap window */ - const Word8 fullband /* i: fullband flag */ + const Word16 left_mode, /* i: overlap mode of left window half Q0*/ + const Word16 right_mode, /* i: overlap mode of right window half Q0*/ + Word16 *left_overlap, /* o: left overlap length Q0*/ + const PWord16 **left_win, /* o: left overlap window Q15*/ + Word16 *right_overlap, /* o: right overlap length Q0*/ + const PWord16 **right_win, /* o: right overlap window Q15*/ + const Word8 fullband /* i: fullband flag Q0*/ ) { /* LFE is only FULL_OVERLAP*/ IF( fullband == 0 ) @@ -55,25 +55,25 @@ void tcx_get_windows( /* Left part */ SWITCH( left_mode ) { - case TRANSITION_OVERLAP: /* ACELP->TCX transition */ - *left_overlap = hTcxCfg->tcx_mdct_window_trans_length; + case TRANSITION_OVERLAP: /* ACELP->TCX transition */ + *left_overlap = hTcxCfg->tcx_mdct_window_trans_length; /*Q0*/ move16(); - *left_win = hTcxCfg->tcx_mdct_window_trans; + *left_win = hTcxCfg->tcx_mdct_window_trans; /*Q15*/ BREAK; case MIN_OVERLAP: - *left_overlap = hTcxCfg->tcx_mdct_window_min_length; + *left_overlap = hTcxCfg->tcx_mdct_window_min_length; /*Q0*/ move16(); - *left_win = hTcxCfg->tcx_mdct_window_minimum; + *left_win = hTcxCfg->tcx_mdct_window_minimum; /*Q15*/ BREAK; case HALF_OVERLAP: - *left_overlap = hTcxCfg->tcx_mdct_window_half_length; + *left_overlap = hTcxCfg->tcx_mdct_window_half_length; /*Q0*/ move16(); - *left_win = hTcxCfg->tcx_mdct_window_half; + *left_win = hTcxCfg->tcx_mdct_window_half; /*Q15*/ BREAK; case FULL_OVERLAP: - *left_overlap = hTcxCfg->tcx_mdct_window_length; + *left_overlap = hTcxCfg->tcx_mdct_window_length; /*Q0*/ move16(); - *left_win = hTcxCfg->tcx_aldo_window_1_trunc; + *left_win = hTcxCfg->tcx_aldo_window_1_trunc; /*Q15*/ BREAK; default: assert( !"Not supported overlap" ); @@ -83,19 +83,19 @@ void tcx_get_windows( SWITCH( right_mode ) { case MIN_OVERLAP: - *right_overlap = hTcxCfg->tcx_mdct_window_min_length; + *right_overlap = hTcxCfg->tcx_mdct_window_min_length; /*Q0*/ move16(); - *right_win = hTcxCfg->tcx_mdct_window_minimum; + *right_win = hTcxCfg->tcx_mdct_window_minimum; /*Q15*/ BREAK; case HALF_OVERLAP: - *right_overlap = hTcxCfg->tcx_mdct_window_half_length; + *right_overlap = hTcxCfg->tcx_mdct_window_half_length; /*Q0*/ move16(); - *right_win = hTcxCfg->tcx_mdct_window_half; + *right_win = hTcxCfg->tcx_mdct_window_half; /*Q15*/ BREAK; case FULL_OVERLAP: - *right_overlap = hTcxCfg->tcx_mdct_window_delay; + *right_overlap = hTcxCfg->tcx_mdct_window_delay; /*Q0*/ move16(); - *right_win = hTcxCfg->tcx_aldo_window_2; + *right_win = hTcxCfg->tcx_aldo_window_2; /*Q15*/ BREAK; default: assert( !"Not supported overlap" ); @@ -106,20 +106,20 @@ void tcx_get_windows( /* Left part */ SWITCH( left_mode ) { - case TRANSITION_OVERLAP: /* ACELP->TCX transition */ - *left_overlap = hTcxCfg->tcx_mdct_window_trans_lengthFB; + case TRANSITION_OVERLAP: /* ACELP->TCX transition */ + *left_overlap = hTcxCfg->tcx_mdct_window_trans_lengthFB; /*Q0*/ move16(); - *left_win = hTcxCfg->tcx_mdct_window_transFB; + *left_win = hTcxCfg->tcx_mdct_window_transFB; /*Q15*/ BREAK; case MIN_OVERLAP: - *left_overlap = hTcxCfg->tcx_mdct_window_min_lengthFB; + *left_overlap = hTcxCfg->tcx_mdct_window_min_lengthFB; /*Q0*/ move16(); - *left_win = hTcxCfg->tcx_mdct_window_minimumFB; + *left_win = hTcxCfg->tcx_mdct_window_minimumFB; /*Q15*/ BREAK; case HALF_OVERLAP: - *left_overlap = hTcxCfg->tcx_mdct_window_half_lengthFB; + *left_overlap = hTcxCfg->tcx_mdct_window_half_lengthFB; /*Q0*/ move16(); - *left_win = hTcxCfg->tcx_mdct_window_halfFB; + *left_win = hTcxCfg->tcx_mdct_window_halfFB; /*Q15*/ BREAK; case RECTANGULAR_OVERLAP: *left_overlap = 0; @@ -127,9 +127,9 @@ void tcx_get_windows( *left_win = NULL; BREAK; case FULL_OVERLAP: - *left_overlap = hTcxCfg->tcx_mdct_window_lengthFB; + *left_overlap = hTcxCfg->tcx_mdct_window_lengthFB; /*Q0*/ move16(); - *left_win = hTcxCfg->tcx_aldo_window_1_FB_trunc; + *left_win = hTcxCfg->tcx_aldo_window_1_FB_trunc; /*Q15*/ BREAK; default: assert( !"Not supported overlap" ); @@ -139,14 +139,14 @@ void tcx_get_windows( SWITCH( right_mode ) { case MIN_OVERLAP: - *right_overlap = hTcxCfg->tcx_mdct_window_min_lengthFB; + *right_overlap = hTcxCfg->tcx_mdct_window_min_lengthFB; /*Q0*/ move16(); - *right_win = hTcxCfg->tcx_mdct_window_minimumFB; + *right_win = hTcxCfg->tcx_mdct_window_minimumFB; /*Q15*/ BREAK; case HALF_OVERLAP: - *right_overlap = hTcxCfg->tcx_mdct_window_half_lengthFB; + *right_overlap = hTcxCfg->tcx_mdct_window_half_lengthFB; /*Q0*/ move16(); - *right_win = hTcxCfg->tcx_mdct_window_halfFB; + *right_win = hTcxCfg->tcx_mdct_window_halfFB; /*Q15*/ BREAK; case RECTANGULAR_OVERLAP: *right_overlap = 0; @@ -154,9 +154,9 @@ void tcx_get_windows( *right_win = NULL; BREAK; case FULL_OVERLAP: - *right_overlap = hTcxCfg->tcx_mdct_window_delayFB; + *right_overlap = hTcxCfg->tcx_mdct_window_delayFB; /*Q0*/ move16(); - *right_win = hTcxCfg->tcx_aldo_window_2_FB; + *right_win = hTcxCfg->tcx_aldo_window_2_FB; /*Q15*/ BREAK; default: assert( !"Not supported overlap" ); @@ -165,48 +165,48 @@ void tcx_get_windows( } static void tcx_windowing_analysis( - Word16 const *signal, /* i: signal vector */ - Word16 L_frame, /* i: frame length */ - Word16 left_overlap, /* i: left overlap length */ - PWord16 const *left_win, /* i: left overlap window */ - Word16 right_overlap, /* i: right overlap length */ - PWord16 const *right_win, /* i: right overlap window */ - Word16 *output /* o: windowed signal vector */ + Word16 const *signal, /* i: signal vector Qx*/ + Word16 L_frame, /* i: frame length Q0*/ + Word16 left_overlap, /* i: left overlap length Q0*/ + PWord16 const *left_win, /* i: left overlap window Q15*/ + Word16 right_overlap, /* i: right overlap length Q0*/ + PWord16 const *right_win, /* i: right overlap window Q15*/ + Word16 *output /* o: windowed signal vector Qx*/ ) { Word16 w, n; /* Left overlap */ - n = shr( left_overlap, 1 ); + n = shr( left_overlap, 1 ); /*Q0*/ FOR( w = 0; w < n; w++ ) { - *output++ = mult_r( *signal++, left_win[w].v.im ); + *output++ = mult_r( *signal++, left_win[w].v.im ); /*Qx*/ move16(); } FOR( w = 0; w < n; w++ ) { - *output++ = mult_r( *signal++, left_win[n - 1 - w].v.re ); + *output++ = mult_r( *signal++, left_win[n - 1 - w].v.re ); /*Qx*/ move16(); } /* Non overlapping region */ - n = sub( L_frame, shr( add( left_overlap, right_overlap ), 1 ) ); + n = sub( L_frame, shr( add( left_overlap, right_overlap ), 1 ) ); /*Q0*/ FOR( w = 0; w < n; w++ ) { - *output++ = *signal++; + *output++ = *signal++; /*Qx*/ move16(); } /* Right overlap */ - n = shr( right_overlap, 1 ); + n = shr( right_overlap, 1 ); /*Q0*/ FOR( w = 0; w < n; w++ ) { - *output++ = mult_r( *signal++, right_win[w].v.re ); + *output++ = mult_r( *signal++, right_win[w].v.re ); /*Qx*/ move16(); } FOR( w = 0; w < n; w++ ) { - *output++ = mult_r( *signal++, right_win[n - 1 - w].v.im ); + *output++ = mult_r( *signal++, right_win[n - 1 - w].v.im ); /*Qx*/ move16(); } } @@ -217,16 +217,16 @@ static void tcx_windowing_analysis( *-------------------------------------------------------------------*/ void WindowSignal( TCX_CONFIG_HANDLE hTcxCfg, /* i : configuration of TCX */ - Word16 offset, /* i : left folding point offset relative to the input signal pointer */ - const Word16 left_overlap_mode, /* i : overlap mode of left window half */ - Word16 right_overlap_mode, /* i : overlap mode of right window half */ - Word16 *left_overlap_length, /* o : TCX window left overlap length */ - Word16 *right_overlap_length, /* o : TCX window right overlap length */ - const Word16 in[], /* i : input signal */ - Word16 *L_frame, /* i/o: frame length */ - Word16 out[], /* o : output windowed signal */ - const Word16 truncate_aldo, /* i : nonzero to truncate long ALDO slope */ - const Word8 fullband /* i : fullband flag */ + Word16 offset, /* i : left folding point offset relative to the input signal pointer Q0*/ + const Word16 left_overlap_mode, /* i : overlap mode of left window half Q0*/ + Word16 right_overlap_mode, /* i : overlap mode of right window half Q0*/ + Word16 *left_overlap_length, /* o : TCX window left overlap length Q0*/ + Word16 *right_overlap_length, /* o : TCX window right overlap length Q0*/ + const Word16 in[], /* i : input signal Qx*/ + Word16 *L_frame, /* i/o: frame length Q0*/ + Word16 out[], /* o : output windowed signal Qx*/ + const Word16 truncate_aldo, /* i : nonzero to truncate long ALDO slope Q0*/ + const Word8 fullband /* i : fullband flag Q0*/ ) { Word16 l, r; @@ -248,15 +248,15 @@ void WindowSignal( /* Increase frame size for 5ms */ IF( fullband == 0 ) { - *L_frame = add( *L_frame, hTcxCfg->tcx5Size ); + *L_frame = add( *L_frame, hTcxCfg->tcx5Size ); /*Q0*/ move16(); - offset = negate( shr( hTcxCfg->tcx_mdct_window_trans_length, 1 ) ); + offset = negate( shr( hTcxCfg->tcx_mdct_window_trans_length, 1 ) ); /*Q0*/ } ELSE { - *L_frame = add( *L_frame, hTcxCfg->tcx5SizeFB ); + *L_frame = add( *L_frame, hTcxCfg->tcx5SizeFB ); /*Q0*/ move16(); - offset = negate( shr( hTcxCfg->tcx_mdct_window_trans_lengthFB, 1 ) ); + offset = negate( shr( hTcxCfg->tcx_mdct_window_trans_lengthFB, 1 ) ); /*Q0*/ } } @@ -264,7 +264,7 @@ void WindowSignal( * Windowing * *-----------------------------------------------------------*/ - tcx_windowing_analysis( in - shr( l, 1 ) + offset, *L_frame, l, left_win, r, right_win, out ); + tcx_windowing_analysis( in - add( shr( l, 1 ), offset ), *L_frame, l, left_win, r, right_win, out ); test(); test(); IF( EQ_16( left_overlap_mode, FULL_OVERLAP ) && truncate_aldo ) @@ -273,22 +273,22 @@ void WindowSignal( Word16 i, tmp; const PWord16 *p; - p = hTcxCfg->tcx_mdct_window_minimum; - tmp = shr( hTcxCfg->tcx_mdct_window_min_length, 1 ); + p = hTcxCfg->tcx_mdct_window_minimum; /*Q15*/ + tmp = shr( hTcxCfg->tcx_mdct_window_min_length, 1 ); /*Q0*/ IF( fullband != 0 ) { - p = hTcxCfg->tcx_mdct_window_minimumFB; - tmp = shr( hTcxCfg->tcx_mdct_window_min_lengthFB, 1 ); + p = hTcxCfg->tcx_mdct_window_minimumFB; /*Q15*/ + tmp = shr( hTcxCfg->tcx_mdct_window_min_lengthFB, 1 ); /*Q0*/ } FOR( i = 0; i < tmp; i++ ) { - out[i] = mult_r( out[i], p[i].v.im ); + out[i] = mult_r( out[i], p[i].v.im ); /*Qx*/ move16(); } FOR( i = 0; i < tmp; i++ ) { - out[i + tmp] = mult_r( out[i + tmp], p[tmp - 1 - i].v.re ); + out[i + tmp] = mult_r( out[i + tmp], p[tmp - 1 - i].v.re ); /*Qx*/ move16(); } } @@ -305,25 +305,25 @@ void WindowSignal( *-------------------------------------------------------------------*/ void tcx_windowing_synthesis_current_frame( - Word16 *signal, /* i/o: signal vector */ - const PWord16 *window, /* i: TCX window vector */ - const PWord16 *window_half, /* i: TCX window vector for half-overlap window */ - const PWord16 *window_min, /* i: TCX minimum overlap window */ - const Word16 window_length, /* i: TCX window length */ - const Word16 window_half_length, /* i: TCX half window length */ - const Word16 window_min_length, /* i: TCX minimum overlap length */ - const Word16 left_rect, /* i: left part is rectangular */ - const Word16 left_mode, /* i: overlap mode of left window half */ - Word16 *acelp_zir, /* i: acelp ZIR */ - const Word16 *old_syn, - const Word16 *syn_overl, - const Word16 *A_zir, - const PWord16 *window_trans, - Word16 acelp_zir_len, - const Word16 acelp_mem_len, - const Word16 last_core_bfi, /* i : last core */ - const Word8 last_is_cng, - const Word16 fullbandScale ) + Word16 *signal, /* i/o: signal vector Qx*/ + const PWord16 *window, /* i: TCX window vector Q15*/ + const PWord16 *window_half, /* i: TCX window vector for half-overlap window Q15*/ + const PWord16 *window_min, /* i: TCX minimum overlap window Q15*/ + const Word16 window_length, /* i: TCX window length Q0*/ + const Word16 window_half_length, /* i: TCX half window length Q0*/ + const Word16 window_min_length, /* i: TCX minimum overlap length Q0*/ + const Word16 left_rect, /* i: left part is rectangular Q0*/ + const Word16 left_mode, /* i: overlap mode of left window half Q0*/ + Word16 *acelp_zir, /* i: acelp ZIR Qx*/ + const Word16 *old_syn, /*Qx*/ + const Word16 *syn_overl, /*Qx*/ + const Word16 *A_zir, /*Q12*/ + const PWord16 *window_trans, /*Q15*/ + Word16 acelp_zir_len, /*Q0*/ + const Word16 acelp_mem_len, /*Q0*/ + const Word16 last_core_bfi, /* i : last core Q0*/ + const Word8 last_is_cng, /*Q0*/ + const Word16 fullbandScale /*Q0*/ ) { Word16 i, overlap, n, tmp, tmp2; @@ -332,7 +332,7 @@ void tcx_windowing_synthesis_current_frame( /* Init */ - overlap = shr( window_length, 1 ); + overlap = shr( window_length, 1 ); /*Q0*/ /* Past-frame is TCX concealed as CNG and current-frame is TCX */ test(); @@ -353,14 +353,14 @@ void tcx_windowing_synthesis_current_frame( #else lerp( acelp_zir, tmp_buf, acelp_zir_len, idiv1616U( shl( acelp_zir_len, LD_FSCALE_DENOM ), fullbandScale ) ); #endif - acelp_zir = tmp_buf; + acelp_zir = tmp_buf; /*Qx*/ } FOR( i = 0; i < acelp_zir_len; i++ ) { /*signal[i] *= (float)(i)/(float)(acelp_zir_len); signal[i] += acelp_zir[i]*(float)(acelp_zir_len-i)/(float)(acelp_zir_len);*/ - signal[i] = add( mult_r( signal[i], div_s( i, acelp_zir_len ) ), mult_r( acelp_zir[i], div_s( sub( acelp_zir_len, i ), acelp_zir_len ) ) ); + signal[i] = add( mult_r( signal[i], div_s( i, acelp_zir_len ) ), mult_r( acelp_zir[i], div_s( sub( acelp_zir_len, i ), acelp_zir_len ) ) ); /*Qx*/ move16(); } } @@ -377,21 +377,21 @@ void tcx_windowing_synthesis_current_frame( IF( fullbandScale == 0 ) { - tmp = shl( acelp_mem_len, 1 ); + tmp = shl( acelp_mem_len, 1 ); /*Qx*/ /*OLA with ACELP*/ FOR( i = 0; i < acelp_mem_len; i++ ) { /*window decoded TCX with aliasing*/ - tmp2 = mult_r( signal[i + overlap - acelp_mem_len], window_trans[i].v.im ); + tmp2 = mult_r( signal[i + overlap - acelp_mem_len], window_trans[i].v.im ); /*Qx*/ /*Time TDAC: 1)forward part of ACELP*/ #ifdef BASOP_NOGLOB - tmp2 = add_sat( tmp2, mult_r( old_syn[acelp_zir_len - tmp + i], mult_r( window_trans[i].v.re, window_trans[i].v.re ) ) ); + tmp2 = add_sat( tmp2, mult_r( old_syn[acelp_zir_len - tmp + i], mult_r( window_trans[i].v.re, window_trans[i].v.re ) ) ); /*Qx*/ /*Time TDAC: 1)reward part of ACELP*/ - tmp2 = add_sat( tmp2, mult_r( old_syn[acelp_zir_len - i - 1], mult_r( window_trans[i].v.im, window_trans[i].v.re ) ) ); + tmp2 = add_sat( tmp2, mult_r( old_syn[acelp_zir_len - i - 1], mult_r( window_trans[i].v.im, window_trans[i].v.re ) ) ); /*Qx*/ #else tmp2 = add( tmp2, mult_r( old_syn[acelp_zir_len - tmp + i], mult_r( window_trans[i].v.re, window_trans[i].v.re ) ) ); @@ -399,35 +399,35 @@ void tcx_windowing_synthesis_current_frame( tmp2 = add( tmp2, mult_r( old_syn[acelp_zir_len - i - 1], mult_r( window_trans[i].v.im, window_trans[i].v.re ) ) ); #endif move16(); - signal[i + overlap - acelp_mem_len] = tmp2; + signal[i + overlap - acelp_mem_len] = tmp2; /*Qx*/ } FOR( ; i < tmp; i++ ) { /*window decoded TCX with aliasing*/ - tmp2 = mult_r( signal[i + overlap - acelp_mem_len], window_trans[tmp - 1 - i].v.re ); + tmp2 = mult_r( signal[i + overlap - acelp_mem_len], window_trans[tmp - 1 - i].v.re ); /*Qx*/ /*Time TDAC: 1)forward part of ACELP*/ #ifdef BASOP_NOGLOB - tmp2 = add_sat( tmp2, mult_r( old_syn[acelp_zir_len - tmp + i], mult_r( window_trans[tmp - 1 - i].v.im, window_trans[tmp - 1 - i].v.im ) ) ); + tmp2 = add_sat( tmp2, mult_r( old_syn[acelp_zir_len - tmp + i], mult_r( window_trans[tmp - 1 - i].v.im, window_trans[tmp - 1 - i].v.im ) ) ); /*Qx*/ #else tmp2 = add( tmp2, mult_r( old_syn[acelp_zir_len - tmp + i], mult_r( window_trans[tmp - 1 - i].v.im, window_trans[tmp - 1 - i].v.im ) ) ); #endif /*Time TDAC: 1)reward part of ACELP*/ #ifdef BASOP_NOGLOB - tmp2 = add_sat( tmp2, mult_r( old_syn[acelp_zir_len - i - 1], mult_r( window_trans[tmp - 1 - i].v.re, window_trans[tmp - 1 - i].v.im ) ) ); + tmp2 = add_sat( tmp2, mult_r( old_syn[acelp_zir_len - i - 1], mult_r( window_trans[tmp - 1 - i].v.re, window_trans[tmp - 1 - i].v.im ) ) ); /*Qx*/ #else tmp2 = add( tmp2, mult_r( old_syn[acelp_zir_len - i - 1], mult_r( window_trans[tmp - 1 - i].v.re, window_trans[tmp - 1 - i].v.im ) ) ); #endif move16(); - signal[i + overlap - acelp_mem_len] = tmp2; + signal[i + overlap - acelp_mem_len] = tmp2; /*Qx*/ } FOR( i = 0; i < M; i++ ) { move16(); #ifdef BASOP_NOGLOB - signal[overlap + acelp_mem_len - M + i] = sub_sat( signal[overlap + acelp_mem_len - M + i], old_syn[acelp_zir_len - M + i] ); + signal[overlap + acelp_mem_len - M + i] = sub_sat( signal[overlap + acelp_mem_len - M + i], old_syn[acelp_zir_len - M + i] ); /*Qx*/ #else signal[overlap + acelp_mem_len - M + i] = sub( signal[overlap + acelp_mem_len - M + i], old_syn[acelp_zir_len - M + i] ); #endif @@ -444,11 +444,11 @@ void tcx_windowing_synthesis_current_frame( } ELSE { - tmp = extract_l( L_shr( L_mult0( acelp_zir_len, fullbandScale ), LD_FSCALE_DENOM ) ); + tmp = extract_l( L_shr( L_mult0( acelp_zir_len, fullbandScale ), LD_FSCALE_DENOM ) ); /*Q0*/ lerp( acelp_zir, tmp_buf, tmp, acelp_zir_len ); - acelp_zir_len = tmp; + acelp_zir_len = tmp; /*Q0*/ move16(); - acelp_zir = tmp_buf; + acelp_zir = tmp_buf; /*Qx*/ IF( GE_16( acelp_zir_len, 2 * 64 ) ) @@ -456,25 +456,25 @@ void tcx_windowing_synthesis_current_frame( /* apply a simple low-pass to the ZIR, to avoid potentially unmasked HF content */ FOR( i = 2; i < acelp_zir_len; i++ ) { - L_tmp = L_mult( acelp_zir[i - 2], 8192 ); - L_tmp = L_mac( L_tmp, acelp_zir[i - 1], 11469 ); - acelp_zir[i] = mac_r( L_tmp, acelp_zir[i], 13107 ); + L_tmp = L_mult( acelp_zir[i - 2], 8192 /*0.25 in Q15*/ ); + L_tmp = L_mac( L_tmp, acelp_zir[i - 1], 11469 /*0.35 in Q15*/ ); + acelp_zir[i] = mac_r( L_tmp, acelp_zir[i], 13107 /*0.40 in Q15*/ ); /*Qx*/ move16(); } - L_tmp = L_mult( acelp_zir[acelp_zir_len - 1], 13107 ); - L_tmp = L_mac( L_tmp, acelp_zir[acelp_zir_len - 1], 11469 ); - acelp_zir[acelp_zir_len - 1] = mac_r( L_tmp, acelp_zir[acelp_zir_len - 2], 8192 ); + L_tmp = L_mult( acelp_zir[acelp_zir_len - 1], 13107 /*0.40 in Q15*/ ); + L_tmp = L_mac( L_tmp, acelp_zir[acelp_zir_len - 1], 11469 /*0.35 in Q15*/ ); + acelp_zir[acelp_zir_len - 1] = mac_r( L_tmp, acelp_zir[acelp_zir_len - 2], 8192 /*0.25 in Q15*/ ); /*Qx*/ move16(); L_tmp = L_mult( acelp_zir[acelp_zir_len - 2], 13107 ); L_tmp = L_mac( L_tmp, acelp_zir[acelp_zir_len - 1], 11469 ); - acelp_zir[acelp_zir_len - 2] = mac_r( L_tmp, acelp_zir[acelp_zir_len - 1], 8192 ); + acelp_zir[acelp_zir_len - 2] = mac_r( L_tmp, acelp_zir[acelp_zir_len - 1], 8192 ); /*Qx*/ move16(); FOR( i = acelp_zir_len - 3; i >= 0; i-- ) { L_tmp = L_mult( acelp_zir[i], 13107 ); L_tmp = L_mac( L_tmp, acelp_zir[i + 1], 11469 ); - acelp_zir[i] = mac_r( L_tmp, acelp_zir[i + 2], 8192 ); + acelp_zir[i] = mac_r( L_tmp, acelp_zir[i + 2], 8192 ); /*Qx*/ move16(); } } @@ -485,7 +485,7 @@ void tcx_windowing_synthesis_current_frame( /*remove reconstructed ZIR and add ACELP ZIR*/ move16(); #ifdef BASOP_NOGLOB - signal[i + overlap + acelp_mem_len] = sub_sat( signal[i + overlap + acelp_mem_len], mult_r_sat( acelp_zir[i], div_s( sub_sat( acelp_zir_len, i ), acelp_zir_len ) ) ); + signal[i + overlap + acelp_mem_len] = sub_sat( signal[i + overlap + acelp_mem_len], mult_r_sat( acelp_zir[i], div_s( sub_sat( acelp_zir_len, i ), acelp_zir_len ) ) ); /*Qx*/ #else signal[i + overlap + acelp_mem_len] = sub( signal[i + overlap + acelp_mem_len], mult_r( acelp_zir[i], div_s( sub( acelp_zir_len, i ), acelp_zir_len ) ) ); #endif @@ -494,45 +494,45 @@ void tcx_windowing_synthesis_current_frame( /* Rectangular window (past-frame is TCX) */ ELSE IF( left_rect == 1 && last_core_bfi != ACELP_CORE ) { - n = add( overlap, acelp_mem_len ); + n = add( overlap, acelp_mem_len ); /*q0*/ FOR( i = 0; i < n; i++ ) { move16(); signal[i] = 0; } - n = shr( window_length, 1 ); + n = shr( window_length, 1 ); /*q0*/ FOR( i = 0; i < n; i++ ) { move16(); - signal[i + overlap + acelp_mem_len] = mult_r( signal[i + overlap + acelp_mem_len], window[i].v.im ); + signal[i + overlap + acelp_mem_len] = mult_r( signal[i + overlap + acelp_mem_len], window[i].v.im ); /*Qx*/ } FOR( ; i < window_length; i++ ) { move16(); - signal[i + overlap + acelp_mem_len] = mult_r( signal[i + overlap + acelp_mem_len], window[window_length - 1 - i].v.re ); + signal[i + overlap + acelp_mem_len] = mult_r( signal[i + overlap + acelp_mem_len], window[window_length - 1 - i].v.re ); /*Qx*/ } } /* Normal window (past-frame is ACELP) */ ELSE IF( left_rect != 1 && last_core_bfi == ACELP_CORE ) { - n = shr( window_length, 1 ); + n = shr( window_length, 1 ); /*q0*/ FOR( i = 0; i < n; i++ ) { move16(); - signal[i] = mult_r( signal[i], window[i].v.im ); + signal[i] = mult_r( signal[i], window[i].v.im ); /*Qx*/ } FOR( ; i < window_length; i++ ) { move16(); - signal[i] = mult_r( signal[i], window[window_length - 1 - i].v.re ); + signal[i] = mult_r( signal[i], window[window_length - 1 - i].v.re ); /*Qx*/ } FOR( i = 0; i < window_length /*acelp_zir_len*/; i++ ) { move16(); - signal[i] = add( signal[i], syn_overl[i] ); + signal[i] = add( signal[i], syn_overl[i] ); /*Qx*/ } } /* Normal window (past-frame is TCX) */ @@ -540,23 +540,23 @@ void tcx_windowing_synthesis_current_frame( { IF( EQ_16( left_mode, 2 ) ) /* min. overlap */ { - n = shr( sub( window_length, window_min_length ), 1 ); + n = shr( sub( window_length, window_min_length ), 1 ); /*q0*/ FOR( i = 0; i < n; i++ ) { *signal++ = 0; move16(); } - n = shr( window_min_length, 1 ); + n = shr( window_min_length, 1 ); /*q0*/ FOR( i = 0; i < n; i++ ) { - *signal = mult_r( *signal, window_min[i].v.im ); + *signal = mult_r( *signal, window_min[i].v.im ); /*Qx*/ move16(); signal++; } FOR( i = 0; i < n; i++ ) { - *signal = mult_r( *signal, window_min[n - 1 - i].v.re ); + *signal = mult_r( *signal, window_min[n - 1 - i].v.re ); /*Qx*/ move16(); signal++; } @@ -575,13 +575,13 @@ void tcx_windowing_synthesis_current_frame( FOR( w = 0; w < n; w++ ) { move16(); - signal[i] = mult_r( signal[i], window_half[w].v.im ); + signal[i] = mult_r( signal[i], window_half[w].v.im ); /*Qx*/ i = add( i, 1 ); } FOR( w = 0; w < n; w++ ) { move16(); - signal[i] = mult_r( signal[i], window_half[window_half_length / 2 - 1 - w].v.re ); + signal[i] = mult_r( signal[i], window_half[window_half_length / 2 - 1 - w].v.re ); /*Qx*/ i = add( i, 1 ); } } @@ -592,12 +592,12 @@ void tcx_windowing_synthesis_current_frame( FOR( i = 0; i < n; i++ ) { move16(); - signal[i] = mult_r( signal[i], window[i].v.im ); + signal[i] = mult_r( signal[i], window[i].v.im ); /*Qx*/ } FOR( ; i < window_length; i++ ) { move16(); - signal[i] = mult_r( signal[i], window[window_length - 1 - i].v.re ); + signal[i] = mult_r( signal[i], window[window_length - 1 - i].v.re ); /*Qx*/ } } } @@ -610,14 +610,14 @@ void tcx_windowing_synthesis_current_frame( * *-------------------------------------------------------------------*/ void tcx_windowing_synthesis_past_frame( - Word16 *signal, /* i/o: signal vector */ - const PWord16 *window, /* i: TCX window vector */ - const PWord16 *window_half, /* i: TCX window vector for half-overlap window */ - const PWord16 *window_min, /* i: TCX minimum overlap window */ - const Word16 window_length, /* i: TCX window length */ - const Word16 window_half_length, /* i: TCX half window length */ - const Word16 window_min_length, /* i: TCX minimum overlap length */ - const Word16 right_mode /* i: overlap mode (left_mode of current frame) */ + Word16 *signal, /* i/o: signal vector Qx*/ + const PWord16 *window, /* i: TCX window vector Q15*/ + const PWord16 *window_half, /* i: TCX window vector for half-overlap window Q15*/ + const PWord16 *window_min, /* i: TCX minimum overlap window Q15*/ + const Word16 window_length, /* i: TCX window length Q0*/ + const Word16 window_half_length, /* i: TCX half window length Q0*/ + const Word16 window_min_length, /* i: TCX minimum overlap length Q0*/ + const Word16 right_mode /* i: overlap mode (left_mode of current frame) Q0*/ ) { @@ -625,23 +625,23 @@ void tcx_windowing_synthesis_past_frame( IF( EQ_16( right_mode, 2 ) ) /* min. overlap */ { - signal += shr( sub( window_length, window_min_length ), 1 ); + signal += shr( sub( window_length, window_min_length ), 1 ); /*Qx*/ n = shr( window_min_length, 1 ); FOR( i = 0; i < n; i++ ) { - *signal = mult_r( *signal, window_min[i].v.re ); + *signal = mult_r( *signal, window_min[i].v.re ); /*Qx*/ move16(); signal++; } FOR( i = 0; i < n; i++ ) { - *signal = mult_r( *signal, window_min[n - 1 - i].v.im ); + *signal = mult_r( *signal, window_min[n - 1 - i].v.im ); /*Qx*/ move16(); signal++; } - n = shr( sub( window_length, window_min_length ), 1 ); + n = shr( sub( window_length, window_min_length ), 1 ); /*Q0*/ FOR( i = 0; i < n; i++ ) { *signal = 0; @@ -653,17 +653,17 @@ void tcx_windowing_synthesis_past_frame( { Word16 w; - i = shr( sub( window_length, window_half_length ), 1 ); - n = shr( window_half_length, 1 ); + i = shr( sub( window_length, window_half_length ), 1 ); /*Q0*/ + n = shr( window_half_length, 1 ); /*Q0*/ FOR( w = 0; w < n; w++ ) { - signal[i] = mult_r( signal[i], window_half[w].v.re ); + signal[i] = mult_r( signal[i], window_half[w].v.re ); /*Qx*/ move16(); i = add( i, 1 ); } FOR( w = 0; w < n; w++ ) { - signal[i] = mult_r( signal[i], window_half[window_half_length / 2 - 1 - w].v.im ); + signal[i] = mult_r( signal[i], window_half[window_half_length / 2 - 1 - w].v.im ); /*Qx*/ move16(); i = add( i, 1 ); } @@ -676,13 +676,13 @@ void tcx_windowing_synthesis_past_frame( ELSE /* normal full/maximum overlap */ { - n = shr( window_length, 1 ); + n = shr( window_length, 1 ); /*Q0*/ FOR( i = 0; i < n; i++ ) { move16(); - signal[i] = mult_r( signal[i], window[i].v.re ); + signal[i] = mult_r( signal[i], window[i].v.re ); /*Qx*/ move16(); - signal[window_length - 1 - i] = mult_r( signal[window_length - 1 - i], window[i].v.im ); + signal[window_length - 1 - i] = mult_r( signal[window_length - 1 - i], window[i].v.im ); /*Qx*/ } } } @@ -693,14 +693,14 @@ void tcx_windowing_synthesis_past_frame( *-------------------------------------------------------------------*/ void lpc2mdct( - Word16 *lpcCoeffs, - const Word16 lpcOrder, - Word16 *mdct_gains, + Word16 *lpcCoeffs, /*Q12*/ + const Word16 lpcOrder, /*Q0*/ + Word16 *mdct_gains, /*Q15 - mdct_gains_exp*/ Word16 *mdct_gains_exp, - Word16 *mdct_inv_gains, + Word16 *mdct_inv_gains, /*Q15 - mdct_inv_gains_exp*/ Word16 *mdct_inv_gains_exp, - const Word16 length, - const Word16 noInverse ) + const Word16 length, /*Q0*/ + const Word16 noInverse /*Q0*/ ) { Word32 ComplexData[2 * FDNS_NPTS]; Word16 i, j, k, sizeN, step, scale, s, tmp16; @@ -714,7 +714,7 @@ void lpc2mdct( #endif assert( length <= FDNS_NPTS ); - sizeN = shl( length, 1 ); + sizeN = shl( length, 1 ); /*Q0*/ BASOP_getTables( NULL, &ptwiddle, &step, sizeN ); /*ODFT*/ @@ -722,9 +722,9 @@ void lpc2mdct( /* pre-twiddle */ FOR( i = 0; i <= lpcOrder; i++ ) { - ComplexData[2 * i] = L_mult( lpcCoeffs[i], ptwiddle->v.re ); + ComplexData[2 * i] = L_mult( lpcCoeffs[i], ptwiddle->v.re ); /*Q12*/ move32(); - ComplexData[2 * i + 1] = L_negate( L_mult( lpcCoeffs[i], ptwiddle->v.im ) ); + ComplexData[2 * i + 1] = L_negate( L_mult( lpcCoeffs[i], ptwiddle->v.im ) ); /*Q12*/ move32(); ptwiddle += step; } @@ -757,17 +757,17 @@ void lpc2mdct( { /* half length FFT */ scale = add( norm_s( lpcCoeffs[0] ), 1 ); - BASOP_cfft( (cmplx *) ComplexData, FDNS_NPTS, &scale, workBuffer ); + BASOP_cfft( (cmplx *) ComplexData, FDNS_NPTS, &scale, workBuffer ); /*Q31 - scale*/ /*Get amplitude*/ j = sub( length, 1 ); k = 0; FOR( i = 0; i < length / 2; i++ ) { s = sub( norm_l( L_max( L_abs( ComplexData[2 * i] ), L_abs( ComplexData[2 * i + 1] ) ) ), 1 ); - tmp16 = extract_h( L_shl( ComplexData[2 * i], s ) ); - tmp32 = L_mult( tmp16, tmp16 ); - tmp16 = extract_h( L_shl( ComplexData[2 * i + 1], s ) ); - tmp16 = mac_r( tmp32, tmp16, tmp16 ); + tmp16 = extract_h( L_shl( ComplexData[2 * i], s ) ); /*Q15 - scale + s*/ + tmp32 = L_mult( tmp16, tmp16 ); /*Q15 - 2*(scale - s)*/ + tmp16 = extract_h( L_shl( ComplexData[2 * i + 1], s ) ); /*Q15 - scale + s*/ + tmp16 = mac_r( tmp32, tmp16, tmp16 ); /*Q15 - 2*(scale - s)*/ s = shl( sub( scale, s ), 1 ); if ( tmp16 == 0 ) { @@ -779,10 +779,10 @@ void lpc2mdct( tmp16 = 1; move16(); } - BASOP_Util_Sqrt_InvSqrt_MantExp( tmp16, s, &g, &g_e, &ig, &ig_e ); + BASOP_Util_Sqrt_InvSqrt_MantExp( tmp16, s, &g, &g_e, &ig, &ig_e ); /*Q15 - ig_e*/ if ( mdct_gains != 0 ) { - mdct_gains[k] = g; + mdct_gains[k] = g; /*Q15 - g_e*/ move16(); } if ( mdct_gains_exp != 0 ) @@ -792,7 +792,7 @@ void lpc2mdct( } if ( mdct_inv_gains != 0 ) { - mdct_inv_gains[k] = ig; + mdct_inv_gains[k] = ig; /*Q15 - ig_e*/ move16(); } if ( mdct_inv_gains_exp != 0 ) @@ -802,10 +802,10 @@ void lpc2mdct( } k = add( k, 1 ); s = sub( norm_l( L_max( L_abs( ComplexData[2 * j] ), L_abs( ComplexData[2 * j + 1] ) ) ), 1 ); - tmp16 = extract_h( L_shl( ComplexData[2 * j], s ) ); - tmp32 = L_mult( tmp16, tmp16 ); - tmp16 = extract_h( L_shl( ComplexData[2 * j + 1], s ) ); - tmp16 = mac_r( tmp32, tmp16, tmp16 ); + tmp16 = extract_h( L_shl( ComplexData[2 * j], s ) ); /*Q15 - scale + s*/ + tmp32 = L_mult( tmp16, tmp16 ); /*Q15 - 2*(scale - s)*/ + tmp16 = extract_h( L_shl( ComplexData[2 * j + 1], s ) ); /*Q15 - scale + s*/ + tmp16 = mac_r( tmp32, tmp16, tmp16 ); /*Q15 - 2*(scale - s)*/ s = shl( sub( scale, s ), 1 ); if ( tmp16 == 0 ) { @@ -820,7 +820,7 @@ void lpc2mdct( BASOP_Util_Sqrt_InvSqrt_MantExp( tmp16, s, &g, &g_e, &ig, &ig_e ); if ( mdct_gains != 0 ) { - mdct_gains[k] = g; + mdct_gains[k] = g; /*Q15 - g_e*/ move16(); } if ( mdct_gains_exp != 0 ) @@ -830,7 +830,7 @@ void lpc2mdct( } if ( mdct_inv_gains != 0 ) { - mdct_inv_gains[k] = ig; + mdct_inv_gains[k] = ig; /*Q15 - ig_e*/ move16(); } if ( mdct_inv_gains_exp != 0 ) @@ -845,13 +845,13 @@ void lpc2mdct( } void lpc2mdct_2( - Word16 *lpcCoeffs, - const Word16 lpcOrder, - Word16 mdct_gains_fx[], + Word16 *lpcCoeffs, /*Q12*/ + const Word16 lpcOrder, /*Q0*/ + Word16 mdct_gains_fx[], /*Q15 - mdct_gains_e*/ Word16 mdct_gains_e[], - Word16 mdct_inv_gains_fx[], + Word16 mdct_inv_gains_fx[], /*Q15 - mdct_inv_gains_e*/ Word16 mdct_inv_gains_e[], - const Word16 length ) + const Word16 length /*Q0*/ ) { Word16 i, sizeN, j, k, step, scale, s, tmp16; Word16 g, g_e, ig, ig_e; @@ -860,16 +860,16 @@ void lpc2mdct_2( const PWord16 *ptwiddle; assert( length <= FDNS_NPTS ); - sizeN = shl( length, 1 ); + sizeN = shl( length, 1 ); /*Q0*/ BASOP_getTables( NULL, &ptwiddle, &step, sizeN ); /* ODFT */ FOR( i = 0; i < lpcOrder + 1; i++ ) { - RealData_fx[i] = L_mult( lpcCoeffs[i], ptwiddle->v.re ); + RealData_fx[i] = L_mult( lpcCoeffs[i], ptwiddle->v.re ); /*Q12*/ move32(); - ImagData_fx[i] = L_negate( L_mult( lpcCoeffs[i], ptwiddle->v.im ) ); + ImagData_fx[i] = L_negate( L_mult( lpcCoeffs[i], ptwiddle->v.im ) ); /*Q12*/ move32(); ptwiddle += step; } @@ -884,7 +884,7 @@ void lpc2mdct_2( /* half length FFT */ scale = add( norm_s( lpcCoeffs[0] ), 1 ); - BASOP_cfft_ivas( RealData_fx, ImagData_fx, 1, &scale ); + BASOP_cfft_ivas( RealData_fx, ImagData_fx, 1, &scale ); /*Q31 - scale*/ /*Get amplitude*/ j = sub( FDNS_NPTS, 1 ); @@ -896,11 +896,11 @@ void lpc2mdct_2( { s = sub( norm_l( L_max( L_abs( RealData_fx[i] ), L_abs( ImagData_fx[i] ) ) ), 1 ); - tmp16 = extract_h( L_shl( RealData_fx[i], s ) ); - tmp32 = L_mult( tmp16, tmp16 ); + tmp16 = extract_h( L_shl( RealData_fx[i], s ) ); /*Q15 - scale + s*/ + tmp32 = L_mult( tmp16, tmp16 ); /*Q15 - 2*(scale - s)*/ - tmp16 = extract_h( L_shl( ImagData_fx[i], s ) ); - tmp16 = mac_r( tmp32, tmp16, tmp16 ); + tmp16 = extract_h( L_shl( ImagData_fx[i], s ) ); /*Q15 - scale + s*/ + tmp16 = mac_r( tmp32, tmp16, tmp16 ); /*Q15 - 2*(scale - s)*/ s = shl( sub( scale, s ), 1 ); @@ -919,7 +919,7 @@ void lpc2mdct_2( if ( mdct_gains_fx != NULL ) { - mdct_gains_fx[k] = g; + mdct_gains_fx[k] = g; /*Q15 - g_e*/ move16(); } @@ -931,7 +931,7 @@ void lpc2mdct_2( if ( mdct_inv_gains_fx != NULL ) { - mdct_inv_gains_fx[k] = ig; + mdct_inv_gains_fx[k] = ig; /*Q15 - ig_e*/ move16(); } @@ -946,11 +946,11 @@ void lpc2mdct_2( s = sub( norm_l( L_max( L_abs( RealData_fx[j] ), L_abs( ImagData_fx[j] ) ) ), 1 ); - tmp16 = extract_h( L_shl( RealData_fx[j], s ) ); - tmp32 = L_mult( tmp16, tmp16 ); + tmp16 = extract_h( L_shl( RealData_fx[j], s ) ); /*Q15 - scale + s*/ + tmp32 = L_mult( tmp16, tmp16 ); /*Q15 - 2*(scale - s)*/ - tmp16 = extract_h( L_shl( ImagData_fx[j], s ) ); - tmp16 = mac_r( tmp32, tmp16, tmp16 ); + tmp16 = extract_h( L_shl( ImagData_fx[j], s ) ); /*Q15 - scale + s*/ + tmp16 = mac_r( tmp32, tmp16, tmp16 ); /*Q15 - 2*(scale - s)*/ s = shl( sub( scale, s ), 1 ); @@ -1006,9 +1006,9 @@ void lpc2mdct_2( * \param gains_exp shaping gains exponents */ void mdct_shaping( - Word32 x[], - const Word16 lg, - const Word16 gains[], + Word32 x[], /*Qx*/ + const Word16 lg, /*Q0*/ + const Word16 gains[], /*Q15 - gains_exp*/ const Word16 gains_exp[] /*const Word16 nBands*/ /*Parameter added in IVAS, but always equal to FDNS_NPTS */ ) @@ -1016,7 +1016,7 @@ void mdct_shaping( Word16 i, k, l; Word16 m, n, k1, k2, j; - Word32 *px = x; + Word32 *px = x; /*Qx*/ Word16 const *pgains = gains; Word16 const *pgainsexp = gains_exp; #ifdef BASOP_NOGLOB_DECLARE_LOCAL @@ -1024,21 +1024,21 @@ void mdct_shaping( #endif /* FDNS_NPTS = 64 */ - k = shr( lg, 6 ); + k = shr( lg, 6 ); /*Q0*/ m = s_and( lg, 0x3F ); IF( m != 0 ) { IF( LE_16( m, FDNS_NPTS / 2 ) ) { - n = idiv1616U( FDNS_NPTS, m ); + n = idiv1616U( FDNS_NPTS, m ); /*Q0*/ k1 = k; move16(); k2 = add( k, 1 ); } ELSE { - n = idiv1616U( FDNS_NPTS, sub( FDNS_NPTS, m ) ); + n = idiv1616U( FDNS_NPTS, sub( FDNS_NPTS, m ) ); /*Q0*/ k1 = add( k, 1 ); k2 = k; move16(); @@ -1072,7 +1072,7 @@ void mdct_shaping( FOR( l = 0; l < k; l++ ) { - *x = L_shl( Mpy_32_16_r( *x, *gains ), *gains_exp ); + *x = L_shl( Mpy_32_16_r( *x, *gains ), *gains_exp ); /*Qx*/ move32(); x++; } @@ -1086,13 +1086,13 @@ void mdct_shaping( { FOR( l = 0; l < k; l++ ) { - x = &px[l]; + x = &px[l]; /*Qx*/ gains = pgains; gains_exp = pgainsexp; FOR( i = 0; i < FDNS_NPTS; i++ ) { #ifdef BASOP_NOGLOB - *x = L_shl_o( Mpy_32_16_r( *x, *gains ), *gains_exp, &Overflow ); + *x = L_shl_o( Mpy_32_16_r( *x, *gains ), *gains_exp, &Overflow ); /*Qx*/ #else *x = L_shl( Mpy_32_16_r( *x, *gains ), *gains_exp ); #endif @@ -1106,13 +1106,13 @@ void mdct_shaping( } void mdct_shaping_16( - const Word16 x[], - const Word16 lg, - const Word16 lg_total, - const Word16 gains[], + const Word16 x[], /*Qx*/ + const Word16 lg, /*Q0*/ + const Word16 lg_total, /*Q0*/ + const Word16 gains[], /*15 - gains_exp*/ const Word16 gains_exp[], Word16 gains_max_exp, - Word32 y[] ) + Word32 y[] /*Qx*/ ) { Word16 i, k, l; Word16 m, gain_exp; @@ -1123,7 +1123,7 @@ void mdct_shaping_16( Word16 const *pgains_exp; /* FDNS_NPTS = 64 */ - k = shr( lg, 6 ); + k = shr( lg, 6 ); /*Q0*/ m = s_and( lg, 0x3F ); assert( m == 0 ); @@ -1135,13 +1135,13 @@ void mdct_shaping_16( } FOR( l = 0; l < k; l++ ) { - px = &x[l]; - py = &y[l]; - pgains = gains; + px = &x[l]; /*Qx*/ + py = &y[l]; /*Qx*/ + pgains = gains; /*15 - gains_exp*/ pgains_exp = gains_exp_loc; FOR( i = 0; i < FDNS_NPTS; i++ ) { - *py = L_shl( L_mult( *px, *pgains ), *pgains_exp ); + *py = L_shl( L_mult( *px, *pgains ), *pgains_exp ); /*Qx*/ move32(); px += k; py += k; @@ -1154,16 +1154,16 @@ void mdct_shaping_16( gain_exp = sub( gains_exp[FDNS_NPTS - 1], gains_max_exp ); FOR( i = lg; i < lg_total; i++ ) { - y[i] = L_shl( L_mult( x[i], gains[FDNS_NPTS - 1] ), gain_exp ); + y[i] = L_shl( L_mult( x[i], gains[FDNS_NPTS - 1] ), gain_exp ); /*Qx*/ move32(); } } void mdct_noiseShaping_ivas_fx( - Word32 x_fx[], + Word32 x_fx[], /*Q31 - x_e*/ Word16 *x_e, - const Word16 lg, - const Word16 gains_fx[], + const Word16 lg, /*Q0*/ + const Word16 gains_fx[], /*Q15 - gains_exp*/ const Word16 gains_exp[] /*const Word16 nBands*/ /*Parameter added in IVAS, but always equal to FDNS_NPTS */ ) @@ -1174,7 +1174,7 @@ void mdct_noiseShaping_ivas_fx( j = 0; move16(); /* FDNS_NPTS = 64 */ - k = shr( lg, 6 ); + k = shr( lg, 6 ); /*Q0*/ m = s_and( lg, 0x3F ); Word16 max_e = MIN16B; @@ -1188,14 +1188,14 @@ void mdct_noiseShaping_ivas_fx( { IF( LE_16( m, FDNS_NPTS / 2 ) ) { - n = idiv1616U( FDNS_NPTS, m ); + n = idiv1616U( FDNS_NPTS, m ); /*Q0*/ k1 = k; move16(); k2 = add( k, 1 ); } ELSE { - n = idiv1616U( FDNS_NPTS, sub( FDNS_NPTS, m ) ); + n = idiv1616U( FDNS_NPTS, sub( FDNS_NPTS, m ) ); /*Q0*/ k1 = add( k, 1 ); k2 = k; move16(); @@ -1224,9 +1224,9 @@ void mdct_noiseShaping_ivas_fx( FOR( l = 0; l < k; l++ ) { - x_fx[i] = Mpy_32_16_1( x_fx[i], gains_fx[j] ); + x_fx[i] = Mpy_32_16_1( x_fx[i], gains_fx[j] ); /*Q31 - x_e*/ move32(); - x_fx[i] = L_shr( x_fx[i], sub( max_e, add( *x_e, gains_exp[j] ) ) ); + x_fx[i] = L_shr( x_fx[i], sub( max_e, add( *x_e, gains_exp[j] ) ) ); /*Q31 - max_e*/ move32(); i = add( i, 1 ); } @@ -1239,9 +1239,9 @@ void mdct_noiseShaping_ivas_fx( { FOR( l = 0; l < k; l++ ) { - x_fx[i] = Mpy_32_16_1( x_fx[i], gains_fx[j] ); + x_fx[i] = Mpy_32_16_1( x_fx[i], gains_fx[j] ); /*Q31 - x_e*/ move32(); - x_fx[i] = L_shr( x_fx[i], sub( max_e, add( *x_e, gains_exp[j] ) ) ); + x_fx[i] = L_shr( x_fx[i], sub( max_e, add( *x_e, gains_exp[j] ) ) ); /*Q31 - max_e*/ move32(); i = add( i, 1 ); } @@ -1257,9 +1257,9 @@ void mdct_noiseShaping_ivas_fx( void mdct_noiseShaping_interp( - Word32 x[], - const Word16 lg, - Word16 gains[], + Word32 x[], /*Qx*/ + const Word16 lg, /*Q0*/ + Word16 gains[], /*Q15 - gains_exp*/ Word16 gains_exp[] ) { Word16 i, j, jp, jn, k, l; @@ -1267,7 +1267,7 @@ void mdct_noiseShaping_interp( assert( lg % FDNS_NPTS == 0 ); - k = shr( lg, 6 ); /* FDNS_NPTS = 64 */ + k = shr( lg, 6 ); /* FDNS_NPTS = 64 Q0*/ IF( gains ) { @@ -1283,11 +1283,11 @@ void mdct_noiseShaping_interp( FOR( i = 0; i < lg; i += 4 ) { - pg = gains[jp]; + pg = gains[jp]; /*Q15 - gains_exp*/ move16(); - g = gains[j]; + g = gains[j]; /*Q15 - gains_exp*/ move16(); - ng = gains[jn]; + ng = gains[jn]; /*Q15 - gains_exp*/ move16(); /* common exponent for pg and g */ @@ -1298,16 +1298,16 @@ void mdct_noiseShaping_interp( g = shl( g, tmp ); e = s_max( gains_exp[j], gains_exp[jp] ); - tmp = mac_r( L_mult( pg, 12288 /*0.375f Q15*/ ), g, 20480 /*0.625f Q15*/ ); - x[i] = L_shl( Mpy_32_16_1( x[i], tmp ), e ); + tmp = mac_r( L_mult( pg, 12288 /*0.375f Q15*/ ), g, 20480 /*0.625f Q15*/ ); /*Q15 - gains_exp*/ + x[i] = L_shl( Mpy_32_16_1( x[i], tmp ), e ); /*Qx*/ move32(); - tmp = mac_r( L_mult( pg, 4096 /*0.125f Q15*/ ), g, 28672 /*0.875f Q15*/ ); - x[i + 1] = L_shl( Mpy_32_16_1( x[i + 1], tmp ), e ); + tmp = mac_r( L_mult( pg, 4096 /*0.125f Q15*/ ), g, 28672 /*0.875f Q15*/ ); /*Q15 - gains_exp*/ + x[i + 1] = L_shl( Mpy_32_16_1( x[i + 1], tmp ), e ); /*Qx*/ move32(); /* common exponent for g and ng */ - g = gains[j]; + g = gains[j]; /*Q15 - gains_exp*/ move16(); tmp = sub( gains_exp[j], gains_exp[jn] ); if ( tmp > 0 ) @@ -1316,12 +1316,12 @@ void mdct_noiseShaping_interp( g = shl( g, tmp ); e = s_max( gains_exp[j], gains_exp[jn] ); - tmp = mac_r( L_mult( g, 28672 /*0.875f Q15*/ ), ng, 4096 /*0.125f Q15*/ ); - x[i + 2] = L_shl( Mpy_32_16_1( x[i + 2], tmp ), e ); + tmp = mac_r( L_mult( g, 28672 /*0.875f Q15*/ ), ng, 4096 /*0.125f Q15*/ ); /*Q15 - gains_exp*/ + x[i + 2] = L_shl( Mpy_32_16_1( x[i + 2], tmp ), e ); /*Qx*/ move32(); - tmp = mac_r( L_mult( g, 20480 /*0.625f Q15*/ ), ng, 12288 /*0.375f Q15*/ ); - x[i + 3] = L_shl( Mpy_32_16_1( x[i + 3], tmp ), e ); + tmp = mac_r( L_mult( g, 20480 /*0.625f Q15*/ ), ng, 12288 /*0.375f Q15*/ ); /*Q15 - gains_exp*/ + x[i + 3] = L_shl( Mpy_32_16_1( x[i + 3], tmp ), e ); /*Qx*/ move32(); jp = j; @@ -1342,11 +1342,11 @@ void mdct_noiseShaping_interp( FOR( i = 0; i < lg; i += 5 ) { - pg = gains[jp]; + pg = gains[jp]; /*Q15 - gains_exp*/ move16(); - g = gains[j]; + g = gains[j]; /*Q15 - gains_exp*/ move16(); - ng = gains[jn]; + ng = gains[jn]; /*Q15 - gains_exp*/ move16(); /* common exponent for pg and g */ @@ -1357,20 +1357,20 @@ void mdct_noiseShaping_interp( g = shl( g, tmp ); e = s_max( gains_exp[j], gains_exp[jp] ); - tmp = mac_r( L_mult( pg, 13107 /*0.40f Q15*/ ), g, 19661 /*0.60f Q15*/ ); - x[i] = L_shl( Mpy_32_16_1( x[i], tmp ), e ); + tmp = mac_r( L_mult( pg, 13107 /*0.40f Q15*/ ), g, 19661 /*0.60f Q15*/ ); /*Q15 - gains_exp*/ + x[i] = L_shl( Mpy_32_16_1( x[i], tmp ), e ); /*Qx*/ move32(); - tmp = mac_r( L_mult( pg, 6554 /*0.20f Q15*/ ), g, 26214 /*0.80f Q15*/ ); - x[i + 1] = L_shl( Mpy_32_16_1( x[i + 1], tmp ), e ); + tmp = mac_r( L_mult( pg, 6554 /*0.20f Q15*/ ), g, 26214 /*0.80f Q15*/ ); /*Q15 - gains_exp*/ + x[i + 1] = L_shl( Mpy_32_16_1( x[i + 1], tmp ), e ); /*Qx*/ move32(); - x[i + 2] = L_shl( Mpy_32_16_1( x[i + 2], gains[j] ), gains_exp[j] ); + x[i + 2] = L_shl( Mpy_32_16_1( x[i + 2], gains[j] ), gains_exp[j] ); /*Qx*/ move32(); /* common exponent for g and ng */ - g = gains[j]; + g = gains[j]; /*Q15 - gains_exp*/ move16(); tmp = sub( gains_exp[j], gains_exp[jn] ); if ( tmp > 0 ) @@ -1379,12 +1379,12 @@ void mdct_noiseShaping_interp( g = shl( g, tmp ); e = s_max( gains_exp[j], gains_exp[jn] ); - tmp = mac_r( L_mult( g, 26214 /*0.80f Q15*/ ), ng, 6554 /*0.20f Q15*/ ); - x[i + 3] = L_shl( Mpy_32_16_1( x[i + 3], tmp ), e ); + tmp = mac_r( L_mult( g, 26214 /*0.80f Q15*/ ), ng, 6554 /*0.20f Q15*/ ); /*Q15 - gains_exp*/ + x[i + 3] = L_shl( Mpy_32_16_1( x[i + 3], tmp ), e ); /*Qx*/ move32(); - tmp = mac_r( L_mult( g, 19661 /*0.60f Q15*/ ), ng, 13107 /*0.40f Q15*/ ); - x[i + 4] = L_shl( Mpy_32_16_1( x[i + 4], tmp ), e ); + tmp = mac_r( L_mult( g, 19661 /*0.60f Q15*/ ), ng, 13107 /*0.40f Q15*/ ); /*Q15 - gains_exp*/ + x[i + 4] = L_shl( Mpy_32_16_1( x[i + 4], tmp ), e ); /*Qx*/ move32(); jp = j; @@ -1400,7 +1400,7 @@ void mdct_noiseShaping_interp( { FOR( l = 0; l < k; l++ ) { - *x = L_shl( Mpy_32_16_1( *x, *gains ), *gains_exp ); + *x = L_shl( Mpy_32_16_1( *x, *gains ), *gains_exp ); /*Qx*/ move32(); x++; } @@ -1413,10 +1413,10 @@ void mdct_noiseShaping_interp( } void PsychAdaptLowFreqDeemph( - Word32 x[], - const Word16 lpcGains[], + Word32 x[], /*Qx*/ + const Word16 lpcGains[], /*Q15 - lpcGains_e*/ const Word16 lpcGains_e[], - Word16 lf_deemph_factors[] ) + Word16 lf_deemph_factors[] /*Q15*/ ) { Word16 i; Word16 max_val, max_e, fac, min, min_e, tmp, tmp_e; @@ -1428,11 +1428,11 @@ void PsychAdaptLowFreqDeemph( assert( lpcGains[0] >= 0x4000 ); - max_val = lpcGains[0]; + max_val = lpcGains[0]; /*Q15 - lpcGains_e*/ move16(); max_e = lpcGains_e[0]; move16(); - min = lpcGains[0]; + min = lpcGains[0]; /*Q15 - lpcGains_e*/ move16(); min_e = lpcGains_e[0]; move16(); @@ -1442,7 +1442,7 @@ void PsychAdaptLowFreqDeemph( { IF( compMantExp16Unorm( lpcGains[i], lpcGains_e[i], min, min_e ) < 0 ) { - min = lpcGains[i]; + min = lpcGains[i]; /*Q15 - lpcGains_e*/ move16(); min_e = lpcGains_e[i]; move16(); @@ -1450,7 +1450,7 @@ void PsychAdaptLowFreqDeemph( IF( compMantExp16Unorm( lpcGains[i], lpcGains_e[i], max_val, max_e ) > 0 ) { - max_val = lpcGains[i]; + max_val = lpcGains[i]; /*Q15 - lpcGains_e*/ move16(); max_e = lpcGains_e[i]; move16(); @@ -1465,7 +1465,7 @@ void PsychAdaptLowFreqDeemph( /* fac = tmp = (float)pow(max_val / min, 0.0078125f); */ tmp_e = min_e; move16(); - tmp = Inv16( min, &tmp_e ); + tmp = Inv16( min, &tmp_e ); /*Q15 - tmp_e*/ L_tmp = L_shl( L_mult( tmp, max_val ), add( tmp_e, max_e ) ); /* Q31 */ L_tmp = BASOP_Util_Log2( L_tmp ); /* Q25 */ L_tmp = L_shr( L_tmp, 7 ); /* 0.0078125f = 1.f/(1<<7) */ @@ -1488,19 +1488,19 @@ void PsychAdaptLowFreqDeemph( lf_deemph_factors[i] = mult_r( lf_deemph_factors[i], fac ); move16(); } - fac = mult_r( fac, tmp ); + fac = mult_r( fac, tmp ); /* Q15 */ } } } void AdaptLowFreqDeemph( - Word32 x[], + Word32 x[], /*Q31 - x_e*/ Word16 x_e, - Word16 tcx_lpc_shaped_ari, - Word16 lpcGains[], + Word16 tcx_lpc_shaped_ari, /*Q0*/ + Word16 lpcGains[], /*Q15 - lpcGains_e*/ Word16 lpcGains_e[], - const Word16 lg, - Word16 lf_deemph_factors[] ) + const Word16 lg, /*Q0*/ + Word16 lf_deemph_factors[] /*Q15*/ ) { Word16 i, i_max, i_max_old, lg_4; @@ -1529,13 +1529,13 @@ void AdaptLowFreqDeemph( move32(); if ( x[i] < 0 ) - tmp32 = L_add( x[i], v2 ); + tmp32 = L_add( x[i], v2 ); /*Q31 - x_e*/ if ( x[i] > 0 ) - tmp32 = L_sub( x[i], v2 ); + tmp32 = L_sub( x[i], v2 ); /*Q31 - x_e*/ assert( tmp32 != 0 ); - x[i] = tmp32; + x[i] = tmp32; /*Q31 - x_e*/ move32(); i_max = i; move16(); @@ -1546,14 +1546,14 @@ void AdaptLowFreqDeemph( /* 2. expand value range of all xi up to i_max: two extra steps */ FOR( i = 0; i < i_max; i++ ) { - x[i] = L_shr( x[i], 1 ); + x[i] = L_shr( x[i], 1 ); /*Q31 - x_e*/ move32(); - lf_deemph_factors[i] = shr( lf_deemph_factors[i], 1 ); + lf_deemph_factors[i] = shr( lf_deemph_factors[i], 1 ); /*Q15*/ move16(); } /* 3. find first magnitude maximum in lower quarter of spectrum */ - i_max_old = i_max; + i_max_old = i_max; /*Q0*/ move16(); IF( i_max_old >= 0 ) @@ -1567,10 +1567,10 @@ void AdaptLowFreqDeemph( { assert( x[i] != 0 ); if ( x[i] < 0 ) - tmp32 = L_add( x[i], v2 ); + tmp32 = L_add( x[i], v2 ); /*Q31 - x_e*/ if ( x[i] >= 0 ) - tmp32 = L_sub( x[i], v2 ); - x[i] = tmp32; + tmp32 = L_sub( x[i], v2 ); /*Q31 - x_e*/ + x[i] = tmp32; /*Q31 - x_e*/ move32(); i_max = i; move16(); @@ -1582,14 +1582,14 @@ void AdaptLowFreqDeemph( /* 4. expand value range of all xi up to i_max: two extra steps */ FOR( i = 0; i < i_max; i++ ) { - x[i] = L_shr( x[i], 1 ); + x[i] = L_shr( x[i], 1 ); /*Q31 - x_e*/ move32(); - lf_deemph_factors[i] = shr( lf_deemph_factors[i], 1 ); + lf_deemph_factors[i] = shr( lf_deemph_factors[i], 1 ); /*Q15*/ move16(); } /* 5. always expand two lines; lines could be at index 0 and 1! */ - i_max = s_max( i_max, i_max_old ); + i_max = s_max( i_max, i_max_old ); /*Q0*/ i = add( i_max, 1 ); IF( x[i] < 0 ) @@ -1598,17 +1598,17 @@ void AdaptLowFreqDeemph( if ( tmp32 > 0 ) { - lf_deemph_factors[i] = shr( lf_deemph_factors[i], 1 ); + lf_deemph_factors[i] = shr( lf_deemph_factors[i], 1 ); /*Q15*/ move16(); } if ( tmp32 <= 0 ) { - x[i] = L_add( x[i], v2 ); + x[i] = L_add( x[i], v2 ); /*Q31 - x_e*/ move32(); } if ( tmp32 > 0 ) { - x[i] = L_shr( x[i], 1 ); + x[i] = L_shr( x[i], 1 ); /*Q31 - x_e*/ move32(); } } @@ -1618,17 +1618,17 @@ void AdaptLowFreqDeemph( if ( tmp32 < 0 ) { - lf_deemph_factors[i] = shr( lf_deemph_factors[i], 1 ); + lf_deemph_factors[i] = shr( lf_deemph_factors[i], 1 ); /*Q15*/ move16(); } if ( tmp32 >= 0 ) { - x[i] = L_sub( x[i], v2 ); + x[i] = L_sub( x[i], v2 ); /*Q31 - x_e*/ move32(); } if ( tmp32 < 0 ) { - x[i] = L_shr( x[i], 1 ); + x[i] = L_shr( x[i], 1 ); /*Q31 - x_e*/ move32(); } } @@ -1640,17 +1640,17 @@ void AdaptLowFreqDeemph( if ( tmp32 > 0 ) { - lf_deemph_factors[i] = shr( lf_deemph_factors[i], 1 ); + lf_deemph_factors[i] = shr( lf_deemph_factors[i], 1 ); /*Q15*/ move16(); } if ( tmp32 <= 0 ) { - x[i] = L_add( x[i], v2 ); + x[i] = L_add( x[i], v2 ); /*Q31 - x_e*/ move32(); } if ( tmp32 > 0 ) { - x[i] = L_shr( x[i], 1 ); + x[i] = L_shr( x[i], 1 ); /*Q31 - x_e*/ move32(); } } @@ -1660,17 +1660,17 @@ void AdaptLowFreqDeemph( if ( tmp32 < 0 ) { - lf_deemph_factors[i] = shr( lf_deemph_factors[i], 1 ); + lf_deemph_factors[i] = shr( lf_deemph_factors[i], 1 ); /*Q15*/ move16(); } if ( tmp32 >= 0 ) { - x[i] = L_sub( x[i], v2 ); + x[i] = L_sub( x[i], v2 ); /*Q31 - x_e*/ move32(); } if ( tmp32 < 0 ) { - x[i] = L_shr( x[i], 1 ); + x[i] = L_shr( x[i], 1 ); /*Q31 - x_e*/ move32(); } } @@ -1682,17 +1682,17 @@ void AdaptLowFreqDeemph( } void tcx_noise_filling( - Word32 *Q, + Word32 *Q, /*Q31 - Q_e*/ Word16 Q_e, Word16 seed, - const Word16 iFirstLine, - const Word16 lowpassLine, - const Word16 nTransWidth, - const Word16 L_frame, - const Word16 tiltCompFactor, - Word16 fac_ns, - Word16 *infoTCXNoise, - const Word16 element_mode /* i : IVAS element mode */ + const Word16 iFirstLine, /*Q0*/ + const Word16 lowpassLine, /*Q0*/ + const Word16 nTransWidth, /*Q0*/ + const Word16 L_frame, /*Q0*/ + const Word16 tiltCompFactor, /*Q15*/ + Word16 fac_ns, /*Q15*/ + Word16 *infoTCXNoise, /*Q0*/ + const Word16 element_mode /* i : IVAS element mode Q0*/ ) { Word16 i, m, segmentOffset; @@ -1704,14 +1704,14 @@ void tcx_noise_filling( /* get inverse frame length */ - tmp1 = getInvFrameLen( L_frame ); + tmp1 = getInvFrameLen( L_frame ); /*Q21*/ /* tilt_factor = (float)pow(max_val(0.375f, tiltCompFactor), 1.0f/(float)L_frame); */ tmp32 = BASOP_Util_Log2( L_deposit_h( s_max( 0x3000, tiltCompFactor ) ) ); /* 6Q25 */ - tmp32 = L_shr( Mpy_32_16_1( tmp32, tmp1 ), 6 ); + tmp32 = L_shr( Mpy_32_16_1( tmp32, tmp1 ), 6 ); /*Q25*/ BASOP_SATURATE_WARNING_OFF_EVS; #ifdef BASOP_NOGLOB - tilt_factor = round_fx_sat( BASOP_Util_InvLog2( tmp32 ) ); + tilt_factor = round_fx_sat( BASOP_Util_InvLog2( tmp32 ) ); /*Q15*/ #else tilt_factor = round_fx( BASOP_Util_InvLog2( tmp32 ) ); #endif @@ -1720,7 +1720,7 @@ void tcx_noise_filling( /* find last nonzero line below iFirstLine, use it as start offset */ i = iFirstLine; move16(); - tmp1 = shr( iFirstLine, 1 ); + tmp1 = shr( iFirstLine, 1 ); /*Q0*/ IF( EQ_16( element_mode, IVAS_CPE_MDCT ) ) /* ... but only in mono or parametric stereo since it may cause binaural unmasking in discrete stereo */ { segmentOffset = i; @@ -1738,7 +1738,7 @@ void tcx_noise_filling( /* fac_ns *= (float)pow(tilt_factor, (float)i); */ FOR( m = 0; m < i; m++ ) { - fac_ns = mult_r( fac_ns, tilt_factor ); + fac_ns = mult_r( fac_ns, tilt_factor ); /*Q15*/ } i = add( i, 1 ); segmentOffset = i; @@ -1749,7 +1749,7 @@ void tcx_noise_filling( FOR( ; i < lowpassLine; i++ ) { - fac_ns = mult_r( fac_ns, tilt_factor ); + fac_ns = mult_r( fac_ns, tilt_factor ); /*Q15*/ IF( Q[i] != 0 ) { @@ -1758,8 +1758,8 @@ void tcx_noise_filling( /* RMS-normalize current noise-filled segment */ tmp1 = BASOP_Util_Divide3216_Scale( nrg, sub( i, segmentOffset ), &s ); /* mean */ s = add( s, 9 - 15 ); /* scaling */ - tmp1 = ISqrt16( tmp1, &s ); /* 1/RMS */ - tmp1 = mult_r( tmp1, inv_int[nTransWidth] ); /* compensate win */ + tmp1 = ISqrt16( tmp1, &s ); /* 1/RMS Q15 - s*/ + tmp1 = mult_r( tmp1, inv_int[nTransWidth] ); /* compensate win Q15 - s*/ s = add( s, sub( 16, Q_e ) ); /* scaling */ tmp2 = sub( i, win ); @@ -1767,7 +1767,7 @@ void tcx_noise_filling( { FOR( m = segmentOffset; m < tmp2; m++ ) { - Q[m] = L_shl( Mpy_32_16_1( Q[m], tmp1 ), s ); + Q[m] = L_shl( Mpy_32_16_1( Q[m], tmp1 ), s ); /*Q31 - Q_e*/ move32(); } } @@ -1776,7 +1776,7 @@ void tcx_noise_filling( tmp1 = extract_l( L_mult0( tmp2, win ) ); FOR( m = sub( i, win ); m < i; m++ ) { - Q[m] = L_shl( Mpy_32_16_1( Q[m], tmp1 ), s ); + Q[m] = L_shl( Mpy_32_16_1( Q[m], tmp1 ), s ); /*Q31 - Q_e*/ move32(); win = sub( win, 1 ); tmp1 = sub( tmp1, tmp2 ); @@ -1794,7 +1794,7 @@ void tcx_noise_filling( } Random( &seed ); - Q[i] = L_mult0( mult( seed, fac_ns ), win ); + Q[i] = L_mult0( mult( seed, fac_ns ), win ); /*Q31 - Q_e*/ move32(); tmp1 = shr( seed, 4 ); @@ -1813,30 +1813,30 @@ void tcx_noise_filling( /* RMS-normalize uppermost noise-filled segment */ tmp1 = BASOP_Util_Divide3216_Scale( nrg, sub( lowpassLine, segmentOffset ), &s ); /* mean */ s = add( s, 9 - 15 ); /* compensate energy scaling */ - tmp1 = ISqrt16( tmp1, &s ); /* 1/RMS */ - tmp1 = mult_r( tmp1, inv_int[nTransWidth] ); /* compensate win */ + tmp1 = ISqrt16( tmp1, &s ); /* 1/RMS Q15 - s*/ + tmp1 = mult_r( tmp1, inv_int[nTransWidth] ); /* compensate win Q15 - s*/ s = add( s, sub( 16, Q_e ) ); /* compensate noise scaling */ FOR( m = segmentOffset; m < lowpassLine; m++ ) { - Q[m] = L_shl( Mpy_32_16_1( Q[m], tmp1 ), s ); + Q[m] = L_shl( Mpy_32_16_1( Q[m], tmp1 ), s ); /*Q31 - Q_e*/ move32(); } } } void tcx_noise_filling_with_shift( - Word32 *Q, + Word32 *Q, /*Q31 - Q_e*/ Word16 *Q_e, - Word16 seed, - const Word16 iFirstLine, - const Word16 lowpassLine, - const Word16 nTransWidth, - const Word16 L_frame, - const Word16 tiltCompFactor, - Word16 fac_ns, - Word16 *infoTCXNoise, - const Word16 element_mode /* i : IVAS element mode */ + Word16 seed, /*Q0*/ + const Word16 iFirstLine, /*Q0*/ + const Word16 lowpassLine, /*Q0*/ + const Word16 nTransWidth, /*Q0*/ + const Word16 L_frame, /*Q0*/ + const Word16 tiltCompFactor, /*Q0*/ + Word16 fac_ns, /*Q15*/ + Word16 *infoTCXNoise, /*Q0*/ + const Word16 element_mode /* i : IVAS element mode Q0*/ ) { Word16 i, m, segmentOffset; @@ -1850,14 +1850,14 @@ void tcx_noise_filling_with_shift( set16_fx( new_Q_e, *Q_e, N_MAX ); /* get inverse frame length */ - tmp1 = getInvFrameLen( L_frame ); + tmp1 = getInvFrameLen( L_frame ); /*Q21*/ /* tilt_factor = (float)pow(max_val(0.375f, tiltCompFactor), 1.0f/(float)L_frame); */ tmp32 = BASOP_Util_Log2( L_deposit_h( s_max( 0x3000, tiltCompFactor ) ) ); /* 6Q25 */ - tmp32 = L_shr( Mpy_32_16_1( tmp32, tmp1 ), 6 ); + tmp32 = L_shr( Mpy_32_16_1( tmp32, tmp1 ), 6 ); /*Q25*/ BASOP_SATURATE_WARNING_OFF_EVS; #ifdef BASOP_NOGLOB - tilt_factor = round_fx_sat( BASOP_Util_InvLog2( tmp32 ) ); + tilt_factor = round_fx_sat( BASOP_Util_InvLog2( tmp32 ) ); /*Q15*/ #else tilt_factor = round_fx( BASOP_Util_InvLog2( tmp32 ) ); #endif @@ -1884,7 +1884,7 @@ void tcx_noise_filling_with_shift( /* fac_ns *= (float)pow(tilt_factor, (float)i); */ FOR( m = 0; m < i; m++ ) { - fac_ns = mult_r( fac_ns, tilt_factor ); + fac_ns = mult_r( fac_ns, tilt_factor ); /*Q15*/ } i = add( i, 1 ); segmentOffset = i; @@ -1896,7 +1896,7 @@ void tcx_noise_filling_with_shift( FOR( ; i < lowpassLine; i++ ) { - fac_ns = mult_r( fac_ns, tilt_factor ); + fac_ns = mult_r( fac_ns, tilt_factor ); /*Q15*/ IF( Q[i] != 0 ) { @@ -1906,8 +1906,8 @@ void tcx_noise_filling_with_shift( tmp1 = BASOP_Util_Divide3216_Scale( nrg, sub( i, segmentOffset ), &s ); /* mean */ // Q-factor of nrg is -8. exp = 31-(-8) = 39 s = add( s, 39 - 15 ); /* scaling */ - tmp1 = ISqrt16( tmp1, &s ); /* 1/RMS */ - tmp1 = mult_r( tmp1, inv_int[nTransWidth] ); /* compensate win */ + tmp1 = ISqrt16( tmp1, &s ); /* 1/RMS Q15 - s*/ + tmp1 = mult_r( tmp1, inv_int[nTransWidth] ); /* compensate win Q15 - s*/ tmp2 = sub( i, win ); IF( LT_16( segmentOffset, tmp2 ) ) @@ -1916,32 +1916,32 @@ void tcx_noise_filling_with_shift( { Word16 nrm = 31; move16(); - Q[m] = Mpy_32_16_1( Q[m], tmp1 ); + Q[m] = Mpy_32_16_1( Q[m], tmp1 ); /*Q31 - Q_e*/ move32(); IF( Q[m] ) { nrm = norm_l( Q[m] ); } - Q[m] = L_shl( Q[m], nrm ); + Q[m] = L_shl( Q[m], nrm ); /*Q31 - Q_e + nrm*/ move32(); new_Q_e[m] = sub( add( new_Q_e[m], s ), nrm ); move32(); } } - tmp2 = mult( tmp1, inv_int[nTransWidth] ); - tmp1 = extract_l( L_mult0( tmp2, win ) ); + tmp2 = mult( tmp1, inv_int[nTransWidth] ); /*Q15 - s*/ + tmp1 = extract_l( L_mult0( tmp2, win ) ); /*Q15 - s*/ FOR( m = sub( i, win ); m < i; m++ ) { Word16 nrm = 31; - Q[m] = Mpy_32_16_1( Q[m], tmp1 ); + Q[m] = Mpy_32_16_1( Q[m], tmp1 ); /*Q31 - Q_e*/ move32(); IF( Q[m] ) { nrm = norm_l( Q[m] ); } - Q[m] = L_shl( Q[m], nrm ); + Q[m] = L_shl( Q[m], nrm ); /*Q31 - Q_e*/ move32(); new_Q_e[m] = sub( add( new_Q_e[m], s ), nrm ); move32(); @@ -1970,12 +1970,12 @@ void tcx_noise_filling_with_shift( { nrm = norm_l( Q[i] ); } - Q[i] = L_shl( Q[i], nrm ); + Q[i] = L_shl( Q[i], nrm ); /*Q31 - Q_e*/ move32(); new_Q_e[i] = sub( 31, nrm ); tmp1 = shr( seed, 4 ); - nrg = L_mac0( nrg, tmp1, tmp1 ); /* sum up energy of current noise segment */ + nrg = L_mac0( nrg, tmp1, tmp1 ); /* sum up energy of current noise segment Q-8*/ IF( infoTCXNoise ) /* set noiseflags for IGF */ { @@ -1991,8 +1991,8 @@ void tcx_noise_filling_with_shift( tmp1 = BASOP_Util_Divide3216_Scale( nrg, sub( lowpassLine, segmentOffset ), &s ); /* mean */ // Q-factor of nrg is -8. exp = 31-(-8) = 39 s = add( s, 39 - 15 ); /* compensate energy scaling */ - tmp1 = ISqrt16( tmp1, &s ); /* 1/RMS */ - tmp1 = mult_r( tmp1, inv_int[nTransWidth] ); /* compensate win */ + tmp1 = ISqrt16( tmp1, &s ); /* 1/RMS Q15 - s*/ + tmp1 = mult_r( tmp1, inv_int[nTransWidth] ); /* compensate win Q15 - s*/ FOR( m = segmentOffset; m < lowpassLine; m++ ) { @@ -2003,13 +2003,13 @@ void tcx_noise_filling_with_shift( - flt Q[m] = (Q[m] * 2^(new_Q_e[m] - 31)) / (nTransWidth*nTransWidth) - flt tmp1 = (tmp1 * 2^(s - 15)) * (nTransWidth*nTransWidth) */ - Q[m] = Mpy_32_16_1( Q[m], tmp1 ); + Q[m] = Mpy_32_16_1( Q[m], tmp1 ); /*Q15 - Q_e - s*/ move32(); IF( Q[m] ) { nrm = norm_l( Q[m] ); } - Q[m] = L_shl( Q[m], nrm ); + Q[m] = L_shl( Q[m], nrm ); /*Q15 - Q_e - s + nrm*/ move32(); new_Q_e[m] = add( new_Q_e[m], s - nrm ); move32(); @@ -2025,7 +2025,7 @@ void tcx_noise_filling_with_shift( FOR( i = 0; i < lowpassLine; i++ ) { - Q[i] = L_shr( Q[i], sub( max_e, new_Q_e[i] ) ); + Q[i] = L_shr( Q[i], sub( max_e, new_Q_e[i] ) ); /*Q31 - Q_e*/ move32(); } @@ -2040,13 +2040,13 @@ void tcx_noise_filling_with_shift( void InitTnsConfigs( - const Word16 bwidth, - const Word16 L_frame, + const Word16 bwidth, /*Q0*/ + const Word16 L_frame, /*Q0*/ STnsConfig tnsConfig[2][2], - const Word16 igfStopFreq, - const Word32 total_brate, - const Word16 element_mode, - const Word16 MCT_flag ) + const Word16 igfStopFreq, /*Q0*/ + const Word32 total_brate, /*Q0*/ + const Word16 element_mode, /*Q0*/ + const Word16 MCT_flag /*Q0*/ ) { IF( GT_32( total_brate, ACELP_32k ) ) { @@ -2058,13 +2058,13 @@ void InitTnsConfigs( #ifdef IVAS_FLOAT_FIXED void InitTnsConfigs_ivas_fx( - const Word16 bwidth, - const Word16 L_frame, + const Word16 bwidth, /*Q0*/ + const Word16 L_frame, /*Q0*/ STnsConfig tnsConfig[2][2], - const Word16 igfStopFreq, - const Word32 total_brate, - const Word16 element_mode, - const Word16 MCT_flag ) + const Word16 igfStopFreq, /*Q0*/ + const Word32 total_brate, /*Q0*/ + const Word16 element_mode, /*Q0*/ + const Word16 MCT_flag /*Q0*/ ) { IF( GT_32( total_brate, ACELP_32k ) ) { @@ -2078,8 +2078,8 @@ void InitTnsConfigs_ivas_fx( void SetTnsConfig( TCX_CONFIG_HANDLE hTcxCfg, /* i : configuration of TCX */ - const Word16 isTCX20, - const Word16 isAfterACELP ) + const Word16 isTCX20, /*Q0*/ + const Word16 isAfterACELP /*Q0*/ ) { move16(); hTcxCfg->pCurrentTnsConfig = &hTcxCfg->tnsConfig[isTCX20][isAfterACELP]; @@ -2095,10 +2095,10 @@ void SetTnsConfig( void SetAllowTnsOnWhite( STnsConfig tnsConfig[2][2], /* o : updated TNS configurations */ - const Word8 allowTnsOnWhite /* i : flag for TNS in whiteded domain mode */ + const Word8 allowTnsOnWhite /* i : flag for TNS in whiteded domain mode Q0*/ ) { - tnsConfig[0][0].allowTnsOnWhite = allowTnsOnWhite; + tnsConfig[0][0].allowTnsOnWhite = allowTnsOnWhite; /*Q0*/ move16(); tnsConfig[0][1].allowTnsOnWhite = allowTnsOnWhite; move16(); @@ -2112,14 +2112,14 @@ void SetAllowTnsOnWhite( #undef IVAS_CODE_TCX_UTIL void tcx_get_gain( - Word32 *x, /* i: spectrum 1 */ + Word32 *x, /* i: spectrum 1 Q31 - x_e*/ Word16 x_e, /* i: spectrum 1 exponent */ - Word32 *y, /* i: spectrum 2 */ + Word32 *y, /* i: spectrum 2 Q31 - y_e*/ Word16 y_e, /* i: spectrum 2 exponent */ - Word16 n, /* i: length */ - Word16 *gain, /* o: gain */ + Word16 n, /* i: length Q0*/ + Word16 *gain, /* o: gain Q15 - gain_e*/ Word16 *gain_e, /* o: gain exponent */ - Word32 *en_y, /* o: energy of y (optional) */ + Word32 *en_y, /* o: energy of y (optional) Q31 - en_y_e*/ Word16 *en_y_e /* o: energy of y exponent (optional) */ ) { @@ -2138,14 +2138,14 @@ void tcx_get_gain( FOR( i = 0; i < n; i++ ) { if ( x[i] > 0 ) - maxX = L_max( maxX, x[i] ); + maxX = L_max( maxX, x[i] ); /*Q31 - x_e*/ if ( x[i] < 0 ) - minX = L_min( minX, x[i] ); + minX = L_min( minX, x[i] ); /*Q31 - x_e*/ if ( y[i] > 0 ) - maxY = L_max( maxY, y[i] ); + maxY = L_max( maxY, y[i] ); /*Q31 - y_e*/ if ( y[i] < 0 ) - minY = L_min( minY, y[i] ); + minY = L_min( minY, y[i] ); /*Q31 - y_e*/ } sx = s_min( norm_l( maxX ), norm_l( minX ) ); sy = s_min( norm_l( maxY ), norm_l( minY ) ); @@ -2156,9 +2156,9 @@ void tcx_get_gain( corr = L_deposit_l( 0 ); FOR( i = 0; i < n; i++ ) { - tmp = round_fx( L_shl( y[i], sy ) ); - ener = L_mac0( ener, tmp, tmp ); - corr = L_mac0( corr, tmp, round_fx( L_shl( x[i], sx ) ) ); + tmp = round_fx( L_shl( y[i], sy ) ); /*Q15 - y_e + sy*/ + ener = L_mac0( ener, tmp, tmp ); /*Q30 - 2*(y_e - sy)*/ + corr = L_mac0( corr, tmp, round_fx( L_shl( x[i], sx ) ) ); /*Q30 - 2*(x_e - sx + y_e - sy)*/ } if ( ener == 0 ) @@ -2168,15 +2168,15 @@ void tcx_get_gain( corr_e = add( sub( add( x_e, y_e ), add( sx, sy ) ), 1 ); tmp = sub( norm_l( corr ), 1 ); - corr = L_shl( corr, tmp ); + corr = L_shl( corr, tmp ); /*Q31 - corr_e + tmp*/ corr_e = sub( corr_e, tmp ); tmp = norm_l( ener ); - ener = L_shl( ener, tmp ); + ener = L_shl( ener, tmp ); /*Q31 - ener_e + tmp*/ ener_e = sub( ener_e, tmp ); #ifdef BASOP_NOGLOB - tmp = div_s( abs_s( round_fx_o( corr, &Overflow ) ), round_fx_o( ener, &Overflow ) ); + tmp = div_s( abs_s( round_fx_o( corr, &Overflow ) ), round_fx_o( ener, &Overflow ) ); /*Q15 - (corr_e - ener_e)*/ #else tmp = div_s( abs_s( round_fx( corr ) ), round_fx( ener ) ); #endif @@ -2190,7 +2190,7 @@ void tcx_get_gain( if ( en_y != NULL ) { - *en_y = ener; + *en_y = ener; /*Q31 - ener_e*/ move32(); } if ( en_y_e != NULL ) @@ -2248,37 +2248,37 @@ void init_TCX_config_dec( /* TEMPORARY */ #endif void init_TCX_config( TCX_CONFIG_HANDLE hTcxCfg, - Word16 L_frame, - Word16 fscale, - Word16 L_frameTCX, - Word16 fscaleFB ) + Word16 L_frame, /*Q0*/ + Word16 fscale, /*Q0*/ + Word16 L_frameTCX, /*Q0*/ + Word16 fscaleFB /*Q0*/ ) { /* Initialize the TCX MDCT windows */ - hTcxCfg->tcx_mdct_window_length = extract_l( L_shr( L_mult0( L_LOOK_12k8, fscale ), LD_FSCALE_DENOM ) ); + hTcxCfg->tcx_mdct_window_length = extract_l( L_shr( L_mult0( L_LOOK_12k8, fscale ), LD_FSCALE_DENOM ) ); /*Q0*/ move16(); - hTcxCfg->tcx_mdct_window_delay = hTcxCfg->tcx_mdct_window_length; + hTcxCfg->tcx_mdct_window_delay = hTcxCfg->tcx_mdct_window_length; /*Q0*/ move16(); hTcxCfg->tcx_mdct_window_half_length = extract_l( L_shr( L_mult0( L_LOOK_12k8 - NS2SA( 12800, 5000000L ), fscale ), LD_FSCALE_DENOM ) ); move16(); - hTcxCfg->tcx_mdct_window_min_length = shr( L_frame, 4 ); /* 1.25ms */ + hTcxCfg->tcx_mdct_window_min_length = shr( L_frame, 4 ); /* 1.25ms Q0*/ move16(); - hTcxCfg->tcx_mdct_window_trans_length = shr( L_frame, 4 ); /* 1.25ms */ + hTcxCfg->tcx_mdct_window_trans_length = shr( L_frame, 4 ); /* 1.25ms Q0*/ move16(); - hTcxCfg->tcx5Size = shr( L_frame, 2 ); /* 5ms */ + hTcxCfg->tcx5Size = shr( L_frame, 2 ); /* 5ms Q0*/ move16(); - hTcxCfg->tcx_mdct_window_lengthFB = extract_l( L_shr( L_mult0( L_LOOK_12k8, fscaleFB ), LD_FSCALE_DENOM ) ); + hTcxCfg->tcx_mdct_window_lengthFB = extract_l( L_shr( L_mult0( L_LOOK_12k8, fscaleFB ), LD_FSCALE_DENOM ) ); /*Q0*/ move16(); - hTcxCfg->tcx_mdct_window_delayFB = hTcxCfg->tcx_mdct_window_lengthFB; + hTcxCfg->tcx_mdct_window_delayFB = hTcxCfg->tcx_mdct_window_lengthFB; /*Q0*/ move16(); - hTcxCfg->tcx_mdct_window_half_lengthFB = extract_l( L_shr( L_mult0( L_LOOK_12k8 - NS2SA( 12800, 5000000L ), fscaleFB ), LD_FSCALE_DENOM ) ); + hTcxCfg->tcx_mdct_window_half_lengthFB = extract_l( L_shr( L_mult0( L_LOOK_12k8 - NS2SA( 12800, 5000000L ), fscaleFB ), LD_FSCALE_DENOM ) ); /*Q0*/ move16(); - hTcxCfg->tcx_mdct_window_min_lengthFB = shr( L_frameTCX, 4 ); /* 1.25ms */ + hTcxCfg->tcx_mdct_window_min_lengthFB = shr( L_frameTCX, 4 ); /* 1.25ms Q0*/ move16(); - hTcxCfg->tcx_mdct_window_trans_lengthFB = shr( L_frameTCX, 4 ); /* 1.25ms */ + hTcxCfg->tcx_mdct_window_trans_lengthFB = shr( L_frameTCX, 4 ); /* 1.25ms Q0*/ move16(); - hTcxCfg->tcx5SizeFB = shr( L_frameTCX, 2 ); /* 5ms */ + hTcxCfg->tcx5SizeFB = shr( L_frameTCX, 2 ); /* 5ms Q0*/ move16(); mdct_window_sine( hTcxCfg->tcx_mdct_window, hTcxCfg->tcx_mdct_window_length ); mdct_window_sine( hTcxCfg->tcx_mdct_window_half, hTcxCfg->tcx_mdct_window_half_length ); diff --git a/lib_enc/core_enc_init.c b/lib_enc/core_enc_init.c index ef2e5408b..95e3f74f6 100644 --- a/lib_enc/core_enc_init.c +++ b/lib_enc/core_enc_init.c @@ -1944,26 +1944,26 @@ static void init_modes_ivas_fx( IF( LT_32( n, FRAME_SIZE_NB - 1 ) ) { test(); - IF( FrameSizeConfig[n].frame_bits <= st->bits_frame_nominal && FrameSizeConfig[n + 1].frame_bits > st->bits_frame_nominal ) + IF( LE_32( FrameSizeConfig[n].frame_bits, st->bits_frame_nominal ) && GT_32( FrameSizeConfig[n + 1].frame_bits, st->bits_frame_nominal ) ) { st->frame_size_index = n; move16(); st->bits_frame = st->bits_frame_nominal; move16(); - st->bits_frame_core = st->bits_frame_nominal - FrameSizeConfig[n].transmission_bits - FrameSizeConfig[n].bandwidth_bits - FrameSizeConfig[n].reserved_bits; + st->bits_frame_core = sub( sub( sub( st->bits_frame_nominal, FrameSizeConfig[n].transmission_bits ), FrameSizeConfig[n].bandwidth_bits ), FrameSizeConfig[n].reserved_bits ); move16(); BREAK; } } ELSE { - IF( FrameSizeConfig[n].frame_bits <= st->bits_frame_nominal ) + IF( LE_32( FrameSizeConfig[n].frame_bits, st->bits_frame_nominal ) ) { st->frame_size_index = n; move16(); st->bits_frame = st->bits_frame_nominal; move16(); - st->bits_frame_core = st->bits_frame_nominal - FrameSizeConfig[n].transmission_bits - FrameSizeConfig[n].bandwidth_bits - FrameSizeConfig[n].reserved_bits; + st->bits_frame_core = sub( sub( sub( st->bits_frame_nominal, FrameSizeConfig[n].transmission_bits ), FrameSizeConfig[n].bandwidth_bits ), FrameSizeConfig[n].reserved_bits ); move16(); BREAK; } diff --git a/lib_enc/gs_enc_fx.c b/lib_enc/gs_enc_fx.c index e1cd71e0a..4e1d5ef30 100644 --- a/lib_enc/gs_enc_fx.c +++ b/lib_enc/gs_enc_fx.c @@ -684,7 +684,7 @@ void encod_audio_ivas_fx( * Remove potential pre-echo in case an onset has been detected *--------------------------------------------------------------------------------------*/ - pre_echo_att_fx( &hGSCEnc->Last_frame_ener_fx, exc, attack_flag, Q_exc, st_fx->last_coder_type, st_fx->L_frame ); + pre_echo_att_ivas_fx( &hGSCEnc->Last_frame_ener_fx, exc, attack_flag, Q_exc, st_fx->last_coder_type, st_fx->L_frame ); /*--------------------------------------------------------------------------------------* * Update BWE excitation diff --git a/lib_enc/ivas_cpe_enc.c b/lib_enc/ivas_cpe_enc.c index 4d18891c4..7948c6e17 100644 --- a/lib_enc/ivas_cpe_enc.c +++ b/lib_enc/ivas_cpe_enc.c @@ -382,15 +382,6 @@ ivas_error ivas_cpe_enc_fx( stereo_switching_enc_fx( hCPE, sts[0]->old_input_signal_fx, input_frame, q_inp ); #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - - if ( hCPE->element_mode > IVAS_CPE_DFT && hCPE->input_mem[0] != NULL && hCPE->element_mode != IVAS_CPE_MDCT ) - { - for ( n = 0; n < CPE_CHANNELS; n++ ) - { - fixedToFloat_arr( hCPE->input_mem_fx[n], hCPE->input_mem[n], q_inp, STEREO_DFT_OVL_MAX * input_frame / L_FRAME48k ); - } - } - if ( hCPE->element_mode == IVAS_CPE_DFT ) { for ( n = 0; n < CPE_CHANNELS; n++ ) @@ -467,7 +458,7 @@ ivas_error ivas_cpe_enc_fx( #ifdef IVAS_FLOAT_FIXED_CONVERSIONS floatToFixed_arr16( sts[n]->input, sts[n]->input_fx, -1, input_frame ); #endif - RunTransientDetection_ivas_fx( sts[n]->input_fx, input_frame, sts[n]->hTranDet ); + RunTransientDetection_ivas_fx( sts[n]->input_fx, input_frame, sts[n]->hTranDet, -1 ); sts[n]->hTranDet->subblockEnergies.subblockNrg_e = 31 - Q7; sts[n]->hTranDet->subblockEnergies.accSubblockNrg_e = 31 - Q7; move16(); @@ -616,9 +607,7 @@ ivas_error ivas_cpe_enc_fx( #ifndef MSAN_FIX hCPE->hStereoDft->q_input_mem_itd[i] = Q_factor_arr( &hCPE->hStereoDft->input_mem_itd[i][0], STEREO_DFT_OVL_MAX ); #endif // MSAN_FIX - hCPE->q_input_mem[i] = Q_factor_arr( &hCPE->input_mem[i][0], NS2SA( input_Fs, STEREO_DFT_OVL_NS ) ); floatToFixed_arr( sts[i]->old_input_signal, sts[i]->old_input_signal_fx, sts[i]->q_inp, 1965 ); - floatToFixed_arr( &hCPE->input_mem[i][0], &hCPE->input_mem_fx[i][0], hCPE->q_input_mem[i], NS2SA( input_Fs, STEREO_DFT_OVL_NS ) ); #ifndef MSAN_FIX floatToFixed_arr( &hCPE->hStereoDft->input_mem_itd[i][0], &hCPE->hStereoDft->input_mem_itd_fx[i][0], hCPE->hStereoDft->q_input_mem_itd[i], STEREO_DFT_OVL_MAX ); #endif // MSAN_FIX @@ -758,9 +747,7 @@ ivas_error ivas_cpe_enc_fx( FOR( int16_t i = 0; i < CPE_CHANNELS; i++ ) { sts[i]->q_inp = Q_factor_arr( sts[i]->old_input_signal, 1965 ); // check length - hCPE->q_input_mem[i] = Q_factor_arr( &hCPE->input_mem[i][0], NS2SA( input_Fs, STEREO_DFT_OVL_NS ) ); floatToFixed_arr( sts[i]->old_input_signal, sts[i]->old_input_signal_fx, sts[i]->q_inp, 1965 ); - floatToFixed_arr( &hCPE->input_mem[i][0], &hCPE->input_mem_fx[i][0], hCPE->q_input_mem[i], NS2SA( input_Fs, STEREO_DFT_OVL_NS ) ); } floatToFixed_arr( hCPE->hCoreCoder[0]->voicing, hCPE->hCoreCoder[0]->voicing_fx, 15, 3 ); if ( hCPE->element_mode == IVAS_CPE_DFT && hCPE->hStereoDft->res_cod_mode[STEREO_DFT_OFFSET] ) @@ -775,7 +762,6 @@ ivas_error ivas_cpe_enc_fx( { FOR( int16_t i = 0; i < CPE_CHANNELS; i++ ) { - fixedToFloat_arr( &hCPE->input_mem_fx[i][0], &hCPE->input_mem[i][0], hCPE->q_input_mem[i], NS2SA( input_Fs, STEREO_DFT_OVL_NS ) ); fixedToFloat_arr( sts[i]->old_input_signal_fx, sts[i]->old_input_signal, sts[i]->q_inp, 1965 ); } } @@ -835,7 +821,6 @@ ivas_error ivas_cpe_enc_fx( FOR( i = 0; i < CPE_CHANNELS; i++ ) { - fixedToFloat_arr( &hCPE->input_mem_fx[i][0], &hCPE->input_mem[i][0], hCPE->q_input_mem[i], NS2SA( input_Fs, STEREO_DFT_OVL_NS ) ); me2f_buf( hCPE->hStereoDft->DFT_fx[i], hCPE->hStereoDft->DFT_fx_e[i], hCPE->hStereoDft->DFT[i], STEREO_DFT_N_MAX_ENC ); } /*local fix2flt*/ @@ -2188,23 +2173,6 @@ ivas_error create_cpe_enc( * Input memory buffer: allocate and initialize *-----------------------------------------------------------------*/ - for ( n = 0; n < CPE_CHANNELS; n++ ) - { - if ( ivas_format == STEREO_FORMAT || ivas_format == MASA_FORMAT || ( ivas_format == MC_FORMAT && st_ivas->mc_mode == MC_MODE_MCMASA ) || ivas_format == MASA_ISM_FORMAT ) - { - if ( ( hCPE->input_mem[n] = (float *) malloc( sizeof( float ) * NS2SA( input_Fs, STEREO_DFT_OVL_NS ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DFT stereo memory\n" ) ); - } - - set_zero( hCPE->input_mem[n], NS2SA( input_Fs, STEREO_DFT_OVL_NS ) ); - } - else - { - hCPE->input_mem[n] = NULL; - } - } - // This should be removed when actual create_cpe_enc_fx #ifdef IVAS_FLOAT_FIXED FOR( n = 0; n < CPE_CHANNELS; n++ ) @@ -2506,31 +2474,10 @@ ivas_error create_cpe_enc_fx( } ELSE { - hCPE->input_mem[n] = NULL; hCPE->input_mem_fx[n] = NULL; } } - -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS // TODO: To be removed later - for ( n = 0; n < CPE_CHANNELS; n++ ) - { - if ( ivas_format == STEREO_FORMAT || ivas_format == MASA_FORMAT || ( ivas_format == MC_FORMAT && st_ivas->mc_mode == MC_MODE_MCMASA ) || ivas_format == MASA_ISM_FORMAT ) - { - if ( ( hCPE->input_mem[n] = (float *) malloc( sizeof( float ) * NS2SA( input_Fs, STEREO_DFT_OVL_NS ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DFT stereo memory\n" ) ); - } - - set_zero( hCPE->input_mem[n], NS2SA( input_Fs, STEREO_DFT_OVL_NS ) ); - } - else - { - hCPE->input_mem[n] = NULL; - } - } -#endif - /*-----------------------------------------------------------------* * stereo classifier: allocate and initialize *-----------------------------------------------------------------*/ @@ -2548,7 +2495,7 @@ ivas_error create_cpe_enc_fx( IF( EQ_16( cpe_id, sub( st_ivas->nCPE, 1 ) ) ) { - IF( ( error = ivas_initialize_MD_bstr_enc( &( hCPE->hMetaData ), st_ivas ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_initialize_MD_bstr_enc( &( hCPE->hMetaData ), st_ivas ) ), IVAS_ERR_OK ) ) { return error; } @@ -2570,16 +2517,17 @@ ivas_error create_cpe_enc_fx( IF( GT_16( st_ivas->nCPE, 1 ) ) { st->total_brate = hCPE->element_brate; /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() */ + move32(); } ELSE { st->total_brate = L_shr( hCPE->element_brate, CPE_CHANNELS ); /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() */ + move32(); } - move32(); st->mct_chan_mode = MCT_CHAN_MODE_REGULAR; move32(); - IF( ( error = init_encoder_ivas_fx( st, st_ivas, n, hEncoderConfig->var_SID_rate_flag, hEncoderConfig->interval_SID, 0, ISM_MODE_NONE, hCPE->element_brate ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = init_encoder_ivas_fx( st, st_ivas, n, hEncoderConfig->var_SID_rate_flag, hEncoderConfig->interval_SID, 0, ISM_MODE_NONE, hCPE->element_brate ) ), IVAS_ERR_OK ) ) { return error; } @@ -2620,7 +2568,7 @@ ivas_error create_cpe_enc_fx( { FOR( n = 0; n < CPE_CHANNELS; n++ ) { - IF( ( error = front_vad_create_fx( &( hCPE->hFrontVad[n] ), hEncoderConfig ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = front_vad_create_fx( &( hCPE->hFrontVad[n] ), hEncoderConfig ) ), IVAS_ERR_OK ) ) { return error; } @@ -2640,7 +2588,7 @@ ivas_error create_cpe_enc_fx( IF( EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) ) { - IF( ( error = stereo_dft_enc_create_fx( &( hCPE->hStereoDft ), input_Fs, max_bwidth ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = stereo_dft_enc_create_fx( &( hCPE->hStereoDft ), input_Fs, max_bwidth ) ), IVAS_ERR_OK ) ) { return error; } @@ -2709,7 +2657,7 @@ ivas_error create_cpe_enc_fx( test(); IF( EQ_16( hCPE->element_mode, IVAS_CPE_MDCT ) && LE_32( element_brate, MAX_MDCT_ITD_BRATE ) && EQ_16( ivas_format, STEREO_FORMAT ) ) { - IF( ( error = initMdctItdHandling( hCPE->hStereoMdct, input_Fs ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = initMdctItdHandling( hCPE->hStereoMdct, input_Fs ) ), IVAS_ERR_OK ) ) { return error; } @@ -2741,14 +2689,9 @@ void destroy_cpe_enc( } FOR( n = 0; n < CPE_CHANNELS; n++ ){ - IF( hCPE->input_mem[n] != NULL ){ - free( hCPE->input_mem[n] ); - hCPE->input_mem[n] = NULL; -} #ifdef IVAS_FLOAT_FIXED -IF( hCPE->input_mem_fx[n] != NULL ) -{ - free( hCPE->input_mem_fx[n] ); + IF( hCPE->input_mem_fx[n] != NULL ){ + free( hCPE->input_mem_fx[n] ); hCPE->input_mem_fx[n] = NULL; } #endif diff --git a/lib_enc/ivas_ism_enc.c b/lib_enc/ivas_ism_enc.c index e81b89e13..335b524a3 100644 --- a/lib_enc/ivas_ism_enc.c +++ b/lib_enc/ivas_ism_enc.c @@ -558,7 +558,7 @@ ivas_error ivas_ism_enc_fx( #ifdef IVAS_FLOAT_FIXED_CONVERSIONS fixedToFloat_arrL( st->input32_fx, st->input, q_data, input_frame ); #endif - RunTransientDetection_ivas_fx( st->input_fx, input_frame, st->hTranDet ); + RunTransientDetection_ivas_fx( st->input_fx, input_frame, st->hTranDet, -1 ); st->hTranDet->subblockEnergies.subblockNrg_e = 31 - Q7; st->hTranDet->subblockEnergies.accSubblockNrg_e = 31 - Q7; move16(); diff --git a/lib_enc/ivas_mc_param_enc.c b/lib_enc/ivas_mc_param_enc.c index 4c5c7905e..22de8cfe6 100644 --- a/lib_enc/ivas_mc_param_enc.c +++ b/lib_enc/ivas_mc_param_enc.c @@ -892,7 +892,7 @@ void ivas_param_mc_enc_fx( #else Copy_Scale_sig_32_16( data_dmx_fx[ch], data_dmx_fx16[ch], input_frame, -Q1 - Q11 ); // Q11 -> Q(-1) #endif - RunTransientDetection_ivas_fx( data_dmx_fx16[ch], input_frame, st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet ); + RunTransientDetection_ivas_fx( data_dmx_fx16[ch], input_frame, st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet, -1 ); ivas_param_mc_transient_detection_fx( hParamMC, st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet, &bAttackPresent[ch], &attackIdx[ch] ); } @@ -984,7 +984,7 @@ void ivas_param_mc_enc_fx( set32_fx( data_f_fx[ch], 0, input_frame ); set16_fx( data_f_fx16, 0, input_frame ); - RunTransientDetection_ivas_fx( data_f_fx16, input_frame, st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet ); + RunTransientDetection_ivas_fx( data_f_fx16, input_frame, st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet, -1 ); } } diff --git a/lib_enc/ivas_osba_enc.c b/lib_enc/ivas_osba_enc.c index f9fcd6ca9..7c5a22c8e 100644 --- a/lib_enc/ivas_osba_enc.c +++ b/lib_enc/ivas_osba_enc.c @@ -434,14 +434,14 @@ ivas_error ivas_osba_enc_reconfig( move16(); ivas_spar_enc_close_fx( &( st_ivas->hSpar ), hEncoderConfig->input_Fs, hEncoderConfig->nchan_inp, spar_reconfig_flag ); - IF( ( error = ivas_spar_enc_open( st_ivas, spar_reconfig_flag ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_spar_enc_open( st_ivas, spar_reconfig_flag ) ), IVAS_ERR_OK ) ) { return error; } } st_ivas->hSpar->spar_reconfig_flag = spar_reconfig_flag; move16(); - IF( ( error = ivas_dirac_enc_reconfigure( st_ivas ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_dirac_enc_reconfigure( st_ivas ) ), IVAS_ERR_OK ) ) { return error; } @@ -457,12 +457,15 @@ ivas_error ivas_osba_enc_reconfig( FOR( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) { q_direction[dir].band_data[j].energy_ratio_index[i] = 0; + move32(); q_direction[dir].band_data[j].energy_ratio_index_mod[i] = 0; + move32(); } } } } hSpar->enc_param_start_band = hDirAC->hConfig->enc_param_start_band; + move16(); /*-----------------------------------------------------------------* * Allocate, initialize, and configure SCE/CPE/MCT handles @@ -472,6 +475,7 @@ ivas_error ivas_osba_enc_reconfig( IF( old_ism_mode == ISM_MODE_NONE && EQ_32( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) ) { st_ivas->nCPE = add( st_ivas->nCPE, shr( add( st_ivas->hEncoderConfig->nchan_ism, 1 ), 1 ) ); + move16(); } ELSE IF( EQ_32( old_ism_mode, ISM_SBA_MODE_DISC ) && st_ivas->ism_mode == ISM_MODE_NONE ) { @@ -480,6 +484,7 @@ ivas_error ivas_osba_enc_reconfig( ELSE IF( EQ_32( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) ) { st_ivas->nCPE = add( st_ivas->nCPE, shr( add( st_ivas->hEncoderConfig->nchan_ism, 1 ), 1 ) ); + move16(); nCPE_old = st_ivas->nCPE; move16(); nchan_transport_old = st_ivas->nchan_transport; @@ -489,7 +494,7 @@ ivas_error ivas_osba_enc_reconfig( Word16 tmp_e; Word32 bitrate_per_chan = L_deposit_h( BASOP_Util_Divide3216_Scale( ivas_total_brate, st_ivas->nchan_transport, &tmp_e ) ); bitrate_per_chan = L_shr( bitrate_per_chan, sub( 15, tmp_e ) ); - IF( ( error = ivas_corecoder_enc_reconfig_fx( st_ivas, nSCE_old, nCPE_old, nchan_transport_old, bitrate_per_chan, imult3216( bitrate_per_chan, CPE_CHANNELS ), MC_MODE_NONE ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_corecoder_enc_reconfig_fx( st_ivas, nSCE_old, nCPE_old, nchan_transport_old, bitrate_per_chan, imult3216( bitrate_per_chan, CPE_CHANNELS ), MC_MODE_NONE ) ), IVAS_ERR_OK ) ) { return error; } diff --git a/lib_enc/ivas_sce_enc.c b/lib_enc/ivas_sce_enc.c index 43f9a9322..a6d14e723 100644 --- a/lib_enc/ivas_sce_enc.c +++ b/lib_enc/ivas_sce_enc.c @@ -103,6 +103,7 @@ ivas_error ivas_sce_enc_fx( IVAS_FORMAT ivas_format; ivas_error error; Word16 flag_16k_smc; + Word16 q_input; /*stores q for input_fx*/ push_wmops( "ivas_sce_enc" ); @@ -117,8 +118,14 @@ ivas_error ivas_sce_enc_fx( /*------------------------------------------------------------------* * Initialization - general *-----------------------------------------------------------------*/ - Copy32( data_fx, st->input32_fx, input_frame ); // Q(q_data_fx) - Copy_Scale_sig32_16( st->input32_fx, st->input_fx, input_frame, sub( Q16 - 1, q_data_fx ) ); // Q(q_data_fx) -> Q(-1) + Copy32( data_fx, st->input32_fx, input_frame ); // Q(q_data_fx) + q_input = sub( add( L_norm_arr( st->input32_fx, input_frame ), q_data_fx ), 16 ); + if ( GE_16( q_input, -1 ) ) + { + q_input = -1; + move16(); + } + Copy_Scale_sig32_16( st->input32_fx, st->input_fx, input_frame, sub( add( Q16, q_input ), q_data_fx ) ); // Q(q_data_fx) -> Q(q_input) #ifdef IVAS_FLOAT_FIXED_CONVERSIONS fixedToFloat_arrL( st->input32_fx, st->input, q_data_fx, input_frame ); @@ -152,7 +159,7 @@ ivas_error ivas_sce_enc_fx( test(); IF( NE_32( ivas_format, MC_FORMAT ) || NE_32( st_ivas->mc_mode, MC_MODE_PARAMMC ) ) { - RunTransientDetection_ivas_fx( st->input_fx, input_frame, st->hTranDet ); + RunTransientDetection_ivas_fx( st->input_fx, input_frame, st->hTranDet, q_input ); st->hTranDet->subblockEnergies.subblockNrg_e = 31 - Q7; st->hTranDet->subblockEnergies.accSubblockNrg_e = 31 - Q7; move16(); diff --git a/lib_enc/ivas_stat_enc.h b/lib_enc/ivas_stat_enc.h index ce900485d..515008c0f 100644 --- a/lib_enc/ivas_stat_enc.h +++ b/lib_enc/ivas_stat_enc.h @@ -1561,7 +1561,7 @@ typedef struct cpe_enc_data_structure STEREO_CNG_ENC_HANDLE hStereoCng; /* Stereo CNG data structure */ FRONT_VAD_ENC_HANDLE hFrontVad[CPE_CHANNELS]; - float *input_mem[CPE_CHANNELS]; /* input channels buffers memory; needed to be up-to-date for TD->DFT stereo switching */ + // float *input_mem[CPE_CHANNELS]; /* input channels buffers memory; needed to be up-to-date for TD->DFT stereo switching */ Word32 brate_surplus; /* bitrate surplus for bitrate adaptation in combined format coding */ Word16 *input_mem_fx[CPE_CHANNELS]; /* input channels buffers memory; needed to be up-to-date for TD->DFT stereo switching */ diff --git a/lib_enc/ivas_stereo_dft_enc.c b/lib_enc/ivas_stereo_dft_enc.c index 52c669b13..24d57bb0e 100644 --- a/lib_enc/ivas_stereo_dft_enc.c +++ b/lib_enc/ivas_stereo_dft_enc.c @@ -1344,6 +1344,7 @@ void stereo_enc_itd_init_fx( ) { hItd->prev_itd = 0; + move16(); set32_fx( hItd->itd_fx, 0, STEREO_DFT_ENC_DFT_NB ); set32_fx( hItd->deltaItd_fx, 0, STEREO_DFT_ENC_DFT_NB ); set16_fx( hItd->td_itd, 0, STEREO_DFT_ENC_DFT_NB ); @@ -1351,40 +1352,64 @@ void stereo_enc_itd_init_fx( set16_fx( hItd->itd_index, 0, STEREO_DFT_ENC_DFT_NB ); set32_fx( hItd->xcorr_smooth_fx, 0, STEREO_DFT_N_32k_ENC ); hItd->xcorr_smooth_fx_e = 0; + move16(); hItd->lp_phat_peak_fx = 0; + move32(); hItd->itd_hangover = 0; + move16(); hItd->itd_cnt = 0; + move16(); hItd->prev_sum_nrg_L_lb_fx = 0; + move32(); hItd->prev_sum_nrg_L_lb_fx_e = 0; + move16(); set32_fx( hItd->prev_xcorr_lb_fx, 0, STEREO_DFT_XCORR_LB_MAX ); hItd->prev_xcorr_lb_fx_e = 0; + move16(); set32_fx( hItd->E_band_n_fx, ITD_VAD_E_BAND_N_INIT, STEREO_DFT_ITD_VAD_BAND_NUM ); hItd->vad_frm_cnt = 0; + move16(); hItd->pre_vad = 0; + move16(); hItd->itd_nonzero_cnt = 0; + move16(); set32_fx( hItd->acorr_L_fx, 0, STEREO_DFT_BAND_MAX ); hItd->acorr_L_fx_e = 0; + move16(); set32_fx( hItd->acorr_R_fx, 0, STEREO_DFT_BAND_MAX ); hItd->acorr_R_fx_e = 0; + move16(); hItd->cohSNR_fx = 983040; /*Q16*/ + move32(); hItd->itd_thres_fx = 0; + move32(); hItd->valid_itd_cnt = 0; - + move16(); hItd->detected_itd_flag = 0; + move16(); hItd->itd_tracking = 0; + move16(); hItd->prev_max_fx = 0; + move32(); hItd->prev_index = 0; + move16(); hItd->prev_avg_max_fx = 0; + move32(); hItd->prev_avg_max_fx_e = 0; + move16(); hItd->currFlatness_fx = 0; - + move16(); /* Xtalk classifier */ hItd->prev_m1_fx = 0; + move32(); hItd->prev_m2_fx = 0; + move32(); hItd->prev_itd1 = 0; + move16(); hItd->prev_itd2 = 0; - + move16(); hItd->hybrid_itd_max = 0; + move16(); return; } diff --git a/lib_enc/ivas_stereo_dmx_evs.c b/lib_enc/ivas_stereo_dmx_evs.c index d3be66ae9..c4f14de99 100644 --- a/lib_enc/ivas_stereo_dmx_evs.c +++ b/lib_enc/ivas_stereo_dmx_evs.c @@ -208,17 +208,17 @@ static void calc_energy_fx( const Word32 ratio_float_fx ); static void create_M_signal_fx( - const Word32 srcL_fx[], /* i : Lch input signal Q16 */ - const Word32 srcR_fx[], /* i : Rch input signal Q16 */ - Word32 dmx_fx[], /* o : output signal Q31 */ - const Word32 w_curr_fx, /* i : adapting weight Q31 */ - const int16_t input_frame, /* i : input frame length per channel */ - const Word32 wnd_fx[], /* i : window coef Q31 */ - Word32 *w_prev_fx, /* i/o: adapting prev weight Q31*/ - Word32 *dmx_energy_fx, /* i/o: downmix signal energy dmx_energy_fx_e */ - Word16 *dmx_energy_fx_e, /* i/o: downmix signal energy */ - Word32 *src_energy_fx, /* i/o: input signal energy src_energy_fx_e */ - Word16 *src_energy_fx_e /* i/o: input signal energy */ + const Word32 srcL_fx[], /* i : Lch input signal Q16 */ + const Word32 srcR_fx[], /* i : Rch input signal Q16 */ + Word32 dmx_fx[], /* o : output signal Q31 */ + const Word32 w_curr_fx, /* i : adapting weight Q31 */ + const Word16 input_frame, /* i : input frame length per channel */ + const Word32 wnd_fx[], /* i : window coef Q31 */ + Word32 *w_prev_fx, /* i/o: adapting prev weight Q31*/ + Word32 *dmx_energy_fx, /* i/o: downmix signal energy dmx_energy_fx_e */ + Word16 *dmx_energy_fx_e, /* i/o: downmix signal energy */ + Word32 *src_energy_fx, /* i/o: input signal energy src_energy_fx_e */ + Word16 *src_energy_fx_e /* i/o: input signal energy */ ); static Word32 find_poc_peak_fx( STEREO_DMX_EVS_POC_HANDLE hPOC, /* i/o: phase only correlation structure */ @@ -2571,17 +2571,17 @@ static void adapt_gain( *-------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED static void create_M_signal_fx( - const Word32 srcL_fx[], /* i : Lch input signal Q16 */ - const Word32 srcR_fx[], /* i : Rch input signal Q16 */ - Word32 dmx_fx[], /* o : output signal Q31 */ - const Word32 w_curr_fx, /* i : adapting weight Q31 */ - const int16_t input_frame, /* i : input frame length per channel */ - const Word32 wnd_fx[], /* i : window coef Q31 */ - Word32 *w_prev_fx, /* i/o: adapting prev weight Q31*/ - Word32 *dmx_energy_fx, /* i/o: downmix signal energy dmx_energy_fx_e */ - Word16 *dmx_energy_fx_e, /* i/o: downmix signal energy */ - Word32 *src_energy_fx, /* i/o: input signal energy src_energy_fx_e */ - Word16 *src_energy_fx_e /* i/o: input signal energy */ + const Word32 srcL_fx[], /* i : Lch input signal Q16 */ + const Word32 srcR_fx[], /* i : Rch input signal Q16 */ + Word32 dmx_fx[], /* o : output signal Q31 */ + const Word32 w_curr_fx, /* i : adapting weight Q31 */ + const Word16 input_frame, /* i : input frame length per channel */ + const Word32 wnd_fx[], /* i : window coef Q31 */ + Word32 *w_prev_fx, /* i/o: adapting prev weight Q31*/ + Word32 *dmx_energy_fx, /* i/o: downmix signal energy dmx_energy_fx_e */ + Word16 *dmx_energy_fx_e, /* i/o: downmix signal energy */ + Word32 *src_energy_fx, /* i/o: input signal energy src_energy_fx_e */ + Word16 *src_energy_fx_e /* i/o: input signal energy */ ) { Word32 amp_mod_fx[CPE_CHANNELS]; @@ -2593,8 +2593,16 @@ static void create_M_signal_fx( /* Initialization */ eps_fx = 1024; // 1024.0f in Q0 move32(); - Lbias_fx = ( w_prev_fx[2] == 0 ) ? 1073741824 : 67108864; // 4.0f in Q28 : 0.25f in Q28 - move32(); + IF( w_prev_fx[2] == 0 ) + { + Lbias_fx = 1073741824; // 4.0f in Q28 + move32(); + } + ELSE + { + Lbias_fx = 67108864; // 0.25f in Q28 + move32(); + } weighted_ave_fx( srcL_fx, srcR_fx, dmx_fx, w_curr_fx, w_prev_fx[0], input_frame, wnd_fx ); calc_energy_fx( srcL_fx, srcL_fx, src_energy_fx, src_energy_fx_e, input_frame, STEREO_DMX_EVS_DMX_EGY_FORGETTING_FX ); calc_energy_fx( srcR_fx, srcR_fx, src_energy_fx + 1, src_energy_fx_e + 1, input_frame, STEREO_DMX_EVS_DMX_EGY_FORGETTING_FX ); diff --git a/lib_enc/ivas_stereo_mdct_stereo_enc.c b/lib_enc/ivas_stereo_mdct_stereo_enc.c index da0cff0fe..40adc73a1 100644 --- a/lib_enc/ivas_stereo_mdct_stereo_enc.c +++ b/lib_enc/ivas_stereo_mdct_stereo_enc.c @@ -133,9 +133,13 @@ static void dft_ana_init( ) { hDft_ana->N = extract_l( Mpy_32_16_1( input_Fs, 656 ) ); + move16(); hDft_ana->NFFT = extract_l( Mpy_32_16_1( input_Fs, 1311 ) ); + move16(); hDft_ana->dft_ovl = extract_l( Mpy_32_16_1( input_Fs, 287 ) ); + move16(); hDft_ana->dft_zp = extract_l( Mpy_32_16_1( input_Fs, 185 ) ); + move16(); hDft_ana->dft_trigo_32k_fx = dft_trigo_32k_fx; @@ -143,12 +147,14 @@ static void dft_ana_init( { hDft_ana->dft_trigo_fx = dft_trigo_32k_fx; hDft_ana->dft_trigo_step = STEREO_DFT_TRIGO_SRATE_16k_STEP; + move16(); hDft_ana->win_ana_fx = win_ana_16k_fx; } ELSE IF( EQ_32( input_Fs, 32000 ) ) { hDft_ana->dft_trigo_fx = dft_trigo_32k_fx; hDft_ana->dft_trigo_step = STEREO_DFT_TRIGO_SRATE_32k_STEP; + move16(); hDft_ana->win_ana_fx = win_ana_32k_fx; } ELSE @@ -156,6 +162,7 @@ static void dft_ana_init( assert( input_Fs == 48000 ); hDft_ana->dft_trigo_fx = dft_trigo_48k_fx; hDft_ana->dft_trigo_step = STEREO_DFT_TRIGO_SRATE_48k_STEP; + move16(); hDft_ana->win_ana_fx = win_ana_48k_fx; } diff --git a/lib_enc/prot_fx_enc.h b/lib_enc/prot_fx_enc.h index a48d3bbd0..cfb2ba9d2 100644 --- a/lib_enc/prot_fx_enc.h +++ b/lib_enc/prot_fx_enc.h @@ -1096,9 +1096,10 @@ void RunTransientDetection_fx( Word16 const *i, Word16 nSamplesAvailable, struct void RunTransientDetection_ivas_fx( - const Word16 *input_fx, /* i : input signal Q: -1 */ - const int16_t length, /* i : frame length */ - TRAN_DET_HANDLE hTranDet /* i/o: transient detection handle */ + const Word16 *input_fx, /* i : input signal Q: q_input */ + const Word16 length, /* i : frame length */ + TRAN_DET_HANDLE hTranDet, /* i/o: transient detection handle */ + Word16 q_input /*i: stores q for input_fx*/ ); /** Get the average temporal flatness measure using subblock energies aligned with the TCX. diff --git a/lib_enc/transient_detection_fx.c b/lib_enc/transient_detection_fx.c index 4c9907b28..f15a3862e 100644 --- a/lib_enc/transient_detection_fx.c +++ b/lib_enc/transient_detection_fx.c @@ -540,9 +540,10 @@ void RunTransientDetection_fx( Word16 const *input, Word16 nSamplesAvailable, Tr #ifdef IVAS_FLOAT_FIXED void RunTransientDetection_ivas_fx( - const Word16 *input_fx, /* i : input signal Q: -1 */ - const Word16 length, /* i : frame length */ - TRAN_DET_HANDLE hTranDet /* i/o: transient detection handle */ + const Word16 *input_fx, /* i : input signal Q: q_input */ + const Word16 length, /* i : frame length */ + TRAN_DET_HANDLE hTranDet, /* i/o: transient detection handle */ + Word16 q_input /*i: stores q for input_fx*/ ) { @@ -560,7 +561,7 @@ void RunTransientDetection_ivas_fx( /* Update subblock energies. */ #ifdef MSAN_FIX - Scale_sig( filteredInput_fx, length, 8 ); + Scale_sig( filteredInput_fx, length, sub( 7, q_input ) ); // q7 #else Scale_sig( filteredInput_fx, L_FRAME_MAX, 8 ); #endif diff --git a/lib_enc/vad_fx.c b/lib_enc/vad_fx.c index 18a71e294..1326cc457 100644 --- a/lib_enc/vad_fx.c +++ b/lib_enc/vad_fx.c @@ -146,8 +146,11 @@ void wb_vad_init_ivas_fx( /* is set to max (-> start with hangover) */ hVAD->vad_flag_reg_H = L_deposit_l( 0 ); + move32(); hVAD->vad_flag_reg_L = L_deposit_l( 0 ); + move32(); hVAD->vad_prim_reg = L_deposit_l( 0 ); + move32(); hVAD->vad_flag_cnt_50 = 0; move16(); hVAD->vad_prim_cnt_16 = 0; @@ -1985,12 +1988,10 @@ Word16 wb_vad_ivas_fx( if ( hNoiseEst == NULL ) { hNoiseEst = st_fx->hNoiseEst; - move16(); } if ( hVAD == NULL ) { - move16(); hVAD = st_fx->hVAD; } if ( LT_16( lp_speech_fx, -100 * 256 ) ) @@ -2079,10 +2080,8 @@ Word16 wb_vad_ivas_fx( sign_thr_HE_SAD = 40; move16(); /* 2.5f Q4 */ - ; min_snr_HE_SAD = 3; move16(); /* 0.2f Q4 */ - ; } ELSE /* NB input */ { @@ -2103,10 +2102,8 @@ Word16 wb_vad_ivas_fx( move16(); /* .25 *Q4 MIN_SNR */ sign_thr_HE_SAD = 42; move16(); /* 2.65f Q4 */ - ; min_snr_HE_SAD = 1; move16(); /* 0.05f Q4 */ - ; } hangover_short = 0; @@ -2313,7 +2310,7 @@ Word16 wb_vad_ivas_fx( } } - if ( LT_32( L_snr, 2 * ( 1 << 4 ) ) ) + IF( LT_32( L_snr, 2 * ( 1 << 4 ) ) ) { nb_sig_snr = sub( nb_sig_snr, 1 ); /* nb_sig_snr--; */ } @@ -2368,7 +2365,7 @@ Word16 wb_vad_ivas_fx( tmp1 = tmp; move16(); /* ftmp1 = ftmp; */ sub( 0, 0 ); - if ( i < 7 ) + IF( i < 7 ) { #ifdef BASOP_NOGLOB tmp1 = add_o( tmp, 3277, &Overflow ); /*.4 in Q13 ftmp1 = ftmp + 0.4f; */ @@ -2410,6 +2407,7 @@ Word16 wb_vad_ivas_fx( norm_tmp = norm_l( tmp1 ); scaled_tmp = L_shl( tmp1, norm_tmp ); /*13+norm_tmp*/ L_msnr = scaled_tmp; + move32(); L_msnr_e = sub( 18, norm_tmp ); FOR( j = 1; j < stmp; j++ ) { @@ -2462,11 +2460,11 @@ Word16 wb_vad_ivas_fx( /* float saves all snrs in an snr[] vector , in fix we only save two bands */ - if ( EQ_16( i, 18 ) ) + IF( EQ_16( i, 18 ) ) { L_snr18 = L_add( L_snr, 0 ); /*Q4 */ } - if ( EQ_16( i, 19 ) ) + IF( EQ_16( i, 19 ) ) { L_snr19 = L_add( L_snr, 0 ); /* Q4 */ } @@ -2531,6 +2529,7 @@ Word16 wb_vad_ivas_fx( /* Separated SNR_SUM outlier modification */ L_snr_sum_ol = L_snr_sum; /* snr_sum_ol = snr_sum; */ + move32(); test(); test(); @@ -2590,7 +2589,6 @@ Word16 wb_vad_ivas_fx( *---------------------------------------------------------------------*/ lp_snr = sub( lp_speech_fx, lp_noise_fx ); /*Q8*/ - sub( 0, 0 ); IF( LT_16( lp_snr, hNoiseEst->sign_dyn_lp_fx ) ) { lp_snr = add( lp_snr, 1 << 8 ); /* lp_snr += 1; */ @@ -2608,16 +2606,19 @@ Word16 wb_vad_ivas_fx( L_tmp = L_mac( L_tmp, nc, (Word16) 32767 ); /* Q8+Q15+1 = Q24 */ thr1 = mac_r( L_tmp, lp_snr, nk ); /* Q8+Q15+1 - 16 --> Q8 */ + test(); IF( st_fx->element_mode > EVS_MONO && hNoiseEst->first_noise_updt_cnt < 100 ) { /* lower threshold during warmup time */ thr1 = sub( thr1, 2560 ); L_vad_thr = 0; + move32(); } IF( GT_16( lp_snr, (Word16) 20 * ( 1 << 8 ) ) ) /* if (lp_snr > 20.0f )*/ { - IF( st_fx->element_mode == EVS_MONO || hNoiseEst->first_noise_updt_cnt >= 100 ) + test(); + IF( st_fx->element_mode == EVS_MONO || GE_16( hNoiseEst->first_noise_updt_cnt, 100 ) ) { /* thr1 = thr1 + 0.3f * (lp_snr - 20.0f); */ thr1 = add( thr1, mult( 9830, sub( lp_snr, (Word16) 20 * ( 1 << 8 ) ) ) ); /* Q15*Q8+1 -16 --> Q8 */ @@ -2628,6 +2629,7 @@ Word16 wb_vad_ivas_fx( if ( EQ_16( st_fx->max_band, 16 ) && GT_16( lp_snr, 40 * 256 ) && GT_16( thr1, 6600 ) && LT_16( lp_speech_fx, 11520 ) ) { thr1 = 6600; + move16(); } } } @@ -2667,8 +2669,8 @@ Word16 wb_vad_ivas_fx( test(); /*_DIFF_FLOAT_FIX_ -> the conditions around Opt_SC_VBR_fx are invertered compared to float ### st_fx->Opt_SC_VBR!=0 vs !st_fx->Opt_SC_VBR #####*/ test(); - IF( ( snr_outlier_index <= 4 && ( st_fx->last_coder_type > UNVOICED ) && !st_fx->Opt_SC_VBR ) || - ( snr_outlier_index <= 4 && ( last_7k2_coder_type > UNVOICED ) && st_fx->Opt_SC_VBR ) ) + IF( ( LE_16( snr_outlier_index, 4 ) && ( st_fx->last_coder_type > UNVOICED ) && !st_fx->Opt_SC_VBR ) || + ( LE_16( snr_outlier_index, 4 ) && ( last_7k2_coder_type > UNVOICED ) && st_fx->Opt_SC_VBR ) ) { @@ -2696,7 +2698,7 @@ Word16 wb_vad_ivas_fx( #else /* BASOP_NOGLOB */ tmp2 = round_fx( L_shl( L_tmp2, 14 ) ); /* Q10(high word)+ 14 -16 --> Q8*/ #endif - if ( L_tmp2 > 0 ) + IF( L_tmp2 > 0 ) { thr1_ol = add( thr1_ol, tmp2 ); /* Q24 >>16 + Q8 */ } @@ -2718,6 +2720,7 @@ Word16 wb_vad_ivas_fx( flag_he1 = 1; move16(); /* he1 primary decision */ hVAD->nb_active_frames_he1 = add( hVAD->nb_active_frames_he1, 1 ); /* Counter of consecutive active speech frames */ + move16(); IF( GE_16( hVAD->nb_active_frames_he1, ACTIVE_FRAMES_FX ) ) { @@ -2729,14 +2732,16 @@ Word16 wb_vad_ivas_fx( /* inside HO period */ test(); - if ( sub( hVAD->hangover_cnt_he1, HANGOVER_LONG_HE_FX ) < 0 && hVAD->hangover_cnt_he1 != 0 ) + IF( sub( hVAD->hangover_cnt_he1, HANGOVER_LONG_HE_FX ) < 0 && hVAD->hangover_cnt_he1 != 0 ) { hVAD->hangover_cnt_he1 = add( hVAD->hangover_cnt_he1, 1 ); + move16(); } - if ( hVAD->soft_hangover > 0 ) + IF( hVAD->soft_hangover > 0 ) { hVAD->soft_hangover = sub( hVAD->soft_hangover, 1 ); + move16(); } } ELSE @@ -2768,7 +2773,6 @@ Word16 wb_vad_ivas_fx( IF( LT_16( hVAD->bcg_flux_fx, 640 ) ) { hangover_hd = add( shr( hangover_hd, 1 ), 1 ); - move16(); } /* VAD hangover for he1 */ @@ -2780,6 +2784,7 @@ Word16 wb_vad_ivas_fx( flag_he1 = 1; move16(); hVAD->soft_hangover = sub( hVAD->soft_hangover, 1 ); + move16(); } ELSE { @@ -2801,6 +2806,7 @@ Word16 wb_vad_ivas_fx( flag_he1 = 1; move16(); hVAD->hangover_cnt_he1 = add( hVAD->hangover_cnt_he1, 1 ); + move16(); } @@ -2816,11 +2822,13 @@ Word16 wb_vad_ivas_fx( { /*st->bcg_flux = 0.9f * st->bcg_flux + (1-0.9f)*(st->bcg_flux+50);*/ hVAD->bcg_flux_fx = mac_r( L_mult( hVAD->bcg_flux_fx, 29491 ), add( hVAD->bcg_flux_fx, 800 ), 3277 ); /*Q4 */ + move16(); } ELSE { /*st->bcg_flux = 0.9f * st->bcg_flux + (1-0.9f)*snr_sumt*/ hVAD->bcg_flux_fx = mac_r( L_mult( hVAD->bcg_flux_fx, 29491 ), snr_sumt, 3277 ); /*Q4 */ + move16(); } } ELSE @@ -2829,11 +2837,13 @@ Word16 wb_vad_ivas_fx( { /*st->bcg_flux = 0.99f * st->bcg_flux + (1-0.99f)*(st->bcg_flux+10);*/ hVAD->bcg_flux_fx = mac_r( L_mult( hVAD->bcg_flux_fx, 32440 ), add( hVAD->bcg_flux_fx, 160 ), 328 ); /*Q4 */ + move16(); } ELSE { /*st->bcg_flux = 0.99f * st->bcg_flux + (1-0.99f)*snr_sumt;*/ hVAD->bcg_flux_fx = mac_r( L_mult( hVAD->bcg_flux_fx, 32440 ), snr_sumt, 328 ); /*Q4 */ + move16(); } } } @@ -2845,11 +2855,13 @@ Word16 wb_vad_ivas_fx( { /*st->bcg_flux = 0.95f * st->bcg_flux + (1-0.95f)*(st->bcg_flux-30);*/ hVAD->bcg_flux_fx = mac_r( L_mult( hVAD->bcg_flux_fx, 31131 ), sub( hVAD->bcg_flux_fx, 480 ), 1638 ); /*Q4 */ + move16(); } ELSE { /*st->bcg_flux = 0.95f * st->bcg_flux + (1-0.95f)*snr_sumt;*/ hVAD->bcg_flux_fx = mac_r( L_mult( hVAD->bcg_flux_fx, 31131 ), snr_sumt, 1638 ); /*Q4 */ + move16(); } } ELSE @@ -2858,16 +2870,19 @@ Word16 wb_vad_ivas_fx( { /*st->bcg_flux = 0.9992f * st->bcg_flux + (1-0.9992f)*(st->bcg_flux-10);*/ hVAD->bcg_flux_fx = mac_r( L_mult( hVAD->bcg_flux_fx, 32742 ), sub( hVAD->bcg_flux_fx, 160 ), 26 ); /*Q4 */ + move16(); } ELSE { /*st->bcg_flux = 0.9992f * st->bcg_flux + (1-0.9992f)*snr_sumt;*/ hVAD->bcg_flux_fx = mac_r( L_mult( hVAD->bcg_flux_fx, 32742 ), snr_sumt, 26 ); /*Q4 */ + move16(); } } } hVAD->bcg_flux_init = s_max( hVAD->bcg_flux_init, 0 ); + move16(); } flag = 0; @@ -2885,6 +2900,7 @@ Word16 wb_vad_ivas_fx( move16(); hVAD->nb_active_frames = add( hVAD->nb_active_frames, 1 ); /* Counter of consecutive active speech frames */ + move16(); IF( GE_16( hVAD->nb_active_frames, ACTIVE_FRAMES_FX ) ) { @@ -2896,9 +2912,10 @@ Word16 wb_vad_ivas_fx( /* inside HO period */ test(); - if ( LT_16( hVAD->hangover_cnt, HANGOVER_LONG_FX ) && hVAD->hangover_cnt != 0 ) + IF( LT_16( hVAD->hangover_cnt, HANGOVER_LONG_FX ) && hVAD->hangover_cnt != 0 ) { hVAD->hangover_cnt = add( hVAD->hangover_cnt, 1 ); + move16(); } } ELSE @@ -2918,14 +2935,16 @@ Word16 wb_vad_ivas_fx( { test(); test(); - if ( EQ_16( st_fx->element_mode, EVS_MONO ) && ( LT_16( lp_snr, th_clean ) ) && ( st_fx->Opt_SC_VBR != 0 ) && ( GE_16( hVAD->hangover_cnt, 2 ) ) ) + test(); + if ( ( st_fx->element_mode == EVS_MONO ) && ( LT_16( lp_snr, th_clean ) ) && ( st_fx->Opt_SC_VBR != 0 ) && ( GE_16( hVAD->hangover_cnt, 2 ) ) ) { *noisy_speech_HO = 1; move16(); } test(); test(); - if ( EQ_16( st_fx->element_mode, EVS_MONO ) && ( GE_16( lp_snr, th_clean ) ) && ( st_fx->Opt_SC_VBR != 0 ) && ( GE_16( hVAD->hangover_cnt, 2 ) ) ) + test(); + if ( ( st_fx->element_mode == EVS_MONO ) && ( GE_16( lp_snr, th_clean ) ) && ( st_fx->Opt_SC_VBR != 0 ) && ( GE_16( hVAD->hangover_cnt, 2 ) ) ) { *clean_speech_HO = 1; move16(); @@ -2972,6 +2991,7 @@ Word16 wb_vad_ivas_fx( IF( GT_16( snr_sum, thr1 ) ) /* Speech present, possibly in hangover */ { hVAD->nb_active_frames = add( hVAD->nb_active_frames, 1 ); /* Counter of consecutive active speech frames */ + move16(); IF( GE_16( hVAD->nb_active_frames, ACTIVE_FRAMES_FX ) ) { hVAD->nb_active_frames = ACTIVE_FRAMES_FX; @@ -2995,6 +3015,7 @@ Word16 wb_vad_ivas_fx( IF( LT_16( hVAD->hangover_cnt, HANGOVER_LONG_NB_FX ) ) { hVAD->hangover_cnt = add( hVAD->hangover_cnt, 1 ); + move16(); IF( LT_16( lp_snr, 4864 ) ) /*19.0f Q8*/ /* very low SNR */ @@ -3018,7 +3039,7 @@ Word16 wb_vad_ivas_fx( tmp = 282; move16(); /* 1.10f; */ } - if ( LT_16( lp_snr, th_clean ) ) + IF( LT_16( lp_snr, th_clean ) ) { thr2 = sub( thr1_nb_mod, tmp ); /*thr2 = thr1 - [ 1.10 || 1.3 ];*/ } @@ -3041,11 +3062,11 @@ Word16 wb_vad_ivas_fx( st_fx->localVAD = 0; move16(); - if ( EQ_16( st_fx->element_mode, EVS_MONO ) ) + if ( st_fx->element_mode == EVS_MONO ) { *NB_speech_HO = 1; + move16(); } - move16(); } thr1 = thr1_nb_mod; move16(); /* needed for st_fx->vadnoise_fx update below */ @@ -3072,7 +3093,7 @@ Word16 wb_vad_ivas_fx( } } - if ( st_fx->hSC_VBR != NULL ) + IF( st_fx->hSC_VBR != NULL ) { /* SC-VBR */ st_fx->hSC_VBR->vadsnr_fx = snr_sum; @@ -3083,17 +3104,21 @@ Word16 wb_vad_ivas_fx( /* Updates */ hVAD->prim_act_quick_fx = mult_r( 26214, hVAD->prim_act_quick_fx ); /*Q15 */ + move16(); if ( st_fx->localVAD != 0 ) { hVAD->prim_act_quick_fx = add( 6554, hVAD->prim_act_quick_fx ); /*Q15 */ + move16(); } hVAD->prim_act_slow_fx = mult_r( 32440, hVAD->prim_act_slow_fx ); /*Q15 */ + move16(); if ( st_fx->localVAD != 0 ) { hVAD->prim_act_slow_fx = add( 328, hVAD->prim_act_slow_fx ); /*Q15 */ + move16(); } tmp = hVAD->prim_act_slow_fx; @@ -3105,18 +3130,22 @@ Word16 wb_vad_ivas_fx( } /*st->prim_act = 0.1f * tmp + (1.0f-0.1f)* st->prim_act;*/ hVAD->prim_act_fx = mac_r( L_mult( 3277, tmp ), 29491, hVAD->prim_act_fx ); - + move16(); hVAD->prim_act_quick_he_fx = mult_r( 26214, hVAD->prim_act_quick_he_fx ); /*Q15 */ + move16(); if ( *localVAD_HE_SAD != 0 ) { hVAD->prim_act_quick_he_fx = add( 6554, hVAD->prim_act_quick_he_fx ); /*Q15 */ + move16(); } hVAD->prim_act_slow_he_fx = mult_r( 32440, hVAD->prim_act_slow_he_fx ); /*Q15 */ + move16(); if ( *localVAD_HE_SAD != 0 ) { hVAD->prim_act_slow_he_fx = add( 328, hVAD->prim_act_slow_he_fx ); /*Q15 */ + move16(); } tmp = hVAD->prim_act_slow_he_fx; @@ -3127,42 +3156,50 @@ Word16 wb_vad_ivas_fx( move16(); } hVAD->prim_act_he_fx = mac_r( L_mult( 3277, tmp ), 29491, hVAD->prim_act_he_fx ); - + move16(); if ( L_and( hVAD->vad_flag_reg_H, (Word32) 0x40000L ) != 0 ) /* 0x4000L = 0x01L << 18 */ { hVAD->vad_flag_cnt_50 = sub( hVAD->vad_flag_cnt_50, 1 ); + move16(); } hVAD->vad_flag_reg_H = L_shl( L_and( hVAD->vad_flag_reg_H, (Word32) 0x3fffffffL ), 1 ); - + move32(); if ( L_and( hVAD->vad_flag_reg_L, (Word32) 0x40000000L ) != 0 ) { hVAD->vad_flag_reg_H = L_or( hVAD->vad_flag_reg_H, 0x01L ); + move32(); } hVAD->vad_flag_reg_L = L_shl( L_and( hVAD->vad_flag_reg_L, (Word32) 0x3fffffffL ), 1 ); - + move32(); IF( flag != 0 ) /* should not include the extra DTX hangover */ { hVAD->vad_flag_reg_L = L_or( hVAD->vad_flag_reg_L, 0x01L ); + move32(); hVAD->vad_flag_cnt_50 = add( hVAD->vad_flag_cnt_50, 1 ); + move16(); } if ( L_and( hVAD->vad_prim_reg, (Word32) 0x8000L ) != 0 ) /* 0x8000L = 1L << 15 */ { hVAD->vad_prim_cnt_16 = sub( hVAD->vad_prim_cnt_16, 1 ); + move16(); } hVAD->vad_prim_reg = L_shl( L_and( hVAD->vad_prim_reg, (Word32) 0x3fffffffL ), 1 ); + move32(); IF( st_fx->localVAD != 0 ) { hVAD->vad_prim_reg = L_or( hVAD->vad_prim_reg, 0x01L ); + move32(); hVAD->vad_prim_cnt_16 = add( hVAD->vad_prim_cnt_16, 1 ); + move16(); } return flag; -- GitLab From 5c1e7d54e55de0a64a6d89839b29ebf17114debf Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Fri, 15 Nov 2024 08:42:49 +0530 Subject: [PATCH 124/128] Fix for 3GPP issue 1041: Decoder crash for Stereo at 32kbps JBM operation in stereo_dft_res_ecu_burst_att_fx() link #1041 --- lib_dec/ivas_stereo_dft_plc_fx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_dec/ivas_stereo_dft_plc_fx.c b/lib_dec/ivas_stereo_dft_plc_fx.c index a8bb5a6e6..875f50ac5 100644 --- a/lib_dec/ivas_stereo_dft_plc_fx.c +++ b/lib_dec/ivas_stereo_dft_plc_fx.c @@ -760,7 +760,7 @@ void stereo_dft_res_ecu_burst_att_fx( } ELSE { - fac = L_sub( MAX_32, L_deposit_h( BASOP_Util_Divide3232_Scale( sub( hStereoDft->time_offs, L_ana ), add( hStereoDft->time_offs, L_ana ), &q_fac ) ) ); /* Q0 */ + fac = L_sub( MAX_32, L_deposit_h( BASOP_Util_Divide3232_Scale( L_sub( hStereoDft->time_offs, L_ana ), L_add( hStereoDft->time_offs, L_ana ), &q_fac ) ) ); /* Q0 */ } v_multc_fixed( pDFT_RES, fac, pDFT_RES, shl( L_res, 1 ) ); -- GitLab From d3befffa2fd89f2b0ca1e5948d1abcdda8890da7 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Fri, 15 Nov 2024 09:51:45 +0530 Subject: [PATCH 125/128] EVS BE fix --- lib_com/tcx_utils_fx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_com/tcx_utils_fx.c b/lib_com/tcx_utils_fx.c index dab13dff4..7f961f74c 100644 --- a/lib_com/tcx_utils_fx.c +++ b/lib_com/tcx_utils_fx.c @@ -264,7 +264,7 @@ void WindowSignal( * Windowing * *-----------------------------------------------------------*/ - tcx_windowing_analysis( in - add( shr( l, 1 ), offset ), *L_frame, l, left_win, r, right_win, out ); + tcx_windowing_analysis( in - sub( shr( l, 1 ), offset ), *L_frame, l, left_win, r, right_win, out ); test(); test(); IF( EQ_16( left_overlap_mode, FULL_OVERLAP ) && truncate_aldo ) -- GitLab From bc5a73b650325744483f2d3e02edf71aef099c18 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Sat, 16 Nov 2024 15:00:38 +0530 Subject: [PATCH 126/128] Fix for 3GPP issue 968: Decoder crash for OMASA ISM4_1TC / ISM4_2TC with bitrate switching and FER in enhancer_ivas_fx2() Link #968, #989, #990 --- lib_com/enhancer_fx.c | 52 +++++++++++++++---------------------------- 1 file changed, 18 insertions(+), 34 deletions(-) diff --git a/lib_com/enhancer_fx.c b/lib_com/enhancer_fx.c index 8d8bb2ef3..88bc70497 100644 --- a/lib_com/enhancer_fx.c +++ b/lib_com/enhancer_fx.c @@ -600,9 +600,11 @@ void enhancer_ivas_fx2( Word16 tmp, fac, *pt_exc2; Word16 i; Word32 L_tmp; + Word32 L_tmp1, L_tmp2; Word16 gain_code_hi; Word16 pit_sharp, tmp16; Word16 excp[L_SUBFR], sc; + Word64 w_temp; pit_sharp = gain_pit; @@ -751,50 +753,32 @@ void enhancer_ivas_fx2( * filter with coefs [-tmp 1.0 -tmp] where tmp=0...0.25. * This is applied to code and add_fxed to exc2 *-----------------------------------------------------------------*/ + + L_tmp1 = L_deposit_h( gain_code_hi ); // Q = 16 + Q_exc, gain_code + L_tmp2 = L_mult( tmp, gain_code_hi ); // Q = 16 + Q_exc, gain_code * temp + /* pt_exc2[0] += code[0] - tmp * code[1] */ - L_tmp = L_deposit_h( code[0] ); /* if Enc :Q9 * Q15 -> Q25 */ - L_tmp = L_msu( L_tmp, code[1], tmp ); /* Q12 * Q15 -> Q28 */ -#ifdef BASOP_NOGLOB - L_tmp = L_shl_sat( L_mult( gain_code_hi, extract_h( L_tmp ) ), sc ); - pt_exc2[0] = msu_r_sat( L_tmp, -32768, pt_exc2[0] ); + w_temp = W_msu_32_16( W_mult_32_16( L_tmp1, code[0] ), L_tmp2, code[1] ); // Q = 32 + Q_exc - sc (16+Q_exc+15-sc+1) + w_temp = W_shl( w_temp, sc ); // Q = 32 + Q_exc + pt_exc2[0] = W_round32_s( W_msu_32_16( w_temp, MIN_32, pt_exc2[0] ) ); // Q = Q_exc move16(); -#else - L_tmp = L_shl( L_mult( gain_code_hi, extract_h( L_tmp ) ), sc ); - pt_exc2[0] = msu_r( L_tmp, -32768, pt_exc2[0] ); - move16(); -#endif - move16(); /* in Q_exc */ FOR( i = 1; i < L_SUBFR - 1; i++ ) { - /* pt_exc2[i] += code[i] - tmp * code[i-1] - tmp * code[i+1] */ - L_tmp = L_msu( -32768, code[i], -32768 ); - L_tmp = L_msu( L_tmp, code[i + 1], tmp ); -#ifdef BASOP_NOGLOB - tmp16 = msu_r_sat( L_tmp, code[i - 1], tmp ); - L_tmp = L_shl_sat( L_mult( gain_code_hi, tmp16 ), sc ); - pt_exc2[i] = msu_r_sat( L_tmp, -32768, pt_exc2[i] ); + /* pt_exc2[i] += (code[i] - tmp * code[i-1] - tmp * code[i+1]) * gain_code */ + w_temp = W_msu_32_16( W_mult_32_16( L_tmp1, code[i] ), L_tmp2, code[i - 1] ); // Q = 32 + Q_exc - sc (16+Q_exc+15-sc+1) + w_temp = W_msu_32_16( w_temp, L_tmp2, code[i + 1] ); // Q = 32 + Q_exc - sc (16+Q_exc+15-sc+1) + w_temp = W_shl( w_temp, sc ); // Q = 32 + Q_exc + pt_exc2[i] = W_round32_s( W_msu_32_16( w_temp, MIN_32, pt_exc2[i] ) ); // Q = Q_exc move16(); -#else - tmp16 = msu_r( L_tmp, code[i - 1], tmp ); - L_tmp = L_shl( L_mult( gain_code_hi, tmp16 ), sc ); - pt_exc2[i] = msu_r( L_tmp, -32768, pt_exc2[i] ); -#endif - move16(); /* in Q_exc */ } /* pt_exc2[L_SUBFR-1] += code[L_SUBFR-1] - tmp * code[L_SUBFR-2] */ - L_tmp = L_deposit_h( code[L_SUBFR - 1] ); /*Q28 */ - L_tmp = L_msu( L_tmp, code[L_SUBFR - 2], tmp ); /*Q28 */ - L_tmp = L_shl( L_mult( gain_code_hi, extract_h( L_tmp ) ), sc ); -#ifdef BASOP_NOGLOB - pt_exc2[L_SUBFR - 1] = msu_r_sat( L_tmp, -32768, pt_exc2[L_SUBFR - 1] ); + w_temp = W_msu_32_16( W_mult_32_16( L_tmp1, code[L_SUBFR - 1] ), L_tmp2, code[L_SUBFR - 2] ); // Q = 32 + Q_exc - sc (16+Q_exc+15-sc+1) + w_temp = W_shl( w_temp, sc ); // Q = 32 + Q_exc + pt_exc2[L_SUBFR - 1] = W_round32_s( W_msu_32_16( w_temp, MIN_32, pt_exc2[L_SUBFR - 1] ) ); // Q = Q_exc move16(); -#else - pt_exc2[L_SUBFR - 1] = msu_r( L_tmp, -32768, pt_exc2[L_SUBFR - 1] ); - move16(); -#endif - move16(); /* in Q_exc */ + test(); test(); IF( Opt_AMR_WB && ( EQ_32( core_brate, ACELP_8k85 ) || EQ_32( core_brate, ACELP_6k60 ) ) ) -- GitLab From 1b983b413b344febfc4211493401775194cb21b7 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Mon, 18 Nov 2024 13:57:11 +0530 Subject: [PATCH 127/128] Encoder SCE/CPE cleanup, SBA/OMASA LTV crash fixes --- lib_com/int_lsp.c | 1 + lib_com/ivas_prot.h | 93 ++-- lib_com/ivas_prot_fx.h | 28 +- lib_com/ivas_stat_com.h | 4 +- lib_com/prot.h | 13 +- lib_com/prot_fx.h | 25 + lib_com/rom_com.c | 51 ++ lib_com/stat_com.h | 8 +- lib_dec/acelp_core_dec_ivas_fx.c | 10 +- lib_dec/cng_dec_fx.c | 741 +++++++++++++++++++++++++++-- lib_dec/jbm_pcmdsp_apa.c | 3 + lib_dec/lsf_dec_fx.c | 263 ++++++++++ lib_enc/acelp_core_enc.c | 29 +- lib_enc/analy_lp_fx.c | 4 +- lib_enc/cod4t64.c | 6 + lib_enc/dtx.c | 99 ++-- lib_enc/enc_acelp.c | 10 + lib_enc/enc_acelpx.c | 2 + lib_enc/gs_enc.c | 6 +- lib_enc/inov_enc.c | 2 + lib_enc/ivas_core_pre_proc_front.c | 679 +++++++------------------- lib_enc/ivas_cpe_enc.c | 113 +++-- lib_enc/ivas_front_vad.c | 7 +- lib_enc/ivas_ism_enc.c | 99 ++-- lib_enc/ivas_sce_enc.c | 61 ++- lib_enc/ivas_stat_enc.h | 31 +- lib_enc/ivas_stereo_classifier.c | 52 +- lib_enc/ivas_stereo_dft_enc.c | 4 +- lib_enc/ivas_stereo_dft_enc_itd.c | 124 ++++- lib_enc/ivas_stereo_dft_td_itd.c | 2 +- lib_enc/ivas_stereo_ica_enc.c | 36 +- lib_enc/ivas_stereo_td_analysis.c | 6 +- lib_enc/lsf_enc_fx.c | 4 +- lib_enc/nois_est_fx.c | 2 +- lib_enc/speech_music_classif.c | 11 +- lib_enc/speech_music_classif_fx.c | 19 +- lib_enc/stat_enc.h | 124 ++--- lib_enc/swb_tbe_enc_fx.c | 2 +- 38 files changed, 1815 insertions(+), 959 deletions(-) diff --git a/lib_com/int_lsp.c b/lib_com/int_lsp.c index 0adb332fa..75d76eb94 100644 --- a/lib_com/int_lsp.c +++ b/lib_com/int_lsp.c @@ -344,6 +344,7 @@ void int_lsp4_ivas_fx( } ELSE IF( EQ_16( relax_prev_lsf_interp, -2 ) ) { + // This condition not present in int_lsp4_fx pt_int_coeffs = interpol_frac2_mid_fx; /*Q15*/ } ELSE diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index 4296a51fd..2409d91bd 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -227,51 +227,52 @@ ivas_error pre_proc_front_ivas( ); ivas_error pre_proc_front_ivas_fx( - SCE_ENC_HANDLE hSCE, /* i/o: SCE encoder structure */ - CPE_ENC_HANDLE hCPE, /* i/o: CPE encoder structure */ - const int32_t element_brate, /* i : SCE/CPE element bitrate */ - const int16_t nb_bits_metadata, /* i : number of metadata bits */ - const int16_t input_frame, /* i : frame length */ - const int16_t n, /* i : channel number */ - Word16 old_inp_12k8_fx[], /* o : buffer of old input signal */ - float old_inp_12k8[], /* o : buffer of old input signal */ - float old_inp_16k[], /* o : buffer of old input signal @16kHz */ - float *ener, /* o : residual energy from Levinson-Durbin */ - float *relE, /* o : frame relative energy */ - float A[NB_SUBFR16k * ( M + 1 )], /* o : A(z) unquantized for the 4 subframes */ - float Aw[NB_SUBFR16k * ( M + 1 )], /* o : weighted A(z) unquantized for subframes */ - float epsP[M + 1], /* o : LP prediction errors */ - float lsp_new[M], /* o : LSPs at the end of the frame */ - float lsp_mid[M], /* o : LSPs in the middle of the frame */ - int16_t *vad_hover_flag, /* o : VAD hangover flag */ - int16_t *attack_flag, /* o : flag signaling attack */ - float realBuffer[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i/o: real buffer */ - float imagBuffer[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i/o: imag buffer */ - float old_wsp[], /* o : weighted input signal buffer */ - float pitch_fr[NB_SUBFR], /* o : fractional pitch values */ - float voicing_fr[NB_SUBFR], /* o : fractional pitch gains */ - int16_t *loc_harm, /* o : harmonicity flag */ - float *cor_map_sum, /* o : speech/music clasif. parameter */ - int16_t *vad_flag_dtx, /* o : HE-SAD flag with additional DTX HO */ - float enerBuffer[CLDFB_NO_CHANNELS_MAX], /* o : energy buffer */ - float fft_buff[2 * L_FFT], /* o : FFT buffer */ - Word16 fft_buff_fx[2 * L_FFT], /* o : FFT buffer */ - const float tdm_A_PCh[M + 1], /* i : unq. LP coeff. of primary channel */ - const float tdm_lsp_new_PCh[M], /* i : unq. LSPs of primary channel */ - const float currFlatness, /* i : flatness parameter */ - const int16_t tdm_ratio_idx, /* i : Current Ratio_L index */ - float fr_bands_LR[][2 * NB_BANDS], /* i : energy in frequency bands */ - const float Etot_LR[], /* i : total energy Left & Right channel */ - float lf_E_LR[][2 * VOIC_BINS], /* i : per bin spectrum energy in lf, LR channels */ - const int16_t localVAD_HE_SAD_LR[], /* i : HE-SAD flag without hangover, LR channels */ - float band_energies_LR[2 * NB_BANDS], /* o : energy in critical bands without minimum noise floor E_MIN */ - const int16_t flag_16k_smc, /* i : flag to indicate if the OL SMC is run at 16 kHz */ - const int16_t front_vad_flag, /* i : front-VAD flag to overwrite VAD decision */ - const int16_t force_front_vad, /* i : flag to force VAD decision */ - const int16_t front_vad_dtx_flag, /* i : front-VAD DTX flag to overwrite VAD decision*/ - const IVAS_FORMAT ivas_format, /* i : IVAS format */ - const int16_t MCT_flag, /* i : hMCT handle allocated (1) or not (0) */ - const int32_t ivas_total_brate /* i : IVAS total bitrate */ + SCE_ENC_HANDLE hSCE, /* i/o: SCE encoder structure */ + CPE_ENC_HANDLE hCPE, /* i/o: CPE encoder structure */ + const Word32 element_brate, /* i : SCE/CPE element bitrate */ + const Word16 nb_bits_metadata, /* i : number of metadata bits */ + const Word16 input_frame, /* i : frame length */ + const Word16 n, /* i : channel number */ + Word16 old_inp_12k8_fx[], /* o : (Q-1) buffer of old input signal */ + float old_inp_12k8[], /* o : buffer of old input signal */ + float old_inp_16k[], /* o : buffer of old input signal @16kHz */ + float *ener, /* o : residual energy from Levinson-Durbin */ + Word16 *relE_fx, /* o : frame relative energy Q8 */ + Word16 A_fx[NB_SUBFR16k * ( M + 1 )], /* o : A(z) unquantized for the 4 subframes */ + Word16 Aw_fx[NB_SUBFR16k * ( M + 1 )], /* o : weighted A(z) unquantized for subframes */ + float epsP[M + 1], /* o : LP prediction errors */ + Word16 lsp_new_fx[M], /* o : LSPs at the end of the frame Q15 */ + Word16 lsp_mid_fx[M], /* o : LSPs in the middle of the frame Q15 */ + Word16 *vad_hover_flag, /* o : VAD hangover flag */ + Word16 *attack_flag, /* o : flag signaling attack */ + Word32 realBuffer_fx[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i/o: real buffer Q(q_re_im_buf) */ + Word32 imagBuffer_fx[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i/o: imag buffer Q(q_re_im_buf) */ + Word16 *q_re_im_buf, /* i/o: Q-factor of real and imag buffer */ + float old_wsp[], /* o : weighted input signal buffer */ + Word16 pitch_fr_fx[NB_SUBFR], /* o : fractional pitch values Q6 */ + Word16 voicing_fr_fx[NB_SUBFR], /* o : fractional pitch gains Q15 */ + Word16 *loc_harm, /* o : harmonicity flag */ + Word16 *cor_map_sum_fx, /* o : speech/music clasif. parameter Q8 */ + Word16 *vad_flag_dtx, /* o : HE-SAD flag with additional DTX HO */ + float enerBuffer[CLDFB_NO_CHANNELS_MAX], /* o : energy buffer */ + float fft_buff[2 * L_FFT], /* o : FFT buffer */ + Word16 fft_buff_fx[2 * L_FFT], /* o : FFT buffer */ + const Word16 tdm_A_PCh_fx[M + 1], /* i : unq. LP coeff. of primary channel Q12 */ + const Word16 tdm_lsp_new_PCh_fx[M], /* i : unq. LSPs of primary channel Q15 */ + const Word16 currFlatness_fx, /* i : flatness parameter Q7 */ + const Word16 tdm_ratio_idx, /* i : Current Ratio_L index */ + float fr_bands_LR[][2 * NB_BANDS], /* i : energy in frequency bands */ + const Word16 Etot_LR_fx[], /* i : total energy Left & Right channel Q8*/ + float lf_E_LR[][2 * VOIC_BINS], /* i : per bin spectrum energy in lf, LR channels */ + const Word16 localVAD_HE_SAD_LR[], /* i : HE-SAD flag without hangover, LR channels */ + float band_energies_LR[2 * NB_BANDS], /* o : energy in critical bands without minimum noise floor E_MIN */ + const Word16 flag_16k_smc, /* i : flag to indicate if the OL SMC is run at 16 kHz */ + const Word16 front_vad_flag, /* i : front-VAD flag to overwrite VAD decision */ + const Word16 force_front_vad, /* i : flag to force VAD decision */ + const Word16 front_vad_dtx_flag, /* i : front-VAD DTX flag to overwrite VAD decision*/ + const IVAS_FORMAT ivas_format, /* i : IVAS format */ + const Word16 MCT_flag, /* i : hMCT handle allocated (1) or not (0) */ + const Word32 ivas_total_brate /* i : IVAS total bitrate - for setting the DTX */ ); ivas_error pre_proc_ivas( Encoder_State *st, /* i/o: encoder state structure */ @@ -2276,7 +2277,6 @@ void td_stereo_param_updt( const int16_t flag_ACELP16k, /* i : ACELP@16kHz flag */ const int16_t tdm_use_IAWB_Ave_lpc /* i : flag to indicate the usage of mean inactive LP coefficients */ ); -#endif void gsc_enc( Encoder_State *st, /* i/o: State structure */ @@ -2290,7 +2290,6 @@ void gsc_enc( float *tmp_noise /* o : long-term noise energy */ ); -#ifndef IVAS_FLOAT_FIXED void tdm_low_rate_enc( Encoder_State *st, /* i/o: State structure */ const float Aq[], /* i : 12k8 Lp coefficient */ diff --git a/lib_com/ivas_prot_fx.h b/lib_com/ivas_prot_fx.h index e0c66f460..d549056b5 100644 --- a/lib_com/ivas_prot_fx.h +++ b/lib_com/ivas_prot_fx.h @@ -3110,16 +3110,15 @@ void stereo_classifier_features_ivas_fx( const Word16 idchan, /* i : channel ID */ const Word16 element_mode, /* i : element mode */ const Word16 vad_flag, /* i : VAD flag */ - Word32 lsf_new_fx[], /* i : LSFs at the end of the frame */ + Word16 lsf_new_fx[], /* i : LSFs at the end of the frame Q1*1.28 */ Word32 epsP_fx[], /* i : LP analysis residual energies for each iteration*/ - Word16 pitch[], /*q0 i : open-loop pitch values for quantiz. */ - Word16 voicing_fx[], /* i : OL maximum normalized correlation */ + Word16 pitch[], /* i : open-loop pitch values for quantiz. Q0 */ + Word16 voicing_fx[], /* i : OL maximum normalized correlation Q15 */ Word32 cor_map_sum_fx, /* i : speech/music clasif. parameter */ Word32 non_staX_fx, /* i : unbound non-stationarity for sp/mu clas. */ - Word32 sp_div_fx, /* i : spectral diversity feature */ + Word16 sp_div_fx, /* i : spectral diversity feature */ const Word16 clas, /* i : signal class */ Word16 epsP_e, /*exponent for epsP_fx */ - Word16 voicing_e, /*exponent for voicing_fx */ Word16 cor_map_sum_e, /*exponent for cor_map_sum_fx */ Word16 non_staX_e, /*exponent for non_staX_fx */ Word16 sp_div_e /*exponent for sp_div_fx */ @@ -3974,15 +3973,14 @@ Word16 ivas_smc_gmm_fx( STEREO_CLASSIF_HANDLE hStereoClassif, /* i/o: stereo classifier structure */ const Word16 localVAD_HE_SAD, /* i : HE-SAD flag without hangover */ const Word16 Etot_fx, /* i : total frame energy */ - Word16 lsp_new_fx[M], /* i : LSPs in current frame TODO:For now removing 'const' to avoid warning */ - Word16 cor_map_sum_fx, /* i : correlation map sum (from multi-harmonic anal.) */ - Word32 epsP_fx[M + 1], /* i : LP prediciton error TODO:For now removing 'const' to avoid warning */ - Word32 PS_fx[], /* i : energy spectrum TODO:For now removing 'const' to avoid warning */ - const Word16 non_sta_fx, /* i : unbound non-stationarity */ - const Word16 relE_fx, /* i : relative frame energy */ + const Word16 lsp_new_fx[M], /* i : LSPs in current frame Q15 */ + const Word16 cor_map_sum_fx, /* i : correlation map sum (from multi-harmonic anal.) Q8 */ + const Word32 epsP_fx[M + 1], /* i : LP prediciton error */ + const Word32 PS_fx[], /* i : energy spectrum */ + const Word16 non_sta_fx, /* i : unbound non-stationarity Q8 */ + const Word16 relE_fx, /* i : relative frame energy Q8 */ Word16 *high_lpn_flag, /* i/o: sp/mus LPN flag */ - const Word16 flag_spitch /* i : flag to indicate very short stable pitch */ - , + const Word16 flag_spitch, /* i : flag to indicate very short stable pitch */ Word16 Qfact_PS, Word16 Q_esp, Word16 Qfact_PS_past ); @@ -4407,8 +4405,8 @@ Word16 tdm_lp_comparison_fx( const Word16 *A_PCh_fx, /* i : primary channel LP coefficients Q12*/ const Word16 *A_SCh_fx, /* i : secondary channel LP coeff. Q12*/ const Word16 m, /* i : filter length */ - const Word32 *isp_PCh_fx, /* i : primary channel LSPs Q31 */ - const Word32 *isp_SCh_fx, /* i : secondary channel LSPs Q31 */ + const Word16 *isp_PCh_fx, /* i : primary channel LSPs Q15 */ + const Word16 *isp_SCh_fx, /* i : secondary channel LSPs Q15 */ const Word16 L_frame, /* i : frame length */ const Word32 element_brate_wo_meta, /* i : element bitrate without metadata*/ Word16 Q_speech ); diff --git a/lib_com/ivas_stat_com.h b/lib_com/ivas_stat_com.h index b893c1d84..a050f7675 100644 --- a/lib_com/ivas_stat_com.h +++ b/lib_com/ivas_stat_com.h @@ -868,9 +868,7 @@ typedef struct ivas_fb_mixer_state_structure /* store sin part in const table (no need to store 1s and 0s, no need to do windowing for 1's and 0's as well) */ Word16 cross_fade_start_offset; Word16 cross_fade_end_offset; - const float *pFilterbank_cross_fade; Word16 ana_window_offset; - const float *pAna_window; Word16 prior_input_length; Word16 windowed_fr_offset; @@ -881,6 +879,8 @@ typedef struct ivas_fb_mixer_state_structure const Word16 *pAna_window_fx; #else float cldfb_cross_fade[CLDFB_NO_COL_MAX]; + const float *pFilterbank_cross_fade; + const float *pAna_window; #endif // IVAS_FLOAT_FIXED Word16 cldfb_cross_fade_start; Word16 cldfb_cross_fade_end; diff --git a/lib_com/prot.h b/lib_com/prot.h index 4f795250c..71ede8fe3 100644 --- a/lib_com/prot.h +++ b/lib_com/prot.h @@ -3164,6 +3164,7 @@ void find_targets( float *h1 /* o : impulse response of weighted synthesis filter */ ); +#ifndef IVAS_FLOAT_FIXED void inov_encode( Encoder_State *st, /* i/o: encoder state structure */ const int32_t core_brate, /* i : core bitrate */ @@ -3188,6 +3189,7 @@ void inov_encode( int16_t *unbits, /* o : number of unused bits for EVS_PI */ const int16_t L_subfr /* i : subframe length */ ); +#endif void acelp_1t64( BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ @@ -3206,6 +3208,7 @@ void acelp_2t32( float y[] /* o : filtered fixed codebook excitation */ ); +#ifndef IVAS_FLOAT_FIXED int16_t acelp_4t64( BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ float dn[], /* i : corr. between target and h[]. */ @@ -3219,6 +3222,7 @@ int16_t acelp_4t64( const int16_t cmpl_flag, /* i : coomplexity reduction flag */ const int16_t Opt_AMR_WB /* i : flag indicating AMR-WB IO mode */ ); +#endif /*! r: return (2*N)+1 bits */ int16_t quant_2p_2N1( @@ -3406,7 +3410,7 @@ void lp_gain_updt( float *lp_gainc, /* i/o: LP-filtered code gain (FEC) */ const int16_t L_frame /* i : length of the frame */ ); - +#ifndef IVAS_FLOAT_FIXED void enc_pit_exc( Encoder_State *st, /* i/o: state structure */ const float *speech, /* i : Input speech */ @@ -3424,11 +3428,13 @@ void enc_pit_exc( const int16_t tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag */ const float tdm_Pri_pitch_buf[] /* i : primary channel pitch buffer */ ); +#endif void GSC_enc_init( GSC_ENC_HANDLE hGSCEnc /* i/o: GSC data handle */ ); +#ifndef IVAS_FLOAT_FIXED void encod_audio( Encoder_State *st, /* i/o: state structure */ const float speech[], /* i : input speech */ @@ -3446,6 +3452,7 @@ void encod_audio( const int16_t tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag */ const float tdm_Pri_pitch_buf[] /* i : primary channel pitch buffer */ ); +#endif /*! r: index of the last band where pitch contribution is significant */ int16_t Pit_exc_contribution_len( @@ -4222,6 +4229,7 @@ void pre_exc( const int16_t L_subfr /* i : subframe length */ ); +#ifndef IVAS_FLOAT_FIXED void encod_unvoiced( Encoder_State *st, /* i/o: state structure */ const float *speech, /* i : input speech */ @@ -4273,6 +4281,7 @@ int16_t encod_tran( int16_t position, /* i : maximum of residual signal index */ int16_t *unbits /* i/o: number of unused bits */ ); +#endif void encod_amr_wb( Encoder_State *st, /* i/o: state structure */ @@ -6739,6 +6748,7 @@ void acelp_pulsesign( float vec[], const float alp ); +#ifndef IVAS_FLOAT_FIXED void E_ACELP_4t( float dn[], float cn[], @@ -6770,6 +6780,7 @@ void E_ACELP_4tsearchx( float code[], PulseConfig *config, int16_t ind[] ); +#endif int16_t E_ACELP_indexing( float code[], diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index df01a6775..76d46c48c 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -5928,6 +5928,21 @@ void lsf_dec_fx( #endif ); +void lsf_dec_ivas_fx( + Decoder_State *st_fx, /* i/o: State structure */ + const Word16 tc_subfr, /* i : TC subframe index Q0*/ + Word16 *Aq, /* o : quantized A(z) for 4 subframes Q12*/ + Word16 *LSF_Q_prediction, /* o : LSF prediction mode Q0*/ + Word16 *lsf_new, /* o : de-quantized LSF vector Q(x2.56)*/ + Word16 *lsp_new, /* o : de-quantized LSP vector Q15*/ + Word16 *lsp_mid, /* o : de-quantized mid-frame LSP vector Q15*/ + const Word16 tdm_low_rate_mode /* i : secondary channel low rate mode flag Q0*/ +#if defined LSF_RE_USE_SECONDARY_CHANNEL || defined FIX_798_LSF_SECONDARY_CH_MISSING_CODE + , + const Word16 tdm_lsfQ_PCh[M] /* i : Q LSFs for primary channel Qx*/ +#endif +); + /*! r: index of the maximum value in the input vector */ Word16 maximum_l( const Word32 *vec, /* i : input vector */ @@ -6085,6 +6100,16 @@ void CNG_dec_fx( Word16 *sid_bw, /* i : 0-NB/WB, 1-SWB SID Q0 */ Word32 *q_env ); +void CNG_dec_ivas_fx( + Decoder_State *st_fx, /* i/o: State structure */ + const Word16 last_element_mode, /* i : last element mode Q0 */ + Word16 Aq[], /* o : LP coefficients Q12 */ + Word16 *lsp_new, /* i/o: current frame LSPs Q15 */ + Word16 *lsf_new, /* i/o: current frame LSFs Qlog2(2.56) */ + Word16 *allow_cn_step, /* o : allow CN step Q0 */ + Word16 *sid_bw, /* i : 0-NB/WB, 1-SWB SID Q0 */ + Word32 *q_env ); + void swb_CNG_dec_fx( Decoder_State *st_fx, /* i/o: State structure */ const Word16 *synth_fx, /* i : ACELP core synthesis at 32kHz Qsyn*/ diff --git a/lib_com/rom_com.c b/lib_com/rom_com.c index acf416c0a..cec1af1e9 100644 --- a/lib_com/rom_com.c +++ b/lib_com/rom_com.c @@ -2777,6 +2777,56 @@ const Word16 interpol_frac_mid_relaxprev_pred_16k_fx[NB_SUBFR16k * 3] = { 4915, *----------------------------------------------------------------------------------*/ /* Innovative codebook config */ +#ifdef IVAS_FLOAT_FIXED +const PulseConfig PulseConfTable[] = +{ + /* Design rules: + * ---> "fixed" + "tried-pair-pos"*2 = pulses & 0xfe + * ---> tracks with pulses % 3 == 0, have always TRACKPOS_FIXED_FIRST */ + /* bits,iter,alp,pulses,fixed,tried-pair-pos,codetrack */ + { 7, 4, 16384/*2.0f Q13*/, 1, 0, {8}, TRACKPOS_FREE_ONE }, /* 7 bits, 1 pulses, 4 tracks, 1000 free track */ + { 10, 4, 16384/*2.0f Q13*/, 2, 0, {8}, TRACKPOS_FIXED_EVEN }, /* 10 bits, 2 pulses, 4 tracks 1010 (used only even tracks designed for NB) */ + { 12, 4, 16384/*2.0f Q13*/, 2, 0, {8}, TRACKPOS_FIXED_TWO }, /* 12 bits, 2 pulses, 2 tracks 11 used all tracks ala AMR-WB 6.6 */ + { 15, 4, 16384/*2.0f Q13*/, 3, 0, {8}, TRACKPOS_FIXED_FIRST }, /* 15 bits, 3 pulses, 4 tracks 1110 fixed track to first ? */ + { 17, 6, 16384/*2.0f Q13*/, 3, 0, {8}, TRACKPOS_FREE_THREE }, /* 17 bits, 3 pulses, 4 tracks (used all tracks) - 1110, 1101, 1011, 0111 */ + { 20, 4, 16384/*2.0f Q13*/, 4, 0, {4, 8}, TRACKPOS_FIXED_FIRST }, /* 20 bits, 4 pulses, 4 tracks 1111 */ + { 24, 4, 16384/*2.0f Q13*/, 5, 0, {4, 8}, TRACKPOS_FIXED_FIRST }, /* 24 bits, 5 pulses, 4 tracks 2111 fixed track to first */ + { 26, 4, 16384/*2.0f Q13*/, 5, 0, {4, 8}, TRACKPOS_FREE_ONE }, /* 26 bits, 5 pulses, 4 tracks 2111 one free track ? */ + { 28, 4, 12288/*1.5f Q13*/, 6, 0, {4, 8, 8}, TRACKPOS_FIXED_FIRST }, /* 28 bits, 6 pulses, 4 tracks 2211 */ + { 30, 4, 12288/*1.5f Q13*/, 6, 0, {4, 8, 8}, TRACKPOS_FIXED_TWO }, /* 30 bits, 6 pulses, 4 tracks 2211 free consecutive track positions ? */ + { 32, 4, 12288/*1.5f Q13*/, 7, 0, {4, 8, 8}, TRACKPOS_FIXED_FIRST }, /* 32 bits, 6 pulses, 4 tracks 2221 fixed ?*/ + { 34, 4, 12288/*1.5f Q13*/, 7, 0, {4, 8, 8}, TRACKPOS_FREE_THREE }, /* 34 bits, 6 pulses, 4 tracks 2221 free track positions ? */ + { 36, 4, 8192/*1.0f Q13*/, 8, 2, {4, 8, 8}, TRACKPOS_FIXED_FIRST }, /* 36 bits, 8 pulses, 4 tracks 2222 */ + { 40, 4, 8192/*1.0f Q13*/, 9, 2, {4, 8, 8}, TRACKPOS_FIXED_FIRST }, /* 40 bits, 9 pulses, 4 tracks 3222 fixed ?*/ + { 43, 4, 8192/*1.0f Q13*/, 10, 2, {4, 6, 8, 8}, TRACKPOS_FIXED_FIRST }, /* 44 bits, 10 pulses, 4 tracks 3322 */ + { 46, 4, 8192/*1.0f Q13*/, 10, 2, {4, 6, 8, 8}, TRACKPOS_FIXED_TWO }, /* 46 bits, 10 pulses, 4 tracks 3322 free consecutive tracks ? */ + { 47, 4, 8192/*1.0f Q13*/, 11, 2, {4, 6, 8, 8}, TRACKPOS_FIXED_FIRST }, /* 47 bits, 10 pulses, 4 tracks 3332 fixed ? */ + { 49, 4, 8192/*1.0f Q13*/, 11, 2, {4, 6, 8, 8}, TRACKPOS_FREE_THREE }, /* 49 bits, 10 pulses, 4 tracks 3332 free three track positions ? */ + { 50, 4, 8192/*1.0f Q13*/, 12, 4, {4, 6, 8, 8}, TRACKPOS_FIXED_FIRST }, /* 50 bits, 12 pulses, 4 tracks 3333 */ + { 53, 4, 8192/*1.0f Q13*/, 13, 4, {4, 6, 8, 8}, TRACKPOS_FIXED_FIRST }, /* 53 bits, 13 pulses, 4 tracks 4333 fixed ? */ + { 55, 4, 8192/*1.0f Q13*/, 13, 4, {4, 6, 8, 8}, TRACKPOS_FREE_ONE }, /* 55 bits, 13 pulses, 4 tracks 4333 free one ? */ + { 56, 4, 8192/*1.0f Q13*/, 14, 4, {4, 6, 6, 8, 8}, TRACKPOS_FIXED_FIRST }, /* 56 bits, 14 pulses, 4 tracks 4433 fixed ?!?! */ + { 58, 4, 8192/*1.0f Q13*/, 14, 4, {4, 6, 6, 8, 8}, TRACKPOS_FIXED_TWO }, /* 58 bits, 14 pulses, 4 tracks 4433 free consecutive ? */ + { 59, 4, 8192/*1.0f Q13*/, 15, 4, {4, 6, 6, 8, 8}, TRACKPOS_FIXED_FIRST }, /* 59 bits, 15 pulses, 4 tracks 4443 fixed ? */ + { 61, 4, 8192/*1.0f Q13*/, 15, 4, {4, 6, 6, 8, 8}, TRACKPOS_FREE_THREE }, /* 61 bits, 15 pulses, 4 tracks 4443 free ? */ + { 62, 3, 6554/*0.8f Q13*/, 16, 4, {4, 4, 6, 6, 8, 8}, TRACKPOS_FIXED_FIRST }, /* 62 bits, 16 pulses, 4 tracks 4444 */ + { 65, 3, 6554/*0.8f Q13*/, 17, 4, {4, 4, 6, 6, 8, 8}, TRACKPOS_FIXED_FIRST }, /* 65 bits, 17 pulses, 4 tracks 5444 fixed ?*/ + { 68, 3, 6144/*0.75f Q13*/, 18, 4, {2, 3, 4, 5, 6, 7, 8}, TRACKPOS_FIXED_FIRST }, /* 68 bits, 18 pulses, 4 tracks 5544 */ + { 70, 3, 6144/*0.75f Q13*/, 19, 4, {2, 3, 4, 5, 6, 7, 8}, TRACKPOS_FIXED_FIRST }, /* 70 bits, 19 pulses, 4 tracks 5554 fixed ? */ + { 73, 3, 6144/*0.75f Q13*/, 20, 4, {2, 3, 4, 5, 6, 7, 8, 8}, TRACKPOS_FIXED_FIRST }, /* 73 bits, 20 pulses, 4 tracks 5555 fixed ? */ + { 75, 3, 6144/*0.75f Q13*/, 21, 4, {2, 3, 4, 5, 6, 7, 8, 8}, TRACKPOS_FIXED_FIRST }, /* 75 bits, 21 pulses, 4 tracks 6555 fixed ? */ + { 78, 3, 6144/*0.75f Q13*/, 22, 4, {2, 3, 4, 5, 6, 7, 8, 8, 8}, TRACKPOS_FIXED_FIRST }, /* 78 bits, 22 pulses, 4 tracks 6655 fixed ? */ + { 80, 3, 6144/*0.75f Q13*/, 23, 4, {2, 3, 4, 5, 6, 7, 8, 8, 8}, TRACKPOS_FIXED_FIRST }, /* 80 bits, 23 pulses, 4 tracks 6665 fixed ? */ + { 83, 2, 2458/*0.30f Q13*/, 24, 4, {2, 3, 4, 5, 6, 7, 8, 8, 8, 8}, TRACKPOS_FIXED_FIRST}, /* 83 bits, 24 pulses, 4 tracks 6666 */ + { 85, 2, 2458/*0.30f Q13*/, 25, 4, {2, 3, 4, 5, 6, 7, 8, 8, 8, 8}, TRACKPOS_FIXED_FIRST}, /* 85 bits, 25 pulses, 4 tracks 7666 */ + { 87, 2, 2048/*0.25f Q13*/, 26, 4, {2, 3, 4, 5, 6, 7, 8, 8, 8, 8, 8}, TRACKPOS_FIXED_FIRST}, /* 87 bits, 26 pulses, 4 tracks 7766 */ + { 89, 2, 2048/*0.25f Q13*/, 27, 4, {2, 3, 4, 5, 6, 7, 8, 8, 8, 8, 8}, TRACKPOS_FIXED_FIRST}, /* 89 bits, 27 pulses, 4 tracks 7776 */ + { 92, 2, 2048/*0.25f Q13*/, 28, 4, {2, 3, 4, 5, 6, 7, 8, 8, 8, 8, 8, 8}, TRACKPOS_FIXED_FIRST}, /* 92 bits, 28 pulses, 4 tracks 7777 */ + { 94, 2, 2048/*0.25f Q13*/, 29, 4, {2, 3, 4, 5, 6, 7, 8, 8, 8, 8, 8, 8}, TRACKPOS_FIXED_FIRST}, /* 94 bits, 29 pulses, 4 tracks 8777 */ + { 96, 1, 1638/*0.20f Q13*/, 30, 4, {2, 3, 4, 5, 6, 7, 8, 8, 8, 8, 8, 8, 8}, TRACKPOS_FIXED_FIRST}, /* 96 bits, 30 pulses, 4 tracks 8877 */ + { 98, 1, 1638/*0.20f Q13*/, 31, 4, {2, 3, 4, 5, 6, 7, 8, 8, 8, 8, 8, 8, 8}, TRACKPOS_FIXED_FIRST}, /* 98 bits, 31 pulses, 4 tracks 8887 */ +}; +#else const PulseConfig PulseConfTable[] = { /* Design rules: @@ -2825,6 +2875,7 @@ const PulseConfig PulseConfTable[] = { 96, 1, 0.20f, 1638/*0.20f Q13*/, 30, 4, {2, 3, 4, 5, 6, 7, 8, 8, 8, 8, 8, 8, 8}, TRACKPOS_FIXED_FIRST}, /* 96 bits, 30 pulses, 4 tracks 8877 */ { 98, 1, 0.20f, 1638/*0.20f Q13*/, 31, 4, {2, 3, 4, 5, 6, 7, 8, 8, 8, 8, 8, 8, 8}, TRACKPOS_FIXED_FIRST}, /* 98 bits, 31 pulses, 4 tracks 8887 */ }; +#endif /* Number of pulses & positions to the number of unique states that can be achieved with those pulses */ diff --git a/lib_com/stat_com.h b/lib_com/stat_com.h index 1bbd51a5f..8a6da6ead 100644 --- a/lib_com/stat_com.h +++ b/lib_com/stat_com.h @@ -170,9 +170,11 @@ typedef struct typedef struct { - Word16 bits; /* bits per subframe */ - Word16 nbiter; /* number of iterations */ - float alp_flt; /* initial energy of all fixed pulses */ + Word16 bits; /* bits per subframe */ + Word16 nbiter; /* number of iterations */ +#ifndef IVAS_FLOAT_FIXED + float alp_flt; /* initial energy of all fixed pulses */ +#endif Word16 alp; /* initial energy of all fixed pulses, exponent = ALP_E Q13*/ Word16 nb_pulse; /* number of pulses */ Word16 fixedpulses; /* number of pulses whose position is determined from correlation and not by iteration */ diff --git a/lib_dec/acelp_core_dec_ivas_fx.c b/lib_dec/acelp_core_dec_ivas_fx.c index 3fcf4610b..7a7db41a7 100644 --- a/lib_dec/acelp_core_dec_ivas_fx.c +++ b/lib_dec/acelp_core_dec_ivas_fx.c @@ -205,7 +205,7 @@ ivas_error acelp_core_dec_ivas_fx( configureFdCngDec_fx( st->hFdCngDec, st->bwidth, ACELP_14k25, st->L_frame, st->last_L_frame, st->element_mode ); /* decode CNG parameters */ - CNG_dec_fx( st, last_element_mode, Aq_fx, lsp_new_fx, lsf_new_fx, &allow_cn_step, sid_bw, q_env_fx ); + CNG_dec_ivas_fx( st, last_element_mode, Aq_fx, lsp_new_fx, lsf_new_fx, &allow_cn_step, sid_bw, q_env_fx ); /* comfort noise generation */ CNG_exc_fx( st->core_brate, st->L_frame, &st->hTdCngDec->Enew_fx, &st->hTdCngDec->cng_seed, NULL, NULL, &st->lp_ener_fx, st->last_core_brate, &st->first_CNG, &( st->hTdCngDec->cng_ener_seed ), NULL, allow_cn_step, &st->hTdCngDec->last_allow_cn_step, st->prev_Q_exc, st->Q_exc, st->hTdCngDec->num_ho, q_env_fx, st->hTdCngDec->lp_env_fx, st->hTdCngDec->old_env_fx, st->hTdCngDec->exc_mem_fx, st->hTdCngDec->exc_mem1_fx, sid_bw, &st->hTdCngDec->cng_ener_seed1, NULL, st->Opt_AMR_WB, st->element_mode ); @@ -645,7 +645,7 @@ ivas_error acelp_core_dec_ivas_fx( /* decode CNG parameters */ IF( st->cng_type == LP_CNG ) { - CNG_dec_fx( st, last_element_mode, Aq_fx, lsp_new_fx, lsf_new_fx, &allow_cn_step, sid_bw, q_env_fx ); + CNG_dec_ivas_fx( st, last_element_mode, Aq_fx, lsp_new_fx, lsf_new_fx, &allow_cn_step, sid_bw, q_env_fx ); FOR( Word32 nsf = 0; nsf < NB_SUBFR16k; nsf++ ) { Scale_sig( Aq_fx + imult3216( nsf, ( M + 1 ) ), M + 1, sub( norm_s( Aq_fx[nsf * ( M + 1 )] ), Q2 ) ); @@ -892,9 +892,9 @@ ivas_error acelp_core_dec_ivas_fx( IF( !tdm_lp_reuse_flag ) { #ifdef FIX_798_LSF_SECONDARY_CH_MISSING_CODE - lsf_dec_fx( st, tc_subfr, Aq_fx, &LSF_Q_prediction, lsf_new_fx, lsp_new_fx, lsp_mid_fx, tdm_low_rate_mode, tdm_lsfQ_PCh_fx ); + lsf_dec_ivas_fx( st, tc_subfr, Aq_fx, &LSF_Q_prediction, lsf_new_fx, lsp_new_fx, lsp_mid_fx, tdm_low_rate_mode, tdm_lsfQ_PCh_fx ); #else - lsf_dec_fx( st, tc_subfr, Aq_fx, &LSF_Q_prediction, lsf_new_fx, lsp_new_fx, lsp_mid_fx, tdm_low_rate_mode /*, tdm_lsfQ_PCh*/ ); + lsf_dec_ivas_fx( st, tc_subfr, Aq_fx, &LSF_Q_prediction, lsf_new_fx, lsp_new_fx, lsp_mid_fx, tdm_low_rate_mode /*, tdm_lsfQ_PCh*/ ); #endif } ELSE @@ -1023,7 +1023,7 @@ ivas_error acelp_core_dec_ivas_fx( test(); IF( ( st->stab_fac_fx == 0 ) && ( st->old_bfi_cnt > 0 ) && NE_16( st->clas_dec, VOICED_CLAS ) && NE_16( st->clas_dec, ONSET ) && ( st->relax_prev_lsf_interp == 0 ) && !( EQ_16( st->element_mode, IVAS_CPE_TD ) && EQ_16( st->idchan, 1 ) ) ) { - int_lsp4_fx( st->L_frame, st->lsp_old_fx, lsp_mid_fx, lsp_new_fx, Aq_fx, M, 2 ); + int_lsp4_ivas_fx( st->L_frame, st->lsp_old_fx, lsp_mid_fx, lsp_new_fx, Aq_fx, M, 2 ); } /*---------------------------------------------------------------* diff --git a/lib_dec/cng_dec_fx.c b/lib_dec/cng_dec_fx.c index d17bf1966..258bde6d7 100644 --- a/lib_dec/cng_dec_fx.c +++ b/lib_dec/cng_dec_fx.c @@ -10,28 +10,723 @@ #include "prot_fx.h" #include "ivas_cnst.h" +#ifdef IVAS_FLOAT_FIXED /*Temporary location to be move in prot* when merge is done*/ void E_LPC_f_isp_a_conversion( const Word16 *isp, Word16 *a, const Word16 m ); void E_LPC_f_lsp_a_conversion( const Word16 *isp, Word16 *a, const Word16 m ); -/*-----------------------------------------------------------------* - * Local function prototypes - *-----------------------------------------------------------------*/ +/*-----------------------------------------------------------------* + * Local function prototypes + *-----------------------------------------------------------------*/ + +static void shb_CNG_decod_fx( Decoder_State *st_fx, const Word16 *synth_fx, Word16 *shb_synth_fx, const Word16 sid_bw, const Word16 Qsyn ); + +static void shb_CNG_decod_ivas_fx( Decoder_State *st_fx, const Word16 *synth_fx, Word16 *shb_synth_fx, const Word16 sid_bw, const Word16 Qsyn ); + +/*-----------------------------------------------------------------* + * Decode residual signal energy + *-----------------------------------------------------------------*/ + +void CNG_dec_fx( + Decoder_State *st_fx, /* i/o: State structure */ + const Word16 last_element_mode, /* i : last element mode Q0 */ + Word16 Aq[], /* o : LP coefficients Q12 */ + Word16 *lsp_new, /* i/o: current frame LSPs Q15 */ + Word16 *lsf_new, /* i/o: current frame LSFs Qlog2(2.56) */ + Word16 *allow_cn_step, /* o : allow CN step Q0 */ + Word16 *sid_bw /* i : 0-NB/WB, 1-SWB SID Q0 */ + , + Word32 *q_env ) +{ + Word16 istep; + Word16 i, L_enr_index; + Word32 L_ener; + Word16 ener_fra, ener_int; + Word16 num_bits; + Word16 weights, ptr, j, k; + Word16 m1; + Word16 m = 0; + move16(); + Word16 tmp[HO_HIST_SIZE * M]; + Word16 burst_ho_cnt = 0; + move16(); + Word16 ll, s_ptr; + Word32 L_enr, L_tmp1; + Word16 tmp1, exp; + Word16 lsf_tmp[M]; + Word32 C[M]; + Word32 max_val[2]; + Word16 max_idx[2]; + Word16 ftmp_fx; + Word16 lsp_tmp[M]; + Word16 dev; + Word16 max_dev; + Word16 dist; + Word16 tmpv; + Word16 env_idx[2]; + Word32 enr1; + Word32 env[NUM_ENV_CNG]; + Word32 tmp_env[HO_HIST_SIZE * NUM_ENV_CNG]; + Word32 L_tmp; + Word16 fra; + Word16 temp_lo_fx, temp_hi_fx; + Word16 exp_pow; + Word16 tmp_loop; + Word16 enr_new, Aq_tmp[M + 1]; + + Word16 LSF_Q_prediction; /* o : LSF prediction mode - just temporary variable in CNG */ + TD_CNG_DEC_HANDLE hTdCngDec; +#ifdef BASOP_NOGLOB_DECLARE_LOCAL + Flag Overflow = 0; + move32(); +#endif + hTdCngDec = st_fx->hTdCngDec; + + m = 0; + move16(); + /*-----------------------------------------------------------------* + * Decode CNG spectral envelope (only in SID frame) + *-----------------------------------------------------------------*/ + test(); + IF( EQ_32( st_fx->core_brate, SID_1k75 ) || EQ_32( st_fx->core_brate, SID_2k40 ) ) + { + /* de-quantize the LSF vector */ + IF( st_fx->Opt_AMR_WB != 0 ) + { + /* Flt function */ + isf_dec_amr_wb_fx( st_fx, Aq, lsf_new, lsp_new ); + /* check IF ISPs may trigger too much synthesis energy */ + + E_LPC_f_isp_a_conversion( lsp_new, Aq_tmp, M ); + enr_new = Enr_1_Az_fx( Aq_tmp, 2 * L_SUBFR ); + + IF( ( shr( enr_new, 14 ) > 0 ) ) + { + /* Use old LSP vector */ + Copy( st_fx->lsp_old_fx, lsp_new, M ); /* Q15 */ + Copy( st_fx->lsf_old_fx, lsf_new, M ); /* Q2.56 */ + } + } + ELSE + { + lsf_dec_fx( st_fx, 0, Aq, &LSF_Q_prediction, lsf_new, lsp_new, 0, 0 +#if defined LSF_RE_USE_SECONDARY_CHANNEL || defined FIX_798_LSF_SECONDARY_CH_MISSING_CODE + , + NULL +#endif + ); + /* check IF LSPs may trigger too much synthesis energy */ + + E_LPC_f_lsp_a_conversion( lsp_new, Aq_tmp, M ); + enr_new = Enr_1_Az_fx( Aq_tmp, 2 * L_SUBFR ); + + IF( shr( enr_new, 14 ) > 0 ) + { + /* Use old LSP vector */ + Copy( st_fx->lsp_old_fx, lsp_new, M ); /* Q15 */ + Copy( st_fx->lsf_old_fx, lsf_new, M ); /* Q2.56 */ + } + } + } + ELSE + { + /* Use old LSP vector */ + Copy( st_fx->lsp_old_fx, lsp_new, M ); /* Q15 */ + Copy( st_fx->lsf_old_fx, lsf_new, M ); /* Q2.56 */ + } + + /* Initialize the CNG spectral envelope in case of the very first CNG frame */ + IF( st_fx->first_CNG == 0 ) + { + Copy( st_fx->lsp_old_fx, st_fx->lspCNG_fx, M ); /* Q15 */ + } + + /*-----------------------------------------------------------------* + * Decode residual signal energy + *-----------------------------------------------------------------*/ + + *allow_cn_step = 0; + move16(); + test(); + IF( EQ_32( st_fx->core_brate, SID_1k75 ) || EQ_32( st_fx->core_brate, SID_2k40 ) ) + { + istep = ISTEP_AMR_WB_SID_FX; /* Q15 */ + move16(); + if ( EQ_32( st_fx->core_brate, SID_2k40 ) ) + { + istep = ISTEP_SID_FX; /* Q15 */ + move16(); + } + + /* initialize the energy quantization parameters */ + num_bits = 6; + move16(); + if ( st_fx->Opt_AMR_WB == 0 ) + { + num_bits = 7; + move16(); + } + + /* decode the energy index */ + L_enr_index = get_next_indice_fx( st_fx, num_bits ); + + IF( LE_32( st_fx->last_core_brate, SID_2k40 ) || EQ_16( st_fx->prev_bfi, 1 ) ) + { + tmp1 = add( hTdCngDec->old_enr_index, 20 ); + } + ELSE + { + tmp1 = add( hTdCngDec->old_enr_index, 40 ); + } + IF( GT_16( L_enr_index, tmp1 ) && hTdCngDec->old_enr_index >= 0 ) /* Likely bit error and not startup */ + { + L_enr_index = tmp1; + move16(); + L_enr_index = s_min( L_enr_index, 127 ); /* Q0 */ + IF( st_fx->Opt_AMR_WB ) + { + L_enr_index = s_min( L_enr_index, 63 ); /* Q0 */ + } + } + + test(); + test(); + test(); + IF( GT_32( st_fx->last_core_brate, SID_1k75 ) && + NE_16( st_fx->first_CNG, 0 ) && + GE_16( hTdCngDec->old_enr_index, 0 ) && + GT_16( L_enr_index, add( hTdCngDec->old_enr_index, 1 ) ) ) + { + *allow_cn_step = 1; + move16(); + } + + hTdCngDec->old_enr_index = L_enr_index; + move16(); + if ( !L_enr_index ) + { + L_enr_index = -5; + move16(); + } + /* st_fx->Enew = L_enr_index / step - 2.0f;*/ + L_ener = L_mult( L_enr_index, istep ); /* Q16 (0+15) */ + /* subtract by 2 not done to leave Energy in Q2 */ + + /* extract integral and fractional parts */ + ener_fra = L_Extract_lc( L_ener, &ener_int ); + ener_int = add( ener_int, 4 ); /* Q2 to Q6 */ + + /* find the new energy value */ + hTdCngDec->Enew_fx = Pow2( ener_int, ener_fra ); + move32(); + + IF( EQ_32( st_fx->core_brate, SID_2k40 ) ) + { + burst_ho_cnt = get_next_indice_fx( st_fx, 3 ); /* 3bit */ + + *sid_bw = get_next_indice_fx( st_fx, 1 ); + move16(); + IF( *sid_bw == 0 ) + { + env_idx[0] = get_next_indice_fx( st_fx, 6 ); + move16(); + + /* get quantized res_env_details */ + FOR( i = 0; i < NUM_ENV_CNG; i++ ) + { + q_env[i] = L_deposit_l( CNG_details_codebook_fx[env_idx[0]][i] ); + move32(); + } + } + } + /* Reset CNG history IF CNG frame length is changed */ + test(); + test(); + IF( EQ_16( st_fx->bwidth, WB ) && NE_16( st_fx->first_CNG, 0 ) && NE_16( st_fx->L_frame, st_fx->last_CNG_L_frame ) ) + { + hTdCngDec->ho_hist_size = 0; + move16(); + } + } + + /*---------------------------------------------------------------------* + * CNG spectral envelope update + * Find A(z) coefficients + *---------------------------------------------------------------------*/ + test(); + test(); + test(); + IF( LE_32( st_fx->last_core_brate, SID_2k40 ) ) + { + /* Reset hangover counter if not first SID period */ + if ( GT_32( st_fx->core_brate, FRAME_NO_DATA ) ) + { + hTdCngDec->num_ho = 0; + move16(); + } + /* Update LSPs IF last SID energy not outliers or insufficient number of hangover frames */ + test(); + IF( LT_16( hTdCngDec->num_ho, 3 ) || LT_32( Mult_32_16( hTdCngDec->Enew_fx, 21845 /*1/1.5f, Q15*/ ), st_fx->lp_ener_fx ) ) + { + FOR( i = 0; i < M; i++ ) + { + /* AR low-pass filter */ + st_fx->lspCNG_fx[i] = mac_r( L_mult( CNG_ISF_FACT_FX, st_fx->lspCNG_fx[i] ), 32768 - CNG_ISF_FACT_FX, lsp_new[i] ); + move16(); /* Q15 (15+15+1-16) */ + } + } + } + ELSE + { + /* Update CNG_mode IF allowed */ + test(); + test(); + test(); + IF( ( st_fx->Opt_AMR_WB || EQ_16( st_fx->bwidth, WB ) ) && ( !st_fx->first_CNG || GE_16( hTdCngDec->act_cnt2, MIN_ACT_CNG_UPD ) ) ) + { + IF( GT_32( st_fx->last_active_brate, ACELP_16k40 ) ) + { + st_fx->CNG_mode = -1; + move16(); + } + ELSE + { + st_fx->CNG_mode = get_cng_mode( st_fx->last_active_brate ); + move16(); + } + } + + /* If first sid after active burst update LSF history from circ buffer */ + burst_ho_cnt = s_min( burst_ho_cnt, hTdCngDec->ho_circ_size ); /* MODE1_DTX_IN_CODEC_B_FIX Q0*/ + hTdCngDec->act_cnt = 0; + move16(); + s_ptr = add( sub( hTdCngDec->ho_circ_ptr, burst_ho_cnt ), 1 ); + IF( s_ptr < 0 ) + { + s_ptr = add( s_ptr, hTdCngDec->ho_circ_size ); + } + + FOR( ll = burst_ho_cnt; ll > 0; ll-- ) + { + hTdCngDec->ho_hist_ptr = add( hTdCngDec->ho_hist_ptr, 1 ); /* Q0 */ + move16(); + if ( EQ_16( hTdCngDec->ho_hist_ptr, HO_HIST_SIZE ) ) + { + hTdCngDec->ho_hist_ptr = 0; + move16(); + } + + /* Conversion between 12.8k and 16k LSPs */ + test(); + test(); + test(); + IF( ( EQ_16( st_fx->L_frame, L_FRAME16k ) && hTdCngDec->ho_16k_lsp[s_ptr] == 0 ) || ( EQ_16( st_fx->L_frame, L_FRAME ) && EQ_16( hTdCngDec->ho_16k_lsp[s_ptr], 1 ) ) ) + { + /* Conversion from 16k LPSs to 12k8 */ + lsp_convert_poly_fx( &( hTdCngDec->ho_lsp_circ_fx[s_ptr * M] ), st_fx->L_frame, 0 ); + } + /* update the circular buffers */ + Copy( &( hTdCngDec->ho_lsp_circ_fx[s_ptr * M] ), &( hTdCngDec->ho_lsp_hist_fx[hTdCngDec->ho_hist_ptr * M] ), M ); /* Qx */ + Copy32( &( hTdCngDec->ho_ener_circ_fx[s_ptr] ), &( hTdCngDec->ho_ener_hist_fx[hTdCngDec->ho_hist_ptr] ), 1 ); /* Q6 */ + hTdCngDec->ho_sid_bw = L_shl( L_and( hTdCngDec->ho_sid_bw, (Word32) 0x3fffffffL ), 1 ); + move32(); + Copy32( &( hTdCngDec->ho_env_circ_fx[s_ptr * NUM_ENV_CNG] ), &( hTdCngDec->ho_env_hist_fx[hTdCngDec->ho_hist_ptr * NUM_ENV_CNG] ), NUM_ENV_CNG ); /* Qx */ + + hTdCngDec->ho_hist_size = add( hTdCngDec->ho_hist_size, 1 ); + move16(); + + if ( GT_16( hTdCngDec->ho_hist_size, HO_HIST_SIZE ) ) + { + hTdCngDec->ho_hist_size = HO_HIST_SIZE; + move16(); + } + + s_ptr = add( s_ptr, 1 ); + if ( EQ_16( s_ptr, hTdCngDec->ho_circ_size ) ) + { + s_ptr = 0; + move16(); + } + } + + IF( hTdCngDec->ho_hist_size > 0 ) /* can be -1 at init MODE1_DTX_IN_CODEC_B_FIX */ + { + /* *allow_cn_step |= ( st_fx->ho_ener_hist[st_fx->ho_hist_ptr] > 4.0f * st_fx->lp_ener );*/ + L_tmp1 = L_shr( hTdCngDec->ho_ener_hist_fx[hTdCngDec->ho_hist_ptr], 2 ); + L_tmp1 = L_sub( L_tmp1, st_fx->lp_ener_fx ); + + test(); + test(); + IF( ( L_tmp1 > 0 && ( st_fx->first_CNG || st_fx->element_mode == EVS_MONO ) ) ) + { + *allow_cn_step = s_or( *allow_cn_step, 1 ); + move16(); + } + } + IF( EQ_16( last_element_mode, IVAS_CPE_TD ) ) + { + *allow_cn_step = 1; + move16(); + } + test(); + IF( EQ_16( *allow_cn_step, 0 ) && GT_16( hTdCngDec->ho_hist_size, 0 ) ) + { + /* Use average of energies below last energy */ + ptr = hTdCngDec->ho_hist_ptr; + move16(); + Copy( &( hTdCngDec->ho_lsp_hist_fx[ptr * M] ), tmp, M ); /* Qx */ + m1 = 0; + move16(); + IF( L_and( hTdCngDec->ho_sid_bw, (Word32) 0x1 ) == 0 ) + { + Copy32( &hTdCngDec->ho_env_hist_fx[ptr * NUM_ENV_CNG], tmp_env, NUM_ENV_CNG ); + m1 = 1; + move16(); + } + L_enr = Mult_32_16( hTdCngDec->ho_ener_hist_fx[ptr], W_DTX_HO_FX[0] ); /* Q6+15-15->Q6 */ + + weights = W_DTX_HO_FX[0]; /* Q15 */ + move16(); + + m = 1; + move16(); + FOR( k = 1; k < hTdCngDec->ho_hist_size; k++ ) + { + ptr--; + if ( ptr < 0 ) + { + ptr = HO_HIST_SIZE - 1; + move16(); + } + + test(); + IF( LT_32( Mult_32_16( hTdCngDec->ho_ener_hist_fx[ptr], ONE_OVER_BUF_H_NRG_FX ), hTdCngDec->ho_ener_hist_fx[hTdCngDec->ho_hist_ptr] ) && + GT_32( hTdCngDec->ho_ener_hist_fx[ptr], Mult_32_16( hTdCngDec->ho_ener_hist_fx[hTdCngDec->ho_hist_ptr], BUF_L_NRG_FX ) ) ) + { + /*enr += W_DTX_HO[k] * st_fx->ho_ener_hist[ptr];*/ + L_tmp1 = Mult_32_16( hTdCngDec->ho_ener_hist_fx[ptr], W_DTX_HO_FX[k] ); /* Q6+15-15->Q6 */ + L_enr = L_add( L_enr, L_tmp1 ); /* Q6 */ + + /*weights += W_DTX_HO[k];*/ + weights = add( weights, W_DTX_HO_FX[k] ); /* Q15 */ + + Copy( &hTdCngDec->ho_lsp_hist_fx[ptr * M], &tmp[m * M], M ); /* Qx */ + IF( EQ_32( L_and( hTdCngDec->ho_sid_bw, L_shl( (Word32) 0x1, k ) ), 0 ) ) + { + Copy32( &hTdCngDec->ho_env_hist_fx[ptr * NUM_ENV_CNG], &tmp_env[m1 * NUM_ENV_CNG], NUM_ENV_CNG ); /* Qx */ + m1++; + } + m++; + } + } + + /*enr /= weights;*/ + exp = norm_s( weights ); + tmp1 = div_s( shl( 1, sub( 14, exp ) ), weights ); /* Q(15+14-exp-15) */ + L_tmp1 = Mult_32_16( L_enr, tmp1 ); /* Q(14-exp+6-15)->Q(5-exp) */ + L_enr = L_shl( L_tmp1, add( exp, 1 ) ); /* Q6 */ + + st_fx->lp_ener_fx = L_enr; /* Q6 */ + move32(); + set32_fx( max_val, 0, 2 ); + set16_fx( max_idx, 0, 2 ); + + FOR( i = 0; i < m; i++ ) + { + IF( EQ_16( st_fx->L_frame, L_FRAME ) ) + { + lsp2lsf_fx( &tmp[i * M], lsf_tmp, M, INT_FS_FX ); + ftmp_fx = 964; + move16(); /*X2.56 */ + tmpv = sub( 16384, add( lsf_tmp[M - 1], ftmp_fx ) ); /*QX2.56*/ + L_tmp = L_mult0( tmpv, tmpv ); /*QX6.5536*/ + } + ELSE + { + lsp2lsf_fx( &tmp[i * M], lsf_tmp, M, INT_FS_16k_FX ); + ftmp_fx = 1205; + move16(); /*QX2.56*/ + tmpv = sub( 20480, add( lsf_tmp[M - 1], ftmp_fx ) ); /*QX2.56*/ + L_tmp = L_mult0( tmpv, tmpv ); /*QX6.5536*/ + } + + tmpv = sub( lsf_tmp[0], ftmp_fx ); /*QX2.56*/ + L_tmp = L_mac0( L_tmp, tmpv, tmpv ); /*QX6.5536*/ + FOR( j = 0; j < M - 1; j++ ) + { + tmpv = sub( sub( lsf_tmp[j + 1], lsf_tmp[j] ), ftmp_fx ); /*QX2.56*/ + L_tmp = L_mac0( L_tmp, tmpv, tmpv ); /*QX6.5536*/ + } + + C[i] = Mpy_32_16_1( L_tmp, 1928 ); /*QX6.5536*/ + move32(); + + IF( GT_32( C[i], max_val[0] ) ) + { + max_val[1] = max_val[0]; + move32(); + max_idx[1] = max_idx[0]; + move16(); + max_val[0] = C[i]; + move32(); + max_idx[0] = i; + move16(); + } + ELSE IF( GT_32( C[i], max_val[1] ) ) + { + max_val[1] = C[i]; + move32(); + max_idx[1] = i; + move16(); + } + } + + IF( EQ_16( m, 1 ) ) + { + Copy( tmp, lsp_tmp, M ); /* Qx */ + } + ELSE IF( LT_16( m, 4 ) ) + { + FOR( i = 0; i < M; i++ ) + { + L_tmp1 = 0; + move32(); + FOR( j = 0; j < m; j++ ) + { + L_tmp1 = L_add( L_tmp1, L_deposit_l( tmp[j * M + i] ) ); + } + + L_tmp1 = L_sub( L_tmp1, L_deposit_l( tmp[max_idx[0] * M + i] ) ); + tmpv = div_s( 1, sub( m, 1 ) ); /*Q15*/ + L_tmp1 = Mpy_32_16_1( L_tmp1, tmpv ); /*Q15*/ + lsp_tmp[i] = extract_l( L_tmp1 ); /*Q15*/ + move16(); + } + } + ELSE + { + FOR( i = 0; i < M; i++ ) + { + L_tmp1 = 0; + move32(); + FOR( j = 0; j < m; j++ ) + { + L_tmp1 = L_add( L_tmp1, L_deposit_l( tmp[j * M + i] ) ); + } -#ifdef IVAS_FLOAT_FIXED -static void shb_CNG_decod_fx( Decoder_State *st_fx, const Word16 *synth_fx, Word16 *shb_synth_fx, const Word16 sid_bw, const Word16 Qsyn ); + L_tmp1 = L_sub( L_tmp1, L_add( L_deposit_l( tmp[max_idx[0] * M + i] ), L_deposit_l( tmp[max_idx[1] * M + i] ) ) ); /*Q15*/ + tmpv = div_s( 1, sub( m, 2 ) ); /*Q15*/ + L_tmp1 = Mpy_32_16_1( L_tmp1, tmpv ); /*Q15*/ + lsp_tmp[i] = extract_l( L_tmp1 ); /*Q15*/ + move16(); + } + } + + dist = 0; + move16(); /*Q15*/ + max_dev = 0; + move16(); /*Q15*/ + FOR( i = 0; i < M; i++ ) + { + dev = abs_s( sub( lsp_tmp[i], lsp_new[i] ) ); /*Q15*/ +#ifdef BASOP_NOGLOB + dist = add_o( dist, dev, &Overflow ); /*Q15*/ +#else + dist = add( dist, dev ); /*Q15*/ #endif + if ( GT_16( dev, max_dev ) ) + { + max_dev = dev; + move16(); + } + } -#ifdef IVAS_FLOAT_FIXED -static void shb_CNG_decod_ivas_fx( Decoder_State *st_fx, const Word16 *synth_fx, Word16 *shb_synth_fx, const Word16 sid_bw, const Word16 Qsyn ); + test(); + IF( GT_16( dist, 13107 ) || GT_16( max_dev, 3277 ) ) /* 0.4 and 0.1 in Q15 */ + { + FOR( i = 0; i < M; i++ ) + { + st_fx->lspCNG_fx[i] = lsp_tmp[i]; + move16(); /*Q15*/ + } + } + ELSE + { + FOR( i = 0; i < M; i++ ) + { + /* AR low-pass filter */ + st_fx->lspCNG_fx[i] = add( mult_r( 26214, lsp_tmp[i] ), mult_r( 6554, lsp_new[i] ) ); /* Q15 */ + move16(); + } + } + IF( m1 > 0 ) + { + FOR( i = 0; i < NUM_ENV_CNG; i++ ) + { + L_tmp = L_deposit_l( 0 ); + FOR( j = 0; j < m1; j++ ) + { + /* env[i] += tmp_env[j*NUM_ENV_CNG+i];*/ +#ifdef BASOP_NOGLOB + L_tmp = L_add_sat( L_tmp, tmp_env[j * NUM_ENV_CNG + i] ); +#else + L_tmp = L_add( L_tmp, tmp_env[j * NUM_ENV_CNG + i] ); +#endif + } + /* env[i] /= (float)m1; */ + /* env[i] = env[i] - 2*st_fx->lp_ener_fx; */ + IF( EQ_16( m1, 1 ) ) + { +#ifdef BASOP_NOGLOB + L_tmp = L_sub_sat( L_tmp, L_add_sat( st_fx->lp_ener_fx, st_fx->lp_ener_fx ) ); /* Q6 */ +#else + L_tmp = L_sub( L_tmp, L_add( st_fx->lp_ener_fx, st_fx->lp_ener_fx ) ); +#endif + } + ELSE + { + tmp1 = div_s( 1, m1 ); + L_tmp = Mult_32_16( L_tmp, tmp1 ); /* Q6 */ +#ifdef BASOP_NOGLOB + L_tmp = L_sub_sat( L_tmp, L_add_sat( st_fx->lp_ener_fx, st_fx->lp_ener_fx ) ); /* Q6 */ +#else + L_tmp = L_sub( L_tmp, L_add( st_fx->lp_ener_fx, st_fx->lp_ener_fx ) ); #endif + } + env[i] = L_tmp; /* Q6 */ + move32(); + } -/*-----------------------------------------------------------------* - * Decode residual signal energy - *-----------------------------------------------------------------*/ + Copy32( env, hTdCngDec->lp_env_fx, NUM_ENV_CNG ); /* Q6 */ + } + } + ELSE + { + Copy( lsp_new, st_fx->lspCNG_fx, M ); /* use newly analyzed ISFs */ /* Q15 */ + } + } -#ifdef IVAS_FLOAT_FIXED -void CNG_dec_fx( + test(); + IF( EQ_32( st_fx->core_brate, SID_1k75 ) || EQ_32( st_fx->core_brate, SID_2k40 ) ) + { + /* Update hangover memory during CNG */ + test(); +#ifdef BASOP_NOGLOB + IF( ( *allow_cn_step == 0 ) && LT_32( hTdCngDec->Enew_fx, L_add_sat( st_fx->lp_ener_fx, L_shr( st_fx->lp_ener_fx, 1 ) ) ) ) +#else + IF( *allow_cn_step == 0 && LT_32( hTdCngDec->Enew_fx, L_add( st_fx->lp_ener_fx, L_shr( st_fx->lp_ener_fx, 1 ) ) ) ) +#endif + { + /* update the pointer to circular buffer of old LSP vectors */ + hTdCngDec->ho_hist_ptr++; + move16(); + if ( EQ_16( hTdCngDec->ho_hist_ptr, HO_HIST_SIZE ) ) + { + hTdCngDec->ho_hist_ptr = 0; + move16(); + } + + /* update the circular buffer of old LSP vectors with the new LSP vector */ + Copy( lsp_new, &( hTdCngDec->ho_lsp_hist_fx[( hTdCngDec->ho_hist_ptr ) * M] ), M ); /* Q15 */ + + /* update the hangover energy buffer */ + hTdCngDec->ho_ener_hist_fx[hTdCngDec->ho_hist_ptr] = hTdCngDec->Enew_fx; /* Q6 */ + move32(); + test(); + IF( EQ_32( st_fx->core_brate, SID_2k40 ) && ( *sid_bw == 0 ) ) + { + /* enr1 = (float)log10( st->Enew*L_frame + 0.1f ) / (float)log10( 2.0f );*/ + exp = norm_l( hTdCngDec->Enew_fx ); + L_tmp = L_shl( hTdCngDec->Enew_fx, exp ); /*Q(exp+6)*/ + L_tmp = Mult_32_16( L_tmp, shl( st_fx->L_frame, 5 ) ); /*Q(exp+6+5-15=exp-4)*/ +#ifdef BASOP_NOGLOB + L_tmp = L_shr_sat( L_tmp, sub( exp, 10 ) ); /*Q6*/ +#else + L_tmp = L_shr( L_tmp, sub( exp, 10 ) ); /*Q6*/ +#endif + 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 = L_shr( L_tmp, 10 ); /* Q6 */ + + FOR( i = 0; i < NUM_ENV_CNG; i++ ) + { + /* get quantized envelope */ + /* env[i] = pow(2.0f,(enr1 - q_env[i])) + 2*st->Enew;*/ + 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 ) ); /* Q6 */ + move32(); + L_tmp = L_add( hTdCngDec->Enew_fx, hTdCngDec->Enew_fx ); + env[i] = L_add( env[i], L_tmp ); /* Q6 */ + move32(); + } + hTdCngDec->ho_sid_bw = L_shl( L_and( hTdCngDec->ho_sid_bw, (Word32) 0x3fffffffL ), 1 ); /* Q0 */ + move32(); + Copy32( env, &( hTdCngDec->ho_env_hist_fx[hTdCngDec->ho_hist_ptr * NUM_ENV_CNG] ), NUM_ENV_CNG ); /* Q6 */ + } + ELSE IF( ( *sid_bw != 0 ) ) + { + hTdCngDec->ho_sid_bw = L_shl( L_and( hTdCngDec->ho_sid_bw, (Word32) 0x3fffffffL ), 1 ); /* Q0 */ + move32(); + hTdCngDec->ho_sid_bw = L_or( hTdCngDec->ho_sid_bw, 0x1L ); /* Q0 */ + move32(); + } + + hTdCngDec->ho_hist_size = add( hTdCngDec->ho_hist_size, 1 ); + move16(); + if ( GT_16( hTdCngDec->ho_hist_size, HO_HIST_SIZE ) ) + { + hTdCngDec->ho_hist_size = HO_HIST_SIZE; + move16(); + } + } + /* Update the frame length memory */ + st_fx->last_CNG_L_frame = st_fx->L_frame; + move16(); + + if ( NE_32( st_fx->core_brate, SID_1k75 ) ) + { + hTdCngDec->num_ho = m; + move16(); + } + } + + IF( st_fx->element_mode == EVS_MONO ) + { + st_fx->last_CNG_L_frame = st_fx->L_frame; + move16(); + + IF( NE_32( st_fx->core_brate, SID_1k75 ) ) + { + hTdCngDec->num_ho = m; + move16(); + } + } + IF( st_fx->Opt_AMR_WB ) + { + E_LPC_f_isp_a_conversion( st_fx->lspCNG_fx, Aq, M ); + } + ELSE + { + E_LPC_f_lsp_a_conversion( st_fx->lspCNG_fx, Aq, M ); + } + + tmp_loop = shr( st_fx->L_frame, 6 ); + FOR( i = 1; i < tmp_loop; i++ ) /* L_frame/L_SUBFR */ + { + Copy( Aq, &Aq[i * ( M + 1 )], add( M, 1 ) ); /* Q12 */ + } + + return; +} + +void CNG_dec_ivas_fx( Decoder_State *st_fx, /* i/o: State structure */ const Word16 last_element_mode, /* i : last element mode Q0 */ Word16 Aq[], /* o : LP coefficients Q12 */ @@ -113,10 +808,10 @@ void CNG_dec_fx( } ELSE { - lsf_dec_fx( st_fx, 0, Aq, &LSF_Q_prediction, lsf_new, lsp_new, 0, 0 + lsf_dec_ivas_fx( st_fx, 0, Aq, &LSF_Q_prediction, lsf_new, lsp_new, 0, 0 #if defined LSF_RE_USE_SECONDARY_CHANNEL || defined FIX_798_LSF_SECONDARY_CH_MISSING_CODE - , - NULL + , + NULL #endif ); /* check IF LSPs may trigger too much synthesis energy */ @@ -536,7 +1231,7 @@ void CNG_dec_fx( #ifdef BASOP_NOGLOB dist = add_o( dist, dev, &Overflow ); /*Q15*/ #else - dist = add( dist, dev ); /*Q15*/ + dist = add( dist, dev ); /*Q15*/ #endif if ( GT_16( dev, max_dev ) ) { @@ -729,14 +1424,13 @@ void CNG_dec_fx( return; } -#endif /*---------------------------------------------------------------------* * swb_CNG_dec() * * Comfort noise generation for SHB signal *---------------------------------------------------------------------*/ -#ifdef IVAS_FLOAT_FIXED + void swb_CNG_dec_fx( Decoder_State *st_fx, /* i/o: State structure */ const Word16 *synth_fx, /* i : ACELP core synthesis at 32kHz Qsyn*/ @@ -775,9 +1469,7 @@ void swb_CNG_dec_fx( return; } -#endif -#ifdef IVAS_FLOAT_FIXED void swb_CNG_dec_ivas_fx( Decoder_State *st_fx, /* i/o: State structure */ const Word16 *synth_fx, /* i : ACELP core synthesis at 32kHz Qsyn*/ @@ -815,14 +1507,13 @@ void swb_CNG_dec_ivas_fx( return; } -#endif /*---------------------------------------------------------------------* * shb_CNG_decod() * * Main routine of SHB SID decoding and CNG *---------------------------------------------------------------------*/ -#ifdef IVAS_FLOAT_FIXED + static void shb_CNG_decod_fx( Decoder_State *st_fx, /* i/o: State structure */ const Word16 *synth_fx, /* i : ACELP core synthesis at 32kHz Qsyn*/ @@ -1112,9 +1803,7 @@ static void shb_CNG_decod_fx( return; } -#endif -#ifdef IVAS_FLOAT_FIXED static void shb_CNG_decod_ivas_fx( Decoder_State *st, /* i/o: State structure */ const Word16 *synth_fx, /* i : ACELP core synthesis at 32kHz Qsyn*/ @@ -1394,7 +2083,6 @@ static void shb_CNG_decod_ivas_fx( ResetSHBbuffer_Dec_fx( st ); return; } -#endif /*-------------------------------------------------------------------* * td_cng_dec_init_fx() @@ -1402,7 +2090,6 @@ static void shb_CNG_decod_ivas_fx( * *-------------------------------------------------------------------*/ -#ifdef IVAS_FLOAT_FIXED void td_cng_dec_init_fx( DEC_CORE_HANDLE st /* i/o: decoder state structure */ ) @@ -1492,9 +2179,7 @@ void td_cng_dec_init_fx( return; } -#endif -#ifdef IVAS_FLOAT_FIXED void td_cng_dec_init_ivas_fx( DEC_CORE_HANDLE st /* i/o: decoder state structure */ ) diff --git a/lib_dec/jbm_pcmdsp_apa.c b/lib_dec/jbm_pcmdsp_apa.c index 297221eb4..4eff4ad5e 100644 --- a/lib_dec/jbm_pcmdsp_apa.c +++ b/lib_dec/jbm_pcmdsp_apa.c @@ -271,6 +271,9 @@ UWord8 apa_reconfigure( free( ps->buf_out_fx ); ps->buf_out_fx = (Word16 *) malloc( sizeof( Word16 ) * ps->buf_out_capacity ); +#ifdef MSAN_FIX + memset( ps->buf_out_fx, 0, ( sizeof( Word16 ) * ps->buf_out_capacity ) ); +#endif ps->Q_buf_out = Q15; move16(); IF( !ps->buf_out_fx ) diff --git a/lib_dec/lsf_dec_fx.c b/lib_dec/lsf_dec_fx.c index a50c98d09..3f92a6972 100644 --- a/lib_dec/lsf_dec_fx.c +++ b/lib_dec/lsf_dec_fx.c @@ -102,6 +102,7 @@ static void dqlsf_CNG_fx( /* RETURN ARGUMENTS : */ /* _ None */ /*===========================================================================*/ + void lsf_dec_fx( Decoder_State *st_fx, /* i/o: State structure */ const Word16 tc_subfr, /* i : TC subframe index Q0*/ @@ -333,6 +334,268 @@ void lsf_dec_fx( return; } + +/*===========================================================================*/ +/* FUNCTION : lsf_dec_ivas_fx() */ +/*---------------------------------------------------------------------------*/ +/* PURPOSE : LSF decoder */ +/*---------------------------------------------------------------------------*/ +/* INPUT ARGUMENTS : */ +/* _ (Struct) st_fx : decoder static memory */ +/* _ (Word16) L_frame : length of the frame */ +/* _ (Word16) coder_type : coding type */ +/* _ (Word16) bwidth : input signal bandwidth */ +/*---------------------------------------------------------------------------*/ +/* OUTPUT ARGUMENTS : */ +/* _ (Word16*) Aq : LP filter coefficient Q12 */ +/* _ (Word16*) lsf_new : LP filter coefficient Q(x2.56) */ +/* _ (Word16*) lsp_new : LP filter coefficient Q15 */ +/* _ (Word16*) lsp_mid : LP filter coefficient Q15 */ +/*---------------------------------------------------------------------------*/ + +/* _ (Word16[]) st_fx->lsf_adaptive_mean_fx : FEC - adaptive mean LSF */ +/* vector for FEC Q(x2.56) */ +/* _ (Word16[]) st_fx->mem_AR_fx : AR memory of LSF quantizer */ +/* (past quantized LSFs without mean) Q(x2.56) */ +/* _ (Word16) st_fx->stab_fac_fx : LSF stability factor Q15 */ +/*---------------------------------------------------------------------------*/ +/* RETURN ARGUMENTS : */ +/* _ None */ +/*===========================================================================*/ + +void lsf_dec_ivas_fx( + Decoder_State *st_fx, /* i/o: State structure */ + const Word16 tc_subfr, /* i : TC subframe index Q0*/ + Word16 *Aq, /* o : quantized A(z) for 4 subframes Q12*/ + Word16 *LSF_Q_prediction, /* o : LSF prediction mode Q0*/ + Word16 *lsf_new, /* o : de-quantized LSF vector Q(x2.56)*/ + Word16 *lsp_new, /* o : de-quantized LSP vector Q15*/ + Word16 *lsp_mid, /* o : de-quantized mid-frame LSP vector Q15*/ + const Word16 tdm_low_rate_mode /* i : secondary channel low rate mode flag Q0*/ +#if defined LSF_RE_USE_SECONDARY_CHANNEL || defined FIX_798_LSF_SECONDARY_CH_MISSING_CODE + , + const Word16 tdm_lsfQ_PCh[M] /* i : Q LSFs for primary channel Qx*/ +#endif +) +{ + Word16 i; + Word16 no_param_lpc; + Word16 param_lpc[NPRM_LPC_NEW]; + Word32 L_tmp; + Word16 nBits = 0; + move16(); + Word16 tmp_old[M + 1], tmp_new[M + 1]; + Word16 enr_old = 0, enr_new = 0; + move16(); + move16(); + Word16 lsf_diff, coder_type; + + /* initialize */ + coder_type = st_fx->coder_type; + if ( EQ_32( st_fx->core_brate, SID_2k40 ) ) + { + coder_type = INACTIVE; /* Q0 */ + move16(); + } + test(); + if ( EQ_16( coder_type, AUDIO ) && st_fx->GSC_IVAS_mode > 0 ) + { + coder_type = GENERIC; /* Q0 */ + move16(); + } + no_param_lpc = 0; + nBits = 0; + move16(); + move16(); + + /* Find the number of bits for LSF quantization */ + IF( EQ_32( st_fx->core_brate, SID_2k40 ) ) + { + nBits = LSF_BITS_CNG; /* Q0 */ + move16(); + } + ELSE + { + test(); + IF( st_fx->nelp_mode_dec == 0 && st_fx->ppp_mode_dec == 0 ) + { + nBits = st_fx->acelp_cfg.lsf_bits; /* Q0 */ + move16(); + } + ELSE IF( EQ_16( st_fx->nelp_mode_dec, 1 ) ) + { + IF( EQ_16( coder_type, UNVOICED ) ) + { + nBits = 30; /* Q0 */ + move16(); + if ( st_fx->bwidth == NB ) + { + nBits = 32; /* Q0 */ + move16(); + } + } + } + ELSE IF( EQ_16( st_fx->ppp_mode_dec, 1 ) ) + { + nBits = 26; /* Q0 */ + move16(); + } + } + + /* LSF de-quantization */ + lsf_end_dec_fx( st_fx, 0, coder_type, st_fx->bwidth, nBits, lsf_new, param_lpc, LSF_Q_prediction, &no_param_lpc +#ifdef FIX_798_LSF_SECONDARY_CH_MISSING_CODE + , + tdm_lsfQ_PCh +#endif + ); + + /* convert quantized LSFs to LSPs */ + + lsf2lsp_fx( lsf_new, lsp_new, M, st_fx->sr_core ); + /* set seed_acelp used in UC mode */ + test(); + IF( EQ_16( coder_type, UNVOICED ) && GT_16( st_fx->element_mode, EVS_MONO ) ) + { + st_fx->seed_acelp = 0; + move16(); + FOR( i = no_param_lpc - 1; i >= 0; i-- ) + { + /* rightshift before *seed_acelp+param_lpc[i] to avoid overflows*/ + st_fx->seed_acelp = extract_l( L_add( imult3216( 31821L /* Q0 */, add( shr( ( st_fx->seed_acelp ), 1 ), param_lpc[i] ) ), 13849L /* Q0 */ ) ); /* Q0 */ + move16(); + // PMTE() /*IVAS_CODE to be completed */ + } + } + IF( EQ_32( st_fx->core_brate, SID_2k40 ) ) + { + /* return if SID frame (conversion to A(z) done in the calling function) */ + return; + } + + /*-------------------------------------------------------------------------------------* + * FEC - update adaptive LSF mean vector + *-------------------------------------------------------------------------------------*/ + + FOR( i = 0; i < M; i++ ) + { + L_tmp = L_mult( lsf_new[i], 10922 ); /*Q(x2.56+16)*/ + L_tmp = L_mac( L_tmp, st_fx->lsfoldbfi1_fx[i], 10922 ); /*Q(x2.56+16)*/ + L_tmp = L_mac( L_tmp, st_fx->lsfoldbfi0_fx[i], 10922 ); /*Q(x2.56+16)*/ + st_fx->lsf_adaptive_mean_fx[i] = round_fx( L_tmp ); /*Q(x2.56)*/ + move16(); + } + + test(); + test(); + IF( ( st_fx->prev_bfi && ( EQ_16( coder_type, TRANSITION ) ) && ( EQ_16( tc_subfr, sub( st_fx->L_frame, L_SUBFR ) ) ) ) ) + { + lsf_diff = 1205; + move16(); /*int_fs / (float)(2*(M+1)); = 470.588 -> 1205 in Q2.56 */ + if ( EQ_16( st_fx->L_frame, L_FRAME ) ) + { + lsf_diff = 964; + move16(); /*int_fs / (float)(2*(M+1)); = 376.47 -> 964 in Q2.56 */ + } + st_fx->lsf_old_fx[0] = lsf_diff; + move16(); + + FOR( i = 1; i < M; i++ ) + { + st_fx->lsf_old_fx[i] = add( st_fx->lsf_old_fx[i - 1], lsf_diff ); /* Q2.56 */ + move16(); + } + lsf2lsp_fx( st_fx->lsf_old_fx, st_fx->lsp_old_fx, M, st_fx->sr_core ); + } + /*-------------------------------------------------------------------------------------* + * Mid-frame LSF decoding + * LSP interpolation and conversion of LSPs to A(z) + *-------------------------------------------------------------------------------------*/ + IF( st_fx->rate_switching_reset ) + { + /*extrapolation in case of unstable LSF convert*/ + Copy( lsp_new, st_fx->lsp_old_fx, M ); /* Q15 */ + Copy( lsf_new, st_fx->lsf_old_fx, M ); /* Q2.56 */ + } + { + /* Mid-frame LSF decoding */ + lsf_mid_dec_fx( st_fx, lsp_new, coder_type, lsp_mid ); + } + test(); + test(); + IF( !( st_fx->prev_bfi && ( EQ_16( coder_type, TRANSITION ) ) && ( EQ_16( tc_subfr, sub( st_fx->L_frame, L_SUBFR ) ) ) ) ) + { + IF( st_fx->prev_bfi ) + { + /* check, if LSP interpolation can be relaxed */ + E_LPC_f_lsp_a_conversion( st_fx->lsp_old_fx, tmp_old, M ); + enr_old = Enr_1_Az_fx( tmp_old, 2 * L_SUBFR ); /* Q3 */ + + E_LPC_f_lsp_a_conversion( lsp_new, tmp_new, M ); + enr_new = Enr_1_Az_fx( tmp_new, 2 * L_SUBFR ); /* Q3 */ + + IF( LT_16( enr_new, mult_r( 9830 /*0.3 Q15*/, enr_old ) ) ) + { + /* OLD CODE : if( st->safety_net == 1), replaced with a decision similar to MODE2 */ + st_fx->relax_prev_lsf_interp = -1; + move16(); + test(); + test(); + test(); + test(); + if ( st_fx->clas_dec == UNVOICED_CLAS || EQ_16( st_fx->clas_dec, SIN_ONSET ) || st_fx->clas_dec == INACTIVE_CLAS || EQ_16( coder_type, GENERIC ) || EQ_16( coder_type, TRANSITION ) ) + { + st_fx->relax_prev_lsf_interp = 1; + move16(); + } + } + } + } + test(); + IF( EQ_16( st_fx->last_core, HQ_CORE ) && st_fx->core == ACELP_CORE ) + { + /* update old LSPs/LSFs in case of HQ->ACELP core switching */ + Copy( lsp_mid, st_fx->lsp_old_fx, M ); /* Q15 */ + lsp2lsf_fx( lsp_mid, st_fx->lsf_old_fx, M, st_fx->sr_core ); /* Q15 */ + } + test(); + IF( EQ_16( tdm_low_rate_mode, 1 ) && GT_16( coder_type, UNVOICED ) ) + { + // PMT("To be verified") + IF( EQ_16( st_fx->active_cnt, 1 ) ) + { + Copy( lsp_mid, st_fx->lsp_old_fx, M ); /* Q15 */ + lsp2lsf_fx( lsp_mid, st_fx->lsf_old_fx, M, st_fx->sr_core ); /* Q15 */ + Copy( lsp_new, lsp_mid, M ); /* Q15 */ + } + + /* LSP interpolation and conversion of LSPs to A(z) - two-subframe mode */ + int_lsp4_ivas_fx( st_fx->L_frame, st_fx->lsp_old_fx, lsp_mid, lsp_new, Aq, M, -2 ); + } + ELSE + { + /* LSP interpolation and conversion of LSPs to A(z) */ + int_lsp4_ivas_fx( st_fx->L_frame, st_fx->lsp_old_fx, lsp_mid, lsp_new, Aq, M, st_fx->relax_prev_lsf_interp ); + } + /*------------------------------------------------------------------* + * Check LSF stability (distance between old LSFs and current LSFs) + *------------------------------------------------------------------*/ + + IF( st_fx->element_mode == EVS_MONO ) + { + st_fx->stab_fac_fx = lsf_stab_fx( lsf_new, st_fx->lsf_old_fx, 0, st_fx->L_frame ); /*Q15*/ + move16(); + } + ELSE + { + st_fx->stab_fac_fx = lsf_stab_ivas_fx( lsf_new, st_fx->lsf_old_fx, 0, st_fx->L_frame ); /* Q15 */ + move16(); + } + + return; +} + + /*========================================================================*/ /* FUNCTION : lsf_end_dec_fx() */ /*------------------------------------------------------------------------*/ diff --git a/lib_enc/acelp_core_enc.c b/lib_enc/acelp_core_enc.c index 45e429430..19cf8c52a 100644 --- a/lib_enc/acelp_core_enc.c +++ b/lib_enc/acelp_core_enc.c @@ -289,7 +289,6 @@ ivas_error acelp_core_enc( /* reset the GSC pre echo energy threshold in case of switching */ if ( st->hGSCEnc != NULL ) { - st->hGSCEnc->Last_frame_ener = (float) MAX_32; st->hGSCEnc->Last_frame_ener_fx = MAX_32; move32(); } @@ -417,11 +416,11 @@ ivas_error acelp_core_enc( IF( st->rate_switching_reset ) { /*extrapolation in case of unstable LSP*/ - int_lsp4_fx( st->L_frame, lsp_mid_fx, lsp_mid_fx, lsp_new_fx, A_fx, M, 0 ); + int_lsp4_ivas_fx( st->L_frame, lsp_mid_fx, lsp_mid_fx, lsp_new_fx, A_fx, M, 0 ); } ELSE { - int_lsp4_fx( st->L_frame, st->lsp_old_fx, lsp_mid_fx, lsp_new_fx, A_fx, M, 0 ); + int_lsp4_ivas_fx( st->L_frame, st->lsp_old_fx, lsp_mid_fx, lsp_new_fx, A_fx, M, 0 ); } /* Reset LPC mem */ @@ -489,7 +488,6 @@ ivas_error acelp_core_enc( floatToFixed_arr( Aq, Aq_fx, NB_SUBFR16k * ( M + 1 ), Q12 ); floatToFixed_arr( lsp_mid, lsp_mid_fx, Q15, M ); floatToFixed_arr( lsp_new, lsp_new_fx, Q15, M ); - floatToFixed_arr( st->hTdCngEnc->exc_mem2, st->hTdCngEnc->exc_mem2_fx, Q_new - 1, 30 ); for ( i = 0; i < M; i++ ) { lsf_new_fx[i] = (Word16) ( lsf_new[i] * 2.56f ); @@ -501,7 +499,6 @@ ivas_error acelp_core_enc( fixedToFloat_arr( Aq_fx, Aq, Q12, NB_SUBFR16k * ( M + 1 ) ); fixedToFloat_arr( lsp_new_fx, lsp_new, Q15, M ); fixedToFloat_arrL32( q_env_fx, q_env, Q6, NUM_ENV_CNG ); - fixedToFloat_arr( st->hTdCngEnc->exc_mem2_fx, st->hTdCngEnc->exc_mem2, Q_new - 1, 30 ); for ( i = 0; i < M; i++ ) { lsf_new[i] = ( (float) lsf_new_fx[i] / 2.56f ); @@ -516,17 +513,9 @@ ivas_error acelp_core_enc( #ifdef IVAS_FLOAT_FIXED_CONVERSIONS floatToFixed_arr32( q_env, q_env_fx, Q6, NUM_ENV_CNG ); - // Word16 Q_exc_l = Q_factor_arr( st->hTdCngEnc->exc_mem, 24 ); - // Word16 Q_exc1_l = Q_factor_arr( st->hTdCngEnc->exc_mem1, 30 ); - // Q_exc_l = min( Q_exc_l, Q_exc1_l ); - floatToFixed_arr( st->hTdCngEnc->exc_mem, st->hTdCngEnc->exc_mem_fx, Q_new - 1, 24 ); - floatToFixed_arr( st->hTdCngEnc->exc_mem1, st->hTdCngEnc->exc_mem1_fx, Q_new - 1, 30 ); #endif /* comfort noise generation */ - // CNG_exc( st->core_brate, st->L_frame, &st->hTdCngEnc->Enew_fx, &st->hTdCngEnc->cng_seed, exc, exc2, &st->hTdCngEnc->lp_ener, st->last_core_brate, &st->hDtxEnc->first_CNG, - //&st->hTdCngEnc->cng_ener_seed, bwe_exc, allow_cn_step, &st->hTdCngEnc->last_allow_cn_step, st->hTdCngEnc->num_ho, q_env, st->hTdCngEnc->lp_env, st->hTdCngEnc->old_env, - // st->hTdCngEnc->exc_mem, st->hTdCngEnc->exc_mem1, &sid_bw, &st->hTdCngEnc->cng_ener_seed1, exc3, st->Opt_AMR_WB, EVS_MONO ); CNG_exc_fx( st->core_brate, st->L_frame, &st->hTdCngEnc->Enew_fx, &st->hTdCngEnc->cng_seed, exc_fx, exc2_fx, &st->hTdCngEnc->lp_ener_fx, st->last_core_brate, &st->hDtxEnc->first_CNG, &st->hTdCngEnc->cng_ener_seed, bwe_exc_fx, allow_cn_step, &st->hTdCngEnc->last_allow_cn_step, sub( st->prev_Q_new, 1 ), sub( Q_new, 1 ), st->hTdCngEnc->num_ho, q_env_fx, st->hTdCngEnc->lp_env_fx, st->hTdCngEnc->old_env_fx, st->hTdCngEnc->exc_mem_fx, st->hTdCngEnc->exc_mem1_fx, &sid_bw, &st->hTdCngEnc->cng_ener_seed1, exc3_fx, st->Opt_AMR_WB, EVS_MONO ); @@ -537,8 +526,6 @@ ivas_error acelp_core_enc( fixedToFloat_arr( exc2_fx, exc2, Q_new - 1, st->L_frame ); fixedToFloat_arr( exc3_fx, exc3, Q_new - 1, st->L_frame ); fixedToFloat_arr( bwe_exc_fx, bwe_exc, Q_new - 1, st->L_frame ); - fixedToFloat_arr( st->hTdCngEnc->exc_mem_fx, st->hTdCngEnc->exc_mem, Q_new - 1, 24 ); - fixedToFloat_arr( st->hTdCngEnc->exc_mem1_fx, st->hTdCngEnc->exc_mem1, Q_new - 1, 30 ); #endif } else @@ -731,22 +718,14 @@ ivas_error acelp_core_enc( IF( tdm_lsfQ_PCh ) tdm_lsfQ_PCh_fx[idx] = (Word16) ( tdm_lsfQ_PCh[idx] * 2.56f ); } - // Q_old_bwe_exc = Q_factor_arr( old_bwe_exc, 1380 ); floatToFixed_arr( old_bwe_exc, old_bwe_exc_fx, Q_new, 1380 ); - /*Q_exc = Q_factor_arr( old_exc_flt, st->L_frame ); - hLPDmem->e_old_exc = Q_factor_arr( &hLPDmem->old_exc_flt[-M - 1], L_EXC_MEM + M + 1 ) - 1; - Q_exc = min(s_min( Q_exc, hLPDmem->e_old_exc ), Q_new); - hLPDmem->e_old_exc = Q15 - Q_exc;*/ floatToFixed_arr( &hLPDmem->old_exc_flt[-M - 1], &hLPDmem->old_exc[-M - 1], Q_new, L_EXC_MEM + M + 1 ); floatToFixed_arr( old_exc_flt, old_exc_fx, Q_new, st->L_frame ); st->preemph_fac = float_to_fix16( st->preemph_fac_flt, Q15 ); floatToFixed_arr( st->voicing, st->voicing_fx, Q15, 3 ); - // Word16 pitch_buf_fx[NB_SUBFR16k]; - // Word16 voice_factors_fx[NB_SUBFR16k]; floatToFixed_arr( voice_factors, voice_factors_fx, Q15, NB_SUBFR16k ); - st->hGSCEnc->Last_frame_ener_fx = floatToFixed_32( st->hGSCEnc->Last_frame_ener, Q4 ); f2me_buf_16( st->hGSCEnc->last_exc_dct_in, st->hGSCEnc->last_exc_dct_in_fx, &st->hGSCEnc->Q_last_exc_dct_in, L_FRAME16k ); st->hGSCEnc->Q_last_exc_dct_in = Q15 - st->hGSCEnc->Q_last_exc_dct_in; #endif @@ -1016,7 +995,6 @@ ivas_error acelp_core_enc( fixedToFloat_arr( &Aq_fx[i * ( M + 1 )], &Aq[i * ( M + 1 )], 14 - norm_s( Aq_fx[i * ( M + 1 )] ), ( M + 1 ) ); } fixedToFloat_arr( old_exc_fx, old_exc_flt, Q_new, st->L_frame ); - // me2f_buf_16(&hLPDmem->old_exc[-M - 1], hLPDmem->e_old_exc, &hLPDmem->old_exc_flt[-M - 1], L_EXC_MEM + M + 1); fixedToFloat_arr( &hLPDmem->old_exc[-M - 1], &hLPDmem->old_exc_flt[-M - 1], Q_new, L_EXC_MEM + M + 1 ); fixedToFloat_arr( old_bwe_exc_fx, old_bwe_exc, Q_new, 1380 ); fixedToFloat_arr( res_fx, res, Q_new, st->L_frame ); @@ -1028,7 +1006,6 @@ ivas_error acelp_core_enc( fixedToFloat_arr( exc2_fx, exc2, Q_new, L_FRAME16k ); if ( st->hBWE_TD ) fixedToFloat_arr( bwe_exc_fx, bwe_exc, Q_new, L_FRAME32k ); - st->hGSCEnc->Last_frame_ener = fixedToFloat_32( st->hGSCEnc->Last_frame_ener_fx, Q4 ); me2f_buf_16( st->hGSCEnc->last_exc_dct_in_fx, Q15 - st->hGSCEnc->Q_last_exc_dct_in, st->hGSCEnc->last_exc_dct_in, L_FRAME16k ); fixedToFloat_arr( syn_fx, syn, Q_new - 1, L_FRAME16k ); fixedToFloat_arr( voice_factors_fx, voice_factors, Q15, NB_SUBFR16k ); @@ -1113,7 +1090,7 @@ ivas_error acelp_core_enc( Word32 epsP_fx[M + 1]; Word16 e_epsP; f2me_buf( epsP, epsP_fx, &e_epsP, M + 1 ); - st->exc_pe_fx = float_to_fix16( st->exc_pe, st->Q_stat_noise ); + // st->exc_pe_fx = float_to_fix16_thrld( st->exc_pe, st->Q_stat_noise ); floatToFixed_arr( lsp_new, lsp_new_fx, 15, 16 ); floatToFixed_arr( lsp_mid, lsp_mid_fx, 15, 16 ); #endif diff --git a/lib_enc/analy_lp_fx.c b/lib_enc/analy_lp_fx.c index cd8856713..ee21c7ae8 100644 --- a/lib_enc/analy_lp_fx.c +++ b/lib_enc/analy_lp_fx.c @@ -111,12 +111,12 @@ void analy_lp_ivas_fx( IF( EQ_16( sec_chan_low_rate, 1 ) ) { /* LSP interpolation */ - int_lsp4_fx( L_frame, lsp_old, lsp_mid, lsp_new, A, M, -2 ); + int_lsp4_ivas_fx( L_frame, lsp_old, lsp_mid, lsp_new, A, M, -2 ); } ELSE { /* LSP interpolation */ - int_lsp4_fx( L_frame, lsp_old, lsp_mid, lsp_new, A, M, 0 ); + int_lsp4_ivas_fx( L_frame, lsp_old, lsp_mid, lsp_new, A, M, 0 ); } Copy( lsp_new, lsp_old, M ); *ener = L_Comp( epsP_h[M], epsP_l[M] ); diff --git a/lib_enc/cod4t64.c b/lib_enc/cod4t64.c index 88bbc93ec..5c609ad9d 100644 --- a/lib_enc/cod4t64.c +++ b/lib_enc/cod4t64.c @@ -47,11 +47,13 @@ * Local function prototypes *---------------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED static int16_t quant_1p_N1( const int16_t pos, const int16_t N ); static int16_t quant_3p_3N1( const int16_t pos1, const int16_t pos2, const int16_t pos3, const int16_t N ); static int32_t quant_4p_4N( const int16_t pos[], const int16_t N ); static int32_t quant_5p_5N( const int16_t pos[], const int16_t N ); static int32_t quant_6p_6N_2( const int16_t pos[], const int16_t N ); +#endif static int16_t pre_process( const float v[], int16_t pos_vector[], int16_t pos_vector_num[], int16_t *pulse_pos_num ); static int32_t fcb_encode_position( const int16_t pos_vector[], int16_t n, const int16_t pos_num, const int16_t flag ); static int32_t fcb_encode_class( const int16_t buffer[], const int16_t pulse_num, const int16_t pos_num ); @@ -78,6 +80,7 @@ static int32_t fcb_encode_PI( const float v[], const int16_t pulse_num ); * Each pulse can have sixteen (16) possible positions. *---------------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED int16_t acelp_4t64( BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ float dn[], /* i : corr. between target and h[]. */ @@ -436,6 +439,7 @@ static int16_t quant_1p_N1( /*---------------------------------------------------------------------* * Quantization of 2 pulses with 2*N+1 bits: * *---------------------------------------------------------------------*/ +#endif /*! r: return (2*N)+1 bits */ int16_t quant_2p_2N1( @@ -494,6 +498,7 @@ int16_t quant_2p_2N1( return index; } +#ifndef IVAS_FLOAT_FIXED /*---------------------------------------------------------------------* * Quantization of 3 pulses with 3*N+1 bits: * *---------------------------------------------------------------------*/ @@ -767,6 +772,7 @@ static int32_t quant_6p_6N_2( return ( index ); } +#endif /*---------------------------------------------------------------------* *order the pulse position * diff --git a/lib_enc/dtx.c b/lib_enc/dtx.c index ac6b98299..2c2161079 100644 --- a/lib_enc/dtx.c +++ b/lib_enc/dtx.c @@ -761,118 +761,97 @@ void dtx_hangover_control( #ifdef IVAS_FLOAT_FIXED void td_cng_enc_init( TD_CNG_ENC_HANDLE hTdCngEnc, /* i/o: DTX/TD CNG data handle */ - const int16_t Opt_DTX_ON, /* i : flag indicating DTX operation */ - const int16_t max_bwidth /* i : maximum encoded bandwidth */ + const Word16 Opt_DTX_ON, /* i : flag indicating DTX operation */ + const Word16 max_bwidth /* i : maximum encoded bandwidth */ ) { hTdCngEnc->cng_seed = RANDOM_INITSEED; hTdCngEnc->cng_ener_seed = RANDOM_INITSEED; hTdCngEnc->cng_ener_seed1 = RANDOM_INITSEED; -#ifndef IVAS_FLOAT_FIXED - hTdCngEnc->lp_ener = 0.0f; -#else hTdCngEnc->lp_ener_fx = 0; -#endif hTdCngEnc->old_enr_index = -1; -#ifndef IVAS_FLOAT_FIXED - hTdCngEnc->Enew = 0.0f; - - hTdCngEnc->lp_sp_enr = 0.0f; -#else hTdCngEnc->Enew_fx = 0; - hTdCngEnc->lp_sp_enr_fx = 0; -#endif - hTdCngEnc->last_allow_cn_step = 0; - -#ifndef IVAS_FLOAT_FIXED - hTdCngEnc->CNG_att = 0.0f; -#else hTdCngEnc->CNG_att_fx = 0; -#endif - - if ( Opt_DTX_ON ) + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + + IF( Opt_DTX_ON ) { hTdCngEnc->cng_hist_ptr = -1; -#ifndef IVAS_FLOAT_FIXED - set_f( hTdCngEnc->cng_lsp_hist, 0, DTX_HIST_SIZE * M ); - set_f( hTdCngEnc->cng_ener_hist, 0, DTX_HIST_SIZE ); -#else set16_fx( hTdCngEnc->cng_lsp_hist_fx, 0, DTX_HIST_SIZE * M ); set16_fx( hTdCngEnc->cng_ener_hist_fx, 0, DTX_HIST_SIZE ); -#endif hTdCngEnc->ho_hist_ptr = -1; hTdCngEnc->ho_sid_bw = 0; -#ifndef IVAS_FLOAT_FIXED - set_f( hTdCngEnc->ho_lsp_hist, 0, HO_HIST_SIZE * M ); - set_f( hTdCngEnc->ho_ener_hist, 0, HO_HIST_SIZE ); - set_f( hTdCngEnc->ho_env_hist, 0, HO_HIST_SIZE * NUM_ENV_CNG ); -#else set16_fx( hTdCngEnc->ho_lsp_hist_fx, 0, HO_HIST_SIZE * M ); set32_fx( hTdCngEnc->ho_ener_hist_fx, 0, HO_HIST_SIZE ); set32_fx( hTdCngEnc->ho_env_hist_fx, 0, HO_HIST_SIZE * NUM_ENV_CNG ); -#endif hTdCngEnc->ho_hist_size = 0; hTdCngEnc->act_cnt = 0; + move16(); + move16(); + move16(); + move16(); + move16(); } - set_s( hTdCngEnc->ho_16k_lsp, 0, HO_HIST_SIZE ); + set16_fx( hTdCngEnc->ho_16k_lsp, 0, HO_HIST_SIZE ); hTdCngEnc->act_cnt2 = 0; hTdCngEnc->num_ho = 0; + move16(); + move16(); hTdCngEnc->ho_circ_ptr = -1; -#ifndef IVAS_FLOAT_FIXED - set_f( hTdCngEnc->ho_lsp_circ, 0, HO_HIST_SIZE * M ); - set_f( hTdCngEnc->ho_ener_circ, 0, HO_HIST_SIZE ); - set_f( hTdCngEnc->ho_env_circ, 0, HO_HIST_SIZE * NUM_ENV_CNG ); -#else + move16(); set16_fx( hTdCngEnc->ho_lsp_circ_fx, 0, HO_HIST_SIZE * M ); set32_fx( hTdCngEnc->ho_ener_circ_fx, 0, HO_HIST_SIZE ); set32_fx( hTdCngEnc->ho_env_circ_fx, 0, HO_HIST_SIZE * NUM_ENV_CNG ); -#endif hTdCngEnc->ho_circ_size = 0; hTdCngEnc->burst_ho_cnt = 0; hTdCngEnc->cng_buf_cnt = 0; + move16(); + move16(); + move16(); - -#ifndef IVAS_FLOAT_FIXED - set_f( hTdCngEnc->lp_env, 0.0f, 20 ); - set_f( hTdCngEnc->cng_res_env, 0.0f, 20 * 8 ); -#else set32_fx( hTdCngEnc->lp_env_fx, 0, 20 ); set32_fx( hTdCngEnc->cng_res_env_fx, 0, 20 * 8 ); -#endif - set_f( hTdCngEnc->exc_mem, 0.0f, 24 ); - set_f( hTdCngEnc->exc_mem1, 0.0f, 30 ); - set_f( hTdCngEnc->exc_mem2, 0.0f, 30 ); -#ifndef IVAS_FLOAT_FIXED - set_f( hTdCngEnc->old_env, 0.0f, NUM_ENV_CNG ); -#else + set16_fx( hTdCngEnc->exc_mem_fx, 0, 24 ); + set16_fx( hTdCngEnc->exc_mem1_fx, 0, 30 ); + set16_fx( hTdCngEnc->exc_mem2_fx, 0, 30 ); set32_fx( hTdCngEnc->old_env_fx, 0, NUM_ENV_CNG ); -#endif + #ifdef IVAS_FLOAT_FIXED_CONVERSIONS // required for float fixed conversions set_f( hTdCngEnc->cng_exc2_buf_flt, 0.0f, HO_HIST_SIZE * L_FFT ); #endif /* SWB CNG/DTX */ -#ifndef IVAS_FLOAT_FIXED - hTdCngEnc->last_wb_cng_ener = -6.02f; - hTdCngEnc->last_shb_cng_ener = -6.02f; - hTdCngEnc->mov_wb_cng_ener = -6.02f; - hTdCngEnc->mov_shb_cng_ener = -6.02f; -#else hTdCngEnc->last_wb_cng_ener_fx = -1541; hTdCngEnc->last_shb_cng_ener_fx = -1541; hTdCngEnc->mov_wb_cng_ener_fx = -1541; hTdCngEnc->mov_shb_cng_ener_fx = -1541; -#endif + move16(); + move16(); + move16(); + move16(); hTdCngEnc->shb_cng_ini_cnt = 1; hTdCngEnc->shb_NO_DATA_cnt = 0; - hTdCngEnc->last_SID_bwidth = min( max_bwidth, SWB ); + move16(); + move16(); + hTdCngEnc->last_SID_bwidth = s_min( max_bwidth, SWB ); hTdCngEnc->last_vad = 0; hTdCngEnc->last_idx_ener = 0; + move16(); + move16(); + move16(); return; } diff --git a/lib_enc/enc_acelp.c b/lib_enc/enc_acelp.c index 30ce1c54a..e2eff084b 100644 --- a/lib_enc/enc_acelp.c +++ b/lib_enc/enc_acelp.c @@ -74,6 +74,7 @@ static void E_ACELP_codearithp( const float v[], uint32_t *n, uint32_t *ps, int1 * Returns: * void */ +#ifndef IVAS_FLOAT_FIXED static void acelp_h_vec_corr1( float h[], float vec[], @@ -139,6 +140,7 @@ static void acelp_h_vec_corr2( } return; } +#endif /* @@ -164,6 +166,7 @@ static void acelp_h_vec_corr2( * Returns: * void */ +#ifndef IVAS_FLOAT_FIXED static void acelp_2pulse_search( int16_t nb_pos_ix, int16_t track_x, @@ -236,6 +239,7 @@ static void acelp_2pulse_search( return; } +#endif /* @@ -257,6 +261,7 @@ static void acelp_2pulse_search( * Returns: * void */ +#ifndef IVAS_FLOAT_FIXED static void E_ACELP_1pulse_search( int16_t track_x, int16_t track_y, @@ -321,6 +326,7 @@ static void E_ACELP_1pulse_search( return; } +#endif /* @@ -417,6 +423,7 @@ void acelp_findcandidates( } +#ifndef IVAS_FLOAT_FIXED static void acelp_hbuf( float *h_buf, float **h, @@ -1006,6 +1013,7 @@ void E_ACELP_4tsearch( return; } +#endif /* @@ -1043,6 +1051,7 @@ void E_ACELP_4tsearch( * void */ +#ifndef IVAS_FLOAT_FIXED void E_ACELP_4t( float dn[], float cn[], @@ -1088,6 +1097,7 @@ void E_ACELP_4t( return; } +#endif int16_t E_ACELP_indexing( diff --git a/lib_enc/enc_acelpx.c b/lib_enc/enc_acelpx.c index 8a01982a1..c7fb86512 100644 --- a/lib_enc/enc_acelpx.c +++ b/lib_enc/enc_acelpx.c @@ -42,6 +42,7 @@ #include "wmc_auto.h" +#ifndef IVAS_FLOAT_FIXED /* Iterations: nb_pos_ix*16 */ static void E_ACELP_2pulse_searchx( const int16_t nb_pos_ix, @@ -495,3 +496,4 @@ void E_ACELP_4tsearchx( return; } +#endif diff --git a/lib_enc/gs_enc.c b/lib_enc/gs_enc.c index f60107866..1a068ff68 100644 --- a/lib_enc/gs_enc.c +++ b/lib_enc/gs_enc.c @@ -46,20 +46,18 @@ #include "prot_fx.h" #endif -#ifndef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* * Local function prototypes *-------------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED static float edyn( const float *vec, const int16_t lvec ); - /*-------------------------------------------------------------------* * encod_audio() * * Encode audio (AC) frames *-------------------------------------------------------------------*/ - void encod_audio( Encoder_State *st, /* i/o: State structure */ const float speech[], /* i : input speech */ @@ -685,8 +683,8 @@ void GSC_enc_init( set16_fx( hGSCEnc->mem_syn_tmp_fx, 0, M ); #endif - hGSCEnc->Last_frame_ener = (float) MAX_32; #ifndef IVAS_FLOAT_FIXED + hGSCEnc->Last_frame_ener = (float) MAX_32; hGSCEnc->mid_dyn = 40.0f; #else hGSCEnc->mid_dyn_fx = 5120; diff --git a/lib_enc/inov_enc.c b/lib_enc/inov_enc.c index 58c880029..80af44816 100644 --- a/lib_enc/inov_enc.c +++ b/lib_enc/inov_enc.c @@ -48,6 +48,7 @@ * Encode the algebraic innovation *---------------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED void inov_encode( Encoder_State *st, /* i/o: encoder state structure */ const int32_t core_brate, /* i : core bitrate */ @@ -378,3 +379,4 @@ void inov_encode( return; } +#endif diff --git a/lib_enc/ivas_core_pre_proc_front.c b/lib_enc/ivas_core_pre_proc_front.c index c83202108..532b59ed4 100644 --- a/lib_enc/ivas_core_pre_proc_front.c +++ b/lib_enc/ivas_core_pre_proc_front.c @@ -862,51 +862,52 @@ ivas_error pre_proc_front_ivas( } #else ivas_error pre_proc_front_ivas_fx( - SCE_ENC_HANDLE hSCE, /* i/o: SCE encoder structure */ - CPE_ENC_HANDLE hCPE, /* i/o: CPE encoder structure */ - const Word32 element_brate, /* i : SCE/CPE element bitrate */ - const Word16 nb_bits_metadata, /* i : number of metadata bits */ - const Word16 input_frame, /* i : frame length */ - const Word16 n, /* i : channel number */ - Word16 old_inp_12k8_fx[], /* o : (Q-1) buffer of old input signal */ - float old_inp_12k8[], /* o : buffer of old input signal */ - float old_inp_16k[], /* o : buffer of old input signal @16kHz */ - float *ener, /* o : residual energy from Levinson-Durbin */ - float *relE, /* o : frame relative energy */ - float A[NB_SUBFR16k * ( M + 1 )], /* o : A(z) unquantized for the 4 subframes */ - float Aw[NB_SUBFR16k * ( M + 1 )], /* o : weighted A(z) unquantized for subframes */ - float epsP[M + 1], /* o : LP prediction errors */ - float lsp_new[M], /* o : LSPs at the end of the frame */ - float lsp_mid[M], /* o : LSPs in the middle of the frame */ - Word16 *vad_hover_flag, /* o : VAD hangover flag */ - Word16 *attack_flag, /* o : flag signaling attack */ - float realBuffer[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i/o: real buffer */ - float imagBuffer[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i/o: imag buffer */ - float old_wsp[], /* o : weighted input signal buffer */ - float pitch_fr[NB_SUBFR], /* o : fractional pitch values */ - float voicing_fr[NB_SUBFR], /* o : fractional pitch gains */ - Word16 *loc_harm, /* o : harmonicity flag */ - float *cor_map_sum, /* o : speech/music clasif. parameter */ - Word16 *vad_flag_dtx, /* o : HE-SAD flag with additional DTX HO */ - float enerBuffer[CLDFB_NO_CHANNELS_MAX], /* o : energy buffer */ - float fft_buff[2 * L_FFT], /* o : FFT buffer */ - Word16 fft_buff_fx[2 * L_FFT], /* o : FFT buffer */ - const float tdm_A_PCh[M + 1], /* i : unq. LP coeff. of primary channel */ - const float tdm_lsp_new_PCh[M], /* i : unq. LSPs of primary channel */ - const float currFlatness, /* i : flatness parameter */ - const Word16 tdm_ratio_idx, /* i : Current Ratio_L index */ - float fr_bands_LR[][2 * NB_BANDS], /* i : energy in frequency bands */ - const float Etot_LR[], /* i : total energy Left & Right channel Q8*/ - float lf_E_LR[][2 * VOIC_BINS], /* i : per bin spectrum energy in lf, LR channels */ - const Word16 localVAD_HE_SAD_LR[], /* i : HE-SAD flag without hangover, LR channels */ - float band_energies_LR[2 * NB_BANDS], /* o : energy in critical bands without minimum noise floor E_MIN */ - const Word16 flag_16k_smc, /* i : flag to indicate if the OL SMC is run at 16 kHz */ - const Word16 front_vad_flag, /* i : front-VAD flag to overwrite VAD decision */ - const Word16 force_front_vad, /* i : flag to force VAD decision */ - const Word16 front_vad_dtx_flag, /* i : front-VAD DTX flag to overwrite VAD decision*/ - const IVAS_FORMAT ivas_format, /* i : IVAS format */ - const Word16 MCT_flag, /* i : hMCT handle allocated (1) or not (0) */ - const Word32 ivas_total_brate /* i : IVAS total bitrate - for setting the DTX */ + SCE_ENC_HANDLE hSCE, /* i/o: SCE encoder structure */ + CPE_ENC_HANDLE hCPE, /* i/o: CPE encoder structure */ + const Word32 element_brate, /* i : SCE/CPE element bitrate */ + const Word16 nb_bits_metadata, /* i : number of metadata bits */ + const Word16 input_frame, /* i : frame length */ + const Word16 n, /* i : channel number */ + Word16 old_inp_12k8_fx[], /* o : (Q-1) buffer of old input signal */ + float old_inp_12k8[], /* o : buffer of old input signal */ + float old_inp_16k[], /* o : buffer of old input signal @16kHz */ + float *ener, /* o : residual energy from Levinson-Durbin */ + Word16 *relE_fx, /* o : frame relative energy Q8 */ + Word16 A_fx[NB_SUBFR16k * ( M + 1 )], /* o : A(z) unquantized for the 4 subframes Q12 */ + Word16 Aw_fx[NB_SUBFR16k * ( M + 1 )], /* o : weighted A(z) unquantized for subframes Q12 */ + float epsP[M + 1], /* o : LP prediction errors */ + Word16 lsp_new_fx[M], /* o : LSPs at the end of the frame Q15 */ + Word16 lsp_mid_fx[M], /* o : LSPs in the middle of the frame Q15 */ + Word16 *vad_hover_flag, /* o : VAD hangover flag */ + Word16 *attack_flag, /* o : flag signaling attack */ + Word32 realBuffer_fx[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i/o: real buffer Q(q_re_im_buf) */ + Word32 imagBuffer_fx[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i/o: imag buffer Q(q_re_im_buf) */ + Word16 *q_re_im_buf, /* i/o: Q-factor of real and imag buffer */ + float old_wsp[], /* o : weighted input signal buffer */ + Word16 pitch_fr_fx[NB_SUBFR], /* o : fractional pitch values Q6 */ + Word16 voicing_fr_fx[NB_SUBFR], /* o : fractional pitch gains Q15 */ + Word16 *loc_harm, /* o : harmonicity flag */ + Word16 *cor_map_sum_fx, /* o : speech/music clasif. parameter Q8 */ + Word16 *vad_flag_dtx, /* o : HE-SAD flag with additional DTX HO */ + float enerBuffer[CLDFB_NO_CHANNELS_MAX], /* o : energy buffer */ + float fft_buff[2 * L_FFT], /* o : FFT buffer */ + Word16 fft_buff_fx[2 * L_FFT], /* o : FFT buffer */ + const Word16 tdm_A_PCh_fx[M + 1], /* i : unq. LP coeff. of primary channel Q12 */ + const Word16 tdm_lsp_new_PCh_fx[M], /* i : unq. LSPs of primary channel Q15 */ + const Word16 currFlatness_fx, /* i : flatness parameter Q7 */ + const Word16 tdm_ratio_idx, /* i : Current Ratio_L index */ + float fr_bands_LR[][2 * NB_BANDS], /* i : energy in frequency bands */ + const Word16 Etot_LR_fx[], /* i : total energy Left & Right channel Q8*/ + float lf_E_LR[][2 * VOIC_BINS], /* i : per bin spectrum energy in lf, LR channels */ + const Word16 localVAD_HE_SAD_LR[], /* i : HE-SAD flag without hangover, LR channels */ + float band_energies_LR[2 * NB_BANDS], /* o : energy in critical bands without minimum noise floor E_MIN */ + const Word16 flag_16k_smc, /* i : flag to indicate if the OL SMC is run at 16 kHz */ + const Word16 front_vad_flag, /* i : front-VAD flag to overwrite VAD decision */ + const Word16 force_front_vad, /* i : flag to force VAD decision */ + const Word16 front_vad_dtx_flag, /* i : front-VAD DTX flag to overwrite VAD decision*/ + const IVAS_FORMAT ivas_format, /* i : IVAS format */ + const Word16 MCT_flag, /* i : hMCT handle allocated (1) or not (0) */ + const Word32 ivas_total_brate /* i : IVAS total bitrate - for setting the DTX */ ) { #ifdef IVAS_FLOAT_FIXED_CONVERSIONS @@ -944,16 +945,6 @@ ivas_error pre_proc_front_ivas_fx( f2me_buf_16( st->inp_12k8_mem_stereo_sw, st->inp_12k8_mem_stereo_sw_fx, &inp_12k8_mem_stereo_sw_e, 4 ); f2me_16( st->mem_preemph_DFT, &st->mem_preemph_DFT_fx, &mem_preemph_DFT_e ); f2me_16( st->mem_preemph, &st->mem_preemph_fx, &mem_preemph_e ); - Word16 relE_fx; - Word16 old_wsp_fx[L_WSP]; - Word16 pitch_fr_fx[NB_SUBFR]; - Word16 voicing_fr_fx[NB_SUBFR]; - Word16 A_fx[NB_SUBFR16k * ( M + 1 )]; - Word16 epsP_h[M + 1]; /* o : LP prediction errors */ - Word16 epsP_l[M + 1]; /* o : LP prediction errors */ - Word16 cor_map_sum16_fx; /* o : speech/music clasif. parameter */ - Word32 fr_bands_LR_fx[2][2 * NB_BANDS]; -#endif // IVAS_FLOAT_FIXED_TO_BE_REMOVED float *inp_12k8, *new_inp_12k8; /* pointers to current frame and new data */ float *wsp; /* weighted input signal buffer */ float Etot; /* total energy */ @@ -963,72 +954,41 @@ ivas_error pre_proc_front_ivas_fx( float tmpE[NB_BANDS]; /* Temporary averaged energy of 2 sf. */ float tmpN_LR[CPE_CHANNELS][NB_BANDS]; /* Temporary noise update */ float tmpE_LR[CPE_CHANNELS][NB_BANDS]; /* Temporary averaged energy of 2 sf. */ - float cor_map_sum_LR[CPE_CHANNELS]; /* speech/music clasif. parameter */ - // float non_staX_LR; /* non-stationarity for sp/mus classifier */ - // float ncharX_LR; /* noise character for sp/mus classifier */ - // float sp_div_LR; /* spectral diversity feature */ - float S_map_LR[L_FFT / 2]; /* short-term correlation map */ - float corr_shiftL; /* correlation shift */ - float corr_shiftR; /* correlation shift */ - // Word16 loc_harmLR[CPE_CHANNELS]; /* harmonicity flag */ + float PS[128]; /* speech/music clasif. parameters */ + float hp_E[2]; /* Energy in HF */ + float band_energies[2 * NB_BANDS]; /* energy in critical bands without minimum noise floor E_MIN */ + float *res_cod_SNR_M, tmpF[STEREO_DFT_BAND_MAX]; +#endif // IVAS_FLOAT_FIXED_TO_BE_REMOVED + + Word16 old_wsp_fx[L_WSP]; + Word16 epsP_h[M + 1]; /* o : LP prediction errors */ + Word16 epsP_l[M + 1]; /* o : LP prediction errors */ + Word32 fr_bands_LR_fx[2][2 * NB_BANDS]; Word16 lr_vad_enabled; /* LR VAD indicator */ - float ee[2]; /* Spectral tilt */ - float corr_shift; /* correlation shift */ - float sp_div, PS[128]; /* speech/music clasif. parameters */ Word16 L_look; /* length of look-ahead */ -#if 0 - float mem_decim_dummy[2 * L_FILT_MAX]; /* dummy decimation filter memory */ - float temp1F_icatdmResampBuf[L_FILT_MAX]; /* temp buffers for ICA TDM resamplers */ -#endif - float hp_E[2]; /* Energy in HF */ Word16 flag_spitch; Word16 high_lpn_flag; - float lsf_new[M]; - Word32 lsf_new_fx[M]; - float band_energies[2 * NB_BANDS]; /* energy in critical bands without minimum noise floor E_MIN */ -#if 0 - Word32 band_energies_fx[2 * NB_BANDS]; /* energy in critical bands without minimum noise floor E_MIN */ -#endif + Word16 lsf_new_fx[M]; // Q2.56 Word16 localVAD_HE_SAD; - float non_staX; - Word16 currFlatness_fx; - Word32 non_staX_fx; - float stab_fac; + Word16 non_staX_fx; Word16 alw_pitch_lag_12k8[2]; Word16 alw_voicing_fx[2]; Word16 last_core_orig; - // float dummy; - float S_map[L_FFT / 2]; - // Word16 S_map_fx[L_FFT / 2]; Word16 i, lMemRecalc, lMemRecalc_12k8; Word16 smc_dec; - // float dE1X; - // float ncharX; - // Encoder_State *st; - // float *signal_in; Word16 element_mode; Word32 input_Fs, last_element_brate; Word16 *tdm_SM_last_clas, tmpS; - float *res_cod_SNR_M, tmpF[STEREO_DFT_BAND_MAX]; STEREO_CLASSIF_HANDLE hStereoClassif; Word16 old_pitch1; /* previous frame OL pitch[1] @12.8 kHz */ Word16 LR_localVAD; ivas_error error; Word32 epsP_fx[17]; /*to be removed later*/ - Word32 cor_map_sum_fx; push_wmops( "pre_proc_front" ); Word16 *signal_in_fx; -#if 0 - Word16 *lgBin_E_fx; - Word32 PS_fx[128]; - Word32 lf_E_fx[2 * VOIC_BINS]; /* per bin spectrum energy in lf */ -#endif Word32 *signal32_in_fx; -#if 0 - Word16 *inp_12k8_fx; -#endif Word16 *inp_12k8_fx, *new_inp_12k8_fx; /* pointers to current frame and new data */ CLDFB_SCALE_FACTOR cldfbScale; Word32 *enerBuffer_fx; @@ -1036,9 +996,6 @@ ivas_error pre_proc_front_ivas_fx( Word16 *temp1F_icatdmResampBuf_fx; Word16 *old_inp_16k_fx; Word16 *mem_decim_dummy_fx; /* dummy decimation filter memory */ -#if 1 - Word16 Etot_16fx; /* total energy, Q8 */ -#endif Word32 tmpF_fx[STEREO_DFT_BAND_MAX]; #ifndef REMOVE_IVAS_UNUSED_PARAMETERS_WARNING Word32 *res_cod_SNR_M_fx; @@ -1047,37 +1004,26 @@ ivas_error pre_proc_front_ivas_fx( Word16 new_inp_out_size; Word16 Q_new_inp; Word16 mem_decim_size; - // Word16 *wsp_fx; - // Word16 pitch_fr_fx[NB_SUBFR]; - // Word16 voicing_fr_fx[NB_SUBFR]; #ifndef REMOVE_IVAS_UNUSED_PARAMETERS_WARNING Word16 Q_new; Word16 corr_shift_fx; #endif -#if 0 - Word16 Q_exp; - Word32 Le_min_scaled; - Word16 relE_fx; -#endif Word16 dummy_fx; Word16 ncharX_fx; Word16 ncharX_LR_fx; /* noise character for sp/mus classifier */ Word16 loc_harmLR_fx[CPE_CHANNELS]; /* harmonicity flag */ - Word16 non_staX16_fx; - Word16 non_staX_LR_fx; /* non-stationarity for sp/mus classifier */ - Word32 sp_div_fx; - Word16 sp_div16_fx; + Word16 non_staX_LR_fx; /* non-stationarity for sp/mus classifier */ + Word16 sp_div_fx; Word16 q_sp_div; Word16 sp_div_LR_fx; Word16 q_sp_div_LR; Word16 *wsp_fx; Word32 dE1X_fx; - Word16 Etot_LR_fx[2]; Word16 S_map_fx[L_FFT / 2]; Word16 cor_map_sum_LR_fx[CPE_CHANNELS]; /* speech/music clasif. parameter */ Word16 S_map_LR_fx[L_FFT / 2]; /* short-term correlation map */ - Word32 Etot_fx; /* total energy */ + Word16 Etot_fx; /* total energy Q8 */ Word32 tmpN_fx[NB_BANDS]; /* Temporary noise update */ Word32 tmpE_fx[NB_BANDS]; /* Temporary averaged energy of 2 sf. */ Word32 tmpN_LR_fx[CPE_CHANNELS][NB_BANDS]; /* Temporary noise update */ @@ -1090,6 +1036,8 @@ ivas_error pre_proc_front_ivas_fx( Word32 lf_E_fx[2 * VOIC_BINS]; /* per bin spectrum energy in lf */ Word32 lf_E_LR_fx[2][2 * VOIC_BINS]; /* per bin spectrum energy in lf */ Word32 hp_E_fx[2]; /* Energy in HF */ + Word16 realBuffer16[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; + Word16 imagBuffer16[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; enerBuffer_exp = 0; move16(); @@ -1098,18 +1046,12 @@ ivas_error pre_proc_front_ivas_fx( mem_decim_dummy_fx = (Word16 *) malloc( 90 * sizeof( Word16 * ) ); temp1F_icatdmResampBuf_fx = (Word16 *) malloc( 45 * sizeof( Word16 * ) ); set16_fx( fft_buff_fx, 0, 512 ); - Word16 realBuffer16[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; - Word16 imagBuffer16[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; - Word32 realBuffer_fx[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; #ifdef MSAN_FIX - for ( Word16 k = 0; k < CLDFB_NO_COL_MAX; k++ ) + FOR( Word16 k = 0; k < CLDFB_NO_COL_MAX; k++ ) { set32_fx( realBuffer_fx[k], 0, CLDFB_NO_CHANNELS_MAX ); } -#endif - Word32 imagBuffer_fx[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; -#ifdef MSAN_FIX - for ( Word16 k = 0; k < CLDFB_NO_COL_MAX; k++ ) + FOR( Word16 k = 0; k < CLDFB_NO_COL_MAX; k++ ) { set32_fx( imagBuffer_fx[k], 0, CLDFB_NO_CHANNELS_MAX ); } @@ -1133,7 +1075,7 @@ ivas_error pre_proc_front_ivas_fx( move16(); tdm_SM_last_clas = &tmpS; -#ifdef IVAS_FLOAT_FIXED_TO_BE_REMOVED +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS set_f( tmpF, 0, STEREO_DFT_BAND_MAX ); res_cod_SNR_M = tmpF; #endif // IVAS_FLOAT @@ -1239,15 +1181,8 @@ ivas_error pre_proc_front_ivas_fx( localVAD_HE_SAD = 0; move16(); -#if 1 - corr_shiftL = 0; - corr_shiftR = 0; -#endif // DEBUG - -#if 1 snr_sum_he_fx = 0; move16(); -#endif corr_shiftL_fx = 0; corr_shiftR_fx = 0; @@ -1271,6 +1206,7 @@ ivas_error pre_proc_front_ivas_fx( move16(); } *attack_flag = 0; + move16(); IF( st->Opt_SC_VBR ) { @@ -1287,7 +1223,7 @@ ivas_error pre_proc_front_ivas_fx( L_look = L_LOOK_12k8; /* lookahead at 12.8kHz */ move16(); -#ifdef IVAS_FLOAT_FIXED_TO_BE_REMOVED +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS new_inp_12k8 = old_inp_12k8 + L_INP_MEM; /* pointer to new samples of the input signal in 12.8kHz core */ // int x = L_INP_MEM - L_look; inp_12k8 = new_inp_12k8 - L_look; /* pointer to the current frame of input signal in 12.8kHz core */ @@ -1295,7 +1231,7 @@ ivas_error pre_proc_front_ivas_fx( new_inp_12k8_fx = old_inp_12k8_fx + L_INP_MEM; /* pointer to new samples of the input signal in 12.8kHz core */ inp_12k8_fx = new_inp_12k8_fx - L_look; /* pointer to the current frame of input signal in 12.8kHz core */ -#ifdef IVAS_FLOAT_FIXED_TO_BE_REMOVED +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS if ( NE_16( element_mode, IVAS_CPE_DFT ) ) { new_inp_12k8 -= L_FILT; @@ -1374,6 +1310,9 @@ ivas_error pre_proc_front_ivas_fx( move16(); } + *q_re_im_buf = sub( 16, cldfbScale.lb_scale ); + move16(); + /*----------------------------------------------------------------* * Change the sampling frequency to 12.8 kHz * (if not available from downsampled DMX) @@ -1460,7 +1399,6 @@ ivas_error pre_proc_front_ivas_fx( #endif // DEBUG #ifndef MSAN_FIX /*To be enabled when updations related to new_inp_12k8_fx is enabled */ -#if 1 IF( EQ_16( element_mode, IVAS_CPE_DFT ) ) { Copy( new_inp_12k8_fx - STEREO_DFT_OVL_12k8, st->buf_speech_enc + L_FRAME32k - STEREO_DFT_OVL_12k8, L_FRAME + STEREO_DFT_OVL_12k8 ); @@ -1476,8 +1414,7 @@ ivas_error pre_proc_front_ivas_fx( Copy( new_inp_12k8_fx, st->buf_speech_enc + L_FRAME32k, L_FRAME ); Scale_sig( st->buf_speech_enc + L_FRAME32k, L_FRAME, 1 ); } -#endif -#endif // !MSAN_FIX +#endif // !MSAN_FIX /*------------------------------------------------------------------* * Perform fixed preemphasis (12.8 kHz signal) through 1 - g*z^-1 *-----------------------------------------------------------------*/ @@ -1577,15 +1514,6 @@ ivas_error pre_proc_front_ivas_fx( fixedToFloat_arr( st->inp_12k8_mem_stereo_sw_fx, st->inp_12k8_mem_stereo_sw, 15 - inp_12k8_mem_stereo_sw_e, STEREO_DFT_OVL_12k8 - L_MEM_RECALC_12K8 - L_FILT ); fixedToFloat_arr( old_inp_12k8_fx, old_inp_12k8, 15 - old_inp_12k8_e, L_INP_MEM + L_FRAME ); // To be removed - /*analysisCldfbEncoder_ivas_fx*/ - for ( i = 0; i < CLDFB_NO_COL_MAX; i++ ) - { - for ( int j = 0; j < CLDFB_NO_CHANNELS_MAX; j++ ) - { - realBuffer[i][j] = fixedToFloat( realBuffer_fx[i][j], 16 - cldfbScale.lb_scale ); - imagBuffer[i][j] = fixedToFloat( imagBuffer_fx[i][j], 16 - cldfbScale.lb_scale ); - } - } cldfbScale.hb_scale = cldfbScale.lb_scale; fixedToFloat_arrL( enerBuffer_fx, enerBuffer, 31 - enerBuffer_exp, 60 ); #endif @@ -1634,8 +1562,7 @@ ivas_error pre_proc_front_ivas_fx( #endif #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - /*float to fix conversions for noise_est_pre_32fx*/ - Etot_fx = (Word32) ( Etot * ( 1 << 24 ) ); + Etot_fx = (Word16) ( Etot * ( 1 << 8 ) ); /*float to fix conversions for wb_vad_ivas_fx*/ Word16 Q_new = Q_factor_arr( fr_bands, 40 ) + 3; @@ -1654,14 +1581,12 @@ ivas_error pre_proc_front_ivas_fx( floatToFixed_arrL( fr_bands_LR[1], fr_bands_LR_fx[1], Q_bands1 + QSCALE, 2 * NB_BANDS ); floatToFixed_arrL( hCPE->hFrontVad[0]->hNoiseEst->bckr, hCPE->hFrontVad[0]->hNoiseEst->bckr_fx, Q_bands0 + QSCALE, NB_BANDS ); floatToFixed_arrL( hCPE->hFrontVad[1]->hNoiseEst->bckr, hCPE->hFrontVad[1]->hNoiseEst->bckr_fx, Q_bands1 + QSCALE, NB_BANDS ); - Etot_LR_fx[0] = float_to_fix16( Etot_LR[0], 8 ); - Etot_LR_fx[1] = float_to_fix16( Etot_LR[1], 8 ); } #endif // IVAS_FLOAT_FIXED_TO_BE_REMOVED IF( hStereoClassif != NULL ) { - IF( GT_32( L_sub( L_shl( st->lp_speech_fx, 16 ), Etot_fx ), 25 << Q24 ) ) /*q24*/ + IF( GT_32( sub( st->lp_speech_fx, Etot_fx ), 25 << Q8 ) ) /*Q8*/ { hStereoClassif->silence_flag = 2; move16(); @@ -1679,7 +1604,7 @@ ivas_error pre_proc_front_ivas_fx( * SAD (1-signal, 0-noise) *----------------------------------------------------------------*/ - noise_est_pre_32fx( Etot_fx, st->ini_frame, st->hNoiseEst, st->idchan, element_mode, hCPE != NULL ? hCPE->last_element_mode : element_mode ); + noise_est_pre_32fx( L_deposit_h( Etot_fx ), st->ini_frame, st->hNoiseEst, st->idchan, element_mode, hCPE != NULL ? hCPE->last_element_mode : element_mode ); test(); test(); @@ -1780,8 +1705,8 @@ ivas_error pre_proc_front_ivas_fx( *----------------------------------------------------------------*/ Word32 Le_min_scaled = L_shr_r( L_add( L_shr( E_MIN_FXQ15, sub( 14, add( Q_new, QSCALE ) ) ), 1 ), 1 ); - Etot_16fx = extract_h( Etot_fx ); /*q24 to q8*/ - noise_est_down_fx( fr_bands_fx, st->hNoiseEst->bckr_fx, tmpN_fx, tmpE_fx, st->min_band, st->max_band, &st->hNoiseEst->totalNoise_fx, Etot_16fx, &st->hNoiseEst->Etot_last_fx, &st->hNoiseEst->Etot_v_h2_fx, Q_new, Le_min_scaled ); + + noise_est_down_fx( fr_bands_fx, st->hNoiseEst->bckr_fx, tmpN_fx, tmpE_fx, st->min_band, st->max_band, &st->hNoiseEst->totalNoise_fx, Etot_fx, &st->hNoiseEst->Etot_last_fx, &st->hNoiseEst->Etot_v_h2_fx, Q_new, Le_min_scaled ); test(); IF( lr_vad_enabled && st->idchan == 0 ) @@ -1812,39 +1737,27 @@ ivas_error pre_proc_front_ivas_fx( fixedToFloat_arrL( tmpE_LR_fx[0], tmpE_LR[0], Q_bands0 + QSCALE, 20 ); fixedToFloat_arrL( tmpN_LR_fx[1], tmpN_LR[1], Q_bands1 + QSCALE, 20 ); fixedToFloat_arrL( tmpE_LR_fx[1], tmpE_LR[1], Q_bands1 + QSCALE, 20 ); - - // performing fix to float conversion of (corr_shift_fx) - corr_shiftL = fix16_to_float( corr_shiftL_fx, 15 ); - corr_shiftR = fix16_to_float( corr_shiftR_fx, 15 ); } #endif - *relE = Etot - st->lp_speech; + *relE_fx = sub( Etot_fx, st->lp_speech_fx ); + move16(); -#ifndef IVAS_FLOAT_FIXED - corr_shift = correlation_shift( st->hNoiseEst->totalNoise ); -#else corr_shift_fx = correlation_shift_fx( st->hNoiseEst->totalNoise_fx ); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - // performing fix to float conversion of (corr_shift_fx) - corr_shift = fix16_to_float( corr_shift_fx, 15 ); -#endif -#endif /*----------------------------------------------------------------* * FD-CNG Noise Estimator *----------------------------------------------------------------*/ - if ( st->hFdCngEnc != NULL ) + IF( st->hFdCngEnc != NULL ) { -#ifdef IVAS_FLOAT_FIXED resetFdCngEnc_fx( st ); -#else - resetFdCngEnc( st ); -#endif - if ( st->idchan == 0 || element_mode == IVAS_CPE_MDCT ) + test(); + IF( st->idchan == 0 || EQ_16( element_mode, IVAS_CPE_MDCT ) ) { - if ( element_mode == IVAS_CPE_TD && lr_vad_enabled && band_energies_LR != NULL ) + test(); + test(); + IF( EQ_16( element_mode, IVAS_CPE_TD ) && lr_vad_enabled && band_energies_LR != NULL ) { #ifdef IVAS_FLOAT_FIXED_CONVERSIONS Word32 band_energies_LR_fx[2 * NB_BANDS] = { 0 }; /* energy in critical bands without minimum noise floor E_MIN */ @@ -1962,49 +1875,67 @@ ivas_error pre_proc_front_ivas_fx( /*-----------------------------------------------------------------* * Select SID or FRAME_NO_DATA frame if DTX enabled *-----------------------------------------------------------------*/ - - if ( hCPE != NULL && element_mode != IVAS_CPE_DFT && element_mode != IVAS_CPE_MDCT ) + test(); + test(); + if ( hCPE != NULL && NE_16( element_mode, IVAS_CPE_DFT ) && NE_16( element_mode, IVAS_CPE_MDCT ) ) { *vad_flag_dtx = 1; + move16(); } - if ( st->Opt_DTX_ON == 1 && *vad_flag_dtx == 0 && element_mode == IVAS_CPE_DFT && element_brate <= ACELP_16k40 && hCPE->hStereoDft->hConfig->force_mono_transmission == 1 ) /* force LP_CNG usage for MASA DTX when mono tranmission */ + test(); + test(); + test(); + test(); + if ( EQ_16( st->Opt_DTX_ON, 1 ) && *vad_flag_dtx == 0 && EQ_16( element_mode, IVAS_CPE_DFT ) && LE_32( element_brate, ACELP_16k40 ) && EQ_16( hCPE->hStereoDft->hConfig->force_mono_transmission, 1 ) ) /* force LP_CNG usage for MASA DTX when mono tranmission */ { st->cng_type = LP_CNG; + move16(); } -#ifndef IVAS_FLOAT_FIXED - dtx( st, ivas_total_brate, *vad_flag_dtx, inp_12k8 ); -#else #ifdef IVAS_FLOAT_FIXED_CONVERSIONS Word16 Q_inp_12k8 = Q_factor_arr( inp_12k8, L_FRAME ); floatToFixed_arr( inp_12k8, inp_12k8_fx, Q_inp_12k8, L_FRAME ); - // Q_lp_noise = Q_factor( st->lp_noise ); #endif dtx_ivas_fx( st, ivas_total_brate, *vad_flag_dtx, inp_12k8_fx, Q_inp_12k8 ); -#endif - if ( hCPE != NULL && hCPE->hStereoDft != NULL && st->core_brate == SID_2k40 ) + + test(); + test(); + IF( hCPE != NULL && hCPE->hStereoDft != NULL && EQ_32( st->core_brate, SID_2k40 ) ) { /* Add another period of expected xcorr updates */ - hCPE->hStereoDft->expectedNumUpdates += st->hDtxEnc->max_SID; + hCPE->hStereoDft->expectedNumUpdates = add( hCPE->hStereoDft->expectedNumUpdates, st->hDtxEnc->max_SID ); + move16(); } /*----------------------------------------------------------------* * Adjust FD-CNG Noise Estimator *----------------------------------------------------------------*/ - - if ( st->hFdCngEnc != NULL && ( st->ini_frame == 0 || last_element_brate != element_brate || st->last_bwidth != st->bwidth ) ) + test(); + test(); + test(); + IF( st->hFdCngEnc != NULL && ( st->ini_frame == 0 || NE_32( last_element_brate, element_brate ) || NE_16( st->last_bwidth, st->bwidth ) ) ) { - int32_t total_brate; + Word32 total_brate; - total_brate = ( element_mode == IVAS_SCE ) ? st->total_brate : st->bits_frame_nominal * FRAMES_PER_SEC; + IF( EQ_16( element_mode, IVAS_SCE ) ) + { + total_brate = st->total_brate; + move32(); + } + ELSE + { + total_brate = imult3216( FRAMES_PER_SEC, st->bits_frame_nominal ); + } configureFdCngEnc( st->hFdCngEnc, max( st->input_bwidth, WB ), total_brate ); - configureFdCngEnc_ivas_fx( st->hFdCngEnc, max( st->input_bwidth, WB ), total_brate ); - if ( hCPE != NULL ) + configureFdCngEnc_ivas_fx( st->hFdCngEnc, s_max( st->input_bwidth, WB ), total_brate ); + IF( hCPE != NULL ) { - st->hFdCngEnc->hFdCngCom->CngBitrate = hCPE->element_brate - 1; + st->hFdCngEnc->hFdCngCom->CngBitrate = L_sub( hCPE->element_brate, 1 ); + move32(); } } + test(); IF( st->hFdCngEnc != NULL && st->Opt_DTX_ON ) { Word16 zero_flag = 0, msPeriodog_fx_Q = Q31; @@ -2020,6 +1951,7 @@ ivas_error pre_proc_front_ivas_fx( st->hFdCngEnc->msPeriodog_fx_exp = sub( 31, msPeriodog_fx_Q ); Word16 energy_ho_fx_Q = Q31; + move16(); zero_flag = get_zero_flag( st->hFdCngEnc->energy_ho_fx, NPART ); IF( zero_flag ) { @@ -2030,6 +1962,7 @@ ivas_error pre_proc_front_ivas_fx( st->hFdCngEnc->energy_ho_fx_exp = st->hFdCngEnc->energy_ho_fx_exp - energy_ho_fx_Q; Word16 msNoiseEst_old_Q = Q31; + move16(); zero_flag = get_zero_flag( st->hFdCngEnc->msNoiseEst_old_fx, NPART ); IF( zero_flag ) { @@ -2053,13 +1986,9 @@ ivas_error pre_proc_front_ivas_fx( Word16 *inp_12k8_loc_fx, *new_inp_12k8_loc_fx; /* pointers to current frame and new data */ new_inp_12k8_loc_fx = old_inp_12k8_loc_fx + L_INP_MEM; /* pointer to new samples of the input signal in 12.8kHz core */ inp_12k8_loc_fx = new_inp_12k8_loc_fx - L_look; /* pointer to the current frame of input signal in 12.8kHz core */ - Word16 lsp_new_loc_fx[M]; - Word16 lsp_mid_loc_fx[M]; - Word16 lsf_new_16_loc_fx[M]; Word16 stab_fac_fx; Word16 Q_new_loc; Word16 Q_r[2] = { 0 }; - Word16 A_loc_fx[NB_SUBFR16k * ( M + 1 )] = { 0 }; Word16 epsP_l_loc[M + 1]; Word16 epsP_h_loc[M + 1]; Word32 ener_fx; @@ -2077,10 +2006,6 @@ ivas_error pre_proc_front_ivas_fx( { old_inp_12k8_loc_fx[idx] = (Word16) ( old_inp_12k8[idx] * ( 1 << Q_new_loc ) ); } - for ( int idx = 0; idx < M; idx++ ) - { - lsp_new_loc_fx[idx] = (Word16) ( lsp_new[idx] * 32767 ); - } for ( int idx = 0; idx < 3; idx++ ) { st->voicing_fx[idx] = (Word16) ( st->voicing[idx] * 32767 ); @@ -2107,14 +2032,14 @@ ivas_error pre_proc_front_ivas_fx( move16(); } - analy_lp_ivas_fx( inp_12k8_loc_fx, L_FRAME, L_look, &ener_fx, A_loc_fx, epsP_h_loc, epsP_l_loc, lsp_new_loc_fx, lsp_mid_loc_fx, st->lsp_old1_fx, alw_pitch_lag_12k8, alw_voicing_fx, + analy_lp_ivas_fx( inp_12k8_loc_fx, L_FRAME, L_look, &ener_fx, A_fx, epsP_h_loc, epsP_l_loc, lsp_new_fx, lsp_mid_fx, st->lsp_old1_fx, alw_pitch_lag_12k8, alw_voicing_fx, INT_FS_12k8, i, Q_new_loc, Q_r ); - lsp2lsf_fx( lsp_new_loc_fx, lsf_new_16_loc_fx, M, INT_FS_12k8 ); + lsp2lsf_fx( lsp_new_fx, lsf_new_fx, M, INT_FS_12k8 ); - stab_fac_fx = lsf_stab_fx( lsf_new_16_loc_fx, st->lsf_old1_fx, 0, L_FRAME ); + stab_fac_fx = lsf_stab_fx( lsf_new_fx, st->lsf_old1_fx, 0, L_FRAME ); - Copy( lsf_new_16_loc_fx, st->lsf_old1_fx, M ); + Copy( lsf_new_fx, st->lsf_old1_fx, M ); #ifdef IVAS_FLOAT_FIXED_CONVERSIONS float power_2 = powf( 2.0, (float) ( Q_r[0] + 1 ) ); @@ -2128,20 +2053,6 @@ ivas_error pre_proc_front_ivas_fx( check_float = (float) ener_fx / power_2; *ener = check_float; - for ( int idx = 0; idx < M; idx++ ) - { - - lsp_new[idx] = (float) lsp_new_loc_fx[idx] / 32767.0f; - lsp_mid[idx] = (float) lsp_mid_loc_fx[idx] / 32767.0f; - lsf_new[idx] = (float) ( (float) lsf_new_16_loc_fx[idx] / 2.56f ); - } - for ( int idx = 0; idx < NB_SUBFR16k * ( M + 1 ); idx++ ) - { - A[idx] = (float) ( (float) A_loc_fx[idx] / 16384.0f ); - } - - stab_fac = (float) ( (float) stab_fac_fx / 32767.0f ); - free( old_inp_12k8_loc_fx ); #endif @@ -2151,33 +2062,14 @@ ivas_error pre_proc_front_ivas_fx( * Comparison of the LP coefficents to determine if it is possible * to reuse the primary channel LP coefficients in the secondary channel *----------------------------------------------------------------*/ -#ifdef IVAS_FLOAT_FIXED - Word32 isp_PCh_fx[M]; - Word32 isp_SCh_fx[M]; - Word16 A_SCh_fx[M + 1]; - Word16 A_PCh_fx[M + 1]; - Word32 speech_buff[L_FRAME + M]; #ifdef IVAS_FLOAT_FIXED_CONVERSIONS + Word32 speech_buff[L_FRAME + M]; Word16 Q_speech = Q_factor_arrL( inp_12k8 - M, L_FRAME + M ); Word16 gb1 = find_guarded_bits_fx( M ); floatToFixed_arr32( inp_12k8 - M, speech_buff, Q_speech - gb1, L_FRAME + M ); - for ( i = 0; i < M + 1; i++ ) - { - A_PCh_fx[i] = (Word16) ( tdm_A_PCh[i] * ONE_IN_Q12 ); - A_SCh_fx[i] = (Word16) ( A[i] * ONE_IN_Q12 ); - } - - for ( i = 0; i < M; i++ ) - { - isp_PCh_fx[i] = (Word32) ( tdm_lsp_new_PCh[i] * MAX_32 ); - isp_SCh_fx[i] = (Word32) ( lsp_new[i] * MAX_32 ); - } -#endif - hCPE->hStereoTD->tdm_lp_reuse_flag = tdm_lp_comparison_fx( hCPE->hStereoTD, hCPE->hStereoClassif, st, &speech_buff[0], A_PCh_fx, A_SCh_fx, M, isp_PCh_fx, isp_SCh_fx, L_FRAME, element_brate - nb_bits_metadata * FRAMES_PER_SEC, Q_speech ); -#else - hCPE->hStereoTD->tdm_lp_reuse_flag = tdm_lp_comparison( hCPE->hStereoTD, hCPE->hStereoClassif, st, inp_12k8, tdm_A_PCh, A, M, tdm_lsp_new_PCh, lsp_new, L_FRAME, element_brate - nb_bits_metadata * FRAMES_PER_SEC ); - #endif + hCPE->hStereoTD->tdm_lp_reuse_flag = tdm_lp_comparison_fx( hCPE->hStereoTD, hCPE->hStereoClassif, st, &speech_buff[0], tdm_A_PCh_fx, A_fx, M, tdm_lsp_new_PCh_fx, lsp_new_fx, L_FRAME, L_sub( element_brate, imult3216( FRAMES_PER_SEC, nb_bits_metadata ) ), Q_speech ); + move16(); } /*----------------------------------------------------------------* @@ -2187,15 +2079,11 @@ ivas_error pre_proc_front_ivas_fx( * 1/4 pitch precision improvement *----------------------------------------------------------------*/ -#ifdef IVAS_FLOAT_FIXED #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - Word16 Aw_fx[NB_SUBFR16k * ( M + 1 )] = { 0 }; Word16 buf[15000] = { 0 }; Word16 *inp_12k8_fx1 = &buf[M]; // this is done because find_wsp accesses inp from -16 index Word16 wsp_fx1[L_FRAME + L_LOOK_12k8] = { 0 }; - floatToFixed_arr16( A, A_fx, Q12, NB_SUBFR16k * ( M + 1 ) ); - Word16 e1, e2, q_inp_12k8; f2me_buf_16( inp_12k8 - M, inp_12k8_fx1, &e1, 368 + M ); f2me_buf_16( &st->mem_wsp, &st->mem_wsp_fx, &e2, 1 ); @@ -2216,13 +2104,6 @@ ivas_error pre_proc_front_ivas_fx( } #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - FOR( i = 0; i < ( NB_SUBFR16k - 1 ); i++ ) - { - FOR( int j = 0; j < M + 1; j++ ) - { - Aw[i * ( M + 1 ) + j] = (float) Aw_fx[i * ( M + 1 ) + j] / Aw_fx[i * ( M + 1 )]; - } - } FOR( i = 0; i < L_FRAME + L_LOOK_12k8; i++ ) { wsp[i] = fixedToFloat( wsp_fx1[i], q_inp_12k8 ); @@ -2230,18 +2111,8 @@ ivas_error pre_proc_front_ivas_fx( st->mem_wsp = fixedToFloat( st->mem_wsp_fx, q_inp_12k8 ); #endif -#else - find_wsp( L_FRAME, L_SUBFR, NB_SUBFR, A, Aw, inp_12k8, TILT_FAC, wsp, &st->mem_wsp, GAMMA1_FLT, L_look ); - - if ( st->vad_flag == 0 ) - { - /* reset the OL pitch tracker memories during inactive frames */ - pitch_ol_init( &st->old_thres, &st->old_pitch, &st->delta_pit, &st->old_corr ); - } -#endif - old_pitch1 = st->pitch[1]; - + move16(); #ifdef IVAS_FLOAT_FIXED Word16 exp_wsp = 0, Q_wsp = 0; @@ -2251,25 +2122,21 @@ ivas_error pre_proc_front_ivas_fx( Copy( st->old_wsp_fx, old_wsp_fx, L_WSP_MEM ); wsp_fx = old_wsp_fx + L_WSP_MEM; floatToFixed_arr( st->voicing, st->voicing_fx, Q15, 3 ); - corr_shift_fx = (Word16) floatToFixed( corr_shift, Q15 ); f2me_buf_16( wsp, wsp_fx, &exp_wsp, L_WSP - L_WSP_MEM ); Q_wsp = sub( 15, exp_wsp ); floatToFixed_arr( wsp, wsp_fx, Q_wsp, L_WSP - L_WSP_MEM ); floatToFixed_arr( st->old_wsp2, st->old_wsp2_fx, Q_wsp, 115 ); floatToFixed_arr( st->mem_decim2, st->mem_decim2_fx, Q_wsp, 3 ); - relE_fx = (Word16) floatToFixed( *relE, Q8 ); #endif pitch_ol_ivas_fx( st->pitch, st->voicing_fx, &st->old_pitch, &st->old_corr_fx, corr_shift_fx, &st->old_thres_fx, - &st->delta_pit, st->old_wsp2_fx, wsp_fx, st->mem_decim2_fx, relE_fx, st->clas, st->input_bwidth, st->Opt_SC_VBR ); + &st->delta_pit, st->old_wsp2_fx, wsp_fx, st->mem_decim2_fx, *relE_fx, st->clas, st->input_bwidth, st->Opt_SC_VBR ); #ifdef IVAS_FLOAT_FIXED_CONVERSIONS fixedToFloat_arr( st->voicing_fx, st->voicing, Q15, 3 ); - corr_shift = fixedToFloat( corr_shift_fx, Q15 ); fixedToFloat_arr( st->old_wsp2_fx, st->old_wsp2, Q_wsp, 115 ); fixedToFloat_arr( st->mem_decim2_fx, st->mem_decim2, Q_wsp, 3 ); - *relE = fixedToFloat( relE_fx, Q8 ); #endif #else @@ -2277,8 +2144,7 @@ ivas_error pre_proc_front_ivas_fx( #endif /* Updates for adaptive lag window memory */ st->old_pitch_la = st->pitch[2]; - -#ifdef IVAS_FLOAT_FIXED + move16(); #ifdef IVAS_FLOAT_FIXED_CONVERSIONS @@ -2288,10 +2154,6 @@ ivas_error pre_proc_front_ivas_fx( floatToFixed_arr16( st->Bin_E, st->lgBin_E_fx, Q7, L_FFT / 2 ); // Function StableHighPitchDetect_fx excepts st->lgBin_E_fx to be in Q7 - corr_shift_fx = float_to_fix16( corr_shift, Q15 ); - corr_shiftL_fx = float_to_fix16( corr_shiftL, Q15 ); - corr_shiftR_fx = float_to_fix16( corr_shiftR, Q15 ); - Word16 q_fr_bands = Q30; q_fr_bands = min( q_fr_bands, Q_factor_arrL( tmpN, NB_BANDS ) ); q_fr_bands = min( q_fr_bands, Q_factor_arrL( tmpE, NB_BANDS ) ); @@ -2356,23 +2218,12 @@ ivas_error pre_proc_front_ivas_fx( q_inp_12k8 = Q_factor_arr( old_inp_12k8, L_INP_12k8 ); // inp_12k8_fx floatToFixed_arr16( old_inp_12k8, old_inp_12k8_fx, q_inp_12k8, L_INP_12k8 ); - Word16 Etot16_fx = float_to_fix16( Etot, Q8 ); - relE_fx = float_to_fix16( *relE, Q8 ); - Word16 Q_epsp = Q_factor_arrL( epsP, M + 1 ); floatToFixed_arr32( epsP, epsP_fx, Q_epsp, M + 1 ); FOR( Word16 j = 0; j <= M; j++ ) { L_Extract( epsP_fx[j], &epsP_h[j], &epsP_l[j] ); } - - if ( lr_vad_enabled && st->idchan == 0 ) - { - for ( int j = 0; j < 2; j++ ) - { - Etot_LR_fx[j] = float_to_fix16( Etot_LR[j], Q8 ); - } - } #endif // IVAS_FLOAT_FIXED_CONVERSIONS /* Detection of very short stable pitch period */ @@ -2412,8 +2263,8 @@ ivas_error pre_proc_front_ivas_fx( * Update estimated noise energy and voicing cut-off frequency *-----------------------------------------------------------------*/ - noise_est_ivas_fx( st, old_pitch1, tmpN_fx, epsP_h, epsP_l, Etot16_fx, relE_fx, corr_shift_fx, tmpE_fx, fr_bands_fx, &cor_map_sum16_fx, &ncharX_fx, &sp_div16_fx, &q_sp_div, - &non_staX16_fx, loc_harm, lf_E_fx, &st->hNoiseEst->harm_cor_cnt, st->hNoiseEst->Etot_l_lp_fx, st->hNoiseEst->Etot_v_h2_fx, &st->hNoiseEst->bg_cnt, st->lgBin_E_fx, sub( q_fr_bands, QSCALE ), L_shl( E_MIN_IVAS_FX, sub( q_fr_bands, Q19 ) ), &dummy_fx, S_map_fx, hStereoClassif, NULL, st->ini_frame ); + noise_est_ivas_fx( st, old_pitch1, tmpN_fx, epsP_h, epsP_l, Etot_fx, *relE_fx, corr_shift_fx, tmpE_fx, fr_bands_fx, cor_map_sum_fx, &ncharX_fx, &sp_div_fx, &q_sp_div, + &non_staX_fx, loc_harm, lf_E_fx, &st->hNoiseEst->harm_cor_cnt, st->hNoiseEst->Etot_l_lp_fx, st->hNoiseEst->Etot_v_h2_fx, &st->hNoiseEst->bg_cnt, st->lgBin_E_fx, sub( q_fr_bands, QSCALE ), L_shl( E_MIN_IVAS_FX, sub( q_fr_bands, Q19 ) ), &dummy_fx, S_map_fx, hStereoClassif, NULL, st->ini_frame ); test(); IF( lr_vad_enabled && st->idchan == 0 ) @@ -2443,26 +2294,14 @@ ivas_error pre_proc_front_ivas_fx( *-----------------------------------------------------------------*/ find_tilt_ivas_fx( fr_bands_fx, st->hNoiseEst->bckr_fx, ee_fx, st->pitch, st->voicing_fx, lf_E_fx, corr_shift_fx, st->input_bwidth, st->max_band, hp_E_fx, MODE1, q_fr_bands, &( st->bckr_tilt_lt ), st->Opt_SC_VBR ); - st->coder_type = find_uv_ivas_fx( st, pitch_fr_fx, voicing_fr_fx, inp_12k8_fx, ee_fx, &dE1X_fx, corr_shift_fx, relE_fx, Etot16_fx, hp_E_fx, &flag_spitch, last_core_orig, hStereoClassif, q_inp_12k8, q_fr_bands ); + st->coder_type = find_uv_ivas_fx( st, pitch_fr_fx, voicing_fr_fx, inp_12k8_fx, ee_fx, &dE1X_fx, corr_shift_fx, *relE_fx, Etot_fx, hp_E_fx, &flag_spitch, last_core_orig, hStereoClassif, q_inp_12k8, q_fr_bands ); #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - fixedToFloat_arr( pitch_fr_fx, pitch_fr, Q6, NB_SUBFR ); - fixedToFloat_arr( voicing_fr_fx, voicing_fr, Q15, NB_SUBFR ); - - fixedToFloat_arrL32( ee_fx, ee, Q6, 2 ); fixedToFloat_arrL32( hp_E_fx, hp_E, q_fr_bands, 2 ); - - non_staX = fixedToFloat_16( non_staX16_fx, Q8 ); - sp_div = fixedToFloat_16( sp_div16_fx, q_sp_div ); - *cor_map_sum = fixedToFloat_16( cor_map_sum16_fx, Q8 ); - - fixedToFloat_arr( S_map_fx, S_map, Q7, L_FFT / 2 ); fixedToFloat_arr( st->lgBin_E_fx, st->Bin_E, Q7, L_FFT / 2 ); if ( lr_vad_enabled && st->idchan == 0 ) { - fixedToFloat_arr( cor_map_sum_LR_fx, cor_map_sum_LR, Q8, 2 ); - fixedToFloat_arr( S_map_LR_fx, S_map_LR, Q7, L_FFT / 2 ); for ( int j = 0; j < 2; j++ ) { fixedToFloat_arrL32( hCPE->hFrontVad[j]->hNoiseEst->bckr_fx, hCPE->hFrontVad[j]->hNoiseEst->bckr, q_fr_bands, NB_BANDS ); @@ -2478,71 +2317,6 @@ ivas_error pre_proc_front_ivas_fx( fixedToFloat_arrL32( st->hNoiseEst->ave_enr_fx, st->hNoiseEst->ave_enr, q_fr_bands, NB_BANDS ); fixedToFloat_arrL32( st->hNoiseEst->ave_enr2_fx, st->hNoiseEst->ave_enr2, q_fr_bands, NB_BANDS ); #endif -#else - - /* Detection of very short stable pitch period */ - StableHighPitchDetect( &flag_spitch, st->pitch, st->voicing, st->Bin_E, wsp, st->localVAD, &st->voicing_sm, &st->voicing0_sm, &st->LF_EnergyRatio_sm, &st->predecision_flag, &st->diff_sm, &st->energy_sm ); - - /* 1/4 pitch precision improvement */ - if ( element_brate <= IVAS_32k ) - { - pitch_ol2( PIT_MIN_EXTEND, st->pitch[0], &pitch_fr[0], &voicing_fr[0], 0, wsp, 7 ); - pitch_ol2( PIT_MIN_EXTEND, st->pitch[0], &pitch_fr[1], &voicing_fr[1], L_SUBFR, wsp, 7 ); - pitch_ol2( PIT_MIN_EXTEND, st->pitch[1], &pitch_fr[2], &voicing_fr[2], 2 * L_SUBFR, wsp, 7 ); - pitch_ol2( PIT_MIN_EXTEND, st->pitch[1], &pitch_fr[3], &voicing_fr[3], 3 * L_SUBFR, wsp, 7 ); - } - else - { - pitch_fr[0] = st->pitch[0]; - pitch_fr[1] = st->pitch[0]; - pitch_fr[2] = st->pitch[1]; - pitch_fr[3] = st->pitch[1]; - - voicing_fr[0] = st->voicing[0]; - voicing_fr[1] = st->voicing[0]; - voicing_fr[2] = st->voicing[1]; - voicing_fr[3] = st->voicing[1]; - } - - /*------------------------------------------------------------------* - * Update estimated noise energy and voicing cut-off frequency - *-----------------------------------------------------------------*/ - - noise_est( st, old_pitch1, tmpN, epsP, Etot, *relE, corr_shift, tmpE, fr_bands, cor_map_sum, &ncharX, &sp_div, - &non_staX, loc_harm, lf_E, &st->hNoiseEst->harm_cor_cnt, st->hNoiseEst->Etot_l_lp, &dummy /*sp_floor*/, S_map, hStereoClassif, NULL, st->ini_frame ); - - if ( lr_vad_enabled && st->idchan == 0 ) - { - /* Run noise_est for Left and Right channel */ - *loc_harmLR = *loc_harm; - noise_est( st, old_pitch1, tmpN_LR[0], epsP, Etot_LR[0], Etot_LR[0] - hCPE->hFrontVad[0]->lp_speech, corr_shiftL, tmpE_LR[0], fr_bands_LR[0], &cor_map_sum_LR[0], &ncharX_LR, &sp_div_LR, - &non_staX_LR, loc_harmLR, lf_E_LR[0], &hCPE->hFrontVad[0]->hNoiseEst->harm_cor_cnt, hCPE->hFrontVad[0]->hNoiseEst->Etot_l_lp, &dummy, S_map_LR, NULL, hCPE->hFrontVad[0], hCPE->hFrontVad[0]->ini_frame ); - - /* Note: the index [0] in the last argument is intended, the ini_frame counter is only maintained in the zero-th channel's VAD handle */ - noise_est( st, old_pitch1, tmpN_LR[1], epsP, Etot_LR[1], Etot_LR[1] - hCPE->hFrontVad[1]->lp_speech, corr_shiftR, tmpE_LR[1], fr_bands_LR[1], &cor_map_sum_LR[1], &ncharX_LR, &sp_div_LR, - &non_staX_LR, loc_harmLR, lf_E_LR[1], &hCPE->hFrontVad[1]->hNoiseEst->harm_cor_cnt, hCPE->hFrontVad[1]->hNoiseEst->Etot_l_lp, &dummy, S_map_LR, NULL, hCPE->hFrontVad[1], hCPE->hFrontVad[0]->ini_frame ); - } - - /*------------------------------------------------------------------* - * Update parameters used in the VAD and DTX - *-----------------------------------------------------------------*/ - - vad_param_updt( st, corr_shift, corr_shift, A, old_pitch1, NULL, 1 ); - - if ( lr_vad_enabled && st->idchan == 0 ) - { - vad_param_updt( st, corr_shiftL, corr_shiftR, A, old_pitch1, &hCPE->hFrontVad[0], CPE_CHANNELS ); - } - - /*-----------------------------------------------------------------* - * Find spectral tilt - * UC and VC frame selection - *-----------------------------------------------------------------*/ - - find_tilt( fr_bands, st->hNoiseEst->bckr, ee, st->pitch, st->voicing, lf_E, corr_shift, st->input_bwidth, st->max_band, hp_E, MODE1, &( st->bckr_tilt_lt_flt ), st->Opt_SC_VBR ); - - st->coder_type = find_uv( st, pitch_fr, voicing_fr, inp_12k8, ee, &dE1X, corr_shift, *relE, Etot, hp_E, &flag_spitch, last_core_orig, hStereoClassif ); -#endif // IVAS_FLOAT_FIXED /*-----------------------------------------------------------------* * channel aware mode configuration * @@ -2550,138 +2324,95 @@ ivas_error pre_proc_front_ivas_fx( st->rf_mode = 0; st->rf_target_bits_write = 0; + move16(); + move16(); /*-----------------------------------------------------------------* * Signal classification for FEC * TC frame selection *-----------------------------------------------------------------*/ -#ifdef IVAS_FLOAT_FIXED #ifdef IVAS_FLOAT_FIXED_CONVERSIONS Word16 oi12k8_fx[L_INP_12k8]; floatToFixed_arr( old_inp_12k8, oi12k8_fx, 0, L_INP_12k8 ); // Q_fac doesn't matter as it is only being used for sign Word16 *ni12k8_fx = oi12k8_fx + L_INP_MEM; inp_12k8_fx = ni12k8_fx - L_look; - floatToFixed_arrL( ee, ee_fx, Q6, 2 ); - relE_fx = float_to_fix16( *relE, Q8 ); floatToFixed_arr( st->voicing, st->voicing_fx, Q15, 3 ); #endif - st->clas = signal_clas_fx( st, inp_12k8_fx, ee_fx, relE_fx, L_look, tdm_SM_last_clas ); + st->clas = signal_clas_fx( st, inp_12k8_fx, ee_fx, *relE_fx, L_look, tdm_SM_last_clas ); #ifdef IVAS_FLOAT_FIXED_CONVERSIONS fixedToFloat_arr( st->voicing_fx, st->voicing, Q15, 3 ); #endif -#else - st->clas = signal_clas( st, inp_12k8, ee, *relE, L_look, tdm_SM_last_clas ); -#endif -#ifndef IVAS_FLOAT_FIXED - select_TC( MODE1, st->tc_cnt, &st->coder_type, st->localVAD ); -#else + select_TC_fx( MODE1, st->tc_cnt, &st->coder_type, st->localVAD ); -#endif + if ( st->Opt_SC_VBR ) { st->hSC_VBR->Local_VAD = st->localVAD; + move16(); } /*-----------------------------------------------------------------* * Collect stereo classifier features *-----------------------------------------------------------------*/ -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - Word16 cor_map_sum_e; - f2me( *cor_map_sum, &cor_map_sum_fx, &cor_map_sum_e ); -#endif - if ( hStereoClassif != NULL ) + IF( hStereoClassif != NULL ) { -#if 1 #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - Word16 non_staX_e, sp_div_e, epsP_e, max_e_Etot; - floatToFixed_arr32( lsf_new, lsf_new_fx, Q15, M ); - f2me_buf_16( st->voicing, st->voicing_fx, &st->voicing_e, 3 ); - f2me( non_staX, &non_staX_fx, &non_staX_e ); + Word16 epsP_e, max_e_Etot; + floatToFixed_arr( st->voicing, st->voicing_fx, Q15, 3 ); f2me_buf( epsP, epsP_fx, &epsP_e, 17 ); - f2me( sp_div, &sp_div_fx, &sp_div_e ); #endif // IVAS_FLOAT_FIXED_CONVERSIONS - max_e_Etot = max( hStereoClassif->e_Etot_buf_fx, max( hStereoClassif->Etot_up_e, hStereoClassif->Etot_dn_e ) ); + + max_e_Etot = s_max( hStereoClassif->e_Etot_buf_fx, s_max( hStereoClassif->Etot_up_e, hStereoClassif->Etot_dn_e ) ); scale_sig32( hStereoClassif->Etot_buf_fx, 3, hStereoClassif->e_Etot_buf_fx - max_e_Etot ); hStereoClassif->Etot_up_fx = L_shr( hStereoClassif->Etot_up_fx, max_e_Etot - hStereoClassif->Etot_up_e ); hStereoClassif->Etot_dn_fx = L_shr( hStereoClassif->Etot_dn_fx, max_e_Etot - hStereoClassif->Etot_dn_e ); hStereoClassif->Etot_up_e = hStereoClassif->Etot_dn_e = hStereoClassif->e_Etot_buf_fx = max_e_Etot; stereo_classifier_features_ivas_fx( hStereoClassif, st->idchan, element_mode, localVAD_HE_SAD, lsf_new_fx, epsP_fx, - st->pitch, st->voicing_fx, cor_map_sum_fx, non_staX_fx, sp_div_fx, - st->clas, epsP_e, st->voicing_e, cor_map_sum_e, non_staX_e, sp_div_e ); - -#else - stereo_classifier_features( hStereoClassif, st->idchan, element_mode, localVAD_HE_SAD, lsf_new, epsP, st->pitch, st->voicing, *cor_map_sum, non_staX, sp_div, st->clas ); -#endif // IVAS_FLOAT_FIXED + st->pitch, st->voicing_fx, *cor_map_sum_fx, non_staX_fx, sp_div_fx, + st->clas, epsP_e, ( 15 - Q8 ) /* exp of cor_map_sum */, ( 15 - Q8 ) /* exp of non_staX_fx */, sub( 15, q_sp_div ) ); } /*----------------------------------------------------------------* * 1st stage speech/music classification (GMM model) *----------------------------------------------------------------*/ -#if 0 - smc_dec = ivas_smc_gmm( st, hStereoClassif, localVAD_HE_SAD, Etot, lsp_new, *cor_map_sum, epsP, PS, non_staX, *relE, &high_lpn_flag, flag_spitch ); -#else +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS SP_MUS_CLAS_HANDLE hSpMusClas = st->hSpMusClas; -#if 1 - Word16 lsp_new_fx[M]; Word32 PS_fx[128]; Word16 Q_esp; - Word16 non_sta_fx = float_to_fix16( non_staX, Q6 ); - Word16 Etot_fx_0 = float_to_fix16( Etot, Q8 ); - floatToFixed_arr( lsp_new, lsp_new_fx, Q15, M ); - relE_fx = float_to_fix16( *relE, 8 ); floatToFixed_arr16( st->voicing, st->voicing_fx, 15, 3 ); Word16 Qfact_PS = Q_factor_arrL( PS, 128 ); floatToFixed_arr32( PS, PS_fx, Qfact_PS, 128 ); Word16 e_esp; f2me_buf( epsP, epsP_fx, &e_esp, M + 1 ); Q_esp = sub( 31, e_esp ); - Word16 Qfact_PS_past = Q_factor_arrL( hSpMusClas->past_PS, 67 ); - floatToFixed_arr32( hSpMusClas->past_PS, hSpMusClas->past_PS_fx, Qfact_PS_past, 67 ); -#endif - smc_dec = ivas_smc_gmm_fx( st, hStereoClassif, localVAD_HE_SAD, Etot_fx_0, lsp_new_fx, extract_l( L_shr( cor_map_sum_fx, sub( 23, cor_map_sum_e ) ) ) /*q8*/, epsP_fx, PS_fx, non_sta_fx, relE_fx, &high_lpn_flag, flag_spitch, Qfact_PS, Q_esp, Qfact_PS_past ); -#if 1 - fixedToFloat_arrL32( hSpMusClas->past_PS_fx, hSpMusClas->past_PS, Qfact_PS_past, 67 ); -#endif #endif - + smc_dec = ivas_smc_gmm_fx( st, hStereoClassif, localVAD_HE_SAD, Etot_fx, lsp_new_fx, *cor_map_sum_fx /*Q8*/, epsP_fx, PS_fx, non_staX_fx, *relE_fx, &high_lpn_flag, flag_spitch, Qfact_PS, Q_esp, hSpMusClas->past_PS_Q ); /*----------------------------------------------------------------* * VAD energy updates * Update of old per-band energy spectrum *----------------------------------------------------------------*/ -#ifndef IVAS_FLOAT_FIXED - long_enr( st, Etot, localVAD_HE_SAD, high_lpn_flag, NULL, 1, NULL, NULL ); -#else #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - // conv params from float to fix - Etot_fx = float_to_fix( Etot, 8 ); - Etot16_fx = extract_l( Etot_fx ); st->lp_speech_fx = float_to_fix16( st->lp_speech, 8 ); #endif - ivas_long_enr_fx( st, Etot16_fx, localVAD_HE_SAD, high_lpn_flag, NULL, 1, NULL, NULL ); + + ivas_long_enr_fx( st, Etot_fx, localVAD_HE_SAD, high_lpn_flag, NULL, 1, NULL, NULL ); + #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - // conv params from fix to float st->lp_speech = fix16_to_float( st->lp_speech_fx, 8 ); #endif -#endif + mvr2r( fr_bands + NB_BANDS, st->hNoiseEst->enrO, NB_BANDS ); - if ( lr_vad_enabled && st->idchan == 0 ) + test(); + IF( lr_vad_enabled && st->idchan == 0 ) { -#ifndef IVAS_FLOAT_FIXED - long_enr( st, -1, localVAD_HE_SAD, high_lpn_flag, hCPE->hFrontVad, CPE_CHANNELS, localVAD_HE_SAD_LR, Etot_LR ); -#else -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - // conv params from float to fix - Etot_LR_fx[0] = float_to_fix16( Etot_LR[0], 8 ); - Etot_LR_fx[1] = float_to_fix16( Etot_LR[1], 8 ); -#endif ivas_long_enr_fx( st, -1, localVAD_HE_SAD, high_lpn_flag, hCPE->hFrontVad, CPE_CHANNELS, localVAD_HE_SAD_LR, Etot_LR_fx ); -#endif + mvr2r( fr_bands_LR[0] + NB_BANDS, hCPE->hFrontVad[0]->hNoiseEst->enrO, NB_BANDS ); mvr2r( fr_bands_LR[1] + NB_BANDS, hCPE->hFrontVad[1]->hNoiseEst->enrO, NB_BANDS ); } @@ -2692,19 +2423,25 @@ ivas_error pre_proc_front_ivas_fx( *----------------------------------------------------------------*/ st->GSC_IVAS_mode = 0; - if ( st->idchan == 1 && element_mode == IVAS_CPE_TD ) + move16(); + test(); + IF( EQ_16( st->idchan, 1 ) && EQ_16( element_mode, IVAS_CPE_TD ) ) { /* No speech/music classification in the secondary channel of TD stereo */ st->sp_aud_decision1 = 0; st->sp_aud_decision2 = 0; + move16(); + move16(); st->GSC_noisy_speech = 0; + move16(); if ( st->hGSCEnc != NULL ) { st->hGSCEnc->noise_lev = NOISE_LEVEL_SP3; + move16(); } } - else if ( element_mode != IVAS_CPE_MDCT ) + ELSE IF( NE_16( element_mode, IVAS_CPE_MDCT ) ) { /* SNR-based speech/music classification */ if ( ( element_mode >= IVAS_CPE_DFT && element_brate >= IVAS_24k4 ) || ( element_mode == IVAS_SCE && element_brate >= SCE_SMC_THR ) ) @@ -2756,47 +2493,24 @@ ivas_error pre_proc_front_ivas_fx( /* these are for ivas_acelp_tcx20_switching_fx */ #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - Word16 lsp_mid_fx_1[M]; Word32 res_cod_SNR_M_fx[STEREO_DFT_BAND_MAX]; Word16 res_cod_SNR_M_fx_e[STEREO_DFT_BAND_MAX]; Word16 tcx_mdct_window_fx[L_LOOK_16k]; - // Word16 stab_fac_fx; - float tmp = currFlatness * ONE_IN_Q7; Word16 wsp_fx_temp[L_WSP]; Word16 *wsp_fx_l; - non_staX16_fx = float_to_fix16( non_staX, Q8 ); - // currFlatness_fx = float_to_fix16_thrld( currFlatness, Q7 ); - if ( tmp > MAX_16 ) - { - currFlatness_fx = MAX_16; - } - else if ( tmp < MIN_16 ) - { - currFlatness_fx = MIN_16; - } - else - currFlatness_fx = (Word16) tmp; - stab_fac_fx = float_to_fix16( stab_fac, Q15 ); if ( flag_16k_smc ) floatToFixed_arr16( st->hTcxCfg->tcx_mdct_window_flt, tcx_mdct_window_fx, Q15, L_LOOK_16k ); else floatToFixed_arr16( st->hTcxCfg->tcx_mdct_window_flt, tcx_mdct_window_fx, Q15, L_LOOK_12k8 ); - floatToFixed_arr( pitch_fr, pitch_fr_fx, Q6, NB_SUBFR ); - floatToFixed_arr( voicing_fr, voicing_fr_fx, Q15, NB_SUBFR ); floatToFixed_arrL( st->hTcxEnc->spectrum_long, st->hTcxEnc->spectrum_long_fx, Q15, N_MAX ); #endif - if ( flag_16k_smc ) + IF( flag_16k_smc ) { -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - Word16 lsp_mid_fx[M]; - - floatToFixed_arr16( Aw, Aw_fx, Q12, NB_SUBFR16k * ( M + 1 ) ); - floatToFixed_arr16( lsp_new, lsp_new_fx, Q15, M ); - floatToFixed_arr16( lsp_mid, lsp_mid_fx, Q15, M ); #ifdef IVAS_FLOAT_FIXED_CONVERSIONS Word16 Q_old_inp_16k = -1; floatToFixed_arr16( st->input, st->input_fx, -1, 960 ); + floatToFixed_arr16( st->lspold_enc, st->lspold_enc_fx, 15, 16 ); st->mem_preemph_enc = (Word16) floatToFixed( st->mem_preemph_enc_flt, Q_old_inp_16k ); st->mem_preemph16k_fx = (Word16) floatToFixed( st->mem_preemph16k, Q_old_inp_16k ); st->mem_preemph16k_DFT_fx = (Word16) floatToFixed( st->mem_preemph16k_DFT, Q_old_inp_16k ); @@ -2816,7 +2530,6 @@ ivas_error pre_proc_front_ivas_fx( floatToFixed_arr16( st->hBWE_FD->old_wtda_swb, st->hBWE_FD->L_old_wtda_swb_fx, Q_old_inp_16k, L_FRAME48k ); st->Q_old_wtda = -1; // This reset needs to be looked into } -#endif #endif /* Compute core-coder buffers at internal sampling rate */ @@ -2828,11 +2541,6 @@ ivas_error pre_proc_front_ivas_fx( { return error; } -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - fixedToFloat_arr( Aw_fx, Aw, Q12, NB_SUBFR16k * ( M + 1 ) ); - fixedToFloat_arr( lsp_new_fx, lsp_new, Q15, M ); - fixedToFloat_arr( lsp_mid_fx, lsp_mid, Q15, M ); -#endif #ifdef IVAS_FLOAT_FIXED_CONVERSIONS // No need to do fixed to float for signal_in_fx st->mem_preemph_enc_flt = fixedToFloat_16( st->mem_preemph_enc, Q_old_inp_16k ); @@ -2846,6 +2554,7 @@ ivas_error pre_proc_front_ivas_fx( } fixedToFloat_arr( old_inp_16k_fx, old_inp_16k, Q_old_inp_16k, L_INP ); + fixedToFloat_arr( st->lspold_enc_fx, st->lspold_enc, 15, 16 ); fixedToFloat_arr( st->input_fx, st->input, -1, 960 ); fixedToFloat_arr( st->old_inp_16k_fx, st->old_inp_16k, Q_old_inp_16k, L_INP_MEM ); fixedToFloat_arr( st->mem_decim16k_fx, st->mem_decim16k, Q_old_inp_16k, 2 * L_FILT_MAX ); @@ -2867,12 +2576,11 @@ ivas_error pre_proc_front_ivas_fx( #ifdef IVAS_FLOAT_FIXED #ifdef IVAS_FLOAT_FIXED_CONVERSIONS Word16 q_speech_enc; - floatToFixed_arr16( lsp_mid, lsp_mid_fx_1, Q15, M ); q_speech_enc = s_min( Q_factor_arr( st->speech_enc_flt - 560, 2 * 560 ), Q_factor_arr( st->wspeech_enc_flt - 560, 2 * 560 ) ); floatToFixed_arr( st->speech_enc_flt - 560, st->speech_enc - 560, q_speech_enc, 2 * 560 ); floatToFixed_arr( st->wspeech_enc_flt - 560, st->wspeech_enc - 560, q_speech_enc, 2 * 560 ); #endif - smc_dec = ivas_acelp_tcx20_switching_fx( st, st->speech_enc, q_speech_enc, st->wspeech_enc, non_staX16_fx, pitch_fr_fx, voicing_fr_fx, currFlatness_fx, lsp_mid_fx_1, stab_fac_fx, res_cod_SNR_M_fx, res_cod_SNR_M_fx_e, tcx_mdct_window_fx, flag_16k_smc ); + smc_dec = ivas_acelp_tcx20_switching_fx( st, st->speech_enc, q_speech_enc, st->wspeech_enc, non_staX_fx, pitch_fr_fx, voicing_fr_fx, currFlatness_fx, lsp_mid_fx, stab_fac_fx, res_cod_SNR_M_fx, res_cod_SNR_M_fx_e, tcx_mdct_window_fx, flag_16k_smc ); #ifdef IVAS_FLOAT_FIXED_CONVERSIONS for ( i = 0; i < 7; i++ ) { @@ -2898,15 +2606,13 @@ ivas_error pre_proc_front_ivas_fx( break; } } - floatToFixed_arr16( lsp_mid, lsp_mid_fx_1, Q15, M ); floatToFixed_arr( inp_12k8, inp_12k8_fx, Q_new, ATT_NSEG * ATT_SEG_LEN ); floatToFixed_arr( wsp - L_WSP_MEM, wsp_fx_temp, Q_new, L_WSP_MEM ); wsp_fx_l = wsp_fx_temp + L_WSP_MEM; floatToFixed_arr( wsp, wsp_fx_l, Q_new, L_WSP - L_WSP_MEM ); #endif - smc_dec = ivas_acelp_tcx20_switching_fx( st, inp_12k8_fx, Q_new, wsp_fx_l, non_staX16_fx, pitch_fr_fx, voicing_fr_fx, currFlatness_fx, lsp_mid_fx_1, stab_fac_fx, res_cod_SNR_M_fx, res_cod_SNR_M_fx_e, tcx_mdct_window_fx, flag_16k_smc ); + smc_dec = ivas_acelp_tcx20_switching_fx( st, inp_12k8_fx, Q_new, wsp_fx_l, non_staX_fx, pitch_fr_fx, voicing_fr_fx, currFlatness_fx, lsp_mid_fx, stab_fac_fx, res_cod_SNR_M_fx, res_cod_SNR_M_fx_e, tcx_mdct_window_fx, flag_16k_smc ); #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - // st->prevTempFlatness = currFlatness; for ( i = 0; i < 7; i++ ) { res_cod_SNR_M[i] = me2f( res_cod_SNR_M_fx[i], res_cod_SNR_M_fx_e[i] ); @@ -2920,7 +2626,6 @@ ivas_error pre_proc_front_ivas_fx( /* Switch to ACELP for non-harmonic transient signals */ else if ( ( ( element_mode >= IVAS_CPE_DFT && element_brate <= IVAS_16k4 ) || ( element_mode == IVAS_SCE && element_brate < SCE_SMC_THR ) ) && ( loc_harm[0] != 1 ) && smc_dec == MUSIC ) { -#ifdef IVAS_FLOAT_FIXED #ifdef IVAS_FLOAT_FIXED_CONVERSIONS IF( EQ_16( element_mode, IVAS_SCE ) ) { @@ -2968,33 +2673,10 @@ ivas_error pre_proc_front_ivas_fx( } } } -#else - if ( element_mode == IVAS_SCE ) - { - if ( transient_analysis( st->hTranDet, st->hNoiseEst->cor_map, st->hNoiseEst->multi_harm_limit ) ) - - { - smc_dec = SPEECH; - } - } - else if ( element_mode == IVAS_CPE_DFT ) - { - for ( i = 0; i < CPE_CHANNELS; i++ ) - { - if ( smc_dec != SPEECH && transient_analysis( hCPE->hCoreCoder[i]->hTranDet, st->hNoiseEst->cor_map, st->hNoiseEst->multi_harm_limit ) ) - { - smc_dec = SPEECH; /* overwrite initial music decision, initial SPEECH_MUSIC never changed */ - } - } - } -#endif } #ifdef IVAS_FLOAT_FIXED #ifdef IVAS_FLOAT_FIXED_CONVERSIONS #define ATT_SEG_LEN ( L_FRAME / ATT_NSEG ) - relE_fx = float_to_fix16( *relE, Q8 ); - Etot16_fx = float_to_fix16( Etot, Q8 ); - // Q_new = s_min(Q_factor_arr( inp_12k8, ATT_NSEG * ATT_SEG_LEN ), Q_factor_arr( st->Bin_E, 256 )) - 1; Q_new = 0; /* Dynamic Q_new used above causes overflow issues */ for ( int k = 0; k < ATT_NSEG * ATT_SEG_LEN; k++ ) { @@ -3006,21 +2688,9 @@ ivas_error pre_proc_front_ivas_fx( } floatToFixed_arr( inp_12k8, inp_12k8_fx, Q_new, ATT_NSEG * ATT_SEG_LEN ); floatToFixed_arrL( st->Bin_E, st->Bin_E_fx, Q_new + Q_SCALE - 2, TOD_NSPEC ); - floatToFixed_arrL( st->hSpMusClas->tod_lt_Bin_E, st->hSpMusClas->tod_lt_Bin_E_fx, Q_new + Q_SCALE - 2, TOD_NSPEC ); - floatToFixed_arr( S_map, S_map_fx, Q7, L_FFT / 2 ); - floatToFixed_arrL( st->hSpMusClas->finc_prev, st->hSpMusClas->finc_prev_fx, 2 * Q_new, ATT_NSEG ); - st->hSpMusClas->lt_finc_fx = floatToFixed( st->hSpMusClas->lt_finc, 2 * Q_new ); #endif // IVAS_FLOAT_FIXED_CONVERSIONS - /* 2nd stage speech/music classification (ACELP/GSC/TCX core selection) */ - ivas_smc_mode_selection_fx( st, element_brate, smc_dec, relE_fx, Etot16_fx, attack_flag, inp_12k8_fx, Q_new, S_map_fx, flag_spitch ); - -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - fixedToFloat_arrL( st->hSpMusClas->finc_prev_fx, st->hSpMusClas->finc_prev, 2 * Q_new, ATT_NSEG ); - st->hSpMusClas->lt_finc = fixedToFloat( st->hSpMusClas->lt_finc_fx, 2 * Q_new ); - fixedToFloat_arrL( st->hSpMusClas->tod_lt_Bin_E_fx, st->hSpMusClas->tod_lt_Bin_E, Q_new + Q_SCALE - 2, TOD_NSPEC ); -#endif // IVAS_FLOAT_FIXED_CONVERSIONS - + ivas_smc_mode_selection_fx( st, element_brate, smc_dec, *relE_fx, Etot_fx, attack_flag, inp_12k8_fx, Q_new, S_map_fx, flag_spitch ); #else /* 2nd stage speech/music classification (ACELP/GSC/TCX core selection) */ ivas_smc_mode_selection( st, element_brate, smc_dec, *relE, Etot, attack_flag, inp_12k8, S_map, flag_spitch ); @@ -3043,11 +2713,6 @@ ivas_error pre_proc_front_ivas_fx( mvr2r( &old_inp_12k8[L_FRAME], st->old_inp_12k8, L_INP_MEM ); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - Word16 tmp = norm_s( A_fx[0] ); - fixedToFloat_arr( A_fx, A, Q14 - tmp, NB_SUBFR16k * ( M + 1 ) ); -#endif - #ifdef IVAS_FLOAT_FIXED free( enerBuffer_fx ); free( old_inp_16k_fx ); diff --git a/lib_enc/ivas_cpe_enc.c b/lib_enc/ivas_cpe_enc.c index 7948c6e17..3d6e11ebc 100644 --- a/lib_enc/ivas_cpe_enc.c +++ b/lib_enc/ivas_cpe_enc.c @@ -96,6 +96,7 @@ ivas_error ivas_cpe_enc_fx( #endif float ener[CPE_CHANNELS]; /* residual energy from Levinson-Durbin */ float relE[CPE_CHANNELS]; /* frame relative energy */ + Word16 relE_fx[CPE_CHANNELS]; /* frame relative energy Q8 */ #ifdef IVAS_FLOAT_FIXED_CONVERSIONS // required for float to fix conversion float A[CPE_CHANNELS][NB_SUBFR16k * ( M + 1 )] = { 0 }; /* A(z) unquantized for subframes */ float Aw[CPE_CHANNELS][NB_SUBFR16k * ( M + 1 )] = { 0 }; /* weighted A(z) unquantized for subframes */ @@ -103,23 +104,31 @@ ivas_error ivas_cpe_enc_fx( float A[CPE_CHANNELS][NB_SUBFR16k * ( M + 1 )]; /* A(z) unquantized for subframes */ float Aw[CPE_CHANNELS][NB_SUBFR16k * ( M + 1 )]; /* weighted A(z) unquantized for subframes */ #endif - float epsP[CPE_CHANNELS][M + 1]; /* LP prediction errors */ - float lsp_new[CPE_CHANNELS][M]; /* LSPs at the end of the frame */ - float lsp_mid[CPE_CHANNELS][M]; /* ISPs in the middle of the frame */ - Word16 vad_hover_flag[CPE_CHANNELS]; /* VAD hangover flag */ - Word16 attack_flag[CPE_CHANNELS]; /* attack flag (GSC or TC) */ - float realBuffer[CPE_CHANNELS][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; /* real buffer */ - float imagBuffer[CPE_CHANNELS][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; /* imag buffer */ - float old_wsp[CPE_CHANNELS][L_WSP]; /* old weighted input signal */ - float pitch_fr[CPE_CHANNELS][NB_SUBFR]; /* fractional pitch values */ - float voicing_fr[CPE_CHANNELS][NB_SUBFR]; /* fractional pitch gains */ - Word16 pitch_fr_fx[CPE_CHANNELS][NB_SUBFR]; /* Q6, fractional pitch values */ - Word16 voicing_fr_fx[CPE_CHANNELS][NB_SUBFR]; /* Q15, fractional pitch gains */ - Word16 loc_harm[CPE_CHANNELS]; /* harmonicity flag */ - float cor_map_sum[CPE_CHANNELS]; /* speech/music clasif. parameter */ - Word16 vad_flag_dtx[CPE_CHANNELS]; /* HE-SAD flag with additional DTX HO */ - float enerBuffer[CPE_CHANNELS][CLDFB_NO_CHANNELS_MAX]; /* energy buffer */ - float currFlatness[CPE_CHANNELS] = { 0 }; /* flatness parameter */ + Word16 A_fx[CPE_CHANNELS][NB_SUBFR16k * ( M + 1 )] = { 0 }; /* A(z) unquantized for subframes Q12 */ + Word16 Aw_fx[CPE_CHANNELS][NB_SUBFR16k * ( M + 1 )] = { 0 }; /* weighted A(z) unquantized for subframes Q12 */ + float epsP[CPE_CHANNELS][M + 1]; /* LP prediction errors */ + float lsp_new[CPE_CHANNELS][M]; /* LSPs at the end of the frame */ + float lsp_mid[CPE_CHANNELS][M]; /* ISPs in the middle of the frame */ + Word16 lsp_new_fx[CPE_CHANNELS][M]; /* LSPs at the end of the frame Q15 */ + Word16 lsp_mid_fx[CPE_CHANNELS][M]; /* ISPs in the middle of the frame Q15 */ + Word16 vad_hover_flag[CPE_CHANNELS]; /* VAD hangover flag */ + Word16 attack_flag[CPE_CHANNELS]; /* attack flag (GSC or TC) */ + float realBuffer[CPE_CHANNELS][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; /* real buffer */ + float imagBuffer[CPE_CHANNELS][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; /* imag buffer */ + Word32 realBuffer_fx[CPE_CHANNELS][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; /* real buffer */ + Word32 imagBuffer_fx[CPE_CHANNELS][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; /* imag buffer */ + Word16 q_re_im_buf = 0; + move16(); + float old_wsp[CPE_CHANNELS][L_WSP]; /* old weighted input signal */ + float pitch_fr[CPE_CHANNELS][NB_SUBFR]; /* fractional pitch values */ + float voicing_fr[CPE_CHANNELS][NB_SUBFR]; /* fractional pitch gains */ + Word16 pitch_fr_fx[CPE_CHANNELS][NB_SUBFR]; /* Q6, fractional pitch values */ + Word16 voicing_fr_fx[CPE_CHANNELS][NB_SUBFR]; /* Q15, fractional pitch gains */ + Word16 loc_harm[CPE_CHANNELS]; /* harmonicity flag */ + float cor_map_sum[CPE_CHANNELS]; /* speech/music clasif. parameter */ + Word16 cor_map_sum_fx[CPE_CHANNELS]; /* speech/music clasif. parameter Q8 */ + Word16 vad_flag_dtx[CPE_CHANNELS]; /* HE-SAD flag with additional DTX HO */ + float enerBuffer[CPE_CHANNELS][CLDFB_NO_CHANNELS_MAX]; /* energy buffer */ #ifdef IVAS_FLOAT_FIXED Word16 currFlatness_fx[CPE_CHANNELS]; /* flatness parameter Q7 */ #endif @@ -129,7 +138,7 @@ ivas_error ivas_cpe_enc_fx( Word16 nb_bits; /* number of DFT stereo side bits */ float fr_bands[CPE_CHANNELS][2 * NB_BANDS]; /* energy in frequency bands */ - float Etot_LR[CPE_CHANNELS]; /* total energy */ + Word16 Etot_LR_fx[CPE_CHANNELS]; /* total energy Q8 */ float lf_E[CPE_CHANNELS][2 * VOIC_BINS]; /* per bin spectrum energy in lf */ Word16 localVAD_HE_SAD[CPE_CHANNELS]; /* HE-SAD flag without hangover, LR channels */ float band_energies_LR[2 * NB_BANDS]; /* energy in critical bands without minimum noise floor E_MIN */ @@ -222,6 +231,15 @@ ivas_error ivas_cpe_enc_fx( #endif } + FOR( Word16 i = 0; i < CPE_CHANNELS; i++ ) + { + FOR( Word16 j = 0; j < CLDFB_NO_COL_MAX; j++ ) + { + set_zero_fx( realBuffer_fx[i][j], CLDFB_NO_CHANNELS_MAX ); + set_zero_fx( imagBuffer_fx[i][j], CLDFB_NO_CHANNELS_MAX ); + } + } + /*----------------------------------------------------------------* * Stereo technology selection * Front-VAD on input L and R channels @@ -239,7 +257,6 @@ ivas_error ivas_cpe_enc_fx( move16(); Word16 Q_buffer[2]; Word32 band_energies_LR_fx[2 * NB_BANDS]; - Word16 Etot_LR_fx[CPE_CHANNELS]; Word32 lf_E_fx[CPE_CHANNELS][2 * VOIC_BINS]; Word32 fr_bands_fx[CPE_CHANNELS][2 * NB_BANDS]; Word16 band_ener_guardbits = find_guarded_bits_fx( 2 * NB_BANDS ); @@ -297,7 +314,6 @@ ivas_error ivas_cpe_enc_fx( fixedToFloat_arrL( fr_bands_fx[n], fr_bands[n], Q_buffer[n] + QSCALE, 40 ); fixedToFloat_arrL( lf_E_fx[n], lf_E[n], Q_buffer[n] + QSCALE - 2, 148 ); - Etot_LR[n] = fixedToFloat( Etot_LR_fx[n], Q8 ); fixedToFloat_arrL( hCPE->hFrontVad[n]->hNoiseEst->bckr_fx, hCPE->hFrontVad[n]->hNoiseEst->bckr, Q_new_old + QSCALE, 20 ); fixedToFloat_arrL( hCPE->hFrontVad[n]->hNoiseEst->enrO_fx, hCPE->hFrontVad[n]->hNoiseEst->enrO, Q_new_old + QSCALE, 20 ); if ( front_create_flag ) @@ -448,7 +464,8 @@ ivas_error ivas_cpe_enc_fx( { IF( sts[n]->hTranDet == NULL ) { - currFlatness[n] = 0; + currFlatness_fx[n] = 0; + move16(); CONTINUE; } @@ -467,24 +484,13 @@ ivas_error ivas_cpe_enc_fx( currFlatness_fx[n] = GetTCXAvgTemporalFlatnessMeasure_ivas_fx( sts[n]->hTranDet, NSUBBLOCKS, 0 ); move16(); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - currFlatness[n] = fix16_to_float( currFlatness_fx[n], Q7 ); -#endif } /* Synchonize detection for downmix-based stereo */ test(); IF( EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) || EQ_16( hCPE->element_mode, IVAS_CPE_TD ) ) { -#ifdef IVAS_FLOAT_FIXED -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - currFlatness_fx[0] = float_to_fix16( currFlatness[0], Q7 ); - currFlatness_fx[1] = float_to_fix16( currFlatness[1], Q7 ); -#endif set_transient_stereo_fx( hCPE, currFlatness_fx ); -#else - set_transient_stereo( hCPE, currFlatness ); -#endif } /*----------------------------------------------------------------* @@ -616,12 +622,6 @@ ivas_error ivas_cpe_enc_fx( hCPE->hStereoClassif->xtalk_score_fx = floatToFixed( hCPE->hStereoClassif->xtalk_score, 31 ); #endif // !MSAN_FIX - for ( i = 0; i < STEREO_DFT_BAND_MAX; i++ ) - { - f2me( hCPE->hStereoDft->res_cod_NRG_M[i], &hCPE->hStereoDft->res_cod_NRG_M_fx[i], &hCPE->hStereoDft->res_cod_NRG_M_fx_e[i] ); - f2me( hCPE->hStereoDft->res_cod_NRG_S[i], &hCPE->hStereoDft->res_cod_NRG_S_fx[i], &hCPE->hStereoDft->res_cod_NRG_S_fx_e[i] ); - } - /* flt2fix: to be removed */ floatToFixed_arr( hCPE->hCoreCoder[0]->voicing, hCPE->hCoreCoder[0]->voicing_fx, 15, 3 ); /* flt2fix end */ @@ -824,13 +824,6 @@ ivas_error ivas_cpe_enc_fx( me2f_buf( hCPE->hStereoDft->DFT_fx[i], hCPE->hStereoDft->DFT_fx_e[i], hCPE->hStereoDft->DFT[i], STEREO_DFT_N_MAX_ENC ); } /*local fix2flt*/ - - for ( i = 0; i < STEREO_DFT_BAND_MAX; i++ ) - { - hCPE->hStereoDft->res_cod_NRG_M[i] = me2f( hCPE->hStereoDft->res_cod_NRG_M_fx[i], hCPE->hStereoDft->res_cod_NRG_M_fx_e[i] ); - hCPE->hStereoDft->res_cod_NRG_S[i] = me2f( hCPE->hStereoDft->res_cod_NRG_S_fx[i], hCPE->hStereoDft->res_cod_NRG_S_fx_e[i] ); - } - /*fix2flt: dft_synthesize*/ fixedToFloat_arrL( sts[0]->input32_fx + out_start_ind, sts[0]->input + out_start_ind, 16, out_end_ind - out_start_ind ); fixedToFloat_arrL( old_inp_12k8_fx[0] + L_INP_MEM + out_12k8_start_ind[0], old_inp_12k8[0] + L_INP_MEM + out_12k8_start_ind[0], 16, out_12k8_end_ind[0] - out_12k8_start_ind[0] ); @@ -887,13 +880,35 @@ ivas_error ivas_cpe_enc_fx( * Front Pre-processing *----------------------------------------------------------------*/ - for ( n = 0; n < n_CoreChannels; n++ ) + FOR( n = 0; n < n_CoreChannels; n++ ) { #ifdef IVAS_FLOAT_FIXED +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + floatToFixed_arr16( A[0], A_fx[0], Q12, M + 1 ); +#endif error = pre_proc_front_ivas_fx( NULL, hCPE, hCPE->element_brate, nb_bits_metadata, input_frame, n, old_inp_12k8_16fx[n], old_inp_12k8[n], old_inp_16k[n], - &ener[n], &relE[n], A[n], Aw[n], epsP[n], lsp_new[n], lsp_mid[n], &vad_hover_flag[n], &attack_flag[n], - realBuffer[n], imagBuffer[n], old_wsp[n], pitch_fr[n], voicing_fr[n], &loc_harm[n], &cor_map_sum[n], &vad_flag_dtx[n], enerBuffer[n], - fft_buff[n], fft_buff_fx[n], A[0], lsp_new[0], currFlatness[n], tdm_ratio_idx, fr_bands, Etot_LR, lf_E, localVAD_HE_SAD, band_energies_LR, 0, st_ivas->hSpar != NULL ? st_ivas->hSpar->front_vad_flag : 0, 0, 0, ivas_format, st_ivas->hMCT != NULL, ivas_total_brate ); + &ener[n], &relE_fx[n], A_fx[n], Aw_fx[n], epsP[n], lsp_new_fx[n], lsp_mid_fx[n], &vad_hover_flag[n], &attack_flag[n], + realBuffer_fx[n], imagBuffer_fx[n], &q_re_im_buf, old_wsp[n], pitch_fr_fx[n], voicing_fr_fx[n], &loc_harm[n], &cor_map_sum_fx[n], &vad_flag_dtx[n], enerBuffer[n], + fft_buff[n], fft_buff_fx[n], A_fx[0], lsp_new_fx[0], currFlatness_fx[n], tdm_ratio_idx, fr_bands, Etot_LR_fx, lf_E, localVAD_HE_SAD, band_energies_LR, 0, st_ivas->hSpar != NULL ? st_ivas->hSpar->front_vad_flag : 0, 0, 0, ivas_format, st_ivas->hMCT != NULL, ivas_total_brate ); + +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + fixedToFloat_arr( A_fx[n], A[n], 14 - norm_s( A_fx[n][0] ), NB_SUBFR16k * ( M + 1 ) ); + fixedToFloat_arr( Aw_fx[n], Aw[n], 14 - norm_s( Aw_fx[n][0] ), NB_SUBFR16k * ( M + 1 ) ); + fixedToFloat_arr( lsp_new_fx[n], lsp_new[n], Q15, M ); + fixedToFloat_arr( lsp_mid_fx[n], lsp_mid[n], Q15, M ); + fixedToFloat_arr( pitch_fr_fx[n], pitch_fr[n], Q6, NB_SUBFR ); + fixedToFloat_arr( voicing_fr_fx[n], voicing_fr[n], Q15, NB_SUBFR ); + relE[n] = fix16_to_float( relE_fx[n], Q8 ); + cor_map_sum[n] = fix16_to_float( cor_map_sum_fx[n], Q8 ); + for ( int i = 0; i < CLDFB_NO_COL_MAX; i++ ) + { + for ( int j = 0; j < CLDFB_NO_CHANNELS_MAX; j++ ) + { + realBuffer[n][i][j] = fixedToFloat( realBuffer_fx[n][i][j], q_re_im_buf ); + imagBuffer[n][i][j] = fixedToFloat( imagBuffer_fx[n][i][j], q_re_im_buf ); + } + } +#endif #else error = pre_proc_front_ivas( NULL, hCPE, hCPE->element_brate, nb_bits_metadata, input_frame, n, old_inp_12k8[n], old_inp_16k[n], &ener[n], &relE[n], A[n], Aw[n], epsP[n], lsp_new[n], lsp_mid[n], &vad_hover_flag[n], &attack_flag[n], diff --git a/lib_enc/ivas_front_vad.c b/lib_enc/ivas_front_vad.c index e1b06984b..ff557c150 100644 --- a/lib_enc/ivas_front_vad.c +++ b/lib_enc/ivas_front_vad.c @@ -1090,13 +1090,8 @@ ivas_error front_vad_spar_fx( Word16 e_esp; f2me_buf( epsP, epsP_fx, &e_esp, M + 1 ); Q_esp = sub( 31, e_esp ); - Word16 Qfact_PS_past = Q_factor_arrL( hSpMusClas->past_PS, 67 ); - floatToFixed_arr32( hSpMusClas->past_PS, hSpMusClas->past_PS_fx, Qfact_PS_past, 67 ); -#endif - ivas_smc_gmm_fx( st, NULL, localVAD_HE_SAD[0], Etot_fx_0, lsp_new_fx, cor_map_sum_fx, epsP_fx, PS_fx, non_sta_fx, relE_fx, &high_lpn_flag, flag_spitch, Qfact_PS, Q_esp, Qfact_PS_past ); -#if 1 - fixedToFloat_arrL32( hSpMusClas->past_PS_fx, hSpMusClas->past_PS, Qfact_PS_past, 67 ); #endif + ivas_smc_gmm_fx( st, NULL, localVAD_HE_SAD[0], Etot_fx_0, lsp_new_fx, cor_map_sum_fx, epsP_fx, PS_fx, non_sta_fx, relE_fx, &high_lpn_flag, flag_spitch, Qfact_PS, Q_esp, hSpMusClas->past_PS_Q ); #endif /* long-term energy update */ diff --git a/lib_enc/ivas_ism_enc.c b/lib_enc/ivas_ism_enc.c index 335b524a3..2d7ba881e 100644 --- a/lib_enc/ivas_ism_enc.c +++ b/lib_enc/ivas_ism_enc.c @@ -445,34 +445,44 @@ ivas_error ivas_ism_enc_fx( Word16 relE_fx[MAX_NUM_OBJECTS][1]; /* frame relative energy, Q8 */ #ifdef IVAS_FLOAT_FIXED_CONVERSIONS // required for float to fix conversion - float A[MAX_NUM_OBJECTS][1][NB_SUBFR16k * ( M + 1 )] = { 0 }; /* A(z) unquantized for subframes */ - float Aw[MAX_NUM_OBJECTS][1][NB_SUBFR16k * ( M + 1 )] = { 0 }; /* weighted A(z) unquantized for subframes */ + float A[MAX_NUM_OBJECTS][1][NB_SUBFR16k * ( M + 1 )] = { 0 }; /* A(z) unquantized for subframes */ + float Aw[MAX_NUM_OBJECTS][1][NB_SUBFR16k * ( M + 1 )] = { 0 }; /* weighted A(z) unquantized for subframes */ #else float A[MAX_NUM_OBJECTS][1][NB_SUBFR16k * ( M + 1 )]; /* A(z) unquantized for subframes */ float Aw[MAX_NUM_OBJECTS][1][NB_SUBFR16k * ( M + 1 )]; /* weighted A(z) unquantized for subframes */ #endif - float epsP[MAX_NUM_OBJECTS][1][M + 1]; /* LP prediction errors */ - float lsp_new[MAX_NUM_OBJECTS][1][M]; /* LSPs at the end of the frame */ - float lsp_mid[MAX_NUM_OBJECTS][1][M]; /* ISPs in the middle of the frame */ - Word16 vad_hover_flag[MAX_NUM_OBJECTS][1]; /* VAD hangover flag */ - Word16 attack_flag[MAX_NUM_OBJECTS][1]; /* attack flag (GSC or TC) */ - float realBuffer[MAX_NUM_OBJECTS][1][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; /* real buffer */ - float imagBuffer[MAX_NUM_OBJECTS][1][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; /* imag buffer */ - float old_wsp[MAX_NUM_OBJECTS][1][L_WSP]; /* old weighted input signal */ - float pitch_fr[MAX_NUM_OBJECTS][1][NB_SUBFR]; /* fractional pitch values */ - float voicing_fr[MAX_NUM_OBJECTS][1][NB_SUBFR]; /* fractional pitch gains */ - Word16 loc_harm[MAX_NUM_OBJECTS][1]; /* harmonicity flag */ - float cor_map_sum[MAX_NUM_OBJECTS][1]; /* speech/music clasif. parameter */ - Word16 vad_flag_dtx[MAX_NUM_OBJECTS][1]; /* HE-SAD flag with additional DTX HO */ - float enerBuffer[MAX_NUM_OBJECTS][1][CLDFB_NO_CHANNELS_MAX]; /* energy buffer */ - Word16 currFlatness_fx[1]; /* flatness parameter */ - float currFlatness[1]; /* flatness parameter */ - float fft_buff[MAX_NUM_OBJECTS][1][2 * L_FFT]; /* FFT buffer */ - Word16 fft_buff_fx[MAX_NUM_OBJECTS][1][2 * L_FFT]; /* FFT buffer */ - float fr_bands[1][2 * NB_BANDS]; /* energy in frequency bands */ - float Etot_LR[1]; /* total energy; correlation shift */ - float lf_E[1][2 * VOIC_BINS]; /* per bin spectrum energy in lf */ - Word16 localVAD_HE_SAD[1]; /* local HE VAD */ + Word16 A_fx[MAX_NUM_OBJECTS][1][NB_SUBFR16k * ( M + 1 )] = { 0 }; /* A(z) unquantized for subframes */ + Word16 Aw_fx[MAX_NUM_OBJECTS][1][NB_SUBFR16k * ( M + 1 )] = { 0 }; /* weighted A(z) unquantized for subframes */ + float epsP[MAX_NUM_OBJECTS][1][M + 1]; /* LP prediction errors */ + float lsp_new[MAX_NUM_OBJECTS][1][M]; /* LSPs at the end of the frame */ + float lsp_mid[MAX_NUM_OBJECTS][1][M]; /* ISPs in the middle of the frame */ + Word16 lsp_new_fx[MAX_NUM_OBJECTS][1][M]; /* LSPs at the end of the frame Q15 */ + Word16 lsp_mid_fx[MAX_NUM_OBJECTS][1][M]; /* ISPs in the middle of the frame Q15 */ + Word16 vad_hover_flag[MAX_NUM_OBJECTS][1]; /* VAD hangover flag */ + Word16 attack_flag[MAX_NUM_OBJECTS][1]; /* attack flag (GSC or TC) */ + Word16 q_re_im_buf = 0; + move16(); + Word32 realBuffer_fx[MAX_NUM_OBJECTS][1][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; /* real buffer */ + Word32 imagBuffer_fx[MAX_NUM_OBJECTS][1][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; /* imag buffer */ + float realBuffer[MAX_NUM_OBJECTS][1][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; /* real buffer */ + float imagBuffer[MAX_NUM_OBJECTS][1][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; /* imag buffer */ + float old_wsp[MAX_NUM_OBJECTS][1][L_WSP]; /* old weighted input signal */ + float pitch_fr[MAX_NUM_OBJECTS][1][NB_SUBFR]; /* fractional pitch values */ + float voicing_fr[MAX_NUM_OBJECTS][1][NB_SUBFR]; /* fractional pitch gains */ + Word16 pitch_fr_fx[MAX_NUM_OBJECTS][1][NB_SUBFR]; /* fractional pitch values Q6 */ + Word16 voicing_fr_fx[MAX_NUM_OBJECTS][1][NB_SUBFR]; /* fractional pitch gains Q15 */ + Word16 loc_harm[MAX_NUM_OBJECTS][1]; /* harmonicity flag */ + float cor_map_sum[MAX_NUM_OBJECTS][1]; /* speech/music clasif. parameter */ + Word16 cor_map_sum_fx[MAX_NUM_OBJECTS][1]; /* speech/music clasif. parameter Q8 */ + Word16 vad_flag_dtx[MAX_NUM_OBJECTS][1]; /* HE-SAD flag with additional DTX HO */ + float enerBuffer[MAX_NUM_OBJECTS][1][CLDFB_NO_CHANNELS_MAX]; /* energy buffer */ + Word16 currFlatness_fx[1]; /* flatness parameter */ + float fft_buff[MAX_NUM_OBJECTS][1][2 * L_FFT]; /* FFT buffer */ + Word16 fft_buff_fx[MAX_NUM_OBJECTS][1][2 * L_FFT]; /* FFT buffer */ + float fr_bands[1][2 * NB_BANDS]; /* energy in frequency bands */ + Word16 Etot_LR_fx[1]; /* total energy; correlation shift Q8 */ + float lf_E[1][2 * VOIC_BINS]; /* per bin spectrum energy in lf */ + Word16 localVAD_HE_SAD[1]; /* local HE VAD */ Word16 nchan_ism, dtx_flag, sid_flag, flag_noisy_speech; Word16 md_diff_flag[MAX_NUM_OBJECTS]; Encoder_State *prev_st = NULL; @@ -533,6 +543,11 @@ ivas_error ivas_ism_enc_fx( st->element_mode = IVAS_SCE; move16(); + FOR( i = 0; i < CLDFB_NO_COL_MAX; i++ ) + { + set_zero_fx( realBuffer_fx[sce_id][0][i], CLDFB_NO_CHANNELS_MAX ); + set_zero_fx( imagBuffer_fx[sce_id][0][i], CLDFB_NO_CHANNELS_MAX ); + } /*------------------------------------------------------------------* * SCE initialization - core coder *-----------------------------------------------------------------*/ @@ -566,9 +581,6 @@ ivas_error ivas_ism_enc_fx( currFlatness_fx[0] = GetTCXAvgTemporalFlatnessMeasure_fx( (const TransientDetection *) st->hTranDet, NSUBBLOCKS, 0 ); move16(); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - currFlatness[0] = me2f_16( currFlatness_fx[0], 15 - Q7 ); -#endif /*----------------------------------------------------------------* * Configuration of core encoder @@ -583,10 +595,37 @@ ivas_error ivas_ism_enc_fx( /*----------------------------------------------------------------* * Front Pre-processing *----------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + floatToFixed_arr16( A[sce_id][0], A_fx[sce_id][0], Q12, M + 1 ); +#endif error = pre_proc_front_ivas_fx( hSCE, NULL, hSCE->element_brate, nb_bits_metadata[sce_id], input_frame, 0, old_inp_12k8_fx[sce_id][0], old_inp_12k8[sce_id][0], old_inp_16k[sce_id][0], - &ener[sce_id][0], &relE[sce_id][0], A[sce_id][0], Aw[sce_id][0], epsP[sce_id][0], lsp_new[sce_id][0], lsp_mid[sce_id][0], &vad_hover_flag[sce_id][0], &attack_flag[sce_id][0], - realBuffer[sce_id][0], imagBuffer[sce_id][0], old_wsp[sce_id][0], pitch_fr[sce_id][0], voicing_fr[sce_id][0], &loc_harm[sce_id][0], &cor_map_sum[sce_id][0], &vad_flag_dtx[sce_id][0], enerBuffer[sce_id][0], - fft_buff[sce_id][0], fft_buff_fx[sce_id][0], A[sce_id][0], lsp_new[sce_id][0], currFlatness[0], 0, fr_bands, Etot_LR, lf_E, localVAD_HE_SAD, NULL, 0, 0, 0, 0, ISM_FORMAT, 0, st_ivas->hEncoderConfig->ivas_total_brate ); + &ener[sce_id][0], &relE_fx[sce_id][0], A_fx[sce_id][0], Aw_fx[sce_id][0], epsP[sce_id][0], lsp_new_fx[sce_id][0], lsp_mid_fx[sce_id][0], &vad_hover_flag[sce_id][0], &attack_flag[sce_id][0], + realBuffer_fx[sce_id][0], imagBuffer_fx[sce_id][0], &q_re_im_buf, old_wsp[sce_id][0], pitch_fr_fx[sce_id][0], voicing_fr_fx[sce_id][0], &loc_harm[sce_id][0], &cor_map_sum_fx[sce_id][0], &vad_flag_dtx[sce_id][0], enerBuffer[sce_id][0], + fft_buff[sce_id][0], fft_buff_fx[sce_id][0], A_fx[sce_id][0], lsp_new_fx[sce_id][0], currFlatness_fx[0], 0, fr_bands, Etot_LR_fx, lf_E, localVAD_HE_SAD, NULL, 0, 0, 0, 0, ISM_FORMAT, 0, st_ivas->hEncoderConfig->ivas_total_brate ); + +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + fixedToFloat_arr( A_fx[sce_id][0], A[sce_id][0], 14 - norm_s( A_fx[sce_id][0][0] ), NB_SUBFR16k * ( M + 1 ) ); + fixedToFloat_arr( Aw_fx[sce_id][0], Aw[sce_id][0], 14 - norm_s( Aw_fx[sce_id][0][0] ), NB_SUBFR16k * ( M + 1 ) ); + // fixedToFloat_arr( lsp_new_fx[sce_id][0], lsp_new[sce_id][0], Q15, M ); + // fixedToFloat_arr( lsp_mid_fx[sce_id][0], lsp_mid[sce_id][0], Q15, M ); + for ( int idx = 0; idx < M; idx++ ) + { + lsp_new[sce_id][0][idx] = (float) lsp_new_fx[sce_id][0][idx] / 32767.0f; + lsp_mid[sce_id][0][idx] = (float) lsp_mid_fx[sce_id][0][idx] / 32767.0f; + } + fixedToFloat_arr( pitch_fr_fx[sce_id][0], pitch_fr[sce_id][0], Q6, NB_SUBFR ); + fixedToFloat_arr( voicing_fr_fx[sce_id][0], voicing_fr[sce_id][0], Q15, NB_SUBFR ); + relE[sce_id][0] = fix16_to_float( relE_fx[sce_id][0], Q8 ); + cor_map_sum[sce_id][0] = fix16_to_float( cor_map_sum_fx[sce_id][0], Q8 ); + for ( i = 0; i < CLDFB_NO_COL_MAX; i++ ) + { + for ( int j = 0; j < CLDFB_NO_CHANNELS_MAX; j++ ) + { + realBuffer[sce_id][0][i][j] = fixedToFloat( realBuffer_fx[sce_id][0][i][j], q_re_im_buf ); + imagBuffer[sce_id][0][i][j] = fixedToFloat( imagBuffer_fx[sce_id][0][i][j], q_re_im_buf ); + } + } +#endif IF( NE_32( error, IVAS_ERR_OK ) ) { diff --git a/lib_enc/ivas_sce_enc.c b/lib_enc/ivas_sce_enc.c index a6d14e723..e45170c6d 100644 --- a/lib_enc/ivas_sce_enc.c +++ b/lib_enc/ivas_sce_enc.c @@ -85,12 +85,25 @@ ivas_error ivas_sce_enc_fx( float voicing_fr[1][NB_SUBFR]; /* fractional pitch gains */ float cor_map_sum[1]; /* speech/music clasif. parameter */ float enerBuffer[1][CLDFB_NO_CHANNELS_MAX]; /* energy buffer */ - float currFlatness[1]; /* flatness parameter */ float fft_buff[1][2 * L_FFT]; /* FFT buffer */ float fr_bands[1][2 * NB_BANDS]; /* energy in frequency bands */ - float Etot_LR[1]; /* total energy */ float lf_E[1][2 * VOIC_BINS]; /* per bin spectrum energy in lf */ #endif + Word16 A_fx[1][NB_SUBFR16k * ( M + 1 )]; /* A(z) unquantized for subframes */ + Word16 Aw_fx[1][NB_SUBFR16k * ( M + 1 )]; /* weighted A(z) unquantized for subframes */ + Word16 lsp_new_fx[1][M]; /* LSPs at the end of the frame Q15 */ + Word16 lsp_mid_fx[1][M]; /* ISPs in the middle of the frame Q15 */ + Word16 pitch_fr_fx[1][NB_SUBFR]; /* fractional pitch values */ + Word16 voicing_fr_fx[1][NB_SUBFR]; /* fractional pitch gains */ + Word16 relE_fx[1]; /* frame relative energy Q8 */ + Word16 currFlatness_fx[1]; /* flatness parameter Q7 */ + Word16 Etot_LR_fx[1]; /* total energy Q8 */ + Word32 realBuffer_fx[1][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; /* real buffer */ + Word32 imagBuffer_fx[1][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; /* imag buffer */ + Word16 q_re_im_buf = Q31; + move16(); + Word16 cor_map_sum_fx[1]; /* speech/music clasif. parameter Q8 */ + Word16 old_inp_12k8_fx[1][L_INP_12k8]; /* buffer of input signal @ 12k8 */ Word16 vad_hover_flag[1]; /* VAD hangover flag */ Word16 attack_flag[1]; /* attack flag (GSC or TC) */ @@ -134,6 +147,15 @@ ivas_error ivas_sce_enc_fx( st->element_mode = IVAS_SCE; move16(); + set16_fx( A_fx[0], 0, NB_SUBFR16k * ( M + 1 ) ); + set16_fx( Aw_fx[0], 0, NB_SUBFR16k * ( M + 1 ) ); + + FOR( Word16 i = 0; i < CLDFB_NO_COL_MAX; i++ ) + { + set_zero_fx( realBuffer_fx[0][i], CLDFB_NO_CHANNELS_MAX ); + set_zero_fx( imagBuffer_fx[0][i], CLDFB_NO_CHANNELS_MAX ); + } + /*------------------------------------------------------------------* * SCE initialization - core coder *-----------------------------------------------------------------*/ @@ -166,10 +188,8 @@ ivas_error ivas_sce_enc_fx( move16(); } - Word16 tmp = GetTCXAvgTemporalFlatnessMeasure_fx( (const TransientDetection *) st->hTranDet, NSUBBLOCKS, 0 ); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - currFlatness[0] = me2f_16( tmp, 15 - Q7 ); -#endif + currFlatness_fx[0] = GetTCXAvgTemporalFlatnessMeasure_fx( (const TransientDetection *) st->hTranDet, NSUBBLOCKS, 0 ); + move16(); /*----------------------------------------------------------------* * Configuration of core encoder @@ -233,11 +253,34 @@ ivas_error ivas_sce_enc_fx( * Front Pre-processing *----------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + floatToFixed_arr16( A[0], A_fx[0], Q12, M + 1 ); +#endif + error = pre_proc_front_ivas_fx( hSCE, NULL, hSCE->element_brate, nb_bits_metadata, input_frame, 0, old_inp_12k8_fx[0], old_inp_12k8[0], old_inp_16k[0], - &ener[0], &relE[0], A[0], Aw[0], epsP[0], lsp_new[0], lsp_mid[0], &vad_hover_flag[0], &attack_flag[0], - realBuffer[0], imagBuffer[0], old_wsp[0], pitch_fr[0], voicing_fr[0], &loc_harm[0], &cor_map_sum[0], &vad_flag_dtx[0], enerBuffer[0], - fft_buff[0], fft_buff_fx[0], A[0], lsp_new[0], currFlatness[0], 0, fr_bands, Etot_LR, lf_E, localVAD_HE_SAD, NULL, flag_16k_smc, + &ener[0], &relE_fx[0], A_fx[0], Aw_fx[0], epsP[0], lsp_new_fx[0], lsp_mid_fx[0], &vad_hover_flag[0], &attack_flag[0], + realBuffer_fx[0], imagBuffer_fx[0], &q_re_im_buf, old_wsp[0], pitch_fr_fx[0], voicing_fr_fx[0], &loc_harm[0], &cor_map_sum_fx[0], &vad_flag_dtx[0], enerBuffer[0], + fft_buff[0], fft_buff_fx[0], A_fx[0], lsp_new_fx[0], currFlatness_fx[0], 0, fr_bands, Etot_LR_fx, lf_E, localVAD_HE_SAD, NULL, flag_16k_smc, st_ivas->hSpar != NULL ? st_ivas->hSpar->front_vad_flag : 0, st_ivas->hSpar != NULL ? st_ivas->hSpar->force_front_vad : 0, st_ivas->hSpar != NULL ? st_ivas->hSpar->front_vad_dtx_flag : 0, ivas_format, 0, st_ivas->hEncoderConfig->ivas_total_brate ); + +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + fixedToFloat_arr( A_fx[0], A[0], 14 - norm_s( A_fx[0][0] ), NB_SUBFR16k * ( M + 1 ) ); + fixedToFloat_arr( Aw_fx[0], Aw[0], 14 - norm_s( Aw_fx[0][0] ), NB_SUBFR16k * ( M + 1 ) ); + fixedToFloat_arr( lsp_new_fx[0], lsp_new[0], Q15, M ); + fixedToFloat_arr( lsp_mid_fx[0], lsp_mid[0], Q15, M ); + fixedToFloat_arr( pitch_fr_fx[0], pitch_fr[0], Q6, NB_SUBFR ); + fixedToFloat_arr( voicing_fr_fx[0], voicing_fr[0], Q15, NB_SUBFR ); + relE[0] = fix16_to_float( relE_fx[0], Q8 ); + cor_map_sum[0] = fix16_to_float( cor_map_sum_fx[0], Q8 ); + for ( int i = 0; i < CLDFB_NO_COL_MAX; i++ ) + { + for ( int j = 0; j < CLDFB_NO_CHANNELS_MAX; j++ ) + { + realBuffer[0][i][j] = fixedToFloat( realBuffer_fx[0][i][j], q_re_im_buf ); + imagBuffer[0][i][j] = fixedToFloat( imagBuffer_fx[0][i][j], q_re_im_buf ); + } + } +#endif #else error = pre_proc_front_ivas( hSCE, NULL, hSCE->element_brate, nb_bits_metadata, input_frame, 0, old_inp_12k8[0], old_inp_16k[0], &ener[0], &relE[0], A[0], Aw[0], epsP[0], lsp_new[0], lsp_mid[0], &vad_hover_flag[0], &attack_flag[0], diff --git a/lib_enc/ivas_stat_enc.h b/lib_enc/ivas_stat_enc.h index 515008c0f..681de918c 100644 --- a/lib_enc/ivas_stat_enc.h +++ b/lib_enc/ivas_stat_enc.h @@ -330,10 +330,10 @@ typedef struct stereo_dft_enc_data_struct int16_t res_cod_mode[STEREO_DFT_ENC_DFT_NB]; /* mode from 0 (off) to 3 */ int16_t res_cod_band_max; /* Band max for coding of residual */ int16_t res_cod_line_max; /* Maximum number of MDCT lines to code for the residual coding */ - float res_cod_NRG_M[STEREO_DFT_BAND_MAX]; - float res_cod_NRG_S[STEREO_DFT_BAND_MAX]; float res_cod_SNR_M[STEREO_DFT_BAND_MAX]; #ifndef IVAS_FLOAT_FIXED + float res_cod_NRG_M[STEREO_DFT_BAND_MAX]; + float res_cod_NRG_S[STEREO_DFT_BAND_MAX]; float old_snr; #endif int16_t first_frm_flag; /* ADAP first frame flag */ @@ -832,11 +832,10 @@ typedef struct ivas_stereo_classifier_data_structure // Above needs to remove once everything done - Word32 voicing_ch1_fx[3]; - Word16 voicing_ch1_e; + Word16 voicing_ch1_fx[3]; Word32 cor_map_sum_ch1_fx; Word16 cor_map_sum_ch1_e; - Word32 lsf_ch1_fx[M]; + Word16 lsf_ch1_fx[M]; Word32 lepsP_ch1_fx; Word16 lepsP_ch1_e; Word32 dE1_ch1_fx, dE1_ch2_fx; @@ -845,8 +844,7 @@ typedef struct ivas_stereo_classifier_data_structure Word16 nchar_ch1_e, nchar_ch2_e; Word32 non_sta_ch1_fx; Word16 non_sta_ch1_e; - Word32 sp_div_ch1_fx; - Word16 sp_div_ch1_e; + Word16 sp_div_ch1_fx; Word32 ps_sta_ch1_fx, ps_sta_ch2_fx; Word16 ps_sta_ch1_e, ps_sta_ch2_e; Word32 prev_g_IPD_fx; // Q29 @@ -1107,23 +1105,24 @@ typedef struct ivas_spar_enc_lib_t ivas_enc_cov_handler_state_t *hCovEnc; ivas_trans_det_state_t *hTranDet; ivas_agc_enc_state_t *hAgcEnc; - int16_t dirac_to_spar_md_bands[DIRAC_MAX_NBANDS]; - int16_t enc_param_start_band; - int16_t AGC_Enable; + Word16 dirac_to_spar_md_bands[DIRAC_MAX_NBANDS]; + Word16 enc_param_start_band; + Word16 AGC_Enable; PCA_ENC_STATE *hPCA; - int32_t core_nominal_brate; /* Nominal bitrate for core coding */ + Word32 core_nominal_brate; /* Nominal bitrate for core coding */ FRONT_VAD_ENC_HANDLE hFrontVad; /* front-VAD handle */ ENC_CORE_HANDLE hCoreCoderVAD; /* core-coder handle for front-VAD module */ #ifndef EVS_FLOAT_ENC // ENC_CORE_HANDLE_FX hCoreCoderVAD_fx; /* core coder handle */ #endif - int16_t spar_reconfig_flag; - int16_t front_vad_flag; - int16_t front_vad_dtx_flag; - int16_t force_front_vad; - + Word16 spar_reconfig_flag; + Word16 front_vad_flag; + Word16 front_vad_dtx_flag; + Word16 force_front_vad; +#ifndef IVAS_FLOAT_FIXED float *input_data_mem[MAX_NUM_OBJECTS]; +#endif } SPAR_ENC_DATA, *SPAR_ENC_HANDLE; diff --git a/lib_enc/ivas_stereo_classifier.c b/lib_enc/ivas_stereo_classifier.c index a0872c08e..b85e182f3 100644 --- a/lib_enc/ivas_stereo_classifier.c +++ b/lib_enc/ivas_stereo_classifier.c @@ -492,12 +492,10 @@ void stereo_classifier_init_fx( hStereoClassif->clas_ch1 = 0; move16(); set16_fx( hStereoClassif->pitch_ch1, 0, 3 ); - set_zero_fx( hStereoClassif->voicing_ch1_fx, 3 ); - hStereoClassif->voicing_ch1_e = 0; - move16(); + set16_fx( hStereoClassif->voicing_ch1_fx, 0, 3 ); hStereoClassif->cor_map_sum_ch1_fx = 0; move32(); - set_zero_fx( hStereoClassif->lsf_ch1_fx, M ); + set16_fx( hStereoClassif->lsf_ch1_fx, 0, M ); hStereoClassif->lepsP_ch1_fx = 0; move32(); hStereoClassif->dE1_ch1_fx = 0; @@ -522,8 +520,6 @@ void stereo_classifier_init_fx( move16(); hStereoClassif->sp_div_ch1_fx = 0; move32(); - hStereoClassif->sp_div_ch1_e = 0; - move16(); hStereoClassif->ps_diff_ch1_fx = 0; move32(); hStereoClassif->ps_diff_ch1_e = 0; @@ -632,9 +628,9 @@ void stereo_classifier_init_fx( /* Information on ouputs: hStereoClassif->Etot_buf_fx has expoenent hStereoClassif->e_Etot_buf_fx hStereoClassif->relE_buf_fx has expoenent hStereoClassif->relE_buf_e -hStereoClassif->lsf_ch1_fx has exponent 16 +hStereoClassif->lsf_ch1_fx has Q1*1.28 hStereoClassif->xtalk_fv_fx has exponent 16 -hStereoClassif->voicing_ch1_fx has exponent hStereoClassif->voicing_ch1_e +hStereoClassif->voicing_ch1_fx has Q-factor Q15 hStereoClassif->lepsP_ch1_fx has exponent 16 hStereoClassif->Etot_up_fx has exponent hStereoClassif->Etot_up_e hStereoClassif->Etot_dn_fx has exponent hStereoClassif->Etot_dn_e @@ -642,7 +638,7 @@ hStereoClassif->relE_0_1_fx has exponent hStereoClassif->relE_buf_e hStereoClassif->relE_0_1_LT_fx has exponent hStereoClassif->relE_buf_e hStereoClassif->cor_map_sum_ch1_fx has exponent hStereoClassif->cor_map_sum_ch1_e hStereoClassif->non_sta_ch1_fx has exponent hStereoClassif->non_sta_ch1_e -hStereoClassif->sp_div_ch1_fx has exponent hStereoClassif->sp_div_ch1_e +hStereoClassif->sp_div_ch1_fx has exponent sp_div_e hStereoClassif->nchar_ch1_fx has exponent hStereoClassif->nchar_ch1_e hStereoClassif->nchar_ch2_fx has exponent hStereoClassif->nchar_ch2_e hStereoClassif->dE1_ch1_fx has exponent hStereoClassif->dE1_ch1_e @@ -658,16 +654,15 @@ void stereo_classifier_features_ivas_fx( const Word16 idchan, /* i : channel ID */ const Word16 element_mode, /* i : element mode */ const Word16 vad_flag, /* i : VAD flag */ - Word32 lsf_new_fx[], /* i : LSFs at the end of the frame */ + Word16 lsf_new_fx[], /* i : LSFs at the end of the frame Q1*1.28 */ Word32 epsP_fx[], /* i : LP analysis residual energies for each iteration*/ - Word16 pitch[], /*q0 i : open-loop pitch values for quantiz. */ - Word16 voicing_fx[], /* i : OL maximum normalized correlation */ + Word16 pitch[], /* i : open-loop pitch values for quantiz. Q0 */ + Word16 voicing_fx[], /* i : OL maximum normalized correlation Q15 */ Word32 cor_map_sum_fx, /* i : speech/music clasif. parameter */ Word32 non_staX_fx, /* i : unbound non-stationarity for sp/mu clas. */ - Word32 sp_div_fx, /* i : spectral diversity feature */ + Word16 sp_div_fx, /* i : spectral diversity feature */ const Word16 clas, /* i : signal class */ Word16 epsP_e, /*exponent for epsP_fx */ - Word16 voicing_e, /*exponent for voicing_fx */ Word16 cor_map_sum_e, /*exponent for cor_map_sum_fx */ Word16 non_staX_e, /*exponent for non_staX_fx */ Word16 sp_div_e /*exponent for sp_div_fx */ @@ -833,16 +828,16 @@ void stereo_classifier_features_ivas_fx( IF( idchan == 0 ) { - Copy32( lsf_new_fx, hStereoClassif->lsf_ch1_fx, M ); + Copy( lsf_new_fx, hStereoClassif->lsf_ch1_fx, M ); hStereoClassif->lepsP_ch1_fx = L_shr( L_sub( BASOP_Util_Loge( L_add( epsP_fx[13], L_shr( 21474 /*1e-5*2^31*/, epsP_e ) ), epsP_e ), BASOP_Util_Loge( L_add( epsP_fx[0], L_shr( 21474 /*1e-5*2^31*/, epsP_e ) ), epsP_e ) ), 10 ); /*q15*/ move32(); move16(); - hStereoClassif->xtalk_fv_fx[E_lsf_1] = lsf_new_fx[0]; /*q15*/ - hStereoClassif->xtalk_fv_fx[E_lsf_4] = lsf_new_fx[3]; /*q15*/ - hStereoClassif->xtalk_fv_fx[E_lsf_9] = lsf_new_fx[8]; /*q15*/ - hStereoClassif->xtalk_fv_fx[E_lsf_14] = lsf_new_fx[13]; /*q15*/ - hStereoClassif->xtalk_fv_fx[E_lepsP_13] = hStereoClassif->lepsP_ch1_fx; /*q15*/ + hStereoClassif->xtalk_fv_fx[E_lsf_1] = Mpy_32_16_1( 419430400 /* 1/2.56f in Q30 */, lsf_new_fx[0] ); /*q15*/ + hStereoClassif->xtalk_fv_fx[E_lsf_4] = Mpy_32_16_1( 419430400 /* 1/2.56f in Q30 */, lsf_new_fx[3] ); /*q15*/ + hStereoClassif->xtalk_fv_fx[E_lsf_9] = Mpy_32_16_1( 419430400 /* 1/2.56f in Q30 */, lsf_new_fx[8] ); /*q15*/ + hStereoClassif->xtalk_fv_fx[E_lsf_14] = Mpy_32_16_1( 419430400 /* 1/2.56f in Q30 */, lsf_new_fx[13] ); /*q15*/ + hStereoClassif->xtalk_fv_fx[E_lepsP_13] = hStereoClassif->lepsP_ch1_fx; /*q15*/ move32(); move32(); move32(); @@ -863,7 +858,7 @@ void stereo_classifier_features_ivas_fx( } FOR( i = 0; i < M; i++ ) { - hStereoClassif->xtalk_fv_fx[E_sum_d_LSF] = L_add( hStereoClassif->xtalk_fv_fx[E_sum_d_LSF], L_abs( L_sub( lsf_new_fx[i], hStereoClassif->lsf_ch1_fx[i] ) ) ); /*q15*/ + hStereoClassif->xtalk_fv_fx[E_sum_d_LSF] = L_add( hStereoClassif->xtalk_fv_fx[E_sum_d_LSF], L_abs( Mpy_32_16_1( 419430400 /* 1/2.56f in Q30 */, sub( lsf_new_fx[i], hStereoClassif->lsf_ch1_fx[i] ) ) ) ); /*q15*/ move32(); } @@ -882,12 +877,10 @@ void stereo_classifier_features_ivas_fx( IF( idchan == 0 ) { Copy( pitch, hStereoClassif->pitch_ch1, 3 ); - Copy_Scale_sig_16_32_no_sat( voicing_fx, hStereoClassif->voicing_ch1_fx, 3, 16 ); - hStereoClassif->voicing_ch1_e = voicing_e; - move16(); + Copy( voicing_fx, hStereoClassif->voicing_ch1_fx, 3 ); - hStereoClassif->xtalk_fv_fx[E_pitch] = Mult_32_16( L_shl( add( pitch[0], add( pitch[1], pitch[2] ) ), 15 ), 10923 ); /*q15*/ - hStereoClassif->xtalk_fv_fx[E_voicing] = Mult_32_16( L_add( voicing_fx[0], L_add( voicing_fx[1], voicing_fx[2] ) ), 10923 ); /*q15*/ + hStereoClassif->xtalk_fv_fx[E_pitch] = Mpy_32_16_1( L_shl( add( pitch[0], add( pitch[1], pitch[2] ) ), 15 ), 10923 ); /*q15*/ + hStereoClassif->xtalk_fv_fx[E_voicing] = Mpy_32_16_1( L_add( voicing_fx[0], L_add( voicing_fx[1], voicing_fx[2] ) ), 10923 ); /*q15*/ move32(); move32(); } @@ -898,7 +891,7 @@ void stereo_classifier_features_ivas_fx( FOR( i = 0; i < 3; i++ ) { hStereoClassif->xtalk_fv_fx[E_d_pitch] = L_add( hStereoClassif->xtalk_fv_fx[E_d_pitch], L_shl( abs_s( sub( pitch[i], hStereoClassif->pitch_ch1[i] ) ), Q15 ) ); - hStereoClassif->xtalk_fv_fx[E_d_voicing] = L_add( hStereoClassif->xtalk_fv_fx[E_d_voicing], L_abs( L_sub( L_shl( voicing_fx[i], voicing_e ), L_shr( hStereoClassif->voicing_ch1_fx[i], sub( 16, hStereoClassif->voicing_ch1_e ) ) ) ) ); + hStereoClassif->xtalk_fv_fx[E_d_voicing] = L_add( hStereoClassif->xtalk_fv_fx[E_d_voicing], L_abs( L_sub( voicing_fx[i], hStereoClassif->voicing_ch1_fx[i] ) ) ); move32(); move32(); } @@ -930,11 +923,10 @@ void stereo_classifier_features_ivas_fx( hStereoClassif->non_sta_ch1_fx = non_staX_fx; hStereoClassif->non_sta_ch1_e = non_staX_e; hStereoClassif->sp_div_ch1_fx = sp_div_fx; - hStereoClassif->sp_div_ch1_e = sp_div_e; hStereoClassif->xtalk_fv_fx[E_cor_map_sum] = L_shr( cor_map_sum_fx, sub( 16, cor_map_sum_e ) ); /*q15*/ hStereoClassif->xtalk_fv_fx[E_nchar] = L_shr( BASOP_Util_Loge( L_add( L_shr( hStereoClassif->nchar_ch1_fx, 1 ), L_shl( 1, sub( 30, hStereoClassif->nchar_ch1_e ) ) ), add( hStereoClassif->nchar_ch1_e, 1 ) ) /*q25*/, 10 ); /*q15*/ hStereoClassif->xtalk_fv_fx[E_non_sta] = L_shr( non_staX_fx, sub( 16, non_staX_e ) ); /*q15*/ - hStereoClassif->xtalk_fv_fx[E_sp_div] = L_shr( BASOP_Util_Loge( L_add( L_shr( sp_div_fx, 1 ), L_shl( 1, sub( 31, add( sp_div_e, 1 ) ) ) ), add( sp_div_e, 1 ) ), 10 ); /*q15*/ + hStereoClassif->xtalk_fv_fx[E_sp_div] = L_shr( BASOP_Util_Loge( L_deposit_h( add( shr( sp_div_fx, 1 ), shl( 1, sub( 15 - 1, sp_div_e ) ) ) ), add( sp_div_e, 1 ) ), 10 ); /*q15*/ move32(); move32(); move32(); @@ -951,7 +943,7 @@ void stereo_classifier_features_ivas_fx( hStereoClassif->xtalk_fv_fx[E_d_cor_map_sum] = L_abs( L_sub( L_shr( hStereoClassif->cor_map_sum_ch1_fx, sub( 16, hStereoClassif->cor_map_sum_ch1_e ) ) /*q15*/, L_shr( cor_map_sum_fx, sub( 16, cor_map_sum_e ) ) /*q15*/ ) ); /*q15*/ hStereoClassif->xtalk_fv_fx[E_d_nchar] = L_abs( L_shr( L_sub( BASOP_Util_Loge( L_add( L_shr( hStereoClassif->nchar_ch1_fx, 1 ), L_shl( 1, sub( 30, hStereoClassif->nchar_ch1_e ) ) ), add( hStereoClassif->nchar_ch1_e, 1 ) ), BASOP_Util_Loge( L_add( L_shr( hStereoClassif->nchar_ch2_fx, 1 ), L_shl( 1, sub( 30, hStereoClassif->nchar_ch2_e ) ) ), add( hStereoClassif->nchar_ch2_e, 1 ) ) ) /*q25*/, 10 ) ); /*q15*/ hStereoClassif->xtalk_fv_fx[E_d_non_sta] = L_abs( L_sub( L_shr( hStereoClassif->non_sta_ch1_fx, sub( 16, hStereoClassif->non_sta_ch1_e ) ) /*q15*/, L_shr( non_staX_fx, sub( 16, non_staX_e ) ) /*q15*/ ) ); /*q15*/ - hStereoClassif->xtalk_fv_fx[E_d_sp_div] = L_abs( L_shr( L_sub( BASOP_Util_Loge( L_add( L_shr( hStereoClassif->sp_div_ch1_fx, 1 ), L_shl( 1, sub( 30, hStereoClassif->sp_div_ch1_e ) ) ), add( hStereoClassif->sp_div_ch1_e, 1 ) ), BASOP_Util_Loge( L_add( L_shr( sp_div_fx, 1 ), L_shl( 1, sub( 30, sp_div_e ) ) ), add( sp_div_e, 1 ) ) ) /*q25*/, 10 ) ); /*q15*/ + hStereoClassif->xtalk_fv_fx[E_d_sp_div] = L_abs( L_shr( L_sub( BASOP_Util_Loge( L_deposit_h( add( shr( hStereoClassif->sp_div_ch1_fx, 1 ), shl( 1, sub( 15 - 1, sp_div_e ) ) ) ), add( sp_div_e, 1 ) ), BASOP_Util_Loge( L_deposit_h( add( shr( sp_div_fx, 1 ), shl( 1, sub( 15 - 1, sp_div_e ) ) ) ), add( sp_div_e, 1 ) ) ) /*q25*/, 10 ) ); /*q15*/ move32(); move32(); move32(); diff --git a/lib_enc/ivas_stereo_dft_enc.c b/lib_enc/ivas_stereo_dft_enc.c index 24d57bb0e..901b4855e 100644 --- a/lib_enc/ivas_stereo_dft_enc.c +++ b/lib_enc/ivas_stereo_dft_enc.c @@ -980,9 +980,9 @@ void stereo_dft_enc_reset( STEREO_DFT_ENC_DATA_HANDLE hStereoDft /* i/o: encoder stereo handle */ ) { - int16_t i; /*reset parameters*/ #ifndef IVAS_FLOAT_FIXED + int16_t i; set_zero( hStereoDft->side_gain, STEREO_DFT_ENC_DFT_NB * STEREO_DFT_BAND_MAX ); #endif set_s( hStereoDft->side_gain_index_EC, 15, STEREO_DFT_BAND_MAX ); @@ -1040,12 +1040,12 @@ void stereo_dft_enc_reset( hStereoDft->switch_fade_factor = 0.5f; #endif hStereoDft->res_cod_mode[STEREO_DFT_OFFSET - 1] = STEREO_DFT_RES_COD_1kHz; +#ifndef IVAS_FLOAT_FIXED for ( i = 0; i < STEREO_DFT_BAND_MAX; i++ ) { hStereoDft->res_cod_NRG_M[i] = 0; hStereoDft->res_cod_NRG_S[i] = 0; } -#ifndef IVAS_FLOAT_FIXED hStereoDft->old_snr = 0.f; #endif diff --git a/lib_enc/ivas_stereo_dft_enc_itd.c b/lib_enc/ivas_stereo_dft_enc_itd.c index d19c753c8..d558a4c34 100644 --- a/lib_enc/ivas_stereo_dft_enc_itd.c +++ b/lib_enc/ivas_stereo_dft_enc_itd.c @@ -1424,6 +1424,8 @@ void stereo_dft_enc_compute_itd_fx( Word16 q_temp; Word64 W_temp; Word16 W_temp_q; + Word64 W_temp1; + Word16 W_temp_q1; Word32 tmp; Word16 exp; IF( EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) ) @@ -1498,30 +1500,34 @@ void stereo_dft_enc_compute_itd_fx( // log_prod_L = logf( max( FLT_MIN, ABSVAL( pDFT_L[0] ) ) ); IF( L_abs( pDFT_L[0] ) <= 0 ) { - log_prod_L = -1272712205; + log_prod_L = -1465264128; /* logf(FLT_MIN) in Q24 */ move32(); + log_prod_L_e = 7; + move16(); } ELSE { // log_prod_L = Mpy_32_32( L_add( BASOP_Util_Log2( L_abs( pDFT_L[0] ) ), L_shl( DFT_L_e_tmp[0], 25 ) ), LOG_E_2 ); log_prod_L = BASOP_Util_Loge( L_abs( pDFT_L[0] ), DFT_L_e[0] ); + log_prod_L_e = 6; + move16(); } - log_prod_L_e = 6; - move16(); // log_prod_R = logf( max( FLT_MIN, ABSVAL( pDFT_R[0] ) ) ); IF( L_abs( pDFT_R[0] ) <= 0 ) { - log_prod_R = -1272712205; + log_prod_R = -1465264128; /* logf(FLT_MIN) in Q24 */ move32(); + log_prod_R_e = 7; + move16(); } ELSE { // log_prod_R = Mpy_32_32( L_add( BASOP_Util_Log2( L_abs( pDFT_R[0] ) ), L_shl( DFT_R_e_tmp[0], 25 ) ), LOG_E_2 ); log_prod_R = BASOP_Util_Loge( L_abs( pDFT_R[0] ), DFT_R_e[0] ); + log_prod_R_e = 6; + move16(); } - log_prod_R_e = 6; - move16(); prod_L = MAX_32; // Q31 move32(); @@ -1576,17 +1582,49 @@ void stereo_dft_enc_compute_itd_fx( i = i; }*/ // xcorr[2 * i] = pDFT_L[2 * i] * pDFT_R[2 * i] + pDFT_L[2 * i + 1] * pDFT_R[2 * i + 1]; - xcorr[2 * i] = BASOP_Util_Add_Mant32Exp( Mpy_32_32( pDFT_L[2 * i], pDFT_R[2 * i] ), add( DFT_L_e[2 * i], DFT_R_e[2 * i] ), Mpy_32_32( pDFT_L[2 * i + 1], pDFT_R[2 * i + 1] ), add( DFT_L_e[2 * i + 1], DFT_R_e[2 * i + 1] ), &xcorr_e[2 * i] ); + W_temp = W_mult0_32_32( pDFT_L[2 * i], pDFT_R[2 * i] ); // Q62 - (DFT_L_e[2 * i] + DFT_R_e[2 * i]) + W_temp_q = W_norm( W_temp ); + L_temp = W_extract_h( W_shl( W_temp, W_temp_q ) ); // Q62 - (DFT_L_e[2 * i] + DFT_R_e[2 * i]) + (W_temp_q - Q32) = Q30 + W_temp_q - (DFT_L_e[2 * i] + DFT_R_e[2 * i]) + W_temp_q = add( Q30, sub( W_temp_q, add( DFT_L_e[2 * i], DFT_R_e[2 * i] ) ) ); + W_temp1 = W_mult0_32_32( pDFT_L[2 * i + 1], pDFT_R[2 * i + 1] ); // Q62 - (DFT_L_e[2 * i + 1] + DFT_R_e[2 * i + 1]) + W_temp_q1 = W_norm( W_temp1 ); + L_temp2 = W_extract_h( W_shl( W_temp1, W_temp_q1 ) ); // Q62 - (DFT_L_e[2 * i + 1] + DFT_R_e[2 * i + 1]) + (W_temp_q - Q32) = Q30 + W_temp_q - (DFT_L_e[2 * i + 1] + DFT_R_e[2 * i + 1]) + W_temp_q1 = add( Q30, sub( W_temp_q1, add( DFT_L_e[2 * i + 1], DFT_R_e[2 * i + 1] ) ) ); + xcorr[2 * i] = BASOP_Util_Add_Mant32Exp( L_temp, sub( Q31, W_temp_q ), L_temp2, sub( Q31, W_temp_q1 ), &xcorr_e[2 * i] ); move32(); // xcorr[2 * i + 1] = pDFT_L[2 * i + 1] * pDFT_R[2 * i] - pDFT_L[2 * i] * pDFT_R[2 * i + 1]; - xcorr[2 * i + 1] = BASOP_Util_Add_Mant32Exp( Mpy_32_32( pDFT_L[2 * i + 1], pDFT_R[2 * i] ), add( DFT_L_e[2 * i + 1], DFT_R_e[2 * i] ), L_negate( Mpy_32_32( pDFT_L[2 * i], pDFT_R[2 * i + 1] ) ), add( DFT_L_e[2 * i], DFT_R_e[2 * i + 1] ), &xcorr_e[2 * i + 1] ); + W_temp = W_mult0_32_32( pDFT_L[2 * i + 1], pDFT_R[2 * i] ); // Q62 - (DFT_L_e[2 * i + 1] + DFT_R_e[2 * i]) + W_temp_q = W_norm( W_temp ); + L_temp = W_extract_h( W_shl( W_temp, W_temp_q ) ); // Q62 - (DFT_L_e[2 * i + 1] + DFT_R_e[2 * i]) + (W_temp_q - Q32) = Q30 + W_temp_q - (DFT_L_e[2 * i + 1] + DFT_R_e[2 * i]) + W_temp_q = add( Q30, sub( W_temp_q, add( DFT_L_e[2 * i + 1], DFT_R_e[2 * i] ) ) ); + W_temp1 = W_mult0_32_32( L_negate( pDFT_L[2 * i] ), pDFT_R[2 * i + 1] ); // Q62 - (DFT_L_e[2 * i] + DFT_R_e[2 * i + 1]) + W_temp_q1 = W_norm( W_temp1 ); + L_temp2 = W_extract_h( W_shl( W_temp1, W_temp_q1 ) ); // Q62 - (DFT_L_e[2 * i] + DFT_R_e[2 * i + 1]) + (W_temp_q - Q32) = Q30 + W_temp_q - (DFT_L_e[2 * i] + DFT_R_e[2 * i + 1]) + W_temp_q1 = add( Q30, sub( W_temp_q1, add( DFT_L_e[2 * i], DFT_R_e[2 * i + 1] ) ) ); + xcorr[2 * i + 1] = BASOP_Util_Add_Mant32Exp( L_temp, sub( Q31, W_temp_q ), L_temp2, sub( Q31, W_temp_q1 ), &xcorr_e[2 * i + 1] ); move32(); // pNrgL[i] = pDFT_L[2 * i] * pDFT_L[2 * i] + pDFT_L[2 * i + 1] * pDFT_L[2 * i + 1]; - pNrgL[i] = BASOP_Util_Add_Mant32Exp( Mpy_32_32( pDFT_L[2 * i], pDFT_L[2 * i] ), shl( DFT_L_e[2 * i], 1 ), Mpy_32_32( pDFT_L[2 * i + 1], pDFT_L[2 * i + 1] ), shl( DFT_L_e[2 * i + 1], 1 ), &pNrgL_e[i] ); + W_temp = W_mult0_32_32( pDFT_L[2 * i], pDFT_L[2 * i] ); // Q62 - (DFT_L_e[2 * i] * 2) + W_temp_q = W_norm( W_temp ); + L_temp = W_extract_h( W_shl( W_temp, W_temp_q ) ); // Q62 - (DFT_L_e[2 * i] * 2) + (W_temp_q - Q32) = Q30 + W_temp_q - (DFT_L_e[2 * i] * 2) + W_temp_q = add( Q30, sub( W_temp_q, shl( DFT_L_e[2 * i], 1 ) ) ); + W_temp1 = W_mult0_32_32( pDFT_L[2 * i + 1], pDFT_L[2 * i + 1] ); // Q62 - (DFT_L_e[2 * i + 1] * 2) + W_temp_q1 = W_norm( W_temp1 ); + L_temp2 = W_extract_h( W_shl( W_temp1, W_temp_q1 ) ); // Q62 - (DFT_L_e[2 * i + 1] * 2) + (W_temp_q - Q32) = Q30 + W_temp_q - (DFT_L_e[2 * i + 1] * 2) + W_temp_q1 = add( Q30, sub( W_temp_q1, shl( DFT_L_e[2 * i + 1], 1 ) ) ); + pNrgL[i] = BASOP_Util_Add_Mant32Exp( L_temp, sub( Q31, W_temp_q ), L_temp2, sub( Q31, W_temp_q1 ), &pNrgL_e[i] ); move32(); // pNrgR[i] = pDFT_R[2 * i] * pDFT_R[2 * i] + pDFT_R[2 * i + 1] * pDFT_R[2 * i + 1]; - pNrgR[i] = BASOP_Util_Add_Mant32Exp( Mpy_32_32( pDFT_R[2 * i], pDFT_R[2 * i] ), shl( DFT_R_e[2 * i], 1 ), Mpy_32_32( pDFT_R[2 * i + 1], pDFT_R[2 * i + 1] ), shl( DFT_R_e[2 * i + 1], 1 ), &pNrgR_e[i] ); + W_temp = W_mult0_32_32( pDFT_R[2 * i], pDFT_R[2 * i] ); // Q62 - (DFT_R_e[2 * i] * 2) + W_temp_q = W_norm( W_temp ); + L_temp = W_extract_h( W_shl( W_temp, W_temp_q ) ); // Q62 - (DFT_R_e[2 * i] * 2) + (W_temp_q - Q32) = Q30 + W_temp_q - (DFT_R_e[2 * i] * 2) + W_temp_q = add( Q30, sub( W_temp_q, shl( DFT_R_e[2 * i], 1 ) ) ); + W_temp1 = W_mult0_32_32( pDFT_R[2 * i + 1], pDFT_R[2 * i + 1] ); // Q62 - (DFT_R_e[2 * i + 1] * 2) + W_temp_q1 = W_norm( W_temp1 ); + L_temp2 = W_extract_h( W_shl( W_temp1, W_temp_q1 ) ); // Q62 - (DFT_R_e[2 * i + 1] * 2) + (W_temp_q - Q32) = Q30 + W_temp_q - (DFT_R_e[2 * i + 1] * 2) + W_temp_q1 = add( Q30, sub( W_temp_q1, shl( DFT_R_e[2 * i + 1], 1 ) ) ); + pNrgR[i] = BASOP_Util_Add_Mant32Exp( L_temp, sub( Q31, W_temp_q ), L_temp2, sub( Q31, W_temp_q1 ), &pNrgR_e[i] ); move32(); Spd_L[i] = pNrgL[i]; @@ -1615,11 +1653,17 @@ void stereo_dft_enc_compute_itd_fx( // sum_abs_R += abs_R; sum_abs_R = BASOP_Util_Add_Mant32Exp( sum_abs_R, sum_abs_R_e, abs_R, abs_R_e, &sum_abs_R_e ); // prod_L *= abs_L; - prod_L = Mpy_32_32( prod_L, abs_L ); - prod_L_e = add( prod_L_e, abs_L_e ); + W_temp = W_mult0_32_32( prod_L, abs_L ); // Q62 - (prod_L_e + abs_L_e) + W_temp_q = W_norm( W_temp ); + prod_L = W_extract_h( W_shl( W_temp, W_temp_q ) ); // Q62 - (prod_L_e + abs_L_e) + (W_temp_q - Q32) = Q30 + W_temp_q - (prod_L_e + abs_L_e) + W_temp_q = add( Q30, sub( W_temp_q, add( prod_L_e, abs_L_e ) ) ); + prod_L_e = sub( Q31, W_temp_q ); // prod_R *= abs_R; - prod_R = Mpy_32_32( prod_R, abs_R ); - prod_R_e = add( prod_R_e, abs_R_e ); + W_temp = W_mult0_32_32( prod_R, abs_R ); // Q62 - (prod_R_e + abs_R_e) + W_temp_q = W_norm( W_temp ); + prod_R = W_extract_h( W_shl( W_temp, W_temp_q ) ); // Q62 - (prod_R_e + abs_R_e) + (W_temp_q - Q32) = Q30 + W_temp_q - (prod_R_e + abs_R_e) + W_temp_q = add( Q30, sub( W_temp_q, add( prod_R_e, abs_R_e ) ) ); + prod_R_e = sub( Q31, W_temp_q ); // grand_dot_prod_real += xcorr[2 * i]; grand_dot_prod_real = BASOP_Util_Add_Mant32Exp( grand_dot_prod_real, grand_dot_prod_real_e, xcorr[2 * i], xcorr_e[2 * i], &grand_dot_prod_real_e ); @@ -1648,9 +1692,9 @@ void stereo_dft_enc_compute_itd_fx( prod_R = L_max( 0, prod_R ); IF( prod_L <= 0 ) { - L_temp = -1272712205; + L_temp = -1465264128; /* logf(FLT_MIN) in Q24 */ move32(); - L_temp_e = 6; + L_temp_e = 7; move16(); } ELSE @@ -1664,9 +1708,9 @@ void stereo_dft_enc_compute_itd_fx( IF( L_abs( prod_R ) <= 0 ) { - L_temp = -1272712205; + L_temp = -1465264128; /* logf(FLT_MIN) in Q24 */ move32(); - L_temp_e = 6; + L_temp_e = 7; move16(); } ELSE @@ -1839,7 +1883,7 @@ void stereo_dft_enc_compute_itd_fx( move32(); L_temp_e = 0; move16(); - FOR( i = 0; i < 11; i++ ) + FOR( Word16 ii = 0; ii < 11; ii++ ) { L_temp = BASOP_Util_Add_Mant32Exp( L_temp, L_temp_e, Spd_L[i + 1], Spd_L_e[i + 1], &L_temp_e ); } @@ -1912,17 +1956,49 @@ void stereo_dft_enc_compute_itd_fx( FOR( ; i < NFFT / 2; i++ ) { // xcorr[2 * i] = pDFT_L[2 * i] * pDFT_R[2 * i] + pDFT_L[2 * i + 1] * pDFT_R[2 * i + 1]; - xcorr[2 * i] = BASOP_Util_Add_Mant32Exp( Mpy_32_32( pDFT_L[2 * i], pDFT_R[2 * i] ), add( DFT_L_e[2 * i], DFT_R_e[2 * i] ), Mpy_32_32( pDFT_L[2 * i + 1], pDFT_R[2 * i + 1] ), add( DFT_L_e[2 * i + 1], DFT_R_e[2 * i + 1] ), &xcorr_e[2 * i] ); + W_temp = W_mult0_32_32( pDFT_L[2 * i], pDFT_R[2 * i] ); // Q62 - (DFT_L_e[2 * i] + DFT_R_e[2 * i]) + W_temp_q = W_norm( W_temp ); + L_temp = W_extract_h( W_shl( W_temp, W_temp_q ) ); // Q62 - (DFT_L_e[2 * i] + DFT_R_e[2 * i]) + (W_temp_q - Q32) = Q30 + W_temp_q - (DFT_L_e[2 * i] + DFT_R_e[2 * i]) + W_temp_q = add( Q30, sub( W_temp_q, add( DFT_L_e[2 * i], DFT_R_e[2 * i] ) ) ); + W_temp1 = W_mult0_32_32( pDFT_L[2 * i + 1], pDFT_R[2 * i + 1] ); // Q62 - (DFT_L_e[2 * i + 1] + DFT_R_e[2 * i + 1]) + W_temp_q1 = W_norm( W_temp1 ); + L_temp2 = W_extract_h( W_shl( W_temp1, W_temp_q1 ) ); // Q62 - (DFT_L_e[2 * i + 1] + DFT_R_e[2 * i + 1]) + (W_temp_q - Q32) = Q30 + W_temp_q - (DFT_L_e[2 * i + 1] + DFT_R_e[2 * i + 1]) + W_temp_q1 = add( Q30, sub( W_temp_q1, add( DFT_L_e[2 * i + 1], DFT_R_e[2 * i + 1] ) ) ); + xcorr[2 * i] = BASOP_Util_Add_Mant32Exp( L_temp, sub( Q31, W_temp_q ), L_temp2, sub( Q31, W_temp_q1 ), &xcorr_e[2 * i] ); move32(); // xcorr[2 * i + 1] = pDFT_L[2 * i + 1] * pDFT_R[2 * i] - pDFT_L[2 * i] * pDFT_R[2 * i + 1]; - xcorr[2 * i + 1] = BASOP_Util_Add_Mant32Exp( Mpy_32_32( pDFT_L[2 * i + 1], pDFT_R[2 * i] ), add( DFT_L_e[2 * i + 1], DFT_R_e[2 * i] ), L_negate( Mpy_32_32( pDFT_L[2 * i], pDFT_R[2 * i + 1] ) ), add( DFT_L_e[2 * i], DFT_R_e[2 * i + 1] ), &xcorr_e[2 * i + 1] ); + W_temp = W_mult0_32_32( pDFT_L[2 * i + 1], pDFT_R[2 * i] ); // Q62 - (DFT_L_e[2 * i + 1] + DFT_R_e[2 * i]) + W_temp_q = W_norm( W_temp ); + L_temp = W_extract_h( W_shl( W_temp, W_temp_q ) ); // Q62 - (DFT_L_e[2 * i + 1] + DFT_R_e[2 * i]) + (W_temp_q - Q32) = Q30 + W_temp_q - (DFT_L_e[2 * i + 1] + DFT_R_e[2 * i]) + W_temp_q = add( Q30, sub( W_temp_q, add( DFT_L_e[2 * i + 1], DFT_R_e[2 * i] ) ) ); + W_temp1 = W_mult0_32_32( L_negate( pDFT_L[2 * i] ), pDFT_R[2 * i + 1] ); // Q62 - (DFT_L_e[2 * i] + DFT_R_e[2 * i + 1]) + W_temp_q1 = W_norm( W_temp1 ); + L_temp2 = W_extract_h( W_shl( W_temp1, W_temp_q1 ) ); // Q62 - (DFT_L_e[2 * i] + DFT_R_e[2 * i + 1]) + (W_temp_q - Q32) = Q30 + W_temp_q - (DFT_L_e[2 * i] + DFT_R_e[2 * i + 1]) + W_temp_q1 = add( Q30, sub( W_temp_q1, add( DFT_L_e[2 * i], DFT_R_e[2 * i + 1] ) ) ); + xcorr[2 * i + 1] = BASOP_Util_Add_Mant32Exp( L_temp, sub( Q31, W_temp_q ), L_temp2, sub( Q31, W_temp_q1 ), &xcorr_e[2 * i + 1] ); move32(); // pNrgL[i] = pDFT_L[2 * i] * pDFT_L[2 * i] + pDFT_L[2 * i + 1] * pDFT_L[2 * i + 1]; - pNrgL[i] = BASOP_Util_Add_Mant32Exp( Mpy_32_32( pDFT_L[2 * i], pDFT_L[2 * i] ), shl( DFT_L_e[2 * i], 1 ), Mpy_32_32( pDFT_L[2 * i + 1], pDFT_L[2 * i + 1] ), shl( DFT_L_e[2 * i + 1], 1 ), &pNrgL_e[i] ); + W_temp = W_mult0_32_32( pDFT_L[2 * i], pDFT_L[2 * i] ); // Q62 - (DFT_L_e[2 * i] * 2) + W_temp_q = W_norm( W_temp ); + L_temp = W_extract_h( W_shl( W_temp, W_temp_q ) ); // Q62 - (DFT_L_e[2 * i] * 2) + (W_temp_q - Q32) = Q30 + W_temp_q - (DFT_L_e[2 * i] * 2) + W_temp_q = add( Q30, sub( W_temp_q, shl( DFT_L_e[2 * i], 1 ) ) ); + W_temp1 = W_mult0_32_32( pDFT_L[2 * i + 1], pDFT_L[2 * i + 1] ); // Q62 - (DFT_L_e[2 * i + 1] * 2) + W_temp_q1 = W_norm( W_temp1 ); + L_temp2 = W_extract_h( W_shl( W_temp1, W_temp_q1 ) ); // Q62 - (DFT_L_e[2 * i + 1] * 2) + (W_temp_q - Q32) = Q30 + W_temp_q - (DFT_L_e[2 * i + 1] * 2) + W_temp_q1 = add( Q30, sub( W_temp_q1, shl( DFT_L_e[2 * i + 1], 1 ) ) ); + pNrgL[i] = BASOP_Util_Add_Mant32Exp( L_temp, sub( Q31, W_temp_q ), L_temp2, sub( Q31, W_temp_q1 ), &pNrgL_e[i] ); move32(); // pNrgR[i] = pDFT_R[2 * i] * pDFT_R[2 * i] + pDFT_R[2 * i + 1] * pDFT_R[2 * i + 1]; - pNrgR[i] = BASOP_Util_Add_Mant32Exp( Mpy_32_32( pDFT_R[2 * i], pDFT_R[2 * i] ), shl( DFT_R_e[2 * i], 1 ), Mpy_32_32( pDFT_R[2 * i + 1], pDFT_R[2 * i + 1] ), shl( DFT_R_e[2 * i + 1], 1 ), &pNrgR_e[i] ); + W_temp = W_mult0_32_32( pDFT_R[2 * i], pDFT_R[2 * i] ); // Q62 - (DFT_R_e[2 * i] * 2) + W_temp_q = W_norm( W_temp ); + L_temp = W_extract_h( W_shl( W_temp, W_temp_q ) ); // Q62 - (DFT_R_e[2 * i] * 2) + (W_temp_q - Q32) = Q30 + W_temp_q - (DFT_R_e[2 * i] * 2) + W_temp_q = add( Q30, sub( W_temp_q, shl( DFT_R_e[2 * i], 1 ) ) ); + W_temp1 = W_mult0_32_32( pDFT_R[2 * i + 1], pDFT_R[2 * i + 1] ); // Q62 - (DFT_R_e[2 * i + 1] * 2) + W_temp_q1 = W_norm( W_temp1 ); + L_temp2 = W_extract_h( W_shl( W_temp1, W_temp_q1 ) ); // Q62 - (DFT_R_e[2 * i + 1] * 2) + (W_temp_q - Q32) = Q30 + W_temp_q - (DFT_R_e[2 * i + 1] * 2) + W_temp_q1 = add( Q30, sub( W_temp_q1, shl( DFT_R_e[2 * i + 1], 1 ) ) ); + pNrgR[i] = BASOP_Util_Add_Mant32Exp( L_temp, sub( Q31, W_temp_q ), L_temp2, sub( Q31, W_temp_q1 ), &pNrgR_e[i] ); move32(); /* Calculate L and R energy power spectrum */ Spd_L[i] = pNrgL[i]; @@ -2318,7 +2394,7 @@ void stereo_dft_enc_compute_itd_fx( hItd->xcorr_smooth_fx[i] = L_shr_r( hItd->xcorr_smooth_fx[i], sub( hItd->xcorr_smooth_fx_e, xcorr_smooth_fx_tmp_e[i] ) ); move32(); } - max_exp = 0; + max_exp = MIN_16; move16(); FOR( i = 0; i < STEREO_DFT_N_32k_ENC; i++ ) { diff --git a/lib_enc/ivas_stereo_dft_td_itd.c b/lib_enc/ivas_stereo_dft_td_itd.c index a61ee2250..3462f614b 100644 --- a/lib_enc/ivas_stereo_dft_td_itd.c +++ b/lib_enc/ivas_stereo_dft_td_itd.c @@ -141,7 +141,7 @@ static void stereo_td_get_td_itd_fx( d = BASOP_Util_Divide3232_Scale( input_Fs, 16000, &d_e ); temp_div = BASOP_Util_Divide3232_Scale( itd, L_deposit_h( d ), &temp_e ); temp_e = add( temp_e, sub( sub( 31, q_itd ), d_e ) ); // e+(e1-e2)// - temp_add = add_sat( temp_div, shr( FLR_FX, temp_e ) ); + temp_add = add_sat( temp_div, shr_sat( FLR_FX, temp_e ) ); *td_itd_32 = shl( shr( temp_add, sub( 15, temp_e ) ), 1 ); move16(); diff --git a/lib_enc/ivas_stereo_ica_enc.c b/lib_enc/ivas_stereo_ica_enc.c index 6cad92d83..bd8a947d7 100644 --- a/lib_enc/ivas_stereo_ica_enc.c +++ b/lib_enc/ivas_stereo_ica_enc.c @@ -1821,9 +1821,20 @@ static void estDownmixGain_fx( currentGain = BASOP_Util_Divide3232_Scale( tempN, tempD, &exp ); currentGain_e = exp; move16(); + if ( currentGain == 0 ) + { + currentGain_e = 0; + move16(); + } } - currentGain = s_max( EPSILON_FX, currentGain ); + IF( GT_32( EPSILON_FX, currentGain ) ) + { + currentGain = EPSILON_FX; + move16(); + currentGain_e = 0; + move16(); + } hStereoTCA->instTargetGain_fx = L_shl_sat( L_deposit_h( currentGain ), sub( currentGain_e, 2 ) ); move32(); prevTargetGain_log10 = BASOP_Util_Log10( hStereoTCA->prevTargetGain_fx, 2 ); // Output in Q25 @@ -1845,6 +1856,11 @@ static void estDownmixGain_fx( tempD = BASOP_util_Pow2( L_mult( currentGain, 27213 ), add( currentGain_e, Q2 ), &exp ); unclr_instTargetGain = L_deposit_h( BASOP_Util_Divide3232_Scale( tempN, L_add( tempD, EPSILON_FX ), &exp_div ) ); exp = add( sub( exp_chan, exp ), exp_div ); + if ( unclr_instTargetGain == 0 ) + { + exp = 0; + move16(); + } unclr_instTargetGain = BASOP_Util_Log10( L_add( unclr_instTargetGain, L_shr( MAX_32, sub( Q31, exp ) ) ), exp ); // unclr_fv_fx is expected in Q15 - log result will be in Q25 - hence rightshift by 10. hStereoClassif->unclr_fv_fx[E_ica_instTargetGain] = L_shr( unclr_instTargetGain, Q10 ); @@ -2314,8 +2330,8 @@ void stereo_tca_enc_fx( } /* populate L/R memories into current buffers */ - Word16 tempp_scale = getScaleFactor32( hStereoTCA->memChanL_fx, L_MEM_RECALC_48K + L_MEM_RECALC_48k_SCH ); - tempp_scale = s_min( tempp_scale, getScaleFactor32( hStereoTCA->memChanR_fx, L_MEM_RECALC_48K + L_MEM_RECALC_48k_SCH ) ); + Word16 tempp_scale = L_norm_arr( hStereoTCA->memChanL_fx, L_MEM_RECALC_48K + L_MEM_RECALC_48k_SCH ); + tempp_scale = s_min( tempp_scale, L_norm_arr( hStereoTCA->memChanR_fx, L_MEM_RECALC_48K + L_MEM_RECALC_48k_SCH ) ); scale_sig32( hStereoTCA->memChanL_fx, L_MEM_RECALC_48K + L_MEM_RECALC_48k_SCH, tempp_scale ); scale_sig32( hStereoTCA->memChanR_fx, L_MEM_RECALC_48K + L_MEM_RECALC_48k_SCH, tempp_scale ); hStereoTCA->memChan_q = add( hStereoTCA->memChan_q, tempp_scale ); @@ -2684,14 +2700,18 @@ void stereo_tca_enc_fx( /* quantize the corrStats */ Word16 temp_exp, tempF_16fx; - Word16 scalar_value = BASOP_Util_Divide3232_Scale( currentNCShift, dsFactor, &temp_exp ); - if ( scalar_value == 0 ) + Word16 scalar_value = BASOP_Util_Divide1616_Scale( currentNCShift, dsFactor, &temp_exp ); + IF( temp_exp < 0 ) { - temp_exp = 14; + scalar_value = shl( scalar_value, sub( temp_exp, Q3 ) ); // Q12 + hStereoTCA->indx_ica_NCShift = usquant_fx( scalar_value, &tempF_16fx, 0, ONE_IN_Q11, 1 << STEREO_BITS_TCA_CORRSTATS ); + move16(); + } + ELSE + { + hStereoTCA->indx_ica_NCShift = usquant_fx( scalar_value, &tempF_16fx, 0, shl( 1, sub( 14, temp_exp ) ), 1 << STEREO_BITS_TCA_CORRSTATS ); move16(); } - hStereoTCA->indx_ica_NCShift = usquant_fx( scalar_value, &tempF_16fx, 0, shl( 1, sub( 14, temp_exp ) ), 1 << STEREO_BITS_TCA_CORRSTATS ); - move16(); tempF_fx = tempF_16fx; move32(); } diff --git a/lib_enc/ivas_stereo_td_analysis.c b/lib_enc/ivas_stereo_td_analysis.c index c745013c2..20bc57c1d 100644 --- a/lib_enc/ivas_stereo_td_analysis.c +++ b/lib_enc/ivas_stereo_td_analysis.c @@ -2823,8 +2823,8 @@ Word16 tdm_lp_comparison_fx( const Word16 *A_PCh_fx, /* i : primary channel LP coefficients Q12*/ const Word16 *A_SCh_fx, /* i : secondary channel LP coeff. Q12*/ const Word16 m, /* i : filter length */ - const Word32 *isp_PCh_fx, /* i : primary channel LSPs Q31 */ - const Word32 *isp_SCh_fx, /* i : secondary channel LSPs Q31 */ + const Word16 *isp_PCh_fx, /* i : primary channel LSPs Q15 */ + const Word16 *isp_SCh_fx, /* i : secondary channel LSPs Q15 */ const Word16 L_frame, /* i : frame length */ const Word32 element_brate_wo_meta, /* i : element bitrate without metadata*/ Word16 Q_speech ) @@ -2879,7 +2879,7 @@ Word16 tdm_lp_comparison_fx( FOR( i = 0; i < m; i++ ) { // ftmp = isp_SCh[i] - isp_PCh[i]; - ftmp_fx = L_sub( isp_SCh_fx[i], isp_PCh_fx[i] ); + ftmp_fx = L_deposit_h( sub( isp_SCh_fx[i], isp_PCh_fx[i] ) ); // dist += ftmp * ftmp; dist_fx = L_add( dist_fx, L_shr( Mpy_32_32( ftmp_fx, ftmp_fx ), gb ) ); // Q31-gb } diff --git a/lib_enc/lsf_enc_fx.c b/lib_enc/lsf_enc_fx.c index c2635ec42..8cc57eb2d 100644 --- a/lib_enc/lsf_enc_fx.c +++ b/lib_enc/lsf_enc_fx.c @@ -579,11 +579,11 @@ void lsf_enc_ivas_fx( } /* LSP interpolation and conversion of LSPs to A(z) - two-subframe mode */ - int_lsp4_fx( st->L_frame, st->lsp_old_fx, lsp_mid, lsp_new, Aq, M, -2 ); + int_lsp4_ivas_fx( st->L_frame, st->lsp_old_fx, lsp_mid, lsp_new, Aq, M, -2 ); } ELSE { - int_lsp4_fx( st->L_frame, st->lsp_old_fx, lsp_mid, lsp_new, Aq, M, 0 ); + int_lsp4_ivas_fx( st->L_frame, st->lsp_old_fx, lsp_mid, lsp_new, Aq, M, 0 ); } /*------------------------------------------------------------------* * Check LSF stability (distance between old LSFs and current LSFs) diff --git a/lib_enc/nois_est_fx.c b/lib_enc/nois_est_fx.c index d5f2028f0..eb04543a4 100644 --- a/lib_enc/nois_est_fx.c +++ b/lib_enc/nois_est_fx.c @@ -2153,7 +2153,7 @@ void noise_est_ivas_fx( Word16 *ncharX, /* o : Q11 */ Word16 *sp_div, /* o : Q_sp_div */ Word16 *Q_sp_div, /* o : Q factor for sp_div */ - Word16 *non_staX, /* o : non-stationarity for sp/mus classifier */ + Word16 *non_staX, /* o : non-stationarity for sp/mus classifier Q8 */ Word16 *loc_harm, /* o : multi-harmonicity flag for UV classifier */ const Word32 *lf_E, /* i : per bin energy for low frequencies Q_new + Q_SCALE -2 */ Word16 *st_harm_cor_cnt, /* i/o : 1st harm correlation timer Q0 */ diff --git a/lib_enc/speech_music_classif.c b/lib_enc/speech_music_classif.c index 1e937bf73..bf74ed5ad 100644 --- a/lib_enc/speech_music_classif.c +++ b/lib_enc/speech_music_classif.c @@ -142,6 +142,8 @@ void speech_music_clas_init( #endif hSpMusClas->sp_mus_state = -8; + set32_fx( hSpMusClas->past_PS_fx, 0, HIGHEST_FBIN - LOWEST_FBIN ); + hSpMusClas->past_PS_Q = Q31; #ifndef IVAS_FLOAT_FIXED hSpMusClas->wdrop = 0.0f; hSpMusClas->wrise = 0.0f; @@ -150,9 +152,7 @@ void speech_music_clas_init( set_f( hSpMusClas->last_lsp, 0.0f, M_LSP_SPMUS ); hSpMusClas->last_cor_map_sum = 0.0f; hSpMusClas->last_non_sta = 0.0f; -#endif set_f( hSpMusClas->past_PS, 0.0f, HIGHEST_FBIN - LOWEST_FBIN ); -#ifndef IVAS_FLOAT_FIXED hSpMusClas->past_ps_diff = 0; hSpMusClas->past_epsP2 = 01; hSpMusClas->past_epsP = 0; @@ -232,17 +232,18 @@ void speech_music_clas_init( hSpMusClas->mov_log_max_spl = 200.0f; hSpMusClas->old_lt_diff[0] = 0.0f; hSpMusClas->old_lt_diff[1] = 0.0f; -#endif - set_f( hSpMusClas->finc_prev, 0.0f, ATT_NSEG ); hSpMusClas->lt_finc = 0.0f; +#endif + hSpMusClas->last_strong_attack = 0; #ifdef IVAS_FLOAT_FIXED hSpMusClas->tdm_lt_Etot_fx = 328 /* 0.01 in Q15*/; + set32_fx( hSpMusClas->tod_lt_Bin_E_fx, 0, TOD_NSPEC ); #else hSpMusClas->tdm_lt_Etot = 0.01f; -#endif set_f( hSpMusClas->tod_lt_Bin_E, 0.0f, TOD_NSPEC ); +#endif #ifndef IVAS_FLOAT_FIXED set_f( hSpMusClas->tod_S_map_lt, 0.0f, TOD_NSPEC ); hSpMusClas->tod_thr_lt = TOD_THR_MASS; diff --git a/lib_enc/speech_music_classif_fx.c b/lib_enc/speech_music_classif_fx.c index cc240abe4..b7c079905 100644 --- a/lib_enc/speech_music_classif_fx.c +++ b/lib_enc/speech_music_classif_fx.c @@ -1740,15 +1740,14 @@ Word16 ivas_smc_gmm_fx( STEREO_CLASSIF_HANDLE hStereoClassif, /* i/o: stereo classifier structure */ const Word16 localVAD_HE_SAD, /* i : HE-SAD flag without hangover */ const Word16 Etot_fx, /* i : total frame energy */ - Word16 lsp_new_fx[M], /* i : LSPs in current frame TODO:For now removing 'const' to avoid warning */ - Word16 cor_map_sum_fx, /* i : correlation map sum (from multi-harmonic anal.) */ - Word32 epsP_fx[M + 1], /* i : LP prediciton error TODO:For now removing 'const' to avoid warning */ - Word32 PS_fx[], /* i : energy spectrum TODO:For now removing 'const' to avoid warning */ - const Word16 non_sta_fx, /* i : unbound non-stationarity */ - const Word16 relE_fx, /* i : relative frame energy */ + const Word16 lsp_new_fx[M], /* i : LSPs in current frame Q15 */ + const Word16 cor_map_sum_fx, /* i : correlation map sum (from multi-harmonic anal.) Q8 */ + const Word32 epsP_fx[M + 1], /* i : LP prediciton error */ + const Word32 PS_fx[], /* i : energy spectrum */ + const Word16 non_sta_fx, /* i : unbound non-stationarity Q8 */ + const Word16 relE_fx, /* i : relative frame energy Q8 */ Word16 *high_lpn_flag, /* i/o: sp/mus LPN flag */ - const Word16 flag_spitch /* i : flag to indicate very short stable pitch */ - , + const Word16 flag_spitch, /* i : flag to indicate very short stable pitch */ Word16 Qfact_PS, Word16 Q_esp, Word16 Qfact_PS_past ) @@ -2020,11 +2019,11 @@ Word16 ivas_smc_gmm_fx( *pFV++ = acosf( lsp_new[6] );*/ /* [7] cor_map_sum */ - *pFV_fx++ = L_shl( cor_map_sum_fx, Q12 ); + *pFV_fx++ = L_shl( cor_map_sum_fx, Q12 ); /*scaling from Q8 to Q20*/ move32(); /* [8] non_sta */ - *pFV_fx++ = L_shl( non_sta_fx, Q14 ); /*scaling from 6 to 20*/ + *pFV_fx++ = L_shl( non_sta_fx, Q12 ); /*scaling from Q8 to Q20*/ move32(); /* [9] epsP */ diff --git a/lib_enc/stat_enc.h b/lib_enc/stat_enc.h index 605fbbdbe..223778e89 100644 --- a/lib_enc/stat_enc.h +++ b/lib_enc/stat_enc.h @@ -394,21 +394,21 @@ typedef struct cldfb_vad_structure typedef struct td_cng_enc_structure { - int16_t lp_cng_mode2; + Word16 lp_cng_mode2; #ifndef IVAS_FLOAT_FIXED float lp_ener; /* CNG and DTX - low-pass filtered energy for CNG */ #else Word32 lp_ener_fx; /* CNG and DTX - low-pass filtered energy for CNG Q6 */ #endif - int16_t cng_seed; /* CNG and DTX - seed for white noise random generator */ - int16_t old_enr_index; /* CNG and DTX - index of last encoded CNG energy */ + Word16 cng_seed; /* CNG and DTX - seed for white noise random generator */ + Word16 old_enr_index; /* CNG and DTX - index of last encoded CNG energy */ #ifndef IVAS_FLOAT_FIXED float Enew; /* CNG and DTX - CNG target residual energy */ #else Word32 Enew_fx; /* CNG and DTX - CNG target residual energy Q6 */ #endif - int16_t cng_hist_ptr; /* CNG and DTX - pointer for averaging buffers */ + Word16 cng_hist_ptr; /* CNG and DTX - pointer for averaging buffers */ #ifndef IVAS_FLOAT_FIXED float cng_lsp_hist[DTX_HIST_SIZE * M]; /* CNG and DTX - old LSP buffer for averaging */ float cng_ener_hist[DTX_HIST_SIZE]; /* CNG and DTX - log energy buffer for averaging */ @@ -416,17 +416,17 @@ typedef struct td_cng_enc_structure Word16 cng_lsp_hist_fx[DTX_HIST_SIZE * M]; /* CNG and DTX - old LSP buffer for averaging Q15 */ Word16 cng_ener_hist_fx[DTX_HIST_SIZE]; /* CNG and DTX - log energy buffer for averaging Q8 */ #endif - int16_t cng_ener_seed; /* CNG and DTX - seed for random generator for variation of excitation energy */ - int16_t cng_ener_seed1; + Word16 cng_ener_seed; /* CNG and DTX - seed for random generator for variation of excitation energy */ + Word16 cng_ener_seed1; #ifndef IVAS_FLOAT_FIXED float lp_sp_enr; #else Word16 lp_sp_enr_fx; /* Q8 */ #endif - int16_t last_allow_cn_step; - int16_t ho_hist_size; /* CNG and DTX - size of DTX hangover history buffer for averaging, <0,HO_HIST_SIZE> */ - int16_t ho_hist_ptr; /* CNG and DTX - pointer for averaging buffers */ - int32_t ho_sid_bw; /* CNG and DTX - SID bandwidth flags */ + Word16 last_allow_cn_step; + Word16 ho_hist_size; /* CNG and DTX - size of DTX hangover history buffer for averaging, <0,HO_HIST_SIZE> */ + Word16 ho_hist_ptr; /* CNG and DTX - pointer for averaging buffers */ + int32_t ho_sid_bw; /* CNG and DTX - SID bandwidth flags */ #ifndef IVAS_FLOAT_FIXED float ho_lsp_hist[HO_HIST_SIZE * M]; /* CNG and DTX - old LSP buffer for averaging */ float ho_ener_hist[HO_HIST_SIZE]; /* CNG and DTX - energy buffer for averaging */ @@ -437,9 +437,9 @@ typedef struct td_cng_enc_structure Word32 ho_env_hist_fx[HO_HIST_SIZE * NUM_ENV_CNG]; /* Q6 */ #endif - int16_t act_cnt; /* CNG and DTX - counter of active frames */ - int16_t ho_circ_size; /* CNG and DTX - size of DTX hangover history buffer for averaging, <0,HO_HIST_SIZE> */ - int16_t ho_circ_ptr; /* CNG and DTX - pointer for averaging buffers */ + Word16 act_cnt; /* CNG and DTX - counter of active frames */ + Word16 ho_circ_size; /* CNG and DTX - size of DTX hangover history buffer for averaging, <0,HO_HIST_SIZE> */ + Word16 ho_circ_ptr; /* CNG and DTX - pointer for averaging buffers */ #ifndef IVAS_FLOAT_FIXED float ho_lsp_circ[HO_HIST_SIZE * M]; /* CNG and DTX - old LSP buffer for averaging */ float ho_ener_circ[HO_HIST_SIZE]; /* CNG and DTX - energy buffer for averaging */ @@ -449,8 +449,8 @@ typedef struct td_cng_enc_structure Word32 ho_ener_circ_fx[HO_HIST_SIZE]; /* CNG and DTX - energy buffer for averaging Q6 */ Word32 ho_env_circ_fx[HO_HIST_SIZE * NUM_ENV_CNG]; /* Q6 */ #endif - int16_t burst_ho_cnt; /* CNG and DTX - counter of hangover frames at end of active burst */ - int16_t cng_buf_cnt; /* CNG and DTX - Counter of buffered CNG parameters */ + Word16 burst_ho_cnt; /* CNG and DTX - counter of hangover frames at end of active burst */ + Word16 cng_buf_cnt; /* CNG and DTX - Counter of buffered CNG parameters */ float cng_exc2_buf_flt[HO_HIST_SIZE * L_FFT]; /* CNG and DTX - exc2 buffer for storing */ Word16 cng_exc2_buf[HO_HIST_SIZE * L_FFT]; /* CNG and DTX - exc2 buffer for storing */ Word16 cng_Qexc_buf[HO_HIST_SIZE]; /* CNG and DTX - Q_exc buffer for storing */ @@ -460,32 +460,32 @@ typedef struct td_cng_enc_structure #else Word16 CNG_att_fx; /* CNG and DTX - attenuation factor for CNG, in dB Q7 */ #endif - int16_t ho_16k_lsp[HO_HIST_SIZE]; /* CNG and DTX - 16k LSPs flags */ - int16_t act_cnt2; /* CNG and DTX - counter of active frames for CNG_mode switching */ + Word16 ho_16k_lsp[HO_HIST_SIZE]; /* CNG and DTX - 16k LSPs flags */ + Word16 act_cnt2; /* CNG and DTX - counter of active frames for CNG_mode switching */ #ifndef IVAS_FLOAT_FIXED float ho_lsp_circ2[HO_HIST_SIZE * M]; /* CNG and DTX - second buffer of LSPs */ #else Word16 ho_lsp_circ2_fx[HO_HIST_SIZE * M]; /* CNG and DTX - second buffer of LSPs Q15 */ #endif - int16_t num_ho; /* CNG and DTX - number of selected hangover frames */ + Word16 num_ho; /* CNG and DTX - number of selected hangover frames */ #ifndef IVAS_FLOAT_FIXED float old_env[NUM_ENV_CNG]; float lp_env[NUM_ENV_CNG]; float cng_res_env[NUM_ENV_CNG * HO_HIST_SIZE]; + float exc_mem[24]; + float exc_mem1[30]; + float exc_mem2[30]; #else Word32 old_env_fx[NUM_ENV_CNG]; /* Q6 */ Word32 lp_env_fx[NUM_ENV_CNG]; /* Q6 */ Word32 cng_res_env_fx[NUM_ENV_CNG * HO_HIST_SIZE]; /* Q6 */ #endif - float exc_mem[24]; - float exc_mem1[30]; - float exc_mem2[30]; Word16 exc_mem_fx[24]; Word16 exc_mem1_fx[30]; Word16 exc_mem2_fx[30]; /* SWB DTX/CNG parameters */ - int16_t last_vad; + Word16 last_vad; #ifndef IVAS_FLOAT_FIXED float last_wb_cng_ener; float last_shb_cng_ener; @@ -497,10 +497,10 @@ typedef struct td_cng_enc_structure Word16 mov_wb_cng_ener_fx; /* Q8 */ Word16 mov_shb_cng_ener_fx; /* Q8 */ #endif - int16_t last_idx_ener; - int16_t shb_cng_ini_cnt; - int16_t last_SID_bwidth; - int16_t shb_NO_DATA_cnt; + Word16 last_idx_ener; + Word16 shb_cng_ini_cnt; + Word16 last_SID_bwidth; + Word16 shb_NO_DATA_cnt; } TD_CNG_ENC_DATA, *TD_CNG_ENC_HANDLE; @@ -647,7 +647,6 @@ typedef struct igf_enc_private_data_struct IGF_INFO igfInfo; Word16 igfScfQuantized[IGF_MAX_SFB]; IGFSCFENC_INSTANCE hIGFSCFArithEnc; -#ifdef IVAS_FLOAT_FIXED Word16 prevSFM_FIR_SFB_TB_fx[IGF_MAX_SFB]; Word16 prevSFB_FIR_TB_e[IGF_MAX_SFB]; Word16 prevSFB_IIR_TB_e[IGF_MAX_SFB]; @@ -663,7 +662,6 @@ typedef struct igf_enc_private_data_struct Word16 prevDampingFactor_IIR_fx[IGF_MAX_SFB]; Word16 prevDampingFactor_IIR_e[IGF_MAX_SFB]; Word16 igfPastSFM_fx[IGF_MAX_TILES][IGF_PAST_SFM_LEN]; /*2Q13*/ -#endif // IVAS_FLOAT_FIXED Word16 logSpec[L_FRAME_PLUS]; @@ -810,9 +808,10 @@ typedef struct sp_mus_clas_structure #else Word32 FV_st_fx[N_SMC_FEATURES]; /* Speech/music classifier - short-term mean of the feature vector Q20 */ #endif - float past_PS[HIGHEST_FBIN - LOWEST_FBIN]; + Word16 past_PS_Q; Word32 past_PS_fx[HIGHEST_FBIN - LOWEST_FBIN]; #ifndef IVAS_FLOAT_FIXED + float past_PS[HIGHEST_FBIN - LOWEST_FBIN]; float past_ps_diff; float prev_FV[N_SMC_FEATURES]; float past_epsP; @@ -823,7 +822,7 @@ typedef struct sp_mus_clas_structure Word16 past_epsP_fx; Word16 past_epsP2_fx; /* Q10 */ #endif - int16_t inact_cnt; + Word16 inact_cnt; #ifndef IVAS_FLOAT_FIXED float wdrop; float wrise; @@ -836,8 +835,8 @@ typedef struct sp_mus_clas_structure Word32 wdlp_0_95_sp_32fx; /* IVAS - Q24 */ Word32 wdlp_xtalk_fx; /* Q19 */ #endif - int16_t sp_mus_state; - int16_t past_dec[HANG_LEN - 1]; /* Speech/music classifier - buffer of past binary decisions */ + Word16 sp_mus_state; + Word16 past_dec[HANG_LEN - 1]; /* Speech/music classifier - buffer of past binary decisions */ #ifndef IVAS_FLOAT_FIXED float past_dlp[HANG_LEN - 1]; /* Speech/music classifier - buffer of past non-binary decisions */ float past_dlp_mean_ST[HANG_LEN - 1]; /* Speech/music classifier - buffer of past non-binary decisions (with ST smoothing) */ @@ -847,7 +846,7 @@ typedef struct sp_mus_clas_structure Word32 past_dlp_mean_ST_fx[HANG_LEN - 1]; /* Speech/music classifier - buffer of past non-binary decisions (with ST smoothing) Q19 */ Word32 dlp_mean_ST_fx; /* Q19 */ #endif - int16_t flag_spitch_cnt; + Word16 flag_spitch_cnt; #ifndef IVAS_FLOAT_FIXED float dlp_mean_LT; float dlp_var_LT; @@ -870,9 +869,9 @@ typedef struct sp_mus_clas_structure Word16 gsc_mem_etot_fx; /* Speech/music classifier - total energy memory Q8 */ #endif - int16_t gsc_last_music_flag; /* Speech/music classifier - last music flag */ - int16_t gsc_nb_thr_1; /* Speech/music classifier - number of consecutives frames of level 1 */ - int16_t gsc_nb_thr_3; /* Speech/music classifier - number of consecutives frames of level 3 */ + Word16 gsc_last_music_flag; /* Speech/music classifier - last music flag */ + Word16 gsc_nb_thr_1; /* Speech/music classifier - number of consecutives frames of level 1 */ + Word16 gsc_nb_thr_3; /* Speech/music classifier - number of consecutives frames of level 3 */ #ifndef IVAS_FLOAT_FIXED float mold_corr; float mean_avr_dyn; /* Speech/music classifier - long term average dynamic */ @@ -887,7 +886,7 @@ typedef struct sp_mus_clas_structure Word16 ener_RAT_fx; /* Speech/music classifier - LF/to total energy ratio Q15 */ #endif - int16_t relE_attack_cnt; + Word16 relE_attack_cnt; #ifndef IVAS_FLOAT_FIXED float prev_relE; float prev_Etot; @@ -895,8 +894,8 @@ typedef struct sp_mus_clas_structure Word16 prev_relE_fx; /* Q8 */ Word16 prev_Etot_fx; /* Q8 */ #endif - int16_t prev_vad; - int16_t vad_0_1_cnt; + Word16 prev_vad; + Word16 vad_0_1_cnt; #ifndef IVAS_FLOAT_FIXED float relE_attack_sum; #else @@ -926,13 +925,13 @@ typedef struct sp_mus_clas_structure Word16 buf_dlp_fx[10]; /* Q9 */ #endif - int16_t onset_cnt; + Word16 onset_cnt; #ifndef IVAS_FLOAT_FIXED float buf_etot[4]; #else Word16 buf_etot_fx[4]; /* Q8 */ #endif - int16_t attack_hangover; + Word16 attack_hangover; #ifndef IVAS_FLOAT_FIXED float dec_mov; float dec_mov1; @@ -944,21 +943,23 @@ typedef struct sp_mus_clas_structure Word16 mov_log_max_spl_fx; /* Q7 */ Word16 old_lt_diff_fx[2]; /* Q7 */ #endif - int16_t UV_cnt1; + Word16 UV_cnt1; #ifndef IVAS_FLOAT_FIXED float LT_UV_cnt1; #else Word16 LT_UV_cnt1_fx; /* Q6 */ #endif - float finc_prev[ATT_NSEG]; /* strong attack detection - previous finc */ - float lt_finc; /* strong attack detection - long-term finc energy */ +#ifndef IVAS_FLOAT_FIXED + float finc_prev[ATT_NSEG]; /* strong attack detection - previous finc */ + float lt_finc; /* strong attack detection - long-term finc energy */ +#endif Word32 finc_prev_fx[ATT_NSEG]; /* strong attack detection - previous finc, (Q_new * 2) */ Word32 lt_finc_fx; /* strong attack detection - long-term finc energy, (Q_new * 2) */ int16_t last_strong_attack; /* strong attack detection - last strong attack flag */ - float tod_lt_Bin_E[TOD_NSPEC]; /* tonal detector - long-term energy spectrum */ Word32 tod_lt_Bin_E_fx[TOD_NSPEC]; /* tonal detector - long-term energy spectrum, Q_new + Q_SCALE - 2 */ #ifndef IVAS_FLOAT_FIXED + float tod_lt_Bin_E[TOD_NSPEC]; /* tonal detector - long-term energy spectrum */ float tod_S_map_lt[TOD_NSPEC]; /* tonal detector - long-term correlation map */ float tod_thr_lt; /* tonal detector - adaptive threshold */ float tod_weight; /* tonal detector - adaptive weight */ @@ -972,7 +973,7 @@ typedef struct sp_mus_clas_structure Word32 tod_S_mass_lt_fx; /* Q22 */ #endif - int16_t lt_music_hangover; + Word16 lt_music_hangover; #ifndef IVAS_FLOAT_FIXED float tonality2_buf[HANG_LEN_INIT]; float tonality3_buf[HANG_LEN_INIT]; @@ -982,9 +983,9 @@ typedef struct sp_mus_clas_structure Word16 tonality3_buf_fx[HANG_LEN_INIT]; /* Q14 */ Word16 LPCErr_buf_fx[HANG_LEN_INIT]; /* Q10 */ #endif - int16_t lt_music_state; - int16_t lt_speech_state; - int16_t lt_speech_hangover; + Word16 lt_music_state; + Word16 lt_speech_state; + Word16 lt_speech_hangover; #ifndef IVAS_FLOAT_FIXED float lpe_buf[HANG_LEN_INIT]; float voicing_buf[HANG_LEN_INIT]; @@ -992,7 +993,7 @@ typedef struct sp_mus_clas_structure Word16 lpe_buf_fx[HANG_LEN_INIT]; /* Q10 */ Word16 voicing_buf_fx[HANG_LEN_INIT]; /* Q13 */ #endif - int16_t gsc_hangover; + Word16 gsc_hangover; #ifndef IVAS_FLOAT_FIXED float sparse_buf[HANG_LEN_INIT]; float hf_spar_buf[HANG_LEN_INIT]; @@ -1002,11 +1003,11 @@ typedef struct sp_mus_clas_structure Word16 hf_spar_buf_fx[HANG_LEN_INIT]; /* Q15 */ Word16 LT_sparse_fx; /* Q8 */ #endif - int16_t gsc_cnt; + Word16 gsc_cnt; /* speech/music classification */ - int16_t last_vad_spa; - int16_t lt_old_mode[3]; + Word16 last_vad_spa; + Word16 lt_old_mode[3]; #ifndef IVAS_FLOAT_FIXED float lt_voicing_flt; float lt_corr_flt; @@ -1016,8 +1017,8 @@ typedef struct sp_mus_clas_structure Word16 lt_corr; /* Q15 */ Word32 lt_tonality; /* Q15 */ #endif - int16_t lt_corr_pitch[3]; - int16_t lt_hangover; + Word16 lt_corr_pitch[3]; + Word16 lt_hangover; #ifndef IVAS_FLOAT_FIXED float lowrate_pitchGain_flt; float tdm_lt_Etot; @@ -1027,7 +1028,7 @@ typedef struct sp_mus_clas_structure Word16 tdm_lt_Etot_fx; /* Q8 */ Word16 var_cor_t_fx[VAR_COR_LEN]; /* Q11 */ #endif - int16_t high_stable_cor; + Word16 high_stable_cor; #ifndef IVAS_FLOAT_FIXED float lps; @@ -1130,7 +1131,8 @@ typedef struct gsc_enc_structure #ifndef IVAS_FLOAT_FIXED float mem_w0_tmp; float mem_syn_tmp[M]; - float mid_dyn; /* AC mode (GSC) - signal dynamic */ + float mid_dyn; /* AC mode (GSC) - signal dynamic */ + float Last_frame_ener; /* AC mode (GSC) - Last frame energy */ #else Word16 mem_w0_tmp_fx; Word16 mem_syn_tmp_fx[M]; @@ -1138,7 +1140,6 @@ typedef struct gsc_enc_structure #endif int16_t noise_lev; /* AC mode (GSC) - noise level */ int16_t past_dyn_dec; /* AC mode (GSC) - Past noise level decision */ - float Last_frame_ener; /* AC mode (GSC) - Last frame energy */ Word32 Last_frame_ener_fx; /* AC mode (GSC) - Last frame energy */ int16_t pit_exc_hangover; /* AC mode (GSC) - Hangover for the time contribution switching */ float last_exc_dct_in[L_FRAME16k]; /* AC mode (GSC) - previous excitation */ @@ -1507,7 +1508,7 @@ typedef struct td_bwe_enc_structure Word16 fb_state_lpc_syn_fx[LPC_SHB_ORDER]; Word16 prev_Q_bwe_exc_fb; Word16 fb_tbe_demph_fx; - Word16 tilt_mem_fx; /* Q12 */ + Word16 tilt_mem_fx; /* Q12 */ #endif int16_t prev_coder_type; @@ -1515,10 +1516,10 @@ typedef struct td_bwe_enc_structure float prev_lsf_diff[LPC_SHB_ORDER - 2]; float prev_tilt_para; #else + float cur_sub_Aq[M + 1]; Word16 prev_lsf_diff_fx[LPC_SHB_ORDER - 2]; /* Q15 */ Word16 prev_tilt_para_fx; /* Q10 */ #endif - float cur_sub_Aq[M + 1]; Word16 cur_sub_Aq_fx[M + 1]; /* Q12 */ /* quantized data */ @@ -2009,8 +2010,7 @@ typedef struct enc_core_structure int16_t pitch[3]; /* open-loop pitch values @12.8 kHz for three half-frames */ float voicing[3]; /* open-loop normalized correlation values for three half-frames */ // Word16 pitch_fx[3]; - Word16 voicing_fx[3]; - Word16 voicing_e; + Word16 voicing_fx[3]; /* Q15 */ LPD_state_HANDLE hLPDmem; /* ACELP LPDmem memories */ diff --git a/lib_enc/swb_tbe_enc_fx.c b/lib_enc/swb_tbe_enc_fx.c index 52ac2398d..3974a326d 100644 --- a/lib_enc/swb_tbe_enc_fx.c +++ b/lib_enc/swb_tbe_enc_fx.c @@ -3560,7 +3560,7 @@ void swb_tbe_enc_ivas_fx( res_e = sub( add( res_e, 31 ), tmp_e ); - acorr_v2a_fx = sub( acorr_v2a_fx, shl( 1, sub( 15, res_e ) ) ); + res_e = BASOP_Util_Add_MantExp( acorr_v2a_fx, res_e, -1, 15, &acorr_v2a_fx ); /* limit in the range 0.0 - 1.0 */ // acorr_v2a = min( 1.0f, max( 0.0f, acorr_v2a ) ); -- GitLab From a2f0e6c4f83bc65f6822cab252d91b12f8332ce3 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Mon, 18 Nov 2024 19:23:58 +0530 Subject: [PATCH 128/128] core_signal_analysis_high_bitrate integration, OMASA LTV crash fixes and few high MLD cases addressing --- lib_com/cldfb_evs.c | 4 + lib_com/ivas_prot.h | 2 + lib_com/ivas_prot_fx.h | 13 +++ lib_com/ivas_sns_com_fx.c | 12 ++- lib_com/prot_fx.h | 11 --- lib_com/tns_base.c | 173 ----------------------------------- lib_enc/ext_sig_ana_fx.c | 15 +-- lib_enc/igf_enc.c | 7 +- lib_enc/ivas_core_enc.c | 68 ++++++++++++-- lib_enc/ivas_mdct_core_enc.c | 9 +- lib_enc/ivas_tcx_core_enc.c | 41 ++++++--- lib_enc/prot_fx_enc.h | 12 +++ lib_enc/swb_tbe_enc_fx.c | 81 +++++++++------- lib_enc/tcx_utils_enc.c | 7 +- lib_enc/tcx_utils_enc_fx.c | 116 +++++++++++++++++++++++ 15 files changed, 321 insertions(+), 250 deletions(-) diff --git a/lib_com/cldfb_evs.c b/lib_com/cldfb_evs.c index c22e583be..923d2b887 100644 --- a/lib_com/cldfb_evs.c +++ b/lib_com/cldfb_evs.c @@ -1405,7 +1405,11 @@ void GetEnergyCldfb( Word32 *energyLookahead, /*!< o: Q(*sf_energyLookahead) { FOR( j = 20; j < numberBandsM; j++ ) { +#ifdef BASOP_NOGLOB + nrg = L_add_o( nrg, L_shr_o( energyValues[k][j], s, &Overflow ), &Overflow ); +#else nrg = L_add( nrg, L_shr( energyValues[k][j], s ) ); +#endif } } diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index 2409d91bd..119824b03 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -612,6 +612,7 @@ void stereo_tcx_core_dec( ); #endif // !IVAS_FLOAT_FIXED +#ifndef IVAS_FLOAT_FIXED void stereo_tcx_core_enc( Encoder_State *st, /* i/o: encoder state structure */ const float new_samples_12k8[], /* i : buffer of input signal @12.8 kHz */ @@ -623,6 +624,7 @@ void stereo_tcx_core_enc( const Word16 last_element_mode, /* i : last element mode, Q0 */ const Word16 vad_hover_flag /* i : VAD hangover flag, Q0 */ ); +#endif void stereo_tcx_init_dec( diff --git a/lib_com/ivas_prot_fx.h b/lib_com/ivas_prot_fx.h index d549056b5..e383aeea0 100644 --- a/lib_com/ivas_prot_fx.h +++ b/lib_com/ivas_prot_fx.h @@ -3080,6 +3080,19 @@ void InternalTCXDecoder_fx( Word16 *gain_tcx_q /* o : quantized global gain (at low bitrates) */ ); +void stereo_tcx_core_enc( + Encoder_State *st, /* i/o: encoder state structure */ + const Word16 new_samples_12k8[], /* i : buffer of input signal @12.8 kHz */ + const Word16 new_samples_16k[], /* i : buffer of input signal @16 kHz */ + const Word16 Aw_fx[], /* i : weighted A(z) unquant. for subframes, Q12 */ + Word16 lsp_new_fx[], /* i : LSPs at the end of the frame, Q15 */ + Word16 lsp_mid_fx[], /* i : LSPs in the middle of the frame, Q15 */ + Word16 pitch_buf_fx[NB_SUBFR16k], /* o : pitch for each subframe, Q6 */ + const Word16 last_element_mode, /* i : last element mode, Q0 */ + const Word16 vad_hover_flag /* i : VAD hangover flag, Q0 */ +); + + Word16 transient_analysis_ivas_fx( TRAN_DET_HANDLE hTranDet, /* i : handle transient detection */ const Word16 cor_map_LT[], /* i : LT correlation map Q_cor_map = Qx */ diff --git a/lib_com/ivas_sns_com_fx.c b/lib_com/ivas_sns_com_fx.c index 9a7a092b3..5931c4ea1 100644 --- a/lib_com/ivas_sns_com_fx.c +++ b/lib_com/ivas_sns_com_fx.c @@ -123,10 +123,18 @@ void sns_compute_scf_fx( } /* Move accumulated values to 32-bit */ - q_shift = W_norm( x_64[0] ); + q_shift = 0; + move16(); + IF( x_64[0] != 0 ) + { + q_shift = W_norm( x_64[0] ); + } FOR( i = 1; i < nBands; ++i ) { - q_shift = s_min( q_shift, W_norm( x_64[i] ) ); + IF( x_64[i] != 0 ) + { + q_shift = s_min( q_shift, W_norm( x_64[i] ) ); + } } FOR( i = 0; i < nBands; ++i ) { diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index 76d46c48c..f1cb75f78 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -3512,17 +3512,6 @@ Word16 ITF_Detect_fx( Word32 const pSpectrum[], Word16 *curr_order, Word16 Q ); -Word16 ITF_Detect_ivas_fx( - const Word32 pSpectrum[], - const Word16 startLine, - const Word16 stopLine, - const Word16 maxOrder, - Word16 *A, - Word16 *Q_A, - Word16 *predictionGain, - Word16 *curr_order, - Word16 Q ); - void ITF_Apply_fx( Word32 spectrum[], Word16 startLine, Word16 stopLine, diff --git a/lib_com/tns_base.c b/lib_com/tns_base.c index 5e16ff6c2..1e8e45df7 100644 --- a/lib_com/tns_base.c +++ b/lib_com/tns_base.c @@ -613,179 +613,6 @@ Word16 ITF_Detect_fx( return 1; } - -Word16 ITF_Detect_ivas_fx( - const Word32 pSpectrum[], /*Q*/ - const Word16 startLine, /*Q0*/ - const Word16 stopLine, /*Q0*/ - const Word16 maxOrder, /*Q0*/ - Word16 *A, /*Q_A*/ - Word16 *Q_A, - Word16 *predictionGain, /*Q7*/ - Word16 *curr_order, /*Q0*/ - Word16 Q ) -{ - - Word16 spectrumLength; - Word16 const nSubdivisions = MAX_SUBDIVISIONS; - move16(); - Word16 iSubdivisions; - Word16 iStartLine; - Word16 iEndLine; - Word16 facs[MAX_SUBDIVISIONS]; - Word16 facs_e[MAX_SUBDIVISIONS]; /* exponents of facs[][] */ - Word16 shifts[MAX_SUBDIVISIONS]; - Word16 tmp, headroom, shift; - Word32 rxx[ITF_MAX_FILTER_ORDER + 1]; - Word16 lag; - Word32 L_tmp, tmp32; - Word16 tmpbuf[325]; - Word16 n, i; - Word32 norms[MAX_SUBDIVISIONS]; - Word16 norms_e[MAX_SUBDIVISIONS]; -#ifdef BASOP_NOGLOB_DECLARE_LOCAL - Flag Overflow = 0; - move32(); -#endif - - set16_fx( norms_e, sub( 31, Q ), MAX_SUBDIVISIONS ); - if ( maxOrder <= 0 ) - { - return 0; - } - - /* Calculate norms for each spectrum part */ - FOR( iSubdivisions = 0; iSubdivisions < nSubdivisions; iSubdivisions++ ) - { - assert( ( nSubdivisions == 1 ) || ( nSubdivisions == 3 ) ); - - tmp = sub( stopLine, startLine ); - iStartLine = imult1616( tmp, iSubdivisions ); /*Q0*/ - iEndLine = add( iStartLine, tmp ); - - IF( EQ_16( nSubdivisions, 3 ) ) - iStartLine = mult( iStartLine, 0x2AAB ); /*Q0*/ - iStartLine = add( iStartLine, startLine ); - - IF( EQ_16( nSubdivisions, 3 ) ) - iEndLine = mult( iEndLine, 0x2AAB ); /*Q0*/ - iEndLine = add( iEndLine, startLine ); - headroom = getScaleFactor32( pSpectrum + iStartLine - IGF_START_MN, sub( iEndLine, iStartLine ) ); - /* Calculate norm of spectrum band */ - L_tmp = Norm32Norm( pSpectrum + iStartLine - IGF_START_MN, headroom, sub( iEndLine, iStartLine ), &shift ); /*Q31 - shift*/ - - /* Check threshold HLM_MIN_NRG */ - BASOP_SATURATE_WARNING_OFF_EVS; -#ifdef BASOP_NOGLOB - tmp32 = L_sub( L_shl_o( L_tmp, sub( shift, 24 - Q ), &Overflow ), 4194304l /*HLM_MIN_NRG Q7*/ ); /*Q7*/ -#else /* BASOP_NOGLOB */ - tmp32 = L_sub( L_shl( L_tmp, sub( shift, 24 - Q ) ), 4194304l /*HLM_MIN_NRG Q7*/ ); -#endif - BASOP_SATURATE_WARNING_ON_EVS; - - /* get pre-shift for autocorrelation */ - tmp = sub( shift, norm_l( L_tmp ) ); /* exponent for normalized L_tmp */ - tmp = shr( sub( 1, tmp ), 1 ); /* pre-shift to apply before autocorrelation */ - shifts[iSubdivisions] = s_min( tmp, headroom ); - move16(); - - /* calc normalization factor */ - facs[iSubdivisions] = 0; - move16(); - facs_e[iSubdivisions] = 0; - move16(); - - if ( tmp32 > 0 ) - { - facs[iSubdivisions] = 0x7FFF; /*Q15*/ - move16(); /* normalization not needed for one subdivision */ - } - - IF( L_tmp > 0 ) - { - facs_e[iSubdivisions] = shl( sub( tmp, shifts[iSubdivisions] ), 1 ); - move16(); - - tmp = sub( 1, shl( tmp, 1 ) ); /* exponent of autocorrelation */ - L_tmp = L_shl( L_tmp, sub( shift, tmp ) ); /* shift L_tmp to that exponent */ - - /* calc factor (with 2 bits headroom for sum of 3 subdivisions) */ - facs[iSubdivisions] = div_s( 0x2000, round_fx_o( L_tmp, &Overflow ) ); /* L_tmp is >= 0x2000000 Q15*/ - move16(); - } - norms[iSubdivisions] = sum2_32_fx( pSpectrum + sub( iStartLine, IGF_START_MN ), sub( iEndLine, iStartLine ), &norms_e[iSubdivisions] ); /*Q31 - norms_e*/ - move16(); - } - - /* Calculate normalized autocorrelation for spectrum subdivision and get filter parameters based on it */ - set32_fx( rxx, 0, ITF_MAX_FILTER_ORDER + 1 ); - - spectrumLength = sub( stopLine, startLine ); - test(); - FOR( iSubdivisions = 0; ( iSubdivisions < nSubdivisions ) && GT_64( norms[iSubdivisions], W_shl( HLM_MIN_NRG_FX, sub( 31, norms_e[iSubdivisions] ) ) ); iSubdivisions++ ) - { - test(); - assert( ( nSubdivisions == 1 ) || ( nSubdivisions == 3 ) ); - - iStartLine = imult1616( spectrumLength, iSubdivisions ); /*Q0*/ - iEndLine = add( iStartLine, spectrumLength ); - - IF( EQ_16( nSubdivisions, 3 ) ) - iStartLine = mult( iStartLine, 0x2AAB ); /*Q0*/ - iStartLine = add( iStartLine, startLine ); - - IF( EQ_16( nSubdivisions, 3 ) ) - iEndLine = mult( iEndLine, 0x2AAB ); /*Q0*/ - iEndLine = add( iEndLine, startLine ); - - - move16(); - shift = shifts[iSubdivisions]; - - n = sub( iEndLine, iStartLine ); - assert( n < (Word16) ( sizeof( tmpbuf ) / sizeof( Word16 ) ) ); - FOR( i = 0; i < n; i++ ) - { - tmpbuf[i] = round_fx_o( L_shl( pSpectrum[iStartLine + i - IGF_START_MN], shift ), &Overflow ); /*Q+shift-16*/ - move16(); - } - - FOR( lag = 1; lag <= maxOrder; lag++ ) - { - n = sub( sub( iEndLine, lag ), iStartLine ); - - { - Word64 tmp64 = 0; - FOR( i = 0; i < n; i++ ) - { - tmp64 = W_mac0_16_16( tmp64, tmpbuf[i], tmpbuf[i + lag] ); /*2*( Q+shift-16)*/ - } - L_tmp = W_sat_l( tmp64 ); /*2*( Q+shift-16)*/ - } - - L_tmp = Mpy_32_16_1( L_tmp, facs[iSubdivisions] ); /*2*( Q+shift-16)*/ - L_tmp = L_shl( L_tmp, facs_e[iSubdivisions] ); - - rxx[lag] = L_add( rxx[lag], L_tmp ); /*2*( Q+shift-16)*/ - move32(); - } - } - - *predictionGain = 0; - move16(); - IF( EQ_16( iSubdivisions, nSubdivisions ) ) /* meaning there is no subdivision with low energy */ - { - rxx[0] = 3 * ONE_IN_Q29; - move32(); - /* Limit the maximum order to spectrum length/4 */ - ITF_GetFilterParameters_fx( rxx, s_min( maxOrder, shr( spectrumLength, 2 ) ), A, Q_A, predictionGain ); - - *curr_order = maxOrder; /*Q0*/ - move16(); - } - - return 1; -} /* Helper functions for Hufmann table coding */ diff --git a/lib_enc/ext_sig_ana_fx.c b/lib_enc/ext_sig_ana_fx.c index f81c1a665..4092c58f2 100644 --- a/lib_enc/ext_sig_ana_fx.c +++ b/lib_enc/ext_sig_ana_fx.c @@ -660,11 +660,12 @@ void core_signal_analysis_high_bitrate_ivas_fx( Word16 i, frameno; Word16 L_subframe; Word16 left_overlap = -1, right_overlap = -1, folding_offset; - Word32 buf[N_MAX + L_MDCT_OVLP_MAX]; /* Buffer for TCX20/TCX10 windowing */ - Word16 mdstWin[N_MAX + L_MDCT_OVLP_MAX]; /* Buffer for MDST windowing */ + Word32 buf[N_MAX + L_MDCT_OVLP_MAX]; /* Buffer for TCX20/TCX10 windowing */ + Word32 buf_powerSPec[N_MAX + L_MDCT_OVLP_MAX]; /* Buffer for TCX20/TCX10 windowing */ + Word16 mdstWin[N_MAX + L_MDCT_OVLP_MAX]; /* Buffer for MDST windowing */ Word16 *pMdstWin; Word16 lpc_left_overlap_mode, lpc_right_overlap_mode; - Word32 *powerSpec = buf; + Word32 *powerSpec = buf_powerSPec; Word16 powerSpec_e; Word16 *tcx20Win = (Word16 *) buf; Word32 *tcx20Win_32 = buf; @@ -1146,9 +1147,9 @@ void core_signal_analysis_high_bitrate_ivas_fx( } /* Compute noise-measure flags for spectrum filling and quantization */ - AnalyzePowerSpectrum_fx( st, div_l( L_mult( L_subframe, st->L_frame ), hTcxEnc->L_frameTCX ), - L_subframe, left_overlap, right_overlap, hTcxEnc->spectrum_fx[frameno], hTcxEnc->spectrum_e[frameno], - pMdstWin, powerSpec, &powerSpec_e ); + AnalyzePowerSpectrum_ivas_fx( st, div_l( L_mult( L_subframe, st->L_frame ), hTcxEnc->L_frameTCX ), + L_subframe, left_overlap, right_overlap, hTcxEnc->spectrum_fx[frameno], hTcxEnc->spectrum_e[frameno], + pMdstWin, powerSpec, &powerSpec_e ); } } } @@ -1387,6 +1388,8 @@ void core_signal_analysis_high_bitrate_ivas_fx( { Word16 q_spectrum = sub( Q31, hTcxEnc->spectrum_e[frameno] ); Word16 q_powerSpec = sub( Q31, powerSpec_e ); + st->hIGFEnc->spec_be_igf_e = hTcxEnc->spectrum_e[frameno]; + move16(); ProcessIGF_ivas_fx( st, hTcxEnc->spectrum_fx[frameno], hTcxEnc->spectrum_fx[frameno], &q_spectrum, powerSpec, &q_powerSpec, transform_type[frameno] == TCX_20, frameno, 0, vad_hover_flag ); } } diff --git a/lib_enc/igf_enc.c b/lib_enc/igf_enc.c index 52ca1a022..0cd4a48b9 100644 --- a/lib_enc/igf_enc.c +++ b/lib_enc/igf_enc.c @@ -1049,7 +1049,12 @@ static void IGF_CalculateEnvelope_ivas_fx( FOR( sb = swb_offset[sfb]; sb < swb_offset[sfb + 1]; sb++ ) { sfbEnergyC = BASOP_Util_Add_Mant32Exp( sfbEnergyC, sfbEnergyC_e, pPowerSpectrum_fx[sb], e_ps, &sfbEnergyC_e ); - sfbEnergyTileR = BASOP_Util_Add_Mant32Exp( sfbEnergyTileR, sfbEnergyTileR_e, Mult_32_32( pMDCTSpectrum_fx[strt_cpy], pMDCTSpectrum_fx[strt_cpy] ), shl( e_mdct, 1 ), &sfbEnergyTileR_e ); + // sfbEnergyTileR = BASOP_Util_Add_Mant32Exp( sfbEnergyTileR, sfbEnergyTileR_e, Mult_32_32( pMDCTSpectrum_fx[strt_cpy], pMDCTSpectrum_fx[strt_cpy] ), shl( e_mdct, 1 ), &sfbEnergyTileR_e ); + Word64 tmp64 = W_mult_32_32( pMDCTSpectrum_fx[strt_cpy], pMDCTSpectrum_fx[strt_cpy] ); + Word16 tmp64_e = W_norm( tmp64 ); + tmp64 = W_shl( tmp64, tmp64_e ); + + sfbEnergyTileR = BASOP_Util_Add_Mant32Exp( sfbEnergyTileR, sfbEnergyTileR_e, W_extract_h( tmp64 ), shl( e_mdct, 1 ) - tmp64_e, &sfbEnergyTileR_e ); sfbEnergyTileC = BASOP_Util_Add_Mant32Exp( sfbEnergyTileC, sfbEnergyTileC_e, pPowerSpectrum_fx[strt_cpy], e_ps, &sfbEnergyTileC_e ); strt_cpy = add( strt_cpy, 1 ); diff --git a/lib_enc/ivas_core_enc.c b/lib_enc/ivas_core_enc.c index 5b1bf1f14..6dd5c909b 100644 --- a/lib_enc/ivas_core_enc.c +++ b/lib_enc/ivas_core_enc.c @@ -135,6 +135,10 @@ ivas_error ivas_core_enc( Word16 i; #endif +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + Word16 lsp_new_fx[CPE_CHANNELS][M], lsp_mid_fx[CPE_CHANNELS][M]; +#endif + set32_fx( new_swb_speech_buffer_fx, 0, L_FRAME48k + STEREO_DFT_OVL_MAX ); set16_fx( new_swb_speech_buffer_fx_16, 0, L_FRAME48k + STEREO_DFT_OVL_MAX ); @@ -421,12 +425,8 @@ ivas_error ivas_core_enc( #ifdef IVAS_FLOAT_FIXED_CONVERSIONS Word16 Aw_fx[CPE_CHANNELS][NB_SUBFR16k * ( M + 1 )]; float Aw_flt[CPE_CHANNELS][NB_SUBFR16k * ( M + 1 )]; - // Word16 lsp_new_fx[M], lsp_mid_fx[M]; - // Word16 n_subframes = EQ_16( st->hTcxEnc->tcxMode, TCX_10 ) ? 2 : 1; mvr2r( Aw[n], Aw_flt[n], st->nb_subfr * ( M + 1 ) ); floatToFixed_arr( Aw_flt[n], Aw_fx[n], Q12, st->nb_subfr * ( M + 1 ) ); - // floatToFixed_arr( lsp_new, lsp_new_fx, Q15, M ); - // floatToFixed_arr( lsp_mid, lsp_mid_fx, Q15, M ); st->hTcxCfg->preemph_fac = float_to_fix16( st->hTcxCfg->preemph_fac_flt, Q15 ); st->hTcxEnc->measuredBwRatio = float_to_fix16( st->hTcxEnc->measuredBwRatio_flt, Q14 ); @@ -434,13 +434,69 @@ ivas_error ivas_core_enc( st->hTcxEnc->Q_old_out = Q_factor_arr( st->hTcxEnc->old_out, L_FRAME32k ) - 1; floatToFixed_arr( st->hTcxEnc->old_out, st->hTcxEnc->old_out_fx, st->hTcxEnc->Q_old_out, L_FRAME32k ); -#endif // IVAS_FLOAT_FIXED_CONVERSIONS + Word16 nSubframes; + TCX_ENC_HANDLE hTcxEnc = st->hTcxEnc; + IF( EQ_16( hTcxEnc->tcxMode, TCX_20 ) ) + { + nSubframes = 1; + } + ELSE + { + nSubframes = 2; + } + hTcxEnc->tcxltp_norm_corr_past = float_to_fix16( hTcxEnc->tcxltp_norm_corr_past_flt, Q15 ); + floatToFixed_arr16( st->lspold_enc, st->lspold_enc_fx, Q15, M ); + + Word16 q_spectrum = L_get_q_buf1( hTcxEnc->spectrum[0], st->hTcxEnc->L_frameTCX / nSubframes ); + hTcxEnc->spectrum_e[0] = 31 - q_spectrum; + floatToFixed_arrL32( hTcxEnc->spectrum[0], hTcxEnc->spectrum_fx[0], sub( Q31, hTcxEnc->spectrum_e[0] ), st->hTcxEnc->L_frameTCX / nSubframes ); + IF( hTcxEnc->tcxMode != TCX_20 ) + { + q_spectrum = L_get_q_buf1( hTcxEnc->spectrum[1], st->hTcxEnc->L_frameTCX / nSubframes ); + hTcxEnc->spectrum_e[1] = 31 - q_spectrum; + floatToFixed_arrL32( hTcxEnc->spectrum[1], hTcxEnc->spectrum_fx[1], sub( Q31, hTcxEnc->spectrum_e[1] ), st->hTcxEnc->L_frameTCX / nSubframes ); + } + + floatToFixed_arr( lsp_new[n], lsp_new_fx[n], Q15, M ); + floatToFixed_arr( lsp_mid[n], lsp_mid_fx[n], Q15, M ); +#endif +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + q_old_inp_12k8_fx = Q_factor_arr( old_inp_12k8[n], L_INP_12k8 ); + q_old_inp_16k_fx = Q_factor_arr( old_inp_16k[n], L_INP ); + floatToFixed_arr16( old_inp_12k8[n], old_inp_12k8_fx, q_old_inp_12k8_fx, L_INP_12k8 ); + floatToFixed_arr16( old_inp_16k[n], old_inp_16k_fx, q_old_inp_16k_fx, L_INP ); +#endif /* TCX core encoder */ - stereo_tcx_core_enc( st, old_inp_12k8[n] + L_INP_MEM, old_inp_16k[n] + L_INP_MEM, Aw_fx[n], lsp_new[n], lsp_mid[n], pitch_buf_fx[n], last_element_mode, vad_hover_flag[0] ); + stereo_tcx_core_enc( st, old_inp_12k8_fx + L_INP_MEM, old_inp_16k_fx + L_INP_MEM, Aw_fx[n], lsp_new_fx[n], lsp_mid_fx[n], pitch_buf_fx[n], last_element_mode, vad_hover_flag[0] ); + +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + fixedToFloat_arr( lsp_new_fx[n], lsp_new[n], Q15, M ); + fixedToFloat_arr( lsp_mid_fx[n], lsp_mid[n], Q15, M ); + fixedToFloat_arr( st->lspold_enc_fx, st->lspold_enc, Q15, M ); +#endif +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS_ + if ( st->element_mode == IVAS_CPE_DFT ) + { + fixedToFloat_arr( st->buf_wspeech_enc, st->buf_wspeech_enc_flt, q_fac, L_FRAME16k + L_SUBFR + L_FRAME16k + L_NEXT_MAX_16k + 320 ); + } + else if ( st->element_mode != IVAS_CPE_MDCT ) + { + hTcxEnc->tcxltp_gain_past_flt = fix16_to_float( hTcxEnc->tcxltp_gain_past, Q15 ); + hTcxEnc->tcxltp_gain_flt = fix16_to_float( hTcxEnc->tcxltp_gain, Q15 ); + fixedToFloat_arr( st->hTcxEnc->buf_speech_ltp, st->hTcxEnc->buf_speech_ltp_flt, q_fac, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k ); + } + + fixedToFloat_arrL32( hTcxEnc->spectrum_fx[0], hTcxEnc->spectrum[0], sub( Q31, hTcxEnc->spectrum_e[0] ), st->hTcxEnc->L_frameTCX / nSubframes ); + IF( hTcxEnc->tcxMode != TCX_20 ) + { + fixedToFloat_arrL32( hTcxEnc->spectrum_fx[1], hTcxEnc->spectrum[1], sub( Q31, hTcxEnc->spectrum_e[1] ), st->hTcxEnc->L_frameTCX / nSubframes ); + } +#endif #ifdef IVAS_FLOAT_FIXED_CONVERSIONS + hTcxEnc->tcxltp_norm_corr_past_flt = fix16_to_float( hTcxEnc->tcxltp_norm_corr_past, Q15 ); fixedToFloat_arr( pitch_buf_fx[n], pitch_buf[n], Q6, NB_SUBFR16k ); fixedToFloat_arr( st->hTcxEnc->old_out_fx, st->hTcxEnc->old_out, st->hTcxEnc->Q_old_out, L_FRAME32k ); diff --git a/lib_enc/ivas_mdct_core_enc.c b/lib_enc/ivas_mdct_core_enc.c index 8d7aa9855..c719ac54e 100644 --- a/lib_enc/ivas_mdct_core_enc.c +++ b/lib_enc/ivas_mdct_core_enc.c @@ -1850,7 +1850,8 @@ void ivas_mdct_core_whitening_enc( overlap_mode[2] = st->hTcxCfg->tcx_curr_overlap_mode; /* Overlap between the current and the next frame */ move16(); } - +#endif +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS_ Word16 offset; IF( ( EQ_16( transform_type[0], TCX_20 ) ) && ( NE_16( st->hTcxCfg->tcx_last_overlap_mode, TRANSITION_OVERLAP ) ) ) { @@ -1913,7 +1914,8 @@ void ivas_mdct_core_whitening_enc( floatToFixed_arrL32( windowedSignal[ch] + L_FRAME48k + 2, windowedSignal_fx[ch] + L_FRAME48k + 2, 0, len_windowSignal ); } } - +#endif +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS if ( st->element_mode == IVAS_CPE_DFT ) { hTcxEnc->tcxltp_norm_corr_past = float_to_fix16( hTcxEnc->tcxltp_norm_corr_past_flt, Q15 ); @@ -1941,10 +1943,13 @@ void ivas_mdct_core_whitening_enc( floatToFixed_arrL32( hTcxEnc->spectrum[1], hTcxEnc->spectrum_fx[1], sub( Q31, hTcxEnc->spectrum_e[1] ), st->hTcxEnc->L_frameTCX / nSubframes ); } + floatToFixed_arr( st->input_buff, st->input_buff_fx, 0, L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ) ); + Q_new = 0; #endif core_signal_analysis_high_bitrate_ivas_fx( new_samples_fx[ch] + L_INP_MEM, T_op[ch], NULL, NULL, st, tnsSize[ch], tnsBits[ch], param_core[ch], <pBits[ch], windowedSignal_fx[ch], st->L_frame, st->hTcxEnc->L_frameTCX, hCPE->last_element_mode, 0, mdst_spectrum_fx[ch], mdst_spectrum_e[ch], &Q_new ); #ifdef IVAS_FLOAT_FIXED_CONVERSIONS + fixedToFloat_arr( st->input_buff_fx, st->input_buff, 0, L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ) ); IF( NE_16( st->element_mode, IVAS_CPE_MDCT ) ) { diff --git a/lib_enc/ivas_tcx_core_enc.c b/lib_enc/ivas_tcx_core_enc.c index 26a1d1ffb..2b6e1907d 100644 --- a/lib_enc/ivas_tcx_core_enc.c +++ b/lib_enc/ivas_tcx_core_enc.c @@ -229,11 +229,11 @@ void stereo_tcx_init_enc( #ifdef IVAS_FLOAT_FIXED void stereo_tcx_core_enc( Encoder_State *st, /* i/o: encoder state structure */ - const float new_samples_12k8[], /* i : buffer of input signal @12.8 kHz */ - const float new_samples_16k[], /* i : buffer of input signal @16 kHz */ + const Word16 new_samples_12k8[], /* i : buffer of input signal @12.8 kHz */ + const Word16 new_samples_16k[], /* i : buffer of input signal @16 kHz */ const Word16 Aw_fx[], /* i : weighted A(z) unquant. for subframes, Q12 */ - float lsp_new[], /* i : LSPs at the end of the frame, Q15 */ - float lsp_mid[], /* i : LSPs in the middle of the frame, Q15 */ + Word16 lsp_new_fx[], /* i : LSPs at the end of the frame, Q15 */ + Word16 lsp_mid_fx[], /* i : LSPs in the middle of the frame, Q15 */ Word16 pitch_buf_fx[NB_SUBFR16k], /* o : pitch for each subframe, Q6 */ const Word16 last_element_mode, /* i : last element mode, Q0 */ const Word16 vad_hover_flag /* i : VAD hangover flag, Q0 */ @@ -244,7 +244,7 @@ void stereo_tcx_core_enc( Word16 tmp1, tmp2; /*size and windowing*/ - const float *p_new_samples; + const Word16 *p_new_samples; Word16 q_ind_val; Word16 n_subframes; Word16 last_core_orig; @@ -306,7 +306,6 @@ void stereo_tcx_core_enc( #ifdef IVAS_FLOAT_FIXED_CONVERSIONS Word16 Q_new, Q_exc, q_comm_Bin; - Word16 lsp_new_fx[M], lsp_mid_fx[M]; #endif /*--------------------------------------------------------------* @@ -380,13 +379,11 @@ void stereo_tcx_core_enc( IF( EQ_16( st->L_frame, L_FRAME ) ) { - move16(); p_new_samples = new_samples_12k8; } ELSE { p_new_samples = new_samples_16k; - move16(); } /*--------------------------------------------------------------* @@ -452,7 +449,21 @@ void stereo_tcx_core_enc( *---------------------------------------------------------------*/ /* TODO: integrate this. */ +#ifdef IVAS_FLOAT_FIXED +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + floatToFixed_arr( st->input_buff, st->input_buff_fx, 0, L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ) ); + st->prev_Q_new = 0; + st->Q_old = 0; +#endif + Q_new = 0; + move16(); + core_signal_analysis_high_bitrate_ivas_fx( p_new_samples, T_op, lsp_new_fx, lsp_mid_fx, st, tnsSize, tnsBits, param_core, <pBits, NULL, st->L_frame, hTcxEnc->L_frameTCX, last_element_mode, vad_hover_flag, NULL, NULL, &Q_new ); +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + fixedToFloat_arr( st->input_buff_fx, st->input_buff, 0, L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ) ); +#endif +#else core_signal_analysis_high_bitrate( p_new_samples, T_op, lsp_new, lsp_mid, st, NULL, tnsSize, tnsBits, param_core, <pBits, NULL, st->L_frame, hTcxEnc->L_frameTCX, last_element_mode, vad_hover_flag ); +#endif bitsAvailable = sub( st->bits_frame_core, nbits_header ); IF( st->igf ) @@ -461,13 +472,13 @@ void stereo_tcx_core_enc( } #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - floatToFixed_arr( lsp_new, lsp_new_fx, Q15, M ); - floatToFixed_arr( lsp_mid, lsp_mid_fx, Q15, M ); - q_comm_Bin = s_min( Q_factor_arrL( st->Bin_E_old, 128 ), Q_factor_arrL( st->Bin_E, 256 ) ); Q_new = q_comm_Bin - ( QSCALE - 2 ); const Word16 Q_ener = Q_new + Q_SCALE - 2; // Q_new + Q_SCALE -2 +#endif +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS_ + st->stab_fac_fx = float_to_fix16( st->stab_fac, Q15 ); floatToFixed_arrL( st->Bin_E_old, st->Bin_E_old_fx, q_comm_Bin, 128 ); floatToFixed_arrL( st->Bin_E, st->Bin_E_fx, q_comm_Bin, 256 ); @@ -500,7 +511,9 @@ void stereo_tcx_core_enc( L_frameTCX = sub( L_frameTCX, st->hTcxCfg->lfacNextFB ); } } +#endif +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS Q_new = 0; st->hTcxCfg->bandwidth = float_to_fix16( st->hTcxCfg->bandwidth_flt, Q15 ); @@ -512,7 +525,8 @@ void stereo_tcx_core_enc( { floatToFixed_arr( st->hTdCngEnc->cng_exc2_buf_flt, st->hTdCngEnc->cng_exc2_buf, Q_exc, HO_HIST_SIZE * L_FFT ); } - +#endif +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS floatToFixed_arr( st->synth_flt, st->synth, Q_new, st->L_frame ); floatToFixed_arr( st->hLPDmem->syn_flt, st->hLPDmem->syn, Q_new, M + 1 ); if ( st->tcxonly == 0 ) @@ -822,9 +836,6 @@ void stereo_tcx_core_enc( fixedToFloat_arrL( st->Bin_E_old_fx, st->Bin_E_old, q_comm_Bin, 128 ); fixedToFloat_arrL( st->Bin_E_fx, st->Bin_E, q_comm_Bin, 256 ); - - fixedToFloat_arr( lsp_new_fx, lsp_new, Q15, M ); - fixedToFloat_arr( lsp_mid_fx, lsp_mid, Q15, M ); #endif pop_wmops(); diff --git a/lib_enc/prot_fx_enc.h b/lib_enc/prot_fx_enc.h index cfb2ba9d2..0a9bc483e 100644 --- a/lib_enc/prot_fx_enc.h +++ b/lib_enc/prot_fx_enc.h @@ -1246,6 +1246,18 @@ void AnalyzePowerSpectrum_fx( Word16 const signal[], /* i : windowed signal corresponding to mdctSpectrum */ Word32 powerSpec[], /* o : Power spectrum. Can point to signal */ Word16 *powerSpec_e ); + +void AnalyzePowerSpectrum_ivas_fx( + Encoder_State *st, /* i/o: encoder states */ + Word16 L_frame, /* i : frame length */ + Word16 L_frameTCX, /* i : full band frame length */ + Word16 left_overlap, /* i : left overlap length */ + Word16 right_overlap, /* i : right overlap length */ + Word32 const mdctSpectrum[], /* i : MDCT spectrum */ + Word16 mdctSpectrum_e, + Word16 const signal[], /* i : windowed signal corresponding to mdctSpectrum */ + Word32 powerSpec[], /* o : Power spectrum. Can point to signal */ + Word16 *powerSpec_e ); void AdaptLowFreqEmph_fx( Word32 x[], Word16 x_e, Word16 xq[], diff --git a/lib_enc/swb_tbe_enc_fx.c b/lib_enc/swb_tbe_enc_fx.c index 3974a326d..9b193ef8d 100644 --- a/lib_enc/swb_tbe_enc_fx.c +++ b/lib_enc/swb_tbe_enc_fx.c @@ -3714,32 +3714,49 @@ void swb_tbe_enc_ivas_fx( } Copy( shaped_shb_excitationTemp_fx, &shaped_shb_excitation_fx[L_SHB_LAHEAD], L_FRAME16k ); - - tmp = sub( shl( Q_bwe_exc, 1 ), 31 ); - prev_pow_fx = L_shl( 21475l /*0.00001f Q31*/, tmp ); /* 2*(Q_bwe_exc) */ - curr_pow_fx = L_shl( 21475l /*0.00001f Q31*/, tmp ); /* 2*(Q_bwe_exc) */ - FOR( i = 0; i < L_SHB_LAHEAD + 10; i++ ) + Word16 max_val; + maximum_abs_16_fx( shaped_shb_excitation_fx, L_FRAME16k + L_SHB_LAHEAD, &max_val ); + IF( max_val == 0 ) { + Lscale = ONE_IN_Q31; /* 1.0f in Q31 */ + move32(); + IF( GT_16( voice_factors_fx[0], 24576 /*0.75f Q15*/ ) ) + { + Lscale = ONE_IN_Q30; /* sqrtf(0.25) = 0.5 in Q31 */ + move32(); + } + exp = 0; + move16(); + } + ELSE + { + tmp = sub( shl( Q_bwe_exc, 1 ), 31 ); + prev_pow_fx = L_shl( 21475l /*0.00001f Q31*/, tmp ); /* 2*(Q_bwe_exc) */ + curr_pow_fx = L_shl( 21475l /*0.00001f Q31*/, tmp ); /* 2*(Q_bwe_exc) */ + FOR( i = 0; i < L_SHB_LAHEAD + 10; i++ ) + { #ifdef BASOP_NOGLOB - prev_pow_fx = L_mac0_o( prev_pow_fx, shaped_shb_excitation_fx[i], shaped_shb_excitation_fx[i], &Overflow ); /* 2*Q_bwe_exc */ - curr_pow_fx = L_mac0_o( curr_pow_fx, shaped_shb_excitation_fx[i + L_SHB_LAHEAD + 10], shaped_shb_excitation_fx[i + L_SHB_LAHEAD + 10], &Overflow ); /* 2*Q_bwe_exc */ + prev_pow_fx = L_mac0_o( prev_pow_fx, shaped_shb_excitation_fx[i], shaped_shb_excitation_fx[i], &Overflow ); /* 2*Q_bwe_exc */ + curr_pow_fx = L_mac0_o( curr_pow_fx, shaped_shb_excitation_fx[i + L_SHB_LAHEAD + 10], shaped_shb_excitation_fx[i + L_SHB_LAHEAD + 10], &Overflow ); /* 2*Q_bwe_exc */ #else - prev_pow_fx = L_mac0( prev_pow_fx, shaped_shb_excitation_fx[i], shaped_shb_excitation_fx[i] ); /* 2*Q_bwe_exc */ - curr_pow_fx = L_mac0( curr_pow_fx, shaped_shb_excitation_fx[i + L_SHB_LAHEAD + 10], shaped_shb_excitation_fx[i + L_SHB_LAHEAD + 10] ); /* 2*Q_bwe_exc */ + prev_pow_fx = L_mac0( prev_pow_fx, shaped_shb_excitation_fx[i], shaped_shb_excitation_fx[i] ); /* 2*Q_bwe_exc */ + curr_pow_fx = L_mac0( curr_pow_fx, shaped_shb_excitation_fx[i + L_SHB_LAHEAD + 10], shaped_shb_excitation_fx[i + L_SHB_LAHEAD + 10] ); /* 2*Q_bwe_exc */ #endif - } + } - if ( GT_16( voice_factors_fx[0], 24576 /*0.75f Q15*/ ) ) - { - /*curr_pow_fx = Mult_32_16( curr_pow_fx, 8192);*/ /* Q(2*Q_bwe_exc) */ - curr_pow_fx = L_shr( curr_pow_fx, 2 ); /* scale by 0.25 */ + if ( GT_16( voice_factors_fx[0], 24576 /*0.75f Q15*/ ) ) + { + /*curr_pow_fx = Mult_32_16( curr_pow_fx, 8192);*/ /* Q(2*Q_bwe_exc) */ + curr_pow_fx = L_shr( curr_pow_fx, 2 ); /* scale by 0.25 */ + } + + Lscale = root_a_over_b_fx( curr_pow_fx, + shl( Q_bwe_exc, 1 ), + prev_pow_fx, + shl( Q_bwe_exc, 1 ), + &exp ); } - Lscale = root_a_over_b_fx( curr_pow_fx, - shl( Q_bwe_exc, 1 ), - prev_pow_fx, - shl( Q_bwe_exc, 1 ), - &exp ); FOR( i = 0; i < L_SHB_LAHEAD; i++ ) { L_tmp = Mult_32_16( Lscale, shaped_shb_excitation_fx[i] ); /* Q(16-exp+Q_bwe_exc) */ @@ -3758,8 +3775,8 @@ void swb_tbe_enc_ivas_fx( tmp = i_mult_o( sub( i, 19 ), 3277 /*0.1f Q15*/, &Overflow ); /* Q15 */ L_tmp1 = Mult_32_16( L_shl_o( 1, sub( 31, exp ), &Overflow ), tmp ); /* Q31-exp */ #else - tmp = i_mult( sub( i, 19 ), 3277 /*0.1f Q15*/ ); /* Q15 */ - L_tmp1 = Mult_32_16( L_shl( 1, sub( 31, exp ) ), tmp ); /* Q31-exp */ + tmp = i_mult( sub( i, 19 ), 3277 /*0.1f Q15*/ ); /* Q15 */ + L_tmp1 = Mult_32_16( L_shl( 1, sub( 31, exp ) ), tmp ); /* Q31-exp */ #endif tmp = sub( 32767 /*1.0f Q15*/, tmp ); Lscale = L_add( Mult_32_16( Lscale, tmp ), L_tmp1 ); @@ -3767,7 +3784,7 @@ void swb_tbe_enc_ivas_fx( #ifdef BASOP_NOGLOB shaped_shb_excitation_fx[i] = round_fx_o( L_shl_o( L_tmp, exp, &Overflow ), &Overflow ); /* Q_bwe_exc */ #else - shaped_shb_excitation_fx[i] = round_fx( L_shl( L_tmp, exp ) ); /* Q_bwe_exc */ + shaped_shb_excitation_fx[i] = round_fx( L_shl( L_tmp, exp ) ); /* Q_bwe_exc */ #endif move16(); } @@ -4276,7 +4293,7 @@ void swb_tbe_enc_ivas_fx( #ifdef BASOP_NOGLOB tmp = round_fx_o( L_shl_o( L_tmp, 31 - ( 7 - exp ), &Overflow ), &Overflow ); /* Q15 */ #else - tmp = round_fx( L_shl( L_tmp, 31 - ( 7 - exp ) ) ); /* Q15 */ + tmp = round_fx( L_shl( L_tmp, 31 - ( 7 - exp ) ) ); /* Q15 */ #endif } tmp = s_min( tmp, 32767 /*1.0f Q15*/ ); @@ -4550,10 +4567,10 @@ static void EstimateSHBFrameGain_fx( sig = round_fx_o( Mult_32_16( mod_syn[i], win_shb[i] ), &Overflow ); /*Q_synSHB */ synNrg = L_mac0_o( synNrg, sig, sig, &Overflow ); /* 2*Q_synSHB */ #else - sig = mult_r( oriSHB[i], win_shb[i] ); /* Q_oriSHB */ - oriNrg = L_mac0( oriNrg, sig, sig ); /* 2*Q_orisHB*/ - sig = round_fx( Mult_32_16( mod_syn[i], win_shb[i] ) ); /*Q_synSHB */ - synNrg = L_mac0( synNrg, sig, sig ); /* 2*Q_synSHB */ + sig = mult_r( oriSHB[i], win_shb[i] ); /* Q_oriSHB */ + oriNrg = L_mac0( oriNrg, sig, sig ); /* 2*Q_orisHB*/ + sig = round_fx( Mult_32_16( mod_syn[i], win_shb[i] ) ); /*Q_synSHB */ + synNrg = L_mac0( synNrg, sig, sig ); /* 2*Q_synSHB */ #endif } @@ -4564,9 +4581,9 @@ static void EstimateSHBFrameGain_fx( sig = round_fx_o( mod_syn[i], &Overflow ); /* Q_oriSHB */ synNrg = L_mac0_o( synNrg, sig, sig, &Overflow ); /* 2*Q_oriSHB */ #else - oriNrg = L_mac0( oriNrg, oriSHB[i], oriSHB[i] ); /* 2*Q_oriSHB */ - sig = round_fx( mod_syn[i] ); /* Q_oriSHB */ - synNrg = L_mac0( synNrg, sig, sig ); /* 2*Q_oriSHB */ + oriNrg = L_mac0( oriNrg, oriSHB[i], oriSHB[i] ); /* 2*Q_oriSHB */ + sig = round_fx( mod_syn[i] ); /* Q_oriSHB */ + synNrg = L_mac0( synNrg, sig, sig ); /* 2*Q_oriSHB */ #endif } @@ -4580,8 +4597,8 @@ static void EstimateSHBFrameGain_fx( sig = round_fx_o( Mult_32_16( mod_syn[i], win_shb[l_frame + l_shb_lahead - 1 - i] ), &Overflow ); /* Q_oriSHB */ synNrg = L_mac0_o( synNrg, sig, sig, &Overflow ); /* 2*Q_oriSHB */ #else - sig = mult_r( oriSHB[i], win_shb[l_frame + l_shb_lahead - 1 - i] ); /* Q_oriSHB */ - oriNrg = L_mac0( oriNrg, sig, sig ); /* 2*Q_oriSHB */ + sig = mult_r( oriSHB[i], win_shb[l_frame + l_shb_lahead - 1 - i] ); /* Q_oriSHB */ + oriNrg = L_mac0( oriNrg, sig, sig ); /* 2*Q_oriSHB */ sig = round_fx( Mult_32_16( mod_syn[i], win_shb[l_frame + l_shb_lahead - 1 - i] ) ); /* Q_oriSHB */ synNrg = L_mac0( synNrg, sig, sig ); /* 2*Q_oriSHB */ diff --git a/lib_enc/tcx_utils_enc.c b/lib_enc/tcx_utils_enc.c index a4225f2ce..f10b01afb 100644 --- a/lib_enc/tcx_utils_enc.c +++ b/lib_enc/tcx_utils_enc.c @@ -1571,7 +1571,7 @@ void ProcessIGF_ivas_fx( q_A = 0; move16(); - ITF_Detect_ivas_fx( hIGFEnc->spec_be_igf, hIGFEnc->infoStartLine, hIGFEnc->infoStopLine, 8 /*maxOrder*/, A, &q_A, &predictionGain, &curr_order, sub( 31, hIGFEnc->spec_be_igf_e ) ); + ITF_Detect_fx( hIGFEnc->spec_be_igf, hIGFEnc->infoStartLine, hIGFEnc->infoStopLine, 8 /*maxOrder*/, A, &q_A, &predictionGain, &curr_order, sub( 31, hIGFEnc->spec_be_igf_e ) ); test(); IF( LT_32( L_deposit_l( hIGFEnc->tns_predictionGain ), 9646899 /* 1.15 in Q23 */ ) && LT_32( L_deposit_l( predictionGain ), 9646899 /* 1.15 in Q23 */ ) ) @@ -1748,7 +1748,10 @@ void ProcessStereoIGF_fx( Q_A = 0; move16(); - ITF_Detect_ivas_fx( hIGFEnc[ch]->spec_be_igf, hIGFEnc[ch]->infoStartLine, hIGFEnc[ch]->infoStopLine, 8 /*maxOrder*/, A, &Q_A, &predictionGain, &curr_order, sub( 31, hIGFEnc[ch]->spec_be_igf_e ) ); + predictionGain = 0; + move16(); + + ITF_Detect_fx( hIGFEnc[ch]->spec_be_igf, hIGFEnc[ch]->infoStartLine, hIGFEnc[ch]->infoStopLine, 8 /*maxOrder*/, A, &Q_A, &predictionGain, &curr_order, sub( 31, hIGFEnc[ch]->spec_be_igf_e ) ); test(); hIGFEnc[ch]->flatteningTrigger = LT_32( hIGFEnc[ch]->tns_predictionGain, ONE_POINT_ONE_FIVE_Q23 ) && LT_32( predictionGain, ONE_POINT_ONE_FIVE_Q7 ); diff --git a/lib_enc/tcx_utils_enc_fx.c b/lib_enc/tcx_utils_enc_fx.c index cef9e3066..950856d73 100644 --- a/lib_enc/tcx_utils_enc_fx.c +++ b/lib_enc/tcx_utils_enc_fx.c @@ -315,6 +315,122 @@ void AnalyzePowerSpectrum_fx( } } +void AnalyzePowerSpectrum_ivas_fx( + Encoder_State *st, /* i/o: encoder states */ + Word16 L_frame, /* input: frame length */ + Word16 L_frameTCX, /* input: full band frame length */ + Word16 left_overlap, /* input: left overlap length */ + Word16 right_overlap, /* input: right overlap length */ + Word32 const mdctSpectrum[], /* input: MDCT spectrum */ + Word16 mdctSpectrum_e, + Word16 const signal[], /* input: windowed signal corresponding to mdctSpectrum */ + Word32 powerSpec[], /* output: Power spectrum. Can point to signal */ + Word16 *powerSpec_e ) +{ + Word16 i, iStart, iEnd, lowpassLine; + Word16 tmp, s1, s2; + Word32 tmp32; + Word8 tmp8; + TCX_ENC_HANDLE hTcxEnc = st->hTcxEnc; + + lowpassLine = L_frameTCX; + move16(); + + *powerSpec_e = 16; + move16(); + TCX_MDST( signal, powerSpec, powerSpec_e, left_overlap, sub( L_frameTCX, shr( add( left_overlap, right_overlap ), 1 ) ), right_overlap, st->element_mode ); + + iStart = 0; + move16(); + iEnd = L_frameTCX; + move16(); + + IF( st->narrowBand != 0 ) + { + attenuateNbSpectrum_fx( L_frameTCX, powerSpec ); + } + + /* get shift to common exponent */ + s1 = 0; + move16(); + s2 = 0; + move16(); + tmp = sub( mdctSpectrum_e, *powerSpec_e ); + if ( tmp > 0 ) + { + s2 = negate( tmp ); + } + if ( tmp < 0 ) + { + s1 = tmp; + move16(); + } + + /* get headroom */ + tmp = sub( getScaleFactor32( mdctSpectrum, L_frameTCX ), s1 ); + tmp = s_min( tmp, sub( getScaleFactor32( powerSpec, L_frameTCX ), s2 ) ); + s1 = add( s1, tmp ); + s2 = add( s2, tmp ); + + /* power spectrum: MDCT^2 + MDST^2 */ + FOR( i = iStart; i < iEnd; i++ ) + { + // To be checked +#ifdef BASOP_NOGLOB + tmp = round_fx_sat( L_shl_sat( mdctSpectrum[i], s1 ) ); +#else + tmp = round_fx( L_shl( mdctSpectrum[i], s1 ) ); +#endif + tmp32 = L_mult0( tmp, tmp ); + +#ifdef BASOP_NOGLOB + tmp = round_fx_sat( L_shl_sat( powerSpec[i], s2 ) ); +#else + tmp = round_fx( L_shl( powerSpec[i], s2 ) ); +#endif + tmp32 = L_mac0( tmp32, tmp, tmp ); + + powerSpec[i] = tmp32; + move32(); + } + + *powerSpec_e = add( shl( sub( mdctSpectrum_e, s1 ), 1 ), 1 ); + move16(); + + tmp8 = 0; + move16(); + test(); + if ( L_msu0( L_mult0( st->L_frame, extract_l( st->last_sr_core ) ), st->L_frame_past, extract_l( st->sr_core ) ) != 0 || NE_16( st->last_core, TCX_20_CORE ) ) + { + tmp8 = 1; + move16(); + } + + ComputeSpectrumNoiseMeasure_fx( powerSpec, + L_frameTCX, + divide3216( L_mult( hTcxEnc->nmStartLine, L_frame ), st->L_frame ), + tmp8, + hTcxEnc->memQuantZeros, + lowpassLine ); + + IF( LE_32( st->total_brate, ACELP_24k40 ) ) + { + lowpassLine = shl( mult( st->hTcxCfg->bandwidth, L_frame ), 1 ); + + test(); + detectLowpassFac( powerSpec, *powerSpec_e, + L_frame, + sub( st->last_core, ACELP_CORE ) == 0, + &hTcxEnc->measuredBwRatio, + lowpassLine ); + } + ELSE + { + hTcxEnc->measuredBwRatio = 0x4000; + move16(); + } +} + void AdaptLowFreqEmph_fx( Word32 x[], Word16 x_e, Word16 xq[], -- GitLab